Skip to content

Commit

Permalink
Updates to app/modules and supporting directories to realign APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
TerryE committed Sep 13, 2019
1 parent 1056ad8 commit 2a50243
Show file tree
Hide file tree
Showing 90 changed files with 619 additions and 666 deletions.
10 changes: 4 additions & 6 deletions app/driver/input.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
#include <stdint.h>
#include "mem.h"

/**DEBUG**/extern void dbg_printf(const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));

static void input_handler(platform_task_param_t flag, uint8 priority);

static struct input_state {
Expand Down Expand Up @@ -63,7 +61,7 @@ static bool uart_getc(char *c){
** The ins.data check detects up the first task call which used to initialise
** everything.
*/
int lua_main (void);
extern int lua_main (void);
static bool input_readline(void);

static void input_handler(platform_task_param_t flag, uint8 priority) {
Expand All @@ -79,7 +77,7 @@ static void input_handler(platform_task_param_t flag, uint8 priority) {
/*
** The input state (ins) is private, so input_setup() exposes the necessary
** access to public properties and is called in user_init() before the Lua
** enviroment is initialised. The second routine input_setup_receive() is
** enviroment is initialised. The second routine input_setup_receive() is
** called in lua.c after the Lua environment is available to bind the Lua
** input handler. Any UART input before this receive setup is ignored.
*/
Expand Down Expand Up @@ -112,15 +110,15 @@ void input_setprompt (const char *prompt) {
}

/*
** input_readline() is called from the input_handler() event routine which is
** input_readline() is called from the input_handler() event routine which is
** posted by the UART Rx ISR posts. This works in one of two modes depending on
** the bool ins.run_input.
** - TRUE: it clears the UART FIFO up to EOL, doing any callback and sending
** the line to Lua.
** - FALSE: it clears the UART FIFO doing callbacks according to the data_len /
** end_char break.
*/
void lua_input_string (const char *line, int len);
extern void lua_input_string (const char *line, int len);

static bool input_readline(void) {
char ch = NUL;
Expand Down
4 changes: 2 additions & 2 deletions app/driver/pwm2.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Software PWM using soft-interrupt timer1.
* Software PWM using soft-interrupt timer1.
* Supports higher frequencies compared to Espressif provided one.
*
* Nikolay Fiykov
Expand Down Expand Up @@ -204,7 +204,7 @@ void pwm2_setup_pin(
const uint32_t freqDivisor,
const uint32_t resolution,
const uint32_t initDuty
)
)
{
moduleData->setupData.pin[pin].pulseResolutions = resolution;
moduleData->setupData.pin[pin].divisableFrequency = divisableFreq;
Expand Down
20 changes: 14 additions & 6 deletions app/driver/uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,16 +188,24 @@ uart0_tx_buffer(uint8 *buf, uint16 len)
* FunctionName : uart0_sendStr
* Description : use uart0 to transfer buffer
* Parameters : uint8 *buf - point to send buffer
* uint16 len - buffer len
* Returns :
*******************************************************************************/
void ICACHE_FLASH_ATTR uart0_sendStr(const char *str)
{
void ICACHE_FLASH_ATTR uart0_sendStr(const char *str) {
while(*str)
{
// uart_tx_one_char(UART0, *str++);
uart0_putc(*str++);
}
}

/******************************************************************************
* FunctionName : uart0_sendStr
* Description : use uart0 to transfer buffer
* Parameters : uint8 *buf - point to send buffer
* size_t len - buffer len
* Returns :
*******************************************************************************/
void ICACHE_FLASH_ATTR uart0_sendStrn(const char *str, size_t len) {
size_t i;
for(i = 0; i < len; i++)
uart0_putc(*str++);
}

/******************************************************************************
Expand Down
2 changes: 1 addition & 1 deletion app/include/driver/pwm2.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Software PWM using soft-interrupt timer1.
* Software PWM using soft-interrupt timer1.
* Supports higher frequencies compared to Espressif provided one.
*
* Nikolay Fiykov
Expand Down
1 change: 1 addition & 0 deletions app/include/driver/uart.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ void uart_init_task(os_signal_t sig_input, uint8 *flag_input);
UartConfig uart_get_config(uint8 uart_no);
void uart0_alt(uint8 on);
void uart0_sendStr(const char *str);
void uart0_sendStrn(const char *str, size_t len);
void uart0_putc(const char c);
void uart0_tx_buffer(uint8 *buf, uint16 len);
void uart_setup(uint8 uart_no);
Expand Down
25 changes: 4 additions & 21 deletions app/include/module.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define __MODULE_H__

#include "user_modules.h"
#include "lrotable.h"
#include "lnodemcu.h"

/* Registering a module within NodeMCU is really easy these days!
*
Expand Down Expand Up @@ -38,23 +38,6 @@
#define MODULE_PASTE_(x,y) x##y
#define MODULE_EXPAND_PASTE_(x,y) MODULE_PASTE_(x,y)

#ifdef LUA_CROSS_COMPILER
#ifdef _MSC_VER
//on msvc it is necessary to go through more pre-processor hoops to get the
//section name built; string merging does not happen in the _declspecs.
//NOTE: linker magic is invoked via the magical '$' character. Caveat editor.
#define __TOKIFY(s) .rodata1$##s
#define __TOTOK(s) __TOKIFY(s)
#define __STRINGIFY(x) #x
#define __TOSTRING(x) __STRINGIFY(x)
#define __ROSECNAME(s) __TOSTRING(__TOTOK(s))
#define LOCK_IN_SECTION(s) __declspec ( allocate( __ROSECNAME(s) ) )
#else
#define LOCK_IN_SECTION(s) __attribute__((used,unused,section(".rodata1." #s)))
#endif
#else
#define LOCK_IN_SECTION(s) __attribute__((used,unused,section(".lua_" #s)))
#endif
/* For the ROM table, we name the variable according to ( | denotes concat):
* cfgname | _module_selected | LUA_USE_MODULES_##cfgname
* where the LUA_USE_MODULES_XYZ macro is first expanded to yield either
Expand All @@ -67,8 +50,8 @@
*/
#define NODEMCU_MODULE(cfgname, luaname, map, initfunc) \
const LOCK_IN_SECTION(libs) \
luaR_entry MODULE_PASTE_(lua_lib_,cfgname) = { luaname, LRO_FUNCVAL(initfunc) }; \
ROTable_entry MODULE_PASTE_(lua_lib_,cfgname) = { luaname, LRO_FUNCVAL(initfunc) }; \
const LOCK_IN_SECTION(rotable) \
luaR_entry MODULE_EXPAND_PASTE_(cfgname,MODULE_EXPAND_PASTE_(_module_selected,MODULE_PASTE_(LUA_USE_MODULES_,cfgname))) \
= {luaname, LRO_ROVAL(map ## _map)}
ROTable_entry MODULE_EXPAND_PASTE_(cfgname,MODULE_EXPAND_PASTE_(_module_selected,MODULE_PASTE_(LUA_USE_MODULES_,cfgname))) \
= {luaname, LRO_ROVAL(map)}
#endif
10 changes: 5 additions & 5 deletions app/include/task/task.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#ifndef _TASK_H_
#define _TASK_H_
/*
** The task interface is now part of the core platform interface.
** The task interface is now part of the core platform interface.
** This header is preserved for backwards compatability only.
*/
*/
#include "platform.h"

#define TASK_PRIORITY_LOW PLATFORM_TASK_PRIORITY_LOW
#define TASK_PRIORITY_MEDIUM PLATFORM_TASK_PRIORITY_MEDIUM
#define TASK_PRIORITY_HIGH PLATFORM_TASK_PRIORITY_HIGH
#define TASK_PRIORITY_LOW PLATFORM_TASK_PRIORITY_LOW
#define TASK_PRIORITY_MEDIUM PLATFORM_TASK_PRIORITY_MEDIUM
#define TASK_PRIORITY_HIGH PLATFORM_TASK_PRIORITY_HIGH

#define task_post(priority,handle,param) platform_post(priority,handle,param)
#define task_post_low(handle,param) platform_post_low(handle,param)
Expand Down
10 changes: 6 additions & 4 deletions app/include/user_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,12 +235,14 @@
#define LUA_USE_BUILTIN_DEBUG_MINIMAL // for debug.getregistry() and debug.traceback()

#ifdef DEVELOPMENT_TOOLS
#if defined(LUA_CROSS_COMPILER) || !defined(DEVELOPMENT_USE_GDB)
extern void luaL_assertfail(const char *file, int line, const char *message);
#define lua_assert(x) ((x) ? (void) 0 : luaL_assertfail(__FILE__, __LINE__, #x))
#else
#ifdef DEVELOPMENT_USE_GDB
extern void luaL_dbgbreak(void);
#define lua_assert(x) ((x) ? (void) 0 : luaL_dbgbreak())
#else
#ifdef LUA_CROSS_COMPILER
extern void luaL_assertfail(const char *file, int line, const char *message);
#define lua_assert(x) ((x) ? (void) 0 : luaL_assertfail(__FILE__, __LINE__, #x))
#endif
#endif
#endif

Expand Down
5 changes: 2 additions & 3 deletions app/lua/lflash.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,8 @@ void dumpStrt(stringtable *tb, const char *type) {
for (i=0; i<tb->size; i++)
for(o = tb->hash[i], j=0; o; (o=o->gch.next), j++ ) {
TString *ts =cast(TString *, o);
NODE_DBG("%5d %5d %08x %08x %5d %1s %s\n",
i, j, (size_t) ts, ts->tsv.hash, ts->tsv.len,
ts_isreadonly(ts) ? "R" : " ", getstr(ts));
NODE_DBG("%5d %5d %08x %08x %5d %s\n",
i, j, (size_t) ts, ts->tsv.hash, ts->tsv.len, getstr(ts));
}
}

Expand Down
67 changes: 67 additions & 0 deletions app/lua/lnodemcu.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/* Read-only tables for Lua */

#ifndef lnodemcu_h
#define lnodemcu_h

#include "lua.h"
#include "lobject.h"
#include "llimits.h"
#include "ltm.h"

#ifdef LUA_USE_HOST
#define LRO_STRKEY(k) k
#define LOCK_IN_SECTION(s)
#else
#define LRO_STRKEY(k) ((STORE_ATTR char *) k)
#define LOCK_IN_SECTION(s) __attribute__((used,unused,section(".lua_" #s)))
#endif

/* Macros one can use to define rotable entries */
#define LRO_FUNCVAL(v) {{.p = v}, LUA_TLIGHTFUNCTION}
#define LRO_LUDATA(v) {{.p = cast(void*,v)}, LUA_TLIGHTUSERDATA}
#define LRO_NILVAL {{.p = NULL}, LUA_TNIL}
#define LRO_NUMVAL(v) {{.n = v}, LUA_TNUMBER}
#define LRO_INTVAL(v) LRO_NUMVAL(v)
#define LRO_FLOATVAL(v) LRO_NUMVAL(v)
#define LRO_ROVAL(v) {{.gc = cast(GCObject *, &(v ## _ROTable))}, LUA_TROTABLE}

#define LROT_MARKED 0 //<<<<<<<<<<*** TBD *** >>>>>>>>>>>

#define LROT_FUNCENTRY(n,f) {LRO_STRKEY(#n), LRO_FUNCVAL(f)},
#define LROT_LUDENTRY(n,x) {LRO_STRKEY(#n), LRO_LUDATA(x)},
#define LROT_NUMENTRY(n,x) {LRO_STRKEY(#n), LRO_NUMVAL(x)},
#define LROT_INTENTRY(n,x) LROT_NUMENTRY(n,x)
#define LROT_FLOATENTRY(n,x) LROT_NUMENTRY(n,x)
#define LROT_TABENTRY(n,t) {LRO_STRKEY(#n), LRO_ROVAL(t)},

#define LROT_TABLE(rt) const ROTable rt ## _ROTable
#define LROT_ENTRYREF(rt) (rt ##_entries)
#define LROT_TABLEREF(rt) (&rt ##_ROTable)
#define LROT_BEGIN(rt,mt,f) LROT_TABLE(rt); \
static const ROTable_entry rt ## _entries[] = {
#define LROT_ENTRIES_IN_SECTION(rt,s) \
static const ROTable_entry LOCK_IN_SECTION(s) rt ## _entries[] = {
#define LROT_END(rt,mt,f) {NULL, LRO_NILVAL} }; \
const ROTable rt ## _ROTable = { \
(GCObject *)1, LUA_TROTABLE, LROT_MARKED, \
cast(lu_byte, ~(f)), (sizeof(rt ## _entries)/sizeof(ROTable_entry)) - 1, \
cast(Table *, mt), cast(ROTable_entry *, rt ## _entries) };
#define LROT_BREAK(rt) };

#define LROT_MASK(m) cast(lu_byte, 1<<TM_ ## m)

/*
* These are statically coded can be any combination of the fast index tags
* listed in ltm.h: EQ, GC, INDEX, LEN, MODE, NEWINDEX or combined by anding
* GC+INDEX is the only common combination used, hence the combinaton macro
*/
#define LROT_MASK_EQ LROT_MASK(EQ)
#define LROT_MASK_GC LROT_MASK(GC)
#define LROT_MASK_INDEX LROT_MASK(INDEX)
#define LROT_MASK_LEN LROT_MASK(LEN)
#define LROT_MASK_MODE LROT_MASK(MODE)
#define LROT_MASK_NEWINDEX LROT_MASK(NEWINDEX)
#define LROT_MASK_GC_INDEX (LROT_MASK_GC | LROT_MASK_INDEX)

/* Maximum length of a rotable name and of a string key*/
#endif
4 changes: 2 additions & 2 deletions app/modules/adc.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ static int adc_init107( lua_State *L )
}

// Module function map
LROT_BEGIN(adc)
LROT_BEGIN(adc, NULL, 0)
LROT_FUNCENTRY( read, adc_sample )
LROT_FUNCENTRY( readvdd33, adc_readvdd33 )
LROT_FUNCENTRY( force_init_mode, adc_init107 )
LROT_NUMENTRY( INIT_ADC, 0x00 )
LROT_NUMENTRY( INIT_VDD33, 0xff )
LROT_END( adc, NULL, 0 )
LROT_END(adc, NULL, 0)


NODEMCU_MODULE(ADC, "adc", adc, NULL);
16 changes: 8 additions & 8 deletions app/modules/ads1115.c
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ static int ads1115_lua_startread(lua_State *L) {
return 0;
}

luaL_argcheck(L, (lua_type(L, 2) == LUA_TFUNCTION || lua_type(L, 2) == LUA_TLIGHTFUNCTION), 2, "Must be function");
luaL_argcheck(L, lua_isfunction(L, 2), 2, "Must be function");
lua_pushvalue(L, 2);
ads_ctrl->timer_ref = luaL_ref(L, LUA_REGISTRYINDEX);

Expand Down Expand Up @@ -531,7 +531,7 @@ static int ads1115_lua_delete(lua_State *L) {
return 0;
}

LROT_BEGIN(ads1115)
LROT_BEGIN(ads1115, NULL, 0)
LROT_FUNCENTRY( ads1115, ads1115_lua_register_1115 )
LROT_FUNCENTRY( ads1015, ads1115_lua_register_1015 )
LROT_FUNCENTRY( reset, ads1115_lua_reset )
Expand Down Expand Up @@ -576,19 +576,19 @@ LROT_BEGIN(ads1115)
LROT_NUMENTRY( COMP_4CONV, ADS1115_CQUE_4CONV )
LROT_NUMENTRY( CMODE_TRAD, ADS1115_CMODE_TRAD )
LROT_NUMENTRY( CMODE_WINDOW, ADS1115_CMODE_WINDOW )
LROT_END(ads1115, NULL, 0 )
LROT_END(ads1115, NULL, 0)

LROT_BEGIN(ads1115_instance)

LROT_BEGIN(ads1115_instance, NULL, LROT_MASK_GC_INDEX)
LROT_TABENTRY( __index , ads1115_instance )
LROT_FUNCENTRY( __gc, ads1115_lua_delete )
LROT_FUNCENTRY( setting, ads1115_lua_setting )
LROT_FUNCENTRY( startread, ads1115_lua_startread )
LROT_FUNCENTRY( read, ads1115_lua_read )
#ifdef ADS1115_INCLUDE_TEST_FUNCTION
LROT_FUNCENTRY( test_volt_conversion, test_volt_conversion )
#endif
LROT_TABENTRY( __index, ads1115_instance )
LROT_FUNCENTRY( __gc, ads1115_lua_delete )
LROT_END(ads1115_instance, ads1115_instance, LROT_MASK_GC_INDEX )

LROT_END(ads1115_instance, NULL, LROT_MASK_GC_INDEX)

int luaopen_ads1115(lua_State *L) {
luaL_rometatable(L, metatable_name, LROT_TABLEREF(ads1115_instance));
Expand Down
4 changes: 2 additions & 2 deletions app/modules/adxl345.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ static int adxl345_read(lua_State* L) {
return 3;
}

LROT_BEGIN(adxl345)
LROT_BEGIN(adxl345, NULL, 0)
LROT_FUNCENTRY( read, adxl345_read )
LROT_FUNCENTRY( setup, adxl345_setup )
LROT_END( adxl345, NULL, 0 )
LROT_END(adxl345, NULL, 0)


NODEMCU_MODULE(ADXL345, "adxl345", adxl345, NULL);
4 changes: 2 additions & 2 deletions app/modules/am2320.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,10 @@ static int am2320_read(lua_State* L)
return 2;
}

LROT_BEGIN(am2320)
LROT_BEGIN(am2320, NULL, 0)
LROT_FUNCENTRY( read, am2320_read )
LROT_FUNCENTRY( setup, am2320_setup )
LROT_END( am2320, NULL, 0 )
LROT_END(am2320, NULL, 0)


NODEMCU_MODULE(AM2320, "am2320", am2320, NULL);
13 changes: 3 additions & 10 deletions app/modules/apa102.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#include <stdlib.h>
#include <string.h>
#include "lualib.h"
#include "lauxlib.h"
#include "lrotable.h"
#include "module.h"
#include "platform.h"
#include "user_interface.h"
Expand Down Expand Up @@ -101,14 +99,9 @@ static int apa102_write(lua_State* L) {
}


LROT_PUBLIC_BEGIN(apa102)
LROT_BEGIN(apa102, NULL, 0)
LROT_FUNCENTRY( write, apa102_write )
LROT_END( apa102, NULL, 0 )
LROT_END(apa102, NULL, 0)


LUALIB_API int luaopen_apa102(lua_State *L) {
LREGISTER(L, "apa102", apa102_map);
return 0;
}

NODEMCU_MODULE(APA102, "apa102", apa102, luaopen_apa102);
NODEMCU_MODULE(APA102, "apa102", apa102, NULL);
Loading

0 comments on commit 2a50243

Please sign in to comment.