From b773290b8cae175e1d25e1de8319fa78e4a586de Mon Sep 17 00:00:00 2001 From: TerryE Date: Sun, 13 Dec 2015 02:29:37 +0000 Subject: [PATCH] Major cleanup of module registration pass 2. carrying on Johny's edits as per my comments on #810 --- app/modules/adc.c | 13 +-- app/modules/auxmods.h | 23 ----- app/modules/bit.c | 4 + app/modules/bmp085.c | 16 ++-- app/modules/cjson.c | 61 +++++++------- app/modules/coap.c | 53 ++++++------ app/modules/crypto.c | 20 +++-- app/modules/dht.c | 22 ++--- app/modules/enduser_setup.c | 7 +- app/modules/file.c | 39 ++++----- app/modules/gpio.c | 30 +++---- app/modules/hx711.c | 9 +- app/modules/i2c.c | 29 +++---- app/modules/mqtt.c | 29 +++---- app/modules/net.c | 85 +++++++++---------- app/modules/ow.c | 40 ++++----- app/modules/pwm.c | 23 ++--- app/modules/rc.c | 8 +- app/modules/rtcfifo.c | 7 +- app/modules/rtcmem.c | 10 ++- app/modules/rtctime.c | 16 ++-- app/modules/sntp.c | 10 ++- app/modules/spi.c | 29 +++---- app/modules/tmr.c | 36 ++++---- app/modules/tsl2561.c | 45 +++++----- app/modules/u8g.c | 162 ++++++++++++++++++------------------ app/modules/uart.c | 17 ++-- app/modules/wifi.c | 139 +++++++++++++++---------------- app/platform/platform.h | 16 ++++ 29 files changed, 515 insertions(+), 483 deletions(-) delete mode 100644 app/modules/auxmods.h diff --git a/app/modules/adc.c b/app/modules/adc.c index a0d24870..aedd16e1 100644 --- a/app/modules/adc.c +++ b/app/modules/adc.c @@ -2,7 +2,6 @@ #include "lauxlib.h" #include "platform.h" -#include "auxmods.h" #include "lrodefs.h" #include "c_types.h" @@ -26,14 +25,16 @@ static int adc_readvdd33( lua_State* L ) } // Module function map -const LUA_REG_TYPE adc_map[] = -{ - { LSTRKEY( "read" ), LFUNCVAL( adc_sample ) }, +const LUA_REG_TYPE adc_map[] = { + { LSTRKEY( "read" ), LFUNCVAL( adc_sample ) }, { LSTRKEY( "readvdd33" ), LFUNCVAL( adc_readvdd33) }, { LNILKEY, LNILVAL } }; -LUALIB_API int luaopen_adc( lua_State *L ) -{ +LUALIB_API int luaopen_adc( 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 } diff --git a/app/modules/auxmods.h b/app/modules/auxmods.h deleted file mode 100644 index 12a67f41..00000000 --- a/app/modules/auxmods.h +++ /dev/null @@ -1,23 +0,0 @@ -// Auxiliary Lua modules. All of them are declared here, then each platform -// decides what module(s) to register in the src/platform/xxxxx/platform_conf.h file -// FIXME: no longer platform_conf.h - either CPU header file, or board file - -#ifndef __AUXMODS_H__ -#define __AUXMODS_H__ - -// Helper macros -#define MOD_CHECK_ID( mod, id )\ - if( !platform_ ## mod ## _exists( id ) )\ - return luaL_error( L, #mod" %d does not exist", ( unsigned )id ) - -#define MOD_CHECK_TIMER( id )\ - if( id == PLATFORM_TIMER_SYS_ID && !platform_timer_sys_available() )\ - return luaL_error( L, "the system timer is not available on this platform" );\ - if( !platform_timer_exists( id ) )\ - return luaL_error( L, "timer %d does not exist", ( unsigned )id )\ - -#define MOD_CHECK_RES_ID( mod, id, resmod, resid )\ - if( !platform_ ## mod ## _check_ ## resmod ## _id( id, resid ) )\ - return luaL_error( L, #resmod" %d not valid with " #mod " %d", ( unsigned )resid, ( unsigned )id ) - -#endif diff --git a/app/modules/bit.c b/app/modules/bit.c index 31ae96d3..d6914457 100644 --- a/app/modules/bit.c +++ b/app/modules/bit.c @@ -136,5 +136,9 @@ const LUA_REG_TYPE bit_map[] = { }; LUALIB_API int luaopen_bit (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 } diff --git a/app/modules/bmp085.c b/app/modules/bmp085.c index d75379e8..57a73bc1 100644 --- a/app/modules/bmp085.c +++ b/app/modules/bmp085.c @@ -183,16 +183,18 @@ static int ICACHE_FLASH_ATTR bmp085_lua_pressure(lua_State* L) { return 1; } -const LUA_REG_TYPE bmp085_map[] = -{ - { LSTRKEY( "temperature" ), LFUNCVAL( bmp085_lua_temperature )}, - { LSTRKEY( "pressure" ), LFUNCVAL( bmp085_lua_pressure )}, +const LUA_REG_TYPE bmp085_map[] = { + { LSTRKEY( "temperature" ), LFUNCVAL( bmp085_lua_temperature )}, + { LSTRKEY( "pressure" ), LFUNCVAL( bmp085_lua_pressure )}, { LSTRKEY( "pressure_raw" ), LFUNCVAL( bmp085_lua_pressure_raw )}, - { LSTRKEY( "init" ), LFUNCVAL( bmp085_init )}, + { LSTRKEY( "init" ), LFUNCVAL( bmp085_init )}, { LNILKEY, LNILVAL} }; LUALIB_API int luaopen_bmp085(lua_State *L) { - return 0; +#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 } - diff --git a/app/modules/cjson.c b/app/modules/cjson.c index 73a49dbf..23947a5d 100644 --- a/app/modules/cjson.c +++ b/app/modules/cjson.c @@ -1528,37 +1528,7 @@ static int json_protect_conversion(lua_State *l) * errors are memory related */ return luaL_error(l, "Memory allocation error in CJSON protected call"); } -#endif -// Module function map -const LUA_REG_TYPE cjson_map[] = -{ - { LSTRKEY( "encode" ), LFUNCVAL( json_encode ) }, - { LSTRKEY( "decode" ), LFUNCVAL( json_decode ) }, - // { LSTRKEY( "encode_sparse_array" ), LFUNCVAL( json_cfg_encode_sparse_array ) }, - // { LSTRKEY( "encode_max_depth" ), LFUNCVAL( json_cfg_encode_max_depth ) }, - // { LSTRKEY( "decode_max_depth" ), LFUNCVAL( json_cfg_decode_max_depth ) }, - // { LSTRKEY( "encode_number_precision" ), LFUNCVAL( json_cfg_encode_number_precision ) }, - // { LSTRKEY( "encode_keep_buffer" ), LFUNCVAL( json_cfg_encode_keep_buffer ) }, - // { LSTRKEY( "encode_invalid_numbers" ), LFUNCVAL( json_cfg_encode_invalid_numbers ) }, - // { LSTRKEY( "decode_invalid_numbers" ), LFUNCVAL( json_cfg_decode_invalid_numbers ) }, - // { LSTRKEY( "new" ), LFUNCVAL( lua_cjson_new ) }, - { LNILKEY, LNILVAL } -}; - -LUALIB_API int luaopen_cjson( lua_State *L ) -{ - cjson_mem_setlua (L); - - /* Initialise number conversions */ - // fpconv_init(); // not needed for a specific cpu. - if(-1==cfg_init(&_cfg)){ - return luaL_error(L, "BUG: Unable to init config for cjson");; - } - return 0; -} - -#if 0 /* Return cjson module table */ static int lua_cjson_new(lua_State *l) { @@ -1628,5 +1598,36 @@ int luaopen_cjson_safe(lua_State *l) return 1; } #endif + +// Module function map +const LUA_REG_TYPE cjson_map[] = { + { LSTRKEY( "encode" ), LFUNCVAL( json_encode ) }, + { LSTRKEY( "decode" ), LFUNCVAL( json_decode ) }, +//{ LSTRKEY( "encode_sparse_array" ), LFUNCVAL( json_cfg_encode_sparse_array ) }, +//{ LSTRKEY( "encode_max_depth" ), LFUNCVAL( json_cfg_encode_max_depth ) }, +//{ LSTRKEY( "decode_max_depth" ), LFUNCVAL( json_cfg_decode_max_depth ) }, +//{ LSTRKEY( "encode_number_precision" ), LFUNCVAL( json_cfg_encode_number_precision ) }, +//{ LSTRKEY( "encode_keep_buffer" ), LFUNCVAL( json_cfg_encode_keep_buffer ) }, +//{ LSTRKEY( "encode_invalid_numbers" ), LFUNCVAL( json_cfg_encode_invalid_numbers ) }, +//{ LSTRKEY( "decode_invalid_numbers" ), LFUNCVAL( json_cfg_decode_invalid_numbers ) }, +//{ LSTRKEY( "new" ), LFUNCVAL( lua_cjson_new ) }, + { LNILKEY, LNILVAL } +}; + +LUALIB_API int luaopen_cjson( lua_State *L ) +{ + cjson_mem_setlua (L); + + /* Initialise number conversions */ + // fpconv_init(); // not needed for a specific cpu. + if(-1==cfg_init(&_cfg)){ + return luaL_error(L, "BUG: Unable to init config for cjson");; + } +#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 +} /* vi:ai et sw=4 ts=4: */ diff --git a/app/modules/coap.c b/app/modules/coap.c index 6da5cb4f..94d2b670 100644 --- a/app/modules/coap.c +++ b/app/modules/coap.c @@ -558,41 +558,38 @@ static int coap_client_delete( lua_State* L ) } // Module function map -static const LUA_REG_TYPE coap_server_map[] = -{ - { LSTRKEY( "listen" ), LFUNCVAL ( coap_server_listen ) }, - { LSTRKEY( "close" ), LFUNCVAL ( coap_server_close ) }, - { LSTRKEY( "var" ), LFUNCVAL ( coap_server_var ) }, - { LSTRKEY( "func" ), LFUNCVAL ( coap_server_func ) }, - { LSTRKEY( "__gc" ), LFUNCVAL ( coap_server_delete ) }, - { LSTRKEY( "__index" ), LROVAL ( coap_server_map ) }, +static const LUA_REG_TYPE coap_server_map[] = { + { LSTRKEY( "listen" ), LFUNCVAL( coap_server_listen ) }, + { LSTRKEY( "close" ), LFUNCVAL( coap_server_close ) }, + { LSTRKEY( "var" ), LFUNCVAL( coap_server_var ) }, + { LSTRKEY( "func" ), LFUNCVAL( coap_server_func ) }, + { LSTRKEY( "__gc" ), LFUNCVAL( coap_server_delete ) }, + { LSTRKEY( "__index" ), LROVAL( coap_server_map ) }, { LNILKEY, LNILVAL } }; -static const LUA_REG_TYPE coap_client_map[] = -{ - { LSTRKEY( "get" ), LFUNCVAL ( coap_client_get ) }, - { LSTRKEY( "post" ), LFUNCVAL ( coap_client_post ) }, - { LSTRKEY( "put" ), LFUNCVAL ( coap_client_put ) }, - { LSTRKEY( "delete" ), LFUNCVAL ( coap_client_delete ) }, - { LSTRKEY( "__gc" ), LFUNCVAL ( coap_client_gcdelete ) }, - { LSTRKEY( "__index" ), LROVAL ( coap_client_map ) }, +static const LUA_REG_TYPE coap_client_map[] = { + { LSTRKEY( "get" ), LFUNCVAL( coap_client_get ) }, + { LSTRKEY( "post" ), LFUNCVAL( coap_client_post ) }, + { LSTRKEY( "put" ), LFUNCVAL( coap_client_put ) }, + { LSTRKEY( "delete" ), LFUNCVAL( coap_client_delete ) }, + { LSTRKEY( "__gc" ), LFUNCVAL( coap_client_gcdelete ) }, + { LSTRKEY( "__index" ), LROVAL( coap_client_map ) }, { LNILKEY, LNILVAL } }; const LUA_REG_TYPE coap_map[] = { - { LSTRKEY( "Server" ), LFUNCVAL ( coap_createServer ) }, - { LSTRKEY( "Client" ), LFUNCVAL ( coap_createClient ) }, - { LSTRKEY( "CON" ), LNUMVAL( COAP_TYPE_CON ) }, - { LSTRKEY( "NON" ), LNUMVAL( COAP_TYPE_NONCON ) }, - { LSTRKEY( "TEXT_PLAIN"), LNUMVAL( COAP_CONTENTTYPE_TEXT_PLAIN ) }, - { LSTRKEY( "LINKFORMAT"), LNUMVAL( COAP_CONTENTTYPE_APPLICATION_LINKFORMAT ) }, - { LSTRKEY( "XML"), LNUMVAL( COAP_CONTENTTYPE_APPLICATION_XML ) }, + { LSTRKEY( "Server" ), LFUNCVAL( coap_createServer ) }, + { LSTRKEY( "Client" ), LFUNCVAL( coap_createClient ) }, + { LSTRKEY( "CON" ), LNUMVAL( COAP_TYPE_CON ) }, + { LSTRKEY( "NON" ), LNUMVAL( COAP_TYPE_NONCON ) }, + { LSTRKEY( "TEXT_PLAIN"), LNUMVAL( COAP_CONTENTTYPE_TEXT_PLAIN ) }, + { LSTRKEY( "LINKFORMAT"), LNUMVAL( COAP_CONTENTTYPE_APPLICATION_LINKFORMAT ) }, + { LSTRKEY( "XML"), LNUMVAL( COAP_CONTENTTYPE_APPLICATION_XML ) }, { LSTRKEY( "OCTET_STREAM"), LNUMVAL( COAP_CONTENTTYPE_APPLICATION_OCTET_STREAM ) }, - { LSTRKEY( "EXI"), LNUMVAL( COAP_CONTENTTYPE_APPLICATION_EXI ) }, - { LSTRKEY( "JSON"), LNUMVAL( COAP_CONTENTTYPE_APPLICATION_JSON) }, - + { LSTRKEY( "EXI"), LNUMVAL( COAP_CONTENTTYPE_APPLICATION_EXI ) }, + { LSTRKEY( "JSON"), LNUMVAL( COAP_CONTENTTYPE_APPLICATION_JSON) }, { LSTRKEY( "__metatable" ), LROVAL( coap_map ) }, { LNILKEY, LNILVAL } }; @@ -602,5 +599,9 @@ LUALIB_API int luaopen_coap( lua_State *L ) endpoint_setup(); luaL_rometatable(L, "coap_server", (void *)coap_server_map); // create metatable for coap_server luaL_rometatable(L, "coap_client", (void *)coap_client_map); // create metatable for coap_client +#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 } diff --git a/app/modules/crypto.c b/app/modules/crypto.c index 7557dd14..e9067495 100644 --- a/app/modules/crypto.c +++ b/app/modules/crypto.c @@ -150,18 +150,20 @@ static int crypto_lhmac (lua_State *L) // Module function map -const LUA_REG_TYPE crypto_map[] = -{ - { LSTRKEY( "sha1" ), LFUNCVAL( crypto_sha1 ) }, +const LUA_REG_TYPE crypto_map[] = { + { LSTRKEY( "sha1" ), LFUNCVAL( crypto_sha1 ) }, { LSTRKEY( "toBase64" ), LFUNCVAL( crypto_base64_encode ) }, - { LSTRKEY( "toHex" ), LFUNCVAL( crypto_hex_encode ) }, - { LSTRKEY( "mask" ), LFUNCVAL( crypto_mask ) }, - { LSTRKEY( "hash" ), LFUNCVAL( crypto_lhash ) }, - { LSTRKEY( "hmac" ), LFUNCVAL( crypto_lhmac ) }, + { LSTRKEY( "toHex" ), LFUNCVAL( crypto_hex_encode ) }, + { LSTRKEY( "mask" ), LFUNCVAL( crypto_mask ) }, + { LSTRKEY( "hash" ), LFUNCVAL( crypto_lhash ) }, + { LSTRKEY( "hmac" ), LFUNCVAL( crypto_lhmac ) }, { LNILKEY, LNILVAL } }; -LUALIB_API int luaopen_crypto( lua_State *L ) -{ +LUALIB_API int luaopen_crypto( 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 } diff --git a/app/modules/dht.c b/app/modules/dht.c index 3d7067ec..c951341f 100644 --- a/app/modules/dht.c +++ b/app/modules/dht.c @@ -1,8 +1,8 @@ // Module for interfacing with the DHTxx sensors (xx = 11-21-22-33-44). #include "lauxlib.h" -#include "auxmods.h" #include "lrodefs.h" +#include "platform.h" #include "cpu_esp8266.h" #include "dht.h" @@ -99,18 +99,20 @@ static int dht_lapi_readxx( lua_State *L ) // } // Module function map -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 ) }, +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 ) }, + { LSTRKEY( "ERROR_TIMEOUT" ), LNUMVAL( DHTLIB_ERROR_TIMEOUT ) }, { LNILKEY, LNILVAL } }; -LUALIB_API int luaopen_dht( lua_State *L ) -{ +LUALIB_API int luaopen_dht( 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 } diff --git a/app/modules/enduser_setup.c b/app/modules/enduser_setup.c index d1cb83b5..a7b06a57 100644 --- a/app/modules/enduser_setup.c +++ b/app/modules/enduser_setup.c @@ -927,14 +927,17 @@ static int enduser_setup_stop(lua_State* L) } -const LUA_REG_TYPE enduser_setup_map[] = -{ +const LUA_REG_TYPE enduser_setup_map[] = { { LSTRKEY( "start" ), LFUNCVAL( enduser_setup_start )}, { LSTRKEY( "stop" ), LFUNCVAL( enduser_setup_stop )}, { LNILKEY, LNILVAL} }; LUALIB_API int luaopen_enduser_setup(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 } diff --git a/app/modules/file.c b/app/modules/file.c index e41e4841..80f8ec54 100644 --- a/app/modules/file.c +++ b/app/modules/file.c @@ -296,29 +296,30 @@ static int file_writeline( lua_State* L ) } // Module function map -const LUA_REG_TYPE file_map[] = -{ - { LSTRKEY( "list" ), LFUNCVAL( file_list ) }, - { LSTRKEY( "open" ), LFUNCVAL( file_open ) }, - { LSTRKEY( "close" ), LFUNCVAL( file_close ) }, - { LSTRKEY( "write" ), LFUNCVAL( file_write ) }, +const LUA_REG_TYPE file_map[] = { + { LSTRKEY( "list" ), LFUNCVAL( file_list ) }, + { LSTRKEY( "open" ), LFUNCVAL( file_open ) }, + { LSTRKEY( "close" ), LFUNCVAL( file_close ) }, + { LSTRKEY( "write" ), LFUNCVAL( file_write ) }, { LSTRKEY( "writeline" ), LFUNCVAL( file_writeline ) }, - { LSTRKEY( "read" ), LFUNCVAL( file_read ) }, - { LSTRKEY( "readline" ), LFUNCVAL( file_readline ) }, - { LSTRKEY( "format" ), LFUNCVAL( file_format ) }, -#if defined(BUILD_WOFS) -#elif defined(BUILD_SPIFFS) - { LSTRKEY( "remove" ), LFUNCVAL( file_remove ) }, - { LSTRKEY( "seek" ), LFUNCVAL( file_seek ) }, - { LSTRKEY( "flush" ), LFUNCVAL( file_flush ) }, - // { LSTRKEY( "check" ), LFUNCVAL( file_check ) }, - { LSTRKEY( "rename" ), LFUNCVAL( file_rename ) }, - { LSTRKEY( "fsinfo" ), LFUNCVAL( file_fsinfo ) }, + { LSTRKEY( "read" ), LFUNCVAL( file_read ) }, + { LSTRKEY( "readline" ), LFUNCVAL( file_readline ) }, + { LSTRKEY( "format" ), LFUNCVAL( file_format ) }, +#if defined(BUILD_SPIFFS) && !defined(BUILD_WOFS) + { LSTRKEY( "remove" ), LFUNCVAL( file_remove ) }, + { LSTRKEY( "seek" ), LFUNCVAL( file_seek ) }, + { LSTRKEY( "flush" ), LFUNCVAL( file_flush ) }, +//{ LSTRKEY( "check" ), LFUNCVAL( file_check ) }, + { LSTRKEY( "rename" ), LFUNCVAL( file_rename ) }, + { LSTRKEY( "fsinfo" ), LFUNCVAL( file_fsinfo ) }, #endif { LNILKEY, LNILVAL } }; -LUALIB_API int luaopen_file( lua_State *L ) -{ +LUALIB_API int luaopen_file( 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 } diff --git a/app/modules/gpio.c b/app/modules/gpio.c index 49b1507c..d19c0220 100644 --- a/app/modules/gpio.c +++ b/app/modules/gpio.c @@ -1,7 +1,6 @@ // Module for interfacing with GPIO #include "lauxlib.h" -#include "auxmods.h" #include "platform.h" #include "lrodefs.h" @@ -221,27 +220,25 @@ static int lgpio_serout( lua_State* L ) #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 ) }, +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( "trig" ), LFUNCVAL( lgpio_trig ) }, - { LSTRKEY( "INT" ), LNUMVAL( INTERRUPT ) }, + { LSTRKEY( "trig" ), LFUNCVAL( lgpio_trig ) }, + { LSTRKEY( "INT" ), LNUMVAL( INTERRUPT ) }, #endif { LSTRKEY( "OUTPUT" ), LNUMVAL( OUTPUT ) }, - { LSTRKEY( "INPUT" ), LNUMVAL( INPUT ) }, - { LSTRKEY( "HIGH" ), LNUMVAL( HIGH ) }, - { LSTRKEY( "LOW" ), LNUMVAL( LOW ) }, - { LSTRKEY( "FLOAT" ), LNUMVAL( FLOAT ) }, + { LSTRKEY( "INPUT" ), LNUMVAL( INPUT ) }, + { 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 ) -{ +LUALIB_API int luaopen_gpio( lua_State *L ) { #ifdef GPIO_INTERRUPT_ENABLE int i; for(i=0;i