Dozingfiretruck 4 роки тому
батько
коміт
ce93144409

+ 18 - 7
components/lcd/luat_lcd.c

@@ -121,7 +121,16 @@ int luat_lcd_init(luat_lcd_conf_t* conf) {
 }
 
 int luat_lcd_close(luat_lcd_conf_t* conf) {
-    return conf->opts->close(conf);
+    if (conf->pin_pwr != 255)
+        luat_gpio_set(conf->pin_pwr, Luat_GPIO_LOW);
+    return 0;
+}
+
+int luat_lcd_display_off(luat_lcd_conf_t* conf) {
+    if (conf->pin_pwr != 255)
+        luat_gpio_set(conf->pin_pwr, Luat_GPIO_LOW);
+    lcd_write_cmd(conf,0x28);
+    return 0;
 }
 
 int luat_lcd_display_on(luat_lcd_conf_t* conf) {
@@ -131,18 +140,20 @@ int luat_lcd_display_on(luat_lcd_conf_t* conf) {
     return 0;
 }
 
-int luat_lcd_display_off(luat_lcd_conf_t* conf) {
+int luat_lcd_sleep(luat_lcd_conf_t* conf) {
     if (conf->pin_pwr != 255)
         luat_gpio_set(conf->pin_pwr, Luat_GPIO_LOW);
+    luat_timer_mdelay(5);
+    lcd_write_cmd(conf,0x10);
     return 0;
 }
 
-int luat_lcd_sleep(luat_lcd_conf_t* conf) {
-    return conf->opts->sleep(conf);
-}
-
 int luat_lcd_wakeup(luat_lcd_conf_t* conf) {
-    return conf->opts->wakeup(conf);
+    if (conf->pin_pwr != 255)
+        luat_gpio_set(conf->pin_pwr, Luat_GPIO_HIGH);
+    luat_timer_mdelay(5);
+    lcd_write_cmd(conf,0x11);
+    return 0;
 }
 
 int luat_lcd_set_address(luat_lcd_conf_t* conf,uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2) {

+ 0 - 5
components/lcd/luat_lcd.h

@@ -64,9 +64,6 @@ typedef struct luat_lcd_conf {
 typedef struct luat_lcd_opts {
     const char* name;
     int (*init)(luat_lcd_conf_t* conf);
-    int (*close)(luat_lcd_conf_t* conf);
-    int (*sleep)(luat_lcd_conf_t* conf);
-    int (*wakeup)(luat_lcd_conf_t* conf);
 } luat_lcd_opts_t;
 
 int lcd_write_cmd(luat_lcd_conf_t* conf,const uint8_t cmd);
@@ -97,8 +94,6 @@ int luat_lcd_draw_circle(luat_lcd_conf_t* conf,uint16_t x0, uint16_t y0, uint8_t
 void luat_lcd_execute_cmds(luat_lcd_conf_t* conf, uint32_t* cmds, uint32_t count);
 
 typedef struct luat_lcd_custom {
-    uint8_t sleepcmd;
-    uint8_t wakecmd;
     size_t init_cmd_count;
     uint32_t *initcmd; // 实际命令长度与init_cmd_count相同
 }luat_lcd_custom_t;

+ 2 - 29
components/lcd/luat_lcd_custom.c

@@ -12,30 +12,6 @@
 #define LCD_H 320
 #define LCD_DIRECTION 0
 
-static int custom_sleep(luat_lcd_conf_t* conf) {
-    if (conf->pin_pwr != 255)
-        luat_gpio_set(conf->pin_pwr, Luat_GPIO_LOW);
-    luat_timer_mdelay(5);
-    luat_lcd_custom_t * cst = (luat_lcd_custom_t *)conf->userdata;
-    lcd_write_cmd(conf, cst->sleepcmd);
-    return 0;
-}
-
-static int custom_wakeup(luat_lcd_conf_t* conf) {
-    if (conf->pin_pwr != 255)
-        luat_gpio_set(conf->pin_pwr, Luat_GPIO_HIGH);
-    luat_timer_mdelay(5);
-    luat_lcd_custom_t * cst = (luat_lcd_custom_t *)conf->userdata;
-    lcd_write_cmd(conf, cst->wakecmd);
-    return 0;
-}
-
-static int custom_close(luat_lcd_conf_t* conf) {
-    if (conf->pin_pwr != 255)
-        luat_gpio_set(conf->pin_pwr, Luat_GPIO_LOW);
-    return 0;
-}
-
 static int custom_init(luat_lcd_conf_t* conf) {
 
     if (conf->w == 0)
@@ -56,13 +32,13 @@ static int custom_init(luat_lcd_conf_t* conf) {
     luat_timer_mdelay(100);
     luat_gpio_set(conf->pin_rst, Luat_GPIO_HIGH);
 
-    custom_wakeup(conf);
+    luat_lcd_wakeup(conf);
     luat_timer_mdelay(120);
     // 发送初始化命令
     luat_lcd_custom_t * cst = (luat_lcd_custom_t *)conf->userdata;
     luat_lcd_execute_cmds(conf, cst->initcmd, cst->init_cmd_count);
     
-    custom_wakeup(conf);
+    luat_lcd_wakeup(conf);
     /* wait for power stability */
     luat_timer_mdelay(100);
     luat_lcd_clear(conf,WHITE);
@@ -74,8 +50,5 @@ static int custom_init(luat_lcd_conf_t* conf) {
 const luat_lcd_opts_t lcd_opts_custom = {
     .name = "custom",
     .init = custom_init,
-    .close = custom_close,
-    .sleep = custom_sleep,
-    .wakeup = custom_wakeup,
 };
 

+ 0 - 25
components/lcd/luat_lcd_gc9106l.c

@@ -12,28 +12,6 @@
 #define LCD_H 160
 #define LCD_DIRECTION 0
 
-static int gc9106l_sleep(luat_lcd_conf_t* conf) {
-    if (conf->pin_pwr != 255)
-        luat_gpio_set(conf->pin_pwr, Luat_GPIO_LOW);
-    luat_timer_mdelay(5);
-    lcd_write_cmd(conf,0x10);
-    return 0;
-}
-
-static int gc9106l_wakeup(luat_lcd_conf_t* conf) {
-    if (conf->pin_pwr != 255)
-        luat_gpio_set(conf->pin_pwr, Luat_GPIO_HIGH);
-    luat_timer_mdelay(5);
-    lcd_write_cmd(conf,0x11);
-    //luat_timer_mdelay(120); // 外部休眠就好了吧
-    return 0;
-}
-
-static int gc9106l_close(luat_lcd_conf_t* conf) {
-    if (conf->pin_pwr != 255)
-        luat_gpio_set(conf->pin_pwr, Luat_GPIO_LOW);
-    return 0;
-}
 static int gc9106l_init(luat_lcd_conf_t* conf) {
     if (conf->w == 0)
         conf->w = LCD_W;
@@ -120,8 +98,5 @@ static int gc9106l_init(luat_lcd_conf_t* conf) {
 const luat_lcd_opts_t lcd_opts_gc9106l = {
     .name = "gc9106l",
     .init = gc9106l_init,
-    .close = gc9106l_close,
-    .sleep = gc9106l_sleep,
-    .wakeup = gc9106l_wakeup,
 };
 

+ 0 - 30
components/lcd/luat_lcd_gc9306.c

@@ -12,33 +12,6 @@
 #define LCD_H 320
 #define LCD_DIRECTION 0
 
-static int gc9306_sleep(luat_lcd_conf_t* conf) {
-    if (conf->pin_pwr != 255)
-        luat_gpio_set(conf->pin_pwr, Luat_GPIO_LOW);
-    lcd_write_cmd(conf,0xfe);
-    lcd_write_cmd(conf,0xef);
-    lcd_write_cmd(conf,0x28);
-    luat_timer_mdelay(120);
-    lcd_write_cmd(conf,0x10);
-    return 0;
-}
-
-static int gc9306_wakeup(luat_lcd_conf_t* conf) {
-    if (conf->pin_pwr != 255)
-        luat_gpio_set(conf->pin_pwr, Luat_GPIO_HIGH);
-    lcd_write_cmd(conf,0xfe);
-    lcd_write_cmd(conf,0xef);
-    lcd_write_cmd(conf,0x11);
-    luat_timer_mdelay(120);
-    lcd_write_cmd(conf,0x29);
-    return 0;
-}
-
-static int gc9306_close(luat_lcd_conf_t* conf) {
-    if (conf->pin_pwr != 255)
-        luat_gpio_set(conf->pin_pwr, Luat_GPIO_LOW);
-    return 0;
-}
 static int gc9306_init(luat_lcd_conf_t* conf) {
     if (conf->w == 0)
         conf->w = LCD_W;
@@ -199,8 +172,5 @@ static int gc9306_init(luat_lcd_conf_t* conf) {
 const luat_lcd_opts_t lcd_opts_gc9306 = {
     .name = "gc9306",
     .init = gc9306_init,
-    .close = gc9306_close,
-    .sleep = gc9306_sleep,
-    .wakeup = gc9306_wakeup,
 };
 

+ 0 - 25
components/lcd/luat_lcd_gc9a01.c

@@ -12,28 +12,6 @@
 #define LCD_H 240
 #define LCD_DIRECTION 0
 
-static int gc9a01_sleep(luat_lcd_conf_t* conf) {
-    if (conf->pin_pwr != 255)
-        luat_gpio_set(conf->pin_pwr, Luat_GPIO_LOW);
-    luat_timer_mdelay(5);
-    lcd_write_cmd(conf,0x10);
-    return 0;
-}
-
-static int gc9a01_wakeup(luat_lcd_conf_t* conf) {
-    if (conf->pin_pwr != 255)
-        luat_gpio_set(conf->pin_pwr, Luat_GPIO_HIGH);
-    luat_timer_mdelay(5);
-    lcd_write_cmd(conf,0x11);
-    //luat_timer_mdelay(120); // 外部休眠就好了吧
-    return 0;
-}
-
-static int gc9a01_close(luat_lcd_conf_t* conf) {
-    if (conf->pin_pwr != 255)
-        luat_gpio_set(conf->pin_pwr, Luat_GPIO_LOW);
-    return 0;
-}
 static int gc9a01_init(luat_lcd_conf_t* conf) {
     if (conf->w == 0)
         conf->w = LCD_W;
@@ -287,8 +265,5 @@ static int gc9a01_init(luat_lcd_conf_t* conf) {
 const luat_lcd_opts_t lcd_opts_gc9a01 = {
     .name = "gc9a01",
     .init = gc9a01_init,
-    .close = gc9a01_close,
-    .sleep = gc9a01_sleep,
-    .wakeup = gc9a01_wakeup,
 };
 

+ 0 - 25
components/lcd/luat_lcd_ili9341.c

@@ -12,28 +12,6 @@
 #define LCD_H 320
 #define LCD_DIRECTION 0
 
-static int ili9341_sleep(luat_lcd_conf_t* conf) {
-    if (conf->pin_pwr != 255)
-        luat_gpio_set(conf->pin_pwr, Luat_GPIO_LOW);
-    luat_timer_mdelay(5);
-    lcd_write_cmd(conf,0x10);
-    return 0;
-}
-
-static int ili9341_wakeup(luat_lcd_conf_t* conf) {
-    if (conf->pin_pwr != 255)
-        luat_gpio_set(conf->pin_pwr, Luat_GPIO_HIGH);
-    luat_timer_mdelay(5);
-    lcd_write_cmd(conf,0x11);
-    //luat_timer_mdelay(120); // 外部休眠就好了吧
-    return 0;
-}
-
-static int ili9341_close(luat_lcd_conf_t* conf) {
-    if (conf->pin_pwr != 255)
-        luat_gpio_set(conf->pin_pwr, Luat_GPIO_LOW);
-    return 0;
-}
 static int ili9341_init(luat_lcd_conf_t* conf) {
     if (conf->w == 0)
         conf->w = LCD_W;
@@ -168,8 +146,5 @@ static int ili9341_init(luat_lcd_conf_t* conf) {
 const luat_lcd_opts_t lcd_opts_ili9341 = {
     .name = "ili9341",
     .init = ili9341_init,
-    .close = ili9341_close,
-    .sleep = ili9341_sleep,
-    .wakeup = ili9341_wakeup,
 };
 

+ 0 - 25
components/lcd/luat_lcd_ili9488.c

@@ -12,28 +12,6 @@
 #define LCD_H 480
 #define LCD_DIRECTION 0
 
-static int ili9488_sleep(luat_lcd_conf_t* conf) {
-    if (conf->pin_pwr != 255)
-        luat_gpio_set(conf->pin_pwr, Luat_GPIO_LOW);
-    luat_timer_mdelay(5);
-    lcd_write_cmd(conf,0x10);
-    return 0;
-}
-
-static int ili9488_wakeup(luat_lcd_conf_t* conf) {
-    if (conf->pin_pwr != 255)
-        luat_gpio_set(conf->pin_pwr, Luat_GPIO_HIGH);
-    luat_timer_mdelay(5);
-    lcd_write_cmd(conf,0x11);
-    //luat_timer_mdelay(120); // 外部休眠就好了吧
-    return 0;
-}
-
-static int ili9488_close(luat_lcd_conf_t* conf) {
-    if (conf->pin_pwr != 255)
-        luat_gpio_set(conf->pin_pwr, Luat_GPIO_LOW);
-    return 0;
-}
 static int ili9488_init(luat_lcd_conf_t* conf) {
     if (conf->w == 0)
         conf->w = LCD_W;
@@ -294,8 +272,5 @@ static int ili9488_init(luat_lcd_conf_t* conf) {
 const luat_lcd_opts_t lcd_opts_ili9488 = {
     .name = "ili9488",
     .init = ili9488_init,
-    .close = ili9488_close,
-    .sleep = ili9488_sleep,
-    .wakeup = ili9488_wakeup,
 };
 

+ 0 - 25
components/lcd/luat_lcd_st7735.c

@@ -12,28 +12,6 @@
 #define LCD_H 160
 #define LCD_DIRECTION 0
 
-static int st7735_sleep(luat_lcd_conf_t* conf) {
-    if (conf->pin_pwr != 255)
-        luat_gpio_set(conf->pin_pwr, Luat_GPIO_LOW);
-    luat_timer_mdelay(5);
-    lcd_write_cmd(conf,0x10);
-    return 0;
-}
-
-static int st7735_wakeup(luat_lcd_conf_t* conf) {
-    if (conf->pin_pwr != 255)
-        luat_gpio_set(conf->pin_pwr, Luat_GPIO_HIGH);
-    luat_timer_mdelay(5);
-    lcd_write_cmd(conf,0x11);
-    //luat_timer_mdelay(120); // 外部休眠就好了吧
-    return 0;
-}
-
-static int st7735_close(luat_lcd_conf_t* conf) {
-    if (conf->pin_pwr != 255)
-        luat_gpio_set(conf->pin_pwr, Luat_GPIO_LOW);
-    return 0;
-}
 static int st7735_init(luat_lcd_conf_t* conf) {
     if (conf->w == 0)
         conf->w = LCD_W;
@@ -150,8 +128,5 @@ static int st7735_init(luat_lcd_conf_t* conf) {
 const luat_lcd_opts_t lcd_opts_st7735 = {
     .name = "st7735",
     .init = st7735_init,
-    .close = st7735_close,
-    .sleep = st7735_sleep,
-    .wakeup = st7735_wakeup,
 };
 

+ 0 - 25
components/lcd/luat_lcd_st7735s.c

@@ -12,28 +12,6 @@
 #define LCD_H 160
 #define LCD_DIRECTION 0
 
-static int st7735s_sleep(luat_lcd_conf_t* conf) {
-	if (conf->pin_pwr != 255)
-    	luat_gpio_set(conf->pin_pwr, Luat_GPIO_LOW);
-    luat_timer_mdelay(5);
-    lcd_write_cmd(conf,0x10);
-    return 0;
-}
-
-static int st7735s_wakeup(luat_lcd_conf_t* conf) {
-	if (conf->pin_pwr != 255)
-    	luat_gpio_set(conf->pin_pwr, Luat_GPIO_HIGH);
-    luat_timer_mdelay(5);
-    lcd_write_cmd(conf,0x11);
-    //luat_timer_mdelay(120); // 外部休眠就好了吧
-    return 0;
-}
-
-static int st7735s_close(luat_lcd_conf_t* conf) {
-	if (conf->pin_pwr != 255)
-    	luat_gpio_set(conf->pin_pwr, Luat_GPIO_LOW);
-    return 0;
-}
 static int st7735s_init(luat_lcd_conf_t* conf) {
     if (conf->w == 0) {
         conf->w = LCD_W;
@@ -158,8 +136,5 @@ static int st7735s_init(luat_lcd_conf_t* conf) {
 const luat_lcd_opts_t lcd_opts_st7735s = {
     .name = "st7735s",
     .init = st7735s_init,
-    .close = st7735s_close,
-    .sleep = st7735s_sleep,
-    .wakeup = st7735s_wakeup,
 };
 

+ 0 - 25
components/lcd/luat_lcd_st7735v.c

@@ -12,28 +12,6 @@
 #define LCD_H 160
 #define LCD_DIRECTION 0
 
-static int st7735v_sleep(luat_lcd_conf_t* conf) {
-    if (conf->pin_pwr != 255)
-        luat_gpio_set(conf->pin_pwr, Luat_GPIO_LOW);
-    luat_timer_mdelay(5);
-    lcd_write_cmd(conf,0x10);
-    return 0;
-}
-
-static int st7735v_wakeup(luat_lcd_conf_t* conf) {
-    if (conf->pin_pwr != 255)
-        luat_gpio_set(conf->pin_pwr, Luat_GPIO_HIGH);
-    luat_timer_mdelay(5);
-    lcd_write_cmd(conf,0x11);
-    //luat_timer_mdelay(120); // 外部休眠就好了吧
-    return 0;
-}
-
-static int st7735v_close(luat_lcd_conf_t* conf) {
-    if (conf->pin_pwr != 255)
-        luat_gpio_set(conf->pin_pwr, Luat_GPIO_LOW);
-    return 0;
-}
 static int st7735v_init(luat_lcd_conf_t* conf) {
     if (conf->w == 0)
         conf->w = LCD_W;
@@ -167,8 +145,5 @@ static int st7735v_init(luat_lcd_conf_t* conf) {
 const luat_lcd_opts_t lcd_opts_st7735v = {
     .name = "st7735v",
     .init = st7735v_init,
-    .close = st7735v_close,
-    .sleep = st7735v_sleep,
-    .wakeup = st7735v_wakeup,
 };
 

+ 0 - 28
components/lcd/luat_lcd_st7789.c

@@ -12,32 +12,7 @@
 #define LCD_H 320
 #define LCD_DIRECTION 0
 
-static int st7789_sleep(luat_lcd_conf_t* conf) {
-    if (conf->pin_pwr != 255)
-        luat_gpio_set(conf->pin_pwr, Luat_GPIO_LOW);
-    luat_timer_mdelay(5);
-    lcd_write_cmd(conf,0x10);
-    return 0;
-}
-
-static int st7789_wakeup(luat_lcd_conf_t* conf) {
-    if (conf->pin_pwr != 255)
-        luat_gpio_set(conf->pin_pwr, Luat_GPIO_HIGH);
-    luat_timer_mdelay(5);
-    lcd_write_cmd(conf,0x11);
-    //luat_timer_mdelay(120); // 外部休眠就好了吧
-    return 0;
-}
-
-static int st7789_close(luat_lcd_conf_t* conf) {
-    if (conf->pin_pwr != 255)
-        luat_gpio_set(conf->pin_pwr, Luat_GPIO_LOW);
-    return 0;
-}
-
-
 static int st7789_init(luat_lcd_conf_t* conf) {
-
     if (conf->w == 0)
         conf->w = LCD_W;
     if (conf->h == 0)
@@ -146,8 +121,5 @@ static int st7789_init(luat_lcd_conf_t* conf) {
 const luat_lcd_opts_t lcd_opts_st7789 = {
     .name = "st7789",
     .init = st7789_init,
-    .close = st7789_close,
-    .sleep = st7789_sleep,
-    .wakeup = st7789_wakeup,
 };
 

+ 0 - 11
components/lcd/luat_lib_lcd.c

@@ -188,17 +188,6 @@ static int l_lcd_init(lua_State* L) {
         if (s_index == 0){
             luat_lcd_custom_t *cst = luat_heap_malloc(sizeof(luat_lcd_custom_t));
 
-            // 获取initcmd/sleepcmd/wakecmd
-            lua_pushstring(L, "sleepcmd");
-            lua_gettable(L, 2);
-            cst->sleepcmd = luaL_checkinteger(L, -1);
-            lua_pop(L, 1);
-
-            lua_pushstring(L, "wakecmd");
-            lua_gettable(L, 2);
-            cst->wakecmd = luaL_checkinteger(L, -1);
-            lua_pop(L, 1);
-
             lua_pushstring(L, "initcmd");
             lua_gettable(L, 2);
             cst->init_cmd_count = lua_rawlen(L, -1);