Skip to content

Commit

Permalink
change dcd_init() return from void to bool
Browse files Browse the repository at this point in the history
  • Loading branch information
hathach committed Oct 14, 2024
1 parent 1f18be9 commit e83e083
Show file tree
Hide file tree
Showing 36 changed files with 103 additions and 49 deletions.
2 changes: 1 addition & 1 deletion src/device/dcd.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ void dcd_dcache_clean_invalidate(void const* addr, uint32_t data_size) TU_ATTR_W
//--------------------------------------------------------------------+

// Initialize controller to device mode
void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init);
bool dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init);

// Deinitialize controller, unset device mode.
bool dcd_deinit(uint8_t rhport);
Expand Down
9 changes: 5 additions & 4 deletions src/device/usbd.c
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ bool tud_rhport_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) {
}
TU_ASSERT(rh_init);

TU_LOG_USBD("USBD init on controller %u, speed = %s\r\n", rh_init->rhport,
TU_LOG_USBD("USBD init on controller %u, speed = %s\r\n", rhport,
rh_init->speed == TUSB_SPEED_HIGH ? "High" : "Full");
TU_LOG_INT(CFG_TUD_LOG_LEVEL, sizeof(usbd_device_t));
TU_LOG_INT(CFG_TUD_LOG_LEVEL, sizeof(dcd_event_t));
Expand Down Expand Up @@ -490,15 +490,16 @@ bool tud_rhport_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) {
_usbd_rhport = rhport;

// Init device controller driver
dcd_init(rhport, rh_init);
TU_ASSERT(dcd_init(rhport, rh_init));
dcd_int_enable(rhport);

return true;
}

bool tud_deinit(uint8_t rhport) {
// skip if not initialized
if (!tud_inited()) return true;
if (!tud_inited()) {
return true; // skip if not initialized
}

TU_LOG_USBD("USBD deinit on controller %u\r\n", rhport);

Expand Down
3 changes: 2 additions & 1 deletion src/portable/bridgetek/ft9xx/dcd_ft9xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ static uint16_t _ft9xx_dusb_out(uint8_t ep_number, uint8_t *buffer, uint16_t len
*------------------------------------------------------------------*/

// Initialize controller to device mode
void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) {
bool dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) {
(void) rh_init;
TU_LOG2("FT9xx initialisation\r\n");

Expand All @@ -526,6 +526,7 @@ void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) {
interrupt_attach(interrupt_usb_device, (int8_t)interrupt_usb_device, _ft9xx_usbd_ISR);

dcd_connect(rhport);
return true;
}

// Enable device interrupt
Expand Down
3 changes: 2 additions & 1 deletion src/portable/chipidea/ci_fs/dcd_ci_fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ static void process_bus_resume(uint8_t rhport)
/*------------------------------------------------------------------*/
/* Device API
*------------------------------------------------------------------*/
void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) {
bool dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) {
(void) rhport;
(void) rh_init;

Expand Down Expand Up @@ -296,6 +296,7 @@ void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) {

dcd_connect(rhport);
// NVIC_ClearPendingIRQ(CIFS_IRQN);
return true;
}

void dcd_set_address(uint8_t rhport, uint8_t dev_addr)
Expand Down
6 changes: 4 additions & 2 deletions src/portable/chipidea/ci_hs/dcd_ci_hs.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,13 +234,13 @@ static void bus_reset(uint8_t rhport)
dcd_dcache_clean_invalidate(&_dcd_data, sizeof(dcd_data_t));
}

void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) {
bool dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) {
(void) rh_init;
tu_memclr(&_dcd_data, sizeof(dcd_data_t));

ci_hs_regs_t* dcd_reg = CI_HS_REG(rhport);

TU_ASSERT(ci_ep_count(dcd_reg) <= TUP_DCD_ENDPOINT_MAX, );
TU_ASSERT(ci_ep_count(dcd_reg) <= TUP_DCD_ENDPOINT_MAX);

// Reset controller
dcd_reg->USBCMD |= USBCMD_RESET;
Expand Down Expand Up @@ -268,6 +268,8 @@ void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) {
usbcmd |= USBCMD_RUN_STOP; // run

dcd_reg->USBCMD = usbcmd;

return true;
}

