Browse Source

update:支持自定义lcd 绘制

Dozingfiretruck 1 year ago
parent
commit
e91edb5a41
3 changed files with 20 additions and 10 deletions
  1. 10 2
      components/lcd/luat_lcd.c
  2. 5 1
      components/lcd/luat_lcd.h
  3. 5 7
      components/lcd/luat_lib_lcd.c

+ 10 - 2
components/lcd/luat_lcd.c

@@ -252,7 +252,7 @@ int luat_lcd_set_direction(luat_lcd_conf_t* conf, uint8_t direction){
 }
 
 #ifndef LUAT_USE_LCD_CUSTOM_DRAW
-int luat_lcd_flush(luat_lcd_conf_t* conf) {
+int luat_lcd_flush_default(luat_lcd_conf_t* conf) {
     if (conf->buff == NULL) {
         return 0;
     }
@@ -282,7 +282,11 @@ int luat_lcd_flush(luat_lcd_conf_t* conf) {
     return 0;
 }
 
-int luat_lcd_draw(luat_lcd_conf_t* conf, int16_t x1, int16_t y1, int16_t x2, int16_t y2, luat_color_t* color) {
+LUAT_WEAK int luat_lcd_flush(luat_lcd_conf_t* conf) {
+    return luat_lcd_flush_default(conf);
+}
+
+int luat_lcd_draw_default(luat_lcd_conf_t* conf, int16_t x1, int16_t y1, int16_t x2, int16_t y2, luat_color_t* color) {
     if (x1 >= conf->w || y1 >= conf->h || x2 < 0 || y2 < 0 || x2 < x1 || y2 < y1) {
         // LLOGE("out of lcd buff range %d %d %d %d", x1, y1, x2, y2);
         // LLOGE("out of lcd buff range %d %d %d %d %d", x1 >= conf->w, y1 >= conf->h, y2 < 0, x2 < x1, y2 < y1);
@@ -379,6 +383,10 @@ int luat_lcd_draw(luat_lcd_conf_t* conf, int16_t x1, int16_t y1, int16_t x2, int
     }
     return 0;
 }
+
+LUAT_WEAK int luat_lcd_draw(luat_lcd_conf_t* conf, int16_t x1, int16_t y1, int16_t x2, int16_t y2, luat_color_t* color) {
+    return luat_lcd_draw_default(conf, x1, y1, x2, y2, color);
+}
 #endif
 
 int luat_lcd_draw_point(luat_lcd_conf_t* conf, int16_t x, int16_t y, luat_color_t color) {

+ 5 - 1
components/lcd/luat_lcd.h

@@ -125,9 +125,13 @@ void luat_lcd_execute_cmds(luat_lcd_conf_t* conf);
 int lcd_write_cmd_data(luat_lcd_conf_t* conf,const uint8_t cmd, const uint8_t *data, uint8_t data_len);
 int lcd_read_cmd_data(luat_lcd_conf_t* conf,const uint8_t cmd, const uint8_t *data, uint8_t data_len, uint8_t dummy_bit);
 
+// xxx_default 一般为通用spi设备使用
+int luat_lcd_init_default(luat_lcd_conf_t* conf);
+int luat_lcd_flush_default(luat_lcd_conf_t* conf);
+int luat_lcd_draw_default(luat_lcd_conf_t* conf, int16_t x1, int16_t y1, int16_t x2, int16_t y2, luat_color_t* color);
+
 luat_lcd_conf_t* luat_lcd_get_default(void);
 const char* luat_lcd_name(luat_lcd_conf_t* conf);
-int luat_lcd_init_default(luat_lcd_conf_t* conf);//通用spi设备使用
 int luat_lcd_init(luat_lcd_conf_t* conf);
 int luat_lcd_close(luat_lcd_conf_t* conf);
 int luat_lcd_display_on(luat_lcd_conf_t* conf);

+ 5 - 7
components/lcd/luat_lib_lcd.c

@@ -97,6 +97,7 @@ lcd.init("st7796s",{port = "DMA2D",direction = 2,w = 160,h = 80,xoffset = 1,yoff
 */
 
 static int l_lcd_init(lua_State* L) {
+    int ret;
     size_t len = 0;
     uint8_t spi_device = 0;
     luat_lcd_conf_t *conf = luat_heap_malloc(sizeof(luat_lcd_conf_t));
@@ -111,7 +112,6 @@ static int l_lcd_init(lua_State* L) {
     }
 #if defined LUAT_USE_LCD_SERVICE
     uint8_t init_in_service = 0;
-    int ret;
     if (lua_isboolean(L, 4)) {
     	init_in_service = lua_toboolean(L, 4);
     }
@@ -162,7 +162,6 @@ static int l_lcd_init(lua_State* L) {
                     goto end; 
                 }
             }
-
             if (spi_device == 1 && conf->port != LUAT_LCD_SPI_DEVICE) {
               LLOGE("port is not device but find luat_spi_device_t");
               goto end;
@@ -227,7 +226,7 @@ static int l_lcd_init(lua_State* L) {
                 conf->h = luaL_checkinteger(L, -1);
             }
             lua_pop(L, 1);
-            conf->buffer_size = (conf->w * conf->h) * 2;
+            conf->buffer_size = (conf->w * conf->h) * sizeof(luat_color_t);
 
             lua_pushstring(L, "xoffset");
             if (LUA_TNUMBER == lua_gettable(L, 2)) {
@@ -326,13 +325,12 @@ static int l_lcd_init(lua_State* L) {
 #if defined LUAT_USE_LCD_SERVICE
         if (init_in_service) {
         	ret = luat_lcd_init_in_service(conf);
-        } else {
+        } else 
+#endif
+        {
         	ret = luat_lcd_init(conf);
         }
 
-#else
-        int ret = luat_lcd_init(conf);
-#endif
         if (ret != 0) {
             LLOGE("lcd init fail %d", ret);
             luat_heap_free(conf);