Просмотр исходного кода

add: 支持获取硬件版本号, 当前仅Air780E系列有用到

https://gitee.com/openLuat/LuatOS/issues/I7NQHZ
Wendal Chen 2 лет назад
Родитель
Сommit
418d8bd749
3 измененных файлов с 38 добавлено и 8 удалено
  1. 2 0
      components/hmeta/luat_hmeta.h
  2. 35 7
      components/hmeta/luat_lib_hmeta.c
  3. 1 1
      demo/hmeta/main.lua

+ 2 - 0
components/hmeta/luat_hmeta.h

@@ -4,6 +4,8 @@
 
 // 获取模块的设备类型, 原始需求是区分Air780E和Air600E
 int luat_hmeta_model_name(char* buff);
+// 获取硬件版本号, 例如A11, A14
+int luat_hmeta_hwversion(char* buff);
 
 
 // -------------------------------------------------------

+ 35 - 7
components/hmeta/luat_lib_hmeta.c

@@ -46,20 +46,48 @@ static int l_hmeta_model(lua_State *L) {
     return 1;
 }
 
-static int l_hmeta_gpio(lua_State *L) {
-    return 0;
+/*
+获取模组的硬件版本号
+@api hmeta.hwver()
+@return string 若能识别到,返回模组类型, 否则会是nil
+@usage
+sys.taskInit(function()
+    while 1 do
+        sys.wait(3000)
+        -- hmeta识别底层模组类型的
+        -- 不同的模组可以使用相同的bsp,但根据封装的不同,根据内部数据仍可识别出具体模块
+        log.info("hmeta", hmeta.model(), hmeta.hwver())
+        log.info("bsp",   rtos.bsp())
+    end
+end)
+*/
+static int l_hmeta_hwver(lua_State *L) {
+    char buff[40] = {0};
+    luat_hmeta_hwversion(buff);
+    if (strlen(buff)) {
+        lua_pushstring(L, buff);
+    }
+    else {
+        lua_pushnil(L);
+    }
+    return 1;
 }
 
-static int l_hmeta_uart(lua_State *L) {
-    return 0;
-}
+// static int l_hmeta_gpio(lua_State *L) {
+//     return 0;
+// }
+
+// static int l_hmeta_uart(lua_State *L) {
+//     return 0;
+// }
 
 #include "rotable2.h"
 static const rotable_Reg_t reg_hmeta[] =
 {
     { "model" ,           ROREG_FUNC(l_hmeta_model)},
-    { "gpio" ,            ROREG_FUNC(l_hmeta_gpio)},
-    { "uart" ,            ROREG_FUNC(l_hmeta_uart)},
+    { "hwver" ,           ROREG_FUNC(l_hmeta_hwver)},
+    // { "gpio" ,            ROREG_FUNC(l_hmeta_gpio)},
+    // { "uart" ,            ROREG_FUNC(l_hmeta_uart)},
 	{ NULL,               ROREG_INT(0)}
 };
 

+ 1 - 1
demo/hmeta/main.lua

@@ -17,7 +17,7 @@ sys.taskInit(function()
     while 1 do
         -- hmeta识别底层模组类型的
         -- 不同的模组可以使用相同的bsp,但根据封装的不同,根据内部数据仍可识别出具体模块
-        log.info("hmeta", hmeta.model())
+        log.info("hmeta", hmeta.model(), hmeta.hwver and hmeta.hwver())
         log.info("bsp",   rtos.bsp())
         sys.wait(3000)
     end