//*****************************************************************************
//
//! Initializes HID mouse device operation for a given USB controller.
//!
//! \param ulIndex is the index of the USB controller which is to be
//! initialized for HID mouse device operation.
//! \param psDevice points to a structure containing parameters customizing
//! the operation of the HID mouse device.
//!
//! This call is very similar to USBDHIDMouseInit() except that it is used for
//! initializing an instance of the HID mouse device for use in a composite
//! device.
//!
//! \return Returns zero on failure or a non-zero instance value that should be
//! used with the remaining USB HID Mouse APIs.
//
//*****************************************************************************
void *
USBDHIDMouseCompositeInit(unsigned long ulIndex,
                          const tUSBDHIDMouseDevice *psDevice)
{
    tHIDMouseInstance *psInst;
    tUSBDHIDDevice *psHIDDevice;


    //
    // Check parameter validity.
    //
    ASSERT(psDevice);
    ASSERT(psDevice->ppStringDescriptors);
    ASSERT(psDevice->psPrivateHIDMouseData);
    ASSERT(psDevice->pfnCallback);

    //
    // Get a pointer to our instance data
    //
    psInst = psDevice->psPrivateHIDMouseData;

    //
    // Get a pointer to the HID device data.
    //
    psHIDDevice = &psDevice->psPrivateHIDMouseData->sHIDDevice;

    //
    // Initialize the various fields in our instance structure.
    //
    psInst->ucUSBConfigured = 0;
    psInst->ucProtocol = USB_HID_PROTOCOL_REPORT;
    psInst->sReportIdle.ucDuration4mS = 0;
    psInst->sReportIdle.ucReportID = 0;
    psInst->sReportIdle.ulTimeSinceReportmS = 0;
    psInst->sReportIdle.usTimeTillNextmS = 0;
    psInst->eMouseState = HID_MOUSE_STATE_UNCONFIGURED;

    //
    // Initialize the HID device class instance structure based on input from
    // the caller.
    //
    psHIDDevice->usPID = psDevice->usPID;
    psHIDDevice->usVID = psDevice->usVID;
    psHIDDevice->usMaxPowermA = psDevice->usMaxPowermA;
    psHIDDevice->ucPwrAttributes = psDevice->ucPwrAttributes;
    psHIDDevice->ucSubclass = USB_HID_SCLASS_BOOT;
    psHIDDevice->ucProtocol = USB_HID_PROTOCOL_MOUSE;
    psHIDDevice->ucNumInputReports = 1;
    psHIDDevice->psReportIdle = &psInst->sReportIdle;
    psHIDDevice->pfnRxCallback = HIDMouseRxHandler;
    psHIDDevice->pvRxCBData = (void *)psDevice;
    psHIDDevice->pfnTxCallback = HIDMouseTxHandler;
    psHIDDevice->pvTxCBData = (void *)psDevice;
    psHIDDevice->bUseOutEndpoint = false;
    psHIDDevice->psHIDDescriptor = &g_sMouseHIDDescriptor;
    psHIDDevice->ppClassDescriptors= g_pMouseClassDescriptors;
    psHIDDevice->ppStringDescriptors = psDevice->ppStringDescriptors;
    psHIDDevice->ulNumStringDescriptors = psDevice->ulNumStringDescriptors;
    psHIDDevice->psPrivateHIDData = &psInst->sHIDInstance;

    //
    // Initialize the lower layer HID driver and pass it the various structures
    // and descriptors necessary to declare that we are a keyboard.
    //
    return(USBDHIDCompositeInit(ulIndex, psHIDDevice));
}
Exemplo n.º 2
0
//*****************************************************************************
//
//! Initializes HID keyboard device operation for a given USB controller.
//!
//! \param ui32Index is the index of the USB controller which is to be
//! initialized for HID keyboard device operation.
//! \param psHIDKbDevice points to a structure containing parameters
//! customizing the operation of the HID keyboard device.
//! \param psCompEntry is the composite device entry to initialize when
//! creating a composite device.
//!
//! This call is very similar to USBDKeyboardInit() except that it is used for
//! initializing an instance of the HID keyboard device for use in a composite
//! device.  If this HID keyboard is part of a composite device, then the
//! \e psCompEntry should point to the composite device entry to initialize.
//! This is part of the array that is passed to the USBDCompositeInit()
//! function.
//!
//! \return Returns zero on failure or a non-zero instance value that should be
//! used with the remaining USB HID Keyboard APIs.
//
//*****************************************************************************
void *
USBDHIDKeyboardCompositeInit(uint32_t ui32Index,
                             tUSBDHIDKeyboardDevice *psHIDKbDevice,
                             tCompositeEntry *psCompEntry)
{
    tHIDKeyboardInstance *psInst;
    uint32_t ui32Loop;
    tUSBDHIDDevice *psHIDDevice;

    //
    // Check parameter validity.
    //
    ASSERT(psHIDKbDevice);
    ASSERT(psHIDKbDevice->ppui8StringDescriptors);
    ASSERT(psHIDKbDevice->pfnCallback);

    //
    // Get a pointer to our instance data
    //
    psInst = &psHIDKbDevice->sPrivateData;

    //
    // Initialize the various fields in our instance structure.
    //
    psInst->ui8USBConfigured = 0;
    psInst->ui8Protocol = USB_HID_PROTOCOL_REPORT;
    psInst->sReportIdle.ui8Duration4mS = 125;
    psInst->sReportIdle.ui8ReportID = 0;
    psInst->sReportIdle.ui32TimeSinceReportmS = 0;
    psInst->sReportIdle.ui16TimeTillNextmS = 0;
    psInst->ui8LEDStates = 0;
    psInst->ui8KeyCount = 0;
    for(ui32Loop = 0; ui32Loop < KEYB_MAX_CHARS_PER_REPORT; ui32Loop++)
    {
        psInst->pui8KeysPressed[ui32Loop] = HID_KEYB_USAGE_RESERVED;
    }

    psInst->eKeyboardState = HID_KEYBOARD_STATE_UNCONFIGURED;

    //
    // Get a pointer to the HID device data.
    //
    psHIDDevice = &psInst->sHIDDevice;

    //
    // Initialize the HID device class instance structure based on input from
    // the caller.
    //
    psHIDDevice->ui16PID = psHIDKbDevice->ui16PID;
    psHIDDevice->ui16VID = psHIDKbDevice->ui16VID;
    psHIDDevice->ui16MaxPowermA = psHIDKbDevice->ui16MaxPowermA;
    psHIDDevice->ui8PwrAttributes = psHIDKbDevice->ui8PwrAttributes;
    psHIDDevice->ui8Subclass = USB_HID_SCLASS_BOOT;
    psHIDDevice->ui8Protocol = USB_HID_PROTOCOL_KEYB;
    psHIDDevice->ui8NumInputReports = 1;
    psHIDDevice->psReportIdle = 0;
    psHIDDevice->pfnRxCallback = HIDKeyboardRxHandler;
    psHIDDevice->pvRxCBData = (void *)psHIDKbDevice;
    psHIDDevice->pfnTxCallback = HIDKeyboardTxHandler;
    psHIDDevice->pvTxCBData = (void *)psHIDKbDevice;
    psHIDDevice->bUseOutEndpoint = false,

    psHIDDevice->psHIDDescriptor = &g_sKeybHIDDescriptor;
    psHIDDevice->ppui8ClassDescriptors = g_pui8KeybClassDescriptors;
    psHIDDevice->ppui8StringDescriptors =
                                        psHIDKbDevice->ppui8StringDescriptors;
    psHIDDevice->ui32NumStringDescriptors =
                                        psHIDKbDevice->ui32NumStringDescriptors;
    psHIDDevice->ppsConfigDescriptor = g_ppsHIDConfigDescriptors;

    psHIDDevice->psReportIdle = &psInst->sReportIdle;

    //
    // Initialize the lower layer HID driver and pass it the various structures
    // and descriptors necessary to declare that we are a keyboard.
    //
    return(USBDHIDCompositeInit(ui32Index, psHIDDevice, psCompEntry));
}
Exemplo n.º 3
0
//*****************************************************************************
//
//! Initializes HID gamepad device operation for a given USB controller.
//!
//! \param ui32Index is the index of the USB controller that is to be
//! initialized for HID gamepad device operation.
//! \param psGamepad points to a structure containing parameters
//! customizing the operation of the HID gamepad device.
//! \param psCompEntry is the composite device entry to initialize when
//! creating a composite device.
//!
//! This call is very similar to USBDHIDGamepadInit() except that it is used
//! for initializing an instance of the HID gamepad device for use in a
//! composite device.  If this HID gamepad is part of a composite device, then
//! the \e psCompEntry should point to the composite device entry to
//! initialize.  This entry is part of the array that is passed to the
//! USBDCompositeInit() function to start up and complete configuration of a
//! composite USB device.
//!
//! \return Returns NULL on failure or the \e psGamepad value that should be
//! used with the remaining USB HID gamepad APIs.
//
//*****************************************************************************
tUSBDHIDGamepadDevice *
USBDHIDGamepadCompositeInit(uint32_t ui32Index,
                            tUSBDHIDGamepadDevice *psGamepad,
                            tCompositeEntry *psCompEntry)
{
    tUSBDGamepadInstance *psInst;
    tUSBDHIDDevice *psHIDDevice;

    //
    // Check parameter validity.
    //
    ASSERT(psGamepad);
    ASSERT(psGamepad->ppui8StringDescriptors);
    ASSERT(psGamepad->pfnCallback);

    //
    // Get a pointer to our instance data
    //
    psInst = &psGamepad->sPrivateData;

    //
    // Initialize the various fields in our instance structure.
    //
    psInst->iState = eHIDGamepadStateNotConnected;

    //
    // Get a pointer to the HID device data.
    //
    psHIDDevice = &psInst->sHIDDevice;

    //
    // Initialize the HID device class instance structure based on input from
    // the caller.
    //
    psHIDDevice->ui16PID = psGamepad->ui16PID;
    psHIDDevice->ui16VID = psGamepad->ui16VID;
    psHIDDevice->ui16MaxPowermA = psGamepad->ui16MaxPowermA;
    psHIDDevice->ui8PwrAttributes = psGamepad->ui8PwrAttributes;
    psHIDDevice->ui8Subclass = 0;
    psHIDDevice->ui8Protocol = 0;
    psHIDDevice->ui8NumInputReports = 1;
    psHIDDevice->psReportIdle = &psInst->sReportIdle;
    psInst->sReportIdle.ui8Duration4mS = 125;
    psInst->sReportIdle.ui8ReportID = 0;
    psInst->sReportIdle.ui32TimeSinceReportmS = 0;
    psInst->sReportIdle.ui16TimeTillNextmS = 0;
    psHIDDevice->pfnTxCallback = HIDGamepadTxHandler;
    psHIDDevice->pvRxCBData = (void *)psGamepad;
    psHIDDevice->pfnRxCallback = HIDGamepadRxHandler;
    psHIDDevice->pvTxCBData = (void *)psGamepad;
    psHIDDevice->bUseOutEndpoint = false,
    psHIDDevice->psHIDDescriptor = &g_sGameHIDDescriptor;
    psHIDDevice->ppui8ClassDescriptors = g_ppui8GameClassDescriptors;
    psHIDDevice->ppui8StringDescriptors = psGamepad->ppui8StringDescriptors;
    psHIDDevice->ui32NumStringDescriptors =
                                          psGamepad->ui32NumStringDescriptors;
    psHIDDevice->ppsConfigDescriptor = g_ppsHIDConfigDescriptors;

    //
    // If there was an override for the report descriptor then use it.
    //
    if(psGamepad->pui8ReportDescriptor)
    {
        //
        // Save the report descriptor in the list of report descriptors.
        //
        g_ppui8GameClassDescriptors[0] = psGamepad->pui8ReportDescriptor;

        //
        // Override the report descriptor size.
        //
        g_sGameHIDDescriptor.sClassDescriptor[0].wDescriptorLength =
                                                    psGamepad->ui32ReportSize;
    }

    //
    // Initialize the lower layer HID driver and pass it the various structures
    // and descriptors necessary to declare that we are a gamepad.
    //
    return(USBDHIDCompositeInit(ui32Index, psHIDDevice, psCompEntry));
}
Exemplo n.º 4
0
//*****************************************************************************
//
//! Initializes HID mouse device operation for a given USB controller.
//!
//! \param ui32Index is the index of the USB controller which is to be
//! initialized for HID mouse device operation.
//! \param psMouseDevice points to a structure containing parameters
//! customizing the operation of the HID mouse device.
//! \param psCompEntry is the composite device entry to initialize when
//! creating a composite device.
//!
//! This call is very similar to USBDHIDMouseInit() except that it is used for
//! initializing an instance of the HID mouse device for use in a composite
//! device.  If this HID mouse is part of a composite device, then the
//! \e psCompEntry should point to the composite device entry to initialize.
//! This is part of the array that is passed to the USBDCompositeInit()
//! function.
//!
//! \return Returns zero on failure or a non-zero instance value that should be
//! used with the remaining USB HID Mouse APIs.
//
//*****************************************************************************
void *
USBDHIDMouseCompositeInit(uint32_t ui32Index,
                          tUSBDHIDMouseDevice *psMouseDevice,
                          tCompositeEntry *psCompEntry)
{
    tHIDMouseInstance *psInst;
    tUSBDHIDDevice *psHIDDevice;


    //
    // Check parameter validity.
    //
    ASSERT(psMouseDevice);
    ASSERT(psMouseDevice->ppui8StringDescriptors);
    ASSERT(psMouseDevice->pfnCallback);

    //
    // Get a pointer to our instance data
    //
    psInst = &psMouseDevice->sPrivateData;

    //
    // Get a pointer to the HID device data.
    //
    psHIDDevice = &psMouseDevice->sPrivateData.sHIDDevice;

    //
    // Initialize the various fields in our instance structure.
    //
    psInst->ui8USBConfigured = 0;
    psInst->ui8Protocol = USB_HID_PROTOCOL_REPORT;
    psInst->sReportIdle.ui8Duration4mS = 0;
    psInst->sReportIdle.ui8ReportID = 0;
    psInst->sReportIdle.ui32TimeSinceReportmS = 0;
    psInst->sReportIdle.ui16TimeTillNextmS = 0;
    psInst->iMouseState = eHIDMouseStateUnconfigured;

    //
    // Initialize the HID device class instance structure based on input from
    // the caller.
    //
    psHIDDevice->ui16PID = psMouseDevice->ui16PID;
    psHIDDevice->ui16VID = psMouseDevice->ui16VID;
    psHIDDevice->ui16MaxPowermA = psMouseDevice->ui16MaxPowermA;
    psHIDDevice->ui8PwrAttributes = psMouseDevice->ui8PwrAttributes;
    psHIDDevice->ui8Subclass = USB_HID_SCLASS_BOOT;
    psHIDDevice->ui8Protocol = USB_HID_PROTOCOL_MOUSE;
    psHIDDevice->ui8NumInputReports = 1;
    psHIDDevice->psReportIdle = &psInst->sReportIdle;
    psHIDDevice->pfnRxCallback = HIDMouseRxHandler;
    psHIDDevice->pvRxCBData = (void *)psMouseDevice;
    psHIDDevice->pfnTxCallback = HIDMouseTxHandler;
    psHIDDevice->pvTxCBData = (void *)psMouseDevice;
    psHIDDevice->bUseOutEndpoint = false;
    psHIDDevice->psHIDDescriptor = &g_sMouseHIDDescriptor;
    psHIDDevice->ppui8ClassDescriptors = g_pui8MouseClassDescriptors;
    psHIDDevice->ppui8StringDescriptors =
                                    psMouseDevice->ppui8StringDescriptors;
    psHIDDevice->ui32NumStringDescriptors =
                                    psMouseDevice->ui32NumStringDescriptors;
    psHIDDevice->ppsConfigDescriptor = g_ppsHIDConfigDescriptors;

    //
    // Initialize the lower layer HID driver and pass it the various structures
    // and descriptors necessary to declare that we are a keyboard.
    //
    return(USBDHIDCompositeInit(ui32Index, psHIDDevice, psCompEntry));
}
Exemplo n.º 5
0
int main(void) {
	int i;
	uint8_t data[64];

    // Enable lazy stacking for interrupt handlers.  This allows floating-point
    // instructions to be used within interrupt handlers, but at the expense of
    // extra stack usage.
    ROM_FPULazyStackingEnable();

    // Set the clocking to run from the PLL at 50MHz.
    ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
                       SYSCTL_XTAL_16MHZ);

    // Enable the GPIO peripheral used for USB, and configure the USB
    // pins.
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);

    ROM_GPIOPinTypeUSBAnalog(GPIO_PORTD_BASE, GPIO_PIN_4 | GPIO_PIN_5);

    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
	ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1 + GPIO_PIN_2 + GPIO_PIN_3);
	ROM_GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1 + GPIO_PIN_2 + GPIO_PIN_3, 0);

    // Init diagnostic
    diagnostic_clear_eventhistory();

    // Init UART
    ConfigureUART();

    // Print welcome message
    UARTprintf("Configuring USB\n");

    //------------------------------------------------------
