Adding the console uart format support (#189)

Some of the MCU use format other than 8N1.
Adding the support for other format.
pull/193/head
bitdump 8 years ago committed by Thorsten von Eicken
parent 4dcd61714b
commit c5513d063d
  1. 11
      esp-link/config.c
  2. 3
      esp-link/config.h
  3. 4
      esp-link/main.c
  4. 26
      html/console.html
  5. 32
      serial/console.c
  6. 1
      serial/console.h
  7. 28
      serial/uart.c
  8. 3
      serial/uart.h

@ -31,7 +31,10 @@ FlashConfig flashDefault = {
.rx_pullup = 1,
.sntp_server = "us.pool.ntp.org\0",
.syslog_host = "\0", .syslog_minheap = 8192, .syslog_filter = 7, .syslog_showtick = 1, .syslog_showdate = 0,
.mdns_enable = 1, .mdns_servername = "http\0", .timezone_offset = 0
.mdns_enable = 1, .mdns_servername = "http\0", .timezone_offset = 0,
.data_bits = EIGHT_BITS,
.parity = NONE_BITS,
.stop_bits = ONE_STOP_BIT,
};
typedef union {
@ -152,6 +155,12 @@ bool ICACHE_FLASH_ATTR configRestore(void) {
os_memset(flashConfig.mqtt_old_host, 0, 32);
} else os_printf("mqtt_host is '%s'\n", flashConfig.mqtt_host);
if (flashConfig.data_bits == 0) {
// restore to default 8N1
flashConfig.data_bits = flashDefault.data_bits;
flashConfig.parity = flashDefault.parity;
flashConfig.stop_bits = flashDefault.stop_bits;
}
return true;
}

@ -38,6 +38,9 @@ typedef struct {
char mdns_servername[32];
int8_t timezone_offset;
char mqtt_host[64]; // MQTT host we connect to, was 32-char mqtt_old_host
int8_t data_bits;
int8_t parity;
int8_t stop_bits;
} FlashConfig;
extern FlashConfig flashConfig;

@ -74,6 +74,7 @@ HttpdBuiltInUrl builtInUrls[] = {
{ "/log/reset", cgiReset, NULL },
{ "/console/reset", ajaxConsoleReset, NULL },
{ "/console/baud", ajaxConsoleBaud, NULL },
{ "/console/fmt", ajaxConsoleFormat, NULL },
{ "/console/text", ajaxConsole, NULL },
{ "/console/send", ajaxConsoleSend, NULL },
//Enable the line below to protect the WiFi configuration with an username/password combo.
@ -135,7 +136,8 @@ void user_init(void) {
gpio_init();
gpio_output_set(0, 0, 0, (1<<15)); // some people tie it to GND, gotta ensure it's disabled
// init UART
uart_init(flashConfig.baud_rate, 115200);
uart_init(CALC_UARTMODE(flashConfig.data_bits, flashConfig.parity, flashConfig.stop_bits),
flashConfig.baud_rate, 115200);
logInit(); // must come after init of uart
// Say hello (leave some time to cause break in TX after boot loader's msg
os_delay_us(10000L);

@ -18,7 +18,17 @@
<option value="19200">19200</option>
<option value="9600">9600</option>
</select>
&nbsp; Fmt: 8N1
&nbsp; Fmt:
<select id="fmt-sel" class="pure-button" href="#">
<option value="8N1">8N1</option>
<option value="8E1">8E1</option>
<option value="8N2">8N2</option>
<option value="8E2">8E2</option>
<option value="7N1">7N1</option>
<option value="7E1">7E1</option>
<option value="7N2">7N2</option>
<option value="7E2">7E2</option>
</select>
</p>
<div class="pure-g">
<div class="pure-u-1-4"><legend><b>Console</b></legend></div>
@ -93,6 +103,20 @@
);
});
ajaxJson('GET', "/console/fmt",
function(data) { $("#fmt-sel").value = data.fmt; },
function(s, st) { showNotification(st); }
);
bnd($("#fmt-sel"), "change", function(ev) {
ev.preventDefault();
var fmt = $("#fmt-sel").value;
ajaxSpin('POST', "/console/fmt?fmt="+fmt,
function(resp) { showNotification("" + fmt + " format set"); },
function(s, st) { showWarning("Error setting format: " + st); }
);
});
consoleSendInit();
addClass($('html')[0], "height100");

