From ab61e9c03a9bba1a8d02c818a6859b9fdb4aa555 Mon Sep 17 00:00:00 2001 From: Natalia Date: Fri, 5 Apr 2019 07:56:11 +0300 Subject: [PATCH 01/74] I2C sw driver with support of multiple buses, Slow, Fast, FastPlus, and user-defined speed selection (#2465) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * I2C driver speed-up, i2c.SLOW, i2c.FAST and user-defined speed selection * - Multiple buses (up to 10) with different speeds on each bus - Standard(Slow, 100kHz), Fast(400kHz) and FastPlus(1MHz) modes or an arbitrary clock speed - Sharing SDA line over multiple I²C buses to save available pins - GPIO16 pin can be used as SCL pin, but it does not support clock stretching and selected bus will be limited to FAST speed. * Dynamic memory allocation, error checks, simplification, timing tweaks. * Separated the code of old driver for better compatibility and simplicity * Change of driver interface * Add bus status check in setup(); simplify getDC(); remove unnesessary lines in ACK read/write * Fix for moved doc file and trailing whitespaces --- app/driver/i2c_master.c | 601 ++++++++++++++++++++++++-------- app/include/driver/i2c_master.h | 80 +---- app/include/user_config.h | 16 + app/modules/i2c.c | 19 +- app/platform/cpu_esp8266.h | 6 + app/platform/platform.c | 28 +- app/platform/platform.h | 4 +- docs/modules/i2c.md | 135 +++++-- 8 files changed, 631 insertions(+), 258 deletions(-) diff --git a/app/driver/i2c_master.c b/app/driver/i2c_master.c index f8de4bc49b..b3ec4869da 100644 --- a/app/driver/i2c_master.c +++ b/app/driver/i2c_master.c @@ -1,20 +1,421 @@ -/****************************************************************************** - * Copyright 2013-2014 Espressif Systems (Wuxi) +/* + * ESPRESSIF MIT License * - * FileName: i2c_master.c + * Copyright (c) 2016 * - * Description: i2c master API + * Permission is hereby granted for use on ESPRESSIF SYSTEMS ESP8266 only, in which case, + * it is free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the Software is furnished + * to do so, subject to the following conditions: * - * Modification history: - * 2014/3/12, v1.0 create this file. -*******************************************************************************/ + * The above copyright notice and this permission notice shall be included in all copies or + * substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * + * Rework of original driver: Natalia Sorokina , 2018 + */ + +#include "../libc/c_stdlib.h" #include "ets_sys.h" #include "osapi.h" #include "gpio.h" +#include "user_interface.h" + +#include "cpu_esp8266.h" +#include "pin_map.h" + +#include "user_config.h" #include "driver/i2c_master.h" -#include "pin_map.h" + +#ifndef I2C_MASTER_OLD_VERSION +/****************************************************************************** +* NEW driver +* Enabled if I2C_MASTER_OLD_VERSION is not defined in user_config.h +*******************************************************************************/ +// Supports multiple i2c buses +// I2C speed in range 25kHz - 550kHz (25kHz - 1MHz if CPU at 160MHz) +// If GPIO16 is used as SCL then speed is limited to 25kHz - 400kHz +// Speed is defined for every bus separately + +// enable use GPIO16 (D0) pin as SCL line +#ifdef I2C_MASTER_GPIO16_ENABLE +#define IS_PIN16(n) ((n)==16) +// CPU_CYCLES_BETWEEN_DELAYS describes how much cpu cycles code runs +// between i2c_master_setDC() calls if delay is zero and i2c_master_set_DC_delay() +// is not being called. This is not exact value, but proportional with length of code. +// Increasing the value results in less delay and faster i2c clock speed. +#define CPU_CYCLES_BETWEEN_DELAYS 80 +// CPU_CYCLES_GPIO16 is added to CPU_CYCLES_BETWEEN_DELAYS, +// as RTC-related IO takes much more time than standard GPIOs. +// Increasing the value results in less delay and faster i2c clock speed for GPIO16. +#define CPU_CYCLES_GPIO16 90 + +#else +// If GPIO16 support is not enabled, remove GPIO16-related code during compile +// and change timing constants. +#define IS_PIN16(n) (0) +#define CPU_CYCLES_BETWEEN_DELAYS 74 +#endif //I2C_MASTER_GPIO16_ENABLE + +#define MIN_SPEED 25000 +#define MAX_NUMBER_OF_I2C NUM_I2C + +typedef struct { + uint8 last_SDA; + uint8 last_SCL; + uint8 pin_SDA; + uint8 pin_SCL; + uint32 pin_SDA_SCL_mask; + uint32 pin_SDA_mask; + uint32 pin_SCL_mask; + uint32 speed; + sint16 cycles_delay; +} i2c_master_state_t; +static i2c_master_state_t *i2c[MAX_NUMBER_OF_I2C]; + +/****************************************************************************** + * FunctionName : i2c_master_set_DC_delay + * Description : Internal used function - calculate delay for i2c_master_setDC + * Parameters : bus id + * Returns : NONE +*******************************************************************************/ +LOCAL void ICACHE_FLASH_ATTR +i2c_master_set_DC_delay(uint16 id) +{ + // [cpu cycles per half SCL clock period] - [cpu cycles that code takes to run] + i2c[id]->cycles_delay = system_get_cpu_freq() * 500000 / i2c[id]->speed - CPU_CYCLES_BETWEEN_DELAYS; + #ifdef I2C_MASTER_GPIO16_ENABLE + if(IS_PIN16(i2c[id]->pin_SCL)){ //if GPIO16 + i2c[id]->cycles_delay -= CPU_CYCLES_GPIO16; //decrease delay + } + #endif //I2C_MASTER_GPIO16_ENABLE + if(i2c[id]->cycles_delay < 0){ + i2c[id]->cycles_delay = 0; + } +} +/****************************************************************************** + * FunctionName : i2c_master_wait_cpu_cycles + * Description : Internal used function - wait for given count of cpu cycles + * Parameters : sint16 cycles_delay + * Returns : NONE +*******************************************************************************/ +static inline void i2c_master_wait_cpu_cycles(sint16 cycles_delay) +{ + uint32 cycles_start; + uint32 cycles_curr; + // uses special 'ccount' register which is increased every CPU cycle + // to make precise delay + asm volatile("rsr %0, ccount":"=a"(cycles_start)); + do{ + asm volatile("rsr %0, ccount":"=a"(cycles_curr)); + } while (cycles_curr - cycles_start < cycles_delay); +} + +/****************************************************************************** + * FunctionName : i2c_master_wait_gpio_SCL_high + * Description : Internal used function - wait until SCL line in a high state + (slave device may hold SCL line low until it is ready to proceed) + * Parameters : bus id + * Returns : NONE +*******************************************************************************/ +static inline void i2c_master_wait_gpio_SCL_high(uint16 id) +{ + // retrieves bitmask of all GPIOs from memory-mapped gpio register and exits if SCL bit is set + // equivalent, but slow variant: + // while(!(READ_PERI_REG(PERIPHS_GPIO_BASEADDR + GPIO_IN_ADDRESS) & i2c[id]->pin_SCL_mask)) {}; + // even slower: while (!(gpio_input_get() & i2c[id]->pin_SCL_mask)) {}; + asm volatile("l_wait:" + "l16ui %0, %[gpio_in_addr], 0;" //read gpio state into register %0 + "memw;" //wait for read completion + "bnall %0, %[gpio_SCL_mask], l_wait;" // test if SCL bit not set + ::[gpio_SCL_mask] "r" (i2c[id]->pin_SCL_mask), + [gpio_in_addr] "r" (PERIPHS_GPIO_BASEADDR + GPIO_IN_ADDRESS) + ); +} + +/****************************************************************************** + * FunctionName : i2c_master_setDC + * Description : Internal used function - + * set i2c SDA and SCL bit value for half clock cycle + * Parameters : bus id, uint8 SDA, uint8 SCL + * Returns : NONE +*******************************************************************************/ +LOCAL void ICACHE_FLASH_ATTR +i2c_master_setDC(uint16 id, uint8 SDA, uint8 SCL) +{ + uint32 this_SDA_SCL_set_mask; + uint32 this_SDA_SCL_clear_mask; + i2c[id]->last_SDA = SDA; + i2c[id]->last_SCL = SCL; + + if(i2c[id]->cycles_delay > 0){ + i2c_master_wait_cpu_cycles(i2c[id]->cycles_delay); + } + if (IS_PIN16(i2c[id]->pin_SCL)){ //GPIO16 wired differently, it has it's own register address + WRITE_PERI_REG(RTC_GPIO_OUT, SCL); // write SCL value + if(1 == SDA){ + GPIO_REG_WRITE(GPIO_OUT_W1TS_ADDRESS, i2c[id]->pin_SDA_mask); //SDA = 1 + }else{ + GPIO_REG_WRITE(GPIO_OUT_W1TC_ADDRESS, i2c[id]->pin_SDA_mask); // SDA = 0 + } + if(1 == SCL){ //clock stretching, GPIO16 version + while(!(READ_PERI_REG(RTC_GPIO_IN_DATA) & 1)) {}; //read SCL value until SCL goes high + }else{ + // dummy read operation and empty CPU cycles to maintain equal times for low and high state + READ_PERI_REG(RTC_GPIO_IN_DATA) & 1; asm volatile("nop;nop;nop;nop;"); + } + } + else{ + this_SDA_SCL_set_mask = (SDA << i2c[id]->pin_SDA) | (SCL << i2c[id]->pin_SCL); + this_SDA_SCL_clear_mask = i2c[id]->pin_SDA_SCL_mask ^ this_SDA_SCL_set_mask; + GPIO_REG_WRITE(GPIO_OUT_W1TC_ADDRESS, this_SDA_SCL_clear_mask); + GPIO_REG_WRITE(GPIO_OUT_W1TS_ADDRESS, this_SDA_SCL_set_mask); + if(1 == SCL) { //clock stretching + i2c_master_wait_gpio_SCL_high(id); + }else{ + asm volatile("nop;nop;nop;"); // empty CPU cycles to maintain equal times for low and high state + } + } +} + +/****************************************************************************** + * FunctionName : i2c_master_getDC + * Description : Internal used function - + * get i2c SDA bit value + * Parameters : bus id + * Returns : uint8 - SDA bit value +*******************************************************************************/ +static inline uint8 ICACHE_FLASH_ATTR +i2c_master_getDC(uint16 id) +{ + return (READ_PERI_REG(PERIPHS_GPIO_BASEADDR + GPIO_IN_ADDRESS) >> i2c[id]->pin_SDA) & 1; +} + +/****************************************************************************** + * FunctionName : i2c_master_configured + * Description : checks if i2c bus is configured + * Parameters : bus id + * Returns : boolean value, true if configured +*******************************************************************************/ +bool ICACHE_FLASH_ATTR +i2c_master_configured(uint16 id){ + return !(NULL == i2c[id]); +} + +/****************************************************************************** + * FunctionName : i2c_master_init + * Description : initialize I2C bus to enable i2c operations + (reset state of all slave devices) + * Parameters : bus id + * Returns : NONE +*******************************************************************************/ +void ICACHE_FLASH_ATTR +i2c_master_init(uint16 id) +{ + uint8 i; + + i2c_master_setDC(id, 1, 0); + + // when SCL = 0, toggle SDA to clear up + i2c_master_setDC(id, 0, 0) ; + i2c_master_setDC(id, 1, 0) ; + + // set data_cnt to max value + for (i = 0; i < 28; i++) { + i2c_master_setDC(id, 1, 0); + i2c_master_setDC(id, 1, 1); + } + + // reset all + i2c_master_stop(id); + return; +} + +/****************************************************************************** + * FunctionName : i2c_master_setup + * Description : Initializes and configures the driver on given bus ID + * Parameters : bus id + * Returns : configured speed +*******************************************************************************/ +uint32 ICACHE_FLASH_ATTR +i2c_master_setup(uint16 id, uint8 sda, uint8 scl, uint32 speed) +{ + if(NULL == i2c[id]){ + i2c[id] = (i2c_master_state_t*) c_malloc(sizeof(i2c_master_state_t)); + } + if(NULL == i2c[id]){ // if malloc failed + return 0; + } + i2c[id]->last_SDA = 1; //default idle state + i2c[id]->last_SCL = 1; + i2c[id]->pin_SDA = pin_num[sda]; + i2c[id]->pin_SCL = pin_num[scl]; + i2c[id]->pin_SDA_mask = 1 << i2c[id]->pin_SDA; + i2c[id]->pin_SCL_mask = 1 << i2c[id]->pin_SCL; + i2c[id]->pin_SDA_SCL_mask = i2c[id]->pin_SDA_mask | i2c[id]->pin_SCL_mask; + i2c[id]->speed = speed; + i2c[id]->cycles_delay = 0; + + if(i2c[id]->speed < MIN_SPEED){ + i2c[id]->speed = MIN_SPEED; + } + i2c_master_set_DC_delay(id); // recalibrate clock + + ETS_GPIO_INTR_DISABLE(); //disable gpio interrupts + + if (IS_PIN16(i2c[id]->pin_SCL)){ //if GPIO16 + CLEAR_PERI_REG_MASK(PAD_XPD_DCDC_CONF, 0x43); //disable all functions for XPD_DCDC + SET_PERI_REG_MASK(PAD_XPD_DCDC_CONF, 0x1); // select function RTC_GPIO0 for pin XPD_DCDC + CLEAR_PERI_REG_MASK(RTC_GPIO_CONF, 0x1); //mux configuration for out enable + SET_PERI_REG_MASK(RTC_GPIO_ENABLE, 0x1); //out enable + SET_PERI_REG_MASK(RTC_GPIO_OUT, 0x1); // set SCL high + } + else{ + PIN_FUNC_SELECT(pin_mux[scl], pin_func[scl]); + SET_PERI_REG_MASK(PERIPHS_GPIO_BASEADDR + GPIO_PIN_ADDR(GPIO_ID_PIN(i2c[id]->pin_SCL)), + GPIO_PIN_PAD_DRIVER_SET(GPIO_PAD_DRIVER_ENABLE)); //open drain + gpio_output_set(i2c[id]->pin_SCL_mask, 0, i2c[id]->pin_SCL_mask, 0); //enable and set high + } + PIN_FUNC_SELECT(pin_mux[sda], pin_func[sda]); + SET_PERI_REG_MASK(PERIPHS_GPIO_BASEADDR + GPIO_PIN_ADDR(GPIO_ID_PIN(i2c[id]->pin_SDA)), + GPIO_PIN_PAD_DRIVER_SET(GPIO_PAD_DRIVER_ENABLE)); //open drain + gpio_output_set(i2c[id]->pin_SDA_mask, 0, i2c[id]->pin_SDA_mask, 0); //enable and set high + + ETS_GPIO_INTR_ENABLE(); //enable gpio interrupts + + if (! (gpio_input_get() ^ i2c[id]->pin_SCL_mask)){ //SCL is in low state, bus failure + return 0; + } + i2c_master_init(id); + if (! (gpio_input_get() ^ i2c[id]->pin_SDA_mask)){ //SDA is in low state, bus failure + return 0; + } + return i2c[id]->speed; +} + +/****************************************************************************** + * FunctionName : i2c_master_start + * Description : set i2c to send state + * Parameters : bus id + * Returns : NONE +*******************************************************************************/ +void ICACHE_FLASH_ATTR +i2c_master_start(uint16 id) +{ + i2c_master_set_DC_delay(id); // recalibrate clock + i2c_master_setDC(id, 1, i2c[id]->last_SCL); + i2c_master_setDC(id, 1, 1); + i2c_master_setDC(id, 0, 1); +} + +/****************************************************************************** + * FunctionName : i2c_master_stop + * Description : set i2c to stop sending state + * Parameters : bus id + * Returns : NONE +*******************************************************************************/ +void ICACHE_FLASH_ATTR +i2c_master_stop(uint16 id) +{ + i2c_master_setDC(id, 0, i2c[id]->last_SCL); + i2c_master_setDC(id, 0, 1); + i2c_master_setDC(id, 1, 1); +} + +/****************************************************************************** + * FunctionName : i2c_master_readByte + * Description : read Byte from i2c bus + * Parameters : bus id + * Returns : uint8 - readed value +*******************************************************************************/ +uint8 ICACHE_FLASH_ATTR +i2c_master_readByte(uint16 id, sint16 ack) +{ + uint8 retVal = 0; + uint8 k; + sint8 i; + //invert and clamp ACK to 0/1, because ACK == 1 for i2c means SDA in low state + uint8 ackLevel = (ack ? 0 : 1); + + i2c_master_setDC(id, i2c[id]->last_SDA, 0); + i2c_master_setDC(id, 1, 0); + for (i = 7; i >= 0; i--) { + i2c_master_setDC(id, 1, 1); + k = i2c_master_getDC(id); + i2c_master_setDC(id, 1, 0); // unnecessary in last iteration + k <<= i; + retVal |= k; + } + // set ACK + i2c_master_setDC(id, ackLevel, 0); + i2c_master_setDC(id, ackLevel, 1); + i2c_master_setDC(id, 1, 0); + return retVal; +} + +/****************************************************************************** + * FunctionName : i2c_master_writeByte + * Description : write wrdata value(one byte) into i2c + * Parameters : bus id, uint8 wrdata - write value + * Returns : NONE +*******************************************************************************/ +uint8 ICACHE_FLASH_ATTR +i2c_master_writeByte(uint16 id, uint8 wrdata) +{ + uint8 dat; + sint8 i; + uint8 retVal; + + i2c_master_setDC(id, i2c[id]->last_SDA, 0); + for (i = 7; i >= 0; i--) { + dat = (wrdata >> i) & 1; + i2c_master_setDC(id, dat, 0); + i2c_master_setDC(id, dat, 1); + } + //get ACK + i2c_master_setDC(id, 1, 0); + i2c_master_setDC(id, 1, 1); + retVal = i2c_master_getDC(id); + i2c_master_setDC(id, 1, 0); + return ! retVal; +} + + + +#else // if defined I2C_MASTER_OLD_VERSION +/****************************************************************************** +* OLD driver +* Enabled when I2C_MASTER_OLD_VERSION is defined in user_config.h +*******************************************************************************/ + +#define I2C_MASTER_SDA_MUX (pin_mux[sda]) +#define I2C_MASTER_SCL_MUX (pin_mux[scl]) +#define I2C_MASTER_SDA_GPIO (pinSDA) +#define I2C_MASTER_SCL_GPIO (pinSCL) +#define I2C_MASTER_SDA_FUNC (pin_func[sda]) +#define I2C_MASTER_SCL_FUNC (pin_func[scl]) +#define I2C_MASTER_SDA_HIGH_SCL_HIGH() \ + gpio_output_set(1<= 0; i--) { dat = wrdata >> i; i2c_master_setDC(dat, 0); - i2c_master_wait(5); i2c_master_setDC(dat, 1); - i2c_master_wait(5); if (i == 0) { i2c_master_wait(3); //// } i2c_master_setDC(dat, 0); - i2c_master_wait(5); } + // get ACK + i2c_master_setDC(m_nLastSDA, 0); + i2c_master_setDC(1, 0); + i2c_master_setDC(1, 1); + retVal = i2c_master_getDC(); + i2c_master_wait(5); + i2c_master_setDC(1, 0); + return ! retVal; } +#endif diff --git a/app/include/driver/i2c_master.h b/app/include/driver/i2c_master.h index 18635d5f23..5a9eed193a 100644 --- a/app/include/driver/i2c_master.h +++ b/app/include/driver/i2c_master.h @@ -1,74 +1,12 @@ #ifndef __I2C_MASTER_H__ #define __I2C_MASTER_H__ -#define I2C_MASTER_SDA_MUX (pin_mux[sda]) -#define I2C_MASTER_SCL_MUX (pin_mux[scl]) -#define I2C_MASTER_SDA_GPIO (pinSDA) -#define I2C_MASTER_SCL_GPIO (pinSCL) -#define I2C_MASTER_SDA_FUNC (pin_func[sda]) -#define I2C_MASTER_SCL_FUNC (pin_func[scl]) - -// #define I2C_MASTER_SDA_MUX PERIPHS_IO_MUX_GPIO2_U -// #define I2C_MASTER_SCL_MUX PERIPHS_IO_MUX_MTDO_U -// #define I2C_MASTER_SDA_GPIO 2 -// #define I2C_MASTER_SCL_GPIO 15 -// #define I2C_MASTER_SDA_FUNC FUNC_GPIO2 -// #define I2C_MASTER_SCL_FUNC FUNC_GPIO15 - -// #define I2C_MASTER_SDA_MUX PERIPHS_IO_MUX_GPIO2_U -// #define I2C_MASTER_SCL_MUX PERIPHS_IO_MUX_MTMS_U -// #define I2C_MASTER_SDA_GPIO 2 -// #define I2C_MASTER_SCL_GPIO 14 -// #define I2C_MASTER_SDA_FUNC FUNC_GPIO2 -// #define I2C_MASTER_SCL_FUNC FUNC_GPIO14 - -//#define I2C_MASTER_SDA_MUX PERIPHS_IO_MUX_GPIO2_U -//#define I2C_MASTER_SCL_MUX PERIPHS_IO_MUX_GPIO0_U -//#define I2C_MASTER_SDA_GPIO 2 -//#define I2C_MASTER_SCL_GPIO 0 -//#define I2C_MASTER_SDA_FUNC FUNC_GPIO2 -//#define I2C_MASTER_SCL_FUNC FUNC_GPIO0 - -#if 0 -#define I2C_MASTER_GPIO_SET(pin) \ - gpio_output_set(1< Date: Fri, 5 Apr 2019 05:57:02 +0100 Subject: [PATCH 02/74] mbedtls bump to 2.7.9 (#2655) No major fixes, but was looking anyway. Specifically, to https://github.com/ARMmbed/mbedtls.git 079e813949251be1e7a9d395abd20b2c63422787 --- app/include/mbedtls/bn_mul.h | 8 ++++++- app/include/mbedtls/check_config.h | 4 ++++ app/include/mbedtls/ctr_drbg.h | 6 +++++ app/include/mbedtls/hmac_drbg.h | 6 +++++ app/include/mbedtls/pkcs12.h | 10 ++++++++ app/include/mbedtls/pkcs5.h | 10 ++++++++ app/include/mbedtls/ssl.h | 8 +++++++ app/include/mbedtls/version.h | 8 +++---- app/mbedtls/library/asn1write.c | 26 ++++++++++++++++++-- app/mbedtls/library/bignum.c | 38 ++++++++++++++++++++---------- app/mbedtls/library/pkcs12.c | 4 ++++ app/mbedtls/library/pkcs5.c | 17 +------------ 12 files changed, 109 insertions(+), 36 deletions(-) diff --git a/app/include/mbedtls/bn_mul.h b/app/include/mbedtls/bn_mul.h index 80e4b380d1..3a254aae9d 100644 --- a/app/include/mbedtls/bn_mul.h +++ b/app/include/mbedtls/bn_mul.h @@ -38,6 +38,12 @@ #ifndef MBEDTLS_BN_MUL_H #define MBEDTLS_BN_MUL_H +#if !defined(MBEDTLS_CONFIG_FILE) +#include "config.h" +#else +#include MBEDTLS_CONFIG_FILE +#endif + #include "bignum.h" #if defined(MBEDTLS_HAVE_ASM) @@ -734,7 +740,7 @@ "sw $10, %2 \n\t" \ : "=m" (c), "=m" (d), "=m" (s) \ : "m" (s), "m" (d), "m" (c), "m" (b) \ - : "$9", "$10", "$11", "$12", "$13", "$14", "$15" \ + : "$9", "$10", "$11", "$12", "$13", "$14", "$15", "lo", "hi" \ ); #endif /* MIPS */ diff --git a/app/include/mbedtls/check_config.h b/app/include/mbedtls/check_config.h index be80332963..fa7110fe92 100644 --- a/app/include/mbedtls/check_config.h +++ b/app/include/mbedtls/check_config.h @@ -122,6 +122,10 @@ #error "MBEDTLS_ECP_C defined, but not all prerequisites" #endif +#if defined(MBEDTLS_PK_PARSE_C) && !defined(MBEDTLS_ASN1_PARSE_C) +#error "MBEDTLS_PK_PARSE_C defined, but not all prerequesites" +#endif + #if defined(MBEDTLS_ENTROPY_C) && (!defined(MBEDTLS_SHA512_C) && \ !defined(MBEDTLS_SHA256_C)) #error "MBEDTLS_ENTROPY_C defined, but not all prerequisites" diff --git a/app/include/mbedtls/ctr_drbg.h b/app/include/mbedtls/ctr_drbg.h index 2b4dc73d3f..5a32843152 100644 --- a/app/include/mbedtls/ctr_drbg.h +++ b/app/include/mbedtls/ctr_drbg.h @@ -28,6 +28,12 @@ #ifndef MBEDTLS_CTR_DRBG_H #define MBEDTLS_CTR_DRBG_H +#if !defined(MBEDTLS_CONFIG_FILE) +#include "config.h" +#else +#include MBEDTLS_CONFIG_FILE +#endif + #include "aes.h" #if defined(MBEDTLS_THREADING_C) diff --git a/app/include/mbedtls/hmac_drbg.h b/app/include/mbedtls/hmac_drbg.h index dd31fc8fdd..f58b1e31d8 100644 --- a/app/include/mbedtls/hmac_drbg.h +++ b/app/include/mbedtls/hmac_drbg.h @@ -24,6 +24,12 @@ #ifndef MBEDTLS_HMAC_DRBG_H #define MBEDTLS_HMAC_DRBG_H +#if !defined(MBEDTLS_CONFIG_FILE) +#include "config.h" +#else +#include MBEDTLS_CONFIG_FILE +#endif + #include "md.h" #if defined(MBEDTLS_THREADING_C) diff --git a/app/include/mbedtls/pkcs12.h b/app/include/mbedtls/pkcs12.h index a621ef5b15..d441357b7f 100644 --- a/app/include/mbedtls/pkcs12.h +++ b/app/include/mbedtls/pkcs12.h @@ -24,6 +24,12 @@ #ifndef MBEDTLS_PKCS12_H #define MBEDTLS_PKCS12_H +#if !defined(MBEDTLS_CONFIG_FILE) +#include "config.h" +#else +#include MBEDTLS_CONFIG_FILE +#endif + #include "md.h" #include "cipher.h" #include "asn1.h" @@ -46,6 +52,8 @@ extern "C" { #endif +#if defined(MBEDTLS_ASN1_PARSE_C) + /** * \brief PKCS12 Password Based function (encryption / decryption) * for pbeWithSHAAnd128BitRC4 @@ -87,6 +95,8 @@ int mbedtls_pkcs12_pbe( mbedtls_asn1_buf *pbe_params, int mode, const unsigned char *input, size_t len, unsigned char *output ); +#endif /* MBEDTLS_ASN1_PARSE_C */ + /** * \brief The PKCS#12 derivation function uses a password and a salt * to produce pseudo-random bits for a particular "purpose". diff --git a/app/include/mbedtls/pkcs5.h b/app/include/mbedtls/pkcs5.h index 9a3c9fddcc..f201250046 100644 --- a/app/include/mbedtls/pkcs5.h +++ b/app/include/mbedtls/pkcs5.h @@ -26,6 +26,12 @@ #ifndef MBEDTLS_PKCS5_H #define MBEDTLS_PKCS5_H +#if !defined(MBEDTLS_CONFIG_FILE) +#include "config.h" +#else +#include MBEDTLS_CONFIG_FILE +#endif + #include "asn1.h" #include "md.h" @@ -44,6 +50,8 @@ extern "C" { #endif +#if defined(MBEDTLS_ASN1_PARSE_C) + /** * \brief PKCS#5 PBES2 function * @@ -62,6 +70,8 @@ int mbedtls_pkcs5_pbes2( const mbedtls_asn1_buf *pbe_params, int mode, const unsigned char *data, size_t datalen, unsigned char *output ); +#endif /* MBEDTLS_ASN1_PARSE_C */ + /** * \brief PKCS#5 PBKDF2 using HMAC * diff --git a/app/include/mbedtls/ssl.h b/app/include/mbedtls/ssl.h index db8b85f612..5593a5282a 100644 --- a/app/include/mbedtls/ssl.h +++ b/app/include/mbedtls/ssl.h @@ -1618,6 +1618,14 @@ void mbedtls_ssl_conf_ca_chain( mbedtls_ssl_config *conf, * whether it matches those preferences - the server can then * decide what it wants to do with it. * + * \note The provided \p pk_key needs to match the public key in the + * first certificate in \p own_cert, or all handshakes using + * that certificate will fail. It is your responsibility + * to ensure that; this function will not perform any check. + * You may use mbedtls_pk_check_pair() in order to perform + * this check yourself, but be aware that this function can + * be computationally expensive on some key types. + * * \param conf SSL configuration * \param own_cert own public certificate chain * \param pk_key own private key diff --git a/app/include/mbedtls/version.h b/app/include/mbedtls/version.h index d54d56f766..36feff0d82 100644 --- a/app/include/mbedtls/version.h +++ b/app/include/mbedtls/version.h @@ -40,16 +40,16 @@ */ #define MBEDTLS_VERSION_MAJOR 2 #define MBEDTLS_VERSION_MINOR 7 -#define MBEDTLS_VERSION_PATCH 8 +#define MBEDTLS_VERSION_PATCH 9 /** * The single version number has the following structure: * MMNNPP00 * Major version | Minor version | Patch version */ -#define MBEDTLS_VERSION_NUMBER 0x02070800 -#define MBEDTLS_VERSION_STRING "2.7.8" -#define MBEDTLS_VERSION_STRING_FULL "mbed TLS 2.7.8" +#define MBEDTLS_VERSION_NUMBER 0x02070900 +#define MBEDTLS_VERSION_STRING "2.7.9" +#define MBEDTLS_VERSION_STRING_FULL "mbed TLS 2.7.9" #if defined(MBEDTLS_VERSION_C) diff --git a/app/mbedtls/library/asn1write.c b/app/mbedtls/library/asn1write.c index c8db8beae4..c13e85e56a 100644 --- a/app/mbedtls/library/asn1write.c +++ b/app/mbedtls/library/asn1write.c @@ -331,14 +331,36 @@ int mbedtls_asn1_write_octet_string( unsigned char **p, unsigned char *start, return( (int) len ); } -mbedtls_asn1_named_data *mbedtls_asn1_store_named_data( mbedtls_asn1_named_data **head, + +/* This is a copy of the ASN.1 parsing function mbedtls_asn1_find_named_data(), + * which is replicated to avoid a dependency ASN1_WRITE_C on ASN1_PARSE_C. */ +static mbedtls_asn1_named_data *asn1_find_named_data( + mbedtls_asn1_named_data *list, + const char *oid, size_t len ) +{ + while( list != NULL ) + { + if( list->oid.len == len && + memcmp( list->oid.p, oid, len ) == 0 ) + { + break; + } + + list = list->next; + } + + return( list ); +} + +mbedtls_asn1_named_data *mbedtls_asn1_store_named_data( + mbedtls_asn1_named_data **head, const char *oid, size_t oid_len, const unsigned char *val, size_t val_len ) { mbedtls_asn1_named_data *cur; - if( ( cur = mbedtls_asn1_find_named_data( *head, oid, oid_len ) ) == NULL ) + if( ( cur = asn1_find_named_data( *head, oid, oid_len ) ) == NULL ) { // Add new entry if not present yet based on OID // diff --git a/app/mbedtls/library/bignum.c b/app/mbedtls/library/bignum.c index 18daea2589..ba817bebf5 100644 --- a/app/mbedtls/library/bignum.c +++ b/app/mbedtls/library/bignum.c @@ -500,26 +500,38 @@ int mbedtls_mpi_read_string( mbedtls_mpi *X, int radix, const char *s ) } /* - * Helper to write the digits high-order first + * Helper to write the digits high-order first. */ -static int mpi_write_hlp( mbedtls_mpi *X, int radix, char **p ) +static int mpi_write_hlp( mbedtls_mpi *X, int radix, + char **p, const size_t buflen ) { int ret; mbedtls_mpi_uint r; + size_t length = 0; + char *p_end = *p + buflen; - if( radix < 2 || radix > 16 ) - return( MBEDTLS_ERR_MPI_BAD_INPUT_DATA ); + do + { + if( length >= buflen ) + { + return( MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL ); + } - MBEDTLS_MPI_CHK( mbedtls_mpi_mod_int( &r, X, radix ) ); - MBEDTLS_MPI_CHK( mbedtls_mpi_div_int( X, NULL, X, radix ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_mod_int( &r, X, radix ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_div_int( X, NULL, X, radix ) ); + /* + * Write the residue in the current position, as an ASCII character. + */ + if( r < 0xA ) + *(--p_end) = (char)( '0' + r ); + else + *(--p_end) = (char)( 'A' + ( r - 0xA ) ); - if( mbedtls_mpi_cmp_int( X, 0 ) != 0 ) - MBEDTLS_MPI_CHK( mpi_write_hlp( X, radix, p ) ); + length++; + } while( mbedtls_mpi_cmp_int( X, 0 ) != 0 ); - if( r < 10 ) - *(*p)++ = (char)( r + 0x30 ); - else - *(*p)++ = (char)( r + 0x37 ); + memmove( *p, p_end, length ); + *p += length; cleanup: @@ -589,7 +601,7 @@ int mbedtls_mpi_write_string( const mbedtls_mpi *X, int radix, if( T.s == -1 ) T.s = 1; - MBEDTLS_MPI_CHK( mpi_write_hlp( &T, radix, &p ) ); + MBEDTLS_MPI_CHK( mpi_write_hlp( &T, radix, &p, buflen ) ); } *p++ = '\0'; diff --git a/app/mbedtls/library/pkcs12.c b/app/mbedtls/library/pkcs12.c index c603a13577..5e8b2879a0 100644 --- a/app/mbedtls/library/pkcs12.c +++ b/app/mbedtls/library/pkcs12.c @@ -52,6 +52,8 @@ static void mbedtls_zeroize( void *v, size_t n ) { volatile unsigned char *p = v; while( n-- ) *p++ = 0; } +#if defined(MBEDTLS_ASN1_PARSE_C) + static int pkcs12_parse_pbe_params( mbedtls_asn1_buf *params, mbedtls_asn1_buf *salt, int *iterations ) { @@ -230,6 +232,8 @@ int mbedtls_pkcs12_pbe( mbedtls_asn1_buf *pbe_params, int mode, return( ret ); } +#endif /* MBEDTLS_ASN1_PARSE_C */ + static void pkcs12_fill_buffer( unsigned char *data, size_t data_len, const unsigned char *filler, size_t fill_len ) { diff --git a/app/mbedtls/library/pkcs5.c b/app/mbedtls/library/pkcs5.c index f04f0ab25e..50133435ce 100644 --- a/app/mbedtls/library/pkcs5.c +++ b/app/mbedtls/library/pkcs5.c @@ -54,22 +54,7 @@ #define mbedtls_printf printf #endif -#if !defined(MBEDTLS_ASN1_PARSE_C) -int mbedtls_pkcs5_pbes2( const mbedtls_asn1_buf *pbe_params, int mode, - const unsigned char *pwd, size_t pwdlen, - const unsigned char *data, size_t datalen, - unsigned char *output ) -{ - ((void) pbe_params); - ((void) mode); - ((void) pwd); - ((void) pwdlen); - ((void) data); - ((void) datalen); - ((void) output); - return( MBEDTLS_ERR_PKCS5_FEATURE_UNAVAILABLE ); -} -#else +#if defined(MBEDTLS_ASN1_PARSE_C) static int pkcs5_parse_pbkdf2_params( const mbedtls_asn1_buf *params, mbedtls_asn1_buf *salt, int *iterations, int *keylen, mbedtls_md_type_t *md_type ) From b6cd2c3edd258e52618a7dfde6c0666f4b956393 Mon Sep 17 00:00:00 2001 From: Nathaniel Wesley Filardo Date: Fri, 5 Apr 2019 15:55:07 +0100 Subject: [PATCH 03/74] Remove moribund C ds18b20 module (#2492) Just use Lua speaking OW (via C) instead. --- app/include/user_modules.h | 1 - app/modules/ds18b20.c | 305 ------------------------------------- docs/modules/ds18b20.md | 137 ----------------- mkdocs.yml | 1 - 4 files changed, 444 deletions(-) delete mode 100644 app/modules/ds18b20.c delete mode 100644 docs/modules/ds18b20.md diff --git a/app/include/user_modules.h b/app/include/user_modules.h index 009accd9e0..2818ed7f16 100644 --- a/app/include/user_modules.h +++ b/app/include/user_modules.h @@ -22,7 +22,6 @@ //#define LUA_USE_MODULES_CRON //#define LUA_USE_MODULES_CRYPTO #define LUA_USE_MODULES_DHT -//#define LUA_USE_MODULES_DS18B20 //#define LUA_USE_MODULES_ENCODER //#define LUA_USE_MODULES_ENDUSER_SETUP // USE_DNS in dhcpserver.h needs to be enabled for this module to work. #define LUA_USE_MODULES_FILE diff --git a/app/modules/ds18b20.c b/app/modules/ds18b20.c deleted file mode 100644 index 4e58da1153..0000000000 --- a/app/modules/ds18b20.c +++ /dev/null @@ -1,305 +0,0 @@ -//*************************************************************************** -// DS18B20 module for ESP8266 with nodeMCU -// fetchbot @github -// MIT license, http://opensource.org/licenses/MIT -//*************************************************************************** - -#include "module.h" -#include "lauxlib.h" -#include "platform.h" -#include "osapi.h" -#include "driver/onewire.h" -#include "c_stdio.h" -#include "c_stdlib.h" - -//*************************************************************************** -// OW ROM COMMANDS -//*************************************************************************** - -#define DS18B20_ROM_SEARCH (0xF0) -#define DS18B20_ROM_READ (0x33) -#define DS18B20_ROM_MATCH (0x55) -#define DS18B20_ROM_SKIP (0xCC) -#define DS18B20_ROM_SEARCH_ALARM (0xEC) - -//*************************************************************************** -// OW FUNCTION COMMANDS -//*************************************************************************** - -#define DS18B20_FUNC_CONVERT (0x44) -#define DS18B20_FUNC_SCRATCH_WRITE (0x4E) -#define DS18B20_FUNC_SCRATCH_READ (0xBE) -#define DS18B20_FUNC_SCRATCH_COPY (0x48) -#define DS18B20_FUNC_E2_RECALL (0xB8) -#define DS18B20_FUNC_POWER_READ (0xB4) - -//*************************************************************************** -// Initial EEPROM values -//*************************************************************************** - -#define DS18B20_EEPROM_TH (0x4B) // 75 degree -#define DS18B20_EEPROM_TL (0x46) // 70 degree -#define DS18B20_EEPROM_RES (0x7F) // 12 bit resolution - -//*************************************************************************** - -static uint8_t ds18b20_bus_pin; -static uint8_t ds18b20_device_family; -static uint8_t ds18b20_device_search = 0; -static uint8_t ds18b20_device_index; -static uint8_t ds18b20_device_par; -static uint8_t ds18b20_device_conf[3]; -static uint8_t ds18b20_device_rom[8]; -static uint8_t ds18b20_device_scratchpad[9]; -static double ds18b20_device_scratchpad_temp; -static int ds18b20_device_scratchpad_temp_dec; -static uint8_t ds18b20_device_scratchpad_conf; -static uint8_t ds18b20_device_res = 12; // 12 bit resolution (750ms conversion time) - -os_timer_t ds18b20_timer; // timer for conversion delay -int ds18b20_timer_ref; // callback when readout is ready - -int ds18b20_table_ref; -static int ds18b20_table_offset; - -static int ds18b20_lua_readoutdone(void); - -// Setup onewire bus for DS18B20 temperature sensors -// Lua: ds18b20.setup(OW_BUS_PIN) -static int ds18b20_lua_setup(lua_State *L) { - - platform_print_deprecation_note("ds18b20 C module superseded by Lua implementation", "soon"); - - // check ow bus pin value - if (!lua_isnumber(L, 1) || lua_isnumber(L, 1) == 0) { - return luaL_error(L, "wrong 1-wire pin"); - } - - ds18b20_bus_pin = luaL_checkinteger(L, 1); - MOD_CHECK_ID(ow, ds18b20_bus_pin); - onewire_init(ds18b20_bus_pin); -} - -static int ds18b20_set_device(uint8_t *ds18b20_device_rom) { - onewire_reset(ds18b20_bus_pin); - onewire_select(ds18b20_bus_pin, ds18b20_device_rom); - onewire_write(ds18b20_bus_pin, DS18B20_FUNC_SCRATCH_WRITE, 0); - onewire_write_bytes(ds18b20_bus_pin, ds18b20_device_conf, 3, 0); -} - -// Change sensor settings -// Lua: ds18b20.setting(ROM, RES) -static int ds18b20_lua_setting(lua_State *L) { - // check rom table and resolution setting - if (!lua_istable(L, 1) || !lua_isnumber(L, 2)) { - return luaL_error(L, "wrong arg range"); - } - - ds18b20_device_res = luaL_checkinteger(L, 2); - - if (!((ds18b20_device_res == 9) || (ds18b20_device_res == 10) || (ds18b20_device_res == 11) || (ds18b20_device_res == 12))) { - return luaL_error(L, "Invalid argument: resolution"); - } - - // no change to th and tl setting - ds18b20_device_conf[0] = DS18B20_EEPROM_TH; - ds18b20_device_conf[1] = DS18B20_EEPROM_TL; - ds18b20_device_conf[2] = ((ds18b20_device_res - 9) << 5) + 0x1F; - - uint8_t table_len = lua_objlen(L, 1); - - const char *str[table_len]; - const char *sep = ":"; - - uint8_t string_index = 0; - - lua_pushnil(L); - while (lua_next(L, -3)) { - str[string_index] = lua_tostring(L, -1); - lua_pop(L, 1); - string_index++; - } - lua_pop(L, 1); - - for (uint8_t i = 0; i < string_index; i++) { - for (uint8_t j = 0; j < 8; j++) { - ds18b20_device_rom[j] = strtoul(str[i], NULL, 16); - str[i] = strchr(str[i], *sep); - if (str[i] == NULL || *str[i] == '\0') break; - str[i]++; - } - ds18b20_set_device(ds18b20_device_rom); - } - - // set conversion delay once to max if sensors with higher resolution still on the bus - ds18b20_device_res = 12; - - return 0; -} - -#include "pm/swtimer.h" - -// Reads sensor values from all devices -// Lua: ds18b20.read(function(INDEX, ROM, RES, TEMP, TEMP_DEC, PAR) print(INDEX, ROM, RES, TEMP, TEMP_DEC, PAR) end, ROM[, FAMILY]) -static int ds18b20_lua_read(lua_State *L) { - - luaL_argcheck(L, (lua_type(L, 1) == LUA_TFUNCTION || lua_type(L, 1) == LUA_TLIGHTFUNCTION), 1, "Must be function"); - - lua_pushvalue(L, 1); - ds18b20_timer_ref = luaL_ref(L, LUA_REGISTRYINDEX); - - if (!lua_istable(L, 2)) { - return luaL_error(L, "wrong arg range"); - } - - if (lua_isnumber(L, 3)) { - ds18b20_device_family = luaL_checkinteger(L, 3); - onewire_target_search(ds18b20_bus_pin, ds18b20_device_family); - ds18b20_table_offset = -3; - } else { - ds18b20_table_offset = -2; - } - - lua_pushvalue(L, 2); - ds18b20_table_ref = luaL_ref(L, LUA_REGISTRYINDEX); - - lua_pushnil(L); - if (lua_next(L, ds18b20_table_offset)) { - lua_pop(L, 2); - ds18b20_device_search = 0; - } else { - ds18b20_device_search = 1; - } - - os_timer_disarm(&ds18b20_timer); - - // perform a temperature conversion for all sensors and set timer - onewire_reset(ds18b20_bus_pin); - onewire_write(ds18b20_bus_pin, DS18B20_ROM_SKIP, 0); - onewire_write(ds18b20_bus_pin, DS18B20_FUNC_CONVERT, 1); - os_timer_setfn(&ds18b20_timer, (os_timer_func_t *)ds18b20_lua_readoutdone, NULL); - SWTIMER_REG_CB(ds18b20_lua_readoutdone, SWTIMER_DROP); - //The function ds18b20_lua_readoutdone reads the temperature from the sensor(s) after a set amount of time depending on temperature resolution - //MY guess: If this timer manages to get suspended before it fires and the temperature data is time sensitive then resulting data would be invalid and should be discarded - - switch (ds18b20_device_res) { - case (9): - os_timer_arm(&ds18b20_timer, 95, 0); - break; - case (10): - os_timer_arm(&ds18b20_timer, 190, 0); - break; - case (11): - os_timer_arm(&ds18b20_timer, 380, 0); - break; - case (12): - os_timer_arm(&ds18b20_timer, 760, 0); - break; - } -} - -static int ds18b20_read_device(uint8_t *ds18b20_device_rom) { - lua_State *L = lua_getstate(); - int16_t ds18b20_raw_temp; - - if (onewire_crc8(ds18b20_device_rom,7) == ds18b20_device_rom[7]) { - - onewire_reset(ds18b20_bus_pin); - onewire_select(ds18b20_bus_pin, ds18b20_device_rom); - onewire_write(ds18b20_bus_pin, DS18B20_FUNC_POWER_READ, 0); - - if (onewire_read(ds18b20_bus_pin)) ds18b20_device_par = 0; - else ds18b20_device_par = 1; - - onewire_reset(ds18b20_bus_pin); - onewire_select(ds18b20_bus_pin, ds18b20_device_rom); - onewire_write(ds18b20_bus_pin, DS18B20_FUNC_SCRATCH_READ, 0); - onewire_read_bytes(ds18b20_bus_pin, ds18b20_device_scratchpad, 9); - - if (onewire_crc8(ds18b20_device_scratchpad,8) == ds18b20_device_scratchpad[8]) { - - lua_rawgeti(L, LUA_REGISTRYINDEX, ds18b20_timer_ref); - - lua_pushinteger(L, ds18b20_device_index); - - lua_pushfstring(L, "%d:%d:%d:%d:%d:%d:%d:%d", ds18b20_device_rom[0], ds18b20_device_rom[1], ds18b20_device_rom[2], ds18b20_device_rom[3], ds18b20_device_rom[4], ds18b20_device_rom[5], ds18b20_device_rom[6], ds18b20_device_rom[7]); - - ds18b20_device_scratchpad_conf = (ds18b20_device_scratchpad[4] >> 5) + 9; - ds18b20_raw_temp = ((ds18b20_device_scratchpad[1] << 8) | ds18b20_device_scratchpad[0]); - ds18b20_device_scratchpad_temp = (double)ds18b20_raw_temp / 16; - ds18b20_device_scratchpad_temp_dec = (ds18b20_raw_temp - (ds18b20_raw_temp / 16 * 16)) * 1000 / 16; - - if (ds18b20_device_scratchpad_conf >= ds18b20_device_res) { - ds18b20_device_res = ds18b20_device_scratchpad_conf; - } - - lua_pushinteger(L, ds18b20_device_scratchpad_conf); - lua_pushnumber(L, ds18b20_device_scratchpad_temp); - lua_pushinteger(L, ds18b20_device_scratchpad_temp_dec); - - lua_pushinteger(L, ds18b20_device_par); - - lua_pcall(L, 6, 0, 0); - - ds18b20_device_index++; - } - } -} - -static int ds18b20_lua_readoutdone(void) { - - lua_State *L = lua_getstate(); - os_timer_disarm(&ds18b20_timer); - - ds18b20_device_index = 1; - // set conversion delay to min and change it after finding the sensor with the highest resolution setting - ds18b20_device_res = 9; - - if (ds18b20_device_search) { - // iterate through all sensors on the bus and read temperature, resolution and parasitc settings - while (onewire_search(ds18b20_bus_pin, ds18b20_device_rom)) { - ds18b20_read_device(ds18b20_device_rom); - } - } else { - lua_rawgeti(L, LUA_REGISTRYINDEX, ds18b20_table_ref); - uint8_t table_len = lua_objlen(L, -1); - - const char *str[table_len]; - const char *sep = ":"; - - uint8_t string_index = 0; - - lua_pushnil(L); - while (lua_next(L, -2)) { - str[string_index] = lua_tostring(L, -1); - lua_pop(L, 1); - string_index++; - } - lua_pop(L, 1); - - for (uint8_t i = 0; i < string_index; i++) { - for (uint8_t j = 0; j < 8; j++) { - ds18b20_device_rom[j] = strtoul(str[i], NULL, 16); - str[i] = strchr(str[i], *sep); - if (str[i] == NULL || *str[i] == '\0') break; - str[i]++; - } - ds18b20_read_device(ds18b20_device_rom); - } - } - - luaL_unref(L, LUA_REGISTRYINDEX, ds18b20_table_ref); - ds18b20_table_ref = LUA_NOREF; - - luaL_unref(L, LUA_REGISTRYINDEX, ds18b20_timer_ref); - ds18b20_timer_ref = LUA_NOREF; -} - -static const LUA_REG_TYPE ds18b20_map[] = { - { LSTRKEY( "read" ), LFUNCVAL(ds18b20_lua_read) }, - { LSTRKEY( "setting" ), LFUNCVAL(ds18b20_lua_setting) }, - { LSTRKEY( "setup" ), LFUNCVAL(ds18b20_lua_setup) }, - { LNILKEY, LNILVAL } -}; - -NODEMCU_MODULE(DS18B20, "ds18b20", ds18b20_map, NULL); diff --git a/docs/modules/ds18b20.md b/docs/modules/ds18b20.md deleted file mode 100644 index 33effd21d8..0000000000 --- a/docs/modules/ds18b20.md +++ /dev/null @@ -1,137 +0,0 @@ -# DS18B20 Module -| Since | Origin / Contributor | Maintainer | Source | -| :----- | :-------------------- | :---------- | :------ | -| 2017-06-11 | [fetchbot](https://github.com/fetchbot) | [fetchbot](https://github.com/fetchbot) | [ds18b20.c](../../app/modules/ds18b20.c)| - -This module provides access to the DS18B20 1-Wire digital thermometer. - -## Deprecation Notice - -Note that NodeMCU offers both a C module (this one) and [a Lua module for this -sensor](https://github.com/nodemcu/nodemcu-firmware/tree/dev/lua_modules/ds18b20). -The C implementation is deprecated and will be removed soon; please transition -to Lua code. - -## ds18b20.read() -Issues a temperature conversion of all connected sensors on the onewire bus and returns the measurment results after a conversion delay in a callback function. -The returned measurements can be filtered through the ROM addresses passed as a table or by the family type. -The callback function gets invoked for every specified sensor. - -#### Syntax -`ds18b20.read(CALLBACK, ROM[, FAMILY_ADDRESS])` - -#### Parameters -- `CALLBACK` callback function executed for each sensor - * e.g. `function(INDEX, ROM, RES, TEMP, TEMP_DEC, PAR) print(INDEX, ROM, RES, TEMP, TEMP_DEC, PAR) end` -- `ROM` table which contains the addresses for the specified sensors, or left empty to perform a onewire bus search for all sensors - * e.g. `{"28:FF:FF:FF:FF:FF:FF:FF","28:FF:FF:FF:FF:FF:FF:FF"}`, `{}` -- `FAMILY_ADDRESS` optional to limit the search for devices to a specific family type - * e.g `0x28` - -#### Returns -`nil` - -#### Callback function parameters -- `INDEX` index of the sensor on the bus -- `ROM` sensors 64-bit lasered rom code - * `28:FF:FF:FF:FF:FF:FF:FF` LSB, 8-bit family code, 48-bit serial number, MSB 8-bit crc -- `RES` temperature resolution -- `TEMP` temperature -- `TEMP_DEC` temperature decimals for integer firmware -- `PAR` sensor parasitic flag - -!!! note - - If using float firmware then `temp` is a floating point number. On an integer firmware, the final value has to be concatenated from `temp` and `temp_dec`. - -#### Example -```lua -local ow_pin = 3 -ds18b20.setup(ow_pin) - --- read all sensors and print all measurement results -ds18b20.read( - function(ind,rom,res,temp,tdec,par) - print(ind,string.format("%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X",string.match(rom,"(%d+):(%d+):(%d+):(%d+):(%d+):(%d+):(%d+):(%d+)")),res,temp,tdec,par) - end,{}); - --- read only sensors with family type 0x28 and print all measurement results -ds18b20.read( - function(ind,rom,res,temp,tdec,par) - print(ind,string.format("%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X",string.match(rom,"(%d+):(%d+):(%d+):(%d+):(%d+):(%d+):(%d+):(%d+)")),res,temp,tdec,par) - end,{},0x28); - --- save device roms in a variable -local addr = {} -ds18b20.read( - function(ind,rom,res,temp,tdec,par) - addr[ind] = {string.format("%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X",string.match(rom,"(%d+):(%d+):(%d+):(%d+):(%d+):(%d+):(%d+):(%d+)"))} - end,{}); - --- read only sensors listed in the variable addr -ds18b20.read( - function(ind,rom,res,temp,tdec,par) - print(ind,string.format("%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X",string.match(rom,"(%d+):(%d+):(%d+):(%d+):(%d+):(%d+):(%d+):(%d+)")),res,temp,tdec,par) - end,addr); - --- print only parasitic sensors -ds18b20.read( - function(ind,rom,res,temp,tdec,par) - if (par == 1) then - print(ind,string.format("%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X",string.match(rom,"(%d+):(%d+):(%d+):(%d+):(%d+):(%d+):(%d+):(%d+)")),res,temp,tdec,par) - end - end,{}); - --- print if temperature is greater or less than a defined value -ds18b20.read( - function(ind,rom,res,temp,tdec,par) - if (t > 25) then - print(ind,string.format("%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X",string.match(rom,"(%d+):(%d+):(%d+):(%d+):(%d+):(%d+):(%d+):(%d+)")),res,temp,tdec,par) - end - if (t < 20) then - print(ind,string.format("%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X",string.match(rom,"(%d+):(%d+):(%d+):(%d+):(%d+):(%d+):(%d+):(%d+)")),res,temp,tdec,par) - end - end,{}); -``` - -## ds18b20.setting() -Configuration of the temperature resolution settings. - -#### Syntax -`ds18b20.setting(ROM, RES)` - -#### Parameters -- `ROM` table which contains the addresses for the specified sensors, or empty for all sensors - * e.g. `{"28:FF:FF:FF:FF:FF:FF:FF","28:FF:FF:FF:FF:FF:FF:FF"}`, `{}` -- `RES` temperature bit resolution - * `9` - `12` - -#### Returns -`nil` - -#### Example -```lua -local ow_pin = 3 -ds18b20.setup(ow_pin) - -ds18b20.setting({"28:FF:FF:FF:FF:FF:FF:FF","28:FF:FF:FF:FF:FF:FF:FF"}, 9) -``` - -## ds18b20.setup() -Initializes the onewire bus on the selected pin. - -#### Syntax -`ds18b20.setup(OW_BUS_PIN)` - -#### Parameters -- `OW_BUS_PIN` - * `1` - `12` - -#### Returns -`nil` - -#### Example -```lua -local ow_pin = 3 -ds18b20.setup(ow_pin) -``` diff --git a/mkdocs.yml b/mkdocs.yml index 4b2b1f2c13..746c8929ff 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -68,7 +68,6 @@ pages: - 'cron': 'modules/cron.md' - 'crypto': 'modules/crypto.md' - 'dht': 'modules/dht.md' - - 'ds18b20': 'modules/ds18b20.md' - 'encoder': 'modules/encoder.md' - 'enduser setup': 'modules/enduser-setup.md' - 'file': 'modules/file.md' From 9a471079209a5039305946d57a43c8758d94ccf9 Mon Sep 17 00:00:00 2001 From: Terry Ellison Date: Fri, 5 Apr 2019 16:01:45 +0100 Subject: [PATCH 04/74] SDK 3.0 release (#2692) * Rebaseline firmware to non-OS SDK version 3.0 * Note that SDK version 3.0 introduces the concept of a Flash Partition Table(PT). This is located at Flash offset 0x10000 in our firmware build. * The firmware is now PT aware with both LFS and SPIFFS taking their partition size and location from the PT * A new tool `tools/nodemcu-partition.py` is now used to initialise these data and can also download LFS and SPIFFS images to these partitions. --- Makefile | 61 +- app/Makefile | 3 +- app/esp-gdbstub/gdbstub.c | 17 +- app/include/lwip/mem.h | 27 +- app/include/user_config.h | 30 +- app/libc/c_math.c | 29 +- app/lua/ldblib.c | 6 +- app/lua/lflash.c | 45 +- app/lua/lflash.h | 2 +- app/lua/lgc.c | 4 - app/lua/lgc.h | 2 +- app/lua/lobject.h | 2 - app/lua/lstate.c | 5 +- app/lua/lstate.h | 3 +- app/lua/lstring.c | 2 +- app/lua/lua.c | 2 - app/lua/luac_cross/lflashimg.c | 2 - app/modules/node.c | 8 - app/modules/rtctime.c | 4 +- app/platform/flash_api.c | 176 +---- app/platform/flash_api.h | 6 +- app/platform/platform.c | 9 + app/platform/platform.h | 1 + app/platform/vfs.c | 11 +- app/spiffs/Makefile | 1 + app/spiffs/myspiffs.h | 20 - app/spiffs/spiffs.c | 176 ++--- app/spiffs/spiffs_config.h | 2 +- app/user/user_exceptions.c | 115 --- app/user/user_main.c | 289 ++++---- docs/compiling.md | 9 +- docs/getting-started.md | 31 +- docs/modules/node.md | 2 +- ld/nodemcu.ld | 14 +- sdk-overrides/include/mem.h | 11 - tools/esptool.py | 1236 -------------------------------- tools/nodemcu-partition.py | 286 ++++++++ 37 files changed, 717 insertions(+), 1932 deletions(-) delete mode 100644 app/spiffs/myspiffs.h delete mode 100644 app/user/user_exceptions.c delete mode 100644 sdk-overrides/include/mem.h delete mode 100755 tools/esptool.py create mode 100755 tools/nodemcu-partition.py diff --git a/Makefile b/Makefile index fbcbcda64b..de3376b35e 100644 --- a/Makefile +++ b/Makefile @@ -5,20 +5,14 @@ TOOLCHAIN_VERSION:=20181106.0 # SDK base version, as released by Espressif -SDK_BASE_VER:=2.2.1 - -# no patch: SDK_VER equals SDK_BASE_VER and sdk dir depends on sdk_extracted +SDK_BASE_VER:=3.0 SDK_VER:=$(SDK_BASE_VER) SDK_DIR_DEPENDS:=sdk_extracted -# with patch: SDK_VER differs from SDK_BASE_VER and sdk dir depends on sdk_patched -#SDK_PATCH_VER:=f8f27ce -#SDK_VER:=$(SDK_BASE_VER)-$(SDK_PATCH_VER) -#SDK_DIR_DEPENDS:=sdk_patched - SDK_FILE_VER:=$(SDK_BASE_VER) -SDK_FILE_SHA1:=48f2242d5895823709f222bf0fffce9d525996c8 -# SDK_PATCH_SHA1:=0bc21ec77b08488f04d3e1c9d161b711d07201a8 +SDK_FILE_SHA1:=029fc23fe87e03c9852de636490b2d7b9e07f01a +ESPTOOL_VER:=2.6 + # Ensure we search "our" SDK before the tool-chain's SDK (if any) TOP_DIR:=$(abspath $(dir $(lastword $(MAKEFILE_LIST)))) SDK_REL_DIR=sdk/esp_iot_sdk_v$(SDK_VER) @@ -109,6 +103,7 @@ else CPP = $(WRAPCC) xtensa-lx106-elf-gcc -E OBJCOPY = xtensa-lx106-elf-objcopy FIRMWAREDIR = ../bin/ + WGET = wget --tries=10 --timeout=15 --waitretry=30 --read-timeout=20 --retry-connrefused UNAME_S := $(shell uname -s) ifeq ($(UNAME_S),Linux) # LINUX @@ -128,8 +123,12 @@ else endif endif ############################################################# -ESPTOOL ?= ../tools/esptool.py +GITHUB_TOOLCHAIN = https://github.com/jmattsson/esp-toolchains +GITHUB_SDK = https://github.com/espressif/ESP8266_NONOS_SDK +GITHUB_ESPTOOL = https://github.com/espressif/esptool + +ESPTOOL ?= $(TOP_DIR)/tools/toolchains/esptool.py CSRCS ?= $(wildcard *.c) CXXSRCS ?= $(wildcard *.cpp) @@ -234,18 +233,16 @@ $(BINODIR)/%.bin: $(IMAGEODIR)/%.out all: toolchain sdk_pruned pre_build .subdirs $(OBJS) $(OLIBS) $(OIMAGES) $(OBINS) $(SPECIAL_MKTARGETS) .PHONY: sdk_extracted -.PHONY: sdk_patched .PHONY: sdk_pruned .PHONY: toolchain sdk_extracted: $(TOP_DIR)/sdk/.extracted-$(SDK_BASE_VER) -sdk_patched: sdk_extracted $(TOP_DIR)/sdk/.patched-$(SDK_VER) sdk_pruned: $(SDK_DIR_DEPENDS) $(TOP_DIR)/sdk/.pruned-$(SDK_VER) ifeq ($(OS),Windows_NT) toolchain: else -toolchain: $(TOP_DIR)/tools/toolchains/esp8266-$(PLATFORM)-$(TOOLCHAIN_VERSION)/bin/xtensa-lx106-elf-gcc +toolchain: $(TOP_DIR)/tools/toolchains/esp8266-$(PLATFORM)-$(TOOLCHAIN_VERSION)/bin/xtensa-lx106-elf-gcc $(TOP_DIR)/tools/toolchains/esptool.py $(TOP_DIR)/tools/toolchains/esp8266-$(PLATFORM)-$(TOOLCHAIN_VERSION)/bin/xtensa-lx106-elf-gcc: $(TOP_DIR)/cache/toolchain-esp8266-$(PLATFORM)-$(TOOLCHAIN_VERSION).tar.xz mkdir -p $(TOP_DIR)/tools/toolchains/ @@ -256,22 +253,34 @@ $(TOP_DIR)/tools/toolchains/esp8266-$(PLATFORM)-$(TOOLCHAIN_VERSION)/bin/xtensa- $(TOP_DIR)/cache/toolchain-esp8266-$(PLATFORM)-$(TOOLCHAIN_VERSION).tar.xz: mkdir -p $(TOP_DIR)/cache $(summary) WGET $(patsubst $(TOP_DIR)/%,%,$@) - wget --tries=10 --timeout=15 --waitretry=30 --read-timeout=20 --retry-connrefused https://github.com/jmattsson/esp-toolchains/releases/download/$(PLATFORM)-$(TOOLCHAIN_VERSION)/toolchain-esp8266-$(PLATFORM)-$(TOOLCHAIN_VERSION).tar.xz -O $@ || { rm -f "$@"; exit 1; } + $(WGET) $(GITHUB_TOOLCHAIN)/releases/download/$(PLATFORM)-$(TOOLCHAIN_VERSION)/toolchain-esp8266-$(PLATFORM)-$(TOOLCHAIN_VERSION).tar.xz -O $@ \ + || { rm -f "$@"; exit 1; } endif +$(TOP_DIR)/tools/toolchains/esptool.py: $(TOP_DIR)/cache/esptool/v$(ESPTOOL_VER).tar.gz + mkdir -p $(TOP_DIR)/tools/toolchains/ + tar -C $(TOP_DIR)/tools/toolchains/ -xzf $< --strip-components=1 esptool-$(ESPTOOL_VER)/esptool.py + chmod +x $@ + touch $@ + +$(TOP_DIR)/cache/esptool/v$(ESPTOOL_VER).tar.gz: + mkdir -p $(TOP_DIR)/cache/esptool/ + $(WGET) $(GITHUB_ESPTOOL)/archive/v$(ESPTOOL_VER).tar.gz -O $@ || { rm -f "$@"; exit 1; } + $(TOP_DIR)/sdk/.extracted-$(SDK_BASE_VER): $(TOP_DIR)/cache/v$(SDK_FILE_VER).zip mkdir -p "$(dir $@)" $(summary) UNZIP $(patsubst $(TOP_DIR)/%,%,$<) - (cd "$(dir $@)" && rm -fr esp_iot_sdk_v$(SDK_VER) ESP8266_NONOS_SDK-$(SDK_BASE_VER) && unzip $(TOP_DIR)/cache/v$(SDK_FILE_VER).zip ESP8266_NONOS_SDK-$(SDK_BASE_VER)/lib/* ESP8266_NONOS_SDK-$(SDK_BASE_VER)/ld/eagle.rom.addr.v6.ld ESP8266_NONOS_SDK-$(SDK_BASE_VER)/include/* ESP8266_NONOS_SDK-$(SDK_BASE_VER)/bin/esp_init_data_default_v05.bin) + (cd "$(dir $@)" && \ + rm -fr esp_iot_sdk_v$(SDK_VER) ESP8266_NONOS_SDK-$(SDK_BASE_VER) && \ + unzip $(TOP_DIR)/cache/v$(SDK_FILE_VER).zip \ + 'ESP8266_NONOS_SDK-$(SDK_BASE_VER)/lib/*' \ + 'ESP8266_NONOS_SDK-$(SDK_BASE_VER)/ld/*.v6.ld' \ + 'ESP8266_NONOS_SDK-$(SDK_BASE_VER)/include/*' \ + 'ESP8266_NONOS_SDK-$(SDK_BASE_VER)/bin/esp_init_data_default_v05.bin' \ + ) mv $(dir $@)/ESP8266_NONOS_SDK-$(SDK_BASE_VER) $(dir $@)/esp_iot_sdk_v$(SDK_BASE_VER) touch $@ -$(TOP_DIR)/sdk/.patched-$(SDK_VER): $(TOP_DIR)/cache/$(SDK_PATCH_VER).patch - mv $(dir $@)/esp_iot_sdk_v$(SDK_BASE_VER) $(dir $@)/esp_iot_sdk_v$(SDK_VER) - $(summary) APPLY $(patsubst $(TOP_DIR)/%,%,$<) - git apply --verbose -p1 --exclude='*VERSION' --exclude='*bin/at*' --directory=$(SDK_REL_DIR) $< - touch $@ - $(TOP_DIR)/sdk/.pruned-$(SDK_VER): rm -f $(SDK_DIR)/lib/liblwip.a $(SDK_DIR)/lib/libssl.a $(SDK_DIR)/lib/libmbedtls.a $(summary) PRUNE libmain.a libc.a @@ -282,15 +291,9 @@ $(TOP_DIR)/sdk/.pruned-$(SDK_VER): $(TOP_DIR)/cache/v$(SDK_FILE_VER).zip: mkdir -p "$(dir $@)" $(summary) WGET $(patsubst $(TOP_DIR)/%,%,$@) - wget --tries=10 --timeout=15 --waitretry=30 --read-timeout=20 --retry-connrefused https://github.com/espressif/ESP8266_NONOS_SDK/archive/v$(SDK_FILE_VER).zip -O $@ || { rm -f "$@"; exit 1; } + $(WGET) $(GITHUB_SDK)/archive/v$(SDK_FILE_VER).zip -O $@ || { rm -f "$@"; exit 1; } (echo "$(SDK_FILE_SHA1) $@" | sha1sum -c -) || { rm -f "$@"; exit 1; } -$(TOP_DIR)/cache/$(SDK_PATCH_VER).patch: - mkdir -p "$(dir $@)" - $(summary) WGET $(SDK_PATCH_VER).patch - wget --tries=10 --timeout=15 --waitretry=30 --read-timeout=20 --retry-connrefused "https://github.com/espressif/ESP8266_NONOS_SDK/compare/v$(SDK_BASE_VER)...$(SDK_PATCH_VER).patch" -O $@ || { rm -f "$@"; exit 1; } - (echo "$(SDK_PATCH_SHA1) $@" | sha1sum -c -) || { rm -f "$@"; exit 1; } - clean: $(foreach d, $(SUBDIRS), $(MAKE) -C $(d) clean;) $(RM) -r $(ODIR)/$(TARGET)/$(FLAVOR) diff --git a/app/Makefile b/app/Makefile index 968e845534..222f03b319 100644 --- a/app/Makefile +++ b/app/Makefile @@ -97,7 +97,6 @@ LINKFLAGS_eagle.app.v6 = \ -T$(LD_FILE) \ -Wl,@../ld/defsym.rom \ -Wl,--no-check-sections \ - -Wl,--wrap=_xtos_set_exception_handler \ -Wl,-static \ $(addprefix -u , $(SELECTED_MODULE_SYMS)) \ -Wl,--start-group \ @@ -116,6 +115,8 @@ LINKFLAGS_eagle.app.v6 = \ $(DEP_LIBS_eagle.app.v6) \ -Wl,--end-group \ -lm +# -Wl,--cref +# -Wl,--wrap=_xtos_set_exception_handler DEPENDS_eagle.app.v6 = \ $(LD_FILE) \ diff --git a/app/esp-gdbstub/gdbstub.c b/app/esp-gdbstub/gdbstub.c index 5ee8ee9228..509e9bb403 100644 --- a/app/esp-gdbstub/gdbstub.c +++ b/app/esp-gdbstub/gdbstub.c @@ -659,11 +659,22 @@ static void ATTR_GDBFN gdb_semihost_putchar1(char c) { } #if !GDBSTUB_FREERTOS -//The OS-less SDK uses the Xtensa HAL to handle exceptions. We can use those functions to catch any -//fatal exceptions and invoke the debugger when this happens. +/* The non-OS SDK uses the Xtensa HAL to handle exceptions, and the SDK now establishes exception + * handlers for EXCCAUSE errors: ILLEGAL, INSTR_ERROR, LOAD_STORE_ERROR, PRIVILEGED, UNALIGNED, + * LOAD_PROHIBITED and STORE_PROHIBITED. These handlers are established in SDK/app_main.c. + * LOAD_STORE_ERROR is handled by SDK/user_exceptions.o:load_non_32_wide_handler() which is a + * fork of our version. The remaining are handled by a static function at + * SDK:app+main.c:offset 0x0348. + * + * Our SDK 2 load_non_32_wide_handler chained into the gdb stub handler if the error was anything + * other than a L8UI, L16SI or L16UI at a flash mapped address. However in this current + * implementation, we have left the Espressif handler in place and handle the other errors with + * the debugger. This means that the debugger will not capture other load store errors. I + * might revise this. + */ static void ATTR_GDBINIT install_exceptions() { int i; - int exno[]={EXCCAUSE_ILLEGAL, EXCCAUSE_SYSCALL, EXCCAUSE_INSTR_ERROR, EXCCAUSE_LOAD_STORE_ERROR, + const int exno[]={EXCCAUSE_ILLEGAL, EXCCAUSE_SYSCALL, EXCCAUSE_INSTR_ERROR, /* EXCCAUSE_LOAD_STORE_ERROR, */ EXCCAUSE_DIVIDE_BY_ZERO, EXCCAUSE_UNALIGNED, EXCCAUSE_INSTR_DATA_ERROR, EXCCAUSE_LOAD_STORE_DATA_ERROR, EXCCAUSE_INSTR_ADDR_ERROR, EXCCAUSE_LOAD_STORE_ADDR_ERROR, EXCCAUSE_INSTR_PROHIBITED, EXCCAUSE_LOAD_PROHIBITED, EXCCAUSE_STORE_PROHIBITED}; diff --git a/app/include/lwip/mem.h b/app/include/lwip/mem.h index 3e4e6149b3..825d222611 100644 --- a/app/include/lwip/mem.h +++ b/app/include/lwip/mem.h @@ -51,40 +51,39 @@ typedef size_t mem_size_t; * allow these defines to be overridden. */ #ifndef MEMLEAK_DEBUG + #ifndef mem_free -#define mem_free vPortFree +#define mem_free(s) vPortFree(s, "", __LINE__) #endif #ifndef mem_malloc -#define mem_malloc pvPortMalloc +#define mem_malloc(s) pvPortMalloc(s, "", __LINE__,false) #endif #ifndef mem_calloc -#define mem_calloc pvPortCalloc +#define mem_calloc(l, s) pvPortCalloc(l, s, "", __LINE__) #endif #ifndef mem_realloc -#define mem_realloc pvPortRealloc +#define mem_realloc(p, s) pvPortRealloc(p, s, "", __LINE__) #endif #ifndef mem_zalloc -#define mem_zalloc pvPortZalloc +#define mem_zalloc(s) pvPortZalloc(s, "", __LINE__) #endif + #else + #ifndef mem_free -#define mem_free(s) \ -do{\ - const char *file = mem_debug_file;\ - vPortFree(s, file, __LINE__);\ -}while(0) +#define mem_free(s) vPortFree(s, mem_debug_file, __LINE__) #endif #ifndef mem_malloc -#define mem_malloc(s) ({const char *file = mem_debug_file; pvPortMalloc(s, file, __LINE__);}) +#define mem_malloc(s) pvPortMalloc(s, mem_debug_file, __LINE__,false) #endif #ifndef mem_calloc -#define mem_calloc(l, s) ({const char *file = mem_debug_file; pvPortCalloc(l, s, file, __LINE__);}) +#define mem_calloc(l, s) pvPortCalloc(l, s, mem_debug_file, __LINE__) #endif #ifndef mem_realloc -#define mem_realloc(p, s) ({const char *file = mem_debug_file; pvPortRealloc(p, s, file, __LINE__);}) +#define mem_realloc(p, s) pvPortRealloc(p, s, mem_debug_file, __LINE__) #endif #ifndef mem_zalloc -#define mem_zalloc(s) ({const char *file = mem_debug_file; pvPortZalloc(s, file, __LINE__);}) +#define mem_zalloc(s) pvPortZalloc(s, mem_debug_file, __LINE__) #endif #endif diff --git a/app/include/user_config.h b/app/include/user_config.h index 06e52a2ae7..56567880a6 100644 --- a/app/include/user_config.h +++ b/app/include/user_config.h @@ -7,8 +7,8 @@ // this out and enabling the explicitly size, e.g. FLASH_4M. Valid sizes are // FLASH_512K, FLASH_1M, FLASH_2M, FLASH_4M, FLASH_8M, FLASH_16M. -#define FLASH_AUTOSIZE -//#define FLASH_4M +//#define FLASH_AUTOSIZE +#define FLASH_4M // The firmware now selects a baudrate of 115,200 by default, but the driver @@ -41,11 +41,8 @@ // The Lua Flash Store (LFS) allows you to store Lua code in Flash memory and // the Lua VMS will execute this code directly from flash without needing any -// RAM overhead. If you want to enable LFS then set the following define to -// the size of the store that you need. This can be any multiple of 4kB up to -// a maximum 256Kb. - -//#define LUA_FLASH_STORE 0x10000 +// RAM overhead. Note that you should now configure LFS directly in the +// System Partition Table and not at build time. // By default Lua executes the file init.lua at start up. The following @@ -71,10 +68,10 @@ // general, limiting the size of the FS only to what your application needs // gives the fastest start-up and imaging times. +// Note that you should now configure SPIFFS size and position directly in the +// System Partition Table and not at build time. + #define BUILD_SPIFFS -//#define SPIFFS_FIXED_LOCATION 0x100000 -//#define SPIFFS_MAX_FILESYSTEM_SIZE 0x20000 -//#define SPIFFS_SIZE_1M_BOUNDARY #define SPIFFS_CACHE 1 // Enable if you use you SPIFFS in R/W mode #define SPIFFS_MAX_OPEN_FILES 4 // maximum number of open files for SPIFFS #define FS_OBJ_NAME_LEN 31 // maximum length of a filename @@ -206,6 +203,19 @@ // change this if you have tracked the implications through the Firmware sources // and understand the these. +#define NODEMCU_EAGLEROM_PARTITION 1 +#define NODEMCU_IROM0TEXT_PARTITION 2 +#define NODEMCU_LFS0_PARTITION 3 +#define NODEMCU_LFS1_PARTITION 4 +#define NODEMCU_TLSCERT_PARTITION 5 +#define NODEMCU_SPIFFS0_PARTITION 6 +#define NODEMCU_SPIFFS1_PARTITION 7 + +#define LUA_FLASH_STORE 0x0 +#define SPIFFS_FIXED_LOCATION 0x0 +#define SPIFFS_MAX_FILESYSTEM_SIZE (~0x0) +//#define SPIFFS_SIZE_1M_BOUNDARY + #define LUA_TASK_PRIO USER_TASK_PRIO_0 #define LUA_PROCESS_LINE_SIG 2 #define LUA_OPTIMIZE_DEBUG 2 diff --git a/app/libc/c_math.c b/app/libc/c_math.c index 635e8b2295..2eb4468785 100644 --- a/app/libc/c_math.c +++ b/app/libc/c_math.c @@ -11,7 +11,7 @@ double floor(double x) #define MINEXP -2047 /* (MIN_EXP * 16) - 1 */ #define HUGE MAXFLOAT -double a1[] ICACHE_STORE_ATTR ICACHE_RODATA_ATTR = +static const double a1[] = { 1.0, 0.95760328069857365, @@ -31,7 +31,7 @@ double a1[] ICACHE_STORE_ATTR ICACHE_RODATA_ATTR = 0.52213689121370692, 0.50000000000000000 }; -double a2[] ICACHE_STORE_ATTR ICACHE_RODATA_ATTR = +static const double a2[] = { 0.24114209503420288E-17, 0.92291566937243079E-18, @@ -42,18 +42,19 @@ double a2[] ICACHE_STORE_ATTR ICACHE_RODATA_ATTR = 0.29306999570789681E-17, 0.11260851040933474E-17 }; -double p1 ICACHE_STORE_ATTR ICACHE_RODATA_ATTR = 0.833333333333332114e-1; -double p2 ICACHE_STORE_ATTR ICACHE_RODATA_ATTR = 0.125000000005037992e-1; -double p3 ICACHE_STORE_ATTR ICACHE_RODATA_ATTR = 0.223214212859242590e-2; -double p4 ICACHE_STORE_ATTR ICACHE_RODATA_ATTR = 0.434457756721631196e-3; -double q1 ICACHE_STORE_ATTR ICACHE_RODATA_ATTR = 0.693147180559945296e0; -double q2 ICACHE_STORE_ATTR ICACHE_RODATA_ATTR = 0.240226506959095371e0; -double q3 ICACHE_STORE_ATTR ICACHE_RODATA_ATTR = 0.555041086640855953e-1; -double q4 ICACHE_STORE_ATTR ICACHE_RODATA_ATTR = 0.961812905951724170e-2; -double q5 ICACHE_STORE_ATTR ICACHE_RODATA_ATTR = 0.133335413135857847e-2; -double q6 ICACHE_STORE_ATTR ICACHE_RODATA_ATTR = 0.154002904409897646e-3; -double q7 ICACHE_STORE_ATTR ICACHE_RODATA_ATTR = 0.149288526805956082e-4; -double k ICACHE_STORE_ATTR ICACHE_RODATA_ATTR = 0.442695040888963407; +static const double + p1 = 0.833333333333332114e-1, + p2 = 0.125000000005037992e-1, + p3 = 0.223214212859242590e-2, + p4 = 0.434457756721631196e-3, + q1 = 0.693147180559945296e0, + q2 = 0.240226506959095371e0, + q3 = 0.555041086640855953e-1, + q4 = 0.961812905951724170e-2, + q5 = 0.133335413135857847e-2, + q6 = 0.154002904409897646e-3, + q7 = 0.149288526805956082e-4, + k = 0.442695040888963407; double pow(double x, double y) { diff --git a/app/lua/ldblib.c b/app/lua/ldblib.c index 02e1e3d1ad..3eef8fd47b 100644 --- a/app/lua/ldblib.c +++ b/app/lua/ldblib.c @@ -28,12 +28,12 @@ static int db_getregistry (lua_State *L) { } static int db_getstrings (lua_State *L) { - size_t i,n; + size_t i,n=0; stringtable *tb; GCObject *o; -#if defined(LUA_FLASH_STORE) && !defined(LUA_CROSS_COMPILER) +#ifndef LUA_CROSS_COMPILER const char *opt = lua_tolstring (L, 1, &n); - if (n==3 && memcmp(opt, "ROM", 4) == 0) { + if (n==3 && c_memcmp(opt, "ROM", 4) == 0) { if (G(L)->ROstrt.hash == NULL) return 0; tb = &G(L)->ROstrt; diff --git a/app/lua/lflash.c b/app/lua/lflash.c index 4c5f42cb1a..17218fe1c1 100644 --- a/app/lua/lflash.c +++ b/app/lua/lflash.c @@ -8,7 +8,6 @@ #define LUAC_CROSS_FILE #include "lua.h" -#ifdef LUA_FLASH_STORE #include "lobject.h" #include "lauxlib.h" #include "lstate.h" @@ -31,6 +30,7 @@ */ static char *flashAddr; +static uint32_t flashSize; static uint32_t flashAddrPhys; static uint32_t flashSector; static uint32_t curOffset; @@ -38,9 +38,8 @@ static uint32_t curOffset; #define ALIGN(s) (((s)+sizeof(size_t)-1) & ((size_t) (- (signed) sizeof(size_t)))) #define ALIGN_BITS(s) (((uint32_t)s) & (sizeof(size_t)-1)) #define ALL_SET (~0) -#define FLASH_SIZE LUA_FLASH_STORE #define FLASH_PAGE_SIZE INTERNAL_FLASH_SECTOR_SIZE -#define FLASH_PAGES (FLASH_SIZE/FLASH_PAGE_SIZE) +#define FLASH_PAGES (flashSize/FLASH_PAGE_SIZE) #define READ_BLOCKSIZE 1024 #define WRITE_BLOCKSIZE 2048 #define DICTIONARY_WINDOW 16384 @@ -49,8 +48,6 @@ static uint32_t curOffset; #define WRITE_BLOCKS ((DICTIONARY_WINDOW/WRITE_BLOCKSIZE)+1) #define WRITE_BLOCK_WORDS (WRITE_BLOCKSIZE/WORDSIZE) -char flash_region_base[FLASH_SIZE] ICACHE_FLASH_RESERVED_ATTR; - struct INPUT { int fd; int len; @@ -152,11 +149,16 @@ static void flashErase(uint32_t start, uint32_t end){ * Hook in lstate.c:f_luaopen() to set up ROstrt and ROpvmain if needed */ LUAI_FUNC void luaN_init (lua_State *L) { - curOffset = 0; - flashAddr = flash_region_base; - flashAddrPhys = platform_flash_mapped2phys((uint32_t)flashAddr); + + flashSize = platform_flash_get_partition (NODEMCU_LFS0_PARTITION, &flashAddrPhys); + if (flashSize == 0) { + return; // Nothing to do if the size is zero + } + G(L)->LFSsize = flashSize; + flashAddr = cast(char *, platform_flash_phys2mapped(flashAddrPhys)); flashSector = platform_flash_get_sector_of_address(flashAddrPhys); FlashHeader *fh = cast(FlashHeader *, flashAddr); + curOffset = 0; /* * For the LFS to be valid, its signature has to be correct for this build @@ -201,6 +203,13 @@ LUALIB_API int luaN_reload_reboot (lua_State *L) { // luaL_dbgbreak(); const char *fn = lua_tostring(L, 1), *msg = ""; int status; + + if (G(L)->LFSsize == 0) { + lua_pushstring(L, "No LFS partition allocated"); + return 1; + } + + /* * Do a protected call of loadLFS. * @@ -264,13 +273,18 @@ LUAI_FUNC int luaN_index (lua_State *L) { int i; int n = lua_gettop(L); - /* Return nil + the LFS base address if the LFS isn't loaded */ - if(!(G(L)->ROpvmain)) { + /* Return nil + the LFS base address if the LFS size > 0 and it isn't loaded */ + if (!(G(L)->ROpvmain)) { lua_settop(L, 0); lua_pushnil(L); - lua_pushinteger(L, (lua_Integer) flashAddr); - lua_pushinteger(L, flashAddrPhys); - return 3; + if (G(L)->LFSsize) { + lua_pushinteger(L, (lua_Integer) flashAddr); + lua_pushinteger(L, flashAddrPhys); + lua_pushinteger(L, G(L)->LFSsize); + return 4; + } else { + return 1; + } } /* Push the LClosure of the LFS index function */ @@ -409,10 +423,10 @@ int procFirstPass (void) { flash_error("Incorrect LFS build type"); if ((fh->flash_sig & ~FLASH_SIG_ABSOLUTE) != FLASH_SIG) flash_error("incorrect LFS header signature"); - if (fh->flash_size > FLASH_SIZE) + if (fh->flash_size > flashSize) flash_error("LFS Image too big for configured LFS region"); if ((fh->flash_size & 0x3) || - fh->flash_size > FLASH_SIZE || + fh->flash_size > flashSize || out->flagsLen != 1 + (out->flashLen/WORDSIZE - 1) / BITS_PER_WORD) flash_error("LFS length mismatch"); out->flags = luaM_newvector(out->L, out->flagsLen, uint); @@ -557,4 +571,3 @@ static int loadLFSgc (lua_State *L) { } return 0; } -#endif diff --git a/app/lua/lflash.h b/app/lua/lflash.h index 5088a4a77f..722d0f3605 100644 --- a/app/lua/lflash.h +++ b/app/lua/lflash.h @@ -3,7 +3,7 @@ ** See Copyright Notice in lua.h */ -#if defined(LUA_FLASH_STORE) && !defined(lflash_h) +#ifndef lflash_h #define lflash_h #include "lobject.h" diff --git a/app/lua/lgc.c b/app/lua/lgc.c index b9c80a3358..645703d660 100644 --- a/app/lua/lgc.c +++ b/app/lua/lgc.c @@ -28,10 +28,6 @@ #define GCSWEEPCOST 10 #define GCFINALIZECOST 100 -#if READONLYMASK != (1<marked, FIXEDSTACKBIT) #define fixedstack(x) l_setbit((x)->marked, FIXEDSTACKBIT) #define unfixedstack(x) resetbit((x)->marked, FIXEDSTACKBIT) -#ifdef LUA_FLASH_STORE +#ifndef LUA_CROSS_COMPILER #define isLFSobject(x) testbit(getmarked(x), LFSBIT) #define stringfix(s) if (!test2bits(getmarked(&(s)->tsv), FIXEDBIT, LFSBIT)) {l_setbit((s)->tsv.marked, FIXEDBIT);} #else diff --git a/app/lua/lobject.h b/app/lua/lobject.h index 708d2a9daf..e217383118 100644 --- a/app/lua/lobject.h +++ b/app/lua/lobject.h @@ -24,9 +24,7 @@ #define NUM_TAGS (LAST_TAG+1) #define READONLYMASK (1<<7) /* denormalised bitmask for READONLYBIT and */ -#ifdef LUA_FLASH_STORE #define LFSMASK (1<<6) /* LFSBIT to avoid include proliferation */ -#endif /* ** Extra tags for non-values */ diff --git a/app/lua/lstate.c b/app/lua/lstate.c index ccfa2d3735..55e107a666 100644 --- a/app/lua/lstate.c +++ b/app/lua/lstate.c @@ -73,7 +73,7 @@ static void f_luaopen (lua_State *L, void *ud) { sethvalue(L, gt(L), luaH_new(L, 0, 2)); /* table of globals */ sethvalue(L, registry(L), luaH_new(L, 0, 2)); /* registry */ luaS_resize(L, MINSTRTABSIZE); /* initial size of string table */ -#if defined(LUA_FLASH_STORE) && !defined(LUA_CROSS_COMPILER) +#ifndef LUA_CROSS_COMPILER luaN_init(L); /* optionally map RO string table */ #endif luaT_init(L); @@ -196,11 +196,12 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) { #else g->memlimit = 0; #endif -#if defined(LUA_FLASH_STORE) && !defined(LUA_CROSS_COMPILER) +#ifndef LUA_CROSS_COMPILER g->ROstrt.size = 0; g->ROstrt.nuse = 0; g->ROstrt.hash = NULL; g->ROpvmain = NULL; + g->LFSsize = 0; #endif for (i=0; imt[i] = NULL; if (luaD_rawrunprotected(L, f_luaopen, NULL) != 0) { diff --git a/app/lua/lstate.h b/app/lua/lstate.h index 55d3d89c4e..88b7d57f5a 100644 --- a/app/lua/lstate.h +++ b/app/lua/lstate.h @@ -94,9 +94,10 @@ typedef struct global_State { UpVal uvhead; /* head of double-linked list of all open upvalues */ struct Table *mt[NUM_TAGS]; /* metatables for basic types */ TString *tmname[TM_N]; /* array with tag-method names */ -#if defined(LUA_FLASH_STORE) && !defined(LUA_CROSS_COMPILER) +#ifndef LUA_CROSS_COMPILER stringtable ROstrt; /* Flash-based hash table for RO strings */ Proto *ROpvmain; /* Flash-based Proto main */ + int LFSsize; /* Size of Lua Flash Store */ #endif } global_State; diff --git a/app/lua/lstring.c b/app/lua/lstring.c index 9278b5cd56..be4591875d 100644 --- a/app/lua/lstring.c +++ b/app/lua/lstring.c @@ -112,7 +112,7 @@ LUAI_FUNC TString *luaS_newlstr (lua_State *L, const char *str, size_t l) { return ts; } } -#if defined(LUA_FLASH_STORE) && !defined(LUA_CROSS_COMPILER) +#ifndef LUA_CROSS_COMPILER /* * The RAM strt is searched first since RAM access is faster tham Flash access. * If a miss, then search the RO string table. diff --git a/app/lua/lua.c b/app/lua/lua.c index a30f49f8b2..cb226b51f9 100644 --- a/app/lua/lua.c +++ b/app/lua/lua.c @@ -22,9 +22,7 @@ #include "lauxlib.h" #include "lualib.h" #include "legc.h" -#ifdef LUA_FLASH_STORE #include "lflash.h" -#endif #include "os_type.h" lua_State *globalL = NULL; diff --git a/app/lua/luac_cross/lflashimg.c b/app/lua/luac_cross/lflashimg.c index 0fef0dd8c0..4dd5a85323 100644 --- a/app/lua/luac_cross/lflashimg.c +++ b/app/lua/luac_cross/lflashimg.c @@ -16,8 +16,6 @@ #define LUA_CORE #include "lobject.h" #include "lstring.h" -#undef LUA_FLASH_STORE -#define LUA_FLASH_STORE #include "lflash.h" #include "uzlib.h" diff --git a/app/modules/node.c b/app/modules/node.c index e655d52cf4..7094c5394d 100644 --- a/app/modules/node.c +++ b/app/modules/node.c @@ -17,9 +17,7 @@ #include "platform.h" #include "lrodefs.h" -#ifdef LUA_FLASH_STORE #include "lflash.h" -#endif #include "c_types.h" #include "c_string.h" #include "driver/uart.h" @@ -162,10 +160,6 @@ static int node_flashid( lua_State* L ) // Lua: flashsize() static int node_flashsize( lua_State* L ) { - if (lua_type(L, 1) == LUA_TNUMBER) - { - flash_rom_set_size_byte(luaL_checkinteger(L, 1)); - } uint32_t sz = flash_rom_get_size_byte(); lua_pushinteger( L, sz ); return 1; @@ -603,10 +597,8 @@ static const LUA_REG_TYPE node_map[] = { LSTRKEY( "heap" ), LFUNCVAL( node_heap ) }, { LSTRKEY( "info" ), LFUNCVAL( node_info ) }, { LSTRKEY( "task" ), LROVAL( node_task_map ) }, -#ifdef LUA_FLASH_STORE { LSTRKEY( "flashreload" ), LFUNCVAL( luaN_reload_reboot ) }, { LSTRKEY( "flashindex" ), LFUNCVAL( luaN_index ) }, -#endif { LSTRKEY( "restart" ), LFUNCVAL( node_restart ) }, { LSTRKEY( "dsleep" ), LFUNCVAL( node_deepsleep ) }, { LSTRKEY( "dsleepMax" ), LFUNCVAL( dsleepMax ) }, diff --git a/app/modules/rtctime.c b/app/modules/rtctime.c index d780fd9470..fc806287e4 100644 --- a/app/modules/rtctime.c +++ b/app/modules/rtctime.c @@ -46,10 +46,10 @@ void __attribute__((noreturn)) TEXT_SECTION_ATTR rtc_time_enter_deep_sleep_final void rtctime_early_startup (void) { - Cache_Read_Enable (0, 0, 1); +// Cache_Read_Enable (0, 0, 1); rtc_time_register_bootup (); rtc_time_switch_clocks (); - Cache_Read_Disable (); +// Cache_Read_Disable (); } void rtctime_late_startup (void) diff --git a/app/platform/flash_api.c b/app/platform/flash_api.c index 6901afc059..fb77d04b09 100644 --- a/app/platform/flash_api.c +++ b/app/platform/flash_api.c @@ -39,16 +39,19 @@ uint32_t flash_detect_size_byte(void) #undef FLASH_BUFFER_SIZE_DETECT } -SPIFlashInfo flash_rom_getinfo(void) +static SPIFlashInfo spi_flash_info = {0}; + +SPIFlashInfo *flash_rom_getinfo(void) { - volatile SPIFlashInfo spi_flash_info ICACHE_STORE_ATTR; - spi_flash_read(0, (uint32 *)(& spi_flash_info), sizeof(spi_flash_info)); - return spi_flash_info; + if (spi_flash_info.entry_point == 0) { + spi_flash_read(0, (uint32 *)(& spi_flash_info), sizeof(spi_flash_info)); + } + return &spi_flash_info; } uint8_t flash_rom_get_size_type(void) { - return flash_rom_getinfo().size; + return flash_rom_getinfo()->size; } uint32_t flash_rom_get_size_byte(void) @@ -56,7 +59,7 @@ uint32_t flash_rom_get_size_byte(void) static uint32_t flash_size = 0; if (flash_size == 0) { - switch (flash_rom_getinfo().size) + switch (flash_rom_getinfo()->size) { case SIZE_2MBIT: // 2Mbit, 256kByte @@ -107,99 +110,15 @@ uint32_t flash_rom_get_size_byte(void) return flash_size; } -bool flash_rom_set_size_type(uint8_t size) -{ - // Dangerous, here are dinosaur infested!!!!! - // Reboot required!!! - // If you don't know what you're doing, your nodemcu may turn into stone ... - NODE_DBG("\nBEGIN SET FLASH HEADER\n"); - uint8_t data[SPI_FLASH_SEC_SIZE] ICACHE_STORE_ATTR; - if (SPI_FLASH_RESULT_OK == spi_flash_read(0, (uint32 *)data, SPI_FLASH_SEC_SIZE)) - { - NODE_DBG("\nflash_rom_set_size_type(%u), was %u\n", size, ((SPIFlashInfo *)data)->size ); - ((SPIFlashInfo *)data)->size = size; - if (SPI_FLASH_RESULT_OK == spi_flash_erase_sector(0 * SPI_FLASH_SEC_SIZE)) - { - NODE_DBG("\nSECTOR 0 ERASE SUCCESS\n"); - } - if (SPI_FLASH_RESULT_OK == spi_flash_write(0, (uint32 *)data, SPI_FLASH_SEC_SIZE)) - { - NODE_DBG("\nWRITE SUCCESS, %u\n", size); - } - } - NODE_DBG("\nEND SET FLASH HEADER\n"); - return true; -} - -bool flash_rom_set_size_byte(uint32_t size) -{ - // Dangerous, here are dinosaur infested!!!!! - // Reboot required!!! - // If you don't know what you're doing, your nodemcu may turn into stone ... - bool result = true; - uint32_t flash_size = 0; - switch (size) - { - case 256 * 1024: - // 2Mbit, 256kByte - flash_size = SIZE_2MBIT; - flash_rom_set_size_type(flash_size); - break; - case 512 * 1024: - // 4Mbit, 512kByte - flash_size = SIZE_4MBIT; - flash_rom_set_size_type(flash_size); - break; - case 1 * 1024 * 1024: - // 8Mbit, 1MByte - flash_size = SIZE_8MBIT; - flash_rom_set_size_type(flash_size); - break; - case 2 * 1024 * 1024: - // 16Mbit, 2MByte - flash_size = SIZE_16MBIT; - flash_rom_set_size_type(flash_size); - break; - case 4 * 1024 * 1024: - // 32Mbit, 4MByte - flash_size = SIZE_32MBIT; - flash_rom_set_size_type(flash_size); - break; - case 8 * 1024 * 1024: - // 64Mbit, 8MByte - flash_size = SIZE_64MBIT; - flash_rom_set_size_type(flash_size); - break; - case 16 * 1024 * 1024: - // 128Mbit, 16MByte - flash_size = SIZE_128MBIT; - flash_rom_set_size_type(flash_size); - break; - default: - // Unknown flash size. - result = false; - break; - } - return result; -} - uint16_t flash_rom_get_sec_num(void) { - //static uint16_t sec_num = 0; - // return flash_rom_get_size_byte() / (SPI_FLASH_SEC_SIZE); - // c_printf("\nflash_rom_get_size_byte()=%d\n", ( flash_rom_get_size_byte() / (SPI_FLASH_SEC_SIZE) )); - // if( sec_num == 0 ) - //{ - // sec_num = 4 * 1024 * 1024 / (SPI_FLASH_SEC_SIZE); - //} - //return sec_num; return ( flash_rom_get_size_byte() / (SPI_FLASH_SEC_SIZE) ); } uint8_t flash_rom_get_mode(void) { - SPIFlashInfo spi_flash_info = flash_rom_getinfo(); - switch (spi_flash_info.mode) + uint8_t mode = flash_rom_getinfo()->mode; + switch (mode) { // Reserved for future use case MODE_QIO: @@ -211,14 +130,14 @@ uint8_t flash_rom_get_mode(void) case MODE_DOUT: break; } - return spi_flash_info.mode; + return mode; } uint32_t flash_rom_get_speed(void) { uint32_t speed = 0; - SPIFlashInfo spi_flash_info = flash_rom_getinfo(); - switch (spi_flash_info.speed) + uint8_t spi_speed = flash_rom_getinfo()->speed; + switch (spi_speed) { case SPEED_40MHZ: // 40MHz @@ -240,47 +159,6 @@ uint32_t flash_rom_get_speed(void) return speed; } -bool flash_rom_set_speed(uint32_t speed) -{ - // Dangerous, here are dinosaur infested!!!!! - // Reboot required!!! - // If you don't know what you're doing, your nodemcu may turn into stone ... - NODE_DBG("\nBEGIN SET FLASH HEADER\n"); - uint8_t data[SPI_FLASH_SEC_SIZE] ICACHE_STORE_ATTR; - uint8_t speed_type = SPEED_40MHZ; - if (speed < 26700000) - { - speed_type = SPEED_20MHZ; - } - else if (speed < 40000000) - { - speed_type = SPEED_26MHZ; - } - else if (speed < 80000000) - { - speed_type = SPEED_40MHZ; - } - else if (speed >= 80000000) - { - speed_type = SPEED_80MHZ; - } - if (SPI_FLASH_RESULT_OK == spi_flash_read(0, (uint32 *)data, SPI_FLASH_SEC_SIZE)) - { - ((SPIFlashInfo *)(&data[0]))->speed = speed_type; - NODE_DBG("\nflash_rom_set_speed(%u), was %u\n", speed_type, ((SPIFlashInfo *)(&data[0]))->speed ); - if (SPI_FLASH_RESULT_OK == spi_flash_erase_sector(0 * SPI_FLASH_SEC_SIZE)) - { - NODE_DBG("\nERASE SUCCESS\n"); - } - if (SPI_FLASH_RESULT_OK == spi_flash_write(0, (uint32 *)data, SPI_FLASH_SEC_SIZE)) - { - NODE_DBG("\nWRITE SUCCESS, %u\n", speed_type); - } - } - NODE_DBG("\nEND SET FLASH HEADER\n"); - return true; -} - uint8_t byte_of_aligned_array(const uint8_t *aligned_array, uint32_t index) { if ( (((uint32_t)aligned_array) % 4) != 0 ) @@ -303,31 +181,5 @@ uint16_t word_of_aligned_array(const uint16_t *aligned_array, uint32_t index) volatile uint32_t v = ((uint32_t *)aligned_array)[ index / 2 ]; uint16_t *p = (uint16_t *) (&v); return (index % 2 == 0) ? p[ 0 ] : p[ 1 ]; - // return p[ (index % 2) ]; // -- why error??? - // (byte_of_aligned_array((uint8_t *)aligned_array, index * 2 + 1) << 8) | byte_of_aligned_array((uint8_t *)aligned_array, index * 2); } -// uint8_t flash_rom_get_checksum(void) -// { -// // SPIFlashInfo spi_flash_info ICACHE_STORE_ATTR = flash_rom_getinfo(); -// // uint32_t address = sizeof(spi_flash_info) + spi_flash_info.segment_size; -// // uint32_t address_aligned_4bytes = (address + 3) & 0xFFFFFFFC; -// // uint8_t buffer[64] = {0}; -// // spi_flash_read(address, (uint32 *) buffer, 64); -// // uint8_t i = 0; -// // c_printf("\nBEGIN DUMP\n"); -// // for (i = 0; i < 64; i++) -// // { -// // c_printf("%02x," , buffer[i]); -// // } -// // i = (address + 0x10) & 0x10 - 1; -// // c_printf("\nSIZE:%d CHECK SUM:%02x\n", spi_flash_info.segment_size, buffer[i]); -// // c_printf("\nEND DUMP\n"); -// // return buffer[0]; -// return 0; -// } - -// uint8_t flash_rom_calc_checksum(void) -// { -// return 0; -// } diff --git a/app/platform/flash_api.h b/app/platform/flash_api.h index b0fb16be20..148c514744 100644 --- a/app/platform/flash_api.h +++ b/app/platform/flash_api.h @@ -79,18 +79,14 @@ typedef struct uint32_t segment_size; } ICACHE_STORE_TYPEDEF_ATTR SPIFlashInfo; -SPIFlashInfo flash_rom_getinfo(void); +SPIFlashInfo *flash_rom_getinfo(void); uint8_t flash_rom_get_size_type(void); uint32_t flash_rom_get_size_byte(void); uint32_t flash_detect_size_byte(void); -bool flash_rom_set_size_type(uint8_t); -bool flash_rom_set_size_byte(uint32_t); uint16_t flash_rom_get_sec_num(void); uint8_t flash_rom_get_mode(void); uint32_t flash_rom_get_speed(void); uint8_t byte_of_aligned_array(const uint8_t* aligned_array, uint32_t index); uint16_t word_of_aligned_array(const uint16_t *aligned_array, uint32_t index); -// uint8_t flash_rom_get_checksum(void); -// uint8_t flash_rom_calc_checksum(void); #endif // __FLASH_API_H__ diff --git a/app/platform/platform.c b/app/platform/platform.c index 7d45471d01..0fdc66d846 100644 --- a/app/platform/platform.c +++ b/app/platform/platform.c @@ -946,6 +946,15 @@ uint32_t platform_flash_phys2mapped (uint32_t phys_addr) { return (meg&1) ? -1 : phys_addr + INTERNAL_FLASH_MAPPED_ADDRESS - meg; } +uint32_t platform_flash_get_partition (uint32_t part_id, uint32_t *addr) { + partition_item_t pt = {0,0,0}; + system_partition_get_item(SYSTEM_PARTITION_CUSTOMER_BEGIN + part_id, &pt); + if (addr) { + *addr = pt.addr; + } + return pt.type == 0 ? 0 : pt.size; +} + void* platform_print_deprecation_note( const char *msg, const char *time_frame) { c_printf( "Warning, deprecated API! %s. It will be removed %s. See documentation for details.\n", msg, time_frame ); diff --git a/app/platform/platform.h b/app/platform/platform.h index 06395e37c5..3897f4f489 100644 --- a/app/platform/platform.h +++ b/app/platform/platform.h @@ -289,6 +289,7 @@ int platform_flash_erase_sector( uint32_t sector_id ); */ uint32_t platform_flash_mapped2phys (uint32_t mapped_addr); uint32_t platform_flash_phys2mapped (uint32_t phys_addr); +uint32_t platform_flash_get_partition (uint32_t part_id, uint32_t *addr); // ***************************************************************************** // Allocator support diff --git a/app/platform/vfs.c b/app/platform/vfs.c index 444d4c4392..76773985ed 100644 --- a/app/platform/vfs.c +++ b/app/platform/vfs.c @@ -33,11 +33,14 @@ sint32_t vfs_get_rtc( vfs_time *tm ) static int dir_level = 1; -static const char *normalize_path( const char *path ) -{ + #if ! LDRV_TRAVERSAL - return path; + +#define normalize_path(p) (p) + #else +static const char *normalize_path( const char *path ) +{ const char *temp = path; size_t len; @@ -63,8 +66,8 @@ static const char *normalize_path( const char *path ) // path traverses via root return temp; } -#endif } +#endif // --------------------------------------------------------------------------- diff --git a/app/spiffs/Makefile b/app/spiffs/Makefile index 2deb1efbde..2b1af59f16 100644 --- a/app/spiffs/Makefile +++ b/app/spiffs/Makefile @@ -23,6 +23,7 @@ endif # for a subtree within the makefile rooted therein # DEFINES += -Dprintf=c_printf +#DEFINES += -DDEVELOPMENT_TOOLS -DNODE_DEBUG -DSPIFFS_API_DBG=NODE_DBG ############################################################# # Recursion Magic - Don't touch this!! diff --git a/app/spiffs/myspiffs.h b/app/spiffs/myspiffs.h deleted file mode 100644 index a269aca9e3..0000000000 --- a/app/spiffs/myspiffs.h +++ /dev/null @@ -1,20 +0,0 @@ -#include "spiffs.h" -bool myspiffs_mount(); -void myspiffs_unmount(); -int myspiffs_open(const char *name, int flags); -int myspiffs_close( int fd ); -size_t myspiffs_write( int fd, const void* ptr, size_t len ); -size_t myspiffs_read( int fd, void* ptr, size_t len); -int myspiffs_lseek( int fd, int off, int whence ); -int myspiffs_eof( int fd ); -int myspiffs_tell( int fd ); -int myspiffs_getc( int fd ); -int myspiffs_ungetc( int c, int fd ); -int myspiffs_flush( int fd ); -int myspiffs_error( int fd ); -void myspiffs_clearerr( int fd ); -int myspiffs_check( void ); -int myspiffs_rename( const char *old, const char *newname ); -size_t myspiffs_size( int fd ); -int myspiffs_format (void); - diff --git a/app/spiffs/spiffs.c b/app/spiffs/spiffs.c index 704685ed0d..794bc1a7e4 100644 --- a/app/spiffs/spiffs.c +++ b/app/spiffs/spiffs.c @@ -2,14 +2,31 @@ #include "platform.h" #include "spiffs.h" +/* + * With the intoduction of a unified FatFS and SPIFFS support (#1397), the SPIFFS + * interface is now abstracted through a uses a single SPIFFS entry point + * myspiffs_realm() which returns a vfs_fs_fns object (as does myfatfs_realm()). + * All other functions and data are static. + * + * Non-OS SDK V3.0 introduces a flash partition table (PT) and SPIFFS has now been + * updated to support this: + * - SPIFFS limits search to the specifed SPIFFS0 address and size. + * - Any headroom / offset from other partitions is reflected in the PT allocations. + * - Unforced mounts will attempt to mount any valid SPIFSS found in this range + * (NodeMCU uses the SPIFFS_USE_MAGIC setting to make existing FS discoverable). + * - Subject to the following, no offset or FS search is done. The FS is assumed + * to be at the first valid location at the start of the partition. + */ #include "spiffs_nucleus.h" -spiffs fs; +static spiffs fs; #define LOG_PAGE_SIZE 256 #define LOG_BLOCK_SIZE (INTERNAL_FLASH_SECTOR_SIZE * 2) #define LOG_BLOCK_SIZE_SMALL_FS (INTERNAL_FLASH_SECTOR_SIZE) #define MIN_BLOCKS_FS 4 +#define MASK_1MB (0x100000-1) +#define ALIGN (0x2000) static u8_t spiffs_work_buf[LOG_PAGE_SIZE*2]; static u8_t spiffs_fds[sizeof(spiffs_fd) * SPIFFS_MAX_OPEN_FILES]; @@ -42,131 +59,64 @@ void myspiffs_check_callback(spiffs_check_type type, spiffs_check_report report, } /******************* -The W25Q32BV array is organized into 16,384 programmable pages of 256-bytes each. Up to 256 bytes can be programmed at a time.  -Pages can be erased in groups of 16 (4KB sector erase), groups of 128 (32KB block erase), groups of 256 (64KB block erase) or  -the entire chip (chip erase). The W25Q32BV has 1,024 erasable sectors and 64 erasable blocks respectively.  -The small 4KB sectors allow for greater flexibility in applications that require data and parameter storage.  - -********************/ + * Note that the W25Q32BV array is organized into 16,384 programmable pages of 256-bytes  + * each. Up to 256 bytes can be programmed at a time. Pages can be erased in groups of  + * 16 (4KB sector erase), groups of 128 (32KB block erase), groups of 256 (64KB block  + * erase) or the entire chip (chip erase). The W25Q32BV has 1,024 erasable sectors and  + * 64 erasable blocks respectively. The small 4KB sectors allow for greater flexibility  + * in applications that require data and parameter storage.  + * + * Returns TRUE if FS was found. + */ +static bool myspiffs_set_cfg(spiffs_config *cfg, bool force_create) { + uint32 pt_start, pt_size, pt_end; -static bool myspiffs_set_location(spiffs_config *cfg, int align, int offset, int block_size) { -#ifdef SPIFFS_FIXED_LOCATION - cfg->phys_addr = (SPIFFS_FIXED_LOCATION + block_size - 1) & ~(block_size-1); -#else - cfg->phys_addr = ( u32_t )platform_flash_get_first_free_block_address( NULL ) + offset; - cfg->phys_addr = (cfg->phys_addr + align - 1) & ~(align - 1); -#endif -#ifdef SPIFFS_SIZE_1M_BOUNDARY - cfg->phys_size = ((0x100000 - (SYS_PARAM_SEC_NUM * INTERNAL_FLASH_SECTOR_SIZE) - ( ( u32_t )cfg->phys_addr )) & ~(block_size - 1)) & 0xfffff; -#else - cfg->phys_size = (INTERNAL_FLASH_SIZE - ( ( u32_t )cfg->phys_addr )) & ~(block_size - 1); -#endif - if ((int) cfg->phys_size < 0) { + pt_size = platform_flash_get_partition (NODEMCU_SPIFFS0_PARTITION, &pt_start); + if (pt_size == 0) { return FALSE; } - cfg->log_block_size = block_size; - - return (cfg->phys_size / block_size) >= MIN_BLOCKS_FS; -} - -/* - * Returns TRUE if FS was found - * align must be a power of two - */ -static bool myspiffs_set_cfg_block(spiffs_config *cfg, int align, int offset, int block_size, bool force_create) { - cfg->phys_erase_block = INTERNAL_FLASH_SECTOR_SIZE; // according to datasheet - cfg->log_page_size = LOG_PAGE_SIZE; // as we said + pt_end = pt_start + pt_size; cfg->hal_read_f = my_spiffs_read; cfg->hal_write_f = my_spiffs_write; cfg->hal_erase_f = my_spiffs_erase; - - if (!myspiffs_set_location(cfg, align, offset, block_size)) { + cfg->phys_erase_block = INTERNAL_FLASH_SECTOR_SIZE; + cfg->log_page_size = LOG_PAGE_SIZE; + cfg->phys_addr = (pt_start + ALIGN - 1) & ~(ALIGN - 1); + cfg->phys_size = (pt_end & ~(ALIGN - 1)) - cfg->phys_addr; + + if (cfg->phys_size < MIN_BLOCKS_FS * LOG_BLOCK_SIZE_SMALL_FS) { return FALSE; + } else if (cfg->phys_size < MIN_BLOCKS_FS * LOG_BLOCK_SIZE_SMALL_FS) { + cfg->log_block_size = LOG_BLOCK_SIZE_SMALL_FS; + } else { + cfg->log_block_size = LOG_BLOCK_SIZE; } - NODE_DBG("fs.start:%x,max:%x\n",cfg->phys_addr,cfg->phys_size); - #ifdef SPIFFS_USE_MAGIC_LENGTH - if (force_create) { - return TRUE; - } - - int size = SPIFFS_probe_fs(cfg); - - if (size > 0 && size < cfg->phys_size) { - NODE_DBG("Overriding size:%x\n",size); - cfg->phys_size = size; - } - if (size > 0) { - return TRUE; - } - return FALSE; -#else - return TRUE; -#endif -} - -static bool myspiffs_set_cfg(spiffs_config *cfg, int align, int offset, bool force_create) { - if (force_create) { - return myspiffs_set_cfg_block(cfg, align, offset, LOG_BLOCK_SIZE , TRUE) || - myspiffs_set_cfg_block(cfg, align, offset, LOG_BLOCK_SIZE_SMALL_FS, TRUE); - } - - return myspiffs_set_cfg_block(cfg, align, offset, LOG_BLOCK_SIZE_SMALL_FS, FALSE) || - myspiffs_set_cfg_block(cfg, align, offset, LOG_BLOCK_SIZE , FALSE); -} - -static bool myspiffs_find_cfg(spiffs_config *cfg, bool force_create) { - int i; - if (!force_create) { -#ifdef SPIFFS_FIXED_LOCATION - if (myspiffs_set_cfg(cfg, 0, 0, FALSE)) { - return TRUE; - } -#else - if (INTERNAL_FLASH_SIZE >= 700000) { - for (i = 0; i < 8; i++) { - if (myspiffs_set_cfg(cfg, 0x10000, 0x10000 * i, FALSE)) { - return TRUE; - } - } - } + int size = SPIFFS_probe_fs(cfg); - for (i = 0; i < 8; i++) { - if (myspiffs_set_cfg(cfg, LOG_BLOCK_SIZE, LOG_BLOCK_SIZE * i, FALSE)) { - return TRUE; - } + if (size > 0 && size < cfg->phys_size) { + NODE_DBG("Overriding size:%x\n",size); + cfg->phys_size = size; } -#endif - } - - // No existing file system -- set up for a format - if (INTERNAL_FLASH_SIZE >= 700000) { - myspiffs_set_cfg(cfg, 0x10000, 0x10000, TRUE); -#ifndef SPIFFS_MAX_FILESYSTEM_SIZE - if (cfg->phys_size < 400000) { - // Don't waste so much in alignment - myspiffs_set_cfg(cfg, LOG_BLOCK_SIZE, LOG_BLOCK_SIZE * 4, TRUE); + if (size <= 0) { + return FALSE; } -#endif - } else { - myspiffs_set_cfg(cfg, LOG_BLOCK_SIZE, 0, TRUE); - } - -#ifdef SPIFFS_MAX_FILESYSTEM_SIZE - if (cfg->phys_size > SPIFFS_MAX_FILESYSTEM_SIZE) { - cfg->phys_size = (SPIFFS_MAX_FILESYSTEM_SIZE) & ~(cfg->log_block_size - 1); } #endif - return FALSE; + NODE_DBG("myspiffs set cfg block: %x %x %x %x %x %x\n", pt_start, pt_end, + cfg->phys_size, cfg->phys_addr, cfg->phys_size, cfg->log_block_size); + + return TRUE; } -static bool myspiffs_mount_internal(bool force_mount) { + +static bool myspiffs_mount(bool force_mount) { spiffs_config cfg; - if (!myspiffs_find_cfg(&cfg, force_mount) && !force_mount) { + if (!myspiffs_set_cfg(&cfg, force_mount) && !force_mount) { return FALSE; } @@ -189,10 +139,6 @@ static bool myspiffs_mount_internal(bool force_mount) { return res == SPIFFS_OK; } -bool myspiffs_mount() { - return myspiffs_mount_internal(FALSE); -} - void myspiffs_unmount() { SPIFFS_unmount(&fs); } @@ -202,7 +148,7 @@ void myspiffs_unmount() { int myspiffs_format( void ) { SPIFFS_unmount(&fs); - myspiffs_mount_internal(TRUE); + myspiffs_mount(TRUE); SPIFFS_unmount(&fs); NODE_DBG("Formatting: size 0x%x, addr 0x%x\n", fs.cfg.phys_size, fs.cfg.phys_addr); @@ -211,7 +157,7 @@ int myspiffs_format( void ) return 0; } - return myspiffs_mount(); + return myspiffs_mount(FALSE); } #if 0 @@ -555,7 +501,7 @@ static sint32_t myspiffs_vfs_fscfg( uint32_t *phys_addr, uint32_t *phys_size ) { static vfs_vol *myspiffs_vfs_mount( const char *name, int num ) { // volume descriptor not supported, just return TRUE / FALSE - return myspiffs_mount() ? (vfs_vol *)1 : NULL; + return myspiffs_mount(FALSE) ? (vfs_vol *)1 : NULL; } static sint32_t myspiffs_vfs_format( void ) { @@ -574,12 +520,12 @@ static void myspiffs_vfs_clearerr( void ) { // --------------------------------------------------------------------------- // VFS interface functions // + vfs_fs_fns *myspiffs_realm( const char *inname, char **outname, int set_current_drive ) { if (inname[0] == '/') { - size_t idstr_len = c_strlen( MY_LDRV_ID ); // logical drive is specified, check if it's our id - if (0 == c_strncmp( &(inname[1]), MY_LDRV_ID, idstr_len )) { - *outname = (char *)&(inname[1 + idstr_len]); + if (0 == c_strncmp(inname + 1, MY_LDRV_ID, sizeof(MY_LDRV_ID)-1)) { + *outname = (char *)(inname + sizeof(MY_LDRV_ID)); if (*outname[0] == '/') { // skip leading / (*outname)++; diff --git a/app/spiffs/spiffs_config.h b/app/spiffs/spiffs_config.h index ac7c23e818..6cb233fd00 100644 --- a/app/spiffs/spiffs_config.h +++ b/app/spiffs/spiffs_config.h @@ -165,7 +165,7 @@ // Lower value generates more read/writes. No meaning having it bigger // than logical page size. #ifndef SPIFFS_COPY_BUFFER_STACK -#define SPIFFS_COPY_BUFFER_STACK (64) +#define SPIFFS_COPY_BUFFER_STACK (256) #endif // Enable this to have an identifiable spiffs filesystem. This will look for diff --git a/app/user/user_exceptions.c b/app/user/user_exceptions.c deleted file mode 100644 index f2ad11aea4..0000000000 --- a/app/user/user_exceptions.c +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Copyright 2015 Dius Computing Pty Ltd. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the - * distribution. - * - Neither the name of the copyright holders nor the names of - * its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - * - * @author Johny Mattsson - */ - -#include "user_exceptions.h" - -static exception_handler_fn load_store_handler; - -void load_non_32_wide_handler (struct exception_frame *ef, uint32_t cause) -{ - uint32_t val, insn; - (void)cause; /* If this is not EXCCAUSE_LOAD_STORE_ERROR you're doing it wrong! */ - - asm ( - /* - * Move the aligned content of the exception addr to val - */ - "rsr a6, EXCVADDR;" /* read out the faulting address */ - "movi a5, ~3;" /* prepare a mask for the EPC */ - "and a5, a5, a6;" /* apply mask for 32bit aligned base */ - "l32i a5, a5, 0;" /* load aligned value */ - "ssa8l a6;" /* set up shift register for value */ - "srl %[val], a5;" /* shift left to align value */ - /* we are done with a6 = EXCVADDR */ - /* - * Move the aligned instruction to insn - */ - "movi a5, ~3;" /* prepare a mask for the insn */ - "and a6, a5, %[epc];" /* apply mask for 32bit aligned base */ - "l32i a5, a6, 0;" /* load part 1 */ - "l32i a6, a6, 4;" /* load part 2 */ - "ssa8l %[epc];" /* set up shift register for src op */ - "src %[op], a6, a5;" /* right shift to get faulting instruction */ - :[val]"=r"(val), [op]"=r"(insn) - :[epc]"r"(ef->epc) - :"a5", "a6" - ); - -/* These instructions have the format 0xADSBII where AB = opcode and D = dest reg */ - uint32_t regno = (insn>>4)&0x0f; /* pick out nibble D*/ - uint32_t opcode = (uint8_t) (((insn>>12)<<4)|(insn&0xf)); /* and nibbles AB */ -#define L8UI 0x02u -#define L16UI 0x12u -#define L16SI 0x92u - - if (opcode == L8UI) { /* L8UI */ - val = (uint8_t) val; - } else { - val = (uint16_t) val; /* assume L16SI or L16UI */ - if (opcode == L16SI) { - val = (unsigned)((int)((sint16_t)val)); /* force signed 16->32 bit */ - } else if (opcode != L16UI) { - /* - * Anything other than L8UI, L16SI or L16UI then chain to the next handler - * if set (typically a remote GDB break). Otherwise execute the default action - * which is to trigger a system break and hang if the break doesn't get handled - */ - if (load_store_handler) { - load_store_handler(NULL, 0 /* ef , cause */); - return; - } else { - asm ("break 1, 1"); - while (1) {} - } - } - } - ef->a_reg[regno ? regno-1: regno] = val; /* carry out the load */ - ef->epc += 3; /* resume at following instruction */ -} - -/** - * The SDK's user_main function installs a debugging handler regardless - * of whether there's a proper handler installed for EXCCAUSE_LOAD_STORE_ERROR, - * which of course breaks everything if we allow that to go through. As such, - * we use the linker to wrap that call and stop the SDK from shooting itself in - * its proverbial foot. We do save the EXCCAUSE_LOAD_STORE_ERROR handler so that - * we can chain to it above. - */ -exception_handler_fn TEXT_SECTION_ATTR -__wrap__xtos_set_exception_handler (uint32_t cause, exception_handler_fn fn) -{ - if (cause != EXCCAUSE_LOAD_STORE_ERROR) - __real__xtos_set_exception_handler (cause, fn); - else - load_store_handler = fn; -} diff --git a/app/user/user_main.c b/app/user/user_main.c index 78ac3fe9b4..c3be30302f 100644 --- a/app/user/user_main.c +++ b/app/user/user_main.c @@ -16,7 +16,6 @@ #include "vfs.h" #include "flash_api.h" #include "user_interface.h" -#include "user_exceptions.h" #include "user_modules.h" #include "ets_sys.h" @@ -24,6 +23,7 @@ #include "task/task.h" #include "mem.h" #include "espconn.h" +#include "sections.h" #ifdef LUA_USE_MODULES_RTCTIME #include "rtc/rtctime.h" @@ -36,74 +36,163 @@ static uint8 input_sig_flag = 0; extern const uint32_t init_data[]; extern const uint32_t init_data_end[]; __asm__( - /* Place in .text for same reason as user_start_trampoline */ - ".section \".rodata.dram\"\n" ".align 4\n" - "init_data:\n" - ".incbin \"" ESP_INIT_DATA_DEFAULT "\"\n" + "init_data: .incbin \"" ESP_INIT_DATA_DEFAULT "\"\n" "init_data_end:\n" - ".previous\n" ); - -/* Note: the trampoline *must* be explicitly put into the .text segment, since - * by the time it is invoked the irom has not yet been mapped. This naturally - * also goes for anything the trampoline itself calls. +extern const char _irom0_text_start[], _irom0_text_end[],_flash_used_end[]; +#define IROM0_SIZE (_irom0_text_end - _irom0_text_start) + +#define INIT_DATA_SIZE (init_data_end - init_data) + +#define PRE_INIT_TEXT_ATTR __attribute__((section(".p3.pre_init"))) +#define IROM_PTABLE_ATTR __attribute__((section(".irom0.ptable"))) + +#define PARTITION(n) (SYSTEM_PARTITION_CUSTOMER_BEGIN + n) + +#define SIZE_256K 0x00040000 +#define SIZE_1024K 0x00100000 +#define FLASH_BASE_ADDR ((char *) 0x40200000) + +//TODO: map the TLS server and client certs into NODEMCU_TLSCERT_PARTITION +const partition_item_t partition_init_table[] IROM_PTABLE_ATTR = { + { PARTITION(NODEMCU_EAGLEROM_PARTITION), 0x00000, 0x0B000}, + { SYSTEM_PARTITION_RF_CAL, 0x0B000, 0x1000}, + { SYSTEM_PARTITION_PHY_DATA, 0x0C000, 0x1000}, + { SYSTEM_PARTITION_SYSTEM_PARAMETER, 0x0D000, 0x3000}, + { PARTITION(NODEMCU_IROM0TEXT_PARTITION), 0x10000, 0x0000}, + { PARTITION(NODEMCU_LFS0_PARTITION), 0x0, LUA_FLASH_STORE}, + { PARTITION(NODEMCU_SPIFFS0_PARTITION), 0x0, SPIFFS_MAX_FILESYSTEM_SIZE}, + {0,(uint32_t) &_irom0_text_end,0} +}; +// The following enum must maintain the partition table order +enum partition {iram0=0, rf_call, phy_data, sys_parm, irom0, lfs, spiffs}; +#define PTABLE_SIZE ((sizeof(partition_init_table)/sizeof(partition_item_t))-1) +#define PT_CHUNK 0x8000 +#define PT_ALIGN(n) ((n + (PT_CHUNK-1)) & (~((PT_CHUNK-1)))) +/* + * The non-OS SDK prolog has been fundamentally revised in V3. See SDK EN document + * Partition Table.md for further discussion. This version of user_main.c is a + * complete rework aligned to V3, with the redundant pre-V3 features removed. + * + * SDK V3 significantly reduces the RAM footprint required by the SDK and introduces + * the use of a partition table (PT) to control flash allocation. The NodeMCU uses + * this PT for overall allocation of its flash resources. A constant copy PT is + * maintained at the start of IROM0 (flash offset 0x10000) -- see partition_init_table + * declaration above -- to facilitate its modification either in the firmware binary + * or in the flash itself. This is Flash PT used during startup to create the live PT + * in RAM that is used by the SDK. + * + * Note that user_pre_init() runs with Icache enabled -- that is the IROM0 partition + * is already mapped the address space at 0x40210000 and so that most SDK services + * are available, such as system_get_flash_size_map() which returns the valid flash + * size (including the 8Mb and 16Mb variants). + * + * We will be separately releasing a host PC-base python tool to configure the PT, + * etc., but the following code will initialise the PT to sensible defaults even if + * this tool isn't used. */ -void TEXT_SECTION_ATTR user_start_trampoline (void) -{ - __real__xtos_set_exception_handler ( - EXCCAUSE_LOAD_STORE_ERROR, load_non_32_wide_handler); +static int setup_partition_table(partition_item_t *pt, uint32_t *n) { + +// Flash size lookup is SIZE_256K*2^N where N is as follows (see SDK/user_interface.h) + static char flash_size_scaler[] = + /* 0 1 2 3 4 5 6 7 8 9 */ + /* ½M ¼M 1M 2M 4M 2M 4M 4M 8M 16M */ + "\001\000\002\003\004\003\004\004\005\006"; + enum flash_size_map fs_size_code = system_get_flash_size_map(); + uint32_t flash_size = SIZE_256K << flash_size_scaler[fs_size_code]; + uint32_t first_free_flash_addr = partition_init_table[PTABLE_SIZE].addr + - (uint32_t) FLASH_BASE_ADDR; + int i,j; + + os_memcpy(pt, partition_init_table, PTABLE_SIZE * sizeof(*pt)); + + + if (flash_size < SIZE_1024K) { + os_printf("Flash size (%u) too small to support NodeMCU\n", flash_size); + return -1; + } else { + os_printf("system SPI FI size:%u, Flash size: %u\n", fs_size_code, flash_size ); + } + +// Calculate the runtime sized partitions +// The iram0, rf_call, phy_data, sys_parm partitions are as-is. + if (pt[irom0].size == 0) { + pt[irom0].size = first_free_flash_addr - pt[irom0].addr; + } + if (pt[lfs].addr == 0) { + pt[lfs].addr = PT_ALIGN(pt[irom0].addr + pt[irom0].size); + os_printf("LFS base: %08X\n", pt[lfs].addr); + } + if (pt[lfs].size == 0) { + pt[lfs].size = 0x10000; + os_printf("LFS size: %08X\n", pt[lfs].size); + } + if (pt[spiffs].addr == 0) { + pt[spiffs].addr = PT_ALIGN(pt[lfs].addr + pt[lfs].size); + os_printf("SPIFFS base: %08X\n", pt[spiffs].addr); + } + + if (pt[spiffs].size == SPIFFS_MAX_FILESYSTEM_SIZE) { + pt[spiffs].size = flash_size - pt[spiffs].addr; + os_printf("SPIFFS size: %08X\n", pt[spiffs].size); + } + +// Check that the phys data partition has been initialised and if not then do this +// now to prevent the SDK halting on a "rf_cal[0] !=0x05,is 0xFF" error. + uint32_t init_data_hdr = 0xffffffff, data_addr = pt[phy_data].addr; + int status = spi_flash_read(data_addr, &init_data_hdr, sizeof (uint32_t)); + if (status == SPI_FLASH_RESULT_OK && *(char *)&init_data_hdr != 0x05) { + uint32_t idata[INIT_DATA_SIZE]; + os_printf("Writing Init Data to 0x%08x\n",data_addr); + spi_flash_erase_sector(data_addr/SPI_FLASH_SEC_SIZE); + os_memcpy(idata, init_data, sizeof(idata)); + spi_flash_write(data_addr, idata, sizeof(idata)); + os_delay_us(1000); + } + +// Check partitions are page aligned and remove and any zero-length partitions. +// This must be done last as this might break the enum partition ordering. + for (i = 0, j = 0; i < PTABLE_SIZE; i++) { + const partition_item_t *p = pt + i; + if ((p->addr| p->size) & (SPI_FLASH_SEC_SIZE-1)) { + os_printf("Partitions must be flash page aligned\n"); + return -1; + } + if (p->size == 0) + continue; + if (j < i) { + pt[j] = *p; + p = pt + j; + } + os_printf("%2u: %08x %08x %08x\n", j, p->type, p->addr, p->size); + j++; + } + + *n = j; + return fs_size_code; +} +void user_pre_init(void) { #ifdef LUA_USE_MODULES_RTCTIME // Note: Keep this as close to call_user_start() as possible, since it // is where the cpu clock actually gets bumped to 80MHz. - rtctime_early_startup (); + rtctime_early_startup (); #endif + static partition_item_t pt[PTABLE_SIZE]; - /* Re-implementation of default init data deployment. The SDK does not - * appear to be laying down its own version of init data anymore, so - * we have to do it again. To see whether we need to, we read out - * the flash size and do a test for esp_init_data based on that size. - * If it's missing, we need to initialize it *right now* before the SDK - * starts up and gets stuck at "rf_cal[0] !=0x05,is 0xFF". - * If the size byte is wrong, then we'll end up fixing up the init data - * again on the next boot, after we've corrected the size byte. - * Only remaining issue is lack of spare code bytes in iram, so this - * is deliberately quite terse and not as readable as one might like. - */ - SPIFlashInfo sfi; - - // enable operations on >4MB flash chip - extern SpiFlashChip * flashchip; - uint32 orig_chip_size = flashchip->chip_size; - flashchip->chip_size = FLASH_SIZE_16MBYTE; - - SPIRead (0, (uint32_t *)(&sfi), sizeof (sfi)); // Cache read not enabled yet, safe to use - // handle all size entries - switch (sfi.size) { - case 0: sfi.size = 1; break; // SIZE_4MBIT - case 1: sfi.size = 0; break; // SIZE_2MBIT - case 5: sfi.size = 3; break; // SIZE_16MBIT_8M_8M - case 6: // fall-through - case 7: sfi.size = 4; break; // SIZE_32MBIT_8M_8M, SIZE_32MBIT_16M_16M - case 8: sfi.size = 5; break; // SIZE_64MBIT - case 9: sfi.size = 6; break; // SIZE_128MBIT - default: break; - } - uint32_t flash_end_addr = (256 * 1024) << sfi.size; - uint32_t init_data_hdr = 0xffffffff; - uint32_t init_data_addr = flash_end_addr - 4 * SPI_FLASH_SEC_SIZE; - SPIRead (init_data_addr, &init_data_hdr, sizeof (init_data_hdr)); - if (init_data_hdr == 0xffffffff) - { - SPIEraseSector (init_data_addr); - SPIWrite (init_data_addr, init_data, 4 * (init_data_end - init_data)); - } + uint32_t pt_size; + uint32_t fs_size_code = setup_partition_table(pt, &pt_size); + if( fs_size_code > 0 && system_partition_table_regist(pt, pt_size, fs_size_code)) { + return; + } + os_printf("system_partition_table_regist fail (%u)\n", fs_size_code); + while(1); - // revert temporary setting - flashchip->chip_size = orig_chip_size; +} - call_user_start (); +uint32 ICACHE_RAM_ATTR user_iram_memory_is_enabled(void) { + return FALSE; // NodeMCU runs like a dog if iRAM is enabled } // +================== New task interface ==================+ @@ -138,32 +227,17 @@ void nodemcu_init(void) { NODE_DBG("Can not init platform for modules.\n"); return; } - uint32_t size_detected = flash_detect_size_byte(); - uint32_t size_from_rom = flash_rom_get_size_byte(); - if( size_detected != size_from_rom ) { - NODE_ERR("Self adjust flash size. 0x%x (ROM) -> 0x%x (Detected)\n", - size_from_rom, size_detected); - // Fit hardware real flash size. - flash_rom_set_size_byte(size_detected); - - system_restart (); - // Don't post the start_lua task, we're about to reboot... - return; - } #ifdef BUILD_SPIFFS if (!vfs_mount("/FLASH", 0)) { // Failed to mount -- try reformat - dbg_printf("Formatting file system. Please wait...\n"); + dbg_printf("Formatting file system. Please wait...\n"); if (!vfs_format()) { NODE_ERR( "\n*** ERROR ***: unable to format. FS might be compromised.\n" ); NODE_ERR( "It is advised to re-flash the NodeMCU image.\n" ); } - // Note that fs_format leaves the file system mounted } - // test_spiffs(); #endif - // endpoint_setup(); if (!task_post_low(task_get_id(start_lua),'s')) NODE_ERR("Failed to post the start_lua task!\n"); @@ -179,59 +253,6 @@ void user_rf_pre_init(void) } #endif -/****************************************************************************** - * FunctionName : user_rf_cal_sector_set - * Description : SDK just reversed 4 sectors, used for rf init data and paramters. - * We add this function to force users to set rf cal sector, since - * we don't know which sector is free in user's application. - * sector map for last several sectors : ABCCC - * A : rf cal - * B : rf init data - * C : sdk parameters - * Parameters : none - * Returns : rf cal sector -*******************************************************************************/ -uint32 -user_rf_cal_sector_set(void) -{ - enum flash_size_map size_map = system_get_flash_size_map(); - uint32 rf_cal_sec = 0; - - switch (size_map) { - case FLASH_SIZE_4M_MAP_256_256: - rf_cal_sec = 128 - 5; - break; - - case FLASH_SIZE_8M_MAP_512_512: - rf_cal_sec = 256 - 5; - break; - - case FLASH_SIZE_16M_MAP_512_512: - case FLASH_SIZE_16M_MAP_1024_1024: - rf_cal_sec = 512 - 5; - break; - - case FLASH_SIZE_32M_MAP_512_512: - case FLASH_SIZE_32M_MAP_1024_1024: - case FLASH_SIZE_32M_MAP_2048_2048: - rf_cal_sec = 1024 - 5; - break; - - case FLASH_SIZE_64M_MAP_1024_1024: - rf_cal_sec = 2048 - 5; - break; - - case FLASH_SIZE_128M_MAP_1024_1024: - rf_cal_sec = 4096 - 5; - break; - - default: - rf_cal_sec = 0; - break; - } - - return rf_cal_sec; -} /****************************************************************************** * FunctionName : user_init @@ -241,6 +262,7 @@ user_rf_cal_sector_set(void) *******************************************************************************/ void user_init(void) { + #ifdef LUA_USE_MODULES_RTCTIME rtctime_late_startup (); #endif @@ -255,3 +277,18 @@ void user_init(void) #endif system_init_done_cb(nodemcu_init); } + +/* + * The SDK now establishes exception handlers for EXCCAUSE errors: ILLEGAL, + * INSTR_ERROR, LOAD_STORE_ERROR, PRIVILEGED, UNALIGNED, LOAD_PROHIBITED, + * STORE_PROHIBITED. These handlers are established in SDK/app_main.c. + * LOAD_STORE_ERROR is handled by SDK/user_exceptions.o:load_non_32_wide_handler() + * which is a fork of our version. The remaining are handled by a static function + * at SDK:app+main.c:offset 0x0348. + * +void __real__xtos_set_exception_handler (uint32_t cause, exception_handler_fn fn); +void __wrap__xtos_set_exception_handler (uint32_t cause, exception_handler_fn fn) { + os_printf("Exception handler %x %x\n", cause, fn); + __real__xtos_set_exception_handler (cause, fn); +} + */ diff --git a/docs/compiling.md b/docs/compiling.md index 01fae44f23..731ee547bb 100644 --- a/docs/compiling.md +++ b/docs/compiling.md @@ -50,19 +50,20 @@ mode is enabled by specifying the `-f`option. - **Compact relocatable**. This is selected by the `-f` option. Here the compiler compresses the compiled binary so that image is small for downloading over Wifi/WAN (e.g. a full 64Kb LFS image is compressed down to a 22Kb file.) The LVM processes such image in two passes with the integrity of the image validated on the first, and the LFS itself gets updated on the second. The LVM also checks that the image will fit in the allocated LFS region before loading, but you can also use the `-m` option to throw a compile error if the image is too large, for example `-m 0x10000` will raise an error if the image will not load into a 64Kb regions. -- **Absolute**. This is selected by the `-a ` option. Here the compiler fixes all addresses relative to the base address specified. This allows an LFS absolute image to be loaded directly into the ESP flash using a tool such as `esptool.py`. +- **Absolute**. This is selected by the `-a ` option. Here the compiler fixes all addresses relative to the base address specified. This allows an LFS absolute image to be loaded directly into the ESP flash using a tool such as `esptool.py`. _Note that the new NodeMCU loader uses the `-f` compact relocatable form and does relocation based on the Partition Table, so this option is deprecated and will be removed in future releases. These two modes target two separate use cases: the compact relocatable format facilitates simple OTA updates to an LFS based Lua application; the absolute format facilitates factory installation of LFS based applications. Also note that the `app/lua/luac_cross` make and Makefile can be executed to build -just the `luac.cross` image. You must first ensure that the following options in -`app/include/user_config.h` are matched to your target configuration: +just the `luac.cross` image. You must first ensure that the following option in +`app/include/user_config.h` is matched to your target configuration: ```c //#define LUA_NUMBER_INTEGRAL // uncomment if you want an integer build -//#define LUA_FLASH_STORE 0x10000 // uncomment if you LFS support ``` +Note that the use of LFS and the LFS region size is now configured through the partition table. + Developers have successfully built this on Linux (including docker builds), MacOS, Win10/WSL and WinX/Cygwin. diff --git a/docs/getting-started.md b/docs/getting-started.md index 8dbea439cc..4c3a76aee0 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -226,7 +226,7 @@ Detailed instructions available in the image's README. As for available config o ### For LFS -1. In `app/include/user_config.h` uncomment `#define LUA_FLASH_STORE 0x10000` and adjust the size if necessary. +1. In `app/include/user_config.h` edit the line `#define LUA_FLASH_STORE 0x0` and adjust the size to that needed. Note that this must be a multiple of 4Kb. 2. Build as you would otherwise build with this image (i.e. see its README) [↑ back to matrix](#task-os-selector) @@ -238,24 +238,25 @@ _Note that this Docker image is not an official NodeMCU offering. It's maintaine A local copy of `luac.cross` is only needed if you want to compile the Lua files into an LFS image yourself and you are _not_ using Docker. ### Windows -Windows 10 users can install and use the Windows Subsystem for Linux (WSL). Alternatively all Windows users can [install Cygwin](https://www.cygwin.com/install.html) (only Cygwin core + **gcc-core** + **gnu make**). Either way, you will need a copy of the `luac.cross` compiler: - -- You can either download this from Terry's fileserver. The [ELF variant](http://files.ellisons.org.uk/esp8266/luac.cross) is used for all recent Linux and WSL flavours, or the [cygwin binary](http://files.ellisons.org.uk/esp8266/luac.cross.cygwin)) for the Cygwin environment. -- Or you can compile it yourself by downloading the current NodeMCU sources (this [ZIPfile](https://github.com/nodemcu/nodemcu-firmware/archive/master.zip)); edit the `app/includes/user_config.h` file and then `cd` to the `app/lua/luac_cross` and run make to build the compiler in the NodeMCU firmware root directory. Note that the `luac.cross` make only needs the host toolchain which is installed by default. - -### macOS - -TBD - -1. `$ cd app/lua/luac_cross` -2. `$ make` +Windows users can compile a local copy of the `luac.cross` executable for use on a development PC. To this you need: +- To download the current NodeMCU sources (this [dev ZIP file](https://github.com/nodemcu/nodemcu-firmware/archive/dev.zip) or [master ZIP file](https://github.com/nodemcu/nodemcu-firmware/archive/master.zip)) and unpack into a local folder, say `C:\nodemcu-firmware`; choose the master / dev versions to match the firmware version that you want to use. If you want an Integer buld then edit the `app/includes/user_config.h` file to select this. +- Choose a preferred toolchain to build your `luac.cross` executable. You have a number of options here: + - If you are a Windows 10 user with the Windows Subsystem for Linux (WSL) already installed, then this is a Linux environment so you can follow the [Linux build instructions](#Linux) below. + - A less resource intensive option which works on all Windows OS variants is to use Cygwin or MinGW, which are varaint ports of the [GNU Compiler Collection](https://gcc.gnu.org/) to Windows and which can both compile to native Windows executables. In the case of Cygwin, [install Cygwin](https://www.cygwin.com/install.html) (selecting the Cygwin core + **gcc-core** + **gnu make** in the install menu). In the case of MinGW you again only need a very basic C build environment so [install the MINGW](http://mingw.org/wiki/InstallationHOWTOforMinGW); you only need the core GCC and mingw32-make. Both both these create a **Cmd** prompt which paths in the relevant GCC toolchain. Switch to the `app/lua/luac_cross` and run make to build the compiler in the NodeMCU firmware root directory. You do this by rning `make` in Cygwin and `mingw32-make -f mingw32-Makefile.mak` in MinGW. + - If you can C development experience on the PC and a version of the MS Visual Studio on your PC then you can also simply build the image using the supplied MS project file. +- Once you have a built `luac.cross` executable, then you can use this to compile Lua code into an LFS image. You might wish to move this out of the nodemcu-firmware hierarchy, since this folder hierarchy is no longer required and can be trashed. ### Linux -TBD +- Ensure that you have a "build essential" GCC toolchain installed. +- Download the current NodeMCU sources (this [dev ZIP file](https://github.com/nodemcu/nodemcu-firmware/archive/dev.zip) or [master ZIP file](https://github.com/nodemcu/nodemcu-firmware/archive/master.zip)) and unpack into a local folder; choose the master / dev versions to match the firmware version that you want to use. If you want an Integer buld then edit the `app/includes/user_config.h` file to select this. +- Change directory to the `app/lua/luac_cross` sub-folder +- Run `make` to build the executable. +- Once you have a built `luac.cross` executable, then you can use this to compile Lua code into an LFS image. You might wish to move this out of the nodemcu-firmware hierarchy, since this folder hierarchy is no longer required and can be trashed. + +### macOS -1. `$ cd app/lua/luac_cross` -2. `$ make` +As for [Linux](#linux) [↑ back to matrix](#task-os-selector) diff --git a/docs/modules/node.md b/docs/modules/node.md index c2c29f830e..5d6a132e6e 100644 --- a/docs/modules/node.md +++ b/docs/modules/node.md @@ -183,7 +183,7 @@ Returns the function reference for a function in the [LFS (Lua Flash Store)](../ `modulename` The name of the module to be loaded. If this is `nil` or invalid then an info list is returned #### Returns -- In the case where the LFS in not loaded, `node.flashindex` evaluates to `nil`, followed by the flash and mapped base addresss of the LFS +- In the case where the LFS in not loaded, `node.flashindex` evaluates to `nil`, followed by the flash mapped base addresss of the LFS, its flash offset, and the size of the LFS. - If the LFS is loaded and the function is called with the name of a valid module in the LFS, then the function is returned in the same way the `load()` and the other Lua load functions do. - Otherwise an extended info list is returned: the Unix time of the LFS build, the flash and mapped base addresses of the LFS and its current length, and an array of the valid module names in the LFS. diff --git a/ld/nodemcu.ld b/ld/nodemcu.ld index 154f2f67a6..1b329d7647 100644 --- a/ld/nodemcu.ld +++ b/ld/nodemcu.ld @@ -5,6 +5,7 @@ MEMORY dport0_0_seg : org = 0x3FF00000, len = 0x10 dram0_0_seg : org = 0x3FFE8000, len = 0x14000 iram1_0_seg : org = 0x40100000, len = 0x8000 + iram0_0_seg : org = 0x4010E000, len = 0x2000 irom0_0_seg : org = 0x40210000, len = 0xE0000 } @@ -14,12 +15,13 @@ PHDRS dram0_0_phdr PT_LOAD; dram0_0_bss_phdr PT_LOAD; iram1_0_phdr PT_LOAD; + iram0_0_phdr PT_LOAD; irom0_0_phdr PT_LOAD; } /* Default entry point: */ -ENTRY(user_start_trampoline) +ENTRY(call_user_start) EXTERN(_DebugExceptionVector) EXTERN(_DoubleExceptionVector) EXTERN(_KernelExceptionVector) @@ -221,11 +223,21 @@ SECTIONS _lit4_end = ABSOLUTE(.); } >iram1_0_seg :iram1_0_phdr + .pre_init_ram : ALIGN(0x1000) + { + _iram0_start = ABSOLUTE(.); + *(*.pre_init) + _iram0_end = ABSOLUTE(.); + } >iram0_0_seg :iram0_0_phdr + .irom0.text : ALIGN(0x1000) { _irom0_text_start = ABSOLUTE(.); + *(.irom0.ptable) + . = ALIGN(0x1000); *(.servercert.flash) *(.clientcert.flash) + . = ALIGN(0x1000); *(.irom0.literal .irom.literal .irom.text.literal .irom0.text .irom.text) *(.literal .text .literal.* .text.*) *(.rodata*) diff --git a/sdk-overrides/include/mem.h b/sdk-overrides/include/mem.h deleted file mode 100644 index 1a2f91ecb5..0000000000 --- a/sdk-overrides/include/mem.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef _SDK_OVERRIDE_MEM_H_ -#define _SDK_OVERRIDE_MEM_H_ - -void *pvPortMalloc (size_t sz, const char *, unsigned); -void vPortFree (void *p, const char *, unsigned); -void *pvPortZalloc (size_t sz, const char *, unsigned); -void *pvPortRealloc (void *p, size_t n, const char *, unsigned); - -#include_next "mem.h" - -#endif diff --git a/tools/esptool.py b/tools/esptool.py deleted file mode 100755 index 38ffb7246b..0000000000 --- a/tools/esptool.py +++ /dev/null @@ -1,1236 +0,0 @@ -#!/usr/bin/env python -# NB: Before sending a PR to change the above line to '#!/usr/bin/env python2', please read https://github.com/themadinventor/esptool/issues/21 -# -# ESP8266 ROM Bootloader Utility -# https://github.com/themadinventor/esptool -# -# Copyright (C) 2014-2016 Fredrik Ahlberg, Angus Gratton, other contributors as noted. -# -# This program is free software; you can redistribute it and/or modify it under -# the terms of the GNU General Public License as published by the Free Software -# Foundation; either version 2 of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along with -# this program; if not, write to the Free Software Foundation, Inc., 51 Franklin -# Street, Fifth Floor, Boston, MA 02110-1301 USA. - -import argparse -import hashlib -import inspect -import json -import os -import serial -import struct -import subprocess -import sys -import tempfile -import time - - -__version__ = "1.2-dev" - - -class ESPROM(object): - # These are the currently known commands supported by the ROM - ESP_FLASH_BEGIN = 0x02 - ESP_FLASH_DATA = 0x03 - ESP_FLASH_END = 0x04 - ESP_MEM_BEGIN = 0x05 - ESP_MEM_END = 0x06 - ESP_MEM_DATA = 0x07 - ESP_SYNC = 0x08 - ESP_WRITE_REG = 0x09 - ESP_READ_REG = 0x0a - - # Maximum block sized for RAM and Flash writes, respectively. - ESP_RAM_BLOCK = 0x1800 - ESP_FLASH_BLOCK = 0x400 - - # Default baudrate. The ROM auto-bauds, so we can use more or less whatever we want. - ESP_ROM_BAUD = 115200 - - # First byte of the application image - ESP_IMAGE_MAGIC = 0xe9 - - # Initial state for the checksum routine - ESP_CHECKSUM_MAGIC = 0xef - - # OTP ROM addresses - ESP_OTP_MAC0 = 0x3ff00050 - ESP_OTP_MAC1 = 0x3ff00054 - ESP_OTP_MAC3 = 0x3ff0005c - - # Flash sector size, minimum unit of erase. - ESP_FLASH_SECTOR = 0x1000 - - def __init__(self, port=0, baud=ESP_ROM_BAUD): - self._port = serial.Serial(port) - self._slip_reader = slip_reader(port) - # setting baud rate in a separate step is a workaround for - # CH341 driver on some Linux versions (this opens at 9600 then - # sets), shouldn't matter for other platforms/drivers. See - # https://github.com/themadinventor/esptool/issues/44#issuecomment-107094446 - self._port.baudrate = baud - - """ Read a SLIP packet from the serial port """ - def read(self): - return self._slip_reader.next() - - """ Write bytes to the serial port while performing SLIP escaping """ - def write(self, packet): - buf = '\xc0' \ - + (packet.replace('\xdb','\xdb\xdd').replace('\xc0','\xdb\xdc')) \ - + '\xc0' - self._port.write(buf) - - """ Calculate checksum of a blob, as it is defined by the ROM """ - @staticmethod - def checksum(data, state=ESP_CHECKSUM_MAGIC): - for b in data: - state ^= ord(b) - return state - - """ Send a request and read the response """ - def command(self, op=None, data=None, chk=0): - if op is not None: - pkt = struct.pack('> 16) & 0xff, (mac3 >> 8) & 0xff, mac3 & 0xff) - elif ((mac1 >> 16) & 0xff) == 0: - oui = (0x18, 0xfe, 0x34) - elif ((mac1 >> 16) & 0xff) == 1: - oui = (0xac, 0xd0, 0x74) - else: - raise FatalError("Unknown OUI") - return oui + ((mac1 >> 8) & 0xff, mac1 & 0xff, (mac0 >> 24) & 0xff) - - """ Read Chip ID from OTP ROM - see http://esp8266-re.foogod.com/wiki/System_get_chip_id_%28IoT_RTOS_SDK_0.9.9%29 """ - def chip_id(self): - id0 = self.read_reg(self.ESP_OTP_MAC0) - id1 = self.read_reg(self.ESP_OTP_MAC1) - return (id0 >> 24) | ((id1 & 0xffffff) << 8) - - """ Read SPI flash manufacturer and device id """ - def flash_id(self): - self.flash_begin(0, 0) - self.write_reg(0x60000240, 0x0, 0xffffffff) - self.write_reg(0x60000200, 0x10000000, 0xffffffff) - flash_id = self.read_reg(0x60000240) - self.flash_finish(False) - return flash_id - - """ Abuse the loader protocol to force flash to be left in write mode """ - def flash_unlock_dio(self): - # Enable flash write mode - self.flash_begin(0, 0) - # Reset the chip rather than call flash_finish(), which would have - # write protected the chip again (why oh why does it do that?!) - self.mem_begin(0,0,0,0x40100000) - self.mem_finish(0x40000080) - - """ Perform a chip erase of SPI flash """ - def flash_erase(self): - # Trick ROM to initialize SFlash - self.flash_begin(0, 0) - - # This is hacky: we don't have a custom stub, instead we trick - # the bootloader to jump to the SPIEraseChip() routine and then halt/crash - # when it tries to boot an unconfigured system. - self.mem_begin(0,0,0,0x40100000) - self.mem_finish(0x40004984) - - # Yup - there's no good way to detect if we succeeded. - # It it on the other hand unlikely to fail. - - def run_stub(self, stub, params, read_output=True): - stub = dict(stub) - stub['code'] = unhexify(stub['code']) - if 'data' in stub: - stub['data'] = unhexify(stub['data']) - - if stub['num_params'] != len(params): - raise FatalError('Stub requires %d params, %d provided' - % (stub['num_params'], len(params))) - - params = struct.pack('<' + ('I' * stub['num_params']), *params) - pc = params + stub['code'] - - # Upload - self.mem_begin(len(pc), 1, len(pc), stub['params_start']) - self.mem_block(pc, 0) - if 'data' in stub: - self.mem_begin(len(stub['data']), 1, len(stub['data']), stub['data_start']) - self.mem_block(stub['data'], 0) - self.mem_finish(stub['entry']) - - if read_output: - print 'Stub executed, reading response:' - while True: - p = self.read() - print hexify(p) - if p == '': - return - - -class ESPBOOTLOADER(object): - """ These are constants related to software ESP bootloader, working with 'v2' image files """ - - # First byte of the "v2" application image - IMAGE_V2_MAGIC = 0xea - - # First 'segment' value in a "v2" application image, appears to be a constant version value? - IMAGE_V2_SEGMENT = 4 - - -def LoadFirmwareImage(filename): - """ Load a firmware image, without knowing what kind of file (v1 or v2) it is. - - Returns a BaseFirmwareImage subclass, either ESPFirmwareImage (v1) or OTAFirmwareImage (v2). - """ - with open(filename, 'rb') as f: - magic = ord(f.read(1)) - f.seek(0) - if magic == ESPROM.ESP_IMAGE_MAGIC: - return ESPFirmwareImage(f) - elif magic == ESPBOOTLOADER.IMAGE_V2_MAGIC: - return OTAFirmwareImage(f) - else: - raise FatalError("Invalid image magic number: %d" % magic) - - -class BaseFirmwareImage(object): - """ Base class with common firmware image functions """ - def __init__(self): - self.segments = [] - self.entrypoint = 0 - - def add_segment(self, addr, data, pad_to=4): - """ Add a segment to the image, with specified address & data - (padded to a boundary of pad_to size) """ - # Data should be aligned on word boundary - l = len(data) - if l % pad_to: - data += b"\x00" * (pad_to - l % pad_to) - if l > 0: - self.segments.append((addr, len(data), data)) - - def load_segment(self, f, is_irom_segment=False): - """ Load the next segment from the image file """ - (offset, size) = struct.unpack(' 0x40200000 or offset < 0x3ffe0000 or size > 65536: - raise FatalError('Suspicious segment 0x%x, length %d' % (offset, size)) - segment_data = f.read(size) - if len(segment_data) < size: - raise FatalError('End of file reading segment 0x%x, length %d (actual length %d)' % (offset, size, len(segment_data))) - segment = (offset, size, segment_data) - self.segments.append(segment) - return segment - - def save_segment(self, f, segment, checksum=None): - """ Save the next segment to the image file, return next checksum value if provided """ - (offset, size, data) = segment - f.write(struct.pack(' 16: - raise FatalError('Invalid firmware image magic=%d segments=%d' % (magic, segments)) - - for i in xrange(segments): - self.load_segment(load_file) - self.checksum = self.read_checksum(load_file) - - def save(self, filename): - with open(filename, 'wb') as f: - self.write_v1_header(f, self.segments) - checksum = ESPROM.ESP_CHECKSUM_MAGIC - for segment in self.segments: - checksum = self.save_segment(f, segment, checksum) - self.append_checksum(f, checksum) - - -class OTAFirmwareImage(BaseFirmwareImage): - """ 'Version 2' firmware image, segments loaded by software bootloader stub - (ie Espressif bootloader or rboot) - """ - def __init__(self, load_file=None): - super(OTAFirmwareImage, self).__init__() - self.version = 2 - if load_file is not None: - (magic, segments, first_flash_mode, first_flash_size_freq, first_entrypoint) = struct.unpack(' 16: - raise FatalError('Invalid V2 second header magic=%d segments=%d' % (magic, segments)) - - # load all the usual segments - for _ in xrange(segments): - self.load_segment(load_file) - self.checksum = self.read_checksum(load_file) - - def save(self, filename): - with open(filename, 'wb') as f: - # Save first header for irom0 segment - f.write(struct.pack(' 0: - esp._port.baudrate = baud_rate - # Read the greeting. - p = esp.read() - if p != 'OHAI': - raise FatalError('Failed to connect to the flasher (got %s)' % hexify(p)) - - def flash_write(self, addr, data, show_progress=False): - assert addr % self._esp.ESP_FLASH_SECTOR == 0, 'Address must be sector-aligned' - assert len(data) % self._esp.ESP_FLASH_SECTOR == 0, 'Length must be sector-aligned' - sys.stdout.write('Writing %d @ 0x%x... ' % (len(data), addr)) - sys.stdout.flush() - self._esp.write(struct.pack(' length: - raise FatalError('Read more than expected') - p = self._esp.read() - if len(p) != 16: - raise FatalError('Expected digest, got: %s' % hexify(p)) - expected_digest = hexify(p).upper() - digest = hashlib.md5(data).hexdigest().upper() - print - if digest != expected_digest: - raise FatalError('Digest mismatch: expected %s, got %s' % (expected_digest, digest)) - p = self._esp.read() - if len(p) != 1: - raise FatalError('Expected status, got: %s' % hexify(p)) - status_code = struct.unpack(', ) or a single -# argument. - -def load_ram(esp, args): - image = LoadFirmwareImage(args.filename) - - print 'RAM boot...' - for (offset, size, data) in image.segments: - print 'Downloading %d bytes at %08x...' % (size, offset), - sys.stdout.flush() - esp.mem_begin(size, div_roundup(size, esp.ESP_RAM_BLOCK), esp.ESP_RAM_BLOCK, offset) - - seq = 0 - while len(data) > 0: - esp.mem_block(data[0:esp.ESP_RAM_BLOCK], seq) - data = data[esp.ESP_RAM_BLOCK:] - seq += 1 - print 'done!' - - print 'All segments done, executing at %08x' % image.entrypoint - esp.mem_finish(image.entrypoint) - - -def read_mem(esp, args): - print '0x%08x = 0x%08x' % (args.address, esp.read_reg(args.address)) - - -def write_mem(esp, args): - esp.write_reg(args.address, args.value, args.mask, 0) - print 'Wrote %08x, mask %08x to %08x' % (args.value, args.mask, args.address) - - -def dump_mem(esp, args): - f = file(args.filename, 'wb') - for i in xrange(args.size / 4): - d = esp.read_reg(args.address + (i * 4)) - f.write(struct.pack('> 8) & 0xff, (flash_id >> 16) & 0xff) - - -def read_flash(esp, args): - flasher = CesantaFlasher(esp, args.baud) - t = time.time() - data = flasher.flash_read(args.address, args.size, not args.no_progress) - t = time.time() - t - print ('\rRead %d bytes at 0x%x in %.1f seconds (%.1f kbit/s)...' - % (len(data), args.address, t, len(data) / t * 8 / 1000)) - file(args.filename, 'wb').write(data) - - -def _verify_flash(flasher, args, flash_params=None): - differences = False - for address, argfile in args.addr_filename: - image = argfile.read() - argfile.seek(0) # rewind in case we need it again - if address == 0 and image[0] == '\xe9' and flash_params is not None: - image = image[0:2] + flash_params + image[4:] - image_size = len(image) - print 'Verifying 0x%x (%d) bytes @ 0x%08x in flash against %s...' % (image_size, image_size, address, argfile.name) - # Try digest first, only read if there are differences. - digest, _ = flasher.flash_digest(address, image_size) - digest = hexify(digest).upper() - expected_digest = hashlib.md5(image).hexdigest().upper() - if digest == expected_digest: - print '-- verify OK (digest matched)' - continue - else: - differences = True - if getattr(args, 'diff', 'no') != 'yes': - print '-- verify FAILED (digest mismatch)' - continue - - flash = flasher.flash_read(address, image_size) - assert flash != image - diff = [i for i in xrange(image_size) if flash[i] != image[i]] - print '-- verify FAILED: %d differences, first @ 0x%08x' % (len(diff), address + diff[0]) - for d in diff: - print ' %08x %02x %02x' % (address + d, ord(flash[d]), ord(image[d])) - if differences: - raise FatalError("Verify failed.") - - -def verify_flash(esp, args, flash_params=None): - flasher = CesantaFlasher(esp) - _verify_flash(flasher, args, flash_params) - - -def version(args): - print __version__ - -# -# End of operations functions -# - - -def main(): - parser = argparse.ArgumentParser(description='esptool.py v%s - ESP8266 ROM Bootloader Utility' % __version__, prog='esptool') - - parser.add_argument( - '--port', '-p', - help='Serial port device', - default=os.environ.get('ESPTOOL_PORT', '/dev/ttyUSB0')) - - parser.add_argument( - '--baud', '-b', - help='Serial port baud rate used when flashing/reading', - type=arg_auto_int, - default=os.environ.get('ESPTOOL_BAUD', ESPROM.ESP_ROM_BAUD)) - - subparsers = parser.add_subparsers( - dest='operation', - help='Run esptool {command} -h for additional help') - - parser_load_ram = subparsers.add_parser( - 'load_ram', - help='Download an image to RAM and execute') - parser_load_ram.add_argument('filename', help='Firmware image') - - parser_dump_mem = subparsers.add_parser( - 'dump_mem', - help='Dump arbitrary memory to disk') - parser_dump_mem.add_argument('address', help='Base address', type=arg_auto_int) - parser_dump_mem.add_argument('size', help='Size of region to dump', type=arg_auto_int) - parser_dump_mem.add_argument('filename', help='Name of binary dump') - - parser_read_mem = subparsers.add_parser( - 'read_mem', - help='Read arbitrary memory location') - parser_read_mem.add_argument('address', help='Address to read', type=arg_auto_int) - - parser_write_mem = subparsers.add_parser( - 'write_mem', - help='Read-modify-write to arbitrary memory location') - parser_write_mem.add_argument('address', help='Address to write', type=arg_auto_int) - parser_write_mem.add_argument('value', help='Value', type=arg_auto_int) - parser_write_mem.add_argument('mask', help='Mask of bits to write', type=arg_auto_int) - - def add_spi_flash_subparsers(parent): - """ Add common parser arguments for SPI flash properties """ - parent.add_argument('--flash_freq', '-ff', help='SPI Flash frequency', - choices=['40m', '26m', '20m', '80m'], - default=os.environ.get('ESPTOOL_FF', '40m')) - parent.add_argument('--flash_mode', '-fm', help='SPI Flash mode', - choices=['qio', 'qout', 'dio', 'dout'], - default=os.environ.get('ESPTOOL_FM', 'qio')) - parent.add_argument('--flash_size', '-fs', help='SPI Flash size in Mbit', type=str.lower, - choices=['4m', '2m', '8m', '16m', '32m', '16m-c1', '32m-c1', '32m-c2', '64m', '128m'], - default=os.environ.get('ESPTOOL_FS', '4m')) - - parser_write_flash = subparsers.add_parser( - 'write_flash', - help='Write a binary blob to flash') - parser_write_flash.add_argument('addr_filename', metavar='
', help='Address followed by binary filename, separated by space', - action=AddrFilenamePairAction) - add_spi_flash_subparsers(parser_write_flash) - parser_write_flash.add_argument('--no-progress', '-p', help='Suppress progress output', action="store_true") - parser_write_flash.add_argument('--verify', help='Verify just-written data (only necessary if very cautious, data is already CRCed', action='store_true') - - subparsers.add_parser( - 'run', - help='Run application code in flash') - - parser_image_info = subparsers.add_parser( - 'image_info', - help='Dump headers from an application image') - parser_image_info.add_argument('filename', help='Image file to parse') - - parser_make_image = subparsers.add_parser( - 'make_image', - help='Create an application image from binary files') - parser_make_image.add_argument('output', help='Output image file') - parser_make_image.add_argument('--segfile', '-f', action='append', help='Segment input file') - parser_make_image.add_argument('--segaddr', '-a', action='append', help='Segment base address', type=arg_auto_int) - parser_make_image.add_argument('--entrypoint', '-e', help='Address of entry point', type=arg_auto_int, default=0) - - parser_elf2image = subparsers.add_parser( - 'elf2image', - help='Create an application image from ELF file') - parser_elf2image.add_argument('input', help='Input ELF file') - parser_elf2image.add_argument('--output', '-o', help='Output filename prefix (for version 1 image), or filename (for version 2 single image)', type=str) - parser_elf2image.add_argument('--version', '-e', help='Output image version', choices=['1','2'], default='1') - add_spi_flash_subparsers(parser_elf2image) - - subparsers.add_parser( - 'read_mac', - help='Read MAC address from OTP ROM') - - subparsers.add_parser( - 'chip_id', - help='Read Chip ID from OTP ROM') - - subparsers.add_parser( - 'flash_id', - help='Read SPI flash manufacturer and device ID') - - parser_read_flash = subparsers.add_parser( - 'read_flash', - help='Read SPI flash content') - parser_read_flash.add_argument('address', help='Start address', type=arg_auto_int) - parser_read_flash.add_argument('size', help='Size of region to dump', type=arg_auto_int) - parser_read_flash.add_argument('filename', help='Name of binary dump') - parser_read_flash.add_argument('--no-progress', '-p', help='Suppress progress output', action="store_true") - - parser_verify_flash = subparsers.add_parser( - 'verify_flash', - help='Verify a binary blob against flash') - parser_verify_flash.add_argument('addr_filename', help='Address and binary file to verify there, separated by space', - action=AddrFilenamePairAction) - parser_verify_flash.add_argument('--diff', '-d', help='Show differences', - choices=['no', 'yes'], default='no') - - subparsers.add_parser( - 'erase_flash', - help='Perform Chip Erase on SPI flash') - - subparsers.add_parser( - 'version', help='Print esptool version') - - # internal sanity check - every operation matches a module function of the same name - for operation in subparsers.choices.keys(): - assert operation in globals(), "%s should be a module function" % operation - - args = parser.parse_args() - - print 'esptool.py v%s' % __version__ - - # operation function can take 1 arg (args), 2 args (esp, arg) - # or be a member function of the ESPROM class. - - operation_func = globals()[args.operation] - operation_args,_,_,_ = inspect.getargspec(operation_func) - if operation_args[0] == 'esp': # operation function takes an ESPROM connection object - initial_baud = min(ESPROM.ESP_ROM_BAUD, args.baud) # don't sync faster than the default baud rate - esp = ESPROM(args.port, initial_baud) - esp.connect() - operation_func(esp, args) - else: - operation_func(args) - - -class AddrFilenamePairAction(argparse.Action): - """ Custom parser class for the address/filename pairs passed as arguments """ - def __init__(self, option_strings, dest, nargs='+', **kwargs): - super(AddrFilenamePairAction, self).__init__(option_strings, dest, nargs, **kwargs) - - def __call__(self, parser, namespace, values, option_string=None): - # validate pair arguments - pairs = [] - for i in range(0,len(values),2): - try: - address = int(values[i],0) - except ValueError as e: - raise argparse.ArgumentError(self,'Address "%s" must be a number' % values[i]) - try: - argfile = open(values[i + 1], 'rb') - except IOError as e: - raise argparse.ArgumentError(self, e) - except IndexError: - raise argparse.ArgumentError(self,'Must be pairs of an address and the binary filename to write there') - pairs.append((address, argfile)) - setattr(namespace, self.dest, pairs) - -# This is "wrapped" stub_flasher.c, to be loaded using run_stub. -_CESANTA_FLASHER_STUB = """\ -{"code_start": 1074790404, "code": "080000601C000060000000601000006031FCFF71FCFF\ -81FCFFC02000680332D218C020004807404074DCC48608005823C0200098081BA5A9239245005803\ -1B555903582337350129230B446604DFC6F3FF21EEFFC0200069020DF0000000010078480040004A\ -0040B449004012C1F0C921D911E901DD0209312020B4ED033C2C56C2073020B43C3C56420701F5FF\ -C000003C4C569206CD0EEADD860300202C4101F1FFC0000056A204C2DCF0C02DC0CC6CCAE2D1EAFF\ -0606002030F456D3FD86FBFF00002020F501E8FFC00000EC82D0CCC0C02EC0C73DEB2ADC46030020\ -2C4101E1FFC00000DC42C2DCF0C02DC056BCFEC602003C5C8601003C6C4600003C7C08312D0CD811\ -C821E80112C1100DF0000C180000140010400C0000607418000064180000801800008C1800008418\ -0000881800009018000018980040880F0040A80F0040349800404C4A0040740F0040800F0040980F\ -00400099004012C1E091F5FFC961CD0221EFFFE941F9310971D9519011C01A223902E2D1180C0222\ -6E1D21E4FF31E9FF2AF11A332D0F42630001EAFFC00000C030B43C2256A31621E1FF1A2228022030\ -B43C3256B31501ADFFC00000DD023C4256ED1431D6FF4D010C52D90E192E126E0101DDFFC0000021\ -D2FF32A101C020004802303420C0200039022C0201D7FFC00000463300000031CDFF1A333803D023\ -C03199FF27B31ADC7F31CBFF1A3328030198FFC0000056C20E2193FF2ADD060E000031C6FF1A3328\ -030191FFC0000056820DD2DD10460800000021BEFF1A2228029CE231BCFFC020F51A33290331BBFF\ -C02C411A332903C0F0F4222E1D22D204273D9332A3FFC02000280E27B3F721ABFF381E1A2242A400\ -01B5FFC00000381E2D0C42A40001B3FFC0000056120801B2FFC00000C02000280EC2DC0422D2FCC0\ -2000290E01ADFFC00000222E1D22D204226E1D281E22D204E7B204291E860000126E012198FF32A0\ -042A21C54C003198FF222E1D1A33380337B202C6D6FF2C02019FFFC000002191FF318CFF1A223A31\ -019CFFC00000218DFF1C031A22C549000C02060300003C528601003C624600003C72918BFF9A1108\ -71C861D851E841F83112C1200DF00010000068100000581000007010000074100000781000007C10\ -0000801000001C4B0040803C004091FDFF12C1E061F7FFC961E941F9310971D9519011C01A662906\ -21F3FFC2D1101A22390231F2FF0C0F1A33590331EAFFF26C1AED045C2247B3028636002D0C016DFF\ -C0000021E5FF41EAFF2A611A4469040622000021E4FF1A222802F0D2C0D7BE01DD0E31E0FF4D0D1A\ -3328033D0101E2FFC00000561209D03D2010212001DFFFC000004D0D2D0C3D01015DFFC0000041D5\ -FFDAFF1A444804D0648041D2FF1A4462640061D1FF106680622600673F1331D0FF10338028030C43\ -853A002642164613000041CAFF222C1A1A444804202FC047328006F6FF222C1A273F3861C2FF222C\ -1A1A6668066732B921BDFF3D0C1022800148FFC0000021BAFF1C031A2201BFFFC000000C02460300\ -5C3206020000005C424600005C5291B7FF9A110871C861D851E841F83112C1200DF0B0100000C010\ -0000D010000012C1E091FEFFC961D951E9410971F931CD039011C0ED02DD0431A1FF9C1422A06247\ -B302062D0021F4FF1A22490286010021F1FF1A223902219CFF2AF12D0F011FFFC00000461C0022D1\ -10011CFFC0000021E9FFFD0C1A222802C7B20621E6FF1A22F8022D0E3D014D0F0195FFC000008C52\ -22A063C6180000218BFF3D01102280F04F200111FFC00000AC7D22D1103D014D0F010DFFC0000021\ -D6FF32D110102280010EFFC0000021D3FF1C031A220185FFC00000FAEEF0CCC056ACF821CDFF317A\ -FF1A223A310105FFC0000021C9FF1C031A22017CFFC000002D0C91C8FF9A110871C861D851E841F8\ -3112C1200DF0000200600000001040020060FFFFFF0012C1E00C02290131FAFF21FAFF026107C961\ -C02000226300C02000C80320CC10564CFF21F5FFC02000380221F4FF20231029010C432D010163FF\ -C0000008712D0CC86112C1200DF00080FE3F8449004012C1D0C9A109B17CFC22C1110C13C51C0026\ -1202463000220111C24110B68202462B0031F5FF3022A02802A002002D011C03851A0066820A2801\ -32210105A6FF0607003C12C60500000010212032A01085180066A20F2221003811482105B3FF2241\ -10861A004C1206FDFF2D011C03C5160066B20E280138114821583185CFFF06F7FF005C1286F5FF00\ -10212032A01085140066A20D2221003811482105E1FF06EFFF0022A06146EDFF45F0FFC6EBFF0000\ -01D2FFC0000006E9FF000C022241100C1322C110C50F00220111060600000022C1100C13C50E0022\ -011132C2FA303074B6230206C8FF08B1C8A112C1300DF0000000000010404F484149007519031027\ -000000110040A8100040BC0F0040583F0040CC2E00401CE20040D83900408000004021F4FF12C1E0\ -C961C80221F2FF097129010C02D951C91101F4FFC0000001F3FFC00000AC2C22A3E801F2FFC00000\ -21EAFFC031412A233D0C01EFFFC000003D0222A00001EDFFC00000C1E4FF2D0C01E8FFC000002D01\ -32A004450400C5E7FFDD022D0C01E3FFC00000666D1F4B2131DCFF4600004B22C0200048023794F5\ -31D9FFC0200039023DF08601000001DCFFC000000871C861D85112C1200DF000000012C1F0026103\ -01EAFEC00000083112C1100DF000643B004012C1D0E98109B1C9A1D991F97129013911E2A0C001FA\ -FFC00000CD02E792F40C0DE2A0C0F2A0DB860D00000001F4FFC00000204220E71240F7921C226102\ -01EFFFC0000052A0DC482157120952A0DD571205460500004D0C3801DA234242001BDD3811379DC5\ -C6000000000C0DC2A0C001E3FFC00000C792F608B12D0DC8A1D891E881F87112C1300DF00000", "\ -entry": 1074792180, "num_params": 1, "params_start": 1074790400, "data": "FE0510\ -401A0610403B0610405A0610407A061040820610408C0610408C061040", "data_start": 10736\ -43520} -""" - -if __name__ == '__main__': - try: - main() - except FatalError as e: - print '\nA fatal error occurred: %s' % e - sys.exit(2) diff --git a/tools/nodemcu-partition.py b/tools/nodemcu-partition.py new file mode 100755 index 0000000000..1c9ab46118 --- /dev/null +++ b/tools/nodemcu-partition.py @@ -0,0 +1,286 @@ +#!/usr/bin/env python +# +# ESP8266 LFS Loader Utility +# +# Copyright (C) 2019 Terry Ellison, NodeMCU Firmware Community Project. drawing +# heavily from and including content from esptool.py with full acknowledgement +# under GPL 2.0, with said content: Copyright (C) 2014-2016 Fredrik Ahlberg, Angus +# Gratton, Espressif Systems (Shanghai) PTE LTD, other contributors as noted. +# https://github.com/espressif/esptool +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation; either version 2 of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, write to the Free Software Foundation, Inc., 51 Franklin +# Street, Fifth Floor, Boston, MA 02110-1301 USA. + +import os +import sys +sys.path.append(os.path.realpath(os.path.dirname(__file__) + '/toolchains/')) +import esptool + +import io +import tempfile +import shutil + +from pprint import pprint + +import argparse +import gzip +import copy +import inspect +import struct +import string + +__version__ = '1.0' +__program__ = 'nodemcu-partition.py' +ROM0_Seg = 0x010000 +FLASH_PAGESIZE = 0x001000 +FLASH_BASE_ADDR = 0x40200000 +PARTITION_TYPES = { + 4: 'RF_CAL', + 5: 'PHY_DATA', + 6: 'SYSTEM_PARAMETER', + 101: 'EAGLEROM', + 102: 'IROM0TEXT', + 103: 'LFS0', + 104: 'LFS1', + 105: 'TLSCERT', + 106: 'SPIFFS0', + 107: 'SPIFFS1'} + +MAX_PT_SIZE = 20*3 +FLASH_SIG = 0xfafaa150 +FLASH_SIG_MASK = 0xfffffff0 +FLASH_SIG_ABSOLUTE = 0x00000001 +WORDSIZE = 4 +WORDBITS = 32 + +PACK_INT = struct.Struct(">= 1 + + return ''.join([PACK_INT.pack(i) for i in image]) + +def main(): + + def arg_auto_int(x): + ux = x.upper() + if "MB" in ux: + return int(ux[:ux.index("MB")]) * 1024 * 1024 + elif "KB" in ux: + return int(ux[:ux.index("KB")]) * 1024 + else: + return int(ux, 0) + + print('%s V%s' %(__program__, __version__)) + + # ---------- process the arguments ---------- # + + a = argparse.ArgumentParser( + description='%s V%s - ESP8266 NodeMCU Loader Utility' % + (__program__, __version__), + prog='esplfs') + a.add_argument('--port', '-p', help='Serial port device') + a.add_argument('--baud', '-b', type=arg_auto_int, + help='Serial port baud rate used when flashing/reading') + a.add_argument('--lfs-addr', '-la', dest="la", type=arg_auto_int, + help='(Overwrite) start address of LFS partition') + a.add_argument('--lfs-size', '-ls', dest="ls", type=arg_auto_int, + help='(Overwrite) length of LFS partition') + a.add_argument('--lfs-file', '-lf', dest="lf", help='LFS image file') + a.add_argument('--spiffs-addr', '-sa', dest="sa", type=arg_auto_int, + help='(Overwrite) start address of SPIFFS partition') + a.add_argument('--spiffs-size', '-ss', dest="ss", type=arg_auto_int, + help='(Overwrite) length of SPIFFS partition') + a.add_argument('--spiffs-file', '-sf', dest="sf", help='SPIFFS image file') + + arg = a.parse_args() + + if arg.lf is not None: + if not os.path.exists(arg.lf): + raise FatalError("LFS image %s does not exist" % arg.lf) + + if arg.sf is not None: + if not os.path.exists(arg.sf): + raise FatalError("SPIFFS image %s does not exist" % arg.sf) + + base = [] if arg.port is None else ['--port',arg.port] + if arg.baud is not None: base.extend(['--baud',arg.baud]) + + # ---------- Use esptool to read the PT ---------- # + + tmpdir = tempfile.mkdtemp() + pt_file = tmpdir + '/pt.dmp' + espargs = base+['--after', 'no_reset', 'read_flash', '--no-progress', + str(ROM0_Seg), str(FLASH_PAGESIZE), pt_file] + esptool.main(espargs) + + with open(pt_file,"rb") as f: + data = f.read() + + pt, pt_map, n = load_PT(data, arg) + n = n+1 + + odata = ''.join([PACK_INT.pack(pt[i]) for i in range(0,3*n)]) + \ + "\xFF" * len(data[3*4*n:]) + + # ---------- If the PT has changed then use esptool to rewrite it ---------- # + + if odata != data: + print("PT updated") + pt_file = tmpdir + '/opt.dmp' + with open(pt_file,"wb") as f: + f.write(odata) + espargs = base+['--after', 'no_reset', 'write_flash', '--no-progress', + str(ROM0_Seg), pt_file] + esptool.main(espargs) + + if arg.lf is not None: + i = pt_map['LFS0'] + la,ls = pt[i+1], pt[i+2] + + # ---------- Read and relocate the LFS image ---------- # + + with gzip.open(arg.lf) as f: + lfs = f.read() + lfs = relocate_lfs(lfs, la, ls) + + # ---------- Write to a temp file and use esptool to write it to flash ---------- # + + img_file = tmpdir + '/lfs.img' + espargs = base + ['write_flash', str(la), img_file] + with open(img_file,"wb") as f: + f.write(lfs) + esptool.main(espargs) + + if arg.sf is not None: + sa = pt[pt_map['SPIFFS0']+1] + + # ---------- Write to a temp file and use esptool to write it to flash ---------- # + + spiffs_file = arg.sf + espargs = base + ['', str(sa), spiffs_file] + esptool.main(espargs) + + # ---------- Clean up temp directory ---------- # + + espargs = base + ['--after', 'hard_reset', 'flash_id'] + esptool.main(espargs) + + shutil.rmtree(tmpdir) + +def _main(): + main() + +if __name__ == '__main__': + _main() From 528973548c0d442945e787f4a92d10863b69c998 Mon Sep 17 00:00:00 2001 From: Terry Ellison Date: Fri, 5 Apr 2019 18:18:00 +0100 Subject: [PATCH 05/74] fix EM:0 error, and other memory leaks, plus minor typos in doc --- app/modules/crypto.c | 126 +++++++++++++++++------------------------ docs/modules/crypto.md | 8 +-- 2 files changed, 55 insertions(+), 79 deletions(-) diff --git a/app/modules/crypto.c b/app/modules/crypto.c index da4b4cdc46..4ecc8e8dce 100644 --- a/app/modules/crypto.c +++ b/app/modules/crypto.c @@ -75,22 +75,21 @@ static const char* bytes64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwx */ static int crypto_base64_encode( lua_State* L ) { - int len; + int len, i; const char* msg = luaL_checklstring(L, 1, &len); - int blen = (len + 2) / 3 * 4; - char* out = (char*)c_malloc(blen); - int j = 0, i; + luaL_Buffer out; + + luaL_buffinit(L, &out); for (i = 0; i < len; i += 3) { int a = msg[i]; int b = (i + 1 < len) ? msg[i + 1] : 0; int c = (i + 2 < len) ? msg[i + 2] : 0; - out[j++] = bytes64[a >> 2]; - out[j++] = bytes64[((a & 3) << 4) | (b >> 4)]; - out[j++] = (i + 1 < len) ? bytes64[((b & 15) << 2) | (c >> 6)] : 61; - out[j++] = (i + 2 < len) ? bytes64[(c & 63)] : 61; + luaL_addchar(&out, bytes64[a >> 2]); + luaL_addchar(&out, bytes64[((a & 3) << 4) | (b >> 4)]); + luaL_addchar(&out, (i + 1 < len) ? bytes64[((b & 15) << 2) | (c >> 6)] : 61); + luaL_addchar(&out, (i + 2 < len) ? bytes64[(c & 63)] : 61); } - lua_pushlstring(L, out, j); - c_free(out); + luaL_pushresult(&out); return 1; } @@ -101,16 +100,16 @@ static int crypto_base64_encode( lua_State* L ) */ static int crypto_hex_encode( lua_State* L) { - int len; + int len, i; const char* msg = luaL_checklstring(L, 1, &len); - char* out = (char*)c_malloc(len * 2); - int i, j = 0; + luaL_Buffer out; + + luaL_buffinit(L, &out); for (i = 0; i < len; i++) { - out[j++] = crypto_hexbytes[msg[i] >> 4]; - out[j++] = crypto_hexbytes[msg[i] & 0xf]; + luaL_addchar(&out, crypto_hexbytes[msg[i] >> 4]); + luaL_addchar(&out, crypto_hexbytes[msg[i] & 0xf]); } - lua_pushlstring(L, out, len*2); - c_free(out); + luaL_pushresult(&out); return 1; } #endif @@ -121,22 +120,20 @@ static int crypto_hex_encode( lua_State* L) */ static int crypto_mask( lua_State* L ) { - int len, mask_len; + int len, mask_len, i; const char* msg = luaL_checklstring(L, 1, &len); const char* mask = luaL_checklstring(L, 2, &mask_len); + luaL_Buffer b; if(mask_len <= 0) return luaL_error(L, "invalid argument: mask"); - int i; - char* copy = (char*)c_malloc(len); - + luaL_buffinit(L, &b); for (i = 0; i < len; i++) { - copy[i] = msg[i] ^ mask[i % mask_len]; + luaL_addchar(&b, msg[i] ^ mask[i % mask_len]); } - lua_pushlstring(L, copy, len); - c_free(copy); + luaL_pushresult(&b); return 1; } @@ -175,30 +172,36 @@ static int crypto_lhash (lua_State *L) static int crypto_new_hash_hmac (lua_State *L, int what) { + /* get pointer to relevant hash_mechs table entry in app/crypto/digest.c */ const digest_mech_info_t *mi = crypto_digest_mech (luaL_checkstring (L, 1)); if (!mi) return bad_mech (L); - size_t len = 0; - const char *key = 0; - uint8_t *k_opad = 0; + size_t len = 0, k_opad_len = 0, udlen; + const char *key = NULL; + uint8_t *k_opad = NULL; + if (what == WANT_HMAC) { key = luaL_checklstring (L, 2, &len); - k_opad = luaM_malloc (L, mi->block_size); + k_opad_len = mi->block_size; } - void *ctx = luaM_malloc (L, mi->ctx_size); + // create a userdatum with specific metatable. This comprises the ud header, + // the encrypto context block, and an optional HMAC block + udlen = sizeof(digest_user_datum_t) + mi->ctx_size + k_opad_len; + digest_user_datum_t *dudat = (digest_user_datum_t *)lua_newuserdata(L, udlen); + void *ctx = (char *)(dudat + 1); mi->create (ctx); - - if (what == WANT_HMAC) - crypto_hmac_begin (ctx, mi, key, len, k_opad); - - // create a userdataum with specific metatable - digest_user_datum_t *dudat = (digest_user_datum_t *)lua_newuserdata(L, sizeof(digest_user_datum_t)); + luaL_getmetatable(L, "crypto.hash"); lua_setmetatable(L, -2); + if (what == WANT_HMAC) { + k_opad = (char *)ctx + mi->ctx_size; + crypto_hmac_begin (ctx, mi, key, len, k_opad); + } + // Set pointers to the mechanics and CTX dudat->mech_info = mi; dudat->ctx = ctx; @@ -262,23 +265,6 @@ static int crypto_hash_finalize (lua_State *L) return 1; } -/* Frees memory for the user datum and CTX hash state */ -static int crypto_hash_gcdelete (lua_State *L) -{ - NODE_DBG("enter crypto_hash_delete.\n"); - digest_user_datum_t *dudat; - - dudat = (digest_user_datum_t *)luaL_checkudata(L, 1, "crypto.hash"); - - // luaM_free() uses type info to obtain original size, so have to delve - // one level deeper and explicitly pass the size due to void* - luaM_realloc_ (L, dudat->ctx, dudat->mech_info->ctx_size, 0); - luaM_free (L, dudat->k_opad); - - return 0; -} - - static sint32_t vfs_read_wrap (int fd, void *ptr, size_t len) { return vfs_read (fd, ptr, len); @@ -356,40 +342,31 @@ static const crypto_mech_t *get_mech (lua_State *L, int idx) static int crypto_encdec (lua_State *L, bool enc) { const crypto_mech_t *mech = get_mech (L, 1); - size_t klen; + size_t klen, dlen, ivlen, bs = mech->block_size; + const char *key = luaL_checklstring (L, 2, &klen); - size_t dlen; const char *data = luaL_checklstring (L, 3, &dlen); - - size_t ivlen; const char *iv = luaL_optlstring (L, 4, "", &ivlen); - size_t bs = mech->block_size; size_t outlen = ((dlen + bs -1) / bs) * bs; - char *buf = (char *)os_zalloc (outlen); - if (!buf) - return luaL_error (L, "crypto init failed"); - crypto_op_t op = - { + char *buf = luaM_newvector(L, outlen, char); + + crypto_op_t op = { key, klen, iv, ivlen, data, dlen, buf, outlen, enc ? OP_ENCRYPT : OP_DECRYPT }; - if (!mech->run (&op)) - { - os_free (buf); - return luaL_error (L, "crypto op failed"); - } - else - { - lua_pushlstring (L, buf, outlen); - // note: if lua_pushlstring runs out of memory, we leak buf :( - os_free (buf); - return 1; - } + + int status = mech->run (&op); + + lua_pushlstring (L, buf, outlen); /* discarded on error but what the hell */ + luaM_freearray(L, buf, outlen, char); + + return status ? 1 : luaL_error (L, "crypto op failed"); + } static int lcrypto_encrypt (lua_State *L) @@ -406,7 +383,6 @@ static int lcrypto_decrypt (lua_State *L) static const LUA_REG_TYPE crypto_hash_map[] = { { LSTRKEY( "update" ), LFUNCVAL( crypto_hash_update ) }, { LSTRKEY( "finalize" ), LFUNCVAL( crypto_hash_finalize ) }, - { LSTRKEY( "__gc" ), LFUNCVAL( crypto_hash_gcdelete ) }, { LSTRKEY( "__index" ), LROVAL( crypto_hash_map ) }, { LNILKEY, LNILVAL } }; diff --git a/docs/modules/crypto.md b/docs/modules/crypto.md index 43a58bd1bd..97f9dec296 100644 --- a/docs/modules/crypto.md +++ b/docs/modules/crypto.md @@ -124,8 +124,8 @@ Userdata object with `update` and `finalize` functions available. #### Example ```lua hashobj = crypto.new_hash("SHA1") -hashobj:update("FirstString")) -hashobj:update("SecondString")) +hashobj:update("FirstString") +hashobj:update("SecondString") digest = hashobj:finalize() print(crypto.toHex(digest)) ``` @@ -167,8 +167,8 @@ Userdata object with `update` and `finalize` functions available. #### Example ```lua hmacobj = crypto.new_hmac("SHA1", "s3kr3t") -hmacobj:update("FirstString")) -hmacobj:update("SecondString")) +hmacobj:update("FirstString") +hmacobj:update("SecondString") digest = hmacobj:finalize() print(crypto.toHex(digest)) ``` From fc94439b74ee82888594ccb31bf4afcd1d04a879 Mon Sep 17 00:00:00 2001 From: Terry Ellison Date: Mon, 8 Apr 2019 13:57:46 +0100 Subject: [PATCH 06/74] crypto.c: Clarify comments on use of userdata for header + context + key opad blocks --- app/modules/crypto.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/app/modules/crypto.c b/app/modules/crypto.c index 4ecc8e8dce..81fcd28fb3 100644 --- a/app/modules/crypto.c +++ b/app/modules/crypto.c @@ -172,7 +172,8 @@ static int crypto_lhash (lua_State *L) static int crypto_new_hash_hmac (lua_State *L, int what) { - /* get pointer to relevant hash_mechs table entry in app/crypto/digest.c */ + // get pointer to relevant hash_mechs table entry in app/crypto/digest.c. Note that + // the size of the table needed is dependent on the the digest type const digest_mech_info_t *mi = crypto_digest_mech (luaL_checkstring (L, 1)); if (!mi) return bad_mech (L); @@ -182,22 +183,24 @@ static int crypto_new_hash_hmac (lua_State *L, int what) uint8_t *k_opad = NULL; if (what == WANT_HMAC) - { + { // The key and k_opad are only used for HMAC; these default to NULLs for HASH key = luaL_checklstring (L, 2, &len); k_opad_len = mi->block_size; } // create a userdatum with specific metatable. This comprises the ud header, - // the encrypto context block, and an optional HMAC block + // the encrypto context block, and an optional HMAC block as a single allocation + // unit udlen = sizeof(digest_user_datum_t) + mi->ctx_size + k_opad_len; digest_user_datum_t *dudat = (digest_user_datum_t *)lua_newuserdata(L, udlen); - void *ctx = (char *)(dudat + 1); - mi->create (ctx); - - luaL_getmetatable(L, "crypto.hash"); + luaL_getmetatable(L, "crypto.hash"); // and set its metatable to the crypto.hash table lua_setmetatable(L, -2); + void *ctx = dudat + 1; // The context block immediately follows the digest_user_datum + mi->create (ctx); + if (what == WANT_HMAC) { + // The k_opad block immediately follows the context block k_opad = (char *)ctx + mi->ctx_size; crypto_hmac_begin (ctx, mi, key, len, k_opad); } From 9842a8ef830d52854b514170ef3169b4883f4bd4 Mon Sep 17 00:00:00 2001 From: Gregor Hartmann Date: Tue, 9 Apr 2019 15:37:47 +0200 Subject: [PATCH 07/74] Add building luac.cross to travis ci builds (#2682) Add building luac.cross to travis ci builds --- .travis.yml | 36 +++++++++++++++++++---------- tools/travis/ci-build-linux.sh | 23 ++++++++++++++++++ tools/travis/ci-build-windows-ms.sh | 11 +++++++++ tools/{ => travis}/pr-build.sh | 4 ---- 4 files changed, 58 insertions(+), 16 deletions(-) create mode 100644 tools/travis/ci-build-linux.sh create mode 100644 tools/travis/ci-build-windows-ms.sh rename tools/{ => travis}/pr-build.sh (90%) diff --git a/.travis.yml b/.travis.yml index 6e69a80c30..6a808926c0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,20 @@ +#os: +# - windows +# - linux + language: cpp + +matrix: + include: + - os: linux + env: + - OS="$TRAVIS_OS_NAME" + - LUACC=./luac.cross + - os: windows + env: + - MSBUILD_PATH="c:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin" + - OS="$TRAVIS_OS_NAME" + - LUACC=msvc/luac-cross/x64/Debug/luac.cross.exe addons: apt: packages: @@ -8,16 +24,12 @@ cache: - directories: - cache script: -- export BUILD_DATE=$(date +%Y%m%d) -- make EXTRA_CCFLAGS="-DBUILD_DATE='\"'$BUILD_DATE'\"'" all -- cd bin/ -- file_name_float="nodemcu_float_${TRAVIS_TAG}.bin" -- srec_cat -output ${file_name_float} -binary 0x00000.bin -binary -fill 0xff 0x00000 0x10000 0x10000.bin -binary -offset 0x10000 -- cd ../ -- make clean -- make EXTRA_CCFLAGS="-DLUA_NUMBER_INTEGRAL -DBUILD_DATE='\"'$BUILD_DATE'\"'" -- cd bin/ -- file_name_integer="nodemcu_integer_${TRAVIS_TAG}.bin" -- srec_cat -output ${file_name_integer} -binary 0x00000.bin -binary -fill 0xff 0x00000 0x10000 0x10000.bin -binary -offset 0x10000 +- echo OS is $OS $TRAVIS_OS_NAME # http://docs.travis-ci.com/user/environment-variables/#Convenience-Variables -- if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then bash "$TRAVIS_BUILD_DIR"/tools/pr-build.sh; fi +- if [ "$OS" = "linux" ]; then bash "$TRAVIS_BUILD_DIR"/tools/travis/ci-build-linux.sh; fi +- if [ "$OS" = "windows" ]; then bash "$TRAVIS_BUILD_DIR"/tools/travis/ci-build-windows-ms.sh; fi +- if [ "$OS" = "linux" -a "$TRAVIS_PULL_REQUEST" != "false" ]; then bash "$TRAVIS_BUILD_DIR"/tools/travis/pr-build.sh; fi +- cd "$TRAVIS_BUILD_DIR" +- LUA_FILES=`find lua_modules lua_examples -iname "*.lua"` +- echo checking $LUA_FILES +- $LUACC -p $LUA_FILES diff --git a/tools/travis/ci-build-linux.sh b/tools/travis/ci-build-linux.sh new file mode 100644 index 0000000000..cb728eed62 --- /dev/null +++ b/tools/travis/ci-build-linux.sh @@ -0,0 +1,23 @@ +#!/bin/sh + +set -e + +echo "Running ci build for linux" +( + cd "$TRAVIS_BUILD_DIR" || exit + export BUILD_DATE=$(date +%Y%m%d) + + # build integer firmware + make EXTRA_CCFLAGS="-DLUA_NUMBER_INTEGRAL -DBUILD_DATE='\"'$BUILD_DATE'\"'" + cd bin/ || exit + file_name_integer="nodemcu_integer_${TRAVIS_TAG}.bin" + srec_cat -output ${file_name_integer} -binary 0x00000.bin -binary -fill 0xff 0x00000 0x10000 0x10000.bin -binary -offset 0x10000 + cd ../ || exit + + # build float firmware + make clean + make EXTRA_CCFLAGS="-DBUILD_DATE='\"'$BUILD_DATE'\"'" all + cd bin/ || exit + file_name_float="nodemcu_float_${TRAVIS_TAG}.bin" + srec_cat -output ${file_name_float} -binary 0x00000.bin -binary -fill 0xff 0x00000 0x10000 0x10000.bin -binary -offset 0x10000 +) diff --git a/tools/travis/ci-build-windows-ms.sh b/tools/travis/ci-build-windows-ms.sh new file mode 100644 index 0000000000..904107abd0 --- /dev/null +++ b/tools/travis/ci-build-windows-ms.sh @@ -0,0 +1,11 @@ +#!/bin/sh + +set -e + +echo "Running ci build for windows msbuild (supports only hosttools)" +( + cd "$TRAVIS_BUILD_DIR"/msvc || exit + export PATH=$MSBUILD_PATH:$PATH + msbuild.exe hosttools.sln +) + diff --git a/tools/pr-build.sh b/tools/travis/pr-build.sh similarity index 90% rename from tools/pr-build.sh rename to tools/travis/pr-build.sh index 0670c74181..f7866f71ed 100644 --- a/tools/pr-build.sh +++ b/tools/travis/pr-build.sh @@ -29,8 +29,4 @@ cd "$TRAVIS_BUILD_DIR"/ld || exit cd "$TRAVIS_BUILD_DIR" || exit make clean make - -LUA_FILES=`find lua_modules lua_examples -iname "*.lua"` -echo checking $LUA_FILES -./luac.cross -p $LUA_FILES ) From 5a6992c26a45a730edb2fff828e1edba16ef858d Mon Sep 17 00:00:00 2001 From: ziggurat29 <30310677+ziggurat29@users.noreply.github.com> Date: Tue, 9 Apr 2019 08:38:49 -0500 Subject: [PATCH 08/74] added spiffsimg host tools project to msvc build configuration. (#2686) --- app/spiffs/spiffs_nucleus.h | 12 + msvc/hosttools.sln | 10 + msvc/spiffsimg/getopt.h | 651 +++++++++++++++ msvc/spiffsimg/spiffsimg.vcxproj | 207 +++++ msvc/spiffsimg/spiffsimg.vcxproj.filters | 81 ++ tools/spiffsimg/main.c | 957 ++++++++++++----------- tools/spiffsimg/spiffs_typedefs.h | 2 +- 7 files changed, 1463 insertions(+), 457 deletions(-) create mode 100644 msvc/spiffsimg/getopt.h create mode 100644 msvc/spiffsimg/spiffsimg.vcxproj create mode 100644 msvc/spiffsimg/spiffsimg.vcxproj.filters diff --git a/app/spiffs/spiffs_nucleus.h b/app/spiffs/spiffs_nucleus.h index 2b03b8c991..c4a0729bc5 100644 --- a/app/spiffs/spiffs_nucleus.h +++ b/app/spiffs/spiffs_nucleus.h @@ -476,6 +476,9 @@ typedef struct { // object structs +#ifdef _MSC_VER +#pragma pack ( push, 1 ) +#endif // page header, part of each page except object lookup pages // NB: this is always aligned when the data page is an object index, @@ -492,8 +495,13 @@ typedef struct SPIFFS_PACKED { // object index header page header typedef struct SPIFFS_PACKED #if SPIFFS_ALIGNED_OBJECT_INDEX_TABLES +#ifdef _MSC_VER +//Note: the following needs to track the sizeof(spiffs_page_ix), which is defined in spiffs_config.h + __declspec( align( 2 ) ) +#else __attribute(( aligned(sizeof(spiffs_page_ix)) )) #endif +#endif { // common page header spiffs_page_header p_hdr; @@ -517,6 +525,10 @@ typedef struct SPIFFS_PACKED { u8_t _align[4 - ((sizeof(spiffs_page_header)&3)==0 ? 4 : (sizeof(spiffs_page_header)&3))]; } spiffs_page_object_ix; +#ifdef _MSC_VER +#pragma pack ( pop ) +#endif + // callback func for object lookup visitor typedef s32_t (*spiffs_visitor_f)(spiffs *fs, spiffs_obj_id id, spiffs_block_ix bix, int ix_entry, const void *user_const_p, void *user_var_p); diff --git a/msvc/hosttools.sln b/msvc/hosttools.sln index 30f55e26d4..75514eea14 100644 --- a/msvc/hosttools.sln +++ b/msvc/hosttools.sln @@ -5,6 +5,8 @@ VisualStudioVersion = 15.0.28307.168 MinimumVisualStudioVersion = 10.0.40219.1 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "luac-cross", "luac-cross\luac-cross.vcxproj", "{78A3411A-A18F-41A4-B4A7-D76B273F0E44}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "spiffsimg", "spiffsimg\spiffsimg.vcxproj", "{2DD84C09-254C-4884-A863-456EA1E32DCE}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x64 = Debug|x64 @@ -21,6 +23,14 @@ Global {78A3411A-A18F-41A4-B4A7-D76B273F0E44}.Release|x64.Build.0 = Release|x64 {78A3411A-A18F-41A4-B4A7-D76B273F0E44}.Release|x86.ActiveCfg = Release|Win32 {78A3411A-A18F-41A4-B4A7-D76B273F0E44}.Release|x86.Build.0 = Release|Win32 + {2DD84C09-254C-4884-A863-456EA1E32DCE}.Debug|x64.ActiveCfg = Debug|x64 + {2DD84C09-254C-4884-A863-456EA1E32DCE}.Debug|x64.Build.0 = Debug|x64 + {2DD84C09-254C-4884-A863-456EA1E32DCE}.Debug|x86.ActiveCfg = Debug|Win32 + {2DD84C09-254C-4884-A863-456EA1E32DCE}.Debug|x86.Build.0 = Debug|Win32 + {2DD84C09-254C-4884-A863-456EA1E32DCE}.Release|x64.ActiveCfg = Release|x64 + {2DD84C09-254C-4884-A863-456EA1E32DCE}.Release|x64.Build.0 = Release|x64 + {2DD84C09-254C-4884-A863-456EA1E32DCE}.Release|x86.ActiveCfg = Release|Win32 + {2DD84C09-254C-4884-A863-456EA1E32DCE}.Release|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/msvc/spiffsimg/getopt.h b/msvc/spiffsimg/getopt.h new file mode 100644 index 0000000000..520cc6a1f1 --- /dev/null +++ b/msvc/spiffsimg/getopt.h @@ -0,0 +1,651 @@ +#ifndef __GETOPT_H__ +/** + * DISCLAIMER + * This file is part of the mingw-w64 runtime package. + * + * The mingw-w64 runtime package and its code is distributed in the hope that it + * will be useful but WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESSED OR + * IMPLIED ARE HEREBY DISCLAIMED. This includes but is not limited to + * warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + */ + /* + * Copyright (c) 2002 Todd C. Miller + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Sponsored in part by the Defense Advanced Research Projects + * Agency (DARPA) and Air Force Research Laboratory, Air Force + * Materiel Command, USAF, under agreement number F39502-99-1-0512. + */ +/*- + * Copyright (c) 2000 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Dieter Baron and Thomas Klausner. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#define __GETOPT_H__ + +/* All the headers include this file. */ +#include +#include +#include +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define REPLACE_GETOPT /* use this getopt as the system getopt(3) */ + +#ifdef REPLACE_GETOPT +int opterr = 1; /* if error message should be printed */ +int optind = 1; /* index into parent argv vector */ +int optopt = '?'; /* character checked for validity */ +#undef optreset /* see getopt.h */ +#define optreset __mingw_optreset +int optreset; /* reset getopt */ +char *optarg; /* argument associated with option */ +#endif + +//extern int optind; /* index of first non-option in argv */ +//extern int optopt; /* single option character, as parsed */ +//extern int opterr; /* flag to enable built-in diagnostics... */ +// /* (user may set to zero, to suppress) */ +// +//extern char *optarg; /* pointer to argument of current option */ + +#define PRINT_ERROR ((opterr) && (*options != ':')) + +#define FLAG_PERMUTE 0x01 /* permute non-options to the end of argv */ +#define FLAG_ALLARGS 0x02 /* treat non-options as args to option "-1" */ +#define FLAG_LONGONLY 0x04 /* operate as getopt_long_only */ + +/* return values */ +#define BADCH (int)'?' +#define BADARG ((*options == ':') ? (int)':' : (int)'?') +#define INORDER (int)1 + +#ifndef __CYGWIN__ +#define __progname __argv[0] +#else +extern char __declspec(dllimport) *__progname; +#endif + +#ifdef __CYGWIN__ +static char EMSG[] = ""; +#else +#define EMSG "" +#endif + +static int getopt_internal(int, char * const *, const char *, + const struct option *, int *, int); +static int parse_long_options(char * const *, const char *, + const struct option *, int *, int); +static int gcd(int, int); +static void permute_args(int, int, int, char * const *); + +static char *place = EMSG; /* option letter processing */ + +/* XXX: set optreset to 1 rather than these two */ +static int nonopt_start = -1; /* first non option argument (for permute) */ +static int nonopt_end = -1; /* first option after non options (for permute) */ + +/* Error messages */ +static const char recargchar[] = "option requires an argument -- %c"; +static const char recargstring[] = "option requires an argument -- %s"; +static const char ambig[] = "ambiguous option -- %.*s"; +static const char noarg[] = "option doesn't take an argument -- %.*s"; +static const char illoptchar[] = "unknown option -- %c"; +static const char illoptstring[] = "unknown option -- %s"; + +static void +_vwarnx(const char *fmt,va_list ap) +{ + (void)fprintf(stderr,"%s: ",__progname); + if (fmt != NULL) + (void)vfprintf(stderr,fmt,ap); + (void)fprintf(stderr,"\n"); +} + +static void +warnx(const char *fmt,...) +{ + va_list ap; + va_start(ap,fmt); + _vwarnx(fmt,ap); + va_end(ap); +} + +/* + * Compute the greatest common divisor of a and b. + */ +static int +gcd(int a, int b) +{ + int c; + + c = a % b; + while (c != 0) { + a = b; + b = c; + c = a % b; + } + + return (b); +} + +/* + * Exchange the block from nonopt_start to nonopt_end with the block + * from nonopt_end to opt_end (keeping the same order of arguments + * in each block). + */ +static void +permute_args(int panonopt_start, int panonopt_end, int opt_end, + char * const *nargv) +{ + int cstart, cyclelen, i, j, ncycle, nnonopts, nopts, pos; + char *swap; + + /* + * compute lengths of blocks and number and size of cycles + */ + nnonopts = panonopt_end - panonopt_start; + nopts = opt_end - panonopt_end; + ncycle = gcd(nnonopts, nopts); + cyclelen = (opt_end - panonopt_start) / ncycle; + + for (i = 0; i < ncycle; i++) { + cstart = panonopt_end+i; + pos = cstart; + for (j = 0; j < cyclelen; j++) { + if (pos >= panonopt_end) + pos -= nnonopts; + else + pos += nopts; + swap = nargv[pos]; + /* LINTED const cast */ + ((char **) nargv)[pos] = nargv[cstart]; + /* LINTED const cast */ + ((char **)nargv)[cstart] = swap; + } + } +} + +#ifdef REPLACE_GETOPT +/* + * getopt -- + * Parse argc/argv argument vector. + * + * [eventually this will replace the BSD getopt] + */ +int +getopt(int nargc, char * const *nargv, const char *options) +{ + + /* + * We don't pass FLAG_PERMUTE to getopt_internal() since + * the BSD getopt(3) (unlike GNU) has never done this. + * + * Furthermore, since many privileged programs call getopt() + * before dropping privileges it makes sense to keep things + * as simple (and bug-free) as possible. + */ + return (getopt_internal(nargc, nargv, options, NULL, NULL, 0)); +} +#endif /* REPLACE_GETOPT */ + +//extern int getopt(int nargc, char * const *nargv, const char *options); + +#ifdef _BSD_SOURCE +/* + * BSD adds the non-standard `optreset' feature, for reinitialisation + * of `getopt' parsing. We support this feature, for applications which + * proclaim their BSD heritage, before including this header; however, + * to maintain portability, developers are advised to avoid it. + */ +# define optreset __mingw_optreset +extern int optreset; +#endif +#ifdef __cplusplus +} +#endif +/* + * POSIX requires the `getopt' API to be specified in `unistd.h'; + * thus, `unistd.h' includes this header. However, we do not want + * to expose the `getopt_long' or `getopt_long_only' APIs, when + * included in this manner. Thus, close the standard __GETOPT_H__ + * declarations block, and open an additional __GETOPT_LONG_H__ + * specific block, only when *not* __UNISTD_H_SOURCED__, in which + * to declare the extended API. + */ +#endif /* !defined(__GETOPT_H__) */ + +#if !defined(__UNISTD_H_SOURCED__) && !defined(__GETOPT_LONG_H__) +#define __GETOPT_LONG_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +struct option /* specification for a long form option... */ +{ + const char *name; /* option name, without leading hyphens */ + int has_arg; /* does it take an argument? */ + int *flag; /* where to save its status, or NULL */ + int val; /* its associated status value */ +}; + +enum /* permitted values for its `has_arg' field... */ +{ + no_argument = 0, /* option never takes an argument */ + required_argument, /* option always requires an argument */ + optional_argument /* option may take an argument */ +}; + +/* + * parse_long_options -- + * Parse long options in argc/argv argument vector. + * Returns -1 if short_too is set and the option does not match long_options. + */ +static int +parse_long_options(char * const *nargv, const char *options, + const struct option *long_options, int *idx, int short_too) +{ + char *current_argv, *has_equal; + size_t current_argv_len; + int i, ambiguous, match; + +#define IDENTICAL_INTERPRETATION(_x, _y) \ + (long_options[(_x)].has_arg == long_options[(_y)].has_arg && \ + long_options[(_x)].flag == long_options[(_y)].flag && \ + long_options[(_x)].val == long_options[(_y)].val) + + current_argv = place; + match = -1; + ambiguous = 0; + + optind++; + + if ((has_equal = strchr(current_argv, '=')) != NULL) { + /* argument found (--option=arg) */ + current_argv_len = has_equal - current_argv; + has_equal++; + } else + current_argv_len = strlen(current_argv); + + for (i = 0; long_options[i].name; i++) { + /* find matching long option */ + if (strncmp(current_argv, long_options[i].name, + current_argv_len)) + continue; + + if (strlen(long_options[i].name) == current_argv_len) { + /* exact match */ + match = i; + ambiguous = 0; + break; + } + /* + * If this is a known short option, don't allow + * a partial match of a single character. + */ + if (short_too && current_argv_len == 1) + continue; + + if (match == -1) /* partial match */ + match = i; + else if (!IDENTICAL_INTERPRETATION(i, match)) + ambiguous = 1; + } + if (ambiguous) { + /* ambiguous abbreviation */ + if (PRINT_ERROR) + warnx(ambig, (int)current_argv_len, + current_argv); + optopt = 0; + return (BADCH); + } + if (match != -1) { /* option found */ + if (long_options[match].has_arg == no_argument + && has_equal) { + if (PRINT_ERROR) + warnx(noarg, (int)current_argv_len, + current_argv); + /* + * XXX: GNU sets optopt to val regardless of flag + */ + if (long_options[match].flag == NULL) + optopt = long_options[match].val; + else + optopt = 0; + return (BADARG); + } + if (long_options[match].has_arg == required_argument || + long_options[match].has_arg == optional_argument) { + if (has_equal) + optarg = has_equal; + else if (long_options[match].has_arg == + required_argument) { + /* + * optional argument doesn't use next nargv + */ + optarg = nargv[optind++]; + } + } + if ((long_options[match].has_arg == required_argument) + && (optarg == NULL)) { + /* + * Missing argument; leading ':' indicates no error + * should be generated. + */ + if (PRINT_ERROR) + warnx(recargstring, + current_argv); + /* + * XXX: GNU sets optopt to val regardless of flag + */ + if (long_options[match].flag == NULL) + optopt = long_options[match].val; + else + optopt = 0; + --optind; + return (BADARG); + } + } else { /* unknown option */ + if (short_too) { + --optind; + return (-1); + } + if (PRINT_ERROR) + warnx(illoptstring, current_argv); + optopt = 0; + return (BADCH); + } + if (idx) + *idx = match; + if (long_options[match].flag) { + *long_options[match].flag = long_options[match].val; + return (0); + } else + return (long_options[match].val); +#undef IDENTICAL_INTERPRETATION +} + +/* + * getopt_internal -- + * Parse argc/argv argument vector. Called by user level routines. + */ +static int +getopt_internal(int nargc, char * const *nargv, const char *options, + const struct option *long_options, int *idx, int flags) +{ + char *oli; /* option letter list index */ + int optchar, short_too; + static int posixly_correct = -1; + + if (options == NULL) + return (-1); + + /* + * XXX Some GNU programs (like cvs) set optind to 0 instead of + * XXX using optreset. Work around this braindamage. + */ + if (optind == 0) + optind = optreset = 1; + + /* + * Disable GNU extensions if POSIXLY_CORRECT is set or options + * string begins with a '+'. + * + * CV, 2009-12-14: Check POSIXLY_CORRECT anew if optind == 0 or + * optreset != 0 for GNU compatibility. + */ + if (posixly_correct == -1 || optreset != 0) + posixly_correct = (getenv("POSIXLY_CORRECT") != NULL); + if (*options == '-') + flags |= FLAG_ALLARGS; + else if (posixly_correct || *options == '+') + flags &= ~FLAG_PERMUTE; + if (*options == '+' || *options == '-') + options++; + + optarg = NULL; + if (optreset) + nonopt_start = nonopt_end = -1; +start: + if (optreset || !*place) { /* update scanning pointer */ + optreset = 0; + if (optind >= nargc) { /* end of argument vector */ + place = EMSG; + if (nonopt_end != -1) { + /* do permutation, if we have to */ + permute_args(nonopt_start, nonopt_end, + optind, nargv); + optind -= nonopt_end - nonopt_start; + } + else if (nonopt_start != -1) { + /* + * If we skipped non-options, set optind + * to the first of them. + */ + optind = nonopt_start; + } + nonopt_start = nonopt_end = -1; + return (-1); + } + if (*(place = nargv[optind]) != '-' || + (place[1] == '\0' && strchr(options, '-') == NULL)) { + place = EMSG; /* found non-option */ + if (flags & FLAG_ALLARGS) { + /* + * GNU extension: + * return non-option as argument to option 1 + */ + optarg = nargv[optind++]; + return (INORDER); + } + if (!(flags & FLAG_PERMUTE)) { + /* + * If no permutation wanted, stop parsing + * at first non-option. + */ + return (-1); + } + /* do permutation */ + if (nonopt_start == -1) + nonopt_start = optind; + else if (nonopt_end != -1) { + permute_args(nonopt_start, nonopt_end, + optind, nargv); + nonopt_start = optind - + (nonopt_end - nonopt_start); + nonopt_end = -1; + } + optind++; + /* process next argument */ + goto start; + } + if (nonopt_start != -1 && nonopt_end == -1) + nonopt_end = optind; + + /* + * If we have "-" do nothing, if "--" we are done. + */ + if (place[1] != '\0' && *++place == '-' && place[1] == '\0') { + optind++; + place = EMSG; + /* + * We found an option (--), so if we skipped + * non-options, we have to permute. + */ + if (nonopt_end != -1) { + permute_args(nonopt_start, nonopt_end, + optind, nargv); + optind -= nonopt_end - nonopt_start; + } + nonopt_start = nonopt_end = -1; + return (-1); + } + } + + /* + * Check long options if: + * 1) we were passed some + * 2) the arg is not just "-" + * 3) either the arg starts with -- we are getopt_long_only() + */ + if (long_options != NULL && place != nargv[optind] && + (*place == '-' || (flags & FLAG_LONGONLY))) { + short_too = 0; + if (*place == '-') + place++; /* --foo long option */ + else if (*place != ':' && strchr(options, *place) != NULL) + short_too = 1; /* could be short option too */ + + optchar = parse_long_options(nargv, options, long_options, + idx, short_too); + if (optchar != -1) { + place = EMSG; + return (optchar); + } + } + + if ((optchar = (int)*place++) == (int)':' || + (optchar == (int)'-' && *place != '\0') || + (oli = (char*)strchr(options, optchar)) == NULL) { + /* + * If the user specified "-" and '-' isn't listed in + * options, return -1 (non-option) as per POSIX. + * Otherwise, it is an unknown option character (or ':'). + */ + if (optchar == (int)'-' && *place == '\0') + return (-1); + if (!*place) + ++optind; + if (PRINT_ERROR) + warnx(illoptchar, optchar); + optopt = optchar; + return (BADCH); + } + if (long_options != NULL && optchar == 'W' && oli[1] == ';') { + /* -W long-option */ + if (*place) /* no space */ + /* NOTHING */; + else if (++optind >= nargc) { /* no arg */ + place = EMSG; + if (PRINT_ERROR) + warnx(recargchar, optchar); + optopt = optchar; + return (BADARG); + } else /* white space */ + place = nargv[optind]; + optchar = parse_long_options(nargv, options, long_options, + idx, 0); + place = EMSG; + return (optchar); + } + if (*++oli != ':') { /* doesn't take argument */ + if (!*place) + ++optind; + } else { /* takes (optional) argument */ + optarg = NULL; + if (*place) /* no white space */ + optarg = place; + else if (oli[1] != ':') { /* arg not optional */ + if (++optind >= nargc) { /* no arg */ + place = EMSG; + if (PRINT_ERROR) + warnx(recargchar, optchar); + optopt = optchar; + return (BADARG); + } else + optarg = nargv[optind]; + } + place = EMSG; + ++optind; + } + /* dump back option letter */ + return (optchar); +} + +/* + * getopt_long -- + * Parse argc/argv argument vector. + */ +int +getopt_long(int nargc, char * const *nargv, const char *options, + const struct option *long_options, int *idx) +{ + + return (getopt_internal(nargc, nargv, options, long_options, idx, + FLAG_PERMUTE)); +} + +/* + * getopt_long_only -- + * Parse argc/argv argument vector. + */ +int +getopt_long_only(int nargc, char * const *nargv, const char *options, + const struct option *long_options, int *idx) +{ + + return (getopt_internal(nargc, nargv, options, long_options, idx, + FLAG_PERMUTE|FLAG_LONGONLY)); +} + +//extern int getopt_long(int nargc, char * const *nargv, const char *options, +// const struct option *long_options, int *idx); +//extern int getopt_long_only(int nargc, char * const *nargv, const char *options, +// const struct option *long_options, int *idx); +/* + * Previous MinGW implementation had... + */ +#ifndef HAVE_DECL_GETOPT +/* + * ...for the long form API only; keep this for compatibility. + */ +# define HAVE_DECL_GETOPT 1 +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* !defined(__UNISTD_H_SOURCED__) && !defined(__GETOPT_LONG_H__) */ diff --git a/msvc/spiffsimg/spiffsimg.vcxproj b/msvc/spiffsimg/spiffsimg.vcxproj new file mode 100644 index 0000000000..3927d90036 --- /dev/null +++ b/msvc/spiffsimg/spiffsimg.vcxproj @@ -0,0 +1,207 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 15.0 + {2DD84C09-254C-4884-A863-456EA1E32DCE} + Win32Proj + spiffsimg + 7.0 + + + + Application + true + v141_xp + MultiByte + + + Application + false + v141_xp + true + MultiByte + + + Application + true + v141_xp + MultiByte + + + Application + false + v141_xp + true + MultiByte + + + + + + + + + + + + + + + + + + + + + true + $(ProjectDir)$(Platform)\$(Configuration)\ + $(ProjectDir)$(Platform)\$(Configuration)\ + + + true + $(ProjectDir)$(Platform)\$(Configuration)\ + $(ProjectDir)$(Platform)\$(Configuration)\ + + + false + $(ProjectDir)$(Platform)\$(Configuration)\ + $(ProjectDir)$(Platform)\$(Configuration)\ + + + false + $(ProjectDir)$(Platform)\$(Configuration)\ + $(ProjectDir)$(Platform)\$(Configuration)\ + + + + NotUsing + Level3 + Disabled + true + NODEMCU_SPIFFS_NO_INCLUDE;dbg_printf=printf;_CRT_SECURE_NO_WARNINGS;_CONSOLE;_DEBUG;WIN32;%(PreprocessorDefinitions) + true + pch.h + MultiThreadedDebug + $(ProjectDir)\..\..\app\include;$(ProjectDir)\..\..\app\spiffs;$(ProjectDir) + $(ProjectDir)\..\..\tools\spiffsimg\spiffs_typedefs.h;%(ForcedIncludeFiles) + + + Console + true + true + setargv.obj;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + + + + + NotUsing + Level3 + Disabled + true + NODEMCU_SPIFFS_NO_INCLUDE;dbg_printf=printf;_CRT_SECURE_NO_WARNINGS;_CONSOLE;_DEBUG;WIN32;%(PreprocessorDefinitions) + true + pch.h + MultiThreadedDebug + $(ProjectDir)\..\..\app\include;$(ProjectDir)\..\..\app\spiffs;$(ProjectDir) + $(ProjectDir)\..\..\tools\spiffsimg\spiffs_typedefs.h;%(ForcedIncludeFiles) + + + Console + true + true + setargv.obj;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + + + + + NotUsing + Level3 + MaxSpeed + true + true + true + NODEMCU_SPIFFS_NO_INCLUDE;dbg_printf=printf;_CRT_SECURE_NO_WARNINGS;_CONSOLE;NDEBUG;WIN32;%(PreprocessorDefinitions) + true + pch.h + MultiThreaded + $(ProjectDir)\..\..\app\include;$(ProjectDir)\..\..\app\spiffs;$(ProjectDir) + $(ProjectDir)\..\..\tools\spiffsimg\spiffs_typedefs.h;%(ForcedIncludeFiles) + + + Console + true + true + true + true + setargv.obj;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + + + + + NotUsing + Level3 + MaxSpeed + true + true + true + NODEMCU_SPIFFS_NO_INCLUDE;dbg_printf=printf;_CRT_SECURE_NO_WARNINGS;_CONSOLE;NDEBUG;WIN32;%(PreprocessorDefinitions) + true + pch.h + MultiThreaded + $(ProjectDir)\..\..\app\include;$(ProjectDir)\..\..\app\spiffs;$(ProjectDir) + $(ProjectDir)\..\..\tools\spiffsimg\spiffs_typedefs.h;%(ForcedIncludeFiles) + + + Console + true + true + true + true + setargv.obj;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + + + + + + + + + + 4996 + 4996 + 4996 + 4996 + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/msvc/spiffsimg/spiffsimg.vcxproj.filters b/msvc/spiffsimg/spiffsimg.vcxproj.filters new file mode 100644 index 0000000000..bbf3b230e6 --- /dev/null +++ b/msvc/spiffsimg/spiffsimg.vcxproj.filters @@ -0,0 +1,81 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + {cc72cbf7-30a4-4c62-9413-509516a67c12} + + + {2796bdda-1fd8-4088-8d4e-41fdd71d5170} + + + {ba2fdaa9-bc69-4fb5-b789-9d2b46d7fd31} + + + {d6547699-189a-45e8-82d8-4af0a0b4cfd7} + + + {131db3e8-d55b-4d0a-810b-ae33c5e41bb3} + + + {184f25b5-aca7-476f-981f-16d7a8294ca7} + + + + + tools\spiffsimg + + + app\spiffs + + + app\spiffs + + + app\spiffs + + + app\spiffs + + + app\spiffs + + + + + tools\spiffsimg + + + app\spiffs + + + app\spiffs + + + app\spiffs + + + app\spiffs + + + app\include + + + app\platform + + + Header Files + + + \ No newline at end of file diff --git a/tools/spiffsimg/main.c b/tools/spiffsimg/main.c index c6f6985f6a..d62234e2de 100644 --- a/tools/spiffsimg/main.c +++ b/tools/spiffsimg/main.c @@ -1,456 +1,501 @@ -/* - * Copyright 2015 Dius Computing Pty Ltd. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the - * distribution. - * - Neither the name of the copyright holders nor the names of - * its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - * - * @author Johny Mattsson - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "spiffs.h" -#define NO_CPU_ESP8266_INCLUDE -#include "../platform/cpu_esp8266.h" - -static spiffs fs; -static uint8_t *flash; - -static int retcode = 0; - -#define LOG_PAGE_SIZE 256 - -// If the caclulated size is this or less, then use smaller blocks -// (1 page) rather than the normal 2 pages. This gives a little bit -// more flexibility for the file system, at the expense of a bit of -// efficiency -#define SMALL_FILESYSTEM (128 * 1024) - -static int delete_on_die = 0; -static const char *delete_list[10]; -static int delete_list_index = 0; - -static u8_t spiffs_work_buf[LOG_PAGE_SIZE*2]; -static u8_t spiffs_fds[32*4]; - -static s32_t flash_read (u32_t addr, u32_t size, u8_t *dst) { - memcpy (dst, flash + addr, size); - return SPIFFS_OK; -} - -static s32_t flash_write (u32_t addr, u32_t size, u8_t *src) { - memcpy (flash + addr, src, size); - return SPIFFS_OK; -} - -static s32_t flash_erase (u32_t addr, u32_t size) { - memset (flash + addr, 0xff, size); - return SPIFFS_OK; -} - - -static void die (const char *what) -{ - if (errno == 0) { - fprintf(stderr, "%s: fatal error\n", what); - } else { - perror (what); - } - if (delete_on_die) { - const char **p = delete_list; - while (*p) { - unlink(*p); - p++; - } - } - exit (1); -} - - -static void list (void) -{ - spiffs_DIR dir; - if (!SPIFFS_opendir (&fs, "/", &dir)) - die ("spiffs_opendir"); - struct spiffs_dirent de; - while (SPIFFS_readdir (&dir, &de)) - { - static const char types[] = "?fdhs"; // file, dir, hardlink, softlink - char name[sizeof(de.name)+1] = { 0 }; - memcpy (name, de.name, sizeof(de.name)); - printf("%c %6u %s\n", types[de.type], de.size, name); - } - SPIFFS_closedir (&dir); -} - - -static void cat (char *fname) -{ - spiffs_file fh = SPIFFS_open (&fs, fname, SPIFFS_RDONLY, 0); - char buff[512]; - s32_t n; - while ((n = SPIFFS_read (&fs, fh, buff, sizeof (buff))) > 0) - write (STDOUT_FILENO, buff, n); - SPIFFS_close (&fs, fh); -} - - -static void import (char *src, char *dst) -{ - int fd = open (src, O_RDONLY); - if (fd < 0) - die (src); - - spiffs_file fh = SPIFFS_open (&fs, dst, SPIFFS_CREAT | SPIFFS_TRUNC | SPIFFS_WRONLY, 0); - if (fh < 0) - die ("spiffs_open"); - - char buff[16384]; - s32_t n; - while ((n = read (fd, buff, sizeof (buff))) > 0) - if (SPIFFS_write (&fs, fh, buff, n) < 0) - die ("spiffs_write"); - - if (SPIFFS_close (&fs, fh) < 0) - die("spiffs_close"); - close (fd); -} - - -static void export (char *src, char *dst) -{ - spiffs_file fh = SPIFFS_open (&fs, src, SPIFFS_RDONLY, 0); - if (fh < 0) - die ("spiffs_open"); - - int fd = open (dst, O_CREAT | O_TRUNC | O_WRONLY, 0664); - if (fd < 0) - die (dst); - - char buff[512]; - s32_t n; - while ((n = SPIFFS_read (&fs, fh, buff, sizeof (buff))) > 0) - if (write (fd, buff, n) < 0) - die ("write"); - - SPIFFS_close (&fs, fh); - close (fd); -} - - -char *trim (char *in) -{ - if (!in) - return ""; - - char *out = 0; - while (*in) - { - if (!out && !isspace (*in)) - out = in; - ++in; - } - if (!out) - return ""; - while (--in > out && isspace (*in)) - ; - in[1] = 0; - return out; -} - - -void syntax (void) -{ - fprintf (stderr, - "Syntax: spiffsimg -f [-d] [-o ] [-c size] [-S flashsize] [-U usedsize] [-l | -i | -r ]\n\n" - ); - exit (1); -} - -static size_t getsize(const char *s) -{ - char *end = 0; - size_t val = strtoul(s, &end, 0); - - if (end) { - int factor; - if (*end == 'k' || *end == 'K') { - factor = 1 << 10; - end++; - } else if (*end == 'm' || *end == 'M') { - factor = 1 << 20; - end++; - } else { - factor = 1; - } - // Capital B is bytes - if (*end == 'B') { - factor = factor << 3; - } - // we want bytes - val = (val * factor) / 8; - } - - return val; -} - -int main (int argc, char *argv[]) -{ - if (argc == 1) - syntax (); - - int opt; - const char *fname = 0; - bool create = false; - enum { CMD_NONE, CMD_LIST, CMD_INTERACTIVE, CMD_SCRIPT } command = CMD_NONE; - int sz = 0; - const char *script_name = 0; - const char *resolved = 0; - int flashsize = 0; - int used = 0; - while ((opt = getopt (argc, argv, "do:f:c:lir:S:U:")) != -1) - { - switch (opt) - { - case 'f': fname = optarg; break; - case 'o': resolved = optarg; break; - case 'c': create = true; sz = strtol(optarg, 0, 0); break; - case 'S': create = true; flashsize = getsize(optarg); break; - case 'U': create = true; used = strtol(optarg, 0, 0); break; - case 'd': delete_on_die = 1; break; - case 'l': command = CMD_LIST; break; - case 'i': command = CMD_INTERACTIVE; break; - case 'r': command = CMD_SCRIPT; script_name = optarg; break; - default: die ("unknown option"); - } - } - - if (!fname) { - die("Need a filename"); - } - - int fd; - - if (create) - { - if (!sz) { - if (!flashsize || !used) { - die("Missing flashSize or Used"); - } - sz = flashsize - used - SYS_PARAM_SEC_NUM * 4096; // This leaves space for the parameter area - if (sz < 0x4000) { - die("Not enough space"); - } - if (sz > SMALL_FILESYSTEM) { - used = (used + 0xffff) & ~0xffff; - } else { - used = (used + 0x1fff) & ~0x1fff; - } - sz = flashsize - used - SYS_PARAM_SEC_NUM * 4096; - } - sz &= ~(0x1fff); - - if (used == 0) { - if (strchr(fname, '%')) { - die("Unable to calculate where to put the flash image, and % present in filename"); - } - } - - char fnamebuff[1024]; - - sprintf(fnamebuff, fname, used); - - delete_list[delete_list_index++] = strdup(fnamebuff);; - fd = open (fnamebuff, (create ? (O_CREAT | O_TRUNC) : 0) | O_RDWR, 0664); - if (fd == -1) - die ("open"); - - if (resolved) { - delete_list[delete_list_index++] = resolved; - FILE *f = fopen(resolved, "w"); - fprintf(f, "0x%x", used); - fclose(f); - } - - if (lseek (fd, sz -1, SEEK_SET) == -1) - die ("lseek"); - if (write (fd, "", 1) != 1) - die ("write"); - } - else { - fd = open (fname, O_RDWR, 0664); - if (fd == -1) - die ("open"); - - if (!sz) - { - off_t offs = lseek (fd, 0, SEEK_END); - if (offs == -1) - die ("lseek"); - sz = offs; - } - } - - if (sz & (0x1000 -1)) - die ("file size not multiple of erase block size"); - - flash = mmap (0, sz, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); - if (!flash) - die ("mmap"); - - if (create) - memset (flash, 0xff, sz); - - spiffs_config cfg; - cfg.phys_size = sz; - cfg.phys_addr = 0; - cfg.phys_erase_block = 0x1000; - cfg.log_block_size = 0x1000 * (sz > SMALL_FILESYSTEM ? 2 : 1); - cfg.log_page_size = LOG_PAGE_SIZE; - cfg.hal_read_f = flash_read; - cfg.hal_write_f = flash_write; - cfg.hal_erase_f = flash_erase; - if (cfg.phys_size < 4 * cfg.log_block_size) { - die("disk not large enough for four blocks"); - } - - if (SPIFFS_mount (&fs, &cfg, - spiffs_work_buf, - spiffs_fds, - sizeof(spiffs_fds), - malloc(65536), 65536, 0) != 0) { - if (create) { - if (SPIFFS_format(&fs) != 0) { - die("spiffs_format"); - } - if (SPIFFS_mount (&fs, &cfg, - spiffs_work_buf, - spiffs_fds, - sizeof(spiffs_fds), - malloc(65536), 65536, 0) != 0) { - die ("spiffs_mount"); - } - if (command == CMD_INTERACTIVE) { - printf("Created filesystem -- size 0x%x, block_size=%d\n", cfg.phys_size, cfg.log_block_size); - } - } else { - die ("spiffs_mount"); - } - } - - if (command == CMD_NONE) - ; // maybe just wanted to create an empty image? - else if (command == CMD_LIST) - list (); - else - { - FILE *in = (command == CMD_INTERACTIVE) ? stdin : fopen (script_name, "r"); - if (!in) - die ("fopen"); - char buff[128] = { 0 }; - if (in == stdin) - printf("> "); - while (fgets (buff, sizeof (buff) -1, in)) - { - char *line = trim (buff); - if (!line[0] || line[0] == '#') - continue; - if (strcmp (line, "ls") == 0) - list (); - else if (strncmp (line, "import ", 7) == 0) - { - char *src = 0, *dst = 0; - if (sscanf (line +7, " %ms %ms", &src, &dst) != 2) - { - fprintf (stderr, "SYNTAX ERROR: %s\n", line); - retcode = 1; - } - else - import (src, dst); - free (src); - free (dst); - } - else if (strncmp (line, "export ", 7) == 0) - { - char *src = 0, *dst = 0; - if (sscanf (line + 7, " %ms %ms", &src, &dst) != 2) - { - fprintf (stderr, "SYNTAX ERROR: %s\n", line); - retcode = 1; - } - else - export (src, dst); - free (src); - free (dst); - } - else if (strncmp (line, "rm ", 3) == 0) - { - if (SPIFFS_remove (&fs, trim (line + 3)) < 0) - { - fprintf (stderr, "FAILED: %s\n", line); - retcode = 1; - } - } - else if (strncmp (line, "cat ", 4) == 0) - cat (trim (line + 4)); - else if (strncmp (line, "info", 4) == 0) - { - u32_t total, used; - if (SPIFFS_info (&fs, &total, &used) < 0) - { - fprintf (stderr, "FAILED: %s\n", line); - retcode = 1; - } - else - printf ("Total: %u, Used: %u\n", total, used); - } - else - { - printf ("SYNTAX ERROR: %s\n", line); - retcode = 1; - } - - if (in == stdin) - printf ("> "); - } - if (in == stdin) - printf ("\n"); - } - - SPIFFS_unmount (&fs); - munmap (flash, sz); - close (fd); - return retcode; -} +/* + * Copyright 2015 Dius Computing Pty Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the + * distribution. + * - Neither the name of the copyright holders nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * + * @author Johny Mattsson + */ + +#include +#include +#include +#include +#include +#ifdef _MSC_VER +#include "getopt.h" /* local copy from MingW project */ +#include +#define STDIN_FILENO 0 +#define STDOUT_FILENO 1 +#define STDERR_FILENO 2 +typedef ptrdiff_t off_t; +#else +#include +#include +#include +#endif +#include +#include +#include "spiffs.h" +#define NO_CPU_ESP8266_INCLUDE +#include "../platform/cpu_esp8266.h" + +static spiffs fs; +static uint8_t *flash; + +static int retcode = 0; + +#define LOG_PAGE_SIZE 256 + +// If the caclulated size is this or less, then use smaller blocks +// (1 page) rather than the normal 2 pages. This gives a little bit +// more flexibility for the file system, at the expense of a bit of +// efficiency +#define SMALL_FILESYSTEM (128 * 1024) + +static int delete_on_die = 0; +static const char *delete_list[10]; +static int delete_list_index = 0; + +static u8_t spiffs_work_buf[LOG_PAGE_SIZE*2]; +static u8_t spiffs_fds[32*4]; + +static s32_t flash_read (u32_t addr, u32_t size, u8_t *dst) { + memcpy (dst, flash + addr, size); + return SPIFFS_OK; +} + +static s32_t flash_write (u32_t addr, u32_t size, u8_t *src) { + memcpy (flash + addr, src, size); + return SPIFFS_OK; +} + +static s32_t flash_erase (u32_t addr, u32_t size) { + memset (flash + addr, 0xff, size); + return SPIFFS_OK; +} + + +static void die (const char *what) +{ + if (errno == 0) { + fprintf(stderr, "%s: fatal error\n", what); + } else { + perror (what); + } + if (delete_on_die) { + const char **p = delete_list; + while (*p) { + unlink(*p); + p++; + } + } + exit (1); +} + + +static void list (void) +{ + spiffs_DIR dir; + if (!SPIFFS_opendir (&fs, "/", &dir)) + die ("spiffs_opendir"); + struct spiffs_dirent de; + while (SPIFFS_readdir (&dir, &de)) + { + static const char types[] = "?fdhs"; // file, dir, hardlink, softlink + char name[sizeof(de.name)+1] = { 0 }; + memcpy (name, de.name, sizeof(de.name)); + printf("%c %6u %s\n", types[de.type], de.size, name); + } + SPIFFS_closedir (&dir); +} + + +static void cat (char *fname) +{ + spiffs_file fh = SPIFFS_open (&fs, fname, SPIFFS_RDONLY, 0); + char buff[512]; + s32_t n; + while ((n = SPIFFS_read (&fs, fh, buff, sizeof (buff))) > 0) + write (STDOUT_FILENO, buff, n); + SPIFFS_close (&fs, fh); +} + + +static void import (char *src, char *dst) +{ + int fd = open (src, O_RDONLY); + if (fd < 0) + die (src); + + spiffs_file fh = SPIFFS_open (&fs, dst, SPIFFS_CREAT | SPIFFS_TRUNC | SPIFFS_WRONLY, 0); + if (fh < 0) + die ("spiffs_open"); + + char buff[16384]; + s32_t n; + while ((n = read (fd, buff, sizeof (buff))) > 0) + if (SPIFFS_write (&fs, fh, buff, n) < 0) + die ("spiffs_write"); + + if (SPIFFS_close (&fs, fh) < 0) + die("spiffs_close"); + close (fd); +} + + +static void export (char *src, char *dst) +{ + spiffs_file fh = SPIFFS_open (&fs, src, SPIFFS_RDONLY, 0); + if (fh < 0) + die ("spiffs_open"); + + int fd = open (dst, O_CREAT | O_TRUNC | O_WRONLY, 0664); + if (fd < 0) + die (dst); + + char buff[512]; + s32_t n; + while ((n = SPIFFS_read (&fs, fh, buff, sizeof (buff))) > 0) + if (write (fd, buff, n) < 0) + die ("write"); + + SPIFFS_close (&fs, fh); + close (fd); +} + + +char *trim (char *in) +{ + if (!in) + return ""; + + char *out = 0; + while (*in) + { + if (!out && !isspace (*in)) + out = in; + ++in; + } + if (!out) + return ""; + while (--in > out && isspace (*in)) + ; + in[1] = 0; + return out; +} + + +void syntax (void) +{ + fprintf (stderr, + "Syntax: spiffsimg -f [-d] [-o ] [-c size] [-S flashsize] [-U usedsize] [-l | -i | -r ]\n\n" + ); + exit (1); +} + +static size_t getsize(const char *s) +{ + char *end = 0; + size_t val = strtoul(s, &end, 0); + + if (end) { + int factor; + if (*end == 'k' || *end == 'K') { + factor = 1 << 10; + end++; + } else if (*end == 'm' || *end == 'M') { + factor = 1 << 20; + end++; + } else { + factor = 1; + } + // Capital B is bytes + if (*end == 'B') { + factor = factor << 3; + } + // we want bytes + val = (val * factor) / 8; + } + + return val; +} + +int main (int argc, char *argv[]) +{ + if (argc == 1) + syntax (); + + int opt; + const char *fname = 0; + bool create = false; + enum { CMD_NONE, CMD_LIST, CMD_INTERACTIVE, CMD_SCRIPT } command = CMD_NONE; + int sz = 0; + const char *script_name = 0; + const char *resolved = 0; + int flashsize = 0; + int used = 0; + while ((opt = getopt (argc, argv, "do:f:c:lir:S:U:")) != -1) + { + switch (opt) + { + case 'f': fname = optarg; break; + case 'o': resolved = optarg; break; + case 'c': create = true; sz = strtol(optarg, 0, 0); break; + case 'S': create = true; flashsize = getsize(optarg); break; + case 'U': create = true; used = strtol(optarg, 0, 0); break; + case 'd': delete_on_die = 1; break; + case 'l': command = CMD_LIST; break; + case 'i': command = CMD_INTERACTIVE; break; + case 'r': command = CMD_SCRIPT; script_name = optarg; break; + default: die ("unknown option"); + } + } + + if (!fname) { + die("Need a filename"); + } + +#ifdef _MSC_VER + _set_fmode( _O_BINARY ); //change default open mode to binary rather than text +#endif + int fd; + + if (create) + { + if (!sz) { + if (!flashsize || !used) { + die("Missing flashSize or Used"); + } + sz = flashsize - used - SYS_PARAM_SEC_NUM * 4096; // This leaves space for the parameter area + if (sz < 0x4000) { + die("Not enough space"); + } + if (sz > SMALL_FILESYSTEM) { + used = (used + 0xffff) & ~0xffff; + } else { + used = (used + 0x1fff) & ~0x1fff; + } + sz = flashsize - used - SYS_PARAM_SEC_NUM * 4096; + } + sz &= ~(0x1fff); + + if (used == 0) { + if (strchr(fname, '%')) { + die("Unable to calculate where to put the flash image, and % present in filename"); + } + } + + char fnamebuff[1024]; + + sprintf(fnamebuff, fname, used); + + delete_list[delete_list_index++] = strdup(fnamebuff);; + fd = open (fnamebuff, (create ? (O_CREAT | O_TRUNC) : 0) | O_RDWR, 0664); + if (fd == -1) + die ("open"); + + if (resolved) { + delete_list[delete_list_index++] = resolved; + FILE *f = fopen(resolved, "w"); + fprintf(f, "0x%x", used); + fclose(f); + } + + if (lseek (fd, sz -1, SEEK_SET) == -1) + die ("lseek"); + if (write (fd, "", 1) != 1) + die ("write"); + } + else { + fd = open (fname, O_RDWR, 0664); + if (fd == -1) + die ("open"); + + if (!sz) + { + off_t offs = lseek (fd, 0, SEEK_END); + if (offs == -1) + die ("lseek"); + sz = offs; + } + } + + if (sz & (0x1000 -1)) + die ("file size not multiple of erase block size"); + +#ifdef _MSC_VER + //We don't have a mmap(), so we simply allocate a file buffer we write out + //at the end of the program. This also means that we need to let the program + //end normally (i.e. not via Ctrl-C) or else that final write will not happen. + //If you are in interactive mode, there is not a command for 'exit', however + //EOF may be used to end the interactive loop by pressing Ctrl-Z, return. + flash = (uint8_t*)malloc( sz ); + if ( lseek( fd, 0, SEEK_SET ) == -1 ) + die( "lseek" ); + if ( read( fd, flash, sz ) != sz ) + die( "write" ); +#else + flash = mmap( 0, sz, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0 ); +#endif + if (!flash) + die ("mmap"); + + if (create) + memset (flash, 0xff, sz); + + spiffs_config cfg; + cfg.phys_size = sz; + cfg.phys_addr = 0; + cfg.phys_erase_block = 0x1000; + cfg.log_block_size = 0x1000 * (sz > SMALL_FILESYSTEM ? 2 : 1); + cfg.log_page_size = LOG_PAGE_SIZE; + cfg.hal_read_f = flash_read; + cfg.hal_write_f = flash_write; + cfg.hal_erase_f = flash_erase; + if (cfg.phys_size < 4 * cfg.log_block_size) { + die("disk not large enough for four blocks"); + } + + if (SPIFFS_mount (&fs, &cfg, + spiffs_work_buf, + spiffs_fds, + sizeof(spiffs_fds), + malloc(65536), 65536, 0) != 0) { + if (create) { + if (SPIFFS_format(&fs) != 0) { + die("spiffs_format"); + } + if (SPIFFS_mount (&fs, &cfg, + spiffs_work_buf, + spiffs_fds, + sizeof(spiffs_fds), + malloc(65536), 65536, 0) != 0) { + die ("spiffs_mount"); + } + if (command == CMD_INTERACTIVE) { + printf("Created filesystem -- size 0x%x, block_size=%d\n", cfg.phys_size, cfg.log_block_size); + } + } else { + die ("spiffs_mount"); + } + } + + if (command == CMD_NONE) + ; // maybe just wanted to create an empty image? + else if (command == CMD_LIST) + list (); + else + { + FILE *in = (command == CMD_INTERACTIVE) ? stdin : fopen (script_name, "r"); + if (!in) + die ("fopen"); + char buff[128] = { 0 }; + if (in == stdin) + printf("> "); + while (fgets (buff, sizeof (buff) -1, in)) + { + char *line = trim (buff); + if (!line[0] || line[0] == '#') + continue; + if (strcmp (line, "ls") == 0) + list (); + else if (strncmp (line, "import ", 7) == 0) + { + char *src = 0, *dst = 0; +#ifdef _MSC_VER + src = (char*)malloc(260 + 1); //MAX_PATH + dst = (char*)malloc( 260 + 1 ); + if (sscanf (line +7, " %260s %260s", src, dst) != 2) +#else + if (sscanf (line +7, " %ms %ms", &src, &dst) != 2) +#endif + { + fprintf (stderr, "SYNTAX ERROR: %s\n", line); + retcode = 1; + } + else + import (src, dst); + free (src); + free (dst); + } + else if (strncmp (line, "export ", 7) == 0) + { + char *src = 0, *dst = 0; +#ifdef _MSC_VER + src = (char*)malloc( 260 + 1 ); //MAX_PATH + dst = (char*)malloc( 260 + 1 ); + if ( sscanf( line + 7, " %260s %260s", src, dst ) != 2 ) +#else + if (sscanf (line + 7, " %ms %ms", &src, &dst) != 2) +#endif + { + fprintf (stderr, "SYNTAX ERROR: %s\n", line); + retcode = 1; + } + else + export (src, dst); + free (src); + free (dst); + } + else if (strncmp (line, "rm ", 3) == 0) + { + if (SPIFFS_remove (&fs, trim (line + 3)) < 0) + { + fprintf (stderr, "FAILED: %s\n", line); + retcode = 1; + } + } + else if (strncmp (line, "cat ", 4) == 0) + cat (trim (line + 4)); + else if (strncmp (line, "info", 4) == 0) + { + u32_t total, used; + if (SPIFFS_info (&fs, &total, &used) < 0) + { + fprintf (stderr, "FAILED: %s\n", line); + retcode = 1; + } + else + printf ("Total: %u, Used: %u\n", total, used); + } + else + { + printf ("SYNTAX ERROR: %s\n", line); + retcode = 1; + } + + if (in == stdin) + printf ("> "); + } + if (in == stdin) + printf ("\n"); + } + + SPIFFS_unmount (&fs); +#ifdef _MSC_VER + if ( lseek( fd, 0, SEEK_SET ) == -1 ) + die( "lseek" ); + if ( write( fd, flash, sz ) != sz ) + die( "write" ); + free( flash ); +#else + munmap (flash, sz); +#endif + close (fd); + return retcode; +} diff --git a/tools/spiffsimg/spiffs_typedefs.h b/tools/spiffsimg/spiffs_typedefs.h index f694d125a9..c0dd2591e8 100644 --- a/tools/spiffsimg/spiffs_typedefs.h +++ b/tools/spiffsimg/spiffs_typedefs.h @@ -10,7 +10,7 @@ typedef uint16_t u16_t; typedef int8_t s8_t; typedef uint8_t u8_t; -#ifndef __CYGWIN__ +#if !defined(__CYGWIN__) && !defined(_MSC_VER) typedef long long ptrdiff_t; #define offsetof(type, member) __builtin_offsetof (type, member) #endif From c3e24436f2968b8610275fce9b28e3b32588562b Mon Sep 17 00:00:00 2001 From: Terry Ellison Date: Thu, 11 Apr 2019 22:17:00 +0100 Subject: [PATCH 09/74] Lua string optimisation in file.c + get/put contents methods (#2717) * Lua string optimisation in file.c + get/put contents methods * Doc fix: move putcontents() into correct alphabetic order slot in list of static methods --- app/modules/file.c | 119 ++++++++++++++++++++++++++----------------- docs/modules/file.md | 45 ++++++++++++++++ 2 files changed, 118 insertions(+), 46 deletions(-) diff --git a/app/modules/file.c b/app/modules/file.c index 1d9dc9f8a9..d1de588c0f 100644 --- a/app/modules/file.c +++ b/app/modules/file.c @@ -421,67 +421,42 @@ static int file_stat( lua_State* L ) // g_read() static int file_g_read( lua_State* L, int n, int16_t end_char, int fd ) { - static char *heap_mem = NULL; - // free leftover memory - if (heap_mem) { - luaM_free(L, heap_mem); - heap_mem = NULL; - } - - if(n <= 0) - n = FILE_READ_CHUNK; - - if(end_char < 0 || end_char >255) - end_char = EOF; - + int i, j; + luaL_Buffer b; + char p[LUAL_BUFFERSIZE/2]; if(!fd) return luaL_error(L, "open a file first"); - char *p; - int i; + luaL_buffinit(L, &b); - if (n > LUAL_BUFFERSIZE) { - // get buffer from heap - p = heap_mem = luaM_malloc(L, n); - } else { - // small chunks go onto the stack - p = alloca(n); - } + for (j = 0; j < n; j += sizeof(p)) { + int nwanted = (j <= n - sizeof(p)) ? sizeof(p) : n - j; + int nread = vfs_read(fd, p, nwanted); - n = vfs_read(fd, p, n); - // bypass search if no end character provided - if (n > 0 && end_char != EOF) { - for (i = 0; i < n; ++i) - if (p[i] == end_char) - { - ++i; + if (nread == VFS_RES_ERR || nread == 0) { + lua_pushnil(L); + return 1; + } + + for (i = 0; i < nread; ++i) { + luaL_addchar(&b, p[i]); + if (p[i] == end_char) { + vfs_lseek(fd, -nread + j + i + 1, VFS_SEEK_CUR); //reposition after end char found + nread = 0; // force break on outer loop break; } - } else { - i = n; - } - - if (i == 0 || n == VFS_RES_ERR) { - if (heap_mem) { - luaM_free(L, heap_mem); - heap_mem = NULL; } - lua_pushnil(L); - return 1; - } - vfs_lseek(fd, -(n - i), VFS_SEEK_CUR); - lua_pushlstring(L, p, i); - if (heap_mem) { - luaM_free(L, heap_mem); - heap_mem = NULL; + if (nread < nwanted) + break; } + luaL_pushresult(&b); return 1; } // Lua: read() -// file.read() will read all byte in file +// file.read() will read FILE_READ_CHUNK bytes, or EOF is reached. // file.read(10) will read 10 byte from file, or EOF is reached. // file.read('q') will read until 'q' or EOF is reached. static int file_read( lua_State* L ) @@ -516,6 +491,28 @@ static int file_readline( lua_State* L ) return file_g_read(L, FILE_READ_CHUNK, '\n', fd); } +// Lua: getfile(filename) +static int file_getfile( lua_State* L ) +{ + // Warning this code C calls other file_* routines to avoid duplication code. These + // use Lua stack addressing of arguments, so this does Lua stack maniplation to + // align these + int ret_cnt = 0; + lua_settop(L ,1); + // Stack [1] = FD + file_open(L); + // Stack [1] = filename; [2] = FD or nil + if (!lua_isnil(L, -1)) { + lua_remove(L, 1); // dump filename, so [1] = FD + file_fd_ud *ud = (file_fd_ud *)luaL_checkudata(L, 1, "file.obj"); + ret_cnt = file_g_read(L, LUAI_MAXINT32, EOF, ud->fd); + // Stack [1] = FD; [2] = contents if ret_cnt = 1; + file_close(L); // leaves Stack unchanged if [1] = FD + lua_remove(L, 1); // Dump FD leaving contents as [1] / ToS + } + return ret_cnt; +} + // Lua: write("string") static int file_write( lua_State* L ) { @@ -556,6 +553,34 @@ static int file_writeline( lua_State* L ) return 1; } +// Lua: getfile(filename) +static int file_putfile( lua_State* L ) +{ + // Warning this code C calls other file_* routines to avoid duplication code. These + // use Lua stack addressing of arguments, so this does Lua stack maniplation to + // align these + int ret_cnt = 0; + lua_settop(L, 2); + lua_pushvalue(L, 2); //dup contents onto the ToS [3] + lua_pushliteral(L, "w+"); + lua_replace(L, 2); + // Stack [1] = filename; [2] "w+" [3] contents; + file_open(L); + // Stack [1] = filename; [2] "w+" [3] contents; [4] FD or nil + + if (!lua_isnil(L, -1)) { + lua_remove(L, 2); //dump "w+" attribute literal + lua_replace(L, 1); + // Stack [1] = FD; [2] contents + file_write(L); + // Stack [1] = FD; [2] contents; [3] result status + lua_remove(L, 2); //dump contents + file_close(L); + lua_remove(L, 1); // Dump FD leaving status as ToS + } + return 1; +} + // Lua: fsinfo() static int file_fsinfo( lua_State* L ) { @@ -661,6 +686,8 @@ static const LUA_REG_TYPE file_map[] = { { LSTRKEY( "flush" ), LFUNCVAL( file_flush ) }, { LSTRKEY( "rename" ), LFUNCVAL( file_rename ) }, { LSTRKEY( "exists" ), LFUNCVAL( file_exists ) }, + { LSTRKEY( "getcontents" ), LFUNCVAL( file_getfile ) }, + { LSTRKEY( "putcontents" ), LFUNCVAL( file_putfile ) }, { LSTRKEY( "fsinfo" ), LFUNCVAL( file_fsinfo ) }, { LSTRKEY( "on" ), LFUNCVAL( file_on ) }, { LSTRKEY( "stat" ), LFUNCVAL( file_stat ) }, diff --git a/docs/modules/file.md b/docs/modules/file.md index 43f11b510f..75ecc2ef15 100644 --- a/docs/modules/file.md +++ b/docs/modules/file.md @@ -139,6 +139,27 @@ remaining, used, total=file.fsinfo() print("\nFile system info:\nTotal : "..total.." (k)Bytes\nUsed : "..used.." (k)Bytes\nRemain: "..remaining.." (k)Bytes\n") ``` +## file.getcontents() + +Open and read the contents of a file. + +#### Syntax +`file.getcontents(filename)` + +#### Parameters +- `filename` file to be opened and read + +#### Returns +file contents if the file exists. `nil` if the file does not exist. + +#### Example (basic model) +```lua +print(file.getcontents('welcome.txt')) +``` +#### See also +- [`file.putcontents()`](#fileputcontents) + + ## file.list() Lists all files in the file system. @@ -287,6 +308,30 @@ file.remove("foo.lua") #### See also [`file.open()`](#fileopen) +## file.putcontents() + +Open and write the contents of a file. + +#### Syntax +`file.putcontents(filename, contents)` + +#### Parameters +- `filename` file to be created +- `contents` to be written to the file + +#### Returns +`true` if the write is ok, `nil` on error + +#### Example (basic model) +```lua +file.putcontents('welcome.txt', [[ + Hello to new user + ----------------- +]]) +``` +#### See also +- [`file.getcontents()`](#filegetcontents) + ## file.rename() Renames a file. If a file is currently open, it will be closed first. From c50d007f9e736f4193c7e68598fa5c0ed5f670bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20St=C3=B6r?= Date: Fri, 19 Apr 2019 15:51:32 +0200 Subject: [PATCH 10/74] Add README Fixes #2725 --- lua_modules/fifo/README.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 lua_modules/fifo/README.md diff --git a/lua_modules/fifo/README.md b/lua_modules/fifo/README.md new file mode 100644 index 0000000000..a6f74e40f9 --- /dev/null +++ b/lua_modules/fifo/README.md @@ -0,0 +1,3 @@ +# FIFO Module + +Documentation for this Lua module is available in the [fifo.md](../../docs/lua-modules/fifo.md) file and in the [Official NodeMCU Documentation](https://nodemcu.readthedocs.io/) in `Lua Modules` section. From 37f8f6a04a4e5f9354f2e66bb6805baaeda6fb7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20St=C3=B6r?= Date: Fri, 19 Apr 2019 16:04:10 +0200 Subject: [PATCH 11/74] Small overhaul Fixes #2724 --- docs/lua-modules/redis.md | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/docs/lua-modules/redis.md b/docs/lua-modules/redis.md index 836897edd0..c7fc4152a8 100644 --- a/docs/lua-modules/redis.md +++ b/docs/lua-modules/redis.md @@ -22,21 +22,25 @@ Function used to connect to Redis server. `redis.connect(host, [port])` #### Parameters -- `host`: Redis host name or address -- `port`: Redis database port. Default value is 6379. +- `host` Redis host name or address +- `port` Redis database port. Default value is 6379. #### Returns Object with rest of the functions. -## subscribe() +!!! important + + You need to start calling this `connect()` function to obtain a Redis object. All other functions are invoked on this object. Note the difference between `redis.connect()` (single dot) and `redis:subscribe()` (colon). + +## redis:subscribe() Subscribe to a Redis channel. #### Syntax `redis:subscribe(channel, handler)` #### Parameters -- `channel`: Channel name -- `handler`: Handler function that will be called on new message in subscribed channel +- `channel` Channel name +- `handler` Handler function that will be called on new message in subscribed channel #### Returns `nil` @@ -48,8 +52,8 @@ Publish a message to a Redis channel. `redis:publish(channel, message)` #### Parameters -- `channel`: Channel name -- `message`: Message to publish +- `channel` Channel name +- `message` Message to publish #### Returns `nil` @@ -61,12 +65,12 @@ Unsubscribes from a channel. `redis:unsubscribe(channel)` #### Parameters -- `channel`: Channel name to unsubscribe from +- `channel` Channel name to unsubscribe from #### Returns `nil` -#### redis:close() +## redis:close() Function to close connection to Redis server. #### Syntax @@ -78,9 +82,11 @@ None #### Returns `nil` -#### Example +## Example ```lua local redis = dofile("redis.lua").connect(host, port) -redis:publish("chan1", foo") -redis:subscribe("chan1", function(channel, msg) print(channel, msg) end) +redis:publish("chan1", "foo") +redis:subscribe("chan1", function(channel, msg) + print(channel, msg) +end) ``` From 530c353ff8bd4ce184851b1b700dd5c93706c7e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arnim=20L=C3=A4uger?= Date: Sun, 28 Apr 2019 15:45:04 +0200 Subject: [PATCH 12/74] Update u8g2 to v2.25.10 (#2735) * Upgrade u8g2 and add updateDisplayArea bindings * u8g2 2.25.10 * add displays for 2.24.3 and 2.25.10 * remove workaround for hal pointer and make use of u8x8's user_ptr * fix doc * add binding for `updateDisplay()` --- app/include/u8g2_displays.h | 171 +++++++++++++++++--------------- app/modules/u8g2.c | 34 ++++++- app/platform/u8x8_nodemcu_hal.c | 15 +-- app/platform/u8x8_nodemcu_hal.h | 1 - app/u8g2lib/Makefile | 2 +- app/u8g2lib/u8g2 | 2 +- docs/modules/u8g2.md | 27 ++++- 7 files changed, 154 insertions(+), 98 deletions(-) diff --git a/app/include/u8g2_displays.h b/app/include/u8g2_displays.h index ba5c3426f0..b074ef1ab5 100644 --- a/app/include/u8g2_displays.h +++ b/app/include/u8g2_displays.h @@ -7,50 +7,53 @@ // *************************************************************************** // Enable display drivers // -// Uncomment the U8G2_DISPLAY_TABLE_ENTRY for the device(s) you want to -// compile into the firmware. +// Copy the uncommented U8G2_DISPLAY_TABLE_ENTRY for the device(s) you want to +// compile into the firmware to U8G2_DISPLAY_TABLE_I2C or U8G2_DISPLAY_TABLE_SPI. // Stick to the assignments to *_I2C and *_SPI tables. #ifndef U8G2_DISPLAY_TABLE_I2C_EXTRA // I2C based displays go into here: -// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_uc1610_i2c_ea_dogxl160_f, uc1610_i2c_ea_dogxl160) \ -// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_ssd1325_i2c_nhd_128x64_f, ssd1325_i2c_nhd_128x64) \ -// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_ssd1306_i2c_64x48_er_f, ssd1306_i2c_64x48_er) \ -// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_uc1608_i2c_erc24064_f, uc1608_i2c_erc24064) \ -// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_st7588_i2c_jlx12864_f, st7588_i2c_jlx12864) \ -// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_ssd1309_i2c_128x64_noname0_f, ssd1309_i2c_128x64_noname0) \ -// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_uc1611_i2c_ea_dogxl240_f, uc1611_i2c_ea_dogxl240) \ -// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_ssd1305_i2c_128x32_noname_f, ssd1305_i2c_128x32_noname) \ -// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_ssd1306_i2c_128x32_univision_f, ssd1306_i2c_128x32_univision) \ -// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_uc1608_i2c_240x128_f, uc1608_i2c_240x128) \ // U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_ld7032_i2c_60x32_f, ld7032_i2c_60x32) \ -// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_uc1611_i2c_ew50850_f, uc1611_i2c_ew50850) \ -// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_uc1604_i2c_jlx19264_f, uc1604_i2c_jlx19264) \ -// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_uc1601_i2c_128x32_f, uc1601_i2c_128x32) \ // U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_sh1106_i2c_128x64_vcomh0_f, sh1106_i2c_128x64_vcomh0) \ -// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_ssd1306_i2c_96x16_er_f, ssd1306_i2c_96x16_er) \ // U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_sh1106_i2c_128x64_noname_f, sh1106_i2c_128x64_noname) \ // U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_sh1107_i2c_64x128_f, sh1107_i2c_64x128) \ -// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_sh1107_i2c_seeed_96x96_f, sh1107_i2c_seeed_96x96) \ // U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_sh1107_i2c_128x128_f, sh1107_i2c_128x128) \ +// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_sh1107_i2c_seeed_96x96_f, sh1107_i2c_seeed_96x96) \ // U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_sh1108_i2c_160x160_f, sh1108_i2c_160x160) \ // U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_sh1122_i2c_256x64_f, sh1122_i2c_256x64) \ -// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_ssd1306_i2c_128x64_vcomh0_f, ssd1306_i2c_128x64_vcomh0) \ +// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_ssd0323_i2c_os128064_f, ssd0323_i2c_os128064) \ +// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_ssd1305_i2c_128x32_noname_f, ssd1305_i2c_128x32_noname) \ +// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_ssd1306_i2c_64x48_er_f, ssd1306_i2c_64x48_er) \ +// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_ssd1306_i2c_96x16_er_f, ssd1306_i2c_96x16_er) \ +// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_ssd1306_i2c_128x32_univision_f, ssd1306_i2c_128x32_univision) \ +// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_ssd1306_i2c_128x64_alt0_f, ssd1306_i2c_128x64_alt0) \ // U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_ssd1306_i2c_128x64_noname_f, ssd1306_i2c_128x64_noname) \ +// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_ssd1306_i2c_128x64_vcomh0_f, ssd1306_i2c_128x64_vcomh0) \ +// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_ssd1309_i2c_128x64_noname0_f, ssd1309_i2c_128x64_noname0) \ // U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_ssd1309_i2c_128x64_noname2_f, ssd1309_i2c_128x64_noname2) \ -// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_ssd1306_i2c_128x64_alt0_f, ssd1306_i2c_128x64_alt0) \ -// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_uc1611_i2c_ea_dogm240_f, uc1611_i2c_ea_dogm240) \ +// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_ssd1318_i2c_128x96_f, ssd1318_i2c_128x96) \ +// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_ssd1318_i2c_128x96_xcp_f, ssd1318_i2c_128x96_xcp) \ +// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_ssd1325_i2c_nhd_128x64_f, ssd1325_i2c_nhd_128x64) \ // U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_ssd1326_i2c_er_256x32_f, ssd1326_i2c_er_256x32 )\ -// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_ssd1327_i2c_seeed_96x96_f, ssd1327_i2c_seeed_96x96) \ // U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_ssd1327_i2c_ea_w128128_f, ssd1327_i2c_ea_w128128) \ // U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_ssd1327_i2c_midas_128x128_f, ssd1327_i2c_midas_128x128) \ +// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_ssd1327_i2c_seeed_96x96_f, ssd1327_i2c_seeed_96x96) \ // U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_st7567_i2c_64x32_f, st7567_i2c_64x32) \ +// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_st7588_i2c_jlx12864_f, st7588_i2c_jlx12864) \ // U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_st75256_i2c_jlx256128_f, st75256_i2c_jlx256128) \ // U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_st75256_i2c_jlx256160_f, st75256_i2c_jlx256160) \ // U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_st75256_i2c_jlx240160_f, st75256_i2c_jlx240160) \ // U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_st75256_i2c_jlx25664_f, st75256_i2c_jlx25664) \ // U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_st75256_i2c_jlx172104_f, st75256_i2c_jlx172104) \ +// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_uc1601_i2c_128x32_f, uc1601_i2c_128x32) \ +// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_uc1604_i2c_jlx19264_f, uc1604_i2c_jlx19264) \ +// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_uc1608_i2c_240x128_f, uc1608_i2c_240x128) \ +// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_uc1608_i2c_erc24064_f, uc1608_i2c_erc24064) \ +// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_uc1610_i2c_ea_dogxl160_f, uc1610_i2c_ea_dogxl160) \ +// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_uc1611_i2c_ea_dogm240_f, uc1611_i2c_ea_dogm240) \ +// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_uc1611_i2c_ea_dogxl240_f, uc1611_i2c_ea_dogxl240) \ +// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_uc1611_i2c_ew50850_f, uc1611_i2c_ew50850) \ #define U8G2_DISPLAY_TABLE_I2C \ U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_ssd1306_i2c_128x64_noname_f, ssd1306_i2c_128x64_noname) \ @@ -67,83 +70,89 @@ #ifndef U8G2_DISPLAY_TABLE_SPI_EXTRA // SPI based displays go into here: -// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_ssd1606_172x72_f, ssd1606_172x72) \ -// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_uc1608_240x128_f, uc1608_240x128) \ -// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_st7565_erc12864_f, st7565_erc12864) \ -// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_ssd1309_128x64_noname0_f, ssd1309_128x64_noname0) \ -// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_uc1601_128x32_f, uc1601_128x32) \ -// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_uc1608_erc24064_f, uc1608_erc24064) \ -// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_st7565_lm6059_f, st7565_lm6059) \ -// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_uc1611_ea_dogxl240_f, uc1611_ea_dogxl240) \ -// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_st7565_nhd_c12864_f, st7565_nhd_c12864) \ -// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_ssd1306_128x64_vcomh0_f, ssd1306_128x64_vcomh0) \ -// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_ssd1305_128x32_noname_f, ssd1305_128x32_noname) \ -// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_max7219_32x8_f, max7219_32x8) \ -// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_ls013b7dh03_128x128_f, ls013b7dh03_128x128) \ +// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_hx1230_96x68_f, hx1230_96x68) \ // U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_il3820_v2_296x128_f, il3820_v2_296x128) \ -// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_uc1610_ea_dogxl160_f, uc1610_ea_dogxl160) \ -// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_uc1611_ea_dogm240_f, uc1611_ea_dogm240) \ -// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_uc1604_jlx19264_f, uc1604_jlx19264) \ -// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_st7920_s_192x32_f, st7920_s_192x32) \ -// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_ssd1325_nhd_128x64_f, ssd1325_nhd_128x64) \ -// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_ssd1306_128x64_noname_f, ssd1306_128x64_noname) \ -// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_ssd1306_128x64_alt0_f, ssd1306_128x64_alt0) \ -// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_sed1520_122x32_f, sed1520_122x32) \ -// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_st7565_ea_dogm128_f, st7565_ea_dogm128) \ +// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_ist3020_erc19264_f, ist3020_erc19264) \ +// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_lc7981_160x80_f, lc7981_160x80) \ +// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_lc7981_160x160_f, lc7981_160x160) \ +// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_lc7981_240x64_f, lc7981_240x64) \ +// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_lc7981_240x128_f, lc7981_240x128) \ // U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_ld7032_60x32_f, ld7032_60x32) \ -// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_ssd1607_200x200_f, ssd1607_200x200) \ -// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_ssd1309_128x64_noname2_f, ssd1309_128x64_noname2) \ -// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_sh1106_128x64_noname_f, sh1106_128x64_noname) \ +// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_ls013b7dh03_128x128_f, ls013b7dh03_128x128) \ +// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_max7219_32x8_f, max7219_32x8) \ +// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_nt7534_tg12864r_f, nt7534_tg12864r) \ +// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_pcd8544_84x48_f, pcd8544_84x48) \ +// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_pcf8812_96x65_f, pcf8812_96x65) \ +// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_sed1520_122x32_f, sed1520_122x32) \ // U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_sh1107_64x128_f, sh1107_64x128) \ -// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_sh1107_seeed_96x96_f, sh1107_seeed_96x96) \ +// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_sh1106_128x64_noname_f, sh1106_128x64_noname) \ +// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_sh1106_128x64_vcomh0_f, sh1106_128x64_vcomh0) \ // U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_sh1107_128x128_f, sh1107_128x128) \ // U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_sh1108_160x160_f, sh1108_160x160) \ +// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_sh1107_seeed_96x96_f, sh1107_seeed_96x96) \ // U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_sh1122_256x64_f, sh1122_256x64) \ +// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_ssd0323_os128064_f, ssd0323_os128064) \ +// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_ssd1305_128x32_noname_f, ssd1305_128x32_noname) \ +// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_ssd1306_64x48_er_f, ssd1306_64x48_er) \ +// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_ssd1306_96x16_er_f, ssd1306_96x16_er) \ // U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_ssd1306_128x32_univision_f, ssd1306_128x32_univision) \ -// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_st7920_s_128x64_f, st7920_s_128x64) \ -// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_st7565_64128n_f, st7565_64128n) \ -// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_uc1701_ea_dogs102_f, uc1701_ea_dogs102) \ -// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_uc1611_ew50850_f, uc1611_ew50850) \ -// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_ssd1322_nhd_256x64_f, ssd1322_nhd_256x64) \ +// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_ssd1306_128x64_alt0_f, ssd1306_128x64_alt0) \ +// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_ssd1306_128x64_noname_f, ssd1306_128x64_noname) \ +// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_ssd1306_128x64_vcomh0_f, ssd1306_128x64_vcomh0) \ +// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_ssd1309_128x64_noname0_f, ssd1309_128x64_noname0) \ +// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_ssd1309_128x64_noname2_f, ssd1309_128x64_noname2) \ +// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_ssd1318_128x96_f, ssd1318_128x96) \ +// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_ssd1318_128x96_xcp_f, ssd1318_128x96_xcp) \ // U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_ssd1322_nhd_128x64_f, ssd1322_nhd_128x64) \ -// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_st7565_ea_dogm132_f, st7565_ea_dogm132) \ -// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_ssd1329_128x96_noname_f, ssd1329_128x96_noname) \ -// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_st7565_zolen_128x64_f, st7565_zolen_128x64) \ -// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_st75256_jlx256128_f, st75256_jlx256128) \ -// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_ssd1306_96x16_er_f, ssd1306_96x16_er) \ -// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_ist3020_erc19264_f, ist3020_erc19264) \ -// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_st7588_jlx12864_f, st7588_jlx12864) \ +// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_ssd1322_nhd_256x64_f, ssd1322_nhd_256x64) \ +// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_ssd1325_nhd_128x64_f, ssd1325_nhd_128x64) \ // U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_ssd1326_er_256x32_f, ssd1326_er_256x32 )\ -// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_ssd1327_seeed_96x96_f, ssd1327_seeed_96x96) \ // U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_ssd1327_ea_w128128_f, ssd1327_ea_w128128) \ // U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_ssd1327_midas_128x128_f, ssd1327_midas_128x128) \ -// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_st75256_jlx172104_f, st75256_jlx172104) \ +// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_ssd1327_seeed_96x96_f, ssd1327_seeed_96x96) \ +// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_ssd1329_128x96_noname_f, ssd1329_128x96_noname) \ +// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_ssd1606_172x72_f, ssd1606_172x72) \ +// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_ssd1607_200x200_f, ssd1607_200x200) \ +// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_ssd1607_gd_200x200_f, ssd1607_gd_200x200) \ +// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_ssd1607_ws_200x200_f, ssd1607_ws_200x200) \ +// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_st7565_64128n_f, st7565_64128n) \ +// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_st7565_ea_dogm132_f, st7565_ea_dogm132) \ +// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_st7565_ea_dogm128_f, st7565_ea_dogm128) \ +// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_st7565_erc12864_f, st7565_erc12864) \ +// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_st7565_erc12864_alt_f, st7565_erc12864_alt) \ +// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_st7565_lm6059_f, st7565_lm6059) \ // U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_st7565_nhd_c12832_f, st7565_nhd_c12832) \ -// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_st75256_jlx256160_f, st75256_jlx256160) \ -// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_st75256_jlx240160_f, st75256_jlx240160) \ -// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_st75256_jlx25664_f, st75256_jlx25664) \ -// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_ssd1306_64x48_er_f, ssd1306_64x48_er) \ -// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_pcf8812_96x65_f, pcf8812_96x65) \ -// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_st7567_pi_132x64_f, st7567_pi_132x64) \ -// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_st7567_jlx12864_f, st7567_jlx12864) \ +// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_st7565_nhd_c12864_f, st7565_nhd_c12864) \ +// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_st7565_zolen_128x64_f, st7565_zolen_128x64) \ // U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_st7567_enh_dg128064i_f, st7567_enh_dg128064i) \ // U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_st7567_64x32_f, st7567_64x32) \ -// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_st7586s_s028hn118a_f, st7586s_s028hn118a) \ +// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_st7567_jlx12864_f, st7567_jlx12864) \ +// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_st7567_pi_132x64_f, st7567_pi_132x64) \ // U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_st7586s_erc240160_f, st7586s_erc240160) \ -// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_pcd8544_84x48_f, pcd8544_84x48) \ -// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_sh1106_128x64_vcomh0_f, sh1106_128x64_vcomh0) \ -// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_nt7534_tg12864r_f, nt7534_tg12864r) \ -// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_uc1701_mini12864_f, uc1701_mini12864) \ -// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_t6963_240x128_f, t6963_240x128) \ -// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_t6963_240x64_f, t6963_240x64) \ -// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_t6963_256x64_f, t6963_256x64) \ +// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_st7586s_s028hn118a_f, st7586s_s028hn118a) \ +// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_st7588_jlx12864_f, st7588_jlx12864) \ +// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_st7920_s_192x32_f, st7920_s_192x32) \ +// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_st7920_s_128x64_f, st7920_s_128x64) \ +// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_st75256_jlx25664_f, st75256_jlx25664) \ +// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_st75256_jlx172104_f, st75256_jlx172104) \ +// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_st75256_jlx240160_f, st75256_jlx240160) \ +// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_st75256_jlx256128_f, st75256_jlx256128) \ +// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_st75256_jlx256160_f, st75256_jlx256160) \ // U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_t6963_128x64_f, t6963_128x64) \ // U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_t6963_160x80_f, t6963_160x80) \ -// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_lc7981_160x80_f, lc7981_160x80) \ -// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_lc7981_160x160_f, lc7981_160x160) \ -// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_lc7981_240x128_f, lc7981_240x128) \ -// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_lc7981_240x64_f, lc7981_240x64) \ -// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_hx1230_96x68_f, hx1230_96x68) \ +// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_t6963_240x64_f, t6963_240x64) \ +// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_t6963_240x128_f, t6963_240x128) \ +// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_t6963_256x64_f, t6963_256x64) \ +// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_uc1601_128x32_f, uc1601_128x32) \ +// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_uc1604_jlx19264_f, uc1604_jlx19264) \ +// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_uc1608_240x128_f, uc1608_240x128) \ +// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_uc1608_erc24064_f, uc1608_erc24064) \ +// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_uc1610_ea_dogxl160_f, uc1610_ea_dogxl160) \ +// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_uc1611_ea_dogm240_f, uc1611_ea_dogm240) \ +// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_uc1611_ea_dogxl240_f, uc1611_ea_dogxl240) \ +// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_uc1611_ew50850_f, uc1611_ew50850) \ +// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_uc1701_ea_dogs102_f, uc1701_ea_dogs102) \ +// U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_uc1701_mini12864_f, uc1701_mini12864) \ #define U8G2_DISPLAY_TABLE_SPI \ U8G2_DISPLAY_TABLE_ENTRY(u8g2_Setup_ssd1306_128x64_noname_f, ssd1306_128x64_noname) \ diff --git a/app/modules/u8g2.c b/app/modules/u8g2.c index b613b5ea47..6af428bdeb 100644 --- a/app/modules/u8g2.c +++ b/app/modules/u8g2.c @@ -11,6 +11,7 @@ #include "lauxlib.h" #define U8X8_USE_PINS +#define U8X8_WITH_USER_PTR #include "u8g2.h" #include "u8x8_nodemcu_hal.h" @@ -540,6 +541,29 @@ static int lu8g2_setPowerSave( lua_State *L ) return 0; } +static int lu8g2_updateDisplay( lua_State *L ) +{ + GET_U8G2(); + + u8g2_UpdateDisplay( u8g2 ); + +} + +static int lu8g2_updateDisplayArea( lua_State *L ) +{ + GET_U8G2(); + int stack = 1; + + int x = luaL_checkint( L, ++stack ); + int y = luaL_checkint( L, ++stack ); + int w = luaL_checkint( L, ++stack ); + int h = luaL_checkint( L, ++stack ); + + u8g2_UpdateDisplayArea( u8g2, x, y, w, h ); + + return 0; +} + static const LUA_REG_TYPE lu8g2_display_map[] = { { LSTRKEY( "clearBuffer" ), LFUNCVAL( lu8g2_clearBuffer ) }, @@ -581,6 +605,8 @@ static const LUA_REG_TYPE lu8g2_display_map[] = { { LSTRKEY( "setFontRefHeightExtendedText" ), LFUNCVAL( lu8g2_setFontRefHeightExtendedText ) }, { LSTRKEY( "setFontRefHeightText" ), LFUNCVAL( lu8g2_setFontRefHeightText ) }, { LSTRKEY( "setPowerSave" ), LFUNCVAL( lu8g2_setPowerSave ) }, + { LSTRKEY( "updateDispla" ), LFUNCVAL( lu8g2_updateDisplay ) }, + { LSTRKEY( "updateDisplayArea" ), LFUNCVAL( lu8g2_updateDisplayArea ) }, //{ LSTRKEY( "__gc" ), LFUNCVAL( lu8g2_display_free ) }, { LSTRKEY( "__index" ), LROVAL( lu8g2_display_map ) }, {LNILKEY, LNILVAL} @@ -622,11 +648,11 @@ static int ldisplay_i2c( lua_State *L, display_setup_fn_t setup_fn ) u8g2_nodemcu_t *ext_u8g2 = &(ud->u8g2); ud->font_ref = LUA_NOREF; ud->host_ref = LUA_NOREF; - /* the i2c driver id is forwarded in the hal member */ - ext_u8g2->hal = id >= 0 ? (void *)id : NULL; u8g2_t *u8g2 = (u8g2_t *)ext_u8g2; u8x8_t *u8x8 = (u8x8_t *)u8g2; + /* the i2c driver id is forwarded in the user pointer */ + u8x8->user_ptr = id >= 0 ? (void *)id : NULL; setup_fn( u8g2, U8G2_R0, u8x8_byte_nodemcu_i2c, u8x8_gpio_and_delay_nodemcu ); @@ -715,11 +741,11 @@ static int ldisplay_spi( lua_State *L, display_setup_fn_t setup_fn ) u8g2_nodemcu_t *ext_u8g2 = &(ud->u8g2); ud->font_ref = LUA_NOREF; ud->host_ref = host_ref; - /* the spi host id is forwarded in the hal member */ - ext_u8g2->hal = host ? (void *)(host->host) : NULL; u8g2_t *u8g2 = (u8g2_t *)ext_u8g2; u8x8_t *u8x8 = (u8x8_t *)u8g2; + /* the spi host id is forwarded in the user pointer */ + u8x8->user_ptr = host ? (void *)(host->host) : NULL; setup_fn( u8g2, U8G2_R0, u8x8_byte_nodemcu_spi, u8x8_gpio_and_delay_nodemcu ); diff --git a/app/platform/u8x8_nodemcu_hal.c b/app/platform/u8x8_nodemcu_hal.c index 509a01b4ea..321a3093bb 100644 --- a/app/platform/u8x8_nodemcu_hal.c +++ b/app/platform/u8x8_nodemcu_hal.c @@ -11,6 +11,7 @@ #include "platform.h" #define U8X8_USE_PINS +#define U8X8_WITH_USER_PTR #include "u8x8_nodemcu_hal.h" // static variables containing info about the i2c link @@ -45,7 +46,7 @@ static void force_flush_buffer(u8x8_t *u8x8) { // spi hal has a buffer that can be flushed if (u8x8->byte_cb == u8x8_byte_nodemcu_spi) { - hal_spi_t *hal = ((u8g2_nodemcu_t *)u8x8)->hal; + hal_spi_t *hal = u8x8->user_ptr; flush_buffer_spi( hal ); } } @@ -164,7 +165,7 @@ uint8_t u8x8_gpio_and_delay_nodemcu(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, uint8_t u8x8_byte_nodemcu_i2c(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr) { uint8_t *data; - hal_i2c_t *hal = ((u8g2_nodemcu_t *)u8x8)->hal; + hal_i2c_t *hal = u8x8->user_ptr; switch(msg) { case U8X8_MSG_BYTE_SEND: @@ -186,12 +187,12 @@ uint8_t u8x8_byte_nodemcu_i2c(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void * case U8X8_MSG_BYTE_INIT: { - // the hal member initially contains the i2c id + // the user pointer initially contains the i2c id int id = (int)hal; if (!(hal = c_malloc( sizeof ( hal_i2c_t ) ))) return 0; hal->id = id; - ((u8g2_nodemcu_t *)u8x8)->hal = hal; + u8x8->user_ptr = hal; } break; @@ -229,7 +230,7 @@ uint8_t u8x8_byte_nodemcu_i2c(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void * uint8_t u8x8_byte_nodemcu_spi(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr) { - hal_spi_t *hal = ((u8g2_nodemcu_t *)u8x8)->hal; + hal_spi_t *hal = u8x8->user_ptr; switch(msg) { case U8X8_MSG_BYTE_INIT: @@ -237,12 +238,12 @@ uint8_t u8x8_byte_nodemcu_spi(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void * /* disable chipselect */ u8x8_gpio_SetCS( u8x8, u8x8->display_info->chip_disable_level ); - // the hal member initially contains the spi host id + // the user pointer initially contains the spi host id int host = (int)hal; if (!(hal = c_malloc( sizeof ( hal_spi_t ) ))) return 0; hal->host = host; - ((u8g2_nodemcu_t *)u8x8)->hal = hal; + u8x8->user_ptr = hal; hal->buffer.data = NULL; hal->last_dc = 0; diff --git a/app/platform/u8x8_nodemcu_hal.h b/app/platform/u8x8_nodemcu_hal.h index 22a17402bc..6557dfdbbf 100644 --- a/app/platform/u8x8_nodemcu_hal.h +++ b/app/platform/u8x8_nodemcu_hal.h @@ -8,7 +8,6 @@ // extend standard u8g2_t struct with info that's needed in the communication callbacks typedef struct { u8g2_t u8g2; - void *hal; // elements for the overlay display driver struct { diff --git a/app/u8g2lib/Makefile b/app/u8g2lib/Makefile index 1343a949f5..e1b0b82d76 100644 --- a/app/u8g2lib/Makefile +++ b/app/u8g2lib/Makefile @@ -24,7 +24,7 @@ STD_CFLAGS=-std=gnu11 -Wimplicit # makefile at its root level - these are then overridden # for a subtree within the makefile rooted therein # -DEFINES += -DU8X8_USE_PINS -DU8G2_USE_LARGE_FONTS +DEFINES += -DU8X8_USE_PINS -DU8G2_USE_LARGE_FONTS -DU8X8_WITH_USER_PTR ############################################################# # Recursion Magic - Don't touch this!! diff --git a/app/u8g2lib/u8g2 b/app/u8g2lib/u8g2 index d4da825422..2ee84c8f14 160000 --- a/app/u8g2lib/u8g2 +++ b/app/u8g2lib/u8g2 @@ -1 +1 @@ -Subproject commit d4da8254220adf39db44faa52a0842967095d230 +Subproject commit 2ee84c8f14adaa8fd1ebfe091c4de348c5474b18 diff --git a/docs/modules/u8g2.md b/docs/modules/u8g2.md index 90b753a12b..ad7a90e549 100644 --- a/docs/modules/u8g2.md +++ b/docs/modules/u8g2.md @@ -43,9 +43,11 @@ The NodeMCU firmware supports the following displays in I²C and SPI mode: - sh1106 128x64 - sh1107 - variants 64x128, seeed 96x96, 128x128 - sh1108 160x160 +- ssd0323 os128064 - ssd1305 128x32 - ssd1306 - variants 128x32, 128x64, 64x48, and 96x16 - ssd1309 128x64 +- ssd1318 128x96, 128x96_xcp - ssd1325 128x63 - ssd1326 er 256x32 - ssd1327 - variants 96x96, ea w128128, and midas 128x128 @@ -73,15 +75,15 @@ SPI only: - ssd1322 nhd 256x64 and nhd 128x64 variants - ssd1329 128x96 - ssd1606 172x72 -- ssd1607 200x200 -- st7565 - variants 64128n, dogm128/132, erc12864, lm6059, c12832/c12864, and zolen 128x64 +- ssd1607 200x200, gd_200x200, ws_200x200 +- st7565 - variants 64128n, dogm128/132, erc12864, erc12864_alt, lm6059, c12832/c12864, and zolen 128x64 - st7567 - variants 132x64, jlx12864, and enh_dg128064i - st7586 - s028hn118a and erc240160 variants - st75256 - jlx172104 and jlx256128 variants - t6963 - variants 240x128, 240x64, 256x64, 128x64, and 160x80 - uc1701 - dogs102 and mini12864 variants -This integration uses full "RAM" memory buffer without picture loop and calls u8g2's `begin()` internally when creating a display object. It is based on [v2.23.18](https://github.com/olikraus/U8g2_Arduino/releases/tag/2.23.18). +This integration uses full "RAM" memory buffer without picture loop and calls u8g2's `begin()` internally when creating a display object. It is based on [v2.25.10](https://github.com/olikraus/U8g2_Arduino/releases/tag/2.25.10). ## Overview @@ -165,6 +167,7 @@ Initialize a display via I²C. - `u8g2.sh1107_i2c_seeed_96x96()` - `u8g2.sh1107_i2c_128x128()` - `u8g2.sh1108_i2c_160x160()` +- `u8g2.ssd0323_i2c_os128064()` - `u8g2.ssd1305_i2c_128x32_noname()` - `u8g2.ssd1306_i2c_128x32_univision()` - `u8g2.ssd1306_i2c_128x64_noname()` @@ -174,6 +177,8 @@ Initialize a display via I²C. - `u8g2.ssd1306_i2c_128x64_alt0()` - `u8g2.ssd1306_i2c_64x48_er()` - `u8g2.ssd1306_i2c_96x16_er()` +- `u8g2.ssd1318_i2c_128x96()` +- `u8g2.ssd1318_i2c_128x96_xcp()` - `u8g2.ssd1325_i2c_nhd_128x64()` - `u8g2.ssd1326_i2c_er_256x32()` - `u8g2.ssd1327_i2c_seeed_96x96()` @@ -249,6 +254,7 @@ Initialize a display via Hardware SPI. - `u8g2.sh1107_128x128()` - `u8g2.sh1108_160x160()` - `u8g2.sh1122_256x64()` +- `u8g2.ssd0323_os128064()` - `u8g2.ssd1305_128x32_noname()` - `u8g2.ssd1306_128x32_univision()` - `u8g2.ssd1306_128x64_noname()` @@ -258,6 +264,8 @@ Initialize a display via Hardware SPI. - `u8g2.ssd1306_96x16_er()` - `u8g2.ssd1309_128x64_noname0()` - `u8g2.ssd1309_128x64_noname2()` +- `u8g2.ssd1318_128x96()` +- `u8g2.ssd1318_128x96_xcp()` - `u8g2.ssd1322_nhd_128x64()` - `u8g2.ssd1326_er_256x32()` - `u8g2.ssd1327_ea_w128128()` @@ -269,10 +277,13 @@ Initialize a display via Hardware SPI. - `u8g2.sed1520_122x32()` - `u8g2.ssd1606_172x72()` - `u8g2.ssd1607_200x200()` +- `u8g2.ssd1607_gd_200x200()` +- `u8g2.ssd1607_ws_200x200()` - `u8g2.st7565_64128n()` - `u8g2.st7565_ea_dogm128()` - `u8g2.st7565_ea_dogm132()` - `u8g2.st7565_erc12864()` +- `u8g2.st7565_erc12864_alt()` - `u8g2.st7565_lm6059()` - `u8g2.st7565_nhd_c12832()` - `u8g2.st7565_nhd_c12864()` @@ -590,3 +601,13 @@ See [u8g2 setFontRefHeightText()](https://github.com/olikraus/u8g2/wiki/u8g2refe Activate or disable power save mode of the display. See [u8g2 setPowerSave()](https://github.com/olikraus/u8g2/wiki/u8g2reference#setpowersave). + +## u8g2.disp:updateDisplay() +Updates the display. + +See [u8g2 updateDisplay()](https://github.com/olikraus/u8g2/wiki/u8g2reference#updateDisplay). + +## u8g2.disp:updateDisplayArea() +Updates the specified rectangle area of the display. + +See [u8g2 updateDisplayArea()](https://github.com/olikraus/u8g2/wiki/u8g2reference#updateDisplayArea). From b7a99358cc3e96f1013d3fe51bae8b696386147e Mon Sep 17 00:00:00 2001 From: devsaurus Date: Sun, 28 Apr 2019 21:32:31 +0200 Subject: [PATCH 13/74] u8g2: fix return value --- app/modules/u8g2.c | 1 + 1 file changed, 1 insertion(+) diff --git a/app/modules/u8g2.c b/app/modules/u8g2.c index 6af428bdeb..307cbea1d3 100644 --- a/app/modules/u8g2.c +++ b/app/modules/u8g2.c @@ -547,6 +547,7 @@ static int lu8g2_updateDisplay( lua_State *L ) u8g2_UpdateDisplay( u8g2 ); + return 0; } static int lu8g2_updateDisplayArea( lua_State *L ) From bc61528db77d7a2e67dbb96889400d0e729cc6c8 Mon Sep 17 00:00:00 2001 From: Terry Ellison Date: Wed, 1 May 2019 18:29:11 +0100 Subject: [PATCH 14/74] 1st Tranch of SDK 3.0 follow up changes (#2732) 1st Tranche of SDK 3.0 follow up changes --- Makefile | 225 ++++++++++++++++------------ app/include/user_config.h | 23 ++- app/include/user_modules.h | 14 +- app/libc/c_string.h | 1 + app/modules/file.c | 24 +-- app/modules/node.c | 178 +++++++++++++++++++++- app/platform/platform.c | 129 +++++++++++++++- app/platform/platform.h | 43 +++++- app/user/user_main.c | 292 +++++++++++++++++++++++-------------- docs/modules/node.md | 43 ++++++ ld/nodemcu.ld | 2 +- tools/nodemcu-partition.py | 257 ++++++++++++++++++++++---------- 12 files changed, 914 insertions(+), 317 deletions(-) diff --git a/Makefile b/Makefile index de3376b35e..a642f6d45b 100644 --- a/Makefile +++ b/Makefile @@ -2,21 +2,32 @@ # .NOTPARALLEL: -TOOLCHAIN_VERSION:=20181106.0 +TOP_DIR:=$(abspath $(dir $(lastword $(MAKEFILE_LIST)))) -# SDK base version, as released by Espressif -SDK_BASE_VER:=3.0 -SDK_VER:=$(SDK_BASE_VER) -SDK_DIR_DEPENDS:=sdk_extracted +# SDK base version, as released by Espressif depends on the RELEASE flag +# +# RELEASE = lastest pulls the latest V3.0.0 branch version as at the issue of this make +# otherwise it pulls the labelled version in the SDK version's release directory +# +ifeq ("$(RELEASE)","latest") + export RELEASE:=$(RELEASE) + SDK_VER := 3.0.0-dev-190412 + SDK_COMMIT_SHA1:= 39ec2d4573eb77fda73f6afcf6dd1b3c41e74fcd + SDK_FILE_SHA1 := 44f7724490739536526fc4298d6fcc2fa2d29471 + SDK_ZIP_ROOT := ESP8266_NONOS_SDK-$(SDK_COMMIT_SHA1) + SDK_FILE_VER := $(SDK_COMMIT_SHA1) +else + SDK_VER := 3.0 + SDK_FILE_SHA1 := 029fc23fe87e03c9852de636490b2d7b9e07f01a + SDK_ZIP_ROOT := ESP8266_NONOS_SDK-$(SDK_VER) + SDK_FILE_VER := v$(SDK_VER) +endif +SDK_REL_DIR := sdk/esp_iot_sdk_v$(SDK_VER) +SDK_DIR := $(TOP_DIR)/$(SDK_REL_DIR) -SDK_FILE_VER:=$(SDK_BASE_VER) -SDK_FILE_SHA1:=029fc23fe87e03c9852de636490b2d7b9e07f01a -ESPTOOL_VER:=2.6 +ESPTOOL_VER := 2.6 -# Ensure we search "our" SDK before the tool-chain's SDK (if any) -TOP_DIR:=$(abspath $(dir $(lastword $(MAKEFILE_LIST)))) -SDK_REL_DIR=sdk/esp_iot_sdk_v$(SDK_VER) -SDK_DIR:=$(TOP_DIR)/$(SDK_REL_DIR) +# Ensure that the Espresif SDK is searched before the tool-chain's SDK (if any) CCFLAGS:= -I$(TOP_DIR)/sdk-overrides/include -I$(TOP_DIR)/app/include/lwip/app -I$(SDK_DIR)/include LDFLAGS:= -L$(SDK_DIR)/lib -L$(SDK_DIR)/ld $(LDFLAGS) @@ -27,19 +38,19 @@ else CCFLAGS += -O2 endif -#Handling of V=1/VERBOSE=1 flag + +# Handling of V=1/VERBOSE=1 flag # # if V=1, $(summary) does nothing # if V is unset or not 1, $(summary) echoes a summary VERBOSE ?= V ?= $(VERBOSE) ifeq ("$(V)","1") -export summary := @true + export summary := @true else -export summary := @echo - -# disable echoing of commands, directory names -MAKEFLAGS += --silent -w + export summary := @echo + # disable echoing of commands, directory names + MAKEFLAGS += --silent -w endif # $(V)==1 ifndef BAUDRATE @@ -49,9 +60,34 @@ endif ############################################################# # Select compile # -ifeq ($(OS),Windows_NT) -# WIN32 -# We are under windows. +# ** HEALTH WARNING ** This section is largely legacy directives left over from +# an Espressif template. As far as I (TerrryE) know, we've only used the Linux +# Path. I have successfully build AMD and Intel (both x86, AMD64) and RPi ARM6 +# all under Ubuntu. Our docker container runs on Windows in an Ubuntu VM. +# Johny Mattson maintains a prebuild AMD64 xtensa cross-compile gcc v4.8.5 +# toolchain which is compatible with the non-OS SDK and can be used on any recent +# Ubuntu version including the Docker and Travis build environments. +# +# You have the option to build your own toolchain and specify a TOOLCHAIN_ROOT +# environment variable (see https://github.com/pfalcon/esp-open-sdk). If your +# architecture is compatable then you can omit this variable and the make will +# download and use this prebuilt toolchain. +# +# If any developers wish to develop, test and support alternative environments +# then please raise a GitHub issue on this work. +# + +ifndef $(OS) + # Assume Windows if MAKE_HOST contains "indows" and Linux otherwise + ifneq (,$(findstring indows,$(MAKE_HOST))) + OS := windows + else + OS := linux + endif +endif + +ifneq (,$(findstring indows,$(OS))) + #------------ BEGIN UNTESTED ------------ We are not under Linux, e.g.under windows. ifeq ($(XTENSA_CORE),lx106) # It is xcc AR = xt-ar @@ -85,58 +121,54 @@ ifeq ($(OS),Windows_NT) ifeq ($(PROCESSOR_ARCHITECTURE),x86) # ->IA32 endif + #---------------- END UNTESTED ---------------- We are under windows. else -# We are under other system, may be Linux. Assume using gcc. - # Can we use -fdata-sections? - PLATFORM:=linux-x86_64 + # We are under other system, may be Linux. Assume using gcc. + + UNAME_S := $(shell uname -s) + UNAME_P := $(shell uname -p) + ifeq ($(OS),linux) + ifndef TOOLCHAIN_ROOT + TOOLCHAIN_VERSION = 20181106.0 + GCCTOOLCHAIN = linux-x86_64-$(TOOLCHAIN_VERSION) + TOOLCHAIN_ROOT = $(TOP_DIR)/tools/toolchains/esp8266-$(GCCTOOLCHAIN) + GITHUB_TOOLCHAIN = https://github.com/jmattsson/esp-toolchains + export PATH:=$(PATH):$(TOOLCHAIN_ROOT)/bin + endif + endif + ifndef COMPORT ESPPORT = /dev/ttyUSB0 else ESPPORT = $(COMPORT) endif - export PATH := $(PATH):$(TOP_DIR)/tools/toolchains/esp8266-$(PLATFORM)-$(TOOLCHAIN_VERSION)/bin/ + CCFLAGS += -ffunction-sections -fno-jump-tables -fdata-sections - AR = xtensa-lx106-elf-ar - CC = $(WRAPCC) xtensa-lx106-elf-gcc - CXX = $(WRAPCC) xtensa-lx106-elf-g++ - NM = xtensa-lx106-elf-nm - CPP = $(WRAPCC) xtensa-lx106-elf-gcc -E + AR = xtensa-lx106-elf-ar + CC = $(WRAPCC) xtensa-lx106-elf-gcc + CXX = $(WRAPCC) xtensa-lx106-elf-g++ + NM = xtensa-lx106-elf-nm + CPP = $(WRAPCC) xtensa-lx106-elf-gcc -E OBJCOPY = xtensa-lx106-elf-objcopy FIRMWAREDIR = ../bin/ WGET = wget --tries=10 --timeout=15 --waitretry=30 --read-timeout=20 --retry-connrefused - UNAME_S := $(shell uname -s) - ifeq ($(UNAME_S),Linux) -# LINUX - endif - ifeq ($(UNAME_S),Darwin) -# OSX - endif - UNAME_P := $(shell uname -p) - ifeq ($(UNAME_P),x86_64) -# ->AMD64 - endif - ifneq ($(filter %86,$(UNAME_P)),) -# ->IA32 - endif - ifneq ($(filter arm%,$(UNAME_P)),) -# ->ARM - endif endif -############################################################# -GITHUB_TOOLCHAIN = https://github.com/jmattsson/esp-toolchains GITHUB_SDK = https://github.com/espressif/ESP8266_NONOS_SDK GITHUB_ESPTOOL = https://github.com/espressif/esptool ESPTOOL ?= $(TOP_DIR)/tools/toolchains/esptool.py -CSRCS ?= $(wildcard *.c) -CXXSRCS ?= $(wildcard *.cpp) -ASRCs ?= $(wildcard *.s) -ASRCS ?= $(wildcard *.S) SUBDIRS ?= $(patsubst %/,%,$(dir $(filter-out tools/Makefile,$(wildcard */Makefile)))) -ODIR := .output +ODIR := .output + +ifdef TARGET +CSRCS ?= $(wildcard *.c) +CXXSRCS ?= $(wildcard *.cpp) +ASRCs ?= $(wildcard *.s) +ASRCS ?= $(wildcard *.S) + OBJODIR := $(ODIR)/$(TARGET)/$(FLAVOR)/obj OBJS := $(CSRCS:%.c=$(OBJODIR)/%.o) \ @@ -159,19 +191,19 @@ BINODIR := $(ODIR)/$(TARGET)/$(FLAVOR)/bin OBINS := $(GEN_BINS:%=$(BINODIR)/%) ifndef PDIR -ifneq ($(wildcard $(TOP_DIR)/local/fs/*),) -SPECIAL_MKTARGETS += spiffs-image -else -SPECIAL_MKTARGETS += spiffs-image-remove + ifneq ($(wildcard $(TOP_DIR)/local/fs/*),) + SPECIAL_MKTARGETS += spiffs-image + else + SPECIAL_MKTARGETS += spiffs-image-remove + endif endif -endif - +endif # TARGET # # Note: # https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html -# If you add global optimize options like "-O2" here -# they will override "-Os" defined above. -# "-Os" should be used to reduce code size +# If you add global optimize options then they will override "-Os" defined above. +# Note that "-Os" should NOT be used to reduce code size because of the runtime +# impact of the extra non-aligned exception burdon. # CCFLAGS += \ -g \ @@ -193,6 +225,8 @@ DFLAGS = $(CCFLAGS) $(DDEFINES) $(EXTRA_CCFLAGS) $(STD_CFLAGS) $(INCLUDES) # Functions # +ifdef TARGET + define ShortcutRule $(1): .subdirs $(2)/$(1) endef @@ -225,39 +259,46 @@ $(BINODIR)/%.bin: $(IMAGEODIR)/%.out $(summary) ESPTOOL $(patsubst $(TOP_DIR)/%,%,$(CURDIR))/$< $(FIRMWAREDIR) $(ESPTOOL) elf2image --flash_mode dio --flash_freq 40m $< -o $(FIRMWAREDIR) +endif # TARGET ############################################################# # Rules base # Should be done in top-level makefile only # -all: toolchain sdk_pruned pre_build .subdirs $(OBJS) $(OLIBS) $(OIMAGES) $(OBINS) $(SPECIAL_MKTARGETS) +ifndef TARGET +all: toolchain sdk_pruned pre_build .subdirs +else +all: .subdirs $(OBJS) $(OLIBS) $(OIMAGES) $(OBINS) $(SPECIAL_MKTARGETS) +endif .PHONY: sdk_extracted .PHONY: sdk_pruned .PHONY: toolchain -sdk_extracted: $(TOP_DIR)/sdk/.extracted-$(SDK_BASE_VER) -sdk_pruned: $(SDK_DIR_DEPENDS) $(TOP_DIR)/sdk/.pruned-$(SDK_VER) +sdk_extracted: $(TOP_DIR)/sdk/.extracted-$(SDK_VER) +sdk_pruned: sdk_extracted toolchain $(TOP_DIR)/sdk/.pruned-$(SDK_VER) -ifeq ($(OS),Windows_NT) -toolchain: -else -toolchain: $(TOP_DIR)/tools/toolchains/esp8266-$(PLATFORM)-$(TOOLCHAIN_VERSION)/bin/xtensa-lx106-elf-gcc $(TOP_DIR)/tools/toolchains/esptool.py +ifdef GITHUB_TOOLCHAIN + TOOLCHAIN_ROOT := $(TOP_DIR)/tools/toolchains/esp8266-linux-x86_64-$(TOOLCHAIN_VERSION) + +toolchain: $(TOOLCHAIN_ROOT)/bin $(ESPTOOL) -$(TOP_DIR)/tools/toolchains/esp8266-$(PLATFORM)-$(TOOLCHAIN_VERSION)/bin/xtensa-lx106-elf-gcc: $(TOP_DIR)/cache/toolchain-esp8266-$(PLATFORM)-$(TOOLCHAIN_VERSION).tar.xz +$(TOOLCHAIN_ROOT)/bin: $(TOP_DIR)/cache/toolchain-esp8266-$(GCCTOOLCHAIN).tar.xz mkdir -p $(TOP_DIR)/tools/toolchains/ $(summary) EXTRACT $(patsubst $(TOP_DIR)/%,%,$<) tar -xJf $< -C $(TOP_DIR)/tools/toolchains/ touch $@ -$(TOP_DIR)/cache/toolchain-esp8266-$(PLATFORM)-$(TOOLCHAIN_VERSION).tar.xz: +$(TOP_DIR)/cache/toolchain-esp8266-$(GCCTOOLCHAIN).tar.xz: mkdir -p $(TOP_DIR)/cache $(summary) WGET $(patsubst $(TOP_DIR)/%,%,$@) - $(WGET) $(GITHUB_TOOLCHAIN)/releases/download/$(PLATFORM)-$(TOOLCHAIN_VERSION)/toolchain-esp8266-$(PLATFORM)-$(TOOLCHAIN_VERSION).tar.xz -O $@ \ + $(WGET) $(GITHUB_TOOLCHAIN)/releases/download/$(GCCTOOLCHAIN)/toolchain-esp8266-$(GCCTOOLCHAIN).tar.xz -O $@ \ || { rm -f "$@"; exit 1; } +else +toolchain: $(ESPTOOL) endif -$(TOP_DIR)/tools/toolchains/esptool.py: $(TOP_DIR)/cache/esptool/v$(ESPTOOL_VER).tar.gz +$(ESPTOOL): $(TOP_DIR)/cache/esptool/v$(ESPTOOL_VER).tar.gz mkdir -p $(TOP_DIR)/tools/toolchains/ tar -C $(TOP_DIR)/tools/toolchains/ -xzf $< --strip-components=1 esptool-$(ESPTOOL_VER)/esptool.py chmod +x $@ @@ -267,31 +308,32 @@ $(TOP_DIR)/cache/esptool/v$(ESPTOOL_VER).tar.gz: mkdir -p $(TOP_DIR)/cache/esptool/ $(WGET) $(GITHUB_ESPTOOL)/archive/v$(ESPTOOL_VER).tar.gz -O $@ || { rm -f "$@"; exit 1; } -$(TOP_DIR)/sdk/.extracted-$(SDK_BASE_VER): $(TOP_DIR)/cache/v$(SDK_FILE_VER).zip +$(TOP_DIR)/sdk/.extracted-$(SDK_VER): $(TOP_DIR)/cache/$(SDK_FILE_VER).zip mkdir -p "$(dir $@)" $(summary) UNZIP $(patsubst $(TOP_DIR)/%,%,$<) (cd "$(dir $@)" && \ - rm -fr esp_iot_sdk_v$(SDK_VER) ESP8266_NONOS_SDK-$(SDK_BASE_VER) && \ - unzip $(TOP_DIR)/cache/v$(SDK_FILE_VER).zip \ - 'ESP8266_NONOS_SDK-$(SDK_BASE_VER)/lib/*' \ - 'ESP8266_NONOS_SDK-$(SDK_BASE_VER)/ld/*.v6.ld' \ - 'ESP8266_NONOS_SDK-$(SDK_BASE_VER)/include/*' \ - 'ESP8266_NONOS_SDK-$(SDK_BASE_VER)/bin/esp_init_data_default_v05.bin' \ + rm -fr esp_iot_sdk_v$(SDK_VER) ESP8266_NONOS_SDK-* && \ + unzip $(TOP_DIR)/cache/$(SDK_FILE_VER).zip \ + '$(SDK_ZIP_ROOT)/lib/*' \ + '$(SDK_ZIP_ROOT)/ld/*.v6.ld' \ + '$(SDK_ZIP_ROOT)/include/*' \ + '$(SDK_ZIP_ROOT)/bin/esp_init_data_default_v05.bin' \ ) - mv $(dir $@)/ESP8266_NONOS_SDK-$(SDK_BASE_VER) $(dir $@)/esp_iot_sdk_v$(SDK_BASE_VER) + mv $(dir $@)/$(SDK_ZIP_ROOT) $(dir $@)/esp_iot_sdk_v$(SDK_VER) touch $@ $(TOP_DIR)/sdk/.pruned-$(SDK_VER): rm -f $(SDK_DIR)/lib/liblwip.a $(SDK_DIR)/lib/libssl.a $(SDK_DIR)/lib/libmbedtls.a $(summary) PRUNE libmain.a libc.a + echo $(PATH) $(AR) d $(SDK_DIR)/lib/libmain.a time.o $(AR) d $(SDK_DIR)/lib/libc.a lib_a-time.o touch $@ -$(TOP_DIR)/cache/v$(SDK_FILE_VER).zip: +$(TOP_DIR)/cache/$(SDK_FILE_VER).zip: mkdir -p "$(dir $@)" $(summary) WGET $(patsubst $(TOP_DIR)/%,%,$@) - $(WGET) $(GITHUB_SDK)/archive/v$(SDK_FILE_VER).zip -O $@ || { rm -f "$@"; exit 1; } + $(WGET) $(GITHUB_SDK)/archive/$(SDK_FILE_VER).zip -O $@ || { rm -f "$@"; exit 1; } (echo "$(SDK_FILE_SHA1) $@" | sha1sum -c -) || { rm -f "$@"; exit 1; } clean: @@ -329,15 +371,12 @@ endif .subdirs: @set -e; $(foreach d, $(SUBDIRS), $(MAKE) -C $(d);) -#.subdirs: -# $(foreach d, $(SUBDIRS), $(MAKE) -C $(d)) - ifneq ($(MAKECMDGOALS),clean) -ifneq ($(MAKECMDGOALS),clobber) -ifdef DEPS -sinclude $(DEPS) -endif -endif + ifneq ($(MAKECMDGOALS),clobber) + ifdef DEPS + sinclude $(DEPS) + endif + endif endif .PHONY: spiffs-image-remove @@ -365,6 +404,7 @@ pre_build: @-rm -f $(TOP_DIR)/app/modules/server-ca.crt.h endif +ifdef TARGET $(OBJODIR)/%.o: %.c @mkdir -p $(dir $@); $(summary) CC $(patsubst $(TOP_DIR)/%,%,$(CURDIR))/$< @@ -424,6 +464,7 @@ $(foreach lib,$(GEN_LIBS),$(eval $(call MakeLibrary,$(basename $(lib))))) $(foreach image,$(GEN_IMAGES),$(eval $(call MakeImage,$(basename $(image))))) +endif # TARGET ############################################################# # Recursion Magic - Don't touch this!! # diff --git a/app/include/user_config.h b/app/include/user_config.h index 56567880a6..4dfdaadd4c 100644 --- a/app/include/user_config.h +++ b/app/include/user_config.h @@ -41,9 +41,12 @@ // The Lua Flash Store (LFS) allows you to store Lua code in Flash memory and // the Lua VMS will execute this code directly from flash without needing any -// RAM overhead. Note that you should now configure LFS directly in the -// System Partition Table and not at build time. +// RAM overhead. You can now configure LFS directly in the System Partition +// Table insted of at compile time. However for backwards compatibility setting +// LUA_FLASH_STORE defines the default partition size if the NodeMCU partition +// tool is not used. +//#define LUA_FLASH_STORE 0x10000 // By default Lua executes the file init.lua at start up. The following // define allows you to replace this with an alternative startup. Warning: @@ -68,11 +71,14 @@ // general, limiting the size of the FS only to what your application needs // gives the fastest start-up and imaging times. -// Note that you should now configure SPIFFS size and position directly in the -// System Partition Table and not at build time. +// You can now configure SPIFFS size and position directly in the System +// Partition Table. However backwards compatibility SPIFFS_MAX_FILESYSTEM_SIZE +// can be set and this defines the default SPIFFS partition size if the NodeMCU +// partition tool is not used. The value (~0x0) means the maximum size remaining. #define BUILD_SPIFFS #define SPIFFS_CACHE 1 // Enable if you use you SPIFFS in R/W mode +//#define SPIFFS_MAX_FILESYSTEM_SIZE 0x20000 #define SPIFFS_MAX_OPEN_FILES 4 // maximum number of open files for SPIFFS #define FS_OBJ_NAME_LEN 31 // maximum length of a filename @@ -211,9 +217,14 @@ #define NODEMCU_SPIFFS0_PARTITION 6 #define NODEMCU_SPIFFS1_PARTITION 7 -#define LUA_FLASH_STORE 0x0 +#ifndef LUA_FLASH_STORE +# define LUA_FLASH_STORE 0x0 +#endif + #define SPIFFS_FIXED_LOCATION 0x0 -#define SPIFFS_MAX_FILESYSTEM_SIZE (~0x0) +#ifndef SPIFFS_MAX_FILESYSTEM_SIZE +# define SPIFFS_MAX_FILESYSTEM_SIZE 0xFFFFFFFF +#endif //#define SPIFFS_SIZE_1M_BOUNDARY #define LUA_TASK_PRIO USER_TASK_PRIO_0 diff --git a/app/include/user_modules.h b/app/include/user_modules.h index 2818ed7f16..6aa35b9630 100644 --- a/app/include/user_modules.h +++ b/app/include/user_modules.h @@ -7,7 +7,7 @@ // includes general purpose interface modules which require at most two GPIO pins. // See https://github.com/nodemcu/nodemcu-firmware/pull/1127 for discussions. // New modules should be disabled by default and added in alphabetical order. -#define LUA_USE_MODULES_ADC +//#define LUA_USE_MODULES_ADC //#define LUA_USE_MODULES_ADS1115 //#define LUA_USE_MODULES_ADXL345 //#define LUA_USE_MODULES_AM2320 @@ -21,22 +21,22 @@ //#define LUA_USE_MODULES_COLOR_UTILS //#define LUA_USE_MODULES_CRON //#define LUA_USE_MODULES_CRYPTO -#define LUA_USE_MODULES_DHT +//#define LUA_USE_MODULES_DHT //#define LUA_USE_MODULES_ENCODER //#define LUA_USE_MODULES_ENDUSER_SETUP // USE_DNS in dhcpserver.h needs to be enabled for this module to work. #define LUA_USE_MODULES_FILE -//#define LUA_USE_MODULES_GDBSTUB -#define LUA_USE_MODULES_GPIO +#define LUA_USE_MODULES_GDBSTUB +//#define LUA_USE_MODULES_GPIO //#define LUA_USE_MODULES_GPIO_PULSE //#define LUA_USE_MODULES_HDC1080 //#define LUA_USE_MODULES_HMC5883L //#define LUA_USE_MODULES_HTTP //#define LUA_USE_MODULES_HX711 -#define LUA_USE_MODULES_I2C +//#define LUA_USE_MODULES_I2C //#define LUA_USE_MODULES_L3G4200D //#define LUA_USE_MODULES_MCP4725 //#define LUA_USE_MODULES_MDNS -#define LUA_USE_MODULES_MQTT +//#define LUA_USE_MODULES_MQTT #define LUA_USE_MODULES_NET #define LUA_USE_MODULES_NODE #define LUA_USE_MODULES_OW @@ -54,7 +54,7 @@ //#define LUA_USE_MODULES_SJSON //#define LUA_USE_MODULES_SNTP //#define LUA_USE_MODULES_SOMFY -#define LUA_USE_MODULES_SPI +//#define LUA_USE_MODULES_SPI //#define LUA_USE_MODULES_SQLITE3 //#define LUA_USE_MODULES_STRUCT //#define LUA_USE_MODULES_SWITEC diff --git a/app/libc/c_string.h b/app/libc/c_string.h index 22d44b7168..cced15bacc 100644 --- a/app/libc/c_string.h +++ b/app/libc/c_string.h @@ -15,6 +15,7 @@ #define c_memcmp os_memcmp #define c_memcpy os_memcpy +#define c_memmove os_memmove #define c_memset os_memset #define c_strcat os_strcat diff --git a/app/modules/file.c b/app/modules/file.c index d1de588c0f..f9ae816e37 100644 --- a/app/modules/file.c +++ b/app/modules/file.c @@ -435,7 +435,7 @@ static int file_g_read( lua_State* L, int n, int16_t end_char, int fd ) int nread = vfs_read(fd, p, nwanted); if (nread == VFS_RES_ERR || nread == 0) { - lua_pushnil(L); + lua_pushnil(L); return 1; } @@ -495,19 +495,19 @@ static int file_readline( lua_State* L ) static int file_getfile( lua_State* L ) { // Warning this code C calls other file_* routines to avoid duplication code. These - // use Lua stack addressing of arguments, so this does Lua stack maniplation to + // use Lua stack addressing of arguments, so this does Lua stack maniplation to // align these int ret_cnt = 0; lua_settop(L ,1); // Stack [1] = FD - file_open(L); + file_open(L); // Stack [1] = filename; [2] = FD or nil if (!lua_isnil(L, -1)) { lua_remove(L, 1); // dump filename, so [1] = FD file_fd_ud *ud = (file_fd_ud *)luaL_checkudata(L, 1, "file.obj"); - ret_cnt = file_g_read(L, LUAI_MAXINT32, EOF, ud->fd); - // Stack [1] = FD; [2] = contents if ret_cnt = 1; - file_close(L); // leaves Stack unchanged if [1] = FD + ret_cnt = file_g_read(L, LUAI_MAXINT32, EOF, ud->fd); + // Stack [1] = FD; [2] = contents if ret_cnt = 1; + file_close(L); // leaves Stack unchanged if [1] = FD lua_remove(L, 1); // Dump FD leaving contents as [1] / ToS } return ret_cnt; @@ -557,23 +557,23 @@ static int file_writeline( lua_State* L ) static int file_putfile( lua_State* L ) { // Warning this code C calls other file_* routines to avoid duplication code. These - // use Lua stack addressing of arguments, so this does Lua stack maniplation to + // use Lua stack addressing of arguments, so this does Lua stack maniplation to // align these int ret_cnt = 0; lua_settop(L, 2); lua_pushvalue(L, 2); //dup contents onto the ToS [3] lua_pushliteral(L, "w+"); lua_replace(L, 2); - // Stack [1] = filename; [2] "w+" [3] contents; - file_open(L); - // Stack [1] = filename; [2] "w+" [3] contents; [4] FD or nil + // Stack [1] = filename; [2] "w+" [3] contents; + file_open(L); + // Stack [1] = filename; [2] "w+" [3] contents; [4] FD or nil if (!lua_isnil(L, -1)) { lua_remove(L, 2); //dump "w+" attribute literal lua_replace(L, 1); - // Stack [1] = FD; [2] contents + // Stack [1] = FD; [2] contents file_write(L); - // Stack [1] = FD; [2] contents; [3] result status + // Stack [1] = FD; [2] contents; [3] result status lua_remove(L, 2); //dump contents file_close(L); lua_remove(L, 1); // Dump FD leaving status as ToS diff --git a/app/modules/node.c b/app/modules/node.c index 7094c5394d..c4285605dc 100644 --- a/app/modules/node.c +++ b/app/modules/node.c @@ -1,5 +1,4 @@ // Module for interfacing with system - #include "module.h" #include "lauxlib.h" @@ -572,6 +571,177 @@ static int node_random (lua_State *L) { return 1; } +#ifdef DEVELOPMENT_TOOLS +// Lua: rec = node.readrcr(id) +static int node_readrcr (lua_State *L) { + int id = luaL_checkinteger(L, 1); + char *data; + int n = platform_rcr_read(id, (void **)&data); + if (n == ~0) return 0; + lua_pushlstring(L, data, n); + return 1; +} +// Lua: n = node.writercr(id,rec) +static int node_writercr (lua_State *L) { + int id = luaL_checkinteger(L, 1),l; + const char *data = lua_tolstring(L, 2, &l); + int n = platform_rcr_write(id, data, l); + lua_pushinteger(L, n); + return 1; +} +#endif + +typedef enum pt_t { lfs_addr=0, lfs_size, spiffs_addr, spiffs_size, max_pt} pt_t; + +static const LUA_REG_TYPE pt_map[] = { + { LSTRKEY( "lfs_addr" ), LNUMVAL( lfs_addr ) }, + { LSTRKEY( "lfs_size" ), LNUMVAL( lfs_size ) }, + { LSTRKEY( "spiffs_addr" ), LNUMVAL( spiffs_addr ) }, + { LSTRKEY( "spiffs_size" ), LNUMVAL( spiffs_size ) }, + { LNILKEY, LNILVAL } +}; + +// Lua: ptinfo = node.getpartitiontable() +static int node_getpartitiontable (lua_State *L) { + uint32_t param[max_pt] = {0}; + param[lfs_size] = platform_flash_get_partition(NODEMCU_LFS0_PARTITION, param + lfs_addr); + param[spiffs_size] = platform_flash_get_partition(NODEMCU_SPIFFS0_PARTITION, param + spiffs_addr); + + lua_settop(L, 0); + lua_createtable (L, 0, max_pt); /* at index 1 */ + lua_pushrotable(L, (void*)pt_map); /* at index 2 */ + lua_pushnil(L); /* first key at index 3 */ + while (lua_next(L, 2) != 0) { /* key at index 3, and v at index 4 */ + lua_pushvalue(L, 3); /* dup key to index 5 */ + lua_pushinteger(L, param[lua_tointeger(L, 4)]); /* param [v] at index 6 */ + lua_rawset(L, 1); + lua_pop(L, 1); /* discard v */ + } + lua_pop(L, 1); /* discard pt_map reference */ + return 1; +} + +static void insert_partition(partition_item_t *p, int n, uint32_t type, uint32_t addr) { + if (n>0) + c_memmove(p+1, p, n*sizeof(partition_item_t)); /* overlapped so must be move not cpy */ + p->type = type; + p->addr = addr; + p->size = 0; +} + +static void delete_partition(partition_item_t *p, int n) { + if (n>0) + c_memmove(p, p+1, n*sizeof(partition_item_t)); /* overlapped so must be move not cpy */ +} + +#define SKIP (~0) +#define IROM0_PARTITION (SYSTEM_PARTITION_CUSTOMER_BEGIN + NODEMCU_IROM0TEXT_PARTITION) +#define LFS_PARTITION (SYSTEM_PARTITION_CUSTOMER_BEGIN + NODEMCU_LFS0_PARTITION) +#define SPIFFS_PARTITION (SYSTEM_PARTITION_CUSTOMER_BEGIN + NODEMCU_SPIFFS0_PARTITION) + +// Lua: node.setpartitiontable(pt_settings) +static int node_setpartitiontable (lua_State *L) { + partition_item_t *rcr_pt = NULL, *pt; + uint32_t flash_size = flash_rom_get_size_byte(); + uint32_t i = platform_rcr_read(PLATFORM_RCR_PT, (void **) &rcr_pt); + uint32_t last = 0; + uint32_t n = i / sizeof(partition_item_t); + uint32_t param[max_pt] = {SKIP, SKIP, SKIP, SKIP}; + + luaL_argcheck(L, lua_istable(L, 1), 1, "must be table"); + lua_settop(L, 1); + /* convert input table into 4 option array */ + lua_pushrotable(L, (void*)pt_map); /* at index 2 */ + lua_pushnil(L); /* first key at index 3 */ + while (lua_next(L, 1) != 0) { + /* 'key' (at index 3) and 'value' (at index 4) */ + luaL_argcheck(L, lua_isstring(L, 3) && lua_isnumber(L, 4), 1, "invalid partition setting"); + lua_pushvalue(L, 3); /* dup key to index 5 */ + lua_rawget(L, 2); /* lookup in pt_map */ + luaL_argcheck(L, !lua_isnil(L, -1), 1, "invalid partition setting"); + param[lua_tointeger(L, 5)] = lua_tointeger(L, 4); + /* removes 'value'; keeps 'key' for next iteration */ + lua_pop(L, 2); /* discard value and lookup */ + } + /* + * Allocate a scratch Partition Table as userdata on the Lua stack, and copy the + * current Flash PT into this for manipulation + */ + lua_newuserdata(L, (n+2)*sizeof(partition_item_t)); + pt = lua_touserdata (L, -1); + c_memcpy(pt, rcr_pt, n*sizeof(partition_item_t)); + pt[n].type = 0; pt[n+1].type = 0; + + for (i = 0; i < n; i ++) { + partition_item_t *p = pt + i; + + if (p->type == IROM0_PARTITION && p[1].type != LFS_PARTITION) { + // if the LFS partition is not following IROM0 then slot a blank one in + insert_partition(p + 1, n-i-1, LFS_PARTITION, p->addr + p->size); + n++; + + } else if (p->type == LFS_PARTITION) { + if (p[1].type != SPIFFS_PARTITION) { + // if the SPIFFS partition is not following LFS then slot a blank one in + insert_partition(p + 1, n-i-1, SPIFFS_PARTITION, 0); + n++; + } + // update the LFS options if set + if (param[lfs_addr] != SKIP) { + p->addr = param[lfs_addr]; + } + if (param[lfs_size] != SKIP) { + p->size = param[lfs_size]; + } + } else if (p->type == SPIFFS_PARTITION) { + // update the SPIFFS options if set + if (param[spiffs_addr] != SKIP) { + p->addr = param[spiffs_addr]; + p->size = SKIP; + } + if (param[spiffs_size] != SKIP) { + // BOTCH: - at the moment the firmware doesn't boot if the SPIFFS partition + // is deleted so the minimum SPIFFS size is 64Kb + p->size = param[spiffs_size] > 0x10000 ? param[spiffs_size] : 0x10000; + } + if (p->size == SKIP) { + if (p->addr < 0) { + // This allocate all the remaining flash to SPIFFS + p->addr = last; + p->size = flash_size - last; + } else { + p->size = flash_size - p->addr; + } + } else if (/* size is specified && */ p->addr == 0) { + // if the is addr not specified then start SPIFFS at 1Mb + // boundary if the size will fit otherwise make it consecutive + // to the previous partition. + p->addr = (p->size <= flash_size - 0x100000) ? 0x100000 : last; + } + } + + if (p->size == 0) { + // Delete 0-sized partitions as the SDK barfs on these + delete_partition(p, n-i-1); + n--; i--; + } else { + // Do consistency tests on the partition + if (p->addr & (INTERNAL_FLASH_SECTOR_SIZE - 1) || + p->size & (INTERNAL_FLASH_SECTOR_SIZE - 1) || + p->addr < last || + p->addr + p->size > flash_size) { + luaL_error(L, "value out of range"); + } + } + } +// for (i = 0; i < n; i ++) +// dbg_printf("Partition %d: %04x %06x %06x\n", i, pt[i].type, pt[i].addr, pt[i].size); + platform_rcr_write(PLATFORM_RCR_PT, pt, n*sizeof(partition_item_t)); + while(1); // Trigger WDT; the new PT will be loaded on reboot + + return 0; +} + // Module function map @@ -605,6 +775,10 @@ static const LUA_REG_TYPE node_map[] = { LSTRKEY( "sleep" ), LFUNCVAL( node_sleep ) }, #ifdef PMSLEEP_ENABLE PMSLEEP_INT_MAP, +#endif +#ifdef DEVELOPMENT_TOOLS + { LSTRKEY( "readrcr" ), LFUNCVAL( node_readrcr ) }, + { LSTRKEY( "writercr" ), LFUNCVAL( node_writercr ) }, #endif { LSTRKEY( "chipid" ), LFUNCVAL( node_chipid ) }, { LSTRKEY( "flashid" ), LFUNCVAL( node_flashid ) }, @@ -628,6 +802,8 @@ static const LUA_REG_TYPE node_map[] = #ifdef DEVELOPMENT_TOOLS { LSTRKEY( "osprint" ), LFUNCVAL( node_osprint ) }, #endif + { LSTRKEY( "getpartitiontable" ), LFUNCVAL( node_getpartitiontable ) }, + { LSTRKEY( "setpartitiontable" ), LFUNCVAL( node_setpartitiontable ) }, // Combined to dsleep(us, option) // { LSTRKEY( "dsleepsetoption" ), LFUNCVAL( node_deepsleep_setoption) }, diff --git a/app/platform/platform.c b/app/platform/platform.c index 0fdc66d846..cec211f59e 100644 --- a/app/platform/platform.c +++ b/app/platform/platform.c @@ -903,10 +903,10 @@ uint32_t platform_s_flash_read( void *to, uint32_t fromaddr, uint32_t size ) r = flash_read(fromaddr, to2, size2); if(SPI_FLASH_RESULT_OK == r) { - os_memmove(to,to2,size2); + c_memmove(to,to2,size2); // This is overlapped so must be memmove and not memcpy char back[ INTERNAL_FLASH_READ_UNIT_SIZE ] __attribute__ ((aligned(INTERNAL_FLASH_READ_UNIT_SIZE))); r=flash_read(fromaddr+size2,(uint32*)back,INTERNAL_FLASH_READ_UNIT_SIZE); - os_memcpy((uint8_t*)to+size2,back,INTERNAL_FLASH_READ_UNIT_SIZE); + c_memcpy((uint8_t*)to+size2,back,INTERNAL_FLASH_READ_UNIT_SIZE); } } else @@ -936,7 +936,7 @@ static uint32_t flash_map_meg_offset (void) { return m0 + m1; } -uint32_t platform_flash_mapped2phys (uint32_t mapped_addr) { +uint32_t platform_flash_mapped2phys (uint32_t mapped_addr) { uint32_t meg = flash_map_meg_offset(); return (meg&1) ? -1 : mapped_addr - INTERNAL_FLASH_MAPPED_ADDRESS + meg ; } @@ -946,7 +946,7 @@ uint32_t platform_flash_phys2mapped (uint32_t phys_addr) { return (meg&1) ? -1 : phys_addr + INTERNAL_FLASH_MAPPED_ADDRESS - meg; } -uint32_t platform_flash_get_partition (uint32_t part_id, uint32_t *addr) { +uint32_t platform_flash_get_partition (uint32_t part_id, uint32_t *addr) { partition_item_t pt = {0,0,0}; system_partition_get_item(SYSTEM_PARTITION_CUSTOMER_BEGIN + part_id, &pt); if (addr) { @@ -954,6 +954,127 @@ uint32_t platform_flash_get_partition (uint32_t part_id, uint32_t *addr) { } return pt.type == 0 ? 0 : pt.size; } +/* + * The Reboot Config Records are stored in the 4K flash page at offset 0x10000 (in + * the linker section .irom0.ptable) and is used for configuration changes that + * persist across reboots. This page contains a sequence of records, each of which + * is word-aligned and comprises a header and body of length 0-64 words. The 4-byte + * header comprises a length, a RCR id, and two zero fill bytes. These are written + * using flash NAND writing rules, so any unused area (all 0xFF) can be overwritten + * by a new record without needing to erase the RCR page. Ditto any existing + * record can be marked as deleted by over-writing the header with the id set to + * PLATFORM_RCR_DELETED (0x0). Note that the last word is not used additions so a + * scan for PLATFORM_RCR_FREE will always terminate. + * + * The number of updates is extremely low, so it is unlikely (but possible) that + * the page might fill with the churn of new RCRs, so in this case the write function + * compacts the page by eliminating all deleted records. This does require a flash + * sector erase. + * + * NOTE THAT THIS ALGO ISN'T 100% ROBUST, eg. a powerfail between the erase and the + * wite-back will leave the page unitialised; ditto a powerfail between the record + * appned and old deletion will leave two records. However this is better than the + * general integrity of SPIFFS, for example and the vulnerable window is typically + * less than 1 mSec every configuration change. + */ +extern uint32_t _irom0_text_start[]; +#define RCR_WORD(i) (_irom0_text_start[i]) +#define WORDSIZE sizeof(uint32_t) +#define FLASH_SECTOR_WORDS (INTERNAL_FLASH_SECTOR_SIZE/WORDSIZE) + +uint32_t platform_rcr_read (uint8_t rec_id, void **rec) { +//DEBUG os_printf("platform_rcr_read(%d,%08x)\n",rec_id,rec); + platform_rcr_t *rcr = (platform_rcr_t *) &RCR_WORD(0); + uint32_t i = 0; + /* + * Chain down the RCR page looking for a record that matches the record + * ID. If found return the size of the record and optionally its address. + */ + while (1) { + // copy RCR header into RAM to avoid unaligned exceptions + platform_rcr_t r = (platform_rcr_t) RCR_WORD(i); + if (r.id == rec_id) { + if (rec) *rec = &RCR_WORD(i+1); + return r.len * WORDSIZE; + } else if (r.id == PLATFORM_RCR_FREE) { + break; + } + i += 1 + r.len; + } + return ~0; +} + +/* + * Chain down the RCR page and look for an existing record that matches the record + * ID and the first free record. If there is enough room, then append the new + * record and mark any previous record as deleted. If the page is full then GC, + * erase the page and rewrite with the GCed content. + */ +#define MAXREC 65 +uint32_t platform_rcr_write (uint8_t rec_id, const void *inrec, uint8_t n) { + uint32_t nwords = (n+WORDSIZE-1) / WORDSIZE; + uint32_t reclen = (nwords+1)*WORDSIZE; + uint32_t *prev=NULL, *new = NULL; + + // make local stack copy of inrec including header and any trailing fill bytes + uint32_t rec[MAXREC]; + if (nwords >= MAXREC) + return ~0; + rec[0] = 0; rec[nwords] = 0; + ((platform_rcr_t *) rec)->id = rec_id; + ((platform_rcr_t *) rec)->len = nwords; + c_memcpy(rec+1, inrec, n); // let memcpy handle 0 and odd byte cases + + // find previous copy if any and exit if the replacement is the same value + uint8_t np = platform_rcr_read (rec_id, (void **) &prev); + if (prev && !os_memcmp(prev-1, rec, reclen)) + return n; + + // find next free slot + platform_rcr_read (PLATFORM_RCR_FREE, (void **) &new); + uint32_t nfree = &RCR_WORD(FLASH_SECTOR_WORDS) - new; + + // Is there enough room to fit the rec in the RCR page? + if (nwords < nfree) { // Note inequality needed to leave at least one all set word + uint32_t addr = platform_flash_mapped2phys((uint32_t)&new[-1]); + platform_s_flash_write(rec, addr, reclen); + + if (prev) { // If a previous exists, then overwrite the hdr as DELETED + platform_rcr_t rcr = {0}; + addr = platform_flash_mapped2phys((uint32_t)&prev[-1]); + rcr.id = PLATFORM_RCR_DELETED; rcr.len = np/WORDSIZE; + platform_s_flash_write(&rcr, addr, WORDSIZE); + } + + } else { + platform_rcr_t *rcr = (platform_rcr_t *) &RCR_WORD(0), newrcr = {0}; + uint32_t flash_addr = platform_flash_mapped2phys((uint32_t)&RCR_WORD(0)); + uint32_t *buf, i, l, pass; + + for (pass = 1; pass <= 2; pass++) { + for (i = 0, l = 0; i < FLASH_SECTOR_WORDS - nfree; ) { + platform_rcr_t r = rcr[i]; // again avoid unaligned exceptions + if (r.id == PLATFORM_RCR_FREE) + break; + if (r.id != PLATFORM_RCR_DELETED && r.id != rec_id) { + if (pass == 2) memcpy(buf + l, rcr + i, (r.len + 1)*WORDSIZE); + l += r.len + 1; + } + i += r.len + 1; + } + if (pass == 2) memcpy(buf + l, rec, reclen); + l += nwords + 1; + if (pass == 1) buf = c_malloc(l * WORDSIZE); + + if (l >= FLASH_SECTOR_WORDS || !buf) + return ~0; + } + platform_flash_erase_sector(flash_addr/INTERNAL_FLASH_SECTOR_SIZE); + platform_s_flash_write(buf, flash_addr, l*WORDSIZE); + c_free(buf); + } + return nwords*WORDSIZE; +} void* platform_print_deprecation_note( const char *msg, const char *time_frame) { diff --git a/app/platform/platform.h b/app/platform/platform.h index 3897f4f489..4350b5f403 100644 --- a/app/platform/platform.h +++ b/app/platform/platform.h @@ -291,13 +291,6 @@ uint32_t platform_flash_mapped2phys (uint32_t mapped_addr); uint32_t platform_flash_phys2mapped (uint32_t phys_addr); uint32_t platform_flash_get_partition (uint32_t part_id, uint32_t *addr); -// ***************************************************************************** -// Allocator support - -void* platform_get_first_free_ram( unsigned id ); -void* platform_get_last_free_ram( unsigned id ); - - // ***************************************************************************** // Other glue @@ -324,4 +317,40 @@ void* platform_print_deprecation_note( const char *msg, const char *time_frame); if( !platform_ ## mod ## _check_ ## resmod ## _id( id, resid ) )\ return luaL_error( L, #resmod" %d not valid with " #mod " %d", ( unsigned )resid, ( unsigned )id ) +// ***************************************************************************** +// Reboot config page +/* + * The 4K flash page in the linker section .irom0.ptable (offset 0x10000) is used + * for configuration changes that persist across reboots. This 4k page contains a + * sequence of records that are written using flash NAND writing rules. See the + * header app/spiffs/spiffs_nucleus.h for a discussion of how SPIFFS uses these. A + * similar technique is used here. + * + * Each record is word aligned and the first two bytes of the record are its size + * and record type. Type 0xFF means unused and type 0x00 means deleted. New + * records can be added by overwriting the first unused slot. Records can be + * replaced by adding the new version, then setting the type of the previous version + * to deleted. This all works and can be implemented with platform_s_flash_write() + * upto the 4K limit. + * + * If a new record cannot fit into the page then the deleted records are GCed by + * copying the active records into a RAM scratch pad, erasing the page and writing + * them back. Yes, this is powerfail unsafe for a few mSec, but this is no worse + * than writing to SPIFFS and won't even occur in normal production use. + */ +#define IROM_PTABLE_ATTR __attribute__((section(".irom0.ptable"))) +#define PLATFORM_PARTITION(n) (SYSTEM_PARTITION_CUSTOMER_BEGIN + n) +#define PLATFORM_RCR_DELETED 0x0 +#define PLATFORM_RCR_PT 0x1 +#define PLATFORM_RCR_PHY_DATA 0x2 +#define PLATFORM_RCR_REFLASH 0x3 +#define PLATFORM_RCR_FREE 0xFF +typedef union { + uint32_t hdr; + struct { uint8_t len,id; }; +} platform_rcr_t; + +uint32_t platform_rcr_read (uint8_t rec_id, void **rec); +uint32_t platform_rcr_write (uint8_t rec_id, const void *rec, uint8_t size); + #endif diff --git a/app/user/user_main.c b/app/user/user_main.c index c3be30302f..9f80fb9b82 100644 --- a/app/user/user_main.c +++ b/app/user/user_main.c @@ -33,43 +33,66 @@ static task_handle_t input_sig; static uint8 input_sig_flag = 0; /* Contents of esp_init_data_default.bin */ -extern const uint32_t init_data[]; -extern const uint32_t init_data_end[]; +extern const uint32_t init_data[], init_data_end[]; +#define INIT_DATA_SIZE ((init_data_end - init_data)*sizeof(uint32_t)) __asm__( ".align 4\n" "init_data: .incbin \"" ESP_INIT_DATA_DEFAULT "\"\n" "init_data_end:\n" ); -extern const char _irom0_text_start[], _irom0_text_end[],_flash_used_end[]; +extern const char _irom0_text_start[], _irom0_text_end[], _flash_used_end[]; #define IROM0_SIZE (_irom0_text_end - _irom0_text_start) -#define INIT_DATA_SIZE (init_data_end - init_data) #define PRE_INIT_TEXT_ATTR __attribute__((section(".p3.pre_init"))) #define IROM_PTABLE_ATTR __attribute__((section(".irom0.ptable"))) +#define USED_ATTR __attribute__((used)) #define PARTITION(n) (SYSTEM_PARTITION_CUSTOMER_BEGIN + n) #define SIZE_256K 0x00040000 #define SIZE_1024K 0x00100000 +#define PT_CHUNK 0x00002000 +#define PT_ALIGN(n) ((n + (PT_CHUNK-1)) & (~((PT_CHUNK-1)))) #define FLASH_BASE_ADDR ((char *) 0x40200000) -//TODO: map the TLS server and client certs into NODEMCU_TLSCERT_PARTITION -const partition_item_t partition_init_table[] IROM_PTABLE_ATTR = { - { PARTITION(NODEMCU_EAGLEROM_PARTITION), 0x00000, 0x0B000}, - { SYSTEM_PARTITION_RF_CAL, 0x0B000, 0x1000}, - { SYSTEM_PARTITION_PHY_DATA, 0x0C000, 0x1000}, - { SYSTEM_PARTITION_SYSTEM_PARAMETER, 0x0D000, 0x3000}, - { PARTITION(NODEMCU_IROM0TEXT_PARTITION), 0x10000, 0x0000}, - { PARTITION(NODEMCU_LFS0_PARTITION), 0x0, LUA_FLASH_STORE}, - { PARTITION(NODEMCU_SPIFFS0_PARTITION), 0x0, SPIFFS_MAX_FILESYSTEM_SIZE}, +#define NODEMCU_PARTITION_EAGLEROM PLATFORM_PARTITION(NODEMCU_EAGLEROM_PARTITION) +#define NODEMCU_PARTITION_IROM0TEXT PLATFORM_PARTITION(NODEMCU_IROM0TEXT_PARTITION) +#define NODEMCU_PARTITION_LFS PLATFORM_PARTITION(NODEMCU_LFS0_PARTITION) +#define NODEMCU_PARTITION_SPIFFS PLATFORM_PARTITION(NODEMCU_SPIFFS0_PARTITION) + +#define MAX_PARTITIONS 20 +#define WORDSIZE sizeof(uint32_t) +#define PTABLE_SIZE 7 /** THIS MUST BE MATCHED TO NO OF PT ENTRIES BELOW **/ +struct defaultpt { + platform_rcr_t hdr; + partition_item_t pt[PTABLE_SIZE+1]; // the +! is for the endmarker + }; +#define PT_LEN (NUM_PARTITIONS*sizeof(partition_item_t)) +/* + * See app/platform/platform.h for how the platform reboot config records are used + * and these records are allocated. The first record is a default partition table + * and this is statically declared in compilation below. + */ +static const struct defaultpt rompt IROM_PTABLE_ATTR USED_ATTR = { + .hdr = {.len = sizeof(struct defaultpt)/WORDSIZE - 1, + .id = PLATFORM_RCR_PT}, + .pt = { + { NODEMCU_PARTITION_EAGLEROM, 0x00000, 0x0B000}, + { SYSTEM_PARTITION_RF_CAL, 0x0B000, 0x1000}, + { SYSTEM_PARTITION_PHY_DATA, 0x0C000, 0x1000}, + { SYSTEM_PARTITION_SYSTEM_PARAMETER, 0x0D000, 0x3000}, + { NODEMCU_PARTITION_IROM0TEXT, 0x10000, 0x0000}, + { NODEMCU_PARTITION_LFS, 0x0, LUA_FLASH_STORE}, + { NODEMCU_PARTITION_SPIFFS, 0x0, SPIFFS_MAX_FILESYSTEM_SIZE}, {0,(uint32_t) &_irom0_text_end,0} + } }; -// The following enum must maintain the partition table order -enum partition {iram0=0, rf_call, phy_data, sys_parm, irom0, lfs, spiffs}; -#define PTABLE_SIZE ((sizeof(partition_init_table)/sizeof(partition_item_t))-1) -#define PT_CHUNK 0x8000 -#define PT_ALIGN(n) ((n + (PT_CHUNK-1)) & (~((PT_CHUNK-1)))) +//TODO: map the TLS server and client certs into NODEMCU_TLSCERT_PARTITION + +static uint32_t first_time_setup(partition_item_t *pt, uint32_t n, uint32_t flash_size); +static void phy_data_setup (partition_item_t *pt, uint32_t n); + /* * The non-OS SDK prolog has been fundamentally revised in V3. See SDK EN document * Partition Table.md for further discussion. This version of user_main.c is a @@ -77,118 +100,173 @@ enum partition {iram0=0, rf_call, phy_data, sys_parm, irom0, lfs, spiffs}; * * SDK V3 significantly reduces the RAM footprint required by the SDK and introduces * the use of a partition table (PT) to control flash allocation. The NodeMCU uses - * this PT for overall allocation of its flash resources. A constant copy PT is - * maintained at the start of IROM0 (flash offset 0x10000) -- see partition_init_table - * declaration above -- to facilitate its modification either in the firmware binary - * or in the flash itself. This is Flash PT used during startup to create the live PT - * in RAM that is used by the SDK. + * this PT for overall allocation of its flash resources. The non_OS SDK calls the + * user_pre_init() entry to do all of this startup configuration. Note that this + * runs with Icache enabled -- that is the IROM0 partition is already mapped the + * address space at 0x40210000 and so that most SDK services are available, such + * as system_get_flash_size_map() which returns the valid flash size (including the + * 8Mb and 16Mb variants). * - * Note that user_pre_init() runs with Icache enabled -- that is the IROM0 partition - * is already mapped the address space at 0x40210000 and so that most SDK services - * are available, such as system_get_flash_size_map() which returns the valid flash - * size (including the 8Mb and 16Mb variants). + * The first 4K page of IROM0 (flash offset 0x10000) is used to maintain a set of + * Resource Communication Records (RCR) for inter-boot configuration using a NAND + * write-once algo (see app/platform/platform.h). One of the current records is the + * SDK3.0 PT. This build statically compiles in an initial version at the start of + * the PT, with a {0, _irom0_text_end,0} marker as the last record and some fields + * also that need to be recomputed at runtime. This version is either replaced + * by first boot processing after provisioning, or by a node.setpartitiontable() + * API call. These replacement PTs are complete and can be passed directly for use + * by the non-OS SDK. * - * We will be separately releasing a host PC-base python tool to configure the PT, - * etc., but the following code will initialise the PT to sensible defaults even if - * this tool isn't used. + * Note that we have released a host PC-base python tool, nodemcu-partition.py, to + * configure the PT, etc during provisioning. */ -static int setup_partition_table(partition_item_t *pt, uint32_t *n) { - -// Flash size lookup is SIZE_256K*2^N where N is as follows (see SDK/user_interface.h) - static char flash_size_scaler[] = - /* 0 1 2 3 4 5 6 7 8 9 */ - /* ½M ¼M 1M 2M 4M 2M 4M 4M 8M 16M */ - "\001\000\002\003\004\003\004\004\005\006"; +void user_pre_init(void) { +#ifdef LUA_USE_MODULES_RTCTIME + // Note: Keep this as close to call_user_start() as possible, since it + // is where the cpu clock actually gets bumped to 80MHz. + rtctime_early_startup (); +#endif + partition_item_t *rcr_pt = NULL, *pt; enum flash_size_map fs_size_code = system_get_flash_size_map(); +// Flash size lookup is SIZE_256K*2^N where N is as follows (see SDK/user_interface.h) + /* 0 1 2 3 4 5 6 7 8 9 */ + /* ½M ¼M 1M 2M 4M 2M 4M 4M 8M 16M */ + static char flash_size_scaler[] = "\001\000\002\003\004\003\004\004\005\006"; uint32_t flash_size = SIZE_256K << flash_size_scaler[fs_size_code]; - uint32_t first_free_flash_addr = partition_init_table[PTABLE_SIZE].addr - - (uint32_t) FLASH_BASE_ADDR; - int i,j; - - os_memcpy(pt, partition_init_table, PTABLE_SIZE * sizeof(*pt)); + uint32_t i = platform_rcr_read(PLATFORM_RCR_PT, (void **) &rcr_pt); + uint32_t n = i / sizeof(partition_item_t); if (flash_size < SIZE_1024K) { os_printf("Flash size (%u) too small to support NodeMCU\n", flash_size); - return -1; + return; } else { os_printf("system SPI FI size:%u, Flash size: %u\n", fs_size_code, flash_size ); } -// Calculate the runtime sized partitions -// The iram0, rf_call, phy_data, sys_parm partitions are as-is. - if (pt[irom0].size == 0) { - pt[irom0].size = first_free_flash_addr - pt[irom0].addr; - } - if (pt[lfs].addr == 0) { - pt[lfs].addr = PT_ALIGN(pt[irom0].addr + pt[irom0].size); - os_printf("LFS base: %08X\n", pt[lfs].addr); - } - if (pt[lfs].size == 0) { - pt[lfs].size = 0x10000; - os_printf("LFS size: %08X\n", pt[lfs].size); + pt = os_malloc(i); // We will work on and register a RAM copy of the PT + // Return if anything is amiss; The SDK will halt if the PT hasn't been registered + if ( !rcr_pt || !pt || n * sizeof(partition_item_t) != i) { + return; } - if (pt[spiffs].addr == 0) { - pt[spiffs].addr = PT_ALIGN(pt[lfs].addr + pt[lfs].size); - os_printf("SPIFFS base: %08X\n", pt[spiffs].addr); + os_memcpy(pt, rcr_pt, i); + + if (pt[n-1].type == 0) { + // If the last PT entry is a {0,XX,0} end marker, then we need first time setup + n = first_time_setup(pt, n-1, flash_size); // return n because setup might shrink the PT } - if (pt[spiffs].size == SPIFFS_MAX_FILESYSTEM_SIZE) { - pt[spiffs].size = flash_size - pt[spiffs].addr; - os_printf("SPIFFS size: %08X\n", pt[spiffs].size); + if (platform_rcr_read(PLATFORM_RCR_PHY_DATA, NULL)!=0) { + phy_data_setup(pt, n); } -// Check that the phys data partition has been initialised and if not then do this -// now to prevent the SDK halting on a "rf_cal[0] !=0x05,is 0xFF" error. - uint32_t init_data_hdr = 0xffffffff, data_addr = pt[phy_data].addr; - int status = spi_flash_read(data_addr, &init_data_hdr, sizeof (uint32_t)); - if (status == SPI_FLASH_RESULT_OK && *(char *)&init_data_hdr != 0x05) { - uint32_t idata[INIT_DATA_SIZE]; - os_printf("Writing Init Data to 0x%08x\n",data_addr); - spi_flash_erase_sector(data_addr/SPI_FLASH_SEC_SIZE); - os_memcpy(idata, init_data, sizeof(idata)); - spi_flash_write(data_addr, idata, sizeof(idata)); - os_delay_us(1000); + // Now register the partition and return +// for (i=0;i 1 && system_partition_table_regist(pt, n, fs_size_code)) { + return; } + os_printf("Invalid system partition table\n"); + while(1); // Trigger WDT} +} -// Check partitions are page aligned and remove and any zero-length partitions. -// This must be done last as this might break the enum partition ordering. - for (i = 0, j = 0; i < PTABLE_SIZE; i++) { - const partition_item_t *p = pt + i; - if ((p->addr| p->size) & (SPI_FLASH_SEC_SIZE-1)) { - os_printf("Partitions must be flash page aligned\n"); - return -1; - } - if (p->size == 0) - continue; - if (j < i) { - pt[j] = *p; - p = pt + j; +/* + * If the PLATFORM_RCR_PT record doesn't exist then the PHY_DATA partition might + * not have been initialised. This must be set to the proper default init data + * otherwise the SDK will halt on the "rf_cal[0] !=0x05,is 0xFF" error. + */ +static void phy_data_setup (partition_item_t *pt, uint32_t n) { + uint8_t header[sizeof(uint32_t)] = {0}; + int i; + + for (i = 0; i < n; i++) { + if (pt[i].type == SYSTEM_PARTITION_PHY_DATA) { + uint32_t addr = pt[i].addr; + platform_s_flash_read(header, addr, sizeof(header)); + if (header[0] != 0x05) { + uint32_t sector = pt[i].addr/INTERNAL_FLASH_SECTOR_SIZE; + if (platform_flash_erase_sector(sector) == PLATFORM_OK) { + os_printf("Writing Init Data to 0x%08x\n",addr); + platform_s_flash_write(init_data, addr, INIT_DATA_SIZE); + } + } + // flag setup complete so we don't retry this every boot + platform_rcr_write(PLATFORM_RCR_PHY_DATA, &addr, 0); + return; } - os_printf("%2u: %08x %08x %08x\n", j, p->type, p->addr, p->size); - j++; } - - *n = j; - return fs_size_code; + // If the PHY_DATA doesn't exist or the write fails then the + // SDK will raise the rf_cal error anyway, so just return. } -void user_pre_init(void) { -#ifdef LUA_USE_MODULES_RTCTIME - // Note: Keep this as close to call_user_start() as possible, since it - // is where the cpu clock actually gets bumped to 80MHz. - rtctime_early_startup (); -#endif - static partition_item_t pt[PTABLE_SIZE]; +/* + * First time setup does the one-off PT calculations and checks. If these are OK, + * then writes back a new RCR for the updated PT and triggers a reboot. It returns + * on failure. + */ +static uint32_t first_time_setup(partition_item_t *pt, uint32_t n, uint32_t flash_size) { + int i, j, last = 0, newn = n; + /* + * Scan down the PT adjusting and 0 entries to sensible defaults. Also delete any + * zero-sized partitions (as the SDK barfs on these). + */ + for (i = 0, j = 0; i < n; i ++) { + partition_item_t *p = pt + i; + switch (p->type) { + + case NODEMCU_PARTITION_IROM0TEXT: + // If the IROM0 partition size is 0 then compute from the IROM0_SIZE. Note + // that the size in the end-marker is used by the nodemcu-partition.py + // script and not here. + if (p->size == 0) { + p->size = PT_ALIGN(IROM0_SIZE); + } + break; + + case NODEMCU_PARTITION_LFS: + // Properly align the LFS partition size and make it consecutive to + // the previous partition. + p->size = PT_ALIGN(p->size); + if (p->addr == 0) + p->addr = last; + break; + + case NODEMCU_PARTITION_SPIFFS: + if (p->size == ~0x0 && p->addr == 0) { + // This allocate all the remaining flash to SPIFFS + p->addr = last; + p->size = flash_size - last; + } else if (p->size == ~0x0) { + p->size = flash_size - p->addr; + } else if (p->addr == 0) { + // if the is addr not specified then start SPIFFS at 1Mb + // boundary if the size will fit otherwise make it consecutive + // to the previous partition. + p->addr = (p->size <= flash_size - 0x100000) ? 0x100000 : last; + } + } - uint32_t pt_size; - uint32_t fs_size_code = setup_partition_table(pt, &pt_size); - if( fs_size_code > 0 && system_partition_table_regist(pt, pt_size, fs_size_code)) { - return; + if (p->size == 0) { + // Delete 0-sized partitions as the SDK barfs on these + newn--; + } else { + // Do consistency tests on the partition + if (p->addr & (INTERNAL_FLASH_SECTOR_SIZE - 1) || + p->size & (INTERNAL_FLASH_SECTOR_SIZE - 1) || + p->addr < last || + p->addr + p->size > flash_size) { + os_printf("Partition %u invalid alignment\n", i); + while(1) {/*system_soft_wdt_feed ();*/} + } + if (j < i) // shift the partition down if we have any deleted slots + pt[j] = *p; +//os_printf("Partition %d: %04x %06x %06x\n", j, p->type, p->addr, p->size); + j++; + last = p->addr + p->size; + } } - os_printf("system_partition_table_regist fail (%u)\n", fs_size_code); - while(1); + platform_rcr_write(PLATFORM_RCR_PT, pt, newn*sizeof(partition_item_t)); + while(1); // Trigger WDT; the new PT will be loaded on reboot } uint32 ICACHE_RAM_ATTR user_iram_memory_is_enabled(void) { @@ -277,18 +355,18 @@ void user_init(void) #endif system_init_done_cb(nodemcu_init); } - +#if 0 /* * The SDK now establishes exception handlers for EXCCAUSE errors: ILLEGAL, * INSTR_ERROR, LOAD_STORE_ERROR, PRIVILEGED, UNALIGNED, LOAD_PROHIBITED, * STORE_PROHIBITED. These handlers are established in SDK/app_main.c. * LOAD_STORE_ERROR is handled by SDK/user_exceptions.o:load_non_32_wide_handler() * which is a fork of our version. The remaining are handled by a static function - * at SDK:app+main.c:offset 0x0348. - * + * at SDK:app+main.c:offset 0x0348. This wrappoer is only needed for debugging. + */ void __real__xtos_set_exception_handler (uint32_t cause, exception_handler_fn fn); void __wrap__xtos_set_exception_handler (uint32_t cause, exception_handler_fn fn) { os_printf("Exception handler %x %x\n", cause, fn); __real__xtos_set_exception_handler (cause, fn); } - */ +#endif diff --git a/docs/modules/node.md b/docs/modules/node.md index 5d6a132e6e..deaa007e83 100644 --- a/docs/modules/node.md +++ b/docs/modules/node.md @@ -239,6 +239,24 @@ do end ``` +## node.getpartitiontable() + +Get the current LFS and SPIFFS partition information. + +#### Syntax +`node.getpartitiontable()` + +#### Parameters +none + +#### Returns +An array containing entries for `lfs_addr`, `lfs_size`, `spiffs_addr` and `spiffs_size`. The address values are offsets relative to the startof the Flash memory. + +#### Example +```lua +print("The LFS size is " .. node.getpartitiontable().lfs_size) +``` + ## node.heap() Returns the current available heap size in bytes. Note that due to fragmentation, actual allocations of this size may not be possible. @@ -407,6 +425,31 @@ target CPU frequency (number) node.setcpufreq(node.CPU80MHZ) ``` +## node.setpartitiontable() + +Sets the current LFS and / or SPIFFS partition information. + +#### Syntax +`node.setpartitiontable(partition_info)` + +!!! note + This function is typically only used once during initial provisioning after first flashing the firmware. It does some consistency checks to validate the specified parameters, and it then reboots the ESP module to load the new partition table. If the LFS or SPIFFS regions have changed then you will need to reload LFS, reformat the SPIFSS and reload its contents. + +#### Parameters +An array containing one or more of the following enties. The address values are byte offsets relative to the startof the Flash memory. The size values are in bytes. Note that these parameters must be a multiple of 8Kb to align to Flash page boundaries. +- `lfs_addr`. The base address of the LFS region. +- `lfs_size`. The size of the LFS region. +- `spiffs_addr`. The base address of the SPIFFS region. +- `spiffs_size`. The size of the SPIFFS region. + +#### Returns +Not applicable. The ESP module will be rebooted for a valid new set, or a Lua error will be thown if inconsistencies are detected. + +#### Example +```lua +node.setpartitiontable{lfs_size = 0x20000, spiffs_addr = 0x120000, spiffs_size = 0x20000} +``` + ## node.sleep() diff --git a/ld/nodemcu.ld b/ld/nodemcu.ld index 1b329d7647..ab08e61a6e 100644 --- a/ld/nodemcu.ld +++ b/ld/nodemcu.ld @@ -233,7 +233,7 @@ SECTIONS .irom0.text : ALIGN(0x1000) { _irom0_text_start = ABSOLUTE(.); - *(.irom0.ptable) + KEEP(*(.irom0.ptable)) . = ALIGN(0x1000); *(.servercert.flash) *(.clientcert.flash) diff --git a/tools/nodemcu-partition.py b/tools/nodemcu-partition.py index 1c9ab46118..23668082e4 100755 --- a/tools/nodemcu-partition.py +++ b/tools/nodemcu-partition.py @@ -6,7 +6,7 @@ # heavily from and including content from esptool.py with full acknowledgement # under GPL 2.0, with said content: Copyright (C) 2014-2016 Fredrik Ahlberg, Angus # Gratton, Espressif Systems (Shanghai) PTE LTD, other contributors as noted. -# https://github.com/espressif/esptool +# https:# github.com/espressif/esptool # # This program is free software; you can redistribute it and/or modify it under # the terms of the GNU General Public License as published by the Free Software @@ -37,13 +37,14 @@ import inspect import struct import string +import math __version__ = '1.0' __program__ = 'nodemcu-partition.py' ROM0_Seg = 0x010000 FLASH_PAGESIZE = 0x001000 FLASH_BASE_ADDR = 0x40200000 -PARTITION_TYPES = { +PARTITION_TYPE = { 4: 'RF_CAL', 5: 'PHY_DATA', 6: 'SYSTEM_PARAMETER', @@ -55,6 +56,10 @@ 106: 'SPIFFS0', 107: 'SPIFFS1'} +IROM0TEXT = 102 +LFS = 103 +SPIFFS = 106 + MAX_PT_SIZE = 20*3 FLASH_SIG = 0xfafaa150 FLASH_SIG_MASK = 0xfffffff0 @@ -62,7 +67,14 @@ WORDSIZE = 4 WORDBITS = 32 -PACK_INT = struct.Struct(" 0: + map['LFS'] = {"addr" : Paddr, "size" : Psize} + + elif Ptype == SPIFFS: + # The logic here is convolved. Explicit start and length can be + # set, but the SPIFFS region is aslo contrained by the end of the + # previos partition and the end of Flash. The size = -1 value + # means use up remaining flash and the SPIFFS will be moved to the + # 1Mb boundary if the address is default and the specified size + # allows this. + if args.sa is not None: + Paddr = args.sa + if args.ss is not None: + Psize = args.ss if args.ss >= 0 else SPIFFS_USE_ALL + if Psize == SPIFFS_USE_ALL: + # This allocate all the remaining flash to SPIFFS + if Paddr < lastEnd: + Paddr = lastEnd + Psize = flash_size - Paddr + else: + if Paddr == 0: + # if the is addr not specified then start SPIFFS at 1Mb + # boundary if the size will fit otherwise make it consecutive + # to the previous partition. + Paddr = 0x100000 if Psize <= flash_size - 0x100000 else lastEnd + elif Paddr < lastEnd: + Paddr = lastEnd + if Psize > flash_size - Paddr: + Psize = flash_size - Paddr + if Psize > 0: + map['SPIFFS'] = {"addr" : Paddr, "size" : Psize} + + if Psize > 0: + Pname = PARTITION_TYPE[Ptype] if Ptype in PARTITION_TYPE \ + else ("Type %d" % Ptype) + print(" %-18s %06x %06x"% (Pname, Paddr, Psize)) + # Do consistency tests on the partition + if (Paddr & (FLASH_PAGESIZE - 1)) > 0 or \ + (Psize & (FLASH_PAGESIZE - 1)) > 0 or \ + Paddr < lastEnd or \ + Paddr + Psize > flash_size: + print (lastEnd, flash_size) + raise FatalError("Partition %u invalid alignment\n" % (i/3)) + + newPT.extend([Ptype, Paddr, Psize]) + lastEnd = Paddr + Psize + + recs.append([PLATFORM_RCR_PT,newPT]) + return recs, map def relocate_lfs(data, addr, size): """ @@ -144,8 +234,7 @@ def relocate_lfs(data, addr, size): aligned and so first needs scaling by the wordsize.) """ addr += FLASH_BASE_ADDR - w = [PACK_INT.unpack_from(data,WORDSIZE*i)[0] \ - for i in range(0, len(data) // WORDSIZE)] + w = [PACK_INT.unpack_from(data,i)[0] for i in range(0, len(data),WORDSIZE)] flash_sig, flash_size = w[0], w[1] assert ((flash_sig & FLASH_SIG_MASK) == FLASH_SIG and @@ -155,6 +244,7 @@ def relocate_lfs(data, addr, size): flash_size //= WORDSIZE flags_size = (flash_size + WORDBITS - 1) // WORDBITS + print WORDSIZE*flash_size, size, len(data), WORDSIZE*(flash_size + flags_size) assert (WORDSIZE*flash_size <= size and len(data) == WORDSIZE*(flash_size + flags_size)) @@ -175,10 +265,10 @@ def main(): def arg_auto_int(x): ux = x.upper() - if "MB" in ux: - return int(ux[:ux.index("MB")]) * 1024 * 1024 - elif "KB" in ux: - return int(ux[:ux.index("KB")]) * 1024 + if "M" in ux: + return int(ux[:ux.index("M")]) * 1024 * 1024 + elif "K" in ux: + return int(ux[:ux.index("K")]) * 1024 else: return int(ux, 0) @@ -187,22 +277,24 @@ def arg_auto_int(x): # ---------- process the arguments ---------- # a = argparse.ArgumentParser( - description='%s V%s - ESP8266 NodeMCU Loader Utility' % + description='%s V%s - ESP8266 NodeMCU Loader Utility' % (__program__, __version__), - prog='esplfs') + prog=__program__) a.add_argument('--port', '-p', help='Serial port device') a.add_argument('--baud', '-b', type=arg_auto_int, help='Serial port baud rate used when flashing/reading') - a.add_argument('--lfs-addr', '-la', dest="la", type=arg_auto_int, + a.add_argument('--flash_size', '-fs', dest="fs", type=arg_auto_int, + help='Flash size used in SPIFFS allocation (Default 4MB)') + a.add_argument('--lfs_addr', '-la', dest="la", type=arg_auto_int, help='(Overwrite) start address of LFS partition') - a.add_argument('--lfs-size', '-ls', dest="ls", type=arg_auto_int, + a.add_argument('--lfs_size', '-ls', dest="ls", type=arg_auto_int, help='(Overwrite) length of LFS partition') - a.add_argument('--lfs-file', '-lf', dest="lf", help='LFS image file') - a.add_argument('--spiffs-addr', '-sa', dest="sa", type=arg_auto_int, + a.add_argument('--lfs_file', '-lf', dest="lf", help='LFS image file') + a.add_argument('--spiffs_addr', '-sa', dest="sa", type=arg_auto_int, help='(Overwrite) start address of SPIFFS partition') - a.add_argument('--spiffs-size', '-ss', dest="ss", type=arg_auto_int, + a.add_argument('--spiffs_size', '-ss', dest="ss", type=arg_auto_int, help='(Overwrite) length of SPIFFS partition') - a.add_argument('--spiffs-file', '-sf', dest="sf", help='SPIFFS image file') + a.add_argument('--spiffs_file', '-sf', dest="sf", help='SPIFFS image file') arg = a.parse_args() @@ -228,11 +320,11 @@ def arg_auto_int(x): with open(pt_file,"rb") as f: data = f.read() - pt, pt_map, n = load_PT(data, arg) - n = n+1 + # ---------- Update the PT if necessary ---------- # - odata = ''.join([PACK_INT.pack(pt[i]) for i in range(0,3*n)]) + \ - "\xFF" * len(data[3*4*n:]) + recs, pt_map = load_PT(data, arg) + odata = repack_RCR(recs) + odata = odata + "\xFF" * (FLASH_PAGESIZE - len(odata)) # ---------- If the PT has changed then use esptool to rewrite it ---------- # @@ -246,13 +338,16 @@ def arg_auto_int(x): esptool.main(espargs) if arg.lf is not None: - i = pt_map['LFS0'] - la,ls = pt[i+1], pt[i+2] + if 'LFS' not in pt_map: + raise FatalError("No LFS partition; cannot write LFS image") + la,ls = pt_map['LFS']['addr'], pt_map['LFS']['size'] # ---------- Read and relocate the LFS image ---------- # - + with gzip.open(arg.lf) as f: lfs = f.read() + if len(lfs) > ls: + raise FatalError("LFS partition to small for LFS image") lfs = relocate_lfs(lfs, la, ls) # ---------- Write to a temp file and use esptool to write it to flash ---------- # @@ -264,7 +359,9 @@ def arg_auto_int(x): esptool.main(espargs) if arg.sf is not None: - sa = pt[pt_map['SPIFFS0']+1] + if 'SPIFFS' not in pt_map: + raise FatalError("No SPIFSS partition; cannot write SPIFFS image") + sa,ss = pt_map['SPIFFS']['addr'], pt_map['SPIFFS']['size'] # ---------- Write to a temp file and use esptool to write it to flash ---------- # @@ -274,8 +371,8 @@ def arg_auto_int(x): # ---------- Clean up temp directory ---------- # - espargs = base + ['--after', 'hard_reset', 'flash_id'] - esptool.main(espargs) +# espargs = base + ['--after', 'hard_reset', 'flash_id'] +# esptool.main(espargs) shutil.rmtree(tmpdir) From e0f3dbed416ec00bc1d68b0adf532187c6d44cd8 Mon Sep 17 00:00:00 2001 From: Terry Ellison Date: Tue, 7 May 2019 18:49:16 +0300 Subject: [PATCH 15/74] Fix 2749 + restore correct user_modules.h (#2750) --- app/include/user_modules.h | 14 +++++++------- app/modules/file.c | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/include/user_modules.h b/app/include/user_modules.h index 6aa35b9630..2818ed7f16 100644 --- a/app/include/user_modules.h +++ b/app/include/user_modules.h @@ -7,7 +7,7 @@ // includes general purpose interface modules which require at most two GPIO pins. // See https://github.com/nodemcu/nodemcu-firmware/pull/1127 for discussions. // New modules should be disabled by default and added in alphabetical order. -//#define LUA_USE_MODULES_ADC +#define LUA_USE_MODULES_ADC //#define LUA_USE_MODULES_ADS1115 //#define LUA_USE_MODULES_ADXL345 //#define LUA_USE_MODULES_AM2320 @@ -21,22 +21,22 @@ //#define LUA_USE_MODULES_COLOR_UTILS //#define LUA_USE_MODULES_CRON //#define LUA_USE_MODULES_CRYPTO -//#define LUA_USE_MODULES_DHT +#define LUA_USE_MODULES_DHT //#define LUA_USE_MODULES_ENCODER //#define LUA_USE_MODULES_ENDUSER_SETUP // USE_DNS in dhcpserver.h needs to be enabled for this module to work. #define LUA_USE_MODULES_FILE -#define LUA_USE_MODULES_GDBSTUB -//#define LUA_USE_MODULES_GPIO +//#define LUA_USE_MODULES_GDBSTUB +#define LUA_USE_MODULES_GPIO //#define LUA_USE_MODULES_GPIO_PULSE //#define LUA_USE_MODULES_HDC1080 //#define LUA_USE_MODULES_HMC5883L //#define LUA_USE_MODULES_HTTP //#define LUA_USE_MODULES_HX711 -//#define LUA_USE_MODULES_I2C +#define LUA_USE_MODULES_I2C //#define LUA_USE_MODULES_L3G4200D //#define LUA_USE_MODULES_MCP4725 //#define LUA_USE_MODULES_MDNS -//#define LUA_USE_MODULES_MQTT +#define LUA_USE_MODULES_MQTT #define LUA_USE_MODULES_NET #define LUA_USE_MODULES_NODE #define LUA_USE_MODULES_OW @@ -54,7 +54,7 @@ //#define LUA_USE_MODULES_SJSON //#define LUA_USE_MODULES_SNTP //#define LUA_USE_MODULES_SOMFY -//#define LUA_USE_MODULES_SPI +#define LUA_USE_MODULES_SPI //#define LUA_USE_MODULES_SQLITE3 //#define LUA_USE_MODULES_STRUCT //#define LUA_USE_MODULES_SWITEC diff --git a/app/modules/file.c b/app/modules/file.c index f9ae816e37..4986f7c95e 100644 --- a/app/modules/file.c +++ b/app/modules/file.c @@ -431,7 +431,7 @@ static int file_g_read( lua_State* L, int n, int16_t end_char, int fd ) luaL_buffinit(L, &b); for (j = 0; j < n; j += sizeof(p)) { - int nwanted = (j <= n - sizeof(p)) ? sizeof(p) : n - j; + int nwanted = (n - j >= sizeof(p)) ? sizeof(p) : n - j; int nread = vfs_read(fd, p, nwanted); if (nread == VFS_RES_ERR || nread == 0) { @@ -456,7 +456,7 @@ static int file_g_read( lua_State* L, int n, int16_t end_char, int fd ) } // Lua: read() -// file.read() will read FILE_READ_CHUNK bytes, or EOF is reached. +// file.read() will read FILE _CHUNK bytes, or EOF is reached. // file.read(10) will read 10 byte from file, or EOF is reached. // file.read('q') will read until 'q' or EOF is reached. static int file_read( lua_State* L ) From 1990f95740e9f7d375b1157a25d0b6b508586c27 Mon Sep 17 00:00:00 2001 From: Terry Ellison Date: Wed, 8 May 2019 14:08:20 +0300 Subject: [PATCH 16/74] Updated ROTables 1st tranch (#2742) Updated ROTables --- app/Makefile | 2 - app/include/module.h | 15 +-- app/include/pm/pmSleep.h | 16 +-- app/include/user_config.h | 2 +- app/lua/lauxlib.c | 4 - app/lua/lbaselib.c | 128 ++++++++++------------ app/lua/ldblib.c | 44 ++++---- app/lua/linit.c | 122 +++++++++++---------- app/lua/lmathlib.c | 122 ++++++++------------- app/lua/loadlib.c | 35 +++--- app/lua/lrodefs.h | 18 ++-- app/lua/lrotable.c | 71 +++++------- app/lua/lrotable.h | 35 +++--- app/lua/lstrlib.c | 76 ++++--------- app/lua/ltable.c | 8 +- app/lua/ltablib.c | 29 +++-- app/lua/luac_cross/Makefile | 2 +- app/lua/luac_cross/liolib.c | 61 +++++------ app/lua/luac_cross/loslib.c | 34 +++--- app/lua/luaconf.h | 4 +- app/modules/adc.c | 18 ++-- app/modules/ads1115.c | 117 ++++++++++---------- app/modules/adxl345.c | 12 +-- app/modules/am2320.c | 12 +-- app/modules/apa102.c | 11 +- app/modules/bit.c | 34 +++--- app/modules/bloom.c | 28 ++--- app/modules/bme280.c | 28 ++--- app/modules/bme680.c | 22 ++-- app/modules/bmp085.c | 18 ++-- app/modules/coap.c | 75 +++++++------ app/modules/color_utils.c | 19 ++-- app/modules/cron.c | 30 +++--- app/modules/crypto.c | 44 ++++---- app/modules/dht.c | 20 ++-- app/modules/encoder.c | 18 ++-- app/modules/enduser_setup.c | 16 +-- app/modules/file.c | 106 +++++++++--------- app/modules/gdbstub.c | 14 +-- app/modules/gpio.c | 38 +++---- app/modules/gpio_pulse.c | 39 ++++--- app/modules/hdc1080.c | 12 +-- app/modules/hmc5883l.c | 12 +-- app/modules/http.c | 22 ++-- app/modules/hx711.c | 12 +-- app/modules/i2c.c | 32 +++--- app/modules/l3g4200d.c | 12 +-- app/modules/mcp4725.c | 22 ++-- app/modules/mdns.c | 12 +-- app/modules/mqtt.c | 68 ++++++------ app/modules/net.c | 126 +++++++++++----------- app/modules/node.c | 119 ++++++++++---------- app/modules/ow.c | 38 +++---- app/modules/pcm.c | 50 ++++----- app/modules/perf.c | 12 +-- app/modules/pwm.c | 26 ++--- app/modules/rc.c | 10 +- app/modules/rfswitch.c | 11 +- app/modules/rotary.c | 34 +++--- app/modules/rtcfifo.c | 24 ++--- app/modules/rtcmem.c | 12 +-- app/modules/rtctime.c | 22 ++-- app/modules/si7021.c | 32 +++--- app/modules/sigma_delta.c | 21 ++-- app/modules/sjson.c | 91 +++++----------- app/modules/sntp.c | 14 +-- app/modules/somfy.c | 18 ++-- app/modules/spi.c | 42 ++++---- app/modules/sqlite3.c | 2 + app/modules/struct.c | 11 +- app/modules/switec.c | 20 ++-- app/modules/tcs34725.c | 22 ++-- app/modules/tls.c | 60 +++++------ app/modules/tm1829.c | 11 +- app/modules/tmr.c | 62 +++++------ app/modules/tsl2561.c | 46 ++++---- app/modules/u8g2.c | 128 +++++++++++----------- app/modules/uart.c | 32 +++--- app/modules/ucg.c | 132 +++++++++++------------ app/modules/websocket.c | 36 +++---- app/modules/wifi.c | 204 +++++++++++++++++------------------ app/modules/wifi_common.h | 4 +- app/modules/wifi_eventmon.c | 96 ++++++++--------- app/modules/wifi_monitor.c | 44 ++++---- app/modules/wps.c | 24 ++--- app/modules/ws2801.c | 15 ++- app/modules/ws2812.c | 68 ++++++------ app/modules/ws2812_effects.c | 35 +++--- app/modules/xpt2046.c | 24 ++--- app/pm/swtimer.c | 18 ++-- 90 files changed, 1684 insertions(+), 1863 deletions(-) diff --git a/app/Makefile b/app/Makefile index 222f03b319..e4aa96c2a9 100644 --- a/app/Makefile +++ b/app/Makefile @@ -138,8 +138,6 @@ 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 \ diff --git a/app/include/module.h b/app/include/module.h index 1af7015467..dbcef654c0 100644 --- a/app/include/module.h +++ b/app/include/module.h @@ -2,7 +2,7 @@ #define __MODULE_H__ #include "user_modules.h" -#include "lrodefs.h" +#include "lrotable.h" /* Registering a module within NodeMCU is really easy these days! * @@ -18,11 +18,11 @@ * * Then simply put a line like this at the bottom of your module file: * - * NODEMCU_MODULE(MYNAME, "myname", myname_map, luaopen_myname); + * NODEMCU_MODULE(MYNAME, "myname", myname, luaopen_myname); * * or perhaps * - * NODEMCU_MODULE(MYNAME, "myname", myname_map, NULL); + * NODEMCU_MODULE(MYNAME, "myname", myname, NULL); * * if you don't need an init function. * @@ -67,13 +67,8 @@ */ #define NODEMCU_MODULE(cfgname, luaname, map, initfunc) \ const LOCK_IN_SECTION(libs) \ - luaL_Reg MODULE_PASTE_(lua_lib_,cfgname) = { luaname, initfunc }; \ + luaR_entry MODULE_PASTE_(lua_lib_,cfgname) = { luaname, LRO_FUNCVAL(initfunc) }; \ const LOCK_IN_SECTION(rotable) \ luaR_entry MODULE_EXPAND_PASTE_(cfgname,MODULE_EXPAND_PASTE_(_module_selected,MODULE_PASTE_(LUA_USE_MODULES_,cfgname))) \ - = {LSTRKEY(luaname), LROVAL(map)} - -#if !defined(LUA_CROSS_COMPILER) && !(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 - + = {luaname, LRO_ROVAL(map ## _map)} #endif diff --git a/app/include/pm/pmSleep.h b/app/include/pm/pmSleep.h index a3c6ff34ad..eca8590aee 100644 --- a/app/include/pm/pmSleep.h +++ b/app/include/pm/pmSleep.h @@ -24,23 +24,17 @@ #define PMSLEEP_ERR(...) #endif - - - - #define PMSLEEP_SLEEP_MIN_TIME 50000 #define PMSLEEP_SLEEP_MAX_TIME 268435454 //FPM_MAX_SLEEP_TIME-1 #define pmSleep_INIT_CFG(X) pmSleep_param_t X = {.sleep_duration=0, .wake_pin=255, \ .preserve_opmode=TRUE, .suspend_cb_ptr=NULL, .resume_cb_ptr=NULL} #define PMSLEEP_INT_MAP \ - { LSTRKEY( "INT_BOTH" ), LNUMVAL( GPIO_PIN_INTR_ANYEDGE ) }, \ - { LSTRKEY( "INT_UP" ), LNUMVAL( GPIO_PIN_INTR_POSEDGE ) }, \ - { LSTRKEY( "INT_DOWN" ), LNUMVAL( GPIO_PIN_INTR_NEGEDGE ) }, \ - { LSTRKEY( "INT_HIGH" ), LNUMVAL( GPIO_PIN_INTR_HILEVEL ) }, \ - { LSTRKEY( "INT_LOW" ), LNUMVAL( GPIO_PIN_INTR_LOLEVEL ) } - - + LROT_NUMENTRY( INT_BOTH, GPIO_PIN_INTR_ANYEDGE ) \ + LROT_NUMENTRY( INT_UP, GPIO_PIN_INTR_POSEDGE ) \ + LROT_NUMENTRY( INT_DOWN, GPIO_PIN_INTR_NEGEDGE ) \ + LROT_NUMENTRY( INT_HIGH, GPIO_PIN_INTR_HILEVEL ) \ + LROT_NUMENTRY( INT_LOW, GPIO_PIN_INTR_LOLEVEL ) typedef struct pmSleep_param{ uint32 sleep_duration; diff --git a/app/include/user_config.h b/app/include/user_config.h index 4dfdaadd4c..49f79c8691 100644 --- a/app/include/user_config.h +++ b/app/include/user_config.h @@ -244,7 +244,7 @@ extern void luaL_dbgbreak(void); #endif #endif -#if !defined(LUA_NUMBER_INTEGRAL) && defined (LUA_DWORD_ALIGNED_TVALUES) +#if !defined(LUA_NUMBER_INTEGRAL) && !defined (LUA_DWORD_ALIGNED_TVALUES) #define LUA_PACK_TVALUES #else #undef LUA_PACK_TVALUES diff --git a/app/lua/lauxlib.c b/app/lua/lauxlib.c index d6ee1f3427..de2ae48978 100644 --- a/app/lua/lauxlib.c +++ b/app/lua/lauxlib.c @@ -419,11 +419,7 @@ LUALIB_API void (luaL_register) (lua_State *L, const char *libname, LUALIB_API void (luaL_register_light) (lua_State *L, const char *libname, const luaL_Reg *l) { -#if LUA_OPTIMIZE_MEMORY > 0 luaI_openlib(L, libname, l, 0, LUA_USELIGHTFUNCTIONS); -#else - luaI_openlib(L, libname, l, 0, LUA_USECCLOSURES); -#endif } static int libsize (const luaL_Reg *l) { diff --git a/app/lua/lbaselib.c b/app/lua/lbaselib.c index 05a0a33615..16ee1cf953 100644 --- a/app/lua/lbaselib.c +++ b/app/lua/lbaselib.c @@ -16,7 +16,7 @@ #include C_HEADER_STDLIB #include "lauxlib.h" #include "lualib.h" -#include "lrodefs.h" +#include "lrotable.h" @@ -462,64 +462,59 @@ static int luaB_newproxy (lua_State *L) { return 1; } -#include "lrodefs.h" +#include "lrotable.h" -extern const luaR_entry lua_rotable_base[]; +LROT_EXTERN(lua_rotable_base); /* - * ESP builds use specific linker directives to marshal all ROTable declarations - * into a single ROTable in the PSECT ".lua_rotable". + * Separate ROTables are used for the base functions and library ROTables, with + * the base functions ROTable declared below. The library ROTable is chained + * from this using its __index meta-method. * - * This is not practical on Posix builds using a standard link so for cross - * compiler builds, separate ROTables are used for the base functions and library - * ROTables, with the latter chained from the former using its __index meta-method. - * In this case all library ROTables are defined in linit.c. + * ESP builds use specific linker directives to marshal all the ROTable entries + * for the library modules into a single ROTable in the PSECT ".lua_rotable". + * This is not practical on Posix builds using a standard GNU link, so the + * equivalent ROTable for the core libraries defined in linit.c for the cross- + * compiler build. */ -#ifdef LUA_CROSS_COMPILER -#define BASE_ROTABLE base_func_map -#define LOCK_IN_ROTABLE -static const LUA_REG_TYPE base_func_meta[] = { - LROT_TABENTRY(__index, lua_rotable_base), - LROT_END}; -#else -#define BASE_ROTABLE lua_rotable_base -#define LOCK_IN_ROTABLE __attribute__((used,unused,section(".lua_rotable"))) -#endif -static const LUA_REG_TYPE LOCK_IN_ROTABLE base_func_map[] = { - LROT_FUNCENTRY(assert, luaB_assert), - LROT_FUNCENTRY(collectgarbage, luaB_collectgarbage), - LROT_FUNCENTRY(dofile, luaB_dofile), - LROT_FUNCENTRY(error, luaB_error), - LROT_FUNCENTRY(gcinfo, luaB_gcinfo), - LROT_FUNCENTRY(getfenv, luaB_getfenv), - LROT_FUNCENTRY(getmetatable, luaB_getmetatable), - LROT_FUNCENTRY(loadfile, luaB_loadfile), - LROT_FUNCENTRY(load, luaB_load), - LROT_FUNCENTRY(loadstring, luaB_loadstring), - LROT_FUNCENTRY(next, luaB_next), - LROT_FUNCENTRY(pcall, luaB_pcall), - LROT_FUNCENTRY(print, luaB_print), - LROT_FUNCENTRY(rawequal, luaB_rawequal), - LROT_FUNCENTRY(rawget, luaB_rawget), - LROT_FUNCENTRY(rawset, luaB_rawset), - LROT_FUNCENTRY(select, luaB_select), - LROT_FUNCENTRY(setfenv, luaB_setfenv), - LROT_FUNCENTRY(setmetatable, luaB_setmetatable), - LROT_FUNCENTRY(tonumber, luaB_tonumber), - LROT_FUNCENTRY(tostring, luaB_tostring), - LROT_FUNCENTRY(type, luaB_type), - LROT_FUNCENTRY(unpack, luaB_unpack), +LROT_EXTERN(lua_rotables); + +LROT_PUBLIC_BEGIN(base_func_meta) + LROT_TABENTRY( __index, lua_rotables ) +LROT_END(base_func, base_func_meta, LROT_MASK_INDEX) + +LROT_PUBLIC_BEGIN(base_func) + LROT_FUNCENTRY(assert, luaB_assert) + LROT_FUNCENTRY(collectgarbage, luaB_collectgarbage) + LROT_FUNCENTRY(dofile, luaB_dofile) + LROT_FUNCENTRY(error, luaB_error) + LROT_FUNCENTRY(gcinfo, luaB_gcinfo) + LROT_FUNCENTRY(getfenv, luaB_getfenv) + LROT_FUNCENTRY(getmetatable, luaB_getmetatable) + LROT_FUNCENTRY(loadfile, luaB_loadfile) + LROT_FUNCENTRY(load, luaB_load) + LROT_FUNCENTRY(loadstring, luaB_loadstring) + LROT_FUNCENTRY(next, luaB_next) + LROT_FUNCENTRY(pcall, luaB_pcall) + LROT_FUNCENTRY(print, luaB_print) + LROT_FUNCENTRY(rawequal, luaB_rawequal) + LROT_FUNCENTRY(rawget, luaB_rawget) + LROT_FUNCENTRY(rawset, luaB_rawset) + LROT_FUNCENTRY(select, luaB_select) + LROT_FUNCENTRY(setfenv, luaB_setfenv) + LROT_FUNCENTRY(setmetatable, luaB_setmetatable) + LROT_FUNCENTRY(tonumber, luaB_tonumber) + LROT_FUNCENTRY(tostring, luaB_tostring) + LROT_FUNCENTRY(type, luaB_type) + LROT_FUNCENTRY(unpack, luaB_unpack) LROT_FUNCENTRY(xpcall, luaB_xpcall) -#ifdef LUA_CROSS_COMPILER - ,LROT_TABENTRY(__metatable, base_func_meta), - LROT_END -#endif -}; + LROT_TABENTRY(__metatable, base_func_meta) +LROT_END(base_func, base_func_meta, LROT_MASK_INDEX) -static const luaL_Reg base_funcs[] = { - {NULL, NULL} -}; +LROT_BEGIN(G_meta) + LROT_TABENTRY( __index, base_func ) +LROT_END(G_meta, NULL, 0) /* @@ -650,17 +645,14 @@ static int luaB_corunning (lua_State *L) { return 1; } -#undef MIN_OPT_LEVEL -#define MIN_OPT_LEVEL 1 -const LUA_REG_TYPE co_funcs[] = { - {LSTRKEY("create"), LFUNCVAL(luaB_cocreate)}, - {LSTRKEY("resume"), LFUNCVAL(luaB_coresume)}, - {LSTRKEY("running"), LFUNCVAL(luaB_corunning)}, - {LSTRKEY("status"), LFUNCVAL(luaB_costatus)}, - {LSTRKEY("wrap"), LFUNCVAL(luaB_cowrap)}, - {LSTRKEY("yield"), LFUNCVAL(luaB_yield)}, - {LNILKEY, LNILVAL} -}; +LROT_PUBLIC_BEGIN(co_funcs) + LROT_FUNCENTRY( create, luaB_cocreate ) + LROT_FUNCENTRY( resume, luaB_coresume ) + LROT_FUNCENTRY( running, luaB_corunning ) + LROT_FUNCENTRY( status, luaB_costatus ) + LROT_FUNCENTRY( wrap, luaB_cowrap ) + LROT_FUNCENTRY( yield, luaB_yield ) +LROT_END (co_funcs, NULL, 0) /* }====================================================== */ @@ -676,14 +668,12 @@ static void base_open (lua_State *L) { /* set global _G */ lua_pushvalue(L, LUA_GLOBALSINDEX); lua_setglobal(L, "_G"); + /* open lib into global table */ - luaL_register_light(L, "_G", base_funcs); -#if LUA_OPTIMIZE_MEMORY > 0 - lua_pushvalue(L, -1); - lua_setmetatable(L, -2); - lua_pushrotable(L, (void *)BASE_ROTABLE); - lua_setglobal(L, "__index"); -#endif + luaL_register_light(L, "_G", &((luaL_Reg) {0})); + lua_pushrotable(L, LROT_TABLEREF(G_meta)); + lua_setmetatable(L, LUA_GLOBALSINDEX); + lua_pushliteral(L, LUA_VERSION); lua_setglobal(L, "_VERSION"); /* set global _VERSION */ /* `ipairs' and `pairs' need auxliliary functions as upvalues */ diff --git a/app/lua/ldblib.c b/app/lua/ldblib.c index 3eef8fd47b..d41721bd26 100644 --- a/app/lua/ldblib.c +++ b/app/lua/ldblib.c @@ -18,9 +18,9 @@ #include "lualib.h" #include "lstring.h" #include "lflash.h" -#include "user_modules.h" - +#include "lrotable.h" +#include "user_modules.h" static int db_getregistry (lua_State *L) { lua_pushvalue(L, LUA_REGISTRYINDEX); @@ -417,32 +417,28 @@ 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[] = { +LROT_PUBLIC_BEGIN(dblib) #ifndef LUA_USE_BUILTIN_DEBUG_MINIMAL - {LSTRKEY("debug"), LFUNCVAL(db_debug)}, - {LSTRKEY("getfenv"), LFUNCVAL(db_getfenv)}, - {LSTRKEY("gethook"), LFUNCVAL(db_gethook)}, - {LSTRKEY("getinfo"), LFUNCVAL(db_getinfo)}, - {LSTRKEY("getlocal"), LFUNCVAL(db_getlocal)}, + LROT_FUNCENTRY( debug, db_debug ) + LROT_FUNCENTRY( getfenv, db_getfenv ) + LROT_FUNCENTRY( gethook, db_gethook ) + LROT_FUNCENTRY( getinfo, db_getinfo ) + LROT_FUNCENTRY( getlocal, db_getlocal ) #endif - {LSTRKEY("getregistry"), LFUNCVAL(db_getregistry)}, - {LSTRKEY("getstrings"), LFUNCVAL(db_getstrings)}, + LROT_FUNCENTRY( getregistry, db_getregistry ) + LROT_FUNCENTRY( getstrings, db_getstrings ) #ifndef LUA_USE_BUILTIN_DEBUG_MINIMAL - {LSTRKEY("getmetatable"), LFUNCVAL(db_getmetatable)}, - {LSTRKEY("getupvalue"), LFUNCVAL(db_getupvalue)}, - {LSTRKEY("setfenv"), LFUNCVAL(db_setfenv)}, - {LSTRKEY("sethook"), LFUNCVAL(db_sethook)}, - {LSTRKEY("setlocal"), LFUNCVAL(db_setlocal)}, - {LSTRKEY("setmetatable"), LFUNCVAL(db_setmetatable)}, - {LSTRKEY("setupvalue"), LFUNCVAL(db_setupvalue)}, + LROT_FUNCENTRY( getmetatable, db_getmetatable ) + LROT_FUNCENTRY( getupvalue, db_getupvalue ) + LROT_FUNCENTRY( setfenv, db_setfenv ) + LROT_FUNCENTRY( sethook, db_sethook ) + LROT_FUNCENTRY( setlocal, db_setlocal ) + LROT_FUNCENTRY( setmetatable, db_setmetatable ) + LROT_FUNCENTRY( setupvalue, db_setupvalue ) #endif - {LSTRKEY("traceback"), LFUNCVAL(db_errorfb)}, - {LNILKEY, LNILVAL} -}; + LROT_FUNCENTRY( traceback, db_errorfb ) +LROT_END(dblib, NULL, 0) LUALIB_API int luaopen_debug (lua_State *L) { - LREGISTER(L, LUA_DBLIBNAME, dblib); + return 0; } diff --git a/app/lua/linit.c b/app/lua/linit.c index b94a269bd4..cd4f4bbacf 100644 --- a/app/lua/linit.c +++ b/app/lua/linit.c @@ -15,45 +15,43 @@ #include "lauxlib.h" #include "luaconf.h" #include "module.h" +#include "lstate.h" -#if !defined(LUA_CROSS_COMPILER) && !(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)" +LROT_EXTERN(strlib); +LROT_EXTERN(tab_funcs); +LROT_EXTERN(dblib); +LROT_EXTERN(co_funcs); +LROT_EXTERN(math); +#if defined(LUA_CROSS_COMPILER) +LROT_EXTERN(oslib); +LROT_EXTERN(iolib); #endif - -extern const luaR_entry strlib[], tab_funcs[], dblib[], - co_funcs[], math_map[], syslib[]; -extern const luaR_entry syslib[], io_funcs[]; // Only used on cross-compile builds - /* * The NodeMCU Lua initalisation has been adapted to use linker-based module - * registration. This uses a PSECT naming convention to allow the lib and rotab - * entries to be collected by the linker into consoliated tables. The linker - * defines lua_libs_base and lua_rotable_base. + * registration. This uses a PSECT naming convention to allow the ROTable and + * initialisation function entries to be collected by the linker into two + * consoliated ROTables. This significantly simplifies adding new modules and + * configuring builds with a small subset of the total modules. + * + * This linker-based approach is not practical for cross compiler builds which + * must link on a range of platforms, and where we don't have control of PSECT + * placement. However unlike the target builds, the luac.cross builds only + * used a small and fixed list of libraries and so in this case the table can + * be defined in this source file, so in this case all library ROTables are + * defined here, avoiding the need for linker magic is avoided on host builds. * - * This is not practical on Posix builds which use a standard loader declaration - * so for cross compiler builds, separate ROTables are used for the base functions - * and library ROTables, with the latter chained from the former using its __index - * meta-method. In this case all library ROTables are defined here, avoiding the - * need for linker magic is avoided on host builds. + * Note that a separate ROTable is defined in lbaselib.c for the base functions + * and there is a metatable index cascade from _G to this base function table to + * the master rotables table. In the target build, the linker marshals the + * table, hence the LROT_BREAK() macros which don't 0 terminate the lists. */ -#if defined(LUA_CROSS_COMPILER) -#define LUA_ROTABLES lua_rotable_base -#define LUA_LIBS lua_libs_base -#else /* declare Xtensa toolchain linker defined constants */ -extern const luaL_Reg lua_libs_base[]; -extern const luaR_entry lua_rotable_base[]; -#define LUA_ROTABLES lua_rotable_core -#define LUA_LIBS lua_libs_core -#endif - #ifdef _MSC_VER //MSVC requires us to declare these sections before we refer to them #pragma section(__ROSECNAME(A), read) #pragma section(__ROSECNAME(zzzzzzzz), read) #pragma section(__ROSECNAME(libs), read) #pragma section(__ROSECNAME(rotable), read) - //These help us to find the beginning and ending of the RO data. NOTE: linker //magic is used; the section names are lexically sorted, so 'a' and 'z' are //important to keep the other sections lexically between these two dummy @@ -61,43 +59,57 @@ extern const luaR_entry lua_rotable_base[]; const LOCK_IN_SECTION(A) char _ro_start[1] = {0}; const LOCK_IN_SECTION(zzzzzzzz) char _ro_end[1] = {0}; #endif -static const LOCK_IN_SECTION(libs) luaL_reg LUA_LIBS[] = { - {"", luaopen_base}, - {LUA_LOADLIBNAME, luaopen_package}, - {LUA_STRLIBNAME, luaopen_string}, - {LUA_TABLIBNAME, luaopen_table}, - {LUA_DBLIBNAME, luaopen_debug} -#if defined(LUA_CROSS_COMPILER) - ,{LUA_IOLIBNAME, luaopen_io}, - {NULL, NULL} + +LROT_PUBLIC_TABLE(lua_rotables) + +LROT_PUBLIC_BEGIN(LOCK_IN_SECTION(rotable) lua_rotables) + LROT_TABENTRY( string, strlib ) + LROT_TABENTRY( table, tab_funcs ) + LROT_TABENTRY( debug, dblib) + LROT_TABENTRY( coroutine, co_funcs ) + LROT_TABENTRY( math, math ) + LROT_TABENTRY( ROM, lua_rotables ) +#ifdef LUA_CROSS_COMPILER + LROT_TABENTRY( os, oslib ) + LROT_TABENTRY( io, iolib ) +LROT_END(lua_rotables, NULL, 0) +#else +LROT_BREAK(lua_rotables) #endif -}; -#define ENTRY(n,t) {LSTRKEY(n), LRO_ROVAL(t)} +LROT_PUBLIC_BEGIN(LOCK_IN_SECTION(libs) lua_libs) + LROT_FUNCENTRY( _, luaopen_base ) + LROT_FUNCENTRY( package, luaopen_package ) + LROT_FUNCENTRY( string, luaopen_string ) + LROT_FUNCENTRY( table, luaopen_table ) + LROT_FUNCENTRY( debug, luaopen_debug ) +#ifndef LUA_CROSS_COMPILER +LROT_BREAK(lua_rotables) +#else + LROT_FUNCENTRY( io, luaopen_io ) +LROT_END( lua_libs, NULL, 0) +#endif -const LOCK_IN_SECTION(rotable) ROTable LUA_ROTABLES[] = { - ENTRY("ROM", LUA_ROTABLES), - ENTRY(LUA_STRLIBNAME, strlib), - ENTRY(LUA_TABLIBNAME, tab_funcs), - ENTRY(LUA_DBLIBNAME, dblib), - ENTRY(LUA_COLIBNAME, co_funcs), - ENTRY(LUA_MATHLIBNAME, math_map) -#if defined(LUA_CROSS_COMPILER) - ,ENTRY(LUA_OSLIBNAME, syslib), - LROT_END +#ifndef LUA_CROSS_COMPILER +extern void luaL_dbgbreak(void); #endif - }; void luaL_openlibs (lua_State *L) { - const luaL_Reg *lib = lua_libs_base; + lua_pushrotable(L, LROT_TABLEREF(lua_libs)); + lua_pushnil(L); /* first key */ /* loop round and open libraries */ - for (; lib->name; lib++) { - if (lib->func) { - lua_pushcfunction(L, lib->func); - lua_pushstring(L, lib->name); - lua_call(L, 1, 0); +#ifndef LUA_CROSS_COMPILER +// luaL_dbgbreak(); // This is a test point for debugging library start ups +#endif + while (lua_next(L, -2) != 0) { + if (lua_islightfunction(L,-1) && + fvalue(L->top-1)) { // only process function entries + lua_pushvalue(L, -2); + lua_call(L, 1, 0); // call luaopen_XXX(libname) + } else { + lua_pop(L, 1); } } + lua_pop(L, 1); //cleanup stack } - diff --git a/app/lua/lmathlib.c b/app/lua/lmathlib.c index ae11f23419..2a10b6e9b1 100644 --- a/app/lua/lmathlib.c +++ b/app/lua/lmathlib.c @@ -15,6 +15,7 @@ #include "lauxlib.h" #include "lualib.h" +#include "lrotable.h" #undef PI #define PI (3.14159265358979323846) @@ -308,92 +309,57 @@ static int math_randomseed (lua_State *L) { return 0; } - - -#undef MIN_OPT_LEVEL -#define MIN_OPT_LEVEL 1 -#include "lrodefs.h" -const LUA_REG_TYPE math_map[] = { +LROT_PUBLIC_BEGIN(math) #ifdef LUA_NUMBER_INTEGRAL - {LSTRKEY("abs"), LFUNCVAL(math_abs)}, - {LSTRKEY("ceil"), LFUNCVAL(math_identity)}, - {LSTRKEY("floor"), LFUNCVAL(math_identity)}, - {LSTRKEY("max"), LFUNCVAL(math_max)}, - {LSTRKEY("min"), LFUNCVAL(math_min)}, - {LSTRKEY("pow"), LFUNCVAL(math_pow)}, - {LSTRKEY("random"), LFUNCVAL(math_random)}, - {LSTRKEY("randomseed"), LFUNCVAL(math_randomseed)}, - {LSTRKEY("sqrt"), LFUNCVAL(math_sqrt)}, -#if LUA_OPTIMIZE_MEMORY > 0 - {LSTRKEY("huge"), LNUMVAL(INT_MAX)}, -#endif + LROT_FUNCENTRY( abs, math_abs ) + LROT_FUNCENTRY( ceil, math_identity ) + LROT_FUNCENTRY( floor, math_identity ) + LROT_FUNCENTRY( max, math_max ) + LROT_FUNCENTRY( min, math_min ) + LROT_FUNCENTRY( pow, math_pow ) + LROT_FUNCENTRY( random, math_random ) + LROT_FUNCENTRY( randomseed, math_randomseed ) + LROT_FUNCENTRY( sqrt, math_sqrt ) + LROT_NUMENTRY( huge, INT_MAX ) #else - {LSTRKEY("abs"), LFUNCVAL(math_abs)}, - // {LSTRKEY("acos"), LFUNCVAL(math_acos)}, - // {LSTRKEY("asin"), LFUNCVAL(math_asin)}, - // {LSTRKEY("atan2"), LFUNCVAL(math_atan2)}, - // {LSTRKEY("atan"), LFUNCVAL(math_atan)}, - {LSTRKEY("ceil"), LFUNCVAL(math_ceil)}, - // {LSTRKEY("cosh"), LFUNCVAL(math_cosh)}, - // {LSTRKEY("cos"), LFUNCVAL(math_cos)}, - // {LSTRKEY("deg"), LFUNCVAL(math_deg)}, - // {LSTRKEY("exp"), LFUNCVAL(math_exp)}, - {LSTRKEY("floor"), LFUNCVAL(math_floor)}, - // {LSTRKEY("fmod"), LFUNCVAL(math_fmod)}, -#if LUA_OPTIMIZE_MEMORY > 0 && defined(LUA_COMPAT_MOD) - // {LSTRKEY("mod"), LFUNCVAL(math_fmod)}, -#endif - // {LSTRKEY("frexp"), LFUNCVAL(math_frexp)}, - // {LSTRKEY("ldexp"), LFUNCVAL(math_ldexp)}, - // {LSTRKEY("log10"), LFUNCVAL(math_log10)}, - // {LSTRKEY("log"), LFUNCVAL(math_log)}, - {LSTRKEY("max"), LFUNCVAL(math_max)}, - {LSTRKEY("min"), LFUNCVAL(math_min)}, - // {LSTRKEY("modf"), LFUNCVAL(math_modf)}, - {LSTRKEY("pow"), LFUNCVAL(math_pow)}, - // {LSTRKEY("rad"), LFUNCVAL(math_rad)}, - {LSTRKEY("random"), LFUNCVAL(math_random)}, - {LSTRKEY("randomseed"), LFUNCVAL(math_randomseed)}, - // {LSTRKEY("sinh"), LFUNCVAL(math_sinh)}, - // {LSTRKEY("sin"), LFUNCVAL(math_sin)}, - {LSTRKEY("sqrt"), LFUNCVAL(math_sqrt)}, - // {LSTRKEY("tanh"), LFUNCVAL(math_tanh)}, - // {LSTRKEY("tan"), LFUNCVAL(math_tan)}, -#if LUA_OPTIMIZE_MEMORY > 0 - {LSTRKEY("pi"), LNUMVAL(PI)}, - {LSTRKEY("huge"), LNUMVAL(HUGE_VAL)}, -#endif // #if LUA_OPTIMIZE_MEMORY > 0 + LROT_FUNCENTRY( abs, math_abs ) +// LROT_FUNCENTRY( acos, math_acos ) +// LROT_FUNCENTRY( asin, math_asin ) +// LROT_FUNCENTRY( atan2, math_atan2 ) +// LROT_FUNCENTRY( atan, math_atan ) + LROT_FUNCENTRY( ceil, math_ceil ) +// LROT_FUNCENTRY( cosh, math_cosh ) +// LROT_FUNCENTRY( cos, math_cos ) +// LROT_FUNCENTRY( deg, math_deg ) +// LROT_FUNCENTRY( exp, math_exp ) + LROT_FUNCENTRY( floor, math_floor ) +// LROT_FUNCENTRY( fmod, math_fmod ) +// LROT_FUNCENTRY( mod, math_fmod ) +// LROT_FUNCENTRY( frexp, math_frexp ) +// LROT_FUNCENTRY( ldexp, math_ldexp ) +// LROT_FUNCENTRY( log10, math_log10 ) +// LROT_FUNCENTRY( log, math_log ) + LROT_FUNCENTRY( max, math_max ) + LROT_FUNCENTRY( min, math_min ) +// LROT_FUNCENTRY( modf, math_modf ) + LROT_FUNCENTRY( pow, math_pow ) +// LROT_FUNCENTRY( rad, math_rad ) + LROT_FUNCENTRY( random, math_random ) + LROT_FUNCENTRY( randomseed, math_randomseed ) +// LROT_FUNCENTRY( sinh, math_sinh ) +// LROT_FUNCENTRY( sin, math_sin ) + LROT_FUNCENTRY( sqrt, math_sqrt ) +// LROT_FUNCENTRY( tanh, math_tanh ) +// LROT_FUNCENTRY( tan, math_tan ) + LROT_NUMENTRY( pi, PI ) + LROT_NUMENTRY( huge, HUGE_VAL ) #endif // #ifdef LUA_NUMBER_INTEGRAL - {LNILKEY, LNILVAL} -}; +LROT_END(math, NULL, 0) /* ** Open math library */ - -#if defined LUA_NUMBER_INTEGRAL -# include "c_limits.h" /* for INT_MAX */ -#endif - LUALIB_API int luaopen_math (lua_State *L) { -#if LUA_OPTIMIZE_MEMORY > 0 return 0; -#else - luaL_register(L, LUA_MATHLIBNAME, math_map); -# if defined LUA_NUMBER_INTEGRAL - lua_pushnumber(L, INT_MAX); - lua_setfield(L, -2, "huge"); -# else - lua_pushnumber(L, PI); - lua_setfield(L, -2, "pi"); - lua_pushnumber(L, HUGE_VAL); - lua_setfield(L, -2, "huge"); -# if defined(LUA_COMPAT_MOD) - lua_getfield(L, -1, "fmod"); - lua_setfield(L, -2, "mod"); -# endif -# endif - return 1; -#endif } diff --git a/app/lua/loadlib.c b/app/lua/loadlib.c index 7ed2a5e516..b8cc691143 100644 --- a/app/lua/loadlib.c +++ b/app/lua/loadlib.c @@ -24,6 +24,7 @@ #include "lauxlib.h" #include "lualib.h" +#include "lrotable.h" /* prefix for open functions in C libraries */ #define LUA_POF "luaopen_" @@ -361,7 +362,9 @@ static const char * findfile (lua_State *L, const char *name, const char *pname) { const char *path; name = luaL_gsub(L, name, ".", LUA_DIRSEP); - lua_getfield(L, LUA_ENVIRONINDEX, pname); + lua_getfield(L, LUA_GLOBALSINDEX, "package"); + lua_getfield(L, -1, pname); + lua_remove(L, -2); path = lua_tostring(L, -1); if (path == NULL) luaL_error(L, LUA_QL("package.%s") " must be a string", pname); @@ -447,7 +450,9 @@ static int loader_Croot (lua_State *L) { static int loader_preload (lua_State *L) { const char *name = luaL_checkstring(L, 1); - lua_getfield(L, LUA_ENVIRONINDEX, "preload"); + lua_getfield(L, LUA_GLOBALSINDEX, "package"); + lua_getfield(L, -1, "preload"); + lua_remove(L, -2); if (!lua_istable(L, -1)) luaL_error(L, LUA_QL("package.preload") " must be a table"); lua_getfield(L, -1, name); @@ -480,7 +485,9 @@ static int ll_require (lua_State *L) { lua_pop(L, 1); } /* else must load it; iterate over available loaders */ - lua_getfield(L, LUA_ENVIRONINDEX, "loaders"); + lua_getfield(L, LUA_GLOBALSINDEX, "package"); + lua_getfield(L, -1, "loaders"); + lua_remove(L, -2); if (!lua_istable(L, -1)) luaL_error(L, LUA_QL("package.loaders") " must be a table"); lua_pushliteral(L, ""); /* error message accumulator */ @@ -650,34 +657,20 @@ static const luaL_Reg ll_funcs[] = { 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[] = { - {LRO_STRKEY("__gc"), LRO_FUNCVAL(gctm)}, - {LRO_NILKEY, LRO_NILVAL} -}; -#endif +LROT_PUBLIC_BEGIN(lmt) + LROT_FUNCENTRY(__gc,gctm) +LROT_END(lmt,lmt, LROT_MASK_GC) LUALIB_API int luaopen_package (lua_State *L) { int i; /* create new type _LOADLIB */ -#if LUA_OPTIMIZE_MEMORY == 0 - luaL_newmetatable(L, "_LOADLIB"); - lua_pushlightfunction(L, gctm); - lua_setfield(L, -2, "__gc"); -#else - luaL_rometatable(L, "_LOADLIB", (void*)lmt); -#endif + luaL_rometatable(L, "_LOADLIB",LROT_TABLEREF(lmt)); /* create `package' table */ luaL_register_light(L, LUA_LOADLIBNAME, pk_funcs); #if defined(LUA_COMPAT_LOADLIB) lua_getfield(L, -1, "loadlib"); lua_setfield(L, LUA_GLOBALSINDEX, "loadlib"); #endif - lua_pushvalue(L, -1); - lua_replace(L, LUA_ENVIRONINDEX); /* create `loaders' table */ lua_createtable(L, sizeof(loaders)/sizeof(loaders[0]) - 1, 0); /* fill it with pre-defined loaders */ diff --git a/app/lua/lrodefs.h b/app/lua/lrodefs.h index 32ead3b016..f95490672f 100644 --- a/app/lua/lrodefs.h +++ b/app/lua/lrodefs.h @@ -25,8 +25,7 @@ #define LNUMVAL LRO_NUMVAL #define LROVAL LRO_ROVAL #define LNILVAL LRO_NILVAL -#define LREGISTER(L, name, table)\ - return 0 +#define LREGISTER(L, name, table) return 0 #else #define LUA_REG_TYPE luaL_reg #define LSTRKEY(x) x @@ -38,10 +37,17 @@ return 1 #endif -#define LROT_TABENTRY(n,t) {LSTRKEY(#n), LRO_ROVAL(t)} -#define LROT_FUNCENTRY(n,f) {LSTRKEY(#n), LRO_FUNCVAL(f)} -#define LROT_NUMENTRY(n,x) {LSTRKEY(#n), LRO_NUMVAL(x)} -#define LROT_END {LNILKEY, LNILVAL} +#define LROT_TABLE(t) static const LUA_REG_TYPE t ## _map[]; +#define LROT_TABLEREF(t) ((void *) t ## _map) +#define LROT_BEGIN(t) static const LUA_REG_TYPE t ## _map [] = { +#define LROT_PUBLIC_BEGIN(t) const LUA_REG_TYPE t ## _map[] = { +#define LROT_EXTERN(t) extern const LUA_REG_TYPE t ## _map[] +#define LROT_TABENTRY(n,t) {LRO_STRKEY(#n), LRO_ROVAL(t ## _map)}, +#define LROT_FUNCENTRY(n,f) {LRO_STRKEY(#n), LRO_FUNCVAL(f)}, +#define LROT_NUMENTRY(n,x) {LRO_STRKEY(#n), LRO_NUMVAL(x)}, +#define LROT_LUDENTRY(n,x) {LRO_STRKEY(#n), LRO_LUDATA((void *) x)}, +#define LROT_END(t,mt, f) {LRO_NILKEY, LRO_NILVAL} }; +#define LREGISTER(L, name, table) return 0 #endif /* lrodefs_h */ diff --git a/app/lua/lrotable.c b/app/lua/lrotable.c index 3ee3e5f7fe..80230db864 100644 --- a/app/lua/lrotable.c +++ b/app/lua/lrotable.c @@ -14,7 +14,7 @@ #else #define ALIGNED_STRING (__attribute__((aligned(4))) char *) #endif -#define LA_LINES 16 +#define LA_LINES 32 #define LA_SLOTS 4 //#define COLLECT_STATS @@ -36,7 +36,7 @@ * Note that this hash does a couple of prime multiples and a modulus 2^X * with is all evaluated in H/W, and adequately randomizes the lookup. */ -#define HASH(a,b) (519*((size_t)(a)>>4) + 17*((size_t)(b)>>4)) +#define HASH(a,b) ((((519*(size_t)(a)))>>4) + ((b) ? (b)->tsv.hash: 0)) static struct { unsigned hash; @@ -83,19 +83,18 @@ static void update_cache(unsigned hash, ROTable *rotable, unsigned ndx) { const TValue* luaR_findentry(ROTable *rotable, TString *key, unsigned *ppos) { const luaR_entry *pentry = rotable; const char *strkey = key ? getstr(key) : ALIGNED_STRING "__metatable" ; - size_t hash = HASH(rotable, key); + unsigned hash = HASH(rotable, key); + unsigned i = 0; int j = lookup_cache(hash, rotable); unsigned l = key ? key->tsv.len : sizeof("__metatable")-1; if (pentry) { - if (j >= 0){ - if ((pentry[j].key.type == LUA_TSTRING) && - !c_strcmp(pentry[j].key.id.strkey, strkey)) { - if (ppos) - *ppos = j; - return &pentry[j].value; - } + if (j >= 0 && !c_strcmp(pentry[j].key, strkey)) { + if (ppos) + *ppos = j; +//dbg_printf("%3d hit %p %s\n", (hash>>2) & (LA_LINES-1), rotable, strkey); + return &pentry[j].value; } /* * The invariants for 1st word comparison are deferred to here since they @@ -105,40 +104,22 @@ const TValue* luaR_findentry(ROTable *rotable, TString *key, unsigned *ppos) { unsigned name4, mask4 = l > 2 ? (~0u) : (~0u)>>((3-l)*8); c_memcpy(&name4, strkey, sizeof(name4)); - for(;pentry->key.type != LUA_TNIL; i++, pentry++) { - if ((pentry->key.type == LUA_TSTRING) && - ((*(unsigned *)pentry->key.id.strkey ^ name4) & mask4) == 0 && - !c_strcmp(pentry->key.id.strkey, strkey)) { + for(;pentry->key != NULL; i++, pentry++) { + if (((*(unsigned *)pentry->key ^ name4) & mask4) == 0 && + !c_strcmp(pentry->key, strkey)) { +//dbg_printf("%p %s hit after %d probes \n", rotable, strkey, (int)(rotable-pentry)); if (ppos) *ppos = i; - if (j==-1) { - update_cache(hash, rotable, pentry - rotable); - } else if (j != (pentry - rotable)) { - j = 0; - } - return &pentry->value; + update_cache(hash, rotable, pentry - rotable); +//dbg_printf("%3d %3d %p %s\n", (hash>>2) & (LA_LINES-1), (int)(pentry-rotable), rotable, strkey); + return &pentry->value; } } } +//dbg_printf("%p %s miss after %d probes \n", rotable, strkey, (int)(rotable-pentry)); return luaO_nilobject; } -const TValue* luaR_findentryN(ROTable *rotable, luaR_numkey numkey, unsigned *ppos) { - unsigned i = 0; - const luaR_entry *pentry = rotable; - if (pentry) { - for ( ;pentry->key.type != LUA_TNIL; i++, pentry++) { - if (pentry->key.type == LUA_TNUMBER && (luaR_numkey) pentry->key.id.numkey == numkey) { - if (ppos) - *ppos = i; - return &pentry->value; - } - } - } - return NULL; -} - - /* Find the metatable of a given table */ void* luaR_getmeta(ROTable *rotable) { const TValue *res = luaR_findentry(rotable, NULL, NULL); @@ -147,15 +128,13 @@ void* luaR_getmeta(ROTable *rotable) { static void luaR_next_helper(lua_State *L, ROTable *pentries, int pos, TValue *key, TValue *val) { - setnilvalue(key); - setnilvalue(val); - if (pentries[pos].key.type != LUA_TNIL) { + if (pentries[pos].key) { /* Found an entry */ - if (pentries[pos].key.type == LUA_TSTRING) - setsvalue(L, key, luaS_new(L, pentries[pos].key.id.strkey)) - else - setnvalue(key, (lua_Number)pentries[pos].key.id.numkey) - setobj2s(L, val, &pentries[pos].value); + setsvalue(L, key, luaS_new(L, pentries[pos].key)); + setobj2s(L, val, &pentries[pos].value); + } else { + setnilvalue(key); + setnilvalue(val); } } @@ -167,12 +146,10 @@ void luaR_next(lua_State *L, ROTable *rotable, TValue *key, TValue *val) { /* Special case: if key is nil, return the first element of the rotable */ if (ttisnil(key)) luaR_next_helper(L, rotable, 0, key, val); - else if (ttisstring(key) || ttisnumber(key)) { + else if (ttisstring(key)) { /* Find the previous key again */ if (ttisstring(key)) { luaR_findentry(rotable, rawtsvalue(key), &keypos); - } else { - luaR_findentryN(rotable, (luaR_numkey)nvalue(key), &keypos); } /* Advance to next key */ keypos ++; diff --git a/app/lua/lrotable.h b/app/lua/lrotable.h index 593fca4eb0..c0eb2ec598 100644 --- a/app/lua/lrotable.h +++ b/app/lua/lrotable.h @@ -7,6 +7,7 @@ #include "luaconf.h" #include "lobject.h" #include "llimits.h" +#include "lrotable.h" /* Macros one can use to define rotable entries */ #define LRO_FUNCVAL(v) {{.p = v}, LUA_TLIGHTFUNCTION} @@ -14,13 +15,28 @@ #define LRO_NUMVAL(v) {{.n = v}, LUA_TNUMBER} #define LRO_ROVAL(v) {{.p = (void*)v}, LUA_TROTABLE} #define LRO_NILVAL {{.p = NULL}, LUA_TNIL} + #ifdef LUA_CROSS_COMPILER -#define LRO_STRKEY(k) {LUA_TSTRING, {.strkey = k}} +#define LRO_STRKEY(k) k #else -#define LRO_STRKEY(k) {LUA_TSTRING, {.strkey = (STORE_ATTR char *) k}} +#define LRO_STRKEY(k) ((STORE_ATTR char *) k) #endif -#define LRO_NUMKEY(k) {LUA_TNUMBER, {.numkey = k}} -#define LRO_NILKEY {LUA_TNIL, {.strkey=NULL}} + +#define LROT_TABLE(t) static const LUA_REG_TYPE t ## _map[]; +#define LROT_PUBLIC_TABLE(t) const LUA_REG_TYPE t ## _map[]; +#define LROT_TABLEREF(t) ((void *) t ## _map) +#define LROT_BEGIN(t) static const LUA_REG_TYPE t ## _map [] = { +#define LROT_PUBLIC_BEGIN(t) const LUA_REG_TYPE t ## _map[] = { +#define LROT_EXTERN(t) extern const LUA_REG_TYPE t ## _map[] +#define LROT_TABENTRY(n,t) {LRO_STRKEY(#n), LRO_ROVAL(t ## _map)}, +#define LROT_FUNCENTRY(n,f) {LRO_STRKEY(#n), LRO_FUNCVAL(f)}, +#define LROT_NUMENTRY(n,x) {LRO_STRKEY(#n), LRO_NUMVAL(x)}, +#define LROT_LUDENTRY(n,x) {LRO_STRKEY(#n), LRO_LUDATA((void *) x)}, +#define LROT_END(t,mt, f) {NULL, LRO_NILVAL} }; +#define LROT_BREAK(t) }; + +#define LUA_REG_TYPE luaR_entry +#define LREGISTER(L, name, table) return 0 /* Maximum length of a rotable name and of a string key*/ #define LUA_MAX_ROTABLE_NAME 32 @@ -28,18 +44,9 @@ /* Type of a numeric key in a rotable */ typedef int luaR_numkey; -/* The next structure defines the type of a key */ -typedef struct { - int type; - union { - const char* strkey; - luaR_numkey numkey; - } id; -} luaR_key; - /* An entry in the read only table */ typedef struct luaR_entry { - const luaR_key key; + const char *key; const TValue value; } luaR_entry; diff --git a/app/lua/lstrlib.c b/app/lua/lstrlib.c index ba4fdc976a..2bcd5e8461 100644 --- a/app/lua/lstrlib.c +++ b/app/lua/lstrlib.c @@ -15,12 +15,12 @@ #include "lauxlib.h" #include "lualib.h" +#include "lrotable.h" /* macro to `unsign' a character */ #define uchar(c) ((unsigned char)(c)) - static int str_len (lua_State *L) { size_t l; luaL_checklstring(L, 1, &l); @@ -576,7 +576,7 @@ static int gmatch (lua_State *L) { return 1; } -#if LUA_OPTIMIZE_MEMORY == 0 || !defined(LUA_COMPAT_GFIND) +#ifndef LUA_COMPAT_GFIND static int gfind_nodef (lua_State *L) { return luaL_error(L, LUA_QL("string.gfind") " was renamed to " LUA_QL("string.gmatch")); @@ -824,67 +824,37 @@ 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[] = { - {LSTRKEY("byte"), LFUNCVAL(str_byte)}, - {LSTRKEY("char"), LFUNCVAL(str_char)}, - {LSTRKEY("dump"), LFUNCVAL(str_dump)}, - {LSTRKEY("find"), LFUNCVAL(str_find)}, - {LSTRKEY("format"), LFUNCVAL(str_format)}, -#if LUA_OPTIMIZE_MEMORY > 0 && defined(LUA_COMPAT_GFIND) - {LSTRKEY("gfind"), LFUNCVAL(gmatch)}, +LROT_PUBLIC_BEGIN(strlib) + LROT_FUNCENTRY( byte, str_byte ) + LROT_FUNCENTRY( char, str_char ) + LROT_FUNCENTRY( dump, str_dump ) + LROT_FUNCENTRY( find, str_find ) + LROT_FUNCENTRY( format, str_format ) +#ifdef LUA_COMPAT_GFIND + LROT_FUNCENTRY( gfind, gmatch ) #else - {LSTRKEY("gfind"), LFUNCVAL(gfind_nodef)}, -#endif - {LSTRKEY("gmatch"), LFUNCVAL(gmatch)}, - {LSTRKEY("gsub"), LFUNCVAL(str_gsub)}, - {LSTRKEY("len"), LFUNCVAL(str_len)}, - {LSTRKEY("lower"), LFUNCVAL(str_lower)}, - {LSTRKEY("match"), LFUNCVAL(str_match)}, - {LSTRKEY("rep"), LFUNCVAL(str_rep)}, - {LSTRKEY("reverse"), LFUNCVAL(str_reverse)}, - {LSTRKEY("sub"), LFUNCVAL(str_sub)}, - {LSTRKEY("upper"), LFUNCVAL(str_upper)}, -#if LUA_OPTIMIZE_MEMORY > 0 - {LSTRKEY("__index"), LROVAL(strlib)}, -#endif - {LNILKEY, LNILVAL} -}; - - -#if LUA_OPTIMIZE_MEMORY != 2 -static void createmetatable (lua_State *L) { - lua_createtable(L, 0, 1); /* create metatable for strings */ - lua_pushliteral(L, ""); /* dummy string */ - lua_pushvalue(L, -2); - lua_setmetatable(L, -2); /* set string metatable */ - lua_pop(L, 1); /* pop dummy string */ - lua_pushvalue(L, -2); /* string library... */ - lua_setfield(L, -2, "__index"); /* ...is the __index metamethod */ - lua_pop(L, 1); /* pop metatable */ -} + LROT_FUNCENTRY( gfind, gfind_nodef ) #endif + LROT_FUNCENTRY( gmatch, gmatch ) + LROT_FUNCENTRY( gsub, str_gsub ) + LROT_FUNCENTRY( len, str_len ) + LROT_FUNCENTRY( lower, str_lower ) + LROT_FUNCENTRY( match, str_match ) + LROT_FUNCENTRY( rep, str_rep ) + LROT_FUNCENTRY( reverse, str_reverse ) + LROT_FUNCENTRY( sub, str_sub ) + LROT_FUNCENTRY( upper, str_upper ) + LROT_TABENTRY( __index, strlib ) +LROT_END(strlib, NULL, 0) // OR DO WE NEED LRTO_MASK_INDEX **TODO** /* ** Open string library */ LUALIB_API int luaopen_string (lua_State *L) { -#if LUA_OPTIMIZE_MEMORY == 0 - luaL_register(L, LUA_STRLIBNAME, strlib); -#if defined(LUA_COMPAT_GFIND) - lua_getfield(L, -1, "gmatch"); - lua_setfield(L, -2, "gfind"); -#endif - createmetatable(L); - return 1; -#else lua_pushliteral(L,""); - lua_pushrotable(L, (void*)strlib); + lua_pushrotable(L, LROT_TABLEREF(strlib)); lua_setmetatable(L, -2); lua_pop(L,1); return 0; -#endif } diff --git a/app/lua/ltable.c b/app/lua/ltable.c index c65b67d5f1..8417fc14b5 100644 --- a/app/lua/ltable.c +++ b/app/lua/ltable.c @@ -580,7 +580,7 @@ const TValue *luaH_getnum (Table *t, int key) { /* same thing for rotables */ const TValue *luaH_getnum_ro (void *t, int key) { - const TValue *res = luaR_findentryN(t, key, NULL); + const TValue *res = NULL; // integer values not supported: luaR_findentryN(t, key, NULL); return res ? res : luaO_nilobject; } @@ -739,11 +739,7 @@ int luaH_getn (Table *t) { /* same thing for rotables */ int luaH_getn_ro (void *t) { - int i = 1, len=0; - - while(luaR_findentryN(t, i ++, NULL)) - len ++; - return len; + return 0; // Integer Keys are not currently supported for ROTables } int luaH_isdummy (Node *n) { return n == dummynode; } diff --git a/app/lua/ltablib.c b/app/lua/ltablib.c index 01422eeb7a..d664774d44 100644 --- a/app/lua/ltablib.c +++ b/app/lua/ltablib.c @@ -13,6 +13,7 @@ #include "lauxlib.h" #include "lualib.h" +#include "lrotable.h" #define aux_getn(L,n) (luaL_checktype(L, n, LUA_TTABLE), luaL_getn(L, n)) @@ -265,22 +266,18 @@ static int sort (lua_State *L) { /* }====================================================== */ -#undef MIN_OPT_LEVEL -#define MIN_OPT_LEVEL 1 -#include "lrodefs.h" -const LUA_REG_TYPE tab_funcs[] = { - {LSTRKEY("concat"), LFUNCVAL(tconcat)}, - {LSTRKEY("foreach"), LFUNCVAL(foreach)}, - {LSTRKEY("foreachi"), LFUNCVAL(foreachi)}, - {LSTRKEY("getn"), LFUNCVAL(getn)}, - {LSTRKEY("maxn"), LFUNCVAL(maxn)}, - {LSTRKEY("insert"), LFUNCVAL(tinsert)}, - {LSTRKEY("remove"), LFUNCVAL(tremove)}, - {LSTRKEY("setn"), LFUNCVAL(setn)}, - {LSTRKEY("sort"), LFUNCVAL(sort)}, - {LNILKEY, LNILVAL} -}; +LROT_PUBLIC_BEGIN(tab_funcs) + LROT_FUNCENTRY( concat, tconcat ) + LROT_FUNCENTRY( foreach, foreach ) + LROT_FUNCENTRY( foreachi, foreachi ) + LROT_FUNCENTRY( getn, getn ) + LROT_FUNCENTRY( maxn, maxn ) + LROT_FUNCENTRY( insert, tinsert ) + LROT_FUNCENTRY( remove, tremove ) + LROT_FUNCENTRY( setn, setn ) + LROT_FUNCENTRY( sort, sort ) +LROT_END(tab_funcs, NULL, 0) LUALIB_API int luaopen_table (lua_State *L) { - LREGISTER(L, LUA_TABLIBNAME, tab_funcs); + return 1; } diff --git a/app/lua/luac_cross/Makefile b/app/lua/luac_cross/Makefile index 8f1f42cecb..da133ec5a7 100644 --- a/app/lua/luac_cross/Makefile +++ b/app/lua/luac_cross/Makefile @@ -13,7 +13,7 @@ LDFLAGS:= -L$(SDK_DIR)/lib -L$(SDK_DIR)/ld -lm -ldl -Wl,-Map=mapfile CCFLAGS += -Wall -DEFINES += -DLUA_CROSS_COMPILER -DLUA_OPTIMIZE_MEMORY=2 +DEFINES += -DLUA_CROSS_COMPILER TARGET = host diff --git a/app/lua/luac_cross/liolib.c b/app/lua/luac_cross/liolib.c index 7098a40319..3eda785682 100644 --- a/app/lua/luac_cross/liolib.c +++ b/app/lua/luac_cross/liolib.c @@ -12,12 +12,12 @@ #define liolib_c #define LUA_LIB -#define LUA_OPTIMIZE_MEMORY 2 #include "lua.h" #include "lauxlib.h" #include "lualib.h" +#include "lrotable.h" #define IO_INPUT 1 #define IO_OUTPUT 2 @@ -439,36 +439,31 @@ static int f_flush (lua_State *L) { return pushresult(L, fflush(tofile(L)) == 0, NULL); } -#define MIN_OPT_LEVEL 2 -#include "lrodefs.h" -const LUA_REG_TYPE iolib_funcs[] = { - {LSTRKEY("close"), LFUNCVAL(io_close)}, - {LSTRKEY("flush"), LFUNCVAL(io_flush)}, - {LSTRKEY("input"), LFUNCVAL(io_input)}, - {LSTRKEY("lines"), LFUNCVAL(io_lines)}, - {LSTRKEY("open"), LFUNCVAL(io_open)}, - {LSTRKEY("output"), LFUNCVAL(io_output)}, - {LSTRKEY("read"), LFUNCVAL(io_read)}, - {LSTRKEY("type"), LFUNCVAL(io_type)}, - {LSTRKEY("write"), LFUNCVAL(io_write)}, - {LSTRKEY("__index"), LROVAL(iolib_funcs)}, - {LNILKEY, LNILVAL} -}; - -#include "lrodefs.h" -const LUA_REG_TYPE flib[] = { - {LSTRKEY("close"), LFUNCVAL(io_close)}, - {LSTRKEY("flush"), LFUNCVAL(f_flush)}, - {LSTRKEY("lines"), LFUNCVAL(f_lines)}, - {LSTRKEY("read"), LFUNCVAL(f_read)}, - {LSTRKEY("seek"), LFUNCVAL(f_seek)}, - {LSTRKEY("setvbuf"), LFUNCVAL(f_setvbuf)}, - {LSTRKEY("write"), LFUNCVAL(f_write)}, - {LSTRKEY("__gc"), LFUNCVAL(io_gc)}, - {LSTRKEY("__tostring"), LFUNCVAL(io_tostring)}, - {LSTRKEY("__index"), LROVAL(flib)}, - {LNILKEY, LNILVAL} -}; +LROT_PUBLIC_BEGIN(iolib) + LROT_FUNCENTRY( close, io_close ) + LROT_FUNCENTRY( flush, io_flush ) + LROT_FUNCENTRY( input, io_input ) + LROT_FUNCENTRY( lines, io_lines ) + LROT_FUNCENTRY( open, io_open ) + LROT_FUNCENTRY( output, io_output ) + LROT_FUNCENTRY( read, io_read ) + LROT_FUNCENTRY( type, io_type ) + LROT_FUNCENTRY( write, io_write ) + LROT_TABENTRY( __index, iolib ) +LROT_END(iolib, NULL, 0) + +LROT_BEGIN(flib) + LROT_FUNCENTRY( close, io_close ) + LROT_FUNCENTRY( flush, f_flush ) + LROT_FUNCENTRY( lines, f_lines ) + LROT_FUNCENTRY( read, f_read ) + LROT_FUNCENTRY( seek, f_seek ) + LROT_FUNCENTRY( setvbuf, f_setvbuf ) + LROT_FUNCENTRY( write, f_write ) + LROT_FUNCENTRY( __gc, io_gc ) + LROT_FUNCENTRY( __tostring, io_tostring ) + LROT_TABENTRY( __index, flib ) +LROT_END(flib, NULL, LROT_MASK_GC_INDEX) static const luaL_Reg io_base[] = {{NULL, NULL}}; @@ -481,12 +476,12 @@ static void createstdfile (lua_State *L, FILE *f, int k, const char *fname) { } LUALIB_API int luaopen_io(lua_State *L) { - luaL_rometatable(L, LUA_FILEHANDLE, (void*) flib); /* create metatable for file handles */ + luaL_rometatable(L, LUA_FILEHANDLE, LROT_TABLEREF(flib)); /* create metatable for file handles */ luaL_register_light(L, LUA_IOLIBNAME, io_base); lua_pushvalue(L, -1); lua_setmetatable(L, -2); lua_pushliteral(L, "__index"); - lua_pushrotable(L, (void *)iolib_funcs); + lua_pushrotable(L, LROT_TABLEREF(iolib)); lua_rawset(L, -3); /* create (and set) default files */ diff --git a/app/lua/luac_cross/loslib.c b/app/lua/luac_cross/loslib.c index 6792d48d73..59c22794ba 100644 --- a/app/lua/luac_cross/loslib.c +++ b/app/lua/luac_cross/loslib.c @@ -20,6 +20,7 @@ #include "lauxlib.h" #include "lualib.h" +#include "lrotable.h" static int os_pushresult (lua_State *L, int i, const char *filename) { int en = errno; /* calls to Lua API may change this value */ @@ -219,30 +220,25 @@ 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[] = { - {LSTRKEY("clock"), LFUNCVAL(os_clock)}, - {LSTRKEY("date"), LFUNCVAL(os_date)}, +LROT_PUBLIC_BEGIN(oslib) + LROT_FUNCENTRY( clock, os_clock ) + LROT_FUNCENTRY( date, os_date ) #if !defined LUA_NUMBER_INTEGRAL - {LSTRKEY("difftime"), LFUNCVAL(os_difftime)}, + LROT_FUNCENTRY( difftime, os_difftime ) #endif - {LSTRKEY("execute"), LFUNCVAL(os_execute)}, - {LSTRKEY("exit"), LFUNCVAL(os_exit)}, - {LSTRKEY("getenv"), LFUNCVAL(os_getenv)}, - {LSTRKEY("remove"), LFUNCVAL(os_remove)}, - {LSTRKEY("rename"), LFUNCVAL(os_rename)}, - {LSTRKEY("setlocale"), LFUNCVAL(os_setlocale)}, - {LSTRKEY("time"), LFUNCVAL(os_time)}, - {LSTRKEY("tmpname"), LFUNCVAL(os_tmpname)}, - {LNILKEY, LNILVAL} -}; - + LROT_FUNCENTRY( execute, os_execute ) + LROT_FUNCENTRY( exit, os_exit ) + LROT_FUNCENTRY( getenv, os_getenv ) + LROT_FUNCENTRY( remove, os_remove ) + LROT_FUNCENTRY( rename, os_rename ) + LROT_FUNCENTRY( setlocale, os_setlocale ) + LROT_FUNCENTRY( time, os_time ) + LROT_FUNCENTRY( tmpname, os_tmpname ) +LROT_END(oslib, NULL, 0) /* }====================================================== */ LUALIB_API int luaopen_os (lua_State *L) { - LREGISTER(L, LUA_OSLIBNAME, syslib); + return 1; } diff --git a/app/lua/luaconf.h b/app/lua/luaconf.h index ca8e4b4095..ddea8a76c2 100644 --- a/app/lua/luaconf.h +++ b/app/lua/luaconf.h @@ -910,8 +910,8 @@ union luai_Cast { double l_d; long l_l; }; ** without modifying the main part of the file. */ -#if LUA_OPTIMIZE_MEMORY == 2 && defined(LUA_USE_POPEN) -#error "Pipes not supported in aggresive optimization mode (LUA_OPTIMIZE_MEMORY=2)" +#if defined(LUA_USE_POPEN) +#error "Pipes not supported NodeMCU firmware" #endif #endif diff --git a/app/modules/adc.c b/app/modules/adc.c index 4b79f58d1a..2d9777ca62 100644 --- a/app/modules/adc.c +++ b/app/modules/adc.c @@ -61,13 +61,13 @@ static int adc_init107( lua_State *L ) } // Module function map -static const LUA_REG_TYPE adc_map[] = { - { LSTRKEY( "read" ), LFUNCVAL( adc_sample ) }, - { LSTRKEY( "readvdd33" ), LFUNCVAL( adc_readvdd33 ) }, - { LSTRKEY( "force_init_mode" ), LFUNCVAL( adc_init107 ) }, - { LSTRKEY( "INIT_ADC" ), LNUMVAL( 0x00 ) }, - { LSTRKEY( "INIT_VDD33" ),LNUMVAL( 0xff ) }, - { LNILKEY, LNILVAL } -}; +LROT_BEGIN(adc) + LROT_FUNCENTRY( read, adc_sample ) + LROT_FUNCENTRY( readvdd33, adc_readvdd33 ) + LROT_FUNCENTRY( force_init_mode, adc_init107 ) + LROT_NUMENTRY( INIT_ADC, 0x00 ) + LROT_NUMENTRY( INIT_VDD33, 0xff ) +LROT_END( adc, NULL, 0 ) -NODEMCU_MODULE(ADC, "adc", adc_map, NULL); + +NODEMCU_MODULE(ADC, "adc", adc, NULL); diff --git a/app/modules/ads1115.c b/app/modules/ads1115.c index 1814c81112..0c34436106 100644 --- a/app/modules/ads1115.c +++ b/app/modules/ads1115.c @@ -531,71 +531,68 @@ static int ads1115_lua_delete(lua_State *L) { return 0; } -static const LUA_REG_TYPE ads1115_map[] = { - - { LSTRKEY( "ads1115" ), LFUNCVAL(ads1115_lua_register_1115) }, - { LSTRKEY( "ads1015" ), LFUNCVAL(ads1115_lua_register_1015) }, - { LSTRKEY( "reset" ), LFUNCVAL(ads1115_lua_reset) }, - { LSTRKEY( "ADDR_GND" ), LNUMVAL(ADS1115_I2C_ADDR_GND) }, - { LSTRKEY( "ADDR_VDD" ), LNUMVAL(ADS1115_I2C_ADDR_VDD) }, - { LSTRKEY( "ADDR_SDA" ), LNUMVAL(ADS1115_I2C_ADDR_SDA) }, - { LSTRKEY( "ADDR_SCL" ), LNUMVAL(ADS1115_I2C_ADDR_SCL) }, - { LSTRKEY( "SINGLE_SHOT" ), LNUMVAL(ADS1115_MODE_SINGLE) }, - { LSTRKEY( "CONTINUOUS" ), LNUMVAL(ADS1115_MODE_CONTIN) }, - { LSTRKEY( "DIFF_0_1" ), LNUMVAL(ADS1115_MUX_DIFF_0_1) }, - { LSTRKEY( "DIFF_0_3" ), LNUMVAL(ADS1115_MUX_DIFF_0_3) }, - { LSTRKEY( "DIFF_1_3" ), LNUMVAL(ADS1115_MUX_DIFF_1_3) }, - { LSTRKEY( "DIFF_2_3" ), LNUMVAL(ADS1115_MUX_DIFF_2_3) }, - { LSTRKEY( "SINGLE_0" ), LNUMVAL(ADS1115_MUX_SINGLE_0) }, - { LSTRKEY( "SINGLE_1" ), LNUMVAL(ADS1115_MUX_SINGLE_1) }, - { LSTRKEY( "SINGLE_2" ), LNUMVAL(ADS1115_MUX_SINGLE_2) }, - { LSTRKEY( "SINGLE_3" ), LNUMVAL(ADS1115_MUX_SINGLE_3) }, - { LSTRKEY( "GAIN_6_144V" ), LNUMVAL(ADS1115_PGA_6_144V) }, - { LSTRKEY( "GAIN_4_096V" ), LNUMVAL(ADS1115_PGA_4_096V) }, - { LSTRKEY( "GAIN_2_048V" ), LNUMVAL(ADS1115_PGA_2_048V) }, - { LSTRKEY( "GAIN_1_024V" ), LNUMVAL(ADS1115_PGA_1_024V) }, - { LSTRKEY( "GAIN_0_512V" ), LNUMVAL(ADS1115_PGA_0_512V) }, - { LSTRKEY( "GAIN_0_256V" ), LNUMVAL(ADS1115_PGA_0_256V) }, - { LSTRKEY( "DR_8SPS" ), LNUMVAL(ADS1115_DR_8SPS) }, - { LSTRKEY( "DR_16SPS" ), LNUMVAL(ADS1115_DR_16SPS) }, - { LSTRKEY( "DR_32SPS" ), LNUMVAL(ADS1115_DR_32SPS) }, - { LSTRKEY( "DR_64SPS" ), LNUMVAL(ADS1115_DR_64SPS) }, - { LSTRKEY( "DR_128SPS" ), LNUMVAL(ADS1115_DR_128SPS) }, - { LSTRKEY( "DR_250SPS" ), LNUMVAL(ADS1115_DR_250SPS) }, - { LSTRKEY( "DR_475SPS" ), LNUMVAL(ADS1115_DR_475SPS) }, - { LSTRKEY( "DR_490SPS" ), LNUMVAL(ADS1115_DR_490SPS) }, - { LSTRKEY( "DR_860SPS" ), LNUMVAL(ADS1115_DR_860SPS) }, - { LSTRKEY( "DR_920SPS" ), LNUMVAL(ADS1115_DR_920SPS) }, - { LSTRKEY( "DR_1600SPS" ), LNUMVAL(ADS1115_DR_1600SPS) }, - { LSTRKEY( "DR_2400SPS" ), LNUMVAL(ADS1115_DR_2400SPS) }, - { LSTRKEY( "DR_3300SPS" ), LNUMVAL(ADS1115_DR_3300SPS) }, - { LSTRKEY( "CONV_RDY_1" ), LNUMVAL(ADS1115_CQUE_1CONV) }, - { LSTRKEY( "CONV_RDY_2" ), LNUMVAL(ADS1115_CQUE_2CONV) }, - { LSTRKEY( "CONV_RDY_4" ), LNUMVAL(ADS1115_CQUE_4CONV) }, - { LSTRKEY( "COMP_1CONV" ), LNUMVAL(ADS1115_CQUE_1CONV) }, - { LSTRKEY( "COMP_2CONV" ), LNUMVAL(ADS1115_CQUE_2CONV) }, - { LSTRKEY( "COMP_4CONV" ), LNUMVAL(ADS1115_CQUE_4CONV) }, - { LSTRKEY( "CMODE_TRAD"), LNUMVAL(ADS1115_CMODE_TRAD) }, - { LSTRKEY( "CMODE_WINDOW"), LNUMVAL(ADS1115_CMODE_WINDOW) }, - { LNILKEY, LNILVAL } -}; - -static const LUA_REG_TYPE ads1115_instance_map[] = { - { LSTRKEY( "setting" ), LFUNCVAL(ads1115_lua_setting) }, - { LSTRKEY( "startread" ), LFUNCVAL(ads1115_lua_startread) }, - { LSTRKEY( "read" ), LFUNCVAL(ads1115_lua_read) }, +LROT_BEGIN(ads1115) + LROT_FUNCENTRY( ads1115, ads1115_lua_register_1115 ) + LROT_FUNCENTRY( ads1015, ads1115_lua_register_1015 ) + LROT_FUNCENTRY( reset, ads1115_lua_reset ) + LROT_NUMENTRY( ADDR_GND, ADS1115_I2C_ADDR_GND ) + LROT_NUMENTRY( ADDR_VDD, ADS1115_I2C_ADDR_VDD ) + LROT_NUMENTRY( ADDR_SDA, ADS1115_I2C_ADDR_SDA ) + LROT_NUMENTRY( ADDR_SCL, ADS1115_I2C_ADDR_SCL ) + LROT_NUMENTRY( SINGLE_SHOT, ADS1115_MODE_SINGLE ) + LROT_NUMENTRY( CONTINUOUS, ADS1115_MODE_CONTIN ) + LROT_NUMENTRY( DIFF_0_1, ADS1115_MUX_DIFF_0_1 ) + LROT_NUMENTRY( DIFF_0_3, ADS1115_MUX_DIFF_0_3 ) + LROT_NUMENTRY( DIFF_1_3, ADS1115_MUX_DIFF_1_3 ) + LROT_NUMENTRY( DIFF_2_3, ADS1115_MUX_DIFF_2_3 ) + LROT_NUMENTRY( SINGLE_0, ADS1115_MUX_SINGLE_0 ) + LROT_NUMENTRY( SINGLE_1, ADS1115_MUX_SINGLE_1 ) + LROT_NUMENTRY( SINGLE_2, ADS1115_MUX_SINGLE_2 ) + LROT_NUMENTRY( SINGLE_3, ADS1115_MUX_SINGLE_3 ) + LROT_NUMENTRY( GAIN_6_144V, ADS1115_PGA_6_144V ) + LROT_NUMENTRY( GAIN_4_096V, ADS1115_PGA_4_096V ) + LROT_NUMENTRY( GAIN_2_048V, ADS1115_PGA_2_048V ) + LROT_NUMENTRY( GAIN_1_024V, ADS1115_PGA_1_024V ) + LROT_NUMENTRY( GAIN_0_512V, ADS1115_PGA_0_512V ) + LROT_NUMENTRY( GAIN_0_256V, ADS1115_PGA_0_256V ) + LROT_NUMENTRY( DR_8SPS, ADS1115_DR_8SPS ) + LROT_NUMENTRY( DR_16SPS, ADS1115_DR_16SPS ) + LROT_NUMENTRY( DR_32SPS, ADS1115_DR_32SPS ) + LROT_NUMENTRY( DR_64SPS, ADS1115_DR_64SPS ) + LROT_NUMENTRY( DR_128SPS, ADS1115_DR_128SPS ) + LROT_NUMENTRY( DR_250SPS, ADS1115_DR_250SPS ) + LROT_NUMENTRY( DR_475SPS, ADS1115_DR_475SPS ) + LROT_NUMENTRY( DR_490SPS, ADS1115_DR_490SPS ) + LROT_NUMENTRY( DR_860SPS, ADS1115_DR_860SPS ) + LROT_NUMENTRY( DR_920SPS, ADS1115_DR_920SPS ) + LROT_NUMENTRY( DR_1600SPS, ADS1115_DR_1600SPS ) + LROT_NUMENTRY( DR_2400SPS, ADS1115_DR_2400SPS ) + LROT_NUMENTRY( DR_3300SPS, ADS1115_DR_3300SPS ) + LROT_NUMENTRY( CONV_RDY_1, ADS1115_CQUE_1CONV ) + LROT_NUMENTRY( CONV_RDY_2, ADS1115_CQUE_2CONV ) + LROT_NUMENTRY( CONV_RDY_4, ADS1115_CQUE_4CONV ) + LROT_NUMENTRY( COMP_1CONV, ADS1115_CQUE_1CONV ) + LROT_NUMENTRY( COMP_2CONV, ADS1115_CQUE_2CONV ) + LROT_NUMENTRY( COMP_4CONV, ADS1115_CQUE_4CONV ) + LROT_NUMENTRY( CMODE_TRAD, ADS1115_CMODE_TRAD ) + LROT_NUMENTRY( CMODE_WINDOW, ADS1115_CMODE_WINDOW ) +LROT_END(ads1115, NULL, 0 ) + +LROT_BEGIN(ads1115_instance) + LROT_FUNCENTRY( setting, ads1115_lua_setting ) + LROT_FUNCENTRY( startread, ads1115_lua_startread ) + LROT_FUNCENTRY( read, ads1115_lua_read ) #ifdef ADS1115_INCLUDE_TEST_FUNCTION - { LSTRKEY( "test_volt_conversion" ), LFUNCVAL(test_volt_conversion)}, + LROT_FUNCENTRY( test_volt_conversion, test_volt_conversion ) #endif - { LSTRKEY( "__index" ), LROVAL(ads1115_instance_map) }, - { LSTRKEY( "__gc" ), LFUNCVAL(ads1115_lua_delete) }, - { LNILKEY, LNILVAL } -}; + LROT_TABENTRY( "__index", ads1115_instance ) + LROT_FUNCENTRY( __gc, ads1115_lua_delete ) +LROT_END(ads1115_instance, ads1115_instance, LROT_MASK_GC_INDEX ) int luaopen_ads1115(lua_State *L) { - luaL_rometatable(L, metatable_name, (void *)ads1115_instance_map); + luaL_rometatable(L, metatable_name, LROT_TABLEREF(ads1115_instance)); return 0; } -NODEMCU_MODULE(ADS1115, "ads1115", ads1115_map, luaopen_ads1115); +NODEMCU_MODULE(ADS1115, "ads1115", ads1115, luaopen_ads1115); diff --git a/app/modules/adxl345.c b/app/modules/adxl345.c index 0699af1ab9..2628bdc9f7 100644 --- a/app/modules/adxl345.c +++ b/app/modules/adxl345.c @@ -76,10 +76,10 @@ static int adxl345_read(lua_State* L) { return 3; } -static const LUA_REG_TYPE adxl345_map[] = { - { LSTRKEY( "read" ), LFUNCVAL( adxl345_read )}, - { LSTRKEY( "setup" ), LFUNCVAL( adxl345_setup )}, - { LNILKEY, LNILVAL} -}; +LROT_BEGIN(adxl345) + LROT_FUNCENTRY( read, adxl345_read ) + LROT_FUNCENTRY( setup, adxl345_setup ) +LROT_END( adxl345, NULL, 0 ) -NODEMCU_MODULE(ADXL345, "adxl345", adxl345_map, NULL); + +NODEMCU_MODULE(ADXL345, "adxl345", adxl345, NULL); diff --git a/app/modules/am2320.c b/app/modules/am2320.c index 5ae097888a..4317448b83 100644 --- a/app/modules/am2320.c +++ b/app/modules/am2320.c @@ -129,10 +129,10 @@ static int am2320_read(lua_State* L) return 2; } -static const LUA_REG_TYPE am2320_map[] = { - { LSTRKEY( "read" ), LFUNCVAL( am2320_read )}, - { LSTRKEY( "setup" ), LFUNCVAL( am2320_setup )}, - { LNILKEY, LNILVAL} -}; +LROT_BEGIN(am2320) + LROT_FUNCENTRY( read, am2320_read ) + LROT_FUNCENTRY( setup, am2320_setup ) +LROT_END( am2320, NULL, 0 ) -NODEMCU_MODULE(AM2320, "am2320", am2320_map, NULL); + +NODEMCU_MODULE(AM2320, "am2320", am2320, NULL); diff --git a/app/modules/apa102.c b/app/modules/apa102.c index c43a57b86c..b4db436853 100644 --- a/app/modules/apa102.c +++ b/app/modules/apa102.c @@ -101,15 +101,14 @@ static int apa102_write(lua_State* L) { } -const LUA_REG_TYPE apa102_map[] = -{ - { LSTRKEY( "write" ), LFUNCVAL( apa102_write )}, - { LNILKEY, LNILVAL} -}; +LROT_PUBLIC_BEGIN(apa102) + LROT_FUNCENTRY( write, apa102_write ) +LROT_END( apa102, NULL, 0 ) + LUALIB_API int luaopen_apa102(lua_State *L) { LREGISTER(L, "apa102", apa102_map); return 0; } -NODEMCU_MODULE(APA102, "apa102", apa102_map, luaopen_apa102); +NODEMCU_MODULE(APA102, "apa102", apa102, luaopen_apa102); diff --git a/app/modules/bit.c b/app/modules/bit.c index 7e63d3f9c1..0c2b2e3b56 100644 --- a/app/modules/bit.c +++ b/app/modules/bit.c @@ -119,20 +119,20 @@ static int bit_clear( lua_State* L ) return 1; } -static const LUA_REG_TYPE bit_map[] = { - { LSTRKEY( "bnot" ), LFUNCVAL( bit_bnot ) }, - { LSTRKEY( "band" ), LFUNCVAL( bit_band ) }, - { LSTRKEY( "bor" ), LFUNCVAL( bit_bor ) }, - { LSTRKEY( "bxor" ), LFUNCVAL( bit_bxor ) }, - { LSTRKEY( "lshift" ), LFUNCVAL( bit_lshift ) }, - { LSTRKEY( "rshift" ), LFUNCVAL( bit_rshift ) }, - { LSTRKEY( "arshift" ), LFUNCVAL( bit_arshift ) }, - { LSTRKEY( "bit" ), LFUNCVAL( bit_bit ) }, - { LSTRKEY( "set" ), LFUNCVAL( bit_set ) }, - { LSTRKEY( "clear" ), LFUNCVAL( bit_clear ) }, - { LSTRKEY( "isset" ), LFUNCVAL( bit_isset ) }, - { LSTRKEY( "isclear" ), LFUNCVAL( bit_isclear ) }, - { LNILKEY, LNILVAL} -}; - -NODEMCU_MODULE(BIT, "bit", bit_map, NULL); +LROT_BEGIN(bit) + LROT_FUNCENTRY( bnot, bit_bnot ) + LROT_FUNCENTRY( band, bit_band ) + LROT_FUNCENTRY( bor, bit_bor ) + LROT_FUNCENTRY( bxor, bit_bxor ) + LROT_FUNCENTRY( lshift, bit_lshift ) + LROT_FUNCENTRY( rshift, bit_rshift ) + LROT_FUNCENTRY( arshift, bit_arshift ) + LROT_FUNCENTRY( bit, bit_bit ) + LROT_FUNCENTRY( set, bit_set ) + LROT_FUNCENTRY( clear, bit_clear ) + LROT_FUNCENTRY( isset, bit_isset ) + LROT_FUNCENTRY( isclear, bit_isclear ) +LROT_END( bit, NULL, 0 ) + + +NODEMCU_MODULE(BIT, "bit", bit, NULL); diff --git a/app/modules/bloom.c b/app/modules/bloom.c index afe6760f45..514c347ecd 100644 --- a/app/modules/bloom.c +++ b/app/modules/bloom.c @@ -169,24 +169,24 @@ static int bloom_create(lua_State *L) { return 1; } -static const LUA_REG_TYPE bloom_filter_map[] = { - { LSTRKEY( "add" ), LFUNCVAL( bloom_filter_add ) }, - { LSTRKEY( "check" ), LFUNCVAL( bloom_filter_check ) }, - { LSTRKEY( "reset" ), LFUNCVAL( bloom_filter_reset ) }, - { LSTRKEY( "info" ), LFUNCVAL( bloom_filter_info ) }, - { LSTRKEY( "__index" ), LROVAL( bloom_filter_map ) }, - { LNILKEY, LNILVAL } -}; +LROT_BEGIN(bloom_filter) + LROT_FUNCENTRY( add, bloom_filter_add ) + LROT_FUNCENTRY( check, bloom_filter_check ) + LROT_FUNCENTRY( reset, bloom_filter_reset ) + LROT_FUNCENTRY( info, bloom_filter_info ) + LROT_TABENTRY( __index, bloom_filter ) +LROT_END( bloom_filter, bloom_filter, LROT_MASK_INDEX ) + // Module function map -static const LUA_REG_TYPE bloom_map[] = { - { LSTRKEY( "create" ), LFUNCVAL( bloom_create ) }, - { LNILKEY, LNILVAL } -}; +LROT_BEGIN(bloom) + LROT_FUNCENTRY( create, bloom_create ) +LROT_END( bloom, NULL, 0 ) + LUALIB_API int bloom_open(lua_State *L) { - luaL_rometatable(L, "bloom.filter", (void *)bloom_filter_map); + luaL_rometatable(L, "bloom.filter", LROT_TABLEREF(bloom_filter)); return 1; } -NODEMCU_MODULE(BLOOM, "bloom", bloom_map, bloom_open); +NODEMCU_MODULE(BLOOM, "bloom", bloom, bloom_open); diff --git a/app/modules/bme280.c b/app/modules/bme280.c index 260b5ecde5..b642e8b928 100644 --- a/app/modules/bme280.c +++ b/app/modules/bme280.c @@ -470,17 +470,17 @@ static int bme280_lua_dewpoint(lua_State* L) { return 1; } -static const LUA_REG_TYPE bme280_map[] = { - { LSTRKEY( "setup" ), LFUNCVAL(bme280_lua_setup)}, - { LSTRKEY( "temp" ), LFUNCVAL(bme280_lua_temp)}, - { LSTRKEY( "baro" ), LFUNCVAL(bme280_lua_baro)}, - { LSTRKEY( "humi" ), LFUNCVAL(bme280_lua_humi)}, - { LSTRKEY( "startreadout" ), LFUNCVAL(bme280_lua_startreadout)}, - { LSTRKEY( "qfe2qnh" ), LFUNCVAL(bme280_lua_qfe2qnh)}, - { LSTRKEY( "altitude" ), LFUNCVAL(bme280_lua_altitude)}, - { LSTRKEY( "dewpoint" ), LFUNCVAL(bme280_lua_dewpoint)}, - { LSTRKEY( "read" ), LFUNCVAL(bme280_lua_read)}, - { LNILKEY, LNILVAL} -}; - -NODEMCU_MODULE(BME280, "bme280", bme280_map, NULL); +LROT_BEGIN(bme280) + LROT_FUNCENTRY( setup, bme280_lua_setup ) + LROT_FUNCENTRY( temp, bme280_lua_temp ) + LROT_FUNCENTRY( baro, bme280_lua_baro ) + LROT_FUNCENTRY( humi, bme280_lua_humi ) + LROT_FUNCENTRY( startreadout, bme280_lua_startreadout ) + LROT_FUNCENTRY( qfe2qnh, bme280_lua_qfe2qnh ) + LROT_FUNCENTRY( altitude, bme280_lua_altitude ) + LROT_FUNCENTRY( dewpoint, bme280_lua_dewpoint ) + LROT_FUNCENTRY( read, bme280_lua_read ) +LROT_END( bme280, NULL, 0 ) + + +NODEMCU_MODULE(BME280, "bme280", bme280, NULL); diff --git a/app/modules/bme680.c b/app/modules/bme680.c index 8ffa522902..dfc1c0e9f6 100644 --- a/app/modules/bme680.c +++ b/app/modules/bme680.c @@ -534,14 +534,14 @@ static int bme680_lua_dewpoint(lua_State* L) { return 1; } -static const LUA_REG_TYPE bme680_map[] = { - { LSTRKEY( "setup" ), LFUNCVAL(bme680_lua_setup)}, - { LSTRKEY( "startreadout" ), LFUNCVAL(bme680_lua_startreadout)}, - { LSTRKEY( "qfe2qnh" ), LFUNCVAL(bme680_lua_qfe2qnh)}, - { LSTRKEY( "altitude" ), LFUNCVAL(bme680_lua_altitude)}, - { LSTRKEY( "dewpoint" ), LFUNCVAL(bme680_lua_dewpoint)}, - { LSTRKEY( "read" ), LFUNCVAL(bme680_lua_read)}, - { LNILKEY, LNILVAL} -}; - -NODEMCU_MODULE(BME680, "bme680", bme680_map, NULL); +LROT_BEGIN(bme680) + LROT_FUNCENTRY( setup, bme680_lua_setup ) + LROT_FUNCENTRY( startreadout, bme680_lua_startreadout ) + LROT_FUNCENTRY( qfe2qnh, bme680_lua_qfe2qnh ) + LROT_FUNCENTRY( altitude, bme680_lua_altitude ) + LROT_FUNCENTRY( dewpoint, bme680_lua_dewpoint ) + LROT_FUNCENTRY( read, bme680_lua_read ) +LROT_END( bme680, NULL, 0 ) + + +NODEMCU_MODULE(BME680, "bme680", bme680, NULL); diff --git a/app/modules/bmp085.c b/app/modules/bmp085.c index 6f332b6450..4ccc9e855f 100644 --- a/app/modules/bmp085.c +++ b/app/modules/bmp085.c @@ -169,12 +169,12 @@ static int bmp085_lua_pressure(lua_State* L) { return 1; } -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 )}, - { LSTRKEY( "setup" ), LFUNCVAL( bmp085_setup )}, - { LNILKEY, LNILVAL} -}; - -NODEMCU_MODULE(BMP085, "bmp085", bmp085_map, NULL); +LROT_BEGIN(bmp085) + LROT_FUNCENTRY( temperature, bmp085_lua_temperature ) + LROT_FUNCENTRY( pressure, bmp085_lua_pressure ) + LROT_FUNCENTRY( pressure_raw, bmp085_lua_pressure_raw ) + LROT_FUNCENTRY( setup, bmp085_setup ) +LROT_END( bmp085, NULL, 0 ) + + +NODEMCU_MODULE(BMP085, "bmp085", bmp085, NULL); diff --git a/app/modules/coap.c b/app/modules/coap.c index 8bd74f4b61..2b18b6b24d 100644 --- a/app/modules/coap.c +++ b/app/modules/coap.c @@ -556,48 +556,47 @@ 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 ) }, - { 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 ) }, - { LNILKEY, LNILVAL } -}; - -static 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( "OCTET_STREAM"), LNUMVAL( COAP_CONTENTTYPE_APPLICATION_OCTET_STREAM ) }, - { LSTRKEY( "EXI"), LNUMVAL( COAP_CONTENTTYPE_APPLICATION_EXI ) }, - { LSTRKEY( "JSON"), LNUMVAL( COAP_CONTENTTYPE_APPLICATION_JSON) }, - { LSTRKEY( "__metatable" ), LROVAL( coap_map ) }, - { LNILKEY, LNILVAL } -}; +LROT_BEGIN(coap_server) + LROT_FUNCENTRY( listen, coap_server_listen ) + LROT_FUNCENTRY( close, coap_server_close ) + LROT_FUNCENTRY( var, coap_server_var ) + LROT_FUNCENTRY( func, coap_server_func ) + LROT_FUNCENTRY( __gc, coap_server_delete ) + LROT_TABENTRY( __index, coap_server ) +LROT_END( coap_server, coap_server, 0 ) + + +LROT_BEGIN(coap_client) + LROT_FUNCENTRY( get, coap_client_get ) + LROT_FUNCENTRY( post, coap_client_post ) + LROT_FUNCENTRY( put, coap_client_put ) + LROT_FUNCENTRY( delete, coap_client_delete ) + LROT_FUNCENTRY( __gc, coap_client_gcdelete ) + LROT_TABENTRY( __index, coap_client ) +LROT_END( coap_client, coap_client, 0 ) + + +LROT_BEGIN(coap) + LROT_FUNCENTRY( Server, coap_createServer ) + LROT_FUNCENTRY( Client, coap_createClient ) + LROT_NUMENTRY( CON, COAP_TYPE_CON ) + LROT_NUMENTRY( NON, COAP_TYPE_NONCON ) + LROT_NUMENTRY( TEXT_PLAIN, COAP_CONTENTTYPE_TEXT_PLAIN ) + LROT_NUMENTRY( LINKFORMAT, COAP_CONTENTTYPE_APPLICATION_LINKFORMAT ) + LROT_NUMENTRY( XML, COAP_CONTENTTYPE_APPLICATION_XML ) + LROT_NUMENTRY( OCTET_STREAM, COAP_CONTENTTYPE_APPLICATION_OCTET_STREAM ) + LROT_NUMENTRY( EXI, COAP_CONTENTTYPE_APPLICATION_EXI ) + LROT_NUMENTRY( JSON, COAP_CONTENTTYPE_APPLICATION_JSON ) + LROT_TABENTRY( __metatable, coap ) +LROT_END( coap, coap, 0 ) + 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 + luaL_rometatable(L, "coap_server", LROT_TABLEREF(coap_server)); + luaL_rometatable(L, "coap_client", LROT_TABLEREF(coap_client)); return 0; } -NODEMCU_MODULE(COAP, "coap", coap_map, luaopen_coap); +NODEMCU_MODULE(COAP, "coap", coap, luaopen_coap); diff --git a/app/modules/color_utils.c b/app/modules/color_utils.c index ce244b0a84..6c37cd8cdb 100644 --- a/app/modules/color_utils.c +++ b/app/modules/color_utils.c @@ -234,13 +234,12 @@ static int cu_grb2hsv(lua_State *L) { } -static const LUA_REG_TYPE color_utils_map[] = -{ - { LSTRKEY( "hsv2grb" ), LFUNCVAL( cu_hsv2grb )}, - { LSTRKEY( "hsv2grbw" ), LFUNCVAL( cu_hsv2grbw )}, - { LSTRKEY( "colorWheel" ), LFUNCVAL( cu_color_wheel )}, - { LSTRKEY( "grb2hsv" ), LFUNCVAL( cu_grb2hsv )}, - { LNILKEY, LNILVAL} -}; - -NODEMCU_MODULE(COLOR_UTILS, "color_utils", color_utils_map, NULL); +LROT_BEGIN(color_utils) + LROT_FUNCENTRY( hsv2grb, cu_hsv2grb ) + LROT_FUNCENTRY( hsv2grbw, cu_hsv2grbw ) + LROT_FUNCENTRY( colorWheel, cu_color_wheel ) + LROT_FUNCENTRY( grb2hsv, cu_grb2hsv ) +LROT_END( color_utils, NULL, 0 ) + + +NODEMCU_MODULE(COLOR_UTILS, "color_utils", color_utils, NULL); diff --git a/app/modules/cron.c b/app/modules/cron.c index 2ff16e119b..60175d2f30 100644 --- a/app/modules/cron.c +++ b/app/modules/cron.c @@ -224,20 +224,20 @@ static void cron_handle_tmr() { cron_handle_time(tm.tm_mon + 1, tm.tm_mday, tm.tm_wday, tm.tm_hour, tm.tm_min); } -static const LUA_REG_TYPE cronent_map[] = { - { LSTRKEY( "schedule" ), LFUNCVAL( lcron_schedule ) }, - { LSTRKEY( "handler" ), LFUNCVAL( lcron_handler ) }, - { LSTRKEY( "unschedule" ), LFUNCVAL( lcron_unschedule ) }, - { LSTRKEY( "__gc" ), LFUNCVAL( lcron_delete ) }, - { LSTRKEY( "__index" ), LROVAL( cronent_map ) }, - { LNILKEY, LNILVAL } -}; +LROT_BEGIN(cronent) + LROT_FUNCENTRY( schedule, lcron_schedule ) + LROT_FUNCENTRY( handler, lcron_handler ) + LROT_FUNCENTRY( unschedule, lcron_unschedule ) + LROT_FUNCENTRY( __gc, lcron_delete ) + LROT_TABENTRY( __index, cronent ) +LROT_END( cronent, cronent, LROT_MASK_GC_INDEX ) + + +LROT_BEGIN(cron) + LROT_FUNCENTRY( schedule, lcron_create ) + LROT_FUNCENTRY( reset, lcron_reset ) +LROT_END( cron, NULL, 0 ) -static const LUA_REG_TYPE cron_map[] = { - { LSTRKEY( "schedule" ), LFUNCVAL( lcron_create ) }, - { LSTRKEY( "reset" ), LFUNCVAL( lcron_reset ) }, - { LNILKEY, LNILVAL } -}; #include "pm/swtimer.h" int luaopen_cron( lua_State *L ) { @@ -247,8 +247,8 @@ int luaopen_cron( lua_State *L ) { //cron_handle_tmr determines when to execute a scheduled cron job //My guess: To be sure to give the other modules required by cron enough time to get to a ready state, restart cron_timer. os_timer_arm(&cron_timer, 1000, 0); - luaL_rometatable(L, "cron.entry", (void *)cronent_map); + luaL_rometatable(L, "cron.entry", LROT_TABLEREF(cronent)); return 0; } -NODEMCU_MODULE(CRON, "cron", cron_map, luaopen_cron); +NODEMCU_MODULE(CRON, "cron", cron, luaopen_cron); diff --git a/app/modules/crypto.c b/app/modules/crypto.c index 81fcd28fb3..e648c82ed6 100644 --- a/app/modules/crypto.c +++ b/app/modules/crypto.c @@ -383,34 +383,34 @@ static int lcrypto_decrypt (lua_State *L) } // Hash function map -static const LUA_REG_TYPE crypto_hash_map[] = { - { LSTRKEY( "update" ), LFUNCVAL( crypto_hash_update ) }, - { LSTRKEY( "finalize" ), LFUNCVAL( crypto_hash_finalize ) }, - { LSTRKEY( "__index" ), LROVAL( crypto_hash_map ) }, - { LNILKEY, LNILVAL } -}; +LROT_BEGIN(crypto_hash) + LROT_FUNCENTRY( update, crypto_hash_update ) + LROT_FUNCENTRY( finalize, crypto_hash_finalize ) + LROT_TABENTRY( __index, crypto_hash ) +LROT_END( crypto_hash, crypto_hash, LROT_MASK_INDEX ) + // Module function 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 ) }, - { LSTRKEY( "mask" ), LFUNCVAL( crypto_mask ) }, - { LSTRKEY( "hash" ), LFUNCVAL( crypto_lhash ) }, - { LSTRKEY( "fhash" ), LFUNCVAL( crypto_flhash ) }, - { LSTRKEY( "new_hash" ), LFUNCVAL( crypto_new_hash ) }, - { LSTRKEY( "hmac" ), LFUNCVAL( crypto_lhmac ) }, - { LSTRKEY( "new_hmac" ), LFUNCVAL( crypto_new_hmac ) }, - { LSTRKEY( "encrypt" ), LFUNCVAL( lcrypto_encrypt ) }, - { LSTRKEY( "decrypt" ), LFUNCVAL( lcrypto_decrypt ) }, - { LNILKEY, LNILVAL } -}; +LROT_BEGIN(crypto) + LROT_FUNCENTRY( sha1, crypto_sha1 ) + LROT_FUNCENTRY( toBase64, crypto_base64_encode ) + LROT_FUNCENTRY( toHex, crypto_hex_encode ) + LROT_FUNCENTRY( mask, crypto_mask ) + LROT_FUNCENTRY( hash, crypto_lhash ) + LROT_FUNCENTRY( fhash, crypto_flhash ) + LROT_FUNCENTRY( new_hash, crypto_new_hash ) + LROT_FUNCENTRY( hmac, crypto_lhmac ) + LROT_FUNCENTRY( new_hmac, crypto_new_hmac ) + LROT_FUNCENTRY( encrypt, lcrypto_encrypt ) + LROT_FUNCENTRY( decrypt, lcrypto_decrypt ) +LROT_END( crypto, NULL, 0 ) + int luaopen_crypto ( lua_State *L ) { - luaL_rometatable(L, "crypto.hash", (void *)crypto_hash_map); // create metatable for crypto.hash + luaL_rometatable(L, "crypto.hash", LROT_TABLEREF(crypto_hash)); return 0; } -NODEMCU_MODULE(CRYPTO, "crypto", crypto_map, luaopen_crypto); +NODEMCU_MODULE(CRYPTO, "crypto", crypto, luaopen_crypto); diff --git a/app/modules/dht.c b/app/modules/dht.c index 673ed2f267..85e2bdfb65 100644 --- a/app/modules/dht.c +++ b/app/modules/dht.c @@ -99,14 +99,14 @@ static int dht_lapi_readxx( lua_State *L ) // } // Module function 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 ) }, - { LSTRKEY( "OK" ), LNUMVAL( DHTLIB_OK ) }, - { LSTRKEY( "ERROR_CHECKSUM" ), LNUMVAL( DHTLIB_ERROR_CHECKSUM ) }, - { LSTRKEY( "ERROR_TIMEOUT" ), LNUMVAL( DHTLIB_ERROR_TIMEOUT ) }, - { LNILKEY, LNILVAL } -}; +LROT_BEGIN(dht) + LROT_FUNCENTRY( read, dht_lapi_read ) + LROT_FUNCENTRY( read11, dht_lapi_read11 ) + LROT_FUNCENTRY( readxx, dht_lapi_readxx ) + LROT_NUMENTRY( OK, DHTLIB_OK ) + LROT_NUMENTRY( ERROR_CHECKSUM, DHTLIB_ERROR_CHECKSUM ) + LROT_NUMENTRY( ERROR_TIMEOUT, DHTLIB_ERROR_TIMEOUT ) +LROT_END( dht, NULL, 0 ) -NODEMCU_MODULE(DHT, "dht", dht_map, NULL); + +NODEMCU_MODULE(DHT, "dht", dht, NULL); diff --git a/app/modules/encoder.c b/app/modules/encoder.c index 7160665f9b..b3c1798575 100644 --- a/app/modules/encoder.c +++ b/app/modules/encoder.c @@ -153,12 +153,12 @@ static int do_func (lua_State *L, uint8 * (*conv_func)(lua_State *, const uint8 DECLARE_FUNCTION(toHex); // Module function map -static const LUA_REG_TYPE encoder_map[] = { - { LSTRKEY("fromBase64"), LFUNCVAL(encoder_fromBase64) }, - { LSTRKEY("toBase64"), LFUNCVAL(encoder_toBase64) }, - { LSTRKEY("fromHex"), LFUNCVAL(encoder_fromHex) }, - { LSTRKEY("toHex"), LFUNCVAL(encoder_toHex) }, - { LNILKEY, LNILVAL } -}; - -NODEMCU_MODULE(ENCODER, "encoder", encoder_map, NULL); +LROT_BEGIN(encoder) + LROT_FUNCENTRY( fromBase64, encoder_fromBase64 ) + LROT_FUNCENTRY( toBase64, encoder_toBase64 ) + LROT_FUNCENTRY( fromHex, encoder_fromHex ) + LROT_FUNCENTRY( toHex, encoder_toHex ) +LROT_END( encoder, NULL, 0 ) + + +NODEMCU_MODULE(ENCODER, "encoder", encoder, NULL); diff --git a/app/modules/enduser_setup.c b/app/modules/enduser_setup.c index 8d73442bab..a03a87b0ee 100644 --- a/app/modules/enduser_setup.c +++ b/app/modules/enduser_setup.c @@ -1784,11 +1784,11 @@ static int enduser_setup_stop(lua_State* L) } -static const LUA_REG_TYPE enduser_setup_map[] = { - { LSTRKEY( "manual" ), LFUNCVAL( enduser_setup_manual )}, - { LSTRKEY( "start" ), LFUNCVAL( enduser_setup_start )}, - { LSTRKEY( "stop" ), LFUNCVAL( enduser_setup_stop )}, - { LNILKEY, LNILVAL} -}; - -NODEMCU_MODULE(ENDUSER_SETUP, "enduser_setup", enduser_setup_map, NULL); +LROT_BEGIN(enduser_setup) + LROT_FUNCENTRY( manual, enduser_setup_manual ) + LROT_FUNCENTRY( start, enduser_setup_start ) + LROT_FUNCENTRY( stop, enduser_setup_stop ) +LROT_END( enduser_setup, NULL, 0 ) + + +NODEMCU_MODULE(ENDUSER_SETUP, "enduser_setup", enduser_setup, NULL); diff --git a/app/modules/file.c b/app/modules/file.c index 4986f7c95e..7ca15aa2f9 100644 --- a/app/modules/file.c +++ b/app/modules/file.c @@ -644,64 +644,68 @@ static int file_vol_umount( lua_State *L ) } -static const LUA_REG_TYPE file_obj_map[] = -{ - { LSTRKEY( "close" ), LFUNCVAL( file_close ) }, - { LSTRKEY( "read" ), LFUNCVAL( file_read ) }, - { LSTRKEY( "readline" ), LFUNCVAL( file_readline ) }, - { LSTRKEY( "write" ), LFUNCVAL( file_write ) }, - { LSTRKEY( "writeline" ), LFUNCVAL( file_writeline ) }, - { LSTRKEY( "seek" ), LFUNCVAL( file_seek ) }, - { LSTRKEY( "flush" ), LFUNCVAL( file_flush ) }, - { LSTRKEY( "__gc" ), LFUNCVAL( file_obj_free ) }, - { LSTRKEY( "__index" ), LROVAL( file_obj_map ) }, - { LNILKEY, LNILVAL } -}; - -static const LUA_REG_TYPE file_vol_map[] = -{ - { LSTRKEY( "umount" ), LFUNCVAL( file_vol_umount )}, - //{ LSTRKEY( "getfree" ), LFUNCVAL( file_vol_getfree )}, - //{ LSTRKEY( "getlabel" ), LFUNCVAL( file_vol_getlabel )}, - //{ LSTRKEY( "__gc" ), LFUNCVAL( file_vol_free ) }, - { LSTRKEY( "__index" ), LROVAL( file_vol_map ) }, - { LNILKEY, LNILVAL } -}; +LROT_BEGIN(file_obj) + LROT_FUNCENTRY( close, file_close ) + LROT_FUNCENTRY( read, file_read ) + LROT_FUNCENTRY( readline, file_readline ) + LROT_FUNCENTRY( write, file_write ) + LROT_FUNCENTRY( writeline, file_writeline ) + LROT_FUNCENTRY( seek, file_seek ) + LROT_FUNCENTRY( flush, file_flush ) + LROT_FUNCENTRY( __gc, file_obj_free ) + LROT_TABENTRY( __index, file_obj ) +LROT_END( file_obj, file_obj, LROT_MASK_GC_INDEX ) + + +LROT_BEGIN(file_vol) + LROT_FUNCENTRY( umount, file_vol_umount ) + // LROT_FUNCENTRY( getfree, file_vol_getfree ) + // LROT_FUNCENTRY( getlabel, file_vol_getlabel ) + // LROT_FUNCENTRY( __gc, file_vol_free ) + LROT_TABENTRY( __index, file_vol ) +LROT_END( file_vol, file_vol, LROT_MASK_GC_INDEX ) -// Module function map -static 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 ) }, #ifdef BUILD_SPIFFS - { LSTRKEY( "format" ), LFUNCVAL( file_format ) }, - { LSTRKEY( "fscfg" ), LFUNCVAL( file_fscfg ) }, +#define LROT_FUNCENTRY_S(n,f) LROT_FUNCENTRY(n,f) +#else +#define LROT_FUNCENTRY_S(n,f) #endif - { LSTRKEY( "remove" ), LFUNCVAL( file_remove ) }, - { LSTRKEY( "seek" ), LFUNCVAL( file_seek ) }, - { LSTRKEY( "flush" ), LFUNCVAL( file_flush ) }, - { LSTRKEY( "rename" ), LFUNCVAL( file_rename ) }, - { LSTRKEY( "exists" ), LFUNCVAL( file_exists ) }, - { LSTRKEY( "getcontents" ), LFUNCVAL( file_getfile ) }, - { LSTRKEY( "putcontents" ), LFUNCVAL( file_putfile ) }, - { LSTRKEY( "fsinfo" ), LFUNCVAL( file_fsinfo ) }, - { LSTRKEY( "on" ), LFUNCVAL( file_on ) }, - { LSTRKEY( "stat" ), LFUNCVAL( file_stat ) }, #ifdef BUILD_FATFS - { LSTRKEY( "mount" ), LFUNCVAL( file_mount ) }, - { LSTRKEY( "chdir" ), LFUNCVAL( file_chdir ) }, +#define LROT_FUNCENTRY_F(n,f) LROT_FUNCENTRY(n,f) +#else +#define LROT_FUNCENTRY_F(n,f) #endif - { LNILKEY, LNILVAL } -}; + +// Module function map +LROT_BEGIN(file) + LROT_FUNCENTRY( list, file_list ) + LROT_FUNCENTRY( open, file_open ) + LROT_FUNCENTRY( close, file_close ) + LROT_FUNCENTRY( write, file_write ) + LROT_FUNCENTRY( writeline, file_writeline ) + LROT_FUNCENTRY( read, file_read ) + LROT_FUNCENTRY( readline, file_readline ) + LROT_FUNCENTRY_S( format, file_format ) + LROT_FUNCENTRY_S( fscfg, file_fscfg ) + LROT_FUNCENTRY( remove, file_remove ) + LROT_FUNCENTRY( seek, file_seek ) + LROT_FUNCENTRY( flush, file_flush ) + LROT_FUNCENTRY( rename, file_rename ) + LROT_FUNCENTRY( exists, file_exists ) + LROT_FUNCENTRY( getcontents, file_getfile ) + LROT_FUNCENTRY( putcontents, file_putfile ) + LROT_FUNCENTRY( fsinfo, file_fsinfo ) + LROT_FUNCENTRY( on, file_on ) + LROT_FUNCENTRY( stat, file_stat ) + LROT_FUNCENTRY_F( mount, file_mount ) + LROT_FUNCENTRY_F( chdir, file_chdir ) +LROT_END( file, NULL, 0 ) + int luaopen_file( lua_State *L ) { - luaL_rometatable( L, "file.vol", (void *)file_vol_map ); - luaL_rometatable( L, "file.obj", (void *)file_obj_map ); + luaL_rometatable( L, "file.vol", LROT_TABLEREF(file_vol)); + luaL_rometatable( L, "file.obj", LROT_TABLEREF(file_obj)); return 0; } -NODEMCU_MODULE(FILE, "file", file_map, luaopen_file); +NODEMCU_MODULE(FILE, "file", file, luaopen_file); diff --git a/app/modules/gdbstub.c b/app/modules/gdbstub.c index 007516e17f..9ba6922cf4 100644 --- a/app/modules/gdbstub.c +++ b/app/modules/gdbstub.c @@ -39,11 +39,11 @@ static int lgdbstub_open(lua_State *L) { } // Module function map -static const LUA_REG_TYPE gdbstub_map[] = { - { LSTRKEY( "brk" ), LFUNCVAL( lgdbstub_break ) }, - { LSTRKEY( "gdboutput" ), LFUNCVAL( lgdbstub_gdboutput) }, - { LSTRKEY( "open" ), LFUNCVAL( lgdbstub_open) }, - { LNILKEY, LNILVAL } -}; +LROT_BEGIN(gdbstub) + LROT_FUNCENTRY( brk, lgdbstub_break ) + LROT_FUNCENTRY( gdboutput, lgdbstub_gdboutput ) + LROT_FUNCENTRY( open, lgdbstub_open ) +LROT_END( gdbstub, NULL, 0 ) -NODEMCU_MODULE(GDBSTUB, "gdbstub", gdbstub_map, NULL); + +NODEMCU_MODULE(GDBSTUB, "gdbstub", gdbstub, NULL); diff --git a/app/modules/gpio.c b/app/modules/gpio.c index ff1e77af91..16b79365b8 100644 --- a/app/modules/gpio.c +++ b/app/modules/gpio.c @@ -319,32 +319,32 @@ static int lgpio_serout( lua_State* L ) #undef DELAY_TABLE_MAX_LEN #ifdef LUA_USE_MODULES_GPIO_PULSE -extern const LUA_REG_TYPE gpio_pulse_map[]; +LROT_EXTERN(gpio_pulse); extern int gpio_pulse_init(lua_State *); #endif // Module function map -static 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 ) }, +LROT_BEGIN(gpio) + LROT_FUNCENTRY( mode, lgpio_mode ) + LROT_FUNCENTRY( read, lgpio_read ) + LROT_FUNCENTRY( write, lgpio_write ) + LROT_FUNCENTRY( serout, lgpio_serout ) #ifdef LUA_USE_MODULES_GPIO_PULSE - { LSTRKEY( "pulse" ), LROVAL( gpio_pulse_map ) }, //declared in gpio_pulse.c + LROT_TABENTRY( pulse, gpio_pulse ) #endif #ifdef GPIO_INTERRUPT_ENABLE - { LSTRKEY( "trig" ), LFUNCVAL( lgpio_trig ) }, - { LSTRKEY( "INT" ), LNUMVAL( INTERRUPT ) }, + LROT_FUNCENTRY( trig, lgpio_trig ) + LROT_NUMENTRY( INT, INTERRUPT ) #endif - { LSTRKEY( "OUTPUT" ), LNUMVAL( OUTPUT ) }, - { LSTRKEY( "OPENDRAIN" ), LNUMVAL( OPENDRAIN ) }, - { LSTRKEY( "INPUT" ), LNUMVAL( INPUT ) }, - { LSTRKEY( "HIGH" ), LNUMVAL( HIGH ) }, - { LSTRKEY( "LOW" ), LNUMVAL( LOW ) }, - { LSTRKEY( "FLOAT" ), LNUMVAL( FLOAT ) }, - { LSTRKEY( "PULLUP" ), LNUMVAL( PULLUP ) }, - { LNILKEY, LNILVAL } -}; + LROT_NUMENTRY( OUTPUT, OUTPUT ) + LROT_NUMENTRY( OPENDRAIN, OPENDRAIN ) + LROT_NUMENTRY( INPUT, INPUT ) + LROT_NUMENTRY( HIGH, HIGH ) + LROT_NUMENTRY( LOW, LOW ) + LROT_NUMENTRY( FLOAT, FLOAT ) + LROT_NUMENTRY( PULLUP, PULLUP ) +LROT_END( gpio, NULL, 0 ) + int luaopen_gpio( lua_State *L ) { #ifdef LUA_USE_MODULES_GPIO_PULSE @@ -362,4 +362,4 @@ int luaopen_gpio( lua_State *L ) { return 0; } -NODEMCU_MODULE(GPIO, "gpio", gpio_map, luaopen_gpio); +NODEMCU_MODULE(GPIO, "gpio", gpio, luaopen_gpio); diff --git a/app/modules/gpio_pulse.c b/app/modules/gpio_pulse.c index 265543ade2..bc1197441b 100644 --- a/app/modules/gpio_pulse.c +++ b/app/modules/gpio_pulse.c @@ -467,31 +467,30 @@ static void gpio_pulse_task(os_param_t param, uint8_t prio) } } -static const LUA_REG_TYPE pulse_map[] = { - { LSTRKEY( "getstate" ), LFUNCVAL( gpio_pulse_getstate ) }, - { LSTRKEY( "stop" ), LFUNCVAL( gpio_pulse_stop ) }, - { LSTRKEY( "cancel" ), LFUNCVAL( gpio_pulse_cancel ) }, - { LSTRKEY( "start" ), LFUNCVAL( gpio_pulse_start ) }, - { LSTRKEY( "adjust" ), LFUNCVAL( gpio_pulse_adjust ) }, - { LSTRKEY( "update" ), LFUNCVAL( gpio_pulse_update ) }, - { LSTRKEY( "__gc" ), LFUNCVAL( gpio_pulse_delete ) }, - { LSTRKEY( "__index" ), LROVAL( pulse_map ) }, - { LNILKEY, LNILVAL } -}; - -const LUA_REG_TYPE gpio_pulse_map[] = -{ - { LSTRKEY( "build" ), LFUNCVAL( gpio_pulse_build ) }, - { LSTRKEY( "__index" ), LROVAL( gpio_pulse_map ) }, - { LNILKEY, LNILVAL } -}; +LROT_BEGIN(pulse) + LROT_FUNCENTRY( getstate, gpio_pulse_getstate ) + LROT_FUNCENTRY( stop, gpio_pulse_stop ) + LROT_FUNCENTRY( cancel, gpio_pulse_cancel ) + LROT_FUNCENTRY( start, gpio_pulse_start ) + LROT_FUNCENTRY( adjust, gpio_pulse_adjust ) + LROT_FUNCENTRY( update, gpio_pulse_update ) + LROT_FUNCENTRY( __gc, gpio_pulse_delete ) + LROT_TABENTRY( __index, pulse ) +LROT_END( pulse, pulse, LROT_MASK_GC_INDEX ) + + +LROT_PUBLIC_BEGIN(gpio_pulse) + LROT_FUNCENTRY( build, gpio_pulse_build ) + LROT_TABENTRY( __index, gpio_pulse ) +LROT_END( gpio_pulse, gpio_pulse, LROT_MASK_INDEX ) + int gpio_pulse_init(lua_State *L) { - luaL_rometatable(L, "gpio.pulse", (void *)pulse_map); + luaL_rometatable(L, "gpio.pulse", LROT_TABLEREF(pulse)); tasknumber = task_get_id(gpio_pulse_task); return 0; } -//NODEMCU_MODULE(GPIOPULSE, "gpiopulse", gpio_pulse_map, gpio_pulse_init); +NODEMCU_MODULE(GPIOPULSE, "gpiopulse", gpio_pulse, gpio_pulse_init); diff --git a/app/modules/hdc1080.c b/app/modules/hdc1080.c index 5410340e94..095c3701a5 100644 --- a/app/modules/hdc1080.c +++ b/app/modules/hdc1080.c @@ -99,10 +99,10 @@ static int hdc1080_read(lua_State* L) { return 2; } -static const LUA_REG_TYPE hdc1080_map[] = { - { LSTRKEY( "read" ), LFUNCVAL( hdc1080_read )}, - { LSTRKEY( "setup" ), LFUNCVAL( hdc1080_setup )}, - { LNILKEY, LNILVAL} -}; +LROT_BEGIN(hdc1080) + LROT_FUNCENTRY( read, hdc1080_read ) + LROT_FUNCENTRY( setup, hdc1080_setup ) +LROT_END( hdc1080, NULL, 0 ) -NODEMCU_MODULE(HDC1080, "hdc1080", hdc1080_map, NULL); + +NODEMCU_MODULE(HDC1080, "hdc1080", hdc1080, NULL); diff --git a/app/modules/hmc5883l.c b/app/modules/hmc5883l.c index a228f58fe4..7c0108a0a8 100644 --- a/app/modules/hmc5883l.c +++ b/app/modules/hmc5883l.c @@ -89,10 +89,10 @@ static int hmc5883_read(lua_State* L) { return 3; } -static const LUA_REG_TYPE hmc5883_map[] = { - { LSTRKEY( "read" ), LFUNCVAL( hmc5883_read )}, - { LSTRKEY( "setup" ), LFUNCVAL( hmc5883_setup )}, - { LNILKEY, LNILVAL} -}; +LROT_BEGIN(hmc5883) + LROT_FUNCENTRY( read, hmc5883_read ) + LROT_FUNCENTRY( setup, hmc5883_setup ) +LROT_END( hmc5883, NULL, 0 ) -NODEMCU_MODULE(HMC5883L, "hmc5883l", hmc5883_map, NULL); + +NODEMCU_MODULE(HMC5883L, "hmc5883l", hmc5883, NULL); diff --git a/app/modules/http.c b/app/modules/http.c index c56e80ff9d..87f077acab 100644 --- a/app/modules/http.c +++ b/app/modules/http.c @@ -269,17 +269,17 @@ static int http_lapi_get( lua_State *L ) } // Module function map -static const LUA_REG_TYPE http_map[] = { - { LSTRKEY( "request" ), LFUNCVAL( http_lapi_request ) }, - { LSTRKEY( "post" ), LFUNCVAL( http_lapi_post ) }, - { LSTRKEY( "put" ), LFUNCVAL( http_lapi_put ) }, - { LSTRKEY( "delete" ), LFUNCVAL( http_lapi_delete ) }, - { LSTRKEY( "get" ), LFUNCVAL( http_lapi_get ) }, +LROT_BEGIN(http) + LROT_FUNCENTRY( request, http_lapi_request ) + LROT_FUNCENTRY( post, http_lapi_post ) + LROT_FUNCENTRY( put, http_lapi_put ) + LROT_FUNCENTRY( delete, http_lapi_delete ) + LROT_FUNCENTRY( get, http_lapi_get ) - { LSTRKEY( "OK" ), LNUMVAL( 0 ) }, - { LSTRKEY( "ERROR" ), LNUMVAL( HTTP_STATUS_GENERIC_ERROR ) }, + LROT_NUMENTRY( OK, 0 ) + LROT_NUMENTRY( ERROR, HTTP_STATUS_GENERIC_ERROR ) - { LNILKEY, LNILVAL } -}; +LROT_END( http, NULL, 0 ) -NODEMCU_MODULE(HTTP, "http", http_map, NULL); + +NODEMCU_MODULE(HTTP, "http", http, NULL); diff --git a/app/modules/hx711.c b/app/modules/hx711.c index c5bee07e32..8f89ca7f7b 100644 --- a/app/modules/hx711.c +++ b/app/modules/hx711.c @@ -66,15 +66,15 @@ static int ICACHE_FLASH_ATTR hx711_read(lua_State* L) { } // Module function map -static const LUA_REG_TYPE hx711_map[] = { - { LSTRKEY( "init" ), LFUNCVAL( hx711_init )}, - { LSTRKEY( "read" ), LFUNCVAL( hx711_read )}, - { LNILKEY, LNILVAL} -}; +LROT_BEGIN(hx711) + LROT_FUNCENTRY( init, hx711_init ) + LROT_FUNCENTRY( read, hx711_read ) +LROT_END( hx711, NULL, 0 ) + int luaopen_hx711(lua_State *L) { // TODO: Make sure that the GPIO system is initialized return 0; } -NODEMCU_MODULE(HX711, "hx711", hx711_map, luaopen_hx711); +NODEMCU_MODULE(HX711, "hx711", hx711, luaopen_hx711); diff --git a/app/modules/i2c.c b/app/modules/i2c.c index 07040c141a..ca2aa8bf9e 100644 --- a/app/modules/i2c.c +++ b/app/modules/i2c.c @@ -146,19 +146,19 @@ static int i2c_read( lua_State *L ) } // Module function map -static const LUA_REG_TYPE i2c_map[] = { - { LSTRKEY( "setup" ), LFUNCVAL( i2c_setup ) }, - { LSTRKEY( "start" ), LFUNCVAL( i2c_start ) }, - { LSTRKEY( "stop" ), LFUNCVAL( i2c_stop ) }, - { LSTRKEY( "address" ), LFUNCVAL( i2c_address ) }, - { LSTRKEY( "write" ), LFUNCVAL( i2c_write ) }, - { LSTRKEY( "read" ), LFUNCVAL( i2c_read ) }, - { LSTRKEY( "FASTPLUS" ), LNUMVAL( PLATFORM_I2C_SPEED_FASTPLUS ) }, - { 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 ) }, - { LNILKEY, LNILVAL } -}; - -NODEMCU_MODULE(I2C, "i2c", i2c_map, NULL); +LROT_BEGIN(i2c) + LROT_FUNCENTRY( setup, i2c_setup ) + LROT_FUNCENTRY( start, i2c_start ) + LROT_FUNCENTRY( stop, i2c_stop ) + LROT_FUNCENTRY( address, i2c_address ) + LROT_FUNCENTRY( write, i2c_write ) + LROT_FUNCENTRY( read, i2c_read ) + LROT_NUMENTRY( FASTPLUS, PLATFORM_I2C_SPEED_FASTPLUS ) + LROT_NUMENTRY( FAST, PLATFORM_I2C_SPEED_FAST ) + LROT_NUMENTRY( SLOW, PLATFORM_I2C_SPEED_SLOW ) + LROT_NUMENTRY( TRANSMITTER, PLATFORM_I2C_DIRECTION_TRANSMITTER ) + LROT_NUMENTRY( RECEIVER, PLATFORM_I2C_DIRECTION_RECEIVER ) +LROT_END( i2c, NULL, 0 ) + + +NODEMCU_MODULE(I2C, "i2c", i2c, NULL); diff --git a/app/modules/l3g4200d.c b/app/modules/l3g4200d.c index e7a161a133..a6f2fd765c 100644 --- a/app/modules/l3g4200d.c +++ b/app/modules/l3g4200d.c @@ -79,10 +79,10 @@ static int l3g4200d_read(lua_State* L) { return 3; } -static const LUA_REG_TYPE l3g4200d_map[] = { - { LSTRKEY( "read" ), LFUNCVAL( l3g4200d_read )}, - { LSTRKEY( "setup" ), LFUNCVAL( l3g4200d_setup )}, - { LNILKEY, LNILVAL} -}; +LROT_BEGIN(l3g4200d) + LROT_FUNCENTRY( read, l3g4200d_read ) + LROT_FUNCENTRY( setup, l3g4200d_setup ) +LROT_END( l3g4200d, NULL, 0 ) -NODEMCU_MODULE(L3G4200D, "l3g4200d", l3g4200d_map, NULL); + +NODEMCU_MODULE(L3G4200D, "l3g4200d", l3g4200d, NULL); diff --git a/app/modules/mcp4725.c b/app/modules/mcp4725.c index b91177461b..37fee1fba9 100644 --- a/app/modules/mcp4725.c +++ b/app/modules/mcp4725.c @@ -204,14 +204,14 @@ static int mcp4725_read(lua_State* L){ } -static const LUA_REG_TYPE mcp4725_map[] = { - { LSTRKEY( "write" ), LFUNCVAL( mcp4725_write ) }, - { LSTRKEY( "read" ), LFUNCVAL( mcp4725_read ) }, - { LSTRKEY( "PWRDN_NONE" ), LNUMVAL(MCP4725_POWER_DOWN_NORMAL) }, - { LSTRKEY( "PWRDN_1K" ), LNUMVAL((MCP4725_POWER_DOWN_RES_1K)>>1) }, - { LSTRKEY( "PWRDN_100K" ), LNUMVAL((MCP4725_POWER_DOWN_RES_100K)>>1) }, - { LSTRKEY( "PWRDN_500K" ), LNUMVAL((MCP4725_POWER_DOWN_RES_500K)>>1) }, - { LNILKEY, LNILVAL} -}; - -NODEMCU_MODULE(MCP4725, "mcp4725", mcp4725_map, NULL); +LROT_BEGIN(mcp4725) + LROT_FUNCENTRY( write, mcp4725_write ) + LROT_FUNCENTRY( read, mcp4725_read ) + LROT_NUMENTRY( PWRDN_NONE, MCP4725_POWER_DOWN_NORMAL ) + LROT_NUMENTRY( PWRDN_1K, MCP4725_POWER_DOWN_RES_1K>>1 ) + LROT_NUMENTRY( PWRDN_100K, MCP4725_POWER_DOWN_RES_100K>>1 ) + LROT_NUMENTRY( PWRDN_500K, MCP4725_POWER_DOWN_RES_500K>>1 ) +LROT_END( mcp4725, NULL, 0 ) + + +NODEMCU_MODULE(MCP4725, "mcp4725", mcp4725, NULL); diff --git a/app/modules/mdns.c b/app/modules/mdns.c index 1137907b16..5afeb30e8e 100644 --- a/app/modules/mdns.c +++ b/app/modules/mdns.c @@ -88,10 +88,10 @@ static int mdns_register(lua_State *L) } // Module function map -static const LUA_REG_TYPE mdns_map[] = { - { LSTRKEY("register"), LFUNCVAL(mdns_register) }, - { LSTRKEY("close"), LFUNCVAL(mdns_close) }, - { LNILKEY, LNILVAL } -}; +LROT_BEGIN(mdns) + LROT_FUNCENTRY( register, mdns_register ) + LROT_FUNCENTRY( close, mdns_close ) +LROT_END( mdns, NULL, 0 ) -NODEMCU_MODULE(MDNS, "mdns", mdns_map, NULL); + +NODEMCU_MODULE(MDNS, "mdns", mdns, NULL); diff --git a/app/modules/mqtt.c b/app/modules/mqtt.c index d0f9d7aea9..92570c04ec 100644 --- a/app/modules/mqtt.c +++ b/app/modules/mqtt.c @@ -1873,43 +1873,43 @@ static int mqtt_socket_lwt( lua_State* L ) } // Module function map -static const LUA_REG_TYPE mqtt_socket_map[] = { - { LSTRKEY( "connect" ), LFUNCVAL( mqtt_socket_connect ) }, - { LSTRKEY( "close" ), LFUNCVAL( mqtt_socket_close ) }, - { LSTRKEY( "publish" ), LFUNCVAL( mqtt_socket_publish ) }, - { LSTRKEY( "subscribe" ), LFUNCVAL( mqtt_socket_subscribe ) }, - { LSTRKEY( "unsubscribe" ), LFUNCVAL( mqtt_socket_unsubscribe ) }, - { LSTRKEY( "lwt" ), LFUNCVAL( mqtt_socket_lwt ) }, - { LSTRKEY( "on" ), LFUNCVAL( mqtt_socket_on ) }, - { LSTRKEY( "__gc" ), LFUNCVAL( mqtt_delete ) }, - { LSTRKEY( "__index" ), LROVAL( mqtt_socket_map ) }, - { LNILKEY, LNILVAL } -}; - - -static const LUA_REG_TYPE mqtt_map[] = { - { LSTRKEY( "Client" ), LFUNCVAL( mqtt_socket_client ) }, - - { LSTRKEY( "CONN_FAIL_SERVER_NOT_FOUND" ), LNUMVAL( MQTT_CONN_FAIL_SERVER_NOT_FOUND ) }, - { LSTRKEY( "CONN_FAIL_NOT_A_CONNACK_MSG" ), LNUMVAL( MQTT_CONN_FAIL_NOT_A_CONNACK_MSG ) }, - { LSTRKEY( "CONN_FAIL_DNS" ), LNUMVAL( MQTT_CONN_FAIL_DNS ) }, - { LSTRKEY( "CONN_FAIL_TIMEOUT_RECEIVING" ), LNUMVAL( MQTT_CONN_FAIL_TIMEOUT_RECEIVING ) }, - { LSTRKEY( "CONN_FAIL_TIMEOUT_SENDING" ), LNUMVAL( MQTT_CONN_FAIL_TIMEOUT_SENDING ) }, - { LSTRKEY( "CONNACK_ACCEPTED" ), LNUMVAL( MQTT_CONNACK_ACCEPTED ) }, - { LSTRKEY( "CONNACK_REFUSED_PROTOCOL_VER" ), LNUMVAL( MQTT_CONNACK_REFUSED_PROTOCOL_VER ) }, - { LSTRKEY( "CONNACK_REFUSED_ID_REJECTED" ), LNUMVAL( MQTT_CONNACK_REFUSED_ID_REJECTED ) }, - { LSTRKEY( "CONNACK_REFUSED_SERVER_UNAVAILABLE" ), LNUMVAL( MQTT_CONNACK_REFUSED_SERVER_UNAVAILABLE ) }, - { LSTRKEY( "CONNACK_REFUSED_BAD_USER_OR_PASS" ), LNUMVAL( MQTT_CONNACK_REFUSED_BAD_USER_OR_PASS ) }, - { LSTRKEY( "CONNACK_REFUSED_NOT_AUTHORIZED" ), LNUMVAL( MQTT_CONNACK_REFUSED_NOT_AUTHORIZED ) }, - - { LSTRKEY( "__metatable" ), LROVAL( mqtt_map ) }, - { LNILKEY, LNILVAL } -}; +LROT_BEGIN(mqtt_socket) + LROT_FUNCENTRY( connect, mqtt_socket_connect ) + LROT_FUNCENTRY( close, mqtt_socket_close ) + LROT_FUNCENTRY( publish, mqtt_socket_publish ) + LROT_FUNCENTRY( subscribe, mqtt_socket_subscribe ) + LROT_FUNCENTRY( unsubscribe, mqtt_socket_unsubscribe ) + LROT_FUNCENTRY( lwt, mqtt_socket_lwt ) + LROT_FUNCENTRY( on, mqtt_socket_on ) + LROT_FUNCENTRY( __gc, mqtt_delete ) + LROT_TABENTRY( __index, mqtt_socket ) +LROT_END( mqtt_socket, mqtt_socket, 0 ) + + + +LROT_BEGIN(mqtt) + LROT_FUNCENTRY( Client, mqtt_socket_client ) + + LROT_NUMENTRY( CONN_FAIL_SERVER_NOT_FOUND, MQTT_CONN_FAIL_SERVER_NOT_FOUND ) + LROT_NUMENTRY( CONN_FAIL_NOT_A_CONNACK_MSG, MQTT_CONN_FAIL_NOT_A_CONNACK_MSG ) + LROT_NUMENTRY( CONN_FAIL_DNS, MQTT_CONN_FAIL_DNS ) + LROT_NUMENTRY( CONN_FAIL_TIMEOUT_RECEIVING, MQTT_CONN_FAIL_TIMEOUT_RECEIVING ) + LROT_NUMENTRY( CONN_FAIL_TIMEOUT_SENDING, MQTT_CONN_FAIL_TIMEOUT_SENDING ) + LROT_NUMENTRY( CONNACK_ACCEPTED, MQTT_CONNACK_ACCEPTED ) + LROT_NUMENTRY( CONNACK_REFUSED_PROTOCOL_VER, MQTT_CONNACK_REFUSED_PROTOCOL_VER ) + LROT_NUMENTRY( CONNACK_REFUSED_ID_REJECTED, MQTT_CONNACK_REFUSED_ID_REJECTED ) + LROT_NUMENTRY( CONNACK_REFUSED_SERVER_UNAVAILABLE, MQTT_CONNACK_REFUSED_SERVER_UNAVAILABLE ) + LROT_NUMENTRY( CONNACK_REFUSED_BAD_USER_OR_PASS, MQTT_CONNACK_REFUSED_BAD_USER_OR_PASS ) + LROT_NUMENTRY( CONNACK_REFUSED_NOT_AUTHORIZED, MQTT_CONNACK_REFUSED_NOT_AUTHORIZED ) + + LROT_TABENTRY( __metatable, mqtt ) +LROT_END( mqtt, mqtt, 0 ) + int luaopen_mqtt( lua_State *L ) { - luaL_rometatable(L, "mqtt.socket", (void *)mqtt_socket_map); // create metatable for mqtt.socket + luaL_rometatable(L, "mqtt.socket", LROT_TABLEREF(mqtt_socket)); return 0; } -NODEMCU_MODULE(MQTT, "mqtt", mqtt_map, luaopen_mqtt); +NODEMCU_MODULE(MQTT, "mqtt", mqtt, luaopen_mqtt); diff --git a/app/modules/net.c b/app/modules/net.c index 12010b9c08..1336089d69 100644 --- a/app/modules/net.c +++ b/app/modules/net.c @@ -968,79 +968,79 @@ static int net_getdnsserver( lua_State* L ) { #pragma mark - Tables #ifdef TLS_MODULE_PRESENT -extern const LUA_REG_TYPE tls_cert_map[]; +LROT_EXTERN(tls_cert); #endif // Module function map -static const LUA_REG_TYPE net_tcpserver_map[] = { - { LSTRKEY( "listen" ), LFUNCVAL( net_listen ) }, - { LSTRKEY( "getaddr" ), LFUNCVAL( net_getaddr ) }, - { LSTRKEY( "close" ), LFUNCVAL( net_close ) }, - { LSTRKEY( "__gc" ), LFUNCVAL( net_delete ) }, - { LSTRKEY( "__index" ), LROVAL( net_tcpserver_map ) }, - { LNILKEY, LNILVAL } -}; - -static const LUA_REG_TYPE net_tcpsocket_map[] = { - { LSTRKEY( "connect" ), LFUNCVAL( net_connect ) }, - { LSTRKEY( "close" ), LFUNCVAL( net_close ) }, - { LSTRKEY( "on" ), LFUNCVAL( net_on ) }, - { LSTRKEY( "send" ), LFUNCVAL( net_send ) }, - { LSTRKEY( "hold" ), LFUNCVAL( net_hold ) }, - { LSTRKEY( "unhold" ), LFUNCVAL( net_unhold ) }, - { LSTRKEY( "dns" ), LFUNCVAL( net_dns ) }, - { LSTRKEY( "ttl" ), LFUNCVAL( net_ttl ) }, - { LSTRKEY( "getpeer" ), LFUNCVAL( net_getpeer ) }, - { LSTRKEY( "getaddr" ), LFUNCVAL( net_getaddr ) }, - { LSTRKEY( "__gc" ), LFUNCVAL( net_delete ) }, - { LSTRKEY( "__index" ), LROVAL( net_tcpsocket_map ) }, - { LNILKEY, LNILVAL } -}; - -static const LUA_REG_TYPE net_udpsocket_map[] = { - { LSTRKEY( "listen" ), LFUNCVAL( net_listen ) }, - { LSTRKEY( "close" ), LFUNCVAL( net_close ) }, - { LSTRKEY( "on" ), LFUNCVAL( net_on ) }, - { LSTRKEY( "send" ), LFUNCVAL( net_send ) }, - { LSTRKEY( "dns" ), LFUNCVAL( net_dns ) }, - { LSTRKEY( "ttl" ), LFUNCVAL( net_ttl ) }, - { LSTRKEY( "getaddr" ), LFUNCVAL( net_getaddr ) }, - { LSTRKEY( "__gc" ), LFUNCVAL( net_delete ) }, - { LSTRKEY( "__index" ), LROVAL( net_udpsocket_map ) }, - { LNILKEY, LNILVAL } -}; - -static const LUA_REG_TYPE net_dns_map[] = { - { LSTRKEY( "setdnsserver" ), LFUNCVAL( net_setdnsserver ) }, - { LSTRKEY( "getdnsserver" ), LFUNCVAL( net_getdnsserver ) }, - { LSTRKEY( "resolve" ), LFUNCVAL( net_dns_static ) }, - { LNILKEY, LNILVAL } -}; - -static const LUA_REG_TYPE net_map[] = { - { LSTRKEY( "createServer" ), LFUNCVAL( net_createServer ) }, - { LSTRKEY( "createConnection" ), LFUNCVAL( net_createConnection ) }, - { LSTRKEY( "createUDPSocket" ), LFUNCVAL( net_createUDPSocket ) }, - { LSTRKEY( "multicastJoin"), LFUNCVAL( net_multicastJoin ) }, - { LSTRKEY( "multicastLeave"), LFUNCVAL( net_multicastLeave ) }, - { LSTRKEY( "dns" ), LROVAL( net_dns_map ) }, +LROT_BEGIN(net_tcpserver) + LROT_FUNCENTRY( listen, net_listen ) + LROT_FUNCENTRY( getaddr, net_getaddr ) + LROT_FUNCENTRY( close, net_close ) + LROT_FUNCENTRY( __gc, net_delete ) + LROT_TABENTRY( __index, net_tcpserver ) +LROT_END( net_tcpserver, net_tcpserver, 0 ) + + +LROT_BEGIN(net_tcpsocket) + LROT_FUNCENTRY( connect, net_connect ) + LROT_FUNCENTRY( close, net_close ) + LROT_FUNCENTRY( on, net_on ) + LROT_FUNCENTRY( send, net_send ) + LROT_FUNCENTRY( hold, net_hold ) + LROT_FUNCENTRY( unhold, net_unhold ) + LROT_FUNCENTRY( dns, net_dns ) + LROT_FUNCENTRY( ttl, net_ttl ) + LROT_FUNCENTRY( getpeer, net_getpeer ) + LROT_FUNCENTRY( getaddr, net_getaddr ) + LROT_FUNCENTRY( __gc, net_delete ) + LROT_TABENTRY( __index, net_tcpsocket ) +LROT_END( net_tcpsocket, net_tcpsocket, 0 ) + + +LROT_BEGIN(net_udpsocket) + LROT_FUNCENTRY( listen, net_listen ) + LROT_FUNCENTRY( close, net_close ) + LROT_FUNCENTRY( on, net_on ) + LROT_FUNCENTRY( send, net_send ) + LROT_FUNCENTRY( dns, net_dns ) + LROT_FUNCENTRY( ttl, net_ttl ) + LROT_FUNCENTRY( getaddr, net_getaddr ) + LROT_FUNCENTRY( __gc, net_delete ) + LROT_TABENTRY( __index, net_udpsocket ) +LROT_END( net_udpsocket, net_udpsocket, 0 ) + + +LROT_BEGIN(net_dns) + LROT_FUNCENTRY( setdnsserver, net_setdnsserver ) + LROT_FUNCENTRY( getdnsserver, net_getdnsserver ) + LROT_FUNCENTRY( resolve, net_dns_static ) +LROT_END( net_dns, net_dns, 0 ) + + +LROT_BEGIN(net) + LROT_FUNCENTRY( createServer, net_createServer ) + LROT_FUNCENTRY( createConnection, net_createConnection ) + LROT_FUNCENTRY( createUDPSocket, net_createUDPSocket ) + LROT_FUNCENTRY( multicastJoin, net_multicastJoin ) + LROT_FUNCENTRY( multicastLeave, net_multicastLeave ) + LROT_TABENTRY( dns, net_dns ) #ifdef TLS_MODULE_PRESENT - { LSTRKEY( "cert" ), LROVAL( tls_cert_map ) }, + LROT_TABENTRY( cert, tls_cert ) #endif - { LSTRKEY( "TCP" ), LNUMVAL( TYPE_TCP ) }, - { LSTRKEY( "UDP" ), LNUMVAL( TYPE_UDP ) }, - { LSTRKEY( "__metatable" ), LROVAL( net_map ) }, - { LNILKEY, LNILVAL } -}; + LROT_NUMENTRY( TCP, TYPE_TCP ) + LROT_NUMENTRY( UDP, TYPE_UDP ) + LROT_TABENTRY( __metatable, net ) +LROT_END( net, net, 0 ) + int luaopen_net( lua_State *L ) { igmp_init(); - luaL_rometatable(L, NET_TABLE_TCP_SERVER, (void *)net_tcpserver_map); - luaL_rometatable(L, NET_TABLE_TCP_CLIENT, (void *)net_tcpsocket_map); - luaL_rometatable(L, NET_TABLE_UDP_SOCKET, (void *)net_udpsocket_map); + luaL_rometatable(L, NET_TABLE_TCP_SERVER, LROT_TABLEREF(net_tcpserver)); + luaL_rometatable(L, NET_TABLE_TCP_CLIENT, LROT_TABLEREF(net_tcpsocket)); + luaL_rometatable(L, NET_TABLE_UDP_SOCKET, LROT_TABLEREF(net_udpsocket)); return 0; } -NODEMCU_MODULE(NET, "net", net_map, luaopen_net); +NODEMCU_MODULE(NET, "net", net, luaopen_net); diff --git a/app/modules/node.c b/app/modules/node.c index c4285605dc..db33dc25c2 100644 --- a/app/modules/node.c +++ b/app/modules/node.c @@ -15,7 +15,6 @@ #include "lundump.h" #include "platform.h" -#include "lrodefs.h" #include "lflash.h" #include "c_types.h" #include "c_string.h" @@ -593,13 +592,13 @@ static int node_writercr (lua_State *L) { typedef enum pt_t { lfs_addr=0, lfs_size, spiffs_addr, spiffs_size, max_pt} pt_t; -static const LUA_REG_TYPE pt_map[] = { - { LSTRKEY( "lfs_addr" ), LNUMVAL( lfs_addr ) }, - { LSTRKEY( "lfs_size" ), LNUMVAL( lfs_size ) }, - { LSTRKEY( "spiffs_addr" ), LNUMVAL( spiffs_addr ) }, - { LSTRKEY( "spiffs_size" ), LNUMVAL( spiffs_size ) }, - { LNILKEY, LNILVAL } -}; +LROT_BEGIN(pt) + LROT_NUMENTRY( lfs_addr, lfs_addr ) + LROT_NUMENTRY( lfs_size, lfs_size ) + LROT_NUMENTRY( spiffs_addr, spiffs_addr ) + LROT_NUMENTRY( spiffs_size, spiffs_size ) +LROT_END( pt, NULL, 0 ) + // Lua: ptinfo = node.getpartitiontable() static int node_getpartitiontable (lua_State *L) { @@ -745,69 +744,67 @@ static int node_setpartitiontable (lua_State *L) { // Module function map -static const LUA_REG_TYPE node_egc_map[] = { - { LSTRKEY( "meminfo" ), LFUNCVAL( node_egc_meminfo ) }, - { LSTRKEY( "setmode" ), LFUNCVAL( node_egc_setmode ) }, - { LSTRKEY( "NOT_ACTIVE" ), LNUMVAL( EGC_NOT_ACTIVE ) }, - { LSTRKEY( "ON_ALLOC_FAILURE" ), LNUMVAL( EGC_ON_ALLOC_FAILURE ) }, - { LSTRKEY( "ON_MEM_LIMIT" ), LNUMVAL( EGC_ON_MEM_LIMIT ) }, - { LSTRKEY( "ALWAYS" ), LNUMVAL( EGC_ALWAYS ) }, - { LNILKEY, LNILVAL } -}; -static const LUA_REG_TYPE node_task_map[] = { - { LSTRKEY( "post" ), LFUNCVAL( node_task_post ) }, - { LSTRKEY( "LOW_PRIORITY" ), LNUMVAL( TASK_PRIORITY_LOW ) }, - { LSTRKEY( "MEDIUM_PRIORITY" ), LNUMVAL( TASK_PRIORITY_MEDIUM ) }, - { LSTRKEY( "HIGH_PRIORITY" ), LNUMVAL( TASK_PRIORITY_HIGH ) }, - { LNILKEY, LNILVAL } -}; - -static const LUA_REG_TYPE node_map[] = -{ - { LSTRKEY( "heap" ), LFUNCVAL( node_heap ) }, - { LSTRKEY( "info" ), LFUNCVAL( node_info ) }, - { LSTRKEY( "task" ), LROVAL( node_task_map ) }, - { LSTRKEY( "flashreload" ), LFUNCVAL( luaN_reload_reboot ) }, - { LSTRKEY( "flashindex" ), LFUNCVAL( luaN_index ) }, - { LSTRKEY( "restart" ), LFUNCVAL( node_restart ) }, - { LSTRKEY( "dsleep" ), LFUNCVAL( node_deepsleep ) }, - { LSTRKEY( "dsleepMax" ), LFUNCVAL( dsleepMax ) }, - { LSTRKEY( "sleep" ), LFUNCVAL( node_sleep ) }, +LROT_BEGIN(node_egc) + LROT_FUNCENTRY( meminfo, node_egc_meminfo ) + LROT_FUNCENTRY( setmode, node_egc_setmode ) + LROT_NUMENTRY( NOT_ACTIVE, EGC_NOT_ACTIVE ) + LROT_NUMENTRY( ON_ALLOC_FAILURE, EGC_ON_ALLOC_FAILURE ) + LROT_NUMENTRY( ON_MEM_LIMIT, EGC_ON_MEM_LIMIT ) + LROT_NUMENTRY( ALWAYS, EGC_ALWAYS ) +LROT_END( node_egc, NULL, 0 ) + +LROT_BEGIN(node_task) + LROT_FUNCENTRY( post, node_task_post ) + LROT_NUMENTRY( LOW_PRIORITY, TASK_PRIORITY_LOW ) + LROT_NUMENTRY( MEDIUM_PRIORITY, TASK_PRIORITY_MEDIUM ) + LROT_NUMENTRY( HIGH_PRIORITY, TASK_PRIORITY_HIGH ) +LROT_END( node_task, NULL, 0 ) + +LROT_BEGIN(node) + LROT_FUNCENTRY( heap, node_heap ) + LROT_FUNCENTRY( info, node_info ) + LROT_TABENTRY( task, node_task ) + LROT_FUNCENTRY( flashreload, luaN_reload_reboot ) + LROT_FUNCENTRY( flashindex, luaN_index ) + LROT_FUNCENTRY( restart, node_restart ) + LROT_FUNCENTRY( dsleep, node_deepsleep ) + LROT_FUNCENTRY( dsleepMax, dsleepMax ) + LROT_FUNCENTRY( sleep, node_sleep ) #ifdef PMSLEEP_ENABLE PMSLEEP_INT_MAP, #endif #ifdef DEVELOPMENT_TOOLS - { LSTRKEY( "readrcr" ), LFUNCVAL( node_readrcr ) }, - { LSTRKEY( "writercr" ), LFUNCVAL( node_writercr ) }, + LROT_FUNCENTRY( readrcr, node_readrcr ) + LROT_FUNCENTRY( writercr, node_writercr ) #endif - { LSTRKEY( "chipid" ), LFUNCVAL( node_chipid ) }, - { LSTRKEY( "flashid" ), LFUNCVAL( node_flashid ) }, - { LSTRKEY( "flashsize" ), LFUNCVAL( node_flashsize) }, - { LSTRKEY( "input" ), LFUNCVAL( node_input ) }, - { LSTRKEY( "output" ), LFUNCVAL( node_output ) }, + LROT_FUNCENTRY( chipid, node_chipid ) + LROT_FUNCENTRY( flashid, node_flashid ) + LROT_FUNCENTRY( flashsize, node_flashsize ) + LROT_FUNCENTRY( input, node_input ) + LROT_FUNCENTRY( output, node_output ) // Moved to adc module, use adc.readvdd33() -// { LSTRKEY( "readvdd33" ), LFUNCVAL( node_readvdd33) }, - { LSTRKEY( "compile" ), LFUNCVAL( node_compile) }, - { LSTRKEY( "CPU80MHZ" ), LNUMVAL( CPU80MHZ ) }, - { LSTRKEY( "CPU160MHZ" ), LNUMVAL( CPU160MHZ ) }, - { LSTRKEY( "setcpufreq" ), LFUNCVAL( node_setcpufreq) }, - { LSTRKEY( "getcpufreq" ), LFUNCVAL( node_getcpufreq) }, - { LSTRKEY( "bootreason" ), LFUNCVAL( node_bootreason) }, - { LSTRKEY( "restore" ), LFUNCVAL( node_restore) }, - { LSTRKEY( "random" ), LFUNCVAL( node_random) }, +// LROT_FUNCENTRY( readvdd33, node_readvdd33 ) + LROT_FUNCENTRY( compile, node_compile ) + LROT_NUMENTRY( CPU80MHZ, CPU80MHZ ) + LROT_NUMENTRY( CPU160MHZ, CPU160MHZ ) + LROT_FUNCENTRY( setcpufreq, node_setcpufreq ) + LROT_FUNCENTRY( getcpufreq, node_getcpufreq ) + LROT_FUNCENTRY( bootreason, node_bootreason ) + LROT_FUNCENTRY( restore, node_restore ) + LROT_FUNCENTRY( random, node_random ) #ifdef LUA_OPTIMIZE_DEBUG - { LSTRKEY( "stripdebug" ), LFUNCVAL( node_stripdebug ) }, + LROT_FUNCENTRY( stripdebug, node_stripdebug ) #endif - { LSTRKEY( "egc" ), LROVAL( node_egc_map ) }, + LROT_TABENTRY( egc, node_egc ) #ifdef DEVELOPMENT_TOOLS - { LSTRKEY( "osprint" ), LFUNCVAL( node_osprint ) }, + LROT_FUNCENTRY( osprint, node_osprint ) #endif - { LSTRKEY( "getpartitiontable" ), LFUNCVAL( node_getpartitiontable ) }, - { LSTRKEY( "setpartitiontable" ), LFUNCVAL( node_setpartitiontable ) }, + LROT_FUNCENTRY( getpartitiontable, node_getpartitiontable ) + LROT_FUNCENTRY( setpartitiontable, node_setpartitiontable ) // Combined to dsleep(us, option) -// { LSTRKEY( "dsleepsetoption" ), LFUNCVAL( node_deepsleep_setoption) }, - { LNILKEY, LNILVAL } -}; +// LROT_FUNCENTRY( dsleepsetoption, node_deepsleep_setoption ) +LROT_END( node, NULL, 0 ) + -NODEMCU_MODULE(NODE, "node", node_map, NULL); +NODEMCU_MODULE(NODE, "node", node, NULL); diff --git a/app/modules/ow.c b/app/modules/ow.c index e1574010d6..06a07404fd 100644 --- a/app/modules/ow.c +++ b/app/modules/ow.c @@ -282,29 +282,29 @@ static int ow_crc16( lua_State *L ) #endif // Module function map -static const LUA_REG_TYPE ow_map[] = { - { LSTRKEY( "setup" ), LFUNCVAL( ow_setup ) }, - { LSTRKEY( "reset" ), LFUNCVAL( ow_reset ) }, - { LSTRKEY( "skip" ), LFUNCVAL( ow_skip ) }, - { LSTRKEY( "select" ), LFUNCVAL( ow_select ) }, - { LSTRKEY( "write" ), LFUNCVAL( ow_write ) }, - { LSTRKEY( "write_bytes" ), LFUNCVAL( ow_write_bytes ) }, - { LSTRKEY( "read" ), LFUNCVAL( ow_read ) }, - { LSTRKEY( "read_bytes" ), LFUNCVAL( ow_read_bytes ) }, - { LSTRKEY( "depower" ), LFUNCVAL( ow_depower ) }, +LROT_BEGIN(ow) + LROT_FUNCENTRY( setup, ow_setup ) + LROT_FUNCENTRY( reset, ow_reset ) + LROT_FUNCENTRY( skip, ow_skip ) + LROT_FUNCENTRY( select, ow_select ) + LROT_FUNCENTRY( write, ow_write ) + LROT_FUNCENTRY( write_bytes, ow_write_bytes ) + LROT_FUNCENTRY( read, ow_read ) + LROT_FUNCENTRY( read_bytes, ow_read_bytes ) + LROT_FUNCENTRY( depower, ow_depower ) #if ONEWIRE_SEARCH - { LSTRKEY( "reset_search" ), LFUNCVAL( ow_reset_search ) }, - { LSTRKEY( "target_search" ), LFUNCVAL( ow_target_search ) }, - { LSTRKEY( "search" ), LFUNCVAL( ow_search ) }, + LROT_FUNCENTRY( reset_search, ow_reset_search ) + LROT_FUNCENTRY( target_search, ow_target_search ) + LROT_FUNCENTRY( search, ow_search ) #endif #if ONEWIRE_CRC - { LSTRKEY( "crc8" ), LFUNCVAL( ow_crc8 ) }, + LROT_FUNCENTRY( crc8, ow_crc8 ) #if ONEWIRE_CRC16 - { LSTRKEY( "check_crc16" ), LFUNCVAL( ow_check_crc16 ) }, - { LSTRKEY( "crc16" ), LFUNCVAL( ow_crc16 ) }, + LROT_FUNCENTRY( check_crc16, ow_check_crc16 ) + LROT_FUNCENTRY( crc16, ow_crc16 ) #endif #endif - { LNILKEY, LNILVAL } -}; +LROT_END( ow, NULL, 0 ) -NODEMCU_MODULE(OW, "ow", ow_map, NULL); + +NODEMCU_MODULE(OW, "ow", ow, NULL); diff --git a/app/modules/pcm.c b/app/modules/pcm.c index 8b4ebee8b9..5193ec63d1 100644 --- a/app/modules/pcm.c +++ b/app/modules/pcm.c @@ -229,34 +229,34 @@ static int pcm_new( lua_State *L ) } -static const LUA_REG_TYPE pcm_driver_map[] = { - { LSTRKEY( "play" ), LFUNCVAL( pcm_drv_play ) }, - { LSTRKEY( "pause" ), LFUNCVAL( pcm_drv_pause ) }, - { LSTRKEY( "stop" ), LFUNCVAL( pcm_drv_stop ) }, - { LSTRKEY( "close" ), LFUNCVAL( pcm_drv_close ) }, - { LSTRKEY( "on" ), LFUNCVAL( pcm_drv_on ) }, - { LSTRKEY( "__gc" ), LFUNCVAL( pcm_drv_free ) }, - { LSTRKEY( "__index" ), LROVAL( pcm_driver_map ) }, - { LNILKEY, LNILVAL } -}; +LROT_BEGIN(pcm_driver) + LROT_FUNCENTRY( play, pcm_drv_play ) + LROT_FUNCENTRY( pause, pcm_drv_pause ) + LROT_FUNCENTRY( stop, pcm_drv_stop ) + LROT_FUNCENTRY( close, pcm_drv_close ) + LROT_FUNCENTRY( on, pcm_drv_on ) + LROT_FUNCENTRY( __gc, pcm_drv_free ) + LROT_TABENTRY( __index, pcm_driver ) +LROT_END( pcm_driver, pcm_driver, LROT_MASK_GC_INDEX ) + // Module function map -static const LUA_REG_TYPE pcm_map[] = { - { LSTRKEY( "new" ), LFUNCVAL( pcm_new ) }, - { LSTRKEY( "SD" ), LNUMVAL( PCM_DRIVER_SD ) }, - { LSTRKEY( "RATE_1K" ), LNUMVAL( PCM_RATE_1K ) }, - { LSTRKEY( "RATE_2K" ), LNUMVAL( PCM_RATE_2K ) }, - { LSTRKEY( "RATE_4K" ), LNUMVAL( PCM_RATE_4K ) }, - { LSTRKEY( "RATE_5K" ), LNUMVAL( PCM_RATE_5K ) }, - { LSTRKEY( "RATE_8K" ), LNUMVAL( PCM_RATE_8K ) }, - { LSTRKEY( "RATE_10K" ), LNUMVAL( PCM_RATE_10K ) }, - { LSTRKEY( "RATE_12K" ), LNUMVAL( PCM_RATE_12K ) }, - { LSTRKEY( "RATE_16K" ), LNUMVAL( PCM_RATE_16K ) }, - { LNILKEY, LNILVAL } -}; +LROT_BEGIN(pcm) + LROT_FUNCENTRY( new, pcm_new ) + LROT_NUMENTRY( SD, PCM_DRIVER_SD ) + LROT_NUMENTRY( RATE_1K, PCM_RATE_1K ) + LROT_NUMENTRY( RATE_2K, PCM_RATE_2K ) + LROT_NUMENTRY( RATE_4K, PCM_RATE_4K ) + LROT_NUMENTRY( RATE_5K, PCM_RATE_5K ) + LROT_NUMENTRY( RATE_8K, PCM_RATE_8K ) + LROT_NUMENTRY( RATE_10K, PCM_RATE_10K ) + LROT_NUMENTRY( RATE_12K, PCM_RATE_12K ) + LROT_NUMENTRY( RATE_16K, PCM_RATE_16K ) +LROT_END( pcm, NULL, 0 ) + int luaopen_pcm( lua_State *L ) { - luaL_rometatable( L, "pcm.driver", (void *)pcm_driver_map ); // create metatable + luaL_rometatable( L, "pcm.driver", LROT_TABLEREF(pcm_driver)); pcm_data_vu_task = task_get_id( pcm_data_vu ); pcm_data_play_task = task_get_id( pcm_data_play ); @@ -264,4 +264,4 @@ int luaopen_pcm( lua_State *L ) { return 0; } -NODEMCU_MODULE(PCM, "pcm", pcm_map, luaopen_pcm); +NODEMCU_MODULE(PCM, "pcm", pcm, luaopen_pcm); diff --git a/app/modules/perf.c b/app/modules/perf.c index c287b0ccb2..fc5f712ebe 100644 --- a/app/modules/perf.c +++ b/app/modules/perf.c @@ -135,10 +135,10 @@ static int perf_stop(lua_State *L) return 4; } -static const LUA_REG_TYPE perf_map[] = { - { LSTRKEY( "start" ), LFUNCVAL( perf_start ) }, - { LSTRKEY( "stop" ), LFUNCVAL( perf_stop ) }, - { LNILKEY, LNILVAL } -}; +LROT_BEGIN(perf) + LROT_FUNCENTRY( start, perf_start ) + LROT_FUNCENTRY( stop, perf_stop ) +LROT_END( perf, NULL, 0 ) -NODEMCU_MODULE(PERF, "perf", perf_map, NULL); + +NODEMCU_MODULE(PERF, "perf", perf, NULL); diff --git a/app/modules/pwm.c b/app/modules/pwm.c index c48aef2bb3..8296e43346 100644 --- a/app/modules/pwm.c +++ b/app/modules/pwm.c @@ -128,16 +128,16 @@ int lpwm_open( lua_State *L ) { } // Module function map -static const LUA_REG_TYPE pwm_map[] = { - { LSTRKEY( "setup" ), LFUNCVAL( lpwm_setup ) }, - { LSTRKEY( "close" ), LFUNCVAL( lpwm_close ) }, - { LSTRKEY( "start" ), LFUNCVAL( lpwm_start ) }, - { LSTRKEY( "stop" ), LFUNCVAL( lpwm_stop ) }, - { LSTRKEY( "setclock" ), LFUNCVAL( lpwm_setclock ) }, - { LSTRKEY( "getclock" ), LFUNCVAL( lpwm_getclock ) }, - { LSTRKEY( "setduty" ), LFUNCVAL( lpwm_setduty ) }, - { LSTRKEY( "getduty" ), LFUNCVAL( lpwm_getduty ) }, - { LNILKEY, LNILVAL } -}; - -NODEMCU_MODULE(PWM, "pwm", pwm_map, lpwm_open); +LROT_BEGIN(pwm) + LROT_FUNCENTRY( setup, lpwm_setup ) + LROT_FUNCENTRY( close, lpwm_close ) + LROT_FUNCENTRY( start, lpwm_start ) + LROT_FUNCENTRY( stop, lpwm_stop ) + LROT_FUNCENTRY( setclock, lpwm_setclock ) + LROT_FUNCENTRY( getclock, lpwm_getclock ) + LROT_FUNCENTRY( setduty, lpwm_setduty ) + LROT_FUNCENTRY( getduty, lpwm_getduty ) +LROT_END( pwm, NULL, 0 ) + + +NODEMCU_MODULE(PWM, "pwm", pwm, lpwm_open); diff --git a/app/modules/rc.c b/app/modules/rc.c index 72c0dff471..4f4c85e689 100644 --- a/app/modules/rc.c +++ b/app/modules/rc.c @@ -81,14 +81,14 @@ static int ICACHE_FLASH_ATTR rc_send(lua_State* L) { } // Module function map -static const LUA_REG_TYPE rc_map[] = { - { LSTRKEY( "send" ), LFUNCVAL( rc_send )}, - { LNILKEY, LNILVAL} -}; +LROT_BEGIN(rc) + LROT_FUNCENTRY( send, rc_send ) +LROT_END( rc, NULL, 0 ) + int luaopen_rc(lua_State *L) { // TODO: Make sure that the GPIO system is initialized return 0; } -NODEMCU_MODULE(RC, "rc", rc_map, luaopen_rc); +NODEMCU_MODULE(RC, "rc", rc, luaopen_rc); diff --git a/app/modules/rfswitch.c b/app/modules/rfswitch.c index cdcb64fd18..5d59e5b43d 100644 --- a/app/modules/rfswitch.c +++ b/app/modules/rfswitch.c @@ -102,10 +102,9 @@ static int rfswitch_send( lua_State *L ) } // Module function map -static const LUA_REG_TYPE rfswitch_map[] = -{ - { LSTRKEY( "send" ), LFUNCVAL( rfswitch_send ) }, - { LNILKEY, LNILVAL } -}; +LROT_BEGIN(rfswitch) + LROT_FUNCENTRY( send, rfswitch_send ) +LROT_END( rfswitch, NULL, 0 ) + -NODEMCU_MODULE(RFSWITCH, "rfswitch", rfswitch_map, NULL); +NODEMCU_MODULE(RFSWITCH, "rfswitch", rfswitch, NULL); diff --git a/app/modules/rotary.c b/app/modules/rotary.c index eb96481e02..5436b56f3d 100644 --- a/app/modules/rotary.c +++ b/app/modules/rotary.c @@ -395,20 +395,20 @@ static int rotary_open(lua_State *L) } // Module function map -static const LUA_REG_TYPE rotary_map[] = { - { LSTRKEY( "setup" ), LFUNCVAL( lrotary_setup ) }, - { LSTRKEY( "close" ), LFUNCVAL( lrotary_close ) }, - { LSTRKEY( "on" ), LFUNCVAL( lrotary_on ) }, - { LSTRKEY( "getpos" ), LFUNCVAL( lrotary_getpos) }, - { LSTRKEY( "TURN" ), LNUMVAL( MASK(TURN) ) }, - { LSTRKEY( "PRESS" ), LNUMVAL( MASK(PRESS) ) }, - { LSTRKEY( "RELEASE" ), LNUMVAL( MASK(RELEASE) ) }, - { LSTRKEY( "LONGPRESS" ),LNUMVAL( MASK(LONGPRESS) ) }, - { LSTRKEY( "CLICK" ), LNUMVAL( MASK(CLICK) ) }, - { LSTRKEY( "DBLCLICK" ), LNUMVAL( MASK(DBLCLICK)) }, - { LSTRKEY( "ALL" ), LNUMVAL( ROTARY_ALL ) }, - - { LNILKEY, LNILVAL } -}; - -NODEMCU_MODULE(ROTARY, "rotary", rotary_map, rotary_open); +LROT_BEGIN(rotary) + LROT_FUNCENTRY( setup, lrotary_setup ) + LROT_FUNCENTRY( close, lrotary_close ) + LROT_FUNCENTRY( on, lrotary_on ) + LROT_FUNCENTRY( getpos, lrotary_getpos ) + LROT_NUMENTRY( TURN, MASK(TURN) ) + LROT_NUMENTRY( PRESS, MASK(PRESS) ) + LROT_NUMENTRY( RELEASE, MASK(RELEASE) ) + LROT_NUMENTRY( LONGPRESS, MASK(LONGPRESS) ) + LROT_NUMENTRY( CLICK, MASK(CLICK) ) + LROT_NUMENTRY( DBLCLICK, MASK(DBLCLICK) ) + LROT_NUMENTRY( ALL, ROTARY_ALL ) + +LROT_END( rotary, NULL, 0 ) + + +NODEMCU_MODULE(ROTARY, "rotary", rotary, rotary_open); diff --git a/app/modules/rtcfifo.c b/app/modules/rtcfifo.c index 4e0e54abdd..dfea7777f1 100644 --- a/app/modules/rtcfifo.c +++ b/app/modules/rtcfifo.c @@ -165,18 +165,18 @@ static int rtcfifo_dsleep_until_sample (lua_State *L) #endif // Module function map -static const LUA_REG_TYPE rtcfifo_map[] = { - { LSTRKEY("prepare"), LFUNCVAL(rtcfifo_prepare) }, - { LSTRKEY("ready"), LFUNCVAL(rtcfifo_ready) }, - { LSTRKEY("put"), LFUNCVAL(rtcfifo_put) }, - { LSTRKEY("pop"), LFUNCVAL(rtcfifo_pop) }, - { LSTRKEY("peek"), LFUNCVAL(rtcfifo_peek) }, - { LSTRKEY("drop"), LFUNCVAL(rtcfifo_drop) }, - { LSTRKEY("count"), LFUNCVAL(rtcfifo_count) }, +LROT_BEGIN(rtcfifo) + LROT_FUNCENTRY( prepare, rtcfifo_prepare ) + LROT_FUNCENTRY( ready, rtcfifo_ready ) + LROT_FUNCENTRY( put, rtcfifo_put ) + LROT_FUNCENTRY( pop, rtcfifo_pop ) + LROT_FUNCENTRY( peek, rtcfifo_peek ) + LROT_FUNCENTRY( drop, rtcfifo_drop ) + LROT_FUNCENTRY( count, rtcfifo_count ) #ifdef LUA_USE_MODULES_RTCTIME - { LSTRKEY("dsleep_until_sample"), LFUNCVAL(rtcfifo_dsleep_until_sample) }, + LROT_FUNCENTRY( dsleep_until_sample, rtcfifo_dsleep_until_sample ) #endif - { LNILKEY, LNILVAL } -}; +LROT_END( rtcfifo, NULL, 0 ) -NODEMCU_MODULE(RTCFIFO, "rtcfifo", rtcfifo_map, NULL); + +NODEMCU_MODULE(RTCFIFO, "rtcfifo", rtcfifo, NULL); diff --git a/app/modules/rtcmem.c b/app/modules/rtcmem.c index 1aea2acb9d..8dc90dd5b1 100644 --- a/app/modules/rtcmem.c +++ b/app/modules/rtcmem.c @@ -41,10 +41,10 @@ static int rtcmem_write32 (lua_State *L) // Module function map -static const LUA_REG_TYPE rtcmem_map[] = { - { LSTRKEY("read32"), LFUNCVAL(rtcmem_read32) }, - { LSTRKEY("write32"), LFUNCVAL(rtcmem_write32) }, - { LNILKEY, LNILVAL } -}; +LROT_BEGIN(rtcmem) + LROT_FUNCENTRY( read32, rtcmem_read32 ) + LROT_FUNCENTRY( write32, rtcmem_write32 ) +LROT_END( rtcmem, NULL, 0 ) -NODEMCU_MODULE(RTCMEM, "rtcmem", rtcmem_map, NULL); + +NODEMCU_MODULE(RTCMEM, "rtcmem", rtcmem, NULL); diff --git a/app/modules/rtctime.c b/app/modules/rtctime.c index fc806287e4..d24de5d98d 100644 --- a/app/modules/rtctime.c +++ b/app/modules/rtctime.c @@ -228,14 +228,14 @@ static int rtctime_epoch2cal (lua_State *L) } // Module function map -static const LUA_REG_TYPE rtctime_map[] = { - { LSTRKEY("set"), LFUNCVAL(rtctime_set) }, - { LSTRKEY("get"), LFUNCVAL(rtctime_get) }, - { LSTRKEY("adjust_delta"), LFUNCVAL(rtctime_adjust_delta) }, - { LSTRKEY("dsleep"), LFUNCVAL(rtctime_dsleep) }, - { LSTRKEY("dsleep_aligned"), LFUNCVAL(rtctime_dsleep_aligned) }, - { LSTRKEY("epoch2cal"), LFUNCVAL(rtctime_epoch2cal) }, - { LNILKEY, LNILVAL } -}; - -NODEMCU_MODULE(RTCTIME, "rtctime", rtctime_map, NULL); +LROT_BEGIN(rtctime) + LROT_FUNCENTRY( set, rtctime_set ) + LROT_FUNCENTRY( get, rtctime_get ) + LROT_FUNCENTRY( adjust_delta, rtctime_adjust_delta ) + LROT_FUNCENTRY( dsleep, rtctime_dsleep ) + LROT_FUNCENTRY( dsleep_aligned, rtctime_dsleep_aligned ) + LROT_FUNCENTRY( epoch2cal, rtctime_epoch2cal ) +LROT_END( rtctime, NULL, 0 ) + + +NODEMCU_MODULE(RTCTIME, "rtctime", rtctime, NULL); diff --git a/app/modules/si7021.c b/app/modules/si7021.c index fbcbebc43b..6d882480b2 100644 --- a/app/modules/si7021.c +++ b/app/modules/si7021.c @@ -247,19 +247,19 @@ static int si7021_lua_firmware(lua_State* L) { return 1; } -static const LUA_REG_TYPE si7021_map[] = { - { LSTRKEY( "setup" ), LFUNCVAL(si7021_lua_setup) }, - { LSTRKEY( "setting" ), LFUNCVAL(si7021_lua_setting) }, - { LSTRKEY( "read" ), LFUNCVAL(si7021_lua_read) }, - { LSTRKEY( "serial" ), LFUNCVAL(si7021_lua_serial) }, - { LSTRKEY( "firmware" ), LFUNCVAL(si7021_lua_firmware) }, - { LSTRKEY( "RH12_TEMP14" ), LNUMVAL(SI7021_RH12_TEMP14) }, - { LSTRKEY( "RH08_TEMP12" ), LNUMVAL(SI7021_RH08_TEMP12) }, - { LSTRKEY( "RH10_TEMP13" ), LNUMVAL(SI7021_RH10_TEMP13) }, - { LSTRKEY( "RH11_TEMP11" ), LNUMVAL(SI7021_RH11_TEMP11) }, - { LSTRKEY( "HEATER_ENABLE" ), LNUMVAL(SI7021_HEATER_ENABLE) }, - { LSTRKEY( "HEATER_DISABLE" ), LNUMVAL(SI7021_HEATER_DISABLE) }, - { LNILKEY, LNILVAL } -}; - -NODEMCU_MODULE(SI7021, "si7021", si7021_map, NULL); +LROT_BEGIN(si7021) + LROT_FUNCENTRY( setup, si7021_lua_setup ) + LROT_FUNCENTRY( setting, si7021_lua_setting ) + LROT_FUNCENTRY( read, si7021_lua_read ) + LROT_FUNCENTRY( serial, si7021_lua_serial ) + LROT_FUNCENTRY( firmware, si7021_lua_firmware ) + LROT_NUMENTRY( RH12_TEMP14, SI7021_RH12_TEMP14 ) + LROT_NUMENTRY( RH08_TEMP12, SI7021_RH08_TEMP12 ) + LROT_NUMENTRY( RH10_TEMP13, SI7021_RH10_TEMP13 ) + LROT_NUMENTRY( RH11_TEMP11, SI7021_RH11_TEMP11 ) + LROT_NUMENTRY( HEATER_ENABLE, SI7021_HEATER_ENABLE ) + LROT_NUMENTRY( HEATER_DISABLE, SI7021_HEATER_DISABLE ) +LROT_END( si7021, NULL, 0 ) + + +NODEMCU_MODULE(SI7021, "si7021", si7021, NULL); diff --git a/app/modules/sigma_delta.c b/app/modules/sigma_delta.c index 7bcbb7e711..53d03fcf44 100644 --- a/app/modules/sigma_delta.c +++ b/app/modules/sigma_delta.c @@ -74,14 +74,13 @@ static int sigma_delta_settarget( lua_State *L ) // Module function map -static const LUA_REG_TYPE sigma_delta_map[] = -{ - { LSTRKEY( "setup" ), LFUNCVAL( sigma_delta_setup ) }, - { LSTRKEY( "close" ), LFUNCVAL( sigma_delta_close ) }, - { LSTRKEY( "setpwmduty" ), LFUNCVAL( sigma_delta_setpwmduty ) }, - { LSTRKEY( "setprescale" ), LFUNCVAL( sigma_delta_setprescale ) }, - { LSTRKEY( "settarget" ), LFUNCVAL( sigma_delta_settarget ) }, - { LNILKEY, LNILVAL } -}; - -NODEMCU_MODULE(SIGMA_DELTA, "sigma_delta", sigma_delta_map, NULL); +LROT_BEGIN(sigma_delta) + LROT_FUNCENTRY( setup, sigma_delta_setup ) + LROT_FUNCENTRY( close, sigma_delta_close ) + LROT_FUNCENTRY( setpwmduty, sigma_delta_setpwmduty ) + LROT_FUNCENTRY( setprescale, sigma_delta_setprescale ) + LROT_FUNCENTRY( settarget, sigma_delta_settarget ) +LROT_END( sigma_delta, NULL, 0 ) + + +NODEMCU_MODULE(SIGMA_DELTA, "sigma_delta", sigma_delta, NULL); diff --git a/app/modules/sjson.c b/app/modules/sjson.c index 41babaf5a9..7be6bb1bca 100644 --- a/app/modules/sjson.c +++ b/app/modules/sjson.c @@ -992,74 +992,33 @@ static int sjson_encoder_destructor(lua_State *L) { return 0; } -#ifdef LOCAL_LUA -static const luaL_Reg sjson_encoder_map[] = { - { "read", sjson_encoder_read }, - { "__gc", sjson_encoder_destructor }, - { NULL, NULL } -}; - -static const luaL_Reg sjson_decoder_map[] = { - { "write", sjson_decoder_write }, - { "result", sjson_decoder_result }, - { "__gc", sjson_decoder_destructor }, - { NULL, NULL } -}; - -static const luaL_Reg sjsonlib[] = { - { "decode", sjson_decode }, - { "decoder", sjson_decoder }, - { "encode", sjson_encode }, - { "encoder", sjson_encoder }, - {NULL, NULL} -}; -#else -static const LUA_REG_TYPE sjson_encoder_map[] = { - { LSTRKEY( "read" ), LFUNCVAL( sjson_encoder_read ) }, - { LSTRKEY( "__gc" ), LFUNCVAL( sjson_encoder_destructor ) }, - { LSTRKEY( "__index" ), LROVAL( sjson_encoder_map ) }, - { LNILKEY, LNILVAL } -}; - -static const LUA_REG_TYPE sjson_decoder_map[] = { - { LSTRKEY( "write" ), LFUNCVAL( sjson_decoder_write ) }, - { LSTRKEY( "result" ), LFUNCVAL( sjson_decoder_result ) }, - { LSTRKEY( "__gc" ), LFUNCVAL( sjson_decoder_destructor ) }, - { LSTRKEY( "__index" ), LROVAL( sjson_decoder_map ) }, - { LNILKEY, LNILVAL } -}; - -static const LUA_REG_TYPE sjson_map[] = { - { LSTRKEY( "encode" ), LFUNCVAL( sjson_encode ) }, - { LSTRKEY( "decode" ), LFUNCVAL( sjson_decode ) }, - { LSTRKEY( "encoder" ), LFUNCVAL( sjson_encoder ) }, - { LSTRKEY( "decoder" ), LFUNCVAL( sjson_decoder ) }, - { LSTRKEY( "NULL" ), LUDATA( 0 ) }, - { LNILKEY, LNILVAL } -}; -#endif +LROT_BEGIN(sjson_encoder) + LROT_FUNCENTRY( read, sjson_encoder_read ) + LROT_FUNCENTRY( __gc, sjson_encoder_destructor ) + LROT_TABENTRY( __index, sjson_encoder ) +LROT_END( sjson_encoder, sjson_encoder, LROT_MASK_GC_INDEX ) + + +LROT_BEGIN(sjson_decoder) + LROT_FUNCENTRY( write, sjson_decoder_write ) + LROT_FUNCENTRY( result, sjson_decoder_result ) + LROT_FUNCENTRY( __gc, sjson_decoder_destructor ) + LROT_TABENTRY( __index, sjson_decoder ) +LROT_END( sjson_decoder, sjson_decoder, LROT_MASK_GC_INDEX ) + + +LROT_BEGIN(sjson) + LROT_FUNCENTRY( encode, sjson_encode ) + LROT_FUNCENTRY( decode, sjson_decode ) + LROT_FUNCENTRY( encoder, sjson_encoder ) + LROT_FUNCENTRY( decoder, sjson_decoder ) + LROT_LUDENTRY( NULL, 0 ) +LROT_END( sjson, NULL, 0 ) LUALIB_API int luaopen_sjson (lua_State *L) { -#ifdef LOCAL_LUA - luaL_register(L, LUA_SJSONLIBNAME, sjsonlib); - lua_getglobal(L, LUA_SJSONLIBNAME); - lua_pushstring(L, "NULL"); - lua_pushlightuserdata(L, 0); - lua_settable(L, -3); - lua_pop(L, 1); - luaL_newmetatable(L, "sjson.encoder"); - luaL_register(L, NULL, sjson_encoder_map); - lua_setfield(L, -1, "__index"); - luaL_newmetatable(L, "sjson.decoder"); - luaL_register(L, NULL, sjson_decoder_map); - lua_setfield(L, -1, "__index"); -#else - luaL_rometatable(L, "sjson.decoder", (void *)sjson_decoder_map); - luaL_rometatable(L, "sjson.encoder", (void *)sjson_encoder_map); -#endif + luaL_rometatable(L, "sjson.decoder", LROT_TABLEREF(sjson_decoder)); + luaL_rometatable(L, "sjson.encoder", LROT_TABLEREF(sjson_encoder)); return 1; } -#ifndef LOCAL_LUA -NODEMCU_MODULE(SJSON, "sjson", sjson_map, luaopen_sjson); -#endif +NODEMCU_MODULE(SJSON, "sjson", sjson, luaopen_sjson); diff --git a/app/modules/sntp.c b/app/modules/sntp.c index c4fedba630..7d1b987256 100644 --- a/app/modules/sntp.c +++ b/app/modules/sntp.c @@ -869,13 +869,13 @@ static int sntp_open(lua_State *L) // Module function map -static const LUA_REG_TYPE sntp_map[] = { - { LSTRKEY("sync"), LFUNCVAL(sntp_sync) }, +LROT_BEGIN(sntp) + LROT_FUNCENTRY( sync, sntp_sync ) #ifdef LUA_USE_MODULES_RTCTIME - { LSTRKEY("setoffset"), LFUNCVAL(sntp_setoffset) }, - { LSTRKEY("getoffset"), LFUNCVAL(sntp_getoffset) }, + LROT_FUNCENTRY( setoffset, sntp_setoffset ) + LROT_FUNCENTRY( getoffset, sntp_getoffset ) #endif - { LNILKEY, LNILVAL } -}; +LROT_END( sntp, NULL, 0 ) -NODEMCU_MODULE(SNTP, "sntp", sntp_map, sntp_open); + +NODEMCU_MODULE(SNTP, "sntp", sntp, sntp_open); diff --git a/app/modules/somfy.c b/app/modules/somfy.c index fbf477238a..c8ae5d7e13 100644 --- a/app/modules/somfy.c +++ b/app/modules/somfy.c @@ -231,18 +231,18 @@ static int somfy_lua_sendcommand(lua_State* L) { // pin, remote, command, rollin return 0; } -static const LUA_REG_TYPE somfy_map[] = { - { LSTRKEY( "UP" ), LNUMVAL( SOMFY_UP ) }, - { LSTRKEY( "DOWN" ), LNUMVAL( SOMFY_DOWN ) }, - { LSTRKEY( "PROG" ), LNUMVAL( SOMFY_PROG ) }, - { LSTRKEY( "STOP" ), LNUMVAL( SOMFY_STOP ) }, - { LSTRKEY( "sendcommand" ), LFUNCVAL(somfy_lua_sendcommand)}, - { LNILKEY, LNILVAL} -}; +LROT_BEGIN(somfy) + LROT_NUMENTRY( UP, SOMFY_UP ) + LROT_NUMENTRY( DOWN, SOMFY_DOWN ) + LROT_NUMENTRY( PROG, SOMFY_PROG ) + LROT_NUMENTRY( STOP, SOMFY_STOP ) + LROT_FUNCENTRY( sendcommand, somfy_lua_sendcommand ) +LROT_END( somfy, NULL, 0 ) + int luaopen_somfy( lua_State *L ) { done_taskid = task_get_id((task_callback_t) somfy_transmissionDone); return 0; } -NODEMCU_MODULE(SOMFY, "somfy", somfy_map, luaopen_somfy); \ No newline at end of file +NODEMCU_MODULE(SOMFY, "somfy", somfy, luaopen_somfy); \ No newline at end of file diff --git a/app/modules/spi.c b/app/modules/spi.c index e230503e8e..91c6b05cda 100644 --- a/app/modules/spi.c +++ b/app/modules/spi.c @@ -319,24 +319,24 @@ static int spi_set_clock_div( lua_State *L ) // Module function map -static const LUA_REG_TYPE spi_map[] = { - { LSTRKEY( "setup" ), LFUNCVAL( spi_setup ) }, - { LSTRKEY( "send" ), LFUNCVAL( spi_send_recv ) }, - { LSTRKEY( "recv" ), LFUNCVAL( spi_recv ) }, - { LSTRKEY( "set_mosi" ), LFUNCVAL( spi_set_mosi ) }, - { LSTRKEY( "get_miso" ), LFUNCVAL( spi_get_miso ) }, - { LSTRKEY( "transaction" ), LFUNCVAL( spi_transaction ) }, - { LSTRKEY( "set_clock_div" ), LFUNCVAL( spi_set_clock_div ) }, - { LSTRKEY( "MASTER" ), LNUMVAL( PLATFORM_SPI_MASTER ) }, - { LSTRKEY( "SLAVE" ), LNUMVAL( PLATFORM_SPI_SLAVE) }, - { LSTRKEY( "CPHA_LOW" ), LNUMVAL( PLATFORM_SPI_CPHA_LOW) }, - { LSTRKEY( "CPHA_HIGH" ), LNUMVAL( PLATFORM_SPI_CPHA_HIGH) }, - { LSTRKEY( "CPOL_LOW" ), LNUMVAL( PLATFORM_SPI_CPOL_LOW) }, - { LSTRKEY( "CPOL_HIGH" ), LNUMVAL( PLATFORM_SPI_CPOL_HIGH) }, - { LSTRKEY( "DATABITS_8" ), LNUMVAL( 8 ) }, - { LSTRKEY( "HALFDUPLEX" ), LNUMVAL( SPI_HALFDUPLEX ) }, - { LSTRKEY( "FULLDUPLEX" ), LNUMVAL( SPI_FULLDUPLEX ) }, - { LNILKEY, LNILVAL } -}; - -NODEMCU_MODULE(SPI, "spi", spi_map, NULL); +LROT_BEGIN(spi) + LROT_FUNCENTRY( setup, spi_setup ) + LROT_FUNCENTRY( send, spi_send_recv ) + LROT_FUNCENTRY( recv, spi_recv ) + LROT_FUNCENTRY( set_mosi, spi_set_mosi ) + LROT_FUNCENTRY( get_miso, spi_get_miso ) + LROT_FUNCENTRY( transaction, spi_transaction ) + LROT_FUNCENTRY( set_clock_div, spi_set_clock_div ) + LROT_NUMENTRY( MASTER, PLATFORM_SPI_MASTER ) + LROT_NUMENTRY( SLAVE, PLATFORM_SPI_SLAVE ) + LROT_NUMENTRY( CPHA_LOW, PLATFORM_SPI_CPHA_LOW ) + LROT_NUMENTRY( CPHA_HIGH, PLATFORM_SPI_CPHA_HIGH ) + LROT_NUMENTRY( CPOL_LOW, PLATFORM_SPI_CPOL_LOW ) + LROT_NUMENTRY( CPOL_HIGH, PLATFORM_SPI_CPOL_HIGH ) + LROT_NUMENTRY( DATABITS_8, 8 ) + LROT_NUMENTRY( HALFDUPLEX, SPI_HALFDUPLEX ) + LROT_NUMENTRY( FULLDUPLEX, SPI_FULLDUPLEX ) +LROT_END( spi, NULL, 0 ) + + +NODEMCU_MODULE(SPI, "spi", spi, NULL); diff --git a/app/modules/sqlite3.c b/app/modules/sqlite3.c index d46d8f484b..825da29f0b 100644 --- a/app/modules/sqlite3.c +++ b/app/modules/sqlite3.c @@ -25,6 +25,7 @@ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ************************************************************************/ +#if 0 #define LSQLITE_VERSION "0.9.4" #define LSQLITE_OMIT_UPDATE_HOOK 1 #define SQLITE_OMIT_PROGRESS_CALLBACK 1 @@ -2429,3 +2430,4 @@ LUALIB_API int luaopen_lsqlite3(lua_State *L) { } NODEMCU_MODULE(SQLITE3, "sqlite3", sqlitelib, luaopen_lsqlite3); +#endif diff --git a/app/modules/struct.c b/app/modules/struct.c index f375f6c45c..583383a4b2 100644 --- a/app/modules/struct.c +++ b/app/modules/struct.c @@ -389,13 +389,12 @@ static int b_size (lua_State *L) { /* }====================================================== */ +LROT_BEGIN(thislib) + LROT_FUNCENTRY( pack, b_pack ) + LROT_FUNCENTRY( unpack, b_unpack ) + LROT_FUNCENTRY( size, b_size ) +LROT_END( thislib, NULL, 0 ) -static const LUA_REG_TYPE thislib[] = { - {LSTRKEY("pack"), LFUNCVAL(b_pack)}, - {LSTRKEY("unpack"), LFUNCVAL(b_unpack)}, - {LSTRKEY("size"), LFUNCVAL(b_size)}, - {LNILKEY, LNILVAL} -}; NODEMCU_MODULE(STRUCT, "struct", thislib, NULL); diff --git a/app/modules/switec.c b/app/modules/switec.c index 5dd9922c5d..a954b89264 100644 --- a/app/modules/switec.c +++ b/app/modules/switec.c @@ -196,17 +196,17 @@ static int switec_open(lua_State *L) // Module function map -static const LUA_REG_TYPE switec_map[] = { - { LSTRKEY( "setup" ), LFUNCVAL( lswitec_setup ) }, - { LSTRKEY( "close" ), LFUNCVAL( lswitec_close ) }, - { LSTRKEY( "reset" ), LFUNCVAL( lswitec_reset ) }, - { LSTRKEY( "moveto" ), LFUNCVAL( lswitec_moveto) }, - { LSTRKEY( "getpos" ), LFUNCVAL( lswitec_getpos) }, +LROT_BEGIN(switec) + LROT_FUNCENTRY( setup, lswitec_setup ) + LROT_FUNCENTRY( close, lswitec_close ) + LROT_FUNCENTRY( reset, lswitec_reset ) + LROT_FUNCENTRY( moveto, lswitec_moveto ) + LROT_FUNCENTRY( getpos, lswitec_getpos ) #ifdef SQITEC_DEBUG - { LSTRKEY( "dequeue" ), LFUNCVAL( lswitec_dequeue) }, + LROT_FUNCENTRY( dequeue, lswitec_dequeue ) #endif - { LNILKEY, LNILVAL } -}; +LROT_END( switec, NULL, 0 ) -NODEMCU_MODULE(SWITEC, "switec", switec_map, switec_open); + +NODEMCU_MODULE(SWITEC, "switec", switec, switec_open); diff --git a/app/modules/tcs34725.c b/app/modules/tcs34725.c index 6794abc90d..a673394594 100644 --- a/app/modules/tcs34725.c +++ b/app/modules/tcs34725.c @@ -342,14 +342,14 @@ uint8_t tcs34725GetRawData(lua_State* L) } -static const LUA_REG_TYPE tcs34725_map[] = { - { LSTRKEY( "setup" ), LFUNCVAL(tcs34725Setup)}, - { LSTRKEY( "enable" ), LFUNCVAL(tcs34725Enable)}, - { LSTRKEY( "disable" ), LFUNCVAL(tcs34725Disable)}, - { LSTRKEY( "raw" ), LFUNCVAL(tcs34725GetRawData)}, - { LSTRKEY( "setGain" ), LFUNCVAL(tcs34725LuaSetGain)}, - { LSTRKEY( "setIntegrationTime" ), LFUNCVAL(tcs34725LuaSetIntegrationTime)}, - { LNILKEY, LNILVAL} -}; - -NODEMCU_MODULE(TCS34725, "tcs34725", tcs34725_map, NULL); \ No newline at end of file +LROT_BEGIN(tcs34725) + LROT_FUNCENTRY( setup, tcs34725Setup ) + LROT_FUNCENTRY( enable, tcs34725Enable ) + LROT_FUNCENTRY( disable, tcs34725Disable ) + LROT_FUNCENTRY( raw, tcs34725GetRawData ) + LROT_FUNCENTRY( setGain, tcs34725LuaSetGain ) + LROT_FUNCENTRY( setIntegrationTime, tcs34725LuaSetIntegrationTime ) +LROT_END( tcs34725, NULL, 0 ) + + +NODEMCU_MODULE(TCS34725, "tcs34725", tcs34725, NULL); \ No newline at end of file diff --git a/app/modules/tls.c b/app/modules/tls.c index dcec652aa7..d66c628e72 100644 --- a/app/modules/tls.c +++ b/app/modules/tls.c @@ -31,7 +31,7 @@ __attribute__((section(".servercert.flash"))) unsigned char tls_server_cert_area __attribute__((section(".clientcert.flash"))) unsigned char tls_client_cert_area[INTERNAL_FLASH_SECTOR_SIZE]; extern int tls_socket_create( lua_State *L ); -extern const LUA_REG_TYPE tls_cert_map[]; +LROT_EXTERN(tls_cert); typedef struct { struct espconn *pesp_conn; @@ -613,40 +613,40 @@ static int tls_set_debug_threshold(lua_State *L) { } #endif -static const LUA_REG_TYPE tls_socket_map[] = { - { LSTRKEY( "connect" ), LFUNCVAL( tls_socket_connect ) }, - { LSTRKEY( "close" ), LFUNCVAL( tls_socket_close ) }, - { LSTRKEY( "on" ), LFUNCVAL( tls_socket_on ) }, - { LSTRKEY( "send" ), LFUNCVAL( tls_socket_send ) }, - { LSTRKEY( "hold" ), LFUNCVAL( tls_socket_hold ) }, - { LSTRKEY( "unhold" ), LFUNCVAL( tls_socket_unhold ) }, - { LSTRKEY( "getpeer" ), LFUNCVAL( tls_socket_getpeer ) }, - { LSTRKEY( "__gc" ), LFUNCVAL( tls_socket_delete ) }, - { LSTRKEY( "__index" ), LROVAL( tls_socket_map ) }, - { LNILKEY, LNILVAL } -}; - -const LUA_REG_TYPE tls_cert_map[] = { - { LSTRKEY( "verify" ), LFUNCVAL( tls_cert_verify ) }, - { LSTRKEY( "auth" ), LFUNCVAL( tls_cert_auth ) }, - { LSTRKEY( "__index" ), LROVAL( tls_cert_map ) }, - { LNILKEY, LNILVAL } -}; - -static const LUA_REG_TYPE tls_map[] = { - { LSTRKEY( "createConnection" ), LFUNCVAL( tls_socket_create ) }, +LROT_BEGIN(tls_socket) + LROT_FUNCENTRY( connect, tls_socket_connect ) + LROT_FUNCENTRY( close, tls_socket_close ) + LROT_FUNCENTRY( on, tls_socket_on ) + LROT_FUNCENTRY( send, tls_socket_send ) + LROT_FUNCENTRY( hold, tls_socket_hold ) + LROT_FUNCENTRY( unhold, tls_socket_unhold ) + LROT_FUNCENTRY( getpeer, tls_socket_getpeer ) + LROT_FUNCENTRY( __gc, tls_socket_delete ) + LROT_TABENTRY( __index, tls_socket ) +LROT_END( tls_socket, tls_socket, 0 ) + + +LROT_PUBLIC_BEGIN(tls_cert) + LROT_FUNCENTRY( verify, tls_cert_verify ) + LROT_FUNCENTRY( auth, tls_cert_auth ) + LROT_TABENTRY( __index, tls_cert ) +LROT_END( tls_cert, tls_cert, 0 ) + + +LROT_BEGIN(tls) + LROT_FUNCENTRY( createConnection, tls_socket_create ) #if defined(MBEDTLS_DEBUG_C) - { LSTRKEY( "setDebug" ), LFUNCVAL( tls_set_debug_threshold ) }, + LROT_FUNCENTRY( setDebug, tls_set_debug_threshold ) #endif - { LSTRKEY( "cert" ), LROVAL( tls_cert_map ) }, - { LSTRKEY( "__metatable" ), LROVAL( tls_map ) }, - { LNILKEY, LNILVAL } -}; + LROT_TABENTRY( cert, tls_cert ) + LROT_TABENTRY( __metatable, tls ) +LROT_END( tls, tls, 0 ) + int luaopen_tls( lua_State *L ) { - luaL_rometatable(L, "tls.socket", (void *)tls_socket_map); // create metatable for net.server + luaL_rometatable(L, "tls.socket", LROT_TABLEREF(tls_socket)); return 0; } -NODEMCU_MODULE(TLS, "tls", tls_map, luaopen_tls); +NODEMCU_MODULE(TLS, "tls", tls, luaopen_tls); #endif diff --git a/app/modules/tm1829.c b/app/modules/tm1829.c index 4b96d01fde..21f149dae4 100644 --- a/app/modules/tm1829.c +++ b/app/modules/tm1829.c @@ -100,15 +100,14 @@ static int ICACHE_FLASH_ATTR tm1829_write(lua_State* L) return 0; } -static const LUA_REG_TYPE tm1829_map[] = -{ - { LSTRKEY( "write" ), LFUNCVAL( tm1829_write) }, - { LNILKEY, LNILVAL } -}; +LROT_BEGIN(tm1829) + LROT_FUNCENTRY( write, tm1829_write ) +LROT_END( tm1829, NULL, 0 ) + int luaopen_tm1829(lua_State *L) { // TODO: Make sure that the GPIO system is initialized return 0; } -NODEMCU_MODULE(TM1829, "tm1829", tm1829_map, luaopen_tm1829); +NODEMCU_MODULE(TM1829, "tm1829", tm1829, luaopen_tm1829); diff --git a/app/modules/tmr.c b/app/modules/tmr.c index 48c6071bb0..6625f973ab 100644 --- a/app/modules/tmr.c +++ b/app/modules/tmr.c @@ -369,43 +369,43 @@ static int tmr_create( lua_State *L ) { // Module function map -static const LUA_REG_TYPE tmr_dyn_map[] = { - { LSTRKEY( "register" ), LFUNCVAL( tmr_register ) }, - { LSTRKEY( "alarm" ), LFUNCVAL( tmr_alarm ) }, - { LSTRKEY( "start" ), LFUNCVAL( tmr_start ) }, - { LSTRKEY( "stop" ), LFUNCVAL( tmr_stop ) }, - { LSTRKEY( "unregister" ), LFUNCVAL( tmr_unregister ) }, - { LSTRKEY( "state" ), LFUNCVAL( tmr_state ) }, - { LSTRKEY( "interval" ), LFUNCVAL( tmr_interval) }, +LROT_BEGIN(tmr_dyn) + LROT_FUNCENTRY( register, tmr_register ) + LROT_FUNCENTRY( alarm, tmr_alarm ) + LROT_FUNCENTRY( start, tmr_start ) + LROT_FUNCENTRY( stop, tmr_stop ) + LROT_FUNCENTRY( unregister, tmr_unregister ) + LROT_FUNCENTRY( state, tmr_state ) + LROT_FUNCENTRY( interval, tmr_interval ) #ifdef TIMER_SUSPEND_ENABLE - { LSTRKEY( "suspend" ), LFUNCVAL( tmr_suspend ) }, - { LSTRKEY( "resume" ), LFUNCVAL( tmr_resume ) }, + LROT_FUNCENTRY( suspend, tmr_suspend ) + LROT_FUNCENTRY( resume, tmr_resume ) #endif - { LSTRKEY( "__gc" ), LFUNCVAL( tmr_unregister ) }, - { LSTRKEY( "__index" ), LROVAL( tmr_dyn_map ) }, - { LNILKEY, LNILVAL } -}; - -static const LUA_REG_TYPE tmr_map[] = { - { LSTRKEY( "delay" ), LFUNCVAL( tmr_delay ) }, - { LSTRKEY( "now" ), LFUNCVAL( tmr_now ) }, - { LSTRKEY( "wdclr" ), LFUNCVAL( tmr_wdclr ) }, - { LSTRKEY( "softwd" ), LFUNCVAL( tmr_softwd ) }, - { LSTRKEY( "time" ), LFUNCVAL( tmr_time ) }, + LROT_FUNCENTRY( __gc, tmr_unregister ) + LROT_TABENTRY( __index, tmr_dyn ) +LROT_END( tmr_dyn, tmr_dyn, LROT_MASK_GC_INDEX ) + + +LROT_BEGIN(tmr) + LROT_FUNCENTRY( delay, tmr_delay ) + LROT_FUNCENTRY( now, tmr_now ) + LROT_FUNCENTRY( wdclr, tmr_wdclr ) + LROT_FUNCENTRY( softwd, tmr_softwd ) + LROT_FUNCENTRY( time, tmr_time ) #ifdef TIMER_SUSPEND_ENABLE - { LSTRKEY( "suspend_all" ), LFUNCVAL( tmr_suspend_all ) }, - { LSTRKEY( "resume_all" ), LFUNCVAL( tmr_resume_all ) }, + LROT_FUNCENTRY( suspend_all, tmr_suspend_all ) + LROT_FUNCENTRY( resume_all, tmr_resume_all ) #endif - { LSTRKEY( "create" ), LFUNCVAL( tmr_create ) }, - { LSTRKEY( "ALARM_SINGLE" ), LNUMVAL( TIMER_MODE_SINGLE ) }, - { LSTRKEY( "ALARM_SEMI" ), LNUMVAL( TIMER_MODE_SEMI ) }, - { LSTRKEY( "ALARM_AUTO" ), LNUMVAL( TIMER_MODE_AUTO ) }, - { LNILKEY, LNILVAL } -}; + LROT_FUNCENTRY( create, tmr_create ) + LROT_NUMENTRY( ALARM_SINGLE, TIMER_MODE_SINGLE ) + LROT_NUMENTRY( ALARM_SEMI, TIMER_MODE_SEMI ) + LROT_NUMENTRY( ALARM_AUTO, TIMER_MODE_AUTO ) +LROT_END( tmr, NULL, 0 ) + #include "pm/swtimer.h" int luaopen_tmr( lua_State *L ){ - luaL_rometatable(L, "tmr.timer", (void *)tmr_dyn_map); + luaL_rometatable(L, "tmr.timer", LROT_TABLEREF(tmr_dyn)); last_rtc_time=system_get_rtc_time(); // Right now is time 0 last_rtc_time_us=0; @@ -425,4 +425,4 @@ int luaopen_tmr( lua_State *L ){ return 0; } -NODEMCU_MODULE(TMR, "tmr", tmr_map, luaopen_tmr); +NODEMCU_MODULE(TMR, "tmr", tmr, luaopen_tmr); diff --git a/app/modules/tsl2561.c b/app/modules/tsl2561.c index 77a721639b..5daa6a7c0c 100644 --- a/app/modules/tsl2561.c +++ b/app/modules/tsl2561.c @@ -101,27 +101,27 @@ static int ICACHE_FLASH_ATTR tsl2561_lua_getchannels(lua_State* L) { } // Module function map -static const LUA_REG_TYPE tsl2561_map[] = { - { LSTRKEY( "settiming" ), LFUNCVAL( tsl2561_lua_settiming)}, - { LSTRKEY( "getlux" ), LFUNCVAL( tsl2561_lua_calclux )}, - { LSTRKEY( "getrawchannels" ), LFUNCVAL( tsl2561_lua_getchannels )}, - { LSTRKEY( "init" ), LFUNCVAL( tsl2561_init )}, - { LSTRKEY( "TSL2561_OK" ), LNUMVAL( TSL2561_ERROR_OK )}, - { LSTRKEY( "TSL2561_ERROR_I2CINIT" ), LNUMVAL( TSL2561_ERROR_I2CINIT )}, - { LSTRKEY( "TSL2561_ERROR_I2CBUSY" ), LNUMVAL( TSL2561_ERROR_I2CBUSY )}, - { LSTRKEY( "TSL2561_ERROR_NOINIT" ), LNUMVAL( TSL2561_ERROR_NOINIT )}, - { LSTRKEY( "TSL2561_ERROR_LAST" ), LNUMVAL( TSL2561_ERROR_LAST )}, - { LSTRKEY( "INTEGRATIONTIME_13MS" ), LNUMVAL( TSL2561_INTEGRATIONTIME_13MS )}, - { LSTRKEY( "INTEGRATIONTIME_101MS" ), LNUMVAL( TSL2561_INTEGRATIONTIME_101MS )}, - { LSTRKEY( "INTEGRATIONTIME_402MS" ), LNUMVAL( TSL2561_INTEGRATIONTIME_402MS )}, - { LSTRKEY( "GAIN_1X" ), LNUMVAL( TSL2561_GAIN_1X )}, - { LSTRKEY( "GAIN_16X" ), LNUMVAL( TSL2561_GAIN_16X )}, - { LSTRKEY( "PACKAGE_CS" ), LNUMVAL( TSL2561_PACKAGE_CS )}, - { LSTRKEY( "PACKAGE_T_FN_CL" ), LNUMVAL( TSL2561_PACKAGE_T_FN_CL )}, - { LSTRKEY( "ADDRESS_GND" ), LNUMVAL( TSL2561_ADDRESS_GND )}, - { LSTRKEY( "ADDRESS_FLOAT" ), LNUMVAL( TSL2561_ADDRESS_FLOAT )}, - { LSTRKEY( "ADDRESS_VDD" ), LNUMVAL( TSL2561_ADDRESS_VDD )}, - { LNILKEY, LNILVAL} -}; +LROT_BEGIN(tsl2561) + LROT_FUNCENTRY( settiming, tsl2561_lua_settiming ) + LROT_FUNCENTRY( getlux, tsl2561_lua_calclux ) + LROT_FUNCENTRY( getrawchannels, tsl2561_lua_getchannels ) + LROT_FUNCENTRY( init, tsl2561_init ) + LROT_NUMENTRY( TSL2561_OK, TSL2561_ERROR_OK ) + LROT_NUMENTRY( TSL2561_ERROR_I2CINIT, TSL2561_ERROR_I2CINIT ) + LROT_NUMENTRY( TSL2561_ERROR_I2CBUSY, TSL2561_ERROR_I2CBUSY ) + LROT_NUMENTRY( TSL2561_ERROR_NOINIT, TSL2561_ERROR_NOINIT ) + LROT_NUMENTRY( TSL2561_ERROR_LAST, TSL2561_ERROR_LAST ) + LROT_NUMENTRY( INTEGRATIONTIME_13MS, TSL2561_INTEGRATIONTIME_13MS ) + LROT_NUMENTRY( INTEGRATIONTIME_101MS, TSL2561_INTEGRATIONTIME_101MS ) + LROT_NUMENTRY( INTEGRATIONTIME_402MS, TSL2561_INTEGRATIONTIME_402MS ) + LROT_NUMENTRY( GAIN_1X, TSL2561_GAIN_1X ) + LROT_NUMENTRY( GAIN_16X, TSL2561_GAIN_16X ) + LROT_NUMENTRY( PACKAGE_CS, TSL2561_PACKAGE_CS ) + LROT_NUMENTRY( PACKAGE_T_FN_CL, TSL2561_PACKAGE_T_FN_CL ) + LROT_NUMENTRY( ADDRESS_GND, TSL2561_ADDRESS_GND ) + LROT_NUMENTRY( ADDRESS_FLOAT, TSL2561_ADDRESS_FLOAT ) + LROT_NUMENTRY( ADDRESS_VDD, TSL2561_ADDRESS_VDD ) +LROT_END( tsl2561, NULL, 0 ) -NODEMCU_MODULE(TSL2561, "tsl2561", tsl2561_map, NULL); + +NODEMCU_MODULE(TSL2561, "tsl2561", tsl2561, NULL); diff --git a/app/modules/u8g2.c b/app/modules/u8g2.c index 307cbea1d3..3758ee7162 100644 --- a/app/modules/u8g2.c +++ b/app/modules/u8g2.c @@ -566,52 +566,51 @@ static int lu8g2_updateDisplayArea( lua_State *L ) } -static const LUA_REG_TYPE lu8g2_display_map[] = { - { LSTRKEY( "clearBuffer" ), LFUNCVAL( lu8g2_clearBuffer ) }, - { LSTRKEY( "drawBox" ), LFUNCVAL( lu8g2_drawBox ) }, - { LSTRKEY( "drawCircle" ), LFUNCVAL( lu8g2_drawCircle ) }, - { LSTRKEY( "drawDisc" ), LFUNCVAL( lu8g2_drawDisc ) }, - { LSTRKEY( "drawEllipse" ), LFUNCVAL( lu8g2_drawEllipse ) }, - { LSTRKEY( "drawFilledEllipse" ), LFUNCVAL( lu8g2_drawFilledEllipse ) }, - { LSTRKEY( "drawFrame" ), LFUNCVAL( lu8g2_drawFrame ) }, - { LSTRKEY( "drawGlyph" ), LFUNCVAL( lu8g2_drawGlyph ) }, - { LSTRKEY( "drawHLine" ), LFUNCVAL( lu8g2_drawHLine ) }, - { LSTRKEY( "drawLine" ), LFUNCVAL( lu8g2_drawLine ) }, - { LSTRKEY( "drawPixel" ), LFUNCVAL( lu8g2_drawPixel ) }, - { LSTRKEY( "drawRBox" ), LFUNCVAL( lu8g2_drawRBox ) }, - { LSTRKEY( "drawRFrame" ), LFUNCVAL( lu8g2_drawRFrame ) }, - { LSTRKEY( "drawStr" ), LFUNCVAL( lu8g2_drawStr ) }, - { LSTRKEY( "drawTriangle" ), LFUNCVAL( lu8g2_drawTriangle ) }, - { LSTRKEY( "drawUTF8" ), LFUNCVAL( lu8g2_drawUTF8 ) }, - { LSTRKEY( "drawVLine" ), LFUNCVAL( lu8g2_drawVLine ) }, - { LSTRKEY( "drawXBM" ), LFUNCVAL( lu8g2_drawXBM ) }, - { LSTRKEY( "getAscent" ), LFUNCVAL( lu8g2_getAscent ) }, - { LSTRKEY( "getDescent" ), LFUNCVAL( lu8g2_getDescent ) }, - { LSTRKEY( "getStrWidth" ), LFUNCVAL( lu8g2_getStrWidth ) }, - { LSTRKEY( "getUTF8Width" ), LFUNCVAL( lu8g2_getUTF8Width ) }, - { LSTRKEY( "sendBuffer" ), LFUNCVAL( lu8g2_sendBuffer ) }, - { LSTRKEY( "setBitmapMode" ), LFUNCVAL( lu8g2_setBitmapMode ) }, - { LSTRKEY( "setContrast" ), LFUNCVAL( lu8g2_setContrast ) }, - { LSTRKEY( "setDisplayRotation" ), LFUNCVAL( lu8g2_setDisplayRotation ) }, - { LSTRKEY( "setDrawColor" ), LFUNCVAL( lu8g2_setDrawColor ) }, - { LSTRKEY( "setFlipMode" ), LFUNCVAL( lu8g2_setFlipMode ) }, - { LSTRKEY( "setFont" ), LFUNCVAL( lu8g2_setFont ) }, - { LSTRKEY( "setFontDirection" ), LFUNCVAL( lu8g2_setFontDirection ) }, - { LSTRKEY( "setFontMode" ), LFUNCVAL( lu8g2_setFontMode ) }, - { LSTRKEY( "setFontPosBaseline" ), LFUNCVAL( lu8g2_setFontPosBaseline ) }, - { LSTRKEY( "setFontPosBottom" ), LFUNCVAL( lu8g2_setFontPosBottom ) }, - { LSTRKEY( "setFontPosTop" ), LFUNCVAL( lu8g2_setFontPosTop ) }, - { LSTRKEY( "setFontPosCenter" ), LFUNCVAL( lu8g2_setFontPosCenter ) }, - { LSTRKEY( "setFontRefHeightAll" ), LFUNCVAL( lu8g2_setFontRefHeightAll ) }, - { LSTRKEY( "setFontRefHeightExtendedText" ), LFUNCVAL( lu8g2_setFontRefHeightExtendedText ) }, - { LSTRKEY( "setFontRefHeightText" ), LFUNCVAL( lu8g2_setFontRefHeightText ) }, - { LSTRKEY( "setPowerSave" ), LFUNCVAL( lu8g2_setPowerSave ) }, - { LSTRKEY( "updateDispla" ), LFUNCVAL( lu8g2_updateDisplay ) }, - { LSTRKEY( "updateDisplayArea" ), LFUNCVAL( lu8g2_updateDisplayArea ) }, - //{ LSTRKEY( "__gc" ), LFUNCVAL( lu8g2_display_free ) }, - { LSTRKEY( "__index" ), LROVAL( lu8g2_display_map ) }, - {LNILKEY, LNILVAL} -}; +LROT_BEGIN(lu8g2_display) + LROT_FUNCENTRY( clearBuffer, lu8g2_clearBuffer ) + LROT_FUNCENTRY( drawBox, lu8g2_drawBox ) + LROT_FUNCENTRY( drawCircle, lu8g2_drawCircle ) + LROT_FUNCENTRY( drawDisc, lu8g2_drawDisc ) + LROT_FUNCENTRY( drawEllipse, lu8g2_drawEllipse ) + LROT_FUNCENTRY( drawFilledEllipse, lu8g2_drawFilledEllipse ) + LROT_FUNCENTRY( drawFrame, lu8g2_drawFrame ) + LROT_FUNCENTRY( drawGlyph, lu8g2_drawGlyph ) + LROT_FUNCENTRY( drawHLine, lu8g2_drawHLine ) + LROT_FUNCENTRY( drawLine, lu8g2_drawLine ) + LROT_FUNCENTRY( drawPixel, lu8g2_drawPixel ) + LROT_FUNCENTRY( drawRBox, lu8g2_drawRBox ) + LROT_FUNCENTRY( drawRFrame, lu8g2_drawRFrame ) + LROT_FUNCENTRY( drawStr, lu8g2_drawStr ) + LROT_FUNCENTRY( drawTriangle, lu8g2_drawTriangle ) + LROT_FUNCENTRY( drawUTF8, lu8g2_drawUTF8 ) + LROT_FUNCENTRY( drawVLine, lu8g2_drawVLine ) + LROT_FUNCENTRY( drawXBM, lu8g2_drawXBM ) + LROT_FUNCENTRY( getAscent, lu8g2_getAscent ) + LROT_FUNCENTRY( getDescent, lu8g2_getDescent ) + LROT_FUNCENTRY( getStrWidth, lu8g2_getStrWidth ) + LROT_FUNCENTRY( getUTF8Width, lu8g2_getUTF8Width ) + LROT_FUNCENTRY( sendBuffer, lu8g2_sendBuffer ) + LROT_FUNCENTRY( setBitmapMode, lu8g2_setBitmapMode ) + LROT_FUNCENTRY( setContrast, lu8g2_setContrast ) + LROT_FUNCENTRY( setDisplayRotation, lu8g2_setDisplayRotation ) + LROT_FUNCENTRY( setDrawColor, lu8g2_setDrawColor ) + LROT_FUNCENTRY( setFlipMode, lu8g2_setFlipMode ) + LROT_FUNCENTRY( setFont, lu8g2_setFont ) + LROT_FUNCENTRY( setFontDirection, lu8g2_setFontDirection ) + LROT_FUNCENTRY( setFontMode, lu8g2_setFontMode ) + LROT_FUNCENTRY( setFontPosBaseline, lu8g2_setFontPosBaseline ) + LROT_FUNCENTRY( setFontPosBottom, lu8g2_setFontPosBottom ) + LROT_FUNCENTRY( setFontPosTop, lu8g2_setFontPosTop ) + LROT_FUNCENTRY( setFontPosCenter, lu8g2_setFontPosCenter ) + LROT_FUNCENTRY( setFontRefHeightAll, lu8g2_setFontRefHeightAll ) + LROT_FUNCENTRY( setFontRefHeightExtendedText, lu8g2_setFontRefHeightExtendedText ) + LROT_FUNCENTRY( setFontRefHeightText, lu8g2_setFontRefHeightText ) + LROT_FUNCENTRY( setPowerSave, lu8g2_setPowerSave ) + LROT_FUNCENTRY( updateDispla, lu8g2_updateDisplay ) + LROT_FUNCENTRY( updateDisplayArea, lu8g2_updateDisplayArea ) + // LROT_FUNCENTRY( __gc, lu8g2_display_free ) + LROT_TABENTRY( __index, lu8g2_display ) +LROT_END( lu8g2_display, lu8g2_display, LROT_MASK_GC_INDEX ) uint8_t u8x8_d_overlay(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr); @@ -808,36 +807,33 @@ U8G2_DISPLAY_TABLE_SPI #undef U8G2_FONT_TABLE_ENTRY #undef U8G2_DISPLAY_TABLE_ENTRY -#define U8G2_DISPLAY_TABLE_ENTRY(function, binding) \ - { LSTRKEY( #binding ), LFUNCVAL( l ## binding ) }, - -static const LUA_REG_TYPE lu8g2_map[] = { +#define U8G2_DISPLAY_TABLE_ENTRY(function, binding) LROT_FUNCENTRY(#binding,l ## binding) +LROT_BEGIN(lu8g2) U8G2_DISPLAY_TABLE_I2C U8G2_DISPLAY_TABLE_SPI // // Register fonts -#define U8G2_FONT_TABLE_ENTRY(font) \ - { LSTRKEY( #font ), LUDATA( (void *)(u8g2_ ## font) ) }, +#define U8G2_FONT_TABLE_ENTRY(font) LROT_LUDENTRY(font, u8g2_ ## font) U8G2_FONT_TABLE // - { LSTRKEY( "DRAW_UPPER_RIGHT" ), LNUMVAL( U8G2_DRAW_UPPER_RIGHT ) }, - { LSTRKEY( "DRAW_UPPER_LEFT" ), LNUMVAL( U8G2_DRAW_UPPER_LEFT ) }, - { LSTRKEY( "DRAW_LOWER_RIGHT" ), LNUMVAL( U8G2_DRAW_LOWER_RIGHT ) }, - { LSTRKEY( "DRAW_LOWER_LEFT" ), LNUMVAL( U8G2_DRAW_LOWER_LEFT ) }, - { LSTRKEY( "DRAW_ALL" ), LNUMVAL( U8G2_DRAW_ALL ) }, - { LSTRKEY( "R0" ), LUDATA( (void *)U8G2_R0 ) }, - { LSTRKEY( "R1" ), LUDATA( (void *)U8G2_R1 ) }, - { LSTRKEY( "R2" ), LUDATA( (void *)U8G2_R2 ) }, - { LSTRKEY( "R3" ), LUDATA( (void *)U8G2_R3 ) }, - { LSTRKEY( "MIRROR" ), LUDATA( (void *)U8G2_MIRROR ) }, - {LNILKEY, LNILVAL} -}; + LROT_NUMENTRY( DRAW_UPPER_RIGHT, U8G2_DRAW_UPPER_RIGHT ) + LROT_NUMENTRY( DRAW_UPPER_LEFT, U8G2_DRAW_UPPER_LEFT ) + LROT_NUMENTRY( DRAW_LOWER_RIGHT, U8G2_DRAW_LOWER_RIGHT ) + LROT_NUMENTRY( DRAW_LOWER_LEFT, U8G2_DRAW_LOWER_LEFT ) + LROT_NUMENTRY( DRAW_ALL, U8G2_DRAW_ALL ) + LROT_LUDENTRY( R0, U8G2_R0 ) + LROT_LUDENTRY( R1, U8G2_R1 ) + LROT_LUDENTRY( R2, U8G2_R2 ) + LROT_LUDENTRY( R3, U8G2_R3 ) + LROT_LUDENTRY( MIRROR, U8G2_MIRROR ) +LROT_END( lu8g2, NULL, 0 ) + int luaopen_u8g2( lua_State *L ) { - luaL_rometatable(L, "u8g2.display", (void *)lu8g2_display_map); + luaL_rometatable(L, "u8g2.display", LROT_TABLEREF(lu8g2_display)); return 0; } -NODEMCU_MODULE(U8G2, "u8g2", lu8g2_map, luaopen_u8g2); +NODEMCU_MODULE(U8G2, "u8g2", lu8g2, luaopen_u8g2); #endif /* defined(LUA_USE_MODULES_U8G2) || defined(ESP_PLATFORM) */ diff --git a/app/modules/uart.c b/app/modules/uart.c index 584cba57b4..a9b7efeeaf 100644 --- a/app/modules/uart.c +++ b/app/modules/uart.c @@ -174,19 +174,19 @@ static int l_uart_write( lua_State* L ) } // Module function map -static const LUA_REG_TYPE uart_map[] = { - { LSTRKEY( "setup" ), LFUNCVAL( l_uart_setup ) }, - { LSTRKEY( "getconfig" ), LFUNCVAL( l_uart_getconfig ) }, - { LSTRKEY( "write" ), LFUNCVAL( l_uart_write ) }, - { LSTRKEY( "on" ), LFUNCVAL( l_uart_on ) }, - { LSTRKEY( "alt" ), LFUNCVAL( l_uart_alt ) }, - { LSTRKEY( "STOPBITS_1" ), LNUMVAL( PLATFORM_UART_STOPBITS_1 ) }, - { LSTRKEY( "STOPBITS_1_5" ), LNUMVAL( PLATFORM_UART_STOPBITS_1_5 ) }, - { LSTRKEY( "STOPBITS_2" ), LNUMVAL( PLATFORM_UART_STOPBITS_2 ) }, - { LSTRKEY( "PARITY_NONE" ), LNUMVAL( PLATFORM_UART_PARITY_NONE ) }, - { LSTRKEY( "PARITY_EVEN" ), LNUMVAL( PLATFORM_UART_PARITY_EVEN ) }, - { LSTRKEY( "PARITY_ODD" ), LNUMVAL( PLATFORM_UART_PARITY_ODD ) }, - { LNILKEY, LNILVAL } -}; - -NODEMCU_MODULE(UART, "uart", uart_map, NULL); +LROT_BEGIN(uart) + LROT_FUNCENTRY( setup, l_uart_setup ) + LROT_FUNCENTRY( getconfig, l_uart_getconfig ) + LROT_FUNCENTRY( write, l_uart_write ) + LROT_FUNCENTRY( on, l_uart_on ) + LROT_FUNCENTRY( alt, l_uart_alt ) + LROT_NUMENTRY( STOPBITS_1, PLATFORM_UART_STOPBITS_1 ) + LROT_NUMENTRY( STOPBITS_1_5, PLATFORM_UART_STOPBITS_1_5 ) + LROT_NUMENTRY( STOPBITS_2, PLATFORM_UART_STOPBITS_2 ) + LROT_NUMENTRY( PARITY_NONE, PLATFORM_UART_PARITY_NONE ) + LROT_NUMENTRY( PARITY_EVEN, PLATFORM_UART_PARITY_EVEN ) + LROT_NUMENTRY( PARITY_ODD, PLATFORM_UART_PARITY_ODD ) +LROT_END( uart, NULL, 0 ) + + +NODEMCU_MODULE(UART, "uart", uart, NULL); diff --git a/app/modules/ucg.c b/app/modules/ucg.c index 5dfbc5621a..4d2690c588 100644 --- a/app/modules/ucg.c +++ b/app/modules/ucg.c @@ -690,89 +690,87 @@ UCG_DISPLAY_TABLE // Module function map -static const LUA_REG_TYPE lucg_display_map[] = -{ - { LSTRKEY( "begin" ), LFUNCVAL( lucg_begin ) }, - { LSTRKEY( "clearScreen" ), LFUNCVAL( lucg_clearScreen ) }, - { LSTRKEY( "draw90Line" ), LFUNCVAL( lucg_draw90Line ) }, - { LSTRKEY( "drawBox" ), LFUNCVAL( lucg_drawBox ) }, - { LSTRKEY( "drawCircle" ), LFUNCVAL( lucg_drawCircle ) }, - { LSTRKEY( "drawDisc" ), LFUNCVAL( lucg_drawDisc ) }, - { LSTRKEY( "drawFrame" ), LFUNCVAL( lucg_drawFrame ) }, - { LSTRKEY( "drawGlyph" ), LFUNCVAL( lucg_drawGlyph ) }, - { LSTRKEY( "drawGradientBox" ), LFUNCVAL( lucg_drawGradientBox ) }, - { LSTRKEY( "drawGradientLine" ), LFUNCVAL( lucg_drawGradientLine ) }, - { LSTRKEY( "drawHLine" ), LFUNCVAL( lucg_drawHLine ) }, - { LSTRKEY( "drawLine" ), LFUNCVAL( lucg_drawLine ) }, - { LSTRKEY( "drawPixel" ), LFUNCVAL( lucg_drawPixel ) }, - { LSTRKEY( "drawRBox" ), LFUNCVAL( lucg_drawRBox ) }, - { LSTRKEY( "drawRFrame" ), LFUNCVAL( lucg_drawRFrame ) }, - { LSTRKEY( "drawString" ), LFUNCVAL( lucg_drawString ) }, - { LSTRKEY( "drawTetragon" ), LFUNCVAL( lucg_drawTetragon ) }, - { LSTRKEY( "drawTriangle" ), LFUNCVAL( lucg_drawTriangle ) }, - { LSTRKEY( "drawVLine" ), LFUNCVAL( lucg_drawVLine ) }, - { LSTRKEY( "getFontAscent" ), LFUNCVAL( lucg_getFontAscent ) }, - { LSTRKEY( "getFontDescent" ), LFUNCVAL( lucg_getFontDescent ) }, - { LSTRKEY( "getHeight" ), LFUNCVAL( lucg_getHeight ) }, - { LSTRKEY( "getStrWidth" ), LFUNCVAL( lucg_getStrWidth ) }, - { LSTRKEY( "getWidth" ), LFUNCVAL( lucg_getWidth ) }, - { LSTRKEY( "print" ), LFUNCVAL( lucg_print ) }, - { LSTRKEY( "setClipRange" ), LFUNCVAL( lucg_setClipRange ) }, - { LSTRKEY( "setColor" ), LFUNCVAL( lucg_setColor ) }, - { LSTRKEY( "setFont" ), LFUNCVAL( lucg_setFont ) }, - { LSTRKEY( "setFontMode" ), LFUNCVAL( lucg_setFontMode ) }, - { LSTRKEY( "setFontPosBaseline" ), LFUNCVAL( lucg_setFontPosBaseline ) }, - { LSTRKEY( "setFontPosBottom" ), LFUNCVAL( lucg_setFontPosBottom ) }, - { LSTRKEY( "setFontPosCenter" ), LFUNCVAL( lucg_setFontPosCenter ) }, - { LSTRKEY( "setFontPosTop" ), LFUNCVAL( lucg_setFontPosTop ) }, - { LSTRKEY( "setMaxClipRange" ), LFUNCVAL( lucg_setMaxClipRange ) }, - { LSTRKEY( "setPrintDir" ), LFUNCVAL( lucg_setPrintDir ) }, - { LSTRKEY( "setPrintPos" ), LFUNCVAL( lucg_setPrintPos ) }, - { LSTRKEY( "setRotate90" ), LFUNCVAL( lucg_setRotate90 ) }, - { LSTRKEY( "setRotate180" ), LFUNCVAL( lucg_setRotate180 ) }, - { LSTRKEY( "setRotate270" ), LFUNCVAL( lucg_setRotate270 ) }, - { LSTRKEY( "setScale2x2" ), LFUNCVAL( lucg_setScale2x2 ) }, - { LSTRKEY( "undoClipRange" ), LFUNCVAL( lucg_setMaxClipRange ) }, - { LSTRKEY( "undoRotate" ), LFUNCVAL( lucg_undoRotate ) }, - { LSTRKEY( "undoScale" ), LFUNCVAL( lucg_undoScale ) }, - - { LSTRKEY( "__gc" ), LFUNCVAL( lucg_close_display ) }, - { LSTRKEY( "__index" ), LROVAL ( lucg_display_map ) }, - { LNILKEY, LNILVAL } -}; - -static const LUA_REG_TYPE lucg_map[] = -{ +LROT_BEGIN(lucg_display) + LROT_FUNCENTRY( begin, lucg_begin ) + LROT_FUNCENTRY( clearScreen, lucg_clearScreen ) + LROT_FUNCENTRY( draw90Line, lucg_draw90Line ) + LROT_FUNCENTRY( drawBox, lucg_drawBox ) + LROT_FUNCENTRY( drawCircle, lucg_drawCircle ) + LROT_FUNCENTRY( drawDisc, lucg_drawDisc ) + LROT_FUNCENTRY( drawFrame, lucg_drawFrame ) + LROT_FUNCENTRY( drawGlyph, lucg_drawGlyph ) + LROT_FUNCENTRY( drawGradientBox, lucg_drawGradientBox ) + LROT_FUNCENTRY( drawGradientLine, lucg_drawGradientLine ) + LROT_FUNCENTRY( drawHLine, lucg_drawHLine ) + LROT_FUNCENTRY( drawLine, lucg_drawLine ) + LROT_FUNCENTRY( drawPixel, lucg_drawPixel ) + LROT_FUNCENTRY( drawRBox, lucg_drawRBox ) + LROT_FUNCENTRY( drawRFrame, lucg_drawRFrame ) + LROT_FUNCENTRY( drawString, lucg_drawString ) + LROT_FUNCENTRY( drawTetragon, lucg_drawTetragon ) + LROT_FUNCENTRY( drawTriangle, lucg_drawTriangle ) + LROT_FUNCENTRY( drawVLine, lucg_drawVLine ) + LROT_FUNCENTRY( getFontAscent, lucg_getFontAscent ) + LROT_FUNCENTRY( getFontDescent, lucg_getFontDescent ) + LROT_FUNCENTRY( getHeight, lucg_getHeight ) + LROT_FUNCENTRY( getStrWidth, lucg_getStrWidth ) + LROT_FUNCENTRY( getWidth, lucg_getWidth ) + LROT_FUNCENTRY( print, lucg_print ) + LROT_FUNCENTRY( setClipRange, lucg_setClipRange ) + LROT_FUNCENTRY( setColor, lucg_setColor ) + LROT_FUNCENTRY( setFont, lucg_setFont ) + LROT_FUNCENTRY( setFontMode, lucg_setFontMode ) + LROT_FUNCENTRY( setFontPosBaseline, lucg_setFontPosBaseline ) + LROT_FUNCENTRY( setFontPosBottom, lucg_setFontPosBottom ) + LROT_FUNCENTRY( setFontPosCenter, lucg_setFontPosCenter ) + LROT_FUNCENTRY( setFontPosTop, lucg_setFontPosTop ) + LROT_FUNCENTRY( setMaxClipRange, lucg_setMaxClipRange ) + LROT_FUNCENTRY( setPrintDir, lucg_setPrintDir ) + LROT_FUNCENTRY( setPrintPos, lucg_setPrintPos ) + LROT_FUNCENTRY( setRotate90, lucg_setRotate90 ) + LROT_FUNCENTRY( setRotate180, lucg_setRotate180 ) + LROT_FUNCENTRY( setRotate270, lucg_setRotate270 ) + LROT_FUNCENTRY( setScale2x2, lucg_setScale2x2 ) + LROT_FUNCENTRY( undoClipRange, lucg_setMaxClipRange ) + LROT_FUNCENTRY( undoRotate, lucg_undoRotate ) + LROT_FUNCENTRY( undoScale, lucg_undoScale ) + + LROT_FUNCENTRY( __gc, lucg_close_display ) + LROT_TABENTRY( __index, lucg_display ) +LROT_END( lucg_display, lucg_display, 0 ) + + +LROT_BEGIN(lucg) #undef UCG_DISPLAY_TABLE_ENTRY -#define UCG_DISPLAY_TABLE_ENTRY(binding, device, extension) { LSTRKEY( #binding ), LFUNCVAL ( l ## binding ) }, +#define UCG_DISPLAY_TABLE_ENTRY(binding, device, extension) LROT_FUNCENTRY(binding,l ## binding) UCG_DISPLAY_TABLE // Register fonts #undef UCG_FONT_TABLE_ENTRY -#define UCG_FONT_TABLE_ENTRY(font) { LSTRKEY( #font ), LUDATA( (void *)(ucg_ ## font) ) }, +#define UCG_FONT_TABLE_ENTRY(font) LROT_LUDENTRY(font, ucg_ ## font ) UCG_FONT_TABLE // Font modes - { LSTRKEY( "FONT_MODE_TRANSPARENT" ), LNUMVAL( UCG_FONT_MODE_TRANSPARENT ) }, - { LSTRKEY( "FONT_MODE_SOLID" ), LNUMVAL( UCG_FONT_MODE_SOLID ) }, + LROT_NUMENTRY( FONT_MODE_TRANSPARENT, UCG_FONT_MODE_TRANSPARENT ) + LROT_NUMENTRY( FONT_MODE_SOLID, UCG_FONT_MODE_SOLID ) // Options for circle/ disc drawing - { LSTRKEY( "DRAW_UPPER_RIGHT" ), LNUMVAL( UCG_DRAW_UPPER_RIGHT ) }, - { LSTRKEY( "DRAW_UPPER_LEFT" ), LNUMVAL( UCG_DRAW_UPPER_LEFT ) }, - { LSTRKEY( "DRAW_LOWER_RIGHT" ), LNUMVAL( UCG_DRAW_LOWER_RIGHT ) }, - { LSTRKEY( "DRAW_LOWER_LEFT" ), LNUMVAL( UCG_DRAW_LOWER_LEFT ) }, - { LSTRKEY( "DRAW_ALL" ), LNUMVAL( UCG_DRAW_ALL ) }, + LROT_NUMENTRY( DRAW_UPPER_RIGHT, UCG_DRAW_UPPER_RIGHT ) + LROT_NUMENTRY( DRAW_UPPER_LEFT, UCG_DRAW_UPPER_LEFT ) + LROT_NUMENTRY( DRAW_LOWER_RIGHT, UCG_DRAW_LOWER_RIGHT ) + LROT_NUMENTRY( DRAW_LOWER_LEFT, UCG_DRAW_LOWER_LEFT ) + LROT_NUMENTRY( DRAW_ALL, UCG_DRAW_ALL ) + + LROT_TABENTRY( __metatable, lucg ) +LROT_END( lucg, lucg, 0 ) - { LSTRKEY( "__metatable" ), LROVAL( lucg_map ) }, - { LNILKEY, LNILVAL } -}; int luaopen_ucg( lua_State *L ) { - luaL_rometatable(L, "ucg.display", (void *)lucg_display_map); // create metatable + luaL_rometatable(L, "ucg.display", LROT_TABLEREF(lucg_display)); return 0; } -NODEMCU_MODULE(UCG, "ucg", lucg_map, luaopen_ucg); +NODEMCU_MODULE(UCG, "ucg", lucg, luaopen_ucg); #endif /* LUA_USE_MODULES_UCG */ diff --git a/app/modules/websocket.c b/app/modules/websocket.c index 0fa0b0f070..27e886afcb 100644 --- a/app/modules/websocket.c +++ b/app/modules/websocket.c @@ -307,28 +307,26 @@ static int websocketclient_gc(lua_State *L) { return 0; } -static const LUA_REG_TYPE websocket_map[] = -{ - { LSTRKEY("createClient"), LFUNCVAL(websocket_createClient) }, - { LNILKEY, LNILVAL } -}; - -static const LUA_REG_TYPE websocketclient_map[] = -{ - { LSTRKEY("on"), LFUNCVAL(websocketclient_on) }, - { LSTRKEY("config"), LFUNCVAL(websocketclient_config) }, - { LSTRKEY("connect"), LFUNCVAL(websocketclient_connect) }, - { LSTRKEY("send"), LFUNCVAL(websocketclient_send) }, - { LSTRKEY("close"), LFUNCVAL(websocketclient_close) }, - { LSTRKEY("__gc" ), LFUNCVAL(websocketclient_gc) }, - { LSTRKEY("__index"), LROVAL(websocketclient_map) }, - { LNILKEY, LNILVAL } -}; +LROT_BEGIN(websocket) + LROT_FUNCENTRY( createClient, websocket_createClient ) +LROT_END( websocket, NULL, 0 ) + + +LROT_BEGIN(websocketclient) + LROT_FUNCENTRY( on, websocketclient_on ) + LROT_FUNCENTRY( config, websocketclient_config ) + LROT_FUNCENTRY( connect, websocketclient_connect ) + LROT_FUNCENTRY( send, websocketclient_send ) + LROT_FUNCENTRY( close, websocketclient_close ) + LROT_FUNCENTRY( __gc, websocketclient_gc ) + LROT_TABENTRY( __index, websocketclient ) +LROT_END( websocketclient, websocketclient, LROT_MASK_GC_INDEX ) + int loadWebsocketModule(lua_State *L) { - luaL_rometatable(L, METATABLE_WSCLIENT, (void *) websocketclient_map); + luaL_rometatable(L, METATABLE_WSCLIENT, LROT_TABLEREF( websocketclient)); return 0; } -NODEMCU_MODULE(WEBSOCKET, "websocket", websocket_map, loadWebsocketModule); +NODEMCU_MODULE(WEBSOCKET, "websocket", websocket, loadWebsocketModule); diff --git a/app/modules/wifi.c b/app/modules/wifi.c index 4b92e63538..794fdef1b0 100644 --- a/app/modules/wifi.c +++ b/app/modules/wifi.c @@ -1864,114 +1864,114 @@ static int wifi_ap_dhcp_stop( lua_State* L ) // Module function map -static const LUA_REG_TYPE wifi_station_map[] = { - { LSTRKEY( "autoconnect" ), LFUNCVAL( wifi_station_setauto ) }, - { LSTRKEY( "changeap" ), LFUNCVAL( wifi_station_change_ap ) }, - { LSTRKEY( "clearconfig"), LFUNCVAL( wifi_station_clear_config ) }, - { LSTRKEY( "config" ), LFUNCVAL( wifi_station_config ) }, - { LSTRKEY( "connect" ), LFUNCVAL( wifi_station_connect4lua ) }, - { LSTRKEY( "disconnect" ), LFUNCVAL( wifi_station_disconnect4lua ) }, - { LSTRKEY( "getap" ), LFUNCVAL( wifi_station_listap ) }, - { LSTRKEY( "getapindex" ), LFUNCVAL( wifi_station_get_ap_index ) }, - { LSTRKEY( "getapinfo" ), LFUNCVAL( wifi_station_get_ap_info4lua ) }, - { LSTRKEY( "getbroadcast" ), LFUNCVAL( wifi_station_getbroadcast) }, - { LSTRKEY( "getconfig" ), LFUNCVAL( wifi_station_getconfig_current ) }, - { LSTRKEY( "getdefaultconfig" ), LFUNCVAL( wifi_station_getconfig_default ) }, - { LSTRKEY( "gethostname" ), LFUNCVAL( wifi_sta_gethostname ) }, - { LSTRKEY( "getip" ), LFUNCVAL( wifi_station_getip ) }, - { LSTRKEY( "getmac" ), LFUNCVAL( wifi_station_getmac ) }, - { LSTRKEY( "getrssi" ), LFUNCVAL( wifi_station_getrssi ) }, - { LSTRKEY( "setaplimit" ), LFUNCVAL( wifi_station_ap_number_set4lua ) }, - { LSTRKEY( "sethostname" ), LFUNCVAL( wifi_sta_sethostname_lua ) }, - { LSTRKEY( "setip" ), LFUNCVAL( wifi_station_setip ) }, - { LSTRKEY( "setmac" ), LFUNCVAL( wifi_station_setmac ) }, - { LSTRKEY( "sleeptype" ), LFUNCVAL( wifi_station_sleeptype ) }, - { LSTRKEY( "status" ), LFUNCVAL( wifi_station_status ) }, - { LNILKEY, LNILVAL } -}; - -static const LUA_REG_TYPE wifi_ap_dhcp_map[] = { - { LSTRKEY( "config" ), LFUNCVAL( wifi_ap_dhcp_config ) }, - { LSTRKEY( "start" ), LFUNCVAL( wifi_ap_dhcp_start ) }, - { LSTRKEY( "stop" ), LFUNCVAL( wifi_ap_dhcp_stop ) }, - { LNILKEY, LNILVAL } -}; - -static const LUA_REG_TYPE wifi_ap_map[] = { - { LSTRKEY( "config" ), LFUNCVAL( wifi_ap_config ) }, - { LSTRKEY( "deauth" ), LFUNCVAL( wifi_ap_deauth ) }, - { LSTRKEY( "getip" ), LFUNCVAL( wifi_ap_getip ) }, - { LSTRKEY( "setip" ), LFUNCVAL( wifi_ap_setip ) }, - { LSTRKEY( "getbroadcast" ), LFUNCVAL( wifi_ap_getbroadcast) }, - { LSTRKEY( "getmac" ), LFUNCVAL( wifi_ap_getmac ) }, - { LSTRKEY( "setmac" ), LFUNCVAL( wifi_ap_setmac ) }, - { LSTRKEY( "getclient" ), LFUNCVAL( wifi_ap_listclient ) }, - { LSTRKEY( "getconfig" ), LFUNCVAL( wifi_ap_getconfig_current ) }, - { LSTRKEY( "getdefaultconfig" ), LFUNCVAL( wifi_ap_getconfig_default ) }, - { LSTRKEY( "dhcp" ), LROVAL( wifi_ap_dhcp_map ) }, -//{ LSTRKEY( "__metatable" ), LROVAL( wifi_ap_map ) }, - { LNILKEY, LNILVAL } -}; - -static const LUA_REG_TYPE wifi_map[] = { - { LSTRKEY( "setmode" ), LFUNCVAL( wifi_setmode ) }, - { LSTRKEY( "getmode" ), LFUNCVAL( wifi_getmode ) }, - { LSTRKEY( "getdefaultmode" ), LFUNCVAL( wifi_getdefaultmode ) }, - { LSTRKEY( "getchannel" ), LFUNCVAL( wifi_getchannel ) }, - { LSTRKEY( "getcountry" ), LFUNCVAL( wifi_getcountry ) }, - { LSTRKEY( "setcountry" ), LFUNCVAL( wifi_setcountry ) }, - { LSTRKEY( "setphymode" ), LFUNCVAL( wifi_setphymode ) }, - { LSTRKEY( "getphymode" ), LFUNCVAL( wifi_getphymode ) }, - { LSTRKEY( "setmaxtxpower" ), LFUNCVAL( wifi_setmaxtxpower ) }, - { LSTRKEY( "suspend" ), LFUNCVAL( wifi_suspend ) }, - { LSTRKEY( "resume" ), LFUNCVAL( wifi_resume ) }, - { LSTRKEY( "nullmodesleep" ), LFUNCVAL( wifi_null_mode_auto_sleep ) }, +LROT_BEGIN(wifi_station) + LROT_FUNCENTRY( autoconnect, wifi_station_setauto ) + LROT_FUNCENTRY( changeap, wifi_station_change_ap ) + LROT_FUNCENTRY( clearconfig, wifi_station_clear_config ) + LROT_FUNCENTRY( config, wifi_station_config ) + LROT_FUNCENTRY( connect, wifi_station_connect4lua ) + LROT_FUNCENTRY( disconnect, wifi_station_disconnect4lua ) + LROT_FUNCENTRY( getap, wifi_station_listap ) + LROT_FUNCENTRY( getapindex, wifi_station_get_ap_index ) + LROT_FUNCENTRY( getapinfo, wifi_station_get_ap_info4lua ) + LROT_FUNCENTRY( getbroadcast, wifi_station_getbroadcast ) + LROT_FUNCENTRY( getconfig, wifi_station_getconfig_current ) + LROT_FUNCENTRY( getdefaultconfig, wifi_station_getconfig_default ) + LROT_FUNCENTRY( gethostname, wifi_sta_gethostname ) + LROT_FUNCENTRY( getip, wifi_station_getip ) + LROT_FUNCENTRY( getmac, wifi_station_getmac ) + LROT_FUNCENTRY( getrssi, wifi_station_getrssi ) + LROT_FUNCENTRY( setaplimit, wifi_station_ap_number_set4lua ) + LROT_FUNCENTRY( sethostname, wifi_sta_sethostname_lua ) + LROT_FUNCENTRY( setip, wifi_station_setip ) + LROT_FUNCENTRY( setmac, wifi_station_setmac ) + LROT_FUNCENTRY( sleeptype, wifi_station_sleeptype ) + LROT_FUNCENTRY( status, wifi_station_status ) +LROT_END( wifi_station, wifi_station, 0 ) + + +LROT_BEGIN(wifi_ap_dhcp) + LROT_FUNCENTRY( config, wifi_ap_dhcp_config ) + LROT_FUNCENTRY( start, wifi_ap_dhcp_start ) + LROT_FUNCENTRY( stop, wifi_ap_dhcp_stop ) +LROT_END( wifi_ap_dhcp, wifi_ap_dhcp, 0 ) + + +LROT_BEGIN(wifi_ap) + LROT_FUNCENTRY( config, wifi_ap_config ) + LROT_FUNCENTRY( deauth, wifi_ap_deauth ) + LROT_FUNCENTRY( getip, wifi_ap_getip ) + LROT_FUNCENTRY( setip, wifi_ap_setip ) + LROT_FUNCENTRY( getbroadcast, wifi_ap_getbroadcast ) + LROT_FUNCENTRY( getmac, wifi_ap_getmac ) + LROT_FUNCENTRY( setmac, wifi_ap_setmac ) + LROT_FUNCENTRY( getclient, wifi_ap_listclient ) + LROT_FUNCENTRY( getconfig, wifi_ap_getconfig_current ) + LROT_FUNCENTRY( getdefaultconfig, wifi_ap_getconfig_default ) + LROT_TABENTRY( dhcp, wifi_ap_dhcp ) +// LROT_TABENTRY( __metatable, wifi_ap ) +LROT_END( wifi_ap, wifi_ap, 0 ) + + +LROT_BEGIN(wifi) + LROT_FUNCENTRY( setmode, wifi_setmode ) + LROT_FUNCENTRY( getmode, wifi_getmode ) + LROT_FUNCENTRY( getdefaultmode, wifi_getdefaultmode ) + LROT_FUNCENTRY( getchannel, wifi_getchannel ) + LROT_FUNCENTRY( getcountry, wifi_getcountry ) + LROT_FUNCENTRY( setcountry, wifi_setcountry ) + LROT_FUNCENTRY( setphymode, wifi_setphymode ) + LROT_FUNCENTRY( getphymode, wifi_getphymode ) + LROT_FUNCENTRY( setmaxtxpower, wifi_setmaxtxpower ) + LROT_FUNCENTRY( suspend, wifi_suspend ) + LROT_FUNCENTRY( resume, wifi_resume ) + LROT_FUNCENTRY( nullmodesleep, wifi_null_mode_auto_sleep ) #ifdef WIFI_SMART_ENABLE - { LSTRKEY( "startsmart" ), LFUNCVAL( wifi_start_smart ) }, - { LSTRKEY( "stopsmart" ), LFUNCVAL( wifi_exit_smart ) }, + LROT_FUNCENTRY( startsmart, wifi_start_smart ) + LROT_FUNCENTRY( stopsmart, wifi_exit_smart ) #endif - { LSTRKEY( "sleeptype" ), LFUNCVAL( wifi_station_sleeptype ) }, + LROT_FUNCENTRY( sleeptype, wifi_station_sleeptype ) - { LSTRKEY( "sta" ), LROVAL( wifi_station_map ) }, - { LSTRKEY( "ap" ), LROVAL( wifi_ap_map ) }, + LROT_TABENTRY( sta, wifi_station ) + LROT_TABENTRY( ap, wifi_ap ) #if defined(WIFI_SDK_EVENT_MONITOR_ENABLE) - { LSTRKEY( "eventmon" ), LROVAL( wifi_event_monitor_map ) }, //declared in wifi_eventmon.c + LROT_TABENTRY( eventmon, wifi_event_monitor ) #endif #if defined(LUA_USE_MODULES_WIFI_MONITOR) - { LSTRKEY( "monitor" ), LROVAL( wifi_monitor_map ) }, //declared in wifi_monitor.c + LROT_TABENTRY( monitor, wifi_monitor ) #endif - { LSTRKEY( "NULLMODE" ), LNUMVAL( NULL_MODE ) }, - { LSTRKEY( "STATION" ), LNUMVAL( STATION_MODE ) }, - { LSTRKEY( "SOFTAP" ), LNUMVAL( SOFTAP_MODE ) }, - { LSTRKEY( "STATIONAP" ), LNUMVAL( STATIONAP_MODE ) }, - - { LSTRKEY( "PHYMODE_B" ), LNUMVAL( PHY_MODE_11B ) }, - { LSTRKEY( "PHYMODE_G" ), LNUMVAL( PHY_MODE_11G ) }, - { LSTRKEY( "PHYMODE_N" ), LNUMVAL( PHY_MODE_11N ) }, - - { LSTRKEY( "NONE_SLEEP" ), LNUMVAL( NONE_SLEEP_T ) }, - { LSTRKEY( "LIGHT_SLEEP" ), LNUMVAL( LIGHT_SLEEP_T ) }, - { LSTRKEY( "MODEM_SLEEP" ), LNUMVAL( MODEM_SLEEP_T ) }, - - { LSTRKEY( "OPEN" ), LNUMVAL( AUTH_OPEN ) }, -//{ LSTRKEY( "WEP" ), LNUMVAL( AUTH_WEP ) }, - { LSTRKEY( "WPA_PSK" ), LNUMVAL( AUTH_WPA_PSK ) }, - { LSTRKEY( "WPA2_PSK" ), LNUMVAL( AUTH_WPA2_PSK ) }, - { LSTRKEY( "WPA_WPA2_PSK" ), LNUMVAL( AUTH_WPA_WPA2_PSK ) }, - - { LSTRKEY( "STA_IDLE" ), LNUMVAL( STATION_IDLE ) }, - { LSTRKEY( "STA_CONNECTING" ), LNUMVAL( STATION_CONNECTING ) }, - { LSTRKEY( "STA_WRONGPWD" ), LNUMVAL( STATION_WRONG_PASSWORD ) }, - { LSTRKEY( "STA_APNOTFOUND" ), LNUMVAL( STATION_NO_AP_FOUND ) }, - { LSTRKEY( "STA_FAIL" ), LNUMVAL( STATION_CONNECT_FAIL ) }, - { LSTRKEY( "STA_GOTIP" ), LNUMVAL( STATION_GOT_IP ) }, - - { LSTRKEY( "COUNTRY_AUTO" ), LNUMVAL( WIFI_COUNTRY_POLICY_AUTO ) }, - { LSTRKEY( "COUNTRY_MANUAL" ), LNUMVAL( WIFI_COUNTRY_POLICY_MANUAL ) }, - - { LSTRKEY( "__metatable" ), LROVAL( wifi_map ) }, - { LNILKEY, LNILVAL } -}; + LROT_NUMENTRY( NULLMODE, NULL_MODE ) + LROT_NUMENTRY( STATION, STATION_MODE ) + LROT_NUMENTRY( SOFTAP, SOFTAP_MODE ) + LROT_NUMENTRY( STATIONAP, STATIONAP_MODE ) + + LROT_NUMENTRY( PHYMODE_B, PHY_MODE_11B ) + LROT_NUMENTRY( PHYMODE_G, PHY_MODE_11G ) + LROT_NUMENTRY( PHYMODE_N, PHY_MODE_11N ) + + LROT_NUMENTRY( NONE_SLEEP, NONE_SLEEP_T ) + LROT_NUMENTRY( LIGHT_SLEEP, LIGHT_SLEEP_T ) + LROT_NUMENTRY( MODEM_SLEEP, MODEM_SLEEP_T ) + + LROT_NUMENTRY( OPEN, AUTH_OPEN ) +// LROT_NUMENTRY( WEP, AUTH_WEP ) + LROT_NUMENTRY( WPA_PSK, AUTH_WPA_PSK ) + LROT_NUMENTRY( WPA2_PSK, AUTH_WPA2_PSK ) + LROT_NUMENTRY( WPA_WPA2_PSK, AUTH_WPA_WPA2_PSK ) + + LROT_NUMENTRY( STA_IDLE, STATION_IDLE ) + LROT_NUMENTRY( STA_CONNECTING, STATION_CONNECTING ) + LROT_NUMENTRY( STA_WRONGPWD, STATION_WRONG_PASSWORD ) + LROT_NUMENTRY( STA_APNOTFOUND, STATION_NO_AP_FOUND ) + LROT_NUMENTRY( STA_FAIL, STATION_CONNECT_FAIL ) + LROT_NUMENTRY( STA_GOTIP, STATION_GOT_IP ) + + LROT_NUMENTRY( COUNTRY_AUTO, WIFI_COUNTRY_POLICY_AUTO ) + LROT_NUMENTRY( COUNTRY_MANUAL, WIFI_COUNTRY_POLICY_MANUAL ) + + LROT_TABENTRY( __metatable, wifi ) +LROT_END( wifi, wifi, 0 ) + // Used by user_rf_pre_init(user_main.c) void wifi_change_default_host_name(void) @@ -2024,4 +2024,4 @@ int luaopen_wifi( lua_State *L ) return 0; } -NODEMCU_MODULE(WIFI, "wifi", wifi_map, luaopen_wifi); +NODEMCU_MODULE(WIFI, "wifi", wifi, luaopen_wifi); diff --git a/app/modules/wifi_common.h b/app/modules/wifi_common.h index 789633a35d..c94a857d97 100644 --- a/app/modules/wifi_common.h +++ b/app/modules/wifi_common.h @@ -58,13 +58,13 @@ enum wifi_suspension_state{ #ifdef WIFI_SDK_EVENT_MONITOR_ENABLE - extern const LUA_REG_TYPE wifi_event_monitor_map[]; + LROT_EXTERN(wifi_event_monitor); void wifi_eventmon_init(); int wifi_event_monitor_register(lua_State* L); #endif #ifdef LUA_USE_MODULES_WIFI_MONITOR - extern const LUA_REG_TYPE wifi_monitor_map[]; + LROT_EXTERN(wifi_monitor); int wifi_monitor_init(lua_State *L); #endif diff --git a/app/modules/wifi_eventmon.c b/app/modules/wifi_eventmon.c index 06bce2a3b1..89c2fb7daf 100644 --- a/app/modules/wifi_eventmon.c +++ b/app/modules/wifi_eventmon.c @@ -247,59 +247,57 @@ static void wifi_event_monitor_process_event_queue(task_param_t param, uint8 pri } #ifdef WIFI_EVENT_MONITOR_DISCONNECT_REASON_LIST_ENABLE -static const LUA_REG_TYPE wifi_event_monitor_reason_map[] = -{ - { LSTRKEY( "UNSPECIFIED" ), LNUMVAL( REASON_UNSPECIFIED ) }, - { LSTRKEY( "AUTH_EXPIRE" ), LNUMVAL( REASON_AUTH_EXPIRE ) }, - { LSTRKEY( "AUTH_LEAVE" ), LNUMVAL( REASON_AUTH_LEAVE ) }, - { LSTRKEY( "ASSOC_EXPIRE" ), LNUMVAL( REASON_ASSOC_EXPIRE ) }, - { LSTRKEY( "ASSOC_TOOMANY" ), LNUMVAL( REASON_ASSOC_TOOMANY ) }, - { LSTRKEY( "NOT_AUTHED" ), LNUMVAL( REASON_NOT_AUTHED ) }, - { LSTRKEY( "NOT_ASSOCED" ), LNUMVAL( REASON_NOT_ASSOCED ) }, - { LSTRKEY( "ASSOC_LEAVE" ), LNUMVAL( REASON_ASSOC_LEAVE ) }, - { LSTRKEY( "ASSOC_NOT_AUTHED" ), LNUMVAL( REASON_ASSOC_NOT_AUTHED ) }, - { LSTRKEY( "DISASSOC_PWRCAP_BAD" ), LNUMVAL( REASON_DISASSOC_PWRCAP_BAD ) }, - { LSTRKEY( "DISASSOC_SUPCHAN_BAD" ), LNUMVAL( REASON_DISASSOC_SUPCHAN_BAD ) }, - { LSTRKEY( "IE_INVALID" ), LNUMVAL( REASON_IE_INVALID ) }, - { LSTRKEY( "MIC_FAILURE" ), LNUMVAL( REASON_MIC_FAILURE ) }, - { LSTRKEY( "4WAY_HANDSHAKE_TIMEOUT" ), LNUMVAL( REASON_4WAY_HANDSHAKE_TIMEOUT ) }, - { LSTRKEY( "GROUP_KEY_UPDATE_TIMEOUT" ), LNUMVAL( REASON_GROUP_KEY_UPDATE_TIMEOUT ) }, - { LSTRKEY( "IE_IN_4WAY_DIFFERS" ), LNUMVAL( REASON_IE_IN_4WAY_DIFFERS ) }, - { LSTRKEY( "GROUP_CIPHER_INVALID" ), LNUMVAL( REASON_GROUP_CIPHER_INVALID ) }, - { LSTRKEY( "PAIRWISE_CIPHER_INVALID" ), LNUMVAL( REASON_PAIRWISE_CIPHER_INVALID ) }, - { LSTRKEY( "AKMP_INVALID" ), LNUMVAL( REASON_AKMP_INVALID ) }, - { LSTRKEY( "UNSUPP_RSN_IE_VERSION" ), LNUMVAL( REASON_UNSUPP_RSN_IE_VERSION ) }, - { LSTRKEY( "INVALID_RSN_IE_CAP" ), LNUMVAL( REASON_INVALID_RSN_IE_CAP ) }, - { LSTRKEY( "802_1X_AUTH_FAILED" ), LNUMVAL( REASON_802_1X_AUTH_FAILED ) }, - { LSTRKEY( "CIPHER_SUITE_REJECTED" ), LNUMVAL( REASON_CIPHER_SUITE_REJECTED ) }, - { LSTRKEY( "BEACON_TIMEOUT" ), LNUMVAL( REASON_BEACON_TIMEOUT ) }, - { LSTRKEY( "NO_AP_FOUND" ), LNUMVAL( REASON_NO_AP_FOUND ) }, - { LSTRKEY( "AUTH_FAIL" ), LNUMVAL( REASON_AUTH_FAIL ) }, - { LSTRKEY( "ASSOC_FAIL" ), LNUMVAL( REASON_ASSOC_FAIL ) }, - { LSTRKEY( "HANDSHAKE_TIMEOUT" ), LNUMVAL( REASON_HANDSHAKE_TIMEOUT ) }, - { LNILKEY, LNILVAL } -}; +LROT_BEGIN(wifi_event_monitor_reason) + LROT_NUMENTRY( UNSPECIFIED, REASON_UNSPECIFIED ) + LROT_NUMENTRY( AUTH_EXPIRE, REASON_AUTH_EXPIRE ) + LROT_NUMENTRY( AUTH_LEAVE, REASON_AUTH_LEAVE ) + LROT_NUMENTRY( ASSOC_EXPIRE, REASON_ASSOC_EXPIRE ) + LROT_NUMENTRY( ASSOC_TOOMANY, REASON_ASSOC_TOOMANY ) + LROT_NUMENTRY( NOT_AUTHED, REASON_NOT_AUTHED ) + LROT_NUMENTRY( NOT_ASSOCED, REASON_NOT_ASSOCED ) + LROT_NUMENTRY( ASSOC_LEAVE, REASON_ASSOC_LEAVE ) + LROT_NUMENTRY( ASSOC_NOT_AUTHED, REASON_ASSOC_NOT_AUTHED ) + LROT_NUMENTRY( DISASSOC_PWRCAP_BAD, REASON_DISASSOC_PWRCAP_BAD ) + LROT_NUMENTRY( DISASSOC_SUPCHAN_BAD, REASON_DISASSOC_SUPCHAN_BAD ) + LROT_NUMENTRY( IE_INVALID, REASON_IE_INVALID ) + LROT_NUMENTRY( MIC_FAILURE, REASON_MIC_FAILURE ) + LROT_NUMENTRY( 4WAY_HANDSHAKE_TIMEOUT, REASON_4WAY_HANDSHAKE_TIMEOUT ) + LROT_NUMENTRY( GROUP_KEY_UPDATE_TIMEOUT, REASON_GROUP_KEY_UPDATE_TIMEOUT ) + LROT_NUMENTRY( IE_IN_4WAY_DIFFERS, REASON_IE_IN_4WAY_DIFFERS ) + LROT_NUMENTRY( GROUP_CIPHER_INVALID, REASON_GROUP_CIPHER_INVALID ) + LROT_NUMENTRY( PAIRWISE_CIPHER_INVALID, REASON_PAIRWISE_CIPHER_INVALID ) + LROT_NUMENTRY( AKMP_INVALID, REASON_AKMP_INVALID ) + LROT_NUMENTRY( UNSUPP_RSN_IE_VERSION, REASON_UNSUPP_RSN_IE_VERSION ) + LROT_NUMENTRY( INVALID_RSN_IE_CAP, REASON_INVALID_RSN_IE_CAP ) + LROT_NUMENTRY( 802_1X_AUTH_FAILED, REASON_802_1X_AUTH_FAILED ) + LROT_NUMENTRY( CIPHER_SUITE_REJECTED, REASON_CIPHER_SUITE_REJECTED ) + LROT_NUMENTRY( BEACON_TIMEOUT, REASON_BEACON_TIMEOUT ) + LROT_NUMENTRY( NO_AP_FOUND, REASON_NO_AP_FOUND ) + LROT_NUMENTRY( AUTH_FAIL, REASON_AUTH_FAIL ) + LROT_NUMENTRY( ASSOC_FAIL, REASON_ASSOC_FAIL ) + LROT_NUMENTRY( HANDSHAKE_TIMEOUT, REASON_HANDSHAKE_TIMEOUT ) +LROT_END( wifi_event_monitor_reason, NULL, 0 ) + #endif -const LUA_REG_TYPE wifi_event_monitor_map[] = -{ - { LSTRKEY( "register" ), LFUNCVAL( wifi_event_monitor_register ) }, - { LSTRKEY( "unregister" ), LFUNCVAL( wifi_event_monitor_register ) }, - { LSTRKEY( "STA_CONNECTED" ), LNUMVAL( EVENT_STAMODE_CONNECTED ) }, - { LSTRKEY( "STA_DISCONNECTED" ), LNUMVAL( EVENT_STAMODE_DISCONNECTED ) }, - { LSTRKEY( "STA_AUTHMODE_CHANGE" ), LNUMVAL( EVENT_STAMODE_AUTHMODE_CHANGE ) }, - { LSTRKEY( "STA_GOT_IP" ), LNUMVAL( EVENT_STAMODE_GOT_IP ) }, - { LSTRKEY( "STA_DHCP_TIMEOUT" ), LNUMVAL( EVENT_STAMODE_DHCP_TIMEOUT ) }, - { LSTRKEY( "AP_STACONNECTED" ), LNUMVAL( EVENT_SOFTAPMODE_STACONNECTED ) }, - { LSTRKEY( "AP_STADISCONNECTED" ), LNUMVAL( EVENT_SOFTAPMODE_STADISCONNECTED ) }, - { LSTRKEY( "AP_PROBEREQRECVED" ), LNUMVAL( EVENT_SOFTAPMODE_PROBEREQRECVED ) }, - { LSTRKEY( "WIFI_MODE_CHANGED" ), LNUMVAL( EVENT_OPMODE_CHANGED ) }, - { LSTRKEY( "EVENT_MAX" ), LNUMVAL( EVENT_MAX ) }, +LROT_PUBLIC_BEGIN(wifi_event_monitor) + LROT_FUNCENTRY( register, wifi_event_monitor_register ) + LROT_FUNCENTRY( unregister, wifi_event_monitor_register ) + LROT_NUMENTRY( STA_CONNECTED, EVENT_STAMODE_CONNECTED ) + LROT_NUMENTRY( STA_DISCONNECTED, EVENT_STAMODE_DISCONNECTED ) + LROT_NUMENTRY( STA_AUTHMODE_CHANGE, EVENT_STAMODE_AUTHMODE_CHANGE ) + LROT_NUMENTRY( STA_GOT_IP, EVENT_STAMODE_GOT_IP ) + LROT_NUMENTRY( STA_DHCP_TIMEOUT, EVENT_STAMODE_DHCP_TIMEOUT ) + LROT_NUMENTRY( AP_STACONNECTED, EVENT_SOFTAPMODE_STACONNECTED ) + LROT_NUMENTRY( AP_STADISCONNECTED, EVENT_SOFTAPMODE_STADISCONNECTED ) + LROT_NUMENTRY( AP_PROBEREQRECVED, EVENT_SOFTAPMODE_PROBEREQRECVED ) + LROT_NUMENTRY( WIFI_MODE_CHANGED, EVENT_OPMODE_CHANGED ) + LROT_NUMENTRY( EVENT_MAX, EVENT_MAX ) #ifdef WIFI_EVENT_MONITOR_DISCONNECT_REASON_LIST_ENABLE - { LSTRKEY( "reason" ), LROVAL( wifi_event_monitor_reason_map ) }, + LROT_TABENTRY( reason, wifi_event_monitor_reason ) #endif - { LNILKEY, LNILVAL } -}; +LROT_END( wifi_event_monitor, NULL, 0 ) + void wifi_eventmon_init() { diff --git a/app/modules/wifi_monitor.c b/app/modules/wifi_monitor.c index 6bea56f898..88067b8fd4 100644 --- a/app/modules/wifi_monitor.c +++ b/app/modules/wifi_monitor.c @@ -276,7 +276,7 @@ typedef struct { uint8 buf[]; } packet_t; -static const LUA_REG_TYPE packet_function_map[]; +LROT_TABLE(packet_function) static void wifi_rx_cb(uint8 *buf, uint16 len) { if (len != sizeof(struct sniffer_buf2)) { @@ -570,7 +570,7 @@ static int packet_map_lookup(lua_State *L) { } // Now search the packet function map - lua_pushrotable(L, (void *)packet_function_map); + lua_pushrotable(L, LROT_TABLEREF(packet_function)); lua_getfield(L, -1, field); if (!lua_isnil(L, -1)) { return 1; @@ -757,32 +757,32 @@ static int wifi_monitor_stop(lua_State *L) { return 0; } -static const LUA_REG_TYPE packet_function_map[] = { - { LSTRKEY( "radio_byte" ), LFUNCVAL( packet_radio_byte ) }, - { LSTRKEY( "frame_byte" ), LFUNCVAL( packet_frame_byte ) }, - { LSTRKEY( "radio_sub" ), LFUNCVAL( packet_radio_sub ) }, - { LSTRKEY( "frame_sub" ), LFUNCVAL( packet_frame_sub ) }, - { LSTRKEY( "radio_subhex" ), LFUNCVAL( packet_radio_subhex ) }, - { LSTRKEY( "frame_subhex" ), LFUNCVAL( packet_frame_subhex ) }, - { LNILKEY, LNILVAL } -}; +LROT_BEGIN(packet_function) + LROT_FUNCENTRY( radio_byte, packet_radio_byte ) + LROT_FUNCENTRY( frame_byte, packet_frame_byte ) + LROT_FUNCENTRY( radio_sub, packet_radio_sub ) + LROT_FUNCENTRY( frame_sub, packet_frame_sub ) + LROT_FUNCENTRY( radio_subhex, packet_radio_subhex ) + LROT_FUNCENTRY( frame_subhex, packet_frame_subhex ) +LROT_END( packet_function, packet_function, LROT_MASK_INDEX ) + + +LROT_BEGIN(packet) + LROT_FUNCENTRY( __index, packet_map_lookup ) +LROT_END( packet, packet, LROT_MASK_INDEX ) -static const LUA_REG_TYPE packet_map[] = { - { LSTRKEY( "__index" ), LFUNCVAL( packet_map_lookup ) }, - { LNILKEY, LNILVAL } -}; // Module function map -const LUA_REG_TYPE wifi_monitor_map[] = { - { LSTRKEY( "start" ), LFUNCVAL( wifi_monitor_start ) }, - { LSTRKEY( "stop" ), LFUNCVAL( wifi_monitor_stop ) }, - { LSTRKEY( "channel" ), LFUNCVAL( wifi_monitor_channel ) }, - { LNILKEY, LNILVAL } -}; +LROT_PUBLIC_BEGIN(wifi_monitor) + LROT_FUNCENTRY( start, wifi_monitor_start ) + LROT_FUNCENTRY( stop, wifi_monitor_stop ) + LROT_FUNCENTRY( channel, wifi_monitor_channel ) +LROT_END( wifi_monitor, NULL, 0 ) + int wifi_monitor_init(lua_State *L) { - luaL_rometatable(L, "wifi.packet", (void *)packet_map); + luaL_rometatable(L, "wifi.packet", LROT_TABLEREF(packet)); tasknumber = task_get_id(monitor_task); eventmon_setup(); diff --git a/app/modules/wps.c b/app/modules/wps.c index 0513eaca4d..e23f6be55c 100644 --- a/app/modules/wps.c +++ b/app/modules/wps.c @@ -52,22 +52,22 @@ static int ICACHE_FLASH_ATTR wps_start(lua_State* L) } // Module function map -const LUA_REG_TYPE wps_map[] = { - { LSTRKEY( "disable" ), LFUNCVAL( wps_disable ) }, - { LSTRKEY( "enable" ), LFUNCVAL( wps_enable ) }, - { LSTRKEY( "start" ), LFUNCVAL( wps_start ) }, - { LSTRKEY( "SUCCESS" ), LNUMVAL( WPS_CB_ST_SUCCESS ) }, - { LSTRKEY( "FAILED" ), LNUMVAL( WPS_CB_ST_FAILED ) }, - { LSTRKEY( "TIMEOUT" ), LNUMVAL( WPS_CB_ST_TIMEOUT ) }, - { LSTRKEY( "WEP" ), LNUMVAL( WPS_CB_ST_WEP ) }, - { LSTRKEY( "SCAN_ERR" ), LNUMVAL( 4 ) }, // WPS_CB_ST_SCAN_ERR - { LNILKEY, LNILVAL } -}; +LROT_BEGIN(wps) + LROT_FUNCENTRY( disable, wps_disable ) + LROT_FUNCENTRY( enable, wps_enable ) + LROT_FUNCENTRY( start, wps_start ) + LROT_NUMENTRY( SUCCESS, WPS_CB_ST_SUCCESS ) + LROT_NUMENTRY( FAILED, WPS_CB_ST_FAILED ) + LROT_NUMENTRY( TIMEOUT, WPS_CB_ST_TIMEOUT ) + LROT_NUMENTRY( WEP, WPS_CB_ST_WEP ) + LROT_NUMENTRY( SCAN_ERR, 4 ) +LROT_END( wps, NULL, 0 ) + int luaopen_wps( lua_State *L ) { return 0; } -NODEMCU_MODULE(WPS, "wps", wps_map, luaopen_wps); +NODEMCU_MODULE(WPS, "wps", wps, luaopen_wps); diff --git a/app/modules/ws2801.c b/app/modules/ws2801.c index 57e54bc919..b325898ba3 100644 --- a/app/modules/ws2801.c +++ b/app/modules/ws2801.c @@ -122,11 +122,10 @@ static int ICACHE_FLASH_ATTR ws2801_writergb(lua_State* L) { return 0; } -static const LUA_REG_TYPE ws2801_map[] = -{ - { LSTRKEY( "write" ), LFUNCVAL( ws2801_writergb )}, - { LSTRKEY( "init" ), LFUNCVAL( ws2801_init_lua )}, - { LNILKEY, LNILVAL} -}; - -NODEMCU_MODULE(WS2801, "ws2801", ws2801_map, NULL); +LROT_BEGIN(ws2801) + LROT_FUNCENTRY( write, ws2801_writergb ) + LROT_FUNCENTRY( init, ws2801_init_lua ) +LROT_END( ws2801, NULL, 0 ) + + +NODEMCU_MODULE(WS2801, "ws2801", ws2801, NULL); diff --git a/app/modules/ws2812.c b/app/modules/ws2812.c index 3ca69c5187..a962fc8b2b 100644 --- a/app/modules/ws2812.c +++ b/app/modules/ws2812.c @@ -591,44 +591,42 @@ static int ws2812_buffer_tostring(lua_State* L) { } -static const LUA_REG_TYPE ws2812_buffer_map[] = -{ - { LSTRKEY( "dump" ), LFUNCVAL( ws2812_buffer_dump )}, - { LSTRKEY( "fade" ), LFUNCVAL( ws2812_buffer_fade )}, - { LSTRKEY( "fill" ), LFUNCVAL( ws2812_buffer_fill_lua )}, - { LSTRKEY( "get" ), LFUNCVAL( ws2812_buffer_get )}, - { LSTRKEY( "replace" ), LFUNCVAL( ws2812_buffer_replace )}, - { LSTRKEY( "mix" ), LFUNCVAL( ws2812_buffer_mix )}, - { LSTRKEY( "power" ), LFUNCVAL( ws2812_buffer_power )}, - { LSTRKEY( "set" ), LFUNCVAL( ws2812_buffer_set )}, - { LSTRKEY( "shift" ), LFUNCVAL( ws2812_buffer_shift_lua )}, - { LSTRKEY( "size" ), LFUNCVAL( ws2812_buffer_size )}, - { LSTRKEY( "sub" ), LFUNCVAL( ws2812_buffer_sub )}, - { LSTRKEY( "__concat" ),LFUNCVAL( ws2812_buffer_concat )}, - { LSTRKEY( "__index" ), LROVAL( ws2812_buffer_map )}, - { LSTRKEY( "__tostring" ), LFUNCVAL( ws2812_buffer_tostring )}, - { LNILKEY, LNILVAL} -}; - - -static const LUA_REG_TYPE ws2812_map[] = -{ - { LSTRKEY( "init" ), LFUNCVAL( ws2812_init )}, - { LSTRKEY( "newBuffer" ), LFUNCVAL( ws2812_new_buffer )}, - { LSTRKEY( "write" ), LFUNCVAL( ws2812_write )}, - { LSTRKEY( "FADE_IN" ), LNUMVAL( FADE_IN ) }, - { LSTRKEY( "FADE_OUT" ), LNUMVAL( FADE_OUT ) }, - { LSTRKEY( "MODE_SINGLE" ), LNUMVAL( MODE_SINGLE ) }, - { LSTRKEY( "MODE_DUAL" ), LNUMVAL( MODE_DUAL ) }, - { LSTRKEY( "SHIFT_LOGICAL" ), LNUMVAL( SHIFT_LOGICAL ) }, - { LSTRKEY( "SHIFT_CIRCULAR" ), LNUMVAL( SHIFT_CIRCULAR ) }, - { LNILKEY, LNILVAL} -}; +LROT_BEGIN(ws2812_buffer) + LROT_FUNCENTRY( dump, ws2812_buffer_dump ) + LROT_FUNCENTRY( fade, ws2812_buffer_fade ) + LROT_FUNCENTRY( fill, ws2812_buffer_fill_lua ) + LROT_FUNCENTRY( get, ws2812_buffer_get ) + LROT_FUNCENTRY( replace, ws2812_buffer_replace ) + LROT_FUNCENTRY( mix, ws2812_buffer_mix ) + LROT_FUNCENTRY( power, ws2812_buffer_power ) + LROT_FUNCENTRY( set, ws2812_buffer_set ) + LROT_FUNCENTRY( shift, ws2812_buffer_shift_lua ) + LROT_FUNCENTRY( size, ws2812_buffer_size ) + LROT_FUNCENTRY( sub, ws2812_buffer_sub ) + LROT_FUNCENTRY( __concat, ws2812_buffer_concat ) + LROT_TABENTRY( __index, ws2812_buffer ) + LROT_FUNCENTRY( __tostring, ws2812_buffer_tostring ) +LROT_END( ws2812_buffer, ws2812_buffer, LROT_MASK_INDEX ) + + + +LROT_BEGIN(ws2812) + LROT_FUNCENTRY( init, ws2812_init ) + LROT_FUNCENTRY( newBuffer, ws2812_new_buffer ) + LROT_FUNCENTRY( write, ws2812_write ) + LROT_NUMENTRY( FADE_IN, FADE_IN ) + LROT_NUMENTRY( FADE_OUT, FADE_OUT ) + LROT_NUMENTRY( MODE_SINGLE, MODE_SINGLE ) + LROT_NUMENTRY( MODE_DUAL, MODE_DUAL ) + LROT_NUMENTRY( SHIFT_LOGICAL, SHIFT_LOGICAL ) + LROT_NUMENTRY( SHIFT_CIRCULAR, SHIFT_CIRCULAR ) +LROT_END( ws2812, NULL, 0 ) + int luaopen_ws2812(lua_State *L) { // TODO: Make sure that the GPIO system is initialized - luaL_rometatable(L, "ws2812.buffer", (void *)ws2812_buffer_map); // create metatable for ws2812.buffer + luaL_rometatable(L, "ws2812.buffer", LROT_TABLEREF(ws2812_buffer)); return 0; } -NODEMCU_MODULE(WS2812, "ws2812", ws2812_map, luaopen_ws2812); +NODEMCU_MODULE(WS2812, "ws2812", ws2812, luaopen_ws2812); diff --git a/app/modules/ws2812_effects.c b/app/modules/ws2812_effects.c index 17b7306ed0..6945c8b8b3 100644 --- a/app/modules/ws2812_effects.c +++ b/app/modules/ws2812_effects.c @@ -1038,23 +1038,22 @@ static int ws2812_effects_tostring(lua_State* L) { return 1; } -static const LUA_REG_TYPE ws2812_effects_map[] = -{ - { LSTRKEY( "init" ), LFUNCVAL( ws2812_effects_init )}, - { LSTRKEY( "set_brightness" ), LFUNCVAL( ws2812_effects_set_brightness )}, - { LSTRKEY( "set_color" ), LFUNCVAL( ws2812_effects_set_color )}, - { LSTRKEY( "set_speed" ), LFUNCVAL( ws2812_effects_set_speed )}, - { LSTRKEY( "set_delay" ), LFUNCVAL( ws2812_effects_set_delay )}, - { LSTRKEY( "set_mode" ), LFUNCVAL( ws2812_effects_set_mode )}, - { LSTRKEY( "start" ), LFUNCVAL( ws2812_effects_start )}, - { LSTRKEY( "stop" ), LFUNCVAL( ws2812_effects_stop )}, - { LSTRKEY( "get_delay" ), LFUNCVAL( ws2812_effects_get_delay )}, - { LSTRKEY( "get_speed" ), LFUNCVAL( ws2812_effects_get_speed )}, - - { LSTRKEY( "__index" ), LROVAL( ws2812_effects_map )}, - { LSTRKEY( "__tostring" ), LFUNCVAL( ws2812_effects_tostring )}, - { LNILKEY, LNILVAL} -}; +LROT_BEGIN(ws2812_effects) + LROT_FUNCENTRY( init, ws2812_effects_init ) + LROT_FUNCENTRY( set_brightness, ws2812_effects_set_brightness ) + LROT_FUNCENTRY( set_color, ws2812_effects_set_color ) + LROT_FUNCENTRY( set_speed, ws2812_effects_set_speed ) + LROT_FUNCENTRY( set_delay, ws2812_effects_set_delay ) + LROT_FUNCENTRY( set_mode, ws2812_effects_set_mode ) + LROT_FUNCENTRY( start, ws2812_effects_start ) + LROT_FUNCENTRY( stop, ws2812_effects_stop ) + LROT_FUNCENTRY( get_delay, ws2812_effects_get_delay ) + LROT_FUNCENTRY( get_speed, ws2812_effects_get_speed ) + + LROT_TABENTRY( __index, ws2812_effects ) + LROT_FUNCENTRY( __tostring, ws2812_effects_tostring ) +LROT_END( ws2812_effects, ws2812_effects, LROT_MASK_INDEX ) + -NODEMCU_MODULE(WS2812_EFFECTS, "ws2812_effects", ws2812_effects_map, NULL); +NODEMCU_MODULE(WS2812_EFFECTS, "ws2812_effects", ws2812_effects, NULL); diff --git a/app/modules/xpt2046.c b/app/modules/xpt2046.c index 5bd90f4246..ebe29085ec 100644 --- a/app/modules/xpt2046.c +++ b/app/modules/xpt2046.c @@ -203,15 +203,15 @@ static int xpt2046_getPositionAvg( lua_State* L ) { } // Module function map -static const LUA_REG_TYPE xpt2046_map[] = { - { LSTRKEY( "isTouched"), LFUNCVAL(xpt2046_isTouched) }, - { LSTRKEY( "getRaw" ), LFUNCVAL(xpt2046_getRaw) }, - { LSTRKEY( "getPosition"), LFUNCVAL(xpt2046_getPosition)}, - { LSTRKEY( "getPositionAvg"), LFUNCVAL(xpt2046_getPositionAvg)}, - { LSTRKEY( "setCalibration"), LFUNCVAL(xpt2046_setCalibration)}, - { LSTRKEY( "init" ), LFUNCVAL(xpt2046_init) }, - { LNILKEY, LNILVAL } -}; - - -NODEMCU_MODULE(XPT2046, "xpt2046", xpt2046_map, NULL); +LROT_BEGIN(xpt2046) + LROT_FUNCENTRY( isTouched, xpt2046_isTouched ) + LROT_FUNCENTRY( getRaw, xpt2046_getRaw ) + LROT_FUNCENTRY( getPosition, xpt2046_getPosition ) + LROT_FUNCENTRY( getPositionAvg, xpt2046_getPositionAvg ) + LROT_FUNCENTRY( setCalibration, xpt2046_setCalibration ) + LROT_FUNCENTRY( init, xpt2046_init ) +LROT_END( xpt2046, NULL, 0 ) + + + +NODEMCU_MODULE(XPT2046, "xpt2046", xpt2046, NULL); diff --git a/app/pm/swtimer.c b/app/pm/swtimer.c index 3faf45ceb4..64fbeeb058 100644 --- a/app/pm/swtimer.c +++ b/app/pm/swtimer.c @@ -530,15 +530,15 @@ int resume_timers_lua(lua_State* L){ return 0; } -static const LUA_REG_TYPE test_swtimer_debug_map[] = { - { LSTRKEY( "timer_list" ), LFUNCVAL( print_timer_list ) }, - { LSTRKEY( "susp_timer_list" ), LFUNCVAL( print_susp_timer_list ) }, - { LSTRKEY( "suspend" ), LFUNCVAL( suspend_timers_lua ) }, - { LSTRKEY( "resume" ), LFUNCVAL( resume_timers_lua ) }, - { LNILKEY, LNILVAL } -}; - -NODEMCU_MODULE(SWTMR_DBG, "SWTMR_DBG", test_swtimer_debug_map, NULL); +LROT_BEGIN(test_swtimer_debug) + LROT_FUNCENTRY( timer_list, print_timer_list ) + LROT_FUNCENTRY( susp_timer_list, print_susp_timer_list ) + LROT_FUNCENTRY( suspend, suspend_timers_lua ) + LROT_FUNCENTRY( resume, resume_timers_lua ) +LROT_END( test_swtimer_debug, NULL, 0 ) + + +NODEMCU_MODULE(SWTMR_DBG, "SWTMR_DBG", test_swtimer_debug, NULL); #endif From f1b5dfc34e89825fde61e32f9fa29eaf79f238b1 Mon Sep 17 00:00:00 2001 From: Terry Ellison Date: Fri, 17 May 2019 13:04:19 +0100 Subject: [PATCH 17/74] SDK-3.0 tranche updates (#2757) includes some dRAM -> iRAM optimisations --- Makefile | 37 +++++++++++++++++++++---------------- app/Makefile | 1 + app/esp-gdbstub/gdbstub.c | 2 +- app/include/user_config.h | 2 ++ app/lua/lauxlib.c | 10 ++++++++-- app/lua/lrotable.c | 33 ++++++++++++++++++++++++--------- app/lwip/core/dns.c | 2 +- app/modules/node.c | 2 +- app/spiffs/spiffs.c | 4 ++-- app/user/user_main.c | 2 +- ld/nodemcu.ld | 1 + tools/nodemcu-partition.py | 3 ++- 12 files changed, 65 insertions(+), 34 deletions(-) diff --git a/Makefile b/Makefile index a642f6d45b..7b9631a502 100644 --- a/Makefile +++ b/Makefile @@ -9,18 +9,23 @@ TOP_DIR:=$(abspath $(dir $(lastword $(MAKEFILE_LIST)))) # RELEASE = lastest pulls the latest V3.0.0 branch version as at the issue of this make # otherwise it pulls the labelled version in the SDK version's release directory # -ifeq ("$(RELEASE)","latest") - export RELEASE:=$(RELEASE) - SDK_VER := 3.0.0-dev-190412 - SDK_COMMIT_SHA1:= 39ec2d4573eb77fda73f6afcf6dd1b3c41e74fcd - SDK_FILE_SHA1 := 44f7724490739536526fc4298d6fcc2fa2d29471 - SDK_ZIP_ROOT := ESP8266_NONOS_SDK-$(SDK_COMMIT_SHA1) - SDK_FILE_VER := $(SDK_COMMIT_SHA1) -else - SDK_VER := 3.0 - SDK_FILE_SHA1 := 029fc23fe87e03c9852de636490b2d7b9e07f01a +ifeq ("$(RELEASE)","latest-3.0") + SDK_VER := 3.0.0 + SDK_FILE_SHA1 := NA + SDK_ZIP_ROOT := ESP8266_NONOS_SDK-release-v$(SDK_VER) + SDK_FILE_VER := release/v$(SDK_VER) +else ifeq ("$(RELEASE)","master") + SDK_VER := master + SDK_FILE_SHA1 := NA SDK_ZIP_ROOT := ESP8266_NONOS_SDK-$(SDK_VER) - SDK_FILE_VER := v$(SDK_VER) + SDK_FILE_VER := $(SDK_VER) +else +# SDK_VER := 3.0 +# SDK_FILE_VER := v$(SDK_VER) + SDK_FILE_VER := e4434aa730e78c63040ace360493aef420ec267c + SDK_VER := 3.0-e4434aa + SDK_FILE_SHA1 := ac6528a6a206d3d4c220e4035ced423eb314cfbf + SDK_ZIP_ROOT := ESP8266_NONOS_SDK-$(SDK_FILE_VER) endif SDK_REL_DIR := sdk/esp_iot_sdk_v$(SDK_VER) SDK_DIR := $(TOP_DIR)/$(SDK_REL_DIR) @@ -314,10 +319,10 @@ $(TOP_DIR)/sdk/.extracted-$(SDK_VER): $(TOP_DIR)/cache/$(SDK_FILE_VER).zip (cd "$(dir $@)" && \ rm -fr esp_iot_sdk_v$(SDK_VER) ESP8266_NONOS_SDK-* && \ unzip $(TOP_DIR)/cache/$(SDK_FILE_VER).zip \ - '$(SDK_ZIP_ROOT)/lib/*' \ - '$(SDK_ZIP_ROOT)/ld/*.v6.ld' \ - '$(SDK_ZIP_ROOT)/include/*' \ - '$(SDK_ZIP_ROOT)/bin/esp_init_data_default_v05.bin' \ + '*/lib/*' \ + '*/ld/*.v6.ld' \ + '*/include/*' \ + '*/bin/esp_init_data_default_v05.bin' \ ) mv $(dir $@)/$(SDK_ZIP_ROOT) $(dir $@)/esp_iot_sdk_v$(SDK_VER) touch $@ @@ -334,7 +339,7 @@ $(TOP_DIR)/cache/$(SDK_FILE_VER).zip: mkdir -p "$(dir $@)" $(summary) WGET $(patsubst $(TOP_DIR)/%,%,$@) $(WGET) $(GITHUB_SDK)/archive/$(SDK_FILE_VER).zip -O $@ || { rm -f "$@"; exit 1; } - (echo "$(SDK_FILE_SHA1) $@" | sha1sum -c -) || { rm -f "$@"; exit 1; } + if test "$(SDK_FILE_SHA1)" != "NA"; then echo "$(SDK_FILE_SHA1) $@" | sha1sum -c - || { rm -f "$@"; exit 1; }; fi clean: $(foreach d, $(SUBDIRS), $(MAKE) -C $(d) clean;) diff --git a/app/Makefile b/app/Makefile index e4aa96c2a9..52c57da566 100644 --- a/app/Makefile +++ b/app/Makefile @@ -143,6 +143,7 @@ CONFIGURATION_DEFINES = -D__ets__ \ -DEBUF_LWIP \ -DUSE_OPTIMIZE_PRINTF \ -DMBEDTLS_USER_CONFIG_FILE=\"user_mbedtls.h\" \ + -DMEM_DEFAULT_USE_DRAM DEFINES += \ $(UNIVERSAL_TARGET_DEFINES) \ diff --git a/app/esp-gdbstub/gdbstub.c b/app/esp-gdbstub/gdbstub.c index 509e9bb403..9849b5c43e 100644 --- a/app/esp-gdbstub/gdbstub.c +++ b/app/esp-gdbstub/gdbstub.c @@ -107,7 +107,7 @@ extern void xthal_set_intenable(int); #define OBUFLEN 32 //The asm stub saves the Xtensa registers here when a debugging exception happens. -struct XTensa_exception_frame_s gdbstub_savedRegs; +struct XTensa_exception_frame_s IRAM_DATA_ATTR gdbstub_savedRegs; #if GDBSTUB_USE_OWN_STACK //This is the debugging exception stack. int exceptionStack[256]; diff --git a/app/include/user_config.h b/app/include/user_config.h index 49f79c8691..64870bb239 100644 --- a/app/include/user_config.h +++ b/app/include/user_config.h @@ -278,6 +278,8 @@ extern void luaL_dbgbreak(void); #define ICACHE_FLASH_RESERVED_ATTR \ __attribute__((section(".irom.reserved." __FILE__ "." ICACHE_STRING(__LINE__)),\ used,unused,aligned(INTERNAL_FLASH_SECTOR_SIZE))) +#define IRAM_DATA_ATTR \ + __attribute__((section(".iram0.data." __FILE__ "." ICACHE_STRING(__LINE__)))) #ifdef GPIO_SAFE_NO_INTR_ENABLE #define NO_INTR_CODE ICACHE_RAM_ATTR __attribute__ ((noinline)) diff --git a/app/lua/lauxlib.c b/app/lua/lauxlib.c index de2ae48978..514b75e361 100644 --- a/app/lua/lauxlib.c +++ b/app/lua/lauxlib.c @@ -918,6 +918,11 @@ static int l_check_memlimit(lua_State *L, size_t needbytes) { return (g->totalbytes >= limit) ? 1 : 0; } +#ifndef LUA_CROSS_COMPILER +#define REALLOC(p,o,n) (void *) this_realloc(p,o,n) +#else +#define REALLOC(p,o,n) (void *) (ptr? this_realloc(p,o,n) : c_malloc(n)) +#endif static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) { lua_State *L = (lua_State *)ud; @@ -946,10 +951,11 @@ static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) { if(G(L)->memlimit > 0 && (mode & EGC_ON_MEM_LIMIT) && l_check_memlimit(L, nsize - osize)) return NULL; } - nptr = (void *)this_realloc(ptr, osize, nsize); + nptr = REALLOC(ptr, osize, nsize); if (nptr == NULL && L != NULL && (mode & EGC_ON_ALLOC_FAILURE)) { + dbg_printf("Emergency full collection\n"); /**** DEBUG ***/ luaC_fullgc(L); /* emergency full collection. */ - nptr = (void *)this_realloc(ptr, osize, nsize); /* try allocation again */ + nptr = REALLOC(ptr, osize, nsize); /* try allocation again */ } return nptr; } diff --git a/app/lua/lrotable.c b/app/lua/lrotable.c index 80230db864..d4290ae150 100644 --- a/app/lua/lrotable.c +++ b/app/lua/lrotable.c @@ -14,6 +14,12 @@ #else #define ALIGNED_STRING (__attribute__((aligned(4))) char *) #endif + +#ifdef LUA_CROSS_COMPILER +#undef IRAM_DATA_ATTR +#define IRAM_DATA_ATTR +#endif + #define LA_LINES 32 #define LA_SLOTS 4 //#define COLLECT_STATS @@ -36,13 +42,15 @@ * Note that this hash does a couple of prime multiples and a modulus 2^X * with is all evaluated in H/W, and adequately randomizes the lookup. */ -#define HASH(a,b) ((((519*(size_t)(a)))>>4) + ((b) ? (b)->tsv.hash: 0)) +#define HASH(a,b) (unsigned)((((519*(size_t)(a)))>>4) + ((b) ? (b)->tsv.hash: 0)) -static struct { +typedef struct { unsigned hash; unsigned addr:24; unsigned ndx:8; -} cache[LA_LINES][LA_SLOTS]; +} cache_line_t; + +static cache_line_t IRAM_DATA_ATTR cache[LA_LINES][LA_SLOTS]; #ifdef COLLECT_STATS unsigned cache_stats[3]; @@ -55,10 +63,10 @@ static int lookup_cache(unsigned hash, ROTable *rotable) { int i = (hash>>2) & (LA_LINES-1), j; for (j = 0; j>2 & (LA_LINES-1), j; +#ifndef _MSC_VER + cache_line_t cl = {hash, (size_t) rotable, ndx}; +#else + cache_line_t cl; // MSC doesn't allow non-scalar initialisers, which + cl.hash = hash; // is a pity because xtensa gcc generates optimum + cl.addr = (size_t) rotable; // code using them. + cl.ndx = ndx; +#endif + COUNT(2); if (ndx>0xffu) return; for (j = LA_SLOTS-1; j>0; j--) cache[i][j] = cache[i][j-1]; - cache[i][0].hash = hash; - cache[i][0].addr = (size_t) rotable; - cache[i][0].ndx = ndx; + cache[i][0] = cl; } /* * Find a string key entry in a rotable and return it. Note that this internally diff --git a/app/lwip/core/dns.c b/app/lwip/core/dns.c index 90ea11240f..9a77575dbf 100644 --- a/app/lwip/core/dns.c +++ b/app/lwip/core/dns.c @@ -222,7 +222,7 @@ static void dns_check_entries(void); /* DNS variables */ static struct udp_pcb *dns_pcb; static u8_t dns_seqno; -static struct dns_table_entry dns_table[DNS_TABLE_SIZE]; +static struct dns_table_entry IRAM_DATA_ATTR dns_table[DNS_TABLE_SIZE]; static ip_addr_t dns_servers[DNS_MAX_SERVERS]; /** Contiguous buffer for processing responses */ //static u8_t dns_payload_buffer[LWIP_MEM_ALIGN_BUFFER(DNS_MSG_SIZE)]; diff --git a/app/modules/node.c b/app/modules/node.c index db33dc25c2..7a01bac112 100644 --- a/app/modules/node.c +++ b/app/modules/node.c @@ -771,7 +771,7 @@ LROT_BEGIN(node) LROT_FUNCENTRY( dsleepMax, dsleepMax ) LROT_FUNCENTRY( sleep, node_sleep ) #ifdef PMSLEEP_ENABLE - PMSLEEP_INT_MAP, + PMSLEEP_INT_MAP #endif #ifdef DEVELOPMENT_TOOLS LROT_FUNCENTRY( readrcr, node_readrcr ) diff --git a/app/spiffs/spiffs.c b/app/spiffs/spiffs.c index 794bc1a7e4..bfd47cba5d 100644 --- a/app/spiffs/spiffs.c +++ b/app/spiffs/spiffs.c @@ -28,10 +28,10 @@ static spiffs fs; #define MASK_1MB (0x100000-1) #define ALIGN (0x2000) -static u8_t spiffs_work_buf[LOG_PAGE_SIZE*2]; +static u8_t IRAM_DATA_ATTR spiffs_work_buf[LOG_PAGE_SIZE*2]; static u8_t spiffs_fds[sizeof(spiffs_fd) * SPIFFS_MAX_OPEN_FILES]; #if SPIFFS_CACHE -static u8_t myspiffs_cache[20 + (LOG_PAGE_SIZE+20)*4]; +static u8_t IRAM_DATA_ATTR myspiffs_cache[20 + (LOG_PAGE_SIZE+20)*4]; #endif static s32_t my_spiffs_read(u32_t addr, u32_t size, u8_t *dst) { diff --git a/app/user/user_main.c b/app/user/user_main.c index 9f80fb9b82..57501ddedc 100644 --- a/app/user/user_main.c +++ b/app/user/user_main.c @@ -144,7 +144,7 @@ void user_pre_init(void) { os_printf("system SPI FI size:%u, Flash size: %u\n", fs_size_code, flash_size ); } - pt = os_malloc(i); // We will work on and register a RAM copy of the PT + pt = os_malloc_iram(i); // We will work on and register a copy of the PT in iRAM // Return if anything is amiss; The SDK will halt if the PT hasn't been registered if ( !rcr_pt || !pt || n * sizeof(partition_item_t) != i) { return; diff --git a/ld/nodemcu.ld b/ld/nodemcu.ld index ab08e61a6e..294b260586 100644 --- a/ld/nodemcu.ld +++ b/ld/nodemcu.ld @@ -124,6 +124,7 @@ SECTIONS /* *libwps.a:*(.literal .text) - tested that safe to keep in iROM */ *(.iram.text .iram0.text .iram0.text.*) + *(.iram0.data.*) *(.stub .gnu.warning .gnu.linkonce.literal.* .gnu.linkonce.t.*.literal .gnu.linkonce.t.*) diff --git a/tools/nodemcu-partition.py b/tools/nodemcu-partition.py index 23668082e4..c168729cd0 100755 --- a/tools/nodemcu-partition.py +++ b/tools/nodemcu-partition.py @@ -22,7 +22,8 @@ import os import sys -sys.path.append(os.path.realpath(os.path.dirname(__file__) + '/toolchains/')) +print os.path.dirname(os.path.realpath(__file__)) +sys.path.append(os.path.dirname(os.path.realpath(__file__)) + '/toolchains/') import esptool import io From 45a7187a6c53647d87737ac91dd61beafb96353d Mon Sep 17 00:00:00 2001 From: Martijn van Buul Date: Fri, 17 May 2019 14:13:49 +0200 Subject: [PATCH 18/74] luaOTA updated to include object form timers (#2752) --- lua_examples/luaOTA/ESP-11223344.json | 4 ++++ lua_examples/luaOTA/README.md | 21 +++++++++++++-------- lua_examples/luaOTA/_doTick.lua | 6 +++--- lua_examples/luaOTA/_init.lua | 2 +- lua_examples/luaOTA/_provision.lua | 6 +++--- lua_examples/luaOTA/check.lua | 12 ++++++++---- 6 files changed, 32 insertions(+), 19 deletions(-) create mode 100644 lua_examples/luaOTA/ESP-11223344.json diff --git a/lua_examples/luaOTA/ESP-11223344.json b/lua_examples/luaOTA/ESP-11223344.json new file mode 100644 index 0000000000..0d1667903f --- /dev/null +++ b/lua_examples/luaOTA/ESP-11223344.json @@ -0,0 +1,4 @@ +{ + "files": [ "main.lc", "supporfile.lc", "othercontent.txt" ], + "secret": "supersekrit" +} diff --git a/lua_examples/luaOTA/README.md b/lua_examples/luaOTA/README.md index 1220c66c34..d6c92d3bd0 100644 --- a/lua_examples/luaOTA/README.md +++ b/lua_examples/luaOTA/README.md @@ -31,7 +31,7 @@ call which invokes the `luaOTA` module by a `require "luaOTA.check"` statement. The `config.json` file which provides the minimum configuration parameters to connect to the WiFi and provisioning server, however these can by overridden through the UART by -first doing a `tmr.stop(0)` and then a manual initialisation as described in the +first doing a `abortOTA()` and then a manual initialisation as described in the [init.lua](#initlua) section below. `luaOTA` configures the wifi and connects to the required sid in STA mode using the @@ -90,13 +90,17 @@ require "LuaOTA.check" however if the configuration is incomplete then this can be aborted as manual process by entering the manual command through the UART ```Lua -tmr.stop(0); require "luaOTA.check":_init {ssid ="SOMESID" --[[etc. ]]} +abortOTA(); require "luaOTA.check":_init {ssid ="SOMESID" --[[etc. ]]} ``` where the parameters to the `_init` method are: - `ssid` and `spwd`. The SSID of the Wifi service to connect to, together with its password. - `server` and `port`. The name or IP address and port of the provisioning server. +- `app`. The filename of the module which will be `required` after provisioning is +complete. Defaults to LuaOTA/default. +- `entry`. The method that will be called on the module indicated by `app`. Defaults +to `init` - `secret`. A site-specific secret shared with the provisioning server for MD5-based signing of the protocol messages. - `leave`. If true the STA service is left connected otherwise the wifi is shutdown @@ -129,6 +133,12 @@ Note that even though this file is included in the `luaOTA` subdirectory within examples, this is designed to run on the host and should not be included in the ESP SPIFFS. +The example server expects a repository directory, which is expected to contain +the to-be-provisioned files (.lua files, .lc files...). Additionally, it expects +a .json file for every ESP that is to be provisioned, containing the "secret" +as well as the relevant filenames. This file should be called 'ESP-xxxxxxxx.json', +with 'xxxxxxxx' replaced with the ChipID. + ## Implementation Notes - The NodeMCu build must include the following modules: `wifi`, `net`, `file`, `tmr`, @@ -156,11 +166,6 @@ called using the object form self:someFunc() to get the context as a parameter. - This coding also makes a lot of use of tailcalls (See PiL 6.3) to keep the stack size to a minimum. -- The update process uses a master timer in `tmr` slot 0. The index form is used here -in preference to the object form because of the reduced memory footprint. This also -allows the developer to abort the process early in the boot sequence by issuing a -`tmr.stop(0)` through UART0. - - The command protocol is unencrypted and uses JSON encoding, but all exchanges are signed by a 6 char signature taken extracted from a MD5 based digest across the JSON string. Any command which fails the signature causes the update to be aborted. Commands @@ -205,7 +210,7 @@ function using an object constructor `self:self:somefunction()`, but where the f can have a self argument then the alternative is to use an upvalue binding. See the `tmr` alarm call at the end of `_init.lua` as an example: ```Lua - tmr.alarm(0, 500, tmr.ALARM_AUTO, self:_doTick()) + self.timer:alarm( 500, tmr.ALARM_AUTO, self:_doTick()) ``` - The `self:_doTick()` is evaluated before the alarm API call. This autoloads `luaOTA/_doTick.lc` which stores `self` as a local and returns a function which takes diff --git a/lua_examples/luaOTA/_doTick.lua b/lua_examples/luaOTA/_doTick.lua index 8b989742e3..e8a7238f8c 100644 --- a/lua_examples/luaOTA/_doTick.lua +++ b/lua_examples/luaOTA/_doTick.lua @@ -1,4 +1,4 @@ -tmr.stop(0)--SAFETRIM +if (self.timer) then self.timer:stop() end--SAFETRIM -- function _doTick(self) -- Upvals @@ -32,7 +32,7 @@ tmr.stop(0)--SAFETRIM -- some resources that are no longer needed and set backstop timer for general -- timeout. This also dereferences the previous doTick cb so it can now be GCed. collectgarbage() - tmr.alarm(0, 30000, tmr.ALARM_SINGLE, self.startApp) + self.timer:alarm(0, 30000, tmr.ALARM_SINGLE, self.startApp) return self:_provision(socket,rec) end @@ -67,7 +67,7 @@ tmr.stop(0)--SAFETRIM return self.startApp("OK: Timeout on waiting for wifi station setup") elseif (tick_count == 26) then -- wait up to 2.5 secs for TCP response - tmr.unregister(0) + self.timer:unregister() pcall(conn.close, conn) self.socket=nil return startApp("OK: Timeout on waiting for provision service response") diff --git a/lua_examples/luaOTA/_init.lua b/lua_examples/luaOTA/_init.lua index eed3cf84c0..c9e11c89cd 100644 --- a/lua_examples/luaOTA/_init.lua +++ b/lua_examples/luaOTA/_init.lua @@ -45,5 +45,5 @@ package.loaded[self.modname] = nil self.modname=nil - tmr.alarm(0, 500, tmr.ALARM_AUTO, self:_doTick()) + self.timer:alarm( 500, tmr.ALARM_AUTO, self:_doTick()) -- end diff --git a/lua_examples/luaOTA/_provision.lua b/lua_examples/luaOTA/_provision.lua index dfb3d6dacd..3b69fcae38 100644 --- a/lua_examples/luaOTA/_provision.lua +++ b/lua_examples/luaOTA/_provision.lua @@ -17,7 +17,7 @@ local function receiveRec(socket, rec) -- upval: self, buf, crypto -- Note that for 2nd and subsequent responses, we assme that the service has -- "authenticated" itself, so any protocol errors are fatal and lkely to -- cause a repeating boot, throw any protocol errors are thrown. - local buf, config, file, log = buf, self.config, file, self.log + local config, file, log = self.config, file, self.log local cmdlen = (rec:find('\n',1, true) or 0) - 1 local cmd,hash = rec:sub(1,cmdlen-6), rec:sub(cmdlen-5,cmdlen) if cmdlen < 16 or @@ -89,9 +89,9 @@ local function receiveRec(socket, rec) -- upval: self, buf, crypto end if s then - print("Updated ".. name) + print("Updated ".. cmd.name) else - file.remove(name) + file.remove(cmd.name) resp.s = "write failed" end buf = {} diff --git a/lua_examples/luaOTA/check.lua b/lua_examples/luaOTA/check.lua index bb740f1798..46dcd27310 100644 --- a/lua_examples/luaOTA/check.lua +++ b/lua_examples/luaOTA/check.lua @@ -9,8 +9,8 @@ -------------------------------------------------------------------------------- -- upvals -local crypto, file, json, net, node, table, tmr, wifi = - crypto, file, sjson, net, node, table, tmr, wifi +local crypto, file, json, net, node, table, wifi = + crypto, file, sjson, net, node, table, wifi local error, pcall = error, pcall local loadfile, gc = loadfile, collectgarbage local concat, unpack = table.concat, unpack or table.unpack @@ -19,7 +19,11 @@ local self = {post = node.task.post, prefix = "luaOTA/", conf = {}} self.log = (DEBUG == true) and print or function() end self.modname = ... +self.timer = tmr.create() +_G["stopOTA"] = function() + self.timer:stop() +end -------------------------------------------------------------------------------------- -- Utility Functions @@ -40,9 +44,9 @@ function self.sign(arg) --upval: crypto, json, self return arg .. crypto.toHex(crypto.hmac("MD5", arg, self.secret):sub(-3)) .. '\n' end -function self.startApp(arg) --upval: gc, self, tmr, wifi +function self.startApp(arg) --upval: gc, self, wifi gc();gc() - tmr.unregister(0) + self.timer.unregister() self.socket = nil if not self.config.leave then wifi.setmode(wifi.NULLMODE,false) end local appMod = self.config.app or "luaOTA.default" From d6980ad802d58ecc083f953bfc83d5b6ec226c18 Mon Sep 17 00:00:00 2001 From: Terry Ellison Date: Sun, 19 May 2019 14:38:23 +0100 Subject: [PATCH 19/74] SDK 3.0 tranche3 (#2761) Force libpp.a into iRAM, and backout redundant IRAM_DATA_ATTR changes --- app/esp-gdbstub/gdbstub.c | 2 +- app/include/user_config.h | 9 +-------- app/lua/lauxlib.c | 10 ++-------- app/lua/lrotable.c | 7 +------ app/lwip/core/dns.c | 2 +- app/modules/file.c | 8 ++++++++ app/platform/platform.c | 1 - app/spiffs/spiffs.c | 41 +++++++++++++-------------------------- app/user/user_main.c | 18 ++++------------- ld/nodemcu.ld | 34 +++++++++++++------------------- 10 files changed, 46 insertions(+), 86 deletions(-) diff --git a/app/esp-gdbstub/gdbstub.c b/app/esp-gdbstub/gdbstub.c index 9849b5c43e..509e9bb403 100644 --- a/app/esp-gdbstub/gdbstub.c +++ b/app/esp-gdbstub/gdbstub.c @@ -107,7 +107,7 @@ extern void xthal_set_intenable(int); #define OBUFLEN 32 //The asm stub saves the Xtensa registers here when a debugging exception happens. -struct XTensa_exception_frame_s IRAM_DATA_ATTR gdbstub_savedRegs; +struct XTensa_exception_frame_s gdbstub_savedRegs; #if GDBSTUB_USE_OWN_STACK //This is the debugging exception stack. int exceptionStack[256]; diff --git a/app/include/user_config.h b/app/include/user_config.h index 64870bb239..e87adbc7f4 100644 --- a/app/include/user_config.h +++ b/app/include/user_config.h @@ -273,14 +273,7 @@ extern void luaL_dbgbreak(void); #define ICACHE_STORE_ATTR __attribute__((aligned(4))) #define ICACHE_STRING(x) ICACHE_STRING2(x) #define ICACHE_STRING2(x) #x -#define ICACHE_RAM_ATTR \ - __attribute__((section(".iram0.text." __FILE__ "." ICACHE_STRING(__LINE__)))) -#define ICACHE_FLASH_RESERVED_ATTR \ - __attribute__((section(".irom.reserved." __FILE__ "." ICACHE_STRING(__LINE__)),\ - used,unused,aligned(INTERNAL_FLASH_SECTOR_SIZE))) -#define IRAM_DATA_ATTR \ - __attribute__((section(".iram0.data." __FILE__ "." ICACHE_STRING(__LINE__)))) - +#define ICACHE_RAM_ATTR __attribute__((section(".iram0.text." __FILE__ "." ICACHE_STRING(__LINE__)))) #ifdef GPIO_SAFE_NO_INTR_ENABLE #define NO_INTR_CODE ICACHE_RAM_ATTR __attribute__ ((noinline)) #else diff --git a/app/lua/lauxlib.c b/app/lua/lauxlib.c index 514b75e361..de2ae48978 100644 --- a/app/lua/lauxlib.c +++ b/app/lua/lauxlib.c @@ -918,11 +918,6 @@ static int l_check_memlimit(lua_State *L, size_t needbytes) { return (g->totalbytes >= limit) ? 1 : 0; } -#ifndef LUA_CROSS_COMPILER -#define REALLOC(p,o,n) (void *) this_realloc(p,o,n) -#else -#define REALLOC(p,o,n) (void *) (ptr? this_realloc(p,o,n) : c_malloc(n)) -#endif static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) { lua_State *L = (lua_State *)ud; @@ -951,11 +946,10 @@ static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) { if(G(L)->memlimit > 0 && (mode & EGC_ON_MEM_LIMIT) && l_check_memlimit(L, nsize - osize)) return NULL; } - nptr = REALLOC(ptr, osize, nsize); + nptr = (void *)this_realloc(ptr, osize, nsize); if (nptr == NULL && L != NULL && (mode & EGC_ON_ALLOC_FAILURE)) { - dbg_printf("Emergency full collection\n"); /**** DEBUG ***/ luaC_fullgc(L); /* emergency full collection. */ - nptr = REALLOC(ptr, osize, nsize); /* try allocation again */ + nptr = (void *)this_realloc(ptr, osize, nsize); /* try allocation again */ } return nptr; } diff --git a/app/lua/lrotable.c b/app/lua/lrotable.c index d4290ae150..5a73ef75fa 100644 --- a/app/lua/lrotable.c +++ b/app/lua/lrotable.c @@ -15,11 +15,6 @@ #define ALIGNED_STRING (__attribute__((aligned(4))) char *) #endif -#ifdef LUA_CROSS_COMPILER -#undef IRAM_DATA_ATTR -#define IRAM_DATA_ATTR -#endif - #define LA_LINES 32 #define LA_SLOTS 4 //#define COLLECT_STATS @@ -50,7 +45,7 @@ typedef struct { unsigned ndx:8; } cache_line_t; -static cache_line_t IRAM_DATA_ATTR cache[LA_LINES][LA_SLOTS]; +static cache_line_t cache [LA_LINES][LA_SLOTS]; #ifdef COLLECT_STATS unsigned cache_stats[3]; diff --git a/app/lwip/core/dns.c b/app/lwip/core/dns.c index 9a77575dbf..90ea11240f 100644 --- a/app/lwip/core/dns.c +++ b/app/lwip/core/dns.c @@ -222,7 +222,7 @@ static void dns_check_entries(void); /* DNS variables */ static struct udp_pcb *dns_pcb; static u8_t dns_seqno; -static struct dns_table_entry IRAM_DATA_ATTR dns_table[DNS_TABLE_SIZE]; +static struct dns_table_entry dns_table[DNS_TABLE_SIZE]; static ip_addr_t dns_servers[DNS_MAX_SERVERS]; /** Contiguous buffer for processing responses */ //static u8_t dns_payload_buffer[LWIP_MEM_ALIGN_BUFFER(DNS_MSG_SIZE)]; diff --git a/app/modules/file.c b/app/modules/file.c index 7ca15aa2f9..4ed4f37c98 100644 --- a/app/modules/file.c +++ b/app/modules/file.c @@ -703,6 +703,14 @@ LROT_END( file, NULL, 0 ) int luaopen_file( lua_State *L ) { + if (!vfs_mount("/FLASH", 0)) { + // Failed to mount -- try reformat + dbg_printf("Formatting file system. Please wait...\n"); + if (!vfs_format()) { + NODE_ERR( "\n*** ERROR ***: unable to format. FS might be compromised.\n" ); + NODE_ERR( "It is advised to re-flash the NodeMCU image.\n" ); + } + } luaL_rometatable( L, "file.vol", LROT_TABLEREF(file_vol)); luaL_rometatable( L, "file.obj", LROT_TABLEREF(file_obj)); return 0; diff --git a/app/platform/platform.c b/app/platform/platform.c index cec211f59e..4ad94dade8 100644 --- a/app/platform/platform.c +++ b/app/platform/platform.c @@ -923,7 +923,6 @@ uint32_t platform_s_flash_read( void *to, uint32_t fromaddr, uint32_t size ) int platform_flash_erase_sector( uint32_t sector_id ) { NODE_DBG( "flash_erase_sector(%u)\n", sector_id); - system_soft_wdt_feed (); return flash_erase( sector_id ) == SPI_FLASH_RESULT_OK ? PLATFORM_OK : PLATFORM_ERR; } diff --git a/app/spiffs/spiffs.c b/app/spiffs/spiffs.c index bfd47cba5d..1809b0f361 100644 --- a/app/spiffs/spiffs.c +++ b/app/spiffs/spiffs.c @@ -28,10 +28,10 @@ static spiffs fs; #define MASK_1MB (0x100000-1) #define ALIGN (0x2000) -static u8_t IRAM_DATA_ATTR spiffs_work_buf[LOG_PAGE_SIZE*2]; +static u8_t spiffs_work_buf[LOG_PAGE_SIZE*2]; static u8_t spiffs_fds[sizeof(spiffs_fd) * SPIFFS_MAX_OPEN_FILES]; #if SPIFFS_CACHE -static u8_t IRAM_DATA_ATTR myspiffs_cache[20 + (LOG_PAGE_SIZE+20)*4]; +static u8_t myspiffs_cache[20 + (LOG_PAGE_SIZE+20)*4]; #endif static s32_t my_spiffs_read(u32_t addr, u32_t size, u8_t *dst) { @@ -44,12 +44,18 @@ static s32_t my_spiffs_write(u32_t addr, u32_t size, u8_t *src) { return SPIFFS_OK; } +static int erase_cnt = -1; // If set to >=0 then erasing gives a ... feedback static s32_t my_spiffs_erase(u32_t addr, u32_t size) { u32_t sect_first = platform_flash_get_sector_of_address(addr); u32_t sect_last = sect_first; - while( sect_first <= sect_last ) - if( platform_flash_erase_sector( sect_first ++ ) == PLATFORM_ERR ) + while( sect_first <= sect_last ) { + if (erase_cnt >= 0 && (erase_cnt++ & 0xF) == 0) { + dbg_printf("."); + } + if( platform_flash_erase_sector( sect_first ++ ) == PLATFORM_ERR ) { return SPIFFS_ERR_INTERNAL; + } + } return SPIFFS_OK; } @@ -152,31 +158,12 @@ int myspiffs_format( void ) SPIFFS_unmount(&fs); NODE_DBG("Formatting: size 0x%x, addr 0x%x\n", fs.cfg.phys_size, fs.cfg.phys_addr); + erase_cnt = 0; + int status = SPIFFS_format(&fs); + erase_cnt = -1; - if (SPIFFS_format(&fs) < 0) { - return 0; - } - - return myspiffs_mount(FALSE); -} - -#if 0 -void test_spiffs() { - char buf[12]; - - // Surely, I've mounted spiffs before entering here - - spiffs_file fd = SPIFFS_open(&fs, "my_file", SPIFFS_CREAT | SPIFFS_TRUNC | SPIFFS_RDWR, 0); - if (SPIFFS_write(&fs, fd, (u8_t *)"Hello world", 12) < 0) NODE_DBG("errno %i\n", SPIFFS_errno(&fs)); - SPIFFS_close(&fs, fd); - - fd = SPIFFS_open(&fs, "my_file", SPIFFS_RDWR, 0); - if (SPIFFS_read(&fs, fd, (u8_t *)buf, 12) < 0) NODE_DBG("errno %i\n", SPIFFS_errno(&fs)); - SPIFFS_close(&fs, fd); - - NODE_DBG("--> %s <--\n", buf); + return status < 0 ? 0 : myspiffs_mount(FALSE); } -#endif // *************************************************************************** diff --git a/app/user/user_main.c b/app/user/user_main.c index 57501ddedc..008e384b3a 100644 --- a/app/user/user_main.c +++ b/app/user/user_main.c @@ -92,6 +92,7 @@ static const struct defaultpt rompt IROM_PTABLE_ATTR USED_ATTR = { static uint32_t first_time_setup(partition_item_t *pt, uint32_t n, uint32_t flash_size); static void phy_data_setup (partition_item_t *pt, uint32_t n); +extern void _ResetHandler(void); /* * The non-OS SDK prolog has been fundamentally revised in V3. See SDK EN document @@ -166,7 +167,7 @@ void user_pre_init(void) { return; } os_printf("Invalid system partition table\n"); - while(1); // Trigger WDT} + while (1) {}; } /* @@ -266,7 +267,8 @@ static uint32_t first_time_setup(partition_item_t *pt, uint32_t n, uint32_t flas } platform_rcr_write(PLATFORM_RCR_PT, pt, newn*sizeof(partition_item_t)); - while(1); // Trigger WDT; the new PT will be loaded on reboot + ets_delay_us(5000); + _ResetHandler(); // Trigger reset; the new PT will be loaded on reboot } uint32 ICACHE_RAM_ATTR user_iram_memory_is_enabled(void) { @@ -305,18 +307,6 @@ void nodemcu_init(void) { NODE_DBG("Can not init platform for modules.\n"); return; } - -#ifdef BUILD_SPIFFS - if (!vfs_mount("/FLASH", 0)) { - // Failed to mount -- try reformat - dbg_printf("Formatting file system. Please wait...\n"); - if (!vfs_format()) { - NODE_ERR( "\n*** ERROR ***: unable to format. FS might be compromised.\n" ); - NODE_ERR( "It is advised to re-flash the NodeMCU image.\n" ); - } - } -#endif - if (!task_post_low(task_get_id(start_lua),'s')) NODE_ERR("Failed to post the start_lua task!\n"); } diff --git a/ld/nodemcu.ld b/ld/nodemcu.ld index 294b260586..2f5ffbcc7f 100644 --- a/ld/nodemcu.ld +++ b/ld/nodemcu.ld @@ -104,25 +104,20 @@ SECTIONS *(.entry.text) *(.init.literal) *(.init) - - /* SDK libraries that used in bootup process, interruption handling - * and other ways where flash cache (iROM) is unavailable: */ - *libmain.a:*(.literal .literal.* .text .text.*) - *libnet80211.a:*(.literal .text) - *libphy.a:*(.literal .text) - *libpp.a:*(.literal .text) - *libgcc.a:*(.literal .text) - - /* Following SDK libraries have .text sections, but not included in iRAM: */ - /* *libat.a:*(.literal .text) - not used anywhere in NodeMCU */ - /* *libcrypto.a:*(.literal .text) - tested that safe to keep in iROM */ - /* *libdriver.a:*(.literal .text) - not used anywhere in NodeMCU */ - /* *libespnow.a:*(.literal .text) - not used anywhere in NodeMCU */ - /* *liblwip_536.a:*(.literal .text) - source-based library used instead */ - /* *libpwm.a:*(.literal .text) - our own implementation used instead */ - /* *libwpa.a:*(.literal .text) - tested that safe to keep in iROM */ - /* *libwps.a:*(.literal .text) - tested that safe to keep in iROM */ - + /* + * SDK libraries that used in bootup process, interruption handling + * and other ways where flash cache (iROM) is unavailable: + */ + *libmain.a:*( .literal .literal.* .text .text.*) + *libphy.a:*( .literal .literal.* .text .text.*) + *libpp.a:*( .literal .literal.* .text .text.*) + *libgcc.a:*( .literal .literal.* .text .text.*) + /* + * The following SDK libraries have .literal and .text sections, but are + * either not used in NodeMCU or are safe to execute out of in iROM: + * libat.a libcrypto.a libdriver.a libnet80211.a libespnow.a + * liblwip_536.a ibpwm.a libwpa.a ibwps.a + */ *(.iram.text .iram0.text .iram0.text.*) *(.iram0.data.*) @@ -260,7 +255,6 @@ SECTIONS /* Reserved areas, flash page aligned and last */ . = ALIGN(4096); - KEEP(*(.irom.reserved .irom.reserved.*)) _irom0_text_end = ABSOLUTE(.); _flash_used_end = ABSOLUTE(.); From a62db23626ea2f98d3bc3ce6506ce8cbb14c09b1 Mon Sep 17 00:00:00 2001 From: Terry Ellison Date: Mon, 20 May 2019 10:13:14 +0100 Subject: [PATCH 20/74] Fix nodemcu.ld (#2762) --- ld/nodemcu.ld | 1 + 1 file changed, 1 insertion(+) diff --git a/ld/nodemcu.ld b/ld/nodemcu.ld index 2f5ffbcc7f..5f8ca7058f 100644 --- a/ld/nodemcu.ld +++ b/ld/nodemcu.ld @@ -112,6 +112,7 @@ SECTIONS *libphy.a:*( .literal .literal.* .text .text.*) *libpp.a:*( .literal .literal.* .text .text.*) *libgcc.a:*( .literal .literal.* .text .text.*) + *libnet80211.a:*(.literal .text ) /* * The following SDK libraries have .literal and .text sections, but are * either not used in NodeMCU or are safe to execute out of in iROM: From 036bff566524a5d168f2e081618c914dc6757fcc Mon Sep 17 00:00:00 2001 From: Terry Ellison Date: Mon, 20 May 2019 15:05:52 +0100 Subject: [PATCH 21/74] Use dynamic memory for cached DNS names (#2763) Fixes #2511 --- app/lwip/core/dns.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/lwip/core/dns.c b/app/lwip/core/dns.c index 90ea11240f..43691ecc45 100644 --- a/app/lwip/core/dns.c +++ b/app/lwip/core/dns.c @@ -177,7 +177,7 @@ struct dns_table_entry { u8_t seqno; u8_t err; u32_t ttl; - char name[DNS_MAX_NAME_LENGTH]; + char *name; ip_addr_t ipaddr; /* pointer to callback on DNS query done */ dns_found_callback found; @@ -924,11 +924,14 @@ dns_enqueue(const char *name, dns_found_callback found, void *callback_arg) LWIP_DEBUGF(DNS_DEBUG, ("dns_enqueue: \"%s\": use DNS entry %"U16_F"\n", name, (u16_t)(i))); /* fill the entry */ + namelen = LWIP_MIN(os_strlen(name), DNS_MAX_NAME_LENGTH-1); + if ((pEntry->name = (char *) mem_realloc(pEntry->name, namelen+1)) == NULL) { + return ERR_MEM; + } pEntry->state = DNS_STATE_NEW; pEntry->seqno = dns_seqno++; pEntry->found = found; pEntry->arg = callback_arg; - namelen = LWIP_MIN(os_strlen(name), DNS_MAX_NAME_LENGTH-1); MEMCPY(pEntry->name, name, namelen); pEntry->name[namelen] = 0; From bc1dd37aee09856e45d105d2c820cc1dc12fb0e9 Mon Sep 17 00:00:00 2001 From: Alistair Witt Date: Wed, 22 May 2019 22:03:06 +1000 Subject: [PATCH 22/74] Replaced obsolete static timers in lfs_fragments.lua (nodemcu #2764) --- lua_examples/lfs/lfs_fragments.lua | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lua_examples/lfs/lfs_fragments.lua b/lua_examples/lfs/lfs_fragments.lua index 556585e6ae..c5e53e06e4 100644 --- a/lua_examples/lfs/lfs_fragments.lua +++ b/lua_examples/lfs/lfs_fragments.lua @@ -56,8 +56,11 @@ if node.flashindex() == nil then node.flashreload('flash.img') end -tmr.alarm(0, 1000, tmr.ALARM_SINGLE, - function() - local fi=node.flashindex; return pcall(fi and fi'_init') - end) +local initTimer = tmr.create() +initTimer:register(1000, tmr.ALARM_SINGLE, + function() + local fi=node.flashindex; return pcall(fi and fi'_init') + end + ) +initTimer:start() From 5f43a414e756e778f57fce240ad4ab6ce17d7013 Mon Sep 17 00:00:00 2001 From: Nikolay Fiykov Date: Sat, 25 May 2019 23:08:13 +0300 Subject: [PATCH 23/74] Add pwm2 module (#2747) --- .gitignore | 1 + app/driver/pwm2.c | 251 ++++++++++++++++++++++++++++++ app/include/driver/pwm2.h | 65 ++++++++ app/include/user_modules.h | 1 + app/modules/pwm2.c | 145 +++++++++++++++++ app/platform/hw_timer.c | 125 ++++++++++++++- app/platform/hw_timer.h | 8 + docs/modules/pwm2.md | 309 +++++++++++++++++++++++++++++++++++++ mkdocs.yml | 1 + 9 files changed, 899 insertions(+), 7 deletions(-) create mode 100644 app/driver/pwm2.c create mode 100644 app/include/driver/pwm2.h create mode 100644 app/modules/pwm2.c create mode 100644 docs/modules/pwm2.md diff --git a/.gitignore b/.gitignore index ddf3c2d233..abca1f1738 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ tools/toolchains/ .cproject .project .settings/ +.vscode diff --git a/app/driver/pwm2.c b/app/driver/pwm2.c new file mode 100644 index 0000000000..ad41307c90 --- /dev/null +++ b/app/driver/pwm2.c @@ -0,0 +1,251 @@ +/* + * Software PWM using soft-interrupt timer1. + * Supports higher frequencies compared to Espressif provided one. + * + * Nikolay Fiykov + */ + +#include +#include "c_types.h" +#include "mem.h" +#include "pin_map.h" +#include "platform.h" +#include "hw_timer.h" +#include "driver/pwm2.h" + +#define PWM2_TMR_MAGIC_80MHZ 16 +#define PWM2_TMR_MAGIC_160MHZ 32 + +// module vars, lazy initialized, allocated only if pwm2 is being used + +static pwm2_module_data_t *moduleData = NULL; + +//############################ +// tools + +static bool isPinSetup(const pwm2_module_data_t *data, const uint8_t pin) { + return data->setupData.pin[pin].pulseResolutions > 0; +} + +static uint32_t getCPUTicksPerSec() { + return system_get_cpu_freq() * 1000000; +} + +static uint8_t getCpuTimerTicksDivisor() { + return system_get_cpu_freq() == 80 ? PWM2_TMR_MAGIC_80MHZ : PWM2_TMR_MAGIC_160MHZ; +} + +static uint32_t findGCD(uint32_t n1, uint32_t n2) { + uint32_t n3; + while (n2 != 0) { + n3 = n1; + n1 = n2; + n2 = n3 % n2; + } + return n1; +} + +static uint32_t findGreatesCommonDividerForTimerTicks(uint32_t newTimerTicks, uint32_t oldTimerTicks) { + return oldTimerTicks == 0 ? newTimerTicks : findGCD(newTimerTicks, oldTimerTicks); +} + +static uint16_t findAllEnabledGpioMask(pwm2_module_data_t *moduleData) { + uint16_t enableGpioMask = 0; + for (int i = 1; i < GPIO_PIN_NUM; i++) { + if (moduleData->setupData.pin[i].pulseResolutions > 0) { + enableGpioMask |= moduleData->interruptData.pin[i].gpioMask; + } + } + return enableGpioMask; +} + +static uint32_t findCommonCPUTicksDivisor(pwm2_module_data_t *moduleData) { + uint32_t gcdCPUTicks = 0; + for (int i = 1; i < GPIO_PIN_NUM; i++) { + if (moduleData->setupData.pin[i].pulseResolutions > 0) { + gcdCPUTicks = findGreatesCommonDividerForTimerTicks(moduleData->setupData.pin[i].resolutionCPUTicks, gcdCPUTicks); + } + } + return gcdCPUTicks; +} + +static uint32_t cpuToTimerTicks(uint32_t cpuTicks) { + return cpuTicks / getCpuTimerTicksDivisor(); +} + +static void updatePinResolutionToInterruptsMultiplier(pwm2_pin_setup_t *sPin, uint32_t timerCPUTicks) { + sPin->resolutionInterruptCounterMultiplier = sPin->resolutionCPUTicks / timerCPUTicks; +} + +static void updatePinPulseToInterruptsCounter(pwm2_pin_interrupt_t *iPin, pwm2_pin_setup_t *sPin) { + iPin->pulseInterruptCcounter = (sPin->pulseResolutions + 1) * sPin->resolutionInterruptCounterMultiplier; +} + +static uint8_t getDutyAdjustment(const uint32_t duty, const uint32_t pulse) { + if (duty == 0) { + return 0; + } else if (duty == pulse) { + return 2; + } else { + return 1; + } +} + +static void updatePinOffCounter(pwm2_pin_interrupt_t *iPin, pwm2_pin_setup_t *sPin) { + iPin->offInterruptCounter = (sPin->duty + getDutyAdjustment(sPin->duty, sPin->pulseResolutions)) * sPin->resolutionInterruptCounterMultiplier; +} + +static void reCalculateCommonToAllPinsData(pwm2_module_data_t *moduleData) { + moduleData->interruptData.enabledGpioMask = findAllEnabledGpioMask(moduleData); + moduleData->setupData.interruptTimerCPUTicks = findCommonCPUTicksDivisor(moduleData); + moduleData->setupData.interruptTimerTicks = cpuToTimerTicks(moduleData->setupData.interruptTimerCPUTicks); + for (int i = 1; i < GPIO_PIN_NUM; i++) { + if (isPinSetup(moduleData, i)) { + updatePinResolutionToInterruptsMultiplier(&moduleData->setupData.pin[i], moduleData->setupData.interruptTimerCPUTicks); + updatePinPulseToInterruptsCounter(&moduleData->interruptData.pin[i], &moduleData->setupData.pin[i]); + updatePinOffCounter(&moduleData->interruptData.pin[i], &moduleData->setupData.pin[i]); + } + } +} + +static uint64_t enduserFreqToCPUTicks(const uint64_t divisableFreq, const uint64_t freqDivisor, const uint64_t resolution) { + return (getCPUTicksPerSec() / (freqDivisor * resolution)) * divisableFreq; +} + +static uint16_t getPinGpioMask(uint8_t pin) { + return 1 << GPIO_ID_PIN(pin_num[pin]); +} + +static void set_duty(pwm2_module_data_t *moduleData, const uint8_t pin, const uint32_t duty) { + pwm2_pin_setup_t *sPin = &moduleData->setupData.pin[pin]; + pwm2_pin_interrupt_t *iPin = &moduleData->interruptData.pin[pin]; + sPin->duty = duty; + updatePinOffCounter(iPin, sPin); +} + +static void configureAllPinsAsGpioOutput(pwm2_module_data_t *moduleData) { + for (int i = 1; i < GPIO_PIN_NUM; i++) { + if (isPinSetup(moduleData, i)) { + PIN_FUNC_SELECT(pin_mux[i], pin_func[i]); // set pin as gpio + PIN_PULLUP_EN(pin_mux[i]); // set pin pullup on + } + } +} + +static void resetPinCounters(pwm2_module_data_t *moduleData) { + for (int i = 1; i < GPIO_PIN_NUM; i++) { + if (isPinSetup(moduleData, i)) { + moduleData->interruptData.pin[i].currentInterruptCounter = 0; + } + } +} + +//############################ +// interrupt handler related + +static inline void computeIsPinOn(pwm2_pin_interrupt_t *pin, uint16_t *maskOn) { + if (pin->currentInterruptCounter == pin->pulseInterruptCcounter) { + pin->currentInterruptCounter = 1; + } else { + pin->currentInterruptCounter++; + } + // ets_printf("curr=%u on=%u\n", pin->currentInterruptCounter, (pin->currentInterruptCounter < pin->offInterruptCounter)); + if (pin->currentInterruptCounter < pin->offInterruptCounter) { + *maskOn |= pin->gpioMask; + } +} + +static inline bool isPinSetup2(const pwm2_interrupt_handler_data_t *data, const uint8_t pin) { + return data->pin[pin].gpioMask > 0; +} + +static inline uint16_t findAllPinOns(pwm2_interrupt_handler_data_t *data) { + uint16_t maskOn = 0; + for (int i = 1; i < GPIO_PIN_NUM; i++) { + if (isPinSetup2(data, i)) { + computeIsPinOn(&data->pin[i], &maskOn); + } + } + return maskOn; +} + +static inline void setGpioPins(const uint16_t enabledGpioMask, const register uint16_t maskOn) { + GPIO_REG_WRITE(GPIO_OUT_W1TS_ADDRESS, maskOn); + const register uint16_t maskOff = ~maskOn & enabledGpioMask; + GPIO_REG_WRITE(GPIO_OUT_W1TC_ADDRESS, maskOff); +} + +static void ICACHE_RAM_ATTR timerInterruptHandler(os_param_t arg) { + pwm2_interrupt_handler_data_t *data = (pwm2_interrupt_handler_data_t *)arg; + setGpioPins(data->enabledGpioMask, findAllPinOns(data)); +} + +//############################ +// driver's public API + +void pwm2_init() { + moduleData = os_malloc(sizeof(pwm2_module_data_t)); + memset(moduleData, 0, sizeof(*moduleData)); +} + +pwm2_module_data_t *pwm2_get_module_data() { + return moduleData; +} + +bool pwm2_is_pin_setup(const uint8_t pin) { + return isPinSetup(moduleData, pin); +} + +void pwm2_setup_pin( + const uint8_t pin, + const uint32_t divisableFreq, + const uint32_t freqDivisor, + const uint32_t resolution, + const uint32_t initDuty + ) +{ + moduleData->setupData.pin[pin].pulseResolutions = resolution; + moduleData->setupData.pin[pin].divisableFrequency = divisableFreq; + moduleData->setupData.pin[pin].frequencyDivisor = freqDivisor; + moduleData->setupData.pin[pin].resolutionCPUTicks = enduserFreqToCPUTicks(divisableFreq, freqDivisor, resolution); + moduleData->interruptData.pin[pin].gpioMask = getPinGpioMask(pin); + reCalculateCommonToAllPinsData(moduleData); + set_duty(moduleData, pin, initDuty); +} + +void pwm2_release_pin(const uint8_t pin) { + moduleData->setupData.pin[pin].pulseResolutions = 0; + moduleData->interruptData.pin[pin].gpioMask = 0; +} + +void pwm2_stop() { + if (!moduleData->setupData.isStarted) { + return; + } + platform_hw_timer_close_exclusive(); + GPIO_REG_WRITE(GPIO_ENABLE_W1TC_ADDRESS, moduleData->interruptData.enabledGpioMask); // clear pins of being gpio output + moduleData->setupData.isStarted = false; +} + +bool pwm2_start() { + if (moduleData->setupData.isStarted) { + return true; + } + if (!platform_hw_timer_init_exclusive(FRC1_SOURCE, TRUE, timerInterruptHandler, (os_param_t)&moduleData->interruptData, (void (*)(void))NULL)) { + return false; + } + configureAllPinsAsGpioOutput(moduleData); + resetPinCounters(moduleData); + GPIO_REG_WRITE(GPIO_ENABLE_W1TS_ADDRESS, moduleData->interruptData.enabledGpioMask); // set pins as gpio output + moduleData->setupData.isStarted = true; + platform_hw_timer_arm_ticks_exclusive(moduleData->setupData.interruptTimerTicks); + return true; +} + +bool pwm2_is_started() { + return moduleData->setupData.isStarted; +} + +void pwm2_set_duty(const uint8_t pin, const uint32_t duty) { + set_duty(moduleData, pin, duty); +} diff --git a/app/include/driver/pwm2.h b/app/include/driver/pwm2.h new file mode 100644 index 0000000000..c0fad44f2a --- /dev/null +++ b/app/include/driver/pwm2.h @@ -0,0 +1,65 @@ +/* + * Software PWM using soft-interrupt timer1. + * Supports higher frequencies compared to Espressif provided one. + * + * Nikolay Fiykov + */ + +#ifndef __PWM2_H__ +#define __PWM2_H__ + +#include "c_types.h" +#include "pin_map.h" + +typedef struct { + uint32_t offInterruptCounter; + uint32_t pulseInterruptCcounter; + uint32_t currentInterruptCounter; + uint16_t gpioMask; +} pwm2_pin_interrupt_t; + +typedef struct { + pwm2_pin_interrupt_t pin[GPIO_PIN_NUM]; + uint16_t enabledGpioMask; +} pwm2_interrupt_handler_data_t; + +typedef struct { + uint32_t pulseResolutions; + uint32_t divisableFrequency; + uint32_t frequencyDivisor; + uint32_t duty; + uint32_t resolutionCPUTicks; + uint32_t resolutionInterruptCounterMultiplier; +} pwm2_pin_setup_t; + +typedef struct { + pwm2_pin_setup_t pin[GPIO_PIN_NUM]; + uint32_t interruptTimerCPUTicks; + uint32_t interruptTimerTicks; + bool isStarted; +} pwm2_setup_data_t; + +typedef struct { + pwm2_interrupt_handler_data_t interruptData; + pwm2_setup_data_t setupData; +} pwm2_module_data_t; + +// driver's public API + +void pwm2_init(); +pwm2_module_data_t *pwm2_get_module_data(); +bool pwm2_is_pin_setup(const uint8_t pin); +void pwm2_setup_pin( + const uint8_t pin, + const uint32_t divisableFreq, + const uint32_t freqDivisor, + const uint32_t resolution, + const uint32_t initDuty + ); +void pwm2_release_pin(const uint8_t pin); +void pwm2_stop(); +bool pwm2_start(); +bool pwm2_is_started(); +void pwm2_set_duty(const uint8_t pin, const uint32_t duty); + +#endif diff --git a/app/include/user_modules.h b/app/include/user_modules.h index 2818ed7f16..ecb2f4461f 100644 --- a/app/include/user_modules.h +++ b/app/include/user_modules.h @@ -43,6 +43,7 @@ //#define LUA_USE_MODULES_PCM //#define LUA_USE_MODULES_PERF //#define LUA_USE_MODULES_PWM +//#define LUA_USE_MODULES_PWM2 //#define LUA_USE_MODULES_RC //#define LUA_USE_MODULES_RFSWITCH //#define LUA_USE_MODULES_ROTARY diff --git a/app/modules/pwm2.c b/app/modules/pwm2.c new file mode 100644 index 0000000000..027b4019ff --- /dev/null +++ b/app/modules/pwm2.c @@ -0,0 +1,145 @@ +/* + * Software PWM using soft-interrupt timer1. + * Supports higher frequencies compared to Espressif provided one. + * + * Nikolay Fiykov + */ + +// Module for interfacing with PWM2 driver + +#include "c_types.h" +#include "lauxlib.h" +#include "module.h" +#include "driver/pwm2.h" + +#define luaL_argcheck2(L, cond, numarg, extramsg) \ + if (!(cond)) return luaL_argerror(L, (numarg), (extramsg)) + +//############################ +// lua bindings + +static int lpwm2_open(lua_State *L) { + pwm2_init(); + return 0; +} + +static int lpwm2_get_timer_data(lua_State *L) { + lua_pushboolean(L, pwm2_get_module_data()->setupData.isStarted); + lua_pushinteger(L, pwm2_get_module_data()->setupData.interruptTimerCPUTicks); + lua_pushinteger(L, pwm2_get_module_data()->setupData.interruptTimerTicks); + return 3; +} + +static int lpwm2_get_pin_data(lua_State *L) { + const uint8 pin = luaL_checkinteger(L, 1); + luaL_argcheck2(L, pin > 0 && pin <= GPIO_PIN_NUM, 1, "invalid pin number"); + lua_pushinteger(L, pwm2_is_pin_setup(pin)); + lua_pushinteger(L, pwm2_get_module_data()->setupData.pin[pin].duty); + lua_pushinteger(L, pwm2_get_module_data()->setupData.pin[pin].pulseResolutions); + lua_pushinteger(L, pwm2_get_module_data()->setupData.pin[pin].divisableFrequency); + lua_pushinteger(L, pwm2_get_module_data()->setupData.pin[pin].frequencyDivisor); + lua_pushinteger(L, pwm2_get_module_data()->setupData.pin[pin].resolutionCPUTicks); + lua_pushinteger(L, pwm2_get_module_data()->setupData.pin[pin].resolutionInterruptCounterMultiplier); + return 7; +} + +static int lpwm2_setup_pin_common(lua_State *L, const bool isFreqHz) { + if (pwm2_is_started()) { + return luaL_error(L, "pwm2 : already started, stop it before setting up pins."); + } + const int pin = lua_tointeger(L, 1); + const int freq = lua_tointeger(L, 2); + const int resolution = lua_tointeger(L, 3); + const int initDuty = lua_tointeger(L, 4); + const int freqFractions = luaL_optinteger(L, 5, 1); + + luaL_argcheck2(L, pin > 0 && pin <= GPIO_PIN_NUM, 1, "invalid pin number"); + luaL_argcheck2(L, freq > 0, 2, "invalid frequency"); + luaL_argcheck2(L, resolution > 0, 3, "invalid frequency resolution"); + luaL_argcheck2(L, initDuty >= 0 && initDuty <= resolution, 4, "invalid duty"); + luaL_argcheck2(L, freqFractions > 0, 5, "invalid frequency fractions"); + + if (isFreqHz) { + pwm2_setup_pin(pin, freqFractions, freq, resolution, initDuty); + } else { + pwm2_setup_pin(pin, freq, freqFractions, resolution, initDuty); + } + return 0; +} + +static int lpwm2_setup_pin_hz(lua_State *L) { + return lpwm2_setup_pin_common(L, true); +} + +static int lpwm2_setup_pin_sec(lua_State *L) { + return lpwm2_setup_pin_common(L, false); +} + +static int lpwm2_set_duty(lua_State *L) { + int pos = 0; + while (true) { + int pin = luaL_optinteger(L, ++pos, -1); + if (pin == -1) { + break; + } + luaL_argcheck2(L, pin > 0 && pin <= GPIO_PIN_NUM, pos, "invalid pin number"); + + int duty = luaL_optinteger(L, ++pos, -1); + luaL_argcheck2(L, duty >= 0 && duty <= pwm2_get_module_data()->setupData.pin[pin].pulseResolutions, pos, "invalid duty"); + + if (!pwm2_is_pin_setup(pin)) { + return luaL_error(L, "pwm2 : pin=%d is not setup yet", pin); + } + pwm2_set_duty(pin, duty); + } + return 0; +} + +static int lpwm2_release_pin(lua_State *L) { + if (pwm2_is_started()) { + return luaL_error(L, "pwm2 : pwm is started, stop it first."); + } + int pos = 0; + while (true) { + int pin = luaL_optinteger(L, ++pos, -1); + if (pin == -1) { + break; + } + luaL_argcheck2(L, pin > 0 && pin <= GPIO_PIN_NUM, pos, "invalid pin number"); + pwm2_release_pin(2); + } + return 0; +} + +static int lpwm2_stop(lua_State *L) { + pwm2_stop(); + return 0; +} + +static int lpwm2_start(lua_State *L) { + if (!pwm2_start()) { + luaL_error(L, "pwm2: currently platform timer1 is being used by another module.\n"); + lua_pushboolean(L, false); + } else { + lua_pushboolean(L, true); + } + return 1; +} + +// Module function map +LROT_BEGIN(pwm2) +LROT_FUNCENTRY(setup_pin_hz, lpwm2_setup_pin_hz) +LROT_FUNCENTRY(setup_pin_sec, lpwm2_setup_pin_sec) +LROT_FUNCENTRY(release_pin, lpwm2_release_pin) +LROT_FUNCENTRY(start, lpwm2_start) +LROT_FUNCENTRY(stop, lpwm2_stop) +LROT_FUNCENTRY(set_duty, lpwm2_set_duty) +LROT_FUNCENTRY(get_timer_data, lpwm2_get_timer_data) +LROT_FUNCENTRY(get_pin_data, lpwm2_get_pin_data) +// LROT_FUNCENTRY(print_setup, lpwm2_print_setup) +// LROT_FUNCENTRY( time_it, lpwm2_timeit) +// LROT_FUNCENTRY( test_tmr_manual, lpwm2_timing_frc1_manual_load_overhead) +// LROT_FUNCENTRY( test_tmr_auto, lpwm2_timing_frc1_auto_load_overhead) +LROT_END(pwm2, NULL, 0) + +NODEMCU_MODULE(PWM2, "pwm2", pwm2, lpwm2_open); diff --git a/app/platform/hw_timer.c b/app/platform/hw_timer.c index 0a0e45db08..938d18098c 100644 --- a/app/platform/hw_timer.c +++ b/app/platform/hw_timer.c @@ -86,6 +86,15 @@ static int32_t last_timer_load; #define LOCK() do { ets_intr_lock(); lock_count++; } while (0) #define UNLOCK() if (--lock_count == 0) ets_intr_unlock() +/* + * It is possible to reserve the timer exclusively, for one module alone. + * This way the interrupt overhead is minimal. + * Drawback is that no other module can use the timer at same time. + * If flag if true, indicates someone reserved the timer exclusively. + * Unline shared used (default), only one client can reserve exclusively. + */ +static bool reserved_exclusively = false; + /* * To start a timer, you write to FRCI_LOAD_ADDRESS, and that starts the counting * down. When it reaches zero, the interrupt fires -- but the counting continues. @@ -275,6 +284,8 @@ static void ICACHE_RAM_ATTR insert_active_tu(timer_user *tu) { *******************************************************************************/ bool ICACHE_RAM_ATTR platform_hw_timer_arm_ticks(os_param_t owner, uint32_t ticks) { + if (reserved_exclusively) return false; + timer_user *tu = find_tu_and_remove(owner); if (!tu) { @@ -322,6 +333,8 @@ bool ICACHE_RAM_ATTR platform_hw_timer_arm_us(os_param_t owner, uint32_t microse *******************************************************************************/ bool platform_hw_timer_set_func(os_param_t owner, void (* user_hw_timer_cb_set)(os_param_t), os_param_t arg) { + if (reserved_exclusively) return false; + timer_user *tu = find_tu(owner); if (!tu) { return false; @@ -393,6 +406,8 @@ static void ICACHE_RAM_ATTR hw_timer_nmi_cb(void) *******************************************************************************/ uint32_t ICACHE_RAM_ATTR platform_hw_timer_get_delay_ticks(os_param_t owner) { + if (reserved_exclusively) return 0; + timer_user *tu = find_tu(owner); if (!tu) { return 0; @@ -412,7 +427,7 @@ uint32_t ICACHE_RAM_ATTR platform_hw_timer_get_delay_ticks(os_param_t owner) /****************************************************************************** * FunctionName : platform_hw_timer_init -* Description : initialize the hardware isr timer +* Description : initialize the hardware isr timer for shared use i.e. multiple owners. * Parameters : os_param_t owner * FRC1_TIMER_SOURCE_TYPE source_type: * FRC1_SOURCE, timer use frc1 isr as isr source. @@ -424,6 +439,8 @@ uint32_t ICACHE_RAM_ATTR platform_hw_timer_get_delay_ticks(os_param_t owner) *******************************************************************************/ bool platform_hw_timer_init(os_param_t owner, FRC1_TIMER_SOURCE_TYPE source_type, bool autoload) { + if (reserved_exclusively) return false; + timer_user *tu = find_tu_and_remove(owner); if (!tu) { @@ -456,19 +473,25 @@ bool platform_hw_timer_init(os_param_t owner, FRC1_TIMER_SOURCE_TYPE source_type /****************************************************************************** * FunctionName : platform_hw_timer_close -* Description : ends use of the hardware isr timer -* Parameters : os_param_t owner +* Description : ends use of the hardware isr timer. +* Parameters : os_param_t owner. * Returns : true if it worked *******************************************************************************/ bool ICACHE_RAM_ATTR platform_hw_timer_close(os_param_t owner) { + if (reserved_exclusively) return false; + timer_user *tu = find_tu_and_remove(owner); if (tu) { - LOCK(); - tu->next = inactive; - inactive = tu; - UNLOCK(); + if (tu == inactive) { + inactive == NULL; + } else { + LOCK(); + tu->next = inactive; + inactive = tu; + UNLOCK(); + } } // This will never actually run.... @@ -484,3 +507,91 @@ bool ICACHE_RAM_ATTR platform_hw_timer_close(os_param_t owner) return true; } +/****************************************************************************** +* FunctionName : platform_hw_timer_init_exclusive +* Description : initialize the hardware isr timer for exclusive use by the caller. +* Parameters : FRC1_TIMER_SOURCE_TYPE source_type: +* FRC1_SOURCE, timer use frc1 isr as isr source. +* NMI_SOURCE, timer use nmi isr as isr source. +* bool autoload: +* 0, not autoload, +* 1, autoload mode, +* void (* frc1_timer_cb)(os_param_t): timer callback function when FRC1_SOURCE is being used +* os_param_t arg : argument passed to frc1_timer_cb or NULL +* void (* nmi_timer_cb)(void) : timer callback function when NMI_SOURCE is being used +* Returns : true if it worked, false if the timer is already served for shared or exclusive use +*******************************************************************************/ +bool platform_hw_timer_init_exclusive( + FRC1_TIMER_SOURCE_TYPE source_type, + bool autoload, + void (* frc1_timer_cb)(os_param_t), + os_param_t arg, + void (*nmi_timer_cb)(void) + ) +{ + if (active || inactive) return false; + if (reserved_exclusively) return false; + reserved_exclusively = true; + + RTC_REG_WRITE(FRC1_CTRL_ADDRESS, (autoload ? FRC1_AUTO_LOAD : 0) | DIVIDED_BY_16 | FRC1_ENABLE_TIMER | TM_EDGE_INT); + + if (source_type == NMI_SOURCE) { + ETS_FRC_TIMER1_NMI_INTR_ATTACH(nmi_timer_cb); + } else { + ETS_FRC_TIMER1_INTR_ATTACH((void (*)(void *))frc1_timer_cb, (void*)arg); + } + + TM1_EDGE_INT_ENABLE(); + ETS_FRC1_INTR_ENABLE(); + + return true; +} + +/****************************************************************************** +* FunctionName : platform_hw_timer_close_exclusive +* Description : ends use of the hardware isr timer in exclusive mode. +* Parameters : +* Returns : true if it worked +*******************************************************************************/ +bool ICACHE_RAM_ATTR platform_hw_timer_close_exclusive() +{ + if (!reserved_exclusively) return true; + reserved_exclusively = false; + + /* Set no reload mode */ + RTC_REG_WRITE(FRC1_CTRL_ADDRESS, DIVIDED_BY_16 | TM_EDGE_INT); + + TM1_EDGE_INT_DISABLE(); + ETS_FRC1_INTR_DISABLE(); + + return true; +} + +/****************************************************************************** +* FunctionName : platform_hw_timer_arm_ticks_exclusive +* Description : set a trigger timer delay for this timer. +* Parameters : uint32 ticks : +* Returns : true if it worked +*******************************************************************************/ +bool ICACHE_RAM_ATTR platform_hw_timer_arm_ticks_exclusive(uint32_t ticks) +{ + RTC_REG_WRITE(FRC1_LOAD_ADDRESS, ticks); + return true; +} + +/****************************************************************************** +* FunctionName : platform_hw_timer_arm_us_exclusive +* Description : set a trigger timer delay for this timer. +* Parameters : uint32 microseconds : +* in autoload mode +* 50 ~ 0x7fffff; for FRC1 source. +* 100 ~ 0x7fffff; for NMI source. +* in non autoload mode: +* 10 ~ 0x7fffff; +* Returns : true if it worked +*******************************************************************************/ +bool ICACHE_RAM_ATTR platform_hw_timer_arm_us_exclusive(uint32_t microseconds) +{ + RTC_REG_WRITE(FRC1_LOAD_ADDRESS, US_TO_RTC_TIMER_TICKS(microseconds)); + return true; +} diff --git a/app/platform/hw_timer.h b/app/platform/hw_timer.h index f2290fc5b7..ee2f8e2dc5 100644 --- a/app/platform/hw_timer.h +++ b/app/platform/hw_timer.h @@ -30,5 +30,13 @@ bool ICACHE_RAM_ATTR platform_hw_timer_close(os_param_t owner); uint32_t ICACHE_RAM_ATTR platform_hw_timer_get_delay_ticks(os_param_t owner); +bool platform_hw_timer_init_exclusive(FRC1_TIMER_SOURCE_TYPE source_type, bool autoload, void (* frc1_timer_cb)(os_param_t), os_param_t arg, void (*nmi_timer_cb)(void) ); + +bool ICACHE_RAM_ATTR platform_hw_timer_close_exclusive(); + +bool ICACHE_RAM_ATTR platform_hw_timer_arm_ticks_exclusive(uint32_t ticks); + +bool ICACHE_RAM_ATTR platform_hw_timer_arm_us_exclusive(uint32_t microseconds); + #endif diff --git a/docs/modules/pwm2.md b/docs/modules/pwm2.md new file mode 100644 index 0000000000..de46796142 --- /dev/null +++ b/docs/modules/pwm2.md @@ -0,0 +1,309 @@ +# PWM2 Module +| Since | Origin / Contributor | Maintainer | Source | +| :----- | :-------------------- | :---------- | :------ | +| 2019-02-12 | [fikin](https://github.com/fikin) | [fikin](https://github.com/fikin) | [pwm2.c](../../../app/modules/pwm2.c)| + +Module to generate PWM impulses to any of the GPIO pins. + +PWM is being generated by software using soft-interrupt TIMER1 FRC1. This module is using the timer in exclusive mode. See [understanding timer use](#understanding-timer-use) for more. + +Supported frequencies are roughly from 120kHZ (with 50% duty) up to pulse/53sec (or 250kHz and 26 sec for CPU160). See [understanding frequencies](#understand-frequencies) for more. + +Supported are also frequency fractions even for integer-only firmware builds. + +Supported are all of the GPIO pins except pin 0. + +One can generate different PWM signals to any of them at the same time. See [working with multiple frequencies](#working-with-multiple-frequencies) for more. + +This module supports CPU80MHz as well as CPU160MHz. Frequency boundaries are same but by using CPU160MHz one can hope of doing more work meantime. + +Typical usage is as following: +```lua +pwm2.setup_pin_hz(3,250000,2,1) -- pin 3, PWM freq of 250kHz, pulse period of 2 steps, initial duty 1 period step +pwm2.setup_pin_hz(4,1,2,1) -- pin 4, PWM freq of 1Hz, pulse period of 2 steps, initial duty 1 period step +pwm2.start() -- starts pwm, internal led will blink with 0.5sec interval +... +pwm2.set_duty(4, 2) -- led full off (pin is high) +... +pwm2.set_duty(4, 0) -- led full on (pin is low) +... +pwm2.stop() -- PWM stopped, gpio pin released, timer1 released +``` + +## Understand frequencies + +All frequencines and periods internally are expressed as CPU ticks using following formula: `cpuTicksPerSecond / (frequencyHz * period)`. For example, 1kHz with 1000 period for CPU80MHz results in 80 CPU ticks per period i.e. period is 1uS long. + +In order to allow for better tunning, I've added an optional frequencyDivisor argument when setting pins up. With it one can express the frequency as division between two values : `frequency / divisor`. For example to model 100,1Hz frequency one has to specify frequency of 1001 and divisor 10. + +An easy way to express sub-Hz frequencies, i.e. the ones taking seconds to complete one impulse, is to use setup in seconds methods. For them formula to compute CPU ticks is `cpuTicksPerSecond * frequencySec / period`. Max pulse duration is limited by roll-over of the ESP's internal CPU 32bits ticks counter. For CPU80 that would be every 53 seconds, for CPU160 that would be half. + +## Frequency precision and limits + +ESP's TIMER1 FRC1 is operating at fixed, own frequency of 5MHz. Therefore the precision of individual interrupt is 200ns. But that limit cannot be attained. + +OS timer interrupt handler code itself has internal overhead. For auto-loaded interrupts it is about 50CPUTicks. For short periods of time one can interrupt at approximately 1MHz but then watchdog will intervene. + +PWM2 own interrupt handler has an overhead of 162CPUTicks + 12CPUTicks per each used pin. + +With the fastest setup i.e. 1 pin, 50% duty cycle (pulse period of 2) and CPU80 one could expect to achive PWM frequency of 125kHz. +For 12 pins that would drop to about 100kHz. With CPU160 one could reach 220kHz with 1 pin. + +Frequencies internally are expressed as CPU ticks first then to TIMER1 ticks. Because TIMER1 frequency is 1/16 of CPU frequency, some frequency precision is lost when converting from CPU to TIMER ticks. One can inspect exact values used via [pwm2.get_timer_data()](#pwm2get_timer_data). Value of `interruptTimerCPUTicks` represents desired interrupt period in CPUTicks. And `interruptTimerTicks` represents actually used interrupt period as TIMER1 ticks (1/16 of CPU). + +## Working with multiple frequencies + +When working with multiple pins, this module auto-discovers what would be the right underlying interrupt frequency. It does so by computing the greatest common frequency divisor and use it as common frequency for all pins. + +When using same frequency for many pins, tunning frequency of single pin is enough to ensure precision. + +When using different frequencies, one has to pay close attention at their greates common divisor when expressed as CPU ticks. For example, mixing 100kHz with period 2 and 0.5Hz with period 2 results in underlying interrupt period of 800CPU ticks. But changing to 100kHz+1 will easily result to divisor of 1. This is clearly non-working combination. +Another example is frequency of 120kHz with period 2, which results in period of 333CPU ticks. If combined with even-resulting frequency like 1Hz with period of 2, this will lead to common divisor of 1, which is clearly a non-working setup either. +For the moment best would be to use [pwm2.get_timer_data()](#pwm2get_timer_data) and observe how `interruptTimerCPUTicks` and `interruptTimerTicks` change with given input. + +## Understanding timer use + +This module is using soft-interrupt TIMER1 FRC1 to generate PWM signal. Since its interrupts can be masked, as some part of OS are doing it, it is possible to have some impact on the quality of generated PWM signal. As a general principle, one should not expect high precision signal with this module. +Also note that interrupt masking is dependent on other activities happening within the ESP besides pwm2 module. + +Additionally this timer is used by other modules like pwm, pcm, ws2812 and etc. Since an exclusive lock is maintained on the timer, simultaneous use of such modules would not be possible. + +## Troubleshooting watchdog timeouts + +Watchdog interrupt typically will occur if choosen frequency (and period) is too big i.e. too small timer ticks value. For CPU80MHz I guess threshold is around 125kHz with period of 2 and single pin (CPU80), given not much other load on the system. For CPU160 threshold is 225kHz. + +Another reason for watchdog interrupt to occur is due to mixing otherwise not very compatible frequencies when multiple pins are used. See [working with multiple frequencies](#working-with-multiple-frequencies) for more. + +Both cases are best anlyzed using [pwm2.get_timer_data()](#pwm2get_timer_data) watching values of `interruptTimerCPUTicks` and `interruptTimerTicks`. For `interruptTimerCPUTicks` with CPU80 anything below (330/630) for (1/12) pins would be cause for special attention. + +## Differences with PWM module + +PWM and PWM2 are modules doing similar job and have much in common. +Here are few PWM2 highlights compared to PWM module: + +- PWM2 is using TIMER1 exclusively, which allows for possibly a better quality PWM signal +- PWM2 can generate PWM frequencies in the range of 1pulse/53 seconds up to 125kHz (26sec/225kHz for CPU160) +- PWM2 can generate PWM frequencies with fractions i.e. 1001kHz +- PWM2 supports CPU160 +- PWM2 supports virtually all GPIO ports at the same time + +Unlike PWM2, PWM can: + +- generate PWM pulse with a little bit bigger duty cycle i.e. 1kHz at 1000 pulse period +- can be used at the same time with some other modules like gpio.pulse + +## pwm2.setup_pin_hz() + +Assigns PWM frequency expressed as Hz to given pin. +This method is suitable for setting up frequencies in the range of >= 1Hz. + +### Syntax + +`pwm2.setup_pin_hz(pin,frequencyAsHz,pulsePeriod,initialDuty [,frequencyDivisor])` + +### Parameters + +- `pin` 1-12 +- `frequencyAsHz` desired frequency in Hz, for example 1000 for 1KHz +- `pulsePeriod` discreet steps in single PWM pulse, for example 100 +- `initialDuty` initial duty in pulse period steps i.e. 50 for 50% pulse of 100 resolution +- `frequencyDivisor` an integer to divide product of frequency and pulsePeriod. Used to form frequency fractions. By default not required. + +### Returns + +`nil` + +### See also + +- [pwm2.setup_pin_sec()](#pwm2setup_pin_sec) +- [pwm2.start()](#pwm2start) +- [pwm2.release_pin()](#pwm2release_pin) +- [understanding frequencies](#understand-frequencies) +- [working with multiple frequencies](#working-with-multiple-frequencies) +- [pwm2.get_timer_data()](#pwm2get_timer_data) + +## pwm2.setup_pin_sec() + +Assigns PWM frequency expressed as one impulse per second(s) to given pin. +This method is suitable for setting up frequencies in the range of 0 < 1Hz but expressed as seconds instead. +For example 0.5Hz are expressed as 2 seconds impulse. + +### Syntax + +`pwm2.setup_pin_sec(pin,frequencyAsSec,pulsePeriod,initialDuty [,frequencyDivisor])` + +### Parameters + +- `pin` 1-12 +- `frequencyAsSec` desired frequency as one impulse for given seconds, for example 2 means PWM with impulse long 2 seconds. +- `pulsePeriod` discreet steps in single PWM pulse, for example 100 +- `initialDuty` initial duty in pulse period steps i.e. 50 for 50% pulse of 100 resolution +- `frequencyDivisor` an integer to divide product of frequency and pulsePeriod. Used to form frequency fractions. By default not required. + +### Returns + +`nil` + +### See also + +- [pwm2.setup_pin_hz()](#pwm2setup_pin_hz) +- [pwm2.start()](#pwm2start) +- [pwm2.release_pin()](#pwm2release_pin) +- [understanding frequencies](#understand-frequencies) +- [working with multiple frequencies](#working-with-multiple-frequencies) +- [pwm2.get_timer_data()](#pwm2get_timer_data) + +## pwm2.start() + +Starts PWM for all setup pins. +At this moment GPIO pins are marked as output and TIMER1 is being reserved for this module. +If the TIMER1 is already reserved by another module this method reports a Lua error and returns false. + +### Syntax + +`pwm2.start()` + +### Parameters + +`nil` + +### Returns + +- `bool` true if PWM started ok, false of TIMER1 is reserved by another module. + +### See also + +- [pwm2.setup_pin_hz()](#pwm2setup_pin_hz) +- [pwm2.setup_pin_sec()](#pwm2setup_pin_sec) +- [pwm2.set_duty()](#pwm2set_duty) +- [pwm2.stop()](#pwm2stop) + +## pwm2.stop() + +Stops PWM for all pins. All GPIO pins and TIMER1 are being released. +One can resume PWM with previous pin settings by calling [pwm2.start()](#pwm2start) right after stop. + +### Syntax + +`pwm2.stop()` + +### Parameters + +`nil` + +### Returns + +`nil` + +### See also + +- [pwm2.start()](#pwm2start) +- [pwm2.release_pin()](#pwm2release_pin) + +## pwm2.set_duty() + +Sets duty cycle for one or more a pins. This method takes immediate effect to ongoing PWM generation. + +### Syntax + +`pwm2.set_duty(pin, duty [,pin,duty]*)` + +### Parameters + +- `pin` 1~12, IO index +- `duty` 0~period, pwm duty cycle + +### Returns + +`nil` + +### See also + +- [pwm2.stop()](#pwm2stop) + +## pwm2.release_pin() + +Releases given pin from previously done setup. This method is applicable when PWM is stopped and given pin is not needed anymore. +Releasing pins is not strictly needed. This method is useful for start-stop-start situations when pins do change. + +### Syntax + +`pwm2.release_pin(pin)` + +### Parameters + +- `pin` 1~12, IO index + +### Returns + +`nil` + +### See also + +- [pwm2.setup_pin_hz()](#pwm2setup_pin_hz) +- [pwm2.setup_pin_sec()](#pwm2setup_pin_sec) +- [pwm2.stop()](#pwm2stop) + +## pwm2.get_timer_data() + +Prints internal data structures related to the timer. This method is usefull for people troubleshooting frequency side effects. + +### Syntax + +`pwm2.get_timer_data()` + +### Parameters + +`nil` + +### Returns + +- `isStarted` bool, if true PWM2 has been started +- `interruptTimerCPUTicks` int, desired timer interrupt period in CPU ticks +- `interruptTimerTicks` int, actual timer interrupt period in timer ticks + +### Example + +``` +isStarted, interruptTimerCPUTicks, interruptTimerTicks = pwm2.get_timer_data() +``` + +### See also + +- [pwm2.setup_pin_hz()](#pwm2setup_pin_hz) +- [pwm2.setup_pin_sec()](#pwm2setup_pin_sec) +- [pwm2.get_pin_data()](#pwm2get_pin_data) + +## pwm2.get_pin_data() + +Prints internal data structures related to given GPIO pin. This method is usefull for people troubleshooting frequency side effects. + +### Syntax + +`pwm2.get_pin_data(pin)` + +### Parameters + +- `pin` 1~12, IO index + +### Returns + +- `isPinSetup` bool, if 1 pin is setup +- `duty` int, assigned duty +- `pulseResolutions` int, assigned pulse periods +- `divisableFrequency` int, assigned frequency +- `frequencyDivisor` int, assigned frequency divisor +- `resolutionCPUTicks` int, calculated one pulse period in CPU ticks +- `resolutionInterruptCounterMultiplier` int, how many timer interrupts constitute one pulse period + +### Example + +``` +isPinSetup, duty, pulseResolutions, divisableFrequency, frequencyDivisor, resolutionCPUTicks, resolutionInterruptCounterMultiplier = pwm2..get_pin_data(4) +``` + +### See also + +- [pwm2.setup_pin_hz()](#pwm2setup_pin_hz) +- [pwm2.setup_pin_sec()](#pwm2setup_pin_sec) +- [pwm2.get_timer_data()](#pwm2get_timer_data) diff --git a/mkdocs.yml b/mkdocs.yml index 746c8929ff..bd79d837ca 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -88,6 +88,7 @@ pages: - 'pcm' : 'modules/pcm.md' - 'perf': 'modules/perf.md' - 'pwm' : 'modules/pwm.md' + - 'pwm2' : 'modules/pwm2.md' - 'rc' : 'modules/rc.md' - 'rfswitch' : 'modules/rfswitch.md' - 'rotary' : 'modules/rotary.md' From a9256aec8bff7ba500ea5e7becc14cbcf8187d37 Mon Sep 17 00:00:00 2001 From: galjonsfigur <44552519+galjonsfigur@users.noreply.github.com> Date: Sat, 1 Jun 2019 18:05:19 +0200 Subject: [PATCH 24/74] Fix issue #2753 and fix documentation example (#2776) --- app/modules/ads1115.c | 2 +- docs/modules/ads1115.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/modules/ads1115.c b/app/modules/ads1115.c index 0c34436106..72181ba44e 100644 --- a/app/modules/ads1115.c +++ b/app/modules/ads1115.c @@ -585,7 +585,7 @@ LROT_BEGIN(ads1115_instance) #ifdef ADS1115_INCLUDE_TEST_FUNCTION LROT_FUNCENTRY( test_volt_conversion, test_volt_conversion ) #endif - LROT_TABENTRY( "__index", ads1115_instance ) + LROT_TABENTRY( __index, ads1115_instance ) LROT_FUNCENTRY( __gc, ads1115_lua_delete ) LROT_END(ads1115_instance, ads1115_instance, LROT_MASK_GC_INDEX ) diff --git a/docs/modules/ads1115.md b/docs/modules/ads1115.md index a093586782..9f35933b42 100644 --- a/docs/modules/ads1115.md +++ b/docs/modules/ads1115.md @@ -125,7 +125,7 @@ adc1:setting(ads1115.GAIN_6_144V, ads1115.DR_128SPS, ads1115.SINGLE_0, ads1115.C local function comparator(level, when) -- read adc result with read() when threshold reached gpio.trig(alert_pin) - volt, volt_dec, adc, sign = ads1:read() + volt, volt_dec, adc, sign = adc1:read() print(volt, volt_dec, adc, sign) end gpio.mode(alert_pin, gpio.INT) From 7a969b56518a83836384dfec0f6ec2eb886d1048 Mon Sep 17 00:00:00 2001 From: galjonsfigur <44552519+galjonsfigur@users.noreply.github.com> Date: Sat, 1 Jun 2019 18:07:40 +0200 Subject: [PATCH 25/74] Modify HTTP OTA to not erase saved credentials (#2758) (#2778) --- lua_examples/lfs/HTTP_OTA.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua_examples/lfs/HTTP_OTA.lua b/lua_examples/lfs/HTTP_OTA.lua index 60819d447f..42472de5ae 100644 --- a/lua_examples/lfs/HTTP_OTA.lua +++ b/lua_examples/lfs/HTTP_OTA.lua @@ -65,7 +65,7 @@ finalise = function(sck) sck:close() local s = file.stat(image) if (s and size == s.size) then - wifi.setmode(wifi.NULLMODE) + wifi.setmode(wifi.NULLMODE, false) collectgarbage();collectgarbage() -- run as separate task to maximise RAM available node.task.post(function() node.flashreload(image) end) From 5f147a735252de9605c76cda29e4cbab692c65a5 Mon Sep 17 00:00:00 2001 From: Terry Ellison Date: Wed, 19 Jun 2019 15:16:17 +0300 Subject: [PATCH 26/74] Baseline version of Pipe library (#2797) --- app/include/user_modules.h | 1 + app/modules/pipe.c | 309 +++++++++++++++++++++++++++++++++++++ docs/modules/pipe.md | 131 ++++++++++++++++ 3 files changed, 441 insertions(+) create mode 100644 app/modules/pipe.c create mode 100644 docs/modules/pipe.md diff --git a/app/include/user_modules.h b/app/include/user_modules.h index ecb2f4461f..0b28dbe757 100644 --- a/app/include/user_modules.h +++ b/app/include/user_modules.h @@ -42,6 +42,7 @@ #define LUA_USE_MODULES_OW //#define LUA_USE_MODULES_PCM //#define LUA_USE_MODULES_PERF +//#define LUA_USE_MODULES_PIPE //#define LUA_USE_MODULES_PWM //#define LUA_USE_MODULES_PWM2 //#define LUA_USE_MODULES_RC diff --git a/app/modules/pipe.c b/app/modules/pipe.c new file mode 100644 index 0000000000..7e300eaf01 --- /dev/null +++ b/app/modules/pipe.c @@ -0,0 +1,309 @@ +/* +** The pipe algo is somewhat similar to the luaL_Buffer algo, except that it uses +** table to store the LUAL_BUFFERSIZE byte array chunks instead of the stack. +** Writing is always to the last UD in the table and overflow pushes a new UD to +** the end of the table. Reading is always from the first UD in the table and +** underrun removes the first UD to shift a new one into slot 1. +** +** Reads and writes may span multiple UD buffers and if the read spans multiple UDs +** then the parts are collected as strings on the Lua stack and then concatenated +** with a `lua_concat()`. +** +** Note that pipes also support the undocumented length and tostring operators +** for debugging puposes, so if p is a pipe then #p[1] gives the effective +** length of pipe slot 1 and printing p[1] gives its contents +** +** Read the docs/modules/pipe.md documentation for a functional description. +*/ + +#include "module.h" +#include "lauxlib.h" +#include + +#define INVALID_LEN ((unsigned)-1) + +#define LUA_USE_MODULES_PIPE + +typedef struct buffer { + int start, end; + char buf[LUAL_BUFFERSIZE]; +} buffer_t; + +LROT_TABLE(pipe_meta) + +/* Validation and utility functions */ + +#define AT_HEAD 1 +#define AT_TAIL 0 + +static buffer_t *checkPipeUD (lua_State *L, int ndx) { // [-0, +0, v] + buffer_t *ud = lua_touserdata(L, ndx); + if (ud && lua_getmetatable(L, ndx)) { /* Get UD and its metatable? */ + lua_pushrotable(L, LROT_TABLEREF(pipe_meta)); /* push correct metatable */ + if (lua_rawequal(L, -1, -2)) { /* Do these match? */ + lua_pop(L, 2); /* remove both metatables */ + return ud; /* and return ptr to buffer_t rec */ + } + } + if (!lua_istable(L,ndx)) + luaL_typerror(L, ndx, "pipeUD"); /* NORETURN error */ + return NULL; /* keep compiler happy */ +} + +static buffer_t *newPipeUD(lua_State *L, int ndx, int n) { // [-0,+0,-] + buffer_t *ud = (buffer_t *) lua_newuserdata(L, sizeof(buffer_t)); + lua_pushrotable(L, LROT_TABLEREF(pipe_meta)); /* push the metatable */ + lua_setmetatable(L, -2); /* set UD's metabtable to pipe_meta */ + ud->start = ud->end = 0; + lua_rawseti(L, ndx, n); /* T[#T+1] = new UD */ + return ud; /* ud points to new T[#T] */ +} + +static buffer_t *checkPipeTable (lua_State *L, int tbl, int head) {//[-0, +0, v] + int m = lua_gettop(L), n = lua_objlen(L, tbl); + if (lua_type(L, tbl) == LUA_TTABLE && lua_getmetatable(L, tbl)) { + lua_pushrotable(L, LROT_TABLEREF(pipe_meta));/* push comparison metatable */ + if (lua_rawequal(L, -1, -2)) { /* check these match */ + buffer_t *ud; + if (n == 0) { + ud = head ? NULL : newPipeUD(L, tbl, 1); + } else { + int i = head ? 1 : n; /* point to head or tail of T */ + lua_rawgeti(L, tbl, i); /* and fetch UD */ + ud = checkPipeUD(L, -1); + } + lua_settop(L, m); + return ud; /* and return ptr to buffer_t rec */ + } + } + luaL_typerror(L, tbl, "pipe table"); + return NULL; /* NORETURN avoid compiler error */ +} + +#define CHAR_DELIM -1 +#define CHAR_DELIM_KEEP -2 +static char getsize_delim (lua_State *L, int ndx, int *len) { // [-0, +0, v] + char delim; + int n; + if( lua_type( L, ndx ) == LUA_TNUMBER ) { + n = luaL_checkinteger( L, ndx ); + luaL_argcheck(L, n > 0, ndx, "invalid chunk size"); + delim = '\0'; + } else if (lua_isnil(L, ndx)) { + n = CHAR_DELIM; + delim = '\n'; + } else { + size_t ldelim; + const char *s = lua_tolstring( L, 2, &ldelim); + n = ldelim == 2 && s[1] == '+' ? CHAR_DELIM_KEEP : CHAR_DELIM ; + luaL_argcheck(L, ldelim + n == 0, ndx, "invalid delimiter"); + delim = s[0]; + } + if (len) + *len = n; + return delim; +} + +/* Lua callable methods */ + +//Lua s = pipeUD:tostring() +static int pipe__tostring (lua_State *L) { + if (lua_type(L, 1) == LUA_TTABLE) { + lua_pushfstring(L, "Pipe: %p", lua_topointer(L, 1)); + } else { + buffer_t *ud = checkPipeUD(L, 1); + lua_pushlstring(L, ud->buf + ud->start, ud->end - ud->start); + } + return 1; +} + +// len = #pipeobj[1] +static int pipe__len (lua_State *L) { + if (lua_type(L, 1) == LUA_TTABLE) { + lua_pushinteger(L, lua_objlen(L, 1)); + } else { + buffer_t *ud = checkPipeUD(L, 1); + lua_pushinteger(L, ud->end - ud->start); + } + return 1; +} + +// Lua: buf = pipe.create() +static int pipe_create(lua_State *L) { + lua_createtable (L, 1, 0); + lua_pushrotable(L, LROT_TABLEREF(pipe_meta)); + lua_setmetatable(L, 1); /* set table's metabtable to pipe_meta */ + return 1; /* return the table */ +} + +// Lua: rec = p:read(end_or_delim) // also [-2, +1,- ] +static int pipe_read(lua_State *L) { + buffer_t *ud = checkPipeTable(L, 1, AT_HEAD); + int i, k=0, n; + lua_settop(L,2); + const char delim = getsize_delim(L, 2, &n); + lua_pop(L,1); + + while (ud && n) { + int want, used, avail = ud->end - ud->start; + + if (n < 0 /* one of the CHAR_DELIM flags */) { + /* getting a delimited chunk so scan for delimiter */ + for (i = ud->start; i < ud->end && ud->buf[i] != delim; i++) {} + /* Can't have i = ud->end and ud->buf[i] == delim so either */ + /* we've scanned full buffer avail OR we've hit a delim char */ + if (i == ud->end) { + want = used = avail; /* case where we've scanned without a hit */ + } else { + want = used = i + 1 - ud->start; /* case where we've hit a delim */ + if (n == CHAR_DELIM) + want--; + } + } else { + want = used = (n < avail) ? n : avail; + n -= used; + } + lua_pushlstring(L, ud->buf + ud->start, want); /* part we want */ + k++; + ud->start += used; + if (ud->start == ud->end) { + /* shift the pipe array down overwriting T[1] */ + int nUD = lua_objlen(L, 1); + for (i = 1; i < nUD; i++) { /* for i = 1, nUD-1 */ + lua_rawgeti(L, 1, i+1); lua_rawseti(L, 1, i); /* T[i] = T[i+1] */ + } + lua_pushnil(L); lua_rawseti(L, 1, nUD--); /* T[n] = nil */ + if (nUD) { + lua_rawgeti(L, 1, 1); + ud = checkPipeUD(L, -1); + lua_pop(L, 1); + } else { + ud = NULL; + } + } + } + if (k) + lua_concat(L, k); + else + lua_pushnil(L); + return 1; +} + +// Lua: buf:unread(some_string) +static int pipe_unread(lua_State *L) { + size_t l = INVALID_LEN; + const char *s = lua_tolstring(L, 2, &l); + if (l==0) + return 0; + luaL_argcheck(L, l != INVALID_LEN, 2, "must be a string"); + buffer_t *ud = checkPipeTable(L, 1, AT_HEAD); + + do { + int used = ud->end - ud->start, lrem = LUAL_BUFFERSIZE-used; + + if (used == LUAL_BUFFERSIZE) { + int i, nUD = lua_objlen(L, 1); + for (i = nUD; i > 0; i--) { /* for i = nUD-1,1,-1 */ + lua_rawgeti(L, 1, i); lua_rawseti(L, 1, i+1); /* T[i+1] = T[i] */ + } + ud = newPipeUD(L, 1, 1); + used = 0; lrem = LUAL_BUFFERSIZE; + } else if (ud->end < LUAL_BUFFERSIZE) { + memmove(ud->buf + lrem, + ud->buf + ud->start, used); /* must be memmove not cpy */ + } + ud->start = lrem; ud->end = LUAL_BUFFERSIZE; + + if (l <= (unsigned )lrem) + break; + + /* If we've got here then the remaining string is strictly longer than the */ + /* remaining buffer space, so top off the buffer before looping around again */ + l -= lrem; + memcpy(ud->buf, s + l, lrem); + ud->start = 0; + + } while(1); + + /* Copy any residual tail to the UD buffer. Note that this is l>0 and */ + ud->start -= l; + memcpy(ud->buf + ud->start, s, l); + return 0; +} + +// Lua: buf:write(some_string) +static int pipe_write(lua_State *L) { + size_t l = INVALID_LEN; + const char *s = lua_tolstring(L, 2, &l); + if (l==0) + return 0; + luaL_argcheck(L, l != INVALID_LEN, 2, "must be a string"); + buffer_t *ud = checkPipeTable(L, 1, AT_TAIL); + + do { + int used = ud->end - ud->start; + + if (used == LUAL_BUFFERSIZE) { + ud = newPipeUD(L, 1, lua_objlen(L, 1)+1); + used = 0; + } else if (ud->start) { + memmove(ud->buf, ud->buf + ud->start, used); /* must be memmove not cpy */ + ud->start = 0; ud->end = used; + } + + int lrem = LUAL_BUFFERSIZE-used; + if (l <= (unsigned )lrem) + break; + + /* If we've got here then the remaining string is longer than the buffer */ + /* space left, so top off the buffer before looping around again */ + memcpy(ud->buf + ud->end, s, lrem); + ud->end += lrem; + l -= lrem; + s += lrem; + + } while(1); + + /* Copy any residual tail to the UD buffer. Note that this is l>0 and */ + memcpy(ud->buf + ud->end, s, l); + ud->end += l; + return 0; +} + +// Lua: fread = pobj:reader(1400) -- or other number +// fread = pobj:reader('\n') -- or other delimiter (delim is stripped) +// fread = pobj:reader('\n+') -- or other delimiter (delim is retained) +#define TBL lua_upvalueindex(1) +#define N lua_upvalueindex(2) +static int pipe_read_aux(lua_State *L) { + lua_settop(L, 0); /* ignore args since we use upvals instead */ + lua_pushvalue(L, TBL); + lua_pushvalue(L, N); + return pipe_read(L); +} +static int pipe_reader(lua_State *L) { + lua_settop(L,2); + checkPipeTable (L, 1,AT_HEAD); + getsize_delim(L, 2, NULL); + lua_pushcclosure(L, pipe_read_aux, 2); /* return (closure, nil, table) */ + return 1; +} + + +LROT_BEGIN(pipe_meta) + LROT_TABENTRY( __index, pipe_meta) + LROT_FUNCENTRY( __len, pipe__len ) + LROT_FUNCENTRY( __tostring, pipe__tostring ) + LROT_FUNCENTRY( read, pipe_read ) + LROT_FUNCENTRY( reader, pipe_reader ) + LROT_FUNCENTRY( unread, pipe_unread ) + LROT_FUNCENTRY( write, pipe_write ) +LROT_END( pipe_meta, NULL, LROT_MASK_INDEX ) + + +LROT_BEGIN(pipe) + LROT_FUNCENTRY( create, pipe_create ) +LROT_END( lb, NULL, 0 ) + + +NODEMCU_MODULE(PIPE, "pipe", pipe, NULL); diff --git a/docs/modules/pipe.md b/docs/modules/pipe.md new file mode 100644 index 0000000000..2eb87fa4b1 --- /dev/null +++ b/docs/modules/pipe.md @@ -0,0 +1,131 @@ +# pipe Module +| Since | Origin / Contributor | Maintainer | Source | +| :----- | :-------------------- | :---------- | :------ | +| 2019-07-18 | [Terry Ellison](https://github.com/TerryE) | [Terry Ellison](https://github.com/TerryE) | [pipe.c](../../app/modules/pipe.c)| + +The pipe module provides RAM-efficient a means of passing character stream of records from one Lua +task to another. + +## pipe.create() + +Create a pipe. + +#### Syntax +`pobj = pipe.create()` + +#### Parameters +None + +#### Returns +A pipe resource. + + +## pobj:read() + +Read a record from a pipe object. + +Note that the recommended method of reading from a pipe is to user a reader function as described below. + +#### Syntax +`pobj:read([size/end_char])` + +#### Parameters +- `size/end_char` + - If numeric then a string of `size` length will be returned from the pipe. + - If a string then this is a single character delimiter, followed by an optional "+" flag. The delimiter is used as an end-of-record to split the character stream into separate records. If the flag "+" is specified then the delimiter is also returned at the end of the record, otherwise it is discarded. + - If omitted, then this defaults to `"\n+"` + +Note that if the last record in the pipe is missing a delimiter or is too short, then it is still returned, emptying the pipe. + +#### Returns +A string or `nil` if the pipe is empty + +#### Example +```lua +line = pobj:read('\n') +line = pobj:read(50) +``` + +## pobj:reader() + +Returns a Lua **iterator** function for a pipe object. This is as described in the +[Lua Language: For Statement](http://www.lua.org/manual/5.1/manual.html#2.4.5). \(Note that the +`state` and `object` variables mentioned in 2.5.4 are optional and default to `nil`, so this +conforms to to the`for` iterator syntax and works in a for because it maintains the state and `pobj` +internally as upvalues. + +An emptied pipe takes up minimal RAM resources (an empty Lua array), and just like any other array +this is reclaimed if all variables referencing it go out of scope or are over-written). Note +that any reader iterators that you have created also refer to the pipe as an upval, so you will +need to descard these to desope the pipe array. + +#### Syntax +`myFunc = pobj:reader([size/end_char])` + +#### Parameters +- `size/end_char` as for `pobj:read()` + +#### Returns +- `myFunc` iterator function + +#### Examples + +- used in `for` loop: +```lua +for rec in p:reader() do print(rec) end +-- or +fp = p:reader() +-- ... +for rec in fp do print(rec) end +``` + +- used in callback task: +```Lua +do + local pipe_reader = p:reader(1400) + local function flush(sk) -- Upvals flush, pipe_reader + local next = pipe_reader() + if next then + sk:send(next, flush) + else + sk:on('sent') -- dereference to allow GC + flush = nil + end + end + flush() +end +``` + +## pobj:unread() + +Write a string to a head of pipe object. This can be used to back-out a previous read. + +#### Syntax +`pobj:write(s)` + +#### Parameters +`s` Any input string. Note that with all Lua strings, these may contain all character values including "\0". + +#### Returns +Nothing + +#### Example + +```Lua +a=p:read() +p:unread() -- restores pipe to state before the read +``` + +## pobj:write() + +Write a string to a pipe object. + +#### Syntax +`pobj:write(s)` + +#### Parameters +`s` Any input string. Note that with all Lua strings, these may contain all character values including "\0". + +#### Returns +Nothing + From 16f75e996acf75b9992414f223391bffcc519a82 Mon Sep 17 00:00:00 2001 From: galjonsfigur <44552519+galjonsfigur@users.noreply.github.com> Date: Sat, 22 Jun 2019 00:20:36 +0200 Subject: [PATCH 27/74] Updated LFS introduction (#2807) --- docs/getting-started.md | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/docs/getting-started.md b/docs/getting-started.md index 4c3a76aee0..3f16c13af5 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -326,4 +326,45 @@ Once the LFS image file is on SPIFFS, you can execute the [node.flashreload()](. Do a protected call of this `_init` code: `pcall(node.flashindex("_init"))` and check the error status. See [Programming Techniques and Approachs](lfs.md#programming-techniques-and-approachs) in the LFS whitepaper for a more detailed description. +### Minimal LFS example + +Below is a brief overview of building and running the simplest LFS-based system possible. + +To use LFS, start with a version of NodeMCU with LUA_FLASH_STORE set in app/include/user_config.h, and load it on the ESP8266 in the usual way (whatever that is for your set up). + +Then build an LFS file system. This can be done in several ways, as discussed above; one of the easiest is to use `luac.cross -f -o lfs.img *lua` on the host machine. The file [lua_examples/lfs/_init.lua](https://github.com/nodemcu/nodemcu-firmware/tree/dev/lua_examples/lfs/_init.lua) should definitely be included in the image, since it's the easiest way of registering the LFS modules. The `lfs.img` file can then be downloaded to the ESP8266 just like any other file. + +The next step is to tell the ESP8266 that the LFS file system exists. This is done with eg. [node.flashreload("lfs.img")](../modules/node/#nodeflashreload), which will trigger a reset, followed by [node.flashindex("_init")()](../modules/node/#nodeflashindex) to register the modules; logging into the esp8266 and running the following commands gives an overview of the command sequence, given a main.lua file consisting of the line `print("LFS main() module")` + +``` +> +> node.flashreload("lfs.img") +-- flashreload() triggers a reset here. +> print(LFS) +nil +> node.flashindex("_init")() +-- LFS is now initialised. +> print(LFS) +table: 3fff06e0 +-- List the modules in the LFS. +> print(LFS._list) +table: 3fff0728 +> for k,v in pairs(LFS._list) do print(k,v) end +1 dummy_strings +2 _init +3 main +-- Call the LFS main() module. +> LFS.main() +LFS main() module +> +``` + +Note that no error correction has been used, since the commands are intended to be entered at a terminal, and errors will become obvious. + +After that, it's a question of setting up the ESP8266 boot process to check for the existence of an LFS image and run whichever module is required. Once the LFS module table has been registered by running [lua_examples/lfs/_init.lua](https://github.com/nodemcu/nodemcu-firmware/tree/dev/lua_examples/lfs/_init.lua) , running an LFS module is simple a matter of eg: LFS.main() + +[node.flashreload()](../modules/node/#nodeflashreload) need only be rerun if the LFS image is updated; ater it has loaded the LFS image into flash memory the original file (in SPIFFS) is no longer used, and can be deleted. + +Once LFS is known to work, then modules such as [lua_examples/lfs/dummy_strings.lua](https://github.com/nodemcu/nodemcu-firmware/tree/dev/lua_examples/lfs/dummy_strings.lua) can usefully be added, together of course with effective error checking. + [↑ back to matrix](#task-os-selector) From dd3e0ed9887e2ad3498b4d693cc3fecb8a96112a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20St=C3=B6r?= Date: Sat, 22 Jun 2019 00:39:14 +0200 Subject: [PATCH 28/74] Small fixes --- docs/getting-started.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/getting-started.md b/docs/getting-started.md index 3f16c13af5..2f49ba65b9 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -330,7 +330,7 @@ Do a protected call of this `_init` code: `pcall(node.flashindex("_init"))` and Below is a brief overview of building and running the simplest LFS-based system possible. -To use LFS, start with a version of NodeMCU with LUA_FLASH_STORE set in app/include/user_config.h, and load it on the ESP8266 in the usual way (whatever that is for your set up). +To use LFS, start with a version of NodeMCU with `LUA_FLASH_STORE` set in `app/include/user_config.h`, and load it on the ESP8266 in the usual way (whatever that is for your set up). Then build an LFS file system. This can be done in several ways, as discussed above; one of the easiest is to use `luac.cross -f -o lfs.img *lua` on the host machine. The file [lua_examples/lfs/_init.lua](https://github.com/nodemcu/nodemcu-firmware/tree/dev/lua_examples/lfs/_init.lua) should definitely be included in the image, since it's the easiest way of registering the LFS modules. The `lfs.img` file can then be downloaded to the ESP8266 just like any other file. @@ -361,9 +361,9 @@ LFS main() module Note that no error correction has been used, since the commands are intended to be entered at a terminal, and errors will become obvious. -After that, it's a question of setting up the ESP8266 boot process to check for the existence of an LFS image and run whichever module is required. Once the LFS module table has been registered by running [lua_examples/lfs/_init.lua](https://github.com/nodemcu/nodemcu-firmware/tree/dev/lua_examples/lfs/_init.lua) , running an LFS module is simple a matter of eg: LFS.main() +Then you should set up the ESP8266 boot process to check for the existence of an LFS image and run whichever module is required. Once the LFS module table has been registered by running [lua_examples/lfs/_init.lua](https://github.com/nodemcu/nodemcu-firmware/tree/dev/lua_examples/lfs/_init.lua) , running an LFS module is simple a matter of eg: `LFS.main()`. -[node.flashreload()](../modules/node/#nodeflashreload) need only be rerun if the LFS image is updated; ater it has loaded the LFS image into flash memory the original file (in SPIFFS) is no longer used, and can be deleted. +[node.flashreload()](../modules/node/#nodeflashreload) need only be rerun if the LFS image is updated; after it has loaded the LFS image into flash memory the original file (in SPIFFS) is no longer used, and can be deleted. Once LFS is known to work, then modules such as [lua_examples/lfs/dummy_strings.lua](https://github.com/nodemcu/nodemcu-firmware/tree/dev/lua_examples/lfs/dummy_strings.lua) can usefully be added, together of course with effective error checking. From 2d584a2a6ab1a198b2a504b9ab7c5fdbe278ff0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20St=C3=B6r?= Date: Sat, 22 Jun 2019 12:47:14 +0200 Subject: [PATCH 29/74] Fix ROTable call Fixes #2806 --- app/modules/u8g2.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/modules/u8g2.c b/app/modules/u8g2.c index 3758ee7162..a9704b8305 100644 --- a/app/modules/u8g2.c +++ b/app/modules/u8g2.c @@ -807,7 +807,7 @@ U8G2_DISPLAY_TABLE_SPI #undef U8G2_FONT_TABLE_ENTRY #undef U8G2_DISPLAY_TABLE_ENTRY -#define U8G2_DISPLAY_TABLE_ENTRY(function, binding) LROT_FUNCENTRY(#binding,l ## binding) +#define U8G2_DISPLAY_TABLE_ENTRY(function, binding) LROT_FUNCENTRY(binding,l ## binding) LROT_BEGIN(lu8g2) U8G2_DISPLAY_TABLE_I2C U8G2_DISPLAY_TABLE_SPI From 93b1a2dce9c2c293462268968fb7422acc2050a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20St=C3=B6r?= Date: Sat, 22 Jun 2019 22:53:37 +0200 Subject: [PATCH 30/74] Add aka titles --- docs/modules/enduser-setup.md | 2 +- mkdocs.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/modules/enduser-setup.md b/docs/modules/enduser-setup.md index 496dd9d920..9eb367b0b1 100644 --- a/docs/modules/enduser-setup.md +++ b/docs/modules/enduser-setup.md @@ -1,4 +1,4 @@ -# enduser setup Module +# enduser setup Module aka Captive Portal aka WiFi Manager | Since | Origin / Contributor | Maintainer | Source | | :----- | :-------------------- | :---------- | :------ | | 2015-09-02 | [Robert Foss](https://github.com/robertfoss) | [Robert Foss](https://github.com/robertfoss) | [enduser_setup.c](../../app/modules/enduser_setup.c)| diff --git a/mkdocs.yml b/mkdocs.yml index bd79d837ca..4d704d1751 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -69,7 +69,7 @@ pages: - 'crypto': 'modules/crypto.md' - 'dht': 'modules/dht.md' - 'encoder': 'modules/encoder.md' - - 'enduser setup': 'modules/enduser-setup.md' + - 'enduser setup / captive portal / WiFi manager': 'modules/enduser-setup.md' - 'file': 'modules/file.md' - 'gdbstub': 'modules/gdbstub.md' - 'gpio': 'modules/gpio.md' From 7de8a017059b21dda0c0afbd1dd05cece9ce7588 Mon Sep 17 00:00:00 2001 From: galjonsfigur <44552519+galjonsfigur@users.noreply.github.com> Date: Fri, 28 Jun 2019 06:53:19 +0200 Subject: [PATCH 31/74] Add luacheck config and configuration for Travis CI (#2790) * Move luacheck conf and fix Travis for all possible filenames * Add lua script to help with luacheck config * Add xargs approach for current luac.cross file checking * Enable luacheck but do not break build --- .travis.yml | 8 +- CONTRIBUTING.md | 7 + tools/luacheck_config.lua | 883 +++++++++++++++++++++++++++++++ tools/luacheck_config_helper.lua | 139 +++++ tools/travis/localua.sh | 113 ++++ tools/travis/run-luacheck.sh | 17 + 6 files changed, 1164 insertions(+), 3 deletions(-) create mode 100644 tools/luacheck_config.lua create mode 100755 tools/luacheck_config_helper.lua create mode 100755 tools/travis/localua.sh create mode 100644 tools/travis/run-luacheck.sh diff --git a/.travis.yml b/.travis.yml index 6a808926c0..90e27f0edf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,6 +30,8 @@ script: - if [ "$OS" = "windows" ]; then bash "$TRAVIS_BUILD_DIR"/tools/travis/ci-build-windows-ms.sh; fi - if [ "$OS" = "linux" -a "$TRAVIS_PULL_REQUEST" != "false" ]; then bash "$TRAVIS_BUILD_DIR"/tools/travis/pr-build.sh; fi - cd "$TRAVIS_BUILD_DIR" -- LUA_FILES=`find lua_modules lua_examples -iname "*.lua"` -- echo checking $LUA_FILES -- $LUACC -p $LUA_FILES +- echo "checking:" +- find lua_modules lua_examples -iname "*.lua" -print0 | xargs -0 echo +- find lua_modules lua_examples -iname "*.lua" -print0 | xargs -0 $LUACC -p +- if [ "$OS" = "linux" ]; then bash "$TRAVIS_BUILD_DIR"/tools/travis/run-luacheck.sh || true ; fi + diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index faa05ed6a0..2dba89b508 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -26,6 +26,13 @@ Use the platform and tools you feel most comfortable with. There are no constrai - [Full-fledged Linux environment](http://www.esp8266.com/wiki/doku.php?id=toolchain#how_to_setup_a_vm_to_host_your_toolchain), either physical or virtual. - [Docker image](https://hub.docker.com/r/marcelstoer/nodemcu-build/) which allows running the build inside the container as if you were running a build script on your local machine. +## Writing Lua Code +A great resource about writing Lua for NodeMCU can be found in [Lua Developer FAQ](https://nodemcu.readthedocs.io/en/latest/lua-developer-faq/) - make sure to read it! When you're writing your Lua code and it's not working as it should you can test it with `luacheck` tool that can help you find various types of bugs. To install it you have to install [luarocks](https://luarocks.org/) and use command `sudo luarocks install luacheck` to install the tool. Now you're ready to go! By using this command (assuming you're in `nodemcu-firmware` directory): + +`luacheck --config tools/luacheck_config.lua ` + +you can look for bugs and problems within the code! + ## Writing Documentation The NodeMCU documentation is maintained within the same repository as the code. The primary reason is to keep the two in sync more easily. It's thus trivial for the NodeMCU team to verify that a PR includes the necessary documentation. Furthermore, the documentation is merged automatically with the code if it moves from branch X to Y. diff --git a/tools/luacheck_config.lua b/tools/luacheck_config.lua new file mode 100644 index 0000000000..34a8b6eb59 --- /dev/null +++ b/tools/luacheck_config.lua @@ -0,0 +1,883 @@ +local empty = { } +local read_write = {read_only = false} + +stds.nodemcu_libs = { + read_globals = { + adc = { + fields = { + INIT_ADC = empty, + INIT_VDD33 = empty, + force_init_mode = empty, + read = empty, + readvdd33 = empty + } + }, + ads1115 = { + fields = { + ADDR_GND = empty, + ADDR_SCL = empty, + ADDR_SDA = empty, + ADDR_VDD = empty, + CMODE_TRAD = empty, + CMODE_WINDOW = empty, + COMP_1CONV = empty, + COMP_2CONV = empty, + COMP_4CONV = empty, + CONTINUOUS = empty, + CONV_RDY_1 = empty, + CONV_RDY_2 = empty, + CONV_RDY_4 = empty, + DIFF_0_1 = empty, + DIFF_0_3 = empty, + DIFF_1_3 = empty, + DIFF_2_3 = empty, + DR_128SPS = empty, + DR_1600SPS = empty, + DR_16SPS = empty, + DR_2400SPS = empty, + DR_250SPS = empty, + DR_32SPS = empty, + DR_3300SPS = empty, + DR_475SPS = empty, + DR_490SPS = empty, + DR_64SPS = empty, + DR_860SPS = empty, + DR_8SPS = empty, + DR_920SPS = empty, + GAIN_0_256V = empty, + GAIN_0_512V = empty, + GAIN_1_024V = empty, + GAIN_2_048V = empty, + GAIN_4_096V = empty, + GAIN_6_144V = empty, + SINGLE_0 = empty, + SINGLE_1 = empty, + SINGLE_2 = empty, + SINGLE_3 = empty, + SINGLE_SHOT = empty, + ads1015 = empty, + ads1115 = empty, + read = empty, + reset = empty, + } + }, + adxl345 = { + fields = { + read = empty, + setup = empty + } + }, + am2320 = { + fields = { + read = empty, + setup = empty + } + }, + apa102 = { + fields = { + write = empty + } + }, + bit = { + fields = { + arshift = empty, + band = empty, + bit = empty, + bnot = empty, + bor = empty, + bxor = empty, + clear = empty, + isclear = empty, + isset = empty, + lshift = empty, + rshift = empty, + set = empty + } + }, + bloom = { + fields = { + create = empty + } + }, + bme280 = { + fields = { + altitude = empty, + baro = empty, + dewpoint = empty, + humi = empty, + qfe2qnh = empty, + read = empty, + setup = empty, + startreadout = empty, + temp = empty + } + }, + bme680 = { + fields = { + altitude = empty, + dewpoint = empty, + qfe2qnh = empty, + read = empty, + setup = empty, + startreadout = empty + } + }, + bmp085 = { + fields = { + pressure = empty, + pressure_raw = empty, + setup = empty, + temperature = empty + } + }, + coap = { + fields = { + CON = empty, + Client = empty, + EXI = empty, + JSON = empty, + LINKFORMAT = empty, + NON = empty, + OCTET_STREAM = empty, + Server = empty, + TEXT_PLAIN = empty, + XML = empty + } + }, + color_utils = { + fields = { + colorWheel = empty, + grb2hsv = empty, + hsv2grb = empty, + hsv2grbw = empty + } + }, + cron = { + fields = { + reset = empty, + schedule = empty + } + }, + crypto = { + fields = { + decrypt = empty, + encrypt = empty, + fhash = empty, + hash = empty, + hmac = empty, + mask = empty, + new_hash = empty, + new_hmac = empty, + sha1 = empty, + toBase64 = empty, + toHex = empty + } + }, + dht = { + fields = { + ERROR_CHECKSUM = empty, + ERROR_TIMEOUT = empty, + OK = empty, + read = empty, + read11 = empty, + readxx = empty + } + }, + encoder = { + fields = { + fromBase64 = empty, + fromHex = empty, + toBase64 = empty, + toHex = empty + } + }, + enduser_setup = { + fields = { + manual = empty, + start = empty, + stop = empty + } + }, + file = { + fields = { + close = empty, + exists = empty, + flush = empty, + fsinfo = empty, + getcontents = empty, + list = empty, + on = empty, + open = empty, + putcontents = empty, + read = empty, + readline = empty, + remove = empty, + rename = empty, + seek = empty, + stat = empty, + write = empty, + writeline = empty + } + }, + gdbstub = { + fields = { + brk = empty, + gdboutput = empty, + open = empty + } + }, + gpio = { + fields = { + FLOAT = empty, + HIGH = empty, + INPUT = empty, + INT = empty, + LOW = empty, + OPENDRAIN = empty, + OUTPUT = empty, + PULLUP = empty, + mode = empty, + read = empty, + serout = empty, + trig = empty, + write = empty, + pulse = { + fields = { + adjust = empty, + cancel = empty, + getstate = empty, + start = empty, + stop = empty, + update = empty + } + } + } + }, + hdc1080 = { + fields = { + read = empty, + setup = empty + } + }, + hmc5883 = { + fields = { + read = empty, + setup = empty + } + }, + http = { + fields = { + ERROR = empty, + OK = empty, + delete = empty, + get = empty, + post = empty, + put = empty, + request = empty + } + }, + hx711 = { + fields = { + init = empty, + read = empty + } + }, + i2c = { + fields = { + FAST = empty, + FASTPLUS = empty, + RECEIVER = empty, + SLOW = empty, + TRANSMITTER = empty, + address = empty, + read = empty, + setup = empty, + start = empty, + stop = empty, + write = empty + } + }, + l3g4200d = { + fields = { + read = empty, + setup = empty + } + }, + mcp4725 = { + fields = { + PWRDN_100K = empty, + PWRDN_1K = empty, + PWRDN_500K = empty, + PWRDN_NONE = empty, + read = empty, + write = empty + } + }, + mdns = { + fields = { + close = empty, + register = empty + } + }, + mqtt = { + fields = { + CONNACK_ACCEPTED = empty, + CONNACK_REFUSED_BAD_USER_OR_PASS = empty, + CONNACK_REFUSED_ID_REJECTED = empty, + CONNACK_REFUSED_NOT_AUTHORIZED = empty, + CONNACK_REFUSED_PROTOCOL_VER = empty, + CONNACK_REFUSED_SERVER_UNAVAILABLE = empty, + CONN_FAIL_DNS = empty, + CONN_FAIL_NOT_A_CONNACK_MSG = empty, + CONN_FAIL_SERVER_NOT_FOUND = empty, + CONN_FAIL_TIMEOUT_RECEIVING = empty, + CONN_FAIL_TIMEOUT_SENDING = empty, + Client = empty + } + }, + net = { + fields = { + TCP = empty, + UDP = empty, + cert = empty, + createConnection = empty, + createServer = empty, + createUDPSocket = empty, + dns = { + fields = { + getdnsserver = empty, + resolve = empty, + setdnsserver = empty + } + }, + multicastJoin = empty, + multicastLeave = empty + } + }, + node = { + fields = { + CPU160MHZ = empty, + CPU80MHZ = empty, + bootreason = empty, + chipid = empty, + compile = empty, + dsleep = empty, + dsleepMax = empty, + dsleepsetoption = empty, + flashid = empty, + flashindex = empty, + flashreload = empty, + flashsize = empty, + getcpufreq = empty, + getpartitiontable = empty, + heap = empty, + info = empty, + input = empty, + osprint = empty, + output = empty, + random = empty, + readrcr = empty, + readvdd33 = empty, + restart = empty, + restore = empty, + setcpufreq = empty, + setpartitiontable = empty, + sleep = empty, + stripdebug = empty, + writercr = empty, + egc = { + fields = { + setmode = empty, + meminfo = empty + } + }, + task = { + fields = { + post = empty + } + } + } + }, + ow = { + fields = { + check_crc16 = empty, + crc16 = empty, + crc8 = empty, + depower = empty, + read = empty, + read_bytes = empty, + reset = empty, + reset_search = empty, + search = empty, + select = empty, + setup = empty, + skip = empty, + target_search = empty, + write = empty, + write_bytes = empty + } + }, + pcm = { + fields = { + RATE_10K = empty, + RATE_12K = empty, + RATE_16K = empty, + RATE_1K = empty, + RATE_2K = empty, + RATE_4K = empty, + RATE_5K = empty, + RATE_8K = empty, + SD = empty, + new = empty + } + }, + pwm = { + fields = { + close = empty, + getclock = empty, + getduty = empty, + setclock = empty, + setduty = empty, + setup = empty, + start = empty, + stop = empty + } + }, + pwm2 = { + fields = { + get_pin_data = empty, + get_timer_data = empty, + release_pin = empty, + set_duty = empty, + setup_pin_hz = empty, + setup_pin_sec = empty, + start = empty, + stop = empty, + } + }, + rc = { + fields = { + send = empty + } + }, + rfswitch = { + fields = { + send = empty + } + }, + rotary = { + fields = { + ALL = empty, + CLICK = empty, + DBLCLICK = empty, + LONGPRESS = empty, + PRESS = empty, + RELEASE = empty, + TURN = empty, + close = empty, + getpos = empty, + on = empty, + setup = empty + } + }, + rtcfifo = { + fields = { + count = empty, + drop = empty, + dsleep_until_sample = empty, + peek = empty, + pop = empty, + prepare = empty, + put = empty, + ready = empty + } + }, + rtcmem = { + fields = { + read32 = empty, + write32 = empty + } + }, + rtctime = { + fields = { + adjust_delta = empty, + dsleep = empty, + dsleep_aligned = empty, + epoch2cal = empty, + get = empty, + set = empty + } + }, + si7021 = { + fields = { + HEATER_DISABLE = empty, + HEATER_ENABLE = empty, + RH08_TEMP12 = empty, + RH10_TEMP13 = empty, + RH11_TEMP11 = empty, + RH12_TEMP14 = empty, + firmware = empty, + read = empty, + serial = empty, + setting = empty, + setup = empty + } + }, + sigma_delta = { + fields = { + close = empty, + setprescale = empty, + setpwmduty = empty, + settarget = empty, + setup = empty + } + }, + sjson = { + fields = { + decode = empty, + decoder = empty, + encode = empty, + encoder = empty + } + }, + sntp = { + fields = { + getoffset = empty, + setoffset = empty, + sync = empty + } + }, + somfy = { + fields = { + DOWN = empty, + PROG = empty, + STOP = empty, + UP = empty, + sendcommand = empty + } + }, + spi = { + fields = { + CPHA_HIGH = empty, + CPHA_LOW = empty, + CPOL_HIGH = empty, + CPOL_LOW = empty, + DATABITS_8 = empty, + FULLDUPLEX = empty, + HALFDUPLEX = empty, + MASTER = empty, + SLAVE = empty, + get_miso = empty, + recv = empty, + send = empty, + set_clock_div = empty, + set_mosi = empty, + setup = empty, + transaction = empty + } + }, + switec = { + fields = { + close = empty, + dequeue = empty, + getpos = empty, + moveto = empty, + reset = empty, + setup = empty + } + }, + tcs34725 = { + fields = { + disable = empty, + enable = empty, + raw = empty, + setGain = empty, + setIntegrationTime = empty, + setup = empty + } + }, + tls = { + fields = { + createConnection = empty, + setDebug = empty, + cert = { + fields = { + auth = empty, + verify = empty + } + } + } + }, + tm1829 = { + fields = { + write = empty + } + }, + tmr = { + fields = { + ALARM_AUTO = empty, + ALARM_SEMI = empty, + ALARM_SINGLE = empty, + create = empty, + delay = empty, + now = empty, + resume_all = empty, + softwd = empty, + suspend_all = empty, + time = empty, + wdclr = empty + } + }, + tsl2561 = { + fields = { + ADDRESS_FLOAT = empty, + ADDRESS_GND = empty, + ADDRESS_VDD = empty, + GAIN_16X = empty, + GAIN_1X = empty, + INTEGRATIONTIME_101MS = empty, + INTEGRATIONTIME_13MS = empty, + INTEGRATIONTIME_402MS = empty, + PACKAGE_CS = empty, + PACKAGE_T_FN_CL = empty, + TSL2561_ERROR_I2CBUSY = empty, + TSL2561_ERROR_I2CINIT = empty, + TSL2561_ERROR_LAST = empty, + TSL2561_ERROR_NOINIT = empty, + TSL2561_OK = empty, + getlux = empty, + getrawchannels = empty, + init = empty, + settiming = empty + } + }, + -- There would be too many fields for all the fonts and displays + u8g2 = {other_fields = true}, + uart = { + fields = { + PARITY_EVEN = empty, + PARITY_NONE = empty, + PARITY_ODD = empty, + STOPBITS_1 = empty, + STOPBITS_1_5 = empty, + STOPBITS_2 = empty, + alt = empty, + getconfig = empty, + on = empty, + setup = empty, + write = empty + } + }, + -- There would be too many fields for all the fonts and displays + ucg = {other_fields = true}, + websocket = { + fields = { + createClient = empty + } + }, + wifi = { + fields = { + COUNTRY_AUTO = empty, + COUNTRY_MANUAL = empty, + LIGHT_SLEEP = empty, + MODEM_SLEEP = empty, + NONE_SLEEP = empty, + NULLMODE = empty, + OPEN = empty, + PHYMODE_B = empty, + PHYMODE_G = empty, + PHYMODE_N = empty, + SOFTAP = empty, + STATION = empty, + STATIONAP = empty, + STA_APNOTFOUND = empty, + STA_CONNECTING = empty, + STA_FAIL = empty, + STA_GOTIP = empty, + STA_IDLE = empty, + STA_WRONGPWD = empty, + WEP = empty, + WPA2_PSK = empty, + WPA_PSK = empty, + WPA_WPA2_PSK = empty, + getchannel = empty, + getcountry = empty, + getdefaultmode = empty, + getmode = empty, + getphymode = empty, + nullmodesleep = empty, + resume = empty, + setcountry = empty, + setmaxtxpower = empty, + setmode = empty, + setphymode = empty, + sleeptype = empty, + startsmart = empty, + stopsmart = empty, + suspend = empty, + sta = { + fields = { + autoconnect = empty, + changeap = empty, + clearconfig = empty, + config = empty, + connect = empty, + disconnect = empty, + getap = empty, + getapindex = empty, + getapinfo = empty, + getbroadcast = empty, + getconfig = empty, + getdefaultconfig = empty, + gethostname = empty, + getip = empty, + getmac = empty, + getrssi = empty, + setaplimit = empty, + sethostname = empty, + setip = empty, + setmac = empty, + sleeptype = empty, + status = empty + } + }, + ap = { + fields = { + config = empty, + deauth = empty, + getbroadcast = empty, + getclient = empty, + getconfig = empty, + getdefaultconfig = empty, + getip = empty, + getmac = empty, + setip = empty, + setmac = empty, + dhcp = { + fields = { + config = empty, + start = empty, + stop = empty + } + }, + } + }, + eventmon = { + fields = { + AP_PROBEREQRECVED = empty, + AP_STACONNECTED = empty, + AP_STADISCONNECTED = empty, + EVENT_MAX = empty, + STA_AUTHMODE_CHANGE = empty, + STA_CONNECTED = empty, + STA_DHCP_TIMEOUT = empty, + STA_DISCONNECTED = empty, + STA_GOT_IP = empty, + WIFI_MODE_CHANGED = empty, + register = empty, + unregister = empty, + reason = { + fields = { + ["4WAY_HANDSHAKE_TIMEOUT"] = empty, + ["802_1X_AUTH_FAILED"] = empty, + AKMP_INVALID = empty, + ASSOC_EXPIRE = empty, + ASSOC_FAIL = empty, + ASSOC_LEAVE = empty, + ASSOC_NOT_AUTHED = empty, + ASSOC_TOOMANY = empty, + AUTH_EXPIRE = empty, + AUTH_FAIL = empty, + AUTH_LEAVE = empty, + BEACON_TIMEOUT = empty, + CIPHER_SUITE_REJECTED = empty, + DISASSOC_PWRCAP_BAD = empty, + DISASSOC_SUPCHAN_BAD = empty, + GROUP_CIPHER_INVALID = empty, + GROUP_KEY_UPDATE_TIMEOUT = empty, + HANDSHAKE_TIMEOUT = empty, + IE_INVALID = empty, + IE_IN_4WAY_DIFFERS = empty, + INVALID_RSN_IE_CAP = empty, + MIC_FAILURE = empty, + NOT_ASSOCED = empty, + NOT_AUTHED = empty, + NO_AP_FOUND = empty, + PAIRWISE_CIPHER_INVALID = empty, + UNSPECIFIED = empty, + UNSUPP_RSN_IE_VERSION = empty + } + } + } + }, + monitor = { + fields = { + channel = empty, + start = empty, + stop = empty + } + } + } + }, + wps = { + fields = { + FAILED = empty, + SCAN_ERR = empty, + SUCCESS = empty, + TIMEOUT = empty, + WEP = empty, + disable = empty, + enable = empty, + start = empty + } + }, + ws2801 = { + fields = { + init = empty, + write = empty + } + }, + ws2812 = { + fields = { + FADE_IN = empty, + FADE_OUT = empty, + MODE_DUAL = empty, + MODE_SINGLE = empty, + SHIFT_CIRCULAR = empty, + SHIFT_LOGICAL = empty, + init = empty, + newBuffer = empty, + write = empty + } + }, + ws2812_effects = { + fields = { + get_delay = empty, + get_speed = empty, + init = empty, + set_brightness = empty, + set_color = empty, + set_delay = empty, + set_mode = empty, + set_speed = empty, + start = empty, + stop = empty + } + }, + xpt2046 = { + fields = { + getPosition = empty, + getPositionAvg = empty, + getRaw = empty, + init = empty, + isTouched = empty, + setCalibration = empty + } + }, + pack = empty, + unpack = empty, + size = empty + } +} + +std = "lua51+nodemcu_libs" \ No newline at end of file diff --git a/tools/luacheck_config_helper.lua b/tools/luacheck_config_helper.lua new file mode 100755 index 0000000000..f7b5bb2e62 --- /dev/null +++ b/tools/luacheck_config_helper.lua @@ -0,0 +1,139 @@ +#!/usr/bin/lua + +--- +-- Script to extract names and the functions themselves from NodeMCU modules and +-- to help creating luacheck configuration. +-- Usage: ../../tools/luacheck_config_helper.lua *.c (or filename for single module) + +local M = {} + +-- Recursive object dumper, for debugging. +-- (c) 2010 David Manura, MIT License. +-- From: https://github.com/davidm/lua-inspect/blob/master/lib/luainspect/dump.lua +local ignore_keys_ = {lineinfo = true} +local norecurse_keys_ = {parent = true, ast = true} +local function dumpstring_key_(k, isseen, newindent) + local ks = type(k) == 'string' and k:match'^[%a_][%w_]*$' and k or + '[' .. M.dumpstring(k, isseen, newindent) .. ']' + return ks +end + +local function sort_keys_(a, b) + if type(a) == 'number' and type(b) == 'number' then + return a < b + elseif type(a) == 'number' then + return false + elseif type(b) == 'number' then + return true + elseif type(a) == 'string' and type(b) == 'string' then + return a < b + else + return tostring(a) < tostring(b) -- arbitrary + end +end + +function M.dumpstring(o, isseen, indent, key) + isseen = isseen or {} + indent = indent or '' + + if type(o) == 'table' then + if isseen[o] or norecurse_keys_[key] then + return (type(o.tag) == 'string' and '`' .. o.tag .. ':' or '') .. tostring(o) + else isseen[o] = true end -- avoid recursion + + local used = {} + + local tag = o.tag + local s = '{' + if type(o.tag) == 'string' then + s = '`' .. tag .. s; used['tag'] = true + end + local newindent = indent .. ' ' + + local ks = {}; for k in pairs(o) do ks[#ks+1] = k end + table.sort(ks, sort_keys_) + + local forcenummultiline + for k in pairs(o) do + if type(k) == 'number' and type(o[k]) == 'table' then forcenummultiline = true end + end + + -- inline elements + for _,k in ipairs(ks) do + if ignore_keys_[k] then used[k] = true + elseif (type(k) ~= 'number' or not forcenummultiline) and + type(k) ~= 'table' and (type(o[k]) ~= 'table' or norecurse_keys_[k]) + then + s = s .. dumpstring_key_(k, isseen, newindent) .. ' = ' .. M.dumpstring(o[k], isseen, newindent, k) .. ', ' + used[k] = true + end + end + + -- elements on separate lines + local done + for _,k in ipairs(ks) do + if not used[k] then + if not done then s = s .. '\n'; done = true end + s = s .. newindent .. dumpstring_key_(k, isseen) .. ' = ' .. M.dumpstring(o[k], isseen, newindent, k) .. ',\n' + end + end + s = s:gsub(',(%s*)$', '%1') + s = s .. (done and indent or '') .. '}' + return s + elseif type(o) == 'string' then + return string.format('%q', o) + else + return tostring(o) + end +end +-- End of dump.lua code + +local function printTables(fileName) + + local findBegin, field + if type(fileName) ~= "string" then error("Wrong argument") end + local file = io.open(fileName, "r") + if not file then error("Can't open file") end + local result = {} + result.fields = {} + + for line in file:lines() do + findBegin, _, field = string.find(line, "LROT_BEGIN%((%g+)%)") + if findBegin then + io.write(field.." = ") + end + findBegin, _, field = string.find(line, "LROT_PUBLIC_BEGIN%((%g+)%)") + if findBegin then + print(field.." = ") + end + + findBegin, _, field = string.find(line, "LROT_FUNCENTRY%(%s?(%g+),") + if not findBegin then + findBegin, _, field = string.find(line, "LROT_NUMENTRY%(%s?(%g+),") + end + if not findBegin then + findBegin, _, field = string.find(line, "LROT_TABENTRY%(%s?(%g+),") + end + + if findBegin then + if not string.find(field, "__") then + result.fields[field] = {} + end + end + + findBegin = string.find(line, "LROT_END") + if findBegin then + print(string.gsub(M.dumpstring(result), "{}", "empty")..',') + result = {} + result.fields = {} + end + end +end + +local function main() + for i = 1, #arg do + printTables(arg[i]) + end +end + +main() \ No newline at end of file diff --git a/tools/travis/localua.sh b/tools/travis/localua.sh new file mode 100755 index 0000000000..124a2fe556 --- /dev/null +++ b/tools/travis/localua.sh @@ -0,0 +1,113 @@ +#!/bin/bash + +# Downloads and installs a self-contained Lua and LuaRocks. +# Supports Linux, macOS and MSYS2. +# Copyright (c) 2015-2019 Pierre Chapuis, MIT Licensed. +# Latest stable version available at: https://loadk.com/localua.sh +# Maintained at: https://github.com/oploadk/localua + +DEFAULT_LUA_V="5.3.5" +DEFAULT_LR_V="3.0.4" + +usage () { + >&2 echo -e "USAGE: $0 output-dir [lua-version] [luarocks-version]\n" + >&2 echo -n "The first optional argument is the Lua version, " + >&2 echo -n "the second one is the LuaRocks version. " + >&2 echo -e "Defaults are Lua $DEFAULT_LUA_V and LuaRocks $DEFAULT_LR_V.\n" + >&2 echo -n "You can set a custom build directory with environment " + >&2 echo -e "variable LOCALUA_BUILD_DIRECTORY (not useful in general).\n" + >&2 echo -e "You can set a custom makefile target with LOCALUA_TARGET.\n" + >&2 echo -e "You can disable LUA_COMPAT by setting LOCALUA_NO_COMPAT.\n" + >&2 echo -e "You can skip luarocks by setting LOCALUA_NO_LUAROCKS." + exit 1 +} + +# Set output directory, Lua version and LuaRocks version + +ODIR="$1" +[ -z "$ODIR" ] && usage + +LUA_V="$2" +[ -z "$LUA_V" ] && LUA_V="$DEFAULT_LUA_V" + +LUA_SHORTV="$(echo $LUA_V | cut -c 1-3)" + +LR_V="$3" +[ -z "$LR_V" ] && LR_V="$DEFAULT_LR_V" + +# Set build directory + +BDIR="$LOCALUA_BUILD_DIRECTORY" +[ -z "$BDIR" ] && BDIR="$(mktemp -d /tmp/localua-XXXXXX)" + +# Create output directory and get absolute path + +mkdir -p "$ODIR" +>/dev/null pushd "$ODIR" + ODIR="$(pwd)" +>/dev/null popd + +# Download, unpack and build Lua and LuaRocks + +if [ -z "$LOCALUA_TARGET" ]; then + case "$(uname)" in + Linux) + LOCALUA_TARGET="linux";; + Darwin) + LOCALUA_TARGET="macosx";; + MSYS*) + LOCALUA_TARGET="msys";; + *) + LOCALUA_TARGET="posix";; + esac +fi + +pushd "$BDIR" + wget "http://www.lua.org/ftp/lua-${LUA_V}.tar.gz" + tar xf "lua-${LUA_V}.tar.gz" + pushd "lua-${LUA_V}" + sed 's#"/usr/local/"#"'"$ODIR"'/"#' "src/luaconf.h" > "$BDIR/t" + mv "$BDIR/t" "src/luaconf.h" + if [ ! -z "$LOCALUA_NO_COMPAT" ]; then + sed 's#-DLUA_COMPAT_5_2##' "src/Makefile" > "$BDIR/t" + sed 's#-DLUA_COMPAT_ALL##' "$BDIR/t" > "src/Makefile" + fi + + if [ "$LOCALUA_TARGET" = "msys" ]; then + >> "src/Makefile" echo + >> "src/Makefile" echo 'msys:' >> "src/Makefile" + >> "src/Makefile" echo -ne "\t" + >> "src/Makefile" echo '$(MAKE) "LUA_A=lua53.dll" "LUA_T=lua.exe" \' + >> "src/Makefile" echo -ne "\t" + >> "src/Makefile" echo '"AR=$(CC) -shared -Wl,--out-implib,liblua.dll.a -o" "RANLIB=strip --strip-unneeded" \' + >> "src/Makefile" echo -ne "\t" + >> "src/Makefile" echo '"SYSCFLAGS=-DLUA_BUILD_AS_DLL -DLUA_USE_POSIX -DLUA_USE_DLOPEN" "SYSLIBS=" "SYSLDFLAGS=-s" lua.exe' + >> "src/Makefile" echo -ne "\t" + >> "src/Makefile" echo '$(MAKE) "LUAC_T=luac.exe" luac.exe' + + make -C src "$LOCALUA_TARGET" || exit 1 + make \ + TO_BIN="lua.exe luac.exe lua53.dll" \ + TO_LIB="liblua.a liblua.dll.a" \ + INSTALL_TOP="$ODIR" install || exit 1 + else + make "$LOCALUA_TARGET" || exit 1 + make INSTALL_TOP="$ODIR" install || exit 1 + fi + + popd + if [ -z "$LOCALUA_NO_LUAROCKS" ]; then + wget "http://luarocks.org/releases/luarocks-${LR_V}.tar.gz" + tar xf "luarocks-${LR_V}.tar.gz" + pushd "luarocks-${LR_V}" + ./configure --with-lua="$ODIR" --prefix="$ODIR" \ + --lua-version="$LUA_SHORTV" \ + --sysconfdir="$ODIR/luarocks" --force-config + make bootstrap + popd + fi +popd + +# Cleanup + +rm -rf "$BDIR" diff --git a/tools/travis/run-luacheck.sh b/tools/travis/run-luacheck.sh new file mode 100644 index 0000000000..d97241f715 --- /dev/null +++ b/tools/travis/run-luacheck.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +set -e + +echo "Installing Lua 5.3, LuaRocks and Luacheck" +( + cd "$TRAVIS_BUILD_DIR" || exit + bash tools/travis/localua.sh cache/localua || exit + cache/localua/bin/luarocks install luacheck || exit +) + +( + echo "Static analysys of:" + find lua_modules lua_examples -iname "*.lua" -print0 | xargs -0 echo +) + +(find lua_modules lua_examples -iname "*.lua" -print0 | xargs -0 cache/localua/bin/luacheck --config tools/luacheck_config.lua) || exit From bc7ffb3eb84cf73000a27f7345f9a69c2f7d54cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arnim=20L=C3=A4uger?= Date: Fri, 5 Jul 2019 07:55:54 +0200 Subject: [PATCH 32/74] fix unref default file descriptor while still in use (#2818) --- app/modules/file.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/app/modules/file.c b/app/modules/file.c index 4ed4f37c98..be5cdf44ef 100644 --- a/app/modules/file.c +++ b/app/modules/file.c @@ -126,15 +126,16 @@ static int file_close( lua_State* L ) ud = (file_fd_ud *)luaL_checkudata(L, 1, "file.obj"); } - // unref default file descriptor - luaL_unref( L, LUA_REGISTRYINDEX, file_fd_ref ); - file_fd_ref = LUA_NOREF; - if(ud->fd){ vfs_close(ud->fd); // mark as closed ud->fd = 0; } + + // unref default file descriptor + luaL_unref( L, LUA_REGISTRYINDEX, file_fd_ref ); + file_fd_ref = LUA_NOREF; + return 0; } From 0398c3360bf09cf3c4a4af900586b317cc43ad1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20St=C3=B6r?= Date: Mon, 8 Jul 2019 21:48:16 +0200 Subject: [PATCH 33/74] Save the post data in a file on the filesystem (#2810) * Use cross-browser JS for query params in EUS * Update EUS doc to explain how to use parameters * Remove ; in Lua code * Rewrite the endpoint table * Do not use properties as global Lua variables * remove enduser_setup.html.gz * rename folder 'eus' to 'enduser_setup' * Change input type for password to "password" * Replace outdated captive portal screen shot --- app/modules/enduser_setup.c | 249 +++++++++++++++--- app/modules/enduser_setup/.gitattributes | 1 + app/modules/enduser_setup/.gitignore | 1 + .../{eus => enduser_setup}/enduser_setup.html | 54 ++-- .../enduser_setup/enduser_setup.html.gz.def.h | 218 +++++++++++++++ app/modules/{eus => enduser_setup}/prepare.sh | 2 +- app/modules/eus/enduser_setup.html.gz | Bin 2423 -> 0 bytes app/modules/eus/http_html_backup.def | 205 -------------- docs/img/enduser-setup-captive-portal.png | Bin 0 -> 34739 bytes docs/img/enduser-setup.jpg | Bin 35554 -> 0 bytes docs/modules/enduser-setup.md | 114 ++++++-- 11 files changed, 547 insertions(+), 297 deletions(-) create mode 100644 app/modules/enduser_setup/.gitattributes create mode 100644 app/modules/enduser_setup/.gitignore rename app/modules/{eus => enduser_setup}/enduser_setup.html (83%) create mode 100644 app/modules/enduser_setup/enduser_setup.html.gz.def.h rename app/modules/{eus => enduser_setup}/prepare.sh (65%) delete mode 100644 app/modules/eus/enduser_setup.html.gz delete mode 100644 app/modules/eus/http_html_backup.def create mode 100644 docs/img/enduser-setup-captive-portal.png delete mode 100644 docs/img/enduser-setup.jpg diff --git a/app/modules/enduser_setup.c b/app/modules/enduser_setup.c index a03a87b0ee..addef5f436 100644 --- a/app/modules/enduser_setup.c +++ b/app/modules/enduser_setup.c @@ -93,6 +93,7 @@ static const char http_html_filename[] = "enduser_setup.html"; static const char http_header_200[] = "HTTP/1.1 200 OK\r\nCache-control:no-cache\r\nConnection:close\r\nContent-Type:text/html\r\n"; /* Note single \r\n here! */ static const char http_header_204[] = "HTTP/1.1 204 No Content\r\nContent-Length:0\r\nConnection:close\r\n\r\n"; static const char http_header_302[] = "HTTP/1.1 302 Moved\r\nLocation: /\r\nContent-Length:0\r\nConnection:close\r\n\r\n"; +static const char http_header_302_trying[] = "HTTP/1.1 302 Moved\r\nLocation: /?trying=true\r\nContent-Length:0\r\nConnection:close\r\n\r\n"; static const char http_header_400[] = "HTTP/1.1 400 Bad request\r\nContent-Length:0\r\nConnection:close\r\n\r\n"; static const char http_header_404[] = "HTTP/1.1 404 Not found\r\nContent-Length:0\r\nConnection:close\r\n\r\n"; static const char http_header_405[] = "HTTP/1.1 405 Method Not Allowed\r\nContent-Length:0\r\nConnection:close\r\n\r\n"; @@ -101,8 +102,8 @@ static const char http_header_500[] = "HTTP/1.1 500 Internal Error\r\nContent-Le static const char http_header_content_len_fmt[] = "Content-length:%5d\r\n\r\n"; static const char http_html_gzip_contentencoding[] = "Content-Encoding: gzip\r\n"; -/* Externally defined: static const char http_html_backup[] = ... */ -#include "eus/http_html_backup.def" +/* Externally defined: static const char enduser_setup_html_default[] = ... */ +#include "enduser_setup/enduser_setup.html.gz.def.h" typedef struct scan_listener { @@ -398,9 +399,9 @@ static err_t close_once_sent (void *arg, struct tcp_pcb *pcb, u16_t len) /** * Search String * - * Search string for first occurance of any char in srch_str. + * Search string for first occurence of any char in srch_str. * - * @return -1 iff no occurance of char was found. + * @return -1 if no occurence of char was found. */ static int enduser_setup_srch_str(const char *str, const char *srch_str) { @@ -418,9 +419,9 @@ static int enduser_setup_srch_str(const char *str, const char *srch_str) /** * Load HTTP Payload * - * @return - 0 iff payload loaded successfully - * 1 iff backup html was loaded - * 2 iff out of memory + * @return - 0 if payload loaded successfully + * 1 if default html was loaded + * 2 if out of memory */ static int enduser_setup_http_load_payload(void) { @@ -466,16 +467,16 @@ static int enduser_setup_http_load_payload(void) if (!f || err == VFS_RES_ERR || err2 == VFS_RES_ERR) { - ENDUSER_SETUP_DEBUG("Unable to load file enduser_setup.html, loading backup HTML..."); + ENDUSER_SETUP_DEBUG("Unable to load file enduser_setup.html, loading default HTML..."); - c_sprintf(cl_hdr, http_header_content_len_fmt, sizeof(http_html_backup)); + c_sprintf(cl_hdr, http_header_content_len_fmt, sizeof(enduser_setup_html_default)); cl_len = c_strlen(cl_hdr); - int html_len = LITLEN(http_html_backup); + int html_len = LITLEN(enduser_setup_html_default); - if (http_html_backup[0] == 0x1f && http_html_backup[1] == 0x8b) + if (enduser_setup_html_default[0] == 0x1f && enduser_setup_html_default[1] == 0x8b) { ce_len = c_strlen(http_html_gzip_contentencoding); - html_len = http_html_backup_len; /* Defined in eus/http_html_backup.def by xxd -i */ + html_len = enduser_setup_html_default_len; /* Defined in enduser_setup/enduser_setup.html.gz.def.h by xxd -i */ ENDUSER_SETUP_DEBUG("Content is gzipped"); } @@ -499,7 +500,7 @@ static int enduser_setup_http_load_payload(void) c_memcpy(&(state->http_payload_data[offset]), &(cl_hdr), cl_len); offset += cl_len; - c_memcpy(&(state->http_payload_data[offset]), &(http_html_backup), sizeof(http_html_backup)); + c_memcpy(&(state->http_payload_data[offset]), &(enduser_setup_html_default), sizeof(enduser_setup_html_default)); return 1; } @@ -548,7 +549,7 @@ static int enduser_setup_http_load_payload(void) * * Parse escaped and form encoded data of request. * - * @return - return 0 iff the HTTP parameter is decoded into a valid string. + * @return - return 0 if the HTTP parameter is decoded into a valid string. */ static int enduser_setup_http_urldecode(char *dst, const char *src, int src_len, int dst_len) { @@ -631,13 +632,167 @@ static void do_station_cfg (task_param_t param, uint8_t prio) luaM_free(lua_getstate(), cnf); } +/** + * Count the number of occurences of a character in a string + * + * return the number of times the character was encountered in the string + */ +static int count_char_occurence(const char *input, const char char_to_count) { + const char *current = input; + int occur = 0; + while (*current != 0) { + if (*current == char_to_count) occur++; + current++; + } + return occur; +} + +/* structure used to store the key/value pairs that we find in a HTTP POST body */ +struct keypairs_t { + char **keypairs; + int keypairs_nb; +}; + +static void enduser_setup_free_keypairs(struct keypairs_t *kp) { + if (kp == NULL) return; + + if (kp->keypairs != NULL) { + for (int i = 0; i < kp->keypairs_nb * 2; i++) { + os_free(kp->keypairs[i]); + } + } + os_free(kp->keypairs); + os_free(kp); +} + +static struct keypairs_t * enduser_setup_alloc_keypairs(int kp_number ){ + struct keypairs_t *kp = os_malloc(sizeof(struct keypairs_t)); + os_memset(kp, 0, sizeof(struct keypairs_t)); + + kp->keypairs = os_malloc(kp_number * 2 * sizeof(char *)); + kp->keypairs_nb = kp_number; + return kp; +} + +/** + * Parses a form-urlencoded body into a struct keypairs_t, which contains an array of key,values strings and the size of the array. + */ +static struct keypairs_t *enduser_setup_get_keypairs_from_form(char *form_body, int form_length) { + int keypair_nb = count_char_occurence(form_body, '&') + 1; + int equal_nb = count_char_occurence(form_body, '='); + + if (keypair_nb == 1 && equal_nb == 0) { + ENDUSER_SETUP_DEBUG("No keypair in form body"); + return NULL; + } + + struct keypairs_t *kp = enduser_setup_alloc_keypairs(keypair_nb); + + int current_idx = 0; + int err; + + char *body_copy = os_malloc(form_length+1); + os_bzero(body_copy, form_length+1); + os_memcpy(body_copy, form_body, form_length); + char *tok = strtok(body_copy, "="); + + char last_tok = '='; + while (tok) { + size_t len = strlen(tok); + kp->keypairs[current_idx] = os_malloc(len + 1); + err = enduser_setup_http_urldecode(kp->keypairs[current_idx], tok, len, len + 1); + if (err) { + ENDUSER_SETUP_DEBUG("Unable to decode parameter"); + enduser_setup_free_keypairs(kp); + os_free(body_copy); + return NULL; + } + + current_idx++; + if (current_idx > keypair_nb*2) { + ENDUSER_SETUP_DEBUG("Too many keypairs!"); + enduser_setup_free_keypairs(kp); + os_free(body_copy); + return NULL; + } + + if (last_tok == '=') { + tok = strtok(NULL, "&"); // now search for the '&' + last_tok='&'; + } else { + tok = strtok(NULL, "="); // search for the next '=' + last_tok='='; + } + } + os_free(body_copy); + return kp; +} + + +/** + * This function saves the form data received when the configuration is sent to the ESP into a eus_params.lua file + */ +static int enduser_setup_write_file_with_extra_configuration_data(char *form_body, int form_length) { + ENDUSER_SETUP_DEBUG("enduser: write data from posted form"); + ENDUSER_SETUP_DEBUG(form_body); + + // We will save the form data into a file in the LUA format: KEY="VALUE", so that configuration data is available for load in the lua code. + // As input, we have a string as such: "key1=value1&key2=value2&key3=value%203" (urlencoded), the number of '&' tells us how many keypairs there are (the count + 1) + + struct keypairs_t *kp = enduser_setup_get_keypairs_from_form(form_body, form_length); + if (kp == NULL || kp->keypairs_nb == 0) { + ENDUSER_SETUP_DEBUG("enduser: No extra configuration."); + if (kp != NULL) enduser_setup_free_keypairs(kp); + return 1; + } + + // Now that we have the keys and the values, let's save them in a lua file + int p_file = vfs_open("eus_params.lua", "w"); + if (p_file == 0) + { + ENDUSER_SETUP_DEBUG("Can't open file in write mode!"); + enduser_setup_free_keypairs(kp); + return 1; + } + + // write all key pairs as KEY="VALUE"\n into a Lua table, example: + // local p = {} + // p.wifi_ssid="ssid" + // p.wifi_password="password" + // p.device_name="foo-node" + // return p + vfs_write(p_file, "local p={}\n", 11); + int idx = 0; + for( idx = 0; idx < kp->keypairs_nb*2; idx=idx+2){ + char* to_write = kp->keypairs[idx]; + size_t length = c_strlen(to_write); + + vfs_write(p_file, "p.", 2); + + vfs_write(p_file, to_write, length); + + vfs_write(p_file, "=\"", 2); + + to_write = kp->keypairs[idx+1]; + length = c_strlen(to_write); + vfs_write(p_file, to_write, length); + + vfs_write(p_file, "\"\n", 2); + } + vfs_write(p_file, "return p\n", 9); + + vfs_close(p_file); + enduser_setup_free_keypairs(kp); + // TODO: we could call back in the LUA with an associative table setup, but this is MVP2... + return 0; +} /** * Handle HTTP Credentials * - * @return - return 0 iff credentials are found and handled successfully - * return 1 iff credentials aren't found - * return 2 iff an error occured + * @return - return 0 if credentials are found and handled successfully + * return 1 if credentials aren't found + * return 2 if an error occured */ static int enduser_setup_http_handle_credentials(char *data, unsigned short data_len) { @@ -682,7 +837,6 @@ static int enduser_setup_http_handle_credentials(char *data, unsigned short data return 1; } - ENDUSER_SETUP_DEBUG(""); ENDUSER_SETUP_DEBUG("WiFi Credentials Stored"); ENDUSER_SETUP_DEBUG("-----------------------"); @@ -702,7 +856,7 @@ static int enduser_setup_http_handle_credentials(char *data, unsigned short data /** * Serve HTML * - * @return - return 0 iff html was served successfully + * @return - return 0 if html was served successfully */ static int enduser_setup_http_serve_header(struct tcp_pcb *http_client, const char *header, uint32_t header_len) { @@ -763,7 +917,7 @@ static err_t streamout_sent (void *arg, struct tcp_pcb *pcb, u16_t len) /** * Serve HTML * - * @return - return 0 iff html was served successfully + * @return - return 0 if html was served successfully */ static int enduser_setup_http_serve_html(struct tcp_pcb *http_client) { @@ -957,6 +1111,37 @@ static void enduser_setup_handle_OPTIONS (struct tcp_pcb *http_client, char *dat } +static err_t enduser_setup_handle_POST(struct tcp_pcb *http_client, char* data, size_t data_len) +{ + ENDUSER_SETUP_DEBUG("Handling POST"); + if (c_strncmp(data + 5, "/setwifi ", 9) == 0) // User clicked the submit button + { + switch (enduser_setup_http_handle_credentials(data, data_len)) + { + case 0: { + // all went fine, extract all the form data into a file + char* body=strstr(data, "\r\n\r\n"); + char *content_length_str = strstr(data, "Content-Length: "); + if( body != NULL && content_length_str != NULL){ + int bodylength = c_atoi(content_length_str + 16); + body += 4; // length of the double CRLF found above + enduser_setup_write_file_with_extra_configuration_data(body, bodylength); + } + // redirect user to the base page with the trying flag + enduser_setup_http_serve_header(http_client, http_header_302_trying, LITLEN(http_header_302_trying)); + break; + } + case 1: + enduser_setup_http_serve_header(http_client, http_header_400, LITLEN(http_header_400)); + break; + default: + ENDUSER_SETUP_ERROR("http_recvcb failed. Failed to handle wifi credentials.", ENDUSER_SETUP_ERR_UNKOWN_ERROR, ENDUSER_SETUP_ERR_NONFATAL); + break; + } + } +} + + /* --- WiFi AP scanning support -------------------------------------------- */ static void free_scan_listeners (void) @@ -1165,7 +1350,7 @@ static err_t enduser_setup_http_recvcb(void *arg, struct tcp_pcb *http_client, s if (c_strncmp(data, "GET ", 4) == 0) { - if (c_strncmp(data + 4, "/ ", 2) == 0) + if (c_strncmp(data + 4, "/ ", 2) == 0 || c_strncmp(data + 4, "/?", 2) == 0) { if (enduser_setup_http_serve_html(http_client) != 0) { @@ -1237,21 +1422,6 @@ static err_t enduser_setup_http_recvcb(void *arg, struct tcp_pcb *http_client, s break; } } - else if (c_strncmp(data + 4, "/setwifi?", 9) == 0) - { - switch (enduser_setup_http_handle_credentials(data, data_len)) - { - case 0: - enduser_setup_serve_status_as_json(http_client); - break; - case 1: - enduser_setup_http_serve_header(http_client, http_header_400, LITLEN(http_header_400)); - break; - default: - ENDUSER_SETUP_ERROR("http_recvcb failed. Failed to handle wifi credentials.", ENDUSER_SETUP_ERR_UNKOWN_ERROR, ENDUSER_SETUP_ERR_NONFATAL); - break; - } - } else if (c_strncmp(data + 4, "/generate_204", 13) == 0) { /* Convince Android devices that they have internet access to avoid pesky dialogues. */ @@ -1267,6 +1437,10 @@ static err_t enduser_setup_http_recvcb(void *arg, struct tcp_pcb *http_client, s { enduser_setup_handle_OPTIONS(http_client, data, data_len); } + else if (c_strncmp(data, "POST ", 5) == 0) + { + enduser_setup_handle_POST(http_client, data, data_len); + } else /* not GET or OPTIONS */ { enduser_setup_http_serve_header(http_client, http_header_405, LITLEN(http_header_405)); @@ -1279,6 +1453,7 @@ static err_t enduser_setup_http_recvcb(void *arg, struct tcp_pcb *http_client, s return ret; } + static err_t enduser_setup_http_connectcb(void *arg, struct tcp_pcb *pcb, err_t err) { ENDUSER_SETUP_DEBUG("enduser_setup_http_connectcb"); @@ -1332,7 +1507,7 @@ static int enduser_setup_http_start(void) int err = enduser_setup_http_load_payload(); if (err == 1) { - ENDUSER_SETUP_DEBUG("enduser_setup_http_start info. Loaded backup HTML."); + ENDUSER_SETUP_DEBUG("enduser_setup_http_start info. Loaded default HTML."); } else if (err == 2) { diff --git a/app/modules/enduser_setup/.gitattributes b/app/modules/enduser_setup/.gitattributes new file mode 100644 index 0000000000..4a8a437832 --- /dev/null +++ b/app/modules/enduser_setup/.gitattributes @@ -0,0 +1 @@ +*.sh text eol=lf diff --git a/app/modules/enduser_setup/.gitignore b/app/modules/enduser_setup/.gitignore new file mode 100644 index 0000000000..f72d8a38d1 --- /dev/null +++ b/app/modules/enduser_setup/.gitignore @@ -0,0 +1 @@ +enduser_setup.html.gz diff --git a/app/modules/eus/enduser_setup.html b/app/modules/enduser_setup/enduser_setup.html similarity index 83% rename from app/modules/eus/enduser_setup.html rename to app/modules/enduser_setup/enduser_setup.html index 8a25e16057..551795f408 100644 --- a/app/modules/eus/enduser_setup.html +++ b/app/modules/enduser_setup/enduser_setup.html @@ -153,14 +153,17 @@

Connect device to your Wi-Fi

- - - - - +
+ + + + + + +

Success!

@@ -180,6 +183,11 @@

Updating Status...

var ab = $('#networks'), ap = $('#aplist'); var stopAll = false, ra, rs, submitted = false; + $.urlParam = function (name) { + var results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(window.location.href); + if (results == null) { return null;} + else { return decodeURI(results[1]) || 0;} + } function show(f, y) { if (y == null) y = f; $(f).style.display = y == f ? 'block' : 'none'; @@ -240,13 +248,6 @@

Updating Status...

} } } - function submit() { - submitted = true; - var url = '/setwifi?wifi_ssid=' + encodeURIComponent($('#ssid').value) + '&wifi_password=' + encodeURIComponent($('#wifi_password').value); - clearTimeout(rs); - fetch(url, 'GET', newSt, 2); - cur('#f3'); - } function fetch(url, method, callback, time_out) { var xhr = new XMLHttpRequest(); xhr.onloadend = function () { @@ -305,18 +306,19 @@

Updating Status...

fetch('/aplist?n=' + Math.random(), 'GET', gotAp, 10); } window.onload = function() { - ab.innerText = 'Scan for Networks'; - ab.onclick = refrAp; - $('#aplist').onchange = function () { - $('#ssid').value = $('#aplist').value; - }; - $('#submit').onclick = submit; - $('#bk2').onclick = function () { - cur('#f1') - } - rs = to(refr, 0.5); + let trying = $.urlParam('trying'); + ab.innerText = 'Scan for Networks'; + ab.onclick = refrAp; + $('#aplist').onchange = function () { + $('#ssid').value = $('#aplist').value; + }; + $('#bk2').onclick = function () { + cur('#f1') + } + rs = to(refr, 0.5); + if( trying ) cur("#f3"); } - \ No newline at end of file + diff --git a/app/modules/enduser_setup/enduser_setup.html.gz.def.h b/app/modules/enduser_setup/enduser_setup.html.gz.def.h new file mode 100644 index 0000000000..d829ee0d22 --- /dev/null +++ b/app/modules/enduser_setup/enduser_setup.html.gz.def.h @@ -0,0 +1,218 @@ +static const char enduser_setup_html_default[] = { + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x03, 0x9d, 0x59, + 0xfb, 0x73, 0xdb, 0xc6, 0xf1, 0xff, 0x59, 0xf9, 0x2b, 0x56, 0x92, 0xbf, + 0x06, 0x64, 0x93, 0x10, 0xa9, 0x87, 0xe3, 0x91, 0x48, 0x66, 0xfc, 0x4d, + 0x9c, 0x47, 0x27, 0x76, 0x3c, 0x96, 0x32, 0x69, 0xc6, 0x55, 0x33, 0x47, + 0xe0, 0x40, 0x5c, 0x04, 0xe2, 0xd0, 0xbb, 0x83, 0x28, 0x36, 0xf1, 0xff, + 0xde, 0x5d, 0x2c, 0x8e, 0x20, 0x08, 0x95, 0xd3, 0x76, 0x62, 0x89, 0xb8, + 0xc3, 0xbe, 0xf7, 0xb3, 0x0f, 0x2a, 0x93, 0xc3, 0x6f, 0x7e, 0xfa, 0xfa, + 0xf6, 0xd7, 0x0f, 0x6f, 0x21, 0x73, 0xcb, 0x7c, 0xf6, 0xc5, 0x84, 0x3f, + 0xf0, 0x53, 0x8a, 0x64, 0xf6, 0xc5, 0xc1, 0x64, 0x29, 0x9d, 0x80, 0x42, + 0x2c, 0xe5, 0x34, 0x78, 0x50, 0x72, 0x55, 0x6a, 0xe3, 0x02, 0x88, 0x75, + 0xe1, 0x64, 0xe1, 0xa6, 0xc1, 0x4a, 0x25, 0x2e, 0x9b, 0x26, 0xf2, 0x41, + 0xc5, 0x72, 0x58, 0x1f, 0x06, 0xa0, 0x0a, 0xe5, 0x94, 0xc8, 0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9, 0xbf, 0x55, 0xc4, 0x34, 0xcb, 0x32, 0x97, 0x4e, 0x12, 0x51, 0x47, + 0xf3, 0x87, 0x46, 0x66, 0xab, 0xf5, 0x70, 0x38, 0x84, 0x5f, 0x75, 0x05, + 0x31, 0xc6, 0x11, 0x01, 0x0f, 0xb5, 0x15, 0x16, 0x32, 0x69, 0x50, 0x54, + 0x91, 0x40, 0x26, 0x1e, 0x24, 0xb8, 0x4c, 0x2e, 0xa1, 0xd4, 0x25, 0x54, + 0x25, 0x12, 0x30, 0x14, 0xf2, 0x4a, 0x40, 0xac, 0x13, 0x7a, 0x69, 0x74, + 0xb5, 0xc8, 0x88, 0x08, 0x52, 0x95, 0x4b, 0x90, 0x95, 0x45, 0xe3, 0x8d, + 0x58, 0xda, 0x88, 0x88, 0x86, 0xc3, 0x8e, 0x87, 0xec, 0xce, 0x91, 0xad, + 0xe6, 0x4b, 0xe5, 0x8e, 0xe0, 0x41, 0xe4, 0x15, 0x1e, 0x6f, 0x50, 0xcd, + 0x11, 0x1a, 0xc5, 0x29, 0x20, 0x58, 0x31, 0x34, 0xfb, 0x20, 0x3d, 0xf3, + 0x20, 0x1d, 0xcf, 0x6e, 0xaa, 0x38, 0x96, 0xd6, 0x1e, 0x22, 0x20, 0x3d, + 0x74, 0x1b, 0x2a, 0x85, 0x47, 0x0f, 0x65, 0xf4, 0xce, 0x78, 0x1c, 0x67, + 0xc2, 0x82, 0x65, 0xae, 0xb4, 0xca, 0xf3, 0x35, 0xc4, 0x8c, 0x73, 0x99, + 0x10, 0xc4, 0xc9, 0x03, 0x4e, 0x4d, 0x83, 0xd0, 0x68, 0x32, 0x37, 0x18, + 0x2a, 0xfc, 0x7d, 0x4a, 0x62, 0x60, 0x29, 0xd6, 0x50, 0x60, 0xdd, 0xc7, + 0xb9, 0xb6, 0xe4, 0xb8, 0xb2, 0x80, 0x2b, 0x23, 0x94, 0x62, 0x21, 0x23, + 0x5f, 0x15, 0x1d, 0xa3, 0xfb, 0xe6, 0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0xe0, 0x05, 0x12, 0xf5, 0xd8, 0x31, + 0x94, 0x26, 0xdc, 0xf2, 0xed, 0xb0, 0xc9, 0xfc, 0x09, 0x5e, 0x20, 0x99, + 0x74, 0x71, 0x16, 0x06, 0xa7, 0x96, 0xf1, 0xfa, 0xbb, 0xd5, 0xc5, 0x57, + 0xc5, 0x94, 0x92, 0xf5, 0x4e, 0xb8, 0x2c, 0x32, 0x02, 0x13, 0xb3, 0x0c, + 0x11, 0x48, 0xc1, 0x77, 0x6f, 0x6f, 0x83, 0x01, 0xe5, 0xf5, 0xc6, 0x0d, + 0xe0, 0xac, 0xaf, 0x27, 0xae, 0xcc, 0xc6, 0x3d, 0x8a, 0x29, 0x62, 0x2e, + 0x1d, 0x23, 0x47, 0x93, 0x48, 0x7f, 0x75, 0xd6, 0xbf, 0x3a, 0xa7, 0xab, + 0x9e, 0x40, 0x56, 0x15, 0x22, 0x22, 0x13, 0x96, 0xca, 0xcb, 0xa7, 0x77, + 0xda, 0x58, 0x16, 0x62, 0x10, 0x17, 0x14, 0x22, 0x72, 0x73, 0x00, 0xe7, + 0x78, 0xe9, 0x1d, 0xb5, 0x70, 0x38, 0xc5, 0x75, 0x78, 0xd4, 0x70, 0x1f, + 0x50, 0x15, 0x50, 0x05, 0x44, 0xaa, 0x28, 0xa4, 0xb9, 0xc5, 0x01, 0x40, + 0x31, 0x7f, 0xb3, 0x12, 0x6a, 0xab, 0x62, 0x21, 0x24, 0xdf, 0x2d, 0xa1, + 0xf4, 0x84, 0x52, 0x81, 0x36, 0x01, 0x63, 0x0b, 0x9f, 0x59, 0x2e, 0x75, + 0x11, 0x9d, 0x42, 0x82, 0x99, 0x47, 0x7e, 0xeb, 0x0c, 0x72, 0x07, 0x5e, + 0xc9, 0x01, 0x5e, 0xc3, 0x5f, 0x6e, 0x7e, 0x7a, 0x1f, 0x95, 0xc2, 0x58, + 0x19, 0x26, 0x6c, 0x25, 0x7a, 0xb6, 0xb1, 0xc1, 0xaf, 0x0c, 0x3b, 0x96, + 0x1c, 0x7d, 0x53, 0xdf, 0x5f, 0xc1, 0x11, 0x2a, 0x4f, 0x22, 0xa6, 0x52, + 0x09, 0xf9, 0xd3, 0x54, 0x57, 0x8c, 0x54, 0x09, 0xca, 0x55, 0xa4, 0x71, + 0xeb, 0xde, 0x12, 0xfb, 0x27, 0x56, 0x1f, 0xfc, 0x90, 0xe4, 0x32, 0x18, + 0x34, 0x87, 0x66, 0xed, 0xe0, 0xb6, 0xb8, 0xb9, 0xfd, 0x56, 0xa8, 0x5c, + 0x26, 0x30, 0x84, 0x95, 0xd1, 0xe8, 0xb8, 0x1f, 0x8c, 0xbd, 0xf7, 0xbe, + 0x6d, 0x43, 0xa1, 0x1d, 0xa4, 0xba, 0x2a, 0x76, 0x48, 0xda, 0x23, 0x77, + 0xcc, 0xa7, 0x27, 0xc1, 0x61, 0x50, 0x13, 0xdd, 0x7d, 0x4a, 0x22, 0x06, + 0xd9, 0x1d, 0x9b, 0xce, 0x39, 0x72, 0x9b, 0x4a, 0x63, 0x51, 0xb6, 0x0e, + 0xc5, 0xd1, 0x16, 0xc9, 0x61, 0xdb, 0x90, 0x9e, 0x3f, 0x07, 0x2f, 0x04, + 0x66, 0x30, 0xee, 0x9c, 0x27, 0x70, 0xd9, 0x11, 0xf1, 0x5e, 0x22, 0x83, + 0xa0, 0x79, 0xa8, 0x12, 0x78, 0xdf, 0x38, 0x42, 0x13, 0xd8, 0xcf, 0x6c, + 0xaf, 0xe3, 0x49, 0x58, 0x58, 0xb7, 0x65, 0x81, 0xd7, 0x41, 0x09, 0x47, + 0x2d, 0x3e, 0xd3, 0x08, 0x78, 0x06, 0x74, 0x93, 0xe2, 0x83, 0xb6, 0xa5, + 0x3a, 0x53, 0x49, 0xba, 0xec, 0x81, 0x56, 0x30, 0xad, 0x07, 0x95, 0x97, + 0xee, 0x3d, 0xda, 0x95, 0x3d, 0x0e, 0x3c, 0x3d, 0xfd, 0xee, 0xb5, 0x2e, + 0x2e, 0x5e, 0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x5a, 0xe2, 0x2f, + 0x39, 0x8f, 0x1b, 0xc9, 0xf3, 0x7b, 0x1c, 0xae, 0x5e, 0x71, 0x4f, 0x6a, + 0x77, 0x4e, 0xd6, 0x9c, 0xfd, 0x85, 0x70, 0x14, 0x35, 0x85, 0xa3, 0xd2, + 0xd0, 0x87, 0xe3, 0x04, 0x88, 0xed, 0x08, 0x17, 0xcf, 0xa3, 0x26, 0x9a, + 0x00, 0x93, 0x53, 0xff, 0xc5, 0x6c, 0x72, 0xca, 0x7f, 0x03, 0xc2, 0x07, + 0xfe, 0x1f, 0x53, 0xff, 0x02, 0x2a, 0x13, 0x18, 0xb6, 0xb0, 0x1a, 0x00, + 0x00 +}; +unsigned int enduser_setup_html_default_len = 2569; diff --git a/app/modules/eus/prepare.sh b/app/modules/enduser_setup/prepare.sh similarity index 65% rename from app/modules/eus/prepare.sh rename to app/modules/enduser_setup/prepare.sh index 133ea9bb68..063a287eab 100644 --- a/app/modules/eus/prepare.sh +++ b/app/modules/enduser_setup/prepare.sh @@ -3,5 +3,5 @@ # Uses zopfli for better gzip compression # sudo apt-get install zopfli zopfli --gzip ./enduser_setup.html -xxd -i ./enduser_setup.html.gz | sed 's/unsigned char/static const char/; s/__enduser_setup_html_gz/http_html_backup/' > http_html_backup.def +xxd -i ./enduser_setup.html.gz | sed 's/unsigned char/static const char/; s/__enduser_setup_html_gz/enduser_setup_html_default/' > enduser_setup.html.gz.def.h diff --git a/app/modules/eus/enduser_setup.html.gz b/app/modules/eus/enduser_setup.html.gz deleted file mode 100644 index a8897cd6937d23a40a36ece175e76e33f66fce48..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2423 zcmV--35fO|iwFP!000021C?2ObK5o&|J(T#>$(@pjoz};jP>Z``o2lhPVG*wlgV@- z60}fL01p5y>)L$x+vO6XD5{$4G4J*IS7SCq_(grA;ElOgdN$w_ymEea7}DeC9}jymQoScZanqeN+f23C-~p!I)8!@zU=){bcS8v zfBmb=nq2+23}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{H@IL8tl6_#)IYxe0X)MZ> zP<*mSa$eW(^XCwRzyd~%=NVi#M7)#8AmCBZYV@vh1hW~!#0ff%riJr+76ct-z^`|a z#)RjDu0niPcOY*INr$bZ6-*nFDo76=9m*a>yY%6=W`!^^p}1?Df&o>26qanl8ke5t z_!s3cr*)yMbE#vK$e(}u{!5(EMoaBG1PR?ED2QJnFR2`!H+FzitPR4QjOpTo#0&Q zDFwH-7o%D^@ts7w5vtc%hPjUrO_Ae}j0GtiP-~BBw%VjlzzP2R6GqrBKP#uno&ue8 z+R)z{|2n7kOoI0yrl~v)J(z0-n=sWX5yE*@?(K$3*NvVUc>0;t_kINn814#$v@|;{ zQMRkACEF~2m$8oy1rb4`Q`33h8S6WB$V3;GficYCW#3|{Ko3OurIJC0RCt)&QT5GC zPC^#E@qh?DsobclyNJ0`W1&N=3K@q}{Fs%fRya)I#S67FgT%kslTUR?#P8LIKGiUl zZbL!Htuv8x%lq!`?Hg2tg7{V}X(tiOtlpUT!kc@HI7KhyV4ycT#yopK@{*=CH<6|} zb>EpVTpUl9_S`+QqMq!p^DbPozE&4xv*cqJCD~Z+uR7%crM1Wpx2<{D*aDK}eins4 z9E4H{OA5Ec=}~8HW1&fR2&s#X0K;Cikzx5wwZWRxYTpW7hz!2g-fpAg(6G|bYFc(n zVdE86T4{WU2PPy+Yvln?ly=&L#DhS)AUHHiZD#iA^^=$RQ=2FE8(MUCt!Sf=WWx=6 zzgt)S0{nl00{DwSLF0D@k*tKim&dv|z~Rhn{7MOjEcIh8oM$#(*ZTRWCc)o%_5E?( p^|rwB%lGDDJnUarxB<)t;WyiCz<+ANFXjLL`5&Ripkx*r002x2ziI#g diff --git a/app/modules/eus/http_html_backup.def b/app/modules/eus/http_html_backup.def deleted file mode 100644 index 97e5592a7a..0000000000 --- a/app/modules/eus/http_html_backup.def +++ /dev/null @@ -1,205 +0,0 @@ -static const char http_html_backup[] = { - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0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0xb5, 0xb0, 0x48, 0x7e, - 0x03, 0xc3, 0x29, 0x3d, 0xe5, 0x22, 0x49, 0x94, 0xbe, 0xaf, 0x1e, 0x3f, - 0xe2, 0x0b, 0xff, 0x91, 0xcd, 0x5d, 0xfc, 0x5c, 0x9a, 0x64, 0xcb, 0x4c, - 0x2b, 0xa9, 0xee, 0x57, 0xfe, 0x06, 0x46, 0xc3, 0xe1, 0x3f, 0x4a, 0xbe, - 0x14, 0x2d, 0xee, 0xa5, 0x62, 0xad, 0xb2, 0xed, 0x0d, 0x38, 0xa1, 0x5d, - 0xcf, 0x49, 0xab, 0xd2, 0xf2, 0x8e, 0x94, 0xf6, 0x44, 0xa6, 0xee, 0x51, - 0x4b, 0x2c, 0xd1, 0x33, 0x5b, 0x1e, 0x2f, 0x45, 0xfc, 0x70, 0x6f, 0x4d, - 0xa1, 0x93, 0x1b, 0xb8, 0xb8, 0xba, 0xba, 0x4a, 0xae, 0xae, 0xf6, 0x74, - 0x5e, 0x54, 0x18, 0xb0, 0xbe, 0xdc, 0x38, 0x74, 0xda, 0xa0, 0x00, 0xb1, - 0x74, 0x26, 0x2b, 0xbc, 0x64, 0xc9, 0x26, 0x0f, 0x86, 0x5b, 0x36, 0x88, - 0x1f, 0x96, 0xc6, 0x7b, 0xb3, 0x0e, 0x4f, 0x99, 0x4c, 0x77, 0x37, 0x25, - 0x86, 0x37, 0x30, 0x19, 0x0f, 0xf3, 0xa7, 0xe9, 0xbe, 0x27, 0x57, 0xaf, - 0xc2, 0x49, 0x00, 0x44, 0x14, 0xde, 0xec, 0x19, 0xa4, 0x74, 0x5e, 0xf8, - 0x12, 0x85, 0x02, 0x85, 0x6b, 0xfa, 0xe6, 0x64, 0x26, 0xe3, 0xca, 0xc2, - 0xde, 0x46, 0x2e, 0x1f, 0x14, 0xfa, 0x99, 0xe7, 0x52, 0x58, 0xa1, 0x63, - 0x79, 0x03, 0xda, 0x68, 0x59, 0xd9, 0x63, 0x13, 0x69, 0x7b, 0x56, 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0, 0x14, 0x58, 0x22, 0xbc, 0x78, 0x7e, 0xf1, 0x34, 0xbe, 0x5e, - 0xc6, 0x53, 0xf4, 0x1c, 0xcf, 0x03, 0x0d, 0xcf, 0x01, 0xa2, 0xe2, 0x1c, - 0xe2, 0xe5, 0x8b, 0xbf, 0xa3, 0x1a, 0xbe, 0x66, 0x62, 0x76, 0x93, 0xbf, - 0xf2, 0xa0, 0x43, 0x2e, 0xe7, 0x54, 0x52, 0x2f, 0x53, 0x65, 0x06, 0xc7, - 0xc6, 0x5a, 0x64, 0x9a, 0x9b, 0x34, 0xe5, 0x67, 0x91, 0x2b, 0x2f, 0x32, - 0x6c, 0x0b, 0x73, 0xaa, 0x17, 0xc0, 0xd2, 0x89, 0xe5, 0xca, 0x64, 0x98, - 0x48, 0xf3, 0xa8, 0x84, 0x01, 0xde, 0xa1, 0xd2, 0x08, 0x06, 0x87, 0xc2, - 0x37, 0x2a, 0x55, 0xbf, 0xe5, 0xe8, 0x38, 0xe2, 0xf1, 0x77, 0xb5, 0x30, - 0xcd, 0x3a, 0xcf, 0xa4, 0x97, 0x44, 0xd4, 0x50, 0xfb, 0x63, 0x90, 0x39, - 0x68, 0xa1, 0xef, 0x8a, 0xe5, 0x5a, 0xf9, 0x7d, 0xec, 0x17, 0xb7, 0xe2, - 0x51, 0x36, 0x10, 0x3f, 0x12, 0xf0, 0x71, 0x08, 0xf8, 0x68, 0x71, 0x5b, - 0xc4, 0xb1, 0x74, 0xee, 0x1c, 0x83, 0x3b, 0x6a, 0x06, 0x48, 0xe1, 0x63, - 0x48, 0x8b, 0x5f, 0x31, 0x09, 0x42, 0x4e, 0xac, 0x84, 0x03, 0xc7, 0x5c, - 0x69, 0x91, 0x65, 0x5b, 0x88, 0x39, 0x67, 0x64, 0x42, 0xe9, 0xe2, 0x57, - 0x12, 0x18, 0xa6, 0x2a, 0x33, 0xfa, 0xb3, 0xa5, 0x45, 0xcb, 0xf1, 0x7d, - 0x40, 0x62, 0x60, 0x2d, 0x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 0x52, 0x79, 0xef, 0x09, 0x4e, - 0x5b, 0xc7, 0x42, 0xac, 0x83, 0x39, 0x41, 0x44, 0x6e, 0x76, 0x61, 0x82, - 0x87, 0xc1, 0x51, 0x07, 0xe7, 0x73, 0xdc, 0xc4, 0x86, 0x15, 0xf7, 0x19, - 0x25, 0x0d, 0x25, 0x4c, 0x5f, 0x69, 0x2d, 0xed, 0x1d, 0xb6, 0x2f, 0xc2, - 0xfc, 0xf5, 0x46, 0xa8, 0xbd, 0x04, 0x87, 0x0e, 0xf9, 0xee, 0xf0, 0x15, - 0x5d, 0x52, 0x28, 0xd0, 0x26, 0x90, 0x98, 0x33, 0x24, 0xa3, 0x92, 0x4b, - 0x45, 0x67, 0x52, 0x48, 0x30, 0xf2, 0xc8, 0xef, 0xbc, 0x45, 0xee, 0x28, - 0x28, 0x39, 0xc3, 0x63, 0xf8, 0xd7, 0xed, 0x0f, 0xef, 0xfa, 0xb9, 0xb0, - 0x4e, 0x76, 0x12, 0xb6, 0x12, 0x3d, 0xdb, 0xd9, 0x10, 0xa6, 0xd5, 0x81, - 0x25, 0x9f, 0x7c, 0x55, 0x9e, 0xdf, 0xc0, 0x27, 0xa8, 0x3c, 0xe9, 0x33, - 0x95, 0x4a, 0x4a, 0x7f, 0x38, 0xc3, 0x63, 0xa4, 0x4a, 0x50, 0xae, 0x22, - 0x8d, 0x7b, 0xe7, 0x8e, 0xd8, 0xdf, 0xb3, 0xfa, 0xe8, 0xfb, 0x24, 0x93, - 0x51, 0xb7, 0x7a, 0xa8, 0x26, 0x1e, 0x77, 0x91, 0xdd, 0xe9, 0x37, 0x42, - 0x65, 0x32, 0x81, 0x1e, 0x6c, 0xac, 0x41, 0xc7, 0x43, 0x5b, 0x6f, 0xdf, - 0x57, 0x75, 0x07, 0xda, 0x78, 0x48, 0x4d, 0xa1, 0x0f, 0x49, 0xc2, 0x63, - 0x35, 0x3b, 0x8e, 0x37, 0xce, 0xf3, 0xa8, 0x24, 0xfa, 0xf0, 0x3e, 0xe9, - 0x73, 0x92, 0x7d, 0x60, 0xd3, 0x39, 0x46, 0x7e, 0x57, 0x69, 0x2c, 0xca, - 0x95, 0x50, 0x7c, 0xb2, 0x47, 0x72, 0x5e, 0xd7, 0xef, 0xf3, 0xe7, 0x10, - 0x84, 0xc0, 0x02, 0x46, 0x8d, 0xe7, 0x19, 0x5c, 0x37, 0x44, 0xbc, 0x93, - 0xc8, 0x20, 0xe0, 0x51, 0xd0, 0x6a, 0xf4, 0xae, 0x72, 0x04, 0xb3, 0x19, - 0xc2, 0xc4, 0x09, 0x3a, 0x8e, 0xa6, 0x85, 0xf3, 0x7b, 0x16, 0x04, 0x1d, - 0x65, 0xc0, 0xaf, 0x77, 0x91, 0xc6, 0x84, 0xe7, 0x84, 0xae, 0x42, 0x7c, - 0x56, 0x77, 0x20, 0x6f, 0x0b, 0x49, 0x87, 0xad, 0xa4, 0x15, 0x4c, 0x1b, - 0x92, 0x2a, 0x48, 0x0f, 0x1e, 0x1d, 0xca, 0x1e, 0x45, 0xbb, 0xf4, 0xe1, - 0xb7, 0x66, 0x85, 0x30, 0x32, 0xa1, 0xb8, 0x6b, 0x9c, 0x82, 0x01, 0x55, - 0x7e, 0x14, 0x96, 0x6c, 0xc2, 0x1a, 0x97, 0x9e, 0xe6, 0xf8, 0x17, 0xe5, - 0x30, 0xa7, 0x75, 0xa1, 0xac, 0x73, 0xa9, 0x63, 0x93, 0xc8, 0x9f, 0x7f, - 0xfa, 0xfe, 0x4b, 0x9c, 0xd1, 0x46, 0x4b, 0xed, 0x3b, 0x04, 0x09, 0xdd, - 0x23, 0x28, 0x88, 0x5f, 0x21, 0x2f, 0xa9, 0x1c, 0x9e, 0x37, 0x76, 0x80, - 0x53, 0xac, 0x0d, 0xc2, 0x9d, 0x8c, 0xe9, 0xf1, 0x12, 0xde, 0xf5, 0x20, - 0xb4, 0xf2, 0x78, 0x97, 0x09, 0x60, 0x4c, 0xa2, 0x76, 0x8f, 0xd8, 0x63, - 0x5d, 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, 0x78, 0xfa, 0x99, 0xd4, 0xf7, 0x7e, 0x05, 0x0b, 0x18, 0xee, 0x0a, - 0x84, 0xb4, 0x34, 0x3b, 0x2d, 0x51, 0xb6, 0xab, 0xab, 0x25, 0xdb, 0x2c, - 0x7f, 0x97, 0xb1, 0x8f, 0x0e, 0x05, 0x11, 0x41, 0xa3, 0x53, 0xd3, 0x79, - 0xdf, 0x19, 0xeb, 0x3b, 0x75, 0xc8, 0x44, 0x17, 0x96, 0x81, 0x31, 0xcc, - 0xe1, 0x65, 0xdf, 0x62, 0xa9, 0x40, 0x0f, 0x44, 0xf9, 0xa5, 0x92, 0x41, - 0x86, 0x54, 0x78, 0x98, 0xdc, 0x51, 0xf5, 0xcd, 0x4c, 0x4e, 0x42, 0x16, - 0xbc, 0xf1, 0x80, 0x08, 0x3d, 0xa9, 0xdc, 0xa8, 0xaa, 0xbb, 0x88, 0xb9, - 0x52, 0x63, 0xa1, 0x43, 0xac, 0x0a, 0x19, 0x87, 0x53, 0xfc, 0x98, 0x95, - 0xa8, 0x56, 0x38, 0x4c, 0xe1, 0xc5, 0x0b, 0xb5, 0x33, 0x83, 0xc4, 0xbf, - 0xd8, 0x93, 0x4f, 0x75, 0x49, 0xc4, 0xef, 0xd5, 0x87, 0x3e, 0xd5, 0x30, - 0x95, 0x6e, 0x43, 0x41, 0xc8, 0xad, 0x33, 0x91, 0x73, 0xcb, 0xfb, 0xee, - 0xee, 0xed, 0x1b, 0x54, 0x84, 0x82, 0xf8, 0x56, 0x2c, 0x69, 0x27, 0x11, - 0xcb, 0xac, 0xde, 0x98, 0xf8, 0xc2, 0x9b, 0x7b, 0x8c, 0x38, 0x45, 0x2f, - 0xe4, 0x60, 0xa0, 0x37, 0x3a, 0xc6, 0x3c, 0x7b, 0x40, 0xf2, 0x92, 0xa6, - 0x35, 0x37, 0x91, 0xa6, 0x39, 0x75, 0xdf, 0x99, 0x30, 0x5c, 0x1c, 0x4f, - 0x96, 0xf6, 0xdc, 0x3d, 0x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9c, 0x67, 0x36, 0x5e, 0xd7, 0xfa, 0xf9, - 0xa8, 0x26, 0xc1, 0xdf, 0x79, 0xf5, 0xfd, 0x71, 0xdd, 0xf5, 0xb6, 0xc0, - 0xf2, 0xcb, 0xf7, 0xe6, 0x62, 0x3c, 0xec, 0x5f, 0x57, 0xb8, 0x01, 0xcc, - 0x06, 0xe1, 0x37, 0xdb, 0x6c, 0xc0, 0x7f, 0x6a, 0xc1, 0x2f, 0xe5, 0xff, - 0xff, 0xf9, 0x1f, 0xa1, 0xc6, 0xa0, 0x64, 0x16, 0x1a, 0x00, 0x00 -}; -unsigned int http_html_backup_len = 2423; diff --git a/docs/img/enduser-setup-captive-portal.png b/docs/img/enduser-setup-captive-portal.png new file mode 100644 index 0000000000000000000000000000000000000000..92f52050e02aad134a671f31dcc528e4fb319ff2 GIT binary patch literal 34739 zcmd3NbzGBO*zo8s=^mgU(xFIqBdAE1zyPJY8x)nAL6?M}v~-8mke2S0fpm`EcMqTN zt?&K!{cSKfyY6$Yj&rW_`k|&W5k4J02m~ThRZ(~h0%1WxAoOBfY+ywCN|YD`ittrc zkbUBfwmE@CJPjgMY@OjGw2pXx&TLb_6W%k^ufjzmyxEKJ(- z%{t1AIJ984-z3&3^T{+d_xzVpG^%fw} zrIgQ&4>2S+Jd1TOb?@S>8@@b(U**j%;GD)FcTXBliFtRHx6UU;PK%eyhDCl}DmhUn zq)8R!3UJOl91gisAn$@euH>utdZQDK_R5B-w=Q-0L`cK~kb7xYd%-jKFc8S!O2!cj zf<_Ap4iW-8IikBF_JZvb*+HPT!)&zLdOR3Cnt=>9Xu%8*mSBGNHCTdojzk*-A{@53 z7z)1FGrt2S0A{&3LKAJ?6adrbfG8FBay_~DB!H_|1PnIhHdUWk}j6N=*l#>KJx%^ z7Enfj%W@O?f>aKdrTryq2zLl~xHBG|R{Gqf^ir5^>9nl7)h;KLn63a3kowebvC+3A z4U{H}SsuL0H0p<-Z!JfYreSEb*L%;sa{xHJy*5 z9&kuLZwz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*q%MXTd?R!-m-gB^BO$*JWCPhTghQ>l8=jOH9 z)F2(wZY)FGbZ#SEg)R%zCUz}34=MSea`R!uOc``)6SQ=zw#OHoD?;D6E4>h8mW3hO z6GQHa_sg$7UpRMtQ7?2-LkkCQ_hSj)ebX~3kzn}QGJN1Ln}>VVa~Eca5K8=3yXSD) zdyatP%EbpJhf6b0W>>AtNkPI-=Ctp26CcjGO*OJC&1@uKZ|mhhfLU(L6{h&|;lBVE C`nweX diff --git a/docs/modules/enduser-setup.md b/docs/modules/enduser-setup.md index 9eb367b0b1..86060d7a73 100644 --- a/docs/modules/enduser-setup.md +++ b/docs/modules/enduser-setup.md @@ -3,49 +3,107 @@ | :----- | :-------------------- | :---------- | :------ | | 2015-09-02 | [Robert Foss](https://github.com/robertfoss) | [Robert Foss](https://github.com/robertfoss) | [enduser_setup.c](../../app/modules/enduser_setup.c)| -This module provides a simple way of configuring ESP8266 chips without using a serial interface or pre-programming WiFi credentials onto the chip. +This module provides a simple way of configuring ESP8266 chips without using a +serial interface or pre-programming WiFi credentials onto the chip. + +After running [`enduser_setup.start()`](#enduser_setupstart), a wireless +network named "SetupGadget_XXXXXX" will starting. This prefix can be overridden +in `user_config.h` by defining `ENDUSER_SETUP_AP_SSID`. Connect to that SSID +and then navigate to the root of any website or to 192.168.4.1. +`http://example.com/` will work, but do not use `.local` domains because it +will fail on iOS. A web page similar to the one depicted below will load, +allowing the end user to provide their Wi-Fi credentials. + +![enduser setup config dialog](../img/enduser-setup-captive-portal.png "enduser setup config dialog") + +After an IP address has been successfully obtained, then this module will stop +as if [`enduser_setup.stop()`](#enduser_setupstop) had been called. There is a +10-second delay before teardown to allow connected clients to obtain a last +status message while the SoftAP is still active. + +Alternative HTML can be served by placing a file called `enduser_setup.html` on +the filesystem. Everything needed by the web page must be included in this one +file. This file will be kept in RAM, so keep it as small as possible. The file +can be gzip'd ahead of time to reduce the size (i.e., using `gzip -n` or +`zopfli`), and when served, the End User Setup module will add the appropriate +`Content-Encoding` header to the response. + +*Note: If gzipped, the file can also be named `enduser_setup.html.gz` for +semantic purposes. GZIP encoding is determined by the file's contents, not the +filename.* + +### Additional configuration parameters + +You can also add some additional inputs in the `enduser_setup.html` (as long as +you keep those needed for the WiFi setup). The additional data will be written +in a `eus_params.lua` file in the root filesystem of the ESP8266, which you can +then load in your own code. In this case, the data will be saved as a set of +variables with the name being the input name, and the value being a string +representing what you put in the form. + +For instance, if your HTML contains two additional inputs: + +```html + + +``` + +Then the `eus_params.lua` file will contain the following: -![enduser setup config dialog](../img/enduser-setup.jpg "enduser setup config dialog") +```lua +-- those wifi_* are the base parameters that are saved anyway +local p = {} +p.wifi_ssid="ssid" +p.wifi_password="password" +-- your own parameters: +p.timeout_delay="xxx" +p.device_name="yyy" +return p +``` -After running [`enduser_setup.start()`](#enduser_setupstart), a wireless network named "SetupGadget_XXXXXX" will start (this prefix can be overridden in `user_config.h` by defining -`ENDUSER_SETUP_AP_SSID`). Connect to that SSID and then navigate to the root -of any website (e.g., `http://example.com/` will work, but do not use `.local` domains because it will fail on iOS). A web page similar to the picture above will load, allowing the -end user to provide their Wi-Fi information. +### How to use the eus_params.lua file -After an IP address has been successfully obtained, then this module will stop as if [`enduser_setup.stop()`](#enduser_setupstop) had been called. There is a 10-second delay before -teardown to allow connected clients to obtain a last status message while the SoftAP is still active. +Simply include the file by using the `dofile` function: +```lua +p = dofile('eus_params.lua') +-- now use the parameters in the Lua table +print("Wifi device_name: " .. p.device_name) +``` -Alternative HTML can be served by placing a file called `enduser_setup.html` on the filesystem. Everything needed by the web page must be included in this one file. This file will be kept -in RAM, so keep it as small as possible. The file can be gzip'd ahead of time to reduce the size (i.e., using `gzip -n` or `zopfli`), and when served, the End User Setup module will add -the appropriate `Content-Encoding` header to the response. +### HTTP endpoints: -*Note: If gzipped, the file can also be named `enduser_setup.html.gz` for semantic purposes. Gzip encoding is determined by the file's contents, not the filename.* +|Path|Method|Description| +|----|------|-----------| +|/|GET|Returns HTML for the web page. Will return the contents of `enduser_setup.html` if it exists on the filesystem, otherwise will return a page embedded into the firmware image.| +|/aplist|GET|Forces the ESP8266 to perform a site survey across all channels, reporting access points that it can find. Return payload is a JSON array: `[{"ssid":"foobar","rssi":-36,"chan":3}]`| +|/generate_204|GET|Returns a HTTP 204 status (expected by certain Android clients during Wi-Fi connectivity checks)| +|/status|GET|Returns plaintext status description, used by the web page| +|/status.json|GET|Returns a JSON payload containing the ESP8266's chip id in hexadecimal format and the status code: 0=Idle, 1=Connecting, 2=Wrong Password, 3=Network not Found, 4=Failed, 5=Success| +|/setwifi|POST|HTML form post for setting the WiFi credentials. Expects HTTP content type `application/x-www-form-urlencoded`. Supports sending and storing additinal configuration parameters (as input fields). Returns the same payload as `/status.json` instead of redirecting to `/`. See also: `/update`.| +|/update|GET|Data submission target. Example: `http://example.com/update?wifi_ssid=foobar&wifi_password=CorrectHorseBatteryStaple`. Will redirect to `/` when complete. Note that will NOT update the `eus_params.lua` file i.e. it does NOT support sending arbitrary parameters. See also: `/setwifi`. | -The following HTTP endpoints exist: +Module functions are described below. -|Endpoint|Description| -|--------|-----------| -|/|Returns HTML for the web page. Will return the contents of `enduser_setup.html` if it exists on the filesystem, otherwise will return a page embedded into the firmware image.| -|/aplist|Forces the ESP8266 to perform a site survey across all channels, reporting access points that it can find. Return payload is a JSON array: `[{"ssid":"foobar","rssi":-36,"chan":3}]`| -|/generate_204|Returns a HTTP 204 status (expected by certain Android clients during Wi-Fi connectivity checks)| -|/status|Returns plaintext status description, used by the web page| -|/status.json|Returns a JSON payload containing the ESP8266's chip id in hexadecimal format and the status code: 0=Idle, 1=Connecting, 2=Wrong Password, 3=Network not Found, 4=Failed, 5=Success| -|/setwifi|Endpoint intended for services to use for setting the wifi credentials. Identical to `/update` except returns the same payload as `/status.json` instead of redirecting to `/`.| -|/update|Form submission target. Example: `http://example.com/update?wifi_ssid=foobar&wifi_password=CorrectHorseBatteryStaple`. Must be a GET request. Will redirect to `/` when complete. | ## enduser_setup.manual() Controls whether manual AP configuration is used. -By default the `enduser_setup` module automatically configures an open access point when starting, and stops it when the device has been successfully joined to a WiFi network. If manual mode has been enabled, neither of this is done. The device must be manually configured for `wifi.SOFTAP` mode prior to calling `enduser_setup.start()`. Additionally, the portal is not stopped after the device has successfully joined to a WiFi network. +By default the `enduser_setup` module automatically configures an open access +point when starting, and stops it when the device has been successfully joined +to a WiFi network. If manual mode has been enabled, neither of this is done. +The device must be manually configured for `wifi.SOFTAP` mode prior to calling +`enduser_setup.start()`. Additionally, the portal is not stopped after the +device has successfully joined to a WiFi network. #### Syntax `enduser_setup.manual([on_off])` #### Parameters - - `on_off` a boolean value indicating whether to use manual mode; if not given, the function only returns the current setting. + - `on_off` a boolean value indicating whether to use manual mode; if not + given, the function only returns the current setting. #### Returns The current setting, true if manual mode is enabled, false if it is not. @@ -57,12 +115,12 @@ wifi.ap.config({ssid="MyPersonalSSID", auth=wifi.OPEN}) enduser_setup.manual(true) enduser_setup.start( function() - print("Connected to wifi as:" .. wifi.sta.getip()) + print("Connected to WiFi as:" .. wifi.sta.getip()) end, function(err, str) print("enduser_setup: Err #" .. err .. ": " .. str) end -); +) ``` ## enduser_setup.start() @@ -86,13 +144,13 @@ Starts the captive portal. ```lua enduser_setup.start( function() - print("Connected to wifi as:" .. wifi.sta.getip()) + print("Connected to WiFi as:" .. wifi.sta.getip()) end, function(err, str) print("enduser_setup: Err #" .. err .. ": " .. str) end, print -- Lua print function can serve as the debug callback -); +) ``` ## enduser_setup.stop() From a0d06822329d4ef5f7bf22b741ce9048f7d0edc4 Mon Sep 17 00:00:00 2001 From: Gregor Hartmann Date: Thu, 11 Jul 2019 12:57:49 +0200 Subject: [PATCH 34/74] Update enduser_setup.html.gz.def.h (#2827) --- .../enduser_setup/enduser_setup.html.gz.def.h | 433 +++++++++--------- 1 file changed, 217 insertions(+), 216 deletions(-) diff --git a/app/modules/enduser_setup/enduser_setup.html.gz.def.h b/app/modules/enduser_setup/enduser_setup.html.gz.def.h index d829ee0d22..83e32dd059 100644 --- a/app/modules/enduser_setup/enduser_setup.html.gz.def.h +++ b/app/modules/enduser_setup/enduser_setup.html.gz.def.h @@ -1,218 +1,219 @@ static const char enduser_setup_html_default[] = { - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x03, 0x9d, 0x59, - 0xfb, 0x73, 0xdb, 0xc6, 0xf1, 0xff, 0x59, 0xf9, 0x2b, 0x56, 0x92, 0xbf, - 0x06, 0x64, 0x93, 0x10, 0xa9, 0x87, 0xe3, 0x91, 0x48, 0x66, 0xfc, 0x4d, - 0x9c, 0x47, 0x27, 0x76, 0x3c, 0x96, 0x32, 0x69, 0xc6, 0x55, 0x33, 0x47, - 0xe0, 0x40, 0x5c, 0x04, 0xe2, 0xd0, 0xbb, 0x83, 0x28, 0x36, 0xf1, 0xff, - 0xde, 0x5d, 0x2c, 0x8e, 0x20, 0x08, 0x95, 0xd3, 0x76, 0x62, 0x89, 0xb8, - 0xc3, 0xbe, 0xf7, 0xb3, 0x0f, 0x2a, 0x93, 0xc3, 0x6f, 0x7e, 0xfa, 0xfa, - 0xf6, 0xd7, 0x0f, 0x6f, 0x21, 0x73, 0xcb, 0x7c, 0xf6, 0xc5, 0x84, 0x3f, - 0xf0, 0x53, 0x8a, 0x64, 0xf6, 0xc5, 0xc1, 0x64, 0x29, 0x9d, 0x80, 0x42, - 0x2c, 0xe5, 0x34, 0x78, 0x50, 0x72, 0x55, 0x6a, 0xe3, 0x02, 0x88, 0x75, - 0xe1, 0x64, 0xe1, 0xa6, 0xc1, 0x4a, 0x25, 0x2e, 0x9b, 0x26, 0xf2, 0x41, - 0xc5, 0x72, 0x58, 0x1f, 0x06, 0xa0, 0x0a, 0xe5, 0x94, 0xc8, 0x87, 0x36, - 0x16, 0xb9, 0x9c, 0x8e, 0xa3, 0x51, 0x40, 0x72, 0x9c, 0x72, 0xb9, 0x9c, - 0xfd, 0xa2, 0xbe, 0x55, 0xf0, 0xa3, 0x5e, 0xa8, 0x62, 0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 0xc6, 0x11, 0x01, 0x0f, 0xb5, 0x15, 0x16, 0x32, 0x69, 0x50, 0x54, - 0x91, 0x40, 0x26, 0x1e, 0x24, 0xb8, 0x4c, 0x2e, 0xa1, 0xd4, 0x25, 0x54, - 0x25, 0x12, 0x30, 0x14, 0xf2, 0x4a, 0x40, 0xac, 0x13, 0x7a, 0x69, 0x74, - 0xb5, 0xc8, 0x88, 0x08, 0x52, 0x95, 0x4b, 0x90, 0x95, 0x45, 0xe3, 0x8d, - 0x58, 0xda, 0x88, 0x88, 0x86, 0xc3, 0x8e, 0x87, 0xec, 0xce, 0x91, 0xad, - 0xe6, 0x4b, 0xe5, 0x8e, 0xe0, 0x41, 0xe4, 0x15, 0x1e, 0x6f, 0x50, 0xcd, - 0x11, 0x1a, 0xc5, 0x29, 0x20, 0x58, 0x31, 0x34, 0xfb, 0x20, 0x3d, 0xf3, - 0x20, 0x1d, 0xcf, 0x6e, 0xaa, 0x38, 0x96, 0xd6, 0x1e, 0x22, 0x20, 0x3d, - 0x74, 0x1b, 0x2a, 0x85, 0x47, 0x0f, 0x65, 0xf4, 0xce, 0x78, 0x1c, 0x67, - 0xc2, 0x82, 0x65, 0xae, 0xb4, 0xca, 0xf3, 0x35, 0xc4, 0x8c, 0x73, 0x99, - 0x10, 0xc4, 0xc9, 0x03, 0x4e, 0x4d, 0x83, 0xd0, 0x68, 0x32, 0x37, 0x18, - 0x2a, 0xfc, 0x7d, 0x4a, 0x62, 0x60, 0x29, 0xd6, 0x50, 0x60, 0xdd, 0xc7, - 0xb9, 0xb6, 0xe4, 0xb8, 0xb2, 0x80, 0x2b, 0x23, 0x94, 0x62, 0x21, 0x23, - 0x5f, 0x15, 0x1d, 0xa3, 0xfb, 0xe6, 0x7b, 0x9a, 0xec, 0x6c, 0x76, 0x6b, - 0xd6, 0xd8, 0x5f, 0xa2, 0x88, 0x58, 0xc9, 0xab, 0x6e, 0x91, 0x50, 0xdf, - 0xee, 0xd7, 0x47, 0xd0, 0x14, 0x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 0xf1, 0xfa, 0xbb, 0xd5, 0xc5, 0x57, - 0xc5, 0x94, 0x92, 0xf5, 0x4e, 0xb8, 0x2c, 0x32, 0x02, 0x13, 0xb3, 0x0c, - 0x11, 0x48, 0xc1, 0x77, 0x6f, 0x6f, 0x83, 0x01, 0xe5, 0xf5, 0xc6, 0x0d, - 0xe0, 0xac, 0xaf, 0x27, 0xae, 0xcc, 0xc6, 0x3d, 0x8a, 0x29, 0x62, 0x2e, - 0x1d, 0x23, 0x47, 0x93, 0x48, 0x7f, 0x75, 0xd6, 0xbf, 0x3a, 0xa7, 0xab, - 0x9e, 0x40, 0x56, 0x15, 0x22, 0x22, 0x13, 0x96, 0xca, 0xcb, 0xa7, 0x77, - 0xda, 0x58, 0x16, 0x62, 0x10, 0x17, 0x14, 0x22, 0x72, 0x73, 0x00, 0xe7, - 0x78, 0xe9, 0x1d, 0xb5, 0x70, 0x38, 0xc5, 0x75, 0x78, 0xd4, 0x70, 0x1f, - 0x50, 0x15, 0x50, 0x05, 0x44, 0xaa, 0x28, 0xa4, 0xb9, 0xc5, 0x01, 0x40, - 0x31, 0x7f, 0xb3, 0x12, 0x6a, 0xab, 0x62, 0x21, 0x24, 0xdf, 0x2d, 0xa1, - 0xf4, 0x84, 0x52, 0x81, 0x36, 0x01, 0x63, 0x0b, 0x9f, 0x59, 0x2e, 0x75, - 0x11, 0x9d, 0x42, 0x82, 0x99, 0x47, 0x7e, 0xeb, 0x0c, 0x72, 0x07, 0x5e, - 0xc9, 0x01, 0x5e, 0xc3, 0x5f, 0x6e, 0x7e, 0x7a, 0x1f, 0x95, 0xc2, 0x58, - 0x19, 0x26, 0x6c, 0x25, 0x7a, 0xb6, 0xb1, 0xc1, 0xaf, 0x0c, 0x3b, 0x96, - 0x1c, 0x7d, 0x53, 0xdf, 0x5f, 0xc1, 0x11, 0x2a, 0x4f, 0x22, 0xa6, 0x52, - 0x09, 0xf9, 0xd3, 0x54, 0x57, 0x8c, 0x54, 0x09, 0xca, 0x55, 0xa4, 0x71, - 0xeb, 0xde, 0x12, 0xfb, 0x27, 0x56, 0x1f, 0xfc, 0x90, 0xe4, 0x32, 0x18, - 0x34, 0x87, 0x66, 0xed, 0xe0, 0xb6, 0xb8, 0xb9, 0xfd, 0x56, 0xa8, 0x5c, - 0x26, 0x30, 0x84, 0x95, 0xd1, 0xe8, 0xb8, 0x1f, 0x8c, 0xbd, 0xf7, 0xbe, - 0x6d, 0x43, 0xa1, 0x1d, 0xa4, 0xba, 0x2a, 0x76, 0x48, 0xda, 0x23, 0x77, - 0xcc, 0xa7, 0x27, 0xc1, 0x61, 0x50, 0x13, 0xdd, 0x7d, 0x4a, 0x22, 0x06, - 0xd9, 0x1d, 0x9b, 0xce, 0x39, 0x72, 0x9b, 0x4a, 0x63, 0x51, 0xb6, 0x0e, - 0xc5, 0xd1, 0x16, 0xc9, 0x61, 0xdb, 0x90, 0x9e, 0x3f, 0x07, 0x2f, 0x04, - 0x66, 0x30, 0xee, 0x9c, 0x27, 0x70, 0xd9, 0x11, 0xf1, 0x5e, 0x22, 0x83, - 0xa0, 0x79, 0xa8, 0x12, 0x78, 0xdf, 0x38, 0x42, 0x13, 0xd8, 0xcf, 0x6c, - 0xaf, 0xe3, 0x49, 0x58, 0x58, 0xb7, 0x65, 0x81, 0xd7, 0x41, 0x09, 0x47, - 0x2d, 0x3e, 0xd3, 0x08, 0x78, 0x06, 0x74, 0x93, 0xe2, 0x83, 0xb6, 0xa5, - 0x3a, 0x53, 0x49, 0xba, 0xec, 0x81, 0x56, 0x30, 0xad, 0x07, 0x95, 0x97, - 0xee, 0x3d, 0xda, 0x95, 0x3d, 0x0e, 0x3c, 0x3d, 0xfd, 0xee, 0xb5, 0x2e, - 0x2e, 0x5e, 0x6c, 0xcc, 0x83, 0x66, 0x45, 0x1c, 0x40, 0x2c, 0xf2, 0x9c, - 0xbe, 0x34, 0x0d, 0xc0, 0xa1, 0xce, 0xdf, 0x50, 0xe9, 0x56, 0x7b, 0x7e, - 0xcc, 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 0x35, 0x85, 0xa3, 0xd2, - 0xd0, 0x87, 0xe3, 0x04, 0x88, 0xed, 0x08, 0x17, 0xcf, 0xa3, 0x26, 0x9a, - 0x00, 0x93, 0x53, 0xff, 0xc5, 0x6c, 0x72, 0xca, 0x7f, 0x03, 0xc2, 0x07, - 0xfe, 0x1f, 0x53, 0xff, 0x02, 0x2a, 0x13, 0x18, 0xb6, 0xb0, 0x1a, 0x00, - 0x00 + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x03, 0x95, 0x59, + 0x7d, 0x73, 0xdc, 0xb6, 0xd1, 0xff, 0x5b, 0xcf, 0xcc, 0xf3, 0x1d, 0x56, + 0x92, 0x6b, 0x52, 0xf6, 0x1d, 0x4f, 0xa7, 0x17, 0xc7, 0x23, 0xdd, 0x29, + 0xe3, 0x26, 0xce, 0x4b, 0x27, 0x76, 0x3c, 0x91, 0x33, 0x69, 0xc6, 0x75, + 0x33, 0x38, 0x12, 0x14, 0x11, 0xf3, 0x08, 0x16, 0x00, 0x25, 0x5d, 0x13, + 0x7f, 0xf7, 0xee, 0x12, 0x8b, 0xe3, 0xd1, 0x64, 0xd4, 0x74, 0x12, 0x89, + 0x04, 0xb0, 0xef, 0xfb, 0xc3, 0xee, 0x52, 0x5e, 0xec, 0x7f, 0xf9, 0xfd, + 0x17, 0x6f, 0x7f, 0x7e, 0xf3, 0x12, 0x0a, 0xb7, 0x2e, 0xaf, 0xfe, 0xff, + 0xff, 0x16, 0xfc, 0xa4, 0x37, 0x29, 0x32, 0x7c, 0xdb, 0x5b, 0xac, 0xa5, + 0x13, 0x50, 0x89, 0xb5, 0x5c, 0x46, 0xb7, 0x4a, 0xde, 0xd5, 0xda, 0xb8, + 0x08, 0x52, 0x5d, 0x39, 0x59, 0xb9, 0x65, 0x74, 0xa7, 0x32, 0x57, 0x2c, + 0x33, 0x79, 0xab, 0x52, 0x39, 0x6d, 0x17, 0x13, 0x50, 0x95, 0x72, 0x4a, + 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, 0xd9, 0x59, 0x2b, 0xdd, + 0x5b, 0xb5, 0x96, 0xba, 0x71, 0x74, 0x4c, 0xc3, 0xc0, 0x31, 0x3c, 0x41, + 0xaa, 0x11, 0x09, 0x18, 0x58, 0x13, 0xef, 0x7a, 0xb9, 0xcf, 0x58, 0x38, + 0xf2, 0x97, 0x27, 0x97, 0x2e, 0x2d, 0xe2, 0x68, 0x66, 0x3d, 0x8e, 0x7f, + 0xb5, 0xba, 0xfa, 0xbc, 0x5a, 0x52, 0xf2, 0x5e, 0x09, 0x57, 0x24, 0x46, + 0x60, 0xa2, 0xd6, 0x31, 0x82, 0x2b, 0xfa, 0xfa, 0xe5, 0xdb, 0x68, 0x42, + 0x79, 0xbe, 0x76, 0x13, 0x38, 0x19, 0xd3, 0x95, 0x36, 0xa6, 0x73, 0xb4, + 0x0d, 0x71, 0x74, 0x98, 0xcf, 0x91, 0x29, 0xe4, 0x36, 0xec, 0x9d, 0x8c, + 0xec, 0x9d, 0xfa, 0xbd, 0x81, 0x54, 0xaf, 0x31, 0x46, 0xac, 0x66, 0x5e, + 0x34, 0xcf, 0xbc, 0x21, 0x00, 0xc6, 0xb2, 0x20, 0x43, 0x30, 0xc4, 0x80, + 0x91, 0xc7, 0x13, 0x38, 0xa5, 0xdd, 0xad, 0xd3, 0x16, 0xf6, 0x97, 0x38, + 0x92, 0x1f, 0x07, 0x09, 0x7b, 0x74, 0x4b, 0xe8, 0x86, 0x24, 0xaa, 0xaa, + 0xa4, 0x79, 0x8b, 0x2d, 0x8a, 0xd2, 0xf0, 0xe2, 0x4e, 0xa8, 0x9d, 0x5b, + 0x0d, 0x31, 0xc5, 0xc1, 0x12, 0x82, 0x8f, 0x22, 0xaf, 0xe4, 0x23, 0x78, + 0xd8, 0xe1, 0x82, 0x45, 0x53, 0xb9, 0xd1, 0x39, 0x64, 0x88, 0x08, 0x94, + 0x60, 0x9d, 0x41, 0xfe, 0x68, 0xab, 0x67, 0x0f, 0xf7, 0xe1, 0x6f, 0x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02, 0x35, 0x43, 0x2e, 0x68, 0x08, 0xae, 0x0d, 0xe4, 0xcf, 0xb7, + 0xf2, 0x7d, 0x7d, 0x1c, 0x29, 0x7b, 0xfe, 0xb2, 0x37, 0xa6, 0x9c, 0xf0, + 0x14, 0x3a, 0x81, 0x54, 0x94, 0x25, 0x7d, 0xcd, 0x4d, 0xc0, 0xa1, 0xe6, + 0x5f, 0x50, 0xf5, 0x6e, 0x7d, 0xbf, 0x2f, 0x0c, 0xd7, 0xf6, 0xbf, 0xbf, + 0xfa, 0xee, 0x1b, 0xe7, 0xea, 0x1f, 0x24, 0x36, 0x27, 0xeb, 0x62, 0x56, + 0x85, 0xe7, 0x89, 0xae, 0x4a, 0x2d, 0x32, 0x59, 0x65, 0xbd, 0x4e, 0xb1, + 0x35, 0x2f, 0x28, 0x88, 0x91, 0x96, 0xcd, 0x9f, 0x00, 0xbd, 0x1b, 0x69, + 0x6b, 0x5d, 0x59, 0x49, 0xc1, 0x64, 0x71, 0x1f, 0x77, 0x84, 0x3a, 0x1f, + 0x88, 0xff, 0x22, 0x74, 0x3a, 0x9f, 0x78, 0x78, 0x0c, 0x04, 0xd4, 0xb2, + 0x8a, 0x83, 0x93, 0xad, 0xc7, 0x14, 0xea, 0x1d, 0xb3, 0xad, 0x74, 0xec, + 0xcc, 0x37, 0x12, 0xcd, 0xc7, 0x10, 0xbe, 0x40, 0x84, 0xd6, 0x2e, 0x9a, + 0x40, 0x24, 0xea, 0xba, 0x54, 0xbe, 0x35, 0xcd, 0xa8, 0x22, 0x46, 0x3b, + 0x7c, 0x9d, 0x5d, 0x71, 0x88, 0x18, 0xb5, 0x99, 0x39, 0xd6, 0x96, 0x27, + 0x6d, 0x25, 0xde, 0x55, 0x51, 0x65, 0xf1, 0x58, 0x49, 0xbb, 0xd1, 0xee, + 0x45, 0x4d, 0x25, 0x8d, 0x84, 0xef, 0xc6, 0x9b, 0xda, 0x76, 0xd7, 0x06, + 0x3d, 0x92, 0xb0, 0x6c, 0x11, 0x8c, 0x89, 0x14, 0xf6, 0xf9, 0x32, 0x8c, + 0x14, 0x20, 0x3a, 0xef, 0xd5, 0xa0, 0xc0, 0x94, 0x94, 0xb2, 0xba, 0x71, + 0x05, 0x62, 0xe6, 0xb8, 0xc3, 0x0c, 0x29, 0xea, 0x57, 0x26, 0x22, 0x1d, + 0x42, 0x6e, 0x28, 0x5d, 0xaf, 0x7e, 0x95, 0xa9, 0x8b, 0x06, 0xa2, 0x88, + 0xa2, 0x57, 0xdb, 0xf8, 0x28, 0xb1, 0xda, 0xb8, 0xb8, 0xcb, 0xa1, 0x98, + 0xc0, 0x8a, 0x99, 0xbb, 0x86, 0xb6, 0x4a, 0x8c, 0xb5, 0x0a, 0xa6, 0x20, + 0xda, 0x97, 0x20, 0x27, 0xd8, 0x43, 0xa1, 0xd1, 0xb5, 0xa5, 0x12, 0xbd, + 0xd0, 0x35, 0xc9, 0xb9, 0xf2, 0xe3, 0x11, 0x88, 0x70, 0x6f, 0xdb, 0x09, + 0x8c, 0xcf, 0x22, 0x66, 0xcb, 0xb5, 0x81, 0x98, 0x78, 0x15, 0x72, 0x1e, + 0x5f, 0xe2, 0x63, 0xd1, 0x46, 0x98, 0x23, 0x72, 0x09, 0x4f, 0x9f, 0xaa, + 0xce, 0x14, 0x52, 0xf0, 0x74, 0x47, 0x03, 0xd5, 0x7e, 0xa2, 0x7e, 0xa7, + 0xde, 0x27, 0x68, 0x53, 0x86, 0xcb, 0x68, 0xa0, 0xe2, 0xa3, 0x7f, 0x88, + 0xda, 0x17, 0x86, 0x6f, 0xde, 0xbe, 0xfa, 0x0e, 0x96, 0x64, 0x2b, 0x9f, + 0x8b, 0x15, 0xb5, 0x79, 0xb1, 0x2a, 0xbb, 0x09, 0x8b, 0x4f, 0x9c, 0xbe, + 0x41, 0x0c, 0x50, 0x36, 0x19, 0x9a, 0x1d, 0x87, 0xae, 0x52, 0x84, 0xdf, + 0x07, 0x64, 0x68, 0x89, 0x86, 0x9d, 0x87, 0xa8,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87, 0xb2, 0xbb, + 0xfb, 0x69, 0x43, 0x24, 0x85, 0xa8, 0x6e, 0xe4, 0x78, 0x83, 0x78, 0xb4, + 0xcd, 0x6f, 0xd2, 0x7e, 0x37, 0xf7, 0x3f, 0x8c, 0x78, 0x93, 0xd3, 0xda, + 0x09, 0xc7, 0xcf, 0x47, 0x3c, 0x63, 0xe5, 0x43, 0xc1, 0xfd, 0x66, 0xeb, + 0x99, 0x47, 0x46, 0xcf, 0xe3, 0x24, 0x5c, 0x2c, 0x95, 0xc7, 0x21, 0x30, + 0x47, 0x40, 0x9c, 0x07, 0x38, 0xe7, 0x1e, 0x6c, 0x43, 0x0b, 0xb0, 0x98, + 0x6d, 0x3f, 0x12, 0x17, 0x33, 0xfe, 0x9b, 0x15, 0xbd, 0xf2, 0x3f, 0xef, + 0xfd, 0x07, 0xb4, 0xda, 0xa2, 0xb2, 0xf8, 0x1b, 0x00, 0x00 }; -unsigned int enduser_setup_html_default_len = 2569; +unsigned int enduser_setup_html_default_len = 2590; From bd0549ac4aca3455d161bc81b05459d396061854 Mon Sep 17 00:00:00 2001 From: Gregor Date: Sun, 14 Jul 2019 21:48:07 +0200 Subject: [PATCH 35/74] fix rounding in ws2812:buffer:mix --- app/modules/ws2812.c | 1 + 1 file changed, 1 insertion(+) diff --git a/app/modules/ws2812.c b/app/modules/ws2812.c index a962fc8b2b..3be67e89d6 100644 --- a/app/modules/ws2812.c +++ b/app/modules/ws2812.c @@ -425,6 +425,7 @@ static int ws2812_buffer_mix(lua_State* L) { val += (int32_t)(source[src].values[i] * source[src].factor); } + val += 128; // rounding istead of floor val >>= 8; if (val < 0) { From 9f8b74debd9f030d63f8b4db3db07bc15b748765 Mon Sep 17 00:00:00 2001 From: Nathaniel Wesley Filardo Date: Tue, 16 Jul 2019 10:30:41 +0100 Subject: [PATCH 36/74] MQTT tweaks (#2822) * mqtt:connect() secure parameter should be boolean Continue to honor the old 0/1 values, but make them undocumented and add a deprecation warning to the code and docs. Eventually, this should go away. * mqtt: rip out deprecated autoreconnect * mqtt: expose all the callbacks via :on --- app/modules/mqtt.c | 105 +++++++++++++++---------------------------- docs/modules/mqtt.md | 48 ++++++++++++-------- 2 files changed, 67 insertions(+), 86 deletions(-) diff --git a/app/modules/mqtt.c b/app/modules/mqtt.c index 92570c04ec..2a411e9f26 100644 --- a/app/modules/mqtt.c +++ b/app/modules/mqtt.c @@ -50,10 +50,6 @@ typedef struct mqtt_event_data_t uint16_t data_offset; } mqtt_event_data_t; -#define RECONNECT_OFF 0 -#define RECONNECT_POSSIBLE 1 -#define RECONNECT_ON 2 - typedef enum { MQTT_RECV_NORMAL, MQTT_RECV_BUFFERING_SHORT, @@ -64,7 +60,6 @@ typedef enum { typedef struct mqtt_state_t { uint16_t port; - uint8_t auto_reconnect; // 0 is not auto_reconnect. 1 is auto reconnect, but never connected. 2 is auto reconnect, but once connected mqtt_connect_info_t* connect_info; mqtt_connection_t mqtt_connection; msg_queue_t* pending_msg_q; @@ -144,31 +139,19 @@ static void mqtt_socket_disconnected(void *arg) // tcp only mud->mqtt_state.recv_buffer_size = 0; mud->mqtt_state.recv_buffer_state = MQTT_RECV_NORMAL; - if(mud->mqtt_state.auto_reconnect == RECONNECT_ON) { - mud->pesp_conn->reverse = mud; - mud->pesp_conn->type = ESPCONN_TCP; - mud->pesp_conn->state = ESPCONN_NONE; - mud->connected = false; - mud->pesp_conn->proto.tcp->remote_port = mud->mqtt_state.port; - mud->pesp_conn->proto.tcp->local_port = espconn_port(); - espconn_regist_connectcb(mud->pesp_conn, mqtt_socket_connected); - espconn_regist_reconcb(mud->pesp_conn, mqtt_socket_reconnected); - socket_connect(pesp_conn); - } else { - if(mud->pesp_conn){ - mud->pesp_conn->reverse = NULL; - if(mud->pesp_conn->proto.tcp) - c_free(mud->pesp_conn->proto.tcp); - mud->pesp_conn->proto.tcp = NULL; - c_free(mud->pesp_conn); - mud->pesp_conn = NULL; - } - - mud->connected = false; - luaL_unref(L, LUA_REGISTRYINDEX, mud->self_ref); - mud->self_ref = LUA_NOREF; // unref this, and the mqtt.socket userdata will delete it self + if(mud->pesp_conn){ + mud->pesp_conn->reverse = NULL; + if(mud->pesp_conn->proto.tcp) + c_free(mud->pesp_conn->proto.tcp); + mud->pesp_conn->proto.tcp = NULL; + c_free(mud->pesp_conn); + mud->pesp_conn = NULL; } + mud->connected = false; + luaL_unref(L, LUA_REGISTRYINDEX, mud->self_ref); + mud->self_ref = LUA_NOREF; // unref this, and the mqtt.socket userdata will delete it self + if(call_back){ lua_call(L, 1, 0); } @@ -191,24 +174,18 @@ static void mqtt_socket_reconnected(void *arg, sint8_t err) mud->event_timeout = 0; // no need to count anymore - if(mud->mqtt_state.auto_reconnect == RECONNECT_ON) { - pesp_conn->proto.tcp->remote_port = mud->mqtt_state.port; - pesp_conn->proto.tcp->local_port = espconn_port(); - socket_connect(pesp_conn); - } else { #ifdef CLIENT_SSL_ENABLE - if (mud->secure) { - espconn_secure_disconnect(pesp_conn); - } else + if (mud->secure) { + espconn_secure_disconnect(pesp_conn); + } else #endif - { - espconn_disconnect(pesp_conn); - } + { + espconn_disconnect(pesp_conn); + } - mqtt_connack_fail(mud, MQTT_CONN_FAIL_SERVER_NOT_FOUND); + mqtt_connack_fail(mud, MQTT_CONN_FAIL_SERVER_NOT_FOUND); - mqtt_socket_disconnected(arg); - } + mqtt_socket_disconnected(arg); NODE_DBG("leave mqtt_socket_reconnected.\n"); } @@ -475,9 +452,6 @@ static void mqtt_socket_received(void *arg, char *pdata, unsigned short len) mud->keepalive_sent = 0; luaL_unref(L, LUA_REGISTRYINDEX, mud->cb_connect_fail_ref); mud->cb_connect_fail_ref = LUA_NOREF; - if (mud->mqtt_state.auto_reconnect == RECONNECT_POSSIBLE) { - mud->mqtt_state.auto_reconnect = RECONNECT_ON; - } if(mud->cb_connect_ref == LUA_NOREF) break; if(mud->self_ref == LUA_NOREF) @@ -1050,7 +1024,6 @@ static int mqtt_socket_client( lua_State* L ) mud->connect_info.max_message_length = max_message_length; mud->mqtt_state.pending_msg_q = NULL; - mud->mqtt_state.auto_reconnect = RECONNECT_OFF; mud->mqtt_state.port = 1883; mud->mqtt_state.connect_info = &mud->connect_info; mud->mqtt_state.recv_buffer = NULL; @@ -1242,7 +1215,7 @@ static sint8 socket_dns_found(const char *name, ip_addr_t *ipaddr, void *arg) } #include "pm/swtimer.h" -// Lua: mqtt:connect( host, port, secure, auto_reconnect, function(client), function(client, connect_return_code) ) +// Lua: mqtt:connect( host, port, secure, function(client), function(client, connect_return_code) ) static int mqtt_socket_connect( lua_State* L ) { NODE_DBG("enter mqtt_socket_connect.\n"); @@ -1252,7 +1225,7 @@ static int mqtt_socket_connect( lua_State* L ) ip_addr_t ipaddr; const char *domain; int stack = 1; - unsigned secure = 0, auto_reconnect = RECONNECT_OFF; + unsigned secure = 0; int top = lua_gettop(L); sint8 espconn_status; @@ -1315,13 +1288,15 @@ static int mqtt_socket_connect( lua_State* L ) pesp_conn->proto.tcp->local_port = espconn_port(); mud->mqtt_state.port = port; - if ( (stack<=top) && lua_isnumber(L, stack) ) + if ( (stack<=top) && (lua_isnumber(L, stack) || lua_isboolean(L, stack)) ) { - secure = lua_tointeger(L, stack); - stack++; - if ( secure != 0 && secure != 1 ){ - secure = 0; // default to 0 + if (lua_isnumber(L, stack)) { + platform_print_deprecation_note("mqtt.connect secure parameter as integer","in the future"); + secure = !!lua_tointeger(L, stack); + } else { + secure = lua_toboolean(L, stack); } + stack++; } else { secure = 0; // default to 0 } @@ -1334,19 +1309,6 @@ static int mqtt_socket_connect( lua_State* L ) } #endif - if ( (stack<=top) && lua_isnumber(L, stack) ) - { - platform_print_deprecation_note("autoreconnect is deprecated", "in the next version"); - auto_reconnect = lua_tointeger(L, stack); - stack++; - if ( auto_reconnect != RECONNECT_OFF && auto_reconnect != RECONNECT_POSSIBLE ){ - auto_reconnect = RECONNECT_OFF; // default to 0 - } - } else { - auto_reconnect = RECONNECT_OFF; // default to 0 - } - mud->mqtt_state.auto_reconnect = auto_reconnect; - // call back function when a connection is obtained, tcp only if ((stack<=top) && (lua_type(L, stack) == LUA_TFUNCTION || lua_type(L, stack) == LUA_TLIGHTFUNCTION)){ lua_pushvalue(L, stack); // copy argument (func) to the top of stack @@ -1416,8 +1378,6 @@ static int mqtt_socket_close( lua_State* L ) return 1; } - mud->mqtt_state.auto_reconnect = RECONNECT_OFF; // stop auto reconnect. - sint8 espconn_status = ESPCONN_CONN; if (mud->connected) { // Send disconnect message @@ -1486,6 +1446,15 @@ static int mqtt_socket_on( lua_State* L ) }else if( sl == 8 && c_strcmp(method, "overflow") == 0){ luaL_unref(L, LUA_REGISTRYINDEX, mud->cb_overflow_ref); mud->cb_overflow_ref = luaL_ref(L, LUA_REGISTRYINDEX); + }else if( sl == 6 && c_strcmp(method, "puback") == 0){ + luaL_unref(L, LUA_REGISTRYINDEX, mud->cb_puback_ref); + mud->cb_puback_ref = luaL_ref(L, LUA_REGISTRYINDEX); + }else if( sl == 6 && c_strcmp(method, "suback") == 0){ + luaL_unref(L, LUA_REGISTRYINDEX, mud->cb_suback_ref); + mud->cb_suback_ref = luaL_ref(L, LUA_REGISTRYINDEX); + }else if( sl == 8 && c_strcmp(method, "unsuback") == 0){ + luaL_unref(L, LUA_REGISTRYINDEX, mud->cb_unsuback_ref); + mud->cb_unsuback_ref = luaL_ref(L, LUA_REGISTRYINDEX); }else{ lua_pop(L, 1); return luaL_error( L, "method not supported" ); diff --git a/docs/modules/mqtt.md b/docs/modules/mqtt.md index 64817e1950..bf285a3554 100644 --- a/docs/modules/mqtt.md +++ b/docs/modules/mqtt.md @@ -123,13 +123,12 @@ none Connects to the broker specified by the given host, port, and secure options. #### Syntax -`mqtt:connect(host[, port[, secure[, autoreconnect]]][, function(client)[, function(client, reason)]])` +`mqtt:connect(host[, port[, secure]][, function(client)[, function(client, reason)]])` #### Parameters - `host` host, domain or IP (string) - `port` broker port (number), default 1883 -- `secure` 0/1 for `false`/`true`, default 0. Take note of constraints documented in the [net module](net.md). -- `autoreconnect` 0/1 for `false`/`true`, default 0. This option is *deprecated*. +- `secure` boolean: if `true`, use TLS. Take note of constraints documented in the [net module](net.md). - `function(client)` callback function for when the connection was established - `function(client, reason)` callback function for when the connection could not be established. No further callbacks should be called. @@ -138,11 +137,8 @@ Connects to the broker specified by the given host, port, and secure options. #### Notes -Don't use `autoreconnect`. Let me repeat that, don't use `autoreconnect`. You should handle the errors explicitly and appropriately for -your application. In particular, the default for `cleansession` above is `true`, so all subscriptions are destroyed when the connection -is lost for any reason. - -In order to acheive a consistent connection, handle errors in the error callback. For example: +An application should watch for connection failures and handle errors in the error callback, +in order to achieve a reliable connection to the server. For example: ``` function handle_mqtt_error(client, reason) @@ -156,13 +152,12 @@ end In reality, the connected function should do something useful! -This is the description of how the `autoreconnect` functionality may (or may not) work. +The two callbacks to `:connect()` alias with the "connect" and "offline" +callbacks available through `:on()`. -> When `autoreconnect` is set, then the connection will be re-established when it breaks. No error indication will be given (but all the -> subscriptions may be lost if `cleansession` is true). However, if the -> very first connection fails, then no reconnect attempt is made, and the error is signalled through the callback (if any). The first connection -> is considered a success if the client connects to a server and gets back a good response packet in response to its MQTT connection request. -> This implies (for example) that the username and password are correct. +Previously, we instructed an application to pass either the *integer* 0 or +*integer* 1 for `secure`. Now, this will trigger a deprecation warning; please +use the *boolean* `false` or `true` instead. #### Connection failure callback reason codes: @@ -213,7 +208,7 @@ Registers a callback function for an event. `mqtt:on(event, function(client[, topic[, message]]))` #### Parameters -- `event` can be "connect", "message", "offline" or "overflow" +- `event` can be "connect", "suback", "unsuback", "puback", "message", "overflow", or "offline" - `function(client[, topic[, message]])` callback function. The first parameter is the client. If event is "message", the 2nd and 3rd param are received topic and message (strings). #### Returns @@ -231,8 +226,13 @@ Publishes a message. - `message` the message to publish, (buffer or string) - `qos` QoS level - `retain` retain flag -- `function(client)` optional callback fired when PUBACK received. NOTE: When calling publish() more than once, the last callback function defined will be called for ALL publish commands. +- `function(client)` optional callback fired when PUBACK received. + +#### Notes +When calling publish() more than once, the last callback function defined will +be called for ALL publish commands. This callback argument also aliases with +the "puback" callback for `:on()`. #### Returns `true` on success, `false` otherwise @@ -249,7 +249,13 @@ Subscribes to one or several topics. - `topic` a [topic string](http://www.hivemq.com/blog/mqtt-essentials-part-5-mqtt-topics-best-practices) - `qos` QoS subscription level, default 0 - `table` array of 'topic, qos' pairs to subscribe to -- `function(client)` optional callback fired when subscription(s) succeeded. NOTE: When calling subscribe() more than once, the last callback function defined will be called for ALL subscribe commands. +- `function(client)` optional callback fired when subscription(s) succeeded. + +#### Notes + +When calling subscribe() more than once, the last callback function defined +will be called for ALL subscribe commands. This callback argument also aliases +with the "suback" callback for `:on()`. #### Returns `true` on success, `false` otherwise @@ -278,7 +284,13 @@ Unsubscribes from one or several topics. #### Parameters - `topic` a [topic string](http://www.hivemq.com/blog/mqtt-essentials-part-5-mqtt-topics-best-practices) - `table` array of 'topic, anything' pairs to unsubscribe from -- `function(client)` optional callback fired when unsubscription(s) succeeded. NOTE: When calling unsubscribe() more than once, the last callback function defined will be called for ALL unsubscribe commands. +- `function(client)` optional callback fired when unsubscription(s) succeeded. + +#### Notes + +When calling subscribe() more than once, the last callback function defined +will be called for ALL subscribe commands. This callback argument also aliases +with the "unsuback" callback for `:on()`. #### Returns `true` on success, `false` otherwise From 526d21dab44b7f9b3868a8700a8bfac232c463c1 Mon Sep 17 00:00:00 2001 From: Johny Mattsson Date: Mon, 22 Jul 2019 07:58:21 +1000 Subject: [PATCH 37/74] Major cleanup - c_whatever is finally history. (#2838) The PR removed the bulk of non-newlib headers from the NodeMCU source base. app/libc has now been cut down to the bare minimum overrides to shadow the corresponding functions in the SDK's libc. The old c_xyz.h headerfiles have been nuked in favour of the standard headers, with a few exceptions over in sdk-overrides. Again, shipping a libc.a without headers is a terrible thing to do. We're still living on a prayer that libc was configured the same was as a default-configured xtensa gcc toolchain assumes it is. That part I cannot do anything about, unfortunately, but it's no worse than it has been before. This enables our source files to compile successfully using the standard header files, and use the typical malloc()/calloc()/realloc()/free(), the strwhatever()s and memwhatever()s. These end up, through macro and linker magic, mapped to the appropriate SDK or ROM functions. --- app/Makefile | 28 +-- app/coap/coap.c | 50 ++--- app/coap/coap.h | 4 +- app/coap/coap_io.c | 6 +- app/coap/coap_server.c | 4 +- app/coap/coap_timer.c | 1 + app/coap/endpoints.c | 70 +++--- app/coap/hash.c | 4 +- app/coap/node.c | 10 +- app/coap/pdu.c | 30 +-- app/coap/str.c | 8 +- app/coap/str.h | 2 +- app/coap/uri.c | 16 +- app/crypto/digests.c | 3 +- app/crypto/mech.c | 7 +- app/dht/dht.c | 2 +- app/driver/i2c_master.c | 2 +- app/driver/rotary.c | 8 +- app/driver/switec.c | 16 +- app/fatfs/myfatfs.c | 147 ++++++------- app/http/httpclient.c | 2 +- app/include/pm/pmSleep.h | 2 +- app/include/user_config.h | 5 + app/include/user_mbedtls.h | 6 +- app/libc/c_ctype.c | 16 -- app/libc/c_ctype.h | 42 ---- app/libc/c_errno.h | 19 -- app/libc/c_fcntl.h | 9 - app/libc/c_limits.h | 58 ----- app/libc/c_locale.h | 62 ------ app/libc/c_math.h | 62 ------ app/libc/c_signal.h | 6 - app/libc/c_stdarg.h | 22 -- app/libc/c_stddef.h | 23 -- app/libc/c_stdint.h | 273 ------------------------ app/libc/c_stdio.h | 105 --------- app/libc/c_stdlib.h | 64 ------ app/libc/c_string.c | 129 ----------- app/libc/c_string.h | 50 ----- app/libc/{c_math.c => math.c} | 105 +-------- app/libc/{c_stdio.c => stdio.c} | 102 +++------ app/libc/{c_stdlib.c => stdlib.c} | 23 +- app/lua/lapi.c | 7 +- app/lua/lauxlib.c | 69 +++--- app/lua/lauxlib.h | 6 - app/lua/lbaselib.c | 16 +- app/lua/lcode.c | 4 +- app/lua/ldblib.c | 38 ++-- app/lua/ldebug.c | 8 +- app/lua/ldo.c | 2 +- app/lua/ldump.c | 14 +- app/lua/lflash.c | 20 +- app/lua/lfunc.c | 4 +- app/lua/lgc.c | 8 +- app/lua/llex.c | 10 +- app/lua/llimits.h | 2 - app/lua/lmathlib.c | 4 +- app/lua/lmem.h | 6 - app/lua/loadlib.c | 22 +- app/lua/lobject.c | 34 +-- app/lua/lobject.h | 4 - app/lua/lparser.c | 2 +- app/lua/lrotable.c | 8 +- app/lua/lstring.c | 8 +- app/lua/lstring.h | 2 +- app/lua/lstrlib.c | 32 +-- app/lua/ltable.c | 6 +- app/lua/ltm.c | 2 +- app/lua/lua.c | 33 ++- app/lua/lua.h | 14 +- app/lua/luac_cross/Makefile | 5 +- app/lua/luac_cross/mingw32-Makefile.mak | 3 +- app/lua/luaconf.h | 38 +--- app/lua/lundump.c | 6 +- app/lua/lundump.h | 4 - app/lua/lvm.c | 12 +- app/lua/lzio.c | 4 +- app/mbedtls/library/platform.c | 9 - app/mbedtls/platform/mbedtls_mem.c | 4 + app/mbedtls/platform/memcompat.c | 3 + app/modules/ads1115.c | 2 +- app/modules/adxl345.c | 4 +- app/modules/apa102.c | 4 +- app/modules/bit.c | 2 +- app/modules/bloom.c | 1 + app/modules/bme280.c | 2 +- app/modules/bme680.c | 2 +- app/modules/bmp085.c | 4 +- app/modules/coap.c | 46 ++-- app/modules/color_utils.c | 6 +- app/modules/color_utils.h | 6 +- app/modules/cron.c | 4 +- app/modules/crypto.c | 4 +- app/modules/encoder.c | 6 +- app/modules/enduser_setup.c | 202 +++++++++--------- app/modules/file.c | 14 +- app/modules/gpio.c | 2 +- app/modules/gpio_pulse.c | 2 +- app/modules/hdc1080.c | 6 +- app/modules/hmc5883l.c | 4 +- app/modules/http.c | 4 +- app/modules/hx711.c | 4 +- app/modules/l3g4200d.c | 4 +- app/modules/mdns.c | 16 +- app/modules/mqtt.c | 102 ++++----- app/modules/net.c | 15 +- app/modules/node.c | 20 +- app/modules/pcm.c | 18 +- app/modules/perf.c | 2 +- app/modules/rotary.c | 6 +- app/modules/rtcfifo.c | 1 + app/modules/sjson.c | 6 +- app/modules/sntp.c | 18 +- app/modules/sqlite3.c | 18 +- app/modules/tcs34725.c | 2 +- app/modules/tls.c | 24 +-- app/modules/tm1829.c | 8 +- app/modules/tmr.c | 24 +-- app/modules/uart.c | 4 +- app/modules/websocket.c | 16 +- app/modules/wifi.c | 60 +++--- app/modules/wifi_common.c | 2 +- app/modules/wifi_common.h | 15 +- app/modules/wifi_eventmon.c | 6 +- app/modules/wifi_monitor.c | 12 +- app/modules/ws2801.c | 5 +- app/modules/ws2812.c | 36 ++-- app/modules/ws2812.h | 6 +- app/modules/ws2812_effects.c | 14 +- app/mqtt/mqtt_msg.c | 26 +-- app/mqtt/msg_queue.c | 19 +- app/net/nodemcu_mdns.c | 34 +-- app/pcm/drv_sigma_delta.c | 2 +- app/pcm/pcm_core.c | 10 +- app/platform/common.c | 8 +- app/platform/flash_api.c | 5 +- app/platform/hw_timer.c | 6 +- app/platform/platform.c | 28 +-- app/platform/u8x8_nodemcu_hal.c | 16 +- app/platform/ucg_nodemcu_hal.c | 2 +- app/platform/vfs.c | 97 ++++----- app/platform/vfs.h | 42 ++-- app/platform/vfs_int.h | 58 +++-- app/pm/swtimer.c | 21 +- app/sjson/memcompat.h | 4 - app/smart/smart.c | 64 +++--- app/spiffs/Makefile | 1 - app/spiffs/nodemcu_spiffs.h | 7 +- app/spiffs/spiffs.c | 42 ++-- app/sqlite3/esp8266.c | 8 +- app/sqlite3/sqlite3.c | 14 +- app/task/task.c | 2 +- app/u8g2lib/u8x8_d_fbrle.c | 6 +- app/{libc => user}/dbg_printf.c | 6 +- app/user/user_main.c | 6 +- app/uzlib/uzlib.h | 14 +- app/uzlib/uzlib_inflate.c | 4 - app/websocket/websocketclient.c | 40 ++-- ld/defsym.rom | 1 + sdk-overrides/include/c_types.h | 11 - sdk-overrides/include/ets_sys.h | 2 +- sdk-overrides/include/mem.h | 2 + sdk-overrides/include/osapi.h | 9 +- sdk-overrides/include/stdbool.h | 7 + sdk-overrides/include/stdio.h | 21 ++ sdk-overrides/include/stdlib.h | 13 ++ 166 files changed, 1202 insertions(+), 2323 deletions(-) delete mode 100644 app/libc/c_ctype.c delete mode 100644 app/libc/c_ctype.h delete mode 100644 app/libc/c_errno.h delete mode 100644 app/libc/c_fcntl.h delete mode 100644 app/libc/c_limits.h delete mode 100644 app/libc/c_locale.h delete mode 100644 app/libc/c_math.h delete mode 100644 app/libc/c_signal.h delete mode 100644 app/libc/c_stdarg.h delete mode 100644 app/libc/c_stddef.h delete mode 100644 app/libc/c_stdint.h delete mode 100644 app/libc/c_stdio.h delete mode 100644 app/libc/c_stdlib.h delete mode 100644 app/libc/c_string.c delete mode 100644 app/libc/c_string.h rename app/libc/{c_math.c => math.c} (72%) rename app/libc/{c_stdio.c => stdio.c} (95%) rename app/libc/{c_stdlib.c => stdlib.c} (92%) create mode 100644 app/mbedtls/platform/mbedtls_mem.c create mode 100644 app/mbedtls/platform/memcompat.c rename app/{libc => user}/dbg_printf.c (98%) delete mode 100644 sdk-overrides/include/c_types.h create mode 100644 sdk-overrides/include/mem.h create mode 100644 sdk-overrides/include/stdbool.h create mode 100644 sdk-overrides/include/stdio.h create mode 100644 sdk-overrides/include/stdlib.h diff --git a/app/Makefile b/app/Makefile index 52c57da566..897b3f8b04 100644 --- a/app/Makefile +++ b/app/Makefile @@ -90,31 +90,33 @@ COMPONENTS_eagle.app.v6 = \ # 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 \ - -Wl,-Map=mapfile \ +LINKFLAGS_eagle.app.v6 = \ + -Wl,--gc-sections \ + -Wl,-Map=mapfile \ -nostdlib \ - -T$(LD_FILE) \ - -Wl,@../ld/defsym.rom \ - -Wl,--no-check-sections \ - -Wl,-static \ + -T$(LD_FILE) \ + -Wl,@../ld/defsym.rom \ + -Wl,--no-check-sections \ + -Wl,-static \ $(addprefix -u , $(SELECTED_MODULE_SYMS)) \ - -Wl,--start-group \ + -Wl,--start-group \ -lmain \ - -lc \ + $(DEP_LIBS_eagle.app.v6)\ + -Wl,--end-group \ + -Wl,--start-group \ -lgcc \ -lhal \ -lphy \ -lpp \ -lnet80211 \ + -lsmartconfig \ -lwpa \ -lwpa2 \ - -lsmartconfig \ -lcrypto \ -lwps \ - $(DEP_LIBS_eagle.app.v6) \ - -Wl,--end-group \ - -lm + -lc \ + -lm \ + -Wl,--end-group # -Wl,--cref # -Wl,--wrap=_xtos_set_exception_handler diff --git a/app/coap/coap.c b/app/coap/coap.c index f207a953fd..e487c3ab7c 100644 --- a/app/coap/coap.c +++ b/app/coap/coap.c @@ -1,6 +1,6 @@ #include "user_config.h" -#include "c_stdio.h" -#include "c_string.h" +#include +#include #include "coap.h" #include "uri.h" @@ -10,12 +10,12 @@ extern const coap_endpoint_t endpoints[]; #ifdef COAP_DEBUG void coap_dumpHeader(coap_header_t *hdr) { - c_printf("Header:\n"); - c_printf(" ver 0x%02X\n", hdr->ver); - c_printf(" t 0x%02X\n", hdr->ver); - c_printf(" tkl 0x%02X\n", hdr->tkl); - c_printf(" code 0x%02X\n", hdr->code); - c_printf(" id 0x%02X%02X\n", hdr->id[0], hdr->id[1]); + printf("Header:\n"); + printf(" ver 0x%02X\n", hdr->ver); + printf(" t 0x%02X\n", hdr->ver); + printf(" tkl 0x%02X\n", hdr->tkl); + printf(" code 0x%02X\n", hdr->code); + printf(" id 0x%02X%02X\n", hdr->id[0], hdr->id[1]); } void coap_dump(const uint8_t *buf, size_t buflen, bool bare) @@ -23,14 +23,14 @@ void coap_dump(const uint8_t *buf, size_t buflen, bool bare) if (bare) { while(buflen--) - c_printf("%02X%s", *buf++, (buflen > 0) ? " " : ""); + printf("%02X%s", *buf++, (buflen > 0) ? " " : ""); } else { - c_printf("Dump: "); + printf("Dump: "); while(buflen--) - c_printf("%02X%s", *buf++, (buflen > 0) ? " " : ""); - c_printf("\n"); + printf("%02X%s", *buf++, (buflen > 0) ? " " : ""); + printf("\n"); } } #endif @@ -100,7 +100,7 @@ int coap_buildToken(const coap_buffer_t *tokbuf, const coap_header_t *hdr, uint8 return COAP_ERR_UNSUPPORTED; if (hdr->tkl > 0) - c_memcpy(p, tokbuf->p, hdr->tkl); + memcpy(p, tokbuf->p, hdr->tkl); // http://tools.ietf.org/html/rfc7252#section-3.1 // inject options @@ -260,12 +260,12 @@ int coap_buildOptionHeader(uint32_t optDelta, size_t length, uint8_t *buf, size_ void coap_dumpOptions(coap_option_t *opts, size_t numopt) { size_t i; - c_printf(" Options:\n"); + printf(" Options:\n"); for (i=0;ihdr); coap_dumpOptions(pkt->opts, pkt->numopts); - c_printf("Payload: "); + printf("Payload: "); coap_dump(pkt->payload.p, pkt->payload.len, true); - c_printf("\n"); + printf("\n"); } #endif @@ -325,7 +325,7 @@ int coap_buffer_to_string(char *strbuf, size_t strbuflen, const coap_buffer_t *b { if (buf->len+1 > strbuflen) return COAP_ERR_BUFFER_TOO_SMALL; - c_memcpy(strbuf, buf->p, buf->len); + memcpy(strbuf, buf->p, buf->len); strbuf[buf->len] = 0; return 0; } @@ -360,7 +360,7 @@ int coap_build(uint8_t *buf, size_t *buflen, const coap_packet_t *pkt) p += rc; left -= rc; - c_memcpy(p, pkt->opts[i].buf.p, pkt->opts[i].buf.len); + memcpy(p, pkt->opts[i].buf.p, pkt->opts[i].buf.len); p += pkt->opts[i].buf.len; left -= pkt->opts[i].buf.len; running_delta = pkt->opts[i].num; @@ -373,7 +373,7 @@ int coap_build(uint8_t *buf, size_t *buflen, const coap_packet_t *pkt) if (*buflen < 4 + 1 + pkt->payload.len + opts_len) return COAP_ERR_BUFFER_TOO_SMALL; buf[4 + opts_len] = 0xFF; // payload marker - c_memcpy(buf+5 + opts_len, pkt->payload.p, pkt->payload.len); + memcpy(buf+5 + opts_len, pkt->payload.p, pkt->payload.len); *buflen = opts_len + 5 + pkt->payload.len; } else @@ -471,7 +471,7 @@ int coap_make_request(coap_rw_buffer_t *scratch, coap_packet_t *pkt, coap_msgtyp /* split arg into Uri-* options */ // const char *addr = uri->host.s; - // if(uri->host.length && (c_strlen(addr) != uri->host.length || c_memcmp(addr, uri->host.s, uri->host.length) != 0)){ + // if(uri->host.length && (strlen(addr) != uri->host.length || memcmp(addr, uri->host.s, uri->host.length) != 0)){ if(uri->host.length){ /* add Uri-Host */ // addr is destination address @@ -525,9 +525,9 @@ int coap_handle_req(coap_rw_buffer_t *scratch, const coap_packet_t *inpkt, coap_ goto next; for (i=0;ipath->count;i++) { - if (opt[i].buf.len != c_strlen(ep->path->elems[i])) + if (opt[i].buf.len != strlen(ep->path->elems[i])) goto next; - if (0 != c_memcmp(ep->path->elems[i], opt[i].buf.p, opt[i].buf.len)) + if (0 != memcmp(ep->path->elems[i], opt[i].buf.p, opt[i].buf.len)) goto next; } // pre-path match! @@ -551,5 +551,5 @@ void coap_setup(void) int check_token(coap_packet_t *pkt) { - return pkt->tok.len == the_token.len && c_memcmp(pkt->tok.p, the_token.p, the_token.len) == 0; + return pkt->tok.len == the_token.len && memcmp(pkt->tok.p, the_token.p, the_token.len) == 0; } diff --git a/app/coap/coap.h b/app/coap/coap.h index a931cbd93a..97c35cb4b4 100644 --- a/app/coap/coap.h +++ b/app/coap/coap.h @@ -5,8 +5,8 @@ extern "C" { #endif -#include "c_stdint.h" -#include "c_stddef.h" +#include +#include #include "lualib.h" #include "lauxlib.h" diff --git a/app/coap/coap_io.c b/app/coap/coap_io.c index 7d19fd872b..21feade4b3 100644 --- a/app/coap/coap_io.c +++ b/app/coap/coap_io.c @@ -1,4 +1,4 @@ -#include "c_string.h" +#include #include "coap_io.h" #include "node.h" #include "espconn.h" @@ -16,10 +16,10 @@ coap_tid_t coap_send(struct espconn *pesp_conn, coap_pdu_t *pdu) { espconn_sent(pesp_conn, (unsigned char *)(pdu->msg.p), pdu->msg.len); if(pesp_conn->type == ESPCONN_TCP){ - c_memcpy(&ip, pesp_conn->proto.tcp->remote_ip, sizeof(ip)); + memcpy(&ip, pesp_conn->proto.tcp->remote_ip, sizeof(ip)); port = pesp_conn->proto.tcp->remote_port; }else{ - c_memcpy(&ip, pesp_conn->proto.udp->remote_ip, sizeof(ip)); + memcpy(&ip, pesp_conn->proto.udp->remote_ip, sizeof(ip)); port = pesp_conn->proto.udp->remote_port; } coap_transaction_id(ip, port, pdu->pkt, &id); diff --git a/app/coap/coap_server.c b/app/coap/coap_server.c index cbec01f96b..55c171f984 100644 --- a/app/coap/coap_server.c +++ b/app/coap/coap_server.c @@ -1,6 +1,6 @@ #include "user_config.h" #include "c_types.h" -#include "c_stdlib.h" +#include #include "coap.h" @@ -51,7 +51,7 @@ size_t coap_server_respond(char *req, unsigned short reqlen, char *rsp, unsigned #endif } if(rsppkt.content.p){ - c_free(rsppkt.content.p); + free(rsppkt.content.p); rsppkt.content.p = NULL; rsppkt.content.len = 0; } diff --git a/app/coap/coap_timer.c b/app/coap/coap_timer.c index 384ecab22f..c8434193f0 100644 --- a/app/coap/coap_timer.c +++ b/app/coap/coap_timer.c @@ -1,6 +1,7 @@ #include "node.h" #include "coap_timer.h" #include "os_type.h" +#include "osapi.h" #include "pm/swtimer.h" static os_timer_t coap_timer; diff --git a/app/coap/endpoints.c b/app/coap/endpoints.c index 4d09f73b78..1ec882874b 100644 --- a/app/coap/endpoints.c +++ b/app/coap/endpoints.c @@ -1,6 +1,6 @@ -#include "c_stdio.h" -#include "c_string.h" -#include "c_stdlib.h" +#include +#include +#include #include "coap.h" #include "lua.h" @@ -21,14 +21,14 @@ void endpoint_setup(void) static const coap_endpoint_path_t path_well_known_core = {2, {".well-known", "core"}}; static int handle_get_well_known_core(const coap_endpoint_t *ep, coap_rw_buffer_t *scratch, const coap_packet_t *inpkt, coap_packet_t *outpkt, uint8_t id_hi, uint8_t id_lo) { - outpkt->content.p = (uint8_t *)c_zalloc(MAX_PAYLOAD_SIZE); // this should be free-ed when outpkt is built in coap_server_respond() + outpkt->content.p = (uint8_t *)calloc(1,MAX_PAYLOAD_SIZE); // this should be free-ed when outpkt is built in coap_server_respond() if(outpkt->content.p == NULL){ NODE_DBG("not enough memory\n"); return COAP_ERR_BUFFER_TOO_SMALL; } outpkt->content.len = MAX_PAYLOAD_SIZE; build_well_known_rsp(outpkt->content.p, outpkt->content.len); - return coap_make_response(scratch, outpkt, (const uint8_t *)outpkt->content.p, c_strlen(outpkt->content.p), id_hi, id_lo, &inpkt->tok, COAP_RSPCODE_CONTENT, COAP_CONTENTTYPE_APPLICATION_LINKFORMAT); + return coap_make_response(scratch, outpkt, (const uint8_t *)outpkt->content.p, strlen(outpkt->content.p), id_hi, id_lo, &inpkt->tok, COAP_RSPCODE_CONTENT, COAP_CONTENTTYPE_APPLICATION_LINKFORMAT); } static const coap_endpoint_path_t path_variable = {2, {"v1", "v"}}; @@ -49,17 +49,17 @@ static int handle_get_variable(const coap_endpoint_t *ep, coap_rw_buffer_t *scra { coap_luser_entry *h = ep->user_entry->next; // ->next: skip the first entry(head) while(NULL != h){ - if (opt[count-1].buf.len != c_strlen(h->name)) + if (opt[count-1].buf.len != strlen(h->name)) { h = h->next; continue; } - if (0 == c_memcmp(h->name, opt[count-1].buf.p, opt[count-1].buf.len)) + if (0 == memcmp(h->name, opt[count-1].buf.p, opt[count-1].buf.len)) { NODE_DBG("/v1/v/"); NODE_DBG((char *)h->name); NODE_DBG(" match.\n"); - if(c_strlen(h->name)) + if(strlen(h->name)) { n = lua_gettop(L); lua_getglobal(L, h->name); @@ -70,7 +70,7 @@ static int handle_get_variable(const coap_endpoint_t *ep, coap_rw_buffer_t *scra } else { const char *res = lua_tostring(L,-1); lua_settop(L, n); - return coap_make_response(scratch, outpkt, (const uint8_t *)res, c_strlen(res), id_hi, id_lo, &inpkt->tok, COAP_RSPCODE_CONTENT, h->content_type); + return coap_make_response(scratch, outpkt, (const uint8_t *)res, strlen(res), id_hi, id_lo, &inpkt->tok, COAP_RSPCODE_CONTENT, h->content_type); } } } else { @@ -105,18 +105,18 @@ static int handle_post_function(const coap_endpoint_t *ep, coap_rw_buffer_t *scr { coap_luser_entry *h = ep->user_entry->next; // ->next: skip the first entry(head) while(NULL != h){ - if (opt[count-1].buf.len != c_strlen(h->name)) + if (opt[count-1].buf.len != strlen(h->name)) { h = h->next; continue; } - if (0 == c_memcmp(h->name, opt[count-1].buf.p, opt[count-1].buf.len)) + if (0 == memcmp(h->name, opt[count-1].buf.p, opt[count-1].buf.len)) { NODE_DBG("/v1/f/"); NODE_DBG((char *)h->name); NODE_DBG(" match.\n"); - if(c_strlen(h->name)) + if(strlen(h->name)) { n = lua_gettop(L); lua_getglobal(L, h->name); @@ -173,7 +173,7 @@ static int handle_post_command(const coap_endpoint_t *ep, coap_rw_buffer_t *scra { char line[LUA_MAXINPUT]; if (!coap_buffer_to_string(line, LUA_MAXINPUT, &inpkt->payload) && - lua_put_line(line, c_strlen(line))) { + lua_put_line(line, strlen(line))) { NODE_DBG("\nResult(if any):\n"); system_os_post (LUA_TASK_PRIO, LUA_PROCESS_LINE_SIG, 0); } @@ -211,7 +211,7 @@ void build_well_known_rsp(char *rsp, uint16_t rsplen) int i; uint16_t len = rsplen; - c_memset(rsp, 0, len); + memset(rsp, 0, len); len--; // Null-terminated string @@ -222,57 +222,57 @@ void build_well_known_rsp(char *rsp, uint16_t rsplen) continue; } if (NULL == ep->user_entry){ - if (0 < c_strlen(rsp)) { - c_strncat(rsp, ",", len); + if (0 < strlen(rsp)) { + strncat(rsp, ",", len); len--; } - c_strncat(rsp, "<", len); + strncat(rsp, "<", len); len--; for (i = 0; i < ep->path->count; i++) { - c_strncat(rsp, "/", len); + strncat(rsp, "/", len); len--; - c_strncat(rsp, ep->path->elems[i], len); - len -= c_strlen(ep->path->elems[i]); + strncat(rsp, ep->path->elems[i], len); + len -= strlen(ep->path->elems[i]); } - c_strncat(rsp, ">;", len); + strncat(rsp, ">;", len); len -= 2; - c_strncat(rsp, ep->core_attr, len); - len -= c_strlen(ep->core_attr); + strncat(rsp, ep->core_attr, len); + len -= strlen(ep->core_attr); } else { coap_luser_entry *h = ep->user_entry->next; // ->next: skip the first entry(head) while(NULL != h){ - if (0 < c_strlen(rsp)) { - c_strncat(rsp, ",", len); + if (0 < strlen(rsp)) { + strncat(rsp, ",", len); len--; } - c_strncat(rsp, "<", len); + strncat(rsp, "<", len); len--; for (i = 0; i < ep->path->count; i++) { - c_strncat(rsp, "/", len); + strncat(rsp, "/", len); len--; - c_strncat(rsp, ep->path->elems[i], len); - len -= c_strlen(ep->path->elems[i]); + strncat(rsp, ep->path->elems[i], len); + len -= strlen(ep->path->elems[i]); } - c_strncat(rsp, "/", len); + strncat(rsp, "/", len); len--; - c_strncat(rsp, h->name, len); - len -= c_strlen(h->name); + strncat(rsp, h->name, len); + len -= strlen(h->name); - c_strncat(rsp, ">;", len); + strncat(rsp, ">;", len); len -= 2; - c_strncat(rsp, ep->core_attr, len); - len -= c_strlen(ep->core_attr); + strncat(rsp, ep->core_attr, len); + len -= strlen(ep->core_attr); h = h->next; } diff --git a/app/coap/hash.c b/app/coap/hash.c index 0638ffa909..99f4db89b5 100644 --- a/app/coap/hash.c +++ b/app/coap/hash.c @@ -1,5 +1,5 @@ #include "hash.h" -#include "c_string.h" +#include /* Caution: When changing this, update COAP_DEFAULT_WKC_HASHKEY * accordingly (see int coap_hash_path()); */ @@ -20,7 +20,7 @@ void coap_hash(const unsigned char *s, unsigned int len, coap_key_t h) { void coap_transaction_id(const uint32_t ip, const uint32_t port, const coap_packet_t *pkt, coap_tid_t *id) { coap_key_t h; - c_memset(h, 0, sizeof(coap_key_t)); + memset(h, 0, sizeof(coap_key_t)); /* Compare the transport address. */ coap_hash((const unsigned char *)&(port), sizeof(port), h); diff --git a/app/coap/node.c b/app/coap/node.c index 7e33544941..52186ecb25 100644 --- a/app/coap/node.c +++ b/app/coap/node.c @@ -1,14 +1,14 @@ -#include "c_string.h" -#include "c_stdlib.h" +#include +#include #include "node.h" static inline coap_queue_t * coap_malloc_node(void) { - return (coap_queue_t *)c_zalloc(sizeof(coap_queue_t)); + return (coap_queue_t *)calloc(1,sizeof(coap_queue_t)); } void coap_free_node(coap_queue_t *node) { - c_free(node); + free(node); } int coap_insert_node(coap_queue_t **queue, coap_queue_t *node) { @@ -73,7 +73,7 @@ coap_queue_t * coap_new_node(void) { return NULL; } - c_memset(node, 0, sizeof(*node)); + memset(node, 0, sizeof(*node)); return node; } diff --git a/app/coap/pdu.c b/app/coap/pdu.c index be287d95e8..892bee6ca2 100644 --- a/app/coap/pdu.c +++ b/app/coap/pdu.c @@ -1,38 +1,38 @@ -#include "c_stdlib.h" +#include #include "pdu.h" coap_pdu_t * coap_new_pdu(void) { coap_pdu_t *pdu = NULL; - pdu = (coap_pdu_t *)c_zalloc(sizeof(coap_pdu_t)); + pdu = (coap_pdu_t *)calloc(1,sizeof(coap_pdu_t)); if(!pdu){ NODE_DBG("coap_new_pdu malloc error.\n"); return NULL; } - pdu->scratch.p = (uint8_t *)c_zalloc(MAX_REQ_SCRATCH_SIZE); + pdu->scratch.p = (uint8_t *)calloc(1,MAX_REQ_SCRATCH_SIZE); if(!pdu->scratch.p){ NODE_DBG("coap_new_pdu malloc error.\n"); - c_free(pdu); + free(pdu); return NULL; } pdu->scratch.len = MAX_REQ_SCRATCH_SIZE; - pdu->pkt = (coap_packet_t *)c_zalloc(sizeof(coap_packet_t)); + pdu->pkt = (coap_packet_t *)calloc(1,sizeof(coap_packet_t)); if(!pdu->pkt){ NODE_DBG("coap_new_pdu malloc error.\n"); - c_free(pdu->scratch.p); - c_free(pdu); + free(pdu->scratch.p); + free(pdu); return NULL; } pdu->pkt->content.p = NULL; pdu->pkt->content.len = 0; - pdu->msg.p = (uint8_t *)c_zalloc(MAX_REQUEST_SIZE+1); // +1 for string '\0' + pdu->msg.p = (uint8_t *)calloc(1,MAX_REQUEST_SIZE+1); // +1 for string '\0' if(!pdu->msg.p){ NODE_DBG("coap_new_pdu malloc error.\n"); - c_free(pdu->pkt); - c_free(pdu->scratch.p); - c_free(pdu); + free(pdu->pkt); + free(pdu->scratch.p); + free(pdu); return NULL; } pdu->msg.len = MAX_REQUEST_SIZE; @@ -44,22 +44,22 @@ void coap_delete_pdu(coap_pdu_t *pdu){ return; if(pdu->scratch.p){ - c_free(pdu->scratch.p); + free(pdu->scratch.p); pdu->scratch.p = NULL; pdu->scratch.len = 0; } if(pdu->pkt){ - c_free(pdu->pkt); + free(pdu->pkt); pdu->pkt = NULL; } if(pdu->msg.p){ - c_free(pdu->msg.p); + free(pdu->msg.p); pdu->msg.p = NULL; pdu->msg.len = 0; } - c_free(pdu); + free(pdu); pdu = NULL; } diff --git a/app/coap/str.c b/app/coap/str.c index c31a021f8a..1c882eede8 100644 --- a/app/coap/str.c +++ b/app/coap/str.c @@ -6,23 +6,23 @@ * README for terms of use. */ -#include "c_stdlib.h" +#include #include "c_types.h" #include "str.h" str * coap_new_string(size_t size) { - str *s = (str *)c_malloc(sizeof(str) + size + 1); + str *s = (str *)malloc(sizeof(str) + size + 1); if ( !s ) { return NULL; } - c_memset(s, 0, sizeof(str)); + memset(s, 0, sizeof(str)); s->s = ((unsigned char *)s) + sizeof(str); return s; } void coap_delete_string(str *s) { - c_free(s); + free(s); } diff --git a/app/coap/str.h b/app/coap/str.h index efcd9a3d5b..0289cf44c5 100644 --- a/app/coap/str.h +++ b/app/coap/str.h @@ -9,7 +9,7 @@ #ifndef _COAP_STR_H_ #define _COAP_STR_H_ -#include "c_string.h" +#include typedef struct { size_t length; /* length of string */ diff --git a/app/coap/uri.c b/app/coap/uri.c index a87dcb2fe9..c57de10aab 100644 --- a/app/coap/uri.c +++ b/app/coap/uri.c @@ -1,10 +1,10 @@ /* uri.c -- helper functions for URI treatment */ -#include "c_stdio.h" -#include "c_stdlib.h" -#include "c_string.h" -#include "c_ctype.h" +#include +#include +#include +#include #include "coap.h" #include "uri.h" @@ -43,7 +43,7 @@ int coap_split_uri(unsigned char *str_var, size_t len, coap_uri_t *uri) { if (!str_var || !uri) return -1; - c_memset(uri, 0, sizeof(coap_uri_t)); + memset(uri, 0, sizeof(coap_uri_t)); uri->port = COAP_DEFAULT_PORT; /* search for scheme */ @@ -394,16 +394,16 @@ int coap_split_query(coap_rw_buffer_t *scratch, coap_packet_t *pkt, const unsign coap_uri_t * coap_new_uri(const unsigned char *uri, unsigned int length) { unsigned char *result; - result = (unsigned char *)c_malloc(length + 1 + sizeof(coap_uri_t)); + result = (unsigned char *)malloc(length + 1 + sizeof(coap_uri_t)); if (!result) return NULL; - c_memcpy(URI_DATA(result), uri, length); + memcpy(URI_DATA(result), uri, length); URI_DATA(result)[length] = '\0'; /* make it zero-terminated */ if (coap_split_uri(URI_DATA(result), length, (coap_uri_t *)result) < 0) { - c_free(result); + free(result); return NULL; } return (coap_uri_t *)result; diff --git a/app/crypto/digests.c b/app/crypto/digests.c index 409b3e9055..0553658129 100644 --- a/app/crypto/digests.c +++ b/app/crypto/digests.c @@ -34,7 +34,8 @@ #include "osapi.h" #include "mem.h" #include -#include +#include +#include #ifdef MD2_ENABLE #include "ssl/ssl_crypto.h" diff --git a/app/crypto/mech.c b/app/crypto/mech.c index 4fa5adec19..d093835831 100644 --- a/app/crypto/mech.c +++ b/app/crypto/mech.c @@ -33,7 +33,8 @@ #include "mech.h" #include "sdk-aes.h" -#include "c_string.h" +#include +#include /* ----- AES ---------------------------------------------------------- */ @@ -58,7 +59,7 @@ static bool do_aes (crypto_op_t *co, bool with_cbc) char iv[AES_BLOCKSIZE] = { 0 }; if (with_cbc && co->ivlen) - c_memcpy (iv, co->iv, co->ivlen < AES_BLOCKSIZE ? co->ivlen : AES_BLOCKSIZE); + memcpy (iv, co->iv, co->ivlen < AES_BLOCKSIZE ? co->ivlen : AES_BLOCKSIZE); const char *src = co->data; char *dst = co->out; @@ -68,7 +69,7 @@ static bool do_aes (crypto_op_t *co, bool with_cbc) { char block[AES_BLOCKSIZE] = { 0 }; size_t n = left > AES_BLOCKSIZE ? AES_BLOCKSIZE : left; - c_memcpy (block, src, n); + memcpy (block, src, n); if (with_cbc && co->op == OP_ENCRYPT) { diff --git a/app/dht/dht.c b/app/dht/dht.c index 932725e310..cc412e5233 100644 --- a/app/dht/dht.c +++ b/app/dht/dht.c @@ -29,7 +29,7 @@ #include "user_interface.h" #include "platform.h" -#include "c_stdio.h" +#include #include "dht.h" #ifndef LOW diff --git a/app/driver/i2c_master.c b/app/driver/i2c_master.c index b3ec4869da..618d089844 100644 --- a/app/driver/i2c_master.c +++ b/app/driver/i2c_master.c @@ -24,7 +24,7 @@ * Rework of original driver: Natalia Sorokina , 2018 */ -#include "../libc/c_stdlib.h" +#include #include "ets_sys.h" #include "osapi.h" #include "gpio.h" diff --git a/app/driver/rotary.c b/app/driver/rotary.c index eedeb5e1fa..6e01506ebe 100644 --- a/app/driver/rotary.c +++ b/app/driver/rotary.c @@ -12,8 +12,8 @@ #include "platform.h" #include "c_types.h" -#include "../libc/c_stdlib.h" -#include "../libc/c_stdio.h" +#include +#include #include "driver/rotary.h" #include "user_interface.h" #include "task/task.h" @@ -87,7 +87,7 @@ int rotary_close(uint32_t channel) rotary_clear_pin(d->phase_b_pin); rotary_clear_pin(d->press_pin); - c_free(d); + free(d); set_gpio_bits(); @@ -207,7 +207,7 @@ int rotary_setup(uint32_t channel, int phase_a, int phase_b, int press, task_han } } - DATA *d = (DATA *) c_zalloc(sizeof(DATA)); + DATA *d = (DATA *) calloc(1, sizeof(DATA)); if (!d) { return -1; } diff --git a/app/driver/switec.c b/app/driver/switec.c index 1dbfe20fee..23c1a5f125 100644 --- a/app/driver/switec.c +++ b/app/driver/switec.c @@ -15,8 +15,8 @@ #include "platform.h" #include "c_types.h" -#include "../libc/c_stdlib.h" -#include "../libc/c_stdio.h" +#include +#include #include "driver/switec.h" #include "ets_sys.h" #include "os_type.h" @@ -101,7 +101,7 @@ int switec_close(uint32_t channel) gpio_output_set(0, 0, 0, d->mask); data[channel] = NULL; - c_free(d); + free(d); // See if there are any other channels active for (channel = 0; channel < sizeof(data)/sizeof(data[0]); channel++) { @@ -259,7 +259,7 @@ int switec_setup(uint32_t channel, int *pin, int max_deg_per_sec, task_handle_t } } - DATA *d = (DATA *) c_zalloc(sizeof(DATA)); + DATA *d = (DATA *) calloc(1, sizeof(DATA)); if (!d) { return -1; } @@ -269,7 +269,7 @@ int switec_setup(uint32_t channel, int *pin, int max_deg_per_sec, task_handle_t // no autoreload if (!platform_hw_timer_init(TIMER_OWNER, FRC1_SOURCE, FALSE)) { // Failed to get the timer - c_free(d); + free(d); return -1; } } @@ -299,12 +299,12 @@ int switec_setup(uint32_t channel, int *pin, int max_deg_per_sec, task_handle_t #ifdef SWITEC_DEBUG for (i = 0; i < 4; i++) { - c_printf("pin[%d]=%d\n", i, pin[i]); + printf("pin[%d]=%d\n", i, pin[i]); } - c_printf("Mask=0x%x\n", d->mask); + printf("Mask=0x%x\n", d->mask); for (i = 0; i < N_STATES; i++) { - c_printf("pinstate[%d]=0x%x\n", i, d->pinstate[i]); + printf("pinstate[%d]=0x%x\n", i, d->pinstate[i]); } #endif diff --git a/app/fatfs/myfatfs.c b/app/fatfs/myfatfs.c index be079f3173..c7a9c0a1d4 100644 --- a/app/fatfs/myfatfs.c +++ b/app/fatfs/myfatfs.c @@ -1,5 +1,6 @@ -#include -#include +#include +#include +#include #include "vfs_int.h" @@ -12,37 +13,37 @@ static FRESULT last_result = FR_OK; static const char* const volstr[FF_VOLUMES] = {FF_VOLUME_STRS}; -static int is_current_drive = FALSE; +static int is_current_drive = false; // forward declarations -static sint32_t myfatfs_close( const struct vfs_file *fd ); -static sint32_t myfatfs_read( const struct vfs_file *fd, void *ptr, size_t len ); -static sint32_t myfatfs_write( const struct vfs_file *fd, const void *ptr, size_t len ); -static sint32_t myfatfs_lseek( const struct vfs_file *fd, sint32_t off, int whence ); -static sint32_t myfatfs_eof( const struct vfs_file *fd ); -static sint32_t myfatfs_tell( const struct vfs_file *fd ); -static sint32_t myfatfs_flush( const struct vfs_file *fd ); +static int32_t myfatfs_close( const struct vfs_file *fd ); +static int32_t myfatfs_read( const struct vfs_file *fd, void *ptr, size_t len ); +static int32_t myfatfs_write( const struct vfs_file *fd, const void *ptr, size_t len ); +static int32_t myfatfs_lseek( const struct vfs_file *fd, int32_t off, int whence ); +static int32_t myfatfs_eof( const struct vfs_file *fd ); +static int32_t myfatfs_tell( const struct vfs_file *fd ); +static int32_t myfatfs_flush( const struct vfs_file *fd ); static uint32_t myfatfs_fsize( const struct vfs_file *fd ); -static sint32_t myfatfs_ferrno( const struct vfs_file *fd ); +static int32_t myfatfs_ferrno( const struct vfs_file *fd ); -static sint32_t myfatfs_closedir( const struct vfs_dir *dd ); -static sint32_t myfatfs_readdir( const struct vfs_dir *dd, struct vfs_stat *buf ); +static int32_t myfatfs_closedir( const struct vfs_dir *dd ); +static int32_t myfatfs_readdir( const struct vfs_dir *dd, struct vfs_stat *buf ); static vfs_vol *myfatfs_mount( const char *name, int num ); static vfs_file *myfatfs_open( const char *name, const char *mode ); static vfs_dir *myfatfs_opendir( const char *name ); -static sint32_t myfatfs_stat( const char *name, struct vfs_stat *buf ); -static sint32_t myfatfs_remove( const char *name ); -static sint32_t myfatfs_rename( const char *oldname, const char *newname ); -static sint32_t myfatfs_mkdir( const char *name ); -static sint32_t myfatfs_fsinfo( uint32_t *total, uint32_t *used ); -static sint32_t myfatfs_chdrive( const char *name ); -static sint32_t myfatfs_chdir( const char *name ); -static sint32_t myfatfs_errno( void ); +static int32_t myfatfs_stat( const char *name, struct vfs_stat *buf ); +static int32_t myfatfs_remove( const char *name ); +static int32_t myfatfs_rename( const char *oldname, const char *newname ); +static int32_t myfatfs_mkdir( const char *name ); +static int32_t myfatfs_fsinfo( uint32_t *total, uint32_t *used ); +static int32_t myfatfs_chdrive( const char *name ); +static int32_t myfatfs_chdir( const char *name ); +static int32_t myfatfs_errno( void ); static void myfatfs_clearerr( void ); -static sint32_t myfatfs_umount( const struct vfs_vol *vol ); +static int32_t myfatfs_umount( const struct vfs_vol *vol ); // --------------------------------------------------------------------------- @@ -112,12 +113,12 @@ struct myvfs_dir { // void *ff_memalloc( UINT size ) { - return c_malloc( size ); + return malloc( size ); } void ff_memfree( void *mblock ) { - c_free( mblock ); + free( mblock ); } // TODO @@ -153,14 +154,14 @@ DWORD get_fattime( void ) const struct myvfs_vol *myvol = (const struct myvfs_vol *)descr; \ FATFS *fs = (FATFS *)&(myvol->fs); -static sint32_t myfatfs_umount( const struct vfs_vol *vol ) +static int32_t myfatfs_umount( const struct vfs_vol *vol ) { GET_FATFS_FS(vol); last_result = f_mount( NULL, myvol->ldrname, 0 ); - c_free( myvol->ldrname ); - c_free( (void *)vol ); + free( myvol->ldrname ); + free( (void *)vol ); return last_result == FR_OK ? VFS_RES_OK : VFS_RES_ERR; } @@ -173,19 +174,19 @@ static sint32_t myfatfs_umount( const struct vfs_vol *vol ) const struct myvfs_file *myfd = (const struct myvfs_file *)descr; \ FIL *fp = (FIL *)&(myfd->fp); -static sint32_t myfatfs_close( const struct vfs_file *fd ) +static int32_t myfatfs_close( const struct vfs_file *fd ) { GET_FIL_FP(fd) last_result = f_close( fp ); // free descriptor memory - c_free( (void *)fd ); + free( (void *)fd ); return last_result == FR_OK ? VFS_RES_OK : VFS_RES_ERR; } -static sint32_t myfatfs_read( const struct vfs_file *fd, void *ptr, size_t len ) +static int32_t myfatfs_read( const struct vfs_file *fd, void *ptr, size_t len ) { GET_FIL_FP(fd); UINT act_read; @@ -195,7 +196,7 @@ static sint32_t myfatfs_read( const struct vfs_file *fd, void *ptr, size_t len ) return last_result == FR_OK ? act_read : VFS_RES_ERR; } -static sint32_t myfatfs_write( const struct vfs_file *fd, const void *ptr, size_t len ) +static int32_t myfatfs_write( const struct vfs_file *fd, const void *ptr, size_t len ) { GET_FIL_FP(fd); UINT act_written; @@ -205,7 +206,7 @@ static sint32_t myfatfs_write( const struct vfs_file *fd, const void *ptr, size_ return last_result == FR_OK ? act_written : VFS_RES_ERR; } -static sint32_t myfatfs_lseek( const struct vfs_file *fd, sint32_t off, int whence ) +static int32_t myfatfs_lseek( const struct vfs_file *fd, int32_t off, int whence ) { GET_FIL_FP(fd); FSIZE_t new_pos; @@ -231,7 +232,7 @@ static sint32_t myfatfs_lseek( const struct vfs_file *fd, sint32_t off, int when return last_result == FR_OK ? new_pos : VFS_RES_ERR; } -static sint32_t myfatfs_eof( const struct vfs_file *fd ) +static int32_t myfatfs_eof( const struct vfs_file *fd ) { GET_FIL_FP(fd); @@ -240,7 +241,7 @@ static sint32_t myfatfs_eof( const struct vfs_file *fd ) return f_eof( fp ); } -static sint32_t myfatfs_tell( const struct vfs_file *fd ) +static int32_t myfatfs_tell( const struct vfs_file *fd ) { GET_FIL_FP(fd); @@ -249,7 +250,7 @@ static sint32_t myfatfs_tell( const struct vfs_file *fd ) return f_tell( fp ); } -static sint32_t myfatfs_flush( const struct vfs_file *fd ) +static int32_t myfatfs_flush( const struct vfs_file *fd ) { GET_FIL_FP(fd); @@ -267,7 +268,7 @@ static uint32_t myfatfs_fsize( const struct vfs_file *fd ) return f_size( fp ); } -static sint32_t myfatfs_ferrno( const struct vfs_file *fd ) +static int32_t myfatfs_ferrno( const struct vfs_file *fd ) { return -last_result; } @@ -280,24 +281,24 @@ static sint32_t myfatfs_ferrno( const struct vfs_file *fd ) const struct myvfs_dir *mydd = (const struct myvfs_dir *)descr; \ DIR *dp = (DIR *)&(mydd->dp); -static sint32_t myfatfs_closedir( const struct vfs_dir *dd ) +static int32_t myfatfs_closedir( const struct vfs_dir *dd ) { GET_DIR_DP(dd); last_result = f_closedir( dp ); // free descriptor memory - c_free( (void *)dd ); + free( (void *)dd ); return last_result == FR_OK ? VFS_RES_OK : VFS_RES_ERR; } static void myfatfs_fill_stat( const FILINFO *fno, struct vfs_stat *buf ) { - c_memset( buf, 0, sizeof( struct vfs_stat ) ); + memset( buf, 0, sizeof( struct vfs_stat ) ); // fill in supported stat entries - c_strncpy( buf->name, fno->fname, FS_OBJ_NAME_LEN+1 ); + strncpy( buf->name, fno->fname, FS_OBJ_NAME_LEN+1 ); buf->name[FS_OBJ_NAME_LEN] = '\0'; buf->size = fno->fsize; buf->is_dir = fno->fattrib & AM_DIR ? 1 : 0; @@ -316,7 +317,7 @@ static void myfatfs_fill_stat( const FILINFO *fno, struct vfs_stat *buf ) buf->tm_valid = 1; } -static sint32_t myfatfs_readdir( const struct vfs_dir *dd, struct vfs_stat *buf ) +static int32_t myfatfs_readdir( const struct vfs_dir *dd, struct vfs_stat *buf ) { GET_DIR_DP(dd); FILINFO fno; @@ -340,19 +341,19 @@ static sint32_t myfatfs_readdir( const struct vfs_dir *dd, struct vfs_stat *buf static vfs_vol *myfatfs_mount( const char *name, int num ) { struct myvfs_vol *vol; - const size_t len = c_strlen( name ); + const size_t len = strlen( name ); // num argument specifies the physical driver = SS/CS pin number for this sd card if (num >= 0) { for (int i = 0; i < NUM_LOGICAL_DRIVES; i++) { - if (0 == c_strncmp( name, volstr[i], c_strlen( volstr[i] ) )) { + if (0 == strncmp( name, volstr[i], strlen( volstr[i] ) )) { VolToPart[i].pd = num; } } } - if (vol = c_malloc( sizeof( struct myvfs_vol ) )) { - if (vol->ldrname = c_strdup( name )) { + if (vol = malloc( sizeof( struct myvfs_vol ) )) { + if (vol->ldrname = strdup( name )) { if (FR_OK == (last_result = f_mount( &(vol->fs), name, 1 ))) { vol->vfs_vol.fs_type = VFS_FS_FATFS; vol->vfs_vol.fns = &myfatfs_vol_fns; @@ -362,29 +363,29 @@ static vfs_vol *myfatfs_mount( const char *name, int num ) } if (vol) { - if (vol->ldrname) c_free( vol->ldrname ); - c_free( vol ); + if (vol->ldrname) free( vol->ldrname ); + free( vol ); } return NULL; } static BYTE myfatfs_mode2flag( const char *mode ) { - if (c_strlen( mode ) == 1) { - if(c_strcmp( mode, "w" ) == 0) + if (strlen( mode ) == 1) { + if(strcmp( mode, "w" ) == 0) return FA_WRITE | FA_CREATE_ALWAYS; - else if (c_strcmp( mode, "r" ) == 0) + else if (strcmp( mode, "r" ) == 0) return FA_READ | FA_OPEN_EXISTING; - else if (c_strcmp( mode, "a" ) == 0) + else if (strcmp( mode, "a" ) == 0) return FA_WRITE | FA_OPEN_ALWAYS; else return FA_READ | FA_OPEN_EXISTING; - } else if (c_strlen( mode ) == 2) { - if (c_strcmp( mode, "r+" ) == 0) + } else if (strlen( mode ) == 2) { + if (strcmp( mode, "r+" ) == 0) return FA_READ | FA_WRITE | FA_OPEN_EXISTING; - else if (c_strcmp( mode, "w+" ) == 0) + else if (strcmp( mode, "w+" ) == 0) return FA_READ | FA_WRITE | FA_CREATE_ALWAYS; - else if (c_strcmp( mode, "a+" ) ==0 ) + else if (strcmp( mode, "a+" ) ==0 ) return FA_READ | FA_WRITE | FA_OPEN_ALWAYS; else return FA_READ | FA_OPEN_EXISTING; @@ -398,7 +399,7 @@ static vfs_file *myfatfs_open( const char *name, const char *mode ) struct myvfs_file *fd; const BYTE flags = myfatfs_mode2flag( mode ); - if (fd = c_malloc( sizeof( struct myvfs_file ) )) { + if (fd = malloc( sizeof( struct myvfs_file ) )) { if (FR_OK == (last_result = f_open( &(fd->fp), name, flags ))) { // skip to end of file for append mode if (flags & FA_OPEN_ALWAYS) @@ -408,7 +409,7 @@ static vfs_file *myfatfs_open( const char *name, const char *mode ) fd->vfs_file.fns = &myfatfs_file_fns; return (vfs_file *)fd; } else { - c_free( fd ); + free( fd ); } } @@ -419,20 +420,20 @@ static vfs_dir *myfatfs_opendir( const char *name ) { struct myvfs_dir *dd; - if (dd = c_malloc( sizeof( struct myvfs_dir ) )) { + if (dd = malloc( sizeof( struct myvfs_dir ) )) { if (FR_OK == (last_result = f_opendir( &(dd->dp), name ))) { dd->vfs_dir.fs_type = VFS_FS_FATFS; dd->vfs_dir.fns = &myfatfs_dir_fns; return (vfs_dir *)dd; } else { - c_free( dd ); + free( dd ); } } return NULL; } -static sint32_t myfatfs_stat( const char *name, struct vfs_stat *buf ) +static int32_t myfatfs_stat( const char *name, struct vfs_stat *buf ) { FILINFO fno; @@ -445,28 +446,28 @@ static sint32_t myfatfs_stat( const char *name, struct vfs_stat *buf ) } } -static sint32_t myfatfs_remove( const char *name ) +static int32_t myfatfs_remove( const char *name ) { last_result = f_unlink( name ); return last_result == FR_OK ? VFS_RES_OK : VFS_RES_ERR; } -static sint32_t myfatfs_rename( const char *oldname, const char *newname ) +static int32_t myfatfs_rename( const char *oldname, const char *newname ) { last_result = f_rename( oldname, newname ); return last_result == FR_OK ? VFS_RES_OK : VFS_RES_ERR; } -static sint32_t myfatfs_mkdir( const char *name ) +static int32_t myfatfs_mkdir( const char *name ) { last_result = f_mkdir( name ); return last_result == FR_OK ? VFS_RES_OK : VFS_RES_ERR; } -static sint32_t myfatfs_fsinfo( uint32_t *total, uint32_t *used ) +static int32_t myfatfs_fsinfo( uint32_t *total, uint32_t *used ) { DWORD free_clusters; FATFS *fatfs; @@ -480,21 +481,21 @@ static sint32_t myfatfs_fsinfo( uint32_t *total, uint32_t *used ) return last_result == FR_OK ? VFS_RES_OK : VFS_RES_ERR; } -static sint32_t myfatfs_chdrive( const char *name ) +static int32_t myfatfs_chdrive( const char *name ) { last_result = f_chdrive( name ); return last_result == FR_OK ? VFS_RES_OK : VFS_RES_ERR; } -static sint32_t myfatfs_chdir( const char *name ) +static int32_t myfatfs_chdir( const char *name ) { last_result = f_chdir( name ); return last_result == FR_OK ? VFS_RES_OK : VFS_RES_ERR; } -static sint32_t myfatfs_errno( void ) +static int32_t myfatfs_errno( void ) { return -last_result; } @@ -515,10 +516,10 @@ vfs_fs_fns *myfatfs_realm( const char *inname, char **outname, int set_current_d // logical drive is specified, check if it's one of ours for (int i = 0; i < FF_VOLUMES; i++) { - size_t volstr_len = c_strlen( volstr[i] ); - if (0 == c_strncmp( &(inname[1]), volstr[i], volstr_len )) { - oname = c_strdup( inname ); - c_strcpy( oname, volstr[i] ); + size_t volstr_len = strlen( volstr[i] ); + if (0 == strncmp( &(inname[1]), volstr[i], volstr_len )) { + oname = strdup( inname ); + strcpy( oname, volstr[i] ); oname[volstr_len] = ':'; *outname = oname; @@ -529,11 +530,11 @@ vfs_fs_fns *myfatfs_realm( const char *inname, char **outname, int set_current_d } else { // no logical drive in patchspec, are we current drive? if (is_current_drive) { - *outname = c_strdup( inname ); + *outname = strdup( inname ); return &myfatfs_fs_fns; } } - if (set_current_drive) is_current_drive = FALSE; + if (set_current_drive) is_current_drive = false; return NULL; } diff --git a/app/http/httpclient.c b/app/http/httpclient.c index 51c209d883..1419d59771 100644 --- a/app/http/httpclient.c +++ b/app/http/httpclient.c @@ -13,7 +13,7 @@ */ #include "osapi.h" -#include "../libc/c_stdio.h" +#include #include "user_interface.h" #include "espconn.h" #include "mem.h" diff --git a/app/include/pm/pmSleep.h b/app/include/pm/pmSleep.h index eca8590aee..093c7dc5cb 100644 --- a/app/include/pm/pmSleep.h +++ b/app/include/pm/pmSleep.h @@ -6,7 +6,7 @@ #include "gpio.h" #include "platform.h" #include "task/task.h" -#include "c_string.h" +#include #if defined(DEVELOP_VERSION) #define PMSLEEP_DEBUG diff --git a/app/include/user_config.h b/app/include/user_config.h index e87adbc7f4..4866e6a91d 100644 --- a/app/include/user_config.h +++ b/app/include/user_config.h @@ -255,6 +255,11 @@ extern void luaL_dbgbreak(void); #define COAP_DEBUG #endif /* DEVELOP_VERSION */ + +#if !defined(LUA_CROSS_COMPILER) && !defined(dbg_printf) +extern void dbg_printf(const char *fmt, ...); +#endif + #ifdef NODE_DEBUG #define NODE_DBG dbg_printf #else diff --git a/app/include/user_mbedtls.h b/app/include/user_mbedtls.h index f6614f4cb2..cb3b792345 100644 --- a/app/include/user_mbedtls.h +++ b/app/include/user_mbedtls.h @@ -274,8 +274,10 @@ //#define MBEDTLS_MEMORY_ALIGN_MULTIPLE 4 /**< Align on multiples of this value */ //#define MBEDTLS_PLATFORM_STD_MEM_HDR /**< Header to include if MBEDTLS_PLATFORM_NO_STD_FUNCTIONS is defined. Don't define if no header is needed. */ -#define MBEDTLS_PLATFORM_STD_CALLOC pvPortCalloc /**< Default allocator to use, can be undefined */ -#define MBEDTLS_PLATFORM_STD_FREE vPortFree /**< Default free to use, can be undefined */ +extern void *mbedtls_calloc_wrap(size_t n, size_t sz); +#define MBEDTLS_PLATFORM_STD_CALLOC mbedtls_calloc_wrap /**< Default allocator to use, can be undefined */ +extern void mbedtls_free_wrap(void *p); +#define MBEDTLS_PLATFORM_STD_FREE mbedtls_free_wrap /**< Default free to use, can be undefined */ //#define MBEDTLS_PLATFORM_STD_EXIT exit /**< Default exit to use, can be undefined */ //#define MBEDTLS_PLATFORM_STD_TIME time /**< Default time to use, can be undefined. MBEDTLS_HAVE_TIME must be enabled */ //#define MBEDTLS_PLATFORM_STD_FPRINTF fprintf /**< Default fprintf to use, can be undefined */ diff --git a/app/libc/c_ctype.c b/app/libc/c_ctype.c deleted file mode 100644 index 90f8d709fb..0000000000 --- a/app/libc/c_ctype.c +++ /dev/null @@ -1,16 +0,0 @@ -#include "c_ctype.h" -#include "c_types.h" - -// int isalnum(int c){} -// int isalpha(int c){} -// int iscntrl(int c){} -// int isdigit(int c){} -// // int isgraph(int c){} -// int islower(int c){} -// int isprint(int c){} -// int ispunct(int c){} -// int isspace(int c){} -// int isupper(int c){} -// int isxdigit(int c){} -// int tolower(int c){} -// int toupper(int c){} diff --git a/app/libc/c_ctype.h b/app/libc/c_ctype.h deleted file mode 100644 index c7d443f244..0000000000 --- a/app/libc/c_ctype.h +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef _C_CTYPE_H_ -#define _C_CTYPE_H_ - -#if 0 -int isalnum(int); -int isalpha(int); -int iscntrl(int); -int isdigit(int); -// int isgraph(int); -int islower(int); -int isprint(int); -int ispunct(int); -int isspace(int); -int isupper(int); -int isxdigit(int); -int tolower(int); -int toupper(int); - -#if !defined(__STRICT_ANSI__) || defined(__cplusplus) || __STDC_VERSION__ >= 199901L -// int isblank(int); -#endif - -#ifndef __STRICT_ANSI__ -// int isascii(int); -// int toascii(int); -#define _tolower(__c) ((unsigned char)(__c) - 'A' + 'a') -#define _toupper(__c) ((unsigned char)(__c) - 'a' + 'A') -#endif - -#define _U 01 -#define _L 02 -#define _N 04 -#define _S 010 -#define _P 020 -#define _C 040 -#define _X 0100 -#define _B 0200 - -/* For C++ backward-compatibility only. */ -// extern char _ctype_[]; -#endif -#endif /* _C_CTYPE_H_ */ diff --git a/app/libc/c_errno.h b/app/libc/c_errno.h deleted file mode 100644 index b0d79e4423..0000000000 --- a/app/libc/c_errno.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef __c_errno_h -#define __c_errno_h - -#include -// #ifndef errno -// extern int errno; -// #endif - -// #define EDOM 1 -// #define ERANGE 2 -// #define EILSEQ 4 -// #define ESIGNUM 3 -// #define EINVAL 5 -// #define ENOMEM 6 - -#endif - -/* end of c_errno.h */ - diff --git a/app/libc/c_fcntl.h b/app/libc/c_fcntl.h deleted file mode 100644 index 84bba18edd..0000000000 --- a/app/libc/c_fcntl.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef __c_fcntl_h -#define __c_fcntl_h - -#include - -#endif - -/* end of c_fcntl.h */ - diff --git a/app/libc/c_limits.h b/app/libc/c_limits.h deleted file mode 100644 index 226a5bbc97..0000000000 --- a/app/libc/c_limits.h +++ /dev/null @@ -1,58 +0,0 @@ -#ifndef __c_limits_h -#define __c_limits_h - -#include -#if 0 -#define CHAR_BIT 8 - /* max number of bits for smallest object that is not a bit-field (byte) */ -#define SCHAR_MIN (-128) - /* mimimum value for an object of type signed char */ -#define SCHAR_MAX 127 - /* maximum value for an object of type signed char */ -#define UCHAR_MAX 255 - /* maximum value for an object of type unsigned char */ -#ifdef __FEATURE_SIGNED_CHAR - #define CHAR_MIN (-128) - /* minimum value for an object of type char */ - #define CHAR_MAX 127 - /* maximum value for an object of type char */ -#else - #define CHAR_MIN 0 - /* minimum value for an object of type char */ - #define CHAR_MAX 255 - /* maximum value for an object of type char */ -#endif - -#define SHRT_MIN (-0x8000) - /* minimum value for an object of type short int */ -#define SHRT_MAX 0x7fff - /* maximum value for an object of type short int */ -#define USHRT_MAX 65535 - /* maximum value for an object of type unsigned short int */ -#define INT_MIN (~0x7fffffff) /* -2147483648 and 0x80000000 are unsigned */ - /* minimum value for an object of type int */ -#define INT_MAX 0x7fffffff - /* maximum value for an object of type int */ -#define UINT_MAX 0xffffffffU - /* maximum value for an object of type unsigned int */ -#define LONG_MIN (~0x7fffffffL) - /* minimum value for an object of type long int */ -#define LONG_MAX 0x7fffffffL - /* maximum value for an object of type long int */ -#define ULONG_MAX 0xffffffffUL - /* maximum value for an object of type unsigned long int */ -#if !defined(__STRICT_ANSI__) || (defined(__STDC_VERSION__) && 199901L <= __STDC_VERSION__) - #define LLONG_MIN (~0x7fffffffffffffffLL) - /* minimum value for an object of type long long int */ - #define LLONG_MAX 0x7fffffffffffffffLL - /* maximum value for an object of type long long int */ - #define ULLONG_MAX 0xffffffffffffffffULL - /* maximum value for an object of type unsigned long int */ -#endif - -#endif - -#endif - -/* end of c_limits.h */ - diff --git a/app/libc/c_locale.h b/app/libc/c_locale.h deleted file mode 100644 index 2b5f5b6456..0000000000 --- a/app/libc/c_locale.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - c_locale.h - Values appropriate for the formatting of monetary and other - numberic quantities. -*/ - -#ifndef _C_LOCALE_H_ -#define _C_LOCALE_H_ - -#include - -#if 0 -#ifndef NULL -#define NULL 0 -#endif - -#define LC_ALL 0 -#define LC_COLLATE 1 -#define LC_CTYPE 2 -#define LC_MONETARY 3 -#define LC_NUMERIC 4 -#define LC_TIME 5 -#define LC_MESSAGES 6 - -struct lconv -{ - char *decimal_point; - char *thousands_sep; - char *grouping; - char *int_curr_symbol; - char *currency_symbol; - char *mon_decimal_point; - char *mon_thousands_sep; - char *mon_grouping; - char *positive_sign; - char *negative_sign; - char int_frac_digits; - char frac_digits; - char p_cs_precedes; - char p_sep_by_space; - char n_cs_precedes; - char n_sep_by_space; - char p_sign_posn; - char n_sign_posn; - char int_n_cs_precedes; - char int_n_sep_by_space; - char int_n_sign_posn; - char int_p_cs_precedes; - char int_p_sep_by_space; - char int_p_sign_posn; -}; - -#ifndef _REENT_ONLY -// char *setlocale(int category, const char *locale); -struct lconv *localeconv(void); -#endif - -// struct _reent; -// char *_setlocale_r(struct _reent *, int category, const char *locale); -// struct lconv *_localeconv_r(struct _reent *); -#endif -#endif /* _C_LOCALE_H_ */ diff --git a/app/libc/c_math.h b/app/libc/c_math.h deleted file mode 100644 index ef18ee7960..0000000000 --- a/app/libc/c_math.h +++ /dev/null @@ -1,62 +0,0 @@ -#ifndef _C_MATH_H_ -#define _C_MATH_H_ -#include - -double floor(double); -double pow(double, double); - -#if 0 -#ifndef HUGE_VAL - #define HUGE_VAL (1.0e99) - #endif - - #ifndef HUGE_VALF - #define HUGE_VALF (1.0e999999999F) - #endif - - #if !defined(HUGE_VALL) && defined(_HAVE_LONG_DOUBLE) - #define HUGE_VALL (1.0e999999999L) - #endif - - #if !defined(INFINITY) - #define INFINITY (HUGE_VALF) - #endif - - -/* Reentrant ANSI C functions. */ - -#ifndef __math_68881 -// double atan(double); -// double cos(double); -// double sin(double); -// double tan(double); -// double tanh(double); -// double frexp(double, int *); -// double modf(double, double *); -// double ceil(double); -// double fabs(double); -// double floor(double); -#endif /* ! defined (__math_68881) */ - -/* Non reentrant ANSI C functions. */ - -#ifndef _REENT_ONLY -#ifndef __math_68881 -// double acos(double); -// double asin(double); -// double atan2(double, double); -// double cosh(double); -// double sinh(double); -// double exp(double); -// double ldexp(double, int); -// double log(double); -// double log10(double); -// double pow(double, double); -// double sqrt(double); -// double fmod(double, double); -#endif /* ! defined (__math_68881) */ -#endif /* ! defined (_REENT_ONLY) */ - -#endif - -#endif /* _MATH_H_ */ diff --git a/app/libc/c_signal.h b/app/libc/c_signal.h deleted file mode 100644 index dab308f4ed..0000000000 --- a/app/libc/c_signal.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef _C_SIGNAL_H_ -#define _C_SIGNAL_H_ - -#include - -#endif /* _C_SIGNAL_H_ */ diff --git a/app/libc/c_stdarg.h b/app/libc/c_stdarg.h deleted file mode 100644 index 1fa745d37c..0000000000 --- a/app/libc/c_stdarg.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef __c_stdarg_h -#define __c_stdarg_h - -#if defined(__GNUC__) - -#include - -#else - -typedef char * va_list; - -#define _INTSIZEOF(n) ((sizeof(n) + sizeof(int) - 1) & ~(sizeof(int) - 1)) - -#define va_start(ap,v) (ap = (va_list)&v + _INTSIZEOF(v)) -#define va_arg(ap,t) (*(t *)((ap += _INTSIZEOF(t)) - _INTSIZEOF(t))) -#define va_end(ap) (ap = (va_list)0) - -#endif - -#endif - -/* end of c_stdarg.h */ diff --git a/app/libc/c_stddef.h b/app/libc/c_stddef.h deleted file mode 100644 index f87717c4b1..0000000000 --- a/app/libc/c_stddef.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef __c_stddef_h -#define __c_stddef_h - -typedef signed int ptrdiff_t; - -#if !defined(offsetof) -#define offsetof(s, m) (size_t)&(((s *)0)->m) -#endif - -#if !defined(__size_t) - #define __size_t 1 - typedef unsigned int size_t; /* others (e.g. ) also define */ - /* the unsigned integral type of the result of the sizeof operator. */ -#endif - -#undef NULL /* others (e.g. ) also define */ -#define NULL 0 - /* null pointer constant. */ - -#endif - -/* end of c_stddef.h */ - diff --git a/app/libc/c_stdint.h b/app/libc/c_stdint.h deleted file mode 100644 index 734c5f67a7..0000000000 --- a/app/libc/c_stdint.h +++ /dev/null @@ -1,273 +0,0 @@ -#ifndef __c_stdint_h -#define __c_stdint_h - -#include "c_types.h" -#if 0 -/* - * Depending on compiler version __int64 or __INT64_TYPE__ should be defined. - */ -#ifndef __int64 - #ifdef __INT64_TYPE__ - #define __int64 __INT64_TYPE__ - #else - #define __int64 long long - #endif - /* On some architectures neither of these may be defined - if so, fall - through and error out if used. */ -#endif - - #ifndef __STDINT_DECLS - #define __STDINT_DECLS - - #undef __CLIBNS - - #ifdef __cplusplus - namespace std { - #define __CLIBNS std:: - extern "C" { - #else - #define __CLIBNS - #endif /* __cplusplus */ - - -/* - * 'signed' is redundant below, except for 'signed char' and if - * the typedef is used to declare a bitfield. - * '__int64' is used instead of 'long long' so that this header - * can be used in --strict mode. - */ - - /* 7.18.1.1 */ - - /* exact-width signed integer types */ -typedef signed char int8_t; -typedef signed short int int16_t; -typedef signed int int32_t; -typedef signed __int64 int64_t; - - /* exact-width unsigned integer types */ -typedef unsigned char uint8_t; -typedef unsigned short int uint16_t; -typedef unsigned int uint32_t; -typedef unsigned __int64 uint64_t; - - /* 7.18.1.2 */ - - /* smallest type of at least n bits */ - /* minimum-width signed integer types */ -typedef signed char int_least8_t; -typedef signed short int int_least16_t; -typedef signed int int_least32_t; -typedef signed __int64 int_least64_t; - - /* minimum-width unsigned integer types */ -typedef unsigned char uint_least8_t; -typedef unsigned short int uint_least16_t; -typedef unsigned int uint_least32_t; -typedef unsigned __int64 uint_least64_t; - - /* 7.18.1.3 */ - - /* fastest minimum-width signed integer types */ -typedef signed int int_fast8_t; -typedef signed int int_fast16_t; -typedef signed int int_fast32_t; -typedef signed __int64 int_fast64_t; - - /* fastest minimum-width unsigned integer types */ -typedef unsigned int uint_fast8_t; -typedef unsigned int uint_fast16_t; -typedef unsigned int uint_fast32_t; -typedef unsigned __int64 uint_fast64_t; - - /* 7.18.1.4 integer types capable of holding object pointers */ -typedef signed int intptr_t; -typedef unsigned int uintptr_t; - - /* 7.18.1.5 greatest-width integer types */ -typedef signed __int64 intmax_t; -typedef unsigned __int64 uintmax_t; - - -#if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS) - - /* 7.18.2.1 */ - - /* minimum values of exact-width signed integer types */ -#define INT8_MIN -128 -#define INT16_MIN -32768 -#define INT32_MIN (~0x7fffffff) /* -2147483648 is unsigned */ -#define INT64_MIN __ESCAPE__(~0x7fffffffffffffffll) /* -9223372036854775808 is unsigned */ - - /* maximum values of exact-width signed integer types */ -#define INT8_MAX 127 -#define INT16_MAX 32767 -#define INT32_MAX 2147483647 -#define INT64_MAX __ESCAPE__(9223372036854775807ll) - - /* maximum values of exact-width unsigned integer types */ -#define UINT8_MAX 255 -#define UINT16_MAX 65535 -#define UINT32_MAX 4294967295u -#define UINT64_MAX __ESCAPE__(18446744073709551615ull) - - /* 7.18.2.2 */ - - /* minimum values of minimum-width signed integer types */ -#define INT_LEAST8_MIN -128 -#define INT_LEAST16_MIN -32768 -#define INT_LEAST32_MIN (~0x7fffffff) -#define INT_LEAST64_MIN __ESCAPE__(~0x7fffffffffffffffll) - - /* maximum values of minimum-width signed integer types */ -#define INT_LEAST8_MAX 127 -#define INT_LEAST16_MAX 32767 -#define INT_LEAST32_MAX 2147483647 -#define INT_LEAST64_MAX __ESCAPE__(9223372036854775807ll) - - /* maximum values of minimum-width unsigned integer types */ -#define UINT_LEAST8_MAX 255 -#define UINT_LEAST16_MAX 65535 -#define UINT_LEAST32_MAX 4294967295u -#define UINT_LEAST64_MAX __ESCAPE__(18446744073709551615ull) - - /* 7.18.2.3 */ - - /* minimum values of fastest minimum-width signed integer types */ -#define INT_FAST8_MIN (~0x7fffffff) -#define INT_FAST16_MIN (~0x7fffffff) -#define INT_FAST32_MIN (~0x7fffffff) -#define INT_FAST64_MIN __ESCAPE__(~0x7fffffffffffffffll) - - /* maximum values of fastest minimum-width signed integer types */ -#define INT_FAST8_MAX 2147483647 -#define INT_FAST16_MAX 2147483647 -#define INT_FAST32_MAX 2147483647 -#define INT_FAST64_MAX __ESCAPE__(9223372036854775807ll) - - /* maximum values of fastest minimum-width unsigned integer types */ -#define UINT_FAST8_MAX 4294967295u -#define UINT_FAST16_MAX 4294967295u -#define UINT_FAST32_MAX 4294967295u -#define UINT_FAST64_MAX __ESCAPE__(18446744073709551615ull) - - /* 7.18.2.4 */ - - /* minimum value of pointer-holding signed integer type */ -#define INTPTR_MIN (~0x7fffffff) - - /* maximum value of pointer-holding signed integer type */ -#define INTPTR_MAX 2147483647 - - /* maximum value of pointer-holding unsigned integer type */ -#define UINTPTR_MAX 4294967295u - - /* 7.18.2.5 */ - - /* minimum value of greatest-width signed integer type */ -#define INTMAX_MIN __ESCAPE__(~0x7fffffffffffffffll) - - /* maximum value of greatest-width signed integer type */ -#define INTMAX_MAX __ESCAPE__(9223372036854775807ll) - - /* maximum value of greatest-width unsigned integer type */ -#define UINTMAX_MAX __ESCAPE__(18446744073709551615ull) - - /* 7.18.3 */ - - /* limits of ptrdiff_t */ -#define PTRDIFF_MIN (~0x7fffffff) -#define PTRDIFF_MAX 2147483647 - - /* limits of sig_atomic_t */ -#define SIG_ATOMIC_MIN (~0x7fffffff) -#define SIG_ATOMIC_MAX 2147483647 - - /* limit of size_t */ -#define SIZE_MAX 4294967295u - - /* limits of wchar_t */ - /* NB we have to undef and redef because they're defined in both - * stdint.h and wchar.h */ -#undef WCHAR_MIN -#undef WCHAR_MAX - -#if defined(__WCHAR32) || (defined(__ARM_SIZEOF_WCHAR_T) && __ARM_SIZEOF_WCHAR_T == 4) - #define WCHAR_MIN 0 - #define WCHAR_MAX 0xffffffffU -#else - #define WCHAR_MIN 0 - #define WCHAR_MAX 65535 -#endif - - /* limits of wint_t */ -#define WINT_MIN (~0x7fffffff) -#define WINT_MAX 2147483647 - -#endif /* __STDC_LIMIT_MACROS */ - -#if !defined(__cplusplus) || defined(__STDC_CONSTANT_MACROS) - - /* 7.18.4.1 macros for minimum-width integer constants */ -#define INT8_C(x) (x) -#define INT16_C(x) (x) -#define INT32_C(x) (x) -#define INT64_C(x) __ESCAPE__(x ## ll) - -#define UINT8_C(x) (x ## u) -#define UINT16_C(x) (x ## u) -#define UINT32_C(x) (x ## u) -#define UINT64_C(x) __ESCAPE__(x ## ull) - - /* 7.18.4.2 macros for greatest-width integer constants */ -#define INTMAX_C(x) __ESCAPE__(x ## ll) -#define UINTMAX_C(x) __ESCAPE__(x ## ull) - -#endif /* __STDC_CONSTANT_MACROS */ - - #ifdef __cplusplus - } /* extern "C" */ - } /* namespace std */ - #endif /* __cplusplus */ - #endif /* __STDINT_DECLS */ - - #ifdef __cplusplus - #ifndef __STDINT_NO_EXPORTS - using ::std::int8_t; - using ::std::int16_t; - using ::std::int32_t; - using ::std::int64_t; - using ::std::uint8_t; - using ::std::uint16_t; - using ::std::uint32_t; - using ::std::uint64_t; - using ::std::int_least8_t; - using ::std::int_least16_t; - using ::std::int_least32_t; - using ::std::int_least64_t; - using ::std::uint_least8_t; - using ::std::uint_least16_t; - using ::std::uint_least32_t; - using ::std::uint_least64_t; - using ::std::int_fast8_t; - using ::std::int_fast16_t; - using ::std::int_fast32_t; - using ::std::int_fast64_t; - using ::std::uint_fast8_t; - using ::std::uint_fast16_t; - using ::std::uint_fast32_t; - using ::std::uint_fast64_t; - using ::std::intptr_t; - using ::std::uintptr_t; - using ::std::intmax_t; - using ::std::uintmax_t; - #endif - #endif /* __cplusplus */ -#endif - -#endif /* __c_stdint_h */ - -/* end of c_stdint.h */ - - - diff --git a/app/libc/c_stdio.h b/app/libc/c_stdio.h deleted file mode 100644 index 4c9a9bf34b..0000000000 --- a/app/libc/c_stdio.h +++ /dev/null @@ -1,105 +0,0 @@ -#ifndef _C_STDIO_H_ -#define _C_STDIO_H_ - -#define __need_size_t - -#include "c_stddef.h" -#include "osapi.h" -// #include "driver/uart.h" - -// #define __need___va_list -//#include "c_stdarg.h" - -//struct __sFILE{ -// int _r; /* read space left for getc() */ -// int _w; /* write space left for putc() */ -//}; -// typedef struct __sFILE __FILE; -// typedef __FILE FILE; - -extern int c_stdin; -extern int c_stdout; -extern int c_stderr; - -// #define _IOFBF 0 /* setvbuf should set fully buffered */ -// #define _IOLBF 1 /* setvbuf should set line buffered */ -// #define _IONBF 2 /* setvbuf should set unbuffered */ - -// #ifndef NULL -// #define NULL 0 -// #endif - -#define EOF (-1) - -#ifdef __BUFSIZ__ -#define BUFSIZ __BUFSIZ__ -#else -#define BUFSIZ 1024 -#endif - -#ifndef SEEK_SET -#define SEEK_SET 0 /* set file offset to offset */ -#endif -#ifndef SEEK_CUR -#define SEEK_CUR 1 /* set file offset to current plus offset */ -#endif -#ifndef SEEK_END -#define SEEK_END 2 /* set file offset to EOF plus offset */ -#endif - -// #define c_malloc os_malloc -// #define c_zalloc os_zalloc -// #define c_free os_free - -extern void output_redirect(const char *str); -#define c_puts output_redirect - -// #define c_printf os_printf -// int c_printf(const char *c, ...); -#if defined( LUA_NUMBER_INTEGRAL ) -#define c_sprintf os_sprintf -#else -#include "c_stdarg.h" -int c_sprintf(char* s,const char *fmt, ...); -#endif - -extern void dbg_printf(const char *fmt, ...) __attribute__ ((format (printf, 1, 2))); - -#define c_vsprintf ets_vsprintf -#define c_printf(...) do { \ - unsigned char __print_buf[BUFSIZ]; \ - c_sprintf(__print_buf, __VA_ARGS__); \ - c_puts(__print_buf); \ -} while(0) - -// #define c_getc ets_getc -// #define c_getchar ets_getc -// note: contact esp to ensure the real getchar function.. - -// FILE *c_fopen(const char *_name, const char *_type); -// FILE *c_freopen(const char *, const char *, FILE *); -// FILE *c_tmpfile(void); - -// int c_putchar(int); -// int c_printf(const char *, ...); -// int c_sprintf(char *, const char *, ...); -// int c_getc(FILE *); - -// int c_ungetc(int, FILE *); - -// int c_fprintf(FILE *, const char *, ...); -// int c_fscanf(FILE *, const char *, ...); -// int c_fclose(FILE *); -// int c_fflush(FILE *); -// int c_setvbuf(FILE *, char *, int, size_t); -// void c_clearerr(FILE *); -// int c_fseek(FILE *, long, int); -// long c_ftell( FILE *); -// int c_fputs(const char *, FILE *); -// char *c_fgets(char *, int, FILE *); -// size_t c_fread(void *, size_t _size, size_t _n, FILE *); -// size_t c_fwrite(const void * , size_t _size, size_t _n, FILE *); -// int c_feof(FILE *); -// int c_ferror(FILE *); - -#endif /* _C_STDIO_H_ */ diff --git a/app/libc/c_stdlib.h b/app/libc/c_stdlib.h deleted file mode 100644 index 171c7fbb2e..0000000000 --- a/app/libc/c_stdlib.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * c_stdlib.h - * - * Definitions for common types, variables, and functions. - */ - -#ifndef _C_STDLIB_H_ -#define _C_STDLIB_H_ - -#include "c_stddef.h" -#include "mem.h" - -#include - -#define EXIT_FAILURE 1 -#define EXIT_SUCCESS 0 - -#define __INT_MAX__ 2147483647 -#undef __RAND_MAX -#if __INT_MAX__ == 32767 -#define __RAND_MAX 32767 -#else -#define __RAND_MAX 0x7fffffff -#endif -#define RAND_MAX __RAND_MAX - -#ifndef mem_realloc -#define mem_realloc pvPortRealloc -#endif -#ifndef os_realloc -#define os_realloc(p, s) mem_realloc((p), (s)) -#endif - -#define c_free os_free -#define c_malloc os_malloc -#define c_zalloc os_zalloc -#define c_realloc os_realloc - -#define c_abs abs -#define c_atoi atoi -//#define c_strtod strtod -#define c_strtol strtol -#define c_strtoul strtoul - -// int c_abs(int); - -// void c_exit(int); - -//const char *c_getenv(const char *__string); - -// void *c_malloc(size_t __size); -// void *c_zalloc(size_t __size); -// void c_free(void *); - -// int c_rand(void); -// void c_srand(unsigned int __seed); - -// int c_atoi(const char *__nptr); -double c_strtod(const char *__n, char **__end_PTR); -// // long c_strtol(const char *__n, char **__end_PTR, int __base); -// unsigned long c_strtoul(const char *__n, char **__end_PTR, int __base); -// // long long c_strtoll(const char *__n, char **__end_PTR, int __base); - -#endif /* _C_STDLIB_H_ */ diff --git a/app/libc/c_string.c b/app/libc/c_string.c deleted file mode 100644 index 011a1899af..0000000000 --- a/app/libc/c_string.c +++ /dev/null @@ -1,129 +0,0 @@ -#include "c_string.h" -#include "c_stdlib.h" - -// const char *c_strstr(const char * __s1, const char * __s2){ -// } - -// char *c_strncat(char * s1, const char * s2, size_t n){ -// } - -// size_t c_strcspn(const char * s1, const char * s2){ -// } - -// const char *c_strpbrk(const char * s1, const char * s2){ -// } - -// int c_strcoll(const char * s1, const char * s2){ -// } -// -char *c_strdup(const char *c) { - int len = os_strlen(c) + 1; - char *ret = os_malloc(len); - if (ret) { - memcpy(ret, c, len); - } - return ret; -} - -/* $OpenBSD: strlcpy.c,v 1.8 2003/06/17 21:56:24 millert Exp $ */ - -/* - * Copyright (c) 1998 Todd C. Miller - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -/* - * Copy src to string dst of size siz. At most siz-1 characters - * will be copied. Always NUL terminates (unless siz == 0). - * Returns strlen(src); if retval >= siz, truncation occurred. - */ -size_t -c_strlcpy(char *dst, const char *src, size_t siz) -{ - register char *d = dst; - register const char *s = src; - register size_t n = siz; - - /* Copy as many bytes as will fit */ - if (n != 0 && --n != 0) { - do { - if ((*d++ = *s++) == 0) - break; - } while (--n != 0); - } - - /* Not enough room in dst, add NUL and traverse rest of src */ - if (n == 0) { - if (siz != 0) - *d = '\0'; /* NUL-terminate dst */ - while (*s++) - ; - } - - return(s - src - 1); /* count does not include NUL */ -} - -/* $OpenBSD: strlcat.c,v 1.11 2003/06/17 21:56:24 millert Exp $ */ - -/* - * Copyright (c) 1998 Todd C. Miller - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -/* - * Appends src to string dst of size siz (unlike strncat, siz is the - * full size of dst, not space left). At most siz-1 characters - * will be copied. Always NUL terminates (unless siz <= strlen(dst)). - * Returns strlen(src) + MIN(siz, strlen(initial dst)). - * If retval >= siz, truncation occurred. - */ -size_t -c_strlcat(char *dst, const char *src, size_t siz) -{ - register char *d = dst; - register const char *s = src; - register size_t n = siz; - size_t dlen; - - /* Find the end of dst and adjust bytes left but don't go past end */ - while (n-- != 0 && *d != '\0') - d++; - dlen = d - dst; - n = siz - dlen; - - if (n == 0) - return(dlen + strlen(s)); - while (*s != '\0') { - if (n != 1) { - *d++ = *s; - n--; - } - s++; - } - *d = '\0'; - - return(dlen + (s - src)); /* count does not include NUL */ -} - diff --git a/app/libc/c_string.h b/app/libc/c_string.h deleted file mode 100644 index cced15bacc..0000000000 --- a/app/libc/c_string.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * c_string.h - * - * Definitions for memory and string functions. - */ - -#ifndef _C_STRING_H_ -#define _C_STRING_H_ -#include "c_stddef.h" -#include "osapi.h" - -#ifndef NULL -#define NULL 0 -#endif - -#define c_memcmp os_memcmp -#define c_memcpy os_memcpy -#define c_memmove os_memmove -#define c_memset os_memset - -#define c_strcat os_strcat -#define c_strchr os_strchr -#define c_strcmp os_strcmp -#define c_strcpy os_strcpy -#define c_strlen os_strlen -#define c_strncmp os_strncmp -#define c_strncpy os_strncpy -// #define c_strstr os_strstr -#define c_strncasecmp c_strncmp - -#define c_strstr strstr -#define c_strncat strncat -#define c_strcspn strcspn -#define c_strpbrk strpbrk -#define c_strcoll strcoll -#define c_strrchr strrchr - -// const char *c_strstr(const char * __s1, const char * __s2); -// char *c_strncat(char * __restrict /*s1*/, const char * __restrict /*s2*/, size_t n); -// size_t c_strcspn(const char * s1, const char * s2); -// const char *c_strpbrk(const char * /*s1*/, const char * /*s2*/); -// int c_strcoll(const char * /*s1*/, const char * /*s2*/); -// - -extern size_t c_strlcpy(char *dst, const char *src, size_t siz); -extern size_t c_strlcat(char *dst, const char *src, size_t siz); -extern char *c_strdup(const char *src); - - -#endif /* _C_STRING_H_ */ diff --git a/app/libc/c_math.c b/app/libc/math.c similarity index 72% rename from app/libc/c_math.c rename to app/libc/math.c index 2eb4468785..3c469209f3 100644 --- a/app/libc/c_math.c +++ b/app/libc/math.c @@ -1,6 +1,5 @@ -#include "c_math.h" -#include "c_types.h" -#include "user_config.h" +#include +#include double floor(double x) { @@ -135,103 +134,3 @@ double pow(double x, double y) double res = ldexp(z, m); return flipsignal ? -res : res; } - -#if 0 -#ifndef __math_68881 -double atan(double x) -{ - return x; -} -double cos(double x) -{ - return x; -} -double sin(double x) -{ - return x; -} -double tan(double x) -{ - return x; -} -double tanh(double x) -{ - return x; -} -double frexp(double x, int *y) -{ - return x; -} -double modf(double x, double *y) -{ - return x; -} -double ceil(double x) -{ - return x; -} -double fabs(double x) -{ - return x; -} -double floor(double x) -{ - return x; -} -#endif /* ! defined (__math_68881) */ - -/* Non reentrant ANSI C functions. */ - -#ifndef _REENT_ONLY -#ifndef __math_68881 -double acos(double x) -{ - return x; -} -double asin(double x) -{ - return x; -} -double atan2(double x, double y) -{ - return x; -} -double cosh(double x) -{ - return x; -} -double sinh(double x) -{ - return x; -} -double exp(double x) -{ - return x; -} -double ldexp(double x, int y) -{ - return x; -} -double log(double x) -{ - return x; -} -double log10(double x) -{ - return x; -} -double pow(double x, double y) -{ - return x; -} -double sqrt(double x) -{ - return x; -} -double fmod(double x, double y) -{ - return x; -} -#endif /* ! defined (__math_68881) */ -#endif /* ! defined (_REENT_ONLY) */ -#endif diff --git a/app/libc/c_stdio.c b/app/libc/stdio.c similarity index 95% rename from app/libc/c_stdio.c rename to app/libc/stdio.c index 3b634613af..0b03ef8fd0 100644 --- a/app/libc/c_stdio.c +++ b/app/libc/stdio.c @@ -1,61 +1,28 @@ -#include "c_stdio.h" -// #include "driver/uart.h" +#include int c_stdin = 999; int c_stdout = 1000; int c_stderr = 1001; -// FILE *c_fopen(const char *_name, const char *_type){ -// } -// FILE *c_freopen(const char *_name, const char *_type, FILE *_f){ -// } -// FILE *c_tmpfile(void){ -// } - -// int c_putchar(int c){ -// } - -// int c_printf(const char *c, ...){ -// } - -// int c_sprintf(char *c, const char *s, ...){ -// } - -// int c_fprintf(FILE *f, const char *s, ...){ -// } -// int c_fscanf(FILE *f, const char *s, ...){ -// } -// int c_fclose(FILE *f){ -// } -// int c_fflush(FILE *f){ -// } -// int c_setvbuf(FILE *f, char *c, int d, size_t t){ -// } -// void c_clearerr(FILE *f){ -// } -// int c_fseek(FILE *f, long l, int d){ -// } -// long c_ftell( FILE *f){ -// } -// int c_fputs(const char *c, FILE *f){ -// } -// char *c_fgets(char *c, int d, FILE *f){ -// } -// int c_ungetc(int d, FILE *f){ -// } -// size_t c_fread(void *p, size_t _size, size_t _n, FILE *f){ -// } -// size_t c_fwrite(const void *p, size_t _size, size_t _n, FILE *f){ -// } -// int c_feof(FILE *f){ -// } -// int c_ferror(FILE *f){ -// } -// int c_getc(FILE *f){ -// } - #if defined( LUA_NUMBER_INTEGRAL ) +#include + +int sprintf(char *s, const char *fmt, ...) +{ + int n; + va_list arg; + va_start(arg, fmt); + n = ets_vsprintf(s, fmt, arg); + va_end(arg); + return n; +} + +int vsprintf (char *d, const char *s, va_list ap) +{ + return ets_vsprintf(d, s, ap); +} + #else #define FLOATINGPT 1 @@ -97,8 +64,7 @@ int c_stderr = 1001; * SUCH DAMAGE. * */ -//#include -#include "c_string.h" +#include char * strichr(char *p, int c) @@ -147,8 +113,7 @@ strichr(char *p, int c) * SUCH DAMAGE. * */ -//#include -#include "c_string.h" +#include #define FMT_RJUST 0 #define FMT_LJUST 1 @@ -221,10 +186,8 @@ str_fmt(char *p, int size, int fmt) * SUCH DAMAGE. * */ -//#include -//#include -#include "c_string.h" -#include "c_ctype.h" +#include +#include void strtoupper(char *p) @@ -269,10 +232,9 @@ strtoupper(char *p) */ //#include -//#include +#include +#include //#include -#include "c_string.h" -typedef unsigned int u_int32_t; typedef unsigned int u_int; typedef unsigned long u_long; typedef int32_t register_t; @@ -371,7 +333,7 @@ _atob (u_quad_t *vp, char *p, int base) * converts p to binary result in vp, rtn 1 on success */ int -atob(u_int32_t *vp, char *p, int base) +atob(uint32_t *vp, char *p, int base) { u_quad_t v; @@ -554,13 +516,10 @@ gethex(int32_t *vp, char *p, int n) * */ //#include -//#include -//#include -//#include //#include -#include "c_stdarg.h" -#include "c_string.h" -#include "c_ctype.h" +#include +#include +#include /* * int vsprintf(d,s,ap) @@ -1091,10 +1050,9 @@ exponent(char *p, int exp, int fmtch) } return (p); } -#endif /* FLOATINGPT */ -int c_sprintf(char *s, const char *fmt, ...) +int sprintf(char *s, const char *fmt, ...) { int n; va_list arg; @@ -1104,4 +1062,6 @@ int c_sprintf(char *s, const char *fmt, ...) return n; } +#endif /* FLOATINGPT */ + #endif diff --git a/app/libc/c_stdlib.c b/app/libc/stdlib.c similarity index 92% rename from app/libc/c_stdlib.c rename to app/libc/stdlib.c index 4f39cc8631..6299eceb34 100644 --- a/app/libc/c_stdlib.c +++ b/app/libc/stdlib.c @@ -1,23 +1,13 @@ -//#include "user_interface.h" #include "user_config.h" -#ifdef LUA_CROSS_COMPILER - #include #include #include + +#ifdef LUA_CROSS_COMPILER #define ICACHE_RODATA_ATTR #define TRUE 1 #define FALSE 0 - -#else - -#include "c_stdlib.h" -#include "c_types.h" -#include "c_string.h" -#include <_ansi.h> -//#include -//#include "mprec.h" #endif double powersOf10[] ICACHE_STORE_ATTR ICACHE_RODATA_ATTR = /* Table giving binary powers of 10. Entry */ { @@ -32,7 +22,7 @@ double powersOf10[] ICACHE_STORE_ATTR ICACHE_RODATA_ATTR = /* Table giving bin 1.0e256 }; -double c_strtod(const char *string, char **endPtr) +double strtod(const char *string, char **endPtr) { int maxExponent = 511; /* Largest possible base 10 exponent. Any * exponent larger than this will already @@ -256,10 +246,3 @@ double c_strtod(const char *string, char **endPtr) } return fraction; } - -// long c_strtol(const char *__n, char **__end_PTR, int __base){ -// } -// unsigned long c_strtoul(const char *__n, char **__end_PTR, int __base){ -// } -// long long c_strtoll(const char *__n, char **__end_PTR, int __base){ -// } diff --git a/app/lua/lapi.c b/app/lua/lapi.c index 29df306be3..6139e2f2cf 100644 --- a/app/lua/lapi.c +++ b/app/lua/lapi.c @@ -10,9 +10,8 @@ #include "lua.h" -//#include C_HEADER_ASSERT -#include C_HEADER_MATH -#include C_HEADER_STRING +#include +#include #include "lapi.h" #include "ldebug.h" #include "ldo.h" @@ -463,7 +462,7 @@ LUA_API void lua_pushstring (lua_State *L, const char *s) { if (s == NULL) lua_pushnil(L); else - lua_pushlstring(L, s, c_strlen(s)); + lua_pushlstring(L, s, strlen(s)); } diff --git a/app/lua/lauxlib.c b/app/lua/lauxlib.c index de2ae48978..773d01a35f 100644 --- a/app/lua/lauxlib.c +++ b/app/lua/lauxlib.c @@ -7,18 +7,19 @@ #define LUAC_CROSS_FILE #include "lua.h" -#include C_HEADER_CTYPE +#include #ifdef __MINGW__ #include #else #ifdef _MSC_VER //msvc #defines errno, which interferes with our #include macro #undef errno #endif -#include C_HEADER_ERRNO +#include #endif -#include C_HEADER_STDIO -#include C_HEADER_STDLIB -#include C_HEADER_STRING +#include +#include +#include +#include #ifndef LUA_CROSS_COMPILER #include "vfs.h" #include "user_interface.h" @@ -100,7 +101,7 @@ static void scanBlocks (void) { for (i=0; p ;i++) { s = memcmp(p->mark, marker, MARKSIZE) ? '<' : ' '; e = memcmp(cast(char *, p+1) + p->size, marker, MARKSIZE) ? '>' : ' '; - c_printf("%4u %p %8lu %c %c\n", i, p, p->size, s, e); + printf("%4u %p %8lu %c %c\n", i, p, p->size, s, e); ASSERT(p->next); p = p->next; } @@ -136,7 +137,7 @@ static void freeblock (MemHeader *block) { p->next = next; } fillmem(block, sizeof(MemHeader) + size + MARKSIZE); /* erase block */ - c_free(block); /* actually free block */ + free(block); /* actually free block */ mc.numblocks--; /* update counts */ mc.total -= size; } @@ -163,7 +164,7 @@ void *debug_realloc (void *b, size_t oldsize, size_t size) { MemHeader *newblock; size_t commonsize = (oldsize < size) ? oldsize : size; size_t realsize = sizeof(MemHeader) + size + MARKSIZE; - newblock = cast(MemHeader *, c_malloc(realsize)); /* alloc a new block */ + newblock = cast(MemHeader *, malloc(realsize)); /* alloc a new block */ if (newblock == NULL) return NULL; /* really out of memory? */ if (block) { @@ -190,7 +191,7 @@ void *debug_realloc (void *b, size_t oldsize, size_t size) { /* }====================================================================== */ #else -#define this_realloc(p,os,s) c_realloc(p,s) +#define this_realloc(p,os,s) realloc(p,s) #endif /* DEBUG_ALLOCATOR */ /* @@ -205,7 +206,7 @@ LUALIB_API int luaL_argerror (lua_State *L, int narg, const char *extramsg) { if (!lua_getstack(L, 0, &ar)) /* no stack frame? */ return luaL_error(L, "bad argument #%d (%s)", narg, extramsg); lua_getinfo(L, "n", &ar); - if (c_strcmp(ar.namewhat, "method") == 0) { + if (strcmp(ar.namewhat, "method") == 0) { narg--; /* do not count `self' */ if (narg == 0) /* error is in the self argument itself? */ return luaL_error(L, "calling " LUA_QS " on bad self (%s)", @@ -262,7 +263,7 @@ LUALIB_API int luaL_checkoption (lua_State *L, int narg, const char *def, luaL_checkstring(L, narg); int i; for (i=0; lst[i]; i++) - if (c_strcmp(lst[i], name) == 0) + if (strcmp(lst[i], name) == 0) return i; return luaL_argerror(L, narg, lua_pushfstring(L, "invalid option " LUA_QS, name)); @@ -352,7 +353,7 @@ LUALIB_API const char *luaL_optlstring (lua_State *L, int narg, const char *def, size_t *len) { if (lua_isnoneornil(L, narg)) { if (len) - *len = (def ? c_strlen(def) : 0); + *len = (def ? strlen(def) : 0); return def; } else return luaL_checklstring(L, narg, len); @@ -533,10 +534,10 @@ LUALIB_API int luaL_getn (lua_State *L, int t) { LUALIB_API const char *luaL_gsub (lua_State *L, const char *s, const char *p, const char *r) { const char *wild; - size_t l = c_strlen(p); + size_t l = strlen(p); luaL_Buffer b; luaL_buffinit(L, &b); - while ((wild = c_strstr(s, p)) != NULL) { + while ((wild = strstr(s, p)) != NULL) { luaL_addlstring(&b, s, wild - s); /* push prefix */ luaL_addstring(&b, r); /* push replacement in place of pattern */ s = wild + l; /* continue after `p' */ @@ -552,8 +553,8 @@ LUALIB_API const char *luaL_findtable (lua_State *L, int idx, const char *e; lua_pushvalue(L, idx); do { - e = c_strchr(fname, '.'); - if (e == NULL) e = fname + c_strlen(fname); + e = strchr(fname, '.'); + if (e == NULL) e = fname + strlen(fname); lua_pushlstring(L, fname, e - fname); lua_rawget(L, -2); @@ -634,7 +635,7 @@ LUALIB_API void luaL_addlstring (luaL_Buffer *B, const char *s, size_t l) { LUALIB_API void luaL_addstring (luaL_Buffer *B, const char *s) { - luaL_addlstring(B, s, c_strlen(s)); + luaL_addlstring(B, s, strlen(s)); } @@ -650,7 +651,7 @@ LUALIB_API void luaL_addvalue (luaL_Buffer *B) { size_t vl; const char *s = lua_tolstring(L, -1, &vl); if (vl <= bufffree(B)) { /* fit into buffer? */ - c_memcpy(B->p, s, vl); /* put it there */ + memcpy(B->p, s, vl); /* put it there */ B->p += vl; lua_pop(L, 1); /* remove from stack */ } @@ -730,14 +731,14 @@ static const char *getF (lua_State *L, void *ud, size_t *size) { *size = 1; return "\n"; } - if (c_feof(lf->f)) return NULL; - *size = c_fread(lf->buff, 1, sizeof(lf->buff), lf->f); + if (feof(lf->f)) return NULL; + *size = fread(lf->buff, 1, sizeof(lf->buff), lf->f); return (*size > 0) ? lf->buff : NULL; } static int errfile (lua_State *L, const char *what, int fnameindex) { - const char *serr = c_strerror(errno); + const char *serr = strerror(errno); const char *filename = lua_tostring(L, fnameindex) + 1; lua_pushfstring(L, "cannot %s %s: %s", what, filename, serr); lua_remove(L, fnameindex); @@ -757,27 +758,27 @@ LUALIB_API int luaL_loadfile (lua_State *L, const char *filename) { } else { lua_pushfstring(L, "@%s", filename); - lf.f = c_fopen(filename, "r"); + lf.f = fopen(filename, "r"); if (lf.f == NULL) return errfile(L, "open", fnameindex); } - c = c_getc(lf.f); + c = getc(lf.f); if (c == '#') { /* Unix exec. file? */ lf.extraline = 1; - while ((c = c_getc(lf.f)) != EOF && c != '\n') ; /* skip first line */ - if (c == '\n') c = c_getc(lf.f); + while ((c = getc(lf.f)) != EOF && c != '\n') ; /* skip first line */ + if (c == '\n') c = getc(lf.f); } if (c == LUA_SIGNATURE[0] && filename) { /* binary file? */ - lf.f = c_freopen(filename, "rb", lf.f); /* reopen in binary mode */ + lf.f = freopen(filename, "rb", lf.f); /* reopen in binary mode */ if (lf.f == NULL) return errfile(L, "reopen", fnameindex); /* skip eventual `#!...' */ - while ((c = c_getc(lf.f)) != EOF && c != LUA_SIGNATURE[0]) {} + while ((c = getc(lf.f)) != EOF && c != LUA_SIGNATURE[0]) {} lf.extraline = 0; } - c_ungetc(c, lf.f); + ungetc(c, lf.f); status = lua_load(L, getF, &lf, lua_tostring(L, -1)); - readstatus = c_ferror(lf.f); - if (filename) c_fclose(lf.f); /* close file (even in case of errors) */ + readstatus = ferror(lf.f); + if (filename) fclose(lf.f); /* close file (even in case of errors) */ if (readstatus) { lua_settop(L, fnameindex); /* ignore results from `lua_load' */ return errfile(L, "read", fnameindex); @@ -788,8 +789,6 @@ LUALIB_API int luaL_loadfile (lua_State *L, const char *filename) { #else -#include C_HEADER_FCNTL - typedef struct LoadFSF { int extraline; int f; @@ -893,7 +892,7 @@ LUALIB_API int luaL_loadbuffer (lua_State *L, const char *buff, size_t size, LUALIB_API int (luaL_loadstring) (lua_State *L, const char *s) { - return luaL_loadbuffer(L, s, c_strlen(s), s); + return luaL_loadbuffer(L, s, strlen(s), s); } @@ -928,7 +927,7 @@ static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) { #ifdef DEBUG_ALLOCATOR return (void *)this_realloc(ptr, osize, nsize); #else - c_free(ptr); + free(ptr); return NULL; #endif } @@ -988,7 +987,7 @@ LUALIB_API void luaL_dbgbreak(void) { static int panic (lua_State *L) { (void)L; /* to avoid warnings */ #if defined(LUA_USE_STDIO) - c_fprintf(c_stderr, "PANIC: unprotected error in call to Lua API (%s)\n", + fprintf(c_stderr, "PANIC: unprotected error in call to Lua API (%s)\n", lua_tostring(L, -1)); #else luai_writestringerror("PANIC: unprotected error in call to Lua API (%s)\n", diff --git a/app/lua/lauxlib.h b/app/lua/lauxlib.h index 333fa4e218..09dbd2c097 100644 --- a/app/lua/lauxlib.h +++ b/app/lua/lauxlib.h @@ -8,15 +8,9 @@ #ifndef lauxlib_h #define lauxlib_h - #include "lua.h" -#ifdef LUA_CROSS_COMPILER #include -#else -#include "c_stdio.h" -#endif - #if defined(LUA_COMPAT_GETN) LUALIB_API int (luaL_getn) (lua_State *L, int t); diff --git a/app/lua/lbaselib.c b/app/lua/lbaselib.c index 16ee1cf953..02b69bc872 100644 --- a/app/lua/lbaselib.c +++ b/app/lua/lbaselib.c @@ -11,9 +11,9 @@ #define LUAC_CROSS_FILE #include "lua.h" -#include C_HEADER_STDIO -#include C_HEADER_STRING -#include C_HEADER_STDLIB +#include +#include +#include #include "lauxlib.h" #include "lualib.h" #include "lrotable.h" @@ -41,16 +41,16 @@ static int luaB_print (lua_State *L) { return luaL_error(L, LUA_QL("tostring") " must return a string to " LUA_QL("print")); #if defined(LUA_USE_STDIO) - if (i>1) c_fputs("\t", c_stdout); - c_fputs(s, c_stdout); + if (i>1) fputs("\t", c_stdout); + fputs(s, c_stdout); #else if (i>1) luai_writestring("\t", 1); - luai_writestring(s, c_strlen(s)); + luai_writestring(s, strlen(s)); #endif lua_pop(L, 1); /* pop result */ } #if defined(LUA_USE_STDIO) - c_fputs("\n", c_stdout); + fputs("\n", c_stdout); #else luai_writeline(); #endif @@ -72,7 +72,7 @@ static int luaB_tonumber (lua_State *L) { char *s2; unsigned long n; luaL_argcheck(L, 2 <= base && base <= 36, 2, "base out of range"); - n = c_strtoul(s1, &s2, base); + n = strtoul(s1, &s2, base); if (s1 != s2) { /* at least one valid digit? */ while (isspace((unsigned char)(*s2))) s2++; /* skip trailing spaces */ if (*s2 == '\0') { /* no invalid trailing characters? */ diff --git a/app/lua/lcode.c b/app/lua/lcode.c index ed53def708..5fa535ce42 100644 --- a/app/lua/lcode.c +++ b/app/lua/lcode.c @@ -10,7 +10,7 @@ #define LUAC_CROSS_FILE #include "lua.h" -#include C_HEADER_STDLIB +#include #include "lcode.h" #include "ldebug.h" @@ -81,7 +81,7 @@ static void fixjump (FuncState *fs, int pc, int dest) { Instruction *jmp = &fs->f->code[pc]; int offset = dest-(pc+1); lua_assert(dest != NO_JUMP); - if (c_abs(offset) > MAXARG_sBx) + if (abs(offset) > MAXARG_sBx) luaX_syntaxerror(fs->ls, "control structure too long"); SETARG_sBx(*jmp, offset); } diff --git a/app/lua/ldblib.c b/app/lua/ldblib.c index d41721bd26..d3926e9d0f 100644 --- a/app/lua/ldblib.c +++ b/app/lua/ldblib.c @@ -10,9 +10,9 @@ #define LUAC_CROSS_FILE #include "lua.h" -#include C_HEADER_STDIO -#include C_HEADER_STDLIB -#include C_HEADER_STRING +#include +#include +#include #include "lauxlib.h" #include "lualib.h" @@ -33,7 +33,7 @@ static int db_getstrings (lua_State *L) { GCObject *o; #ifndef LUA_CROSS_COMPILER const char *opt = lua_tolstring (L, 1, &n); - if (n==3 && c_memcmp(opt, "ROM", 4) == 0) { + if (n==3 && memcmp(opt, "ROM", 4) == 0) { if (G(L)->ROstrt.hash == NULL) return 0; tb = &G(L)->ROstrt; @@ -155,24 +155,24 @@ static int db_getinfo (lua_State *L) { if (!lua_getinfo(L1, options, &ar)) return luaL_argerror(L, arg+2, "invalid option"); lua_createtable(L, 0, 2); - if (c_strchr(options, 'S')) { + if (strchr(options, 'S')) { settabss(L, "source", ar.source); settabss(L, "short_src", ar.short_src); settabsi(L, "linedefined", ar.linedefined); settabsi(L, "lastlinedefined", ar.lastlinedefined); settabss(L, "what", ar.what); } - if (c_strchr(options, 'l')) + if (strchr(options, 'l')) settabsi(L, "currentline", ar.currentline); - if (c_strchr(options, 'u')) + if (strchr(options, 'u')) settabsi(L, "nups", ar.nups); - if (c_strchr(options, 'n')) { + if (strchr(options, 'n')) { settabss(L, "name", ar.name); settabss(L, "namewhat", ar.namewhat); } - if (c_strchr(options, 'L')) + if (strchr(options, 'L')) treatstackoption(L, L1, "activelines"); - if (c_strchr(options, 'f')) + if (strchr(options, 'f')) treatstackoption(L, L1, "func"); return 1; /* return table */ } @@ -261,9 +261,9 @@ static void hookf (lua_State *L, lua_Debug *ar) { static int makemask (const char *smask, int count) { int mask = 0; - if (c_strchr(smask, 'c')) mask |= LUA_MASKCALL; - if (c_strchr(smask, 'r')) mask |= LUA_MASKRET; - if (c_strchr(smask, 'l')) mask |= LUA_MASKLINE; + if (strchr(smask, 'c')) mask |= LUA_MASKCALL; + if (strchr(smask, 'r')) mask |= LUA_MASKRET; + if (strchr(smask, 'l')) mask |= LUA_MASKLINE; if (count > 0) mask |= LUA_MASKCOUNT; return mask; } @@ -340,19 +340,19 @@ static int db_debug (lua_State *L) { for (;;) { char buffer[LUA_MAXINPUT]; #if defined(LUA_USE_STDIO) - c_fputs("lua_debug> ", c_stderr); - if (c_fgets(buffer, sizeof(buffer), c_stdin) == 0 || + fputs("lua_debug> ", c_stderr); + if (fgets(buffer, sizeof(buffer), c_stdin) == 0 || #else // luai_writestringerror("%s", "lua_debug>"); if (lua_readline(L, buffer, "lua_debug>") == 0 || #endif - c_strcmp(buffer, "cont\n") == 0) + strcmp(buffer, "cont\n") == 0) return 0; - if (luaL_loadbuffer(L, buffer, c_strlen(buffer), "=(debug command)") || + if (luaL_loadbuffer(L, buffer, strlen(buffer), "=(debug command)") || lua_pcall(L, 0, 0, 0)) { #if defined(LUA_USE_STDIO) - c_fputs(lua_tostring(L, -1), c_stderr); - c_fputs("\n", c_stderr); + fputs(lua_tostring(L, -1), c_stderr); + fputs("\n", c_stderr); #else luai_writestringerror("%s\n", lua_tostring(L, -1)); #endif diff --git a/app/lua/ldebug.c b/app/lua/ldebug.c index 1441e69dc1..eab0ef62b2 100644 --- a/app/lua/ldebug.c +++ b/app/lua/ldebug.c @@ -10,7 +10,7 @@ #define LUAC_CROSS_FILE #include "lua.h" -#include C_HEADER_STRING +#include #include "lapi.h" #include "lcode.h" @@ -253,7 +253,7 @@ static int stripdebug (lua_State *L, Proto *f, int level) { TString* dummy; switch (level) { case 3: - sizepackedlineinfo = c_strlen(cast(char *, f->packedlineinfo))+1; + sizepackedlineinfo = strlen(cast(char *, f->packedlineinfo))+1; f->packedlineinfo = luaM_freearray(L, f->packedlineinfo, sizepackedlineinfo, unsigned char); len += sizepackedlineinfo; case 2: @@ -344,7 +344,7 @@ LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) { plight = fvalue(ci->func); } status = auxgetinfo(L, what, ar, f, plight, ci); - if (c_strchr(what, 'f')) { + if (strchr(what, 'f')) { if (f != NULL) setclvalue(L, L->top, f) else if (plight != NULL) @@ -353,7 +353,7 @@ LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) { setnilvalue(L->top); incr_top(L); } - if (c_strchr(what, 'L')) + if (strchr(what, 'L')) collectvalidlines(L, f); lua_unlock(L); return status; diff --git a/app/lua/ldo.c b/app/lua/ldo.c index 6414a61bc0..86126f0a4a 100644 --- a/app/lua/ldo.c +++ b/app/lua/ldo.c @@ -11,7 +11,7 @@ #define LUAC_CROSS_FILE #include "lua.h" -#include C_HEADER_STRING +#include #include "ldebug.h" #include "ldo.h" diff --git a/app/lua/ldump.c b/app/lua/ldump.c index 7681fed6c0..db2a036202 100644 --- a/app/lua/ldump.c +++ b/app/lua/ldump.c @@ -9,7 +9,7 @@ #define LUAC_CROSS_FILE #include "lua.h" -#include C_HEADER_STRING +#include #include "lobject.h" #include "lstate.h" @@ -150,9 +150,9 @@ static void DumpNumber(lua_Number x, DumpState* D) if(D->target.is_arm_fpa) { char *pnum=(char*)&y, temp[4]; - c_memcpy(temp,pnum,4); - c_memcpy(pnum,pnum+4,4); - c_memcpy(pnum+4,temp,4); + memcpy(temp,pnum,4); + memcpy(pnum,pnum+4,4); + memcpy(pnum+4,temp,4); } MaybeByteSwap((char*)&y,8,D); DumpVar(y,D); @@ -171,7 +171,7 @@ static void DumpCode(const Proto *f, DumpState* D) Align4(D); for (i=0; isizecode; i++) { - c_memcpy(buf,&f->code[i],sizeof(Instruction)); + memcpy(buf,&f->code[i],sizeof(Instruction)); MaybeByteSwap(buf,sizeof(Instruction),D); DumpBlock(buf,sizeof(Instruction),D); } @@ -230,7 +230,7 @@ static void DumpDebug(const Proto* f, DumpState* D) int i,n; #ifdef LUA_OPTIMIZE_DEBUG - n = (D->strip || f->packedlineinfo == NULL) ? 0: c_strlen(cast(char *,f->packedlineinfo))+1; + n = (D->strip || f->packedlineinfo == NULL) ? 0: strlen(cast(char *,f->packedlineinfo))+1; DumpInt(n,D); Align4(D); if (n) @@ -281,7 +281,7 @@ static void DumpHeader(DumpState* D) char *h=buf; /* This code must be kept in sync wiht luaU_header */ - c_memcpy(h,LUA_SIGNATURE,sizeof(LUA_SIGNATURE)-1); + memcpy(h,LUA_SIGNATURE,sizeof(LUA_SIGNATURE)-1); h+=sizeof(LUA_SIGNATURE)-1; *h++=(char)LUAC_VERSION; *h++=(char)LUAC_FORMAT; diff --git a/app/lua/lflash.c b/app/lua/lflash.c index 17218fe1c1..ba1c46d336 100644 --- a/app/lua/lflash.c +++ b/app/lua/lflash.c @@ -17,10 +17,10 @@ #include "vfs.h" #include "uzlib.h" -#include "c_fcntl.h" -#include "c_stdio.h" -#include "c_stdlib.h" -#include "c_string.h" +#include +#include +#include +#include /* * Flash memory is a fixed memory addressable block that is serially allocated by the @@ -388,13 +388,13 @@ static void put_byte (uint8_t value) { } -static uint8_t recall_byte (uint offset) { +static uint8_t recall_byte (unsigned offset) { if(offset > DICTIONARY_WINDOW || offset >= out->ndx) flash_error("invalid dictionary offset on inflate"); /* ndx starts at 1. Need relative to 0 */ - uint n = out->ndx - offset; - uint pos = n % WRITE_BLOCKSIZE; - uint blockNo = out->ndx / WRITE_BLOCKSIZE - n / WRITE_BLOCKSIZE; + unsigned n = out->ndx - offset; + unsigned pos = n % WRITE_BLOCKSIZE; + unsigned blockNo = out->ndx / WRITE_BLOCKSIZE - n / WRITE_BLOCKSIZE; return out->block[blockNo]->byte[pos]; } @@ -429,7 +429,7 @@ int procFirstPass (void) { fh->flash_size > flashSize || out->flagsLen != 1 + (out->flashLen/WORDSIZE - 1) / BITS_PER_WORD) flash_error("LFS length mismatch"); - out->flags = luaM_newvector(out->L, out->flagsLen, uint); + out->flags = luaM_newvector(out->L, out->flagsLen, unsigned); } /* update running CRC */ @@ -512,7 +512,7 @@ static int loadLFS (lua_State *L) { in->len = vfs_size(in->fd); if (in->len <= 200 || /* size of an empty luac output */ vfs_lseek(in->fd, in->len-4, VFS_SEEK_SET) != in->len-4 || - vfs_read(in->fd, &out->len, sizeof(uint)) != sizeof(uint)) + vfs_read(in->fd, &out->len, sizeof(unsigned)) != sizeof(unsigned)) flash_error("read error on LFS image file"); vfs_lseek(in->fd, 0, VFS_SEEK_SET); diff --git a/app/lua/lfunc.c b/app/lua/lfunc.c index fe502f6bd9..a9c6e2d964 100644 --- a/app/lua/lfunc.c +++ b/app/lua/lfunc.c @@ -9,7 +9,7 @@ #define LUAC_CROSS_FILE #include "lua.h" -#include C_HEADER_STRING +#include #include "lfunc.h" #include "lgc.h" @@ -150,7 +150,7 @@ void luaF_freeproto (lua_State *L, Proto *f) { luaM_freearray(L, f->code, f->sizecode, Instruction); #ifdef LUA_OPTIMIZE_DEBUG if (f->packedlineinfo) { - luaM_freearray(L, f->packedlineinfo, c_strlen(cast(char *, f->packedlineinfo))+1, unsigned char); + luaM_freearray(L, f->packedlineinfo, strlen(cast(char *, f->packedlineinfo))+1, unsigned char); } #else luaM_freearray(L, f->lineinfo, f->sizelineinfo, int); diff --git a/app/lua/lgc.c b/app/lua/lgc.c index 645703d660..5f1c28fa2f 100644 --- a/app/lua/lgc.c +++ b/app/lua/lgc.c @@ -9,7 +9,7 @@ #define LUAC_CROSS_FILE #include "lua.h" -#include C_HEADER_STRING +#include #include "ldebug.h" #include "ldo.h" @@ -173,8 +173,8 @@ static int traversetable (global_State *g, Table *h) { } if (mode && ttisstring(mode)) { /* is there a weak mode? */ - weakkey = (c_strchr(svalue(mode), 'k') != NULL); - weakvalue = (c_strchr(svalue(mode), 'v') != NULL); + weakkey = (strchr(svalue(mode), 'k') != NULL); + weakvalue = (strchr(svalue(mode), 'v') != NULL); if (weakkey || weakvalue) { /* is really weak? */ h->marked &= ~(KEYWEAK | VALUEWEAK); /* clear bits */ h->marked |= cast_byte((weakkey << KEYWEAKBIT) | @@ -333,7 +333,7 @@ static l_mem propagatemark (global_State *g) { (proto_isreadonly(p) ? 0 : sizeof(Instruction) * p->sizecode + #ifdef LUA_OPTIMIZE_DEBUG (p->packedlineinfo ? - c_strlen(cast(char *, p->packedlineinfo))+1 : + strlen(cast(char *, p->packedlineinfo))+1 : 0)); #else sizeof(int) * p->sizelineinfo); diff --git a/app/lua/llex.c b/app/lua/llex.c index d38c993b58..4a8edbc383 100644 --- a/app/lua/llex.c +++ b/app/lua/llex.c @@ -10,9 +10,9 @@ #define LUAC_CROSS_FILE #include "lua.h" -#include C_HEADER_CTYPE -#include C_HEADER_LOCALE -#include C_HEADER_STRING +#include +#include +#include #include "ldo.h" #include "llex.h" @@ -154,7 +154,7 @@ void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, TString *source) { static int check_next (LexState *ls, const char *set) { - if (!c_strchr(set, ls->current)) + if (!strchr(set, ls->current)) return 0; save_and_next(ls); return 1; @@ -422,7 +422,7 @@ static int llex (LexState *ls, SemInfo *seminfo) { /* look for reserved word */ save(ls, '\0'); for (i = 0; i < NUM_RESERVED; i++) - if (!c_strcmp(luaX_tokens[i], luaZ_buffer(ls->buff))) + if (!strcmp(luaX_tokens[i], luaZ_buffer(ls->buff))) return i + FIRST_RESERVED; ts = luaX_newstring(ls, luaZ_buffer(ls->buff), luaZ_bufflen(ls->buff) - 1); diff --git a/app/lua/llimits.h b/app/lua/llimits.h index fec09c2e8b..21db9d3d27 100644 --- a/app/lua/llimits.h +++ b/app/lua/llimits.h @@ -8,8 +8,6 @@ #define llimits_h -//#include "c_limits.h" - #include "lua.h" typedef LUAI_UINT32 lu_int32; diff --git a/app/lua/lmathlib.c b/app/lua/lmathlib.c index 2a10b6e9b1..26967652b9 100644 --- a/app/lua/lmathlib.c +++ b/app/lua/lmathlib.c @@ -10,8 +10,8 @@ #define LUAC_CROSS_FILE #include "lua.h" -#include C_HEADER_STDLIB -#include C_HEADER_MATH +#include +#include #include "lauxlib.h" #include "lualib.h" diff --git a/app/lua/lmem.h b/app/lua/lmem.h index 4766454ff1..4ef1199793 100644 --- a/app/lua/lmem.h +++ b/app/lua/lmem.h @@ -8,12 +8,6 @@ #define lmem_h -//#ifdef LUA_CROSS_COMPILER -//#include -//#else -//#include "c_stddef.h" -//#endif - #include "llimits.h" #include "lua.h" diff --git a/app/lua/loadlib.c b/app/lua/loadlib.c index b8cc691143..a4ab42c97a 100644 --- a/app/lua/loadlib.c +++ b/app/lua/loadlib.c @@ -14,9 +14,9 @@ #define LUAC_CROSS_FILE #include "lua.h" -#include C_HEADER_STDLIB -#include C_HEADER_STRING -#include C_HEADER_FCNTL +#include +#include +#include #ifndef LUA_CROSS_COMPILER #include "vfs.h" @@ -103,7 +103,7 @@ static void setprogdir (lua_State *L) { char *lb; DWORD nsize = sizeof(buff)/sizeof(char); DWORD n = GetModuleFileNameA(NULL, buff, nsize); - if (n == 0 || n == nsize || (lb = c_strrchr(buff, '\\')) == NULL) + if (n == 0 || n == nsize || (lb = strrchr(buff, '\\')) == NULL) luaL_error(L, "unable to get ModuleFileName"); else { *lb = '\0'; @@ -333,9 +333,9 @@ static int ll_loadlib (lua_State *L) { */ #ifdef LUA_CROSS_COMPILER static int readable (const char *filename) { - FILE *f = c_fopen(filename, "r"); /* try to open file */ + FILE *f = fopen(filename, "r"); /* try to open file */ if (f == NULL) return 0; /* open failed */ - c_fclose(f); + fclose(f); return 1; } #else @@ -351,8 +351,8 @@ static const char * pushnexttemplate (lua_State *L, const char *path) { const char *l; while (*path == *LUA_PATHSEP) path++; /* skip separators */ if (*path == '\0') return NULL; /* no more templates */ - l = c_strchr(path, *LUA_PATHSEP); /* find next separator */ - if (l == NULL) l = path + c_strlen(path); + l = strchr(path, *LUA_PATHSEP); /* find next separator */ + if (l == NULL) l = path + strlen(path); lua_pushlstring(L, path, l - path); /* template */ return l; } @@ -406,7 +406,7 @@ static int loader_Lua (lua_State *L) { static const char *mkfuncname (lua_State *L, const char *modname) { const char *funcname; - const char *mark = c_strchr(modname, *LUA_IGMARK); + const char *mark = strchr(modname, *LUA_IGMARK); if (mark) modname = mark + 1; funcname = luaL_gsub(L, modname, ".", LUA_OFSEP); funcname = lua_pushfstring(L, POF"%s", funcname); @@ -431,7 +431,7 @@ static int loader_Croot (lua_State *L) { const char *funcname; const char *filename; const char *name = luaL_checkstring(L, 1); - const char *p = c_strchr(name, '.'); + const char *p = strchr(name, '.'); int stat; if (p == NULL) return 0; /* is root */ lua_pushlstring(L, name, p - name); @@ -559,7 +559,7 @@ static void modinit (lua_State *L, const char *modname) { lua_setfield(L, -2, "_M"); /* module._M = module */ lua_pushstring(L, modname); lua_setfield(L, -2, "_NAME"); - dot = c_strrchr(modname, '.'); /* look for last dot in module name */ + dot = strrchr(modname, '.'); /* look for last dot in module name */ if (dot == NULL) dot = modname; else dot++; /* set _PACKAGE as package name (full module name minus last part) */ diff --git a/app/lua/lobject.c b/app/lua/lobject.c index 9f7339709c..214a3658a0 100644 --- a/app/lua/lobject.c +++ b/app/lua/lobject.c @@ -10,9 +10,9 @@ #define LUAC_CROSS_FILE #include "lua.h" -#include C_HEADER_STDIO -#include C_HEADER_STRING -#include C_HEADER_STDLIB +#include +#include +#include #include "ldo.h" #include "lmem.h" @@ -116,7 +116,7 @@ int luaO_str2d (const char *s, lua_Number *result) { *result = cast_num(lres); } #else - *result = cast_num(c_strtoul(s, &endptr, 16)); + *result = cast_num(strtoul(s, &endptr, 16)); #endif if (*endptr == '\0') return 1; /* most common case */ while (isspace(cast(unsigned char, *endptr))) endptr++; @@ -137,7 +137,7 @@ const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp) { int n = 1; pushstr(L, ""); for (;;) { - const char *e = c_strchr(fmt, '%'); + const char *e = strchr(fmt, '%'); if (e == NULL) break; setsvalue2s(L, L->top, luaS_newlstr(L, fmt, e-fmt)); incr_top(L); @@ -167,7 +167,7 @@ const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp) { } case 'p': { char buff[4*sizeof(void *) + 8]; /* should be enough space for a `%p' */ - c_sprintf(buff, "%p", va_arg(argp, void *)); + sprintf(buff, "%p", va_arg(argp, void *)); pushstr(L, buff); break; } @@ -206,7 +206,7 @@ const char *luaO_pushfstring (lua_State *L, const char *fmt, ...) { void luaO_chunkid (char *out, const char *source, size_t bufflen) { if (*source == '=') { - c_strncpy(out, source+1, bufflen); /* remove first char */ + strncpy(out, source+1, bufflen); /* remove first char */ out[bufflen-1] = '\0'; /* ensures null termination */ } else { /* out = "source", or "...source" */ @@ -214,26 +214,26 @@ void luaO_chunkid (char *out, const char *source, size_t bufflen) { size_t l; source++; /* skip the `@' */ bufflen -= sizeof(" '...' "); - l = c_strlen(source); - c_strcpy(out, ""); + l = strlen(source); + strcpy(out, ""); if (l > bufflen) { source += (l-bufflen); /* get last part of file name */ - c_strcat(out, "..."); + strcat(out, "..."); } - c_strcat(out, source); + strcat(out, source); } else { /* out = [string "string"] */ - size_t len = c_strcspn(source, "\n\r"); /* stop at first newline */ + size_t len = strcspn(source, "\n\r"); /* stop at first newline */ bufflen -= sizeof(" [string \"...\"] "); if (len > bufflen) len = bufflen; - c_strcpy(out, "[string \""); + strcpy(out, "[string \""); if (source[len] != '\0') { /* must truncate? */ - c_strncat(out, source, len); - c_strcat(out, "..."); + strncat(out, source, len); + strcat(out, "..."); } else - c_strcat(out, source); - c_strcat(out, "\"]"); + strcat(out, source); + strcat(out, "\"]"); } } } diff --git a/app/lua/lobject.h b/app/lua/lobject.h index e217383118..7741ddbf2d 100644 --- a/app/lua/lobject.h +++ b/app/lua/lobject.h @@ -8,11 +8,7 @@ #ifndef lobject_h #define lobject_h -#ifdef LUA_CROSS_COMPILER #include -#else -#include "c_stdarg.h" -#endif #include "llimits.h" #include "lua.h" diff --git a/app/lua/lparser.c b/app/lua/lparser.c index ae95535983..097d1a8441 100644 --- a/app/lua/lparser.c +++ b/app/lua/lparser.c @@ -10,7 +10,7 @@ #define LUAC_CROSS_FILE #include "lua.h" -#include C_HEADER_STRING +#include #include "lcode.h" #include "ldebug.h" diff --git a/app/lua/lrotable.c b/app/lua/lrotable.c index 5a73ef75fa..a2b809af0e 100644 --- a/app/lua/lrotable.c +++ b/app/lua/lrotable.c @@ -2,7 +2,7 @@ #define LUAC_CROSS_FILE #include "lua.h" -#include C_HEADER_STRING +#include #include "lrotable.h" #include "lauxlib.h" #include "lstring.h" @@ -100,7 +100,7 @@ const TValue* luaR_findentry(ROTable *rotable, TString *key, unsigned *ppos) { unsigned l = key ? key->tsv.len : sizeof("__metatable")-1; if (pentry) { - if (j >= 0 && !c_strcmp(pentry[j].key, strkey)) { + if (j >= 0 && !strcmp(pentry[j].key, strkey)) { if (ppos) *ppos = j; //dbg_printf("%3d hit %p %s\n", (hash>>2) & (LA_LINES-1), rotable, strkey); @@ -112,11 +112,11 @@ const TValue* luaR_findentry(ROTable *rotable, TString *key, unsigned *ppos) { * is included so a "on\0" has a mask of 0xFFFFFF and "a\0" has 0xFFFF. */ unsigned name4, mask4 = l > 2 ? (~0u) : (~0u)>>((3-l)*8); - c_memcpy(&name4, strkey, sizeof(name4)); + memcpy(&name4, strkey, sizeof(name4)); for(;pentry->key != NULL; i++, pentry++) { if (((*(unsigned *)pentry->key ^ name4) & mask4) == 0 && - !c_strcmp(pentry->key, strkey)) { + !strcmp(pentry->key, strkey)) { //dbg_printf("%p %s hit after %d probes \n", rotable, strkey, (int)(rotable-pentry)); if (ppos) *ppos = i; diff --git a/app/lua/lstring.c b/app/lua/lstring.c index be4591875d..5803b059dc 100644 --- a/app/lua/lstring.c +++ b/app/lua/lstring.c @@ -11,7 +11,7 @@ #define LUAC_CROSS_FILE #include "lua.h" -#include C_HEADER_STRING +#include #include "lmem.h" #include "lobject.h" @@ -67,7 +67,7 @@ static TString *newlstr (lua_State *L, const char *str, size_t l, ts->tsv.marked = luaC_white(G(L)); ts->tsv.tt = LUA_TSTRING; if (!readonly) { - c_memcpy(ts+1, str, l*sizeof(char)); + memcpy(ts+1, str, l*sizeof(char)); ((char *)(ts+1))[l] = '\0'; /* ending 0 */ } else { *(char **)(ts+1) = (char *)str; @@ -106,7 +106,7 @@ LUAI_FUNC TString *luaS_newlstr (lua_State *L, const char *str, size_t l) { o != NULL; o = o->gch.next) { TString *ts = rawgco2ts(o); - if (ts->tsv.len == l && (c_memcmp(str, getstr(ts), l) == 0)) { + if (ts->tsv.len == l && (memcmp(str, getstr(ts), l) == 0)) { /* string may be dead */ if (isdead(G(L), o)) changewhite(o); return ts; @@ -131,7 +131,7 @@ LUAI_FUNC TString *luaS_newlstr (lua_State *L, const char *str, size_t l) { /* New additions to the RAM strt are tagged as readonly if the string address * is in the CTEXT segment (target only, not luac.cross) */ int readonly = (lua_is_ptr_in_ro_area(str) && l+1 > sizeof(char**) && - l == c_strlen(str) ? LUAS_READONLY_STRING : LUAS_REGULAR_STRING); + l == strlen(str) ? LUAS_READONLY_STRING : LUAS_REGULAR_STRING); return newlstr(L, str, l, h, readonly); /* not found */ } diff --git a/app/lua/lstring.h b/app/lua/lstring.h index 227489c295..366f92b32e 100644 --- a/app/lua/lstring.h +++ b/app/lua/lstring.h @@ -17,7 +17,7 @@ #define sizeudata(u) (sizeof(union Udata)+(u)->len) -#define luaS_new(L, s) (luaS_newlstr(L, s, c_strlen(s))) +#define luaS_new(L, s) (luaS_newlstr(L, s, strlen(s))) #define luaS_newliteral(L, s) (luaS_newlstr(L, "" s, \ (sizeof(s)/sizeof(char))-1)) diff --git a/app/lua/lstrlib.c b/app/lua/lstrlib.c index 2bcd5e8461..72b503daf4 100644 --- a/app/lua/lstrlib.c +++ b/app/lua/lstrlib.c @@ -10,8 +10,8 @@ #define LUAC_CROSS_FILE #include "lua.h" -#include C_HEADER_STDIO -#include C_HEADER_STRING +#include +#include #include "lauxlib.h" #include "lualib.h" @@ -352,7 +352,7 @@ static const char *match_capture (MatchState *ms, const char *s, int l) { l = check_capture(ms, l); len = ms->capture[l].len; if ((size_t)(ms->src_end-s) >= len && - c_memcmp(ms->capture[l].init, s, len) == 0) + memcmp(ms->capture[l].init, s, len) == 0) return s+len; else return NULL; } @@ -447,7 +447,7 @@ static const char *lmemfind (const char *s1, size_t l1, l1 = l1-l2; /* `s2' cannot be found after that */ while (l1 > 0 && (init = (const char *)memchr(s1, *s2, l1)) != NULL) { init++; /* 1st char is already checked */ - if (c_memcmp(init, s2+1, l2) == 0) + if (memcmp(init, s2+1, l2) == 0) return init-1; else { /* correct `l1' and `s1' to try again */ l1 -= init-s1; @@ -496,7 +496,7 @@ static int str_find_aux (lua_State *L, int find) { if (init < 0) init = 0; else if ((size_t)(init) > l1) init = (ptrdiff_t)l1; if (find && (lua_toboolean(L, 4) || /* explicit request? */ - c_strpbrk(p, SPECIALS) == NULL)) { /* or no special characters? */ + strpbrk(p, SPECIALS) == NULL)) { /* or no special characters? */ /* do a plain search */ const char *s2 = lmemfind(s+init, l1-init, p, l2); if (s2) { @@ -723,7 +723,7 @@ static void addquoted (lua_State *L, luaL_Buffer *b, int arg) { static const char *scanformat (lua_State *L, const char *strfrmt, char *form) { const char *p = strfrmt; - while (*p != '\0' && c_strchr(FLAGS, *p) != NULL) p++; /* skip flags */ + while (*p != '\0' && strchr(FLAGS, *p) != NULL) p++; /* skip flags */ if ((size_t)(p - strfrmt) >= sizeof(FLAGS)) luaL_error(L, "invalid format (repeated flags)"); if (isdigit(uchar(*p))) p++; /* skip width */ @@ -736,7 +736,7 @@ static const char *scanformat (lua_State *L, const char *strfrmt, char *form) { if (isdigit(uchar(*p))) luaL_error(L, "invalid format (width or precision too long)"); *(form++) = '%'; - c_strncpy(form, strfrmt, p - strfrmt + 1); + strncpy(form, strfrmt, p - strfrmt + 1); form += p - strfrmt + 1; *form = '\0'; return p; @@ -744,9 +744,9 @@ static const char *scanformat (lua_State *L, const char *strfrmt, char *form) { static void addintlen (char *form) { - size_t l = c_strlen(form); + size_t l = strlen(form); char spec = form[l - 1]; - c_strcpy(form + l - 1, LUA_INTFRMLEN); + strcpy(form + l - 1, LUA_INTFRMLEN); form[l + sizeof(LUA_INTFRMLEN) - 2] = spec; form[l + sizeof(LUA_INTFRMLEN) - 1] = '\0'; } @@ -773,23 +773,23 @@ static int str_format (lua_State *L) { strfrmt = scanformat(L, strfrmt, form); switch (*strfrmt++) { case 'c': { - c_sprintf(buff, form, (int)luaL_checknumber(L, arg)); + sprintf(buff, form, (int)luaL_checknumber(L, arg)); break; } case 'd': case 'i': { addintlen(form); - c_sprintf(buff, form, (LUA_INTFRM_T)luaL_checknumber(L, arg)); + sprintf(buff, form, (LUA_INTFRM_T)luaL_checknumber(L, arg)); break; } case 'o': case 'u': case 'x': case 'X': { addintlen(form); - c_sprintf(buff, form, (unsigned LUA_INTFRM_T)luaL_checknumber(L, arg)); + sprintf(buff, form, (unsigned LUA_INTFRM_T)luaL_checknumber(L, arg)); break; } #if !defined LUA_NUMBER_INTEGRAL case 'e': case 'E': case 'f': case 'g': case 'G': { - c_sprintf(buff, form, (double)luaL_checknumber(L, arg)); + sprintf(buff, form, (double)luaL_checknumber(L, arg)); break; } #endif @@ -800,7 +800,7 @@ static int str_format (lua_State *L) { case 's': { size_t l; const char *s = luaL_checklstring(L, arg, &l); - if (!c_strchr(form, '.') && l >= 100) { + if (!strchr(form, '.') && l >= 100) { /* no precision and string is too long to be formatted; keep original string */ lua_pushvalue(L, arg); @@ -808,7 +808,7 @@ static int str_format (lua_State *L) { continue; /* skip the `addsize' at the end */ } else { - c_sprintf(buff, form, s); + sprintf(buff, form, s); break; } } @@ -817,7 +817,7 @@ static int str_format (lua_State *L) { LUA_QL("format"), *(strfrmt - 1)); } } - luaL_addlstring(&b, buff, c_strlen(buff)); + luaL_addlstring(&b, buff, strlen(buff)); } } luaL_pushresult(&b); diff --git a/app/lua/ltable.c b/app/lua/ltable.c index 8417fc14b5..93fb1db1e7 100644 --- a/app/lua/ltable.c +++ b/app/lua/ltable.c @@ -23,8 +23,8 @@ #define LUAC_CROSS_FILE #include "lua.h" -#include C_HEADER_MATH -#include C_HEADER_STRING +#include +#include #include "ldebug.h" #include "ldo.h" @@ -86,7 +86,7 @@ static Node *hashnum (const Table *t, lua_Number n) { int i; if (luai_numeq(n, 0)) /* avoid problems with -0 */ return gnode(t, 0); - c_memcpy(a, &n, sizeof(a)); + memcpy(a, &n, sizeof(a)); for (i = 1; i < numints; i++) a[0] += a[i]; return hashmod(t, a[0]); } diff --git a/app/lua/ltm.c b/app/lua/ltm.c index b1d9b66797..6f5962db40 100644 --- a/app/lua/ltm.c +++ b/app/lua/ltm.c @@ -10,7 +10,7 @@ #define LUAC_CROSS_FILE #include "lua.h" -#include C_HEADER_STRING +#include #include "lobject.h" #include "lstate.h" diff --git a/app/lua/lua.c b/app/lua/lua.c index cb226b51f9..81b04751c2 100644 --- a/app/lua/lua.c +++ b/app/lua/lua.c @@ -5,10 +5,9 @@ */ -// #include "c_signal.h" -#include "c_stdio.h" -#include "c_stdlib.h" -#include "c_string.h" +#include +#include +#include #include "user_interface.h" #include "user_version.h" #include "driver/readline.h" @@ -32,9 +31,9 @@ static const char *progname = LUA_PROGNAME; static void l_message (const char *pname, const char *msg) { #if defined(LUA_USE_STDIO) - if (pname) c_fprintf(c_stderr, "%s: ", pname); - c_fprintf(c_stderr, "%s\n", msg); - c_fflush(c_stderr); + if (pname) fprintf(c_stderr, "%s: ", pname); + fprintf(c_stderr, "%s\n", msg); + fflush(c_stderr); #else if (pname) luai_writestringerror("%s: ", pname); luai_writestringerror("%s\n", msg); @@ -122,7 +121,7 @@ static int dofsfile (lua_State *L, const char *name) { static int dostring (lua_State *L, const char *s, const char *name) { - int status = luaL_loadbuffer(L, s, c_strlen(s), name) || docall(L, 0, 1); + int status = luaL_loadbuffer(L, s, strlen(s), name) || docall(L, 0, 1); return report(L, status); } @@ -148,7 +147,7 @@ static int incomplete (lua_State *L, int status) { size_t lmsg; const char *msg = lua_tolstring(L, -1, &lmsg); const char *tp = msg + lmsg - (sizeof(LUA_QL("")) - 1); - if (c_strstr(msg, LUA_QL("")) == tp) { + if (strstr(msg, LUA_QL("")) == tp) { lua_pop(L, 1); return 1; } @@ -214,7 +213,7 @@ static int runargs (lua_State *L, char **argv, int n) { int memlimit=0; if (*limit == '\0') limit = argv[++i]; lua_assert(limit != NULL); - memlimit = c_atoi(limit); + memlimit = atoi(limit); lua_gc(L, LUA_GCSETMEMLIMIT, memlimit); break; } @@ -307,7 +306,7 @@ int lua_main (int argc, char **argv) { gLoad.L = L; gLoad.firstline = 1; gLoad.done = 0; - gLoad.line = c_malloc(LUA_MAXINPUT); + gLoad.line = malloc(LUA_MAXINPUT); gLoad.len = LUA_MAXINPUT; gLoad.line_position = 0; gLoad.prmt = get_prompt(L, 1); @@ -324,7 +323,7 @@ int lua_main (int argc, char **argv) { int lua_put_line(const char *s, size_t l) { if (s == NULL || ++l > LUA_MAXINPUT || gLoad.line_position > 0) return 0; - c_memcpy(gLoad.line, s, l); + memcpy(gLoad.line, s, l); gLoad.line[l] = '\0'; gLoad.line_position = l; gLoad.done = 1; @@ -336,7 +335,7 @@ void lua_handle_input (bool force) { while (gLoad.L && (force || readline (&gLoad))) { NODE_DBG("Handle Input: first=%u, pos=%u, len=%u, actual=%u, line=%s\n", gLoad.firstline, - gLoad.line_position, gLoad.len, c_strlen(gLoad.line), gLoad.line); + gLoad.line_position, gLoad.len, strlen(gLoad.line), gLoad.line); dojob (&gLoad); force = false; } @@ -357,7 +356,7 @@ static void dojob(lua_Load *load){ do{ if(load->done == 1){ - l = c_strlen(b); + l = strlen(b); if (l > 0 && b[l-1] == '\n') /* line ends with newline? */ b[l-1] = '\0'; /* remove it */ if (load->firstline && b[0] == '=') /* first line starts with `=' ? */ @@ -401,8 +400,8 @@ static void dojob(lua_Load *load){ load->done = 0; load->line_position = 0; - c_memset(load->line, 0, load->len); - c_puts(load->prmt); + memset(load->line, 0, load->len); + puts(load->prmt); } #ifndef uart_putc @@ -468,7 +467,7 @@ static bool readline(lua_Load *load){ if (load->line_position == 0) { /* Get a empty line, then go to get a new line */ - c_puts(load->prmt); + puts(load->prmt); continue; } else { load->done = 1; diff --git a/app/lua/lua.h b/app/lua/lua.h index b6f6c413b1..a4b5c4e219 100644 --- a/app/lua/lua.h +++ b/app/lua/lua.h @@ -11,16 +11,10 @@ #ifdef LUAC_CROSS_FILE #include "luac_cross.h" #endif -#ifdef LUA_CROSS_COMPILER -#include -#include -#include -#else -#include "c_stdarg.h" -#include "c_stddef.h" -#include "c_types.h" -#include -#endif +#include +#include "stdarg.h" +#include "stddef.h" +#include "ctype.h" #include "luaconf.h" diff --git a/app/lua/luac_cross/Makefile b/app/lua/luac_cross/Makefile index da133ec5a7..984d2b6594 100644 --- a/app/lua/luac_cross/Makefile +++ b/app/lua/luac_cross/Makefile @@ -8,7 +8,7 @@ summary ?= @true -CCFLAGS:= -I.. -I../../include -I../../libc -I../../uzlib +CCFLAGS:= -I.. -I../../include -I../../uzlib LDFLAGS:= -L$(SDK_DIR)/lib -L$(SDK_DIR)/ld -lm -ldl -Wl,-Map=mapfile CCFLAGS += -Wall @@ -33,13 +33,12 @@ LUASRC := lapi.c lauxlib.c lbaselib.c lcode.c ldblib.c ldebug.c lmathlib.c lmem.c loadlib.c lobject.c lopcodes.c lparser.c \ lrotable.c lstate.c lstring.c lstrlib.c ltable.c ltablib.c \ ltm.c lundump.c lvm.c lzio.c -LIBCSRC := c_stdlib.c UZSRC := uzlib_deflate.c crc32.c # # This relies on the files being unique on the vpath # -SRC := $(LUACSRC) $(LUASRC) $(LIBCSRC) $(UZSRC) +SRC := $(LUACSRC) $(LUASRC) $(UZSRC) vpath %.c .:..:../../libc:../../uzlib ODIR := .output/$(TARGET)/$(FLAVOR)/obj diff --git a/app/lua/luac_cross/mingw32-Makefile.mak b/app/lua/luac_cross/mingw32-Makefile.mak index b3b6b7f6f5..ebfa4a5b5e 100644 --- a/app/lua/luac_cross/mingw32-Makefile.mak +++ b/app/lua/luac_cross/mingw32-Makefile.mak @@ -38,12 +38,11 @@ LUASRC := lapi.c lauxlib.c lbaselib.c lcode.c ldblib.c ldebug.c lmathlib.c lmem.c loadlib.c lobject.c lopcodes.c lparser.c \ lrotable.c lstate.c lstring.c lstrlib.c ltable.c ltablib.c \ ltm.c lundump.c lvm.c lzio.c -LIBCSRC := c_stdlib.c UZSRC := uzlib_deflate.c crc32.c # # This relies on the files being unique on the vpath # -SRC := $(LUACSRC) $(LUASRC) $(LIBCSRC) $(UZSRC) +SRC := $(LUACSRC) $(LUASRC) $(UZSRC) vpath %.c .:..:../../libc:../../uzlib diff --git a/app/lua/luaconf.h b/app/lua/luaconf.h index ddea8a76c2..3170b0dded 100644 --- a/app/lua/luaconf.h +++ b/app/lua/luaconf.h @@ -8,13 +8,9 @@ #ifndef lconfig_h #define lconfig_h -#ifdef LUA_CROSS_COMPILER #include #include -#else -#include "c_limits.h" -#include "c_stddef.h" -#endif +#include #include "user_config.h" /* @@ -262,11 +258,7 @@ #define lua_stdin_is_tty() isatty(0) #elif defined(LUA_WIN) #include -#ifdef LUA_CROSS_COMPILER #include -#else -#include "c_stdio.h" -#endif #define lua_stdin_is_tty() _isatty(_fileno(stdin)) #else @@ -317,11 +309,11 @@ #define lua_saveline(L,idx) \ if (lua_strlen(L,idx) > 0) /* non-empty line? */ \ add_history(lua_tostring(L, idx)); /* add it to history */ -#define lua_freeline(L,b) ((void)L, c_free(b)) +#define lua_freeline(L,b) ((void)L, free(b)) #else // #if defined(LUA_CROSS_COMPILER) && defined(LUA_USE_READLINE) #define lua_readline(L,b,p) \ - ((void)L, c_fputs(p, c_stdout), c_fflush(c_stdout), /* show prompt */ \ - c_fgets(b, LUA_MAXINPUT, c_stdin) != NULL) /* get line */ + ((void)L, fputs(p, c_stdout), fflush(c_stdout), /* show prompt */ \ + fgets(b, LUA_MAXINPUT, c_stdin) != NULL) /* get line */ #define lua_saveline(L,idx) { (void)L; (void)idx; } #define lua_freeline(L,b) { (void)L; (void)b; } #endif // #if defined(LUA_USE_READLINE) @@ -342,8 +334,8 @@ extern int readline4lua(const char *prompt, char *buffer, int length); ** avoids including 'stdio.h' everywhere.) */ #if !defined(LUA_USE_STDIO) -#define luai_writestring(s, l) c_puts(s) -#define luai_writeline() c_puts("\n") +#define luai_writestring(s, l) puts(s) +#define luai_writeline() puts("\n") #endif // defined(LUA_USE_STDIO) /* @@ -622,31 +614,23 @@ extern int readline4lua(const char *prompt, char *buffer, int length); #define LUA_NUMBER_SCAN "%lf" #define LUA_NUMBER_FMT "%.14g" #endif // #if defined LUA_NUMBER_INTEGRAL -#define lua_number2str(s,n) c_sprintf((s), LUA_NUMBER_FMT, (n)) +#define lua_number2str(s,n) sprintf((s), LUA_NUMBER_FMT, (n)) #define LUAI_MAXNUMBER2STR 32 /* 16 digits, sign, point, and \0 */ #if defined LUA_NUMBER_INTEGRAL #if !defined LUA_INTEGRAL_LONGLONG - #define lua_str2number(s,p) c_strtol((s), (p), 10) + #define lua_str2number(s,p) strtol((s), (p), 10) #else - #define lua_str2number(s,p) c_strtoll((s), (p), 10) + #define lua_str2number(s,p) strtoll((s), (p), 10) #endif // #if !defined LUA_INTEGRAL_LONGLONG #else -#ifdef _MSC_VER //what's wrong with stdlib strtod? #define lua_str2number(s,p) strtod((s), (p)) -#else -#define lua_str2number(s,p) c_strtod((s), (p)) -#endif #endif // #if defined LUA_NUMBER_INTEGRAL /* @@ The luai_num* macros define the primitive operations over numbers. */ #if defined(LUA_CORE) || defined(LUA_LIB) -#ifdef LUA_CROSS_COMPILER #include -#else -#include "c_math.h" -#endif #define luai_numadd(a,b) ((a)+(b)) #define luai_numsub(a,b) ((a)-(b)) #define luai_nummul(a,b) ((a)*(b)) @@ -801,7 +785,7 @@ union luai_Cast { double l_d; long l_l; }; #include #define LUA_TMPNAMBUFSIZE 32 #define lua_tmpnam(b,e) { \ - c_strcpy(b, "/tmp/lua_XXXXXX"); \ + strcpy(b, "/tmp/lua_XXXXXX"); \ e = mkstemp(b); \ if (e != -1) close(e); \ e = (e == -1); } @@ -821,7 +805,7 @@ union luai_Cast { double l_d; long l_l; }; */ #if defined(LUA_USE_POPEN) -#define lua_popen(L,c,m) ((void)L, c_fflush(NULL), popen(c,m)) +#define lua_popen(L,c,m) ((void)L, fflush(NULL), popen(c,m)) #define lua_pclose(L,file) ((void)L, (pclose(file) != -1)) #elif defined(LUA_WIN) diff --git a/app/lua/lundump.c b/app/lua/lundump.c index 0baedf2939..4ccb467719 100644 --- a/app/lua/lundump.c +++ b/app/lua/lundump.c @@ -9,7 +9,7 @@ #define LUAC_CROSS_FILE #include "lua.h" -#include C_HEADER_STRING +#include #include "ldebug.h" #include "ldo.h" @@ -309,7 +309,7 @@ static void LoadHeader(LoadState* S) S->numsize=h[10]=s[10]; /* length of lua_Number */ S->toflt=(s[11]>intck); /* check if conversion from int lua_Number to flt is needed */ if(S->toflt) s[11]=h[11]; - IF (c_memcmp(h,s,LUAC_HEADERSIZE)!=0, "bad header"); + IF (memcmp(h,s,LUAC_HEADERSIZE)!=0, "bad header"); } /* @@ -338,7 +338,7 @@ Proto* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff, const char* name) void luaU_header (char* h) { int x=1; - c_memcpy(h,LUA_SIGNATURE,sizeof(LUA_SIGNATURE)-1); + memcpy(h,LUA_SIGNATURE,sizeof(LUA_SIGNATURE)-1); h+=sizeof(LUA_SIGNATURE)-1; *h++=(char)LUAC_VERSION; *h++=(char)LUAC_FORMAT; diff --git a/app/lua/lundump.h b/app/lua/lundump.h index 219b980d39..eaa58597d0 100644 --- a/app/lua/lundump.h +++ b/app/lua/lundump.h @@ -7,11 +7,7 @@ #ifndef lundump_h #define lundump_h -#ifdef LUA_CROSS_COMPILER #include -#else -#include "c_stdint.h" -#endif #include "lobject.h" #include "lzio.h" diff --git a/app/lua/lvm.c b/app/lua/lvm.c index a0243d6cd9..11cc6ce1da 100644 --- a/app/lua/lvm.c +++ b/app/lua/lvm.c @@ -10,9 +10,9 @@ #define LUAC_CROSS_FILE #include "lua.h" -#include C_HEADER_STDIO -#include C_HEADER_STRING -#include C_HEADER_MATH +#include +#include +#include #include "ldebug.h" #include "ldo.h" @@ -252,10 +252,10 @@ static int l_strcmp (const TString *ls, const TString *rs) { const char *r = getstr(rs); size_t lr = rs->tsv.len; for (;;) { - int temp = c_strcoll(l, r); + int temp = strcoll(l, r); if (temp != 0) return temp; else { /* strings are equal up to a `\0' */ - size_t len = c_strlen(l); /* index of first `\0' in both strings */ + size_t len = strlen(l); /* index of first `\0' in both strings */ if (len == lr) /* r is finished? */ return (len == ll) ? 0 : 1; else if (len == ll) /* l is finished? */ @@ -363,7 +363,7 @@ void luaV_concat (lua_State *L, int total, int last) { tl = 0; for (i=n; i>0; i--) { /* concat all strings */ size_t l = tsvalue(top-i)->len; - c_memcpy(buffer+tl, svalue(top-i), l); + memcpy(buffer+tl, svalue(top-i), l); tl += l; } setsvalue2s(L, top-n, luaS_newlstr(L, buffer, tl)); diff --git a/app/lua/lzio.c b/app/lua/lzio.c index 84d811c306..16108489ee 100644 --- a/app/lua/lzio.c +++ b/app/lua/lzio.c @@ -10,7 +10,7 @@ #define LUAC_CROSS_FILE #include "lua.h" -#include C_HEADER_STRING +#include #include "llimits.h" #include "lmem.h" @@ -62,7 +62,7 @@ size_t luaZ_read (ZIO *z, void *b, size_t n) { return n; /* return number of missing bytes */ m = (n <= z->n) ? n : z->n; /* min. between n and z->n */ if (b) - c_memcpy(b, z->p, m); + memcpy(b, z->p, m); z->n -= m; z->i += m; z->p += m; diff --git a/app/mbedtls/library/platform.c b/app/mbedtls/library/platform.c index dd3dde99b8..aa88fc1a66 100644 --- a/app/mbedtls/library/platform.c +++ b/app/mbedtls/library/platform.c @@ -25,15 +25,6 @@ #include MBEDTLS_CONFIG_FILE #endif -// XXX Espressif are hacks sometimes. This is BS, but is taken from -// the mbedtls platform.c from their SDK. Really, this should go -// somewhere else. Note that the prototype here for vPortFree differs (!) -// from the one in sdk-overrides.h. That's above my pay grade. -// --nwf; 2018 Feb 18 -extern void *pvPortCalloc(unsigned int count, unsigned int size); -extern void vPortFree( void *pv ); - - #if defined(MBEDTLS_PLATFORM_C) #include "mbedtls/platform.h" diff --git a/app/mbedtls/platform/mbedtls_mem.c b/app/mbedtls/platform/mbedtls_mem.c new file mode 100644 index 0000000000..9281362f05 --- /dev/null +++ b/app/mbedtls/platform/mbedtls_mem.c @@ -0,0 +1,4 @@ +#include + +void *mbedtls_calloc(size_t n, size_t sz) { return calloc(n, sz); } +void mbedtls_free(void *p) { free(p); } diff --git a/app/mbedtls/platform/memcompat.c b/app/mbedtls/platform/memcompat.c new file mode 100644 index 0000000000..ff765d7ce0 --- /dev/null +++ b/app/mbedtls/platform/memcompat.c @@ -0,0 +1,3 @@ +#include +void *mbedtls_calloc_wrap(size_t n, size_t sz) { return calloc(n, sz); } +void mbedtls_free_wrap(void *p) { free(p); } diff --git a/app/modules/ads1115.c b/app/modules/ads1115.c index 72181ba44e..950f1a1df9 100644 --- a/app/modules/ads1115.c +++ b/app/modules/ads1115.c @@ -8,7 +8,7 @@ #include "lauxlib.h" #include "platform.h" #include "osapi.h" -#include "c_stdlib.h" +#include //*************************************************************************** diff --git a/app/modules/adxl345.c b/app/modules/adxl345.c index 2628bdc9f7..f18a112227 100644 --- a/app/modules/adxl345.c +++ b/app/modules/adxl345.c @@ -6,8 +6,8 @@ #include "module.h" #include "lauxlib.h" #include "platform.h" -#include "c_stdlib.h" -#include "c_string.h" +#include +#include static const uint32_t adxl345_i2c_id = 0; static const uint8_t adxl345_i2c_addr = 0x53; diff --git a/app/modules/apa102.c b/app/modules/apa102.c index b4db436853..8179662b1a 100644 --- a/app/modules/apa102.c +++ b/app/modules/apa102.c @@ -1,5 +1,5 @@ -#include "c_stdlib.h" -#include "c_string.h" +#include +#include #include "lualib.h" #include "lauxlib.h" #include "lrotable.h" diff --git a/app/modules/bit.c b/app/modules/bit.c index 0c2b2e3b56..70cbfef06e 100644 --- a/app/modules/bit.c +++ b/app/modules/bit.c @@ -6,7 +6,7 @@ #include "module.h" -#include "c_limits.h" +#include #include "lauxlib.h" diff --git a/app/modules/bloom.c b/app/modules/bloom.c index 514c347ecd..922e3ed25a 100644 --- a/app/modules/bloom.c +++ b/app/modules/bloom.c @@ -6,6 +6,7 @@ #include "module.h" #include "lauxlib.h" +#include #include "c_types.h" #include "../crypto/sha2.h" diff --git a/app/modules/bme280.c b/app/modules/bme280.c index b642e8b928..e8525921c8 100644 --- a/app/modules/bme280.c +++ b/app/modules/bme280.c @@ -11,7 +11,7 @@ #include "module.h" #include "lauxlib.h" #include "platform.h" -#include "c_math.h" +#include /****************************************************/ /**\name registers definition */ diff --git a/app/modules/bme680.c b/app/modules/bme680.c index dfc1c0e9f6..85efbe2068 100644 --- a/app/modules/bme680.c +++ b/app/modules/bme680.c @@ -9,7 +9,7 @@ #include "module.h" #include "lauxlib.h" #include "platform.h" -#include "c_math.h" +#include #include "bme680_defs.h" diff --git a/app/modules/bmp085.c b/app/modules/bmp085.c index 4ccc9e855f..97eeadfb43 100644 --- a/app/modules/bmp085.c +++ b/app/modules/bmp085.c @@ -1,8 +1,8 @@ #include "module.h" #include "lauxlib.h" #include "platform.h" -#include "c_stdlib.h" -#include "c_string.h" +#include +#include static const uint32_t bmp085_i2c_id = 0; static const uint8_t bmp085_i2c_addr = 0x77; diff --git a/app/modules/coap.c b/app/modules/coap.c index 2b18b6b24d..f810154e17 100644 --- a/app/modules/coap.c +++ b/app/modules/coap.c @@ -4,8 +4,8 @@ #include "lauxlib.h" #include "platform.h" -#include "c_string.h" -#include "c_stdlib.h" +#include +#include #include "c_types.h" #include "mem.h" @@ -36,13 +36,13 @@ static void coap_received(void *arg, char *pdata, unsigned short len) // static uint8_t buf[MAX_MESSAGE_SIZE+1] = {0}; // +1 for string '\0' uint8_t buf[MAX_MESSAGE_SIZE+1] = {0}; // +1 for string '\0' - c_memset(buf, 0, sizeof(buf)); // wipe prev data + memset(buf, 0, sizeof(buf)); // wipe prev data if (len > MAX_MESSAGE_SIZE) { NODE_DBG("Request Entity Too Large.\n"); // NOTE: should response 4.13 to client... return; } - // c_memcpy(buf, pdata, len); + // memcpy(buf, pdata, len); size_t rsplen = coap_server_respond(pdata, len, buf, MAX_MESSAGE_SIZE+1); @@ -52,11 +52,11 @@ static void coap_received(void *arg, char *pdata, unsigned short len) return; pesp_conn->proto.udp->remote_port = pr->remote_port; os_memmove (pesp_conn->proto.udp->remote_ip, pr->remote_ip, 4); - // The remot_info apparently should *not* be os_free()d, fyi + // The remot_info apparently should *not* be free()d, fyi espconn_sent(pesp_conn, (unsigned char *)buf, rsplen); - // c_memset(buf, 0, sizeof(buf)); + // memset(buf, 0, sizeof(buf)); } static void coap_sent(void *arg) @@ -83,7 +83,7 @@ static int coap_create( lua_State* L, const char* mt ) lua_setmetatable(L, -2); // create the espconn struct - pesp_conn = (struct espconn *)c_zalloc(sizeof(struct espconn)); + pesp_conn = (struct espconn *)calloc(1,sizeof(struct espconn)); if(!pesp_conn) return luaL_error(L, "not enough memory"); @@ -93,9 +93,9 @@ static int coap_create( lua_State* L, const char* mt ) pesp_conn->proto.tcp = NULL; pesp_conn->proto.udp = NULL; - pesp_conn->proto.udp = (esp_udp *)c_zalloc(sizeof(esp_udp)); + pesp_conn->proto.udp = (esp_udp *)calloc(1,sizeof(esp_udp)); if(!pesp_conn->proto.udp){ - c_free(pesp_conn); + free(pesp_conn); cud->pesp_conn = pesp_conn = NULL; return luaL_error(L, "not enough memory"); } @@ -131,9 +131,9 @@ static int coap_delete( lua_State* L, const char* mt ) { if(cud->pesp_conn->proto.udp->remote_port || cud->pesp_conn->proto.udp->local_port) espconn_delete(cud->pesp_conn); - c_free(cud->pesp_conn->proto.udp); + free(cud->pesp_conn->proto.udp); cud->pesp_conn->proto.udp = NULL; - c_free(cud->pesp_conn); + free(cud->pesp_conn); cud->pesp_conn = NULL; } @@ -170,7 +170,7 @@ static int coap_start( lua_State* L, const char* mt ) ip = "0.0.0.0"; } ipaddr.addr = ipaddr_addr(ip); - c_memcpy(pesp_conn->proto.udp->local_ip, &ipaddr.addr, 4); + memcpy(pesp_conn->proto.udp->local_ip, &ipaddr.addr, 4); NODE_DBG("UDP ip is set: "); NODE_DBG(IPSTR, IP2STR(&ipaddr.addr)); NODE_DBG("\n"); @@ -235,7 +235,7 @@ static void coap_response_handler(void *arg, char *pdata, unsigned short len) pkt.content.len = 0; // static uint8_t buf[MAX_MESSAGE_SIZE+1] = {0}; // +1 for string '\0' uint8_t buf[MAX_MESSAGE_SIZE+1] = {0}; // +1 for string '\0' - c_memset(buf, 0, sizeof(buf)); // wipe prev data + memset(buf, 0, sizeof(buf)); // wipe prev data int rc; if( len > MAX_MESSAGE_SIZE ) @@ -243,7 +243,7 @@ static void coap_response_handler(void *arg, char *pdata, unsigned short len) NODE_DBG("Request Entity Too Large.\n"); // NOTE: should response 4.13 to client... return; } - c_memcpy(buf, pdata, len); + memcpy(buf, pdata, len); if (0 != (rc = coap_parse(&pkt, buf, len))){ NODE_DBG("Bad packet rc=%d\n", rc); @@ -271,7 +271,7 @@ static void coap_response_handler(void *arg, char *pdata, unsigned short len) uint32_t ip = 0, port = 0; coap_tid_t id = COAP_INVALID_TID; - c_memcpy(&ip, pesp_conn->proto.udp->remote_ip, sizeof(ip)); + memcpy(&ip, pesp_conn->proto.udp->remote_ip, sizeof(ip)); port = pesp_conn->proto.udp->remote_port; coap_transaction_id(ip, port, &pkt, &id); @@ -303,7 +303,7 @@ static void coap_response_handler(void *arg, char *pdata, unsigned short len) if(pesp_conn->proto.udp->remote_port || pesp_conn->proto.udp->local_port) espconn_delete(pesp_conn); } - // c_memset(buf, 0, sizeof(buf)); + // memset(buf, 0, sizeof(buf)); } // Lua: client:request( [CON], uri, [payload] ) @@ -354,7 +354,7 @@ static int coap_request( lua_State* L, coap_method_t m ) pesp_conn->proto.udp->local_port = espconn_port(); if(uri->host.length){ - c_memcpy(host, uri->host.s, uri->host.length); + memcpy(host, uri->host.s, uri->host.length); host[uri->host.length] = '\0'; ipaddr.addr = ipaddr_addr(host); @@ -362,7 +362,7 @@ static int coap_request( lua_State* L, coap_method_t m ) NODE_DBG(host); NODE_DBG("\n"); - c_memcpy(pesp_conn->proto.udp->remote_ip, &ipaddr.addr, 4); + memcpy(pesp_conn->proto.udp->remote_ip, &ipaddr.addr, 4); NODE_DBG("UDP ip is set: "); NODE_DBG(IPSTR, IP2STR(&ipaddr.addr)); NODE_DBG("\n"); @@ -371,7 +371,7 @@ static int coap_request( lua_State* L, coap_method_t m ) coap_pdu_t *pdu = coap_new_pdu(); // should call coap_delete_pdu() somewhere if(!pdu){ if(uri) - c_free(uri); + free(uri); return luaL_error (L, "alloc fail"); } @@ -422,7 +422,7 @@ static int coap_request( lua_State* L, coap_method_t m ) } if(uri) - c_free((void *)uri); + free((void *)uri); NODE_DBG("coap_request is called.\n"); return 0; @@ -447,13 +447,13 @@ static int coap_regist( lua_State* L, const char* mt, int isvar ) h = function_entry; while(NULL!=h->next){ // goto the end of the list - if(h->name!= NULL && c_strcmp(h->name, name)==0) // key exist, override it + if(h->name!= NULL && strcmp(h->name, name)==0) // key exist, override it break; h = h->next; } - if(h->name==NULL || c_strcmp(h->name, name)!=0){ // not exists. make a new one. - h->next = (coap_luser_entry *)c_zalloc(sizeof(coap_luser_entry)); + if(h->name==NULL || strcmp(h->name, name)!=0){ // not exists. make a new one. + h->next = (coap_luser_entry *)calloc(1,sizeof(coap_luser_entry)); h = h->next; if(h == NULL) return luaL_error(L, "not enough memory"); diff --git a/app/modules/color_utils.c b/app/modules/color_utils.c index 6c37cd8cdb..78a5a58fba 100644 --- a/app/modules/color_utils.c +++ b/app/modules/color_utils.c @@ -2,9 +2,9 @@ #include "lauxlib.h" #include "lmem.h" #include "platform.h" -#include "c_stdlib.h" -#include "c_math.h" -#include "c_string.h" +#include +#include +#include #include "user_interface.h" #include "osapi.h" diff --git a/app/modules/color_utils.h b/app/modules/color_utils.h index c937cd7fdd..42a911b1f8 100644 --- a/app/modules/color_utils.h +++ b/app/modules/color_utils.h @@ -5,9 +5,9 @@ #include "lauxlib.h" #include "lmem.h" #include "platform.h" -#include "c_stdlib.h" -#include "c_math.h" -#include "c_string.h" +#include +#include +#include #include "user_interface.h" #include "osapi.h" diff --git a/app/modules/cron.c b/app/modules/cron.c index 60175d2f30..5196c00358 100644 --- a/app/modules/cron.c +++ b/app/modules/cron.c @@ -5,7 +5,7 @@ #include "lmem.h" #include "user_interface.h" #include "c_types.h" -#include "c_string.h" +#include #include "ets_sys.h" #include "time.h" #include "rtc/rtctime.h" @@ -176,7 +176,7 @@ static int lcron_reset(lua_State *L) { luaL_unref(L, LUA_REGISTRYINDEX, cronent_list[i]); } cronent_count = 0; - os_free(cronent_list); + free(cronent_list); cronent_list = 0; return 0; } diff --git a/app/modules/crypto.c b/app/modules/crypto.c index e648c82ed6..f55b7f2ebc 100644 --- a/app/modules/crypto.c +++ b/app/modules/crypto.c @@ -1,11 +1,11 @@ // Module for cryptography -#include +#include #include "module.h" #include "lauxlib.h" #include "platform.h" #include "c_types.h" -#include "c_stdlib.h" +#include #include "vfs.h" #include "../crypto/digests.h" #include "../crypto/mech.h" diff --git a/app/modules/encoder.c b/app/modules/encoder.c index b3c1798575..53c08b740a 100644 --- a/app/modules/encoder.c +++ b/app/modules/encoder.c @@ -3,7 +3,7 @@ #include "module.h" #include "lauxlib.h" #include "lmem.h" -#include "c_string.h" +#include #define BASE64_INVALID '\xff' #define BASE64_PADDING '=' #define ISBASE64(c) (unbytes64[c] != BASE64_INVALID) @@ -19,7 +19,7 @@ static uint8 *toBase64 ( lua_State* L, const uint8 *msg, size_t *len){ int buf_size = (n + 2) / 3 * 4; // estimated encoded size uint8 * q, *out = (uint8 *)luaM_malloc(L, buf_size); uint8 bytes64[sizeof(b64)]; - c_memcpy(bytes64, b64, sizeof(b64)); //Avoid lots of flash unaligned fetches + memcpy(bytes64, b64, sizeof(b64)); //Avoid lots of flash unaligned fetches for (i = 0, q = out; i < n; i += 3) { int a = msg[i]; @@ -46,7 +46,7 @@ static uint8 *fromBase64 ( lua_State* L, const uint8 *enc_msg, size_t *len){ if (n & 3) luaL_error (L, "Invalid base64 string"); - c_memset(unbytes64, BASE64_INVALID, sizeof(unbytes64)); + memset(unbytes64, BASE64_INVALID, sizeof(unbytes64)); for (i = 0; i < sizeof(b64)-1; i++) unbytes64[b64[i]] = i; // sequential so no exceptions if (enc_msg[n-1] == BASE64_PADDING) { diff --git a/app/modules/enduser_setup.c b/app/modules/enduser_setup.c index addef5f436..caf676d43d 100644 --- a/app/modules/enduser_setup.c +++ b/app/modules/enduser_setup.c @@ -38,9 +38,9 @@ #include "lauxlib.h" #include "lmem.h" #include "platform.h" -#include "c_stdlib.h" -#include "c_stdio.h" -#include "c_string.h" +#include +#include +#include #include "ctype.h" #include "user_interface.h" #include "espconn.h" @@ -248,7 +248,7 @@ static void enduser_setup_check_station(void *p) (void)p; struct ip_info ip; - c_memset(&ip, 0, sizeof(struct ip_info)); + memset(&ip, 0, sizeof(struct ip_info)); wifi_get_ip_info(STATION_IF, &ip); @@ -266,7 +266,7 @@ static void enduser_setup_check_station(void *p) /* No IP Address yet, so check the reported status */ uint8_t curr_status = wifi_station_get_connect_status(); char buf[20]; - c_sprintf(buf, "status=%d,chan=%d", curr_status, currChan); + sprintf(buf, "status=%d,chan=%d", curr_status, currChan); ENDUSER_SETUP_DEBUG(buf); if (curr_status == 2 || curr_status == 3 || curr_status == 4) @@ -290,7 +290,7 @@ static void enduser_setup_check_station(void *p) return; } - c_sprintf (ipaddr, "%d.%d.%d.%d", IP2STR(&ip.ip.addr)); + sprintf (ipaddr, "%d.%d.%d.%d", IP2STR(&ip.ip.addr)); state->success = 1; state->lastStationStatus = 5; /* We have an IP Address, so the status is 5 (as of SDK 1.5.1) */ @@ -298,7 +298,7 @@ static void enduser_setup_check_station(void *p) #if ENDUSER_SETUP_DEBUG_ENABLE char debuginfo[100]; - c_sprintf(debuginfo, "AP_CHAN: %d, STA_CHAN: %d", state->softAPchannel, currChan); + sprintf(debuginfo, "AP_CHAN: %d, STA_CHAN: %d", state->softAPchannel, currChan); ENDUSER_SETUP_DEBUG(debuginfo); #endif @@ -462,27 +462,27 @@ static int enduser_setup_http_load_payload(void) char cl_hdr[30]; size_t ce_len = 0; - c_sprintf(cl_hdr, http_header_content_len_fmt, file_len); - size_t cl_len = c_strlen(cl_hdr); + sprintf(cl_hdr, http_header_content_len_fmt, file_len); + size_t cl_len = strlen(cl_hdr); if (!f || err == VFS_RES_ERR || err2 == VFS_RES_ERR) { ENDUSER_SETUP_DEBUG("Unable to load file enduser_setup.html, loading default HTML..."); - c_sprintf(cl_hdr, http_header_content_len_fmt, sizeof(enduser_setup_html_default)); - cl_len = c_strlen(cl_hdr); + sprintf(cl_hdr, http_header_content_len_fmt, sizeof(enduser_setup_html_default)); + cl_len = strlen(cl_hdr); int html_len = LITLEN(enduser_setup_html_default); if (enduser_setup_html_default[0] == 0x1f && enduser_setup_html_default[1] == 0x8b) { - ce_len = c_strlen(http_html_gzip_contentencoding); + ce_len = strlen(http_html_gzip_contentencoding); html_len = enduser_setup_html_default_len; /* Defined in enduser_setup/enduser_setup.html.gz.def.h by xxd -i */ ENDUSER_SETUP_DEBUG("Content is gzipped"); } int payload_len = LITLEN(http_header_200) + cl_len + ce_len + html_len; state->http_payload_len = payload_len; - state->http_payload_data = (char *) c_malloc(payload_len); + state->http_payload_data = (char *) malloc(payload_len); if (state->http_payload_data == NULL) { @@ -490,17 +490,17 @@ static int enduser_setup_http_load_payload(void) } int offset = 0; - c_memcpy(&(state->http_payload_data[offset]), &(http_header_200), LITLEN(http_header_200)); + memcpy(&(state->http_payload_data[offset]), &(http_header_200), LITLEN(http_header_200)); offset += LITLEN(http_header_200); if (ce_len > 0) { - offset += c_sprintf(state->http_payload_data + offset, http_html_gzip_contentencoding, ce_len); + offset += sprintf(state->http_payload_data + offset, http_html_gzip_contentencoding, ce_len); } - c_memcpy(&(state->http_payload_data[offset]), &(cl_hdr), cl_len); + memcpy(&(state->http_payload_data[offset]), &(cl_hdr), cl_len); offset += cl_len; - c_memcpy(&(state->http_payload_data[offset]), &(enduser_setup_html_default), sizeof(enduser_setup_html_default)); + memcpy(&(state->http_payload_data[offset]), &(enduser_setup_html_default), sizeof(enduser_setup_html_default)); return 1; } @@ -510,13 +510,13 @@ static int enduser_setup_http_load_payload(void) if (magic[0] == 0x1f && magic[1] == 0x8b) { - ce_len = c_strlen(http_html_gzip_contentencoding); + ce_len = strlen(http_html_gzip_contentencoding); ENDUSER_SETUP_DEBUG("Content is gzipped"); } int payload_len = LITLEN(http_header_200) + cl_len + ce_len + file_len; state->http_payload_len = payload_len; - state->http_payload_data = (char *) c_malloc(payload_len); + state->http_payload_data = (char *) malloc(payload_len); if (state->http_payload_data == NULL) { @@ -527,15 +527,15 @@ static int enduser_setup_http_load_payload(void) int offset = 0; - c_memcpy(&(state->http_payload_data[offset]), &(http_header_200), LITLEN(http_header_200)); + memcpy(&(state->http_payload_data[offset]), &(http_header_200), LITLEN(http_header_200)); offset += LITLEN(http_header_200); if (ce_len > 0) { - offset += c_sprintf(state->http_payload_data + offset, http_html_gzip_contentencoding, ce_len); + offset += sprintf(state->http_payload_data + offset, http_html_gzip_contentencoding, ce_len); } - c_memcpy(&(state->http_payload_data[offset]), &(cl_hdr), cl_len); + memcpy(&(state->http_payload_data[offset]), &(cl_hdr), cl_len); offset += cl_len; vfs_read(f, &(state->http_payload_data[offset]), file_len); vfs_close(f); @@ -658,18 +658,18 @@ static void enduser_setup_free_keypairs(struct keypairs_t *kp) { if (kp->keypairs != NULL) { for (int i = 0; i < kp->keypairs_nb * 2; i++) { - os_free(kp->keypairs[i]); + free(kp->keypairs[i]); } } - os_free(kp->keypairs); - os_free(kp); + free(kp->keypairs); + free(kp); } static struct keypairs_t * enduser_setup_alloc_keypairs(int kp_number ){ - struct keypairs_t *kp = os_malloc(sizeof(struct keypairs_t)); + struct keypairs_t *kp = malloc(sizeof(struct keypairs_t)); os_memset(kp, 0, sizeof(struct keypairs_t)); - kp->keypairs = os_malloc(kp_number * 2 * sizeof(char *)); + kp->keypairs = malloc(kp_number * 2 * sizeof(char *)); kp->keypairs_nb = kp_number; return kp; } @@ -691,7 +691,7 @@ static struct keypairs_t *enduser_setup_get_keypairs_from_form(char *form_body, int current_idx = 0; int err; - char *body_copy = os_malloc(form_length+1); + char *body_copy = malloc(form_length+1); os_bzero(body_copy, form_length+1); os_memcpy(body_copy, form_body, form_length); char *tok = strtok(body_copy, "="); @@ -699,12 +699,12 @@ static struct keypairs_t *enduser_setup_get_keypairs_from_form(char *form_body, char last_tok = '='; while (tok) { size_t len = strlen(tok); - kp->keypairs[current_idx] = os_malloc(len + 1); + kp->keypairs[current_idx] = malloc(len + 1); err = enduser_setup_http_urldecode(kp->keypairs[current_idx], tok, len, len + 1); if (err) { ENDUSER_SETUP_DEBUG("Unable to decode parameter"); enduser_setup_free_keypairs(kp); - os_free(body_copy); + free(body_copy); return NULL; } @@ -712,7 +712,7 @@ static struct keypairs_t *enduser_setup_get_keypairs_from_form(char *form_body, if (current_idx > keypair_nb*2) { ENDUSER_SETUP_DEBUG("Too many keypairs!"); enduser_setup_free_keypairs(kp); - os_free(body_copy); + free(body_copy); return NULL; } @@ -724,7 +724,7 @@ static struct keypairs_t *enduser_setup_get_keypairs_from_form(char *form_body, last_tok='='; } } - os_free(body_copy); + free(body_copy); return kp; } @@ -765,7 +765,7 @@ static int enduser_setup_write_file_with_extra_configuration_data(char *form_bod int idx = 0; for( idx = 0; idx < kp->keypairs_nb*2; idx=idx+2){ char* to_write = kp->keypairs[idx]; - size_t length = c_strlen(to_write); + size_t length = strlen(to_write); vfs_write(p_file, "p.", 2); @@ -774,7 +774,7 @@ static int enduser_setup_write_file_with_extra_configuration_data(char *form_bod vfs_write(p_file, "=\"", 2); to_write = kp->keypairs[idx+1]; - length = c_strlen(to_write); + length = strlen(to_write); vfs_write(p_file, to_write, length); vfs_write(p_file, "\"\n", 2); @@ -824,14 +824,14 @@ static int enduser_setup_http_handle_credentials(char *data, unsigned short data struct station_config *cnf = luaM_malloc(lua_getstate(), sizeof(struct station_config)); - c_memset(cnf, 0, sizeof(struct station_config)); + memset(cnf, 0, sizeof(struct station_config)); cnf->threshold.rssi = -127; cnf->threshold.authmode = AUTH_OPEN; int err; err = enduser_setup_http_urldecode(cnf->ssid, name_str_start, name_str_len, sizeof(cnf->ssid)); err |= enduser_setup_http_urldecode(cnf->password, pwd_str_start, pwd_str_len, sizeof(cnf->password)); - if (err != 0 || c_strlen(cnf->ssid) == 0) + if (err != 0 || strlen(cnf->ssid) == 0) { ENDUSER_SETUP_DEBUG("Unable to decode HTTP parameter to valid password or SSID"); return 1; @@ -990,21 +990,21 @@ static void enduser_setup_serve_status(struct tcp_pcb *conn) ip_addr[0] = '\0'; if (curr_state == STATION_GOT_IP) { - c_sprintf (ip_addr, "%d.%d.%d.%d", IP2STR(&ip_info.ip.addr)); + sprintf (ip_addr, "%d.%d.%d.%d", IP2STR(&ip_info.ip.addr)); } - int state_len = c_strlen(s); - int ip_len = c_strlen(ip_addr); - int ssid_len = c_strlen(config.ssid); + int state_len = strlen(s); + int ip_len = strlen(ip_addr); + int ssid_len = strlen(config.ssid); int status_len = state_len + ssid_len + ip_len + 1; char status_buf[status_len]; memset(status_buf, 0, status_len); - status_len = c_sprintf(status_buf, s, config.ssid, ip_addr); + status_len = sprintf(status_buf, s, config.ssid, ip_addr); int buf_len = sizeof(fmt) + status_len + 10; /* 10 = (9+1), 1 byte is '\0' and 9 are reserved for length field */ char buf[buf_len]; memset(buf, 0, buf_len); - int output_len = c_sprintf(buf, fmt, status_len, status_buf); + int output_len = sprintf(buf, fmt, status_len, status_buf); enduser_setup_http_serve_header(conn, buf, output_len); } @@ -1014,11 +1014,11 @@ static void enduser_setup_serve_status(struct tcp_pcb *conn) default: { const char *s = states[curr_state]; - int status_len = c_strlen(s); + int status_len = strlen(s); int buf_len = sizeof(fmt) + status_len + 10; /* 10 = (9+1), 1 byte is '\0' and 9 are reserved for length field */ char buf[buf_len]; memset(buf, 0, buf_len); - int output_len = c_sprintf(buf, fmt, status_len, s); + int output_len = sprintf(buf, fmt, status_len, s); enduser_setup_http_serve_header(conn, buf, output_len); } @@ -1048,13 +1048,13 @@ static void enduser_setup_serve_status_as_json (struct tcp_pcb *http_client) /* If IP address not yet available, get now */ if (strlen(ipaddr) == 0) { - c_sprintf(ipaddr, "%d.%d.%d.%d", IP2STR(&ip_info.ip.addr)); + sprintf(ipaddr, "%d.%d.%d.%d", IP2STR(&ip_info.ip.addr)); } - c_sprintf(json_payload, "{\"deviceid\":\"%s\", \"status\":%d}", ipaddr, curr_status); + sprintf(json_payload, "{\"deviceid\":\"%s\", \"status\":%d}", ipaddr, curr_status); } else { - c_sprintf(json_payload, "{\"deviceid\":\"%06X\", \"status\":%d}", system_get_chip_id(), curr_status); + sprintf(json_payload, "{\"deviceid\":\"%06X\", \"status\":%d}", system_get_chip_id(), curr_status); } const char fmt[] = @@ -1067,9 +1067,9 @@ static void enduser_setup_serve_status_as_json (struct tcp_pcb *http_client) "\r\n" "%s"; - int len = c_strlen(json_payload); - char buf[c_strlen(fmt) + NUMLEN(len) + len - 4]; - len = c_sprintf (buf, fmt, len, json_payload); + int len = strlen(json_payload); + char buf[strlen(fmt) + NUMLEN(len) + len - 4]; + len = sprintf (buf, fmt, len, json_payload); enduser_setup_http_serve_header (http_client, buf, len); } @@ -1098,15 +1098,15 @@ static void enduser_setup_handle_OPTIONS (struct tcp_pcb *http_client, char *dat int type = 0; - if (c_strncmp(data, "GET ", 4) == 0) + if (strncmp(data, "GET ", 4) == 0) { - if (c_strncmp(data + 4, "/aplist", 7) == 0 || c_strncmp(data + 4, "/setwifi?", 9) == 0 || c_strncmp(data + 4, "/status.json", 12) == 0) + if (strncmp(data + 4, "/aplist", 7) == 0 || strncmp(data + 4, "/setwifi?", 9) == 0 || strncmp(data + 4, "/status.json", 12) == 0) { - enduser_setup_http_serve_header (http_client, json, c_strlen(json)); + enduser_setup_http_serve_header (http_client, json, strlen(json)); return; } } - enduser_setup_http_serve_header (http_client, others, c_strlen(others)); + enduser_setup_http_serve_header (http_client, others, strlen(others)); return; } @@ -1114,7 +1114,7 @@ static void enduser_setup_handle_OPTIONS (struct tcp_pcb *http_client, char *dat static err_t enduser_setup_handle_POST(struct tcp_pcb *http_client, char* data, size_t data_len) { ENDUSER_SETUP_DEBUG("Handling POST"); - if (c_strncmp(data + 5, "/setwifi ", 9) == 0) // User clicked the submit button + if (strncmp(data + 5, "/setwifi ", 9) == 0) // User clicked the submit button { switch (enduser_setup_http_handle_credentials(data, data_len)) { @@ -1123,7 +1123,7 @@ static err_t enduser_setup_handle_POST(struct tcp_pcb *http_client, char* data, char* body=strstr(data, "\r\n\r\n"); char *content_length_str = strstr(data, "Content-Length: "); if( body != NULL && content_length_str != NULL){ - int bodylength = c_atoi(content_length_str + 16); + int bodylength = atoi(content_length_str + 16); body += 4; // length of the double CRLF found above enduser_setup_write_file_with_extra_configuration_data(body, bodylength); } @@ -1157,7 +1157,7 @@ static void free_scan_listeners (void) while (l) { next = l->next; - c_free (l); + free (l); l = next; } state->scan_listeners = 0; @@ -1177,7 +1177,7 @@ static void remove_scan_listener (scan_listener_t *l) if (*sl == l) { *sl = l->next; - c_free (l); + free (l); /* No early exit to guard against multi-entry on list */ } else @@ -1256,7 +1256,7 @@ static void on_scan_done (void *arg, STATUS status) /* To be able to safely escape a pathological SSID, we need 2*32 bytes */ const size_t max_entry_sz = 27 + 2*32 + 6; /* {"ssid":"","rssi":,"chan":} */ const size_t alloc_sz = hdr_sz + num_nets * max_entry_sz + 3; - char *http = os_zalloc (alloc_sz); + char *http = calloc (1, alloc_sz); if (!http) { goto serve_500; @@ -1282,26 +1282,26 @@ static void on_scan_done (void *arg, STATUS status) strcpy (p, entry_mid); p += sizeof (entry_mid) -1; - p += c_sprintf (p, "%d", wn->rssi); + p += sprintf (p, "%d", wn->rssi); const char entry_chan[] = ",\"chan\":"; strcpy (p, entry_chan); p += sizeof (entry_chan) -1; - p += c_sprintf (p, "%d", wn->channel); + p += sprintf (p, "%d", wn->channel); *p++ = '}'; } *p++ = ']'; size_t body_sz = (p - http) - hdr_sz; - c_sprintf (http, header_fmt, body_sz); + sprintf (http, header_fmt, body_sz); http[hdr_sz] = '['; /* Rewrite the \0 with the correct start of body */ notify_scan_listeners (http, hdr_sz + body_sz); ENDUSER_SETUP_DEBUG(http + hdr_sz); - c_free (http); + free (http); return; } @@ -1334,7 +1334,7 @@ static err_t enduser_setup_http_recvcb(void *arg, struct tcp_pcb *http_client, s return ERR_OK; } - char *data = os_zalloc (p->tot_len + 1); + char *data = calloc (1, p->tot_len + 1); if (!data) return ERR_MEM; @@ -1348,9 +1348,9 @@ static err_t enduser_setup_http_recvcb(void *arg, struct tcp_pcb *http_client, s ENDUSER_SETUP_DEBUG(data); #endif - if (c_strncmp(data, "GET ", 4) == 0) + if (strncmp(data, "GET ", 4) == 0) { - if (c_strncmp(data + 4, "/ ", 2) == 0 || c_strncmp(data + 4, "/?", 2) == 0) + if (strncmp(data + 4, "/ ", 2) == 0 || strncmp(data + 4, "/?", 2) == 0) { if (enduser_setup_http_serve_html(http_client) != 0) { @@ -1361,12 +1361,12 @@ static err_t enduser_setup_http_recvcb(void *arg, struct tcp_pcb *http_client, s goto free_out; /* streaming now in progress */ } } - else if (c_strncmp(data + 4, "/aplist", 7) == 0) + else if (strncmp(data + 4, "/aplist", 7) == 0) { /* Don't do an AP Scan while station is trying to connect to Wi-Fi */ if (state->connecting == 0) { - scan_listener_t *l = os_malloc (sizeof (scan_listener_t)); + scan_listener_t *l = malloc (sizeof (scan_listener_t)); if (!l) { ENDUSER_SETUP_ERROR("out of memory", ENDUSER_SETUP_ERR_OUT_OF_MEMORY, ENDUSER_SETUP_ERR_NONFATAL); @@ -1398,16 +1398,16 @@ static err_t enduser_setup_http_recvcb(void *arg, struct tcp_pcb *http_client, s enduser_setup_http_serve_header(http_client, http_header_204, LITLEN(http_header_204)); } } - else if (c_strncmp(data + 4, "/status.json", 12) == 0) + else if (strncmp(data + 4, "/status.json", 12) == 0) { enduser_setup_serve_status_as_json(http_client); } - else if (c_strncmp(data + 4, "/status", 7) == 0) + else if (strncmp(data + 4, "/status", 7) == 0) { enduser_setup_serve_status(http_client); } - else if (c_strncmp(data + 4, "/update?", 8) == 0) + else if (strncmp(data + 4, "/update?", 8) == 0) { switch (enduser_setup_http_handle_credentials(data, data_len)) { @@ -1422,7 +1422,7 @@ static err_t enduser_setup_http_recvcb(void *arg, struct tcp_pcb *http_client, s break; } } - else if (c_strncmp(data + 4, "/generate_204", 13) == 0) + else if (strncmp(data + 4, "/generate_204", 13) == 0) { /* Convince Android devices that they have internet access to avoid pesky dialogues. */ enduser_setup_http_serve_header(http_client, http_header_204, LITLEN(http_header_204)); @@ -1433,11 +1433,11 @@ static err_t enduser_setup_http_recvcb(void *arg, struct tcp_pcb *http_client, s enduser_setup_http_serve_header(http_client, http_header_404, LITLEN(http_header_404)); } } - else if (c_strncmp(data, "OPTIONS ", 8) == 0) + else if (strncmp(data, "OPTIONS ", 8) == 0) { enduser_setup_handle_OPTIONS(http_client, data, data_len); } - else if (c_strncmp(data, "POST ", 5) == 0) + else if (strncmp(data, "POST ", 5) == 0) { enduser_setup_handle_POST(http_client, data, data_len); } @@ -1449,7 +1449,7 @@ static err_t enduser_setup_http_recvcb(void *arg, struct tcp_pcb *http_client, s deferred_close (http_client); free_out: - os_free (data); + free (data); return ret; } @@ -1542,20 +1542,20 @@ static void enduser_setup_ap_start(void) ENDUSER_SETUP_DEBUG("enduser_setup_ap_start"); struct softap_config cnf; - c_memset(&(cnf), 0, sizeof(struct softap_config)); + 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(ssid); - c_memcpy(&(cnf.ssid), ssid, ssid_name_len); + int ssid_name_len = strlen(ssid); + memcpy(&(cnf.ssid), ssid, ssid_name_len); uint8_t mac[6]; wifi_get_macaddr(SOFTAP_IF, mac); cnf.ssid[ssid_name_len] = '_'; - c_sprintf(cnf.ssid + ssid_name_len + 1, "%02X%02X%02X", mac[3], mac[4], mac[5]); + sprintf(cnf.ssid + ssid_name_len + 1, "%02X%02X%02X", mac[3], mac[4], mac[5]); cnf.ssid_len = ssid_name_len + 7; cnf.channel = state == NULL? 1 : state->softAPchannel; cnf.authmode = AUTH_OPEN; @@ -1567,7 +1567,7 @@ static void enduser_setup_ap_start(void) #if ENDUSER_SETUP_DEBUG_ENABLE char debuginfo[100]; - c_sprintf(debuginfo, "SSID: %s, CHAN: %d", cnf.ssid, cnf.channel); + sprintf(debuginfo, "SSID: %s, CHAN: %d", cnf.ssid, cnf.channel); ENDUSER_SETUP_DEBUG(debuginfo); #endif } @@ -1614,15 +1614,15 @@ static void enduser_setup_dns_recv_callback(void *arg, char *recv_data, unsigned struct espconn *callback_espconn = arg; struct ip_info ip_info; - uint32_t qname_len = c_strlen(&(recv_data[12])) + 1; /* \0=1byte */ + uint32_t qname_len = strlen(&(recv_data[12])) + 1; /* \0=1byte */ uint32_t dns_reply_static_len = (uint32_t) sizeof(dns_header) + (uint32_t) sizeof(dns_body) + 2 + 4; /* dns_id=2bytes, ip=4bytes */ uint32_t dns_reply_len = dns_reply_static_len + qname_len; #if ENDUSER_SETUP_DEBUG_ENABLE - char *qname = c_malloc(qname_len + 12); + char *qname = malloc(qname_len + 12); if (qname != NULL) { - c_sprintf(qname, "DNS QUERY = %s", &(recv_data[12])); + sprintf(qname, "DNS QUERY = %s", &(recv_data[12])); uint32_t p; int i, j; @@ -1639,7 +1639,7 @@ static void enduser_setup_dns_recv_callback(void *arg, char *recv_data, unsigned } qname[i-1]='\0'; ENDUSER_SETUP_DEBUG(qname); - c_free(qname); + free(qname); } #endif @@ -1656,22 +1656,22 @@ static void enduser_setup_dns_recv_callback(void *arg, char *recv_data, unsigned } - char *dns_reply = (char *) c_malloc(dns_reply_len); + char *dns_reply = (char *) malloc(dns_reply_len); if (dns_reply == NULL) { ENDUSER_SETUP_ERROR_VOID("dns_recv_callback failed. Failed to allocate memory.", ENDUSER_SETUP_ERR_OUT_OF_MEMORY, ENDUSER_SETUP_ERR_NONFATAL); } uint32_t insert_byte = 0; - c_memcpy(&(dns_reply[insert_byte]), recv_data, 2); + memcpy(&(dns_reply[insert_byte]), recv_data, 2); insert_byte += 2; - c_memcpy(&(dns_reply[insert_byte]), dns_header, sizeof(dns_header)); + memcpy(&(dns_reply[insert_byte]), dns_header, sizeof(dns_header)); insert_byte += (uint32_t) sizeof(dns_header); - c_memcpy(&(dns_reply[insert_byte]), &(recv_data[12]), qname_len); + memcpy(&(dns_reply[insert_byte]), &(recv_data[12]), qname_len); insert_byte += qname_len; - c_memcpy(&(dns_reply[insert_byte]), dns_body, sizeof(dns_body)); + memcpy(&(dns_reply[insert_byte]), dns_body, sizeof(dns_body)); insert_byte += (uint32_t) sizeof(dns_body); - c_memcpy(&(dns_reply[insert_byte]), &(ip_info.ip), 4); + memcpy(&(dns_reply[insert_byte]), &(ip_info.ip), 4); /* SDK 1.4.0 changed behaviour, for UDP server need to look up remote ip/port */ remot_info *pr = 0; @@ -1684,7 +1684,7 @@ static void enduser_setup_dns_recv_callback(void *arg, char *recv_data, unsigned int8_t err; err = espconn_send(callback_espconn, dns_reply, dns_reply_len); - c_free(dns_reply); + free(dns_reply); if (err == ESPCONN_MEM) { ENDUSER_SETUP_ERROR_VOID("dns_recv_callback failed. Failed to allocate memory for send.", ENDUSER_SETUP_ERR_OUT_OF_MEMORY, ENDUSER_SETUP_ERR_FATAL); @@ -1725,16 +1725,16 @@ static void enduser_setup_free(void) { if (state->espconn_dns_udp->proto.udp != NULL) { - c_free(state->espconn_dns_udp->proto.udp); + free(state->espconn_dns_udp->proto.udp); } - c_free(state->espconn_dns_udp); + free(state->espconn_dns_udp); } - c_free(state->http_payload_data); + free(state->http_payload_data); free_scan_listeners (); - c_free(state); + free(state); state = NULL; } @@ -1747,20 +1747,20 @@ static int enduser_setup_dns_start(void) { ENDUSER_SETUP_ERROR("dns_start failed. Appears to already be started (espconn_dns_udp != NULL).", ENDUSER_SETUP_ERR_ALREADY_INITIALIZED, ENDUSER_SETUP_ERR_FATAL); } - state->espconn_dns_udp = (struct espconn *) c_malloc(sizeof(struct espconn)); + state->espconn_dns_udp = (struct espconn *) malloc(sizeof(struct espconn)); if (state->espconn_dns_udp == NULL) { ENDUSER_SETUP_ERROR("dns_start failed. Memory allocation failed (espconn_dns_udp == NULL).", ENDUSER_SETUP_ERR_OUT_OF_MEMORY, ENDUSER_SETUP_ERR_FATAL); } - esp_udp *esp_udp_data = (esp_udp *) c_malloc(sizeof(esp_udp)); + esp_udp *esp_udp_data = (esp_udp *) malloc(sizeof(esp_udp)); if (esp_udp_data == NULL) { ENDUSER_SETUP_ERROR("dns_start failed. Memory allocation failed (esp_udp == NULL).", ENDUSER_SETUP_ERR_OUT_OF_MEMORY, ENDUSER_SETUP_ERR_FATAL); } - c_memset(state->espconn_dns_udp, 0, sizeof(struct espconn)); - c_memset(esp_udp_data, 0, sizeof(esp_udp)); + memset(state->espconn_dns_udp, 0, sizeof(struct espconn)); + memset(esp_udp_data, 0, sizeof(esp_udp)); state->espconn_dns_udp->proto.udp = esp_udp_data; state->espconn_dns_udp->type = ESPCONN_UDP; state->espconn_dns_udp->state = ESPCONN_NONE; @@ -1816,7 +1816,7 @@ static int enduser_setup_init(lua_State *L) } else { - state = (enduser_setup_state_t *) os_zalloc(sizeof(enduser_setup_state_t)); + state = (enduser_setup_state_t *) calloc(1, sizeof(enduser_setup_state_t)); if (state == NULL) { @@ -1824,7 +1824,7 @@ static int enduser_setup_init(lua_State *L) } else { - c_memset(state, 0, sizeof(enduser_setup_state_t)); + memset(state, 0, sizeof(enduser_setup_state_t)); state->lua_connected_cb_ref = LUA_NOREF; state->lua_err_cb_ref = LUA_NOREF; diff --git a/app/modules/file.c b/app/modules/file.c index be5cdf44ef..03763b74f0 100644 --- a/app/modules/file.c +++ b/app/modules/file.c @@ -7,7 +7,7 @@ #include "c_types.h" #include "vfs.h" -#include "c_string.h" +#include #include @@ -190,7 +190,7 @@ static int file_open( lua_State* L ) const char *fname = luaL_checklstring( L, 1, &len ); const char *basename = vfs_basename( fname ); - luaL_argcheck(L, c_strlen(basename) <= FS_OBJ_NAME_LEN && c_strlen(fname) == len, 1, "filename invalid"); + luaL_argcheck(L, strlen(basename) <= FS_OBJ_NAME_LEN && strlen(fname) == len, 1, "filename invalid"); const char *mode = luaL_optstring(L, 2, "r"); @@ -303,7 +303,7 @@ static int file_exists( lua_State* L ) size_t len; const char *fname = luaL_checklstring( L, 1, &len ); const char *basename = vfs_basename( fname ); - luaL_argcheck(L, c_strlen(basename) <= FS_OBJ_NAME_LEN && c_strlen(fname) == len, 1, "filename invalid"); + luaL_argcheck(L, strlen(basename) <= FS_OBJ_NAME_LEN && strlen(fname) == len, 1, "filename invalid"); struct vfs_stat stat; lua_pushboolean(L, vfs_stat((char *)fname, &stat) == VFS_RES_OK ? 1 : 0); @@ -317,7 +317,7 @@ static int file_remove( lua_State* L ) size_t len; const char *fname = luaL_checklstring( L, 1, &len ); const char *basename = vfs_basename( fname ); - luaL_argcheck(L, c_strlen(basename) <= FS_OBJ_NAME_LEN && c_strlen(fname) == len, 1, "filename invalid"); + luaL_argcheck(L, strlen(basename) <= FS_OBJ_NAME_LEN && strlen(fname) == len, 1, "filename invalid"); vfs_remove((char *)fname); return 0; } @@ -343,11 +343,11 @@ static int file_rename( lua_State* L ) const char *oldname = luaL_checklstring( L, 1, &len ); const char *basename = vfs_basename( oldname ); - luaL_argcheck(L, c_strlen(basename) <= FS_OBJ_NAME_LEN && c_strlen(oldname) == len, 1, "filename invalid"); + luaL_argcheck(L, strlen(basename) <= FS_OBJ_NAME_LEN && strlen(oldname) == len, 1, "filename invalid"); const char *newname = luaL_checklstring( L, 2, &len ); basename = vfs_basename( newname ); - luaL_argcheck(L, c_strlen(basename) <= FS_OBJ_NAME_LEN && c_strlen(newname) == len, 2, "filename invalid"); + luaL_argcheck(L, strlen(basename) <= FS_OBJ_NAME_LEN && strlen(newname) == len, 2, "filename invalid"); if(0 <= vfs_rename( oldname, newname )){ lua_pushboolean(L, 1); @@ -362,7 +362,7 @@ static int file_stat( lua_State* L ) { size_t len; const char *fname = luaL_checklstring( L, 1, &len ); - luaL_argcheck( L, c_strlen(fname) <= FS_OBJ_NAME_LEN && c_strlen(fname) == len, 1, "filename invalid" ); + luaL_argcheck( L, strlen(fname) <= FS_OBJ_NAME_LEN && strlen(fname) == len, 1, "filename invalid" ); struct vfs_stat stat; if (vfs_stat( (char *)fname, &stat ) != VFS_RES_OK) { diff --git a/app/modules/gpio.c b/app/modules/gpio.c index 16b79365b8..4310441331 100644 --- a/app/modules/gpio.c +++ b/app/modules/gpio.c @@ -7,7 +7,7 @@ #include "platform.h" #include "user_interface.h" #include "c_types.h" -#include "c_string.h" +#include #include "gpio.h" #include "hw_timer.h" diff --git a/app/modules/gpio_pulse.c b/app/modules/gpio_pulse.c index bc1197441b..359458629d 100644 --- a/app/modules/gpio_pulse.c +++ b/app/modules/gpio_pulse.c @@ -4,7 +4,7 @@ #include "platform.h" #include "user_interface.h" #include "c_types.h" -#include "c_string.h" +#include #include "gpio.h" #include "hw_timer.h" #include "pin_map.h" diff --git a/app/modules/hdc1080.c b/app/modules/hdc1080.c index 095c3701a5..bc3f995f80 100644 --- a/app/modules/hdc1080.c +++ b/app/modules/hdc1080.c @@ -7,9 +7,9 @@ #include "module.h" #include "lauxlib.h" #include "platform.h" -#include "c_stdlib.h" -#include "c_string.h" -#include "c_math.h" +#include +#include +#include static const uint32_t hdc1080_i2c_id = 0; static const uint8_t hdc1080_i2c_addr = 0x40; diff --git a/app/modules/hmc5883l.c b/app/modules/hmc5883l.c index 7c0108a0a8..5dd13535cc 100644 --- a/app/modules/hmc5883l.c +++ b/app/modules/hmc5883l.c @@ -6,8 +6,8 @@ #include "module.h" #include "lauxlib.h" #include "platform.h" -#include "c_stdlib.h" -#include "c_string.h" +#include +#include static const uint32_t hmc5883_i2c_id = 0; static const uint8_t hmc5883_i2c_addr = 0x1E; diff --git a/app/modules/http.c b/app/modules/http.c index 87f077acab..0b37d5774a 100644 --- a/app/modules/http.c +++ b/app/modules/http.c @@ -3,7 +3,7 @@ * vowstar@gmail.com * 2015-12-29 *******************************************************************************/ -#include +#include #include "module.h" #include "lauxlib.h" #include "platform.h" @@ -92,7 +92,7 @@ static void http_callback( char * response, int http_status, char ** full_respon } if (full_response_p && *full_response_p) { - c_free(*full_response_p); + free(*full_response_p); *full_response_p = NULL; } diff --git a/app/modules/hx711.c b/app/modules/hx711.c index 8f89ca7f7b..61198e33a1 100644 --- a/app/modules/hx711.c +++ b/app/modules/hx711.c @@ -4,8 +4,8 @@ #include "module.h" #include "lauxlib.h" #include "platform.h" -#include "c_stdlib.h" -#include "c_string.h" +#include +#include #include "user_interface.h" static uint8_t data_pin; static uint8_t clk_pin; diff --git a/app/modules/l3g4200d.c b/app/modules/l3g4200d.c index a6f2fd765c..eef6d6d7f6 100644 --- a/app/modules/l3g4200d.c +++ b/app/modules/l3g4200d.c @@ -6,8 +6,8 @@ #include "module.h" #include "lauxlib.h" #include "platform.h" -#include "c_stdlib.h" -#include "c_string.h" +#include +#include static const uint32_t i2c_id = 0; static const uint8_t i2c_addr = 0x69; diff --git a/app/modules/mdns.c b/app/modules/mdns.c index 5afeb30e8e..8694c04582 100644 --- a/app/modules/mdns.c +++ b/app/modules/mdns.c @@ -3,11 +3,11 @@ #include "module.h" #include "lauxlib.h" -#include "c_string.h" -#include "c_stdlib.h" +#include +#include +#include #include "c_types.h" -#include "mem.h" #include "lwip/ip_addr.h" #include "nodemcu_mdns.h" #include "user_interface.h" @@ -43,16 +43,16 @@ static int mdns_register(lua_State *L) luaL_checktype(L, -2, LUA_TSTRING); const char *key = luaL_checkstring(L, -2); - if (c_strcmp(key, "port") == 0) { + if (strcmp(key, "port") == 0) { info.service_port = luaL_checknumber(L, -1); - } else if (c_strcmp(key, "service") == 0) { + } else if (strcmp(key, "service") == 0) { info.service_name = luaL_checkstring(L, -1); - } else if (c_strcmp(key, "description") == 0) { + } else if (strcmp(key, "description") == 0) { info.host_desc = luaL_checkstring(L, -1); } else { - int len = c_strlen(key) + 1; + int len = strlen(key) + 1; const char *value = luaL_checkstring(L, -1); - char *p = alloca(len + c_strlen(value) + 1); + char *p = alloca(len + strlen(value) + 1); strcpy(p, key); strcat(p, "="); strcat(p, value); diff --git a/app/modules/mqtt.c b/app/modules/mqtt.c index 2a411e9f26..49ae3e5bf8 100644 --- a/app/modules/mqtt.c +++ b/app/modules/mqtt.c @@ -4,8 +4,8 @@ #include "lauxlib.h" #include "platform.h" -#include "c_string.h" -#include "c_stdlib.h" +#include +#include #include "c_types.h" #include "mem.h" @@ -133,7 +133,7 @@ static void mqtt_socket_disconnected(void *arg) // tcp only } if(mud->mqtt_state.recv_buffer) { - c_free(mud->mqtt_state.recv_buffer); + free(mud->mqtt_state.recv_buffer); mud->mqtt_state.recv_buffer = NULL; } mud->mqtt_state.recv_buffer_size = 0; @@ -142,9 +142,9 @@ static void mqtt_socket_disconnected(void *arg) // tcp only if(mud->pesp_conn){ mud->pesp_conn->reverse = NULL; if(mud->pesp_conn->proto.tcp) - c_free(mud->pesp_conn->proto.tcp); + free(mud->pesp_conn->proto.tcp); mud->pesp_conn->proto.tcp = NULL; - c_free(mud->pesp_conn); + free(mud->pesp_conn); mud->pesp_conn = NULL; } @@ -303,7 +303,7 @@ static void mqtt_socket_received(void *arg, char *pdata, unsigned short len) // Last buffer had so few byte that we could not determine message length. // Store in a local heap buffer and operate on this, as if was the regular pdata buffer. // Avoids having to repeat message size/overflow logic. - temp_pdata = c_zalloc(mud->mqtt_state.recv_buffer_size + len); + temp_pdata = calloc(1,mud->mqtt_state.recv_buffer_size + len); if(temp_pdata == NULL) { NODE_DBG("MQTT[buffering-short]: Failed to allocate %u bytes, disconnecting...\n", mud->mqtt_state.recv_buffer_size + len); #ifdef CLIENT_SSL_ENABLE @@ -320,7 +320,7 @@ static void mqtt_socket_received(void *arg, char *pdata, unsigned short len) NODE_DBG("MQTT[buffering-short]: Continuing with %u + %u bytes\n", mud->mqtt_state.recv_buffer_size, len); memcpy(temp_pdata, mud->mqtt_state.recv_buffer, mud->mqtt_state.recv_buffer_size); memcpy(temp_pdata + mud->mqtt_state.recv_buffer_size, pdata, len); - c_free(mud->mqtt_state.recv_buffer); + free(mud->mqtt_state.recv_buffer); mud->mqtt_state.recv_buffer = NULL; mud->mqtt_state.recv_buffer_state = MQTT_RECV_NORMAL; @@ -533,7 +533,7 @@ static void mqtt_socket_received(void *arg, char *pdata, unsigned short len) // max_message_length is 16bit. uint16_t alloc_size = message_length > 0 ? (uint16_t)message_length : in_buffer_length; - mud->mqtt_state.recv_buffer = c_zalloc(alloc_size); + mud->mqtt_state.recv_buffer = calloc(1,alloc_size); if (mud->mqtt_state.recv_buffer == NULL) { NODE_DBG("MQTT: Failed to allocate %u bytes, disconnecting...\n", alloc_size); #ifdef CLIENT_SSL_ENABLE @@ -674,7 +674,7 @@ static void mqtt_socket_received(void *arg, char *pdata, unsigned short len) if(continuation_buffer != NULL) { NODE_DBG("MQTT[buffering]: buffered message finished. Continuing with rest of rx buffer (%u)\n", len); - c_free(mud->mqtt_state.recv_buffer); + free(mud->mqtt_state.recv_buffer); mud->mqtt_state.recv_buffer = NULL; in_buffer = continuation_buffer; @@ -698,7 +698,7 @@ static void mqtt_socket_received(void *arg, char *pdata, unsigned short len) RX_PACKET_FINISHED: if(temp_pdata != NULL) { - c_free(temp_pdata); + free(temp_pdata); } mqtt_send_if_possible(pesp_conn); @@ -902,12 +902,12 @@ static int mqtt_socket_client( lua_State* L ) lmqtt_userdata *mud; char tempid[20] = {0}; - c_sprintf(tempid, "%s%x", "NodeMCU_", system_get_chip_id() ); + sprintf(tempid, "%s%x", "NodeMCU_", system_get_chip_id() ); NODE_DBG(tempid); NODE_DBG("\n"); const char *clientId = tempid, *username = NULL, *password = NULL; - size_t idl = c_strlen(tempid); + size_t idl = strlen(tempid); size_t unl = 0, pwl = 0; int keepalive = 0; int stack = 1; @@ -917,7 +917,7 @@ static int mqtt_socket_client( lua_State* L ) // create a object mud = (lmqtt_userdata *)lua_newuserdata(L, sizeof(lmqtt_userdata)); - c_memset(mud, 0, sizeof(*mud)); + memset(mud, 0, sizeof(*mud)); // pre-initialize it, in case of errors mud->self_ref = LUA_NOREF; mud->cb_connect_ref = LUA_NOREF; @@ -989,30 +989,30 @@ static int mqtt_socket_client( lua_State* L ) } // TODO: check the zalloc result. - mud->connect_info.client_id = (uint8_t *)c_zalloc(idl+1); - mud->connect_info.username = (uint8_t *)c_zalloc(unl + 1); - mud->connect_info.password = (uint8_t *)c_zalloc(pwl + 1); + mud->connect_info.client_id = (uint8_t *)calloc(1,idl+1); + mud->connect_info.username = (uint8_t *)calloc(1,unl + 1); + mud->connect_info.password = (uint8_t *)calloc(1,pwl + 1); if(!mud->connect_info.client_id || !mud->connect_info.username || !mud->connect_info.password){ if(mud->connect_info.client_id) { - c_free(mud->connect_info.client_id); + free(mud->connect_info.client_id); mud->connect_info.client_id = NULL; } if(mud->connect_info.username) { - c_free(mud->connect_info.username); + free(mud->connect_info.username); mud->connect_info.username = NULL; } if(mud->connect_info.password) { - c_free(mud->connect_info.password); + free(mud->connect_info.password); mud->connect_info.password = NULL; } return luaL_error(L, "not enough memory"); } - c_memcpy(mud->connect_info.client_id, clientId, idl); + memcpy(mud->connect_info.client_id, clientId, idl); mud->connect_info.client_id[idl] = 0; - c_memcpy(mud->connect_info.username, username, unl); + memcpy(mud->connect_info.username, username, unl); mud->connect_info.username[unl] = 0; - c_memcpy(mud->connect_info.password, password, pwl); + memcpy(mud->connect_info.password, password, pwl); mud->connect_info.password[pwl] = 0; NODE_DBG("MQTT: Init info: %s, %s, %s\r\n", mud->connect_info.client_id, mud->connect_info.username, mud->connect_info.password); @@ -1055,9 +1055,9 @@ static int mqtt_delete( lua_State* L ) if(mud->pesp_conn){ // for client connected to tcp server, this should set NULL in disconnect cb mud->pesp_conn->reverse = NULL; if(mud->pesp_conn->proto.tcp) - c_free(mud->pesp_conn->proto.tcp); + free(mud->pesp_conn->proto.tcp); mud->pesp_conn->proto.tcp = NULL; - c_free(mud->pesp_conn); + free(mud->pesp_conn); mud->pesp_conn = NULL; // for socket, it will free this when disconnected } while(mud->mqtt_state.pending_msg_q) { @@ -1066,34 +1066,34 @@ static int mqtt_delete( lua_State* L ) // ---- alloc-ed in mqtt_socket_lwt() if(mud->connect_info.will_topic){ - c_free(mud->connect_info.will_topic); + free(mud->connect_info.will_topic); mud->connect_info.will_topic = NULL; } if(mud->connect_info.will_message){ - c_free(mud->connect_info.will_message); + free(mud->connect_info.will_message); mud->connect_info.will_message = NULL; } // ---- //--------- alloc-ed in mqtt_socket_received() if(mud->mqtt_state.recv_buffer) { - c_free(mud->mqtt_state.recv_buffer); + free(mud->mqtt_state.recv_buffer); mud->mqtt_state.recv_buffer = NULL; } // ---- //--------- alloc-ed in mqtt_socket_client() if(mud->connect_info.client_id){ - c_free(mud->connect_info.client_id); + free(mud->connect_info.client_id); mud->connect_info.client_id = NULL; } if(mud->connect_info.username){ - c_free(mud->connect_info.username); + free(mud->connect_info.username); mud->connect_info.username = NULL; } if(mud->connect_info.password){ - c_free(mud->connect_info.password); + free(mud->connect_info.password); mud->connect_info.password = NULL; } // ------- @@ -1203,7 +1203,7 @@ static sint8 socket_dns_found(const char *name, ip_addr_t *ipaddr, void *arg) if(ipaddr->addr != 0) { dns_reconn_count = 0; - c_memcpy(pesp_conn->proto.tcp->remote_ip, &(ipaddr->addr), 4); + memcpy(pesp_conn->proto.tcp->remote_ip, &(ipaddr->addr), 4); NODE_DBG("TCP ip is set: "); NODE_DBG(IPSTR, IP2STR(&(ipaddr->addr))); NODE_DBG("\n"); @@ -1241,7 +1241,7 @@ static int mqtt_socket_connect( lua_State* L ) struct espconn *pesp_conn = mud->pesp_conn; if(!pesp_conn) { - pesp_conn = mud->pesp_conn = (struct espconn *)c_zalloc(sizeof(struct espconn)); + pesp_conn = mud->pesp_conn = (struct espconn *)calloc(1,sizeof(struct espconn)); } else { espconn_delete(pesp_conn); } @@ -1249,9 +1249,9 @@ static int mqtt_socket_connect( lua_State* L ) if(!pesp_conn) return luaL_error(L, "not enough memory"); if (!pesp_conn->proto.tcp) - pesp_conn->proto.tcp = (esp_tcp *)c_zalloc(sizeof(esp_tcp)); + pesp_conn->proto.tcp = (esp_tcp *)calloc(1,sizeof(esp_tcp)); if(!pesp_conn->proto.tcp){ - c_free(pesp_conn); + free(pesp_conn); pesp_conn = mud->pesp_conn = NULL; return luaL_error(L, "not enough memory"); } @@ -1271,7 +1271,7 @@ static int mqtt_socket_connect( lua_State* L ) domain = "127.0.0.1"; } ipaddr.addr = ipaddr_addr(domain); - c_memcpy(pesp_conn->proto.tcp->remote_ip, &ipaddr.addr, 4); + memcpy(pesp_conn->proto.tcp->remote_ip, &ipaddr.addr, 4); NODE_DBG("TCP ip is set: "); NODE_DBG(IPSTR, IP2STR(&ipaddr.addr)); NODE_DBG("\n"); @@ -1340,7 +1340,7 @@ static int mqtt_socket_connect( lua_State* L ) //My guess: If in doubt, resume the timer // timer started in socket_connect() - if((ipaddr.addr == IPADDR_NONE) && (c_memcmp(domain,"255.255.255.255",16) != 0)) + if((ipaddr.addr == IPADDR_NONE) && (memcmp(domain,"255.255.255.255",16) != 0)) { host_ip.addr = 0; dns_reconn_count = 0; @@ -1434,25 +1434,25 @@ static int mqtt_socket_on( lua_State* L ) luaL_checkanyfunction(L, 3); lua_pushvalue(L, 3); // copy argument (func) to the top of stack - if( sl == 7 && c_strcmp(method, "connect") == 0){ + if( sl == 7 && strcmp(method, "connect") == 0){ luaL_unref(L, LUA_REGISTRYINDEX, mud->cb_connect_ref); mud->cb_connect_ref = luaL_ref(L, LUA_REGISTRYINDEX); - }else if( sl == 7 && c_strcmp(method, "offline") == 0){ + }else if( sl == 7 && strcmp(method, "offline") == 0){ luaL_unref(L, LUA_REGISTRYINDEX, mud->cb_disconnect_ref); mud->cb_disconnect_ref = luaL_ref(L, LUA_REGISTRYINDEX); - }else if( sl == 7 && c_strcmp(method, "message") == 0){ + }else if( sl == 7 && strcmp(method, "message") == 0){ luaL_unref(L, LUA_REGISTRYINDEX, mud->cb_message_ref); mud->cb_message_ref = luaL_ref(L, LUA_REGISTRYINDEX); - }else if( sl == 8 && c_strcmp(method, "overflow") == 0){ + }else if( sl == 8 && strcmp(method, "overflow") == 0){ luaL_unref(L, LUA_REGISTRYINDEX, mud->cb_overflow_ref); mud->cb_overflow_ref = luaL_ref(L, LUA_REGISTRYINDEX); - }else if( sl == 6 && c_strcmp(method, "puback") == 0){ + }else if( sl == 6 && strcmp(method, "puback") == 0){ luaL_unref(L, LUA_REGISTRYINDEX, mud->cb_puback_ref); mud->cb_puback_ref = luaL_ref(L, LUA_REGISTRYINDEX); - }else if( sl == 6 && c_strcmp(method, "suback") == 0){ + }else if( sl == 6 && strcmp(method, "suback") == 0){ luaL_unref(L, LUA_REGISTRYINDEX, mud->cb_suback_ref); mud->cb_suback_ref = luaL_ref(L, LUA_REGISTRYINDEX); - }else if( sl == 8 && c_strcmp(method, "unsuback") == 0){ + }else if( sl == 8 && strcmp(method, "unsuback") == 0){ luaL_unref(L, LUA_REGISTRYINDEX, mud->cb_unsuback_ref); mud->cb_unsuback_ref = luaL_ref(L, LUA_REGISTRYINDEX); }else{ @@ -1795,30 +1795,30 @@ static int mqtt_socket_lwt( lua_State* L ) } stack++; if(mud->connect_info.will_topic){ // free the previous one if there is any - c_free(mud->connect_info.will_topic); + free(mud->connect_info.will_topic); mud->connect_info.will_topic = NULL; } if(mud->connect_info.will_message){ - c_free(mud->connect_info.will_message); + free(mud->connect_info.will_message); mud->connect_info.will_message = NULL; } - mud->connect_info.will_topic = (uint8_t*) c_zalloc( topicSize + 1 ); - mud->connect_info.will_message = (uint8_t*) c_zalloc( msgSize + 1 ); + mud->connect_info.will_topic = (uint8_t*) calloc(1, topicSize + 1 ); + mud->connect_info.will_message = (uint8_t*) calloc(1, msgSize + 1 ); if(!mud->connect_info.will_topic || !mud->connect_info.will_message){ if(mud->connect_info.will_topic){ - c_free(mud->connect_info.will_topic); + free(mud->connect_info.will_topic); mud->connect_info.will_topic = NULL; } if(mud->connect_info.will_message){ - c_free(mud->connect_info.will_message); + free(mud->connect_info.will_message); mud->connect_info.will_message = NULL; } return luaL_error( L, "not enough memory"); } - c_memcpy(mud->connect_info.will_topic, lwtTopic, topicSize); + memcpy(mud->connect_info.will_topic, lwtTopic, topicSize); mud->connect_info.will_topic[topicSize] = 0; - c_memcpy(mud->connect_info.will_message, lwtMsg, msgSize); + memcpy(mud->connect_info.will_message, lwtMsg, msgSize); mud->connect_info.will_message[msgSize] = 0; if ( lua_isnumber(L, stack) ) diff --git a/app/modules/net.c b/app/modules/net.c index 1336089d69..d0b705d7d9 100644 --- a/app/modules/net.c +++ b/app/modules/net.c @@ -5,8 +5,9 @@ #include "platform.h" #include "lmem.h" -#include "c_string.h" -#include "c_stdlib.h" +#include +#include +#include #include "c_types.h" #include "mem.h" @@ -875,14 +876,14 @@ static void net_dns_static_cb(const char *name, ip_addr_t *ipaddr, void *callbac addr = *ipaddr; else addr.addr = 0xFFFFFFFF; int cb_ref = ((int*)callback_arg)[0]; - c_free(callback_arg); + free(callback_arg); lua_State *L = lua_getstate(); lua_rawgeti(L, LUA_REGISTRYINDEX, cb_ref); lua_pushnil(L); if (addr.addr != 0xFFFFFFFF) { char iptmp[20]; - size_t ipl = c_sprintf(iptmp, IPSTR, IP2STR(&addr.addr)); + size_t ipl = sprintf(iptmp, IPSTR, IP2STR(&addr.addr)); lua_pushlstring(L, iptmp, ipl); } else { lua_pushnil(L); @@ -906,7 +907,7 @@ static int net_dns_static( lua_State* L ) { if (cbref == LUA_NOREF) { return luaL_error(L, "wrong callback"); } - int *cbref_ptr = c_zalloc(sizeof(int)); + int *cbref_ptr = calloc(1, sizeof(int)); cbref_ptr[0] = cbref; ip_addr_t addr; err_t err = dns_gethostbyname(domain, &addr, net_dns_static_cb, cbref_ptr); @@ -917,7 +918,7 @@ static int net_dns_static( lua_State* L ) { return 0; } else { int e = lwip_lua_checkerr(L, err); - c_free(cbref_ptr); + free(cbref_ptr); return e; } return 0; @@ -958,7 +959,7 @@ static int net_getdnsserver( lua_State* L ) { lua_pushnil( L ); } else { char temp[20] = {0}; - c_sprintf(temp, IPSTR, IP2STR( &ipaddr.addr ) ); + sprintf(temp, IPSTR, IP2STR( &ipaddr.addr ) ); lua_pushstring( L, temp ); } diff --git a/app/modules/node.c b/app/modules/node.c index 7a01bac112..cc834c31da 100644 --- a/app/modules/node.c +++ b/app/modules/node.c @@ -17,7 +17,7 @@ #include "platform.h" #include "lflash.h" #include "c_types.h" -#include "c_string.h" +#include #include "driver/uart.h" #include "user_interface.h" #include "flash_api.h" @@ -189,7 +189,7 @@ static int output_redir_ref = LUA_NOREF; static int serial_debug = 1; void output_redirect(const char *str) { lua_State *L = lua_getstate(); - // if(c_strlen(str)>=TX_BUFF_SIZE){ + // if(strlen(str)>=TX_BUFF_SIZE){ // NODE_ERR("output too long.\n"); // return; // } @@ -260,18 +260,18 @@ static int node_compile( lua_State* L ) size_t len; const char *fname = luaL_checklstring( L, 1, &len ); const char *basename = vfs_basename( fname ); - luaL_argcheck(L, c_strlen(basename) <= FS_OBJ_NAME_LEN && c_strlen(fname) == len, 1, "filename invalid"); + luaL_argcheck(L, strlen(basename) <= FS_OBJ_NAME_LEN && strlen(fname) == len, 1, "filename invalid"); char *output = luaM_malloc( L, len+1 ); - c_strcpy(output, fname); + strcpy(output, fname); // check here that filename end with ".lua". - if (len < 4 || (c_strcmp( output + len - 4, ".lua") != 0) ) { + if (len < 4 || (strcmp( output + len - 4, ".lua") != 0) ) { luaM_free( L, output ); return luaL_error(L, "not a .lua file"); } - output[c_strlen(output) - 2] = 'c'; - output[c_strlen(output) - 1] = '\0'; + output[strlen(output) - 2] = 'c'; + output[strlen(output) - 1] = '\0'; NODE_DBG(output); NODE_DBG("\n"); if (luaL_loadfsfile(L, fname) != 0) { @@ -622,7 +622,7 @@ static int node_getpartitiontable (lua_State *L) { static void insert_partition(partition_item_t *p, int n, uint32_t type, uint32_t addr) { if (n>0) - c_memmove(p+1, p, n*sizeof(partition_item_t)); /* overlapped so must be move not cpy */ + memmove(p+1, p, n*sizeof(partition_item_t)); /* overlapped so must be move not cpy */ p->type = type; p->addr = addr; p->size = 0; @@ -630,7 +630,7 @@ static void insert_partition(partition_item_t *p, int n, uint32_t type, uint32_t static void delete_partition(partition_item_t *p, int n) { if (n>0) - c_memmove(p, p+1, n*sizeof(partition_item_t)); /* overlapped so must be move not cpy */ + memmove(p, p+1, n*sizeof(partition_item_t)); /* overlapped so must be move not cpy */ } #define SKIP (~0) @@ -668,7 +668,7 @@ static int node_setpartitiontable (lua_State *L) { */ lua_newuserdata(L, (n+2)*sizeof(partition_item_t)); pt = lua_touserdata (L, -1); - c_memcpy(pt, rcr_pt, n*sizeof(partition_item_t)); + memcpy(pt, rcr_pt, n*sizeof(partition_item_t)); pt[n].type = 0; pt[n+1].type = 0; for (i = 0; i < n; i ++) { diff --git a/app/modules/pcm.c b/app/modules/pcm.c index 5193ec63d1..f9056bcd78 100644 --- a/app/modules/pcm.c +++ b/app/modules/pcm.c @@ -3,8 +3,8 @@ #include "module.h" #include "lauxlib.h" #include "task/task.h" -#include "c_string.h" -#include "c_stdlib.h" +#include +#include #include "pcm.h" #include "pcm_drv.h" @@ -43,11 +43,11 @@ static int pcm_drv_free( lua_State *L ) UNREF_CB( cfg->self_ref ); if (cfg->bufs[0].data) { - c_free( cfg->bufs[0].data ); + free( cfg->bufs[0].data ); cfg->bufs[0].data = NULL; } if (cfg->bufs[1].data) { - c_free( cfg->bufs[1].data ); + free( cfg->bufs[1].data ); cfg->bufs[1].data = NULL; } @@ -152,19 +152,19 @@ static int pcm_drv_on( lua_State *L ) is_func = TRUE; } - if ((len == 4) && (c_strcmp( event, "data" ) == 0)) { + if ((len == 4) && (strcmp( event, "data" ) == 0)) { luaL_unref( L, LUA_REGISTRYINDEX, cfg->cb_data_ref); cfg->cb_data_ref = COND_REF( is_func ); - } else if ((len == 7) && (c_strcmp( event, "drained" ) == 0)) { + } else if ((len == 7) && (strcmp( event, "drained" ) == 0)) { luaL_unref( L, LUA_REGISTRYINDEX, cfg->cb_drained_ref); cfg->cb_drained_ref = COND_REF( is_func ); - } else if ((len == 6) && (c_strcmp( event, "paused" ) == 0)) { + } else if ((len == 6) && (strcmp( event, "paused" ) == 0)) { luaL_unref( L, LUA_REGISTRYINDEX, cfg->cb_paused_ref); cfg->cb_paused_ref = COND_REF( is_func ); - } else if ((len == 7) && (c_strcmp( event, "stopped" ) == 0)) { + } else if ((len == 7) && (strcmp( event, "stopped" ) == 0)) { luaL_unref( L, LUA_REGISTRYINDEX, cfg->cb_stopped_ref); cfg->cb_stopped_ref = COND_REF( is_func ); - } else if ((len == 2) && (c_strcmp( event, "vu" ) == 0)) { + } else if ((len == 2) && (strcmp( event, "vu" ) == 0)) { luaL_unref( L, LUA_REGISTRYINDEX, cfg->cb_vu_ref); cfg->cb_vu_ref = COND_REF( is_func ); diff --git a/app/modules/perf.c b/app/modules/perf.c index fc5f712ebe..96196d848e 100644 --- a/app/modules/perf.c +++ b/app/modules/perf.c @@ -9,7 +9,7 @@ #include "ets_sys.h" #include "os_type.h" #include "osapi.h" -#include "c_stdlib.h" +#include #include "module.h" #include "lauxlib.h" diff --git a/app/modules/rotary.c b/app/modules/rotary.c index 5436b56f3d..27df544065 100644 --- a/app/modules/rotary.c +++ b/app/modules/rotary.c @@ -12,7 +12,7 @@ #include "c_types.h" #include "user_interface.h" #include "driver/rotary.h" -#include "../libc/c_stdlib.h" +#include #define MASK(x) (1 << ROTARY_ ## x ## _INDEX) @@ -145,7 +145,7 @@ static int lrotary_setup( lua_State* L ) callback_free(L, id, ROTARY_ALL); if (!data[id]) { - data[id] = (DATA *) c_zalloc(sizeof(DATA)); + data[id] = (DATA *) calloc(1, sizeof(DATA)); if (!data[id]) { return -1; } @@ -211,7 +211,7 @@ static int lrotary_close( lua_State* L ) DATA *d = data[id]; if (d) { data[id] = NULL; - c_free(d); + free(d); } if (rotary_close( id )) { diff --git a/app/modules/rtcfifo.c b/app/modules/rtcfifo.c index dfea7777f1..9ae5e2e227 100644 --- a/app/modules/rtcfifo.c +++ b/app/modules/rtcfifo.c @@ -6,6 +6,7 @@ #include "rtc/rtctime.h" #define RTCTIME_SLEEP_ALIGNED rtctime_deep_sleep_until_aligned_us #include "rtc/rtcfifo.h" +#include // rtcfifo.prepare ([{sensor_count=n, interval_us=m, storage_begin=x, storage_end=y}]) static int rtcfifo_prepare (lua_State *L) diff --git a/app/modules/sjson.c b/app/modules/sjson.c index 7be6bb1bca..530dfb25b1 100644 --- a/app/modules/sjson.c +++ b/app/modules/sjson.c @@ -6,9 +6,9 @@ #ifndef LOCAL_LUA #include "module.h" -#include "c_string.h" -#include "c_math.h" -#include "c_limits.h" +#include +#include +#include #endif #include "json_config.h" diff --git a/app/modules/sntp.c b/app/modules/sntp.c index 7d1b987256..9af8bda9f3 100644 --- a/app/modules/sntp.c +++ b/app/modules/sntp.c @@ -38,7 +38,7 @@ #include "os_type.h" #include "osapi.h" #include "lwip/udp.h" -#include "c_stdlib.h" +#include #include "user_modules.h" #include "lwip/dns.h" #include "task/task.h" @@ -180,18 +180,18 @@ static void cleanup (lua_State *L) luaL_unref (L, LUA_REGISTRYINDEX, state->sync_cb_ref); luaL_unref (L, LUA_REGISTRYINDEX, state->err_cb_ref); luaL_unref (L, LUA_REGISTRYINDEX, state->list_ref); - os_free (state); + free (state); state = 0; } static ip_addr_t* get_free_server() { - ip_addr_t* temp = (ip_addr_t *) c_malloc((server_count + 1) * sizeof(ip_addr_t)); + ip_addr_t* temp = (ip_addr_t *) malloc((server_count + 1) * sizeof(ip_addr_t)); if (server_count > 0) { memcpy(temp, serverp, server_count * sizeof(ip_addr_t)); } if (serverp) { - c_free(serverp); + free(serverp); } serverp = temp; @@ -671,7 +671,7 @@ static void sntp_dolookups (lua_State *L) { } static char *state_init(lua_State *L) { - state = (sntp_state_t *)c_malloc (sizeof (sntp_state_t)); + state = (sntp_state_t *)malloc (sizeof (sntp_state_t)); if (!state) return ("out of memory"); @@ -700,7 +700,7 @@ static char *set_repeat_mode(lua_State *L, bool enable) { if (enable) { set_repeat_mode(L, FALSE); - repeat = (sntp_repeat_t *) c_malloc(sizeof(sntp_repeat_t)); + repeat = (sntp_repeat_t *) malloc(sizeof(sntp_repeat_t)); if (!repeat) { return "no memory"; } @@ -722,7 +722,7 @@ static char *set_repeat_mode(lua_State *L, bool enable) luaL_unref (L, LUA_REGISTRYINDEX, repeat->sync_cb_ref); luaL_unref (L, LUA_REGISTRYINDEX, repeat->err_cb_ref); luaL_unref (L, LUA_REGISTRYINDEX, repeat->list_ref); - c_free(repeat); + free(repeat); repeat = NULL; } } @@ -811,7 +811,7 @@ static int sntp_sync (lua_State *L) for (i = 0; i < 4; i++) { lua_pushnumber(L, i + 1); char buf[64]; - c_sprintf(buf, "%d.nodemcu.pool.ntp.org", i); + sprintf(buf, "%d.nodemcu.pool.ntp.org", i); lua_pushstring(L, buf); lua_settable(L, -3); } @@ -835,7 +835,7 @@ static int sntp_sync (lua_State *L) { if (state->pcb) udp_remove (state->pcb); - c_free (state); + free (state); state = 0; } return luaL_error (L, errmsg); diff --git a/app/modules/sqlite3.c b/app/modules/sqlite3.c index 825da29f0b..a6b9cde643 100644 --- a/app/modules/sqlite3.c +++ b/app/modules/sqlite3.c @@ -31,7 +31,7 @@ #define SQLITE_OMIT_PROGRESS_CALLBACK 1 #include -#include +#include #include #define LUA_LIB @@ -273,7 +273,7 @@ static int dbvm_tostring(lua_State *L) { if (svm->vm == NULL) strcpy(buff, "closed"); else - c_sprintf(buff, "%p", svm); + sprintf(buff, "%p", svm); lua_pushfstring(L, "sqlite virtual machine (%s)", buff); return 1; } @@ -743,7 +743,7 @@ static int cleanupdb(lua_State *L, sdb *db) { luaL_unref(L, LUA_REGISTRYINDEX, func->fn_step); luaL_unref(L, LUA_REGISTRYINDEX, func->fn_finalize); luaL_unref(L, LUA_REGISTRYINDEX, func->udata); - c_free(func); + free(func); func = func_next; } db->func = NULL; @@ -800,7 +800,7 @@ static int lcontext_tostring(lua_State *L) { if (ctx->ctx == NULL) strcpy(buff, "closed"); else - c_sprintf(buff, "%p", ctx->ctx); + sprintf(buff, "%p", ctx->ctx); lua_pushfstring(L, "sqlite function context (%s)", buff); return 1; } @@ -1156,7 +1156,7 @@ static int db_register_function(lua_State *L, int aggregate) { if (aggregate) luaL_checktype(L, 5, LUA_TFUNCTION); /* maybe an alternative way to allocate memory should be used/avoided */ - func = (sdb_func*)c_malloc(sizeof(sdb_func)); + func = (sdb_func*)malloc(sizeof(sdb_func)); if (func == NULL) { luaL_error(L, "out of memory"); } @@ -1194,7 +1194,7 @@ static int db_register_function(lua_State *L, int aggregate) { } else { /* free allocated memory */ - c_free(func); + free(func); } lua_pushboolean(L, result == SQLITE_OK ? 1 : 0); @@ -1232,7 +1232,7 @@ static int collwrapper(scc *co,int l1,const void *p1, static void collfree(scc *co) { if (co) { luaL_unref(co->L,LUA_REGISTRYINDEX,co->ref); - c_free(co); + free(co); } } @@ -1246,7 +1246,7 @@ static int db_create_collation(lua_State *L) { else if (!lua_isnil(L,3)) luaL_error(L,"create_collation: function or nil expected"); if (collfunc != NULL) { - co=(scc *)c_malloc(sizeof(scc)); /* userdata is a no-no as it + co=(scc *)malloc(sizeof(scc)); /* userdata is a no-no as it will be garbage-collected */ if (co) { co->L=L; @@ -2037,7 +2037,7 @@ static int db_tostring(lua_State *L) { if (db->db == NULL) strcpy(buff, "closed"); else - c_sprintf(buff, "%p", lua_touserdata(L, 1)); + sprintf(buff, "%p", lua_touserdata(L, 1)); lua_pushfstring(L, "sqlite database (%s)", buff); return 1; } diff --git a/app/modules/tcs34725.c b/app/modules/tcs34725.c index a673394594..b5d59f28df 100644 --- a/app/modules/tcs34725.c +++ b/app/modules/tcs34725.c @@ -22,7 +22,7 @@ #include "module.h" #include "lauxlib.h" #include "platform.h" -#include "c_math.h" +#include // #define TCS34725_ADDRESS (0x29<<1) #define TCS34725_ADDRESS (0x29) diff --git a/app/modules/tls.c b/app/modules/tls.c index d66c628e72..d59af574b7 100644 --- a/app/modules/tls.c +++ b/app/modules/tls.c @@ -8,8 +8,8 @@ #include "platform.h" #include "lmem.h" -#include "c_string.h" -#include "c_stdlib.h" +#include +#include #include "c_types.h" #include "mem.h" @@ -77,10 +77,10 @@ static void tls_socket_cleanup(tls_socket_ud *ud) { if (ud->pesp_conn) { espconn_secure_disconnect(ud->pesp_conn); if (ud->pesp_conn->proto.tcp) { - c_free(ud->pesp_conn->proto.tcp); + free(ud->pesp_conn->proto.tcp); ud->pesp_conn->proto.tcp = NULL; } - c_free(ud->pesp_conn); + free(ud->pesp_conn); ud->pesp_conn = NULL; } lua_State *L = lua_getstate(); @@ -167,7 +167,7 @@ static void tls_socket_dns_cb( const char* domain, const ip_addr_t *ip_addr, tls lua_pushnil(L); } else { char tmp[20]; - c_sprintf(tmp, IPSTR, IP2STR(&addr.addr)); + sprintf(tmp, IPSTR, IP2STR(&addr.addr)); lua_pushstring(L, tmp); } lua_call(L, 2, 0); @@ -205,13 +205,13 @@ static int tls_socket_connect( lua_State *L ) { if (domain == NULL) return luaL_error(L, "invalid domain"); - ud->pesp_conn = (struct espconn*)c_zalloc(sizeof(struct espconn)); + ud->pesp_conn = (struct espconn*)calloc(1,sizeof(struct espconn)); if(!ud->pesp_conn) return luaL_error(L, "not enough memory"); ud->pesp_conn->proto.udp = NULL; - ud->pesp_conn->proto.tcp = (esp_tcp *)c_zalloc(sizeof(esp_tcp)); + ud->pesp_conn->proto.tcp = (esp_tcp *)calloc(1,sizeof(esp_tcp)); if(!ud->pesp_conn->proto.tcp){ - c_free(ud->pesp_conn); + free(ud->pesp_conn); ud->pesp_conn = NULL; return luaL_error(L, "not enough memory"); } @@ -349,7 +349,7 @@ static int tls_socket_getpeer( lua_State *L ) { if(ud->pesp_conn && ud->pesp_conn->proto.tcp->remote_port != 0){ char temp[20] = {0}; - c_sprintf(temp, IPSTR, IP2STR( &(ud->pesp_conn->proto.tcp->remote_ip) ) ); + sprintf(temp, IPSTR, IP2STR( &(ud->pesp_conn->proto.tcp->remote_ip) ) ); lua_pushstring( L, temp ); lua_pushinteger( L, ud->pesp_conn->proto.tcp->remote_port ); } else { @@ -382,10 +382,10 @@ static int tls_socket_delete( lua_State *L ) { if (ud->pesp_conn) { espconn_secure_disconnect(ud->pesp_conn); if (ud->pesp_conn->proto.tcp) { - c_free(ud->pesp_conn->proto.tcp); + free(ud->pesp_conn->proto.tcp); ud->pesp_conn->proto.tcp = NULL; } - c_free(ud->pesp_conn); + free(ud->pesp_conn); ud->pesp_conn = NULL; } @@ -507,7 +507,7 @@ static const char *fill_page_with_pem(lua_State *L, const unsigned char *flash_m memset(buffer, 0xff, buffer_limit - buffer); // Lets see if it matches what is already there.... - if (c_memcmp(buffer_base, flash_memory, INTERNAL_FLASH_SECTOR_SIZE) != 0) { + if (memcmp(buffer_base, flash_memory, INTERNAL_FLASH_SECTOR_SIZE) != 0) { // Starts being dangerous if (platform_flash_erase_sector(flash_offset / INTERNAL_FLASH_SECTOR_SIZE) != PLATFORM_OK) { luaM_free(L, buffer_base); diff --git a/app/modules/tm1829.c b/app/modules/tm1829.c index 21f149dae4..c0da809c75 100644 --- a/app/modules/tm1829.c +++ b/app/modules/tm1829.c @@ -1,8 +1,8 @@ #include "module.h" #include "lauxlib.h" #include "platform.h" -#include "c_stdlib.h" -#include "c_string.h" +#include +#include #include "user_interface.h" static inline uint32_t _getCycleCount(void) { @@ -68,7 +68,7 @@ static int ICACHE_FLASH_ATTR tm1829_write(lua_State* L) const char *rgb = luaL_checklstring(L, 2, &length); // dont modify lua-internal lstring - make a copy instead - char *buffer = (char *)c_malloc(length); + char *buffer = (char *)malloc(length); // Ignore incomplete Byte triples at the end of buffer length -= length % 3; @@ -95,7 +95,7 @@ static int ICACHE_FLASH_ATTR tm1829_write(lua_State* L) os_delay_us(500); // reset time - c_free(buffer); + free(buffer); return 0; } diff --git a/app/modules/tmr.c b/app/modules/tmr.c index 6625f973ab..14b7f528fc 100644 --- a/app/modules/tmr.c +++ b/app/modules/tmr.c @@ -78,7 +78,7 @@ typedef struct{ uint32_t interval; uint8_t mode; }timer_struct_t; -typedef timer_struct_t* timer_t; +typedef timer_struct_t* tmr_t; // The previous implementation extended the rtc counter to 64 bits, and then // applied rtc2sec with the current calibration value to that 64 bit value. @@ -97,7 +97,7 @@ static sint32_t soft_watchdog = -1; static os_timer_t rtc_timer; static void alarm_timer_common(void* arg){ - timer_t tmr = (timer_t)arg; + tmr_t tmr = (tmr_t)arg; lua_State* L = lua_getstate(); if(tmr->lua_ref == LUA_NOREF) return; @@ -142,16 +142,16 @@ static int tmr_now(lua_State* L){ return 1; } -static timer_t tmr_get( lua_State *L, int stack ) { - timer_t t = (timer_t)luaL_checkudata(L, stack, "tmr.timer"); +static tmr_t tmr_get( lua_State *L, int stack ) { + tmr_t t = (tmr_t)luaL_checkudata(L, stack, "tmr.timer"); if (t == NULL) - return (timer_t)luaL_error(L, "timer object expected"); + return (tmr_t)luaL_error(L, "timer object expected"); return t; } // Lua: tmr.register( ref, interval, mode, function ) static int tmr_register(lua_State* L){ - timer_t tmr = tmr_get(L, 1); + tmr_t tmr = tmr_get(L, 1); uint32_t interval = luaL_checkinteger(L, 2); uint8_t mode = luaL_checkinteger(L, 3); @@ -176,7 +176,7 @@ static int tmr_register(lua_State* L){ // Lua: tmr.start( id / ref ) static int tmr_start(lua_State* L){ - timer_t tmr = tmr_get(L, 1); + tmr_t tmr = tmr_get(L, 1); if (tmr->self_ref == LUA_NOREF) { lua_pushvalue(L, 1); @@ -202,7 +202,7 @@ static int tmr_alarm(lua_State* L){ // Lua: tmr.stop( id / ref ) static int tmr_stop(lua_State* L){ - timer_t tmr = tmr_get(L, 1); + tmr_t tmr = tmr_get(L, 1); if (tmr->self_ref != LUA_REFNIL) { luaL_unref(L, LUA_REGISTRYINDEX, tmr->self_ref); @@ -244,7 +244,7 @@ static int tmr_resume_all (lua_State *L){ // Lua: tmr.unregister( id / ref ) static int tmr_unregister(lua_State* L){ - timer_t tmr = tmr_get(L, 1); + tmr_t tmr = tmr_get(L, 1); if (tmr->self_ref != LUA_REFNIL) { luaL_unref(L, LUA_REGISTRYINDEX, tmr->self_ref); @@ -262,7 +262,7 @@ static int tmr_unregister(lua_State* L){ // Lua: tmr.interval( id / ref, interval ) static int tmr_interval(lua_State* L){ - timer_t tmr = tmr_get(L, 1); + tmr_t tmr = tmr_get(L, 1); uint32_t interval = luaL_checkinteger(L, 2); luaL_argcheck(L, (interval > 0 && interval <= MAX_TIMEOUT), 2, MAX_TIMEOUT_ERR_STR); @@ -278,7 +278,7 @@ static int tmr_interval(lua_State* L){ // Lua: tmr.state( id / ref ) static int tmr_state(lua_State* L){ - timer_t tmr = tmr_get(L, 1); + tmr_t tmr = tmr_get(L, 1); if(tmr->mode == TIMER_MODE_OFF){ lua_pushnil(L); @@ -355,7 +355,7 @@ static int tmr_softwd( lua_State* L ){ // Lua: tmr.create() static int tmr_create( lua_State *L ) { - timer_t ud = (timer_t)lua_newuserdata(L, sizeof(timer_struct_t)); + tmr_t ud = (tmr_t)lua_newuserdata(L, sizeof(timer_struct_t)); if (!ud) return luaL_error(L, "not enough memory"); luaL_getmetatable(L, "tmr.timer"); lua_setmetatable(L, -2); diff --git a/app/modules/uart.c b/app/modules/uart.c index a9b7efeeaf..364873d7d5 100644 --- a/app/modules/uart.c +++ b/app/modules/uart.c @@ -5,7 +5,7 @@ #include "platform.h" #include "c_types.h" -#include "c_string.h" +#include #include "rom.h" static int uart_receive_rf = LUA_NOREF; @@ -67,7 +67,7 @@ static int l_uart_on( lua_State* L ) } else { lua_pushnil(L); } - if(sl == 4 && c_strcmp(method, "data") == 0){ + if(sl == 4 && strcmp(method, "data") == 0){ run_input = true; if(uart_receive_rf != LUA_NOREF){ luaL_unref(L, LUA_REGISTRYINDEX, uart_receive_rf); diff --git a/app/modules/websocket.c b/app/modules/websocket.c index 27e886afcb..77d83d082f 100644 --- a/app/modules/websocket.c +++ b/app/modules/websocket.c @@ -14,8 +14,8 @@ #include "module.h" #include "c_types.h" -#include "c_string.h" -#include "c_stdlib.h" +#include +#include #include "websocketclient.h" @@ -191,14 +191,14 @@ static int websocketclient_connect(lua_State *L) { static header_t *realloc_headers(header_t *headers, int new_size) { if(headers) { for(header_t *header = headers; header->key; header++) { - c_free(header->value); - c_free(header->key); + free(header->value); + free(header->key); } - c_free(headers); + free(headers); } if(!new_size) return NULL; - return (header_t *)c_malloc(sizeof(header_t) * (new_size + 1)); + return (header_t *)malloc(sizeof(header_t) * (new_size + 1)); } static int websocketclient_config(lua_State *L) { @@ -225,8 +225,8 @@ static int websocketclient_config(lua_State *L) { lua_pushnil(L); while(lua_next(L, -2)) { - header->key = c_strdup(lua_tostring(L, -2)); - header->value = c_strdup(lua_tostring(L, -1)); + header->key = strdup(lua_tostring(L, -2)); + header->value = strdup(lua_tostring(L, -1)); header++; lua_pop(L, 1); } diff --git a/app/modules/wifi.c b/app/modules/wifi.c index 794fdef1b0..ddcc3096cd 100644 --- a/app/modules/wifi.c +++ b/app/modules/wifi.c @@ -6,8 +6,8 @@ #include "lauxlib.h" #include "platform.h" -#include "c_string.h" -#include "c_stdlib.h" +#include +#include #include "ctype.h" #include "c_types.h" @@ -95,18 +95,18 @@ static void wifi_scan_done(void *arg, STATUS status) while (bss_link != NULL) { - c_memset(ssid, 0, 33); - if (c_strlen(bss_link->ssid) <= 32) + memset(ssid, 0, 33); + if (strlen(bss_link->ssid) <= 32) { - c_memcpy(ssid, bss_link->ssid, c_strlen(bss_link->ssid)); + memcpy(ssid, bss_link->ssid, strlen(bss_link->ssid)); } else { - c_memcpy(ssid, bss_link->ssid, 32); + memcpy(ssid, bss_link->ssid, 32); } if(getap_output_format==1) //use new format(BSSID : SSID, RSSI, Authmode, Channel) { - c_sprintf(temp,MACSTR, MAC2STR(bss_link->bssid)); + sprintf(temp,MACSTR, MAC2STR(bss_link->bssid)); wifi_add_sprintf_field(L, temp, "%s,%d,%d,%d", ssid, bss_link->rssi, bss_link->authmode, bss_link->channel); NODE_DBG(MACSTR" : %s\n",MAC2STR(bss_link->bssid) , temp);//00 00 00 00 00 00 @@ -260,7 +260,7 @@ static int wifi_setcountry( lua_State* L ){ if( lua_isstring(L, -1) ){ const char *country_code = luaL_checklstring( L, -1, &len ); luaL_argcheck(L, (len==2 && isalpha(country_code[0]) && isalpha(country_code[1])), 1, "country: country code must be 2 chars"); - c_memcpy(cfg.cc, country_code, len); + memcpy(cfg.cc, country_code, len); if(cfg.cc[0] >= 0x61) cfg.cc[0]=cfg.cc[0]-32; //if lowercase change to uppercase if(cfg.cc[1] >= 0x61) cfg.cc[1]=cfg.cc[1]-32; //if lowercase change to uppercase } @@ -552,7 +552,7 @@ static int wifi_getmac( lua_State* L, uint8_t mode ) char temp[64]; uint8_t mac[6]; wifi_get_macaddr(mode, mac); - c_sprintf(temp, MACSTR, MAC2STR(mac)); + sprintf(temp, MACSTR, MAC2STR(mac)); lua_pushstring( L, temp ); return 1; } @@ -581,11 +581,11 @@ static int wifi_getip( lua_State* L, uint8_t mode ) } else { - c_sprintf(temp, "%d.%d.%d.%d", IP2STR(&pTempIp.ip) ); + sprintf(temp, "%d.%d.%d.%d", IP2STR(&pTempIp.ip) ); lua_pushstring( L, temp ); - c_sprintf(temp, "%d.%d.%d.%d", IP2STR(&pTempIp.netmask) ); + sprintf(temp, "%d.%d.%d.%d", IP2STR(&pTempIp.netmask) ); lua_pushstring( L, temp ); - c_sprintf(temp, "%d.%d.%d.%d", IP2STR(&pTempIp.gw) ); + sprintf(temp, "%d.%d.%d.%d", IP2STR(&pTempIp.gw) ); lua_pushstring( L, temp ); return 3; } @@ -609,7 +609,7 @@ static int wifi_getbroadcast( lua_State* L, uint8_t mode ) uint32 broadcast_address32 = ~pTempIp.netmask.addr | subnet_mask32; broadcast_address.addr = broadcast_address32; - c_sprintf(temp, "%d.%d.%d.%d", IP2STR(&broadcast_address) ); + sprintf(temp, "%d.%d.%d.%d", IP2STR(&broadcast_address) ); lua_pushstring( L, temp ); return 1; @@ -688,7 +688,7 @@ static int wifi_station_get_ap_info4lua( lua_State* L ) lua_pushstring(L, temp); lua_setfield(L, -2, "ssid"); #if defined(WIFI_DEBUG) - c_sprintf(debug_temp, " %-6d %-32s ", i, temp); + sprintf(debug_temp, " %-6d %-32s ", i, temp); #endif memset(temp, 0, sizeof(temp)); @@ -699,13 +699,13 @@ static int wifi_station_get_ap_info4lua( lua_State* L ) lua_setfield(L, -2, "pwd"); } #if defined(WIFI_DEBUG) - c_sprintf(debug_temp + strlen(debug_temp), "%-64s ", temp); + sprintf(debug_temp + strlen(debug_temp), "%-64s ", temp); #endif memset(temp, 0, sizeof(temp)); if (config[i].bssid_set) { - c_sprintf(temp, MACSTR, MAC2STR(config[i].bssid)); + sprintf(temp, MACSTR, MAC2STR(config[i].bssid)); lua_pushstring(L, temp); lua_setfield(L, -2, "bssid"); } @@ -812,7 +812,7 @@ static int wifi_station_getconfig( lua_State* L, bool get_flash_cfg) lua_setfield(L, -2, "bssid_set"); memset(temp, 0, sizeof(temp)); - c_sprintf(temp, MACSTR, MAC2STR(sta_conf.bssid)); + sprintf(temp, MACSTR, MAC2STR(sta_conf.bssid)); lua_pushstring( L, temp); lua_setfield(L, -2, "bssid"); @@ -827,7 +827,7 @@ static int wifi_station_getconfig( lua_State* L, bool get_flash_cfg) memcpy(temp, sta_conf.password, sizeof(sta_conf.password)); lua_pushstring(L, temp); lua_pushinteger( L, sta_conf.bssid_set); - c_sprintf(temp, MACSTR, MAC2STR(sta_conf.bssid)); + sprintf(temp, MACSTR, MAC2STR(sta_conf.bssid)); lua_pushstring( L, temp); return 4; } @@ -1180,8 +1180,8 @@ static int wifi_station_listap( lua_State* L ) const char *ssidstr = luaL_checklstring( L, -1, &len ); if(len>32) return luaL_error( L, "ssid:<32" ); - c_memset(ssid, 0, 32); - c_memcpy(ssid, ssidstr, len); + memset(ssid, 0, 32); + memcpy(ssid, ssidstr, len); scan_cfg.ssid=ssid; NODE_DBG(scan_cfg.ssid); NODE_DBG("\n"); @@ -1199,7 +1199,7 @@ static int wifi_station_listap( lua_State* L ) { const char *macaddr = luaL_checklstring( L, -1, &len ); luaL_argcheck(L, len==17, 1, INVALID_MAC_STR); - c_memset(bssid, 0, 6); + memset(bssid, 0, 6); ets_str2macaddr(bssid, macaddr); scan_cfg.bssid=bssid; NODE_DBG(MACSTR, MAC2STR(scan_cfg.bssid)); @@ -1401,7 +1401,7 @@ static int wifi_ap_deauth( lua_State* L ) } else { - c_memset(&mac, 0xFF, sizeof(mac)); + memset(&mac, 0xFF, sizeof(mac)); } lua_pushboolean(L,wifi_softap_deauth(mac)); return 1; @@ -1799,7 +1799,7 @@ static int wifi_ap_listclient( lua_State* L ) struct station_info * next_station; while (station != NULL) { - c_sprintf(temp, MACSTR, MAC2STR(station->bssid)); + sprintf(temp, MACSTR, MAC2STR(station->bssid)); wifi_add_sprintf_field(L, temp, IPSTR, IP2STR(&station->ip)); station = STAILQ_NEXT(station, next); } @@ -1833,9 +1833,9 @@ static int wifi_ap_dhcp_config( lua_State* L ) ip4_addr4(&lease.end_ip) += config.max_connection - 1; char temp[64]; - c_sprintf(temp, IPSTR, IP2STR(&lease.start_ip)); + sprintf(temp, IPSTR, IP2STR(&lease.start_ip)); lua_pushstring(L, temp); - c_sprintf(temp, IPSTR, IP2STR(&lease.end_ip)); + sprintf(temp, IPSTR, IP2STR(&lease.end_ip)); lua_pushstring(L, temp); // note: DHCP max range = 101 from start_ip to end_ip @@ -1983,20 +1983,20 @@ void wifi_change_default_host_name(void) wifi_get_macaddr(STATION_IF, mac); #ifndef WIFI_STA_HOSTNAME - c_sprintf(temp, "NODE-%X%X%X", (mac)[3], (mac)[4], (mac)[5]); + sprintf(temp, "NODE-%X%X%X", (mac)[3], (mac)[4], (mac)[5]); #elif defined(WIFI_STA_HOSTNAME) && !defined(WIFI_STA_HOSTNAME_APPEND_MAC) if(wifi_sta_checkhostname(WIFI_STA_HOSTNAME, strlen(WIFI_STA_HOSTNAME))){ - c_sprintf(temp, "%s", WIFI_STA_HOSTNAME); + sprintf(temp, "%s", WIFI_STA_HOSTNAME); } else{ - c_sprintf(temp, "NODE-%X%X%X", (mac)[3], (mac)[4], (mac)[5]); + sprintf(temp, "NODE-%X%X%X", (mac)[3], (mac)[4], (mac)[5]); } #elif defined(WIFI_STA_HOSTNAME) && defined(WIFI_STA_HOSTNAME_APPEND_MAC) if(strlen(WIFI_STA_HOSTNAME) <= 26 && wifi_sta_checkhostname(WIFI_STA_HOSTNAME, strlen(WIFI_STA_HOSTNAME))){ - c_sprintf(temp, "%s%X%X%X", WIFI_STA_HOSTNAME, (mac)[3], (mac)[4], (mac)[5]); + sprintf(temp, "%s%X%X%X", WIFI_STA_HOSTNAME, (mac)[3], (mac)[4], (mac)[5]); } else{ - c_sprintf(temp, "NODE-%X%X%X", (mac)[3], (mac)[4], (mac)[5]); + sprintf(temp, "NODE-%X%X%X", (mac)[3], (mac)[4], (mac)[5]); } #endif diff --git a/app/modules/wifi_common.c b/app/modules/wifi_common.c index cba000ebba..b2afc5ea92 100644 --- a/app/modules/wifi_common.c +++ b/app/modules/wifi_common.c @@ -10,7 +10,7 @@ void wifi_add_sprintf_field(lua_State* L, char* name, char* string, ...) char buffer[256]; va_list arglist; va_start( arglist, string ); - c_vsprintf( buffer, string, arglist ); + vsprintf( buffer, string, arglist ); va_end( arglist ); lua_pushstring(L, buffer); lua_setfield(L, -2, name); diff --git a/app/modules/wifi_common.h b/app/modules/wifi_common.h index c94a857d97..3c14354eaa 100644 --- a/app/modules/wifi_common.h +++ b/app/modules/wifi_common.h @@ -5,12 +5,11 @@ #include "lauxlib.h" #include "platform.h" -#include "c_string.h" -#include "c_stdlib.h" -#include "c_types.h" +#include +#include +#include #include "user_interface.h" #include "user_config.h" -#include "c_stdio.h" #include "task/task.h" //#define WIFI_DEBUG @@ -37,16 +36,16 @@ static inline void unregister_lua_cb(lua_State* L, int* cb_ref){ void wifi_change_default_host_name(void); #if defined(WIFI_DEBUG) || defined(NODE_DEBUG) -#define WIFI_DBG(...) c_printf(__VA_ARGS__) +#define WIFI_DBG(...) printf(__VA_ARGS__) #else -#define WIFI_DBG(...) //c_printf(__VA_ARGS__) +#define WIFI_DBG(...) //printf(__VA_ARGS__) #endif #if defined(EVENT_DEBUG) || defined(NODE_DEBUG) -#define EVENT_DBG(fmt, ...) c_printf("\n EVENT_DBG(%s): "fmt"\n", __FUNCTION__, ##__VA_ARGS__) +#define EVENT_DBG(fmt, ...) printf("\n EVENT_DBG(%s): "fmt"\n", __FUNCTION__, ##__VA_ARGS__) #else -#define EVENT_DBG(...) //c_printf(__VA_ARGS__) +#define EVENT_DBG(...) //printf(__VA_ARGS__) #endif enum wifi_suspension_state{ diff --git a/app/modules/wifi_eventmon.c b/app/modules/wifi_eventmon.c index 89c2fb7daf..5d016f914d 100644 --- a/app/modules/wifi_eventmon.c +++ b/app/modules/wifi_eventmon.c @@ -4,8 +4,8 @@ #include "lauxlib.h" #include "platform.h" -#include "c_string.h" -#include "c_stdlib.h" +#include +#include #include "c_types.h" #include "user_interface.h" @@ -82,7 +82,7 @@ static void wifi_event_monitor_handle_event_cb(System_Event_t *evt) lua_rawgeti(L, LUA_REGISTRYINDEX, event_queue_ref); System_Event_t* evt_tmp = lua_newuserdata(L, sizeof(System_Event_t)); - c_memcpy(evt_tmp, evt, sizeof(System_Event_t)); //copy event data to new struct + memcpy(evt_tmp, evt, sizeof(System_Event_t)); //copy event data to new struct sint32_t evt_ud_ref = luaL_ref(L, LUA_REGISTRYINDEX); size_t queue_len = lua_objlen(L, -1); diff --git a/app/modules/wifi_monitor.c b/app/modules/wifi_monitor.c index 88067b8fd4..041bb03f85 100644 --- a/app/modules/wifi_monitor.c +++ b/app/modules/wifi_monitor.c @@ -5,8 +5,8 @@ #include "lapi.h" #include "platform.h" -#include "c_string.h" -#include "c_stdlib.h" +#include +#include #include "ctype.h" #include "c_types.h" @@ -294,12 +294,12 @@ static void wifi_rx_cb(uint8 *buf, uint16 len) { return; } - packet_t *packet = (packet_t *) c_malloc(len + sizeof(packet_t)); + packet_t *packet = (packet_t *) malloc(len + sizeof(packet_t)); if (packet) { packet->len = len; memcpy(packet->buf, buf, len); if (!task_post_medium(tasknumber, (ETSParam) packet)) { - c_free(packet); + free(packet); } } } @@ -320,11 +320,11 @@ static void monitor_task(os_param_t param, uint8_t prio) luaL_getmetatable(L, "wifi.packet"); lua_setmetatable(L, -2); - c_free(input); + free(input); lua_call(L, 1, 0); } else { - c_free(input); + free(input); } } diff --git a/app/modules/ws2801.c b/app/modules/ws2801.c index b325898ba3..bbc34b4978 100644 --- a/app/modules/ws2801.c +++ b/app/modules/ws2801.c @@ -1,8 +1,9 @@ #include "module.h" #include "lauxlib.h" #include "platform.h" -#include "c_stdlib.h" -#include "c_string.h" +#include +#include +#include "osapi.h" /** * Code is based on https://github.com/CHERTS/esp8266-devkit/blob/master/Espressif/examples/EspLightNode/user/ws2801.c diff --git a/app/modules/ws2812.c b/app/modules/ws2812.c index 3be67e89d6..fa892079c0 100644 --- a/app/modules/ws2812.c +++ b/app/modules/ws2812.c @@ -2,9 +2,9 @@ #include "lauxlib.h" #include "lmem.h" #include "platform.h" -#include "c_stdlib.h" -#include "c_math.h" -#include "c_string.h" +#include +#include +#include #include "user_interface.h" #include "driver/uart.h" #include "osapi.h" @@ -201,7 +201,7 @@ static int ws2812_new_buffer(lua_State *L) { ws2812_buffer * buffer = allocate_buffer(L, leds, colorsPerLed); - c_memset(buffer->values, 0, colorsPerLed * leds); + memset(buffer->values, 0, colorsPerLed * leds); return 1; } @@ -295,7 +295,7 @@ int ws2812_buffer_shift(ws2812_buffer * buffer, int shiftValue, unsigned shift_t return 0; } - uint8_t * tmp_pixels = c_malloc(buffer->colorsPerLed * sizeof(uint8_t) * shift); + uint8_t * tmp_pixels = malloc(buffer->colorsPerLed * sizeof(uint8_t) * shift); int i,j; size_t shift_len, remaining_len; // calculate length of shift section and remaining section @@ -305,37 +305,37 @@ int ws2812_buffer_shift(ws2812_buffer * buffer, int shiftValue, unsigned shift_t if (shiftValue > 0) { // Store the values which are moved out of the array (last n pixels) - c_memcpy(tmp_pixels, &buffer->values[offset + (size-shift)*buffer->colorsPerLed], shift_len); + memcpy(tmp_pixels, &buffer->values[offset + (size-shift)*buffer->colorsPerLed], shift_len); // Move pixels to end os_memmove(&buffer->values[offset + shift*buffer->colorsPerLed], &buffer->values[offset], remaining_len); // Fill beginning with temp data if (shift_type == SHIFT_LOGICAL) { - c_memset(&buffer->values[offset], 0, shift_len); + memset(&buffer->values[offset], 0, shift_len); } else { - c_memcpy(&buffer->values[offset], tmp_pixels, shift_len); + memcpy(&buffer->values[offset], tmp_pixels, shift_len); } } else { // Store the values which are moved out of the array (last n pixels) - c_memcpy(tmp_pixels, &buffer->values[offset], shift_len); + memcpy(tmp_pixels, &buffer->values[offset], shift_len); // Move pixels to end os_memmove(&buffer->values[offset], &buffer->values[offset + shift*buffer->colorsPerLed], remaining_len); // Fill beginning with temp data if (shift_type == SHIFT_LOGICAL) { - c_memset(&buffer->values[offset + (size-shift)*buffer->colorsPerLed], 0, shift_len); + memset(&buffer->values[offset + (size-shift)*buffer->colorsPerLed], 0, shift_len); } else { - c_memcpy(&buffer->values[offset + (size-shift)*buffer->colorsPerLed], tmp_pixels, shift_len); + memcpy(&buffer->values[offset + (size-shift)*buffer->colorsPerLed], tmp_pixels, shift_len); } } // Free memory - c_free(tmp_pixels); + free(tmp_pixels); return 0; } @@ -386,7 +386,7 @@ static int ws2812_buffer_replace(lua_State* L) { luaL_argcheck(L, srcLen + start - 1 <= buffer->size, 2, "Does not fit into destination"); - c_memcpy(buffer->values + (start - 1) * buffer->colorsPerLed, src, srcLen * buffer->colorsPerLed); + memcpy(buffer->values + (start - 1) * buffer->colorsPerLed, src, srcLen * buffer->colorsPerLed); return 0; } @@ -504,7 +504,7 @@ static int ws2812_buffer_set(lua_State* L) { return luaL_error(L, "string size will exceed strip length"); } - c_memcpy(&buffer->values[buffer->colorsPerLed*led], buf, len); + memcpy(&buffer->values[buffer->colorsPerLed*led], buf, len); } else { @@ -535,7 +535,7 @@ static int ws2812_buffer_sub(lua_State* L) { if (end > (ptrdiff_t)l) end = (ptrdiff_t)l; if (start <= end) { ws2812_buffer *result = allocate_buffer(L, end - start + 1, lhs->colorsPerLed); - c_memcpy(result->values, lhs->values + lhs->colorsPerLed * (start - 1), lhs->colorsPerLed * (end - start + 1)); + memcpy(result->values, lhs->values + lhs->colorsPerLed * (start - 1), lhs->colorsPerLed * (end - start + 1)); } else { ws2812_buffer *result = allocate_buffer(L, 0, lhs->colorsPerLed); } @@ -553,8 +553,8 @@ static int ws2812_buffer_concat(lua_State* L) { ws2812_buffer * buffer = allocate_buffer(L, leds, colorsPerLed); - c_memcpy(buffer->values, lhs->values, lhs->colorsPerLed * lhs->size); - c_memcpy(buffer->values + lhs->colorsPerLed * lhs->size, rhs->values, rhs->colorsPerLed * rhs->size); + memcpy(buffer->values, lhs->values, lhs->colorsPerLed * lhs->size); + memcpy(buffer->values + lhs->colorsPerLed * lhs->size, rhs->values, rhs->colorsPerLed * rhs->size); return 1; } @@ -579,7 +579,7 @@ static int ws2812_buffer_tostring(lua_State* L) { luaL_addchar(&result, ','); } char numbuf[5]; - c_sprintf(numbuf, "%d", buffer->values[p]); + sprintf(numbuf, "%d", buffer->values[p]); luaL_addstring(&result, numbuf); } luaL_addchar(&result, ')'); diff --git a/app/modules/ws2812.h b/app/modules/ws2812.h index 40c0fb2685..9b31910f62 100644 --- a/app/modules/ws2812.h +++ b/app/modules/ws2812.h @@ -5,9 +5,9 @@ #include "lauxlib.h" #include "lmem.h" #include "platform.h" -#include "c_stdlib.h" -#include "c_math.h" -#include "c_string.h" +#include +#include +#include #include "user_interface.h" #include "driver/uart.h" #include "osapi.h" diff --git a/app/modules/ws2812_effects.c b/app/modules/ws2812_effects.c index 6945c8b8b3..e53676becf 100644 --- a/app/modules/ws2812_effects.c +++ b/app/modules/ws2812_effects.c @@ -2,9 +2,9 @@ #include "lauxlib.h" #include "lmem.h" #include "platform.h" -#include "c_stdlib.h" -#include "c_math.h" -#include "c_string.h" +#include +#include +#include #include "user_interface.h" #include "driver/uart.h" #include "osapi.h" @@ -18,8 +18,6 @@ #define DEFAULT_MODE 0 #define DEFAULT_COLOR 0xFF0000 -#define UINT32_MAX 4294967295U - #define SPEED_MIN 0 #define SPEED_MAX 255 #define SPEED_DEFAULT 150 @@ -161,11 +159,11 @@ static int ws2812_effects_init(lua_State *L) { // get rid of old state if (state != NULL) { luaL_unref(L, LUA_REGISTRYINDEX, state->buffer_ref); - os_free((void *) state); + free((void *) state); } // Allocate memory and set all to zero size_t size = sizeof(ws2812_effects) + buffer->colorsPerLed*sizeof(uint8_t); - state = (ws2812_effects *) os_zalloc(size); + state = (ws2812_effects *) calloc(1,size); // initialize state->speed = SPEED_DEFAULT; state->mode_delay = DELAY_DEFAULT; @@ -307,7 +305,7 @@ static int ws2812_effects_mode_blink() { else { // off ws2812_buffer * buffer = state->buffer; - c_memset(&buffer->values[0], 0, buffer->size * buffer->colorsPerLed); + memset(&buffer->values[0], 0, buffer->size * buffer->colorsPerLed); } return 0; } diff --git a/app/mqtt/mqtt_msg.c b/app/mqtt/mqtt_msg.c index 979cedf429..f397569507 100644 --- a/app/mqtt/mqtt_msg.c +++ b/app/mqtt/mqtt_msg.c @@ -29,7 +29,7 @@ * */ -#include "c_string.h" +#include #include "mqtt_msg.h" #define MQTT_MAX_FIXED_HEADER_SIZE 3 @@ -61,7 +61,7 @@ static int append_string(mqtt_connection_t* connection, const char* string, int connection->buffer[connection->message.length++] = len >> 8; connection->buffer[connection->message.length++] = len & 0xff; - c_memcpy(connection->buffer + connection->message.length, string, len); + memcpy(connection->buffer + connection->message.length, string, len); connection->message.length += len; return len + 2; @@ -121,7 +121,7 @@ static mqtt_message_t* fini_message(mqtt_connection_t* connection, int type, int void mqtt_msg_init(mqtt_connection_t* connection, uint8_t* buffer, uint16_t buffer_length) { - c_memset(connection, 0, sizeof(connection)); + memset(connection, 0, sizeof(connection)); connection->buffer = buffer; connection->buffer_length = buffer_length; } @@ -299,7 +299,7 @@ mqtt_message_t* mqtt_msg_connect(mqtt_connection_t* connection, mqtt_connect_inf variable_header->lengthMsb = 0; variable_header->lengthLsb = 4; - c_memcpy(variable_header->magic, "MQTT", 4); + memcpy(variable_header->magic, "MQTT", 4); variable_header->version = 4; variable_header->flags = 0; variable_header->keepaliveMsb = info->keepalive >> 8; @@ -310,7 +310,7 @@ mqtt_message_t* mqtt_msg_connect(mqtt_connection_t* connection, mqtt_connect_inf if(info->client_id != NULL && info->client_id[0] != '\0') { - if(append_string(connection, info->client_id, c_strlen(info->client_id)) < 0) + if(append_string(connection, info->client_id, strlen(info->client_id)) < 0) return fail_message(connection); } else @@ -318,10 +318,10 @@ mqtt_message_t* mqtt_msg_connect(mqtt_connection_t* connection, mqtt_connect_inf if(info->will_topic != NULL && info->will_topic[0] != '\0') { - if(append_string(connection, info->will_topic, c_strlen(info->will_topic)) < 0) + if(append_string(connection, info->will_topic, strlen(info->will_topic)) < 0) return fail_message(connection); - if(append_string(connection, info->will_message, c_strlen(info->will_message)) < 0) + if(append_string(connection, info->will_message, strlen(info->will_message)) < 0) return fail_message(connection); variable_header->flags |= MQTT_CONNECT_FLAG_WILL; @@ -332,7 +332,7 @@ mqtt_message_t* mqtt_msg_connect(mqtt_connection_t* connection, mqtt_connect_inf if(info->username != NULL && info->username[0] != '\0') { - if(append_string(connection, info->username, c_strlen(info->username)) < 0) + if(append_string(connection, info->username, strlen(info->username)) < 0) return fail_message(connection); variable_header->flags |= MQTT_CONNECT_FLAG_USERNAME; @@ -340,7 +340,7 @@ mqtt_message_t* mqtt_msg_connect(mqtt_connection_t* connection, mqtt_connect_inf if(info->password != NULL && info->password[0] != '\0') { - if(append_string(connection, info->password, c_strlen(info->password)) < 0) + if(append_string(connection, info->password, strlen(info->password)) < 0) return fail_message(connection); variable_header->flags |= MQTT_CONNECT_FLAG_PASSWORD; @@ -356,7 +356,7 @@ mqtt_message_t* mqtt_msg_publish(mqtt_connection_t* connection, const char* topi if(topic == NULL || topic[0] == '\0') return fail_message(connection); - if(append_string(connection, topic, c_strlen(topic)) < 0) + if(append_string(connection, topic, strlen(topic)) < 0) return fail_message(connection); if(qos > 0) @@ -369,7 +369,7 @@ mqtt_message_t* mqtt_msg_publish(mqtt_connection_t* connection, const char* topi if(connection->message.length + data_length > connection->buffer_length) return fail_message(connection); - c_memcpy(connection->buffer + connection->message.length, data, data_length); + memcpy(connection->buffer + connection->message.length, data, data_length); connection->message.length += data_length; return fini_message(connection, MQTT_MSG_TYPE_PUBLISH, 0, qos, retain); @@ -422,7 +422,7 @@ mqtt_message_t* mqtt_msg_subscribe_topic(mqtt_connection_t* connection, const ch if(topic == NULL || topic[0] == '\0') return fail_message(connection); - if(append_string(connection, topic, c_strlen(topic)) < 0) + if(append_string(connection, topic, strlen(topic)) < 0) return fail_message(connection); if(connection->message.length + 1 > connection->buffer_length) @@ -462,7 +462,7 @@ mqtt_message_t* mqtt_msg_unsubscribe_topic(mqtt_connection_t* connection, const if(topic == NULL || topic[0] == '\0') return fail_message(connection); - if(append_string(connection, topic, c_strlen(topic)) < 0) + if(append_string(connection, topic, strlen(topic)) < 0) return fail_message(connection); return &connection->message; diff --git a/app/mqtt/msg_queue.c b/app/mqtt/msg_queue.c index 392957ffa9..1b00d5e8b8 100644 --- a/app/mqtt/msg_queue.c +++ b/app/mqtt/msg_queue.c @@ -1,7 +1,8 @@ -#include "c_string.h" -#include "c_stdlib.h" -#include "c_stdio.h" +#include +#include +#include #include "msg_queue.h" +#include "user_config.h" msg_queue_t *msg_enqueue(msg_queue_t **head, mqtt_message_t *msg, uint16_t msg_id, int msg_type, int publish_qos){ if(!head){ @@ -11,19 +12,19 @@ msg_queue_t *msg_enqueue(msg_queue_t **head, mqtt_message_t *msg, uint16_t msg_i NODE_DBG("empty message\n"); return NULL; } - msg_queue_t *node = (msg_queue_t *)c_zalloc(sizeof(msg_queue_t)); + msg_queue_t *node = (msg_queue_t *)calloc(1,sizeof(msg_queue_t)); if(!node){ NODE_DBG("not enough memory\n"); return NULL; } - node->msg.data = (uint8_t *)c_zalloc(msg->length); + node->msg.data = (uint8_t *)calloc(1,msg->length); if(!node->msg.data){ NODE_DBG("not enough memory\n"); - c_free(node); + free(node); return NULL; } - c_memcpy(node->msg.data, msg->data, msg->length); + memcpy(node->msg.data, msg->data, msg->length); node->msg.length = msg->length; node->next = NULL; node->msg_id = msg_id; @@ -43,10 +44,10 @@ msg_queue_t *msg_enqueue(msg_queue_t **head, mqtt_message_t *msg, uint16_t msg_i void msg_destroy(msg_queue_t *node){ if(!node) return; if(node->msg.data){ - c_free(node->msg.data); + free(node->msg.data); node->msg.data = NULL; } - c_free(node); + free(node); } msg_queue_t * msg_dequeue(msg_queue_t **head){ diff --git a/app/net/nodemcu_mdns.c b/app/net/nodemcu_mdns.c index a5eb418289..5750a9b73a 100644 --- a/app/net/nodemcu_mdns.c +++ b/app/net/nodemcu_mdns.c @@ -48,7 +48,7 @@ #include "osapi.h" #include "os_type.h" #include "user_interface.h" -#include "c_string.h" +#include #include "nodemcu_mdns.h" #if 0 @@ -484,7 +484,7 @@ mdns_send_service(struct nodemcu_mdns_info *info, u16_t id, struct ip_addr *dst_ hdr->numextrarr = htons(1); query = (char*) hdr + SIZEOF_DNS_HDR; query_end = (char *) p->payload + p->tot_len; - c_strlcpy(tmpBuf, service_name_with_suffix, sizeof(tmpBuf)); + strlcpy(tmpBuf, service_name_with_suffix, sizeof(tmpBuf)); pHostname = tmpBuf; --pHostname; @@ -618,9 +618,9 @@ mdns_send_service(struct nodemcu_mdns_info *info, u16_t id, struct ip_addr *dst_ ans.type = htons(DNS_RRTYPE_SRV); ans.class = htons(dns_class); ans.ttl = htonl(min(max_ttl, 300)); - c_strlcpy(tmpBuf,ms_info->host_name, sizeof(tmpBuf)); - c_strlcat(tmpBuf, ".", sizeof(tmpBuf)); - c_strlcat(tmpBuf, MDNS_LOCAL, sizeof(tmpBuf)); + strlcpy(tmpBuf,ms_info->host_name, sizeof(tmpBuf)); + strlcat(tmpBuf, ".", sizeof(tmpBuf)); + strlcat(tmpBuf, MDNS_LOCAL, sizeof(tmpBuf)); length = os_strlen(tmpBuf) + MDNS_LENGTH_ADD; ans.len = htons(SIZEOF_MDNS_SERVICE + length); length = 0; @@ -931,9 +931,9 @@ mdns_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, struct ip_addr *addr, actual_rr = DNS_RRTYPE_PTR; } } else { - c_strlcpy(tmpBuf,ms_info->host_name, sizeof(tmpBuf)); - c_strlcat(tmpBuf, ".", sizeof(tmpBuf)); - c_strlcat(tmpBuf, MDNS_LOCAL, sizeof(tmpBuf)); + strlcpy(tmpBuf,ms_info->host_name, sizeof(tmpBuf)); + strlcat(tmpBuf, ".", sizeof(tmpBuf)); + strlcat(tmpBuf, MDNS_LOCAL, sizeof(tmpBuf)); no_rr_name = tmpBuf; if (mdns_compare_name((unsigned char *) tmpBuf, @@ -944,9 +944,9 @@ mdns_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, struct ip_addr *addr, actual_rr = DNS_RRTYPE_A; } } else { - c_strlcpy(tmpBuf,ms_info->host_desc, sizeof(tmpBuf)); - c_strlcat(tmpBuf, ".", sizeof(tmpBuf)); - c_strlcat(tmpBuf, service_name_with_suffix, sizeof(tmpBuf)); + strlcpy(tmpBuf,ms_info->host_desc, sizeof(tmpBuf)); + strlcat(tmpBuf, ".", sizeof(tmpBuf)); + strlcat(tmpBuf, service_name_with_suffix, sizeof(tmpBuf)); if (mdns_compare_name((unsigned char *) tmpBuf, (unsigned char *) qptr, (unsigned char *) hdr) == 0) { if (qry_type == DNS_RRTYPE_TXT || qry_type == DNS_RRTYPE_SRV || qry_type == DNS_RRTYPE_ANY) { @@ -1003,7 +1003,7 @@ mdns_set_servicename(const char *name) { if (service_name_with_suffix) { os_free(service_name_with_suffix); } - service_name_with_suffix = c_strdup(tmpBuf); + service_name_with_suffix = strdup(tmpBuf); } static u8_t reg_counter; @@ -1029,15 +1029,15 @@ mdns_dup_info(const struct nodemcu_mdns_info *info) { // calculate length int len = sizeof(struct nodemcu_mdns_info); - len += c_strlen(info->host_name) + 1; - len += c_strlen(info->host_desc) + 1; - len += c_strlen(info->service_name) + 1; + len += strlen(info->host_name) + 1; + len += strlen(info->host_desc) + 1; + len += strlen(info->service_name) + 1; int i; for (i = 0; i < sizeof(info->txt_data) / sizeof(info->txt_data[0]) && info->txt_data[i]; i++) { - len += c_strlen(info->txt_data[i]) + 1; + len += strlen(info->txt_data[i]) + 1; } -#define COPY_OVER(dest, src, p) len = c_strlen(src) + 1; memcpy(p, src, len); dest = p; p += len +#define COPY_OVER(dest, src, p) len = strlen(src) + 1; memcpy(p, src, len); dest = p; p += len result = (struct nodemcu_mdns_info *) os_zalloc(len); if (result) { diff --git a/app/pcm/drv_sigma_delta.c b/app/pcm/drv_sigma_delta.c index 967df73e5b..0fdfe1f7bd 100644 --- a/app/pcm/drv_sigma_delta.c +++ b/app/pcm/drv_sigma_delta.c @@ -5,7 +5,7 @@ #include "platform.h" #include "hw_timer.h" #include "task/task.h" -#include "c_stdlib.h" +#include #include "pcm.h" diff --git a/app/pcm/pcm_core.c b/app/pcm/pcm_core.c index f489630a3d..0d347dd41f 100644 --- a/app/pcm/pcm_core.c +++ b/app/pcm/pcm_core.c @@ -13,8 +13,8 @@ #include "lauxlib.h" #include "task/task.h" -#include "c_string.h" -#include "c_stdlib.h" +#include +#include #include "pcm.h" @@ -58,9 +58,9 @@ void pcm_data_play( task_param_t param, uint8 prio ) if (lua_type( L, -1 ) == LUA_TSTRING) { data = lua_tolstring( L, -1, &string_len ); if (string_len > buf->buf_size) { - uint8_t *new_data = (uint8_t *) c_malloc( string_len ); + uint8_t *new_data = (uint8_t *) malloc( string_len ); if (new_data) { - if (buf->data) c_free( buf->data ); + if (buf->data) free( buf->data ); buf->buf_size = string_len; buf->data = new_data; } @@ -70,7 +70,7 @@ void pcm_data_play( task_param_t param, uint8 prio ) if (data) { size_t to_copy = string_len > buf->buf_size ? buf->buf_size : string_len; - c_memcpy( buf->data, data, to_copy ); + memcpy( buf->data, data, to_copy ); buf->rpos = 0; buf->len = to_copy; diff --git a/app/platform/common.c b/app/platform/common.c index 7de2a9484a..e047b114ac 100644 --- a/app/platform/common.c +++ b/app/platform/common.c @@ -2,8 +2,8 @@ #include "platform.h" #include "common.h" -#include "c_string.h" -#include "c_stdio.h" +#include +#include void cmn_platform_init(void) { @@ -102,7 +102,7 @@ uint32_t platform_flash_write( const void *from, uint32_t toaddr, uint32_t size { rest = toaddr & blkmask; temp = toaddr & ~blkmask; // this is the actual aligned address - // c_memcpy( tmpdata, ( const void* )temp, blksize ); + // memcpy( tmpdata, ( const void* )temp, blksize ); platform_s_flash_read( tmpdata, temp, blksize ); for( i = rest; size && ( i < blksize ); i ++, size --, pfrom ++ ) tmpdata[ i ] = *pfrom; @@ -125,7 +125,7 @@ uint32_t platform_flash_write( const void *from, uint32_t toaddr, uint32_t size // And the final part of a block if needed if( rest ) { - // c_memcpy( tmpdata, ( const void* )toaddr, blksize ); + // memcpy( tmpdata, ( const void* )toaddr, blksize ); platform_s_flash_read( tmpdata, toaddr, blksize ); for( i = 0; size && ( i < rest ); i ++, size --, pfrom ++ ) tmpdata[ i ] = *pfrom; diff --git a/app/platform/flash_api.c b/app/platform/flash_api.c index fb77d04b09..813be330ef 100644 --- a/app/platform/flash_api.c +++ b/app/platform/flash_api.c @@ -6,7 +6,8 @@ #include "user_config.h" #include "flash_api.h" #include "spi_flash.h" -#include "c_stdio.h" +#include +#include uint32_t flash_detect_size_byte(void) { @@ -25,7 +26,7 @@ uint32_t flash_detect_size_byte(void) dummy_size = FLASH_SIZE_256KBYTE; while ((dummy_size < FLASH_SIZE_16MBYTE) && (SPI_FLASH_RESULT_OK == flash_read(dummy_size, (uint32 *)data_new, FLASH_BUFFER_SIZE_DETECT)) && - (0 != os_memcmp(data_orig, data_new, FLASH_BUFFER_SIZE_DETECT)) + (0 != memcmp(data_orig, data_new, FLASH_BUFFER_SIZE_DETECT)) ) { dummy_size *= 2; diff --git a/app/platform/hw_timer.c b/app/platform/hw_timer.c index 938d18098c..7d1bc744ea 100644 --- a/app/platform/hw_timer.c +++ b/app/platform/hw_timer.c @@ -17,8 +17,8 @@ * a small numeric value that is known not to clash. *******************************************************************************/ #include "platform.h" -#include "c_stdio.h" -#include "c_stdlib.h" +#include +#include #include "ets_sys.h" #include "os_type.h" #include "osapi.h" @@ -444,7 +444,7 @@ bool platform_hw_timer_init(os_param_t owner, FRC1_TIMER_SOURCE_TYPE source_type timer_user *tu = find_tu_and_remove(owner); if (!tu) { - tu = (timer_user *) c_malloc(sizeof(*tu)); + tu = (timer_user *) malloc(sizeof(*tu)); if (!tu) { return false; } diff --git a/app/platform/platform.c b/app/platform/platform.c index 4ad94dade8..a343652cbd 100644 --- a/app/platform/platform.c +++ b/app/platform/platform.c @@ -2,9 +2,9 @@ #include "platform.h" #include "common.h" -#include "c_stdio.h" -#include "c_string.h" -#include "c_stdlib.h" +#include +#include +#include #include "llimits.h" #include "gpio.h" #include "user_interface.h" @@ -320,7 +320,7 @@ int platform_gpio_register_intr_hook(uint32_t bits, platform_hook_function hook) } // These return NULL if the count = 0 so only error check if > 0) - nh.entry = c_malloc( nh.count * sizeof(*(nh.entry)) ); + nh.entry = malloc( nh.count * sizeof(*(nh.entry)) ); if (nh.count && !(nh.entry)) { return 0; // Allocation failure } @@ -345,7 +345,7 @@ int platform_gpio_register_intr_hook(uint32_t bits, platform_hook_function hook) platform_gpio_hook = nh; ETS_GPIO_INTR_ENABLE(); - c_free(oh.entry); + free(oh.entry); return 1; } #endif // GPIO_INTERRUPT_HOOK_ENABLE @@ -865,15 +865,15 @@ uint32_t platform_s_flash_write( const void *from, uint32_t toaddr, uint32_t siz uint32_t *apbuf = NULL; uint32_t fromaddr = (uint32_t)from; if( (fromaddr & blkmask ) || (fromaddr >= INTERNAL_FLASH_MAPPED_ADDRESS)) { - apbuf = (uint32_t *)c_malloc(size); + apbuf = (uint32_t *)malloc(size); if(!apbuf) return 0; - c_memcpy(apbuf, from, size); + memcpy(apbuf, from, size); } system_soft_wdt_feed (); r = flash_write(toaddr, apbuf?(uint32 *)apbuf:(uint32 *)from, size); if(apbuf) - c_free(apbuf); + free(apbuf); if(SPI_FLASH_RESULT_OK == r) return size; else{ @@ -903,10 +903,10 @@ uint32_t platform_s_flash_read( void *to, uint32_t fromaddr, uint32_t size ) r = flash_read(fromaddr, to2, size2); if(SPI_FLASH_RESULT_OK == r) { - c_memmove(to,to2,size2); // This is overlapped so must be memmove and not memcpy + memmove(to,to2,size2); // This is overlapped so must be memmove and not memcpy char back[ INTERNAL_FLASH_READ_UNIT_SIZE ] __attribute__ ((aligned(INTERNAL_FLASH_READ_UNIT_SIZE))); r=flash_read(fromaddr+size2,(uint32*)back,INTERNAL_FLASH_READ_UNIT_SIZE); - c_memcpy((uint8_t*)to+size2,back,INTERNAL_FLASH_READ_UNIT_SIZE); + memcpy((uint8_t*)to+size2,back,INTERNAL_FLASH_READ_UNIT_SIZE); } } else @@ -1022,7 +1022,7 @@ uint32_t platform_rcr_write (uint8_t rec_id, const void *inrec, uint8_t n) { rec[0] = 0; rec[nwords] = 0; ((platform_rcr_t *) rec)->id = rec_id; ((platform_rcr_t *) rec)->len = nwords; - c_memcpy(rec+1, inrec, n); // let memcpy handle 0 and odd byte cases + memcpy(rec+1, inrec, n); // let memcpy handle 0 and odd byte cases // find previous copy if any and exit if the replacement is the same value uint8_t np = platform_rcr_read (rec_id, (void **) &prev); @@ -1063,19 +1063,19 @@ uint32_t platform_rcr_write (uint8_t rec_id, const void *inrec, uint8_t n) { } if (pass == 2) memcpy(buf + l, rec, reclen); l += nwords + 1; - if (pass == 1) buf = c_malloc(l * WORDSIZE); + if (pass == 1) buf = malloc(l * WORDSIZE); if (l >= FLASH_SECTOR_WORDS || !buf) return ~0; } platform_flash_erase_sector(flash_addr/INTERNAL_FLASH_SECTOR_SIZE); platform_s_flash_write(buf, flash_addr, l*WORDSIZE); - c_free(buf); + free(buf); } return nwords*WORDSIZE; } void* platform_print_deprecation_note( const char *msg, const char *time_frame) { - c_printf( "Warning, deprecated API! %s. It will be removed %s. See documentation for details.\n", msg, time_frame ); + printf( "Warning, deprecated API! %s. It will be removed %s. See documentation for details.\n", msg, time_frame ); } diff --git a/app/platform/u8x8_nodemcu_hal.c b/app/platform/u8x8_nodemcu_hal.c index 321a3093bb..82a5a81b12 100644 --- a/app/platform/u8x8_nodemcu_hal.c +++ b/app/platform/u8x8_nodemcu_hal.c @@ -6,7 +6,7 @@ #ifdef LUA_USE_MODULES_U8G2 #include -#include "c_stdlib.h" +#include #include "platform.h" @@ -189,7 +189,7 @@ uint8_t u8x8_byte_nodemcu_i2c(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void * { // the user pointer initially contains the i2c id int id = (int)hal; - if (!(hal = c_malloc( sizeof ( hal_i2c_t ) ))) + if (!(hal = malloc( sizeof ( hal_i2c_t ) ))) return 0; hal->id = id; u8x8->user_ptr = hal; @@ -240,7 +240,7 @@ uint8_t u8x8_byte_nodemcu_spi(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void * // the user pointer initially contains the spi host id int host = (int)hal; - if (!(hal = c_malloc( sizeof ( hal_spi_t ) ))) + if (!(hal = malloc( sizeof ( hal_spi_t ) ))) return 0; hal->host = host; u8x8->user_ptr = hal; @@ -260,7 +260,7 @@ uint8_t u8x8_byte_nodemcu_spi(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void * case U8X8_MSG_BYTE_START_TRANSFER: hal->buffer.size = 256; - if (!(hal->buffer.data = (uint8_t *)c_malloc( hal->buffer.size ))) + if (!(hal->buffer.data = (uint8_t *)malloc( hal->buffer.size ))) return 0; hal->buffer.used = 0; @@ -274,13 +274,13 @@ uint8_t u8x8_byte_nodemcu_spi(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void * while (hal->buffer.size - hal->buffer.used < arg_int) { hal->buffer.size *= 2; uint8_t *tmp; - if (!(tmp = (uint8_t *)c_malloc( hal->buffer.size ))) { - c_free( hal->buffer.data ); + if (!(tmp = (uint8_t *)malloc( hal->buffer.size ))) { + free( hal->buffer.data ); hal->buffer.data = NULL; return 0; } os_memcpy( tmp, hal->buffer.data, hal->buffer.used ); - c_free( hal->buffer.data ); + free( hal->buffer.data ); hal->buffer.data = tmp; } os_memcpy( hal->buffer.data + hal->buffer.used, arg_ptr, arg_int ); @@ -295,7 +295,7 @@ uint8_t u8x8_byte_nodemcu_spi(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void * u8x8_gpio_SetCS( u8x8, u8x8->display_info->chip_disable_level ); - c_free( hal->buffer.data ); + free( hal->buffer.data ); hal->buffer.data = NULL; break; diff --git a/app/platform/ucg_nodemcu_hal.c b/app/platform/ucg_nodemcu_hal.c index f579cc8c5e..a72990f6bd 100644 --- a/app/platform/ucg_nodemcu_hal.c +++ b/app/platform/ucg_nodemcu_hal.c @@ -5,7 +5,7 @@ #ifdef LUA_USE_MODULES_UCG #include -#include "c_stdlib.h" +#include #include "platform.h" diff --git a/app/platform/vfs.c b/app/platform/vfs.c index 76773985ed..035c7f99c6 100644 --- a/app/platform/vfs.c +++ b/app/platform/vfs.c @@ -1,27 +1,28 @@ - - -#include "c_stdlib.h" -#include "c_stdio.h" +#include +#include +#include #include "vfs.h" - +#include "vfs_int.h" #define LDRV_TRAVERSAL 0 +// This interferes with our clearerr member in our ops struct +#undef clearerr // --------------------------------------------------------------------------- // RTC system interface // -static sint32_t (*rtc_cb)( vfs_time *tm ) = NULL; +static int32_t (*rtc_cb)( vfs_time *tm ) = NULL; // called by operating system -void vfs_register_rtc_cb( sint32_t (*cb)( vfs_time *tm ) ) +void vfs_register_rtc_cb( int32_t (*cb)( vfs_time *tm ) ) { // allow NULL pointer to unregister callback function rtc_cb = cb; } // called by file system drivers -sint32_t vfs_get_rtc( vfs_time *tm ) +int32_t vfs_get_rtc( vfs_time *tm ) { if (rtc_cb) { return rtc_cb( tm ); @@ -44,7 +45,7 @@ static const char *normalize_path( const char *path ) const char *temp = path; size_t len; - while ((len = c_strlen( temp )) >= 2) { + while ((len = strlen( temp )) >= 2) { if (temp[0] == '.' && temp[1] == '.') { --dir_level; if (len >= 4 && dir_level > 0) { @@ -88,7 +89,7 @@ vfs_vol *vfs_mount( const char *name, int num ) #ifdef BUILD_FATFS if (fs_fns = myfatfs_realm( normname, &outname, FALSE )) { vfs_vol *r = fs_fns->mount( outname, num ); - c_free( outname ); + free( outname ); return r; } #endif @@ -111,7 +112,7 @@ int vfs_open( const char *name, const char *mode ) #ifdef BUILD_FATFS if (fs_fns = myfatfs_realm( normname, &outname, FALSE )) { int r = (int)fs_fns->open( outname, mode ); - c_free( outname ); + free( outname ); return r; } #endif @@ -134,7 +135,7 @@ vfs_dir *vfs_opendir( const char *name ) #ifdef BUILD_FATFS if (fs_fns = myfatfs_realm( normname, &outname, FALSE )) { vfs_dir *r = fs_fns->opendir( outname ); - c_free( outname ); + free( outname ); return r; } #endif @@ -142,7 +143,7 @@ vfs_dir *vfs_opendir( const char *name ) return NULL; } -sint32_t vfs_stat( const char *name, struct vfs_stat *buf ) +int32_t vfs_stat( const char *name, struct vfs_stat *buf ) { vfs_fs_fns *fs_fns; const char *normname = normalize_path( name ); @@ -156,8 +157,8 @@ sint32_t vfs_stat( const char *name, struct vfs_stat *buf ) #ifdef BUILD_FATFS if (fs_fns = myfatfs_realm( normname, &outname, FALSE )) { - sint32_t r = fs_fns->stat( outname, buf ); - c_free( outname ); + int32_t r = fs_fns->stat( outname, buf ); + free( outname ); return r; } #endif @@ -165,7 +166,7 @@ sint32_t vfs_stat( const char *name, struct vfs_stat *buf ) return VFS_RES_ERR; } -sint32_t vfs_remove( const char *name ) +int32_t vfs_remove( const char *name ) { vfs_fs_fns *fs_fns; const char *normname = normalize_path( name ); @@ -179,8 +180,8 @@ sint32_t vfs_remove( const char *name ) #ifdef BUILD_FATFS if (fs_fns = myfatfs_realm( normname, &outname, FALSE )) { - sint32_t r = fs_fns->remove( outname ); - c_free( outname ); + int32_t r = fs_fns->remove( outname ); + free( outname ); return r; } #endif @@ -188,7 +189,7 @@ sint32_t vfs_remove( const char *name ) return VFS_RES_ERR; } -sint32_t vfs_rename( const char *oldname, const char *newname ) +int32_t vfs_rename( const char *oldname, const char *newname ) { vfs_fs_fns *fs_fns; const char *normoldname = normalize_path( oldname ); @@ -206,19 +207,19 @@ sint32_t vfs_rename( const char *oldname, const char *newname ) #ifdef BUILD_FATFS if (myfatfs_realm( normoldname, &oldoutname, FALSE )) { if (fs_fns = myfatfs_realm( normnewname, &newoutname, FALSE )) { - sint32_t r = fs_fns->rename( oldoutname, newoutname ); - c_free( oldoutname ); - c_free( newoutname ); + int32_t r = fs_fns->rename( oldoutname, newoutname ); + free( oldoutname ); + free( newoutname ); return r; } - c_free( oldoutname ); + free( oldoutname ); } #endif return -1; } -sint32_t vfs_mkdir( const char *name ) +int32_t vfs_mkdir( const char *name ) { vfs_fs_fns *fs_fns; const char *normname = normalize_path( name ); @@ -230,8 +231,8 @@ sint32_t vfs_mkdir( const char *name ) #ifdef BUILD_FATFS if (fs_fns = myfatfs_realm( normname, &outname, FALSE )) { - sint32_t r = fs_fns->mkdir( outname ); - c_free( outname ); + int32_t r = fs_fns->mkdir( outname ); + free( outname ); return r; } #endif @@ -239,7 +240,7 @@ sint32_t vfs_mkdir( const char *name ) return VFS_RES_ERR; } -sint32_t vfs_fsinfo( const char *name, uint32_t *total, uint32_t *used ) +int32_t vfs_fsinfo( const char *name, uint32_t *total, uint32_t *used ) { vfs_fs_fns *fs_fns; char *outname; @@ -256,7 +257,7 @@ sint32_t vfs_fsinfo( const char *name, uint32_t *total, uint32_t *used ) #ifdef BUILD_FATFS if (fs_fns = myfatfs_realm( normname, &outname, FALSE )) { - c_free( outname ); + free( outname ); return fs_fns->fsinfo( total, used ); } #endif @@ -264,7 +265,7 @@ sint32_t vfs_fsinfo( const char *name, uint32_t *total, uint32_t *used ) return VFS_RES_ERR; } -sint32_t vfs_fscfg( const char *name, uint32_t *phys_addr, uint32_t *phys_size) +int32_t vfs_fscfg( const char *name, uint32_t *phys_addr, uint32_t *phys_size) { vfs_fs_fns *fs_fns; char *outname; @@ -283,7 +284,7 @@ sint32_t vfs_fscfg( const char *name, uint32_t *phys_addr, uint32_t *phys_size) return VFS_RES_ERR; } -sint32_t vfs_format( void ) +int32_t vfs_format( void ) { vfs_fs_fns *fs_fns; char *outname; @@ -302,7 +303,7 @@ sint32_t vfs_format( void ) return 0; } -sint32_t vfs_chdir( const char *path ) +int32_t vfs_chdir( const char *path ) { vfs_fs_fns *fs_fns; const char *normpath = normalize_path( path ); @@ -318,9 +319,9 @@ sint32_t vfs_chdir( const char *path ) } else { level = normpath; } - while (c_strlen( level ) > 0) { + while (strlen( level ) > 0) { dir_level++; - if (level = c_strchr( level, '/' )) { + if (level = strchr( level, '/' )) { level++; } else { break; @@ -331,7 +332,7 @@ sint32_t vfs_chdir( const char *path ) #ifdef BUILD_SPIFFS if (fs_fns = myspiffs_realm( normpath, &outname, TRUE )) { // our SPIFFS integration doesn't support directories - if (c_strlen( outname ) == 0) { + if (strlen( outname ) == 0) { ok = VFS_RES_OK; } } @@ -339,7 +340,7 @@ sint32_t vfs_chdir( const char *path ) #ifdef BUILD_FATFS if (fs_fns = myfatfs_realm( normpath, &outname, TRUE )) { - if (c_strchr( outname, ':' )) { + if (strchr( outname, ':' )) { // need to set FatFS' default drive fs_fns->chdrive( outname ); // and force chdir to root in case path points only to root @@ -348,14 +349,14 @@ sint32_t vfs_chdir( const char *path ) if (fs_fns->chdir( outname ) == VFS_RES_OK) { ok = VFS_RES_OK; } - c_free( outname ); + free( outname ); } #endif return ok == VFS_RES_OK ? VFS_RES_OK : VFS_RES_ERR; } -sint32_t vfs_errno( const char *name ) +int32_t vfs_errno( const char *name ) { vfs_fs_fns *fs_fns; char *outname; @@ -372,8 +373,8 @@ sint32_t vfs_errno( const char *name ) #ifdef BUILD_FATFS if (fs_fns = myfatfs_realm( normname, &outname, FALSE )) { - sint32_t r = fs_fns->ferrno( ); - c_free( outname ); + int32_t r = fs_fns->ferrno( ); + free( outname ); return r; } #endif @@ -381,7 +382,7 @@ sint32_t vfs_errno( const char *name ) return VFS_RES_ERR; } -sint32_t vfs_ferrno( int fd ) +int32_t vfs_ferrno( int fd ) { vfs_file *f = (vfs_file *)fd; @@ -400,8 +401,8 @@ sint32_t vfs_ferrno( int fd ) #ifdef BUILD_FATFS if (fs_fns = myfatfs_realm( name, &outname, FALSE )) { - sint32_t r = fs_fns->ferrno( ); - c_free( outname ); + int32_t r = fs_fns->ferrno( ); + free( outname ); return r; } #endif @@ -420,14 +421,14 @@ void vfs_clearerr( const char *name ) #ifdef BUILD_SPIFFS if (fs_fns = myspiffs_realm( normname, &outname, FALSE )) { - fs_fns->clearerr( ); + fs_fns->clearerr ( ); } #endif #ifdef BUILD_FATFS if (fs_fns = myfatfs_realm( normname, &outname, FALSE )) { - fs_fns->clearerr( ); - c_free( outname ); + fs_fns->clearerr ( ); + free( outname ); } #endif } @@ -437,9 +438,9 @@ const char *vfs_basename( const char *path ) const char *basename; // deduce basename (incl. extension) for length check - if (basename = c_strrchr( path, '/' )) { + if (basename = strrchr( path, '/' )) { basename++; - } else if (basename = c_strrchr( path, ':' )) { + } else if (basename = strrchr( path, ':' )) { basename++; } else { basename = path; @@ -455,7 +456,7 @@ const char *vfs_basename( const char *path ) int vfs_getc( int fd ) { unsigned char c = 0xFF; - sint32_t res; + int32_t res; if(!vfs_eof( fd )) { if (1 != vfs_read( fd, &c, 1 )) { diff --git a/app/platform/vfs.h b/app/platform/vfs.h index d0ae29f92e..e9784e9863 100644 --- a/app/platform/vfs.h +++ b/app/platform/vfs.h @@ -15,7 +15,7 @@ // vfs_close - close file descriptor and free memory // fd: file descriptor // Returns: VFS_RES_OK or negative value in case of error -static sint32_t vfs_close( int fd ) { +static int32_t vfs_close( int fd ) { vfs_file *f = (vfs_file *)fd; return f ? f->fns->close( f ) : VFS_RES_ERR; } @@ -25,7 +25,7 @@ static sint32_t vfs_close( int fd ) { // ptr: destination data buffer // len: requested length // Returns: Number of bytes read, or VFS_RES_ERR in case of error -static sint32_t vfs_read( int fd, void *ptr, size_t len ) { +static int32_t vfs_read( int fd, void *ptr, size_t len ) { vfs_file *f = (vfs_file *)fd; return f ? f->fns->read( f, ptr, len ) : VFS_RES_ERR; } @@ -35,7 +35,7 @@ static sint32_t vfs_read( int fd, void *ptr, size_t len ) { // ptr: source data buffer // len: requested length // Returns: Number of bytes written, or VFS_RES_ERR in case of error -static sint32_t vfs_write( int fd, const void *ptr, size_t len ) { +static int32_t vfs_write( int fd, const void *ptr, size_t len ) { vfs_file *f = (vfs_file *)fd; return f ? f->fns->write( f, ptr, len ) : VFS_RES_ERR; } @@ -51,7 +51,7 @@ int vfs_ungetc( int c, int fd ); // VFS_SEEK_CUR - set pointer to current position + off // VFS_SEEK_END - set pointer to end of file + off // Returns: New position, or VFS_RES_ERR in case of error -static sint32_t vfs_lseek( int fd, sint32_t off, int whence ) { +static int32_t vfs_lseek( int fd, int32_t off, int whence ) { vfs_file *f = (vfs_file *)fd; return f ? f->fns->lseek( f, off, whence ) : VFS_RES_ERR; } @@ -59,7 +59,7 @@ static sint32_t vfs_lseek( int fd, sint32_t off, int whence ) { // vfs_eof - test for end-of-file // fd: file descriptor // Returns: 0 if not at end, != 0 if end of file -static sint32_t vfs_eof( int fd ) { +static int32_t vfs_eof( int fd ) { vfs_file *f = (vfs_file *)fd; return f ? f->fns->eof( f ) : VFS_RES_ERR; } @@ -67,7 +67,7 @@ static sint32_t vfs_eof( int fd ) { // vfs_tell - get read/write position // fd: file descriptor // Returns: Current position -static sint32_t vfs_tell( int fd ) { +static int32_t vfs_tell( int fd ) { vfs_file *f = (vfs_file *)fd; return f ? f->fns->tell( f ) : VFS_RES_ERR; } @@ -75,7 +75,7 @@ static sint32_t vfs_tell( int fd ) { // vfs_flush - flush write cache to file // fd: file descriptor // Returns: VFS_RES_OK, or VFS_RES_ERR in case of error -static sint32_t vfs_flush( int fd ) { +static int32_t vfs_flush( int fd ) { vfs_file *f = (vfs_file *)fd; return f ? f->fns->flush( f ) : VFS_RES_ERR; } @@ -91,7 +91,7 @@ static uint32_t vfs_size( int fd ) { // vfs_ferrno - get file system specific errno // fd: file descriptor // Returns: errno -sint32_t vfs_ferrno( int fd ); +int32_t vfs_ferrno( int fd ); // --------------------------------------------------------------------------- // dir functions @@ -100,13 +100,13 @@ sint32_t vfs_ferrno( int fd ); // vfs_closedir - close directory descriptor and free memory // dd: dir descriptor // Returns: VFS_RES_OK, or VFS_RES_ERR in case of error -static sint32_t vfs_closedir( vfs_dir *dd ) { return dd->fns->close( dd ); } +static int32_t vfs_closedir( vfs_dir *dd ) { return dd->fns->close( dd ); } // vfs_readdir - read next directory item // dd: dir descriptor // buf: pre-allocated stat structure to be filled in // Returns: VFS_RES_OK if next item found, otherwise VFS_RES_ERR -static sint32_t vfs_readdir( vfs_dir *dd, struct vfs_stat *buf ) { return dd->fns->readdir( dd, buf ); } +static int32_t vfs_readdir( vfs_dir *dd, struct vfs_stat *buf ) { return dd->fns->readdir( dd, buf ); } // --------------------------------------------------------------------------- // volume functions @@ -115,7 +115,7 @@ static sint32_t vfs_readdir( vfs_dir *dd, struct vfs_stat *buf ) { return dd->fn // vfs_umount - unmount logical drive and free memory // vol: volume object // Returns: VFS_RES_OK, or VFS_RES_ERR in case of error -static sint32_t vfs_umount( vfs_vol *vol ) { return vol->fns->umount( vol ); } +static int32_t vfs_umount( vfs_vol *vol ) { return vol->fns->umount( vol ); } // --------------------------------------------------------------------------- // file system functions @@ -142,56 +142,56 @@ vfs_dir *vfs_opendir( const char *name ); // name: file or directory name // buf: pre-allocated structure to be filled in // Returns: VFS_RES_OK, or VFS_RES_ERR in case of error -sint32_t vfs_stat( const char *name, struct vfs_stat *buf ); +int32_t vfs_stat( const char *name, struct vfs_stat *buf ); // vfs_remove - remove file or directory // name: file or directory name // Returns: VFS_RES_OK, or VFS_RES_ERR in case of error -sint32_t vfs_remove( const char *name ); +int32_t vfs_remove( const char *name ); // vfs_rename - rename file or directory // name: file or directory name // Returns: VFS_RES_OK, or VFS_RES_ERR in case of error -sint32_t vfs_rename( const char *oldname, const char *newname ); +int32_t vfs_rename( const char *oldname, const char *newname ); // vfs_mkdir - create directory // name: directory name // Returns: VFS_RES_OK, or VFS_RES_ERR in case of error -sint32_t vfs_mkdir( const char *name ); +int32_t vfs_mkdir( const char *name ); // vfs_fsinfo - get file system info // name: logical drive identifier // total: receives total amount // used: received used amount // Returns: VFS_RES_OK, or VFS_RES_ERR in case of error -sint32_t vfs_fsinfo( const char *name, uint32_t *total, uint32_t *used ); +int32_t vfs_fsinfo( const char *name, uint32_t *total, uint32_t *used ); // vfs_format - format file system // Returns: 1, or 0 in case of error -sint32_t vfs_format( void ); +int32_t vfs_format( void ); // vfs_chdir - change default directory // path: new default directory // Returns: VFS_RES_OK, or VFS_RES_ERR in case of error -sint32_t vfs_chdir( const char *path ); +int32_t vfs_chdir( const char *path ); // vfs_fscfg - query configuration settings of file system // phys_addr: pointer to store physical address information // phys_size: pointer to store physical size information // Returns: VFS_RES_OK, or VFS_RES_ERR in case of error -sint32_t vfs_fscfg( const char *name, uint32_t *phys_addr, uint32_t *phys_size); +int32_t vfs_fscfg( const char *name, uint32_t *phys_addr, uint32_t *phys_size); // vfs_errno - get file system specific errno // name: logical drive identifier // Returns: errno -sint32_t vfs_errno( const char *name ); +int32_t vfs_errno( const char *name ); // vfs_clearerr - cleaer file system specific errno void vfs_clearerr( const char *name ); // vfs_register_rtc_cb - register callback function for RTC query // cb: pointer to callback function -void vfs_register_rtc_cb( sint32_t (*cb)( vfs_time *tm ) ); +void vfs_register_rtc_cb( int32_t (*cb)( vfs_time *tm ) ); // vfs_basename - identify basename (incl. extension) // path: full file system path diff --git a/app/platform/vfs_int.h b/app/platform/vfs_int.h index f1a0539f2d..3fccd67555 100644 --- a/app/platform/vfs_int.h +++ b/app/platform/vfs_int.h @@ -3,16 +3,10 @@ #ifndef __VFS_INT_H__ #define __VFS_INT_H__ -#include -#include - -#if 0 -#include "spiffs.h" - -#include "fatfs_prefix_lib.h" -#include "ff.h" -#endif +#include +#include +#include "user_config.h" #define VFS_EOF -1 @@ -62,15 +56,15 @@ struct vfs_stat { // file descriptor functions struct vfs_file_fns { - sint32_t (*close)( const struct vfs_file *fd ); - sint32_t (*read)( const struct vfs_file *fd, void *ptr, size_t len ); - sint32_t (*write)( const struct vfs_file *fd, const void *ptr, size_t len ); - sint32_t (*lseek)( const struct vfs_file *fd, sint32_t off, int whence ); - sint32_t (*eof)( const struct vfs_file *fd ); - sint32_t (*tell)( const struct vfs_file *fd ); - sint32_t (*flush)( const struct vfs_file *fd ); + int32_t (*close)( const struct vfs_file *fd ); + int32_t (*read)( const struct vfs_file *fd, void *ptr, size_t len ); + int32_t (*write)( const struct vfs_file *fd, const void *ptr, size_t len ); + int32_t (*lseek)( const struct vfs_file *fd, int32_t off, int whence ); + int32_t (*eof)( const struct vfs_file *fd ); + int32_t (*tell)( const struct vfs_file *fd ); + int32_t (*flush)( const struct vfs_file *fd ); uint32_t (*size)( const struct vfs_file *fd ); - sint32_t (*ferrno)( const struct vfs_file *fd ); + int32_t (*ferrno)( const struct vfs_file *fd ); }; typedef const struct vfs_file_fns vfs_file_fns; @@ -83,8 +77,8 @@ typedef const struct vfs_dir vfs_dir; // dir descriptor functions struct vfs_dir_fns { - sint32_t (*close)( const struct vfs_dir *dd ); - sint32_t (*readdir)( const struct vfs_dir *dd, struct vfs_stat *buf ); + int32_t (*close)( const struct vfs_dir *dd ); + int32_t (*readdir)( const struct vfs_dir *dd, struct vfs_stat *buf ); }; typedef const struct vfs_dir_fns vfs_dir_fns; @@ -97,7 +91,7 @@ typedef const struct vfs_vol vfs_vol; // volume functions struct vfs_vol_fns { - sint32_t (*umount)( const struct vfs_vol *vol ); + int32_t (*umount)( const struct vfs_vol *vol ); }; typedef const struct vfs_vol_fns vfs_vol_fns; @@ -105,17 +99,17 @@ struct vfs_fs_fns { vfs_vol *(*mount)( const char *name, int num ); vfs_file *(*open)( const char *name, const char *mode ); vfs_dir *(*opendir)( const char *name ); - sint32_t (*stat)( const char *name, struct vfs_stat *buf ); - sint32_t (*remove)( const char *name ); - sint32_t (*rename)( const char *oldname, const char *newname ); - sint32_t (*mkdir)( const char *name ); - sint32_t (*fsinfo)( uint32_t *total, uint32_t *used ); - sint32_t (*fscfg)( uint32_t *phys_addr, uint32_t *phys_size ); - sint32_t (*format)( void ); - sint32_t (*chdrive)( const char * ); - sint32_t (*chdir)( const char * ); - sint32_t (*ferrno)( void ); - void (*clearerr)( void ); + int32_t (*stat)( const char *name, struct vfs_stat *buf ); + int32_t (*remove)( const char *name ); + int32_t (*rename)( const char *oldname, const char *newname ); + int32_t (*mkdir)( const char *name ); + int32_t (*fsinfo)( uint32_t *total, uint32_t *used ); + int32_t (*fscfg)( uint32_t *phys_addr, uint32_t *phys_size ); + int32_t (*format)( void ); + int32_t (*chdrive)( const char * ); + int32_t (*chdir)( const char * ); + int32_t (*ferrno)( void ); + void (*clearerr)( void ); }; typedef const struct vfs_fs_fns vfs_fs_fns; @@ -123,6 +117,6 @@ typedef const struct vfs_fs_fns vfs_fs_fns; vfs_fs_fns *myspiffs_realm( const char *inname, char **outname, int set_current_drive ); vfs_fs_fns *myfatfs_realm( const char *inname, char **outname, int set_current_drive ); -sint32_t vfs_get_rtc( vfs_time *tm ); +int32_t vfs_get_rtc( vfs_time *tm ); #endif diff --git a/app/pm/swtimer.c b/app/pm/swtimer.c index 64fbeeb058..0e89a3fd6e 100644 --- a/app/pm/swtimer.c +++ b/app/pm/swtimer.c @@ -37,16 +37,17 @@ * Once there are no more suspended timers, the function returns * * - */#include "module.h" + */ +#include "module.h" #include "lauxlib.h" #include "platform.h" #include "user_interface.h" #include "user_modules.h" -#include "c_string.h" -#include "c_stdlib.h" -#include "ctype.h" +#include +#include +#include #include "c_types.h" @@ -138,7 +139,7 @@ void swtmr_suspend_timers(){ size_t registered_cb_qty = lua_objlen(L, -1); //allocate a temporary array to hold the list of callback pointers - cb_registry_item_t** cb_reg_array = c_zalloc(sizeof(cb_registry_item_t*)*registered_cb_qty); + cb_registry_item_t** cb_reg_array = calloc(1,sizeof(cb_registry_item_t*)*registered_cb_qty); if(!cb_reg_array){ luaL_error(L, "%s: unable to suspend timers, out of memory!", __func__); return; @@ -242,7 +243,7 @@ void swtmr_suspend_timers(){ } //tmr_cb_ptr_array is no longer needed. - c_free(cb_reg_array); + free(cb_reg_array); //add suspended_timer_list pointer to swtimer table. lua_pushstring(L, SUSP_LIST_STR); @@ -391,7 +392,7 @@ void swtmr_cb_register(void* timer_cb_ptr, uint8 suspend_policy){ static void add_to_reg_queue(void* timer_cb_ptr, uint8 suspend_policy){ if(!timer_cb_ptr) return; - tmr_cb_queue_t* queue_temp = c_zalloc(sizeof(tmr_cb_queue_t)); + tmr_cb_queue_t* queue_temp = calloc(1,sizeof(tmr_cb_queue_t)); if(!queue_temp){ //it's boot time currently and we're already out of memory, something is very wrong... dbg_printf("\n\t%s:out of memory, rebooting.", __FUNCTION__); @@ -430,7 +431,7 @@ static void process_cb_register_queue(task_param_t param, uint8 priority) void* cb_ptr_tmp = register_queue_ptr->tmr_cb_ptr; swtmr_cb_register(cb_ptr_tmp, register_queue_ptr->suspend_policy); register_queue = register_queue->next; - c_free(register_queue_ptr); + free(register_queue_ptr); } return; } @@ -457,7 +458,7 @@ int print_timer_list(lua_State* L){ } lua_pop(L, 1); size_t registered_cb_qty = lua_objlen(L, -1); - cb_registry_item_t** cb_reg_array = c_zalloc(sizeof(cb_registry_item_t*)*registered_cb_qty); + cb_registry_item_t** cb_reg_array = calloc(1,sizeof(cb_registry_item_t*)*registered_cb_qty); if(!cb_reg_array){ luaL_error(L, "%s: unable to suspend timers, out of memory!", __func__); return 0; @@ -490,7 +491,7 @@ int print_timer_list(lua_State* L){ timer_list_ptr = timer_list_ptr->timer_next; } - c_free(cb_reg_array); + free(cb_reg_array); lua_pop(L, 1); return 0; diff --git a/app/sjson/memcompat.h b/app/sjson/memcompat.h index 2e3f84fb39..7112e2010c 100644 --- a/app/sjson/memcompat.h +++ b/app/sjson/memcompat.h @@ -4,8 +4,4 @@ #include "c_types.h" #include "mem.h" -static inline void *malloc(size_t sz) { return os_malloc(sz); } -static inline void free(void *p) { return os_free(p); } -static inline void *calloc(size_t n, size_t sz) { return os_zalloc(n*sz); } - #endif diff --git a/app/smart/smart.c b/app/smart/smart.c index 18af2a8667..77b2cdf87d 100644 --- a/app/smart/smart.c +++ b/app/smart/smart.c @@ -1,6 +1,6 @@ -#include "c_stdio.h" -#include "c_stdlib.h" -#include "c_string.h" +#include +#include +#include #include "user_interface.h" #include "smart.h" #include "pm/swtimer.h" @@ -39,7 +39,7 @@ int smart_check(uint8_t *nibble, uint16_t len, uint8_t *dst, uint8_t *got){ uint16_t dst_len = len/NIBBLE_PER_BYTE; uint16_t byte_num = 0, bit_num = 0; int i = 0, res = 1; // assume ok. - c_memset(dst,0,dst_len); + memset(dst,0,dst_len); if(NIBBLE_PER_BYTE==1){ for(i=0;ibase_len == am[i]->flag[0]) // store new source-dest adress pair to the map until flag[0] is got { // BSSID, SA, DA, store the SA, DA - c_memcpy(am[i]->addr, &buf[ADDR_MATCH_START], ADDR_MATCH_LENGTH); + memcpy(am[i]->addr, &buf[ADDR_MATCH_START], ADDR_MATCH_LENGTH); am[i]->flag_match_num++; // =1 am[i]->cur_base_seq = seq; // assume the first seq is found am[i]->base_seq_valid = 1; @@ -169,7 +169,7 @@ void detect(uint8 *arg, uint16 len){ } break; // break any way for the next packet to come } - else if(0 == c_memcmp(am[i]->addr, &buf[ADDR_MATCH_START], ADDR_MATCH_LENGTH)){ // source-dest adress pair match + else if(0 == memcmp(am[i]->addr, &buf[ADDR_MATCH_START], ADDR_MATCH_LENGTH)){ // source-dest adress pair match if(am[i]->base_seq_valid == 0){ if ( len - am[i]->base_len == am[i]->flag[0]) { // found the new flag[0] // here flag_match_num is already = 1 @@ -236,7 +236,7 @@ void detect(uint8 *arg, uint16 len){ // break out, or loop done. goto end; } else { // cur_base_seq is ref to SSID_FLAG when patern is alread found - if(0 != c_memcmp(matched->addr, &buf[ADDR_MATCH_START], ADDR_MATCH_LENGTH)){ // source-dest adress pair not match, ignore it + if(0 != memcmp(matched->addr, &buf[ADDR_MATCH_START], ADDR_MATCH_LENGTH)){ // source-dest adress pair not match, ignore it return; } if (matched->base_seq_valid == 0){ // SSID_FLAG seq invalid, need to find the next valid seq number @@ -455,7 +455,7 @@ void reset_map(smart_addr_map **am, size_t num){ am[i]->base_seq_valid = 0; am[i]->ssid_len = 0; am[i]->pwd_len = 0; - c_memset(am[i]->addr, 0, ADDR_MATCH_LENGTH); + memset(am[i]->addr, 0, ADDR_MATCH_LENGTH); if(SEP_1_INDEX==0){ am[i]->flag[0] = SEP_1; am[i]->flag[1] = SEP_2; @@ -511,34 +511,34 @@ void smart_end(){ for (i = 0; i < ADDR_MAP_NUM; ++i) { if(am[i]){ - c_free(am[i]); + free(am[i]); am[i] = NULL; } matched = NULL; } if(sta_conf){ - c_free(sta_conf); + free(sta_conf); sta_conf = NULL; } if(got_password){ - c_free(got_password); + free(got_password); got_password = NULL; } if(got_ssid){ - c_free(got_ssid); + free(got_ssid); got_ssid = NULL; } if(password_nibble){ - c_free(password_nibble); + free(password_nibble); password_nibble = NULL; } if(ssid_nibble){ - c_free(ssid_nibble); + free(ssid_nibble); ssid_nibble = NULL; } // system_restart(); // restart to enable the mode @@ -583,14 +583,14 @@ void smart_next_channel(){ NODE_ERR("switch to channel %d\n", cur_channel); wifi_set_channel(cur_channel); reset_map(am, ADDR_MAP_NUM); - c_memset(sta_conf->ssid, 0, sizeof(sta_conf->ssid)); - c_memset(sta_conf->password, 0, sizeof(sta_conf->password)); + memset(sta_conf->ssid, 0, sizeof(sta_conf->ssid)); + memset(sta_conf->password, 0, sizeof(sta_conf->password)); - c_memset(got_ssid, 0, SSID_BIT_MAX); - c_memset(got_password, 0, PWD_BIT_MAX); + memset(got_ssid, 0, SSID_BIT_MAX); + memset(got_password, 0, PWD_BIT_MAX); - c_memset(ssid_nibble, 0, SSID_NIBBLE_MAX); - c_memset(password_nibble, 0, PWD_NIBBLE_MAX); + memset(ssid_nibble, 0, SSID_NIBBLE_MAX); + memset(password_nibble, 0, PWD_NIBBLE_MAX); os_timer_disarm(&smart_timer); os_timer_arm(&smart_timer, TIME_OUT_PER_CHANNEL, 0); // no repeat @@ -604,7 +604,7 @@ void smart_begin(int chnl, smart_succeed s, void *arg){ for (i = 0; i < ADDR_MAP_NUM; ++i) { if(!am[i]){ - am[i] = (smart_addr_map*)c_zalloc(sizeof(smart_addr_map)); + am[i] = (smart_addr_map*)calloc(1,sizeof(smart_addr_map)); if(!am[i]){ NODE_DBG("smart_begin map no memory\n"); smart_end(); @@ -613,7 +613,7 @@ void smart_begin(int chnl, smart_succeed s, void *arg){ } } if(!sta_conf){ - sta_conf = (struct station_config *)c_zalloc(sizeof(struct station_config)); + sta_conf = (struct station_config *)calloc(1,sizeof(struct station_config)); if(!sta_conf){ NODE_DBG("smart_begin sta_conf no memory\n"); smart_end(); @@ -622,7 +622,7 @@ void smart_begin(int chnl, smart_succeed s, void *arg){ } if(!ssid_nibble){ - ssid_nibble = (uint8_t *)c_zalloc(SSID_NIBBLE_MAX); + ssid_nibble = (uint8_t *)calloc(1,SSID_NIBBLE_MAX); if(!ssid_nibble){ NODE_DBG("smart_begin sta_conf no memory\n"); smart_end(); @@ -631,7 +631,7 @@ void smart_begin(int chnl, smart_succeed s, void *arg){ } if(!password_nibble){ - password_nibble = (uint8_t *)c_zalloc(PWD_NIBBLE_MAX); + password_nibble = (uint8_t *)calloc(1,PWD_NIBBLE_MAX); if(!password_nibble){ NODE_DBG("smart_begin sta_conf no memory\n"); smart_end(); @@ -640,7 +640,7 @@ void smart_begin(int chnl, smart_succeed s, void *arg){ } if(!got_ssid){ - got_ssid = (uint8_t *)c_zalloc(SSID_BIT_MAX); + got_ssid = (uint8_t *)calloc(1,SSID_BIT_MAX); if(!got_ssid){ NODE_DBG("smart_begin sta_conf no memory\n"); smart_end(); @@ -649,7 +649,7 @@ void smart_begin(int chnl, smart_succeed s, void *arg){ } if(!got_password){ - got_password = (uint8_t *)c_zalloc(PWD_BIT_MAX); + got_password = (uint8_t *)calloc(1,PWD_BIT_MAX); if(!got_password){ NODE_DBG("smart_begin sta_conf no memory\n"); smart_end(); @@ -657,14 +657,14 @@ void smart_begin(int chnl, smart_succeed s, void *arg){ } } reset_map(am, ADDR_MAP_NUM); - // c_memset(sta_conf->ssid, 0, sizeof(sta_conf->ssid)); - // c_memset(sta_conf->password, 0, sizeof(sta_conf->password)); + // memset(sta_conf->ssid, 0, sizeof(sta_conf->ssid)); + // memset(sta_conf->password, 0, sizeof(sta_conf->password)); - // c_memset(got_ssid, 0, SSID_BIT_MAX); - // c_memset(got_password, 0, PWD_BIT_MAX); + // memset(got_ssid, 0, SSID_BIT_MAX); + // memset(got_password, 0, PWD_BIT_MAX); - // c_memset(ssid_nibble, 0, SSID_NIBBLE_MAX); - // c_memset(password_nibble, 0, PWD_NIBBLE_MAX); + // memset(ssid_nibble, 0, SSID_NIBBLE_MAX); + // memset(password_nibble, 0, PWD_NIBBLE_MAX); mode = wifi_get_opmode(); if( (STATION_MODE == mode) || (mode == STATIONAP_MODE) ){ wifi_station_set_auto_connect(false); diff --git a/app/spiffs/Makefile b/app/spiffs/Makefile index 2b1af59f16..688bc9f35c 100644 --- a/app/spiffs/Makefile +++ b/app/spiffs/Makefile @@ -22,7 +22,6 @@ endif # makefile at its root level - these are then overridden # for a subtree within the makefile rooted therein # -DEFINES += -Dprintf=c_printf #DEFINES += -DDEVELOPMENT_TOOLS -DNODE_DEBUG -DSPIFFS_API_DBG=NODE_DBG ############################################################# diff --git a/app/spiffs/nodemcu_spiffs.h b/app/spiffs/nodemcu_spiffs.h index e4026d623b..3a8b2c453e 100644 --- a/app/spiffs/nodemcu_spiffs.h +++ b/app/spiffs/nodemcu_spiffs.h @@ -2,11 +2,10 @@ #define _NODEMCU_SPIFFS_H #ifndef NODEMCU_SPIFFS_NO_INCLUDE -#include "c_stdint.h" -#include "c_stddef.h" -#include "c_stdio.h" +#include +#include +#include #include "user_interface.h" -typedef uint32_t intptr_t; #endif // Turn off stats diff --git a/app/spiffs/spiffs.c b/app/spiffs/spiffs.c index 1809b0f361..57f15a27ca 100644 --- a/app/spiffs/spiffs.c +++ b/app/spiffs/spiffs.c @@ -1,4 +1,4 @@ -#include "c_stdio.h" +#include #include "platform.h" #include "spiffs.h" @@ -170,7 +170,7 @@ int myspiffs_format( void ) // vfs API // *************************************************************************** -#include +#include #include "vfs_int.h" #define MY_LDRV_ID "FLASH" @@ -281,7 +281,7 @@ static sint32_t myspiffs_vfs_closedir( const struct vfs_dir *dd ) { sint32_t res = SPIFFS_closedir( d ); // free descriptor memory - c_free( (void *)dd ); + free( (void *)dd ); } static sint32_t myspiffs_vfs_readdir( const struct vfs_dir *dd, struct vfs_stat *buf ) { @@ -289,11 +289,11 @@ static sint32_t myspiffs_vfs_readdir( const struct vfs_dir *dd, struct vfs_stat struct spiffs_dirent dirent; if (SPIFFS_readdir( d, &dirent )) { - c_memset( buf, 0, sizeof( struct vfs_stat ) ); + memset( buf, 0, sizeof( struct vfs_stat ) ); // copy entries to item // fill in supported stat entries - c_strncpy( buf->name, dirent.name, FS_OBJ_NAME_LEN+1 ); + strncpy( buf->name, dirent.name, FS_OBJ_NAME_LEN+1 ); buf->name[FS_OBJ_NAME_LEN] = '\0'; buf->size = dirent.size; return VFS_RES_OK; @@ -316,7 +316,7 @@ static sint32_t myspiffs_vfs_close( const struct vfs_file *fd ) { sint32_t res = SPIFFS_close( &fs, fh ); // free descriptor memory - c_free( (void *)fd ); + free( (void *)fd ); return res; } @@ -392,21 +392,21 @@ static sint32_t myspiffs_vfs_ferrno( const struct vfs_file *fd ) { static int fs_mode2flag(const char *mode){ - if(c_strlen(mode)==1){ - if(c_strcmp(mode,"w")==0) + if(strlen(mode)==1){ + if(strcmp(mode,"w")==0) return SPIFFS_WRONLY|SPIFFS_CREAT|SPIFFS_TRUNC; - else if(c_strcmp(mode, "r")==0) + else if(strcmp(mode, "r")==0) return SPIFFS_RDONLY; - else if(c_strcmp(mode, "a")==0) + else if(strcmp(mode, "a")==0) return SPIFFS_WRONLY|SPIFFS_CREAT|SPIFFS_APPEND; else return SPIFFS_RDONLY; - } else if (c_strlen(mode)==2){ - if(c_strcmp(mode,"r+")==0) + } else if (strlen(mode)==2){ + if(strcmp(mode,"r+")==0) return SPIFFS_RDWR; - else if(c_strcmp(mode, "w+")==0) + else if(strcmp(mode, "w+")==0) return SPIFFS_RDWR|SPIFFS_CREAT|SPIFFS_TRUNC; - else if(c_strcmp(mode, "a+")==0) + else if(strcmp(mode, "a+")==0) return SPIFFS_RDWR|SPIFFS_CREAT|SPIFFS_APPEND; else return SPIFFS_RDONLY; @@ -422,13 +422,13 @@ static vfs_file *myspiffs_vfs_open( const char *name, const char *mode ) { struct myvfs_file *fd; int flags = fs_mode2flag( mode ); - if (fd = (struct myvfs_file *)c_malloc( sizeof( struct myvfs_file ) )) { + if (fd = (struct myvfs_file *)malloc( sizeof( struct myvfs_file ) )) { if (0 < (fd->fh = SPIFFS_open( &fs, name, flags, 0 ))) { fd->vfs_file.fs_type = VFS_FS_SPIFFS; fd->vfs_file.fns = &myspiffs_file_fns; return (vfs_file *)fd; } else { - c_free( fd ); + free( fd ); } } @@ -438,13 +438,13 @@ static vfs_file *myspiffs_vfs_open( const char *name, const char *mode ) { static vfs_dir *myspiffs_vfs_opendir( const char *name ){ struct myvfs_dir *dd; - if (dd = (struct myvfs_dir *)c_malloc( sizeof( struct myvfs_dir ) )) { + if (dd = (struct myvfs_dir *)malloc( sizeof( struct myvfs_dir ) )) { if (SPIFFS_opendir( &fs, name, &(dd->d) )) { dd->vfs_dir.fs_type = VFS_FS_SPIFFS; dd->vfs_dir.fns = &myspiffs_dd_fns; return (vfs_dir *)dd; } else { - c_free( dd ); + free( dd ); } } @@ -455,10 +455,10 @@ static sint32_t myspiffs_vfs_stat( const char *name, struct vfs_stat *buf ) { spiffs_stat stat; if (0 <= SPIFFS_stat( &fs, name, &stat )) { - c_memset( buf, 0, sizeof( struct vfs_stat ) ); + memset( buf, 0, sizeof( struct vfs_stat ) ); // fill in supported stat entries - c_strncpy( buf->name, stat.name, FS_OBJ_NAME_LEN+1 ); + strncpy( buf->name, stat.name, FS_OBJ_NAME_LEN+1 ); buf->name[FS_OBJ_NAME_LEN] = '\0'; buf->size = stat.size; @@ -511,7 +511,7 @@ static void myspiffs_vfs_clearerr( void ) { vfs_fs_fns *myspiffs_realm( const char *inname, char **outname, int set_current_drive ) { if (inname[0] == '/') { // logical drive is specified, check if it's our id - if (0 == c_strncmp(inname + 1, MY_LDRV_ID, sizeof(MY_LDRV_ID)-1)) { + if (0 == strncmp(inname + 1, MY_LDRV_ID, sizeof(MY_LDRV_ID)-1)) { *outname = (char *)(inname + sizeof(MY_LDRV_ID)); if (*outname[0] == '/') { // skip leading / diff --git a/app/sqlite3/esp8266.c b/app/sqlite3/esp8266.c index 9980916744..1cd8f1da55 100644 --- a/app/sqlite3/esp8266.c +++ b/app/sqlite3/esp8266.c @@ -7,10 +7,10 @@ * http://www.sqlite.org/src/doc/trunk/src/test_vfs.c **/ -#include -#include -#include -#include +#include +#include +#include +#include "c_types.h" #include #include #include diff --git a/app/sqlite3/sqlite3.c b/app/sqlite3/sqlite3.c index 0f550abfc9..8cfe9305cb 100644 --- a/app/sqlite3/sqlite3.c +++ b/app/sqlite3/sqlite3.c @@ -11017,7 +11017,7 @@ struct fts5_api { ** Include standard header files as necessary */ #ifdef HAVE_STDINT_H -#include +#include #endif #ifdef HAVE_INTTYPES_H #include @@ -11608,9 +11608,9 @@ SQLITE_PRIVATE void sqlite3HashClear(Hash*); /************** End of parse.h ***********************************************/ /************** Continuing where we left off in sqliteInt.h ******************/ -#include -#include -#include +#include +#include +#include #include #include @@ -12585,7 +12585,7 @@ SQLITE_PRIVATE int sqlite3SchemaMutexHeld(sqlite3*,int,Schema*); */ #ifndef SQLITE_VDBE_H #define SQLITE_VDBE_H -/* #include */ +/* #include */ /* ** A single VDBE is an opaque structure named "Vdbe". Only routines @@ -18868,7 +18868,7 @@ SQLITE_API int sqlite3_db_status( ** Richmond, Virginia (USA) */ /* #include "sqliteInt.h" */ -/* #include */ +/* #include */ /* #include */ #include @@ -20978,7 +20978,7 @@ SQLITE_PRIVATE void sqlite3MemSetDefault(void){ # define backtrace(A,B) 1 # define backtrace_symbols_fd(A,B,C) #endif -/* #include */ +/* #include */ /* ** Each memory allocation looks like this: diff --git a/app/task/task.c b/app/task/task.c index 5d68c76e7b..e9bc9ef630 100644 --- a/app/task/task.c +++ b/app/task/task.c @@ -3,7 +3,7 @@ */ #include "task/task.h" #include "mem.h" -#include "c_stdio.h" +#include #define TASK_HANDLE_MONIKER 0x68680000 #define TASK_HANDLE_MASK 0xFFF80000 diff --git a/app/u8g2lib/u8x8_d_fbrle.c b/app/u8g2lib/u8x8_d_fbrle.c index 93875513df..8dd743601d 100644 --- a/app/u8g2lib/u8x8_d_fbrle.c +++ b/app/u8g2lib/u8x8_d_fbrle.c @@ -6,7 +6,7 @@ #include "u8x8_nodemcu_hal.h" -#include "c_stdlib.h" +#include static const u8x8_display_info_t u8x8_fbrle_display_info = @@ -104,7 +104,7 @@ static uint8_t u8x8_d_fbrle(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *ar uint8_t *buf = ((u8x8_tile_t *)arg_ptr)->tile_ptr; struct fbrle_line *fbrle_line; - if (!(fbrle_line = (struct fbrle_line *)c_malloc( fbrle_line_size ))) { + if (!(fbrle_line = (struct fbrle_line *)malloc( fbrle_line_size ))) { break; } @@ -147,7 +147,7 @@ static uint8_t u8x8_d_fbrle(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *ar } } - c_free( fbrle_line ); + free( fbrle_line ); } break; diff --git a/app/libc/dbg_printf.c b/app/user/dbg_printf.c similarity index 98% rename from app/libc/dbg_printf.c rename to app/user/dbg_printf.c index 0772b69625..6dcb5895c7 100644 --- a/app/libc/dbg_printf.c +++ b/app/user/dbg_printf.c @@ -39,9 +39,9 @@ // overflows. The downside is that it does not implement a wide range // of formatting characters. -#include -#include -#include +#include +#include +#include #include "driver/uart.h" static void kprintn (void (*)(const char), uint32_t, int, int, char); diff --git a/app/user/user_main.c b/app/user/user_main.c index 008e384b3a..9afb1fb8d1 100644 --- a/app/user/user_main.c +++ b/app/user/user_main.c @@ -10,9 +10,9 @@ *******************************************************************************/ #include "lua.h" #include "platform.h" -#include "c_string.h" -#include "c_stdlib.h" -#include "c_stdio.h" +#include +#include +#include #include "vfs.h" #include "flash_api.h" #include "user_interface.h" diff --git a/app/uzlib/uzlib.h b/app/uzlib/uzlib.h index ae9c99ac02..0627f44e7e 100644 --- a/app/uzlib/uzlib.h +++ b/app/uzlib/uzlib.h @@ -12,21 +12,20 @@ #define UZLIB_INFLATE_H #include +#include +#include + +#define uz_malloc malloc +#define uz_free free #if defined(__XTENSA__) -#include "c_stdint.h" #include "mem.h" #define UZLIB_THROW(v) longjmp(unwindAddr, (v)) #define UZLIB_SETJMP setjmp -#define uz_malloc os_malloc -#define uz_free os_free #else /* Host */ -#include -#include - extern int dbg_break(void); #if defined(_MSC_VER) || defined(__MINGW32__) //msvc requires old name for longjmp #define UZLIB_THROW(v) {dbg_break();longjmp(unwindAddr, (v));} @@ -36,9 +35,6 @@ extern int dbg_break(void); #define UZLIB_SETJMP(n) _setjmp(n) #endif -#define uz_malloc malloc -#define uz_free free - #endif /* defined(__XTENSA__) */ extern jmp_buf unwindAddr; diff --git a/app/uzlib/uzlib_inflate.c b/app/uzlib/uzlib_inflate.c index 394560532b..a3eec362c0 100644 --- a/app/uzlib/uzlib_inflate.c +++ b/app/uzlib/uzlib_inflate.c @@ -39,11 +39,7 @@ */ #include -#ifdef __XTENSA__ -#include "c_stdio.h" -#else #include -#endif #include "uzlib.h" diff --git a/app/websocket/websocketclient.c b/app/websocket/websocketclient.c index 8a4bbd6925..b96e47269d 100644 --- a/app/websocket/websocketclient.c +++ b/app/websocket/websocketclient.c @@ -30,9 +30,9 @@ #include "stdlib.h" #include "c_types.h" -#include "c_string.h" -#include "c_stdlib.h" -#include "c_stdio.h" +#include +#include +#include #include "websocketclient.h" @@ -83,7 +83,7 @@ static char *cryptoSha1(char *data, unsigned int len) { SHA1Init(&ctx); SHA1Update(&ctx, data, len); - uint8_t *digest = (uint8_t *) c_zalloc(20); + uint8_t *digest = (uint8_t *) calloc(1,20); SHA1Final(digest, &ctx); return (char *) digest; // Requires free } @@ -93,7 +93,7 @@ static const char *bytes64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwx static char *base64Encode(char *data, unsigned int len) { int blen = (len + 2) / 3 * 4; - char *out = (char *) c_zalloc(blen + 1); + char *out = (char *) calloc(1,blen + 1); out[blen] = '\0'; int j = 0, i; for (i = 0; i < len; i += 3) { @@ -197,7 +197,7 @@ static void ws_sendFrame(struct espconn *conn, int opCode, const char *data, uns return; } - char *b = c_zalloc(10 + len); // 10 bytes = worst case scenario for framming + char *b = calloc(1,10 + len); // 10 bytes = worst case scenario for framming if (b == NULL) { NODE_DBG("Out of memory when receiving message, disconnecting...\n"); @@ -301,7 +301,7 @@ static void ws_receiveCallback(void *arg, char *buf, unsigned short len) { if (ws->frameBuffer != NULL) { // Append previous frameBuffer with new content NODE_DBG("Appending new frameBuffer to old one \n"); - ws->frameBuffer = c_realloc(ws->frameBuffer, ws->frameBufferLen + len); + ws->frameBuffer = realloc(ws->frameBuffer, ws->frameBufferLen + len); if (ws->frameBuffer == NULL) { NODE_DBG("Failed to allocate new framebuffer, disconnecting...\n"); @@ -358,7 +358,7 @@ static void ws_receiveCallback(void *arg, char *buf, unsigned short len) { NODE_DBG("INCOMPLETE Frame \n"); if (ws->frameBuffer == NULL) { NODE_DBG("Allocing new frameBuffer \n"); - ws->frameBuffer = c_zalloc(len); + ws->frameBuffer = calloc(1,len); if (ws->frameBuffer == NULL) { NODE_DBG("Failed to allocate framebuffer, disconnecting... \n"); @@ -379,7 +379,7 @@ static void ws_receiveCallback(void *arg, char *buf, unsigned short len) { NODE_DBG("PARTIAL frame! Should concat payload and later restore opcode\n"); if(ws->payloadBuffer == NULL) { NODE_DBG("Allocing new payloadBuffer \n"); - ws->payloadBuffer = c_zalloc(payloadLength); + ws->payloadBuffer = calloc(1,payloadLength); if (ws->payloadBuffer == NULL) { NODE_DBG("Failed to allocate payloadBuffer, disconnecting...\n"); @@ -395,7 +395,7 @@ static void ws_receiveCallback(void *arg, char *buf, unsigned short len) { ws->payloadOriginalOpCode = opCode; } else { NODE_DBG("Appending new payloadBuffer to old one \n"); - ws->payloadBuffer = c_realloc(ws->payloadBuffer, ws->payloadBufferLen + payloadLength); + ws->payloadBuffer = realloc(ws->payloadBuffer, ws->payloadBufferLen + payloadLength); if (ws->payloadBuffer == NULL) { NODE_DBG("Failed to allocate new framebuffer, disconnecting...\n"); @@ -425,7 +425,7 @@ static void ws_receiveCallback(void *arg, char *buf, unsigned short len) { return; } // concat buffer with payload - payload = c_zalloc(ws->payloadBufferLen + payloadLength); + payload = calloc(1,ws->payloadBufferLen + payloadLength); if (payload == NULL) { NODE_DBG("Failed to allocate new framebuffer, disconnecting...\n"); @@ -457,7 +457,7 @@ static void ws_receiveCallback(void *arg, char *buf, unsigned short len) { extensionDataOffset += 2; } - payload = c_zalloc(payloadLength - extensionDataOffset + 1); + payload = calloc(1,payloadLength - extensionDataOffset + 1); if (payload == NULL) { NODE_DBG("Failed to allocate payload, disconnecting...\n"); @@ -511,7 +511,7 @@ static void ws_receiveCallback(void *arg, char *buf, unsigned short len) { if (ws->frameBuffer != NULL) { NODE_DBG("Reallocing frameBuffer to remove consumed frame\n"); - ws->frameBuffer = c_realloc(ws->frameBuffer, ws->frameBufferLen + len); + ws->frameBuffer = realloc(ws->frameBuffer, ws->frameBufferLen + len); if (ws->frameBuffer == NULL) { NODE_DBG("Failed to allocate new frame buffer, disconnecting...\n"); @@ -738,12 +738,12 @@ void ws_connect(ws_info *ws, const char *url) { } // Extract protocol - either ws or wss - bool isSecure = c_strncasecmp(url, PROTOCOL_SECURE, strlen(PROTOCOL_SECURE)) == 0; + bool isSecure = strncasecmp(url, PROTOCOL_SECURE, strlen(PROTOCOL_SECURE)) == 0; if (isSecure) { url += strlen(PROTOCOL_SECURE); } else { - if (c_strncasecmp(url, PROTOCOL_INSECURE, strlen(PROTOCOL_INSECURE)) != 0) { + if (strncasecmp(url, PROTOCOL_INSECURE, strlen(PROTOCOL_INSECURE)) != 0) { NODE_DBG("Failed to extract protocol from: %s\n", url); if (ws->onFailure) ws->onFailure(ws, -1); return; @@ -752,7 +752,7 @@ void ws_connect(ws_info *ws, const char *url) { } // Extract path - it should start with '/' - char *path = c_strchr(url, '/'); + char *path = strchr(url, '/'); // Extract hostname, possibly including port char hostname[256]; @@ -800,9 +800,9 @@ void ws_connect(ws_info *ws, const char *url) { // Prepare internal ws_info ws->connectionState = 1; ws->isSecure = isSecure; - ws->hostname = c_strdup(hostname); + ws->hostname = strdup(hostname); ws->port = port; - ws->path = c_strdup(path); + ws->path = strdup(path); ws->expectedSecKey = NULL; ws->knownFailureCode = 0; ws->frameBuffer = NULL; @@ -813,10 +813,10 @@ void ws_connect(ws_info *ws, const char *url) { ws->unhealthyPoints = 0; // Prepare espconn - struct espconn *conn = (struct espconn *) c_zalloc(sizeof(struct espconn)); + struct espconn *conn = (struct espconn *) calloc(1,sizeof(struct espconn)); conn->type = ESPCONN_TCP; conn->state = ESPCONN_NONE; - conn->proto.tcp = (esp_tcp *) c_zalloc(sizeof(esp_tcp)); + conn->proto.tcp = (esp_tcp *) calloc(1,sizeof(esp_tcp)); conn->proto.tcp->local_port = espconn_port(); conn->proto.tcp->remote_port = ws->port; diff --git a/ld/defsym.rom b/ld/defsym.rom index 5369fb0f89..542201dce2 100644 --- a/ld/defsym.rom +++ b/ld/defsym.rom @@ -4,6 +4,7 @@ --defsym=strncmp=ets_strncmp --defsym=strncpy=ets_strncpy --defsym=strstr=ets_strstr +--defsym=strdup=ets_strdup --defsym=memcmp=ets_memcmp --defsym=memcpy=ets_memcpy --defsym=memmove=ets_memmove diff --git a/sdk-overrides/include/c_types.h b/sdk-overrides/include/c_types.h deleted file mode 100644 index 115b66af5c..0000000000 --- a/sdk-overrides/include/c_types.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef _OVERRIDE_C_TYPES_H_ -#define _OVERRIDE_C_TYPES_H_ - -#include_next "c_types.h" - -typedef long long int64_t; -typedef int8_t sint8_t; -typedef int16_t sint16_t; -typedef int64_t sint64_t; - -#endif diff --git a/sdk-overrides/include/ets_sys.h b/sdk-overrides/include/ets_sys.h index eb4cf80d29..157e835f00 100644 --- a/sdk-overrides/include/ets_sys.h +++ b/sdk-overrides/include/ets_sys.h @@ -3,7 +3,7 @@ #include_next "ets_sys.h" -#include "../libc/c_stdarg.h" +#include int ets_sprintf(char *str, const char *format, ...) __attribute__ ((format (printf, 2, 3))); diff --git a/sdk-overrides/include/mem.h b/sdk-overrides/include/mem.h new file mode 100644 index 0000000000..b55c7bd560 --- /dev/null +++ b/sdk-overrides/include/mem.h @@ -0,0 +1,2 @@ +#include +#include_next "mem.h" diff --git a/sdk-overrides/include/osapi.h b/sdk-overrides/include/osapi.h index 7b751c372c..4e503f8aa4 100644 --- a/sdk-overrides/include/osapi.h +++ b/sdk-overrides/include/osapi.h @@ -1,11 +1,10 @@ #ifndef _SDK_OVERRIDE_OSAPI_H_ #define _SDK_OVERRIDE_OSAPI_H_ -#include "rom.h" +#include_next "osapi.h" -int atoi(const char *nptr); -int os_printf(const char *format, ...) __attribute__ ((format (printf, 1, 2))); -int os_printf_plus(const char *format, ...) __attribute__ ((format (printf, 1, 2))); +#include +#include "rom.h" unsigned int uart_baudrate_detect(unsigned int uart_no, unsigned int async); @@ -13,6 +12,4 @@ void NmiTimSetFunc(void (*func)(void)); void call_user_start(void); -#include_next "osapi.h" - #endif diff --git a/sdk-overrides/include/stdbool.h b/sdk-overrides/include/stdbool.h new file mode 100644 index 0000000000..2d7131d367 --- /dev/null +++ b/sdk-overrides/include/stdbool.h @@ -0,0 +1,7 @@ +#ifndef __stdbool_h__ +#define __stdbool_h__ + +// For compatibility with SDK. Boo. +#include_next "c_types.h" + +#endif diff --git a/sdk-overrides/include/stdio.h b/sdk-overrides/include/stdio.h new file mode 100644 index 0000000000..1abc104a19 --- /dev/null +++ b/sdk-overrides/include/stdio.h @@ -0,0 +1,21 @@ +#ifndef _OVERRIDE_STDIO_H_ +#define _OVERRIDE_STDIO_H_ + +#include_next "stdio.h" + +#ifdef __BUFSIZ__ +# define BUFSIZ __BUFSIZ__ +#else +# define BUFSIZ 1024 +#endif + +#define printf(...) do { \ + unsigned char __printf_buf[BUFSIZ]; \ + sprintf(__printf_buf, __VA_ARGS__); \ + puts(__printf_buf); \ +} while(0) + +extern void output_redirect(const char *str); +#define puts output_redirect + +#endif diff --git a/sdk-overrides/include/stdlib.h b/sdk-overrides/include/stdlib.h new file mode 100644 index 0000000000..a420d3cad5 --- /dev/null +++ b/sdk-overrides/include/stdlib.h @@ -0,0 +1,13 @@ +#ifndef _OVERRIDE_STDLIB_H_ +#define _OVERRIDE_STDLIB_H_ + +#include_next "stdlib.h" + +#include "mem.h" + +#define free os_free +#define malloc os_malloc +#define calloc(n,sz) os_zalloc(n*sz) +#define realloc os_realloc + +#endif From f7a545b9517201d83c30155e6bdcd8ee98138767 Mon Sep 17 00:00:00 2001 From: Johny Mattsson Date: Tue, 23 Jul 2019 14:22:38 +1000 Subject: [PATCH 38/74] Evict c_types.h, tidy up a other c_prefixes. (#2841) --- Makefile | 4 +- app/coap/coap_client.c | 2 +- app/coap/coap_io.h | 1 - app/coap/coap_server.c | 3 +- app/coap/str.c | 2 +- app/crypto/digests.h | 5 +- app/crypto/mech.h | 4 +- app/crypto/sha2.h | 3 +- app/dht/dht.h | 4 +- app/driver/pwm2.c | 4 +- app/driver/readline.c | 2 +- app/driver/rotary.c | 2 +- app/driver/switec.c | 3 +- app/esp-gdbstub/gdbstub.c | 1 - app/include/arch/cc.h | 2 +- app/include/driver/onewire.h | 3 +- app/include/driver/pwm2.h | 2 +- app/include/driver/rotary.h | 2 +- app/include/driver/switec.h | 2 +- app/include/driver/uart.h | 2 +- app/include/lwip/app/espconn_buf.h | 3 +- app/include/pm/pmSleep.h | 2 +- app/include/rom.h | 2 +- app/include/rtc/rtcaccess.h | 2 +- app/include/rtc/rtctime.h | 2 +- app/include/user_mbedtls.h | 3 +- app/libc/stdlib.c | 1 + app/lua/legc.c | 1 - app/lua/luac_cross.h | 61 +---------------- app/lua/luac_cross/lflashimg.c | 8 +-- app/lua/luac_cross/loslib.c | 12 ++-- app/lua/luac_cross/luac.c | 8 +-- app/lua/luac_cross/print.c | 4 +- app/lwip/core/sys_arch.c | 2 +- app/mbedtls/app/Espconn_mem.c | 2 +- app/mbedtls/app/lwIPFile.c | 2 +- app/modules/adc.c | 2 +- app/modules/bloom.c | 2 +- app/modules/coap.c | 4 +- app/modules/cron.c | 4 +- app/modules/crypto.c | 4 +- app/modules/file.c | 2 +- app/modules/gdbstub.c | 2 +- app/modules/gpio.c | 2 +- app/modules/gpio_pulse.c | 2 +- app/modules/mdns.c | 2 +- app/modules/mqtt.c | 4 +- app/modules/net.c | 4 +- app/modules/node.c | 2 +- app/modules/pwm.c | 2 +- app/modules/pwm2.c | 2 +- app/modules/rotary.c | 4 +- app/modules/somfy.c | 3 +- app/modules/sqlite3.c | 2 +- app/modules/switec.c | 2 +- app/modules/tls.c | 4 +- app/modules/tmr.c | 2 +- app/modules/uart.c | 2 +- app/modules/websocket.c | 4 +- app/modules/wifi.c | 4 +- app/modules/wifi_eventmon.c | 4 +- app/modules/wifi_monitor.c | 4 +- app/mqtt/mqtt_msg.h | 2 +- app/platform/cpu_esp8266.h | 3 + app/platform/pin_map.h | 2 +- app/platform/platform.h | 2 +- app/platform/sdcard.c | 2 +- app/platform/sdcard.h | 3 +- app/pm/swtimer.c | 4 +- app/sjson/memcompat.h | 2 +- app/sqlite3/esp8266.c | 4 +- app/sqlite3/sqlite3.c | 92 +++++++++++++------------- app/tsl2561/tsl2561.h | 2 +- app/websocket/websocketclient.c | 5 +- sdk-overrides/include/c_types.h | 6 ++ sdk-overrides/include/ets_sys.h | 4 ++ sdk-overrides/include/osapi.h | 5 +- sdk-overrides/include/stdbool.h | 7 +- sdk-overrides/include/stdint.h | 65 ++++++++++++++++++ sdk-overrides/include/stdlib.h | 2 +- sdk-overrides/include/user_interface.h | 4 ++ 81 files changed, 250 insertions(+), 209 deletions(-) create mode 100644 sdk-overrides/include/c_types.h create mode 100644 sdk-overrides/include/stdint.h diff --git a/Makefile b/Makefile index 7b9631a502..052908ff3e 100644 --- a/Makefile +++ b/Makefile @@ -33,7 +33,9 @@ SDK_DIR := $(TOP_DIR)/$(SDK_REL_DIR) ESPTOOL_VER := 2.6 # Ensure that the Espresif SDK is searched before the tool-chain's SDK (if any) -CCFLAGS:= -I$(TOP_DIR)/sdk-overrides/include -I$(TOP_DIR)/app/include/lwip/app -I$(SDK_DIR)/include +# Also, prevent the SDK's c_types.h from being included from anywhere, by +# predefining its include-guard. +CCFLAGS:= -I$(TOP_DIR)/sdk-overrides/include -I$(TOP_DIR)/app/include/lwip/app -I$(SDK_DIR)/include -D_C_TYPES_H_ LDFLAGS:= -L$(SDK_DIR)/lib -L$(SDK_DIR)/ld $(LDFLAGS) ifdef DEBUG diff --git a/app/coap/coap_client.c b/app/coap/coap_client.c index 63caf074b5..ae50b7c8de 100644 --- a/app/coap/coap_client.c +++ b/app/coap/coap_client.c @@ -1,5 +1,5 @@ #include "user_config.h" -#include "c_types.h" +#include #include "coap.h" #include "hash.h" diff --git a/app/coap/coap_io.h b/app/coap/coap_io.h index dd1b91c5cf..5126e6ca08 100644 --- a/app/coap/coap_io.h +++ b/app/coap/coap_io.h @@ -5,7 +5,6 @@ extern "C" { #endif -#include "c_types.h" #include "lwip/ip_addr.h" #include "espconn.h" #include "pdu.h" diff --git a/app/coap/coap_server.c b/app/coap/coap_server.c index 55c171f984..48671b5055 100644 --- a/app/coap/coap_server.c +++ b/app/coap/coap_server.c @@ -1,5 +1,6 @@ #include "user_config.h" -#include "c_types.h" +#include +#include #include #include "coap.h" diff --git a/app/coap/str.c b/app/coap/str.c index 1c882eede8..2e519c4667 100644 --- a/app/coap/str.c +++ b/app/coap/str.c @@ -7,7 +7,7 @@ */ #include -#include "c_types.h" +#include #include "str.h" diff --git a/app/crypto/digests.h b/app/crypto/digests.h index 93d802bb7d..bdd042105d 100644 --- a/app/crypto/digests.h +++ b/app/crypto/digests.h @@ -1,12 +1,13 @@ #ifndef _CRYPTO_DIGESTS_H_ #define _CRYPTO_DIGESTS_H_ -#include +#include +#include typedef void (*create_ctx_fn)(void *ctx); typedef void (*update_ctx_fn)(void *ctx, const uint8_t *msg, int len); typedef void (*finalize_ctx_fn)(uint8_t *digest, void *ctx); -typedef sint32_t ( *read_fn )(int fd, void *ptr, size_t len); +typedef int32_t ( *read_fn )(int fd, void *ptr, size_t len); /** * Description of a message digest mechanism. diff --git a/app/crypto/mech.h b/app/crypto/mech.h index a5d90d6ce8..98eef3b42e 100644 --- a/app/crypto/mech.h +++ b/app/crypto/mech.h @@ -1,7 +1,9 @@ #ifndef _MECH_H_ #define _MECH_H_ -#include "c_types.h" +#include +#include +#include typedef struct { diff --git a/app/crypto/sha2.h b/app/crypto/sha2.h index 7ec49634ab..a0fd187c87 100644 --- a/app/crypto/sha2.h +++ b/app/crypto/sha2.h @@ -1,7 +1,8 @@ #ifndef __SHA2_H__ #define __SHA2_H__ -#include +#include +#include /************************************************************************** * SHA256/384/512 declarations diff --git a/app/dht/dht.h b/app/dht/dht.h index 7e80d5e097..8c78909c44 100644 --- a/app/dht/dht.h +++ b/app/dht/dht.h @@ -17,7 +17,7 @@ // #else // #include // #endif -#include "c_types.h" +#include #define DHT_LIB_VERSION "0.1.14" @@ -67,4 +67,4 @@ double dht_getTemperature(void); #endif // // END OF FILE -// \ No newline at end of file +// diff --git a/app/driver/pwm2.c b/app/driver/pwm2.c index ad41307c90..38da5c21c7 100644 --- a/app/driver/pwm2.c +++ b/app/driver/pwm2.c @@ -5,8 +5,8 @@ * Nikolay Fiykov */ -#include -#include "c_types.h" +#include +#include #include "mem.h" #include "pin_map.h" #include "platform.h" diff --git a/app/driver/readline.c b/app/driver/readline.c index c262064be6..99192bbc85 100644 --- a/app/driver/readline.c +++ b/app/driver/readline.c @@ -2,7 +2,7 @@ #include "os_type.h" #include "osapi.h" #include "driver/uart.h" -#include "c_types.h" +#include LOCAL os_timer_t readline_timer; diff --git a/app/driver/rotary.c b/app/driver/rotary.c index 6e01506ebe..c54bda555e 100644 --- a/app/driver/rotary.c +++ b/app/driver/rotary.c @@ -11,7 +11,7 @@ */ #include "platform.h" -#include "c_types.h" +#include #include #include #include "driver/rotary.h" diff --git a/app/driver/switec.c b/app/driver/switec.c index 23c1a5f125..d776749aec 100644 --- a/app/driver/switec.c +++ b/app/driver/switec.c @@ -14,7 +14,8 @@ */ #include "platform.h" -#include "c_types.h" +#include +#include #include #include #include "driver/switec.h" diff --git a/app/esp-gdbstub/gdbstub.c b/app/esp-gdbstub/gdbstub.c index 509e9bb403..ded8c537b4 100644 --- a/app/esp-gdbstub/gdbstub.c +++ b/app/esp-gdbstub/gdbstub.c @@ -10,7 +10,6 @@ #include "gdbstub.h" #include "ets_sys.h" #include "eagle_soc.h" -#include "c_types.h" #include "gpio.h" #include "xtensa/corebits.h" #include "driver/uart.h" diff --git a/app/include/arch/cc.h b/app/include/arch/cc.h index 2829bd9869..6fbff3efd3 100644 --- a/app/include/arch/cc.h +++ b/app/include/arch/cc.h @@ -35,7 +35,7 @@ #define __ARCH_CC_H__ //#include -#include "c_types.h" +#include #include "ets_sys.h" #include "osapi.h" #define EFAULT 14 diff --git a/app/include/driver/onewire.h b/app/include/driver/onewire.h index c52492e7c1..f808825243 100644 --- a/app/include/driver/onewire.h +++ b/app/include/driver/onewire.h @@ -1,7 +1,8 @@ #ifndef __ONEWIRE_H__ #define __ONEWIRE_H__ -#include "c_types.h" +#include +#include // You can exclude certain features from OneWire. In theory, this // might save some space. In practice, the compiler automatically diff --git a/app/include/driver/pwm2.h b/app/include/driver/pwm2.h index c0fad44f2a..1ca28463a7 100644 --- a/app/include/driver/pwm2.h +++ b/app/include/driver/pwm2.h @@ -8,7 +8,7 @@ #ifndef __PWM2_H__ #define __PWM2_H__ -#include "c_types.h" +#include #include "pin_map.h" typedef struct { diff --git a/app/include/driver/rotary.h b/app/include/driver/rotary.h index d4c3ec5985..31215c743f 100644 --- a/app/include/driver/rotary.h +++ b/app/include/driver/rotary.h @@ -4,7 +4,7 @@ #ifndef __ROTARY_H__ #define __ROTARY_H__ -#include "c_types.h" +#include #define ROTARY_CHANNEL_COUNT 3 diff --git a/app/include/driver/switec.h b/app/include/driver/switec.h index 2fd5b5c0e8..65b64fd492 100644 --- a/app/include/driver/switec.h +++ b/app/include/driver/switec.h @@ -4,7 +4,7 @@ #ifndef __SWITEC_H__ #define __SWITEC_H__ -#include "c_types.h" +#include #define SWITEC_CHANNEL_COUNT 3 diff --git a/app/include/driver/uart.h b/app/include/driver/uart.h index 76c04f8e79..310f605417 100644 --- a/app/include/driver/uart.h +++ b/app/include/driver/uart.h @@ -3,7 +3,7 @@ #include "uart_register.h" #include "eagle_soc.h" -#include "c_types.h" +#include #include "os_type.h" #define RX_BUFF_SIZE 0x100 diff --git a/app/include/lwip/app/espconn_buf.h b/app/include/lwip/app/espconn_buf.h index 8bdfaa12ab..a7a10a68a7 100644 --- a/app/include/lwip/app/espconn_buf.h +++ b/app/include/lwip/app/espconn_buf.h @@ -14,7 +14,8 @@ * Created on: Apr 22, 2016 * Author: liuhan */ -#include "c_types.h" +#include +#include #include "ets_sys.h" #include "os_type.h" diff --git a/app/include/pm/pmSleep.h b/app/include/pm/pmSleep.h index 093c7dc5cb..2fb8f46cf2 100644 --- a/app/include/pm/pmSleep.h +++ b/app/include/pm/pmSleep.h @@ -1,7 +1,7 @@ #ifndef __FPM_SLEEP_H__ #define __FPM_SLEEP_H__ #include "user_interface.h" -#include "c_types.h" +#include #include "lauxlib.h" #include "gpio.h" #include "platform.h" diff --git a/app/include/rom.h b/app/include/rom.h index f64d50a01e..3548f28a3a 100644 --- a/app/include/rom.h +++ b/app/include/rom.h @@ -3,7 +3,7 @@ #ifndef _ROM_H_ #define _ROM_H_ -#include "c_types.h" +#include #include "ets_sys.h" // SHA1 is assumed to match the netbsd sha1.h headers diff --git a/app/include/rtc/rtcaccess.h b/app/include/rtc/rtcaccess.h index 4d27cb6fc2..92f81f5c49 100644 --- a/app/include/rtc/rtcaccess.h +++ b/app/include/rtc/rtcaccess.h @@ -1,7 +1,7 @@ #ifndef RTC_ACCESS_H #define RTC_ACCESS_H -#include +#include #define RTC_MMIO_BASE 0x60000700 #define RTC_USER_MEM_BASE 0x60001200 diff --git a/app/include/rtc/rtctime.h b/app/include/rtc/rtctime.h index 81bf8f67cc..5cb7b83df1 100644 --- a/app/include/rtc/rtctime.h +++ b/app/include/rtc/rtctime.h @@ -38,7 +38,7 @@ * relevant functions and expose these instead, through the rtctime.c module. */ -#include +#include #include "sections.h" #ifndef _RTCTIME_INTERNAL_H_ diff --git a/app/include/user_mbedtls.h b/app/include/user_mbedtls.h index cb3b792345..dcfe4c8e3f 100644 --- a/app/include/user_mbedtls.h +++ b/app/include/user_mbedtls.h @@ -1,4 +1,5 @@ -#include "c_types.h" +#include +#include #include "user_config.h" diff --git a/app/libc/stdlib.c b/app/libc/stdlib.c index 6299eceb34..08fbda0b01 100644 --- a/app/libc/stdlib.c +++ b/app/libc/stdlib.c @@ -3,6 +3,7 @@ #include #include #include +#include #ifdef LUA_CROSS_COMPILER #define ICACHE_RODATA_ATTR diff --git a/app/lua/legc.c b/app/lua/legc.c index 8b13b26f1e..c0bf07a6f2 100644 --- a/app/lua/legc.c +++ b/app/lua/legc.c @@ -2,7 +2,6 @@ #include "legc.h" #include "lstate.h" -#include "c_types.h" void legc_set_mode(lua_State *L, int mode, int limit) { global_State *g = G(L); diff --git a/app/lua/luac_cross.h b/app/lua/luac_cross.h index f4a4da83ed..716a743bd7 100644 --- a/app/lua/luac_cross.h +++ b/app/lua/luac_cross.h @@ -6,73 +6,14 @@ #define luac_cross_h #ifdef LUA_CROSS_COMPILER - -#define C_HEADER_ASSERT -#define C_HEADER_CTYPE -#define C_HEADER_ERRNO -#define C_HEADER_FCNTL -#define C_HEADER_LOCALE -#define C_HEADER_MATH -#define C_HEADER_STDIO -#define C_HEADER_STDLIB -#define C_HEADER_STRING -#define C_HEADER_TIME - #define ICACHE_RODATA_ATTR -#define c_abs abs -#define c_exit exit -#define c_fclose fclose -#define c_feof feof -#define c_ferror ferror -#define c_fopen fopen -#define c_fread fread -#define c_free free -#define c_freopen freopen -#define c_getc getc -#define c_getenv getenv -#define c_malloc malloc -#define c_memcmp memcmp -#define c_memcpy memcpy -#define c_printf printf -#define c_puts puts -#define c_reader reader -#define c_realloc realloc -#define c_sprintf sprintf #define c_stderr stderr #define c_stdin stdin #define c_stdout stdout -#define c_strcat strcat -#define c_strchr strchr -#define c_strcmp strcmp -#define c_strcoll strcoll -#define c_strcpy strcpy -#define c_strcspn strcspn -#define c_strerror strerror -#define c_strlen strlen -#define c_strncat strncat -#define c_strncmp strncmp -#define c_strncpy strncpy -#define c_strpbrk strpbrk -#define c_strrchr strrchr -#define c_strstr strstr -double c_strtod(const char *__n, char **__end_PTR); -#define c_ungetc ungetc -#define c_strtol strtol -#define c_strtoul strtoul + #define dbg_printf printf #else -#define C_HEADER_ASSERT "c_assert.h" -#define C_HEADER_CTYPE "c_ctype.h" -#define C_HEADER_ERRNO "c_errno.h" -#define C_HEADER_FCNTL "c_fcntl.h" -#define C_HEADER_LOCALE "c_locale.h" -#define C_HEADER_MATH "c_math.h" -#define C_HEADER_STDIO "c_stdio.h" -#define C_HEADER_STDLIB "c_stdlib.h" -#define C_HEADER_STRING "c_string.h" -#define C_HEADER_TIME "c_time.h" - #endif /* LUA_CROSS_COMPILER */ #endif /* luac_cross_h */ diff --git a/app/lua/luac_cross/lflashimg.c b/app/lua/luac_cross/lflashimg.c index 4dd5a85323..7ded81fdc8 100644 --- a/app/lua/luac_cross/lflashimg.c +++ b/app/lua/luac_cross/lflashimg.c @@ -7,10 +7,10 @@ #define LUAC_CROSS_FILE #include "luac_cross.h" -#include C_HEADER_CTYPE -#include C_HEADER_STDIO -#include C_HEADER_STDLIB -#include C_HEADER_STRING +#include +#include +#include +#include #define lflashimg_c #define LUA_CORE diff --git a/app/lua/luac_cross/loslib.c b/app/lua/luac_cross/loslib.c index 59c22794ba..604ea79380 100644 --- a/app/lua/luac_cross/loslib.c +++ b/app/lua/luac_cross/loslib.c @@ -7,11 +7,11 @@ #define LUAC_CROSS_FILE #include "luac_cross.h" -#include C_HEADER_ERRNO -#include C_HEADER_LOCALE -#include C_HEADER_STDLIB -#include C_HEADER_STRING -#include C_HEADER_TIME +#include +#include +#include +#include +#include #define loslib_c #define LUA_LIB @@ -217,7 +217,7 @@ static int os_setlocale (lua_State *L) { static int os_exit (lua_State *L) { - c_exit(luaL_optint(L, 1, EXIT_SUCCESS)); + exit(luaL_optint(L, 1, EXIT_SUCCESS)); } LROT_PUBLIC_BEGIN(oslib) diff --git a/app/lua/luac_cross/luac.c b/app/lua/luac_cross/luac.c index 7853604ab3..2cb62ee389 100644 --- a/app/lua/luac_cross/luac.c +++ b/app/lua/luac_cross/luac.c @@ -7,10 +7,10 @@ #define LUAC_CROSS_FILE #include "luac_cross.h" -#include C_HEADER_ERRNO -#include C_HEADER_STDIO -#include C_HEADER_STDLIB -#include C_HEADER_STRING +#include +#include +#include +#include #include #define luac_c diff --git a/app/lua/luac_cross/print.c b/app/lua/luac_cross/print.c index 1273d47e71..71b8352ac2 100644 --- a/app/lua/luac_cross/print.c +++ b/app/lua/luac_cross/print.c @@ -7,8 +7,8 @@ #define LUAC_CROSS_FILE #include "luac_cross.h" -#include C_HEADER_CTYPE -#include C_HEADER_STDIO +#include +#include #define luac_c #define LUA_CORE diff --git a/app/lwip/core/sys_arch.c b/app/lwip/core/sys_arch.c index 81bb220846..7dd953ba84 100644 --- a/app/lwip/core/sys_arch.c +++ b/app/lwip/core/sys_arch.c @@ -2,7 +2,7 @@ * copyright (c) 2010 - 2011 espressif system */ -#include "c_types.h" +#include #include "ets_sys.h" #include "osapi.h" #include "os_type.h" diff --git a/app/mbedtls/app/Espconn_mem.c b/app/mbedtls/app/Espconn_mem.c index 41b1dd92dc..5620b1b9eb 100644 --- a/app/mbedtls/app/Espconn_mem.c +++ b/app/mbedtls/app/Espconn_mem.c @@ -1,4 +1,4 @@ -#include "c_types.h" +#include #include "mem.h" #include "user_interface.h" diff --git a/app/mbedtls/app/lwIPFile.c b/app/mbedtls/app/lwIPFile.c index bdae8fd147..b9fadd2270 100644 --- a/app/mbedtls/app/lwIPFile.c +++ b/app/mbedtls/app/lwIPFile.c @@ -22,7 +22,7 @@ * */ -#include "c_types.h" +#include #include //#include "os.h" diff --git a/app/modules/adc.c b/app/modules/adc.c index 2d9777ca62..5b87e97fc9 100644 --- a/app/modules/adc.c +++ b/app/modules/adc.c @@ -4,7 +4,7 @@ #include "lauxlib.h" #include "platform.h" -#include "c_types.h" +#include #include "user_interface.h" // Lua: read(id) , return system adc diff --git a/app/modules/bloom.c b/app/modules/bloom.c index 922e3ed25a..5198c1203f 100644 --- a/app/modules/bloom.c +++ b/app/modules/bloom.c @@ -7,7 +7,7 @@ #include "module.h" #include "lauxlib.h" #include -#include "c_types.h" +#include #include "../crypto/sha2.h" #if defined(LUA_USE_MODULES_BLOOM) && !defined(SHA2_ENABLE) diff --git a/app/modules/coap.c b/app/modules/coap.c index f810154e17..a50a086f01 100644 --- a/app/modules/coap.c +++ b/app/modules/coap.c @@ -5,9 +5,9 @@ #include "platform.h" #include -#include +#include -#include "c_types.h" +#include #include "mem.h" #include "lwip/ip_addr.h" #include "espconn.h" diff --git a/app/modules/cron.c b/app/modules/cron.c index 5196c00358..d39a2754d5 100644 --- a/app/modules/cron.c +++ b/app/modules/cron.c @@ -4,12 +4,12 @@ #include "lauxlib.h" #include "lmem.h" #include "user_interface.h" -#include "c_types.h" +#include +#include #include #include "ets_sys.h" #include "time.h" #include "rtc/rtctime.h" -#include "stdlib.h" #include "mem.h" struct cronent_desc { diff --git a/app/modules/crypto.c b/app/modules/crypto.c index f55b7f2ebc..3deabdaa1d 100644 --- a/app/modules/crypto.c +++ b/app/modules/crypto.c @@ -4,8 +4,8 @@ #include "module.h" #include "lauxlib.h" #include "platform.h" -#include "c_types.h" -#include +#include +#include #include "vfs.h" #include "../crypto/digests.h" #include "../crypto/mech.h" diff --git a/app/modules/file.c b/app/modules/file.c index 03763b74f0..34ff3ed4a3 100644 --- a/app/modules/file.c +++ b/app/modules/file.c @@ -5,7 +5,7 @@ #include "lmem.h" #include "platform.h" -#include "c_types.h" +#include #include "vfs.h" #include diff --git a/app/modules/gdbstub.c b/app/modules/gdbstub.c index 9ba6922cf4..a76d97b009 100644 --- a/app/modules/gdbstub.c +++ b/app/modules/gdbstub.c @@ -17,7 +17,7 @@ #include "module.h" #include "lauxlib.h" #include "platform.h" -#include "c_types.h" +#include #include "user_interface.h" #include "../esp-gdbstub/gdbstub.h" diff --git a/app/modules/gpio.c b/app/modules/gpio.c index 4310441331..939d3d25f5 100644 --- a/app/modules/gpio.c +++ b/app/modules/gpio.c @@ -6,7 +6,7 @@ #include "lmem.h" #include "platform.h" #include "user_interface.h" -#include "c_types.h" +#include #include #include "gpio.h" #include "hw_timer.h" diff --git a/app/modules/gpio_pulse.c b/app/modules/gpio_pulse.c index 359458629d..15909572f4 100644 --- a/app/modules/gpio_pulse.c +++ b/app/modules/gpio_pulse.c @@ -3,7 +3,7 @@ #include "lmem.h" #include "platform.h" #include "user_interface.h" -#include "c_types.h" +#include #include #include "gpio.h" #include "hw_timer.h" diff --git a/app/modules/mdns.c b/app/modules/mdns.c index 8694c04582..a574f3757a 100644 --- a/app/modules/mdns.c +++ b/app/modules/mdns.c @@ -7,7 +7,7 @@ #include #include -#include "c_types.h" +#include #include "lwip/ip_addr.h" #include "nodemcu_mdns.h" #include "user_interface.h" diff --git a/app/modules/mqtt.c b/app/modules/mqtt.c index 49ae3e5bf8..dcb25005bb 100644 --- a/app/modules/mqtt.c +++ b/app/modules/mqtt.c @@ -5,9 +5,9 @@ #include "platform.h" #include -#include +#include -#include "c_types.h" +#include #include "mem.h" #include "lwip/ip_addr.h" #include "espconn.h" diff --git a/app/modules/net.c b/app/modules/net.c index d0b705d7d9..fdbd575d8d 100644 --- a/app/modules/net.c +++ b/app/modules/net.c @@ -7,9 +7,9 @@ #include #include -#include +#include -#include "c_types.h" +#include #include "mem.h" #include "osapi.h" #include "lwip/err.h" diff --git a/app/modules/node.c b/app/modules/node.c index cc834c31da..a44f3fa43c 100644 --- a/app/modules/node.c +++ b/app/modules/node.c @@ -16,7 +16,7 @@ #include "platform.h" #include "lflash.h" -#include "c_types.h" +#include #include #include "driver/uart.h" #include "user_interface.h" diff --git a/app/modules/pwm.c b/app/modules/pwm.c index 8296e43346..c7d83568ac 100644 --- a/app/modules/pwm.c +++ b/app/modules/pwm.c @@ -3,7 +3,7 @@ #include "module.h" #include "lauxlib.h" #include "platform.h" -#include "c_types.h" +#include // Lua: realfrequency = setup( id, frequency, duty ) static int lpwm_setup( lua_State* L ) diff --git a/app/modules/pwm2.c b/app/modules/pwm2.c index 027b4019ff..4ee316722d 100644 --- a/app/modules/pwm2.c +++ b/app/modules/pwm2.c @@ -7,7 +7,7 @@ // Module for interfacing with PWM2 driver -#include "c_types.h" +#include #include "lauxlib.h" #include "module.h" #include "driver/pwm2.h" diff --git a/app/modules/rotary.c b/app/modules/rotary.c index 27df544065..44397ef72d 100644 --- a/app/modules/rotary.c +++ b/app/modules/rotary.c @@ -9,10 +9,10 @@ #include "module.h" #include "lauxlib.h" #include "platform.h" -#include "c_types.h" +#include +#include #include "user_interface.h" #include "driver/rotary.h" -#include #define MASK(x) (1 << ROTARY_ ## x ## _INDEX) diff --git a/app/modules/somfy.c b/app/modules/somfy.c index c8ae5d7e13..79abf50ef2 100644 --- a/app/modules/somfy.c +++ b/app/modules/somfy.c @@ -11,6 +11,7 @@ //#define NODE_DEBUG +#include #include "os_type.h" #include "osapi.h" #include "sections.h" @@ -245,4 +246,4 @@ int luaopen_somfy( lua_State *L ) { return 0; } -NODEMCU_MODULE(SOMFY, "somfy", somfy, luaopen_somfy); \ No newline at end of file +NODEMCU_MODULE(SOMFY, "somfy", somfy, luaopen_somfy); diff --git a/app/modules/sqlite3.c b/app/modules/sqlite3.c index a6b9cde643..c842249813 100644 --- a/app/modules/sqlite3.c +++ b/app/modules/sqlite3.c @@ -30,7 +30,7 @@ #define LSQLITE_OMIT_UPDATE_HOOK 1 #define SQLITE_OMIT_PROGRESS_CALLBACK 1 -#include +#include #include #include diff --git a/app/modules/switec.c b/app/modules/switec.c index a954b89264..08b698983f 100644 --- a/app/modules/switec.c +++ b/app/modules/switec.c @@ -16,7 +16,7 @@ #include "module.h" #include "lauxlib.h" #include "platform.h" -#include "c_types.h" +#include #include "task/task.h" #include "driver/switec.h" diff --git a/app/modules/tls.c b/app/modules/tls.c index d59af574b7..b9a63f6202 100644 --- a/app/modules/tls.c +++ b/app/modules/tls.c @@ -9,9 +9,9 @@ #include "lmem.h" #include -#include +#include -#include "c_types.h" +#include #include "mem.h" #include "lwip/ip_addr.h" #include "espconn.h" diff --git a/app/modules/tmr.c b/app/modules/tmr.c index 14b7f528fc..10c09db3e2 100644 --- a/app/modules/tmr.c +++ b/app/modules/tmr.c @@ -51,7 +51,7 @@ tmr.softwd(int) #include "module.h" #include "lauxlib.h" #include "platform.h" -#include "c_types.h" +#include #include "user_interface.h" #include "pm/swtimer.h" diff --git a/app/modules/uart.c b/app/modules/uart.c index 364873d7d5..5dcba1c4b0 100644 --- a/app/modules/uart.c +++ b/app/modules/uart.c @@ -4,7 +4,7 @@ #include "lauxlib.h" #include "platform.h" -#include "c_types.h" +#include #include #include "rom.h" diff --git a/app/modules/websocket.c b/app/modules/websocket.c index 77d83d082f..71ecd67ae9 100644 --- a/app/modules/websocket.c +++ b/app/modules/websocket.c @@ -13,9 +13,9 @@ #include "platform.h" #include "module.h" -#include "c_types.h" +#include #include -#include +#include #include "websocketclient.h" diff --git a/app/modules/wifi.c b/app/modules/wifi.c index ddcc3096cd..6e5b6d0231 100644 --- a/app/modules/wifi.c +++ b/app/modules/wifi.c @@ -7,10 +7,10 @@ #include "platform.h" #include -#include +#include #include "ctype.h" -#include "c_types.h" +#include #include "user_interface.h" #include "wifi_common.h" diff --git a/app/modules/wifi_eventmon.c b/app/modules/wifi_eventmon.c index 5d016f914d..f5d87170f1 100644 --- a/app/modules/wifi_eventmon.c +++ b/app/modules/wifi_eventmon.c @@ -5,9 +5,9 @@ #include "platform.h" #include -#include +#include -#include "c_types.h" +#include #include "user_interface.h" #include "smart.h" #include "smartconfig.h" diff --git a/app/modules/wifi_monitor.c b/app/modules/wifi_monitor.c index 041bb03f85..951f5be4b0 100644 --- a/app/modules/wifi_monitor.c +++ b/app/modules/wifi_monitor.c @@ -6,10 +6,10 @@ #include "platform.h" #include -#include +#include #include "ctype.h" -#include "c_types.h" +#include #include "user_interface.h" #include "wifi_common.h" #include "sys/network_80211.h" diff --git a/app/mqtt/mqtt_msg.h b/app/mqtt/mqtt_msg.h index 57d07158ff..85f70f6d73 100644 --- a/app/mqtt/mqtt_msg.h +++ b/app/mqtt/mqtt_msg.h @@ -7,7 +7,7 @@ #ifndef MQTT_MSG_H #define MQTT_MSG_H -#include "c_types.h" +#include #ifdef __cplusplus extern "C" { #endif diff --git a/app/platform/cpu_esp8266.h b/app/platform/cpu_esp8266.h index 7ff7b6cf1e..4d82b684ea 100644 --- a/app/platform/cpu_esp8266.h +++ b/app/platform/cpu_esp8266.h @@ -2,6 +2,9 @@ #define __CPU_ESP8266_H__ #ifndef NO_CPU_ESP8266_INCLUDE +#include +#include +#include #include "os_type.h" #include "spi_flash.h" #include "pin_map.h" diff --git a/app/platform/pin_map.h b/app/platform/pin_map.h index a4d3fe934d..4ad1b7c98f 100644 --- a/app/platform/pin_map.h +++ b/app/platform/pin_map.h @@ -2,7 +2,7 @@ #ifndef __PIN_MAP_H__ #define __PIN_MAP_H__ -#include "c_types.h" +#include #include "user_config.h" #include "gpio.h" diff --git a/app/platform/platform.h b/app/platform/platform.h index 4350b5f403..3a41ddfc85 100644 --- a/app/platform/platform.h +++ b/app/platform/platform.h @@ -3,9 +3,9 @@ #ifndef __PLATFORM_H__ #define __PLATFORM_H__ +#include #include "cpu_esp8266.h" -#include "c_types.h" #include "driver/pwm.h" #include "driver/uart.h" #include "task/task.h" diff --git a/app/platform/sdcard.c b/app/platform/sdcard.c index 1a2f6535af..143d96c89b 100644 --- a/app/platform/sdcard.c +++ b/app/platform/sdcard.c @@ -1,6 +1,6 @@ #include "platform.h" #include "driver/spi.h" -#include "c_types.h" +#include #include "sdcard.h" diff --git a/app/platform/sdcard.h b/app/platform/sdcard.h index a408b4c1d9..f6bb4133cd 100644 --- a/app/platform/sdcard.h +++ b/app/platform/sdcard.h @@ -1,7 +1,8 @@ #ifndef _SDCARD_H #define _SDCARD_H -#include "c_types.h" +#include +#include int platform_sdcard_init( uint8_t spi_no, uint8_t ss_pin ); int platform_sdcard_status( void ); diff --git a/app/pm/swtimer.c b/app/pm/swtimer.c index 0e89a3fd6e..5e0bb38b3f 100644 --- a/app/pm/swtimer.c +++ b/app/pm/swtimer.c @@ -48,8 +48,8 @@ #include #include #include - -#include "c_types.h" +#include +#include //#define SWTMR_DEBUG #if !defined(SWTMR_DBG) && defined(LUA_USE_MODULES_SWTMR_DBG) diff --git a/app/sjson/memcompat.h b/app/sjson/memcompat.h index 7112e2010c..d6fba37b22 100644 --- a/app/sjson/memcompat.h +++ b/app/sjson/memcompat.h @@ -1,7 +1,7 @@ #ifndef __MEMCOMPAT_H__ #define __MEMCOMPAT_H__ -#include "c_types.h" +#include #include "mem.h" #endif diff --git a/app/sqlite3/esp8266.c b/app/sqlite3/esp8266.c index 1cd8f1da55..c058e49528 100644 --- a/app/sqlite3/esp8266.c +++ b/app/sqlite3/esp8266.c @@ -8,9 +8,9 @@ **/ #include -#include +#include #include -#include "c_types.h" +#include #include #include #include diff --git a/app/sqlite3/sqlite3.c b/app/sqlite3/sqlite3.c index 8cfe9305cb..5843118189 100644 --- a/app/sqlite3/sqlite3.c +++ b/app/sqlite3/sqlite3.c @@ -2795,7 +2795,7 @@ SQLITE_API void sqlite3_free_table(char **result); ** table and column names into a constructed SQL statement. ** ** ^(The "%z" formatting option works like "%s" but with the -** addition that after the c_string has been read and copied into +** addition that after the string has been read and copied into ** the result, [sqlite3_free()] is called on the input string.)^ */ SQLITE_API char *sqlite3_mprintf(const char*,...); @@ -29771,7 +29771,7 @@ SQLITE_PRIVATE const char *sqlite3OpcodeName(int i){ /* ** standard include files. */ -#include +#include #include #include #include @@ -78053,7 +78053,7 @@ static int findNextHostParameter(const char *zSql, int *pnToken){ ** obtained from sqlite3DbMalloc(). If sqlite3.nVdbeExec is 1, then the ** string contains a copy of zRawSql but with host parameters expanded to ** their current bindings. Or, if sqlite3.nVdbeExec is greater than 1, -** then the returned c_string holds a copy of zRawSql with "-- " prepended +** then the returned string holds a copy of zRawSql with "-- " prepended ** to each line of text. ** ** If the SQLITE_TRACE_SIZE_LIMIT macro is defined to an integer, then @@ -89198,8 +89198,8 @@ SQLITE_PRIVATE int sqlite3JournalSize(sqlite3_vfs *pVfs){ ** an SQL statement. */ /* #include "sqliteInt.h" */ -/* #include */ -/* #include */ +/* #include */ +/* #include */ /* @@ -105553,7 +105553,7 @@ SQLITE_PRIVATE void sqlite3ResolvePartIdxLabel(Parse *pParse, int iLabel){ ** time functions, are implemented separately.) */ /* #include "sqliteInt.h" */ -/* #include */ +/* #include */ /* #include */ /* #include "vdbeInt.h" */ @@ -108885,7 +108885,7 @@ SQLITE_PRIVATE void sqlite3OpenTable( /* ** Return a pointer to the column affinity string associated with index -** pIdx. A column affinity c_string has one character for each column in +** pIdx. A column affinity string has one character for each column in ** the table, according to the affinity of the column: ** ** Character Column affinity @@ -108951,7 +108951,7 @@ SQLITE_PRIVATE const char *sqlite3IndexAffinityStr(sqlite3 *db, Index *pIdx){ ** then just set the P4 operand of the previous opcode (which should be ** an OP_MakeRecord) to the affinity string. ** -** A column affinity c_string has one character per column: +** A column affinity string has one character per column: ** ** Character Column affinity ** ------------------------------ @@ -135437,7 +135437,7 @@ SQLITE_PRIVATE void sqlite3WhereEnd(WhereInfo *pWInfo){ ** The following is the concatenation of all %include directives from the ** input grammar file: */ -/* #include */ +/* #include */ /************ Begin %include sections from the grammar ************************/ /* #include "sqliteInt.h" */ @@ -136309,7 +136309,7 @@ struct yyParser { typedef struct yyParser yyParser; #ifndef NDEBUG -/* #include */ +/* #include */ static FILE *yyTraceFILE = 0; static char *yyTracePrompt = 0; #endif /* NDEBUG */ @@ -138629,7 +138629,7 @@ SQLITE_PRIVATE void sqlite3Parser( ** parser for analysis. */ /* #include "sqliteInt.h" */ -/* #include */ +/* #include */ /* Character classes for tokenizing ** @@ -145471,10 +145471,10 @@ SQLITE_PRIVATE int sqlite3FtsUnicodeIsdiacritic(int); #endif /* #include */ -/* #include */ +/* #include */ /* #include */ -/* #include */ -/* #include */ +/* #include */ +/* #include */ /* #include */ /* #include "fts3.h" */ @@ -151141,7 +151141,7 @@ SQLITE_API int sqlite3_fts3_init( /* #include "fts3Int.h" */ #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) -/* #include */ +/* #include */ /* #include */ typedef struct Fts3auxTable Fts3auxTable; @@ -151758,7 +151758,7 @@ SQLITE_API int sqlite3_fts3_enable_parentheses = 0; */ #define SQLITE_FTS3_DEFAULT_NEAR_PARAM 10 -/* #include */ +/* #include */ /* #include */ /* @@ -152786,7 +152786,7 @@ SQLITE_PRIVATE void sqlite3Fts3ExprFree(Fts3Expr *pDel){ #ifdef SQLITE_TEST -/* #include */ +/* #include */ /* ** Function to query the hash-table of tokenizers (see README.tokenizers). @@ -153019,8 +153019,8 @@ SQLITE_PRIVATE int sqlite3Fts3ExprInitTestInterface(sqlite3* db){ #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) /* #include */ -/* #include */ -/* #include */ +/* #include */ +/* #include */ /* #include "fts3_hash.h" */ @@ -153404,9 +153404,9 @@ SQLITE_PRIVATE void *sqlite3Fts3HashInsert( #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) /* #include */ -/* #include */ -/* #include */ -/* #include */ +/* #include */ +/* #include */ +/* #include */ /* #include "fts3_tokenizer.h" */ @@ -154070,7 +154070,7 @@ SQLITE_PRIVATE void sqlite3Fts3PorterTokenizerModule( #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) /* #include */ -/* #include */ +/* #include */ /* ** Return true if the two-argument version of fts3_tokenizer() @@ -154272,7 +154272,7 @@ SQLITE_PRIVATE int sqlite3Fts3InitTokenizer( #else # include "tcl.h" #endif -/* #include */ +/* #include */ /* ** Implementation of a special SQL scalar function for testing tokenizers @@ -154588,9 +154588,9 @@ SQLITE_PRIVATE int sqlite3Fts3InitHashTable( #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) /* #include */ -/* #include */ -/* #include */ -/* #include */ +/* #include */ +/* #include */ +/* #include */ /* #include "fts3_tokenizer.h" */ @@ -154840,7 +154840,7 @@ SQLITE_PRIVATE void sqlite3Fts3SimpleTokenizerModule( /* #include "fts3Int.h" */ #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) -/* #include */ +/* #include */ /* #include */ typedef struct Fts3tokTable Fts3tokTable; @@ -155276,9 +155276,9 @@ SQLITE_PRIVATE int sqlite3Fts3InitTok(sqlite3 *db, Fts3Hash *pHash){ /* #include "fts3Int.h" */ #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) -/* #include */ +/* #include */ /* #include */ -/* #include */ +/* #include */ #define FTS_MAX_APPENDABLE_HEIGHT 16 @@ -160954,7 +160954,7 @@ SQLITE_PRIVATE int sqlite3Fts3Optimize(Fts3Table *p){ /* #include "fts3Int.h" */ #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) -/* #include */ +/* #include */ /* #include */ /* @@ -162124,7 +162124,7 @@ static int fts3MatchinfoLcs(Fts3Cursor *pCsr, MatchInfo *pInfo){ ** be returned by the matchinfo() function. Argument zArg contains the ** format string passed as the second argument to matchinfo (or the ** default value "pcx" if no second argument was specified). The format -** c_string has already been validated and the pInfo->aMatchinfo[] array +** string has already been validated and the pInfo->aMatchinfo[] array ** is guaranteed to be large enough for the output. ** ** If bGlobal is true, then populate all fields of the matchinfo() output. @@ -162668,9 +162668,9 @@ SQLITE_PRIVATE void sqlite3Fts3Matchinfo( #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) /* #include */ -/* #include */ -/* #include */ -/* #include */ +/* #include */ +/* #include */ +/* #include */ /* #include "fts3_tokenizer.h" */ @@ -163473,9 +163473,9 @@ SQLITE_PRIVATE int sqlite3FtsUnicodeFold(int c, int bRemoveDiacritic){ /* #include "sqlite3.h" */ #endif -/* #include */ +/* #include */ /* #include */ -/* #include */ +/* #include */ #ifndef SQLITE_AMALGAMATION #include "sqlite3rtree.h" @@ -168105,8 +168105,8 @@ SQLITE_PRIVATE void sqlite3Fts3IcuTokenizerModule( */ /* #include */ -/* #include */ -/* #include */ +/* #include */ +/* #include */ /* #include "sqlite3.h" */ @@ -174118,7 +174118,7 @@ SQLITE_PRIVATE int sqlite3DbstatRegister(sqlite3 *db){ return SQLITE_OK; } #if defined(SQLITE_ENABLE_SESSION) && defined(SQLITE_ENABLE_PREUPDATE_HOOK) /* #include "sqlite3session.h" */ /* #include */ -/* #include */ +/* #include */ #ifndef SQLITE_AMALGAMATION /* # include "sqliteInt.h" */ @@ -178800,8 +178800,8 @@ SQLITE_API int sqlite3changeset_concat_strm( #endif SQLITE_EXTENSION_INIT1 /* #include */ -/* #include */ -/* #include */ +/* #include */ +/* #include */ /* #include */ /* Mark a function parameter as unused, to suppress nuisance compiler @@ -181812,7 +181812,7 @@ struct fts5_api { /* #include "sqlite3ext.h" */ SQLITE_EXTENSION_INIT1 -/* #include */ +/* #include */ /* #include */ #ifndef SQLITE_AMALGAMATION @@ -182624,7 +182624,7 @@ static int sqlite3Fts5UnicodeFold(int c, int bRemoveDiacritic); ** The following is the concatenation of all %include directives from the ** input grammar file: */ -/* #include */ +/* #include */ /************ Begin %include sections from the grammar ************************/ /* #include "fts5Int.h" */ @@ -182929,7 +182929,7 @@ struct fts5yyParser { typedef struct fts5yyParser fts5yyParser; #ifndef NDEBUG -/* #include */ +/* #include */ static FILE *fts5yyTraceFILE = 0; static char *fts5yyTracePrompt = 0; #endif /* NDEBUG */ @@ -185988,7 +185988,7 @@ static void *sqlite3Fts5ParserAlloc(void *(*mallocProc)(u64)); static void sqlite3Fts5ParserFree(void*, void (*freeProc)(void*)); static void sqlite3Fts5Parser(void*, int, Fts5Token, Fts5Parse*); #ifndef NDEBUG -/* #include */ +/* #include */ static void sqlite3Fts5ParserTrace(FILE*, char*); #endif diff --git a/app/tsl2561/tsl2561.h b/app/tsl2561/tsl2561.h index 23c8f1b3fb..af322b55fa 100644 --- a/app/tsl2561/tsl2561.h +++ b/app/tsl2561/tsl2561.h @@ -33,7 +33,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /**************************************************************************/ -#include "c_types.h" +#include #ifndef _TSL2561_H_ #define _TSL2561_H_ diff --git a/app/websocket/websocketclient.c b/app/websocket/websocketclient.c index b96e47269d..b03fad4dd9 100644 --- a/app/websocket/websocketclient.c +++ b/app/websocket/websocketclient.c @@ -27,9 +27,8 @@ #include "espconn.h" #include "mem.h" #include "limits.h" -#include "stdlib.h" - -#include "c_types.h" +#include +#include #include #include #include diff --git a/sdk-overrides/include/c_types.h b/sdk-overrides/include/c_types.h new file mode 100644 index 0000000000..6d4558024c --- /dev/null +++ b/sdk-overrides/include/c_types.h @@ -0,0 +1,6 @@ +#ifndef _SDKOVERRIDES_C_TYPES_H_ +#define _SDKOVERRIDES_C_TYPES_H_ + +#error "Please do not use c_types.h, use instead" + +#endif diff --git a/sdk-overrides/include/ets_sys.h b/sdk-overrides/include/ets_sys.h index 157e835f00..eae2c1b5f3 100644 --- a/sdk-overrides/include/ets_sys.h +++ b/sdk-overrides/include/ets_sys.h @@ -1,6 +1,10 @@ #ifndef SDK_OVERRIDES_INCLUDE_ETS_SYS_H_ #define SDK_OVERRIDES_INCLUDE_ETS_SYS_H_ +#include +#include +#include + #include_next "ets_sys.h" #include diff --git a/sdk-overrides/include/osapi.h b/sdk-overrides/include/osapi.h index 4e503f8aa4..c192fa0d88 100644 --- a/sdk-overrides/include/osapi.h +++ b/sdk-overrides/include/osapi.h @@ -1,9 +1,12 @@ #ifndef _SDK_OVERRIDE_OSAPI_H_ #define _SDK_OVERRIDE_OSAPI_H_ +#include +#include +#include + #include_next "osapi.h" -#include #include "rom.h" unsigned int uart_baudrate_detect(unsigned int uart_no, unsigned int async); diff --git a/sdk-overrides/include/stdbool.h b/sdk-overrides/include/stdbool.h index 2d7131d367..b9f3689931 100644 --- a/sdk-overrides/include/stdbool.h +++ b/sdk-overrides/include/stdbool.h @@ -2,6 +2,11 @@ #define __stdbool_h__ // For compatibility with SDK. Boo. -#include_next "c_types.h" +typedef unsigned char bool; +#define BOOL bool +#define true (1) +#define false (0) +#define TRUE true +#define FALSE false #endif diff --git a/sdk-overrides/include/stdint.h b/sdk-overrides/include/stdint.h new file mode 100644 index 0000000000..8930dea873 --- /dev/null +++ b/sdk-overrides/include/stdint.h @@ -0,0 +1,65 @@ +#ifndef _SDKOVERRIDES_STDINT_H_ +#define _SDKOVERRIDES_STDINT_H_ + +#include_next "stdint.h" + +// Compatibility cruft from c_types.h, ideally we should get rid of this! +typedef signed char sint8_t; +typedef signed short sint16_t; +typedef signed int sint32_t; +typedef signed long long sint64_t; +typedef unsigned long long u_int64_t; +typedef float real32_t; +typedef double real64_t; + +typedef unsigned char uint8; +typedef unsigned char u8; +typedef signed char sint8; +typedef signed char int8; +typedef signed char s8; +typedef unsigned short uint16; +typedef unsigned short u16; +typedef signed short sint16; +typedef signed short s16; +typedef unsigned int uint32; +typedef unsigned int u_int; +typedef unsigned int u32; +typedef signed int sint32; +typedef signed int s32; +typedef int int32; +typedef signed long long sint64; +typedef unsigned long long uint64; +typedef unsigned long long u64; +typedef float real32; +typedef double real64; + +#define __le16 u16 + +// And this stuff really doesn't belong in a types file in the first place... +#ifndef __packed +#define __packed __attribute__((packed)) +#endif + +#define LOCAL static + +typedef enum { + OK = 0, + FAIL, + PENDING, + BUSY, + CANCEL, +} STATUS; + +#define BIT(nr) (1UL << (nr)) + +#define REG_SET_BIT(_r, _b) (*(volatile uint32_t*)(_r) |= (_b)) +#define REG_CLR_BIT(_r, _b) (*(volatile uint32_t*)(_r) &= ~(_b)) + +#define DMEM_ATTR __attribute__((section(".bss"))) +#define SHMEM_ATTR + +#define ICACHE_FLASH_ATTR __attribute__((section(".irom0.text"))) +#define ICACHE_RODATA_ATTR __attribute__((section(".irom.text"))) +#define STORE_ATTR __attribute__((aligned(4))) + +#endif diff --git a/sdk-overrides/include/stdlib.h b/sdk-overrides/include/stdlib.h index a420d3cad5..276ca77b72 100644 --- a/sdk-overrides/include/stdlib.h +++ b/sdk-overrides/include/stdlib.h @@ -2,7 +2,7 @@ #define _OVERRIDE_STDLIB_H_ #include_next "stdlib.h" - +#include #include "mem.h" #define free os_free diff --git a/sdk-overrides/include/user_interface.h b/sdk-overrides/include/user_interface.h index 200ee6df53..267abf63ad 100644 --- a/sdk-overrides/include/user_interface.h +++ b/sdk-overrides/include/user_interface.h @@ -1,6 +1,10 @@ #ifndef SDK_OVERRIDES_INCLUDE_USER_INTERFACE_H_ #define SDK_OVERRIDES_INCLUDE_USER_INTERFACE_H_ +#include +#include +#include + #include_next "user_interface.h" bool wifi_softap_deauth(uint8 mac[6]); From 98c2c0520d221d9fbbb2107d7273cd64af3535fd Mon Sep 17 00:00:00 2001 From: Terry Ellison Date: Tue, 23 Jul 2019 18:47:18 +0300 Subject: [PATCH 39/74] Dev make cleanup (#2842) --- Makefile | 130 ++++++++++++++++---------------- app/Makefile | 55 +++++--------- app/coap/Makefile | 4 - app/crypto/Makefile | 4 - app/dht/Makefile | 7 -- app/driver/Makefile | 3 - app/esp-gdbstub/Makefile | 2 - app/fatfs/Makefile | 5 -- app/http/Makefile | 5 -- app/libc/Makefile | 2 - app/lua/Makefile | 6 -- app/lua/luac_cross/Makefile | 2 +- app/lwip/Makefile | 14 ++-- app/lwip/api/Makefile | 2 - app/lwip/app/Makefile | 2 - app/lwip/core/Makefile | 2 - app/lwip/core/ipv4/Makefile | 2 - app/lwip/netif/Makefile | 2 - app/mbedtls/Makefile | 8 +- app/mbedtls/app/Makefile | 2 - app/mbedtls/library/Makefile | 2 - app/mbedtls/platform/Makefile | 2 - app/modules/Makefile | 22 +----- app/modules/coap.c | 12 +-- app/modules/dht.c | 2 +- app/modules/http.c | 2 +- app/modules/mqtt.c | 4 +- app/modules/pcm.c | 4 +- app/modules/sjson.c | 4 +- app/modules/sqlite3.c | 2 +- app/modules/websocket.c | 2 +- app/modules/wifi.c | 4 +- app/modules/wifi_eventmon.c | 2 +- app/mqtt/Makefile | 3 - app/net/Makefile | 3 - app/pcm/Makefile | 5 -- app/platform/Makefile | 8 +- app/pm/Makefile | 9 --- app/sjson/Makefile | 5 -- app/smart/Makefile | 3 - app/spiffs/Makefile | 4 - app/sqlite3/Makefile | 5 +- app/task/Makefile | 3 - app/tsl2561/Makefile | 7 -- app/u8g2lib/Makefile | 4 - app/ucglib/Makefile | 3 - app/user/Makefile | 6 -- app/user/dbg_printf.c | 1 + app/uzlib/Makefile | 3 - app/websocket/Makefile | 6 -- sdk-overrides/include/c_types.h | 1 + sdk-overrides/include/espconn.h | 1 + sdk-overrides/include/mem.h | 1 + sdk-overrides/include/osapi.h | 1 + tools/Makefile | 10 +-- tools/spiffsimg/Makefile | 6 +- 56 files changed, 135 insertions(+), 286 deletions(-) create mode 120000 sdk-overrides/include/espconn.h diff --git a/Makefile b/Makefile index 052908ff3e..4e796ed2c6 100644 --- a/Makefile +++ b/Makefile @@ -29,14 +29,15 @@ else endif SDK_REL_DIR := sdk/esp_iot_sdk_v$(SDK_VER) SDK_DIR := $(TOP_DIR)/$(SDK_REL_DIR) +APP_DIR := $(TOP_DIR)/app ESPTOOL_VER := 2.6 -# Ensure that the Espresif SDK is searched before the tool-chain's SDK (if any) -# Also, prevent the SDK's c_types.h from being included from anywhere, by -# predefining its include-guard. -CCFLAGS:= -I$(TOP_DIR)/sdk-overrides/include -I$(TOP_DIR)/app/include/lwip/app -I$(SDK_DIR)/include -D_C_TYPES_H_ -LDFLAGS:= -L$(SDK_DIR)/lib -L$(SDK_DIR)/ld $(LDFLAGS) +# Ensure that the Espresif SDK is search before application paths and also prevent +# the SDK's c_types.h from being included from anywhere, by predefining its include-guard. + +CCFLAGS := $(CCFLAGS) -I $(PDIR)sdk-overrides/include -I $(SDK_DIR)/include -D_C_TYPES_H_ +LDFLAGS := -L$(SDK_DIR)/lib -L$(SDK_DIR)/ld $(LDFLAGS) ifdef DEBUG CCFLAGS += -ggdb -O0 @@ -61,18 +62,18 @@ else endif # $(V)==1 ifndef BAUDRATE - BAUDRATE=115200 + BAUDRATE=115200 endif ############################################################# # Select compile # -# ** HEALTH WARNING ** This section is largely legacy directives left over from +# ** HEALTH WARNING ** This section is largely legacy directives left over from # an Espressif template. As far as I (TerrryE) know, we've only used the Linux # Path. I have successfully build AMD and Intel (both x86, AMD64) and RPi ARM6 # all under Ubuntu. Our docker container runs on Windows in an Ubuntu VM. # Johny Mattson maintains a prebuild AMD64 xtensa cross-compile gcc v4.8.5 -# toolchain which is compatible with the non-OS SDK and can be used on any recent +# toolchain which is compatible with the non-OS SDK and can be used on any recent # Ubuntu version including the Docker and Travis build environments. # # You have the option to build your own toolchain and specify a TOOLCHAIN_ROOT @@ -80,7 +81,7 @@ endif # architecture is compatable then you can omit this variable and the make will # download and use this prebuilt toolchain. # -# If any developers wish to develop, test and support alternative environments +# If any developers wish to develop, test and support alternative environments # then please raise a GitHub issue on this work. # @@ -95,39 +96,39 @@ endif ifneq (,$(findstring indows,$(OS))) #------------ BEGIN UNTESTED ------------ We are not under Linux, e.g.under windows. - ifeq ($(XTENSA_CORE),lx106) - # It is xcc - AR = xt-ar - CC = xt-xcc - CXX = xt-xcc - NM = xt-nm - CPP = xt-cpp - OBJCOPY = xt-objcopy - #MAKE = xt-make - CCFLAGS += --rename-section .text=.irom0.text --rename-section .literal=.irom0.literal - else - # It is gcc, may be cygwin - # Can we use -fdata-sections? - CCFLAGS += -ffunction-sections -fno-jump-tables -fdata-sections - AR = xtensa-lx106-elf-ar - CC = xtensa-lx106-elf-gcc - CXX = xtensa-lx106-elf-g++ - NM = xtensa-lx106-elf-nm - CPP = xtensa-lx106-elf-cpp - OBJCOPY = xtensa-lx106-elf-objcopy - endif - FIRMWAREDIR = ..\\bin\\ - ifndef COMPORT - ESPPORT = com1 - else - ESPPORT = $(COMPORT) - endif - ifeq ($(PROCESSOR_ARCHITECTURE),AMD64) + ifeq ($(XTENSA_CORE),lx106) + # It is xcc + AR = xt-ar + CC = xt-xcc + CXX = xt-xcc + NM = xt-nm + CPP = xt-cpp + OBJCOPY = xt-objcopy + #MAKE = xt-make + CCFLAGS += --rename-section .text=.irom0.text --rename-section .literal=.irom0.literal + else + # It is gcc, may be cygwin + # Can we use -fdata-sections? + CCFLAGS += -ffunction-sections -fno-jump-tables -fdata-sections + AR = xtensa-lx106-elf-ar + CC = xtensa-lx106-elf-gcc + CXX = xtensa-lx106-elf-g++ + NM = xtensa-lx106-elf-nm + CPP = xtensa-lx106-elf-cpp + OBJCOPY = xtensa-lx106-elf-objcopy + endif + FIRMWAREDIR = ..\\bin\\ + ifndef COMPORT + ESPPORT = com1 + else + ESPPORT = $(COMPORT) + endif + ifeq ($(PROCESSOR_ARCHITECTURE),AMD64) # ->AMD64 - endif - ifeq ($(PROCESSOR_ARCHITECTURE),x86) + endif + ifeq ($(PROCESSOR_ARCHITECTURE),x86) # ->IA32 - endif + endif #---------------- END UNTESTED ---------------- We are under windows. else # We are under other system, may be Linux. Assume using gcc. @@ -141,23 +142,23 @@ else TOOLCHAIN_ROOT = $(TOP_DIR)/tools/toolchains/esp8266-$(GCCTOOLCHAIN) GITHUB_TOOLCHAIN = https://github.com/jmattsson/esp-toolchains export PATH:=$(PATH):$(TOOLCHAIN_ROOT)/bin - endif - endif - - ifndef COMPORT - ESPPORT = /dev/ttyUSB0 - else - ESPPORT = $(COMPORT) - endif - - CCFLAGS += -ffunction-sections -fno-jump-tables -fdata-sections - AR = xtensa-lx106-elf-ar - CC = $(WRAPCC) xtensa-lx106-elf-gcc - CXX = $(WRAPCC) xtensa-lx106-elf-g++ - NM = xtensa-lx106-elf-nm - CPP = $(WRAPCC) xtensa-lx106-elf-gcc -E - OBJCOPY = xtensa-lx106-elf-objcopy - FIRMWAREDIR = ../bin/ + endif + endif + + ifndef COMPORT + ESPPORT = /dev/ttyUSB0 + else + ESPPORT = $(COMPORT) + endif + + CCFLAGS += -ffunction-sections -fno-jump-tables -fdata-sections + AR = xtensa-lx106-elf-ar + CC = $(WRAPCC) xtensa-lx106-elf-gcc + CXX = $(WRAPCC) xtensa-lx106-elf-g++ + NM = xtensa-lx106-elf-nm + CPP = $(WRAPCC) xtensa-lx106-elf-gcc -E + OBJCOPY = xtensa-lx106-elf-objcopy + FIRMWAREDIR = ../bin/ WGET = wget --tries=10 --timeout=15 --waitretry=30 --read-timeout=20 --retry-connrefused endif @@ -221,7 +222,7 @@ CCFLAGS += \ -fno-inline-functions \ -nostdlib \ -mlongcalls \ - -mtext-section-literals + -mtext-section-literals \ # -Wall CFLAGS = $(CCFLAGS) $(DEFINES) $(EXTRA_CCFLAGS) $(STD_CFLAGS) $(INCLUDES) @@ -370,7 +371,7 @@ flash1m-dout: flashinternal: ifndef PDIR - $(MAKE) -C ./app flashinternal + $(MAKE) -C $(APP_DIR) flashinternal else $(ESPTOOL) --port $(ESPPORT) --baud $(BAUDRATE) write_flash $(FLASHOPTIONS) 0x00000 $(FIRMWAREDIR)0x00000.bin 0x10000 $(FIRMWAREDIR)0x10000.bin endif @@ -395,20 +396,20 @@ spiffs-image-remove: spiffs-image: bin/0x10000.bin $(MAKE) -C tools - +############ Note: this target needs moving into app/modules make ############ .PHONY: pre_build ifneq ($(wildcard $(TOP_DIR)/server-ca.crt),) -pre_build: $(TOP_DIR)/app/modules/server-ca.crt.h +pre_build: $(APP_DIR)/modules/server-ca.crt.h -$(TOP_DIR)/app/modules/server-ca.crt.h: $(TOP_DIR)/server-ca.crt +$(APP_DIR)/modules/server-ca.crt.h: $(TOP_DIR)/server-ca.crt $(summary) MKCERT $(patsubst $(TOP_DIR)/%,%,$<) - python $(TOP_DIR)/tools/make_server_cert.py $(TOP_DIR)/server-ca.crt > $(TOP_DIR)/app/modules/server-ca.crt.h + python $(TOP_DIR)/tools/make_server_cert.py $(TOP_DIR)/server-ca.crt > $(APP_DIR)/modules/server-ca.crt.h DEFINES += -DHAVE_SSL_SERVER_CRT=\"server-ca.crt.h\" else pre_build: - @-rm -f $(TOP_DIR)/app/modules/server-ca.crt.h + @-rm -f $(APP_DIR)/modules/server-ca.crt.h endif ifdef TARGET @@ -484,6 +485,5 @@ endif # TARGET # Required for each makefile to inherit from the parent # -INCLUDES := $(INCLUDES) -I $(PDIR)include -I $(PDIR)include/$(TARGET) PDIR := ../$(PDIR) sinclude $(PDIR)Makefile diff --git a/app/Makefile b/app/Makefile index 897b3f8b04..4fab0eedaa 100644 --- a/app/Makefile +++ b/app/Makefile @@ -15,8 +15,6 @@ TARGET = eagle #FLAVOR = release FLAVOR = debug -#EXTRA_CCFLAGS += -u - ifndef PDIR # { GEN_IMAGES= eagle.app.v6.out GEN_BINS= eagle.app.v6.bin @@ -42,10 +40,10 @@ SUBDIRS= \ smart \ modules \ spiffs \ - net \ + net \ fatfs \ esp-gdbstub \ - pm \ + pm \ uzlib \ $(OPT_SEL_MKTARGETS) @@ -54,19 +52,19 @@ endif # } PDIR APPDIR = . LDDIR = ../ld -TARGET_LDFLAGS = \ +TARGET_LDFLAGS = \ -nostdlib \ -Wl,-EL \ - --longcalls \ + --longcalls \ --text-section-literals LD_FILE = $(LDDIR)/nodemcu.ld -COMPONENTS_eagle.app.v6 = \ +COMPONENTS_eagle.app.v6 = \ user/libuser.a \ crypto/libcrypto.a \ driver/libdriver.a \ - platform/libplatform.a \ + platform/libplatform.a \ task/libtask.a \ libc/liblibc.a \ lua/liblua.a \ @@ -74,16 +72,15 @@ COMPONENTS_eagle.app.v6 = \ smart/smart.a \ spiffs/spiffs.a \ fatfs/libfatfs.a \ - pm/libpm.a \ - esp-gdbstub/libgdbstub.a \ - net/libnodemcu_net.a \ - mbedtls/libmbedtls.a \ - modules/libmodules.a \ + pm/libpm.a \ + esp-gdbstub/libgdbstub.a \ + net/libnodemcu_net.a \ + mbedtls/libmbedtls.a \ + modules/libmodules.a \ smart/smart.a \ uzlib/libuzlib.a \ $(OPT_SEL_COMPONENTS) - # 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 @@ -134,27 +131,15 @@ DEPENDS_eagle.app.v6 = \ #UNIVERSAL_TARGET_DEFINES = \ -# Other potential configuration flags include: -# -DTXRX_TXBUF_DEBUG -# -DTXRX_RXBUF_DEBUG -# -DWLAN_CONFIG_CCX -CONFIGURATION_DEFINES = -D__ets__ \ - -DICACHE_FLASH \ - -DLWIP_OPEN_SRC \ - -DPBUF_RSV_FOR_WLAN \ - -DEBUF_LWIP \ - -DUSE_OPTIMIZE_PRINTF \ - -DMBEDTLS_USER_CONFIG_FILE=\"user_mbedtls.h\" \ - -DMEM_DEFAULT_USE_DRAM - -DEFINES += \ - $(UNIVERSAL_TARGET_DEFINES) \ - $(CONFIGURATION_DEFINES) +CONFIGURATION_DEFINES += -DLWIP_OPEN_SRC -DDEFINES += \ - $(UNIVERSAL_TARGET_DEFINES) \ +DEFINES += \ + $(UNIVERSAL_TARGET_DEFINES) \ $(CONFIGURATION_DEFINES) +DDEFINES += \ + $(UNIVERSAL_TARGET_DEFINES) \ + $(CONFIGURATION_DEFINES) ############################################################# # Recursion Magic - Don't touch this!! @@ -167,10 +152,10 @@ DDEFINES += \ # # Required for each makefile to inherit from the parent # - -INCLUDES := $(INCLUDES) -I $(PDIR)include -INCLUDES += -I ./ +INCLUDES := -I $(PDIR)libc -I $(PDIR)lua -I $(PDIR)platform \ + $(INCLUDES) -I $(PDIR) -I $(PDIR)include PDIR := ../$(PDIR) + sinclude $(PDIR)Makefile .PHONY: FORCE diff --git a/app/coap/Makefile b/app/coap/Makefile index 89ea3b4356..6ad9dcc9f0 100644 --- a/app/coap/Makefile +++ b/app/coap/Makefile @@ -36,10 +36,6 @@ endif # Required for each makefile to inherit from the parent # -INCLUDES := $(INCLUDES) -I $(PDIR)include -INCLUDES += -I ./ -INCLUDES += -I ../libc -INCLUDES += -I ../lua PDIR := ../$(PDIR) sinclude $(PDIR)Makefile diff --git a/app/crypto/Makefile b/app/crypto/Makefile index e472e6d630..17c7713499 100644 --- a/app/crypto/Makefile +++ b/app/crypto/Makefile @@ -38,10 +38,6 @@ STD_CFLAGS=-std=gnu11 -Wimplicit # Required for each makefile to inherit from the parent # -INCLUDES := $(INCLUDES) -I $(PDIR)include -INCLUDES += -I ./ -INCLUDES += -I ../libc -INCLUDES += -I ../platform PDIR := ../$(PDIR) sinclude $(PDIR)Makefile diff --git a/app/dht/Makefile b/app/dht/Makefile index 2da62da8a9..5bb139ffbc 100644 --- a/app/dht/Makefile +++ b/app/dht/Makefile @@ -37,13 +37,6 @@ endif # Required for each makefile to inherit from the parent # -INCLUDES := $(INCLUDES) -I $(PDIR)include -INCLUDES += -I ./ -INCLUDES += -I ./include -INCLUDES += -I ../include -INCLUDES += -I ../../include -INCLUDES += -I ../libc -INCLUDES += -I ../platform PDIR := ../$(PDIR) sinclude $(PDIR)Makefile diff --git a/app/driver/Makefile b/app/driver/Makefile index a3f1515645..5dbd685374 100644 --- a/app/driver/Makefile +++ b/app/driver/Makefile @@ -38,9 +38,6 @@ STD_CFLAGS=-std=gnu11 -Wimplicit # Required for each makefile to inherit from the parent # -INCLUDES := $(INCLUDES) -I $(PDIR)include -INCLUDES += -I ./ -INCLUDES += -I ../platform PDIR := ../$(PDIR) sinclude $(PDIR)Makefile diff --git a/app/esp-gdbstub/Makefile b/app/esp-gdbstub/Makefile index 015e9df78f..f5f390ab6d 100644 --- a/app/esp-gdbstub/Makefile +++ b/app/esp-gdbstub/Makefile @@ -37,8 +37,6 @@ endif # Required for each makefile to inherit from the parent # -INCLUDES += -I $(PDIR)include -INCLUDES += -I ./ INCLUDES += -I ../../include/ets PDIR := ../$(PDIR) sinclude $(PDIR)Makefile diff --git a/app/fatfs/Makefile b/app/fatfs/Makefile index 33d242aefa..d1bca3e299 100644 --- a/app/fatfs/Makefile +++ b/app/fatfs/Makefile @@ -42,11 +42,6 @@ STD_CFLAGS=-std=gnu11 -Wimplicit -imacros $(FATFS_INC_DIR)fatfs_prefix_lib.h # Required for each makefile to inherit from the parent # -INCLUDES := $(INCLUDES) -I $(PDIR)include -INCLUDES += -I ./ -INCLUDES += -I ../platform -INCLUDES += -I ../libc -INCLUDES += -I ../lua PDIR := ../$(PDIR) sinclude $(PDIR)Makefile diff --git a/app/http/Makefile b/app/http/Makefile index e4a184ef82..963cf28c93 100644 --- a/app/http/Makefile +++ b/app/http/Makefile @@ -38,11 +38,6 @@ STD_CFLAGS=-std=gnu11 -Wimplicit # Required for each makefile to inherit from the parent # -INCLUDES := $(INCLUDES) -I $(PDIR)include -INCLUDES += -I ./ -INCLUDES += -I ./include -INCLUDES += -I ../include -INCLUDES += -I ../../include PDIR := ../$(PDIR) sinclude $(PDIR)Makefile diff --git a/app/libc/Makefile b/app/libc/Makefile index 9bc7eb8725..dfb6232d80 100644 --- a/app/libc/Makefile +++ b/app/libc/Makefile @@ -36,8 +36,6 @@ endif # Required for each makefile to inherit from the parent # -INCLUDES := $(INCLUDES) -I $(PDIR)include -INCLUDES += -I ./ PDIR := ../$(PDIR) sinclude $(PDIR)Makefile diff --git a/app/lua/Makefile b/app/lua/Makefile index 059f69e260..16d97ab05d 100644 --- a/app/lua/Makefile +++ b/app/lua/Makefile @@ -40,12 +40,6 @@ STD_CFLAGS=-std=gnu11 -Wimplicit # Required for each makefile to inherit from the parent # -INCLUDES := $(INCLUDES) -I $(PDIR)include -INCLUDES += -I ./ -INCLUDES += -I ../spiffs -INCLUDES += -I ../libc -INCLUDES += -I ../modules -INCLUDES += -I ../platform INCLUDES += -I ../uzlib PDIR := ../$(PDIR) sinclude $(PDIR)Makefile diff --git a/app/lua/luac_cross/Makefile b/app/lua/luac_cross/Makefile index 984d2b6594..2589b63b5d 100644 --- a/app/lua/luac_cross/Makefile +++ b/app/lua/luac_cross/Makefile @@ -53,7 +53,7 @@ CC := $(WRAPCC) gcc ECHO := echo -BUILD_TYPE := $(shell $(CC) $(EXTRA_CCFLAGS) -E -dM - <../../../app/include/user_config.h | grep LUA_NUMBER_INTEGRAL | wc -l) +BUILD_TYPE := $(shell $(CC) $(EXTRA_CCFLAGS) -E -dM - <../../include/user_config.h | grep LUA_NUMBER_INTEGRAL | wc -l) ifeq ($(BUILD_TYPE),0) IMAGE := ../../../luac.cross else diff --git a/app/lwip/Makefile b/app/lwip/Makefile index 461a7c947f..a8b25699cd 100644 --- a/app/lwip/Makefile +++ b/app/lwip/Makefile @@ -14,9 +14,9 @@ ifndef PDIR UP_EXTRACT_DIR = .. GEN_LIBS = liblwip.a -COMPONENTS_liblwip = api/liblwipapi.a \ - app/liblwipapp.a \ - core/liblwipcore.a \ +COMPONENTS_liblwip = api/liblwipapi.a \ + app/liblwipapp.a \ + core/liblwipcore.a \ core/ipv4/liblwipipv4.a \ netif/liblwipnetif.a endif @@ -29,7 +29,11 @@ endif # makefile at its root level - these are then overridden # for a subtree within the makefile rooted therein # -#DEFINES += +# Other potential configuration flags include: +# -DTXRX_TXBUF_DEBUG +# -DTXRX_RXBUF_DEBUG +# -DWLAN_CONFIG_CCX +CONFIGURATION_DEFINES += -DPBUF_RSV_FOR_WLAN -DEBUF_LWIP ############################################################# # Recursion Magic - Don't touch this!! @@ -43,8 +47,6 @@ endif # Required for each makefile to inherit from the parent # -INCLUDES := $(INCLUDES) -I $(PDIR)include -INCLUDES += -I ./ PDIR := ../$(PDIR) sinclude $(PDIR)Makefile diff --git a/app/lwip/api/Makefile b/app/lwip/api/Makefile index 95abe4b63a..cecc962e6d 100644 --- a/app/lwip/api/Makefile +++ b/app/lwip/api/Makefile @@ -39,8 +39,6 @@ endif # Required for each makefile to inherit from the parent # -INCLUDES := $(INCLUDES) -I $(PDIR)include -INCLUDES += -I ./ PDIR := ../$(PDIR) sinclude $(PDIR)Makefile diff --git a/app/lwip/app/Makefile b/app/lwip/app/Makefile index 8f5bef151b..943535771d 100644 --- a/app/lwip/app/Makefile +++ b/app/lwip/app/Makefile @@ -39,8 +39,6 @@ endif # Required for each makefile to inherit from the parent # -INCLUDES := $(INCLUDES) -I $(PDIR)include -INCLUDES += -I ./ PDIR := ../$(PDIR) sinclude $(PDIR)Makefile diff --git a/app/lwip/core/Makefile b/app/lwip/core/Makefile index e3cd64dfb2..b3fc4f67f3 100644 --- a/app/lwip/core/Makefile +++ b/app/lwip/core/Makefile @@ -39,8 +39,6 @@ endif # Required for each makefile to inherit from the parent # -INCLUDES := $(INCLUDES) -I $(PDIR)include -INCLUDES += -I ./ PDIR := ../$(PDIR) sinclude $(PDIR)Makefile diff --git a/app/lwip/core/ipv4/Makefile b/app/lwip/core/ipv4/Makefile index 51c595434b..4570cf5541 100644 --- a/app/lwip/core/ipv4/Makefile +++ b/app/lwip/core/ipv4/Makefile @@ -39,8 +39,6 @@ endif # Required for each makefile to inherit from the parent # -INCLUDES := $(INCLUDES) -I $(PDIR)include -INCLUDES += -I ./ PDIR := ../$(PDIR) sinclude $(PDIR)Makefile diff --git a/app/lwip/netif/Makefile b/app/lwip/netif/Makefile index 368e0d2173..ecdffab845 100644 --- a/app/lwip/netif/Makefile +++ b/app/lwip/netif/Makefile @@ -39,8 +39,6 @@ endif # Required for each makefile to inherit from the parent # -INCLUDES := $(INCLUDES) -I $(PDIR)include -INCLUDES += -I ./ PDIR := ../$(PDIR) sinclude $(PDIR)Makefile diff --git a/app/mbedtls/Makefile b/app/mbedtls/Makefile index 9af2841faa..462821364f 100644 --- a/app/mbedtls/Makefile +++ b/app/mbedtls/Makefile @@ -14,7 +14,9 @@ ifndef PDIR UP_EXTRACT_DIR = .. GEN_LIBS = libmbedtls.a -COMPONENTS_libmbedtls = library/liblibrary.a platform/libplatform.a app/libapp.a +COMPONENTS_libmbedtls = library/liblibrary.a \ + platform/libplatform.a \ + app/libapp.a endif @@ -26,7 +28,7 @@ endif # for a subtree within the makefile rooted therein # DEFINES += -#CCFLAGS += --rename-section .text=.irom0.text --rename-section .literal=.irom0.literal +CONFIGURATION_DEFINES += -DMBEDTLS_USER_CONFIG_FILE=\"user_mbedtls.h\" ############################################################# # Recursion Magic - Don't touch this!! @@ -40,8 +42,6 @@ DEFINES += # Required for each makefile to inherit from the parent # -INCLUDES := $(INCLUDES) -I $(PDIR)include -INCLUDES += -I ./ PDIR := ../$(PDIR) sinclude $(PDIR)Makefile diff --git a/app/mbedtls/app/Makefile b/app/mbedtls/app/Makefile index 6bdb009f00..fa5dc92fd6 100644 --- a/app/mbedtls/app/Makefile +++ b/app/mbedtls/app/Makefile @@ -39,8 +39,6 @@ endif # Required for each makefile to inherit from the parent # -INCLUDES := $(INCLUDES) -I $(PDIR)include -INCLUDES += -I ./ PDIR := ../$(PDIR) sinclude $(PDIR)Makefile diff --git a/app/mbedtls/library/Makefile b/app/mbedtls/library/Makefile index d746b86064..7c74cde44a 100644 --- a/app/mbedtls/library/Makefile +++ b/app/mbedtls/library/Makefile @@ -39,8 +39,6 @@ endif # Required for each makefile to inherit from the parent # -INCLUDES := $(INCLUDES) -I $(PDIR)include -INCLUDES += -I ./ PDIR := ../$(PDIR) sinclude $(PDIR)Makefile diff --git a/app/mbedtls/platform/Makefile b/app/mbedtls/platform/Makefile index 72136eee92..5d1d15646c 100644 --- a/app/mbedtls/platform/Makefile +++ b/app/mbedtls/platform/Makefile @@ -39,8 +39,6 @@ endif # Required for each makefile to inherit from the parent # -INCLUDES := $(INCLUDES) -I $(PDIR)include -INCLUDES += -I ./ PDIR := ../$(PDIR) sinclude $(PDIR)Makefile diff --git a/app/modules/Makefile b/app/modules/Makefile index 1387c8407b..db18e74399 100644 --- a/app/modules/Makefile +++ b/app/modules/Makefile @@ -25,6 +25,7 @@ STD_CFLAGS=-std=gnu11 -Wimplicit # for a subtree within the makefile rooted therein # #DEFINES += +CONFIGURATION_DEFINES += -DMBEDTLS_USER_CONFIG_FILE=\"user_mbedtls.h\" ############################################################# # Recursion Magic - Don't touch this!! @@ -38,25 +39,8 @@ STD_CFLAGS=-std=gnu11 -Wimplicit # Required for each makefile to inherit from the parent # -INCLUDES := $(INCLUDES) -I $(PDIR)include -INCLUDES += -I ./ -INCLUDES += -I ../libc -INCLUDES += -I ../coap -INCLUDES += -I ../mqtt -INCLUDES += -I ../u8g2lib/u8g2/src/clib -INCLUDES += -I ../ucglib/ucg/src/clib -INCLUDES += -I ../lua -INCLUDES += -I ../pcm -INCLUDES += -I ../platform -INCLUDES += -I ../spiffs -INCLUDES += -I ../smart -INCLUDES += -I ../dht -INCLUDES += -I ../fatfs -INCLUDES += -I ../http -INCLUDES += -I ../sjson -INCLUDES += -I ../websocket -INCLUDES += -I ../pm -INCLUDES += -I ../sqlite3 +INCLUDES += -I ../u8g2lib/u8g2/src/clib -I ../ucglib/ucg/src/clib + PDIR := ../$(PDIR) sinclude $(PDIR)Makefile diff --git a/app/modules/coap.c b/app/modules/coap.c index a50a086f01..0c37af48b6 100644 --- a/app/modules/coap.c +++ b/app/modules/coap.c @@ -13,12 +13,12 @@ #include "espconn.h" #include "driver/uart.h" -#include "coap.h" -#include "uri.h" -#include "node.h" -#include "coap_timer.h" -#include "coap_io.h" -#include "coap_server.h" +#include "coap/coap.h" +#include "coap/uri.h" +#include "coap/node.h" +#include "coap/coap_timer.h" +#include "coap/coap_io.h" +#include "coap/coap_server.h" coap_queue_t *gQueue = NULL; diff --git a/app/modules/dht.c b/app/modules/dht.c index 85e2bdfb65..7e3e4f1d6f 100644 --- a/app/modules/dht.c +++ b/app/modules/dht.c @@ -4,7 +4,7 @@ #include "lauxlib.h" #include "platform.h" #include "cpu_esp8266.h" -#include "dht.h" +#include "dht/dht.h" #define NUM_DHT GPIO_PIN_NUM diff --git a/app/modules/http.c b/app/modules/http.c index 0b37d5774a..fddc902a83 100644 --- a/app/modules/http.c +++ b/app/modules/http.c @@ -8,7 +8,7 @@ #include "lauxlib.h" #include "platform.h" #include "cpu_esp8266.h" -#include "httpclient.h" +#include "http/httpclient.h" static int http_callback_registry = LUA_NOREF; diff --git a/app/modules/mqtt.c b/app/modules/mqtt.c index dcb25005bb..035c005932 100644 --- a/app/modules/mqtt.c +++ b/app/modules/mqtt.c @@ -12,8 +12,8 @@ #include "lwip/ip_addr.h" #include "espconn.h" -#include "mqtt_msg.h" -#include "msg_queue.h" +#include "mqtt/mqtt_msg.h" +#include "mqtt/msg_queue.h" #include "user_interface.h" diff --git a/app/modules/pcm.c b/app/modules/pcm.c index f9056bcd78..55c85bd437 100644 --- a/app/modules/pcm.c +++ b/app/modules/pcm.c @@ -6,8 +6,8 @@ #include #include -#include "pcm.h" -#include "pcm_drv.h" +#include "pcm/pcm.h" +#include "pcm/pcm_drv.h" #define GET_PUD() pud_t *pud = (pud_t *)luaL_checkudata(L, 1, "pcm.driver"); \ diff --git a/app/modules/sjson.c b/app/modules/sjson.c index 530dfb25b1..cc39cedfc6 100644 --- a/app/modules/sjson.c +++ b/app/modules/sjson.c @@ -11,8 +11,8 @@ #include #endif -#include "json_config.h" -#include "jsonsl.h" +#include "sjson/json_config.h" +#include "sjson/jsonsl.h" #define LUA_SJSONLIBNAME "sjson" diff --git a/app/modules/sqlite3.c b/app/modules/sqlite3.c index c842249813..d5fa464832 100644 --- a/app/modules/sqlite3.c +++ b/app/modules/sqlite3.c @@ -59,7 +59,7 @@ #endif #endif -#include "sqlite3.h" +#include "sqlite3/sqlite3.h" /* compile time features */ #if !defined(SQLITE_OMIT_PROGRESS_CALLBACK) diff --git a/app/modules/websocket.c b/app/modules/websocket.c index 71ecd67ae9..d7b840ea3f 100644 --- a/app/modules/websocket.c +++ b/app/modules/websocket.c @@ -17,7 +17,7 @@ #include #include -#include "websocketclient.h" +#include "websocket/websocketclient.h" #define METATABLE_WSCLIENT "websocket.client" diff --git a/app/modules/wifi.c b/app/modules/wifi.c index 6e5b6d0231..7d5766a575 100644 --- a/app/modules/wifi.c +++ b/app/modules/wifi.c @@ -16,8 +16,8 @@ #ifdef WIFI_SMART_ENABLE -#include "smart.h" -#include "smartconfig.h" +#include "smart/smart.h" +#include "smart/smartconfig.h" static int wifi_smart_succeed = LUA_NOREF; #endif diff --git a/app/modules/wifi_eventmon.c b/app/modules/wifi_eventmon.c index f5d87170f1..0989c7d417 100644 --- a/app/modules/wifi_eventmon.c +++ b/app/modules/wifi_eventmon.c @@ -9,7 +9,7 @@ #include #include "user_interface.h" -#include "smart.h" +#include "smart/smart.h" #include "smartconfig.h" #include "user_config.h" diff --git a/app/mqtt/Makefile b/app/mqtt/Makefile index a0fde1e7a0..c47de52b81 100644 --- a/app/mqtt/Makefile +++ b/app/mqtt/Makefile @@ -38,9 +38,6 @@ STD_CFLAGS=-std=gnu11 -Wimplicit # Required for each makefile to inherit from the parent # -INCLUDES := $(INCLUDES) -I $(PDIR)include -INCLUDES += -I ./ -INCLUDES += -I ../libc PDIR := ../$(PDIR) sinclude $(PDIR)Makefile diff --git a/app/net/Makefile b/app/net/Makefile index 1c9cdcf61b..d67ec5c2f3 100644 --- a/app/net/Makefile +++ b/app/net/Makefile @@ -36,9 +36,6 @@ endif # Required for each makefile to inherit from the parent # -INCLUDES := $(INCLUDES) -I $(PDIR)include -INCLUDES += -I ./ -INCLUDES += -I ../libc PDIR := ../$(PDIR) sinclude $(PDIR)Makefile diff --git a/app/pcm/Makefile b/app/pcm/Makefile index 4beb5794a0..9cb5272ce6 100644 --- a/app/pcm/Makefile +++ b/app/pcm/Makefile @@ -38,10 +38,5 @@ STD_CFLAGS=-std=gnu11 -Wimplicit # Required for each makefile to inherit from the parent # -INCLUDES := $(INCLUDES) -I $(PDIR)include -INCLUDES += -I ./ -INCLUDES += -I ../lua -INCLUDES += -I ../libc -INCLUDES += -I ../platform PDIR := ../$(PDIR) sinclude $(PDIR)Makefile diff --git a/app/platform/Makefile b/app/platform/Makefile index 07bb225c5b..b8cadc7a86 100644 --- a/app/platform/Makefile +++ b/app/platform/Makefile @@ -38,13 +38,7 @@ STD_CFLAGS=-std=gnu11 -Wimplicit # Required for each makefile to inherit from the parent # -INCLUDES := $(INCLUDES) -I $(PDIR)include -INCLUDES += -I ./ -INCLUDES += -I ../spiffs -INCLUDES += -I ../libc -INCLUDES += -I ../lua -INCLUDES += -I ../u8g2lib/u8g2/src/clib -INCLUDES += -I ../ucglib/ucg/src/clib +INCLUDES += -I ../spiffs -I ../u8g2lib/u8g2/src/clib -I ../ucglib/ucg/src/clib PDIR := ../$(PDIR) sinclude $(PDIR)Makefile diff --git a/app/pm/Makefile b/app/pm/Makefile index b338250b44..de66032d74 100644 --- a/app/pm/Makefile +++ b/app/pm/Makefile @@ -38,15 +38,6 @@ STD_CFLAGS=-std=gnu11 -Wimplicit # Required for each makefile to inherit from the parent # -INCLUDES := $(INCLUDES) -I $(PDIR)include -INCLUDES += -I ./ -INCLUDES += -I ./include -INCLUDES += -I ../include -INCLUDES += -I ../../include -INCLUDES += -I ../lua -INCLUDES += -I ../platform -INCLUDES += -I ../libc - PDIR := ../$(PDIR) sinclude $(PDIR)Makefile diff --git a/app/sjson/Makefile b/app/sjson/Makefile index a439800492..6e44131900 100644 --- a/app/sjson/Makefile +++ b/app/sjson/Makefile @@ -37,11 +37,6 @@ DEFINES += -include memcompat.h -include json_config.h # Required for each makefile to inherit from the parent # -INCLUDES := $(INCLUDES) -I $(PDIR)include -INCLUDES += -I ./ -INCLUDES += -I ./include -INCLUDES += -I ../include -INCLUDES += -I ../../include PDIR := ../$(PDIR) sinclude $(PDIR)Makefile diff --git a/app/smart/Makefile b/app/smart/Makefile index 635d27b891..4259ecd65d 100644 --- a/app/smart/Makefile +++ b/app/smart/Makefile @@ -36,9 +36,6 @@ endif # Required for each makefile to inherit from the parent # -INCLUDES := $(INCLUDES) -I $(PDIR)include -INCLUDES += -I ./ -INCLUDES += -I ../libc PDIR := ../$(PDIR) sinclude $(PDIR)Makefile diff --git a/app/spiffs/Makefile b/app/spiffs/Makefile index 688bc9f35c..b7b6b9b959 100644 --- a/app/spiffs/Makefile +++ b/app/spiffs/Makefile @@ -36,9 +36,5 @@ endif # Required for each makefile to inherit from the parent # -INCLUDES := $(INCLUDES) -I $(PDIR)include -INCLUDES += -I ./ -INCLUDES += -I ../libc -INCLUDES += -I ../platform PDIR := ../$(PDIR) sinclude $(PDIR)Makefile diff --git a/app/sqlite3/Makefile b/app/sqlite3/Makefile index 2b5339b4db..fcaa2a433a 100644 --- a/app/sqlite3/Makefile +++ b/app/sqlite3/Makefile @@ -38,9 +38,6 @@ STD_CFLAGS= -std=gnu11 -Wimplicit -Wno-undef -include config_ext.h # Required for each makefile to inherit from the parent # -INCLUDES := $(INCLUDES) -I $(PDIR)include -INCLUDES += -I ./ -INCLUDES += -I ../libc -INCLUDES += -I ../platform +INCLUDES += -I . PDIR := ../$(PDIR) sinclude $(PDIR)Makefile diff --git a/app/task/Makefile b/app/task/Makefile index 24a454fe4f..b7db4b50c0 100644 --- a/app/task/Makefile +++ b/app/task/Makefile @@ -36,9 +36,6 @@ endif # Required for each makefile to inherit from the parent # -INCLUDES := $(INCLUDES) -I $(PDIR)include -INCLUDES += -I ./ -INCLUDES += -I ../libc PDIR := ../$(PDIR) sinclude $(PDIR)Makefile diff --git a/app/tsl2561/Makefile b/app/tsl2561/Makefile index 48dfef98f1..b964831680 100644 --- a/app/tsl2561/Makefile +++ b/app/tsl2561/Makefile @@ -38,13 +38,6 @@ STD_CFLAGS=-std=gnu11 -Wimplicit # Required for each makefile to inherit from the parent # -INCLUDES := $(INCLUDES) -I $(PDIR)include -INCLUDES += -I ./ -INCLUDES += -I ./include -INCLUDES += -I ../include -INCLUDES += -I ../../include -INCLUDES += -I ../libc -INCLUDES += -I ../platform PDIR := ../$(PDIR) sinclude $(PDIR)Makefile diff --git a/app/u8g2lib/Makefile b/app/u8g2lib/Makefile index e1b0b82d76..173b5ce636 100644 --- a/app/u8g2lib/Makefile +++ b/app/u8g2lib/Makefile @@ -40,11 +40,7 @@ DEFINES += -DU8X8_USE_PINS -DU8G2_USE_LARGE_FONTS -DU8X8_WITH_USER_PTR CSRCS := $(wildcard u8g2/src/clib/*.c *.c) -INCLUDES := $(INCLUDES) -I $(PDIR)include INCLUDES += -I u8g2/src/clib -INCLUDES += -I ../libc -INCLUDES += -I ../lua -INCLUDES += -I ../platform PDIR := ../$(PDIR) sinclude $(PDIR)Makefile diff --git a/app/ucglib/Makefile b/app/ucglib/Makefile index ff257844d9..0e495e6e3e 100644 --- a/app/ucglib/Makefile +++ b/app/ucglib/Makefile @@ -40,10 +40,7 @@ DEFINES += -DUSE_PIN_LIST CSRCS := $(wildcard ucg/src/clib/*.c *.c) -INCLUDES := $(INCLUDES) -I $(PDIR)include INCLUDES += -I ucg/src/clib -INCLUDES += -I ./ -INCLUDES += -I ../libc PDIR := ../$(PDIR) sinclude $(PDIR)Makefile diff --git a/app/user/Makefile b/app/user/Makefile index 5ffdb00ac1..34e6446dd4 100644 --- a/app/user/Makefile +++ b/app/user/Makefile @@ -38,12 +38,6 @@ DEFINES += -DESP_INIT_DATA_DEFAULT="\"$(SDK_DIR)/bin/esp_init_data_default_v05.b # Required for each makefile to inherit from the parent # -INCLUDES := $(INCLUDES) -I $(PDIR)include -INCLUDES += -I ./ -INCLUDES += -I ../../include/ets -INCLUDES += -I ../libc -INCLUDES += -I ../platform -INCLUDES += -I ../lua INCLUDES += -I ../spiffs PDIR := ../$(PDIR) sinclude $(PDIR)Makefile diff --git a/app/user/dbg_printf.c b/app/user/dbg_printf.c index 6dcb5895c7..0be12d8a01 100644 --- a/app/user/dbg_printf.c +++ b/app/user/dbg_printf.c @@ -39,6 +39,7 @@ // overflows. The downside is that it does not implement a wide range // of formatting characters. +#include #include #include #include diff --git a/app/uzlib/Makefile b/app/uzlib/Makefile index 379af8bd14..5b3d1b54df 100644 --- a/app/uzlib/Makefile +++ b/app/uzlib/Makefile @@ -37,9 +37,6 @@ endif # Required for each makefile to inherit from the parent # -INCLUDES := $(INCLUDES) -I $(PDIR)include -INCLUDES += -I ./ -INCLUDES += -I ../libc PDIR := ../$(PDIR) sinclude $(PDIR)Makefile diff --git a/app/websocket/Makefile b/app/websocket/Makefile index 8a4a39d2a0..0c20357ab8 100644 --- a/app/websocket/Makefile +++ b/app/websocket/Makefile @@ -38,12 +38,6 @@ STD_CFLAGS=-std=gnu11 -Wimplicit # Required for each makefile to inherit from the parent # -INCLUDES := $(INCLUDES) -I $(PDIR)include -INCLUDES += -I ./ -INCLUDES += -I ./include -INCLUDES += -I ../include -INCLUDES += -I ../libc -INCLUDES += -I ../../include PDIR := ../$(PDIR) sinclude $(PDIR)Makefile diff --git a/sdk-overrides/include/c_types.h b/sdk-overrides/include/c_types.h index 6d4558024c..1657ced178 100644 --- a/sdk-overrides/include/c_types.h +++ b/sdk-overrides/include/c_types.h @@ -1,3 +1,4 @@ + #ifndef _SDKOVERRIDES_C_TYPES_H_ #define _SDKOVERRIDES_C_TYPES_H_ diff --git a/sdk-overrides/include/espconn.h b/sdk-overrides/include/espconn.h new file mode 120000 index 0000000000..401b860b6c --- /dev/null +++ b/sdk-overrides/include/espconn.h @@ -0,0 +1 @@ +../../app/include/lwip/app/espconn.h \ No newline at end of file diff --git a/sdk-overrides/include/mem.h b/sdk-overrides/include/mem.h index b55c7bd560..b0c9fcdd4e 100644 --- a/sdk-overrides/include/mem.h +++ b/sdk-overrides/include/mem.h @@ -1,2 +1,3 @@ #include +#define MEM_DEFAULT_USE_DRAM #include_next "mem.h" diff --git a/sdk-overrides/include/osapi.h b/sdk-overrides/include/osapi.h index c192fa0d88..9d736de409 100644 --- a/sdk-overrides/include/osapi.h +++ b/sdk-overrides/include/osapi.h @@ -4,6 +4,7 @@ #include #include #include +#define USE_OPTIMIZE_PRINTF #include_next "osapi.h" diff --git a/tools/Makefile b/tools/Makefile index dd97331208..db93291def 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -7,7 +7,7 @@ LUASOURCE ?= ../local/lua FLASHSIZE ?= 4mb 32mb 8mb FLASH_SW = -S SUBDIRS = - +APP_DIR = ../app OBJDUMP = $(or $(shell which objdump),xtensa-lx106-elf-objdump) ############################################################# @@ -20,23 +20,23 @@ SPIFFSFILES ?= $(patsubst $(FSSOURCE)/%,%,$(shell find $(FSSOURCE)/ -name '*' '! # Get the filesize of /bin/0x10000.bin and SPIFFS sizing # -FLASH_FS_SIZE := $(shell $(CC) -E -dM - <../app/include/user_config.h | grep SPIFFS_MAX_FILESYSTEM_SIZE| cut -d ' ' -f 3) +FLASH_FS_SIZE := $(shell $(CC) -E -dM - <$(APP_DIR)/include/user_config.h | grep SPIFFS_MAX_FILESYSTEM_SIZE| cut -d ' ' -f 3) ifneq ($(strip $(FLASH_FS_SIZE)),) FLASHSIZE = $(shell printf "0x%x" $(FLASH_FS_SIZE)) FLASH_SW = -c endif -FLASH_FS_LOC := $(shell $(CC) -E -dM - <../app/include/user_config.h | grep SPIFFS_FIXED_LOCATION| cut -d ' ' -f 3) +FLASH_FS_LOC := $(shell $(CC) -E -dM - <$(APP_DIR)/include/user_config.h | grep SPIFFS_FIXED_LOCATION| cut -d ' ' -f 3) ifeq ($(strip $(FLASH_FS_LOC)),) -FLASH_FS_LOC := $(shell printf "0x%x" $$((0x$(shell $(OBJDUMP) -t ../app/.output/eagle/debug/image/eagle.app.v6.out |grep " _flash_used_end" |cut -f1 -d" ") - 0x40200000))) +FLASH_FS_LOC := $(shell printf "0x%x" $$((0x$(shell $(OBJDUMP) -t $(APP_DIR)/.output/eagle/debug/image/eagle.app.v6.out |grep " _flash_used_end" |cut -f1 -d" ") - 0x40200000))) else FLASH_FS_LOC := $(shell printf "0x%x" $(FLASH_FS_LOC)) endif LFSSOURCES := $(wildcard $(LUASOURCE)/*.lua) -BUILD_TYPE := $(shell $(CC) $(EXTRA_CCFLAGS) -E -dM - <../app/include/user_config.h | grep LUA_NUMBER_INTEGRAL | wc -l) +BUILD_TYPE := $(shell $(CC) $(EXTRA_CCFLAGS) -E -dM - <$(APP_DIR)/include/user_config.h | grep LUA_NUMBER_INTEGRAL | wc -l) ifeq ($(BUILD_TYPE),0) LUAC_CROSS := ../luac.cross else diff --git a/tools/spiffsimg/Makefile b/tools/spiffsimg/Makefile index d5ba6a8dab..ee77e6a579 100644 --- a/tools/spiffsimg/Makefile +++ b/tools/spiffsimg/Makefile @@ -1,13 +1,13 @@ - +APP_DIR = ../../app summary ?= @true CC =gcc SRCS=\ main.c \ - ../../app/spiffs/spiffs_cache.c ../../app/spiffs/spiffs_check.c ../../app/spiffs/spiffs_gc.c ../../app/spiffs/spiffs_hydrogen.c ../../app/spiffs/spiffs_nucleus.c + $(APP_DIR)/spiffs/spiffs_cache.c $(APP_DIR)/spiffs/spiffs_check.c $(APP_DIR)/spiffs/spiffs_gc.c $(APP_DIR)/spiffs/spiffs_hydrogen.c $(APP_DIR)/spiffs/spiffs_nucleus.c -CFLAGS=-g -Wall -Wextra -Wno-unused-parameter -Wno-unused-function -I. -I../../app/spiffs -I../../app/include -DNODEMCU_SPIFFS_NO_INCLUDE --include spiffs_typedefs.h -Ddbg_printf=printf +CFLAGS=-g -Wall -Wextra -Wno-unused-parameter -Wno-unused-function -I. -I$(APP_DIR)/spiffs -I$(APP_DIR)/include -DNODEMCU_SPIFFS_NO_INCLUDE --include spiffs_typedefs.h -Ddbg_printf=printf spiffsimg: $(SRCS) $(summary) HOSTCC $(CURDIR)/$< From c7ff86ff275c01497271b1f2542d6e750cc87ca6 Mon Sep 17 00:00:00 2001 From: Terry Ellison Date: Tue, 23 Jul 2019 20:29:44 +0300 Subject: [PATCH 40/74] remove luacheck run for Travs and minor tweaks following #2838 (#2845) --- .travis.yml | 6 ------ app/driver/i2c_master.c | 2 +- app/pm/pmSleep.c | 2 +- 3 files changed, 2 insertions(+), 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index 90e27f0edf..e096f9f64b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -29,9 +29,3 @@ script: - if [ "$OS" = "linux" ]; then bash "$TRAVIS_BUILD_DIR"/tools/travis/ci-build-linux.sh; fi - if [ "$OS" = "windows" ]; then bash "$TRAVIS_BUILD_DIR"/tools/travis/ci-build-windows-ms.sh; fi - if [ "$OS" = "linux" -a "$TRAVIS_PULL_REQUEST" != "false" ]; then bash "$TRAVIS_BUILD_DIR"/tools/travis/pr-build.sh; fi -- cd "$TRAVIS_BUILD_DIR" -- echo "checking:" -- find lua_modules lua_examples -iname "*.lua" -print0 | xargs -0 echo -- find lua_modules lua_examples -iname "*.lua" -print0 | xargs -0 $LUACC -p -- if [ "$OS" = "linux" ]; then bash "$TRAVIS_BUILD_DIR"/tools/travis/run-luacheck.sh || true ; fi - diff --git a/app/driver/i2c_master.c b/app/driver/i2c_master.c index 618d089844..c95ae65f26 100644 --- a/app/driver/i2c_master.c +++ b/app/driver/i2c_master.c @@ -252,7 +252,7 @@ uint32 ICACHE_FLASH_ATTR i2c_master_setup(uint16 id, uint8 sda, uint8 scl, uint32 speed) { if(NULL == i2c[id]){ - i2c[id] = (i2c_master_state_t*) c_malloc(sizeof(i2c_master_state_t)); + i2c[id] = (i2c_master_state_t*) malloc(sizeof(i2c_master_state_t)); } if(NULL == i2c[id]){ // if malloc failed return 0; diff --git a/app/pm/pmSleep.c b/app/pm/pmSleep.c index d1774fc196..c7d6782960 100644 --- a/app/pm/pmSleep.c +++ b/app/pm/pmSleep.c @@ -370,7 +370,7 @@ void pmSleep_suspend(pmSleep_param_t *cfg){ wifi_fpm_set_wakeup_cb(resume_cb); // Set resume C callback - c_memcpy(¤t_config, cfg, sizeof(pmSleep_param_t)); + memcpy(¤t_config, cfg, sizeof(pmSleep_param_t)); PMSLEEP_DBG("sleep duration is %d", current_config.sleep_duration); os_timer_disarm(&null_mode_check_timer); From 21b3f38ab8d31d4bcf642ffe894bae2a071abe44 Mon Sep 17 00:00:00 2001 From: Johny Mattsson Date: Fri, 26 Jul 2019 14:43:08 +1000 Subject: [PATCH 41/74] Replace symlink with actual file. (#2856) Due to Windows limitations. Sigh. --- sdk-overrides/include/espconn.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) mode change 120000 => 100644 sdk-overrides/include/espconn.h diff --git a/sdk-overrides/include/espconn.h b/sdk-overrides/include/espconn.h deleted file mode 120000 index 401b860b6c..0000000000 --- a/sdk-overrides/include/espconn.h +++ /dev/null @@ -1 +0,0 @@ -../../app/include/lwip/app/espconn.h \ No newline at end of file diff --git a/sdk-overrides/include/espconn.h b/sdk-overrides/include/espconn.h new file mode 100644 index 0000000000..1a55e53e96 --- /dev/null +++ b/sdk-overrides/include/espconn.h @@ -0,0 +1,5 @@ +#ifndef _SDK_OVERRIDE_ESPCONN_H_ +#define _SDK_OVERRIDE_ESPCONN_H_ +// Pull in the correct lwIP header +#include "../../app/include/lwip/app/espconn.h" +#endif From 6d9c5a49a409441089f9a57005f7276871e364a8 Mon Sep 17 00:00:00 2001 From: Terry Ellison Date: Fri, 26 Jul 2019 16:43:56 +0100 Subject: [PATCH 42/74] Example Lua module for coroutining (#2851) --- docs/lua-modules/cohelper.md | 88 +++++++++++++++++++++++++++++++ lua_modules/cohelper/README.md | 3 ++ lua_modules/cohelper/cohelper.lua | 27 ++++++++++ 3 files changed, 118 insertions(+) create mode 100644 docs/lua-modules/cohelper.md create mode 100644 lua_modules/cohelper/README.md create mode 100644 lua_modules/cohelper/cohelper.lua diff --git a/docs/lua-modules/cohelper.md b/docs/lua-modules/cohelper.md new file mode 100644 index 0000000000..7909ab123f --- /dev/null +++ b/docs/lua-modules/cohelper.md @@ -0,0 +1,88 @@ +# cohelper Module +| Since | Origin / Contributor | Maintainer | Source | +| :----- | :-------------------- | :---------- | :------ | +| 2019-07-24 | [TerryE](https://github.com/TerryE) | [TerryE](https://github.com/TerryE) | [cohelper.lua](../../lua_modules/cohelper/cohelper.lua) | + +This module provides a simple wrapper around long running functions to allow +these to execute within the SDK and its advised limit of 15 mSec per individual +task execution. It does this by exploiting the standard Lua coroutine +functionality as described in the [Lua RM §2.11](https://www.lua.org/manual/5.1/manual.html#2.11) and [PiL Chapter 9](https://www.lua.org/pil/9.html). + +The NodeMCU Lua VM fully supports the standard coroutine functionality. Any +interactive or callback tasks are executed in the default thread, and the coroutine +itself runs in a second separate Lua stack. The coroutine can call any library +functions, but any subsequent callbacks will, of course, execute in the default +stack. + +Interaction between the coroutine and the parent is through yield and resume +statements, and since the order of SDK tasks is indeterminate, the application +must take care to handle any ordering issues. This particular example uses +the `node.task.post()` API with the `taskYield()`function to resume itself, +so the running code can call `taskYield()` at regular points in the processing +to spilt the work into separate SDK tasks. + +A similar approach could be based on timer or on a socket or pipe CB. If you +want to develop such a variant then start by reviewing the source and understanding +what it does. + +### Require +```lua +local cohelper = require("cohelper") +-- or linked directly with the `exec()` method +require("cohelper").exec(func, ) +``` + +### Release + +Not required. All resources are released on completion of the `exec()` method. + +## `cohelper.exec()` +Execute a function which is wrapped by a coroutine handler. + +#### Syntax +`require("cohelper").exec(func, )` + +#### Parameters +- `func`: Lua function to be executed as a coroutine. +- ``: list of 0 or more parameters used to initialise func. the number and types must be matched to the funct declaration + +#### Returns +Return result of first yield. + +#### Notes +1. The coroutine function `func()` has 1+_n_ arguments The first is the supplied task yield function. Calling this yield function within `func()` will temporarily break execution and cause an SDK reschedule which migh allow other executinng tasks to be executed before is resumed. The remaining arguments are passed to the `func()` on first call. +2. The current implementation passes a single integer parameter across `resume()` / `yield()` interface. This acts to count the number of yields that occur. Depending on your appplication requirements, you might wish to amend this. + +### Full Example + +Here is a function which recursively walks the globals environment, the ROM table +and the Registry. Without coroutining, this walk terminate with a PANIC following +a watchdog timout. I don't want to sprinkle the code with `tmr.wdclr(`) that could +in turn cause the network stack to fail. Here is how to do it using coroutining: + +```Lua +require "cohelper".exec( + function(taskYield, list) + local s, n, nCBs = {}, 0, 0 + + local function list_entry (name, v) -- upval: taskYield, nCBs + print(name, v) + n = n + 1 + if n % 20 == 0 then nCBs = taskYield(nCBs) end + if type(v):sub(-5) ~= 'table' or s[v] or name == 'Reg.stdout' then return end + s[v]=true + for k,tv in pairs(v) do + list_entry(name..'.'..k, tv) + end + s[v] = nil + end + + for k,v in pairs(list) do + list_entry(k, v) + end + print ('Total lines, print batches = ', n, nCBs) + end, + {_G = _G, Reg = debug.getregistry(), ROM = ROM} +) +``` + diff --git a/lua_modules/cohelper/README.md b/lua_modules/cohelper/README.md new file mode 100644 index 0000000000..7706aa2c3c --- /dev/null +++ b/lua_modules/cohelper/README.md @@ -0,0 +1,3 @@ +# Coroutine Helper Module + +Documentation for this Lua module is available in the [Lua Modules->cohelper](../../docs/lua-modules/cohelper.md) MD file and in the [Official NodeMCU Documentation](https://nodemcu.readthedocs.io/) in `Lua Modules` section. diff --git a/lua_modules/cohelper/cohelper.lua b/lua_modules/cohelper/cohelper.lua new file mode 100644 index 0000000000..f463f9b4c1 --- /dev/null +++ b/lua_modules/cohelper/cohelper.lua @@ -0,0 +1,27 @@ +--[[ A coroutine Helper T. Ellison, June 2019 + +This version of couroutine helper demonstrates the use of corouting within +NodeMCU execution to split structured Lua code into smaller tasks + +]] +--luacheck: read globals node + +local modname = ... + +local function taskYieldFactory(co) + local post = node.task.post + return function(nCBs) -- upval: co,post + post(function () -- upval: co, nCBs + coroutine.resume(co, nCBs or 0) + end) + return coroutine.yield() + 1 + end +end + +return { exec = function(func, ...) -- upval: modname + package.loaded[modname] = nil + local co = coroutine.create(func) + return coroutine.resume(co, taskYieldFactory(co), ... ) +end } + + From 21c35a1a973e6b39fba0f2a406df1e1f36e8fc6c Mon Sep 17 00:00:00 2001 From: Gregor Date: Thu, 27 Jun 2019 16:44:25 +0200 Subject: [PATCH 43/74] Create buildinfo.h and return new Values in node.info --- .gitignore | 1 + app/include/user_version.h | 3 +- app/modules/node.c | 8 ++++- tools/update_buildinfo.sh | 64 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 tools/update_buildinfo.sh diff --git a/.gitignore b/.gitignore index abca1f1738..8336090701 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ tools/toolchains/ .project .settings/ .vscode +buildinfo.h diff --git a/app/include/user_version.h b/app/include/user_version.h index f8ba27dba8..254967d5c4 100644 --- a/app/include/user_version.h +++ b/app/include/user_version.h @@ -2,6 +2,7 @@ #define __USER_VERSION_H__ #include "version.h" /* ESP firmware header */ +#include "/tmp/buildinfo.h" #define NODE_VERSION_MAJOR ESP_SDK_VERSION_MAJOR #define NODE_VERSION_MINOR ESP_SDK_VERSION_MINOR @@ -11,7 +12,7 @@ #define NODE_VERSION_STR(x) #x #define NODE_VERSION_XSTR(x) NODE_VERSION_STR(x) -#define NODE_VERSION "NodeMCU " ESP_SDK_VERSION_STRING "." NODE_VERSION_XSTR(NODE_VERSION_INTERNAL) +#define NODE_VERSION "NodeMCU " ESP_SDK_VERSION_STRING "." NODE_VERSION_XSTR(NODE_VERSION_INTERNAL) "\n" NODE_VERSION_LONG #ifndef BUILD_DATE #define BUILD_DATE "unspecified" diff --git a/app/modules/node.c b/app/modules/node.c index a44f3fa43c..a7cdd71995 100644 --- a/app/modules/node.c +++ b/app/modules/node.c @@ -128,7 +128,13 @@ static int node_info( lua_State* L ) lua_pushinteger(L, flash_rom_get_size_byte() / 1024); // flash size in KB lua_pushinteger(L, flash_rom_get_mode()); lua_pushinteger(L, flash_rom_get_speed()); - return 8; + lua_pushstring(L, BUILDINFO_BRANCH); + lua_pushstring(L, BUILDINFO_COMMIT_ID); + lua_pushboolean(L, BUILDINFO_SSL); + lua_pushstring(L, BUILDINFO_LFS); + lua_pushstring(L, BUILDINFO_MODULES); + lua_pushstring(L, BUILDINFO_BUILD_TYPE); + return 14; } // Lua: chipid() diff --git a/tools/update_buildinfo.sh b/tools/update_buildinfo.sh new file mode 100644 index 0000000000..081fc5430d --- /dev/null +++ b/tools/update_buildinfo.sh @@ -0,0 +1,64 @@ +#!/usr/bin/env bash + +BUILD_DATE="$(date "+%Y-%m-%d %H:%M")" +COMMIT_ID="$(git rev-parse HEAD)" +BRANCH="$(git rev-parse --abbrev-ref HEAD | sed -r 's/[\/\\]+/_/g')" +RELEASE="$(git describe --tags --long | sed -r 's/(.*)-(.*)-.*/\1 +\2/g' | sed 's/ +0$//')" + +# figure out whether SSL is enabled in user_config.h +if grep -Eq "^#define CLIENT_SSL_ENABLE" ../app/include/user_config.h; then + SSL="true" + else + SSL="false" + fi + +# figure out whether LFS configuration in user_config.h +LFS=$(grep "^#define LUA_FLASH_STORE" ../app/include/user_config.h | tr -d '\r' | cut -d ' ' -f 3-) +if [ -z "$LFS" ]; then + LFS="disabled" +else + LFS="Size: ${LFS}" + fi + +# figure out whether Int build is enabled in user_config.h +if grep -Eq "^#define LUA_NUMBER_INTEGRAL" ../app/include/user_config.h; then + BUILD_TYPE=integer +else + BUILD_TYPE=float +fi + +MODULES=$(awk '/^[ \t]*#define LUA_USE_MODULES/{modules=modules sep tolower(substr($2,17));sep=","}END{if(length(modules)==0)modules="-";print modules}' ../app/include/user_modules.h | tr -d '\r') + +# create temp buildinfo +TEMPFILE=/tmp/buildinfo.h +cat > $TEMPFILE << EndOfMessage +#ifndef __BUILDINFO_H__ +#define __BUILDINFO_H__ +EndOfMessage + +echo "#define BUILDINFO_BRANCH \""$BRANCH"\"" >> $TEMPFILE +echo "#define BUILDINFO_COMMIT_ID \""$COMMIT_ID"\"" >> $TEMPFILE +echo "#define BUILDINFO_RELEASE \""$RELEASE"\"" >> $TEMPFILE +echo "#define BUILDINFO_SSL "$SSL >> $TEMPFILE +echo "#define BUILDINFO_SSL_STR \""$SSL"\"" >> $TEMPFILE +echo "#define BUILDINFO_BUILD_TYPE \""$BUILD_TYPE"\"" >> $TEMPFILE +echo "#define BUILDINFO_LFS \""$LFS"\"" >> $TEMPFILE +echo "#define BUILDINFO_MODULES \""$MODULES"\"" >> $TEMPFILE + +cat >> $TEMPFILE << EndOfMessage2 + +#define NODE_VERSION_LONG \\ + "\tbranch: '" BUILDINFO_BRANCH "'\n" \\ + "\tcommit: '" BUILDINFO_COMMIT_ID "'\n" \\ + "\tSSL: '" BUILDINFO_SSL_STR "'\n" \\ + "\tBuild type: '" BUILDINFO_BUILD_TYPE "'\n" \\ + "\tLFS: '" BUILDINFO_LFS "'\n" \\ + "\tmodules: '" BUILDINFO_MODULES "'\n" + +EndOfMessage2 + + + +#echo "#define NODE_VERSION_LONG \"\\n\\tbranch: '"$BRANCH"'\\n\\tcommit: '"$COMMIT_ID"'\\n\\tSSL: '"$SSL"'\\n\\tBuild type: '"$BUILD_TYPE"'\\n\\tLFS: '"$LFS"'\\n\\tmodules: '"$MODULES"'\\n\"" >> $TEMPFILE + +echo "#endif /* __BUILDINFO_H__ */" >> $TEMPFILE From 4b279939b6d9308c7343ee9fadf9d1a1f51b7328 Mon Sep 17 00:00:00 2001 From: Gregor Date: Thu, 4 Jul 2019 20:26:15 +0200 Subject: [PATCH 44/74] Add release info --- app/modules/node.c | 5 ++++- tools/update_buildinfo.sh | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/app/modules/node.c b/app/modules/node.c index a7cdd71995..b50fc0db13 100644 --- a/app/modules/node.c +++ b/app/modules/node.c @@ -130,11 +130,14 @@ static int node_info( lua_State* L ) lua_pushinteger(L, flash_rom_get_speed()); lua_pushstring(L, BUILDINFO_BRANCH); lua_pushstring(L, BUILDINFO_COMMIT_ID); + lua_pushstring(L, BUILDINFO_RELEASE); + lua_pushnumber(L, BUILDINFO_RELEASE_DTS); lua_pushboolean(L, BUILDINFO_SSL); lua_pushstring(L, BUILDINFO_LFS); lua_pushstring(L, BUILDINFO_MODULES); lua_pushstring(L, BUILDINFO_BUILD_TYPE); - return 14; + + return 16; } // Lua: chipid() diff --git a/tools/update_buildinfo.sh b/tools/update_buildinfo.sh index 081fc5430d..b4a08813b9 100644 --- a/tools/update_buildinfo.sh +++ b/tools/update_buildinfo.sh @@ -4,6 +4,7 @@ BUILD_DATE="$(date "+%Y-%m-%d %H:%M")" COMMIT_ID="$(git rev-parse HEAD)" BRANCH="$(git rev-parse --abbrev-ref HEAD | sed -r 's/[\/\\]+/_/g')" RELEASE="$(git describe --tags --long | sed -r 's/(.*)-(.*)-.*/\1 +\2/g' | sed 's/ +0$//')" +RELEASE_DTS=0$(git show -s --format=%cd --date=format:"%Y%m%d%H%M" HEAD) # figure out whether SSL is enabled in user_config.h if grep -Eq "^#define CLIENT_SSL_ENABLE" ../app/include/user_config.h; then @@ -39,6 +40,7 @@ EndOfMessage echo "#define BUILDINFO_BRANCH \""$BRANCH"\"" >> $TEMPFILE echo "#define BUILDINFO_COMMIT_ID \""$COMMIT_ID"\"" >> $TEMPFILE echo "#define BUILDINFO_RELEASE \""$RELEASE"\"" >> $TEMPFILE +echo "#define BUILDINFO_RELEASE_DTS "$RELEASE_DTS"" >> $TEMPFILE echo "#define BUILDINFO_SSL "$SSL >> $TEMPFILE echo "#define BUILDINFO_SSL_STR \""$SSL"\"" >> $TEMPFILE echo "#define BUILDINFO_BUILD_TYPE \""$BUILD_TYPE"\"" >> $TEMPFILE @@ -50,6 +52,8 @@ cat >> $TEMPFILE << EndOfMessage2 #define NODE_VERSION_LONG \\ "\tbranch: '" BUILDINFO_BRANCH "'\n" \\ "\tcommit: '" BUILDINFO_COMMIT_ID "'\n" \\ + "\trelease: '" BUILDINFO_RELEASE "'\n" \\ + "\trelease DTS: '" BUILDINFO_RELEASE_DTS "'\n" \\ "\tSSL: '" BUILDINFO_SSL_STR "'\n" \\ "\tBuild type: '" BUILDINFO_BUILD_TYPE "'\n" \\ "\tLFS: '" BUILDINFO_LFS "'\n" \\ From e0273185db3c6392692f1eba3877e8f2999196bd Mon Sep 17 00:00:00 2001 From: Gregor Date: Thu, 11 Jul 2019 22:49:26 +0200 Subject: [PATCH 45/74] include buildinfo generation in makefile --- Makefile | 7 ++++++- app/include/user_version.h | 2 +- tools/update_buildinfo.sh | 23 +++++++++++++---------- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index 4e796ed2c6..67ff4ece2f 100644 --- a/Makefile +++ b/Makefile @@ -274,7 +274,7 @@ endif # TARGET # ifndef TARGET -all: toolchain sdk_pruned pre_build .subdirs +all: toolchain sdk_pruned pre_build buildinfo .subdirs else all: .subdirs $(OBJS) $(OLIBS) $(OIMAGES) $(OBINS) $(SPECIAL_MKTARGETS) endif @@ -412,6 +412,11 @@ pre_build: @-rm -f $(APP_DIR)/modules/server-ca.crt.h endif +.PHONY: buildinfo + +buildinfo: + tools/update_buildinfo.sh + ifdef TARGET $(OBJODIR)/%.o: %.c @mkdir -p $(dir $@); diff --git a/app/include/user_version.h b/app/include/user_version.h index 254967d5c4..51221395cc 100644 --- a/app/include/user_version.h +++ b/app/include/user_version.h @@ -2,7 +2,7 @@ #define __USER_VERSION_H__ #include "version.h" /* ESP firmware header */ -#include "/tmp/buildinfo.h" +#include #define NODE_VERSION_MAJOR ESP_SDK_VERSION_MAJOR #define NODE_VERSION_MINOR ESP_SDK_VERSION_MINOR diff --git a/tools/update_buildinfo.sh b/tools/update_buildinfo.sh index b4a08813b9..993c0f7da4 100644 --- a/tools/update_buildinfo.sh +++ b/tools/update_buildinfo.sh @@ -1,5 +1,8 @@ #!/usr/bin/env bash +USER_MODULES_H=app/include/user_modules.h +USER_CONFIG_H=app/include/user_config.h + BUILD_DATE="$(date "+%Y-%m-%d %H:%M")" COMMIT_ID="$(git rev-parse HEAD)" BRANCH="$(git rev-parse --abbrev-ref HEAD | sed -r 's/[\/\\]+/_/g')" @@ -7,14 +10,14 @@ RELEASE="$(git describe --tags --long | sed -r 's/(.*)-(.*)-.*/\1 +\2/g' | sed ' RELEASE_DTS=0$(git show -s --format=%cd --date=format:"%Y%m%d%H%M" HEAD) # figure out whether SSL is enabled in user_config.h -if grep -Eq "^#define CLIENT_SSL_ENABLE" ../app/include/user_config.h; then +if grep -Eq "^#define CLIENT_SSL_ENABLE" $USER_CONFIG_H; then SSL="true" else SSL="false" fi # figure out whether LFS configuration in user_config.h -LFS=$(grep "^#define LUA_FLASH_STORE" ../app/include/user_config.h | tr -d '\r' | cut -d ' ' -f 3-) +LFS=$(grep "^#define LUA_FLASH_STORE" $USER_CONFIG_H | tr -d '\r' | cut -d ' ' -f 3-) if [ -z "$LFS" ]; then LFS="disabled" else @@ -22,13 +25,13 @@ else fi # figure out whether Int build is enabled in user_config.h -if grep -Eq "^#define LUA_NUMBER_INTEGRAL" ../app/include/user_config.h; then +if grep -Eq "^#define LUA_NUMBER_INTEGRAL" $USER_CONFIG_H; then BUILD_TYPE=integer else BUILD_TYPE=float fi -MODULES=$(awk '/^[ \t]*#define LUA_USE_MODULES/{modules=modules sep tolower(substr($2,17));sep=","}END{if(length(modules)==0)modules="-";print modules}' ../app/include/user_modules.h | tr -d '\r') +MODULES=$(awk '/^[ \t]*#define LUA_USE_MODULES/{modules=modules sep tolower(substr($2,17));sep=","}END{if(length(modules)==0)modules="-";print modules}' $USER_MODULES_H | tr -d '\r') # create temp buildinfo TEMPFILE=/tmp/buildinfo.h @@ -40,7 +43,8 @@ EndOfMessage echo "#define BUILDINFO_BRANCH \""$BRANCH"\"" >> $TEMPFILE echo "#define BUILDINFO_COMMIT_ID \""$COMMIT_ID"\"" >> $TEMPFILE echo "#define BUILDINFO_RELEASE \""$RELEASE"\"" >> $TEMPFILE -echo "#define BUILDINFO_RELEASE_DTS "$RELEASE_DTS"" >> $TEMPFILE +echo "#define BUILDINFO_RELEASE_DTS "$RELEASE_DTS >> $TEMPFILE +echo "#define BUILDINFO_RELEASE_DTS_STR \""$RELEASE_DTS"\"" >> $TEMPFILE echo "#define BUILDINFO_SSL "$SSL >> $TEMPFILE echo "#define BUILDINFO_SSL_STR \""$SSL"\"" >> $TEMPFILE echo "#define BUILDINFO_BUILD_TYPE \""$BUILD_TYPE"\"" >> $TEMPFILE @@ -53,7 +57,7 @@ cat >> $TEMPFILE << EndOfMessage2 "\tbranch: '" BUILDINFO_BRANCH "'\n" \\ "\tcommit: '" BUILDINFO_COMMIT_ID "'\n" \\ "\trelease: '" BUILDINFO_RELEASE "'\n" \\ - "\trelease DTS: '" BUILDINFO_RELEASE_DTS "'\n" \\ + "\trelease DTS: '" BUILDINFO_RELEASE_DTS_STR "'\n" \\ "\tSSL: '" BUILDINFO_SSL_STR "'\n" \\ "\tBuild type: '" BUILDINFO_BUILD_TYPE "'\n" \\ "\tLFS: '" BUILDINFO_LFS "'\n" \\ @@ -61,8 +65,7 @@ cat >> $TEMPFILE << EndOfMessage2 EndOfMessage2 - - -#echo "#define NODE_VERSION_LONG \"\\n\\tbranch: '"$BRANCH"'\\n\\tcommit: '"$COMMIT_ID"'\\n\\tSSL: '"$SSL"'\\n\\tBuild type: '"$BUILD_TYPE"'\\n\\tLFS: '"$LFS"'\\n\\tmodules: '"$MODULES"'\\n\"" >> $TEMPFILE - echo "#endif /* __BUILDINFO_H__ */" >> $TEMPFILE + +diff -q $TEMPFILE app/include/buildinfo.h || cp $TEMPFILE app/include/buildinfo.h +rm $TEMPFILE \ No newline at end of file From e6c2f4cb5512bf9b69c1b820f3a3f5f59f4236e1 Mon Sep 17 00:00:00 2001 From: Gregor Date: Fri, 12 Jul 2019 19:23:02 +0200 Subject: [PATCH 46/74] Include environment variable USER_PROLOG in user config default --- tools/update_buildinfo.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tools/update_buildinfo.sh b/tools/update_buildinfo.sh index 993c0f7da4..ba846d4bd1 100644 --- a/tools/update_buildinfo.sh +++ b/tools/update_buildinfo.sh @@ -40,6 +40,11 @@ cat > $TEMPFILE << EndOfMessage #define __BUILDINFO_H__ EndOfMessage +if [ -n "$USER_PROLOG" ]; then + USER_PROLOG_LINE="$USER_PROLOG"\\n +fi + +echo "#define USER_PROLOG \""$USER_PROLOG"\"" >> $TEMPFILE echo "#define BUILDINFO_BRANCH \""$BRANCH"\"" >> $TEMPFILE echo "#define BUILDINFO_COMMIT_ID \""$COMMIT_ID"\"" >> $TEMPFILE echo "#define BUILDINFO_RELEASE \""$RELEASE"\"" >> $TEMPFILE @@ -52,8 +57,8 @@ echo "#define BUILDINFO_LFS \""$LFS"\"" >> $TEMPFILE echo "#define BUILDINFO_MODULES \""$MODULES"\"" >> $TEMPFILE cat >> $TEMPFILE << EndOfMessage2 - #define NODE_VERSION_LONG \\ + "$USER_PROLOG_LINE" \\ "\tbranch: '" BUILDINFO_BRANCH "'\n" \\ "\tcommit: '" BUILDINFO_COMMIT_ID "'\n" \\ "\trelease: '" BUILDINFO_RELEASE "'\n" \\ From ad90e8dd5101ebff8ee5213691ef85d6177865d0 Mon Sep 17 00:00:00 2001 From: Gregor Date: Fri, 12 Jul 2019 20:59:59 +0200 Subject: [PATCH 47/74] tweal the startup message a bit --- app/include/user_version.h | 2 +- tools/update_buildinfo.sh | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/include/user_version.h b/app/include/user_version.h index 51221395cc..20048c678c 100644 --- a/app/include/user_version.h +++ b/app/include/user_version.h @@ -12,7 +12,7 @@ #define NODE_VERSION_STR(x) #x #define NODE_VERSION_XSTR(x) NODE_VERSION_STR(x) -#define NODE_VERSION "NodeMCU " ESP_SDK_VERSION_STRING "." NODE_VERSION_XSTR(NODE_VERSION_INTERNAL) "\n" NODE_VERSION_LONG +# define NODE_VERSION "NodeMCU " ESP_SDK_VERSION_STRING "." NODE_VERSION_XSTR(NODE_VERSION_INTERNAL) " " NODE_VERSION_LONG #ifndef BUILD_DATE #define BUILD_DATE "unspecified" diff --git a/tools/update_buildinfo.sh b/tools/update_buildinfo.sh index ba846d4bd1..dad660a169 100644 --- a/tools/update_buildinfo.sh +++ b/tools/update_buildinfo.sh @@ -59,14 +59,14 @@ echo "#define BUILDINFO_MODULES \""$MODULES"\"" >> $TEMPFILE cat >> $TEMPFILE << EndOfMessage2 #define NODE_VERSION_LONG \\ "$USER_PROLOG_LINE" \\ - "\tbranch: '" BUILDINFO_BRANCH "'\n" \\ - "\tcommit: '" BUILDINFO_COMMIT_ID "'\n" \\ - "\trelease: '" BUILDINFO_RELEASE "'\n" \\ - "\trelease DTS: '" BUILDINFO_RELEASE_DTS_STR "'\n" \\ - "\tSSL: '" BUILDINFO_SSL_STR "'\n" \\ - "\tBuild type: '" BUILDINFO_BUILD_TYPE "'\n" \\ - "\tLFS: '" BUILDINFO_LFS "'\n" \\ - "\tmodules: '" BUILDINFO_MODULES "'\n" + "\tbranch: " BUILDINFO_BRANCH "\n" \\ + "\tcommit: " BUILDINFO_COMMIT_ID "\n" \\ + "\trelease: " BUILDINFO_RELEASE "\n" \\ + "\trelease DTS: " BUILDINFO_RELEASE_DTS_STR "\n" \\ + "\tSSL: " BUILDINFO_SSL_STR "\n" \\ + "\tBuild type: " BUILDINFO_BUILD_TYPE "\n" \\ + "\tLFS: " BUILDINFO_LFS "\n" \\ + "\tmodules: " BUILDINFO_MODULES "\n" EndOfMessage2 From bc4b177086d355f8c19c1300c7b7991d164ed4c5 Mon Sep 17 00:00:00 2001 From: Gregor Date: Fri, 12 Jul 2019 21:36:44 +0200 Subject: [PATCH 48/74] Fix small issues and add execute bit for unix --- tools/update_buildinfo.sh | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/tools/update_buildinfo.sh b/tools/update_buildinfo.sh index dad660a169..426b11f8a7 100644 --- a/tools/update_buildinfo.sh +++ b/tools/update_buildinfo.sh @@ -11,18 +11,18 @@ RELEASE_DTS=0$(git show -s --format=%cd --date=format:"%Y%m%d%H%M" HEAD) # figure out whether SSL is enabled in user_config.h if grep -Eq "^#define CLIENT_SSL_ENABLE" $USER_CONFIG_H; then - SSL="true" - else - SSL="false" - fi + SSL="true" +else + SSL="false" +fi # figure out whether LFS configuration in user_config.h LFS=$(grep "^#define LUA_FLASH_STORE" $USER_CONFIG_H | tr -d '\r' | cut -d ' ' -f 3-) if [ -z "$LFS" ]; then - LFS="disabled" + LFS="disabled" else - LFS="Size: ${LFS}" - fi + LFS="Size: ${LFS}" +fi # figure out whether Int build is enabled in user_config.h if grep -Eq "^#define LUA_NUMBER_INTEGRAL" $USER_CONFIG_H; then @@ -58,19 +58,19 @@ echo "#define BUILDINFO_MODULES \""$MODULES"\"" >> $TEMPFILE cat >> $TEMPFILE << EndOfMessage2 #define NODE_VERSION_LONG \\ - "$USER_PROLOG_LINE" \\ - "\tbranch: " BUILDINFO_BRANCH "\n" \\ - "\tcommit: " BUILDINFO_COMMIT_ID "\n" \\ - "\trelease: " BUILDINFO_RELEASE "\n" \\ - "\trelease DTS: " BUILDINFO_RELEASE_DTS_STR "\n" \\ - "\tSSL: " BUILDINFO_SSL_STR "\n" \\ - "\tBuild type: " BUILDINFO_BUILD_TYPE "\n" \\ - "\tLFS: " BUILDINFO_LFS "\n" \\ - "\tmodules: " BUILDINFO_MODULES "\n" - + "$USER_PROLOG_LINE" \\ + "\tbranch: " BUILDINFO_BRANCH "\n" \\ + "\tcommit: " BUILDINFO_COMMIT_ID "\n" \\ + "\trelease: " BUILDINFO_RELEASE "\n" \\ + "\trelease DTS: " BUILDINFO_RELEASE_DTS_STR "\n" \\ + "\tSSL: " BUILDINFO_SSL_STR "\n" \\ + "\tBuild type: " BUILDINFO_BUILD_TYPE "\n" \\ + "\tLFS: " BUILDINFO_LFS "\n" \\ + "\tmodules: " BUILDINFO_MODULES "\n" + EndOfMessage2 echo "#endif /* __BUILDINFO_H__ */" >> $TEMPFILE diff -q $TEMPFILE app/include/buildinfo.h || cp $TEMPFILE app/include/buildinfo.h -rm $TEMPFILE \ No newline at end of file +rm $TEMPFILE From 2d80042f91c21ca7cc99cd1a3811a6a774abdcb4 Mon Sep 17 00:00:00 2001 From: Gregor Date: Fri, 12 Jul 2019 21:40:11 +0200 Subject: [PATCH 49/74] update file permission --- app/include/user_config.h | 4 ++-- app/include/user_modules.h | 36 +++++++++++++++++------------------ app/lwip/core/dhcp.c | 11 +++++++++++ lua_modules/bh1750/bh1750.lua | 26 ++++++++++++------------- tools/update_buildinfo.sh | 0 5 files changed, 44 insertions(+), 33 deletions(-) mode change 100644 => 100755 tools/update_buildinfo.sh diff --git a/app/include/user_config.h b/app/include/user_config.h index 4866e6a91d..283ef9d4ef 100644 --- a/app/include/user_config.h +++ b/app/include/user_config.h @@ -46,7 +46,7 @@ // LUA_FLASH_STORE defines the default partition size if the NodeMCU partition // tool is not used. -//#define LUA_FLASH_STORE 0x10000 +#define LUA_FLASH_STORE 0x40000 // By default Lua executes the file init.lua at start up. The following // define allows you to replace this with an alternative startup. Warning: @@ -135,7 +135,7 @@ #define WIFI_EVENT_MONITOR_DISCONNECT_REASON_LIST_ENABLE // Enable use of the WiFi.monitor sub-module -//#define LUA_USE_MODULES_WIFI_MONITOR +#define LUA_USE_MODULES_WIFI_MONITOR // Whilst the DNS client details can be configured through the WiFi API, diff --git a/app/include/user_modules.h b/app/include/user_modules.h index 0b28dbe757..600add8525 100644 --- a/app/include/user_modules.h +++ b/app/include/user_modules.h @@ -18,11 +18,11 @@ //#define LUA_USE_MODULES_BME280 //#define LUA_USE_MODULES_BME680 //#define LUA_USE_MODULES_COAP -//#define LUA_USE_MODULES_COLOR_UTILS +#define LUA_USE_MODULES_COLOR_UTILS //#define LUA_USE_MODULES_CRON -//#define LUA_USE_MODULES_CRYPTO +#define LUA_USE_MODULES_CRYPTO #define LUA_USE_MODULES_DHT -//#define LUA_USE_MODULES_ENCODER +#define LUA_USE_MODULES_ENCODER //#define LUA_USE_MODULES_ENDUSER_SETUP // USE_DNS in dhcpserver.h needs to be enabled for this module to work. #define LUA_USE_MODULES_FILE //#define LUA_USE_MODULES_GDBSTUB @@ -30,35 +30,35 @@ //#define LUA_USE_MODULES_GPIO_PULSE //#define LUA_USE_MODULES_HDC1080 //#define LUA_USE_MODULES_HMC5883L -//#define LUA_USE_MODULES_HTTP +#define LUA_USE_MODULES_HTTP //#define LUA_USE_MODULES_HX711 #define LUA_USE_MODULES_I2C -//#define LUA_USE_MODULES_L3G4200D +#define LUA_USE_MODULES_L3G4200D //#define LUA_USE_MODULES_MCP4725 -//#define LUA_USE_MODULES_MDNS -#define LUA_USE_MODULES_MQTT +#define LUA_USE_MODULES_MDNS +//#define LUA_USE_MODULES_MQTT #define LUA_USE_MODULES_NET #define LUA_USE_MODULES_NODE #define LUA_USE_MODULES_OW //#define LUA_USE_MODULES_PCM //#define LUA_USE_MODULES_PERF -//#define LUA_USE_MODULES_PIPE -//#define LUA_USE_MODULES_PWM +#define LUA_USE_MODULES_PIPE +#define LUA_USE_MODULES_PWM //#define LUA_USE_MODULES_PWM2 //#define LUA_USE_MODULES_RC //#define LUA_USE_MODULES_RFSWITCH //#define LUA_USE_MODULES_ROTARY -//#define LUA_USE_MODULES_RTCFIFO -//#define LUA_USE_MODULES_RTCMEM -//#define LUA_USE_MODULES_RTCTIME +#define LUA_USE_MODULES_RTCFIFO +#define LUA_USE_MODULES_RTCMEM +#define LUA_USE_MODULES_RTCTIME //#define LUA_USE_MODULES_SI7021 //#define LUA_USE_MODULES_SIGMA_DELTA -//#define LUA_USE_MODULES_SJSON -//#define LUA_USE_MODULES_SNTP +#define LUA_USE_MODULES_SJSON +#define LUA_USE_MODULES_SNTP //#define LUA_USE_MODULES_SOMFY #define LUA_USE_MODULES_SPI //#define LUA_USE_MODULES_SQLITE3 -//#define LUA_USE_MODULES_STRUCT +#define LUA_USE_MODULES_STRUCT //#define LUA_USE_MODULES_SWITEC //#define LUA_USE_MODULES_TCS34725 //#define LUA_USE_MODULES_TM1829 @@ -70,11 +70,11 @@ //#define LUA_USE_MODULES_UCG //#define LUA_USE_MODULES_WEBSOCKET #define LUA_USE_MODULES_WIFI -//#define LUA_USE_MODULES_WIFI_MONITOR +#define LUA_USE_MODULES_WIFI_MONITOR //#define LUA_USE_MODULES_WPS //#define LUA_USE_MODULES_WS2801 -//#define LUA_USE_MODULES_WS2812 -//#define LUA_USE_MODULES_WS2812_EFFECTS +#define LUA_USE_MODULES_WS2812 +#define LUA_USE_MODULES_WS2812_EFFECTS //#define LUA_USE_MODULES_XPT2046 //debug modules diff --git a/app/lwip/core/dhcp.c b/app/lwip/core/dhcp.c index 88ac82a64c..526bebc7ee 100644 --- a/app/lwip/core/dhcp.c +++ b/app/lwip/core/dhcp.c @@ -593,6 +593,17 @@ dhcp_handle_ack(struct netif *netif) n++; } #endif /* LWIP_DNS */ +/* + if (dhcp_option_given(dhcp, DHCP_OPTION_IDX_NTP)) { + ip4_addr_set_u32(&dhcp->offered_ntp_addr, htonl(dhcp_get_option_value(dhcp, DHCP_OPTION_IDX_NTP))); + char buf[64]; + c_sprintf(buf, "%d.%d.%d.%d", IP2STR(&dhcp->offered_ntp_addr)); + platform_print_deprecation_note("found NTP ip", buf); + } + else + { + platform_print_deprecation_note("found NO NTP ip", "never"); + }*/ } /** Set a statically allocated struct dhcp to work with. diff --git a/lua_modules/bh1750/bh1750.lua b/lua_modules/bh1750/bh1750.lua index 5a06611ee3..175f87e74d 100644 --- a/lua_modules/bh1750/bh1750.lua +++ b/lua_modules/bh1750/bh1750.lua @@ -9,19 +9,19 @@ local moduleName = ... local M = {} _G[moduleName] = M - --I2C slave address of GY-30 - local GY_30_address = 0x23 - -- i2c interface ID - local id = 0 - --LUX - local l - --CMD - local CMD = 0x10 - local init = false - --Make it more faster - local i2c = i2c - function M.init(sda, scl) - i2c.setup(id, sda, scl, i2c.SLOW) +--I2C slave address of GY-30 +local GY_30_address = 0x23 +-- i2c interface ID +local id = 0 +--LUX +local l +--CMD +local CMD = 0x10 +local init = false +--Make it more faster +local i2c = i2c +function M.init(sda, scl) + i2c.setup(id, sda, scl, i2c.SLOW) --print("i2c ok..") init = true end diff --git a/tools/update_buildinfo.sh b/tools/update_buildinfo.sh old mode 100644 new mode 100755 From 299b24893296298159e9615d71d14994abff503b Mon Sep 17 00:00:00 2001 From: Gregor Date: Fri, 12 Jul 2019 21:52:33 +0200 Subject: [PATCH 50/74] Cover for failed RELEASE_DTS calculation --- tools/update_buildinfo.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/update_buildinfo.sh b/tools/update_buildinfo.sh index 426b11f8a7..117ff0f1f4 100755 --- a/tools/update_buildinfo.sh +++ b/tools/update_buildinfo.sh @@ -7,7 +7,10 @@ BUILD_DATE="$(date "+%Y-%m-%d %H:%M")" COMMIT_ID="$(git rev-parse HEAD)" BRANCH="$(git rev-parse --abbrev-ref HEAD | sed -r 's/[\/\\]+/_/g')" RELEASE="$(git describe --tags --long | sed -r 's/(.*)-(.*)-.*/\1 +\2/g' | sed 's/ +0$//')" -RELEASE_DTS=0$(git show -s --format=%cd --date=format:"%Y%m%d%H%M" HEAD) +RELEASE_DTS=$(git show -s --format=%cd --date=format:"%Y%m%d%H%M" HEAD) +if [ -z "$RELEASE_DTS"]; then + RELEASE_DTS=0 +fi # figure out whether SSL is enabled in user_config.h if grep -Eq "^#define CLIENT_SSL_ENABLE" $USER_CONFIG_H; then From 6f1e366946efbe20c6866b83c7a69fb58628a3f3 Mon Sep 17 00:00:00 2001 From: Gregor Date: Fri, 12 Jul 2019 21:55:44 +0200 Subject: [PATCH 51/74] Revert "update file permission" This reverts commit af9b123bc1c0603859caf9fcd6fcfdeeeb08dbce. --- app/include/user_config.h | 4 ++-- app/include/user_modules.h | 36 +++++++++++++++++------------------ app/lwip/core/dhcp.c | 11 ----------- lua_modules/bh1750/bh1750.lua | 26 ++++++++++++------------- tools/update_buildinfo.sh | 0 5 files changed, 33 insertions(+), 44 deletions(-) mode change 100755 => 100644 tools/update_buildinfo.sh diff --git a/app/include/user_config.h b/app/include/user_config.h index 283ef9d4ef..4866e6a91d 100644 --- a/app/include/user_config.h +++ b/app/include/user_config.h @@ -46,7 +46,7 @@ // LUA_FLASH_STORE defines the default partition size if the NodeMCU partition // tool is not used. -#define LUA_FLASH_STORE 0x40000 +//#define LUA_FLASH_STORE 0x10000 // By default Lua executes the file init.lua at start up. The following // define allows you to replace this with an alternative startup. Warning: @@ -135,7 +135,7 @@ #define WIFI_EVENT_MONITOR_DISCONNECT_REASON_LIST_ENABLE // Enable use of the WiFi.monitor sub-module -#define LUA_USE_MODULES_WIFI_MONITOR +//#define LUA_USE_MODULES_WIFI_MONITOR // Whilst the DNS client details can be configured through the WiFi API, diff --git a/app/include/user_modules.h b/app/include/user_modules.h index 600add8525..0b28dbe757 100644 --- a/app/include/user_modules.h +++ b/app/include/user_modules.h @@ -18,11 +18,11 @@ //#define LUA_USE_MODULES_BME280 //#define LUA_USE_MODULES_BME680 //#define LUA_USE_MODULES_COAP -#define LUA_USE_MODULES_COLOR_UTILS +//#define LUA_USE_MODULES_COLOR_UTILS //#define LUA_USE_MODULES_CRON -#define LUA_USE_MODULES_CRYPTO +//#define LUA_USE_MODULES_CRYPTO #define LUA_USE_MODULES_DHT -#define LUA_USE_MODULES_ENCODER +//#define LUA_USE_MODULES_ENCODER //#define LUA_USE_MODULES_ENDUSER_SETUP // USE_DNS in dhcpserver.h needs to be enabled for this module to work. #define LUA_USE_MODULES_FILE //#define LUA_USE_MODULES_GDBSTUB @@ -30,35 +30,35 @@ //#define LUA_USE_MODULES_GPIO_PULSE //#define LUA_USE_MODULES_HDC1080 //#define LUA_USE_MODULES_HMC5883L -#define LUA_USE_MODULES_HTTP +//#define LUA_USE_MODULES_HTTP //#define LUA_USE_MODULES_HX711 #define LUA_USE_MODULES_I2C -#define LUA_USE_MODULES_L3G4200D +//#define LUA_USE_MODULES_L3G4200D //#define LUA_USE_MODULES_MCP4725 -#define LUA_USE_MODULES_MDNS -//#define LUA_USE_MODULES_MQTT +//#define LUA_USE_MODULES_MDNS +#define LUA_USE_MODULES_MQTT #define LUA_USE_MODULES_NET #define LUA_USE_MODULES_NODE #define LUA_USE_MODULES_OW //#define LUA_USE_MODULES_PCM //#define LUA_USE_MODULES_PERF -#define LUA_USE_MODULES_PIPE -#define LUA_USE_MODULES_PWM +//#define LUA_USE_MODULES_PIPE +//#define LUA_USE_MODULES_PWM //#define LUA_USE_MODULES_PWM2 //#define LUA_USE_MODULES_RC //#define LUA_USE_MODULES_RFSWITCH //#define LUA_USE_MODULES_ROTARY -#define LUA_USE_MODULES_RTCFIFO -#define LUA_USE_MODULES_RTCMEM -#define LUA_USE_MODULES_RTCTIME +//#define LUA_USE_MODULES_RTCFIFO +//#define LUA_USE_MODULES_RTCMEM +//#define LUA_USE_MODULES_RTCTIME //#define LUA_USE_MODULES_SI7021 //#define LUA_USE_MODULES_SIGMA_DELTA -#define LUA_USE_MODULES_SJSON -#define LUA_USE_MODULES_SNTP +//#define LUA_USE_MODULES_SJSON +//#define LUA_USE_MODULES_SNTP //#define LUA_USE_MODULES_SOMFY #define LUA_USE_MODULES_SPI //#define LUA_USE_MODULES_SQLITE3 -#define LUA_USE_MODULES_STRUCT +//#define LUA_USE_MODULES_STRUCT //#define LUA_USE_MODULES_SWITEC //#define LUA_USE_MODULES_TCS34725 //#define LUA_USE_MODULES_TM1829 @@ -70,11 +70,11 @@ //#define LUA_USE_MODULES_UCG //#define LUA_USE_MODULES_WEBSOCKET #define LUA_USE_MODULES_WIFI -#define LUA_USE_MODULES_WIFI_MONITOR +//#define LUA_USE_MODULES_WIFI_MONITOR //#define LUA_USE_MODULES_WPS //#define LUA_USE_MODULES_WS2801 -#define LUA_USE_MODULES_WS2812 -#define LUA_USE_MODULES_WS2812_EFFECTS +//#define LUA_USE_MODULES_WS2812 +//#define LUA_USE_MODULES_WS2812_EFFECTS //#define LUA_USE_MODULES_XPT2046 //debug modules diff --git a/app/lwip/core/dhcp.c b/app/lwip/core/dhcp.c index 526bebc7ee..88ac82a64c 100644 --- a/app/lwip/core/dhcp.c +++ b/app/lwip/core/dhcp.c @@ -593,17 +593,6 @@ dhcp_handle_ack(struct netif *netif) n++; } #endif /* LWIP_DNS */ -/* - if (dhcp_option_given(dhcp, DHCP_OPTION_IDX_NTP)) { - ip4_addr_set_u32(&dhcp->offered_ntp_addr, htonl(dhcp_get_option_value(dhcp, DHCP_OPTION_IDX_NTP))); - char buf[64]; - c_sprintf(buf, "%d.%d.%d.%d", IP2STR(&dhcp->offered_ntp_addr)); - platform_print_deprecation_note("found NTP ip", buf); - } - else - { - platform_print_deprecation_note("found NO NTP ip", "never"); - }*/ } /** Set a statically allocated struct dhcp to work with. diff --git a/lua_modules/bh1750/bh1750.lua b/lua_modules/bh1750/bh1750.lua index 175f87e74d..5a06611ee3 100644 --- a/lua_modules/bh1750/bh1750.lua +++ b/lua_modules/bh1750/bh1750.lua @@ -9,19 +9,19 @@ local moduleName = ... local M = {} _G[moduleName] = M ---I2C slave address of GY-30 -local GY_30_address = 0x23 --- i2c interface ID -local id = 0 ---LUX -local l ---CMD -local CMD = 0x10 -local init = false ---Make it more faster -local i2c = i2c -function M.init(sda, scl) - i2c.setup(id, sda, scl, i2c.SLOW) + --I2C slave address of GY-30 + local GY_30_address = 0x23 + -- i2c interface ID + local id = 0 + --LUX + local l + --CMD + local CMD = 0x10 + local init = false + --Make it more faster + local i2c = i2c + function M.init(sda, scl) + i2c.setup(id, sda, scl, i2c.SLOW) --print("i2c ok..") init = true end diff --git a/tools/update_buildinfo.sh b/tools/update_buildinfo.sh old mode 100755 new mode 100644 From 6a78546707760d98475a6ecc0985ad234a3cfc2d Mon Sep 17 00:00:00 2001 From: Gregor Date: Fri, 12 Jul 2019 21:57:16 +0200 Subject: [PATCH 52/74] update file permission --- tools/update_buildinfo.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 tools/update_buildinfo.sh diff --git a/tools/update_buildinfo.sh b/tools/update_buildinfo.sh old mode 100644 new mode 100755 From 063988f12a21eaeb55912b54aa8a23866731c4bf Mon Sep 17 00:00:00 2001 From: Gregor Date: Fri, 12 Jul 2019 22:39:04 +0200 Subject: [PATCH 53/74] Change DTS to string since it is too big as number --- app/include/user_version.h | 2 ++ app/modules/node.c | 2 +- tools/update_buildinfo.sh | 8 ++------ 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/app/include/user_version.h b/app/include/user_version.h index 20048c678c..33817c5c30 100644 --- a/app/include/user_version.h +++ b/app/include/user_version.h @@ -13,6 +13,8 @@ #define NODE_VERSION_XSTR(x) NODE_VERSION_STR(x) # define NODE_VERSION "NodeMCU " ESP_SDK_VERSION_STRING "." NODE_VERSION_XSTR(NODE_VERSION_INTERNAL) " " NODE_VERSION_LONG +// Leave the space after # in the line above. It busts replacement of NODE_VERSION in the docker build which is not needed anymore with this PR. +// Can be removed when the script is adapted #ifndef BUILD_DATE #define BUILD_DATE "unspecified" diff --git a/app/modules/node.c b/app/modules/node.c index b50fc0db13..af39f2c6ce 100644 --- a/app/modules/node.c +++ b/app/modules/node.c @@ -131,7 +131,7 @@ static int node_info( lua_State* L ) lua_pushstring(L, BUILDINFO_BRANCH); lua_pushstring(L, BUILDINFO_COMMIT_ID); lua_pushstring(L, BUILDINFO_RELEASE); - lua_pushnumber(L, BUILDINFO_RELEASE_DTS); + lua_pushstring(L, BUILDINFO_RELEASE_DTS); lua_pushboolean(L, BUILDINFO_SSL); lua_pushstring(L, BUILDINFO_LFS); lua_pushstring(L, BUILDINFO_MODULES); diff --git a/tools/update_buildinfo.sh b/tools/update_buildinfo.sh index 117ff0f1f4..9e8a553a53 100755 --- a/tools/update_buildinfo.sh +++ b/tools/update_buildinfo.sh @@ -8,9 +8,6 @@ COMMIT_ID="$(git rev-parse HEAD)" BRANCH="$(git rev-parse --abbrev-ref HEAD | sed -r 's/[\/\\]+/_/g')" RELEASE="$(git describe --tags --long | sed -r 's/(.*)-(.*)-.*/\1 +\2/g' | sed 's/ +0$//')" RELEASE_DTS=$(git show -s --format=%cd --date=format:"%Y%m%d%H%M" HEAD) -if [ -z "$RELEASE_DTS"]; then - RELEASE_DTS=0 -fi # figure out whether SSL is enabled in user_config.h if grep -Eq "^#define CLIENT_SSL_ENABLE" $USER_CONFIG_H; then @@ -51,8 +48,7 @@ echo "#define USER_PROLOG \""$USER_PROLOG"\"" >> $TEMPFILE echo "#define BUILDINFO_BRANCH \""$BRANCH"\"" >> $TEMPFILE echo "#define BUILDINFO_COMMIT_ID \""$COMMIT_ID"\"" >> $TEMPFILE echo "#define BUILDINFO_RELEASE \""$RELEASE"\"" >> $TEMPFILE -echo "#define BUILDINFO_RELEASE_DTS "$RELEASE_DTS >> $TEMPFILE -echo "#define BUILDINFO_RELEASE_DTS_STR \""$RELEASE_DTS"\"" >> $TEMPFILE +echo "#define BUILDINFO_RELEASE_DTS \""$RELEASE_DTS"\"" >> $TEMPFILE echo "#define BUILDINFO_SSL "$SSL >> $TEMPFILE echo "#define BUILDINFO_SSL_STR \""$SSL"\"" >> $TEMPFILE echo "#define BUILDINFO_BUILD_TYPE \""$BUILD_TYPE"\"" >> $TEMPFILE @@ -65,7 +61,7 @@ cat >> $TEMPFILE << EndOfMessage2 "\tbranch: " BUILDINFO_BRANCH "\n" \\ "\tcommit: " BUILDINFO_COMMIT_ID "\n" \\ "\trelease: " BUILDINFO_RELEASE "\n" \\ - "\trelease DTS: " BUILDINFO_RELEASE_DTS_STR "\n" \\ + "\trelease DTS: " BUILDINFO_RELEASE_DTS "\n" \\ "\tSSL: " BUILDINFO_SSL_STR "\n" \\ "\tBuild type: " BUILDINFO_BUILD_TYPE "\n" \\ "\tLFS: " BUILDINFO_LFS "\n" \\ From 1c94629ea78544898ae4692bcf3eccb30cfcb8aa Mon Sep 17 00:00:00 2001 From: Gregor Date: Sat, 13 Jul 2019 22:46:58 +0200 Subject: [PATCH 54/74] Added documantation --- docs/modules/node.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/docs/modules/node.md b/docs/modules/node.md index deaa007e83..daea47b808 100644 --- a/docs/modules/node.md +++ b/docs/modules/node.md @@ -272,7 +272,7 @@ system heap size left in bytes (number) ## node.info() -Returns NodeMCU version, chipid, flashid, flash size, flash mode, flash speed, and Lua File Store (LFS) usage statics. +Returns NodeMCU version, chipid, flashid, flash size, flash mode, flash speed, branch, git commit_id, release, release_dts, ssl, lfs info, modules and the build_type. #### Syntax `node.info()` @@ -289,6 +289,15 @@ none - `flashsize` (number) - `flashmode` (number) - `flashspeed` (number) + - `branch` (string) + - `git commit_id` (string) + - `release` (string) Release name +additional commits e.g. "2.0.0-master_20170202 +403" + - `release_dts` (string) in an ordering format. e.g. "201908111200" + - `ssl` (boolean) + - `lfs info` (string) "disabled" or "Size: {whatever is in user_config.h}" + - `modules` (string) comma separated list + - `build_type` (string) `integer` or `float` + #### Example ```lua From 13f22e1f8ea6d40d93919039528572b4343750bc Mon Sep 17 00:00:00 2001 From: Gregor Date: Sat, 13 Jul 2019 23:02:29 +0200 Subject: [PATCH 55/74] Also adapt documentation for building --- docs/build.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/docs/build.md b/docs/build.md index 206f9dd9ae..dc1ddabc45 100644 --- a/docs/build.md +++ b/docs/build.md @@ -93,12 +93,14 @@ make EXTRA_CCFLAGS="-DLUA_NUMBER_INTEGRAL .... ``` ### Tag Your Build -Identify your firmware builds by editing `app/include/user_version.h` +Identify your firmware builds by setting the environment variable `USER_PROLOG`. +You may also edit `app/include/user_version.h`. The variable `USER_PROLOG` will be included in `NODE_VERSION_LONG`. ```c -#define NODE_VERSION "NodeMCU " ESP_SDK_VERSION_STRING "." NODE_VERSION_XSTR(NODE_VERSION_INTERNAL) +#define NODE_VERSION "NodeMCU " ESP_SDK_VERSION_STRING "." NODE_VERSION_XSTR(NODE_VERSION_INTERNAL) " " NODE_VERSION_LONG + #ifndef BUILD_DATE -#define BUILD_DATE "YYYYMMDD" +#define BUILD_DATE "unspecified" #endif ``` From 1d976e54f2a68b934dd435344b40a8edc6ef671f Mon Sep 17 00:00:00 2001 From: Gregor Date: Sat, 13 Jul 2019 23:26:49 +0200 Subject: [PATCH 56/74] inprove USER_PROLOG handling --- tools/update_buildinfo.sh | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/tools/update_buildinfo.sh b/tools/update_buildinfo.sh index 9e8a553a53..d07c51dd7e 100755 --- a/tools/update_buildinfo.sh +++ b/tools/update_buildinfo.sh @@ -40,10 +40,6 @@ cat > $TEMPFILE << EndOfMessage #define __BUILDINFO_H__ EndOfMessage -if [ -n "$USER_PROLOG" ]; then - USER_PROLOG_LINE="$USER_PROLOG"\\n -fi - echo "#define USER_PROLOG \""$USER_PROLOG"\"" >> $TEMPFILE echo "#define BUILDINFO_BRANCH \""$BRANCH"\"" >> $TEMPFILE echo "#define BUILDINFO_COMMIT_ID \""$COMMIT_ID"\"" >> $TEMPFILE @@ -57,7 +53,7 @@ echo "#define BUILDINFO_MODULES \""$MODULES"\"" >> $TEMPFILE cat >> $TEMPFILE << EndOfMessage2 #define NODE_VERSION_LONG \\ - "$USER_PROLOG_LINE" \\ + "$USER_PROLOG \n" \\ "\tbranch: " BUILDINFO_BRANCH "\n" \\ "\tcommit: " BUILDINFO_COMMIT_ID "\n" \\ "\trelease: " BUILDINFO_RELEASE "\n" \\ From dd1f8752839495337c4aa56e34cd0789c8126a22 Mon Sep 17 00:00:00 2001 From: Gregor Date: Fri, 19 Jul 2019 08:53:14 +0200 Subject: [PATCH 57/74] Fix typos and small enhancement of docu --- docs/modules/node.md | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/docs/modules/node.md b/docs/modules/node.md index daea47b808..ee04db2174 100644 --- a/docs/modules/node.md +++ b/docs/modules/node.md @@ -250,13 +250,17 @@ Get the current LFS and SPIFFS partition information. none #### Returns -An array containing entries for `lfs_addr`, `lfs_size`, `spiffs_addr` and `spiffs_size`. The address values are offsets relative to the startof the Flash memory. +An array containing entries for `lfs_addr`, `lfs_size`, `spiffs_addr` and `spiffs_size`. The address values are offsets relative to the start of the Flash memory. #### Example ```lua print("The LFS size is " .. node.getpartitiontable().lfs_size) ``` +#### See also +[`node.setpartitiontable()`](#nodesetpartitiontable) + + ## node.heap() Returns the current available heap size in bytes. Note that due to fragmentation, actual allocations of this size may not be possible. @@ -445,7 +449,7 @@ Sets the current LFS and / or SPIFFS partition information. This function is typically only used once during initial provisioning after first flashing the firmware. It does some consistency checks to validate the specified parameters, and it then reboots the ESP module to load the new partition table. If the LFS or SPIFFS regions have changed then you will need to reload LFS, reformat the SPIFSS and reload its contents. #### Parameters -An array containing one or more of the following enties. The address values are byte offsets relative to the startof the Flash memory. The size values are in bytes. Note that these parameters must be a multiple of 8Kb to align to Flash page boundaries. +An array containing one or more of the following enties. The address values are byte offsets relative to the start of the Flash memory. The size values are in bytes. Note that these parameters must be a multiple of 8Kb to align to Flash page boundaries. - `lfs_addr`. The base address of the LFS region. - `lfs_size`. The size of the LFS region. - `spiffs_addr`. The base address of the SPIFFS region. @@ -459,6 +463,10 @@ Not applicable. The ESP module will be rebooted for a valid new set, or a Lua e node.setpartitiontable{lfs_size = 0x20000, spiffs_addr = 0x120000, spiffs_size = 0x20000} ``` +#### See also +[`node.getpartitiontable()`](#nodegetpartitiontable) + + ## node.sleep() From 5fafa6378c251cd8f03e05bfd7a20bdc67a27bfc Mon Sep 17 00:00:00 2001 From: Gregor Date: Fri, 19 Jul 2019 21:24:22 +0200 Subject: [PATCH 58/74] change to better UI and get information directly from .h file --- .gitignore | 3 ++ app/modules/node.c | 99 ++++++++++++++++++++++++++++++++------- app/user/user_main.c | 2 +- docs/modules/node.md | 67 ++++++++++++++++++-------- tools/update_buildinfo.sh | 54 ++++++++++----------- 5 files changed, 160 insertions(+), 65 deletions(-) diff --git a/.gitignore b/.gitignore index 8336090701..736ae691be 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ local/ user_config.h server-ca.crt luac.cross +luac.cross.int uz_unzip uz_zip tools/toolchains/ @@ -15,4 +16,6 @@ tools/toolchains/ .project .settings/ .vscode + +#ignore temp file for build infos buildinfo.h diff --git a/app/modules/node.c b/app/modules/node.c index af39f2c6ce..962e60732c 100644 --- a/app/modules/node.c +++ b/app/modules/node.c @@ -120,24 +120,87 @@ static int node_sleep( lua_State* L ) #endif //PMSLEEP_ENABLE static int node_info( lua_State* L ) { - lua_pushinteger(L, NODE_VERSION_MAJOR); - lua_pushinteger(L, NODE_VERSION_MINOR); - lua_pushinteger(L, NODE_VERSION_REVISION); - lua_pushinteger(L, system_get_chip_id()); // chip id - lua_pushinteger(L, spi_flash_get_id()); // flash id - lua_pushinteger(L, flash_rom_get_size_byte() / 1024); // flash size in KB - lua_pushinteger(L, flash_rom_get_mode()); - lua_pushinteger(L, flash_rom_get_speed()); - lua_pushstring(L, BUILDINFO_BRANCH); - lua_pushstring(L, BUILDINFO_COMMIT_ID); - lua_pushstring(L, BUILDINFO_RELEASE); - lua_pushstring(L, BUILDINFO_RELEASE_DTS); - lua_pushboolean(L, BUILDINFO_SSL); - lua_pushstring(L, BUILDINFO_LFS); - lua_pushstring(L, BUILDINFO_MODULES); - lua_pushstring(L, BUILDINFO_BUILD_TYPE); - - return 16; + const char* options[] = {"hw", "sw_version", "build_config", "legacy", NULL}; + int option = luaL_checkoption (L, 1, options[3], options); + + switch (option) { + case 0: { // hw + lua_createtable (L, 0, 5); + int table_index = lua_gettop(L); + lua_pushliteral(L, "chip_id"); + lua_pushinteger(L, system_get_chip_id()); // chip id + lua_settable(L, table_index); + lua_pushliteral(L, "flash_id"); + lua_pushinteger(L, spi_flash_get_id()); // flash id + lua_settable(L, table_index); + lua_pushliteral(L, "flash_size"); + lua_pushinteger(L, flash_rom_get_size_byte() / 1024); // flash size in KB + lua_settable(L, table_index); + lua_pushliteral(L, "flash_mode"); + lua_pushinteger(L, flash_rom_get_mode()); + lua_settable(L, table_index); + lua_pushliteral(L, "flash_speed"); + lua_pushinteger(L, flash_rom_get_speed()); + lua_settable(L, table_index); + return 1; + } + case 1: { // sw_version + lua_createtable (L, 0, 7); + int table_index = lua_gettop(L); + lua_pushliteral(L, "node_version_major"); + lua_pushinteger(L, NODE_VERSION_MAJOR); + lua_settable(L, table_index); + lua_pushliteral(L, "node_version_minor"); + lua_pushinteger(L, NODE_VERSION_MINOR); + lua_settable(L, table_index); + lua_pushliteral(L, "node_version_revision"); + lua_pushinteger(L, NODE_VERSION_REVISION); + lua_settable(L, table_index); + lua_pushliteral(L, "git_branch"); + lua_pushstring(L, BUILDINFO_BRANCH); + lua_settable(L, table_index); + lua_pushliteral(L, "git_commit_id"); + lua_pushstring(L, BUILDINFO_COMMIT_ID); + lua_settable(L, table_index); + lua_pushliteral(L, "git_release"); + lua_pushstring(L, BUILDINFO_RELEASE); + lua_settable(L, table_index); + lua_pushliteral(L, "git_commit_dts"); + lua_pushstring(L, BUILDINFO_RELEASE_DTS); + lua_settable(L, table_index); + return 1; + } + case 2: { // build_config + lua_createtable (L, 0, 4); + int table_index = lua_gettop(L); + lua_pushliteral(L, "ssl"); + lua_pushboolean(L, BUILDINFO_SSL); + lua_settable(L, table_index); + lua_pushliteral(L, "lfs_size"); + lua_pushnumber(L, BUILDINFO_LFS); + lua_settable(L, table_index); + lua_pushliteral(L, "modules"); + lua_pushstring(L, BUILDINFO_MODULES); + lua_settable(L, table_index); + lua_pushliteral(L, "number_type"); + lua_pushstring(L, BUILDINFO_BUILD_TYPE); + lua_settable(L, table_index); + return 1; + } + default: + { + platform_print_deprecation_note("node.info() without parameter", "in the next version"); + lua_pushinteger(L, NODE_VERSION_MAJOR); + lua_pushinteger(L, NODE_VERSION_MINOR); + lua_pushinteger(L, NODE_VERSION_REVISION); + lua_pushinteger(L, system_get_chip_id()); // chip id + lua_pushinteger(L, spi_flash_get_id()); // flash id + lua_pushinteger(L, flash_rom_get_size_byte() / 1024); // flash size in KB + lua_pushinteger(L, flash_rom_get_mode()); + lua_pushinteger(L, flash_rom_get_speed()); + return 8; + } + } } // Lua: chipid() diff --git a/app/user/user_main.c b/app/user/user_main.c index 9afb1fb8d1..2b9e97b1c7 100644 --- a/app/user/user_main.c +++ b/app/user/user_main.c @@ -103,7 +103,7 @@ extern void _ResetHandler(void); * the use of a partition table (PT) to control flash allocation. The NodeMCU uses * this PT for overall allocation of its flash resources. The non_OS SDK calls the * user_pre_init() entry to do all of this startup configuration. Note that this - * runs with Icache enabled -- that is the IROM0 partition is already mapped the + * runs with Icache enabled -- that is the IROM0 partition is already mapped to the * address space at 0x40210000 and so that most SDK services are available, such * as system_get_flash_size_map() which returns the valid flash size (including the * 8Mb and 16Mb variants). diff --git a/docs/modules/node.md b/docs/modules/node.md index ee04db2174..2a16f751b6 100644 --- a/docs/modules/node.md +++ b/docs/modules/node.md @@ -276,32 +276,50 @@ system heap size left in bytes (number) ## node.info() -Returns NodeMCU version, chipid, flashid, flash size, flash mode, flash speed, branch, git commit_id, release, release_dts, ssl, lfs info, modules and the build_type. +Returns information about hardware, software version and build configuration. + #### Syntax -`node.info()` +`node.info([kind])` #### Parameters -none +`kind` kind of information (optional, if ommited return legacy information). May be one of `"hw"`, `"sw_version"`, `"build_config"`. #### Returns - - `majorVer` (number) - - `minorVer` (number) - - `devVer` (number) - - `chipid` (number) - - `flashid` (number) - - `flashsize` (number) - - `flashmode` (number) - - `flashspeed` (number) - - `branch` (string) - - `git commit_id` (string) - - `release` (string) Release name +additional commits e.g. "2.0.0-master_20170202 +403" - - `release_dts` (string) in an ordering format. e.g. "201908111200" - - `ssl` (boolean) - - `lfs info` (string) "disabled" or "Size: {whatever is in user_config.h}" - - `modules` (string) comma separated list - - `build_type` (string) `integer` or `float` + if a `kind` is given the return value will be a table containing the following elements: + - for `kind` = `"hw"` + - `chip_id` (number) + - `flash_id` (number) + - `flash_size` (number) + - `flash_mode` (number) QIO = 0, QOUT = 1, DIO = 2, DOUT = 15. + - `flash_speed` (number) + - for `kind` = `"sw_version"` + - `git_branch` (string) + - `git_commit_id` (string) + - `git_release` (string) Release name +additional commits e.g. "2.0.0-master_20170202 +403" + - `git_commit_dts` (string) in an ordering format. e.g. "201908111200" + - `node_verion_major` (number) + - `node_verion_minor` (number) + - `node_verion_revision` (number) + - for `kind` = `"build_config"` + - `ssl` (boolean) + - `lfs_size` (number) as defined at build time + - `modules` (string) comma separated list + - `number_type` (string) `integer` or `float` + +!!! attention +This interface is deprecated and will be removed in one of the next releases. Use the above calls instead. + + - for no `kind` given: --deprecated + - `majorVer` (number) + - `minorVer` (number) + - `devVer` (number) + - `chipid` (number) + - `flashid` (number) + - `flashsize` (number) + - `flashmode` (number) + - `flashspeed` (number) #### Example ```lua @@ -309,6 +327,17 @@ majorVer, minorVer, devVer, chipid, flashid, flashsize, flashmode, flashspeed = print("NodeMCU "..majorVer.."."..minorVer.."."..devVer) ``` +```lua +for k,v in pairs(node.info("build_config")) do +print (k,v) +end +``` + +```lua +print(node.info("sw_version").git_release) +``` + + ## node.input() Submits a string to the Lua interpreter. Similar to `pcall(loadstring(str))`, but without the single-line limitation. diff --git a/tools/update_buildinfo.sh b/tools/update_buildinfo.sh index d07c51dd7e..19aed018e4 100755 --- a/tools/update_buildinfo.sh +++ b/tools/update_buildinfo.sh @@ -9,28 +9,6 @@ BRANCH="$(git rev-parse --abbrev-ref HEAD | sed -r 's/[\/\\]+/_/g')" RELEASE="$(git describe --tags --long | sed -r 's/(.*)-(.*)-.*/\1 +\2/g' | sed 's/ +0$//')" RELEASE_DTS=$(git show -s --format=%cd --date=format:"%Y%m%d%H%M" HEAD) -# figure out whether SSL is enabled in user_config.h -if grep -Eq "^#define CLIENT_SSL_ENABLE" $USER_CONFIG_H; then - SSL="true" -else - SSL="false" -fi - -# figure out whether LFS configuration in user_config.h -LFS=$(grep "^#define LUA_FLASH_STORE" $USER_CONFIG_H | tr -d '\r' | cut -d ' ' -f 3-) -if [ -z "$LFS" ]; then - LFS="disabled" -else - LFS="Size: ${LFS}" -fi - -# figure out whether Int build is enabled in user_config.h -if grep -Eq "^#define LUA_NUMBER_INTEGRAL" $USER_CONFIG_H; then - BUILD_TYPE=integer -else - BUILD_TYPE=float -fi - MODULES=$(awk '/^[ \t]*#define LUA_USE_MODULES/{modules=modules sep tolower(substr($2,17));sep=","}END{if(length(modules)==0)modules="-";print modules}' $USER_MODULES_H | tr -d '\r') # create temp buildinfo @@ -38,6 +16,32 @@ TEMPFILE=/tmp/buildinfo.h cat > $TEMPFILE << EndOfMessage #ifndef __BUILDINFO_H__ #define __BUILDINFO_H__ + +#include "user_config.h" + +#define BUILDINFO_STR_HELPER(x) #x +#define BUILDINFO_TO_STR(x) BUILDINFO_STR_HELPER(x) + +#ifdef LUA_FLASH_STORE +#define BUILDINFO_LFS LUA_FLASH_STORE +#else +#define BUILDINFO_LFS 0 +#endif + +#ifdef CLIENT_SSL_ENABLE +#define BUILDINFO_SSL true +#define BUILDINFO_SSL_STR "true" +#else +#define BUILDINFO_SSL false +#define BUILDINFO_SSL_STR "false" +#endif + +#ifdef LUA_NUMBER_INTEGRAL +#define BUILDINFO_BUILD_TYPE "integer" +#else +#define BUILDINFO_BUILD_TYPE "float" +#endif + EndOfMessage echo "#define USER_PROLOG \""$USER_PROLOG"\"" >> $TEMPFILE @@ -45,10 +49,6 @@ echo "#define BUILDINFO_BRANCH \""$BRANCH"\"" >> $TEMPFILE echo "#define BUILDINFO_COMMIT_ID \""$COMMIT_ID"\"" >> $TEMPFILE echo "#define BUILDINFO_RELEASE \""$RELEASE"\"" >> $TEMPFILE echo "#define BUILDINFO_RELEASE_DTS \""$RELEASE_DTS"\"" >> $TEMPFILE -echo "#define BUILDINFO_SSL "$SSL >> $TEMPFILE -echo "#define BUILDINFO_SSL_STR \""$SSL"\"" >> $TEMPFILE -echo "#define BUILDINFO_BUILD_TYPE \""$BUILD_TYPE"\"" >> $TEMPFILE -echo "#define BUILDINFO_LFS \""$LFS"\"" >> $TEMPFILE echo "#define BUILDINFO_MODULES \""$MODULES"\"" >> $TEMPFILE cat >> $TEMPFILE << EndOfMessage2 @@ -60,7 +60,7 @@ cat >> $TEMPFILE << EndOfMessage2 "\trelease DTS: " BUILDINFO_RELEASE_DTS "\n" \\ "\tSSL: " BUILDINFO_SSL_STR "\n" \\ "\tBuild type: " BUILDINFO_BUILD_TYPE "\n" \\ - "\tLFS: " BUILDINFO_LFS "\n" \\ + "\tLFS: " BUILDINFO_TO_STR(BUILDINFO_LFS) "\n" \\ "\tmodules: " BUILDINFO_MODULES "\n" EndOfMessage2 From 06666a7854729472e9aad13d2ddf4239f9a66fcf Mon Sep 17 00:00:00 2001 From: Gregor Date: Mon, 22 Jul 2019 22:42:06 +0200 Subject: [PATCH 59/74] using lua_setfield now --- app/modules/node.c | 48 ++++++++++++++++------------------------------ 1 file changed, 16 insertions(+), 32 deletions(-) diff --git a/app/modules/node.c b/app/modules/node.c index 962e60732c..167b8b21db 100644 --- a/app/modules/node.c +++ b/app/modules/node.c @@ -127,64 +127,48 @@ static int node_info( lua_State* L ) case 0: { // hw lua_createtable (L, 0, 5); int table_index = lua_gettop(L); - lua_pushliteral(L, "chip_id"); lua_pushinteger(L, system_get_chip_id()); // chip id - lua_settable(L, table_index); - lua_pushliteral(L, "flash_id"); + lua_setfield(L, table_index, "chip_id"); lua_pushinteger(L, spi_flash_get_id()); // flash id - lua_settable(L, table_index); - lua_pushliteral(L, "flash_size"); + lua_setfield(L, table_index, "flash_id"); lua_pushinteger(L, flash_rom_get_size_byte() / 1024); // flash size in KB - lua_settable(L, table_index); - lua_pushliteral(L, "flash_mode"); + lua_setfield(L, table_index, "flash_size"); lua_pushinteger(L, flash_rom_get_mode()); - lua_settable(L, table_index); - lua_pushliteral(L, "flash_speed"); + lua_setfield(L, table_index, "flash_mode"); lua_pushinteger(L, flash_rom_get_speed()); - lua_settable(L, table_index); + lua_setfield(L, table_index, "flash_speed"); return 1; } case 1: { // sw_version lua_createtable (L, 0, 7); int table_index = lua_gettop(L); - lua_pushliteral(L, "node_version_major"); lua_pushinteger(L, NODE_VERSION_MAJOR); - lua_settable(L, table_index); - lua_pushliteral(L, "node_version_minor"); + lua_setfield(L, table_index, "node_version_major"); lua_pushinteger(L, NODE_VERSION_MINOR); - lua_settable(L, table_index); - lua_pushliteral(L, "node_version_revision"); + lua_setfield(L, table_index, "node_version_minor"); lua_pushinteger(L, NODE_VERSION_REVISION); - lua_settable(L, table_index); - lua_pushliteral(L, "git_branch"); + lua_setfield(L, table_index, "node_version_revision"); lua_pushstring(L, BUILDINFO_BRANCH); - lua_settable(L, table_index); - lua_pushliteral(L, "git_commit_id"); + lua_setfield(L, table_index, "git_branch"); lua_pushstring(L, BUILDINFO_COMMIT_ID); - lua_settable(L, table_index); - lua_pushliteral(L, "git_release"); + lua_setfield(L, table_index, "git_commit_id"); lua_pushstring(L, BUILDINFO_RELEASE); - lua_settable(L, table_index); - lua_pushliteral(L, "git_commit_dts"); + lua_setfield(L, table_index, "git_release"); lua_pushstring(L, BUILDINFO_RELEASE_DTS); - lua_settable(L, table_index); + lua_setfield(L, table_index, "git_commit_dts"); return 1; } case 2: { // build_config lua_createtable (L, 0, 4); int table_index = lua_gettop(L); - lua_pushliteral(L, "ssl"); lua_pushboolean(L, BUILDINFO_SSL); - lua_settable(L, table_index); - lua_pushliteral(L, "lfs_size"); + lua_setfield(L, table_index, "ssl"); lua_pushnumber(L, BUILDINFO_LFS); - lua_settable(L, table_index); - lua_pushliteral(L, "modules"); + lua_setfield(L, table_index, "lfs_size"); lua_pushstring(L, BUILDINFO_MODULES); - lua_settable(L, table_index); - lua_pushliteral(L, "number_type"); + lua_setfield(L, table_index, "modules"); lua_pushstring(L, BUILDINFO_BUILD_TYPE); - lua_settable(L, table_index); + lua_setfield(L, table_index, "number_type"); return 1; } default: From 9eec82fead4eaf1f37a2ceaf84d1f917f69e7cc1 Mon Sep 17 00:00:00 2001 From: Gregor Date: Mon, 22 Jul 2019 23:43:53 +0200 Subject: [PATCH 60/74] Get DTS in UTC as Marcel proposed. --- tools/update_buildinfo.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/update_buildinfo.sh b/tools/update_buildinfo.sh index 19aed018e4..5b2f1b7c00 100755 --- a/tools/update_buildinfo.sh +++ b/tools/update_buildinfo.sh @@ -7,7 +7,7 @@ BUILD_DATE="$(date "+%Y-%m-%d %H:%M")" COMMIT_ID="$(git rev-parse HEAD)" BRANCH="$(git rev-parse --abbrev-ref HEAD | sed -r 's/[\/\\]+/_/g')" RELEASE="$(git describe --tags --long | sed -r 's/(.*)-(.*)-.*/\1 +\2/g' | sed 's/ +0$//')" -RELEASE_DTS=$(git show -s --format=%cd --date=format:"%Y%m%d%H%M" HEAD) +RELEASE_DTS=$(TZ=UTC git show --quiet --date=format-local:"%Y%m%d%H%M" --format="%cd" HEAD) MODULES=$(awk '/^[ \t]*#define LUA_USE_MODULES/{modules=modules sep tolower(substr($2,17));sep=","}END{if(length(modules)==0)modules="-";print modules}' $USER_MODULES_H | tr -d '\r') From 73e6651fe89e95d534bbaa9e68cc6085409ded3b Mon Sep 17 00:00:00 2001 From: Gregor Hartmann Date: Sat, 27 Jul 2019 08:21:35 +0200 Subject: [PATCH 61/74] Add support for DCHP NTP server (option 42) (#2709) * Add DHCP option 42 / NTP * Update dhcp.c * resolve merge conflict * add lineend at end of file * fix merge conflict resolution error --- app/include/lwip/dhcp.h | 4 ++++ app/lwip/core/dhcp.c | 49 ++++++++++++++++++++++++++--------------- app/modules/sntp.c | 28 ++++++++++++++++------- 3 files changed, 55 insertions(+), 26 deletions(-) diff --git a/app/include/lwip/dhcp.h b/app/include/lwip/dhcp.h index f94d85d8a4..e7606ce24b 100644 --- a/app/include/lwip/dhcp.h +++ b/app/include/lwip/dhcp.h @@ -53,6 +53,7 @@ struct dhcp ip_addr_t offered_ip_addr; ip_addr_t offered_sn_mask; ip_addr_t offered_gw_addr; + ip_addr_t offered_ntp_addr; u32_t offered_t0_lease; /* lease period (in seconds) */ u32_t offered_t1_renew; /* recommended renew time (usually 50% of lease period) */ @@ -207,6 +208,9 @@ void dhcp_fine_tmr(void); #define DHCP_OPTION_TCP_TTL 37 #define DHCP_OPTION_END 255 +/* time */ +#define DHCP_OPTION_NTP 42 + /**add options for support more router by liuHan**/ #define DHCP_OPTION_DOMAIN_NAME 15 #define DHCP_OPTION_PRD 31 diff --git a/app/lwip/core/dhcp.c b/app/lwip/core/dhcp.c index 88ac82a64c..bfc65cc540 100644 --- a/app/lwip/core/dhcp.c +++ b/app/lwip/core/dhcp.c @@ -119,7 +119,8 @@ static const char mem_debug_file[] ICACHE_RODATA_ATTR = __FILE__; #define DHCP_OPTION_IDX_T2 5 #define DHCP_OPTION_IDX_SUBNET_MASK 6 #define DHCP_OPTION_IDX_ROUTER 7 -#define DHCP_OPTION_IDX_DNS_SERVER 8 +#define DHCP_OPTION_IDX_NTP 8 +#define DHCP_OPTION_IDX_DNS_SERVER 9 #define DHCP_OPTION_IDX_MAX (DHCP_OPTION_IDX_DNS_SERVER + DNS_MAX_SERVERS) /** Holds the decoded option values, only valid while in dhcp_recv. @@ -292,19 +293,20 @@ dhcp_select(struct netif *netif) dhcp_option(dhcp, DHCP_OPTION_SERVER_ID, 4); dhcp_option_long(dhcp, ntohl(ip4_addr_get_u32(&dhcp->server_ip_addr))); - dhcp_option(dhcp, DHCP_OPTION_PARAMETER_REQUEST_LIST, 12/*num options*/); + dhcp_option(dhcp, DHCP_OPTION_PARAMETER_REQUEST_LIST, 13/*num options*/); dhcp_option_byte(dhcp, DHCP_OPTION_SUBNET_MASK); dhcp_option_byte(dhcp, DHCP_OPTION_ROUTER); dhcp_option_byte(dhcp, DHCP_OPTION_BROADCAST); dhcp_option_byte(dhcp, DHCP_OPTION_DNS_SERVER); + dhcp_option_byte(dhcp, DHCP_OPTION_NTP); dhcp_option_byte(dhcp, DHCP_OPTION_DOMAIN_NAME); - dhcp_option_byte(dhcp, DHCP_OPTION_NB_TINS); - dhcp_option_byte(dhcp, DHCP_OPTION_NB_TINT); - dhcp_option_byte(dhcp, DHCP_OPTION_NB_TIS); - dhcp_option_byte(dhcp, DHCP_OPTION_PRD); - dhcp_option_byte(dhcp, DHCP_OPTION_STATIC_ROUTER); - dhcp_option_byte(dhcp, DHCP_OPTION_CLASSLESS_STATIC_ROUTER); - dhcp_option_byte(dhcp, DHCP_OPTION_VSN); + dhcp_option_byte(dhcp, DHCP_OPTION_NB_TINS); + dhcp_option_byte(dhcp, DHCP_OPTION_NB_TINT); + dhcp_option_byte(dhcp, DHCP_OPTION_NB_TIS); + dhcp_option_byte(dhcp, DHCP_OPTION_PRD); + dhcp_option_byte(dhcp, DHCP_OPTION_STATIC_ROUTER); + dhcp_option_byte(dhcp, DHCP_OPTION_CLASSLESS_STATIC_ROUTER); + dhcp_option_byte(dhcp, DHCP_OPTION_VSN); #if LWIP_NETIF_HOSTNAME if (netif->hostname != NULL) { @@ -383,7 +385,7 @@ dhcp_fine_tmr() if (netif->dhcp != NULL) { /*add DHCP retries processing by LiuHan*/ if (DHCP_MAXRTX != 0) { - if (netif->dhcp->tries >= DHCP_MAXRTX){ + if (netif->dhcp->tries >= DHCP_MAXRTX){ os_printf("DHCP timeout\n"); if (netif->dhcp_event != NULL) netif->dhcp_event(); @@ -536,6 +538,7 @@ dhcp_handle_ack(struct netif *netif) #if LWIP_DHCP_BOOTP_FILE ip_addr_set_zero(&dhcp->offered_si_addr); #endif /* LWIP_DHCP_BOOTP_FILE */ + ip_addr_set_zero(&dhcp->offered_ntp_addr); /* lease time given? */ if (dhcp_option_given(dhcp, DHCP_OPTION_IDX_LEASE_TIME)) { @@ -593,6 +596,10 @@ dhcp_handle_ack(struct netif *netif) n++; } #endif /* LWIP_DNS */ + + if (dhcp_option_given(dhcp, DHCP_OPTION_IDX_NTP)) { + ip4_addr_set_u32(&dhcp->offered_ntp_addr, htonl(dhcp_get_option_value(dhcp, DHCP_OPTION_IDX_NTP))); + } } /** Set a statically allocated struct dhcp to work with. @@ -915,19 +922,20 @@ dhcp_discover(struct netif *netif) } } #endif /* LWIP_NETIF_HOSTNAME */ - dhcp_option(dhcp, DHCP_OPTION_PARAMETER_REQUEST_LIST, 12/*num options*/); + dhcp_option(dhcp, DHCP_OPTION_PARAMETER_REQUEST_LIST, 13/*num options*/); dhcp_option_byte(dhcp, DHCP_OPTION_SUBNET_MASK); dhcp_option_byte(dhcp, DHCP_OPTION_ROUTER); dhcp_option_byte(dhcp, DHCP_OPTION_BROADCAST); dhcp_option_byte(dhcp, DHCP_OPTION_DNS_SERVER); + dhcp_option_byte(dhcp, DHCP_OPTION_NTP); dhcp_option_byte(dhcp, DHCP_OPTION_DOMAIN_NAME); - dhcp_option_byte(dhcp, DHCP_OPTION_NB_TINS); - dhcp_option_byte(dhcp, DHCP_OPTION_NB_TINT); - dhcp_option_byte(dhcp, DHCP_OPTION_NB_TIS); - dhcp_option_byte(dhcp, DHCP_OPTION_PRD); - dhcp_option_byte(dhcp, DHCP_OPTION_STATIC_ROUTER); - dhcp_option_byte(dhcp, DHCP_OPTION_CLASSLESS_STATIC_ROUTER); - dhcp_option_byte(dhcp, DHCP_OPTION_VSN); + dhcp_option_byte(dhcp, DHCP_OPTION_NB_TINS); + dhcp_option_byte(dhcp, DHCP_OPTION_NB_TINT); + dhcp_option_byte(dhcp, DHCP_OPTION_NB_TIS); + dhcp_option_byte(dhcp, DHCP_OPTION_PRD); + dhcp_option_byte(dhcp, DHCP_OPTION_STATIC_ROUTER); + dhcp_option_byte(dhcp, DHCP_OPTION_CLASSLESS_STATIC_ROUTER); + dhcp_option_byte(dhcp, DHCP_OPTION_VSN); dhcp_option_trailer(dhcp); @@ -1253,6 +1261,7 @@ dhcp_release(struct netif *netif) #if LWIP_DHCP_BOOTP_FILE ip_addr_set_zero(&dhcp->offered_si_addr); #endif /* LWIP_DHCP_BOOTP_FILE */ + ip_addr_set_zero(&dhcp->offered_ntp_addr); dhcp->offered_t0_lease = dhcp->offered_t1_renew = dhcp->offered_t2_rebind = 0; /* create and initialize the DHCP message header */ @@ -1463,6 +1472,10 @@ dhcp_parse_reply(struct dhcp *dhcp, struct pbuf *p) LWIP_ASSERT("len >= decode_len", len >= decode_len); decode_idx = DHCP_OPTION_IDX_DNS_SERVER; break; + case(DHCP_OPTION_NTP): + LWIP_ASSERT("len == 4", len == 4); + decode_idx = DHCP_OPTION_IDX_NTP; + break; case(DHCP_OPTION_LEASE_TIME): LWIP_ASSERT("len == 4", len == 4); decode_idx = DHCP_OPTION_IDX_LEASE_TIME; diff --git a/app/modules/sntp.c b/app/modules/sntp.c index 9af8bda9f3..97ae32a8bf 100644 --- a/app/modules/sntp.c +++ b/app/modules/sntp.c @@ -39,6 +39,8 @@ #include "osapi.h" #include "lwip/udp.h" #include +#include "lwip/inet.h" +#include "lwip/dhcp.h" #include "user_modules.h" #include "lwip/dns.h" #include "task/task.h" @@ -48,6 +50,8 @@ #include "rtc/rtctime.h" #endif +struct netif * eagle_lwip_getif(uint8 index); + #define max(a,b) ((a < b) ? b : a) #define NTP_PORT 123 @@ -805,15 +809,23 @@ static int sntp_sync (lua_State *L) server_count++; } } else if (server_count == 0) { - // default to ntp pool lua_newtable(L); - int i; - for (i = 0; i < 4; i++) { - lua_pushnumber(L, i + 1); - char buf[64]; - sprintf(buf, "%d.nodemcu.pool.ntp.org", i); - lua_pushstring(L, buf); - lua_settable(L, -3); + struct netif *iface = (struct netif *)eagle_lwip_getif(0x00); + if (iface->dhcp && iface->dhcp->offered_ntp_addr.addr) { + ip_addr_t ntp_addr = iface->dhcp->offered_ntp_addr; + lua_pushnumber(L, 1); + lua_pushstring(L, inet_ntoa(ntp_addr)); + lua_settable(L, -3); + } else { + // default to ntp pool + int i; + for (i = 0; i < 4; i++) { + lua_pushnumber(L, i + 1); + char buf[64]; + sprintf(buf, "%d.nodemcu.pool.ntp.org", i); + lua_pushstring(L, buf); + lua_settable(L, -3); + } } luaL_unref (L, LUA_REGISTRYINDEX, state->list_ref); state->list_ref = luaL_ref(L, LUA_REGISTRYINDEX); From 0ff3084fe35d120c056cdfac8d4f35088d8c8d86 Mon Sep 17 00:00:00 2001 From: Gregor Date: Sat, 27 Jul 2019 08:27:19 +0200 Subject: [PATCH 62/74] small fixes as outcome of review --- docs/modules/node.md | 14 +++++++------- tools/update_buildinfo.sh | 21 ++++++++------------- 2 files changed, 15 insertions(+), 20 deletions(-) diff --git a/docs/modules/node.md b/docs/modules/node.md index 2a16f751b6..1db3196483 100644 --- a/docs/modules/node.md +++ b/docs/modules/node.md @@ -280,20 +280,20 @@ Returns information about hardware, software version and build configuration. #### Syntax -`node.info([kind])` +`node.info([group])` #### Parameters -`kind` kind of information (optional, if ommited return legacy information). May be one of `"hw"`, `"sw_version"`, `"build_config"`. +`group` group of information (optional, if ommited return legacy information). May be one of `"hw"`, `"sw_version"`, `"build_config"`. #### Returns - if a `kind` is given the return value will be a table containing the following elements: - - for `kind` = `"hw"` + if a `group` is given the return value will be a table containing the following elements: + - for `group` = `"hw"` - `chip_id` (number) - `flash_id` (number) - `flash_size` (number) - `flash_mode` (number) QIO = 0, QOUT = 1, DIO = 2, DOUT = 15. - `flash_speed` (number) - - for `kind` = `"sw_version"` + - for `group` = `"sw_version"` - `git_branch` (string) - `git_commit_id` (string) - `git_release` (string) Release name +additional commits e.g. "2.0.0-master_20170202 +403" @@ -301,7 +301,7 @@ Returns information about hardware, software version and build configuration. - `node_verion_major` (number) - `node_verion_minor` (number) - `node_verion_revision` (number) - - for `kind` = `"build_config"` + - for `group` = `"build_config"` - `ssl` (boolean) - `lfs_size` (number) as defined at build time - `modules` (string) comma separated list @@ -311,7 +311,7 @@ Returns information about hardware, software version and build configuration. This interface is deprecated and will be removed in one of the next releases. Use the above calls instead. - - for no `kind` given: --deprecated + - for no `group` given: --deprecated - `majorVer` (number) - `minorVer` (number) - `devVer` (number) diff --git a/tools/update_buildinfo.sh b/tools/update_buildinfo.sh index 5b2f1b7c00..bb2ee5cbd2 100755 --- a/tools/update_buildinfo.sh +++ b/tools/update_buildinfo.sh @@ -1,9 +1,7 @@ #!/usr/bin/env bash USER_MODULES_H=app/include/user_modules.h -USER_CONFIG_H=app/include/user_config.h -BUILD_DATE="$(date "+%Y-%m-%d %H:%M")" COMMIT_ID="$(git rev-parse HEAD)" BRANCH="$(git rev-parse --abbrev-ref HEAD | sed -r 's/[\/\\]+/_/g')" RELEASE="$(git describe --tags --long | sed -r 's/(.*)-(.*)-.*/\1 +\2/g' | sed 's/ +0$//')" @@ -42,18 +40,15 @@ cat > $TEMPFILE << EndOfMessage #define BUILDINFO_BUILD_TYPE "float" #endif -EndOfMessage - -echo "#define USER_PROLOG \""$USER_PROLOG"\"" >> $TEMPFILE -echo "#define BUILDINFO_BRANCH \""$BRANCH"\"" >> $TEMPFILE -echo "#define BUILDINFO_COMMIT_ID \""$COMMIT_ID"\"" >> $TEMPFILE -echo "#define BUILDINFO_RELEASE \""$RELEASE"\"" >> $TEMPFILE -echo "#define BUILDINFO_RELEASE_DTS \""$RELEASE_DTS"\"" >> $TEMPFILE -echo "#define BUILDINFO_MODULES \""$MODULES"\"" >> $TEMPFILE +#define USER_PROLOG "$USER_PROLOG" +#define BUILDINFO_BRANCH "$BRANCH" +#define BUILDINFO_COMMIT_ID "$COMMIT_ID" +#define BUILDINFO_RELEASE "$RELEASE" +#define BUILDINFO_RELEASE_DTS "$RELEASE_DTS" +#define BUILDINFO_MODULES "$MODULES" -cat >> $TEMPFILE << EndOfMessage2 #define NODE_VERSION_LONG \\ - "$USER_PROLOG \n" \\ + USER_PROLOG "\n" \\ "\tbranch: " BUILDINFO_BRANCH "\n" \\ "\tcommit: " BUILDINFO_COMMIT_ID "\n" \\ "\trelease: " BUILDINFO_RELEASE "\n" \\ @@ -63,7 +58,7 @@ cat >> $TEMPFILE << EndOfMessage2 "\tLFS: " BUILDINFO_TO_STR(BUILDINFO_LFS) "\n" \\ "\tmodules: " BUILDINFO_MODULES "\n" -EndOfMessage2 +EndOfMessage echo "#endif /* __BUILDINFO_H__ */" >> $TEMPFILE From 825e35053f00e0816fb31c85c0fa967c16183369 Mon Sep 17 00:00:00 2001 From: Gregor Hartmann Date: Sat, 27 Jul 2019 12:55:34 +0200 Subject: [PATCH 63/74] have common capitalization in startup message --- tools/update_buildinfo.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/update_buildinfo.sh b/tools/update_buildinfo.sh index bb2ee5cbd2..9113ec5716 100755 --- a/tools/update_buildinfo.sh +++ b/tools/update_buildinfo.sh @@ -54,7 +54,7 @@ cat > $TEMPFILE << EndOfMessage "\trelease: " BUILDINFO_RELEASE "\n" \\ "\trelease DTS: " BUILDINFO_RELEASE_DTS "\n" \\ "\tSSL: " BUILDINFO_SSL_STR "\n" \\ - "\tBuild type: " BUILDINFO_BUILD_TYPE "\n" \\ + "\tbuild type: " BUILDINFO_BUILD_TYPE "\n" \\ "\tLFS: " BUILDINFO_TO_STR(BUILDINFO_LFS) "\n" \\ "\tmodules: " BUILDINFO_MODULES "\n" From d054d17694f09fe5710cf0adb6f434117c808dd4 Mon Sep 17 00:00:00 2001 From: Gregor Hartmann Date: Sat, 27 Jul 2019 13:09:11 +0200 Subject: [PATCH 64/74] adapt sed calls for macOS --- tools/update_buildinfo.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/update_buildinfo.sh b/tools/update_buildinfo.sh index 9113ec5716..99a376f993 100755 --- a/tools/update_buildinfo.sh +++ b/tools/update_buildinfo.sh @@ -3,8 +3,8 @@ USER_MODULES_H=app/include/user_modules.h COMMIT_ID="$(git rev-parse HEAD)" -BRANCH="$(git rev-parse --abbrev-ref HEAD | sed -r 's/[\/\\]+/_/g')" -RELEASE="$(git describe --tags --long | sed -r 's/(.*)-(.*)-.*/\1 +\2/g' | sed 's/ +0$//')" +BRANCH="$(git rev-parse --abbrev-ref HEAD | sed -E 's/[\/\\]+/_/g')" +RELEASE="$(git describe --tags --long | sed -E 's/(.*)-(.*)-.*/\1 +\2/g' | sed 's/ +0$//')" RELEASE_DTS=$(TZ=UTC git show --quiet --date=format-local:"%Y%m%d%H%M" --format="%cd" HEAD) MODULES=$(awk '/^[ \t]*#define LUA_USE_MODULES/{modules=modules sep tolower(substr($2,17));sep=","}END{if(length(modules)==0)modules="-";print modules}' $USER_MODULES_H | tr -d '\r') From 3d30c985cb3b7f21d31f5fa1568b5c8272aa9140 Mon Sep 17 00:00:00 2001 From: Nathaniel Wesley Filardo Date: Sat, 27 Jul 2019 13:18:34 +0100 Subject: [PATCH 65/74] Clarify DNS callbacks (#2860) --- docs/modules/net.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/docs/modules/net.md b/docs/modules/net.md index 1667b85920..dd1c0ee495 100644 --- a/docs/modules/net.md +++ b/docs/modules/net.md @@ -236,6 +236,10 @@ Provides DNS resolution for a hostname. - `domain` domain name - `function(net.socket, ip)` callback function. The first parameter is the socket, the second parameter is the IP address as a string. +If a callback `c` is provided, it is equivalent to having called `:on("dns", +c)` on this socket; this callback will, hereafter, receive any pending +resolution results recieved for this socket! + #### Returns `nil` @@ -580,6 +584,11 @@ Resolve a hostname to an IP address. Doesn't require a socket like [`net.socket. - `host` hostname to resolve - `function(sk, ip)` callback called when the name was resolved. `sk` is always `nil` +There is at most one callback for all `net.dns.resolve()` requests at any time; +all resolution results are sent to the most recent callback specified at time +of receipt! If multiple DNS callbacks are needed, associate them with separate +sockets using [`net.socket:dns()`](#netsocketdns). + #### Returns `nil` From 7d387dd4d680a07065ddf8b554087a0be8ae0cd6 Mon Sep 17 00:00:00 2001 From: Nathaniel Wesley Filardo Date: Sat, 27 Jul 2019 13:20:26 +0100 Subject: [PATCH 66/74] Simplify and tidy SNTP (#2700) * list_ref can become LUA_REFNIL, because that's what rawgeti returns for LUA_NOREF. Defensively guard for this, rather than falling into the sntp_dolookups loop with nil on the stack. * set_repeat_mode should not call itself, but should rather always do what it's going to do and then optionally do the rest if directed. * sntp_sync should not try to special case the single string argument: we should be queueing that name for DNS resolution, too. Towards that end, if we are given a single string, build a table and make that the list_ref and call off to sntp_dolookups, just like we otherwise do. FIXES: #2699 --- app/modules/sntp.c | 46 +++++++++++++++++++--------------------------- 1 file changed, 19 insertions(+), 27 deletions(-) diff --git a/app/modules/sntp.c b/app/modules/sntp.c index 97ae32a8bf..887129b0c3 100644 --- a/app/modules/sntp.c +++ b/app/modules/sntp.c @@ -627,7 +627,7 @@ static void sntp_dolookups (lua_State *L) { // Step through each element of the table, converting it to an address // at the end, start the lookups. If we have already looked everything up, // then move straight to sending the packets. - if (state->list_ref == LUA_NOREF) { + if ((state->list_ref == LUA_NOREF) || (state->list_ref == LUA_REFNIL)) { sntp_dosend(); return; } @@ -702,8 +702,16 @@ static char *state_init(lua_State *L) { static char *set_repeat_mode(lua_State *L, bool enable) { + if (repeat) { + os_timer_disarm (&repeat->timer); + luaL_unref (L, LUA_REGISTRYINDEX, repeat->sync_cb_ref); + luaL_unref (L, LUA_REGISTRYINDEX, repeat->err_cb_ref); + luaL_unref (L, LUA_REGISTRYINDEX, repeat->list_ref); + free(repeat); + repeat = NULL; + } + if (enable) { - set_repeat_mode(L, FALSE); repeat = (sntp_repeat_t *) malloc(sizeof(sntp_repeat_t)); if (!repeat) { return "no memory"; @@ -720,16 +728,8 @@ static char *set_repeat_mode(lua_State *L, bool enable) //The function on_long_timeout returns errors to the developer //My guess: Error reporting is a good thing, resume the timer. os_timer_arm(&repeat->timer, 1000 * 1000, 1); - } else { - if (repeat) { - os_timer_disarm (&repeat->timer); - luaL_unref (L, LUA_REGISTRYINDEX, repeat->sync_cb_ref); - luaL_unref (L, LUA_REGISTRYINDEX, repeat->err_cb_ref); - luaL_unref (L, LUA_REGISTRYINDEX, repeat->list_ref); - free(repeat); - repeat = NULL; - } } + return NULL; } @@ -791,22 +791,17 @@ static int sntp_sync (lua_State *L) if (lua_istable(L, 1)) { // Save a reference to the table lua_pushvalue(L, 1); - luaL_unref (L, LUA_REGISTRYINDEX, state->list_ref); - state->list_ref = luaL_ref(L, LUA_REGISTRYINDEX); - sntp_dolookups(L); - goto good_ret; } else { size_t l; const char *hostname = luaL_checklstring(L, 1, &l); if (l>128 || hostname == NULL) sync_err("need <128 hostname"); - err_t err = dns_gethostbyname(hostname, get_free_server(), sntp_dns_found, state); - if (err == ERR_INPROGRESS) { - goto good_ret; - } else if (err == ERR_ARG) - sync_err("bad hostname"); - server_count++; + /* Construct a singleton table containing the one server */ + lua_newtable(L); + lua_pushnumber(L, 1); + lua_pushstring(L, hostname); + lua_settable(L, -3); } } else if (server_count == 0) { lua_newtable(L); @@ -827,15 +822,12 @@ static int sntp_sync (lua_State *L) lua_settable(L, -3); } } - luaL_unref (L, LUA_REGISTRYINDEX, state->list_ref); - state->list_ref = luaL_ref(L, LUA_REGISTRYINDEX); - sntp_dolookups(L); - goto good_ret; } - sntp_dosend (); + luaL_unref (L, LUA_REGISTRYINDEX, state->list_ref); + state->list_ref = luaL_ref(L, LUA_REGISTRYINDEX); + sntp_dolookups(L); -good_ret: if (!lua_isnoneornil(L, 4)) { set_repeat_mode(L, 1); } From 49ac968bde4d64f73e06c132cf8840932eaf651a Mon Sep 17 00:00:00 2001 From: Nathaniel Wesley Filardo Date: Sat, 27 Jul 2019 13:21:52 +0100 Subject: [PATCH 67/74] Lost fixes to nodemcu-partition.py (#2861) --- tools/nodemcu-partition.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/nodemcu-partition.py b/tools/nodemcu-partition.py index c168729cd0..d3c0b214c3 100755 --- a/tools/nodemcu-partition.py +++ b/tools/nodemcu-partition.py @@ -126,7 +126,7 @@ def load_PT(data, args): """ PTrec,recs = unpack_RCR(data) - flash_size = fs.args if args.fs is not None else DEFAULT_FLASH_SIZE + flash_size = args.fs if args.fs is not None else DEFAULT_FLASH_SIZE # The partition table format is a set of 3*uint32 fields (type, addr, size), # with the optional last slot being an end marker (0,size,0) where size is @@ -367,7 +367,7 @@ def arg_auto_int(x): # ---------- Write to a temp file and use esptool to write it to flash ---------- # spiffs_file = arg.sf - espargs = base + ['', str(sa), spiffs_file] + espargs = base + ['write_flash', str(sa), spiffs_file] esptool.main(espargs) # ---------- Clean up temp directory ---------- # From 0659e5529ed16be097d0cef1e729a7eddd0cd25c Mon Sep 17 00:00:00 2001 From: Gregor Hartmann Date: Thu, 1 Aug 2019 21:31:18 +0200 Subject: [PATCH 68/74] Fix enduser_setup default POST request (#2852) --- app/modules/enduser_setup.c | 62 +++++++++++++++++++++---------------- 1 file changed, 36 insertions(+), 26 deletions(-) diff --git a/app/modules/enduser_setup.c b/app/modules/enduser_setup.c index caf676d43d..b7e06d2bcf 100644 --- a/app/modules/enduser_setup.c +++ b/app/modules/enduser_setup.c @@ -397,18 +397,25 @@ static err_t close_once_sent (void *arg, struct tcp_pcb *pcb, u16_t len) /* ------------------------------------------------------------------------- */ /** - * Search String - * - * Search string for first occurence of any char in srch_str. + * Get length of param value + * + * This is being called with a fragment of the parameters passed in the + * URL for GET requests or part of the body of a POST request. + * The string will look like one of these + * "SecretPassword HTTP/1.1" + * "SecretPassword&wifi_ssid=..." + * "SecretPassword" + * The string is searched for the first occurence of deliemiter '&' or ' '. + * If found return the length up to that position. + * If not found return the length of the string. * - * @return -1 if no occurence of char was found. */ -static int enduser_setup_srch_str(const char *str, const char *srch_str) +static int enduser_setup_get_lenth_of_param_value(const char *str) { - char *found = strpbrk (str, srch_str); + char *found = strpbrk (str, "& "); if (!found) { - return -1; + return strlen(str); } else { @@ -469,6 +476,11 @@ static int enduser_setup_http_load_payload(void) { ENDUSER_SETUP_DEBUG("Unable to load file enduser_setup.html, loading default HTML..."); + if (f) + { + vfs_close(f); + } + sprintf(cl_hdr, http_header_content_len_fmt, sizeof(enduser_setup_html_default)); cl_len = strlen(cl_hdr); int html_len = LITLEN(enduser_setup_html_default); @@ -801,8 +813,8 @@ static int enduser_setup_http_handle_credentials(char *data, unsigned short data state->success = 0; state->lastStationStatus = 0; - char *name_str = (char *) ((uint32_t)strstr(&(data[6]), "wifi_ssid=")); - char *pwd_str = (char *) ((uint32_t)strstr(&(data[6]), "wifi_password=")); + char *name_str = strstr(data, "wifi_ssid="); + char *pwd_str = strstr(data, "wifi_password="); if (name_str == NULL || pwd_str == NULL) { ENDUSER_SETUP_DEBUG("Password or SSID string not found"); @@ -814,13 +826,8 @@ static int enduser_setup_http_handle_credentials(char *data, unsigned short data char *name_str_start = name_str + name_field_len; char *pwd_str_start = pwd_str + pwd_field_len; - int name_str_len = enduser_setup_srch_str(name_str_start, "& "); - int pwd_str_len = enduser_setup_srch_str(pwd_str_start, "& "); - if (name_str_len == -1 || pwd_str_len == -1) - { - ENDUSER_SETUP_DEBUG("Password or SSID HTTP paramter divider not found"); - return 1; - } + int name_str_len = enduser_setup_get_lenth_of_param_value(name_str_start); + int pwd_str_len = enduser_setup_get_lenth_of_param_value(pwd_str_start); struct station_config *cnf = luaM_malloc(lua_getstate(), sizeof(struct station_config)); @@ -1111,22 +1118,25 @@ static void enduser_setup_handle_OPTIONS (struct tcp_pcb *http_client, char *dat } -static err_t enduser_setup_handle_POST(struct tcp_pcb *http_client, char* data, size_t data_len) +static void enduser_setup_handle_POST(struct tcp_pcb *http_client, char* data, size_t data_len) { ENDUSER_SETUP_DEBUG("Handling POST"); if (strncmp(data + 5, "/setwifi ", 9) == 0) // User clicked the submit button { - switch (enduser_setup_http_handle_credentials(data, data_len)) + char* body=strstr(data, "\r\n\r\n"); + char *content_length_str = strstr(data, "Content-Length: "); + if( body == NULL || content_length_str == NULL) + { + enduser_setup_http_serve_header(http_client, http_header_400, LITLEN(http_header_400)); + return; + } + int bodylength = atoi(content_length_str + 16); + body += 4; // length of the double CRLF found above + switch (enduser_setup_http_handle_credentials(body, bodylength)) { case 0: { // all went fine, extract all the form data into a file - char* body=strstr(data, "\r\n\r\n"); - char *content_length_str = strstr(data, "Content-Length: "); - if( body != NULL && content_length_str != NULL){ - int bodylength = atoi(content_length_str + 16); - body += 4; // length of the double CRLF found above enduser_setup_write_file_with_extra_configuration_data(body, bodylength); - } // redirect user to the base page with the trying flag enduser_setup_http_serve_header(http_client, http_header_302_trying, LITLEN(http_header_302_trying)); break; @@ -1135,10 +1145,10 @@ static err_t enduser_setup_handle_POST(struct tcp_pcb *http_client, char* data, enduser_setup_http_serve_header(http_client, http_header_400, LITLEN(http_header_400)); break; default: - ENDUSER_SETUP_ERROR("http_recvcb failed. Failed to handle wifi credentials.", ENDUSER_SETUP_ERR_UNKOWN_ERROR, ENDUSER_SETUP_ERR_NONFATAL); + ENDUSER_SETUP_ERROR_VOID("http_recvcb failed. Failed to handle wifi credentials.", ENDUSER_SETUP_ERR_UNKOWN_ERROR, ENDUSER_SETUP_ERR_NONFATAL); break; } - } + } } From 7d02e5a75c25c8b40e5b83d52a6bbaa6dcd09607 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20St=C3=B6r?= Date: Thu, 1 Aug 2019 22:03:09 +0200 Subject: [PATCH 69/74] Change version in title to 3.0 Fixes #2840 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 686c729698..77551bb5dd 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# **NodeMCU 2.2.1** # +# NodeMCU 3.0.0 [![Join the chat at https://gitter.im/nodemcu/nodemcu-firmware](https://img.shields.io/gitter/room/badges/shields.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) From ad9f3bdb567a257c3ba320772314f30645f1da79 Mon Sep 17 00:00:00 2001 From: Nathaniel Wesley Filardo Date: Sun, 4 Aug 2019 11:19:32 +0100 Subject: [PATCH 70/74] Be more assertive in the TLS documentation (#2874) We just don't have the memory to be a real TLS client on the 8266. Put that in a big box and point at it from the http and mqtt modules; others may also wish to give reference. --- docs/modules/http.md | 5 +++- docs/modules/mqtt.md | 5 ++++ docs/modules/tls.md | 70 ++++++++++++++++++++++++++++++++------------ 3 files changed, 60 insertions(+), 20 deletions(-) diff --git a/docs/modules/http.md b/docs/modules/http.md index 4b8f71c81f..2dabc01bc9 100644 --- a/docs/modules/http.md +++ b/docs/modules/http.md @@ -20,7 +20,10 @@ to make it easy to access. If there are multiple headers of the same name, then **SSL/TLS support** -Take note of constraints documented in the [net module](net.md). +!!! attention + + Secure (`https`) connections come with quite a few limitations. Please see + the warnings in the [tls module](tls.md)'s documentation. ## http.delete() diff --git a/docs/modules/mqtt.md b/docs/modules/mqtt.md index bf285a3554..0a01d1bab9 100644 --- a/docs/modules/mqtt.md +++ b/docs/modules/mqtt.md @@ -132,6 +132,11 @@ Connects to the broker specified by the given host, port, and secure options. - `function(client)` callback function for when the connection was established - `function(client, reason)` callback function for when the connection could not be established. No further callbacks should be called. +!!! attention + + Secure (`https`) connections come with quite a few limitations. Please see + the warnings in the [tls module](tls.md)'s documentation. + #### Returns `true` on success, `false` otherwise diff --git a/docs/modules/tls.md b/docs/modules/tls.md index 9fd0a518b9..ebe300b942 100644 --- a/docs/modules/tls.md +++ b/docs/modules/tls.md @@ -20,20 +20,29 @@ most common features supported. Specifically, it provides: - key exchange algorithms: DHE and ECDHE - elliptic curves: secp{256,384}r1, secp256k1, bp{256,384}. -!!! tip - If possible, you will likely be much better served by using the ECDSA - signature and key exchange algorithms than by using RSA. An - increasingly large fraction of the Internet understands ECDSA, and most - server software can speak it as well. The much smaller key size (at - equivalent security!) is beneficial for NodeMCU's limited RAM. - - https://wiki.openssl.org/index.php/Command_Line_Elliptic_Curve_Operations - details how to create ECDSA keys and certificates. +!!! warning -!!! tip - The complete configuration is stored in [user_mbedtls.h](../../app/include/user_mbedtls.h). This is the file to edit if you build your own firmware and want to change mbed TLS behavior. + The severe memory constraints of the ESP8266 mean that the `tls` module + is by far better suited for communication with custom, purpose-built + endpoints with small certificate chains (ideally, even self-signed) + than it is with the Internet at large. By default, our mbedTLS + configuration requests TLS fragments of at most 4KiB and is unwilling + to process fragmented messages, meaning that the entire ServerHello, + which includes the server's certificate chain, must conform to this + limit. We do not believe it useful or easy to be fully compliant with + the TLS specification, which requires a 16KiB recieve buffer and, + therefore, 32KiB of heap within mbedTLS, even in the steady-state. + While it is possible to slightly raise the buffer sizes with custom + nodeMCU builds, connecting to endpoints out of your control will remain + a precarious position, and so we strongly suggest that TLS connections + be made only to endpoints under your control, whose TLS configurations + can ensure that their ServerHello messages are small. A reasonable + compromise is to have a "real" computer do TLS proxying for you; the + [socat](http://www.dest-unreach.org/socat/) program is one possible + mechanism of achieving such a "bent pipe" with TLS on both halves. !!! warning + The TLS glue provided by Espressif provides no interface to TLS SNI. As such, NodeMCU TLS should not be expected to function with endpoints requiring the use of SNI, which is a growing fraction of the Internet @@ -43,15 +52,38 @@ most common features supported. Specifically, it provides: pair. !!! warning + The TLS handshake is very heap intensive, requiring between 25 and 30 - **kilobytes** of heap. Some, but not all, of that is made available - again once the handshake has completed and the connection is open. - Because of this, we have disabled mbedTLS's support for connection - renegotiation. You may find it necessary to restructure your - application so that connections happen early in boot when heap is - relatively plentiful, with connection failures inducing reboots. - -For a list of features have a look at the [mbed TLS features page](https://tls.mbed.org/core-features). + **kilobytes** of heap, even with our reduced buffer sizes. Some, but + not all, of that is made available again once the handshake has + completed and the connection is open. Because of this, we have + disabled mbedTLS's support for connection renegotiation. You may find + it necessary to restructure your application so that connections happen + early in boot when heap is relatively plentiful, with connection + failures inducing reboots. LFS may also be of utility in freeing up + heap space, should you wish to attempt re-establishing connections + without rebooting. + +!!! tip + + If possible, you will likely be much better served by using the ECDSA + signature and key exchange algorithms than by using RSA. An + increasingly large fraction of the Internet understands ECDSA, and most + server software can speak it as well. The much smaller key size (at + equivalent security!) is beneficial for NodeMCU's limited RAM. + + https://wiki.openssl.org/index.php/Command_Line_Elliptic_Curve_Operations + details how to create ECDSA keys and certificates. + +!!! tip + + The complete configuration is stored in + [user_mbedtls.h](../../app/include/user_mbedtls.h). This is the file to + edit if you build your own firmware and want to change mbed TLS + behavior. + + For a list of possible features have a look at the + [mbed TLS features page](https://tls.mbed.org/core-features). This module handles certificate verification when SSL/TLS is in use. From 537c6f99095c139c9658c85670d8fd369c65b9c5 Mon Sep 17 00:00:00 2001 From: Gregor Hartmann Date: Tue, 6 Aug 2019 12:36:50 +0200 Subject: [PATCH 71/74] Re-enabling test-compiling all Lua files during CI (#2877) --- .travis.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.travis.yml b/.travis.yml index e096f9f64b..7994a09736 100644 --- a/.travis.yml +++ b/.travis.yml @@ -29,3 +29,8 @@ script: - if [ "$OS" = "linux" ]; then bash "$TRAVIS_BUILD_DIR"/tools/travis/ci-build-linux.sh; fi - if [ "$OS" = "windows" ]; then bash "$TRAVIS_BUILD_DIR"/tools/travis/ci-build-windows-ms.sh; fi - if [ "$OS" = "linux" -a "$TRAVIS_PULL_REQUEST" != "false" ]; then bash "$TRAVIS_BUILD_DIR"/tools/travis/pr-build.sh; fi +- cd "$TRAVIS_BUILD_DIR" +- echo "checking:" +- find lua_modules lua_examples -iname "*.lua" -print0 | xargs -0 echo +- find lua_modules lua_examples -iname "*.lua" -print0 | xargs -0 $LUACC -p +# - if [ "$OS" = "linux" ]; then bash "$TRAVIS_BUILD_DIR"/tools/travis/run-luacheck.sh || true ; fi From 0b90495517c8e2b34dbb3a2a99455ac3c4f05f1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20St=C3=B6r?= Date: Tue, 6 Aug 2019 23:30:55 +0200 Subject: [PATCH 72/74] Fix node.info() --- docs/modules/node.md | 65 ++++++++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 32 deletions(-) diff --git a/docs/modules/node.md b/docs/modules/node.md index 1db3196483..033a9dc668 100644 --- a/docs/modules/node.md +++ b/docs/modules/node.md @@ -283,43 +283,44 @@ Returns information about hardware, software version and build configuration. `node.info([group])` #### Parameters -`group` group of information (optional, if ommited return legacy information). May be one of `"hw"`, `"sw_version"`, `"build_config"`. +`group` A designator for a group of properties. May be one of `"hw"`, `"sw_version"`, `"build_config"`. It is currently optional; if omitted the legacy structure is returned. However, not providing any value is deprecated. #### Returns - if a `group` is given the return value will be a table containing the following elements: - - for `group` = `"hw"` - - `chip_id` (number) - - `flash_id` (number) - - `flash_size` (number) - - `flash_mode` (number) QIO = 0, QOUT = 1, DIO = 2, DOUT = 15. - - `flash_speed` (number) - - for `group` = `"sw_version"` - - `git_branch` (string) - - `git_commit_id` (string) - - `git_release` (string) Release name +additional commits e.g. "2.0.0-master_20170202 +403" - - `git_commit_dts` (string) in an ordering format. e.g. "201908111200" - - `node_verion_major` (number) - - `node_verion_minor` (number) - - `node_verion_revision` (number) - - for `group` = `"build_config"` - - `ssl` (boolean) - - `lfs_size` (number) as defined at build time - - `modules` (string) comma separated list - - `number_type` (string) `integer` or `float` +If a `group` is given the return value will be a table containing the following elements: + +- for `group` = `"hw"` + - `chip_id` (number) + - `flash_id` (number) + - `flash_size` (number) + - `flash_mode` (number) 0 = QIO, 1 = QOUT, 2 = DIO, 15 = DOUT. + - `flash_speed` (number) +- for `group` = `"sw_version"` + - `git_branch` (string) + - `git_commit_id` (string) + - `git_release` (string) release name +additional commits e.g. "2.0.0-master_20170202 +403" + - `git_commit_dts` (string) commit timestamp in an ordering format. e.g. "201908111200" + - `node_verion_major` (number) + - `node_verion_minor` (number) + - `node_verion_revision` (number) +- for `group` = `"build_config"` + - `ssl` (boolean) + - `lfs_size` (number) as defined at build time + - `modules` (string) comma separated list + - `number_type` (string) `integer` or `float` !!! attention -This interface is deprecated and will be removed in one of the next releases. Use the above calls instead. + Not providing a `group` is deprecated and support for that will be removed in one of the next releases. - - for no `group` given: --deprecated - - `majorVer` (number) - - `minorVer` (number) - - `devVer` (number) - - `chipid` (number) - - `flashid` (number) - - `flashsize` (number) - - `flashmode` (number) - - `flashspeed` (number) +- for `group` = `nil` + - `majorVer` (number) + - `minorVer` (number) + - `devVer` (number) + - `chipid` (number) + - `flashid` (number) + - `flashsize` (number) + - `flashmode` (number) + - `flashspeed` (number) #### Example ```lua @@ -329,7 +330,7 @@ print("NodeMCU "..majorVer.."."..minorVer.."."..devVer) ```lua for k,v in pairs(node.info("build_config")) do -print (k,v) + print (k,v) end ``` From 739b675b72a65659d18c0aed4d8494bb9d3344c2 Mon Sep 17 00:00:00 2001 From: Gregor Hartmann Date: Thu, 15 Aug 2019 12:33:22 +0200 Subject: [PATCH 73/74] add build_date to build info (#2888) --- app/include/user_version.h | 2 +- tools/update_buildinfo.sh | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/include/user_version.h b/app/include/user_version.h index 33817c5c30..ddcd8c66af 100644 --- a/app/include/user_version.h +++ b/app/include/user_version.h @@ -17,7 +17,7 @@ // Can be removed when the script is adapted #ifndef BUILD_DATE -#define BUILD_DATE "unspecified" +#define BUILD_DATE BUILDINFO_BUILD_DATE #endif extern char SDK_VERSION[]; diff --git a/tools/update_buildinfo.sh b/tools/update_buildinfo.sh index 99a376f993..66370a90d3 100755 --- a/tools/update_buildinfo.sh +++ b/tools/update_buildinfo.sh @@ -6,6 +6,7 @@ COMMIT_ID="$(git rev-parse HEAD)" BRANCH="$(git rev-parse --abbrev-ref HEAD | sed -E 's/[\/\\]+/_/g')" RELEASE="$(git describe --tags --long | sed -E 's/(.*)-(.*)-.*/\1 +\2/g' | sed 's/ +0$//')" RELEASE_DTS=$(TZ=UTC git show --quiet --date=format-local:"%Y%m%d%H%M" --format="%cd" HEAD) +BUILD_DATE="$(date "+%Y-%m-%d %H:%M")" MODULES=$(awk '/^[ \t]*#define LUA_USE_MODULES/{modules=modules sep tolower(substr($2,17));sep=","}END{if(length(modules)==0)modules="-";print modules}' $USER_MODULES_H | tr -d '\r') @@ -46,6 +47,7 @@ cat > $TEMPFILE << EndOfMessage #define BUILDINFO_RELEASE "$RELEASE" #define BUILDINFO_RELEASE_DTS "$RELEASE_DTS" #define BUILDINFO_MODULES "$MODULES" +#define BUILDINFO_BUILD_DATE "$BUILD_DATE" #define NODE_VERSION_LONG \\ USER_PROLOG "\n" \\ From a08e74d9ade5392c3378846d51be1c4211b089be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20St=C3=B6r?= Date: Tue, 27 Aug 2019 22:13:17 +0200 Subject: [PATCH 74/74] Complement list of missing standard Lua modules --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 77551bb5dd..f3f4506b68 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ The firmware was initially developed as is a companion project to the popular ES # Summary - Easy to program wireless node and/or access point -- Based on Lua 5.1.4 (without `debug` & `os` modules) +- Based on Lua 5.1.4 but without `debug`, `io`, `os` and (most of the) `math` modules - Asynchronous event-driven programming model - more than **65 built-in modules** - Firmware available with or without floating point support (integer-only uses less memory)