USB
USB 简介
USB(Universal Serial Bus)是一种通用的总线标准,用于连接主机和外设设备。USB 主机可以通过 USB 接口与 USB 设备连接,实现数据传输、电源供给等功能。
USB IF(USB Implementers Forum)是 USB 标准的制定者,它制定了 USB 标准,包括 USB 1.1、USB 2.0等,定义了 USB 接口的物理层、数据链路层、传输层、会话层、表示层等协议,以及 USB 设备类(Device Class)标准,常见的设备类包括 HID(Human Interface Device,人机接口设备)、MSC(Mass Storage Class,大容量存储设备)、CDC(Communication Device Class,通信设备)、Audio、Video 等。
博通BK7258芯片内置 USB 外设,支持各种各样的 USB 应用,包括 USB 多媒体类应用,USB 通信类应用,USB 存储类应用,USB 人机交互类应用等。
默认支持的驱动包括HUB、 UVC(USB Video Class)、UAC(USB Audio Class),其他类的驱动需要打开相应的宏开关进行编译加载。
USB 相关宏定义
CONFIG_USB=y 打开USB的总开关宏定义 使能USB的代码功能
CONFIG_USB_VBAT_CONTROL_GPIO_ID=0x1C 默认使用的GPIO是GPIO_28进行USB Vbus电的控制,用户根据自己的实际情况进行配置
CONFIG_CHERRY_USB=y 默认使用的CherryUSB的开源代码,用户可根据实际情况进行版本的更新
CONFIG_USB_HOST 主程序作为HOST 对连接上的设备进行设备枚举
CONFIG_USB_DEVICE 主程序作为DEVICE 连接到HOST被枚举
CONFIG_TASK_USB_PRIO 设置USB Driver处理线程的优先级
CONFIG_USB_HUB_MULTIPLE_DEVICES 在Host模式下,支持HUB的驱动,以及支持HUB 统一接口的操作。注意最多支持1个HUB的连接
CONFIG_USBHOST_HUB_MAX_EHPORTS=4 默认最多支持4个port 接口的HUB操作
CONFIG_USBHOST_HUB_PORT_SUPPORT_MAX_DEVICE=5 默认每个接口支持5种class设备的连接
CONFIG_USB_UVC 支持USB Vidoe Class的HOST驱动
CONFIG_USB_UAC 支持USB Audio Class的HOST驱动
USB 基本使用
USB open
USB 测试示例
注:BK7258 USB 默认运行在CPU1, 测试目标:USB模块开关正常,枚举正常,解析正常,断开/连接等状态记录正常。
作为HOST 识别枚举U盘为例,输入命令和LOG信息如下图所示:
1、默认串口输入 bootcore 1 1 启动CPU1 ,log如下
CLI Boot CPU1
2、默认串口输入cpu1 usb power 1c 1,log如下
CLI USB PowerON
3、默认串口输入cpu1 usb open_host,枚举成功log如下
CLI USB Open Host
4、默认串口输入cpu1 usb close,log如下
CLI USB Close
5、默认串口输入cpu1 usb power 1c 0,log如下
CLI USB PowerDown
USB HUB 端口数量和设备枚举信息调整的memory size
若设备出现超过1024bytes的枚举信息,则需要对默认配置进行调整 使用hub时,需要根据设备情况对port 数据量进行配置
USB HUB
USB API Status
API |
BK7258_cp1 |
|---|---|
Y |
|
Y |
|
Y |
|
Y |
|
Y |
|
|
Y |
Y |
|
|
Y |
USB Port Number
Capability |
BK7258 |
BK7258_cp1 |
BK7258_cp2 |
|---|---|---|---|
Port Number |
1 |
1 |
1 |
USB Pin and GPIO Map
USB Pin |
BK7258 |
BK7258_cp1 |
BK7258_cp2 |
|---|---|---|---|
USB power |
28 |
28 |
28 |
USB API Reference
Header File
Functions
-
bk_err_t bk_usb_driver_init(void)
USB Driver initialization.
Register the adaptation layer and pass the function pointers used by the closed source library. Register the current USB Class type to be supported, and it can be uninstalled and reinitialized during execution. But be sure to do so before calling other interfaces.
Configure Interrupt handling function registration
Configure Class Driver Registration
This API should be called before any other USB APIs.
- 返回
BK_OK: succeed
others: other errors.
-
bk_err_t bk_usb_driver_deinit(void)
USB Driver uninstallation.
Turn off the USB main interrupt switch Unregister Total Interrupt Handling Function Unregistered Class Driver
This API should be called after any other USB APIs.
- 返回
BK_OK: succeed
others: other errors.
-
bk_err_t bk_usb_power_ops(uint32_t gpio_id, bool ops)
Pin controlled USB Vbus.
This API controls VBUS for USB:
Determine whether to output voltage through the high and low levels of a GPIO output parameter: gpio_id Select the corresponding pin number ops Choose to power on or off
Configure whether USB is power on
When the fusion device is working, if there is a device voting for use, it cannot be directly turned off.
- 返回
BK_OK: succeed
others: other errors.
-
bk_err_t bk_usb_open(uint32_t usb_mode)
open the USB
This API configure the resoure common to USB:
Select the identity as host or slave parameter: usb_mode USB_HOST_MODE = 0 USB_DEVICE_MODE = 1
Configure USB common clock
Configure USB common registers
This API should be called before any other USB APIs.
- 返回
BK_OK: succeed
others: other errors.
-
bk_err_t bk_usb_close(void)
close the USB
This API release USB resources:
Restore register
Turn off the power and clock
This API should be called after any other USB APIs.
- 返回
BK_OK: succeed
others: other errors.
-
bool bk_usb_get_device_connect_status(void)
Obtain whether there is currently a device connection.
- 返回
TRUE: connect
FALSE: disconnect
USB API Typedefs
Header File
Structures
-
struct usb_device_descriptor_t
-
struct usb_configuration_descriptor_t
-
struct usb_interface_association_descriptor_t
-
struct usb_interface_descriptor_t
-
struct usb_audio_endpoint_general_descriptor_t
-
struct s_bk_usb_endpoint_descriptor
-
struct bk_uvc_format_index
-
struct bk_uvc_frame
-
struct bk_uvc_all_frame
-
struct bk_uvc_device_brief_info_t
-
struct bk_uvc_config_t
-
struct audio_packet_t
-
struct audio_packet_control_t
-
struct bk_uac_ring_buffer_t
-
struct bk_uac_device_brief_info_t
-
struct bk_uac_mic_config_t
-
struct bk_uac_spk_config_t
-
struct bk_uac_config_t
-
struct bk_uvc_uac_app_callback
-
struct s_usb_device_request
-
struct s_usb_transfer_buffer_info
-
struct bk_usb_hub_port_info
-
struct usb_hub_pipe
Macros
-
BK_ERR_USB_NOT_POWER
USB vbus poweron, etc
-
BK_ERR_USB_NOT_OPEN
USB dose not turn on clock and power, etc
-
BK_ERR_USB_NOT_CLOSE
USB dose not turn off clock and power, etc
-
BK_ERR_USB_NOT_CONNECT
USB device not connected
-
BK_ERR_USB_OPERATION_NULL_POINTER
USB Operated with null pointer
-
BK_ERR_USB_UVC_NOT_START
UVC Transfer not started
-
BK_ERR_USB_UVC_NOT_STOP
UVC Transfer not stopped
-
BK_ERR_USB_UVC_NOT_PAUSE
UVC Transfer not paused
-
BK_ERR_USB_UVC_GET_PARAMETER_FAILED
UVC The command to obtain parameters did not respond
-
BK_ERR_USB_UVC_SET_PARAMETER_FAILED
UVC Configuration parameter command did not respond
-
BK_ERR_USB_UVC_SET_INTERFACE_FAILED
UVC The set port command did not respond
-
BK_ERR_USB_UVC_NOSUPPORT_ATTRIBUTE
UVC The attribute configuration is not supported
-
BK_ERR_USB_UAC_NOT_START
UAC Transfer not started
-
BK_ERR_USB_UAC_NOT_STOP
UAC Transfer not stopped
-
BK_ERR_USB_UAC_NOT_PAUSE
UAC Transfer not paused
-
BK_ERR_USB_UAC_GET_PARAMETER_FAILED
UAC The command to obtain parameters did not respond
-
BK_ERR_USB_UAC_SET_PARAMETER_FAILED
UAC Configuration parameter command did not respond
-
BK_ERR_USB_UAC_SET_INTERFACE_FAILED
UAC The set port command did not respond
-
BK_ERR_USB_UAC_NOSUPPORT_ATTRIBUTE
UAC The attribute configuration is not supported
-
BK_USB_ENDPOINT_XFERTYPE_MASK
Type Definitions
-
typedef void (*control_irpcomplete)(void*, void*)
-
typedef void (*usbh_hub_connect_disconnect_cb_t)(bk_usb_hub_port_info *port_info, void *arg)
Enumerations
-
enum E_USB_CONNECTION_STATUS
Values:
-
enumerator USB_DEVICE_DISCONNECT
-
enumerator USB_DEVICE_CONNECT
-
enumerator USB_DEVICE_DISCONNECT
-
enum E_FRAME_RATE_ID
Values:
-
enumerator FPS_60
-
enumerator FPS_30
-
enumerator FPS_25
-
enumerator FPS_20
-
enumerator FPS_15
-
enumerator FPS_10
-
enumerator FPS_5
-
enumerator FPS_60
-
enum E_USB_DEVICE_T
Values:
-
enumerator USB_UVC_DEVICE
-
enumerator USB_UVC_H26X_DEVICE
-
enumerator USB_UAC_MIC_DEVICE
-
enumerator USB_UAC_SPEAKER_DEVICE
-
enumerator USB_MSD_DEVICE
-
enumerator USB_OTA_DEVICE
-
enumerator USB_USER_CHECK_DEVICE
-
enumerator USB_CDC_DEVICE
-
enumerator USB_DEVICE_MAX
-
enumerator USB_UVC_DEVICE
-
enum E_USB_ENDPOINT_TRANSFER_MODE_T
Values:
-
enumerator USB_ENDPOINT_CONTROL_TRANSFER
-
enumerator USB_ENDPOINT_ISOCH_TRANSFER
-
enumerator USB_ENDPOINT_BULK_TRANSFER
-
enumerator USB_ENDPOINT_INT_TRANSFER
-
enumerator USB_ENDPOINT_INVALID_TRANSFER
-
enumerator USB_ENDPOINT_CONTROL_TRANSFER
-
enum bk_usb_drv_op_t
Values:
-
enumerator USB_DRV_IDLE
-
enumerator USB_DRV_EXIT
-
enumerator USB_POWER_OPS
-
enumerator USB_DRV_USB_INIT
-
enumerator USB_DRV_USB_DEINIT
-
enumerator USB_DRV_SET_DEV_USE
-
enumerator USB_DRV_USB_OPEN
-
enumerator USB_DRV_USB_CLOSE
-
enumerator USB_DRV_CONNECT_HANDLE
-
enumerator USB_DRV_DISCONNECT_HANDLE
-
enumerator USB_DRV_GET_DEV_CONNECT_STATUS
-
enumerator USB_DRV_CHECK_DEV_SUPPORT
-
enumerator USB_DRV_PRASE_DESCRIPTOR
-
enumerator USB_DRV_INIT_CONTROL_TRANS
-
enumerator USB_DRV_DEINIT_CONTROL_TRANS
-
enumerator USB_DRV_CONTROL_TRANSFER
-
enumerator USB_DRV_UVC_REGISTER_CONNECT_CB
-
enumerator USB_DRV_UVC_REGISTER_DISCONNECT_CB
-
enumerator USB_DRV_UVC_GET_PARAM
-
enumerator USB_DRV_UVC_SET_PARAM
-
enumerator USB_DRV_UVC_REGISTER_TRANSFER_OPS
-
enumerator USB_DRV_UVC_TRANSFER_BUFFER_MALLOC
-
enumerator USB_DRV_UVC_TRANSFER_BUFFER_PUSH
-
enumerator USB_DRV_UVC_TRANSFER_BUFFER_POP
-
enumerator USB_DRV_UVC_TRANSFER_BUFFER_FREE
-
enumerator USB_DRV_VIDEO_OPEN_PIPE
-
enumerator USB_DRV_VIDEO_CLOSE_PIPE
-
enumerator USB_DRV_VIDEO_START
-
enumerator USB_DRV_VIDEO_STOP
-
enumerator USB_DRV_VIDEO_RX
-
enumerator USB_DRV_VIDEO_RXED
-
enumerator USB_DRV_UAC_REGISTER_CONNECT_CB
-
enumerator USB_DRV_UAC_REGISTER_DISCONNECT_CB
-
enumerator USB_DRV_UAC_GET_PARAM
-
enumerator USB_DRV_UAC_SET_PARAM
-
enumerator USB_DRV_UAC_REGISTER_TRANSFER_OPS
-
enumerator USB_DRV_UAC_TRANSFER_BUFFER_MALLOC
-
enumerator USB_DRV_UAC_TRANSFER_BUFFER_PUSH
-
enumerator USB_DRV_UAC_TRANSFER_BUFFER_POP
-
enumerator USB_DRV_UAC_TRANSFER_BUFFER_FREE
-
enumerator USB_DRV_AUDIO_OPEN_PIPE
-
enumerator USB_DRV_AUDIO_CLOSE_PIPE
-
enumerator USB_DRV_AUDIO_MIC_START
-
enumerator USB_DRV_AUDIO_MIC_STOP
-
enumerator USB_DRV_AUDIO_SPK_START
-
enumerator USB_DRV_AUDIO_SPK_STOP
-
enumerator USB_DRV_AUDIO_RX
-
enumerator USB_DRV_AUDIO_RXED
-
enumerator USB_DRV_AUDIO_TX
-
enumerator USB_DRV_AUDIO_TXED
-
enumerator USB_DRV_UVC_TRANSFER_DUAL_BUFFER_MALLOC
-
enumerator USB_DRV_UVC_TRANSFER_DUAL_BUFFER_PUSH
-
enumerator USB_DRV_UVC_TRANSFER_DUAL_BUFFER_POP
-
enumerator USB_DRV_UVC_TRANSFER_DUAL_BUFFER_FREE
-
enumerator USB_DRV_VIDEO_DUAL_START
-
enumerator USB_DRV_VIDEO_DUAL_STOP
-
enumerator USB_DRV_VIDEO_DUAL_RX
-
enumerator USB_DRV_VIDEO_DUAL_RXED
-
enumerator USB_DRV_IDLE
-
enum E_USB_ATTRIBUTE_OP
Values:
-
enumerator USB_ATTRIBUTE_RC_UNDEFINED
-
enumerator USB_ATTRIBUTE_SET_CUR
-
enumerator USB_ATTRIBUTE_GET_CUR
-
enumerator USB_ATTRIBUTE_GET_MIN
-
enumerator USB_ATTRIBUTE_GET_MAX
-
enumerator USB_ATTRIBUTE_GET_RES
-
enumerator USB_ATTRIBUTE_GET_LEN
-
enumerator USB_ATTRIBUTE_GET_INFO
-
enumerator USB_ATTRIBUTE_GET_DEF
-
enumerator USB_ATTRIBUTE_RC_UNDEFINED
-
enum E_UVC_ATTRIBUTE_T
Values:
-
enumerator UVC_ATTRIBUTE_CONTROL_UNDEFINED
-
enumerator UVC_ATTRIBUTE_BACKLIGHT_COMPENSATION
-
enumerator UVC_ATTRIBUTE_BRIGHTNESS
-
enumerator UVC_ATTRIBUTE_CONTRAST
-
enumerator UVC_ATTRIBUTE_GAIN
-
enumerator UVC_ATTRIBUTE_POWER_LINE_FREQUENCY
-
enumerator UVC_ATTRIBUTE_HUE
-
enumerator UVC_ATTRIBUTE_SATURATION
-
enumerator UVC_ATTRIBUTE_SHARPNESS
-
enumerator UVC_ATTRIBUTE_GAMMA
-
enumerator UVC_ATTRIBUTE_WHITE_BALANCE_TEMPERATURE
-
enumerator UVC_ATTRIBUTE_WHITE_BALANCE_TEMPERATURE_AUTO
-
enumerator UVC_ATTRIBUTE_WHITE_BALANCE_COMPONENT
-
enumerator UVC_ATTRIBUTE_WHITE_BALANCE_COMPONENT_AUTO
-
enumerator UVC_ATTRIBUTE_DIGITAL_MULTIPLIER
-
enumerator UVC_ATTRIBUTE_DIGITAL_MULTIPLIER_LIMIT
-
enumerator UVC_ATTRIBUTE_HUE_AUTO
-
enumerator UVC_ATTRIBUTE_ANALOG_VIDEO_STANDARD
-
enumerator UVC_ATTRIBUTE_ANALOG_LOCK_STATUS
-
enumerator UVC_ATTRIBUTE_NUM
-
enumerator UVC_ATTRIBUTE_CONTROL_UNDEFINED
-
enum E_UAC_ATTRIBUTE_T
Values:
-
enumerator UAC_ATTRIBUTE_UNDEF
-
enumerator UAC_ATTRIBUTE_MUTE
-
enumerator UAC_ATTRIBUTE_VOLUME
-
enumerator UAC_ATTRIBUTE_BASS
-
enumerator UAC_ATTRIBUTE_MID
-
enumerator UAC_ATTRIBUTE_TREBLE
-
enumerator UAC_ATTRIBUTE_GRAPHIC_EQUALIZER
-
enumerator UAC_ATTRIBUTE_AUTOMATIC_GAIN
-
enumerator UAC_ATTRIBUTE_DEALY
-
enumerator UAC_ATTRIBUTE_BASS_BOOST
-
enumerator UAC_ATTRIBUTE_LOUDNESS
-
enumerator UAC_ATTRIBUTE_INP_GAIN
-
enumerator UAC_ATTRIBUTE_INP_GAIN_PAD
-
enumerator UAC_ATTRIBUTE_PHASE_INVERT
-
enumerator UAC_ATTRIBUTE_UNDERFLOW
-
enumerator UAC_ATTRIBUTE_OVERFLOW
-
enumerator UAC_ATTRIBUTE_LATENCY
-
enumerator UAC_ATTRIBUTE_NUM
-
enumerator UAC_ATTRIBUTE_UNDEF