Successfully boot barebones NodeMCU on ESP32 (only).

RTOS driver evicted as it did not play nice with stdio etc.

Implemented a minimal driver to fully support Lua console on UART0. Output
on UART0 done via stdout (provided by the IDF). Input and setup handled
via driver_console/console.c. In addition to the direct input function
console_getc(), the driver also registers in the syscall tables to enable
regular stdio input functions to work (yay!). The Lua VM is still using the
direct interface since it's less overhead, but does also work when going
through stdin/fd 0.

Auto-bauding on the console is not yet functional; revisit when the UART docs
are available.

Module registration/linking/enabling moved over to be Kconfig based. See
updates to base_nodemcu/include/module.h and base_nodemcu/Kconfig for
details.

The sdk-overrides directory/approach is no longer used. The IDF is simply
too different to the old RTOS SDK - we need to adapt our code directly instead.

Everything in app/ is now unused, and will need to be gradually migrated
into components/ though it is probably better to migrate straight from the
latest dev branch.
This commit is contained in:
Johny Mattsson 2016-09-20 13:35:56 +10:00
parent a463d764eb
commit 9bbf8f43fb
46 changed files with 401 additions and 1252 deletions

View File

@ -14,23 +14,17 @@ else
PROJECT_NAME:=NodeMCU
COMPONENTS:=bootloader bt esp32 esptool_py expat freertos json lwip mbedtls newlib nvs_flash partition_table spi_flash tcpip_adapter test task platform spiffs driver_uart
# This is, sadly, the cleanest way to resolve the different non-standard
# conventions for sized integers across the various components.
BASIC_TYPES=-Du32_t=uint32_t -Du16_t=uint16_t -Du8_t=uint8_t -Ds32_t=int32_t -Ds16_t=int16_t -Duint32=uint32_t -Duint16=uint16_t -Duint8=uint8_t -Dsint32=int32_t -Dsint16=int16_t -Dsint8=int8_t
include $(IDF_PATH)/make/project.mk
# SDK/IDF include overrides
INCLUDE_OVERRIDES=\
$(addprefix -I $(PROJECT_PATH)/sdk-overrides/,include esp32-include)
LUA_LTR_DEFINES=\
-DLUA_OPTIMIZE_MEMORY=2 \
-DMIN_OPT_LEVEL=2 \
# Ensure these overrides are always used
CC:=$(CC) $(BASIC_TYPES) $(INCLUDE_OVERRIDES) $(LUA_LTR_DEFINES) -D__ESP32__
CC:=$(CC) $(BASIC_TYPES) $(LUA_LTR_DEFINES) -D__ESP32__
endif

View File

