From 655d8dc768484917a0ae056f9d46a3ddf725a241 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Sun, 17 Oct 2021 03:45:17 -0400 Subject: [PATCH] [bsp][stm32][l475] add lcd_fill_array() --- .../board/ports/drv_lcd.c | 61 +++++++++++++++++-- .../board/ports/drv_lcd.h | 2 +- 2 files changed, 56 insertions(+), 7 deletions(-) diff --git a/bsp/stm32/stm32l475-atk-pandora/board/ports/drv_lcd.c b/bsp/stm32/stm32l475-atk-pandora/board/ports/drv_lcd.c index 6ec90f880c..7a48c7e7e6 100644 --- a/bsp/stm32/stm32l475-atk-pandora/board/ports/drv_lcd.c +++ b/bsp/stm32/stm32l475-atk-pandora/board/ports/drv_lcd.c @@ -8,17 +8,17 @@ * 2018-08-14 flybreak the first version * 2018-09-18 balanceTWK add sleep mode function * 2018-09-27 ZYLX optimized display speed + * 2021-10-17 Meco Man add lcd_fill_array() */ #include #include "drv_spi.h" -#include "drv_lcd.h" +#include #include "drv_lcd_font.h" -#include "drv_gpio.h" +#include -#define DBG_SECTION_NAME "LCD" -#define DBG_COLOR -#define DBG_LEVEL DBG_LOG +#define DBG_TAG "drv.lcd" +#define DBG_LVL DBG_INFO #include #define LCD_PWR_PIN GET_PIN(B, 7) @@ -375,7 +375,7 @@ void lcd_fill(rt_uint16_t x_start, rt_uint16_t y_start, rt_uint16_t x_end, rt_ui rt_uint32_t size = 0, size_remain = 0; rt_uint8_t *fill_buf = RT_NULL; - size = (x_end - x_start) * (y_end - y_start) * 2; + size = (x_end - x_start + 1) * (y_end - y_start + 1) * 2; if (size > LCD_CLEAR_SEND_NUMBER) { @@ -426,6 +426,55 @@ void lcd_fill(rt_uint16_t x_start, rt_uint16_t y_start, rt_uint16_t x_end, rt_ui } } +/** + * full color array on the lcd. + * + * @param x_start start of x position + * @param y_start start of y position + * @param x_end end of x position + * @param y_end end of y position + * @param color Fill color array's pointer + * + * @return void + */ +void lcd_fill_array(rt_uint16_t x_start, rt_uint16_t y_start, rt_uint16_t x_end, rt_uint16_t y_end, void *pcolor) +{ + rt_uint32_t size = 0, size_remain = 0; + + size = (x_end - x_start + 1) * (y_end - y_start + 1) * 2; + + if (size > LCD_CLEAR_SEND_NUMBER) + { + /* the number of remaining to be filled */ + size_remain = size - LCD_CLEAR_SEND_NUMBER; + size = LCD_CLEAR_SEND_NUMBER; + } + + lcd_address_set(x_start, y_start, x_end, y_end); + + /* fast fill */ + while (1) + { + rt_pin_write(LCD_DC_PIN, PIN_HIGH); + rt_spi_send(spi_dev_lcd, pcolor, size); + + /* Fill completed */ + if (size_remain == 0) + break; + + /* calculate the number of fill next time */ + if (size_remain > LCD_CLEAR_SEND_NUMBER) + { + size_remain = size_remain - LCD_CLEAR_SEND_NUMBER; + } + else + { + size = size_remain; + size_remain = 0; + } + } +} + /** * display a line on the lcd. * diff --git a/bsp/stm32/stm32l475-atk-pandora/board/ports/drv_lcd.h b/bsp/stm32/stm32l475-atk-pandora/board/ports/drv_lcd.h index 394305012e..021c010f20 100644 --- a/bsp/stm32/stm32l475-atk-pandora/board/ports/drv_lcd.h +++ b/bsp/stm32/stm32l475-atk-pandora/board/ports/drv_lcd.h @@ -50,7 +50,7 @@ void lcd_draw_circle(rt_uint16_t x0, rt_uint16_t y0, rt_uint8_t r); void lcd_draw_line(rt_uint16_t x1, rt_uint16_t y1, rt_uint16_t x2, rt_uint16_t y2); void lcd_draw_rectangle(rt_uint16_t x1, rt_uint16_t y1, rt_uint16_t x2, rt_uint16_t y2); void lcd_fill(rt_uint16_t x_start, rt_uint16_t y_start, rt_uint16_t x_end, rt_uint16_t y_end, rt_uint16_t color); - +void lcd_fill_array(rt_uint16_t x_start, rt_uint16_t y_start, rt_uint16_t x_end, rt_uint16_t y_end, void *pcolor); void lcd_show_num(rt_uint16_t x, rt_uint16_t y, rt_uint32_t num, rt_uint8_t len, rt_uint32_t size); rt_err_t lcd_show_string(rt_uint16_t x, rt_uint16_t y, rt_uint32_t size, const char *fmt, ...); rt_err_t lcd_show_image(rt_uint16_t x, rt_uint16_t y, rt_uint16_t length, rt_uint16_t wide, const rt_uint8_t *p);