summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhathach <[email protected]>2023-03-22 10:00:42 +0700
committerhathach <[email protected]>2023-03-22 10:00:42 +0700
commitf27486e19abcc020c93c0c938c71e3692c21b9f5 (patch)
tree2433c472d79e252020613b2c3b2c3d756d28ae90
parentf8a5cde3c7fde62c3d6bd379fea6eaa9a629ded6 (diff)
add tuh_hid_itf_get_info() and change tuh_cdc_itf_get_info() to use new tuh_itf_info_t
-rw-r--r--.pre-commit-config.yaml2
-rw-r--r--examples/host/cdc_msc_hid/src/cdc_app.c8
-rw-r--r--src/class/cdc/cdc_host.c20
-rw-r--r--src/class/cdc/cdc_host.h10
-rw-r--r--src/class/hid/hid_host.c23
-rw-r--r--src/class/hid/hid_host.h7
-rw-r--r--tools/build_family.py4
-rw-r--r--tools/get_deps.py8
8 files changed, 58 insertions, 24 deletions
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 7fa6f52ee..d37c27d40 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -15,7 +15,7 @@ repos:
rev: v2.2.4
hooks:
- id: codespell
- #args: [-w]
+ args: [-w]
exclude: ^lib/
- repo: local
diff --git a/examples/host/cdc_msc_hid/src/cdc_app.c b/examples/host/cdc_msc_hid/src/cdc_app.c
index b1b137e0e..7769d109e 100644
--- a/examples/host/cdc_msc_hid/src/cdc_app.c
+++ b/examples/host/cdc_msc_hid/src/cdc_app.c
@@ -87,10 +87,10 @@ void tuh_cdc_rx_cb(uint8_t idx)
void tuh_cdc_mount_cb(uint8_t idx)
{
- tuh_cdc_itf_info_t itf_info = { 0 };
+ tuh_itf_info_t itf_info = { 0 };
tuh_cdc_itf_get_info(idx, &itf_info);
- printf("CDC Interface is mounted: address = %u, itf_num = %u\r\n", itf_info.daddr, itf_info.bInterfaceNumber);
+ printf("CDC Interface is mounted: address = %u, itf_num = %u\r\n", itf_info.daddr, itf_info.desc.bInterfaceNumber);
#ifdef CFG_TUH_CDC_LINE_CODING_ON_ENUM
// 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)
void tuh_cdc_umount_cb(uint8_t idx)
{
- tuh_cdc_itf_info_t itf_info = { 0 };
+ tuh_itf_info_t itf_info = { 0 };
tuh_cdc_itf_get_info(idx, &itf_info);
- printf("CDC Interface is unmounted: address = %u, itf_num = %u\r\n", itf_info.daddr, itf_info.bInterfaceNumber);
+ printf("CDC Interface is unmounted: address = %u, itf_num = %u\r\n", itf_info.daddr, itf_info.desc.bInterfaceNumber);
}
diff --git a/src/class/cdc/cdc_host.c b/src/class/cdc/cdc_host.c
index d34662cb7..fee314823 100644
--- a/src/class/cdc/cdc_host.c
+++ b/src/class/cdc/cdc_host.c
@@ -127,15 +127,25 @@ uint8_t tuh_cdc_itf_get_index(uint8_t daddr, uint8_t itf_num)
return TUSB_INDEX_INVALID_8;
}
-bool tuh_cdc_itf_get_info(uint8_t idx, tuh_cdc_itf_info_t* info)
+bool tuh_cdc_itf_get_info(uint8_t idx, tuh_itf_info_t* info)
{
cdch_interface_t* p_cdc = get_itf(idx);
TU_VERIFY(p_cdc && info);
- info->daddr = p_cdc->daddr;
- info->bInterfaceNumber = p_cdc->bInterfaceNumber;
- info->bInterfaceSubClass = p_cdc->bInterfaceSubClass;
- info->bInterfaceProtocol = p_cdc->bInterfaceProtocol;
+ info->daddr = p_cdc->daddr;
+
+ // re-construct descriptor
+ tusb_desc_interface_t* desc = &info->desc;
+ desc->bLength = sizeof(tusb_desc_interface_t);
+ desc->bDescriptorType = TUSB_DESC_INTERFACE;
+
+ desc->bInterfaceNumber = p_cdc->bInterfaceNumber;
+ desc->bAlternateSetting = 0;
+ desc->bNumEndpoints = 2u + (p_cdc->ep_notif ? 1u : 0u);
+ desc->bInterfaceClass = TUSB_CLASS_CDC;
+ desc->bInterfaceSubClass = p_cdc->bInterfaceSubClass;
+ desc->bInterfaceProtocol = p_cdc->bInterfaceProtocol;
+ desc->iInterface = 0; // not used yet
return true;
}
diff --git a/src/class/cdc/cdc_host.h b/src/class/cdc/cdc_host.h
index 03f32e542..a1e78f158 100644
--- a/src/class/cdc/cdc_host.h
+++ b/src/class/cdc/cdc_host.h
@@ -71,21 +71,13 @@
// Application API
//--------------------------------------------------------------------+
-typedef struct
-{
- uint8_t daddr;
- uint8_t bInterfaceNumber;
- uint8_t bInterfaceSubClass;
- uint8_t bInterfaceProtocol;
-} tuh_cdc_itf_info_t;
-
// Get Interface index from device address + interface number
// return TUSB_INDEX_INVALID_8 (0xFF) if not found
uint8_t tuh_cdc_itf_get_index(uint8_t daddr, uint8_t itf_num);
// Get Interface information
// return true if index is correct and interface is currently mounted
-bool tuh_cdc_itf_get_info(uint8_t idx, tuh_cdc_itf_info_t* info);
+bool tuh_cdc_itf_get_info(uint8_t idx, tuh_itf_info_t* info);
// Check if a interface is mounted
bool tuh_cdc_mounted(uint8_t idx);
diff --git a/src/class/hid/hid_host.c b/src/class/hid/hid_host.c
index f65b2dc20..20373f541 100644
--- a/src/class/hid/hid_host.c
+++ b/src/class/hid/hid_host.c
@@ -134,6 +134,29 @@ bool tuh_hid_mounted(uint8_t daddr, uint8_t idx)
return p_hid != NULL;
}
+bool tuh_hid_itf_get_info(uint8_t daddr, uint8_t idx, tuh_itf_info_t* info)
+{
+ hidh_interface_t* p_hid = get_hid_itf(daddr, idx);
+ TU_VERIFY(p_hid && info);
+
+ info->daddr = daddr;
+
+ // re-construct descriptor
+ tusb_desc_interface_t* desc = &info->desc;
+ desc->bLength = sizeof(tusb_desc_interface_t);
+ desc->bDescriptorType = TUSB_DESC_INTERFACE;
+
+ desc->bInterfaceNumber = p_hid->itf_num;
+ desc->bAlternateSetting = 0;
+ desc->bNumEndpoints = (uint8_t) ((p_hid->ep_in ? 1u : 0u) + (p_hid->ep_out ? 1u : 0u));
+ desc->bInterfaceClass = TUSB_CLASS_HID;
+ desc->bInterfaceSubClass = (p_hid->itf_protocol ? HID_SUBCLASS_BOOT : HID_SUBCLASS_NONE);
+ desc->bInterfaceProtocol = p_hid->itf_protocol;
+ desc->iInterface = 0; // not used yet
+
+ return true;
+}
+
uint8_t tuh_hid_itf_get_index(uint8_t daddr, uint8_t itf_num)
{
for ( uint8_t idx = 0; idx < CFG_TUH_HID; idx++ )
diff --git a/src/class/hid/hid_host.h b/src/class/hid/hid_host.h
index f808f36d4..c0c727e6a 100644
--- a/src/class/hid/hid_host.h
+++ b/src/class/hid/hid_host.h
@@ -71,8 +71,8 @@ uint8_t tuh_hid_itf_get_total_count(void);
// backward compatible rename
#define tuh_hid_instance_count tuh_hid_itf_get_count
-// Check if HID interface is mounted
-bool tuh_hid_mounted(uint8_t dev_addr, uint8_t idx);
+// Get Interface information
+bool tuh_hid_itf_get_info(uint8_t daddr, uint8_t idx, tuh_itf_info_t* itf_info);
// Get Interface index from device address + interface number
// 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);
// Get interface supported protocol (bInterfaceProtocol) check out hid_interface_protocol_enum_t for possible values
uint8_t tuh_hid_interface_protocol(uint8_t dev_addr, uint8_t idx);
+// Check if HID interface is mounted
+bool tuh_hid_mounted(uint8_t dev_addr, uint8_t idx);
+
// Parse report descriptor into array of report_info struct and return number of reports.
// For complicated report, application should write its own parser.
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;
diff --git a/tools/build_family.py b/tools/build_family.py
index cdc099691..532938d42 100644
--- a/tools/build_family.py
+++ b/tools/build_family.py
@@ -34,7 +34,6 @@ def build_family(example, family, make_option):
# sum all element of same index (column sum)
return list(map(sum, list(zip(*result))))
-
if __name__ == '__main__':
# IAR CC
if make_iar_option not in sys.argv:
@@ -68,7 +67,8 @@ if __name__ == '__main__':
print(build_separator)
for family in all_families:
fret = build_family(example, family, make_iar_option)
- total_result = list(map(lambda x, y: x + y, total_result, fret))
+ if len(fret) == len(total_result):
+ total_result = [total_result[i] + fret[i] for i in range(len(fret))]
total_time = time.monotonic() - total_time
print(build_separator)
diff --git a/tools/get_deps.py b/tools/get_deps.py
index 8bf56cd8d..4b81d1468 100644
--- a/tools/get_deps.py
+++ b/tools/get_deps.py
@@ -105,7 +105,13 @@ def get_a_dep(d):
if __name__ == "__main__":
status = 0
- deps = list(deps_mandatory.keys()) + sys.argv[1:]
+ deps = list(deps_mandatory.keys())
+ # get all if executed with all as argument
+ if len(sys.argv) == 2 and sys.argv[1] == 'all':
+ deps += deps_optional
+ else:
+ deps += sys.argv[1:]
+
with Pool() as pool:
status = sum(pool.map(get_a_dep, deps))
sys.exit(status)