rtt更新
This commit is contained in:
310
rt-thread/components/drivers/usb/cherryusb/class/adb/usbd_adb.c
Normal file
310
rt-thread/components/drivers/usb/cherryusb/class/adb/usbd_adb.c
Normal file
@@ -0,0 +1,310 @@
|
||||
/*
|
||||
* Copyright (c) 2024, sakumisu
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#include "usbd_core.h"
|
||||
#include "usbd_adb.h"
|
||||
|
||||
#define ADB_OUT_EP_IDX 0
|
||||
#define ADB_IN_EP_IDX 1
|
||||
|
||||
#define ADB_STATE_READ_MSG 0
|
||||
#define ADB_STATE_READ_DATA 1
|
||||
#define ADB_STATE_WRITE_MSG 2
|
||||
#define ADB_STATE_WRITE_DATA 3
|
||||
#define ADB_STATE_AWRITE_MSG 4
|
||||
#define ADB_STATE_AWRITE_DATA 5
|
||||
|
||||
#define MAX_PAYLOAD_V1 (4 * 1024)
|
||||
#define MAX_PAYLOAD_V2 (256 * 1024)
|
||||
#define MAX_PAYLOAD MAX_PAYLOAD_V1
|
||||
#define A_VERSION 0x01000000
|
||||
|
||||
#define A_SYNC 0x434e5953
|
||||
#define A_CNXN 0x4e584e43
|
||||
#define A_OPEN 0x4e45504f
|
||||
#define A_OKAY 0x59414b4f
|
||||
#define A_CLSE 0x45534c43
|
||||
#define A_WRTE 0x45545257
|
||||
#define A_AUTH 0x48545541
|
||||
|
||||
struct adb_msg {
|
||||
uint32_t command; /* command identifier constant (A_CNXN, ...) */
|
||||
uint32_t arg0; /* first argument */
|
||||
uint32_t arg1; /* second argument */
|
||||
uint32_t data_length; /* length of payload (0 is allowed) */
|
||||
uint32_t data_crc32; /* crc32 of data payload */
|
||||
uint32_t magic; /* command ^ 0xffffffff */
|
||||
};
|
||||
|
||||
struct adb_packet {
|
||||
struct adb_msg msg;
|
||||
uint8_t payload[MAX_PAYLOAD];
|
||||
};
|
||||
|
||||
struct usbd_adb {
|
||||
uint8_t state;
|
||||
uint8_t common_state;
|
||||
uint8_t write_state;
|
||||
bool writable;
|
||||
uint32_t localid;
|
||||
uint32_t shell_remoteid;
|
||||
uint32_t file_remoteid;
|
||||
} adb_client;
|
||||
|
||||
static struct usbd_endpoint adb_ep_data[2];
|
||||
|
||||
USB_NOCACHE_RAM_SECTION struct adb_packet tx_packet;
|
||||
USB_NOCACHE_RAM_SECTION struct adb_packet rx_packet;
|
||||
|
||||
static inline uint32_t adb_packet_checksum(struct adb_packet *packet)
|
||||
{
|
||||
uint32_t sum = 0;
|
||||
uint32_t i;
|
||||
|
||||
for (i = 0; i < packet->msg.data_length; ++i) {
|
||||
sum += (uint32_t)(packet->payload[i]);
|
||||
}
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
static uint32_t usbd_adb_get_remoteid(uint32_t localid)
|
||||
{
|
||||
if (localid == ADB_SHELL_LOALID) {
|
||||
return adb_client.shell_remoteid;
|
||||
} else {
|
||||
return adb_client.file_remoteid;
|
||||
}
|
||||
}
|
||||
|
||||
static void adb_send_msg(struct adb_packet *packet)
|
||||
{
|
||||
adb_client.common_state = ADB_STATE_WRITE_MSG;
|
||||
|
||||
packet->msg.data_crc32 = adb_packet_checksum(packet);
|
||||
packet->msg.magic = packet->msg.command ^ 0xffffffff;
|
||||
|
||||
usbd_ep_start_write(0, adb_ep_data[ADB_IN_EP_IDX].ep_addr, (uint8_t *)&packet->msg, sizeof(struct adb_msg));
|
||||
}
|
||||
|
||||
static void adb_send_okay(struct adb_packet *packet, uint32_t localid)
|
||||
{
|
||||
packet->msg.command = A_OKAY;
|
||||
packet->msg.arg0 = localid;
|
||||
packet->msg.arg1 = usbd_adb_get_remoteid(localid);
|
||||
packet->msg.data_length = 0;
|
||||
|
||||
adb_send_msg(&tx_packet);
|
||||
}
|
||||
|
||||
static void adb_send_close(struct adb_packet *packet, uint32_t localid, uint32_t remoteid)
|
||||
{
|
||||
packet->msg.command = A_CLSE;
|
||||
packet->msg.arg0 = localid;
|
||||
packet->msg.arg1 = remoteid;
|
||||
packet->msg.data_length = 0;
|
||||
|
||||
adb_send_msg(&tx_packet);
|
||||
}
|
||||
|
||||
void usbd_adb_bulk_out(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
{
|
||||
(void)ep;
|
||||
|
||||
if (adb_client.common_state == ADB_STATE_READ_MSG) {
|
||||
if (nbytes != sizeof(struct adb_msg)) {
|
||||
USB_LOG_ERR("invalid adb msg size:%d\r\n", nbytes);
|
||||
return;
|
||||
}
|
||||
|
||||
USB_LOG_DBG("command:%x arg0:%x arg1:%x len:%d\r\n",
|
||||
rx_packet.msg.command,
|
||||
rx_packet.msg.arg0,
|
||||
rx_packet.msg.arg1,
|
||||
rx_packet.msg.data_length);
|
||||
|
||||
if (rx_packet.msg.data_length) {
|
||||
/* setup next out ep read transfer */
|
||||
adb_client.common_state = ADB_STATE_READ_DATA;
|
||||
usbd_ep_start_read(busid, adb_ep_data[ADB_OUT_EP_IDX].ep_addr, rx_packet.payload, rx_packet.msg.data_length);
|
||||
} else {
|
||||
if (rx_packet.msg.command == A_CLSE) {
|
||||
adb_client.writable = false;
|
||||
usbd_adb_notify_write_done();
|
||||
USB_LOG_INFO("Close remoteid:%x\r\n", rx_packet.msg.arg0);
|
||||
}
|
||||
adb_client.common_state = ADB_STATE_READ_MSG;
|
||||
/* setup first out ep read transfer */
|
||||
usbd_ep_start_read(busid, adb_ep_data[ADB_OUT_EP_IDX].ep_addr, (uint8_t *)&rx_packet.msg, sizeof(struct adb_msg));
|
||||
}
|
||||
} else if (adb_client.common_state == ADB_STATE_READ_DATA) {
|
||||
switch (rx_packet.msg.command) {
|
||||
case A_SYNC:
|
||||
|
||||
break;
|
||||
case A_CNXN: /* CONNECT(version, maxdata, "system-id-string") */
|
||||
char *support_feature = "device::"
|
||||
"ro.product.name=cherryadb;"
|
||||
"ro.product.model=cherrysh;"
|
||||
"ro.product.device=cherryadb;"
|
||||
"features=cmd,shell_v1";
|
||||
|
||||
tx_packet.msg.command = A_CNXN;
|
||||
tx_packet.msg.arg0 = A_VERSION;
|
||||
tx_packet.msg.arg1 = MAX_PAYLOAD;
|
||||
tx_packet.msg.data_length = strlen(support_feature);
|
||||
memcpy(tx_packet.payload, support_feature, strlen(support_feature));
|
||||
|
||||
adb_send_msg(&tx_packet);
|
||||
|
||||
adb_client.writable = false;
|
||||
break;
|
||||
case A_OPEN: /* OPEN(local-id, 0, "destination") */
|
||||
rx_packet.payload[rx_packet.msg.data_length] = '\0';
|
||||
|
||||
if (strncmp((const char *)rx_packet.payload, "shell:", 6) == 0) {
|
||||
adb_client.localid = ADB_SHELL_LOALID;
|
||||
adb_client.shell_remoteid = rx_packet.msg.arg0;
|
||||
adb_send_okay(&tx_packet, ADB_SHELL_LOALID);
|
||||
|
||||
USB_LOG_INFO("Open shell service, remoteid:%x\r\n", rx_packet.msg.arg0);
|
||||
} else if (strncmp((const char *)rx_packet.payload, "sync:", 5) == 0) {
|
||||
adb_client.localid = ADB_FILE_LOALID;
|
||||
adb_client.file_remoteid = rx_packet.msg.arg0;
|
||||
adb_send_okay(&tx_packet, ADB_FILE_LOALID);
|
||||
USB_LOG_INFO("Open file service, remoteid:%x\r\n", rx_packet.msg.arg0);
|
||||
}
|
||||
break;
|
||||
case A_OKAY:
|
||||
|
||||
break;
|
||||
case A_CLSE:
|
||||
|
||||
break;
|
||||
case A_WRTE: /* WRITE(local-id, remote-id, "data") */
|
||||
if ((rx_packet.msg.arg0 == adb_client.shell_remoteid) && (rx_packet.msg.arg1 == ADB_SHELL_LOALID)) {
|
||||
adb_send_okay(&tx_packet, rx_packet.msg.arg1);
|
||||
} else if ((rx_packet.msg.arg0 == adb_client.file_remoteid) && (rx_packet.msg.arg1 == ADB_FILE_LOALID)) {
|
||||
adb_send_okay(&tx_packet, rx_packet.msg.arg1);
|
||||
} else {
|
||||
adb_send_close(&tx_packet, 0, rx_packet.msg.arg0);
|
||||
}
|
||||
break;
|
||||
case A_AUTH:
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void usbd_adb_bulk_in(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
{
|
||||
(void)ep;
|
||||
(void)nbytes;
|
||||
|
||||
if (adb_client.common_state == ADB_STATE_WRITE_MSG) {
|
||||
if (tx_packet.msg.data_length) {
|
||||
adb_client.common_state = ADB_STATE_WRITE_DATA;
|
||||
usbd_ep_start_write(busid, adb_ep_data[ADB_IN_EP_IDX].ep_addr, tx_packet.payload, tx_packet.msg.data_length);
|
||||
} else {
|
||||
if (rx_packet.msg.command == A_WRTE) {
|
||||
adb_client.writable = true;
|
||||
if (adb_client.localid == ADB_SHELL_LOALID) {
|
||||
usbd_adb_notify_shell_read(rx_packet.payload, rx_packet.msg.data_length);
|
||||
} else {
|
||||
}
|
||||
}
|
||||
adb_client.common_state = ADB_STATE_READ_MSG;
|
||||
/* setup first out ep read transfer */
|
||||
usbd_ep_start_read(busid, adb_ep_data[ADB_OUT_EP_IDX].ep_addr, (uint8_t *)&rx_packet.msg, sizeof(struct adb_msg));
|
||||
}
|
||||
} else if (adb_client.common_state == ADB_STATE_WRITE_DATA) {
|
||||
adb_client.common_state = ADB_STATE_READ_MSG;
|
||||
/* setup first out ep read transfer */
|
||||
usbd_ep_start_read(busid, adb_ep_data[ADB_OUT_EP_IDX].ep_addr, (uint8_t *)&rx_packet.msg, sizeof(struct adb_msg));
|
||||
} else if (adb_client.write_state == ADB_STATE_AWRITE_MSG) {
|
||||
if (tx_packet.msg.data_length) {
|
||||
adb_client.write_state = ADB_STATE_AWRITE_DATA;
|
||||
usbd_ep_start_write(busid, adb_ep_data[ADB_IN_EP_IDX].ep_addr, tx_packet.payload, tx_packet.msg.data_length);
|
||||
} else {
|
||||
}
|
||||
} else if (adb_client.write_state == ADB_STATE_AWRITE_DATA) {
|
||||
usbd_adb_notify_write_done();
|
||||
}
|
||||
}
|
||||
|
||||
void adb_notify_handler(uint8_t busid, uint8_t event, void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
|
||||
switch (event) {
|
||||
case USBD_EVENT_INIT:
|
||||
break;
|
||||
case USBD_EVENT_DEINIT:
|
||||
break;
|
||||
case USBD_EVENT_RESET:
|
||||
break;
|
||||
case USBD_EVENT_CONFIGURED:
|
||||
adb_client.common_state = ADB_STATE_READ_MSG;
|
||||
/* setup first out ep read transfer */
|
||||
usbd_ep_start_read(busid, adb_ep_data[ADB_OUT_EP_IDX].ep_addr, (uint8_t *)&rx_packet.msg, sizeof(struct adb_msg));
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
struct usbd_interface *usbd_adb_init_intf(uint8_t busid, struct usbd_interface *intf, uint8_t in_ep, uint8_t out_ep)
|
||||
{
|
||||
(void)busid;
|
||||
|
||||
intf->class_interface_handler = NULL;
|
||||
intf->class_endpoint_handler = NULL;
|
||||
intf->vendor_handler = NULL;
|
||||
intf->notify_handler = adb_notify_handler;
|
||||
|
||||
adb_ep_data[ADB_OUT_EP_IDX].ep_addr = out_ep;
|
||||
adb_ep_data[ADB_OUT_EP_IDX].ep_cb = usbd_adb_bulk_out;
|
||||
adb_ep_data[ADB_IN_EP_IDX].ep_addr = in_ep;
|
||||
adb_ep_data[ADB_IN_EP_IDX].ep_cb = usbd_adb_bulk_in;
|
||||
|
||||
usbd_add_endpoint(busid, &adb_ep_data[ADB_OUT_EP_IDX]);
|
||||
usbd_add_endpoint(busid, &adb_ep_data[ADB_IN_EP_IDX]);
|
||||
|
||||
return intf;
|
||||
}
|
||||
|
||||
bool usbd_adb_can_write(void)
|
||||
{
|
||||
return adb_client.writable;
|
||||
}
|
||||
|
||||
int usbd_abd_write(uint32_t localid, const uint8_t *data, uint32_t len)
|
||||
{
|
||||
struct adb_packet *packet;
|
||||
|
||||
packet = &tx_packet;
|
||||
packet->msg.command = A_WRTE;
|
||||
packet->msg.arg0 = localid;
|
||||
packet->msg.arg1 = usbd_adb_get_remoteid(localid);
|
||||
packet->msg.data_length = len;
|
||||
memcpy(packet->payload, data, len);
|
||||
|
||||
packet->msg.data_crc32 = adb_packet_checksum(packet);
|
||||
packet->msg.magic = packet->msg.command ^ 0xffffffff;
|
||||
|
||||
adb_client.write_state = ADB_STATE_AWRITE_MSG;
|
||||
usbd_ep_start_write(0, adb_ep_data[ADB_IN_EP_IDX].ep_addr, (uint8_t *)&packet->msg, sizeof(struct adb_msg));
|
||||
return 0;
|
||||
}
|
||||
|
||||
void usbd_adb_close(uint32_t localid)
|
||||
{
|
||||
adb_send_close(&tx_packet, 0, usbd_adb_get_remoteid(localid));
|
||||
}
|
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright (c) 2024, sakumisu
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#ifndef USBD_ADB_H
|
||||
#define USBD_ADB_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define ADB_SHELL_LOALID 0x01
|
||||
#define ADB_FILE_LOALID 0x02
|
||||
|
||||
// clang-format off
|
||||
#define ADB_DESCRIPTOR_INIT(bFirstInterface, in_ep, out_ep, wMaxPacketSize) \
|
||||
USB_INTERFACE_DESCRIPTOR_INIT(bFirstInterface, 0x00, 0x02, 0xff, 0x42, 0x01, 0x02), \
|
||||
USB_ENDPOINT_DESCRIPTOR_INIT(in_ep, 0x02, wMaxPacketSize, 0x00), \
|
||||
USB_ENDPOINT_DESCRIPTOR_INIT(out_ep, 0x02, wMaxPacketSize, 0x00)
|
||||
// clang-format on
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct usbd_interface *usbd_adb_init_intf(uint8_t busid, struct usbd_interface *intf, uint8_t in_ep, uint8_t out_ep);
|
||||
|
||||
void usbd_adb_notify_shell_read(uint8_t *data, uint32_t len);
|
||||
void usbd_adb_notify_file_read(uint8_t *data, uint32_t len);
|
||||
void usbd_adb_notify_write_done(void);
|
||||
bool usbd_adb_can_write(void);
|
||||
int usbd_abd_write(uint32_t localid, const uint8_t *data, uint32_t len);
|
||||
void usbd_adb_close(uint32_t localid);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* USBD_ADB_H */
|
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (c) 2024, sakumisu
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#ifndef USB_AOA_H
|
||||
#define USB_AOA_H
|
||||
|
||||
//AOA 1.0
|
||||
#define AOA_ACCESSORY_VENDOR_ID 0x18D1
|
||||
#define AOA_ACCESSORY_PRODUCT_ID 0x2D00
|
||||
#define AOA_ACCESSORY_ADB_PRODUCT_ID 0x2D01
|
||||
|
||||
//AOA 2.0
|
||||
#define AOA_AUDIO_PRODUCT_ID 0x2D02
|
||||
#define AOA_AUDIO_ADB_PRODUCT_ID 0x2D03
|
||||
#define AOA_ACCESSORY_AUDIO_PRODUCT_ID 0x2D04
|
||||
#define AOA_ACCESSORY_AUDIO_ADB_PRODUCT_ID 0x2D05
|
||||
|
||||
//AOA 1.0
|
||||
#define AOA_ACCESSORY_GET_PROTOCOL 51
|
||||
#define AOA_ACCESSORY_SEND_STRING 52
|
||||
#define AOA_ACCESSORY_START 53
|
||||
|
||||
//AOA 2.0
|
||||
#define AOA_ACCESSORY_REGISTER_HID 54
|
||||
#define AOA_ACCESSORY_UNREGISTER_HID 55
|
||||
#define AOA_ACCESSORY_SET_HID_REPORT_DESC 56
|
||||
#define AOA_ACCESSORY_SEND_HID_EVENT 57
|
||||
#define AOA_ACCESSORY_SET_AUDIO_MODE 58
|
||||
|
||||
#define AOA_ACCESSORY_STRING_MANUFACTURER 0
|
||||
#define AOA_ACCESSORY_STRING_MODEL 1
|
||||
#define AOA_ACCESSORY_STRING_DESCRIPTION 2
|
||||
#define AOA_ACCESSORY_STRING_VERSION 3
|
||||
#define AOA_ACCESSORY_STRING_URI 4
|
||||
#define AOA_ACCESSORY_STRING_SERIAL 5
|
||||
|
||||
struct aoa_string_info {
|
||||
char acc_manufacturer[64];
|
||||
char acc_model[64];
|
||||
char acc_description[64];
|
||||
char acc_version[64];
|
||||
char acc_uri[64];
|
||||
char acc_serial[64];
|
||||
};
|
||||
|
||||
#endif /* USB_AOA_H */
|
289
rt-thread/components/drivers/usb/cherryusb/class/aoa/usbh_aoa.c
Normal file
289
rt-thread/components/drivers/usb/cherryusb/class/aoa/usbh_aoa.c
Normal file
@@ -0,0 +1,289 @@
|
||||
/*
|
||||
* Copyright (c) 2024, sakumisu
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#include "usbh_core.h"
|
||||
#include "usbh_aoa.h"
|
||||
|
||||
#undef USB_DBG_TAG
|
||||
#define USB_DBG_TAG "usbh_aoa"
|
||||
#include "usb_log.h"
|
||||
|
||||
#define DEV_FORMAT "/dev/aoa"
|
||||
|
||||
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_aoa_buffer[128];
|
||||
|
||||
static struct usbh_aoa g_aoa_class;
|
||||
|
||||
int usbh_aoa_switch(struct usbh_hubport *hport, struct aoa_string_info *info)
|
||||
{
|
||||
struct usb_setup_packet *setup;
|
||||
int ret;
|
||||
|
||||
setup = hport->setup;
|
||||
|
||||
if (setup == NULL) {
|
||||
return -USB_ERR_INVAL;
|
||||
}
|
||||
|
||||
USB_LOG_INFO("Try switch into aoa mode\r\n");
|
||||
|
||||
setup->bmRequestType = USB_REQUEST_DIR_IN | USB_REQUEST_VENDOR | USB_REQUEST_RECIPIENT_DEVICE;
|
||||
setup->bRequest = AOA_ACCESSORY_GET_PROTOCOL;
|
||||
setup->wValue = 0;
|
||||
setup->wIndex = 0;
|
||||
setup->wLength = 2;
|
||||
|
||||
ret = usbh_control_transfer(hport, setup, g_aoa_buffer);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
USB_LOG_INFO("AOA version: v%d.%d\r\n", g_aoa_buffer[0], g_aoa_buffer[1]);
|
||||
|
||||
setup->bmRequestType = USB_REQUEST_DIR_OUT | USB_REQUEST_VENDOR | USB_REQUEST_RECIPIENT_DEVICE;
|
||||
setup->bRequest = AOA_ACCESSORY_SEND_STRING;
|
||||
setup->wValue = 0;
|
||||
setup->wIndex = AOA_ACCESSORY_STRING_MANUFACTURER;
|
||||
setup->wLength = strlen(info->acc_manufacturer) + 1;
|
||||
|
||||
memcpy(g_aoa_buffer, info->acc_manufacturer, strlen(info->acc_manufacturer));
|
||||
ret = usbh_control_transfer(hport, setup, g_aoa_buffer);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
setup->bmRequestType = USB_REQUEST_DIR_OUT | USB_REQUEST_VENDOR | USB_REQUEST_RECIPIENT_DEVICE;
|
||||
setup->bRequest = AOA_ACCESSORY_SEND_STRING;
|
||||
setup->wValue = 0;
|
||||
setup->wIndex = AOA_ACCESSORY_STRING_MODEL;
|
||||
setup->wLength = strlen(info->acc_model) + 1;
|
||||
|
||||
memcpy(g_aoa_buffer, info->acc_model, strlen(info->acc_model));
|
||||
ret = usbh_control_transfer(hport, setup, g_aoa_buffer);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
setup->bmRequestType = USB_REQUEST_DIR_OUT | USB_REQUEST_VENDOR | USB_REQUEST_RECIPIENT_DEVICE;
|
||||
setup->bRequest = AOA_ACCESSORY_SEND_STRING;
|
||||
setup->wValue = 0;
|
||||
setup->wIndex = AOA_ACCESSORY_STRING_DESCRIPTION;
|
||||
setup->wLength = strlen(info->acc_description) + 1;
|
||||
|
||||
memcpy(g_aoa_buffer, info->acc_description, strlen(info->acc_description));
|
||||
ret = usbh_control_transfer(hport, setup, g_aoa_buffer);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
setup->bmRequestType = USB_REQUEST_DIR_OUT | USB_REQUEST_VENDOR | USB_REQUEST_RECIPIENT_DEVICE;
|
||||
setup->bRequest = AOA_ACCESSORY_SEND_STRING;
|
||||
setup->wValue = 0;
|
||||
setup->wIndex = AOA_ACCESSORY_STRING_VERSION;
|
||||
setup->wLength = strlen(info->acc_version) + 1;
|
||||
|
||||
memcpy(g_aoa_buffer, info->acc_version, strlen(info->acc_version));
|
||||
ret = usbh_control_transfer(hport, setup, g_aoa_buffer);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
setup->bmRequestType = USB_REQUEST_DIR_OUT | USB_REQUEST_VENDOR | USB_REQUEST_RECIPIENT_DEVICE;
|
||||
setup->bRequest = AOA_ACCESSORY_SEND_STRING;
|
||||
setup->wValue = 0;
|
||||
setup->wIndex = AOA_ACCESSORY_STRING_URI;
|
||||
setup->wLength = strlen(info->acc_uri) + 1;
|
||||
|
||||
memcpy(g_aoa_buffer, info->acc_uri, strlen(info->acc_uri));
|
||||
ret = usbh_control_transfer(hport, setup, g_aoa_buffer);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
setup->bmRequestType = USB_REQUEST_DIR_OUT | USB_REQUEST_VENDOR | USB_REQUEST_RECIPIENT_DEVICE;
|
||||
setup->bRequest = AOA_ACCESSORY_SEND_STRING;
|
||||
setup->wValue = 0;
|
||||
setup->wIndex = AOA_ACCESSORY_STRING_SERIAL;
|
||||
setup->wLength = strlen(info->acc_serial) + 1;
|
||||
|
||||
memcpy(g_aoa_buffer, info->acc_serial, strlen(info->acc_serial));
|
||||
ret = usbh_control_transfer(hport, setup, g_aoa_buffer);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
setup->bmRequestType = USB_REQUEST_DIR_OUT | USB_REQUEST_VENDOR | USB_REQUEST_RECIPIENT_DEVICE;
|
||||
setup->bRequest = AOA_ACCESSORY_START;
|
||||
setup->wValue = 0;
|
||||
setup->wIndex = 0;
|
||||
setup->wLength = 0;
|
||||
|
||||
ret = usbh_control_transfer(hport, setup, NULL);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
USB_LOG_INFO("Switch into aoa mode success, wait usb device restart...\r\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbh_aoa_register_hid(struct usbh_aoa *aoa_class, uint16_t id, uint8_t *report, uint32_t report_len)
|
||||
{
|
||||
struct usb_setup_packet *setup;
|
||||
int ret;
|
||||
uint8_t len;
|
||||
uint32_t offset;
|
||||
|
||||
if (!aoa_class || !aoa_class->hport) {
|
||||
return -USB_ERR_INVAL;
|
||||
}
|
||||
setup = aoa_class->hport->setup;
|
||||
|
||||
setup->bmRequestType = USB_REQUEST_DIR_OUT | USB_REQUEST_VENDOR | USB_REQUEST_RECIPIENT_DEVICE;
|
||||
setup->bRequest = AOA_ACCESSORY_REGISTER_HID;
|
||||
setup->wValue = id;
|
||||
setup->wIndex = report_len;
|
||||
setup->wLength = 0;
|
||||
|
||||
ret = usbh_control_transfer(aoa_class->hport, setup, NULL);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
offset = 0;
|
||||
while (report_len > 0) {
|
||||
len = report_len > 64 ? 64 : report_len;
|
||||
|
||||
setup->bmRequestType = USB_REQUEST_DIR_OUT | USB_REQUEST_VENDOR | USB_REQUEST_RECIPIENT_DEVICE;
|
||||
setup->bRequest = AOA_ACCESSORY_SET_HID_REPORT_DESC;
|
||||
setup->wValue = id;
|
||||
setup->wIndex = offset;
|
||||
setup->wLength = len;
|
||||
|
||||
memcpy(g_aoa_buffer, report + offset, len);
|
||||
ret = usbh_control_transfer(aoa_class->hport, setup, g_aoa_buffer);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
offset += len;
|
||||
report_len -= len;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int usbh_aoa_send_hid_event(struct usbh_aoa *aoa_class, uint16_t id, uint8_t *event, uint32_t event_len)
|
||||
{
|
||||
struct usb_setup_packet *setup;
|
||||
int ret;
|
||||
uint8_t len;
|
||||
uint32_t offset;
|
||||
|
||||
if (!aoa_class || !aoa_class->hport) {
|
||||
return -USB_ERR_INVAL;
|
||||
}
|
||||
setup = aoa_class->hport->setup;
|
||||
|
||||
setup->bmRequestType = USB_REQUEST_DIR_OUT | USB_REQUEST_VENDOR | USB_REQUEST_RECIPIENT_DEVICE;
|
||||
setup->bRequest = AOA_ACCESSORY_SEND_HID_EVENT;
|
||||
setup->wValue = id;
|
||||
setup->wIndex = 0;
|
||||
setup->wLength = event_len;
|
||||
|
||||
memcpy(g_aoa_buffer, event, event_len);
|
||||
return usbh_control_transfer(aoa_class->hport, setup, event);
|
||||
}
|
||||
|
||||
static int usbh_aoa_connect(struct usbh_hubport *hport, uint8_t intf)
|
||||
{
|
||||
struct usb_endpoint_descriptor *ep_desc;
|
||||
int ret = 0;
|
||||
|
||||
struct usbh_aoa *aoa_class = &g_aoa_class;
|
||||
|
||||
memset(aoa_class, 0, sizeof(struct usbh_aoa));
|
||||
|
||||
aoa_class->hport = hport;
|
||||
aoa_class->intf = intf;
|
||||
|
||||
hport->config.intf[intf].priv = aoa_class;
|
||||
|
||||
for (uint8_t i = 0; i < hport->config.intf[intf].altsetting[0].intf_desc.bNumEndpoints; i++) {
|
||||
ep_desc = &hport->config.intf[intf].altsetting[0].ep[i].ep_desc;
|
||||
|
||||
if (ep_desc->bEndpointAddress & 0x80) {
|
||||
USBH_EP_INIT(aoa_class->bulkin, ep_desc);
|
||||
} else {
|
||||
USBH_EP_INIT(aoa_class->bulkout, ep_desc);
|
||||
}
|
||||
}
|
||||
|
||||
strncpy(hport->config.intf[intf].devname, DEV_FORMAT, CONFIG_USBHOST_DEV_NAMELEN);
|
||||
|
||||
USB_LOG_INFO("Register AOA Class:%s\r\n", hport->config.intf[intf].devname);
|
||||
|
||||
usbh_aoa_run(aoa_class);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int usbh_aoa_disconnect(struct usbh_hubport *hport, uint8_t intf)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
struct usbh_aoa *aoa_class = (struct usbh_aoa *)hport->config.intf[intf].priv;
|
||||
|
||||
if (aoa_class) {
|
||||
if (aoa_class->bulkin) {
|
||||
usbh_kill_urb(&aoa_class->bulkin_urb);
|
||||
}
|
||||
|
||||
if (aoa_class->bulkout) {
|
||||
usbh_kill_urb(&aoa_class->bulkout_urb);
|
||||
}
|
||||
|
||||
if (hport->config.intf[intf].devname[0] != '\0') {
|
||||
USB_LOG_INFO("Unregister AOA Class:%s\r\n", hport->config.intf[intf].devname);
|
||||
usbh_aoa_stop(aoa_class);
|
||||
}
|
||||
|
||||
memset(aoa_class, 0, sizeof(struct usbh_aoa));
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
__WEAK void usbh_aoa_run(struct usbh_aoa *aoa_class)
|
||||
{
|
||||
(void)aoa_class;
|
||||
}
|
||||
|
||||
__WEAK void usbh_aoa_stop(struct usbh_aoa *aoa_class)
|
||||
{
|
||||
(void)aoa_class;
|
||||
}
|
||||
|
||||
static const uint16_t aoa_id_table[][2] = {
|
||||
{ AOA_ACCESSORY_VENDOR_ID, AOA_ACCESSORY_PRODUCT_ID },
|
||||
{ AOA_ACCESSORY_VENDOR_ID, AOA_ACCESSORY_ADB_PRODUCT_ID },
|
||||
{ AOA_ACCESSORY_VENDOR_ID, AOA_AUDIO_PRODUCT_ID },
|
||||
{ AOA_ACCESSORY_VENDOR_ID, AOA_AUDIO_ADB_PRODUCT_ID },
|
||||
{ AOA_ACCESSORY_VENDOR_ID, AOA_ACCESSORY_AUDIO_PRODUCT_ID },
|
||||
{ AOA_ACCESSORY_VENDOR_ID, AOA_ACCESSORY_AUDIO_ADB_PRODUCT_ID },
|
||||
{ 0, 0 },
|
||||
};
|
||||
|
||||
const struct usbh_class_driver aoa_class_driver = {
|
||||
.driver_name = "aoa",
|
||||
.connect = usbh_aoa_connect,
|
||||
.disconnect = usbh_aoa_disconnect
|
||||
};
|
||||
|
||||
CLASS_INFO_DEFINE const struct usbh_class_info aoa_intf_class_info = {
|
||||
.match_flags = USB_CLASS_MATCH_VID_PID | USB_CLASS_MATCH_INTF_CLASS | USB_CLASS_MATCH_INTF_SUBCLASS,
|
||||
.bInterfaceClass = 0xff,
|
||||
.bInterfaceSubClass = 0xff,
|
||||
.bInterfaceProtocol = 0x00,
|
||||
.id_table = aoa_id_table,
|
||||
.class_driver = &aoa_class_driver
|
||||
};
|
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (c) 2024, sakumisu
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#ifndef USBH_AOA_H
|
||||
#define USBH_AOA_H
|
||||
|
||||
#include "usb_aoa.h"
|
||||
|
||||
struct usbh_aoa {
|
||||
struct usbh_hubport *hport;
|
||||
struct usb_endpoint_descriptor *bulkin; /* Bulk IN endpoint */
|
||||
struct usb_endpoint_descriptor *bulkout; /* Bulk OUT endpoint */
|
||||
|
||||
struct usbh_urb bulkout_urb;
|
||||
struct usbh_urb bulkin_urb;
|
||||
|
||||
uint8_t intf;
|
||||
uint8_t minor;
|
||||
|
||||
void *user_data;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int usbh_aoa_switch(struct usbh_hubport *hport, struct aoa_string_info *info);
|
||||
int usbh_aoa_register_hid(struct usbh_aoa *aoa_class, uint16_t id, uint8_t *report, uint32_t report_len);
|
||||
int usbh_aoa_send_hid_event(struct usbh_aoa *aoa_class, uint16_t id, uint8_t *event, uint32_t event_len);
|
||||
|
||||
void usbh_aoa_run(struct usbh_aoa *aoa_class);
|
||||
void usbh_aoa_stop(struct usbh_aoa *aoa_class);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* USBH_AOA_H */
|
@@ -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
|
||||
@@ -648,6 +648,18 @@ struct audio_cs_if_ac_feature_unit_descriptor {
|
||||
|
||||
#define AUDIO_SIZEOF_AC_FEATURE_UNIT_DESC(ch, n) (7 + (ch + 1) * n)
|
||||
|
||||
struct audio_cs_if_ac_selector_unit_descriptor {
|
||||
uint8_t bLength;
|
||||
uint8_t bDescriptorType;
|
||||
uint8_t bDescriptorSubtype;
|
||||
uint8_t bUnitID;
|
||||
uint8_t bNrInPins;
|
||||
uint8_t baSourceID[1];
|
||||
uint8_t iSelector;
|
||||
} __PACKED;
|
||||
|
||||
#define AUDIO_SIZEOF_AC_SELECTOR_UNIT_DESC(n) (6 + n)
|
||||
|
||||
struct audio_cs_if_as_general_descriptor {
|
||||
uint8_t bLength;
|
||||
uint8_t bDescriptorType;
|
||||
@@ -812,6 +824,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 +1162,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 +1268,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))
|
||||
|
@@ -62,7 +62,7 @@ static int audio_class_interface_request_handler(uint8_t busid, struct usb_setup
|
||||
setup->bRequest);
|
||||
|
||||
uint8_t entity_id;
|
||||
uint8_t ep;
|
||||
uint8_t ep = 0;
|
||||
uint8_t subtype = 0x01;
|
||||
uint8_t control_selector;
|
||||
uint8_t ch;
|
||||
@@ -136,27 +136,26 @@ static int audio_class_interface_request_handler(uint8_t busid, struct usb_setup
|
||||
memcpy(&volume, *data, *len);
|
||||
if (volume < 0x8000) {
|
||||
volume_db = volume / 256;
|
||||
} else if (volume > 0x8000) {
|
||||
volume_db = (0xffff - volume + 1) / -256;
|
||||
} else {
|
||||
volume_db = (volume - 0x10000) / 256;
|
||||
}
|
||||
volume_db += 128; /* 0 ~ 255 */
|
||||
USB_LOG_DBG("Set ep:0x%02x ch:%d volume:0x%04x\r\n", ep, ch, volume);
|
||||
USB_LOG_DBG("Set ep:0x%02x ch:%d vol_hex:0x%04x, vol_db:%d dB\r\n", ep, ch, volume, volume_db);
|
||||
usbd_audio_set_volume(busid, ep, ch, volume_db);
|
||||
break;
|
||||
case AUDIO_REQUEST_GET_CUR:
|
||||
volume_db = usbd_audio_get_volume(busid, ep, ch);
|
||||
volume_db -= 128;
|
||||
if (volume_db >= 0) {
|
||||
volume = volume_db * 256;
|
||||
} else {
|
||||
volume = volume_db * 256 + 0xffff + 1;
|
||||
volume = volume_db * 256 + 0x10000;
|
||||
}
|
||||
USB_LOG_DBG("Get ep:0x%02x ch:%d vol_hex:0x%04x, vol_db:%d dB\r\n", ep, ch, volume, volume_db);
|
||||
memcpy(*data, &volume, 2);
|
||||
*len = 2;
|
||||
break;
|
||||
case AUDIO_REQUEST_GET_MIN:
|
||||
(*data)[0] = 0x00; /* -2560/256 dB */
|
||||
(*data)[1] = 0xdb;
|
||||
(*data)[0] = 0x00; /* -100 dB */
|
||||
(*data)[1] = 0x9c;
|
||||
*len = 2;
|
||||
break;
|
||||
case AUDIO_REQUEST_GET_MAX:
|
||||
@@ -165,7 +164,7 @@ static int audio_class_interface_request_handler(uint8_t busid, struct usb_setup
|
||||
*len = 2;
|
||||
break;
|
||||
case AUDIO_REQUEST_GET_RES:
|
||||
(*data)[0] = 0x00; /* -256/256 dB */
|
||||
(*data)[0] = 0x00; /* 1 dB */
|
||||
(*data)[1] = 0x01;
|
||||
*len = 2;
|
||||
break;
|
||||
@@ -178,22 +177,31 @@ static int audio_class_interface_request_handler(uint8_t busid, struct usb_setup
|
||||
case AUDIO_REQUEST_CUR:
|
||||
if (setup->bmRequestType & USB_REQUEST_DIR_MASK) {
|
||||
volume_db = usbd_audio_get_volume(busid, ep, ch);
|
||||
volume = volume_db;
|
||||
if (volume_db >= 0) {
|
||||
volume = volume_db * 256;
|
||||
} else {
|
||||
volume = volume_db * 256 + 0x10000;
|
||||
}
|
||||
USB_LOG_DBG("Get ep:0x%02x ch:%d vol_hex:0x%04x, vol_db:%d dB\r\n", ep, ch, volume, volume_db);
|
||||
memcpy(*data, &volume, 2);
|
||||
*len = 2;
|
||||
} else {
|
||||
memcpy(&volume, *data, *len);
|
||||
volume_db = volume;
|
||||
USB_LOG_DBG("Set ep:0x%02x ch:%d volume:0x%02x\r\n", ep, ch, volume);
|
||||
if (volume < 0x8000) {
|
||||
volume_db = volume / 256;
|
||||
} else {
|
||||
volume_db = (volume - 0x10000) / 256;
|
||||
}
|
||||
USB_LOG_DBG("Set ep:0x%02x ch:%d vol_hex:0x%04x, vol_db:%d dB\r\n", ep, ch, volume, volume_db);
|
||||
usbd_audio_set_volume(busid, ep, ch, volume_db);
|
||||
}
|
||||
break;
|
||||
case AUDIO_REQUEST_RANGE:
|
||||
if (setup->bmRequestType & USB_REQUEST_DIR_MASK) {
|
||||
*((uint16_t *)(*data + 0)) = 1;
|
||||
*((uint16_t *)(*data + 2)) = 0;
|
||||
*((uint16_t *)(*data + 4)) = 100;
|
||||
*((uint16_t *)(*data + 6)) = 1;
|
||||
*((uint16_t *)(*data + 2)) = 0x9c00; /* MIN -100 dB */
|
||||
*((uint16_t *)(*data + 4)) = 0x0000; /* MAX 0 dB */
|
||||
*((uint16_t *)(*data + 6)) = 0x100; /* RES 1 dB */
|
||||
*len = 8;
|
||||
} else {
|
||||
}
|
||||
@@ -287,7 +295,7 @@ static void audio_notify_handler(uint8_t busid, uint8_t event, void *arg)
|
||||
}
|
||||
}
|
||||
|
||||
struct usbd_interface *usbd_audio_init_intf(uint8_t busid,
|
||||
struct usbd_interface *usbd_audio_init_intf(uint8_t busid,
|
||||
struct usbd_interface *intf,
|
||||
uint16_t uac_version,
|
||||
struct audio_entity_info *table,
|
||||
@@ -312,33 +320,58 @@ struct usbd_interface *usbd_audio_init_intf(uint8_t busid,
|
||||
return intf;
|
||||
}
|
||||
|
||||
__WEAK void usbd_audio_set_volume(uint8_t busid, uint8_t ep, uint8_t ch, int volume)
|
||||
__WEAK void usbd_audio_set_volume(uint8_t busid, uint8_t ep, uint8_t ch, int volume_db)
|
||||
{
|
||||
(void)busid;
|
||||
(void)ep;
|
||||
(void)ch;
|
||||
(void)volume_db;
|
||||
}
|
||||
|
||||
__WEAK int usbd_audio_get_volume(uint8_t busid, uint8_t ep, uint8_t ch)
|
||||
{
|
||||
(void)busid;
|
||||
(void)ep;
|
||||
(void)ch;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
__WEAK void usbd_audio_set_mute(uint8_t busid, uint8_t ep, uint8_t ch, bool mute)
|
||||
{
|
||||
(void)busid;
|
||||
(void)ep;
|
||||
(void)ch;
|
||||
(void)mute;
|
||||
}
|
||||
|
||||
__WEAK bool usbd_audio_get_mute(uint8_t busid, uint8_t ep, uint8_t ch)
|
||||
{
|
||||
(void)busid;
|
||||
(void)ep;
|
||||
(void)ch;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
__WEAK void usbd_audio_set_sampling_freq(uint8_t busid, uint8_t ep, uint32_t sampling_freq)
|
||||
{
|
||||
(void)busid;
|
||||
(void)ep;
|
||||
(void)sampling_freq;
|
||||
}
|
||||
|
||||
__WEAK uint32_t usbd_audio_get_sampling_freq(uint8_t busid, uint8_t ep)
|
||||
{
|
||||
(void)busid;
|
||||
(void)ep;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
__WEAK void usbd_audio_get_sampling_freq_table(uint8_t busid, uint8_t ep, uint8_t **sampling_freq_table)
|
||||
{
|
||||
(void)busid;
|
||||
(void)ep;
|
||||
(void)sampling_freq_table;
|
||||
}
|
||||
|
@@ -27,7 +27,7 @@ struct usbd_interface *usbd_audio_init_intf(uint8_t busid, struct usbd_interface
|
||||
void usbd_audio_open(uint8_t busid, uint8_t intf);
|
||||
void usbd_audio_close(uint8_t busid, uint8_t intf);
|
||||
|
||||
void usbd_audio_set_volume(uint8_t busid, uint8_t ep, uint8_t ch, int volume);
|
||||
void usbd_audio_set_volume(uint8_t busid, uint8_t ep, uint8_t ch, int volume_db);
|
||||
int usbd_audio_get_volume(uint8_t busid, uint8_t ep, uint8_t ch);
|
||||
void usbd_audio_set_mute(uint8_t busid, uint8_t ep, uint8_t ch, bool mute);
|
||||
bool usbd_audio_get_mute(uint8_t busid, uint8_t ep, uint8_t ch);
|
||||
|
@@ -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,52 +181,128 @@ 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;
|
||||
}
|
||||
|
||||
int usbh_audio_set_volume(struct usbh_audio *audio_class, const char *name, uint8_t ch, uint8_t volume)
|
||||
int usbh_audio_set_volume(struct usbh_audio *audio_class, const char *name, uint8_t ch, int volume_db)
|
||||
{
|
||||
struct usb_setup_packet *setup;
|
||||
int ret;
|
||||
uint8_t intf = 0xff;
|
||||
uint8_t feature_id = 0xff;
|
||||
uint8_t intf;
|
||||
uint16_t volume_hex;
|
||||
int volume_min_db;
|
||||
int volume_max_db;
|
||||
|
||||
if (!audio_class || !audio_class->hport) {
|
||||
return -USB_ERR_INVAL;
|
||||
}
|
||||
|
||||
if ((volume_db > 127) || (volume_db < -127)) {
|
||||
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;
|
||||
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;
|
||||
intf = audio_class->as_msg_table[i].stream_intf;
|
||||
}
|
||||
}
|
||||
|
||||
if (intf == 0xff) {
|
||||
if (feature_id == 0xff) {
|
||||
return -USB_ERR_NODEV;
|
||||
}
|
||||
|
||||
setup->bmRequestType = USB_REQUEST_DIR_IN | USB_REQUEST_CLASS | USB_REQUEST_RECIPIENT_INTERFACE;
|
||||
setup->bRequest = AUDIO_REQUEST_GET_CUR;
|
||||
setup->wValue = (AUDIO_FU_CONTROL_VOLUME << 8) | ch;
|
||||
setup->wIndex = (feature_id << 8) | audio_class->ctrl_intf;
|
||||
setup->wLength = 2;
|
||||
|
||||
ret = usbh_control_transfer(audio_class->hport, setup, g_audio_buf);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
memcpy(&audio_class->as_msg_table[intf - audio_class->ctrl_intf - 1].volume_cur, g_audio_buf, 2);
|
||||
|
||||
setup->bmRequestType = USB_REQUEST_DIR_IN | USB_REQUEST_CLASS | USB_REQUEST_RECIPIENT_INTERFACE;
|
||||
setup->bRequest = AUDIO_REQUEST_GET_MIN;
|
||||
setup->wValue = (AUDIO_FU_CONTROL_VOLUME << 8) | ch;
|
||||
setup->wIndex = (feature_id << 8) | audio_class->ctrl_intf;
|
||||
setup->wLength = 2;
|
||||
|
||||
ret = usbh_control_transfer(audio_class->hport, setup, g_audio_buf);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
memcpy(&audio_class->as_msg_table[intf - audio_class->ctrl_intf - 1].volume_min, g_audio_buf, 2);
|
||||
|
||||
setup->bmRequestType = USB_REQUEST_DIR_IN | USB_REQUEST_CLASS | USB_REQUEST_RECIPIENT_INTERFACE;
|
||||
setup->bRequest = AUDIO_REQUEST_GET_MAX;
|
||||
setup->wValue = (AUDIO_FU_CONTROL_VOLUME << 8) | ch;
|
||||
setup->wIndex = (feature_id << 8) | audio_class->ctrl_intf;
|
||||
setup->wLength = 2;
|
||||
|
||||
ret = usbh_control_transfer(audio_class->hport, setup, g_audio_buf);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
memcpy(&audio_class->as_msg_table[intf - audio_class->ctrl_intf - 1].volume_max, g_audio_buf, 2);
|
||||
|
||||
setup->bmRequestType = USB_REQUEST_DIR_IN | USB_REQUEST_CLASS | USB_REQUEST_RECIPIENT_INTERFACE;
|
||||
setup->bRequest = AUDIO_REQUEST_GET_RES;
|
||||
setup->wValue = (AUDIO_FU_CONTROL_VOLUME << 8) | ch;
|
||||
setup->wIndex = (feature_id << 8) | audio_class->ctrl_intf;
|
||||
setup->wLength = 2;
|
||||
|
||||
ret = usbh_control_transfer(audio_class->hport, setup, g_audio_buf);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
memcpy(&audio_class->as_msg_table[intf - audio_class->ctrl_intf - 1].volume_res, g_audio_buf, 2);
|
||||
|
||||
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;
|
||||
if (audio_class->as_msg_table[intf - audio_class->ctrl_intf - 1].volume_min < 0x8000) {
|
||||
volume_min_db = audio_class->as_msg_table[intf - audio_class->ctrl_intf - 1].volume_min / 256;
|
||||
} else {
|
||||
volume_min_db = (audio_class->as_msg_table[intf - audio_class->ctrl_intf - 1].volume_min - 0x10000) / 256;
|
||||
}
|
||||
|
||||
if (audio_class->as_msg_table[intf - audio_class->ctrl_intf - 1].volume_max < 0x8000) {
|
||||
volume_max_db = audio_class->as_msg_table[intf - audio_class->ctrl_intf - 1].volume_max / 256;
|
||||
} else {
|
||||
volume_max_db = (audio_class->as_msg_table[intf - audio_class->ctrl_intf - 1].volume_max - 0x10000) / 256;
|
||||
}
|
||||
|
||||
USB_LOG_INFO("Get ch:%d dB range: %d dB ~ %d dB\r\n", volume_min_db, volume_max_db);
|
||||
|
||||
if (volume_db >= 0) {
|
||||
volume_hex = volume_db * 256;
|
||||
if (volume_hex > audio_class->as_msg_table[intf - audio_class->ctrl_intf - 1].volume_max) {
|
||||
return -USB_ERR_RANGE;
|
||||
}
|
||||
} else {
|
||||
volume_hex = volume_db * 256 + 0x10000;
|
||||
if (volume_hex < audio_class->as_msg_table[intf - audio_class->ctrl_intf - 1].volume_min) {
|
||||
return -USB_ERR_RANGE;
|
||||
}
|
||||
}
|
||||
|
||||
memcpy(g_audio_buf, &volume_hex, 2);
|
||||
ret = usbh_control_transfer(audio_class->hport, setup, NULL);
|
||||
|
||||
ret = usbh_control_transfer(audio_class->hport, setup, g_audio_buf);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
audio_class->as_msg_table[intf - audio_class->ctrl_intf - 1].volume_cur = volume_hex;
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -222,34 +310,37 @@ 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;
|
||||
uint8_t intf = 0xff;
|
||||
|
||||
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;
|
||||
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;
|
||||
intf = audio_class->as_msg_table[i].stream_intf;
|
||||
}
|
||||
}
|
||||
|
||||
if (intf == 0xff) {
|
||||
if (feature_id == 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);
|
||||
ret = usbh_control_transfer(audio_class->hport, setup, g_audio_buf);
|
||||
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
audio_class->as_msg_table[intf - audio_class->ctrl_intf - 1].mute = mute;
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -257,26 +348,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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -287,14 +380,14 @@ void usbh_audio_list_module(struct usbh_audio *audio_class)
|
||||
static int usbh_audio_ctrl_connect(struct usbh_hubport *hport, uint8_t intf)
|
||||
{
|
||||
int ret;
|
||||
uint8_t cur_iface = 0xff;
|
||||
uint8_t cur_iface_count = 0xff;
|
||||
uint8_t cur_alt_setting = 0xff;
|
||||
uint8_t cur_iface = 0;
|
||||
uint8_t cur_iface_count = 0;
|
||||
uint8_t cur_alt_setting = 0;
|
||||
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_ac_msg ac_msg_table[CONFIG_USBHOST_AUDIO_MAX_STREAMS];
|
||||
|
||||
struct usbh_audio *audio_class = usbh_audio_class_alloc();
|
||||
if (audio_class == NULL) {
|
||||
@@ -304,8 +397,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,72 +422,49 @@ 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(&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(&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(&ac_msg_table[feature_unit_offset].ac_feature_unit, desc, desc->bLength);
|
||||
feature_unit_offset++;
|
||||
} break;
|
||||
case AUDIO_CONTROL_PROCESSING_UNIT:
|
||||
default:
|
||||
USB_LOG_ERR("Do not support %02x subtype\r\n", p[DESC_bDescriptorSubType]);
|
||||
return -USB_ERR_NOTSUPP;
|
||||
}
|
||||
} 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: {
|
||||
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->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;
|
||||
}
|
||||
} else if ((cur_iface < (audio_class->ctrl_intf + cur_iface_count)) && (cur_iface > audio_class->ctrl_intf)) {
|
||||
switch (p[DESC_bDescriptorSubType]) {
|
||||
case AUDIO_STREAMING_GENERAL:
|
||||
|
||||
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++;
|
||||
}
|
||||
} 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;
|
||||
@@ -407,16 +475,98 @@ 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 control descriptor is invalid\r\n");
|
||||
return -USB_ERR_INVAL;
|
||||
}
|
||||
|
||||
audio_class->module_num = input_offset;
|
||||
if (cur_iface_count == 0xff) {
|
||||
USB_LOG_ERR("Audio descriptor must have iad descriptor\r\n");
|
||||
return -USB_ERR_INVAL;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < audio_class->module_num; i++) {
|
||||
ret = usbh_audio_close(audio_class, audio_class->module[i].name);
|
||||
audio_class->stream_intf_num = input_offset;
|
||||
|
||||
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 == ac_msg_table[streamidx].ac_input.bTerminalID) {
|
||||
/* INPUT --> FEATURE UNIT --> OUTPUT */
|
||||
audio_class->as_msg_table[i].input_terminal_id = 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 (ac_msg_table[streamidx].ac_input.bTerminalID == ac_msg_table[featureidx].ac_feature_unit.bSourceID) {
|
||||
audio_class->as_msg_table[i].feature_terminal_id = 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 (ac_msg_table[featureidx].ac_feature_unit.bUnitID == ac_msg_table[outputid].ac_output.bSourceID) {
|
||||
audio_class->as_msg_table[i].output_terminal_id = ac_msg_table[outputid].ac_output.bTerminalID;
|
||||
|
||||
switch (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 == ac_msg_table[streamidx].ac_output.bTerminalID) {
|
||||
/* OUTPUT --> FEATURE UNIT --> INPUT */
|
||||
audio_class->as_msg_table[i].output_terminal_id = 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 (ac_msg_table[streamidx].ac_output.bSourceID == ac_msg_table[featureidx].ac_feature_unit.bUnitID) {
|
||||
audio_class->as_msg_table[i].feature_terminal_id = 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 (ac_msg_table[featureidx].ac_feature_unit.bSourceID == ac_msg_table[inputid].ac_input.bTerminalID) {
|
||||
audio_class->as_msg_table[i].input_terminal_id = ac_msg_table[inputid].ac_input.bTerminalID;
|
||||
|
||||
switch (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++) {
|
||||
if (audio_class->as_msg_table[i].stream_name == NULL) {
|
||||
USB_LOG_ERR("Audio stream search fail\r\n");
|
||||
return -USB_ERR_NODEV;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -456,20 +606,26 @@ static int usbh_audio_ctrl_disconnect(struct usbh_hubport *hport, uint8_t intf)
|
||||
|
||||
static int usbh_audio_data_connect(struct usbh_hubport *hport, uint8_t intf)
|
||||
{
|
||||
(void)hport;
|
||||
(void)intf;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int usbh_audio_data_disconnect(struct usbh_hubport *hport, uint8_t intf)
|
||||
{
|
||||
(void)hport;
|
||||
(void)intf;
|
||||
return 0;
|
||||
}
|
||||
|
||||
__WEAK void usbh_audio_run(struct usbh_audio *audio_class)
|
||||
{
|
||||
(void)audio_class;
|
||||
}
|
||||
|
||||
__WEAK void usbh_audio_stop(struct usbh_audio *audio_class)
|
||||
{
|
||||
(void)audio_class;
|
||||
}
|
||||
|
||||
const struct usbh_class_driver audio_ctrl_class_driver = {
|
||||
@@ -486,18 +642,18 @@ const struct usbh_class_driver audio_streaming_class_driver = {
|
||||
|
||||
CLASS_INFO_DEFINE const struct usbh_class_info audio_ctrl_intf_class_info = {
|
||||
.match_flags = USB_CLASS_MATCH_INTF_CLASS | USB_CLASS_MATCH_INTF_SUBCLASS,
|
||||
.class = USB_DEVICE_CLASS_AUDIO,
|
||||
.subclass = AUDIO_SUBCLASS_AUDIOCONTROL,
|
||||
.protocol = 0x00,
|
||||
.bInterfaceClass = USB_DEVICE_CLASS_AUDIO,
|
||||
.bInterfaceSubClass = AUDIO_SUBCLASS_AUDIOCONTROL,
|
||||
.bInterfaceProtocol = 0x00,
|
||||
.id_table = NULL,
|
||||
.class_driver = &audio_ctrl_class_driver
|
||||
};
|
||||
|
||||
CLASS_INFO_DEFINE const struct usbh_class_info audio_streaming_intf_class_info = {
|
||||
.match_flags = USB_CLASS_MATCH_INTF_CLASS | USB_CLASS_MATCH_INTF_SUBCLASS,
|
||||
.class = USB_DEVICE_CLASS_AUDIO,
|
||||
.subclass = AUDIO_SUBCLASS_AUDIOSTREAMING,
|
||||
.protocol = 0x00,
|
||||
.bInterfaceClass = USB_DEVICE_CLASS_AUDIO,
|
||||
.bInterfaceSubClass = AUDIO_SUBCLASS_AUDIOSTREAMING,
|
||||
.bInterfaceProtocol = 0x00,
|
||||
.id_table = NULL,
|
||||
.class_driver = &audio_streaming_class_driver
|
||||
};
|
||||
|
@@ -8,34 +8,31 @@
|
||||
|
||||
#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;
|
||||
uint16_t volume_min;
|
||||
uint16_t volume_max;
|
||||
uint16_t volume_res;
|
||||
uint16_t volume_cur;
|
||||
bool mute;
|
||||
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 +47,8 @@ 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_as_msg as_msg_table[CONFIG_USBHOST_AUDIO_MAX_STREAMS];
|
||||
|
||||
void *user_data;
|
||||
};
|
||||
@@ -61,9 +57,9 @@ 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_volume(struct usbh_audio *audio_class, const char *name, uint8_t ch, int volume_db);
|
||||
int usbh_audio_set_mute(struct usbh_audio *audio_class, const char *name, uint8_t ch, bool mute);
|
||||
|
||||
void usbh_audio_run(struct usbh_audio *audio_class);
|
||||
|
@@ -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 */ \
|
||||
@@ -524,7 +524,7 @@ struct cdc_ncm_ndp16 {
|
||||
int_ep, /* bEndpointAddress */ \
|
||||
0x03, /* bmAttributes */ \
|
||||
0x08, 0x00, /* wMaxPacketSize */ \
|
||||
0x10, /* bInterval */ \
|
||||
0x05, /* bInterval */ \
|
||||
0x09, /* bLength */ \
|
||||
USB_DESCRIPTOR_TYPE_INTERFACE, /* bDescriptorType */ \
|
||||
(uint8_t)(bFirstInterface + 1), /* bInterfaceNumber */ \
|
||||
@@ -596,7 +596,7 @@ eth_statistics, wMaxSegmentSize, wNumberMCFilters, bNumberPowerFilters, str_idx)
|
||||
int_ep, /* bEndpointAddress */ \
|
||||
0x03, /* bmAttributes */ \
|
||||
0x10, 0x00, /* wMaxPacketSize */ \
|
||||
0x10, /* bInterval */ \
|
||||
0x05, /* bInterval */ \
|
||||
0x09, /* bLength */ \
|
||||
USB_DESCRIPTOR_TYPE_INTERFACE, /* bDescriptorType */ \
|
||||
(uint8_t)(bFirstInterface + 1), /* bInterfaceNumber */ \
|
||||
|
@@ -1,29 +1,13 @@
|
||||
/*
|
||||
* Copyright (c) 2022, sakumisu
|
||||
* Copyright (c) 2024, sakumisu
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#ifndef USBD_CDC_H
|
||||
#define USBD_CDC_H
|
||||
|
||||
#include "usb_cdc.h"
|
||||
// legacy for old version
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#include "usbd_cdc_acm.h"
|
||||
|
||||
/* Init cdc acm interface driver */
|
||||
struct usbd_interface *usbd_cdc_acm_init_intf(uint8_t busid, struct usbd_interface *intf);
|
||||
|
||||
/* Setup request command callback api */
|
||||
void usbd_cdc_acm_set_line_coding(uint8_t busid, uint8_t intf, struct cdc_line_coding *line_coding);
|
||||
void usbd_cdc_acm_get_line_coding(uint8_t busid, uint8_t intf, struct cdc_line_coding *line_coding);
|
||||
void usbd_cdc_acm_set_dtr(uint8_t busid, uint8_t intf, bool dtr);
|
||||
void usbd_cdc_acm_set_rts(uint8_t busid, uint8_t intf, bool rts);
|
||||
void usbd_cdc_acm_send_break(uint8_t busid, uint8_t intf);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* USBD_CDC_H */
|
||||
#endif
|
@@ -0,0 +1,134 @@
|
||||
/*
|
||||
* Copyright (c) 2022, sakumisu
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#include "usbd_core.h"
|
||||
#include "usbd_cdc_acm.h"
|
||||
|
||||
const char *stop_name[] = { "1", "1.5", "2" };
|
||||
const char *parity_name[] = { "N", "O", "E", "M", "S" };
|
||||
|
||||
static int cdc_acm_class_interface_request_handler(uint8_t busid, struct usb_setup_packet *setup, uint8_t **data, uint32_t *len)
|
||||
{
|
||||
USB_LOG_DBG("CDC Class request: "
|
||||
"bRequest 0x%02x\r\n",
|
||||
setup->bRequest);
|
||||
|
||||
struct cdc_line_coding line_coding;
|
||||
bool dtr, rts;
|
||||
uint8_t intf_num = LO_BYTE(setup->wIndex);
|
||||
|
||||
switch (setup->bRequest) {
|
||||
case CDC_REQUEST_SET_LINE_CODING:
|
||||
|
||||
/*******************************************************************************/
|
||||
/* Line Coding Structure */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Offset | Field | Size | Value | Description */
|
||||
/* 0 | dwDTERate | 4 | Number |Data terminal rate, in bits per second*/
|
||||
/* 4 | bCharFormat | 1 | Number | Stop bits */
|
||||
/* 0 - 1 Stop bit */
|
||||
/* 1 - 1.5 Stop bits */
|
||||
/* 2 - 2 Stop bits */
|
||||
/* 5 | bParityType | 1 | Number | Parity */
|
||||
/* 0 - None */
|
||||
/* 1 - Odd */
|
||||
/* 2 - Even */
|
||||
/* 3 - Mark */
|
||||
/* 4 - Space */
|
||||
/* 6 | bDataBits | 1 | Number Data bits (5, 6, 7, 8 or 16). */
|
||||
/*******************************************************************************/
|
||||
memcpy(&line_coding, *data, setup->wLength);
|
||||
USB_LOG_DBG("Set intf:%d linecoding <%d %d %s %s>\r\n",
|
||||
intf_num,
|
||||
line_coding.dwDTERate,
|
||||
line_coding.bDataBits,
|
||||
parity_name[line_coding.bParityType],
|
||||
stop_name[line_coding.bCharFormat]);
|
||||
|
||||
usbd_cdc_acm_set_line_coding(busid, intf_num, &line_coding);
|
||||
break;
|
||||
|
||||
case CDC_REQUEST_SET_CONTROL_LINE_STATE:
|
||||
dtr = (setup->wValue & 0x0001);
|
||||
rts = (setup->wValue & 0x0002);
|
||||
USB_LOG_DBG("Set intf:%d DTR 0x%x,RTS 0x%x\r\n",
|
||||
intf_num,
|
||||
dtr,
|
||||
rts);
|
||||
usbd_cdc_acm_set_dtr(busid, intf_num, dtr);
|
||||
usbd_cdc_acm_set_rts(busid, intf_num, rts);
|
||||
break;
|
||||
|
||||
case CDC_REQUEST_GET_LINE_CODING:
|
||||
usbd_cdc_acm_get_line_coding(busid, intf_num, &line_coding);
|
||||
memcpy(*data, &line_coding, 7);
|
||||
*len = 7;
|
||||
USB_LOG_DBG("Get intf:%d linecoding %d %d %d %d\r\n",
|
||||
intf_num,
|
||||
line_coding.dwDTERate,
|
||||
line_coding.bCharFormat,
|
||||
line_coding.bParityType,
|
||||
line_coding.bDataBits);
|
||||
break;
|
||||
case CDC_REQUEST_SEND_BREAK:
|
||||
usbd_cdc_acm_send_break(busid, intf_num);
|
||||
break;
|
||||
default:
|
||||
USB_LOG_WRN("Unhandled CDC Class bRequest 0x%02x\r\n", setup->bRequest);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct usbd_interface *usbd_cdc_acm_init_intf(uint8_t busid, struct usbd_interface *intf)
|
||||
{
|
||||
(void)busid;
|
||||
|
||||
intf->class_interface_handler = cdc_acm_class_interface_request_handler;
|
||||
intf->class_endpoint_handler = NULL;
|
||||
intf->vendor_handler = NULL;
|
||||
intf->notify_handler = NULL;
|
||||
|
||||
return intf;
|
||||
}
|
||||
|
||||
__WEAK void usbd_cdc_acm_set_line_coding(uint8_t busid, uint8_t intf, struct cdc_line_coding *line_coding)
|
||||
{
|
||||
(void)busid;
|
||||
(void)intf;
|
||||
(void)line_coding;
|
||||
}
|
||||
|
||||
__WEAK void usbd_cdc_acm_get_line_coding(uint8_t busid, uint8_t intf, struct cdc_line_coding *line_coding)
|
||||
{
|
||||
(void)busid;
|
||||
(void)intf;
|
||||
|
||||
line_coding->dwDTERate = 2000000;
|
||||
line_coding->bDataBits = 8;
|
||||
line_coding->bParityType = 0;
|
||||
line_coding->bCharFormat = 0;
|
||||
}
|
||||
|
||||
__WEAK void usbd_cdc_acm_set_dtr(uint8_t busid, uint8_t intf, bool dtr)
|
||||
{
|
||||
(void)busid;
|
||||
(void)intf;
|
||||
(void)dtr;
|
||||
}
|
||||
|
||||
__WEAK void usbd_cdc_acm_set_rts(uint8_t busid, uint8_t intf, bool rts)
|
||||
{
|
||||
(void)busid;
|
||||
(void)intf;
|
||||
(void)rts;
|
||||
}
|
||||
|
||||
__WEAK void usbd_cdc_acm_send_break(uint8_t busid, uint8_t intf)
|
||||
{
|
||||
(void)busid;
|
||||
(void)intf;
|
||||
}
|
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright (c) 2022, sakumisu
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#ifndef USBD_CDC_ACM_H
|
||||
#define USBD_CDC_ACM_H
|
||||
|
||||
#include "usb_cdc.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Init cdc acm interface driver */
|
||||
struct usbd_interface *usbd_cdc_acm_init_intf(uint8_t busid, struct usbd_interface *intf);
|
||||
|
||||
/* Setup request command callback api */
|
||||
void usbd_cdc_acm_set_line_coding(uint8_t busid, uint8_t intf, struct cdc_line_coding *line_coding);
|
||||
void usbd_cdc_acm_get_line_coding(uint8_t busid, uint8_t intf, struct cdc_line_coding *line_coding);
|
||||
void usbd_cdc_acm_set_dtr(uint8_t busid, uint8_t intf, bool dtr);
|
||||
void usbd_cdc_acm_set_rts(uint8_t busid, uint8_t intf, bool rts);
|
||||
void usbd_cdc_acm_send_break(uint8_t busid, uint8_t intf);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* USBD_CDC_ACM_H */
|
@@ -7,17 +7,21 @@
|
||||
#include "usbd_cdc_ecm.h"
|
||||
|
||||
#define CDC_ECM_OUT_EP_IDX 0
|
||||
#define CDC_ECM_IN_EP_IDX 1
|
||||
#define CDC_ECM_INT_EP_IDX 2
|
||||
#define CDC_ECM_IN_EP_IDX 1
|
||||
#define CDC_ECM_INT_EP_IDX 2
|
||||
|
||||
/* Ethernet Maximum Segment size, typically 1514 bytes */
|
||||
#define CONFIG_CDC_ECM_ETH_MAX_SEGSZE 1536U
|
||||
|
||||
/* Describe EndPoints configuration */
|
||||
static struct usbd_endpoint cdc_ecm_ep_data[3];
|
||||
|
||||
#ifdef CONFIG_USBDEV_CDC_ECM_USING_LWIP
|
||||
static USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_cdc_ecm_rx_buffer[CONFIG_CDC_ECM_ETH_MAX_SEGSZE];
|
||||
static USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_cdc_ecm_tx_buffer[CONFIG_CDC_ECM_ETH_MAX_SEGSZE];
|
||||
#endif
|
||||
static USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_cdc_ecm_notify_buf[16];
|
||||
|
||||
volatile uint8_t *g_cdc_ecm_rx_data_buffer = NULL;
|
||||
volatile uint32_t g_cdc_ecm_rx_data_length = 0;
|
||||
volatile uint32_t g_cdc_ecm_tx_data_length = 0;
|
||||
|
||||
@@ -68,8 +72,10 @@ void usbd_cdc_ecm_send_notify(uint8_t notifycode, uint8_t value, uint32_t *speed
|
||||
break;
|
||||
}
|
||||
|
||||
if (bytes2send) {
|
||||
usbd_ep_start_write(0, cdc_ecm_ep_data[CDC_ECM_INT_EP_IDX].ep_addr, g_cdc_ecm_notify_buf, bytes2send);
|
||||
if (usb_device_is_configured(0)) {
|
||||
if (bytes2send) {
|
||||
usbd_ep_start_write(0, cdc_ecm_ep_data[CDC_ECM_INT_EP_IDX].ep_addr, g_cdc_ecm_notify_buf, bytes2send);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,6 +85,10 @@ static int cdc_ecm_class_interface_request_handler(uint8_t busid, struct usb_set
|
||||
"bRequest 0x%02x\r\n",
|
||||
setup->bRequest);
|
||||
|
||||
(void)busid;
|
||||
(void)data;
|
||||
(void)len;
|
||||
|
||||
g_cmd_intf = LO_BYTE(setup->wIndex);
|
||||
|
||||
switch (setup->bRequest) {
|
||||
@@ -89,11 +99,11 @@ static int cdc_ecm_class_interface_request_handler(uint8_t busid, struct usb_set
|
||||
* bit3 Broadcast
|
||||
* bit4 Multicast
|
||||
*/
|
||||
if (g_current_net_status == 0) {
|
||||
g_current_net_status = 1;
|
||||
usbd_cdc_ecm_send_notify(CDC_ECM_NOTIFY_CODE_NETWORK_CONNECTION, CDC_ECM_NET_CONNECTED, NULL);
|
||||
}
|
||||
|
||||
#ifdef CONFIG_USBDEV_CDC_ECM_USING_LWIP
|
||||
g_connect_speed_table[0] = 100000000; /* 100 Mbps */
|
||||
g_connect_speed_table[1] = 100000000; /* 100 Mbps */
|
||||
usbd_cdc_ecm_set_connect(true, g_connect_speed_table);
|
||||
#endif
|
||||
break;
|
||||
default:
|
||||
USB_LOG_WRN("Unhandled CDC ECM Class bRequest 0x%02x\r\n", setup->bRequest);
|
||||
@@ -105,15 +115,19 @@ static int cdc_ecm_class_interface_request_handler(uint8_t busid, struct usb_set
|
||||
|
||||
void cdc_ecm_notify_handler(uint8_t busid, uint8_t event, void *arg)
|
||||
{
|
||||
(void)busid;
|
||||
(void)arg;
|
||||
|
||||
switch (event) {
|
||||
case USBD_EVENT_RESET:
|
||||
g_current_net_status = 0;
|
||||
g_cdc_ecm_rx_data_length = 0;
|
||||
g_cdc_ecm_tx_data_length = 0;
|
||||
g_cdc_ecm_rx_data_buffer = NULL;
|
||||
break;
|
||||
case USBD_EVENT_CONFIGURED:
|
||||
usbd_ep_start_read(0, cdc_ecm_ep_data[CDC_ECM_OUT_EP_IDX].ep_addr, &g_cdc_ecm_rx_buffer[g_cdc_ecm_rx_data_length], usbd_get_ep_mps(busid, cdc_ecm_ep_data[CDC_ECM_OUT_EP_IDX].ep_addr));
|
||||
#ifdef CONFIG_USBDEV_CDC_ECM_USING_LWIP
|
||||
usbd_cdc_ecm_start_read(g_cdc_ecm_rx_buffer, CONFIG_CDC_ECM_ETH_MAX_SEGSZE);
|
||||
#endif
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -123,36 +137,45 @@ void cdc_ecm_notify_handler(uint8_t busid, uint8_t event, void *arg)
|
||||
|
||||
void cdc_ecm_bulk_out(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
{
|
||||
g_cdc_ecm_rx_data_length += nbytes;
|
||||
(void)busid;
|
||||
|
||||
if (nbytes < usbd_get_ep_mps(busid, ep)) {
|
||||
g_cdc_ecm_rx_data_buffer = g_cdc_ecm_rx_buffer;
|
||||
usbd_cdc_ecm_data_recv_done(g_cdc_ecm_rx_buffer, g_cdc_ecm_rx_data_length);
|
||||
} else {
|
||||
usbd_ep_start_read(0, ep, &g_cdc_ecm_rx_buffer[g_cdc_ecm_rx_data_length], usbd_get_ep_mps(busid, ep));
|
||||
}
|
||||
g_cdc_ecm_rx_data_length = nbytes;
|
||||
usbd_cdc_ecm_data_recv_done(g_cdc_ecm_rx_data_length);
|
||||
}
|
||||
|
||||
void cdc_ecm_bulk_in(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
{
|
||||
if ((nbytes % usbd_get_ep_mps(busid, ep)) == 0 && nbytes) {
|
||||
(void)busid;
|
||||
|
||||
if ((nbytes % usbd_get_ep_mps(0, ep)) == 0 && nbytes) {
|
||||
/* send zlp */
|
||||
usbd_ep_start_write(0, ep, NULL, 0);
|
||||
} else {
|
||||
usbd_cdc_ecm_data_send_done(g_cdc_ecm_tx_data_length);
|
||||
g_cdc_ecm_tx_data_length = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void cdc_ecm_int_in(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
{
|
||||
if (g_current_net_status == 1) {
|
||||
g_current_net_status = 2;
|
||||
usbd_cdc_ecm_send_notify(CDC_ECM_NOTIFY_CODE_NETWORK_CONNECTION, CDC_ECM_NET_CONNECTED, g_connect_speed_table);
|
||||
(void)busid;
|
||||
(void)ep;
|
||||
(void)nbytes;
|
||||
|
||||
if (g_current_net_status == 2) {
|
||||
g_current_net_status = 3;
|
||||
usbd_cdc_ecm_send_notify(CDC_ECM_NOTIFY_CODE_CONNECTION_SPEED_CHANGE, 0, g_connect_speed_table);
|
||||
} else {
|
||||
g_current_net_status = 0;
|
||||
}
|
||||
}
|
||||
|
||||
int usbd_cdc_ecm_start_write(uint8_t *buf, uint32_t len)
|
||||
{
|
||||
if (!usb_device_is_configured(0)) {
|
||||
return -USB_ERR_NODEV;
|
||||
}
|
||||
|
||||
if (g_cdc_ecm_tx_data_length > 0) {
|
||||
return -USB_ERR_BUSY;
|
||||
}
|
||||
@@ -160,14 +183,17 @@ int usbd_cdc_ecm_start_write(uint8_t *buf, uint32_t len)
|
||||
g_cdc_ecm_tx_data_length = len;
|
||||
|
||||
USB_LOG_DBG("txlen:%d\r\n", g_cdc_ecm_tx_data_length);
|
||||
return usbd_ep_start_write(0, cdc_ecm_ep_data[CDC_ECM_IN_EP_IDX].ep_addr, buf, g_cdc_ecm_tx_data_length);
|
||||
return usbd_ep_start_write(0, cdc_ecm_ep_data[CDC_ECM_IN_EP_IDX].ep_addr, buf, len);
|
||||
}
|
||||
|
||||
void usbd_cdc_ecm_start_read_next(void)
|
||||
int usbd_cdc_ecm_start_read(uint8_t *buf, uint32_t len)
|
||||
{
|
||||
if (!usb_device_is_configured(0)) {
|
||||
return -USB_ERR_NODEV;
|
||||
}
|
||||
|
||||
g_cdc_ecm_rx_data_length = 0;
|
||||
g_cdc_ecm_rx_data_buffer = NULL;
|
||||
usbd_ep_start_read(0, cdc_ecm_ep_data[CDC_ECM_OUT_EP_IDX].ep_addr, g_cdc_ecm_rx_buffer, usbd_get_ep_mps(0, cdc_ecm_ep_data[CDC_ECM_OUT_EP_IDX].ep_addr));
|
||||
return usbd_ep_start_read(0, cdc_ecm_ep_data[CDC_ECM_OUT_EP_IDX].ep_addr, buf, len);
|
||||
}
|
||||
|
||||
#ifdef CONFIG_USBDEV_CDC_ECM_USING_LWIP
|
||||
@@ -175,19 +201,19 @@ struct pbuf *usbd_cdc_ecm_eth_rx(void)
|
||||
{
|
||||
struct pbuf *p;
|
||||
|
||||
if (g_cdc_ecm_rx_data_buffer == NULL) {
|
||||
if (g_cdc_ecm_rx_data_length == 0) {
|
||||
return NULL;
|
||||
}
|
||||
p = pbuf_alloc(PBUF_RAW, g_cdc_ecm_rx_data_length, PBUF_POOL);
|
||||
if (p == NULL) {
|
||||
usbd_cdc_ecm_start_read_next();
|
||||
usbd_cdc_ecm_start_read(g_cdc_ecm_rx_buffer, CONFIG_CDC_ECM_ETH_MAX_SEGSZE);
|
||||
return NULL;
|
||||
}
|
||||
usb_memcpy(p->payload, (uint8_t *)g_cdc_ecm_rx_buffer, g_cdc_ecm_rx_data_length);
|
||||
p->len = g_cdc_ecm_rx_data_length;
|
||||
|
||||
USB_LOG_DBG("rxlen:%d\r\n", g_cdc_ecm_rx_data_length);
|
||||
usbd_cdc_ecm_start_read_next();
|
||||
usbd_cdc_ecm_start_read(g_cdc_ecm_rx_buffer, CONFIG_CDC_ECM_ETH_MAX_SEGSZE);
|
||||
return p;
|
||||
}
|
||||
|
||||
@@ -235,11 +261,24 @@ struct usbd_interface *usbd_cdc_ecm_init_intf(struct usbd_interface *intf, const
|
||||
return intf;
|
||||
}
|
||||
|
||||
void usbd_cdc_ecm_set_connect_speed(uint32_t speed[2])
|
||||
void usbd_cdc_ecm_set_connect(bool connect, uint32_t speed[2])
|
||||
{
|
||||
memcpy(g_connect_speed_table, speed, 8);
|
||||
if (connect) {
|
||||
g_current_net_status = 2;
|
||||
memcpy(g_connect_speed_table, speed, 8);
|
||||
usbd_cdc_ecm_send_notify(CDC_ECM_NOTIFY_CODE_NETWORK_CONNECTION, CDC_ECM_NET_CONNECTED, NULL);
|
||||
} else {
|
||||
g_current_net_status = 1;
|
||||
usbd_cdc_ecm_send_notify(CDC_ECM_NOTIFY_CODE_NETWORK_CONNECTION, CDC_ECM_NET_DISCONNECTED, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
__WEAK void usbd_cdc_ecm_data_recv_done(uint8_t *buf, uint32_t len)
|
||||
__WEAK void usbd_cdc_ecm_data_recv_done(uint32_t len)
|
||||
{
|
||||
(void)len;
|
||||
}
|
||||
|
||||
__WEAK void usbd_cdc_ecm_data_send_done(uint32_t len)
|
||||
{
|
||||
(void)len;
|
||||
}
|
||||
|
@@ -12,21 +12,15 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Ethernet Maximum Segment size, typically 1514 bytes */
|
||||
#define CONFIG_CDC_ECM_ETH_MAX_SEGSZE 1514U
|
||||
|
||||
/* Init cdc ecm interface driver */
|
||||
struct usbd_interface *usbd_cdc_ecm_init_intf(struct usbd_interface *intf, const uint8_t int_ep, const uint8_t out_ep, const uint8_t in_ep);
|
||||
|
||||
/* Setup request command callback api */
|
||||
void usbd_cdc_ecm_set_connect_speed(uint32_t speed[2]);
|
||||
void usbd_cdc_ecm_set_connect(bool connect, uint32_t speed[2]);
|
||||
|
||||
/* Api for eth only without any net stack */
|
||||
uint8_t *usbd_cdc_ecm_get_tx_buffer(void);
|
||||
void usbd_cdc_ecm_send_done(void);
|
||||
void usbd_cdc_ecm_data_recv_done(uint32_t len);
|
||||
void usbd_cdc_ecm_data_send_done(uint32_t len);
|
||||
int usbd_cdc_ecm_start_write(uint8_t *buf, uint32_t len);
|
||||
void usbd_cdc_ecm_data_recv_done(uint8_t *buf, uint32_t len);
|
||||
void usbd_cdc_ecm_start_read_next(void);
|
||||
int usbd_cdc_ecm_start_read(uint8_t *buf, uint32_t len);
|
||||
|
||||
#ifdef CONFIG_USBDEV_CDC_ECM_USING_LWIP
|
||||
#include "lwip/netif.h"
|
||||
|
@@ -12,18 +12,18 @@
|
||||
|
||||
#define DEV_FORMAT "/dev/ttyACM%d"
|
||||
|
||||
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_cdc_acm_buf[64];
|
||||
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_cdc_acm_buf[CONFIG_USBHOST_MAX_CDC_ACM_CLASS][USB_ALIGN_UP(64, CONFIG_USB_ALIGN_SIZE)];
|
||||
|
||||
static struct usbh_cdc_acm g_cdc_acm_class[CONFIG_USBHOST_MAX_CDC_ACM_CLASS];
|
||||
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));
|
||||
}
|
||||
@@ -57,9 +57,9 @@ int usbh_cdc_acm_set_line_coding(struct usbh_cdc_acm *cdc_acm_class, struct cdc_
|
||||
setup->wIndex = cdc_acm_class->intf;
|
||||
setup->wLength = 7;
|
||||
|
||||
memcpy(g_cdc_acm_buf, line_coding, sizeof(struct cdc_line_coding));
|
||||
memcpy(g_cdc_acm_buf[cdc_acm_class->minor], line_coding, sizeof(struct cdc_line_coding));
|
||||
|
||||
return usbh_control_transfer(cdc_acm_class->hport, setup, g_cdc_acm_buf);
|
||||
return usbh_control_transfer(cdc_acm_class->hport, setup, g_cdc_acm_buf[cdc_acm_class->minor]);
|
||||
}
|
||||
|
||||
int usbh_cdc_acm_get_line_coding(struct usbh_cdc_acm *cdc_acm_class, struct cdc_line_coding *line_coding)
|
||||
@@ -78,11 +78,11 @@ int usbh_cdc_acm_get_line_coding(struct usbh_cdc_acm *cdc_acm_class, struct cdc_
|
||||
setup->wIndex = cdc_acm_class->intf;
|
||||
setup->wLength = 7;
|
||||
|
||||
ret = usbh_control_transfer(cdc_acm_class->hport, setup, g_cdc_acm_buf);
|
||||
ret = usbh_control_transfer(cdc_acm_class->hport, setup, g_cdc_acm_buf[cdc_acm_class->minor]);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
memcpy(line_coding, g_cdc_acm_buf, sizeof(struct cdc_line_coding));
|
||||
memcpy(line_coding, g_cdc_acm_buf[cdc_acm_class->minor], sizeof(struct cdc_line_coding));
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -231,20 +231,26 @@ int usbh_cdc_acm_bulk_out_transfer(struct usbh_cdc_acm *cdc_acm_class, uint8_t *
|
||||
|
||||
static int usbh_cdc_data_connect(struct usbh_hubport *hport, uint8_t intf)
|
||||
{
|
||||
(void)hport;
|
||||
(void)intf;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int usbh_cdc_data_disconnect(struct usbh_hubport *hport, uint8_t intf)
|
||||
{
|
||||
(void)hport;
|
||||
(void)intf;
|
||||
return 0;
|
||||
}
|
||||
|
||||
__WEAK void usbh_cdc_acm_run(struct usbh_cdc_acm *cdc_acm_class)
|
||||
{
|
||||
(void)cdc_acm_class;
|
||||
}
|
||||
|
||||
__WEAK void usbh_cdc_acm_stop(struct usbh_cdc_acm *cdc_acm_class)
|
||||
{
|
||||
(void)cdc_acm_class;
|
||||
}
|
||||
|
||||
const struct usbh_class_driver cdc_acm_class_driver = {
|
||||
@@ -260,19 +266,19 @@ 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,
|
||||
.class = USB_DEVICE_CLASS_CDC,
|
||||
.subclass = CDC_ABSTRACT_CONTROL_MODEL,
|
||||
.protocol = CDC_COMMON_PROTOCOL_AT_COMMANDS,
|
||||
.match_flags = USB_CLASS_MATCH_INTF_CLASS | USB_CLASS_MATCH_INTF_SUBCLASS,
|
||||
.bInterfaceClass = USB_DEVICE_CLASS_CDC,
|
||||
.bInterfaceSubClass = CDC_ABSTRACT_CONTROL_MODEL,
|
||||
.bInterfaceProtocol = 0x00,
|
||||
.id_table = NULL,
|
||||
.class_driver = &cdc_acm_class_driver
|
||||
};
|
||||
|
||||
CLASS_INFO_DEFINE const struct usbh_class_info cdc_data_class_info = {
|
||||
.match_flags = USB_CLASS_MATCH_INTF_CLASS,
|
||||
.class = USB_DEVICE_CLASS_CDC_DATA,
|
||||
.subclass = 0x00,
|
||||
.protocol = 0x00,
|
||||
.bInterfaceClass = USB_DEVICE_CLASS_CDC_DATA,
|
||||
.bInterfaceSubClass = 0x00,
|
||||
.bInterfaceProtocol = 0x00,
|
||||
.id_table = NULL,
|
||||
.class_driver = &cdc_data_class_driver
|
||||
};
|
||||
|
@@ -236,6 +236,7 @@ void usbh_cdc_ecm_rx_thread(void *argument)
|
||||
uint32_t g_cdc_ecm_rx_length;
|
||||
int ret;
|
||||
|
||||
(void)argument;
|
||||
USB_LOG_INFO("Create cdc ecm rx thread\r\n");
|
||||
// clang-format off
|
||||
find_class:
|
||||
@@ -306,10 +307,12 @@ int usbh_cdc_ecm_eth_output(uint32_t buflen)
|
||||
|
||||
__WEAK void usbh_cdc_ecm_run(struct usbh_cdc_ecm *cdc_ecm_class)
|
||||
{
|
||||
(void)cdc_ecm_class;
|
||||
}
|
||||
|
||||
__WEAK void usbh_cdc_ecm_stop(struct usbh_cdc_ecm *cdc_ecm_class)
|
||||
{
|
||||
(void)cdc_ecm_class;
|
||||
}
|
||||
|
||||
const struct usbh_class_driver cdc_ecm_class_driver = {
|
||||
@@ -320,9 +323,9 @@ const struct usbh_class_driver cdc_ecm_class_driver = {
|
||||
|
||||
CLASS_INFO_DEFINE const struct usbh_class_info cdc_ecm_class_info = {
|
||||
.match_flags = USB_CLASS_MATCH_INTF_CLASS | USB_CLASS_MATCH_INTF_SUBCLASS | USB_CLASS_MATCH_INTF_PROTOCOL,
|
||||
.class = USB_DEVICE_CLASS_CDC,
|
||||
.subclass = CDC_ETHERNET_NETWORKING_CONTROL_MODEL,
|
||||
.protocol = CDC_COMMON_PROTOCOL_NONE,
|
||||
.bInterfaceClass = USB_DEVICE_CLASS_CDC,
|
||||
.bInterfaceSubClass = CDC_ETHERNET_NETWORKING_CONTROL_MODEL,
|
||||
.bInterfaceProtocol = CDC_COMMON_PROTOCOL_NONE,
|
||||
.id_table = NULL,
|
||||
.class_driver = &cdc_ecm_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;
|
||||
}
|
||||
|
||||
@@ -259,6 +259,7 @@ void usbh_cdc_ncm_rx_thread(void *argument)
|
||||
uint32_t transfer_size = (16 * 1024);
|
||||
#endif
|
||||
|
||||
(void)argument;
|
||||
USB_LOG_INFO("Create cdc ncm rx thread\r\n");
|
||||
// clang-format off
|
||||
find_class:
|
||||
@@ -330,7 +331,7 @@ find_class:
|
||||
#else
|
||||
if ((g_cdc_ncm_rx_length + (16 * 1024)) > CONFIG_USBHOST_CDC_NCM_ETH_MAX_RX_SIZE) {
|
||||
#endif
|
||||
USB_LOG_ERR("Rx packet is overflow, please ruduce tcp window size or increase CONFIG_USBHOST_CDC_NCM_ETH_MAX_RX_SIZE\r\n");
|
||||
USB_LOG_ERR("Rx packet is overflow, please reduce tcp window size or increase CONFIG_USBHOST_CDC_NCM_ETH_MAX_RX_SIZE\r\n");
|
||||
while (1) {
|
||||
}
|
||||
}
|
||||
@@ -386,10 +387,12 @@ int usbh_cdc_ncm_eth_output(uint32_t buflen)
|
||||
|
||||
__WEAK void usbh_cdc_ncm_run(struct usbh_cdc_ncm *cdc_ncm_class)
|
||||
{
|
||||
(void)cdc_ncm_class;
|
||||
}
|
||||
|
||||
__WEAK void usbh_cdc_ncm_stop(struct usbh_cdc_ncm *cdc_ncm_class)
|
||||
{
|
||||
(void)cdc_ncm_class;
|
||||
}
|
||||
|
||||
const struct usbh_class_driver cdc_ncm_class_driver = {
|
||||
@@ -400,9 +403,9 @@ const struct usbh_class_driver cdc_ncm_class_driver = {
|
||||
|
||||
CLASS_INFO_DEFINE const struct usbh_class_info cdc_ncm_class_info = {
|
||||
.match_flags = USB_CLASS_MATCH_INTF_CLASS | USB_CLASS_MATCH_INTF_SUBCLASS | USB_CLASS_MATCH_INTF_PROTOCOL,
|
||||
.class = USB_DEVICE_CLASS_CDC,
|
||||
.subclass = CDC_NETWORK_CONTROL_MODEL,
|
||||
.protocol = CDC_COMMON_PROTOCOL_NONE,
|
||||
.bInterfaceClass = USB_DEVICE_CLASS_CDC,
|
||||
.bInterfaceSubClass = CDC_NETWORK_CONTROL_MODEL,
|
||||
.bInterfaceProtocol = CDC_COMMON_PROTOCOL_NONE,
|
||||
.id_table = NULL,
|
||||
.class_driver = &cdc_ncm_class_driver
|
||||
};
|
||||
|
@@ -558,26 +558,24 @@ struct usb_hid_kbd_report
|
||||
};
|
||||
|
||||
/* Keyboard output report (1 byte) (HID B.1),
|
||||
* see USBHID_KBDOUT_* definitions
|
||||
* see HID_KBD_OUTPUT_* definitions
|
||||
*/
|
||||
|
||||
/* Mouse input report (HID B.2) */
|
||||
struct usb_hid_mouse_report
|
||||
{
|
||||
uint8_t buttons; /* See HID_MOUSE_INPUT_BUTTON_* definitions */
|
||||
uint8_t xdisp; /* X displacement */
|
||||
uint8_t ydisp; /* y displacement */
|
||||
int8_t xdisp; /* X displacement */
|
||||
int8_t ydisp; /* y displacement */
|
||||
/* Device specific additional bytes may follow */
|
||||
#ifdef CONFIG_INPUT_MOUSE_WHEEL
|
||||
uint8_t wdisp; /* Wheel displacement */
|
||||
#endif
|
||||
};
|
||||
|
||||
/* Joystick input report (1 bytes) (HID D.1) */
|
||||
struct usb_hid_js_report
|
||||
{
|
||||
uint8_t xpos; /* X position */
|
||||
uint8_t ypos; /* X position */
|
||||
int8_t xpos; /* X position */
|
||||
int8_t ypos; /* X position */
|
||||
uint8_t buttons; /* See USBHID_JSIN_* definitions */
|
||||
uint8_t throttle; /* Throttle */
|
||||
};
|
||||
|
@@ -50,6 +50,8 @@ static int hid_class_interface_request_handler(uint8_t busid, struct usb_setup_p
|
||||
|
||||
struct usbd_interface *usbd_hid_init_intf(uint8_t busid, struct usbd_interface *intf, const uint8_t *desc, uint32_t desc_len)
|
||||
{
|
||||
(void)busid;
|
||||
|
||||
intf->class_interface_handler = hid_class_interface_request_handler;
|
||||
intf->class_endpoint_handler = NULL;
|
||||
intf->vendor_handler = NULL;
|
||||
@@ -60,30 +62,65 @@ struct usbd_interface *usbd_hid_init_intf(uint8_t busid, struct usbd_interface *
|
||||
return intf;
|
||||
}
|
||||
|
||||
/*
|
||||
* Appendix G: HID Request Support Requirements
|
||||
*
|
||||
* The following table enumerates the requests that need to be supported by various types of HID class devices.
|
||||
* Device type GetReport SetReport GetIdle SetIdle GetProtocol SetProtocol
|
||||
* ------------------------------------------------------------------------------------------
|
||||
* Boot Mouse Required Optional Optional Optional Required Required
|
||||
* Non-Boot Mouse Required Optional Optional Optional Optional Optional
|
||||
* Boot Keyboard Required Optional Required Required Required Required
|
||||
* Non-Boot Keybrd Required Optional Required Required Optional Optional
|
||||
* Other Device Required Optional Optional Optional Optional Optional
|
||||
*/
|
||||
|
||||
__WEAK void usbd_hid_get_report(uint8_t busid, uint8_t intf, uint8_t report_id, uint8_t report_type, uint8_t **data, uint32_t *len)
|
||||
{
|
||||
(void)busid;
|
||||
(void)intf;
|
||||
(void)report_id;
|
||||
(void)report_type;
|
||||
(*data[0]) = 0;
|
||||
*len = 1;
|
||||
}
|
||||
|
||||
__WEAK uint8_t usbd_hid_get_idle(uint8_t busid, uint8_t intf, uint8_t report_id)
|
||||
{
|
||||
(void)busid;
|
||||
(void)intf;
|
||||
(void)report_id;
|
||||
return 0;
|
||||
}
|
||||
|
||||
__WEAK uint8_t usbd_hid_get_protocol(uint8_t busid, uint8_t intf)
|
||||
{
|
||||
(void)busid;
|
||||
(void)intf;
|
||||
return 0;
|
||||
}
|
||||
|
||||
__WEAK void usbd_hid_set_report(uint8_t busid, uint8_t intf, uint8_t report_id, uint8_t report_type, uint8_t *report, uint32_t report_len)
|
||||
{
|
||||
(void)busid;
|
||||
(void)intf;
|
||||
(void)report_id;
|
||||
(void)report_type;
|
||||
(void)report;
|
||||
(void)report_len;
|
||||
}
|
||||
|
||||
__WEAK void usbd_hid_set_idle(uint8_t busid, uint8_t intf, uint8_t report_id, uint8_t duration)
|
||||
{
|
||||
(void)busid;
|
||||
(void)intf;
|
||||
(void)report_id;
|
||||
(void)duration;
|
||||
}
|
||||
|
||||
__WEAK void usbd_hid_set_protocol(uint8_t busid, uint8_t intf, uint8_t protocol)
|
||||
{
|
||||
(void)busid;
|
||||
(void)intf;
|
||||
(void)protocol;
|
||||
}
|
@@ -12,18 +12,26 @@
|
||||
|
||||
#define DEV_FORMAT "/dev/input%d"
|
||||
|
||||
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_hid_buf[128];
|
||||
/* general descriptor field offsets */
|
||||
#define DESC_bLength 0 /** Length offset */
|
||||
#define DESC_bDescriptorType 1 /** Descriptor type offset */
|
||||
|
||||
/* interface descriptor field offsets */
|
||||
#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(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];
|
||||
@@ -34,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;
|
||||
@@ -56,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 = 128;
|
||||
setup->wLength = buflen;
|
||||
|
||||
ret = usbh_control_transfer(hid_class->hport, setup, g_hid_buf);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
memcpy(buffer, g_hid_buf, 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)
|
||||
@@ -100,11 +102,11 @@ int usbh_hid_get_idle(struct usbh_hid *hid_class, uint8_t *buffer)
|
||||
setup->wIndex = hid_class->intf;
|
||||
setup->wLength = 1;
|
||||
|
||||
ret = usbh_control_transfer(hid_class->hport, setup, g_hid_buf);
|
||||
if (ret < 0) {
|
||||
ret = usbh_control_transfer(hid_class->hport, setup, g_hid_buf[hid_class->minor]);
|
||||
if (ret < 8) {
|
||||
return ret;
|
||||
}
|
||||
memcpy(buffer, g_hid_buf, 1);
|
||||
memcpy(buffer, g_hid_buf[hid_class->minor], ret - 8);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -147,6 +149,7 @@ int usbh_hid_set_report(struct usbh_hid *hid_class, uint8_t report_type, uint8_t
|
||||
int usbh_hid_get_report(struct usbh_hid *hid_class, uint8_t report_type, uint8_t report_id, uint8_t *buffer, uint32_t buflen)
|
||||
{
|
||||
struct usb_setup_packet *setup;
|
||||
int ret;
|
||||
|
||||
if (!hid_class || !hid_class->hport) {
|
||||
return -USB_ERR_INVAL;
|
||||
@@ -159,13 +162,21 @@ int usbh_hid_get_report(struct usbh_hid *hid_class, uint8_t report_type, uint8_t
|
||||
setup->wIndex = 0;
|
||||
setup->wLength = buflen;
|
||||
|
||||
return usbh_control_transfer(hid_class->hport, setup, buffer);
|
||||
ret = usbh_control_transfer(hid_class->hport, setup, g_hid_buf[hid_class->minor]);
|
||||
if (ret < 8) {
|
||||
return ret;
|
||||
}
|
||||
memcpy(buffer, g_hid_buf[hid_class->minor], ret - 8);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int usbh_hid_connect(struct usbh_hubport *hport, uint8_t intf)
|
||||
{
|
||||
struct usb_endpoint_descriptor *ep_desc;
|
||||
int ret;
|
||||
uint8_t cur_iface = 0xff;
|
||||
uint8_t *p;
|
||||
bool found = false;
|
||||
|
||||
struct usbh_hid *hid_class = usbh_hid_class_alloc();
|
||||
if (hid_class == NULL) {
|
||||
@@ -178,6 +189,42 @@ int usbh_hid_connect(struct usbh_hubport *hport, uint8_t intf)
|
||||
|
||||
hport->config.intf[intf].priv = hid_class;
|
||||
|
||||
p = hport->raw_config_desc;
|
||||
while (p[DESC_bLength]) {
|
||||
switch (p[DESC_bDescriptorType]) {
|
||||
case USB_DESCRIPTOR_TYPE_INTERFACE:
|
||||
cur_iface = p[INTF_DESC_bInterfaceNumber];
|
||||
if (cur_iface == intf) {
|
||||
hid_class->protocol = p[7];
|
||||
struct usb_hid_descriptor *desc = (struct usb_hid_descriptor *)(p + 9);
|
||||
|
||||
if (desc->bDescriptorType != HID_DESCRIPTOR_TYPE_HID) {
|
||||
USB_LOG_ERR("HID descriptor not found\r\n");
|
||||
return -USB_ERR_INVAL;
|
||||
}
|
||||
|
||||
if (desc->subdesc[0].bDescriptorType != HID_DESCRIPTOR_TYPE_HID_REPORT) {
|
||||
USB_LOG_ERR("HID report descriptor not found\r\n");
|
||||
return -USB_ERR_INVAL;
|
||||
}
|
||||
|
||||
hid_class->report_size = desc->subdesc[0].wDescriptorLength;
|
||||
found = true;
|
||||
goto found;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
/* skip to next descriptor */
|
||||
p += p[DESC_bLength];
|
||||
}
|
||||
|
||||
if (found == false) {
|
||||
USB_LOG_ERR("HID interface not found\r\n");
|
||||
return -USB_ERR_INVAL;
|
||||
}
|
||||
found:
|
||||
// /* 0x0 = boot protocol, 0x1 = report protocol */
|
||||
// ret = usbh_hid_set_protocol(hid_class, 0x1);
|
||||
// if (ret < 0) {
|
||||
@@ -189,7 +236,8 @@ int usbh_hid_connect(struct usbh_hubport *hport, uint8_t intf)
|
||||
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;
|
||||
}
|
||||
@@ -239,10 +287,12 @@ int usbh_hid_disconnect(struct usbh_hubport *hport, uint8_t intf)
|
||||
|
||||
__WEAK void usbh_hid_run(struct usbh_hid *hid_class)
|
||||
{
|
||||
(void)hid_class;
|
||||
}
|
||||
|
||||
__WEAK void usbh_hid_stop(struct usbh_hid *hid_class)
|
||||
{
|
||||
(void)hid_class;
|
||||
}
|
||||
|
||||
const struct usbh_class_driver hid_class_driver = {
|
||||
@@ -253,9 +303,9 @@ const struct usbh_class_driver hid_class_driver = {
|
||||
|
||||
CLASS_INFO_DEFINE const struct usbh_class_info hid_custom_class_info = {
|
||||
.match_flags = USB_CLASS_MATCH_INTF_CLASS,
|
||||
.class = USB_DEVICE_CLASS_HID,
|
||||
.subclass = 0x00,
|
||||
.protocol = 0x00,
|
||||
.bInterfaceClass = USB_DEVICE_CLASS_HID,
|
||||
.bInterfaceSubClass = 0x00,
|
||||
.bInterfaceProtocol = 0x00,
|
||||
.id_table = NULL,
|
||||
.class_driver = &hid_class_driver
|
||||
};
|
||||
|
@@ -15,7 +15,9 @@ 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;
|
||||
uint8_t intf; /* interface number */
|
||||
uint8_t minor;
|
||||
|
||||
@@ -26,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);
|
||||
|
@@ -10,6 +10,12 @@
|
||||
#define HUB_DESCRIPTOR_TYPE_HUB 0x29
|
||||
#define HUB_DESCRIPTOR_TYPE_HUB3 0x2A
|
||||
|
||||
#define HUB_MAX_DEPTH 5
|
||||
|
||||
#define HUB_SUBCLASS 0x00
|
||||
#define HUB_PROTOCOL_STT 0x01
|
||||
#define HUB_PROTOCOL_MTT 0x02
|
||||
|
||||
/* Hub class requests */
|
||||
#define HUB_REQUEST_GET_STATUS USB_REQUEST_GET_STATUS
|
||||
#define HUB_REQUEST_CLEAR_FEATURE USB_REQUEST_CLEAR_FEATURE
|
||||
@@ -27,23 +33,31 @@
|
||||
#define HUB_FEATURE_HUB_C_OVERCURRENT (0x1)
|
||||
|
||||
/* Port features */
|
||||
#define HUB_PORT_FEATURE_CONNECTION (0x00)
|
||||
#define HUB_PORT_FEATURE_ENABLE (0x01)
|
||||
#define HUB_PORT_FEATURE_SUSPEND (0x02)
|
||||
#define HUB_PORT_FEATURE_OVERCURRENT (0x03)
|
||||
#define HUB_PORT_FEATURE_RESET (0x04)
|
||||
#define HUB_PORT_FEATURE_L1 (0x05)
|
||||
#define HUB_PORT_FEATURE_POWER (0x08)
|
||||
#define HUB_PORT_FEATURE_LOWSPEED (0x09)
|
||||
#define HUB_PORT_FEATURE_HIGHSPEED (0x0a)
|
||||
#define HUB_PORT_FEATURE_CONNECTION (0x00)
|
||||
#define HUB_PORT_FEATURE_ENABLE (0x01)
|
||||
#define HUB_PORT_FEATURE_SUSPEND (0x02)
|
||||
#define HUB_PORT_FEATURE_OVERCURRENT (0x03)
|
||||
#define HUB_PORT_FEATURE_RESET (0x04)
|
||||
#define HUB_PORT_FEATURE_L1 (0x05) /* USB 2.0 only */
|
||||
|
||||
#define HUB_PORT_FEATURE_POWER (0x08) /* USB 2.0 only */
|
||||
#define HUB_PORT_FEATURE_POWER_SS (0x09) /* USB 3.0 only */
|
||||
/* This is a bit tricky because HUB_PORT_FEATURE_POWER_SS and
|
||||
HUB_PORT_FEATURE_LOWSPEED share the same bit. */
|
||||
#define HUB_PORT_FEATURE_LOWSPEED (0x09) /* USB 2.0 only */
|
||||
#define HUB_PORT_FEATURE_HIGHSPEED (0x0a) /* USB 2.0 only */
|
||||
#define HUB_PORT_FEATURE_TEST (0x0b) /* USB 2.0 only */
|
||||
#define HUB_PORT_FEATURE_INDICATOR (0x0c) /* USB 2.0 only */
|
||||
|
||||
/* Port status change (wPortChange) */
|
||||
#define HUB_PORT_FEATURE_C_CONNECTION (0x10)
|
||||
#define HUB_PORT_FEATURE_C_ENABLE (0x11)
|
||||
#define HUB_PORT_FEATURE_C_SUSPEND (0x12)
|
||||
#define HUB_PORT_FEATURE_C_ENABLE (0x11) /* USB 2.0 only */
|
||||
#define HUB_PORT_FEATURE_C_SUSPEND (0x12) /* USB 2.0 only */
|
||||
#define HUB_PORT_FEATURE_C_OVER_CURREN (0x13)
|
||||
#define HUB_PORT_FEATURE_C_RESET (0x14)
|
||||
#define HUB_PORT_FEATURE_TEST (0x15)
|
||||
#define HUB_PORT_FEATURE_INDICATOR (0x16)
|
||||
#define HUB_PORT_FEATURE_C_PORTL1 (0x17)
|
||||
#define HUB_PORT_FEATURE_C_BH_RESET (0x15) /* USB 3.0 only */
|
||||
#define HUB_PORT_FEATURE_C_LINK_STATE (0x16) /* USB 3.0 only */
|
||||
#define HUB_PORT_FEATURE_C_CONFIG_ERR (0x17) /* USB 3.0 only */
|
||||
|
||||
/* Hub status */
|
||||
#define HUB_STATUS_LOCALPOWER (1 << 0)
|
||||
@@ -56,23 +70,42 @@
|
||||
/* Hub port status */
|
||||
#define HUB_PORT_STATUS_CONNECTION (1 << 0)
|
||||
#define HUB_PORT_STATUS_ENABLE (1 << 1)
|
||||
#define HUB_PORT_STATUS_SUSPEND (1 << 2)
|
||||
#define HUB_PORT_STATUS_SUSPEND (1 << 2) /* USB 2.0 only */
|
||||
#define HUB_PORT_STATUS_OVERCURRENT (1 << 3)
|
||||
#define HUB_PORT_STATUS_RESET (1 << 4)
|
||||
#define HUB_PORT_STATUS_L1 (1 << 5)
|
||||
#define HUB_PORT_STATUS_POWER (1 << 8)
|
||||
#define HUB_PORT_STATUS_LOW_SPEED (1 << 9)
|
||||
#define HUB_PORT_STATUS_HIGH_SPEED (1 << 10)
|
||||
#define HUB_PORT_STATUS_TEST (1 << 11)
|
||||
#define HUB_PORT_STATUS_INDICATOR (1 << 12)
|
||||
#define HUB_PORT_STATUS_L1 (1 << 5) /* USB 2.0 only */
|
||||
|
||||
/* Port Link State (PORT_LINK_STATE), USB 3.0 only */
|
||||
#define HUB_PORT_STATUS_LS_U0 (0x00 << 5)
|
||||
#define HUB_PORT_STATUS_LS_U1 (0x01 << 5)
|
||||
#define HUB_PORT_STATUS_LS_U2 (0x02 << 5)
|
||||
#define HUB_PORT_STATUS_LS_U3 (0x03 << 5)
|
||||
#define HUB_PORT_STATUS_LS_SS_DISABLED (0x04 << 5)
|
||||
#define HUB_PORT_STATUS_LS_RX_DETECT (0x05 << 5)
|
||||
#define HUB_PORT_STATUS_LS_SS_INACTIVE (0x06 << 5)
|
||||
#define HUB_PORT_STATUS_LS_POLLING (0x07 << 5)
|
||||
#define HUB_PORT_STATUS_LS_RECOVERY (0x08 << 5)
|
||||
#define HUB_PORT_STATUS_LS_HOT_RESET (0x09 << 5)
|
||||
#define HUB_PORT_STATUS_LS_COMP_MOD (0x0a << 5)
|
||||
#define HUB_PORT_STATUS_LS_LOOPBACK (0x0b << 5)
|
||||
|
||||
#define HUB_PORT_STATUS_POWER (1 << 8)
|
||||
#define HUB_PORT_STATUS_POWER_SS (1 << 9) /* USB 3.0 only */
|
||||
#define HUB_PORT_STATUS_LOW_SPEED (1 << 9) /* USB 2.0 only */
|
||||
#define HUB_PORT_STATUS_HIGH_SPEED (1 << 10) /* USB 2.0 only */
|
||||
#define HUB_PORT_STATUS_TEST (1 << 11) /* USB 2.0 only */
|
||||
#define HUB_PORT_STATUS_INDICATOR (1 << 12) /* USB 2.0 only */
|
||||
|
||||
/* Hub port status change */
|
||||
#define HUB_PORT_STATUS_C_CONNECTION (1 << 0)
|
||||
#define HUB_PORT_STATUS_C_ENABLE (1 << 1)
|
||||
#define HUB_PORT_STATUS_C_SUSPEND (1 << 2)
|
||||
#define HUB_PORT_STATUS_C_ENABLE (1 << 1) /* USB 2.0 only */
|
||||
#define HUB_PORT_STATUS_C_SUSPEND (1 << 2) /* USB 2.0 only */
|
||||
#define HUB_PORT_STATUS_C_OVERCURRENT (1 << 3)
|
||||
#define HUB_PORT_STATUS_C_RESET (1 << 4)
|
||||
#define HUB_PORT_STATUS_C_L1 (1 << 5)
|
||||
#define HUB_PORT_STATUS_C_L1 (1 << 5) /* USB 2.0 only */
|
||||
#define HUB_PORT_STATUS_C_BH_RESET (1 << 5) /* USB 3.0 only */
|
||||
#define HUB_PORT_STATUS_C_PORTLINK (1 << 6) /* USB 3.0 only */
|
||||
#define HUB_PORT_STATUS_C_CONFIGERR (1 << 7) /* USB 3.0 only */
|
||||
|
||||
/* Hub characteristics */
|
||||
#define HUB_CHAR_LPSM_SHIFT (0) /* Bits 0-1: Logical Power Switching Mode */
|
||||
@@ -106,6 +139,21 @@ struct usb_hub_descriptor {
|
||||
|
||||
#define USB_SIZEOF_HUB_DESC 9
|
||||
|
||||
/* Super speed Hub descriptor */
|
||||
struct usb_hub_ss_descriptor {
|
||||
uint8_t bLength;
|
||||
uint8_t bDescriptorType;
|
||||
uint8_t bNbrPorts;
|
||||
uint16_t wHubCharacteristics;
|
||||
uint8_t bPwrOn2PwrGood;
|
||||
uint8_t bHubContrCurrent;
|
||||
uint8_t bHubHdrDecLat;
|
||||
uint16_t wHubDelay;
|
||||
uint8_t DeviceRemovable;
|
||||
} __PACKED;
|
||||
|
||||
#define USB_SIZEOF_HUB_SS_DESC 11
|
||||
|
||||
/* Hub status */
|
||||
struct hub_status {
|
||||
uint16_t wPortStatus;
|
||||
|
@@ -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,16 +48,14 @@ 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));
|
||||
}
|
||||
#endif
|
||||
|
||||
#if CONFIG_USBHOST_MAX_EXTHUBS > 0
|
||||
static int _usbh_hub_get_hub_descriptor(struct usbh_hub *hub, uint8_t *buffer)
|
||||
{
|
||||
struct usb_setup_packet *setup;
|
||||
@@ -67,15 +65,7 @@ static int _usbh_hub_get_hub_descriptor(struct usbh_hub *hub, uint8_t *buffer)
|
||||
|
||||
setup->bmRequestType = USB_REQUEST_DIR_IN | USB_REQUEST_CLASS | USB_REQUEST_RECIPIENT_DEVICE;
|
||||
setup->bRequest = USB_REQUEST_GET_DESCRIPTOR;
|
||||
|
||||
/* TODO: hub descriptor has some difference between USB 2.0 and USB 3.x,
|
||||
and we havn't handle the difference here */
|
||||
if ((hub->parent->speed == USB_SPEED_SUPER) ||
|
||||
(hub->parent->speed == USB_SPEED_SUPER_PLUS)) {
|
||||
setup->wValue = HUB_DESCRIPTOR_TYPE_HUB3 << 8;
|
||||
} else {
|
||||
setup->wValue = HUB_DESCRIPTOR_TYPE_HUB << 8;
|
||||
}
|
||||
setup->wValue = HUB_DESCRIPTOR_TYPE_HUB << 8;
|
||||
|
||||
setup->wIndex = 0;
|
||||
setup->wLength = USB_SIZEOF_HUB_DESC;
|
||||
@@ -87,8 +77,8 @@ static int _usbh_hub_get_hub_descriptor(struct usbh_hub *hub, uint8_t *buffer)
|
||||
memcpy(buffer, g_hub_buf[hub->bus->busid], USB_SIZEOF_HUB_DESC);
|
||||
return ret;
|
||||
}
|
||||
#if 0
|
||||
static int _usbh_hub_get_status(struct usbh_hub *hub, uint8_t *buffer)
|
||||
|
||||
static int _usbh_hub_get_hub_ss_descriptor(struct usbh_hub *hub, uint8_t *buffer)
|
||||
{
|
||||
struct usb_setup_packet *setup;
|
||||
int ret;
|
||||
@@ -96,20 +86,20 @@ static int _usbh_hub_get_status(struct usbh_hub *hub, uint8_t *buffer)
|
||||
setup = hub->parent->setup;
|
||||
|
||||
setup->bmRequestType = USB_REQUEST_DIR_IN | USB_REQUEST_CLASS | USB_REQUEST_RECIPIENT_DEVICE;
|
||||
setup->bRequest = HUB_REQUEST_GET_STATUS;
|
||||
setup->wValue = 0;
|
||||
setup->bRequest = USB_REQUEST_GET_DESCRIPTOR;
|
||||
setup->wValue = HUB_DESCRIPTOR_TYPE_HUB3 << 8;
|
||||
|
||||
setup->wIndex = 0;
|
||||
setup->wLength = 2;
|
||||
setup->wLength = USB_SIZEOF_HUB_SS_DESC;
|
||||
|
||||
ret = usbh_control_transfer(hub->parent, setup, g_hub_buf[hub->bus->busid]);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
memcpy(buffer, g_hub_buf[hub->bus->busid], 2);
|
||||
memcpy(buffer, g_hub_buf[hub->bus->busid], USB_SIZEOF_HUB_SS_DESC);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
static int _usbh_hub_get_portstatus(struct usbh_hub *hub, uint8_t port, struct hub_port_status *port_status)
|
||||
{
|
||||
@@ -180,6 +170,8 @@ static int _usbh_hub_set_depth(struct usbh_hub *hub, uint16_t depth)
|
||||
#if CONFIG_USBHOST_MAX_EXTHUBS > 0
|
||||
static int parse_hub_descriptor(struct usb_hub_descriptor *desc, uint16_t length)
|
||||
{
|
||||
(void)length;
|
||||
|
||||
if (desc->bLength != USB_SIZEOF_HUB_DESC) {
|
||||
USB_LOG_ERR("invalid device bLength 0x%02x\r\n", desc->bLength);
|
||||
return -1;
|
||||
@@ -199,6 +191,29 @@ static int parse_hub_descriptor(struct usb_hub_descriptor *desc, uint16_t length
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int parse_hub_ss_descriptor(struct usb_hub_ss_descriptor *desc, uint16_t length)
|
||||
{
|
||||
(void)length;
|
||||
|
||||
if (desc->bLength < USB_SIZEOF_HUB_SS_DESC) {
|
||||
USB_LOG_ERR("invalid device bLength 0x%02x\r\n", desc->bLength);
|
||||
return -1;
|
||||
} else if (desc->bDescriptorType != HUB_DESCRIPTOR_TYPE_HUB3) {
|
||||
USB_LOG_ERR("unexpected descriptor 0x%02x\r\n", desc->bDescriptorType);
|
||||
return -2;
|
||||
} else {
|
||||
USB_LOG_RAW("SuperSpeed Hub Descriptor:\r\n");
|
||||
USB_LOG_RAW("bLength: 0x%02x \r\n", desc->bLength);
|
||||
USB_LOG_RAW("bDescriptorType: 0x%02x \r\n", desc->bDescriptorType);
|
||||
USB_LOG_RAW("bNbrPorts: 0x%02x \r\n", desc->bNbrPorts);
|
||||
USB_LOG_RAW("wHubCharacteristics: 0x%04x \r\n", desc->wHubCharacteristics);
|
||||
USB_LOG_RAW("bPwrOn2PwrGood: 0x%02x \r\n", desc->bPwrOn2PwrGood);
|
||||
USB_LOG_RAW("bHubContrCurrent: 0x%02x \r\n", desc->bHubContrCurrent);
|
||||
USB_LOG_RAW("DeviceRemovable: 0x%02x \r\n", desc->DeviceRemovable);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
static int usbh_hub_get_portstatus(struct usbh_hub *hub, uint8_t port, struct hub_port_status *port_status)
|
||||
@@ -311,22 +326,65 @@ static int usbh_hub_connect(struct usbh_hubport *hport, uint8_t intf)
|
||||
hub->hub_addr = hport->dev_addr;
|
||||
hub->parent = hport;
|
||||
hub->bus = hport->bus;
|
||||
hub->speed = hport->speed;
|
||||
|
||||
hport->self = hub;
|
||||
hport->config.intf[intf].priv = hub;
|
||||
|
||||
ret = _usbh_hub_get_hub_descriptor(hub, (uint8_t *)&hub->hub_desc);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
if (hport->depth > HUB_MAX_DEPTH) {
|
||||
USB_LOG_ERR("Hub depth(%d) is overflow\r\n", hport->depth);
|
||||
return -USB_ERR_INVAL;
|
||||
}
|
||||
|
||||
parse_hub_descriptor(&hub->hub_desc, USB_SIZEOF_HUB_DESC);
|
||||
/*
|
||||
* Super-Speed hubs need to know their depth to be able to
|
||||
* parse the bits of the route-string that correspond to
|
||||
* their downstream port number.
|
||||
*
|
||||
*/
|
||||
if ((hport->depth != 0) && (hport->speed == USB_SPEED_SUPER)) {
|
||||
ret = usbh_hub_set_depth(hub, hport->depth - 1);
|
||||
if (ret < 0) {
|
||||
USB_LOG_ERR("Unable to set hub depth \r\n");
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
for (uint8_t port = 0; port < hub->hub_desc.bNbrPorts; port++) {
|
||||
/* Get hub descriptor. */
|
||||
if (hport->speed == USB_SPEED_SUPER) {
|
||||
ret = _usbh_hub_get_hub_ss_descriptor(hub, (uint8_t *)&hub->hub_ss_desc);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
parse_hub_ss_descriptor(&hub->hub_ss_desc, USB_SIZEOF_HUB_SS_DESC);
|
||||
hub->nports = hub->hub_ss_desc.bNbrPorts;
|
||||
hub->powerdelay = hub->hub_ss_desc.bPwrOn2PwrGood * 2;
|
||||
hub->tt_think = 0U;
|
||||
} else {
|
||||
ret = _usbh_hub_get_hub_descriptor(hub, (uint8_t *)&hub->hub_desc);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
parse_hub_descriptor(&hub->hub_desc, USB_SIZEOF_HUB_DESC);
|
||||
hub->nports = hub->hub_desc.bNbrPorts;
|
||||
hub->powerdelay = hub->hub_desc.bPwrOn2PwrGood * 2;
|
||||
hub->tt_think = ((hub->hub_desc.wHubCharacteristics & HUB_CHAR_TTTT_MASK) >> 5);
|
||||
}
|
||||
|
||||
for (uint8_t port = 0; port < hub->nports; port++) {
|
||||
hub->child[port].port = port + 1;
|
||||
hub->child[port].parent = hub;
|
||||
hub->child[port].bus = hport->bus;
|
||||
}
|
||||
|
||||
if (hport->device_desc.bDeviceProtocol == HUB_PROTOCOL_MTT) {
|
||||
hub->ismtt = 1;
|
||||
} else {
|
||||
hub->ismtt = 0;
|
||||
}
|
||||
|
||||
ep_desc = &hport->config.intf[intf].altsetting[0].ep[0].ep_desc;
|
||||
if (ep_desc->bEndpointAddress & 0x80) {
|
||||
USBH_EP_INIT(hub->intin, ep_desc);
|
||||
@@ -334,28 +392,16 @@ static int usbh_hub_connect(struct usbh_hubport *hport, uint8_t intf)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (hport->speed == USB_SPEED_SUPER) {
|
||||
uint16_t depth = 0;
|
||||
struct usbh_hubport *parent = hport->parent->parent;
|
||||
while (parent) {
|
||||
depth++;
|
||||
parent = parent->parent->parent;
|
||||
}
|
||||
|
||||
ret = usbh_hub_set_depth(hub, depth);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
for (uint8_t port = 0; port < hub->hub_desc.bNbrPorts; port++) {
|
||||
for (uint8_t port = 0; port < hub->nports; port++) {
|
||||
ret = usbh_hub_set_feature(hub, port + 1, HUB_PORT_FEATURE_POWER);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
for (uint8_t port = 0; port < hub->hub_desc.bNbrPorts; port++) {
|
||||
usb_osal_msleep(hub->powerdelay);
|
||||
|
||||
for (uint8_t port = 0; port < hub->nports; port++) {
|
||||
ret = usbh_hub_get_portstatus(hub, port + 1, &port_status);
|
||||
USB_LOG_INFO("port %u, status:0x%02x, change:0x%02x\r\n", port + 1, port_status.wPortStatus, port_status.wPortChange);
|
||||
if (ret < 0) {
|
||||
@@ -395,7 +441,7 @@ static int usbh_hub_disconnect(struct usbh_hubport *hport, uint8_t intf)
|
||||
usb_osal_timer_delete(hub->int_timer);
|
||||
}
|
||||
|
||||
for (uint8_t port = 0; port < hub->hub_desc.bNbrPorts; port++) {
|
||||
for (uint8_t port = 0; port < hub->nports; port++) {
|
||||
child = &hub->child[port];
|
||||
usbh_hubport_release(child);
|
||||
child->parent = NULL;
|
||||
@@ -415,7 +461,7 @@ static void usbh_hub_events(struct usbh_hub *hub)
|
||||
{
|
||||
struct usbh_hubport *child;
|
||||
struct hub_port_status port_status;
|
||||
uint8_t portchange_index;
|
||||
uint16_t portchange_index;
|
||||
uint16_t portstatus;
|
||||
uint16_t portchange;
|
||||
uint16_t mask;
|
||||
@@ -429,11 +475,10 @@ static void usbh_hub_events(struct usbh_hub *hub)
|
||||
}
|
||||
|
||||
flags = usb_osal_enter_critical_section();
|
||||
portchange_index = hub->int_buffer[0];
|
||||
hub->int_buffer[0] &= ~portchange_index;
|
||||
memcpy(&portchange_index, hub->int_buffer, 2);
|
||||
usb_osal_leave_critical_section(flags);
|
||||
|
||||
for (uint8_t port = 0; port < hub->hub_desc.bNbrPorts; port++) {
|
||||
for (uint8_t port = 0; port < hub->nports; port++) {
|
||||
USB_LOG_DBG("Port change:0x%02x\r\n", portchange_index);
|
||||
|
||||
if (!(portchange_index & (1 << (port + 1)))) {
|
||||
@@ -539,12 +584,23 @@ static void usbh_hub_events(struct usbh_hub *hub)
|
||||
}
|
||||
}
|
||||
|
||||
if (portstatus & HUB_PORT_STATUS_HIGH_SPEED) {
|
||||
speed = USB_SPEED_HIGH;
|
||||
} else if (portstatus & HUB_PORT_STATUS_LOW_SPEED) {
|
||||
speed = USB_SPEED_LOW;
|
||||
/*
|
||||
* Figure out device speed. This is a bit tricky because
|
||||
* HUB_PORT_STATUS_POWER_SS and HUB_PORT_STATUS_LOW_SPEED share the same bit.
|
||||
*/
|
||||
if (portstatus & HUB_PORT_STATUS_POWER) {
|
||||
if (portstatus & HUB_PORT_STATUS_HIGH_SPEED) {
|
||||
speed = USB_SPEED_HIGH;
|
||||
} else if (portstatus & HUB_PORT_STATUS_LOW_SPEED) {
|
||||
speed = USB_SPEED_LOW;
|
||||
} else {
|
||||
speed = USB_SPEED_FULL;
|
||||
}
|
||||
} else if (portstatus & HUB_PORT_STATUS_POWER_SS) {
|
||||
speed = USB_SPEED_SUPER;
|
||||
} else {
|
||||
speed = USB_SPEED_FULL;
|
||||
USB_LOG_WRN("Port %u does not enable power\r\n", port + 1);
|
||||
continue;
|
||||
}
|
||||
|
||||
child = &hub->child[port];
|
||||
@@ -553,6 +609,7 @@ static void usbh_hub_events(struct usbh_hub *hub)
|
||||
|
||||
memset(child, 0, sizeof(struct usbh_hubport));
|
||||
child->parent = hub;
|
||||
child->depth = (hub->parent ? hub->parent->depth : 0) + 1;
|
||||
child->connected = true;
|
||||
child->port = port + 1;
|
||||
child->speed = speed;
|
||||
@@ -624,7 +681,7 @@ int usbh_hub_initialize(struct usbh_bus *bus)
|
||||
hub->is_roothub = true;
|
||||
hub->parent = NULL;
|
||||
hub->hub_addr = 1;
|
||||
hub->hub_desc.bNbrPorts = CONFIG_USBHOST_MAX_RHPORTS;
|
||||
hub->nports = CONFIG_USBHOST_MAX_RHPORTS;
|
||||
hub->int_buffer = bus->hcd.roothub_intbuf;
|
||||
hub->bus = bus;
|
||||
|
||||
@@ -652,7 +709,7 @@ int usbh_hub_deinitialize(struct usbh_bus *bus)
|
||||
flags = usb_osal_enter_critical_section();
|
||||
|
||||
hub = &bus->hcd.roothub;
|
||||
for (uint8_t port = 0; port < hub->hub_desc.bNbrPorts; port++) {
|
||||
for (uint8_t port = 0; port < hub->nports; port++) {
|
||||
hport = &hub->child[port];
|
||||
|
||||
usbh_hubport_release(hport);
|
||||
@@ -677,9 +734,9 @@ const struct usbh_class_driver hub_class_driver = {
|
||||
|
||||
CLASS_INFO_DEFINE const struct usbh_class_info hub_class_info = {
|
||||
.match_flags = USB_CLASS_MATCH_INTF_CLASS,
|
||||
.class = USB_DEVICE_CLASS_HUB,
|
||||
.subclass = 0,
|
||||
.protocol = 0,
|
||||
.bInterfaceClass = USB_DEVICE_CLASS_HUB,
|
||||
.bInterfaceSubClass = 0,
|
||||
.bInterfaceProtocol = 0,
|
||||
.id_table = NULL,
|
||||
.class_driver = &hub_class_driver
|
||||
};
|
||||
|
@@ -10,10 +10,6 @@
|
||||
|
||||
struct usbh_hub;
|
||||
|
||||
#define USBH_HUB_MAX_PORTS 4
|
||||
/* Maximum size of an interrupt IN transfer */
|
||||
#define USBH_HUB_INTIN_BUFSIZE ((USBH_HUB_MAX_PORTS + 8) >> 3)
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
@@ -9,6 +9,8 @@
|
||||
#include "usb_scsi.h"
|
||||
#if defined(CONFIG_USBDEV_MSC_THREAD)
|
||||
#include "usb_osal.h"
|
||||
#elif defined(CONFIG_USBDEV_MSC_POLLING)
|
||||
#include "chry_ringbuffer.h"
|
||||
#endif
|
||||
|
||||
#define MSD_OUT_EP_IDX 0
|
||||
@@ -50,6 +52,10 @@ USB_NOCACHE_RAM_SECTION struct usbd_msc_priv {
|
||||
usb_osal_mq_t usbd_msc_mq;
|
||||
usb_osal_thread_t usbd_msc_thread;
|
||||
uint32_t nbytes;
|
||||
#elif defined(CONFIG_USBDEV_MSC_POLLING)
|
||||
chry_ringbuffer_t msc_rb;
|
||||
uint8_t msc_rb_pool[2];
|
||||
uint32_t nbytes;
|
||||
#endif
|
||||
} g_usbd_msc[CONFIG_USBDEV_MAX_BUS];
|
||||
|
||||
@@ -94,21 +100,25 @@ static int msc_storage_class_interface_request_handler(uint8_t busid, struct usb
|
||||
|
||||
void msc_storage_notify_handler(uint8_t busid, uint8_t event, void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
|
||||
switch (event) {
|
||||
case USBD_EVENT_INIT:
|
||||
#ifdef CONFIG_USBDEV_MSC_THREAD
|
||||
#if defined(CONFIG_USBDEV_MSC_THREAD)
|
||||
g_usbd_msc[busid].usbd_msc_mq = usb_osal_mq_create(1);
|
||||
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");
|
||||
}
|
||||
#elif defined(CONFIG_USBDEV_MSC_POLLING)
|
||||
chry_ringbuffer_init(&g_usbd_msc[busid].msc_rb, g_usbd_msc[busid].msc_rb_pool, sizeof(g_usbd_msc[busid].msc_rb_pool));
|
||||
#endif
|
||||
break;
|
||||
case USBD_EVENT_DEINIT:
|
||||
#ifdef CONFIG_USBDEV_MSC_THREAD
|
||||
#if defined(CONFIG_USBDEV_MSC_THREAD)
|
||||
if (g_usbd_msc[busid].usbd_msc_mq) {
|
||||
usb_osal_mq_delete(g_usbd_msc[busid].usbd_msc_mq);
|
||||
}
|
||||
@@ -500,6 +510,9 @@ static bool SCSI_readCapacity10(uint8_t busid, uint8_t **data, uint32_t *len)
|
||||
|
||||
static bool SCSI_read10(uint8_t busid, uint8_t **data, uint32_t *len)
|
||||
{
|
||||
(void)data;
|
||||
(void)len;
|
||||
|
||||
if (((g_usbd_msc[busid].cbw.bmFlags & 0x80U) != 0x80U) || (g_usbd_msc[busid].cbw.dDataLength == 0U)) {
|
||||
SCSI_SetSenseData(busid, SCSI_KCQIR_INVALIDCOMMAND);
|
||||
return false;
|
||||
@@ -522,9 +535,12 @@ static bool SCSI_read10(uint8_t busid, uint8_t **data, uint32_t *len)
|
||||
return false;
|
||||
}
|
||||
g_usbd_msc[busid].stage = MSC_DATA_IN;
|
||||
#ifdef CONFIG_USBDEV_MSC_THREAD
|
||||
#if defined(CONFIG_USBDEV_MSC_THREAD)
|
||||
usb_osal_mq_send(g_usbd_msc[busid].usbd_msc_mq, MSC_DATA_IN);
|
||||
return true;
|
||||
#elif defined(CONFIG_USBDEV_MSC_POLLING)
|
||||
chry_ringbuffer_write_byte(&g_usbd_msc[busid].msc_rb, MSC_DATA_IN);
|
||||
return true;
|
||||
#else
|
||||
return SCSI_processRead(busid);
|
||||
#endif
|
||||
@@ -532,6 +548,9 @@ static bool SCSI_read10(uint8_t busid, uint8_t **data, uint32_t *len)
|
||||
|
||||
static bool SCSI_read12(uint8_t busid, uint8_t **data, uint32_t *len)
|
||||
{
|
||||
(void)data;
|
||||
(void)len;
|
||||
|
||||
if (((g_usbd_msc[busid].cbw.bmFlags & 0x80U) != 0x80U) || (g_usbd_msc[busid].cbw.dDataLength == 0U)) {
|
||||
SCSI_SetSenseData(busid, SCSI_KCQIR_INVALIDCOMMAND);
|
||||
return false;
|
||||
@@ -554,9 +573,12 @@ static bool SCSI_read12(uint8_t busid, uint8_t **data, uint32_t *len)
|
||||
return false;
|
||||
}
|
||||
g_usbd_msc[busid].stage = MSC_DATA_IN;
|
||||
#ifdef CONFIG_USBDEV_MSC_THREAD
|
||||
#if defined(CONFIG_USBDEV_MSC_THREAD)
|
||||
usb_osal_mq_send(g_usbd_msc[busid].usbd_msc_mq, MSC_DATA_IN);
|
||||
return true;
|
||||
#elif defined(CONFIG_USBDEV_MSC_POLLING)
|
||||
chry_ringbuffer_write_byte(&g_usbd_msc[busid].msc_rb, MSC_DATA_IN);
|
||||
return true;
|
||||
#else
|
||||
return SCSI_processRead(busid);
|
||||
#endif
|
||||
@@ -565,6 +587,10 @@ static bool SCSI_read12(uint8_t busid, uint8_t **data, uint32_t *len)
|
||||
static bool SCSI_write10(uint8_t busid, uint8_t **data, uint32_t *len)
|
||||
{
|
||||
uint32_t data_len = 0;
|
||||
|
||||
(void)data;
|
||||
(void)len;
|
||||
|
||||
if (((g_usbd_msc[busid].cbw.bmFlags & 0x80U) != 0x00U) || (g_usbd_msc[busid].cbw.dDataLength == 0U)) {
|
||||
SCSI_SetSenseData(busid, SCSI_KCQIR_INVALIDCOMMAND);
|
||||
return false;
|
||||
@@ -594,6 +620,10 @@ static bool SCSI_write10(uint8_t busid, uint8_t **data, uint32_t *len)
|
||||
static bool SCSI_write12(uint8_t busid, uint8_t **data, uint32_t *len)
|
||||
{
|
||||
uint32_t data_len = 0;
|
||||
|
||||
(void)data;
|
||||
(void)len;
|
||||
|
||||
if (((g_usbd_msc[busid].cbw.bmFlags & 0x80U) != 0x00U) || (g_usbd_msc[busid].cbw.dDataLength == 0U)) {
|
||||
SCSI_SetSenseData(busid, SCSI_KCQIR_INVALIDCOMMAND);
|
||||
return false;
|
||||
@@ -803,6 +833,8 @@ static bool SCSI_CBWDecode(uint8_t busid, uint32_t nbytes)
|
||||
|
||||
void mass_storage_bulk_out(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
{
|
||||
(void)ep;
|
||||
|
||||
switch (g_usbd_msc[busid].stage) {
|
||||
case MSC_READ_CBW:
|
||||
if (SCSI_CBWDecode(busid, nbytes) == false) {
|
||||
@@ -815,9 +847,12 @@ void mass_storage_bulk_out(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
switch (g_usbd_msc[busid].cbw.CB[0]) {
|
||||
case SCSI_CMD_WRITE10:
|
||||
case SCSI_CMD_WRITE12:
|
||||
#ifdef CONFIG_USBDEV_MSC_THREAD
|
||||
#if defined(CONFIG_USBDEV_MSC_THREAD)
|
||||
g_usbd_msc[busid].nbytes = nbytes;
|
||||
usb_osal_mq_send(g_usbd_msc[busid].usbd_msc_mq, MSC_DATA_OUT);
|
||||
#elif defined(CONFIG_USBDEV_MSC_POLLING)
|
||||
g_usbd_msc[busid].nbytes = nbytes;
|
||||
chry_ringbuffer_write_byte(&g_usbd_msc[busid].msc_rb, MSC_DATA_OUT);
|
||||
#else
|
||||
if (SCSI_processWrite(busid, nbytes) == false) {
|
||||
usbd_msc_send_csw(busid, CSW_STATUS_CMD_FAILED); /* send fail status to host,and the host will retry*/
|
||||
@@ -835,13 +870,18 @@ void mass_storage_bulk_out(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
|
||||
void mass_storage_bulk_in(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
{
|
||||
(void)ep;
|
||||
(void)nbytes;
|
||||
|
||||
switch (g_usbd_msc[busid].stage) {
|
||||
case MSC_DATA_IN:
|
||||
switch (g_usbd_msc[busid].cbw.CB[0]) {
|
||||
case SCSI_CMD_READ10:
|
||||
case SCSI_CMD_READ12:
|
||||
#ifdef CONFIG_USBDEV_MSC_THREAD
|
||||
#if defined(CONFIG_USBDEV_MSC_THREAD)
|
||||
usb_osal_mq_send(g_usbd_msc[busid].usbd_msc_mq, MSC_DATA_IN);
|
||||
#elif defined(CONFIG_USBDEV_MSC_POLLING)
|
||||
chry_ringbuffer_write_byte(&g_usbd_msc[busid].msc_rb, MSC_DATA_IN);
|
||||
#else
|
||||
if (SCSI_processRead(busid) == false) {
|
||||
usbd_msc_send_csw(busid, CSW_STATUS_CMD_FAILED); /* send fail status to host,and the host will retry*/
|
||||
@@ -870,19 +910,38 @@ void mass_storage_bulk_in(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef CONFIG_USBDEV_MSC_THREAD
|
||||
#if defined(CONFIG_USBDEV_MSC_THREAD)
|
||||
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);
|
||||
if (ret < 0) {
|
||||
continue;
|
||||
}
|
||||
USB_LOG_DBG("%d\r\n", event);
|
||||
USB_LOG_DBG("event:%d\r\n", event);
|
||||
if (event == MSC_DATA_OUT) {
|
||||
if (SCSI_processWrite(busid, g_usbd_msc[busid].nbytes) == false) {
|
||||
usbd_msc_send_csw(busid, CSW_STATUS_CMD_FAILED); /* send fail status to host,and the host will retry*/
|
||||
}
|
||||
} else if (event == MSC_DATA_IN) {
|
||||
if (SCSI_processRead(busid) == false) {
|
||||
usbd_msc_send_csw(busid, CSW_STATUS_CMD_FAILED); /* send fail status to host,and the host will retry*/
|
||||
}
|
||||
} else {
|
||||
}
|
||||
}
|
||||
}
|
||||
#elif defined(CONFIG_USBDEV_MSC_POLLING)
|
||||
void usbd_msc_polling(uint8_t busid)
|
||||
{
|
||||
uint8_t event;
|
||||
|
||||
if (chry_ringbuffer_read_byte(&g_usbd_msc[busid].msc_rb, &event)) {
|
||||
USB_LOG_DBG("event:%d\r\n", event);
|
||||
if (event == MSC_DATA_OUT) {
|
||||
if (SCSI_processWrite(busid, g_usbd_msc[busid].nbytes) == false) {
|
||||
usbd_msc_send_csw(busid, CSW_STATUS_CMD_FAILED); /* send fail status to host,and the host will retry*/
|
||||
@@ -918,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){}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -932,7 +991,7 @@ void usbd_msc_set_readonly(uint8_t busid, bool readonly)
|
||||
g_usbd_msc[busid].readonly = readonly;
|
||||
}
|
||||
|
||||
bool usbd_msc_set_popup(uint8_t busid)
|
||||
bool usbd_msc_get_popup(uint8_t busid)
|
||||
{
|
||||
return g_usbd_msc[busid].popup;
|
||||
}
|
||||
|
@@ -23,7 +23,9 @@ int usbd_msc_sector_read(uint8_t busid, uint8_t lun, uint32_t sector, uint8_t *b
|
||||
int usbd_msc_sector_write(uint8_t busid, uint8_t lun, uint32_t sector, uint8_t *buffer, uint32_t length);
|
||||
|
||||
void usbd_msc_set_readonly(uint8_t busid, bool readonly);
|
||||
bool usbd_msc_set_popup(uint8_t busid);
|
||||
bool usbd_msc_get_popup(uint8_t busid);
|
||||
|
||||
void usbd_msc_polling(uint8_t busid);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@@ -15,7 +15,7 @@
|
||||
|
||||
#define MSC_INQUIRY_TIMEOUT 500
|
||||
|
||||
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_msc_buf[64];
|
||||
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_msc_buf[CONFIG_USBHOST_MAX_MSC_CLASS][USB_ALIGN_UP(64, CONFIG_USB_ALIGN_SIZE)];
|
||||
|
||||
static struct usbh_msc g_msc_class[CONFIG_USBHOST_MAX_MSC_CLASS];
|
||||
static uint32_t g_devinuse = 0;
|
||||
@@ -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));
|
||||
}
|
||||
@@ -87,6 +87,8 @@ static void usbh_msc_cbw_dump(struct CBW *cbw)
|
||||
|
||||
static void usbh_msc_csw_dump(struct CSW *csw)
|
||||
{
|
||||
(void)csw;
|
||||
|
||||
USB_LOG_DBG("CSW:\r\n");
|
||||
USB_LOG_DBG(" signature: 0x%08x\r\n", (unsigned int)csw->dSignature);
|
||||
USB_LOG_DBG(" tag: 0x%08x\r\n", (unsigned int)csw->dTag);
|
||||
@@ -182,14 +184,14 @@ static inline int usbh_msc_scsi_testunitready(struct usbh_msc *msc_class)
|
||||
struct CBW *cbw;
|
||||
|
||||
/* Construct the CBW */
|
||||
cbw = (struct CBW *)g_msc_buf;
|
||||
cbw = (struct CBW *)g_msc_buf[msc_class->sdchar - 'a'];
|
||||
memset(cbw, 0, USB_SIZEOF_MSC_CBW);
|
||||
cbw->dSignature = MSC_CBW_Signature;
|
||||
|
||||
cbw->bCBLength = SCSICMD_TESTUNITREADY_SIZEOF;
|
||||
cbw->CB[0] = SCSI_CMD_TESTUNITREADY;
|
||||
|
||||
return usbh_bulk_cbw_csw_xfer(msc_class, cbw, (struct CSW *)g_msc_buf, NULL, MSC_INQUIRY_TIMEOUT);
|
||||
return usbh_bulk_cbw_csw_xfer(msc_class, cbw, (struct CSW *)g_msc_buf[msc_class->sdchar - 'a'], NULL, MSC_INQUIRY_TIMEOUT);
|
||||
}
|
||||
|
||||
static inline int usbh_msc_scsi_requestsense(struct usbh_msc *msc_class)
|
||||
@@ -197,7 +199,7 @@ static inline int usbh_msc_scsi_requestsense(struct usbh_msc *msc_class)
|
||||
struct CBW *cbw;
|
||||
|
||||
/* Construct the CBW */
|
||||
cbw = (struct CBW *)g_msc_buf;
|
||||
cbw = (struct CBW *)g_msc_buf[msc_class->sdchar - 'a'];
|
||||
memset(cbw, 0, USB_SIZEOF_MSC_CBW);
|
||||
cbw->dSignature = MSC_CBW_Signature;
|
||||
|
||||
@@ -207,7 +209,7 @@ static inline int usbh_msc_scsi_requestsense(struct usbh_msc *msc_class)
|
||||
cbw->CB[0] = SCSI_CMD_REQUESTSENSE;
|
||||
cbw->CB[4] = SCSIRESP_FIXEDSENSEDATA_SIZEOF;
|
||||
|
||||
return usbh_bulk_cbw_csw_xfer(msc_class, cbw, (struct CSW *)g_msc_buf, g_msc_buf, MSC_INQUIRY_TIMEOUT);
|
||||
return usbh_bulk_cbw_csw_xfer(msc_class, cbw, (struct CSW *)g_msc_buf[msc_class->sdchar - 'a'], g_msc_buf[msc_class->sdchar - 'a'], MSC_INQUIRY_TIMEOUT);
|
||||
}
|
||||
|
||||
static inline int usbh_msc_scsi_inquiry(struct usbh_msc *msc_class)
|
||||
@@ -215,7 +217,7 @@ static inline int usbh_msc_scsi_inquiry(struct usbh_msc *msc_class)
|
||||
struct CBW *cbw;
|
||||
|
||||
/* Construct the CBW */
|
||||
cbw = (struct CBW *)g_msc_buf;
|
||||
cbw = (struct CBW *)g_msc_buf[msc_class->sdchar - 'a'];
|
||||
memset(cbw, 0, USB_SIZEOF_MSC_CBW);
|
||||
cbw->dSignature = MSC_CBW_Signature;
|
||||
|
||||
@@ -225,7 +227,7 @@ static inline int usbh_msc_scsi_inquiry(struct usbh_msc *msc_class)
|
||||
cbw->CB[0] = SCSI_CMD_INQUIRY;
|
||||
cbw->CB[4] = SCSIRESP_INQUIRY_SIZEOF;
|
||||
|
||||
return usbh_bulk_cbw_csw_xfer(msc_class, cbw, (struct CSW *)g_msc_buf, g_msc_buf, MSC_INQUIRY_TIMEOUT);
|
||||
return usbh_bulk_cbw_csw_xfer(msc_class, cbw, (struct CSW *)g_msc_buf[msc_class->sdchar - 'a'], g_msc_buf[msc_class->sdchar - 'a'], MSC_INQUIRY_TIMEOUT);
|
||||
}
|
||||
|
||||
static inline int usbh_msc_scsi_readcapacity10(struct usbh_msc *msc_class)
|
||||
@@ -233,7 +235,7 @@ static inline int usbh_msc_scsi_readcapacity10(struct usbh_msc *msc_class)
|
||||
struct CBW *cbw;
|
||||
|
||||
/* Construct the CBW */
|
||||
cbw = (struct CBW *)g_msc_buf;
|
||||
cbw = (struct CBW *)g_msc_buf[msc_class->sdchar - 'a'];
|
||||
memset(cbw, 0, USB_SIZEOF_MSC_CBW);
|
||||
cbw->dSignature = MSC_CBW_Signature;
|
||||
|
||||
@@ -242,7 +244,7 @@ static inline int usbh_msc_scsi_readcapacity10(struct usbh_msc *msc_class)
|
||||
cbw->bCBLength = SCSICMD_READCAPACITY10_SIZEOF;
|
||||
cbw->CB[0] = SCSI_CMD_READCAPACITY10;
|
||||
|
||||
return usbh_bulk_cbw_csw_xfer(msc_class, cbw, (struct CSW *)g_msc_buf, g_msc_buf, MSC_INQUIRY_TIMEOUT);
|
||||
return usbh_bulk_cbw_csw_xfer(msc_class, cbw, (struct CSW *)g_msc_buf[msc_class->sdchar - 'a'], g_msc_buf[msc_class->sdchar - 'a'], MSC_INQUIRY_TIMEOUT);
|
||||
}
|
||||
|
||||
static inline void usbh_msc_modeswitch(struct usbh_msc *msc_class, const uint8_t *message)
|
||||
@@ -250,11 +252,11 @@ static inline void usbh_msc_modeswitch(struct usbh_msc *msc_class, const uint8_t
|
||||
struct CBW *cbw;
|
||||
|
||||
/* Construct the CBW */
|
||||
cbw = (struct CBW *)g_msc_buf;
|
||||
cbw = (struct CBW *)g_msc_buf[msc_class->sdchar - 'a'];
|
||||
|
||||
memcpy(g_msc_buf, message, 31);
|
||||
memcpy(g_msc_buf[msc_class->sdchar - 'a'], message, 31);
|
||||
|
||||
usbh_bulk_cbw_csw_xfer(msc_class, cbw, (struct CSW *)g_msc_buf, NULL, MSC_INQUIRY_TIMEOUT);
|
||||
usbh_bulk_cbw_csw_xfer(msc_class, cbw, (struct CSW *)g_msc_buf[msc_class->sdchar - 'a'], NULL, MSC_INQUIRY_TIMEOUT);
|
||||
}
|
||||
|
||||
static int usbh_msc_connect(struct usbh_hubport *hport, uint8_t intf)
|
||||
@@ -274,12 +276,17 @@ static int usbh_msc_connect(struct usbh_hubport *hport, uint8_t intf)
|
||||
|
||||
hport->config.intf[intf].priv = msc_class;
|
||||
|
||||
ret = usbh_msc_get_maxlun(msc_class, g_msc_buf);
|
||||
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[0] + 1);
|
||||
USB_LOG_INFO("Get max LUN:%u\r\n", g_msc_buf[msc_class->sdchar - 'a'][0] + 1);
|
||||
|
||||
for (uint8_t i = 0; i < hport->config.intf[intf].altsetting[0].intf_desc.bNumEndpoints; i++) {
|
||||
ep_desc = &hport->config.intf[intf].altsetting[0].ep[i].ep_desc;
|
||||
@@ -370,13 +377,12 @@ 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;
|
||||
|
||||
/* Construct the CBW */
|
||||
cbw = (struct CBW *)g_msc_buf;
|
||||
cbw = (struct CBW *)g_msc_buf[msc_class->sdchar - 'a'];
|
||||
memset(cbw, 0, USB_SIZEOF_MSC_CBW);
|
||||
cbw->dSignature = MSC_CBW_Signature;
|
||||
|
||||
@@ -387,7 +393,7 @@ int usbh_msc_scsi_write10(struct usbh_msc *msc_class, uint32_t start_sector, con
|
||||
SET_BE32(&cbw->CB[2], start_sector);
|
||||
SET_BE16(&cbw->CB[7], nsectors);
|
||||
|
||||
return usbh_bulk_cbw_csw_xfer(msc_class, cbw, (struct CSW *)g_msc_buf, (uint8_t *)buffer, CONFIG_USBHOST_MSC_TIMEOUT);
|
||||
return usbh_bulk_cbw_csw_xfer(msc_class, cbw, (struct CSW *)g_msc_buf[msc_class->sdchar - 'a'], (uint8_t *)buffer, CONFIG_USBHOST_MSC_TIMEOUT);
|
||||
}
|
||||
|
||||
int usbh_msc_scsi_read10(struct usbh_msc *msc_class, uint32_t start_sector, const uint8_t *buffer, uint32_t nsectors)
|
||||
@@ -395,7 +401,7 @@ int usbh_msc_scsi_read10(struct usbh_msc *msc_class, uint32_t start_sector, cons
|
||||
struct CBW *cbw;
|
||||
|
||||
/* Construct the CBW */
|
||||
cbw = (struct CBW *)g_msc_buf;
|
||||
cbw = (struct CBW *)g_msc_buf[msc_class->sdchar - 'a'];
|
||||
memset(cbw, 0, USB_SIZEOF_MSC_CBW);
|
||||
cbw->dSignature = MSC_CBW_Signature;
|
||||
|
||||
@@ -407,7 +413,7 @@ int usbh_msc_scsi_read10(struct usbh_msc *msc_class, uint32_t start_sector, cons
|
||||
SET_BE32(&cbw->CB[2], start_sector);
|
||||
SET_BE16(&cbw->CB[7], nsectors);
|
||||
|
||||
return usbh_bulk_cbw_csw_xfer(msc_class, cbw, (struct CSW *)g_msc_buf, (uint8_t *)buffer, CONFIG_USBHOST_MSC_TIMEOUT);
|
||||
return usbh_bulk_cbw_csw_xfer(msc_class, cbw, (struct CSW *)g_msc_buf[msc_class->sdchar - 'a'], (uint8_t *)buffer, CONFIG_USBHOST_MSC_TIMEOUT);
|
||||
}
|
||||
|
||||
void usbh_msc_modeswitch_enable(struct usbh_msc_modeswitch_config *config)
|
||||
@@ -421,10 +427,12 @@ void usbh_msc_modeswitch_enable(struct usbh_msc_modeswitch_config *config)
|
||||
|
||||
__WEAK void usbh_msc_run(struct usbh_msc *msc_class)
|
||||
{
|
||||
(void)msc_class;
|
||||
}
|
||||
|
||||
__WEAK void usbh_msc_stop(struct usbh_msc *msc_class)
|
||||
{
|
||||
(void)msc_class;
|
||||
}
|
||||
|
||||
const struct usbh_class_driver msc_class_driver = {
|
||||
@@ -435,9 +443,9 @@ const struct usbh_class_driver msc_class_driver = {
|
||||
|
||||
CLASS_INFO_DEFINE const struct usbh_class_info msc_class_info = {
|
||||
.match_flags = USB_CLASS_MATCH_INTF_CLASS | USB_CLASS_MATCH_INTF_SUBCLASS | USB_CLASS_MATCH_INTF_PROTOCOL,
|
||||
.class = USB_DEVICE_CLASS_MASS_STORAGE,
|
||||
.subclass = MSC_SUBCLASS_SCSI,
|
||||
.protocol = MSC_PROTOCOL_BULK_ONLY,
|
||||
.bInterfaceClass = USB_DEVICE_CLASS_MASS_STORAGE,
|
||||
.bInterfaceSubClass = MSC_SUBCLASS_SCSI,
|
||||
.bInterfaceProtocol = MSC_PROTOCOL_BULK_ONLY,
|
||||
.id_table = NULL,
|
||||
.class_driver = &msc_class_driver
|
||||
};
|
||||
|
@@ -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));
|
||||
}
|
||||
@@ -89,9 +89,9 @@ static const struct usbh_class_driver xxx_class_driver = {
|
||||
|
||||
CLASS_INFO_DEFINE const struct usbh_class_info xxx_class_info = {
|
||||
.match_flags = USB_CLASS_MATCH_INTF_CLASS | USB_CLASS_MATCH_INTF_SUBCLASS | USB_CLASS_MATCH_INTF_PROTOCOL,
|
||||
.class = 0,
|
||||
.subclass = 0,
|
||||
.protocol = 0,
|
||||
.bInterfaceClass = 0,
|
||||
.bInterfaceSubClass = 0,
|
||||
.bInterfaceProtocol = 0,
|
||||
.id_table = NULL,
|
||||
.class_driver = &xxx_class_driver
|
||||
};
|
||||
|
@@ -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)
|
||||
@@ -680,6 +683,7 @@ void usbh_asix_rx_thread(void *argument)
|
||||
uint32_t transfer_size = (16 * 1024);
|
||||
#endif
|
||||
|
||||
(void)argument;
|
||||
USB_LOG_INFO("Create asix rx thread\r\n");
|
||||
// clang-format off
|
||||
find_class:
|
||||
@@ -742,7 +746,7 @@ find_class:
|
||||
#else
|
||||
if ((g_asix_rx_length + (16 * 1024)) > CONFIG_USBHOST_ASIX_ETH_MAX_RX_SIZE) {
|
||||
#endif
|
||||
USB_LOG_ERR("Rx packet is overflow, please ruduce tcp window size or increase CONFIG_USBHOST_ASIX_ETH_MAX_RX_SIZE\r\n");
|
||||
USB_LOG_ERR("Rx packet is overflow, please reduce tcp window size or increase CONFIG_USBHOST_ASIX_ETH_MAX_RX_SIZE\r\n");
|
||||
while (1) {
|
||||
}
|
||||
}
|
||||
@@ -791,10 +795,12 @@ int usbh_asix_eth_output(uint32_t buflen)
|
||||
|
||||
__WEAK void usbh_asix_run(struct usbh_asix *asix_class)
|
||||
{
|
||||
(void)asix_class;
|
||||
}
|
||||
|
||||
__WEAK void usbh_asix_stop(struct usbh_asix *asix_class)
|
||||
{
|
||||
(void)asix_class;
|
||||
}
|
||||
|
||||
static const uint16_t asix_id_table[][2] = {
|
||||
@@ -811,9 +817,9 @@ static const struct usbh_class_driver asix_class_driver = {
|
||||
|
||||
CLASS_INFO_DEFINE const struct usbh_class_info asix_class_info = {
|
||||
.match_flags = USB_CLASS_MATCH_VID_PID | USB_CLASS_MATCH_INTF_CLASS,
|
||||
.class = 0xff,
|
||||
.subclass = 0x00,
|
||||
.protocol = 0x00,
|
||||
.bInterfaceClass = 0xff,
|
||||
.bInterfaceSubClass = 0x00,
|
||||
.bInterfaceProtocol = 0x00,
|
||||
.id_table = asix_id_table,
|
||||
.class_driver = &asix_class_driver
|
||||
};
|
@@ -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:
|
||||
@@ -2140,6 +2142,7 @@ void usbh_rtl8152_rx_thread(void *argument)
|
||||
uint32_t transfer_size = (16 * 1024);
|
||||
#endif
|
||||
|
||||
(void)argument;
|
||||
USB_LOG_INFO("Create rtl8152 rx thread\r\n");
|
||||
// clang-format off
|
||||
find_class:
|
||||
@@ -2210,7 +2213,7 @@ find_class:
|
||||
#else
|
||||
if ((g_rtl8152_rx_length + (16 * 1024)) > CONFIG_USBHOST_RTL8152_ETH_MAX_RX_SIZE) {
|
||||
#endif
|
||||
USB_LOG_ERR("Rx packet is overflow, please ruduce tcp window size or increase CONFIG_USBHOST_RTL8152_ETH_MAX_RX_SIZE\r\n");
|
||||
USB_LOG_ERR("Rx packet is overflow, please reduce tcp window size or increase CONFIG_USBHOST_RTL8152_ETH_MAX_RX_SIZE\r\n");
|
||||
while (1) {
|
||||
}
|
||||
}
|
||||
@@ -2248,10 +2251,12 @@ int usbh_rtl8152_eth_output(uint32_t buflen)
|
||||
|
||||
__WEAK void usbh_rtl8152_run(struct usbh_rtl8152 *rtl8152_class)
|
||||
{
|
||||
(void)rtl8152_class;
|
||||
}
|
||||
|
||||
__WEAK void usbh_rtl8152_stop(struct usbh_rtl8152 *rtl8152_class)
|
||||
{
|
||||
(void)rtl8152_class;
|
||||
}
|
||||
|
||||
static const uint16_t rtl_id_table[][2] = {
|
||||
@@ -2267,9 +2272,9 @@ static const struct usbh_class_driver rtl8152_class_driver = {
|
||||
|
||||
CLASS_INFO_DEFINE const struct usbh_class_info rtl8152_class_info = {
|
||||
.match_flags = USB_CLASS_MATCH_VID_PID | USB_CLASS_MATCH_INTF_CLASS,
|
||||
.class = 0xff,
|
||||
.subclass = 0x00,
|
||||
.protocol = 0x00,
|
||||
.bInterfaceClass = 0xff,
|
||||
.bInterfaceSubClass = 0x00,
|
||||
.bInterfaceProtocol = 0x00,
|
||||
.id_table = rtl_id_table,
|
||||
.class_driver = &rtl8152_class_driver
|
||||
};
|
||||
|
@@ -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));
|
||||
}
|
||||
@@ -349,10 +349,12 @@ int usbh_ch34x_bulk_out_transfer(struct usbh_ch34x *ch34x_class, uint8_t *buffer
|
||||
|
||||
__WEAK void usbh_ch34x_run(struct usbh_ch34x *ch34x_class)
|
||||
{
|
||||
(void)ch34x_class;
|
||||
}
|
||||
|
||||
__WEAK void usbh_ch34x_stop(struct usbh_ch34x *ch34x_class)
|
||||
{
|
||||
(void)ch34x_class;
|
||||
}
|
||||
|
||||
static const uint16_t ch34x_id_table[][2] = {
|
||||
@@ -368,9 +370,9 @@ const struct usbh_class_driver ch34x_class_driver = {
|
||||
|
||||
CLASS_INFO_DEFINE const struct usbh_class_info ch34x_class_info = {
|
||||
.match_flags = USB_CLASS_MATCH_VID_PID | USB_CLASS_MATCH_INTF_CLASS,
|
||||
.class = 0xff,
|
||||
.subclass = 0x00,
|
||||
.protocol = 0x00,
|
||||
.bInterfaceClass = 0xff,
|
||||
.bInterfaceSubClass = 0x00,
|
||||
.bInterfaceProtocol = 0x00,
|
||||
.id_table = ch34x_id_table,
|
||||
.class_driver = &ch34x_class_driver
|
||||
};
|
@@ -10,18 +10,18 @@
|
||||
|
||||
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_cp210x_buf[64];
|
||||
|
||||
#define CONFIG_USBHOST_MAX_CP210X_CLASS 4
|
||||
#define CONFIG_USBHOST_MAX_CP210X_CLASS 1
|
||||
|
||||
static struct usbh_cp210x g_cp210x_class[CONFIG_USBHOST_MAX_CP210X_CLASS];
|
||||
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));
|
||||
}
|
||||
@@ -298,10 +298,12 @@ int usbh_cp210x_bulk_out_transfer(struct usbh_cp210x *cp210x_class, uint8_t *buf
|
||||
|
||||
__WEAK void usbh_cp210x_run(struct usbh_cp210x *cp210x_class)
|
||||
{
|
||||
(void)cp210x_class;
|
||||
}
|
||||
|
||||
__WEAK void usbh_cp210x_stop(struct usbh_cp210x *cp210x_class)
|
||||
{
|
||||
(void)cp210x_class;
|
||||
}
|
||||
|
||||
static const uint16_t cp210x_id_table[][2] = {
|
||||
@@ -317,9 +319,9 @@ const struct usbh_class_driver cp210x_class_driver = {
|
||||
|
||||
CLASS_INFO_DEFINE const struct usbh_class_info cp210x_class_info = {
|
||||
.match_flags = USB_CLASS_MATCH_VID_PID | USB_CLASS_MATCH_INTF_CLASS,
|
||||
.class = 0xff,
|
||||
.subclass = 0x00,
|
||||
.protocol = 0x00,
|
||||
.bInterfaceClass = 0xff,
|
||||
.bInterfaceSubClass = 0x00,
|
||||
.bInterfaceProtocol = 0x00,
|
||||
.id_table = cp210x_id_table,
|
||||
.class_driver = &cp210x_class_driver
|
||||
};
|
@@ -10,18 +10,18 @@
|
||||
|
||||
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_ftdi_buf[64];
|
||||
|
||||
#define CONFIG_USBHOST_MAX_FTDI_CLASS 4
|
||||
#define CONFIG_USBHOST_MAX_FTDI_CLASS 1
|
||||
|
||||
static struct usbh_ftdi g_ftdi_class[CONFIG_USBHOST_MAX_FTDI_CLASS];
|
||||
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));
|
||||
}
|
||||
@@ -57,7 +57,7 @@ static void usbh_ftdi_caculate_baudrate(uint32_t *itdf_divisor, uint32_t actual_
|
||||
}
|
||||
int divisor = FTDI_USB_CLK / baudrate;
|
||||
int frac_bits = 0;
|
||||
for (int i = 0; i < sizeof(frac) / sizeof(frac[0]); i++) {
|
||||
for (uint8_t i = 0; i < sizeof(frac) / sizeof(frac[0]); i++) {
|
||||
if ((divisor & 0xF) == frac[i]) {
|
||||
frac_bits = i;
|
||||
break;
|
||||
@@ -370,10 +370,12 @@ int usbh_ftdi_bulk_out_transfer(struct usbh_ftdi *ftdi_class, uint8_t *buffer, u
|
||||
|
||||
__WEAK void usbh_ftdi_run(struct usbh_ftdi *ftdi_class)
|
||||
{
|
||||
(void)ftdi_class;
|
||||
}
|
||||
|
||||
__WEAK void usbh_ftdi_stop(struct usbh_ftdi *ftdi_class)
|
||||
{
|
||||
(void)ftdi_class;
|
||||
}
|
||||
|
||||
static const uint16_t ftdi_id_table[][2] = {
|
||||
@@ -390,9 +392,9 @@ const struct usbh_class_driver ftdi_class_driver = {
|
||||
|
||||
CLASS_INFO_DEFINE const struct usbh_class_info ftdi_class_info = {
|
||||
.match_flags = USB_CLASS_MATCH_VID_PID | USB_CLASS_MATCH_INTF_CLASS,
|
||||
.class = 0xff,
|
||||
.subclass = 0x00,
|
||||
.protocol = 0x00,
|
||||
.bInterfaceClass = 0xff,
|
||||
.bInterfaceSubClass = 0x00,
|
||||
.bInterfaceProtocol = 0x00,
|
||||
.id_table = ftdi_id_table,
|
||||
.class_driver = &ftdi_class_driver
|
||||
};
|
@@ -15,7 +15,7 @@
|
||||
|
||||
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_pl2303_buf[64];
|
||||
|
||||
#define CONFIG_USBHOST_MAX_PL2303_CLASS 4
|
||||
#define CONFIG_USBHOST_MAX_PL2303_CLASS 1
|
||||
|
||||
#define UT_WRITE_VENDOR_DEVICE (USB_REQUEST_DIR_OUT | USB_REQUEST_VENDOR | USB_REQUEST_RECIPIENT_DEVICE)
|
||||
#define UT_READ_VENDOR_DEVICE (USB_REQUEST_DIR_IN | USB_REQUEST_VENDOR | USB_REQUEST_RECIPIENT_DEVICE)
|
||||
@@ -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));
|
||||
}
|
||||
@@ -413,10 +413,12 @@ int usbh_pl2303_bulk_out_transfer(struct usbh_pl2303 *pl2303_class, uint8_t *buf
|
||||
|
||||
__WEAK void usbh_pl2303_run(struct usbh_pl2303 *pl2303_class)
|
||||
{
|
||||
(void)pl2303_class;
|
||||
}
|
||||
|
||||
__WEAK void usbh_pl2303_stop(struct usbh_pl2303 *pl2303_class)
|
||||
{
|
||||
(void)pl2303_class;
|
||||
}
|
||||
|
||||
static const uint16_t pl2303_id_table[][2] = {
|
||||
@@ -438,9 +440,9 @@ const struct usbh_class_driver pl2303_class_driver = {
|
||||
|
||||
CLASS_INFO_DEFINE const struct usbh_class_info pl2303_class_info = {
|
||||
.match_flags = USB_CLASS_MATCH_VID_PID | USB_CLASS_MATCH_INTF_CLASS,
|
||||
.class = 0xff,
|
||||
.subclass = 0x00,
|
||||
.protocol = 0x00,
|
||||
.bInterfaceClass = 0xff,
|
||||
.bInterfaceSubClass = 0x00,
|
||||
.bInterfaceProtocol = 0x00,
|
||||
.id_table = pl2303_id_table,
|
||||
.class_driver = &pl2303_class_driver
|
||||
};
|
6
rt-thread/components/drivers/usb/cherryusb/class/vendor/wifi/README.md
vendored
Normal file
6
rt-thread/components/drivers/usb/cherryusb/class/vendor/wifi/README.md
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
# BL616 USB WIFI
|
||||
|
||||
Usbwifi firmware please contact bouffalolab. You can purchase a module in the following ways:
|
||||
|
||||
- https://iot.mi.com/moduleBrowser.html
|
||||
- https://docs.ai-thinker.com/ai_m61
|
512
rt-thread/components/drivers/usb/cherryusb/class/vendor/wifi/usbh_bl616.c
vendored
Normal file
512
rt-thread/components/drivers/usb/cherryusb/class/vendor/wifi/usbh_bl616.c
vendored
Normal file
@@ -0,0 +1,512 @@
|
||||
/*
|
||||
* Copyright (c) 2024, sakumisu
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#include "usbh_core.h"
|
||||
#include "usbh_bl616.h"
|
||||
|
||||
#undef USB_DBG_TAG
|
||||
#define USB_DBG_TAG "usbh_bl616"
|
||||
#include "usb_log.h"
|
||||
|
||||
#define DEV_FORMAT "/dev/wifi/bl616"
|
||||
|
||||
#define MAC_FMT "%02X:%02X:%02X:%02X:%02X:%02X"
|
||||
#define ARR_ELE_6(e) (e)[0], (e)[1], (e)[2], (e)[3], (e)[4], (e)[5]
|
||||
|
||||
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_bl616_tx_buffer[2048 + 512];
|
||||
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_bl616_rx_buffer[2048 + 512];
|
||||
|
||||
static struct usbh_bl616 g_bl616_class;
|
||||
|
||||
static const char *auth_to_str(uint8_t auth)
|
||||
{
|
||||
const char *table[RNM_WIFI_AUTH_MAX] = {
|
||||
[RNM_WIFI_AUTH_UNKNOWN] = "UNKNOWN",
|
||||
[RNM_WIFI_AUTH_OPEN] = "OPEN",
|
||||
[RNM_WIFI_AUTH_WEP] = "WEP",
|
||||
[RNM_WIFI_AUTH_WPA_PSK] = "WPA-PSK",
|
||||
[RNM_WIFI_AUTH_WPA2_PSK] = "WPA2-PSK",
|
||||
[RNM_WIFI_AUTH_WPA_WPA2_PSK] = "WPA2-PSK/WPA-PSK",
|
||||
[RNM_WIFI_AUTH_WPA_ENTERPRISE] = "WPA-ENT",
|
||||
[RNM_WIFI_AUTH_WPA3_SAE] = "WPA3-SAE",
|
||||
[RNM_WIFI_AUTH_WPA2_PSK_WPA3_SAE] = "WPA2-PSK/WPA3-SAE",
|
||||
};
|
||||
if (auth < RNM_WIFI_AUTH_MAX)
|
||||
return table[auth];
|
||||
else
|
||||
return table[RNM_WIFI_AUTH_UNKNOWN];
|
||||
}
|
||||
|
||||
static const char *cipher_to_str(uint8_t cipher)
|
||||
{
|
||||
const char *table[RNM_WIFI_CIPHER_MAX] = {
|
||||
[RNM_WIFI_CIPHER_UNKNOWN] = "UNKNOWN",
|
||||
[RNM_WIFI_CIPHER_NONE] = "NONE",
|
||||
[RNM_WIFI_CIPHER_WEP] = "WEP",
|
||||
[RNM_WIFI_CIPHER_AES] = "AES",
|
||||
[RNM_WIFI_CIPHER_TKIP] = "TKIP",
|
||||
[RNM_WIFI_CIPHER_TKIP_AES] = "TKIP/AES",
|
||||
};
|
||||
if (cipher < RNM_WIFI_CIPHER_MAX)
|
||||
return table[cipher];
|
||||
else
|
||||
return table[RNM_WIFI_CIPHER_UNKNOWN];
|
||||
}
|
||||
|
||||
static int parse_get_mac_rsp_msg(struct usbh_bl616 *bl616_class, void *buf, int buf_len)
|
||||
{
|
||||
usb_data_t *usb_hdr = buf;
|
||||
rnm_mac_addr_ind_msg_t *rsp = buf + sizeof(usb_data_t);
|
||||
|
||||
if (buf_len != sizeof(usb_data_t) + sizeof(rnm_mac_addr_ind_msg_t)) {
|
||||
return -1;
|
||||
}
|
||||
if (usb_hdr->type != USBWIFI_DATA_TYPE_CMD || usb_hdr->length != sizeof(rnm_mac_addr_ind_msg_t)) {
|
||||
return -1;
|
||||
}
|
||||
if (rsp->hdr.cmd != BFLB_CMD_GET_MAC_ADDR || !(rsp->hdr.flags & RNM_MSG_FLAG_ACK)) {
|
||||
return -1;
|
||||
}
|
||||
memcpy(bl616_class->sta_mac, rsp->sta_mac, 6);
|
||||
memcpy(bl616_class->ap_mac, rsp->ap_mac, 6);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int usbh_bl616_bulk_in_transfer(struct usbh_bl616 *bl616_class, uint8_t *buffer, uint32_t buflen, uint32_t timeout)
|
||||
{
|
||||
int ret;
|
||||
struct usbh_urb *urb = &bl616_class->bulkin_urb;
|
||||
|
||||
usbh_bulk_urb_fill(urb, bl616_class->hport, bl616_class->bulkin, buffer, buflen, timeout, NULL, NULL);
|
||||
ret = usbh_submit_urb(urb);
|
||||
if (ret == 0) {
|
||||
ret = urb->actual_length;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int usbh_bl616_bulk_out_transfer(struct usbh_bl616 *bl616_class, uint8_t *buffer, uint32_t buflen, uint32_t timeout)
|
||||
{
|
||||
int ret;
|
||||
struct usbh_urb *urb = &bl616_class->bulkout_urb;
|
||||
|
||||
usbh_bulk_urb_fill(urb, bl616_class->hport, bl616_class->bulkout, buffer, buflen, timeout, NULL, NULL);
|
||||
ret = usbh_submit_urb(urb);
|
||||
if (ret == 0) {
|
||||
ret = urb->actual_length;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int usbh_bl616_get_wifi_mac(struct usbh_bl616 *bl616_class)
|
||||
{
|
||||
int ret;
|
||||
uint32_t msg_len;
|
||||
usb_data_t *usb_hdr = (usb_data_t *)g_bl616_tx_buffer;
|
||||
rnm_base_msg_t *rnm_msg = (rnm_base_msg_t *)(g_bl616_tx_buffer + sizeof(usb_data_t));
|
||||
|
||||
memset(usb_hdr, 0, sizeof(usb_data_t));
|
||||
memset(rnm_msg, 0, sizeof(rnm_base_msg_t));
|
||||
|
||||
usb_hdr->type = USBWIFI_DATA_TYPE_CMD;
|
||||
usb_hdr->length = sizeof(rnm_base_msg_t);
|
||||
usb_hdr->payload_offset = sizeof(usb_data_t);
|
||||
|
||||
rnm_msg->cmd = BFLB_CMD_GET_MAC_ADDR;
|
||||
|
||||
msg_len = sizeof(usb_data_t) + sizeof(rnm_base_msg_t);
|
||||
|
||||
ret = usbh_bl616_bulk_out_transfer(bl616_class, g_bl616_tx_buffer, msg_len, 500);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
ret = usbh_bl616_bulk_in_transfer(bl616_class, g_bl616_rx_buffer, sizeof(g_bl616_rx_buffer), 500);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = parse_get_mac_rsp_msg(bl616_class, g_bl616_rx_buffer, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int usbh_bl616_wifi_open(struct usbh_bl616 *bl616_class)
|
||||
{
|
||||
uint32_t msg_len;
|
||||
usb_data_t *usb_hdr = (usb_data_t *)g_bl616_tx_buffer;
|
||||
rnm_base_msg_t *msg = (rnm_base_msg_t *)(g_bl616_tx_buffer + sizeof(usb_data_t));
|
||||
|
||||
memset(usb_hdr, 0, sizeof(usb_data_t));
|
||||
memset(msg, 0, sizeof(rnm_base_msg_t));
|
||||
|
||||
usb_hdr->type = USBWIFI_DATA_TYPE_CMD;
|
||||
usb_hdr->length = sizeof(rnm_base_msg_t);
|
||||
usb_hdr->payload_offset = sizeof(usb_data_t);
|
||||
|
||||
msg->cmd = BFLB_CMD_HELLO;
|
||||
|
||||
msg_len = sizeof(usb_data_t) + sizeof(rnm_base_msg_t);
|
||||
|
||||
return usbh_bl616_bulk_out_transfer(bl616_class, g_bl616_tx_buffer, msg_len, 500);
|
||||
}
|
||||
|
||||
static int usbh_bl616_wifi_close(struct usbh_bl616 *bl616_class)
|
||||
{
|
||||
uint32_t msg_len;
|
||||
usb_data_t *usb_hdr = (usb_data_t *)g_bl616_tx_buffer;
|
||||
rnm_base_msg_t *msg = (rnm_base_msg_t *)(g_bl616_tx_buffer + sizeof(usb_data_t));
|
||||
|
||||
memset(usb_hdr, 0, sizeof(usb_data_t));
|
||||
memset(msg, 0, sizeof(rnm_base_msg_t));
|
||||
|
||||
usb_hdr->type = USBWIFI_DATA_TYPE_CMD;
|
||||
usb_hdr->length = sizeof(rnm_base_msg_t);
|
||||
usb_hdr->payload_offset = sizeof(usb_data_t);
|
||||
|
||||
msg->cmd = BFLB_CMD_UNLOAD_DRV;
|
||||
|
||||
msg_len = sizeof(usb_data_t) + sizeof(rnm_base_msg_t);
|
||||
|
||||
return usbh_bl616_bulk_out_transfer(bl616_class, g_bl616_tx_buffer, msg_len, 500);
|
||||
}
|
||||
|
||||
int usbh_bl616_wifi_sta_connect(const char *ssid,
|
||||
const int ssid_len,
|
||||
const char *password,
|
||||
const int pwd_len)
|
||||
{
|
||||
uint32_t msg_len;
|
||||
usb_data_t *usb_hdr = (usb_data_t *)g_bl616_tx_buffer;
|
||||
rnm_sta_connect_msg_t *msg = (rnm_sta_connect_msg_t *)(g_bl616_tx_buffer + sizeof(usb_data_t));
|
||||
|
||||
memset(usb_hdr, 0, sizeof(usb_data_t));
|
||||
memset(msg, 0, sizeof(rnm_sta_connect_msg_t));
|
||||
|
||||
usb_hdr->type = USBWIFI_DATA_TYPE_CMD;
|
||||
usb_hdr->length = sizeof(rnm_sta_connect_msg_t);
|
||||
usb_hdr->payload_offset = sizeof(usb_data_t);
|
||||
|
||||
msg->hdr.cmd = BFLB_CMD_STA_CONNECT;
|
||||
msg->hdr.msg_id = 0x0001;
|
||||
msg->hdr.session_id = 0x0002;
|
||||
msg->ssid_len = ssid_len;
|
||||
memcpy(msg->ssid, ssid, ssid_len);
|
||||
if (password) {
|
||||
memcpy(msg->password, password, pwd_len);
|
||||
}
|
||||
|
||||
msg_len = sizeof(usb_data_t) + sizeof(rnm_sta_connect_msg_t);
|
||||
|
||||
return usbh_bl616_bulk_out_transfer(&g_bl616_class, g_bl616_tx_buffer, msg_len, 500);
|
||||
}
|
||||
|
||||
int usbh_bl616_wifi_sta_disconnect(void)
|
||||
{
|
||||
uint32_t msg_len;
|
||||
usb_data_t *usb_hdr = (usb_data_t *)g_bl616_tx_buffer;
|
||||
rnm_base_msg_t *msg = (rnm_base_msg_t *)(g_bl616_tx_buffer + sizeof(usb_data_t));
|
||||
|
||||
memset(usb_hdr, 0, sizeof(usb_data_t));
|
||||
memset(msg, 0, sizeof(rnm_base_msg_t));
|
||||
|
||||
usb_hdr->type = USBWIFI_DATA_TYPE_CMD;
|
||||
usb_hdr->length = sizeof(rnm_base_msg_t);
|
||||
usb_hdr->payload_offset = sizeof(usb_data_t);
|
||||
|
||||
msg->cmd = BFLB_CMD_STA_DISCONNECT;
|
||||
|
||||
msg_len = sizeof(usb_data_t) + sizeof(rnm_base_msg_t);
|
||||
|
||||
return usbh_bl616_bulk_out_transfer(&g_bl616_class, g_bl616_tx_buffer, msg_len, 500);
|
||||
}
|
||||
|
||||
int usbh_bl616_get_wifi_scan_result(void)
|
||||
{
|
||||
uint32_t msg_len;
|
||||
usb_data_t *usb_hdr = (usb_data_t *)g_bl616_tx_buffer;
|
||||
rnm_base_msg_t *msg = (rnm_base_msg_t *)(g_bl616_tx_buffer + sizeof(usb_data_t));
|
||||
|
||||
memset(usb_hdr, 0, sizeof(usb_data_t));
|
||||
memset(msg, 0, sizeof(rnm_base_msg_t));
|
||||
|
||||
usb_hdr->type = USBWIFI_DATA_TYPE_CMD;
|
||||
usb_hdr->length = sizeof(rnm_base_msg_t);
|
||||
usb_hdr->payload_offset = sizeof(usb_data_t);
|
||||
|
||||
msg->cmd = BFLB_CMD_SCAN_RESULTS;
|
||||
|
||||
msg_len = sizeof(usb_data_t) + sizeof(rnm_base_msg_t);
|
||||
|
||||
return usbh_bl616_bulk_out_transfer(&g_bl616_class, g_bl616_tx_buffer, msg_len, 500);
|
||||
}
|
||||
|
||||
int usbh_bl616_wifi_scan(void)
|
||||
{
|
||||
int ret;
|
||||
uint32_t msg_len;
|
||||
usb_data_t *usb_hdr = (usb_data_t *)g_bl616_tx_buffer;
|
||||
rnm_base_msg_t *msg = (rnm_base_msg_t *)(g_bl616_tx_buffer + sizeof(usb_data_t));
|
||||
|
||||
memset(usb_hdr, 0, sizeof(usb_data_t));
|
||||
memset(msg, 0, sizeof(rnm_base_msg_t));
|
||||
|
||||
usb_hdr->type = USBWIFI_DATA_TYPE_CMD;
|
||||
usb_hdr->length = sizeof(rnm_base_msg_t);
|
||||
usb_hdr->payload_offset = sizeof(usb_data_t);
|
||||
|
||||
msg->cmd = BFLB_CMD_SCAN;
|
||||
|
||||
msg_len = sizeof(usb_data_t) + sizeof(rnm_base_msg_t);
|
||||
|
||||
ret = usbh_bl616_bulk_out_transfer(&g_bl616_class, g_bl616_tx_buffer, msg_len, 500);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
usb_osal_msleep(500);
|
||||
return usbh_bl616_get_wifi_scan_result();
|
||||
}
|
||||
|
||||
static int usbh_bl616_connect(struct usbh_hubport *hport, uint8_t intf)
|
||||
{
|
||||
struct usb_endpoint_descriptor *ep_desc;
|
||||
int ret = 0;
|
||||
|
||||
struct usbh_bl616 *bl616_class = &g_bl616_class;
|
||||
|
||||
memset(bl616_class, 0, sizeof(struct usbh_bl616));
|
||||
|
||||
bl616_class->hport = hport;
|
||||
bl616_class->intf = intf;
|
||||
|
||||
hport->config.intf[intf].priv = bl616_class;
|
||||
|
||||
for (uint8_t i = 0; i < hport->config.intf[intf].altsetting[0].intf_desc.bNumEndpoints; i++) {
|
||||
ep_desc = &hport->config.intf[intf].altsetting[0].ep[i].ep_desc;
|
||||
|
||||
if (ep_desc->bEndpointAddress & 0x80) {
|
||||
USBH_EP_INIT(bl616_class->bulkin, ep_desc);
|
||||
} else {
|
||||
USBH_EP_INIT(bl616_class->bulkout, ep_desc);
|
||||
}
|
||||
}
|
||||
|
||||
usbh_bl616_get_wifi_mac(bl616_class);
|
||||
usbh_bl616_wifi_close(bl616_class);
|
||||
usbh_bl616_wifi_open(bl616_class);
|
||||
|
||||
USB_LOG_INFO("BL616 WIFI STA MAC address %02x:%02x:%02x:%02x:%02x:%02x\r\n",
|
||||
bl616_class->sta_mac[0],
|
||||
bl616_class->sta_mac[1],
|
||||
bl616_class->sta_mac[2],
|
||||
bl616_class->sta_mac[3],
|
||||
bl616_class->sta_mac[4],
|
||||
bl616_class->sta_mac[5]);
|
||||
|
||||
USB_LOG_INFO("BL616 WIFI AP MAC address %02x:%02x:%02x:%02x:%02x:%02x\r\n",
|
||||
bl616_class->ap_mac[0],
|
||||
bl616_class->ap_mac[1],
|
||||
bl616_class->ap_mac[2],
|
||||
bl616_class->ap_mac[3],
|
||||
bl616_class->ap_mac[4],
|
||||
bl616_class->ap_mac[5]);
|
||||
|
||||
strncpy(hport->config.intf[intf].devname, DEV_FORMAT, CONFIG_USBHOST_DEV_NAMELEN);
|
||||
|
||||
USB_LOG_INFO("Register BL616 WIFI Class:%s\r\n", hport->config.intf[intf].devname);
|
||||
|
||||
usbh_bl616_run(bl616_class);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int usbh_bl616_disconnect(struct usbh_hubport *hport, uint8_t intf)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
struct usbh_bl616 *bl616_class = (struct usbh_bl616 *)hport->config.intf[intf].priv;
|
||||
|
||||
if (bl616_class) {
|
||||
if (bl616_class->bulkin) {
|
||||
usbh_kill_urb(&bl616_class->bulkin_urb);
|
||||
}
|
||||
|
||||
if (bl616_class->bulkout) {
|
||||
usbh_kill_urb(&bl616_class->bulkout_urb);
|
||||
}
|
||||
|
||||
if (hport->config.intf[intf].devname[0] != '\0') {
|
||||
USB_LOG_INFO("Unregister BL616 WIFI Class:%s\r\n", hport->config.intf[intf].devname);
|
||||
usbh_bl616_stop(bl616_class);
|
||||
}
|
||||
|
||||
memset(bl616_class, 0, sizeof(struct usbh_bl616));
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void usbh_bl616_rx_thread(void *argument)
|
||||
{
|
||||
int ret;
|
||||
usb_data_t *usb_hdr;
|
||||
rnm_base_msg_t *msg;
|
||||
rnm_sta_ip_update_ind_msg_t *ipmsg;
|
||||
rnm_scan_ind_msg_t *scanmsg;
|
||||
uint8_t *data;
|
||||
|
||||
(void)argument;
|
||||
USB_LOG_INFO("Create bl616 wifi rx thread\r\n");
|
||||
|
||||
while (1) {
|
||||
ret = usbh_bl616_bulk_in_transfer(&g_bl616_class, g_bl616_rx_buffer, sizeof(g_bl616_rx_buffer), USB_OSAL_WAITING_FOREVER);
|
||||
if (ret < 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
usb_hdr = (usb_data_t *)g_bl616_rx_buffer;
|
||||
|
||||
if (usb_hdr->type == USBWIFI_DATA_TYPE_CMD) {
|
||||
msg = (rnm_base_msg_t *)(g_bl616_rx_buffer + usb_hdr->payload_offset);
|
||||
|
||||
switch (msg->cmd) {
|
||||
case BFLB_CMD_STA_CONNECTED_IND:
|
||||
USB_LOG_INFO("AP connected\n");
|
||||
g_bl616_class.connect_status = true;
|
||||
usbh_bl616_sta_connect_callback();
|
||||
|
||||
break;
|
||||
case BFLB_CMD_STA_DISCONNECTED_IND:
|
||||
if (g_bl616_class.connect_status == true) {
|
||||
g_bl616_class.connect_status = false;
|
||||
USB_LOG_INFO("AP disconnected\n");
|
||||
usbh_bl616_sta_disconnect_callback();
|
||||
}
|
||||
break;
|
||||
case BFLB_CMD_STA_IP_UPDATE_IND:
|
||||
ipmsg = (rnm_sta_ip_update_ind_msg_t *)(g_bl616_rx_buffer + usb_hdr->payload_offset);
|
||||
|
||||
USB_LOG_INFO("WIFI IP update\r\n");
|
||||
USB_LOG_INFO("WIFI IPv4 Address : %d:%d:%d:%d\r\n",
|
||||
ipmsg->ip4_addr[0],
|
||||
ipmsg->ip4_addr[1],
|
||||
ipmsg->ip4_addr[2],
|
||||
ipmsg->ip4_addr[3]);
|
||||
USB_LOG_INFO("WIFI IPv4 Mask : %d:%d:%d:%d\r\n",
|
||||
ipmsg->ip4_mask[0],
|
||||
ipmsg->ip4_mask[1],
|
||||
ipmsg->ip4_mask[2],
|
||||
ipmsg->ip4_mask[3]);
|
||||
USB_LOG_INFO("WIFI IPv4 Gateway : %d:%d:%d:%d\r\n\r\n",
|
||||
ipmsg->ip4_gw[0],
|
||||
ipmsg->ip4_gw[1],
|
||||
ipmsg->ip4_gw[2],
|
||||
ipmsg->ip4_gw[3]);
|
||||
|
||||
g_bl616_class.mode = BL_MODE_STA;
|
||||
usbh_bl616_sta_update_ip(ipmsg->ip4_addr, ipmsg->ip4_mask, ipmsg->ip4_gw);
|
||||
break;
|
||||
case BFLB_CMD_SCAN_RESULTS:
|
||||
scanmsg = (rnm_scan_ind_msg_t *)(g_bl616_rx_buffer + usb_hdr->payload_offset);
|
||||
USB_LOG_INFO("WIFI scan result:\r\n");
|
||||
for (uint32_t i = 0; i < scanmsg->num; ++i) {
|
||||
struct bf1b_wifi_scan_record *r = &scanmsg->records[i];
|
||||
USB_LOG_INFO("BSSID " MAC_FMT ", channel %u, rssi %d, auth %s, cipher %s, SSID %s\r\n",
|
||||
ARR_ELE_6(r->bssid), r->channel, r->rssi,
|
||||
auth_to_str(r->auth_mode), cipher_to_str(r->cipher), r->ssid);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else if (usb_hdr->type == USBWIFI_DATA_TYPE_PKT) {
|
||||
data = (uint8_t *)(g_bl616_rx_buffer + usb_hdr->payload_offset);
|
||||
usbh_bl616_eth_input(data, usb_hdr->length);
|
||||
} else {
|
||||
}
|
||||
}
|
||||
|
||||
USB_LOG_INFO("Delete bl616 wifi rx thread\r\n");
|
||||
usb_osal_thread_delete(NULL);
|
||||
}
|
||||
|
||||
uint8_t *usbh_bl616_get_eth_txbuf(void)
|
||||
{
|
||||
return (g_bl616_tx_buffer + sizeof(usb_data_t));
|
||||
}
|
||||
|
||||
int usbh_bl616_eth_output(uint32_t buflen)
|
||||
{
|
||||
usb_data_t *usb_hdr;
|
||||
uint32_t txlen;
|
||||
|
||||
if (g_bl616_class.connect_status == false) {
|
||||
return -USB_ERR_NOTCONN;
|
||||
}
|
||||
|
||||
usb_hdr = (usb_data_t *)g_bl616_tx_buffer;
|
||||
memset(usb_hdr, 0, sizeof(usb_data_t));
|
||||
|
||||
usb_hdr->type = USBWIFI_DATA_TYPE_PKT;
|
||||
usb_hdr->length = buflen;
|
||||
usb_hdr->payload_offset = sizeof(usb_data_t);
|
||||
|
||||
txlen = buflen + sizeof(usb_data_t);
|
||||
if (!(txlen % USB_GET_MAXPACKETSIZE(g_bl616_class.bulkout->wMaxPacketSize))) {
|
||||
txlen += 1;
|
||||
}
|
||||
USB_LOG_DBG("txlen:%d\r\n", txlen);
|
||||
|
||||
usbh_bulk_urb_fill(&g_bl616_class.bulkout_urb, g_bl616_class.hport, g_bl616_class.bulkout, g_bl616_tx_buffer, txlen, USB_OSAL_WAITING_FOREVER, NULL, NULL);
|
||||
return usbh_submit_urb(&g_bl616_class.bulkout_urb);
|
||||
}
|
||||
|
||||
int wifi_sta_connect(int argc, char **argv)
|
||||
{
|
||||
if (argc < 3) {
|
||||
USB_LOG_ERR("Usage: %s <ssid> <password>\r\n", argv[0]);
|
||||
return -1;
|
||||
}
|
||||
usbh_bl616_wifi_sta_connect(argv[1], strlen(argv[1]), argv[2], strlen(argv[2]));
|
||||
return 0;
|
||||
}
|
||||
|
||||
int wifi_scan(int argc, char **argv)
|
||||
{
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
|
||||
usbh_bl616_wifi_scan();
|
||||
return 0;
|
||||
}
|
||||
|
||||
__WEAK void usbh_bl616_run(struct usbh_bl616 *bl616_class)
|
||||
{
|
||||
(void)bl616_class;
|
||||
}
|
||||
|
||||
__WEAK void usbh_bl616_stop(struct usbh_bl616 *bl616_class)
|
||||
{
|
||||
(void)bl616_class;
|
||||
}
|
||||
|
||||
static const uint16_t bl616_id_table[][2] = {
|
||||
{ 0x349b, 0x616f },
|
||||
{ 0, 0 },
|
||||
};
|
||||
|
||||
static const struct usbh_class_driver bl616_class_driver = {
|
||||
.driver_name = "bl616_wifi",
|
||||
.connect = usbh_bl616_connect,
|
||||
.disconnect = usbh_bl616_disconnect
|
||||
};
|
||||
|
||||
CLASS_INFO_DEFINE const struct usbh_class_info bl616_class_info = {
|
||||
.match_flags = USB_CLASS_MATCH_VID_PID | USB_CLASS_MATCH_INTF_CLASS,
|
||||
.bInterfaceClass = 0xff,
|
||||
.bInterfaceSubClass = 0x00,
|
||||
.bInterfaceProtocol = 0x00,
|
||||
.id_table = bl616_id_table,
|
||||
.class_driver = &bl616_class_driver
|
||||
};
|
220
rt-thread/components/drivers/usb/cherryusb/class/vendor/wifi/usbh_bl616.h
vendored
Normal file
220
rt-thread/components/drivers/usb/cherryusb/class/vendor/wifi/usbh_bl616.h
vendored
Normal file
@@ -0,0 +1,220 @@
|
||||
/*
|
||||
* Copyright (c) 2024, sakumisu
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#ifndef USBH_BL616_H
|
||||
#define USBH_BL616_H
|
||||
|
||||
#define USBWIFI_DATA_TYPE_CMD 0xA55A
|
||||
#define USBWIFI_DATA_TYPE_PKT 0x6996
|
||||
|
||||
#define USB_DATA_FLAG_AP_PKT (1u << 0)
|
||||
|
||||
typedef enum {
|
||||
BFLB_CMD_REBOOT = 0,
|
||||
BFLB_CMD_RESET,
|
||||
BFLB_CMD_HELLO,
|
||||
BFLB_CMD_PING,
|
||||
|
||||
BFLB_CMD_GET_MAC_ADDR,
|
||||
|
||||
// Scan
|
||||
BFLB_CMD_SCAN,
|
||||
BFLB_CMD_SCAN_RESULTS,
|
||||
|
||||
// STA
|
||||
BFLB_CMD_STA_CONNECT,
|
||||
BFLB_CMD_STA_DISCONNECT,
|
||||
BFLB_CMD_STA_CONNECTED_IND,
|
||||
BFLB_CMD_STA_DISCONNECTED_IND,
|
||||
BFLB_CMD_STA_IP_UPDATE_IND,
|
||||
BFLB_CMD_STA_SET_AUTO_RECONNECT,
|
||||
BFLB_CMD_STA_GET_LINK_STATUS,
|
||||
|
||||
// AP
|
||||
BFLB_CMD_AP_START,
|
||||
BFLB_CMD_AP_STOP,
|
||||
BFLB_CMD_AP_STARTED_IND,
|
||||
BFLB_CMD_AP_STOPPED_IND,
|
||||
BFLB_CMD_AP_GET_STA_LIST,
|
||||
|
||||
// Monitor
|
||||
BFLB_CMD_MONITOR_START,
|
||||
BFLB_CMD_MONITOR_STOP,
|
||||
BFLB_CMD_MONITOR_SET_CHANNEL,
|
||||
BFLB_CMD_MONITOR_GET_CHANNEL,
|
||||
|
||||
BFLB_CMD_SET_LPM_MODE,
|
||||
|
||||
// OTA
|
||||
BFLB_CMD_GET_DEV_VERSION,
|
||||
BFLB_CMD_OTA,
|
||||
|
||||
BFLB_CMD_EXT,
|
||||
|
||||
BFLB_CMD_USER_EXT,
|
||||
BFLB_CMD_UNLOAD_DRV,
|
||||
|
||||
BFLB_CMD_MAX,
|
||||
} bflb_cmd_t;
|
||||
|
||||
typedef enum {
|
||||
STATUS_OK,
|
||||
STATUS_NOMEM = 128,
|
||||
STATUS_INVALID_INPUT,
|
||||
STATUS_INVALID_MODE,
|
||||
STATUS_ERR_UNSPECIFIED,
|
||||
STATUS_NOT_IMPLEMENTED,
|
||||
} cmd_status_t;
|
||||
|
||||
typedef enum {
|
||||
RNM_WIFI_AUTH_UNKNOWN = 0,
|
||||
RNM_WIFI_AUTH_OPEN,
|
||||
RNM_WIFI_AUTH_WEP,
|
||||
RNM_WIFI_AUTH_WPA_PSK,
|
||||
RNM_WIFI_AUTH_WPA2_PSK,
|
||||
RNM_WIFI_AUTH_WPA_WPA2_PSK,
|
||||
RNM_WIFI_AUTH_WPA_ENTERPRISE,
|
||||
RNM_WIFI_AUTH_WPA3_SAE,
|
||||
RNM_WIFI_AUTH_WPA2_PSK_WPA3_SAE,
|
||||
RNM_WIFI_AUTH_MAX,
|
||||
} rnm_wifi_auth_mode_t;
|
||||
|
||||
typedef enum {
|
||||
RNM_WIFI_CIPHER_UNKNOWN = 0,
|
||||
RNM_WIFI_CIPHER_NONE,
|
||||
RNM_WIFI_CIPHER_WEP,
|
||||
RNM_WIFI_CIPHER_AES,
|
||||
RNM_WIFI_CIPHER_TKIP,
|
||||
RNM_WIFI_CIPHER_TKIP_AES,
|
||||
RNM_WIFI_CIPHER_MAX,
|
||||
} rnm_wifi_cipher_t;
|
||||
|
||||
/* common header */
|
||||
typedef struct {
|
||||
uint16_t cmd;
|
||||
// flag ACK is used by server to indicate a response to client
|
||||
#define RNM_MSG_FLAG_ACK (1 << 0)
|
||||
// flag TRANSPARENT is never transfered to peer but used locally
|
||||
#define RNM_MSG_FLAG_TRANSPARENT (1 << 1)
|
||||
// flag ASYNC is used by server to notify client events such as STA_CONNECTED
|
||||
#define RNM_MSG_FLAG_ASYNC (1 << 2)
|
||||
uint16_t flags;
|
||||
uint16_t status;
|
||||
uint16_t msg_id;
|
||||
uint16_t session_id;
|
||||
uint16_t msg_id_replying;
|
||||
} rnm_base_msg_t;
|
||||
|
||||
typedef struct {
|
||||
rnm_base_msg_t hdr;
|
||||
} rnm_ack_msg_t;
|
||||
|
||||
typedef struct {
|
||||
rnm_base_msg_t hdr;
|
||||
uint8_t sta_mac[6];
|
||||
uint8_t ap_mac[6];
|
||||
} rnm_mac_addr_ind_msg_t;
|
||||
|
||||
typedef struct {
|
||||
rnm_base_msg_t hdr;
|
||||
uint16_t ssid_len;
|
||||
uint8_t ssid[32];
|
||||
uint8_t password[64];
|
||||
} rnm_sta_connect_msg_t;
|
||||
|
||||
typedef struct {
|
||||
rnm_base_msg_t hdr;
|
||||
uint8_t ip4_addr[4];
|
||||
uint8_t ip4_mask[4];
|
||||
uint8_t ip4_gw[4];
|
||||
uint8_t ip4_dns1[4];
|
||||
uint8_t ip4_dns2[4];
|
||||
uint8_t gw_mac[6];
|
||||
} rnm_sta_ip_update_ind_msg_t;
|
||||
|
||||
struct bf1b_wifi_scan_record {
|
||||
uint8_t bssid[6];
|
||||
// TODO use compressed SSID encoding to save room
|
||||
uint8_t ssid[32 + 1];
|
||||
uint16_t channel;
|
||||
int8_t rssi;
|
||||
uint8_t auth_mode;
|
||||
uint8_t cipher;
|
||||
} __PACKED;
|
||||
|
||||
typedef struct {
|
||||
rnm_base_msg_t hdr;
|
||||
uint16_t num;
|
||||
struct bf1b_wifi_scan_record records[];
|
||||
} rnm_scan_ind_msg_t;
|
||||
|
||||
typedef enum {
|
||||
BL_MODE_NONE,
|
||||
BL_MODE_STA, // card is STA
|
||||
BL_MODE_AP, // card is AP
|
||||
BL_MODE_STA_AP, // card is STA&AP
|
||||
BL_MODE_SNIFFER, // card is sniffer
|
||||
BL_MODE_MAX,
|
||||
} bl_wifi_mode_t;
|
||||
|
||||
typedef struct {
|
||||
uint16_t type;
|
||||
uint16_t length;
|
||||
uint16_t flags;
|
||||
uint16_t payload_offset;
|
||||
uint32_t rsvd[8];
|
||||
uint8_t payload[];
|
||||
} __attribute__((aligned(4))) usb_data_t;
|
||||
|
||||
struct usbh_bl616 {
|
||||
struct usbh_hubport *hport;
|
||||
struct usb_endpoint_descriptor *bulkin; /* Bulk IN endpoint */
|
||||
struct usb_endpoint_descriptor *bulkout; /* Bulk OUT endpoint */
|
||||
|
||||
struct usbh_urb bulkout_urb;
|
||||
struct usbh_urb bulkin_urb;
|
||||
|
||||
uint8_t intf;
|
||||
|
||||
uint8_t sta_mac[6];
|
||||
uint8_t ap_mac[6];
|
||||
uint8_t mode;
|
||||
bool connect_status;
|
||||
|
||||
void *user_data;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int usbh_bl616_wifi_sta_connect(const char *ssid,
|
||||
const int ssid_len,
|
||||
const char *password,
|
||||
const int pwd_len);
|
||||
|
||||
int usbh_bl616_wifi_sta_disconnect(void);
|
||||
int usbh_bl616_wifi_scan(void);
|
||||
|
||||
void usbh_bl616_sta_connect_callback(void);
|
||||
void usbh_bl616_sta_disconnect_callback(void);
|
||||
void usbh_bl616_sta_update_ip(uint8_t ip4_addr[4], uint8_t ip4_mask[4], uint8_t ip4_gw[4]);
|
||||
|
||||
uint8_t *usbh_bl616_get_eth_txbuf(void);
|
||||
int usbh_bl616_eth_output(uint32_t buflen);
|
||||
void usbh_bl616_eth_input(uint8_t *buf, uint32_t buflen);
|
||||
void usbh_bl616_rx_thread(void *argument);
|
||||
|
||||
void usbh_bl616_run(struct usbh_bl616 *bl616_class);
|
||||
void usbh_bl616_stop(struct usbh_bl616 *bl616_class);
|
||||
|
||||
int wifi_sta_connect(int argc, char **argv);
|
||||
int wifi_scan(int argc, char **argv);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* USBH_BL616_H */
|
228
rt-thread/components/drivers/usb/cherryusb/class/vendor/xbox/usbh_xbox.c
vendored
Normal file
228
rt-thread/components/drivers/usb/cherryusb/class/vendor/xbox/usbh_xbox.c
vendored
Normal file
@@ -0,0 +1,228 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Till Harbaum
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#include "usbh_core.h"
|
||||
#include "usbh_xbox.h"
|
||||
|
||||
#define DEV_FORMAT "/dev/xbox%d"
|
||||
|
||||
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_xbox_buf[128];
|
||||
|
||||
static struct usbh_xbox g_xbox_class[CONFIG_USBHOST_MAX_XBOX_CLASS];
|
||||
static uint32_t g_devinuse = 0;
|
||||
|
||||
static struct usbh_xbox *usbh_xbox_class_alloc(void)
|
||||
{
|
||||
uint8_t devno;
|
||||
|
||||
for (devno = 0; devno < CONFIG_USBHOST_MAX_XBOX_CLASS; 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];
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void usbh_xbox_class_free(struct usbh_xbox *xbox_class)
|
||||
{
|
||||
uint8_t devno = xbox_class->minor;
|
||||
|
||||
if (devno < 32) {
|
||||
g_devinuse &= ~(1U << devno);
|
||||
}
|
||||
memset(xbox_class, 0, sizeof(struct usbh_xbox));
|
||||
}
|
||||
|
||||
int usbh_xbox_connect(struct usbh_hubport *hport, uint8_t intf)
|
||||
{
|
||||
struct usb_endpoint_descriptor *ep_desc;
|
||||
|
||||
struct usbh_xbox *xbox_class = usbh_xbox_class_alloc();
|
||||
if (xbox_class == NULL) {
|
||||
USB_LOG_ERR("Fail to alloc xbox_class\r\n");
|
||||
return -USB_ERR_NOMEM;
|
||||
}
|
||||
|
||||
xbox_class->hport = hport;
|
||||
xbox_class->intf = intf;
|
||||
|
||||
hport->config.intf[intf].priv = xbox_class;
|
||||
|
||||
for (uint8_t i = 0; i < hport->config.intf[intf].altsetting[0].intf_desc.bNumEndpoints; i++) {
|
||||
ep_desc = &hport->config.intf[intf].altsetting[0].ep[i].ep_desc;
|
||||
if (ep_desc->bEndpointAddress & 0x80) {
|
||||
USBH_EP_INIT(xbox_class->intin, ep_desc);
|
||||
} else {
|
||||
USBH_EP_INIT(xbox_class->intout, ep_desc);
|
||||
}
|
||||
}
|
||||
|
||||
snprintf(hport->config.intf[intf].devname, CONFIG_USBHOST_DEV_NAMELEN, DEV_FORMAT, xbox_class->minor);
|
||||
|
||||
USB_LOG_INFO("Register XBOX Class:%s\r\n", hport->config.intf[intf].devname);
|
||||
|
||||
usbh_xbox_run(xbox_class);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbh_xbox_disconnect(struct usbh_hubport *hport, uint8_t intf)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
struct usbh_xbox *xbox_class = (struct usbh_xbox *)hport->config.intf[intf].priv;
|
||||
|
||||
if (xbox_class) {
|
||||
if (xbox_class->intin) {
|
||||
usbh_kill_urb(&xbox_class->intin_urb);
|
||||
}
|
||||
|
||||
if (xbox_class->intout) {
|
||||
usbh_kill_urb(&xbox_class->intout_urb);
|
||||
}
|
||||
|
||||
if (hport->config.intf[intf].devname[0] != '\0') {
|
||||
USB_LOG_INFO("Unregister XBOX Class:%s\r\n", hport->config.intf[intf].devname);
|
||||
usbh_xbox_stop(xbox_class);
|
||||
}
|
||||
|
||||
usbh_xbox_class_free(xbox_class);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
__WEAK void usbh_xbox_run(struct usbh_xbox *xbox_class)
|
||||
{
|
||||
}
|
||||
|
||||
__WEAK void usbh_xbox_stop(struct usbh_xbox *xbox_class)
|
||||
{
|
||||
}
|
||||
|
||||
const struct usbh_class_driver xbox_class_driver = {
|
||||
.driver_name = "xbox",
|
||||
.connect = usbh_xbox_connect,
|
||||
.disconnect = usbh_xbox_disconnect
|
||||
};
|
||||
|
||||
static const uint16_t xbox_id_table[][2] = {
|
||||
{ 0x0079, 0x18d4 }, // GPD Win 2 X-Box Controller
|
||||
{ 0x03eb, 0xff01 }, // Wooting One (Legacy)
|
||||
{ 0x03eb, 0xff02 }, // Wooting Two (Legacy)
|
||||
{ 0x044f, 0xb326 }, // Thrustmaster Gamepad GP XID
|
||||
{ 0x045e, 0x028e }, // Microsoft X-Box 360 pad
|
||||
{ 0x045e, 0x028f }, // Microsoft X-Box 360 pad v2
|
||||
{ 0x046d, 0xc21d }, // Logitech Gamepad F310
|
||||
{ 0x046d, 0xc21e }, // Logitech Gamepad F510
|
||||
{ 0x046d, 0xc21f }, // Logitech Gamepad F710
|
||||
{ 0x046d, 0xc242 }, // Logitech Chillstream Controller
|
||||
{ 0x046d, 0xcaa3 }, // Logitech DriveFx Racing Wheel
|
||||
{ 0x056e, 0x2004 }, // Elecom JC-U3613M
|
||||
{ 0x06a3, 0xf51a }, // Saitek P3600
|
||||
{ 0x0738, 0x4716 }, // Mad Catz Wired Xbox 360 Controller
|
||||
{ 0x0738, 0x4718 }, // Mad Catz Street Fighter IV FightStick SE
|
||||
{ 0x0738, 0x4726 }, // Mad Catz Xbox 360 Controller
|
||||
{ 0x0738, 0x4736 }, // Mad Catz MicroCon Gamepad
|
||||
{ 0x0738, 0x4740 }, // Mad Catz Beat Pad
|
||||
{ 0x0738, 0x9871 }, // Mad Catz Portable Drum
|
||||
{ 0x0738, 0xb726 }, // Mad Catz Xbox controller - MW2
|
||||
{ 0x0738, 0xbeef }, // Mad Catz JOYTECH NEO SE Advanced GamePad
|
||||
{ 0x0738, 0xcb02 }, // Saitek Cyborg Rumble Pad - PC/Xbox 360
|
||||
{ 0x0738, 0xcb03 }, // Saitek P3200 Rumble Pad - PC/Xbox 360
|
||||
{ 0x0738, 0xcb29 }, // Saitek Aviator Stick AV8R02
|
||||
{ 0x0738, 0xf738 }, // Super SFIV FightStick TE S
|
||||
{ 0x07ff, 0xffff }, // Mad Catz GamePad
|
||||
{ 0x0e6f, 0x0113 }, // Afterglow AX.1 Gamepad for Xbox 360
|
||||
{ 0x0e6f, 0x011f }, // Rock Candy Gamepad Wired Controller
|
||||
{ 0x0e6f, 0x0131 }, // PDP EA Sports Controller
|
||||
{ 0x0e6f, 0x0133 }, // Xbox 360 Wired Controller
|
||||
{ 0x0e6f, 0x0201 }, // Pelican PL-3601 'TSZ' Wired Xbox 360 Controller
|
||||
{ 0x0e6f, 0x0213 }, // Afterglow Gamepad for Xbox 360
|
||||
{ 0x0e6f, 0x021f }, // Rock Candy Gamepad for Xbox 360
|
||||
{ 0x0e6f, 0x0301 }, // Logic3 Controller
|
||||
{ 0x0e6f, 0x0401 }, // Logic3 Controller
|
||||
{ 0x0e6f, 0x0413 }, // Afterglow AX.1 Gamepad for Xbox 360
|
||||
{ 0x0e6f, 0x0501 }, // PDP Xbox 360 Controller
|
||||
{ 0x0e6f, 0xf900 }, // PDP Afterglow AX.1
|
||||
{ 0x0f0d, 0x000a }, // Hori Co. DOA4 FightStick
|
||||
{ 0x0f0d, 0x000c }, // Hori PadEX Turbo
|
||||
{ 0x1038, 0x1430 }, // SteelSeries Stratus Duo
|
||||
{ 0x1038, 0x1431 }, // SteelSeries Stratus Duo
|
||||
{ 0x11c9, 0x55f0 }, // Nacon GC-100XF
|
||||
{ 0x1209, 0x2882 }, // Ardwiino Controller
|
||||
{ 0x12ab, 0x0301 }, // PDP AFTERGLOW AX.1
|
||||
{ 0x1430, 0x4748 }, // RedOctane Guitar Hero X-plorer
|
||||
{ 0x1430, 0xf801 }, // RedOctane Controller
|
||||
{ 0x146b, 0x0601 }, // BigBen Interactive XBOX 360 Controller
|
||||
{ 0x1532, 0x0037 }, // Razer Sabertooth
|
||||
{ 0x15e4, 0x3f00 }, // Power A Mini Pro Elite
|
||||
{ 0x15e4, 0x3f0a }, // Xbox Airflo wired controller
|
||||
{ 0x15e4, 0x3f10 }, // Batarang Xbox 360 controller
|
||||
{ 0x162e, 0xbeef }, // Joytech Neo-Se Take2
|
||||
{ 0x1689, 0xfd00 }, // Razer Onza Tournament Edition
|
||||
{ 0x1689, 0xfd01 }, // Razer Onza Classic Edition
|
||||
{ 0x1689, 0xfe00 }, // Razer Sabertooth
|
||||
{ 0x1949, 0x041a }, // Amazon Game Controller
|
||||
{ 0x1bad, 0x0002 }, // Harmonix Rock Band Guitar
|
||||
{ 0x1bad, 0xf016 }, // Mad Catz Xbox 360 Controller
|
||||
{ 0x1bad, 0xf021 }, // Mad Cats Ghost Recon FS GamePad
|
||||
{ 0x1bad, 0xf023 }, // MLG Pro Circuit Controller (Xbox)
|
||||
{ 0x1bad, 0xf025 }, // Mad Catz Call Of Duty
|
||||
{ 0x1bad, 0xf027 }, // Mad Catz FPS Pro
|
||||
{ 0x1bad, 0xf028 }, // Street Fighter IV FightPad
|
||||
{ 0x1bad, 0xf030 }, // Mad Catz Xbox 360 MC2 MicroCon Racing Wheel
|
||||
{ 0x1bad, 0xf036 }, // Mad Catz MicroCon GamePad Pro
|
||||
{ 0x1bad, 0xf038 }, // Street Fighter IV FightStick TE
|
||||
{ 0x1bad, 0xf501 }, // HoriPad EX2 Turbo
|
||||
{ 0x1bad, 0xf506 }, // Hori Real Arcade Pro.EX Premium VLX
|
||||
{ 0x1bad, 0xf900 }, // Harmonix Xbox 360 Controller
|
||||
{ 0x1bad, 0xf901 }, // Gamestop Xbox 360 Controller
|
||||
{ 0x1bad, 0xf903 }, // Tron Xbox 360 controller
|
||||
{ 0x1bad, 0xf904 }, // PDP Versus Fighting Pad
|
||||
{ 0x1bad, 0xfa01 }, // MadCatz GamePad
|
||||
{ 0x1bad, 0xfd00 }, // Razer Onza TE
|
||||
{ 0x1bad, 0xfd01 }, // Razer Onza
|
||||
{ 0x20d6, 0x2001 }, // BDA Xbox Series X Wired Controller
|
||||
{ 0x20d6, 0x281f }, // PowerA Wired Controller For Xbox 360
|
||||
{ 0x24c6, 0x5300 }, // PowerA MINI PROEX Controller
|
||||
{ 0x24c6, 0x5303 }, // Xbox Airflo wired controller
|
||||
{ 0x24c6, 0x530a }, // Xbox 360 Pro EX Controller
|
||||
{ 0x24c6, 0x531a }, // PowerA Pro Ex
|
||||
{ 0x24c6, 0x5397 }, // FUS1ON Tournament Controller
|
||||
{ 0x24c6, 0x5500 }, // Hori XBOX 360 EX 2 with Turbo
|
||||
{ 0x24c6, 0x5501 }, // Hori Real Arcade Pro VX-SA
|
||||
{ 0x24c6, 0x5506 }, // Hori SOULCALIBUR V Stick
|
||||
{ 0x24c6, 0x550d }, // Hori GEM Xbox controller
|
||||
{ 0x24c6, 0x5b00 }, // ThrustMaster Ferrari 458 Racing Wheel
|
||||
{ 0x24c6, 0x5b02 }, // Thrustmaster, Inc. GPX Controller
|
||||
{ 0x24c6, 0x5b03 }, // Thrustmaster Ferrari 458 Racing Wheel
|
||||
{ 0x24c6, 0x5d04 }, // Razer Sabertooth
|
||||
{ 0x24c6, 0xfafe }, // Rock Candy Gamepad for Xbox 360
|
||||
{ 0x2563, 0x058d }, // OneXPlayer Gamepad
|
||||
{ 0x2dc8, 0x3106 }, // 8BitDo Ultimate Wireless / Pro 2 Wired Controller
|
||||
{ 0x2dc8, 0x3109 }, // 8BitDo Ultimate Wireless Bluetooth
|
||||
{ 0x31e3, 0x1100 }, // Wooting One
|
||||
{ 0x31e3, 0x1200 }, // Wooting Two
|
||||
{ 0x31e3, 0x1210 }, // Wooting Lekker
|
||||
{ 0x31e3, 0x1220 }, // Wooting Two HE
|
||||
{ 0x31e3, 0x1230 }, // Wooting Two HE (ARM)
|
||||
{ 0x31e3, 0x1300 }, // Wooting 60HE (AVR)
|
||||
{ 0x31e3, 0x1310 }, // Wooting 60HE (ARM)
|
||||
{ 0x3285, 0x0607 }, // Nacon GC-100
|
||||
{ 0x413d, 0x2104 }, // Black Shark Green Ghost Gamepad
|
||||
{ 0x0000, 0x0000 } // end of list
|
||||
};
|
||||
|
||||
CLASS_INFO_DEFINE const struct usbh_class_info xbox_custom_class_info = {
|
||||
.match_flags = USB_CLASS_MATCH_VID_PID | USB_CLASS_MATCH_INTF_CLASS | USB_CLASS_MATCH_INTF_SUBCLASS | USB_CLASS_MATCH_INTF_PROTOCOL,
|
||||
.bInterfaceClass = USB_DEVICE_CLASS_VEND_SPECIFIC,
|
||||
.bInterfaceSubClass = 0x5d,
|
||||
.bInterfaceProtocol = 0x01,
|
||||
.id_table = xbox_id_table,
|
||||
.class_driver = &xbox_class_driver
|
||||
};
|
31
rt-thread/components/drivers/usb/cherryusb/class/vendor/xbox/usbh_xbox.h
vendored
Normal file
31
rt-thread/components/drivers/usb/cherryusb/class/vendor/xbox/usbh_xbox.h
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright (c) 2024, Till Harbaum
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#ifndef USBH_XBOX_H
|
||||
#define USBH_XBOX_H
|
||||
|
||||
struct usbh_xbox {
|
||||
struct usbh_hubport *hport;
|
||||
struct usb_endpoint_descriptor *intin; /* INTR IN endpoint */
|
||||
struct usb_endpoint_descriptor *intout; /* INTR OUT endpoint */
|
||||
struct usbh_urb intin_urb; /* INTR IN urb */
|
||||
struct usbh_urb intout_urb; /* INTR OUT urb */
|
||||
|
||||
uint8_t intf; /* interface number */
|
||||
uint8_t minor;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void usbh_xbox_run(struct usbh_xbox *xbox_class);
|
||||
void usbh_xbox_stop(struct usbh_xbox *xbox_class);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* USBH_XBOX_H */
|
@@ -18,12 +18,28 @@ struct usbd_video_priv {
|
||||
uint8_t power_mode;
|
||||
uint8_t error_code;
|
||||
struct video_entity_info info[3];
|
||||
uint8_t *ep_buf0;
|
||||
uint8_t *ep_buf1;
|
||||
bool ep_buf0_ready;
|
||||
bool ep_buf1_ready;
|
||||
uint32_t ep_buf0_len;
|
||||
uint32_t ep_buf1_len;
|
||||
uint8_t ep_buf_idx;
|
||||
bool stream_finish;
|
||||
uint32_t max_packets;
|
||||
uint8_t *stream_buf;
|
||||
uint32_t stream_len;
|
||||
uint32_t stream_offset;
|
||||
uint8_t stream_frameid;
|
||||
uint32_t stream_headerlen;
|
||||
} 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)
|
||||
{
|
||||
uint8_t control_selector = (uint8_t)(setup->wValue >> 8);
|
||||
|
||||
(void)busid;
|
||||
|
||||
switch (control_selector) {
|
||||
case VIDEO_VC_VIDEO_POWER_MODE_CONTROL:
|
||||
switch (setup->bRequest) {
|
||||
@@ -669,7 +685,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;
|
||||
@@ -698,7 +714,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;
|
||||
@@ -735,9 +751,47 @@ void usbd_video_probe_and_commit_controls_init(uint8_t busid, uint32_t dwFrameIn
|
||||
g_usbd_video[busid].commit.bPreferedVersion = 0;
|
||||
g_usbd_video[busid].commit.bMinVersion = 0;
|
||||
g_usbd_video[busid].commit.bMaxVersion = 0;
|
||||
|
||||
g_usbd_video[busid].stream_frameid = 0;
|
||||
g_usbd_video[busid].stream_headerlen = 2;
|
||||
}
|
||||
|
||||
struct usbd_interface *usbd_video_init_intf(uint8_t busid, struct usbd_interface *intf,
|
||||
static uint32_t usbd_video_prepare_ep_buf_data(uint8_t busid, uint32_t remain, uint8_t *ep_buf)
|
||||
{
|
||||
struct video_payload_header *header;
|
||||
uint32_t len;
|
||||
uint32_t offset;
|
||||
|
||||
len = MIN(remain, (g_usbd_video[busid].probe.dwMaxPayloadTransferSize - g_usbd_video[busid].stream_headerlen) * g_usbd_video[busid].max_packets);
|
||||
offset = 0;
|
||||
while (len > 0) {
|
||||
header = (struct video_payload_header *)&ep_buf[offset];
|
||||
header->bHeaderLength = g_usbd_video[busid].stream_headerlen;
|
||||
header->headerInfoUnion.bmheaderInfo = 0;
|
||||
header->headerInfoUnion.headerInfoBits.endOfHeader = 1;
|
||||
header->headerInfoUnion.headerInfoBits.endOfFrame = 0;
|
||||
header->headerInfoUnion.headerInfoBits.frameIdentifier = g_usbd_video[busid].stream_frameid;
|
||||
|
||||
uint32_t len2 = MIN(len, g_usbd_video[busid].probe.dwMaxPayloadTransferSize - g_usbd_video[busid].stream_headerlen);
|
||||
|
||||
usb_memcpy(&ep_buf[offset + g_usbd_video[busid].stream_headerlen],
|
||||
&g_usbd_video[busid].stream_buf[g_usbd_video[busid].stream_offset],
|
||||
len2);
|
||||
|
||||
g_usbd_video[busid].stream_offset += len2;
|
||||
len -= len2;
|
||||
offset += (len2 + g_usbd_video[busid].stream_headerlen);
|
||||
|
||||
if (g_usbd_video[busid].stream_offset == g_usbd_video[busid].stream_len) {
|
||||
header->headerInfoUnion.headerInfoBits.endOfFrame = 1;
|
||||
}
|
||||
}
|
||||
|
||||
return offset;
|
||||
}
|
||||
|
||||
struct usbd_interface *usbd_video_init_intf(uint8_t busid,
|
||||
struct usbd_interface *intf,
|
||||
uint32_t dwFrameInterval,
|
||||
uint32_t dwMaxVideoFrameSize,
|
||||
uint32_t dwMaxPayloadTransferSize)
|
||||
@@ -761,28 +815,70 @@ struct usbd_interface *usbd_video_init_intf(uint8_t busid, struct usbd_interface
|
||||
return intf;
|
||||
}
|
||||
|
||||
uint32_t usbd_video_payload_fill(uint8_t busid, uint8_t *input, uint32_t input_len, uint8_t *output, uint32_t *out_len)
|
||||
bool usbd_video_stream_split_transfer(uint8_t busid, uint8_t ep)
|
||||
{
|
||||
uint32_t packets;
|
||||
uint32_t last_packet_size;
|
||||
uint32_t picture_pos = 0;
|
||||
static uint8_t uvc_header[2] = { 0x02, 0x80 };
|
||||
uint32_t remain;
|
||||
|
||||
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++) {
|
||||
output[g_usbd_video[busid].probe.dwMaxPayloadTransferSize * i] = uvc_header[0];
|
||||
output[g_usbd_video[busid].probe.dwMaxPayloadTransferSize * i + 1] = uvc_header[1];
|
||||
if (i == (packets - 1)) {
|
||||
memcpy(&output[2 + g_usbd_video[busid].probe.dwMaxPayloadTransferSize * i], &input[picture_pos], last_packet_size);
|
||||
output[g_usbd_video[busid].probe.dwMaxPayloadTransferSize * i + 1] |= (1 << 1);
|
||||
} else {
|
||||
memcpy(&output[2 + g_usbd_video[busid].probe.dwMaxPayloadTransferSize * i], &input[picture_pos], g_usbd_video[busid].probe.dwMaxPayloadTransferSize - 2);
|
||||
picture_pos += g_usbd_video[busid].probe.dwMaxPayloadTransferSize - 2;
|
||||
if (g_usbd_video[busid].ep_buf1_ready && (g_usbd_video[busid].ep_buf_idx == 0)) { /* callback: buf1 ready and buf0 was sent */
|
||||
g_usbd_video[busid].ep_buf0_ready = false;
|
||||
g_usbd_video[busid].ep_buf_idx = 1;
|
||||
usbd_ep_start_write(busid, ep, g_usbd_video[busid].ep_buf1, g_usbd_video[busid].ep_buf1_len);
|
||||
} else if (g_usbd_video[busid].ep_buf0_ready && (g_usbd_video[busid].ep_buf_idx == 1)) { /* callback: buf0 ready and buf1 was sent */
|
||||
g_usbd_video[busid].ep_buf1_ready = false;
|
||||
g_usbd_video[busid].ep_buf_idx = 0;
|
||||
usbd_ep_start_write(busid, ep, g_usbd_video[busid].ep_buf0, g_usbd_video[busid].ep_buf0_len);
|
||||
} else {
|
||||
if (g_usbd_video[busid].stream_finish) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
uvc_header[1] ^= 1;
|
||||
*out_len = (input_len + 2 * packets);
|
||||
return packets;
|
||||
}
|
||||
|
||||
if (!g_usbd_video[busid].ep_buf0_ready) {
|
||||
remain = g_usbd_video[busid].stream_len - g_usbd_video[busid].stream_offset;
|
||||
if (remain == 0) {
|
||||
g_usbd_video[busid].stream_frameid ^= 1;
|
||||
g_usbd_video[busid].stream_finish = true;
|
||||
} else {
|
||||
g_usbd_video[busid].ep_buf0_len = usbd_video_prepare_ep_buf_data(busid, remain, g_usbd_video[busid].ep_buf0);
|
||||
g_usbd_video[busid].ep_buf0_ready = true;
|
||||
if (!g_usbd_video[busid].ep_buf1_ready) {
|
||||
g_usbd_video[busid].ep_buf_idx = 0;
|
||||
usbd_ep_start_write(busid, ep, g_usbd_video[busid].ep_buf0, g_usbd_video[busid].ep_buf0_len);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!g_usbd_video[busid].ep_buf1_ready) {
|
||||
remain = g_usbd_video[busid].stream_len - g_usbd_video[busid].stream_offset;
|
||||
if (remain == 0) {
|
||||
g_usbd_video[busid].stream_frameid ^= 1;
|
||||
g_usbd_video[busid].stream_finish = true;
|
||||
} else {
|
||||
g_usbd_video[busid].ep_buf1_len = usbd_video_prepare_ep_buf_data(busid, remain, g_usbd_video[busid].ep_buf1);
|
||||
g_usbd_video[busid].ep_buf1_ready = true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
int usbd_video_stream_start_write(uint8_t busid, uint8_t ep, uint8_t *ep_buf0, uint8_t *ep_buf1, uint32_t ep_bufsize, uint8_t *stream_buf, uint32_t stream_len)
|
||||
{
|
||||
if ((usb_device_is_configured(busid) == 0) || (stream_len == 0)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
g_usbd_video[busid].ep_buf0 = ep_buf0;
|
||||
g_usbd_video[busid].ep_buf1 = ep_buf1;
|
||||
g_usbd_video[busid].ep_buf0_ready = false;
|
||||
g_usbd_video[busid].ep_buf1_ready = false;
|
||||
g_usbd_video[busid].ep_buf_idx = 0;
|
||||
g_usbd_video[busid].stream_finish = false;
|
||||
g_usbd_video[busid].max_packets = ep_bufsize / g_usbd_video[busid].probe.dwMaxPayloadTransferSize;
|
||||
g_usbd_video[busid].stream_buf = stream_buf;
|
||||
g_usbd_video[busid].stream_len = stream_len;
|
||||
g_usbd_video[busid].stream_offset = 0;
|
||||
|
||||
usbd_video_stream_split_transfer(busid, ep);
|
||||
return 0;
|
||||
}
|
||||
|
@@ -20,7 +20,9 @@ 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);
|
||||
uint32_t usbd_video_payload_fill(uint8_t busid, uint8_t *input, uint32_t input_len, uint8_t *output, uint32_t *out_len);
|
||||
|
||||
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_buf0, uint8_t *ep_buf1, uint32_t ep_bufsize, uint8_t *stream_buf, uint32_t stream_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));
|
||||
}
|
||||
@@ -495,20 +495,26 @@ static int usbh_video_ctrl_disconnect(struct usbh_hubport *hport, uint8_t intf)
|
||||
|
||||
static int usbh_video_streaming_connect(struct usbh_hubport *hport, uint8_t intf)
|
||||
{
|
||||
(void)hport;
|
||||
(void)intf;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int usbh_video_streaming_disconnect(struct usbh_hubport *hport, uint8_t intf)
|
||||
{
|
||||
(void)hport;
|
||||
(void)intf;
|
||||
return 0;
|
||||
}
|
||||
|
||||
__WEAK void usbh_video_run(struct usbh_video *video_class)
|
||||
{
|
||||
(void)video_class;
|
||||
}
|
||||
|
||||
__WEAK void usbh_video_stop(struct usbh_video *video_class)
|
||||
{
|
||||
(void)video_class;
|
||||
}
|
||||
|
||||
const struct usbh_class_driver video_ctrl_class_driver = {
|
||||
@@ -525,18 +531,18 @@ const struct usbh_class_driver video_streaming_class_driver = {
|
||||
|
||||
CLASS_INFO_DEFINE const struct usbh_class_info video_ctrl_class_info = {
|
||||
.match_flags = USB_CLASS_MATCH_INTF_CLASS | USB_CLASS_MATCH_INTF_SUBCLASS | USB_CLASS_MATCH_INTF_PROTOCOL,
|
||||
.class = USB_DEVICE_CLASS_VIDEO,
|
||||
.subclass = VIDEO_SC_VIDEOCONTROL,
|
||||
.protocol = VIDEO_PC_PROTOCOL_UNDEFINED,
|
||||
.bInterfaceClass = USB_DEVICE_CLASS_VIDEO,
|
||||
.bInterfaceSubClass = VIDEO_SC_VIDEOCONTROL,
|
||||
.bInterfaceProtocol = VIDEO_PC_PROTOCOL_UNDEFINED,
|
||||
.id_table = NULL,
|
||||
.class_driver = &video_ctrl_class_driver
|
||||
};
|
||||
|
||||
CLASS_INFO_DEFINE const struct usbh_class_info video_streaming_class_info = {
|
||||
.match_flags = USB_CLASS_MATCH_INTF_CLASS | USB_CLASS_MATCH_INTF_SUBCLASS | USB_CLASS_MATCH_INTF_PROTOCOL,
|
||||
.class = USB_DEVICE_CLASS_VIDEO,
|
||||
.subclass = VIDEO_SC_VIDEOSTREAMING,
|
||||
.protocol = VIDEO_PC_PROTOCOL_UNDEFINED,
|
||||
.bInterfaceClass = USB_DEVICE_CLASS_VIDEO,
|
||||
.bInterfaceSubClass = VIDEO_SC_VIDEOSTREAMING,
|
||||
.bInterfaceProtocol = VIDEO_PC_PROTOCOL_UNDEFINED,
|
||||
.id_table = NULL,
|
||||
.class_driver = &video_streaming_class_driver
|
||||
};
|
||||
|
@@ -102,6 +102,8 @@ static void rndis_notify_rsp(void)
|
||||
|
||||
static int rndis_class_interface_request_handler(uint8_t busid, struct usb_setup_packet *setup, uint8_t **data, uint32_t *len)
|
||||
{
|
||||
(void)busid;
|
||||
|
||||
switch (setup->bRequest) {
|
||||
case CDC_REQUEST_SEND_ENCAPSULATED_COMMAND:
|
||||
rndis_encapsulated_cmd_handler(*data, setup->wLength);
|
||||
@@ -152,6 +154,8 @@ static int rndis_init_cmd_handler(uint8_t *data, uint32_t len)
|
||||
rndis_initialize_msg_t *cmd = (rndis_initialize_msg_t *)data;
|
||||
rndis_initialize_cmplt_t *resp;
|
||||
|
||||
(void)len;
|
||||
|
||||
resp = ((rndis_initialize_cmplt_t *)rndis_encapsulated_resp_buffer);
|
||||
resp->RequestId = cmd->RequestId;
|
||||
resp->MessageType = REMOTE_NDIS_INITIALIZE_CMPLT;
|
||||
@@ -177,6 +181,9 @@ static int rndis_halt_cmd_handler(uint8_t *data, uint32_t len)
|
||||
{
|
||||
rndis_halt_msg_t *resp;
|
||||
|
||||
(void)data;
|
||||
(void)len;
|
||||
|
||||
resp = ((rndis_halt_msg_t *)rndis_encapsulated_resp_buffer);
|
||||
resp->MessageLength = 0;
|
||||
|
||||
@@ -192,6 +199,8 @@ static int rndis_query_cmd_handler(uint8_t *data, uint32_t len)
|
||||
uint8_t *infomation_buffer;
|
||||
uint32_t infomation_len = 0;
|
||||
|
||||
(void)len;
|
||||
|
||||
resp = ((rndis_query_cmplt_t *)rndis_encapsulated_resp_buffer);
|
||||
resp->MessageType = REMOTE_NDIS_QUERY_CMPLT;
|
||||
resp->RequestId = cmd->RequestId;
|
||||
@@ -338,6 +347,8 @@ static int rndis_set_cmd_handler(uint8_t *data, uint32_t len)
|
||||
rndis_set_cmplt_t *resp;
|
||||
rndis_config_parameter_t *param;
|
||||
|
||||
(void)len;
|
||||
|
||||
resp = ((rndis_set_cmplt_t *)rndis_encapsulated_resp_buffer);
|
||||
resp->RequestId = cmd->RequestId;
|
||||
resp->MessageType = REMOTE_NDIS_SET_CMPLT;
|
||||
@@ -394,6 +405,9 @@ static int rndis_reset_cmd_handler(uint8_t *data, uint32_t len)
|
||||
// rndis_reset_msg_t *cmd = (rndis_reset_msg_t *)data;
|
||||
rndis_reset_cmplt_t *resp;
|
||||
|
||||
(void)data;
|
||||
(void)len;
|
||||
|
||||
resp = ((rndis_reset_cmplt_t *)rndis_encapsulated_resp_buffer);
|
||||
resp->MessageType = REMOTE_NDIS_RESET_CMPLT;
|
||||
resp->MessageLength = sizeof(rndis_reset_cmplt_t);
|
||||
@@ -412,6 +426,8 @@ static int rndis_keepalive_cmd_handler(uint8_t *data, uint32_t len)
|
||||
rndis_keepalive_msg_t *cmd = (rndis_keepalive_msg_t *)data;
|
||||
rndis_keepalive_cmplt_t *resp;
|
||||
|
||||
(void)len;
|
||||
|
||||
resp = ((rndis_keepalive_cmplt_t *)rndis_encapsulated_resp_buffer);
|
||||
resp->RequestId = cmd->RequestId;
|
||||
resp->MessageType = REMOTE_NDIS_KEEPALIVE_CMPLT;
|
||||
@@ -425,6 +441,9 @@ static int rndis_keepalive_cmd_handler(uint8_t *data, uint32_t len)
|
||||
|
||||
static void rndis_notify_handler(uint8_t busid, uint8_t event, void *arg)
|
||||
{
|
||||
(void)busid;
|
||||
(void)arg;
|
||||
|
||||
switch (event) {
|
||||
case USBD_EVENT_RESET:
|
||||
g_usbd_rndis.link_status = NDIS_MEDIA_STATE_DISCONNECTED;
|
||||
@@ -445,6 +464,9 @@ void rndis_bulk_out(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
{
|
||||
rndis_data_packet_t *hdr;
|
||||
|
||||
(void)busid;
|
||||
(void)ep;
|
||||
|
||||
hdr = (rndis_data_packet_t *)g_rndis_rx_buffer;
|
||||
g_rndis_rx_data_buffer = g_rndis_rx_buffer;
|
||||
if ((hdr->MessageType != REMOTE_NDIS_PACKET_MSG) || (nbytes < hdr->MessageLength)) {
|
||||
@@ -456,21 +478,28 @@ void rndis_bulk_out(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
g_rndis_rx_data_buffer += hdr->DataOffset + sizeof(rndis_generic_msg_t);
|
||||
g_rndis_rx_data_length = hdr->DataLength;
|
||||
|
||||
usbd_rndis_data_recv_done();
|
||||
usbd_rndis_data_recv_done(g_rndis_rx_data_length);
|
||||
}
|
||||
|
||||
void rndis_bulk_in(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
{
|
||||
if ((nbytes % usbd_get_ep_mps(busid, ep)) == 0 && nbytes) {
|
||||
(void)busid;
|
||||
|
||||
if ((nbytes % usbd_get_ep_mps(0, ep)) == 0 && nbytes) {
|
||||
/* send zlp */
|
||||
usbd_ep_start_write(0, ep, NULL, 0);
|
||||
} else {
|
||||
usbd_rndis_data_send_done(g_rndis_tx_data_length);
|
||||
g_rndis_tx_data_length = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void rndis_int_in(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
{
|
||||
(void)busid;
|
||||
(void)ep;
|
||||
(void)nbytes;
|
||||
|
||||
//USB_LOG_DBG("len:%d\r\n", nbytes);
|
||||
}
|
||||
|
||||
@@ -564,3 +593,13 @@ struct usbd_interface *usbd_rndis_init_intf(struct usbd_interface *intf,
|
||||
|
||||
return intf;
|
||||
}
|
||||
|
||||
__WEAK void usbd_rndis_data_recv_done(uint32_t len)
|
||||
{
|
||||
(void)len;
|
||||
}
|
||||
|
||||
__WEAK void usbd_rndis_data_send_done(uint32_t len)
|
||||
{
|
||||
(void)len;
|
||||
}
|
@@ -18,7 +18,8 @@ struct usbd_interface *usbd_rndis_init_intf(struct usbd_interface *intf,
|
||||
const uint8_t in_ep,
|
||||
const uint8_t int_ep, uint8_t mac[6]);
|
||||
|
||||
void usbd_rndis_data_recv_done(void);
|
||||
void usbd_rndis_data_recv_done(uint32_t len);
|
||||
void usbd_rndis_data_send_done(uint32_t len);
|
||||
|
||||
#ifdef CONFIG_USBDEV_RNDIS_USING_LWIP
|
||||
struct pbuf *usbd_rndis_eth_rx(void);
|
||||
|
@@ -365,14 +365,18 @@ delete :
|
||||
|
||||
__WEAK void usbh_bluetooth_hci_read_callback(uint8_t *data, uint32_t len)
|
||||
{
|
||||
(void)data;
|
||||
(void)len;
|
||||
}
|
||||
|
||||
__WEAK void usbh_bluetooth_run(struct usbh_bluetooth *bluetooth_class)
|
||||
{
|
||||
(void)bluetooth_class;
|
||||
}
|
||||
|
||||
__WEAK void usbh_bluetooth_stop(struct usbh_bluetooth *bluetooth_class)
|
||||
{
|
||||
(void)bluetooth_class;
|
||||
}
|
||||
|
||||
static const struct usbh_class_driver bluetooth_class_driver = {
|
||||
@@ -389,18 +393,18 @@ static const uint16_t bluetooth_id_table[][2] = {
|
||||
|
||||
CLASS_INFO_DEFINE const struct usbh_class_info bluetooth_h4_nrf_class_info = {
|
||||
.match_flags = USB_CLASS_MATCH_VID_PID | USB_CLASS_MATCH_INTF_CLASS,
|
||||
.class = 0xff,
|
||||
.subclass = 0x00,
|
||||
.protocol = 0x00,
|
||||
.bInterfaceClass = 0xff,
|
||||
.bInterfaceSubClass = 0x00,
|
||||
.bInterfaceProtocol = 0x00,
|
||||
.id_table = bluetooth_id_table,
|
||||
.class_driver = &bluetooth_class_driver
|
||||
};
|
||||
#else
|
||||
CLASS_INFO_DEFINE const struct usbh_class_info bluetooth_class_info = {
|
||||
.match_flags = USB_CLASS_MATCH_INTF_CLASS | USB_CLASS_MATCH_INTF_SUBCLASS | USB_CLASS_MATCH_INTF_PROTOCOL,
|
||||
.class = USB_DEVICE_CLASS_WIRELESS,
|
||||
.subclass = 0x01,
|
||||
.protocol = 0x01,
|
||||
.bInterfaceClass = USB_DEVICE_CLASS_WIRELESS,
|
||||
.bInterfaceSubClass = 0x01,
|
||||
.bInterfaceProtocol = 0x01,
|
||||
.id_table = NULL,
|
||||
.class_driver = &bluetooth_class_driver
|
||||
};
|
||||
|
@@ -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)
|
||||
@@ -26,6 +26,7 @@ static struct usbh_rndis g_rndis_class;
|
||||
|
||||
static int usbh_rndis_get_notification(struct usbh_rndis *rndis_class)
|
||||
{
|
||||
(void)rndis_class;
|
||||
// int ret;
|
||||
// struct usbh_urb *urb = &rndis_class->intin_urb;
|
||||
|
||||
@@ -79,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) {
|
||||
@@ -137,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) {
|
||||
@@ -194,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) {
|
||||
@@ -261,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) {
|
||||
@@ -386,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;
|
||||
}
|
||||
@@ -460,6 +461,8 @@ void usbh_rndis_rx_thread(void *argument)
|
||||
uint32_t transfer_size = (16 * 1024);
|
||||
#endif
|
||||
|
||||
(void)argument;
|
||||
|
||||
USB_LOG_INFO("Create rndis rx thread\r\n");
|
||||
// clang-format off
|
||||
find_class:
|
||||
@@ -531,7 +534,7 @@ find_class:
|
||||
#else
|
||||
if ((g_rndis_rx_length + (16 * 1024)) > CONFIG_USBHOST_RNDIS_ETH_MAX_RX_SIZE) {
|
||||
#endif
|
||||
USB_LOG_ERR("Rx packet is overflow, please ruduce tcp window size or increase CONFIG_USBHOST_RNDIS_ETH_MAX_RX_SIZE\r\n");
|
||||
USB_LOG_ERR("Rx packet is overflow, please reduce tcp window size or increase CONFIG_USBHOST_RNDIS_ETH_MAX_RX_SIZE\r\n");
|
||||
while (1) {
|
||||
}
|
||||
}
|
||||
@@ -581,10 +584,12 @@ int usbh_rndis_eth_output(uint32_t buflen)
|
||||
|
||||
__WEAK void usbh_rndis_run(struct usbh_rndis *rndis_class)
|
||||
{
|
||||
(void)rndis_class;
|
||||
}
|
||||
|
||||
__WEAK void usbh_rndis_stop(struct usbh_rndis *rndis_class)
|
||||
{
|
||||
(void)rndis_class;
|
||||
}
|
||||
|
||||
static const struct usbh_class_driver rndis_class_driver = {
|
||||
@@ -595,9 +600,9 @@ static const struct usbh_class_driver rndis_class_driver = {
|
||||
|
||||
CLASS_INFO_DEFINE const struct usbh_class_info rndis_class_info = {
|
||||
.match_flags = USB_CLASS_MATCH_INTF_CLASS | USB_CLASS_MATCH_INTF_SUBCLASS | USB_CLASS_MATCH_INTF_PROTOCOL,
|
||||
.class = USB_DEVICE_CLASS_WIRELESS,
|
||||
.subclass = 0x01,
|
||||
.protocol = 0x03,
|
||||
.bInterfaceClass = USB_DEVICE_CLASS_WIRELESS,
|
||||
.bInterfaceSubClass = 0x01,
|
||||
.bInterfaceProtocol = 0x03,
|
||||
.id_table = NULL,
|
||||
.class_driver = &rndis_class_driver
|
||||
};
|
||||
|
Reference in New Issue
Block a user