Common IO - basic v1.0.0
Common IO - basic v1.0.0 Library
 
Loading...
Searching...
No Matches
usb host Abstraction APIs.

Data Structures

struct  IotUsbDeviceEndpointConfig_t
 Endpoint configuration structure. More...
 
struct  IotUsbInterfaceInfo_t
 Attached device interface information. More...
 
struct  IotUsbConfigurationInfo_t
 Attached device configuration information. More...
 
struct  IotUsbDeviceInfo_t
 Attached device information. More...
 

Macros

#define IOT_USB_HOST_SUCCESS   ( 0 )
 Return values returned by this driver.
 
#define IOT_USB_HOST_ERROR   ( 1 )
 
#define IOT_USB_HOST_BUSY   ( 2 )
 
#define IOT_USB_HOST_INVALID_VALUE   ( 3 )
 
#define IOT_USB_HOST_WRITE_FAIL   ( 4 )
 
#define IOT_USB_HOST_READ_FAIL   ( 5 )
 
#define IOT_USB_HOST_CANCEL_FAILED   ( 6 )
 
#define IOT_USB_HOST_FUNCTION_NOT_SUPPORTED   ( 7 )
 
#define IOT_USB_HOST_NOTHING_TO_CANCEL   ( 8 )
 
#define IOT_USB_HOST_MAX_ENDPOINTS   ( 4 )
 

Typedefs

typedef struct IotUsbHost * IotUsbHostHandle_t
 IotUsbHostHandle_t is the handle type returned by calling iot_usb_host_open(). This is initialized in open and returned to caller. The caller must pass this pointer to the rest of APIs.
 
typedef struct IotUsbDevice * IotUsbDeviceHandle_t
 IotUsbDeviceHandle_t is the handle type returned when device attach and enumerated This device handle is needed for device operation.
 
typedef struct IotUsbConfiguration * IotUsbConfigHandle_t
 IotUsbConfigHandle_t is the configuration handle for device Only one configuration at run time.
 
typedef struct IotUsbInterface * IotUsbInterfaceHandle_t
 IotUsbInterfaceHandle_t is the interface handle, which can be extracted from config One device may have more than one interface to be used.
 
typedef struct IotUsbPipe * IotPipeHandle_t
 IotPipeHandle_t is the pipe handle, which will be used for data and control transfer.
 
typedef void(* IotUsbHostCallback_t) (IotUsbDeviceHandle_t const pxUsbDevice, IotUsbHostEvent_t xEvent, void *pvUserContext)
 USB Host attach/detach notify callback type. This callback is passed to the driver by calling iot_usb_host_set_host_callback.
 
typedef void(* IotUsbHostTransferCallback_t) (void *pvUserContext, uint8_t ucStatus)
 USB Host pipe transfer callback type. This callback is passed to the driver by calling iot_usb_host_set_pipe_callback.
 

Enumerations

enum  IotUsbHostEvent_t {
  eUSBHostAttachEvent , eUSBHostDetachEvent , eUSBHostEnumerationDoneEvent , eUSBHostResetEvent ,
  eUSBHostSuspendEvent , eUSBHostResumeEvent , eUSBHostRemoteWakeEvent
}
 common host notify event types in host callback. More...
 
enum  IotUsbHostIoctlRequest_t {
  eUSBHostGetHosthandle , eUSBHostGetDeviceControlPipe , eUSBHostGetDeviceAddress , eUSBHostOpenDeviceInterface ,
  eUSBHostCloseDeviceInterface , eUSBHostGetDeviceInfo , eUSBHostGetInterfaceInfo , eUSBHostGetInterfaceDescriptor ,
  eUSBHostGetConfigureHandle , eUSBHostGetInterfaceHandle
}
 Ioctl standard device request for USB Host HAL. More...
 

Functions

IotUsbHostHandle_t iot_usb_host_open (int32_t lUsbHostControllerInstance)
 iot_usb_host_open is used to initialize the usb host driver. This must be called before using any other usb host APIs.
 
void iot_usb_host_set_host_callback (IotUsbHostHandle_t const pxUsbHost, IotUsbHostCallback_t xCallback, void *pvUserContext)
 Set up usb host callback to be called on host event.
 
