Skip to content

Commit f27486e

Browse files
committed
add tuh_hid_itf_get_info() and change tuh_cdc_itf_get_info() to use new tuh_itf_info_t
1 parent f8a5cde commit f27486e

File tree

8 files changed

+58
-24
lines changed

8 files changed

+58
-24
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/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
}

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);

src/class/hid/hid_host.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,29 @@ bool tuh_hid_mounted(uint8_t daddr, uint8_t idx)
134134
return p_hid != NULL;
135135
}
136136

137+
bool tuh_hid_itf_get_info(uint8_t daddr, uint8_t idx, tuh_itf_info_t* info)
138+
{
139+
hidh_interface_t* p_hid = get_hid_itf(daddr, idx);
140+
TU_VERIFY(p_hid && info);
141+
142+
info->daddr = daddr;
143+
144+
// re-construct descriptor
145+
tusb_desc_interface_t* desc = &info->desc;
146+
desc->bLength = sizeof(tusb_desc_interface_t);
147+
desc->bDescriptorType = TUSB_DESC_INTERFACE;
148+
149+
desc->bInterfaceNumber = p_hid->itf_num;
150+
desc->bAlternateSetting = 0;
151+
desc->bNumEndpoints = (uint8_t) ((p_hid->ep_in ? 1u : 0u) + (p_hid->ep_out ? 1u : 0u));
152+
desc->bInterfaceClass = TUSB_CLASS_HID;
153+
desc->bInterfaceSubClass = (p_hid->itf_protocol ? HID_SUBCLASS_BOOT : HID_SUBCLASS_NONE);
154+
desc->bInterfaceProtocol = p_hid->itf_protocol;
155+
desc->iInterface = 0; // not used yet
156+
157+
return true;
158+
}
159+
137160
uint8_t tuh_hid_itf_get_index(uint8_t daddr, uint8_t itf_num)
138161
{
139162
for ( uint8_t idx = 0; idx < CFG_TUH_HID; idx++ )

src/class/hid/hid_host.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ uint8_t tuh_hid_itf_get_total_count(void);
7171
// backward compatible rename
7272
#define tuh_hid_instance_count tuh_hid_itf_get_count
7373

74-
// Check if HID interface is mounted
75-
bool tuh_hid_mounted(uint8_t dev_addr, uint8_t idx);
74+
// Get Interface information
75+
bool tuh_hid_itf_get_info(uint8_t daddr, uint8_t idx, tuh_itf_info_t* itf_info);
7676

7777
// Get Interface index from device address + interface number
7878
// return TUSB_INDEX_INVALID_8 (0xFF) if not found
@@ -81,6 +81,9 @@ uint8_t tuh_hid_itf_get_index(uint8_t daddr, uint8_t itf_num);
8181
// Get interface supported protocol (bInterfaceProtocol) check out hid_interface_protocol_enum_t for possible values
8282
uint8_t tuh_hid_interface_protocol(uint8_t dev_addr, uint8_t idx);
8383

84+
// Check if HID interface is mounted
85+
bool tuh_hid_mounted(uint8_t dev_addr, uint8_t idx);
86+
8487
// Parse report descriptor into array of report_info struct and return number of reports.
8588
// For complicated report, application should write its own parser.
8689
uint8_t tuh_hid_parse_report_descriptor(tuh_hid_report_info_t* reports_info_arr, uint8_t arr_count, uint8_t const* desc_report, uint16_t desc_len) TU_ATTR_UNUSED;

tools/build_family.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ def build_family(example, family, make_option):
3434
# sum all element of same index (column sum)
3535
return list(map(sum, list(zip(*result))))
3636

37-
3837
if __name__ == '__main__':
3938
# IAR CC
4039
if make_iar_option not in sys.argv:
@@ -68,7 +67,8 @@ def build_family(example, family, make_option):
6867
print(build_separator)
6968
for family in all_families:
7069
fret = build_family(example, family, make_iar_option)
71-
total_result = list(map(lambda x, y: x + y, total_result, fret))
70+
if len(fret) == len(total_result):
71+
total_result = [total_result[i] + fret[i] for i in range(len(fret))]
7272

7373
total_time = time.monotonic() - total_time
7474
print(build_separator)

tools/get_deps.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,13 @@ def get_a_dep(d):
105105

106106
if __name__ == "__main__":
107107
status = 0
108-
deps = list(deps_mandatory.keys()) + sys.argv[1:]
108+
deps = list(deps_mandatory.keys())
109+
# get all if executed with all as argument
110+
if len(sys.argv) == 2 and sys.argv[1] == 'all':
111+
deps += deps_optional
112+
else:
113+
deps += sys.argv[1:]
114+
109115
with Pool() as pool:
110116
status = sum(pool.map(get_a_dep, deps))
111117
sys.exit(status)

0 commit comments

Comments
 (0)