@ -1,259 +0,0 @@
# copyright (c) 2010 Espressif System
# 2015-2016 NodeMCU team
#
.NOTPARALLEL:
# Get rid of most of the implicit rules by clearing the .SUFFIXES target
.SUFFIXES:
# Get rid of the auto-checkout from old version control systems rules
%: %,v
%: RCS/%,v
%: RCS/%
%: s.%
%: SCCS/s.%
# Set up flags and paths based on hardware target
HW?=ESP8266
ifeq ($(HW),ESP8266)
TARGET=esp8266
TARGET_SDK_LIBS=espconn cirom mirom nopoll
TARGET_LDFLAGS=-u _UserExceptionVectorOverride -Wl,--wrap=printf
LD_FILE=$(LDDIR)/nodemcu.ld
AR = xtensa-lx106-elf-ar
CC = xtensa-lx106-elf-gcc
NM = xtensa-lx106-elf-nm
CPP = xtensa-lx106-elf-cpp
OBJCOPY = xtensa-lx106-elf-objcopy
else ifeq ($(HW),ESP32)
TARGET=esp32
TARGET_SDK_LIBS=rtc c m driver
TARGET_LDFLAGS=
LD_FILE=$(LDDIR)/nodemcu32.ld
AR = xtensa-esp32-elf-ar
CC = xtensa-esp32-elf-gcc
NM = xtensa-esp32-elf-nm
CPP = xtensa-esp32-elf-cpp
OBJCOPY = xtensa-esp32-elf-objcopy
else
$(error Unsupported hardware platform: $(HW))
endif
# Ensure we search "our" SDK before the tool-chain's SDK (if any)
TOP_DIR:=$(abspath $(dir $(lastword $(MAKEFILE_LIST))))
SDKDIR:=$(TOP_DIR)/sdk/$(TARGET)-rtos-sdk
# This is, sadly, the cleanest way to resolve the different non-standard
# conventions for sized integers across the various components.
BASIC_TYPES=-Du32_t=uint32_t -Du16_t=uint16_t -Du8_t=uint8_t -Ds32_t=int32_t -Ds16_t=int16_t -Duint32=uint32_t -Duint16=uint16_t -Duint8=uint8_t -Dsint32=int32_t -Dsint16=int16_t -Dsint8=int8_t
# Include dirs, ensure the overrides come first
INCLUDE_DIRS=\
$(TOP_DIR)/sdk-overrides/include \
$(TOP_DIR)/sdk-overrides/$(TARGET)-include \
$(SDKDIR)/include \
$(SDKDIR)/include/espressif \
$(SDKDIR)/include/espressif/$(TARGET) \
$(SDKDIR)/include/$(TARGET) \
$(SDKDIR)/include/$(TARGET)/uart \
$(SDKDIR)/include/lwip \
$(SDKDIR)/include/lwip/ipv4 \
$(SDKDIR)/include/lwip/ipv6 \
$(SDKDIR)/extra_include \
$(SDKDIR)/third_party/include \
$(SDKDIR)/third_party/include/lwip \
$(SDKDIR)/third_party/include/lwip/ipv4 \
$(SDKDIR)/third_party/include/lwip/ipv6 \
$(SDKDIR)/driver_lib/include \
# ... and we have to mark them all as system include dirs rather than the usual
# -I for user include dir, or the esp-open-sdk toolchain headers wreak havoc
CCFLAGS:=$(addprefix -isystem,$(INCLUDE_DIRS)) $(BASIC_TYPES) -D__$(HW)__
LDFLAGS:= -L$(SDKDIR)/lib -L$(SDKDIR)/ld $(LDFLAGS)
#############################################################
ifndef COMPORT
ESPPORT = /dev/ttyUSB0
else
ESPPORT = $(COMPORT)
endif
CCFLAGS += -Os -ffunction-sections -fno-jump-tables -fdata-sections
FIRMWAREDIR = ../bin/$(TARGET)/
#############################################################
ESPTOOL ?= ../tools/esptool.py
CSRCS ?= $(wildcard *.c)
ASRCs ?= $(wildcard *.s)
ASRCS ?= $(wildcard *.S)
SUBDIRS ?= $(patsubst %/,%,$(dir $(wildcard */Makefile)))
ODIR := .output
OBJODIR := $(ODIR)/$(TARGET)/$(FLAVOR)/obj
OBJS := $(CSRCS:%.c=$(OBJODIR)/%.o) \
$(ASRCs:%.s=$(OBJODIR)/%.o) \
$(ASRCS:%.S=$(OBJODIR)/%.o)
DEPS := $(CSRCS:%.c=$(OBJODIR)/%.d) \
$(ASRCs:%.s=$(OBJODIR)/%.d) \
$(ASRCS:%.S=$(OBJODIR)/%.d)
LIBODIR := $(ODIR)/$(TARGET)/$(FLAVOR)/lib
OLIBS := $(GEN_LIBS:%=$(LIBODIR)/%)
IMAGEODIR := $(ODIR)/$(TARGET)/$(FLAVOR)/image
OIMAGES := $(GEN_IMAGES:%=$(IMAGEODIR)/%)
BINODIR := $(ODIR)/$(TARGET)/$(FLAVOR)/bin
OBINS := $(GEN_BINS:%=$(BINODIR)/%)
#
# 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
#
CCFLAGS += \
-g \
-Wpointer-arith \
-Wundef \
-Werror \
-Wl,-EL \
-fno-inline-functions \
-nostdlib \
-mlongcalls \
-mtext-section-literals
# -Wall
CFLAGS = $(CCFLAGS) $(DEFINES) $(EXTRA_CCFLAGS) $(STD_CFLAGS) $(INCLUDES)
DFLAGS = $(CCFLAGS) $(DDEFINES) $(EXTRA_CCFLAGS) $(STD_CFLAGS) $(INCLUDES)
#############################################################
# Functions
#
define ShortcutRule
$(1): .subdirs $(2)/$(1)
endef
define MakeLibrary
DEP_LIBS_$(1) = $$(foreach lib,$$(filter %.a,$$(COMPONENTS_$(1))),$$(dir $$(lib))$$(LIBODIR)/$$(notdir $$(lib)))
DEP_OBJS_$(1) = $$(foreach obj,$$(filter %.o,$$(COMPONENTS_$(1))),$$(dir $$(obj))$$(OBJODIR)/$$(notdir $$(obj)))
$$(LIBODIR)/$(1).a: $$(OBJS) $$(DEP_OBJS_$(1)) $$(DEP_LIBS_$(1)) $$(DEPENDS_$(1))
@mkdir -p $$(LIBODIR)
$$(if $$(filter %.a,$$?),mkdir -p $$(EXTRACT_DIR)_$(1))
$$(if $$(filter %.a,$$?),cd $$(EXTRACT_DIR)_$(1); $$(foreach lib,$$(filter %.a,$$?),$$(AR) xo $$(UP_EXTRACT_DIR)/$$(lib);))
$$(AR) ru $$@ $$(filter %.o,$$?) $$(if $$(filter %.a,$$?),$$(EXTRACT_DIR)_$(1)/*.o)
$$(if $$(filter %.a,$$?),$$(RM) -r $$(EXTRACT_DIR)_$(1))
endef
define MakeImage
DEP_LIBS_$(1) = $$(foreach lib,$$(filter %.a,$$(COMPONENTS_$(1))),$$(dir $$(lib))$$(LIBODIR)/$$(notdir $$(lib)))
DEP_OBJS_$(1) = $$(foreach obj,$$(filter %.o,$$(COMPONENTS_$(1))),$$(dir $$(obj))$$(OBJODIR)/$$(notdir $$(obj)))
$$(IMAGEODIR)/$(1).out: $$(OBJS) $$(DEP_OBJS_$(1)) $$(DEP_LIBS_$(1)) $$(DEPENDS_$(1))
@mkdir -p $$(IMAGEODIR)
$$(CC) $$(LDFLAGS) $$(if $$(LINKFLAGS_$(1)),$$(LINKFLAGS_$(1)),$$(LINKFLAGS_DEFAULT) $$(OBJS) $$(DEP_OBJS_$(1)) $$(DEP_LIBS_$(1))) -o $$@
endef
$(BINODIR)/%.bin: $(IMAGEODIR)/%.out
@mkdir -p $(BINODIR) $(FIRMWAREDIR)
ifeq ($(HW),ESP8266)
$(ESPTOOL) elf2image $< -o $(FIRMWAREDIR)
else ifeq ($(HW),ESP32)
@rm -f $(FIRMWAREDIR)/*
@$(OBJCOPY) --only-section .text -O binary $< eagle.app.v7.text.bin
@$(OBJCOPY) --only-section .data -O binary $< eagle.app.v7.data.bin
@$(OBJCOPY) --only-section .rodata -O binary $< eagle.app.v7.rodata.bin
@$(OBJCOPY) --only-section .irom0.text -O binary $< eagle.app.v7.irom0text.bin
@$(OBJCOPY) --only-section .drom0.text -O binary $< eagle.app.v7.drom0text.bin
@python $(SDKDIR)/tools/gen_appbin.py $< $(LD_FILE) 0 0 unused_app_cpu.bin $(FIRMWAREDIR)
@rm -f eagle.app.v7.*.bin
endif
#############################################################
# Rules base
# Should be done in top-level makefile only
#
all:pre_build .subdirs $(OBJS) $(OLIBS) $(OIMAGES) $(OBINS) $(SPECIAL_MKTARGETS)
clean:
$(foreach d, $(SUBDIRS), $(MAKE) -C $(d) clean;)
$(RM) -r $(ODIR)/$(TARGET)/$(FLAVOR)
clobber: $(SPECIAL_CLOBBER)
$(foreach d, $(SUBDIRS), $(MAKE) -C $(d) clobber;)
$(RM) -r $(ODIR)
.subdirs:
@set -e; $(foreach d, $(SUBDIRS), $(MAKE) -C $(d);)
ifneq ($(MAKECMDGOALS),clean)
ifneq ($(MAKECMDGOALS),clobber)
ifdef DEPS
sinclude $(DEPS)
endif
endif
endif
.PHONY: pre_build
ifneq ($(wildcard $(TOP_DIR)/server-ca.crt),)
pre_build:
python $(TOP_DIR)/tools/make_server_cert.py $(TOP_DIR)/server-ca.crt > $(TOP_DIR)/app/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
endif
$(OBJODIR)/%.o: %.c
@mkdir -p $(OBJODIR);
$(CC) $(if $(findstring $<,$(DSRCS)),$(DFLAGS),$(CFLAGS)) $(COPTS_$(*F)) -o $@ -c $<
$(OBJODIR)/%.d: %.c
@mkdir -p $(OBJODIR);
@echo DEPEND: $(CC) -M $(CFLAGS) $<
@set -e; rm -f $@; \
$(CC) -M $(CFLAGS) $< > $@.$$$$; \
sed 's,\($*\.o\)[ :]*,$(OBJODIR)/\1 $@ : ,g' < $@.$$$$ > $@; \
rm -f $@.$$$$
$(OBJODIR)/%.o: %.s
@mkdir -p $(OBJODIR);
$(CC) $(CFLAGS) -o $@ -c $<
$(OBJODIR)/%.d: %.s
@mkdir -p $(OBJODIR); \
set -e; rm -f $@; \
$(CC) -M $(CFLAGS) $< > $@.$$$$; \
sed 's,\($*\.o\)[ :]*,$(OBJODIR)/\1 $@ : ,g' < $@.$$$$ > $@; \
rm -f $@.$$$$
$(OBJODIR)/%.o: %.S
@mkdir -p $(OBJODIR);
$(CC) $(CFLAGS) -D__ASSEMBLER__ -o $@ -c $<
$(OBJODIR)/%.d: %.S
@mkdir -p $(OBJODIR); \
set -e; rm -f $@; \
$(CC) -M $(CFLAGS) $< > $@.$$$$; \
sed 's,\($*\.o\)[ :]*,$(OBJODIR)/\1 $@ : ,g' < $@.$$$$ > $@; \
rm -f $@.$$$$
$(foreach lib,$(GEN_LIBS),$(eval $(call ShortcutRule,$(lib),$(LIBODIR))))
$(foreach image,$(GEN_IMAGES),$(eval $(call ShortcutRule,$(image),$(IMAGEODIR))))
$(foreach bin,$(GEN_BINS),$(eval $(call ShortcutRule,$(bin),$(BINODIR))))
$(foreach lib,$(GEN_LIBS),$(eval $(call MakeLibrary,$(basename $(lib)))))
$(foreach image,$(GEN_IMAGES),$(eval $(call MakeImage,$(basename $(image)))))

View File

@ -1,6 +1,3 @@
//#include "user_interface.h"
#include "user_config.h"
#ifdef LUA_CROSS_COMPILER
#include <stdlib.h>

View File

@ -0,0 +1,6 @@
COMPONENT_ADD_INCLUDEDIRS:=include
# Note: It appears this component must come lexicographically before esp32
# in order to get the -T arguments in the right order.
COMPONENT_ADD_LDFLAGS:=-L $(abspath ld) -T nodemcu_core.ld -lbase_nodemcu
include $(IDF_PATH)/make/component_common.mk

View File

@ -0,0 +1,7 @@
#ifndef _SDK_OVERRIDES_STDLIB_H_
#define _SDK_OVERRIDES_STDLIB_H_
extern const char *c_getenv (const char *);
extern double c_strtod(const char *string, char **endPtr);
#endif

View File

@ -2,6 +2,7 @@
#define __MODULE_H__
#include "lrodefs.h"
#include "sdkconfig.h"
/* Registering a module within NodeMCU is really easy these days!
*
@ -25,11 +26,9 @@
*
* if you don't need an init function.
*
* When you've done this, the module can be enabled in user_modules.h with:
*
* #define LUA_USE_MODULES_MYNAME
*
* and within NodeMCU you access it with myname.foo(), assuming you have
* When you've done this, you can simply add a Kconfig entry for the module
* to control whether it gets linked in or not. With it linked in, you can
* then within NodeMCU access it with myname.foo(), assuming you have
* a foo function in your module.
*/
@ -40,10 +39,10 @@
#define LOCK_IN_SECTION(s) __attribute__((used,unused,section(s)))
/* For the ROM table, we name the variable according to ( | denotes concat):
* cfgname | _module_selected | LUA_USE_MODULES_##cfgname
* where the LUA_USE_MODULES_XYZ macro is first expanded to yield either
* cfgname | _module_selected | CONFIG_LUA_MODULE_##cfgname
* where the CONFIG_LUA_MODULE_XYZ macro is first expanded to yield either
* an empty string (or 1) if the module has been enabled, or the literal
* LUA_USE_MOUDLE_XYZ in the case it hasn't. Thus, the name of the variable
* CONFIG_LUA_MODULE_XYZ in the case it hasn't. Thus, the name of the variable
* ends up looking either like XYZ_module_enabled, or if not enabled,
* XYZ_module_enabledLUA_USE_MODULES_XYZ. This forms the basis for
* letting the build system detect automatically (via nm) which modules need
@ -53,11 +52,11 @@
const LOCK_IN_SECTION(".lua_libs") \
luaL_Reg MODULE_PASTE_(lua_lib_,cfgname) = { luaname, initfunc }; \
const LOCK_IN_SECTION(".lua_rotable") \
luaR_table MODULE_EXPAND_PASTE_(cfgname,MODULE_EXPAND_PASTE_(_module_selected,MODULE_PASTE_(LUA_USE_MODULES_,cfgname))) \
luaR_table MODULE_EXPAND_PASTE_(cfgname,MODULE_EXPAND_PASTE_(_module_selected,MODULE_PASTE_(CONFIG_LUA_MODULE_,cfgname))) \
= { luaname, map }
/* System module registration support, not using LUA_USE_MODULES_XYZ. */
/* System module registration support, not using CONFIG_LUA_MODULE_XYZ. */
#define BUILTIN_LIB_INIT(name, luaname, initfunc) \
const LOCK_IN_SECTION(".lua_libs") \
luaL_Reg MODULE_PASTE_(lua_lib_,name) = { luaname, initfunc }

View File

@ -4,7 +4,7 @@
#include "lauxlib.h"
#include "platform.h"
#include "c_types.h"
#include <stdint.h>
#include <string.h>
static lua_State *gL = NULL;
@ -113,17 +113,6 @@ static int uart_setup( lua_State* L )
return 1;
}
// Lua: alt( set )
static int uart_alt( lua_State* L )
{
unsigned set;
set = luaL_checkinteger( L, 1 );
platform_uart_alt( set );
return 0;
}
// Lua: write( id, string1, [string2], ..., [stringn] )
static int uart_write( lua_State* L )
{
@ -159,7 +148,6 @@ static const LUA_REG_TYPE uart_map[] = {
{ LSTRKEY( "setup" ), LFUNCVAL( uart_setup ) },
{ LSTRKEY( "write" ), LFUNCVAL( uart_write ) },
{ LSTRKEY( "on" ), LFUNCVAL( uart_on ) },
{ LSTRKEY( "alt" ), LFUNCVAL( uart_alt ) },
{ 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 ) },

View File

@ -16,50 +16,17 @@
#include "flash_api.h"
#include "sdkconfig.h"
#include "ets_sys.h"
#include "driver/uart.h"
#include "driver/console.h"
#include "task/task.h"
#include "sections.h"
#include "mem.h"
#include "freertos/task.h"
#ifdef LUA_USE_MODULES_RTCTIME
#include "rtc/rtctime.h"
#endif
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#define SIG_LUA 0
#define SIG_UARTINPUT 1
#ifdef __ESP32__
void system_soft_wdt_feed (void)
{
// FIXME this shouldn't go here, and it needs to tickle hardware watchdog
}
#endif
extern void call_user_start (void);
#if defined(__ESP8266__)
/* 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.
*/
void TEXT_SECTION_ATTR user_start_trampoline (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
/* The first thing call_user_start() does is switch the interrupt vector
* base, which enables our 8/16bit load handler on the ESP8266. */
call_user_start ();
}
#endif
// +================== New task interface ==================+
static void start_lua(task_param_t param, task_prio_t prio) {
(void)param;
@ -139,34 +106,19 @@ static void nodemcu_main (void *param)
}
void user_init (void)
void app_main (void)
{
#ifdef LUA_USE_MODULES_RTCTIME
rtctime_late_startup ();
#endif
input_task = task_get_id (handle_input);
UART_ConfigTypeDef cfg;
cfg.baud_rate = CONFIG_CONSOLE_BIT_RATE;
cfg.data_bits = UART_WordLength_8b;
cfg.parity = USART_Parity_None;
cfg.stop_bits = USART_StopBits_1;
cfg.flow_ctrl = USART_HardwareFlowControl_None;
cfg.UART_RxFlowThresh = 120;
cfg.UART_InverseMask = UART_None_Inverse;
ConsoleSetup_t cfg;
cfg.bit_rate = CONFIG_CONSOLE_BIT_RATE;
cfg.data_bits = CONSOLE_NUM_BITS_8;
cfg.parity = CONSOLE_PARITY_NONE;
cfg.stop_bits = CONSOLE_STOP_BITS_1;
cfg.auto_baud = CONFIG_CONSOLE_BIT_RATE_AUTO;
uart_init_uart0_console (&cfg, input_task);
console_init (&cfg, input_task);
#ifndef NODE_DEBUG
# ifndef __ESP32__
system_set_os_print(0);
# endif
#endif
// FIXME! Max supported RTOS stack size is 512 words (2k bytes), but
// NodeMCU currently uses more than that. The game is on to find these
// culprits, but this gcc doesn't do the -fstack-usage option :(
xTaskCreate (
nodemcu_main, "nodemcu", 1536, 0, configTIMER_TASK_PRIORITY +1, NULL);
nodemcu_main, "nodemcu", 2048, 0, configTIMER_TASK_PRIORITY +1, NULL);
}