void iot_usb_host_set_pipe_callback (IotUsbHostHandle_t const pxUsbHost, IotPipeHandle_t pxPipe, IotUsbHostTransferCallback_t xCallback, void *pvUserContext)
 set up usb pipe callback to be called on pipe transfer.
 
IotPipeHandle_t iot_usb_host_pipe_open (IotUsbHostHandle_t const pxUsbHost, uint8_t ucDevAddress, IotUsbDeviceEndpointConfig_t *pxEpConfig)
 This function is used to open a pipe per given device and endpoint descriptor.
 
int32_t iot_usb_host_pipe_close (IotUsbHostHandle_t const pxUsbHost, IotPipeHandle_t pxPipe)
 This function is used to close given pipe.
 
int32_t iot_usb_host_read_async (IotUsbHostHandle_t const pxUsbHost, IotPipeHandle_t pxPipe, void *const pvBuffer, size_t xBytes)
 Starts the usb host read operation in non-blocking mode.
 
int32_t iot_usb_host_write_async (IotUsbHostHandle_t const pxUsbHost, IotPipeHandle_t pxPipe, void *const pvBuffer, size_t xBytes)
 Starts the usb host write operation in non-blocking mode.
 
int32_t iot_usb_host_read_sync (IotUsbHostHandle_t const pxUsbHost, IotPipeHandle_t pxPipe, void *const pvBuffer, size_t xBytes)
 Starts the usb host read operation in blocking mode.
 
int32_t iot_usb_host_write_sync (IotUsbHostHandle_t const pxUsbHost, IotPipeHandle_t pxPipe, void *const pvBuffer, size_t xBytes)
 Starts the usb host write operation in blocking mode.
 
int32_t iot_usb_host_cancel (IotUsbHostHandle_t const pxUsbHost, IotPipeHandle_t pxPipe)
 This function is used to cancel the current operation in progress.
 
int32_t iot_usb_host_ioctl (IotUsbDeviceHandle_t pxUsbDevice, IotUsbHostIoctlRequest_t xRequest, void *const pvBuffer)
 Used for various usb host control function.
 
int32_t iot_usb_host_send_setup (IotUsbHostHandle_t const pxUsbHost, IotPipeHandle_t pxPipe, void *pvSetup, uint8_t *pucData)
 Send setup packet to the pipe.
 
int32_t iot_usb_host_close (IotUsbHostHandle_t const pxUsbHost)
 Close the USB host peripheral.
 

Detailed Description

Macro Definition Documentation

◆ IOT_USB_HOST_SUCCESS

#define IOT_USB_HOST_SUCCESS   ( 0 )

Return values returned by this driver.

USB host operation completed successfully.

◆ IOT_USB_HOST_ERROR

#define IOT_USB_HOST_ERROR   ( 1 )

USB host error.

◆ IOT_USB_HOST_BUSY

#define IOT_USB_HOST_BUSY   ( 2 )

USB host busy.

◆ IOT_USB_HOST_INVALID_VALUE

#define IOT_USB_HOST_INVALID_VALUE   ( 3 )

At least one parameter is invalid.

◆ IOT_USB_HOST_WRITE_FAIL

#define IOT_USB_HOST_WRITE_FAIL   ( 4 )

USB host write operation failed.

◆ IOT_USB_HOST_READ_FAIL

#define IOT_USB_HOST_READ_FAIL   ( 5 )

USB host read operation failed.

◆ IOT_USB_HOST_CANCEL_FAILED

#define IOT_USB_HOST_CANCEL_FAILED   ( 6 )

USB host cancel operation failed.

◆ IOT_USB_HOST_FUNCTION_NOT_SUPPORTED

#define IOT_USB_HOST_FUNCTION_NOT_SUPPORTED   ( 7 )

USB host function not supported.

◆ IOT_USB_HOST_NOTHING_TO_CANCEL

#define IOT_USB_HOST_NOTHING_TO_CANCEL   ( 8 )

No operation in progress to cancel.

◆ IOT_USB_HOST_MAX_ENDPOINTS

#define IOT_USB_HOST_MAX_ENDPOINTS   ( 4 )

Maximum endpoint number for each interface.

Typedef Documentation

◆ IotUsbHostCallback_t

