STM32-LTDC, LCD-TFT, LVGL(MCU3) Lecture 40| LTDC Layers initialization coding contd

 

LTDC Layers initialization coding

 

Configure pitch, line length, and total lines of the frame buffer . These parameters define how the display data is organized and how the LTDC accesses and refreshes the frame buffer.

  1. Pitch: The pitch is the number of bytes between two consecutive lines of the frame buffer. It determines the memory offset required to access the next line of pixels. The pitch value is usually set based on the display resolution and pixel format. It is calculated as the number of pixels per line multiplied by the number of bytes per pixel.
  2. Line length: The line length specifies the number of pixels in each line of the display. It indicates the width of the frame buffer and is closely related to the display resolution. The line length value should be set based on the actual physical width of the display.
  3. Total lines: The total lines parameter defines the number of lines present in the frame buffer. It corresponds to the height of the display and is typically determined by the display resolution.

 

Here’s an example configuration for the frame buffer parameters in LTDC:

Display Resolution: 800×480 pixels

Pixel Format: RGB888 (3 bytes per pixel)

Pitch calculation:

Pitch = (Number of pixels per line) × (Number of bytes per pixel)

  1. Pitch = 800 × 3 = 2400 bytes

 

Line length:

Line length = Number of pixels per line

2. Line length = 800 pixels

 

Total lines:

Total lines = Number of lines in the display

3. Total lines = 480 lines

With these values, you can configure the LTDC’s frame buffer parameters. This example assumes an RGB888 pixel format, where each pixel is represented by 3 bytes (8 bits per channel).

The pitch is set to 2400 bytes, indicating that each line is spaced by 2400 bytes in memory. The line length is set to 800 pixels, corresponding to the width of the display. The total lines are set to 480, representing the height of the display.

Please note that, the actual configuration and register settings for the LTDC may vary depending on the specific microcontroller or SoC being used. It’s important to consult the documentation or reference manual for your particular device to obtain the correct register addresses and bit assignments.

//Configure pitch, line length and total lines of the frame buffer
tmp = 0;
uint32_t pitch = BSP_LTDC_LAYER_WIDTH * 2;
uint32_t line_len = pitch + 3;
REG_SET_VAL(tmp,pitch,0x1FFFU,LTDC_LxCFBLR_CFBP_Pos);
REG_SET_VAL(tmp,line_len,0x1FFFU,LTDC_LxCFBLR_CFBLL_Pos);
REG_WRITE(pLayer->CFBLR,tmp);

REG_SET_VAL(pLayer->CFBLNR,BSP_LTDC_LAYER_HEIGHT,0x7FFU,LTDC_LxCFBLNR_CFBLNBR_Pos);

tmp = 0;

Initializes a temporary variable tmp to zero.

 

uint32_t pitch = BSP_LTDC_LAYER_WIDTH * 2;

Calculates the pitch value, which represents the number of bytes between the start of each line in the frame buffer. It is calculated by multiplying the width of the layer (BSP_LTDC_LAYER_WIDTH) by 2 (assuming 16 bits per pixel, as indicated by the multiplication).

 

uint32_t line_len = pitch + 3;

Calculates the line length, which represents the total number of bytes per line, including the pitch. It is calculated by adding 3 to the pitch value.

 

REG_SET_VAL(tmp, pitch, 0x1FFFU, LTDC_LxCFBLR_CFBP_Pos);

Sets the value of the pitch in the temporary variable tmp using a register setting macro or function. The REG_SET_VAL macro is not explicitly provided in the code snippet, but it likely sets the value of a specific field (LTDC_LxCFBLR_CFBP_Pos) within tmp using a bitmask (0x1FFFU) and a shift operation.

 

REG_SET_VAL(tmp, line_len, 0x1FFFU, LTDC_LxCFBLR_CFBLL_Pos);

Sets the value of the line length in the temporary variable tmp using a similar register setting macro or function. It sets the value of a specific field (LTDC_LxCFBLR_CFBLL_Pos) within tmp using a bitmask (0x1FFFU) and a shift operation.

 

REG_WRITE(player->CFBLR, tmp);

Writes the value of the temporary variable tmp to a specific register (player->CFBLR) that likely controls the frame buffer configuration.

 

REG_SET_VAL(player->CFBLNR, BSP_LTDC_LAYER_HEIGHT, 0x7FFU, LTDC_LxCFBLNR_CFBLNBR_Pos);

Sets the value of the total lines (line count) in the frame buffer configuration register (player->CFBLNR). It sets the value of a specific field (LTDC_LxCFBLNR_CFBLNBR_Pos) using a bitmask (0x7FFU) and a shift operation. The BSP_LTDC_LAYER_HEIGHT represents the height of the layer.

 

In conclusion, this code snippet effectively establishes the configuration parameters associated with the frame buffer for an LTDC layer, including the pitch (bytes between lines), line length (total bytes per line), and the total number of lines in the frame buffer.

 

FastBit Embedded Brain Academy Courses

 Click here: https://fastbitlab.com/course1

 

FastBitLab

The FastBit Embedded Brain Academy uses the power of internet to bring the online courses related to the field of embedded system programming, Real time operating system, Embedded Linux systems, etc at your finger tip with very low cost. Backed with strong experience of industry, we have produced lots of courses with the customer enrolment over 3000+ across 100+ countries.