USB Device Middleware Library 2.10
Functions

General Description

Functions

cy_en_usb_dev_status_t Cy_USB_Dev_CDC_Init (cy_stc_usb_dev_cdc_config_t const *config, cy_stc_usb_dev_cdc_context_t *context, cy_stc_usb_dev_context_t *devContext)
 Initializes the CDC class. More...
 
cy_en_usb_dev_status_t Cy_USB_Dev_CDC_PutData (uint32_t port, uint8_t const *buffer, uint32_t size, cy_stc_usb_dev_cdc_context_t *context)
 Sends a specified number of bytes to USB Host. More...
 
cy_en_usb_dev_status_t Cy_USB_Dev_CDC_PutString (uint32_t port, char_t const *string, int32_t timeout, cy_stc_usb_dev_cdc_context_t *context)
 Sends a null terminated string to the USB Host. More...
 
__STATIC_INLINE cy_en_usb_dev_status_t Cy_USB_Dev_CDC_PutChar (uint32_t port, char_t ch, cy_stc_usb_dev_cdc_context_t *context)
 Sends a single character to the USB Host. More...
 
uint32_t Cy_USB_Dev_CDC_GetCount (uint32_t port, cy_stc_usb_dev_cdc_context_t *context)
 Returns the number of bytes that were received from the USB Host and can be read using Cy_USB_Dev_CDC_GetData or Cy_USB_Dev_CDC_GetChar functions. More...
 
bool Cy_USB_Dev_CDC_IsDataReady (uint32_t port, cy_stc_usb_dev_cdc_context_t *context)
 Returns status if the COM port (CDC Data interface) received data from the USB Host (including zero-length packet). More...
 
bool Cy_USB_Dev_CDC_IsReady (uint32_t port, cy_stc_usb_dev_cdc_context_t *context)
 Returns status if the COM port (CDC Data interface) is ready for sending new data. More...
 
uint32_t Cy_USB_Dev_CDC_GetData (uint32_t port, uint8_t *buffer, uint32_t size, cy_stc_usb_dev_cdc_context_t *context)
 Read a specified number of data bytes received from USB Host by the COM port (CDC Data interface). More...
 
uint32_t Cy_USB_Dev_CDC_GetAll (uint32_t port, uint8_t *buffer, uint32_t maxSize, cy_stc_usb_dev_cdc_context_t *context)
 Read all data received from USB Host by the COM port (CDC Data interface). More...
 
char_t Cy_USB_Dev_CDC_GetChar (uint32_t port, cy_stc_usb_dev_cdc_context_t *context)
 Reads one byte of received data. More...
 
__STATIC_INLINE uint32_t Cy_USB_Dev_CDC_IsLineChanged (uint32_t port, cy_stc_usb_dev_cdc_context_t *context)
 Returns the clear-on-read status of the COM port. More...
 
__STATIC_INLINE uint32_t Cy_USB_Dev_CDC_GetLineControl (uint32_t port, cy_stc_usb_dev_cdc_context_t const *context)
 Returns the line control bitmap for the COM port. More...
 
uint32_t Cy_USB_Dev_CDC_GetDTERate (uint32_t port, cy_stc_usb_dev_cdc_context_t *context)
 Returns the data terminal rate set for this port in bits per second. More...
 
__STATIC_INLINE cy_en_usb_dev_cdc_stop_bit_t Cy_USB_Dev_CDC_GetCharFormat (uint32_t port, cy_stc_usb_dev_cdc_context_t const *context)
 Returns the number of stop bits for the COM port. More...
 
__STATIC_INLINE cy_en_usb_dev_cdc_parity_type_t Cy_USB_Dev_CDC_GetParity (uint32_t port, cy_stc_usb_dev_cdc_context_t const *context)
 Returns the parity type for the COM port. More...
 
__STATIC_INLINE uint32_t Cy_USB_Dev_CDC_GetDataBits (uint32_t port, cy_stc_usb_dev_cdc_context_t const *context)
 Returns the number of data bits for the COM port. More...
 
cy_en_usb_dev_status_t Cy_USB_Dev_CDC_SendSerialState (uint32_t port, uint32_t serialState, cy_stc_usb_dev_cdc_context_t *context)
 Sends the serial state notification to the host using the COM port (CDC interface) IN interrupt endpoint. More...
 
bool Cy_USB_Dev_CDC_IsNotificationReady (uint32_t port, cy_stc_usb_dev_cdc_context_t *context)
 Returns if the COM port (CDC interface) is ready to send notification to the USB Host. More...
 
