Cypress USB Device Middleware Library 2.0
Data Transfer Functions

General Description

Functions

cy_en_usb_dev_status_t Cy_USB_Dev_StartReadEp (uint32_t endpoint, cy_stc_usb_dev_context_t *context)
 Start a reading on a certain endpoint. More...
 
cy_en_usb_dev_status_t Cy_USB_Dev_ReadEpBlocking (uint32_t endpoint, uint8_t *buffer, uint32_t size, uint32_t *actSize, int32_t timeout, cy_stc_usb_dev_context_t *context)
 Read data received from USB Host from a certain endpoint. More...
 
cy_en_usb_dev_status_t Cy_USB_Dev_ReadEpNonBlocking (uint32_t endpoint, uint8_t *buffer, uint32_t size, uint32_t *actSize, cy_stc_usb_dev_context_t *context)
 Read data received from USB Host from a certain endpoint. More...
 
cy_en_usb_dev_status_t Cy_USB_Dev_AbortEpTransfer (uint32_t endpoint, cy_stc_usb_dev_context_t *context)
 Aborts pending read or write endpoint operation. More...
 
__STATIC_INLINE uint32_t Cy_USB_Dev_GetEpNumToRead (uint32_t endpoint, cy_stc_usb_dev_context_t const *context)
 Returns the number of bytes that available to be read from a certain endpoint buffer. More...
 
cy_en_usb_dev_status_t Cy_USB_Dev_WriteEpBlocking (uint32_t endpoint, uint8_t const *buffer, uint32_t size, int32_t timeout, cy_stc_usb_dev_context_t *context)
 Write data to be transferred to USB Host from a certain endpoint. More...
 
cy_en_usb_dev_status_t Cy_USB_Dev_WriteEpNonBlocking (uint32_t endpoint, uint8_t const *buffer, uint32_t size, cy_stc_usb_dev_context_t *context)
 Write data to be transferred to USB Host from a certain endpoint. More...
 
__STATIC_INLINE void Cy_USB_Dev_OverwriteHandleTimeout (cy_fn_usb_dev_handle_timeout_ptr_t handleTimeout, cy_stc_usb_dev_context_t *context)
 Overwrite the handle timeout function that is implemented internally. More...
 

Function Documentation

◆ Cy_USB_Dev_StartReadEp()

cy_en_usb_dev_status_t Cy_USB_Dev_StartReadEp ( uint32_t  endpoint,
cy_stc_usb_dev_context_t context 
)

Start a reading on a certain endpoint.

Parameters
endpointThe OUT data endpoint number.
contextThe pointer to the context structure cy_stc_usb_dev_context_t allocated by the user. The structure is used during the USB Device 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 read is not allowed for OUT endpoints after SET_CONFIGURATION or SET_INTERFACE request therefore this function must be called before reading data from OUT endpoints.

◆ Cy_USB_Dev_ReadEpBlocking()

cy_en_usb_dev_status_t Cy_USB_Dev_ReadEpBlocking ( uint32_t  endpoint,
uint8_t *  buffer,
uint32_t  size,
uint32_t *  actSize,
int32_t  timeout,
cy_stc_usb_dev_context_t context 
)

Read data received from USB Host from a certain endpoint.

Before calling this function, Cy_USB_Dev_StartReadEp must be called. This function is blocking and returns after successful USB Host transfer, or an error or timeout occurred.

Parameters
endpointThe OUT data endpoint number.
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. This value must be less or equal to endpoint maximum packet size.
actSizeThe number of bytes that were actually read.
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_context_t allocated by the user. The structure is used during the USB Device 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_ReadEpNonBlocking()

cy_en_usb_dev_status_t Cy_USB_Dev_ReadEpNonBlocking ( uint32_t  endpoint,
uint8_t *  buffer,
uint32_t  size,
uint32_t *  actSize,
cy_stc_usb_dev_context_t context 
)

Read data received from USB Host from a certain endpoint.

