//***************************************************************************** // // This is the generic callback from host stack. // // pvData is actually a pointer to a tEventInfo structure. // // This function will be called to inform the application when a USB event has // occurred that is outside those related to the keyboard device. At this // point this is used to detect unsupported devices being inserted and removed. // It is also used to inform the application when a power fault has occurred. // This function is required when the g_USBGenericEventDriver is included in // the host controller driver array that is passed in to the // USBHCDRegisterDrivers() function. // //***************************************************************************** void USBHCDEvents(void *pvData) { tEventInfo *pEventInfo; // // Cast this pointer to its actual type. // pEventInfo = (tEventInfo *)pvData; switch(pEventInfo->ulEvent) { // // New keyboard detected. // case USB_EVENT_CONNECTED: { // // See if this is a HID Keyboard. // if((USBHCDDevClass(pEventInfo->ulInstance, 0) == USB_CLASS_HID) && (USBHCDDevProtocol(pEventInfo->ulInstance, 0) == USB_HID_PROTOCOL_KEYB)) { // // Indicate that the keyboard has been detected. // UARTprintf("Keyboard Connected\n"); // // Proceed to the STATE_KEYBOARD_INIT state so that the main // loop can finish initialized the mouse since // USBHKeyboardInit() cannot be called from within a callback. // g_eUSBState = STATE_KEYBOARD_INIT; } break; } // // Unsupported device detected. // case USB_EVENT_UNKNOWN_CONNECTED: { UARTprintf("Unsupported Device Class (0x%02x) Connected.\n", pEventInfo->ulInstance); // // An unknown device was detected. // g_eUSBState = STATE_UNKNOWN_DEVICE; UpdateStatus(); break; } // // Device has been unplugged. // case USB_EVENT_DISCONNECTED: { // // Indicate that the device has been disconnected. // UARTprintf("Device Disconnected\n"); // // Change the state so that the main loop knows that the device // is no longer present. // g_eUSBState = STATE_NO_DEVICE; // // Update the screen. // UpdateStatus(); break; } // // Power Fault occurred. // case USB_EVENT_POWER_FAULT: { UARTprintf("Power Fault\n"); // // No power means no device is present. // g_eUSBState = STATE_POWER_FAULT; UpdateStatus(); break; } default: { break; } } }
//***************************************************************************** // // This function updates the status area of the screen. It uses the current // state of the application to print the status bar. // //***************************************************************************** void UpdateStatus(int32_t i32Port) { tRectangle sRect; uint8_t ui8DevClass, ui8DevProtocol; // // Calculate the box size based on the lPort value to update one of the // status boxes. The first and last boxes will draw slightly off screen // to make the status area have no borders on the sides and bottom. // sRect.i16XMin = DISPLAY_TEXT_BORDER_H + (BUTTON_WIDTH * i32Port); sRect.i16XMax = sRect.i16XMin + BUTTON_WIDTH; sRect.i16YMin = 240 - 10 - BUTTON_HEIGHT; sRect.i16YMax = sRect.i16YMin + BUTTON_HEIGHT; // // Slightly adjust the first box to draw it off screen properly. // if(i32Port == (NUM_HUB_STATUS - 1)) { sRect.i16XMax -= 2; } // // Put the application name in the middle of the banner. // GrContextFontSet(&g_sContext, g_psFontFixed6x8); if(g_psHubStatus[i32Port].bConnected) { ui8DevClass = USBHCDDevClass(g_psHubStatus[i32Port].ui32Instance, 0); ui8DevProtocol = USBHCDDevProtocol( g_psHubStatus[i32Port].ui32Instance, 0); if(ui8DevClass == USB_CLASS_HID) { if(ui8DevProtocol == USB_HID_PROTOCOL_MOUSE) { // // Mouse is currently connected. // UpdateStatusBox(&sRect, "Mouse", true); } else if(ui8DevProtocol == USB_HID_PROTOCOL_KEYB) { // // Keyboard is currently connected. // UpdateStatusBox(&sRect, "Keyboard", true); } else { // // Unknown device is currently connected. // UpdateStatusBox(&sRect, "Unknown", true); } } else if(ui8DevClass == USB_CLASS_MASS_STORAGE) { // // MSC device is currently connected. // UpdateStatusBox(&sRect, "Mass Storage", true); } else if(ui8DevClass == USB_CLASS_HUB) { // // MSC device is currently connected. // UpdateStatusBox(&sRect, "Hub", true); } else { // // Unknown device is currently connected. // UpdateStatusBox(&sRect, "Unknown", true); } } else { // // Unknown device is currently connected. // UpdateStatusBox(&sRect, "No Device", false); } }
//***************************************************************************** // // This is the generic callback from host stack. // // pvData is actually a pointer to a tEventInfo structure. // // This function will be called to inform the application when a USB event has // occurred that is outside those related to the keyboard device. At this // point this is used to detect unsupported devices being inserted and removed. // It is also used to inform the application when a power fault has occurred. // This function is required when the g_USBGenericEventDriver is included in // the host controller driver array that is passed in to the // USBHCDRegisterDrivers() function. // //***************************************************************************** void USBHCDEvents(void *pvData) { tEventInfo *pEventInfo; uint8_t ui8Port; // // Cast this pointer to its actual type. // pEventInfo = (tEventInfo *)pvData; // // Get the hub port number that the device is connected to. // ui8Port = USBHCDDevHubPort(pEventInfo->ui32Instance); switch(pEventInfo->ui32Event) { case USB_EVENT_UNKNOWN_CONNECTED: case USB_EVENT_CONNECTED: { // // If this is the hub then ignore this connection. // if(USBHCDDevClass(pEventInfo->ui32Instance, 0) == USB_CLASS_HUB) { break; } // // If this is not a direct connection, then the hub is on // port 0 so the index should be moved down from 1-4 to 0-3. // if(ui8Port > 0) { ui8Port--; } // // Save the device instance data. // g_psHubStatus[ui8Port].ui32Instance = pEventInfo->ui32Instance; g_psHubStatus[ui8Port].bConnected = true; // // Update the port status for the new device. // UpdateStatus(ui8Port); break; } // // A device has been unplugged. // case USB_EVENT_DISCONNECTED: { // // If this is not a direct connection, then the hub is on // port 0 so the index should be moved down from 1-4 to 0-3. // if(ui8Port > 0) { ui8Port--; } // // Device is no longer connected. // g_psHubStatus[ui8Port].bConnected = false; // // Update the port status for the new device. // UpdateStatus(ui8Port); break; } default: { break; } } }
//***************************************************************************** // // This function updates the status area of the screen. It uses the current // state of the application to print the status bar. // //***************************************************************************** void UIUpdateStatus(void) { uint8_t ui8DevClass, ui8DevProtocol; static const tRectangle psRect[4] = { { DISPLAY_TEXT_BORDER_H, 240 - 10 - BUTTON_HEIGHT, DISPLAY_TEXT_BORDER_H + 124, 240 - 10 }, { DISPLAY_TEXT_BORDER_H + 124, 240 - 10 - BUTTON_HEIGHT, DISPLAY_TEXT_BORDER_H + 184, 240 - 10 }, { DISPLAY_TEXT_BORDER_H + 184, 240 - 10 - BUTTON_HEIGHT, DISPLAY_TEXT_BORDER_H + 244, 240 - 10 }, { DISPLAY_TEXT_BORDER_H + 244, 240 - 10 - BUTTON_HEIGHT, DISPLAY_TEXT_BORDER_H + 303, 240 - 10 }, }; // // Put the application name in the middle of the banner. // GrContextFontSet(&g_sContext, g_psFontFixed6x8); // // Default the protocol to none so that non-HID devices do not update // the keyboard modifiers. // ui8DevProtocol = USB_HID_PROTOCOL_NONE; if(g_sStatus.bConnected) { ui8DevClass = USBHCDDevClass(g_sStatus.ui32Instance, 0); ui8DevProtocol = USBHCDDevProtocol(g_sStatus.ui32Instance, 0); if(ui8DevClass == USB_CLASS_HID) { if(ui8DevProtocol == USB_HID_PROTOCOL_MOUSE) { // // Mouse is currently connected. // UpdateStatusBox(&psRect[0], "Mouse", true); } else if(ui8DevProtocol == USB_HID_PROTOCOL_KEYB) { // // Keyboard is currently connected. // UpdateStatusBox(&psRect[0], "Keyboard", true); } else { // // Unknown device is currently connected. // UpdateStatusBox(&psRect[0], "Unknown", true); } } else if(ui8DevClass == USB_CLASS_MASS_STORAGE) { // // MSC device is currently connected. // UpdateStatusBox(&psRect[0], "Mass Storage", true); } else if(ui8DevClass == USB_CLASS_HUB) { // // MSC device is currently connected. // UpdateStatusBox(&psRect[0], "Hub", true); } else { // // Unknown device is currently connected. // UpdateStatusBox(&psRect[0], "Unknown", true); } } else { // // Unknown device is currently connected. // UpdateStatusBox(&psRect[0], "No Device", false); } if(ui8DevProtocol == USB_HID_PROTOCOL_KEYB) { if(g_sStatus.ui32Modifiers & HID_KEYB_CAPS_LOCK) { UpdateStatusBox(&psRect[1], "CAPS", true); } else { UpdateStatusBox(&psRect[1], "caps", false); } if(g_sStatus.ui32Modifiers & HID_KEYB_SCROLL_LOCK) { UpdateStatusBox(&psRect[2], "SCROLL", true); } else { UpdateStatusBox(&psRect[2], "scroll", false); } if(g_sStatus.ui32Modifiers & HID_KEYB_NUM_LOCK) { UpdateStatusBox(&psRect[3], "NUM", true); } else { UpdateStatusBox(&psRect[3], "num", false); } } else { UpdateStatusBox(&psRect[1], "caps", false); UpdateStatusBox(&psRect[2], "scroll", false); UpdateStatusBox(&psRect[3], "num", false); } }
//***************************************************************************** // // This is the generic callback from host stack. // // \param pvData is actually a pointer to a tEventInfo structure. // // This function will be called to inform the application when a USB event has // occurred that is outside those related to the mouse device. At this // point this is used to detect unsupported devices being inserted and removed. // It is also used to inform the application when a power fault has occurred. // This function is required when the g_USBGenericEventDriver is included in // the host controller driver array that is passed in to the // USBHCDRegisterDrivers() function. // // \return None. // //***************************************************************************** void USBHCDEvents(void *pvData) { tEventInfo *psEventInfo; // // Cast this pointer to its actual type. // psEventInfo = (tEventInfo *)pvData; switch(psEventInfo->ui32Event) { // // New mouse detected. // case USB_EVENT_CONNECTED: { // // See if this is a HID Keyboard. // if((USBHCDDevClass(psEventInfo->ui32Instance, 0) == USB_CLASS_HID) && (USBHCDDevProtocol(psEventInfo->ui32Instance, 0) == USB_HID_PROTOCOL_MOUSE)) { // // Indicate that the mouse has been detected. // UARTprintf("Mouse Connected\n"); // // Proceed to the eStateMouseInit state so that the main loop // can finish initialized the mouse since USBHMouseInit() // cannot be called from within a callback. // iUSBState = eStateMouseInit; } break; } // // Unsupported device detected. // case USB_EVENT_UNKNOWN_CONNECTED: { UARTprintf("Unsupported Device Connected\n"); // // An unknown device was detected. // iUSBState = eStateUnknownDevice; break; } // // Device has been unplugged. // case USB_EVENT_DISCONNECTED: { // // Indicate that the mouse has been disconnected. // UARTprintf("Device Disconnected\n"); // // Change the state so that the main loop knows that the mouse is // no longer present. // iUSBState = eStateNoDevice; // // Reset the button state. // g_ui32Buttons = 0; break; } // // Power Fault. // case USB_EVENT_POWER_FAULT: { UARTprintf("Power Fault\n"); // // No power means no device is present. // iUSBState = eStatePowerFault; break; } default: { break; } } }
//***************************************************************************** // // This is the generic callback from host stack. // // pvData is actually a pointer to a tEventInfo structure. // // This function will be called to inform the application when a USB event has // occurred that is outside those related to the mouse device. At this // point this is used to detect unsupported devices being inserted and removed. // It is also used to inform the application when a power fault has occurred. // This function is required when the g_USBGenericEventDriver is included in // the host controller driver array that is passed in to the // USBHCDRegisterDrivers() function. // //***************************************************************************** void USBHCDEvents(void *pvData) { tEventInfo *pEventInfo; tRectangle sRect; // // Fill the bottom rows of the screen with blue to create the status area. // sRect.i16XMin = 0; sRect.i16YMin = GrContextDpyHeightGet(&g_sContext) - DISPLAY_BANNER_HEIGHT - 1; sRect.i16XMax = GrContextDpyWidthGet(&g_sContext) - 1; sRect.i16YMax = sRect.i16YMin + DISPLAY_BANNER_HEIGHT; GrContextForegroundSet(&g_sContext, DISPLAY_BANNER_BG); GrRectFill(&g_sContext, &sRect); // // Put a white box around the banner. // GrContextForegroundSet(&g_sContext, ClrWhite); GrRectDraw(&g_sContext, &sRect); // // Set the font for the status message // GrContextFontSet(&g_sContext, g_psFontFixed6x8); // // Cast this pointer to its actual type. // pEventInfo = (tEventInfo *)pvData; switch(pEventInfo->ui32Event) { // // New mouse detected. // case USB_EVENT_CONNECTED: { // // See if this is a HID Mouse. // if((USBHCDDevClass(pEventInfo->ui32Instance, 0) == USB_CLASS_HID) && (USBHCDDevProtocol(pEventInfo->ui32Instance, 0) == USB_HID_PROTOCOL_MOUSE)) { // // Indicate that the mouse has been detected. // GrStringDrawCentered(&g_sContext, "Mouse Connected", -1, GrContextDpyWidthGet(&g_sContext) / 2, sRect.i16YMin + 5, 0); // // Set initial mouse information. // GrStringDrawCentered(&g_sContext, "0,0", -1, GrContextDpyWidthGet(&g_sContext) / 2, 26, 1); GrStringDrawCentered(&g_sContext, "000", -1, GrContextDpyWidthGet(&g_sContext) / 2, 46, 1); // // Proceed to the STATE_MOUSE_INIT state so that the main loop // can finish initialized the mouse since USBHMouseInit() // cannot be called from within a callback. // g_eUSBState = STATE_MOUSE_INIT; } break; } // // Unsupported device detected. // case USB_EVENT_UNKNOWN_CONNECTED: { GrStringDrawCentered(&g_sContext, "Unknown Device", -1, GrContextDpyWidthGet(&g_sContext) / 2, sRect.i16YMin + 5, 0); // // An unknown device was detected. // g_eUSBState = STATE_UNKNOWN_DEVICE; break; } // // Device has been unplugged. // case USB_EVENT_DISCONNECTED: { // // Indicate that the device has been disconnected. // GrStringDrawCentered(&g_sContext, "No Device", -1, GrContextDpyWidthGet(&g_sContext) / 2, sRect.i16YMin + 5, 0); // // Reset the mouse information. // GrStringDrawCentered(&g_sContext, " -,- ", -1, GrContextDpyWidthGet(&g_sContext) / 2, 26, 1); GrStringDrawCentered(&g_sContext, "---", -1, GrContextDpyWidthGet(&g_sContext) / 2, 46, 1); // // Change the state so that the main loop knows that the device is // no longer present. // g_eUSBState = STATE_NO_DEVICE; // // Reset the button state. // g_ui32Buttons = 0; break; } // // Power Fault has occurred. // case USB_EVENT_POWER_FAULT: { // // Indicate that there has been a power fault. // GrStringDrawCentered(&g_sContext, "Power Fault", -1, GrContextDpyWidthGet(&g_sContext) / 2, sRect.i16YMin + 5, 0); // // Reset the mouse information. // GrStringDrawCentered(&g_sContext, " -,- ", -1, GrContextDpyWidthGet(&g_sContext) / 2, 26, 1); GrStringDrawCentered(&g_sContext, "---", -1, GrContextDpyWidthGet(&g_sContext) / 2, 46, 1); // // No power means no device is present. // g_eUSBState = STATE_POWER_FAULT; break; } default: { break; } } }
//***************************************************************************** // // This is the generic callback from host stack. // // \param pvData is actually a pointer to a tEventInfo structure. // // This function will be called to inform the application when a USB event has // occurred that is outside those related to the mouse device. At this // point this is used to detect unsupported devices being inserted and removed. // It is also used to inform the application when a power fault has occurred. // This function is required when the g_USBGenericEventDriver is included in // the host controller driver array that is passed in to the // USBHCDRegisterDrivers() function. // // \return None. // //***************************************************************************** void USBHCDEvents(void *pvData) { tEventInfo *pEventInfo; // // Cast this pointer to its actual type. // pEventInfo = (tEventInfo *)pvData; switch(pEventInfo->ulEvent) { // // New mouse detected. // case USB_EVENT_CONNECTED: { // // See if this is a HID Mouse. // if((USBHCDDevClass(pEventInfo->ulInstance, 0) == USB_CLASS_HID) && (USBHCDDevProtocol(pEventInfo->ulInstance, 0) == USB_HID_PROTOCOL_MOUSE)) { // // Indicate that the mouse has been detected. // DEBUG_PRINT("Mouse Connected\n"); // // Proceed to the STATE_MOUSE_INIT state so that the main loop // can finish initialized the mouse since USBHMouseInit() // cannot be called from within a callback. // eUSBState = STATE_MOUSE_INIT; } break; } // // Unsupported detected. // case USB_EVENT_UNKNOWN_CONNECTED: { DEBUG_PRINT("Unsupported Device Connected\n"); // // An unknown device was detected. // eUSBState = STATE_UNKNOWN_DEVICE; UpdateStatus(0, 0, false); break; } // // Device has been unplugged. // case USB_EVENT_DISCONNECTED: { // // Indicate that the mouse has been disconnected. // DEBUG_PRINT("Device Disconnected\n"); // // Change the state so that the main loop knows that the mouse is // no longer present. // eUSBState = STATE_NO_DEVICE; // // Reset the button state. // g_ulButtons = 0; UpdateStatus(0, 0, false); break; } // // Power Fault occurred. // case USB_EVENT_POWER_FAULT: { DEBUG_PRINT("Power Fault\n"); // // No power means no device is present. // eUSBState = STATE_POWER_FAULT; UpdateStatus(0, 0, false); break; } default: { break; } } }
//***************************************************************************** // // This function updates the status area of the screen. It uses the current // state of the application to print the status bar. // //***************************************************************************** void UIUpdateStatus(void) { uint8_t ui8DevClass, ui8DevProtocol; static const char pcNoPos[] = "---,---"; static const tRectangle psRect[2] = { { DISPLAY_TEXT_BORDER_H, STATUS_MIN_Y, DISPLAY_TEXT_BORDER_H + STATUS_MIDDLE_X, STATUS_MIN_Y + BUTTON_HEIGHT }, { DISPLAY_TEXT_BORDER_H + STATUS_MIDDLE_X, STATUS_MIN_Y, BUTTON_MIN_X, STATUS_MIN_Y + BUTTON_HEIGHT }, }; char pcPos[8]; // // Put the application name in the middle of the banner. // GrContextFontSet(&g_sContext, g_psFontFixed6x8); // // Default the protocol to none. // ui8DevProtocol = USB_HID_PROTOCOL_NONE; if(g_sStatus.bConnected) { ui8DevClass = USBHCDDevClass(g_sStatus.ui32Instance, 0); ui8DevProtocol = USBHCDDevProtocol(g_sStatus.ui32Instance, 0); // // If the class has not yet been recognized then print out the new // class of device that has been connected. // if(g_bTypeUpdated == false) { // // Now the class has been updated so do not update it again. // g_bTypeUpdated = true; if(ui8DevClass == USB_CLASS_HID) { if(ui8DevProtocol == USB_HID_PROTOCOL_MOUSE) { // // Mouse is currently connected. // UpdateStatusBox(&psRect[0], "Mouse", true); } else if(ui8DevProtocol == USB_HID_PROTOCOL_KEYB) { // // Keyboard is currently connected. // UpdateStatusBox(&psRect[0], "Keyboard", true); } else { // // Unknown device is currently connected. // UpdateStatusBox(&psRect[0], "Unknown", true); } } else if(ui8DevClass == USB_CLASS_MASS_STORAGE) { // // MSC device is currently connected. // UpdateStatusBox(&psRect[0], "Mass Storage", true); } else if(ui8DevClass == USB_CLASS_HUB) { // // MSC device is currently connected. // UpdateStatusBox(&psRect[0], "Hub", true); } else { // // Unknown device is currently connected. // UpdateStatusBox(&psRect[0], "Unknown", true); } } } else { // // Unknown device is currently connected. // UpdateStatusBox(&psRect[0], "No Device", false); // // No device is present so allow the class to update when a new device // is connected. // g_bTypeUpdated = false; } if(ui8DevProtocol == USB_HID_PROTOCOL_MOUSE) { // // Update the current cursor position. // UpdateCursor(); usprintf(pcPos, "%3d,%3d", g_sCursor.i16XMin, g_sCursor.i16YMin); UpdateStatusBox(&psRect[1], pcPos, false); } else { UpdateStatusBox(&psRect[1], pcNoPos, false); } UpdateButtons(); }