__STATIC_INLINE void Cy_USB_Dev_CDC_RegisterUserCallbacks (cy_cb_usb_dev_request_received_t requestReceivedHandle, cy_cb_usb_dev_request_cmplt_t requestCompletedHandle, cy_stc_usb_dev_cdc_context_t *context)
 Registering user callback to handle CDC class requests that are not supported by provided CDC request handler. More...
 
__STATIC_INLINE cy_stc_usb_dev_class_tCy_USB_Dev_CDC_GetClass (cy_stc_usb_dev_cdc_context_t *context)
 Returns pointer to the CDC class structure. More...
 
__STATIC_INLINE uint32_t Cy_USB_Dev_CDC_GetSerialState (uint32_t port, cy_stc_usb_dev_cdc_context_t const *context)
 Returns the current serial state value for the COM port. More...
 

Function Documentation

◆ Cy_USB_Dev_CDC_Init()

cy_en_usb_dev_status_t Cy_USB_Dev_CDC_Init ( cy_stc_usb_dev_cdc_config_t const *  config,
cy_stc_usb_dev_cdc_context_t context,
cy_stc_usb_dev_context_t devContext 
)

Initializes the CDC class.

This function must be called to enable USB Device CDC functionality.

Parameters
configThe pointer to the CDC configuration structure cy_stc_usb_dev_cdc_config_t.
contextThe pointer to the context structure cy_stc_usb_dev_cdc_context_t allocated by the user. The structure is used during the CDC Class operation for internal configuration and data retention. The user must not modify anything in this structure.
devContextThe pointer to the USB Device context structure cy_stc_usb_dev_context_t.
Returns
Status code of the function execution cy_en_usb_dev_status_t.

◆ Cy_USB_Dev_CDC_PutData()

cy_en_usb_dev_status_t Cy_USB_Dev_CDC_PutData ( uint32_t  port,
uint8_t const *  buffer,
uint32_t  size,
cy_stc_usb_dev_cdc_context_t context 
)

Sends a specified number of bytes to USB Host.

Call Cy_USB_Dev_CDC_IsReady function to ensure that the COM port (CDC Data interface) is ready for sending data to the USB Host before calling this function.

Parameters
portCOM port number. Valid ports are 0 and 1.
bufferThe pointer to the buffer containing data bytes to be sent.
Allocate buffer using CY_USB_DEV_ALLOC_ENDPOINT_BUFFER macro to make it USBFS driver configuration independent (See Allocate Data Endpoint Buffer for more information).
sizeThe number of bytes to send. This value must be less than or equal to the maximum packet size of the CDC Data interface IN endpoint that belongs to the specified COM port.
contextThe pointer to the context structure cy_stc_usb_dev_cdc_context_t allocated by the user. The structure is used during the CDC Class operation for internal configuration and data retention. The user must not modify anything in this structure.
Returns
Status code of the function execution cy_en_usb_dev_status_t.

◆ Cy_USB_Dev_CDC_PutString()

cy_en_usb_dev_status_t Cy_USB_Dev_CDC_PutString ( uint32_t  port,
char_t const *  string,
int32_t  timeout,
cy_stc_usb_dev_cdc_context_t context 
)

Sends a null terminated string to the USB Host.

This function is blocking and returns after successful USB Host transfer, or an error or timeout occurred. Call Cy_USB_Dev_CDC_IsReady function to ensure that the COM port (CDC Data interface) is ready for sending data to the USB Host before calling this function.

Parameters
portCOM port number. Valid ports are 0 and 1.
stringThe pointer to the string to be sent.
The string must be allocated following rules in the section Allocate Data Endpoint Buffer to be USBFS driver configuration independent.
timeoutDefines in milliseconds the time for which this function can block. If that time expires, the function returns. To wait forever, pass CY_USB_DEV_WAIT_FOREVER.
contextThe pointer to the context structure cy_stc_usb_dev_cdc_context_t allocated by the user. The structure is used during the CDC Class operation for internal configuration and data retention. The user must not modify anything in this structure.
Returns
Status code of the function execution cy_en_usb_dev_status_t.
Note
If string parameter is a constant string (example: "USBUART"), it is stored in the stack and aligned to 4 bytes boundary what makes it USBFS driver configuration independent.

◆ Cy_USB_Dev_CDC_PutChar()

__STATIC_INLINE cy_en_usb_dev_status_t Cy_USB_Dev_CDC_PutChar ( uint32_t  port,
char_t  ch,
cy_stc_usb_dev_cdc_context_t context 
)

Sends a single character to the USB Host.

