USB Host CDC APIs for Harmony v2

Files added toHost CDC projects:

  • usb-host-cdc.h
  • usb-host-hub-cdc.h
  • usb-host-cdc.c
  • usb-host-cdc-acm.c

Application Programming Interfaces (APIs) provided:


USB_HOST_CDC_Open

DescriptionInputsReturns
USB_HOST_CDC_Open
Opens the specified Communication Device Class (CDC) device. Once opened,
the application will access the device by the
returned 'handle'.
Host CDC Object IDCDC Handle

Example of opening a CDC Device:


USB_HOST_CDC_HANDLEcdcHostHandle;
USB_HOST_CDC_OBJcdcObj;

. . .

cdcHostHandle =USB_HOST_CDC_Open(cdcObj);
if(cdcHostHandle != USB_HOST_CDC_HANDLE_INVALID)
{
/* The driver was opened successfully. Set the event handler
* and then go to the next state. */

}

. . .


USB_HOST_CDC_Close

DescriptionInputsReturns
USB_HOST_CDC_Close
Closes the association between the application entity that opened
the device and the device. The driver handle becomes invalid.
CDC HandleVoid

Example of closing a CDC Device:


USB_HOST_CDC_HANDLEcdcHostHandle;

. . .

USB_HOST_CDC_Open(cdHostHandle);

. . .


USB_HOST_CDC_AttachEventHandlerSet

DescriptionInputsReturns
USB_HOST_AttachEventHandlerSet
Sets the function to be called when the enumeration process
attaches the device.
Event Handler
Context
USB_HOST_CDC_RESULT

Example of setting the Attach Event handler:

USB_HOST_CDC_OBJcdcObj;
. . .

voidMyAttachFunction(USB_HOST_CDC_OBJcdcObj,uintptr_t context);
{ … }
. . .

USB_HOST_CDC_AttachEventHandlerSet(MyAttachFunction, (uintptr_t) 0);


USB_HOST_CDC_EventHandlerSet

DescriptionInputsReturns
USB_HOST_EventHandlerSet Registers the CDC Host Client driver
event handler for the specific device. This event handler is called by
the driver in response to data transfers by the client device.
Handle
Event Handler
Context
USB_HOST_CDC_RESULT

Example of setting the Event handler:


USB_HOST_CDC_HANDLEcdcHostHandle;
USB_HOST_CDC_OBJcdcObj;

. . .

cdcHostHandle =USB_HOST_CDC_Open(cdcObj);
if(cdcHostHandle != USB_HOST_CDC_HANDLE_INVALID)
{
/* The driver was opened successfully. Set the event handler */
USB_HOST_CDC_EventHandlerSet(cdcHostHandle, MyEventHandler, (uintptr_t)0);
}

. . .


USB_HOST_CDC_Write

DescriptionInputsReturns
USB_HOST_CDC_Write
Writes data to the specified device.
Handle
&Transfer Handle
&Data
length
USB_HOST_CDC_RESULT

Example of writing to a CDC Device:


USB_HOST_CDC_HANDLEcdcHostHandle;
USB_HOST_CDC_RESULTresult;

char prompt[] = "Good Morning" ;

. . .
result =USB_HOST_CDC_Write(cdcHostHandle, NULL, prompt, 13);

if(result == USB_HOST_CDC_RESULT_SUCCESS)
{
// transmit successfully initiated
}

. . .


USB_HOST_CDC_Read

DescriptionInputsReturns
USB_HOST_CDC_Read
Reads data from the specified device.
Handle
&Transfer Handle
&Data
Length
USB_HOST_CDC_RESULT

Example of reading from a CDC Device:


USB_HOST_CDC_HANDLEcdcHostHandle;
USB_HOST_CDC_RESULTresult;

char MyInputBuffer[0x20] ;

. . .
result =USB_HOST_CDC_Read(cdcHostHandle, NULL, MyInputBuffer, 0x20);

if(result == USB_HOST_CDC_EVENT_READ_COMPLETE)
{
// data was successfully received
}

. . .


USB_HOST_CDC_SerialStateNotificationGet


DescriptionInputsReturns
USB_HOST_SerialNotifiationGet
Requests Serial State notification from the attached device.
If the request was accepted, Transfer Handle will contain a
valid transfer handle, else it will contain
USB_HOST_CDC_TRANSFER_HANDLE_INVALID.
Handle
&Transfer Handle
&Serial State
USB_HOST_CDC_RESULT

Example of setting the getting the Serial State:

USB_CDC_SERIAL_STATE state;
USB_HOST_CDC_HANDLE cdcHostHandle;

. . .

USB_HOST_CDC_SerialStateNotificationGet(cdcHostHandle, &transferhandle, state);