{ lua_pushboolean (L, false); return 1; } // Nope, it differs, we need to rewrite it init_data[107] = byte107; if (SPI_FLASH_RESULT_OK != flash_safe_erase_sector (init_sector)) return luaL_error(L, "flash erase error"); if (SPI_FLASH_RESULT_OK != flash_safe_write ( init_sector * SPI_FLASH_SEC_SIZE, (uint32 *)init_data, sizeof(init_data))) return luaL_error(L, "flash write error"); lua_pushboolean (L, true); return 1; } // Module function map static const LUA_REG_TYPE adc_map[] = { { LSTRKEY( "read" ), LFUNCVAL( adc_sample ) }, { LSTRKEY( "readvdd33" ), LFUNCVAL( adc_readvdd33 ) }, { LSTRKEY( "force_init_mode" ), LFUNCVAL( adc_init107 ) }, { LSTRKEY( "INIT_ADC" ), LNUMVAL( 0x00 ) }, { LSTRKEY( "INIT_VDD33" ),LNUMVAL( 0xff ) }, { LNILKEY, LNILVAL } }; NODEMCU_MODULE(ADC, "adc", adc_map, NULL);
{ LSTRKEY( "dsleep" ), LFUNCVAL( node_deepsleep ) }, { LSTRKEY( "info" ), LFUNCVAL( node_info ) }, { LSTRKEY( "chipid" ), LFUNCVAL( node_chipid ) }, { LSTRKEY( "flashid" ), LFUNCVAL( node_flashid ) }, { LSTRKEY( "flashsize" ), LFUNCVAL( node_flashsize) }, { LSTRKEY( "heap" ), LFUNCVAL( node_heap ) }, #ifdef DEVKIT_VERSION_0_9 { LSTRKEY( "key" ), LFUNCVAL( node_key ) }, { LSTRKEY( "led" ), LFUNCVAL( node_led ) }, #endif { LSTRKEY( "input" ), LFUNCVAL( node_input ) }, { LSTRKEY( "output" ), LFUNCVAL( node_output ) }, // Moved to adc module, use adc.readvdd33() // { LSTRKEY( "readvdd33" ), LFUNCVAL( node_readvdd33) }, { LSTRKEY( "compile" ), LFUNCVAL( node_compile) }, { LSTRKEY( "CPU80MHZ" ), LNUMVAL( CPU80MHZ ) }, { LSTRKEY( "CPU160MHZ" ), LNUMVAL( CPU160MHZ ) }, { LSTRKEY( "setcpufreq" ), LFUNCVAL( node_setcpufreq) }, // Combined to dsleep(us, option) // { LSTRKEY( "dsleepsetoption" ), LFUNCVAL( node_deepsleep_setoption) }, #if LUA_OPTIMIZE_MEMORY > 0 #endif { LNILKEY, LNILVAL } }; LUALIB_API int luaopen_node( lua_State *L ) { #if LUA_OPTIMIZE_MEMORY > 0 return 0; #else // #if LUA_OPTIMIZE_MEMORY > 0
lua_pushlstring( L, &cres, 1 ); } return 1; } // Module function map #define MIN_OPT_LEVEL 2 #include "lrodefs.h" const LUA_REG_TYPE uart_map[] = { { LSTRKEY( "setup" ), LFUNCVAL( uart_setup ) }, { LSTRKEY( "write" ), LFUNCVAL( uart_write ) }, { LSTRKEY( "read" ), LFUNCVAL( uart_read ) }, { LSTRKEY( "getchar" ), LFUNCVAL( uart_getchar ) }, #if LUA_OPTIMIZE_MEMORY > 0 { LSTRKEY( "PAR_EVEN" ), LNUMVAL( PLATFORM_UART_PARITY_EVEN ) }, { LSTRKEY( "PAR_ODD" ), LNUMVAL( PLATFORM_UART_PARITY_ODD ) }, { LSTRKEY( "PAR_NONE" ), LNUMVAL( PLATFORM_UART_PARITY_NONE ) }, { LSTRKEY( "STOP_1" ), LNUMVAL( PLATFORM_UART_STOPBITS_1 ) }, { LSTRKEY( "STOP_1_5" ), LNUMVAL( PLATFORM_UART_STOPBITS_1_5 ) }, { LSTRKEY( "STOP_2" ), LNUMVAL( PLATFORM_UART_STOPBITS_2 ) }, { LSTRKEY( "NO_TIMEOUT" ), LNUMVAL( 0 ) }, { LSTRKEY( "INF_TIMEOUT" ), LNUMVAL( PLATFORM_UART_INFINITE_TIMEOUT ) }, #endif { LNILKEY, LNILVAL } }; LUALIB_API int luaopen_uart( lua_State *L ) { #if LUA_OPTIMIZE_MEMORY > 0 return 0;
#define MIN_OPT_LEVEL 1 #include "lrodefs.h" const LUA_REG_TYPE math_map[] = { #ifdef LUA_NUMBER_INTEGRAL {LSTRKEY("abs"), LFUNCVAL(math_abs)}, {LSTRKEY("ceil"), LFUNCVAL(math_identity)}, {LSTRKEY("floor"), LFUNCVAL(math_identity)}, {LSTRKEY("max"), LFUNCVAL(math_max)}, {LSTRKEY("min"), LFUNCVAL(math_min)}, {LSTRKEY("pow"), LFUNCVAL(math_pow)}, {LSTRKEY("random"), LFUNCVAL(math_random)}, {LSTRKEY("randomseed"), LFUNCVAL(math_randomseed)}, {LSTRKEY("sqrt"), LFUNCVAL(math_sqrt)}, #if LUA_OPTIMIZE_MEMORY > 0 {LSTRKEY("huge"), LNUMVAL(LONG_MAX)}, #endif #else {LSTRKEY("abs"), LFUNCVAL(math_abs)}, // {LSTRKEY("acos"), LFUNCVAL(math_acos)}, // {LSTRKEY("asin"), LFUNCVAL(math_asin)}, // {LSTRKEY("atan2"), LFUNCVAL(math_atan2)}, // {LSTRKEY("atan"), LFUNCVAL(math_atan)}, {LSTRKEY("ceil"), LFUNCVAL(math_ceil)}, // {LSTRKEY("cosh"), LFUNCVAL(math_cosh)}, // {LSTRKEY("cos"), LFUNCVAL(math_cos)}, // {LSTRKEY("deg"), LFUNCVAL(math_deg)}, // {LSTRKEY("exp"), LFUNCVAL(math_exp)}, {LSTRKEY("floor"), LFUNCVAL(math_floor)}, // {LSTRKEY("fmod"), LFUNCVAL(math_fmod)}, #if LUA_OPTIMIZE_MEMORY > 0 && defined(LUA_COMPAT_MOD)
} #endif // #ifdef BUILD_SERMUX // Module function map #define MIN_OPT_LEVEL 2 #include "lrodefs.h" const LUA_REG_TYPE uart_map[] = { { LSTRKEY( "setup" ), LFUNCVAL( uart_setup ) }, { LSTRKEY( "write" ), LFUNCVAL( uart_write ) }, { LSTRKEY( "read" ), LFUNCVAL( uart_read ) }, { LSTRKEY( "getchar" ), LFUNCVAL( uart_getchar ) }, { LSTRKEY( "set_buffer" ), LFUNCVAL( uart_set_buffer ) }, { LSTRKEY( "set_flow_control" ), LFUNCVAL( uart_set_flow_control ) }, #if LUA_OPTIMIZE_MEMORY > 0 { LSTRKEY( "PAR_EVEN" ), LNUMVAL( PLATFORM_UART_PARITY_EVEN ) }, { LSTRKEY( "PAR_ODD" ), LNUMVAL( PLATFORM_UART_PARITY_ODD ) }, { LSTRKEY( "PAR_NONE" ), LNUMVAL( PLATFORM_UART_PARITY_NONE ) }, { LSTRKEY( "PAR_MARK" ), LNUMVAL( PLATFORM_UART_PARITY_MARK ) }, { LSTRKEY( "PAR_SPACE" ), LNUMVAL( PLATFORM_UART_PARITY_SPACE ) }, { LSTRKEY( "STOP_1" ), LNUMVAL( PLATFORM_UART_STOPBITS_1 ) }, { LSTRKEY( "STOP_1_5" ), LNUMVAL( PLATFORM_UART_STOPBITS_1_5 ) }, { LSTRKEY( "STOP_2" ), LNUMVAL( PLATFORM_UART_STOPBITS_2 ) }, { LSTRKEY( "NO_TIMEOUT" ), LNUMVAL( 0 ) }, { LSTRKEY( "INF_TIMEOUT" ), LNUMVAL( UART_INFINITE_TIMEOUT ) }, { LSTRKEY( "FLOW_NONE" ), LNUMVAL( PLATFORM_UART_FLOW_NONE ) }, { LSTRKEY( "FLOW_RTS" ), LNUMVAL( PLATFORM_UART_FLOW_RTS ) }, { LSTRKEY( "FLOW_CTS" ), LNUMVAL( PLATFORM_UART_FLOW_CTS ) }, #endif #if LUA_OPTIMIZE_MEMORY > 0 && ( defined( BUILD_SERMUX ) || defined( BUILD_USB_CDC ) ) { LSTRKEY( "__metatable" ), LROVAL( uart_map ) },
return luaL_error( L, "invalid number" ); platform_uart_send( id, ( u8 )len ); } else { luaL_checktype( L, s, LUA_TSTRING ); buf = lua_tolstring( L, s, &len ); for( i = 0; i < len; i ++ ) platform_uart_send( id, buf[ i ] ); } } return 0; } // Module function map static const LUA_REG_TYPE uart_map[] = { { LSTRKEY( "setup" ), LFUNCVAL( uart_setup ) }, { LSTRKEY( "write" ), LFUNCVAL( uart_write ) }, { LSTRKEY( "on" ), LFUNCVAL( uart_on ) }, { LSTRKEY( "alt" ), LFUNCVAL( uart_alt ) }, { LSTRKEY( "STOPBITS_1" ), LNUMVAL( PLATFORM_UART_STOPBITS_1 ) }, { LSTRKEY( "STOPBITS_1_5" ), LNUMVAL( PLATFORM_UART_STOPBITS_1_5 ) }, { LSTRKEY( "STOPBITS_2" ), LNUMVAL( PLATFORM_UART_STOPBITS_2 ) }, { LSTRKEY( "PARITY_NONE" ), LNUMVAL( PLATFORM_UART_PARITY_NONE ) }, { LSTRKEY( "PARITY_EVEN" ), LNUMVAL( PLATFORM_UART_PARITY_EVEN ) }, { LSTRKEY( "PARITY_ODD" ), LNUMVAL( PLATFORM_UART_PARITY_ODD ) }, { LNILKEY, LNILVAL } }; NODEMCU_MODULE(UART, "uart", uart_map, NULL);
{ LSTRKEY( "getdiffnow" ), LFUNCVAL( tmr_getdiffnow ) }, { LSTRKEY( "getmindelay" ), LFUNCVAL( tmr_getmindelay ) }, { LSTRKEY( "getmaxdelay" ), LFUNCVAL( tmr_getmaxdelay ) }, { LSTRKEY( "setclock" ), LFUNCVAL( tmr_setclock ) }, { LSTRKEY( "getclock" ), LFUNCVAL( tmr_getclock ) }, #ifdef BUILD_LUA_INT_HANDLERS { LSTRKEY( "set_match_int" ), LFUNCVAL( tmr_set_match_int ) }, #endif #if LUA_OPTIMIZE_MEMORY > 0 && VTMR_NUM_TIMERS > 0 { LSTRKEY( "__metatable" ), LROVAL( tmr_map ) }, #endif #if VTMR_NUM_TIMERS > 0 { LSTRKEY( "__index" ), LFUNCVAL( tmr_mt_index ) }, #endif #if LUA_OPTIMIZE_MEMORY > 0 { LSTRKEY( "SYS_TIMER" ), LNUMVAL( PLATFORM_TIMER_SYS_ID ) }, #endif #if LUA_OPTIMIZE_MEMORY > 0 && defined( BUILD_LUA_INT_HANDLERS ) { LSTRKEY( "INT_ONESHOT" ), LNUMVAL( PLATFORM_TIMER_INT_ONESHOT ) }, { LSTRKEY( "INT_CYCLIC" ), LNUMVAL( PLATFORM_TIMER_INT_CYCLIC ) }, #endif { LNILKEY, LNILVAL } }; LUALIB_API int luaopen_tmr( lua_State *L ) { #if LUA_OPTIMIZE_MEMORY > 0 return 0; #else // #if LUA_OPTIMIZE_MEMORY > 0 luaL_register( L, AUXLIB_TMR, tmr_map ); #if VTMR_NUM_TIMERS > 0
{ LSTRKEY( "clrscr" ), LFUNCVAL( luaterm_clrscr ) }, { LSTRKEY( "clreol" ), LFUNCVAL( luaterm_clreol ) }, { LSTRKEY( "moveto" ), LFUNCVAL( luaterm_moveto ) }, { LSTRKEY( "moveup" ), LFUNCVAL( luaterm_moveup ) }, { LSTRKEY( "movedown" ), LFUNCVAL( luaterm_movedown ) }, { LSTRKEY( "moveleft" ), LFUNCVAL( luaterm_moveleft ) }, { LSTRKEY( "moveright" ), LFUNCVAL( luaterm_moveright ) }, { LSTRKEY( "getlines" ), LFUNCVAL( luaterm_getlines ) }, { LSTRKEY( "getcols" ), LFUNCVAL( luaterm_getcols ) }, { LSTRKEY( "print" ), LFUNCVAL( luaterm_print ) }, { LSTRKEY( "getcx" ), LFUNCVAL( luaterm_getcx ) }, { LSTRKEY( "getcy" ), LFUNCVAL( luaterm_getcy ) }, { LSTRKEY( "getchar" ), LFUNCVAL( luaterm_getchar ) }, #if LUA_OPTIMIZE_MEMORY > 0 { LSTRKEY( "__metatable" ), LROVAL( term_map ) }, { LSTRKEY( "NOWAIT" ), LNUMVAL( TERM_INPUT_DONT_WAIT ) }, { LSTRKEY( "WAIT" ), LNUMVAL( TERM_INPUT_WAIT ) }, #endif { LSTRKEY( "__index" ), LFUNCVAL( term_mt_index ) }, { LNILKEY, LNILVAL } }; LUALIB_API int luaopen_term( lua_State* L ) { #ifdef BUILD_TERM #if LUA_OPTIMIZE_MEMORY > 0 return 0; #else // #if LUA_OPTIMIZE_MEMORY > 0 // Register methods luaL_register( L, AUXLIB_TERM, term_map );
}; #undef U8G_DISPLAY_TABLE_ENTRY #undef U8G_FONT_TABLE_ENTRY static const LUA_REG_TYPE lu8g_map[] = { #define U8G_DISPLAY_TABLE_ENTRY(device) \ { LSTRKEY( #device ), LFUNCVAL ( lu8g_ ##device ) }, U8G_DISPLAY_TABLE_I2C U8G_DISPLAY_TABLE_SPI // Register fonts #define U8G_FONT_TABLE_ENTRY(font) \ { LSTRKEY( #font ), LUDATA( (void *)(u8g_ ## font) ) }, U8G_FONT_TABLE // Options for circle/ ellipse drawing { LSTRKEY( "DRAW_UPPER_RIGHT" ), LNUMVAL( U8G_DRAW_UPPER_RIGHT ) }, { LSTRKEY( "DRAW_UPPER_LEFT" ), LNUMVAL( U8G_DRAW_UPPER_LEFT ) }, { LSTRKEY( "DRAW_LOWER_RIGHT" ), LNUMVAL( U8G_DRAW_LOWER_RIGHT ) }, { LSTRKEY( "DRAW_LOWER_LEFT" ), LNUMVAL( U8G_DRAW_LOWER_LEFT ) }, { LSTRKEY( "DRAW_ALL" ), LNUMVAL( U8G_DRAW_ALL ) }, // Display modes { LSTRKEY( "MODE_BW" ), LNUMVAL( U8G_MODE_BW ) }, { LSTRKEY( "MODE_GRAY2BIT" ), LNUMVAL( U8G_MODE_GRAY2BIT ) }, { LSTRKEY( "__metatable" ), LROVAL( lu8g_map ) }, { LNILKEY, LNILVAL } }; int luaopen_u8g( lua_State *L ) { luaL_rometatable(L, "u8g.display", (void *)lu8g_display_map); // create metatable return 0; }
const LUA_REG_TYPE wifi_map[] = { { LSTRKEY( "setmode" ), LFUNCVAL( wifi_setmode ) }, { LSTRKEY( "getmode" ), LFUNCVAL( wifi_getmode ) }, { LSTRKEY( "getchannel" ), LFUNCVAL( wifi_getchannel ) }, { LSTRKEY( "setphymode" ), LFUNCVAL( wifi_setphymode ) }, { LSTRKEY( "getphymode" ), LFUNCVAL( wifi_getphymode ) }, { LSTRKEY( "startsmart" ), LFUNCVAL( wifi_start_smart ) }, { LSTRKEY( "stopsmart" ), LFUNCVAL( wifi_exit_smart ) }, { LSTRKEY( "sleeptype" ), LFUNCVAL( wifi_sleeptype ) }, #if LUA_OPTIMIZE_MEMORY > 0 { LSTRKEY( "sta" ), LROVAL( wifi_station_map ) }, { LSTRKEY( "ap" ), LROVAL( wifi_ap_map ) }, // { LSTRKEY( "NULLMODE" ), LNUMVAL( NULL_MODE ) }, { LSTRKEY( "STATION" ), LNUMVAL( STATION_MODE ) }, { LSTRKEY( "SOFTAP" ), LNUMVAL( SOFTAP_MODE ) }, { LSTRKEY( "STATIONAP" ), LNUMVAL( STATIONAP_MODE ) }, { LSTRKEY( "PHYMODE_B" ), LNUMVAL( PHY_MODE_B ) }, { LSTRKEY( "PHYMODE_G" ), LNUMVAL( PHY_MODE_G ) }, { LSTRKEY( "PHYMODE_N" ), LNUMVAL( PHY_MODE_N ) }, { LSTRKEY( "NONE_SLEEP" ), LNUMVAL( NONE_SLEEP_T ) }, { LSTRKEY( "LIGHT_SLEEP" ), LNUMVAL( LIGHT_SLEEP_T ) }, { LSTRKEY( "MODEM_SLEEP" ), LNUMVAL( MODEM_SLEEP_T ) }, { LSTRKEY( "OPEN" ), LNUMVAL( AUTH_OPEN ) }, // { LSTRKEY( "WEP" ), LNUMVAL( AUTH_WEP ) }, { LSTRKEY( "WPA_PSK" ), LNUMVAL( AUTH_WPA_PSK ) }, { LSTRKEY( "WPA2_PSK" ), LNUMVAL( AUTH_WPA2_PSK ) },
{ LSTRKEY( "getdnsserver" ), LFUNCVAL( net_getdnsserver ) }, { LSTRKEY( "resolve" ), LFUNCVAL( net_dns_static ) }, { LNILKEY, LNILVAL } }; static const LUA_REG_TYPE net_map[] = { { LSTRKEY( "createServer" ), LFUNCVAL( net_createServer ) }, { LSTRKEY( "createConnection" ), LFUNCVAL( net_createConnection ) }, { LSTRKEY( "createUDPSocket" ), LFUNCVAL( net_createUDPSocket ) }, { LSTRKEY( "multicastJoin"), LFUNCVAL( net_multicastJoin ) }, { LSTRKEY( "multicastLeave"), LFUNCVAL( net_multicastLeave ) }, { LSTRKEY( "dns" ), LROVAL( net_dns_map ) }, #ifdef TLS_MODULE_PRESENT { LSTRKEY( "cert" ), LROVAL( tls_cert_map ) }, #endif { LSTRKEY( "TCP" ), LNUMVAL( TYPE_TCP ) }, { LSTRKEY( "UDP" ), LNUMVAL( TYPE_UDP ) }, { LSTRKEY( "__metatable" ), LROVAL( net_map ) }, { LNILKEY, LNILVAL } }; int luaopen_net( lua_State *L ) { igmp_init(); luaL_rometatable(L, NET_TABLE_TCP_SERVER, (void *)net_tcpserver_map); luaL_rometatable(L, NET_TABLE_TCP_CLIENT, (void *)net_tcpsocket_map); luaL_rometatable(L, NET_TABLE_UDP_SOCKET, (void *)net_udpsocket_map); return 0; }
return 1; } // Module function map #define MIN_OPT_LEVEL 2 #include "lrodefs.h" const LUA_REG_TYPE i2c_map[] = { { LSTRKEY( "setup" ), LFUNCVAL( i2c_setup ) }, { LSTRKEY( "start" ), LFUNCVAL( i2c_start ) }, { LSTRKEY( "stop" ), LFUNCVAL( i2c_stop ) }, { LSTRKEY( "address" ), LFUNCVAL( i2c_address ) }, { LSTRKEY( "write" ), LFUNCVAL( i2c_write ) }, { LSTRKEY( "read" ), LFUNCVAL( i2c_read ) }, #if LUA_OPTIMIZE_MEMORY > 0 { LSTRKEY( "FAST" ), LNUMVAL( PLATFORM_I2C_SPEED_FAST ) }, { LSTRKEY( "SLOW" ), LNUMVAL( PLATFORM_I2C_SPEED_SLOW ) }, { LSTRKEY( "TRANSMITTER" ), LNUMVAL( PLATFORM_I2C_DIRECTION_TRANSMITTER ) }, { LSTRKEY( "RECEIVER" ), LNUMVAL( PLATFORM_I2C_DIRECTION_RECEIVER ) }, #endif { LNILKEY, LNILVAL } }; LUALIB_API int luaopen_i2c( lua_State *L ) { #if LUA_OPTIMIZE_MEMORY > 0 return 0; #else // #if LUA_OPTIMIZE_MEMORY > 0 luaL_register( L, AUXLIB_I2C, i2c_map ); // Add the stop bits and parity constants (for uart.setup)
{ return 0; } // Module function map #define MIN_OPT_LEVEL 2 #include "lrodefs.h" const LUA_REG_TYPE mcu_map[] = { { LSTRKEY( "write" ), LFUNCVAL( mcu_out_write ) }, { LSTRKEY( "off" ), LFUNCVAL( mcu_out_off ) }, { LSTRKEY( "on" ), LFUNCVAL( mcu_out_on ) }, { LSTRKEY( "read" ), LFUNCVAL( mcu_in_read ) }, { LSTRKEY( "trig" ), LFUNCVAL( mcu_in_trig ) }, { LSTRKEY( "PUMP_IN"), LNUMVAL( OUT_PUMP_IN ) }, { LSTRKEY( "PUMP_OUT"), LNUMVAL( OUT_PUMP_OUT ) }, { LSTRKEY( "PUMP1"), LNUMVAL( OUT_PUMP1 ) }, { LSTRKEY( "PUMP2"), LNUMVAL( OUT_PUMP2 ) }, { LSTRKEY( "PUMP3"), LNUMVAL( OUT_PUMP3 ) }, { LSTRKEY( "HEATER"), LNUMVAL( OUT_HEATER ) }, { LSTRKEY( "FAN"), LNUMVAL( OUT_FAN ) }, { LSTRKEY( "SPRAY"), LNUMVAL( OUT_SPRAY ) }, { LSTRKEY( "LCD"), LNUMVAL( OUT_LCD ) }, { LSTRKEY( "PUMP"), LNUMVAL( OUT_PUMP ) }, { LSTRKEY( "LED"), LNUMVAL( OUT_LED ) }, { LSTRKEY( "PWLED"), LNUMVAL( OUT_PWLED ) }, { LSTRKEY( "BTN1"), LNUMVAL( IN_BTN1 ) }, { LSTRKEY( "BTN2"), LNUMVAL( IN_BTN2 ) }, { LSTRKEY( "BTN3"), LNUMVAL( IN_BTN3 ) }, { LSTRKEY( "BTN4"), LNUMVAL( IN_BTN4 ) },
static int node_osprint( lua_State* L ) { if (lua_toboolean(L, 1)) { system_set_os_print(1); } else { system_set_os_print(0); } return 0; } // Module function map static const LUA_REG_TYPE node_egc_map[] = { { LSTRKEY( "setmode" ), LFUNCVAL( node_egc_setmode ) }, { LSTRKEY( "NOT_ACTIVE" ), LNUMVAL( EGC_NOT_ACTIVE ) }, { LSTRKEY( "ON_ALLOC_FAILURE" ), LNUMVAL( EGC_ON_ALLOC_FAILURE ) }, { LSTRKEY( "ON_MEM_LIMIT" ), LNUMVAL( EGC_ON_MEM_LIMIT ) }, { LSTRKEY( "ALWAYS" ), LNUMVAL( EGC_ALWAYS ) }, { LNILKEY, LNILVAL } }; static const LUA_REG_TYPE node_task_map[] = { { LSTRKEY( "post" ), LFUNCVAL( node_task_post ) }, { LSTRKEY( "LOW_PRIORITY" ), LNUMVAL( TASK_PRIORITY_LOW ) }, { LSTRKEY( "MEDIUM_PRIORITY" ), LNUMVAL( TASK_PRIORITY_MEDIUM ) }, { LSTRKEY( "HIGH_PRIORITY" ), LNUMVAL( TASK_PRIORITY_HIGH ) }, { LNILKEY, LNILVAL } }; static const LUA_REG_TYPE node_map[] = {
else idx = 0; base->AFR[ idx ] &= ~( 0x0F << ( pin * 4 ) ); base->AFR[ idx ] |= func << ( pin * 4 ); } } return 0; } // Module function map #define MIN_OPT_LEVEL 2 #include "lrodefs.h" const LUA_REG_TYPE stm32_pio_map[] = { { LSTRKEY( "set_function" ), LFUNCVAL( stm32_pio_set_function ) }, { LSTRKEY( "GPIO" ), LNUMVAL( PIN_FUNC_GPIO ) }, { LSTRKEY( "ADC" ), LNUMVAL( PIN_FUNC_ADC ) }, { LSTRKEY( "AF0" ), LNUMVAL( 0 ) }, { LSTRKEY( "AF1" ), LNUMVAL( 1 ) }, { LSTRKEY( "AF2" ), LNUMVAL( 2 ) }, { LSTRKEY( "AF3" ), LNUMVAL( 3 ) }, { LSTRKEY( "AF4" ), LNUMVAL( 4 ) }, { LSTRKEY( "AF5" ), LNUMVAL( 5 ) }, { LSTRKEY( "AF6" ), LNUMVAL( 6 ) }, { LSTRKEY( "AF7" ), LNUMVAL( 7 ) }, { LSTRKEY( "AF8" ), LNUMVAL( 8 ) }, { LSTRKEY( "AF9" ), LNUMVAL( 9 ) }, { LSTRKEY( "AF10" ), LNUMVAL( 10 ) }, { LSTRKEY( "AF11" ), LNUMVAL( 11 ) }, { LSTRKEY( "AF12" ), LNUMVAL( 12 ) }, { LSTRKEY( "AF13" ), LNUMVAL( 13 ) },
{ LNILKEY, LNILVAL } }; #if 0 static const LUA_REG_TYPE net_array_map[] = { { LSTRKEY( "__index" ), LFUNCVAL( net_array_index ) }, { LSTRKEY( "__newindex" ), LFUNCVAL( net_array_newindex ) }, { LNILKEY, LNILVAL } }; #endif const LUA_REG_TYPE net_map[] = { { LSTRKEY( "createServer" ), LFUNCVAL ( net_createServer ) }, { LSTRKEY( "createConnection" ), LFUNCVAL ( net_createConnection ) }, #if LUA_OPTIMIZE_MEMORY > 0 { LSTRKEY( "TCP" ), LNUMVAL( TCP ) }, { LSTRKEY( "UDP" ), LNUMVAL( UDP ) }, { LSTRKEY( "__metatable" ), LROVAL( net_map ) }, #endif { LNILKEY, LNILVAL } }; LUALIB_API int luaopen_net( lua_State *L ) { int i; for(i=0;i<MAX_SOCKET;i++) { socket[i] = LUA_NOREF; }
{ LSTRKEY( "input" ), LFUNCVAL( pio_port_input ) }, { LSTRKEY( "setpull" ), LFUNCVAL( pio_port_setpull ) }, { LSTRKEY( "setval" ), LFUNCVAL( pio_port_setval ) }, { LSTRKEY( "sethigh" ), LFUNCVAL( pio_port_sethigh ) }, { LSTRKEY( "setlow" ), LFUNCVAL( pio_port_setlow ) }, { LSTRKEY( "getval" ), LFUNCVAL( pio_port_getval ) }, { LNILKEY, LNILVAL } }; const LUA_REG_TYPE pio_map[] = { { LSTRKEY( "decode" ), LFUNCVAL( pio_decode ) }, #if LUA_OPTIMIZE_MEMORY > 0 { LSTRKEY( "pin" ), LROVAL( pio_pin_map ) }, { LSTRKEY( "port" ), LROVAL( pio_port_map ) }, { LSTRKEY( "INPUT" ), LNUMVAL( PIO_DIR_INPUT ) }, { LSTRKEY( "OUTPUT" ), LNUMVAL( PIO_DIR_OUTPUT ) }, { LSTRKEY( "PULLUP" ), LNUMVAL( PLATFORM_IO_PIN_PULLUP ) }, { LSTRKEY( "PULLDOWN" ), LNUMVAL( PLATFORM_IO_PIN_PULLDOWN ) }, { LSTRKEY( "NOPULL" ), LNUMVAL( PLATFORM_IO_PIN_NOPULL ) }, { LSTRKEY( "__metatable" ), LROVAL( pio_map ) }, #endif { LSTRKEY( "__index" ), LFUNCVAL( pio_mt_index ) }, { LNILKEY, LNILVAL } }; LUALIB_API int luaopen_pio( lua_State *L ) { #if LUA_OPTIMIZE_MEMORY > 0 return 0; #else // #if LUA_OPTIMIZE_MEMORY > 0
{ LNILKEY, LNILVAL } }; static const LUA_REG_TYPE lucg_map[] = { #undef UCG_DISPLAY_TABLE_ENTRY #define UCG_DISPLAY_TABLE_ENTRY(binding, device, extension) { LSTRKEY( #binding ), LFUNCVAL ( lucg_ ##binding ) }, UCG_DISPLAY_TABLE // Register fonts #undef UCG_FONT_TABLE_ENTRY #define UCG_FONT_TABLE_ENTRY(font) { LSTRKEY( #font ), LUDATA( (void *)(ucg_ ## font) ) }, UCG_FONT_TABLE // Font modes { LSTRKEY( "FONT_MODE_TRANSPARENT" ), LNUMVAL( UCG_FONT_MODE_TRANSPARENT ) }, { LSTRKEY( "FONT_MODE_SOLID" ), LNUMVAL( UCG_FONT_MODE_SOLID ) }, // Options for circle/ disc drawing { LSTRKEY( "DRAW_UPPER_RIGHT" ), LNUMVAL( UCG_DRAW_UPPER_RIGHT ) }, { LSTRKEY( "DRAW_UPPER_LEFT" ), LNUMVAL( UCG_DRAW_UPPER_LEFT ) }, { LSTRKEY( "DRAW_LOWER_RIGHT" ), LNUMVAL( UCG_DRAW_LOWER_RIGHT ) }, { LSTRKEY( "DRAW_LOWER_LEFT" ), LNUMVAL( UCG_DRAW_LOWER_LEFT ) }, { LSTRKEY( "DRAW_ALL" ), LNUMVAL( UCG_DRAW_ALL ) }, { LSTRKEY( "__metatable" ), LROVAL( lucg_map ) }, { LNILKEY, LNILVAL } }; int luaopen_ucg( lua_State *L ) {
// Module function map #define MIN_OPT_LEVEL 2 #include "lrodefs.h" const LUA_REG_TYPE net_map[] = { { LSTRKEY( "accept" ), LFUNCVAL( net_accept ) }, { LSTRKEY( "packip" ), LFUNCVAL( net_packip ) }, { LSTRKEY( "unpackip" ), LFUNCVAL( net_unpackip ) }, { LSTRKEY( "connect" ), LFUNCVAL( net_connect ) }, { LSTRKEY( "socket" ), LFUNCVAL( net_socket ) }, { LSTRKEY( "close" ), LFUNCVAL( net_close ) }, { LSTRKEY( "send" ), LFUNCVAL( net_send ) }, { LSTRKEY( "recv" ), LFUNCVAL( net_recv ) }, { LSTRKEY( "lookup" ), LFUNCVAL( net_lookup ) }, #if LUA_OPTIMIZE_MEMORY > 0 { LSTRKEY( "SOCK_STREAM" ), LNUMVAL( ELUA_NET_SOCK_STREAM ) }, { LSTRKEY( "SOCK_DGRAM" ), LNUMVAL( ELUA_NET_SOCK_DGRAM ) }, { LSTRKEY( "ERR_OK" ), LNUMVAL( ELUA_NET_ERR_OK ) }, { LSTRKEY( "ERR_TIMEOUT" ), LNUMVAL( ELUA_NET_ERR_TIMEDOUT ) }, { LSTRKEY( "ERR_CLOSED" ), LNUMVAL( ELUA_NET_ERR_CLOSED ) }, { LSTRKEY( "ERR_ABORTED" ), LNUMVAL( ELUA_NET_ERR_ABORTED ) }, { LSTRKEY( "ERR_OVERFLOW" ), LNUMVAL( ELUA_NET_ERR_OVERFLOW ) }, { LSTRKEY( "NO_TIMEOUT" ), LNUMVAL( 0 ) }, { LSTRKEY( "INF_TIMEOUT" ), LNUMVAL( PLATFORM_TIMER_INF_TIMEOUT ) }, #endif { LNILKEY, LNILVAL } }; LUALIB_API int luaopen_net( lua_State *L ) { #if LUA_OPTIMIZE_MEMORY > 0
static const LUA_REG_TYPE pcm_driver_map[] = { { LSTRKEY( "play" ), LFUNCVAL( pcm_drv_play ) }, { LSTRKEY( "pause" ), LFUNCVAL( pcm_drv_pause ) }, { LSTRKEY( "stop" ), LFUNCVAL( pcm_drv_stop ) }, { LSTRKEY( "close" ), LFUNCVAL( pcm_drv_close ) }, { LSTRKEY( "on" ), LFUNCVAL( pcm_drv_on ) }, { LSTRKEY( "__gc" ), LFUNCVAL( pcm_drv_free ) }, { LSTRKEY( "__index" ), LROVAL( pcm_driver_map ) }, { LNILKEY, LNILVAL } }; // Module function map static const LUA_REG_TYPE pcm_map[] = { { LSTRKEY( "new" ), LFUNCVAL( pcm_new ) }, { LSTRKEY( "SD" ), LNUMVAL( PCM_DRIVER_SD ) }, { LSTRKEY( "RATE_1K" ), LNUMVAL( PCM_RATE_1K ) }, { LSTRKEY( "RATE_2K" ), LNUMVAL( PCM_RATE_2K ) }, { LSTRKEY( "RATE_4K" ), LNUMVAL( PCM_RATE_4K ) }, { LSTRKEY( "RATE_5K" ), LNUMVAL( PCM_RATE_5K ) }, { LSTRKEY( "RATE_8K" ), LNUMVAL( PCM_RATE_8K ) }, { LSTRKEY( "RATE_10K" ), LNUMVAL( PCM_RATE_10K ) }, { LSTRKEY( "RATE_12K" ), LNUMVAL( PCM_RATE_12K ) }, { LSTRKEY( "RATE_16K" ), LNUMVAL( PCM_RATE_16K ) }, { LNILKEY, LNILVAL } }; int luaopen_pcm( lua_State *L ) { luaL_rometatable( L, "pcm.driver", (void *)pcm_driver_map ); // create metatable return 0; }
} else return 0; } // Module function map #define MIN_OPT_LEVEL 2 #include "lrodefs.h" const LUA_REG_TYPE can_map[] = { { LSTRKEY( "setup" ), LFUNCVAL( can_setup ) }, { LSTRKEY( "send" ), LFUNCVAL( can_send ) }, { LSTRKEY( "recv" ), LFUNCVAL( can_recv ) }, #if LUA_OPTIMIZE_MEMORY > 0 { LSTRKEY( "ID_STD" ), LNUMVAL( ELUA_CAN_ID_STD ) }, { LSTRKEY( "ID_EXT" ), LNUMVAL( ELUA_CAN_ID_EXT ) }, #endif { LNILKEY, LNILVAL } }; LUALIB_API int luaopen_can( lua_State *L ) { #if LUA_OPTIMIZE_MEMORY > 0 return 0; #else // #if LUA_OPTIMIZE_MEMORY > 0 luaL_register( L, AUXLIB_CAN, can_map ); // Module constants MOD_REG_NUMBER( L, "ID_STD", ELUA_CAN_ID_STD ); MOD_REG_NUMBER( L, "ID_EXT", ELUA_CAN_ID_EXT );
{ LNILKEY, LNILVAL } }; const LUA_REG_TYPE wifi_map[] = { { LSTRKEY( "setmode" ), LFUNCVAL( wifi_setmode ) }, { LSTRKEY( "getmode" ), LFUNCVAL( wifi_getmode ) }, { LSTRKEY( "startsmart" ), LFUNCVAL( wifi_start_smart ) }, { LSTRKEY( "stopsmart" ), LFUNCVAL( wifi_exit_smart ) }, { LSTRKEY( "sleeptype" ), LFUNCVAL( wifi_sleeptype ) }, #if LUA_OPTIMIZE_MEMORY > 0 { LSTRKEY( "sta" ), LROVAL( wifi_station_map ) }, { LSTRKEY( "ap" ), LROVAL( wifi_ap_map ) }, // { LSTRKEY( "NULLMODE" ), LNUMVAL( NULL_MODE ) }, { LSTRKEY( "STATION" ), LNUMVAL( STATION_MODE ) }, { LSTRKEY( "SOFTAP" ), LNUMVAL( SOFTAP_MODE ) }, { LSTRKEY( "STATIONAP" ), LNUMVAL( STATIONAP_MODE ) }, { LSTRKEY( "NONE_SLEEP" ), LNUMVAL( NONE_SLEEP_T ) }, { LSTRKEY( "LIGHT_SLEEP" ), LNUMVAL( LIGHT_SLEEP_T ) }, { LSTRKEY( "MODEM_SLEEP" ), LNUMVAL( MODEM_SLEEP_T ) }, // { LSTRKEY( "STA_IDLE" ), LNUMVAL( STATION_IDLE ) }, // { LSTRKEY( "STA_CONNECTING" ), LNUMVAL( STATION_CONNECTING ) }, // { LSTRKEY( "STA_WRONGPWD" ), LNUMVAL( STATION_WRONG_PASSWORD ) }, // { LSTRKEY( "STA_APNOTFOUND" ), LNUMVAL( STATION_NO_AP_FOUND ) }, // { LSTRKEY( "STA_FAIL" ), LNUMVAL( STATION_CONNECT_FAIL ) }, // { LSTRKEY( "STA_GOTIP" ), LNUMVAL( STATION_GOT_IP ) }, { LSTRKEY( "__metatable" ), LROVAL( wifi_map ) },
// } // // Lua: result = dht.temperature() // static int dht_lapi_temperature( lua_State *L ) // { // lua_pushnumber( L, dht_getTemperature() ); // return 1; // } // // Lua: result = dht.temperaturedecimal() // static int dht_lapi_temperaturedecimal( lua_State *L ) // { // double value = dht_getTemperature(); // int result = (int)((value - (int)value) * 1000); // lua_pushnumber( L, result ); // return 1; // } // Module function map static const LUA_REG_TYPE dht_map[] = { { LSTRKEY( "read" ), LFUNCVAL( dht_lapi_read ) }, { LSTRKEY( "read11" ), LFUNCVAL( dht_lapi_read11 ) }, { LSTRKEY( "readxx" ), LFUNCVAL( dht_lapi_readxx ) }, { LSTRKEY( "OK" ), LNUMVAL( DHTLIB_OK ) }, { LSTRKEY( "ERROR_CHECKSUM" ), LNUMVAL( DHTLIB_ERROR_CHECKSUM ) }, { LSTRKEY( "ERROR_TIMEOUT" ), LNUMVAL( DHTLIB_ERROR_TIMEOUT ) }, { LNILKEY, LNILVAL } }; NODEMCU_MODULE(DHT, "dht", dht_map, NULL);
{ LSTRKEY( "time" ), LFUNCVAL( tmr_time ) }, { LSTRKEY( "register" ), LFUNCVAL( tmr_register ) }, { LSTRKEY( "alarm" ), LFUNCVAL( tmr_alarm ) }, { LSTRKEY( "start" ), LFUNCVAL( tmr_start ) }, { LSTRKEY( "stop" ), LFUNCVAL( tmr_stop ) }, #ifdef TIMER_SUSPEND_ENABLE { LSTRKEY( "suspend" ), LFUNCVAL( tmr_suspend ) }, { LSTRKEY( "suspend_all" ), LFUNCVAL( tmr_suspend_all ) }, { LSTRKEY( "resume" ), LFUNCVAL( tmr_resume ) }, { LSTRKEY( "resume_all" ), LFUNCVAL( tmr_resume_all ) }, #endif { LSTRKEY( "unregister" ), LFUNCVAL( tmr_unregister ) }, { LSTRKEY( "state" ), LFUNCVAL( tmr_state ) }, { LSTRKEY( "interval" ), LFUNCVAL( tmr_interval ) }, { LSTRKEY( "create" ), LFUNCVAL( tmr_create ) }, { LSTRKEY( "ALARM_SINGLE" ), LNUMVAL( TIMER_MODE_SINGLE ) }, { LSTRKEY( "ALARM_SEMI" ), LNUMVAL( TIMER_MODE_SEMI ) }, { LSTRKEY( "ALARM_AUTO" ), LNUMVAL( TIMER_MODE_AUTO ) }, { LNILKEY, LNILVAL } }; #include "pm/swtimer.h" int luaopen_tmr( lua_State *L ){ int i; luaL_rometatable(L, "tmr.timer", (void *)tmr_dyn_map); for(i=0; i<NUM_TMR; i++){ alarm_timers[i].lua_ref = LUA_NOREF; alarm_timers[i].self_ref = LUA_REFNIL; alarm_timers[i].mode = TIMER_MODE_OFF;
return 0; else { lua_pushinteger( L, sz ); return 1; } } // Module function map #define MIN_OPT_LEVEL 2 #include "lrodefs.h" const LUA_REG_TYPE mbed_pio_map[] = { #if LUA_OPTIMIZE_MEMORY > 0 { LSTRKEY( "__metatable" ), LROVAL( mbed_pio_map ) }, { LSTRKEY( "RES_PULLUP" ), LNUMVAL( PINSEL_PINMODE_PULLUP )}, { LSTRKEY( "RES_TRISTATE" ), LNUMVAL( PINSEL_PINMODE_TRISTATE )}, { LSTRKEY( "RES_PULLDOWN" ), LNUMVAL( PINSEL_PINMODE_PULLDOWN )}, { LSTRKEY( "FUNCTION_0" ), LNUMVAL( PINSEL_FUNC_0 )}, { LSTRKEY( "FUNCTION_1" ), LNUMVAL( PINSEL_FUNC_1 )}, { LSTRKEY( "FUNCTION_2" ), LNUMVAL( PINSEL_FUNC_2 )}, { LSTRKEY( "FUNCTION_3" ), LNUMVAL( PINSEL_FUNC_3 )}, { LSTRKEY( "MODE_DEFAULT" ), LNUMVAL( PINSEL_PINMODE_NORMAL )}, { LSTRKEY( "MODE_OD" ), LNUMVAL( PINSEL_PINMODE_OPENDRAIN )}, #endif { LSTRKEY( "configpin" ), LFUNCVAL( configpin ) }, { LSTRKEY( "__index" ), LFUNCVAL( mbed_pio_mt_index ) }, { LNILKEY, LNILVAL } }; LUALIB_API int luaopen_mbed_pio( lua_State *L )
return 0; } // Module function map #define MIN_OPT_LEVEL 2 #include "lrodefs.h" const LUA_REG_TYPE elua_map[] = { { LSTRKEY( "egc_setup" ), LFUNCVAL( elua_egc_setup ) }, { LSTRKEY( "version" ), LFUNCVAL( elua_version ) }, { LSTRKEY( "save_history" ), LFUNCVAL( elua_save_history ) }, { LSTRKEY( "strftime" ), LFUNCVAL( elua_strftime ) }, { LSTRKEY( "fs_mounted" ), LFUNCVAL( elua_fs_mounted ) }, { LSTRKEY( "help" ), LFUNCVAL( elua_help ) }, #if LUA_OPTIMIZE_MEMORY > 0 { LSTRKEY( "EGC_NOT_ACTIVE" ), LNUMVAL( EGC_NOT_ACTIVE ) }, { LSTRKEY( "EGC_ON_ALLOC_FAILURE" ), LNUMVAL( EGC_ON_ALLOC_FAILURE ) }, { LSTRKEY( "EGC_ON_MEM_LIMIT" ), LNUMVAL( EGC_ON_MEM_LIMIT ) }, { LSTRKEY( "EGC_ALWAYS" ), LNUMVAL( EGC_ALWAYS ) }, #endif { LNILKEY, LNILVAL } }; LUALIB_API int luaopen_elua( lua_State *L ) { #if LUA_OPTIMIZE_MEMORY > 0 return 0; #else luaL_register( L, AUXLIB_ELUA, elua_map ); MOD_REG_NUMBER( L, "EGC_NOT_ACTIVE", EGC_NOT_ACTIVE ); MOD_REG_NUMBER( L, "EGC_ON_ALLOC_FAILURE", EGC_ON_ALLOC_FAILURE );
} while (repeat>0); return 0; } #undef DELAY_TABLE_MAX_LEN // Module function map const LUA_REG_TYPE gpio_map[] = { { LSTRKEY( "mode" ), LFUNCVAL( lgpio_mode ) }, { LSTRKEY( "read" ), LFUNCVAL( lgpio_read ) }, { LSTRKEY( "write" ), LFUNCVAL( lgpio_write ) }, { LSTRKEY( "serout" ), LFUNCVAL( lgpio_serout ) }, #ifdef GPIO_INTERRUPT_ENABLE { LSTRKEY( "remove" ), LFUNCVAL( lgpio_remove_isr ) }, { LSTRKEY( "uninstall" ), LFUNCVAL( lgpio_uninstall ) }, { LSTRKEY( "INT" ), LNUMVAL( PLATFORM_INTERRUPT ) }, #endif { LSTRKEY( "OUTPUT" ), LNUMVAL( OUTPUT ) }, { LSTRKEY( "INPUT" ), LNUMVAL( INPUT ) }, { LSTRKEY( "INOUT" ), LNUMVAL( INOUT ) }, { LSTRKEY( "HIGH" ), LNUMVAL( HIGH ) }, { LSTRKEY( "LOW" ), LNUMVAL( LOW ) }, { LSTRKEY( "FLOAT" ), LNUMVAL( FLOAT ) }, { LSTRKEY( "PULLUP" ), LNUMVAL( PULLUP ) }, { LNILKEY, LNILVAL } }; LUALIB_API int luaopen_gpio(lua_State *L) { #if LUA_OPTIMIZE_MEMORY > 0 return 0;