Call Cy_USB_Dev_CDC_IsReady function to ensure that the COM port (CDC Data interface) is ready for sending data to the USB Host before calling this function.

Parameters
portCOM port number. Valid ports are 0 and 1.
chCharacter to be sent.
contextThe pointer to the context structure cy_stc_usb_dev_cdc_context_t allocated by the user. The structure is used during the CDC Class operation for internal configuration and data retention. The user must not modify anything in this structure.
Returns
Status code of the function execution cy_en_usb_dev_status_t.

◆ Cy_USB_Dev_CDC_GetCount()

uint32_t Cy_USB_Dev_CDC_GetCount ( uint32_t  port,
cy_stc_usb_dev_cdc_context_t context 
)

Returns the number of bytes that were received from the USB Host and can be read using Cy_USB_Dev_CDC_GetData or Cy_USB_Dev_CDC_GetChar functions.

Parameters
portCOM port number. Valid ports are 0 and 1.
contextThe pointer to the context structure cy_stc_usb_dev_cdc_context_t allocated by the user. The structure is used during the CDC Class operation for internal configuration and data retention. The user must not modify anything in this structure.
Returns
Returns the number of bytes that were received.

◆ Cy_USB_Dev_CDC_IsDataReady()

bool Cy_USB_Dev_CDC_IsDataReady ( uint32_t  port,
cy_stc_usb_dev_cdc_context_t context 
)

Returns status if the COM port (CDC Data interface) received data from the USB Host (including zero-length packet).

Parameters
portCOM port number. Valid ports are 0 and 1.
contextThe pointer to the context structure cy_stc_usb_dev_cdc_context_t allocated by the user. The structure is used during the CDC Class operation for internal configuration and data retention. The user must not modify anything in this structure.
Returns
  • True - the COM port (CDC Data interface) received data from the USB Host.
  • False - the COM port (CDC Data interface) is waiting for data from the USB Host.

◆ Cy_USB_Dev_CDC_IsReady()

bool Cy_USB_Dev_CDC_IsReady ( uint32_t  port,
cy_stc_usb_dev_cdc_context_t context 
)

Returns status if the COM port (CDC Data interface) is ready for sending new data.

Parameters
portCOM port number. Valid ports are 0 and 1.
contextThe pointer to the context structure cy_stc_usb_dev_cdc_context_t allocated by the user. The structure is used during the CDC Class operation for internal configuration and data retention. The user must not modify anything in this structure.
Returns
  • True - the COM port (CDC Data interface) is ready for sending new data.
  • False - the COM port (CDC Data interface) is waiting for the USB Host to read previous data.

◆ Cy_USB_Dev_CDC_GetData()

uint32_t Cy_USB_Dev_CDC_GetData ( uint32_t  port,
uint8_t *  buffer,
uint32_t  size,
cy_stc_usb_dev_cdc_context_t context 
)

Read a specified number of data bytes received from USB Host by the COM port (CDC Data interface).

Call Cy_USB_Dev_CDC_IsDataReady function to ensure that data is received from the USB Host before calling this function.

Parameters
portCOM port number. Valid ports are 0 and 1.
bufferThe pointer to buffer that stores data that was read.
Allocate buffer using CY_USB_DEV_ALLOC_ENDPOINT_BUFFER macro to make it USBFS driver configuration independent (See Allocate Data Endpoint Buffer for more information).
sizeThe number of bytes to read.
contextThe pointer to the context structure cy_stc_usb_dev_cdc_context_t allocated by the user. The structure is used during the CDC Class operation for internal configuration and data keeping. The user must not modify anything in this structure.
Returns
The number of bytes that were actually read.

◆ Cy_USB_Dev_CDC_GetAll()

uint32_t Cy_USB_Dev_CDC_GetAll ( uint32_t  port,
uint8_t *  buffer,
uint32_t  maxSize,
cy_stc_usb_dev_cdc_context_t context 
)

Read all data received from USB Host by the COM port (CDC Data interface).

Call Cy_USB_Dev_CDC_IsDataReady function to ensure that data is received from the USB Host before calling this function.

Parameters
portCOM port number. Valid ports are 0 and 1.
bufferThe pointer to buffer that stores data that was read.
Allocate buffer using CY_USB_DEV_ALLOC_ENDPOINT_BUFFER macro to make it USBFS driver configuration independent (See Allocate Data Endpoint Buffer for more information).
maxSizeThe size of buffer to read data into. This value must be not be less then CDC Data interface OUT endpoint maximum packet size that belongs to specified COM port.
contextThe pointer to the context structure cy_stc_usb_dev_cdc_context_t allocated by the user. The structure is used during the CDC Class operation for internal configuration and data retention. The user must not modify anything in this structure.
Returns
The number of bytes that were actually read.

