From e59bb17eaa7d1a590a830e619c3c36a3289aa14e Mon Sep 17 00:00:00 2001 From: sorgelig Date: Wed, 22 Apr 2020 22:59:14 +0800 Subject: [PATCH] Update UART settings. --- menu.cpp | 15 +++++---------- support/st/st_tos.cpp | 9 +++++++++ support/st/st_tos.h | 2 ++ user_io.cpp | 19 +++++++++++++------ user_io.h | 1 + 5 files changed, 30 insertions(+), 16 deletions(-) diff --git a/menu.cpp b/menu.cpp index a9b0819..f1d3a80 100644 --- a/menu.cpp +++ b/menu.cpp @@ -2239,8 +2239,7 @@ void HandleUI(void) uint mode = GetUARTMode() + 1; if (mode > sizeof(config_uart_msg) / sizeof(config_uart_msg[0])) mode = 0; - sprintf(s, "uartmode %d", mode); - system(s); + SetUARTMode(mode); menustate = MENU_UART1; } break; @@ -2251,10 +2250,8 @@ void HandleUI(void) { int mode = GetUARTMode(); SetMidiLinkMode(GetMidiLinkMode() ^ ((menusub == 1) ? 2 : 1)); - sprintf(s, "uartmode %d", 0); - system(s); - sprintf(s, "uartmode %d", mode); - system(s); + SetUARTMode(0); + SetUARTMode(mode); menustate = MENU_UART1; } break; @@ -2263,10 +2260,8 @@ void HandleUI(void) int mode = GetUARTMode(); if(mode != 0) { - sprintf(s, "uartmode %d", 0); - system(s); - sprintf(s, "uartmode %d", mode); - system(s); + SetUARTMode(0); + SetUARTMode(mode); menustate = MENU_8BIT_SYSTEM1; } } diff --git a/support/st/st_tos.cpp b/support/st/st_tos.cpp index 1f51f4f..35e5e5e 100644 --- a/support/st/st_tos.cpp +++ b/support/st/st_tos.cpp @@ -55,8 +55,11 @@ static const char *acsi_cmd_name(int cmd) { return cmdname[cmd]; } +static int uart_mode = 0; static void set_control(uint32_t ctrl) { + ctrl = uart_mode ? (ctrl | TOS_CONTROL_REDIR0) : (ctrl & ~TOS_CONTROL_REDIR0); + spi_uio_cmd_cont(UIO_SET_STATUS2); spi32w(ctrl); DisableIO(); @@ -73,6 +76,12 @@ unsigned long tos_system_ctrl() return config.system_ctrl; } +void tos_uart_mode(int enable) +{ + uart_mode = enable; + set_control(config.system_ctrl); +} + static void memory_read(uint8_t *data, uint32_t words) { EnableIO(); diff --git a/support/st/st_tos.h b/support/st/st_tos.h index 5d4da4e..c4483f6 100644 --- a/support/st/st_tos.h +++ b/support/st/st_tos.h @@ -92,4 +92,6 @@ void tos_config_load(int slot); // slot -1 == last config void tos_config_save(int slot); int tos_config_exists(int slot); +void tos_uart_mode(int enable); + #endif diff --git a/user_io.cpp b/user_io.cpp index 3b65582..07a642d 100644 --- a/user_io.cpp +++ b/user_io.cpp @@ -556,6 +556,17 @@ int GetUARTMode() return 0; } +int SetUARTMode(int mode) +{ + if (is_st()) tos_uart_mode(mode != 3); + MakeFile("/tmp/CORENAME", user_io_get_core_name_ex()); + MakeFile("/tmp/UART_SPEED", is_st() ? "19200" : "115200"); + + char cmd[32]; + sprintf(cmd, "uartmode %d", mode & 0xFF); + system(cmd); +} + int GetMidiLinkMode() { struct stat filestat; @@ -568,7 +579,6 @@ int GetMidiLinkMode() void SetMidiLinkMode(int mode) { - MakeFile("/tmp/CORENAME", user_io_get_core_name_ex()); remove("/tmp/ML_FSYNTH"); remove("/tmp/ML_MUNT"); remove("/tmp/ML_UDP"); @@ -932,12 +942,9 @@ void user_io_init(const char *path, const char *xml) FileLoadConfig(mainpath, &mode, 4); } - char cmd[32]; - system("uartmode 0"); - + SetUARTMode(0); SetMidiLinkMode((mode >> 8) & 0xFF); - sprintf(cmd, "uartmode %d", mode & 0xFF); - system(cmd); + SetUARTMode(mode); } static int joyswap = 0; diff --git a/user_io.h b/user_io.h index 0ccb795..d7a5040 100644 --- a/user_io.h +++ b/user_io.h @@ -243,6 +243,7 @@ int user_io_is_dualsdr(); uint16_t altcfg(int alt = -1); int GetUARTMode(); +int SetUARTMode(int mode); int GetMidiLinkMode(); void SetMidiLinkMode(int mode);