/*********************************************************************************** * @fn halUartPollEvt * * @brief Poll for USB events which are not directly related to the UART. * * @param none * * @return none */ void halUartPollEvt(void) { /* Handle reset signaling on the bus */ if (USBIRQ_GET_EVENT_MASK() & USBIRQ_EVENT_RESET) { USBIRQ_CLEAR_EVENTS(USBIRQ_EVENT_RESET); usbfwResetHandler(); } /* Handle packets on EP0 */ if (USBIRQ_GET_EVENT_MASK() & USBIRQ_EVENT_SETUP) { USBIRQ_CLEAR_EVENTS(USBIRQ_EVENT_SETUP); usbfwSetupHandler(); } /* Handle USB suspend */ if (USBIRQ_GET_EVENT_MASK() & USBIRQ_EVENT_SUSPEND) { /* Clear USB suspend interrupt */ USBIRQ_CLEAR_EVENTS(USBIRQ_EVENT_SUSPEND); #if HAL_UART_USB_SUSPEND /* Take the chip into PM1 until a USB resume is deteceted. */ usbsuspEnter(); #endif /* Running again; first clear RESUME interrupt */ USBIRQ_CLEAR_EVENTS(USBIRQ_EVENT_RESUME); } }
/*********************************************************************************** * @fn usbEventProcess * * @brief Handle the USB events which are not directly related to the UART. * * @param none * * @return none */ static void usbEventProcess(void) { // Handle reset signaling on the bus if (USBIRQ_GET_EVENT_MASK() & USBIRQ_EVENT_RESET) { USBIRQ_CLEAR_EVENTS(USBIRQ_EVENT_RESET); usbfwResetHandler(); } // Handle packets on EP0 if (USBIRQ_GET_EVENT_MASK() & USBIRQ_EVENT_SETUP) { USBIRQ_CLEAR_EVENTS(USBIRQ_EVENT_SETUP); usbfwSetupHandler(); } // Handle USB suspend if (USBIRQ_GET_EVENT_MASK() & USBIRQ_EVENT_SUSPEND) { // Clear USB suspend interrupt USBIRQ_CLEAR_EVENTS(USBIRQ_EVENT_SUSPEND); // Take the chip into PM1 until a USB resume is deteceted. usbsuspEnter(); // Running again; first clear RESUME interrupt USBIRQ_CLEAR_EVENTS(USBIRQ_EVENT_RESUME); } }
/** \brief Processes USB HID events. * * This function processes USB events. Calls application callback function * usbHidAppPoll(). */ void usbHidProcessEvents(void) { // // Handle USB resume // if(USBIRQ_GET_EVENT_MASK() & USBIRQ_EVENT_RESUME) { USBIRQ_CLEAR_EVENTS(USBIRQ_EVENT_RESUME); } // // Handle USB reset // if(USBIRQ_GET_EVENT_MASK() & USBIRQ_EVENT_RESET) { USBIRQ_CLEAR_EVENTS(USBIRQ_EVENT_RESET); usbfwResetHandler(); } // // Handle USB suspend // if(USBIRQ_GET_EVENT_MASK() & USBIRQ_EVENT_SUSPEND) { USBIRQ_CLEAR_EVENTS(USBIRQ_EVENT_SUSPEND); usbsuspEnter(); } // // Handle USB packets on EP0 // if(USBIRQ_GET_EVENT_MASK() & USBIRQ_EVENT_SETUP) { USBIRQ_CLEAR_EVENTS(USBIRQ_EVENT_SETUP); usbfwSetupHandler(); } // // Call application polling callback // usbHidAppPoll(); }
/** \brief Initializes the USB framework * * This function should be called when the microcontroller is ready to accept USB traffic. It enables the * USB peripheral unit and enables the pull-up resistor on the D+ line. */ void usbfwInit(void) { // // Set default values // usbfwData.selfPowered = (usbdpGetConfigurationDesc(1, 0)->bmAttributes & 0x40) ? true : false; usbfwData.remoteWakeup = false; usbfwResetHandler(); // // Enable the USB peripheral unit // UsbEnable(); // // Allow the USB pad IP to to enter standby // HWREG(CCTEST_USBCTRL) = CCTEST_USBCTRL_USB_STB_M; }