diff --git a/cdc_control.c b/cdc_control.c index ce69bcb..16885d1 100644 --- a/cdc_control.c +++ b/cdc_control.c @@ -10,13 +10,6 @@ #include "tos.h" #include "debug.h" -// if cdc itself is to be debugged the debug output cannot be redirected to USB -#ifndef CDC_DEBUG -char cdc_control_debug = 0; -#endif - -char cdc_control_redirect = 0; - static char buffer[32]; static unsigned char fill = 0; static unsigned long flush_timer = 0; @@ -73,10 +66,13 @@ void cdc_control_poll(void) { // check for user input if(usb_cdc_read(&key, 1)) { - - if(cdc_control_redirect == CDC_REDIRECT_RS232) + + switch(tos_get_cdc_control_redirect()) { + case CDC_REDIRECT_RS232: user_io_serial_tx(key); - else { + break; + + case CDC_REDIRECT_CONTROL: // force lower case if((key >= 'A') && (key <= 'Z')) key = key - 'A' + 'a'; @@ -88,11 +84,10 @@ void cdc_control_poll(void) { cdc_puts("Commands:"); cdc_puts("\033[7mR\033[0meset"); cdc_puts("\033[7mC\033[0moldreset"); -#ifndef CDC_DEBUG - cdc_puts("\033[7mD\033[0mebug"); -#endif + cdc_puts("\033[7mD\033[0mebug output redirect"); cdc_puts("R\033[7mS\033[0m232 redirect"); cdc_puts("\033[7mP\033[0marallel redirect"); + cdc_puts("\033[7mM\033[0mIDI redirect"); cdc_puts(""); break; @@ -101,28 +96,36 @@ void cdc_control_poll(void) { tos_reset(0); break; - case 'c': - cdc_puts("Coldreset ..."); - tos_reset(1); - break; - -#ifndef CDC_DEBUG - case 'd': - cdc_puts("Debug enabled"); - cdc_control_debug = 1; + case 'c': + cdc_puts("Coldreset ..."); + tos_reset(1); + break; + + case 'd': + cdc_puts("Debug output redirect enabled"); + tos_set_cdc_control_redirect(CDC_REDIRECT_DEBUG); break; -#endif case 's': cdc_puts("RS232 redirect enabled"); - cdc_control_redirect = CDC_REDIRECT_RS232; + tos_set_cdc_control_redirect(CDC_REDIRECT_RS232); break; - + case 'p': cdc_puts("Parallel redirect enabled"); - cdc_control_redirect = CDC_REDIRECT_PARALLEL; + tos_set_cdc_control_redirect(CDC_REDIRECT_PARALLEL); break; + + case 'm': + cdc_puts("MIDI redirect enabled"); + tos_set_cdc_control_redirect(CDC_REDIRECT_MIDI); + break; + } + break; + + default: + break; } } } diff --git a/cdc_control.h b/cdc_control.h index b5377e5..1e9d635 100644 --- a/cdc_control.h +++ b/cdc_control.h @@ -1,11 +1,12 @@ #ifndef CDC_CONTROL_H #define CDC_CONTROL_H -extern char cdc_control_debug; -extern char cdc_control_redirect; - -#define CDC_REDIRECT_RS232 0x01 -#define CDC_REDIRECT_PARALLEL 0x02 +#define CDC_REDIRECT_NONE 0x00 +#define CDC_REDIRECT_CONTROL 0x01 +#define CDC_REDIRECT_DEBUG 0x02 +#define CDC_REDIRECT_RS232 0x03 +#define CDC_REDIRECT_PARALLEL 0x04 +#define CDC_REDIRECT_MIDI 0x05 void cdc_control_open(void); void cdc_control_poll(void); diff --git a/cdc_enumerate.c b/cdc_enumerate.c index 9c9d931..9b4af85 100644 --- a/cdc_enumerate.c +++ b/cdc_enumerate.c @@ -201,8 +201,8 @@ AT91S_CDC_LINE_CODING line = { static void AT91F_CDC_Enumerate(void); static void tx(char c) { - while(!(AT91C_BASE_US0->US_CSR & AT91C_US_TXRDY)); - AT91C_BASE_US0->US_THR = c; + // while(!(AT91C_BASE_US0->US_CSR & AT91C_US_TXRDY)); + // AT91C_BASE_US0->US_THR = c; } static void tx_str(char *str) { @@ -477,7 +477,6 @@ static void AT91F_CDC_Enumerate(void) { // Handle supported standard device request Cf Table 9-3 in USB specification Rev 1.1 switch ((bRequest << 8) | bmRequestType) { case STD_GET_DESCRIPTOR: - cdc_debugf("get descriptor %x (%d)", wValue, wLength); if (wValue == 0x100) // Return Device Descriptor AT91F_USB_SendData(devDescriptor, MIN(sizeof(devDescriptor), wLength)); else if (wValue == 0x200) // Return Configuration Descriptor diff --git a/debug.h b/debug.h index c614ba1..3e919df 100644 --- a/debug.h +++ b/debug.h @@ -40,14 +40,6 @@ #define ikbd_debugf(...) #endif -#if 0 -// cdc debug output in blue -#define CDC_DEBUG -#define cdc_debugf(a, ...) iprintf("\033[1;34mCDC: " a "\033[0m\n", ##__VA_ARGS__) -#else -#define cdc_debugf(...) -#endif - #if 1 // 8bit debug output in blue #define bit8_debugf(a, ...) iprintf("\033[1;34m8BIT: " a "\033[0m\n", ##__VA_ARGS__) diff --git a/hardware.c b/hardware.c index c40eb8f..f06096e 100644 --- a/hardware.c +++ b/hardware.c @@ -156,7 +156,6 @@ void USART_Write(unsigned char c) { if((AT91C_BASE_US0->US_CSR & AT91C_US_TXRDY) && (tx_wptr == tx_rptr)) { // transmitter ready and buffer empty? -> send directly AT91C_BASE_US0->US_THR = c; - AT91C_BASE_US0->US_IER = AT91C_US_TXRDY; // enable interrupt } else { // transmitter is not ready: block until space in buffer while((unsigned char)(tx_wptr + 1) == tx_rptr); @@ -164,6 +163,8 @@ void USART_Write(unsigned char c) { // there's space in buffer: use it tx_buf[tx_wptr++] = c; } + + AT91C_BASE_US0->US_IER = AT91C_US_TXRDY; // enable interrupt } void USART_Init(unsigned long baudrate) { diff --git a/main.c b/main.c index e7ae202..1c96cec 100644 --- a/main.c +++ b/main.c @@ -149,6 +149,7 @@ int main(void) user_io_init(); + // tos config also contains cdc redirect settings used by minimig tos_config_init(); fpga_init(NULL); diff --git a/menu.c b/menu.c index 700e694..89ce30c 100644 --- a/menu.c +++ b/menu.c @@ -39,6 +39,7 @@ along with this program. If not, see . #include "menu.h" #include "user_io.h" #include "tos.h" +#include "cdc_control.h" #include "debug.h" // other constants @@ -72,6 +73,7 @@ extern const char version[]; const char *config_tos_mem[] = {"512 kB", "1 MB", "2 MB", "4 MB", "8 MB", "14 MB", "--", "--" }; const char *config_tos_wrprot[] = {"none", "A:", "B:", "A: and B:"}; +const char *config_tos_usb[] = {"none", "control", "debug", "serial", "parallel", "midi"}; const char *config_filter_msg[] = {"none", "HORIZONTAL", "VERTICAL", "H+V"}; const char *config_memory_chip_msg[] = {"0.5 MB", "1.0 MB", "1.5 MB", "2.0 MB"}; @@ -473,11 +475,7 @@ void HandleUI(void) break; case MENU_MIST_SYSTEM1 : -#ifdef ENABLE_TURBO menumask=0xff; -#else - menumask=0x7f; -#endif OsdSetTitle("System", 0); @@ -497,25 +495,14 @@ void HandleUI(void) strcat(s, tos_get_cartridge_name()); OsdWrite(3, s, menusub == 3, 0); -#ifdef ENABLE_TURBO - strcpy(s, " Turbo: "); - strcat(s, (tos_system_ctrl() & TOS_CONTROL_TURBO)?"on":"off"); + strcpy(s, " USB I/O: "); + strcat(s, config_tos_usb[tos_get_cdc_control_redirect()]); OsdWrite(4, s, menusub == 4, 0); OsdWrite(5, " Reset", menusub == 5, 0); OsdWrite(6, " Cold boot", menusub == 6, 0); OsdWrite(7, STD_EXIT, menusub == 7,0); -#else - strcpy(s, " Turbo: "); - strcat(s, (tos_system_ctrl() & TOS_CONTROL_TURBO)?"on":"off"); - OsdWrite(4, s, 0, 1); - - OsdWrite(5, " Reset", menusub == 4, 0); - OsdWrite(6, " Cold boot", menusub == 5, 0); - - OsdWrite(7, STD_EXIT, menusub == 6,0); -#endif parentstate = menustate; menustate = MENU_MIST_SYSTEM2; @@ -559,9 +546,11 @@ void HandleUI(void) SelectFile("IMG", SCAN_LFN, MENU_MIST_SYSTEM_FILE_SELECTED, MENU_MIST_SYSTEM1); break; -#ifdef ENABLE_TURBO case 4: - tos_update_sysctrl(tos_system_ctrl() ^ TOS_CONTROL_TURBO ); + if(tos_get_cdc_control_redirect() == CDC_REDIRECT_MIDI) + tos_set_cdc_control_redirect(CDC_REDIRECT_NONE); + else + tos_set_cdc_control_redirect(tos_get_cdc_control_redirect()+1); menustate = MENU_MIST_SYSTEM1; break; @@ -579,23 +568,6 @@ void HandleUI(void) menustate = MENU_MIST_MAIN1; menusub = 3; break; - -#else - case 4: // Reset - tos_reset(0); - menustate = MENU_NONE1; - break; - - case 5: // Cold Boot - tos_reset(1); - menustate = MENU_NONE1; - break; - - case 6: - menustate = MENU_MIST_MAIN1; - menusub = 3; - break; -#endif } } break; diff --git a/syscalls.c b/syscalls.c index aa678aa..7722ee6 100644 --- a/syscalls.c +++ b/syscalls.c @@ -18,6 +18,7 @@ #include "debug.h" #include "hardware.h" +#include "tos.h" #include "swi.h" #include "cdc_control.h" @@ -337,12 +338,10 @@ _swiwrite ( static void write_byte(char byte) { USART_Write(byte); -#ifndef CDC_DEBUG - if(cdc_control_debug) { + if(tos_get_cdc_control_redirect() == CDC_REDIRECT_DEBUG) { cdc_control_tx(byte); if(byte == '\n') cdc_control_flush(); } -#endif } int diff --git a/tos.c b/tos.c index 7bb3dec..52f669c 100644 --- a/tos.c +++ b/tos.c @@ -6,7 +6,9 @@ #include "tos.h" #include "fat.h" #include "fpga.h" +#include "cdc_control.h" #include "debug.h" + #define CONFIG_FILENAME "MIST CFG" typedef struct { @@ -15,6 +17,7 @@ typedef struct { char cart_img[12]; char acsi_img[2][12]; char video_adjust[2]; + char cdc_control_redirect; } tos_config_t; static tos_config_t config; @@ -53,6 +56,15 @@ static const char *acsi_cmd_name(int cmd) { return cmdname[cmd]; } +char tos_get_cdc_control_redirect(void) { + return config.cdc_control_redirect; +} + +void tos_set_cdc_control_redirect(char mode) { + if((mode >= CDC_REDIRECT_NONE) && (mode <= CDC_REDIRECT_MIDI)) + config.cdc_control_redirect = mode; +} + void tos_set_video_adjust(char axis, char value) { config.video_adjust[axis] += value; @@ -982,6 +994,7 @@ void tos_config_init(void) { memcpy(config.acsi_img[0], "HARDDISKHD ", 12); config.acsi_img[1][0] = 0; config.video_adjust[0] = config.video_adjust[1] = 0; + config.cdc_control_redirect = CDC_REDIRECT_NONE; // try to load config if (FileOpen(&file, CONFIG_FILENAME)) { diff --git a/tos.h b/tos.h index a728736..317e5e0 100644 --- a/tos.h +++ b/tos.h @@ -90,6 +90,9 @@ void tos_load_cartridge(char *); void tos_set_video_adjust(char axis, char value); char tos_get_video_adjust(char axis); +char tos_get_cdc_control_redirect(void); +void tos_set_cdc_control_redirect(char mode); + void tos_config_init(void); void tos_config_save(void); diff --git a/user_io.c b/user_io.c index 61ac067..0f05770 100644 --- a/user_io.c +++ b/user_io.c @@ -192,13 +192,13 @@ void user_io_poll() { putchar(c); // forward to USB if redirection via USB/CDC enabled - if(cdc_control_redirect == CDC_REDIRECT_RS232) + if(tos_get_cdc_control_redirect() == CDC_REDIRECT_RS232) cdc_control_tx(c); } DisableIO(); // check for incoming parallel data - if(cdc_control_redirect == CDC_REDIRECT_PARALLEL) { + if(tos_get_cdc_control_redirect() == CDC_REDIRECT_PARALLEL) { EnableIO(); SPI(UIO_PARALLEL_IN); // character 0xff is returned if FPGA isn't configured