Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…o dev

# Conflicts:
#	README.md
  • Loading branch information
vowstar committed Dec 29, 2015
2 parents 50dcea3 + a8359f1 commit 5b6acee
Show file tree
Hide file tree
Showing 62 changed files with 1,043 additions and 1,941 deletions.
489 changes: 270 additions & 219 deletions README.md

Large diffs are not rendered by default.

12 changes: 10 additions & 2 deletions app/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,13 @@ COMPONENTS_eagle.app.v6 = \
crypto/libcrypto.a \
dhtlib/libdhtlib.a \
tsl2561/tsl2561lib.a \
modules/libmodules.a
modules/libmodules.a \

# Inspect the modules library and work out which modules need to be linked.
# For each enabled module, a symbol name of the form XYZ_module_selected is
# returned. At link time those names are declared undefined, so those (and
# only those) modules are pulled in.
SELECTED_MODULE_SYMS=$(filter %_module_selected %module_selected1,$(shell $(NM) modules/.output/$(TARGET)/$(FLAVOR)/lib/libmodules.a))

LINKFLAGS_eagle.app.v6 = \
-Wl,--gc-sections \
Expand All @@ -98,6 +103,7 @@ LINKFLAGS_eagle.app.v6 = \
-Wl,--no-check-sections \
-Wl,--wrap=_xtos_set_exception_handler \
-Wl,-static \
$(addprefix -u , $(SELECTED_MODULE_SYMS)) \
-Wl,--start-group \
-lc \
-lgcc \
Expand Down Expand Up @@ -134,9 +140,11 @@ DEPENDS_eagle.app.v6 = \
# -DWLAN_CONFIG_CCX
CONFIGURATION_DEFINES = -D__ets__ \
-DICACHE_FLASH \
-DLUA_OPTIMIZE_MEMORY=2 \
-DMIN_OPT_LEVEL=2 \
-DLWIP_OPEN_SRC \
-DPBUF_RSV_FOR_WLAN \
-DEBUF_LWIP
-DEBUF_LWIP \

DEFINES += \
$(UNIVERSAL_TARGET_DEFINES) \
Expand Down
8 changes: 4 additions & 4 deletions app/driver/uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ uart_config(uint8 uart_no)

uart_div_modify(uart_no, UART_CLK_FREQ / (UartDev.baut_rate));

WRITE_PERI_REG(UART_CONF0(uart_no), UartDev.exist_parity
| UartDev.parity
| (UartDev.stop_bits << UART_STOP_BIT_NUM_S)
| (UartDev.data_bits << UART_BIT_NUM_S));
WRITE_PERI_REG(UART_CONF0(uart_no), ((UartDev.exist_parity & UART_PARITY_EN_M) << UART_PARITY_EN_S) //SET BIT AND PARITY MODE
| ((UartDev.parity & UART_PARITY_M) <<UART_PARITY_S )
| ((UartDev.stop_bits & UART_STOP_BIT_NUM) << UART_STOP_BIT_NUM_S)
| ((UartDev.data_bits & UART_BIT_NUM) << UART_BIT_NUM_S));


//clear rx and tx fifo,not ready
Expand Down
14 changes: 7 additions & 7 deletions app/include/driver/uart.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,20 @@ typedef enum {
} UartBitsNum4Char;

typedef enum {
ONE_STOP_BIT = 0,
ONE_HALF_STOP_BIT = BIT2,
TWO_STOP_BIT = BIT2
ONE_STOP_BIT = 0x1,
ONE_HALF_STOP_BIT = 0x2,
TWO_STOP_BIT = 0x3
} UartStopBitsNum;

typedef enum {
NONE_BITS = 0,
ODD_BITS = 0,
EVEN_BITS = BIT4
NONE_BITS = 0x2,
ODD_BITS = 1,
EVEN_BITS = 0
} UartParityMode;

typedef enum {
STICK_PARITY_DIS = 0,
STICK_PARITY_EN = BIT3 | BIT5
STICK_PARITY_EN = 1
} UartExistParity;

