/* * The MIT License (MIT) * * Copyright (c) 2019 Ha Thach (tinyusb.org) * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * */ #include #include #include #include #include #include #define LED_BLINK_DELAY_MS 1000 extern void cdc_app_task(void); /*------------- MAIN -------------*/ int main(void) { board_init(); gpio_set_function(12, UART_FUNCSEL_NUM(uart0, 12)); gpio_set_function(13, UART_FUNCSEL_NUM(uart0, 13)); printf("TinyUSB Host CDC Example\n"); // init host stack on configured roothub port const tusb_rhport_init_t rh_init = { .role = TUSB_ROLE_HOST, .speed = TUH_OPT_HIGH_SPEED ? TUSB_SPEED_HIGH : TUSB_SPEED_FULL, }; if(!tuh_rhport_init(BOARD_TUH_RHPORT, &rh_init)) { printf("Failed to init rhport.\n"); return PICO_ERROR_GENERIC; } uint32_t start_ms = 0; bool led_state = false; while(true) { // tinyusb host task tuh_task(); if(board_millis() - start_ms > LED_BLINK_DELAY_MS) { board_led_write(led_state); led_state = ! led_state; start_ms += LED_BLINK_DELAY_MS; } cdc_app_task(); } } // TinyUSB Callbacks void tuh_mount_cb(uint8_t dev_addr) { // application set-up printf("A device with address %d is mounted\r\n", dev_addr); } void tuh_umount_cb(uint8_t dev_addr) { // application tear-down printf("A device with address %d is unmounted \r\n", dev_addr); }