20150415.diff0000644000175000017500000000732312513417075011271 0ustar eyaleyaldiff --git a/Makefile b/Makefile index 85bc27a..0012921 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,7 @@ # copyright (c) 2010 Espressif System # +SDKDIR = /opt/Espressif/ESP8266_SDK + ifndef PDIR endif @@ -243,6 +245,6 @@ $(foreach image,$(GEN_IMAGES),$(eval $(call MakeImage,$(basename $(image))))) # Required for each makefile to inherit from the parent # -INCLUDES := $(INCLUDES) -I $(PDIR)include -I $(PDIR)include/$(TARGET) +INCLUDES := $(INCLUDES) -I $(PDIR)include -I $(PDIR)include/$(TARGET) -I $(SDKDIR)/include PDIR := ../$(PDIR) sinclude $(PDIR)Makefile diff --git a/app/Makefile b/app/Makefile index 4d04d7f..99a3dfc 100644 --- a/app/Makefile +++ b/app/Makefile @@ -89,7 +89,7 @@ COMPONENTS_eagle.app.v6 = \ modules/libmodules.a LINKFLAGS_eagle.app.v6 = \ - -L../lib \ + -L../lib -L$(SDKDIR)/lib \ -Wl,--gc-sections \ -Xlinker -Map=mapfile \ -nostdlib \ diff --git a/app/include/user_modules.h b/app/include/user_modules.h index d8ddc65..ef64665 100644 --- a/app/include/user_modules.h +++ b/app/include/user_modules.h @@ -18,19 +18,20 @@ #define LUA_USE_MODULES_GPIO #define LUA_USE_MODULES_WIFI #define LUA_USE_MODULES_NET -#define LUA_USE_MODULES_PWM -#define LUA_USE_MODULES_I2C -#define LUA_USE_MODULES_SPI +#undef LUA_USE_MODULES_PWM +#undef LUA_USE_MODULES_I2C +#undef LUA_USE_MODULES_SPI #define LUA_USE_MODULES_TMR -#define LUA_USE_MODULES_ADC -#define LUA_USE_MODULES_UART +#undef LUA_USE_MODULES_ADC +#undef LUA_USE_MODULES_UART #define LUA_USE_MODULES_OW #define LUA_USE_MODULES_BIT -#define LUA_USE_MODULES_MQTT -#define LUA_USE_MODULES_COAP -#define LUA_USE_MODULES_U8G -#define LUA_USE_MODULES_WS2812 -#define LUA_USE_MODULES_CJSON +#undef LUA_USE_MODULES_MQTT +#undef LUA_USE_MODULES_COAP +#undef LUA_USE_MODULES_U8G +#undef LUA_USE_MODULES_WS2812 +#undef LUA_USE_MODULES_CJSON +#define LUA_USE_MODULES_MISC #endif /* LUA_USE_MODULES */ #endif /* __USER_MODULES_H__ */ diff --git a/app/include/user_version.h b/app/include/user_version.h index bc64f36..162cd18 100644 --- a/app/include/user_version.h +++ b/app/include/user_version.h @@ -1,12 +1,12 @@ #ifndef __USER_VERSION_H__ #define __USER_VERSION_H__ -#define NODE_VERSION_MAJOR 0U -#define NODE_VERSION_MINOR 9U -#define NODE_VERSION_REVISION 5U +#define NODE_VERSION_MAJOR 1U +#define NODE_VERSION_MINOR 0U +#define NODE_VERSION_REVISION 1U #define NODE_VERSION_INTERNAL 0U -#define NODE_VERSION "NodeMCU 0.9.5" -#define BUILD_DATE "build 20150318" +#define NODE_VERSION "NodeMCU 1.0.1b2" +#define BUILD_DATE "build 20150414-1727-eyal+test" #endif /* __USER_VERSION_H__ */ diff --git a/app/modules/auxmods.h b/app/modules/auxmods.h index 149b1af..5842872 100644 --- a/app/modules/auxmods.h +++ b/app/modules/auxmods.h @@ -82,6 +82,9 @@ LUALIB_API int ( luaopen_ow )( lua_State *L ); #define AUXLIB_CJSON "cjson" LUALIB_API int ( luaopen_ow )( lua_State *L ); +#define AUXLIB_MISC "misc" +LUALIB_API int ( luaopen_misc )( lua_State *L ); + // Helper macros #define MOD_CHECK_ID( mod, id )\ if( !platform_ ## mod ## _exists( id ) )\ diff --git a/app/modules/modules.h b/app/modules/modules.h index fddc45c..b859259 100644 --- a/app/modules/modules.h +++ b/app/modules/modules.h @@ -149,6 +149,14 @@ #define ROM_MODULES_CJSON #endif +#if defined(LUA_USE_MODULES_MISC) +#define MODULES_MISC "misc" +#define ROM_MODULES_MISC \ + _ROM(MODULES_MISC, luaopen_misc, misc_map) +#else +#define ROM_MODULES_MISC +#endif + #define LUA_MODULES_ROM \ ROM_MODULES_GPIO \ ROM_MODULES_PWM \ @@ -167,7 +175,8 @@ ROM_MODULES_OW \ ROM_MODULES_BIT \ ROM_MODULES_WS2812 \ - ROM_MODULES_CJSON + ROM_MODULES_CJSON \ + ROM_MODULES_MISC #endif app/modules/misc.c0000664000175000017500000002133612513140467013065 0ustar eyaleyal// Eyal's misc functions //#include "lua.h" #include "lualib.h" #include "lauxlib.h" #include "platform.h" #include "auxmods.h" #include "lrotable.h" #include "c_types.h" #include "c_string.h" #include //#define RTC_USER_MEM_START 256 // bytes, as documented //#define RTC_USER_MEM_SIZE 512 // bytes #define RTC_USER_MEM_START 64 // bytes, as working #define RTC_USER_MEM_SIZE 128 // bytes #define RTC_USER_MEM_END (RTC_USER_MEM_START+RTC_USER_MEM_SIZE) #define RTC_USER_MEM_BLOCK_SHIFT 2 #define RTC_USER_MEM_BLOCK_SIZE (1 << RTC_USER_MEM_BLOCK_SHIFT) #define RTC_USER_MEM_BLOCK_MASK (RTC_USER_MEM_BLOCK_SIZE - 1) #define RTC_USER_MEM_ADDR_CHECK(nargs) \ int _nargs = (nargs); \ if( _nargs >= 0 && _nargs != lua_gettop( L ) ) \ return luaL_error( L, "wrong number of arguments" ); \ uint32_t addr = luaL_checkinteger(L, 1); \ if (addr < 0 || addr >= 768*2) \ return luaL_error(L, "bad address [0-767*2]") \ /*if (addr < RTC_USER_MEM_START || addr >= RTC_USER_MEM_END || (addr & RTC_USER_MEM_BLOCK_MASK)) \ return luaL_error(L, "bad address [4 aligned, 64-124]")*/ // Lua: rtc_mem_read(addr, size) // array should fall inside START...END static int misc_rtc_mem_read(lua_State* L) { RTC_USER_MEM_ADDR_CHECK (2); uint32_t size = luaL_checkinteger(L, 2); if (size < 1 || addr+size > RTC_USER_MEM_END) return luaL_error(L, "bad size"); /* addr = RTC_USER_MEM_START + (addr >> 2);*/ luaL_Buffer b; luaL_buffinit( L, &b ); char *p = luaL_prepbuffer(&b); if (!system_rtc_mem_read((uint8)addr, (void *)p, (uint16)size)) return luaL_error(L, "rtc memory read failed"); luaL_addsize(&b, size); luaL_pushresult( &b ); return 1; } #define RTC_USER_MEM_WRITE_BYTE(data) \ do { \ int c = (data); \ if( c < 0 || c > 255 ) \ return luaL_error( L, "wrong arg range" ); \ block[nb++] = (char)c; \ if ( RTC_USER_MEM_BLOCK_SIZE == nb ) { \ if (!system_rtc_mem_write(addr, block, (uint16)RTC_USER_MEM_BLOCK_SIZE)) \ break; \ nb = 0; \ ++addr; \ wrote += RTC_USER_MEM_BLOCK_SIZE; \ } \ if (++addr >= RTC_USER_MEM_SIZE) \ break; \ } while (0) // Lua: wrote = rtc_mem_write( addr, data1, [data2], ..., [datan] ) // array should fall inside START...END // data can be either a string, a table or an 8-bit number static int misc_rtc_mem_write(lua_State* L) { if( lua_gettop( L ) < 2 ) return luaL_error( L, "wrong number of arguments" ); RTC_USER_MEM_ADDR_CHECK (-1); const char *pdata; size_t datalen, i; uint8_t block[RTC_USER_MEM_BLOCK_SIZE]; u32 wrote = 0; unsigned argn; int nb = 0; for( argn = 2; argn <= lua_gettop( L ); argn ++ ) { // lua_isnumber() would silently convert a string of digits to an integer // whereas here strings are handled separately. if( lua_type( L, argn ) == LUA_TNUMBER ) { RTC_USER_MEM_WRITE_BYTE (( int )luaL_checkinteger( L, argn )); } else if( lua_istable( L, argn ) ) { datalen = lua_objlen( L, argn ); for( i = 0; i < datalen; i ++ ) { lua_rawgeti( L, argn, i + 1 ); RTC_USER_MEM_WRITE_BYTE (( int )luaL_checkinteger( L, -1 )); lua_pop( L, 1 ); } if( i < datalen ) break; } else { pdata = luaL_checklstring( L, argn, &datalen ); for( i = 0; i < datalen; i ++ ) RTC_USER_MEM_WRITE_BYTE (pdata[i]); if( i < datalen ) break; } } if (nb > 0) { if (system_rtc_mem_write(addr, block, (uint16)nb)) wrote += nb; } lua_pushinteger( L, wrote ); return 1; } #undef RTC_USER_MEM_WRITE_BYTE static int misc_rtc_mem_read_int(lua_State* L) { RTC_USER_MEM_ADDR_CHECK (2); uint32_t size = luaL_checkinteger(L, 2); if (size < 1 || size > RTC_USER_MEM_BLOCK_SIZE) return luaL_error(L, "bad size [1...4]"); unsigned char block[RTC_USER_MEM_BLOCK_SIZE]; if (!system_rtc_mem_read((uint8)addr, (void *)block, (uint16)size)) { // return luaL_error(L, "rtc memory read failed"); return 0; } int nb; uint32_t data = 0; for (nb = 0; nb < size; ++nb) data = (data << 8) + block[nb]; #if 000 char str[40]; c_sprintf (str, "a=%d s=%d b=%d,%d,%d,%d d=0x%lx", addr, size, block[0], block[1], block[2], block[3], data); return luaL_error(L, str); #endif lua_pushinteger( L, data); return 1; } static int misc_rtc_mem_write_int(lua_State* L) { RTC_USER_MEM_ADDR_CHECK (3); uint32_t size = luaL_checkinteger(L, 2); if (size < 1 || size > RTC_USER_MEM_BLOCK_SIZE) return luaL_error(L, "bad size"); uint32_t data = luaL_checkinteger(L, 3); unsigned char block[RTC_USER_MEM_BLOCK_SIZE]; int nb; for (nb = size; nb-- > 0;) { block[nb] = data & 0x0ff; data >>= 8; } #if 000 char str[30]; c_sprintf (str, "addr=%d block=%d,%d,%d,%d", addr, block[0], block[1], block[2], block[3]); return luaL_error(L, str); #endif lua_pushboolean( L, system_rtc_mem_write(addr, block, (uint16)size)); return 1; } static int misc_rtc_mem_clear(lua_State* L) /* DEBUG */ { RTC_USER_MEM_ADDR_CHECK (2); uint32_t size = luaL_checkinteger(L, 2); if (size < 1 || addr+size > 768) return luaL_error(L, "bad size"); luaL_Buffer b; luaL_buffinit( L, &b ); char *p = luaL_prepbuffer(&b); c_memset (p, 0, size); system_rtc_mem_write(addr, p, (uint16)size); lua_pushinteger( L, size); return 1; } static int misc_rtc_mem_read_raw(lua_State* L) /* DEBUG */ { uint32_t src_addr = luaL_checkinteger(L, 1); if (src_addr < 0 || src_addr >= 1024) return luaL_error(L, "bad address"); uint32_t save_size = luaL_checkinteger(L, 2); if (save_size < 1 || save_size > 1024) return luaL_error(L, "bad size"); luaL_Buffer b; luaL_buffinit( L, &b ); char *des_addr = luaL_prepbuffer(&b); if (!system_rtc_mem_read(src_addr, (void *)des_addr, save_size)) return 0; luaL_addsize(&b, save_size); luaL_pushresult( &b ); return 1; } static int misc_rtc_mem_test(lua_State* L) /* DEBUG */ { uint8 rd[32]; uint32 wr[2] = { 0x12345678, 0x87654321 }; system_rtc_mem_write(64, wr, 8); system_rtc_mem_read(64, rd, 4); os_printf("64 %x\n", *(uint32 *)rd); // system_rtc_mem_read(65, rd, 4); // os_printf("65 %x\n", *(uint32 *)rd); system_rtc_mem_read(64, rd, 8); os_printf("64 %x, 65 %x\n", *(uint32 *)rd, *(uint32 *)(rd + 4)); return 0; } static int misc_rtc_mem_test_str(lua_State* L) /* DEBUG */ { uint8 rd[32]; uint32 wr[8] = { 0x11111111, 0x22222222, 0x33333333, 0x44444444, 0x55555555, 0x66666666, 0x77777777, 0x88888888 }; uint8 msg[20]; luaL_Buffer b; luaL_buffinit( L, &b ); char *p = luaL_prepbuffer(&b); system_rtc_mem_write(64, wr, 32); system_rtc_mem_read(64, rd, 4) ; c_sprintf (msg, "64 x%x\n", *(uint32 *)rd); c_strcat (p, msg); // system_rtc_mem_read(65, rd, 4) ; // c_sprintf (msg, "65 x%x\n", *(uint32 *)rd); c_strcat (p, msg); system_rtc_mem_read(68, rd, 4); c_sprintf (msg, "68 x%x\n", *(uint32 *)rd); c_strcat (p, msg); system_rtc_mem_read(64, rd, 32); c_sprintf (msg, "64+0 x%x\n", *(uint32 *)rd); c_strcat (p, msg); c_sprintf (msg, "64+4 x%x\n", *(uint32 *)(rd+4)); c_strcat (p, msg); c_sprintf (msg, "64+16 x%x\n", *(uint32 *)(rd + 16)); c_strcat (p, msg); luaL_addsize(&b, (uint32_t)c_strlen(p)); luaL_pushresult( &b ); return 1; } static int misc_rtc_get_times(lua_State* L) { lua_pushinteger( L, (uint32_t)system_get_rtc_time()); lua_pushinteger( L, (uint32_t)system_rtc_clock_cali_proc()); return 2; } #undef RTC_USER_MEM_START #undef RTC_USER_MEM_SIZE #undef RTC_USER_MEM_END #undef RTC_USER_MEM_BLOCK_SHIFT #undef RTC_USER_MEM_BLOCK_SIZE #undef RTC_USER_MEM_BLOCK_MASK #undef RTC_USER_MEM_ADDR_CHECK // Module function map #define MIN_OPT_LEVEL 2 #include "lrodefs.h" const LUA_REG_TYPE misc_map[] = { { LSTRKEY( "rtc_mem_read" ), LFUNCVAL( misc_rtc_mem_read) }, { LSTRKEY( "rtc_mem_write" ), LFUNCVAL( misc_rtc_mem_write) }, { LSTRKEY( "rtc_mem_read_int" ), LFUNCVAL( misc_rtc_mem_read_int) }, { LSTRKEY( "rtc_mem_write_int" ), LFUNCVAL( misc_rtc_mem_write_int) }, { LSTRKEY( "rtc_mem_clear" ), LFUNCVAL( misc_rtc_mem_clear) }, /* DEBUG */ { LSTRKEY( "rtc_mem_read_raw" ), LFUNCVAL( misc_rtc_mem_read_raw) }, /* DEBUG */ { LSTRKEY( "rtc_mem_test" ), LFUNCVAL( misc_rtc_mem_test) }, /* DEBUG */ { LSTRKEY( "rtc_mem_test_str" ), LFUNCVAL( misc_rtc_mem_test_str) }, /* DEBUG */ { LSTRKEY( "rtc_get_times" ), LFUNCVAL( misc_rtc_get_times) }, #if LUA_OPTIMIZE_MEMORY > 0 #endif { LNILKEY, LNILVAL } }; LUALIB_API int luaopen_misc( lua_State *L ) { #if LUA_OPTIMIZE_MEMORY > 0 return 0; #else // #if LUA_OPTIMIZE_MEMORY > 0 luaL_register( L, AUXLIB_MISC, misc_map ); // Add constants return 1; #endif // #if LUA_OPTIMIZE_MEMORY > 0 }