mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 16:29:51 +03:00
(v2) add GPIOs to WebUI as configurable options (LED, Rx, Tx, Dallas sensor) #466
This commit is contained in:
@@ -61,7 +61,7 @@ void IRAM_ATTR EMSuart::emsuart_rx_intr_handler(void * para) {
|
||||
static uint8_t length;
|
||||
portENTER_CRITICAL(&mux);
|
||||
if (EMS_UART.int_st.brk_det) {
|
||||
EMS_UART.int_clr.brk_det = 1; // clear flag
|
||||
EMS_UART.int_clr.brk_det = 1; // clear flag
|
||||
length = 0;
|
||||
while (EMS_UART.status.rxfifo_cnt) {
|
||||
uint8_t rx = EMS_UART.fifo.rw_byte; // read all bytes from fifo
|
||||
@@ -80,7 +80,6 @@ void IRAM_ATTR EMSuart::emsuart_rx_intr_handler(void * para) {
|
||||
portEXIT_CRITICAL(&mux);
|
||||
}
|
||||
|
||||
|
||||
void IRAM_ATTR EMSuart::emsuart_tx_timer_intr_handler() {
|
||||
if (emsTxBufLen == 0) {
|
||||
return;
|
||||
@@ -106,7 +105,7 @@ void IRAM_ATTR EMSuart::emsuart_tx_timer_intr_handler() {
|
||||
/*
|
||||
* init UART driver
|
||||
*/
|
||||
void EMSuart::start(const uint8_t tx_mode) {
|
||||
void EMSuart::start(const uint8_t tx_mode, const uint8_t rx_gpio, const uint8_t tx_gpio) {
|
||||
if (tx_mode_ != 0xFF) { // uart already initialized
|
||||
tx_mode_ = tx_mode;
|
||||
restart();
|
||||
@@ -121,8 +120,9 @@ void EMSuart::start(const uint8_t tx_mode) {
|
||||
.stop_bits = UART_STOP_BITS_1,
|
||||
.flow_ctrl = UART_HW_FLOWCTRL_DISABLE,
|
||||
};
|
||||
|
||||
uart_param_config(EMSUART_UART, &uart_config);
|
||||
uart_set_pin(EMSUART_UART, EMSUART_TXPIN, EMSUART_RXPIN, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
|
||||
uart_set_pin(EMSUART_UART, tx_gpio, rx_gpio, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
|
||||
EMS_UART.int_ena.val = 0; // disable all intr.
|
||||
EMS_UART.int_clr.val = 0xFFFFFFFF; // clear all intr. flags
|
||||
EMS_UART.idle_conf.tx_brk_num = 10; // breaklength 10 bit
|
||||
@@ -132,7 +132,7 @@ void EMSuart::start(const uint8_t tx_mode) {
|
||||
uart_isr_register(EMSUART_UART, emsuart_rx_intr_handler, NULL, ESP_INTR_FLAG_IRAM, NULL);
|
||||
xTaskCreate(emsuart_recvTask, "emsuart_recvTask", 2048, NULL, configMAX_PRIORITIES - 1, NULL);
|
||||
|
||||
timer = timerBegin(0, 80, true); // timer prescale to 1 us, countup
|
||||
timer = timerBegin(0, 80, true); // timer prescale to 1 us, countup
|
||||
timerAttachInterrupt(timer, &emsuart_tx_timer_intr_handler, true); // Timer with edge interrupt
|
||||
restart();
|
||||
}
|
||||
@@ -160,11 +160,11 @@ void EMSuart::restart() {
|
||||
emsTxBufIdx = 0;
|
||||
emsTxBufLen = 0;
|
||||
if (tx_mode_ > 100) {
|
||||
emsTxWait = EMSUART_TX_BIT_TIME * (tx_mode_ - 90);
|
||||
emsTxWait = EMSUART_TX_BIT_TIME * (tx_mode_ - 90);
|
||||
} else {
|
||||
emsTxWait = EMSUART_TX_BIT_TIME * (tx_mode_ + 10);
|
||||
emsTxWait = EMSUART_TX_BIT_TIME * (tx_mode_ + 10);
|
||||
}
|
||||
if(tx_mode_ == EMS_TXMODE_NEW) {
|
||||
if (tx_mode_ == EMS_TXMODE_NEW) {
|
||||
EMS_UART.conf0.txd_brk = 1;
|
||||
} else {
|
||||
EMS_UART.conf0.txd_brk = 0;
|
||||
|
||||
@@ -66,16 +66,6 @@
|
||||
#define EMSUART_TX_WAIT_PLUS (EMSUART_TX_BIT_TIME * 20) // 2080
|
||||
#define EMSUART_TX_BRK_PLUS (EMSUART_TX_BIT_TIME * 11)
|
||||
|
||||
|
||||
// customize the GPIO pins for RX and TX here
|
||||
#ifdef WEMOS_D1_32
|
||||
#define EMSUART_RXPIN 23 // 17 is UART2 RX. Use 23 for D7 on a Wemos D1-32 mini for backwards compatabilty
|
||||
#define EMSUART_TXPIN 5 // 16 is UART2 TX. Use 5 for D8 on a Wemos D1-32 mini for backwards compatabilty
|
||||
#else
|
||||
#define EMSUART_RXPIN 17 // 17 is UART2 RX. Use 23 for D7 on a Wemos D1-32 mini for backwards compatabilty
|
||||
#define EMSUART_TXPIN 16 // 16 is UART2 TX. Use 5 for D8 on a Wemos D1-32 mini for backwards compatabilty
|
||||
#endif
|
||||
|
||||
namespace emsesp {
|
||||
|
||||
#define EMS_TX_STATUS_OK 1
|
||||
@@ -86,7 +76,7 @@ class EMSuart {
|
||||
EMSuart() = default;
|
||||
~EMSuart() = default;
|
||||
|
||||
static void start(const uint8_t tx_mode);
|
||||
static void start(const uint8_t tx_mode, const uint8_t rx_gpio, const uint8_t tx_gpio);
|
||||
static void send_poll(const uint8_t data);
|
||||
static void stop();
|
||||
static void restart();
|
||||
|
||||
@@ -47,11 +47,11 @@ void ICACHE_RAM_ATTR EMSuart::emsuart_rx_intr_handler(void * para) {
|
||||
if (USIS(EMSUART_UART) & ((1 << UIBD))) { // BREAK detection = End of EMS data block
|
||||
USC0(EMSUART_UART) &= ~(1 << UCBRK); // reset tx-brk
|
||||
if (emsTxBufIdx < emsTxBufLen) { // irq tx_mode is interrupted by <brk>
|
||||
emsTxBufIdx = emsTxBufLen + 1; // stop tx
|
||||
emsTxBufIdx = emsTxBufLen + 1; // stop tx
|
||||
// drop_next_rx = true; // we have trash in buffer
|
||||
}
|
||||
USIC(EMSUART_UART) = (1 << UIBD); // INT clear the BREAK detect interrupt
|
||||
length = 0;
|
||||
USIC(EMSUART_UART) = (1 << UIBD); // INT clear the BREAK detect interrupt
|
||||
length = 0;
|
||||
while ((USS(EMSUART_UART) >> USRXC) & 0x0FF) { // read fifo into buffer
|
||||
uint8_t rx = USF(EMSUART_UART);
|
||||
if (length < EMS_MAXBUFFERSIZE) {
|
||||
@@ -98,7 +98,7 @@ void ICACHE_RAM_ATTR EMSuart::emsuart_tx_timer_intr_handler() {
|
||||
timer1_write(EMSUART_TX_BRK_TIMER);
|
||||
} else {
|
||||
USC0(EMSUART_UART) &= ~(1 << UCBRK); // reset <BRK>
|
||||
sending_ = false;
|
||||
sending_ = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,7 +113,7 @@ void ICACHE_FLASH_ATTR EMSuart::emsuart_flush_fifos() {
|
||||
/*
|
||||
* init UART0 driver
|
||||
*/
|
||||
void ICACHE_FLASH_ATTR EMSuart::start(uint8_t tx_mode) {
|
||||
void ICACHE_FLASH_ATTR EMSuart::start(const uint8_t tx_mode, const uint8_t rx_gpio, const uint8_t tx_gpio) {
|
||||
if (tx_mode_ != 0xFF) { // it's a restart no need to configure uart
|
||||
tx_mode_ = tx_mode;
|
||||
restart();
|
||||
@@ -137,7 +137,7 @@ void ICACHE_FLASH_ATTR EMSuart::start(uint8_t tx_mode) {
|
||||
PIN_FUNC_SELECT(PERIPHS_IO_MUX_U0RXD_U, FUNC_U0RXD);
|
||||
|
||||
// set 9600, 8 bits, no parity check, 1 stop bit
|
||||
USD(EMSUART_UART) = (UART_CLK_FREQ / EMSUART_BAUD);
|
||||
USD(EMSUART_UART) = (UART_CLK_FREQ / EMSUART_BAUD);
|
||||
USC0(EMSUART_UART) = EMSUART_CONFIG; // 8N1
|
||||
emsuart_flush_fifos();
|
||||
|
||||
@@ -161,8 +161,11 @@ void ICACHE_FLASH_ATTR EMSuart::start(uint8_t tx_mode) {
|
||||
// disable esp debug which will go to Tx and mess up the line - see https://github.com/espruino/Espruino/issues/655
|
||||
system_set_os_print(0);
|
||||
|
||||
// swap Rx and Tx pins to use GPIO13 (D7) and GPIO15 (D8) respectively
|
||||
system_uart_swap();
|
||||
if (tx_gpio == 1 && rx_gpio == 3) {
|
||||
system_uart_de_swap();
|
||||
} else if (tx_gpio == 15 && rx_gpio == 13) {
|
||||
system_uart_swap(); // swap Rx and Tx pins to use GPIO13 (D7) and GPIO15 (D8) respectively
|
||||
}
|
||||
|
||||
ETS_UART_INTR_ATTACH(emsuart_rx_intr_handler, nullptr);
|
||||
drop_next_rx = true;
|
||||
@@ -181,7 +184,7 @@ void ICACHE_FLASH_ATTR EMSuart::stop() {
|
||||
USIE(EMSUART_UART) = 0;
|
||||
USC0(EMSUART_UART) &= ~(1 << UCBRK); // clear BRK bit
|
||||
timer1_disable();
|
||||
sending_ = false;
|
||||
sending_ = false;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -227,8 +230,8 @@ uint16_t ICACHE_FLASH_ATTR EMSuart::transmit(uint8_t * buf, uint8_t len) {
|
||||
emsTxBuf[i] = buf[i];
|
||||
}
|
||||
USF(EMSUART_UART) = buf[0]; // send first byte
|
||||
emsTxBufIdx = 0;
|
||||
emsTxBufLen = len;
|
||||
emsTxBufIdx = 0;
|
||||
emsTxBufLen = len;
|
||||
if (tx_mode_ > 100 && len > 1) {
|
||||
timer1_write(EMSUART_TX_WAIT_REPLY); // large delay after first byte
|
||||
} else {
|
||||
|
||||
@@ -71,7 +71,7 @@ class EMSuart {
|
||||
EMSuart() = default;
|
||||
~EMSuart() = default;
|
||||
|
||||
static void ICACHE_FLASH_ATTR start(uint8_t tx_mode);
|
||||
static void ICACHE_FLASH_ATTR start(const uint8_t tx_mode, const uint8_t rx_gpio, const uint8_t tx_gpio);
|
||||
static void ICACHE_FLASH_ATTR stop();
|
||||
static void ICACHE_FLASH_ATTR restart();
|
||||
static void ICACHE_FLASH_ATTR send_poll(uint8_t data);
|
||||
|
||||
Reference in New Issue
Block a user