Skip to content

Commit

Permalink
Merge pull request #2834 from hathach/add-tusb_int_handler-update-tin…
Browse files Browse the repository at this point in the history
…yusb_init

add new tusb_int_handler(rhport, in_isr) and update tusb_init(rhport, role)
  • Loading branch information
hathach authored Oct 10, 2024
2 parents ffdf81f + 57aac43 commit a4fb835
Show file tree
Hide file tree
Showing 59 changed files with 187 additions and 281 deletions.
13 changes: 5 additions & 8 deletions docs/reference/getting_started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,19 @@ It is relatively simple to incorporate tinyusb to your project
* Add *your_project/tinyusb/src* to your include path. Also make sure your current include path also contains the configuration file tusb_config.h.
* Make sure all required macros are all defined properly in tusb_config.h (configure file in demo application is sufficient, but you need to add a few more such as CFG_TUSB_MCU, CFG_TUSB_OS since they are passed by IDE/compiler to maintain a unique configure for all boards).
* If you use the device stack, make sure you have created/modified usb descriptors for your own need. Ultimately you need to implement all **tud descriptor** callbacks for the stack to work.
* Add tusb_init() call to your reset initialization code.
* Call ``tud_int_handler()`` (device) and/or ``tuh_int_handler()`` (host) in your USB IRQ Handler
* Add tusb_init(rhport, role) call to your reset initialization code.
* Call ``tusb_int_handler(rhport, in_isr)`` in your USB IRQ Handler
* Implement all enabled classes's callbacks.
* If you don't use any RTOSes at all, you need to continuously and/or periodically call tud_task()/tuh_task() function. All of the callbacks and functionality are handled and invoked within the call of that task runner.

.. code-block::
int main(void)
{
int main(void) {
your_init_code();
tusb_init(); // initialize tinyusb stack
tusb_init(0, TUSB_ROLE_DEVICE); // initialize device stack on roothub port 0
while(1) // the mainloop
{
while(1) { // the mainloop
your_application_code();
tud_task(); // device task
tuh_task(); // host task
}
Expand Down
2 changes: 1 addition & 1 deletion examples/device/audio_4_channel_mic/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ int main(void)
board_init();

// init device stack on configured roothub port
tud_init(BOARD_TUD_RHPORT);
tusb_init(BOARD_TUD_RHPORT, TUSB_ROLE_DEVICE);

if (board_init_after_tusb) {
board_init_after_tusb();
Expand Down
2 changes: 1 addition & 1 deletion examples/device/audio_4_channel_mic_freertos/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ void usb_device_task(void* param)
// init device stack on configured roothub port
// This should be called after scheduler/kernel is started.
// Otherwise it could cause kernel issue since USB IRQ handler does use RTOS queue API.
tud_init(BOARD_TUD_RHPORT);
tusb_init(BOARD_TUD_RHPORT, TUSB_ROLE_DEVICE);

if (board_init_after_tusb) {
board_init_after_tusb();
Expand Down
2 changes: 1 addition & 1 deletion examples/device/audio_test/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ int main(void)
board_init();

// init device stack on configured roothub port
tud_init(BOARD_TUD_RHPORT);
tusb_init(BOARD_TUD_RHPORT, TUSB_ROLE_DEVICE);

if (board_init_after_tusb) {
board_init_after_tusb();
Expand Down
2 changes: 1 addition & 1 deletion examples/device/audio_test_freertos/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ void usb_device_task(void* param)
// init device stack on configured roothub port
// This should be called after scheduler/kernel is started.
// Otherwise it could cause kernel issue since USB IRQ handler does use RTOS queue API.
tud_init(BOARD_TUD_RHPORT);
tusb_init(BOARD_TUD_RHPORT, TUSB_ROLE_DEVICE);

if (board_init_after_tusb) {
board_init_after_tusb();
Expand Down
2 changes: 1 addition & 1 deletion examples/device/audio_test_multi_rate/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ int main(void)
board_init();

// init device stack on configured roothub port
tud_init(BOARD_TUD_RHPORT);
tusb_init(BOARD_TUD_RHPORT, TUSB_ROLE_DEVICE);

if (board_init_after_tusb) {
board_init_after_tusb();
Expand Down
5 changes: 0 additions & 5 deletions examples/device/board_test/src/tusb_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@
extern "C" {
#endif

// board_test example is special example that doesn't enable device or host stack
// This can cause some TinyUSB API missing, this define hack to allow us to fill those API
// to pass the compilation process
#define tud_int_handler(x)

//--------------------------------------------------------------------
// COMMON CONFIGURATION
//--------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion examples/device/cdc_dual_ports/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ int main(void) {
board_init();

// init device stack on configured roothub port
tud_init(BOARD_TUD_RHPORT);
tusb_init(BOARD_TUD_RHPORT, TUSB_ROLE_DEVICE);

if (board_init_after_tusb) {
board_init_after_tusb();
Expand Down
2 changes: 1 addition & 1 deletion examples/device/cdc_msc/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ int main(void) {
board_init();

// init device stack on configured roothub port
tud_init(BOARD_TUD_RHPORT);
tusb_init(BOARD_TUD_RHPORT, TUSB_ROLE_DEVICE);

if (board_init_after_tusb) {
board_init_after_tusb();
Expand Down
2 changes: 1 addition & 1 deletion examples/device/cdc_msc_freertos/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ static void usb_device_task(void *param) {
// init device stack on configured roothub port
// This should be called after scheduler/kernel is started.
// Otherwise it could cause kernel issue since USB IRQ handler does use RTOS queue API.
tud_init(BOARD_TUD_RHPORT);
tusb_init(BOARD_TUD_RHPORT, TUSB_ROLE_DEVICE);

if (board_init_after_tusb) {
board_init_after_tusb();
Expand Down
2 changes: 1 addition & 1 deletion examples/device/cdc_uac2/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ int main(void)
board_init();

// init device stack on configured roothub port
tud_init(BOARD_TUD_RHPORT);
tusb_init(BOARD_TUD_RHPORT, TUSB_ROLE_DEVICE);

#if (CFG_TUSB_MCU == OPT_MCU_RP2040)
stdio_init_all();
Expand Down
2 changes: 1 addition & 1 deletion examples/device/dfu/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ int main(void)
board_init();

// init device stack on configured roothub port
tud_init(BOARD_TUD_RHPORT);
tusb_init(BOARD_TUD_RHPORT, TUSB_ROLE_DEVICE);

if (board_init_after_tusb) {
board_init_after_tusb();
Expand Down
2 changes: 1 addition & 1 deletion examples/device/dfu_runtime/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ int main(void)
board_init();

// init device stack on configured roothub port
tud_init(BOARD_TUD_RHPORT);
tusb_init(BOARD_TUD_RHPORT, TUSB_ROLE_DEVICE);

if (board_init_after_tusb) {
board_init_after_tusb();
Expand Down
2 changes: 1 addition & 1 deletion examples/device/dynamic_configuration/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ int main(void)
board_init();

// init device stack on configured roothub port
tud_init(BOARD_TUD_RHPORT);
tusb_init(BOARD_TUD_RHPORT, TUSB_ROLE_DEVICE);

if (board_init_after_tusb) {
board_init_after_tusb();
Expand Down
2 changes: 1 addition & 1 deletion examples/device/hid_boot_interface/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ int main(void)
board_init();

// init device stack on configured roothub port
tud_init(BOARD_TUD_RHPORT);
tusb_init(BOARD_TUD_RHPORT, TUSB_ROLE_DEVICE);

if (board_init_after_tusb) {
board_init_after_tusb();
Expand Down
2 changes: 1 addition & 1 deletion examples/device/hid_composite/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ int main(void)
board_init();

// init device stack on configured roothub port
tud_init(BOARD_TUD_RHPORT);
tusb_init(BOARD_TUD_RHPORT, TUSB_ROLE_DEVICE);

if (board_init_after_tusb) {
board_init_after_tusb();
Expand Down
2 changes: 1 addition & 1 deletion examples/device/hid_composite_freertos/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ void usb_device_task(void* param)
// init device stack on configured roothub port
// This should be called after scheduler/kernel is started.
// Otherwise it could cause kernel issue since USB IRQ handler does use RTOS queue API.
tud_init(BOARD_TUD_RHPORT);
tusb_init(BOARD_TUD_RHPORT, TUSB_ROLE_DEVICE);

if (board_init_after_tusb) {
board_init_after_tusb();
Expand Down
2 changes: 1 addition & 1 deletion examples/device/hid_generic_inout/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ int main(void)
board_init();

// init device stack on configured roothub port
tud_init(BOARD_TUD_RHPORT);
tusb_init(BOARD_TUD_RHPORT, TUSB_ROLE_DEVICE);

if (board_init_after_tusb) {
board_init_after_tusb();
Expand Down
2 changes: 1 addition & 1 deletion examples/device/hid_multiple_interface/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ int main(void)
board_init();

// init device stack on configured roothub port
tud_init(BOARD_TUD_RHPORT);
tusb_init(BOARD_TUD_RHPORT, TUSB_ROLE_DEVICE);

if (board_init_after_tusb) {
board_init_after_tusb();
Expand Down
2 changes: 1 addition & 1 deletion examples/device/midi_test/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ int main(void)
board_init();

// init device stack on configured roothub port
tud_init(BOARD_TUD_RHPORT);
tusb_init(BOARD_TUD_RHPORT, TUSB_ROLE_DEVICE);

if (board_init_after_tusb) {
board_init_after_tusb();
Expand Down
2 changes: 1 addition & 1 deletion examples/device/msc_dual_lun/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ int main(void) {
board_init();

// init device stack on configured roothub port
tud_init(BOARD_TUD_RHPORT);
tusb_init(BOARD_TUD_RHPORT, TUSB_ROLE_DEVICE);

if (board_init_after_tusb) {
board_init_after_tusb();
Expand Down
2 changes: 1 addition & 1 deletion examples/device/net_lwip_webserver/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ int main(void) {
board_init();

// init device stack on configured roothub port
tud_init(BOARD_TUD_RHPORT);
tusb_init(BOARD_TUD_RHPORT, TUSB_ROLE_DEVICE);

if (board_init_after_tusb) {
board_init_after_tusb();
Expand Down
2 changes: 1 addition & 1 deletion examples/device/uac2_headset/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ int main(void)
board_init();

// init device stack on configured roothub port
tud_init(BOARD_TUD_RHPORT);
tusb_init(BOARD_TUD_RHPORT, TUSB_ROLE_DEVICE);

if (board_init_after_tusb) {
board_init_after_tusb();
Expand Down
2 changes: 1 addition & 1 deletion examples/device/uac2_speaker_fb/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ int main(void)
board_init();

// init device stack on configured roothub port
tud_init(BOARD_TUD_RHPORT);
tusb_init(BOARD_TUD_RHPORT, TUSB_ROLE_DEVICE);

if (board_init_after_tusb) {
board_init_after_tusb();
Expand Down
2 changes: 1 addition & 1 deletion examples/device/usbtmc/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ int main(void)
board_init();

// init device stack on configured roothub port
tud_init(BOARD_TUD_RHPORT);
tusb_init(BOARD_TUD_RHPORT, TUSB_ROLE_DEVICE);

if (board_init_after_tusb) {
board_init_after_tusb();
Expand Down
4 changes: 2 additions & 2 deletions examples/device/video_capture/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ int main(void) {
freertos_init_task();
#else
// init device stack on configured roothub port
tud_init(BOARD_TUD_RHPORT);
tusb_init(BOARD_TUD_RHPORT, TUSB_ROLE_DEVICE);

if (board_init_after_tusb) {
board_init_after_tusb();
Expand Down Expand Up @@ -319,7 +319,7 @@ void usb_device_task(void *param) {
// init device stack on configured roothub port
// This should be called after scheduler/kernel is started.
// Otherwise, it could cause kernel issue since USB IRQ handler does use RTOS queue API.
tud_init(BOARD_TUD_RHPORT);
tusb_init(BOARD_TUD_RHPORT, TUSB_ROLE_DEVICE);

if (board_init_after_tusb) {
board_init_after_tusb();
Expand Down
4 changes: 2 additions & 2 deletions examples/device/video_capture_2ch/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ int main(void) {
freertos_init_task();
#else
// init device stack on configured roothub port
tud_init(BOARD_TUD_RHPORT);
tusb_init(BOARD_TUD_RHPORT, TUSB_ROLE_DEVICE);

if (board_init_after_tusb) {
board_init_after_tusb();
Expand Down Expand Up @@ -327,7 +327,7 @@ void usb_device_task(void *param) {
// init device stack on configured roothub port
// This should be called after scheduler/kernel is started.
// Otherwise, it could cause kernel issue since USB IRQ handler does use RTOS queue API.
tud_init(BOARD_TUD_RHPORT);
tusb_init(BOARD_TUD_RHPORT, TUSB_ROLE_DEVICE);

if (board_init_after_tusb) {
board_init_after_tusb();
Expand Down
2 changes: 1 addition & 1 deletion examples/device/webusb_serial/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ int main(void) {
board_init();

// init device stack on configured roothub port
tud_init(BOARD_TUD_RHPORT);
tusb_init(BOARD_TUD_RHPORT, TUSB_ROLE_DEVICE);

if (board_init_after_tusb) {
board_init_after_tusb();
Expand Down
4 changes: 2 additions & 2 deletions examples/dual/host_hid_to_device_cdc/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ int main(void) {
printf("TinyUSB Host HID <-> Device CDC Example\r\n");

// init device and host stack on configured roothub port
tud_init(BOARD_TUD_RHPORT);
tuh_init(BOARD_TUH_RHPORT);
tusb_init(BOARD_TUD_RHPORT, TUSB_ROLE_DEVICE);
tusb_init(BOARD_TUH_RHPORT, TUSB_ROLE_HOST);

if (board_init_after_tusb) {
board_init_after_tusb();
Expand Down
4 changes: 2 additions & 2 deletions examples/dual/host_info_to_device_cdc/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ int main(void) {
printf("TinyUSB Host Information -> Device CDC Example\r\n");

// init device and host stack on configured roothub port
tud_init(BOARD_TUD_RHPORT);
tuh_init(BOARD_TUH_RHPORT);
tusb_init(BOARD_TUD_RHPORT, TUSB_ROLE_DEVICE);
tusb_init(BOARD_TUH_RHPORT, TUSB_ROLE_HOST);

if (board_init_after_tusb) {
board_init_after_tusb();
Expand Down
2 changes: 1 addition & 1 deletion examples/host/bare_api/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ int main(void)
printf("TinyUSB Bare API Example\r\n");

// init host stack on configured roothub port
tuh_init(BOARD_TUH_RHPORT);
tusb_init(BOARD_TUH_RHPORT, TUSB_ROLE_HOST);

if (board_init_after_tusb) {
board_init_after_tusb();
Expand Down
2 changes: 1 addition & 1 deletion examples/host/cdc_msc_hid/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ int main(void) {
printf("TinyUSB Host CDC MSC HID Example\r\n");

// init host stack on configured roothub port
tuh_init(BOARD_TUH_RHPORT);
tusb_init(BOARD_TUH_RHPORT, TUSB_ROLE_HOST);

if (board_init_after_tusb) {
board_init_after_tusb();
Expand Down
2 changes: 1 addition & 1 deletion examples/host/cdc_msc_hid_freertos/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ static void usb_host_task(void *param) {
(void) param;

// init host stack on configured roothub port
if (!tuh_init(BOARD_TUH_RHPORT)) {
if (!tusb_init(BOARD_TUH_RHPORT, TUSB_ROLE_HOST)) {
printf("Failed to init USB Host Stack\r\n");
vTaskSuspend(NULL);
}
Expand Down
8 changes: 4 additions & 4 deletions examples/host/device_info/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ add_executable(${PROJECT})

# Example source
target_sources(${PROJECT} PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/src/main.c
)
${CMAKE_CURRENT_SOURCE_DIR}/src/main.c
)

# Example include
target_include_directories(${PROJECT} PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/src
)
${CMAKE_CURRENT_SOURCE_DIR}/src
)

# Configure compilation flags and libraries for the example without RTOS.
# See the corresponding function in hw/bsp/FAMILY/family.cmake for details.
Expand Down
4 changes: 2 additions & 2 deletions examples/host/device_info/only.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ mcu:LPC177X_8X
mcu:LPC18XX
mcu:LPC40XX
mcu:LPC43XX
mcu:MAX3421
mcu:MIMXRT1XXX
mcu:MIMXRT10XX
mcu:MIMXRT11XX
mcu:RP2040
mcu:MSP432E4
mcu:RP2040
mcu:RX65X
mcu:RAXXX
mcu:MAX3421
2 changes: 1 addition & 1 deletion examples/host/device_info/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ int main(void) {
printf("TinyUSB Device Info Example\r\n");

// init host stack on configured roothub port
tuh_init(BOARD_TUH_RHPORT);
tusb_init(BOARD_TUH_RHPORT, TUSB_ROLE_HOST);

if (board_init_after_tusb) {
board_init_after_tusb();
Expand Down
2 changes: 1 addition & 1 deletion examples/host/hid_controller/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ int main(void)
printf("Note: Events only displayed for explicit supported controllers\r\n");

// init host stack on configured roothub port
tuh_init(BOARD_TUH_RHPORT);
tusb_init(BOARD_TUH_RHPORT, TUSB_ROLE_HOST);

if (board_init_after_tusb) {
board_init_after_tusb();
Expand Down
2 changes: 1 addition & 1 deletion examples/host/msc_file_explorer/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ int main(void) {
printf("TinyUSB Host MassStorage Explorer Example\r\n");

// init host stack on configured roothub port
tuh_init(BOARD_TUH_RHPORT);
tusb_init(BOARD_TUH_RHPORT, TUSB_ROLE_HOST);

if (board_init_after_tusb) {
board_init_after_tusb();
Expand Down
Loading

0 comments on commit a4fb835

Please sign in to comment.