View File

@ -1,4 +0,0 @@
COMPONENT_ADD_INCLUDEDIRS:=include
COMPONENT_ADD_LDFLAGS:=-L $(abspath ld) -T core_modules.ld -lcore_modules
include $(IDF_PATH)/make/component_common.mk

View File

@ -0,0 +1,177 @@
/*
* Copyright 2016 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 <jmattsson@dius.com.au>
*/
#include "driver/console.h"
#include "esp_intr.h"
#include "soc/soc.h"
#include "soc/uart_register.h"
#include "soc/dport_reg.h"
#include "freertos/FreeRTOS.h"
#include "freertos/queue.h"
#include <unistd.h>
#include "rom/libc_stubs.h"
#include "sys/reent.h"
#define UART_INPUT_QUEUE_SZ 0x100
#define MAP_CONSOLE_UART_PRO_INT_NO 9 // PRO interrupt used by this driver for uart0
typedef int (*_read_r_fn) (struct _reent *r, int fd, void *buf, int size);
static _read_r_fn _read_r_pro, _read_r_app;
static xQueueHandle uart0Q;
static task_handle_t input_task = 0;
// --- Syscall support for reading from STDIN_FILENO ---------------
static int console_read_r (struct _reent *r, int fd, void *buf, int size, _read_r_fn next)
{
if (fd == STDIN_FILENO)
{
static _lock_t stdin_lock;
_lock_acquire_recursive (&stdin_lock);
char *c = (char *)buf;
int i = 0;
for (; i < size; ++i)
{
if (!console_getc (c++))
break;
}
_lock_release_recursive (&stdin_lock);
return i;
}
else if (next)
return next (r, fd, buf, size);
else
return -1;
}
static int console_read_r_pro (struct _reent *r, int fd, void *buf, int size)
{
return console_read_r (r, fd, buf, size, _read_r_pro);
}
static int console_read_r_app (struct _reent *r, int fd, void *buf, int size)
{
return console_read_r (r, fd, buf, size, _read_r_app);
}
// --- End syscall support -------------------------------------------
static void uart0_rx_intr_handler (void *arg)
{
(void)arg;
bool received = false;
uint32_t status = READ_PERI_REG(UART_INT_ST_REG(CONSOLE_UART));
while (status)
{
if (status & UART_FRM_ERR_INT_ENA)
{
// TODO: report somehow?
WRITE_PERI_REG(UART_INT_CLR_REG(CONSOLE_UART), UART_FRM_ERR_INT_ENA);
}
if ((status & UART_RXFIFO_TOUT_INT_ENA) ||
(status & UART_RXFIFO_FULL_INT_ENA))
{
uint32_t fifo_len = UART_GET_RXFIFO_CNT(CONSOLE_UART);
for (uint32_t i = 0; i < fifo_len; ++i)
{
received = true;
char c = UART_GET_RXFIFO_RD_BYTE(CONSOLE_UART);
if (uart0Q)
xQueueSendToBackFromISR (uart0Q, &c, NULL);
uart_tx_one_char (c);
}
WRITE_PERI_REG(UART_INT_CLR_REG(CONSOLE_UART),
UART_RXFIFO_TOUT_INT_ENA | UART_RXFIFO_FULL_INT_ENA);
}
status = READ_PERI_REG(UART_INT_ST_REG(CONSOLE_UART));
}
if (received && input_task)
task_post_low (input_task, false);
}
void console_setup (const ConsoleSetup_t *cfg)
{
uart_tx_wait_idle (CONSOLE_UART);
uart_div_modify (CONSOLE_UART, (UART_CLK_FREQ << 4) / cfg->bit_rate);
UART_SET_BIT_NUM(CONSOLE_UART, cfg->data_bits);
UART_SET_PARITY_EN(CONSOLE_UART, cfg->parity != CONSOLE_PARITY_NONE);
UART_SET_PARITY(CONSOLE_UART, cfg->parity & 0x1);
UART_SET_STOP_BIT_NUM(CONSOLE_UART, cfg->stop_bits);
// TODO: Make this actually work
UART_SET_AUTOBAUD_EN(CONSOLE_UART, cfg->auto_baud);
}
void console_init (const ConsoleSetup_t *cfg, task_handle_t tsk)
{
input_task = tsk;
uart0Q = xQueueCreate (UART_INPUT_QUEUE_SZ, sizeof (char));
console_setup (cfg);
ESP_INTR_DISABLE(MAP_CONSOLE_UART_PRO_INT_NO);
xt_set_interrupt_handler (MAP_CONSOLE_UART_PRO_INT_NO, uart0_rx_intr_handler, NULL);
UART_SET_RX_TOUT_EN(CONSOLE_UART, true);
UART_SET_RX_TOUT_THRHD(CONSOLE_UART, 2);
UART_SET_RXFIFO_FULL_THRHD(CONSOLE_UART, 10);
WRITE_PERI_REG(UART_INT_ENA_REG(CONSOLE_UART),
UART_RXFIFO_TOUT_INT_ENA |
UART_RXFIFO_FULL_INT_ENA |
UART_FRM_ERR_INT_ENA);
WRITE_PERI_REG(PRO_UART_INTR_MAP_REG, MAP_CONSOLE_UART_PRO_INT_NO);
ESP_INTR_ENABLE(MAP_CONSOLE_UART_PRO_INT_NO);
// Register our console_read_r_xxx functions to support stdin input
_read_r_pro = syscall_table_ptr_pro->_read_r;
_read_r_app = syscall_table_ptr_app->_read_r;
syscall_table_ptr_pro->_read_r = console_read_r_pro;
syscall_table_ptr_app->_read_r = console_read_r_app;
}
bool console_getc (char *c)
{
return (uart0Q && (xQueueReceive (uart0Q, c, 0) == pdTRUE));
}

