From 86d371fb79ca8b1ee6794c33b6a74d4319d9c1a6 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 12 Feb 2025 13:58:01 +0700 Subject: [PATCH] more ci fix --- examples/host/device_info/src/tusb_config.h | 3 +- examples/host/midi_rx/src/main.c | 131 +++++++++----------- examples/host/midi_rx/src/tusb_config.h | 77 ++++++++---- hw/bsp/rp2040/family.c | 4 +- 4 files changed, 117 insertions(+), 98 deletions(-) diff --git a/examples/host/device_info/src/tusb_config.h b/examples/host/device_info/src/tusb_config.h index 5190b5b1f..27dd07e25 100644 --- a/examples/host/device_info/src/tusb_config.h +++ b/examples/host/device_info/src/tusb_config.h @@ -109,8 +109,7 @@ // only hub class is enabled #define CFG_TUH_HUB 1 -// max device support (excluding hub device) -// 1 hub typically has 4 ports +// max device support (excluding hub device): 1 hub typically has 4 ports #define CFG_TUH_DEVICE_MAX (3*CFG_TUH_HUB + 1) #ifdef __cplusplus diff --git a/examples/host/midi_rx/src/main.c b/examples/host/midi_rx/src/main.c index 8b83977e2..a03fd588f 100644 --- a/examples/host/midi_rx/src/main.c +++ b/examples/host/midi_rx/src/main.c @@ -23,8 +23,8 @@ * */ -#include #include +#include #include #include "bsp/board_api.h" @@ -44,22 +44,25 @@ void led_blinking_task(void); void midi_host_rx_task(void); /*------------- MAIN -------------*/ -int main(void) -{ - board_init(); +int main(void) { + board_init(); - printf("TinyUSB Host MIDI Example\r\n"); + printf("TinyUSB Host MIDI Example\r\n"); - tusb_init(); + // init host stack on configured roothub port + tusb_rhport_init_t host_init = { + .role = TUSB_ROLE_HOST, + .speed = TUSB_SPEED_AUTO + }; + tusb_init(BOARD_TUH_RHPORT, &host_init); - while (1) - { - tuh_task(); - led_blinking_task(); - midi_host_rx_task(); - } + while (1) { + tuh_task(); + led_blinking_task(); + midi_host_rx_task(); + } - return 0; + return 0; } #endif @@ -67,36 +70,32 @@ int main(void) //--------------------------------------------------------------------+ // Blinking Task //--------------------------------------------------------------------+ -void led_blinking_task(void) -{ - const uint32_t interval_ms = 1000; - static uint32_t start_ms = 0; +void led_blinking_task(void) { + const uint32_t interval_ms = 1000; + static uint32_t start_ms = 0; - static bool led_state = false; + static bool led_state = false; - // Blink every interval ms - if ( board_millis() - start_ms < interval_ms) return; // not enough time - start_ms += interval_ms; + // Blink every interval ms + if (board_millis() - start_ms < interval_ms) return;// not enough time + start_ms += interval_ms; - board_led_write(led_state); - led_state = 1 - led_state; // toggle + board_led_write(led_state); + led_state = 1 - led_state;// toggle } //--------------------------------------------------------------------+ // MIDI host receive task //--------------------------------------------------------------------+ -void midi_host_rx_task(void) -{ - // device must be attached and have at least one endpoint ready to receive a message - if (!midi_dev_addr || !tuh_midi_configured(midi_dev_addr)) - { - return; - } - if (tuh_midih_get_num_rx_cables(midi_dev_addr) < 1) - { - return; - } - tuh_midi_read_poll(midi_dev_addr); +void midi_host_rx_task(void) { + // device must be attached and have at least one endpoint ready to receive a message + if (!midi_dev_addr || !tuh_midi_configured(midi_dev_addr)) { + return; + } + if (tuh_midih_get_num_rx_cables(midi_dev_addr) < 1) { + return; + } + tuh_midi_read_poll(midi_dev_addr); } //--------------------------------------------------------------------+ @@ -108,51 +107,45 @@ void midi_host_rx_task(void) // can be used to parse common/simple enough descriptor. // Note: if report descriptor length > CFG_TUH_ENUMERATION_BUFSIZE, it will be skipped // therefore report_desc = NULL, desc_len = 0 -void tuh_midi_mount_cb(uint8_t dev_addr, uint8_t in_ep, uint8_t out_ep, uint8_t num_cables_rx, uint16_t num_cables_tx) -{ - (void ) in_ep; - (void ) out_ep; - (void ) num_cables_rx; - (void ) num_cables_tx; +void tuh_midi_mount_cb(uint8_t dev_addr, uint8_t in_ep, uint8_t out_ep, uint8_t num_cables_rx, uint16_t num_cables_tx) { + (void) in_ep; + (void) out_ep; + (void) num_cables_rx; + (void) num_cables_tx; - TU_LOG1("MIDI device address = %u, IN endpoint %u has %u cables, OUT endpoint %u has %u cables\r\n", - dev_addr, in_ep & 0xf, num_cables_rx, out_ep & 0xf, num_cables_tx); + TU_LOG1("MIDI device address = %u, IN endpoint %u has %u cables, OUT endpoint %u has %u cables\r\n", + dev_addr, in_ep & 0xf, num_cables_rx, out_ep & 0xf, num_cables_tx); - midi_dev_addr = dev_addr; + midi_dev_addr = dev_addr; } // Invoked when device with hid interface is un-mounted -void tuh_midi_umount_cb(uint8_t dev_addr, uint8_t instance) -{ - (void ) dev_addr; - (void ) instance; +void tuh_midi_umount_cb(uint8_t dev_addr, uint8_t instance) { + (void) dev_addr; + (void) instance; - TU_LOG1("MIDI device address = %d, instance = %d is unmounted\r\n", dev_addr, instance); - midi_dev_addr = 0; + TU_LOG1("MIDI device address = %d, instance = %d is unmounted\r\n", dev_addr, instance); + midi_dev_addr = 0; } -void tuh_midi_rx_cb(uint8_t dev_addr, uint32_t num_packets) -{ - if (midi_dev_addr != dev_addr) - { - return; - } +void tuh_midi_rx_cb(uint8_t dev_addr, uint32_t num_packets) { + if (midi_dev_addr != dev_addr) { + return; + } - if(num_packets == 0) - { - return; - } + if (num_packets == 0) { + return; + } - uint8_t cable_num; - uint8_t buffer[48]; - uint32_t bytes_read = tuh_midi_stream_read(dev_addr, &cable_num, buffer, sizeof(buffer)); - (void ) bytes_read; + uint8_t cable_num; + uint8_t buffer[48]; + uint32_t bytes_read = tuh_midi_stream_read(dev_addr, &cable_num, buffer, sizeof(buffer)); + (void) bytes_read; - TU_LOG1("Read bytes %lu cable %u", bytes_read, cable_num); - TU_LOG1_MEM(buffer, bytes_read, 2); + TU_LOG1("Read bytes %lu cable %u", bytes_read, cable_num); + TU_LOG1_MEM(buffer, bytes_read, 2); } -void tuh_midi_tx_cb(uint8_t dev_addr) -{ - (void ) dev_addr; +void tuh_midi_tx_cb(uint8_t dev_addr) { + (void) dev_addr; } diff --git a/examples/host/midi_rx/src/tusb_config.h b/examples/host/midi_rx/src/tusb_config.h index 5cc354ea9..1afcbbd63 100644 --- a/examples/host/midi_rx/src/tusb_config.h +++ b/examples/host/midi_rx/src/tusb_config.h @@ -23,15 +23,15 @@ * */ -#ifndef _TUSB_CONFIG_H_ -#define _TUSB_CONFIG_H_ +#ifndef TUSB_CONFIG_H_ +#define TUSB_CONFIG_H_ #ifdef __cplusplus extern "C" { #endif //-------------------------------------------------------------------- -// COMMON CONFIGURATION +// Common Configuration //-------------------------------------------------------------------- // defined by compiler flags for flexibility @@ -39,18 +39,18 @@ extern "C" { #error CFG_TUSB_MCU must be defined #endif -#if CFG_TUSB_MCU == OPT_MCU_LPC43XX || CFG_TUSB_MCU == OPT_MCU_LPC18XX || CFG_TUSB_MCU == OPT_MCU_MIMXRT10XX -#define CFG_TUSB_RHPORT0_MODE (OPT_MODE_HOST | OPT_MODE_HIGH_SPEED) -#else -#define CFG_TUSB_RHPORT0_MODE OPT_MODE_HOST +// Espressif IDF requires "freertos/" prefix in include path +#if TUSB_MCU_VENDOR_ESPRESSIF +#define CFG_TUSB_OS_INC_PATH freertos/ #endif #ifndef CFG_TUSB_OS -#define CFG_TUSB_OS OPT_OS_NONE +#define CFG_TUSB_OS OPT_OS_NONE #endif -// CFG_TUSB_DEBUG is defined by compiler in DEBUG build -// #define CFG_TUSB_DEBUG 0 +#ifndef CFG_TUSB_DEBUG +#define CFG_TUSB_DEBUG 0 +#endif /* USB DMA on some MCUs can only access a specific SRAM region with restriction on alignment. * Tinyusb use follows macros to declare transferring memory so that they can be put @@ -59,38 +59,63 @@ extern "C" { * - CFG_TUSB_MEM SECTION : __attribute__ (( section(".usb_ram") )) * - CFG_TUSB_MEM_ALIGN : __attribute__ ((aligned(4))) */ -#ifndef CFG_TUSB_MEM_SECTION -#define CFG_TUSB_MEM_SECTION +#ifndef CFG_TUH_MEM_SECTION +#define CFG_TUH_MEM_SECTION #endif -#ifndef CFG_TUSB_MEM_ALIGN -#define CFG_TUSB_MEM_ALIGN __attribute__ ((aligned(4))) +#ifndef CFG_TUH_MEM_ALIGN +#define CFG_TUH_MEM_ALIGN __attribute__ ((aligned(4))) #endif //-------------------------------------------------------------------- -// CONFIGURATION +// Host Configuration +//-------------------------------------------------------------------- + +// Enable Host stack +#define CFG_TUH_ENABLED 1 + +#if CFG_TUSB_MCU == OPT_MCU_RP2040 + // #define CFG_TUH_RPI_PIO_USB 1 // use pio-usb as host controller + // #define CFG_TUH_MAX3421 1 // use max3421 as host controller + + // host roothub port is 1 if using either pio-usb or max3421 + #if (defined(CFG_TUH_RPI_PIO_USB) && CFG_TUH_RPI_PIO_USB) || (defined(CFG_TUH_MAX3421) && CFG_TUH_MAX3421) + #define BOARD_TUH_RHPORT 1 + #endif +#endif + +// Default is max speed that hardware controller could support with on-chip PHY +#define CFG_TUH_MAX_SPEED BOARD_TUH_MAX_SPEED + +//------------------------- Board Specific -------------------------- + +// RHPort number used for host can be defined by board.mk, default to port 0 +#ifndef BOARD_TUH_RHPORT +#define BOARD_TUH_RHPORT 0 +#endif + +// RHPort max operational speed can defined by board.mk +#ifndef BOARD_TUH_MAX_SPEED +#define BOARD_TUH_MAX_SPEED OPT_MODE_DEFAULT_SPEED +#endif + +//-------------------------------------------------------------------- +// Driver Configuration //-------------------------------------------------------------------- // Size of buffer to hold descriptors and other data used for enumeration #define CFG_TUH_ENUMERATION_BUFSIZE 256 #define CFG_TUH_HUB 1 -#define CFG_TUH_CDC 0 -#define CFG_TUH_HID 0 // typical keyboard + mouse device can have 3-4 HID interfaces #define CFG_TUH_MIDI 1 // there will be at most one MIDIStreaming Interface descriptor -#define CFG_TUH_MSC 0 -#define CFG_TUH_VENDOR 0 -// max device support (excluding hub device) -#define CFG_TUH_DEVICE_MAX (CFG_TUH_HUB ? 4 : 1) // hub typically has 4 ports +// max device support (excluding hub device): 1 hub typically has 4 ports +#define CFG_TUH_DEVICE_MAX (3*CFG_TUH_HUB + 1) + #define CFG_MIDI_HOST_DEVSTRINGS 1 -//------------- HID -------------// -#define CFG_TUH_HID_EPIN_BUFSIZE 64 -#define CFG_TUH_HID_EPOUT_BUFSIZE 64 - #ifdef __cplusplus } #endif -#endif /* _TUSB_CONFIG_H_ */ +#endif diff --git a/hw/bsp/rp2040/family.c b/hw/bsp/rp2040/family.c index 24aa0b616..689e264bd 100644 --- a/hw/bsp/rp2040/family.c +++ b/hw/bsp/rp2040/family.c @@ -266,7 +266,9 @@ int board_getchar(void) { #if CFG_TUH_ENABLED && defined(CFG_TUH_MAX3421) && CFG_TUH_MAX3421 void max3421_int_handler(uint gpio, uint32_t event_mask) { - if (!(gpio == MAX3421_INTR_PIN && event_mask & GPIO_IRQ_EDGE_FALL)) return; + if (!(gpio == MAX3421_INTR_PIN && event_mask & GPIO_IRQ_EDGE_FALL)) { + return; + } tuh_int_handler(BOARD_TUH_RHPORT, true); }