USB Device CDC API#
USB Device CDC API.
Modules#
Typedefs#
Async comm callback.
Functions#
FUNCTION PROTOTYPES.
Add a new instance of the CDC class.
Add a CDC instance into the USB device configuration.
Get the CDC class enable state.
Add a data interface class to the CDC communication interface class.
Receive data on the CDC data interface.
Receive data on the CDC data interface asynchronously.
Send data on the CDC data interface.
Send data on the CDC data interface asynchronously.
Send a communication interface class notification to the host.
Macros#
MODULE.
COMMUNICATIONS CLASS SUBCLASS CODES DEFINES.
COMMUNICATION CLASS PROTOCOL CODES DEFINES.
DATA INTERFACE CLASS PROTOCOL CODES DEFINES.
MANAGEMENT ELEMENTS REQUESTS DEFINES.
CDC FUNCTIONAL DESCRIPTOR TYPE DEFINES.
CDC FUNCTIONAL DESCRIPTOR SUBTYPE DEFINES.
CDC NOTIFICATION DEFINES.
Typedef Documentation#
sl_usbd_cdc_async_function_t#
typedef void(* sl_usbd_cdc_async_function_t) (uint8_t class_nbr, void *p_buf, uint32_t buf_len, uint32_t xfer_len, void *p_callback_arg, sl_status_t status) )(uint8_t class_nbr, void *p_buf, uint32_t buf_len, uint32_t xfer_len, void *p_callback_arg, sl_status_t status)
Async comm callback.
Function Documentation#
sl_usbd_cdc_init#
sl_status_t sl_usbd_cdc_init (void )
FUNCTION PROTOTYPES.
Type | Direction | Argument Name | Description |
---|---|---|---|
void | N/A |
CDC FUNCTIONS
Initializes CDC class.
Returns
Returns SL_STATUS_OK on success or another SL_STATUS code on failure.
sl_usbd_cdc_create_instance#
sl_status_t sl_usbd_cdc_create_instance (uint8_t subclass, sl_usbd_cdc_subclass_driver_t * p_subclass_drv, void * p_subclass_arg, uint8_t protocol, bool notify_en, uint16_t notify_interval, uint8_t * p_class_nbr)
Add a new instance of the CDC class.
Type | Direction | Argument Name | Description |
---|---|---|---|
uint8_t | N/A | subclass | Communication class subclass subcode (see Note #1). |
sl_usbd_cdc_subclass_driver_t * | N/A | p_subclass_drv | Pointer to the CDC subclass driver. |
void * | N/A | p_subclass_arg | Pointer to the CDC subclass driver argument. |
uint8_t | N/A | protocol | Communication class protocol code. |
bool | N/A | notify_en | Notification enabled : true Enable CDC class notifications. false Disable CDC class notifications. |
uint16_t | N/A | notify_interval | Notification interval in milliseconds (must be a power of 2). |
uint8_t * | N/A | p_class_nbr | Pointer to a variable that will receive class instance number. The variable is set to CDC class instance number if no errors are returned., otherwise it is set to SL_USBD_CDC_NBR_NONE. |
Returns
Returns SL_STATUS_OK on success or another SL_STATUS code on failure.
Note
(1) Communication class subclass codes are defined in 'sl_usbd_class_cdc.h' 'SL_USBD_CDC_SUBCLASS_XXXX'.
sl_usbd_cdc_add_to_configuration#
sl_status_t sl_usbd_cdc_add_to_configuration (uint8_t class_nbr, uint8_t config_nbr)
Add a CDC instance into the USB device configuration.
Type | Direction | Argument Name | Description |
---|---|---|---|
uint8_t | N/A | class_nbr | Class instance number. |
uint8_t | N/A | config_nbr | Configuration index to which to add the new CDC class interface. |
Returns
Returns SL_STATUS_OK on success or another SL_STATUS code on failure.
sl_usbd_cdc_is_enabled#
sl_status_t sl_usbd_cdc_is_enabled (uint8_t class_nbr, bool * p_enabled)
Get the CDC class enable state.
Type | Direction | Argument Name | Description |
---|---|---|---|
uint8_t | N/A | class_nbr | Class instance number. |
bool * | N/A | p_enabled | Pointer to a boolean variable that will receive enable state. The variable is set to true if CDC class is enabled. The variable is set to false if CDC class is not enabled. |
Returns
Returns SL_STATUS_OK on success or another SL_STATUS code on failure.
sl_usbd_cdc_add_data_interface#
sl_status_t sl_usbd_cdc_add_data_interface (uint8_t class_nbr, bool isoc_en, uint8_t protocol, uint8_t * p_if_nbr)
Add a data interface class to the CDC communication interface class.
Type | Direction | Argument Name | Description |
---|---|---|---|
uint8_t | N/A | class_nbr | Class instance number. |
bool | N/A | isoc_en | Data interface isochronous enable (see Note #1) :
|
uint8_t | N/A | protocol | Data interface protocol code. |
uint8_t * | N/A | p_if_nbr | Pointer to a variable that will receive data interface number. |
Returns
Returns SL_STATUS_OK on success or another SL_STATUS code on failure.
Note
(1) The value of 'isoc_en' must be false. Isochronous EPs are not supported.
sl_usbd_cdc_read_data#
sl_status_t sl_usbd_cdc_read_data (uint8_t class_nbr, uint8_t data_if_nbr, uint8_t * p_buf, uint32_t buf_len, uint16_t timeout, uint32_t * p_xfer_len)
Receive data on the CDC data interface.
Type | Direction | Argument Name | Description |
---|---|---|---|
uint8_t | N/A | class_nbr | Class instance number. |
uint8_t | N/A | data_if_nbr | CDC data interface number. |
uint8_t * | N/A | p_buf | Pointer to the destination buffer to receive data. |
uint32_t | N/A | buf_len | Number of octets to receive. |
uint16_t | N/A | timeout | Timeout in milliseconds. |
uint32_t * | N/A | p_xfer_len | Pointer to a variable that will receive transfer length. If no errors are returned, the variable is set to number of octets received, otherwise it is set to 0. |
Returns
Returns SL_STATUS_OK on success or another SL_STATUS code on failure.
sl_usbd_cdc_read_data_async#
sl_status_t sl_usbd_cdc_read_data_async (uint8_t class_nbr, uint8_t data_if_nbr, uint8_t * p_buf, uint32_t buf_len, sl_usbd_cdc_async_function_t async_fnct, void * p_async_arg)
Receive data on the CDC data interface asynchronously.
Type | Direction | Argument Name | Description |
---|---|---|---|
uint8_t | N/A | class_nbr | Class instance number. |
uint8_t | N/A | data_if_nbr | CDC data interface number. |
uint8_t * | N/A | p_buf | Pointer to the destination buffer to receive data. |
uint32_t | N/A | buf_len | Number of octets to receive. |
sl_usbd_cdc_async_function_t | N/A | async_fnct | Function that will be invoked upon completion of receive operation. |
void * | N/A | p_async_arg | Pointer to the argument that will be passed as parameter of 'async_fnct'. |
Returns
Returns SL_STATUS_OK on success or another SL_STATUS code on failure.
sl_usbd_cdc_write_data#
sl_status_t sl_usbd_cdc_write_data (uint8_t class_nbr, uint8_t data_if_nbr, uint8_t * p_buf, uint32_t buf_len, uint16_t timeout, uint32_t * p_xfer_len)
Send data on the CDC data interface.
Type | Direction | Argument Name | Description |
---|---|---|---|
uint8_t | N/A | class_nbr | Class instance number. |
uint8_t | N/A | data_if_nbr | CDC data interface number. |
uint8_t * | N/A | p_buf | Pointer to the buffer of data that will be transmitted. |
uint32_t | N/A | buf_len | Number of octets to transmit. |
uint16_t | N/A | timeout | Timeout in milliseconds. |
uint32_t * | N/A | p_xfer_len | Pointer to a variable that will receive transfer length. If no errors are returned, the variable is set to number of octets transmitted, otherwise it is set to 0. |
Returns
Returns SL_STATUS_OK on success or another SL_STATUS code on failure.
sl_usbd_cdc_write_data_async#
sl_status_t sl_usbd_cdc_write_data_async (uint8_t class_nbr, uint8_t data_if_nbr, uint8_t * p_buf, uint32_t buf_len, sl_usbd_cdc_async_function_t async_fnct, void * p_async_arg)
Send data on the CDC data interface asynchronously.
Type | Direction | Argument Name | Description |
---|---|---|---|
uint8_t | N/A | class_nbr | Class instance number. |
uint8_t | N/A | data_if_nbr | CDC data interface number. |
uint8_t * | N/A | p_buf | Pointer to the buffer of data that will be transmitted. |
uint32_t | N/A | buf_len | Number of octets to transmit. |
sl_usbd_cdc_async_function_t | N/A | async_fnct | Function that will be invoked upon completion of transfer operation. |
void * | N/A | p_async_arg | Pointer to the argument that will be passed as parameter of 'async_fnct'. |
Returns
Returns SL_STATUS_OK on success or another SL_STATUS code on failure.
sl_usbd_cdc_notify_host#
sl_status_t sl_usbd_cdc_notify_host (uint8_t class_nbr, uint8_t notification, uint16_t value, uint8_t * p_buf, uint16_t data_len, bool * p_result)
Send a communication interface class notification to the host.
Type | Direction | Argument Name | Description |
---|---|---|---|
uint8_t | N/A | class_nbr | Class instance number. |
uint8_t | N/A | notification | Notification code. |
uint16_t | N/A | value | Notification value. |
uint8_t * | N/A | p_buf | Pointer to the notification buffer (see Note #1). |
uint16_t | N/A | data_len | Length of the data portion of the notification. |
bool * | N/A | p_result | Pointer to a boolean variable that will receive the result of the operation. The variable is set to true if no errors are encountered, otherwise it is set to false. |
Returns
Returns SL_STATUS_OK on success or another SL_STATUS code on failure.
Note
(1) The notification buffer MUST contain space for the notification header 'SL_USBD_CDC_NOTIFICATION_HEADER' plus the variable-length data portion.