Переглянути джерело

update: luat_gpio_setup也支持alt_func

Wendal Chen 2 роки тому
батько
коміт
3cb00843ce
2 змінених файлів з 7 додано та 19 видалено
  1. 6 5
      luat/include/luat_gpio_legacy.h
  2. 1 14
      luat/modules/luat_lib_gpio.c

+ 6 - 5
luat/include/luat_gpio_legacy.h

@@ -32,13 +32,14 @@ typedef int (*luat_gpio_irq_cb)(int pin, void* args);
 
 typedef struct luat_gpio
 {
-    int pin;
-    int mode;
-    int pull;
-    int irq;
+    int pin;/**<引脚*/
+    int mode;/**<GPIO模式*/
+    int pull;/**<GPIO上下拉模式*/
+    int irq;/**<GPIO中断模式*/
     int lua_ref;
-    luat_gpio_irq_cb irq_cb;
+    luat_gpio_irq_cb irq_cb;/**<中断处理函数*/
     void* irq_args;
+    int alt_func;
 } luat_gpio_t;
 
 int luat_gpio_setup(luat_gpio_t* gpio);

+ 1 - 14
luat/modules/luat_lib_gpio.c

@@ -202,23 +202,10 @@ static int l_gpio_setup(lua_State *L) {
     }
     conf.pull = luaL_optinteger(L, 3, default_gpio_pull);
     conf.irq_cb = 0;
-#ifdef CHIP_EC618
-    int re;
     if (lua_isinteger(L, 5)) {
-    	cfg.alt_fun = luaL_optinteger(L, 5, 0);
-    	cfg.pin = conf.pin;
-    	cfg.pull = conf.pull;
-    	cfg.mode = conf.mode;
-    	cfg.irq_type = conf.irq;
-    	cfg.output_level = conf.irq;
-    	re = luat_gpio_open(&cfg);
+        conf.alt_func = luaL_checkinteger(L, 5);
     }
-    else {
-    	re = luat_gpio_setup(&conf);
-    }
-#else
     int re = luat_gpio_setup(&conf);
-#endif
     if (re != 0) {
         LLOGW("gpio setup fail pin=%d", conf.pin);
         return 0;