From dcd659e5eaf09888af73cd6cd039a863337055af Mon Sep 17 00:00:00 2001 From: bogd Date: Mon, 26 Aug 2024 16:10:21 +0200 Subject: [PATCH] added serial port settings --- include/SysConfiguration.h | 3 +++ src/RestApiHandler.c | 5 +++++ src/SerialPort.c | 13 +++++++++++-- src/SysConfiguration.c | 4 ++++ 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/include/SysConfiguration.h b/include/SysConfiguration.h index 8eca5fc..4e87ae1 100644 --- a/include/SysConfiguration.h +++ b/include/SysConfiguration.h @@ -204,6 +204,9 @@ typedef struct { int Serialmode; int BaudRate; + int DataBits; + int Parity; + int StopBits; int InputBrake; struct { diff --git a/src/RestApiHandler.c b/src/RestApiHandler.c index 763ecd1..deec7df 100644 --- a/src/RestApiHandler.c +++ b/src/RestApiHandler.c @@ -551,6 +551,11 @@ const rest_var_t SystemVariables[] = { 0, "serial_bridge", &SysConfig.serialSettings.Flags.IsBridgeEnabled, VAR_BOOL, RW, 0, 1 }, { 0, "serial_mode", &funct_serial_mode, VAR_FUNCT, R, 1, 2 }, { 0, "serial_baud", &SysConfig.serialSettings.BaudRate, VAR_INT, RW, 1200, 4096000 }, + + { 0, "serial_bits", &SysConfig.serialSettings.DataBits, VAR_INT, RW, 0, 3 }, + { 0, "serial_parity", &SysConfig.serialSettings.Parity, VAR_INT, RW, 0, 3 }, + { 0, "serial_stop", &SysConfig.serialSettings.StopBits, VAR_INT, RW, 1, 3 }, + { 0, "serial_break", &SysConfig.serialSettings.InputBrake, VAR_INT, RW, 1, 50 }, { 0, "serial_visible", (bool*) (&VAR_TRUE), VAR_BOOL, R, 0, 1 }, #else diff --git a/src/SerialPort.c b/src/SerialPort.c index a9e74ad..dfe662a 100644 --- a/src/SerialPort.c +++ b/src/SerialPort.c @@ -231,13 +231,22 @@ void InitSerialPort(void) { uart_config_t uart_config = { .baud_rate = GetSysConf()->serialSettings.BaudRate, - .data_bits = UART_DATA_8_BITS, - .parity = UART_PARITY_DISABLE, + .data_bits = UART_DATA_7_BITS, + .parity = UART_PARITY_EVEN, .stop_bits = UART_STOP_BITS_1, .flow_ctrl = UART_HW_FLOWCTRL_DISABLE, .source_clk = UART_SCLK_APB, }; + //uart_config.data_bits = (uint8_t) GetSysConf()->serialSettings.DataBits; + //uart_config.parity = (uint8_t) GetSysConf()->serialSettings.Parity; + //uart_config.stop_bits = (uint8_t) GetSysConf()->serialSettings.StopBits; + + ESP_LOGI(TAG, "UART data_bits:%d parity:%d stop_bits:%d", + GetSysConf()->serialSettings.DataBits, + GetSysConf()->serialSettings.Parity, + GetSysConf()->serialSettings.StopBits); + ESP_ERROR_CHECK( uart_driver_install(CONFIG_WEBGUIAPP_UART_PORT_NUM, CONFIG_WEBGUIAPP_UART_BUF_SIZE * 2, 0, 20, &uart_event_queue, 0)); ESP_ERROR_CHECK(uart_param_config(CONFIG_WEBGUIAPP_UART_PORT_NUM, &uart_config)); diff --git a/src/SysConfiguration.c b/src/SysConfiguration.c index 02ca2d2..0533fef 100644 --- a/src/SysConfiguration.c +++ b/src/SysConfiguration.c @@ -33,6 +33,7 @@ #include "driver/gpio.h" #include "driver/adc.h" #include "driver/i2c.h" +#include #include "romfs.h" #include "spifs.h" @@ -425,6 +426,9 @@ esp_netif_str_to_ip4(CONFIG_WEBGUIAPP_DNS3_ADDRESS_DEFAULT, (esp_ip4_addr_t*) &C #endif Conf->serialSettings.Serialmode = 1; Conf->serialSettings.BaudRate = CONFIG_WEBGUIAPP_UART_BAUD_RATE; + Conf->serialSettings.DataBits = UART_DATA_8_BITS; + Conf->serialSettings.Parity = UART_PARITY_DISABLE; + Conf->serialSettings.StopBits = UART_STOP_BITS_1; Conf->serialSettings.InputBrake = 50; #endif