LTDC Layers initialization coding and windowing explanation
In the previous article, we explored a few registers of the LTDC layers. In this article, let’s continue with our coding and create another function called “LTDC Layer Init”. This function will be responsible for initializing the LTDC layer according to our application requirements.
To initialize the LTDC layer, you need to follow these steps:
- Configure the pixel format of the layer’s framebuffer.
- Configure the constant alpha and blending factors, namely BF1 and BF2.
- Configure the layer position (Windowing).
- Configure the frame buffer address.
- Optionally, configure the default color of the layer (usually black color is used by default).
- Configure the pitch, line length, and line numbers of the frame buffer.
- Activate immediate reload. This means storing the values from the shadow registers to the real registers. All the configurations mentioned above are stored in the shadow registers, so activating immediate reload is necessary.
- Enable the layer.
You can easily code these steps by referring to the reference manual.
Now, I will explain how to configure the position of the layer and how the windowing works.
Let’s discuss the configuration items for the horizontal position of the layer window.
There are 2 configuration items. WHSTOPS(Start) and WHSPPOS(Stop).
In the LTDC Layerx Window Horizontal Position Configuration Register, you can see the start position and the stop position(Figure 3).
How to calculate the start position and stop position? You can follow the method below.
WHSTOPS(Start) = AHBP+H_start+1
WHSPPOS(Stop) = AHBP+H_start+Layer_width+1(<=AAW)
- WHSTOPS (Start):
- WHSTOPS represents the starting position of the layer window.
- It is calculated using the following formula: WHSTOPS(Start) = AHBP + H_start + 1
- AHBP stands for Accumulated Horizontal Back Porch, which represents the number of horizontal pixels before the active display area starts.
- H_start represents the horizontal offset for the layer window, indicating the number of pixels from the left edge of the screen where the window should start.
- By adding AHBP, H_start, and 1, you can determine the starting position of the layer window vertically.
- WHSPPOS (Stop):
- WHSPPOS represents the stopping position of the layer window.
- It is calculated using the following formula: WHSPPOS(Stop) = AHBP + H_start + Layer_width + 1 (<= AAW)
- Layer_width represents the width of the layer window in pixels.
- AAW stands for Accumulated Active Width, which indicates the total width of the active display area.
- By adding AHBP, H_start, Layer_width, and 1, you can determine the stopping position of the layer window vertically.
- The condition (<= AAW) ensures that the stopping position does not exceed the width of the active display area.
Example:
Let’s assume the following values for the configuration items:
- AHBP = 20
- H_start = 10
- Layer_width = 100
- AAW = 800
WHSTOPS(Start) = AHBP + H_start + 1
WHSTOPS(Start) = 20 + 10 + 1
- WHSTOPS(Start) = 31
WHSPPOS(Stop) = AHBP + H_start + Layer_width + 1 (<= AAW)
WHSPPOS(Stop) = 20 + 10 + 100 + 1 (<= 800)
2.WHSPPOS(Stop) = 131 (<= 800)
In this example, the layer window would start at a vertical position of 31 pixels and stop at a position of 131 pixels, within the allowed range of the active display area.
Similarly, Layer window vertical position configuration items.
There are 2 configuration items here. I mean, the logic is same. Instead of AHBP you should take AVBP, read that value.
In this project, we are displaying VIBGYOR bars as shown in Figure 5. We are utilizing the layer for the entire screen. Our layer window operates as follows: H_start is 0, H_stop is 320, V_start is 0, and V_stop is 240. Based on these values, you need to perform the calculations.
Configure layer position (windowing)
The Layer Position (windowing) in the LCD-TFT Display Controller (LTDC) allows you to define the position and size of each layer within the display. This feature enables you to create multi-layered graphics or blend multiple images on the screen.
To configure the layer position in LTDC, you need to define the Horizontal Start, Horizontal Stop, Vertical Start, and Vertical Stop values for each layer. These values specify the coordinates of the top-left and bottom-right corners of the layer within the display.
// Configure layer position (Windowing) uint32_t tmp = 0; uint32_t AHBP = REG_READ_VAL(pLTDC->BPCR,0xFFFU,LTDC_BPCR_AHBP_Pos); uint32_t WHSTART = AHBP+0 +1; REG_SET_VAL(tmp,WHSTART,0xFFFU,LTDC_LxWHPCR_WHSTPOS_Pos); uint32_t WHSTOP = AHBP+0+BSP_LTDC_LAYER_WIDTH+1; uint32_t AAW = REG_READ_VAL(pLTDC->AWCR,0xFFFU,LTDC_AWCR_AAW_Pos); WHSTOP = (WHSTOP > AAW)?AAW:WHSTOP; REG_SET_VAL(tmp,WHSTOP,0xFFFU,LTDC_LxWHPCR_WHSPPOS_Pos); REG_WRITE(tmp, pLayer->WHPCR);
First let’s calculate WHSTART. WHSTART = AHBP + the Layer width 0, and +1.
uint32_t WHSTART = AHBP + 0 + 1;
This line calculates the start position for the horizontal synchronization (window) of the layer. It adds the value of AHBP (active horizontal back porch) with 0 (presumably for some additional offset) and 1 to obtain the start position. The result is stored in the variable WHSTART.
uint32_t AHBP = REG_READ_VAL(pLTDC->BPCR, 0xFFFU, LTDC_BPCR_AHBP_Pos);
This line reads a value from the LTDC’s BPCR (Back Porch Configuration Register) at the bit position specified by LTDC_BPCR_AHBP_Pos (presumably a constant defined elsewhere) using the REG_READ_VAL function. The extracted value is stored in the variable AHBP, which represents the active horizontal back porch.
After that, let’s create one temporary variable.
uint32_t tmp = 0;
This line initializes a temporary variable tmp of type uint32_t and assigns it the value 0.
REG_SET_VAL(tmp, WHSTART, 0xFFFU, LTDC_LxWHPCR_WHSTPOS_Pos);
This line sets the window start position value in the tmp variable. It uses the REG_SET_VAL function, passing tmp as the target variable, WHSTART as the value to be set, 0xFFFU as the mask (to ensure the value fits within 12 bits), and LTDC_LxWHPCR_WHSTPOS_Pos as the position where the value should be placed within the tmp variable.
uint32_t WHSTOP = AHBP + 0 + BSP_LCD_ACTIVE_WIDTH + 1;
This line calculates the stop position for the horizontal synchronization (window) of the layer. It adds the value of AHBP (active horizontal back porch), 0 (presumably for some additional offset), BSP_LCD_ACTIVE_WIDTH (presumably a constant representing the active width of the LCD screen), and 1 to obtain the stop position. The result is stored in the variable WHSTOP.
uint32_t AAW = REG_READ_VAL(pLTDC->AWCR, 0xFFFU, LTDC_AWCR_AWW_Pos);
This line reads a value from the LTDC’s AWCR (Active Width Configuration Register) at the bit position specified by LTDC_AWCR_AWW_Pos (presumably a constant defined elsewhere) using the REG_READ_VAL function. The extracted value is stored in the variable AAW, which represents the active area width.
WHSTOP = (WHSTOP > AAW) ? AAW : WHSTOP;
This line ensures that the WHSTOP value does not exceed the AAW (active area width) value. If WHSTOP is greater than AAW, it is set to AAW; otherwise, it remains unchanged.
REG_SET_VAL(tmp, WHSTOP, 0xFFFU, LTDC_LxWHPCR_WHSPPOS_Pos);
This line sets the window stop position value in the tmp variable. It uses the REG_SET_VAL function, passing tmp as the target variable, WHSTOP as the value to be set, 0xFFFU as the mask (to ensure the value fits within 12 bits), and LTDC_LxWHPCR_WHSPPOS_Pos as the position where the value should be placed within the tmp variable.
REG_WRITE(tmp, player->WHPCR);
This line writes the final windowing configuration value stored in tmp to the WHPCR (Window Horizontal Position Configuration Register) of the specified player.
Overall, this code calculates the start and stop positions for the horizontal synchronization (windowing) of a layer in the LTDC module and writes the configuration to the appropriate register.
FastBit Embedded Brain Academy Courses
Click here: https://fastbitlab.com/course1