Explorar o código

add: 文档添加常量值展示

chenxuuu %!s(int64=3) %!d(string=hai) anos
pai
achega
c90997fed7
Modificáronse 3 ficheiros con 32 adicións e 1 borrados
  1. 6 0
      luat/modules/luat_lib_uart.c
  2. 18 0
      tools/api_get.py
  3. 8 1
      tools/make_doc_file.py

+ 6 - 0
luat/modules/luat_lib_uart.c

@@ -442,17 +442,23 @@ static const rotable_Reg_t reg_uart[] =
     { "Odd",        ROREG_INT(LUAT_PARITY_ODD)},
     { "Even",       ROREG_INT(LUAT_PARITY_EVEN)},
     { "None",       ROREG_INT(LUAT_PARITY_NONE)},
+    //@const ODD number 奇校验
     { "ODD",        ROREG_INT(LUAT_PARITY_ODD)},
+    //@const EVEN number 偶校验
     { "EVEN",       ROREG_INT(LUAT_PARITY_EVEN)},
+    //@const NONE number 无校验
     { "NONE",       ROREG_INT(LUAT_PARITY_NONE)},
     //高低位顺序
+    //@const LSB number 小端模式
     { "LSB",        ROREG_INT(LUAT_BIT_ORDER_LSB)},
+    //@const MSB number 大端模式
     { "MSB",        ROREG_INT(LUAT_BIT_ORDER_MSB)},
 
     { "tx",      ROREG_FUNC(l_uart_tx)},
     { "rx",       ROREG_FUNC(l_uart_rx)},
 	{ "rx_size",	ROREG_FUNC(l_uart_rx_size)},
 
+    //@const VUART_0 number 虚拟串口0
 	{ "VUART_0",        ROREG_INT(LUAT_VUART_ID_0)},
     { NULL,         ROREG_INT(0) }
 };

+ 18 - 0
tools/api_get.py

@@ -36,6 +36,8 @@ def get_file_list(paths, ext = ".c"):
 # static int l_module_function(lua_State *L) {
 #     //一堆代码
 # }
+#
+#//@const NONE number 无校验
 ########################################################
 #数据结构:
 # modules = [
@@ -46,6 +48,13 @@ def get_file_list(paths, ext = ".c"):
 #         'demo': 'adc',
 #         'video': 'https://xxxxx',
 #         'usage': '--xxxxxxx',
+#         'const': [
+# {
+#    'var':'uart.NONE',
+#    'type':'number',
+#    'summary':'无校验',
+# },
+# ],
 #         'api':[
 #             {
 #                 'api':'adc.read(id)',
@@ -102,6 +111,7 @@ def get_modules(file_list, start="/*", end="*/"):
             module["demo"] = ""
             module["video"] = ""
             module["api"] = []
+            module["const"] = []
         else:
             continue
 
@@ -139,6 +149,14 @@ def get_modules(file_list, start="/*", end="*/"):
             name = re.search(r" *@api *(.+) *",lines[line_now+2],re.I)
             if not name:
                 name = re.search(r" *@function *(.+) *",lines[line_now+2],re.I)
+            #匹配常量
+            const_re = re.search(r"[ \-]*//@const +(.+?) +(.+?) +(.+)",lines[line_now],re.I)
+            if const_re:
+                const = {}
+                const["var"] = module["module"]+"."+const_re.group(1)
+                const["type"] = const_re.group(2)
+                const["summary"] = const_re.group(3)
+                module["const"].append(const)
             if lines[line_now].startswith(start) and name:
                 api = {}
                 api["api"] = name.group(1)

+ 8 - 1
tools/make_doc_file.py

@@ -10,7 +10,7 @@ def make(path,modules,index_text):
 
     doc = open(path+"index.rst", "a+",encoding='utf-8')
     doc.write(index_text)
-    
+
     for module in modules:
         mdoc = open(path+module["module"]+".md", "a+",encoding='utf-8')
         mdoc.write("# "+module["module"]+" - "+module["summary"]+"\n\n")
@@ -28,6 +28,13 @@ def make(path,modules,index_text):
             mdoc.write("**示例**\n\n")
             mdoc.write("```lua\n"+module["usage"]+"\n```\n\n")
 
+        if len(module["const"]) > 0:
+            mdoc.write("## 常量\n\n")
+            mdoc.write("|常量|类型|解释|\n|-|-|-|\n")
+            for const in module["const"]:
+                mdoc.write("|"+const["var"].replace("|","\|")+"|"+const["type"].replace("|","\|")+"|"+const["summary"].replace("|","\|")+"|\n")
+            mdoc.write("\n\n")
+
         doc.write("   "+module["module"]+"\n")
         for api in module["api"]:
             mdoc.write("## "+api["api"]+"\n\n")