more basic usb stuff
This commit is contained in:
parent
5c858f78a1
commit
4d56a9ebb9
1 changed files with 43 additions and 7 deletions
|
@ -1,14 +1,14 @@
|
|||
#include <stdio.h>
|
||||
|
||||
#include "bsp/board.h"
|
||||
#include "pico/multicore.h"
|
||||
#include "pico/stdlib.h"
|
||||
#include "pico/util/queue.h"
|
||||
#include "tusb.h"
|
||||
#include "bsp/board.h"
|
||||
|
||||
#include "tusb_config.h"
|
||||
#include "keyer.h"
|
||||
#include "settings.h"
|
||||
#include "tusb_config.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
|
@ -89,6 +89,43 @@ void core1_main()
|
|||
}
|
||||
}
|
||||
|
||||
[[maybe_unused]]
|
||||
static void echo_serial_port(uint8_t itf, uint8_t buf[], uint32_t count)
|
||||
{
|
||||
for(uint32_t i=0; i<count; i++)
|
||||
{
|
||||
tud_cdc_n_write_char(itf, buf[i]);
|
||||
}
|
||||
|
||||
tud_cdc_n_write_flush(itf);
|
||||
}
|
||||
|
||||
void cdc_task()
|
||||
{
|
||||
const uint8_t UsbInIf = 1;
|
||||
|
||||
if (tud_cdc_n_available(UsbInIf)) {
|
||||
uint8_t buf[64];
|
||||
|
||||
uint32_t count = tud_cdc_n_read(UsbInIf, buf, sizeof(buf));
|
||||
if (count > 1) {
|
||||
printf("Command received …\n");
|
||||
switch (buf[0]) {
|
||||
case 0: // ADMIN COMMAND
|
||||
switch (buf[1]) {
|
||||
case 2: // Host Open
|
||||
// TODO: send back revision code
|
||||
default:
|
||||
printf("Unknown admin command.\n");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
printf("Unknown command.\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
// timer_hw->dbgpause = 2; // workaround for problem with debug and sleep_ms
|
||||
|
@ -97,23 +134,22 @@ int main()
|
|||
setup();
|
||||
board_init();
|
||||
tud_init(BOARD_TUD_RHPORT);
|
||||
|
||||
|
||||
printf("Hello from core0!\n");
|
||||
|
||||
Settings settings{read_settings()};
|
||||
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};
|
||||
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);
|
||||
tud_task();
|
||||
cdc_task();
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
Loading…
Reference in a new issue