@ -80,6 +80,38 @@ ajaxConsoleBaud(HttpdConnData *connData) {
httpdSend(connData, buff, -1);
return HTTPD_CGI_DONE;
}
int ICACHE_FLASH_ATTR
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);
status = configSave() ? 200 : 400;
} else if (connData->requestType == HTTPD_METHOD_GET) {
status = 200;
}
jsonHeader(connData, status);
os_sprintf(buff, "{\"fmt\": \"%c%c%c\"}",
flashConfig.data_bits + '5',
flashConfig.parity ? 'E' : 'N',
flashConfig.stop_bits ? '2': '1');
httpdSend(connData, buff, -1);
return HTTPD_CGI_DONE;
}
int ICACHE_FLASH_ATTR
ajaxConsoleSend(HttpdConnData *connData) {

@ -8,6 +8,7 @@ void ICACHE_FLASH_ATTR console_write_char(char c);
int ajaxConsole(HttpdConnData *connData);
int ajaxConsoleReset(HttpdConnData *connData);
int ajaxConsoleBaud(HttpdConnData *connData);
int ajaxConsoleFormat(HttpdConnData *connData);
int ajaxConsoleSend(HttpdConnData *connData);
int tplConsole(HttpdConnData *connData, char *token, void **arg);

@ -44,8 +44,8 @@ static void uart0_rx_intr_handler(void *para);
* Parameters : uart_no, use UART0 or UART1 defined ahead
* Returns : NONE
*******************************************************************************/
static void ICACHE_FLASH_ATTR
uart_config(uint8 uart_no)
void ICACHE_FLASH_ATTR
uart_config(uint8 uart_no, UartBautRate baudrate, uint32 conf0)
{
if (uart_no == UART1) {
PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO2_U, FUNC_U1TXD_BK);
@ -59,14 +59,11 @@ uart_config(uint8 uart_no)
//PIN_PULLUP_DIS (PERIPHS_IO_MUX_U0RXD_U);
}
uart_div_modify(uart_no, UART_CLK_FREQ / UartDev.baut_rate);
uart_div_modify(uart_no, UART_CLK_FREQ / baudrate);
if (uart_no == UART1) //UART 1 always 8 N 1
WRITE_PERI_REG(UART_CONF0(uart_no),
CALC_UARTMODE(EIGHT_BITS, NONE_BITS, ONE_STOP_BIT));
else
WRITE_PERI_REG(UART_CONF0(uart_no),
CALC_UARTMODE(UartDev.data_bits, UartDev.parity, UartDev.stop_bits));
conf0 = CALC_UARTMODE(EIGHT_BITS, NONE_BITS, ONE_STOP_BIT);
WRITE_PERI_REG(UART_CONF0(uart_no), conf0);
//clear rx and tx fifo,not ready
SET_PERI_REG_MASK(UART_CONF0(uart_no), UART_RXFIFO_RST | UART_TXFIFO_RST);
@ -267,13 +264,11 @@ uart0_baud(int rate) {
* Returns : NONE
*******************************************************************************/
void ICACHE_FLASH_ATTR
uart_init(UartBautRate uart0_br, UartBautRate uart1_br)
uart_init(uint32 conf0, UartBautRate uart0_br, UartBautRate uart1_br)
{
// rom use 74880 baut_rate, here reinitialize
UartDev.baut_rate = uart0_br;
uart_config(UART0);
UartDev.baut_rate = uart1_br;
uart_config(UART1);
uart_config(UART0, uart0_br, conf0);
uart_config(UART1, uart1_br, conf0);
for (int i=0; i<4; i++) uart_tx_one_char(UART1, '\n');
for (int i=0; i<4; i++) uart_tx_one_char(UART0, '\n');
ETS_UART_INTR_ENABLE();
@ -295,10 +290,3 @@ uart_add_recv_cb(UartRecv_cb cb) {
os_printf("UART: max cb count exceeded\n");
}
void ICACHE_FLASH_ATTR
uart_reattach()
{
uart_init(BIT_RATE_74880, BIT_RATE_74880);
// ETS_UART_INTR_ATTACH(uart_rx_intr_handler_ssc, &(UartDev.rcv_buff));
// ETS_UART_INTR_ENABLE();
}

@ -8,7 +8,7 @@ typedef void (*UartRecv_cb)(char *buf, short len);
// Initialize UARTs to the provided baud rates (115200 recommended). This also makes the os_printf
// calls use uart1 for output (for debugging purposes)
void uart_init(UartBautRate uart0_br, UartBautRate uart1_br);
void uart_init(uint32 conf0, UartBautRate uart0_br, UartBautRate uart1_br);
// Transmit a buffer of characters on UART0
void uart0_tx_buffer(char *buf, uint16 len);
@ -27,5 +27,6 @@ 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 uart_config(uint8 uart_no, UartBautRate baudrate, uint32 conf0);
#endif /* __UART_H__ */

Loading…
Cancel
Save