Skip to content

Commit 07976ad

Browse files
authored
Merge pull request hathach#1968 from hathach/refactor-hid-host
Refactor hid host
2 parents ec9c666 + f27486e commit 07976ad

File tree

16 files changed

+326
-223
lines changed

16 files changed

+326
-223
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ repos:
1515
rev: v2.2.4
1616
hooks:
1717
- id: codespell
18-
#args: [-w]
18+
args: [-w]
1919
exclude: ^lib/
2020

2121
- repo: local

examples/dual/host_hid_to_device_cdc/src/tusb_config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@
132132
// max device support (excluding hub device)
133133
#define CFG_TUH_DEVICE_MAX (CFG_TUH_HUB ? 4 : 1) // hub typically has 4 ports
134134

135-
#define CFG_TUH_HID 4
135+
#define CFG_TUH_HID (3*CFG_TUH_DEVICE_MAX)
136136
#define CFG_TUH_HID_EPIN_BUFSIZE 64
137137
#define CFG_TUH_HID_EPOUT_BUFSIZE 64
138138

examples/host/cdc_msc_hid/src/cdc_app.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,10 @@ void tuh_cdc_rx_cb(uint8_t idx)
8787

8888
void tuh_cdc_mount_cb(uint8_t idx)
8989
{
90-
tuh_cdc_itf_info_t itf_info = { 0 };
90+
tuh_itf_info_t itf_info = { 0 };
9191
tuh_cdc_itf_get_info(idx, &itf_info);
9292

93-
printf("CDC Interface is mounted: address = %u, itf_num = %u\r\n", itf_info.daddr, itf_info.bInterfaceNumber);
93+
printf("CDC Interface is mounted: address = %u, itf_num = %u\r\n", itf_info.daddr, itf_info.desc.bInterfaceNumber);
9494

9595
#ifdef CFG_TUH_CDC_LINE_CODING_ON_ENUM
9696
// CFG_TUH_CDC_LINE_CODING_ON_ENUM must be defined for line coding is set by tinyusb in enumeration
@@ -106,8 +106,8 @@ void tuh_cdc_mount_cb(uint8_t idx)
106106

107107
void tuh_cdc_umount_cb(uint8_t idx)
108108
{
109-
tuh_cdc_itf_info_t itf_info = { 0 };
109+
tuh_itf_info_t itf_info = { 0 };
110110
tuh_cdc_itf_get_info(idx, &itf_info);
111111

112-
printf("CDC Interface is unmounted: address = %u, itf_num = %u\r\n", itf_info.daddr, itf_info.bInterfaceNumber);
112+
printf("CDC Interface is unmounted: address = %u, itf_num = %u\r\n", itf_info.daddr, itf_info.desc.bInterfaceNumber);
113113
}

examples/host/cdc_msc_hid/src/tusb_config.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
#if CFG_TUSB_MCU == OPT_MCU_RP2040
3838
// change to 1 if using pico-pio-usb as host controller for raspberry rp2040
39-
#define CFG_TUH_RPI_PIO_USB 0
39+
#define CFG_TUH_RPI_PIO_USB 1
4040
#define BOARD_TUH_RHPORT CFG_TUH_RPI_PIO_USB
4141
#endif
4242

@@ -97,7 +97,7 @@
9797

9898
#define CFG_TUH_HUB 1 // number of supported hubs
9999
#define CFG_TUH_CDC 1
100-
#define CFG_TUH_HID 4 // typical keyboard + mouse device can have 3-4 HID interfaces
100+
#define CFG_TUH_HID (3*CFG_TUH_DEVICE_MAX) // typical keyboard + mouse device can have 3-4 HID interfaces
101101
#define CFG_TUH_MSC 1
102102
#define CFG_TUH_VENDOR 0
103103

examples/host/hid_controller/src/tusb_config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797

9898
#define CFG_TUH_HUB 0
9999
#define CFG_TUH_CDC 0
100-
#define CFG_TUH_HID 4 // typical keyboard + mouse device can have 3-4 HID interfaces
100+
#define CFG_TUH_HID (3*CFG_TUH_DEVICE_MAX) // typical keyboard + mouse device can have 3-4 HID interfaces
101101
#define CFG_TUH_MSC 0
102102
#define CFG_TUH_VENDOR 0
103103

src/class/cdc/cdc_host.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,15 +127,25 @@ uint8_t tuh_cdc_itf_get_index(uint8_t daddr, uint8_t itf_num)
127127
return TUSB_INDEX_INVALID_8;
128128
}
129129

130-
bool tuh_cdc_itf_get_info(uint8_t idx, tuh_cdc_itf_info_t* info)
130+
bool tuh_cdc_itf_get_info(uint8_t idx, tuh_itf_info_t* info)
131131
{
132132
cdch_interface_t* p_cdc = get_itf(idx);
133133
TU_VERIFY(p_cdc && info);
134134

135-
info->daddr = p_cdc->daddr;
136-
info->bInterfaceNumber = p_cdc->bInterfaceNumber;
137-
info->bInterfaceSubClass = p_cdc->bInterfaceSubClass;
138-
info->bInterfaceProtocol = p_cdc->bInterfaceProtocol;
135+
info->daddr = p_cdc->daddr;
136+
137+
// re-construct descriptor
138+
tusb_desc_interface_t* desc = &info->desc;
139+
desc->bLength = sizeof(tusb_desc_interface_t);
140+
desc->bDescriptorType = TUSB_DESC_INTERFACE;
141+
142+
desc->bInterfaceNumber = p_cdc->bInterfaceNumber;
143+
desc->bAlternateSetting = 0;
144+
desc->bNumEndpoints = 2u + (p_cdc->ep_notif ? 1u : 0u);
145+
desc->bInterfaceClass = TUSB_CLASS_CDC;
146+
desc->bInterfaceSubClass = p_cdc->bInterfaceSubClass;
147+
desc->bInterfaceProtocol = p_cdc->bInterfaceProtocol;
148+
desc->iInterface = 0; // not used yet
139149

140150
return true;
141151
}

src/class/cdc/cdc_host.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,21 +71,13 @@
7171
// Application API
7272
//--------------------------------------------------------------------+
7373

74-
typedef struct
75-
{
76-
uint8_t daddr;
77-
uint8_t bInterfaceNumber;
78-
uint8_t bInterfaceSubClass;
79-
uint8_t bInterfaceProtocol;
80-
} tuh_cdc_itf_info_t;
81-
8274
// Get Interface index from device address + interface number
8375
// return TUSB_INDEX_INVALID_8 (0xFF) if not found
8476
uint8_t tuh_cdc_itf_get_index(uint8_t daddr, uint8_t itf_num);
8577

8678
// Get Interface information
8779
// return true if index is correct and interface is currently mounted
88-
bool tuh_cdc_itf_get_info(uint8_t idx, tuh_cdc_itf_info_t* info);
80+
bool tuh_cdc_itf_get_info(uint8_t idx, tuh_itf_info_t* info);
8981

9082
// Check if a interface is mounted
9183
bool tuh_cdc_mounted(uint8_t idx);

0 commit comments

Comments
 (0)