Browse Source

add:添加pin库

Dozingfiretruck 4 years ago
parent
commit
cc70c61439
2 changed files with 52 additions and 0 deletions
  1. 9 0
      app/port/luat_base_air101.c
  2. 43 0
      app/port/luat_pin_air101.c

+ 9 - 0
app/port/luat_base_air101.c

@@ -87,6 +87,7 @@ static const luaL_Reg loadedlibs[] = {
 #ifdef LUAT_USE_RTC
   {"rtc", luaopen_rtc},                   // 实时时钟
 #endif
+  {"pin", luaopen_pin},                   // pin
 //-----------------------------------------------------------------------
 // 工具库, 按需选用
 #ifdef LUAT_USE_CRYPTO
@@ -272,6 +273,14 @@ void luat_os_exit_cri(void) {
   tls_os_release_critical(cpu_sr);
 }
 
+void luat_os_irq_disable(uint8_t IRQ_Type) {
+  tls_irq_disable(IRQ_Type);
+}
+
+void luat_os_irq_enable(uint8_t IRQ_Type) {
+  tls_irq_enable(IRQ_Type);
+}
+
 #ifdef LUAT_USE_LVGL
 #include "lvgl.h"
 #endif

+ 43 - 0
app/port/luat_pin_air101.c

@@ -0,0 +1,43 @@
+#include "wm_gpio_afsel.h"
+#include "luat_base.h"
+
+#define LUAT_LOG_TAG "pin"
+#include "luat_log.h"
+
+static int get_pin_index(lua_State *L){
+    char pin_sn[3]={0};
+    int pin_n;
+    const char* pin_name = luaL_checkstring(L, 1);
+    if (memcmp("PA",pin_name, 2)==0){
+        strncpy(pin_sn, pin_name+2, 2);
+        pin_n = atoi(pin_sn);
+        if (pin_n >= 0 && pin_n < 48){
+            lua_pushinteger(L,pin_n);
+            return 1;
+        }else
+            goto error;
+    }else if(memcmp("PB",pin_name, 2)==0){
+        strncpy(pin_sn, pin_name+2, 2);
+        pin_n = atoi(pin_sn);
+        if (pin_n >= 0 && pin_n < 48){
+            lua_pushinteger(L,pin_n+16);
+            return 1;
+        }else
+            goto error;
+    }
+error:
+    LLOGW("pin does not exist");
+    return 0;
+}
+
+#include "rotable.h"
+static const rotable_Reg reg_pin[] =
+{
+    {"__index", get_pin_index, 0},
+	{ NULL, NULL , 0}
+};
+
+LUAMOD_API int luaopen_pin( lua_State *L ) {
+    luat_newlib(L, reg_pin);
+    return 1;
+}