Update UART settings.

This commit is contained in:
sorgelig
2020-04-22 22:59:14 +08:00
parent 72d8831068
commit e59bb17eaa
5 changed files with 30 additions and 16 deletions

View File

@@ -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;
}
}

View File

@@ -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();

View File

@@ -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

View File

@@ -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;

View File

@@ -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);