USB Host CDC APIs for Harmony v2

Files added to Host 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

Description Inputs Returns
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 ID CDC Handle

Example of opening a CDC Device:


USB_HOST_CDC_HANDLE cdcHostHandle;
USB_HOST_CDC_OBJ cdcObj;

. . .

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

Description Inputs Returns
USB_HOST_CDC_Close
Closes the association between the application entity that opened
the device and the device. The driver handle becomes invalid.
CDC Handle Void

Example of closing a CDC Device:


USB_HOST_CDC_HANDLE cdcHostHandle;

. . .

USB_HOST_CDC_Open(cdHostHandle);

. . .


USB_HOST_CDC_AttachEventHandlerSet

Description Inputs Returns
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_OBJ cdcObj;
. . .

void MyAttachFunction( USB_HOST_CDC_OBJ cdcObj, uintptr_t context);
{ … }
. . .

USB_HOST_CDC_AttachEventHandlerSet(MyAttachFunction, (uintptr_t) 0);


USB_HOST_CDC_EventHandlerSet

Description Inputs Returns
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_HANDLE cdcHostHandle;
USB_HOST_CDC_OBJ cdcObj;

. . .

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

Description Inputs Returns
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_HANDLE cdcHostHandle;
USB_HOST_CDC_RESULT result;

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

Description Inputs Returns
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_HANDLE cdcHostHandle;
USB_HOST_CDC_RESULT result;

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


Description Inputs Returns
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);

© 2024 Microchip Technology, Inc.
Notice: ARM and Cortex are the registered trademarks of ARM Limited in the EU and other countries.
Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.