◆ Cy_USB_Dev_CDC_GetChar()

char_t Cy_USB_Dev_CDC_GetChar ( uint32_t  port,
cy_stc_usb_dev_cdc_context_t context 
)

Reads one byte of received data.

Call Cy_USB_Dev_CDC_IsDataReady function to ensure that data is received from the USB Host before calling this function.

Parameters
portCOM port number. Valid ports are 0 and 1.
contextThe pointer to the context structure cy_stc_usb_dev_cdc_context_t allocated by the user. The structure is used during the CDC Class operation for internal configuration and data retention. The user must not modify anything in this structure.
Returns
Received one character or zero value to indicate there is no data.

◆ Cy_USB_Dev_CDC_IsLineChanged()

__STATIC_INLINE uint32_t Cy_USB_Dev_CDC_IsLineChanged ( uint32_t  port,
cy_stc_usb_dev_cdc_context_t context 
)

Returns the clear-on-read status of the COM port.

Parameters
portCOM port number. Valid ports are 0 and 1.
contextThe pointer to the context structure cy_stc_usb_dev_cdc_context_t allocated by the user. The structure is used during the CDC Class operation for internal configuration and data retention. The user must not modify anything in this structure.
Returns
Note
This function is not interrupt-protected and to prevent a race condition, it should be protected from the USBFS interruption in the place where it is called.

◆ Cy_USB_Dev_CDC_GetLineControl()

__STATIC_INLINE uint32_t Cy_USB_Dev_CDC_GetLineControl ( uint32_t  port,
cy_stc_usb_dev_cdc_context_t const *  context 
)

Returns the line control bitmap for the COM port.

Parameters
portCOM port number. Valid ports are 0 and 1.
contextThe pointer to the context structure cy_stc_usb_dev_cdc_context_t allocated by the user. The structure is used during the CDC Class operation for internal configuration and data retention. The user must not modify anything in this structure.
Returns
Line control bitmap CY_USB_DEV_CDC_LINE_CONTROL_DTR and CY_USB_DEV_CDC_LINE_CONTROL_RTS.

◆ Cy_USB_Dev_CDC_GetDTERate()

uint32_t Cy_USB_Dev_CDC_GetDTERate ( uint32_t  port,
cy_stc_usb_dev_cdc_context_t context 
)

Returns the data terminal rate set for this port in bits per second.

Parameters
portCOM port number. Valid ports are 0 and 1.
contextThe pointer to the context structure cy_stc_usb_dev_cdc_context_t allocated by the user. The structure is used during the CDC Class operation for internal configuration and data retention. The user must not modify anything in this structure.
Returns
Data rate in bits per second.

◆ Cy_USB_Dev_CDC_GetCharFormat()

__STATIC_INLINE cy_en_usb_dev_cdc_stop_bit_t Cy_USB_Dev_CDC_GetCharFormat ( uint32_t  port,
cy_stc_usb_dev_cdc_context_t const *  context 
)

Returns the number of stop bits for the COM port.

Parameters
portCOM port number. Valid ports are 0 and 1.
contextThe pointer to the context structure cy_stc_usb_dev_cdc_context_t allocated by the user. The structure is used during the CDC Class operation for internal configuration and data retention. The user must not modify anything in this structure.
Returns
Number of stop bits cy_en_usb_dev_cdc_stop_bit_t.

◆ Cy_USB_Dev_CDC_GetParity()

__STATIC_INLINE cy_en_usb_dev_cdc_parity_type_t Cy_USB_Dev_CDC_GetParity ( uint32_t  port,
cy_stc_usb_dev_cdc_context_t const *  context 
)

Returns the parity type for the COM port.

Parameters
portCOM port number. Valid ports are 0 and 1.
contextThe pointer to the context structure cy_stc_usb_dev_cdc_context_t allocated by the user. The structure is used during the CDC Class operation for internal configuration and data retention. The user must not modify anything in this structure.
Returns
Parity type cy_en_usb_dev_cdc_parity_type_t.

◆ Cy_USB_Dev_CDC_GetDataBits()

__STATIC_INLINE uint32_t Cy_USB_Dev_CDC_GetDataBits ( uint32_t  port,
cy_stc_usb_dev_cdc_context_t const *  context 
)

Returns the number of data bits for the COM port.

