Преглед изворни кода

fix: 修正一堆编译警告,使得esp32-idf能接受luatos主库的编译

Wendal Chen пре 4 година
родитељ
комит
56847a3a8b

+ 12 - 0
luat/include/luat_dac.h

@@ -0,0 +1,12 @@
+
+#ifndef LUAT_DAC_H
+#define LUAT_DAC_H
+
+#include "luat_base.h"
+
+int luat_dac_setup(uint32_t ch, uint32_t freq, uint32_t mode);
+int luat_dac_write(uint32_t ch, uint16_t* buff, size_t len);
+int luat_dac_close(uint32_t ch);
+
+#endif
+

+ 1 - 0
luat/include/luat_dbg.h

@@ -28,5 +28,6 @@ void luat_dbg_set_runcb(luat_dbg_cb cb, void* params);
 void luat_dbg_backtrace(void* params);
 void luat_dbg_backtrace(void* params);
 void luat_dbg_vars(void* params);
 void luat_dbg_vars(void* params);
 void luat_dbg_gvars(void* params);
 void luat_dbg_gvars(void* params);
+void luat_dbg_jvars(void *params);
 
 
 #endif
 #endif

+ 1 - 1
luat/include/luat_keyboard.h

@@ -6,7 +6,7 @@ typedef struct luat_keyboard_ctx
 {
 {
     uint16_t port;      // 为多keyboard预留,默认为0
     uint16_t port;      // 为多keyboard预留,默认为0
     uint16_t pin_data;  // pin数据, 需要根据pin_map反推按键
     uint16_t pin_data;  // pin数据, 需要根据pin_map反推按键
-    uint16_t state;     // 1 pressed, 0 release
+    uint32_t state;     // 1 pressed, 0 release
     void* userdata;
     void* userdata;
 }luat_keyboard_ctx_t;
 }luat_keyboard_ctx_t;
 
 

+ 8 - 8
luat/modules/luat_cmux.c

