From b961a0308962f2ef916ee255df976566943e34ab Mon Sep 17 00:00:00 2001 From: sorgelig Date: Sat, 7 Apr 2018 07:14:21 +0800 Subject: [PATCH] Add UART settings. --- menu.cpp | 55 +++++++++++++++++++++++++++++++++++++++++++---------- user_io.cpp | 24 ++++++++++++++++++++++- user_io.h | 14 +++++++++++++- 3 files changed, 81 insertions(+), 12 deletions(-) diff --git a/menu.cpp b/menu.cpp index 4ffdb85..764dfec 100644 --- a/menu.cpp +++ b/menu.cpp @@ -32,6 +32,7 @@ along with this program. If not, see . #include #include #include +#include #include "stdio.h" #include "string.h" #include "file_io.h" @@ -171,6 +172,7 @@ const char *config_button_turbo_msg[] = { "OFF", "FAST", "MEDIUM", "SLOW" }; const char *config_button_turbo_choice_msg[] = { "A only", "B only", "A & B" }; const char *joy_button_map[] = { "RIGHT", "LEFT", "DOWN", "UP", "BUTTON 1", "BUTTON 2", "BUTTON 3", "BUTTON 4", "KBD TOGGLE", "BUTTON OSD" }; const char *config_stereo_msg[] = { "0%", "25%", "50%", "100%" }; +const char *config_uart_msg[] = { " None", " PPP", "Console" }; char joy_bnames[12][32]; int joy_bcount = 0; @@ -1239,22 +1241,41 @@ void HandleUI(void) case MENU_8BIT_SYSTEM1: OsdSetSize(16); helptext = helptexts[HELPTEXT_MAIN]; - reboot_req = 0; - m = 0; menumask = 0xfb; + reboot_req = 0; + + OsdSetTitle("System", OSD_ARROW_LEFT); + menustate = MENU_8BIT_SYSTEM2; + parentstate = MENU_8BIT_SYSTEM1; + + s[0] = 0; + m = 0; + if(user_io_get_uart_mode()) + { + int mode = 0; + struct stat filestat; + if (!stat("/tmp/uartmode1", &filestat)) mode = 1; + if (!stat("/tmp/uartmode2", &filestat)) mode = 2; + + menumask |= 4; + sprintf(s, " UART connection %s", config_uart_msg[mode]); + OsdWrite(2, s, menusub == 2, 0); + } + else + { + OsdWrite(m++, "", 0, 0); + } + + OsdWrite(m++, " Core \x16", menusub == 0, 0); + OsdWrite(m++, " Define joystick buttons \x16", menusub == 1, 0); + OsdWrite(3, "", 0, 0); + + m = 0; if (user_io_core_type() == CORE_TYPE_MINIMIG2) { m = 1; menumask &= ~0x10; } - - OsdSetTitle("System", OSD_ARROW_LEFT); - menustate = MENU_8BIT_SYSTEM2; - parentstate = MENU_8BIT_SYSTEM1; - OsdWrite(0, "", 0, 0); - OsdWrite(1, " Core \x16", menusub == 0, 0); - OsdWrite(2, " Define joystick buttons \x16", menusub == 1, 0); - OsdWrite(3, "", 0, 0); OsdWrite(4, m ? " Reset the core" : " Reset settings", menusub == 3, user_io_core_type() == CORE_TYPE_ARCHIE); OsdWrite(5, m ? "" : " Save settings", menusub == 4, 0); OsdWrite(6, "", 0, 0); @@ -1292,6 +1313,20 @@ void HandleUI(void) menusub = 0; break; case 2: + { + int mode = 0; + struct stat filestat; + if (!stat("/tmp/uartmode1", &filestat)) mode = 1; + if (!stat("/tmp/uartmode2", &filestat)) mode = 2; + mode++; + if (mode > 3) mode = 0; + sprintf(s, "uartmode %d", mode); + system(s); + menustate = MENU_8BIT_SYSTEM1; + + sprintf(s, "uartmode.%s", user_io_get_core_name_ex()); + FileSaveConfig(s, &mode, 4); + } break; case 3: if (user_io_core_type() != CORE_TYPE_ARCHIE) diff --git a/user_io.cpp b/user_io.cpp index 9e95db5..1717716 100644 --- a/user_io.cpp +++ b/user_io.cpp @@ -63,6 +63,12 @@ bool caps_status = 0; bool num_status = 0; bool scrl_status = 0; +static uint32_t uart_mode; +uint32_t user_io_get_uart_mode() +{ + return uart_mode; +} + // set by OSD code to suppress forwarding of those keys to the core which // may be in use by an active OSD static char osd_is_visible = 0; @@ -280,7 +286,7 @@ static void parse_config() //MSM6242B layout void send_rtc(int type) { - printf("Update RTC\n"); + //printf("Update RTC\n"); time_t t = time(NULL); @@ -467,6 +473,22 @@ void user_io_init() user_io_8bit_set_status(0, UIO_STATUS_RESET); break; } + + spi_uio_cmd_cont(UIO_GETUARTFLG); + uart_mode = spi_w(0); + DisableIO(); + + uint32_t mode = 0; + if (uart_mode) + { + sprintf(mainpath, "uartmode.%s", user_io_get_core_name_ex()); + FileLoadConfig(mainpath, &mode, 4); + if (mode > 3) mode = 0; + } + + char cmd[32]; + sprintf(cmd, "uartmode %d", mode); + system(cmd); } void user_io_analog_joystick(unsigned char joystick, char valueX, char valueY) diff --git a/user_io.h b/user_io.h index 144a6ea..49d9fb9 100644 --- a/user_io.h +++ b/user_io.h @@ -60,6 +60,7 @@ #define UIO_LEDS 0x25 // control on-board LEDs #define UIO_AUDVOL 0x26 // Digital volume as a number of bits to shift to the right #define UIO_SETHEIGHT 0x27 // Set scaled vertical resolution (to reduce scaling artefacts) +#define UIO_GETUARTFLG 0x28 // Get UART_FLG_* // codes as used by 8bit for file loading from OSD #define UIO_FILE_TX 0x53 @@ -110,7 +111,6 @@ #define KBD_LED_FLAG_MASK 0xC0 #define KBD_LED_FLAG_STATUS 0x40 - #define BUTTON1 0b00000001 #define BUTTON2 0b00000010 #define CONF_VGA_SCALER 0b00000100 @@ -130,6 +130,17 @@ #define CORE_TYPE_MINIMIG2 0xa5 // new Minimig with AGA #define CORE_TYPE_ARCHIE 0xa6 // Acorn Archimedes +#define UART_FLG_PPP 0x0001 +#define UART_FLG_TERM 0x0002 +#define UART_FLG_RTSCTS 0x0004 +#define UART_FLG_DTRDSR 0x0008 +#define UART_FLG_DSRDCD 0x0010 +#define UART_FLG_9600 0x0100 +#define UART_FLG_19200 0x0200 +#define UART_FLG_38400 0x0400 +#define UART_FLG_57600 0x0800 +#define UART_FLG_115200 0x1000 + // user io status bits (currently only used by 8bit) #define UIO_STATUS_RESET 0x01 @@ -184,6 +195,7 @@ char is_x86_core(); char has_menu(); int user_io_get_kbdemu(); +uint32_t user_io_get_uart_mode(); // io controllers interface for FPGA ethernet emulation using usb ethernet // devices attached to the io controller (ethernec emulation)