Ver código fonte

add: 添加touchkey支持

Wendal Chen 4 anos atrás
pai
commit
9cb6fe1456

+ 3 - 0
app/port/luat_base_air101.c

@@ -92,6 +92,9 @@ static const luaL_Reg loadedlibs[] = {
 #endif
 #ifdef LUAT_USE_OTP
   {"otp", luaopen_otp},                   // OTP
+#endif
+#ifdef LUAT_USE_TOUCHKEY
+  {"touchkey", luaopen_touchkey},              // OTP
 #endif
   {"pin", luaopen_pin},                   // pin
 //-----------------------------------------------------------------------

+ 1 - 0
app/port/luat_conf_bsp.h

@@ -40,6 +40,7 @@
 #define LUAT_USE_LCDSEG 1
 // OTP
 #define LUAT_USE_OTP 1
+#define LUAT_USE_TOUCHKEY 1
 
 //----------------------------
 // 常用工具库, 按需启用, cjson和pack是强烈推荐启用的

+ 65 - 0
app/port/luat_touchkey_air101.c

@@ -0,0 +1,65 @@
+#include "luat_base.h"
+#include "luat_touchkey.h"
+#include "luat_msgbus.h"
+
+#include "wm_include.h"
+#include "wm_touchsensor.h"
+#include "wm_gpio_afsel.h"
+#include "wm_io.h"
+#include "wm_regs.h"
+
+static enum tls_io_name touchkeymap[] = {
+  WM_IO_PA_00, // NOP
+  WM_IO_PA_07, /*touch sensor 1*/
+  WM_IO_PA_09, /*touch sensor 2*/
+  WM_IO_PA_10, /*touch sensor 3*/
+  WM_IO_PB_00, /*touch sensor 4*/			
+  WM_IO_PB_01, /*touch sensor 5*/			
+  WM_IO_PB_02, /*touch sensor 6*/			
+  WM_IO_PB_03, /*touch sensor 7*/			
+  WM_IO_PB_04, /*touch sensor 8*/			
+  WM_IO_PB_05, /*touch sensor 9*/			
+  WM_IO_PB_06, /*touch sensor 10*/			
+  WM_IO_PB_07, /*touch sensor 11*/			
+  WM_IO_PB_08, /*touch sensor 12*/			
+  WM_IO_PB_09, /*touch sensor 13*/
+  WM_IO_PA_12, /*touch sensor 14*/
+  WM_IO_PA_14, /*touch sensor 15*/
+};
+
+static void luat_touchkey_cb(uint32_t value) {
+    rtos_msg_t msg;
+    msg.handler = l_touchkey_handler;
+    msg.ptr = NULL;
+	for (uint8_t i = 0; i < 15; i++)
+	{
+		if (value&BIT(i))
+		{
+			msg.arg1 = i + 1;
+            msg.arg2 = tls_touchsensor_countnum_get(i+1);
+			luat_msgbus_put(&msg, 0);
+		}	
+	}
+}
+
+
+int luat_touchkey_setup(luat_touchkey_conf_t *conf) {
+    if (conf->id < 1 || conf->id > 15 )
+        return -1;
+    wm_touch_sensor_config(touchkeymap[(enum tls_io_name)conf->id]);
+    tls_touchsensor_init_config(conf->id, conf->scan_period, conf->window, 1);
+    tls_touchsensor_irq_enable(conf->id);
+    tls_touchsensor_irq_register(luat_touchkey_cb);
+    if (conf->threshold)
+        tls_touchsensor_threshold_config(conf->id, conf->threshold);
+    return 0;
+}
+
+int luat_touchkey_close(uint8_t id) {
+    if (id < 1 || id > 15 )
+        return -1;
+    tls_touchsensor_irq_disable(id);
+    tls_touchsensor_deinit(id);
+    return 0;
+}
+