Пример #1
0
//*****************************************************************************
//
//! Initializes HID customhid device operation for a given USB controller.
//!
//! \param ui32Index is the index of the USB controller which is to be
//! initialized for HID customhid device operation.
//! \param psCustomHidDevice points to a structure containing parameters
//! customizing the operation of the HID customhid device.
//!
//! An application wishing to offer a USB HID customhid interface to a USB host
//! must call this function to initialize the USB controller and attach the
//! customhid device to the USB bus.  This function performs all required USB
//! initialization.
//!
//! On successful completion, this function will return the \e psCustomHidDevice
//! pointer passed to it.  This must be passed on all future calls to the HID
//! customhid device driver.
//!
//! When a host connects and configures the device, the application callback
//! will receive \b USB_EVENT_CONNECTED after which calls can be made to
//! USBDHIDCustomHidStateChange() to report pointer movement and button presses
//! to the host.
//!
//! \note The application must not make any calls to the lower level USB device
//! interfaces if interacting with USB via the USB HID customhid device API.
//! Doing so will cause unpredictable (though almost certainly unpleasant)
//! behavior.
//!
//! \return Returns NULL on failure or the psCustomHidDevice pointer on success.
//
//*****************************************************************************
void *
USBDHIDCustomHidInit(uint32_t ui32Index, tUSBDHIDCustomHidDevice *psCustomHidDevice)
{
    void *pvRetcode;
    tUSBDHIDDevice *psHIDDevice;
    tConfigDescriptor *pConfigDesc;

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

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

    pConfigDesc = (tConfigDescriptor *)g_pui8CustomHidDescriptor;
    pConfigDesc->bmAttributes = psCustomHidDevice->ui8PwrAttributes;
    pConfigDesc->bMaxPower =  (uint8_t)(psCustomHidDevice->ui16MaxPowermA / 2);

    //
    // Call the common initialization routine.
    //
    pvRetcode = USBDHIDCustomHidCompositeInit(ui32Index, psCustomHidDevice, 0);

    //
    // If we initialized the HID layer successfully, pass our device pointer
    // back as the return code, otherwise return NULL to indicate an error.
    //
    if(pvRetcode)
    {
        //
        // Initialize the lower layer HID driver and pass it the various
        // structures and descriptors necessary to declare that we are a
        // keyboard.
        //
        pvRetcode = USBDHIDInit(ui32Index, psHIDDevice);

        return((void *)psCustomHidDevice);
    }
    else
    {
        return((void *)0);
    }
}
//*****************************************************************************
//
//! Initializes HID customhid device operation for a given USB controller.
//!
//! \param ulIndex is the index of the USB controller which is to be
//! initialized for HID customhid device operation.
//! \param psDevice points to a structure containing parameters customizing
//! the operation of the HID customhid device.
//!
//! An application wishing to offer a USB HID customhid interface to a USB host
//! must call this function to initialize the USB controller and attach the
//! customhid device to the USB bus.  This function performs all required USB
//! initialization.
//!
//! On successful completion, this function will return the \e psDevice pointer
//! passed to it.  This must be passed on all future calls to the HID customhid
//! device driver.
//!
//! When a host connects and configures the device, the application callback
//! will receive \b USB_EVENT_CONNECTED after which calls can be made to
//! USBDHIDCustomHidStateChange() to report pointer movement and button presses
//! to the host.
//!
//! \note The application must not make any calls to the lower level USB device
//! interfaces if interacting with USB via the USB HID customhid device API.
//! Doing so will cause unpredictable (though almost certainly unpleasant)
//! behavior.
//!
//! \return Returns NULL on failure or the psDevice pointer on success.
//
//*****************************************************************************
void *
USBDHIDCustomHidInit(unsigned long ulIndex, const tUSBDHIDCustomHidDevice *psDevice)
{
    void *pvRetcode;
    tUSBDHIDDevice *psHIDDevice;

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

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

    //
    // Call the common initialization routine.
    //
    pvRetcode = USBDHIDCustomHidCompositeInit(ulIndex, psDevice);

    //
    // If we initialized the HID layer successfully, pass our device pointer
    // back as the return code, otherwise return NULL to indicate an error.
    //
    if(pvRetcode)
    {
        //
        // Initialize the lower layer HID driver and pass it the various
        // structures and descriptors necessary to declare that we are a
        // keyboard.
        //
        pvRetcode = USBDHIDInit(ulIndex, psHIDDevice);

        return((void *)psDevice);
    }
    else
    {
        return((void *)0);
    }
}