void udc_tick_task(void) { uint32_t dev_info = DEV_INFO; static struct usb_ctrlrequest req_addr, req_conf; static bool set_address = false; static bool set_configuration = false; /* This tick task polls for DEV_EN bit set in DEV_INFO register * as well as tracks current requested configuration * (DEV_INFO [11:8]). On state change it notifies usb stack * about it. * * It is registered on usb connection and removed on usb * extraction. */ /* SET ADDRESS request */ if (set_address == false) if ((dev_info & 0x7f)) { udc_conn = (dev_info & 0x7f); set_address = true; req_addr.bRequestType = USB_DIR_OUT | USB_TYPE_STANDARD | USB_RECIP_DEVICE; req_addr.bRequest = USB_REQ_SET_ADDRESS; req_addr.wValue = (dev_info & 0x7f); req_addr.wIndex = 0; req_addr.wLength = 0; logf("udc_tick_task() ctrl req=%x",req_addr.bRequest); usb_core_control_request(&req_addr); } /* SET CONFIGURATION request */ if (set_configuration == false) if (dev_info & DEV_EN) { set_configuration = true; req_conf.bRequestType = USB_DIR_OUT | USB_TYPE_STANDARD | USB_RECIP_DEVICE; req_conf.bRequest = USB_REQ_SET_CONFIGURATION; req_conf.wValue = ((dev_info >> 8) & 0x0f) + 1; req_conf.wIndex = 0; req_conf.wLength = 0; /* Notify usb stack somehow */ usb_core_control_request(&req_conf); tick_remove_task(udc_tick_task); set_address = false; } }