From 0e23c0b30454d7034e80302517711e735285396e Mon Sep 17 00:00:00 2001 From: Chris Greening Date: Tue, 26 Nov 2024 19:46:45 +0000 Subject: [PATCH] Fix camel case of updateKey and wires up boot button --- firmware/src/Emulator/keyboard_defs.h | 2 ++ firmware/src/Emulator/spectrum.cpp | 2 +- firmware/src/Emulator/spectrum.h | 2 +- firmware/src/Screens/EmulatorScreen.cpp | 5 ++-- firmware/src/Screens/EmulatorScreen.h | 2 +- .../src/Screens/EmulatorScreen/Machine.cpp | 12 ++++----- firmware/src/Screens/EmulatorScreen/Machine.h | 2 +- firmware/src/Screens/ErrorScreen.h | 2 +- firmware/src/Screens/NavigationStack.h | 4 +-- firmware/src/Screens/Screen.h | 2 +- firmware/src/Screens/USBKeyboardScreen.h | 2 +- firmware/src/main.cpp | 25 ++++++++++++++----- 12 files changed, 38 insertions(+), 24 deletions(-) diff --git a/firmware/src/Emulator/keyboard_defs.h b/firmware/src/Emulator/keyboard_defs.h index 42508a9..31e3086 100644 --- a/firmware/src/Emulator/keyboard_defs.h +++ b/firmware/src/Emulator/keyboard_defs.h @@ -53,6 +53,8 @@ enum SpecKeys // special pseudo keys SPECKEY_DEL, SPECKEY_BREAK, + // special keys for the emulator + SPECKEY_MENU, }; const std::unordered_map specKeyToLetter = { diff --git a/firmware/src/Emulator/spectrum.cpp b/firmware/src/Emulator/spectrum.cpp index d076b7d..e29c933 100644 --- a/firmware/src/Emulator/spectrum.cpp +++ b/firmware/src/Emulator/spectrum.cpp @@ -116,7 +116,7 @@ void ZXSpectrum::interrupt() Z80Interrupt(z80Regs, 0x38); } -void ZXSpectrum::updatekey(SpecKeys key, uint8_t state) +void ZXSpectrum::updateKey(SpecKeys key, uint8_t state) { // Bit pattern: XXXFULDR switch (key) diff --git a/firmware/src/Emulator/spectrum.h b/firmware/src/Emulator/spectrum.h index 7052960..80bd819 100644 --- a/firmware/src/Emulator/spectrum.h +++ b/firmware/src/Emulator/spectrum.h @@ -161,7 +161,7 @@ class ZXSpectrum } void interrupt(); - void updatekey(SpecKeys key, uint8_t state); + void updateKey(SpecKeys key, uint8_t state); inline uint8_t z80_peek(uint16_t address) { diff --git a/firmware/src/Screens/EmulatorScreen.cpp b/firmware/src/Screens/EmulatorScreen.cpp index 1cc335b..74146a7 100644 --- a/firmware/src/Screens/EmulatorScreen.cpp +++ b/firmware/src/Screens/EmulatorScreen.cpp @@ -59,7 +59,6 @@ EmulatorScreen::EmulatorScreen(TFTDisplay &tft, AudioOutput *audioOutput, IFiles Serial.println("ROM loading routine hit"); triggerLoadTape(); }); gameLoader = new GameLoader(machine, renderer, audioOutput); - pinMode(0, INPUT_PULLUP); } void EmulatorScreen::run(std::string filename, models_enum model) @@ -102,7 +101,7 @@ void EmulatorScreen::resume() machine->resume(); } -void EmulatorScreen::updatekey(SpecKeys key, uint8_t state) +void EmulatorScreen::updateKey(SpecKeys key, uint8_t state) { // TODO audio capture // if (key == SPECKEY_0) @@ -116,7 +115,7 @@ void EmulatorScreen::updatekey(SpecKeys key, uint8_t state) // Serial.printf("Audio file closed\n"); // } // } - machine->updatekey(key, state); + machine->updateKey(key, state); } void EmulatorScreen::showSaveSnapshotScreen() diff --git a/firmware/src/Screens/EmulatorScreen.h b/firmware/src/Screens/EmulatorScreen.h index 0ddf9c2..054919c 100644 --- a/firmware/src/Screens/EmulatorScreen.h +++ b/firmware/src/Screens/EmulatorScreen.h @@ -23,7 +23,7 @@ class EmulatorScreen : public Screen bool isLoading = false; public: EmulatorScreen(TFTDisplay &tft, AudioOutput *audioOutput, IFiles *files); - void updatekey(SpecKeys key, uint8_t state); + void updateKey(SpecKeys key, uint8_t state); void run(std::string filename, models_enum model); void pause(); void resume(); diff --git a/firmware/src/Screens/EmulatorScreen/Machine.cpp b/firmware/src/Screens/EmulatorScreen/Machine.cpp index f286f1c..1947d3e 100644 --- a/firmware/src/Screens/EmulatorScreen/Machine.cpp +++ b/firmware/src/Screens/EmulatorScreen/Machine.cpp @@ -51,9 +51,9 @@ Machine::Machine(Renderer *renderer, AudioOutput *audioOutput, std::functionupdatekey(key, state); + machine->updateKey(key, state); } } @@ -73,12 +73,12 @@ void Machine::start(FILE *audioFile) { void Machine::tapKey(SpecKeys key) { - machine->updatekey(key, 1); + machine->updateKey(key, 1); for (int i = 0; i < 10; i++) { machine->runForFrame(nullptr, nullptr); } - machine->updatekey(key, 0); + machine->updateKey(key, 0); for (int i = 0; i < 10; i++) { machine->runForFrame(nullptr, nullptr); @@ -97,10 +97,10 @@ void Machine::startLoading() if (machine->hwopt.hw_model == SPECMDL_48K) { tapKey(SPECKEY_J); - machine->updatekey(SPECKEY_SYMB, 1); + machine->updateKey(SPECKEY_SYMB, 1); tapKey(SPECKEY_P); tapKey(SPECKEY_P); - machine->updatekey(SPECKEY_SYMB, 0); + machine->updateKey(SPECKEY_SYMB, 0); tapKey(SPECKEY_ENTER); } else diff --git a/firmware/src/Screens/EmulatorScreen/Machine.h b/firmware/src/Screens/EmulatorScreen/Machine.h index 378e40d..4fbf066 100644 --- a/firmware/src/Screens/EmulatorScreen/Machine.h +++ b/firmware/src/Screens/EmulatorScreen/Machine.h @@ -155,7 +155,7 @@ class Machine { std::function romLoadingRoutineHitCallback; public: Machine(Renderer *renderer, AudioOutput *audioOutput, std::function romLoadingRoutineHitCallback); - void updatekey(SpecKeys key, uint8_t state); + void updateKey(SpecKeys key, uint8_t state); void setup(models_enum model); void start(FILE *audioFile); void pause() { diff --git a/firmware/src/Screens/ErrorScreen.h b/firmware/src/Screens/ErrorScreen.h index 032dc2f..d566581 100644 --- a/firmware/src/Screens/ErrorScreen.h +++ b/firmware/src/Screens/ErrorScreen.h @@ -25,7 +25,7 @@ class ErrorScreen : public Screen updateDisplay(); } - void updatekey(SpecKeys key, uint8_t state) + void updateKey(SpecKeys key, uint8_t state) { if (state == 1) { diff --git a/firmware/src/Screens/NavigationStack.h b/firmware/src/Screens/NavigationStack.h index b061018..39a9232 100644 --- a/firmware/src/Screens/NavigationStack.h +++ b/firmware/src/Screens/NavigationStack.h @@ -40,10 +40,10 @@ class NavigationStack } } } - void updatekey(SpecKeys key, uint8_t state) { + void updateKey(SpecKeys key, uint8_t state) { Screen *top = getTop(); if (top) { - top->updatekey(key, state); + top->updateKey(key, state); } }; void pressKey(SpecKeys key) { diff --git a/firmware/src/Screens/Screen.h b/firmware/src/Screens/Screen.h index def6ad5..d85e04e 100644 --- a/firmware/src/Screens/Screen.h +++ b/firmware/src/Screens/Screen.h @@ -23,7 +23,7 @@ class Screen { public: Screen(TFTDisplay &tft, AudioOutput *audioOutput) : m_tft(tft), m_audioOutput(audioOutput) {} // input - virtual void updatekey(SpecKeys key, uint8_t state) {}; + virtual void updateKey(SpecKeys key, uint8_t state) {}; virtual void pressKey(SpecKeys key) {}; void playKeyClick() { if (m_audioOutput) { diff --git a/firmware/src/Screens/USBKeyboardScreen.h b/firmware/src/Screens/USBKeyboardScreen.h index 3191ed8..6c01d8e 100644 --- a/firmware/src/Screens/USBKeyboardScreen.h +++ b/firmware/src/Screens/USBKeyboardScreen.h @@ -77,7 +77,7 @@ class USBKeyboardScreen : public Screen USB.begin(); } - void updatekey(SpecKeys key, uint8_t state) + void updateKey(SpecKeys key, uint8_t state) { // map from the spectrum key to a hid_key int hid_key = 0; diff --git a/firmware/src/main.cpp b/firmware/src/main.cpp index cc41a08..22a2124 100644 --- a/firmware/src/main.cpp +++ b/firmware/src/main.cpp @@ -105,7 +105,7 @@ void setup(void) [&](SpecKeys key, bool down) { { - navigationStack->updatekey(key, down); + navigationStack->updateKey(key, down); } }); touchKeyboard->calibrate(); @@ -114,7 +114,7 @@ void setup(void) #ifdef TOUCH_KEYBOARD_V2 TouchKeyboardV2 *touchKeyboard = new TouchKeyboardV2( [&](SpecKeys key, bool down) - { navigationStack->updatekey(key, down); }, + { navigationStack->updateKey(key, down); }, [&](SpecKeys key) { navigationStack->pressKey(key); }); touchKeyboard->start(); @@ -138,29 +138,42 @@ void setup(void) navigationStack->push(&menuPicker); // start off the keyboard and feed keys into the active scene SerialKeyboard *keyboard = new SerialKeyboard([&](SpecKeys key, bool down) - { navigationStack->updatekey(key, down); if (down) { navigationStack->pressKey(key); } }); + { navigationStack->updateKey(key, down); if (down) { navigationStack->pressKey(key); } }); // start up the nunchuk controller and feed events into the active screen #ifdef NUNCHUK_CLOCK Nunchuck *nunchuck = new Nunchuck([&](SpecKeys key, bool down) - { navigationStack->updatekey(key, down); }, + { navigationStack->updateKey(key, down); }, [&](SpecKeys key) { navigationStack->pressKey(key); }, NUNCHUK_CLOCK, NUNCHUK_DATA); #endif #ifdef SEESAW_CLOCK AdafruitSeeSaw *seeSaw = new AdafruitSeeSaw([&](SpecKeys key, bool down) - { navigationStack->updatekey(key, down); }, + { navigationStack->updateKey(key, down); }, [&](SpecKeys key) { navigationStack->pressKey(key); }); seeSaw->begin(SEESAW_DATA, SEESAW_CLOCK); #endif Serial.println("Running on core: " + String(xPortGetCoreID())); + // use the boot pin to open the emulator menu + pinMode(0, INPUT_PULLUP); // just keep running + bool bootButtonWasPressed = false; while (true) { - vTaskDelay(10000); + vTaskDelay(100 / portTICK_PERIOD_MS); + if (digitalRead(0) == LOW) + { + navigationStack->updateKey(SPECKEY_MENU, true); + } + else if (bootButtonWasPressed) + { + navigationStack->updateKey(SPECKEY_MENU, false); + navigationStack->pressKey(SPECKEY_MENU); + bootButtonWasPressed = false; + } } }