Hi Nordic
I have been using your example on USB MST to embed it into my application
Everything works ok, but in the main loop im constantly polling for USB power event(app_usbd_event_queue_process()) to detect when the USB cable is connected and where I should initialize the USB stack
Is there a way to register events from the softdevice so the usb event handler is called when an usb cable is inserted ?
I have already added following
static void usbd_user_ev_handler(app_usbd_event_type_t event)
{
switch (event)
{
case APP_USBD_EVT_POWER_DETECTED:
NRF_LOG_INFO("USB power detected");
if (!nrf_drv_usbd_is_enabled())
{
fatfs_uninit();
app_usbd_enable();
}
break;
case APP_USBD_EVT_POWER_REMOVED:
NRF_LOG_INFO("USB power removed");
app_usbd_stop();
m_usb_connected = false;
break;
....
...
}
}
init usb()
{
static const app_usbd_config_t usbd_config = {
.ev_state_proc = usbd_user_ev_handler };
app_usbd_power_events_enable();
sd_power_usbpwrrdy_enable(true);
sd_power_usbdetected_enable(true);
sd_power_usbremoved_enable(true);
}
main()
{
app_sched_execute();
#if DEBUG
while (NRF_LOG_PROCESS());
#endif
power_management_run();
while (app_usbd_event_queue_process());
}
Best Regards
Tommy F Kristensen