Jelajahi Sumber

add:lcd draw

Dozingfiretruck 4 tahun lalu
induk
melakukan
03b69c44d1

+ 73 - 118
components/lcd/luat_lcd_custom.c

@@ -1,118 +1,73 @@
-#include "luat_base.h"
-#include "luat_lcd.h"
-#include "luat_gpio.h"
-#include "luat_spi.h"
-#include "luat_malloc.h"
-#include "luat_timer.h"
-
-#define LUAT_LOG_TAG "custom"
-#include "luat_log.h"
-
-#define LCD_W 240
-#define LCD_H 320
-#define LCD_DIRECTION 0
-
-static int custom_sleep(luat_lcd_conf_t* conf) {
-    luat_gpio_set(conf->pin_pwr, Luat_GPIO_LOW);
-    luat_timer_mdelay(5);
-    luat_lcd_custom_t * cst = (luat_lcd_custom_t *)conf->userdata;
-    luat_lcd_execute_cmds(conf, &cst->sleepcmd, 1);
-    return 0;
-}
-
-static int custom_wakeup(luat_lcd_conf_t* conf) {
-    luat_gpio_set(conf->pin_pwr, Luat_GPIO_HIGH);
-    luat_timer_mdelay(5);
-    luat_lcd_custom_t * cst = (luat_lcd_custom_t *)conf->userdata;
-    luat_lcd_execute_cmds(conf, &cst->wakecmd, 1);
-    return 0;
-}
-
-static int custom_close(luat_lcd_conf_t* conf) {
-    luat_gpio_set(conf->pin_pwr, Luat_GPIO_LOW);
-    return 0;
-}
-
-static int custom_init(luat_lcd_conf_t* conf) {
-
-    if (conf->w == 0 || conf->h == 0)
-        conf->h = LCD_H;
-    if (conf->direction == 0)
-        conf->direction = LCD_DIRECTION;
-    luat_gpio_mode(conf->pin_dc, Luat_GPIO_OUTPUT, Luat_GPIO_DEFAULT, Luat_GPIO_HIGH); // DC
-    luat_gpio_mode(conf->pin_pwr, Luat_GPIO_OUTPUT, Luat_GPIO_DEFAULT, Luat_GPIO_LOW); // POWER
-    luat_gpio_mode(conf->pin_rst, Luat_GPIO_OUTPUT, Luat_GPIO_DEFAULT, Luat_GPIO_LOW); // RST
-
-    luat_gpio_set(conf->pin_pwr, Luat_GPIO_LOW);
-    luat_gpio_set(conf->pin_rst, Luat_GPIO_LOW);
-    luat_timer_mdelay(100);
-    luat_gpio_set(conf->pin_rst, Luat_GPIO_HIGH);
-    
-    // 发送初始化命令
-    luat_lcd_custom_t * cst = (luat_lcd_custom_t *)conf->userdata;
-    luat_lcd_execute_cmds(conf, cst->initcmd, cst->init_cmd_count);
-    return 0;
-};
-
-// TODO 这里的color是ARGB, 需要转为lcd所需要的格式
-static int custom_draw(luat_lcd_conf_t* conf, uint16_t x_start, uint16_t y_start, uint16_t x_end, uint16_t y_end, luat_color_t* color) {
-    uint16_t i = 0, j = 0;
-    uint32_t size = 0, size_remain = 0;
-    uint8_t *fill_buf = NULL;
-    size = (x_end - x_start+1) * (y_end - y_start+1) * 2;
-    if (size > conf->w*conf->h/10)
-    {
-        /* the number of remaining to be filled */
-        size_remain = size - conf->w*conf->h/10;
-        size = conf->w*conf->h/10;
-    }
-    luat_lcd_set_address(conf,x_start, y_start, x_end, y_end);
-    fill_buf = (uint8_t *)luat_heap_malloc(size);
-    if (fill_buf)
-    {
-        /* fast fill */
-        while (1)
-        {
-            for (i = 0; i < size / 2; i++)
-            {
-                fill_buf[2 * i] = color[i]>>8;
-                //color >> 8;
-                fill_buf[2 * i + 1] = color[i];
-            }
-            luat_gpio_set(conf->pin_dc, Luat_GPIO_HIGH);
-            luat_spi_send(conf->port, fill_buf, size);
-            /* Fill completed */
-            if (size_remain == 0)
-                break;
-            /* calculate the number of fill next time */
-            if (size_remain > conf->w*conf->h/10)
-            {
-                size_remain = size_remain - conf->w*conf->h/10;
-            }
-            else
-            {
-                size = size_remain;
-                size_remain = 0;
-            }
-        }
-        luat_heap_free(fill_buf);
-    }
-    else
-    {
-        for (i = y_start; i <= y_end; i++)
-        {
-            for (j = x_start; j <= x_end; j++)lcd_write_half_word(conf,color[i]);
-        }
-    }
-    return 0;
-}
-
-const luat_lcd_opts_t lcd_opts_custom = {
-    .name = "custom",
-    .init = custom_init,
-    .close = custom_close,
-    .draw = custom_draw,
-    .sleep = custom_sleep,
-    .wakeup = custom_wakeup,
-};
-
+#include "luat_base.h"
+#include "luat_lcd.h"
+#include "luat_gpio.h"
+#include "luat_spi.h"
+#include "luat_malloc.h"
+#include "luat_timer.h"
+
+#define LUAT_LOG_TAG "custom"
+#include "luat_log.h"
+
+#define LCD_W 240
+#define LCD_H 320
+#define LCD_DIRECTION 0
+
+static int custom_sleep(luat_lcd_conf_t* conf) {
+    luat_gpio_set(conf->pin_pwr, Luat_GPIO_LOW);
+    luat_timer_mdelay(5);
+    luat_lcd_custom_t * cst = (luat_lcd_custom_t *)conf->userdata;
+    luat_lcd_execute_cmds(conf, &cst->sleepcmd, 1);
+    return 0;
+}
+
+static int custom_wakeup(luat_lcd_conf_t* conf) {
+    luat_gpio_set(conf->pin_pwr, Luat_GPIO_HIGH);
+    luat_timer_mdelay(5);
+    luat_lcd_custom_t * cst = (luat_lcd_custom_t *)conf->userdata;
+    luat_lcd_execute_cmds(conf, &cst->wakecmd, 1);
+    return 0;
+}
+
+static int custom_close(luat_lcd_conf_t* conf) {
+    luat_gpio_set(conf->pin_pwr, Luat_GPIO_LOW);
+    return 0;
+}
+
+static int custom_init(luat_lcd_conf_t* conf) {
+
+    if (conf->w == 0 || conf->h == 0)
+        conf->h = LCD_H;
+    if (conf->direction == 0)
+        conf->direction = LCD_DIRECTION;
+    luat_gpio_mode(conf->pin_dc, Luat_GPIO_OUTPUT, Luat_GPIO_DEFAULT, Luat_GPIO_HIGH); // DC
+    luat_gpio_mode(conf->pin_pwr, Luat_GPIO_OUTPUT, Luat_GPIO_DEFAULT, Luat_GPIO_LOW); // POWER
+    luat_gpio_mode(conf->pin_rst, Luat_GPIO_OUTPUT, Luat_GPIO_DEFAULT, Luat_GPIO_LOW); // RST
+
+    luat_gpio_set(conf->pin_pwr, Luat_GPIO_LOW);
+    luat_gpio_set(conf->pin_rst, Luat_GPIO_LOW);
+    luat_timer_mdelay(100);
+    luat_gpio_set(conf->pin_rst, Luat_GPIO_HIGH);
+    
+    // 发送初始化命令
+    luat_lcd_custom_t * cst = (luat_lcd_custom_t *)conf->userdata;
+    luat_lcd_execute_cmds(conf, cst->initcmd, cst->init_cmd_count);
+    return 0;
+};
+
+static int custom_draw(luat_lcd_conf_t* conf, uint16_t x_start, uint16_t y_start, uint16_t x_end, uint16_t y_end, luat_color_t* color) {
+    uint32_t size = size = (x_end - x_start+1) * (y_end - y_start+1) * 2;
+    luat_lcd_set_address(conf,x_start, y_start, x_end, y_end);
+    luat_gpio_set(conf->pin_dc, Luat_GPIO_HIGH);
+    luat_spi_send(conf->port, color, size);
+    return 0;
+}
+
+const luat_lcd_opts_t lcd_opts_custom = {
+    .name = "custom",
+    .init = custom_init,
+    .close = custom_close,
+    .draw = custom_draw,
+    .sleep = custom_sleep,
+    .wakeup = custom_wakeup,
+};
+

+ 138 - 184
components/lcd/luat_lcd_gc9106l.c