void dcd_int_enable(uint8_t rhport)
Expand Down
7 changes: 4 additions & 3 deletions src/portable/dialog/da146xx/dcd_da146xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -804,15 +804,16 @@ static void handle_ep0_nak(void)
/*------------------------------------------------------------------*/
/* Controller API
*------------------------------------------------------------------*/
void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) {
bool dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) {
(void) rhport;
(void) rh_init;

_dcd.init_called = true;
if (_dcd.vbus_present)
{
if (_dcd.vbus_present) {
dcd_connect(rhport);
}

return true;
}

void dcd_int_enable(uint8_t rhport)
Expand Down
3 changes: 2 additions & 1 deletion src/portable/espressif/esp32sx/dcd_esp32sx.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ static void enum_done_processing(void)
/*------------------------------------------------------------------*/
/* Controller API
*------------------------------------------------------------------*/
void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) {
bool dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) {
(void) rh_init;
ESP_LOGV(TAG, "DCD init - Start");

Expand Down Expand Up @@ -211,6 +211,7 @@ void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) {
USB_DISCONNINTMSK_M; // host most only

dcd_connect(rhport);
return true;
}

void dcd_set_address(uint8_t rhport, uint8_t dev_addr)
Expand Down
3 changes: 2 additions & 1 deletion src/portable/mentor/musb/dcd_musb.c
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ void print_musb_info(musb_regs_t* musb_regs) {
}
#endif

void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) {
bool dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) {
(void) rh_init;
musb_regs_t* musb_regs = MUSB_REGS(rhport);

Expand All @@ -594,6 +594,7 @@ void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) {
musb_dcd_int_clear(rhport);
musb_dcd_phy_init(rhport);
dcd_connect(rhport);
return true;
}

void dcd_int_enable(uint8_t rhport) {
Expand Down
3 changes: 2 additions & 1 deletion src/portable/microchip/pic/dcd_pic.c
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ static void process_bus_resume(uint8_t rhport)
/*------------------------------------------------------------------*/
/* Device API
*------------------------------------------------------------------*/
void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) {
bool dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) {
(void) rh_init;
intr_disable(rhport);
intr_clear(rhport);
Expand Down Expand Up @@ -502,6 +502,7 @@ void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) {
U1IE = _U1IE_URSTIE_MASK;

dcd_connect(rhport);
return true;
}

void dcd_int_enable(uint8_t rhport)
Expand Down
3 changes: 2 additions & 1 deletion src/portable/microchip/pic32mz/dcd_pic32mz.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ static ep0_stage_t ep0_get_stage(void)
/*------------------------------------------------------------------*/
/* Controller API
*------------------------------------------------------------------*/
void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) {
bool dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) {
(void) rh_init;
// Disable endpoint interrupts for now
USB_REGS->INTRRXEbits.w = 0;
Expand All @@ -129,6 +129,7 @@ void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) {
USB_REGS->INTRUSBEbits.w = 7;

dcd_connect(rhport);
return true;
}

void dcd_int_enable(uint8_t rhport)
Expand Down
7 changes: 5 additions & 2 deletions src/portable/microchip/samd/dcd_samd.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,9 @@ static void bus_reset(void)
/*------------------------------------------------------------------*/
/* Controller API
*------------------------------------------------------------------*/
void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) {
(void) rhport; (void) rh_init;
bool dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) {
(void) rhport;
(void) rh_init;

// Reset to get in a clean state.
USB->DEVICE.CTRLA.bit.SWRST = true;
Expand All @@ -101,6 +102,8 @@ void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) {

USB->DEVICE.INTFLAG.reg |= USB->DEVICE.INTFLAG.reg; // clear pending
USB->DEVICE.INTENSET.reg = /* USB_DEVICE_INTENSET_SOF | */ USB_DEVICE_INTENSET_EORST;

return true;
}

#if CFG_TUSB_MCU == OPT_MCU_SAMD51 || CFG_TUSB_MCU == OPT_MCU_SAME5X
Expand Down
4 changes: 3 additions & 1 deletion src/portable/microchip/samg/dcd_samg.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,13 @@ static void bus_reset(void)
}

// Initialize controller to device mode
void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) {
bool dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) {
(void) rhport;
(void) rh_init;

tu_memclr(_dcd_xfer, sizeof(_dcd_xfer));
dcd_connect(rhport);
return true;
}

// Enable device interrupt
Expand Down
3 changes: 2 additions & 1 deletion src/portable/microchip/samx7x/dcd_samx7x.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,10 @@ TU_ATTR_ALWAYS_INLINE static inline void CleanInValidateCache(uint32_t *addr, in
//------------------------------------------------------------------

// Initialize controller to device mode
void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) {
bool dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) {
(void) rh_init;
dcd_connect(rhport);
return true;
}