Parameters
portCOM port number. Valid ports are 0 and 1.
contextThe pointer to the context structure cy_stc_usb_dev_cdc_context_t allocated by the user. The structure is used during the CDC Class operation for internal configuration and data keeping. The user must not modify anything in this structure.
Returns
Number of data bits, which can be 5, 6, 7, 8, or 16.

◆ Cy_USB_Dev_CDC_SendSerialState()

cy_en_usb_dev_status_t Cy_USB_Dev_CDC_SendSerialState ( uint32_t  port,
uint32_t  serialState,
cy_stc_usb_dev_cdc_context_t context 
)

Sends the serial state notification to the host using the COM port (CDC interface) IN interrupt endpoint.

Call Cy_USB_Dev_CDC_IsNotificationReady function to ensure that COM port (CDC interface) is ready send notification before calling this function.

Parameters
portCOM port number. Valid ports are 0 and 1.
serialState16-bit value that will be sent from the USB Device to the USB Host as SERIAL_STATE notification using the CDC interface IN interrupt endpoint. Refer to revision 1.2 of the CDC PSTN Subclass specification for bit field definitions of the 16-bit serial state value.
contextThe pointer to the context structure cy_stc_usb_dev_cdc_context_t allocated by the user. The structure is used during the CDC Class operation for internal configuration and data retention. The user must not modify anything in this structure.
Returns
Status code of the function execution cy_en_usb_dev_status_t.
Note
The maximum packet size of the CDC interface IN interrupt endpoint (that belongs to specified COM port) must be at least 10 bytes to send serial state notifications.

◆ Cy_USB_Dev_CDC_IsNotificationReady()

bool Cy_USB_Dev_CDC_IsNotificationReady ( uint32_t  port,
cy_stc_usb_dev_cdc_context_t context 
)

Returns if the COM port (CDC interface) is ready to send notification to the USB Host.

Parameters
portCOM port number. Valid ports are 0 and 1.
contextThe pointer to the context structure cy_stc_usb_dev_cdc_context_t allocated by the user. The structure is used during the CDC Class operation for internal configuration and data retention. The user must not modify anything in this structure.
Returns
  • True - the COM port (CDC interface) is ready for sending new notification.
  • False - the COM port (CDC interface) is waiting for the USB Host to read previous notification.

◆ Cy_USB_Dev_CDC_RegisterUserCallbacks()

__STATIC_INLINE void Cy_USB_Dev_CDC_RegisterUserCallbacks ( cy_cb_usb_dev_request_received_t  requestReceivedHandle,
cy_cb_usb_dev_request_cmplt_t  requestCompletedHandle,
cy_stc_usb_dev_cdc_context_t context 
)

Registering user callback to handle CDC class requests that are not supported by provided CDC request handler.

Parameters
requestReceivedHandleThe pointer to a callback function. This function is called when setup packet was received from USB Host but was not recognized, therefore might require the user class processing. To remove callback function pass NULL as function pointer.
requestCompletedHandleThe pointer to a callback function. This function is called when USB Device received data from the USB Host as part of current request processing. The requestReceivedHandle function must enable notification to trigger this event. This makes sense only when CDC request processing requires a data stage. To remove callback function pass NULL as function pointer.
contextThe pointer to the context structure cy_stc_usb_dev_context_t allocated by the user. The structure is used during the Audio Class operation for internal configuration and data retention. The user must not modify anything in this structure.

◆ Cy_USB_Dev_CDC_GetClass()

__STATIC_INLINE cy_stc_usb_dev_class_t * Cy_USB_Dev_CDC_GetClass ( cy_stc_usb_dev_cdc_context_t context)

Returns pointer to the CDC class structure.

This function is useful to override class event handlers using Class Support Functions.

Parameters
contextThe pointer to the context structure cy_stc_usb_dev_cdc_context_t allocated by the user. The structure is used during the CDC Class operation for internal configuration and data retention. The user must not modify anything in this structure.
Returns
The pointer to the CDC class structure.

◆ Cy_USB_Dev_CDC_GetSerialState()

__STATIC_INLINE uint32_t Cy_USB_Dev_CDC_GetSerialState ( uint32_t  port,
cy_stc_usb_dev_cdc_context_t const *  context 
)

Returns the current serial state value for the COM port.

Parameters
portCOM port number. Valid ports are 0 and 1.
contextThe pointer to the context structure cy_stc_usb_dev_cdc_context_t allocated by the user. The structure is used during the CDC Class operation for internal configuration and data retention. The user must not modify anything in this structure.
Returns
16-bit serial state value. Refer to revision 1.2 of the CDC PSTN Subclass specification for bit field definitions of the 16-bit serial state value. Zero in case COM port is invalid.