@@ -1,184 +1,138 @@
-#include "luat_base.h"
-#include "luat_lcd.h"
-#include "luat_gpio.h"
-#include "luat_spi.h"
-#include "luat_malloc.h"
-#include "luat_timer.h"
-
-#define LUAT_LOG_TAG "gc9106l"
-#include "luat_log.h"
-
-#define LCD_W 128
-#define LCD_H 160
-#define LCD_DIRECTION 0
-
-static int gc9106l_sleep(luat_lcd_conf_t* conf) {
-    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) {
-    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) {
-    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;
-    if (conf->h == 0)
-        conf->h = LCD_H;
-    if (conf->direction == 0)
-        conf->direction = LCD_DIRECTION;
-
-    // 配置CS脚的GPIO
-    luat_gpio_mode(conf->pin_cs, Luat_GPIO_OUTPUT, Luat_GPIO_PULLUP, 0);
-    luat_gpio_mode(conf->pin_dc, Luat_GPIO_OUTPUT, Luat_GPIO_PULLUP, 0); // DC
-    luat_gpio_mode(conf->pin_pwr, Luat_GPIO_OUTPUT, Luat_GPIO_PULLUP, 0); // POWER
-    luat_gpio_mode(conf->pin_rst, Luat_GPIO_OUTPUT, Luat_GPIO_PULLUP, 0); // RST
-
-    luat_gpio_mode(conf->pin_dc, Luat_GPIO_OUTPUT, Luat_GPIO_DEFAULT, Luat_GPIO_HIGH); // DC
-    luat_gpio_mode(conf->pin_pwr, Luat_GPIO_OUTPUT, Luat_GPIO_DEFAULT, Luat_GPIO_LOW); // POWER
-    luat_gpio_mode(conf->pin_rst, Luat_GPIO_OUTPUT, Luat_GPIO_DEFAULT, Luat_GPIO_LOW); // RST
-
-    luat_gpio_set(conf->pin_pwr, Luat_GPIO_LOW);
-    luat_gpio_set(conf->pin_rst, Luat_GPIO_LOW);
-    luat_timer_mdelay(100);
-    luat_gpio_set(conf->pin_rst, Luat_GPIO_HIGH);
-
-    // 发送初始化命令
-    //------------------------------------gc9106lS Frame Rate-----------------------------------------//
-    lcd_write_cmd(conf,0xFE);
-    lcd_write_cmd(conf,0xEF);
-    lcd_write_cmd(conf,0xB3);
-    lcd_write_data(conf,0x03);
-
-    lcd_write_cmd(conf,0x21);
-    lcd_write_cmd(conf,0x36);
-    if(conf->direction==0)lcd_write_data(conf,0x08);
-    else if(conf->direction==1)lcd_write_data(conf,0xC8);
-    else if(conf->direction==2)lcd_write_data(conf,0x68);
-    else lcd_write_data(conf,0xA8);
-
-    lcd_write_cmd(conf,0x3A);
-    lcd_write_data(conf,0x05);
-    lcd_write_cmd(conf,0xB4);
-    lcd_write_data(conf,0x21);
-
-    lcd_write_cmd(conf,0xF0);
-    lcd_write_data(conf,0x2D);
-    lcd_write_data(conf,0x54);
-    lcd_write_data(conf,0x24);
-    lcd_write_data(conf,0x61);
-    lcd_write_data(conf,0xAB);
-	lcd_write_data(conf,0x2E);
-    lcd_write_data(conf,0x2F);
-    lcd_write_data(conf,0x00);
-    lcd_write_data(conf,0x20);
-    lcd_write_data(conf,0x10);
-    lcd_write_data(conf,0X10);
-    lcd_write_data(conf,0x17);
-    lcd_write_data(conf,0x13);
-    lcd_write_data(conf,0x0F);
-
-    lcd_write_cmd(conf,0xF1);
-    lcd_write_data(conf,0x02);
-    lcd_write_data(conf,0x22);
-    lcd_write_data(conf,0x25);
-    lcd_write_data(conf,0x35);
-    lcd_write_data(conf,0xA8);
-	lcd_write_data(conf,0x08);
-    lcd_write_data(conf,0x08);
-    lcd_write_data(conf,0x00);
-    lcd_write_data(conf,0x00);
-    lcd_write_data(conf,0x09);
-    lcd_write_data(conf,0X09);
-    lcd_write_data(conf,0x17);
-    lcd_write_data(conf,0x18);
-    lcd_write_data(conf,0x0F);
-
-    lcd_write_cmd(conf,0xFE);
-    lcd_write_cmd(conf,0xFF);
-
-    /* Sleep Out */
-    lcd_write_cmd(conf,0x11);
-    /* wait for power stability */
-    luat_timer_mdelay(100);
-    luat_lcd_clear(conf,WHITE);
-    /* display on */
-    luat_lcd_display_on(conf);
-    return 0;
-};
-
-// TODO 这里的color是ARGB, 需要转为lcd所需要的格式
-static int gc9106l_draw(luat_lcd_conf_t* conf, uint16_t x_start, uint16_t y_start, uint16_t x_end, uint16_t y_end, luat_color_t* color) {
-    uint16_t i = 0, j = 0;
-    uint32_t size = 0, size_remain = 0;
-    uint8_t *fill_buf = NULL;
-    size = (x_end - x_start+1) * (y_end - y_start+1) * 2;
-    if (size > conf->w*conf->h/10)
-    {
-        /* the number of remaining to be filled */
-        size_remain = size - conf->w*conf->h/10;
-        size = conf->w*conf->h/10;
-    }
-    luat_lcd_set_address(conf,x_start, y_start, x_end, y_end);
-    fill_buf = (uint8_t *)luat_heap_malloc(size);
-    if (fill_buf)
-    {
-        /* fast fill */
-        while (1)
-        {
-            for (i = 0; i < size / 2; i++)
-            {
-                fill_buf[2 * i] = color[i]>>8;
-                //color >> 8;
-                fill_buf[2 * i + 1] = color[i];
-            }
-            luat_gpio_set(conf->pin_dc, Luat_GPIO_HIGH);
-            luat_spi_send(conf->port, fill_buf, size);
-            /* Fill completed */
-            if (size_remain == 0)
-                break;
-            /* calculate the number of fill next time */
-            if (size_remain > conf->w*conf->h/10)
-            {
-                size_remain = size_remain - conf->w*conf->h/10;
-            }
-            else
-            {
-                size = size_remain;
-                size_remain = 0;
-            }
-        }
-        luat_heap_free(fill_buf);
-    }
-    else
-    {
-        for (i = y_start; i <= y_end; i++)
-        {
-            for (j = x_start; j <= x_end; j++)lcd_write_half_word(conf,color[i]);
-        }
-    }
-    return 0;
-}
-
-
-
-const luat_lcd_opts_t lcd_opts_gc9106l = {
-    .name = "gc9106l",
-    .init = gc9106l_init,
-    .close = gc9106l_close,
-    .draw = gc9106l_draw,
-    .sleep = gc9106l_sleep,
-    .wakeup = gc9106l_wakeup,
-};
-
+#include "luat_base.h"
+#include "luat_lcd.h"
+#include "luat_gpio.h"
+#include "luat_spi.h"
+#include "luat_malloc.h"
+#include "luat_timer.h"
+
+#define LUAT_LOG_TAG "gc9106l"
+#include "luat_log.h"
+
+#define LCD_W 128
+#define LCD_H 160
+#define LCD_DIRECTION 0
+
+static int gc9106l_sleep(luat_lcd_conf_t* conf) {
+    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) {
+    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) {
+    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;
+    if (conf->h == 0)
+        conf->h = LCD_H;
+    if (conf->direction == 0)
+        conf->direction = LCD_DIRECTION;
+
+    // 配置CS脚的GPIO
+    luat_gpio_mode(conf->pin_cs, Luat_GPIO_OUTPUT, Luat_GPIO_PULLUP, 0);
+    luat_gpio_mode(conf->pin_dc, Luat_GPIO_OUTPUT, Luat_GPIO_PULLUP, 0); // DC
+    luat_gpio_mode(conf->pin_pwr, Luat_GPIO_OUTPUT, Luat_GPIO_PULLUP, 0); // POWER
+    luat_gpio_mode(conf->pin_rst, Luat_GPIO_OUTPUT, Luat_GPIO_PULLUP, 0); // RST
+
+    luat_gpio_mode(conf->pin_dc, Luat_GPIO_OUTPUT, Luat_GPIO_DEFAULT, Luat_GPIO_HIGH); // DC
+    luat_gpio_mode(conf->pin_pwr, Luat_GPIO_OUTPUT, Luat_GPIO_DEFAULT, Luat_GPIO_LOW); // POWER
+    luat_gpio_mode(conf->pin_rst, Luat_GPIO_OUTPUT, Luat_GPIO_DEFAULT, Luat_GPIO_LOW); // RST
+
+    luat_gpio_set(conf->pin_pwr, Luat_GPIO_LOW);
+    luat_gpio_set(conf->pin_rst, Luat_GPIO_LOW);
+    luat_timer_mdelay(100);
+    luat_gpio_set(conf->pin_rst, Luat_GPIO_HIGH);
+
+    // 发送初始化命令
+    //------------------------------------gc9106lS Frame Rate-----------------------------------------//
+    lcd_write_cmd(conf,0xFE);
+    lcd_write_cmd(conf,0xEF);
+    lcd_write_cmd(conf,0xB3);
+    lcd_write_data(conf,0x03);
+
+    lcd_write_cmd(conf,0x21);
+    lcd_write_cmd(conf,0x36);
+    if(conf->direction==0)lcd_write_data(conf,0x08);
+    else if(conf->direction==1)lcd_write_data(conf,0xC8);
+    else if(conf->direction==2)lcd_write_data(conf,0x68);
+    else lcd_write_data(conf,0xA8);
+
+    lcd_write_cmd(conf,0x3A);
+    lcd_write_data(conf,0x05);
+    lcd_write_cmd(conf,0xB4);
+    lcd_write_data(conf,0x21);
+
+    lcd_write_cmd(conf,0xF0);
+    lcd_write_data(conf,0x2D);
+    lcd_write_data(conf,0x54);
+    lcd_write_data(conf,0x24);
+    lcd_write_data(conf,0x61);
+    lcd_write_data(conf,0xAB);
+	lcd_write_data(conf,0x2E);
+    lcd_write_data(conf,0x2F);
+    lcd_write_data(conf,0x00);
+    lcd_write_data(conf,0x20);
+    lcd_write_data(conf,0x10);
+    lcd_write_data(conf,0X10);
+    lcd_write_data(conf,0x17);
+    lcd_write_data(conf,0x13);
+    lcd_write_data(conf,0x0F);
+
+    lcd_write_cmd(conf,0xF1);
+    lcd_write_data(conf,0x02);
+    lcd_write_data(conf,0x22);
+    lcd_write_data(conf,0x25);
+    lcd_write_data(conf,0x35);
+    lcd_write_data(conf,0xA8);
+	lcd_write_data(conf,0x08);
+    lcd_write_data(conf,0x08);
+    lcd_write_data(conf,0x00);
+    lcd_write_data(conf,0x00);
+    lcd_write_data(conf,0x09);
+    lcd_write_data(conf,0X09);
+    lcd_write_data(conf,0x17);
+    lcd_write_data(conf,0x18);
+    lcd_write_data(conf,0x0F);
+
+    lcd_write_cmd(conf,0xFE);
+    lcd_write_cmd(conf,0xFF);
+
+    /* Sleep Out */
+    lcd_write_cmd(conf,0x11);
+    /* wait for power stability */
+    luat_timer_mdelay(100);
+    luat_lcd_clear(conf,WHITE);
+    /* display on */
+    luat_lcd_display_on(conf);
+    return 0;
+};
+
+static int gc9106l_draw(luat_lcd_conf_t* conf, uint16_t x_start, uint16_t y_start, uint16_t x_end, uint16_t y_end, luat_color_t* color) {
+    uint32_t size = size = (x_end - x_start+1) * (y_end - y_start+1) * 2;
+    luat_lcd_set_address(conf,x_start, y_start, x_end, y_end);
+    luat_gpio_set(conf->pin_dc, Luat_GPIO_HIGH);
+    luat_spi_send(conf->port, color, size);
+    return 0;
+}
+
+
+const luat_lcd_opts_t lcd_opts_gc9106l = {
+    .name = "gc9106l",
+    .init = gc9106l_init,
+    .close = gc9106l_close,
+    .draw = gc9106l_draw,
+    .sleep = gc9106l_sleep,
+    .wakeup = gc9106l_wakeup,
+};
+

+ 205 - 252
components/lcd/luat_lcd_gc9306.c