View File

@ -0,0 +1,74 @@
/*
* Copyright 2016 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 <jmattsson@dius.com.au>
*/
#include "rom/uart.h"
#include "task/task.h"
#include <stdint.h>
#include <stdbool.h>
#define CONSOLE_UART 0
typedef enum
{
CONSOLE_NUM_BITS_5 = 0x0,
CONSOLE_NUM_BITS_6 = 0x1,
CONSOLE_NUM_BITS_7 = 0x2,
CONSOLE_NUM_BITS_8 = 0x3
} ConsoleNumBits_t;
typedef enum
{
CONSOLE_PARITY_NONE = 0x2,
CONSOLE_PARITY_ODD = 0x1,
CONSOLE_PARITY_EVEN = 0x0
} ConsoleParity_t;
typedef enum
{
CONSOLE_STOP_BITS_1 = 0x1,
CONSOLE_STOP_BITS_1_5 = 0x2,
CONSOLE_STOP_BITS_2 = 0x3
} ConsoleStopBits_t;
typedef struct
{
uint32_t bit_rate;
ConsoleNumBits_t data_bits;
ConsoleParity_t parity;
ConsoleStopBits_t stop_bits;
bool auto_baud;
} ConsoleSetup_t;
void console_init (const ConsoleSetup_t *cfg, task_handle_t tsk);
void console_setup (const ConsoleSetup_t *cfg);
bool console_getc (char *c);

View File

@ -1,8 +0,0 @@
#ifndef READLINE_APP_H
#define READLINE_APP_H
#include <stdbool.h>
bool uart_getc(char *c);
#endif /* READLINE_APP_H */

View File

