Merge remote-tracking branch 'origin/dev-esp32-idf4' into usbcdc-only
This commit is contained in:
commit
dcab2d195f
|
@ -23,6 +23,7 @@ set(module_srcs
|
||||||
"otaupgrade.c"
|
"otaupgrade.c"
|
||||||
"ow.c"
|
"ow.c"
|
||||||
"pipe.c"
|
"pipe.c"
|
||||||
|
"rtcmem.c"
|
||||||
"qrcodegen.c"
|
"qrcodegen.c"
|
||||||
"sigma_delta.c"
|
"sigma_delta.c"
|
||||||
"sjson.c"
|
"sjson.c"
|
||||||
|
@ -58,12 +59,17 @@ if(IDF_TARGET STREQUAL "esp32")
|
||||||
elseif(IDF_TARGET STREQUAL "esp32s2")
|
elseif(IDF_TARGET STREQUAL "esp32s2")
|
||||||
list(APPEND module_srcs
|
list(APPEND module_srcs
|
||||||
"dac.c"
|
"dac.c"
|
||||||
|
"rmt.c"
|
||||||
|
"pulsecnt.c"
|
||||||
)
|
)
|
||||||
elseif(IDF_TARGET STREQUAL "esp32s3")
|
elseif(IDF_TARGET STREQUAL "esp32s3")
|
||||||
list(APPEND module_srcs
|
list(APPEND module_srcs
|
||||||
|
"rmt.c"
|
||||||
|
"pulsecnt.c"
|
||||||
)
|
)
|
||||||
elseif(IDF_TARGET STREQUAL "esp32c3")
|
elseif(IDF_TARGET STREQUAL "esp32c3")
|
||||||
list(APPEND module_srcs
|
list(APPEND module_srcs
|
||||||
|
"rmt.c"
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|
|
@ -225,6 +225,13 @@ menu "NodeMCU modules"
|
||||||
Includes the rmt module to use the ESP32's built-in
|
Includes the rmt module to use the ESP32's built-in
|
||||||
remote control hardware.
|
remote control hardware.
|
||||||
|
|
||||||
|
config NODEMCU_CMODULE_RTCMEM
|
||||||
|
bool "Access to a limited amount of battery backed memory (rtcmem)"
|
||||||
|
default "n"
|
||||||
|
help
|
||||||
|
Includes the rtcmem module to allow access to
|
||||||
|
the battery backed memory.
|
||||||
|
|
||||||
config NODEMCU_CMODULE_SDMMC
|
config NODEMCU_CMODULE_SDMMC
|
||||||
depends on IDF_TARGET_ESP32
|
depends on IDF_TARGET_ESP32
|
||||||
bool "SD-MMC module"
|
bool "SD-MMC module"
|
||||||
|
|
|
@ -0,0 +1,52 @@
|
||||||
|
// Module for RTC user memory access
|
||||||
|
|
||||||
|
#include "module.h"
|
||||||
|
#include "lauxlib.h"
|
||||||
|
#include "esp_attr.h"
|
||||||
|
|
||||||
|
#define RTC_USER_MEM_NUM_DWORDS 128
|
||||||
|
|
||||||
|
RTC_NOINIT_ATTR uint32_t rtc_memory[RTC_USER_MEM_NUM_DWORDS];
|
||||||
|
|
||||||
|
static int rtcmem_read32 (lua_State *L)
|
||||||
|
{
|
||||||
|
int idx = luaL_checkinteger (L, 1);
|
||||||
|
int n = (lua_gettop(L) < 2) ? 1 : lua_tointeger (L, 2);
|
||||||
|
if (n == 0 || !lua_checkstack (L, n)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ret = 0;
|
||||||
|
while (n > 0 && idx >= 0 && idx < RTC_USER_MEM_NUM_DWORDS)
|
||||||
|
{
|
||||||
|
lua_pushinteger (L, rtc_memory[idx++]);
|
||||||
|
--n;
|
||||||
|
++ret;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int rtcmem_write32 (lua_State *L)
|
||||||
|
{
|
||||||
|
int idx = luaL_checkinteger (L, 1);
|
||||||
|
int n = lua_gettop (L) - 1;
|
||||||
|
luaL_argcheck (
|
||||||
|
L, idx + n <= RTC_USER_MEM_NUM_DWORDS, 1, "RTC mem would overrun");
|
||||||
|
int src = 2;
|
||||||
|
while (n-- > 0)
|
||||||
|
{
|
||||||
|
rtc_memory[idx++] = (uint32_t) lua_tointeger(L, src++);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Module function map
|
||||||
|
LROT_BEGIN(rtcmem, NULL, 0)
|
||||||
|
LROT_FUNCENTRY( read32, rtcmem_read32 )
|
||||||
|
LROT_FUNCENTRY( write32, rtcmem_write32 )
|
||||||
|
LROT_END(rtcmem, NULL, 0)
|
||||||
|
|
||||||
|
|
||||||
|
NODEMCU_MODULE(RTCMEM, "rtcmem", rtcmem, NULL);
|
|
@ -10,6 +10,10 @@
|
||||||
|
|
||||||
static lua_State *gL = NULL;
|
static lua_State *gL = NULL;
|
||||||
|
|
||||||
|
bool uart_has_on_data_cb(unsigned id){
|
||||||
|
return uart_status[id].receive_rf != LUA_NOREF;
|
||||||
|
}
|
||||||
|
|
||||||
bool uart_on_data_cb(unsigned id, const char *buf, size_t len){
|
bool uart_on_data_cb(unsigned id, const char *buf, size_t len){
|
||||||
if(!buf || len==0)
|
if(!buf || len==0)
|
||||||
return false;
|
return false;
|
||||||
|
@ -128,23 +132,24 @@ static int uart_on( lua_State* L )
|
||||||
// Lua: actualbaud = setup( id, baud, databits, parity, stopbits, echo )
|
// Lua: actualbaud = setup( id, baud, databits, parity, stopbits, echo )
|
||||||
static int uart_setup( lua_State* L )
|
static int uart_setup( lua_State* L )
|
||||||
{
|
{
|
||||||
unsigned id, databits, parity, stopbits, echo = 1;
|
unsigned id, databits, parity, stopbits;
|
||||||
uint32_t baud, res;
|
uint32_t baud, res;
|
||||||
uart_pins_t pins;
|
uart_pins_t pins;
|
||||||
|
uart_pins_t* pins_to_use = NULL;
|
||||||
|
|
||||||
|
memset(&pins, 0, sizeof(pins));
|
||||||
id = luaL_checkinteger( L, 1 );
|
id = luaL_checkinteger( L, 1 );
|
||||||
MOD_CHECK_ID( uart, id );
|
MOD_CHECK_ID( uart, id );
|
||||||
baud = luaL_checkinteger( L, 2 );
|
baud = luaL_checkinteger( L, 2 );
|
||||||
databits = luaL_checkinteger( L, 3 );
|
databits = luaL_checkinteger( L, 3 );
|
||||||
parity = luaL_checkinteger( L, 4 );
|
parity = luaL_checkinteger( L, 4 );
|
||||||
stopbits = luaL_checkinteger( L, 5 );
|
stopbits = luaL_checkinteger( L, 5 );
|
||||||
if(id == CONFIG_ESP_CONSOLE_UART_NUM && lua_isnumber(L,6)){
|
if (!lua_isnoneornil(L, 6)) {
|
||||||
echo = lua_tointeger(L,6);
|
if(id == CONFIG_ESP_CONSOLE_UART_NUM){
|
||||||
if(echo!=0)
|
input_echo = luaL_checkinteger(L, 6) > 0;
|
||||||
input_echo = true;
|
} else {
|
||||||
else
|
luaL_checktable(L, 6);
|
||||||
input_echo = false;
|
|
||||||
} else if(id != CONFIG_ESP_CONSOLE_UART_NUM && lua_istable( L, 6 )) {
|
|
||||||
lua_getfield (L, 6, "tx");
|
lua_getfield (L, 6, "tx");
|
||||||
pins.tx_pin = luaL_checkint(L, -1);
|
pins.tx_pin = luaL_checkint(L, -1);
|
||||||
lua_getfield (L, 6, "rx");
|
lua_getfield (L, 6, "rx");
|
||||||
|
@ -165,9 +170,12 @@ static int uart_setup( lua_State* L )
|
||||||
|
|
||||||
lua_getfield (L, 6, "flow_control");
|
lua_getfield (L, 6, "flow_control");
|
||||||
pins.flow_control = luaL_optint(L, -1, PLATFORM_UART_FLOW_NONE);
|
pins.flow_control = luaL_optint(L, -1, PLATFORM_UART_FLOW_NONE);
|
||||||
|
|
||||||
|
pins_to_use = &pins;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
res = platform_uart_setup( id, baud, databits, parity, stopbits, &pins );
|
res = platform_uart_setup( id, baud, databits, parity, stopbits, pins_to_use );
|
||||||
lua_pushinteger( L, res );
|
lua_pushinteger( L, res );
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,6 +40,7 @@
|
||||||
#include "nodemcu_esp_event.h"
|
#include "nodemcu_esp_event.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "esp_netif.h"
|
#include "esp_netif.h"
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
static esp_netif_t *wifi_sta = NULL;
|
static esp_netif_t *wifi_sta = NULL;
|
||||||
static int scan_cb_ref = LUA_NOREF;
|
static int scan_cb_ref = LUA_NOREF;
|
||||||
|
@ -207,6 +208,20 @@ static int wifi_sta_setip(lua_State *L)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int wifi_sta_settxpower(lua_State *L)
|
||||||
|
{
|
||||||
|
lua_Number max_power = luaL_checknumber(L, 1);
|
||||||
|
|
||||||
|
esp_err_t err = esp_wifi_set_max_tx_power(floor(max_power * 4 + 0.5));
|
||||||
|
|
||||||
|
if (err != ESP_OK)
|
||||||
|
return luaL_error(L, "failed to set transmit power, code %d", err);
|
||||||
|
|
||||||
|
lua_pushboolean(L, err == ESP_OK);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
static int wifi_sta_sethostname(lua_State *L)
|
static int wifi_sta_sethostname(lua_State *L)
|
||||||
{
|
{
|
||||||
size_t l;
|
size_t l;
|
||||||
|
@ -441,6 +456,7 @@ static int wifi_sta_scan (lua_State *L)
|
||||||
LROT_BEGIN(wifi_sta, NULL, 0)
|
LROT_BEGIN(wifi_sta, NULL, 0)
|
||||||
LROT_FUNCENTRY( setip, wifi_sta_setip )
|
LROT_FUNCENTRY( setip, wifi_sta_setip )
|
||||||
LROT_FUNCENTRY( sethostname, wifi_sta_sethostname)
|
LROT_FUNCENTRY( sethostname, wifi_sta_sethostname)
|
||||||
|
LROT_FUNCENTRY( settxpower, wifi_sta_settxpower)
|
||||||
LROT_FUNCENTRY( config, wifi_sta_config)
|
LROT_FUNCENTRY( config, wifi_sta_config)
|
||||||
LROT_FUNCENTRY( connect, wifi_sta_connect )
|
LROT_FUNCENTRY( connect, wifi_sta_connect )
|
||||||
LROT_FUNCENTRY( disconnect, wifi_sta_disconnect )
|
LROT_FUNCENTRY( disconnect, wifi_sta_disconnect )
|
||||||
|
|
|
@ -89,16 +89,22 @@ static uart_status_t usbcdc_status;
|
||||||
SemaphoreHandle_t usbcdc_sem = NULL;
|
SemaphoreHandle_t usbcdc_sem = NULL;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
extern bool uart_has_on_data_cb(unsigned id);
|
||||||
extern bool uart_on_data_cb(unsigned id, const char *buf, size_t len);
|
extern bool uart_on_data_cb(unsigned id, const char *buf, size_t len);
|
||||||
extern bool uart_on_error_cb(unsigned id, const char *buf, size_t len);
|
extern bool uart_on_error_cb(unsigned id, const char *buf, size_t len);
|
||||||
|
|
||||||
static void handle_uart_data(unsigned int id, uart_event_post_t *post, uart_status_t *us) {
|
static void handle_uart_data(unsigned int id, uart_event_post_t *post, uart_status_t *us) {
|
||||||
|
if (id == CONFIG_ESP_CONSOLE_UART_NUM && run_input) {
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
while (i < post->size) {
|
while (i < post->size) {
|
||||||
if (id == CONFIG_ESP_CONSOLE_UART_NUM && run_input) {
|
|
||||||
unsigned used = feed_lua_input(post->data + i, post->size - i);
|
unsigned used = feed_lua_input(post->data + i, post->size - i);
|
||||||
i += used;
|
i += used;
|
||||||
} else {
|
}
|
||||||
|
}
|
||||||
|
if (uart_has_on_data_cb(id)) {
|
||||||
|
size_t i = 0;
|
||||||
|
while (i < post->size)
|
||||||
|
{
|
||||||
char ch = post->data[i];
|
char ch = post->data[i];
|
||||||
us->line_buffer[us->line_position] = ch;
|
us->line_buffer[us->line_position] = ch;
|
||||||
us->line_position++;
|
us->line_position++;
|
||||||
|
@ -292,8 +298,10 @@ uint32_t platform_uart_setup( unsigned id, uint32_t baud, int databits, int pari
|
||||||
{
|
{
|
||||||
ADJUST_IDR(id, baud);
|
ADJUST_IDR(id, baud);
|
||||||
int flow_control = UART_HW_FLOWCTRL_DISABLE;
|
int flow_control = UART_HW_FLOWCTRL_DISABLE;
|
||||||
|
if (pins != NULL) {
|
||||||
if(pins->flow_control & PLATFORM_UART_FLOW_CTS) flow_control |= UART_HW_FLOWCTRL_CTS;
|
if(pins->flow_control & PLATFORM_UART_FLOW_CTS) flow_control |= UART_HW_FLOWCTRL_CTS;
|
||||||
if(pins->flow_control & PLATFORM_UART_FLOW_RTS) flow_control |= UART_HW_FLOWCTRL_RTS;
|
if(pins->flow_control & PLATFORM_UART_FLOW_RTS) flow_control |= UART_HW_FLOWCTRL_RTS;
|
||||||
|
}
|
||||||
|
|
||||||
uart_config_t cfg = {
|
uart_config_t cfg = {
|
||||||
.baud_rate = baud,
|
.baud_rate = baud,
|
||||||
|
|
|
@ -0,0 +1,66 @@
|
||||||
|
# RTC User Memory Module
|
||||||
|
| Since | Origin / Contributor | Maintainer | Source |
|
||||||
|
| :----- | :-------------------- | :---------- | :------ |
|
||||||
|
| 2015-06-25 | [DiUS](https://github.com/DiUS), [Johny Mattsson](https://github.com/jmattsson) | [PJSG](https://github.com/pjsg) | [rtcmem.c](../../app/modules/rtcmem.c)|
|
||||||
|
|
||||||
|
The rtcmem module provides basic access to the RTC memory.
|
||||||
|
|
||||||
|
This memory is preserved while power is applied, making them highly useful for keeping state across sleep cycles. Some of this memory is reserved for system use,
|
||||||
|
and, for compatibility with NodeMCU on the ESP8266, 128 slots (each 32bit wide) of RTC memory are reserved by this module.
|
||||||
|
This module then provides read and write access to these slots.
|
||||||
|
|
||||||
|
This module is 100% compatible with the ESP8266 version, and this means that, there is no mechanism for arbitrating use of particular slots. It is up to the end user to be aware of which memory is used for what, and avoid conflicts. Unlike the ESP8266 version, no other NodeMCU module uses any of these slots.
|
||||||
|
|
||||||
|
Note that this memory is not necessary preserved across reflashing the firmware. It is the responsibility of the
|
||||||
|
developer to deal with getting inconsistent data.
|
||||||
|
|
||||||
|
## rtcmem.read32()
|
||||||
|
|
||||||
|
Reads one or more 32bit values from RTC user memory.
|
||||||
|
|
||||||
|
#### Syntax
|
||||||
|
`rtcmem.read32(idx [, num])`
|
||||||
|
|
||||||
|
#### Parameters
|
||||||
|
- `idx` zero-based index to start reading from
|
||||||
|
- `num` number of slots to read (default 1)
|
||||||
|
|
||||||
|
#### Returns
|
||||||
|
The value(s) read from RTC user memory.
|
||||||
|
|
||||||
|
If `idx` is outside the valid range [0,127] this function returns nothing.
|
||||||
|
|
||||||
|
If `num` results in overstepping the end of available memory, the function only returns the data from the valid slots.
|
||||||
|
|
||||||
|
#### Example
|
||||||
|
```lua
|
||||||
|
val = rtcmem.read32(0) -- Read the value in slot 0
|
||||||
|
val1, val2 = rtcmem.read32(42, 2) -- Read the values in slots 42 and 43
|
||||||
|
```
|
||||||
|
#### See also
|
||||||
|
[`rtcmem.write32()`](#rtcmemwrite32)
|
||||||
|
|
||||||
|
## rtcmem.write32()
|
||||||
|
|
||||||
|
Writes one or more values to RTC user memory, starting at index `idx`.
|
||||||
|
|
||||||
|
Writing to indices outside the valid range [0,127] has no effect.
|
||||||
|
|
||||||
|
#### Syntax
|
||||||
|
`rtcmem.write32(idx, val [, val2, ...])`
|
||||||
|
|
||||||
|
#### Parameters
|
||||||
|
- `idx` zero-based index to start writing to. Auto-increments if multiple values are given.
|
||||||
|
- `val` value to store (32bit)
|
||||||
|
- `val2...` additional values to store (optional)
|
||||||
|
|
||||||
|
#### Returns
|
||||||
|
`nil`
|
||||||
|
|
||||||
|
#### Example
|
||||||
|
```lua
|
||||||
|
rtcmem.write32(0, 53) -- Store the value 53 in slot 0
|
||||||
|
rtcmem.write32(42, 2, 5, 7) -- Store the values 2, 5 and 7 into slots 42, 43 and 44, respectively.
|
||||||
|
```
|
||||||
|
#### See also
|
||||||
|
[`rtcmem.read32()`](#rtcmemread32)
|
|
@ -233,6 +233,27 @@ Disconnects from AP in station mode.
|
||||||
- [`wifi.sta.connect()`](#wifistaconnect)
|
- [`wifi.sta.connect()`](#wifistaconnect)
|
||||||
|
|
||||||
|
|
||||||
|
## wifi.sta.settxpower
|
||||||
|
|
||||||
|
Allows adjusting the maximum TX power for the WiFi. This is (unfortunately) needed for some boards which
|
||||||
|
have a badly matched antenna.
|
||||||
|
|
||||||
|
#### Syntax
|
||||||
|
`wifi.sta.settxpower(power)`
|
||||||
|
|
||||||
|
#### Parameters
|
||||||
|
- `power` The maximum transmit power in dBm. This must have the range 2dBm - 20dBm. This value is a float.
|
||||||
|
|
||||||
|
#### Returns
|
||||||
|
A `boolean` where `true` is OK.
|
||||||
|
|
||||||
|
#### Example
|
||||||
|
|
||||||
|
```
|
||||||
|
# Needed for the WEMOS C3 Mini
|
||||||
|
wifi.sta.settxpower(8.5)
|
||||||
|
```
|
||||||
|
|
||||||
## wifi.sta.on()
|
## wifi.sta.on()
|
||||||
|
|
||||||
Registers callbacks for WiFi station status events.
|
Registers callbacks for WiFi station status events.
|
||||||
|
|
Loading…
Reference in New Issue