Hardware Abstraction Layer (HAL)

General Description

APIs relating to endpoint management.

Macros

#define CYHAL_USB_DEV_IS_IN_EP(endpoint)   (0U != (0x80U & (uint32_t) (endpoint)))
 Returns true if endpoint direction is IN.
 
#define CYHAL_USB_DEV_GET_EP_NUM(endpoint)   ((uint32_t) (endpoint) & 0x0FU)
 Returns endpoint number (type uint32_t)
 
#define CYHAL_USB_DEV_GET_EP_IDX(endpoint)   (CYHAL_USB_DEV_GET_EP_NUM(endpoint) - 1U)
 Returns endpoint index (type uint32_t)
 

Enumerations

enum  cyhal_usb_dev_ep_type_t {
  CYHAL_USB_DEV_EP_TYPE_CTRL = 0,
  CYHAL_USB_DEV_EP_TYPE_ISO = 1,
  CYHAL_USB_DEV_EP_TYPE_BULK = 2,
  CYHAL_USB_DEV_EP_TYPE_INT = 3
}
 USB Device Endpoints types.
 

Functions

cy_rslt_t cyhal_usb_dev_endpoint_add (cyhal_usb_dev_t *obj, bool alloc, bool enable, cyhal_usb_dev_ep_t endpoint, uint32_t max_packet, cyhal_usb_dev_ep_type_t type)
 Configure an endpoint. More...
 
cy_rslt_t cyhal_usb_dev_endpoint_remove (cyhal_usb_dev_t *obj, cyhal_usb_dev_ep_t endpoint)
 Disable an endpoint. More...
 
cy_rslt_t cyhal_usb_dev_endpoint_stall (cyhal_usb_dev_t *obj, cyhal_usb_dev_ep_t endpoint)
 Perform a functional stall on the given endpoint. More...
 
cy_rslt_t cyhal_usb_dev_endpoint_unstall (cyhal_usb_dev_t *obj, cyhal_usb_dev_ep_t endpoint)
 Unstall the endpoint. More...
 
bool cyhal_usb_dev_endpoint_is_stalled (cyhal_usb_dev_t *obj, cyhal_usb_dev_ep_t endpoint)
 Return the endpoint stall state. More...
 
cy_rslt_t cyhal_usb_dev_endpoint_read (cyhal_usb_dev_t *obj, cyhal_usb_dev_ep_t endpoint, uint8_t *data, uint32_t size)
 Start a read on the given endpoint. More...
 
cy_rslt_t cyhal_usb_dev_endpoint_read_result (cyhal_usb_dev_t *obj, cyhal_usb_dev_ep_t endpoint, uint32_t *act_size)
 Finish a read on the given endpoint. More...
 
cy_rslt_t cyhal_usb_dev_endpoint_write (cyhal_usb_dev_t *obj, cyhal_usb_dev_ep_t endpoint, uint8_t const *data, uint32_t size)
 Start a write on the given endpoint. More...
 
cy_rslt_t cyhal_usb_dev_endpoint_abort (cyhal_usb_dev_t *obj, cyhal_usb_dev_ep_t endpoint)
 Abort the current transfer if it has not yet been sent. More...
 
void cyhal_usb_dev_register_endpoint_callback (cyhal_usb_dev_t *obj, cyhal_usb_dev_ep_t endpoint, cyhal_usb_dev_endpoint_callback_t callback)
 The USB Device endpoint complete callback handler registration. More...
 

Function Documentation

◆ cyhal_usb_dev_endpoint_add()

cy_rslt_t cyhal_usb_dev_endpoint_add ( cyhal_usb_dev_t obj,
bool  alloc,
bool  enable,
cyhal_usb_dev_ep_t  endpoint,
uint32_t  max_packet,
cyhal_usb_dev_ep_type_t  type 
)

Configure an endpoint.

Parameters
[in,out]objThe USB device object
[in]allocTrue to allocates buffer for the endpoint, false to skip allocation
[in]enableTrue to enable endpoint operation, false to skip enablement
[in]endpointEndpoint to configure and enable
[in]max_packetThe maximum packet size that can be sent or received
[in]typeThe type of endpoint (does not care when enable parameter is false)
Returns
The status of the endpoint add request
Note
  • This function cannot be used to configure endpoint 0. That must be done with cyhal_usb_dev_ep0_get_max_packet.
  • After endpoint was enabled it must be removed with cyhal_usb_dev_endpoint_remove and then enabled again.