@ -1,332 +0,0 @@
/*
* ESPRSSIF MIT License
*
* Copyright (c) 2015 <ESPRESSIF SYSTEMS (SHANGHAI) PTE LTD>
*
* Permission is hereby granted for use on ESPRESSIF SYSTEMS ESP32 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:
*
* 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.
*
*/
#ifndef __UART_H__
#define __UART_H__
//#include "c_types.h" /* for BIT(n) definition */
#include "soc/uart_register.h"
#include "task/task.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef enum {
UART_WordLength_5b = 0x0,
UART_WordLength_6b = 0x1,
UART_WordLength_7b = 0x2,
UART_WordLength_8b = 0x3
} UART_WordLength;
typedef enum {
USART_StopBits_1 = 0x1,
USART_StopBits_1_5 = 0x2,
USART_StopBits_2 = 0x3,
} UART_StopBits;
typedef enum {
UART0 = 0x0,
UART1 = 0x1,
} UART_Port;
typedef enum {
USART_Parity_None = 0x2,
USART_Parity_Even = 0x0,
USART_Parity_Odd = 0x1
} UART_ParityMode;
typedef enum {
BIT_RATE_300 = 300,
BIT_RATE_600 = 600,
BIT_RATE_1200 = 1200,
BIT_RATE_2400 = 2400,
BIT_RATE_4800 = 4800,
BIT_RATE_9600 = 9600,
BIT_RATE_19200 = 19200,
BIT_RATE_38400 = 38400,
BIT_RATE_57600 = 57600,
BIT_RATE_74880 = 74880,
BIT_RATE_115200 = 115200,
BIT_RATE_230400 = 230400,
BIT_RATE_460800 = 460800,
BIT_RATE_921600 = 921600,
BIT_RATE_1843200 = 1843200,
BIT_RATE_3686400 = 3686400,
} UART_BautRate; //you can add any rate you need in this range
typedef enum {
USART_HardwareFlowControl_None = 0x0,
USART_HardwareFlowControl_RTS = 0x1,
USART_HardwareFlowControl_CTS = 0x2,
USART_HardwareFlowControl_CTS_RTS = 0x3
} UART_HwFlowCtrl;
typedef enum {
UART_None_Inverse = 0x0,
UART_Rxd_Inverse = UART_RXD_INV,
UART_CTS_Inverse = UART_CTS_INV,
UART_Txd_Inverse = UART_TXD_INV,
UART_RTS_Inverse = UART_RTS_INV,
} UART_LineLevelInverse;
typedef struct {
UART_BautRate baud_rate;
UART_WordLength data_bits;
UART_ParityMode parity; // chip size in byte
UART_StopBits stop_bits;
UART_HwFlowCtrl flow_ctrl;
uint8 UART_RxFlowThresh ;
uint32 UART_InverseMask;
} UART_ConfigTypeDef;
typedef struct {
uint32 UART_IntrEnMask;
uint8 UART_RX_TimeOutIntrThresh;
uint8 UART_TX_FifoEmptyIntrThresh;
uint8 UART_RX_FifoFullIntrThresh;
} UART_IntrConfTypeDef;
//=======================================
/** \defgroup Driver_APIs Driver APIs
* @brief Driver APIs
*/
/** @addtogroup Driver_APIs
* @{
*/
/** \defgroup UART_Driver_APIs UART Driver APIs
* @brief UART driver APIs
*/
/** @addtogroup UART_Driver_APIs
* @{
*/
/**
* @brief Set UART baud rate.
*
* Example : uart_div_modify(uart_no, UART_CLK_FREQ / (UartDev.baut_rate));
*
* @param UART_Port uart_no : UART0 or UART1
* @param uint16 div : frequency divider
*
* @return null
*/
void uart_div_modify(UART_Port uart_no, uint16 div);
/**
* @brief Wait uart tx fifo empty, do not use it if tx flow control enabled.
*
* @param UART_Port uart_no : UART0 or UART1
*
* @return null
*/
void UART_WaitTxFifoEmpty(UART_Port uart_no); //do not use if tx flow control enabled
/**
* @brief Clear uart tx fifo and rx fifo.
*
* @param UART_Port uart_no : UART0 or UART1
*
* @return null
*/
void UART_ResetFifo(UART_Port uart_no);
/**
* @brief Clear uart interrupt flags.
*
* @param UART_Port uart_no : UART0 or UART1
* @param uint32 clr_mask : To clear the interrupt bits
*
* @return null
*/
void UART_ClearIntrStatus(UART_Port uart_no, uint32 clr_mask);
/**
* @brief Enable uart interrupts .
*
* @param UART_Port uart_no : UART0 or UART1
* @param uint32 ena_mask : To enable the interrupt bits
*
* @return null
*/
void UART_SetIntrEna(UART_Port uart_no, uint32 ena_mask);
/**
* @brief Register an application-specific interrupt handler for Uarts interrupts.
*
* @param void *fn : interrupt handler for Uart interrupts.
* @param void *arg : interrupt handler's arg.
*
* @return null
*/
void UART_intr_handler_register(void *fn, void *arg);
/**
* @brief Config from which serial output printf function.
*
* @param UART_Port uart_no : UART0 or UART1
*
* @return null
*/
void UART_SetPrintPort(UART_Port uart_no);
/**
* @brief Config Common parameters of serial ports.
*
* @param UART_Port uart_no : UART0 or UART1
* @param UART_ConfigTypeDef *pUARTConfig : parameters structure
*
* @return null
*/
void UART_ParamConfig(UART_Port uart_no, const UART_ConfigTypeDef *pUARTConfig);
/**
* @brief Config types of uarts.
*
* @param UART_Port uart_no : UART0 or UART1
* @param UART_IntrConfTypeDef *pUARTIntrConf : parameters structure
*
* @return null
*/
void UART_IntrConfig(UART_Port uart_no, const UART_IntrConfTypeDef *pUARTIntrConf);
/**
* @brief Config the length of the uart communication data bits.
*
* @param UART_Port uart_no : UART0 or UART1
* @param UART_WordLength len : the length of the uart communication data bits
*
* @return null
*/
void UART_SetWordLength(UART_Port uart_no, UART_WordLength len);
/**
* @brief Config the length of the uart communication stop bits.
*
* @param UART_Port uart_no : UART0 or UART1
* @param UART_StopBits bit_num : the length uart communication stop bits
*
* @return null
*/
void UART_SetStopBits(UART_Port uart_no, UART_StopBits bit_num);
/**
* @brief Configure whether to open the parity.
*
* @param UART_Port uart_no : UART0 or UART1
* @param UART_ParityMode Parity_mode : the enum of uart parity configuration
*
* @return null
*/
void UART_SetParity(UART_Port uart_no, UART_ParityMode Parity_mode) ;
/**
* @brief Configure the Baud rate.
*
* @param UART_Port uart_no : UART0 or UART1
* @param uint32 baud_rate : the Baud rate
*
* @return null
*/
void UART_SetBaudrate(UART_Port uart_no, uint32 baud_rate);
/**
* @brief Configure Hardware flow control.
*
* @param UART_Port uart_no : UART0 or UART1
* @param UART_HwFlowCtrl flow_ctrl : Hardware flow control mode
* @param uint8 rx_thresh : threshold of Hardware flow control
*
* @return null
*/
void UART_SetFlowCtrl(UART_Port uart_no, UART_HwFlowCtrl flow_ctrl, uint8 rx_thresh);
/**
* @brief Configure trigging signal of uarts.
*
* @param UART_Port uart_no : UART0 or UART1
* @param UART_LineLevelInverse inverse_mask : Choose need to flip the IO
*
* @return null
*/
void UART_SetLineInverse(UART_Port uart_no, UART_LineLevelInverse inverse_mask) ;
/**
* @}
*/
/**
* @}
*/
/**
* Set up uart0 for NodeMCU console use.
* @param config The UART params to apply.
* @param tsk NodeMCU task to be notified when there is input pending.
*/
void uart_init_uart0_console (const UART_ConfigTypeDef *config, task_handle_t tsk);
/**
* Generic UART send interface.
* @param uart_no Which UART to send on (UART0 or UART1).
* @param c The character to send.
*/
void uart_tx_one_char (uint32_t uart_no, uint8_t c);
/**
* Switch (or unswitch) UART0 to the alternate pins.
* Currently only ESP8266.
* @param on True to use alternate RX/TX pins, false to use default pins.
*/
void uart0_alt (bool on);
/**
* Attempts to pull a character off the UART0 receive queue.
* @param c Where to stash the received character, if any.
* @returns True if a character was stored in @c, false if no char available.
*/
bool uart0_getc (char *c);
/**
* Convenience/consistency wrapper for UART0 output.
* @param c The character to output.
*/
static inline void uart0_putc (char c) { uart_tx_one_char (UART0, c); }
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,371 +0,0 @@
#if 0
/*
* ESPRSSIF MIT License
*
* Copyright (c) 2015 <ESPRESSIF SYSTEMS (SHANGHAI) PTE LTD>
* 2016 DiUS Computing Pty Ltd <jmattsson@dius.com.au>
*
* Permission is hereby granted for use on ESPRESSIF SYSTEMS ESP8266/ESP32 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:
*
* 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.
*
*/
#include "soc/soc.h"
#include "soc/io_mux_reg.h"
#include "esp_intr.h"
#include "freertos/FreeRTOS.h"
#include "freertos/queue.h"
#include "freertos/xtensa_api.h"
#include "driver/uart.h"
#include "task/task.h"
#include <stdio.h>
#define UART_INTR_MASK 0x1ff
#define UART_LINE_INV_MASK (0x3f << 19)
static xQueueHandle uartQ[2];
static task_handle_t input_task = 0;
// FIXME: on the ESP32 the interrupts are not shared between UART0 & UART1
void uart_tx_one_char(uint32_t uart, uint8_t TxChar)
{
while (true) {
uint32 fifo_cnt = READ_PERI_REG(UART_STATUS_REG(uart)) & (UART_TXFIFO_CNT << UART_TXFIFO_CNT_S);
if ((fifo_cnt >> UART_TXFIFO_CNT_S & UART_TXFIFO_CNT) < 126) {
break;
}
}
WRITE_PERI_REG(UART_FIFO_REG(uart) , TxChar);
}
static void uart1_write_char(char c)
{
if (c == '\n') {
uart_tx_one_char(UART1, '\r');
uart_tx_one_char(UART1, '\n');
} else if (c == '\r') {
} else {
uart_tx_one_char(UART1, c);
}
}
static void uart0_write_char(char c)
{
if (c == '\n') {
uart_tx_one_char(UART0, '\r');
uart_tx_one_char(UART0, '\n');
} else if (c == '\r') {
} else {
uart_tx_one_char(UART0, c);
}
}
//=================================================================
void UART_SetWordLength(UART_Port uart_no, UART_WordLength len)
{
SET_PERI_REG_BITS(UART_CONF0_REG(uart_no), UART_BIT_NUM, len, UART_BIT_NUM_S);
}
void
UART_SetStopBits(UART_Port uart_no, UART_StopBits bit_num)
{
SET_PERI_REG_BITS(UART_CONF0_REG(uart_no), UART_STOP_BIT_NUM, bit_num, UART_STOP_BIT_NUM_S);
}
void UART_SetLineInverse(UART_Port uart_no, UART_LineLevelInverse inverse_mask)
{
CLEAR_PERI_REG_MASK(UART_CONF0_REG(uart_no), UART_LINE_INV_MASK);
SET_PERI_REG_MASK(UART_CONF0_REG(uart_no), inverse_mask);
}
void UART_SetParity(UART_Port uart_no, UART_ParityMode Parity_mode)
{
CLEAR_PERI_REG_MASK(UART_CONF0_REG(uart_no), UART_PARITY | UART_PARITY_EN);
if (Parity_mode == USART_Parity_None) {
} else {
SET_PERI_REG_MASK(UART_CONF0_REG(uart_no), Parity_mode | UART_PARITY_EN);
}
}
void UART_SetBaudrate(UART_Port uart_no, uint32 baud_rate)
{
uart_div_modify(uart_no, UART_CLK_FREQ / baud_rate);
}
//only when USART_HardwareFlowControl_RTS is set , will the rx_thresh value be set.
void UART_SetFlowCtrl(UART_Port uart_no, UART_HwFlowCtrl flow_ctrl, uint8 rx_thresh)
{
if (uart_no == 0)
{
if (flow_ctrl & USART_HardwareFlowControl_RTS) {
#if defined(__ESP8266__)
PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTDO_U, FUNC_U0RTS);
#elif defined(__ESP32__)
PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO22_U, FUNC_GPIO22_U0RTS);
#endif
SET_PERI_REG_BITS(UART_CONF1_REG(uart_no), UART_RX_FLOW_THRHD, rx_thresh, UART_RX_FLOW_THRHD_S);
SET_PERI_REG_MASK(UART_CONF1_REG(uart_no), UART_RX_FLOW_EN);
} else {
CLEAR_PERI_REG_MASK(UART_CONF1_REG(uart_no), UART_RX_FLOW_EN);
}
if (flow_ctrl & USART_HardwareFlowControl_CTS) {
#if defined(__ESP8266__)
PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTCK_U, FUNC_UART0_CTS);
#elif defined(__ESP32__)
PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO19_U, FUNC_GPIO19_U0CTS);
#endif
SET_PERI_REG_MASK(UART_CONF0_REG(uart_no), UART_TX_FLOW_EN);
} else {
CLEAR_PERI_REG_MASK(UART_CONF0_REG(uart_no), UART_TX_FLOW_EN);
}
}
}
void UART_WaitTxFifoEmpty(UART_Port uart_no) //do not use if tx flow control enabled
{
while (READ_PERI_REG(UART_STATUS_REG(uart_no)) & (UART_TXFIFO_CNT << UART_TXFIFO_CNT_S));
}
void UART_ResetFifo(UART_Port uart_no)
{
SET_PERI_REG_MASK(UART_CONF0_REG(uart_no), UART_RXFIFO_RST | UART_TXFIFO_RST);
CLEAR_PERI_REG_MASK(UART_CONF0_REG(uart_no), UART_RXFIFO_RST | UART_TXFIFO_RST);
}
void UART_ClearIntrStatus(UART_Port uart_no, uint32 clr_mask)
{
WRITE_PERI_REG(UART_INT_CLR_REG(uart_no), clr_mask);
}
void UART_SetIntrEna(UART_Port uart_no, uint32 ena_mask)
{
SET_PERI_REG_MASK(UART_INT_ENA_REG(uart_no), ena_mask);
}
void UART_intr_handler_register(void *fn, void *arg)
{
#if defined(__ESP8266__)
_xt_isr_attach(ETS_UART_INUM, fn, arg);
#elif defined(__ESP32__)
xt_set_interrupt_handler(ETS_UART0_INUM, fn, arg);
#endif
}
void UART_SetPrintPort(UART_Port uart_no)
{
if (uart_no == 1) {
ets_install_putc1(uart1_write_char);
} else {
ets_install_putc1(uart0_write_char);
}
}
void UART_ParamConfig(UART_Port uart_no, const UART_ConfigTypeDef *pUARTConfig)
{
if (uart_no == UART1) {
#if defined(__ESP8266__)
PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO2_U, FUNC_U1TXD_BK);
#elif defined(__ESP32__)
PIN_FUNC_SELECT(PERIPHS_IO_MUX_SD_DATA3_U, FUNC_SD_DATA3_U1TXD);
#endif
} else {
PIN_PULLUP_DIS(PERIPHS_IO_MUX_U0TXD_U);
#if defined(__ESP8266__)
PIN_FUNC_SELECT(PERIPHS_IO_MUX_U0RXD_U, FUNC_U0RXD);
PIN_FUNC_SELECT(PERIPHS_IO_MUX_U0TXD_U, FUNC_U0TXD);
#elif defined(__ESP32__)
PIN_FUNC_SELECT(PERIPHS_IO_MUX_U0RXD_U, FUNC_U0RXD_U0RXD);
PIN_FUNC_SELECT(PERIPHS_IO_MUX_U0TXD_U, FUNC_U0TXD_U0TXD);
#endif
}
UART_SetFlowCtrl(uart_no, pUARTConfig->flow_ctrl, pUARTConfig->UART_RxFlowThresh);
UART_SetBaudrate(uart_no, pUARTConfig->baud_rate);
WRITE_PERI_REG(UART_CONF0_REG(uart_no),
((pUARTConfig->parity == USART_Parity_None) ? 0x0 : (UART_PARITY_EN | pUARTConfig->parity))
| (pUARTConfig->stop_bits << UART_STOP_BIT_NUM_S)
| (pUARTConfig->data_bits << UART_BIT_NUM_S)
| ((pUARTConfig->flow_ctrl & USART_HardwareFlowControl_CTS) ? UART_TX_FLOW_EN : 0x0)
| pUARTConfig->UART_InverseMask
#if defined(__ESP32__)
| UART_TICK_REF_ALWAYS_ON
#endif
);
UART_ResetFifo(uart_no);
}
void UART_IntrConfig(UART_Port uart_no, const UART_IntrConfTypeDef *pUARTIntrConf)
{
uint32 reg_val = 0;
UART_ClearIntrStatus(uart_no, UART_INTR_MASK);
reg_val = READ_PERI_REG(UART_CONF1_REG(uart_no));
reg_val |= ((pUARTIntrConf->UART_IntrEnMask & UART_RXFIFO_TOUT_INT_ENA) ?
((((pUARTIntrConf->UART_RX_TimeOutIntrThresh)&UART_RX_TOUT_THRHD) << UART_RX_TOUT_THRHD_S) | UART_RX_TOUT_EN) : 0);
reg_val |= ((pUARTIntrConf->UART_IntrEnMask & UART_RXFIFO_FULL_INT_ENA) ?
(((pUARTIntrConf->UART_RX_FifoFullIntrThresh)&UART_RXFIFO_FULL_THRHD) << UART_RXFIFO_FULL_THRHD_S) : 0);
reg_val |= ((pUARTIntrConf->UART_IntrEnMask & UART_TXFIFO_EMPTY_INT_ENA) ?
(((pUARTIntrConf->UART_TX_FifoEmptyIntrThresh)&UART_TXFIFO_EMPTY_THRHD) << UART_TXFIFO_EMPTY_THRHD_S) : 0);
WRITE_PERI_REG(UART_CONF1_REG(uart_no), reg_val);
CLEAR_PERI_REG_MASK(UART_INT_ENA_REG(uart_no), UART_INTR_MASK);
SET_PERI_REG_MASK(UART_INT_ENA_REG(uart_no), pUARTIntrConf->UART_IntrEnMask);
}
static void uart0_rx_intr_handler(void *para)
{
/* uart0 and uart1 intr combine togther, when interrupt occur, see reg 0x3ff20020, bit2, bit0 represents
* uart1 and uart0 respectively
*/
uint8 uart_no = UART0; // TODO: support UART1 as well
uint8 fifo_len = 0;
uint32 uart_intr_status = READ_PERI_REG(UART_INT_ST_REG(uart_no)) ;
while (uart_intr_status != 0x0) {
if (UART_FRM_ERR_INT_ST == (uart_intr_status & UART_FRM_ERR_INT_ST)) {
//os_printf_isr("FRM_ERR\r\n");
WRITE_PERI_REG(UART_INT_CLR_REG(uart_no), UART_FRM_ERR_INT_CLR);
} else if (UART_RXFIFO_FULL_INT_ST == (uart_intr_status & UART_RXFIFO_FULL_INT_ST)) {
//os_printf_isr("full\r\n");
fifo_len = (READ_PERI_REG(UART_STATUS_REG(uart_no)) >> UART_RXFIFO_CNT_S)&UART_RXFIFO_CNT;
for (int i = 0; i < fifo_len; ++i)
{
char c = READ_PERI_REG(UART_FIFO_REG(uart_no)) & 0xff;
if (uartQ[uart_no])
xQueueSendToBackFromISR (uartQ[uart_no], &c, NULL);
}
WRITE_PERI_REG(UART_INT_CLR_REG(uart_no), UART_RXFIFO_FULL_INT_CLR);
//CLEAR_PERI_REG_MASK(UART_INT_ENA_REG(uart_no), UART_RXFIFO_FULL_INT_ENA|UART_RXFIFO_TOUT_INT_ENA);
} else if (UART_RXFIFO_TOUT_INT_ST == (uart_intr_status & UART_RXFIFO_TOUT_INT_ST)) {
//os_printf_isr("timeout\r\n");
fifo_len = (READ_PERI_REG(UART_STATUS_REG(uart_no)) >> UART_RXFIFO_CNT_S)&UART_RXFIFO_CNT;
for (int i = 0; i < fifo_len; ++i)
{
char c = READ_PERI_REG(UART_FIFO_REG(uart_no)) & 0xff;
if (uartQ[uart_no])
xQueueSendToBackFromISR (uartQ[uart_no], &c, NULL);
}
WRITE_PERI_REG(UART_INT_CLR_REG(uart_no), UART_RXFIFO_TOUT_INT_CLR);
} else if (UART_TXFIFO_EMPTY_INT_ST == (uart_intr_status & UART_TXFIFO_EMPTY_INT_ST)) {
//os_printf_isr("empty\n\r");
WRITE_PERI_REG(UART_INT_CLR_REG(uart_no), UART_TXFIFO_EMPTY_INT_CLR);
CLEAR_PERI_REG_MASK(UART_INT_ENA_REG(uart_no), UART_TXFIFO_EMPTY_INT_ENA);
} else if (UART_RXFIFO_OVF_INT_ST == (READ_PERI_REG(UART_INT_ST_REG(uart_no)) & UART_RXFIFO_OVF_INT_ST)) {
WRITE_PERI_REG(UART_INT_CLR_REG(uart_no), UART_RXFIFO_OVF_INT_CLR);
//os_printf_isr("RX OVF!!\r\n");
} else {
//skip
}
uart_intr_status = READ_PERI_REG(UART_INT_ST_REG(uart_no)) ;
}
if (fifo_len && input_task)
task_post_low (input_task, false);
}
void uart_init_uart0_console (const UART_ConfigTypeDef *config, task_handle_t tsk)
{
input_task = tsk;
uartQ[0] = xQueueCreate (0x100, sizeof (char));
UART_WaitTxFifoEmpty(UART0);
UART_ParamConfig(UART0, config);
UART_IntrConfTypeDef uart_intr;
uart_intr.UART_IntrEnMask =
UART_RXFIFO_TOUT_INT_ENA |
UART_FRM_ERR_INT_ENA |
UART_RXFIFO_FULL_INT_ENA |
UART_TXFIFO_EMPTY_INT_ENA;
uart_intr.UART_RX_FifoFullIntrThresh = 10;
uart_intr.UART_RX_TimeOutIntrThresh = 2;
uart_intr.UART_TX_FifoEmptyIntrThresh = 20;
UART_IntrConfig(UART0, &uart_intr);
UART_SetPrintPort(UART0);
UART_intr_handler_register(uart0_rx_intr_handler, NULL);
ESP_UART0_INTR_ENABLE();
}
bool uart0_getc (char *c)
{
return (uartQ[UART0] && (xQueueReceive (uartQ[UART0], c, 0) == pdTRUE));
}
void uart0_alt (bool on)
{
#if defined(__ESP8266__)
if (on)
{
PIN_PULLUP_DIS(PERIPHS_IO_MUX_MTDO_U);
PIN_PULLUP_EN(PERIPHS_IO_MUX_MTCK_U);
PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTCK_U, FUNC_U0CTS);
// now make RTS/CTS behave as TX/RX
IOSWAP |= (1 << IOSWAPU0);
}
else
{
PIN_PULLUP_DIS(PERIPHS_IO_MUX_U0TXD_U);
PIN_FUNC_SELECT(PERIPHS_IO_MUX_U0TXD_U, FUNC_U0TXD);
PIN_PULLUP_EN(PERIPHS_IO_MUX_U0RXD_U);
PIN_FUNC_SELECT(PERIPHS_IO_MUX_U0RXD_U, FUNC_U0RXD);
// now make RX/TX behave as TX/RX
IOSWAP &= ~(1 << IOSWAPU0);
}
#else
printf("Alternate UART0 pins not supported on this chip\n");
#endif
}
#endif

