소스 검색

add: 添加对otp库的适配

Wendal Chen 4 년 전
부모
커밋
9f980da3a7
3개의 변경된 파일42개의 추가작업 그리고 2개의 파일을 삭제
  1. 3 0
      app/port/luat_base_air101.c
  2. 4 2
      app/port/luat_conf_bsp.h
  3. 35 0
      app/port/luat_otp_air101.c

+ 3 - 0
app/port/luat_base_air101.c

@@ -89,6 +89,9 @@ static const luaL_Reg loadedlibs[] = {
 #endif
 #ifdef LUAT_USE_RTC
   {"rtc", luaopen_rtc},                   // 实时时钟
+#endif
+#ifdef LUAT_USE_OTP
+  {"otp", luaopen_otp},                   // OTP
 #endif
   {"pin", luaopen_pin},                   // pin
 //-----------------------------------------------------------------------

+ 4 - 2
app/port/luat_conf_bsp.h

@@ -38,6 +38,8 @@
 #define LUAT_USE_SDIO 1
 // 段码屏/段式屏, 按需启用
 #define LUAT_USE_LCDSEG 1
+// OTP
+#define LUAT_USE_OTP 1
 
 //----------------------------
 // 常用工具库, 按需启用, cjson和pack是强烈推荐启用的
@@ -69,9 +71,9 @@
 // 高级功能, 其中shell是推荐启用, 除非你打算uart0也读数据
 #define LUAT_USE_SHELL 1
 // NIMBLE 是蓝牙功能, 名为BLE, 但绝非低功耗.
-#define LUAT_USE_NIMBLE 1
+// #define LUAT_USE_NIMBLE 1
 // FDB 提供kv数据库, 与nvm库类似
-#define LUAT_USE_FDB 1
+// #define LUAT_USE_FDB 1
 // 多虚拟机支持,实验性,一般不启用
 // #define LUAT_USE_VMX 1
 

+ 35 - 0
app/port/luat_otp_air101.c

@@ -0,0 +1,35 @@
+#include "luat_base.h"
+#include "luat_otp.h"
+
+#include "wm_include.h"
+#include "wm_internal_flash.h"
+
+
+int luat_otp_read(int zone, char* buff, size_t offset, size_t len) {
+    if (zone < 0 || zone > 2)
+        return -1;
+    int addr = (zone + 1) * 0x1000 + offset;
+    if (tls_fls_otp_read(addr, (u8*)buff, len) == TLS_FLS_STATUS_OK) {
+        return len;
+    }
+    return -1;
+}
+
+int luat_otp_write(int zone, char* buff, size_t offset, size_t len) {
+    if (zone < 0 || zone > 2)
+        return -1;
+    int addr = (zone + 1) * 0x1000 + offset;
+    if (tls_fls_otp_write(addr, (u8*)buff, len) == TLS_FLS_STATUS_OK) {
+        return 0;
+    }
+    return -1;
+}
+
+int luat_otp_erase(int zone, size_t offset, size_t len) {
+    return 0; // 无需主动擦除
+}
+
+int luat_otp_lock(int zone) {
+    tls_fls_otp_lock();
+    return 0;
+}