Parcourir la source

update: ht1621支持更多的自定义初始化参数

Wendal Chen il y a 1 an
Parent
commit
71d934f6df

+ 25 - 1
components/ht1621/binding/luat_lib_ht1621.c

@@ -20,10 +20,13 @@ ht1621.data(seg, 0, 0xeb) -- 位置0显示数字1
 
 /*
 初始化ht1621
-@api ht1621.setup(pin_cs, pin_data, pin_wr)
+@api ht1621.setup(pin_cs, pin_data, pin_wr, cmd_com_mode, cmd_rc, cmd_sysen)
 @int 片选引脚, 填模块的GPIO编码
 @int 数据引脚, 填模块的GPIO编码
 @int WR引脚, 填模块的GPIO编码
+@int 命令模式, 默认是0x52
+@int 内部RC振荡器,默认0x30
+@int 系统振荡器开,默认0x02
 @return userdata 返回ht1621对象
 @usage
 local seg = ht1621.setup(4, 5, 3)
@@ -37,6 +40,27 @@ static int l_ht1621_setup(lua_State *L) {
     conf->pin_cs = pin_cs;
     conf->pin_data = pin_data;
     conf->pin_wr = pin_wr;
+    if (lua_isinteger(L, 4)) {
+        conf->cmd_com_mode = luaL_checkinteger(L, 4);
+    }
+    else {
+        conf->cmd_com_mode = ComMode;
+    }
+    
+    if (lua_isinteger(L, 5)) {
+        conf->cmd_rc = luaL_checkinteger(L, 5);
+    }
+    else {
+        conf->cmd_rc = RCosc;
+    }
+
+    if (lua_isinteger(L, 6)) {
+        conf->cmd_sysen = luaL_checkinteger(L, 6);
+    }
+    else {
+        conf->cmd_sysen = Sys_en;
+    }
+
     luat_ht1621_init(conf);
     return 1;
 }

+ 9 - 6
components/ht1621/include/luat_ht1621.h

@@ -18,9 +18,9 @@
 // #define cbi(x, y)  (x &= ~(1 <<y ))  /*清零寄器x的第y位*/  
 
 //IO端口定义
-#define LCD_DATA 4
-#define LCD_WR 5
-#define LCD_CS 6
+// #define LCD_DATA 4
+// #define LCD_WR 5
+// #define LCD_CS 6
 
 #ifndef HIGH
 #define HIGH 1
@@ -31,9 +31,12 @@
 #endif
 
 typedef struct luat_ht1621_conf {
-    int pin_data;
-    int pin_wr;
-    int pin_cs;
+    uint8_t pin_data;
+    uint8_t pin_wr;
+    uint8_t pin_cs;
+    uint8_t cmd_com_mode;
+    uint8_t cmd_rc;
+    uint8_t cmd_sysen;
 }luat_ht1621_conf_t;
 
 //定义端口HT1621数据端口 

+ 3 - 3
components/ht1621/src/luat_ht1621.c

@@ -35,9 +35,9 @@ void luat_ht1621_init(luat_ht1621_conf_t *conf) {
 	luat_gpio_mode(conf->pin_data, LUAT_GPIO_OUTPUT, LUAT_GPIO_PULLUP, 0);
 	luat_gpio_mode(conf->pin_wr, LUAT_GPIO_OUTPUT, LUAT_GPIO_PULLUP, 1);
 	luat_ht1621_lcd(conf, 0);
-	luat_ht1621_write_cmd(conf, Sys_en);
-	luat_ht1621_write_cmd(conf, RCosc);
-	luat_ht1621_write_cmd(conf, ComMode);
+	luat_ht1621_write_cmd(conf, conf->cmd_com_mode);
+	luat_ht1621_write_cmd(conf, conf->cmd_rc);
+	luat_ht1621_write_cmd(conf, conf->cmd_sysen);
 	luat_ht1621_lcd(conf, 1);
 }