// Enable device interrupt
Expand Down
3 changes: 2 additions & 1 deletion src/portable/mindmotion/mm32/dcd_mm32f327x_otg.c
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ static void process_bus_active(uint8_t rhport)
/*------------------------------------------------------------------*/
/* Device API
*------------------------------------------------------------------*/
void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) {
bool dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) {
(void) rhport;
(void) rh_init;

Expand All @@ -256,6 +256,7 @@ void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) {

dcd_connect(rhport);
NVIC_ClearPendingIRQ(USB_FS_IRQn);
return true;
}
#define USB_DEVICE_INTERRUPT_PRIORITY (3U)
void dcd_int_enable(uint8_t rhport)
Expand Down
3 changes: 2 additions & 1 deletion src/portable/nordic/nrf5x/dcd_nrf5x.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,11 @@ static void xact_in_dma(uint8_t epnum) {
//--------------------------------------------------------------------+
// Controller API
//--------------------------------------------------------------------+
void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) {
bool dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) {
(void) rhport;
(void) rh_init;
TU_LOG2("dcd init\r\n");
return true;
}

void dcd_int_enable(uint8_t rhport) {
Expand Down
4 changes: 3 additions & 1 deletion src/portable/nuvoton/nuc120/dcd_nuc120.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ static const uint32_t enabled_irqs = USBD_INTSTS_FLDET_STS_Msk | USBD_INTSTS_BUS
NUC100/NUC120 TinyUSB API driver implementation
*/

void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) {
bool dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) {
(void) rhport;
(void) rh_init;

Expand All @@ -215,6 +215,8 @@ void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) {

USBD->INTSTS = enabled_irqs;
USBD->INTEN = enabled_irqs;

return true;
}

void dcd_int_enable(uint8_t rhport)
Expand Down
4 changes: 3 additions & 1 deletion src/portable/nuvoton/nuc121/dcd_nuc121.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ enum {
NUC121/NUC125/NUC126 TinyUSB API driver implementation
*/

void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) {
bool dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) {
(void) rhport;
(void) rh_init;

Expand All @@ -227,6 +227,8 @@ void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) {

USBD->INTSTS = ENABLED_IRQS;
USBD->INTEN = ENABLED_IRQS;

return true;
}

void dcd_int_enable(uint8_t rhport)
Expand Down
4 changes: 3 additions & 1 deletion src/portable/nuvoton/nuc505/dcd_nuc505.c
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ static const uint32_t enabled_irqs = USBD_GINTEN_USBIEN_Msk | \
NUC505 TinyUSB API driver implementation
*/

void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) {
bool dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) {
(void) rhport;
(void) rh_init;

Expand All @@ -291,6 +291,8 @@ void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) {
bus_reset();

usb_attach();

return true;
}

void dcd_int_enable(uint8_t rhport)
Expand Down
4 changes: 3 additions & 1 deletion src/portable/nxp/khci/dcd_khci.c
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ static void process_bus_resume(uint8_t rhport)
/*------------------------------------------------------------------*/
/* Device API
*------------------------------------------------------------------*/
void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) {
bool dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) {
(void) rhport;
(void) rh_init;

Expand Down Expand Up @@ -294,6 +294,8 @@ void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) {

dcd_connect(rhport);
NVIC_ClearPendingIRQ(USB0_IRQn);

return true;
}

void dcd_int_enable(uint8_t rhport)
Expand Down
4 changes: 3 additions & 1 deletion src/portable/nxp/lpc17_40/dcd_lpc17_40.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ static void bus_reset(void)
tu_memclr(&_dcd, sizeof(dcd_data_t));
}

void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) {
bool dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) {
(void) rhport;
(void) rh_init;

Expand All @@ -186,6 +186,8 @@ void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) {

// Clear pending IRQ
NVIC_ClearPendingIRQ(USB_IRQn);

return true;
}

void dcd_int_enable(uint8_t rhport)
Expand Down
4 changes: 3 additions & 1 deletion src/portable/nxp/lpc_ip3511/dcd_lpc_ip3511.c
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ static void edpt_reset_all(uint8_t rhport)
}
prepare_setup_packet(rhport);
}
void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) {
bool dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) {
(void) rh_init;
edpt_reset_all(rhport);

Expand All @@ -303,6 +303,8 @@ void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) {
DEVCMDSTAT_RESET_CHANGE_MASK | DEVCMDSTAT_CONNECT_CHANGE_MASK | DEVCMDSTAT_SUSPEND_CHANGE_MASK;

NVIC_ClearPendingIRQ(_dcd_controller[rhport].irqnum);

return true;
}

void dcd_int_enable(uint8_t rhport)
Expand Down
4 changes: 3 additions & 1 deletion src/portable/raspberrypi/pio_usb/dcd_pio_usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,13 @@ static usb_descriptor_buffers_t desc;
*------------------------------------------------------------------*/

// Initialize controller to device mode
void dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) {
bool dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) {
(void) rhport;
(void) rh_init;
static pio_usb_configuration_t config = PIO_USB_DEFAULT_CONFIG;
usb_device = pio_usb_device_init(&config, &desc);

return true;
}

// Enable device interrupt
Expand Down
Loading

0 comments on commit e83e083

Please sign in to comment.