@@ -1,252 +1,205 @@
-#include "luat_base.h"
-#include "luat_lcd.h"
-#include "luat_gpio.h"
-#include "luat_spi.h"
-#include "luat_malloc.h"
-#include "luat_timer.h"
-
-#define LUAT_LOG_TAG "gc9306"
-#include "luat_log.h"
-
-#define LCD_W 240
-#define LCD_H 320
-#define LCD_DIRECTION 0
-
-static int gc9306_sleep(luat_lcd_conf_t* conf) {
-    luat_gpio_set(conf->pin_pwr, Luat_GPIO_LOW);
-    luat_timer_mdelay(5);
-    lcd_write_cmd(conf,0x10);
-    return 0;
-}
-
-static int gc9306_wakeup(luat_lcd_conf_t* conf) {
-    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 gc9306_close(luat_lcd_conf_t* conf) {
-    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;
-    if (conf->h == 0)
-        conf->h = LCD_H;
-    if (conf->direction == 0)
-        conf->direction = LCD_DIRECTION;
-
-    // 配置CS脚的GPIO
-    luat_gpio_mode(conf->pin_cs, Luat_GPIO_OUTPUT, Luat_GPIO_PULLUP, 0);
-    luat_gpio_mode(conf->pin_dc, Luat_GPIO_OUTPUT, Luat_GPIO_PULLUP, 0); // DC
-    luat_gpio_mode(conf->pin_pwr, Luat_GPIO_OUTPUT, Luat_GPIO_PULLUP, 0); // POWER
-    luat_gpio_mode(conf->pin_rst, Luat_GPIO_OUTPUT, Luat_GPIO_PULLUP, 0); // RST
-
-    luat_gpio_mode(conf->pin_dc, Luat_GPIO_OUTPUT, Luat_GPIO_DEFAULT, Luat_GPIO_HIGH); // DC
-    luat_gpio_mode(conf->pin_pwr, Luat_GPIO_OUTPUT, Luat_GPIO_DEFAULT, Luat_GPIO_LOW); // POWER
-    luat_gpio_mode(conf->pin_rst, Luat_GPIO_OUTPUT, Luat_GPIO_DEFAULT, Luat_GPIO_LOW); // RST
-
-    luat_gpio_set(conf->pin_pwr, Luat_GPIO_LOW);
-    luat_gpio_set(conf->pin_rst, Luat_GPIO_LOW);
-    luat_timer_mdelay(100);
-    luat_gpio_set(conf->pin_rst, Luat_GPIO_HIGH);
-
-    // 发送初始化命令
-    lcd_write_cmd(conf,0xfe);
-    lcd_write_cmd(conf,0xef);
-
-    lcd_write_cmd(conf,0x36);
-    if(conf->direction==0)lcd_write_data(conf,0x48);
-    else if(conf->direction==1)lcd_write_data(conf,0xE8);
-    else if(conf->direction==2)lcd_write_data(conf,0x28);
-    else lcd_write_data(conf,0x38);
-
-    lcd_write_cmd(conf,0x3a);
-    lcd_write_data(conf,0x05);
-
-    lcd_write_cmd(conf,0xa4);
-    lcd_write_data(conf,0x44);
-    lcd_write_data(conf,0x44);
-
-    lcd_write_cmd(conf,0xa5);
-    lcd_write_data(conf,0x42);
-    lcd_write_data(conf,0x42);
-
-    lcd_write_cmd(conf,0xaa);
-    lcd_write_data(conf,0x88);
-    lcd_write_data(conf,0x88);
-
-    lcd_write_cmd(conf,0xe8);
-    lcd_write_data(conf,0x11);
-    lcd_write_data(conf,0x0b);
-
-    lcd_write_cmd(conf,0xe3);
-    lcd_write_data(conf,0x01);
-    lcd_write_data(conf,0x10);
-
-    lcd_write_cmd(conf,0xff);
-    lcd_write_data(conf,0x61);
-    lcd_write_cmd(conf,0xac);
-    lcd_write_data(conf,0x00);
-    lcd_write_cmd(conf,0xad);
-    lcd_write_data(conf,0x33);
-
-    lcd_write_cmd(conf,0xae);
-    lcd_write_data(conf,0x2b);
-
-    lcd_write_cmd(conf,0xaf);
-    lcd_write_data(conf,0x55);
-    lcd_write_cmd(conf,0xa6);
-    lcd_write_data(conf,0x2a);
-    lcd_write_data(conf,0x2a);
-
-    lcd_write_cmd(conf,0xa7);
-    lcd_write_data(conf,0x2b);
-    lcd_write_data(conf,0x2b);
-
-    lcd_write_cmd(conf,0xa8);
-    lcd_write_data(conf,0x18);
-    lcd_write_data(conf,0x18);
-
-    lcd_write_cmd(conf,0xa9);
-    lcd_write_data(conf,0x2a);
-    lcd_write_data(conf,0x2a);
-
-    lcd_write_cmd(conf,0x2a);
-    lcd_write_data(conf,0x00);
-    lcd_write_data(conf,0x00);
-    lcd_write_data(conf,0x00);
-    lcd_write_data(conf,0xef);
-    lcd_write_cmd(conf,0x2b);
-    lcd_write_data(conf,0x00);
-    lcd_write_data(conf,0x00);
-    lcd_write_data(conf,0x01);
-    lcd_write_data(conf,0x3f);
-    lcd_write_cmd(conf,0x2c);
-
-    lcd_write_cmd(conf,0xF0);
-    lcd_write_data(conf,0x02);
-    lcd_write_data(conf,0x01);
-    lcd_write_data(conf,0x00);
-    lcd_write_data(conf,0x06);
-    lcd_write_data(conf,0x09);
-    lcd_write_data(conf,0x0c);
-
-    lcd_write_cmd(conf,0xF1);
-    lcd_write_data(conf,0x01);
-    lcd_write_data(conf,0x03);
-    lcd_write_data(conf,0x00);
-    lcd_write_data(conf,0x3a);
-    lcd_write_data(conf,0x3e);
-    lcd_write_data(conf,0x09);
-
-    lcd_write_cmd(conf,0xF2);
-    lcd_write_data(conf,0x0c);
-    lcd_write_data(conf,0x09);
-    lcd_write_data(conf,0x26);
-    lcd_write_data(conf,0x07);
-    lcd_write_data(conf,0x07);
-    lcd_write_data(conf,0x30);
-
-    lcd_write_cmd(conf,0xF3);
-    lcd_write_data(conf,0x09);
-    lcd_write_data(conf,0x06);
-    lcd_write_data(conf,0x57);
-    lcd_write_data(conf,0x03);
-    lcd_write_data(conf,0x03);
-    lcd_write_data(conf,0x6b);
-
-    lcd_write_cmd(conf,0xF4);
-    lcd_write_data(conf,0x0d);
-    lcd_write_data(conf,0x1d);
-    lcd_write_data(conf,0x1c);
-    lcd_write_data(conf,0x06);
-    lcd_write_data(conf,0x08);
-    lcd_write_data(conf,0x0F);
-
-    lcd_write_cmd(conf,0xF5);
-    lcd_write_data(conf,0x0c);
-    lcd_write_data(conf,0x05);
-    lcd_write_data(conf,0x06);
-    lcd_write_data(conf,0x33);
-    lcd_write_data(conf,0x31);
-    lcd_write_data(conf,0x0F);
-
-    /* Sleep Out */
-    lcd_write_cmd(conf,0x11);
-    /* wait for power stability */
-    luat_timer_mdelay(100);
-    luat_lcd_clear(conf,WHITE);
-    /* display on */
-    luat_lcd_display_on(conf);
-    lcd_write_cmd(conf,0x2c);
-    return 0;
-};
-
-// TODO 这里的color是ARGB, 需要转为lcd所需要的格式
-static int gc9306_draw(luat_lcd_conf_t* conf, uint16_t x_start, uint16_t y_start, uint16_t x_end, uint16_t y_end, luat_color_t* color) {
-    uint16_t i = 0, j = 0;
-    uint32_t size = 0, size_remain = 0;
-    uint8_t *fill_buf = NULL;
-    size = (x_end - x_start+1) * (y_end - y_start+1) * 2;
-    if (size > conf->w*conf->h/10)
-    {
-        /* the number of remaining to be filled */
-        size_remain = size - conf->w*conf->h/10;
-        size = conf->w*conf->h/10;
-    }
-    luat_lcd_set_address(conf,x_start, y_start, x_end, y_end);
-    fill_buf = (uint8_t *)luat_heap_malloc(size);
-    if (fill_buf)
-    {
-        /* fast fill */
-        while (1)
-        {
-            for (i = 0; i < size / 2; i++)
-            {
-                fill_buf[2 * i] = color[i]>>8;
-                //color >> 8;
-                fill_buf[2 * i + 1] = color[i];
-            }
-            luat_gpio_set(conf->pin_dc, Luat_GPIO_HIGH);
-            luat_spi_send(conf->port, fill_buf, size);
-            /* Fill completed */
-            if (size_remain == 0)
-                break;
-            /* calculate the number of fill next time */
-            if (size_remain > conf->w*conf->h/10)
-            {
-                size_remain = size_remain - conf->w*conf->h/10;
-            }
-            else
-            {
-                size = size_remain;
-                size_remain = 0;
-            }
-        }
-        luat_heap_free(fill_buf);
-    }
-    else
-    {
-        for (i = y_start; i <= y_end; i++)
-        {
-            for (j = x_start; j <= x_end; j++)lcd_write_half_word(conf,color[i]);
-        }
-    }
-    return 0;
-}
-
-
-
-const luat_lcd_opts_t lcd_opts_gc9306 = {
-    .name = "gc9306",
-    .init = gc9306_init,
-    .close = gc9306_close,
-    .draw = gc9306_draw,
-    .sleep = gc9306_sleep,
-    .wakeup = gc9306_wakeup,
-};
-
+#include "luat_base.h"
+#include "luat_lcd.h"
+#include "luat_gpio.h"
+#include "luat_spi.h"
+#include "luat_malloc.h"
+#include "luat_timer.h"
+
+#define LUAT_LOG_TAG "gc9306"
+#include "luat_log.h"
+
+#define LCD_W 240
+#define LCD_H 320
+#define LCD_DIRECTION 0
+
+static int gc9306_sleep(luat_lcd_conf_t* conf) {
+    luat_gpio_set(conf->pin_pwr, Luat_GPIO_LOW);
+    luat_timer_mdelay(5);
+    lcd_write_cmd(conf,0x10);
+    return 0;
+}
+
+static int gc9306_wakeup(luat_lcd_conf_t* conf) {
+    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 gc9306_close(luat_lcd_conf_t* conf) {
+    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;
+    if (conf->h == 0)
+        conf->h = LCD_H;
+    if (conf->direction == 0)
+        conf->direction = LCD_DIRECTION;
+
+    // 配置CS脚的GPIO
+    luat_gpio_mode(conf->pin_cs, Luat_GPIO_OUTPUT, Luat_GPIO_PULLUP, 0);
+    luat_gpio_mode(conf->pin_dc, Luat_GPIO_OUTPUT, Luat_GPIO_PULLUP, 0); // DC
+    luat_gpio_mode(conf->pin_pwr, Luat_GPIO_OUTPUT, Luat_GPIO_PULLUP, 0); // POWER
+    luat_gpio_mode(conf->pin_rst, Luat_GPIO_OUTPUT, Luat_GPIO_PULLUP, 0); // RST
+
+    luat_gpio_mode(conf->pin_dc, Luat_GPIO_OUTPUT, Luat_GPIO_DEFAULT, Luat_GPIO_HIGH); // DC
+    luat_gpio_mode(conf->pin_pwr, Luat_GPIO_OUTPUT, Luat_GPIO_DEFAULT, Luat_GPIO_LOW); // POWER
+    luat_gpio_mode(conf->pin_rst, Luat_GPIO_OUTPUT, Luat_GPIO_DEFAULT, Luat_GPIO_LOW); // RST
+
+    luat_gpio_set(conf->pin_pwr, Luat_GPIO_LOW);
+    luat_gpio_set(conf->pin_rst, Luat_GPIO_LOW);
+    luat_timer_mdelay(100);
+    luat_gpio_set(conf->pin_rst, Luat_GPIO_HIGH);
+
+    // 发送初始化命令
+    lcd_write_cmd(conf,0xfe);
+    lcd_write_cmd(conf,0xef);
+
+    lcd_write_cmd(conf,0x36);
+    if(conf->direction==0)lcd_write_data(conf,0x48);
+    else if(conf->direction==1)lcd_write_data(conf,0xE8);
+    else if(conf->direction==2)lcd_write_data(conf,0x28);
+    else lcd_write_data(conf,0x38);
+
+    lcd_write_cmd(conf,0x3a);
+    lcd_write_data(conf,0x05);
+
+    lcd_write_cmd(conf,0xa4);
+    lcd_write_data(conf,0x44);
+    lcd_write_data(conf,0x44);
+
+    lcd_write_cmd(conf,0xa5);
+    lcd_write_data(conf,0x42);
+    lcd_write_data(conf,0x42);
+
+    lcd_write_cmd(conf,0xaa);
+    lcd_write_data(conf,0x88);
+    lcd_write_data(conf,0x88);
+
+    lcd_write_cmd(conf,0xe8);
+    lcd_write_data(conf,0x11);
+    lcd_write_data(conf,0x0b);
+
+    lcd_write_cmd(conf,0xe3);
+    lcd_write_data(conf,0x01);
+    lcd_write_data(conf,0x10);
+
+    lcd_write_cmd(conf,0xff);
+    lcd_write_data(conf,0x61);
+    lcd_write_cmd(conf,0xac);
+    lcd_write_data(conf,0x00);
+    lcd_write_cmd(conf,0xad);
+    lcd_write_data(conf,0x33);
+
+    lcd_write_cmd(conf,0xae);
+    lcd_write_data(conf,0x2b);
+
+    lcd_write_cmd(conf,0xaf);
+    lcd_write_data(conf,0x55);
+    lcd_write_cmd(conf,0xa6);
+    lcd_write_data(conf,0x2a);
+    lcd_write_data(conf,0x2a);
+
+    lcd_write_cmd(conf,0xa7);
+    lcd_write_data(conf,0x2b);
+    lcd_write_data(conf,0x2b);
+
+    lcd_write_cmd(conf,0xa8);
+    lcd_write_data(conf,0x18);
+    lcd_write_data(conf,0x18);
+
+    lcd_write_cmd(conf,0xa9);
+    lcd_write_data(conf,0x2a);
+    lcd_write_data(conf,0x2a);
+
+    lcd_write_cmd(conf,0x2a);
+    lcd_write_data(conf,0x00);
+    lcd_write_data(conf,0x00);
+    lcd_write_data(conf,0x00);
+    lcd_write_data(conf,0xef);
+    lcd_write_cmd(conf,0x2b);
+    lcd_write_data(conf,0x00);
+    lcd_write_data(conf,0x00);
+    lcd_write_data(conf,0x01);
+    lcd_write_data(conf,0x3f);
+    lcd_write_cmd(conf,0x2c);
+
+    lcd_write_cmd(conf,0xF0);
+    lcd_write_data(conf,0x02);
+    lcd_write_data(conf,0x01);
+    lcd_write_data(conf,0x00);
+    lcd_write_data(conf,0x06);
+    lcd_write_data(conf,0x09);
+    lcd_write_data(conf,0x0c);
+
+    lcd_write_cmd(conf,0xF1);
+    lcd_write_data(conf,0x01);
+    lcd_write_data(conf,0x03);
+    lcd_write_data(conf,0x00);
+    lcd_write_data(conf,0x3a);
+    lcd_write_data(conf,0x3e);
+    lcd_write_data(conf,0x09);
+
+    lcd_write_cmd(conf,0xF2);
+    lcd_write_data(conf,0x0c);
+    lcd_write_data(conf,0x09);
+    lcd_write_data(conf,0x26);
+    lcd_write_data(conf,0x07);
+    lcd_write_data(conf,0x07);
+    lcd_write_data(conf,0x30);
+
+    lcd_write_cmd(conf,0xF3);
+    lcd_write_data(conf,0x09);
+    lcd_write_data(conf,0x06);
+    lcd_write_data(conf,0x57);
+    lcd_write_data(conf,0x03);
+    lcd_write_data(conf,0x03);
+    lcd_write_data(conf,0x6b);
+
+    lcd_write_cmd(conf,0xF4);
+    lcd_write_data(conf,0x0d);
+    lcd_write_data(conf,0x1d);
+    lcd_write_data(conf,0x1c);
+    lcd_write_data(conf,0x06);
+    lcd_write_data(conf,0x08);
+    lcd_write_data(conf,0x0F);
+
+    lcd_write_cmd(conf,0xF5);
+    lcd_write_data(conf,0x0c);
+    lcd_write_data(conf,0x05);
+    lcd_write_data(conf,0x06);
+    lcd_write_data(conf,0x33);
+    lcd_write_data(conf,0x31);
+    lcd_write_data(conf,0x0F);
+
+    /* Sleep Out */
+    lcd_write_cmd(conf,0x11);
+    /* wait for power stability */
+    luat_timer_mdelay(100);
+    luat_lcd_clear(conf,WHITE);
+    /* display on */
+    luat_lcd_display_on(conf);
+    lcd_write_cmd(conf,0x2c);
+    return 0;
+};
+
+static int gc9306_draw(luat_lcd_conf_t* conf, uint16_t x_start, uint16_t y_start, uint16_t x_end, uint16_t y_end, luat_color_t* color) {
+    uint32_t size = size = (x_end - x_start+1) * (y_end - y_start+1) * 2;
+    luat_lcd_set_address(conf,x_start, y_start, x_end, y_end);
+    luat_gpio_set(conf->pin_dc, Luat_GPIO_HIGH);
+    luat_spi_send(conf->port, color, size);
+    return 0;
+}
+
+const luat_lcd_opts_t lcd_opts_gc9306 = {
+    .name = "gc9306",
+    .init = gc9306_init,
+    .close = gc9306_close,
+    .draw = gc9306_draw,
+    .sleep = gc9306_sleep,
+    .wakeup = gc9306_wakeup,
+};
+

+ 304 - 351
components/lcd/luat_lcd_gc9a01.c

@@ -1,351 +1,304 @@
-#include "luat_base.h"
-#include "luat_lcd.h"
-#include "luat_gpio.h"
-#include "luat_spi.h"
-#include "luat_malloc.h"
-#include "luat_timer.h"
-
-#define LUAT_LOG_TAG "gc9a01"
-#include "luat_log.h"
-
-#define LCD_W 240
-#define LCD_H 240
-#define LCD_DIRECTION 0
-
-static int gc9a01_sleep(luat_lcd_conf_t* conf) {
-    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) {
-    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) {
-    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;
-    if (conf->h == 0)
-        conf->h = LCD_H;
-    if (conf->direction == 0)
-        conf->direction = LCD_DIRECTION;
-
-    // 配置CS脚的GPIO
-    luat_gpio_mode(conf->pin_cs, Luat_GPIO_OUTPUT, Luat_GPIO_PULLUP, 0);
-    luat_gpio_mode(conf->pin_dc, Luat_GPIO_OUTPUT, Luat_GPIO_PULLUP, 0); // DC
-    luat_gpio_mode(conf->pin_pwr, Luat_GPIO_OUTPUT, Luat_GPIO_PULLUP, 0); // POWER
-    luat_gpio_mode(conf->pin_rst, Luat_GPIO_OUTPUT, Luat_GPIO_PULLUP, 0); // RST
-
-    luat_gpio_mode(conf->pin_dc, Luat_GPIO_OUTPUT, Luat_GPIO_DEFAULT, Luat_GPIO_HIGH); // DC
-    luat_gpio_mode(conf->pin_pwr, Luat_GPIO_OUTPUT, Luat_GPIO_DEFAULT, Luat_GPIO_LOW); // POWER
-    luat_gpio_mode(conf->pin_rst, Luat_GPIO_OUTPUT, Luat_GPIO_DEFAULT, Luat_GPIO_LOW); // RST
-
-    luat_gpio_set(conf->pin_pwr, Luat_GPIO_LOW);
-    luat_gpio_set(conf->pin_rst, Luat_GPIO_LOW);
-    luat_timer_mdelay(100);
-    luat_gpio_set(conf->pin_rst, Luat_GPIO_HIGH);
-
-    // 发送初始化命令
-    lcd_write_cmd(conf,0xEF);
-    lcd_write_cmd(conf,0xEB);
-    lcd_write_data(conf,0x14);
-
-    lcd_write_cmd(conf,0xFE);
-    lcd_write_data(conf,0xEF);
-
-    lcd_write_cmd(conf,0xEB);
-    lcd_write_data(conf,0x14);
-
-    lcd_write_cmd(conf,0x84);
-    lcd_write_data(conf,0x40);
-
-    lcd_write_cmd(conf,0x85);
-    lcd_write_data(conf,0xFF);
-
-    lcd_write_cmd(conf,0x86);
-    lcd_write_data(conf,0xFF);
-    lcd_write_cmd(conf,0x87);
-    lcd_write_data(conf,0xFF);
-    lcd_write_cmd(conf,0x88);
-    lcd_write_data(conf,0x0A);
-
-    lcd_write_cmd(conf,0x89);
-    lcd_write_data(conf,0x21);
-
-    lcd_write_cmd(conf,0x8A);
-    lcd_write_data(conf,0x00);
-
-    lcd_write_cmd(conf,0x8B);
-    lcd_write_data(conf,0x80);
-
-    lcd_write_cmd(conf,0x8C);
-    lcd_write_data(conf,0x01);
-    lcd_write_cmd(conf,0x8D);
-    lcd_write_data(conf,0x01);
-    lcd_write_cmd(conf,0x8E);
-    lcd_write_data(conf,0xFF);
-
-    lcd_write_cmd(conf,0x8F);
-    lcd_write_data(conf,0xFF);
-
-    lcd_write_cmd(conf,0xB6);
-    lcd_write_data(conf,0x00);
-    lcd_write_data(conf,0x20);
-
-    lcd_write_cmd(conf,0x36);
-    if(conf->direction==0)lcd_write_data(conf,0x08);
-    else if(conf->direction==1)lcd_write_data(conf,0xC8);
-    else if(conf->direction==2)lcd_write_data(conf,0x68);
-    else lcd_write_data(conf,0xA8);
-
-    lcd_write_cmd(conf,0x3A);
-    lcd_write_data(conf,0x05);
-
-    lcd_write_cmd(conf,0x90);
-    lcd_write_data(conf,0x08);
-    lcd_write_data(conf,0x08);
-    lcd_write_data(conf,0x08);
-    lcd_write_data(conf,0x08);
-
-    lcd_write_cmd(conf,0xBD);
-    lcd_write_data(conf,0x06);
-    lcd_write_cmd(conf,0xBC);
-    lcd_write_data(conf,0x00);
-    lcd_write_cmd(conf,0xFF);
-    lcd_write_data(conf,0x60);
-    lcd_write_data(conf,0x01);
-    lcd_write_data(conf,0x04);
-
-    lcd_write_cmd(conf,0xC3);
-    lcd_write_data(conf,0x13);
-    lcd_write_cmd(conf,0xC4);
-    lcd_write_data(conf,0x13);
-
-    lcd_write_cmd(conf,0xC9);
-    lcd_write_data(conf,0x22);
-    lcd_write_cmd(conf,0xBE);
-    lcd_write_data(conf,0x11);
-
-    lcd_write_cmd(conf,0xE1);
-    lcd_write_data(conf,0x10);
-    lcd_write_data(conf,0x0E);
-
-    lcd_write_cmd(conf,0xDF);
-    lcd_write_data(conf,0x21);
-    lcd_write_data(conf,0x0c);
-    lcd_write_data(conf,0x02);
-
-    lcd_write_cmd(conf,0xF0);
-    lcd_write_data(conf,0x45);
-    lcd_write_data(conf,0x09);
-    lcd_write_data(conf,0x08);
-    lcd_write_data(conf,0x08);
-    lcd_write_data(conf,0x26);
-    lcd_write_data(conf,0x2A);
-
-    lcd_write_cmd(conf,0xF1);
-    lcd_write_data(conf,0x43);
-    lcd_write_data(conf,0x70);
-    lcd_write_data(conf,0x72);
-    lcd_write_data(conf,0x36);
-    lcd_write_data(conf,0x37);
-    lcd_write_data(conf,0x6F);
-
-    lcd_write_cmd(conf,0xF2);
-    lcd_write_data(conf,0x45);
-    lcd_write_data(conf,0x09);
-    lcd_write_data(conf,0x08);
-    lcd_write_data(conf,0x08);
-    lcd_write_data(conf,0x26);
-    lcd_write_data(conf,0x2A);
-
-    lcd_write_cmd(conf,0xF3);
-    lcd_write_data(conf,0x43);
-    lcd_write_data(conf,0x70);
-    lcd_write_data(conf,0x72);
-    lcd_write_data(conf,0x36);
-    lcd_write_data(conf,0x37);
-    lcd_write_data(conf,0x6F);
-
-    lcd_write_cmd(conf,0xED);
-    lcd_write_data(conf,0x1B);
-    lcd_write_data(conf,0x0B);
-    lcd_write_cmd(conf,0xAE);
-    lcd_write_data(conf,0x77);
-    lcd_write_cmd(conf,0xCD);
-    lcd_write_data(conf,0x63);
-
-    lcd_write_cmd(conf,0x70);
-    lcd_write_data(conf,0x07);
-    lcd_write_data(conf,0x07);
-    lcd_write_data(conf,0x04);
-    lcd_write_data(conf,0x0E);
-    lcd_write_data(conf,0x0F);
-    lcd_write_data(conf,0x09);
-    lcd_write_data(conf,0x07);
-    lcd_write_data(conf,0x08);
-    lcd_write_data(conf,0x03);
-
-    lcd_write_cmd(conf,0xE8);
-    lcd_write_data(conf,0x34);
-
-    lcd_write_cmd(conf,0x62);
-    lcd_write_data(conf,0x18);
-    lcd_write_data(conf,0x0D);
-    lcd_write_data(conf,0x71);
-    lcd_write_data(conf,0xED);
-    lcd_write_data(conf,0x70);
-    lcd_write_data(conf,0x70);
-    lcd_write_data(conf,0x18);
-    lcd_write_data(conf,0x0F);
-    lcd_write_data(conf,0x71);
-    lcd_write_data(conf,0xEF);
-    lcd_write_data(conf,0x70);
-    lcd_write_data(conf,0x70);
-
-    lcd_write_cmd(conf,0x63);
-    lcd_write_data(conf,0x18);
-    lcd_write_data(conf,0x11);
-    lcd_write_data(conf,0x71);
-    lcd_write_data(conf,0xF1);
-    lcd_write_data(conf,0x70);
-    lcd_write_data(conf,0x70);
-    lcd_write_data(conf,0x18);
-    lcd_write_data(conf,0x13);
-    lcd_write_data(conf,0x71);
-    lcd_write_data(conf,0xF3);
-    lcd_write_data(conf,0x70);
-    lcd_write_data(conf,0x70);
-
-    lcd_write_cmd(conf,0x64);
-    lcd_write_data(conf,0x28);
-    lcd_write_data(conf,0x29);
-    lcd_write_data(conf,0xF1);
-    lcd_write_data(conf,0x01);
-    lcd_write_data(conf,0xF1);
-    lcd_write_data(conf,0x00);
-    lcd_write_data(conf,0x07);
-
-    lcd_write_cmd(conf,0x66);
-    lcd_write_data(conf,0x3C);
-    lcd_write_data(conf,0x00);
-    lcd_write_data(conf,0xCD);
-    lcd_write_data(conf,0x67);
-    lcd_write_data(conf,0x45);
-    lcd_write_data(conf,0x45);
-    lcd_write_data(conf,0x10);
-    lcd_write_data(conf,0x00);
-    lcd_write_data(conf,0x00);
-    lcd_write_data(conf,0x00);
-
-    lcd_write_cmd(conf,0x67);
-    lcd_write_data(conf,0x00);
-    lcd_write_data(conf,0x3C);
-    lcd_write_data(conf,0x00);
-    lcd_write_data(conf,0x00);
-    lcd_write_data(conf,0x00);
-    lcd_write_data(conf,0x01);
-    lcd_write_data(conf,0x54);
-    lcd_write_data(conf,0x10);
-    lcd_write_data(conf,0x32);
-    lcd_write_data(conf,0x98);
-
-    lcd_write_cmd(conf,0x74);
-    lcd_write_data(conf,0x10);
-    lcd_write_data(conf,0x85);
-    lcd_write_data(conf,0x80);
-    lcd_write_data(conf,0x00);
-    lcd_write_data(conf,0x00);
-    lcd_write_data(conf,0x4E);
-    lcd_write_data(conf,0x00);
-
-    lcd_write_cmd(conf,0x98);
-    lcd_write_data(conf,0x3e);
-    lcd_write_data(conf,0x07);
-
-    lcd_write_cmd(conf,0x35);
-    lcd_write_data(conf,0x21);
-
-    /* Sleep Out */
-    lcd_write_cmd(conf,0x11);
-    /* wait for power stability */
-    luat_timer_mdelay(100);
-    luat_lcd_clear(conf,WHITE);
-    /* display on */
-    luat_lcd_display_on(conf);
-    return 0;
-};
-
-// TODO 这里的color是ARGB, 需要转为lcd所需要的格式
-static int gc9a01_draw(luat_lcd_conf_t* conf, uint16_t x_start, uint16_t y_start, uint16_t x_end, uint16_t y_end, luat_color_t* color) {
-    uint16_t i = 0, j = 0;
-    uint32_t size = 0, size_remain = 0;
-    uint8_t *fill_buf = NULL;
-    size = (x_end - x_start+1) * (y_end - y_start+1) * 2;
-    if (size > conf->w*conf->h/10)
-    {
-        /* the number of remaining to be filled */
-        size_remain = size - conf->w*conf->h/10;
-        size = conf->w*conf->h/10;
-    }
-    luat_lcd_set_address(conf,x_start, y_start, x_end, y_end);
-    fill_buf = (uint8_t *)luat_heap_malloc(size);
-    if (fill_buf)
-    {
-        /* fast fill */
-        while (1)
-        {
-            for (i = 0; i < size / 2; i++)
-            {
-                fill_buf[2 * i] = color[i]>>8;
-                //color >> 8;
-                fill_buf[2 * i + 1] = color[i];
-            }
-            luat_gpio_set(conf->pin_dc, Luat_GPIO_HIGH);
-            luat_spi_send(conf->port, fill_buf, size);
-            /* Fill completed */
-            if (size_remain == 0)
-                break;
-            /* calculate the number of fill next time */
-            if (size_remain > conf->w*conf->h/10)
-            {
-                size_remain = size_remain - conf->w*conf->h/10;
-            }
-            else
-            {
-                size = size_remain;
-                size_remain = 0;
-            }
-        }
-        luat_heap_free(fill_buf);
-    }
-    else
-    {
-        for (i = y_start; i <= y_end; i++)
-        {
-            for (j = x_start; j <= x_end; j++)lcd_write_half_word(conf,color[i]);
-        }
-    }
-    return 0;
-}
-
-
-
-const luat_lcd_opts_t lcd_opts_gc9a01 = {
-    .name = "gc9a01",
-    .init = gc9a01_init,
-    .close = gc9a01_close,
-    .draw = gc9a01_draw,
-    .sleep = gc9a01_sleep,
-    .wakeup = gc9a01_wakeup,
-};
-
+#include "luat_base.h"
+#include "luat_lcd.h"
+#include "luat_gpio.h"
+#include "luat_spi.h"
+#include "luat_malloc.h"
+#include "luat_timer.h"
+
+#define LUAT_LOG_TAG "gc9a01"
+#include "luat_log.h"
+
+#define LCD_W 240
+#define LCD_H 240
+#define LCD_DIRECTION 0
+
+static int gc9a01_sleep(luat_lcd_conf_t* conf) {
+    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) {
+    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) {
+    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;
+    if (conf->h == 0)
+        conf->h = LCD_H;
+    if (conf->direction == 0)
+        conf->direction = LCD_DIRECTION;
+
+    // 配置CS脚的GPIO
+    luat_gpio_mode(conf->pin_cs, Luat_GPIO_OUTPUT, Luat_GPIO_PULLUP, 0);
+    luat_gpio_mode(conf->pin_dc, Luat_GPIO_OUTPUT, Luat_GPIO_PULLUP, 0); // DC
+    luat_gpio_mode(conf->pin_pwr, Luat_GPIO_OUTPUT, Luat_GPIO_PULLUP, 0); // POWER
+    luat_gpio_mode(conf->pin_rst, Luat_GPIO_OUTPUT, Luat_GPIO_PULLUP, 0); // RST
+
+    luat_gpio_mode(conf->pin_dc, Luat_GPIO_OUTPUT, Luat_GPIO_DEFAULT, Luat_GPIO_HIGH); // DC
+    luat_gpio_mode(conf->pin_pwr, Luat_GPIO_OUTPUT, Luat_GPIO_DEFAULT, Luat_GPIO_LOW); // POWER
+    luat_gpio_mode(conf->pin_rst, Luat_GPIO_OUTPUT, Luat_GPIO_DEFAULT, Luat_GPIO_LOW); // RST
+
+    luat_gpio_set(conf->pin_pwr, Luat_GPIO_LOW);
+    luat_gpio_set(conf->pin_rst, Luat_GPIO_LOW);
+    luat_timer_mdelay(100);
+    luat_gpio_set(conf->pin_rst, Luat_GPIO_HIGH);
+
+    // 发送初始化命令
+    lcd_write_cmd(conf,0xEF);
+    lcd_write_cmd(conf,0xEB);
+    lcd_write_data(conf,0x14);
+
+    lcd_write_cmd(conf,0xFE);
+    lcd_write_data(conf,0xEF);
+
+    lcd_write_cmd(conf,0xEB);
+    lcd_write_data(conf,0x14);
+
+    lcd_write_cmd(conf,0x84);
+    lcd_write_data(conf,0x40);
+
+    lcd_write_cmd(conf,0x85);
+    lcd_write_data(conf,0xFF);
+
+    lcd_write_cmd(conf,0x86);
+    lcd_write_data(conf,0xFF);
+    lcd_write_cmd(conf,0x87);
+    lcd_write_data(conf,0xFF);
+    lcd_write_cmd(conf,0x88);
+    lcd_write_data(conf,0x0A);
+
+    lcd_write_cmd(conf,0x89);
+    lcd_write_data(conf,0x21);
+
+    lcd_write_cmd(conf,0x8A);
+    lcd_write_data(conf,0x00);
+
+    lcd_write_cmd(conf,0x8B);
+    lcd_write_data(conf,0x80);
+
+    lcd_write_cmd(conf,0x8C);
+    lcd_write_data(conf,0x01);
+    lcd_write_cmd(conf,0x8D);
+    lcd_write_data(conf,0x01);
+    lcd_write_cmd(conf,0x8E);
+    lcd_write_data(conf,0xFF);
+
+    lcd_write_cmd(conf,0x8F);
+    lcd_write_data(conf,0xFF);
+
+    lcd_write_cmd(conf,0xB6);
+    lcd_write_data(conf,0x00);
+    lcd_write_data(conf,0x20);
+
+    lcd_write_cmd(conf,0x36);
+    if(conf->direction==0)lcd_write_data(conf,0x08);
+    else if(conf->direction==1)lcd_write_data(conf,0xC8);
+    else if(conf->direction==2)lcd_write_data(conf,0x68);
+    else lcd_write_data(conf,0xA8);
+
+    lcd_write_cmd(conf,0x3A);
+    lcd_write_data(conf,0x05);
+
+    lcd_write_cmd(conf,0x90);
+    lcd_write_data(conf,0x08);
+    lcd_write_data(conf,0x08);
+    lcd_write_data(conf,0x08);
+    lcd_write_data(conf,0x08);
+
+    lcd_write_cmd(conf,0xBD);
+    lcd_write_data(conf,0x06);
+    lcd_write_cmd(conf,0xBC);
+    lcd_write_data(conf,0x00);
+    lcd_write_cmd(conf,0xFF);
+    lcd_write_data(conf,0x60);
+    lcd_write_data(conf,0x01);
+    lcd_write_data(conf,0x04);
+
+    lcd_write_cmd(conf,0xC3);
+    lcd_write_data(conf,0x13);
+    lcd_write_cmd(conf,0xC4);
+    lcd_write_data(conf,0x13);
+
+    lcd_write_cmd(conf,0xC9);
+    lcd_write_data(conf,0x22);
+    lcd_write_cmd(conf,0xBE);
+    lcd_write_data(conf,0x11);
+
+    lcd_write_cmd(conf,0xE1);
+    lcd_write_data(conf,0x10);
+    lcd_write_data(conf,0x0E);
+
+    lcd_write_cmd(conf,0xDF);
+    lcd_write_data(conf,0x21);
+    lcd_write_data(conf,0x0c);
+    lcd_write_data(conf,0x02);
+
+    lcd_write_cmd(conf,0xF0);
+    lcd_write_data(conf,0x45);
+    lcd_write_data(conf,0x09);
+    lcd_write_data(conf,0x08);
+    lcd_write_data(conf,0x08);
+    lcd_write_data(conf,0x26);
+    lcd_write_data(conf,0x2A);
+
+    lcd_write_cmd(conf,0xF1);
+    lcd_write_data(conf,0x43);
+    lcd_write_data(conf,0x70);
+    lcd_write_data(conf,0x72);
+    lcd_write_data(conf,0x36);
+    lcd_write_data(conf,0x37);
+    lcd_write_data(conf,0x6F);
+
+    lcd_write_cmd(conf,0xF2);
+    lcd_write_data(conf,0x45);
+    lcd_write_data(conf,0x09);
+    lcd_write_data(conf,0x08);
+    lcd_write_data(conf,0x08);
+    lcd_write_data(conf,0x26);
+    lcd_write_data(conf,0x2A);
+
+    lcd_write_cmd(conf,0xF3);
+    lcd_write_data(conf,0x43);
+    lcd_write_data(conf,0x70);
+    lcd_write_data(conf,0x72);
+    lcd_write_data(conf,0x36);
+    lcd_write_data(conf,0x37);
+    lcd_write_data(conf,0x6F);
+
+    lcd_write_cmd(conf,0xED);
+    lcd_write_data(conf,0x1B);
+    lcd_write_data(conf,0x0B);
+    lcd_write_cmd(conf,0xAE);
+    lcd_write_data(conf,0x77);
+    lcd_write_cmd(conf,0xCD);
+    lcd_write_data(conf,0x63);
+
+    lcd_write_cmd(conf,0x70);
+    lcd_write_data(conf,0x07);
+    lcd_write_data(conf,0x07);
+    lcd_write_data(conf,0x04);
+    lcd_write_data(conf,0x0E);
+    lcd_write_data(conf,0x0F);
+    lcd_write_data(conf,0x09);
+    lcd_write_data(conf,0x07);
+    lcd_write_data(conf,0x08);
+    lcd_write_data(conf,0x03);
+
+    lcd_write_cmd(conf,0xE8);
+    lcd_write_data(conf,0x34);
+
+    lcd_write_cmd(conf,0x62);
+    lcd_write_data(conf,0x18);
+    lcd_write_data(conf,0x0D);
+    lcd_write_data(conf,0x71);
+    lcd_write_data(conf,0xED);
+    lcd_write_data(conf,0x70);
+    lcd_write_data(conf,0x70);
+    lcd_write_data(conf,0x18);
+    lcd_write_data(conf,0x0F);
+    lcd_write_data(conf,0x71);
+    lcd_write_data(conf,0xEF);
+    lcd_write_data(conf,0x70);
+    lcd_write_data(conf,0x70);
+
+    lcd_write_cmd(conf,0x63);
+    lcd_write_data(conf,0x18);
+    lcd_write_data(conf,0x11);
+    lcd_write_data(conf,0x71);
+    lcd_write_data(conf,0xF1);
+    lcd_write_data(conf,0x70);
+    lcd_write_data(conf,0x70);
+    lcd_write_data(conf,0x18);
+    lcd_write_data(conf,0x13);
+    lcd_write_data(conf,0x71);
+    lcd_write_data(conf,0xF3);
+    lcd_write_data(conf,0x70);
+    lcd_write_data(conf,0x70);
+
+    lcd_write_cmd(conf,0x64);
+    lcd_write_data(conf,0x28);
+    lcd_write_data(conf,0x29);
+    lcd_write_data(conf,0xF1);
+    lcd_write_data(conf,0x01);
+    lcd_write_data(conf,0xF1);
+    lcd_write_data(conf,0x00);
+    lcd_write_data(conf,0x07);
+
+    lcd_write_cmd(conf,0x66);
+    lcd_write_data(conf,0x3C);
+    lcd_write_data(conf,0x00);
+    lcd_write_data(conf,0xCD);
+    lcd_write_data(conf,0x67);
+    lcd_write_data(conf,0x45);
+    lcd_write_data(conf,0x45);
+    lcd_write_data(conf,0x10);
+    lcd_write_data(conf,0x00);
+    lcd_write_data(conf,0x00);
+    lcd_write_data(conf,0x00);
+
+    lcd_write_cmd(conf,0x67);
+    lcd_write_data(conf,0x00);
+    lcd_write_data(conf,0x3C);
+    lcd_write_data(conf,0x00);
+    lcd_write_data(conf,0x00);
+    lcd_write_data(conf,0x00);
+    lcd_write_data(conf,0x01);
+    lcd_write_data(conf,0x54);
+    lcd_write_data(conf,0x10);
+    lcd_write_data(conf,0x32);
+    lcd_write_data(conf,0x98);
+
+    lcd_write_cmd(conf,0x74);
+    lcd_write_data(conf,0x10);
+    lcd_write_data(conf,0x85);
+    lcd_write_data(conf,0x80);
+    lcd_write_data(conf,0x00);
+    lcd_write_data(conf,0x00);
+    lcd_write_data(conf,0x4E);
+    lcd_write_data(conf,0x00);
+
+    lcd_write_cmd(conf,0x98);
+    lcd_write_data(conf,0x3e);
+    lcd_write_data(conf,0x07);
+
+    lcd_write_cmd(conf,0x35);
+    lcd_write_data(conf,0x21);
+
+    /* Sleep Out */
+    lcd_write_cmd(conf,0x11);
+    /* wait for power stability */
+    luat_timer_mdelay(100);
+    luat_lcd_clear(conf,WHITE);
+    /* display on */
+    luat_lcd_display_on(conf);
+    return 0;
+};
+
+static int gc9a01_draw(luat_lcd_conf_t* conf, uint16_t x_start, uint16_t y_start, uint16_t x_end, uint16_t y_end, luat_color_t* color) {
+    uint32_t size = size = (x_end - x_start+1) * (y_end - y_start+1) * 2;
+    luat_lcd_set_address(conf,x_start, y_start, x_end, y_end);
+    luat_gpio_set(conf->pin_dc, Luat_GPIO_HIGH);
+    luat_spi_send(conf->port, color, size);
+    return 0;
+}
+
+const luat_lcd_opts_t lcd_opts_gc9a01 = {
+    .name = "gc9a01",
+    .init = gc9a01_init,
+    .close = gc9a01_close,
+    .draw = gc9a01_draw,
+    .sleep = gc9a01_sleep,
+    .wakeup = gc9a01_wakeup,
+};
+

+ 181 - 228
components/lcd/luat_lcd_ili9341.c

@@ -1,228 +1,181 @@
-#include "luat_base.h"
-#include "luat_lcd.h"
-#include "luat_gpio.h"
-#include "luat_spi.h"
-#include "luat_malloc.h"
-#include "luat_timer.h"
-
-#define LUAT_LOG_TAG "ili9341"
-#include "luat_log.h"
-
-#define LCD_W 240
-#define LCD_H 320
-#define LCD_DIRECTION 0
-
-static int ili9341_sleep(luat_lcd_conf_t* conf) {
-    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) {
-    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) {
-    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;
-    if (conf->h == 0)
-        conf->h = LCD_H;
-    if (conf->direction == 0)
-        conf->direction = LCD_DIRECTION;
-
-    // 配置CS脚的GPIO
-    luat_gpio_mode(conf->pin_cs, Luat_GPIO_OUTPUT, Luat_GPIO_PULLUP, 0);
-    luat_gpio_mode(conf->pin_dc, Luat_GPIO_OUTPUT, Luat_GPIO_PULLUP, 0); // DC
-    luat_gpio_mode(conf->pin_pwr, Luat_GPIO_OUTPUT, Luat_GPIO_PULLUP, 0); // POWER
-    luat_gpio_mode(conf->pin_rst, Luat_GPIO_OUTPUT, Luat_GPIO_PULLUP, 0); // RST
-
-    luat_gpio_mode(conf->pin_dc, Luat_GPIO_OUTPUT, Luat_GPIO_DEFAULT, Luat_GPIO_HIGH); // DC
-    luat_gpio_mode(conf->pin_pwr, Luat_GPIO_OUTPUT, Luat_GPIO_DEFAULT, Luat_GPIO_LOW); // POWER
-    luat_gpio_mode(conf->pin_rst, Luat_GPIO_OUTPUT, Luat_GPIO_DEFAULT, Luat_GPIO_LOW); // RST
-
-    luat_gpio_set(conf->pin_pwr, Luat_GPIO_LOW);
-    luat_gpio_set(conf->pin_rst, Luat_GPIO_LOW);
-    luat_timer_mdelay(100);
-    luat_gpio_set(conf->pin_rst, Luat_GPIO_HIGH);
-
-    // 发送初始化命令
-    lcd_write_cmd(conf,0xCF);
-    lcd_write_data(conf,0x00);
-    lcd_write_data(conf,0xD9);
-    lcd_write_data(conf,0X30);
-    lcd_write_cmd(conf,0xED);
-    lcd_write_data(conf,0x64);
-    lcd_write_data(conf,0x03);
-    lcd_write_data(conf,0X12);
-    lcd_write_data(conf,0X81);
-    lcd_write_cmd(conf,0xE8);
-    lcd_write_data(conf,0x85);
-    lcd_write_data(conf,0x10);
-    lcd_write_data(conf,0x78);
-
-    lcd_write_cmd(conf,0xCB);
-    lcd_write_data(conf,0x39);
-    lcd_write_data(conf,0x2C);
-    lcd_write_data(conf,0x00);
-    lcd_write_data(conf,0x34);
-    lcd_write_data(conf,0x02);
-
-    lcd_write_cmd(conf,0xF7);
-    lcd_write_data(conf,0x20);
-
-    lcd_write_cmd(conf,0xEA);
-    lcd_write_data(conf,0x00);
-    lcd_write_data(conf,0x00);
-
-    lcd_write_cmd(conf,0xC0);
-    lcd_write_data(conf,0x21);
-    lcd_write_cmd(conf,0xC1);
-    lcd_write_data(conf,0x12);
-
-    lcd_write_cmd(conf,0xC5);
-    lcd_write_data(conf,0x32);
-    lcd_write_data(conf,0x3C);
-    lcd_write_cmd(conf,0xC7);
-    lcd_write_data(conf,0XC1);
-
-    lcd_write_cmd(conf,0xC5);
-    lcd_write_data(conf,0x1A);
-    lcd_write_cmd(conf,0x36);
-    lcd_write_data(conf,0x00);
-
-    lcd_write_cmd(conf,0x36);
-    if(conf->direction==0)lcd_write_data(conf,0x08);
-    else if(conf->direction==1)lcd_write_data(conf,0xC8);
-    else if(conf->direction==2)lcd_write_data(conf,0x78);
-    else lcd_write_data(conf,0xA8);
-
-    lcd_write_cmd(conf,0x3A);
-    lcd_write_data(conf,0x55);
-    lcd_write_cmd(conf,0xB1);
-    lcd_write_data(conf,0x00);
-    lcd_write_data(conf,0x18);
-    lcd_write_cmd(conf,0xB6);
-    lcd_write_data(conf,0x0A);
-    lcd_write_data(conf,0xA2);
-    lcd_write_cmd(conf,0xF2);
-    lcd_write_data(conf,0x00);
-    lcd_write_cmd(conf,0x26);
-    lcd_write_data(conf,0x01);
-
-    lcd_write_cmd(conf,0xE0);
-    lcd_write_data(conf,0x0F);
-    lcd_write_data(conf,0x20);
-    lcd_write_data(conf,0x1E);
-    lcd_write_data(conf,0x09);
-    lcd_write_data(conf,0x12);
-    lcd_write_data(conf,0x0B);
-    lcd_write_data(conf,0x50);
-    lcd_write_data(conf,0XBA);
-    lcd_write_data(conf,0x44);
-    lcd_write_data(conf,0x09);
-    lcd_write_data(conf,0x14);
-    lcd_write_data(conf,0x05);
-    lcd_write_data(conf,0x23);
-    lcd_write_data(conf,0x21);
-    lcd_write_data(conf,0x00);
-
-    lcd_write_cmd(conf,0XE1);
-    lcd_write_data(conf,0x00);
-    lcd_write_data(conf,0x19);
-    lcd_write_data(conf,0x19);
-    lcd_write_data(conf,0x00);
-    lcd_write_data(conf,0x12);
-    lcd_write_data(conf,0x07);
-    lcd_write_data(conf,0x2D);
-    lcd_write_data(conf,0x28);
-    lcd_write_data(conf,0x3F);
-    lcd_write_data(conf,0x02);
-    lcd_write_data(conf,0x0A);
-    lcd_write_data(conf,0x08);
-    lcd_write_data(conf,0x25);
-    lcd_write_data(conf,0x2D);
-    lcd_write_data(conf,0x0F);
-
-    /* Sleep Out */
-    lcd_write_cmd(conf,0x11);
-    /* wait for power stability */
-    luat_timer_mdelay(100);
-    luat_lcd_clear(conf,WHITE);
-    /* display on */
-    luat_lcd_display_on(conf);
-    return 0;
-};
-
-// TODO 这里的color是ARGB, 需要转为lcd所需要的格式
-static int ili9341_draw(luat_lcd_conf_t* conf, uint16_t x_start, uint16_t y_start, uint16_t x_end, uint16_t y_end, luat_color_t* color) {
-    uint16_t i = 0, j = 0;
-    uint32_t size = 0, size_remain = 0;
-    uint8_t *fill_buf = NULL;
-    size = (x_end - x_start+1) * (y_end - y_start+1) * 2;
-    if (size > conf->w*conf->h/10)
-    {
-        /* the number of remaining to be filled */
-        size_remain = size - conf->w*conf->h/10;
-        size = conf->w*conf->h/10;
-    }
-    luat_lcd_set_address(conf,x_start, y_start, x_end, y_end);
-    fill_buf = (uint8_t *)luat_heap_malloc(size);
-    if (fill_buf)
-    {
-        /* fast fill */
-        while (1)
-        {
-            for (i = 0; i < size / 2; i++)
-            {
-                fill_buf[2 * i] = color[i]>>8;
-                //color >> 8;
-                fill_buf[2 * i + 1] = color[i];
-            }
-            luat_gpio_set(conf->pin_dc, Luat_GPIO_HIGH);
-            luat_spi_send(conf->port, fill_buf, size);
-            /* Fill completed */
-            if (size_remain == 0)
-                break;
-            /* calculate the number of fill next time */
-            if (size_remain > conf->w*conf->h/10)
-            {
-                size_remain = size_remain - conf->w*conf->h/10;
-            }
-            else
-            {
-                size = size_remain;
-                size_remain = 0;
-            }
-        }
-        luat_heap_free(fill_buf);
-    }
-    else
-    {
-        for (i = y_start; i <= y_end; i++)
-        {
-            for (j = x_start; j <= x_end; j++)lcd_write_half_word(conf,color[i]);
-        }
-    }
-    return 0;
-}
-
-
-
-const luat_lcd_opts_t lcd_opts_ili9341 = {
-    .name = "ili9341",
-    .init = ili9341_init,
-    .close = ili9341_close,
-    .draw = ili9341_draw,
-    .sleep = ili9341_sleep,
-    .wakeup = ili9341_wakeup,
-};
-
+#include "luat_base.h"
+#include "luat_lcd.h"
+#include "luat_gpio.h"
+#include "luat_spi.h"
+#include "luat_malloc.h"
+#include "luat_timer.h"
+
+#define LUAT_LOG_TAG "ili9341"
+#include "luat_log.h"
+
+#define LCD_W 240
+#define LCD_H 320
+#define LCD_DIRECTION 0
+
+static int ili9341_sleep(luat_lcd_conf_t* conf) {
+    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) {
+    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) {
+    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;
+    if (conf->h == 0)
+        conf->h = LCD_H;
+    if (conf->direction == 0)
+        conf->direction = LCD_DIRECTION;
+
+    // 配置CS脚的GPIO
+    luat_gpio_mode(conf->pin_cs, Luat_GPIO_OUTPUT, Luat_GPIO_PULLUP, 0);
+    luat_gpio_mode(conf->pin_dc, Luat_GPIO_OUTPUT, Luat_GPIO_PULLUP, 0); // DC
+    luat_gpio_mode(conf->pin_pwr, Luat_GPIO_OUTPUT, Luat_GPIO_PULLUP, 0); // POWER
+    luat_gpio_mode(conf->pin_rst, Luat_GPIO_OUTPUT, Luat_GPIO_PULLUP, 0); // RST
+
+    luat_gpio_mode(conf->pin_dc, Luat_GPIO_OUTPUT, Luat_GPIO_DEFAULT, Luat_GPIO_HIGH); // DC
+    luat_gpio_mode(conf->pin_pwr, Luat_GPIO_OUTPUT, Luat_GPIO_DEFAULT, Luat_GPIO_LOW); // POWER
+    luat_gpio_mode(conf->pin_rst, Luat_GPIO_OUTPUT, Luat_GPIO_DEFAULT, Luat_GPIO_LOW); // RST
+
+    luat_gpio_set(conf->pin_pwr, Luat_GPIO_LOW);
+    luat_gpio_set(conf->pin_rst, Luat_GPIO_LOW);
+    luat_timer_mdelay(100);
+    luat_gpio_set(conf->pin_rst, Luat_GPIO_HIGH);
+
+    // 发送初始化命令
+    lcd_write_cmd(conf,0xCF);
+    lcd_write_data(conf,0x00);
+    lcd_write_data(conf,0xD9);
+    lcd_write_data(conf,0X30);
+    lcd_write_cmd(conf,0xED);
+    lcd_write_data(conf,0x64);
+    lcd_write_data(conf,0x03);
+    lcd_write_data(conf,0X12);
+    lcd_write_data(conf,0X81);
+    lcd_write_cmd(conf,0xE8);
+    lcd_write_data(conf,0x85);
+    lcd_write_data(conf,0x10);
+    lcd_write_data(conf,0x78);
+
+    lcd_write_cmd(conf,0xCB);
+    lcd_write_data(conf,0x39);
+    lcd_write_data(conf,0x2C);
+    lcd_write_data(conf,0x00);
+    lcd_write_data(conf,0x34);
+    lcd_write_data(conf,0x02);
+
+    lcd_write_cmd(conf,0xF7);
+    lcd_write_data(conf,0x20);
+
+    lcd_write_cmd(conf,0xEA);
+    lcd_write_data(conf,0x00);
+    lcd_write_data(conf,0x00);
+
+    lcd_write_cmd(conf,0xC0);
+    lcd_write_data(conf,0x21);
+    lcd_write_cmd(conf,0xC1);
+    lcd_write_data(conf,0x12);
+
+    lcd_write_cmd(conf,0xC5);
+    lcd_write_data(conf,0x32);
+    lcd_write_data(conf,0x3C);
+    lcd_write_cmd(conf,0xC7);
+    lcd_write_data(conf,0XC1);
+
+    lcd_write_cmd(conf,0xC5);
+    lcd_write_data(conf,0x1A);
+    lcd_write_cmd(conf,0x36);
+    lcd_write_data(conf,0x00);
+
+    lcd_write_cmd(conf,0x36);
+    if(conf->direction==0)lcd_write_data(conf,0x08);
+    else if(conf->direction==1)lcd_write_data(conf,0xC8);
+    else if(conf->direction==2)lcd_write_data(conf,0x78);
+    else lcd_write_data(conf,0xA8);
+
+    lcd_write_cmd(conf,0x3A);
+    lcd_write_data(conf,0x55);
+    lcd_write_cmd(conf,0xB1);
+    lcd_write_data(conf,0x00);
+    lcd_write_data(conf,0x18);
+    lcd_write_cmd(conf,0xB6);
+    lcd_write_data(conf,0x0A);
+    lcd_write_data(conf,0xA2);
+    lcd_write_cmd(conf,0xF2);
+    lcd_write_data(conf,0x00);
+    lcd_write_cmd(conf,0x26);
+    lcd_write_data(conf,0x01);
+
+    lcd_write_cmd(conf,0xE0);
+    lcd_write_data(conf,0x0F);
+    lcd_write_data(conf,0x20);
+    lcd_write_data(conf,0x1E);
+    lcd_write_data(conf,0x09);
+    lcd_write_data(conf,0x12);
+    lcd_write_data(conf,0x0B);
+    lcd_write_data(conf,0x50);
+    lcd_write_data(conf,0XBA);
+    lcd_write_data(conf,0x44);
+    lcd_write_data(conf,0x09);
+    lcd_write_data(conf,0x14);
+    lcd_write_data(conf,0x05);
+    lcd_write_data(conf,0x23);
+    lcd_write_data(conf,0x21);
+    lcd_write_data(conf,0x00);
+
+    lcd_write_cmd(conf,0XE1);
+    lcd_write_data(conf,0x00);
+    lcd_write_data(conf,0x19);
+    lcd_write_data(conf,0x19);
+    lcd_write_data(conf,0x00);
+    lcd_write_data(conf,0x12);
+    lcd_write_data(conf,0x07);
+    lcd_write_data(conf,0x2D);
+    lcd_write_data(conf,0x28);
+    lcd_write_data(conf,0x3F);
+    lcd_write_data(conf,0x02);
+    lcd_write_data(conf,0x0A);
+    lcd_write_data(conf,0x08);
+    lcd_write_data(conf,0x25);
+    lcd_write_data(conf,0x2D);
+    lcd_write_data(conf,0x0F);
+
+    /* Sleep Out */
+    lcd_write_cmd(conf,0x11);
+    /* wait for power stability */
+    luat_timer_mdelay(100);
+    luat_lcd_clear(conf,WHITE);
+    /* display on */
+    luat_lcd_display_on(conf);
+    return 0;
+};
+
+static int ili9341_draw(luat_lcd_conf_t* conf, uint16_t x_start, uint16_t y_start, uint16_t x_end, uint16_t y_end, luat_color_t* color) {
+    uint32_t size = size = (x_end - x_start+1) * (y_end - y_start+1) * 2;
+    luat_lcd_set_address(conf,x_start, y_start, x_end, y_end);
+    luat_gpio_set(conf->pin_dc, Luat_GPIO_HIGH);
+    luat_spi_send(conf->port, color, size);
+    return 0;
+}
+
+const luat_lcd_opts_t lcd_opts_ili9341 = {
+    .name = "ili9341",
+    .init = ili9341_init,
+    .close = ili9341_close,
+    .draw = ili9341_draw,
+    .sleep = ili9341_sleep,
+    .wakeup = ili9341_wakeup,
+};
+

+ 167 - 214
components/lcd/luat_lcd_st7735.c

@@ -1,214 +1,167 @@
-#include "luat_base.h"
-#include "luat_lcd.h"
-#include "luat_gpio.h"
-#include "luat_spi.h"
-#include "luat_malloc.h"
-#include "luat_timer.h"
-
-#define LUAT_LOG_TAG "st7735"
-#include "luat_log.h"
-
-#define LCD_W 128
-#define LCD_H 160
-#define LCD_DIRECTION 0
-
-static int st7735_sleep(luat_lcd_conf_t* conf) {
-    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) {
-    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) {
-    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;
-    if (conf->h == 0)
-        conf->h = LCD_H;
-    if (conf->direction == 0)
-        conf->direction = LCD_DIRECTION;
-
-    // 配置CS脚的GPIO
-    luat_gpio_mode(conf->pin_cs, Luat_GPIO_OUTPUT, Luat_GPIO_PULLUP, 0);
-    luat_gpio_mode(conf->pin_dc, Luat_GPIO_OUTPUT, Luat_GPIO_PULLUP, 0); // DC
-    luat_gpio_mode(conf->pin_pwr, Luat_GPIO_OUTPUT, Luat_GPIO_PULLUP, 0); // POWER
-    luat_gpio_mode(conf->pin_rst, Luat_GPIO_OUTPUT, Luat_GPIO_PULLUP, 0); // RST
-
-    luat_gpio_mode(conf->pin_dc, Luat_GPIO_OUTPUT, Luat_GPIO_DEFAULT, Luat_GPIO_HIGH); // DC
-    luat_gpio_mode(conf->pin_pwr, Luat_GPIO_OUTPUT, Luat_GPIO_DEFAULT, Luat_GPIO_LOW); // POWER
-    luat_gpio_mode(conf->pin_rst, Luat_GPIO_OUTPUT, Luat_GPIO_DEFAULT, Luat_GPIO_LOW); // RST
-
-    luat_gpio_set(conf->pin_pwr, Luat_GPIO_LOW);
-    luat_gpio_set(conf->pin_rst, Luat_GPIO_LOW);
-    luat_timer_mdelay(100);
-    luat_gpio_set(conf->pin_rst, Luat_GPIO_HIGH);
-
-    // 发送初始化命令
-    //------------------------------------ST7735S Frame Rate-----------------------------------------//
-    lcd_write_cmd(conf,0xB1);
-    lcd_write_data(conf,0x05);
-    lcd_write_data(conf,0x3C);
-    lcd_write_data(conf,0x3C);
-    lcd_write_cmd(conf,0xB2);
-    lcd_write_data(conf,0x05);
-    lcd_write_data(conf,0x3C);
-    lcd_write_data(conf,0x3C);
-    lcd_write_cmd(conf,0xB3);
-    lcd_write_data(conf,0x05);
-    lcd_write_data(conf,0x3C);
-    lcd_write_data(conf,0x3C);
-    lcd_write_data(conf,0x05);
-    lcd_write_data(conf,0x3C);
-    lcd_write_data(conf,0x3C);
-    //------------------------------------End ST7735S Frame Rate---------------------------------//
-    lcd_write_cmd(conf,0xB4);
-    lcd_write_data(conf,0x03);
-	//------------------------------------ST7735S Power Sequence---------------------------------//
-    lcd_write_cmd(conf,0xC0);
-    lcd_write_data(conf,0x28);
-    lcd_write_data(conf,0x08);
-    lcd_write_data(conf,0x04);
-    lcd_write_cmd(conf,0xC1);
-    lcd_write_data(conf,0XC0);
-    lcd_write_cmd(conf,0xC2);
-    lcd_write_data(conf,0x0D);
-    lcd_write_data(conf,0x00);
-    lcd_write_cmd(conf,0xC3);
-    lcd_write_data(conf,0x8D);
-    lcd_write_data(conf,0x2A);
-    lcd_write_cmd(conf,0xC4);
-    lcd_write_data(conf,0x8D);
-    lcd_write_data(conf,0xEE);
-	//---------------------------------End ST7735S Power Sequence-------------------------------------//
-    lcd_write_cmd(conf,0xC5);
-    lcd_write_data(conf,0x1A);
-
-    lcd_write_cmd(conf,0x36);
-    if(conf->direction==0)lcd_write_data(conf,0x00);
-    else if(conf->direction==1)lcd_write_data(conf,0xC0);
-    else if(conf->direction==2)lcd_write_data(conf,0x70);
-    else lcd_write_data(conf,0xA0);
-	//------------------------------------ST7735S Gamma Sequence---------------------------------//
-	lcd_write_cmd(conf,0xE0);
-    lcd_write_data(conf,0x04);
-    lcd_write_data(conf,0x22);
-    lcd_write_data(conf,0x07);
-    lcd_write_data(conf,0x0A);
-    lcd_write_data(conf,0x2E);
-    lcd_write_data(conf,0x30);
-    lcd_write_data(conf,0x25);
-    lcd_write_data(conf,0x2A);
-    lcd_write_data(conf,0x28);
-    lcd_write_data(conf,0x26);
-    lcd_write_data(conf,0x2E);
-    lcd_write_data(conf,0x3A);
-    lcd_write_data(conf,0x00);
-    lcd_write_data(conf,0x01);
-    lcd_write_data(conf,0x03);
-    lcd_write_data(conf,0x13);
-    lcd_write_cmd(conf,0xE1);
-    lcd_write_data(conf,0x04);
-    lcd_write_data(conf,0x16);
-    lcd_write_data(conf,0x06);
-    lcd_write_data(conf,0x0D);
-    lcd_write_data(conf,0x2D);
-    lcd_write_data(conf,0x26);
-    lcd_write_data(conf,0x23);
-    lcd_write_data(conf,0x27);
-    lcd_write_data(conf,0x27);
-    lcd_write_data(conf,0x25);
-    lcd_write_data(conf,0x2D);
-    lcd_write_data(conf,0x3B);
-    lcd_write_data(conf,0x00);
-    lcd_write_data(conf,0x01);
-    lcd_write_data(conf,0x04);
-    lcd_write_data(conf,0x13);
-
-    lcd_write_cmd(conf,0x3A);
-    lcd_write_data(conf,0x05);
-
-    /* Sleep Out */
-    lcd_write_cmd(conf,0x11);
-    /* wait for power stability */
-    luat_timer_mdelay(100);
-    luat_lcd_clear(conf,WHITE);
-    /* display on */
-    luat_lcd_display_on(conf);
-    return 0;
-};
-
-// TODO 这里的color是ARGB, 需要转为lcd所需要的格式
-static int st7735_draw(luat_lcd_conf_t* conf, uint16_t x_start, uint16_t y_start, uint16_t x_end, uint16_t y_end, luat_color_t* color) {
-    uint16_t i = 0, j = 0;
-    uint32_t size = 0, size_remain = 0;
-    uint8_t *fill_buf = NULL;
-    size = (x_end - x_start+1) * (y_end - y_start+1) * 2;
-    if (size > conf->w*conf->h/10)
-    {
-        /* the number of remaining to be filled */
-        size_remain = size - conf->w*conf->h/10;
-        size = conf->w*conf->h/10;
-    }
-    luat_lcd_set_address(conf,x_start, y_start, x_end, y_end);
-    fill_buf = (uint8_t *)luat_heap_malloc(size);
-    if (fill_buf)
-    {
-        /* fast fill */
-        while (1)
-        {
-            for (i = 0; i < size / 2; i++)
-            {
-                fill_buf[2 * i] = color[i]>>8;
-                //color >> 8;
-                fill_buf[2 * i + 1] = color[i];
-            }
-            luat_gpio_set(conf->pin_dc, Luat_GPIO_HIGH);
-            luat_spi_send(conf->port, fill_buf, size);
-            /* Fill completed */
-            if (size_remain == 0)
-                break;
-            /* calculate the number of fill next time */
-            if (size_remain > conf->w*conf->h/10)
-            {
-                size_remain = size_remain - conf->w*conf->h/10;
-            }
-            else
-            {
-                size = size_remain;
-                size_remain = 0;
-            }
-        }
-        luat_heap_free(fill_buf);
-    }
-    else
-    {
-        for (i = y_start; i <= y_end; i++)
-        {
-            for (j = x_start; j <= x_end; j++)lcd_write_half_word(conf,color[i]);
-        }
-    }
-    return 0;
-}
-
-
-
-const luat_lcd_opts_t lcd_opts_st7735 = {
-    .name = "st7735",
-    .init = st7735_init,
-    .close = st7735_close,
-    .draw = st7735_draw,
-    .sleep = st7735_sleep,
-    .wakeup = st7735_wakeup,
-};
-
+#include "luat_base.h"
+#include "luat_lcd.h"
+#include "luat_gpio.h"
+#include "luat_spi.h"
+#include "luat_malloc.h"
+#include "luat_timer.h"
+
+#define LUAT_LOG_TAG "st7735"
+#include "luat_log.h"
+
+#define LCD_W 128
+#define LCD_H 160
+#define LCD_DIRECTION 0
+
+static int st7735_sleep(luat_lcd_conf_t* conf) {
+    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) {
+    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) {
+    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;
+    if (conf->h == 0)
+        conf->h = LCD_H;
+    if (conf->direction == 0)
+        conf->direction = LCD_DIRECTION;
+
+    // 配置CS脚的GPIO
+    luat_gpio_mode(conf->pin_cs, Luat_GPIO_OUTPUT, Luat_GPIO_PULLUP, 0);
+    luat_gpio_mode(conf->pin_dc, Luat_GPIO_OUTPUT, Luat_GPIO_PULLUP, 0); // DC
+    luat_gpio_mode(conf->pin_pwr, Luat_GPIO_OUTPUT, Luat_GPIO_PULLUP, 0); // POWER
+    luat_gpio_mode(conf->pin_rst, Luat_GPIO_OUTPUT, Luat_GPIO_PULLUP, 0); // RST
+
+    luat_gpio_mode(conf->pin_dc, Luat_GPIO_OUTPUT, Luat_GPIO_DEFAULT, Luat_GPIO_HIGH); // DC
+    luat_gpio_mode(conf->pin_pwr, Luat_GPIO_OUTPUT, Luat_GPIO_DEFAULT, Luat_GPIO_LOW); // POWER
+    luat_gpio_mode(conf->pin_rst, Luat_GPIO_OUTPUT, Luat_GPIO_DEFAULT, Luat_GPIO_LOW); // RST
+
+    luat_gpio_set(conf->pin_pwr, Luat_GPIO_LOW);
+    luat_gpio_set(conf->pin_rst, Luat_GPIO_LOW);
+    luat_timer_mdelay(100);
+    luat_gpio_set(conf->pin_rst, Luat_GPIO_HIGH);
+
+    // 发送初始化命令
+    //------------------------------------ST7735S Frame Rate-----------------------------------------//
+    lcd_write_cmd(conf,0xB1);
+    lcd_write_data(conf,0x05);
+    lcd_write_data(conf,0x3C);
+    lcd_write_data(conf,0x3C);
+    lcd_write_cmd(conf,0xB2);
+    lcd_write_data(conf,0x05);
+    lcd_write_data(conf,0x3C);
+    lcd_write_data(conf,0x3C);
+    lcd_write_cmd(conf,0xB3);
+    lcd_write_data(conf,0x05);
+    lcd_write_data(conf,0x3C);
+    lcd_write_data(conf,0x3C);
+    lcd_write_data(conf,0x05);
+    lcd_write_data(conf,0x3C);
+    lcd_write_data(conf,0x3C);
+    //------------------------------------End ST7735S Frame Rate---------------------------------//
+    lcd_write_cmd(conf,0xB4);
+    lcd_write_data(conf,0x03);
+	//------------------------------------ST7735S Power Sequence---------------------------------//
+    lcd_write_cmd(conf,0xC0);
+    lcd_write_data(conf,0x28);
+    lcd_write_data(conf,0x08);
+    lcd_write_data(conf,0x04);
+    lcd_write_cmd(conf,0xC1);
+    lcd_write_data(conf,0XC0);
+    lcd_write_cmd(conf,0xC2);
+    lcd_write_data(conf,0x0D);
+    lcd_write_data(conf,0x00);
+    lcd_write_cmd(conf,0xC3);
+    lcd_write_data(conf,0x8D);
+    lcd_write_data(conf,0x2A);
+    lcd_write_cmd(conf,0xC4);
+    lcd_write_data(conf,0x8D);
+    lcd_write_data(conf,0xEE);
+	//---------------------------------End ST7735S Power Sequence-------------------------------------//
+    lcd_write_cmd(conf,0xC5);
+    lcd_write_data(conf,0x1A);
+
+    lcd_write_cmd(conf,0x36);
+    if(conf->direction==0)lcd_write_data(conf,0x00);
+    else if(conf->direction==1)lcd_write_data(conf,0xC0);
+    else if(conf->direction==2)lcd_write_data(conf,0x70);
+    else lcd_write_data(conf,0xA0);
+	//------------------------------------ST7735S Gamma Sequence---------------------------------//
+	lcd_write_cmd(conf,0xE0);
+    lcd_write_data(conf,0x04);
+    lcd_write_data(conf,0x22);
+    lcd_write_data(conf,0x07);
+    lcd_write_data(conf,0x0A);
+    lcd_write_data(conf,0x2E);
+    lcd_write_data(conf,0x30);
+    lcd_write_data(conf,0x25);
+    lcd_write_data(conf,0x2A);
+    lcd_write_data(conf,0x28);
+    lcd_write_data(conf,0x26);
+    lcd_write_data(conf,0x2E);
+    lcd_write_data(conf,0x3A);
+    lcd_write_data(conf,0x00);
+    lcd_write_data(conf,0x01);
+    lcd_write_data(conf,0x03);
+    lcd_write_data(conf,0x13);
+    lcd_write_cmd(conf,0xE1);
+    lcd_write_data(conf,0x04);
+    lcd_write_data(conf,0x16);
+    lcd_write_data(conf,0x06);
+    lcd_write_data(conf,0x0D);
+    lcd_write_data(conf,0x2D);
+    lcd_write_data(conf,0x26);
+    lcd_write_data(conf,0x23);
+    lcd_write_data(conf,0x27);
+    lcd_write_data(conf,0x27);
+    lcd_write_data(conf,0x25);
+    lcd_write_data(conf,0x2D);
+    lcd_write_data(conf,0x3B);
+    lcd_write_data(conf,0x00);
+    lcd_write_data(conf,0x01);
+    lcd_write_data(conf,0x04);
+    lcd_write_data(conf,0x13);
+
+    lcd_write_cmd(conf,0x3A);
+    lcd_write_data(conf,0x05);
+
+    /* Sleep Out */
+    lcd_write_cmd(conf,0x11);
+    /* wait for power stability */
+    luat_timer_mdelay(100);
+    luat_lcd_clear(conf,WHITE);
+    /* display on */
+    luat_lcd_display_on(conf);
+    return 0;
+};
+
+static int st7735_draw(luat_lcd_conf_t* conf, uint16_t x_start, uint16_t y_start, uint16_t x_end, uint16_t y_end, luat_color_t* color) {
+    uint32_t size = size = (x_end - x_start+1) * (y_end - y_start+1) * 2;
+    luat_lcd_set_address(conf,x_start, y_start, x_end, y_end);
+    luat_gpio_set(conf->pin_dc, Luat_GPIO_HIGH);
+    luat_spi_send(conf->port, color, size);
+    return 0;
+}
+
+const luat_lcd_opts_t lcd_opts_st7735 = {
+    .name = "st7735",
+    .init = st7735_init,
+    .close = st7735_close,
+    .draw = st7735_draw,
+    .sleep = st7735_sleep,
+    .wakeup = st7735_wakeup,
+};
+

+ 155 - 200
components/lcd/luat_lcd_st7789.c

@@ -1,200 +1,155 @@
-#include "luat_base.h"
-#include "luat_lcd.h"
-#include "luat_gpio.h"
-#include "luat_spi.h"
-#include "luat_malloc.h"
-#include "luat_timer.h"
-
-#define LUAT_LOG_TAG "st7789"
-#include "luat_log.h"
-
-#define LCD_W 240
-#define LCD_H 320
-#define LCD_DIRECTION 0
-
-static int st7789_sleep(luat_lcd_conf_t* conf) {
-    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) {
-    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) {
-    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)
-        conf->h = LCD_H;
-    if (conf->direction == 0)
-        conf->direction = LCD_DIRECTION;
-    luat_gpio_mode(conf->pin_dc, Luat_GPIO_OUTPUT, Luat_GPIO_DEFAULT, Luat_GPIO_HIGH); // DC
-    luat_gpio_mode(conf->pin_pwr, Luat_GPIO_OUTPUT, Luat_GPIO_DEFAULT, Luat_GPIO_LOW); // POWER
-    luat_gpio_mode(conf->pin_rst, Luat_GPIO_OUTPUT, Luat_GPIO_DEFAULT, Luat_GPIO_LOW); // RST
-
-    luat_gpio_set(conf->pin_pwr, Luat_GPIO_LOW);
-    luat_gpio_set(conf->pin_rst, Luat_GPIO_LOW);
-    luat_timer_mdelay(100);
-    luat_gpio_set(conf->pin_rst, Luat_GPIO_HIGH);
-    // 发送初始化命令
-
-    /* Memory Data Access Control */
-    lcd_write_cmd(conf,0x36);
-    if(conf->direction==0)lcd_write_data(conf,0x00);
-    else if(conf->direction==1)lcd_write_data(conf,0xC0);
-    else if(conf->direction==2)lcd_write_data(conf,0x70);
-    else lcd_write_data(conf,0xA0);
-    /* RGB 5-6-5-bit  */
-    lcd_write_cmd(conf,0x3A);
-    lcd_write_data(conf,0x65);
-    /* Porch Setting */
-    lcd_write_cmd(conf,0xB2);
-    lcd_write_data(conf,0x0C);
-    lcd_write_data(conf,0x0C);
-    lcd_write_data(conf,0x00);
-    lcd_write_data(conf,0x33);
-    lcd_write_data(conf,0x33);
-    /*  Gate Control */
-    lcd_write_cmd(conf,0xB7);
-    lcd_write_data(conf,0x35);
-    /* VCOM Setting */
-    lcd_write_cmd(conf,0xBB);
-    lcd_write_data(conf,0x19);
-    /* LCM Control */
-    lcd_write_cmd(conf,0xC0);
-    lcd_write_data(conf,0x2C);
-    /* VDV and VRH Command Enable */
-    lcd_write_cmd(conf,0xC2);
-    lcd_write_data(conf,0x01);
-    /* VRH Set */
-    lcd_write_cmd(conf,0xC3);
-    lcd_write_data(conf,0x12);
-    /* VDV Set */
-    lcd_write_cmd(conf,0xC4);
-    lcd_write_data(conf,0x20);
-    /* Frame Rate Control in Normal Mode */
-    lcd_write_cmd(conf,0xC6);
-    lcd_write_data(conf,0x0F);
-    /* Power Control 1 */
-    lcd_write_cmd(conf,0xD0);
-    lcd_write_data(conf,0xA4);
-    lcd_write_data(conf,0xA1);
-    /* Positive Voltage Gamma Control */
-    lcd_write_cmd(conf,0xE0);
-    lcd_write_data(conf,0xD0);
-    lcd_write_data(conf,0x04);
-    lcd_write_data(conf,0x0D);
-    lcd_write_data(conf,0x11);
-    lcd_write_data(conf,0x13);
-    lcd_write_data(conf,0x2B);
-    lcd_write_data(conf,0x3F);
-    lcd_write_data(conf,0x54);
-    lcd_write_data(conf,0x4C);
-    lcd_write_data(conf,0x18);
-    lcd_write_data(conf,0x0D);
-    lcd_write_data(conf,0x0B);
-    lcd_write_data(conf,0x1F);
-    lcd_write_data(conf,0x23);
-    /* Negative Voltage Gamma Control */
-    lcd_write_cmd(conf,0xE1);
-    lcd_write_data(conf,0xD0);
-    lcd_write_data(conf,0x04);
-    lcd_write_data(conf,0x0C);
-    lcd_write_data(conf,0x11);
-    lcd_write_data(conf,0x13);
-    lcd_write_data(conf,0x2C);
-    lcd_write_data(conf,0x3F);
-    lcd_write_data(conf,0x44);
-    lcd_write_data(conf,0x51);
-    lcd_write_data(conf,0x2F);
-    lcd_write_data(conf,0x1F);
-    lcd_write_data(conf,0x1F);
-    lcd_write_data(conf,0x20);
-    lcd_write_data(conf,0x23);
-    /* Display Inversion On */
-    lcd_write_cmd(conf,0x21);
-    /* Sleep Out */
-    lcd_write_cmd(conf,0x11);
-    /* wait for power stability */
-    luat_timer_mdelay(100);
-    luat_lcd_clear(conf,WHITE);
-    /* display on */
-    luat_lcd_display_on(conf);
-    return 0;
-};
-
-// TODO 这里的color是ARGB, 需要转为lcd所需要的格式
-static int st7789_draw(luat_lcd_conf_t* conf, uint16_t x_start, uint16_t y_start, uint16_t x_end, uint16_t y_end, luat_color_t* color) {
-    uint16_t i = 0, j = 0;
-    uint32_t size = 0, size_remain = 0;
-    uint8_t *fill_buf = NULL;
-    size = (x_end - x_start+1) * (y_end - y_start+1) * 2;
-    if (size > conf->w*conf->h/10)
-    {
-        /* the number of remaining to be filled */
-        size_remain = size - conf->w*conf->h/10;
-        size = conf->w*conf->h/10;
-    }
-    luat_lcd_set_address(conf,x_start, y_start, x_end, y_end);
-    fill_buf = (uint8_t *)luat_heap_malloc(size);
-    if (fill_buf)
-    {
-        /* fast fill */
-        while (1)
-        {
-            for (i = 0; i < size / 2; i++)
-            {
-                fill_buf[2 * i] = color[i]>>8;
-                //color >> 8;
-                fill_buf[2 * i + 1] = color[i];
-            }
-            luat_gpio_set(conf->pin_dc, Luat_GPIO_HIGH);
-            luat_spi_send(conf->port, fill_buf, size);
-            /* Fill completed */
-            if (size_remain == 0)
-                break;
-            /* calculate the number of fill next time */
-            if (size_remain > conf->w*conf->h/10)
-            {
-                size_remain = size_remain - conf->w*conf->h/10;
-            }
-            else
-            {
-                size = size_remain;
-                size_remain = 0;
-            }
-        }
-        luat_heap_free(fill_buf);
-    }
-    else
-    {
-        for (i = y_start; i <= y_end; i++)
-        {
-            for (j = x_start; j <= x_end; j++)lcd_write_half_word(conf,color[i]);
-        }
-    }
-    return 0;
-}
-
-const luat_lcd_opts_t lcd_opts_st7789 = {
-    .name = "st7789",
-    .init = st7789_init,
-    .close = st7789_close,
-    .draw = st7789_draw,
-    .sleep = st7789_sleep,
-    .wakeup = st7789_wakeup,
-};
-
+#include "luat_base.h"
+#include "luat_lcd.h"
+#include "luat_gpio.h"
+#include "luat_spi.h"
+#include "luat_malloc.h"
+#include "luat_timer.h"
+
+#define LUAT_LOG_TAG "st7789"
+#include "luat_log.h"
+
+#define LCD_W 240
+#define LCD_H 320
+#define LCD_DIRECTION 0
+
+static int st7789_sleep(luat_lcd_conf_t* conf) {
+    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) {
+    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) {
+    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)
+        conf->h = LCD_H;
+    if (conf->direction == 0)
+        conf->direction = LCD_DIRECTION;
+    luat_gpio_mode(conf->pin_dc, Luat_GPIO_OUTPUT, Luat_GPIO_DEFAULT, Luat_GPIO_HIGH); // DC
+    luat_gpio_mode(conf->pin_pwr, Luat_GPIO_OUTPUT, Luat_GPIO_DEFAULT, Luat_GPIO_LOW); // POWER
+    luat_gpio_mode(conf->pin_rst, Luat_GPIO_OUTPUT, Luat_GPIO_DEFAULT, Luat_GPIO_LOW); // RST
+
+    luat_gpio_set(conf->pin_pwr, Luat_GPIO_LOW);
+    luat_gpio_set(conf->pin_rst, Luat_GPIO_LOW);
+    luat_timer_mdelay(100);
+    luat_gpio_set(conf->pin_rst, Luat_GPIO_HIGH);
+    // 发送初始化命令
+
+    /* Memory Data Access Control */
+    lcd_write_cmd(conf,0x36);
+    if(conf->direction==0)lcd_write_data(conf,0x00);
+    else if(conf->direction==1)lcd_write_data(conf,0xC0);
+    else if(conf->direction==2)lcd_write_data(conf,0x70);
+    else lcd_write_data(conf,0xA0);
+    /* RGB 5-6-5-bit  */
+    lcd_write_cmd(conf,0x3A);
+    lcd_write_data(conf,0x65);
+    /* Porch Setting */
+    lcd_write_cmd(conf,0xB2);
+    lcd_write_data(conf,0x0C);
+    lcd_write_data(conf,0x0C);
+    lcd_write_data(conf,0x00);
+    lcd_write_data(conf,0x33);
+    lcd_write_data(conf,0x33);
+    /*  Gate Control */
+    lcd_write_cmd(conf,0xB7);
+    lcd_write_data(conf,0x35);
+    /* VCOM Setting */
+    lcd_write_cmd(conf,0xBB);
+    lcd_write_data(conf,0x19);
+    /* LCM Control */
+    lcd_write_cmd(conf,0xC0);
+    lcd_write_data(conf,0x2C);
+    /* VDV and VRH Command Enable */
+    lcd_write_cmd(conf,0xC2);
+    lcd_write_data(conf,0x01);
+    /* VRH Set */
+    lcd_write_cmd(conf,0xC3);
+    lcd_write_data(conf,0x12);
+    /* VDV Set */
+    lcd_write_cmd(conf,0xC4);
+    lcd_write_data(conf,0x20);
+    /* Frame Rate Control in Normal Mode */
+    lcd_write_cmd(conf,0xC6);
+    lcd_write_data(conf,0x0F);
+    /* Power Control 1 */
+    lcd_write_cmd(conf,0xD0);
+    lcd_write_data(conf,0xA4);
+    lcd_write_data(conf,0xA1);
+    /* Positive Voltage Gamma Control */
+    lcd_write_cmd(conf,0xE0);
+    lcd_write_data(conf,0xD0);
+    lcd_write_data(conf,0x04);
+    lcd_write_data(conf,0x0D);
+    lcd_write_data(conf,0x11);
+    lcd_write_data(conf,0x13);
+    lcd_write_data(conf,0x2B);
+    lcd_write_data(conf,0x3F);
+    lcd_write_data(conf,0x54);
+    lcd_write_data(conf,0x4C);
+    lcd_write_data(conf,0x18);
+    lcd_write_data(conf,0x0D);
+    lcd_write_data(conf,0x0B);
+    lcd_write_data(conf,0x1F);
+    lcd_write_data(conf,0x23);
+    /* Negative Voltage Gamma Control */
+    lcd_write_cmd(conf,0xE1);
+    lcd_write_data(conf,0xD0);
+    lcd_write_data(conf,0x04);
+    lcd_write_data(conf,0x0C);
+    lcd_write_data(conf,0x11);
+    lcd_write_data(conf,0x13);
+    lcd_write_data(conf,0x2C);
+    lcd_write_data(conf,0x3F);
+    lcd_write_data(conf,0x44);
+    lcd_write_data(conf,0x51);
+    lcd_write_data(conf,0x2F);
+    lcd_write_data(conf,0x1F);
+    lcd_write_data(conf,0x1F);
+    lcd_write_data(conf,0x20);
+    lcd_write_data(conf,0x23);
+    /* Display Inversion On */
+    lcd_write_cmd(conf,0x21);
+    /* Sleep Out */
+    lcd_write_cmd(conf,0x11);
+    /* wait for power stability */
+    luat_timer_mdelay(100);
+    luat_lcd_clear(conf,WHITE);
+    /* display on */
+    luat_lcd_display_on(conf);
+    return 0;
+};
+
+static int st7789_draw(luat_lcd_conf_t* conf, uint16_t x_start, uint16_t y_start, uint16_t x_end, uint16_t y_end, luat_color_t* color) {
+    uint32_t size = size = (x_end - x_start+1) * (y_end - y_start+1) * 2;
+    luat_lcd_set_address(conf,x_start, y_start, x_end, y_end);
+    luat_gpio_set(conf->pin_dc, Luat_GPIO_HIGH);
+    luat_spi_send(conf->port, color, size);
+    return 0;
+}
+
+const luat_lcd_opts_t lcd_opts_st7789 = {
+    .name = "st7789",
+    .init = st7789_init,
+    .close = st7789_close,
+    .draw = st7789_draw,
+    .sleep = st7789_sleep,
+    .wakeup = st7789_wakeup,
+};
+

