USB Device Vendor API

Description

USB Device Vendor API.

Data Structures

struct sl_usbd_vendor_callbacks_t
Vendor callbacks.

Functions

sl_status_t sl_usbd_vendor_init (void)
Initialize the internal structures and variables used by the Vendor class.
sl_status_t sl_usbd_vendor_create_instance (bool intr_en, uint16_t interval, sl_usbd_vendor_callbacks_t *p_vendor_callbacks, uint8_t *p_class_nbr)
Add a new instance of the Vendor class.
sl_status_t sl_usbd_vendor_add_to_configuration (uint8_t class_nbr, uint8_t config_nbr)
Add the Vendor class instance into the specified configuration (see Note #1).
sl_status_t sl_usbd_vendor_is_enabled (uint8_t class_nbr, bool *p_enabled)
Get the vendor class enable state.
sl_status_t sl_usbd_vendor_read_bulk_sync (uint8_t class_nbr, void *p_buf, uint32_t buf_len, uint16_t timeout, uint32_t *p_xfer_len)
Add a Microsoft OS extended property to this vendor class instance.
sl_status_t sl_usbd_vendor_write_bulk_sync (uint8_t class_nbr, void *p_buf, uint32_t buf_len, uint16_t timeout, bool end, uint32_t *p_xfer_len)
Send data to the host through Bulk IN endpoint.
sl_status_t sl_usbd_vendor_read_bulk_async (uint8_t class_nbr, void *p_buf, uint32_t buf_len, sl_usbd_vendor_async_function_t async_fnct, void *p_async_arg)
Receive data from the host through the Bulk OUT endpoint.
sl_status_t sl_usbd_vendor_write_bulk_async (uint8_t class_nbr, void *p_buf, uint32_t buf_len, sl_usbd_vendor_async_function_t async_fnct, void *p_async_arg, bool end)
Send data to the host through the Bulk IN endpoint.
sl_status_t sl_usbd_vendor_read_interrupt_sync (uint8_t class_nbr, void *p_buf, uint32_t buf_len, uint16_t timeout, uint32_t *p_xfer_len)
Receive data from the the host through the Interrupt OUT endpoint.
sl_status_t sl_usbd_vendor_write_interrupt_sync (uint8_t class_nbr, void *p_buf, uint32_t buf_len, uint16_t timeout, bool end, uint32_t *p_xfer_len)
Send data to the host through the Interrupt IN endpoint.
sl_status_t sl_usbd_vendor_read_interrupt_async (uint8_t class_nbr, void *p_buf, uint32_t buf_len, sl_usbd_vendor_async_function_t async_fnct, void *p_async_arg)
Receive data from the host through Interrupt OUT endpoint.
sl_status_t sl_usbd_vendor_write_interrupt_async (uint8_t class_nbr, void *p_buf, uint32_t buf_len, sl_usbd_vendor_async_function_t async_fnct, void *p_async_arg, bool end)
Send data to the host through the Interrupt IN endpoint.

Typedefs

typedef void(* sl_usbd_vendor_async_function_t ) (uint8_t class_nbr, void *p_buf, uint32_t buf_len, uint32_t xfer_len, void *p_callback_arg, sl_status_t status)
App callback used for async comm.

Function Documentation

sl_usbd_vendor_init()

sl_status_t sl_usbd_vendor_init ( void )

Initialize the internal structures and variables used by the Vendor class.

Returns
Returns SL_STATUS_OK on success or another SL_STATUS code on failure.

sl_usbd_vendor_create_instance()

sl_status_t sl_usbd_vendor_create_instance ( bool intr_en,
uint16_t interval,
sl_usbd_vendor_callbacks_t * p_vendor_callbacks,
uint8_t * p_class_nbr
)

Add a new instance of the Vendor class.

Parameters
intr_en Interrupt endpoints IN and OUT flag:
  • true Pair of interrupt endpoints added to interface.
  • false Pair of interrupt endpoints not added to interface.
interval Endpoint interval in milliseconds (must be a power of 2).
p_vendor_callbacks Pointer to vendor callback structure. [Content MUST be persistent]
p_class_nbr Pointer to a variable that will receive class instance number, if no errors are returned, or SL_USBD_CLASS_NBR_NONE otherwise.
Returns
Returns SL_STATUS_OK on success or another SL_STATUS code on failure.

sl_usbd_vendor_add_to_configuration()

sl_status_t sl_usbd_vendor_add_to_configuration ( uint8_t class_nbr,
uint8_t config_nbr
)

Add the Vendor class instance into the specified configuration (see Note #1).

Parameters
class_nbr Class instance number.
config_nbr Configuration index to which to add the Vendor class instance.
Returns
Returns SL_STATUS_OK on success or another SL_STATUS code on failure.
Note
(1) Called several times, it creates multiple instances and configurations. For instance, the following architecture could be created :
*               FS
*               |-- Configuration 0
*                   |-- Interface 0 (Vendor 0)
*               |-- Configuration 1
*                   |-- Interface 0 (Vendor 0)
*                   |-- Interface 1 (Vendor 1)
*               
In that example, there are two instances of Vendor class: 'Vendor 0' and '1', and two possible configurations: 'Configuration 0' and '1'. 'Configuration 1' is composed of two interfaces. Each class instance has an association with one of the interfaces. If 'Configuration 1' is activated by the host, it allows the host to access two different functionalities offered by the device.
(2) Configuration Descriptor corresponding to a Vendor-specific device has the following format :
*               Configuration Descriptor
*               |-- Interface Descriptor (Vendor class)
*                   |-- Endpoint Descriptor (Bulk OUT)
*                   |-- Endpoint Descriptor (Bulk IN)
*                   |-- Endpoint Descriptor (Interrupt OUT) - optional
*                   |-- Endpoint Descriptor (Interrupt IN)  - optional
*               

sl_usbd_vendor_is_enabled()

sl_status_t sl_usbd_vendor_is_enabled ( uint8_t class_nbr,
bool * p_enabled
)

Get the vendor class enable state.

Parameters
class_nbr Class instance number.
p_enabled Pointer to a variable that will receive the enable state. The variable is set to true, if the Vendor class is enabled, and is set to false if the Vendor class is NOT enabled.
Returns
Returns SL_STATUS_OK on success or another SL_STATUS code on failure.

sl_usbd_vendor_read_bulk_sync()

sl_status_t sl_usbd_vendor_read_bulk_sync ( uint8_t class_nbr,
void * p_buf,
uint32_t buf_len,
uint16_t timeout,
uint32_t * p_xfer_len
)

Add a Microsoft OS extended property to this vendor class instance.

Parameters
class_nbr Class instance number.
property_type Property type (see Note #2).
  • OS_PROPERTY_TYPE_REG_SZ
  • OS_PROPERTY_TYPE_REG_EXPAND_SZ
  • OS_PROPERTY_TYPE_REG_BINARY
  • OS_PROPERTY_TYPE_REG_DWORD_LITTLE_ENDIAN
  • OS_PROPERTY_TYPE_REG_DWORD_BIG_ENDIAN
  • OS_PROPERTY_TYPE_REG_LINK
  • OS_PROPERTY_TYPE_REG_MULTI_SZ
p_property_name Pointer to the buffer that contains the property name. -— Buffer assumed to be persistent -—
property_name_len Length of the property name in octets.
p_property Pointer to the buffer that contains the property name. -— Buffer assumed to be persistent -—
property_len Length of the property in octets.
Returns
Returns SL_STATUS_OK on success or another SL_STATUS code on failure.
Note
(1) For more information on Microsoft OS descriptors, see ' http://msdn.microsoft.com/en-us/library/windows/hardware/gg463179.aspx' .
(2) For more information on property types, refer to "Table 3. Property Data Types" of "Extended Properties OS Feature Descriptor Specification" document provided by Microsoft available at ' http://msdn.microsoft.com/en-us/library/windows/hardware/gg463179.aspx' .

Receive the data from the host through the Bulk OUT endpoint. This function is blocking.

Parameters
class_nbr Class instance number.
p_buf Pointer to the receive buffer.
buf_len Receive the buffer length in octets.
timeout Timeout in milliseconds.
p_xfer_len Pointer to a variable that will receive transfer length. The variable is set to number of octets received, if no errors are returned, or is set to 0 if any errors are returned.
Returns
Returns SL_STATUS_OK on success or another SL_STATUS code on failure.

sl_usbd_vendor_write_bulk_sync()

sl_status_t sl_usbd_vendor_write_bulk_sync ( uint8_t class_nbr,
void * p_buf,
uint32_t buf_len,
uint16_t timeout,
bool end,
uint32_t * p_xfer_len
)

Send data to the host through Bulk IN endpoint.

This function is blocking.

Parameters
class_nbr Class instance number.
p_buf Pointer to the transmit buffer.
buf_len Transmit the buffer length in octets.
timeout Timeout in milliseconds.
end End-of-transfer flag (see Note #1).
p_xfer_len Pointer to a variable that will receive transfer length. The variable is set to number of octets received, if no errors are returned, or is set to 0 if any errors are returned.
Returns
Returns SL_STATUS_OK on success or another SL_STATUS code on failure.
Note
(1) If the end-of-transfer is set and the transfer length is a multiple of the maximum packet size, a zero-length packet is transferred to signal the end of transfer to the host.

sl_usbd_vendor_read_bulk_async()

sl_status_t sl_usbd_vendor_read_bulk_async ( uint8_t class_nbr,
void * p_buf,
uint32_t buf_len,
sl_usbd_vendor_async_function_t async_fnct,
void * p_async_arg
)

Receive data from the host through the Bulk OUT endpoint.

This function is non-blocking are returns immediately after transfer preparation. Upon transfer completion, a callback provided by the application will be called to finalize the transfer.

Parameters
class_nbr Class instance number.
p_buf Pointer to the receive buffer.
buf_len Receive buffer length in octets.
async_fnct Receive the the callback.
p_async_arg Additional argument provided by the application for the receive callback.
Returns
Returns SL_STATUS_OK on success or another SL_STATUS code on failure.

sl_usbd_vendor_write_bulk_async()

sl_status_t sl_usbd_vendor_write_bulk_async ( uint8_t class_nbr,
void * p_buf,
uint32_t buf_len,
sl_usbd_vendor_async_function_t async_fnct,
void * p_async_arg,
bool end
)

Send data to the host through the Bulk IN endpoint.

This function is non-blocking and returns immediately after transfer preparation. Upon transfer completion, a callback provided by the application will be called to finalize the transfer.

Parameters
class_nbr Class instance number.
p_buf Pointer to the transmit buffer.
buf_len Transmit buffer length in octets.
async_fnct Transmit the callback.
p_async_arg Additional argument provided by the application for the transmit callback.
end End-of-transfer flag (see Note #1).
Returns
Returns SL_STATUS_OK on success or another SL_STATUS code on failure.
Note
(1) If the end-of-transfer is set and the transfer length is a multiple of the maximum packet size, a zero-length packet is transferred to signal the end of transfer to the host.

sl_usbd_vendor_read_interrupt_sync()

sl_status_t sl_usbd_vendor_read_interrupt_sync ( uint8_t class_nbr,
void * p_buf,
uint32_t buf_len,
uint16_t timeout,
uint32_t * p_xfer_len
)

Receive data from the the host through the Interrupt OUT endpoint.

This function is blocking.

Parameters
class_nbr Class instance number.
p_buf Pointer to the receive buffer.
buf_len Receive buffer length in octets.
timeout Timeout in milliseconds.
p_xfer_len Pointer to a variable that will receive transfer length. The variable is set to number of octets received, if no errors are returned, or is set to 0 if any errors are returned.
Returns
Returns SL_STATUS_OK on success or another SL_STATUS code on failure.

sl_usbd_vendor_write_interrupt_sync()

sl_status_t sl_usbd_vendor_write_interrupt_sync ( uint8_t class_nbr,
void * p_buf,
uint32_t buf_len,
uint16_t timeout,
bool end,
uint32_t * p_xfer_len
)

Send data to the host through the Interrupt IN endpoint.

This function is blocking.

Parameters
class_nbr Class instance number.
p_buf Pointer to the transmit buffer.
buf_len Transmit buffer length in octets.
timeout Timeout in milliseconds.
end End-of-transfer flag (see Note #1).
p_xfer_len Pointer to a variable that will receive transfer length. The variable is set to number of octets received, if no errors are returned, or is set to 0 if any errors are returned.
Returns
Returns SL_STATUS_OK on success or another SL_STATUS code on failure.
Note
(1) If the end-of-transfer is set and the transfer length is a multiple of the maximum packet size, a zero-length packet is transferred to signal the end of transfer to the host.

sl_usbd_vendor_read_interrupt_async()

sl_status_t sl_usbd_vendor_read_interrupt_async ( uint8_t class_nbr,
void * p_buf,
uint32_t buf_len,
sl_usbd_vendor_async_function_t async_fnct,
void * p_async_arg
)

Receive data from the host through Interrupt OUT endpoint.

This function is non-blocking and returns immediately after transfer preparation. Upon transfer completion, a callback provided by the application will be called to finalize the transfer.

Parameters
class_nbr Class instance number.
p_buf Pointer to the receive buffer.
buf_len Receive buffer length in octets.
async_fnct Receive callback.
p_async_arg Additional argument provided by application for the receive callback.
Returns
Returns SL_STATUS_OK on success or another SL_STATUS code on failure.

sl_usbd_vendor_write_interrupt_async()

sl_status_t sl_usbd_vendor_write_interrupt_async ( uint8_t class_nbr,
void * p_buf,
uint32_t buf_len,
sl_usbd_vendor_async_function_t async_fnct,
void * p_async_arg,
bool end
)

Send data to the host through the Interrupt IN endpoint.

This function is non-blocking and returns immediately after transfer preparation. Upon transfer completion, a callback provided by the application will be called to finalize the transfer.

Parameters
class_nbr Class instance number.
p_buf Pointer to the transmit buffer.
buf_len Transmit buffer length in octets.
async_fnct Transmit callback.
p_async_arg Additional argument provided by the application for the transmit callback.
end End-of-transfer flag (see Note #1).
Returns
Returns SL_STATUS_OK on success or another SL_STATUS code on failure.
Note
(1) If the end-of-transfer is set and the transfer length is a multiple of the maximum packet size, a zero-length packet is transferred to signal the end of transfer to the host.

Typedef Documentation

sl_usbd_vendor_async_function_t

typedef void(* sl_usbd_vendor_async_function_t) (uint8_t class_nbr, void *p_buf, uint32_t buf_len, uint32_t xfer_len, void *p_callback_arg, sl_status_t status)

App callback used for async comm.