Functions

group group_usb_dev_cdc_functions

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.

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

Return

Status code of the function execution cy_en_usb_dev_status_t.

Parameters
  • config: The pointer to the CDC configuration structure cy_stc_usb_dev_cdc_config_t.

  • context: The 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.

  • devContext: The pointer to the USB Device context structure cy_stc_usb_dev_context_t.

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.

Return

Status code of the function execution cy_en_usb_dev_status_t.

Parameters
  • port: COM port number. Valid ports are 0 and 1.

  • buffer: The 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).

  • size: The 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.

  • context: The 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.

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.

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.

Return

Status code of the function execution cy_en_usb_dev_status_t.

Parameters
  • port: COM port number. Valid ports are 0 and 1.

  • string: The 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.

  • timeout: Defines 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.

  • context: The 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.

__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.

Return

Status code of the function execution cy_en_usb_dev_status_t.

Parameters
  • port: COM port number. Valid ports are 0 and 1.

  • ch: Character to be sent.

  • context: The 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.

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.

Return

Returns the number of bytes that were received.

Parameters
  • port: COM port number. Valid ports are 0 and 1.

  • context: The 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.

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).

Return

  • 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.

Parameters
  • port: COM port number. Valid ports are 0 and 1.

  • context: The 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.

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.

Return

  • 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.

Parameters
  • port: COM port number. Valid ports are 0 and 1.

  • context: The 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.

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.

Return

The number of bytes that were actually read.

Parameters
  • port: COM port number. Valid ports are 0 and 1.

  • buffer: The 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).

  • size: The number of bytes to read.

  • context: The 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.

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.

Return

The number of bytes that were actually read.

Parameters
  • port: COM port number. Valid ports are 0 and 1.

  • buffer: The 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).

  • maxSize: The 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.

  • context: The 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.

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.

Return

Received one character or zero value to indicate there is no data.

Parameters
  • port: COM port number. Valid ports are 0 and 1.

  • context: The 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.

__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.

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.

Return

Parameters
  • port: COM port number. Valid ports are 0 and 1.

  • context: The 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.

__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.

Return

Line control bitmap CY_USB_DEV_CDC_LINE_CONTROL_DTR and CY_USB_DEV_CDC_LINE_CONTROL_RTS.

Parameters
  • port: COM port number. Valid ports are 0 and 1.

  • context: The 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.

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.

Return

Data rate in bits per second.

Parameters
  • port: COM port number. Valid ports are 0 and 1.

  • context: The 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.

__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.

Return

Number of stop bits cy_en_usb_dev_cdc_stop_bit_t.

Parameters
  • port: COM port number. Valid ports are 0 and 1.

  • context: The 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.

__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.

Return

Parity type cy_en_usb_dev_cdc_parity_type_t.

Parameters
  • port: COM port number. Valid ports are 0 and 1.

  • context: The 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.

__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.

Return

Number of data bits, which can be 5, 6, 7, 8, or 16.

Parameters
  • port: COM port number. Valid ports are 0 and 1.

  • context: The 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.

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.

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.

Return

Status code of the function execution cy_en_usb_dev_status_t.

Parameters
  • port: COM port number. Valid ports are 0 and 1.

  • serialState: 16-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.

  • context: The 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.

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.

Return

  • 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.

Parameters
  • port: COM port number. Valid ports are 0 and 1.

  • context: The 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.

__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
  • requestReceivedHandle: The 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.

  • requestCompletedHandle: The 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.

  • context: The 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.

__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.

Return

The pointer to the CDC class structure.

Parameters
  • context: The 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.

__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.

Return

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.

Parameters
  • port: COM port number. Valid ports are 0 and 1.

  • context: The 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.