fix uart settings via telnet and ajax

pull/236/head
Thorsten von Eicken 8 years ago
parent 8fbb639b72
commit b4595eb792
No known key found for this signature in database
GPG Key ID: C7F972A59D834B46
  1. 16
      serial/console.c
  2. 22
      serial/serbridge.c
  3. 6
      serial/uart.c
  4. 1
      serial/uart.h

@ -87,19 +87,17 @@ ajaxConsoleFormat(HttpdConnData *connData) {
if (connData->conn==NULL) return HTTPD_CGI_DONE; // Connection aborted. Clean up.
char buff[16];
int len, status = 400;
uint32 conf0;
len = httpdFindArg(connData->getArgs, "fmt", buff, sizeof(buff));
if (len >= 3) {
int c = buff[0];
if (c >= '5' && c <= '8')
flashConfig.data_bits = c - '5' + FIVE_BITS;
if (buff[1] == 'N' || buff[1] == 'E')
flashConfig.parity = buff[1] == 'E' ? EVEN_BITS : NONE_BITS;
if (buff[2] == '1' || buff[2] == '2')
flashConfig.stop_bits = buff[2] == '2' ? TWO_STOP_BIT : ONE_STOP_BIT;
conf0 = CALC_UARTMODE(flashConfig.data_bits, flashConfig.parity, flashConfig.stop_bits);
uart_config(0, flashConfig.baud_rate, conf0);
if (c >= '5' && c <= '8') flashConfig.data_bits = c - '5' + FIVE_BITS;
if (buff[1] == 'N') flashConfig.parity = NONE_BITS;
if (buff[1] == 'E') flashConfig.parity = EVEN_BITS;
if (buff[1] == 'O') flashConfig.parity = ODD_BITS;
if (buff[2] == '1') flashConfig.stop_bits = ONE_STOP_BIT;
if (buff[2] == '2') flashConfig.stop_bits = TWO_STOP_BIT;
uart0_config(flashConfig.data_bits, flashConfig.parity, flashConfig.stop_bits);
status = configSave() ? 200 : 400;
} else if (connData->requestType == HTTPD_METHOD_GET) {
status = 200;

@ -70,7 +70,7 @@ telnetUnwrap(serbridgeConnData *conn, uint8_t *inBuf, int len)
else uart0_write_char(c); // regular char
break;
case TN_iac:
os_printf("Telnet: IAC + %d\n", c);
//os_printf("Telnet: IAC + %d\n", c);
switch (c) {
case IAC: // second escape -> write one to outbuf and go normal again
state = TN_normal;
@ -118,13 +118,13 @@ telnetUnwrap(serbridgeConnData *conn, uint8_t *inBuf, int len)
case DTR_ON:
if (mcu_reset_pin >= 0) {
#ifdef SERBR_DBG
os_printf("MCU reset gpio%d\n", mcu_reset_pin);
os_printf("Telnet: reset gpio%d\n", mcu_reset_pin);
#endif
GPIO_OUTPUT_SET(mcu_reset_pin, 0);
os_delay_us(100L);
}
#ifdef SERBR_DBG
else { os_printf("MCU reset: no pin\n"); }
else { os_printf("Telnet: reset: no pin\n"); }
#endif
break;
case DTR_OFF:
@ -136,18 +136,21 @@ telnetUnwrap(serbridgeConnData *conn, uint8_t *inBuf, int len)
case RTS_ON:
if (mcu_isp_pin >= 0) {
#ifdef SERBR_DBG
os_printf("MCU ISP gpio%d\n", mcu_isp_pin);
os_printf("Telnet: ISP gpio%d LOW\n", mcu_isp_pin);
#endif
GPIO_OUTPUT_SET(mcu_isp_pin, 0);
os_delay_us(100L);
}
#ifdef SERBR_DBG
else { os_printf("MCU isp: no pin\n"); }
else { os_printf("Telnet: isp: no pin\n"); }
#endif
in_mcu_flashing++;
break;
case RTS_OFF:
if (mcu_isp_pin >= 0) {
#ifdef SERBR_DBG
os_printf("Telnet: ISP gpio%d HIGH\n", mcu_isp_pin);
#endif
GPIO_OUTPUT_SET(mcu_isp_pin, 1);
os_delay_us(100L);
}
@ -159,9 +162,9 @@ telnetUnwrap(serbridgeConnData *conn, uint8_t *inBuf, int len)
case TN_setDataSize:
if (c >= 5 && c <= 8) {
flashConfig.data_bits = c - 5 + FIVE_BITS;
uint32_t conf0 = CALC_UARTMODE(flashConfig.data_bits, flashConfig.parity, flashConfig.stop_bits);
uart_config(0, flashConfig.baud_rate, conf0);
uart0_config(flashConfig.data_bits, flashConfig.parity, flashConfig.stop_bits);
configSave();
os_printf("Telnet: %d bits/char\n", c);
} else if (c == 0) {
// data size of zero means we need to send the current data size
char respBuf[7] = { IAC, SB, ComPortOpt, SetDataSize,
@ -179,6 +182,7 @@ telnetUnwrap(serbridgeConnData *conn, uint8_t *inBuf, int len)
uart0_baud(tn_baud);
flashConfig.baud_rate = tn_baud;
configSave();
os_printf("Telnet: %d baud\n", tn_baud);
} else if (tn_baud == 0) {
// baud rate of zero means we need to send the baud rate
uint32_t b = flashConfig.baud_rate;
@ -202,9 +206,9 @@ telnetUnwrap(serbridgeConnData *conn, uint8_t *inBuf, int len)
if (c == 2) parity = ODD_BITS;
if (c == 3) parity = EVEN_BITS;
flashConfig.parity = parity;
uint32_t conf0 = CALC_UARTMODE(flashConfig.data_bits, flashConfig.parity, flashConfig.stop_bits);
uart_config(0, flashConfig.baud_rate, conf0);
//uart0_config(flashConfig.data_bits, flashConfig.parity, flashConfig.stop_bits);
configSave();
os_printf("Telnet: parity %s\n", c==2?"odd":c==3?"even":"none");
state = TN_end;
break;
}

@ -256,6 +256,12 @@ uart0_baud(int rate) {
uart_div_modify(UART0, UART_CLK_FREQ / rate);
}
void ICACHE_FLASH_ATTR
uart0_config(uint8_t data_bits, uint8_t parity, uint8_t stop_bits) {
uint32_t conf0 = CALC_UARTMODE(data_bits, parity, stop_bits);
WRITE_PERI_REG(UART_CONF0(0), conf0);
}
/******************************************************************************
* FunctionName : uart_init
* Description : user interface for init uart

@ -27,6 +27,7 @@ void uart_add_recv_cb(UartRecv_cb cb);
uint16_t uart0_rx_poll(char *buff, uint16_t nchars, uint32_t timeout_us);
void uart0_baud(int rate);
void uart0_config(uint8_t data_bits, uint8_t parity, uint8_t stop_bits);
void uart_config(uint8 uart_no, UartBautRate baudrate, uint32 conf0);
#endif /* __UART_H__ */

Loading…
Cancel
Save