I've been doing a lot of reading about USB and the Tiva Ware USB library. After reading through all the documentation and the examples I've come up with the following test program for handling mouse input on the TM4C123G LaunchPad, but it does not seem to be working. There are no compile errors and no faults thrown when run, but the mouse callback never gets called.
#include <stdbool.h> #include <stdint.h> #include "inc/hw_ints.h" #include "inc/hw_memmap.h" #include "inc/hw_types.h" #include "driverlib/debug.h" #include "driverlib/fpu.h" #include "driverlib/gpio.h" #include "driverlib/interrupt.h" #include "driverlib/pin_map.h" #include "driverlib/sysctl.h" #include "driverlib/systick.h" #include "driverlib/timer.h" #include "driverlib/uart.h" #include "driverlib/rom.h" #include "usblib/usblib.h" #include "usblib/host/usbhost.h" #include "usblib/host/usbhhid.h" #include "usblib/host/usbhhidmouse.h" //***************************************************************************** // // The the host controller’s memory pool in bytes. // //***************************************************************************** #define HCD_MEMORY_SIZE 128 uint8_t g_pui8HCDPool[HCD_MEMORY_SIZE]; //***************************************************************************** // // The the mouse memory pool in bytes. // //***************************************************************************** #define M_MEMORY_SIZE 128 uint8_t g_pui8Buffer[M_MEMORY_SIZE]; //***************************************************************************** // // The global that holds all of the host drivers in use in the application. // In this case, only the Keyboard class is loaded. // //***************************************************************************** static tUSBHostClassDriver const * const g_ppsHostClassDrivers[] = { &g_sUSBHIDClassDriver//, &g_sUSBHostMSCClassDriver }; static const uint32_t g_ui32NumHostClassDrivers = sizeof(g_ppsHostClassDrivers) / sizeof(tUSBHostClassDriver *); //***************************************************************************** // // Mouse control // //***************************************************************************** #define MOUSE_NOT_CONNECTED 0 #define MOUSE_INIT 1 #define MOUSE_CONNECTED 2 uint32_t iMouseState = MOUSE_NOT_CONNECTED; //***************************************************************************** // // Mouse Callback // //***************************************************************************** uint32_t MouseCallback(tUSBHMouse *psMsInstance, uint32_t ui32Event, uint32_t ui32MsgParam, void *pvMsgData) { switch(ui32Event) { // // New mouse detected. // case USB_EVENT_CONNECTED: { iMouseState = MOUSE_INIT; break; } // // Mouse has been unplugged. // case USB_EVENT_DISCONNECTED: { iMouseState = MOUSE_NOT_CONNECTED; break; } // // New Mouse events detected. // case USBH_EVENT_HID_MS_PRESS: { break; } case USBH_EVENT_HID_MS_REL: { break; } case USBH_EVENT_HID_MS_X: { break; } case USBH_EVENT_HID_MS_Y: { break; } } return(0); } //***************************************************************************** // // Application start // //***************************************************************************** int main() { // // Enable Clocking to the USB controller. // SysCtlPeripheralEnable(SYSCTL_PERIPH_USB0); USBStackModeSet(0, eUSBModeForceHost, 0); // // Set the USB0EPEN and USB0PFLT pins to be controlled by the USB // controller. // SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC); GPIOPinTypeUSBDigital(GPIO_PORTC_BASE, GPIO_PIN_6 | GPIO_PIN_7); // // Register the host class drivers. // USBHCDRegisterDrivers(0, g_ppsHostClassDrivers, g_ui32NumHostClassDrivers); // // Open an instance of the mouse driver. The mouse does not need // to be present at this time, this just saves a place for it and allows // the applications to be notified when a mouse is present. // tUSBHMouse *g_psMouseInstance = USBHMouseOpen((tUSBHIDMouseCallback)MouseCallback, g_pui8Buffer, M_MEMORY_SIZE); // // Initialize the host controller. // USBHCDInit(0, g_pui8HCDPool, HCD_MEMORY_SIZE); // // Main loop of application. // while(1) { switch(iMouseState) { // // This state is entered when they mouse is first detected. // case MOUSE_INIT: { // // Initialized the newly connected mouse. // USBHMouseInit(g_psMouseInstance); // // Proceed to the mouse connected state. // iMouseState = MOUSE_CONNECTED; break; } case MOUSE_CONNECTED: { break; } case MOUSE_NOT_CONNECTED: default: { break; } } // // Periodic call the main loop for the Host controller driver. // USBHCDMain(); } }
Instead of putting in the 0 ohm resistors, like the documentation says to do for host operation, I routed the VBus through jumper wires. PB0 is connected to ground and PB1 is connected to VBus.
What am I over looking?