From 60e9da0877712278db44e640168e1c3237043fbd Mon Sep 17 00:00:00 2001 From: Martin Brodbeck Date: Wed, 14 Feb 2024 10:49:38 +0100 Subject: [PATCH] Keyer should now run on core1 --- src/raspi_keyer.cpp | 49 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 39 insertions(+), 10 deletions(-) diff --git a/src/raspi_keyer.cpp b/src/raspi_keyer.cpp index e51e3a5..d904166 100644 --- a/src/raspi_keyer.cpp +++ b/src/raspi_keyer.cpp @@ -17,6 +17,20 @@ extern const uint LEFT_PADDLE_PIN = 14; extern const uint RIGHT_PADDLE_PIN = 15; extern const uint BUZZER_PIN = 13; +// Stuff for communicating between cores +enum class KeyerQueueCommand +{ + Run, + Stop, + Config, +}; +struct KeyerQueueData +{ + KeyerQueueCommand cmd; + uint8_t wpm; + Mode mode; +}; + queue_t keyerQueue; void setup() @@ -37,18 +51,33 @@ void setup() sleep_ms(1000); } +/* Let's do all the keying stuff in the second core, so there are no timing problems. */ void core1_main() { - Settings settings; - queue_remove_blocking(&keyerQueue, &settings); + KeyerQueueData data; + queue_remove_blocking(&keyerQueue, &data); - Keyer keyer(settings.wpm, settings.mode); + Keyer keyer(data.wpm, data.mode); while (true) { - keyer.run(); - } + queue_try_remove(&keyerQueue, &data); + switch (data.cmd) + { + case KeyerQueueCommand::Run: + keyer.run(); + break; + case KeyerQueueCommand::Stop: + break; + case KeyerQueueCommand::Config: + // set speed and wpm + data.cmd = KeyerQueueCommand::Run; + break; + default: + break; + } + } } int main() @@ -60,14 +89,14 @@ int main() Settings settings{read_settings()}; - /*Keyer keyer(settings.wpm, settings.mode);*/ - - queue_add_blocking(&keyerQueue, &settings); + KeyerQueueData keyerQueueData{KeyerQueueCommand::Run, settings.wpm, settings.mode}; + queue_add_blocking(&keyerQueue, &keyerQueueData); while (true) { - sleep_ms(100); - } + // Currently there's nothing to do on core0 + sleep_ms(1000); + } return 0; }