Commit 4e8ef87d authored by Johny Mattsson's avatar Johny Mattsson
Browse files

Reworked module registration, removed modules.h

Module creation & registration now made a lot simpler. In essence,
each module file is now self-contained and only needs a

  NODEMCU_MODULE(MYNAME, "myname", myname_map, luaopen_myname);

line to both be automatically recognised by the Lua initialization
as well as honor the LUA_USE_MODULES_MYNAME #define.
parent b773290b
// Module for interfacing with the OneWire interface
#include "module.h"
#include "lauxlib.h"
#include "lrodefs.h"
#include "platform.h"
#include "driver/onewire.h"
......@@ -280,7 +280,7 @@ static int ow_crc16( lua_State *L )
#endif
// Module function map
const LUA_REG_TYPE ow_map[] = {
static const LUA_REG_TYPE ow_map[] = {
{ LSTRKEY( "setup" ), LFUNCVAL( ow_setup ) },
{ LSTRKEY( "reset" ), LFUNCVAL( ow_reset ) },
{ LSTRKEY( "skip" ), LFUNCVAL( ow_skip ) },
......@@ -305,10 +305,4 @@ const LUA_REG_TYPE ow_map[] = {
{ LNILKEY, LNILVAL }
};
LUALIB_API int luaopen_ow( lua_State *L ) {
#if MIN_OPT_LEVEL==2 && LUA_OPTIMIZE_MEMORY==2
return 0;
#else
# error "NodeMCU modules must be build with LTR enabled (MIN_OPT_LEVEL=2 and LUA_OPTIMIZE_MEMORY=2)"
#endif
}
NODEMCU_MODULE(OW, "ow", ow_map, NULL);
// Module for interfacing with PWM
#include "module.h"
#include "lauxlib.h"
#include "platform.h"
#include "lrodefs.h"
#include "c_types.h"
// Lua: realfrequency = setup( id, frequency, duty )
......@@ -122,7 +121,7 @@ static int lpwm_getduty( lua_State* L )
}
// Module function map
const LUA_REG_TYPE pwm_map[] = {
static const LUA_REG_TYPE pwm_map[] = {
{ LSTRKEY( "setup" ), LFUNCVAL( lpwm_setup ) },
{ LSTRKEY( "close" ), LFUNCVAL( lpwm_close ) },
{ LSTRKEY( "start" ), LFUNCVAL( lpwm_start ) },
......@@ -134,10 +133,4 @@ const LUA_REG_TYPE pwm_map[] = {
{ LNILKEY, LNILVAL }
};
LUALIB_API int luaopen_pwm( lua_State *L ) {
#if MIN_OPT_LEVEL==2 && LUA_OPTIMIZE_MEMORY==2
return 0;
#else
# error "NodeMCU modules must be build with LTR enabled (MIN_OPT_LEVEL=2 and LUA_OPTIMIZE_MEMORY=2)"
#endif
}
NODEMCU_MODULE(PWM, "pwm", pwm_map, NULL);
#include "module.h"
#include "lauxlib.h"
#include "platform.h"
#include "lrodefs.h"
//#include "driver/easygpio.h"
//static Ping_Data pingA;
#define defPulseLen 185
......@@ -80,17 +80,14 @@ static int ICACHE_FLASH_ATTR rc_send(lua_State* L) {
}
// Module function map
const LUA_REG_TYPE rc_map[] = {
static const LUA_REG_TYPE rc_map[] = {
{ LSTRKEY( "send" ), LFUNCVAL( rc_send )},
{ LNILKEY, LNILVAL}
};
//LUALIB_API int luaopen_ultra(lua_State *L) {
LUALIB_API int luaopen_rc(lua_State *L) {
int luaopen_rc(lua_State *L) {
// TODO: Make sure that the GPIO system is initialized
#if MIN_OPT_LEVEL==2 && LUA_OPTIMIZE_MEMORY==2
return 0;
#else
# error "NodeMCU modules must be build with LTR enabled (MIN_OPT_LEVEL=2 and LUA_OPTIMIZE_MEMORY=2)"
#endif
}
NODEMCU_MODULE(RC, "rc", rc_map, luaopen_rc);
// Module for RTC sample FIFO storage
#include "module.h"
#include "lauxlib.h"
#include "lrodefs.h"
#include "user_modules.h"
#include "rtc/rtctime.h"
#define RTCTIME_SLEEP_ALIGNED rtctime_deep_sleep_until_aligned_us
......@@ -165,7 +165,7 @@ static int rtcfifo_dsleep_until_sample (lua_State *L)
#endif
// Module function map
const LUA_REG_TYPE rtcfifo_map[] = {
static const LUA_REG_TYPE rtcfifo_map[] = {
{ LSTRKEY("prepare"), LFUNCVAL(rtcfifo_prepare) },
{ LSTRKEY("ready"), LFUNCVAL(rtcfifo_ready) },
{ LSTRKEY("put"), LFUNCVAL(rtcfifo_put) },
......@@ -179,11 +179,4 @@ const LUA_REG_TYPE rtcfifo_map[] = {
{ LNILKEY, LNILVAL }
};
LUALIB_API int luaopen_rtcfifo (lua_State *L)
{
#if MIN_OPT_LEVEL==2 && LUA_OPTIMIZE_MEMORY==2
return 0;
#else
# error "NodeMCU modules must be build with LTR enabled (MIN_OPT_LEVEL=2 and LUA_OPTIMIZE_MEMORY=2)"
#endif
}
NODEMCU_MODULE(RTCFIFO, "rtcfifo", rtcfifo_map, NULL);
// Module for RTC user memory access
#include "module.h"
#include "lauxlib.h"
#include "lrodefs.h"
#include "rtc/rtcaccess.h"
static int rtcmem_read32 (lua_State *L)
......@@ -41,16 +41,10 @@ static int rtcmem_write32 (lua_State *L)
// Module function map
const LUA_REG_TYPE rtcmem_map[] = {
static const LUA_REG_TYPE rtcmem_map[] = {
{ LSTRKEY("read32"), LFUNCVAL(rtcmem_read32) },
{ LSTRKEY("write32"), LFUNCVAL(rtcmem_write32) },
{ LNILKEY, LNILVAL }
};
LUALIB_API int luaopen_rtcmem (lua_State *L) {
#if MIN_OPT_LEVEL==2 && LUA_OPTIMIZE_MEMORY==2
return 0;
#else
# error "NodeMCU modules must be build with LTR enabled (MIN_OPT_LEVEL=2 and LUA_OPTIMIZE_MEMORY=2)"
#endif
}
NODEMCU_MODULE(RTCMEM, "rtcmem", rtcmem_map, NULL);
// Module for RTC time keeping
#include "module.h"
#include "lauxlib.h"
#include "lrodefs.h"
#include "rtc/rtctime_internal.h"
#include "rtc/rtctime.h"
......@@ -116,7 +116,7 @@ static int rtctime_dsleep_aligned (lua_State *L)
// Module function map
const LUA_REG_TYPE rtctime_map[] = {
static const LUA_REG_TYPE rtctime_map[] = {
{ LSTRKEY("set"), LFUNCVAL(rtctime_set) },
{ LSTRKEY("get"), LFUNCVAL(rtctime_get) },
{ LSTRKEY("dsleep"), LFUNCVAL(rtctime_dsleep) },
......@@ -124,10 +124,4 @@ const LUA_REG_TYPE rtctime_map[] = {
{ LNILKEY, LNILVAL }
};
LUALIB_API int luaopen_rtctime (lua_State *L) {
#if MIN_OPT_LEVEL==2 && LUA_OPTIMIZE_MEMORY==2
return 0;
#else
# error "NodeMCU modules must be build with LTR enabled (MIN_OPT_LEVEL=2 and LUA_OPTIMIZE_MEMORY=2)"
#endif
}
NODEMCU_MODULE(RTCTIME, "rtctime", rtctime_map, NULL);
......@@ -33,8 +33,8 @@
// Module for Simple Network Time Protocol (SNTP)
#include "module.h"
#include "lauxlib.h"
#include "lrodefs.h"
#include "os_type.h"
#include "osapi.h"
#include "lwip/udp.h"
......@@ -376,15 +376,9 @@ error:
// Module function map
const LUA_REG_TYPE sntp_map[] = {
static const LUA_REG_TYPE sntp_map[] = {
{ LSTRKEY("sync"), LFUNCVAL(sntp_sync) },
{ LNILKEY, LNILVAL }
};
LUALIB_API int luaopen_sntp (lua_State *L) {
#if MIN_OPT_LEVEL==2 && LUA_OPTIMIZE_MEMORY==2
return 0;
#else
# error "NodeMCU modules must be build with LTR enabled (MIN_OPT_LEVEL=2 and LUA_OPTIMIZE_MEMORY=2)"
#endif
}
NODEMCU_MODULE(SNTP, "sntp", sntp_map, NULL);
// Module for interfacing with the SPI interface
#include "module.h"
#include "lauxlib.h"
#include "platform.h"
#include "lrodefs.h"
#define SPI_HALFDUPLEX 0
#define SPI_FULLDUPLEX 1
......@@ -306,7 +306,7 @@ static int spi_transaction( lua_State *L )
// Module function map
const LUA_REG_TYPE spi_map[] = {
static const LUA_REG_TYPE spi_map[] = {
{ LSTRKEY( "setup" ), LFUNCVAL( spi_setup ) },
{ LSTRKEY( "send" ), LFUNCVAL( spi_send_recv ) },
{ LSTRKEY( "recv" ), LFUNCVAL( spi_recv ) },
......@@ -325,10 +325,4 @@ const LUA_REG_TYPE spi_map[] = {
{ LNILKEY, LNILVAL }
};
LUALIB_API int luaopen_spi( lua_State *L ) {
#if MIN_OPT_LEVEL==2 && LUA_OPTIMIZE_MEMORY==2
return 0;
#else
# error "NodeMCU modules must be build with LTR enabled (MIN_OPT_LEVEL=2 and LUA_OPTIMIZE_MEMORY=2)"
#endif
}
NODEMCU_MODULE(SPI, "spi", spi_map, NULL);
......@@ -48,9 +48,9 @@ tmr.softwd(int)
the timer units are seconds
*/
#include "module.h"
#include "lauxlib.h"
#include "platform.h"
#include "lrodefs.h"
#include "c_types.h"
#define TIMER_MODE_OFF 3
......@@ -306,7 +306,7 @@ static int tmr_softwd( lua_State* L ){
// Module function map
const LUA_REG_TYPE tmr_map[] = {
static const LUA_REG_TYPE tmr_map[] = {
{ LSTRKEY( "delay" ), LFUNCVAL( tmr_delay ) },
{ LSTRKEY( "now" ), LFUNCVAL( tmr_now ) },
{ LSTRKEY( "wdclr" ), LFUNCVAL( tmr_wdclr ) },
......@@ -325,7 +325,7 @@ const LUA_REG_TYPE tmr_map[] = {
{ LNILKEY, LNILVAL }
};
LUALIB_API int luaopen_tmr( lua_State *L ){
int luaopen_tmr( lua_State *L ){
int i;
for(i=0; i<NUM_TMR; i++){
alarm_timers[i].lua_ref = LUA_NOREF;
......@@ -336,10 +336,7 @@ LUALIB_API int luaopen_tmr( lua_State *L ){
ets_timer_disarm(&rtc_timer);
ets_timer_setfn(&rtc_timer, rtc_callback, NULL);
ets_timer_arm_new(&rtc_timer, 1000, 1, 1);
#if MIN_OPT_LEVEL==2 && LUA_OPTIMIZE_MEMORY==2
return 0;
#else
# error "NodeMCU modules must be build with LTR enabled (MIN_OPT_LEVEL=2 and LUA_OPTIMIZE_MEMORY=2)"
#endif
}
NODEMCU_MODULE(TMR, "tmr", tmr_map, luaopen_tmr);
......@@ -4,9 +4,9 @@
* Created on: Aug 21, 2015
* Author: Michael Lucas (Aeprox @github)
*/
#include "module.h"
#include "lauxlib.h"
#include "platform.h"
#include "lrodefs.h"
#include "../tsl2561/tsl2561.h"
static uint16_t ch0;
......@@ -101,7 +101,7 @@ static int ICACHE_FLASH_ATTR tsl2561_lua_getchannels(lua_State* L) {
}
// Module function map
const LUA_REG_TYPE tsl2561_map[] = {
static const LUA_REG_TYPE tsl2561_map[] = {
{ LSTRKEY( "settiming" ), LFUNCVAL( tsl2561_lua_settiming)},
{ LSTRKEY( "getlux" ), LFUNCVAL( tsl2561_lua_calclux )},
{ LSTRKEY( "getrawchannels" ), LFUNCVAL( tsl2561_lua_getchannels )},
......@@ -124,10 +124,4 @@ const LUA_REG_TYPE tsl2561_map[] = {
{ LNILKEY, LNILVAL}
};
LUALIB_API int luaopen_tsl2561(lua_State *L) {
#if MIN_OPT_LEVEL==2 && LUA_OPTIMIZE_MEMORY==2
return 0;
#else
# error "NodeMCU modules must be build with LTR enabled (MIN_OPT_LEVEL=2 and LUA_OPTIMIZE_MEMORY=2)"
#endif
}
NODEMCU_MODULE(TSL2561, "tsl2561", tsl2561_map, NULL);
// Module for U8glib
#include "module.h"
#include "lauxlib.h"
#include "platform.h"
#include "lrodefs.h"
#include "c_stdlib.h"
......@@ -1084,7 +1084,7 @@ static const LUA_REG_TYPE lu8g_display_map[] = {
#undef U8G_DISPLAY_TABLE_ENTRY
#undef U8G_FONT_TABLE_ENTRY
const LUA_REG_TYPE lu8g_map[] = {
static const LUA_REG_TYPE lu8g_map[] = {
#define U8G_DISPLAY_TABLE_ENTRY(device) \
{ LSTRKEY( #device ), LFUNCVAL ( lu8g_ ##device ) },
U8G_DISPLAY_TABLE_I2C
......@@ -1106,11 +1106,9 @@ const LUA_REG_TYPE lu8g_map[] = {
{ LNILKEY, LNILVAL }
};
LUALIB_API int luaopen_u8g( lua_State *L ) {
int luaopen_u8g( lua_State *L ) {
luaL_rometatable(L, "u8g.display", (void *)lu8g_display_map); // create metatable
#if MIN_OPT_LEVEL==2 && LUA_OPTIMIZE_MEMORY==2
return 0;
#else
# error "NodeMCU modules must be build with LTR enabled (MIN_OPT_LEVEL=2 and LUA_OPTIMIZE_MEMORY=2)"
#endif
}
NODEMCU_MODULE(U8G, "u8g", lu8g_map, luaopen_u8g);
// Module for interfacing with serial
#include "module.h"
#include "lauxlib.h"
#include "platform.h"
#include "lrodefs.h"
#include "c_types.h"
#include "c_string.h"
......@@ -155,7 +155,7 @@ static int uart_write( lua_State* L )
}
// Module function map
const LUA_REG_TYPE uart_map[] = {
static const LUA_REG_TYPE uart_map[] = {
{ LSTRKEY( "setup" ), LFUNCVAL( uart_setup ) },
{ LSTRKEY( "write" ), LFUNCVAL( uart_write ) },
{ LSTRKEY( "on" ), LFUNCVAL( uart_on ) },
......@@ -163,10 +163,4 @@ const LUA_REG_TYPE uart_map[] = {
{ LNILKEY, LNILVAL }
};
LUALIB_API int luaopen_uart( lua_State *L ) {
#if MIN_OPT_LEVEL==2 && LUA_OPTIMIZE_MEMORY==2
return 0;
#else
# error "NodeMCU modules must be build with LTR enabled (MIN_OPT_LEVEL=2 and LUA_OPTIMIZE_MEMORY=2)"
#endif
}
NODEMCU_MODULE(UART, "uart", uart_map, NULL);
// Module for Ucglib
#include "module.h"
#include "lauxlib.h"
#include "platform.h"
#include "lrodefs.h"
#include "c_stdlib.h"
......@@ -925,7 +925,7 @@ static const LUA_REG_TYPE lucg_display_map[] =
{ LNILKEY, LNILVAL }
};
const LUA_REG_TYPE lucg_map[] =
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 ) },
......@@ -951,8 +951,10 @@ const LUA_REG_TYPE lucg_map[] =
{ LNILKEY, LNILVAL }
};
LUALIB_API int luaopen_ucg( lua_State *L )
int luaopen_ucg( lua_State *L )
{
luaL_rometatable(L, "ucg.display", (void *)lucg_display_map); // create metatable
return 0;
}
NODEMCU_MODULE(UCG, "ucg", lucg_map, luaopen_ucg);
// Module for interfacing with WIFI
#include "module.h"
#include "lauxlib.h"
#include "platform.h"
#include "lrodefs.h"
#include "c_string.h"
#include "c_stdlib.h"
......@@ -1377,7 +1377,7 @@ static const LUA_REG_TYPE wifi_ap_map[] = {
{ LNILKEY, LNILVAL }
};
const LUA_REG_TYPE wifi_map[] = {
static const LUA_REG_TYPE wifi_map[] = {
{ LSTRKEY( "setmode" ), LFUNCVAL( wifi_setmode ) },
{ LSTRKEY( "getmode" ), LFUNCVAL( wifi_getmode ) },
{ LSTRKEY( "getchannel" ), LFUNCVAL( wifi_getchannel ) },
......@@ -1421,11 +1421,4 @@ const LUA_REG_TYPE wifi_map[] = {
{ LNILKEY, LNILVAL }
};
LUALIB_API int luaopen_wifi( lua_State *L )
{
#if MIN_OPT_LEVEL==2 && LUA_OPTIMIZE_MEMORY==2
return 0;
#else
# error "NodeMCU modules must be build with LTR enabled (MIN_OPT_LEVEL=2 and LUA_OPTIMIZE_MEMORY=2)"
#endif
}
NODEMCU_MODULE(WIFI, "wifi", wifi_map, NULL);
#include "module.h"
#include "lauxlib.h"
#include "platform.h"
#include "lrodefs.h"
#include "c_stdlib.h"
#include "c_string.h"
......@@ -122,14 +122,11 @@ static int ICACHE_FLASH_ATTR ws2801_writergb(lua_State* L) {
return 0;
}
const LUA_REG_TYPE ws2801_map[] =
static const LUA_REG_TYPE ws2801_map[] =
{
{ LSTRKEY( "write" ), LFUNCVAL( ws2801_writergb )},
{ LSTRKEY( "init" ), LFUNCVAL( ws2801_init_lua )},
{ LNILKEY, LNILVAL}
};
LUALIB_API int luaopen_ws2801(lua_State *L) {
return 0;
}
NODEMCU_MODULE(WS2801, "ws2801", ws2801_map, NULL);
#include "module.h"
#include "lauxlib.h"
#include "platform.h"
#include "lrodefs.h"
#include "c_stdlib.h"
#include "c_string.h"
#include "user_interface.h"
......@@ -125,14 +125,16 @@ static int ICACHE_FLASH_ATTR ws2812_writegrb(lua_State* L) {
return 0;
}
const LUA_REG_TYPE ws2812_map[] =
static const LUA_REG_TYPE ws2812_map[] =
{
{ LSTRKEY( "writergb" ), LFUNCVAL( ws2812_writergb )},
{ LSTRKEY( "write" ), LFUNCVAL( ws2812_writegrb )},
{ LNILKEY, LNILVAL}
};
LUALIB_API int luaopen_ws2812(lua_State *L) {
int luaopen_ws2812(lua_State *L) {
// TODO: Make sure that the GPIO system is initialized
return 0;
}
NODEMCU_MODULE(WS2812, "ws2812", ws2812_map, luaopen_ws2812);
......@@ -79,6 +79,16 @@ SECTIONS
*(.rodata*)
*(.sdk.version)
/* Link-time arrays containing the defs for the included modules */
. = ALIGN(4);
lua_libs = ABSOLUTE(.);
/* Allow either empty define or defined-to-1 to include the module */
KEEP(*(.lua_libs .lua_libs1))
LONG(0) LONG(0) /* Null-terminate the array */
lua_rotable = ABSOLUTE(.);
KEEP(*(.lua_rotable .lua_rotable1))
LONG(0) LONG(0) /* Null-terminate the array */
/* These are *only* pulled in by Lua, and therefore safe to put in flash */
*/libc.a:lib_a-isalnum.o(.text* .literal*)
*/libc.a:lib_a-isalpha.o(.text* .literal*)
......
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