summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorScott Shawcroft <[email protected]>2022-03-10 11:01:44 -0800
committerScott Shawcroft <[email protected]>2022-03-10 11:01:44 -0800
commit37960990a5fb0a42a5faa19230f0051efaa4e6c0 (patch)
tree0124ae9107e8de40e226577545ef9289628136cd /examples
parent22f682c37879a38aa662c2205d411b2246d0639c (diff)
Print speed. Don't crash if string get fails
Diffstat (limited to 'examples')
-rw-r--r--examples/host/device_info/src/main.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/examples/host/device_info/src/main.c b/examples/host/device_info/src/main.c
index 45b616af0..e6149db89 100644
--- a/examples/host/device_info/src/main.c
+++ b/examples/host/device_info/src/main.c
@@ -90,6 +90,10 @@ static void _wait_and_convert(uint16_t *temp_buf, size_t buf_len) {
while (_get_string_result == 0xff) {
tuh_task();
}
+ if (_get_string_result != XFER_RESULT_SUCCESS) {
+ temp_buf[0] = 0;
+ return;
+ }
size_t utf16_len = ((temp_buf[0] & 0xff) - 2) / sizeof(uint16_t);
size_t utf8_len = _count_utf8_bytes(temp_buf + 1, utf16_len);
_convert_utf16le_to_utf8(temp_buf + 1, utf16_len, (uint8_t *) temp_buf, sizeof(uint16_t) * buf_len);
@@ -128,6 +132,21 @@ int main(void)
tuh_vid_pid_get(i, &vid, &pid);
printf("%d vid %04x pid %04x\r\n", i, vid, pid);
+ tusb_speed_t speed = tuh_speed_get(i);
+ switch (speed) {
+ case TUSB_SPEED_FULL:
+ printf("Full speed\r\n");
+ break;
+ case TUSB_SPEED_LOW:
+ printf("Low speed\r\n");
+ break;
+ case TUSB_SPEED_HIGH:
+ printf("High speed\r\n");
+ break;
+ default:
+ break;
+ }
+
_get_string_result = 0xff;
uint16_t temp_buf[127];
if (tuh_descriptor_string_serial_get(i, 0, temp_buf, TU_ARRAY_SIZE(temp_buf), _transfer_done_cb)) {