more on wk emulation

This commit is contained in:
Martin Brodbeck 2024-02-26 12:06:09 +01:00
parent 97e1f53bfe
commit 7a5d0b97e7

View file

@ -104,7 +104,7 @@ void core1_main()
} }
} }
[[maybe_unused]] static void echo_serial_port(uint8_t itf, uint8_t buf[], uint32_t count) static void usbSend(uint8_t itf, uint8_t buf[], uint32_t count)
{ {
for (uint32_t i = 0; i < count; i++) { for (uint32_t i = 0; i < count; i++) {
tud_cdc_n_write_char(itf, buf[i]); tud_cdc_n_write_char(itf, buf[i]);
@ -113,23 +113,40 @@ void core1_main()
tud_cdc_n_write_flush(itf); tud_cdc_n_write_flush(itf);
} }
static void usbSend(uint8_t itf, uint8_t value) {
tud_cdc_n_write_char(itf, value);
tud_cdc_n_write_flush(itf);
}
void cdc_task() void cdc_task()
{ {
const uint8_t UsbInIf = 1; const uint8_t USB_IF = 0;
if (tud_cdc_n_available(UsbInIf)) { if (tud_cdc_n_available(USB_IF)) {
uint8_t buf[64]; uint8_t buf[64];
uint32_t count = tud_cdc_n_read(UsbInIf, buf, sizeof(buf)); //printf("AHA!!! %d\n", (int)tud_cdc_n_available(USB_IF));
if (count > 1) { uint32_t count = tud_cdc_n_read(USB_IF, buf, sizeof(buf));
printf("Command received …\n");
if (count > 0) {
switch (buf[0]) { switch (buf[0]) {
case 0: // ADMIN COMMAND case 'a' ... 'z':
case 'A' ... 'Z':
case '0' ... '9':
printf("TODO: Send it!\n");
break;
case 0x00: // ADMIN COMMAND
switch (buf[1]) { switch (buf[1]) {
case 2: // Host Open case 0x02: // Host open
// TODO: send back revision code usbSend(USB_IF, 9); // Send WK1 (v9) for now (no WinKeyer PTT control)
break;
case 0x04: // Echo test
printf("Echo test: %x\n", buf[2]);
printf("buf address: %p\n", &buf[2]);
usbSend(USB_IF, &buf[2], 1);
break;
default: default:
printf("Unknown admin command.\n"); printf("Unknown admin command: %x\n", buf[1]);
} }
break; break;
default: default:
@ -204,7 +221,7 @@ int main()
lastWpm = currentWpm; lastWpm = currentWpm;
} }
busy_wait_ms(5000); //busy_wait_ms(5000);
if (!used) { if (!used) {
//KeyerQueueData keyerQueueData {KeyerQueueCommand::SendMessage, 0, settings.mode, "cq cq de dg2smb dg2smb pse k"}; //KeyerQueueData keyerQueueData {KeyerQueueCommand::SendMessage, 0, settings.mode, "cq cq de dg2smb dg2smb pse k"};
//queue_add_blocking(&keyerQueue, &keyerQueueData); //queue_add_blocking(&keyerQueue, &keyerQueueData);