Example #1
0
int getProtocol(tUSBHostDevice *pDevice)
{    
    t_u16 protocol = 0xFFFF;
    tUSBRequest SetupPacket;
    t_u32 ulBytes;
    ulBytes = 0;

    // This is a Vendor Device IN request.
    SetupPacket.bmRequestType = USB_RTYPE_DIR_IN | USB_RTYPE_VENDOR | USB_RTYPE_DEVICE;
    
    // Request an Accessory Get Protocol.
    SetupPacket.bRequest = ACCESSORY_GET_PROTOCOL;
    SetupPacket.wValue = 0;
    SetupPacket.wIndex = 0;
    SetupPacket.wLength = 2;

    // Put the setup packet in the buffer.
    ulBytes = USBHCDControlTransfer(0, &SetupPacket, pDevice->ulAddress,
                                    (t_u8 *)&protocol,
                                    SetupPacket.wLength,
                                    pDevice->DeviceDescriptor.bMaxPacketSize0);

    UARTprintf("getProtocol() ctrlReq return %d bytes, protocol:0x%02X\n", ulBytes, protocol);

    return protocol;
}
Example #2
0
//*****************************************************************************
//
//! This function is used to set the idle timeout for a HID device.
//!
//! \param psHIDInstance is the value that was returned from the call to
//! USBHHIDOpen().
//! \param ui8Duration is the duration of the timeout in milliseconds.
//! \param ui8ReportID is the report identifier to set the timeout on.
//!
//! This function will send the Set Idle command to a HID device to set the
//! idle timeout for a given report.  The length of the timeout is specified
//! by the \e ui8Duration parameter and the report the timeout for is in the
//! \e ui8ReportID value.
//!
//! \return Always returns 0.
//
//*****************************************************************************
uint32_t
USBHHIDSetIdle(tHIDInstance *psHIDInstance, uint8_t ui8Duration,
               uint8_t ui8ReportID)
{
    tUSBRequest sSetupPacket;

    //
    // This is a Class specific interface OUT request.
    //
    sSetupPacket.bmRequestType = USB_RTYPE_DIR_OUT | USB_RTYPE_CLASS |
                                 USB_RTYPE_INTERFACE;

    //
    // Request a Device Descriptor.
    //
    sSetupPacket.bRequest = USBREQ_SET_IDLE;
    sSetupPacket.wValue = (ui8Duration << 8) | ui8ReportID;

    //
    // Set this on interface 1.
    //
    sSetupPacket.wIndex = 0;

    //
    // This is always 0 for this request.
    //
    sSetupPacket.wLength = 0;

    //
    // Put the setup packet in the buffer.
    //
    return(USBHCDControlTransfer(0, &sSetupPacket, psHIDInstance->psDevice,
                                 0, 0, MAX_PACKET_SIZE_EP0));
}
Example #3
0
void sendString(tUSBHostDevice *pDevice, int index, const char *str)
{        
    tUSBRequest SetupPacket;
    t_u32 ulBytes;
    t_u16 wlen;     
    ulBytes = 0;

    wlen = strlen(str) + 1;

    // This is a Vendor Device OUT request.
    SetupPacket.bmRequestType = USB_RTYPE_DIR_OUT | USB_RTYPE_VENDOR | USB_RTYPE_DEVICE;

    // Request an Accessory Get Protocol.
    SetupPacket.bRequest = ACCESSORY_SEND_STRING;
    SetupPacket.wValue = 0;
    SetupPacket.wIndex = index;
    SetupPacket.wLength = wlen;

    // Put the setup packet in the buffer.
    ulBytes = USBHCDControlTransfer(0, &SetupPacket, pDevice->ulAddress,
                                    (t_u8 *)str,
                                    wlen,
                                    pDevice->DeviceDescriptor.bMaxPacketSize0);
    
    UARTprintf("sendString() ctrlReq return %d bytes\n", ulBytes);
}
Example #4
0
//*****************************************************************************
//
// This function is called to send a request to the hub to clear a feature on
// a given port.
//
// \param psHubInstance is the hub device instance.
// \param ui8Port is the port number for this request.
// \param ui16Feature is one of the HUB_FEATURE_PORT_* values.
//
// This function will send the clear feature request to the hub indicated by
// the \e psHubInstance parameter.  The \e ui8Port value indicates which port
// number to send this request to and can range from 0 to the number of valid
// ports on the given hub.  A \e ui8Port value of 0 is an access to the hub
// itself and not one of the hub ports.  The \e ui16Feature is the feature
// request to clear on the given port.  For example, a \e ui16Feature value of
// \e HUB_FEATURE_C_PORT_RESET and \e ui8Port value of 1 will clear the reset
// complete signaling on hub port 1.  Values like the reset feature will
// remain set until actively cleared by this function.
//
// \return None.
//
//*****************************************************************************
static void
HubClearPortFeature(tHubInstance *psHubInstance, uint8_t ui8Port,
                    uint16_t ui16Feature)
{
    tUSBRequest sSetupPacket;
    tUSBHostDevice *psDevice;

    //
    // Retrieve the hub instance and device pointer.
    //
    psDevice = psHubInstance->psDevice;

    //
    // This is a standard OUT request.
    //
    sSetupPacket.bmRequestType = USB_RTYPE_DIR_OUT | USB_RTYPE_CLASS |
                                 USB_RTYPE_OTHER;

    //
    // Set the field to clear the requested port feature.
    //
    sSetupPacket.bRequest = USBREQ_CLEAR_FEATURE;
    sSetupPacket.wValue = ui16Feature;
    sSetupPacket.wIndex = ui8Port;
    sSetupPacket.wLength = 0;

    //
    // Send the request.
    //
    USBHCDControlTransfer(0, &sSetupPacket, psDevice, 0, 0,
                          psDevice->sDeviceDescriptor.bMaxPacketSize0);
}
Example #5
0
//*****************************************************************************
//
// This function is used to retrieve the current status of a port on the
// hub.
//
// \param psHubInstance is the hub device instance.
// \param ui8Port is the port number for this request.
// \param pui16PortStatus is a pointer to the memory to store the current
// status of the port.
// \param pui16PortChange is a pointer to the memory to store the current
// change status of the ports.
//
// This function is used to retrieve the current overall status and change
// status for the port given in the \e ui8Port parameter.  The \e ui8Port value
// indicates which port number to send this request to and can range from 0 to
// the number of valid ports on the given hub.  A \e ui8Port value of 0 is an
// access to the hub itself and not one of the hub ports.
//
// \return None.
//
//*****************************************************************************
static bool
HubGetPortStatus(tHubInstance *psHubInstance, uint8_t ui8Port,
                 uint16_t *pui16PortStatus, uint16_t *pui16PortChange)
{
    uint32_t ui32Data, ui32Read;
    tUSBRequest sSetupPacket;
    tUSBHostDevice *psDevice;

    //
    // Retrieve the device pointer.
    //
    psDevice = psHubInstance->psDevice;

    //
    // This is a standard OUT request.
    //
    sSetupPacket.bmRequestType = USB_RTYPE_DIR_IN | USB_RTYPE_CLASS |
                                 USB_RTYPE_OTHER;

    //
    // Set the fields to get the hub status.
    //
    sSetupPacket.bRequest = USBREQ_GET_STATUS;
    sSetupPacket.wValue = 0;
    sSetupPacket.wIndex = (uint16_t)ui8Port;
    sSetupPacket.wLength = 4;

    //
    // Send the request.
    //
    ui32Read = USBHCDControlTransfer(0, &sSetupPacket, psDevice,
                                (uint8_t *)&ui32Data, 4,
                                psDevice->sDeviceDescriptor.bMaxPacketSize0);

    //
    // Check that we received the correct number of bytes.
    //
    if(ui32Read != 4)
    {
        return(false);
    }
    else
    {
        //
        // We got 4 bytes from the device. Now translate these into the 2
        // 16-bit values we pass back to the caller.
        //
        *pui16PortStatus = (uint16_t)(ui32Data & 0xFFFF);
        *pui16PortChange = (uint16_t)(ui32Data >> 16);

        DEBUG_OUTPUT("Port %d, status 0x%04x, change 0x%04x\n", ui8Port,
                     *pui16PortStatus, *pui16PortChange);
    }

    //
    // All is well.
    //
    return(true);
}
Example #6
0
//*****************************************************************************
//
//! This function is used to set or clear the boot protocol state of a device.
//!
//! \param ulInstance is the value that was returned from the call to
//! USBHHIDOpen().
//! \param ulBootProtocol is either zero or non-zero to indicate which protocol
//! to use for the device.
//!
//! A USB host device can use this function to set the protocol for a connected
//! HID device.  This is commonly used to set keyboards and mice into their
//! simplified boot protocol modes to fix the report structure to a know
//! state.
//!
//! \return This function returns 0.
//
//*****************************************************************************
unsigned long
USBHHIDSetProtocol(unsigned long ulInstance, unsigned long ulBootProtocol)
{
    tUSBRequest SetupPacket;
    tHIDInstance *pHIDInstance;

    pHIDInstance = (tHIDInstance *)ulInstance;

    //
    // This is a Standard Device IN request.
    //
    SetupPacket.bmRequestType = USB_RTYPE_DIR_OUT | USB_RTYPE_CLASS
                    | USB_RTYPE_INTERFACE;

    //
    // Request a Report Descriptor.
    //
    SetupPacket.bRequest = USBREQ_SET_PROTOCOL;

    if(ulBootProtocol)
    {
        //
        // Boot Protocol.
        //
        SetupPacket.wValue = 0;
    }
    else
    {
        //
        // Report Protocol.
        //
        SetupPacket.wValue = 1;
    }

    //
    // Index is always 0 for device requests.
    //
    SetupPacket.wIndex = 0;

    //
    // Always 0.
    //
    SetupPacket.wLength = 0;

    //
    // Now get the full descriptor now that the actual maximum packet size
    // is known.
    //
    USBHCDControlTransfer(
        0,
        &SetupPacket,
        pHIDInstance->pDevice->ulAddress,
        0,
        0,
        pHIDInstance->pDevice->DeviceDescriptor.bMaxPacketSize0);

    return (0);
}
Example #7
0
//*****************************************************************************
//
//! This function is used to set or clear the boot protocol state of a device.
//!
//! \param psHIDInstance is the value that was returned from the call to
//! USBHHIDOpen().
//! \param ui32BootProtocol is either zero or non-zero to indicate which
//! protocol to use for the device.
//!
//! A USB host device can use this function to set the protocol for a connected
//! HID device.  This is commonly used to set keyboards and mice into their
//! simplified boot protocol modes to fix the report structure to a know
//! state.
//!
//! \return This function returns 0.
//
//*****************************************************************************
uint32_t
USBHHIDSetProtocol(tHIDInstance *psHIDInstance, uint32_t ui32BootProtocol)
{
    tUSBRequest sSetupPacket;

    //
    // This is a Standard Device IN request.
    //
    sSetupPacket.bmRequestType = USB_RTYPE_DIR_OUT | USB_RTYPE_CLASS |
                                 USB_RTYPE_INTERFACE;

    //
    // Request a Report Descriptor.
    //
    sSetupPacket.bRequest = USBREQ_SET_PROTOCOL;

    if(ui32BootProtocol)
    {
        //
        // Boot Protocol.
        //
        sSetupPacket.wValue = 0;
    }
    else
    {
        //
        // Report Protocol.
        //
        sSetupPacket.wValue = 1;
    }

    //
    // Index is always 0 for device requests.
    //
    sSetupPacket.wIndex = 0;

    //
    // Always 0.
    //
    sSetupPacket.wLength = 0;

    //
    // Now get the full descriptor now that the actual maximum packet size
    // is known.
    //
    USBHCDControlTransfer(0, &sSetupPacket, psHIDInstance->psDevice, 0, 0,
                psHIDInstance->psDevice->sDeviceDescriptor.bMaxPacketSize0);

    return(0);
}
Example #8
0
//*****************************************************************************
//
// Query the class-specific hub descriptor.
//
//*****************************************************************************
static bool
GetHubDescriptor(tUsbHubDescriptor *psDesc)
{
    uint32_t ui32Read;
    tUSBRequest sSetupPacket;
    tUSBHostDevice *psDevice;

    //
    // Retrieve the device pointer.
    //
    psDevice = g_sRootHub.psDevice;

    //
    // This is a standard OUT request.
    //
    sSetupPacket.bmRequestType = USB_RTYPE_DIR_IN | USB_RTYPE_CLASS |
                                 USB_RTYPE_DEVICE;

    //
    // Set the fields to get the hub descriptor.  Initially, we request only
    // the first 4 bytes of the descriptor.  This will give us the size which
    // we use to determine how many bytes to read to get the full descriptor.
    // This is necessary since we don't know how many ports the hub can support
    // and we only support up to MAX_USB_DEVICES.
    //
    sSetupPacket.bRequest = USBREQ_GET_DESCRIPTOR;
    sSetupPacket.wValue = (USB_DTYPE_HUB << 8);
    sSetupPacket.wIndex = 0;
    sSetupPacket.wLength = sizeof(tUsbHubDescriptor);

    //
    // Send the request.
    //
    ui32Read = USBHCDControlTransfer(0, &sSetupPacket, psDevice,
                                (void *)psDesc, sizeof(tUsbHubDescriptor),
                                psDevice->sDeviceDescriptor.bMaxPacketSize0);

     //
     // Make sure we got at least some data.
     //
     if(ui32Read == 0)
     {
         return(false);
     }

    //
    // All is well.
    //
    return(true);
}
Example #9
0
//*****************************************************************************
//
//! This function can be used to retrieve the report descriptor for a given
//! device instance.
//!
//! \param ulInstance is the value that was returned from the call to
//! USBHHIDOpen().
//! \param pucBuffer is the memory buffer to use to store the report
//! descriptor.
//! \param ulSize is the size in bytes of the buffer pointed to by
//! \e pucBuffer.
//!
//! This function is used to return a report descriptor from a HID device
//! instance so that it can determine how to interpret reports that are
//! returned from the device indicated by the \e ulInstance parameter.
//! This call is blocking and will return the number of bytes read into the
//! \e pucBuffer.
//!
//! \return Returns the number of bytes read into the \e pucBuffer.
//
//*****************************************************************************
unsigned long
USBHHIDGetReportDescriptor(unsigned long ulInstance, unsigned char *pucBuffer,
                           unsigned long ulSize)
{
    tUSBRequest SetupPacket;
    unsigned long ulBytes;
    tHIDInstance *pHIDInstance;

    pHIDInstance = (tHIDInstance *)ulInstance;

    //
    // This is a Standard Device IN request.
    //
    SetupPacket.bmRequestType = USB_RTYPE_DIR_IN | USB_RTYPE_STANDARD
                    | USB_RTYPE_INTERFACE;

    //
    // Request a Report Descriptor.
    //
    SetupPacket.bRequest = USBREQ_GET_DESCRIPTOR;
    SetupPacket.wValue = USB_HID_DTYPE_REPORT << 8;

    //
    // Index is always 0 for device requests.
    //
    SetupPacket.wIndex = 0;

    //
    // All devices must have at least an 8 byte max packet size so just ask
    // for 8 bytes to start with.
    //
    SetupPacket.wLength = ulSize;

    //
    // Now get the full descriptor now that the actual maximum packet size
    // is known.
    //
    ulBytes = USBHCDControlTransfer(
                0,
                &SetupPacket,
                pHIDInstance->pDevice->ulAddress,
                pucBuffer,
                ulSize,
                pHIDInstance->pDevice->DeviceDescriptor.bMaxPacketSize0);

    return (ulBytes);
}
//*****************************************************************************
//
//! This function sets ACM baud rate
//!
//! \param ulAddress is the device address on the USB bus.
//! \param *dataptr is pointer to line coding structure
//!
//!
//! \return None.
//
//*****************************************************************************
int ACMSetLineCoding(tUSBHCDCInstance *psCDCInstance)  //, struct tLineCoding *dataptr)
{
	//System_printf("ACMSetLineCoding: Start\n");
	//System_flush();

    tUSBRequest SetupPacket;

    //
    // This is a Class specific interface OUT request.
    //
    SetupPacket.bmRequestType = bmREQ_CDCOUT;

    //
    // Request a set baud rate
    //
    SetupPacket.bRequest = CDC_SET_LINE_CODING;
    SetupPacket.wValue = 0;

    //
    // Indicate the index
    //
    SetupPacket.wIndex = 0;

    //
    // Zero bytes request
    //
    SetupPacket.wLength = 7;  //sizeof(struct tLineCoding);


    // This is 19200, 8, N, 1
	unsigned char byteLC[] = { 0x00, 0x4B, 0x00, 0x00, 0x00, 0x00, 0x08 };

	unsigned char *byteLCPtr;
	byteLCPtr = byteLC;

    //
    // Put the setup packet in the buffer and send the command.
    //
    if(USBHCDControlTransfer(0, &SetupPacket, psCDCInstance->psDevice, byteLCPtr, 7, MAX_PACKET_SIZE_EP0))
    {
		return 1;
    }

    return 0;
}
Example #11
0
int getConfigDesc(tUSBHostDevice *pDevice)
{
    tUSBRequest SetupPacket;
    t_u32 ulBytes;
    tConfigDescriptor* pconf_desc;

    ulBytes = 0;

    // This is a Standard Device IN request.
    SetupPacket.bmRequestType =
    USB_RTYPE_DIR_IN | USB_RTYPE_STANDARD | USB_RTYPE_DEVICE;

    // Request a Device Descriptor.
    SetupPacket.bRequest = USBREQ_GET_DESCRIPTOR;
    SetupPacket.wValue = USB_DTYPE_CONFIGURATION << 8;

    // Index is always 0 for device configurations requests.
    SetupPacket.wIndex = 0;

    // Save the total size and request the full configuration descriptor.
    SetupPacket.wLength = 0x09;

    // Put the setup packet in the buffer.
    ulBytes = USBHCDControlTransfer(0, &SetupPacket, pDevice->ulAddress,
                                    (t_u8 *)&configDesc[0],
                                    SetupPacket.wLength,
                                    pDevice->DeviceDescriptor.bMaxPacketSize0);

    pconf_desc = (tConfigDescriptor*)&configDesc[0];
    UARTprintf("getConfigDesc() ctrlReq return %d bytes\n", ulBytes);
    if(ulBytes > 0)
    {
        UARTprintf("configDesc details:\n");
        UARTprintf(" bLength=0x%02X (shall be 0x09)\n", pconf_desc->bLength);
        UARTprintf(" wTotalLength=0x%04X\n", pconf_desc->wTotalLength);
        UARTprintf(" bDescriptorType=0x%02X\n", pconf_desc->bDescriptorType);
        UARTprintf(" bNumInterfaces=0x%02X\n", pconf_desc->bNumInterfaces);    
        UARTprintf(" bConfigurationValue=0x%02X\n", pconf_desc->bConfigurationValue);
        UARTprintf(" iConfiguration=0x%02X\n", pconf_desc->iConfiguration);
        UARTprintf(" bmAttributes=0x%02X\n", pconf_desc->bmAttributes);
        UARTprintf(" bMaxPower=0x%02X (unit of 2mA)\n\n", pconf_desc->bMaxPower);    
    }
    
    return(ulBytes);
}
Example #12
0
//*****************************************************************************
//
//! This function is used to set the idle timeout for a HID device.
//!
//! \param ulInstance is the value that was returned from the call to
//! USBHHIDOpen().
//! \param ucDuration is the duration of the timeout in milliseconds.
//! \param ucReportID is the report identifier to set the timeout on.
//!
//! This function will send the Set Idle command to a HID device to set the
//! idle timeout for a given report.  The length of the timeout is specified
//! by the \e ucDuration parameter and the report the timeout for is in the
//! \e ucReportID value.
//!
//! \return Always returns 0.
//
//*****************************************************************************
unsigned long
USBHHIDSetIdle(unsigned long ulInstance, unsigned char ucDuration,
               unsigned char ucReportID)
{
    tUSBRequest SetupPacket;
    tHIDInstance *pHIDInstance;

    pHIDInstance = (tHIDInstance *)ulInstance;

    //
    // This is a Class specific interface OUT request.
    //
    SetupPacket.bmRequestType = USB_RTYPE_DIR_OUT | USB_RTYPE_CLASS
                    | USB_RTYPE_INTERFACE;

    //
    // Request a Device Descriptor.
    //
    SetupPacket.bRequest = USBREQ_SET_IDLE;
    SetupPacket.wValue = (ucDuration << 8) | ucReportID;

    //
    // Set this on interface 1.
    //
    SetupPacket.wIndex = 0;

    //
    // This is always 0 for this request.
    //
    SetupPacket.wLength = 0;

    //
    // Put the setup packet in the buffer.
    //
    USBHCDControlTransfer(0,
                          &SetupPacket,
                          pHIDInstance->pDevice->ulAddress,
                          0,
                          0,
                          MAX_PACKET_SIZE_EP0);

    return (0);
}
Example #13
0
//*****************************************************************************
//
//! This function is used to send a report to a HID device.
//!
//! \param ulInstance is the value that was returned from the call to
//! USBHHIDOpen().
//! \param ulInterface is the interface to send the report to.
//! \param pucData is the memory buffer to use to store the report.
//! \param ulSize is the size in bytes of the buffer pointed to by
//! \e pucBuffer.
//!
//! This function is used to send a report to a USB HID device.  It can be
//! only be called from outside the callback context as this function will not
//! return from the call until the data has been sent successfully.
//!
//! \return Returns the number of bytes sent to the device.
//
//*****************************************************************************
unsigned long
USBHHIDSetReport(unsigned long ulInstance, unsigned long ulInterface,
                 unsigned char *pucData, unsigned long ulSize)
{
    tUSBRequest SetupPacket;
    tHIDInstance *pHIDInstance;

    pHIDInstance = (tHIDInstance *)ulInstance;

    //
    // This is a Standard Device IN request.
    //
    SetupPacket.bmRequestType = USB_RTYPE_DIR_OUT | USB_RTYPE_CLASS
                    | USB_RTYPE_INTERFACE;

    //
    // Request a Report Descriptor.
    //
    SetupPacket.bRequest = USBREQ_SET_REPORT;
    SetupPacket.wValue = USB_HID_REPORT_OUTPUT << 8;

    //
    // Index is always 0 for device requests.
    //
    SetupPacket.wIndex = (unsigned short)ulInterface;

    //
    // Always 0.
    //
    SetupPacket.wLength = ulSize;

    //
    // Now get the full descriptor now that the actual maximum packet size
    // is known.
    //
    USBHCDControlTransfer(0, &SetupPacket, pHIDInstance->pDevice->ulAddress,
                          pucData, ulSize,
                      pHIDInstance->pDevice->DeviceDescriptor.bMaxPacketSize0);

    return (ulSize);
}
Example #14
0
//*****************************************************************************
//
//! This function can be used to retrieve the report descriptor for a given
//! device instance.
//!
//! \param psHIDInstance is the value that was returned from the call to
//! USBHHIDOpen().
//! \param pui8Buffer is the memory buffer to use to store the report
//! descriptor.
//! \param ui32Size is the size in bytes of the buffer pointed to by
//! \e pui8Buffer.
//!
//! This function is used to return a report descriptor from a HID device
//! instance so that it can determine how to interpret reports that are
//! returned from the device indicated by the \e psHIDInstance parameter.
//! This call is blocking and will return the number of bytes read into the
//! \e pui8Buffer.
//!
//! \return Returns the number of bytes read into the \e pui8Buffer.
//
//*****************************************************************************
uint32_t
USBHHIDGetReportDescriptor(tHIDInstance *psHIDInstance, uint8_t *pui8Buffer,
                           uint32_t ui32Size)
{
    tUSBRequest sSetupPacket;
    uint32_t ui32Bytes;

    //
    // This is a Standard Device IN request.
    //
    sSetupPacket.bmRequestType = USB_RTYPE_DIR_IN | USB_RTYPE_STANDARD |
                                 USB_RTYPE_INTERFACE;

    //
    // Request a Report Descriptor.
    //
    sSetupPacket.bRequest = USBREQ_GET_DESCRIPTOR;
    sSetupPacket.wValue = USB_HID_DTYPE_REPORT << 8;

    //
    // Index is always 0 for device requests.
    //
    sSetupPacket.wIndex = 0;

    //
    // All devices must have at least an 8 byte max packet size so just ask
    // for 8 bytes to start with.
    //
    sSetupPacket.wLength = ui32Size;

    //
    // Now get the full descriptor now that the actual maximum packet size
    // is known.
    //
    ui32Bytes = USBHCDControlTransfer(0, &sSetupPacket,
                psHIDInstance->psDevice, pui8Buffer, ui32Size,
                psHIDInstance->psDevice->sDeviceDescriptor.bMaxPacketSize0);

    return(ui32Bytes);
}
//*****************************************************************************
//
//! This function gets ACM Control Line
//!
//! \param ulAddress is the device address on the USB bus.
//! \param State is the State of Control Line
//!
//!
//! \return None.
//
//*****************************************************************************
int ACMGetLineStatus(tUSBHCDCInstance *psCDCInstance)  //, struct tLineStatus *dataptr)
{
	//System_printf("ACMGetLineState: Start\n");
	//System_flush();

    tUSBRequest SetupPacket;

    //
    // This is a Class specific interface IN request.
    //
    SetupPacket.bmRequestType = bmREQ_CDCIN;

    //
    // Request a set baud rate
    //
    SetupPacket.bRequest = CDC_GET_LINE_PARMS;
    SetupPacket.wValue = 0;

    //
    // Indicate the index
    //
    SetupPacket.wIndex = 0;

    //
    // Size of Structure
    //
    SetupPacket.wLength = 7; //sizeof(struct tLineStatus);

    //
    // Put the setup packet in the buffer and send the command.
    //
    if(USBHCDControlTransfer(0, &SetupPacket, psCDCInstance->psDevice, 0, 0, MAX_PACKET_SIZE_EP0))
    {
		return 1;
    }

    return 0;
}
//*****************************************************************************
//
//! This function sets ACM Control Line
//!
//! \param ulAddress is the device address on the USB bus.
//! \param State is the State of Control Line
//!
//! \return None.
//
//*****************************************************************************
int ACMSetControlLineState(tUSBHCDCInstance *psCDCInstance,  int State)
{
	//System_printf("ACMSetControlLineState: Start\n");
	//System_flush();

	tUSBRequest SetupPacket;

    //
    // This is a Class specific interface OUT request.
    //
    SetupPacket.bmRequestType = bmREQ_CDCOUT;  // 0 - host to

    //
    // Request a set baud rate
    //
    SetupPacket.bRequest = CDC_SET_CONTROL_LINE_STATE;
    SetupPacket.wValue = State;

    //
    // Indicate the index
    //
    SetupPacket.wIndex = State; // 2; //This depends on wValue - should be the same the wValue

    //
    // Zero bytes request
    //
    SetupPacket.wLength = 0;

    //
    // Put the setup packet in the buffer and send the command.
    //
    if(USBHCDControlTransfer(0, &SetupPacket, psCDCInstance->psDevice, 0, 0, MAX_PACKET_SIZE_EP0))
    {
		return 1;
    }

    return 0;
}
Example #17
0
//*****************************************************************************
//
//! This function is used to send a report to a HID device.
//!
//! \param psHIDInstance is the value that was returned from the call to
//! USBHHIDOpen().
//! \param ui32Interface is the interface to send the report to.
//! \param pui8Data is the memory buffer to use to store the report.
//! \param ui32Size is the size in bytes of the buffer pointed to by
//! \e pui8Buffer.
//!
//! This function is used to send a report to a USB HID device.  It can be
//! only be called from outside the callback context as this function will not
//! return from the call until the data has been sent successfully.
//!
//! \return Returns the number of bytes sent to the device.
//
//*****************************************************************************
uint32_t
USBHHIDSetReport(tHIDInstance *psHIDInstance, uint32_t ui32Interface,
                 uint8_t *pui8Data, uint32_t ui32Size)
{
    tUSBRequest sSetupPacket;

    //
    // This is a class specific OUT request.
    //
    sSetupPacket.bmRequestType = USB_RTYPE_DIR_OUT | USB_RTYPE_CLASS |
                                 USB_RTYPE_INTERFACE;

    //
    // Request a Report Descriptor.
    //
    sSetupPacket.bRequest = USBREQ_SET_REPORT;
    sSetupPacket.wValue = USB_HID_REPORT_OUTPUT << 8;

    //
    // Index is always 0 for device requests.
    //
    sSetupPacket.wIndex = (uint16_t)ui32Interface;

    //
    // Always 0.
    //
    sSetupPacket.wLength = ui32Size;

    //
    // Now get the full descriptor now that the actual maximum packet size
    // is known.
    //
    USBHCDControlTransfer(0, &sSetupPacket, psHIDInstance->psDevice,
            pui8Data, ui32Size,
            psHIDInstance->psDevice->sDeviceDescriptor.bMaxPacketSize0);

    return(ui32Size);
}
Example #18
0
//*****************************************************************************
//
//! This function retrieves the maximum number of the logical units on a
//! mass storage device.
//!
//! \param ulAddress is the device address on the USB bus.
//! \param ulInterface is the interface number on the device specified by the
//! \e ulAddress parameter.
//! \param pucMaxLUN is the byte value returned from the device for the
//! device's maximum logical unit.
//!
//! The device will return one byte of data that contains the maximum LUN
//! supported by the device.  For example, if the device supports four LUNs
//! then the LUNs would be numbered from 0 to 3 and the return value would be
//! 3.  If no LUN is associated with the device, the value returned shall be 0.
//!
//! \return None.
//
//*****************************************************************************
static void
USBHMSCGetMaxLUN(unsigned int ulIndex, unsigned int ulAddress,
                 unsigned int ulInterface, unsigned char *pucMaxLUN)
{
    tUSBRequest SetupPacket;


    //
    // This is a Class specific interface IN request.
    //
    SetupPacket.bmRequestType =
        USB_RTYPE_DIR_IN | USB_RTYPE_CLASS | USB_RTYPE_INTERFACE;

    //
    // Request a the Max LUN for this interface.
    //
    SetupPacket.bRequest = USBREQ_GET_MAX_LUN;
    SetupPacket.wValue = 0;

    //
    // Indicate the interface to use.
    //
    SetupPacket.wIndex = (unsigned short)ulInterface;

    //
    // Only request a single byte of data.
    //
    SetupPacket.wLength = 1;

    //
    // Put the setup packet in the buffer and send the command.
    //
    if(USBHCDControlTransfer(ulIndex, &SetupPacket, ulAddress, pucMaxLUN, 1,
                             MAX_PACKET_SIZE_EP0) != 1)
    {
        *pucMaxLUN = 0;
    }
}
Example #19
0
//*****************************************************************************
//
//! This function retrieves the maximum number of the logical units on a
//! mass storage device.
//!
//! \param psDevice is the device instance pointer for this request.
//! \param ui32Interface is the interface number on the device specified by the
//! \e ui32Address parameter.
//! \param pui8MaxLUN is the byte value returned from the device for the
//! device's maximum logical unit.
//!
//! The device will return one byte of data that contains the maximum LUN
//! supported by the device.  For example, if the device supports four LUNs
//! then the LUNs would be numbered from 0 to 3 and the return value would be
//! 3.  If no LUN is associated with the device, the value returned shall be 0.
//!
//! \return None.
//
//*****************************************************************************
static void
USBHMSCGetMaxLUN(tUSBHostDevice *psDevice, uint32_t ui32Interface,
                 uint8_t *pui8MaxLUN)
{
    tUSBRequest sSetupPacket;

    //
    // This is a Class specific interface IN request.
    //
    sSetupPacket.bmRequestType =
        USB_RTYPE_DIR_IN | USB_RTYPE_CLASS | USB_RTYPE_INTERFACE;

    //
    // Request a the Max LUN for this interface.
    //
    sSetupPacket.bRequest = USBREQ_GET_MAX_LUN;
    writeusb16_t(&(sSetupPacket.wValue), 0);

    //
    // Indicate the interface to use.
    //
    writeusb16_t(&(sSetupPacket.wIndex), (uint16_t)ui32Interface);

    //
    // Only request a single byte of data.
    //
    writeusb16_t(&(sSetupPacket.wLength), 1);

    //
    // Put the setup packet in the buffer and send the command.
    //
    if(USBHCDControlTransfer(0, &sSetupPacket, psDevice, pui8MaxLUN, 1,
                             MAX_PACKET_SIZE_EP0) != 1)
    {
        *pui8MaxLUN = 0;
    }
}
Example #20
0
void sendStartUpAccessoryMode(tUSBHostDevice *pDevice)
{
    tUSBRequest SetupPacket;
    t_u32 ulBytes;
    ulBytes = 0;
    int nodata;    

    // This is a Vendor Device OUT request.
    SetupPacket.bmRequestType = USB_RTYPE_DIR_OUT | USB_RTYPE_VENDOR | USB_RTYPE_DEVICE;

    // Request an Accessory Get Protocol.
    SetupPacket.bRequest = ACCESSORY_START;
    SetupPacket.wValue = 0;
    SetupPacket.wIndex = 0;
    SetupPacket.wLength = 0;

    // Put the setup packet in the buffer.
    ulBytes = USBHCDControlTransfer(0, &SetupPacket, pDevice->ulAddress,
                                    (t_u8 *)&nodata,
                                    0,
                                    pDevice->DeviceDescriptor.bMaxPacketSize0);

    UARTprintf("sendStartUpAccessoryMode() ctrlReq return %d bytes\n", ulBytes);
}
Example #21
0
int getDeviceDesc(tUSBHostDevice *pDevice)
{
    tUSBRequest SetupPacket;
    t_u32 ulBytes;
    tDeviceDescriptor* pdev_desc;

    ulBytes = 0;

    // This is a Standard Device IN request.
    SetupPacket.bmRequestType =
    USB_RTYPE_DIR_IN | USB_RTYPE_STANDARD | USB_RTYPE_DEVICE;

    // Request a Device Descriptor.
    SetupPacket.bRequest = USBREQ_GET_DESCRIPTOR;
    SetupPacket.wValue = USB_DTYPE_DEVICE << 8;

    // Index is always 0 for device requests.
    SetupPacket.wIndex = 0;

    // All devices must have at least an 8 t_u8 max packet size so just ask
    // for 8 bytes to start with.
    SetupPacket.wLength = 8;

    ulBytes = 0;

    // Discover the max packet size for endpoint 0.
    if(pDevice->DeviceDescriptor.bMaxPacketSize0 == 0)
    {
        // Put the setup packet in the buffer.
        ulBytes = USBHCDControlTransfer(0, &SetupPacket, pDevice->ulAddress,
                                        (t_u8 *)&devDesc[0],
                                        sizeof(tDeviceDescriptor),
                                        MAX_PACKET_SIZE_EP0);
    }

    // Now get the full descriptor now that the actual maximum packet size
    // is known.
    if(ulBytes < sizeof(tDeviceDescriptor))
    {
        SetupPacket.wLength = (t_u16)sizeof(tDeviceDescriptor);

        ulBytes =
        USBHCDControlTransfer(0, &SetupPacket, pDevice->ulAddress,
        (t_u8 *)&devDesc[0],
        sizeof(tDeviceDescriptor),
        pDevice->DeviceDescriptor.bMaxPacketSize0);
    }

    pdev_desc = (tDeviceDescriptor*)&devDesc[0];
    UARTprintf("getDeviceDesc() ctrlReq return %d bytes\n", ulBytes);
    if(ulBytes > 0)
    {
        UARTprintf("DeviceDesc details:\n");        
        UARTprintf(" bLength=0x%02X (shall be 0x12)\n",  pdev_desc->bLength);
        UARTprintf(" bDescriptorType=0x%02X\n", pdev_desc->bDescriptorType);
        UARTprintf(" bcdUSB=0x%02X (USB2.0=0x200)\n",  pdev_desc->bcdUSB);
        UARTprintf(" bDeviceClass=0x%02X\n",  pdev_desc->bDeviceClass);
        UARTprintf(" bDeviceSubClass=0x%02X\n", pdev_desc->bDeviceSubClass);    
        UARTprintf(" bDeviceProtocol=0x%02X\n", pdev_desc->bDeviceProtocol);
        UARTprintf(" bMaxPacketSize0=0x%02X\n", pdev_desc->bMaxPacketSize0);
        UARTprintf(" idVendor=0x%02X\n", pdev_desc->idVendor);
        UARTprintf(" idProduct=0x%02X\n", pdev_desc->idProduct);
        UARTprintf(" bcdDevice=0x%02X\n", pdev_desc->bcdDevice);
        UARTprintf(" iManufacturer=0x%02X\n", pdev_desc->iManufacturer);        
        UARTprintf(" iProduct=0x%02X\n", pdev_desc->iProduct);    
        UARTprintf(" iSerialNumber=0x%02X\n", pdev_desc->iSerialNumber);    
        UARTprintf(" bNumConfigurations=0x%02X\n\n", pdev_desc->bNumConfigurations);        
    }
    
    return(ulBytes);
}