typedef enum {
Expand Down
50 changes: 30 additions & 20 deletions app/include/driver/uart_register.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,26 +78,36 @@
#define UART_RXFIFO_CNT 0x000000FF
#define UART_RXFIFO_CNT_S 0

#define UART_CONF0( i ) (REG_UART_BASE( i ) + 0x20)
#define UART_TXFIFO_RST (BIT(18))
#define UART_RXFIFO_RST (BIT(17))
#define UART_IRDA_EN (BIT(16))
#define UART_TX_FLOW_EN (BIT(15))
#define UART_LOOPBACK (BIT(14))
#define UART_IRDA_RX_INV (BIT(13))
#define UART_IRDA_TX_INV (BIT(12))
#define UART_IRDA_WCTL (BIT(11))
#define UART_IRDA_TX_EN (BIT(10))
#define UART_IRDA_DPLX (BIT(9))
#define UART_TXD_BRK (BIT(8))
#define UART_SW_DTR (BIT(7))
#define UART_SW_RTS (BIT(6))
#define UART_STOP_BIT_NUM 0x00000003
#define UART_STOP_BIT_NUM_S 4
#define UART_BIT_NUM 0x00000003
#define UART_BIT_NUM_S 2
#define UART_PARITY_EN (BIT(1))
#define UART_PARITY (BIT(0))
#define UART_CONF0( i ) (REG_UART_BASE( i ) + 0x20)
#define UART_DTR_INV (BIT(24))
#define UART_RTS_INV (BIT(23))
#define UART_TXD_INV (BIT(22))
#define UART_DSR_INV (BIT(21))
#define UART_CTS_INV (BIT(20))
#define UART_RXD_INV (BIT(19))
#define UART_TXFIFO_RST (BIT(18))
#define UART_RXFIFO_RST (BIT(17))
#define UART_IRDA_EN (BIT(16))
#define UART_TX_FLOW_EN (BIT(15))
#define UART_LOOPBACK (BIT(14))
#define UART_IRDA_RX_INV (BIT(13))
#define UART_IRDA_TX_INV (BIT(12))
#define UART_IRDA_WCTL (BIT(11))
#define UART_IRDA_TX_EN (BIT(10))
#define UART_IRDA_DPLX (BIT(9))
#define UART_TXD_BRK (BIT(8))
#define UART_SW_DTR (BIT(7))
#define UART_SW_RTS (BIT(6))
#define UART_STOP_BIT_NUM 0x00000003
#define UART_STOP_BIT_NUM_S 4
#define UART_BIT_NUM 0x00000003
#define UART_BIT_NUM_S 2
#define UART_PARITY_EN (BIT(1))
#define UART_PARITY_EN_M 0x00000001
#define UART_PARITY_EN_S 1
#define UART_PARITY (BIT(0))
#define UART_PARITY_M 0x00000001
#define UART_PARITY_S 0

#define UART_CONF1( i ) (REG_UART_BASE( i ) + 0x24)
#define UART_RX_TOUT_EN (BIT(31))
Expand Down
74 changes: 74 additions & 0 deletions app/include/module.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#ifndef __MODULE_H__
#define __MODULE_H__

#include "user_modules.h"
#include "lrodefs.h"

/* Registering a module within NodeMCU is really easy these days!
*
* Most of the work is done by a combination of pre-processor, compiler
* and linker "magic". Gone are the days of needing to update 4+ separate
* files just to register a module!
*
* You will need:
* - to include this header
* - a name for the module
* - a LUA_REG_TYPE module map
* - optionally, an init function
*
* Then simply put a line like this at the bottom of your module file:
*
* NODEMCU_MODULE(MYNAME, "myname", myname_map, luaopen_myname);
*
* or perhaps
*
* NODEMCU_MODULE(MYNAME, "myname", myname_map, NULL);
*
* if you don't need an init function.
*
* When you've done this, the module can be enabled in user_modules.h with:
*
* #define LUA_USE_MODULES_MYNAME
*
* and within NodeMCU you access it with myname.foo(), assuming you have
* a foo function in your module.
*/

#define MODULE_EXPAND_(x) x
#define MODULE_PASTE_(x,y) x##y
#define MODULE_EXPAND_PASTE_(x,y) MODULE_PASTE_(x,y)

#define LOCK_IN_SECTION(s) __attribute__((used,unused,section(s)))

/* 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
* an empty string (or 1) if the module has been enabled, or the literal
* LUA_USE_MOUDLE_XYZ in the case it hasn't. Thus, the name of the variable
* ends up looking either like XYZ_module_enabled, or if not enabled,
* XYZ_module_enabledLUA_USE_MODULES_XYZ. This forms the basis for
* letting the build system detect automatically (via nm) which modules need
* to be linked in.
*/
#define NODEMCU_MODULE(cfgname, luaname, map, initfunc) \
const LOCK_IN_SECTION(".lua_libs") \
luaL_Reg MODULE_PASTE_(lua_lib_,cfgname) = { luaname, initfunc }; \
const LOCK_IN_SECTION(".lua_rotable") \
luaR_table MODULE_EXPAND_PASTE_(cfgname,MODULE_EXPAND_PASTE_(_module_selected,MODULE_PASTE_(LUA_USE_MODULES_,cfgname))) \
= { luaname, map }


/* System module registration support, not using LUA_USE_MODULES_XYZ. */
#define BUILTIN_LIB_INIT(name, luaname, initfunc) \
const LOCK_IN_SECTION(".lua_libs") \
luaL_Reg MODULE_PASTE_(lua_lib_,name) = { luaname, initfunc }

#define BUILTIN_LIB(name, luaname, map) \
const LOCK_IN_SECTION(".lua_rotable") \
luaR_table MODULE_PASTE_(lua_rotable_,name) = { luaname, map }

#if !(MIN_OPT_LEVEL==2 && LUA_OPTIMIZE_MEMORY==2)
# error "NodeMCU modules must be built with LTR enabled (MIN_OPT_LEVEL=2 and LUA_OPTIMIZE_MEMORY=2)"
#endif

#endif
5 changes: 1 addition & 4 deletions app/include/user_modules.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
#define LUA_USE_BUILTIN_DEBUG_MINIMAL // for debug.getregistry() and debug.traceback()

#ifndef LUA_CROSS_COMPILER
#define LUA_USE_MODULES

#ifdef LUA_USE_MODULES
#define LUA_USE_MODULES_ADC
#define LUA_USE_MODULES_BIT
//#define LUA_USE_MODULES_BMP085
Expand Down Expand Up @@ -47,7 +45,6 @@
//#define LUA_USE_MODULES_WS2801
#define LUA_USE_MODULES_WS2812

#endif /* LUA_USE_MODULES */
#endif

#endif /* LUA_CROSS_COMPILER */
#endif /* __USER_MODULES_H__ */
1 change: 1 addition & 0 deletions app/lua/lauxlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,7 @@ static int panic (lua_State *L) {
luai_writestringerror("PANIC: unprotected error in call to Lua API (%s)\n",
lua_tostring(L, -1));
#endif
while (1) {}
return 0;
}

Expand Down
1 change: 1 addition & 0 deletions app/lua/lbaselib.c
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,7 @@ static int luaB_newproxy (lua_State *L) {
{LSTRKEY("xpcall"), LFUNCVAL(luaB_xpcall)}

#if LUA_OPTIMIZE_MEMORY == 2
#undef MIN_OPT_LEVEL
#define MIN_OPT_LEVEL 2
#include "lrodefs.h"
const LUA_REG_TYPE base_funcs_list[] = {
Expand Down
1 change: 1 addition & 0 deletions app/lua/ldblib.c
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ static int db_errorfb (lua_State *L) {
return 1;
}

#undef MIN_OPT_LEVEL
#define MIN_OPT_LEVEL 1
#include "lrodefs.h"
const LUA_REG_TYPE dblib[] = {
Expand Down
1 change: 1 addition & 0 deletions app/lua/liolib.c
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,7 @@ static int f_flush (lua_State *L) {
return pushresult(L, fs_flush(tofile(L)) == 0, NULL);
}

#undef MIN_OPT_LEVEL
#define MIN_OPT_LEVEL 2
#include "lrodefs.h"
#if LUA_OPTIMIZE_MEMORY == 2
Expand Down
1 change: 1 addition & 0 deletions app/lua/lmathlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ static int math_randomseed (lua_State *L) {



#undef MIN_OPT_LEVEL
#define MIN_OPT_LEVEL 1
#include "lrodefs.h"
const LUA_REG_TYPE math_map[] = {
Expand Down
1 change: 1 addition & 0 deletions app/lua/loadlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,7 @@ static const lua_CFunction loaders[] =
{loader_preload, loader_Lua, loader_C, loader_Croot, NULL};

#if LUA_OPTIMIZE_MEMORY > 0
#undef MIN_OPT_LEVEL
#define MIN_OPT_LEVEL 1
#include "lrodefs.h"
const LUA_REG_TYPE lmt[] = {
Expand Down
4 changes: 3 additions & 1 deletion app/lua/lobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,11 @@ int luaO_rawequalObj (const TValue *t1, const TValue *t2) {
case LUA_TBOOLEAN:
return bvalue(t1) == bvalue(t2); /* boolean true must be 1 !! */
case LUA_TLIGHTUSERDATA:
return pvalue(t1) == pvalue(t2);
case LUA_TROTABLE:
return rvalue(t1) == rvalue(t2);
case LUA_TLIGHTFUNCTION:
return pvalue(t1) == pvalue(t2);
return fvalue(t1) == fvalue(t2);
default:
lua_assert(iscollectable(t1));
return gcvalue(t1) == gcvalue(t2);
Expand Down
2 changes: 1 addition & 1 deletion app/lua/lrodefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#undef LREGISTER

#if (MIN_OPT_LEVEL > 0) && (LUA_OPTIMIZE_MEMORY >= MIN_OPT_LEVEL)
#define LUA_REG_TYPE luaR_entry ICACHE_RODATA_ATTR
#define LUA_REG_TYPE luaR_entry
#define LSTRKEY LRO_STRKEY
#define LNUMKEY LRO_NUMKEY
#define LNILKEY LRO_NILKEY
Expand Down
1 change: 1 addition & 0 deletions app/lua/lstrlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,7 @@ static int str_format (lua_State *L) {
return 1;
}

#undef MIN_OPT_LEVEL
#define MIN_OPT_LEVEL 1
#include "lrodefs.h"
const LUA_REG_TYPE strlib[] = {
Expand Down
1 change: 1 addition & 0 deletions app/lua/ltablib.c
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ static int sort (lua_State *L) {
/* }====================================================== */


#undef MIN_OPT_LEVEL
#define MIN_OPT_LEVEL 1
#include "lrodefs.h"
const LUA_REG_TYPE tab_funcs[] = {
Expand Down
1 change: 1 addition & 0 deletions app/lua/luac_cross/loslib.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ static int os_exit (lua_State *L) {
c_exit(luaL_optint(L, 1, EXIT_SUCCESS));
}

#undef MIN_OPT_LEVEL
#define MIN_OPT_LEVEL 1
#include "lrodefs.h"
const LUA_REG_TYPE syslib[] = {
Expand Down
27 changes: 4 additions & 23 deletions app/modules/adc.c
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
// Module for interfacing with adc

//#include "lua.h"
#include "lualib.h"
#include "module.h"
#include "lauxlib.h"
#include "platform.h"
#include "auxmods.h"
#include "lrotable.h"

#include "c_types.h"
#include "user_interface.h"
Expand All @@ -28,26 +25,10 @@ static int adc_readvdd33( lua_State* L )
}

// Module function map
#define MIN_OPT_LEVEL 2
#include "lrodefs.h"
const LUA_REG_TYPE adc_map[] =
{
{ LSTRKEY( "read" ), LFUNCVAL( adc_sample ) },
static const LUA_REG_TYPE adc_map[] = {
{ LSTRKEY( "read" ), LFUNCVAL( adc_sample ) },
{ LSTRKEY( "readvdd33" ), LFUNCVAL( adc_readvdd33) },
#if LUA_OPTIMIZE_MEMORY > 0

#endif
{ LNILKEY, LNILVAL }
};

LUALIB_API int luaopen_adc( lua_State *L )
{
#if LUA_OPTIMIZE_MEMORY > 0
return 0;
#else // #if LUA_OPTIMIZE_MEMORY > 0
luaL_register( L, AUXLIB_ADC, adc_map );
// Add constants

return 1;
#endif // #if LUA_OPTIMIZE_MEMORY > 0
}
NODEMCU_MODULE(ADC, "adc", adc_map, NULL);
Loading

0 comments on commit 5b6acee

Please sign in to comment.