drivers: usb_dc_nrfx: add attached event delay
Add configurable attached event delay. Delay can be used to give USB Charging Controller time for initialization. Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
This commit is contained in:
parent
008bfeb43e
commit
26f2e33227
2 changed files with 46 additions and 15 deletions
|
@ -75,6 +75,15 @@ config USB_NRFX_WORK_QUEUE_STACK_SIZE
|
||||||
for handling the events from the USBD ISR, i.e. executing endpoint
|
for handling the events from the USBD ISR, i.e. executing endpoint
|
||||||
callbacks and providing proper notifications to the USB device stack.
|
callbacks and providing proper notifications to the USB device stack.
|
||||||
|
|
||||||
|
config USB_NRFX_ATTACHED_EVENT_DELAY
|
||||||
|
int "USBD attached event delay"
|
||||||
|
range 0 1000
|
||||||
|
default 0
|
||||||
|
depends on USB_NRFX
|
||||||
|
help
|
||||||
|
Configurable attached event delay in milliseconds. Delay can be used
|
||||||
|
to give USB Charging Controller time for initialization.
|
||||||
|
|
||||||
config USB_KINETIS
|
config USB_KINETIS
|
||||||
bool "Kinetis USB Device Controller Driver"
|
bool "Kinetis USB Device Controller Driver"
|
||||||
select USB_DEVICE_DRIVER
|
select USB_DEVICE_DRIVER
|
||||||
|
|
|
@ -466,14 +466,50 @@ static inline struct usbd_event *usbd_evt_alloc(void)
|
||||||
return ev;
|
return ev;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void submit_dc_power_event(enum usbd_periph_state state)
|
||||||
|
{
|
||||||
|
struct usbd_event *ev = usbd_evt_alloc();
|
||||||
|
|
||||||
|
if (!ev) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ev->evt_type = USBD_EVT_POWER;
|
||||||
|
ev->evt.pwr_evt.state = state;
|
||||||
|
|
||||||
|
usbd_evt_put(ev);
|
||||||
|
|
||||||
|
if (usbd_ctx.attached) {
|
||||||
|
usbd_work_schedule();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#if CONFIG_USB_NRFX_ATTACHED_EVENT_DELAY
|
||||||
|
static void attached_evt_delay_handler(struct k_timer *timer)
|
||||||
|
{
|
||||||
|
LOG_DBG("ATTACHED event delay done");
|
||||||
|
submit_dc_power_event(USBD_ATTACHED);
|
||||||
|
}
|
||||||
|
|
||||||
|
static K_TIMER_DEFINE(delay_timer, attached_evt_delay_handler, NULL);
|
||||||
|
#endif
|
||||||
|
|
||||||
static void usb_dc_power_event_handler(nrfx_power_usb_evt_t event)
|
static void usb_dc_power_event_handler(nrfx_power_usb_evt_t event)
|
||||||
{
|
{
|
||||||
enum usbd_periph_state new_state;
|
enum usbd_periph_state new_state;
|
||||||
|
|
||||||
switch (event) {
|
switch (event) {
|
||||||
case NRFX_POWER_USB_EVT_DETECTED:
|
case NRFX_POWER_USB_EVT_DETECTED:
|
||||||
|
#if !CONFIG_USB_NRFX_ATTACHED_EVENT_DELAY
|
||||||
new_state = USBD_ATTACHED;
|
new_state = USBD_ATTACHED;
|
||||||
break;
|
break;
|
||||||
|
#else
|
||||||
|
LOG_DBG("ATTACHED event delayed");
|
||||||
|
k_timer_start(&delay_timer,
|
||||||
|
K_MSEC(CONFIG_USB_NRFX_ATTACHED_EVENT_DELAY),
|
||||||
|
K_NO_WAIT);
|
||||||
|
return;
|
||||||
|
#endif
|
||||||
case NRFX_POWER_USB_EVT_READY:
|
case NRFX_POWER_USB_EVT_READY:
|
||||||
new_state = USBD_POWERED;
|
new_state = USBD_POWERED;
|
||||||
break;
|
break;
|
||||||
|
@ -485,21 +521,7 @@ static void usb_dc_power_event_handler(nrfx_power_usb_evt_t event)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct usbd_event *ev = usbd_evt_alloc();
|
submit_dc_power_event(new_state);
|
||||||
|
|
||||||
if (!ev) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ev->evt_type = USBD_EVT_POWER;
|
|
||||||
ev->evt.pwr_evt.state = new_state;
|
|
||||||
|
|
||||||
|
|
||||||
usbd_evt_put(ev);
|
|
||||||
|
|
||||||
if (usbd_ctx.attached) {
|
|
||||||
usbd_work_schedule();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Stopping HFXO, algorithm supports case when stop comes before clock is
|
/* Stopping HFXO, algorithm supports case when stop comes before clock is
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue