update TinyUSB examples for latest TinyUSB (#325)

This commit is contained in:
Graham Sanderson
2023-02-06 16:56:50 -06:00
committed by GitHub
parent 9600dec1f0
commit f3f5d9fe61
11 changed files with 196 additions and 90 deletions

View File

@@ -35,7 +35,7 @@
//--------------------------------------------------------------------+
void led_blinking_task(void);
extern void cdc_task(void);
extern void cdc_app_task(void);
extern void hid_app_task(void);
/*------------- MAIN -------------*/
@@ -45,38 +45,30 @@ int main(void)
printf("TinyUSB Host CDC MSC HID Example\r\n");
tusb_init();
// init host stack on configured roothub port
tuh_init(BOARD_TUH_RHPORT);
while (1)
{
// tinyusb host task
tuh_task();
led_blinking_task();
#if CFG_TUH_CDC
cdc_task();
#endif
#if CFG_TUH_HID
cdc_app_task();
hid_app_task();
#endif
}
return 0;
}
//--------------------------------------------------------------------+
// USB CDC
// TinyUSB Callbacks
//--------------------------------------------------------------------+
#if CFG_TUH_CDC
CFG_TUSB_MEM_SECTION static char serial_in_buffer[64] = { 0 };
void tuh_mount_cb(uint8_t dev_addr)
{
// application set-up
printf("A device with address %d is mounted\r\n", dev_addr);
tuh_cdc_receive(dev_addr, serial_in_buffer, sizeof(serial_in_buffer), true); // schedule first transfer
}
void tuh_umount_cb(uint8_t dev_addr)
@@ -85,29 +77,6 @@ void tuh_umount_cb(uint8_t dev_addr)
printf("A device with address %d is unmounted \r\n", dev_addr);
}
// invoked ISR context
void tuh_cdc_xfer_isr(uint8_t dev_addr, xfer_result_t event, cdc_pipeid_t pipe_id, uint32_t xferred_bytes)
{
(void) event;
(void) pipe_id;
(void) xferred_bytes;
printf(serial_in_buffer);
tu_memclr(serial_in_buffer, sizeof(serial_in_buffer));
tuh_cdc_receive(dev_addr, serial_in_buffer, sizeof(serial_in_buffer), true); // waiting for next data
}
void cdc_task(void)
{
}
#endif
//--------------------------------------------------------------------+
// TinyUSB Callbacks
//--------------------------------------------------------------------+
//--------------------------------------------------------------------+
// Blinking Task