Keyer should now run on core1

This commit is contained in:
Martin Brodbeck 2024-02-14 10:49:38 +01:00
parent 6ea69df2fa
commit 60e9da0877

View file

@ -17,6 +17,20 @@ extern const uint LEFT_PADDLE_PIN = 14;
extern const uint RIGHT_PADDLE_PIN = 15; extern const uint RIGHT_PADDLE_PIN = 15;
extern const uint BUZZER_PIN = 13; 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; queue_t keyerQueue;
void setup() void setup()
@ -37,18 +51,33 @@ void setup()
sleep_ms(1000); sleep_ms(1000);
} }
/* Let's do all the keying stuff in the second core, so there are no timing problems. */
void core1_main() void core1_main()
{ {
Settings settings; KeyerQueueData data;
queue_remove_blocking(&keyerQueue, &settings); queue_remove_blocking(&keyerQueue, &data);
Keyer keyer(settings.wpm, settings.mode); Keyer keyer(data.wpm, data.mode);
while (true) 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() int main()
@ -60,14 +89,14 @@ int main()
Settings settings{read_settings()}; Settings settings{read_settings()};
/*Keyer keyer(settings.wpm, settings.mode);*/ KeyerQueueData keyerQueueData{KeyerQueueCommand::Run, settings.wpm, settings.mode};
queue_add_blocking(&keyerQueue, &keyerQueueData);
queue_add_blocking(&keyerQueue, &settings);
while (true) while (true)
{ {
sleep_ms(100); // Currently there's nothing to do on core0
} sleep_ms(1000);
}
return 0; return 0;
} }