CDC Class APIs

Files added to CDC Device projects:
usb-device-cdc.h
usb-cdc.h
usb-device-cdc.c
usb-device-cdc-acm.c

APIs provided:


USB_DEVICE_CDC_EventHandler Set

Description Inputs Returns
USB_DEVICE_CDC_EventHandlerSet
registers an event handler for a specified CDC
Driver instance.
USB Device CDC Instance,
Event Handler,
context
Status of the transfer request

Example of registering a CDC Event Handler

USB_DEVICE_CDC_RESULT result;


result = USB_DEVICE_CDC_EventHandlerSet( USB_DEVICE_CDC_INDEX_0,
&EventHandlerFunction,
0);


if( result != USB_DEVICE_CDC_RESULT_OK)
{
//Handle error.

}


USB_DEVICE_CDC_Write

Description Inputs Returns
USB_DEVICE_CDC_Write
initiates a CDC write by sending
a buffer of data to the CDC Driver.
The data is sent out by the driver in
response to Host requests.
USB Device CDC Instance,
Transfer Handle,
Pointer to Data,
Length,
Transfer Flag*
Status of the transfer request

* Note the Transfer Flag indicates whether or not the transfer should continue to the next USB frame or end. It is defined in the enum USB_DEVICE_TRANSFER_FLAG


Example of writing CDC Data

USB_DEVICE_CDC_RESULT result;



// Transfers 15 bytes of data from data-buffer.

result = USB_DEVICE_CDC_Write( USB_DEVICE_CDC_INDEX_0,
&transferhandle,
data-buffer,
15,
USB_DEVICE_CDC_TRANSFER_FLAGS_DATA_COMPLETE);


if( result != USB_DEVICE_CDC_RESULT_OK)
{
//Handle error.

}


USB_DEVICE_CDC_Read

Description Inputs Returns
USB_DEVICE_CDC_Read
requests data to be read from the CDC Function
driver layer. The request will be fulfilled
as data from the Host becomes available.
USB Device CDC Instance,
Transfer Handle,
Pointer input buffer,
Length,
Status of the transfer request

Example of CDC Read

USB_DEVICE_CDC_RESULT result;



// Receiving 127 bytes of data into input-buffer via the CDC interface

result = USB_DEVICE_CDC_Read( USB_DEVICE_CDC_INDEX_0,
&EventHandlerFunction,
input-buffer,
127 );


if( result != USB_DEVICE_CDC_RESULT_OK)
{
//Handle error.

}

USB_DEVICE_CDC_SerialStateNotificationSend

Description Inputs Returns
USB_DEVICE_CDC_SerialStateNotificationSend
sends a request to the CDC driver to send a Serial
State Notification to the Host.
USB Device CDC Instance,
Transfer Handle,
Notification Data
Status of the request

Example of registering a CDC Event Handler

USB_DEVICE_CDC_RESULT result;
USB_CDC_SERIAL_STATE notification;


result = USB_DEVICE_CDC_SerialStateNotificationSend( USB_DEVICE_CDC_INDEX_0,
&transferfunction,
&notification);


if( result != USB_DEVICE_CDC_RESULT_OK)
{
//Handle error.

}


20th Annual
Microchip MASTERs Conference 2016

JW Marriott Desert Ridge Resort-Phoenix, AZ

© 2016 Microchip Technology, Inc.
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.