improve memory management & polling
This commit is contained in:
@@ -12,61 +12,51 @@
|
||||
#include "usb_device.h"
|
||||
#include "usb_host.h"
|
||||
|
||||
static void usb_main(void);
|
||||
|
||||
// main loop
|
||||
int main(void) {
|
||||
|
||||
set_sys_clock_khz(192000, true);
|
||||
set_sys_clock_khz(144000, true);
|
||||
|
||||
sleep_ms(10);
|
||||
|
||||
// setup BLE on core 1
|
||||
// run BLE on core 1
|
||||
multicore_reset_core1();
|
||||
multicore_launch_core1(btstack_main);
|
||||
|
||||
// run usb on core 0
|
||||
usb_main();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void usb_main(void) {
|
||||
// init and run usb host
|
||||
usb_host_init();
|
||||
|
||||
// init and run usb device
|
||||
//usb_device_init();
|
||||
usb_device_init();
|
||||
|
||||
while (true) {
|
||||
switch ( get_host_state() ) {
|
||||
switch ( host_state ) {
|
||||
case HOST_NEW_DESCRIPTOR:
|
||||
if ( host_ready() ) {
|
||||
if(generate_report_descriptor()) {
|
||||
if ( get_desc_hid_report_len() > 0 ) {
|
||||
set_host_state(HOST_MOUNTED);
|
||||
cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN, 1);
|
||||
} else {
|
||||
set_host_state(HOST_INACTIVE);
|
||||
}
|
||||
cdc_print_msg("Updating HID report map\n");
|
||||
update_desc_hid_report();
|
||||
}
|
||||
}
|
||||
host_ready();
|
||||
break;
|
||||
case HOST_START_LISTEN:
|
||||
if (request_hid_reports_all()) {
|
||||
set_host_state(HOST_LISTENING);
|
||||
} else {
|
||||
cdc_print_msg("Error listening to input report(s)\n");
|
||||
set_host_state(HOST_INACTIVE);
|
||||
}
|
||||
request_hid_reports_all();
|
||||
break;
|
||||
case HOST_STOP_LISTEN:
|
||||
if (stop_hid_reports_all()) {
|
||||
set_host_state(HOST_INACTIVE);
|
||||
} else {
|
||||
cdc_print_msg("Error stopping input report(s)\n");
|
||||
}
|
||||
stop_hid_reports_all();
|
||||
break;
|
||||
case HOST_POLL:
|
||||
poll_devices();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
tuh_task(); // tinyusb host task
|
||||
//tud_task(); // tinyusb device task
|
||||
//tud_cdc_write_flush();
|
||||
tud_task(); // tinyusb device task
|
||||
tud_cdc_write_flush();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user