Before calling this function, Cy_USB_Dev_StartReadEp must be called.

Parameters
endpointThe OUT data endpoint number.
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. This value must be less than or equal to endpoint maximum packet size.
actSizeThe number of bytes that were actually read.
contextThe pointer to the context structure cy_stc_usb_dev_context_t allocated by the user. The structure is used during the USB Device 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_AbortEpTransfer()

cy_en_usb_dev_status_t Cy_USB_Dev_AbortEpTransfer ( uint32_t  endpoint,
cy_stc_usb_dev_context_t context 
)

Aborts pending read or write endpoint operation.

If there is any bus activity after abort operation requested the function waits for its completion or timeout. The timeout is time to transfer bulk or interrupt packet of maximum playload size. If this bus activity is a transfer to the aborting endpoint the received data is lost and endpoint transfer completion callbacks is not invoked. After function returns new read or write endpoint operation can be submitted.

Parameters
endpointThe data endpoint number.
contextThe pointer to the context structure cy_stc_usb_dev_context_t allocated by the user. The structure is used during the USB Device 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 abort operation is not supported for ISOC endpoints because these endpoints do not have handshake and are always accessible by the USB Host. Therefore, abort can cause unexpected behavior.

◆ Cy_USB_Dev_GetEpNumToRead()

__STATIC_INLINE uint32_t Cy_USB_Dev_GetEpNumToRead ( uint32_t  endpoint,
cy_stc_usb_dev_context_t const *  context 
)

Returns the number of bytes that available to be read from a certain endpoint buffer.

Before calling this function ensure that the Host wrote data into the endpoint. The returned value is updated after the Host access to the endpoint but remains unchanged after data has been read from the endpoint buffer.

Parameters
endpointThe OUT data endpoint number.
contextThe pointer to the context structure cy_stc_usb_dev_context_t allocated by the user. The structure is used during the USB Device operation for internal configuration and data retention. The user must not modify anything in this structure.
Returns
Number of bytes in OUT endpoint buffer.

◆ Cy_USB_Dev_WriteEpBlocking()

cy_en_usb_dev_status_t Cy_USB_Dev_WriteEpBlocking ( uint32_t  endpoint,
uint8_t const *  buffer,
uint32_t  size,
int32_t  timeout,
cy_stc_usb_dev_context_t context 
)

Write data to be transferred to USB Host from a certain endpoint.

This function is blocking and returns after successful USB Host transfer, or an error or timeout occurred.

Parameters
endpointThe IN data endpoint number.
bufferThe pointer to the buffer containing data bytes to write.
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 write. This value must be less than or equal to endpoint maximum packet size.
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_context_t allocated by the user. The structure is used during the USB Device 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_WriteEpNonBlocking()

cy_en_usb_dev_status_t Cy_USB_Dev_WriteEpNonBlocking ( uint32_t  endpoint,
uint8_t const *  buffer,
uint32_t  size,
cy_stc_usb_dev_context_t context 
)

Write data to be transferred to USB Host from a certain endpoint.

Parameters
endpointThe IN data endpoint number.
bufferThe pointer to the buffer containing data bytes to write.
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 write. This value must be less than or equal to endpoint maximum packet size.
contextThe pointer to the context structure cy_stc_usb_dev_context_t allocated by the user. The structure is used during the USB Device 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_OverwriteHandleTimeout()

__STATIC_INLINE void Cy_USB_Dev_OverwriteHandleTimeout ( cy_fn_usb_dev_handle_timeout_ptr_t  handleTimeout,
cy_stc_usb_dev_context_t context 
)

Overwrite the handle timeout function that is implemented internally.

The internal implementation converts one timeout unit to milliseconds.

Parameters
handleTimeoutThe pointer to function to be executed to handle timeout for blocking operations.
contextThe pointer to the context structure cy_stc_usb_dev_context_t allocated by the user. The structure is used during the USB Device operation for internal configuration and data retention. The user must not modify anything in this structure.