Commit afbbeb45 authored by Johny Mattsson's avatar Johny Mattsson
Browse files

Replaced UART driver.

New driver is a three-way merger between Espressif's esp8266-rtos-sdk example
driver, Espressif's esp32-rtos-sdk not-example driver, and the previous
NodeMCU driver, plus some general clean-ups.

Basic interactivity is now available on the ESP32!
parent f9c65b94
...@@ -54,6 +54,7 @@ INCLUDE_DIRS=\ ...@@ -54,6 +54,7 @@ INCLUDE_DIRS=\
$(SDKDIR)/include/espressif \ $(SDKDIR)/include/espressif \
$(SDKDIR)/include/espressif/$(TARGET) \ $(SDKDIR)/include/espressif/$(TARGET) \
$(SDKDIR)/include/$(TARGET) \ $(SDKDIR)/include/$(TARGET) \
$(SDKDIR)/include/$(TARGET)/uart \
$(SDKDIR)/include/lwip \ $(SDKDIR)/include/lwip \
$(SDKDIR)/include/lwip/ipv4 \ $(SDKDIR)/include/lwip/ipv4 \
$(SDKDIR)/include/lwip/ipv6 \ $(SDKDIR)/include/lwip/ipv6 \
......
...@@ -38,7 +38,7 @@ STD_CFLAGS=-std=gnu11 -Wimplicit ...@@ -38,7 +38,7 @@ STD_CFLAGS=-std=gnu11 -Wimplicit
# Required for each makefile to inherit from the parent # Required for each makefile to inherit from the parent
# #
INCLUDES := $(INCLUDES) -I $(PDIR)include INCLUDES := $(INCLUDES) -I $(PDIR)include -I ../include/driver
INCLUDES += -I ./ INCLUDES += -I ./
INCLUDES += -I ../platform INCLUDES += -I ../platform
PDIR := ../$(PDIR) PDIR := ../$(PDIR)
......
#include "ets_sys.h"
#include "os_type.h"
#include "osapi.h"
#include "driver/uart.h"
#include "c_types.h"
LOCAL os_timer_t readline_timer;
// UartDev is defined and initialized in rom code.
extern UartDevice UartDev;
#define uart_putc uart0_putc
bool uart_getc(char *c){
RcvMsgBuff *pRxBuff = &(UartDev.rcv_buff);
if(pRxBuff->pWritePos == pRxBuff->pReadPos){ // empty
return false;
}
// ETS_UART_INTR_DISABLE();
ETS_INTR_LOCK();
*c = (char)*(pRxBuff->pReadPos);
if (pRxBuff->pReadPos == (pRxBuff->pRcvMsgBuff + RX_BUFF_SIZE)) {
pRxBuff->pReadPos = pRxBuff->pRcvMsgBuff ;
} else {
pRxBuff->pReadPos++;
}
// ETS_UART_INTR_ENABLE();
ETS_INTR_UNLOCK();
return true;
}
#if 0
int readline4lua(const char *prompt, char *buffer, int length){
char ch;
int line_position;
start:
/* show prompt */
uart0_sendStr(prompt);
line_position = 0;
os_memset(buffer, 0, length);
while (1)
{
while (uart_getc(&ch))
{
/* handle CR key */
if (ch == '\r')
{
char next;
if (uart_getc(&next))
ch = next;
}
/* backspace key */
else if (ch == 0x7f || ch == 0x08)
{
if (line_position > 0)
{
uart_putc(0x08);
uart_putc(' ');
uart_putc(0x08);
line_position--;
}
buffer[line_position] = 0;
continue;
}
/* EOF(ctrl+d) */
else if (ch == 0x04)
{
if (line_position == 0)
/* No input which makes lua interpreter close */
return 0;
else
continue;
}
/* end of line */
if (ch == '\r' || ch == '\n')
{
buffer[line_position] = 0;
uart_putc('\n');
if (line_position == 0)
{
/* Get a empty line, then go to get a new line */
goto start;
}
else
{
return line_position;
}
}
/* other control character or not an acsii character */
if (ch < 0x20 || ch >= 0x80)
{
continue;
}
/* echo */
uart_putc(ch);
buffer[line_position] = ch;
ch = 0;
line_position++;
/* it's a large line, discard it */
if (line_position >= length)
line_position = 0;
}
}
}
#endif
This diff is collapsed.
#ifndef UART_APP_H /*
#define UART_APP_H * 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 "uart_register.h" #include "uart_register.h"
#include "eagle_soc.h"
#include "c_types.h"
#include "os_type.h"
#include "task/task.h" #include "task/task.h"
#define RX_BUFF_SIZE 0x100 #ifdef __cplusplus
#define TX_BUFF_SIZE 100 extern "C" {
#endif
typedef enum { typedef enum {
FIVE_BITS = 0x0, UART_WordLength_5b = 0x0,
SIX_BITS = 0x1, UART_WordLength_6b = 0x1,
SEVEN_BITS = 0x2, UART_WordLength_7b = 0x2,
EIGHT_BITS = 0x3 UART_WordLength_8b = 0x3
} UartBitsNum4Char; } UART_WordLength;
typedef enum { typedef enum {
ONE_STOP_BIT = 0x1, USART_StopBits_1 = 0x1,
ONE_HALF_STOP_BIT = 0x2, USART_StopBits_1_5 = 0x2,
TWO_STOP_BIT = 0x3 USART_StopBits_2 = 0x3,
} UartStopBitsNum; } UART_StopBits;
typedef enum { typedef enum {
NONE_BITS = 0x2, UART0 = 0x0,
ODD_BITS = 1, UART1 = 0x1,
EVEN_BITS = 0 } UART_Port;
} UartParityMode;
typedef enum { typedef enum {
STICK_PARITY_DIS = 0, USART_Parity_None = 0x2,
STICK_PARITY_EN = 1 USART_Parity_Even = 0x0,
} UartExistParity; USART_Parity_Odd = 0x1
} UART_ParityMode;
typedef enum { typedef enum {
BIT_RATE_300 = 300, BIT_RATE_300 = 300,
...@@ -47,67 +70,263 @@ typedef enum { ...@@ -47,67 +70,263 @@ typedef enum {
BIT_RATE_74880 = 74880, BIT_RATE_74880 = 74880,
BIT_RATE_115200 = 115200, BIT_RATE_115200 = 115200,
BIT_RATE_230400 = 230400, BIT_RATE_230400 = 230400,
BIT_RATE_256000 = 256000,
BIT_RATE_460800 = 460800, BIT_RATE_460800 = 460800,
BIT_RATE_921600 = 921600, BIT_RATE_921600 = 921600,
BIT_RATE_1843200 = 1843200, BIT_RATE_1843200 = 1843200,
BIT_RATE_3686400 = 3686400, BIT_RATE_3686400 = 3686400,
} UartBautRate; } UART_BautRate; //you can add any rate you need in this range
typedef enum { typedef enum {
NONE_CTRL, USART_HardwareFlowControl_None = 0x0,
HARDWARE_CTRL, USART_HardwareFlowControl_RTS = 0x1,
XON_XOFF_CTRL USART_HardwareFlowControl_CTS = 0x2,
} UartFlowCtrl; USART_HardwareFlowControl_CTS_RTS = 0x3
} UART_HwFlowCtrl;
typedef enum { typedef enum {
EMPTY, UART_None_Inverse = 0x0,
UNDER_WRITE, UART_Rxd_Inverse = UART_RXD_INV,
WRITE_OVER UART_CTS_Inverse = UART_CTS_INV,
} RcvMsgBuffState; UART_Txd_Inverse = UART_TXD_INV,
UART_RTS_Inverse = UART_RTS_INV,
} UART_LineLevelInverse;
typedef struct { typedef struct {
uint32 RcvBuffSize; UART_BautRate baud_rate;
uint8 *pRcvMsgBuff; UART_WordLength data_bits;
uint8 *pWritePos; UART_ParityMode parity; // chip size in byte
uint8 *pReadPos; UART_StopBits stop_bits;
uint8 TrigLvl; //JLU: may need to pad UART_HwFlowCtrl flow_ctrl;
RcvMsgBuffState BuffState; uint8 UART_RxFlowThresh ;
} RcvMsgBuff; uint32 UART_InverseMask;
} UART_ConfigTypeDef;
typedef struct { typedef struct {
uint32 TrxBuffSize; uint32 UART_IntrEnMask;
uint8 *pTrxBuff; uint8 UART_RX_TimeOutIntrThresh;
} TrxMsgBuff; uint8 UART_TX_FifoEmptyIntrThresh;
uint8 UART_RX_FifoFullIntrThresh;
} UART_IntrConfTypeDef;
typedef enum { //=======================================
BAUD_RATE_DET,
WAIT_SYNC_FRM,
SRCH_MSG_HEAD,
RCV_MSG_BODY,
RCV_ESC_CHAR,
} RcvMsgState;
typedef struct { /** \defgroup Driver_APIs Driver APIs
UartBautRate baut_rate; * @brief Driver APIs
UartBitsNum4Char data_bits; */
UartExistParity exist_parity;
UartParityMode parity; // chip size in byte /** @addtogroup Driver_APIs
UartStopBitsNum stop_bits; * @{
UartFlowCtrl flow_ctrl; */
RcvMsgBuff rcv_buff;
TrxMsgBuff trx_buff; /** \defgroup UART_Driver_APIs UART Driver APIs
RcvMsgState rcv_state; * @brief UART driver APIs
int received; */
int buff_uart_no; //indicate which uart use tx/rx buffer
} UartDevice; /** @addtogroup UART_Driver_APIs
* @{
void uart_init(UartBautRate uart0_br, UartBautRate uart1_br, task_handle_t sig_input); */
void uart0_alt(uint8 on);
void uart0_sendStr(const char *str);
void uart0_putc(const char c); /**
void uart0_tx_buffer(uint8 *buf, uint16 len); * @brief Set UART baud rate.
void uart_setup(uint8 uart_no); *
STATUS uart_tx_one_char(uint8 uart, uint8 TxChar); * 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
#endif
//Generated at 2012-07-03 18:44:06
/*
* Copyright (c) 2010 - 2011 Espressif System
*
*/
#ifndef UART_REGISTER_H_INCLUDED
#define UART_REGISTER_H_INCLUDED
#define REG_UART_BASE( i ) (0x60000000+(i)*0xf00)
//version value:32'h062000
#define UART_FIFO( i ) (REG_UART_BASE( i ) + 0x0)
#define UART_RXFIFO_RD_BYTE 0x000000FF
#define UART_RXFIFO_RD_BYTE_S 0
#define UART_INT_RAW( i ) (REG_UART_BASE( i ) + 0x4)
#define UART_RXFIFO_TOUT_INT_RAW (BIT(8))
#define UART_BRK_DET_INT_RAW (BIT(7))
#define UART_CTS_CHG_INT_RAW (BIT(6))
#define UART_DSR_CHG_INT_RAW (BIT(5))
#define UART_RXFIFO_OVF_INT_RAW (BIT(4))
#define UART_FRM_ERR_INT_RAW (BIT(3))
#define UART_PARITY_ERR_INT_RAW (BIT(2))
#define UART_TXFIFO_EMPTY_INT_RAW (BIT(1))
#define UART_RXFIFO_FULL_INT_RAW (BIT(0))
#define UART_INT_ST( i ) (REG_UART_BASE( i ) + 0x8)
#define UART_RXFIFO_TOUT_INT_ST (BIT(8))
#define UART_BRK_DET_INT_ST (BIT(7))
#define UART_CTS_CHG_INT_ST (BIT(6))
#define UART_DSR_CHG_INT_ST (BIT(5))
#define UART_RXFIFO_OVF_INT_ST (BIT(4))
#define UART_FRM_ERR_INT_ST (BIT(3))
#define UART_PARITY_ERR_INT_ST (BIT(2))
#define UART_TXFIFO_EMPTY_INT_ST (BIT(1))
#define UART_RXFIFO_FULL_INT_ST (BIT(0))
#define UART_INT_ENA( i ) (REG_UART_BASE( i ) + 0xC)
#define UART_RXFIFO_TOUT_INT_ENA (BIT(8))
#define UART_BRK_DET_INT_ENA (BIT(7))
#define UART_CTS_CHG_INT_ENA (BIT(6))
#define UART_DSR_CHG_INT_ENA (BIT(5))
#define UART_RXFIFO_OVF_INT_ENA (BIT(4))
#define UART_FRM_ERR_INT_ENA (BIT(3))
#define UART_PARITY_ERR_INT_ENA (BIT(2))
#define UART_TXFIFO_EMPTY_INT_ENA (BIT(1))
#define UART_RXFIFO_FULL_INT_ENA (BIT(0))
#define UART_INT_CLR( i ) (REG_UART_BASE( i ) + 0x10)
#define UART_RXFIFO_TOUT_INT_CLR (BIT(8))
#define UART_BRK_DET_INT_CLR (BIT(7))
#define UART_CTS_CHG_INT_CLR (BIT(6))
#define UART_DSR_CHG_INT_CLR (BIT(5))
#define UART_RXFIFO_OVF_INT_CLR (BIT(4))
#define UART_FRM_ERR_INT_CLR (BIT(3))
#define UART_PARITY_ERR_INT_CLR (BIT(2))
#define UART_TXFIFO_EMPTY_INT_CLR (BIT(1))
#define UART_RXFIFO_FULL_INT_CLR (BIT(0))
#define UART_CLKDIV( i ) (REG_UART_BASE( i ) + 0x14)
#define UART_CLKDIV_CNT 0x000FFFFF
#define UART_CLKDIV_S 0
#define UART_AUTOBAUD( i ) (REG_UART_BASE( i ) + 0x18)
#define UART_GLITCH_FILT 0x000000FF
#define UART_GLITCH_FILT_S 8
#define UART_AUTOBAUD_EN (BIT(0))
#define UART_STATUS( i ) (REG_UART_BASE( i ) + 0x1C)
#define UART_TXD (BIT(31))
#define UART_RTSN (BIT(30))
#define UART_DTRN (BIT(29))
#define UART_TXFIFO_CNT 0x000000FF
#define UART_TXFIFO_CNT_S 16
#define UART_RXD (BIT(15))
#define UART_CTSN (BIT(14))
#define UART_DSRN (BIT(13))
#define UART_RXFIFO_CNT 0x000000FF
#define UART_RXFIFO_CNT_S 0
#define UART_CONF0( i ) (REG_UART_BASE( i ) + 0x20)
#define UART_DTR_INV (BIT(24))
#define UART_RTS_INV (BIT(23))
#define UART_TXD_INV (BIT(22))
#define UART_DSR_INV (BIT(21))
#define UART_CTS_INV (BIT(20))
#define UART_RXD_INV (BIT(19))
#define UART_TXFIFO_RST (BIT(18))
#define UART_RXFIFO_RST (BIT(17))
#define UART_IRDA_EN (BIT(16))
#define UART_TX_FLOW_EN (BIT(15))
#define UART_LOOPBACK (BIT(14))
#define UART_IRDA_RX_INV (BIT(13))
#define UART_IRDA_TX_INV (BIT(12))
#define UART_IRDA_WCTL (BIT(11))
#define UART_IRDA_TX_EN (BIT(10))
#define UART_IRDA_DPLX (BIT(9))
#define UART_TXD_BRK (BIT(8))
#define UART_SW_DTR (BIT(7))
#define UART_SW_RTS (BIT(6))
#define UART_STOP_BIT_NUM 0x00000003
#define UART_STOP_BIT_NUM_S 4
#define UART_BIT_NUM 0x00000003
#define UART_BIT_NUM_S 2
#define UART_PARITY_EN (BIT(1))
#define UART_PARITY_EN_M 0x00000001
#define UART_PARITY_EN_S 1
#define UART_PARITY (BIT(0))
#define UART_PARITY_M 0x00000001
#define UART_PARITY_S 0
#define UART_CONF1( i ) (REG_UART_BASE( i ) + 0x24)
#define UART_RX_TOUT_EN (BIT(31))
#define UART_RX_TOUT_THRHD 0x0000007F
#define UART_RX_TOUT_THRHD_S 24
#define UART_RX_FLOW_EN (BIT(23))
#define UART_RX_FLOW_THRHD 0x0000007F
#define UART_RX_FLOW_THRHD_S 16
#define UART_TXFIFO_EMPTY_THRHD 0x0000007F
#define UART_TXFIFO_EMPTY_THRHD_S 8
#define UART_RXFIFO_FULL_THRHD 0x0000007F
#define UART_RXFIFO_FULL_THRHD_S 0
#define UART_LOWPULSE( i ) (REG_UART_BASE( i ) + 0x28)
#define UART_LOWPULSE_MIN_CNT 0x000FFFFF
#define UART_LOWPULSE_MIN_CNT_S 0
#define UART_HIGHPULSE( i ) (REG_UART_BASE( i ) + 0x2C)
#define UART_HIGHPULSE_MIN_CNT 0x000FFFFF
#define UART_HIGHPULSE_MIN_CNT_S 0
#define UART_PULSE_NUM( i ) (REG_UART_BASE( i ) + 0x30)
#define UART_PULSE_NUM_CNT 0x0003FF
#define UART_PULSE_NUM_CNT_S 0
#define UART_DATE( i ) (REG_UART_BASE( i ) + 0x78)
#define UART_ID( i ) (REG_UART_BASE( i ) + 0x7C)
#define ESP8266_DREG(addr) *((volatile uint32_t *)(0x3FF00000+(addr)))
//IO SWAP Register
#define IOSWAP ESP8266_DREG(0x28)
#define IOSWAPU 0 //Swaps UART
#define IOSWAPS 1 //Swaps SPI
#define IOSWAPU0 2 //Swaps UART 0 pins (u0rxd <-> u0cts), (u0txd <-> u0rts)
#define IOSWAPU1 3 //Swaps UART 1 pins (u1rxd <-> u1cts), (u1txd <-> u1rts)
#define IOSWAPHS 5 //Sets HSPI with higher prio
#define IOSWAP2HS 6 //Sets Two SPI Masters on HSPI
#define IOSWAP2CS 7 //Sets Two SPI Masters on CSPI
#endif // UART_REGISTER_H_INCLUDED
...@@ -168,7 +168,6 @@ void ets_intr_unlock(void); ...@@ -168,7 +168,6 @@ void ets_intr_unlock(void);
int rand(void); int rand(void);
void srand(unsigned int); void srand(unsigned int);
void uart_div_modify(int no, unsigned int freq);
unsigned int uart_baudrate_detect(unsigned int uart_no, unsigned int async); unsigned int uart_baudrate_detect(unsigned int uart_no, unsigned int async);
......
...@@ -549,7 +549,7 @@ static bool readline(lua_Load *load){ ...@@ -549,7 +549,7 @@ static bool readline(lua_Load *load){
// NODE_DBG("readline() is called.\n"); // NODE_DBG("readline() is called.\n");
bool need_dojob = false; bool need_dojob = false;
char ch; char ch;
while (uart_getc(&ch)) while (uart0_getc(&ch))
{ {
if(run_input) if(run_input)
{ {
......
...@@ -336,10 +336,9 @@ void NO_INTR_CODE platform_gpio_intr_init( unsigned pin, GPIO_INT_TYPE type ) ...@@ -336,10 +336,9 @@ void NO_INTR_CODE platform_gpio_intr_init( unsigned pin, GPIO_INT_TYPE type )
// UART // UART
// TODO: Support timeouts. // TODO: Support timeouts.
// UartDev is defined and initialized in rom code.
extern UartDevice UartDev;
uint32_t platform_uart_setup( unsigned id, uint32_t baud, int databits, int parity, int stopbits ) uint32_t platform_uart_setup( unsigned id, uint32_t baud, int databits, int parity, int stopbits )
{ {
UART_ConfigTypeDef cfg;
switch( baud ) switch( baud )
{ {
case BIT_RATE_300: case BIT_RATE_300:
...@@ -354,68 +353,61 @@ uint32_t platform_uart_setup( unsigned id, uint32_t baud, int databits, int pari ...@@ -354,68 +353,61 @@ uint32_t platform_uart_setup( unsigned id, uint32_t baud, int databits, int pari
case BIT_RATE_74880: case BIT_RATE_74880:
case BIT_RATE_115200: case BIT_RATE_115200:
case BIT_RATE_230400: case BIT_RATE_230400:
case BIT_RATE_256000:
case BIT_RATE_460800: case BIT_RATE_460800:
case BIT_RATE_921600: case BIT_RATE_921600:
case BIT_RATE_1843200: case BIT_RATE_1843200:
case BIT_RATE_3686400: case BIT_RATE_3686400:
UartDev.baut_rate = baud; cfg.baud_rate = baud;
break; break;
default: default:
UartDev.baut_rate = BIT_RATE_9600; cfg.baud_rate = BIT_RATE_9600;
break; break;
} }
switch( databits ) switch( databits )
{ {
case 5: case 5:
UartDev.data_bits = FIVE_BITS; cfg.data_bits = UART_WordLength_5b;
break; break;
case 6: case 6:
UartDev.data_bits = SIX_BITS; cfg.data_bits = UART_WordLength_6b;
break; break;
case 7: case 7:
UartDev.data_bits = SEVEN_BITS; cfg.data_bits = UART_WordLength_7b;
break; break;
case 8: case 8:
UartDev.data_bits = EIGHT_BITS;
break;
default: default:
UartDev.data_bits = EIGHT_BITS; cfg.data_bits = UART_WordLength_8b;
break; break;
} }
switch (stopbits) switch (stopbits)
{ {
case PLATFORM_UART_STOPBITS_1_5: case PLATFORM_UART_STOPBITS_1_5:
UartDev.stop_bits = ONE_HALF_STOP_BIT; cfg.stop_bits = USART_StopBits_1_5;
break; break;
case PLATFORM_UART_STOPBITS_2: case PLATFORM_UART_STOPBITS_2:
UartDev.stop_bits = TWO_STOP_BIT; cfg.stop_bits = USART_StopBits_2;
break; break;
default: default:
UartDev.stop_bits = ONE_STOP_BIT; cfg.stop_bits = USART_StopBits_1;
break; break;
} }
switch (parity) switch (parity)
{ {
case PLATFORM_UART_PARITY_EVEN: case PLATFORM_UART_PARITY_EVEN:
UartDev.parity = EVEN_BITS; cfg.parity = USART_Parity_Even;
UartDev.exist_parity = STICK_PARITY_EN;
break; break;
case PLATFORM_UART_PARITY_ODD: case PLATFORM_UART_PARITY_ODD:
UartDev.parity = ODD_BITS; cfg.parity = USART_Parity_Odd;
UartDev.exist_parity = STICK_PARITY_EN;
break; break;
default: default:
UartDev.parity = NONE_BITS; cfg.parity = USART_Parity_None;
UartDev.exist_parity = STICK_PARITY_DIS;
break; break;
} }
uart_setup(id); UART_ParamConfig (id, &cfg);
return baud; return baud;
} }
......
...@@ -76,14 +76,14 @@ static void handle_input(task_param_t flag, task_prio_t priority) { ...@@ -76,14 +76,14 @@ static void handle_input(task_param_t flag, task_prio_t priority) {
lua_handle_input (flag); lua_handle_input (flag);
} }
static task_handle_t input_sig; static task_handle_t input_task;
task_handle_t user_get_input_sig(void) { task_handle_t user_get_input_sig(void) {
return input_sig; return input_task;
} }
bool user_process_input(bool force) { bool user_process_input(bool force) {
return task_post_low(input_sig, force); return task_post_low(input_task, force);
} }
void nodemcu_init(void) void nodemcu_init(void)
...@@ -154,13 +154,18 @@ void user_init(void) ...@@ -154,13 +154,18 @@ void user_init(void)
rtctime_late_startup (); rtctime_late_startup ();
#endif #endif
#if !defined(__ESP32__) input_task = task_get_id (handle_input);
// FIXME - need UART driver for ESP32
UartBautRate br = BIT_RATE_DEFAULT;
input_sig = task_get_id(handle_input); UART_ConfigTypeDef cfg;
uart_init (br, br, input_sig); cfg.baud_rate = BIT_RATE_DEFAULT;
#endif 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;
uart_init_uart0_console (&cfg, input_task);
#ifndef NODE_DEBUG #ifndef NODE_DEBUG
system_set_os_print(0); system_set_os_print(0);
......
...@@ -17,8 +17,6 @@ ...@@ -17,8 +17,6 @@
#define ETS_UART_INTR_ATTACH(fn,arg) _xt_isr_attach(ETS_UART_INUM, fn, arg) #define ETS_UART_INTR_ATTACH(fn,arg) _xt_isr_attach(ETS_UART_INUM, fn, arg)
#define ETS_SPI_INTR_ATTACH(fn,arg) _xt_isr_attach(ETS_SPI_INUM, fn, arg) #define ETS_SPI_INTR_ATTACH(fn,arg) _xt_isr_attach(ETS_SPI_INUM, fn, arg)
#define ETS_UART_INTR_ENABLE() _xt_isr_unmask(1 << ETS_UART_INUM)
#define ETS_UART_INTR_DISABLE() _xt_isr_mask(1 << ETS_UART_INUM)
#define ETS_GPIO_INTR_ENABLE() _xt_isr_unmask(1 << ETS_GPIO_INUM) #define ETS_GPIO_INTR_ENABLE() _xt_isr_unmask(1 << ETS_GPIO_INUM)
#define ETS_GPIO_INTR_DISABLE() _xt_isr_mask(1 << ETS_GPIO_INUM) #define ETS_GPIO_INTR_DISABLE() _xt_isr_mask(1 << ETS_GPIO_INUM)
#define ETS_SPI_INTR_ENABLE() _xt_isr_unmask(1 << ETS_SPI_INUM) #define ETS_SPI_INTR_ENABLE() _xt_isr_unmask(1 << ETS_SPI_INUM)
......
#ifndef _SDK_OVERRIDES_IOSWAP_H_
#define _SDK_OVERRIDES_IOSWAP_H_
#define ESP8266_DREG(addr) *((volatile uint32_t *)(0x3FF00000+(addr)))
#define IOSWAP ESP8266_DREG(0x28)
#define IOSWAPU 0 //Swaps UART
#define IOSWAPS 1 //Swaps SPI
#define IOSWAPU0 2 //Swaps UART 0 pins (u0rxd <-> u0cts), (u0txd <-> u0rts)
#define IOSWAPU1 3 //Swaps UART 1 pins (u1rxd <-> u1cts), (u1txd <-> u1rts)
#define IOSWAPHS 5 //Sets HSPI with higher prio
#define IOSWAP2HS 6 //Sets Two SPI Masters on HSPI
#define IOSWAP2CS 7 //Sets Two SPI Masters on CSPI
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment