111 lines
2.5 KiB
C++
111 lines
2.5 KiB
C++
#include <stdio.h>
|
|
|
|
#include "pico/multicore.h"
|
|
#include "pico/stdlib.h"
|
|
#include "pico/util/queue.h"
|
|
|
|
#include "keyer.h"
|
|
#include "settings.h"
|
|
|
|
namespace
|
|
{
|
|
|
|
}
|
|
|
|
extern const uint LED_PIN = PICO_DEFAULT_LED_PIN;
|
|
extern const uint LEFT_PADDLE_PIN = 14;
|
|
extern const uint RIGHT_PADDLE_PIN = 15;
|
|
extern const uint BUZZER_PIN = 18;
|
|
|
|
// Stuff for communicating between cores
|
|
enum class KeyerQueueCommand {
|
|
Run,
|
|
Stop,
|
|
Config,
|
|
Wait,
|
|
};
|
|
struct KeyerQueueData {
|
|
KeyerQueueCommand cmd;
|
|
uint8_t wpm;
|
|
Mode mode;
|
|
};
|
|
|
|
queue_t keyerQueue;
|
|
|
|
void setup()
|
|
{
|
|
stdio_init_all();
|
|
gpio_init(LED_PIN);
|
|
gpio_set_dir(LED_PIN, GPIO_OUT);
|
|
gpio_put(LED_PIN, 0);
|
|
|
|
// Setup pins for left and right paddles
|
|
gpio_init(LEFT_PADDLE_PIN);
|
|
gpio_set_dir(LEFT_PADDLE_PIN, GPIO_IN);
|
|
gpio_pull_up(LEFT_PADDLE_PIN);
|
|
gpio_init(RIGHT_PADDLE_PIN);
|
|
gpio_set_dir(RIGHT_PADDLE_PIN, GPIO_IN);
|
|
gpio_pull_up(RIGHT_PADDLE_PIN);
|
|
|
|
// sleep_ms(1000);
|
|
}
|
|
|
|
/* Let's do all the keying stuff in the second core, so there are no timing problems. */
|
|
void core1_main()
|
|
{
|
|
printf("Hello from core1!\n");
|
|
KeyerQueueData data;
|
|
queue_remove_blocking(&keyerQueue, &data);
|
|
|
|
Keyer keyer(data.wpm, data.mode);
|
|
|
|
while (true) {
|
|
queue_try_remove(&keyerQueue, &data);
|
|
|
|
switch (data.cmd) {
|
|
case KeyerQueueCommand::Run:
|
|
keyer.run();
|
|
break;
|
|
case KeyerQueueCommand::Stop:
|
|
keyer.stop();
|
|
data.cmd = KeyerQueueCommand::Wait;
|
|
break;
|
|
case KeyerQueueCommand::Config:
|
|
keyer.setSpeed(data.wpm);
|
|
keyer.setMode(data.mode);
|
|
data.cmd = KeyerQueueCommand::Run;
|
|
break;
|
|
case KeyerQueueCommand::Wait:
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
int main()
|
|
{
|
|
// timer_hw->dbgpause = 2; // workaround for problem with debug and sleep_ms
|
|
// https://github.com/raspberrypi/pico-sdk/issues/1152#issuecomment-1418248639
|
|
|
|
setup();
|
|
|
|
printf("Hello from core0!\n");
|
|
|
|
Settings settings{read_settings()};
|
|
settings.wpm = 25; // TODO: remove!
|
|
|
|
queue_init(&keyerQueue, sizeof(KeyerQueueData), 2);
|
|
multicore_reset_core1();
|
|
multicore_launch_core1(core1_main);
|
|
|
|
KeyerQueueData keyerQueueData{KeyerQueueCommand::Run, settings.wpm, settings.mode};
|
|
queue_add_blocking(&keyerQueue, &keyerQueueData);
|
|
|
|
while (true) {
|
|
// Currently there's nothing to do on core0
|
|
sleep_ms(1000);
|
|
}
|
|
|
|
return 0;
|
|
}
|