USB Device

USB Device Overview

A USB (Universal Serial Bus) device is a hardware component that connects to a host (e.g., a computer or microcontroller) via the USB interface. It enables data transfer and power delivery between the host and the device. USB is widely used for peripherals like keyboards, mice, storage drives, cameras, and more.

Usage

  1. All API functions have the first argument as the handle followed by data to the pointer.

  2. To initialize the usb device using rs call

  3. Transmit and receive data from the usb device using rs calls.

  4. Return codes of API functions are defined in header file.

Application Interface

USB device calls

Function

Description

rs_usbd_init

To open the usb device

rs_usbd_packet_received

To receive packet for the usb device

rs_usbd_transmit

To transmit the data to the usb device

Using these ‘rs’ calls to initialize usb device.

Error Code

  • Every API’s for the usb device and returns some success or failure values. Please refer below section,

USB device Header Details

Documentation from the relevant header as follows:

Functions

rs_ret_val_t rs_usbd_init()

Initializes the USB device.

This function sets up the USB device stack and prepares it for operation

Returns:

0 on success or error code on failure

rs_ret_val_t rs_usbd_packet_received(rs_handle_t handle, uint32_t u32_ep, uint8_t *ptr_data, uint32_t u32_len)

Handles the reception of a USB packet.

This function processes a received packet from a USB endpoint.

Parameters:
  • handle[in] - The handle associated with the USB device.

  • u32_ep[in] - The endpoint number that received the packet.

  • ptr_data[out] - Pointer to the buffer where received data is stored.

  • u32_len[in] - The length of the received data.

Returns:

0 on success or error code on failure

rs_ret_val_t rs_usbd_transmit(rs_handle_t handle, uint32_t u32_ep, uint8_t *ptr_data, uint32_t u32_len)

Transmits data over a USB endpoint.

This function sends data through the specified USB endpoint

Parameters:
  • handle[in] - The handle associated with the USB device.

  • u32_ep[in] - The endpoint number to transmit data to.

  • ptr_data[in] - Pointer to the buffer containing data to be sent.

  • u32_len[in] - The length of the data to be transmitted.

Returns:

0 on success or error code on failure

rs_ret_val_t rcb_usbd_packet_received(rs_handle_t handle, uint32_t u32_ep, uint8_t *pre_data, uint32_t u32_len)

Handles the reception of a USB packet with custom handling.

This function processes the received USB packet and performs custom operations on the data received.

Parameters:
  • handle[in] - The handle associated with the USB device.

  • u32_ep[in] - The endpoint number where the packet was received.

  • ptr_data[in] - Pointer to the buffer where the received data is stored.

  • u32_len[in] - The length of the received data.

Returns:

0 on success or error code on failure

rs_ret_val_t rs_usbd_set_pid(uint16_t u16_product_id)

Sets the USB product ID.

This function sets the product ID for the USB device descriptor.

Parameters:

u16_product_id[in] - The product ID to be set.

Returns:

0 on success or error code on failure

rs_ret_val_t rs_usbd_set_vid(uint16_t u16_vendor_id)

Sets the USB vendor ID.

This function sets the vendor ID for the USB device descriptor.

Parameters:

u16_vendor_id[in] - The vendor ID to be set.

Returns:

0 on success or error code on failure