View File

@ -2,7 +2,6 @@
#include "legc.h"
#include "lstate.h"
#include "c_types.h"
void legc_set_mode(lua_State *L, int mode, unsigned limit) {
global_State *g = G(L);

View File

@ -20,6 +20,7 @@
#ifndef LUA_CROSS_COMPILER
#include "flash_fs.h"
#include "c_stdlib.h"
#endif
#include "lauxlib.h"

View File

@ -11,10 +11,10 @@
#include <string.h>
#include "flash_fs.h"
#include "user_version.h"
#include "driver/readline.h"
#include "driver/uart.h"
#include "driver/console.h"
#include "esp_system.h"
#include "platform.h"
#include "c_stdlib.h"
#define lua_c
@ -24,8 +24,6 @@
#include "lualib.h"
#include "legc.h"
#include "os_type.h"
lua_State *globalL = NULL;
lua_Load gLoad;
@ -535,11 +533,9 @@ static void dojob(lua_Load *load){
load->line_position = 0;
memset(load->line, 0, load->len);
printf(load->prmt);
fflush (stdout);
}
#ifndef uart_putc
#define uart_putc uart0_putc
#endif
extern bool uart_on_data_cb(const char *buf, size_t len);
extern bool uart0_echo;
extern bool run_input;
@ -550,7 +546,7 @@ static bool readline(lua_Load *load){
// NODE_DBG("readline() is called.\n");
bool need_dojob = false;
char ch;
while (uart0_getc(&ch))
while (console_getc(&ch))
{
if(run_input)
{
@ -571,9 +567,9 @@ static bool readline(lua_Load *load){
{
if (load->line_position > 0)
{
if(uart0_echo) uart_putc(0x08);
if(uart0_echo) uart_putc(' ');
if(uart0_echo) uart_putc(0x08);
if(uart0_echo) putchar(0x08);
if(uart0_echo) putchar(' ');
if(uart0_echo) putchar(0x08);
load->line_position--;
}
load->line[load->line_position] = 0;
@ -595,12 +591,13 @@ static bool readline(lua_Load *load){
last_nl_char = ch;
load->line[load->line_position] = 0;
if(uart0_echo) uart_putc('\n');
if(uart0_echo) putchar('\n');
uart_on_data_cb(load->line, load->line_position);
if (load->line_position == 0)
{
/* Get a empty line, then go to get a new line */
printf(load->prmt);
fflush (stdout);
} else {
load->done = 1;
need_dojob = true;
@ -615,7 +612,7 @@ static bool readline(lua_Load *load){
// }
/* echo */
if(uart0_echo) uart_putc(ch);
if(uart0_echo) putchar(ch);
/* it's a large line, discard it */
if ( load->line_position + 1 >= load->len ){

View File

@ -10,7 +10,6 @@
#include <limits.h>
#include <stddef.h>
#include "user_config.h"
/*
** ==================================================================

View File

@ -0,0 +1,9 @@
menu "NodeMCU modules"
config LUA_MODULE_NODE
bool "Node module"
default "y"
help
Includes the node module (recommended).
endmenu

View File

@ -0,0 +1,13 @@
# Match up all the module source files with their corresponding Kconfig
# option in the form LUA_MODULE_<modname> and if enabled, add a
# "-u <modname>_module_selected1" option to force the linker to include
# the module. See components/core/include/module.h for further details on
# how this works.
-include $(PROJECT_PATH)/build/include/config/auto.conf
include $(PROJECT_PATH)/components/modules/uppercase.mk
MODULE_NAMES:=$(call uppercase,$(subst .c,,$(wildcard *.c)))
FORCE_LINK:=$(foreach mod,$(MODULE_NAMES),$(if $(CONFIG_LUA_MODULE_$(mod)), -u $(mod)_module_selected1))
COMPONENT_ADD_LDFLAGS=$(FORCE_LINK) -lmodules
include $(IDF_PATH)/make/component_common.mk

20
components/modules/node.c Normal file
View File

@ -0,0 +1,20 @@
#include "module.h"
#include "lauxlib.h"
#include "esp_system.h"
// Lua: heap()
static int node_heap( lua_State* L )
{
uint32_t sz = system_get_free_heap_size();
lua_pushinteger(L, sz);
return 1;
}
static const LUA_REG_TYPE node_map[] =
{
{ LSTRKEY( "heap" ), LFUNCVAL( node_heap ) },
{ LNILKEY, LNILVAL }
};
NODEMCU_MODULE(NODE, "node", node_map, NULL);

View File

@ -0,0 +1,11 @@
uppercase_TABLE:=a,A b,B c,C d,D e,E f,F g,G h,H i,I j,J k,K l,L m,M n,N o,O p,P q,Q r,R s,S t,T u,U v,V w,W x,X y,Y z,Z
define uppercase_internal
$(if $1,$$(subst $(firstword $1),$(call uppercase_internal,$(wordlist
2,$(words $1),$1),$2)),$2)
endef
define uppercase
$(eval uppercase_RESULT:=$(call
uppercase_internal,$(uppercase_TABLE),$1))$(uppercase_RESULT)
endef

View File

@ -3,7 +3,6 @@
* NodeMCU Team
* 2014-12-31
*******************************************************************************/
#include "user_config.h"
#include "flash_api.h"
#include <stdio.h>
#include <string.h>

View File

@ -4,7 +4,7 @@
#include "sdkconfig.h"
#include "esp_spi_flash.h"
#define NUM_UART 2
#define NUM_UART 3
#if defined(CONFIG_FLASH_SIZE_512K)
# define FLASH_SEC_NUM 0x80 // 4MByte: 0x400, 2MByte: 0x200, 1MByte: 0x100, 512KByte: 0x80

View File

@ -50,7 +50,6 @@ static inline int platform_uart_exists( unsigned id ) { return id < NUM_UART; }
uint32_t platform_uart_setup( unsigned id, uint32_t baud, int databits, int parity, int stopbits );
void platform_uart_send( unsigned id, uint8_t data );
int platform_uart_set_flow_control( unsigned id, int type );
void platform_uart_alt( int set );

View File

@ -1,5 +1,6 @@
#include "platform.h"
#include "driver/uart.h"
#include "driver/console.h"
#include <stdio.h>
int platform_init (void)
{
@ -11,89 +12,49 @@ int platform_init (void)
uint32_t platform_uart_setup( unsigned id, uint32_t baud, int databits, int parity, int stopbits )
{
UART_ConfigTypeDef cfg;
switch( baud )
if (id == CONSOLE_UART)
{
case BIT_RATE_300:
case BIT_RATE_600:
case BIT_RATE_1200:
case BIT_RATE_2400:
case BIT_RATE_4800:
case BIT_RATE_9600:
case BIT_RATE_19200:
case BIT_RATE_38400:
case BIT_RATE_57600:
case BIT_RATE_74880:
case BIT_RATE_115200:
case BIT_RATE_230400:
case BIT_RATE_460800:
case BIT_RATE_921600:
case BIT_RATE_1843200:
case BIT_RATE_3686400:
cfg.baud_rate = baud;
break;
default:
cfg.baud_rate = BIT_RATE_9600;
break;
}
ConsoleSetup_t cfg;
cfg.bit_rate = baud;
switch (databits)
{
case 5:
cfg.data_bits = UART_WordLength_5b;
break;
case 6:
cfg.data_bits = UART_WordLength_6b;
break;
case 7:
cfg.data_bits = UART_WordLength_7b;
break;
case 8:
default:
cfg.data_bits = UART_WordLength_8b;
break;
case 5: cfg.data_bits = CONSOLE_NUM_BITS_5; break;
case 6: cfg.data_bits = CONSOLE_NUM_BITS_6; break;
case 7: cfg.data_bits = CONSOLE_NUM_BITS_7; break;
case 8: // fall-through
default: cfg.data_bits = CONSOLE_NUM_BITS_8; break;
}
switch (stopbits)
{
case PLATFORM_UART_STOPBITS_1_5:
cfg.stop_bits = USART_StopBits_1_5;
break;
case PLATFORM_UART_STOPBITS_2:
cfg.stop_bits = USART_StopBits_2;
break;
default:
cfg.stop_bits = USART_StopBits_1;
break;
}
switch (parity)
{
case PLATFORM_UART_PARITY_EVEN:
cfg.parity = USART_Parity_Even;
break;
case PLATFORM_UART_PARITY_ODD:
cfg.parity = USART_Parity_Odd;
break;
default:
cfg.parity = USART_Parity_None;
break;
case PLATFORM_UART_PARITY_EVEN: cfg.parity = CONSOLE_PARITY_EVEN; break;
case PLATFORM_UART_PARITY_ODD: cfg.parity = CONSOLE_PARITY_ODD; break;
default: // fall-through
case PLATFORM_UART_PARITY_NONE: cfg.parity = CONSOLE_PARITY_NONE; break;
}
UART_ParamConfig (id, &cfg);
switch (stopbits)
{
default: // fall-through
case PLATFORM_UART_STOPBITS_1:
cfg.stop_bits = CONSOLE_STOP_BITS_1; break;
case PLATFORM_UART_STOPBITS_1_5:
cfg.stop_bits = CONSOLE_STOP_BITS_1_5; break;
case PLATFORM_UART_STOPBITS_2:
cfg.stop_bits = CONSOLE_STOP_BITS_2; break;
}
cfg.auto_baud = false;
console_setup (&cfg);
return baud;
}
// if set=1, then alternate serial output pins are used. (15=rx, 13=tx)
void platform_uart_alt( int set )
else
{
uart0_alt( set );
return;
printf("UART1/UART2 not yet supported\n");
return 0;
}
}
void platform_uart_send( unsigned id, uint8_t data )
{
uart_tx_one_char(id, data);
if (id == CONSOLE_UART)
putchar (data);
}

View File

@ -1 +1,2 @@
COMPONENT_ADD_INCLUDEDIRS:=include
include $(IDF_PATH)/make/component_common.mk

View File

@ -1,6 +1,6 @@
#include <stdint.h>
#include <stdbool.h>
#include <rom.h>
#include "rom/ets_sys.h"
static char space[]=" ";
static char blank[]=".. ";

View File

@ -0,0 +1,8 @@
#ifndef _HEXDUMP_H_
#define _HEXDUMP_H_
#include <stdint.h>
void hexdump (char *src, uint32_t len, uint32_t base_addr);
#endif

View File

@ -8,7 +8,6 @@
#ifndef SPIFFS_CONFIG_H_
#define SPIFFS_CONFIG_H_
#include "user_config.h"
#include <stdio.h>
#include <stdint.h>
#include <string.h>

View File

@ -3,7 +3,6 @@
#include <stdint.h>
#include <stdbool.h>
#include <c_types.h>
/* use LOW / MEDIUM / HIGH since it isn't clear from the docs which is higher */

View File

@ -2,10 +2,10 @@
This file encapsulates the SDK-based task handling for the NodeMCU Lua firmware.
*/
#include "task/task.h"
#include "mem.h"
#include <stdlib.h>
#include <string.h>
#include "freertos/FreeRTOS.h"
#include "freertos/queue.h"
#include "freertos/semphr.h"

View File

@ -1,17 +0,0 @@
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
void pingTask(void *pvParameters)
{
while (1) {
vTaskDelay(1000 / portTICK_PERIOD_MS);
printf("ping\n");
}
}
void app_main()
{
xTaskCreatePinnedToCore(&pingTask, "pingTask", 2048, NULL, 5, NULL, 0);
}

View File

@ -1 +0,0 @@
include $(IDF_PATH)/make/component_common.mk

View File

@ -1,8 +0,0 @@
#ifndef _SDK_OVERRIDES_C_TYPES_H
#define _SDK_OVERRIDES_C_TYPES_H
#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>
#endif

View File

@ -1,7 +0,0 @@
#ifndef _SDK_OVERRIDES_EAGLE_SOC_
#define _SDK_OVERRIDES_EAGLE_SOC_
// TODO: Discover what this is now called in ESP-IDF...
#define ICACHE_RAM_ATTR
#endif

View File

@ -1,4 +0,0 @@
#ifndef _SDK_OVERRIDES_ESP_LIBC_H_
#define _SDK_OVERRIDES_ESP_LIBC_H_
void *zalloc(size_t n);
#endif

View File

@ -1 +0,0 @@
../../sdk/esp32-rtos-sdk/include

View File

@ -1,27 +0,0 @@
#ifndef _SDK_OVERRIDES_ETS_SYS_H_
#define _SDK_OVERRIDES_ETS_SYS_H_
#include_next <rom/ets_sys.h>
#include <freertos/xtensa_api.h>
#define ETS_UART_INTR_ATTACH(fn,arg) xt_set_interrupt_handler(ETS_UART_INUM, fn, arg)
#define ETS_UART_INTR_ENABLE() xt_ints_on(1 << ETS_UART_INUM)
#define ETS_UART_INTR_DISABLE() xt_ints_off(1 << ETS_UART_INUM)
#define ETS_SPI_INTR_ATTACH(fn,arg) xt_set_interrupt_handler(ETS_SPI_INUM, fn, arg)
#define ETS_SPI_INTR_ENABLE() xt_ints_on(1 << ETS_SPI_INUM)
#define ETS_SPI_INTR_DISABLE() xt_ints_off(1 << ETS_SPI_INUM)
#define ETS_GPIO_INTR_ATTACH(fn,arg) xt_set_interrupt_handler(ETS_GPIO_INUM, fn, arg)
#define ETS_GPIO_INTR_ENABLE() xt_ints_on(1 << ETS_GPIO_INUM)
#define ETS_GPIO_INTR_DISABLE() xt_ints_off(1 << ETS_GPIO_INUM)
#define ETS_FRC_TIMER1_INTR_ATTACH(fn,arg) xt_set_interrupt_handler(ETS_FRC_TIMER1_INUM, fn, arg)
#define ETS_FRC1_INTR_ENABLE() xt_ints_on(1 << ETS_FRC_TIMER1_INUM)
#define ETS_FRC1_INTR_DISABLE() xt_ints_off(1 << ETS_FRC_TIMER1_INUM)
// FIXME: double-check this is the correct bit!
#define TM1_EDGE_INT_ENABLE() SET_PERI_REG_MASK(EDGE_INT_ENABLE_REG, BIT1)
#define TM1_EDGE_INT_DISABLE() CLEAR_PERI_REG_MASK(EDGE_INT_ENABLE_REG, BIT1)
#endif

View File

@ -1,17 +0,0 @@
#ifndef _SDK_OVERRIDES_GPIO_H_
#define _SDK_OVERRIDES_GPIO_H_
#include_next <gpio.h>
#define GPIO_STATUS_W1TC_ADDRESS GPIO_STATUS_W1TC
#define GPIO_STATUS_ADDRESS GPIO_STATUS
#define GPIO_OUT_W1TS_ADDRESS GPIO_OUT_W1TS
#define GPIO_OUT_W1TC_ADDRESS GPIO_OUT_W1TC
#define GPIO_ENABLE_W1TC_ADDRESS GPIO_ENABLE_W1TC
#define GPIO_ENABLE_ADDRESS GPIO_ENABLE
// FIXME: how does this apply to the ESP32?
#define GPIO_PIN_SOURCE_SET(x) 0
#define GPIO_PIN_SOURCE_MASK 0
#endif

View File

@ -1,4 +0,0 @@
#ifndef _SDK_OVERRIDES_USER_INTERFACE_H_
#define _SDK_OVERRIDES_USER_INTERFACE_H_
#endif