Skip to content

Commit

Permalink
debug output changes
Browse files Browse the repository at this point in the history
  • Loading branch information
rasteri committed Nov 15, 2024
1 parent 20855e4 commit 02a396a
Show file tree
Hide file tree
Showing 15 changed files with 85 additions and 149 deletions.
2 changes: 1 addition & 1 deletion firmware/andyalloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
1 change: 1 addition & 0 deletions firmware/linkedlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <stdio.h>
#include <stdlib.h>
#include <string.h>
Expand Down
6 changes: 3 additions & 3 deletions firmware/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);

Expand All @@ -239,7 +239,7 @@ int main(void)

OutputsEnabled = 1;

ANDYS_DEBUG_OUT("ok\n");
DEBUGOUT("ok\n");

// main loop
while (1)
Expand Down
95 changes: 49 additions & 46 deletions firmware/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

__xdata char SendBuffer[255];

bool SerialDebugOutput = 1;
bool KeyboardDebugOutput = 0;
__xdata bool MenuActive = 0;

Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions firmware/menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion firmware/preset.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void DumpPresets(void){

while (currPreset != NULL)
{
DEBUG_OUT("%x ", currPreset->InputUsage);
DEBUGOUT("%x ", currPreset->InputUsage);
currPreset = currPreset->next;
}
}
Expand Down
4 changes: 2 additions & 2 deletions firmware/ps2protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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)
{
Expand Down
4 changes: 2 additions & 2 deletions firmware/scancode.c
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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};
Expand Down
11 changes: 5 additions & 6 deletions firmware/settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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");
}
}

3 changes: 3 additions & 0 deletions firmware/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
17 changes: 9 additions & 8 deletions firmware/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 1 addition & 31 deletions firmware/system.h
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -33,27 +18,12 @@ void mDelaymS(UINT16 n); // ��mSΪ��λ��ʱ

#include <stdio.h>

#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; )
Expand All @@ -74,6 +44,6 @@ void ClockInit(void);

extern volatile uint16_t SoftWatchdog;
extern volatile bool OutputsEnabled;

#define DEBUGOUT(...) { printf(__VA_ARGS__);}
#endif

4 changes: 2 additions & 2 deletions firmware/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ void main()
testlinkedlist();


/*TestDescriptors (
TestDescriptors (
PS4DeviceDescriptor, 18,
PS4ConfigDescriptor, 225,
PS4ReportDescriptor, 507,
Expand Down Expand Up @@ -207,7 +207,7 @@ void main()
CheapoKeyboardConfigDescriptor, 59,
CheapoKeyboardReportDescriptor, 54,
8
);*/
);

/* TestDescriptors (
CheapoGamepadDeviceDescriptor, 18,
Expand Down
Loading

0 comments on commit 02a396a

Please sign in to comment.