update(cherryusb): update to v1.4.1
This commit is contained in:
parent
e47f478e12
commit
4c206caf8b
|
@ -48,6 +48,10 @@ if RT_USING_CHERRYUSB
|
|||
bool "musb_bk"
|
||||
config RT_CHERRYUSB_DEVICE_MUSB_CUSTOM
|
||||
bool "musb_custom"
|
||||
config RT_CHERRYUSB_DEVICE_KINETIS_MCX
|
||||
bool "kinetis_mcx"
|
||||
config RT_CHERRYUSB_DEVICE_KINETIS_CUSTOM
|
||||
bool "kinetis_custom"
|
||||
config RT_CHERRYUSB_DEVICE_CHIPIDEA_MCX
|
||||
bool "chipidea_mcx"
|
||||
config RT_CHERRYUSB_DEVICE_CHIPIDEA_CUSTOM
|
||||
|
@ -192,6 +196,10 @@ if RT_USING_CHERRYUSB
|
|||
bool "pusb2"
|
||||
config RT_CHERRYUSB_HOST_XHCI
|
||||
bool "xhci"
|
||||
config RT_CHERRYUSB_HOST_KINETIS_MCX
|
||||
bool "kinetis_mcx"
|
||||
config RT_CHERRYUSB_HOST_KINETIS_CUSTOM
|
||||
bool "kinetis_custom"
|
||||
endchoice
|
||||
|
||||
config RT_CHERRYUSB_HOST_CDC_ACM
|
||||
|
|
|
@ -22,7 +22,7 @@ In order to make it easier for users to learn USB basics, enumeration, driver lo
|
|||
In order to facilitate the use of the USB interface and to take into account the fact that users have learned about uart and dma, the following advantages have been designed for the data sending and receiving class of interface:
|
||||
|
||||
- Equivalent to using uart tx dma/uart rx dma
|
||||
- There is no limit to the length of send and receive, the user does not need to care about the USB packetization process (the porting driver does the packetization process)
|
||||
- There is no limit to the length of send and receive, the user does not need to care about the USB packetization process (the porting driver does it)
|
||||
|
||||
### Easy to bring out USB performance
|
||||
|
||||
|
@ -32,7 +32,7 @@ Taking into account USB performance issues and trying to achieve the theoretical
|
|||
- Memory zero copy
|
||||
- If IP has DMA then uses DMA mode (DMA with hardware packetization)
|
||||
- Unlimited length make it easier to interface with hardware DMA and take advantage of DMA
|
||||
- Subcontracting function is handled in interrupt
|
||||
- Packetization is handled in interrupt
|
||||
|
||||
## Directory Structure
|
||||
|
||||
|
@ -75,13 +75,13 @@ CherryUSB Device Stack resource usage (GCC 10.2 with -O2):
|
|||
|
||||
| file | FLASH (Byte) | No Cache RAM (Byte) | RAM (Byte) | Heap (Byte) |
|
||||
|:-------------:|:--------------:|:-------------------------:|:-------------:|:----------------:|
|
||||
|usbd_core.c | 3516 | 512(default) + 320 | 0 | 0 |
|
||||
|usbd_cdc.c | 392 | 0 | 0 | 0 |
|
||||
|usbd_msc.c | 2839 | 128 + 512(default) | 16 | 0 |
|
||||
|usbd_hid.c | 364 | 0 | 0 | 0 |
|
||||
|usbd_audio.c | 1455 | 0 | 0 | 0 |
|
||||
|usbd_video.c | 2494 | 0 | 84 | 0 |
|
||||
|usbd_rndis.c | 2109 | 3340 | 76 | 0 |
|
||||
|usbd_core.c | ~4400 | 512(default) + 320 | 0 | 0 |
|
||||
|usbd_cdc_acm.c | ~400 | 0 | 0 | 0 |
|
||||
|usbd_msc.c | ~3800 | 128 + 512(default) | 16 | 0 |
|
||||
|usbd_hid.c | ~360 | 0 | 0 | 0 |
|
||||
|usbd_audio.c | ~1500 | 0 | 0 | 0 |
|
||||
|usbd_video.c | ~2600 | 0 | 84 | 0 |
|
||||
|usbd_rndis.c | ~2100 | 2 * 1580(default)+156+8 | 76 | 0 |
|
||||
|
||||
## Host Stack Overview
|
||||
|
||||
|
@ -111,16 +111,17 @@ CherryUSB Host Stack resource usage (GCC 10.2 with -O2):
|
|||
|
||||
| file | FLASH (Byte) | No Cache RAM (Byte) | RAM (Byte) | Heap (Byte) |
|
||||
|:-------------:|:--------------:|:-------------------------------:|:---------------------------:|:------------:|
|
||||
|usbh_core.c | ~7700 | 512 + 8 * (1+x) *n | 28 | raw_config_desc |
|
||||
|usbh_hub.c | ~5600 | 32 + 4* (1+x) | 12 + sizeof(struct usbh_hub) * (1+x) | 0 |
|
||||
|usbh_cdc_acm.c | ~1200 | 7 | 4 + sizeof(struct usbh_cdc_acm) * x | 0 |
|
||||
|usbh_msc.c | ~2500 | 32 | 4 + sizeof(struct usbh_msc) * x | 0 |
|
||||
|usbh_hid.c | ~1000 | 128 | 4 + sizeof(struct usbh_hid) * x | 0 |
|
||||
|usbh_video.c | ~3700 | 128 | 4 + sizeof(struct usbh_video) * x | 0 |
|
||||
|usbh_audio.c | ~3100 | 128 | 4 + sizeof(struct usbh_audio) * x | 0 |
|
||||
|usbh_rndis.c | ~3900 | 4096 + 2 * 2048(default)| sizeof(struct usbh_rndis) * 1 | 0 |
|
||||
|usbh_cdc_ecm.c | ~2500 | 2 * 1514 | sizeof(struct usbh_cdc_ecm) * 1 | 0 |
|
||||
|usbh_bluetooth.c | ~2300 | 2 * 2048(default) | sizeof(struct usbh_bluetooth) * 1 | 0 |
|
||||
|usbh_core.c | ~9000 | 512 + 8 * (1+x) *n | 28 | raw_config_desc |
|
||||
|usbh_hub.c | ~6000 | 32 + 4 * (1+x) | 12 + sizeof(struct usbh_hub) * (1+x) | 0 |
|
||||
|usbh_cdc_acm.c | ~900 | 7 | 4 + sizeof(struct usbh_cdc_acm) * x | 0 |
|
||||
|usbh_msc.c | ~2700 | 64 | 4 + sizeof(struct usbh_msc) * x | 0 |
|
||||
|usbh_hid.c | ~1400 | 256 | 4 + sizeof(struct usbh_hid) * x | 0 |
|
||||
|usbh_video.c | ~3800 | 128 | 4 + sizeof(struct usbh_video) * x | 0 |
|
||||
|usbh_audio.c | ~4100 | 128 | 4 + sizeof(struct usbh_audio) * x | 0 |
|
||||
|usbh_rndis.c | ~4200 | 512 + 2 * 2048(default)| sizeof(struct usbh_rndis) * 1 | 0 |
|
||||
|usbh_cdc_ecm.c | ~2200 | 2 * 1514 + 16 | sizeof(struct usbh_cdc_ecm) * 1 | 0 |
|
||||
|usbh_cdc_ncm.c | ~3300 | 2 * 2048(default) + 16 + 32 | sizeof(struct usbh_cdc_ncm) * 1 | 0 |
|
||||
|usbh_bluetooth.c | ~1000 | 2 * 2048(default) | sizeof(struct usbh_bluetooth) * 1 | 0 |
|
||||
|
||||
Among them, `sizeof(struct usbh_hub)` and `sizeof(struct usbh_hubport)` are affected by the following macros:
|
||||
|
||||
|
@ -184,7 +185,7 @@ USB basic concepts and how the CherryUSB Device stack is implemented, see [Cherr
|
|||
|Phytium | e2000 | pusb2/xhci |[phytium_repo](https://gitee.com/phytium_embedded/phytium-free-rtos-sdk)|>=1.4.0 | Long-term |
|
||||
|Artinchip | d12x/d13x/d21x | aic/ehci/ohci |[luban-lite](https://gitee.com/artinchip/luban-lite)|<= latest | Long-term |
|
||||
|Espressif | esp32s2/esp32s3/esp32p4 | dwc2 |[esp32_repo](https://github.com/CherryUSB/cherryusb_esp32)|<= latest | Long-term |
|
||||
|NXP | mcx | chipidea/ehci |[nxp_mcx_repo](https://github.com/CherryUSB/cherryusb_mcx)|<= latest | Long-term |
|
||||
|NXP | mcx | kinetis/chipidea/ehci |[nxp_mcx_repo](https://github.com/CherryUSB/cherryusb_mcx)|<= latest | Long-term |
|
||||
|AllwinnerTech | F1C100S/F1C200S | musb |[cherryusb_rtt_f1c100s](https://github.com/CherryUSB/cherryusb_rtt_f1c100s)|<= latest | the same with musb |
|
||||
|Bekencorp | bk7256/bk7258 | musb |[bk_idk](https://github.com/CherryUSB/bk_idk)| v0.7.0 | the same with musb |
|
||||
|Sophgo | cv18xx | dwc2 |[cvi_alios_open](https://github.com/CherryUSB/cvi_alios_open)| v0.7.0 | TBD |
|
||||
|
@ -211,4 +212,4 @@ CherryUSB discord: https://discord.com/invite/wFfvrSAey8.
|
|||
|
||||
Thanks to the following companies for their support (in no particular order).
|
||||
|
||||
<img src="docs/assets/bouffalolab.jpg" width="100" height="100"/> <img src="docs/assets/hpmicro.jpg" width="100" height="100" /> <img src="docs/assets/eastsoft.jpg" width="100" height="100" /> <img src="docs/assets/rtthread.jpg" width="100" height="100" /> <img src="docs/assets/sophgo.jpg" width="100" height="100" /> <img src="docs/assets/phytium.jpg" width="100" height="100" /> <img src="docs/assets/thead.jpg" width="100" height="100" /> <img src="docs/assets/nuvoton.jpg" width="100" height="100" /> <img src="docs/assets/artinchip.jpg" width="100" height="100" /> <img src="docs/assets/bekencorp.jpg" width="100" height="100" />
|
||||
<img src="docs/assets/bouffalolab.jpg" width="100" height="80"/> <img src="docs/assets/hpmicro.jpg" width="100" height="80" /> <img src="docs/assets/eastsoft.jpg" width="100" height="80" /> <img src="docs/assets/rtthread.jpg" width="100" height="80" /> <img src="docs/assets/sophgo.jpg" width="100" height="80" /> <img src="docs/assets/phytium.jpg" width="100" height="80" /> <img src="docs/assets/thead.jpg" width="100" height="80" /> <img src="docs/assets/nuvoton.jpg" width="100" height="80" /> <img src="docs/assets/artinchip.jpg" width="100" height="80" /> <img src="docs/assets/bekencorp.jpg" width="100" height="80" /> <img src="docs/assets/nxp.png" width="100" height="80" /> <img src="docs/assets/espressif.png" width="100" height="80" />
|
||||
|
|
|
@ -22,7 +22,7 @@ CherryUSB 是一个小而美的、可移植性高的、用于嵌入式系统(带
|
|||
为了方便用户使用 USB 接口,考虑到用户学习过 uart 和 dma,因此,设计的数据收发类接口具备以下优点:
|
||||
|
||||
- 等价于使用 uart tx dma/uart rx dma
|
||||
- 收发长度没有限制,用户不需要关心 USB 分包过程(porting 驱动做分包过程)
|
||||
- 收发长度没有限制,用户不需要关心 USB 分包过程(分包过程在 porting 中处理)
|
||||
|
||||
### 易于发挥 USB 性能
|
||||
|
||||
|
@ -32,7 +32,7 @@ CherryUSB 是一个小而美的、可移植性高的、用于嵌入式系统(带
|
|||
- Memory zero copy
|
||||
- IP 如果带 DMA 则使用 DMA 模式(DMA 带硬件分包功能)
|
||||
- 长度无限制,方便对接硬件 DMA 并且发挥 DMA 的优势
|
||||
- 分包功能在中断中处理
|
||||
- 分包过程在中断中执行
|
||||
|
||||
## 目录结构
|
||||
|
||||
|
@ -75,13 +75,13 @@ CherryUSB Device 协议栈资源占用说明(GCC 10.2 with -O2):
|
|||
|
||||
| file | FLASH (Byte) | No Cache RAM (Byte) | RAM (Byte) | Heap (Byte) |
|
||||
|:-------------:|:--------------:|:-------------------------:|:-------------:|:----------------:|
|
||||
|usbd_core.c | 3516 | 512(default) + 320 | 0 | 0 |
|
||||
|usbd_cdc.c | 392 | 0 | 0 | 0 |
|
||||
|usbd_msc.c | 2839 | 128 + 512(default) | 16 | 0 |
|
||||
|usbd_hid.c | 364 | 0 | 0 | 0 |
|
||||
|usbd_audio.c | 1455 | 0 | 0 | 0 |
|
||||
|usbd_video.c | 2494 | 0 | 84 | 0 |
|
||||
|usbd_rndis.c | 2109 | 3340 | 76 | 0 |
|
||||
|usbd_core.c | ~4400 | 512(default) + 320 | 0 | 0 |
|
||||
|usbd_cdc_acm.c | ~400 | 0 | 0 | 0 |
|
||||
|usbd_msc.c | ~3800 | 128 + 512(default) | 16 | 0 |
|
||||
|usbd_hid.c | ~360 | 0 | 0 | 0 |
|
||||
|usbd_audio.c | ~1500 | 0 | 0 | 0 |
|
||||
|usbd_video.c | ~2600 | 0 | 84 | 0 |
|
||||
|usbd_rndis.c | ~2100 | 2 * 1580(default)+156+8 | 76 | 0 |
|
||||
|
||||
## Host 协议栈简介
|
||||
|
||||
|
@ -111,16 +111,17 @@ CherryUSB Host 协议栈资源占用说明(GCC 10.2 with -O2):
|
|||
|
||||
| file | FLASH (Byte) | No Cache RAM (Byte) | RAM (Byte) | Heap (Byte) |
|
||||
|:-------------:|:--------------:|:-------------------------------:|:---------------------------:|:------------:|
|
||||
|usbh_core.c | ~7700 | 512 + 8 * (1+x) *n | 28 | raw_config_desc |
|
||||
|usbh_hub.c | ~5600 | 32 + 4* (1+x) | 12 + sizeof(struct usbh_hub) * (1+x) | 0 |
|
||||
|usbh_cdc_acm.c | ~1200 | 7 | 4 + sizeof(struct usbh_cdc_acm) * x | 0 |
|
||||
|usbh_msc.c | ~2500 | 32 | 4 + sizeof(struct usbh_msc) * x | 0 |
|
||||
|usbh_hid.c | ~1000 | 128 | 4 + sizeof(struct usbh_hid) * x | 0 |
|
||||
|usbh_video.c | ~3700 | 128 | 4 + sizeof(struct usbh_video) * x | 0 |
|
||||
|usbh_audio.c | ~3100 | 128 | 4 + sizeof(struct usbh_audio) * x | 0 |
|
||||
|usbh_rndis.c | ~3900 | 4096 + 2 * 2048(default)| sizeof(struct usbh_rndis) * 1 | 0 |
|
||||
|usbh_cdc_ecm.c | ~2500 | 2 * 1514 | sizeof(struct usbh_cdc_ecm) * 1 | 0 |
|
||||
|usbh_bluetooth.c | ~2300 | 2 * 2048(default) | sizeof(struct usbh_bluetooth) * 1 | 0 |
|
||||
|usbh_core.c | ~9000 | 512 + 8 * (1+x) *n | 28 | raw_config_desc |
|
||||
|usbh_hub.c | ~6000 | 32 + 4 * (1+x) | 12 + sizeof(struct usbh_hub) * (1+x) | 0 |
|
||||
|usbh_cdc_acm.c | ~900 | 7 | 4 + sizeof(struct usbh_cdc_acm) * x | 0 |
|
||||
|usbh_msc.c | ~2700 | 64 | 4 + sizeof(struct usbh_msc) * x | 0 |
|
||||
|usbh_hid.c | ~1400 | 256 | 4 + sizeof(struct usbh_hid) * x | 0 |
|
||||
|usbh_video.c | ~3800 | 128 | 4 + sizeof(struct usbh_video) * x | 0 |
|
||||
|usbh_audio.c | ~4100 | 128 | 4 + sizeof(struct usbh_audio) * x | 0 |
|
||||
|usbh_rndis.c | ~4200 | 512 + 2 * 2048(default)| sizeof(struct usbh_rndis) * 1 | 0 |
|
||||
|usbh_cdc_ecm.c | ~2200 | 2 * 1514 + 16 | sizeof(struct usbh_cdc_ecm) * 1 | 0 |
|
||||
|usbh_cdc_ncm.c | ~3300 | 2 * 2048(default) + 16 + 32 | sizeof(struct usbh_cdc_ncm) * 1 | 0 |
|
||||
|usbh_bluetooth.c | ~1000 | 2 * 2048(default) | sizeof(struct usbh_bluetooth) * 1 | 0 |
|
||||
|
||||
其中,`sizeof(struct usbh_hub)` 和 `sizeof(struct usbh_hubport)` 受以下宏影响:
|
||||
|
||||
|
@ -185,7 +186,7 @@ CherryUSB 快速入门、USB 基本概念,API 手册,Class 基本概念和
|
|||
|Phytium | e2000 | pusb2/xhci |[phytium_repo](https://gitee.com/phytium_embedded/phytium-free-rtos-sdk)|>=1.4.0 | Long-term |
|
||||
|Artinchip | d12x/d13x/d21x | aic/ehci/ohci |[luban-lite](https://gitee.com/artinchip/luban-lite)|<= latest | Long-term |
|
||||
|Espressif | esp32s2/esp32s3/esp32p4 | dwc2 |[esp32_repo](https://github.com/CherryUSB/cherryusb_esp32)|<= latest | Long-term |
|
||||
|NXP | mcx | chipidea/ehci |[nxp_mcx_repo](https://github.com/CherryUSB/cherryusb_mcx)|<= latest | Long-term |
|
||||
|NXP | mcx | kinetis/chipidea/ehci |[nxp_mcx_repo](https://github.com/CherryUSB/cherryusb_mcx)|<= latest | Long-term |
|
||||
|AllwinnerTech | F1C100S/F1C200S | musb |[cherryusb_rtt_f1c100s](https://github.com/CherryUSB/cherryusb_rtt_f1c100s)|<= latest | the same with musb |
|
||||
|Bekencorp | bk7256/bk7258 | musb |[bk_idk](https://github.com/CherryUSB/bk_idk)| v0.7.0 | the same with musb |
|
||||
|Sophgo | cv18xx | dwc2 |[cvi_alios_open](https://github.com/CherryUSB/cvi_alios_open)| v0.7.0 | TBD |
|
||||
|
@ -213,4 +214,4 @@ CherryUSB 微信群:与我联系后邀请加入
|
|||
|
||||
感谢以下企业支持(顺序不分先后)。
|
||||
|
||||
<img src="docs/assets/bouffalolab.jpg" width="100" height="100"/> <img src="docs/assets/hpmicro.jpg" width="100" height="100" /> <img src="docs/assets/eastsoft.jpg" width="100" height="100" /> <img src="docs/assets/rtthread.jpg" width="100" height="100" /> <img src="docs/assets/sophgo.jpg" width="100" height="100" /> <img src="docs/assets/phytium.jpg" width="100" height="100" /> <img src="docs/assets/thead.jpg" width="100" height="100" /> <img src="docs/assets/nuvoton.jpg" width="100" height="100" /> <img src="docs/assets/artinchip.jpg" width="100" height="100" /> <img src="docs/assets/bekencorp.jpg" width="100" height="100" />
|
||||
<img src="docs/assets/bouffalolab.jpg" width="100" height="80"/> <img src="docs/assets/hpmicro.jpg" width="100" height="80" /> <img src="docs/assets/eastsoft.jpg" width="100" height="80" /> <img src="docs/assets/rtthread.jpg" width="100" height="80" /> <img src="docs/assets/sophgo.jpg" width="100" height="80" /> <img src="docs/assets/phytium.jpg" width="100" height="80" /> <img src="docs/assets/thead.jpg" width="100" height="80" /> <img src="docs/assets/nuvoton.jpg" width="100" height="80" /> <img src="docs/assets/artinchip.jpg" width="100" height="80" /> <img src="docs/assets/bekencorp.jpg" width="100" height="80" /> <img src="docs/assets/nxp.png" width="100" height="80" /> <img src="docs/assets/espressif.png" width="100" height="80" />
|
||||
|
|
|
@ -58,6 +58,11 @@ if GetDepend(['RT_CHERRYUSB_DEVICE']):
|
|||
src += Glob('port/musb/usb_glue_bk.c')
|
||||
if GetDepend(['RT_CHERRYUSB_DEVICE_MUSB_CUSTOM']):
|
||||
src += Glob('port/musb/usb_dc_musb.c')
|
||||
if GetDepend(['RT_CHERRYUSB_DEVICE_KINETIS_MCX']):
|
||||
src += Glob('port/kinetis/usb_dc_kinetis.c')
|
||||
src += Glob('port/kinetis/usb_glue_mcx.c')
|
||||
if GetDepend(['RT_CHERRYUSB_DEVICE_KINETIS_CUSTOM']):
|
||||
src += Glob('port/kinetis/usb_dc_kinetis.c')
|
||||
if GetDepend(['RT_CHERRYUSB_DEVICE_CHIPIDEA_MCX']):
|
||||
src += Glob('port/chipidea/usb_dc_chipidea.c')
|
||||
src += Glob('port/chipidea/usb_glue_mcx.c')
|
||||
|
@ -187,6 +192,11 @@ if GetDepend(['RT_CHERRYUSB_HOST']):
|
|||
src += Glob('port/musb/usb_glue_bk.c')
|
||||
if GetDepend(['RT_CHERRYUSB_HOST_MUSB_CUSTOM']):
|
||||
src += Glob('port/musb/usb_hc_musb.c')
|
||||
if GetDepend(['RT_CHERRYUSB_HOST_KINETIS_MCX']):
|
||||
src += Glob('port/kinetis/usb_hc_kinetis.c')
|
||||
src += Glob('port/kinetis/usb_glue_mcx.c')
|
||||
if GetDepend(['RT_CHERRYUSB_HOST_KINETIS_CUSTOM']):
|
||||
src += Glob('port/kinetis/usb_hc_kinetis.c')
|
||||
if GetDepend(['RT_CHERRYUSB_HOST_PUSB2']):
|
||||
path += [cwd + '/port/pusb2/rt-thread']
|
||||
src += Glob('port/pusb2/rt-thread/usb_hc_glue_phytium.c')
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
VERSION_MAJOR = 1
|
||||
VERSION_MINOR = 4
|
||||
PATCHLEVEL = 0
|
||||
PATCHLEVEL = 1
|
||||
VERSION_TWEAK = 0
|
||||
EXTRAVERSION = 0
|
||||
|
|
|
@ -105,6 +105,9 @@ if(CONFIG_CHERRYUSB_DEVICE)
|
|||
elseif("${CONFIG_CHERRYUSB_DEVICE_DCD}" STREQUAL "chipidea_mcx")
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/chipidea/usb_dc_chipidea.c)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/chipidea/usb_glue_mcx.c)
|
||||
elseif("${CONFIG_CHERRYUSB_DEVICE_DCD}" STREQUAL "kinetis_mcx")
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/kinetis/usb_dc_kinetis.c)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/kinetis/usb_glue_mcx.c)
|
||||
elseif("${CONFIG_CHERRYUSB_DEVICE_DCD}" STREQUAL "hpm")
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/hpm/usb_dc_hpm.c)
|
||||
elseif("${CONFIG_CHERRYUSB_DEVICE_DCD}" STREQUAL "bl")
|
||||
|
@ -260,6 +263,9 @@ if(CONFIG_CHERRYUSB_HOST)
|
|||
elseif("${CONFIG_CHERRYUSB_HOST_HCD}" STREQUAL "musb_bk")
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/musb/usb_hc_musb.c)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/musb/usb_glue_bk.c)
|
||||
elseif("${CONFIG_CHERRYUSB_HOST_HCD}" STREQUAL "kinetis_mcx")
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/kinetis/usb_hc_kinetis.c)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/kinetis/usb_glue_mcx.c)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
|
@ -287,6 +293,5 @@ endif()
|
|||
|
||||
if(CONFIG_CHERRYMP)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/third_party/cherrymp/chry_mempool.c)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/third_party/cherrymp/usbh_uvc_queue.c)
|
||||
list(APPEND cherryusb_incs ${CMAKE_CURRENT_LIST_DIR}/third_party/cherrymp)
|
||||
endif()
|
|
@ -218,7 +218,7 @@
|
|||
// #define CONFIG_USB_DWC2_RXALL_FIFO_SIZE (1024 / 4)
|
||||
/* IN Endpoints Max packet Size / 4 */
|
||||
// #define CONFIG_USB_DWC2_TX0_FIFO_SIZE (64 / 4)
|
||||
// #define CONFIG_USB_DWC2_TX1_FIFO_SIZE (512 / 4)
|
||||
// #define CONFIG_USB_DWC2_TX1_FIFO_SIZE (1024 / 4)
|
||||
// #define CONFIG_USB_DWC2_TX2_FIFO_SIZE (64 / 4)
|
||||
// #define CONFIG_USB_DWC2_TX3_FIFO_SIZE (64 / 4)
|
||||
// #define CONFIG_USB_DWC2_TX4_FIFO_SIZE (0 / 4)
|
||||
|
@ -227,6 +227,8 @@
|
|||
// #define CONFIG_USB_DWC2_TX7_FIFO_SIZE (0 / 4)
|
||||
// #define CONFIG_USB_DWC2_TX8_FIFO_SIZE (0 / 4)
|
||||
|
||||
// #define CONFIG_USB_DWC2_DMA_ENABLE
|
||||
|
||||
/* ---------------- MUSB Configuration ---------------- */
|
||||
// #define CONFIG_USB_MUSB_SUNXI
|
||||
|
||||
|
@ -266,7 +268,7 @@
|
|||
* (largest USB packet used / 4) + 1 for status information + 1 transfer complete +
|
||||
* 1 location each for Bulk/Control endpoint for handling NAK/NYET scenario
|
||||
*/
|
||||
// #define CONFIG_USB_DWC2_RX_FIFO_SIZE ((1012 - CONFIG_USB_DWC2_NPTX_FIFO_SIZE - CONFIG_USB_DWC2_PTX_FIFO_SIZE) / 4)
|
||||
// #define CONFIG_USB_DWC2_RX_FIFO_SIZE ((1012 - CONFIG_USB_DWC2_NPTX_FIFO_SIZE - CONFIG_USB_DWC2_PTX_FIFO_SIZE))
|
||||
|
||||
/* ---------------- MUSB Configuration ---------------- */
|
||||
// #define CONFIG_USB_MUSB_SUNXI
|
||||
|
|
|
@ -132,11 +132,11 @@
|
|||
#define AUDIO_FORMAT_ALAW 0x0004
|
||||
#define AUDIO_FORMAT_MULAW 0x0005
|
||||
|
||||
#define AUDIO_V2_FORMAT_PCM 0x00000001
|
||||
#define AUDIO_V2_FORMAT_PCM8 0x00000002
|
||||
#define AUDIO_V2_FORMAT_IEEE_FLOAT 0x00000004
|
||||
#define AUDIO_V2_FORMAT_ALAW 0x00000008
|
||||
#define AUDIO_V2_FORMAT_MULAW 0x00000010
|
||||
#define AUDIO_V2_FORMAT_PCM 0x00000001
|
||||
#define AUDIO_V2_FORMAT_PCM8 0x00000002
|
||||
#define AUDIO_V2_FORMAT_IEEE_FLOAT 0x00000004
|
||||
#define AUDIO_V2_FORMAT_ALAW 0x00000008
|
||||
#define AUDIO_V2_FORMAT_MULAW 0x00000010
|
||||
|
||||
/* bmChannelConfig: a bitmap field that indicates which spatial locations
|
||||
* are occupied by the channels present in the cluster. The bit allocations
|
||||
|
@ -812,6 +812,60 @@ struct audio_cs_ep_ep_general_descriptor {
|
|||
|
||||
#define AUDIO_AS_DESCRIPTOR_INIT_LEN(n) (0x09 + 0x09 + 0x07 + 0x08 + 3 * n + 0x09 + 0x07)
|
||||
|
||||
#define AUDIO_AS_ALTSETTING_DESCRIPTOR_INIT(bInterfaceNumber, bAlternateSetting, bTerminalLink, bNrChannels, bSubFrameSize, bBitResolution, bEndpointAddress, bmAttributes, wMaxPacketSize, bInterval, ...) \
|
||||
0x09, /* bLength */ \
|
||||
USB_DESCRIPTOR_TYPE_INTERFACE, /* bDescriptorType */ \
|
||||
bInterfaceNumber, /* bInterfaceNumber */ \
|
||||
bAlternateSetting, /* bAlternateSetting */ \
|
||||
0x01, /* bNumEndpoints */ \
|
||||
USB_DEVICE_CLASS_AUDIO, /* bInterfaceClass */ \
|
||||
AUDIO_SUBCLASS_AUDIOSTREAMING, /* bInterfaceSubClass */ \
|
||||
AUDIO_PROTOCOL_UNDEFINED, /* bInterfaceProtocol */ \
|
||||
0x00, /* iInterface */ \
|
||||
0x07, /* bLength */ \
|
||||
AUDIO_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType */ \
|
||||
AUDIO_STREAMING_GENERAL, /* bDescriptorSubtype */ \
|
||||
bTerminalLink, /* bTerminalLink : Unit ID of the Output Terminal*/ \
|
||||
0x01, /* bDelay */ \
|
||||
WBVAL(AUDIO_FORMAT_PCM), /* wFormatTag : AUDIO_FORMAT_PCM */ \
|
||||
0x08 + PP_NARG(__VA_ARGS__), /* bLength */ \
|
||||
AUDIO_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType */ \
|
||||
AUDIO_STREAMING_FORMAT_TYPE, /* bDescriptorSubtype */ \
|
||||
AUDIO_FORMAT_TYPE_I, /* bFormatType */ \
|
||||
bNrChannels, /* bNrChannels */ \
|
||||
bSubFrameSize, /* bSubFrameSize : Bytes per audio subframe */ \
|
||||
bBitResolution, /* bBitResolution : bits per sample */ \
|
||||
(PP_NARG(__VA_ARGS__)/3), /* bSamFreqType : only one frequency supported */ \
|
||||
__VA_ARGS__, /* tSamFreq : Audio sampling frequency coded on 3 bytes */ \
|
||||
0x09, /* bLength */ \
|
||||
USB_DESCRIPTOR_TYPE_ENDPOINT, /* bDescriptorType */ \
|
||||
bEndpointAddress, /* bEndpointAddress : IN endpoint 1 */ \
|
||||
bmAttributes, /* bmAttributes */ \
|
||||
WBVAL(wMaxPacketSize), /* wMaxPacketSize */ \
|
||||
bInterval, /* bInterval : one packet per frame */ \
|
||||
0x00, /* bRefresh */ \
|
||||
0x00, /* bSynchAddress */ \
|
||||
0x07, /* bLength */ \
|
||||
AUDIO_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType */ \
|
||||
AUDIO_ENDPOINT_GENERAL, /* bDescriptor */ \
|
||||
AUDIO_EP_CONTROL_SAMPLING_FEQ, /* bmAttributes AUDIO_SAMPLING_FREQ_CONTROL */ \
|
||||
0x00, /* bLockDelayUnits */ \
|
||||
0x00, /* wLockDelay */ \
|
||||
0x00
|
||||
|
||||
#define AUDIO_AS_ALTSETTING_DESCRIPTOR_INIT_LEN(n) (0x09 + 0x07 + 0x08 + 3 * n + 0x09 + 0x07)
|
||||
|
||||
#define AUDIO_AS_ALTSETTING0_DESCRIPTOR_INIT(bInterfaceNumber) \
|
||||
0x09, /* bLength */ \
|
||||
USB_DESCRIPTOR_TYPE_INTERFACE, /* bDescriptorType */ \
|
||||
bInterfaceNumber, /* bInterfaceNumber */ \
|
||||
0x00, /* bAlternateSetting */ \
|
||||
0x01, /* bNumEndpoints */ \
|
||||
USB_DEVICE_CLASS_AUDIO, /* bInterfaceClass */ \
|
||||
AUDIO_SUBCLASS_AUDIOSTREAMING, /* bInterfaceSubClass */ \
|
||||
AUDIO_PROTOCOL_UNDEFINED, /* bInterfaceProtocol */ \
|
||||
0x00 /* iInterface */
|
||||
|
||||
#define AUDIO_MS_STANDARD_DESCRIPTOR_INIT(bInterfaceNumber, bNumEndpoints) \
|
||||
0x09, /* bLength */ \
|
||||
USB_DESCRIPTOR_TYPE_INTERFACE, /* bDescriptorType */ \
|
||||
|
@ -1096,6 +1150,58 @@ struct audio_v2_control_range3_param_block {
|
|||
0x00, /* wLockDelay */ \
|
||||
0x00
|
||||
|
||||
#define AUDIO_V2_AS_ALTSETTING_DESCRIPTOR_INIT(bInterfaceNumber, bAlternateSetting, bTerminalLink, bNrChannels, bmChannelConfig, bSubslotSize, bBitResolution, bEndpointAddress, bmAttributes, wMaxPacketSize, bInterval) \
|
||||
0x09, /* bLength */ \
|
||||
USB_DESCRIPTOR_TYPE_INTERFACE, /* bDescriptorType */ \
|
||||
bInterfaceNumber, /* bInterfaceNumber */ \
|
||||
bAlternateSetting, /* bAlternateSetting */ \
|
||||
0x01, /* bNumEndpoints */ \
|
||||
USB_DEVICE_CLASS_AUDIO, /* bInterfaceClass */ \
|
||||
AUDIO_SUBCLASS_AUDIOSTREAMING, /* bInterfaceSubClass */ \
|
||||
AUDIO_PROTOCOLv20, /* bInterfaceProtocol */ \
|
||||
0x00, /* iInterface */ \
|
||||
0x10, /* bLength */ \
|
||||
AUDIO_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType */ \
|
||||
AUDIO_STREAMING_GENERAL, /* bDescriptorSubtype */ \
|
||||
bTerminalLink, /* bTerminalLink : Unit ID of the Output or Input Terminal*/ \
|
||||
0x00, /* bmControls */ \
|
||||
AUDIO_FORMAT_TYPE_I, /* bFormatType : AUDIO_FORMAT_TYPE_I */ \
|
||||
DBVAL(AUDIO_V2_FORMAT_PCM), /* bmFormats PCM */ \
|
||||
bNrChannels, /* bNrChannels */ \
|
||||
DBVAL(bmChannelConfig), /* bmChannelConfig */ \
|
||||
0x00, /* iChannelNames */ \
|
||||
0x06, /* bLength */ \
|
||||
AUDIO_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType */ \
|
||||
AUDIO_STREAMING_FORMAT_TYPE, /* bDescriptorSubtype */ \
|
||||
AUDIO_FORMAT_TYPE_I, /* bFormatType */ \
|
||||
bSubslotSize, /* bSubslotSize */ \
|
||||
bBitResolution, /* bBitResolution */ \
|
||||
0x07, /* bLength */ \
|
||||
USB_DESCRIPTOR_TYPE_ENDPOINT, /* bDescriptorType */ \
|
||||
bEndpointAddress, /* bEndpointAddress 3 out endpoint for Audio */ \
|
||||
bmAttributes, /* bmAttributes */ \
|
||||
WBVAL(wMaxPacketSize), /* XXXX wMaxPacketSize in Bytes (SampleRate * SlotByteSize * NumChannels) */ \
|
||||
bInterval, /* bInterval */ \
|
||||
0x08, /* bLength */ \
|
||||
AUDIO_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType */ \
|
||||
AUDIO_ENDPOINT_GENERAL, /* bDescriptor */ \
|
||||
0x00, /* bmAttributes */ \
|
||||
0x00, /* bmControls */ \
|
||||
0x00, /* bLockDelayUnits */ \
|
||||
0x00, /* wLockDelay */ \
|
||||
0x00
|
||||
|
||||
#define AUDIO_V2_AS_ALTSETTING0_DESCRIPTOR_INIT(bInterfaceNumber) \
|
||||
0x09, /* bLength */ \
|
||||
USB_DESCRIPTOR_TYPE_INTERFACE, /* bDescriptorType */ \
|
||||
bInterfaceNumber, /* bInterfaceNumber */ \
|
||||
0x00, /* bAlternateSetting */ \
|
||||
0x01, /* bNumEndpoints */ \
|
||||
USB_DEVICE_CLASS_AUDIO, /* bInterfaceClass */ \
|
||||
AUDIO_SUBCLASS_AUDIOSTREAMING, /* bInterfaceSubClass */ \
|
||||
AUDIO_PROTOCOLv20, /* bInterfaceProtocol */ \
|
||||
0x00 /* iInterface */
|
||||
|
||||
#define AUDIO_V2_AS_FEEDBACK_DESCRIPTOR_INIT(bInterfaceNumber, bTerminalLink, bNrChannels, bmChannelConfig, bSubslotSize, bBitResolution, bEndpointAddress, wMaxPacketSize, bInterval, bFeedbackEndpointAddress) \
|
||||
0x09, /* bLength */ \
|
||||
USB_DESCRIPTOR_TYPE_INTERFACE, /* bDescriptorType */ \
|
||||
|
@ -1150,12 +1256,13 @@ struct audio_v2_control_range3_param_block {
|
|||
bFeedbackEndpointAddress, /* bFeedbackEndpointAddress Revise Dir to bEndpointAddress */ \
|
||||
0x11, /* bmAttributes: TransferType=Isochronous SyncType=None EndpointType=Feedback */ \
|
||||
WBVAL(4), /* XXXX wMaxPacketSize in Bytes */ \
|
||||
bInterval /* bInterval */ \
|
||||
bInterval /* bInterval */
|
||||
|
||||
// clang-format on
|
||||
|
||||
#define AUDIO_V2_AS_DESCRIPTOR_INIT_LEN (0x09 + 0x09 + 0x10 + 0x06 + 0x07 + 0x08)
|
||||
#define AUDIO_V2_AS_FEEDBACK_DESCRIPTOR_INIT_LEN (0x09 + 0x09 + 0x10 + 0x06 + 0x07 + 0x08 + 0x07)
|
||||
#define AUDIO_V2_AS_DESCRIPTOR_INIT_LEN (0x09 + 0x09 + 0x10 + 0x06 + 0x07 + 0x08)
|
||||
#define AUDIO_V2_AS_ALTSETTING_DESCRIPTOR_INIT_LEN (0x09 + 0x10 + 0x06 + 0x07 + 0x08)
|
||||
#define AUDIO_V2_AS_FEEDBACK_DESCRIPTOR_INIT_LEN (0x09 + 0x09 + 0x10 + 0x06 + 0x07 + 0x08 + 0x07)
|
||||
|
||||
#define AUDIO_SAMPLE_FREQ_NUM(num) (uint8_t)(num), (uint8_t)((num >> 8))
|
||||
#define AUDIO_SAMPLE_FREQ_3B(frq) (uint8_t)(frq), (uint8_t)((frq >> 8)), (uint8_t)((frq >> 16))
|
||||
|
|
|
@ -21,10 +21,6 @@
|
|||
#define INTF_DESC_bInterfaceNumber 2 /** Interface number offset */
|
||||
#define INTF_DESC_bAlternateSetting 3 /** Alternate setting offset */
|
||||
|
||||
#ifndef CONFIG_USBHOST_MAX_AUDIO_CLASS
|
||||
#define CONFIG_USBHOST_MAX_AUDIO_CLASS 4
|
||||
#endif
|
||||
|
||||
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_audio_buf[128];
|
||||
|
||||
static struct usbh_audio g_audio_class[CONFIG_USBHOST_MAX_AUDIO_CLASS];
|
||||
|
@ -32,11 +28,11 @@ static uint32_t g_devinuse = 0;
|
|||
|
||||
static struct usbh_audio *usbh_audio_class_alloc(void)
|
||||
{
|
||||
int devno;
|
||||
uint8_t devno;
|
||||
|
||||
for (devno = 0; devno < CONFIG_USBHOST_MAX_AUDIO_CLASS; devno++) {
|
||||
if ((g_devinuse & (1 << devno)) == 0) {
|
||||
g_devinuse |= (1 << devno);
|
||||
if ((g_devinuse & (1U << devno)) == 0) {
|
||||
g_devinuse |= (1U << devno);
|
||||
memset(&g_audio_class[devno], 0, sizeof(struct usbh_audio));
|
||||
g_audio_class[devno].minor = devno;
|
||||
return &g_audio_class[devno];
|
||||
|
@ -47,15 +43,15 @@ static struct usbh_audio *usbh_audio_class_alloc(void)
|
|||
|
||||
static void usbh_audio_class_free(struct usbh_audio *audio_class)
|
||||
{
|
||||
int devno = audio_class->minor;
|
||||
uint8_t devno = audio_class->minor;
|
||||
|
||||
if (devno >= 0 && devno < 32) {
|
||||
g_devinuse &= ~(1 << devno);
|
||||
if (devno < 32) {
|
||||
g_devinuse &= ~(1U << devno);
|
||||
}
|
||||
memset(audio_class, 0, sizeof(struct usbh_audio));
|
||||
}
|
||||
|
||||
int usbh_audio_open(struct usbh_audio *audio_class, const char *name, uint32_t samp_freq)
|
||||
int usbh_audio_open(struct usbh_audio *audio_class, const char *name, uint32_t samp_freq, uint8_t bitresolution)
|
||||
{
|
||||
struct usb_setup_packet *setup;
|
||||
struct usb_endpoint_descriptor *ep_desc;
|
||||
|
@ -74,20 +70,24 @@ int usbh_audio_open(struct usbh_audio *audio_class, const char *name, uint32_t s
|
|||
return 0;
|
||||
}
|
||||
|
||||
for (uint8_t i = 0; i < audio_class->module_num; i++) {
|
||||
if (strcmp(name, audio_class->module[i].name) == 0) {
|
||||
for (uint8_t j = 0; j < audio_class->num_of_intf_altsettings; j++) {
|
||||
for (uint8_t k = 0; k < audio_class->module[i].altsetting[j].sampfreq_num; k++) {
|
||||
if (audio_class->module[i].altsetting[j].sampfreq[k] == samp_freq) {
|
||||
intf = audio_class->module[i].data_intf;
|
||||
altsetting = j;
|
||||
goto freq_found;
|
||||
for (uint8_t i = 0; i < audio_class->stream_intf_num; i++) {
|
||||
if (strcmp(name, audio_class->as_msg_table[i].stream_name) == 0) {
|
||||
intf = audio_class->as_msg_table[i].stream_intf;
|
||||
for (uint8_t j = 1; j < audio_class->as_msg_table[i].num_of_altsetting; j++) {
|
||||
if (audio_class->as_msg_table[i].as_format[j].bBitResolution == bitresolution) {
|
||||
for (uint8_t k = 0; k < audio_class->as_msg_table[i].as_format[j].bSamFreqType; k++) {
|
||||
uint32_t freq = 0;
|
||||
|
||||
memcpy(&freq, &audio_class->as_msg_table[i].as_format[j].tSamFreq[3 * k], 3);
|
||||
if (freq == samp_freq) {
|
||||
altsetting = j;
|
||||
goto freq_found;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return -USB_ERR_NODEV;
|
||||
|
||||
freq_found:
|
||||
|
@ -105,16 +105,18 @@ freq_found:
|
|||
|
||||
ep_desc = &audio_class->hport->config.intf[intf].altsetting[altsetting].ep[0].ep_desc;
|
||||
|
||||
setup->bmRequestType = USB_REQUEST_DIR_OUT | USB_REQUEST_CLASS | USB_REQUEST_RECIPIENT_ENDPOINT;
|
||||
setup->bRequest = AUDIO_REQUEST_SET_CUR;
|
||||
setup->wValue = (AUDIO_EP_CONTROL_SAMPLING_FEQ << 8) | 0x00;
|
||||
setup->wIndex = ep_desc->bEndpointAddress;
|
||||
setup->wLength = 3;
|
||||
if (audio_class->as_msg_table[intf - audio_class->ctrl_intf - 1].ep_attr & AUDIO_EP_CONTROL_SAMPLING_FEQ) {
|
||||
setup->bmRequestType = USB_REQUEST_DIR_OUT | USB_REQUEST_CLASS | USB_REQUEST_RECIPIENT_ENDPOINT;
|
||||
setup->bRequest = AUDIO_REQUEST_SET_CUR;
|
||||
setup->wValue = (AUDIO_EP_CONTROL_SAMPLING_FEQ << 8) | 0x00;
|
||||
setup->wIndex = ep_desc->bEndpointAddress;
|
||||
setup->wLength = 3;
|
||||
|
||||
memcpy(g_audio_buf, &samp_freq, 3);
|
||||
ret = usbh_control_transfer(audio_class->hport, setup, g_audio_buf);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
memcpy(g_audio_buf, &samp_freq, 3);
|
||||
ret = usbh_control_transfer(audio_class->hport, setup, g_audio_buf);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
mult = (ep_desc->wMaxPacketSize & USB_MAXPACKETSIZE_ADDITIONAL_TRANSCATION_MASK) >> USB_MAXPACKETSIZE_ADDITIONAL_TRANSCATION_SHIFT;
|
||||
|
@ -127,7 +129,7 @@ freq_found:
|
|||
USBH_EP_INIT(audio_class->isoout, ep_desc);
|
||||
}
|
||||
|
||||
USB_LOG_INFO("Open audio module :%s, altsetting: %u\r\n", name, altsetting);
|
||||
USB_LOG_INFO("Open audio stream :%s, altsetting: %u\r\n", name, altsetting);
|
||||
audio_class->is_opened = true;
|
||||
return ret;
|
||||
}
|
||||
|
@ -145,9 +147,9 @@ int usbh_audio_close(struct usbh_audio *audio_class, const char *name)
|
|||
}
|
||||
setup = audio_class->hport->setup;
|
||||
|
||||
for (size_t i = 0; i < audio_class->module_num; i++) {
|
||||
if (strcmp(name, audio_class->module[i].name) == 0) {
|
||||
intf = audio_class->module[i].data_intf;
|
||||
for (uint8_t i = 0; i < audio_class->stream_intf_num; i++) {
|
||||
if (strcmp(name, audio_class->as_msg_table[i].stream_name) == 0) {
|
||||
intf = audio_class->as_msg_table[i].stream_intf;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -155,7 +157,17 @@ int usbh_audio_close(struct usbh_audio *audio_class, const char *name)
|
|||
return -USB_ERR_NODEV;
|
||||
}
|
||||
|
||||
USB_LOG_INFO("Close audio module :%s\r\n", name);
|
||||
setup->bmRequestType = USB_REQUEST_DIR_OUT | USB_REQUEST_STANDARD | USB_REQUEST_RECIPIENT_INTERFACE;
|
||||
setup->bRequest = USB_REQUEST_SET_INTERFACE;
|
||||
setup->wValue = 0;
|
||||
setup->wIndex = intf;
|
||||
setup->wLength = 0;
|
||||
|
||||
ret = usbh_control_transfer(audio_class->hport, setup, NULL);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
USB_LOG_INFO("Close audio stream :%s\r\n", name);
|
||||
audio_class->is_opened = false;
|
||||
|
||||
ep_desc = &audio_class->hport->config.intf[intf].altsetting[altsetting].ep[0].ep_desc;
|
||||
|
@ -169,14 +181,6 @@ int usbh_audio_close(struct usbh_audio *audio_class, const char *name)
|
|||
}
|
||||
}
|
||||
|
||||
setup->bmRequestType = USB_REQUEST_DIR_OUT | USB_REQUEST_STANDARD | USB_REQUEST_RECIPIENT_INTERFACE;
|
||||
setup->bRequest = USB_REQUEST_SET_INTERFACE;
|
||||
setup->wValue = 0;
|
||||
setup->wIndex = intf;
|
||||
setup->wLength = 0;
|
||||
|
||||
ret = usbh_control_transfer(audio_class->hport, setup, NULL);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -184,30 +188,29 @@ int usbh_audio_set_volume(struct usbh_audio *audio_class, const char *name, uint
|
|||
{
|
||||
struct usb_setup_packet *setup;
|
||||
int ret;
|
||||
uint8_t intf = 0xff;
|
||||
uint8_t feature_id = 0xff;
|
||||
uint16_t volume_hex;
|
||||
|
||||
if (!audio_class || !audio_class->hport) {
|
||||
return -USB_ERR_INVAL;
|
||||
}
|
||||
setup = audio_class->hport->setup;
|
||||
|
||||
for (size_t i = 0; i < audio_class->module_num; i++) {
|
||||
if (strcmp(name, audio_class->module[i].name) == 0) {
|
||||
intf = audio_class->ctrl_intf;
|
||||
feature_id = audio_class->module[i].feature_unit_id;
|
||||
}
|
||||
if (volume > 100) {
|
||||
return -USB_ERR_INVAL;
|
||||
}
|
||||
|
||||
if (intf == 0xff) {
|
||||
return -USB_ERR_NODEV;
|
||||
setup = audio_class->hport->setup;
|
||||
|
||||
for (uint8_t i = 0; i < audio_class->stream_intf_num; i++) {
|
||||
if (strcmp(name, audio_class->as_msg_table[i].stream_name) == 0) {
|
||||
feature_id = audio_class->as_msg_table[i].feature_terminal_id;
|
||||
}
|
||||
}
|
||||
|
||||
setup->bmRequestType = USB_REQUEST_DIR_OUT | USB_REQUEST_CLASS | USB_REQUEST_RECIPIENT_INTERFACE;
|
||||
setup->bRequest = AUDIO_REQUEST_SET_CUR;
|
||||
setup->wValue = (AUDIO_FU_CONTROL_VOLUME << 8) | ch;
|
||||
setup->wIndex = (feature_id << 8) | intf;
|
||||
setup->wIndex = (feature_id << 8) | audio_class->ctrl_intf;
|
||||
setup->wLength = 2;
|
||||
|
||||
volume_hex = -0xDB00 / 100 * volume + 0xdb00;
|
||||
|
@ -222,7 +225,6 @@ int usbh_audio_set_mute(struct usbh_audio *audio_class, const char *name, uint8_
|
|||
{
|
||||
struct usb_setup_packet *setup;
|
||||
int ret;
|
||||
uint8_t intf = 0xff;
|
||||
uint8_t feature_id = 0xff;
|
||||
|
||||
if (!audio_class || !audio_class->hport) {
|
||||
|
@ -230,21 +232,16 @@ int usbh_audio_set_mute(struct usbh_audio *audio_class, const char *name, uint8_
|
|||
}
|
||||
setup = audio_class->hport->setup;
|
||||
|
||||
for (size_t i = 0; i < audio_class->module_num; i++) {
|
||||
if (strcmp(name, audio_class->module[i].name) == 0) {
|
||||
intf = audio_class->ctrl_intf;
|
||||
feature_id = audio_class->module[i].feature_unit_id;
|
||||
for (uint8_t i = 0; i < audio_class->stream_intf_num; i++) {
|
||||
if (strcmp(name, audio_class->as_msg_table[i].stream_name) == 0) {
|
||||
feature_id = audio_class->as_msg_table[i].feature_terminal_id;
|
||||
}
|
||||
}
|
||||
|
||||
if (intf == 0xff) {
|
||||
return -USB_ERR_NODEV;
|
||||
}
|
||||
|
||||
setup->bmRequestType = USB_REQUEST_DIR_OUT | USB_REQUEST_CLASS | USB_REQUEST_RECIPIENT_INTERFACE;
|
||||
setup->bRequest = AUDIO_REQUEST_SET_CUR;
|
||||
setup->wValue = (AUDIO_FU_CONTROL_MUTE << 8) | ch;
|
||||
setup->wIndex = (feature_id << 8) | intf;
|
||||
setup->wIndex = (feature_id << 8) | audio_class->ctrl_intf;
|
||||
setup->wLength = 1;
|
||||
|
||||
memcpy(g_audio_buf, &mute, 1);
|
||||
|
@ -257,26 +254,28 @@ void usbh_audio_list_module(struct usbh_audio *audio_class)
|
|||
{
|
||||
USB_LOG_INFO("============= Audio module information ===================\r\n");
|
||||
USB_LOG_RAW("bcdADC :%04x\r\n", audio_class->bcdADC);
|
||||
USB_LOG_RAW("Num of modules :%u\r\n", audio_class->module_num);
|
||||
USB_LOG_RAW("Num of altsettings:%u\r\n", audio_class->num_of_intf_altsettings);
|
||||
USB_LOG_RAW("Num of audio stream :%u\r\n", audio_class->stream_intf_num);
|
||||
|
||||
for (uint8_t i = 0; i < audio_class->module_num; i++) {
|
||||
USB_LOG_RAW(" module name :%s\r\n", audio_class->module[i].name);
|
||||
USB_LOG_RAW(" module feature unit id :%d\r\n", audio_class->module[i].feature_unit_id);
|
||||
for (uint8_t i = 0; i < audio_class->stream_intf_num; i++) {
|
||||
USB_LOG_RAW("\tstream name :%s\r\n", audio_class->as_msg_table[i].stream_name);
|
||||
USB_LOG_RAW("\tstream intf :%u\r\n", audio_class->as_msg_table[i].stream_intf);
|
||||
USB_LOG_RAW("\tNum of altsetting :%u\r\n", audio_class->as_msg_table[i].num_of_altsetting);
|
||||
|
||||
for (uint8_t j = 0; j < audio_class->num_of_intf_altsettings; j++) {
|
||||
for (uint8_t j = 0; j < audio_class->as_msg_table[i].num_of_altsetting; j++) {
|
||||
if (j == 0) {
|
||||
USB_LOG_RAW(" Ingore altsetting 0\r\n");
|
||||
USB_LOG_RAW("\t\tIngore altsetting 0\r\n");
|
||||
continue;
|
||||
}
|
||||
USB_LOG_RAW(" Altsetting %u\r\n", j);
|
||||
USB_LOG_RAW(" module channels :%u\r\n", audio_class->module[i].altsetting[j].channels);
|
||||
//USB_LOG_RAW(" module format_type :%u\r\n",audio_class->module[i].altsetting[j].format_type);
|
||||
USB_LOG_RAW(" module bitresolution :%u\r\n", audio_class->module[i].altsetting[j].bitresolution);
|
||||
USB_LOG_RAW(" module sampfreq num :%u\r\n", audio_class->module[i].altsetting[j].sampfreq_num);
|
||||
USB_LOG_RAW("\t\tAltsetting :%u\r\n", j);
|
||||
USB_LOG_RAW("\t\t\tbNrChannels :%u\r\n", audio_class->as_msg_table[i].as_format[j].bNrChannels);
|
||||
USB_LOG_RAW("\t\t\tbBitResolution :%u\r\n", audio_class->as_msg_table[i].as_format[j].bBitResolution);
|
||||
USB_LOG_RAW("\t\t\tbSamFreqType :%u\r\n", audio_class->as_msg_table[i].as_format[j].bSamFreqType);
|
||||
|
||||
for (uint8_t k = 0; k < audio_class->module[i].altsetting[j].sampfreq_num; k++) {
|
||||
USB_LOG_RAW(" module sampfreq :%d hz\r\n", audio_class->module[i].altsetting[j].sampfreq[k]);
|
||||
for (uint8_t k = 0; k < audio_class->as_msg_table[i].as_format[j].bSamFreqType; k++) {
|
||||
uint32_t freq = 0;
|
||||
|
||||
memcpy(&freq, &audio_class->as_msg_table[i].as_format[j].tSamFreq[3 * k], 3);
|
||||
USB_LOG_RAW("\t\t\t\tSampleFreq :%u\r\n", freq);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -293,7 +292,6 @@ static int usbh_audio_ctrl_connect(struct usbh_hubport *hport, uint8_t intf)
|
|||
uint8_t input_offset = 0;
|
||||
uint8_t output_offset = 0;
|
||||
uint8_t feature_unit_offset = 0;
|
||||
uint8_t format_offset = 0;
|
||||
uint8_t *p;
|
||||
|
||||
struct usbh_audio *audio_class = usbh_audio_class_alloc();
|
||||
|
@ -304,8 +302,6 @@ static int usbh_audio_ctrl_connect(struct usbh_hubport *hport, uint8_t intf)
|
|||
|
||||
audio_class->hport = hport;
|
||||
audio_class->ctrl_intf = intf;
|
||||
audio_class->num_of_intf_altsettings = hport->config.intf[intf + 1].altsetting_num;
|
||||
|
||||
hport->config.intf[intf].priv = audio_class;
|
||||
|
||||
p = hport->raw_config_desc;
|
||||
|
@ -331,39 +327,19 @@ static int usbh_audio_ctrl_connect(struct usbh_hubport *hport, uint8_t intf)
|
|||
case AUDIO_CONTROL_INPUT_TERMINAL: {
|
||||
struct audio_cs_if_ac_input_terminal_descriptor *desc = (struct audio_cs_if_ac_input_terminal_descriptor *)p;
|
||||
|
||||
audio_class->module[input_offset].input_terminal_id = desc->bTerminalID;
|
||||
audio_class->module[input_offset].input_terminal_type = desc->wTerminalType;
|
||||
audio_class->module[input_offset].input_channel_config = desc->wChannelConfig;
|
||||
|
||||
if (desc->wTerminalType == AUDIO_TERMINAL_STREAMING) {
|
||||
audio_class->module[input_offset].terminal_link_id = desc->bTerminalID;
|
||||
}
|
||||
if (desc->wTerminalType == AUDIO_INTERM_MIC) {
|
||||
audio_class->module[input_offset].name = "mic";
|
||||
}
|
||||
memcpy(&audio_class->ac_msg_table[input_offset].ac_input, desc, sizeof(struct audio_cs_if_ac_input_terminal_descriptor));
|
||||
input_offset++;
|
||||
} break;
|
||||
break;
|
||||
case AUDIO_CONTROL_OUTPUT_TERMINAL: {
|
||||
struct audio_cs_if_ac_output_terminal_descriptor *desc = (struct audio_cs_if_ac_output_terminal_descriptor *)p;
|
||||
audio_class->module[output_offset].output_terminal_id = desc->bTerminalID;
|
||||
audio_class->module[output_offset].output_terminal_type = desc->wTerminalType;
|
||||
if (desc->wTerminalType == AUDIO_TERMINAL_STREAMING) {
|
||||
audio_class->module[output_offset].terminal_link_id = desc->bTerminalID;
|
||||
}
|
||||
if (desc->wTerminalType == AUDIO_OUTTERM_SPEAKER) {
|
||||
audio_class->module[output_offset].name = "speaker";
|
||||
}
|
||||
|
||||
memcpy(&audio_class->ac_msg_table[output_offset].ac_output, desc, sizeof(struct audio_cs_if_ac_output_terminal_descriptor));
|
||||
output_offset++;
|
||||
} break;
|
||||
case AUDIO_CONTROL_FEATURE_UNIT: {
|
||||
struct audio_cs_if_ac_feature_unit_descriptor *desc = (struct audio_cs_if_ac_feature_unit_descriptor *)p;
|
||||
audio_class->module[feature_unit_offset].feature_unit_id = desc->bUnitID;
|
||||
audio_class->module[feature_unit_offset].feature_unit_controlsize = desc->bControlSize;
|
||||
|
||||
for (uint8_t j = 0; j < desc->bControlSize; j++) {
|
||||
audio_class->module[feature_unit_offset].feature_unit_controls[j] = p[6 + j];
|
||||
}
|
||||
memcpy(&audio_class->ac_msg_table[feature_unit_offset].ac_feature_unit, desc, desc->bLength);
|
||||
feature_unit_offset++;
|
||||
} break;
|
||||
case AUDIO_CONTROL_PROCESSING_UNIT:
|
||||
|
@ -372,34 +348,33 @@ static int usbh_audio_ctrl_connect(struct usbh_hubport *hport, uint8_t intf)
|
|||
default:
|
||||
break;
|
||||
}
|
||||
} else if ((cur_iface < (audio_class->ctrl_intf + cur_iface_count)) && (cur_iface > audio_class->ctrl_intf)) {
|
||||
} else if ((cur_iface > audio_class->ctrl_intf) && (cur_iface < (audio_class->ctrl_intf + cur_iface_count))) {
|
||||
switch (p[DESC_bDescriptorSubType]) {
|
||||
case AUDIO_STREAMING_GENERAL:
|
||||
case AUDIO_STREAMING_GENERAL: {
|
||||
struct audio_cs_if_as_general_descriptor *desc = (struct audio_cs_if_as_general_descriptor *)p;
|
||||
|
||||
break;
|
||||
/* all altsetting have the same general */
|
||||
audio_class->as_msg_table[cur_iface - audio_class->ctrl_intf - 1].stream_intf = cur_iface;
|
||||
memcpy(&audio_class->as_msg_table[cur_iface - audio_class->ctrl_intf - 1].as_general, desc, sizeof(struct audio_cs_if_as_general_descriptor));
|
||||
} break;
|
||||
case AUDIO_STREAMING_FORMAT_TYPE: {
|
||||
struct audio_cs_if_as_format_type_descriptor *desc = (struct audio_cs_if_as_format_type_descriptor *)p;
|
||||
|
||||
audio_class->module[format_offset].data_intf = cur_iface;
|
||||
audio_class->module[format_offset].altsetting[cur_alt_setting].channels = desc->bNrChannels;
|
||||
audio_class->module[format_offset].altsetting[cur_alt_setting].format_type = desc->bFormatType;
|
||||
audio_class->module[format_offset].altsetting[cur_alt_setting].bitresolution = desc->bBitResolution;
|
||||
audio_class->module[format_offset].altsetting[cur_alt_setting].sampfreq_num = desc->bSamFreqType;
|
||||
|
||||
for (uint8_t j = 0; j < desc->bSamFreqType; j++) {
|
||||
audio_class->module[format_offset].altsetting[cur_alt_setting].sampfreq[j] = (uint32_t)(p[10 + j * 3] << 16) |
|
||||
(uint32_t)(p[9 + j * 3] << 8) |
|
||||
(uint32_t)(p[8 + j * 3] << 0);
|
||||
}
|
||||
if (cur_alt_setting == (hport->config.intf[intf + 1].altsetting_num - 1)) {
|
||||
format_offset++;
|
||||
}
|
||||
audio_class->as_msg_table[cur_iface - audio_class->ctrl_intf - 1].num_of_altsetting = (cur_alt_setting + 1);
|
||||
memcpy(&audio_class->as_msg_table[cur_iface - audio_class->ctrl_intf - 1].as_format[cur_alt_setting], desc, desc->bLength);
|
||||
} break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case AUDIO_ENDPOINT_DESCRIPTOR_TYPE:
|
||||
if ((cur_iface > audio_class->ctrl_intf) && (cur_iface < (audio_class->ctrl_intf + cur_iface_count))) {
|
||||
if (p[DESC_bDescriptorSubType] == AUDIO_ENDPOINT_GENERAL) {
|
||||
struct audio_cs_ep_ep_general_descriptor *desc = (struct audio_cs_ep_ep_general_descriptor *)p;
|
||||
audio_class->as_msg_table[cur_iface - audio_class->ctrl_intf - 1].ep_attr = desc->bmAttributes;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -407,16 +382,86 @@ static int usbh_audio_ctrl_connect(struct usbh_hubport *hport, uint8_t intf)
|
|||
p += p[DESC_bLength];
|
||||
}
|
||||
|
||||
if ((input_offset != output_offset) && (input_offset != feature_unit_offset) && (input_offset != format_offset)) {
|
||||
if ((input_offset != output_offset) && (input_offset != feature_unit_offset)) {
|
||||
USB_LOG_ERR("Audio descriptor is invalid\r\n");
|
||||
return -USB_ERR_INVAL;
|
||||
}
|
||||
|
||||
audio_class->module_num = input_offset;
|
||||
audio_class->stream_intf_num = input_offset;
|
||||
|
||||
for (size_t i = 0; i < audio_class->module_num; i++) {
|
||||
ret = usbh_audio_close(audio_class, audio_class->module[i].name);
|
||||
for (uint8_t i = 0; i < audio_class->stream_intf_num; i++) {
|
||||
/* Search 0x0101 in input or output desc */
|
||||
for (uint8_t streamidx = 0; streamidx < audio_class->stream_intf_num; streamidx++) {
|
||||
if (audio_class->as_msg_table[i].as_general.bTerminalLink == audio_class->ac_msg_table[streamidx].ac_input.bTerminalID) {
|
||||
/* INPUT --> FEATURE UNIT --> OUTPUT */
|
||||
audio_class->as_msg_table[i].input_terminal_id = audio_class->ac_msg_table[streamidx].ac_input.bTerminalID;
|
||||
|
||||
/* Search input terminal id in feature desc */
|
||||
for (uint8_t featureidx = 0; featureidx < audio_class->stream_intf_num; featureidx++) {
|
||||
if (audio_class->ac_msg_table[streamidx].ac_input.bTerminalID == audio_class->ac_msg_table[featureidx].ac_feature_unit.bSourceID) {
|
||||
audio_class->as_msg_table[i].feature_terminal_id = audio_class->ac_msg_table[featureidx].ac_feature_unit.bUnitID;
|
||||
|
||||
/* Search feature unit id in output desc */
|
||||
for (uint8_t outputid = 0; outputid < audio_class->stream_intf_num; outputid++) {
|
||||
if (audio_class->ac_msg_table[featureidx].ac_feature_unit.bUnitID == audio_class->ac_msg_table[outputid].ac_output.bSourceID) {
|
||||
audio_class->as_msg_table[i].output_terminal_id = audio_class->ac_msg_table[outputid].ac_output.bTerminalID;
|
||||
|
||||
switch (audio_class->ac_msg_table[outputid].ac_output.wTerminalType) {
|
||||
case AUDIO_OUTTERM_SPEAKER:
|
||||
audio_class->as_msg_table[i].stream_name = "speaker";
|
||||
break;
|
||||
case AUDIO_OUTTERM_HEADPHONES:
|
||||
audio_class->as_msg_table[i].stream_name = "headphoens";
|
||||
break;
|
||||
case AUDIO_OUTTERM_HEADDISPLAY:
|
||||
audio_class->as_msg_table[i].stream_name = "headdisplay";
|
||||
break;
|
||||
default:
|
||||
audio_class->as_msg_table[i].stream_name = "unknown";
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (audio_class->as_msg_table[i].as_general.bTerminalLink == audio_class->ac_msg_table[streamidx].ac_output.bTerminalID) {
|
||||
/* OUTPUT --> FEATURE UNIT --> INPUT */
|
||||
audio_class->as_msg_table[i].output_terminal_id = audio_class->ac_msg_table[streamidx].ac_output.bTerminalID;
|
||||
|
||||
/* Search output terminal id in feature desc */
|
||||
for (uint8_t featureidx = 0; featureidx < audio_class->stream_intf_num; featureidx++) {
|
||||
if (audio_class->ac_msg_table[streamidx].ac_output.bSourceID == audio_class->ac_msg_table[featureidx].ac_feature_unit.bUnitID) {
|
||||
audio_class->as_msg_table[i].feature_terminal_id = audio_class->ac_msg_table[featureidx].ac_feature_unit.bUnitID;
|
||||
|
||||
/* Search feature unit id in input desc */
|
||||
for (uint8_t inputid = 0; inputid < audio_class->stream_intf_num; inputid++) {
|
||||
if (audio_class->ac_msg_table[featureidx].ac_feature_unit.bSourceID == audio_class->ac_msg_table[inputid].ac_input.bTerminalID) {
|
||||
audio_class->as_msg_table[i].input_terminal_id = audio_class->ac_msg_table[inputid].ac_input.bTerminalID;
|
||||
|
||||
switch (audio_class->ac_msg_table[inputid].ac_input.wTerminalType) {
|
||||
case AUDIO_INTERM_MIC:
|
||||
audio_class->as_msg_table[i].stream_name = "mic";
|
||||
break;
|
||||
default:
|
||||
audio_class->as_msg_table[i].stream_name = "unknown";
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (uint8_t i = 0; i < audio_class->stream_intf_num; i++) {
|
||||
ret = usbh_audio_close(audio_class, audio_class->as_msg_table[i].stream_name);
|
||||
if (ret < 0) {
|
||||
USB_LOG_ERR("Fail to close audio module :%s\r\n", audio_class->module[i].name);
|
||||
USB_LOG_ERR("Fail to close audio stream :%s\r\n", audio_class->as_msg_table[i].stream_name);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,34 +8,26 @@
|
|||
|
||||
#include "usb_audio.h"
|
||||
|
||||
struct usbh_audio_format_type {
|
||||
uint8_t channels;
|
||||
uint8_t format_type;
|
||||
uint8_t bitresolution;
|
||||
uint8_t sampfreq_num;
|
||||
uint32_t sampfreq[3];
|
||||
#ifndef CONFIG_USBHOST_AUDIO_MAX_STREAMS
|
||||
#define CONFIG_USBHOST_AUDIO_MAX_STREAMS 3
|
||||
#endif
|
||||
|
||||
struct usbh_audio_ac_msg {
|
||||
struct audio_cs_if_ac_input_terminal_descriptor ac_input;
|
||||
struct audio_cs_if_ac_feature_unit_descriptor ac_feature_unit;
|
||||
struct audio_cs_if_ac_output_terminal_descriptor ac_output;
|
||||
};
|
||||
|
||||
/**
|
||||
* bSourceID in feature_unit = input_terminal_id
|
||||
* bSourceID in output_terminal = feature_unit_id
|
||||
* terminal_link_id = input_terminal_id or output_terminal_id (if input_terminal_type or output_terminal_type is 0x0101)
|
||||
*
|
||||
*
|
||||
*/
|
||||
struct usbh_audio_module {
|
||||
const char *name;
|
||||
uint8_t data_intf;
|
||||
struct usbh_audio_as_msg {
|
||||
const char *stream_name;
|
||||
uint8_t stream_intf;
|
||||
uint8_t input_terminal_id;
|
||||
uint16_t input_terminal_type;
|
||||
uint16_t input_channel_config;
|
||||
uint8_t feature_terminal_id;
|
||||
uint8_t output_terminal_id;
|
||||
uint16_t output_terminal_type;
|
||||
uint8_t feature_unit_id;
|
||||
uint8_t feature_unit_controlsize;
|
||||
uint8_t feature_unit_controls[8];
|
||||
uint8_t terminal_link_id;
|
||||
struct usbh_audio_format_type altsetting[CONFIG_USBHOST_MAX_INTF_ALTSETTINGS];
|
||||
uint8_t ep_attr;
|
||||
uint8_t num_of_altsetting;
|
||||
struct audio_cs_if_as_general_descriptor as_general;
|
||||
struct audio_cs_if_as_format_type_descriptor as_format[CONFIG_USBHOST_MAX_INTF_ALTSETTINGS];
|
||||
};
|
||||
|
||||
struct usbh_audio {
|
||||
|
@ -50,9 +42,9 @@ struct usbh_audio {
|
|||
bool is_opened;
|
||||
uint16_t bcdADC;
|
||||
uint8_t bInCollection;
|
||||
uint8_t num_of_intf_altsettings;
|
||||
struct usbh_audio_module module[2];
|
||||
uint8_t module_num;
|
||||
uint8_t stream_intf_num;
|
||||
struct usbh_audio_ac_msg ac_msg_table[CONFIG_USBHOST_AUDIO_MAX_STREAMS];
|
||||
struct usbh_audio_as_msg as_msg_table[CONFIG_USBHOST_AUDIO_MAX_STREAMS];
|
||||
|
||||
void *user_data;
|
||||
};
|
||||
|
@ -61,7 +53,7 @@ struct usbh_audio {
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
int usbh_audio_open(struct usbh_audio *audio_class, const char *name, uint32_t samp_freq);
|
||||
int usbh_audio_open(struct usbh_audio *audio_class, const char *name, uint32_t samp_freq, uint8_t bitresolution);
|
||||
int usbh_audio_close(struct usbh_audio *audio_class, const char *name);
|
||||
int usbh_audio_set_volume(struct usbh_audio *audio_class, const char *name, uint8_t ch, uint8_t volume);
|
||||
int usbh_audio_set_mute(struct usbh_audio *audio_class, const char *name, uint8_t ch, bool mute);
|
||||
|
|
|
@ -421,7 +421,7 @@ struct cdc_ncm_ndp16 {
|
|||
0x02, /* bInterfaceCount */ \
|
||||
USB_DEVICE_CLASS_CDC, /* bFunctionClass */ \
|
||||
CDC_ABSTRACT_CONTROL_MODEL, /* bFunctionSubClass */ \
|
||||
CDC_COMMON_PROTOCOL_AT_COMMANDS, /* bFunctionProtocol */ \
|
||||
CDC_COMMON_PROTOCOL_NONE, /* bFunctionProtocol */ \
|
||||
0x00, /* iFunction */ \
|
||||
0x09, /* bLength */ \
|
||||
USB_DESCRIPTOR_TYPE_INTERFACE, /* bDescriptorType */ \
|
||||
|
@ -430,7 +430,7 @@ struct cdc_ncm_ndp16 {
|
|||
0x01, /* bNumEndpoints */ \
|
||||
USB_DEVICE_CLASS_CDC, /* bInterfaceClass */ \
|
||||
CDC_ABSTRACT_CONTROL_MODEL, /* bInterfaceSubClass */ \
|
||||
CDC_COMMON_PROTOCOL_AT_COMMANDS, /* bInterfaceProtocol */ \
|
||||
CDC_COMMON_PROTOCOL_NONE, /* bInterfaceProtocol */ \
|
||||
str_idx, /* iInterface */ \
|
||||
0x05, /* bLength */ \
|
||||
CDC_CS_INTERFACE, /* bDescriptorType */ \
|
||||
|
@ -489,8 +489,8 @@ struct cdc_ncm_ndp16 {
|
|||
bFirstInterface, /* bFirstInterface */ \
|
||||
0x02, /* bInterfaceCount */ \
|
||||
USB_DEVICE_CLASS_WIRELESS, /* bFunctionClass */ \
|
||||
CDC_DIRECT_LINE_CONTROL_MODEL, /* bFunctionSubClass */ \
|
||||
CDC_COMMON_PROTOCOL_AT_COMMANDS_PCCA_101_AND_ANNEXO, /* bFunctionProtocol */ \
|
||||
0x01, /* bFunctionSubClass */ \
|
||||
0x03, /* bFunctionProtocol */ \
|
||||
0x00, /* iFunction */ \
|
||||
0x09, /* bLength */ \
|
||||
USB_DESCRIPTOR_TYPE_INTERFACE, /* bDescriptorType */ \
|
||||
|
@ -498,8 +498,8 @@ struct cdc_ncm_ndp16 {
|
|||
0x00, /* bAlternateSetting */ \
|
||||
0x01, /* bNumEndpoints */ \
|
||||
USB_DEVICE_CLASS_WIRELESS, /* bInterfaceClass */ \
|
||||
CDC_DIRECT_LINE_CONTROL_MODEL, /* bInterfaceSubClass */ \
|
||||
CDC_COMMON_PROTOCOL_AT_COMMANDS_PCCA_101_AND_ANNEXO, /* bInterfaceProtocol */ \
|
||||
0x01, /* bInterfaceSubClass */ \
|
||||
0x03, /* bInterfaceProtocol */ \
|
||||
str_idx, /* iInterface */ \
|
||||
0x05, /* bLength */ \
|
||||
CDC_CS_INTERFACE, /* bDescriptorType */ \
|
||||
|
|
|
@ -19,11 +19,11 @@ static uint32_t g_devinuse = 0;
|
|||
|
||||
static struct usbh_cdc_acm *usbh_cdc_acm_class_alloc(void)
|
||||
{
|
||||
int devno;
|
||||
uint8_t devno;
|
||||
|
||||
for (devno = 0; devno < CONFIG_USBHOST_MAX_CDC_ACM_CLASS; devno++) {
|
||||
if ((g_devinuse & (1 << devno)) == 0) {
|
||||
g_devinuse |= (1 << devno);
|
||||
if ((g_devinuse & (1U << devno)) == 0) {
|
||||
g_devinuse |= (1U << devno);
|
||||
memset(&g_cdc_acm_class[devno], 0, sizeof(struct usbh_cdc_acm));
|
||||
g_cdc_acm_class[devno].minor = devno;
|
||||
return &g_cdc_acm_class[devno];
|
||||
|
@ -34,10 +34,10 @@ static struct usbh_cdc_acm *usbh_cdc_acm_class_alloc(void)
|
|||
|
||||
static void usbh_cdc_acm_class_free(struct usbh_cdc_acm *cdc_acm_class)
|
||||
{
|
||||
int devno = cdc_acm_class->minor;
|
||||
uint8_t devno = cdc_acm_class->minor;
|
||||
|
||||
if (devno >= 0 && devno < 32) {
|
||||
g_devinuse &= ~(1 << devno);
|
||||
if (devno < 32) {
|
||||
g_devinuse &= ~(1U << devno);
|
||||
}
|
||||
memset(cdc_acm_class, 0, sizeof(struct usbh_cdc_acm));
|
||||
}
|
||||
|
@ -266,10 +266,10 @@ const struct usbh_class_driver cdc_data_class_driver = {
|
|||
};
|
||||
|
||||
CLASS_INFO_DEFINE const struct usbh_class_info cdc_acm_class_info = {
|
||||
.match_flags = USB_CLASS_MATCH_INTF_CLASS | USB_CLASS_MATCH_INTF_SUBCLASS | USB_CLASS_MATCH_INTF_PROTOCOL,
|
||||
.match_flags = USB_CLASS_MATCH_INTF_CLASS | USB_CLASS_MATCH_INTF_SUBCLASS,
|
||||
.class = USB_DEVICE_CLASS_CDC,
|
||||
.subclass = CDC_ABSTRACT_CONTROL_MODEL,
|
||||
.protocol = CDC_COMMON_PROTOCOL_AT_COMMANDS,
|
||||
.protocol = 0x00,
|
||||
.id_table = NULL,
|
||||
.class_driver = &cdc_acm_class_driver
|
||||
};
|
||||
|
|
|
@ -48,7 +48,7 @@ static int usbh_cdc_ncm_get_ntb_parameters(struct usbh_cdc_ncm *cdc_ncm_class, s
|
|||
setup->wLength = 28;
|
||||
|
||||
ret = usbh_control_transfer(cdc_ncm_class->hport, setup, g_cdc_ncm_buf);
|
||||
if (ret < 0) {
|
||||
if (ret < 8) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
@ -20,18 +20,18 @@
|
|||
#define INTF_DESC_bInterfaceNumber 2 /** Interface number offset */
|
||||
#define INTF_DESC_bAlternateSetting 3 /** Alternate setting offset */
|
||||
|
||||
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_hid_buf[CONFIG_USBHOST_MAX_HID_CLASS][USB_ALIGN_UP(256, CONFIG_USB_ALIGN_SIZE)];
|
||||
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_hid_buf[CONFIG_USBHOST_MAX_HID_CLASS][USB_ALIGN_UP(64, CONFIG_USB_ALIGN_SIZE)];
|
||||
|
||||
static struct usbh_hid g_hid_class[CONFIG_USBHOST_MAX_HID_CLASS];
|
||||
static uint32_t g_devinuse = 0;
|
||||
|
||||
static struct usbh_hid *usbh_hid_class_alloc(void)
|
||||
{
|
||||
int devno;
|
||||
uint8_t devno;
|
||||
|
||||
for (devno = 0; devno < CONFIG_USBHOST_MAX_HID_CLASS; devno++) {
|
||||
if ((g_devinuse & (1 << devno)) == 0) {
|
||||
g_devinuse |= (1 << devno);
|
||||
if ((g_devinuse & (1U << devno)) == 0) {
|
||||
g_devinuse |= (1U << devno);
|
||||
memset(&g_hid_class[devno], 0, sizeof(struct usbh_hid));
|
||||
g_hid_class[devno].minor = devno;
|
||||
return &g_hid_class[devno];
|
||||
|
@ -42,18 +42,17 @@ static struct usbh_hid *usbh_hid_class_alloc(void)
|
|||
|
||||
static void usbh_hid_class_free(struct usbh_hid *hid_class)
|
||||
{
|
||||
int devno = hid_class->minor;
|
||||
uint8_t devno = hid_class->minor;
|
||||
|
||||
if (devno >= 0 && devno < 32) {
|
||||
g_devinuse &= ~(1 << devno);
|
||||
if (devno < 32) {
|
||||
g_devinuse &= ~(1U << devno);
|
||||
}
|
||||
memset(hid_class, 0, sizeof(struct usbh_hid));
|
||||
}
|
||||
|
||||
static int usbh_hid_get_report_descriptor(struct usbh_hid *hid_class, uint8_t *buffer)
|
||||
int usbh_hid_get_report_descriptor(struct usbh_hid *hid_class, uint8_t *buffer, uint32_t buflen)
|
||||
{
|
||||
struct usb_setup_packet *setup;
|
||||
int ret;
|
||||
|
||||
if (!hid_class || !hid_class->hport) {
|
||||
return -USB_ERR_INVAL;
|
||||
|
@ -64,14 +63,9 @@ static int usbh_hid_get_report_descriptor(struct usbh_hid *hid_class, uint8_t *b
|
|||
setup->bRequest = USB_REQUEST_GET_DESCRIPTOR;
|
||||
setup->wValue = HID_DESCRIPTOR_TYPE_HID_REPORT << 8;
|
||||
setup->wIndex = hid_class->intf;
|
||||
setup->wLength = hid_class->report_size;
|
||||
setup->wLength = buflen;
|
||||
|
||||
ret = usbh_control_transfer(hid_class->hport, setup, g_hid_buf[hid_class->minor]);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
memcpy(buffer, g_hid_buf[hid_class->minor], ret - 8);
|
||||
return ret;
|
||||
return usbh_control_transfer(hid_class->hport, setup, buffer);
|
||||
}
|
||||
|
||||
int usbh_hid_set_idle(struct usbh_hid *hid_class, uint8_t report_id, uint8_t duration)
|
||||
|
@ -109,7 +103,7 @@ int usbh_hid_get_idle(struct usbh_hid *hid_class, uint8_t *buffer)
|
|||
setup->wLength = 1;
|
||||
|
||||
ret = usbh_control_transfer(hid_class->hport, setup, g_hid_buf[hid_class->minor]);
|
||||
if (ret < 0) {
|
||||
if (ret < 8) {
|
||||
return ret;
|
||||
}
|
||||
memcpy(buffer, g_hid_buf[hid_class->minor], ret - 8);
|
||||
|
@ -169,7 +163,7 @@ int usbh_hid_get_report(struct usbh_hid *hid_class, uint8_t report_type, uint8_t
|
|||
setup->wLength = buflen;
|
||||
|
||||
ret = usbh_control_transfer(hid_class->hport, setup, g_hid_buf[hid_class->minor]);
|
||||
if (ret < 0) {
|
||||
if (ret < 8) {
|
||||
return ret;
|
||||
}
|
||||
memcpy(buffer, g_hid_buf[hid_class->minor], ret - 8);
|
||||
|
@ -215,11 +209,6 @@ int usbh_hid_connect(struct usbh_hubport *hport, uint8_t intf)
|
|||
}
|
||||
|
||||
hid_class->report_size = desc->subdesc[0].wDescriptorLength;
|
||||
|
||||
if (hid_class->report_size > sizeof(g_hid_buf[hid_class->minor])) {
|
||||
USB_LOG_ERR("HID report descriptor too large\r\n");
|
||||
return -USB_ERR_INVAL;
|
||||
}
|
||||
found = true;
|
||||
goto found;
|
||||
}
|
||||
|
@ -247,7 +236,8 @@ found:
|
|||
USB_LOG_WRN("Do not support set idle\r\n");
|
||||
}
|
||||
|
||||
ret = usbh_hid_get_report_descriptor(hid_class, hid_class->report_desc);
|
||||
/* We read report desc but do nothing (because of too much memory usage for parsing report desc, parsed by users) */
|
||||
ret = usbh_hid_get_report_descriptor(hid_class, g_hid_buf[hid_class->minor], MIN(sizeof(g_hid_buf[hid_class->minor]), hid_class->report_size));
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -15,7 +15,6 @@ struct usbh_hid {
|
|||
struct usbh_urb intin_urb; /* INTR IN urb */
|
||||
struct usbh_urb intout_urb; /* INTR OUT urb */
|
||||
|
||||
uint8_t report_desc[256];
|
||||
uint16_t report_size;
|
||||
|
||||
uint8_t protocol;
|
||||
|
@ -29,6 +28,7 @@ struct usbh_hid {
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
int usbh_hid_get_report_descriptor(struct usbh_hid *hid_class, uint8_t *buffer, uint32_t buflen);
|
||||
int usbh_hid_set_idle(struct usbh_hid *hid_class, uint8_t report_id, uint8_t duration);
|
||||
int usbh_hid_get_idle(struct usbh_hid *hid_class, uint8_t *buffer);
|
||||
int usbh_hid_set_report(struct usbh_hid *hid_class, uint8_t report_type, uint8_t report_id, uint8_t *buffer, uint32_t buflen);
|
||||
|
|
|
@ -33,11 +33,11 @@ static uint32_t g_devinuse = 0;
|
|||
|
||||
static struct usbh_hub *usbh_hub_class_alloc(void)
|
||||
{
|
||||
int devno;
|
||||
uint8_t devno;
|
||||
|
||||
for (devno = 0; devno < CONFIG_USBHOST_MAX_EXTHUBS; devno++) {
|
||||
if ((g_devinuse & (1 << devno)) == 0) {
|
||||
g_devinuse |= (1 << devno);
|
||||
if ((g_devinuse & (1U << devno)) == 0) {
|
||||
g_devinuse |= (1U << devno);
|
||||
memset(&g_hub_class[devno], 0, sizeof(struct usbh_hub));
|
||||
g_hub_class[devno].index = EXTHUB_FIRST_INDEX + devno;
|
||||
return &g_hub_class[devno];
|
||||
|
@ -48,10 +48,10 @@ static struct usbh_hub *usbh_hub_class_alloc(void)
|
|||
|
||||
static void usbh_hub_class_free(struct usbh_hub *hub_class)
|
||||
{
|
||||
int devno = hub_class->index - EXTHUB_FIRST_INDEX;
|
||||
uint8_t devno = hub_class->index - EXTHUB_FIRST_INDEX;
|
||||
|
||||
if (devno >= 0 && devno < 32) {
|
||||
g_devinuse &= ~(1 << devno);
|
||||
if (devno < 32) {
|
||||
g_devinuse &= ~(1U << devno);
|
||||
}
|
||||
memset(hub_class, 0, sizeof(struct usbh_hub));
|
||||
}
|
||||
|
|
|
@ -109,7 +109,7 @@ void msc_storage_notify_handler(uint8_t busid, uint8_t event, void *arg)
|
|||
if (g_usbd_msc[busid].usbd_msc_mq == NULL) {
|
||||
USB_LOG_ERR("No memory to alloc for g_usbd_msc[busid].usbd_msc_mq\r\n");
|
||||
}
|
||||
g_usbd_msc[busid].usbd_msc_thread = usb_osal_thread_create("usbd_msc", CONFIG_USBDEV_MSC_STACKSIZE, CONFIG_USBDEV_MSC_PRIO, usbdev_msc_thread, (void *)busid);
|
||||
g_usbd_msc[busid].usbd_msc_thread = usb_osal_thread_create("usbd_msc", CONFIG_USBDEV_MSC_STACKSIZE, CONFIG_USBDEV_MSC_PRIO, usbdev_msc_thread, (void *)(uint32_t)busid);
|
||||
if (g_usbd_msc[busid].usbd_msc_thread == NULL) {
|
||||
USB_LOG_ERR("No memory to alloc for g_usbd_msc[busid].usbd_msc_thread\r\n");
|
||||
}
|
||||
|
@ -915,7 +915,7 @@ static void usbdev_msc_thread(void *argument)
|
|||
{
|
||||
uintptr_t event;
|
||||
int ret;
|
||||
uint8_t busid = (uint8_t)argument;
|
||||
uint8_t busid = (uint8_t)(uint32_t)argument;
|
||||
|
||||
while (1) {
|
||||
ret = usb_osal_mq_recv(g_usbd_msc[busid].usbd_msc_mq, (uintptr_t *)&event, USB_OSAL_WAITING_FOREVER);
|
||||
|
@ -977,9 +977,9 @@ struct usbd_interface *usbd_msc_init_intf(uint8_t busid, struct usbd_interface *
|
|||
for (uint8_t i = 0u; i <= g_usbd_msc[busid].max_lun; i++) {
|
||||
usbd_msc_get_cap(busid, i, &g_usbd_msc[busid].scsi_blk_nbr[i], &g_usbd_msc[busid].scsi_blk_size[i]);
|
||||
|
||||
if (g_usbd_msc[busid].scsi_blk_size[i] > CONFIG_USBDEV_MSC_MAX_BUFSIZE) {
|
||||
USB_LOG_ERR("msc block buffer overflow\r\n");
|
||||
return NULL;
|
||||
if (CONFIG_USBDEV_MSC_MAX_BUFSIZE % g_usbd_msc[busid].scsi_blk_size[i]) {
|
||||
USB_LOG_ERR("CONFIG_USBDEV_MSC_MAX_BUFSIZE must be a multiple of block size\r\n");
|
||||
while(1){}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -23,11 +23,11 @@ static struct usbh_msc_modeswitch_config *g_msc_modeswitch_config = NULL;
|
|||
|
||||
static struct usbh_msc *usbh_msc_class_alloc(void)
|
||||
{
|
||||
int devno;
|
||||
uint8_t devno;
|
||||
|
||||
for (devno = 0; devno < CONFIG_USBHOST_MAX_MSC_CLASS; devno++) {
|
||||
if ((g_devinuse & (1 << devno)) == 0) {
|
||||
g_devinuse |= (1 << devno);
|
||||
if ((g_devinuse & (1U << devno)) == 0) {
|
||||
g_devinuse |= (1U << devno);
|
||||
memset(&g_msc_class[devno], 0, sizeof(struct usbh_msc));
|
||||
g_msc_class[devno].sdchar = 'a' + devno;
|
||||
return &g_msc_class[devno];
|
||||
|
@ -38,10 +38,10 @@ static struct usbh_msc *usbh_msc_class_alloc(void)
|
|||
|
||||
static void usbh_msc_class_free(struct usbh_msc *msc_class)
|
||||
{
|
||||
int devno = msc_class->sdchar - 'a';
|
||||
uint8_t devno = msc_class->sdchar - 'a';
|
||||
|
||||
if (devno >= 0 && devno < 32) {
|
||||
g_devinuse &= ~(1 << devno);
|
||||
if (devno < 32) {
|
||||
g_devinuse &= ~(1U << devno);
|
||||
}
|
||||
memset(msc_class, 0, sizeof(struct usbh_msc));
|
||||
}
|
||||
|
@ -278,7 +278,12 @@ static int usbh_msc_connect(struct usbh_hubport *hport, uint8_t intf)
|
|||
|
||||
ret = usbh_msc_get_maxlun(msc_class, g_msc_buf[msc_class->sdchar - 'a']);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
if (ret == -USB_ERR_STALL) {
|
||||
USB_LOG_WRN("Device does not support multiple LUNs\r\n");
|
||||
g_msc_buf[msc_class->sdchar - 'a'][0] = 0;
|
||||
} else {
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
USB_LOG_INFO("Get max LUN:%u\r\n", g_msc_buf[msc_class->sdchar - 'a'][0] + 1);
|
||||
|
@ -372,7 +377,6 @@ static int usbh_msc_disconnect(struct usbh_hubport *hport, uint8_t intf)
|
|||
return ret;
|
||||
}
|
||||
|
||||
|
||||
int usbh_msc_scsi_write10(struct usbh_msc *msc_class, uint32_t start_sector, const uint8_t *buffer, uint32_t nsectors)
|
||||
{
|
||||
struct CBW *cbw;
|
||||
|
|
|
@ -9,11 +9,11 @@ static uint32_t g_devinuse = 0;
|
|||
|
||||
static struct usbh_xxx *usbh_xxx_class_alloc(void)
|
||||
{
|
||||
int devno;
|
||||
uint8_t devno;
|
||||
|
||||
for (devno = 0; devno < CONFIG_USBHOST_MAX_CUSTOM_CLASS; devno++) {
|
||||
if ((g_devinuse & (1 << devno)) == 0) {
|
||||
g_devinuse |= (1 << devno);
|
||||
if ((g_devinuse & (1U << devno)) == 0) {
|
||||
g_devinuse |= (1U << devno);
|
||||
memset(&g_xxx_class[devno], 0, sizeof(struct usbh_xxx));
|
||||
g_xxx_class[devno].minor = devno;
|
||||
return &g_xxx_class[devno];
|
||||
|
@ -24,10 +24,10 @@ static struct usbh_xxx *usbh_xxx_class_alloc(void)
|
|||
|
||||
static void usbh_xxx_class_free(struct usbh_xxx *xxx_class)
|
||||
{
|
||||
int devno = xxx_class->minor;
|
||||
uint8_t devno = xxx_class->minor;
|
||||
|
||||
if (devno >= 0 && devno < 32) {
|
||||
g_devinuse &= ~(1 << devno);
|
||||
if (devno < 32) {
|
||||
g_devinuse &= ~(1U << devno);
|
||||
}
|
||||
memset(xxx_class, 0, sizeof(struct usbh_xxx));
|
||||
}
|
||||
|
|
|
@ -70,7 +70,7 @@ static int usbh_asix_read_cmd(struct usbh_asix *asix_class,
|
|||
setup->wLength = size;
|
||||
|
||||
ret = usbh_control_transfer(asix_class->hport, setup, g_asix_buf);
|
||||
if (ret < 0) {
|
||||
if (ret < 8) {
|
||||
return ret;
|
||||
}
|
||||
memcpy(data, g_asix_buf, ret - 8);
|
||||
|
@ -98,9 +98,12 @@ static int usbh_asix_write_cmd(struct usbh_asix *asix_class,
|
|||
setup->wIndex = index;
|
||||
setup->wLength = size;
|
||||
|
||||
memcpy(g_asix_buf, data, size);
|
||||
|
||||
return usbh_control_transfer(asix_class->hport, setup, g_asix_buf);
|
||||
if (data && size) {
|
||||
memcpy(g_asix_buf, data, size);
|
||||
return usbh_control_transfer(asix_class->hport, setup, g_asix_buf);
|
||||
} else {
|
||||
return usbh_control_transfer(asix_class->hport, setup, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
static int usbh_asix_mdio_write(struct usbh_asix *asix_class, int phy_id, int loc, int val)
|
||||
|
|
|
@ -961,7 +961,7 @@ static int usbh_rtl8152_read_regs(struct usbh_rtl8152 *rtl8152_class,
|
|||
setup->wLength = size;
|
||||
|
||||
ret = usbh_control_transfer(rtl8152_class->hport, setup, g_rtl8152_buf);
|
||||
if (ret < 0) {
|
||||
if (ret < 8) {
|
||||
return ret;
|
||||
}
|
||||
memcpy(data, g_rtl8152_buf, ret - 8);
|
||||
|
@ -997,9 +997,10 @@ static int generic_ocp_read(struct usbh_rtl8152 *tp, uint16_t index, uint16_t si
|
|||
{
|
||||
uint16_t limit = 64;
|
||||
int ret = 0;
|
||||
uint8_t *buf = data;
|
||||
|
||||
/* both size and indix must be 4 bytes align */
|
||||
if ((size & 3) || !size || (index & 3) || !data)
|
||||
if ((size & 3) || !size || (index & 3) || !buf)
|
||||
return -USB_ERR_INVAL;
|
||||
|
||||
if ((uint32_t)index + (uint32_t)size > 0xffff)
|
||||
|
@ -1007,20 +1008,20 @@ static int generic_ocp_read(struct usbh_rtl8152 *tp, uint16_t index, uint16_t si
|
|||
|
||||
while (size) {
|
||||
if (size > limit) {
|
||||
ret = usbh_rtl8152_read_regs(tp, index, type, limit, data);
|
||||
ret = usbh_rtl8152_read_regs(tp, index, type, limit, buf);
|
||||
if (ret < 0)
|
||||
break;
|
||||
|
||||
index += limit;
|
||||
data += limit;
|
||||
buf += limit;
|
||||
size -= limit;
|
||||
} else {
|
||||
ret = usbh_rtl8152_read_regs(tp, index, type, size, data);
|
||||
ret = usbh_rtl8152_read_regs(tp, index, type, size, buf);
|
||||
if (ret < 0)
|
||||
break;
|
||||
|
||||
index += size;
|
||||
data += size;
|
||||
buf += size;
|
||||
size = 0;
|
||||
break;
|
||||
}
|
||||
|
@ -1035,9 +1036,10 @@ static int generic_ocp_write(struct usbh_rtl8152 *tp, uint16_t index, uint16_t b
|
|||
int ret;
|
||||
uint16_t byteen_start, byteen_end, byen;
|
||||
uint16_t limit = 512;
|
||||
uint8_t *buf = data;
|
||||
|
||||
/* both size and indix must be 4 bytes align */
|
||||
if ((size & 3) || !size || (index & 3) || !data)
|
||||
if ((size & 3) || !size || (index & 3) || !buf)
|
||||
return -USB_ERR_INVAL;
|
||||
|
||||
if ((uint32_t)index + (uint32_t)size > 0xffff)
|
||||
|
@ -1050,12 +1052,12 @@ static int generic_ocp_write(struct usbh_rtl8152 *tp, uint16_t index, uint16_t b
|
|||
|
||||
/* Split the first DWORD if the byte_en is not 0xff */
|
||||
if (byen != BYTE_EN_DWORD) {
|
||||
ret = usbh_rtl8152_write_regs(tp, index, type | byen, 4, data);
|
||||
ret = usbh_rtl8152_write_regs(tp, index, type | byen, 4, buf);
|
||||
if (ret < 0)
|
||||
goto error1;
|
||||
|
||||
index += 4;
|
||||
data += 4;
|
||||
buf += 4;
|
||||
size -= 4;
|
||||
}
|
||||
|
||||
|
@ -1070,22 +1072,22 @@ static int generic_ocp_write(struct usbh_rtl8152 *tp, uint16_t index, uint16_t b
|
|||
if (size > limit) {
|
||||
ret = usbh_rtl8152_write_regs(tp, index,
|
||||
type | BYTE_EN_DWORD,
|
||||
limit, data);
|
||||
limit, buf);
|
||||
if (ret < 0)
|
||||
goto error1;
|
||||
|
||||
index += limit;
|
||||
data += limit;
|
||||
buf += limit;
|
||||
size -= limit;
|
||||
} else {
|
||||
ret = usbh_rtl8152_write_regs(tp, index,
|
||||
type | BYTE_EN_DWORD,
|
||||
size, data);
|
||||
size, buf);
|
||||
if (ret < 0)
|
||||
goto error1;
|
||||
|
||||
index += size;
|
||||
data += size;
|
||||
buf += size;
|
||||
size = 0;
|
||||
break;
|
||||
}
|
||||
|
@ -1093,7 +1095,7 @@ static int generic_ocp_write(struct usbh_rtl8152 *tp, uint16_t index, uint16_t b
|
|||
|
||||
/* Set the last DWORD */
|
||||
if (byen != BYTE_EN_DWORD)
|
||||
ret = usbh_rtl8152_write_regs(tp, index, type | byen, 4, data);
|
||||
ret = usbh_rtl8152_write_regs(tp, index, type | byen, 4, buf);
|
||||
}
|
||||
|
||||
error1:
|
||||
|
|
|
@ -17,11 +17,11 @@ static uint32_t g_devinuse = 0;
|
|||
|
||||
static struct usbh_ch34x *usbh_ch34x_class_alloc(void)
|
||||
{
|
||||
int devno;
|
||||
uint8_t devno;
|
||||
|
||||
for (devno = 0; devno < CONFIG_USBHOST_MAX_CP210X_CLASS; devno++) {
|
||||
if ((g_devinuse & (1 << devno)) == 0) {
|
||||
g_devinuse |= (1 << devno);
|
||||
if ((g_devinuse & (1U << devno)) == 0) {
|
||||
g_devinuse |= (1U << devno);
|
||||
memset(&g_ch34x_class[devno], 0, sizeof(struct usbh_ch34x));
|
||||
g_ch34x_class[devno].minor = devno;
|
||||
return &g_ch34x_class[devno];
|
||||
|
@ -32,10 +32,10 @@ static struct usbh_ch34x *usbh_ch34x_class_alloc(void)
|
|||
|
||||
static void usbh_ch34x_class_free(struct usbh_ch34x *ch34x_class)
|
||||
{
|
||||
int devno = ch34x_class->minor;
|
||||
uint8_t devno = ch34x_class->minor;
|
||||
|
||||
if (devno >= 0 && devno < 32) {
|
||||
g_devinuse &= ~(1 << devno);
|
||||
if (devno < 32) {
|
||||
g_devinuse &= ~(1U << devno);
|
||||
}
|
||||
memset(ch34x_class, 0, sizeof(struct usbh_ch34x));
|
||||
}
|
||||
|
|
|
@ -17,11 +17,11 @@ static uint32_t g_devinuse = 0;
|
|||
|
||||
static struct usbh_cp210x *usbh_cp210x_class_alloc(void)
|
||||
{
|
||||
int devno;
|
||||
uint8_t devno;
|
||||
|
||||
for (devno = 0; devno < CONFIG_USBHOST_MAX_CP210X_CLASS; devno++) {
|
||||
if ((g_devinuse & (1 << devno)) == 0) {
|
||||
g_devinuse |= (1 << devno);
|
||||
if ((g_devinuse & (1U << devno)) == 0) {
|
||||
g_devinuse |= (1U << devno);
|
||||
memset(&g_cp210x_class[devno], 0, sizeof(struct usbh_cp210x));
|
||||
g_cp210x_class[devno].minor = devno;
|
||||
return &g_cp210x_class[devno];
|
||||
|
@ -32,10 +32,10 @@ static struct usbh_cp210x *usbh_cp210x_class_alloc(void)
|
|||
|
||||
static void usbh_cp210x_class_free(struct usbh_cp210x *cp210x_class)
|
||||
{
|
||||
int devno = cp210x_class->minor;
|
||||
uint8_t devno = cp210x_class->minor;
|
||||
|
||||
if (devno >= 0 && devno < 32) {
|
||||
g_devinuse &= ~(1 << devno);
|
||||
if (devno < 32) {
|
||||
g_devinuse &= ~(1U << devno);
|
||||
}
|
||||
memset(cp210x_class, 0, sizeof(struct usbh_cp210x));
|
||||
}
|
||||
|
|
|
@ -17,11 +17,11 @@ static uint32_t g_devinuse = 0;
|
|||
|
||||
static struct usbh_ftdi *usbh_ftdi_class_alloc(void)
|
||||
{
|
||||
int devno;
|
||||
uint8_t devno;
|
||||
|
||||
for (devno = 0; devno < CONFIG_USBHOST_MAX_FTDI_CLASS; devno++) {
|
||||
if ((g_devinuse & (1 << devno)) == 0) {
|
||||
g_devinuse |= (1 << devno);
|
||||
if ((g_devinuse & (1U << devno)) == 0) {
|
||||
g_devinuse |= (1U << devno);
|
||||
memset(&g_ftdi_class[devno], 0, sizeof(struct usbh_ftdi));
|
||||
g_ftdi_class[devno].minor = devno;
|
||||
return &g_ftdi_class[devno];
|
||||
|
@ -32,10 +32,10 @@ static struct usbh_ftdi *usbh_ftdi_class_alloc(void)
|
|||
|
||||
static void usbh_ftdi_class_free(struct usbh_ftdi *ftdi_class)
|
||||
{
|
||||
int devno = ftdi_class->minor;
|
||||
uint8_t devno = ftdi_class->minor;
|
||||
|
||||
if (devno >= 0 && devno < 32) {
|
||||
g_devinuse &= ~(1 << devno);
|
||||
if (devno < 32) {
|
||||
g_devinuse &= ~(1U << devno);
|
||||
}
|
||||
memset(ftdi_class, 0, sizeof(struct usbh_ftdi));
|
||||
}
|
||||
|
|
|
@ -25,11 +25,11 @@ static uint32_t g_devinuse = 0;
|
|||
|
||||
static struct usbh_pl2303 *usbh_pl2303_class_alloc(void)
|
||||
{
|
||||
int devno;
|
||||
uint8_t devno;
|
||||
|
||||
for (devno = 0; devno < CONFIG_USBHOST_MAX_PL2303_CLASS; devno++) {
|
||||
if ((g_devinuse & (1 << devno)) == 0) {
|
||||
g_devinuse |= (1 << devno);
|
||||
if ((g_devinuse & (1U << devno)) == 0) {
|
||||
g_devinuse |= (1U << devno);
|
||||
memset(&g_pl2303_class[devno], 0, sizeof(struct usbh_pl2303));
|
||||
g_pl2303_class[devno].minor = devno;
|
||||
return &g_pl2303_class[devno];
|
||||
|
@ -40,10 +40,10 @@ static struct usbh_pl2303 *usbh_pl2303_class_alloc(void)
|
|||
|
||||
static void usbh_pl2303_class_free(struct usbh_pl2303 *pl2303_class)
|
||||
{
|
||||
int devno = pl2303_class->minor;
|
||||
uint8_t devno = pl2303_class->minor;
|
||||
|
||||
if (devno >= 0 && devno < 32) {
|
||||
g_devinuse &= ~(1 << devno);
|
||||
if (devno < 32) {
|
||||
g_devinuse &= ~(1U << devno);
|
||||
}
|
||||
memset(pl2303_class, 0, sizeof(struct usbh_pl2303));
|
||||
}
|
||||
|
|
|
@ -15,11 +15,11 @@ static uint32_t g_devinuse = 0;
|
|||
|
||||
static struct usbh_xbox *usbh_xbox_class_alloc(void)
|
||||
{
|
||||
int devno;
|
||||
uint8_t devno;
|
||||
|
||||
for (devno = 0; devno < CONFIG_USBHOST_MAX_XBOX_CLASS; devno++) {
|
||||
if ((g_devinuse & (1 << devno)) == 0) {
|
||||
g_devinuse |= (1 << devno);
|
||||
if ((g_devinuse & (1U << devno)) == 0) {
|
||||
g_devinuse |= (1U << devno);
|
||||
memset(&g_xbox_class[devno], 0, sizeof(struct usbh_xbox));
|
||||
g_xbox_class[devno].minor = devno;
|
||||
return &g_xbox_class[devno];
|
||||
|
@ -30,10 +30,10 @@ static struct usbh_xbox *usbh_xbox_class_alloc(void)
|
|||
|
||||
static void usbh_xbox_class_free(struct usbh_xbox *xbox_class)
|
||||
{
|
||||
int devno = xbox_class->minor;
|
||||
uint8_t devno = xbox_class->minor;
|
||||
|
||||
if (devno >= 0 && devno < 32) {
|
||||
g_devinuse &= ~(1 << devno);
|
||||
if (devno < 32) {
|
||||
g_devinuse &= ~(1U << devno);
|
||||
}
|
||||
memset(xbox_class, 0, sizeof(struct usbh_xbox));
|
||||
}
|
||||
|
|
|
@ -18,6 +18,10 @@ struct usbd_video_priv {
|
|||
uint8_t power_mode;
|
||||
uint8_t error_code;
|
||||
struct video_entity_info info[3];
|
||||
uint8_t *ep_buffer;
|
||||
uint8_t *stream_buf;
|
||||
uint32_t stream_len;
|
||||
uint32_t stream_offset;
|
||||
} g_usbd_video[CONFIG_USBDEV_MAX_BUS];
|
||||
|
||||
static int usbd_video_control_request_handler(uint8_t busid, struct usb_setup_packet *setup, uint8_t **data, uint32_t *len)
|
||||
|
@ -671,7 +675,7 @@ static int video_class_interface_request_handler(uint8_t busid, struct usb_setup
|
|||
} else {
|
||||
return usbd_video_control_unit_terminal_request_handler(busid, setup, data, len); /* Unit and Terminal Requests */
|
||||
}
|
||||
} else if (intf_num == 1) { /* Video Stream Inteface */
|
||||
} else if (intf_num == 1) { /* Video Stream Inteface */
|
||||
return usbd_video_stream_request_handler(busid, setup, data, len); /* Interface Stream Requests */
|
||||
}
|
||||
return -1;
|
||||
|
@ -700,7 +704,7 @@ static void video_notify_handler(uint8_t busid, uint8_t event, void *arg)
|
|||
}
|
||||
}
|
||||
|
||||
void usbd_video_probe_and_commit_controls_init(uint8_t busid, uint32_t dwFrameInterval, uint32_t dwMaxVideoFrameSize, uint32_t dwMaxPayloadTransferSize)
|
||||
static void usbd_video_probe_and_commit_controls_init(uint8_t busid, uint32_t dwFrameInterval, uint32_t dwMaxVideoFrameSize, uint32_t dwMaxPayloadTransferSize)
|
||||
{
|
||||
g_usbd_video[busid].probe.hintUnion.bmHint = 0x01;
|
||||
g_usbd_video[busid].probe.hintUnion1.bmHint = 0;
|
||||
|
@ -739,7 +743,8 @@ void usbd_video_probe_and_commit_controls_init(uint8_t busid, uint32_t dwFrameIn
|
|||
g_usbd_video[busid].commit.bMaxVersion = 0;
|
||||
}
|
||||
|
||||
struct usbd_interface *usbd_video_init_intf(uint8_t busid, struct usbd_interface *intf,
|
||||
struct usbd_interface *usbd_video_init_intf(uint8_t busid,
|
||||
struct usbd_interface *intf,
|
||||
uint32_t dwFrameInterval,
|
||||
uint32_t dwMaxVideoFrameSize,
|
||||
uint32_t dwMaxPayloadTransferSize)
|
||||
|
@ -763,6 +768,54 @@ struct usbd_interface *usbd_video_init_intf(uint8_t busid, struct usbd_interface
|
|||
return intf;
|
||||
}
|
||||
|
||||
bool usbd_video_stream_split_transfer(uint8_t busid, uint8_t ep)
|
||||
{
|
||||
struct video_payload_header *header = (struct video_payload_header *)g_usbd_video[busid].ep_buffer;
|
||||
uint32_t remain;
|
||||
uint32_t len;
|
||||
bool last_packet = false;
|
||||
|
||||
header->bHeaderLength = 2;
|
||||
header->headerInfoUnion.headerInfoBits.endOfHeader = 1;
|
||||
|
||||
remain = g_usbd_video[busid].stream_len - g_usbd_video[busid].stream_offset;
|
||||
|
||||
len = MIN(remain, g_usbd_video[busid].probe.dwMaxPayloadTransferSize - header->bHeaderLength);
|
||||
memcpy(&g_usbd_video[busid].ep_buffer[header->bHeaderLength],
|
||||
&g_usbd_video[busid].stream_buf[g_usbd_video[busid].stream_offset],
|
||||
len);
|
||||
|
||||
g_usbd_video[busid].stream_offset += len;
|
||||
|
||||
if (g_usbd_video[busid].stream_offset == g_usbd_video[busid].stream_len) {
|
||||
last_packet = true;
|
||||
header->headerInfoUnion.headerInfoBits.endOfFrame = 1;
|
||||
}
|
||||
|
||||
usbd_ep_start_write(busid, ep, g_usbd_video[busid].ep_buffer, len + header->bHeaderLength);
|
||||
return last_packet;
|
||||
}
|
||||
|
||||
int usbd_video_stream_start_write(uint8_t busid, uint8_t ep, uint8_t *ep_buffer, uint8_t *buf, uint32_t len)
|
||||
{
|
||||
if (usb_device_is_configured(busid) == 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
g_usbd_video[busid].ep_buffer = ep_buffer;
|
||||
g_usbd_video[busid].stream_buf = buf;
|
||||
g_usbd_video[busid].stream_len = len;
|
||||
g_usbd_video[busid].stream_offset = 0;
|
||||
|
||||
struct video_payload_header *header = (struct video_payload_header *)g_usbd_video[busid].ep_buffer;
|
||||
|
||||
header->headerInfoUnion.headerInfoBits.frameIdentifier ^= 1;
|
||||
header->headerInfoUnion.headerInfoBits.endOfFrame = 0;
|
||||
|
||||
usbd_video_stream_split_transfer(busid, ep);
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t usbd_video_payload_fill(uint8_t busid, uint8_t *input, uint32_t input_len, uint8_t *output, uint32_t *out_len)
|
||||
{
|
||||
uint32_t packets;
|
||||
|
@ -770,7 +823,7 @@ uint32_t usbd_video_payload_fill(uint8_t busid, uint8_t *input, uint32_t input_l
|
|||
uint32_t picture_pos = 0;
|
||||
static uint8_t uvc_header[2] = { 0x02, 0x80 };
|
||||
|
||||
packets = (input_len + (g_usbd_video[busid].probe.dwMaxPayloadTransferSize - 2) ) / (g_usbd_video[busid].probe.dwMaxPayloadTransferSize - 2);
|
||||
packets = (input_len + (g_usbd_video[busid].probe.dwMaxPayloadTransferSize - 2)) / (g_usbd_video[busid].probe.dwMaxPayloadTransferSize - 2);
|
||||
last_packet_size = input_len - ((packets - 1) * (g_usbd_video[busid].probe.dwMaxPayloadTransferSize - 2));
|
||||
|
||||
for (size_t i = 0; i < packets; i++) {
|
||||
|
|
|
@ -20,6 +20,10 @@ struct usbd_interface *usbd_video_init_intf(uint8_t busid, struct usbd_interface
|
|||
|
||||
void usbd_video_open(uint8_t busid, uint8_t intf);
|
||||
void usbd_video_close(uint8_t busid, uint8_t intf);
|
||||
|
||||
bool usbd_video_stream_split_transfer(uint8_t busid, uint8_t ep);
|
||||
int usbd_video_stream_start_write(uint8_t busid, uint8_t ep, uint8_t *ep_buffer, uint8_t *buf, uint32_t len);
|
||||
|
||||
uint32_t usbd_video_payload_fill(uint8_t busid, uint8_t *input, uint32_t input_len, uint8_t *output, uint32_t *out_len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -34,11 +34,11 @@ static uint32_t g_devinuse = 0;
|
|||
|
||||
static struct usbh_video *usbh_video_class_alloc(void)
|
||||
{
|
||||
int devno;
|
||||
uint8_t devno;
|
||||
|
||||
for (devno = 0; devno < CONFIG_USBHOST_MAX_VIDEO_CLASS; devno++) {
|
||||
if ((g_devinuse & (1 << devno)) == 0) {
|
||||
g_devinuse |= (1 << devno);
|
||||
if ((g_devinuse & (1U << devno)) == 0) {
|
||||
g_devinuse |= (1U << devno);
|
||||
memset(&g_video_class[devno], 0, sizeof(struct usbh_video));
|
||||
g_video_class[devno].minor = devno;
|
||||
return &g_video_class[devno];
|
||||
|
@ -49,10 +49,10 @@ static struct usbh_video *usbh_video_class_alloc(void)
|
|||
|
||||
static void usbh_video_class_free(struct usbh_video *video_class)
|
||||
{
|
||||
int devno = video_class->minor;
|
||||
uint8_t devno = video_class->minor;
|
||||
|
||||
if (devno >= 0 && devno < 32) {
|
||||
g_devinuse &= ~(1 << devno);
|
||||
if (devno < 32) {
|
||||
g_devinuse &= ~(1U << devno);
|
||||
}
|
||||
memset(video_class, 0, sizeof(struct usbh_video));
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
|
||||
#define DEV_FORMAT "/dev/rndis"
|
||||
|
||||
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_rndis_buf[4096];
|
||||
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_rndis_buf[512];
|
||||
|
||||
#define CONFIG_USBHOST_RNDIS_ETH_MAX_FRAME_SIZE 1514
|
||||
#define CONFIG_USBHOST_RNDIS_ETH_MSG_SIZE (CONFIG_USBHOST_RNDIS_ETH_MAX_FRAME_SIZE + 44)
|
||||
|
@ -80,7 +80,7 @@ static int usbh_rndis_init_msg_transfer(struct usbh_rndis *rndis_class)
|
|||
setup->bRequest = CDC_REQUEST_GET_ENCAPSULATED_RESPONSE;
|
||||
setup->wValue = 0;
|
||||
setup->wIndex = 0;
|
||||
setup->wLength = 4096;
|
||||
setup->wLength = sizeof(g_rndis_buf);
|
||||
|
||||
ret = usbh_control_transfer(rndis_class->hport, setup, (uint8_t *)resp);
|
||||
if (ret < 0) {
|
||||
|
@ -138,7 +138,7 @@ int usbh_rndis_query_msg_transfer(struct usbh_rndis *rndis_class, uint32_t oid,
|
|||
setup->bRequest = CDC_REQUEST_GET_ENCAPSULATED_RESPONSE;
|
||||
setup->wValue = 0;
|
||||
setup->wIndex = 0;
|
||||
setup->wLength = 4096;
|
||||
setup->wLength = sizeof(g_rndis_buf);
|
||||
|
||||
ret = usbh_control_transfer(rndis_class->hport, setup, (uint8_t *)resp);
|
||||
if (ret < 0) {
|
||||
|
@ -195,7 +195,7 @@ static int usbh_rndis_set_msg_transfer(struct usbh_rndis *rndis_class, uint32_t
|
|||
setup->bRequest = CDC_REQUEST_GET_ENCAPSULATED_RESPONSE;
|
||||
setup->wValue = 0;
|
||||
setup->wIndex = 0;
|
||||
setup->wLength = 4096;
|
||||
setup->wLength = sizeof(g_rndis_buf);
|
||||
|
||||
ret = usbh_control_transfer(rndis_class->hport, setup, (uint8_t *)resp);
|
||||
if (ret < 0) {
|
||||
|
@ -262,7 +262,7 @@ int usbh_rndis_keepalive(struct usbh_rndis *rndis_class)
|
|||
setup->bRequest = CDC_REQUEST_GET_ENCAPSULATED_RESPONSE;
|
||||
setup->wValue = 0;
|
||||
setup->wIndex = 0;
|
||||
setup->wLength = 4096;
|
||||
setup->wLength = sizeof(g_rndis_buf);
|
||||
|
||||
ret = usbh_control_transfer(rndis_class->hport, setup, (uint8_t *)resp);
|
||||
if (ret < 0) {
|
||||
|
@ -387,14 +387,14 @@ static int usbh_rndis_connect(struct usbh_hubport *hport, uint8_t intf)
|
|||
}
|
||||
|
||||
uint32_t packet_filter = 0x0f;
|
||||
usbh_rndis_set_msg_transfer(rndis_class, OID_GEN_CURRENT_PACKET_FILTER, (uint8_t *)&packet_filter, 4);
|
||||
ret = usbh_rndis_set_msg_transfer(rndis_class, OID_GEN_CURRENT_PACKET_FILTER, (uint8_t *)&packet_filter, 4);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
USB_LOG_INFO("rndis set OID_GEN_CURRENT_PACKET_FILTER success\r\n");
|
||||
|
||||
uint8_t multicast_list[6] = { 0x01, 0x00, 0x5E, 0x00, 0x00, 0x01 };
|
||||
usbh_rndis_set_msg_transfer(rndis_class, OID_802_3_MULTICAST_LIST, multicast_list, 6);
|
||||
ret = usbh_rndis_set_msg_transfer(rndis_class, OID_802_3_MULTICAST_LIST, multicast_list, 6);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
#undef CHERRYUSB_VERSION_STR
|
||||
#endif
|
||||
|
||||
#define CHERRYUSB_VERSION 0x010400
|
||||
#define CHERRYUSB_VERSION_STR "v1.4.0"
|
||||
#define CHERRYUSB_VERSION 0x010401
|
||||
#define CHERRYUSB_VERSION_STR "v1.4.1"
|
||||
|
||||
#endif
|
|
@ -489,10 +489,13 @@ static bool usbd_set_interface(uint8_t busid, uint8_t iface, uint8_t alt_setting
|
|||
if (cur_iface == iface) {
|
||||
ep_desc = (struct usb_endpoint_descriptor *)p;
|
||||
|
||||
if (cur_alt_setting != alt_setting) {
|
||||
if (alt_setting == 0) {
|
||||
ret = usbd_reset_endpoint(busid, ep_desc);
|
||||
} else {
|
||||
goto find_end;
|
||||
} else if (cur_alt_setting == alt_setting) {
|
||||
ret = usbd_set_endpoint(busid, ep_desc);
|
||||
goto find_end;
|
||||
} else {
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -510,6 +513,7 @@ static bool usbd_set_interface(uint8_t busid, uint8_t iface, uint8_t alt_setting
|
|||
}
|
||||
}
|
||||
|
||||
find_end:
|
||||
usbd_class_event_notify_handler(busid, USBD_EVENT_SET_INTERFACE, (void *)if_desc);
|
||||
|
||||
return ret;
|
||||
|
@ -1406,6 +1410,12 @@ int usbd_initialize(uint8_t busid, uintptr_t reg_base, void (*event_handler)(uin
|
|||
|
||||
int usbd_deinitialize(uint8_t busid)
|
||||
{
|
||||
if (busid >= CONFIG_USBDEV_MAX_BUS) {
|
||||
USB_LOG_ERR("bus overflow\r\n");
|
||||
while (1) {
|
||||
}
|
||||
}
|
||||
|
||||
g_usbd_core[busid].event_handler(busid, USBD_EVENT_DEINIT);
|
||||
usbd_class_event_notify_handler(busid, USBD_EVENT_DEINIT, NULL);
|
||||
usb_dc_deinit(busid);
|
||||
|
|
|
@ -486,7 +486,7 @@ int usbh_enumerate(struct usbh_hubport *hport)
|
|||
goto errout;
|
||||
}
|
||||
USB_LOG_INFO("The device has %d interfaces\r\n", ((struct usb_configuration_descriptor *)ep0_request_buffer[hport->bus->busid])->bNumInterfaces);
|
||||
hport->raw_config_desc = usb_osal_malloc(wTotalLength);
|
||||
hport->raw_config_desc = usb_osal_malloc(wTotalLength + 1);
|
||||
if (hport->raw_config_desc == NULL) {
|
||||
ret = -USB_ERR_NOMEM;
|
||||
USB_LOG_ERR("No memory to alloc for raw_config_desc\r\n");
|
||||
|
@ -495,6 +495,8 @@ int usbh_enumerate(struct usbh_hubport *hport)
|
|||
|
||||
config_value = ((struct usb_configuration_descriptor *)ep0_request_buffer[hport->bus->busid])->bConfigurationValue;
|
||||
memcpy(hport->raw_config_desc, ep0_request_buffer[hport->bus->busid], wTotalLength);
|
||||
hport->raw_config_desc[wTotalLength] = '\0';
|
||||
|
||||
#ifdef CONFIG_USBHOST_GET_STRING_DESC
|
||||
uint8_t string_buffer[128];
|
||||
|
||||
|
@ -649,6 +651,12 @@ int usbh_deinitialize(uint8_t busid)
|
|||
{
|
||||
struct usbh_bus *bus;
|
||||
|
||||
if (busid >= CONFIG_USBHOST_MAX_BUS) {
|
||||
USB_LOG_ERR("bus overflow\r\n");
|
||||
while (1) {
|
||||
}
|
||||
}
|
||||
|
||||
bus = &g_usbhost_bus[busid];
|
||||
|
||||
usbh_hub_deinitialize(bus);
|
||||
|
|
|
@ -175,7 +175,7 @@ static const uint8_t adb_descriptor[] = {
|
|||
0x02,
|
||||
0x01,
|
||||
0x40,
|
||||
0x01,
|
||||
0x00,
|
||||
0x00,
|
||||
#endif
|
||||
0x00
|
||||
|
|
|
@ -144,7 +144,7 @@ const uint8_t audio_v1_descriptor[] = {
|
|||
0x00,
|
||||
0x00,
|
||||
0x40,
|
||||
0x01,
|
||||
0x00,
|
||||
0x00,
|
||||
#endif
|
||||
0x00
|
||||
|
|
|
@ -139,7 +139,7 @@ const uint8_t audio_v1_descriptor[] = {
|
|||
0x00,
|
||||
0x00,
|
||||
0x40,
|
||||
0x01,
|
||||
0x00,
|
||||
0x00,
|
||||
#endif
|
||||
0x00
|
||||
|
|
|
@ -149,7 +149,7 @@ const uint8_t audio_v2_descriptor[] = {
|
|||
0x00,
|
||||
0x00,
|
||||
0x40,
|
||||
0x01,
|
||||
0x00,
|
||||
0x00,
|
||||
#endif
|
||||
0x00
|
||||
|
|
|
@ -196,7 +196,7 @@ uint8_t audio_v2_descriptor[] = {
|
|||
0x00,
|
||||
0x00,
|
||||
0x40,
|
||||
0x01,
|
||||
0x00,
|
||||
0x00,
|
||||
#endif
|
||||
0x00
|
||||
|
|
|
@ -149,7 +149,7 @@ const uint8_t audio_v2_descriptor[] = {
|
|||
0x00,
|
||||
0x00,
|
||||
0x40,
|
||||
0x01,
|
||||
0x00,
|
||||
0x00,
|
||||
#endif
|
||||
0x00
|
||||
|
|
|
@ -95,7 +95,7 @@ const uint8_t msc_bootuf2_descriptor[] = {
|
|||
0x00,
|
||||
0x00,
|
||||
0x40,
|
||||
0x01,
|
||||
0x00,
|
||||
0x00,
|
||||
#endif
|
||||
0x00
|
||||
|
|
|
@ -147,7 +147,7 @@ const uint8_t cdc_acm_hid_msc_descriptor[] = {
|
|||
0x00,
|
||||
0x00,
|
||||
0x40,
|
||||
0x01,
|
||||
0x00,
|
||||
0x00,
|
||||
#endif
|
||||
0x00
|
||||
|
|
|
@ -58,7 +58,7 @@ static const uint8_t device_quality_descriptor[] = {
|
|||
0x02,
|
||||
0x01,
|
||||
0x40,
|
||||
0x01,
|
||||
0x00,
|
||||
0x00,
|
||||
};
|
||||
|
||||
|
@ -173,7 +173,7 @@ static const uint8_t cdc_msc_descriptor[] = {
|
|||
0x02,
|
||||
0x01,
|
||||
0x40,
|
||||
0x01,
|
||||
0x00,
|
||||
0x00,
|
||||
#endif
|
||||
0x00
|
||||
|
|
|
@ -113,7 +113,7 @@ static const uint8_t cdc_descriptor[] = {
|
|||
0x02,
|
||||
0x01,
|
||||
0x40,
|
||||
0x01,
|
||||
0x00,
|
||||
0x00,
|
||||
#endif
|
||||
0x00
|
||||
|
|
|
@ -98,7 +98,7 @@ static const uint8_t cdc_descriptor[] = {
|
|||
0x02,
|
||||
0x01,
|
||||
0x40,
|
||||
0x01,
|
||||
0x00,
|
||||
0x00,
|
||||
#endif
|
||||
0x00
|
||||
|
|
|
@ -124,7 +124,7 @@ static const uint8_t cdc_ecm_descriptor[] = {
|
|||
0x02,
|
||||
0x01,
|
||||
0x40,
|
||||
0x01,
|
||||
0x00,
|
||||
0x00,
|
||||
#endif
|
||||
0x00
|
||||
|
|
|
@ -100,7 +100,7 @@ static const uint8_t cdc_descriptor[] = {
|
|||
0x02,
|
||||
0x01,
|
||||
0x40,
|
||||
0x01,
|
||||
0x00,
|
||||
0x00,
|
||||
#endif
|
||||
0x00
|
||||
|
|
|
@ -136,7 +136,7 @@ const uint8_t dfu_flash_descriptor[] = {
|
|||
0x00,
|
||||
0x00,
|
||||
0x40,
|
||||
0x01,
|
||||
0x00,
|
||||
0x00,
|
||||
#endif
|
||||
0x00
|
||||
|
|
|
@ -146,7 +146,7 @@ static const uint8_t hid_descriptor[] = {
|
|||
0x00,
|
||||
0x00,
|
||||
0x40,
|
||||
0x01,
|
||||
0x00,
|
||||
0x00,
|
||||
#endif
|
||||
0x00
|
||||
|
|
|
@ -122,7 +122,7 @@ static const uint8_t hid_descriptor[] = {
|
|||
0x00,
|
||||
0x00,
|
||||
0x40,
|
||||
0x01,
|
||||
0x00,
|
||||
0x00,
|
||||
#endif
|
||||
0x00
|
||||
|
|
|
@ -126,7 +126,7 @@ const uint8_t hid_descriptor[] = {
|
|||
0x00,
|
||||
0x00,
|
||||
0x40,
|
||||
0x01,
|
||||
0x00,
|
||||
0x00,
|
||||
#endif
|
||||
0x00
|
||||
|
|
|
@ -126,7 +126,7 @@ const uint8_t hid_descriptor[] = {
|
|||
0x00,
|
||||
0x00,
|
||||
0x40,
|
||||
0x01,
|
||||
0x00,
|
||||
0x00,
|
||||
#endif
|
||||
0x00
|
||||
|
|
|
@ -145,7 +145,7 @@ const uint8_t midi_descriptor[] = {
|
|||
0x02,
|
||||
0x01,
|
||||
0x40,
|
||||
0x01,
|
||||
0x00,
|
||||
0x00,
|
||||
#endif
|
||||
0x00
|
||||
|
|
|
@ -94,7 +94,7 @@ const uint8_t msc_ram_descriptor[] = {
|
|||
0x00,
|
||||
0x00,
|
||||
0x40,
|
||||
0x01,
|
||||
0x00,
|
||||
0x00,
|
||||
#endif
|
||||
0x00
|
||||
|
|
|
@ -97,7 +97,7 @@ const uint8_t msc_storage_descriptor[] = {
|
|||
0x00,
|
||||
0x00,
|
||||
0x40,
|
||||
0x01,
|
||||
0x00,
|
||||
0x00,
|
||||
#endif
|
||||
0x00
|
||||
|
|
|
@ -224,7 +224,7 @@ const uint8_t video_audio_hid_descriptor[] = {
|
|||
0x00,
|
||||
0x00,
|
||||
0x40,
|
||||
0x01,
|
||||
0x00,
|
||||
0x00,
|
||||
#endif
|
||||
0x00
|
||||
|
|
|
@ -129,7 +129,7 @@ const uint8_t video_descriptor[] = {
|
|||
0x00,
|
||||
0x00,
|
||||
0x40,
|
||||
0x01,
|
||||
0x00,
|
||||
0x00,
|
||||
#endif
|
||||
0x00
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
#include "usbd_video.h"
|
||||
#include "cherryusb_mjpeg.h"
|
||||
|
||||
#define VIDEO_STREAM_SPLIT_ENABLE 1
|
||||
|
||||
#define VIDEO_IN_EP 0x81
|
||||
#define VIDEO_INT_EP 0x83
|
||||
|
||||
|
@ -34,7 +36,7 @@
|
|||
#define MAX_BIT_RATE (unsigned long)(WIDTH * HEIGHT * 16 * CAM_FPS)
|
||||
#define MAX_FRAME_SIZE (unsigned long)(WIDTH * HEIGHT * 2)
|
||||
|
||||
#define VS_HEADER_SIZ (unsigned int)(VIDEO_SIZEOF_VS_INPUT_HEADER_DESC(1,1) + VIDEO_SIZEOF_VS_FORMAT_MJPEG_DESC + VIDEO_SIZEOF_VS_FRAME_MJPEG_DESC(1))
|
||||
#define VS_HEADER_SIZ (unsigned int)(VIDEO_SIZEOF_VS_INPUT_HEADER_DESC(1, 1) + VIDEO_SIZEOF_VS_FORMAT_MJPEG_DESC + VIDEO_SIZEOF_VS_FRAME_MJPEG_DESC(1))
|
||||
|
||||
#define USB_VIDEO_DESC_SIZ (unsigned long)(9 + \
|
||||
VIDEO_VC_NOEP_DESCRIPTOR_LEN + \
|
||||
|
@ -129,7 +131,7 @@ const uint8_t video_descriptor[] = {
|
|||
0x00,
|
||||
0x00,
|
||||
0x40,
|
||||
0x01,
|
||||
0x00,
|
||||
0x00,
|
||||
#endif
|
||||
0x00
|
||||
|
@ -180,8 +182,14 @@ void usbd_video_close(uint8_t busid, uint8_t intf)
|
|||
|
||||
void usbd_video_iso_callback(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
{
|
||||
//USB_LOG_RAW("actual in len:%d\r\n", nbytes);
|
||||
#if VIDEO_STREAM_SPLIT_ENABLE
|
||||
if (usbd_video_stream_split_transfer(busid, ep)) {
|
||||
/* one frame has done */
|
||||
iso_tx_busy = false;
|
||||
}
|
||||
#else
|
||||
iso_tx_busy = false;
|
||||
#endif
|
||||
}
|
||||
|
||||
static struct usbd_endpoint video_in_ep = {
|
||||
|
@ -202,7 +210,11 @@ void video_init(uint8_t busid, uintptr_t reg_base)
|
|||
usbd_initialize(busid, reg_base, usbd_event_handler);
|
||||
}
|
||||
|
||||
#if VIDEO_STREAM_SPLIT_ENABLE
|
||||
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t packet_buffer[MAX_PAYLOAD_SIZE];
|
||||
#else
|
||||
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t packet_buffer[40 * 1024];
|
||||
#endif
|
||||
|
||||
void video_test(uint8_t busid)
|
||||
{
|
||||
|
@ -210,11 +222,22 @@ void video_test(uint8_t busid)
|
|||
uint32_t packets;
|
||||
|
||||
(void)packets;
|
||||
memset(packet_buffer, 0, 40 * 1024);
|
||||
(void)out_len;
|
||||
memset(packet_buffer, 0, sizeof(packet_buffer));
|
||||
|
||||
while (1) {
|
||||
if (tx_flag) {
|
||||
#if VIDEO_STREAM_SPLIT_ENABLE
|
||||
iso_tx_busy = true;
|
||||
usbd_video_stream_start_write(busid, VIDEO_IN_EP, packet_buffer, (uint8_t *)cherryusb_mjpeg, sizeof(cherryusb_mjpeg));
|
||||
while (iso_tx_busy) {
|
||||
if (tx_flag == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
#else
|
||||
packets = usbd_video_payload_fill(busid, (uint8_t *)cherryusb_mjpeg, sizeof(cherryusb_mjpeg), packet_buffer, &out_len);
|
||||
#if 1
|
||||
|
||||
iso_tx_busy = true;
|
||||
usbd_ep_start_write(busid, VIDEO_IN_EP, packet_buffer, out_len);
|
||||
while (iso_tx_busy) {
|
||||
|
@ -222,27 +245,6 @@ void video_test(uint8_t busid)
|
|||
break;
|
||||
}
|
||||
}
|
||||
#else
|
||||
/* dwc2 must use this method */
|
||||
for (uint32_t i = 0; i < packets; i++) {
|
||||
if (i == (packets - 1)) {
|
||||
iso_tx_busy = true;
|
||||
usbd_ep_start_write(busid, VIDEO_IN_EP, &packet_buffer[i * MAX_PAYLOAD_SIZE], out_len - (packets - 1) * MAX_PAYLOAD_SIZE);
|
||||
while (iso_tx_busy) {
|
||||
if (tx_flag == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
iso_tx_busy = true;
|
||||
usbd_ep_start_write(busid, VIDEO_IN_EP, &packet_buffer[i * MAX_PAYLOAD_SIZE], MAX_PAYLOAD_SIZE);
|
||||
while (iso_tx_busy) {
|
||||
if (tx_flag == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
|
|
@ -131,7 +131,7 @@ const uint8_t video_descriptor[] = {
|
|||
0x00,
|
||||
0x00,
|
||||
0x40,
|
||||
0x01,
|
||||
0x00,
|
||||
0x00,
|
||||
#endif
|
||||
0x00
|
||||
|
|
|
@ -254,7 +254,7 @@ static const uint8_t webusb_hid_descriptor[] = {
|
|||
0x00,
|
||||
0x00,
|
||||
0x40,
|
||||
0x01,
|
||||
0x00,
|
||||
0x00,
|
||||
#endif
|
||||
0x00
|
||||
|
|
|
@ -326,7 +326,7 @@ const uint8_t winusb_descriptor[] = {
|
|||
0x02,
|
||||
0x01,
|
||||
0x40,
|
||||
0x01,
|
||||
0x00,
|
||||
0x00,
|
||||
#endif
|
||||
0x00
|
||||
|
|
|
@ -219,7 +219,7 @@ const uint8_t winusbv2_descriptor[] = {
|
|||
0x00,
|
||||
0x00,
|
||||
0x40,
|
||||
0x01,
|
||||
0x00,
|
||||
0x00,
|
||||
#endif
|
||||
/* End */
|
||||
|
|
|
@ -255,7 +255,7 @@ const uint8_t winusbv2_descriptor[] = {
|
|||
0x00,
|
||||
0x00,
|
||||
0x40,
|
||||
0x01,
|
||||
0x00,
|
||||
0x00,
|
||||
#endif
|
||||
/* End */
|
||||
|
|
|
@ -45,7 +45,7 @@
|
|||
#endif
|
||||
|
||||
#if RT_LWIP_TCPTHREAD_STACKSIZE < 2048
|
||||
#error RT_LWIP_TCPTHREAD_STACKSIZE must be larger than 2048
|
||||
#error RT_LWIP_TCPTHREAD_STACKSIZE must be >= 2048
|
||||
#endif
|
||||
|
||||
// #define CONFIG_USBHOST_PLATFORM_CDC_ECM
|
||||
|
@ -122,6 +122,7 @@ static rt_err_t rt_usbh_cdc_ecm_control(rt_device_t dev, int cmd, void *args)
|
|||
static rt_err_t rt_usbh_cdc_ecm_eth_tx(rt_device_t dev, struct pbuf *p)
|
||||
{
|
||||
int ret;
|
||||
(void)dev;
|
||||
|
||||
usbh_lwip_eth_output_common(p, usbh_cdc_ecm_get_eth_txbuf());
|
||||
ret = usbh_cdc_ecm_eth_output(p->tot_len);
|
||||
|
@ -154,6 +155,8 @@ void usbh_cdc_ecm_run(struct usbh_cdc_ecm *cdc_ecm_class)
|
|||
|
||||
void usbh_cdc_ecm_stop(struct usbh_cdc_ecm *cdc_ecm_class)
|
||||
{
|
||||
(void)cdc_ecm_class;
|
||||
|
||||
eth_device_deinit(&g_cdc_ecm_dev);
|
||||
}
|
||||
#endif
|
||||
|
@ -208,6 +211,7 @@ static rt_err_t rt_usbh_rndis_control(rt_device_t dev, int cmd, void *args)
|
|||
static rt_err_t rt_usbh_rndis_eth_tx(rt_device_t dev, struct pbuf *p)
|
||||
{
|
||||
int ret;
|
||||
(void)dev;
|
||||
|
||||
usbh_lwip_eth_output_common(p, usbh_rndis_get_eth_txbuf());
|
||||
ret = usbh_rndis_eth_output(p->tot_len);
|
||||
|
@ -241,6 +245,8 @@ void usbh_rndis_run(struct usbh_rndis *rndis_class)
|
|||
|
||||
void usbh_rndis_stop(struct usbh_rndis *rndis_class)
|
||||
{
|
||||
(void)rndis_class;
|
||||
|
||||
eth_device_deinit(&g_rndis_dev);
|
||||
// rt_timer_stop(keep_timer);
|
||||
// rt_timer_delete(keep_timer);
|
||||
|
@ -277,6 +283,7 @@ static rt_err_t rt_usbh_cdc_ncm_control(rt_device_t dev, int cmd, void *args)
|
|||
static rt_err_t rt_usbh_cdc_ncm_eth_tx(rt_device_t dev, struct pbuf *p)
|
||||
{
|
||||
int ret;
|
||||
(void)dev;
|
||||
|
||||
usbh_lwip_eth_output_common(p, usbh_cdc_ncm_get_eth_txbuf());
|
||||
ret = usbh_cdc_ncm_eth_output(p->tot_len);
|
||||
|
@ -309,6 +316,8 @@ void usbh_cdc_ncm_run(struct usbh_cdc_ncm *cdc_ncm_class)
|
|||
|
||||
void usbh_cdc_ncm_stop(struct usbh_cdc_ncm *cdc_ncm_class)
|
||||
{
|
||||
(void)cdc_ncm_class;
|
||||
|
||||
eth_device_deinit(&g_cdc_ncm_dev);
|
||||
}
|
||||
#endif
|
||||
|
@ -343,6 +352,7 @@ static rt_err_t rt_usbh_asix_control(rt_device_t dev, int cmd, void *args)
|
|||
static rt_err_t rt_usbh_asix_eth_tx(rt_device_t dev, struct pbuf *p)
|
||||
{
|
||||
int ret;
|
||||
(void)dev;
|
||||
|
||||
usbh_lwip_eth_output_common(p, usbh_asix_get_eth_txbuf());
|
||||
ret = usbh_asix_eth_output(p->tot_len);
|
||||
|
@ -375,6 +385,8 @@ void usbh_asix_run(struct usbh_asix *asix_class)
|
|||
|
||||
void usbh_asix_stop(struct usbh_asix *asix_class)
|
||||
{
|
||||
(void)asix_class;
|
||||
|
||||
eth_device_deinit(&g_asix_dev);
|
||||
}
|
||||
#endif
|
||||
|
@ -409,6 +421,7 @@ static rt_err_t rt_usbh_rtl8152_control(rt_device_t dev, int cmd, void *args)
|
|||
static rt_err_t rt_usbh_rtl8152_eth_tx(rt_device_t dev, struct pbuf *p)
|
||||
{
|
||||
int ret;
|
||||
(void)dev;
|
||||
|
||||
usbh_lwip_eth_output_common(p, usbh_rtl8152_get_eth_txbuf());
|
||||
ret = usbh_rtl8152_eth_output(p->tot_len);
|
||||
|
@ -441,6 +454,8 @@ void usbh_rtl8152_run(struct usbh_rtl8152 *rtl8152_class)
|
|||
|
||||
void usbh_rtl8152_stop(struct usbh_rtl8152 *rtl8152_class)
|
||||
{
|
||||
(void)rtl8152_class;
|
||||
|
||||
eth_device_deinit(&g_rtl8152_dev);
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -51,8 +51,6 @@
|
|||
#endif
|
||||
// clang-format on
|
||||
|
||||
//#define CONFIG_USB_DWC2_DMA_ENABLE
|
||||
|
||||
#ifndef CONFIG_USB_DWC2_RXALL_FIFO_SIZE
|
||||
#define CONFIG_USB_DWC2_RXALL_FIFO_SIZE (1024 / 4)
|
||||
#endif
|
||||
|
@ -62,7 +60,7 @@
|
|||
#endif
|
||||
|
||||
#ifndef CONFIG_USB_DWC2_TX1_FIFO_SIZE
|
||||
#define CONFIG_USB_DWC2_TX1_FIFO_SIZE (512 / 4)
|
||||
#define CONFIG_USB_DWC2_TX1_FIFO_SIZE (1024 / 4)
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_USB_DWC2_TX2_FIFO_SIZE
|
||||
|
@ -119,7 +117,7 @@ USB_NOCACHE_RAM_SECTION struct dwc2_udc {
|
|||
__attribute__((aligned(32))) struct usb_setup_packet setup;
|
||||
struct dwc2_ep_state in_ep[CONFIG_USBDEV_EP_NUM]; /*!< IN endpoint parameters*/
|
||||
struct dwc2_ep_state out_ep[CONFIG_USBDEV_EP_NUM]; /*!< OUT endpoint parameters */
|
||||
} g_dwc2_udc[CONFIG_USBHOST_MAX_BUS];
|
||||
} g_dwc2_udc[CONFIG_USBDEV_MAX_BUS];
|
||||
|
||||
static inline int dwc2_reset(uint8_t busid)
|
||||
{
|
||||
|
@ -386,6 +384,17 @@ static void dwc2_tx_fifo_empty_procecss(uint8_t busid, uint8_t ep_idx)
|
|||
if (len > g_dwc2_udc[busid].in_ep[ep_idx].ep_mps) {
|
||||
len = g_dwc2_udc[busid].in_ep[ep_idx].ep_mps;
|
||||
}
|
||||
if (g_dwc2_udc[busid].in_ep[ep_idx].ep_type == USB_ENDPOINT_TYPE_ISOCHRONOUS) {
|
||||
if ((USB_OTG_DEV->DSTS & (1U << 8)) == 0U) {
|
||||
USB_OTG_INEP(ep_idx)->DIEPCTL &= ~USB_OTG_DIEPCTL_SD0PID_SEVNFRM;
|
||||
USB_OTG_INEP(ep_idx)->DIEPCTL |= USB_OTG_DIEPCTL_SODDFRM;
|
||||
} else {
|
||||
USB_OTG_INEP(ep_idx)->DIEPCTL &= ~USB_OTG_DIEPCTL_SODDFRM;
|
||||
USB_OTG_INEP(ep_idx)->DIEPCTL |= USB_OTG_DIEPCTL_SD0PID_SEVNFRM;
|
||||
}
|
||||
USB_OTG_INEP(ep_idx)->DIEPTSIZ &= ~(USB_OTG_DIEPTSIZ_MULCNT);
|
||||
USB_OTG_INEP(ep_idx)->DIEPTSIZ |= (USB_OTG_DIEPTSIZ_MULCNT & (1U << 29));
|
||||
}
|
||||
|
||||
dwc2_ep_write(busid, ep_idx, g_dwc2_udc[busid].in_ep[ep_idx].xfer_buf, len);
|
||||
g_dwc2_udc[busid].in_ep[ep_idx].xfer_buf += len;
|
||||
|
@ -577,8 +586,7 @@ int usb_dc_init(uint8_t busid)
|
|||
/* Enable interrupts matching to the Device mode ONLY */
|
||||
USB_OTG_GLB->GINTMSK = USB_OTG_GINTMSK_USBRST | USB_OTG_GINTMSK_ENUMDNEM |
|
||||
USB_OTG_GINTMSK_OEPINT | USB_OTG_GINTMSK_IEPINT |
|
||||
USB_OTG_GINTMSK_USBSUSPM | USB_OTG_GINTMSK_WUIM |
|
||||
USB_OTG_GINTMSK_IISOIXFRM | USB_OTG_GINTMSK_PXFRM_IISOOXFRM;
|
||||
USB_OTG_GINTMSK_USBSUSPM | USB_OTG_GINTMSK_WUIM;
|
||||
|
||||
#ifdef CONFIG_USB_DWC2_DMA_ENABLE
|
||||
if (((USB_OTG_GLB->GHWCFG2 & (0x3U << 3)) >> 3) != 2) {
|
||||
|
@ -588,6 +596,7 @@ int usb_dc_init(uint8_t busid)
|
|||
}
|
||||
|
||||
USB_OTG_DEV->DCFG &= ~USB_OTG_DCFG_DESCDMA;
|
||||
USB_OTG_GLB->GAHBCFG &= ~USB_OTG_GAHBCFG_HBSTLEN;
|
||||
USB_OTG_GLB->GAHBCFG |= (USB_OTG_GAHBCFG_DMAEN | USB_OTG_GAHBCFG_HBSTLEN_4);
|
||||
#else
|
||||
USB_OTG_GLB->GINTMSK |= USB_OTG_GINTMSK_RXFLVLM;
|
||||
|
@ -859,13 +868,13 @@ int usbd_ep_is_stalled(uint8_t busid, const uint8_t ep, uint8_t *stalled)
|
|||
uint8_t ep_idx = USB_EP_GET_IDX(ep);
|
||||
|
||||
if (USB_EP_DIR_IS_OUT(ep)) {
|
||||
if(USB_OTG_OUTEP(ep_idx)->DOEPCTL & USB_OTG_DOEPCTL_STALL) {
|
||||
if (USB_OTG_OUTEP(ep_idx)->DOEPCTL & USB_OTG_DOEPCTL_STALL) {
|
||||
*stalled = 1;
|
||||
} else {
|
||||
*stalled = 0;
|
||||
}
|
||||
} else {
|
||||
if(USB_OTG_INEP(ep_idx)->DIEPCTL & USB_OTG_DIEPCTL_STALL) {
|
||||
if (USB_OTG_INEP(ep_idx)->DIEPCTL & USB_OTG_DIEPCTL_STALL) {
|
||||
*stalled = 1;
|
||||
} else {
|
||||
*stalled = 0;
|
||||
|
@ -1111,7 +1120,7 @@ void USBD_IRQHandler(uint8_t busid)
|
|||
}
|
||||
}
|
||||
if (gint_status & USB_OTG_GINTSTS_USBRST) {
|
||||
USB_OTG_GLB->GINTSTS |= USB_OTG_GINTSTS_USBRST;
|
||||
USB_OTG_GLB->GINTSTS = USB_OTG_GINTSTS_USBRST;
|
||||
USB_OTG_DEV->DCTL &= ~USB_OTG_DCTL_RWUSIG;
|
||||
|
||||
dwc2_flush_txfifo(busid, 0x10U);
|
||||
|
@ -1158,58 +1167,22 @@ void USBD_IRQHandler(uint8_t busid)
|
|||
USB_OTG_DEV->DCTL |= USB_OTG_DCTL_CGINAK;
|
||||
}
|
||||
if (gint_status & USB_OTG_GINTSTS_PXFR_INCOMPISOOUT) {
|
||||
daintmask = USB_OTG_DEV->DAINTMSK;
|
||||
daintmask >>= 16;
|
||||
|
||||
for (ep_idx = 1; ep_idx < CONFIG_USBDEV_EP_NUM; ep_idx++) {
|
||||
if ((BIT(ep_idx) & ~daintmask) || (g_dwc2_udc[busid].out_ep[ep_idx].ep_type != USB_ENDPOINT_TYPE_ISOCHRONOUS))
|
||||
continue;
|
||||
if (!(USB_OTG_OUTEP(ep_idx)->DOEPCTL & USB_OTG_DOEPCTL_USBAEP))
|
||||
continue;
|
||||
|
||||
if ((USB_OTG_DEV->DSTS & (1U << 8)) != 0U) {
|
||||
USB_OTG_OUTEP(ep_idx)->DOEPCTL |= USB_OTG_DOEPCTL_SD0PID_SEVNFRM;
|
||||
USB_OTG_OUTEP(ep_idx)->DOEPCTL &= ~USB_OTG_DOEPCTL_SODDFRM;
|
||||
} else {
|
||||
USB_OTG_OUTEP(ep_idx)->DOEPCTL &= ~USB_OTG_DOEPCTL_SD0PID_SEVNFRM;
|
||||
USB_OTG_OUTEP(ep_idx)->DOEPCTL |= USB_OTG_DOEPCTL_SODDFRM;
|
||||
}
|
||||
}
|
||||
|
||||
USB_OTG_GLB->GINTSTS |= USB_OTG_GINTSTS_PXFR_INCOMPISOOUT;
|
||||
}
|
||||
|
||||
if (gint_status & USB_OTG_GINTSTS_IISOIXFR) {
|
||||
daintmask = USB_OTG_DEV->DAINTMSK;
|
||||
daintmask >>= 16;
|
||||
|
||||
for (ep_idx = 1; ep_idx < CONFIG_USBDEV_EP_NUM; ep_idx++) {
|
||||
if (((BIT(ep_idx) & ~daintmask)) || (g_dwc2_udc[busid].in_ep[ep_idx].ep_type != USB_ENDPOINT_TYPE_ISOCHRONOUS))
|
||||
continue;
|
||||
|
||||
if (!(USB_OTG_INEP(ep_idx)->DIEPCTL & USB_OTG_DIEPCTL_USBAEP))
|
||||
continue;
|
||||
|
||||
if ((USB_OTG_DEV->DSTS & (1U << 8)) != 0U) {
|
||||
USB_OTG_INEP(ep_idx)->DIEPCTL |= USB_OTG_DIEPCTL_SD0PID_SEVNFRM;
|
||||
USB_OTG_INEP(ep_idx)->DIEPCTL &= ~USB_OTG_DIEPCTL_SODDFRM;
|
||||
} else {
|
||||
USB_OTG_INEP(ep_idx)->DIEPCTL &= ~USB_OTG_DIEPCTL_SD0PID_SEVNFRM;
|
||||
USB_OTG_INEP(ep_idx)->DIEPCTL |= USB_OTG_DIEPCTL_SODDFRM;
|
||||
}
|
||||
}
|
||||
USB_OTG_GLB->GINTSTS |= USB_OTG_GINTSTS_IISOIXFR;
|
||||
}
|
||||
|
||||
if (gint_status & USB_OTG_GINTSTS_SOF) {
|
||||
USB_OTG_GLB->GINTSTS |= USB_OTG_GINTSTS_SOF;
|
||||
USB_OTG_GLB->GINTSTS = USB_OTG_GINTSTS_SOF;
|
||||
}
|
||||
if (gint_status & USB_OTG_GINTSTS_USBSUSP) {
|
||||
USB_OTG_GLB->GINTSTS |= USB_OTG_GINTSTS_USBSUSP;
|
||||
USB_OTG_GLB->GINTSTS = USB_OTG_GINTSTS_USBSUSP;
|
||||
usbd_event_suspend_handler(busid);
|
||||
}
|
||||
if (gint_status & USB_OTG_GINTSTS_WKUINT) {
|
||||
USB_OTG_GLB->GINTSTS |= USB_OTG_GINTSTS_WKUINT;
|
||||
USB_OTG_GLB->GINTSTS = USB_OTG_GINTSTS_WKUINT;
|
||||
usbd_event_resume_handler(busid);
|
||||
}
|
||||
if (gint_status & USB_OTG_GINTSTS_OTGINT) {
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
* 1 location each for Bulk/Control endpoint for handling NAK/NYET scenario
|
||||
*/
|
||||
#ifndef CONFIG_USB_DWC2_RX_FIFO_SIZE
|
||||
#define CONFIG_USB_DWC2_RX_FIFO_SIZE ((1012 - CONFIG_USB_DWC2_NPTX_FIFO_SIZE - CONFIG_USB_DWC2_PTX_FIFO_SIZE) / 4)
|
||||
#define CONFIG_USB_DWC2_RX_FIFO_SIZE ((1012 - CONFIG_USB_DWC2_NPTX_FIFO_SIZE - CONFIG_USB_DWC2_PTX_FIFO_SIZE))
|
||||
#endif
|
||||
|
||||
#define USB_OTG_GLB ((DWC2_GlobalTypeDef *)(bus->hcd.reg_base))
|
||||
|
@ -498,9 +498,6 @@ int usb_hc_init(struct usbh_bus *bus)
|
|||
/* Restart the Phy Clock */
|
||||
USB_OTG_PCGCCTL = 0U;
|
||||
|
||||
dwc2_drivebus(bus, 1);
|
||||
usb_osal_msleep(200);
|
||||
|
||||
/* Set default Max speed support */
|
||||
USB_OTG_HOST->HCFG &= ~(USB_OTG_HCFG_FSLSS);
|
||||
|
||||
|
@ -524,6 +521,7 @@ int usb_hc_init(struct usbh_bus *bus)
|
|||
ret = dwc2_flush_txfifo(bus, 0x10U);
|
||||
ret = dwc2_flush_rxfifo(bus);
|
||||
|
||||
USB_OTG_GLB->GAHBCFG &= ~USB_OTG_GAHBCFG_HBSTLEN;
|
||||
USB_OTG_GLB->GAHBCFG |= USB_OTG_GAHBCFG_HBSTLEN_4;
|
||||
USB_OTG_GLB->GAHBCFG |= USB_OTG_GAHBCFG_DMAEN;
|
||||
|
||||
|
@ -531,6 +529,9 @@ int usb_hc_init(struct usbh_bus *bus)
|
|||
USB_OTG_GLB->GINTMSK |= (USB_OTG_GINTMSK_PRTIM | USB_OTG_GINTMSK_HCIM |
|
||||
USB_OTG_GINTSTS_DISCINT);
|
||||
|
||||
dwc2_drivebus(bus, 1);
|
||||
usb_osal_msleep(200);
|
||||
|
||||
USB_OTG_GLB->GAHBCFG |= USB_OTG_GAHBCFG_GINT;
|
||||
|
||||
return ret;
|
||||
|
@ -769,8 +770,8 @@ int usbh_submit_urb(struct usbh_urb *urb)
|
|||
}
|
||||
} else {
|
||||
/* Check if intr and iso pipe tx fifo is overflow */
|
||||
if (((USB_GET_MAXPACKETSIZE(urb->ep->wMaxPacketSize) == USB_ENDPOINT_TYPE_ISOCHRONOUS) ||
|
||||
(USB_GET_MAXPACKETSIZE(urb->ep->wMaxPacketSize) == USB_ENDPOINT_TYPE_INTERRUPT)) &&
|
||||
if (((USB_GET_ENDPOINT_TYPE(urb->ep->bmAttributes) == USB_ENDPOINT_TYPE_ISOCHRONOUS) ||
|
||||
(USB_GET_ENDPOINT_TYPE(urb->ep->bmAttributes) == USB_ENDPOINT_TYPE_INTERRUPT)) &&
|
||||
USB_GET_MAXPACKETSIZE(urb->ep->wMaxPacketSize) > (CONFIG_USB_DWC2_PTX_FIFO_SIZE * 4)) {
|
||||
return -USB_ERR_RANGE;
|
||||
} else {
|
||||
|
@ -895,6 +896,7 @@ static void dwc2_inchan_irq_handler(struct usbh_bus *bus, uint8_t ch_num)
|
|||
//printf("s1:%08x\r\n", chan_intstatus);
|
||||
|
||||
if (chan_intstatus & USB_OTG_HCINT_CHH) {
|
||||
USB_OTG_HC(ch_num)->HCINT = chan_intstatus;
|
||||
if (chan_intstatus & USB_OTG_HCINT_XFRC) {
|
||||
urb->errorcode = 0;
|
||||
|
||||
|
@ -948,7 +950,6 @@ static void dwc2_inchan_irq_handler(struct usbh_bus *bus, uint8_t ch_num)
|
|||
urb->errorcode = -USB_ERR_IO;
|
||||
dwc2_urb_waitup(urb);
|
||||
}
|
||||
USB_OTG_HC(ch_num)->HCINT = chan_intstatus;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -965,6 +966,7 @@ static void dwc2_outchan_irq_handler(struct usbh_bus *bus, uint8_t ch_num)
|
|||
//printf("s2:%08x\r\n", chan_intstatus);
|
||||
|
||||
if (chan_intstatus & USB_OTG_HCINT_CHH) {
|
||||
USB_OTG_HC(ch_num)->HCINT = chan_intstatus;
|
||||
if (chan_intstatus & USB_OTG_HCINT_XFRC) {
|
||||
urb->errorcode = 0;
|
||||
|
||||
|
@ -1029,7 +1031,6 @@ static void dwc2_outchan_irq_handler(struct usbh_bus *bus, uint8_t ch_num)
|
|||
urb->errorcode = -USB_ERR_IO;
|
||||
dwc2_urb_waitup(urb);
|
||||
}
|
||||
USB_OTG_HC(ch_num)->HCINT = chan_intstatus;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1130,4 +1131,4 @@ void USBH_IRQHandler(uint8_t busid)
|
|||
USB_OTG_GLB->GINTSTS = USB_OTG_GINTSTS_HCINT;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
# Note
|
||||
|
||||
## Support Chip List
|
||||
|
||||
### NXP
|
||||
|
||||
Modify USB_NOCACHE_RAM_SECTION
|
||||
|
||||
```
|
||||
#define USB_NOCACHE_RAM_SECTION __attribute__((section(".NonCacheable")))
|
||||
```
|
||||
|
||||
- MCXC444/MCXA153 (device only)
|
||||
- MCXN947
|
||||
|
||||
### MM32
|
||||
|
||||
- MM32F3/MM32F5
|
|
@ -0,0 +1,448 @@
|
|||
/*
|
||||
* Copyright (c) 2024, sakumisu
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#include "usbd_core.h"
|
||||
#include "usb_kinetis_reg.h"
|
||||
|
||||
#define USB_OTG_DEV ((KINETIS_TypeDef *)g_usbdev_bus[busid].reg_base)
|
||||
|
||||
/* Endpoint state */
|
||||
struct kinetis_ep_state {
|
||||
uint16_t ep_mps; /* Endpoint max packet size */
|
||||
uint8_t ep_type; /* Endpoint type */
|
||||
uint8_t ep_stalled; /* Endpoint stall flag */
|
||||
uint8_t ep_enable; /* Endpoint enable */
|
||||
bool ep_odd; /* Endpoint odd */
|
||||
uint8_t *xfer_buf;
|
||||
uint32_t xfer_len;
|
||||
uint32_t actual_xfer_len;
|
||||
};
|
||||
|
||||
/* Driver state */
|
||||
struct kinetis_udc {
|
||||
uint8_t dev_addr;
|
||||
struct kinetis_ep_state in_ep[CONFIG_USBDEV_EP_NUM]; /*!< IN endpoint parameters*/
|
||||
struct kinetis_ep_state out_ep[CONFIG_USBDEV_EP_NUM]; /*!< OUT endpoint parameters */
|
||||
} g_kinetis_udc[CONFIG_USBDEV_MAX_BUS];
|
||||
|
||||
USB_NOCACHE_RAM_SECTION __attribute__((aligned(512))) kinetis_bd_table_t g_kinetis_bdt[CONFIG_USBDEV_MAX_BUS];
|
||||
USB_NOCACHE_RAM_SECTION __attribute__((aligned(32))) uint8_t setup_packet[CONFIG_USBDEV_MAX_BUS][8];
|
||||
|
||||
static int kinetis_start_transfer(uint8_t busid, uint8_t ep, uint8_t *buffer, uint16_t buflen)
|
||||
{
|
||||
uint8_t ep_idx = USB_EP_GET_IDX(ep);
|
||||
uint8_t dir;
|
||||
uint8_t odd;
|
||||
uint16_t ep_mps;
|
||||
kinetis_bd_t *bd;
|
||||
kinetis_bd_t *next;
|
||||
|
||||
if (USB_EP_DIR_IS_OUT(ep)) {
|
||||
dir = 0;
|
||||
odd = g_kinetis_udc[busid].out_ep[ep_idx].ep_odd;
|
||||
ep_mps = g_kinetis_udc[busid].out_ep[ep_idx].ep_mps;
|
||||
} else {
|
||||
dir = 1;
|
||||
odd = g_kinetis_udc[busid].in_ep[ep_idx].ep_odd;
|
||||
ep_mps = g_kinetis_udc[busid].in_ep[ep_idx].ep_mps;
|
||||
}
|
||||
|
||||
bd = &g_kinetis_bdt[busid].table[ep_idx][dir][odd];
|
||||
|
||||
if (bd->own) {
|
||||
USB_LOG_INFO("ep%02x is busy\r\n", ep);
|
||||
return -1;
|
||||
}
|
||||
|
||||
bd->bc = buflen >= ep_mps ? ep_mps : buflen;
|
||||
bd->addr = (uint32_t)buffer;
|
||||
bd->own = 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void kinetis_read_setup(uint8_t busid)
|
||||
{
|
||||
uint8_t out_odd = g_kinetis_udc[busid].out_ep[0].ep_odd;
|
||||
uint8_t in_odd = g_kinetis_udc[busid].in_ep[0].ep_odd;
|
||||
|
||||
if (g_kinetis_bdt[busid].table[0][0][out_odd].own) {
|
||||
USB_LOG_INFO("ep0 is busy\r\n");
|
||||
return;
|
||||
}
|
||||
|
||||
g_kinetis_bdt[busid].table[0][0][out_odd].data = 0;
|
||||
g_kinetis_bdt[busid].table[0][0][out_odd ^ 1].data = 1;
|
||||
g_kinetis_bdt[busid].table[0][1][in_odd].data = 1;
|
||||
g_kinetis_bdt[busid].table[0][1][in_odd ^ 1].data = 0;
|
||||
|
||||
kinetis_start_transfer(busid, USB_CONTROL_OUT_EP0, setup_packet[busid], 8);
|
||||
}
|
||||
|
||||
__WEAK void usb_dc_low_level_init(uint8_t busid)
|
||||
{
|
||||
}
|
||||
|
||||
__WEAK void usb_dc_low_level_deinit(uint8_t busid)
|
||||
{
|
||||
}
|
||||
|
||||
int usb_dc_init(uint8_t busid)
|
||||
{
|
||||
usb_dc_low_level_init(busid);
|
||||
|
||||
memset(&g_kinetis_udc[busid], 0, sizeof(g_kinetis_udc[busid]));
|
||||
|
||||
USB_OTG_DEV->BDTPAGE1 = (uint8_t)((uintptr_t)&g_kinetis_bdt[busid] >> 8);
|
||||
USB_OTG_DEV->BDTPAGE2 = (uint8_t)((uintptr_t)&g_kinetis_bdt[busid] >> 16);
|
||||
USB_OTG_DEV->BDTPAGE3 = (uint8_t)((uintptr_t)&g_kinetis_bdt[busid] >> 24);
|
||||
|
||||
USB_OTG_DEV->INTEN = USB_INTEN_USBRSTEN_MASK | USB_INTEN_TOKDNEEN_MASK |
|
||||
USB_INTEN_SLEEPEN_MASK | USB_INTEN_RESUMEEN_MASK |
|
||||
USB_INTEN_ERROREN_MASK;
|
||||
|
||||
USB_OTG_DEV->CTL |= USB_CTL_USBENSOFEN_MASK;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usb_dc_deinit(uint8_t busid)
|
||||
{
|
||||
usb_dc_low_level_deinit(busid);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbd_set_address(uint8_t busid, const uint8_t addr)
|
||||
{
|
||||
g_kinetis_udc[busid].dev_addr = addr;
|
||||
|
||||
if (addr == 0) {
|
||||
USB_OTG_DEV->ADDR = 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbd_set_remote_wakeup(uint8_t busid)
|
||||
{
|
||||
USB_OTG_DEV->CTL |= USB_CTL_RESUME_MASK;
|
||||
|
||||
usbd_kinetis_delay_ms(10);
|
||||
|
||||
USB_OTG_DEV->CTL &= ~USB_CTL_RESUME_MASK;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t usbd_get_port_speed(uint8_t busid)
|
||||
{
|
||||
return USB_SPEED_FULL;
|
||||
}
|
||||
|
||||
int usbd_ep_open(uint8_t busid, const struct usb_endpoint_descriptor *ep)
|
||||
{
|
||||
uint8_t ep_idx = USB_EP_GET_IDX(ep->bEndpointAddress);
|
||||
uint8_t odd;
|
||||
uint8_t dir;
|
||||
kinetis_bd_t *bd;
|
||||
uint8_t regval;
|
||||
|
||||
/* Must not exceed max endpoint number */
|
||||
if (ep_idx >= CONFIG_USBDEV_EP_NUM) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (USB_EP_DIR_IS_OUT(ep->bEndpointAddress)) {
|
||||
g_kinetis_udc[busid].out_ep[ep_idx].ep_mps = USB_GET_MAXPACKETSIZE(ep->wMaxPacketSize);
|
||||
g_kinetis_udc[busid].out_ep[ep_idx].ep_type = USB_GET_ENDPOINT_TYPE(ep->bmAttributes);
|
||||
g_kinetis_udc[busid].out_ep[ep_idx].ep_enable = true;
|
||||
|
||||
dir = 0;
|
||||
odd = g_kinetis_udc[busid].out_ep[ep_idx].ep_odd;
|
||||
} else {
|
||||
g_kinetis_udc[busid].in_ep[ep_idx].ep_mps = USB_GET_MAXPACKETSIZE(ep->wMaxPacketSize);
|
||||
g_kinetis_udc[busid].in_ep[ep_idx].ep_type = USB_GET_ENDPOINT_TYPE(ep->bmAttributes);
|
||||
g_kinetis_udc[busid].in_ep[ep_idx].ep_enable = true;
|
||||
|
||||
dir = 1;
|
||||
odd = g_kinetis_udc[busid].in_ep[ep_idx].ep_odd;
|
||||
}
|
||||
|
||||
if (ep_idx != 0) {
|
||||
regval = USB_ENDPT_EPCTLDIS_MASK;
|
||||
regval |= (USB_GET_ENDPOINT_TYPE(ep->bmAttributes) != USB_ENDPOINT_TYPE_ISOCHRONOUS) ? USB_ENDPT_EPHSHK_MASK : 0;
|
||||
regval |= dir ? USB_ENDPT_EPTXEN_MASK : USB_ENDPT_EPRXEN_MASK;
|
||||
USB_OTG_DEV->ENDPOINT[ep_idx].ENDPT |= regval;
|
||||
|
||||
if (USB_GET_ENDPOINT_TYPE(ep->bmAttributes) != USB_ENDPOINT_TYPE_ISOCHRONOUS) {
|
||||
bd = &g_kinetis_bdt[busid].table[ep_idx][dir][odd];
|
||||
bd->dts = 1;
|
||||
bd->data = 0;
|
||||
|
||||
bd = &g_kinetis_bdt[busid].table[ep_idx][dir][odd ^ 1];
|
||||
bd->dts = 1;
|
||||
bd->data = 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbd_ep_close(uint8_t busid, const uint8_t ep)
|
||||
{
|
||||
uint8_t ep_idx = USB_EP_GET_IDX(ep);
|
||||
uint8_t dir;
|
||||
kinetis_bd_t *bd;
|
||||
|
||||
if (USB_EP_DIR_IS_OUT(ep)) {
|
||||
g_kinetis_udc[busid].out_ep[ep_idx].ep_enable = false;
|
||||
dir = 0;
|
||||
} else {
|
||||
g_kinetis_udc[busid].in_ep[ep_idx].ep_enable = false;
|
||||
dir = 1;
|
||||
}
|
||||
|
||||
bd = &g_kinetis_bdt[busid].table[ep_idx][dir][0];
|
||||
bd->head = 0;
|
||||
|
||||
bd = &g_kinetis_bdt[busid].table[ep_idx][dir][1];
|
||||
bd->head = 0;
|
||||
|
||||
USB_OTG_DEV->ENDPOINT[ep_idx].ENDPT &= ~(dir ? USB_ENDPT_EPTXEN_MASK : USB_ENDPT_EPRXEN_MASK);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbd_ep_set_stall(uint8_t busid, const uint8_t ep)
|
||||
{
|
||||
uint8_t ep_idx = USB_EP_GET_IDX(ep);
|
||||
kinetis_bd_t *bd;
|
||||
uint8_t odd;
|
||||
uint8_t dir;
|
||||
|
||||
if (0 == ep_idx) {
|
||||
USB_OTG_DEV->ENDPOINT[ep_idx].ENDPT |= USB_ENDPT_EPSTALL_MASK;
|
||||
|
||||
if (ep_idx == 0) {
|
||||
kinetis_read_setup(busid);
|
||||
}
|
||||
} else {
|
||||
if (USB_EP_DIR_IS_OUT(ep)) {
|
||||
dir = 0;
|
||||
odd = g_kinetis_udc[busid].out_ep[ep_idx].ep_odd;
|
||||
} else {
|
||||
dir = 1;
|
||||
odd = g_kinetis_udc[busid].in_ep[ep_idx].ep_odd;
|
||||
}
|
||||
|
||||
bd = &g_kinetis_bdt[busid].table[ep_idx][dir][odd];
|
||||
|
||||
bd->bdt_stall = 1;
|
||||
bd->own = 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbd_ep_clear_stall(uint8_t busid, const uint8_t ep)
|
||||
{
|
||||
uint8_t ep_idx = USB_EP_GET_IDX(ep);
|
||||
kinetis_bd_t *bd;
|
||||
uint8_t odd;
|
||||
uint8_t dir;
|
||||
|
||||
if (USB_EP_DIR_IS_OUT(ep)) {
|
||||
dir = 0;
|
||||
odd = g_kinetis_udc[busid].out_ep[ep_idx].ep_odd;
|
||||
} else {
|
||||
dir = 1;
|
||||
odd = g_kinetis_udc[busid].in_ep[ep_idx].ep_odd;
|
||||
}
|
||||
|
||||
bd = &g_kinetis_bdt[busid].table[ep_idx][dir][odd];
|
||||
|
||||
bd->own = 0;
|
||||
bd->bdt_stall = 0;
|
||||
bd->data = 0;
|
||||
|
||||
bd = &g_kinetis_bdt[busid].table[ep_idx][dir][odd ^ 1];
|
||||
bd->data = 1;
|
||||
|
||||
uint8_t regval = USB_OTG_DEV->ENDPOINT[ep_idx].ENDPT;
|
||||
if (regval & USB_ENDPT_EPSTALL_MASK) {
|
||||
USB_OTG_DEV->ENDPOINT[ep_idx].ENDPT = regval & ~USB_ENDPT_EPSTALL_MASK;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbd_ep_is_stalled(uint8_t busid, const uint8_t ep, uint8_t *stalled)
|
||||
{
|
||||
uint8_t ep_idx = USB_EP_GET_IDX(ep);
|
||||
|
||||
uint8_t regval = USB_OTG_DEV->ENDPOINT[ep_idx].ENDPT;
|
||||
if (regval & USB_ENDPT_EPSTALL_MASK) {
|
||||
*stalled = 1;
|
||||
} else {
|
||||
*stalled = 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbd_ep_start_write(uint8_t busid, const uint8_t ep, const uint8_t *data,
|
||||
uint32_t data_len)
|
||||
{
|
||||
uint8_t ep_idx = USB_EP_GET_IDX(ep);
|
||||
|
||||
if (!data && data_len) {
|
||||
return -1;
|
||||
}
|
||||
if (!g_kinetis_udc[busid].in_ep[ep_idx].ep_enable) {
|
||||
return -2;
|
||||
}
|
||||
|
||||
g_kinetis_udc[busid].in_ep[ep_idx].xfer_buf = (uint8_t *)data;
|
||||
g_kinetis_udc[busid].in_ep[ep_idx].xfer_len = data_len;
|
||||
g_kinetis_udc[busid].in_ep[ep_idx].actual_xfer_len = 0;
|
||||
|
||||
return kinetis_start_transfer(busid, ep, (uint8_t *)data, MIN(data_len, g_kinetis_udc[busid].in_ep[ep_idx].ep_mps));
|
||||
}
|
||||
|
||||
int usbd_ep_start_read(uint8_t busid, const uint8_t ep, uint8_t *data,
|
||||
uint32_t data_len)
|
||||
{
|
||||
uint8_t ep_idx = USB_EP_GET_IDX(ep);
|
||||
|
||||
if (!data && data_len) {
|
||||
return -1;
|
||||
}
|
||||
if (!g_kinetis_udc[busid].out_ep[ep_idx].ep_enable) {
|
||||
return -2;
|
||||
}
|
||||
|
||||
g_kinetis_udc[busid].out_ep[ep_idx].xfer_buf = (uint8_t *)data;
|
||||
g_kinetis_udc[busid].out_ep[ep_idx].xfer_len = data_len;
|
||||
g_kinetis_udc[busid].out_ep[ep_idx].actual_xfer_len = 0;
|
||||
|
||||
return kinetis_start_transfer(busid, ep, (uint8_t *)data, MIN(data_len, g_kinetis_udc[busid].out_ep[ep_idx].ep_mps));
|
||||
}
|
||||
|
||||
void USBD_IRQHandler(uint8_t busid)
|
||||
{
|
||||
uint8_t s;
|
||||
uint8_t pid;
|
||||
uint8_t ep_idx;
|
||||
uint8_t dir;
|
||||
uint8_t odd;
|
||||
uint16_t bc;
|
||||
uint8_t is = USB_OTG_DEV->ISTAT;
|
||||
uint8_t mask = USB_OTG_DEV->INTEN;
|
||||
kinetis_bd_t *bd;
|
||||
|
||||
USB_OTG_DEV->ISTAT = is & ~mask;
|
||||
is &= mask;
|
||||
|
||||
if (is & USB_ISTAT_ERROR_MASK) {
|
||||
uint32_t es = USB_OTG_DEV->ERRSTAT;
|
||||
USB_OTG_DEV->ERRSTAT = es;
|
||||
USB_OTG_DEV->ISTAT = is;
|
||||
}
|
||||
|
||||
if (is & USB_ISTAT_USBRST_MASK) {
|
||||
USB_OTG_DEV->ISTAT = is;
|
||||
USB_OTG_DEV->CTL |= USB_CTL_ODDRST_MASK;
|
||||
USB_OTG_DEV->ADDR = 0;
|
||||
|
||||
USB_OTG_DEV->ENDPOINT[0].ENDPT = USB_ENDPT_EPHSHK_MASK | USB_ENDPT_EPRXEN_MASK | USB_ENDPT_EPTXEN_MASK;
|
||||
for (uint8_t i = 1; i < 16; i++) {
|
||||
USB_OTG_DEV->ENDPOINT[i].ENDPT = 0;
|
||||
}
|
||||
|
||||
memset(&g_kinetis_bdt[busid], 0, sizeof(g_kinetis_bdt[busid]));
|
||||
memset(g_kinetis_udc[busid].in_ep, 0, sizeof(struct kinetis_ep_state) * CONFIG_USBDEV_EP_NUM);
|
||||
memset(g_kinetis_udc[busid].out_ep, 0, sizeof(struct kinetis_ep_state) * CONFIG_USBDEV_EP_NUM);
|
||||
usbd_event_reset_handler(busid);
|
||||
|
||||
kinetis_read_setup(busid);
|
||||
|
||||
USB_OTG_DEV->CTL &= ~USB_CTL_ODDRST_MASK;
|
||||
}
|
||||
|
||||
if (is & USB_ISTAT_SLEEP_MASK) {
|
||||
USB_OTG_DEV->ISTAT = USB_ISTAT_SLEEP_MASK;
|
||||
}
|
||||
|
||||
if (is & USB_ISTAT_RESUME_MASK) {
|
||||
USB_OTG_DEV->ISTAT = USB_ISTAT_RESUME_MASK;
|
||||
}
|
||||
|
||||
if (is & USB_ISTAT_SOFTOK_MASK) {
|
||||
USB_OTG_DEV->ISTAT = USB_ISTAT_SOFTOK_MASK;
|
||||
}
|
||||
|
||||
if (is & USB_ISTAT_STALL_MASK) {
|
||||
USB_OTG_DEV->ISTAT = USB_ISTAT_STALL_MASK;
|
||||
}
|
||||
|
||||
if (is & USB_ISTAT_TOKDNE_MASK) {
|
||||
s = USB_OTG_DEV->STAT;
|
||||
USB_OTG_DEV->ISTAT = USB_ISTAT_TOKDNE_MASK; /* must be cleared after get STAT */
|
||||
|
||||
ep_idx = (s & USB_STAT_ENDP_MASK) >> USB_STAT_ENDP_SHIFT;
|
||||
dir = (s & USB_STAT_TX_MASK) >> USB_STAT_TX_SHIFT;
|
||||
odd = (s & USB_STAT_ODD_MASK) >> USB_STAT_ODD_SHIFT;
|
||||
|
||||
bd = &g_kinetis_bdt[busid].table[ep_idx][dir][odd];
|
||||
|
||||
pid = bd->tok_pid;
|
||||
bc = bd->bc;
|
||||
|
||||
bd->bdt_stall = 0;
|
||||
bd->dts = 1;
|
||||
bd->ninc = 0;
|
||||
bd->keep = 0;
|
||||
|
||||
if (dir) {
|
||||
g_kinetis_udc[busid].in_ep[ep_idx].ep_odd = odd ^ 1;
|
||||
} else {
|
||||
g_kinetis_udc[busid].out_ep[ep_idx].ep_odd = odd ^ 1;
|
||||
}
|
||||
|
||||
if (pid == USB_TOKEN_PID_SETUP) {
|
||||
USB_OTG_DEV->CTL &= ~USB_CTL_TXSUSPENDTOKENBUSY_MASK;
|
||||
usbd_event_ep0_setup_complete_handler(busid, (uint8_t *)bd->addr);
|
||||
return;
|
||||
}
|
||||
|
||||
if (dir) {
|
||||
g_kinetis_udc[busid].in_ep[ep_idx].xfer_buf += bc;
|
||||
g_kinetis_udc[busid].in_ep[ep_idx].xfer_len -= bc;
|
||||
g_kinetis_udc[busid].in_ep[ep_idx].actual_xfer_len += bc;
|
||||
|
||||
if (g_kinetis_udc[busid].in_ep[ep_idx].xfer_len == 0) {
|
||||
usbd_event_ep_in_complete_handler(busid, ep_idx | 0x80, g_kinetis_udc[busid].in_ep[ep_idx].actual_xfer_len);
|
||||
} else {
|
||||
kinetis_start_transfer(busid, ep_idx | 0x80, g_kinetis_udc[busid].in_ep[ep_idx].xfer_buf,
|
||||
MIN(g_kinetis_udc[busid].in_ep[ep_idx].xfer_len, g_kinetis_udc[busid].in_ep[ep_idx].ep_mps));
|
||||
}
|
||||
} else {
|
||||
g_kinetis_udc[busid].out_ep[ep_idx].xfer_buf += bc;
|
||||
g_kinetis_udc[busid].out_ep[ep_idx].xfer_len -= bc;
|
||||
g_kinetis_udc[busid].out_ep[ep_idx].actual_xfer_len += bc;
|
||||
|
||||
if ((bc < g_kinetis_udc[busid].out_ep[ep_idx].ep_mps) || (g_kinetis_udc[busid].out_ep[ep_idx].xfer_len == 0)) {
|
||||
usbd_event_ep_out_complete_handler(busid, ep_idx, g_kinetis_udc[busid].out_ep[ep_idx].actual_xfer_len);
|
||||
} else {
|
||||
kinetis_start_transfer(busid, ep_idx, g_kinetis_udc[busid].out_ep[ep_idx].xfer_buf,
|
||||
MIN(g_kinetis_udc[busid].out_ep[ep_idx].xfer_len, g_kinetis_udc[busid].out_ep[ep_idx].ep_mps));
|
||||
}
|
||||
}
|
||||
|
||||
if ((bc == 0) && (ep_idx == 0)) {
|
||||
if ((g_kinetis_udc[busid].dev_addr > 0) && dir) {
|
||||
USB_OTG_DEV->ADDR = g_kinetis_udc[busid].dev_addr;
|
||||
g_kinetis_udc[busid].dev_addr = 0;
|
||||
}
|
||||
|
||||
kinetis_read_setup(busid);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
/*
|
||||
* Copyright (c) 2024, sakumisu
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#include "usbd_core.h"
|
||||
#include "fsl_common.h"
|
||||
#include "usb_kinetis_reg.h"
|
||||
|
||||
#define USB_OTG_DEV ((KINETIS_MCX_TypeDef *)g_usbdev_bus[busid].reg_base)
|
||||
|
||||
#if defined(MCXC444_H_)
|
||||
#define USBD_IRQ USB0_IRQHandler
|
||||
void USB_ClockInit(void)
|
||||
{
|
||||
SystemCoreClockUpdate();
|
||||
CLOCK_EnableUsbfs0Clock(kCLOCK_UsbSrcIrc48M, 48000000U);
|
||||
}
|
||||
#elif defined(MCXA153_H_)
|
||||
#define USBD_IRQ USB0_IRQHandler
|
||||
void USB_ClockInit(void)
|
||||
{
|
||||
RESET_PeripheralReset(kUSB0_RST_SHIFT_RSTn);
|
||||
CLOCK_EnableUsbfsClock();
|
||||
}
|
||||
#elif defined(MCXN947_CM33_CORE0_H_)
|
||||
#define USBD_IRQ USB0_FS_IRQHandler
|
||||
void USB_ClockInit(void)
|
||||
{
|
||||
CLOCK_AttachClk(kCLK_48M_to_USB0);
|
||||
CLOCK_EnableClock(kCLOCK_Usb0Ram);
|
||||
CLOCK_EnableClock(kCLOCK_Usb0Fs);
|
||||
CLOCK_EnableUsbfsClock();
|
||||
}
|
||||
#else
|
||||
#error "Unsupported MCU with Kinetis IP"
|
||||
#endif
|
||||
|
||||
void USBD_IRQ(void)
|
||||
{
|
||||
extern void USBD_IRQHandler(uint8_t busid);
|
||||
USBD_IRQHandler(0);
|
||||
}
|
||||
|
||||
void usb_dc_low_level_init(uint8_t busid)
|
||||
{
|
||||
USB_ClockInit();
|
||||
|
||||
uint8_t irqNumber;
|
||||
|
||||
uint8_t usbDeviceKhciIrq[] = USB_IRQS;
|
||||
irqNumber = usbDeviceKhciIrq[0];
|
||||
|
||||
/* Install isr, set priority, and enable IRQ. */
|
||||
NVIC_SetPriority((IRQn_Type)irqNumber, 3);
|
||||
EnableIRQ((IRQn_Type)irqNumber);
|
||||
|
||||
USB_OTG_DEV->USBTRC0 |= USB_USBTRC0_USBRESET_MASK;
|
||||
while (USB_OTG_DEV->USBTRC0 & USB_USBTRC0_USBRESET_MASK)
|
||||
;
|
||||
|
||||
USB_OTG_DEV->USBTRC0 |= USB_USBTRC0_VREGIN_STS(1); /* software must set this bit to 1 */
|
||||
USB_OTG_DEV->USBCTRL = 0;
|
||||
USB_OTG_DEV->CONTROL |= USB_CONTROL_DPPULLUPNONOTG_MASK;
|
||||
}
|
||||
|
||||
void usb_dc_low_level_deinit(uint8_t busid)
|
||||
{
|
||||
USB_OTG_DEV->CONTROL &= ~USB_CONTROL_DPPULLUPNONOTG_MASK;
|
||||
DisableIRQ((IRQn_Type)USB0_FS_IRQn);
|
||||
}
|
||||
|
||||
void usbd_kinetis_delay_ms(uint8_t ms)
|
||||
{
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
TODO
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue