raspikeyer/src/raspi_keyer.cpp

103 lines
2.1 KiB
C++
Raw Normal View History

2024-02-06 15:50:50 +01:00
#include <stdio.h>
2024-02-10 23:26:53 +01:00
#include "pico/stdlib.h"
2024-02-14 10:13:50 +01:00
#include "pico/multicore.h"
#include "pico/util/queue.h"
2024-02-06 15:50:50 +01:00
2024-02-06 22:11:58 +01:00
#include "settings.h"
2024-02-10 23:26:53 +01:00
#include "keyer.h"
2024-02-06 22:11:58 +01:00
namespace
{
2024-02-13 09:29:13 +01:00
2024-02-06 16:16:18 +01:00
}
2024-02-12 13:48:58 +01:00
extern const uint LED_PIN = PICO_DEFAULT_LED_PIN;
2024-02-10 23:51:55 +01:00
extern const uint LEFT_PADDLE_PIN = 14;
2024-02-12 13:48:58 +01:00
extern const uint RIGHT_PADDLE_PIN = 15;
2024-02-12 15:57:50 +01:00
extern const uint BUZZER_PIN = 13;
2024-02-06 15:50:50 +01:00
2024-02-14 10:49:38 +01:00
// Stuff for communicating between cores
enum class KeyerQueueCommand
{
Run,
Stop,
Config,
};
struct KeyerQueueData
{
KeyerQueueCommand cmd;
uint8_t wpm;
Mode mode;
};
2024-02-14 10:13:50 +01:00
queue_t keyerQueue;
2024-02-09 14:05:15 +01:00
void setup()
2024-02-06 15:50:50 +01:00
{
2024-02-12 13:48:58 +01:00
stdio_init_all();
2024-02-07 11:15:41 +01:00
gpio_init(LED_PIN);
gpio_set_dir(LED_PIN, GPIO_OUT);
gpio_put(LED_PIN, 0);
2024-02-06 15:50:50 +01:00
2024-02-09 14:05:15 +01:00
// Setup pins for left and right paddles
gpio_init(LEFT_PADDLE_PIN);
gpio_set_dir(LEFT_PADDLE_PIN, GPIO_IN);
2024-02-11 15:45:12 +01:00
gpio_pull_up(LEFT_PADDLE_PIN);
2024-02-09 14:05:15 +01:00
gpio_init(RIGHT_PADDLE_PIN);
gpio_set_dir(RIGHT_PADDLE_PIN, GPIO_IN);
2024-02-11 15:45:12 +01:00
gpio_pull_up(RIGHT_PADDLE_PIN);
2024-02-12 15:57:50 +01:00
2024-02-12 13:48:58 +01:00
sleep_ms(1000);
2024-02-09 14:05:15 +01:00
}
2024-02-14 10:49:38 +01:00
/* Let's do all the keying stuff in the second core, so there are no timing problems. */
2024-02-14 10:13:50 +01:00
void core1_main()
{
2024-02-14 10:49:38 +01:00
KeyerQueueData data;
queue_remove_blocking(&keyerQueue, &data);
2024-02-14 10:13:50 +01:00
2024-02-14 10:49:38 +01:00
Keyer keyer(data.wpm, data.mode);
2024-02-14 10:13:50 +01:00
while (true)
{
2024-02-14 10:49:38 +01:00
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;
}
2024-02-14 10:13:50 +01:00
}
}
2024-02-09 14:05:15 +01:00
int main()
{
2024-02-13 09:29:13 +01:00
timer_hw->dbgpause = 0; // workaround for problem with debug and sleep_ms
// https://github.com/raspberrypi/pico-sdk/issues/1152#issuecomment-1418248639
2024-02-10 23:26:53 +01:00
2024-02-09 14:05:15 +01:00
setup();
2024-02-07 11:35:30 +01:00
Settings settings{read_settings()};
2024-02-07 11:15:41 +01:00
2024-02-14 10:49:38 +01:00
KeyerQueueData keyerQueueData{KeyerQueueCommand::Run, settings.wpm, settings.mode};
queue_add_blocking(&keyerQueue, &keyerQueueData);
2024-02-10 23:26:53 +01:00
2024-02-07 11:15:41 +01:00
while (true)
{
2024-02-14 10:49:38 +01:00
// Currently there's nothing to do on core0
sleep_ms(1000);
}
2024-02-07 09:32:11 +01:00
2024-02-06 15:50:50 +01:00
return 0;
}