◆ cyhal_usb_dev_endpoint_remove()

cy_rslt_t cyhal_usb_dev_endpoint_remove ( cyhal_usb_dev_t obj,
cyhal_usb_dev_ep_t  endpoint 
)

Disable an endpoint.

Parameters
[in,out]objThe USB device object
[in]endpointEndpoint to disable
Returns
The status of the endpoint remove request

◆ cyhal_usb_dev_endpoint_stall()

cy_rslt_t cyhal_usb_dev_endpoint_stall ( cyhal_usb_dev_t obj,
cyhal_usb_dev_ep_t  endpoint 
)

Perform a functional stall on the given endpoint.

Set the HALT feature for this endpoint so that all further communication is aborted.

Parameters
[in,out]objThe USB device object
[in]endpointEndpoint to stall
Returns
The status of the endpoint stall request

◆ cyhal_usb_dev_endpoint_unstall()

cy_rslt_t cyhal_usb_dev_endpoint_unstall ( cyhal_usb_dev_t obj,
cyhal_usb_dev_ep_t  endpoint 
)

Unstall the endpoint.

Clear the HALT feature on this endpoint so communication can resume.

Parameters
[in,out]objThe USB device object
[in]endpointEndpoint to stall
Returns
The status of the endpoint unstall request

◆ cyhal_usb_dev_endpoint_is_stalled()

bool cyhal_usb_dev_endpoint_is_stalled ( cyhal_usb_dev_t obj,
cyhal_usb_dev_ep_t  endpoint 
)

Return the endpoint stall state.

Parameters
[in,out]objThe USB device object
[in]endpointEndpoint to check stall state
Returns
True if endpoint stalled, false otherwise.

◆ cyhal_usb_dev_endpoint_read()

cy_rslt_t cyhal_usb_dev_endpoint_read ( cyhal_usb_dev_t obj,
cyhal_usb_dev_ep_t  endpoint,
uint8_t *  data,
uint32_t  size 
)

Start a read on the given endpoint.

Parameters
[in,out]objThe USB device object
[in]endpointEndpoint to start the read on
[in]dataBuffer to fill with data
[in]sizeSize of the read buffer. This must be at least the max packet size for this endpoint.
Returns
The status of start a read operation

◆ cyhal_usb_dev_endpoint_read_result()

cy_rslt_t cyhal_usb_dev_endpoint_read_result ( cyhal_usb_dev_t obj,
cyhal_usb_dev_ep_t  endpoint,
uint32_t *  act_size 
)

Finish a read on the given endpoint.

Parameters
[in,out]objThe USB device object
[in]endpointEndpoint to check
[out]act_sizeActual number of bytes that was read
Returns
The status of a finish read

◆ cyhal_usb_dev_endpoint_write()

cy_rslt_t cyhal_usb_dev_endpoint_write ( cyhal_usb_dev_t obj,
cyhal_usb_dev_ep_t  endpoint,
uint8_t const *  data,
uint32_t  size 
)

Start a write on the given endpoint.

Parameters
[in,out]objThe USB device object
[in]endpointEndpoint to write to
[in]dataBuffer to write
[in]sizeSize of data to write
Returns
The status of a write request

◆ cyhal_usb_dev_endpoint_abort()

cy_rslt_t cyhal_usb_dev_endpoint_abort ( cyhal_usb_dev_t obj,
cyhal_usb_dev_ep_t  endpoint 
)

Abort the current transfer if it has not yet been sent.

Parameters
[in,out]objThe USB device object
[in]endpointEndpoint to abort the transfer on. It is implementation defined if this function has an effect on receive endpoints.
Returns
The status of an abort request
Note
For the ISOC endpoints in pending state this function does not wait for bus activity completion because these endpoints do not have handshake and are always accessible to the Host. Therefore it is safe to call this function for ISOC endpoint when the Host will not access them during abort.

◆ cyhal_usb_dev_register_endpoint_callback()

void cyhal_usb_dev_register_endpoint_callback ( cyhal_usb_dev_t obj,
cyhal_usb_dev_ep_t  endpoint,
cyhal_usb_dev_endpoint_callback_t  callback 
)

The USB Device endpoint complete callback handler registration.

Parameters
[in,out]objThe USB device object
[in]endpointEndpoint to registers handler
[in]callbackThe callback handler which will be invoked when the endpoint comp