@@ -86,9 +86,9 @@ void uih_shell_manage(unsigned char*buff){
     char send_buff[128] = {0};
     char send_buff[128] = {0};
     unsigned char *data = (unsigned char *)luat_heap_malloc(buff[3]>>1);
     unsigned char *data = (unsigned char *)luat_heap_malloc(buff[3]>>1);
     memcpy(data, buff+4, buff[3]>>1);
     memcpy(data, buff+4, buff[3]>>1);
-    if (strncmp("AT\r", data,3) == 0){
+    if (memcpy("AT\r", data, 3) == 0){
         luat_cmux_write(LUAT_CMUX_CH_SHELL,  CMUX_FRAME_UIH & ~ CMUX_CONTROL_PF,"OK\r", 3);
         luat_cmux_write(LUAT_CMUX_CH_SHELL,  CMUX_FRAME_UIH & ~ CMUX_CONTROL_PF,"OK\r", 3);
-    }else if (strncmp("ATI", data,3) == 0){
+    }else if (memcpy("ATI", data, 3) == 0){
         #ifdef LUAT_BSP_VERSION
         #ifdef LUAT_BSP_VERSION
             sprintf(send_buff, "LuatOS-SoC_%s_%s\r\n", luat_os_bsp(), LUAT_BSP_VERSION);
             sprintf(send_buff, "LuatOS-SoC_%s_%s\r\n", luat_os_bsp(), LUAT_BSP_VERSION);
         #else
         #else
@@ -96,16 +96,16 @@ void uih_shell_manage(unsigned char*buff){
         #endif
         #endif
         luat_cmux_write(LUAT_CMUX_CH_SHELL,  CMUX_FRAME_UIH & ~ CMUX_CONTROL_PF,send_buff, strlen(send_buff));
         luat_cmux_write(LUAT_CMUX_CH_SHELL,  CMUX_FRAME_UIH & ~ CMUX_CONTROL_PF,send_buff, strlen(send_buff));
         luat_cmux_write(LUAT_CMUX_CH_SHELL,  CMUX_FRAME_UIH & ~ CMUX_CONTROL_PF,"OK\r", 3);
         luat_cmux_write(LUAT_CMUX_CH_SHELL,  CMUX_FRAME_UIH & ~ CMUX_CONTROL_PF,"OK\r", 3);
-    }else if (strncmp("AT+LUAFLASHSIZE?", data,16) == 0){
+    }else if (memcpy("AT+LUAFLASHSIZE?", data, 16) == 0){
         #ifdef FLASH_FS_REGION_SIZE
         #ifdef FLASH_FS_REGION_SIZE
             sprintf(send_buff, "+LUAFLASHSIZE: 0X%x\r",FLASH_FS_REGION_SIZE);
             sprintf(send_buff, "+LUAFLASHSIZE: 0X%x\r",FLASH_FS_REGION_SIZE);
             luat_cmux_write(LUAT_CMUX_CH_SHELL,  CMUX_FRAME_UIH & ~ CMUX_CONTROL_PF,send_buff, strlen(send_buff));
             luat_cmux_write(LUAT_CMUX_CH_SHELL,  CMUX_FRAME_UIH & ~ CMUX_CONTROL_PF,send_buff, strlen(send_buff));
             luat_cmux_write(LUAT_CMUX_CH_SHELL,  CMUX_FRAME_UIH & ~ CMUX_CONTROL_PF,"OK\r", 3);
             luat_cmux_write(LUAT_CMUX_CH_SHELL,  CMUX_FRAME_UIH & ~ CMUX_CONTROL_PF,"OK\r", 3);
         #endif
         #endif
-    }else if (strncmp("AT+LUACHECKSUM=", data,15) == 0){
+    }else if (memcpy("AT+LUACHECKSUM=", data, 15) == 0){
         luat_cmux_write(LUAT_CMUX_CH_SHELL,  CMUX_FRAME_UIH & ~ CMUX_CONTROL_PF,"+LUAFLASHSIZE: 0\r", 17);
         luat_cmux_write(LUAT_CMUX_CH_SHELL,  CMUX_FRAME_UIH & ~ CMUX_CONTROL_PF,"+LUAFLASHSIZE: 0\r", 17);
         luat_cmux_write(LUAT_CMUX_CH_SHELL,  CMUX_FRAME_UIH & ~ CMUX_CONTROL_PF,"OK\r", 3);
         luat_cmux_write(LUAT_CMUX_CH_SHELL,  CMUX_FRAME_UIH & ~ CMUX_CONTROL_PF,"OK\r", 3);
-    }else if (strncmp("AT+RESET", data,8) == 0){
+    }else if (memcpy("AT+RESET", data, 8) == 0){
         luat_cmux_write(LUAT_CMUX_CH_SHELL,  CMUX_FRAME_UIH & ~ CMUX_CONTROL_PF,"OK\r", 3);
         luat_cmux_write(LUAT_CMUX_CH_SHELL,  CMUX_FRAME_UIH & ~ CMUX_CONTROL_PF,"OK\r", 3);
         luat_os_reboot(0);
         luat_os_reboot(0);
     }
     }
@@ -113,8 +113,8 @@ void uih_shell_manage(unsigned char*buff){
 }
 }
 
 
 void uih_dbg_manage(unsigned char*buff){
 void uih_dbg_manage(unsigned char*buff){
-    char send_buff[128] = {0};
-    unsigned char *data = (unsigned char *)luat_heap_malloc(buff[3]>>1);
+    //char send_buff[128] = {0};
+    char *data = (char *)luat_heap_malloc(buff[3]>>1);
     memcpy(data, buff+4, buff[3]>>1);
     memcpy(data, buff+4, buff[3]>>1);
     if (strcmp("dbg",strtok(data, " ")) == 0){
     if (strcmp("dbg",strtok(data, " ")) == 0){
         char *command = strtok(NULL, " ");
         char *command = strtok(NULL, " ");
@@ -232,7 +232,7 @@ void luat_cmux_write(int port, uint8_t control,char* buff, size_t len) {
         prefix[3] = 1 | (len << 1);
         prefix[3] = 1 | (len << 1);
     }
     }
     luat_shell_write(prefix, prefix_length);
     luat_shell_write(prefix, prefix_length);
-    postfix[0] = cmux_frame_check(prefix+1, prefix_length - 1);
+    postfix[0] = cmux_frame_check((const uint8_t*)(prefix+1), prefix_length - 1);
     if (len > 0)luat_shell_write(buff, len);
     if (len > 0)luat_shell_write(buff, len);
     luat_shell_write(postfix, 2);
     luat_shell_write(postfix, 2);
 }
 }

+ 61 - 0
luat/modules/luat_lib_dac.c

@@ -0,0 +1,61 @@
+#include "luat_base.h"
+#include "luat_dac.h"
+
+static int l_dac_open(lua_State *L) {
+    int ch = luaL_checkinteger(L, 1);
+    int freq = luaL_checkinteger(L, 2);
+    int mode = luaL_optinteger(L, 3, 0);
+    int ret = luat_dac_setup(ch, freq, mode);
+    lua_pushboolean(L, ret == 0 ? 1 : 0);
+    lua_pushinteger(L, ret);
+    return 2;
+}
+
+static int l_dac_write(lua_State *L) {
+    uint16_t* buff;
+    size_t len;
+    int ch;
+    uint16_t value;
+
+    ch = luaL_checkinteger(L, 1);
+    if (lua_isinteger(L, 2)) {
+        value = luaL_checkinteger(L, 2);
+        buff = &value;
+        len = 1;
+    }
+    else if (lua_isuserdata(L, 2)) {
+        return 0; // TODO 支持zbuff
+    }
+    else if (lua_isstring(L, 2)) {
+        buff = (uint16_t*)luaL_checklstring(L, 2, &len);
+    }
+    else {
+        return 0;
+    }
+    int ret = luat_dac_write(ch, buff, len);
+    lua_pushboolean(L, ret == 0 ? 1 : 0);
+    lua_pushinteger(L, ret);
+    return 2;
+}
+
+static int l_dac_close(lua_State *L) {
+    int ch = luaL_checkinteger(L, 1);
+    int ret = luat_dac_close(ch);
+    lua_pushboolean(L, ret == 0 ? 1 : 0);
+    lua_pushinteger(L, ret);
+    return 2;
+}
+
+#include "rotable.h"
+static const rotable_Reg reg_dac[] =
+{
+    { "open" ,       l_dac_open , 0},
+    { "write" ,      l_dac_write , 0},
+    { "close" ,      l_dac_close, 0},
+	{ NULL,          NULL ,       0}
+};
+
+LUAMOD_API int luaopen_dac( lua_State *L ) {
+    luat_newlib(L, reg_dac);
+    return 1;
+}

+ 2 - 2
luat/modules/luat_lib_dbg.c

@@ -237,11 +237,11 @@ void luat_dbg_vars(void *params) {
 
 
     if (lua_getstack(dbg_L, level, dbg_ar) == 1) {
     if (lua_getstack(dbg_L, level, dbg_ar) == 1) {
         int index = 1;
         int index = 1;
-        int valtype = 0;
+        //int valtype = 0;
         char *buff;
         char *buff;
         int ret;
         int ret;
         size_t valstrlen = 0;
         size_t valstrlen = 0;
-        size_t valoutlen = 0;
+        //size_t valoutlen = 0;
         while (1) {
         while (1) {
             const char* varname = lua_getlocal(dbg_L, dbg_ar, index);
             const char* varname = lua_getlocal(dbg_L, dbg_ar, index);
             if (varname) {
             if (varname) {

+ 5 - 5
luat/modules/luat_lib_i2c.c

@@ -237,7 +237,7 @@ i2c发送数据
 i2c.send(1, 0x5C, string.char(0x0F, 0x2F))
 i2c.send(1, 0x5C, string.char(0x0F, 0x2F))
 */
 */
 static int l_i2c_send(lua_State *L) {
 static int l_i2c_send(lua_State *L) {
-    int id;
+    int id = 0;
     if(!lua_isuserdata(L, 1)){
     if(!lua_isuserdata(L, 1)){
         id = luaL_checkinteger(L, 1);
         id = luaL_checkinteger(L, 1);
     }
     }
@@ -290,7 +290,7 @@ i2c接收数据
 local data = i2c.recv(1, 0x5C, 2)
 local data = i2c.recv(1, 0x5C, 2)
 */
 */
 static int l_i2c_recv(lua_State *L) {
 static int l_i2c_recv(lua_State *L) {
-    int id;
+    int id = 0;
     if(!lua_isuserdata(L, 1)){
     if(!lua_isuserdata(L, 1)){
         id = luaL_checkinteger(L, 1);
         id = luaL_checkinteger(L, 1);
     }
     }
@@ -329,7 +329,7 @@ i2c写寄存器数据
 i2c.writeReg(1, 0x5C, 0x01, string.char(0x00, 0xF2))
 i2c.writeReg(1, 0x5C, 0x01, string.char(0x00, 0xF2))
 */
 */
 static int l_i2c_write_reg(lua_State *L) {
 static int l_i2c_write_reg(lua_State *L) {
-    int id;
+    int id = 0;
     if(!lua_isuserdata(L, 1)){
     if(!lua_isuserdata(L, 1)){
         id = luaL_checkinteger(L, 1);
         id = luaL_checkinteger(L, 1);
     }
     }
@@ -368,7 +368,7 @@ i2c读寄存器数据
 i2c.readReg(1, 0x5C, 0x01, 2)
 i2c.readReg(1, 0x5C, 0x01, 2)
 */
 */
 static int l_i2c_read_reg(lua_State *L) {
 static int l_i2c_read_reg(lua_State *L) {
-    int id;
+    int id = 0;
     if(!lua_isuserdata(L, 1)){
     if(!lua_isuserdata(L, 1)){
         id = luaL_checkinteger(L, 1);
         id = luaL_checkinteger(L, 1);
     }
     }
@@ -442,7 +442,7 @@ if re then
 end
 end
 */
 */
 static int l_i2c_readDHT12(lua_State *L) {
 static int l_i2c_readDHT12(lua_State *L) {
-    int id;
+    int id = 0;
     if(!lua_isuserdata(L, 1)){
     if(!lua_isuserdata(L, 1)){
         id = luaL_checkinteger(L, 1);
         id = luaL_checkinteger(L, 1);
     }
     }

+ 1 - 1
luat/modules/luat_lib_log.c

@@ -164,7 +164,7 @@ static const rotable_Reg reg_log[] =
     { "LOG_INFO",   NULL, LUAT_LOG_INFO},
     { "LOG_INFO",   NULL, LUAT_LOG_INFO},
     { "LOG_WARN",   NULL, LUAT_LOG_WARN},
     { "LOG_WARN",   NULL, LUAT_LOG_WARN},
     { "LOG_ERROR",  NULL, LUAT_LOG_ERROR},
     { "LOG_ERROR",  NULL, LUAT_LOG_ERROR},
-	{ NULL, NULL }
+	{ NULL, NULL, 0}
 };
 };
 
 
 LUAMOD_API int luaopen_log( lua_State *L ) {
 LUAMOD_API int luaopen_log( lua_State *L ) {

+ 13 - 4
luat/modules/luat_lib_mqttcore.c

@@ -391,6 +391,9 @@ static size_t _mqtt_unpack_P(lua_State *L, char* ptr) {
 
 
 static int l_mqttcore_unpack(lua_State *L) {
 static int l_mqttcore_unpack(lua_State *L) {
 	size_t slen = 0;
 	size_t slen = 0;
+	size_t nextpos = 0;
+	uint32_t packetId = 0;
+
 	char* data = (char*)luaL_checklstring(L, 1, &slen);
 	char* data = (char*)luaL_checklstring(L, 1, &slen);
 	if (slen < 2) {
 	if (slen < 2) {
 		return 0;
 		return 0;
@@ -451,7 +454,7 @@ static int l_mqttcore_unpack(lua_State *L) {
 	lua_pushinteger(L, retain);
 	lua_pushinteger(L, retain);
 	lua_settable(L, -3);
 	lua_settable(L, -3);
 
 
-	size_t nextpos = poffset+1;
+	nextpos = poffset+1;
 
 
 	switch(id) {
 	switch(id) {
 	case CONNACK:
 	case CONNACK:
@@ -470,7 +473,10 @@ static int l_mqttcore_unpack(lua_State *L) {
 			lua_settable(L, -3);
 			lua_settable(L, -3);
 			if (qos > 0) {
 			if (qos > 0) {
 				lua_pushliteral(L, "packetId");
 				lua_pushliteral(L, "packetId");
-				lua_pushinteger(L, (0xFF & data[nextpos++]) * 256 + (0xFF & data[nextpos++]));
+				packetId = 0xFF & data[nextpos++];
+				packetId = packetId * 256;
+				packetId = packetId + (0xFF & data[nextpos++]);
+				lua_pushinteger(L, packetId);
 				lua_settable(L, -3);
 				lua_settable(L, -3);
 				//LLOGD("nextpos %d after packetId", nextpos);
 				//LLOGD("nextpos %d after packetId", nextpos);
 			}
 			}
@@ -483,7 +489,10 @@ static int l_mqttcore_unpack(lua_State *L) {
 	case PINGRESP:
 	case PINGRESP:
 			if (dlen) {
 			if (dlen) {
 				lua_pushliteral(L, "packetId");
 				lua_pushliteral(L, "packetId");
-				lua_pushinteger(L, (0xFF & data[nextpos++]) * 256 + (0xFF & data[nextpos++]));
+				packetId = 0xFF & data[nextpos++];
+				packetId = packetId * 256;
+				packetId = packetId + (0xFF & data[nextpos++]);
+				lua_pushinteger(L, packetId);
 				lua_settable(L, -3);
 				lua_settable(L, -3);
 			}
 			}
 			break;
 			break;
@@ -505,7 +514,7 @@ static const rotable_Reg reg_mqttcore[] =
 	{ "packZeroData",   l_mqttcore_packZeroData,0},
 	{ "packZeroData",   l_mqttcore_packZeroData,0},
 	{ "packUNSUBSCRIBE",l_mqttcore_packUNSUBSCRIBE,0},
 	{ "packUNSUBSCRIBE",l_mqttcore_packUNSUBSCRIBE,0},
 	{ "unpack",  		l_mqttcore_unpack, 0},
 	{ "unpack",  		l_mqttcore_unpack, 0},
-	{ NULL, NULL }
+	{ NULL, NULL , 0}
 };
 };
 
 
 LUAMOD_API int luaopen_mqttcore( lua_State *L ) {
 LUAMOD_API int luaopen_mqttcore( lua_State *L ) {

+ 1 - 0
luat/modules/luat_lib_uart.c

@@ -131,6 +131,7 @@ static int l_uart_write(lua_State *L)
     {
     {
         luat_zbuff_t *buff = ((luat_zbuff_t *)luaL_checkudata(L, 2, LUAT_ZBUFF_TYPE));
         luat_zbuff_t *buff = ((luat_zbuff_t *)luaL_checkudata(L, 2, LUAT_ZBUFF_TYPE));
         len = buff->len - buff->cursor;
         len = buff->len - buff->cursor;
+        buf = (const char *)(buff->addr + buff->cursor);
     }
     }
     else
     else
     {
     {

+ 1 - 1
luat/modules/luat_lib_vmx.c

@@ -134,7 +134,7 @@ static int vm2vm_copy(int index, lua_State *Lsrc, lua_State *Ldst) {
         lua_pushnumber(Ldst, lua_tonumber(Lsrc, index));
         lua_pushnumber(Ldst, lua_tonumber(Lsrc, index));
     }
     }
     else if (lua_isstring(Lsrc, index)) {
     else if (lua_isstring(Lsrc, index)) {
-        int str_len = 0;
+        size_t str_len = 0;
         const char* tmp = luaL_checklstring(Lsrc, index, &str_len);
         const char* tmp = luaL_checklstring(Lsrc, index, &str_len);
         lua_pushlstring(Ldst, tmp, str_len);
         lua_pushlstring(Ldst, tmp, str_len);
     }
     }

+ 2 - 2
luat/modules/luat_shell.c

@@ -139,7 +139,7 @@ static int luat_shell_loadstr(lua_State *L, void* ptr) {
 }
 }
 
 
 void luat_shell_push(char* uart_buff, size_t rcount) {
 void luat_shell_push(char* uart_buff, size_t rcount) {
-    int ret = 0;
+    //int ret = 0;
     int len = 0;
     int len = 0;
     char buff[128] = {0};
     char buff[128] = {0};
     if (rcount) {
     if (rcount) {
@@ -225,5 +225,5 @@ void luat_shell_push(char* uart_buff, size_t rcount) {
             }
             }
         }
         }
     }
     }
-    return 0;
+    return;
 }
 }

+ 0 - 13
luat/vfs/luat_vfs.c

@@ -166,19 +166,6 @@ FILE* luat_fs_fopen(const char *filename, const char *mode) {
     return NULL;
     return NULL;
 }
 }
 
 
-// #define vfs_fopt(name, ...) luat_fs_##name(FILE* stream) {\
-//     luat_vfs_fd_t* fd = getfd(stream);\
-//     if (fd == NULL || fd->fsMount->fs->fopts.name == NULL) \
-//         return 0;\
-//     return fd->fsMount->fs->fopts.name(fd->fsMount->userdata, fd->fd);\
-// }
-
-// int  vfs_fopt(getc)
-// int  vfs_fopt(ftell)
-// int  vfs_fopt(fclose)
-// int  vfs_fopt(feof)
-// int  vfs_fopt(ferror)
-
 int luat_fs_feof(FILE* stream) {
 int luat_fs_feof(FILE* stream) {
     //LLOGD("call %s %d","feof", ((int)stream) - 1);
     //LLOGD("call %s %d","feof", ((int)stream) - 1);
     luat_vfs_fd_t* fd = getfd(stream);
     luat_vfs_fd_t* fd = getfd(stream);