+ 84 - 84
components/lvgl/binding/luat_lib_lvgl7.c

@@ -1,84 +1,84 @@
-
-#include "luat_base.h"
-#include "luat_lvgl.h"
-#include "luat_malloc.h"
-#include "luat_zbuff.h"
-#include "luat_lcd.h"
-
-
-static lv_disp_t* my_disp = NULL;
-static lv_disp_buf_t my_disp_buff = {0};
-//static lv_disp_drv_t my_disp_drv;
-luat_lcd_conf_t* conf;
-
-static void disp_flush(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p) {
-    //-----
-    if (conf != NULL) {
-        conf->opts->draw(conf, area->x1, area->y1, area->x2, area->y2, color_p);
-    }
-    LLOGD("CALL disp_flush (%d, %d, %d, %d)", area->x1, area->y1, area->x2, area->y2);
-    lv_disp_flush_ready(disp_drv);
-}
-
-#ifdef LUA_USE_WINDOWS
-#include <windows.h>
-extern uint32_t WINDOW_HOR_RES;
-extern uint32_t WINDOW_VER_RES;
-#endif
-
-int luat_lv_init(lua_State *L) {
-    if (my_disp != NULL) {
-        lua_pushboolean(L, 0);
-        return 1;
-    }
-    #ifdef LUA_USE_WINDOWS
-    if (lua_isnumber(L, 1) && lua_isnumber(L, 2)) {
-        WINDOW_HOR_RES= luaL_checkinteger(L, 1);
-        WINDOW_VER_RES = luaL_checkinteger(L, 2);
-    }
-    HWND windrv_init(void);
-    windrv_init();
-    lua_pushboolean(L, 1);
-    return 1;
-    #else
-    conf = luat_lcd_get_default();
-    lv_color_t *fbuffer = NULL;
-    size_t fbuff_size = 0;
-
-    int w = luaL_optinteger(L, 1, conf->w);
-    int h = luaL_optinteger(L, 2, conf->h);
-
-    #ifdef LUA_USE_WINDOWS
-    fbuff_size = w * h;
-    #else
-    fbuff_size = w * 10;
-    #endif
-
-    LLOGD("w %d h %d buff %d", w, h, fbuff_size);
-
-    if (lua_isuserdata(L, 3)) {
-        luat_zbuff *zbuff = tozbuff(L);
-        fbuffer = (lv_color_t *)zbuff->addr;
-        fbuff_size = zbuff->len / sizeof(lv_color_t);
-    }
-    else {
-        fbuffer = luat_heap_malloc(fbuff_size * sizeof(lv_color_t));
-    }
-    lv_disp_buf_init(&my_disp_buff, fbuffer, NULL, fbuff_size);
-
-    lv_disp_drv_t my_disp_drv;
-    lv_disp_drv_init(&my_disp_drv);
-
-    my_disp_drv.flush_cb = disp_flush;
-
-    my_disp_drv.hor_res = w;
-    my_disp_drv.ver_res = h;
-    my_disp_drv.buffer = &my_disp_buff;
-    //LLOGD(">>%s %d", __func__, __LINE__);
-    my_disp = lv_disp_drv_register(&my_disp_drv);
-    //LLOGD(">>%s %d", __func__, __LINE__);
-    lua_pushboolean(L, my_disp != NULL ? 1 : 0);
-    //LLOGD(">>%s %d", __func__, __LINE__);
-    return 1;
-    #endif
-}
+
+#include "luat_base.h"
+#include "luat_lvgl.h"
+#include "luat_malloc.h"
+#include "luat_zbuff.h"
+#include "luat_lcd.h"
+
+
+static lv_disp_t* my_disp = NULL;
+static lv_disp_buf_t my_disp_buff = {0};
+//static lv_disp_drv_t my_disp_drv;
+luat_lcd_conf_t* conf;
+
+static void disp_flush(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p) {
+    //-----
+    if (conf != NULL) {
+        conf->opts->draw(conf, area->x1, area->y1, area->x2, area->y2, color_p);
+    }
+    // LLOGD("CALL disp_flush (%d, %d, %d, %d)", area->x1, area->y1, area->x2, area->y2);
+    lv_disp_flush_ready(disp_drv);
+}
+
+#ifdef LUA_USE_WINDOWS
+#include <windows.h>
+extern uint32_t WINDOW_HOR_RES;
+extern uint32_t WINDOW_VER_RES;
+#endif
+
+int luat_lv_init(lua_State *L) {
+    if (my_disp != NULL) {
+        lua_pushboolean(L, 0);
+        return 1;
+    }
+    #ifdef LUA_USE_WINDOWS
+    if (lua_isnumber(L, 1) && lua_isnumber(L, 2)) {
+        WINDOW_HOR_RES= luaL_checkinteger(L, 1);
+        WINDOW_VER_RES = luaL_checkinteger(L, 2);
+    }
+    HWND windrv_init(void);
+    windrv_init();
+    lua_pushboolean(L, 1);
+    return 1;
+    #else
+    conf = luat_lcd_get_default();
+    lv_color_t *fbuffer = NULL;
+    size_t fbuff_size = 0;
+
+    int w = luaL_optinteger(L, 1, conf->w);
+    int h = luaL_optinteger(L, 2, conf->h);
+
+    #ifdef LUA_USE_WINDOWS
+    fbuff_size = w * h;
+    #else
+    fbuff_size = w * h / 10;
+    #endif
+
+    LLOGD("w %d h %d buff %d", w, h, fbuff_size);
+
+    if (lua_isuserdata(L, 3)) {
+        luat_zbuff *zbuff = tozbuff(L);
+        fbuffer = (lv_color_t *)zbuff->addr;
+        fbuff_size = zbuff->len / sizeof(lv_color_t);
+    }
+    else {
+        fbuffer = luat_heap_malloc(fbuff_size * sizeof(lv_color_t));
+    }
+    lv_disp_buf_init(&my_disp_buff, fbuffer, NULL, fbuff_size);
+
+    lv_disp_drv_t my_disp_drv;
+    lv_disp_drv_init(&my_disp_drv);
+
+    my_disp_drv.flush_cb = disp_flush;
+
+    my_disp_drv.hor_res = w;
+    my_disp_drv.ver_res = h;
+    my_disp_drv.buffer = &my_disp_buff;
+    //LLOGD(">>%s %d", __func__, __LINE__);
+    my_disp = lv_disp_drv_register(&my_disp_drv);
+    //LLOGD(">>%s %d", __func__, __LINE__);
+    lua_pushboolean(L, my_disp != NULL ? 1 : 0);
+    //LLOGD(">>%s %d", __func__, __LINE__);
+    return 1;
+    #endif
+}