typedef void(* IotUsbHostCallback_t) (IotUsbDeviceHandle_t const pxUsbDevice, IotUsbHostEvent_t xEvent, void *pvUserContext)

USB Host attach/detach notify callback type. This callback is passed to the driver by calling iot_usb_host_set_host_callback.

Parameters
[in]pxUsbDeviceUSB device handle, returned when new device attached and enumerated.
[in]xEventUSB host event.
[in]pvUserContextUser Context passed when setting the callback. This is not used by the driver, but just passed back to the user in the callback.

◆ IotUsbHostTransferCallback_t

typedef void(* IotUsbHostTransferCallback_t) (void *pvUserContext, uint8_t ucStatus)

USB Host pipe transfer callback type. This callback is passed to the driver by calling iot_usb_host_set_pipe_callback.

Parameters
[in]ucStatusUsb host transfer status.
[in]pvUserContextUser Context passed when setting the callback. This is not used by the driver, but just passed back to the user in the callback.

Enumeration Type Documentation

◆ IotUsbHostEvent_t

common host notify event types in host callback.

Enumerator
eUSBHostAttachEvent 

USB device is connected to host.

eUSBHostDetachEvent 

USB device is detached to host.

eUSBHostEnumerationDoneEvent 

USB device enumeration is done.

eUSBHostResetEvent 

USB reset is done.

eUSBHostSuspendEvent 

USB suspend happened.

eUSBHostResumeEvent 

USB resume happened.

eUSBHostRemoteWakeEvent 

USB remote wakeup is activated.

◆ IotUsbHostIoctlRequest_t

Ioctl standard device request for USB Host HAL.

Enumerator
eUSBHostGetHosthandle 

Get usb host handle.

eUSBHostGetDeviceControlPipe 

Get usb device control pipe.

eUSBHostGetDeviceAddress 

Get usb device address.

eUSBHostOpenDeviceInterface 

Open usb device interface.

eUSBHostCloseDeviceInterface 

Close usb device interface.

eUSBHostGetDeviceInfo 

Get usb device information.

eUSBHostGetInterfaceInfo 

Get usb interface information.

eUSBHostGetInterfaceDescriptor 

Get usb device interface descriptor.

eUSBHostGetConfigureHandle 

Get usb configure handle.

eUSBHostGetInterfaceHandle 

Get usb interface handle.

Function Documentation

◆ iot_usb_host_open()

IotUsbHostHandle_t iot_usb_host_open ( int32_t  lUsbHostControllerInstance)

iot_usb_host_open is used to initialize the usb host driver. This must be called before using any other usb host APIs.

Parameters
[in]lUsbHostControllerInstanceThe instance of usb host controller to initialize.
Returns
  • The handle IotUsbHostHandle_t on success
  • NULL if
    • invalid lUsbHostControllerInstance
    • open failed
    • already opened

◆ iot_usb_host_set_host_callback()

void iot_usb_host_set_host_callback ( IotUsbHostHandle_t const  pxUsbHost,
IotUsbHostCallback_t  xCallback,
void *  pvUserContext 
)

Set up usb host callback to be called on host event.

Warning
If input handle or if callback function is NULL, this function silently takes no action.
Parameters
[in]pxUsbHostThe usb host peripheral handle returned in the iot_usb_host_open() function.
[in]xCallbackThe callback function to be called on host event.
[in]pvUserContextThe user context to be passed back when callback is called.

◆ iot_usb_host_set_pipe_callback()

void iot_usb_host_set_pipe_callback ( IotUsbHostHandle_t const  pxUsbHost,
IotPipeHandle_t  pxPipe,
IotUsbHostTransferCallback_t  xCallback,
void *  pvUserContext 
)

set up usb pipe callback to be called on pipe transfer.

Warning
If input handle or if callback function is NULL, or invalid pipe handle, this function silently takes no action.
Parameters
[in]pxUsbHostThe usb host peripheral handle returned in iot_usb_host_open() function.
[in]pxPipeThe usb pipe to be operated.
[in]xCallbackThe callback function to be called on pipe transfer.
[in]pvUserContextThe user context to be passed back when callback is called.

◆ iot_usb_host_pipe_open()

