3636
3737#define LCD_WIDTH 512
3838#define LCD_HEIGHT 800
39+ #define LCD_STRIDE 512
3940#define LCD_BITS_PER_PIXEL 16
40- #define LCD_BUF_SIZE (LCD_WIDTH * LCD_HEIGHT * LCD_BITS_PER_PIXEL / 8)
41+ #define LCD_BUF_SIZE (LCD_STRIDE * LCD_HEIGHT * LCD_BITS_PER_PIXEL / 8)
4142#define LCD_PIXEL_FORMAT RTGRAPHIC_PIXEL_FORMAT_RGB565
4243#define LCD_DEVICE (dev ) (struct drv_lcd_device*)(dev)
43- #define RESET_VAL 0U
4444#define GPU_TESSELLATION_BUFFER_SIZE ((LCD_WIDTH) * 128U)
4545#define APP_BUFFER_COUNT (2U)
4646#define DEFAULT_GPU_CMD_BUFFER_SIZE ((64U) * (512))
@@ -76,9 +76,7 @@ struct drv_lcd_device
7676
7777static rt_err_t drv_lcd_init (struct rt_device * device )
7878{
79- struct drv_lcd_device * lcd = LCD_DEVICE (device );
80- /* nothing, right now */
81- lcd = lcd ;
79+ (void )device ;
8280 return RT_EOK ;
8381}
8482
@@ -90,6 +88,53 @@ static rt_err_t drv_lcd_control(struct rt_device *device, int cmd, void *args)
9088 {
9189 case RTGRAPHIC_CTRL_RECT_UPDATE :
9290 {
91+ struct rt_device_rect_info * info = (struct rt_device_rect_info * )args ;
92+ uint32_t start_line = 0U ;
93+ uint32_t end_line = lcd -> lcd_info .height ;
94+ rt_bool_t try_partial = RT_FALSE ;
95+
96+ if (info != RT_NULL )
97+ {
98+ if ((info -> width == 0U ) || (info -> height == 0U ))
99+ {
100+ return RT_EOK ;
101+ }
102+ if ((info -> x >= lcd -> lcd_info .width ) || (info -> y >= lcd -> lcd_info .height ))
103+ {
104+ return RT_EOK ;
105+ }
106+ if ((info -> x + info -> width ) > lcd -> lcd_info .width )
107+ {
108+ info -> width = lcd -> lcd_info .width - info -> x ;
109+ }
110+ if ((info -> y + info -> height ) > lcd -> lcd_info .height )
111+ {
112+ info -> height = lcd -> lcd_info .height - info -> y ;
113+ }
114+
115+ start_line = info -> y ;
116+ end_line = info -> y + info -> height ;
117+ if ((info -> x == 0U ) && (info -> width == lcd -> lcd_info .width ))
118+ {
119+ try_partial = RT_TRUE ;
120+ }
121+ }
122+
123+ if (try_partial &&
124+ ((lcd_gfx_context .dc_context .display_type == GFX_DISP_TYPE_DBI_A ) ||
125+ (lcd_gfx_context .dc_context .display_type == GFX_DISP_TYPE_DBI_B ) ||
126+ (lcd_gfx_context .dc_context .display_type == GFX_DISP_TYPE_DBI_C ) ||
127+ (lcd_gfx_context .dc_context .display_type == GFX_DISP_TYPE_DSI_DBI )))
128+ {
129+ status = Cy_GFXSS_TransferPartialFrame (gfxbase , start_line , end_line , & lcd_gfx_context );
130+ if (CY_GFX_SUCCESS != status )
131+ {
132+ LOG_E ("[%s: %d] Partial frame transfer failed. Error type: %u\r\n" , __func__ , __LINE__ , status );
133+ CY_ASSERT (0 );
134+ }
135+ break ;
136+ }
137+
93138 /* update */
94139 /* Set the frame buffer with the image pointer to be displayed on LCD */
95140 status = Cy_GFXSS_Set_FrameBuffer (gfxbase , (uint32_t * )graphics_buffer , & lcd_gfx_context );
@@ -111,9 +156,11 @@ static rt_err_t drv_lcd_control(struct rt_device *device, int cmd, void *args)
111156 RT_ASSERT (info != RT_NULL );
112157 info -> pixel_format = lcd -> lcd_info .pixel_format ;
113158 info -> bits_per_pixel = 16 ;
159+ info -> pitch = lcd -> lcd_info .pitch ;
114160 info -> width = lcd -> lcd_info .width ;
115161 info -> height = lcd -> lcd_info .height ;
116162 info -> framebuffer = lcd -> lcd_info .framebuffer ;
163+ info -> smem_len = lcd -> lcd_info .smem_len ;
117164 }
118165 break ;
119166 }
@@ -148,6 +195,7 @@ static void dc_irq_handler(void)
148195{
149196 rt_interrupt_enter ();
150197 Cy_GFXSS_Clear_DC_Interrupt (gfxbase , & lcd_gfx_context );
198+ rt_sem_release (& _lcd .lcd_lock );
151199 rt_interrupt_leave ();
152200}
153201
@@ -251,6 +299,8 @@ int drv_lcd_hw_init(void)
251299 _lcd .lcd_info .width = LCD_WIDTH ;
252300 _lcd .lcd_info .bits_per_pixel = LCD_BITS_PER_PIXEL ;
253301 _lcd .lcd_info .pixel_format = LCD_PIXEL_FORMAT ;
302+ _lcd .lcd_info .pitch = LCD_STRIDE * (LCD_BITS_PER_PIXEL / 8 );
303+ _lcd .lcd_info .smem_len = LCD_BUF_SIZE ;
254304
255305 /* malloc memory for Triple Buffering */
256306 // _lcd.front_buf=_lcd.lcd_info.framebuffer = rt_malloc_align(LCD_BUF_SIZE, 32);
@@ -264,7 +314,7 @@ int drv_lcd_hw_init(void)
264314 goto __exit ;
265315 }
266316 /* memset buff to 0xFF */
267- memset (_lcd .lcd_info .framebuffer , 0xFF , LCD_BUF_SIZE );
317+ memset (_lcd .lcd_info .framebuffer , 0x00 , LCD_BUF_SIZE );
268318 device -> type = RT_Device_Class_Graphic ;
269319#ifdef RT_USING_DEVICE_OPS
270320 device -> ops = & lcd_ops ;
0 commit comments