diff --git a/boards/Kconfig.user b/boards/Kconfig.user index acd58be..b09359d 100644 --- a/boards/Kconfig.user +++ b/boards/Kconfig.user @@ -123,6 +123,18 @@ config EXT_OLED_BRIGHTNESS config EXT_THINGSET_SERIAL bool "ThingSet serial interface" +config EXT_THINGSET_SERIAL_RX_BUF_SIZE + depends on EXT_THINGSET_SERIAL + int "ThingSet serial RX buffer size" + range 64 2048 + default 512 + +config EXT_THINGSET_SERIAL_TX_BUF_SIZE + depends on EXT_THINGSET_SERIAL + int "ThingSet serial TX buffer size" + range 256 2048 + default 1024 + config EXT_THINGSET_CAN depends on CAN bool "ThingSet CAN interface" diff --git a/src/config.h_template b/src/config.h_template index 3b3ae9f..42baf47 100644 --- a/src/config.h_template +++ b/src/config.h_template @@ -44,13 +44,13 @@ //#define CUSTOM_DATA_OBJECTS_FILE // OLED display at UEXT port -//#define OLED_ENABLED +#define CONFIG_EXT_OLED_DISPLAY 1 // OLED Brightness (value 0x01-0xff or 1-255) // leave undefined to use default -//#define OLED_BRIGHTNESS 0x1 +#define OLED_BRIGHTNESS 0x1 // UART serial at SWD connector -#define UART_SERIAL_ENABLED +#define CONFIG_EXT_THINGSET_SERIAL 1 // CAN bus drivers (not supported by all charge controllers) //#define CAN_ENABLED diff --git a/src/ext/oled.cpp b/src/ext/oled.cpp index 0ba3b7a..000088c 100644 --- a/src/ext/oled.cpp +++ b/src/ext/oled.cpp @@ -8,7 +8,7 @@ #include "config.h" -#ifdef OLED_ENABLED // otherwise don't compile code to reduce firmware size +#if CONFIG_EXT_OLED_DISPLAY // otherwise don't compile code to reduce firmware size #include #include @@ -198,6 +198,6 @@ void ExtOled::process_1s() oled.display(); } -#endif /* OLED_ENABLED */ +#endif /* CONFIG_EXT_OLED_DISPLAY */ #endif /* UNIT_TEST */ diff --git a/src/ext/serial.cpp b/src/ext/serial.cpp index 23748d2..06e72ba 100644 --- a/src/ext/serial.cpp +++ b/src/ext/serial.cpp @@ -7,10 +7,19 @@ #ifndef UNIT_TEST #include "config.h" + +#if CONFIG_EXT_THINGSET_SERIAL // otherwise don't compile code to reduce firmware size + #include "thingset.h" #include "ext.h" -#define SIZE_BUF_REQ 500 +#ifdef __ZEPHYR__ +#define TX_BUF_SIZE CONFIG_EXT_THINGSET_SERIAL_TX_BUF_SIZE +#define RX_BUF_SIZE CONFIG_EXT_THINGSET_SERIAL_RX_BUF_SIZE +#else +#define TX_BUF_SIZE 1000 +#define RX_BUF_SIZE 500 +#endif #ifdef __MBED__ @@ -27,8 +36,6 @@ #define UART_DEVICE_NAME DT_ALIAS_UART_DBG_LABEL struct device *uart_dev = device_get_binding(UART_DEVICE_NAME); -static unsigned char new_line[] = "\n"; - #endif /* MBED or ZEPHYR */ class ThingSetStream: public ExtInterface @@ -89,8 +96,8 @@ class ThingSetStream: public ExtInterface Stream* stream; #endif /* MBED */ - char buf_resp[1000]; - char buf_req[SIZE_BUF_REQ]; + char buf_resp[TX_BUF_SIZE]; + char buf_req[RX_BUF_SIZE]; size_t req_pos = 0; bool command_flag = false; }; @@ -141,7 +148,7 @@ class ThingSetSerial: public ThingSetStream * for later processing in the normal operation */ -#ifdef UART_SERIAL_ENABLED +#ifdef CONFIG_EXT_THINGSET_SERIAL extern const int pub_channel_serial; #ifdef __MBED__ extern Serial serial; @@ -151,9 +158,7 @@ class ThingSetSerial: public ThingSetStream ThingSetSerial ts_uart(pub_channel_serial); #endif /* MBED or ZEPHYR */ -#endif /* UART_SERIAL_ENABLED */ - -// ToDo: Add USB serial again (previous library was broken with recent mbed releases) +#endif /* CONFIG_EXT_THINGSET_SERIAL */ extern ThingSet ts; @@ -170,7 +175,7 @@ void ThingSetStream::process_1s() for (int i = 0; i < len; i++) { uart_poll_out(uart_dev, buf_resp[i]); } - uart_poll_out(uart_dev, new_line[0]); + uart_poll_out(uart_dev, '\n'); #endif /* MBED or ZREPHYR */ } @@ -194,7 +199,7 @@ void ThingSetStream::process_asap() for (int i = 0; i < len; i++) { uart_poll_out(uart_dev, buf_resp[i]); } - uart_poll_out(uart_dev, new_line[0]); + uart_poll_out(uart_dev, '\n'); #endif /* MBED or ZEPHYR */ } @@ -252,7 +257,7 @@ void ThingSetStream::process_input(void* user_data) // more read characters are simply dropped, unless it is \n // which ends the command input and triggers processing // else if (req_pos < (sizeof(buf_req)-1)) { - else if (req_pos < (SIZE_BUF_REQ-1)) { + else if (req_pos < (RX_BUF_SIZE-1)) { buf_req[req_pos++] = c; } @@ -262,4 +267,7 @@ void ThingSetStream::process_input(void* user_data) #endif } } + +#endif /* CONFIG_EXT_THINGSET_SERIAL */ + #endif /* UNIT_TEST */ diff --git a/zephyr/CMakeLists.txt b/zephyr/CMakeLists.txt index 9bfa5c5..a925c3c 100644 --- a/zephyr/CMakeLists.txt +++ b/zephyr/CMakeLists.txt @@ -30,6 +30,7 @@ target_sources(app PRIVATE ../src/power_port.cpp) target_sources(app PRIVATE ../src/pwm_switch.cpp) target_sources(app PRIVATE ../src/ext/ext.cpp) target_sources(app PRIVATE ../src/ext/oled.cpp) +target_sources(app PRIVATE ../src/ext/serial.cpp) add_subdirectory(../lib/thingset build/thingset) add_subdirectory(../lib/oled-display build/oled-display) diff --git a/zephyr/prj.conf b/zephyr/prj.conf index bb00c1a..da21e89 100644 --- a/zephyr/prj.conf +++ b/zephyr/prj.conf @@ -12,15 +12,8 @@ CONFIG_I2C_1=y CONFIG_ADC=y CONFIG_ADC_1=y -# for OLED display -#CONFIG_DISPLAY=y -#CONFIG_SSD1306=y - CONFIG_LOG=y -#CONFIG_CFB_LOG_LEVEL_DBG=y -#CONFIG_CHARACTER_FRAMEBUFFER=y - #CONFIG_NEWLIB_LIBC_NANO=y CONFIG_NEWLIB_LIBC=y CONFIG_NEWLIB_LIBC_FLOAT_PRINTF=y @@ -31,3 +24,9 @@ CONFIG_CONSOLE_GETCHAR=y CONFIG_CPLUSPLUS=y CONFIG_BUILD_OUTPUT_BIN=y + +# ThingSet protocol interface at UART serial +CONFIG_EXT_THINGSET_SERIAL=y + +# I2C OLED display in UEXT connector +#CONFIG_EXT_OLED_DISPLAY=y