diff --git a/app/driver/uart.c b/app/driver/uart.c old mode 100644 new mode 100755 index 3cb9137c..0785dff6 --- a/app/driver/uart.c +++ b/app/driver/uart.c @@ -21,6 +21,10 @@ #ifndef FUNC_U0RXD #define FUNC_U0RXD 0 #endif +#ifndef FUNC_U0CTS +#define FUNC_U0CTS 4 +#endif + // For event signalling static uint8 task = USER_TASK_PRIO_MAX; @@ -75,6 +79,39 @@ uart_config(uint8 uart_no) SET_PERI_REG_MASK(UART_INT_ENA(uart_no), UART_RXFIFO_FULL_INT_ENA); } + + +/****************************************************************************** + * FunctionName : uart0_alt + * Description : Internal used function + * UART0 pins changed to 13,15 if 'on' is set, else set to normal pins + * Parameters : on - 1 = use alternate pins, 0 = use normal pins + * Returns : NONE +*******************************************************************************/ +void ICACHE_FLASH_ATTR +uart0_alt(uint8 on) +{ + if (on) + { + PIN_PULLUP_DIS(PERIPHS_IO_MUX_MTDO_U); + PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTDO_U, FUNC_U0RTS); + 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); + } +} + + /****************************************************************************** * FunctionName : uart_tx_one_char * Description : Internal used function diff --git a/app/include/driver/uart.h b/app/include/driver/uart.h old mode 100644 new mode 100755 index e766cee4..ab9e1cb7 --- a/app/include/driver/uart.h +++ b/app/include/driver/uart.h @@ -102,6 +102,7 @@ typedef struct { } UartDevice; void uart_init(UartBautRate uart0_br, UartBautRate uart1_br, uint8 task_prio, os_signal_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); diff --git a/app/include/driver/uart_register.h b/app/include/driver/uart_register.h old mode 100644 new mode 100755 index 6398879e..4dddc916 --- a/app/include/driver/uart_register.h +++ b/app/include/driver/uart_register.h @@ -125,4 +125,17 @@ #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 diff --git a/app/modules/uart.c b/app/modules/uart.c old mode 100644 new mode 100755 index 423add10..c4fdcc6f --- a/app/modules/uart.c +++ b/app/modules/uart.c @@ -116,6 +116,17 @@ 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 ) { @@ -154,6 +165,8 @@ 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 ) }, + #if LUA_OPTIMIZE_MEMORY > 0 #endif diff --git a/app/platform/platform.c b/app/platform/platform.c old mode 100644 new mode 100755 index a4b8e080..3d776f3a --- a/app/platform/platform.c +++ b/app/platform/platform.c @@ -251,6 +251,14 @@ uint32_t platform_uart_setup( unsigned id, uint32_t baud, int databits, int pari return baud; } +// if set=1, then alternate serial output pins are used. (15=rx, 13=tx) +void platform_uart_alt( int set ) +{ + uart0_alt( set ); + return; +} + + // Send: version with and without mux void platform_uart_send( unsigned id, u8 data ) {