IotPipeHandle_t iot_usb_host_pipe_open ( IotUsbHostHandle_t const  pxUsbHost,
uint8_t  ucDevAddress,
IotUsbDeviceEndpointConfig_t pxEpConfig 
)

This function is used to open a pipe per given device and endpoint descriptor.

Parameters
[in]pxUsbHostThe usb host peripheral handle returned in iot_usb_host_open() function.
[in]ucDevAddressThe attached device address.
[in]pxEpConfigGiven endpoint configuration.
Returns
  • Pipe handle on success
  • NULL if
    • invalid pxUsbHost
    • invalid ucDevAddress
    • invalid pxEpConfig

◆ iot_usb_host_pipe_close()

int32_t iot_usb_host_pipe_close ( IotUsbHostHandle_t const  pxUsbHost,
IotPipeHandle_t  pxPipe 
)

This function is used to close given pipe.

Parameters
[in]pxUsbHostThe usb host peripheral handle returned in iot_usb_host_open() function.
[in]pxPipeThe pipe handle to be closed.
Returns
  • IOT_USB_HOST_SUCCESS on success
  • IOT_USB_HOST_INVALID_VALUE if
    • pxUsbHost is NULL.
    • pxPipe is NULL.

◆ iot_usb_host_read_async()

int32_t iot_usb_host_read_async ( IotUsbHostHandle_t const  pxUsbHost,
IotPipeHandle_t  pxPipe,
void *const  pvBuffer,
size_t  xBytes 
)

Starts the usb host read operation in non-blocking mode.

Note
iot_usb_host_set_pipe_callback() must be called first in order for the callback function to be called upon read is complete.
Parameters
[in]pxUsbHostThe usb host peripheral handle returned in iot_usb_host_open() function.
[in]pxPipeThe pipe handle.
[out]pvBufferThe receive buffer to read the data into.
[in]xBytesThe number of bytes to read.
Returns
  • IOT_USB_HOST_SUCCESS on success
  • IOT_USB_HOST_INVALID_VALUE if
    • pxUsbHost is NULL.
    • pxPipe is NULL.
    • pvBuffer is NULL.
    • xBytes == 0.
  • IOT_USB_HOST_BUSY if another operation is in progress on the same pipe.
  • IOT_USB_HOST_READ_FAIL if unable to complete the read operation.

◆ iot_usb_host_write_async()

int32_t iot_usb_host_write_async ( IotUsbHostHandle_t const  pxUsbHost,
IotPipeHandle_t  pxPipe,
void *const  pvBuffer,
size_t  xBytes 
)

Starts the usb host write operation in non-blocking mode.

Note
iot_usb_host_set_pipe_callback() must be called first in order for the callback function to be called upon read is complete.
Parameters
[in]pxUsbHostThe usb host peripheral handle returned in iot_usb_host_open() function.
[in]pxPipeThe pipe handle.
[out]pvBufferThe transmit buffer containing the data to be written. It must be allocated by caller and remain valid before write complete.
[in]xBytesThe number of bytes to write.
Returns
  • IOT_USB_HOST_SUCCESS on success
  • IOT_USB_HOST_INVALID_VALUE if
    • pxUsbHost is NULL.
    • pxPipe is NULL.
    • pvBuffer is NULL.
    • xBytes == 0.
  • IOT_USB_HOST_BUSY if another operation is in progress on the same pipe.
  • IOT_USB_HOST_WRITE_FAIL if unable to complete the write operation.

◆ iot_usb_host_read_sync()

int32_t iot_usb_host_read_sync ( IotUsbHostHandle_t const  pxUsbHost,
IotPipeHandle_t  pxPipe,
void *const  pvBuffer,
size_t  xBytes 
)

Starts the usb host read operation in blocking mode.

Note
This function will block until all xBytes are read.
Parameters
[in]pxUsbHostThe usb host peripheral handle returned in iot_usb_host_open() function.
[in]pxPipeThe pipe handle.
[out]pvBufferThe receive buffer to read the data into.
[in]xBytesThe number of bytes to read.
Returns
  • IOT_USB_HOST_SUCCESS on success
  • IOT_USB_HOST_INVALID_VALUE if
    • pxUsbHost is NULL.
    • pxPipe is NULL.
    • pvBuffer is NULL.
    • xBytes == 0.
  • IOT_USB_HOST_BUSY if another operation is in progress on the same pipe.
  • IOT_USB_HOST_READ_FAIL if unable to complete the read operation.

