Parcourir la source

fix: eink库需要支持自定义gpio脚

Wendal Chen il y a 4 ans
Parent
commit
9c86459f3f

+ 28 - 23
luat/packages/eink/luat_lib_eink.c

@@ -26,13 +26,6 @@
 
 #include "u8g2.h"
 
-#define Pin_BUSY        (18)
-#define Pin_RES         (7)
-#define Pin_DC          (9)
-#define Pin_CS          (16)
-
-#define SPI_ID          (0)
-
 #define COLORED      0
 #define UNCOLORED    1
 
@@ -41,7 +34,21 @@
 
 // static EPD epd;
 static Paint paint;
-static unsigned char* frame_buffer;
+static unsigned char* frame_buffer = NULL;
+
+// #ifdef econf
+// #undef econf
+// #endif
+
+eink_conf_t econf = {0};
+
+#define Pin_BUSY        (econf.busy_pin)
+#define Pin_RES         (econf.res_pin)
+#define Pin_DC          (econf.dc_pin)
+#define Pin_CS          (econf.cs_pin)
+
+#define SPI_ID          (econf.spi_id)
+
 
 /**
 初始化eink
@@ -51,8 +58,13 @@ static unsigned char* frame_buffer;
 @return boolean 成功返回true,否则返回false
 */
 static int l_eink_setup(lua_State *L) {
-    int num = luaL_optinteger(L, 1, 1);
-    int spi_id = luaL_optinteger(L, 2, 0);
+    econf.full_mode = luaL_optinteger(L, 1, 1);
+    econf.spi_id = luaL_optinteger(L, 2, 0);
+
+    econf.busy_pin = luaL_optinteger(L, 3, 18);
+    econf.res_pin  = luaL_optinteger(L, 4, 7);
+    econf.dc_pin = luaL_optinteger(L, 5, 9);
+    econf.cs_pin = luaL_optinteger(L, 6, 16);
 
     if (frame_buffer != NULL) {
         lua_pushboolean(L, 1);
@@ -61,7 +73,7 @@ static int l_eink_setup(lua_State *L) {
 
     luat_spi_t spi_config = {0};
     spi_config.bandrate = 2000000U;//luaL_optinteger(L, 1, 2000000U); // 2000000U
-    spi_config.id = spi_id;
+    spi_config.id = SPI_ID;
     spi_config.cs = 255; // 默认无
     spi_config.CPHA = 0; // CPHA0
     spi_config.CPOL = 0; // CPOL0
@@ -71,25 +83,19 @@ static int l_eink_setup(lua_State *L) {
     spi_config.mode = 1; // FULL=1, half=0
 
     //LLOGD("setup GPIO for epd");
-    // TODO 事实上无法配置
-    luat_gpio_mode(luaL_optinteger(L, 3, Pin_BUSY), Luat_GPIO_INPUT, Luat_GPIO_PULLUP, Luat_GPIO_LOW);
-    luat_gpio_mode(luaL_optinteger(L, 4, Pin_RES), Luat_GPIO_OUTPUT, Luat_GPIO_PULLUP, Luat_GPIO_LOW);
-    luat_gpio_mode(luaL_optinteger(L, 5, Pin_DC), Luat_GPIO_OUTPUT, Luat_GPIO_PULLUP, Luat_GPIO_LOW);
-    luat_gpio_mode(luaL_optinteger(L, 6, Pin_CS), Luat_GPIO_OUTPUT, Luat_GPIO_PULLUP, Luat_GPIO_LOW);
+    luat_gpio_mode(Pin_BUSY, Luat_GPIO_INPUT, Luat_GPIO_PULLUP, Luat_GPIO_LOW);
+    luat_gpio_mode(Pin_RES, Luat_GPIO_OUTPUT, Luat_GPIO_PULLUP, Luat_GPIO_LOW);
+    luat_gpio_mode(Pin_DC, Luat_GPIO_OUTPUT, Luat_GPIO_PULLUP, Luat_GPIO_LOW);
+    luat_gpio_mode(Pin_CS, Luat_GPIO_OUTPUT, Luat_GPIO_PULLUP, Luat_GPIO_LOW);
 
-    //LLOGD("spi setup>>>");
     int status = luat_spi_setup(&spi_config);
-    //LLOGD("spi setup<<<");
-    //EPD_Model(MODEL_1in54f);
-    //EPD_Model(MODEL_1in54_V2);
-    // EPD_Model(MODEL_2in13b_V3);
 
     size_t epd_w = 0;
     size_t epd_h = 0;
     if(status == 0)
     {
         LLOGD("spi setup complete, now setup epd");
-        if(num)
+        if(econf.full_mode)
             status = EPD_Init(1, &epd_w, &epd_h);
         else
             status = EPD_Init(0, &epd_w, &epd_h);
@@ -108,7 +114,6 @@ static int l_eink_setup(lua_State *L) {
     return 1;
 }
 
-
 /**
 清除绘图缓冲区
 @api eink.clear()

+ 1 - 1
luat/packages/epaper/DEV_Config.c

@@ -37,7 +37,7 @@
 void DEV_SPI_WriteByte(UBYTE value)
 {
     //HAL_SPI_Transmit(&hspi1, &value, 1, 1000);
-    luat_spi_send(0, (const char*)&value, 1);
+    luat_spi_send(econf.spi_id, (const char*)&value, 1);
 }
 
 int DEV_Module_Init(void)

+ 19 - 8
luat/packages/epaper/DEV_Config.h

@@ -65,18 +65,29 @@
 #define UWORD   uint16_t
 #define UDOUBLE uint32_t
 
-#define Pin_BUSY        (18)
-#define Pin_RES         (7)
-#define Pin_DC          (9)
-#define Pin_CS          (16)
+// #define Pin_BUSY        (18)
+// #define Pin_RES         (7)
+// #define Pin_DC          (9)
+// #define Pin_CS          (16)
+
+typedef struct eink_conf {
+    uint8_t spi_id;
+    uint8_t busy_pin;
+    uint8_t res_pin;
+    uint8_t dc_pin;
+    uint8_t cs_pin;
+    uint8_t full_mode;
+}eink_conf_t;
+
+extern eink_conf_t econf;
 
 /**
  * e-Paper GPIO
 **/
-#define EPD_RST_PIN     (7)
-#define EPD_DC_PIN      (9)
-#define EPD_CS_PIN      (16)
-#define EPD_BUSY_PIN    (18)
+#define EPD_RST_PIN     (econf.res_pin)
+#define EPD_DC_PIN      (econf.dc_pin)
+#define EPD_CS_PIN      (econf.cs_pin)
+#define EPD_BUSY_PIN    (econf.busy_pin)
 
 /**
  * GPIO read and write