//    // Set the USB stack mode to Device mode with VBUS monitoring.
//    USBStackModeSet(0, eUSBModeForceDevice, 0);
//
//    // Pass our device information to the USB library and place the device
//    // on the bus.
//    USBDHIDInit(0, &hiddatapipe_device);

    //------------------------------------------------------

    USBStackModeSet(0, eUSBModeForceDevice, 0);
    USBDHIDCompositeInit(0, &hiddatapipe_device, &(composite_device.psDevices[0]));
	USBDDFUCompositeInit(0, &dfu_device, &(composite_device.psDevices[1]));

	//
	// Pass the USB library our device information, initialize the USB
	// controller and connect the device to the bus.
	//
	USBDCompositeInit(0, &composite_device, DESCRIPTOR_BUFFER_SIZE, composite_descriptorbuffer);

    // Block until connected
    while (!usbstate.connected)
    	;

    // Configure SysTick
	ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / 1000); // 1 ms
	ROM_SysTickEnable();
	ROM_SysTickIntEnable();

	// enable first IN report by clearing USB tx complete
	usbstate.txcomplete = 1;

    while(1) {

    	// uncomment this if event history log is needed
//        if (events.print_history == true)
//        	diagnostic_print_eventhistory();

        // usbstate.txcomplete flag was set to 1 by txhandler after usbdhidreportwrite had succeeded
        if (usbstate.txcomplete  && usbstate.txdataupdated) {
        	// clear usbstate.txcomplete flag to indicate that usbdhidreportwrite is busy
        	usbstate.txcomplete = 0;
        	usbstate.txdataupdated = 0;
        	// put data (1 byte in this case) into the usb pipeline and the host will poll&read it
        	// the polling rate is defined in the interrupt IN endpoint descriptor

        	data[0] = txdata.buffer[0]; // temp buffer to avoid update change of txdata.buffer between the next 2 calls
        	USBDHIDReportWrite(&hiddatapipe_device, data, 1, 0);
        	UARTprintf("Sending irq IN to host: %d\n", data[0]);

        }

        if (usbstate.hostsentreport) {
        	// clear hostsentreport flag
        	usbstate.hostsentreport = 0;

        	for (i = 0; i < HID_REPORTOUT_SIZE; i++) {
        		UARTprintf("Received OUT report from host: %02x\n", rxdata.buffer[i]);
        		rxdata.buffer[i] = 0;
        	}

        }

    }
}