Commit bbeb09b6 authored by Terry Ellison's avatar Terry Ellison Committed by Marcel Stör
Browse files

Squashed updates do get Lua51 and Lua53 working (#3075)

-  Lots of minor but nasty bugfixes to get all tests to run clean
-  core lua and test suite fixes to allow luac -F to run cleanly against test suite
-  next tranch to get LFS working
-  luac.cross -a options plus fixes from feedback
-  UART fixes and lua.c merge
-  commit of wip prior to rebaselining against current dev
-  more tweaks
parent 99aba344
...@@ -101,7 +101,7 @@ static int ICACHE_FLASH_ATTR tsl2561_lua_getchannels(lua_State* L) { ...@@ -101,7 +101,7 @@ static int ICACHE_FLASH_ATTR tsl2561_lua_getchannels(lua_State* L) {
} }
// Module function map // Module function map
LROT_BEGIN(tsl2561) LROT_BEGIN(tsl2561, NULL, 0)
LROT_FUNCENTRY( settiming, tsl2561_lua_settiming ) LROT_FUNCENTRY( settiming, tsl2561_lua_settiming )
LROT_FUNCENTRY( getlux, tsl2561_lua_calclux ) LROT_FUNCENTRY( getlux, tsl2561_lua_calclux )
LROT_FUNCENTRY( getrawchannels, tsl2561_lua_getchannels ) LROT_FUNCENTRY( getrawchannels, tsl2561_lua_getchannels )
...@@ -121,7 +121,7 @@ LROT_BEGIN(tsl2561) ...@@ -121,7 +121,7 @@ LROT_BEGIN(tsl2561)
LROT_NUMENTRY( ADDRESS_GND, TSL2561_ADDRESS_GND ) LROT_NUMENTRY( ADDRESS_GND, TSL2561_ADDRESS_GND )
LROT_NUMENTRY( ADDRESS_FLOAT, TSL2561_ADDRESS_FLOAT ) LROT_NUMENTRY( ADDRESS_FLOAT, TSL2561_ADDRESS_FLOAT )
LROT_NUMENTRY( ADDRESS_VDD, TSL2561_ADDRESS_VDD ) LROT_NUMENTRY( ADDRESS_VDD, TSL2561_ADDRESS_VDD )
LROT_END( tsl2561, NULL, 0 ) LROT_END(tsl2561, NULL, 0)
NODEMCU_MODULE(TSL2561, "tsl2561", tsl2561, NULL); NODEMCU_MODULE(TSL2561, "tsl2561", tsl2561, NULL);
...@@ -566,7 +566,8 @@ static int lu8g2_updateDisplayArea( lua_State *L ) ...@@ -566,7 +566,8 @@ static int lu8g2_updateDisplayArea( lua_State *L )
} }
LROT_BEGIN(lu8g2_display) LROT_BEGIN(lu8g2_display, NULL, LROT_MASK_INDEX)
LROT_TABENTRY( __index, lu8g2_display )
LROT_FUNCENTRY( clearBuffer, lu8g2_clearBuffer ) LROT_FUNCENTRY( clearBuffer, lu8g2_clearBuffer )
LROT_FUNCENTRY( drawBox, lu8g2_drawBox ) LROT_FUNCENTRY( drawBox, lu8g2_drawBox )
LROT_FUNCENTRY( drawCircle, lu8g2_drawCircle ) LROT_FUNCENTRY( drawCircle, lu8g2_drawCircle )
...@@ -608,9 +609,7 @@ LROT_BEGIN(lu8g2_display) ...@@ -608,9 +609,7 @@ LROT_BEGIN(lu8g2_display)
LROT_FUNCENTRY( setPowerSave, lu8g2_setPowerSave ) LROT_FUNCENTRY( setPowerSave, lu8g2_setPowerSave )
LROT_FUNCENTRY( updateDispla, lu8g2_updateDisplay ) LROT_FUNCENTRY( updateDispla, lu8g2_updateDisplay )
LROT_FUNCENTRY( updateDisplayArea, lu8g2_updateDisplayArea ) LROT_FUNCENTRY( updateDisplayArea, lu8g2_updateDisplayArea )
// LROT_FUNCENTRY( __gc, lu8g2_display_free ) LROT_END(lu8g2_display, NULL, LROT_MASK_INDEX)
LROT_TABENTRY( __index, lu8g2_display )
LROT_END( lu8g2_display, lu8g2_display, LROT_MASK_GC_INDEX )
uint8_t u8x8_d_overlay(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr); uint8_t u8x8_d_overlay(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr);
...@@ -808,7 +807,7 @@ U8G2_DISPLAY_TABLE_SPI ...@@ -808,7 +807,7 @@ U8G2_DISPLAY_TABLE_SPI
#undef U8G2_FONT_TABLE_ENTRY #undef U8G2_FONT_TABLE_ENTRY
#undef U8G2_DISPLAY_TABLE_ENTRY #undef U8G2_DISPLAY_TABLE_ENTRY
#define U8G2_DISPLAY_TABLE_ENTRY(function, binding) LROT_FUNCENTRY(binding,l ## binding) #define U8G2_DISPLAY_TABLE_ENTRY(function, binding) LROT_FUNCENTRY(binding,l ## binding)
LROT_BEGIN(lu8g2) LROT_BEGIN(lu8g2, NULL, 0)
U8G2_DISPLAY_TABLE_I2C U8G2_DISPLAY_TABLE_I2C
U8G2_DISPLAY_TABLE_SPI U8G2_DISPLAY_TABLE_SPI
// //
...@@ -826,7 +825,7 @@ LROT_BEGIN(lu8g2) ...@@ -826,7 +825,7 @@ LROT_BEGIN(lu8g2)
LROT_LUDENTRY( R2, U8G2_R2 ) LROT_LUDENTRY( R2, U8G2_R2 )
LROT_LUDENTRY( R3, U8G2_R3 ) LROT_LUDENTRY( R3, U8G2_R3 )
LROT_LUDENTRY( MIRROR, U8G2_MIRROR ) LROT_LUDENTRY( MIRROR, U8G2_MIRROR )
LROT_END( lu8g2, NULL, 0 ) LROT_END(lu8g2, NULL, 0)
int luaopen_u8g2( lua_State *L ) { int luaopen_u8g2( lua_State *L ) {
......
...@@ -15,7 +15,7 @@ void uart_on_data_cb(const char *buf, size_t len){ ...@@ -15,7 +15,7 @@ void uart_on_data_cb(const char *buf, size_t len){
lua_State *L = lua_getstate(); lua_State *L = lua_getstate();
lua_rawgeti(L, LUA_REGISTRYINDEX, uart_receive_rf); lua_rawgeti(L, LUA_REGISTRYINDEX, uart_receive_rf);
lua_pushlstring(L, buf, len); lua_pushlstring(L, buf, len);
luaN_call(L, 1, 0, 0); luaL_pcallx(L, 1, 0);
} }
// Lua: uart.on("method", [number/char], function, [run_input]) // Lua: uart.on("method", [number/char], function, [run_input])
...@@ -28,36 +28,35 @@ static int l_uart_on( lua_State* L ) ...@@ -28,36 +28,35 @@ static int l_uart_on( lua_State* L )
bool run_input = true; bool run_input = true;
luaL_argcheck(L, method && !strcmp(method, "data"), 1, "method not supported"); luaL_argcheck(L, method && !strcmp(method, "data"), 1, "method not supported");
if (lua_type( L, stack ) == LUA_TNUMBER) if (lua_type( L, stack ) == LUA_TNUMBER) {
{
data_len = luaL_checkinteger( L, stack ); data_len = luaL_checkinteger( L, stack );
luaL_argcheck(L, data_len >= 0 && data_len < LUA_MAXINPUT, stack, "wrong arg range"); luaL_argcheck(L, data_len >= 0 && data_len < LUA_MAXINPUT, stack, "wrong arg range");
stack++; stack++;
} } else if (lua_isstring(L, stack)) {
else if (lua_isstring(L, stack))
{
const char *end = luaL_checklstring( L, stack, &el ); const char *end = luaL_checklstring( L, stack, &el );
data_len = 0; end_char = end[0];
end_char = (int16_t) end[0];
stack++; stack++;
if(el!=1) { if(el!=1) {
return luaL_error( L, "wrong arg range" ); return luaL_error( L, "wrong arg range" );
} }
} }
if (lua_isanyfunction(L, stack)) { if (lua_isfunction(L, stack)) {
if (lua_isnumber(L, stack+1) && lua_tointeger(L, stack+1) == 0) { if (lua_isnumber(L, stack+1) && lua_tointeger(L, stack+1) == 0) {
run_input = false; run_input = false;
} }
lua_pushvalue(L, stack); lua_pushvalue(L, stack);
luaL_unref(L, LUA_REGISTRYINDEX, uart_receive_rf); luaL_unref(L, LUA_REGISTRYINDEX, uart_receive_rf);
uart_receive_rf = luaL_ref(L, LUA_REGISTRYINDEX); uart_receive_rf = luaL_ref(L, LUA_REGISTRYINDEX);
} else { } else {
luaL_unref(L, LUA_REGISTRYINDEX, uart_receive_rf); luaL_unref(L, LUA_REGISTRYINDEX, uart_receive_rf);
uart_receive_rf = LUA_NOREF; uart_receive_rf = LUA_NOREF;
} }
input_setup_receive(uart_on_data_cb, data_len, end_char, run_input);
if (uart_receive_rf == LUA_NOREF) {
input_setup_receive(NULL, 0, 0, 1);
} else
input_setup_receive(uart_on_data_cb, data_len, end_char, run_input);
return 0; return 0;
} }
...@@ -144,7 +143,7 @@ static int l_uart_write( lua_State* L ) ...@@ -144,7 +143,7 @@ static int l_uart_write( lua_State* L )
} }
// Module function map // Module function map
LROT_BEGIN(uart) LROT_BEGIN(uart, NULL, 0)
LROT_FUNCENTRY( setup, l_uart_setup ) LROT_FUNCENTRY( setup, l_uart_setup )
LROT_FUNCENTRY( getconfig, l_uart_getconfig ) LROT_FUNCENTRY( getconfig, l_uart_getconfig )
LROT_FUNCENTRY( write, l_uart_write ) LROT_FUNCENTRY( write, l_uart_write )
...@@ -156,7 +155,7 @@ LROT_BEGIN(uart) ...@@ -156,7 +155,7 @@ LROT_BEGIN(uart)
LROT_NUMENTRY( PARITY_NONE, PLATFORM_UART_PARITY_NONE ) LROT_NUMENTRY( PARITY_NONE, PLATFORM_UART_PARITY_NONE )
LROT_NUMENTRY( PARITY_EVEN, PLATFORM_UART_PARITY_EVEN ) LROT_NUMENTRY( PARITY_EVEN, PLATFORM_UART_PARITY_EVEN )
LROT_NUMENTRY( PARITY_ODD, PLATFORM_UART_PARITY_ODD ) LROT_NUMENTRY( PARITY_ODD, PLATFORM_UART_PARITY_ODD )
LROT_END( uart, NULL, 0 ) LROT_END(uart, NULL, 0)
NODEMCU_MODULE(UART, "uart", uart, NULL); NODEMCU_MODULE(UART, "uart", uart, NULL);
...@@ -690,7 +690,9 @@ UCG_DISPLAY_TABLE ...@@ -690,7 +690,9 @@ UCG_DISPLAY_TABLE
// Module function map // Module function map
LROT_BEGIN(lucg_display) LROT_BEGIN(lucg_display, NULL, LROT_MASK_GC_INDEX)
LROT_FUNCENTRY( __gc, lucg_close_display )
LROT_TABENTRY( __index, lucg_display )
LROT_FUNCENTRY( begin, lucg_begin ) LROT_FUNCENTRY( begin, lucg_begin )
LROT_FUNCENTRY( clearScreen, lucg_clearScreen ) LROT_FUNCENTRY( clearScreen, lucg_clearScreen )
LROT_FUNCENTRY( draw90Line, lucg_draw90Line ) LROT_FUNCENTRY( draw90Line, lucg_draw90Line )
...@@ -734,13 +736,10 @@ LROT_BEGIN(lucg_display) ...@@ -734,13 +736,10 @@ LROT_BEGIN(lucg_display)
LROT_FUNCENTRY( undoClipRange, lucg_setMaxClipRange ) LROT_FUNCENTRY( undoClipRange, lucg_setMaxClipRange )
LROT_FUNCENTRY( undoRotate, lucg_undoRotate ) LROT_FUNCENTRY( undoRotate, lucg_undoRotate )
LROT_FUNCENTRY( undoScale, lucg_undoScale ) LROT_FUNCENTRY( undoScale, lucg_undoScale )
LROT_END(lucg_display, NULL, LROT_MASK_GC_INDEX)
LROT_FUNCENTRY( __gc, lucg_close_display )
LROT_TABENTRY( __index, lucg_display )
LROT_END( lucg_display, lucg_display, 0 )
LROT_BEGIN(lucg) LROT_BEGIN(lucg, NULL , 0)
#undef UCG_DISPLAY_TABLE_ENTRY #undef UCG_DISPLAY_TABLE_ENTRY
#define UCG_DISPLAY_TABLE_ENTRY(binding, device, extension) LROT_FUNCENTRY(binding,l ## binding) #define UCG_DISPLAY_TABLE_ENTRY(binding, device, extension) LROT_FUNCENTRY(binding,l ## binding)
UCG_DISPLAY_TABLE UCG_DISPLAY_TABLE
...@@ -760,9 +759,7 @@ LROT_BEGIN(lucg) ...@@ -760,9 +759,7 @@ LROT_BEGIN(lucg)
LROT_NUMENTRY( DRAW_LOWER_RIGHT, UCG_DRAW_LOWER_RIGHT ) LROT_NUMENTRY( DRAW_LOWER_RIGHT, UCG_DRAW_LOWER_RIGHT )
LROT_NUMENTRY( DRAW_LOWER_LEFT, UCG_DRAW_LOWER_LEFT ) LROT_NUMENTRY( DRAW_LOWER_LEFT, UCG_DRAW_LOWER_LEFT )
LROT_NUMENTRY( DRAW_ALL, UCG_DRAW_ALL ) LROT_NUMENTRY( DRAW_ALL, UCG_DRAW_ALL )
LROT_END(lucg, NULL, 0)
LROT_TABENTRY( __metatable, lucg )
LROT_END( lucg, lucg, 0 )
int luaopen_ucg( lua_State *L ) int luaopen_ucg( lua_State *L )
......
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
// ws:connect('ws://echo.websocket.org') // ws:connect('ws://echo.websocket.org')
#include "lmem.h" #include "lmem.h"
#include "lualib.h"
#include "lauxlib.h" #include "lauxlib.h"
#include "platform.h" #include "platform.h"
#include "module.h" #include "module.h"
...@@ -124,9 +123,7 @@ static int websocketclient_on(lua_State *L) { ...@@ -124,9 +123,7 @@ static int websocketclient_on(lua_State *L) {
ws_data *data = (ws_data *) ws->reservedData; ws_data *data = (ws_data *) ws->reservedData;
int handle = luaL_checkoption(L, 2, NULL, (const char * const[]){ "connection", "receive", "close", NULL }); int handle = luaL_checkoption(L, 2, NULL, (const char * const[]){ "connection", "receive", "close", NULL });
if (lua_type(L, 3) != LUA_TNIL && lua_type(L, 3) != LUA_TFUNCTION && lua_type(L, 3) != LUA_TLIGHTFUNCTION) { luaL_argcheck(L, lua_isnil(L,3) || lua_isfunction(L, 3), 3, "function or nil");
return luaL_typerror(L, 3, "function or nil");
}
switch (handle) { switch (handle) {
case 0: case 0:
...@@ -135,7 +132,7 @@ static int websocketclient_on(lua_State *L) { ...@@ -135,7 +132,7 @@ static int websocketclient_on(lua_State *L) {
luaL_unref(L, LUA_REGISTRYINDEX, data->onConnection); luaL_unref(L, LUA_REGISTRYINDEX, data->onConnection);
data->onConnection = LUA_NOREF; data->onConnection = LUA_NOREF;
if (lua_type(L, 3) != LUA_TNIL) { if (!lua_isnil(L,3)) {
lua_pushvalue(L, 3); // copy argument (func) to the top of stack lua_pushvalue(L, 3); // copy argument (func) to the top of stack
data->onConnection = luaL_ref(L, LUA_REGISTRYINDEX); data->onConnection = luaL_ref(L, LUA_REGISTRYINDEX);
} }
...@@ -146,7 +143,7 @@ static int websocketclient_on(lua_State *L) { ...@@ -146,7 +143,7 @@ static int websocketclient_on(lua_State *L) {
luaL_unref(L, LUA_REGISTRYINDEX, data->onReceive); luaL_unref(L, LUA_REGISTRYINDEX, data->onReceive);
data->onReceive = LUA_NOREF; data->onReceive = LUA_NOREF;
if (lua_type(L, 3) != LUA_TNIL) { if (!lua_isnil(L,3)) {
lua_pushvalue(L, 3); // copy argument (func) to the top of stack lua_pushvalue(L, 3); // copy argument (func) to the top of stack
data->onReceive = luaL_ref(L, LUA_REGISTRYINDEX); data->onReceive = luaL_ref(L, LUA_REGISTRYINDEX);
} }
...@@ -157,7 +154,7 @@ static int websocketclient_on(lua_State *L) { ...@@ -157,7 +154,7 @@ static int websocketclient_on(lua_State *L) {
luaL_unref(L, LUA_REGISTRYINDEX, data->onClose); luaL_unref(L, LUA_REGISTRYINDEX, data->onClose);
data->onClose = LUA_NOREF; data->onClose = LUA_NOREF;
if (lua_type(L, 3) != LUA_TNIL) { if (!lua_isnil(L,3)) {
lua_pushvalue(L, 3); // copy argument (func) to the top of stack lua_pushvalue(L, 3); // copy argument (func) to the top of stack
data->onClose = luaL_ref(L, LUA_REGISTRYINDEX); data->onClose = luaL_ref(L, LUA_REGISTRYINDEX);
} }
...@@ -307,20 +304,21 @@ static int websocketclient_gc(lua_State *L) { ...@@ -307,20 +304,21 @@ static int websocketclient_gc(lua_State *L) {
return 0; return 0;
} }
LROT_BEGIN(websocket) LROT_BEGIN(websocket, NULL, 0)
LROT_FUNCENTRY( createClient, websocket_createClient ) LROT_FUNCENTRY( createClient, websocket_createClient )
LROT_END( websocket, NULL, 0 ) LROT_END(websocket, NULL, 0)
LROT_BEGIN(websocketclient) LROT_BEGIN(websocketclient, NULL, LROT_MASK_GC_INDEX)
LROT_FUNCENTRY( __gc, websocketclient_gc )
LROT_TABENTRY( __index, websocketclient )
LROT_FUNCENTRY( on, websocketclient_on ) LROT_FUNCENTRY( on, websocketclient_on )
LROT_FUNCENTRY( config, websocketclient_config ) LROT_FUNCENTRY( config, websocketclient_config )
LROT_FUNCENTRY( connect, websocketclient_connect ) LROT_FUNCENTRY( connect, websocketclient_connect )
LROT_FUNCENTRY( send, websocketclient_send ) LROT_FUNCENTRY( send, websocketclient_send )
LROT_FUNCENTRY( close, websocketclient_close ) LROT_FUNCENTRY( close, websocketclient_close )
LROT_FUNCENTRY( __gc, websocketclient_gc ) LROT_END(websocketclient, NULL, LROT_MASK_GC_INDEX)
LROT_TABENTRY( __index, websocketclient )
LROT_END( websocketclient, websocketclient, LROT_MASK_GC_INDEX )
int loadWebsocketModule(lua_State *L) { int loadWebsocketModule(lua_State *L) {
......
...@@ -150,8 +150,8 @@ static int wifi_start_smart( lua_State* L ) ...@@ -150,8 +150,8 @@ static int wifi_start_smart( lua_State* L )
channel = 6; channel = 6;
} }
// luaL_checkanyfunction(L, stack); // luaL_checktype(L, stack, LUA_TFUNCTION);
if (lua_type(L, stack) == LUA_TFUNCTION || lua_type(L, stack) == LUA_TLIGHTFUNCTION) if (lua_isfunction(L, stack))
{ {
lua_pushvalue(L, stack); // copy argument (func) to the top of stack lua_pushvalue(L, stack); // copy argument (func) to the top of stack
if(wifi_smart_succeed != LUA_NOREF) if(wifi_smart_succeed != LUA_NOREF)
...@@ -184,7 +184,7 @@ static int wifi_start_smart( lua_State* L ) ...@@ -184,7 +184,7 @@ static int wifi_start_smart( lua_State* L )
stack++; stack++;
} }
if (lua_type(L, stack) == LUA_TFUNCTION || lua_type(L, stack) == LUA_TLIGHTFUNCTION) if (lua_isfunction(L, stack))
{ {
lua_pushvalue(L, stack); // copy argument (func) to the top of stack lua_pushvalue(L, stack); // copy argument (func) to the top of stack
register_lua_cb(L, &wifi_smart_succeed); register_lua_cb(L, &wifi_smart_succeed);
...@@ -343,10 +343,7 @@ static int wifi_setmode( lua_State* L ) ...@@ -343,10 +343,7 @@ static int wifi_setmode( lua_State* L )
if(!lua_isnoneornil(L, 2)) if(!lua_isnoneornil(L, 2))
{ {
if(!lua_isboolean(L, 2)) luaL_checktype (L, 2, LUA_TBOOLEAN);
{
luaL_typerror(L, 2, lua_typename(L, LUA_TBOOLEAN));
}
save_to_flash=lua_toboolean(L, 2); save_to_flash=lua_toboolean(L, 2);
} }
...@@ -441,7 +438,7 @@ void wifi_pmSleep_suspend_CB(void) ...@@ -441,7 +438,7 @@ void wifi_pmSleep_suspend_CB(void)
{ {
lua_State* L = lua_getstate(); // Get main Lua thread pointer lua_State* L = lua_getstate(); // Get main Lua thread pointer
lua_rawgeti(L, LUA_REGISTRYINDEX, wifi_suspend_cb_ref); // Push suspend callback onto stack lua_rawgeti(L, LUA_REGISTRYINDEX, wifi_suspend_cb_ref); // Push suspend callback onto stack
lua_unref(L, wifi_suspend_cb_ref); // remove suspend callback from LUA_REGISTRY luaL_unref(L, wifi_suspend_cb_ref); // remove suspend callback from LUA_REGISTRY
wifi_suspend_cb_ref = LUA_NOREF; // Update variable since reference is no longer valid wifi_suspend_cb_ref = LUA_NOREF; // Update variable since reference is no longer valid
lua_call(L, 0, 0); // Execute suspend callback lua_call(L, 0, 0); // Execute suspend callback
} }
...@@ -1248,7 +1245,7 @@ static int wifi_station_listap( lua_State* L ) ...@@ -1248,7 +1245,7 @@ static int wifi_station_listap( lua_State* L )
} }
} }
if (lua_type(L, 2) == LUA_TFUNCTION || lua_type(L, 2) == LUA_TLIGHTFUNCTION) if (lua_isfunction(L, 2))
{ {
lua_pushnil(L); lua_pushnil(L);
lua_insert(L, 2); lua_insert(L, 2);
...@@ -1260,7 +1257,7 @@ static int wifi_station_listap( lua_State* L ) ...@@ -1260,7 +1257,7 @@ static int wifi_station_listap( lua_State* L )
lua_pushnil(L); lua_pushnil(L);
lua_insert(L, 1); lua_insert(L, 1);
} }
else if (lua_type(L, 1) == LUA_TFUNCTION || lua_type(L, 1) == LUA_TLIGHTFUNCTION) else if (lua_isfunction(L, 1))
{ {
lua_pushnil(L); lua_pushnil(L);
lua_insert(L, 1); lua_insert(L, 1);
...@@ -1269,7 +1266,7 @@ static int wifi_station_listap( lua_State* L ) ...@@ -1269,7 +1266,7 @@ static int wifi_station_listap( lua_State* L )
} }
else if(lua_isnil(L, 1)) else if(lua_isnil(L, 1))
{ {
if (lua_type(L, 2) == LUA_TFUNCTION || lua_type(L, 2) == LUA_TLIGHTFUNCTION) if (lua_isfunction(L, 2))
{ {
lua_pushnil(L); lua_pushnil(L);
lua_insert(L, 2); lua_insert(L, 2);
...@@ -1288,7 +1285,7 @@ static int wifi_station_listap( lua_State* L ) ...@@ -1288,7 +1285,7 @@ static int wifi_station_listap( lua_State* L )
return luaL_error( L, "wrong arg type" ); return luaL_error( L, "wrong arg type" );
} }
NODE_DBG("Use alternate output format: %d\n", getap_output_format); NODE_DBG("Use alternate output format: %d\n", getap_output_format);
if (lua_type(L, 3) == LUA_TFUNCTION || lua_type(L, 3) == LUA_TLIGHTFUNCTION) if (lua_isfunction(L, 3))
{ {
lua_pushvalue(L, 3); // copy argument (func) to the top of stack lua_pushvalue(L, 3); // copy argument (func) to the top of stack
register_lua_cb(L, &wifi_scan_succeed); register_lua_cb(L, &wifi_scan_succeed);
...@@ -1508,10 +1505,7 @@ static int wifi_ap_getconfig_default(lua_State *L) ...@@ -1508,10 +1505,7 @@ static int wifi_ap_getconfig_default(lua_State *L)
// Lua: wifi.ap.config(table) // Lua: wifi.ap.config(table)
static int wifi_ap_config( lua_State* L ) static int wifi_ap_config( lua_State* L )
{ {
if (!lua_istable(L, 1)) luaL_checktype(L, 1, LUA_TTABLE);
{
return luaL_typerror(L, 1, lua_typename(L, LUA_TTABLE));
}
struct softap_config config; struct softap_config config;
bool save_to_flash=true; bool save_to_flash=true;
...@@ -1864,7 +1858,7 @@ static int wifi_ap_dhcp_stop( lua_State* L ) ...@@ -1864,7 +1858,7 @@ static int wifi_ap_dhcp_stop( lua_State* L )
// Module function map // Module function map
LROT_BEGIN(wifi_station) LROT_BEGIN(wifi_station, NULL, 0)
LROT_FUNCENTRY( autoconnect, wifi_station_setauto ) LROT_FUNCENTRY( autoconnect, wifi_station_setauto )
LROT_FUNCENTRY( changeap, wifi_station_change_ap ) LROT_FUNCENTRY( changeap, wifi_station_change_ap )
LROT_FUNCENTRY( clearconfig, wifi_station_clear_config ) LROT_FUNCENTRY( clearconfig, wifi_station_clear_config )
...@@ -1887,17 +1881,17 @@ LROT_BEGIN(wifi_station) ...@@ -1887,17 +1881,17 @@ LROT_BEGIN(wifi_station)
LROT_FUNCENTRY( setmac, wifi_station_setmac ) LROT_FUNCENTRY( setmac, wifi_station_setmac )
LROT_FUNCENTRY( sleeptype, wifi_station_sleeptype ) LROT_FUNCENTRY( sleeptype, wifi_station_sleeptype )
LROT_FUNCENTRY( status, wifi_station_status ) LROT_FUNCENTRY( status, wifi_station_status )
LROT_END( wifi_station, wifi_station, 0 ) LROT_END(wifi_station, NULL, 0)
LROT_BEGIN(wifi_ap_dhcp) LROT_BEGIN(wifi_ap_dhcp, NULL, 0)
LROT_FUNCENTRY( config, wifi_ap_dhcp_config ) LROT_FUNCENTRY( config, wifi_ap_dhcp_config )
LROT_FUNCENTRY( start, wifi_ap_dhcp_start ) LROT_FUNCENTRY( start, wifi_ap_dhcp_start )
LROT_FUNCENTRY( stop, wifi_ap_dhcp_stop ) LROT_FUNCENTRY( stop, wifi_ap_dhcp_stop )
LROT_END( wifi_ap_dhcp, wifi_ap_dhcp, 0 ) LROT_END(wifi_ap_dhcp, NULL, 0)
LROT_BEGIN(wifi_ap) LROT_BEGIN(wifi_ap, NULL, 0)
LROT_FUNCENTRY( config, wifi_ap_config ) LROT_FUNCENTRY( config, wifi_ap_config )
LROT_FUNCENTRY( deauth, wifi_ap_deauth ) LROT_FUNCENTRY( deauth, wifi_ap_deauth )
LROT_FUNCENTRY( getip, wifi_ap_getip ) LROT_FUNCENTRY( getip, wifi_ap_getip )
...@@ -1909,10 +1903,10 @@ LROT_BEGIN(wifi_ap) ...@@ -1909,10 +1903,10 @@ LROT_BEGIN(wifi_ap)
LROT_FUNCENTRY( getconfig, wifi_ap_getconfig_current ) LROT_FUNCENTRY( getconfig, wifi_ap_getconfig_current )
LROT_FUNCENTRY( getdefaultconfig, wifi_ap_getconfig_default ) LROT_FUNCENTRY( getdefaultconfig, wifi_ap_getconfig_default )
LROT_TABENTRY( dhcp, wifi_ap_dhcp ) LROT_TABENTRY( dhcp, wifi_ap_dhcp )
LROT_END( wifi_ap, wifi_ap, 0 ) LROT_END(wifi_ap, NULL, 0)
LROT_BEGIN(wifi) LROT_BEGIN(wifi, NULL, 0)
LROT_FUNCENTRY( setmode, wifi_setmode ) LROT_FUNCENTRY( setmode, wifi_setmode )
LROT_FUNCENTRY( getmode, wifi_getmode ) LROT_FUNCENTRY( getmode, wifi_getmode )
LROT_FUNCENTRY( getdefaultmode, wifi_getdefaultmode ) LROT_FUNCENTRY( getdefaultmode, wifi_getdefaultmode )
...@@ -1967,8 +1961,7 @@ LROT_BEGIN(wifi) ...@@ -1967,8 +1961,7 @@ LROT_BEGIN(wifi)
LROT_NUMENTRY( COUNTRY_AUTO, WIFI_COUNTRY_POLICY_AUTO ) LROT_NUMENTRY( COUNTRY_AUTO, WIFI_COUNTRY_POLICY_AUTO )
LROT_NUMENTRY( COUNTRY_MANUAL, WIFI_COUNTRY_POLICY_MANUAL ) LROT_NUMENTRY( COUNTRY_MANUAL, WIFI_COUNTRY_POLICY_MANUAL )
LROT_END(wifi, NULL, 0)
LROT_END( wifi, wifi, 0 )
// Used by user_rf_pre_init(user_main.c) // Used by user_rf_pre_init(user_main.c)
......
...@@ -57,13 +57,13 @@ enum wifi_suspension_state{ ...@@ -57,13 +57,13 @@ enum wifi_suspension_state{
#ifdef WIFI_SDK_EVENT_MONITOR_ENABLE #ifdef WIFI_SDK_EVENT_MONITOR_ENABLE
LROT_EXTERN(wifi_event_monitor); extern LROT_TABLE(wifi_event_monitor);
void wifi_eventmon_init(); void wifi_eventmon_init();
int wifi_event_monitor_register(lua_State* L); int wifi_event_monitor_register(lua_State* L);
#endif #endif
#ifdef LUA_USE_MODULES_WIFI_MONITOR #ifdef LUA_USE_MODULES_WIFI_MONITOR
LROT_EXTERN(wifi_monitor); extern LROT_TABLE(wifi_monitor);
int wifi_monitor_init(lua_State *L); int wifi_monitor_init(lua_State *L);
#endif #endif
......
...@@ -42,7 +42,7 @@ int wifi_event_monitor_register(lua_State* L) ...@@ -42,7 +42,7 @@ int wifi_event_monitor_register(lua_State* L)
} }
else else
{ {
if (lua_type(L, 2) == LUA_TFUNCTION || lua_type(L, 2) == LUA_TLIGHTFUNCTION) //check if 2nd item on stack is a function if (lua_isfunction(L, 2)) //check if 2nd item on stack is a function
{ {
lua_pushvalue(L, 2); // copy argument (func) to the top of stack lua_pushvalue(L, 2); // copy argument (func) to the top of stack
register_lua_cb(L, &wifi_event_cb_ref[id]); //pop function from top of the stack, register it in the LUA_REGISTRY, then assign lua_ref to wifi_event_cb_ref[id] register_lua_cb(L, &wifi_event_cb_ref[id]); //pop function from top of the stack, register it in the LUA_REGISTRY, then assign lua_ref to wifi_event_cb_ref[id]
...@@ -247,7 +247,7 @@ static void wifi_event_monitor_process_event_queue(task_param_t param, uint8 pri ...@@ -247,7 +247,7 @@ static void wifi_event_monitor_process_event_queue(task_param_t param, uint8 pri
} }
#ifdef WIFI_EVENT_MONITOR_DISCONNECT_REASON_LIST_ENABLE #ifdef WIFI_EVENT_MONITOR_DISCONNECT_REASON_LIST_ENABLE
LROT_BEGIN(wifi_event_monitor_reason) LROT_BEGIN(wifi_event_monitor_reason, NULL, 0)
LROT_NUMENTRY( UNSPECIFIED, REASON_UNSPECIFIED ) LROT_NUMENTRY( UNSPECIFIED, REASON_UNSPECIFIED )
LROT_NUMENTRY( AUTH_EXPIRE, REASON_AUTH_EXPIRE ) LROT_NUMENTRY( AUTH_EXPIRE, REASON_AUTH_EXPIRE )
LROT_NUMENTRY( AUTH_LEAVE, REASON_AUTH_LEAVE ) LROT_NUMENTRY( AUTH_LEAVE, REASON_AUTH_LEAVE )
...@@ -276,11 +276,11 @@ LROT_BEGIN(wifi_event_monitor_reason) ...@@ -276,11 +276,11 @@ LROT_BEGIN(wifi_event_monitor_reason)
LROT_NUMENTRY( AUTH_FAIL, REASON_AUTH_FAIL ) LROT_NUMENTRY( AUTH_FAIL, REASON_AUTH_FAIL )
LROT_NUMENTRY( ASSOC_FAIL, REASON_ASSOC_FAIL ) LROT_NUMENTRY( ASSOC_FAIL, REASON_ASSOC_FAIL )
LROT_NUMENTRY( HANDSHAKE_TIMEOUT, REASON_HANDSHAKE_TIMEOUT ) LROT_NUMENTRY( HANDSHAKE_TIMEOUT, REASON_HANDSHAKE_TIMEOUT )
LROT_END( wifi_event_monitor_reason, NULL, 0 ) LROT_END(wifi_event_monitor_reason, NULL, 0)
#endif #endif
LROT_PUBLIC_BEGIN(wifi_event_monitor) LROT_BEGIN(wifi_event_monitor, NULL, 0)
LROT_FUNCENTRY( register, wifi_event_monitor_register ) LROT_FUNCENTRY( register, wifi_event_monitor_register )
LROT_FUNCENTRY( unregister, wifi_event_monitor_register ) LROT_FUNCENTRY( unregister, wifi_event_monitor_register )
LROT_NUMENTRY( STA_CONNECTED, EVENT_STAMODE_CONNECTED ) LROT_NUMENTRY( STA_CONNECTED, EVENT_STAMODE_CONNECTED )
...@@ -296,7 +296,7 @@ LROT_PUBLIC_BEGIN(wifi_event_monitor) ...@@ -296,7 +296,7 @@ LROT_PUBLIC_BEGIN(wifi_event_monitor)
#ifdef WIFI_EVENT_MONITOR_DISCONNECT_REASON_LIST_ENABLE #ifdef WIFI_EVENT_MONITOR_DISCONNECT_REASON_LIST_ENABLE
LROT_TABENTRY( reason, wifi_event_monitor_reason ) LROT_TABENTRY( reason, wifi_event_monitor_reason )
#endif #endif
LROT_END( wifi_event_monitor, NULL, 0 ) LROT_END(wifi_event_monitor, NULL, 0)
void wifi_eventmon_init() void wifi_eventmon_init()
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
#include "module.h" #include "module.h"
#include "lauxlib.h" #include "lauxlib.h"
#include "lapi.h"
#include "platform.h" #include "platform.h"
#include <string.h> #include <string.h>
...@@ -276,7 +275,7 @@ typedef struct { ...@@ -276,7 +275,7 @@ typedef struct {
uint8 buf[]; uint8 buf[];
} packet_t; } packet_t;
LROT_TABLE(packet_function) LROT_TABLE(packet_function);
static void wifi_rx_cb(uint8 *buf, uint16 len) { static void wifi_rx_cb(uint8 *buf, uint16 len) {
if (len != sizeof(struct sniffer_buf2)) { if (len != sizeof(struct sniffer_buf2)) {
...@@ -713,7 +712,7 @@ static int wifi_monitor_start(lua_State *L) { ...@@ -713,7 +712,7 @@ static int wifi_monitor_start(lua_State *L) {
mon_value = 0x00; mon_value = 0x00;
mon_mask = 0x0C; mon_mask = 0x0C;
} }
if (lua_type(L, argno) == LUA_TFUNCTION || lua_type(L, argno) == LUA_TLIGHTFUNCTION) if (lua_isfunction(L, argno))
{ {
lua_pushvalue(L, argno); // copy argument (func) to the top of stack lua_pushvalue(L, argno); // copy argument (func) to the top of stack
recv_cb = luaL_ref(L, LUA_REGISTRYINDEX); recv_cb = luaL_ref(L, LUA_REGISTRYINDEX);
...@@ -757,27 +756,27 @@ static int wifi_monitor_stop(lua_State *L) { ...@@ -757,27 +756,27 @@ static int wifi_monitor_stop(lua_State *L) {
return 0; return 0;
} }
LROT_BEGIN(packet_function) LROT_BEGIN(packet_function, NULL, 0)
LROT_FUNCENTRY( radio_byte, packet_radio_byte ) LROT_FUNCENTRY( radio_byte, packet_radio_byte )
LROT_FUNCENTRY( frame_byte, packet_frame_byte ) LROT_FUNCENTRY( frame_byte, packet_frame_byte )
LROT_FUNCENTRY( radio_sub, packet_radio_sub ) LROT_FUNCENTRY( radio_sub, packet_radio_sub )
LROT_FUNCENTRY( frame_sub, packet_frame_sub ) LROT_FUNCENTRY( frame_sub, packet_frame_sub )
LROT_FUNCENTRY( radio_subhex, packet_radio_subhex ) LROT_FUNCENTRY( radio_subhex, packet_radio_subhex )
LROT_FUNCENTRY( frame_subhex, packet_frame_subhex ) LROT_FUNCENTRY( frame_subhex, packet_frame_subhex )
LROT_END( packet_function, packet_function, LROT_MASK_INDEX ) LROT_END(packet_function, NULL, 0)
LROT_BEGIN(packet) LROT_BEGIN(packet, NULL, LROT_MASK_INDEX)
LROT_FUNCENTRY( __index, packet_map_lookup ) LROT_FUNCENTRY( __index, packet_map_lookup )
LROT_END( packet, packet, LROT_MASK_INDEX ) LROT_END(packet, NULL, LROT_MASK_INDEX)
// Module function map // Module function map
LROT_PUBLIC_BEGIN(wifi_monitor) LROT_BEGIN(wifi_monitor, NULL, 0)
LROT_FUNCENTRY( start, wifi_monitor_start ) LROT_FUNCENTRY( start, wifi_monitor_start )
LROT_FUNCENTRY( stop, wifi_monitor_stop ) LROT_FUNCENTRY( stop, wifi_monitor_stop )
LROT_FUNCENTRY( channel, wifi_monitor_channel ) LROT_FUNCENTRY( channel, wifi_monitor_channel )
LROT_END( wifi_monitor, NULL, 0 ) LROT_END(wifi_monitor, NULL, 0)
int wifi_monitor_init(lua_State *L) int wifi_monitor_init(lua_State *L)
......
...@@ -42,7 +42,7 @@ static int ICACHE_FLASH_ATTR wps_start(lua_State* L) ...@@ -42,7 +42,7 @@ static int ICACHE_FLASH_ATTR wps_start(lua_State* L)
wps_callback_ref = LUA_NOREF; wps_callback_ref = LUA_NOREF;
if (lua_type(L, 1) == LUA_TFUNCTION || lua_type(L, 1) == LUA_TLIGHTFUNCTION) if (lua_isfunction(L, 1))
wps_callback_ref = luaL_ref(L, LUA_REGISTRYINDEX); wps_callback_ref = luaL_ref(L, LUA_REGISTRYINDEX);
else else
return luaL_error (L, "Argument not a function"); return luaL_error (L, "Argument not a function");
...@@ -53,7 +53,7 @@ static int ICACHE_FLASH_ATTR wps_start(lua_State* L) ...@@ -53,7 +53,7 @@ static int ICACHE_FLASH_ATTR wps_start(lua_State* L)
} }
// Module function map // Module function map
LROT_BEGIN(wps) LROT_BEGIN(wps, NULL, 0)
LROT_FUNCENTRY( disable, wps_disable ) LROT_FUNCENTRY( disable, wps_disable )
LROT_FUNCENTRY( enable, wps_enable ) LROT_FUNCENTRY( enable, wps_enable )
LROT_FUNCENTRY( start, wps_start ) LROT_FUNCENTRY( start, wps_start )
...@@ -62,7 +62,7 @@ LROT_BEGIN(wps) ...@@ -62,7 +62,7 @@ LROT_BEGIN(wps)
LROT_NUMENTRY( TIMEOUT, WPS_CB_ST_TIMEOUT ) LROT_NUMENTRY( TIMEOUT, WPS_CB_ST_TIMEOUT )
LROT_NUMENTRY( WEP, WPS_CB_ST_WEP ) LROT_NUMENTRY( WEP, WPS_CB_ST_WEP )
LROT_NUMENTRY( SCAN_ERR, 4 ) LROT_NUMENTRY( SCAN_ERR, 4 )
LROT_END( wps, NULL, 0 ) LROT_END(wps, NULL, 0)
int luaopen_wps( lua_State *L ) int luaopen_wps( lua_State *L )
......
...@@ -123,10 +123,10 @@ static int ICACHE_FLASH_ATTR ws2801_writergb(lua_State* L) { ...@@ -123,10 +123,10 @@ static int ICACHE_FLASH_ATTR ws2801_writergb(lua_State* L) {
return 0; return 0;
} }
LROT_BEGIN(ws2801) LROT_BEGIN(ws2801, NULL, 0)
LROT_FUNCENTRY( write, ws2801_writergb ) LROT_FUNCENTRY( write, ws2801_writergb )
LROT_FUNCENTRY( init, ws2801_init_lua ) LROT_FUNCENTRY( init, ws2801_init_lua )
LROT_END( ws2801, NULL, 0 ) LROT_END(ws2801, NULL, 0)
NODEMCU_MODULE(WS2801, "ws2801", ws2801, NULL); NODEMCU_MODULE(WS2801, "ws2801", ws2801, NULL);
...@@ -600,7 +600,10 @@ static int ws2812_buffer_tostring(lua_State* L) { ...@@ -600,7 +600,10 @@ static int ws2812_buffer_tostring(lua_State* L) {
return 1; return 1;
} }
LROT_BEGIN(ws2812_buffer) LROT_BEGIN(ws2812_buffer_map, NULL, LROT_MASK_INDEX)
LROT_FUNCENTRY( __concat, ws2812_buffer_concat )
LROT_TABENTRY( __index, ws2812_buffer_map )
LROT_FUNCENTRY( __tostring, ws2812_buffer_tostring )
LROT_FUNCENTRY( dump, ws2812_buffer_dump ) LROT_FUNCENTRY( dump, ws2812_buffer_dump )
LROT_FUNCENTRY( fade, ws2812_buffer_fade_lua) LROT_FUNCENTRY( fade, ws2812_buffer_fade_lua)
LROT_FUNCENTRY( fill, ws2812_buffer_fill_lua ) LROT_FUNCENTRY( fill, ws2812_buffer_fill_lua )
...@@ -612,12 +615,9 @@ LROT_BEGIN(ws2812_buffer) ...@@ -612,12 +615,9 @@ LROT_BEGIN(ws2812_buffer)
LROT_FUNCENTRY( shift, ws2812_buffer_shift_lua ) LROT_FUNCENTRY( shift, ws2812_buffer_shift_lua )
LROT_FUNCENTRY( size, ws2812_buffer_size ) LROT_FUNCENTRY( size, ws2812_buffer_size )
LROT_FUNCENTRY( sub, ws2812_buffer_sub ) LROT_FUNCENTRY( sub, ws2812_buffer_sub )
LROT_FUNCENTRY( __concat, ws2812_buffer_concat ) LROT_END(ws2812_buffer_map, NULL, LROT_MASK_INDEX)
LROT_TABENTRY( __index, ws2812_buffer )
LROT_FUNCENTRY( __tostring, ws2812_buffer_tostring )
LROT_END( ws2812_buffer, ws2812_buffer, LROT_MASK_INDEX )
LROT_BEGIN(ws2812) LROT_BEGIN(ws2812, NULL, 0)
LROT_FUNCENTRY( init, ws2812_init ) LROT_FUNCENTRY( init, ws2812_init )
LROT_FUNCENTRY( newBuffer, ws2812_new_buffer ) LROT_FUNCENTRY( newBuffer, ws2812_new_buffer )
LROT_FUNCENTRY( write, ws2812_write ) LROT_FUNCENTRY( write, ws2812_write )
...@@ -627,11 +627,11 @@ LROT_BEGIN(ws2812) ...@@ -627,11 +627,11 @@ LROT_BEGIN(ws2812)
LROT_NUMENTRY( MODE_DUAL, MODE_DUAL ) LROT_NUMENTRY( MODE_DUAL, MODE_DUAL )
LROT_NUMENTRY( SHIFT_LOGICAL, SHIFT_LOGICAL ) LROT_NUMENTRY( SHIFT_LOGICAL, SHIFT_LOGICAL )
LROT_NUMENTRY( SHIFT_CIRCULAR, SHIFT_CIRCULAR ) LROT_NUMENTRY( SHIFT_CIRCULAR, SHIFT_CIRCULAR )
LROT_END( ws2812, NULL, 0 ) LROT_END(ws2812, NULL, 0)
int luaopen_ws2812(lua_State *L) { int luaopen_ws2812(lua_State *L) {
// TODO: Make sure that the GPIO system is initialized // TODO: Make sure that the GPIO system is initialized
luaL_rometatable(L, "ws2812.buffer", LROT_TABLEREF(ws2812_buffer)); luaL_rometatable(L, "ws2812.buffer", LROT_TABLEREF(ws2812_buffer_map));
return 0; return 0;
} }
......
...@@ -1039,7 +1039,8 @@ static int ws2812_effects_tostring(lua_State* L) { ...@@ -1039,7 +1039,8 @@ static int ws2812_effects_tostring(lua_State* L) {
return 1; return 1;
} }
LROT_BEGIN(ws2812_effects) LROT_BEGIN(ws2812_effects_map, NULL, 0)
LROT_FUNCENTRY( __tostring, ws2812_effects_tostring )
LROT_FUNCENTRY( init, ws2812_effects_init ) LROT_FUNCENTRY( init, ws2812_effects_init )
LROT_FUNCENTRY( set_brightness, ws2812_effects_set_brightness ) LROT_FUNCENTRY( set_brightness, ws2812_effects_set_brightness )
LROT_FUNCENTRY( set_color, ws2812_effects_set_color ) LROT_FUNCENTRY( set_color, ws2812_effects_set_color )
...@@ -1050,11 +1051,8 @@ LROT_BEGIN(ws2812_effects) ...@@ -1050,11 +1051,8 @@ LROT_BEGIN(ws2812_effects)
LROT_FUNCENTRY( stop, ws2812_effects_stop ) LROT_FUNCENTRY( stop, ws2812_effects_stop )
LROT_FUNCENTRY( get_delay, ws2812_effects_get_delay ) LROT_FUNCENTRY( get_delay, ws2812_effects_get_delay )
LROT_FUNCENTRY( get_speed, ws2812_effects_get_speed ) LROT_FUNCENTRY( get_speed, ws2812_effects_get_speed )
LROT_END(ws2812_effects_map, NULL, 0)
LROT_TABENTRY( __index, ws2812_effects )
LROT_FUNCENTRY( __tostring, ws2812_effects_tostring )
LROT_END( ws2812_effects, ws2812_effects, LROT_MASK_INDEX )
NODEMCU_MODULE(WS2812_EFFECTS, "ws2812_effects", ws2812_effects, NULL); NODEMCU_MODULE(WS2812_EFFECTS, "ws2812_effects", ws2812_effects_map, NULL);
...@@ -203,14 +203,14 @@ static int xpt2046_getPositionAvg( lua_State* L ) { ...@@ -203,14 +203,14 @@ static int xpt2046_getPositionAvg( lua_State* L ) {
} }
// Module function map // Module function map
LROT_BEGIN(xpt2046) LROT_BEGIN(xpt2046, NULL, 0)
LROT_FUNCENTRY( isTouched, xpt2046_isTouched ) LROT_FUNCENTRY( isTouched, xpt2046_isTouched )
LROT_FUNCENTRY( getRaw, xpt2046_getRaw ) LROT_FUNCENTRY( getRaw, xpt2046_getRaw )
LROT_FUNCENTRY( getPosition, xpt2046_getPosition ) LROT_FUNCENTRY( getPosition, xpt2046_getPosition )
LROT_FUNCENTRY( getPositionAvg, xpt2046_getPositionAvg ) LROT_FUNCENTRY( getPositionAvg, xpt2046_getPositionAvg )
LROT_FUNCENTRY( setCalibration, xpt2046_setCalibration ) LROT_FUNCENTRY( setCalibration, xpt2046_setCalibration )
LROT_FUNCENTRY( init, xpt2046_init ) LROT_FUNCENTRY( init, xpt2046_init )
LROT_END( xpt2046, NULL, 0 ) LROT_END(xpt2046, NULL, 0)
......
...@@ -985,7 +985,6 @@ extern uint32_t _irom0_text_start[]; ...@@ -985,7 +985,6 @@ extern uint32_t _irom0_text_start[];
#define FLASH_SECTOR_WORDS (INTERNAL_FLASH_SECTOR_SIZE/WORDSIZE) #define FLASH_SECTOR_WORDS (INTERNAL_FLASH_SECTOR_SIZE/WORDSIZE)
uint32_t platform_rcr_read (uint8_t rec_id, void **rec) { uint32_t platform_rcr_read (uint8_t rec_id, void **rec) {
//DEBUG os_printf("platform_rcr_read(%d,%08x)\n",rec_id,rec);
platform_rcr_t *rcr = (platform_rcr_t *) &RCR_WORD(0); platform_rcr_t *rcr = (platform_rcr_t *) &RCR_WORD(0);
uint32_t i = 0; uint32_t i = 0;
/* /*
...@@ -1006,6 +1005,19 @@ uint32_t platform_rcr_read (uint8_t rec_id, void **rec) { ...@@ -1006,6 +1005,19 @@ uint32_t platform_rcr_read (uint8_t rec_id, void **rec) {
return ~0; return ~0;
} }
uint32_t platform_rcr_delete (uint8_t rec_id) {
void *rec = NULL;
platform_rcr_read (rec_id, &rec);
if (rec) {
uint32_t *pHdr = cast(uint32_t *,rec)-1;
platform_rcr_t hdr = {.hdr = *pHdr};
hdr.id = PLATFORM_RCR_DELETED;
platform_s_flash_write(&hdr, platform_flash_mapped2phys(cast(uint32_t, pHdr)), WORDSIZE);
return 0;
}
return ~0;
}
/* /*
* Chain down the RCR page and look for an existing record that matches the record * Chain down the RCR page and look for an existing record that matches the record
* ID and the first free record. If there is enough room, then append the new * ID and the first free record. If there is enough room, then append the new
...@@ -1095,7 +1107,7 @@ void* platform_print_deprecation_note( const char *msg, const char *time_frame) ...@@ -1095,7 +1107,7 @@ void* platform_print_deprecation_note( const char *msg, const char *time_frame)
/* /*
* Private struct to hold the 3 event task queues and the dispatch callbacks * Private struct to hold the 3 event task queues and the dispatch callbacks
*/ */
static struct taskQblock { static struct taskQblock {
os_event_t *task_Q[TASK_PRIORITY_COUNT]; os_event_t *task_Q[TASK_PRIORITY_COUNT];
platform_task_callback_t *task_func; platform_task_callback_t *task_func;
int task_count; int task_count;
...@@ -1107,7 +1119,7 @@ static void platform_task_dispatch (os_event_t *e) { ...@@ -1107,7 +1119,7 @@ static void platform_task_dispatch (os_event_t *e) {
uint16_t entry = (handle & TH_UNMASK) >> TH_SHIFT; uint16_t entry = (handle & TH_UNMASK) >> TH_SHIFT;
uint8_t priority = handle & TASK_PRIORITY_MASK; uint8_t priority = handle & TASK_PRIORITY_MASK;
if ( priority <= PLATFORM_TASK_PRIORITY_HIGH && if ( priority <= PLATFORM_TASK_PRIORITY_HIGH &&
TQB.task_func && TQB.task_func &&
entry < TQB.task_count ){ entry < TQB.task_count ){
/* call the registered task handler with the specified parameter and priority */ /* call the registered task handler with the specified parameter and priority */
TQB.task_func[entry](e->par, priority); TQB.task_func[entry](e->par, priority);
...@@ -1119,7 +1131,7 @@ static void platform_task_dispatch (os_event_t *e) { ...@@ -1119,7 +1131,7 @@ static void platform_task_dispatch (os_event_t *e) {
} }
/* /*
* Initialise the task handle callback for a given priority. * Initialise the task handle callback for a given priority.
*/ */
static int task_init_handler (void) { static int task_init_handler (void) {
int p, qlen = TASK_DEFAULT_QUEUE_LEN; int p, qlen = TASK_DEFAULT_QUEUE_LEN;
...@@ -1138,12 +1150,12 @@ static int task_init_handler (void) { ...@@ -1138,12 +1150,12 @@ static int task_init_handler (void) {
/* /*
* Allocate a task handle in the relevant TCB.task_Q. Note that these Qs are resized * Allocate a task handle in the relevant TCB.task_Q. Note that these Qs are resized
* as needed growing in 4 unit bricks. No GC is adopted so handles are permanently * as needed growing in 4 unit bricks. No GC is adopted so handles are permanently
* allocated during boot life. This isn't an issue in practice as only a few handles * allocated during boot life. This isn't an issue in practice as only a few handles
* are created per priority during application init and the more volitile Lua tasks * are created per priority during application init and the more volitile Lua tasks
* are allocated in the Lua registery using the luaX interface which is layered on * are allocated in the Lua registery using the luaX interface which is layered on
* this mechanism. * this mechanism.
*/ */
platform_task_handle_t platform_task_get_id (platform_task_callback_t t) { platform_task_handle_t platform_task_get_id (platform_task_callback_t t) {
if ( (TQB.task_count & (TH_ALLOCATION_BRICK - 1)) == 0 ) { if ( (TQB.task_count & (TH_ALLOCATION_BRICK - 1)) == 0 ) {
TQB.task_func = (platform_task_callback_t *) realloc( TQB.task_func = (platform_task_callback_t *) realloc(
...@@ -1152,8 +1164,8 @@ platform_task_handle_t platform_task_get_id (platform_task_callback_t t) { ...@@ -1152,8 +1164,8 @@ platform_task_handle_t platform_task_get_id (platform_task_callback_t t) {
if (!TQB.task_func) { if (!TQB.task_func) {
NODE_DBG ( "Malloc failure in platform_task_get_id"); NODE_DBG ( "Malloc failure in platform_task_get_id");
return 0; return 0;
} }
os_memset (TQB.task_func+TQB.task_count, 0, os_memset (TQB.task_func+TQB.task_count, 0,
sizeof(platform_task_callback_t)*TH_ALLOCATION_BRICK); sizeof(platform_task_callback_t)*TH_ALLOCATION_BRICK);
} }
TQB.task_func[TQB.task_count++] = t; TQB.task_func[TQB.task_count++] = t;
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
#include <stdint.h> #include <stdint.h>
#include "cpu_esp8266.h" #include "cpu_esp8266.h"
#include "user_interface.h"
#include "driver/pwm.h" #include "driver/pwm.h"
#include "driver/uart.h" #include "driver/uart.h"
// Error / status codes // Error / status codes
...@@ -321,30 +321,32 @@ void* platform_print_deprecation_note( const char *msg, const char *time_frame); ...@@ -321,30 +321,32 @@ void* platform_print_deprecation_note( const char *msg, const char *time_frame);
// ***************************************************************************** // *****************************************************************************
// Reboot config page // Reboot config page
/* /*
* The 4K flash page in the linker section .irom0.ptable (offset 0x10000) is used * The 4K flash page in the linker section .irom0.ptable (offset 0x10000) is used
* for configuration changes that persist across reboots. This 4k page contains a * for configuration changes that persist across reboots. This 4k page contains a
* sequence of records that are written using flash NAND writing rules. See the * sequence of records that are written using flash NAND writing rules. See the
* header app/spiffs/spiffs_nucleus.h for a discussion of how SPIFFS uses these. A * header app/spiffs/spiffs_nucleus.h for a discussion of how SPIFFS uses these. A
* similar technique is used here. * similar technique is used here.
* *
* Each record is word aligned and the first two bytes of the record are its size * Each record is word aligned and the first two bytes of the record are its size
* and record type. Type 0xFF means unused and type 0x00 means deleted. New * and record type. Type 0xFF means unused and type 0x00 means deleted. New
* records can be added by overwriting the first unused slot. Records can be * records can be added by overwriting the first unused slot. Records can be
* replaced by adding the new version, then setting the type of the previous version * replaced by adding the new version, then setting the type of the previous version
* to deleted. This all works and can be implemented with platform_s_flash_write() * to deleted. This all works and can be implemented with platform_s_flash_write()
* upto the 4K limit. * upto the 4K limit.
* *
* If a new record cannot fit into the page then the deleted records are GCed by * If a new record cannot fit into the page then the deleted records are GCed by
* copying the active records into a RAM scratch pad, erasing the page and writing * copying the active records into a RAM scratch pad, erasing the page and writing
* them back. Yes, this is powerfail unsafe for a few mSec, but this is no worse * them back. Yes, this is powerfail unsafe for a few mSec, but this is no worse
* than writing to SPIFFS and won't even occur in normal production use. * than writing to SPIFFS and won't even occur in normal production use.
*/ */
#define IROM_PTABLE_ATTR __attribute__((section(".irom0.ptable"))) #define IROM_PTABLE_ATTR __attribute__((section(".irom0.ptable")))
#define PLATFORM_PARTITION(n) (SYSTEM_PARTITION_CUSTOMER_BEGIN + n) #define PLATFORM_PARTITION(n) (SYSTEM_PARTITION_CUSTOMER_BEGIN + n)
#define PLATFORM_RCR_DELETED 0x0 #define PLATFORM_RCR_DELETED 0x0
#define PLATFORM_RCR_PT 0x1 #define PLATFORM_RCR_PT 0x1
#define PLATFORM_RCR_PHY_DATA 0x2 #define PLATFORM_RCR_PHY_DATA 0x2
#define PLATFORM_RCR_REFLASH 0x3 #define PLATFORM_RCR_REFLASH 0x3
#define PLATFORM_RCR_FLASHLFS 0x4
#define PLATFORM_RCR_INITSTR 0x5
#define PLATFORM_RCR_FREE 0xFF #define PLATFORM_RCR_FREE 0xFF
typedef union { typedef union {
uint32_t hdr; uint32_t hdr;
...@@ -352,6 +354,7 @@ typedef union { ...@@ -352,6 +354,7 @@ typedef union {
} platform_rcr_t; } platform_rcr_t;
uint32_t platform_rcr_read (uint8_t rec_id, void **rec); uint32_t platform_rcr_read (uint8_t rec_id, void **rec);
uint32_t platform_rcr_delete (uint8_t rec_id);
uint32_t platform_rcr_write (uint8_t rec_id, const void *rec, uint8_t size); uint32_t platform_rcr_write (uint8_t rec_id, const void *rec, uint8_t size);
#define PLATFORM_TASK_PRIORITY_LOW 0 #define PLATFORM_TASK_PRIORITY_LOW 0
...@@ -363,14 +366,18 @@ uint32_t platform_rcr_write (uint8_t rec_id, const void *rec, uint8_t size); ...@@ -363,14 +366,18 @@ uint32_t platform_rcr_write (uint8_t rec_id, const void *rec, uint8_t size);
* is just a fixed fingerprint and the count is allocated serially by the task get_id() * is just a fixed fingerprint and the count is allocated serially by the task get_id()
* function. * function.
*/ */
#define platform_post_low(handle,param) platform_post(PLATFORM_TASK_PRIORITY_LOW, handle, param) #define platform_post_low(handle,param) \
#define platform_post_medium(handle,param) platform_post(PLATFORM_TASK_PRIORITY_MEDIUM, handle, param) platform_post(PLATFORM_TASK_PRIORITY_LOW, handle, param)
#define platform_post_high(handle,param) platform_post(PLATFORM_TASK_PRIORITY_HIGH, handle, param) #define platform_post_medium(handle,param) \
platform_post(PLATFORM_TASK_PRIORITY_MEDIUM, handle, param)
#define platform_post_high(handle,param) \
platform_post(PLATFORM_TASK_PRIORITY_HIGH, handle, param)
typedef void (*platform_task_callback_t)(platform_task_param_t param, uint8 prio); typedef void (*platform_task_callback_t)(platform_task_param_t param, uint8 prio);
platform_task_handle_t platform_task_get_id(platform_task_callback_t t); platform_task_handle_t platform_task_get_id(platform_task_callback_t t);
bool platform_post(uint8 prio, platform_task_handle_t h, platform_task_param_t par); bool platform_post(uint8 prio, platform_task_handle_t h, platform_task_param_t par);
#define platform_freeheap() system_get_free_heap_size()
// Get current value of CCOUNt register // Get current value of CCOUNt register
#define CCOUNT_REG ({ int32_t r; asm volatile("rsr %0, ccount" : "=r"(r)); r;}) #define CCOUNT_REG ({ int32_t r; asm volatile("rsr %0, ccount" : "=r"(r)); r;})
......
...@@ -532,12 +532,12 @@ int resume_timers_lua(lua_State* L){ ...@@ -532,12 +532,12 @@ int resume_timers_lua(lua_State* L){
return 0; return 0;
} }
LROT_BEGIN(test_swtimer_debug) LROT_BEGIN(test_swtimer_debug, NULL, 0)
LROT_FUNCENTRY( timer_list, print_timer_list ) LROT_FUNCENTRY( timer_list, print_timer_list )
LROT_FUNCENTRY( susp_timer_list, print_susp_timer_list ) LROT_FUNCENTRY( susp_timer_list, print_susp_timer_list )
LROT_FUNCENTRY( suspend, suspend_timers_lua ) LROT_FUNCENTRY( suspend, suspend_timers_lua )
LROT_FUNCENTRY( resume, resume_timers_lua ) LROT_FUNCENTRY( resume, resume_timers_lua )
LROT_END( test_swtimer_debug, NULL, 0 ) LROT_END(test_swtimer_debug, NULL, 0)
NODEMCU_MODULE(SWTMR_DBG, "SWTMR_DBG", test_swtimer_debug, NULL); NODEMCU_MODULE(SWTMR_DBG, "SWTMR_DBG", test_swtimer_debug, NULL);
......
...@@ -90,7 +90,7 @@ static bool myspiffs_set_cfg(spiffs_config *cfg, bool force_create) { ...@@ -90,7 +90,7 @@ static bool myspiffs_set_cfg(spiffs_config *cfg, bool force_create) {
cfg->log_page_size = LOG_PAGE_SIZE; cfg->log_page_size = LOG_PAGE_SIZE;
cfg->phys_addr = (pt_start + ALIGN - 1) & ~(ALIGN - 1); cfg->phys_addr = (pt_start + ALIGN - 1) & ~(ALIGN - 1);
cfg->phys_size = (pt_end & ~(ALIGN - 1)) - cfg->phys_addr; cfg->phys_size = (pt_end & ~(ALIGN - 1)) - cfg->phys_addr;
if (cfg->phys_size < MIN_BLOCKS_FS * LOG_BLOCK_SIZE_SMALL_FS) { if (cfg->phys_size < MIN_BLOCKS_FS * LOG_BLOCK_SIZE_SMALL_FS) {
return FALSE; return FALSE;
} else if (cfg->phys_size < MIN_BLOCKS_FS * LOG_BLOCK_SIZE_SMALL_FS) { } else if (cfg->phys_size < MIN_BLOCKS_FS * LOG_BLOCK_SIZE_SMALL_FS) {
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#ifdef LUA_USE_MODULES_RTCTIME #ifdef LUA_USE_MODULES_RTCTIME
#include "rtc/rtctime.h" #include "rtc/rtctime.h"
#endif #endif
extern int lua_main (void);
/* Contents of esp_init_data_default.bin */ /* Contents of esp_init_data_default.bin */
extern const uint32_t init_data[], init_data_end[]; extern const uint32_t init_data[], init_data_end[];
...@@ -165,7 +166,7 @@ void user_pre_init(void) { ...@@ -165,7 +166,7 @@ void user_pre_init(void) {
return; return;
} }
os_printf("Invalid system partition table\n"); os_printf("Invalid system partition table\n");
while (1) {}; while (1) {};
} }
/* /*
...@@ -277,7 +278,8 @@ void nodemcu_init(void) { ...@@ -277,7 +278,8 @@ void nodemcu_init(void) {
NODE_DBG("Task task_lua starting.\n"); NODE_DBG("Task task_lua starting.\n");
// Call the Lua bootstrap startup directly. This uses the task interface // Call the Lua bootstrap startup directly. This uses the task interface
// internally to carry out the main lua libraries initialisation. // internally to carry out the main lua libraries initialisation.
lua_main(); if(lua_main())
lua_main(); // If it returns true then LFS restart is needed
} }
#ifdef LUA_USE_MODULES_WIFI #ifdef LUA_USE_MODULES_WIFI
......
...@@ -14,7 +14,7 @@ NodeMCU firmware developers commit or contribute to the project on GitHub and mi ...@@ -14,7 +14,7 @@ NodeMCU firmware developers commit or contribute to the project on GitHub and mi
make make
``` ```
The default build setup reduces output verbosity to a minimum. The verbosity level can be increased by setting the `V` environment variable to 1, e.g. with The default build setup reduces output verbosity to a minimum. The verbosity level can be increased by setting the `V` environment variable to 1, as below. See the root `Makefile` for other available options.
``` ```
V=1 make V=1 make
``` ```
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment