Skip to content

Commit

Permalink
add support for native SAMD HCD
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisDeadman committed Oct 20, 2024
1 parent 8b1e40c commit 965e26d
Show file tree
Hide file tree
Showing 7 changed files with 806 additions and 14 deletions.
16 changes: 14 additions & 2 deletions hw/bsp/samd21/family.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,13 @@
// Forward USB interrupt events to TinyUSB IRQ Handler
//--------------------------------------------------------------------+
void USB_Handler(void) {
#if CFG_TUD_ENABLED
tud_int_handler(0);
#endif

#if CFG_TUH_ENABLED && !(defined(CFG_TUH_MAX3421) && CFG_TUH_MAX3421)
tuh_int_handler(0);
#endif
}

//--------------------------------------------------------------------+
Expand Down Expand Up @@ -140,8 +146,14 @@ void board_init(void) {
gpio_set_pin_function(PIN_PA19, PINMUX_PA19F_TCC0_WO3);
_gclk_enable_channel(TCC0_GCLK_ID, GCLK_CLKCTRL_GEN_GCLK0_Val);

#if CFG_TUH_ENABLED && defined(CFG_TUH_MAX3421) && CFG_TUH_MAX3421
max3421_init();
#if CFG_TUH_ENABLED
#if defined(CFG_TUH_MAX3421) && CFG_TUH_MAX3421
max3421_init();
#else
// VBUS Power
gpio_set_pin_direction(PIN_PA28, GPIO_DIRECTION_OUT);
gpio_set_pin_level(PIN_PA28, true);
#endif
#endif
}

Expand Down
1 change: 1 addition & 0 deletions hw/bsp/samd21/family.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ function(family_configure_example TARGET RTOS)
family_add_tinyusb(${TARGET} OPT_MCU_SAMD21 ${RTOS})
target_sources(${TARGET}-tinyusb PUBLIC
${TOP}/src/portable/microchip/samd/dcd_samd.c
${TOP}/src/portable/microchip/samd/hcd_samd.c
)
target_link_libraries(${TARGET}-tinyusb PUBLIC board_${BOARD})

Expand Down
1 change: 1 addition & 0 deletions hw/bsp/samd21/family.mk
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ LDFLAGS_CLANG +=

SRC_C += \
src/portable/microchip/samd/dcd_samd.c \
src/portable/microchip/samd/hcd_samd.c \
${SDK_DIR}/gcc/gcc/startup_samd21.c \
${SDK_DIR}/gcc/system_samd21.c \
${SDK_DIR}/hal/src/hal_atomic.c \
Expand Down
33 changes: 21 additions & 12 deletions hw/bsp/samd5x_e5x/family.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,24 @@
//--------------------------------------------------------------------+
// Forward USB interrupt events to TinyUSB IRQ Handler
//--------------------------------------------------------------------+
void USB_0_Handler(void) {
TU_ATTR_ALWAYS_INLINE inline void USB_Any_Handler(void)
{
#if CFG_TUD_ENABLED
tud_int_handler(0);
}
#endif

void USB_1_Handler(void) {
tud_int_handler(0);
#if CFG_TUH_ENABLED && !CFG_TUH_MAX3421
tuh_int_handler(0);
#endif
}

void USB_2_Handler(void) {
tud_int_handler(0);
}
void USB_0_Handler(void) { USB_Any_Handler(); }

void USB_3_Handler(void) {
tud_int_handler(0);
}
void USB_1_Handler(void) { USB_Any_Handler(); }

void USB_2_Handler(void) { USB_Any_Handler(); }

void USB_3_Handler(void) { USB_Any_Handler(); }

//--------------------------------------------------------------------+
// Implementation
Expand Down Expand Up @@ -138,8 +141,14 @@ void board_init(void) {
gpio_set_pin_function(PIN_PA24, PINMUX_PA24H_USB_DM);
gpio_set_pin_function(PIN_PA25, PINMUX_PA25H_USB_DP);

#if CFG_TUH_ENABLED && CFG_TUH_MAX3421
max3421_init();
#if CFG_TUH_ENABLED
#if defined(CFG_TUH_MAX3421) && CFG_TUH_MAX3421
max3421_init();
#else
// VBUS Power
gpio_set_pin_direction(PIN_PA28, GPIO_DIRECTION_OUT);
gpio_set_pin_level(PIN_PA28, true);
#endif
#endif
}

Expand Down
1 change: 1 addition & 0 deletions hw/bsp/samd5x_e5x/family.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ function(family_configure_example TARGET RTOS)
family_add_tinyusb(${TARGET} OPT_MCU_SAMD51 ${RTOS})
target_sources(${TARGET}-tinyusb PUBLIC
${TOP}/src/portable/microchip/samd/dcd_samd.c
${TOP}/src/portable/microchip/samd/hcd_samd.c
)
target_link_libraries(${TARGET}-tinyusb PUBLIC board_${BOARD})

Expand Down
1 change: 1 addition & 0 deletions hw/bsp/samd5x_e5x/family.mk
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ LDFLAGS_GCC += \

SRC_C += \
src/portable/microchip/samd/dcd_samd.c \
src/portable/microchip/samd/hcd_samd.c \
${SDK_DIR}/gcc/gcc/startup_${SAM_FAMILY}.c \
${SDK_DIR}/gcc/system_${SAM_FAMILY}.c \
${SDK_DIR}/hpl/gclk/hpl_gclk.c \
Expand Down
Loading

0 comments on commit 965e26d

Please sign in to comment.