11/* Includes ------------------------------------------------------------------*/
22#include <unicore-mx/stm32/rcc.h>
33#include <unicore-mx/stm32/gpio.h>
4- #include <unicore-mx/stm32/ltdc .h>
4+ #include <unicore-mx/lcd_tft/lcd_tft .h>
55#include "RGB_565_480_272.h"
66#include "rk043fn48h.h"
77
88/* Private function prototypes -----------------------------------------------*/
99static void lcd_config (void );
1010static void lcd_pinmux (void );
1111static void lcd_clock (void );
12- static void lcd_config_layer (void );
12+ static void lcd_config_layer (lcd_tft * lt );
1313
1414/* Private functions ---------------------------------------------------------*/
1515
@@ -71,36 +71,24 @@ void lcd_pinmux(void)
7171 gpio_set (GPIOK , GPIO3 );
7272}
7373
74- static void lcd_config_layer (void )
74+ static void lcd_config_layer (lcd_tft * lt )
7575{
76- /* Windowing configuration */
77- ltdc_setup_windowing (LTDC_LAYER_2 , 480 , 272 );
78-
79- /* Specifies the pixel format */
80- ltdc_set_pixel_format (LTDC_LAYER_2 , LTDC_LxPFCR_RGB565 );
81-
82- /* Default color values */
83- ltdc_set_default_colors (LTDC_LAYER_2 , 0 , 0 , 0 , 0 );
84- /* Constant alpha */
85- ltdc_set_constant_alpha (LTDC_LAYER_2 , 255 );
86-
87- /* Blending factors */
88- ltdc_set_blending_factors (LTDC_LAYER_2 , LTDC_LxBFCR_BF1_CONST_ALPHA , LTDC_LxBFCR_BF2_CONST_ALPHA );
89-
90- /* Framebuffer address */
91- ltdc_set_fbuffer_address (LTDC_LAYER_2 , (uint32_t )& RGB_565_480_272 .pixel_data );
92-
93- /* Configures the color frame buffer pitch in byte */
94- ltdc_set_fb_line_length (LTDC_LAYER_2 , 2 * 480 , 2 * 480 ); /* RGB565 is 2 bytes/pixel */
95-
96- /* Configures the frame buffer line number */
97- ltdc_set_fb_line_count (LTDC_LAYER_2 , 272 );
98-
99- /* Enable layer 1 */
100- ltdc_layer_ctrl_enable (LTDC_LAYER_2 , LTDC_LxCR_LAYER_ENABLE );
101-
102- /* Sets the Reload type */
103- ltdc_reload (LTDC_SRCR_IMR );
76+ const struct lcd_tft_layer layer = {
77+ .framebuffer = {
78+ .x = 0 ,
79+ .y = 0 ,
80+ .width = RGB_565_480_272 .width ,
81+ .height = RGB_565_480_272 .height ,
82+ .format = LCD_TFT_RGB565 ,
83+ .data = RGB_565_480_272 .pixel_data
84+ },
85+
86+ .background = 0x00000000 ,
87+ .palette = {.data = NULL , .count = 0 },
88+ .transparent = {.data = NULL , .count = 0 }
89+ };
90+
91+ lcd_tft_layer_set (lt , 1 , & layer );
10492}
10593
10694/**
@@ -116,24 +104,29 @@ static void lcd_config_layer(void)
116104 */
117105static void lcd_config (void )
118106{
119- /* LTDC Initialization */
120- ltdc_ctrl_disable (LTDC_GCR_HSPOL_ACTIVE_HIGH ); /* Active Low Horizontal Sync */
121- ltdc_ctrl_disable (LTDC_GCR_VSPOL_ACTIVE_HIGH ); /* Active Low Vertical Sync */
122- ltdc_ctrl_disable (LTDC_GCR_DEPOL_ACTIVE_HIGH ); /* Active Low Date Enable */
123- ltdc_ctrl_disable (LTDC_GCR_PCPOL_ACTIVE_HIGH ); /* Active Low Pixel Clock */
124-
125- /* Configure the LTDC */
126- ltdc_set_tft_sync_timings (RK043FN48H_HSYNC , RK043FN48H_VSYNC ,
127- RK043FN48H_HBP , RK043FN48H_VBP ,
128- RK043FN48H_WIDTH , RK043FN48H_HEIGHT ,
129- RK043FN48H_HFP , RK043FN48H_VFP );
130-
131- ltdc_set_background_color (0 , 0 , 0 );
132- ltdc_ctrl_enable (LTDC_GCR_LTDC_ENABLE );
133-
134- /* Configure the Layer*/
135- lcd_config_layer ();
136-
107+ const struct lcd_tft_config config = {
108+ .timing = {
109+ .hsync = RK043FN48H_HSYNC ,
110+ .vsync = RK043FN48H_VSYNC ,
111+ .hbp = RK043FN48H_HBP ,
112+ .vbp = RK043FN48H_VBP ,
113+ .height = RK043FN48H_HEIGHT ,
114+ .width = RK043FN48H_WIDTH ,
115+ .vfp = RK043FN48H_VFP ,
116+ .hfp = RK043FN48H_HFP
117+ },
118+ .features = LCD_TFT_HSYNC_ACTIVE_LOW |
119+ LCD_TFT_VSYNC_ACTIVE_LOW |
120+ LCD_TFT_DE_ACTIVE_LOW |
121+ LCD_TFT_CLK_ACTIVE_LOW ,
122+ .output = LCD_TFT_OUTPUT_RGB888 ,
123+ .background = 0x00000000
124+ };
125+
126+ lcd_tft * lt = lcd_tft_init (LCD_TFT_STM32_LTDC , & config );
127+
128+ /* Configure the Layer*/
129+ lcd_config_layer (lt );
137130}
138131
139132
0 commit comments