From 7b65613498263a311685dcfe37c6b2af2233e744 Mon Sep 17 00:00:00 2001 From: Nick Andrew Date: Tue, 17 Nov 2015 00:00:12 +1100 Subject: [PATCH 01/39] Update README base to 1.4.0 Signed-off-by: Nick Andrew --- README.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index c49b870a..a40a8555 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,10 @@ -# **NodeMCU** # -version 0.9.5 +# **NodeMCU 1.4.0** # [![Join the chat at https://gitter.im/nodemcu/nodemcu-firmware](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/nodemcu/nodemcu-firmware?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![Build Status](https://travis-ci.org/nodemcu/nodemcu-firmware.svg)](https://travis-ci.org/nodemcu/nodemcu-firmware) [![Download](https://img.shields.io/badge/download-~400k-orange.svg)](https://github.com/nodemcu/nodemcu-firmware/releases/latest) ###A lua based firmware for wifi-soc esp8266 -Build on [ESP8266 sdk 0.9.5](http://bbs.espressif.com/viewtopic.php?f=5&t=154)
+Build on [ESP8266 sdk 1.4.0](http://bbs.espressif.com/viewtopic.php?f=46&t=1124)
Lua core based on [eLua project](http://www.eluaproject.net/)
cjson based on [lua-cjson](https://github.com/mpx/lua-cjson)
File system based on [spiffs](https://github.com/pellepl/spiffs)
From 64a2189556bf1421220fe50d00deef2f5f1aef1c Mon Sep 17 00:00:00 2001 From: Nick Andrew Date: Tue, 17 Nov 2015 00:05:21 +1100 Subject: [PATCH 02/39] README: Clean up the language --- README.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index a40a8555..7509480b 100644 --- a/README.md +++ b/README.md @@ -11,22 +11,22 @@ File system based on [spiffs](https://github.com/pellepl/spiffs)
Open source development kit for NodeMCU [nodemcu-devkit](https://github.com/nodemcu/nodemcu-devkit)
Flash tool for NodeMCU [nodemcu-flasher](https://github.com/nodemcu/nodemcu-flasher)
-wiki: [NodeMCU wiki](https://github.com/nodemcu/nodemcu-firmware/wiki)
+Developer Wiki: (https://github.com/nodemcu/nodemcu-firmware/wiki)
api: [NodeMCU api](https://github.com/nodemcu/nodemcu-firmware/wiki/nodemcu_api_en)
home: [nodemcu.com](http://www.nodemcu.com)
-bbs: [Chinese bbs](http://bbs.nodemcu.com)
+bbs: [Chinese BBS](http://bbs.nodemcu.com)
docs: [NodeMCU docs](http://www.nodemcu.com/docs/)
Tencent QQ group: 309957875
# Summary - Easy to access wireless router - Based on Lua 5.1.4 (without *debug, os* module.) -- Event-Drive programming preferred. -- Build-in json, file, timer, pwm, i2c, spi, 1-wire, net, mqtt, coap, gpio, wifi, adc, uart and system api. -- GPIO pin re-mapped, use the index to access gpio, i2c, pwm. -- Both Integer(less memory usage) and Float version firmware provided. +- Event-driven programming preferred +- Built-in modules: json, file, timer, pwm, i2c, spi, 1-wire, net, mqtt, coap, gpio, wifi, adc, uart and system api. +- GPIO pins re-mapped: use the index to access gpio, i2c, pwm. +- Both Integer (less memory usage) and Float version firmware provided. -# To Do List (pull requests are very welcomed) +# To Do List (pull requests are very welcome) - loadable c module - fix wifi smart connect - add spi module (done) From de634a95c3b0db61f2cea9f9dc8abc6ba656481d Mon Sep 17 00:00:00 2001 From: Nick Andrew Date: Tue, 17 Nov 2015 00:05:53 +1100 Subject: [PATCH 03/39] README: Remove unnecessary changelog Changelog is in the git history, or major changes should be noted in CHANGELOG.md Signed-off-by: Nick Andrew --- README.md | 38 -------------------------------------- 1 file changed, 38 deletions(-) diff --git a/README.md b/README.md index 7509480b..7ba8d6fb 100644 --- a/README.md +++ b/README.md @@ -34,44 +34,6 @@ Tencent QQ group: 309957875
- add coap module (done) - cross compiler (done) -# Change log -2015-06-27
-fixed ap/station-ap cannot connect to the device.
-added wifi.ap.getconfig().
-fixed net.dns.getdnsserver().
-added new base64 lua example.
-added node.bootreason() to inspect boot cause.
-optimization of u8g.
- -# Change log -2015-06-25
-move constants to ROM. Frees up 16k+ of RAM.
-add dhtlib for DHT11/21/22/33/44, port from Arduino.
-add 433MHz transmission.
-add crypto library.
-re-add ws2812.write().
-add wifi.getchannel.
-changed wifi_setip() to allow setting SoftAP gateway to 0.0.0.0.
-added net.dns.setdnsserver and net.dns.getdnsserver.
-add support for lm92 temperature sensor.
-implement getStrWidth() and setFontLineSpacingFactor().
-add -Os flag to release and debug builds.
-changed output format of table that is output by wifi_scan_done.
-added ability to set scan configuration to wifi.sta.getap.
-added function wifi.sta.getconfig().
-allow connecting to unsecured WiFi networks.
-add setphymode and getphymode to wifi module.
-add multicastJoin and multicastLeave to net module.
-add Yeelink Modules.
- -2015-03-31
-polish mqtt module, add queue for mqtt module.
-add reconnect option to mqtt.connect api, :connect( host, port, secure, auto_reconnect, function(client) )
-move node.readvdd33 to adc.readvdd33.
-tools/esptool.py supported NodeMCU devkit automatic flash. - -[more change log](https://github.com/nodemcu/nodemcu-firmware/wiki)
- ##GPIO NEW TABLE ( Build 20141219 and later) From b27fc6f50c5bbaecb95439b40e4c482a134b0b0f Mon Sep 17 00:00:00 2001 From: Nick Andrew Date: Tue, 17 Nov 2015 00:15:10 +1100 Subject: [PATCH 04/39] README: Move the simple programming examples up The README is presently quite unreadable. The simpler examples of programming an already-flashed ESP8266 are moved up, to give the new user the flavor of what is possible with NodeMCU. Instructions to build the firmware will follow. Signed-off-by: Nick Andrew --- README.md | 334 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 171 insertions(+), 163 deletions(-) diff --git a/README.md b/README.md index 7ba8d6fb..d00d437d 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,177 @@ Tencent QQ group: 309957875
- add coap module (done) - cross compiler (done) -##GPIO NEW TABLE ( Build 20141219 and later) +# Programming Examples + +Because Lua is a high level language and several modules are built into the firmware, you can very easily program your ESP8266. Here are some examples! + +## Connect to your AP + +```lua + ip = wifi.sta.getip() + print(ip) + --nil + wifi.setmode(wifi.STATION) + wifi.sta.config("SSID","password") + ip = wifi.sta.getip() + print(ip) + --192.168.18.110 +``` + +## Manipulate hardware like an Arduino + +```lua + pin = 1 + gpio.mode(pin,gpio.OUTPUT) + gpio.write(pin,gpio.HIGH) + print(gpio.read(pin)) +``` + +## Write a network application in Node.js style + +```lua + -- A simple http client + conn=net.createConnection(net.TCP, 0) + conn:on("receive", function(conn, payload) print(payload) end ) + conn:connect(80,"115.239.210.27") + conn:send("GET / HTTP/1.1\r\nHost: www.baidu.com\r\n" + .."Connection: keep-alive\r\nAccept: */*\r\n\r\n") +``` + +## Or a simple HTTP server + +```lua + -- A simple http server + srv=net.createServer(net.TCP) + srv:listen(80,function(conn) + conn:on("receive",function(conn,payload) + print(payload) + conn:send("

Hello, NodeMcu.

") + end) + conn:on("sent",function(conn) conn:close() end) + end) +``` + +## Connect to MQTT broker + +```lua +-- init mqtt client with keepalive timer 120sec +m = mqtt.Client("clientid", 120, "user", "password") + +-- setup Last Will and Testament (optional) +-- Broker will publish a message with qos = 0, retain = 0, data = "offline" +-- to topic "/lwt" if client don't send keepalive packet +m:lwt("/lwt", "offline", 0, 0) + +m:on("connect", function(con) print ("connected") end) +m:on("offline", function(con) print ("offline") end) + +-- on publish message receive event +m:on("message", function(conn, topic, data) + print(topic .. ":" ) + if data ~= nil then + print(data) + end +end) + +-- m:connect( host, port, secure, auto_reconnect, function(client) ) +-- for secure: m:connect("192.168.11.118", 1880, 1, 0) +-- for auto-reconnect: m:connect("192.168.11.118", 1880, 0, 1) +m:connect("192.168.11.118", 1880, 0, 0, function(conn) print("connected") end) + +-- subscribe topic with qos = 0 +m:subscribe("/topic",0, function(conn) print("subscribe success") end) +-- or subscribe multiple topic (topic/0, qos = 0; topic/1, qos = 1; topic2 , qos = 2) +-- m:subscribe({["topic/0"]=0,["topic/1"]=1,topic2=2}, function(conn) print("subscribe success") end) +-- publish a message with data = hello, QoS = 0, retain = 0 +m:publish("/topic","hello",0,0, function(conn) print("sent") end) + +m:close(); -- if auto-reconnect == 1, will disable auto-reconnect and then disconnect from host. +-- you can call m:connect again + +``` + +## UDP client and server + +```lua +-- a udp server +s=net.createServer(net.UDP) +s:on("receive",function(s,c) print(c) end) +s:listen(5683) + +-- a udp client +cu=net.createConnection(net.UDP) +cu:on("receive",function(cu,c) print(c) end) +cu:connect(5683,"192.168.18.101") +cu:send("hello") +``` + +## Do something shiny with an RGB LED + +```lua + function led(r,g,b) + pwm.setduty(1,r) + pwm.setduty(2,g) + pwm.setduty(3,b) + end + pwm.setup(1,500,512) + pwm.setup(2,500,512) + pwm.setup(3,500,512) + pwm.start(1) + pwm.start(2) + pwm.start(3) + led(512,0,0) -- red + led(0,0,512) -- blue +``` + +## And blink it + +```lua + lighton=0 + tmr.alarm(1,1000,1,function() + if lighton==0 then + lighton=1 + led(512,512,512) + else + lighton=0 + led(0,0,0) + end + end) +``` + +## If you want to run something when the system boots + +```lua + --init.lua will be excuted + file.open("init.lua","w") + file.writeline([[print("Hello, do this at the beginning.")]]) + file.close() + node.restart() -- this will restart the module. +``` + +## Add a simple telnet server to the Lua interpreter + +```lua + -- a simple telnet server + s=net.createServer(net.TCP,180) + s:listen(2323,function(c) + function s_output(str) + if(c~=nil) + then c:send(str) + end + end + node.output(s_output, 0) -- re-direct output to function s_ouput. + c:on("receive",function(c,l) + node.input(l) -- works like pcall(loadstring(l)) but support multiple separate line + end) + c:on("disconnection",function(c) + node.output(nil) -- un-regist the redirect output function, output goes to serial + end) + print("Welcome to NodeMcu world.") + end) +``` + +# GPIO NEW TABLE (Build 20141219 and later) @@ -130,168 +300,6 @@ Victor Brutskiy's [Esplorer](https://github.com/4refr0nt/ESPlorer) support most ####NodeMCU Studio [NodeMCU Studio](https://github.com/nodemcu/nodemcu-studio-csharp) is written in C# and support Windows. This software is opensource and can write lua files to filesystem. -#Start play - -####Connect to your ap - -```lua - ip = wifi.sta.getip() - print(ip) - --nil - wifi.setmode(wifi.STATION) - wifi.sta.config("SSID","password") - ip = wifi.sta.getip() - print(ip) - --192.168.18.110 -``` - -####Manipulate hardware like a arduino - -```lua - pin = 1 - gpio.mode(pin,gpio.OUTPUT) - gpio.write(pin,gpio.HIGH) - print(gpio.read(pin)) -``` - -####Write network application in nodejs style - -```lua - -- A simple http client - conn=net.createConnection(net.TCP, 0) - conn:on("receive", function(conn, payload) print(payload) end ) - conn:connect(80,"115.239.210.27") - conn:send("GET / HTTP/1.1\r\nHost: www.baidu.com\r\n" - .."Connection: keep-alive\r\nAccept: */*\r\n\r\n") -``` - -####Or a simple http server - -```lua - -- A simple http server - srv=net.createServer(net.TCP) - srv:listen(80,function(conn) - conn:on("receive",function(conn,payload) - print(payload) - conn:send("

Hello, NodeMcu.

") - end) - conn:on("sent",function(conn) conn:close() end) - end) -``` - -####Connect to MQTT Broker - -```lua --- init mqtt client with keepalive timer 120sec -m = mqtt.Client("clientid", 120, "user", "password") - --- setup Last Will and Testament (optional) --- Broker will publish a message with qos = 0, retain = 0, data = "offline" --- to topic "/lwt" if client don't send keepalive packet -m:lwt("/lwt", "offline", 0, 0) - -m:on("connect", function(con) print ("connected") end) -m:on("offline", function(con) print ("offline") end) - --- on publish message receive event -m:on("message", function(conn, topic, data) - print(topic .. ":" ) - if data ~= nil then - print(data) - end -end) - --- m:connect( host, port, secure, auto_reconnect, function(client) ) --- for secure: m:connect("192.168.11.118", 1880, 1, 0) --- for auto-reconnect: m:connect("192.168.11.118", 1880, 0, 1) -m:connect("192.168.11.118", 1880, 0, 0, function(conn) print("connected") end) - --- subscribe topic with qos = 0 -m:subscribe("/topic",0, function(conn) print("subscribe success") end) --- or subscribe multiple topic (topic/0, qos = 0; topic/1, qos = 1; topic2 , qos = 2) --- m:subscribe({["topic/0"]=0,["topic/1"]=1,topic2=2}, function(conn) print("subscribe success") end) --- publish a message with data = hello, QoS = 0, retain = 0 -m:publish("/topic","hello",0,0, function(conn) print("sent") end) - -m:close(); -- if auto-reconnect == 1, will disable auto-reconnect and then disconnect from host. --- you can call m:connect again - -``` - -#### UDP client and server -```lua --- a udp server -s=net.createServer(net.UDP) -s:on("receive",function(s,c) print(c) end) -s:listen(5683) - --- a udp client -cu=net.createConnection(net.UDP) -cu:on("receive",function(cu,c) print(c) end) -cu:connect(5683,"192.168.18.101") -cu:send("hello") -``` - -####Do something shining -```lua - function led(r,g,b) - pwm.setduty(1,r) - pwm.setduty(2,g) - pwm.setduty(3,b) - end - pwm.setup(1,500,512) - pwm.setup(2,500,512) - pwm.setup(3,500,512) - pwm.start(1) - pwm.start(2) - pwm.start(3) - led(512,0,0) -- red - led(0,0,512) -- blue -``` - -####And blink it -```lua - lighton=0 - tmr.alarm(1,1000,1,function() - if lighton==0 then - lighton=1 - led(512,512,512) - else - lighton=0 - led(0,0,0) - end - end) -``` - -####If you want to run something when system started -```lua - --init.lua will be excuted - file.open("init.lua","w") - file.writeline([[print("Hello, do this at the beginning.")]]) - file.close() - node.restart() -- this will restart the module. -``` - -####With below code, you can telnet to your esp8266 now -```lua - -- a simple telnet server - s=net.createServer(net.TCP,180) - s:listen(2323,function(c) - function s_output(str) - if(c~=nil) - then c:send(str) - end - end - node.output(s_output, 0) -- re-direct output to function s_ouput. - c:on("receive",function(c,l) - node.input(l) -- works like pcall(loadstring(l)) but support multiple separate line - end) - c:on("disconnection",function(c) - node.output(nil) -- un-regist the redirect output function, output goes to serial - end) - print("Welcome to NodeMcu world.") - end) -``` ####Use DS18B20 module extends your esp8266 ```lua From 1aa5efcba3561a15ea27737d1585ba9fb20f18b1 Mon Sep 17 00:00:00 2001 From: Nick Andrew Date: Tue, 17 Nov 2015 00:40:59 +1100 Subject: [PATCH 05/39] README: Add usable build instructions Put Marcel's online build server first, as this will be the go-to for new users. Note that they should build 'dev' not 'master'. Next, list the docker image which will build from your checked-out repository and possibly including your own changes. Finally, list the prerequisites if you want to build it all yourself, including the sequence of commands (same as the docker image uses). Signed-off-by: Nick Andrew --- README.md | 134 ++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 94 insertions(+), 40 deletions(-) diff --git a/README.md b/README.md index d00d437d..2dc82252 100644 --- a/README.md +++ b/README.md @@ -204,6 +204,99 @@ cu:send("hello") end) ``` +# Building the firmware + +There are several options for building the NodeMCU firmware. + +## Online firmware custom build + +Please try Marcel's [NodeMCU custom builds](http://frightanic.com/nodemcu-custom-build) cloud service and you can choose only the modules you need, and download the firmware once built.
+ +NodeMCU custom builds can build from the master branch (0.9.6; deprecated) and dev +branch (1.4.0). + +## Docker containerised build + +See https://hub.docker.com/r/asmaps/nodemcu-builder/ + +This docker image includes the build toolchain and SDK. You just run the docker +image with your checked-out NodeMCU firmware repository (this one). The docker +image can also flash the firmware to your device. + +You will need to see BUILD OPTIONS below, to configure the firmware before building. + +## Build it yourself + +See BUILD OPTIONS below, to configure the firmware before building. + +### Minimum requirements: + + - unrar + - GNU autoconf, automake, libtool + - GNU gcc, g++, make + - GNU flex, bison, gawk, sed + - python, python-serial, libexpat-dev + - srecord + - The esp-open-sdk from https://github.com/pfalcon/esp-open-sdk.git + +### Build instructions: + +Assuming NodeMCU firmware is checked-out to /opt/nodemcu-firmware: + +```sh +git clone --recursive https://github.com/pfalcon/esp-open-sdk.git /opt/esp-open-sdk +cd /opt/esp-open-sdk +make STANDALONE=y +PATH=/opt/esp-open-sdk/xtensa-lx106-elf/bin:$PATH +cd /opt/nodemcu-firmware +make +``` + +# BUILD OPTIONS + +Disable modules you won't be using, to reduce firmware size on flash and +free more RAM. The ESP8266 is quite limited in available RAM, and running +out can cause a system panic. + +## Edit app/include/user_modules.h + +Comment-out the #define statement for unused modules. + +```c +#define LUA_USE_BUILTIN_STRING // for string.xxx() +#define LUA_USE_BUILTIN_TABLE // for table.xxx() +#define LUA_USE_BUILTIN_COROUTINE // for coroutine.xxx() +#define LUA_USE_BUILTIN_MATH // for math.xxx(), partially work +// #define LUA_USE_BUILTIN_IO // for io.xxx(), partially work + +// #define LUA_USE_BUILTIN_OS // for os.xxx(), not work +// #define LUA_USE_BUILTIN_DEBUG // for debug.xxx(), not work + +#define LUA_USE_MODULES + +#ifdef LUA_USE_MODULES +#define LUA_USE_MODULES_NODE +#define LUA_USE_MODULES_FILE +#define LUA_USE_MODULES_GPIO +#define LUA_USE_MODULES_WIFI +#define LUA_USE_MODULES_NET +#define LUA_USE_MODULES_PWM +#define LUA_USE_MODULES_I2C +#define LUA_USE_MODULES_SPI +#define LUA_USE_MODULES_TMR +#define LUA_USE_MODULES_ADC +#define LUA_USE_MODULES_UART +#define LUA_USE_MODULES_OW +#define LUA_USE_MODULES_BIT +#define LUA_USE_MODULES_MQTT +// #define LUA_USE_MODULES_COAP +#define LUA_USE_MODULES_U8G +#define LUA_USE_MODULES_WS2812 +#define LUA_USE_MODULES_CJSON +#endif /* LUA_USE_MODULES */ +``` + + # GPIO NEW TABLE (Build 20141219 and later) @@ -238,46 +331,6 @@ cu:send("hello")
#### [*] D0(GPIO16) can only be used as gpio read/write. no interrupt supported. no pwm/i2c/ow supported. -#Build option -####file ./app/include/user_modules.h -```c -#define LUA_USE_BUILTIN_STRING // for string.xxx() -#define LUA_USE_BUILTIN_TABLE // for table.xxx() -#define LUA_USE_BUILTIN_COROUTINE // for coroutine.xxx() -#define LUA_USE_BUILTIN_MATH // for math.xxx(), partially work -// #define LUA_USE_BUILTIN_IO // for io.xxx(), partially work - -// #define LUA_USE_BUILTIN_OS // for os.xxx(), not work -// #define LUA_USE_BUILTIN_DEBUG // for debug.xxx(), not work - -#define LUA_USE_MODULES - -#ifdef LUA_USE_MODULES -#define LUA_USE_MODULES_NODE -#define LUA_USE_MODULES_FILE -#define LUA_USE_MODULES_GPIO -#define LUA_USE_MODULES_WIFI -#define LUA_USE_MODULES_NET -#define LUA_USE_MODULES_PWM -#define LUA_USE_MODULES_I2C -#define LUA_USE_MODULES_SPI -#define LUA_USE_MODULES_TMR -#define LUA_USE_MODULES_ADC -#define LUA_USE_MODULES_UART -#define LUA_USE_MODULES_OW -#define LUA_USE_MODULES_BIT -#define LUA_USE_MODULES_MQTT -// #define LUA_USE_MODULES_COAP -#define LUA_USE_MODULES_U8G -#define LUA_USE_MODULES_WS2812 -#define LUA_USE_MODULES_CJSON -#endif /* LUA_USE_MODULES */ -``` -#Online firmware custom build - -For many application, some modules are not used, remove them can free many memory.
- -Please try Marcel's [NodeMCU custom builds](http://frightanic.com/nodemcu-custom-build) cloud service and you can get your own firmware.
#Flash the firmware nodemcu_latest.bin: 0x00000
@@ -300,6 +353,7 @@ Victor Brutskiy's [Esplorer](https://github.com/4refr0nt/ESPlorer) support most ####NodeMCU Studio [NodeMCU Studio](https://github.com/nodemcu/nodemcu-studio-csharp) is written in C# and support Windows. This software is opensource and can write lua files to filesystem. +# OPTIONAL MODULES ####Use DS18B20 module extends your esp8266 ```lua From 20bca021af5185df212525b2acf12a61c9e5e3aa Mon Sep 17 00:00:00 2001 From: Nick Andrew Date: Tue, 17 Nov 2015 00:49:41 +1100 Subject: [PATCH 06/39] README: More work on the build options List the latest set of modules in the example on disabling modules. Show which file to edit to tag your firmware to identify it on boot. Signed-off-by: Nick Andrew --- README.md | 43 ++++++++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 2dc82252..36ac5279 100644 --- a/README.md +++ b/README.md @@ -260,20 +260,9 @@ out can cause a system panic. ## Edit app/include/user_modules.h -Comment-out the #define statement for unused modules. +Comment-out the #define statement for unused modules. Example: ```c -#define LUA_USE_BUILTIN_STRING // for string.xxx() -#define LUA_USE_BUILTIN_TABLE // for table.xxx() -#define LUA_USE_BUILTIN_COROUTINE // for coroutine.xxx() -#define LUA_USE_BUILTIN_MATH // for math.xxx(), partially work -// #define LUA_USE_BUILTIN_IO // for io.xxx(), partially work - -// #define LUA_USE_BUILTIN_OS // for os.xxx(), not work -// #define LUA_USE_BUILTIN_DEBUG // for debug.xxx(), not work - -#define LUA_USE_MODULES - #ifdef LUA_USE_MODULES #define LUA_USE_MODULES_NODE #define LUA_USE_MODULES_FILE @@ -290,12 +279,36 @@ Comment-out the #define statement for unused modules. #define LUA_USE_MODULES_BIT #define LUA_USE_MODULES_MQTT // #define LUA_USE_MODULES_COAP -#define LUA_USE_MODULES_U8G -#define LUA_USE_MODULES_WS2812 -#define LUA_USE_MODULES_CJSON +// #define LUA_USE_MODULES_U8G +// #define LUA_USE_MODULES_WS2801 +// #define LUA_USE_MODULES_WS2812 +// #define LUA_USE_MODULES_CJSON +#define LUA_USE_MODULES_CRYPTO +#define LUA_USE_MODULES_RC +#define LUA_USE_MODULES_DHT +#define LUA_USE_MODULES_RTCMEM +#define LUA_USE_MODULES_RTCTIME +#define LUA_USE_MODULES_RTCFIFO +#define LUA_USE_MODULES_SNTP +// #define LUA_USE_MODULES_BMP085 +#define LUA_USE_MODULES_TSL2561 +// #define LUA_USE_MODULES_HX711 + #endif /* LUA_USE_MODULES */ ``` +## Tagging your build + +Identify your firmware builds by editing `app/include/user_version.h` + +```c +#define NODE_VERSION "NodeMCU 1.4.0+myname" +#ifndef BUILD_DATE +#define BUILD_DATE "YYYYMMDD" +#endif +``` + + # GPIO NEW TABLE (Build 20141219 and later) From c8f9f4ca205eb2c2d29c9f0daedb9de8263297f6 Mon Sep 17 00:00:00 2001 From: Nick Andrew Date: Tue, 17 Nov 2015 00:54:46 +1100 Subject: [PATCH 07/39] README: More tweaking of the summary text Add all the latest module names too. Signed-off-by: Nick Andrew --- README.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 36ac5279..6d902939 100644 --- a/README.md +++ b/README.md @@ -19,14 +19,16 @@ docs: [NodeMCU docs](http://www.nodemcu.com/docs/)
Tencent QQ group: 309957875
# Summary -- Easy to access wireless router + +- Easy to program wireless node and/or Access Point - Based on Lua 5.1.4 (without *debug, os* module.) -- Event-driven programming preferred -- Built-in modules: json, file, timer, pwm, i2c, spi, 1-wire, net, mqtt, coap, gpio, wifi, adc, uart and system api. +- Event-driven programming model preferred +- Built-in modules: node, json, file, timer, pwm, i2c, spi, onewire, net, mqtt, coap, gpio, wifi, adc, uart, bit, u8g, ucg, ws2801, ws2812, crypto, dht, rtc, sntp, bmp085, tls2561, hx711 and system api. - GPIO pins re-mapped: use the index to access gpio, i2c, pwm. - Both Integer (less memory usage) and Float version firmware provided. # To Do List (pull requests are very welcome) + - loadable c module - fix wifi smart connect - add spi module (done) From c1fd5d4ed21c86af1f0d98527ed558dbf7dba9d9 Mon Sep 17 00:00:00 2001 From: Nick Andrew Date: Tue, 17 Nov 2015 00:57:42 +1100 Subject: [PATCH 08/39] README: Temporarily remove the 'download' button Remove the download button until a 1.4.0 release is pushed to github. Signed-off-by: Nick Andrew --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6d902939..68396111 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # **NodeMCU 1.4.0** # [![Join the chat at https://gitter.im/nodemcu/nodemcu-firmware](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/nodemcu/nodemcu-firmware?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) -[![Build Status](https://travis-ci.org/nodemcu/nodemcu-firmware.svg)](https://travis-ci.org/nodemcu/nodemcu-firmware) [![Download](https://img.shields.io/badge/download-~400k-orange.svg)](https://github.com/nodemcu/nodemcu-firmware/releases/latest) +[![Build Status](https://travis-ci.org/nodemcu/nodemcu-firmware.svg)](https://travis-ci.org/nodemcu/nodemcu-firmware) ###A lua based firmware for wifi-soc esp8266 Build on [ESP8266 sdk 1.4.0](http://bbs.espressif.com/viewtopic.php?f=46&t=1124)
From 7b1a371192da1514d508294e5d4137ea640c58ef Mon Sep 17 00:00:00 2001 From: Nick Andrew Date: Tue, 17 Nov 2015 01:04:44 +1100 Subject: [PATCH 09/39] README: Tidy the sample code Signed-off-by: Nick Andrew --- README.md | 88 +++++++++++++++++++++++++++---------------------------- 1 file changed, 44 insertions(+), 44 deletions(-) diff --git a/README.md b/README.md index 68396111..7e4c1cf9 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ Because Lua is a high level language and several modules are built into the firm print(ip) --nil wifi.setmode(wifi.STATION) - wifi.sta.config("SSID","password") + wifi.sta.config("SSID", "password") ip = wifi.sta.getip() print(ip) --192.168.18.110 @@ -57,8 +57,8 @@ Because Lua is a high level language and several modules are built into the firm ```lua pin = 1 - gpio.mode(pin,gpio.OUTPUT) - gpio.write(pin,gpio.HIGH) + gpio.mode(pin, gpio.OUTPUT) + gpio.write(pin, gpio.HIGH) print(gpio.read(pin)) ``` @@ -67,10 +67,10 @@ Because Lua is a high level language and several modules are built into the firm ```lua -- A simple http client conn=net.createConnection(net.TCP, 0) - conn:on("receive", function(conn, payload) print(payload) end ) - conn:connect(80,"115.239.210.27") + conn:on("receive", function(conn, payload) print(payload) end) + conn:connect(80, "115.239.210.27") conn:send("GET / HTTP/1.1\r\nHost: www.baidu.com\r\n" - .."Connection: keep-alive\r\nAccept: */*\r\n\r\n") + .. "Connection: keep-alive\r\nAccept: */*\r\n\r\n") ``` ## Or a simple HTTP server @@ -78,12 +78,12 @@ Because Lua is a high level language and several modules are built into the firm ```lua -- A simple http server srv=net.createServer(net.TCP) - srv:listen(80,function(conn) - conn:on("receive",function(conn,payload) + srv:listen(80, function(conn) + conn:on("receive", function(conn,payload) print(payload) - conn:send("

Hello, NodeMcu.

") + conn:send("

Hello, NodeMCU.

") end) - conn:on("sent",function(conn) conn:close() end) + conn:on("sent", function(conn) conn:close() end) end) ``` @@ -95,33 +95,33 @@ m = mqtt.Client("clientid", 120, "user", "password") -- setup Last Will and Testament (optional) -- Broker will publish a message with qos = 0, retain = 0, data = "offline" --- to topic "/lwt" if client don't send keepalive packet +-- to topic "/lwt" if client doesn't send keepalive packet m:lwt("/lwt", "offline", 0, 0) -m:on("connect", function(con) print ("connected") end) -m:on("offline", function(con) print ("offline") end) +m:on("connect", function(con) print("connected") end) +m:on("offline", function(con) print("offline") end) -- on publish message receive event m:on("message", function(conn, topic, data) - print(topic .. ":" ) + print(topic .. ":") if data ~= nil then print(data) end end) --- m:connect( host, port, secure, auto_reconnect, function(client) ) +-- m:connect(host, port, secure, auto_reconnect, function(client) end) -- for secure: m:connect("192.168.11.118", 1880, 1, 0) -- for auto-reconnect: m:connect("192.168.11.118", 1880, 0, 1) m:connect("192.168.11.118", 1880, 0, 0, function(conn) print("connected") end) --- subscribe topic with qos = 0 -m:subscribe("/topic",0, function(conn) print("subscribe success") end) --- or subscribe multiple topic (topic/0, qos = 0; topic/1, qos = 1; topic2 , qos = 2) +-- subscribe to topic with qos = 0 +m:subscribe("/topic", 0, function(conn) print("subscribe success") end) +-- or subscribe multiple topics (topic/0, qos = 0; topic/1, qos = 1; topic2, qos = 2) -- m:subscribe({["topic/0"]=0,["topic/1"]=1,topic2=2}, function(conn) print("subscribe success") end) -- publish a message with data = hello, QoS = 0, retain = 0 -m:publish("/topic","hello",0,0, function(conn) print("sent") end) +m:publish("/topic", "hello", 0, 0, function(conn) print("sent") end) -m:close(); -- if auto-reconnect == 1, will disable auto-reconnect and then disconnect from host. +m:close(); -- if auto-reconnect == 1, it will disable auto-reconnect and then disconnect from host. -- you can call m:connect again ``` @@ -131,45 +131,45 @@ m:close(); -- if auto-reconnect == 1, will disable auto-reconnect and then disc ```lua -- a udp server s=net.createServer(net.UDP) -s:on("receive",function(s,c) print(c) end) +s:on("receive", function(s, c) print(c) end) s:listen(5683) -- a udp client cu=net.createConnection(net.UDP) -cu:on("receive",function(cu,c) print(c) end) -cu:connect(5683,"192.168.18.101") +cu:on("receive", function(cu, c) print(c) end) +cu:connect(5683, "192.168.18.101") cu:send("hello") ``` ## Do something shiny with an RGB LED ```lua - function led(r,g,b) - pwm.setduty(1,r) - pwm.setduty(2,g) - pwm.setduty(3,b) + function led(r, g, b) + pwm.setduty(1, r) + pwm.setduty(2, g) + pwm.setduty(3, b) end - pwm.setup(1,500,512) - pwm.setup(2,500,512) - pwm.setup(3,500,512) + pwm.setup(1, 500, 512) + pwm.setup(2, 500, 512) + pwm.setup(3, 500, 512) pwm.start(1) pwm.start(2) pwm.start(3) - led(512,0,0) -- red - led(0,0,512) -- blue + led(512, 0, 0) -- red + led(0, 0, 512) -- blue ``` ## And blink it ```lua lighton=0 - tmr.alarm(1,1000,1,function() + tmr.alarm(1, 1000, 1, function() if lighton==0 then lighton=1 - led(512,512,512) + led(512, 512, 512) else lighton=0 - led(0,0,0) + led(0, 0, 0) end end) ``` @@ -177,8 +177,8 @@ cu:send("hello") ## If you want to run something when the system boots ```lua - --init.lua will be excuted - file.open("init.lua","w") + --init.lua will be executed + file.open("init.lua", "w") file.writeline([[print("Hello, do this at the beginning.")]]) file.close() node.restart() -- this will restart the module. @@ -188,21 +188,21 @@ cu:send("hello") ```lua -- a simple telnet server - s=net.createServer(net.TCP,180) - s:listen(2323,function(c) + s=net.createServer(net.TCP, 180) + s:listen(2323, function(c) function s_output(str) if(c~=nil) then c:send(str) end end node.output(s_output, 0) -- re-direct output to function s_ouput. - c:on("receive",function(c,l) - node.input(l) -- works like pcall(loadstring(l)) but support multiple separate line + c:on("receive", function(c, l) + node.input(l) -- works like pcall(loadstring(l)) but support multiples separate lines end) - c:on("disconnection",function(c) - node.output(nil) -- un-regist the redirect output function, output goes to serial + c:on("disconnection", function(c) + node.output(nil) -- un-register the redirect output function, output goes to serial end) - print("Welcome to NodeMcu world.") + print("Welcome to NodeMCU world.") end) ``` From e9091cc3647418da1d7a3f6ffa3c9ab240f7a14c Mon Sep 17 00:00:00 2001 From: Nick Andrew Date: Tue, 17 Nov 2015 01:13:33 +1100 Subject: [PATCH 10/39] README: Remove GPIO NEW TABLE It's in the API documentation and doesn't belong in the top-level README. Signed-off-by: Nick Andrew --- README.md | 38 -------------------------------------- 1 file changed, 38 deletions(-) diff --git a/README.md b/README.md index 7e4c1cf9..89c241c5 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,6 @@ Tencent QQ group: 309957875
- Based on Lua 5.1.4 (without *debug, os* module.) - Event-driven programming model preferred - Built-in modules: node, json, file, timer, pwm, i2c, spi, onewire, net, mqtt, coap, gpio, wifi, adc, uart, bit, u8g, ucg, ws2801, ws2812, crypto, dht, rtc, sntp, bmp085, tls2561, hx711 and system api. -- GPIO pins re-mapped: use the index to access gpio, i2c, pwm. - Both Integer (less memory usage) and Float version firmware provided. # To Do List (pull requests are very welcome) @@ -310,43 +309,6 @@ Identify your firmware builds by editing `app/include/user_version.h` #endif ``` - - -# GPIO NEW TABLE (Build 20141219 and later) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
IO indexESP8266 pinIO indexESP8266 pin
0 [*]GPIO168GPIO15 (SPI CS)
1GPIO59GPIO3 (UART RX)
2GPIO410GPIO1 (UART TX)
3GPIO011GPIO9
4GPIO212GPIO10
5GPIO14 (SPI CLK)
6GPIO12 (SPI MISO)
7GPIO13 (SPI MOSI)
-#### [*] D0(GPIO16) can only be used as gpio read/write. no interrupt supported. no pwm/i2c/ow supported. - - #Flash the firmware nodemcu_latest.bin: 0x00000
for most esp8266 modules, just pull GPIO0 down and restart.
From 7731592b7017ddf64ced3b9eb5e97ff3affebaf7 Mon Sep 17 00:00:00 2001 From: Nick Andrew Date: Tue, 17 Nov 2015 02:44:49 +1100 Subject: [PATCH 11/39] README: Update building and flashing instructions Make it more obvious to run file.format() after flashing. Signed-off-by: Nick Andrew --- README.md | 40 ++++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 89c241c5..b71d098f 100644 --- a/README.md +++ b/README.md @@ -238,7 +238,7 @@ See BUILD OPTIONS below, to configure the firmware before building. - GNU flex, bison, gawk, sed - python, python-serial, libexpat-dev - srecord - - The esp-open-sdk from https://github.com/pfalcon/esp-open-sdk.git + - The esp-open-sdk from https://github.com/pfalcon/esp-open-sdk ### Build instructions: @@ -309,16 +309,40 @@ Identify your firmware builds by editing `app/include/user_version.h` #endif ``` -#Flash the firmware -nodemcu_latest.bin: 0x00000
-for most esp8266 modules, just pull GPIO0 down and restart.
+# Flash the firmware + +## Flash tools for Windows + You can use the [nodemcu-flasher](https://github.com/nodemcu/nodemcu-flasher) to burn the firmware. -Or, if you build your own bin from source code.
-0x00000.bin: 0x00000
-0x10000.bin: 0x10000
+## Flash tools for Linux -*Better run file.format() after flash* +Esptool is a python utility which can read and write the flash in an ESP8266 device. See https://github.com/themadinventor/esptool + +## Preparing the hardware for firmware upgrade + +To enable ESP8266 firmware flashing, the GPIO0 pin must be pulled low before +the device is reset. Conversely, for a normal boot, GPIO0 must be pulled high +or floating. + +If you have a [NodeMCU Development Kit](http://www.nodemcu.com/index_en.html) then +you don't need to do anything, as the USB connection can pull GPIO0 +low by asserting DTR, and reset your board by asserting RTS. + +If you have an ESP-01 or other device without inbuilt USB, you will need to +enable flashing yourself by pulling GPIO0 low or pressing a "flash" switch. + +## Files to burn to the flash + +If you got your firmware from [NodeMCU custom builds](http://frightanic.com/nodemcu-custom-build) then you can flash that file directly to address 0x00000. + +Otherwise, if you built your own firmware from source code: + - bin/0x00000.bin to 0x00000 + - bin/0x10000.bin to 0x10000 + +Also, in some special circumstances, you may need to flash `blank.bin` or `esp_init_data_default.bin` to various addresses on the flash. + +If upgrading from `spiffs` version 0.3.2 to 0.3.3 or later, or after flashing any new firmware, you should run `file.format()` to re-format your flash filesystem. #Connect the hardware in serial baudrate:9600 From 7d05a25b653518df1c1dfbccaf1713e1be1e9d0c Mon Sep 17 00:00:00 2001 From: Nick Andrew Date: Tue, 17 Nov 2015 03:09:57 +1100 Subject: [PATCH 12/39] README: Flashing and connecting Signed-off-by: Nick Andrew --- README.md | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index b71d098f..61ec7d22 100644 --- a/README.md +++ b/README.md @@ -242,7 +242,7 @@ See BUILD OPTIONS below, to configure the firmware before building. ### Build instructions: -Assuming NodeMCU firmware is checked-out to /opt/nodemcu-firmware: +Assuming NodeMCU firmware is checked-out to `/opt/nodemcu-firmware`: ```sh git clone --recursive https://github.com/pfalcon/esp-open-sdk.git /opt/esp-open-sdk @@ -259,7 +259,7 @@ Disable modules you won't be using, to reduce firmware size on flash and free more RAM. The ESP8266 is quite limited in available RAM, and running out can cause a system panic. -## Edit app/include/user_modules.h +## Edit `app/include/user_modules.h` Comment-out the #define statement for unused modules. Example: @@ -340,12 +340,15 @@ Otherwise, if you built your own firmware from source code: - bin/0x00000.bin to 0x00000 - bin/0x10000.bin to 0x10000 -Also, in some special circumstances, you may need to flash `blank.bin` or `esp_init_data_default.bin` to various addresses on the flash. +Also, in some special circumstances, you may need to flash `blank.bin` or `esp_init_data_default.bin` to various addresses on the flash (depending on flash size and type). If upgrading from `spiffs` version 0.3.2 to 0.3.3 or later, or after flashing any new firmware, you should run `file.format()` to re-format your flash filesystem. -#Connect the hardware in serial -baudrate:9600 +# Connecting to your NodeMCU device + +NodeMCU serial interface uses 9600 baud at boot time. To increase the speed after booting, issue `uart.setup(0, 115200, 8, 0, 1, 1 )` (ESPlorer will do this automatically when changing the speed in the dropdown list). + +If the device panics and resets, errors will be written to the serial interface at 115200 bps. #Write Lua script to filesystem ####Esplorer From 81db4ae6bfdd237f4f1a1428c437ddcdc9d186ef Mon Sep 17 00:00:00 2001 From: Nick Andrew Date: Tue, 17 Nov 2015 03:11:48 +1100 Subject: [PATCH 13/39] README: Remove the
tags Change to Markdown list or table. Signed-off-by: Nick Andrew --- README.md | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 61ec7d22..f27e7d5a 100644 --- a/README.md +++ b/README.md @@ -4,19 +4,23 @@ [![Build Status](https://travis-ci.org/nodemcu/nodemcu-firmware.svg)](https://travis-ci.org/nodemcu/nodemcu-firmware) ###A lua based firmware for wifi-soc esp8266 -Build on [ESP8266 sdk 1.4.0](http://bbs.espressif.com/viewtopic.php?f=46&t=1124)
-Lua core based on [eLua project](http://www.eluaproject.net/)
-cjson based on [lua-cjson](https://github.com/mpx/lua-cjson)
-File system based on [spiffs](https://github.com/pellepl/spiffs)
-Open source development kit for NodeMCU [nodemcu-devkit](https://github.com/nodemcu/nodemcu-devkit)
-Flash tool for NodeMCU [nodemcu-flasher](https://github.com/nodemcu/nodemcu-flasher)
+ - Build on [ESP8266 sdk 1.4.0](http://bbs.espressif.com/viewtopic.php?f=46&t=1124) + - Lua core based on [eLua project](http://www.eluaproject.net/) + - cjson based on [lua-cjson](https://github.com/mpx/lua-cjson) + - File system based on [spiffs](https://github.com/pellepl/spiffs) + - Open source development kit for NodeMCU [nodemcu-devkit](https://github.com/nodemcu/nodemcu-devkit) + - Flash tool for NodeMCU [nodemcu-flasher](https://github.com/nodemcu/nodemcu-flasher) -Developer Wiki: (https://github.com/nodemcu/nodemcu-firmware/wiki)
-api: [NodeMCU api](https://github.com/nodemcu/nodemcu-firmware/wiki/nodemcu_api_en)
-home: [nodemcu.com](http://www.nodemcu.com)
-bbs: [Chinese BBS](http://bbs.nodemcu.com)
-docs: [NodeMCU docs](http://www.nodemcu.com/docs/)
-Tencent QQ group: 309957875
+### Resources + +| Resource | Location | +| -------------- | -------------- | +| Developer Wiki | https://github.com/nodemcu/nodemcu-firmware/wiki | +| api | [NodeMCU api](https://github.com/nodemcu/nodemcu-firmware/wiki/nodemcu_api_en) | +| home | [nodemcu.com](http://www.nodemcu.com) | +| bbs | [Chinese BBS](http://bbs.nodemcu.com) | +| docs | [NodeMCU docs](http://www.nodemcu.com/docs/) | +| Tencent QQ group | 309957875 | # Summary @@ -211,7 +215,7 @@ There are several options for building the NodeMCU firmware. ## Online firmware custom build -Please try Marcel's [NodeMCU custom builds](http://frightanic.com/nodemcu-custom-build) cloud service and you can choose only the modules you need, and download the firmware once built.
+Please try Marcel's [NodeMCU custom builds](http://frightanic.com/nodemcu-custom-build) cloud service and you can choose only the modules you need, and download the firmware once built. NodeMCU custom builds can build from the master branch (0.9.6; deprecated) and dev branch (1.4.0). From e1e1cde8f8865435408d529a8910ed3557c54250 Mon Sep 17 00:00:00 2001 From: Nick Andrew Date: Tue, 17 Nov 2015 03:36:19 +1100 Subject: [PATCH 14/39] README: Expand and update the Resources list Signed-off-by: Nick Andrew --- README.md | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index f27e7d5a..7fff744d 100644 --- a/README.md +++ b/README.md @@ -9,18 +9,6 @@ - cjson based on [lua-cjson](https://github.com/mpx/lua-cjson) - File system based on [spiffs](https://github.com/pellepl/spiffs) - Open source development kit for NodeMCU [nodemcu-devkit](https://github.com/nodemcu/nodemcu-devkit) - - Flash tool for NodeMCU [nodemcu-flasher](https://github.com/nodemcu/nodemcu-flasher) - -### Resources - -| Resource | Location | -| -------------- | -------------- | -| Developer Wiki | https://github.com/nodemcu/nodemcu-firmware/wiki | -| api | [NodeMCU api](https://github.com/nodemcu/nodemcu-firmware/wiki/nodemcu_api_en) | -| home | [nodemcu.com](http://www.nodemcu.com) | -| bbs | [Chinese BBS](http://bbs.nodemcu.com) | -| docs | [NodeMCU docs](http://www.nodemcu.com/docs/) | -| Tencent QQ group | 309957875 | # Summary @@ -30,6 +18,21 @@ - Built-in modules: node, json, file, timer, pwm, i2c, spi, onewire, net, mqtt, coap, gpio, wifi, adc, uart, bit, u8g, ucg, ws2801, ws2812, crypto, dht, rtc, sntp, bmp085, tls2561, hx711 and system api. - Both Integer (less memory usage) and Float version firmware provided. +## Useful links + +| Resource | Location | +| -------------- | -------------- | +| Developer Wiki | https://github.com/nodemcu/nodemcu-firmware/wiki | +| API docs | [NodeMCU api](https://github.com/nodemcu/nodemcu-firmware/wiki/nodemcu_api_en) | +| Home | [nodemcu.com](http://www.nodemcu.com) | +| BBS | [Chinese BBS](http://bbs.nodemcu.com) | +| Docs | [NodeMCU docs](http://www.nodemcu.com/docs/) | +| Tencent QQ group | 309957875 | +| Windows flash tool | [nodemcu-flasher](https://github.com/nodemcu/nodemcu-flasher) | +| Linux flash tool | [Esptool](https://github.com/themadinventor/esptool) | +| ESPlorer GUI | https://github.com/4refr0nt/ESPlorer | +| NodeMCU Studio GUI | https://github.com/nodemcu/nodemcu-studio-csharp | + # To Do List (pull requests are very welcome) - loadable c module From 44adcd5f7e971cb4da7cae71345d2a175958ecfd Mon Sep 17 00:00:00 2001 From: Nick Andrew Date: Tue, 17 Nov 2015 03:44:10 +1100 Subject: [PATCH 15/39] README: Setting the initial serial interface rate Signed-off-by: Nick Andrew --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index 7fff744d..8067359b 100644 --- a/README.md +++ b/README.md @@ -316,6 +316,15 @@ Identify your firmware builds by editing `app/include/user_version.h` #endif ``` +## Setting the boot time serial interface rate + +The initial baud rate at boot time is 9600 bps, but you can change this by +editing `app/include/user_config.h` and change BIT_RATE_DEFAULT, e.g.: + +```c +#define BIT_RATE_DEFAULT BIT_RATE_115200 +``` + # Flash the firmware ## Flash tools for Windows From 8eb3fbafd9e887f8f6e09e55f58a05435c72be4d Mon Sep 17 00:00:00 2001 From: Nick Andrew Date: Tue, 17 Nov 2015 03:49:23 +1100 Subject: [PATCH 16/39] README: Tidy up the user interface tools Signed-off-by: Nick Andrew --- README.md | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 8067359b..eefa6828 100644 --- a/README.md +++ b/README.md @@ -366,12 +366,21 @@ NodeMCU serial interface uses 9600 baud at boot time. To increase the speed afte If the device panics and resets, errors will be written to the serial interface at 115200 bps. -#Write Lua script to filesystem -####Esplorer -Victor Brutskiy's [Esplorer](https://github.com/4refr0nt/ESPlorer) support most platforms such as Linux, Windows, Mac OS, etc. This software is opensource and can write lua/lc files to filesystem. +# User Interface tools -####NodeMCU Studio -[NodeMCU Studio](https://github.com/nodemcu/nodemcu-studio-csharp) is written in C# and support Windows. This software is opensource and can write lua files to filesystem. +## Esplorer + +Victor Brutskiy's [ESPlorer](https://github.com/4refr0nt/ESPlorer) is written in Java, is open source and runs on most platforms such as Linux, Windows, Mac OS, etc. + +#### Features + + - Edit Lua scripts and run on the ESP8266 and save to its flash + - Serial console log + - Also supports original AT firmware (reading and setting WiFi modes, etc) + +## NodeMCU Studio + +[NodeMCU Studio](https://github.com/nodemcu/nodemcu-studio-csharp) is written in C# and supports Windows. This software is open source and can write lua files to filesystem. # OPTIONAL MODULES From 703d55da822c4d4929223ae852cc227b214c70e9 Mon Sep 17 00:00:00 2001 From: Nick Andrew Date: Tue, 17 Nov 2015 03:51:56 +1100 Subject: [PATCH 17/39] README: Tidy ugly looking uart.setup() call Signed-off-by: Nick Andrew --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index eefa6828..ecfc81c8 100644 --- a/README.md +++ b/README.md @@ -362,9 +362,9 @@ If upgrading from `spiffs` version 0.3.2 to 0.3.3 or later, or after flashing an # Connecting to your NodeMCU device -NodeMCU serial interface uses 9600 baud at boot time. To increase the speed after booting, issue `uart.setup(0, 115200, 8, 0, 1, 1 )` (ESPlorer will do this automatically when changing the speed in the dropdown list). +NodeMCU serial interface uses 9600 baud at boot time. To increase the speed after booting, issue `uart.setup(0,115200,8,0,1,1)` (ESPlorer will do this automatically when changing the speed in the dropdown list). -If the device panics and resets, errors will be written to the serial interface at 115200 bps. +If the device panics and resets at any time, errors will be written to the serial interface at 115200 bps. # User Interface tools From 0fbf442158d6063b86bd5240b27724d5c90559d9 Mon Sep 17 00:00:00 2001 From: Johny Mattsson Date: Tue, 14 Jul 2015 11:37:12 +1000 Subject: [PATCH 18/39] Do not allow execution to continue after a PANIC! It really does not improve things... --- app/lua/lauxlib.c | 1 + 1 file changed, 1 insertion(+) diff --git a/app/lua/lauxlib.c b/app/lua/lauxlib.c index 35ff8266..1ce21f38 100644 --- a/app/lua/lauxlib.c +++ b/app/lua/lauxlib.c @@ -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; } From e71a2dd64aa09a478eb3300c82a4c6d18cd3c929 Mon Sep 17 00:00:00 2001 From: TerryE Date: Thu, 3 Dec 2015 19:16:30 +0000 Subject: [PATCH 19/39] Fix ECG case in concat where stack top not recalculated --- app/lua/lvm.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/app/lua/lvm.c b/app/lua/lvm.c index f475e3e9..965f4a3c 100644 --- a/app/lua/lvm.c +++ b/app/lua/lvm.c @@ -319,22 +319,25 @@ void luaV_concat (lua_State *L, int total, int last) { lu_mem max_sizet = MAX_SIZET; if (G(L)->memlimit < max_sizet) max_sizet = G(L)->memlimit; do { + /* Any call which does a memory allocation may trim the stack, + invalidating top unless the stack is fixed duri ng the allocation */ StkId top = L->base + last + 1; + fixedstack(L); int n = 2; /* number of elements handled in this pass (at least 2) */ if (!(ttisstring(top-2) || ttisnumber(top-2)) || !tostring(L, top-1)) { + unfixedstack(L); if (!call_binTM(L, top-2, top-1, top-2, TM_CONCAT)) { /* restore 'top' pointer, since stack might have been reallocted */ top = L->base + last + 1; luaG_concaterror(L, top-2, top-1); } - } else if (tsvalue(top-1)->len == 0) /* second op is empty? */ + } else if (tsvalue(top-1)->len == 0) { /* second op is empty? */ (void)tostring(L, top - 2); /* result is first op (as string) */ - else { + } else { /* at least two string values; get as many as possible */ size_t tl = tsvalue(top-1)->len; char *buffer; int i; - fixedstack(L); /* collect total length */ for (n = 1; n < total && tostring(L, top-n-1); n++) { size_t l = tsvalue(top-n-1)->len; @@ -351,10 +354,10 @@ void luaV_concat (lua_State *L, int total, int last) { } setsvalue2s(L, top-n, luaS_newlstr(L, buffer, tl)); luaZ_resetbuffer(&G(L)->buff); - unfixedstack(L); } total -= n-1; /* got `n' strings to create 1 new */ last -= n-1; + unfixedstack(L); } while (total > 1); /* repeat until only 1 result left */ } From e9ee9a57d149b9785ec78b2476ee850148d65d9d Mon Sep 17 00:00:00 2001 From: Nick Andrew Date: Sun, 6 Dec 2015 01:37:59 +1100 Subject: [PATCH 20/39] Remove the lobject.c:88 assertion failures When lua assertions are enabled, normal operation results in many: lobject.c:88: (((t1)->tt) == 4) lobject.c:88: (((t2)->tt) == 4) lobject.c:88: (((t1)->tt) == 4) lobject.c:88: (((t2)->tt) == 4) lobject.c:88: (((t1)->tt) == 4) lobject.c:88: (((t2)->tt) == 4) It comes from using the pvalue() macro for 3 pointer types, where pvalue() also checks the type of pointer and complains through the assertion where the type == 4 (TLIGHTUSERDATA). Use the correct macro according to the type of data being compared to eliminate this assertion error. Signed-off-by: Nick Andrew --- app/lua/lobject.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/lua/lobject.c b/app/lua/lobject.c index 8a142b4e..6a684559 100644 --- a/app/lua/lobject.c +++ b/app/lua/lobject.c @@ -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: - case LUA_TROTABLE: - case LUA_TLIGHTFUNCTION: return pvalue(t1) == pvalue(t2); + case LUA_TROTABLE: + return rvalue(t1) == rvalue(t2); + case LUA_TLIGHTFUNCTION: + return fvalue(t1) == fvalue(t2); default: lua_assert(iscollectable(t1)); return gcvalue(t1) == gcvalue(t2); From b3ae9d143db157fa8cb17125baf1a2b7bd14d582 Mon Sep 17 00:00:00 2001 From: Vowstar Date: Sat, 5 Dec 2015 13:49:31 +0800 Subject: [PATCH 21/39] Add DHT sensor lib description in ReadMe A lot of people don't know DHT sensor lib. --- README.md | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/README.md b/README.md index 7d140e72..e0b73768 100644 --- a/README.md +++ b/README.md @@ -638,3 +638,31 @@ The HX711 is an inexpensive 24bit ADC with programmable 128x, 64x, and 32x gain. -- Read ch A with 128 gain. raw_data = hx711.read(0) ``` + +####Universal DHT Sensor support +Support DHT11, DHT21, DHT22, DHT33, DHT44, etc. +Use all-in-one function to read DHT sensor. +```lua + +pin = 5 +status,temp,humi,temp_decimial,humi_decimial = dht.readxx(pin) +if( status == dht.OK ) then + -- Integer firmware using this example + print( + string.format( + "DHT Temperature:%d.%03d;Humidity:%d.%03d\r\n", + math.floor(temp), + temp_decimial, + math.floor(humi), + humi_decimial + ) + ) + -- Float firmware using this example + print("DHT Temperature:"..temp..";".."Humidity:"..humi) +elseif( status == dht.ERROR_CHECKSUM ) then + print( "DHT Checksum error." ); +elseif( status == dht.ERROR_TIMEOUT ) then + print( "DHT Time out." ); +end + +``` From 1217b477791f0288714a0cabb72dd12f6652ab32 Mon Sep 17 00:00:00 2001 From: Nick Andrew Date: Sun, 6 Dec 2015 11:21:52 +1100 Subject: [PATCH 22/39] Update README SDK; remove todo list Based on @vowstar edits: * Note that the SDK is the NONOS one * Add links for NodeMCU devkit v1.0 and distinguish from v0.9 * Remove the ToDo list (as all are complete but for 1 item) --- README.md | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index e0b73768..03ffaa0f 100644 --- a/README.md +++ b/README.md @@ -4,11 +4,11 @@ [![Build Status](https://travis-ci.org/nodemcu/nodemcu-firmware.svg)](https://travis-ci.org/nodemcu/nodemcu-firmware) ###A lua based firmware for wifi-soc esp8266 - - Build on [ESP8266 sdk 1.4.0](http://bbs.espressif.com/viewtopic.php?f=46&t=1124) + - Build on [ESP8266 NONOS SDK 1.4.0](http://bbs.espressif.com/viewtopic.php?f=46&t=1124) - Lua core based on [eLua project](http://www.eluaproject.net/) - cjson based on [lua-cjson](https://github.com/mpx/lua-cjson) - File system based on [spiffs](https://github.com/pellepl/spiffs) - - Open source development kit for NodeMCU [nodemcu-devkit](https://github.com/nodemcu/nodemcu-devkit) + - Open source development kit for NodeMCU [nodemcu-devkit-v0.9](https://github.com/nodemcu/nodemcu-devkit) [nodemcu-devkit-v1.0](https://github.com/nodemcu/nodemcu-devkit-v1.0) # Summary @@ -33,15 +33,6 @@ | ESPlorer GUI | https://github.com/4refr0nt/ESPlorer | | NodeMCU Studio GUI | https://github.com/nodemcu/nodemcu-studio-csharp | -# To Do List (pull requests are very welcome) - -- loadable c module -- fix wifi smart connect -- add spi module (done) -- add mqtt module (done) -- add coap module (done) -- cross compiler (done) - # Programming Examples Because Lua is a high level language and several modules are built into the firmware, you can very easily program your ESP8266. Here are some examples! From 570bddcfe5ad1a0d7d8108a231f9c8ac4c3ed9d2 Mon Sep 17 00:00:00 2001 From: Nick Andrew Date: Sun, 6 Dec 2015 11:36:19 +1100 Subject: [PATCH 23/39] More README tweaks now that master was updated * Remove the "0.9.6; deprecated" comment regarding the master branch * Add a paragraph on enabling debugging * Clarify (I hope) the conditions under which you need to reformat your flash filesystem. * Remove trailing blanks Signed-off-by: Nick Andrew --- README.md | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 03ffaa0f..e60b9972 100644 --- a/README.md +++ b/README.md @@ -211,8 +211,7 @@ There are several options for building the NodeMCU firmware. Please try Marcel's [NodeMCU custom builds](http://frightanic.com/nodemcu-custom-build) cloud service and you can choose only the modules you need, and download the firmware once built. -NodeMCU custom builds can build from the master branch (0.9.6; deprecated) and dev -branch (1.4.0). +NodeMCU custom builds can build from the master branch and dev branch (with the latest fixes). ## Docker containerised build @@ -316,6 +315,16 @@ editing `app/include/user_config.h` and change BIT_RATE_DEFAULT, e.g.: #define BIT_RATE_DEFAULT BIT_RATE_115200 ``` +## Debugging + +To enable runtime debug messages to serial console, edit `app/include/user_config.h` + +```c +#define DEVELOP_VERSION +``` + +`DEVELOP_VERSION` changes the startup baud rate to 74880. + # Flash the firmware ## Flash tools for Windows @@ -349,7 +358,8 @@ Otherwise, if you built your own firmware from source code: Also, in some special circumstances, you may need to flash `blank.bin` or `esp_init_data_default.bin` to various addresses on the flash (depending on flash size and type). -If upgrading from `spiffs` version 0.3.2 to 0.3.3 or later, or after flashing any new firmware, you should run `file.format()` to re-format your flash filesystem. +If upgrading from `spiffs` version 0.3.2 to 0.3.3 or later, or after flashing any new firmware (particularly one with a much different size), you may need to run `file.format()` to re-format your flash filesystem. +You will know if you need to do this because your flash files disappeared, or they exist but seem empty, or data cannot be written to new files. # Connecting to your NodeMCU device @@ -607,7 +617,7 @@ cc:post(coap.NON, "coap://192.168.18.100:5683/", "Hello") ####cjson ```lua -- Note that when cjson deal with large content, it may fails a memory allocation, and leaks a bit of memory. --- so it's better to detect that and schedule a restart. +-- so it's better to detect that and schedule a restart. -- -- Translate Lua value to/from JSON -- text = cjson.encode(value) @@ -622,7 +632,7 @@ json_text = cjson.encode(value) ####Read an HX711 load cell ADC. Note: currently only chanel A with gain 128 is supported. -The HX711 is an inexpensive 24bit ADC with programmable 128x, 64x, and 32x gain. +The HX711 is an inexpensive 24bit ADC with programmable 128x, 64x, and 32x gain. ```lua -- Initialize the hx711 with clk on pin 5 and data on pin 6 hx711.init(5,6) @@ -631,7 +641,7 @@ The HX711 is an inexpensive 24bit ADC with programmable 128x, 64x, and 32x gain. ``` ####Universal DHT Sensor support -Support DHT11, DHT21, DHT22, DHT33, DHT44, etc. +Support DHT11, DHT21, DHT22, DHT33, DHT44, etc. Use all-in-one function to read DHT sensor. ```lua @@ -639,7 +649,7 @@ pin = 5 status,temp,humi,temp_decimial,humi_decimial = dht.readxx(pin) if( status == dht.OK ) then -- Integer firmware using this example - print( + print( string.format( "DHT Temperature:%d.%03d;Humidity:%d.%03d\r\n", math.floor(temp), From c4e8b04fbf9a7ec9b241cab09447777e846c58c1 Mon Sep 17 00:00:00 2001 From: Johny Mattsson Date: Thu, 3 Dec 2015 12:03:22 +1100 Subject: [PATCH 24/39] Cleaned up all uses of INTERNAL_FLASH_START_ADDRESS. There was only one genuine use of this macro, all other places were using it only as a necessary compensation. While this was fine as long as it was the first meg of flash which was mapped, it became incorrect and quite dangerous whenever this assumption did not hold (such as when running from the second slot in an OTA scenario). The flash API now uses actual addresses, not translated/mapped addresses, and the users of this API have been adjusted accordingly. This makes the flash API work correctly regardless of what flash mapping is in use. The old macro is still available under the new name INTERNAL_FLASH_MAPPED_ADDRESS, and this is used to detect flash writes where the source is mapped flash (and thus has to be bounced), and to adjust the _flash_used_end linker symbol when used with flassh_find_sector() by the filesystem code. The latter usage is not OTA-proof, but in an OTA scenario the filesystem needs a fixed location anyway and thus would not use this code path. --- app/platform/common.c | 14 ++++++-------- app/platform/cpu_esp8266.h | 2 +- app/platform/flash_api.c | 5 ----- app/platform/flash_api.h | 2 -- app/platform/platform.c | 8 +++----- app/spiffs/spiffs.c | 4 ++-- app/wofs/romfs.c | 2 +- 7 files changed, 13 insertions(+), 24 deletions(-) diff --git a/app/platform/common.c b/app/platform/common.c index 617f6831..bb10fb45 100644 --- a/app/platform/common.c +++ b/app/platform/common.c @@ -102,15 +102,14 @@ extern char _flash_used_end[]; // Return the sector number, as well as the start and end address of the sector static uint32_t flashh_find_sector( uint32_t address, uint32_t *pstart, uint32_t *pend ) { - address -= INTERNAL_FLASH_START_ADDRESS; #ifdef INTERNAL_FLASH_SECTOR_SIZE // All the sectors in the flash have the same size, so just align the address uint32_t sect_id = address / INTERNAL_FLASH_SECTOR_SIZE; if( pstart ) - *pstart = sect_id * INTERNAL_FLASH_SECTOR_SIZE + INTERNAL_FLASH_START_ADDRESS; + *pstart = sect_id * INTERNAL_FLASH_SECTOR_SIZE ; if( pend ) - *pend = ( sect_id + 1 ) * INTERNAL_FLASH_SECTOR_SIZE + INTERNAL_FLASH_START_ADDRESS - 1; + *pend = ( sect_id + 1 ) * INTERNAL_FLASH_SECTOR_SIZE - 1; return sect_id; #else // #ifdef INTERNAL_FLASH_SECTOR_SIZE // The flash has blocks of different size @@ -121,9 +120,9 @@ static uint32_t flashh_find_sector( uint32_t address, uint32_t *pstart, uint32_t while( ( total <= address ) && ( i < sizeof( flash_sect_size ) / sizeof( uint32_t ) ) ) total += flash_sect_size[ i ++ ]; if( pstart ) - *pstart = ( total - flash_sect_size[ i - 1 ] ) + INTERNAL_FLASH_START_ADDRESS; + *pstart = ( total - flash_sect_size[ i - 1 ] ); if( pend ) - *pend = total + INTERNAL_FLASH_START_ADDRESS - 1; + *pend = total - 1; return i - 1; #endif // #ifdef INTERNAL_FLASH_SECTOR_SIZE } @@ -150,13 +149,12 @@ uint32_t platform_flash_get_first_free_block_address( uint32_t *psect ) uint32_t start, end, sect; NODE_DBG("_flash_used_end:%08x\n", (uint32_t)_flash_used_end); if(_flash_used_end>0){ // find the used sector - // sect = flashh_find_sector( ( uint32_t )flash_used_size + INTERNAL_FLASH_START_ADDRESS - 1, NULL, &end ); - sect = flashh_find_sector( ( uint32_t )_flash_used_end - 1, NULL, &end ); + sect = flashh_find_sector( ( uint32_t )_flash_used_end - INTERNAL_FLASH_MAPPED_ADDRESS - 1, NULL, &end ); if( psect ) *psect = sect + 1; return end + 1; }else{ - sect = flashh_find_sector( INTERNAL_FLASH_START_ADDRESS, &start, NULL ); // find the first free sector + sect = flashh_find_sector( 0, &start, NULL ); // find the first free sector if( psect ) *psect = sect; return start; diff --git a/app/platform/cpu_esp8266.h b/app/platform/cpu_esp8266.h index ec6440a7..ef618dea 100644 --- a/app/platform/cpu_esp8266.h +++ b/app/platform/cpu_esp8266.h @@ -53,7 +53,7 @@ #define INTERNAL_FLASH_READ_UNIT_SIZE 4 #define INTERNAL_FLASH_SIZE ( (SYS_PARAM_SEC_START) * INTERNAL_FLASH_SECTOR_SIZE ) -#define INTERNAL_FLASH_START_ADDRESS 0x40200000 +#define INTERNAL_FLASH_MAPPED_ADDRESS 0x40200000 // SpiFlashOpResult spi_flash_erase_sector(uint16 sec); // SpiFlashOpResult spi_flash_write(uint32 des_addr, uint32 *src_addr, uint32 size); diff --git a/app/platform/flash_api.c b/app/platform/flash_api.c index 985b2c5f..5955be26 100644 --- a/app/platform/flash_api.c +++ b/app/platform/flash_api.c @@ -96,11 +96,6 @@ SpiFlashOpResult flash_safe_erase_sector(uint16 sec) SPIFlashInfo flash_rom_getinfo(void) { volatile SPIFlashInfo spi_flash_info ICACHE_STORE_ATTR; - // Don't use it before cache read disabled - // FLASH_DISABLE_CACHE(); - // spi_flash_info = *((SPIFlashInfo *)(FLASH_ADDRESS_START_MAP)); - // FLASH_ENABLE_CACHE(); - // Needn't safe mode. spi_flash_read(0, (uint32 *)(& spi_flash_info), sizeof(spi_flash_info)); return spi_flash_info; } diff --git a/app/platform/flash_api.h b/app/platform/flash_api.h index 0063ee1c..99339ee3 100644 --- a/app/platform/flash_api.h +++ b/app/platform/flash_api.h @@ -4,8 +4,6 @@ #include "user_config.h" #include "cpu_esp8266.h" -#define FLASH_ADDRESS_START_MAP (INTERNAL_FLASH_START_ADDRESS) - #define FLASH_SIZE_2MBIT (2 * 1024 * 1024) #define FLASH_SIZE_4MBIT (4 * 1024 * 1024) #define FLASH_SIZE_8MBIT (8 * 1024 * 1024) diff --git a/app/platform/platform.c b/app/platform/platform.c index 3d776f3a..1a45d5b1 100755 --- a/app/platform/platform.c +++ b/app/platform/platform.c @@ -514,12 +514,11 @@ int platform_spi_transaction( uint8_t id, uint8_t cmd_bitlen, spi_data_type cmd_ */ uint32_t platform_s_flash_write( const void *from, uint32_t toaddr, uint32_t size ) { - toaddr -= INTERNAL_FLASH_START_ADDRESS; SpiFlashOpResult r; const uint32_t blkmask = INTERNAL_FLASH_WRITE_UNIT_SIZE - 1; uint32_t *apbuf = NULL; uint32_t fromaddr = (uint32_t)from; - if( (fromaddr & blkmask ) || (fromaddr >= INTERNAL_FLASH_START_ADDRESS)) { + if( (fromaddr & blkmask ) || (fromaddr >= INTERNAL_FLASH_MAPPED_ADDRESS)) { apbuf = (uint32_t *)c_malloc(size); if(!apbuf) return 0; @@ -532,7 +531,7 @@ uint32_t platform_s_flash_write( const void *from, uint32_t toaddr, uint32_t siz if(SPI_FLASH_RESULT_OK == r) return size; else{ - NODE_ERR( "ERROR in flash_write: r=%d at %08X\n", ( int )r, ( unsigned )toaddr+INTERNAL_FLASH_START_ADDRESS ); + NODE_ERR( "ERROR in flash_write: r=%d at %08X\n", ( int )r, ( unsigned )toaddr); return 0; } } @@ -547,7 +546,6 @@ uint32_t platform_s_flash_read( void *to, uint32_t fromaddr, uint32_t size ) if (size==0) return 0; - fromaddr -= INTERNAL_FLASH_START_ADDRESS; SpiFlashOpResult r; system_soft_wdt_feed (); @@ -571,7 +569,7 @@ uint32_t platform_s_flash_read( void *to, uint32_t fromaddr, uint32_t size ) if(SPI_FLASH_RESULT_OK == r) return size; else{ - NODE_ERR( "ERROR in flash_read: r=%d at %08X\n", ( int )r, ( unsigned )fromaddr+INTERNAL_FLASH_START_ADDRESS ); + NODE_ERR( "ERROR in flash_read: r=%d at %08X\n", ( int )r, ( unsigned )fromaddr); return 0; } } diff --git a/app/spiffs/spiffs.c b/app/spiffs/spiffs.c index 03436193..f5c514f7 100644 --- a/app/spiffs/spiffs.c +++ b/app/spiffs/spiffs.c @@ -53,7 +53,7 @@ void myspiffs_mount() { #endif cfg.phys_addr += 0x3000; cfg.phys_addr &= 0xFFFFC000; // align to 4 sector. - cfg.phys_size = INTERNAL_FLASH_SIZE - ( ( u32_t )cfg.phys_addr - INTERNAL_FLASH_START_ADDRESS ); + cfg.phys_size = INTERNAL_FLASH_SIZE - ( ( u32_t )cfg.phys_addr ); cfg.phys_erase_block = INTERNAL_FLASH_SECTOR_SIZE; // according to datasheet cfg.log_block_size = INTERNAL_FLASH_SECTOR_SIZE; // let us not complicate things cfg.log_page_size = LOG_PAGE_SIZE; // as we said @@ -97,7 +97,7 @@ int myspiffs_format( void ) sect_first += 0x3000; sect_first &= 0xFFFFC000; // align to 4 sector. sect_first = platform_flash_get_sector_of_address(sect_first); - sect_last = INTERNAL_FLASH_SIZE + INTERNAL_FLASH_START_ADDRESS - 4; + sect_last = INTERNAL_FLASH_SIZE - SYS_PARAM_SEC_NUM; sect_last = platform_flash_get_sector_of_address(sect_last); NODE_DBG("sect_first: %x, sect_last: %x\n", sect_first, sect_last); while( sect_first <= sect_last ) diff --git a/app/wofs/romfs.c b/app/wofs/romfs.c index 41faad05..75558d63 100644 --- a/app/wofs/romfs.c +++ b/app/wofs/romfs.c @@ -521,7 +521,7 @@ int romfs_init( void ) #if defined( BUILD_WOFS ) // Get the start address and size of WOFS and register it wofs_fsdata.pbase = ( uint8_t* )platform_flash_get_first_free_block_address( NULL ); - wofs_fsdata.max_size = INTERNAL_FLASH_SIZE - ( ( uint32_t )wofs_fsdata.pbase - INTERNAL_FLASH_START_ADDRESS ); + wofs_fsdata.max_size = INTERNAL_FLASH_SIZE - ( ( uint32_t )wofs_fsdata.pbase ); NODE_DBG("wofs.pbase:%x,max:%x\n",wofs_fsdata.pbase,wofs_fsdata.max_size); #endif // ifdef BUILD_WOFS return 0; From d84a24fc9a4758c5f0154d994c3335b2fbfea49d Mon Sep 17 00:00:00 2001 From: Johny Mattsson Date: Tue, 8 Dec 2015 10:25:05 +1100 Subject: [PATCH 25/39] Proper cached-flash to phys address translation. --- app/platform/common.c | 2 +- app/platform/cpu_esp8266.h | 5 +++++ app/platform/platform.c | 11 +++++++++++ app/platform/platform.h | 10 ++++++++++ 4 files changed, 27 insertions(+), 1 deletion(-) diff --git a/app/platform/common.c b/app/platform/common.c index bb10fb45..a977c30c 100644 --- a/app/platform/common.c +++ b/app/platform/common.c @@ -149,7 +149,7 @@ uint32_t platform_flash_get_first_free_block_address( uint32_t *psect ) uint32_t start, end, sect; NODE_DBG("_flash_used_end:%08x\n", (uint32_t)_flash_used_end); if(_flash_used_end>0){ // find the used sector - sect = flashh_find_sector( ( uint32_t )_flash_used_end - INTERNAL_FLASH_MAPPED_ADDRESS - 1, NULL, &end ); + sect = flashh_find_sector( platform_flash_mapped2phys ( (uint32_t)_flash_used_end - 1), NULL, &end ); if( psect ) *psect = sect + 1; return end + 1; diff --git a/app/platform/cpu_esp8266.h b/app/platform/cpu_esp8266.h index ef618dea..20e01015 100644 --- a/app/platform/cpu_esp8266.h +++ b/app/platform/cpu_esp8266.h @@ -68,4 +68,9 @@ #define flash_read spi_flash_read #endif // defined(FLASH_SAFE_API) +#define CACHE_FLASH_CTRL_REG 0x3ff0000c +#define CACHE_FLASH_ACTIVE 0x00000100 +#define CACHE_FLASH_MAPPED0 0x02000000 +#define CACHE_FLASH_MAPPED1 0x00010000 + #endif // #ifndef __CPU_ESP8266_H__ diff --git a/app/platform/platform.c b/app/platform/platform.c index 1a45d5b1..95fa2fc9 100755 --- a/app/platform/platform.c +++ b/app/platform/platform.c @@ -579,3 +579,14 @@ int platform_flash_erase_sector( uint32_t sector_id ) system_soft_wdt_feed (); return flash_erase( sector_id ) == SPI_FLASH_RESULT_OK ? PLATFORM_OK : PLATFORM_ERR; } + +uint32_t platform_flash_mapped2phys (uint32_t mapped_addr) +{ + uint32_t cache_ctrl = READ_PERI_REG(CACHE_FLASH_CTRL_REG); + if (!(cache_ctrl & CACHE_FLASH_ACTIVE)) + return -1; + bool b0 = (cache_ctrl & CACHE_FLASH_MAPPED0) ? 1 : 0; + bool b1 = (cache_ctrl & CACHE_FLASH_MAPPED1) ? 1 : 0; + uint32_t meg = (b1 << 1) | b0; + return mapped_addr - INTERNAL_FLASH_MAPPED_ADDRESS + meg * 0x100000; +} diff --git a/app/platform/platform.h b/app/platform/platform.h index b4d3a00a..47f0b5a7 100644 --- a/app/platform/platform.h +++ b/app/platform/platform.h @@ -237,6 +237,16 @@ uint32_t platform_s_flash_read( void *to, uint32_t fromaddr, uint32_t size ); uint32_t platform_flash_get_num_sectors(void); int platform_flash_erase_sector( uint32_t sector_id ); +/** + * Translated a mapped address to a physical flash address, based on the + * current flash cache mapping. + * @param mapped_addr Address to translate (>= INTERNAL_FLASH_MAPPED_ADDRESS) + * @return the corresponding physical flash address, or -1 if flash cache is + * not currently active. + * @see Cache_Read_Enable. + */ +uint32_t platform_flash_mapped2phys (uint32_t mapped_addr); + // ***************************************************************************** // Allocator support From 6b6456be478e8b72d7a5af2ae1f375ae8d85151e Mon Sep 17 00:00:00 2001 From: Johny Mattsson Date: Sat, 12 Dec 2015 14:27:31 +1100 Subject: [PATCH 26/39] Major cleanup of module registration. As per #810 & #796, only LUA_OPTIMIZE_MEMORY=2 & MIN_OPT_LEVEL=2 are supported when building. This commit effects that limitation. With this change modules/auxmods.h no longer needs to be updated for every new module, nor do module writers need to cater for a hypothetical LUA_OPTIMIZE_MEMORY < 2 scenario. --- app/Makefile | 4 +- app/lua/lbaselib.c | 1 + app/lua/ldblib.c | 1 + app/lua/liolib.c | 1 + app/lua/lmathlib.c | 1 + app/lua/loadlib.c | 1 + app/lua/lstrlib.c | 1 + app/lua/ltablib.c | 1 + app/lua/luac_cross/loslib.c | 1 + app/modules/adc.c | 16 +----- app/modules/auxmods.h | 98 ------------------------------------- app/modules/bit.c | 9 +--- app/modules/bmp085.c | 9 +--- app/modules/cjson.c | 18 +------ app/modules/coap.c | 55 +-------------------- app/modules/crypto.c | 18 +------ app/modules/dht.c | 15 +----- app/modules/enduser_setup.c | 9 +--- app/modules/file.c | 18 +------ app/modules/gpio.c | 28 +---------- app/modules/hx711.c | 9 +--- app/modules/i2c.c | 20 +------- app/modules/mqtt.c | 35 +------------ app/modules/net.c | 60 +---------------------- app/modules/node.c | 17 +------ app/modules/ow.c | 17 +------ app/modules/pwm.c | 14 +----- app/modules/rc.c | 10 ++-- app/modules/rtcfifo.c | 8 +-- app/modules/rtcmem.c | 8 +-- app/modules/rtctime.c | 8 +-- app/modules/sntp.c | 8 +-- app/modules/spi.c | 25 +--------- app/modules/tmr.c | 16 ------ app/modules/tsl2561.c | 9 +--- app/modules/u8g.c | 50 +------------------ app/modules/uart.c | 17 +------ app/modules/ucg.c | 50 +------------------ app/modules/wifi.c | 59 +--------------------- app/modules/ws2801.c | 9 +--- app/modules/ws2812.c | 9 +--- 41 files changed, 52 insertions(+), 711 deletions(-) diff --git a/app/Makefile b/app/Makefile index bc0bfa9e..62819e9d 100644 --- a/app/Makefile +++ b/app/Makefile @@ -134,9 +134,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) \ diff --git a/app/lua/lbaselib.c b/app/lua/lbaselib.c index 7c05a6ea..02dad463 100644 --- a/app/lua/lbaselib.c +++ b/app/lua/lbaselib.c @@ -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[] = { diff --git a/app/lua/ldblib.c b/app/lua/ldblib.c index c9eaa644..10978970 100644 --- a/app/lua/ldblib.c +++ b/app/lua/ldblib.c @@ -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[] = { diff --git a/app/lua/liolib.c b/app/lua/liolib.c index b6e377ff..654dd6fa 100644 --- a/app/lua/liolib.c +++ b/app/lua/liolib.c @@ -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 diff --git a/app/lua/lmathlib.c b/app/lua/lmathlib.c index 42ab2b8a..e3fda445 100644 --- a/app/lua/lmathlib.c +++ b/app/lua/lmathlib.c @@ -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[] = { diff --git a/app/lua/loadlib.c b/app/lua/loadlib.c index 00e8f8dd..6a0aaf17 100644 --- a/app/lua/loadlib.c +++ b/app/lua/loadlib.c @@ -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[] = { diff --git a/app/lua/lstrlib.c b/app/lua/lstrlib.c index 58f702ac..4271c282 100644 --- a/app/lua/lstrlib.c +++ b/app/lua/lstrlib.c @@ -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[] = { diff --git a/app/lua/ltablib.c b/app/lua/ltablib.c index a7182b00..8b0a810b 100644 --- a/app/lua/ltablib.c +++ b/app/lua/ltablib.c @@ -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[] = { diff --git a/app/lua/luac_cross/loslib.c b/app/lua/luac_cross/loslib.c index 5bff693b..a35d2941 100644 --- a/app/lua/luac_cross/loslib.c +++ b/app/lua/luac_cross/loslib.c @@ -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[] = { diff --git a/app/modules/adc.c b/app/modules/adc.c index 2c646870..a0d24870 100644 --- a/app/modules/adc.c +++ b/app/modules/adc.c @@ -1,11 +1,9 @@ // Module for interfacing with adc -//#include "lua.h" -#include "lualib.h" #include "lauxlib.h" #include "platform.h" #include "auxmods.h" -#include "lrotable.h" +#include "lrodefs.h" #include "c_types.h" #include "user_interface.h" @@ -28,26 +26,14 @@ 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 ) }, { 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 } diff --git a/app/modules/auxmods.h b/app/modules/auxmods.h index 602da99a..12a67f41 100644 --- a/app/modules/auxmods.h +++ b/app/modules/auxmods.h @@ -5,95 +5,6 @@ #ifndef __AUXMODS_H__ #define __AUXMODS_H__ -#include "lua.h" - -#define AUXLIB_GPIO "gpio" -LUALIB_API int ( luaopen_gpio )( lua_State *L ); - -#define AUXLIB_SPI "spi" -LUALIB_API int ( luaopen_spi )( lua_State *L ); - -#define AUXLIB_CAN "can" -LUALIB_API int ( luaopen_can )( lua_State *L ); - -#define AUXLIB_TMR "tmr" -LUALIB_API int ( luaopen_tmr )( lua_State *L ); - -#define AUXLIB_PD "pd" -LUALIB_API int ( luaopen_pd )( lua_State *L ); - -#define AUXLIB_UART "uart" -LUALIB_API int ( luaopen_uart )( lua_State *L ); - -#define AUXLIB_TERM "term" -LUALIB_API int ( luaopen_term )( lua_State *L ); - -#define AUXLIB_PWM "pwm" -LUALIB_API int ( luaopen_pwm )( lua_State *L ); - -#define AUXLIB_PACK "pack" -LUALIB_API int ( luaopen_pack )( lua_State *L ); - -#define AUXLIB_BIT "bit" -LUALIB_API int ( luaopen_bit )( lua_State *L ); - -#define AUXLIB_NET "net" -LUALIB_API int ( luaopen_net )( lua_State *L ); - -#define AUXLIB_CPU "cpu" -LUALIB_API int ( luaopen_cpu )( lua_State* L ); - -#define AUXLIB_ADC "adc" -LUALIB_API int ( luaopen_adc )( lua_State *L ); - -#define AUXLIB_RPC "rpc" -LUALIB_API int ( luaopen_rpc )( lua_State *L ); - -#define AUXLIB_BITARRAY "bitarray" -LUALIB_API int ( luaopen_bitarray )( lua_State *L ); - -#define AUXLIB_ELUA "elua" -LUALIB_API int ( luaopen_elua )( lua_State *L ); - -#define AUXLIB_I2C "i2c" -LUALIB_API int ( luaopen_i2c )( lua_State *L ); - -#define AUXLIB_WIFI "wifi" -LUALIB_API int ( luaopen_wifi )( lua_State *L ); - -#define AUXLIB_COAP "coap" -LUALIB_API int ( luaopen_coap )( lua_State *L ); - -#define AUXLIB_MQTT "mqtt" -LUALIB_API int ( luaopen_mqtt )( lua_State *L ); - -#define AUXLIB_U8G "u8g" -LUALIB_API int ( luaopen_u8g )( lua_State *L ); - -#define AUXLIB_UCG "ucg" -LUALIB_API int ( luaopen_ucg )( lua_State *L ); - -#define AUXLIB_NODE "node" -LUALIB_API int ( luaopen_node )( lua_State *L ); - -#define AUXLIB_FILE "file" -LUALIB_API int ( luaopen_file )( lua_State *L ); - -#define AUXLIB_OW "ow" -LUALIB_API int ( luaopen_ow )( lua_State *L ); - -#define AUXLIB_CJSON "cjson" -LUALIB_API int ( luaopen_cjson )( lua_State *L ); - -#define AUXLIB_CRYPTO "crypto" -LUALIB_API int ( luaopen_crypto )( lua_State *L ); - -#define AUXLIB_RC "rc" -LUALIB_API int ( luaopen_rc )( lua_State *L ); - -#define AUXLIB_DHT "dht" -LUALIB_API int ( luaopen_dht )( lua_State *L ); - // Helper macros #define MOD_CHECK_ID( mod, id )\ if( !platform_ ## mod ## _exists( id ) )\ @@ -109,13 +20,4 @@ LUALIB_API int ( luaopen_dht )( lua_State *L ); if( !platform_ ## mod ## _check_ ## resmod ## _id( id, resid ) )\ return luaL_error( L, #resmod" %d not valid with " #mod " %d", ( unsigned )resid, ( unsigned )id ) -#define MOD_REG_NUMBER( L, name, val )\ - lua_pushnumber( L, val );\ - lua_setfield( L, -2, name ) - -#define MOD_REG_LUDATA( L, name, val )\ - lua_pushlightuserdata( L, val );\ - lua_setfield( L, -2, name ) - #endif - diff --git a/app/modules/bit.c b/app/modules/bit.c index ac2d19ba..31ae96d3 100644 --- a/app/modules/bit.c +++ b/app/modules/bit.c @@ -7,11 +7,8 @@ #include "c_limits.h" -//#include "lua.h" #include "lauxlib.h" -#include "auxmods.h" -// #include "type.h" -#include "lrotable.h" +#include "lrodefs.h" /* FIXME: Assume size_t is an unsigned lua_Integer */ typedef size_t lua_UInteger; @@ -122,8 +119,6 @@ static int bit_clear( lua_State* L ) return 1; } -#define MIN_OPT_LEVEL 2 -#include "lrodefs.h" const LUA_REG_TYPE bit_map[] = { { LSTRKEY( "bnot" ), LFUNCVAL( bit_bnot ) }, { LSTRKEY( "band" ), LFUNCVAL( bit_band ) }, @@ -141,5 +136,5 @@ const LUA_REG_TYPE bit_map[] = { }; LUALIB_API int luaopen_bit (lua_State *L) { - LREGISTER( L, "bit", bit_map ); + return 0; } diff --git a/app/modules/bmp085.c b/app/modules/bmp085.c index 31b7d6af..d75379e8 100644 --- a/app/modules/bmp085.c +++ b/app/modules/bmp085.c @@ -1,8 +1,6 @@ -#include "lualib.h" #include "lauxlib.h" #include "platform.h" -#include "auxmods.h" -#include "lrotable.h" +#include "lrodefs.h" #include "c_stdlib.h" #include "c_string.h" @@ -185,8 +183,6 @@ static int ICACHE_FLASH_ATTR bmp085_lua_pressure(lua_State* L) { return 1; } -#define MIN_OPT_LEVEL 2 -#include "lrodefs.h" const LUA_REG_TYPE bmp085_map[] = { { LSTRKEY( "temperature" ), LFUNCVAL( bmp085_lua_temperature )}, @@ -197,7 +193,6 @@ const LUA_REG_TYPE bmp085_map[] = }; LUALIB_API int luaopen_bmp085(lua_State *L) { - LREGISTER(L, "bmp085", bmp085_map); - return 1; + return 0; } diff --git a/app/modules/cjson.c b/app/modules/cjson.c index 2fb10c6c..73a49dbf 100644 --- a/app/modules/cjson.c +++ b/app/modules/cjson.c @@ -40,8 +40,8 @@ #include "c_string.h" #include "c_math.h" #include "c_limits.h" -#include "lua.h" #include "lauxlib.h" +#include "lrodefs.h" #include "flash_api.h" #include "strbuf.h" @@ -1531,8 +1531,6 @@ static int json_protect_conversion(lua_State *l) #endif // Module function map -#define MIN_OPT_LEVEL 2 -#include "lrodefs.h" const LUA_REG_TYPE cjson_map[] = { { LSTRKEY( "encode" ), LFUNCVAL( json_encode ) }, @@ -1545,9 +1543,6 @@ const LUA_REG_TYPE cjson_map[] = // { 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 ) }, -#if LUA_OPTIMIZE_MEMORY > 0 - -#endif { LNILKEY, LNILVAL } }; @@ -1560,18 +1555,7 @@ LUALIB_API int luaopen_cjson( lua_State *L ) if(-1==cfg_init(&_cfg)){ return luaL_error(L, "BUG: Unable to init config for cjson");; } -#if LUA_OPTIMIZE_MEMORY > 0 return 0; -#else // #if LUA_OPTIMIZE_MEMORY > 0 - luaL_register( L, AUXLIB_CJSON, cjson_map ); - // Add constants - /* Set cjson.null */ - lua_pushlightuserdata(l, NULL); - lua_setfield(l, -2, "null"); - - /* Return cjson table */ - return 1; -#endif // #if LUA_OPTIMIZE_MEMORY > 0 } #if 0 diff --git a/app/modules/coap.c b/app/modules/coap.c index 72502ebc..6da5cb4f 100644 --- a/app/modules/coap.c +++ b/app/modules/coap.c @@ -1,11 +1,8 @@ // Module for coapwork -//#include "lua.h" -#include "lualib.h" #include "lauxlib.h" #include "platform.h" -#include "auxmods.h" -#include "lrotable.h" +#include "lrodefs.h" #include "c_string.h" #include "c_stdlib.h" @@ -561,8 +558,6 @@ static int coap_client_delete( lua_State* L ) } // Module function map -#define MIN_OPT_LEVEL 2 -#include "lrodefs.h" static const LUA_REG_TYPE coap_server_map[] = { { LSTRKEY( "listen" ), LFUNCVAL ( coap_server_listen ) }, @@ -570,9 +565,7 @@ static const LUA_REG_TYPE coap_server_map[] = { LSTRKEY( "var" ), LFUNCVAL ( coap_server_var ) }, { LSTRKEY( "func" ), LFUNCVAL ( coap_server_func ) }, { LSTRKEY( "__gc" ), LFUNCVAL ( coap_server_delete ) }, -#if LUA_OPTIMIZE_MEMORY > 0 { LSTRKEY( "__index" ), LROVAL ( coap_server_map ) }, -#endif { LNILKEY, LNILVAL } }; @@ -583,9 +576,7 @@ static const LUA_REG_TYPE coap_client_map[] = { LSTRKEY( "put" ), LFUNCVAL ( coap_client_put ) }, { LSTRKEY( "delete" ), LFUNCVAL ( coap_client_delete ) }, { LSTRKEY( "__gc" ), LFUNCVAL ( coap_client_gcdelete ) }, -#if LUA_OPTIMIZE_MEMORY > 0 { LSTRKEY( "__index" ), LROVAL ( coap_client_map ) }, -#endif { LNILKEY, LNILVAL } }; @@ -593,7 +584,6 @@ const LUA_REG_TYPE coap_map[] = { { LSTRKEY( "Server" ), LFUNCVAL ( coap_createServer ) }, { LSTRKEY( "Client" ), LFUNCVAL ( coap_createClient ) }, -#if LUA_OPTIMIZE_MEMORY > 0 { LSTRKEY( "CON" ), LNUMVAL( COAP_TYPE_CON ) }, { LSTRKEY( "NON" ), LNUMVAL( COAP_TYPE_NONCON ) }, { LSTRKEY( "TEXT_PLAIN"), LNUMVAL( COAP_CONTENTTYPE_TEXT_PLAIN ) }, @@ -604,56 +594,13 @@ const LUA_REG_TYPE coap_map[] = { LSTRKEY( "JSON"), LNUMVAL( COAP_CONTENTTYPE_APPLICATION_JSON) }, { LSTRKEY( "__metatable" ), LROVAL( coap_map ) }, -#endif { LNILKEY, LNILVAL } }; LUALIB_API int luaopen_coap( lua_State *L ) { endpoint_setup(); -#if LUA_OPTIMIZE_MEMORY > 0 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 return 0; -#else // #if LUA_OPTIMIZE_MEMORY > 0 - int n; - luaL_register( L, AUXLIB_COAP, coap_map ); - - // Set it as its own metatable - lua_pushvalue( L, -1 ); - lua_setmetatable( L, -2 ); - - // Module constants - MOD_REG_NUMBER( L, "CON", COAP_TYPE_CON ); - MOD_REG_NUMBER( L, "NON", COAP_TYPE_NONCON ); - MOD_REG_NUMBER( L, "TEXT_PLAIN", COAP_CONTENTTYPE_TEXT_PLAIN ); - MOD_REG_NUMBER( L, "LINKFORMAT", COAP_CONTENTTYPE_APPLICATION_LINKFORMAT ); - MOD_REG_NUMBER( L, "XML", COAP_CONTENTTYPE_APPLICATION_XML); - MOD_REG_NUMBER( L, "OCTET_STREAM", COAP_CONTENTTYPE_APPLICATION_OCTET_STREAM); - MOD_REG_NUMBER( L, "EXI", COAP_CONTENTTYPE_APPLICATION_EXI); - MOD_REG_NUMBER( L, "JSON", COAP_CONTENTTYPE_APPLICATION_JSON); - - n = lua_gettop(L); - - // create metatable - luaL_newmetatable(L, "coap_server"); - // metatable.__index = metatable - lua_pushliteral(L, "__index"); - lua_pushvalue(L,-2); - lua_rawset(L,-3); - // Setup the methods inside metatable - luaL_register( L, NULL, coap_server_map ); - - lua_settop(L, n); - // create metatable - luaL_newmetatable(L, "coap_client"); - // metatable.__index = metatable - lua_pushliteral(L, "__index"); - lua_pushvalue(L,-2); - lua_rawset(L,-3); - // Setup the methods inside metatable - luaL_register( L, NULL, coap_client_map ); - - return 1; -#endif // #if LUA_OPTIMIZE_MEMORY > 0 } diff --git a/app/modules/crypto.c b/app/modules/crypto.c index 3639e436..7557dd14 100644 --- a/app/modules/crypto.c +++ b/app/modules/crypto.c @@ -1,11 +1,8 @@ // Module for cryptography -//#include "lua.h" -#include "lualib.h" #include "lauxlib.h" #include "platform.h" -#include "auxmods.h" -#include "lrotable.h" +#include "lrodefs.h" #include "c_types.h" #include "c_stdlib.h" #include "../crypto/digests.h" @@ -153,8 +150,6 @@ static int crypto_lhmac (lua_State *L) // Module function map -#define MIN_OPT_LEVEL 2 -#include "lrodefs.h" const LUA_REG_TYPE crypto_map[] = { { LSTRKEY( "sha1" ), LFUNCVAL( crypto_sha1 ) }, @@ -163,21 +158,10 @@ const LUA_REG_TYPE crypto_map[] = { LSTRKEY( "mask" ), LFUNCVAL( crypto_mask ) }, { LSTRKEY( "hash" ), LFUNCVAL( crypto_lhash ) }, { LSTRKEY( "hmac" ), LFUNCVAL( crypto_lhmac ) }, - -#if LUA_OPTIMIZE_MEMORY > 0 - -#endif { LNILKEY, LNILVAL } }; LUALIB_API int luaopen_crypto( lua_State *L ) { -#if LUA_OPTIMIZE_MEMORY > 0 return 0; -#else // #if LUA_OPTIMIZE_MEMORY > 0 - luaL_register( L, AUXLIB_CRYPTO, crypto_map ); - // Add constants - - return 1; -#endif // #if LUA_OPTIMIZE_MEMORY > 0 } diff --git a/app/modules/dht.c b/app/modules/dht.c index fcbf5fdb..3d7067ec 100644 --- a/app/modules/dht.c +++ b/app/modules/dht.c @@ -1,9 +1,8 @@ // Module for interfacing with the DHTxx sensors (xx = 11-21-22-33-44). -#include "lualib.h" #include "lauxlib.h" #include "auxmods.h" -#include "lrotable.h" +#include "lrodefs.h" #include "cpu_esp8266.h" #include "dht.h" @@ -100,30 +99,18 @@ static int dht_lapi_readxx( lua_State *L ) // } // Module function map -#define MIN_OPT_LEVEL 2 -#include "lrodefs.h" const LUA_REG_TYPE dht_map[] = { { LSTRKEY( "read" ), LFUNCVAL( dht_lapi_read ) }, { LSTRKEY( "read11" ), LFUNCVAL( dht_lapi_read11 ) }, { LSTRKEY( "readxx" ), LFUNCVAL( dht_lapi_readxx ) }, -#if LUA_OPTIMIZE_MEMORY > 0 { LSTRKEY( "OK" ), LNUMVAL( DHTLIB_OK ) }, { LSTRKEY( "ERROR_CHECKSUM" ), LNUMVAL( DHTLIB_ERROR_CHECKSUM ) }, { LSTRKEY( "ERROR_TIMEOUT" ), LNUMVAL( DHTLIB_ERROR_TIMEOUT ) }, -#endif { LNILKEY, LNILVAL } }; LUALIB_API int luaopen_dht( lua_State *L ) { -#if LUA_OPTIMIZE_MEMORY > 0 return 0; -#else // #if LUA_OPTIMIZE_MEMORY > 0 - luaL_register( L, AUXLIB_DHT, dht_map ); - - // Add the constants - - return 1; -#endif // #if LUA_OPTIMIZE_MEMORY > 0 } diff --git a/app/modules/enduser_setup.c b/app/modules/enduser_setup.c index 19825284..d1cb83b5 100644 --- a/app/modules/enduser_setup.c +++ b/app/modules/enduser_setup.c @@ -32,11 +32,9 @@ */ -#include "lualib.h" #include "lauxlib.h" #include "platform.h" -#include "auxmods.h" -#include "lrotable.h" +#include "lrodefs.h" #include "c_stdlib.h" #include "c_string.h" #include "user_interface.h" @@ -929,8 +927,6 @@ static int enduser_setup_stop(lua_State* L) } -#define MIN_OPT_LEVEL 2 -#include "lrodefs.h" const LUA_REG_TYPE enduser_setup_map[] = { { LSTRKEY( "start" ), LFUNCVAL( enduser_setup_start )}, @@ -939,7 +935,6 @@ const LUA_REG_TYPE enduser_setup_map[] = }; LUALIB_API int luaopen_enduser_setup(lua_State *L) { - LREGISTER(L, "enduser_setup", enduser_setup_map); - return 1; + return 0; } diff --git a/app/modules/file.c b/app/modules/file.c index b4a9cfa0..e41e4841 100644 --- a/app/modules/file.c +++ b/app/modules/file.c @@ -1,11 +1,8 @@ // Module for interfacing with file system -#include "lua.h" -#include "lualib.h" #include "lauxlib.h" #include "platform.h" -#include "auxmods.h" -#include "lrotable.h" +#include "lrodefs.h" #include "c_types.h" #include "flash_fs.h" @@ -299,8 +296,6 @@ static int file_writeline( lua_State* L ) } // Module function map -#define MIN_OPT_LEVEL 2 -#include "lrodefs.h" const LUA_REG_TYPE file_map[] = { { LSTRKEY( "list" ), LFUNCVAL( file_list ) }, @@ -319,22 +314,11 @@ const LUA_REG_TYPE file_map[] = // { LSTRKEY( "check" ), LFUNCVAL( file_check ) }, { LSTRKEY( "rename" ), LFUNCVAL( file_rename ) }, { LSTRKEY( "fsinfo" ), LFUNCVAL( file_fsinfo ) }, -#endif - -#if LUA_OPTIMIZE_MEMORY > 0 - #endif { LNILKEY, LNILVAL } }; LUALIB_API int luaopen_file( lua_State *L ) { -#if LUA_OPTIMIZE_MEMORY > 0 return 0; -#else // #if LUA_OPTIMIZE_MEMORY > 0 - luaL_register( L, AUXLIB_FILE, file_map ); - // Add constants - - return 1; -#endif // #if LUA_OPTIMIZE_MEMORY > 0 } diff --git a/app/modules/gpio.c b/app/modules/gpio.c index 69875050..49b1507c 100644 --- a/app/modules/gpio.c +++ b/app/modules/gpio.c @@ -1,11 +1,9 @@ // Module for interfacing with GPIO -//#include "lua.h" -#include "lualib.h" #include "lauxlib.h" -#include "platform.h" #include "auxmods.h" -#include "lrotable.h" +#include "platform.h" +#include "lrodefs.h" #include "c_types.h" #include "c_string.h" @@ -223,8 +221,6 @@ static int lgpio_serout( lua_State* L ) #undef DELAY_TABLE_MAX_LEN // Module function map -#define MIN_OPT_LEVEL 2 -#include "lrodefs.h" const LUA_REG_TYPE gpio_map[] = { { LSTRKEY( "mode" ), LFUNCVAL( lgpio_mode ) }, @@ -233,9 +229,6 @@ const LUA_REG_TYPE gpio_map[] = { LSTRKEY( "serout" ), LFUNCVAL( lgpio_serout ) }, #ifdef GPIO_INTERRUPT_ENABLE { LSTRKEY( "trig" ), LFUNCVAL( lgpio_trig ) }, -#endif -#if LUA_OPTIMIZE_MEMORY > 0 -#ifdef GPIO_INTERRUPT_ENABLE { LSTRKEY( "INT" ), LNUMVAL( INTERRUPT ) }, #endif { LSTRKEY( "OUTPUT" ), LNUMVAL( OUTPUT ) }, @@ -244,7 +237,6 @@ const LUA_REG_TYPE gpio_map[] = { LSTRKEY( "LOW" ), LNUMVAL( LOW ) }, { LSTRKEY( "FLOAT" ), LNUMVAL( FLOAT ) }, { LSTRKEY( "PULLUP" ), LNUMVAL( PULLUP ) }, -#endif { LNILKEY, LNILVAL } }; @@ -257,21 +249,5 @@ LUALIB_API int luaopen_gpio( lua_State *L ) } platform_gpio_init(gpio_intr_callback); #endif - -#if LUA_OPTIMIZE_MEMORY > 0 return 0; -#else // #if LUA_OPTIMIZE_MEMORY > 0 - luaL_register( L, AUXLIB_GPIO, gpio_map ); - // Add constants -#ifdef GPIO_INTERRUPT_ENABLE - MOD_REG_NUMBER( L, "INT", INTERRUPT ); -#endif - MOD_REG_NUMBER( L, "OUTPUT", OUTPUT ); - MOD_REG_NUMBER( L, "INPUT", INPUT ); - MOD_REG_NUMBER( L, "HIGH", HIGH ); - MOD_REG_NUMBER( L, "LOW", LOW ); - MOD_REG_NUMBER( L, "FLOAT", FLOAT ); - MOD_REG_NUMBER( L, "PULLUP", PULLUP ); - return 1; -#endif // #if LUA_OPTIMIZE_MEMORY > 0 } diff --git a/app/modules/hx711.c b/app/modules/hx711.c index e172643b..37e59ad7 100644 --- a/app/modules/hx711.c +++ b/app/modules/hx711.c @@ -1,11 +1,10 @@ // Module for HX711 load cell amplifier // https://learn.sparkfun.com/tutorials/load-cell-amplifier-hx711-breakout-hookup-guide -#include "lualib.h" #include "lauxlib.h" #include "platform.h" #include "auxmods.h" -#include "lrotable.h" +#include "lrodefs.h" #include "c_stdlib.h" #include "c_string.h" #include "user_interface.h" @@ -67,8 +66,6 @@ static int ICACHE_FLASH_ATTR hx711_read(lua_State* L) { return 1; } -#define MIN_OPT_LEVEL 2 -#include "lrodefs.h" const LUA_REG_TYPE hx711_map[] = { { LSTRKEY( "init" ), LFUNCVAL( hx711_init )}, @@ -77,8 +74,6 @@ const LUA_REG_TYPE hx711_map[] = }; LUALIB_API int luaopen_hx711(lua_State *L) { - // TODO: the below todo was inherited from the ws2812 code but is still valid. // TODO: Make sure that the GPIO system is initialized - LREGISTER(L, "hx711", hx711_map); - return 1; + return 0; } diff --git a/app/modules/i2c.c b/app/modules/i2c.c index c231aeec..0b241d2d 100644 --- a/app/modules/i2c.c +++ b/app/modules/i2c.c @@ -1,11 +1,9 @@ // Module for interfacing with the I2C interface -//#include "lua.h" -#include "lualib.h" #include "lauxlib.h" #include "platform.h" #include "auxmods.h" -#include "lrotable.h" +#include "lrodefs.h" // Lua: speed = i2c.setup( id, sda, scl, speed ) static int i2c_setup( lua_State *L ) @@ -143,8 +141,6 @@ static int i2c_read( lua_State *L ) } // Module function map -#define MIN_OPT_LEVEL 2 -#include "lrodefs.h" const LUA_REG_TYPE i2c_map[] = { { LSTRKEY( "setup" ), LFUNCVAL( i2c_setup ) }, @@ -153,29 +149,15 @@ const LUA_REG_TYPE i2c_map[] = { 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 i2c.setup) - // MOD_REG_NUMBER( L, "FAST", PLATFORM_I2C_SPEED_FAST ); - MOD_REG_NUMBER( L, "SLOW", PLATFORM_I2C_SPEED_SLOW ); - MOD_REG_NUMBER( L, "TRANSMITTER", PLATFORM_I2C_DIRECTION_TRANSMITTER ); - MOD_REG_NUMBER( L, "RECEIVER", PLATFORM_I2C_DIRECTION_RECEIVER ); - - return 1; -#endif // #if LUA_OPTIMIZE_MEMORY > 0 } diff --git a/app/modules/mqtt.c b/app/modules/mqtt.c index 0741cb6d..1cf595a9 100644 --- a/app/modules/mqtt.c +++ b/app/modules/mqtt.c @@ -1,11 +1,9 @@ // Module for mqtt -//#include "lua.h" -#include "lualib.h" #include "lauxlib.h" #include "platform.h" #include "auxmods.h" -#include "lrotable.h" +#include "lrodefs.h" #include "c_string.h" #include "c_stdlib.h" @@ -1392,9 +1390,6 @@ static int mqtt_socket_lwt( lua_State* L ) } // Module function map -#define MIN_OPT_LEVEL 2 -#include "lrodefs.h" - static const LUA_REG_TYPE mqtt_socket_map[] = { { LSTRKEY( "connect" ), LFUNCVAL ( mqtt_socket_connect ) }, @@ -1404,47 +1399,19 @@ static const LUA_REG_TYPE mqtt_socket_map[] = { LSTRKEY( "lwt" ), LFUNCVAL ( mqtt_socket_lwt ) }, { LSTRKEY( "on" ), LFUNCVAL ( mqtt_socket_on ) }, { LSTRKEY( "__gc" ), LFUNCVAL ( mqtt_delete ) }, -#if LUA_OPTIMIZE_MEMORY > 0 { LSTRKEY( "__index" ), LROVAL ( mqtt_socket_map ) }, -#endif { LNILKEY, LNILVAL } }; const LUA_REG_TYPE mqtt_map[] = { { LSTRKEY( "Client" ), LFUNCVAL ( mqtt_socket_client ) }, -#if LUA_OPTIMIZE_MEMORY > 0 - { LSTRKEY( "__metatable" ), LROVAL( mqtt_map ) }, -#endif { LNILKEY, LNILVAL } }; LUALIB_API int luaopen_mqtt( lua_State *L ) { -#if LUA_OPTIMIZE_MEMORY > 0 luaL_rometatable(L, "mqtt.socket", (void *)mqtt_socket_map); // create metatable for mqtt.socket return 0; -#else // #if LUA_OPTIMIZE_MEMORY > 0 - int n; - luaL_register( L, AUXLIB_MQTT, mqtt_map ); - - // Set it as its own metatable - lua_pushvalue( L, -1 ); - lua_setmetatable( L, -2 ); - - // Module constants - // MOD_REG_NUMBER( L, "TCP", TCP ); - - // create metatable - luaL_newmetatable(L, "mqtt.socket"); - // metatable.__index = metatable - lua_pushliteral(L, "__index"); - lua_pushvalue(L,-2); - lua_rawset(L,-3); - // Setup the methods inside metatable - luaL_register( L, NULL, mqtt_socket_map ); - - return 1; -#endif // #if LUA_OPTIMIZE_MEMORY > 0 } diff --git a/app/modules/net.c b/app/modules/net.c index 73afe2b3..6aeed291 100644 --- a/app/modules/net.c +++ b/app/modules/net.c @@ -1,11 +1,9 @@ // Module for network -//#include "lua.h" -#include "lualib.h" #include "lauxlib.h" #include "platform.h" #include "auxmods.h" -#include "lrotable.h" +#include "lrodefs.h" #include "c_string.h" #include "c_stdlib.h" @@ -1508,8 +1506,6 @@ static int expose_array(lua_State* L, char *array, unsigned short len) { #endif // Module function map -#define MIN_OPT_LEVEL 2 -#include "lrodefs.h" static const LUA_REG_TYPE net_server_map[] = { { LSTRKEY( "listen" ), LFUNCVAL ( net_server_listen ) }, @@ -1518,9 +1514,7 @@ static const LUA_REG_TYPE net_server_map[] = { LSTRKEY( "send" ), LFUNCVAL ( net_udpserver_send ) }, // { LSTRKEY( "delete" ), LFUNCVAL ( net_server_delete ) }, { LSTRKEY( "__gc" ), LFUNCVAL ( net_server_delete ) }, -#if LUA_OPTIMIZE_MEMORY > 0 { LSTRKEY( "__index" ), LROVAL ( net_server_map ) }, -#endif { LNILKEY, LNILVAL } }; @@ -1536,9 +1530,7 @@ static const LUA_REG_TYPE net_socket_map[] = { LSTRKEY( "getpeer" ), LFUNCVAL ( net_socket_getpeer ) }, // { LSTRKEY( "delete" ), LFUNCVAL ( net_socket_delete ) }, { LSTRKEY( "__gc" ), LFUNCVAL ( net_socket_delete ) }, -#if LUA_OPTIMIZE_MEMORY > 0 { LSTRKEY( "__index" ), LROVAL ( net_socket_map ) }, -#endif { LNILKEY, LNILVAL } }; #if 0 @@ -1564,13 +1556,11 @@ const LUA_REG_TYPE net_map[] = { LSTRKEY( "createConnection" ), LFUNCVAL ( net_createConnection ) }, { LSTRKEY( "multicastJoin"), LFUNCVAL( net_multicastJoin ) }, { LSTRKEY( "multicastLeave"), LFUNCVAL( net_multicastLeave ) }, -#if LUA_OPTIMIZE_MEMORY > 0 { LSTRKEY( "dns" ), LROVAL( net_dns_map ) }, { LSTRKEY( "TCP" ), LNUMVAL( TCP ) }, { LSTRKEY( "UDP" ), LNUMVAL( UDP ) }, { LSTRKEY( "__metatable" ), LROVAL( net_map ) }, -#endif { LNILKEY, LNILVAL } }; @@ -1582,58 +1572,10 @@ LUALIB_API int luaopen_net( lua_State *L ) socket[i] = LUA_NOREF; } -#if LUA_OPTIMIZE_MEMORY > 0 luaL_rometatable(L, "net.server", (void *)net_server_map); // create metatable for net.server luaL_rometatable(L, "net.socket", (void *)net_socket_map); // create metatable for net.socket #if 0 luaL_rometatable(L, "net.array", (void *)net_array_map); // create metatable for net.array #endif return 0; -#else // #if LUA_OPTIMIZE_MEMORY > 0 - int n; - luaL_register( L, AUXLIB_NET, net_map ); - - // Set it as its own metatable - lua_pushvalue( L, -1 ); - lua_setmetatable( L, -2 ); - - // Module constants - MOD_REG_NUMBER( L, "TCP", TCP ); - MOD_REG_NUMBER( L, "UDP", UDP ); - - n = lua_gettop(L); - - // create metatable - luaL_newmetatable(L, "net.server"); - // metatable.__index = metatable - lua_pushliteral(L, "__index"); - lua_pushvalue(L,-2); - lua_rawset(L,-3); - // Setup the methods inside metatable - luaL_register( L, NULL, net_server_map ); - - lua_settop(L, n); - // create metatable - luaL_newmetatable(L, "net.socket"); - // metatable.__index = metatable - lua_pushliteral(L, "__index"); - lua_pushvalue(L,-2); - lua_rawset(L,-3); - // Setup the methods inside metatable - luaL_register( L, NULL, net_socket_map ); -#if 0 - lua_settop(L, n); - // create metatable - luaL_newmetatable(L, "net.array"); - // Setup the methods inside metatable - luaL_register( L, NULL, net_array_map ); -#endif - - lua_settop(L, n); - lua_newtable( L ); - luaL_register( L, NULL, net_dns_map ); - lua_setfield( L, -2, "dns" ); - - return 1; -#endif // #if LUA_OPTIMIZE_MEMORY > 0 } diff --git a/app/modules/node.c b/app/modules/node.c index d3154746..2b4869c9 100644 --- a/app/modules/node.c +++ b/app/modules/node.c @@ -1,6 +1,5 @@ // Module for interfacing with system -#include "lua.h" #include "lauxlib.h" #include "ldebug.h" @@ -15,14 +14,12 @@ #include "lundump.h" #include "platform.h" -#include "auxmods.h" -#include "lrotable.h" +#include "lrodefs.h" #include "c_types.h" #include "romfs.h" #include "c_string.h" #include "driver/uart.h" -//#include "spi_flash.h" #include "user_interface.h" #include "flash_api.h" #include "flash_fs.h" @@ -550,8 +547,6 @@ static int node_stripdebug (lua_State *L) { #endif // Module function map -#define MIN_OPT_LEVEL 2 -#include "lrodefs.h" const LUA_REG_TYPE node_map[] = { { LSTRKEY( "restart" ), LFUNCVAL( node_restart ) }, @@ -581,20 +576,10 @@ const LUA_REG_TYPE node_map[] = // 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 - luaL_register( L, AUXLIB_NODE, node_map ); - // Add constants - - return 1; -#endif // #if LUA_OPTIMIZE_MEMORY > 0 } diff --git a/app/modules/ow.c b/app/modules/ow.c index c9cbfa1a..be92bb6b 100644 --- a/app/modules/ow.c +++ b/app/modules/ow.c @@ -1,10 +1,8 @@ // Module for interfacing with the OneWire interface -//#include "lua.h" -#include "lualib.h" #include "lauxlib.h" #include "auxmods.h" -#include "lrotable.h" +#include "lrodefs.h" #include "driver/onewire.h" // Lua: ow.setup( id ) @@ -282,8 +280,6 @@ static int ow_crc16( lua_State *L ) #endif // Module function map -#define MIN_OPT_LEVEL 2 -#include "lrodefs.h" const LUA_REG_TYPE ow_map[] = { { LSTRKEY( "setup" ), LFUNCVAL( ow_setup ) }, @@ -306,22 +302,11 @@ const LUA_REG_TYPE ow_map[] = { LSTRKEY( "check_crc16" ), LFUNCVAL( ow_check_crc16 ) }, { LSTRKEY( "crc16" ), LFUNCVAL( ow_crc16 ) }, #endif -#endif -#if LUA_OPTIMIZE_MEMORY > 0 - #endif { LNILKEY, LNILVAL } }; LUALIB_API int luaopen_ow( lua_State *L ) { -#if LUA_OPTIMIZE_MEMORY > 0 return 0; -#else // #if LUA_OPTIMIZE_MEMORY > 0 - luaL_register( L, AUXLIB_OW, ow_map ); - - // Add the constants - - return 1; -#endif // #if LUA_OPTIMIZE_MEMORY > 0 } diff --git a/app/modules/pwm.c b/app/modules/pwm.c index fbf29fe4..b88a2dd8 100644 --- a/app/modules/pwm.c +++ b/app/modules/pwm.c @@ -1,11 +1,9 @@ // Module for interfacing with PWM -//#include "lua.h" -#include "lualib.h" #include "lauxlib.h" #include "platform.h" #include "auxmods.h" -#include "lrotable.h" +#include "lrodefs.h" #include "c_types.h" @@ -125,8 +123,6 @@ static int lpwm_getduty( lua_State* L ) } // Module function map -#define MIN_OPT_LEVEL 2 -#include "lrodefs.h" const LUA_REG_TYPE pwm_map[] = { { LSTRKEY( "setup" ), LFUNCVAL( lpwm_setup ) }, @@ -137,18 +133,10 @@ const LUA_REG_TYPE pwm_map[] = { LSTRKEY( "getclock" ), LFUNCVAL( lpwm_getclock ) }, { LSTRKEY( "setduty" ), LFUNCVAL( lpwm_setduty ) }, { LSTRKEY( "getduty" ), LFUNCVAL( lpwm_getduty ) }, -#if LUA_OPTIMIZE_MEMORY > 0 - -#endif { LNILKEY, LNILVAL } }; LUALIB_API int luaopen_pwm( lua_State *L ) { -#if LUA_OPTIMIZE_MEMORY > 0 return 0; -#else // #if LUA_OPTIMIZE_MEMORY > 0 - luaL_register( L, AUXLIB_PWM, pwm_map ); - return 1; -#endif // #if LUA_OPTIMIZE_MEMORY > 0 } diff --git a/app/modules/rc.c b/app/modules/rc.c index 964896c4..24df4a10 100644 --- a/app/modules/rc.c +++ b/app/modules/rc.c @@ -1,8 +1,6 @@ -#include "lualib.h" #include "lauxlib.h" #include "platform.h" -#include "auxmods.h" -#include "lrotable.h" +#include "lrodefs.h" //#include "driver/easygpio.h" //static Ping_Data pingA; #define defPulseLen 185 @@ -80,8 +78,7 @@ static int ICACHE_FLASH_ATTR rc_send(lua_State* L) { return 1; } -#define MIN_OPT_LEVEL 2 -#include "lrodefs.h" + const LUA_REG_TYPE rc_map[] = { { LSTRKEY( "send" ), LFUNCVAL( rc_send )}, @@ -91,6 +88,5 @@ const LUA_REG_TYPE rc_map[] = //LUALIB_API int luaopen_ultra(lua_State *L) { LUALIB_API int luaopen_rc(lua_State *L) { // TODO: Make sure that the GPIO system is initialized - LREGISTER(L, "rc", rc_map); - return 1; + return 0; } diff --git a/app/modules/rtcfifo.c b/app/modules/rtcfifo.c index 20492ffa..c347c635 100644 --- a/app/modules/rtcfifo.c +++ b/app/modules/rtcfifo.c @@ -1,6 +1,7 @@ // Module for RTC sample FIFO storage #include "lauxlib.h" +#include "lrodefs.h" #include "user_modules.h" #include "rtc/rtctime.h" #define RTCTIME_SLEEP_ALIGNED rtctime_deep_sleep_until_aligned_us @@ -164,8 +165,6 @@ static int rtcfifo_dsleep_until_sample (lua_State *L) #endif // Module function map -#define MIN_OPT_LEVEL 2 -#include "lrodefs.h" const LUA_REG_TYPE rtcfifo_map[] = { { LSTRKEY("prepare"), LFUNCVAL(rtcfifo_prepare) }, @@ -183,10 +182,5 @@ const LUA_REG_TYPE rtcfifo_map[] = LUALIB_API int luaopen_rtcfifo (lua_State *L) { -#if LUA_OPTIMIZE_MEMORY > 0 return 0; -#else - luaL_register (L, AUXLIB_RTCFIFO, rtcfifo_map); - return 1; -#endif } diff --git a/app/modules/rtcmem.c b/app/modules/rtcmem.c index 4baa9c68..db03e515 100644 --- a/app/modules/rtcmem.c +++ b/app/modules/rtcmem.c @@ -1,6 +1,7 @@ // Module for RTC user memory access #include "lauxlib.h" +#include "lrodefs.h" #include "rtc/rtcaccess.h" static int rtcmem_read32 (lua_State *L) @@ -40,8 +41,6 @@ static int rtcmem_write32 (lua_State *L) // Module function map -#define MIN_OPT_LEVEL 2 -#include "lrodefs.h" const LUA_REG_TYPE rtcmem_map[] = { { LSTRKEY("read32"), LFUNCVAL(rtcmem_read32) }, @@ -51,10 +50,5 @@ const LUA_REG_TYPE rtcmem_map[] = LUALIB_API int luaopen_rtcmem (lua_State *L) { -#if LUA_OPTIMIZE_MEMORY > 0 return 0; -#else - luaL_register (L, AUXLIB_RTCMEM, rtcmem_map); - return 1; -#endif } diff --git a/app/modules/rtctime.c b/app/modules/rtctime.c index 2ee298dd..fdb223ac 100644 --- a/app/modules/rtctime.c +++ b/app/modules/rtctime.c @@ -1,6 +1,7 @@ // Module for RTC time keeping #include "lauxlib.h" +#include "lrodefs.h" #include "rtc/rtctime_internal.h" #include "rtc/rtctime.h" @@ -115,8 +116,6 @@ static int rtctime_dsleep_aligned (lua_State *L) // Module function map -#define MIN_OPT_LEVEL 2 -#include "lrodefs.h" const LUA_REG_TYPE rtctime_map[] = { { LSTRKEY("set"), LFUNCVAL(rtctime_set) }, @@ -128,10 +127,5 @@ const LUA_REG_TYPE rtctime_map[] = LUALIB_API int luaopen_rtctime (lua_State *L) { -#if LUA_OPTIMIZE_MEMORY > 0 return 0; -#else - luaL_register (L, AUXLIB_RTCTIME, rtctime_map); - return 1; -#endif } diff --git a/app/modules/sntp.c b/app/modules/sntp.c index 0f08301c..3ae5e1a9 100644 --- a/app/modules/sntp.c +++ b/app/modules/sntp.c @@ -34,6 +34,7 @@ // Module for Simple Network Time Protocol (SNTP) #include "lauxlib.h" +#include "lrodefs.h" #include "os_type.h" #include "osapi.h" #include "lwip/udp.h" @@ -375,8 +376,6 @@ error: // Module function map -#define MIN_OPT_LEVEL 2 -#include "lrodefs.h" const LUA_REG_TYPE sntp_map[] = { { LSTRKEY("sync"), LFUNCVAL(sntp_sync) }, @@ -385,10 +384,5 @@ const LUA_REG_TYPE sntp_map[] = LUALIB_API int luaopen_sntp (lua_State *L) { -#if LUA_OPTIMIZE_MEMORY > 0 return 0; -#else - luaL_register (L, AUXLIB_SNTP, sntp_map); - return 1; -#endif } diff --git a/app/modules/spi.c b/app/modules/spi.c index 6074ec82..40e9ee53 100644 --- a/app/modules/spi.c +++ b/app/modules/spi.c @@ -1,11 +1,9 @@ // Module for interfacing with the SPI interface -//#include "lua.h" -#include "lualib.h" #include "lauxlib.h" #include "platform.h" #include "auxmods.h" -#include "lrotable.h" +#include "lrodefs.h" #define SPI_HALFDUPLEX 0 #define SPI_FULLDUPLEX 1 @@ -309,8 +307,6 @@ static int spi_transaction( lua_State *L ) // Module function map -#define MIN_OPT_LEVEL 2 -#include "lrodefs.h" const LUA_REG_TYPE spi_map[] = { { LSTRKEY( "setup" ), LFUNCVAL( spi_setup ) }, @@ -319,7 +315,6 @@ const LUA_REG_TYPE spi_map[] = { LSTRKEY( "set_mosi" ), LFUNCVAL( spi_set_mosi ) }, { LSTRKEY( "get_miso" ), LFUNCVAL( spi_get_miso ) }, { LSTRKEY( "transaction" ), LFUNCVAL( spi_transaction ) }, -#if LUA_OPTIMIZE_MEMORY > 0 { LSTRKEY( "MASTER" ), LNUMVAL( PLATFORM_SPI_MASTER ) }, { LSTRKEY( "SLAVE" ), LNUMVAL( PLATFORM_SPI_SLAVE) }, { LSTRKEY( "CPHA_LOW" ), LNUMVAL( PLATFORM_SPI_CPHA_LOW) }, @@ -329,28 +324,10 @@ const LUA_REG_TYPE spi_map[] = { LSTRKEY( "DATABITS_8" ), LNUMVAL( 8 ) }, { LSTRKEY( "HALFDUPLEX" ), LNUMVAL( SPI_HALFDUPLEX ) }, { LSTRKEY( "FULLDUPLEX" ), LNUMVAL( SPI_FULLDUPLEX ) }, -#endif // #if LUA_OPTIMIZE_MEMORY > 0 { LNILKEY, LNILVAL } }; LUALIB_API int luaopen_spi( lua_State *L ) { -#if LUA_OPTIMIZE_MEMORY > 0 return 0; -#else // #if LUA_OPTIMIZE_MEMORY > 0 - luaL_register( L, AUXLIB_SPI, spi_map ); - - // Add constants - MOD_REG_NUMBER( L, "MASTER", PLATFORM_SPI_MASTER); - MOD_REG_NUMBER( L, "SLAVE", PLATFORM_SPI_SLAVE); - MOD_REG_NUMBER( L, "CPHA_LOW" , PLATFORM_SPI_CPHA_LOW); - MOD_REG_NUMBER( L, "CPHA_HIGH", PLATFORM_SPI_CPHA_HIGH); - MOD_REG_NUMBER( L, "CPOL_LOW" , PLATFORM_SPI_CPOL_LOW); - MOD_REG_NUMBER( L, "CPOL_HIGH", PLATFORM_SPI_CPOL_HIGH); - MOD_REG_NUMBER( L, "DATABITS_8", 8 ); - MOD_REG_NUMBER( L, "HALFDUPLEX", SPI_HALFDUPLEX ); - MOD_REG_NUMBER( L, "FULLDUPLEX", SPI_FULLDUPLEX ); - - return 1; -#endif // #if LUA_OPTIMIZE_MEMORY > 0 } diff --git a/app/modules/tmr.c b/app/modules/tmr.c index cad2e8dd..c49d5169 100755 --- a/app/modules/tmr.c +++ b/app/modules/tmr.c @@ -48,13 +48,9 @@ tmr.softwd(int) the timer units are seconds */ -#define MIN_OPT_LEVEL 2 - -#include "lualib.h" #include "lauxlib.h" #include "platform.h" #include "auxmods.h" -#include "lrotable.h" #include "lrodefs.h" #include "c_types.h" @@ -324,11 +320,9 @@ const LUA_REG_TYPE tmr_map[] = { { LSTRKEY( "unregister" ), LFUNCVAL ( tmr_unregister ) }, { LSTRKEY( "state" ), LFUNCVAL ( tmr_state ) }, { LSTRKEY( "interval" ), LFUNCVAL ( tmr_interval) }, -#if LUA_OPTIMIZE_MEMORY > 0 { LSTRKEY( "ALARM_SINGLE" ), LNUMVAL( TIMER_MODE_SINGLE ) }, { LSTRKEY( "ALARM_SEMI" ), LNUMVAL( TIMER_MODE_SEMI ) }, { LSTRKEY( "ALARM_AUTO" ), LNUMVAL( TIMER_MODE_AUTO ) }, -#endif { LNILKEY, LNILVAL } }; @@ -344,16 +338,6 @@ LUALIB_API int luaopen_tmr( lua_State *L ){ ets_timer_setfn(&rtc_timer, rtc_callback, NULL); ets_timer_arm_new(&rtc_timer, 1000, 1, 1); -#if LUA_OPTIMIZE_MEMORY > 0 return 0; -#else - luaL_register( L, AUXLIB_TMR, tmr_map ); - lua_pushvalue( L, -1 ); - lua_setmetatable( L, -2 ); - MOD_REG_NUMBER( L, "ALARM_SINGLE", TIMER_MODE_SINGLE ); - MOD_REG_NUMBER( L, "ALARM_SEMI", TIMER_MODE_SEMI ); - MOD_REG_NUMBER( L, "ALARM_AUTO", TIMER_MODE_AUTO ); - return 1; -#endif } diff --git a/app/modules/tsl2561.c b/app/modules/tsl2561.c index a0abbb96..6c8fd96c 100644 --- a/app/modules/tsl2561.c +++ b/app/modules/tsl2561.c @@ -4,11 +4,9 @@ * Created on: Aug 21, 2015 * Author: Michael Lucas (Aeprox @github) */ -#include "lualib.h" #include "lauxlib.h" #include "platform.h" -#include "auxmods.h" -#include "lrotable.h" +#include "lrodefs.h" #include "../tsl2561/tsl2561.h" static uint16_t ch0; @@ -102,8 +100,6 @@ static int ICACHE_FLASH_ATTR tsl2561_lua_getchannels(lua_State* L) { return 3; } -#define MIN_OPT_LEVEL 2 -#include "lrodefs.h" const LUA_REG_TYPE tsl2561_map[] = { { LSTRKEY( "settiming" ), LFUNCVAL( tsl2561_lua_settiming)}, @@ -134,6 +130,5 @@ const LUA_REG_TYPE tsl2561_map[] = }; LUALIB_API int luaopen_tsl2561(lua_State *L) { - LREGISTER(L, "tsl2561", tsl2561_map); - return 1; + return 0; } diff --git a/app/modules/u8g.c b/app/modules/u8g.c index 0397e23a..32102f51 100644 --- a/app/modules/u8g.c +++ b/app/modules/u8g.c @@ -1,10 +1,8 @@ // Module for U8glib -#include "lualib.h" #include "lauxlib.h" #include "platform.h" -#include "auxmods.h" -#include "lrotable.h" +#include "lrodefs.h" #include "c_stdlib.h" @@ -1027,9 +1025,6 @@ U8G_DISPLAY_TABLE_SPI // Module function map -#define MIN_OPT_LEVEL 2 -#include "lrodefs.h" - static const LUA_REG_TYPE lu8g_display_map[] = { { LSTRKEY( "begin" ), LFUNCVAL( lu8g_begin ) }, @@ -1083,9 +1078,7 @@ static const LUA_REG_TYPE lu8g_display_map[] = { LSTRKEY( "undoRotation" ), LFUNCVAL( lu8g_undoRotation ) }, { LSTRKEY( "undoScale" ), LFUNCVAL( lu8g_undoScale ) }, { LSTRKEY( "__gc" ), LFUNCVAL( lu8g_close_display ) }, -#if LUA_OPTIMIZE_MEMORY > 0 { LSTRKEY( "__index" ), LROVAL ( lu8g_display_map ) }, -#endif { LNILKEY, LNILVAL } }; @@ -1096,8 +1089,6 @@ const LUA_REG_TYPE lu8g_map[] = U8G_DISPLAY_TABLE_I2C U8G_DISPLAY_TABLE_SPI -#if LUA_OPTIMIZE_MEMORY > 0 - // Register fonts #undef U8G_FONT_TABLE_ENTRY #define U8G_FONT_TABLE_ENTRY(font) { LSTRKEY( #font ), LUDATA( (void *)(u8g_ ## font) ) }, @@ -1115,50 +1106,11 @@ const LUA_REG_TYPE lu8g_map[] = { LSTRKEY( "MODE_GRAY2BIT" ), LNUMVAL( U8G_MODE_GRAY2BIT ) }, { LSTRKEY( "__metatable" ), LROVAL( lu8g_map ) }, -#endif { LNILKEY, LNILVAL } }; LUALIB_API int luaopen_u8g( lua_State *L ) { -#if LUA_OPTIMIZE_MEMORY > 0 luaL_rometatable(L, "u8g.display", (void *)lu8g_display_map); // create metatable return 0; -#else // #if LUA_OPTIMIZE_MEMORY > 0 - int n; - luaL_register( L, AUXLIB_U8G, lu8g_map ); - - // Set it as its own metatable - lua_pushvalue( L, -1 ); - lua_setmetatable( L, -2 ); - - // Module constants - - // Register fonts -#undef U8G_FONT_TABLE_ENTRY -#define U8G_FONT_TABLE_ENTRY(font) MOD_REG_LUDATA( L, #font, (void *)(u8g_ ## font) ); - U8G_FONT_TABLE - - // Options for circle/ ellipse drawing - MOD_REG_NUMBER( L, "DRAW_UPPER_RIGHT", U8G_DRAW_UPPER_RIGHT ); - MOD_REG_NUMBER( L, "DRAW_UPPER_LEFT", U8G_DRAW_UPPER_LEFT ); - MOD_REG_NUMBER( L, "DRAW_LOWER_RIGHT", U8G_DRAW_LOWER_RIGHT ); - MOD_REG_NUMBER( L, "DRAW_LOWER_LEFT", U8G_DRAW_LOWER_LEFT ); - MOD_REG_NUMBER( L, "DRAW_ALL", U8G_DRAW_ALL ); - - // Display modes - MOD_REG_NUMBER( L, "MODE_BW", U8G_MODE_BW ); - MOD_REG_NUMBER( L, "MODE_GRAY2BIT", U8G_MODE_GRAY2BIT ); - - // create metatable - luaL_newmetatable(L, "u8g.display"); - // metatable.__index = metatable - lua_pushliteral(L, "__index"); - lua_pushvalue(L,-2); - lua_rawset(L,-3); - // Setup the methods inside metatable - luaL_register( L, NULL, u8g_display_map ); - - return 1; -#endif // #if LUA_OPTIMIZE_MEMORY > 0 } diff --git a/app/modules/uart.c b/app/modules/uart.c index c4fdcc6f..d5d81bd7 100755 --- a/app/modules/uart.c +++ b/app/modules/uart.c @@ -1,11 +1,9 @@ // Module for interfacing with serial -//#include "lua.h" -#include "lualib.h" #include "lauxlib.h" #include "platform.h" #include "auxmods.h" -#include "lrotable.h" +#include "lrodefs.h" #include "c_types.h" #include "c_string.h" @@ -158,29 +156,16 @@ static int uart_write( lua_State* L ) } // 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( "on" ), LFUNCVAL( uart_on ) }, { LSTRKEY( "alt" ), LFUNCVAL( uart_alt ) }, - -#if LUA_OPTIMIZE_MEMORY > 0 - -#endif { LNILKEY, LNILVAL } }; LUALIB_API int luaopen_uart( lua_State *L ) { -#if LUA_OPTIMIZE_MEMORY > 0 return 0; -#else // #if LUA_OPTIMIZE_MEMORY > 0 - luaL_register( L, AUXLIB_UART, uart_map ); - // Add constants - - return 1; -#endif // #if LUA_OPTIMIZE_MEMORY > 0 } diff --git a/app/modules/ucg.c b/app/modules/ucg.c index 3d51265f..82fc3067 100644 --- a/app/modules/ucg.c +++ b/app/modules/ucg.c @@ -1,10 +1,8 @@ // Module for Ucglib -#include "lualib.h" #include "lauxlib.h" #include "platform.h" -#include "auxmods.h" -#include "lrotable.h" +#include "lrodefs.h" #include "c_stdlib.h" @@ -876,9 +874,6 @@ UCG_DISPLAY_TABLE // Module function map -#define MIN_OPT_LEVEL 2 -#include "lrodefs.h" - static const LUA_REG_TYPE lucg_display_map[] = { { LSTRKEY( "begin" ), LFUNCVAL( lucg_begin ) }, @@ -926,9 +921,7 @@ static const LUA_REG_TYPE lucg_display_map[] = { LSTRKEY( "undoScale" ), LFUNCVAL( lucg_undoScale ) }, { LSTRKEY( "__gc" ), LFUNCVAL( lucg_close_display ) }, -#if LUA_OPTIMIZE_MEMORY > 0 { LSTRKEY( "__index" ), LROVAL ( lucg_display_map ) }, -#endif { LNILKEY, LNILVAL } }; @@ -938,8 +931,6 @@ const LUA_REG_TYPE lucg_map[] = #define UCG_DISPLAY_TABLE_ENTRY(binding, device, extension) { LSTRKEY( #binding ), LFUNCVAL ( lucg_ ##binding ) }, UCG_DISPLAY_TABLE -#if LUA_OPTIMIZE_MEMORY > 0 - // Register fonts #undef UCG_FONT_TABLE_ENTRY #define UCG_FONT_TABLE_ENTRY(font) { LSTRKEY( #font ), LUDATA( (void *)(ucg_ ## font) ) }, @@ -957,50 +948,11 @@ const LUA_REG_TYPE lucg_map[] = { LSTRKEY( "DRAW_ALL" ), LNUMVAL( UCG_DRAW_ALL ) }, { LSTRKEY( "__metatable" ), LROVAL( lucg_map ) }, -#endif { LNILKEY, LNILVAL } }; LUALIB_API int luaopen_ucg( lua_State *L ) { -#if LUA_OPTIMIZE_MEMORY > 0 luaL_rometatable(L, "ucg.display", (void *)lucg_display_map); // create metatable return 0; -#else // #if LUA_OPTIMIZE_MEMORY > 0 - int n; - luaL_register( L, AUXLIB_UCG, lucg_map ); - - // Set it as its own metatable - lua_pushvalue( L, -1 ); - lua_setmetatable( L, -2 ); - - // Module constants - - // Register fonts -#undef UCG_FONT_TABLE_ENTRY -#define UCG_FONT_TABLE_ENTRY(font) MOD_REG_LUDATA( L, #font, (void *)(ucg_ ## font) ); - UCG_FONT_TABLE - - // Font modes - MOD_REG_NUMBER( L, "FONT_MODE_TRANSPARENT", UCG_FONT_MODE_TRANSPARENT ); - MOD_REG_NUMBER( L, "FONT_MODE_SOLID", UCG_FONT_MODE_SOLID ); - - // Options for circle/ disc drawing - MOD_REG_NUMBER( L, "DRAW_UPPER_RIGHT", UCG_DRAW_UPPER_RIGHT ); - MOD_REG_NUMBER( L, "DRAW_UPPER_LEFT", UCG_DRAW_UPPER_LEFT ); - MOD_REG_NUMBER( L, "DRAW_LOWER_RIGHT", UCG_DRAW_LOWER_RIGHT ); - MOD_REG_NUMBER( L, "DRAW_LOWER_LEFT", UCG_DRAW_LOWER_LEFT ); - MOD_REG_NUMBER( L, "DRAW_ALL", UCG_DRAW_ALL ); - - // create metatable - luaL_newmetatable(L, "ucg.display"); - // metatable.__index = metatable - lua_pushliteral(L, "__index"); - lua_pushvalue(L,-2); - lua_rawset(L,-3); - // Setup the methods inside metatable - luaL_register( L, NULL, lucg_display_map ); - - return 1; -#endif // #if LUA_OPTIMIZE_MEMORY > 0 } diff --git a/app/modules/wifi.c b/app/modules/wifi.c index 9d84ce50..2b076b8f 100644 --- a/app/modules/wifi.c +++ b/app/modules/wifi.c @@ -1,11 +1,8 @@ // Module for interfacing with WIFI -//#include "lua.h" -#include "lualib.h" #include "lauxlib.h" #include "platform.h" -#include "auxmods.h" -#include "lrotable.h" +#include "lrodefs.h" #include "c_string.h" #include "c_stdlib.h" @@ -1340,8 +1337,6 @@ static int wifi_ap_dhcp_stop( lua_State* L ) } // Module function map -#define MIN_OPT_LEVEL 2 -#include "lrodefs.h" static const LUA_REG_TYPE wifi_station_map[] = { { LSTRKEY( "getconfig" ), LFUNCVAL ( wifi_station_getconfig ) }, @@ -1380,11 +1375,9 @@ static const LUA_REG_TYPE wifi_ap_map[] = { LSTRKEY( "setmac" ), LFUNCVAL ( wifi_ap_setmac ) }, { LSTRKEY( "getclient" ), LFUNCVAL ( wifi_ap_listclient ) }, { LSTRKEY( "getconfig" ), LFUNCVAL( wifi_ap_getconfig ) }, -#if LUA_OPTIMIZE_MEMORY > 0 { LSTRKEY( "dhcp" ), LROVAL( wifi_ap_dhcp_map ) }, // { LSTRKEY( "__metatable" ), LROVAL( wifi_ap_map ) }, -#endif { LNILKEY, LNILVAL } }; @@ -1399,7 +1392,7 @@ const LUA_REG_TYPE wifi_map[] = { 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 ) }, @@ -1430,58 +1423,10 @@ const LUA_REG_TYPE wifi_map[] = { LSTRKEY( "STA_GOTIP" ), LNUMVAL( STATION_GOT_IP ) }, { LSTRKEY( "__metatable" ), LROVAL( wifi_map ) }, -#endif { LNILKEY, LNILVAL } }; LUALIB_API int luaopen_wifi( lua_State *L ) { -#if LUA_OPTIMIZE_MEMORY > 0 return 0; -#else // #if LUA_OPTIMIZE_MEMORY > 0 - luaL_register( L, AUXLIB_WIFI, wifi_map ); - - // Set it as its own metatable - lua_pushvalue( L, -1 ); - lua_setmetatable( L, -2 ); - - // Module constants - // MOD_REG_NUMBER( L, "NULLMODE", NULL_MODE ); - MOD_REG_NUMBER( L, "STATION", STATION_MODE ); - MOD_REG_NUMBER( L, "SOFTAP", SOFTAP_MODE ); - MOD_REG_NUMBER( L, "STATIONAP", STATIONAP_MODE ); - - MOD_REG_NUMBER( L, "NONE_SLEEP", NONE_SLEEP_T ); - MOD_REG_NUMBER( L, "LIGHT_SLEEP", LIGHT_SLEEP_T ); - MOD_REG_NUMBER( L, "MODEM_SLEEP", MODEM_SLEEP_T ); - - MOD_REG_NUMBER( L, "OPEN", AUTH_OPEN ); - // MOD_REG_NUMBER( L, "WEP", AUTH_WEP ); - MOD_REG_NUMBER( L, "WPA_PSK", AUTH_WPA_PSK ); - MOD_REG_NUMBER( L, "WPA2_PSK", AUTH_WPA2_PSK ); - MOD_REG_NUMBER( L, "WPA_WPA2_PSK", AUTH_WPA_WPA2_PSK ); - - // MOD_REG_NUMBER( L, "STA_IDLE", STATION_IDLE ); - // MOD_REG_NUMBER( L, "STA_CONNECTING", STATION_CONNECTING ); - // MOD_REG_NUMBER( L, "STA_WRONGPWD", STATION_WRONG_PASSWORD ); - // MOD_REG_NUMBER( L, "STA_APNOTFOUND", STATION_NO_AP_FOUND ); - // MOD_REG_NUMBER( L, "STA_FAIL", STATION_CONNECT_FAIL ); - // MOD_REG_NUMBER( L, "STA_GOTIP", STATION_GOT_IP ); - - // Setup the new tables (station and ap) inside wifi - lua_newtable( L ); - luaL_register( L, NULL, wifi_station_map ); - lua_setfield( L, -2, "sta" ); - - lua_newtable( L ); - luaL_register( L, NULL, wifi_ap_map ); - lua_setfield( L, -2, "ap" ); - - // Setup the new table (dhcp) inside ap - lua_newtable( L ); - luaL_register( L, NULL, wifi_ap_dhcp_map ); - lua_setfield( L, -1, "dhcp" ); - - return 1; -#endif // #if LUA_OPTIMIZE_MEMORY > 0 } diff --git a/app/modules/ws2801.c b/app/modules/ws2801.c index 6ba2199e..9fe04c86 100644 --- a/app/modules/ws2801.c +++ b/app/modules/ws2801.c @@ -1,8 +1,6 @@ -#include "lualib.h" #include "lauxlib.h" #include "platform.h" -#include "auxmods.h" -#include "lrotable.h" +#include "lrodefs.h" #include "c_stdlib.h" #include "c_string.h" @@ -124,8 +122,6 @@ static int ICACHE_FLASH_ATTR ws2801_writergb(lua_State* L) { return 0; } -#define MIN_OPT_LEVEL 2 -#include "lrodefs.h" const LUA_REG_TYPE ws2801_map[] = { { LSTRKEY( "write" ), LFUNCVAL( ws2801_writergb )}, @@ -134,7 +130,6 @@ const LUA_REG_TYPE ws2801_map[] = }; LUALIB_API int luaopen_ws2801(lua_State *L) { - LREGISTER(L, "ws2801", ws2801_map); - return 1; + return 0; } diff --git a/app/modules/ws2812.c b/app/modules/ws2812.c index 6875416d..e23a4b95 100644 --- a/app/modules/ws2812.c +++ b/app/modules/ws2812.c @@ -1,8 +1,6 @@ -#include "lualib.h" #include "lauxlib.h" #include "platform.h" -#include "auxmods.h" -#include "lrotable.h" +#include "lrodefs.h" #include "c_stdlib.h" #include "c_string.h" #include "user_interface.h" @@ -127,8 +125,6 @@ static int ICACHE_FLASH_ATTR ws2812_writegrb(lua_State* L) { return 0; } -#define MIN_OPT_LEVEL 2 -#include "lrodefs.h" const LUA_REG_TYPE ws2812_map[] = { { LSTRKEY( "writergb" ), LFUNCVAL( ws2812_writergb )}, @@ -138,6 +134,5 @@ const LUA_REG_TYPE ws2812_map[] = LUALIB_API int luaopen_ws2812(lua_State *L) { // TODO: Make sure that the GPIO system is initialized - LREGISTER(L, "ws2812", ws2812_map); - return 1; + return 0; } From 4b0cec1757c0376f424f8e13f757afe8e9888634 Mon Sep 17 00:00:00 2001 From: Artem Pastukhov Date: Mon, 14 Dec 2015 11:34:11 +0300 Subject: [PATCH 27/39] * Add u8glib readme. --- app/u8glib/README.md | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 app/u8glib/README.md diff --git a/app/u8glib/README.md b/app/u8glib/README.md new file mode 100644 index 00000000..11530966 --- /dev/null +++ b/app/u8glib/README.md @@ -0,0 +1,28 @@ +##U8glib package + +Ported from https://github.com/olikraus/u8glib + + +Here is black magic with ImageMagic package for image conversion: + + + +```bash +#!/bin/bash + +mkdir out + +for icon in *png; do + convert $icon -depth 1 ./out/$(basename $icon .png)_1bpp.png + if [[ "$icon" == *"black"* ]]; then + convert ./out/$(basename $icon .png)_1bpp.png -background white -alpha Background ./out/$(basename $icon .png)_1bpp.xbm + else + convert ./out/$(basename $icon .png)_1bpp.png -background black -alpha Background ./out/$(basename $icon .png)_1bpp.xbm + fi + cat ./out/$(basename $icon .png)_1bpp.xbm | tr '\n' ' ' | tr -d " " |sed -e s'#^.*{##g' | sed s'#,}##' |sed s'/;//' | xxd -r -p > ./out/$(basename $icon .png).xbm.mono +done + +rm out/*png out/*xbm +``` + +It read all the png in the current folder and put resulting mono to ./out/ From 60096023829f60f3ecebd847b064f1f50fcb68e5 Mon Sep 17 00:00:00 2001 From: Artem Pastukhov Date: Mon, 14 Dec 2015 11:41:10 +0300 Subject: [PATCH 28/39] Some polish --- app/u8glib/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/u8glib/README.md b/app/u8glib/README.md index 11530966..07acdf9d 100644 --- a/app/u8glib/README.md +++ b/app/u8glib/README.md @@ -25,4 +25,4 @@ done rm out/*png out/*xbm ``` -It read all the png in the current folder and put resulting mono to ./out/ +Convert all the png in the current folder and put resulting .mono to ./out From 5cb27f89ae434e2df78c52c30422046f2574f773 Mon Sep 17 00:00:00 2001 From: Artem Pastukhov Date: Tue, 15 Dec 2015 09:35:20 +0300 Subject: [PATCH 29/39] Add ImageMagic info. --- app/u8glib/README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/u8glib/README.md b/app/u8glib/README.md index 07acdf9d..ed5598f8 100644 --- a/app/u8glib/README.md +++ b/app/u8glib/README.md @@ -24,5 +24,11 @@ done rm out/*png out/*xbm ``` - Convert all the png in the current folder and put resulting .mono to ./out + +The convert binary is a part of ImageMagic package. You need to install it. + +``` +sudo apt-get install imagemagick +``` +for Debian/Ubuntu. \ No newline at end of file From b773290b8cae175e1d25e1de8319fa78e4a586de Mon Sep 17 00:00:00 2001 From: TerryE Date: Sun, 13 Dec 2015 02:29:37 +0000 Subject: [PATCH 30/39] 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 Date: Wed, 16 Dec 2015 16:04:58 +1100 Subject: [PATCH 31/39] 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. --- app/include/module.h | 74 +++++++++ app/include/user_modules.h | 5 +- app/lua/lrodefs.h | 2 +- app/modules/adc.c | 12 +- app/modules/bit.c | 12 +- app/modules/bmp085.c | 12 +- app/modules/cjson.c | 12 +- app/modules/coap.c | 12 +- app/modules/crypto.c | 12 +- app/modules/dht.c | 12 +- app/modules/enduser_setup.c | 14 +- app/modules/file.c | 12 +- app/modules/gpio.c | 13 +- app/modules/hx711.c | 12 +- app/modules/i2c.c | 13 +- app/modules/linit.c | 119 ++++----------- app/modules/modules.h | 289 ------------------------------------ app/modules/mqtt.c | 12 +- app/modules/net.c | 12 +- app/modules/node.c | 8 +- app/modules/ow.c | 12 +- app/modules/pwm.c | 13 +- app/modules/rc.c | 13 +- app/modules/rtcfifo.c | 13 +- app/modules/rtcmem.c | 12 +- app/modules/rtctime.c | 12 +- app/modules/sntp.c | 12 +- app/modules/spi.c | 12 +- app/modules/tmr.c | 13 +- app/modules/tsl2561.c | 12 +- app/modules/u8g.c | 12 +- app/modules/uart.c | 12 +- app/modules/ucg.c | 8 +- app/modules/wifi.c | 13 +- app/modules/ws2801.c | 9 +- app/modules/ws2812.c | 8 +- ld/nodemcu.ld | 10 ++ 37 files changed, 229 insertions(+), 636 deletions(-) create mode 100644 app/include/module.h delete mode 100644 app/modules/modules.h diff --git a/app/include/module.h b/app/include/module.h new file mode 100644 index 00000000..9f00a69a --- /dev/null +++ b/app/include/module.h @@ -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_STRIFY__(x) #x +#define MODULE_STRIFY_(x) MODULE_STRIFY__(x) +#define MODULE_EXPAND_(x) x +#define MODULE_PASTE_(x,y) x##y + +/* Given an uppercase name XYZ, look at the corresponding LUA_USE_MODULES_XYZ + * and append that to the section name prefix (e.g. "lua_libs"). For an + * included module, this will yield either ".lua_libs" (for an empty #define) + * or ".lua_libs1" (if #defined to 1). The linker script will then + * pick up all items in those sections and construct an array for us. + * A non-included module ZZZ ends up in a section named + * ".lua_libsLUA_USE_MODULES_ZZZ" which gets discarded by the linker (together + * with the associated module code). + */ +#define PICK_SECTION_(pfx, name) \ + pfx MODULE_STRIFY_(MODULE_EXPAND_(LUA_USE_MODULES_ ## name)) + +#define NODEMCU_MODULE(cfgname, luaname, map, initfunc) \ + static const __attribute__((used,unused,section(PICK_SECTION_(".lua_libs",cfgname)))) \ + luaL_Reg MODULE_PASTE_(lua_lib_,cfgname) = { luaname, initfunc }; \ + static const __attribute__((used,unused,section(PICK_SECTION_(".lua_rotable",cfgname)))) \ + luaR_table MODULE_PASTE_(lua_rotable_,cfgname) = { luaname, map } + + +/* System module registration support, not using LUA_USE_MODULES_XYZ. */ +#define BUILTIN_LIB_INIT(name, luaname, initfunc) \ + static const __attribute__((used,unused,section(".lua_libs"))) \ + luaL_Reg MODULE_PASTE_(lua_lib_,name) = { luaname, initfunc } + +#define BUILTIN_LIB(name, luaname, map) \ + static const __attribute__((used,unused,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 diff --git a/app/include/user_modules.h b/app/include/user_modules.h index 1a4646e2..f3bb0fee 100644 --- a/app/include/user_modules.h +++ b/app/include/user_modules.h @@ -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 @@ -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__ */ diff --git a/app/lua/lrodefs.h b/app/lua/lrodefs.h index 384be3ee..e9bbe7fe 100644 --- a/app/lua/lrodefs.h +++ b/app/lua/lrodefs.h @@ -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 diff --git a/app/modules/adc.c b/app/modules/adc.c index aedd16e1..15bf7de9 100644 --- a/app/modules/adc.c +++ b/app/modules/adc.c @@ -1,8 +1,8 @@ // Module for interfacing with adc +#include "module.h" #include "lauxlib.h" #include "platform.h" -#include "lrodefs.h" #include "c_types.h" #include "user_interface.h" @@ -25,16 +25,10 @@ static int adc_readvdd33( lua_State* L ) } // Module function map -const LUA_REG_TYPE adc_map[] = { +static 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 ) { -#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(ADC, "adc", adc_map, NULL); diff --git a/app/modules/bit.c b/app/modules/bit.c index d6914457..4d196465 100644 --- a/app/modules/bit.c +++ b/app/modules/bit.c @@ -5,10 +5,10 @@ // Modified by BogdanM for eLua +#include "module.h" #include "c_limits.h" #include "lauxlib.h" -#include "lrodefs.h" /* FIXME: Assume size_t is an unsigned lua_Integer */ typedef size_t lua_UInteger; @@ -119,7 +119,7 @@ static int bit_clear( lua_State* L ) return 1; } -const LUA_REG_TYPE bit_map[] = { +static const LUA_REG_TYPE bit_map[] = { { LSTRKEY( "bnot" ), LFUNCVAL( bit_bnot ) }, { LSTRKEY( "band" ), LFUNCVAL( bit_band ) }, { LSTRKEY( "bor" ), LFUNCVAL( bit_bor ) }, @@ -135,10 +135,4 @@ const LUA_REG_TYPE bit_map[] = { { LNILKEY, LNILVAL} }; -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 -} +NODEMCU_MODULE(BIT, "bit", bit_map, NULL); diff --git a/app/modules/bmp085.c b/app/modules/bmp085.c index 57a73bc1..17a7651f 100644 --- a/app/modules/bmp085.c +++ b/app/modules/bmp085.c @@ -1,6 +1,6 @@ +#include "module.h" #include "lauxlib.h" #include "platform.h" -#include "lrodefs.h" #include "c_stdlib.h" #include "c_string.h" @@ -183,7 +183,7 @@ static int ICACHE_FLASH_ATTR bmp085_lua_pressure(lua_State* L) { return 1; } -const LUA_REG_TYPE bmp085_map[] = { +static 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 )}, @@ -191,10 +191,4 @@ const LUA_REG_TYPE bmp085_map[] = { { LNILKEY, LNILVAL} }; -LUALIB_API int luaopen_bmp085(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(BMP085, "bmp085", bmp085_map, NULL); diff --git a/app/modules/cjson.c b/app/modules/cjson.c index 23947a5d..b611c05f 100644 --- a/app/modules/cjson.c +++ b/app/modules/cjson.c @@ -37,11 +37,11 @@ */ // #include +#include "module.h" #include "c_string.h" #include "c_math.h" #include "c_limits.h" #include "lauxlib.h" -#include "lrodefs.h" #include "flash_api.h" #include "strbuf.h" @@ -1600,7 +1600,7 @@ int luaopen_cjson_safe(lua_State *l) #endif // Module function map -const LUA_REG_TYPE cjson_map[] = { +static 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 ) }, @@ -1614,7 +1614,7 @@ const LUA_REG_TYPE cjson_map[] = { { LNILKEY, LNILVAL } }; -LUALIB_API int luaopen_cjson( lua_State *L ) +int luaopen_cjson( lua_State *L ) { cjson_mem_setlua (L); @@ -1623,11 +1623,9 @@ LUALIB_API int luaopen_cjson( lua_State *L ) 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 } + +NODEMCU_MODULE(CJSON, "cjson", cjson_map, luaopen_cjson); /* vi:ai et sw=4 ts=4: */ diff --git a/app/modules/coap.c b/app/modules/coap.c index 94d2b670..2b6efb9e 100644 --- a/app/modules/coap.c +++ b/app/modules/coap.c @@ -1,8 +1,8 @@ // Module for coapwork +#include "module.h" #include "lauxlib.h" #include "platform.h" -#include "lrodefs.h" #include "c_string.h" #include "c_stdlib.h" @@ -578,7 +578,7 @@ static const LUA_REG_TYPE coap_client_map[] = { { LNILKEY, LNILVAL } }; -const LUA_REG_TYPE coap_map[] = +static const LUA_REG_TYPE coap_map[] = { { LSTRKEY( "Server" ), LFUNCVAL( coap_createServer ) }, { LSTRKEY( "Client" ), LFUNCVAL( coap_createClient ) }, @@ -594,14 +594,12 @@ const LUA_REG_TYPE coap_map[] = { LNILKEY, LNILVAL } }; -LUALIB_API int luaopen_coap( lua_State *L ) +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 } + +NODEMCU_MODULE(COAP, "coap", coap_map, luaopen_coap); diff --git a/app/modules/crypto.c b/app/modules/crypto.c index e9067495..4a151579 100644 --- a/app/modules/crypto.c +++ b/app/modules/crypto.c @@ -1,8 +1,8 @@ // Module for cryptography +#include "module.h" #include "lauxlib.h" #include "platform.h" -#include "lrodefs.h" #include "c_types.h" #include "c_stdlib.h" #include "../crypto/digests.h" @@ -150,7 +150,7 @@ static int crypto_lhmac (lua_State *L) // Module function map -const LUA_REG_TYPE crypto_map[] = { +static const LUA_REG_TYPE crypto_map[] = { { LSTRKEY( "sha1" ), LFUNCVAL( crypto_sha1 ) }, { LSTRKEY( "toBase64" ), LFUNCVAL( crypto_base64_encode ) }, { LSTRKEY( "toHex" ), LFUNCVAL( crypto_hex_encode ) }, @@ -160,10 +160,4 @@ const LUA_REG_TYPE crypto_map[] = { { LNILKEY, LNILVAL } }; -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 -} +NODEMCU_MODULE(CRYPTO, "crypto", crypto_map, NULL); diff --git a/app/modules/dht.c b/app/modules/dht.c index c951341f..673ed2f2 100644 --- a/app/modules/dht.c +++ b/app/modules/dht.c @@ -1,7 +1,7 @@ // Module for interfacing with the DHTxx sensors (xx = 11-21-22-33-44). +#include "module.h" #include "lauxlib.h" -#include "lrodefs.h" #include "platform.h" #include "cpu_esp8266.h" #include "dht.h" @@ -99,7 +99,7 @@ static int dht_lapi_readxx( lua_State *L ) // } // Module function map -const LUA_REG_TYPE dht_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 ) }, @@ -109,10 +109,4 @@ const LUA_REG_TYPE dht_map[] = { { LNILKEY, LNILVAL } }; -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 -} +NODEMCU_MODULE(DHT, "dht", dht_map, NULL); diff --git a/app/modules/enduser_setup.c b/app/modules/enduser_setup.c index a7b06a57..1e02e0a3 100644 --- a/app/modules/enduser_setup.c +++ b/app/modules/enduser_setup.c @@ -31,10 +31,9 @@ * @author Robert Foss */ - +#include "module.h" #include "lauxlib.h" #include "platform.h" -#include "lrodefs.h" #include "c_stdlib.h" #include "c_string.h" #include "user_interface.h" @@ -927,17 +926,10 @@ static int enduser_setup_stop(lua_State* L) } -const LUA_REG_TYPE enduser_setup_map[] = { +static 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 -} - +NODEMCU_MODULE(ENDUSER_SETUP, "enduser_setup", enduser_setup_map, NULL); diff --git a/app/modules/file.c b/app/modules/file.c index 80f8ec54..d5e4fd26 100644 --- a/app/modules/file.c +++ b/app/modules/file.c @@ -1,8 +1,8 @@ // Module for interfacing with file system +#include "module.h" #include "lauxlib.h" #include "platform.h" -#include "lrodefs.h" #include "c_types.h" #include "flash_fs.h" @@ -296,7 +296,7 @@ static int file_writeline( lua_State* L ) } // Module function map -const LUA_REG_TYPE file_map[] = { +static const LUA_REG_TYPE file_map[] = { { LSTRKEY( "list" ), LFUNCVAL( file_list ) }, { LSTRKEY( "open" ), LFUNCVAL( file_open ) }, { LSTRKEY( "close" ), LFUNCVAL( file_close ) }, @@ -316,10 +316,4 @@ const LUA_REG_TYPE file_map[] = { { LNILKEY, LNILVAL } }; -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 -} +NODEMCU_MODULE(FILE, "file", file_map, NULL); diff --git a/app/modules/gpio.c b/app/modules/gpio.c index d19c0220..d779a903 100644 --- a/app/modules/gpio.c +++ b/app/modules/gpio.c @@ -1,8 +1,8 @@ // Module for interfacing with GPIO +#include "module.h" #include "lauxlib.h" #include "platform.h" -#include "lrodefs.h" #include "c_types.h" #include "c_string.h" @@ -220,7 +220,7 @@ static int lgpio_serout( lua_State* L ) #undef DELAY_TABLE_MAX_LEN // Module function map -const LUA_REG_TYPE gpio_map[] = { +static const LUA_REG_TYPE gpio_map[] = { { LSTRKEY( "mode" ), LFUNCVAL( lgpio_mode ) }, { LSTRKEY( "read" ), LFUNCVAL( lgpio_read ) }, { LSTRKEY( "write" ), LFUNCVAL( lgpio_write ) }, @@ -238,7 +238,7 @@ const LUA_REG_TYPE gpio_map[] = { { LNILKEY, LNILVAL } }; -LUALIB_API int luaopen_gpio( lua_State *L ) { +int luaopen_gpio( lua_State *L ) { #ifdef GPIO_INTERRUPT_ENABLE int i; for(i=0;i 0 - #if defined(LUA_USE_BUILTIN_STRING) - {LUA_STRLIBNAME, strlib}, - #endif +extern const luaL_Reg lua_libs[]; - #if defined(LUA_USE_BUILTIN_TABLE) - {LUA_TABLIBNAME, tab_funcs}, - #endif - - #if defined(LUA_USE_BUILTIN_DEBUG) || defined(LUA_USE_BUILTIN_DEBUG_MINIMAL) - {LUA_DBLIBNAME, dblib}, - #endif - - #if defined(LUA_USE_BUILTIN_COROUTINE) - {LUA_COLIBNAME, co_funcs}, - #endif - - #if defined(LUA_USE_BUILTIN_MATH) - {LUA_MATHLIBNAME, math_map}, - #endif - - #if defined(LUA_USE_BUILTIN_OS) - {LUA_OSLIBNAME, syslib}, - #endif - -#if defined(LUA_MODULES_ROM) && LUA_OPTIMIZE_MEMORY == 2 -#undef _ROM -#define _ROM( name, openf, table ) { name, table }, - LUA_MODULES_ROM -#endif -#endif - {NULL, NULL} -}; - -LUALIB_API void luaL_openlibs (lua_State *L) { - const luaL_Reg *lib = lualibs; - for (; lib->func; lib++) { - lua_pushcfunction(L, lib->func); - lua_pushstring(L, lib->name); - lua_call(L, 1, 0); +void luaL_openlibs (lua_State *L) { + const luaL_Reg *lib = lua_libs; + for (; lib->name; lib++) { + if (lib->func) + { + lua_pushcfunction(L, lib->func); + lua_pushstring(L, lib->name); + lua_call(L, 1, 0); + } } } diff --git a/app/modules/modules.h b/app/modules/modules.h deleted file mode 100644 index 7292b6e9..00000000 --- a/app/modules/modules.h +++ /dev/null @@ -1,289 +0,0 @@ -/** - * External modules library - */ - -#ifndef __MODULES_H__ -#define __MODULES_H__ - -#if defined(LUA_USE_MODULES_GPIO) -#define MODULES_GPIO "gpio" -#define ROM_MODULES_GPIO \ - _ROM(MODULES_GPIO, luaopen_gpio, gpio_map) -#else -#define ROM_MODULES_GPIO -#endif - -#if defined(LUA_USE_MODULES_PWM) -#define MODULES_PWM "pwm" -#define ROM_MODULES_PWM \ - _ROM(MODULES_PWM, luaopen_pwm, pwm_map) -#else -#define ROM_MODULES_PWM -#endif - -#if defined(LUA_USE_MODULES_WIFI) -#define MODULES_WIFI "wifi" -#define ROM_MODULES_WIFI \ - _ROM(MODULES_WIFI, luaopen_wifi, wifi_map) -#else -#define ROM_MODULES_WIFI -#endif - -#if defined(LUA_USE_MODULES_NET) -#define MODULES_NET "net" -#define ROM_MODULES_NET \ - _ROM(MODULES_NET, luaopen_net, net_map) -#else -#define ROM_MODULES_NET -#endif - -#if defined(LUA_USE_MODULES_COAP) -#define MODULES_COAP "coap" -#define ROM_MODULES_COAP \ - _ROM(MODULES_COAP, luaopen_coap, coap_map) -#else -#define ROM_MODULES_COAP -#endif - -#if defined(LUA_USE_MODULES_MQTT) -#define MODULES_MQTT "mqtt" -#define ROM_MODULES_MQTT \ - _ROM(MODULES_MQTT, luaopen_mqtt, mqtt_map) -#else -#define ROM_MODULES_MQTT -#endif - -#if defined(LUA_USE_MODULES_U8G) -#define MODULES_U8G "u8g" -#define ROM_MODULES_U8G \ - _ROM(MODULES_U8G, luaopen_u8g, lu8g_map) -#else -#define ROM_MODULES_U8G -#endif - -#if defined(LUA_USE_MODULES_UCG) -#define MODULES_UCG "ucg" -#define ROM_MODULES_UCG \ - _ROM(MODULES_UCG, luaopen_ucg, lucg_map) -#else -#define ROM_MODULES_UCG -#endif - -#if defined(LUA_USE_MODULES_I2C) -#define MODULES_I2C "i2c" -#define ROM_MODULES_I2C \ - _ROM(MODULES_I2C, luaopen_i2c, i2c_map) -#else -#define ROM_MODULES_I2C -#endif - -#if defined(LUA_USE_MODULES_SPI) -#define MODULES_SPI "spi" -#define ROM_MODULES_SPI \ - _ROM(MODULES_SPI, luaopen_spi, spi_map) -#else -#define ROM_MODULES_SPI -#endif - -#if defined(LUA_USE_MODULES_TMR) -#define MODULES_TMR "tmr" -#define ROM_MODULES_TMR \ - _ROM(MODULES_TMR, luaopen_tmr, tmr_map) -#else -#define ROM_MODULES_TMR -#endif - -#if defined(LUA_USE_MODULES_NODE) -#define MODULES_NODE "node" -#define ROM_MODULES_NODE \ - _ROM(MODULES_NODE, luaopen_node, node_map) -#else -#define ROM_MODULES_NODE -#endif - -#if defined(LUA_USE_MODULES_FILE) -#define MODULES_FILE "file" -#define ROM_MODULES_FILE \ - _ROM(MODULES_FILE, luaopen_file, file_map) -#else -#define ROM_MODULES_FILE -#endif - -#if defined(LUA_USE_MODULES_ADC) -#define MODULES_ADC "adc" -#define ROM_MODULES_ADC \ - _ROM(MODULES_ADC, luaopen_adc, adc_map) -#else -#define ROM_MODULES_ADC -#endif - -#if defined(LUA_USE_MODULES_UART) -#define MODULES_UART "uart" -#define ROM_MODULES_UART \ - _ROM(MODULES_UART, luaopen_uart, uart_map) -#else -#define ROM_MODULES_UART -#endif - -#if defined(LUA_USE_MODULES_OW) -#define MODULES_OW "ow" -#define ROM_MODULES_OW \ - _ROM(MODULES_OW, luaopen_ow, ow_map) -#else -#define ROM_MODULES_OW -#endif - -#if defined(LUA_USE_MODULES_BIT) -#define MODULES_BIT "bit" -#define ROM_MODULES_BIT \ - _ROM(MODULES_BIT, luaopen_bit, bit_map) -#else -#define ROM_MODULES_BIT -#endif - -#if defined(LUA_USE_MODULES_WS2801) -#define MODULES_WS2801 "ws2801" -#define ROM_MODULES_WS2801 \ - _ROM(MODULES_WS2801, luaopen_ws2801, ws2801_map) -#else -#define ROM_MODULES_WS2801 -#endif - -#if defined(LUA_USE_MODULES_WS2812) -#define MODULES_WS2812 "ws2812" -#define ROM_MODULES_WS2812 \ - _ROM(MODULES_WS2812, luaopen_ws2812, ws2812_map) -#else -#define ROM_MODULES_WS2812 -#endif - -#if defined(LUA_USE_MODULES_ENDUSER_SETUP) -#define MODULES_ENDUSER_SETUP "enduser_setup" -#define ROM_MODULES_ENDUSER_SETUP \ - _ROM(MODULES_ENDUSER_SETUP, luaopen_enduser_setup, enduser_setup_map) -#else -#define ROM_MODULES_ENDUSER_SETUP -#endif - -#if defined(LUA_USE_MODULES_CJSON) -#define MODULES_CJSON "cjson" -#define ROM_MODULES_CJSON \ - _ROM(MODULES_CJSON, luaopen_cjson, cjson_map) -#else -#define ROM_MODULES_CJSON -#endif - -#if defined(LUA_USE_MODULES_CRYPTO) -#define MODULES_CRYPTO "crypto" -#define ROM_MODULES_CRYPTO \ - _ROM(MODULES_CRYPTO, luaopen_crypto, crypto_map) -#else -#define ROM_MODULES_CRYPTO -#endif - -#if defined(LUA_USE_MODULES_RC) -#define MODULES_RC "rc" -#define ROM_MODULES_RC \ - _ROM(MODULES_RC, luaopen_rc, rc_map) -#else -#define ROM_MODULES_RC -#endif - -#if defined(LUA_USE_MODULES_DHT) -#define MODULES_DHT "dht" -#define ROM_MODULES_DHT \ - _ROM(MODULES_DHT, luaopen_dht, dht_map) -#else -#define ROM_MODULES_DHT -#endif - -#if defined(LUA_USE_MODULES_RTCMEM) -#define MODULES_RTCMEM "rtcmem" -#define ROM_MODULES_RTCMEM \ - _ROM(MODULES_RTCMEM, luaopen_rtcmem, rtcmem_map) -#else -#define ROM_MODULES_RTCMEM -#endif - -#if defined(LUA_USE_MODULES_RTCTIME) -#define MODULES_RTCTIME "rtctime" -#define ROM_MODULES_RTCTIME \ - _ROM(MODULES_RTCTIME, luaopen_rtctime, rtctime_map) -#else -#define ROM_MODULES_RTCTIME -#endif - -#if defined(LUA_USE_MODULES_RTCFIFO) -#define MODULES_RTCFIFO "rtcfifo" -#define ROM_MODULES_RTCFIFO \ - _ROM(MODULES_RTCFIFO, luaopen_rtcfifo, rtcfifo_map) -#else -#define ROM_MODULES_RTCFIFO -#endif - -#if defined(LUA_USE_MODULES_SNTP) -#define MODULES_SNTP "sntp" -#define ROM_MODULES_SNTP \ - _ROM(MODULES_SNTP, luaopen_sntp, sntp_map) -#else -#define ROM_MODULES_SNTP -#endif - -#if defined(LUA_USE_MODULES_BMP085) -#define MODULES_BMP085 "bmp085" -#define ROM_MODULES_BMP085 \ - _ROM(MODULES_BMP085, luaopen_bmp085, bmp085_map) -#else -#define ROM_MODULES_BMP085 -#endif - -#if defined(LUA_USE_MODULES_TSL2561) -#define MODULES_TSL2561 "tsl2561" -#define ROM_MODULES_TSL2561 \ - _ROM(MODULES_TSL2561, luaopen_tsl2561, tsl2561_map) -#else -#define ROM_MODULES_TSL2561 -#endif - -#if defined(LUA_USE_MODULES_HX711) -#define MODULES_HX711 "hx711" -#define ROM_MODULES_HX711 \ - _ROM(MODULES_HX711, luaopen_hx711, hx711_map) -#else -#define ROM_MODULES_HX711 -#endif - -#define LUA_MODULES_ROM \ - ROM_MODULES_GPIO \ - ROM_MODULES_PWM \ - ROM_MODULES_WIFI \ - ROM_MODULES_COAP \ - ROM_MODULES_MQTT \ - ROM_MODULES_U8G \ - ROM_MODULES_UCG \ - ROM_MODULES_I2C \ - ROM_MODULES_SPI \ - ROM_MODULES_TMR \ - ROM_MODULES_NODE \ - ROM_MODULES_FILE \ - ROM_MODULES_NET \ - ROM_MODULES_ADC \ - ROM_MODULES_UART \ - ROM_MODULES_OW \ - ROM_MODULES_BIT \ - ROM_MODULES_ENDUSER_SETUP \ - ROM_MODULES_WS2801 \ - ROM_MODULES_WS2812 \ - ROM_MODULES_CJSON \ - ROM_MODULES_CRYPTO \ - ROM_MODULES_RC \ - ROM_MODULES_DHT \ - ROM_MODULES_RTCMEM \ - ROM_MODULES_RTCTIME \ - ROM_MODULES_RTCFIFO \ - ROM_MODULES_SNTP \ - ROM_MODULES_BMP085 \ - ROM_MODULES_TSL2561 \ - ROM_MODULES_HX711 - -#endif diff --git a/app/modules/mqtt.c b/app/modules/mqtt.c index 7d396133..2dde4de6 100644 --- a/app/modules/mqtt.c +++ b/app/modules/mqtt.c @@ -1,8 +1,8 @@ // Module for mqtt +#include "module.h" #include "lauxlib.h" #include "platform.h" -#include "lrodefs.h" #include "c_string.h" #include "c_stdlib.h" @@ -1401,18 +1401,16 @@ static const LUA_REG_TYPE mqtt_socket_map[] = { { LNILKEY, LNILVAL } }; -const LUA_REG_TYPE mqtt_map[] = { +static const LUA_REG_TYPE mqtt_map[] = { { LSTRKEY( "Client" ), LFUNCVAL( mqtt_socket_client ) }, { LSTRKEY( "__metatable" ), LROVAL( mqtt_map ) }, { LNILKEY, LNILVAL } }; -LUALIB_API int luaopen_mqtt( lua_State *L ) +int luaopen_mqtt( lua_State *L ) { luaL_rometatable(L, "mqtt.socket", (void *)mqtt_socket_map); // create metatable for mqtt.socket -#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(MQTT, "mqtt", mqtt_map, luaopen_mqtt); diff --git a/app/modules/net.c b/app/modules/net.c index 9555324e..f0eee3b6 100644 --- a/app/modules/net.c +++ b/app/modules/net.c @@ -1,8 +1,8 @@ // Module for network +#include "module.h" #include "lauxlib.h" #include "platform.h" -#include "lrodefs.h" #include "c_string.h" #include "c_stdlib.h" @@ -1545,7 +1545,7 @@ static const LUA_REG_TYPE net_dns_map[] = { { LNILKEY, LNILVAL } }; -const LUA_REG_TYPE net_map[] = { +static const LUA_REG_TYPE net_map[] = { { LSTRKEY( "createServer" ), LFUNCVAL( net_createServer ) }, { LSTRKEY( "createConnection" ), LFUNCVAL( net_createConnection ) }, { LSTRKEY( "multicastJoin"), LFUNCVAL( net_multicastJoin ) }, @@ -1557,7 +1557,7 @@ const LUA_REG_TYPE net_map[] = { { LNILKEY, LNILVAL } }; -LUALIB_API int luaopen_net( lua_State *L ) { +int luaopen_net( lua_State *L ) { int i; for(i=0;i Date: Wed, 16 Dec 2015 18:59:55 +1100 Subject: [PATCH 32/39] Corrected the 4-page alignment for start of fs. --- app/spiffs/spiffs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/spiffs/spiffs.c b/app/spiffs/spiffs.c index f5c514f7..9f0eba49 100644 --- a/app/spiffs/spiffs.c +++ b/app/spiffs/spiffs.c @@ -51,7 +51,7 @@ void myspiffs_mount() { #else cfg.phys_addr = ( u32_t )platform_flash_get_first_free_block_address( NULL ); #endif - cfg.phys_addr += 0x3000; + cfg.phys_addr += 0x3FFF; cfg.phys_addr &= 0xFFFFC000; // align to 4 sector. cfg.phys_size = INTERNAL_FLASH_SIZE - ( ( u32_t )cfg.phys_addr ); cfg.phys_erase_block = INTERNAL_FLASH_SECTOR_SIZE; // according to datasheet @@ -94,7 +94,7 @@ int myspiffs_format( void ) #else sect_first = ( u32_t )platform_flash_get_first_free_block_address( NULL ); #endif - sect_first += 0x3000; + sect_first += 0x3FFF; sect_first &= 0xFFFFC000; // align to 4 sector. sect_first = platform_flash_get_sector_of_address(sect_first); sect_last = INTERNAL_FLASH_SIZE - SYS_PARAM_SEC_NUM; From 5e9bf95ccc46fea80de80ec79a9351730624f5b0 Mon Sep 17 00:00:00 2001 From: devsaurus Date: Wed, 16 Dec 2015 22:23:04 +0100 Subject: [PATCH 33/39] cpol=high is not implemented due to insufficient hw docs --- app/modules/spi.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/modules/spi.c b/app/modules/spi.c index 6074ec82..c7453e7d 100644 --- a/app/modules/spi.c +++ b/app/modules/spi.c @@ -33,6 +33,10 @@ static int spi_setup( lua_State *L ) if (cpol != PLATFORM_SPI_CPOL_LOW && cpol != PLATFORM_SPI_CPOL_HIGH) { return luaL_error( L, "wrong arg type" ); } + // CPOL_HIGH is not implemented, see app/driver/spi.c spi_master_init() + if (cpol == PLATFORM_SPI_CPOL_HIGH) { + return luaL_error( L, "cpol=high is not implemented" ); + } if (cpha != PLATFORM_SPI_CPHA_LOW && cpha != PLATFORM_SPI_CPHA_HIGH) { return luaL_error( L, "wrong arg type" ); From 7e02935a27864598fda0cef7f968cd7fe6b4457e Mon Sep 17 00:00:00 2001 From: Johny Mattsson Date: Thu, 17 Dec 2015 12:37:01 +1100 Subject: [PATCH 34/39] Deal with ld's overly eager discarding of globals. --- app/Makefile | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/Makefile b/app/Makefile index 62819e9d..83cb23cc 100644 --- a/app/Makefile +++ b/app/Makefile @@ -86,8 +86,10 @@ COMPONENTS_eagle.app.v6 = \ crypto/libcrypto.a \ dhtlib/libdhtlib.a \ tsl2561/tsl2561lib.a \ - modules/libmodules.a + modules/libmodules.a \ +# Special consideration for modules to support NODEMCU_MODULE handling +MODULES_LIB = $(filter %modules.a, $(DEP_LIBS_eagle.app.v6)) LINKFLAGS_eagle.app.v6 = \ -Wl,--gc-sections \ @@ -98,6 +100,9 @@ LINKFLAGS_eagle.app.v6 = \ -Wl,--no-check-sections \ -Wl,--wrap=_xtos_set_exception_handler \ -Wl,-static \ + -Wl,--whole-archive \ + $(MODULES_LIB) \ + -Wl,--no-whole-archive \ -Wl,--start-group \ -lc \ -lgcc \ From da5834e2cf17469ec64c927124d70a3458c68142 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20St=C3=B6r?= Date: Thu, 17 Dec 2015 20:21:47 +0100 Subject: [PATCH 35/39] Add a few small corrections and new Docker link I a discussion with @nickandrew (original author of updated sections) he agreed that we should rather link to *my* Docker image because it has fewer issues then the one currently referenced. The one we identified will soon be addressed. --- README.md | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index e60b9972..0e6704c5 100644 --- a/README.md +++ b/README.md @@ -209,17 +209,15 @@ There are several options for building the NodeMCU firmware. ## Online firmware custom build -Please try Marcel's [NodeMCU custom builds](http://frightanic.com/nodemcu-custom-build) cloud service and you can choose only the modules you need, and download the firmware once built. +Please try Marcel's [NodeMCU custom build](http://nodemcu-build.com) cloud service and you can choose only the modules you need, and download the firmware once built. -NodeMCU custom builds can build from the master branch and dev branch (with the latest fixes). +NodeMCU custom builds can build from all active branches (with the latest fixes). ## Docker containerised build -See https://hub.docker.com/r/asmaps/nodemcu-builder/ +See [https://hub.docker.com/r/marcelstoer/nodemcu-build/](https://hub.docker.com/r/marcelstoer/nodemcu-build/) -This docker image includes the build toolchain and SDK. You just run the docker -image with your checked-out NodeMCU firmware repository (this one). The docker -image can also flash the firmware to your device. +This Docker image includes the build toolchain and SDK. You just run the Docker image with your checked-out NodeMCU firmware repository (this one). You will need to see BUILD OPTIONS below, to configure the firmware before building. From 9003d3e8fb283cc242e1d1962cdc17efe3749119 Mon Sep 17 00:00:00 2001 From: Johny Mattsson Date: Fri, 18 Dec 2015 13:10:48 +1100 Subject: [PATCH 36/39] Rework NODEMCU_MODULE() to not pull in extra gunk. Third time lucky. I hope. Hi Terry. --- app/Makefile | 11 ++++++----- app/include/module.h | 36 ++++++++++++++++++------------------ ld/nodemcu.ld | 4 ++-- 3 files changed, 26 insertions(+), 25 deletions(-) diff --git a/app/Makefile b/app/Makefile index 83cb23cc..77e20ab1 100644 --- a/app/Makefile +++ b/app/Makefile @@ -88,8 +88,11 @@ COMPONENTS_eagle.app.v6 = \ tsl2561/tsl2561lib.a \ modules/libmodules.a \ -# Special consideration for modules to support NODEMCU_MODULE handling -MODULES_LIB = $(filter %modules.a, $(DEP_LIBS_eagle.app.v6)) +# 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 \ @@ -100,9 +103,7 @@ LINKFLAGS_eagle.app.v6 = \ -Wl,--no-check-sections \ -Wl,--wrap=_xtos_set_exception_handler \ -Wl,-static \ - -Wl,--whole-archive \ - $(MODULES_LIB) \ - -Wl,--no-whole-archive \ + $(addprefix -u , $(SELECTED_MODULE_SYMS)) \ -Wl,--start-group \ -lc \ -lgcc \ diff --git a/app/include/module.h b/app/include/module.h index 9f00a69a..919d5758 100644 --- a/app/include/module.h +++ b/app/include/module.h @@ -34,37 +34,37 @@ * a foo function in your module. */ -#define MODULE_STRIFY__(x) #x -#define MODULE_STRIFY_(x) MODULE_STRIFY__(x) #define MODULE_EXPAND_(x) x #define MODULE_PASTE_(x,y) x##y +#define MODULE_EXPAND_PASTE_(x,y) MODULE_PASTE_(x,y) -/* Given an uppercase name XYZ, look at the corresponding LUA_USE_MODULES_XYZ - * and append that to the section name prefix (e.g. "lua_libs"). For an - * included module, this will yield either ".lua_libs" (for an empty #define) - * or ".lua_libs1" (if #defined to 1). The linker script will then - * pick up all items in those sections and construct an array for us. - * A non-included module ZZZ ends up in a section named - * ".lua_libsLUA_USE_MODULES_ZZZ" which gets discarded by the linker (together - * with the associated module code). +#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 PICK_SECTION_(pfx, name) \ - pfx MODULE_STRIFY_(MODULE_EXPAND_(LUA_USE_MODULES_ ## name)) - #define NODEMCU_MODULE(cfgname, luaname, map, initfunc) \ - static const __attribute__((used,unused,section(PICK_SECTION_(".lua_libs",cfgname)))) \ + const LOCK_IN_SECTION(".lua_libs") \ luaL_Reg MODULE_PASTE_(lua_lib_,cfgname) = { luaname, initfunc }; \ - static const __attribute__((used,unused,section(PICK_SECTION_(".lua_rotable",cfgname)))) \ - luaR_table MODULE_PASTE_(lua_rotable_,cfgname) = { luaname, map } + 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) \ - static const __attribute__((used,unused,section(".lua_libs"))) \ + const LOCK_IN_SECTION(".lua_libs") \ luaL_Reg MODULE_PASTE_(lua_lib_,name) = { luaname, initfunc } #define BUILTIN_LIB(name, luaname, map) \ - static const __attribute__((used,unused,section(".lua_rotable"))) \ + const LOCK_IN_SECTION(".lua_rotable") \ luaR_table MODULE_PASTE_(lua_rotable_,name) = { luaname, map } #if !(MIN_OPT_LEVEL==2 && LUA_OPTIMIZE_MEMORY==2) diff --git a/ld/nodemcu.ld b/ld/nodemcu.ld index e67e9af0..8c4ee61a 100644 --- a/ld/nodemcu.ld +++ b/ld/nodemcu.ld @@ -83,10 +83,10 @@ SECTIONS . = ALIGN(4); lua_libs = ABSOLUTE(.); /* Allow either empty define or defined-to-1 to include the module */ - KEEP(*(.lua_libs .lua_libs1)) + KEEP(*(.lua_libs)) LONG(0) LONG(0) /* Null-terminate the array */ lua_rotable = ABSOLUTE(.); - KEEP(*(.lua_rotable .lua_rotable1)) + KEEP(*(.lua_rotable)) LONG(0) LONG(0) /* Null-terminate the array */ /* These are *only* pulled in by Lua, and therefore safe to put in flash */ From 672c396c69853c237c97363a2f9cf729926e7f0c Mon Sep 17 00:00:00 2001 From: Robert Foss Date: Sun, 20 Dec 2015 22:50:36 -0500 Subject: [PATCH 37/39] Fixed compilation error when the enduser_setup module is disabled yet requires ENDUSER_SETUP_AP_SSID to be defined. --- app/modules/enduser_setup.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/modules/enduser_setup.c b/app/modules/enduser_setup.c index 1e02e0a3..067c9535 100644 --- a/app/modules/enduser_setup.c +++ b/app/modules/enduser_setup.c @@ -640,6 +640,10 @@ static void enduser_setup_ap_start(void) struct softap_config cnf; c_memset(&(cnf), 0, sizeof(struct softap_config)); +#ifndef ENDUSER_SETUP_AP_SSID + #define ENDUSER_SETUP_AP_SSID "SetupGadget" +#endif + char ssid[] = ENDUSER_SETUP_AP_SSID; int ssid_name_len = c_strlen(ENDUSER_SETUP_AP_SSID); c_memcpy(&(cnf.ssid), ssid, ssid_name_len); From 6cbe716db09aa8b8cb3dea741984cec80f3f0583 Mon Sep 17 00:00:00 2001 From: devsaurus Date: Mon, 14 Dec 2015 20:17:04 +0100 Subject: [PATCH 38/39] uart: fix parity and stopbit generation --- app/driver/uart.c | 8 ++--- app/include/driver/uart.h | 14 ++++----- app/include/driver/uart_register.h | 50 ++++++++++++++++++------------ app/modules/uart.c | 14 ++++++--- app/platform/platform.c | 7 +++-- app/platform/platform.h | 16 +++++----- 6 files changed, 64 insertions(+), 45 deletions(-) diff --git a/app/driver/uart.c b/app/driver/uart.c index 0785dff6..0b216ef2 100755 --- a/app/driver/uart.c +++ b/app/driver/uart.c @@ -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) < Date: Mon, 28 Dec 2015 15:22:09 +0100 Subject: [PATCH 39/39] fix parameter access for ucg.getStrWidth() --- app/modules/ucg.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/modules/ucg.c b/app/modules/ucg.c index 9c0506d2..f5089e26 100644 --- a/app/modules/ucg.c +++ b/app/modules/ucg.c @@ -402,7 +402,7 @@ static int lucg_getHeight( lua_State *L ) return 1; } -// Lua: width = ucg.getStrWidth( self ) +// Lua: width = ucg.getStrWidth( self, string ) static int lucg_getStrWidth( lua_State *L ) { lucg_userdata_t *lud; @@ -410,7 +410,7 @@ static int lucg_getStrWidth( lua_State *L ) if ((lud = get_lud( L )) == NULL) return 0; - const char *s = luaL_checkstring( L, (1+3) + 1 ); + const char *s = luaL_checkstring( L, 2 ); if (s == NULL) return 0;