more basic usb stuff

This commit is contained in:
Martin Brodbeck 2024-02-19 15:07:29 +01:00
parent 5c858f78a1
commit 4d56a9ebb9

View file

@ -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
@ -111,9 +148,8 @@ int main()
queue_add_blocking(&keyerQueue, &keyerQueueData);
while (true) {
// Currently there's nothing to do on core0
sleep_ms(1000);
tud_task();
cdc_task();
}
return 0;