From 02a396a4acbc33faa96e109d0008c0a4ae0e576d Mon Sep 17 00:00:00 2001 From: rasteri Date: Fri, 15 Nov 2024 13:41:11 +0000 Subject: [PATCH] debug output changes --- firmware/andyalloc.c | 2 +- firmware/linkedlist.c | 1 + firmware/main.c | 6 +-- firmware/menu.c | 95 ++++++++++++++++++++++-------------------- firmware/menu.h | 4 +- firmware/preset.c | 2 +- firmware/ps2protocol.c | 4 +- firmware/scancode.c | 4 +- firmware/settings.c | 11 +++-- firmware/settings.h | 3 ++ firmware/system.c | 17 ++++---- firmware/system.h | 32 +------------- firmware/test.c | 4 +- firmware/uart1.c | 43 ------------------- firmware/usbhost.c | 6 ++- 15 files changed, 85 insertions(+), 149 deletions(-) diff --git a/firmware/andyalloc.c b/firmware/andyalloc.c index 20155cf..608f485 100644 --- a/firmware/andyalloc.c +++ b/firmware/andyalloc.c @@ -31,7 +31,7 @@ void __xdata *andyalloc(size_t size) { // trigger a watchdog reset if we run out of memory if (MemoryFree() <= size) { - ANDYS_DEBUG_OUT("Memory Exhausted"); + DEBUGOUT("Memory Exhausted"); ET0 = 0; while (1); } diff --git a/firmware/linkedlist.c b/firmware/linkedlist.c index f148f0f..dda1a8b 100644 --- a/firmware/linkedlist.c +++ b/firmware/linkedlist.c @@ -5,6 +5,7 @@ can be used as a sparse array kinda based on https://www.geeksforgeeks.org/generic-linked-list-in-c-2/ */ + #include #include #include diff --git a/firmware/main.c b/firmware/main.c index 0e855ed..a0c2369 100644 --- a/firmware/main.c +++ b/firmware/main.c @@ -27,7 +27,7 @@ void EveryMillisecond(void) { SoftWatchdog++; if (SoftWatchdog > 5000) { // if soft watchdog overflows, just go into an infinite loop and we'll trigger the real watchdog - ANDYS_DEBUG_OUT("Soft overflow\n"); + DEBUGOUT("Soft overflow\n"); while(1); } @@ -223,7 +223,7 @@ int main(void) memset(SendBuffer, 0, 255); memset(MouseBuffer, 0, MOUSE_BUFFER_SIZE); - if (WatchdogReset) DEBUG_OUT("Watchdog reset detected (%x), entering safemode\n", PCON); + if (WatchdogReset) DEBUGOUT("Watchdog reset detected (%x), entering safemode\n", PCON); InitSettings(WatchdogReset); @@ -239,7 +239,7 @@ int main(void) OutputsEnabled = 1; - ANDYS_DEBUG_OUT("ok\n"); + DEBUGOUT("ok\n"); // main loop while (1) diff --git a/firmware/menu.c b/firmware/menu.c index 149ed8d..e3fd5ef 100644 --- a/firmware/menu.c +++ b/firmware/menu.c @@ -24,7 +24,6 @@ __xdata char SendBuffer[255]; -bool SerialDebugOutput = 1; bool KeyboardDebugOutput = 0; __xdata bool MenuActive = 0; @@ -115,7 +114,7 @@ void Menu_Task(void) case MENU_STATE_MAIN: if (lastMenuState != MENU_STATE_MAIN) { - SendKeyboardString("\n\nHIDman v1.1.4beta3\n\n"); + SendKeyboardString("\n\nHIDman v1.1.4\n\n"); SendKeyboardString("1. Key\n"); SendKeyboardString("2. Mouse\n"); SendKeyboardString("3. Game\n"); @@ -205,56 +204,60 @@ void Menu_Task(void) case MENU_STATE_DEBUG: if (lastMenuState != MENU_STATE_DEBUG) { - SendKeyboardString("\n\nAdvanced\n\n"); - SendKeyboardString("1. Hard Factory Reset\n"); - SendKeyboardString("2. Soft Factory Reset\n"); - SendKeyboardString("3. Log HID Data\n"); - SendKeyboardString("4. Dump PS2 mouse status\n\n"); + SendKeyboardString("\n\n--\nAdvanced\n\n"); + SendKeyboardString("1. Factory Reset\n"); + SendKeyboardString("2. Log HID Data\n"); + SendKeyboardString("3. PS2 mouse status\n"); + SendKeyboardString("4. Serial Log - "); + YesNo(FlashSettings->SerialDebugOutput); + //SendKeyboardString("5. Memory Test\n\n"); - SendKeyboardString("ESC main menu\n"); + SendKeyboardString("\nESC main menu\n"); lastMenuState = menuState; } switch (menuKey) { - case KEY_1: - // stop timer0 resetting watchdog - ET0 = 0; - case KEY_2: - // trigger a watchdog reset by hanging around - while (1); - break; - case KEY_3: - SendKeyboardString("Logging HID Data. Press ESC to stop...\n"); - KeyboardDebugOutput = 1; - menuState = MENU_STATE_DUMPING; - break; - case KEY_4: - SendKeyboardString("Type %u\n", (&OutputMice[MOUSE_PORT_PS2])->Ps2Type); - SendKeyboardString("Rate %u\n", (&OutputMice[MOUSE_PORT_PS2])->Ps2Rate); - SendKeyboardString("Resolution %u\n", (&OutputMice[MOUSE_PORT_PS2])->Ps2Resolution); - SendKeyboardString("Scaling %u\n", (&OutputMice[MOUSE_PORT_PS2])->Ps2Scaling); - SendKeyboardString("Data reporting %u\n", (&OutputMice[MOUSE_PORT_PS2])->Ps2DataReporting); - SendKeyboardString("\nCommand buffer\n"); - for (UINT8 i = 0; i < MOUSE_BUFFER_SIZE; i++) - { - if (!(i & 0x000F)) - SendKeyboardString("\n"); - SendKeyboardString("%02X ", MouseBuffer[i]); - } - menuState = MENU_STATE_INIT; - break; + case KEY_1: + // stop timer0 resetting watchdog + ET0 = 0; + while(1); + break; + + case KEY_2: + SendKeyboardString("Logging HID Data. Press ESC to stop...\n"); + KeyboardDebugOutput = 1; + menuState = MENU_STATE_DUMPING; + break; + + case KEY_3: + SendKeyboardString("Type %u\n", (&OutputMice[MOUSE_PORT_PS2])->Ps2Type); + SendKeyboardString("Rate %u\n", (&OutputMice[MOUSE_PORT_PS2])->Ps2Rate); + SendKeyboardString("Resolution %u\n", (&OutputMice[MOUSE_PORT_PS2])->Ps2Resolution); + SendKeyboardString("Scaling %u\n", (&OutputMice[MOUSE_PORT_PS2])->Ps2Scaling); + SendKeyboardString("Data reporting %u\n", (&OutputMice[MOUSE_PORT_PS2])->Ps2DataReporting); + SendKeyboardString("\nCommand buffer\n"); + for (UINT8 i = 0; i < MOUSE_BUFFER_SIZE; i++) + { + if (!(i & 0x000F)) + SendKeyboardString("\n"); + SendKeyboardString("%02X ", MouseBuffer[i]); + } + menuState = MENU_STATE_INIT; + break; + + case KEY_4: HMSettings.SerialDebugOutput ^= 1; SyncSettings(); lastMenuState = 0; break; + + case KEY_ESC: menuState = MENU_STATE_MAIN; break; - case KEY_ESC: menuState = MENU_STATE_MAIN; break; - - /*case KEY_5: - SendKeyboardString("Used %lx, free %lx\n", MemoryUsed(), MemoryFree()); - SendKeyboardString("Testing allocator, will reset when complete\n"); - for (int i = 0; i < 128; i++) { - andyalloc(256); - } - DumpReport = 1; - menuState = MENU_STATE_DUMPING; - break;*/ + /*case KEY_5: + SendKeyboardString("Used %lx, free %lx\n", MemoryUsed(), MemoryFree()); + SendKeyboardString("Testing allocator, will reset when complete\n"); + for (int i = 0; i < 128; i++) { + andyalloc(256); + } + DumpReport = 1; + menuState = MENU_STATE_DUMPING; + break;*/ } break; diff --git a/firmware/menu.h b/firmware/menu.h index c3349ee..6dbde9e 100644 --- a/firmware/menu.h +++ b/firmware/menu.h @@ -23,13 +23,13 @@ void SendKeyboardBuffer(void); void Menu_Task(void); extern uint8_t menuState; void inputProcess(void); -#define DEBUGOUT(...) { printf(__VA_ARGS__);} + //#define DEBUGOUT(...) #define SendKeyboardString(...) {sprintf(SendBuffer, __VA_ARGS__); SendKeyboardBuffer();} extern bool KeyboardDebugOutput; -extern bool SerialDebugOutput; + extern uint8_t LEDStatus; #endif \ No newline at end of file diff --git a/firmware/preset.c b/firmware/preset.c index dc6e966..1c8b6c3 100644 --- a/firmware/preset.c +++ b/firmware/preset.c @@ -43,7 +43,7 @@ void DumpPresets(void){ while (currPreset != NULL) { - DEBUG_OUT("%x ", currPreset->InputUsage); + DEBUGOUT("%x ", currPreset->InputUsage); currPreset = currPreset->next; } } diff --git a/firmware/ps2protocol.c b/firmware/ps2protocol.c index fb41c8e..f87d81a 100644 --- a/firmware/ps2protocol.c +++ b/firmware/ps2protocol.c @@ -379,7 +379,7 @@ bool ParseReport(INTERFACE *interface, uint32_t len, uint8_t *report) Menu_Press_Key(c); else { - ANDYS_DEBUG_OUT("\nSendn %x\n", c); + //DEBUGOUT("\nSendn %x\n", c); // Make if (c <= 0x67) { @@ -400,7 +400,7 @@ bool ParseReport(INTERFACE *interface, uint32_t len, uint8_t *report) // break if (c <= 0x67) { - ANDYS_DEBUG_OUT("\nBreakn %x\n", c); + //DEBUGOUT("\nBreakn %x\n", c); // if the key we just released is the one that's repeating then stop if (c == RepeatKey) { diff --git a/firmware/scancode.c b/firmware/scancode.c index d5470f2..d72c8af 100644 --- a/firmware/scancode.c +++ b/firmware/scancode.c @@ -417,7 +417,7 @@ __code unsigned char KEY_PADEN_MAKE[] = {2, 0xE0, 0x5A}; __code unsigned char KEY_PADDOT_MAKE[] = {1, 0x71}; __code unsigned char KEY_PAD0_MAKE[] = {1, 0x70}; __code unsigned char KEY_PAD1_MAKE[] = {1, 0x69}; -__code unsigned char KEY_PAD2_MAKE[] = {1, 0x71}; +__code unsigned char KEY_PAD2_MAKE[] = {1, 0x72}; __code unsigned char KEY_PAD3_MAKE[] = {1, 0x7A}; __code unsigned char KEY_PAD4_MAKE[] = {1, 0x6B}; __code unsigned char KEY_PAD5_MAKE[] = {1, 0x73}; @@ -524,7 +524,7 @@ __code unsigned char KEY_PADEN_BREAK[] = {3, 0xE0, 0xF0, 0x5A}; __code unsigned char KEY_PADDOT_BREAK[] = {2, 0xF0, 0x71}; __code unsigned char KEY_PAD0_BREAK[] = {2, 0xF0, 0x70}; __code unsigned char KEY_PAD1_BREAK[] = {2, 0xF0, 0x69}; -__code unsigned char KEY_PAD2_BREAK[] = {2, 0xF0, 0x71}; +__code unsigned char KEY_PAD2_BREAK[] = {2, 0xF0, 0x72}; __code unsigned char KEY_PAD3_BREAK[] = {2, 0xF0, 0x7A}; __code unsigned char KEY_PAD4_BREAK[] = {2, 0xF0, 0x6B}; __code unsigned char KEY_PAD5_BREAK[] = {2, 0xF0, 0x73}; diff --git a/firmware/settings.c b/firmware/settings.c index f24cf7d..e3a3e88 100644 --- a/firmware/settings.c +++ b/firmware/settings.c @@ -23,8 +23,8 @@ uint8_t SyncSettings(void) { if(EraseDataFlash(0xF000) == 0){ if (WriteDataFlash(0xF000, (uint8_t *)&HMSettings, sizeof(Settings)) == 0) return 0; - else DEBUG_OUT("Cant Write\n"); - }else DEBUG_OUT("Cant Erase\n"); + else DEBUGOUT("Cant Write\n"); + }else DEBUGOUT("Cant Erase\n"); return 1; } @@ -33,24 +33,23 @@ void InitSettings(bool SafeMode){ // magic value not present (or we're in safe mode), initialize flash data if (SafeMode || FlashSettings->Magic != 0x54178008) { - DEBUG_OUT("Magic Missing\n"); + DEBUGOUT("Magic Missing\n"); memset(&HMSettings, 0x00, sizeof(Settings)); HMSettings.Magic = 0x54178008; //if (!SafeMode) HMSettings.Intellimouse = 1; HMSettings.Intellimouse = 1; - HMSettings.MouseReportMode = 1; if (SyncSettings()) { - DEBUG_OUT("Writin failed\n"); + DEBUGOUT("Writin failed\n"); } } memcpy(&HMSettings, FlashSettings, sizeof(Settings)); if (HMSettings.Magic != 0x54178008){ // failed, do something bad - DEBUG_OUT("Initing settings failed\n"); + DEBUGOUT("Initing settings failed\n"); } } diff --git a/firmware/settings.h b/firmware/settings.h index cf1210b..4a7eee8 100644 --- a/firmware/settings.h +++ b/firmware/settings.h @@ -27,6 +27,9 @@ typedef struct Settings { // Use game controller to control mouse bool GameControllerAsMouse; + // Output debug info to serial port + bool SerialDebugOutput; + // What type of computer the keyboard is plugged into (i.e. PS2 or XT) uint8_t KeyboardMode; diff --git a/firmware/system.c b/firmware/system.c index 1687994..f8be084 100644 --- a/firmware/system.c +++ b/firmware/system.c @@ -134,14 +134,15 @@ int putcharserial(int c) int putchar(int c) { -#if !defined(BOARD_MICRO) -if (SerialDebugOutput){ - while (!TI) - ; - TI = 0; - SBUF = c & 0xFF; -} -#endif + #if !defined(BOARD_MICRO) + if (FlashSettings->SerialDebugOutput){ + while (!TI) + ; + TI = 0; + SBUF = c & 0xFF; + } + #endif + if (KeyboardDebugOutput) { // capitals, hold shift first diff --git a/firmware/system.h b/firmware/system.h index 9f31bac..df1c289 100644 --- a/firmware/system.h +++ b/firmware/system.h @@ -1,21 +1,6 @@ #ifndef __SYSTEM_H__ #define __SYSTEM_H__ -//���庯������ֵ -#ifndef SUCCESS -#define SUCCESS 1 -#endif -#ifndef FAIL -#define FAIL 0 -#endif - -//���嶨ʱ����ʼ -#ifndef START -#define START 1 -#endif -#ifndef STOP -#define STOP 0 -#endif //#define FREQ_SYS 48000000ul //ϵͳ��Ƶ48MHz @@ -33,27 +18,12 @@ void mDelaymS(UINT16 n); // ��mSΪ��λ��ʱ #include -#if 0 - #define ANDYS_DEBUG_OUT(...) printf(__VA_ARGS__); -#else - #define ANDYS_DEBUG_OUT(...) (void)0; -#endif - - -#if 0 - #define DEBUG_OUT(...) printf(__VA_ARGS__); -#else - #define DEBUG_OUT(...) (void)0; -#endif void initClock(void); unsigned char UART0Receive(void); void UART0Send(unsigned char b); int putcharserial(int c); -#define DYNAMIC_MEMORY_SIZE 0x400 -extern unsigned char __xdata dynamic_memory_pool[DYNAMIC_MEMORY_SIZE]; - #define st(x) do { x } while (__LINE__ == -1) #define HAL_ENABLE_INTERRUPTS() st( EA = 1; ) @@ -74,6 +44,6 @@ void ClockInit(void); extern volatile uint16_t SoftWatchdog; extern volatile bool OutputsEnabled; - +#define DEBUGOUT(...) { printf(__VA_ARGS__);} #endif diff --git a/firmware/test.c b/firmware/test.c index 658dda0..e1e2317 100644 --- a/firmware/test.c +++ b/firmware/test.c @@ -174,7 +174,7 @@ void main() testlinkedlist(); - /*TestDescriptors ( + TestDescriptors ( PS4DeviceDescriptor, 18, PS4ConfigDescriptor, 225, PS4ReportDescriptor, 507, @@ -207,7 +207,7 @@ void main() CheapoKeyboardConfigDescriptor, 59, CheapoKeyboardReportDescriptor, 54, 8 - );*/ + ); /* TestDescriptors ( CheapoGamepadDeviceDescriptor, 18, diff --git a/firmware/uart1.c b/firmware/uart1.c index 6052db1..c845bfc 100644 --- a/firmware/uart1.c +++ b/firmware/uart1.c @@ -28,23 +28,6 @@ UINT8 CH559UART1_FIFO_CNT = 0; #define CH559UART1_FIFO_TRIG 7 // FIFO full 7 bytes trigger interrupt (1, 2, 4, or 7 bytes) #endif -/************************************************* ****************************** -* Function Name: UART1RegCfgValue() -* Description: CH559UART1 readable register value after correct configuration -* Input: None -* Output: None -* Return: None -************************************************** *****************************/ -void UART1RegCfgValue(void) -{ - DEBUG_OUT("SER1_IER %02X\n",(UINT16)SER1_IER); //0x27/0x17/0x37 are all possible - DEBUG_OUT("SER1_IIR %02X\n",(UINT16)SER1_IIR); //0xc1/0xC2 no interrupt or empty interrupt, "C" means FIFO is on - DEBUG_OUT("SER1_LCR %02X\n",(UINT16)SER1_LCR); //0x03 data format configuration, indicating wireless path interval, no parity, 1 stop bit, 8 data bits - DEBUG_OUT("SER1_MCR %02X\n",(UINT16)SER1_MCR); //0x08 interrupt output enable, excluding other functions such as flow control on - DEBUG_OUT("SER1_LSR %02X\n",(UINT16)SER1_LSR); //0x60, FIFO and line status - DEBUG_OUT("SER1_MSR %02X\n",(UINT16)SER1_MSR); -} - /************************************************* ****************************** * Function Name: ResetUART1() * Description: CH559UART1 port soft reset @@ -231,29 +214,3 @@ void CH559UART1SendStr(PUINT8 SendStr) } #endif } -/* -main() -{ - UINT8 i; - UINT8 buffer[20]; -// CfgFsys( ); //Clock configuration -// mDelaymS(5); //Wait for the external crystal oscillator to stabilize - - mInitSTDIO( ); //Serial port 0, can be used for debugging - DEBUG_OUT("start ...\n"); -To - CH559UART1Init(13,1,2); - UART1RegCfgValue( ); //UART1 register configuration - P4_DIR |= 0x10; //When using P4 port, you must set the direction, TXD1 is set as output - -//inquiry mode - while(1) - { -// CH559UART1SendStr(Str); - CH559UART1Rcv(buffer,7); - for(i = 0;i <7;i++) - { - CH559UART1SendByte(buffer[i]); - } - } -}*/ \ No newline at end of file diff --git a/firmware/usbhost.c b/firmware/usbhost.c index a0814c6..b5293ba 100644 --- a/firmware/usbhost.c +++ b/firmware/usbhost.c @@ -347,8 +347,10 @@ UINT8 HIDDataTransferReceive(USB_HUB_PORT *pUsbDevice) // HIS IS WHERE THE FUN STUFF GOES //ProcessHIDData(pInterface, ReceiveDataBuffer, len); ParseReport(pInterface, len * 8, ReceiveDataBuffer); - DEBUGOUT("I%hX L%X- ", i, len); - DumpHex(ReceiveDataBuffer, len); + if (KeyboardDebugOutput || FlashSettings->SerialDebugOutput) { + DEBUGOUT("I%hX L%X- ", i, len); + DumpHex(ReceiveDataBuffer, len); + } } } }