◆ iot_usb_host_write_sync()

int32_t iot_usb_host_write_sync ( IotUsbHostHandle_t const  pxUsbHost,
IotPipeHandle_t  pxPipe,
void *const  pvBuffer,
size_t  xBytes 
)

Starts the usb host write operation in blocking mode.

Note
This function will block until all xBytes are written.
Parameters
[in]pxUsbHostThe usb host peripheral handle returned in iot_usb_host_open() function.
[in]pxPipeThe pipe handle.
[out]pvBufferThe transmit buffer containing the data to be written. It must be allocated by caller and remain valid before write complete.
[in]xBytesThe number of bytes to write.
Returns
  • IOT_USB_HOST_SUCCESS on success
  • IOT_USB_HOST_INVALID_VALUE if
    • pxUsbHost is NULL.
    • pxPipe is NULL.
    • pvBuffer is NULL.
    • xBytes == 0.
  • IOT_USB_HOST_BUSY if another operation is in progress on the same pipe.
  • IOT_USB_HOST_WRITE_FAIL if unable to complete the write operation.

◆ iot_usb_host_cancel()

int32_t iot_usb_host_cancel ( IotUsbHostHandle_t const  pxUsbHost,
IotPipeHandle_t  pxPipe 
)

This function is used to cancel the current operation in progress.

Parameters
[in]pxUsbHostThe USB Host peripheral handle returned in iot_usb_host_open() function.
[in]pxPipeThe usb pipe on which user want to cancel operation.
Returns
  • IOT_USB_HOST_SUCCESS on success
  • IOT_USB_HOST_INVALID_VALUE if
    • pxUsbHost is NULL.
    • pxPipe is NULL.
  • IOT_USB_HOST_FUNCTION_NOT_SUPPORTED if cancel transfer is not supported.
  • IOT_USB_HOST_NOTHING_TO_CANCEL if nothing to cancel.

◆ iot_usb_host_ioctl()

int32_t iot_usb_host_ioctl ( IotUsbDeviceHandle_t  pxUsbDevice,
IotUsbHostIoctlRequest_t  xRequest,
void *const  pvBuffer 
)

Used for various usb host control function.

Parameters
[in]pxUsbDeviceThe USB device peripheral handle for host to control.
[in]xRequestThe request should be one of IotUsbHostIoctlRequest_t.
[in,out]pvBufferThe request values for the usb host.
Returns
  • IOT_USB_HOST_SUCCESS on success
  • IOT_USB_HOST_INVALID_VALUE if
    • pxUsbDevice is NULL.
    • xRequest is invalid.
    • pvBuffer is NULL.
  • IOT_USB_HOST_FUNCTION_NOT_SUPPORTED if ioctl request not supported.
  • IOT_USB_HOST_ERROR for other error.

◆ iot_usb_host_send_setup()

int32_t iot_usb_host_send_setup ( IotUsbHostHandle_t const  pxUsbHost,
IotPipeHandle_t  pxPipe,
void *  pvSetup,
uint8_t *  pucData 
)

Send setup packet to the pipe.

Parameters
[in]pxUsbHostThe USB Host peripheral handle returned in iot_usb_host_open() function.
[in]pxPipeThe usb pipe on which we are operating.
[in]pvSetupSetup packet.
[in]pucDataData to be sent if needed.
Returns
  • IOT_USB_HOST_SUCCESS on success
  • IOT_USB_HOST_INVALID_VALUE if
    • pxUsbHost is NULL.
    • pxPipe is NULL.
    • pvSetup is NULL.
    • pvData is NULL.
  • IOT_USB_HOST_ERROR for other error.

◆ iot_usb_host_close()

int32_t iot_usb_host_close ( IotUsbHostHandle_t const  pxUsbHost)

Close the USB host peripheral.

Parameters
[in]pxUsbHostThe USB host handle returned in open() call.
Returns
  • IOT_USB_HOST_SUCCESS on success
  • IOT_USB_HOST_INVALID_VALUE if
    • pxUsbHost is NULL.
    • pxUsbHost not open (already closed).