From 4436209213fa31037d76e793e8cd970d7996e872 Mon Sep 17 00:00:00 2001 From: Dean Netherton Date: Sun, 27 Apr 2025 11:50:14 +1000 Subject: [PATCH] ch376-native: fixed issue with parsing configs containing HID configs (keyboards/mice) --- Source/HBIOS/Config/RCEZ80_std.asm | 2 +- .../HBIOS/ch376-native/base-drv/enumerate.c.s | 621 +++++++++++------- .../source-doc/base-drv/enumerate.c | 57 +- .../source-doc/base-drv/protocol.h | 16 + .../source-doc/base-drv/transfers.c | 2 +- 5 files changed, 443 insertions(+), 255 deletions(-) diff --git a/Source/HBIOS/Config/RCEZ80_std.asm b/Source/HBIOS/Config/RCEZ80_std.asm index 8a66a69e..8743b2b0 100644 --- a/Source/HBIOS/Config/RCEZ80_std.asm +++ b/Source/HBIOS/Config/RCEZ80_std.asm @@ -89,7 +89,7 @@ CH1USBENABLE .SET FALSE ; CH376: ENABLE CH376 USB DRIVER CHNATIVEENABLE .SET TRUE ; CH376: ENABLE CH376 NATIVE USB DRIVER CHSCSIENABLE .SET TRUE ; CH376: ENABLE CH376 NATIVE MASS STORAGE DEVICES (REQUIRES CHNATIVEENABLE) CHUFIENABLE .SET TRUE ; CH376: ENABLE CH376 NATIVE UFI FLOPPY DISK DEVICES (REQUIRES CHNATIVEENABLE) -CHNATIVEEZ80 .SET TRUE ; CH376: DELEGATE USB DRIVERS TO EZ80'S FIRMWARE +CHNATIVEEZ80 .SET FALSE ; CH376: DELEGATE USB DRIVERS TO EZ80'S FIRMWARE CHNATIVEFORCE .SET TRUE ; CH376: DISABLE AUTO-DETECTION OF MODULE - ASSUME ITS INSTALLED EZ80TIMER .SET EZ80TMR_INT ; EZ80: TIMER TICK MODEL: EZ80TMR_[INT|FIRM] diff --git a/Source/HBIOS/ch376-native/base-drv/enumerate.c.s b/Source/HBIOS/ch376-native/base-drv/enumerate.c.s index 68f236e6..450eece3 100644 --- a/Source/HBIOS/ch376-native/base-drv/enumerate.c.s +++ b/Source/HBIOS/ch376-native/base-drv/enumerate.c.s @@ -48,7 +48,111 @@ _USB_MODULE_LEDS .EQU 0xff8a ;-------------------------------------------------------- ; code ;-------------------------------------------------------- -;source-doc/base-drv/enumerate.c:13: void parse_endpoint_keyboard(device_config_keyboard *const keyboard_config, const endpoint_descriptor const *pEndpoint) +;source-doc/base-drv/enumerate.c:13: static usb_error adv_to_next_desc(_working *const working, const uint8_t descriptor_type) __sdcccall(1) { +; --------------------------------- +; Function adv_to_next_desc +; --------------------------------- +_adv_to_next_desc: + push ix + ld ix,0 + add ix,sp + push af + push af + ex de, hl +;source-doc/base-drv/enumerate.c:15: const uint8_t *buffer_end = working->config.buffer + MAX_CONFIG_SIZE; + ld hl,0x00ab + add hl, de + ex (sp), hl +;source-doc/base-drv/enumerate.c:17: if (working->ptr >= buffer_end) + ld hl,0x001b + add hl, de + ld (ix-2),l + ld (ix-1),h + pop de + pop hl + ld a,(hl) + push hl + push de + inc hl + ld b,(hl) + ld c,a + sub (ix-4) + ld a, b + sbc a,(ix-3) + jr C,l_adv_to_next_desc_00102 +;source-doc/base-drv/enumerate.c:18: return USB_ERR_BUFF_TO_LARGE; + ld a,0x84 + jr l_adv_to_next_desc_00110 +l_adv_to_next_desc_00102: +;source-doc/base-drv/enumerate.c:20: d = (usb_descriptor_t *)working->ptr; + ld e, c + ld d, b +;source-doc/base-drv/enumerate.c:22: do { +l_adv_to_next_desc_00105: +;source-doc/base-drv/enumerate.c:23: working->ptr += d->bLength; + ld a, (de) + add a, c + ld c, a + ld a,0x00 + adc a, b + ld b, a + ld l,(ix-2) + ld h,(ix-1) + ld (hl), c + inc hl + ld (hl), b +;source-doc/base-drv/enumerate.c:25: if (working->ptr >= buffer_end) + ld a, c + sub (ix-4) + ld a, b + sbc a,(ix-3) + jr C,l_adv_to_next_desc_00104 +;source-doc/base-drv/enumerate.c:26: return USB_ERR_BUFF_TO_LARGE; + ld a,0x84 + jr l_adv_to_next_desc_00110 +l_adv_to_next_desc_00104: +;source-doc/base-drv/enumerate.c:17: if (working->ptr >= buffer_end) + pop de + pop hl + ld c,(hl) + push hl + push de + inc hl + ld b, (hl) +;source-doc/base-drv/enumerate.c:28: d = (usb_descriptor_t *)working->ptr; + ld e, c + ld d, b +;source-doc/base-drv/enumerate.c:29: } while (d->bDescriptorType != descriptor_type); + ld l, e + ld h, d + inc hl + ld a, (hl) + sub (ix+4) + jr NZ,l_adv_to_next_desc_00105 +;source-doc/base-drv/enumerate.c:31: if (working->ptr + d->bLength >= buffer_end) + ld a, (de) + ld l, a + ld h,0x00 + add hl, bc + ld a, l + sub (ix-4) + ld a, h + sbc a,(ix-3) + jr C,l_adv_to_next_desc_00109 +;source-doc/base-drv/enumerate.c:32: return USB_ERR_BUFF_TO_LARGE; + ld a,0x84 + jr l_adv_to_next_desc_00110 +l_adv_to_next_desc_00109: +;source-doc/base-drv/enumerate.c:34: return USB_ERR_OK; + xor a +l_adv_to_next_desc_00110: +;source-doc/base-drv/enumerate.c:35: } + ld sp, ix + pop ix + pop hl + inc sp + jp (hl) +;source-doc/base-drv/enumerate.c:37: void parse_endpoint_keyboard(device_config_keyboard *const keyboard_config, const endpoint_descriptor const *pEndpoint) ; --------------------------------- ; Function parse_endpoint_keyboard ; --------------------------------- @@ -57,11 +161,11 @@ _parse_endpoint_keyboard: ld ix,0 add ix,sp push af -;source-doc/base-drv/enumerate.c:15: endpoint_param *const ep = &keyboard_config->endpoints[0]; +;source-doc/base-drv/enumerate.c:39: endpoint_param *const ep = &keyboard_config->endpoints[0]; inc hl inc hl inc hl -;source-doc/base-drv/enumerate.c:16: ep->number = pEndpoint->bEndpointAddress; +;source-doc/base-drv/enumerate.c:40: ep->number = pEndpoint->bEndpointAddress; ld c,l ld b,h ex (sp),hl @@ -80,12 +184,12 @@ _parse_endpoint_keyboard: and 0xf1 or c ld (hl), a -;source-doc/base-drv/enumerate.c:17: ep->toggle = 0; +;source-doc/base-drv/enumerate.c:41: ep->toggle = 0; pop hl ld c,l ld b,h res 0, (hl) -;source-doc/base-drv/enumerate.c:18: ep->max_packet_sizex = calc_max_packet_sizex(pEndpoint->wMaxPacketSize); +;source-doc/base-drv/enumerate.c:42: ep->max_packet_sizex = calc_max_packet_sizex(pEndpoint->wMaxPacketSize); inc bc ld hl,4 add hl, de @@ -104,11 +208,11 @@ _parse_endpoint_keyboard: and 0xfc or l ld (bc), a -;source-doc/base-drv/enumerate.c:19: } +;source-doc/base-drv/enumerate.c:43: } ld sp, ix pop ix ret -;source-doc/base-drv/enumerate.c:21: usb_device_type identify_class_driver(_working *const working) { +;source-doc/base-drv/enumerate.c:45: usb_device_type identify_class_driver(_working *const working) { ; --------------------------------- ; Function identify_class_driver ; --------------------------------- @@ -116,7 +220,7 @@ _identify_class_driver: push ix ld ix,0 add ix,sp -;source-doc/base-drv/enumerate.c:22: const interface_descriptor *const p = (const interface_descriptor *)working->ptr; +;source-doc/base-drv/enumerate.c:46: const interface_descriptor *const p = (const interface_descriptor *)working->ptr; ld c,(ix+4) ld b,(ix+5) ld hl,27 @@ -124,18 +228,18 @@ _identify_class_driver: ld c, (hl) inc hl ld b, (hl) -;source-doc/base-drv/enumerate.c:23: if (p->bInterfaceClass == 2) +;source-doc/base-drv/enumerate.c:47: if (p->bInterfaceClass == 2) ld hl,5 add hl,bc ld a,(hl) ld e,a sub 0x02 jr NZ,l_identify_class_driver_00102 -;source-doc/base-drv/enumerate.c:24: return USB_IS_CDC; +;source-doc/base-drv/enumerate.c:48: return USB_IS_CDC; ld l,0x03 jr l_identify_class_driver_00118 l_identify_class_driver_00102: -;source-doc/base-drv/enumerate.c:26: if (p->bInterfaceClass == 8 && (p->bInterfaceSubClass == 6 || p->bInterfaceSubClass == 5) && p->bInterfaceProtocol == 80) +;source-doc/base-drv/enumerate.c:50: if (p->bInterfaceClass == 8 && (p->bInterfaceSubClass == 6 || p->bInterfaceSubClass == 5) && p->bInterfaceProtocol == 80) ld a, e sub 0x08 jr NZ,l_identify_class_driver_00199 @@ -160,11 +264,11 @@ l_identify_class_driver_00107: ld a, (hl) sub 0x50 jr NZ,l_identify_class_driver_00104 -;source-doc/base-drv/enumerate.c:27: return USB_IS_MASS_STORAGE; +;source-doc/base-drv/enumerate.c:51: return USB_IS_MASS_STORAGE; ld l,0x02 jr l_identify_class_driver_00118 l_identify_class_driver_00104: -;source-doc/base-drv/enumerate.c:29: if (p->bInterfaceClass == 8 && p->bInterfaceSubClass == 4 && p->bInterfaceProtocol == 0) +;source-doc/base-drv/enumerate.c:53: if (p->bInterfaceClass == 8 && p->bInterfaceSubClass == 4 && p->bInterfaceProtocol == 0) ld a, d or a jr Z,l_identify_class_driver_00109 @@ -178,11 +282,11 @@ l_identify_class_driver_00104: ld a, (hl) or a jr NZ,l_identify_class_driver_00109 -;source-doc/base-drv/enumerate.c:30: return USB_IS_FLOPPY; +;source-doc/base-drv/enumerate.c:54: return USB_IS_FLOPPY; ld l,0x01 jr l_identify_class_driver_00118 l_identify_class_driver_00109: -;source-doc/base-drv/enumerate.c:32: if (p->bInterfaceClass == 9 && p->bInterfaceSubClass == 0 && p->bInterfaceProtocol == 0) +;source-doc/base-drv/enumerate.c:56: if (p->bInterfaceClass == 9 && p->bInterfaceSubClass == 0 && p->bInterfaceProtocol == 0) ld a, e sub 0x09 jr NZ,l_identify_class_driver_00113 @@ -196,93 +300,107 @@ l_identify_class_driver_00109: ld a, (hl) or a jr NZ,l_identify_class_driver_00113 -;source-doc/base-drv/enumerate.c:33: return USB_IS_HUB; +;source-doc/base-drv/enumerate.c:57: return USB_IS_HUB; ld l,0x0f jr l_identify_class_driver_00118 l_identify_class_driver_00113: -;source-doc/base-drv/enumerate.c:35: if (p->bInterfaceClass == 3) +;source-doc/base-drv/enumerate.c:59: if (p->bInterfaceClass == 3) ld a, e sub 0x03 jr NZ,l_identify_class_driver_00117 -;source-doc/base-drv/enumerate.c:36: return USB_IS_KEYBOARD; +;source-doc/base-drv/enumerate.c:60: return USB_IS_KEYBOARD; ld l,0x04 jr l_identify_class_driver_00118 l_identify_class_driver_00117: -;source-doc/base-drv/enumerate.c:38: return USB_IS_UNKNOWN; +;source-doc/base-drv/enumerate.c:62: return USB_IS_UNKNOWN; ld l,0x06 l_identify_class_driver_00118: -;source-doc/base-drv/enumerate.c:39: } +;source-doc/base-drv/enumerate.c:63: } pop ix ret -;source-doc/base-drv/enumerate.c:41: usb_error op_interface_next(_working *const working) __z88dk_fastcall { +;source-doc/base-drv/enumerate.c:65: usb_error op_interface_next(_working *const working) __z88dk_fastcall { ; --------------------------------- ; Function op_interface_next ; --------------------------------- _op_interface_next: ex de, hl -;source-doc/base-drv/enumerate.c:42: if (--working->interface_count == 0) +;source-doc/base-drv/enumerate.c:68: if (--working->interface_count == 0) ld hl,0x0016 add hl, de ld a, (hl) dec a ld (hl), a -;source-doc/base-drv/enumerate.c:43: return USB_ERR_OK; +;source-doc/base-drv/enumerate.c:69: return USB_ERR_OK; or a jr NZ,l_op_interface_next_00102 ld l,a - jr l_op_interface_next_00103 + jr l_op_interface_next_00106 l_op_interface_next_00102: -;source-doc/base-drv/enumerate.c:45: return op_id_class_drv(working); +;source-doc/base-drv/enumerate.c:71: CHECK(adv_to_next_desc(working, USB_DESCR_INTERFACE)); + push de + ld a,0x04 + push af + inc sp + ex de,hl + call _adv_to_next_desc + pop de + ld l, a + or a + ret NZ +;source-doc/base-drv/enumerate.c:72: return op_id_class_drv(working); ex de, hl call _op_id_class_drv ld l, a -l_op_interface_next_00103: -;source-doc/base-drv/enumerate.c:46: } +;source-doc/base-drv/enumerate.c:74: done: +;source-doc/base-drv/enumerate.c:75: return result; +l_op_interface_next_00106: +;source-doc/base-drv/enumerate.c:76: } ret -;source-doc/base-drv/enumerate.c:48: usb_error op_endpoint_next(_working *const working) __sdcccall(1) { +;source-doc/base-drv/enumerate.c:78: usb_error op_endpoint_next(_working *const working) __sdcccall(1) { ; --------------------------------- ; Function op_endpoint_next ; --------------------------------- _op_endpoint_next: - ex de, hl -;source-doc/base-drv/enumerate.c:49: if (working->endpoint_count != 0 && --working->endpoint_count > 0) { - ld hl,0x0017 - add hl, de - ld a, (hl) +;source-doc/base-drv/enumerate.c:81: if (working->endpoint_count != 0 && --working->endpoint_count > 0) { + ld a, l + add a,0x17 + ld c, a + ld a, h + adc a,0x00 + ld b, a + ld a, (bc) or a - jr Z,l_op_endpoint_next_00102 + jr Z,l_op_endpoint_next_00104 dec a - ld (hl), a + ld (bc), a or a - jr Z,l_op_endpoint_next_00102 -;source-doc/base-drv/enumerate.c:50: working->ptr += ((endpoint_descriptor *)working->ptr)->bLength; - ld hl,0x001b - add hl, de - ld c, (hl) - inc hl - ld b, (hl) - dec hl - ld a, (bc) - add a, c + jr Z,l_op_endpoint_next_00104 +;source-doc/base-drv/enumerate.c:82: CHECK(adv_to_next_desc(working, USB_DESCR_ENDPOINT)); + push hl + ld a,0x05 + push af + inc sp + call _adv_to_next_desc + pop hl ld c, a - ld a,0x00 - adc a, b - ld (hl), c - inc hl - ld (hl), a -;source-doc/base-drv/enumerate.c:51: return op_parse_endpoint(working); - ex de, hl + or a + jr NZ,l_op_endpoint_next_00106 +;source-doc/base-drv/enumerate.c:83: return op_parse_endpoint(working); jp _op_parse_endpoint - jr l_op_endpoint_next_00104 -l_op_endpoint_next_00102: -;source-doc/base-drv/enumerate.c:54: return op_interface_next(working); - ex de, hl + jr l_op_endpoint_next_00107 +l_op_endpoint_next_00104: +;source-doc/base-drv/enumerate.c:86: return op_interface_next(working); call _op_interface_next ld a, l -l_op_endpoint_next_00104: -;source-doc/base-drv/enumerate.c:55: } + jr l_op_endpoint_next_00107 +;source-doc/base-drv/enumerate.c:88: done: +l_op_endpoint_next_00106: +;source-doc/base-drv/enumerate.c:89: return result; + ld a, c +l_op_endpoint_next_00107: +;source-doc/base-drv/enumerate.c:90: } ret -;source-doc/base-drv/enumerate.c:57: usb_error op_parse_endpoint(_working *const working) __sdcccall(1) { +;source-doc/base-drv/enumerate.c:92: usb_error op_parse_endpoint(_working *const working) __sdcccall(1) { ; --------------------------------- ; Function op_parse_endpoint ; --------------------------------- @@ -291,7 +409,7 @@ _op_parse_endpoint: ld ix,0 add ix,sp push af -;source-doc/base-drv/enumerate.c:58: const endpoint_descriptor *endpoint = (endpoint_descriptor *)working->ptr; +;source-doc/base-drv/enumerate.c:93: const endpoint_descriptor *endpoint = (endpoint_descriptor *)working->ptr; ld de,0x001c ld c,l ld b,h @@ -301,13 +419,13 @@ _op_parse_endpoint: ld l, (hl) ld (ix-2),l ld (ix-1),a -;source-doc/base-drv/enumerate.c:59: device_config *const device = working->p_current_device; +;source-doc/base-drv/enumerate.c:94: device_config *const device = working->p_current_device; ld hl,29 add hl,bc ld e, (hl) inc hl ld d, (hl) -;source-doc/base-drv/enumerate.c:61: switch (working->usb_device) { +;source-doc/base-drv/enumerate.c:96: switch (working->usb_device) { ld l, c ld h, b inc hl @@ -320,9 +438,9 @@ _op_parse_endpoint: sub 0x04 jr Z,l_op_parse_endpoint_00103 jr l_op_parse_endpoint_00104 -;source-doc/base-drv/enumerate.c:63: case USB_IS_MASS_STORAGE: { +;source-doc/base-drv/enumerate.c:98: case USB_IS_MASS_STORAGE: { l_op_parse_endpoint_00102: -;source-doc/base-drv/enumerate.c:64: parse_endpoints((device_config_storage *)device, endpoint); +;source-doc/base-drv/enumerate.c:99: parse_endpoints((device_config_storage *)device, endpoint); push bc ld l,(ix-2) ld h,(ix-1) @@ -332,28 +450,28 @@ l_op_parse_endpoint_00102: pop af pop af pop bc -;source-doc/base-drv/enumerate.c:65: break; +;source-doc/base-drv/enumerate.c:100: break; jr l_op_parse_endpoint_00104 -;source-doc/base-drv/enumerate.c:68: case USB_IS_KEYBOARD: { +;source-doc/base-drv/enumerate.c:103: case USB_IS_KEYBOARD: { l_op_parse_endpoint_00103: -;source-doc/base-drv/enumerate.c:69: parse_endpoint_keyboard((device_config_keyboard *)device, endpoint); +;source-doc/base-drv/enumerate.c:104: parse_endpoint_keyboard((device_config_keyboard *)device, endpoint); ex de, hl push bc ld e,(ix-2) ld d,(ix-1) call _parse_endpoint_keyboard pop bc -;source-doc/base-drv/enumerate.c:72: } +;source-doc/base-drv/enumerate.c:107: } l_op_parse_endpoint_00104: -;source-doc/base-drv/enumerate.c:74: return op_endpoint_next(working); +;source-doc/base-drv/enumerate.c:109: return op_endpoint_next(working); ld l, c ld h, b call _op_endpoint_next -;source-doc/base-drv/enumerate.c:75: } +;source-doc/base-drv/enumerate.c:110: } ld sp, ix pop ix ret -;source-doc/base-drv/enumerate.c:78: configure_device(const _working *const working, const interface_descriptor *const interface, device_config *const dev_cfg) { +;source-doc/base-drv/enumerate.c:113: configure_device(const _working *const working, const interface_descriptor *const interface, device_config *const dev_cfg) { ; --------------------------------- ; Function configure_device ; --------------------------------- @@ -363,7 +481,7 @@ _configure_device: add ix,sp push af push af -;source-doc/base-drv/enumerate.c:79: dev_cfg->interface_number = interface->bInterfaceNumber; +;source-doc/base-drv/enumerate.c:114: dev_cfg->interface_number = interface->bInterfaceNumber; ld c,(ix+8) ld b,(ix+9) ld e, c @@ -376,7 +494,7 @@ _configure_device: inc hl ld a, (hl) ld (de), a -;source-doc/base-drv/enumerate.c:80: dev_cfg->max_packet_size = working->desc.bMaxPacketSize0; +;source-doc/base-drv/enumerate.c:115: dev_cfg->max_packet_size = working->desc.bMaxPacketSize0; ld hl,0x0001 add hl, bc ex (sp), hl @@ -388,7 +506,7 @@ _configure_device: pop hl push hl ld (hl), a -;source-doc/base-drv/enumerate.c:81: dev_cfg->address = working->current_device_address; +;source-doc/base-drv/enumerate.c:116: dev_cfg->address = working->current_device_address; ld (ix-2),c ld (ix-1),b ld l, e @@ -413,7 +531,7 @@ _configure_device: or c ld (hl), a pop bc -;source-doc/base-drv/enumerate.c:82: dev_cfg->type = working->usb_device; +;source-doc/base-drv/enumerate.c:117: dev_cfg->type = working->usb_device; ld l, e ld h, d inc hl @@ -425,7 +543,7 @@ _configure_device: and 0xf0 or l ld (bc), a -;source-doc/base-drv/enumerate.c:84: return usbtrn_set_configuration(dev_cfg->address, dev_cfg->max_packet_size, working->config.desc.bConfigurationvalue); +;source-doc/base-drv/enumerate.c:119: return usbtrn_set_configuration(dev_cfg->address, dev_cfg->max_packet_size, working->config.desc.bConfigurationvalue); ld hl,36 add hl, de ld b, (hl) @@ -445,11 +563,11 @@ _configure_device: push af inc sp call _usbtrn_set_configuration -;source-doc/base-drv/enumerate.c:85: } +;source-doc/base-drv/enumerate.c:120: } ld sp,ix pop ix ret -;source-doc/base-drv/enumerate.c:87: usb_error op_capture_hub_driver_interface(_working *const working) __sdcccall(1) { +;source-doc/base-drv/enumerate.c:122: usb_error op_capture_hub_driver_interface(_working *const working) __sdcccall(1) { ; --------------------------------- ; Function op_capture_hub_driver_interface ; --------------------------------- @@ -461,7 +579,7 @@ _op_capture_hub_driver_interfac: push af dec sp ex de, hl -;source-doc/base-drv/enumerate.c:88: const interface_descriptor *const interface = (interface_descriptor *)working->ptr; +;source-doc/base-drv/enumerate.c:123: const interface_descriptor *const interface = (interface_descriptor *)working->ptr; ld hl,0x001c add hl,de ld a, (hl) @@ -469,7 +587,7 @@ _op_capture_hub_driver_interfac: ld l, (hl) ld (ix-2),l ld (ix-1),a -;source-doc/base-drv/enumerate.c:92: working->hub_config = &hub_config; +;source-doc/base-drv/enumerate.c:127: working->hub_config = &hub_config; ld hl,0x0019 add hl, de ld c, l @@ -481,13 +599,13 @@ _op_capture_hub_driver_interfac: inc bc ld a, h ld (bc), a -;source-doc/base-drv/enumerate.c:94: hub_config.type = USB_IS_HUB; +;source-doc/base-drv/enumerate.c:129: hub_config.type = USB_IS_HUB; ld hl,0 add hl, sp ld a, (hl) or 0x0f ld (hl), a -;source-doc/base-drv/enumerate.c:95: CHECK(configure_device(working, interface, (device_config *const)&hub_config)); +;source-doc/base-drv/enumerate.c:130: CHECK(configure_device(working, interface, (device_config *const)&hub_config)); push de ld hl,2 add hl, sp @@ -505,18 +623,18 @@ _op_capture_hub_driver_interfac: inc l dec l jr NZ,l_op_capture_hub_driver_interfa -;source-doc/base-drv/enumerate.c:96: RETURN_CHECK(configure_usb_hub(working)); +;source-doc/base-drv/enumerate.c:131: RETURN_CHECK(configure_usb_hub(working)); ex de, hl call _configure_usb_hub ld a, l -;source-doc/base-drv/enumerate.c:97: done: +;source-doc/base-drv/enumerate.c:132: done: l_op_capture_hub_driver_interfa: -;source-doc/base-drv/enumerate.c:98: return result; -;source-doc/base-drv/enumerate.c:99: } +;source-doc/base-drv/enumerate.c:133: return result; +;source-doc/base-drv/enumerate.c:134: } ld sp, ix pop ix ret -;source-doc/base-drv/enumerate.c:101: usb_error op_cap_drv_intf(_working *const working) __z88dk_fastcall { +;source-doc/base-drv/enumerate.c:136: usb_error op_cap_drv_intf(_working *const working) __z88dk_fastcall { ; --------------------------------- ; Function op_cap_drv_intf ; --------------------------------- @@ -529,89 +647,87 @@ _op_cap_drv_intf: ld hl, -14 add hl, sp ld sp, hl -;source-doc/base-drv/enumerate.c:104: const interface_descriptor *const interface = (interface_descriptor *)working->ptr; - ld (ix-2),c - ld l, c - ld (ix-1),b - ld h,b - ld de,0x001b +;source-doc/base-drv/enumerate.c:139: const interface_descriptor *const interface = (interface_descriptor *)working->ptr; + ld l,c + ld h, b + ld de,0x001c add hl, de - ld e, (hl) - inc hl - ld d, (hl) + ld a, (hl) dec hl - ld c, e - ld b, d -;source-doc/base-drv/enumerate.c:106: working->ptr += interface->bLength; - ld a, (bc) - add a, e - ld e, a - ld a,0x00 - adc a, d - ld (hl), e - inc hl - ld (hl), a -;source-doc/base-drv/enumerate.c:107: working->endpoint_count = interface->bNumEndpoints; - ld a,(ix-2) - add a,0x17 - ld e, a - ld a,(ix-1) - adc a,0x00 - ld d, a - ld l, c - ld h, b + ld l, (hl) + ld (ix-2),l + ld (ix-1),a +;source-doc/base-drv/enumerate.c:141: working->endpoint_count = interface->bNumEndpoints; + ld hl,0x0017 + add hl, bc + ex de, hl + ld l,(ix-2) + ld h,(ix-1) inc hl inc hl inc hl inc hl ld a, (hl) ld (de), a -;source-doc/base-drv/enumerate.c:108: working->p_current_device = NULL; - ld a,(ix-2) - add a,0x1d - ld e, a - ld a,(ix-1) - adc a,0x00 - ld d, a - ld l, e - ld h, d +;source-doc/base-drv/enumerate.c:142: if (working->endpoint_count > 0) + or a + jr Z,l_op_cap_drv_intf_00104 +;source-doc/base-drv/enumerate.c:143: CHECK(adv_to_next_desc(working, USB_DESCR_ENDPOINT)); + push bc + ld a,0x05 + push af + inc sp + ld l, c + ld h, b + call _adv_to_next_desc + pop bc + or a + jp NZ, l_op_cap_drv_intf_00117 +l_op_cap_drv_intf_00104: +;source-doc/base-drv/enumerate.c:144: working->p_current_device = NULL; + ld hl,0x001d + add hl, bc + ld e,l + ld d,h xor a ld (hl), a inc hl ld (hl), a -;source-doc/base-drv/enumerate.c:110: switch (working->usb_device) { - ld l,(ix-2) - ld h,(ix-1) +;source-doc/base-drv/enumerate.c:146: switch (working->usb_device) { + ld l, c + ld h, b inc hl inc hl ld a, (hl) cp 0x06 - jr Z,l_op_cap_drv_intf_00104 + jr Z,l_op_cap_drv_intf_00108 sub 0x0f - jr NZ,l_op_cap_drv_intf_00107 -;source-doc/base-drv/enumerate.c:112: CHECK(op_capture_hub_driver_interface(working)) - ld l,(ix-2) - ld h,(ix-1) + jr NZ,l_op_cap_drv_intf_00111 +;source-doc/base-drv/enumerate.c:148: CHECK(op_capture_hub_driver_interface(working)) + ld l,c + ld h,b + push hl call _op_capture_hub_driver_interfac + pop bc or a - jr Z,l_op_cap_drv_intf_00112 - jr l_op_cap_drv_intf_00113 -;source-doc/base-drv/enumerate.c:116: case USB_IS_UNKNOWN: { -l_op_cap_drv_intf_00104: -;source-doc/base-drv/enumerate.c:118: memset(&unkown_dev_cfg, 0, sizeof(device_config)); + jr Z,l_op_cap_drv_intf_00116 + jr l_op_cap_drv_intf_00117 +;source-doc/base-drv/enumerate.c:152: case USB_IS_UNKNOWN: { +l_op_cap_drv_intf_00108: +;source-doc/base-drv/enumerate.c:154: memset(&unkown_dev_cfg, 0, sizeof(device_config)); push bc ld hl,2 add hl, sp ld b,0x06 -l_op_cap_drv_intf_00154: +l_op_cap_drv_intf_00165: xor a ld (hl), a inc hl ld (hl), a inc hl - djnz l_op_cap_drv_intf_00154 + djnz l_op_cap_drv_intf_00165 pop bc -;source-doc/base-drv/enumerate.c:119: working->p_current_device = &unkown_dev_cfg; +;source-doc/base-drv/enumerate.c:155: working->p_current_device = &unkown_dev_cfg; ld hl,0 add hl, sp ld a, l @@ -619,110 +735,119 @@ l_op_cap_drv_intf_00154: inc de ld a, h ld (de), a -;source-doc/base-drv/enumerate.c:120: CHECK(configure_device(working, interface, &unkown_dev_cfg)); - push hl +;source-doc/base-drv/enumerate.c:156: CHECK(configure_device(working, interface, &unkown_dev_cfg)); push bc + push hl ld l,(ix-2) ld h,(ix-1) push hl + push bc call _configure_device pop af pop af pop af ld a, l + pop bc or a - jr Z,l_op_cap_drv_intf_00112 - jr l_op_cap_drv_intf_00113 -;source-doc/base-drv/enumerate.c:124: default: { -l_op_cap_drv_intf_00107: -;source-doc/base-drv/enumerate.c:125: device_config *dev_cfg = find_first_free(); + jr Z,l_op_cap_drv_intf_00116 + jr l_op_cap_drv_intf_00117 +;source-doc/base-drv/enumerate.c:160: default: { +l_op_cap_drv_intf_00111: +;source-doc/base-drv/enumerate.c:161: device_config *dev_cfg = find_first_free(); push bc push de call _find_first_free pop de pop bc -;source-doc/base-drv/enumerate.c:126: if (dev_cfg == NULL) +;source-doc/base-drv/enumerate.c:162: if (dev_cfg == NULL) ld a, h or l - jr NZ,l_op_cap_drv_intf_00109 -;source-doc/base-drv/enumerate.c:127: return USB_ERR_OUT_OF_MEMORY; + jr NZ,l_op_cap_drv_intf_00113 +;source-doc/base-drv/enumerate.c:163: return USB_ERR_OUT_OF_MEMORY; ld l,0x83 - jr l_op_cap_drv_intf_00114 -l_op_cap_drv_intf_00109: -;source-doc/base-drv/enumerate.c:128: working->p_current_device = dev_cfg; + jr l_op_cap_drv_intf_00118 +l_op_cap_drv_intf_00113: +;source-doc/base-drv/enumerate.c:164: working->p_current_device = dev_cfg; ld a, l ld (de), a inc de ld a, h ld (de), a -;source-doc/base-drv/enumerate.c:129: CHECK(configure_device(working, interface, dev_cfg)); - push hl +;source-doc/base-drv/enumerate.c:165: CHECK(configure_device(working, interface, dev_cfg)); push bc + push hl ld l,(ix-2) ld h,(ix-1) push hl + push bc call _configure_device pop af pop af pop af ld a, l + pop bc or a - jr NZ,l_op_cap_drv_intf_00113 -;source-doc/base-drv/enumerate.c:132: } -l_op_cap_drv_intf_00112: -;source-doc/base-drv/enumerate.c:134: result = op_parse_endpoint(working); - ld l,(ix-2) - ld h,(ix-1) + jr NZ,l_op_cap_drv_intf_00117 +;source-doc/base-drv/enumerate.c:168: } +l_op_cap_drv_intf_00116: +;source-doc/base-drv/enumerate.c:170: return op_parse_endpoint(working); + ld l, c + ld h, b call _op_parse_endpoint -;source-doc/base-drv/enumerate.c:136: done: -l_op_cap_drv_intf_00113: -;source-doc/base-drv/enumerate.c:137: return result; ld l, a -l_op_cap_drv_intf_00114: -;source-doc/base-drv/enumerate.c:138: } + jr l_op_cap_drv_intf_00118 +;source-doc/base-drv/enumerate.c:172: done: +l_op_cap_drv_intf_00117: +;source-doc/base-drv/enumerate.c:173: return result; + ld l, a +l_op_cap_drv_intf_00118: +;source-doc/base-drv/enumerate.c:174: } ld sp, ix pop ix ret -;source-doc/base-drv/enumerate.c:140: usb_error op_id_class_drv(_working *const working) __sdcccall(1) { +;source-doc/base-drv/enumerate.c:176: usb_error op_id_class_drv(_working *const working) __sdcccall(1) { ; --------------------------------- ; Function op_id_class_drv ; --------------------------------- _op_id_class_drv: ex de, hl -;source-doc/base-drv/enumerate.c:141: const interface_descriptor *const ptr = (const interface_descriptor *)working->ptr; +;source-doc/base-drv/enumerate.c:177: const interface_descriptor *const ptr = (const interface_descriptor *)working->ptr; ld hl,27 add hl,de ld c, (hl) inc hl ld b, (hl) -;source-doc/base-drv/enumerate.c:143: working->usb_device = ptr->bLength > 5 ? identify_class_driver(working) : 0; - ld l, e - ld h, d - inc hl - inc hl +;source-doc/base-drv/enumerate.c:179: if (ptr->bDescriptorType != USB_DESCR_INTERFACE) + inc bc ld a, (bc) - cp 0x06 - jr C,l_op_id_class_drv_00103 - push hl + sub 0x04 + jr Z,l_op_id_class_drv_00102 +;source-doc/base-drv/enumerate.c:180: return USB_ERR_FAIL; + ld a,0x0e + jr l_op_id_class_drv_00103 +l_op_id_class_drv_00102: +;source-doc/base-drv/enumerate.c:182: working->usb_device = identify_class_driver(working); + ld c, e + ld b, d + inc bc + inc bc + push bc push de push de call _identify_class_driver pop af ld a, l pop de - pop hl - jr l_op_id_class_drv_00104 -l_op_id_class_drv_00103: - xor a -l_op_id_class_drv_00104: - ld (hl), a -;source-doc/base-drv/enumerate.c:145: return op_cap_drv_intf(working); + pop bc + ld (bc), a +;source-doc/base-drv/enumerate.c:184: return op_cap_drv_intf(working); ex de, hl call _op_cap_drv_intf ld a, l -;source-doc/base-drv/enumerate.c:146: } +l_op_id_class_drv_00103: +;source-doc/base-drv/enumerate.c:185: } ret -;source-doc/base-drv/enumerate.c:148: usb_error op_get_cfg_desc(_working *const working) __sdcccall(1) { +;source-doc/base-drv/enumerate.c:187: usb_error op_get_cfg_desc(_working *const working) __sdcccall(1) { ; --------------------------------- ; Function op_get_cfg_desc ; --------------------------------- @@ -731,29 +856,39 @@ _op_get_cfg_desc: ld ix,0 add ix,sp dec sp - ld c, l - ld b, h -;source-doc/base-drv/enumerate.c:149: memset(working->config.buffer, 0, MAX_CONFIG_SIZE); +;source-doc/base-drv/enumerate.c:190: const uint8_t max_packet_size = working->desc.bMaxPacketSize0; + ld d,h + ld c,l + ld b,h + ld hl,10 + add hl,bc + ld a, (hl) + ld (ix-1),a +;source-doc/base-drv/enumerate.c:192: memset(working->config.buffer, 0, MAX_CONFIG_SIZE); ld hl,0x001f add hl, bc push bc ld b,0x46 -l_op_get_cfg_desc_00113: +l_op_get_cfg_desc_00122: xor a ld (hl), a inc hl ld (hl), a inc hl - djnz l_op_get_cfg_desc_00113 + djnz l_op_get_cfg_desc_00122 pop bc -;source-doc/base-drv/enumerate.c:151: const uint8_t max_packet_size = working->desc.bMaxPacketSize0; - ld e,c - ld d,b - ld hl,10 - add hl,bc - ld a, (hl) - ld (ix-1),a -;source-doc/base-drv/enumerate.c:154: working->config.buffer)); +;source-doc/base-drv/enumerate.c:193: working->ptr = working->config.buffer; + ld hl,0x001b + add hl, bc + ld a, c + add a,0x1f + ld e, a + ld a, b + adc a,0x00 + ld (hl), e + inc hl + ld (hl), a +;source-doc/base-drv/enumerate.c:196: working->config.buffer)); ld hl,0x001f add hl, bc ex de, hl @@ -778,25 +913,22 @@ l_op_get_cfg_desc_00113: pop af pop af pop af - pop bc ld a, l - ld (_result), a - ld hl,_result - ld a, (hl) + pop bc or a - jr NZ,l_op_get_cfg_desc_00103 -;source-doc/base-drv/enumerate.c:156: working->ptr = (working->config.buffer + sizeof(config_descriptor)); - ld hl,0x001b - add hl, bc - ld a, c - add a,0x28 - ld e, a - ld a, b - adc a,0x00 - ld (hl), e - inc hl - ld (hl), a -;source-doc/base-drv/enumerate.c:157: working->interface_count = working->config.desc.bNumInterfaces; + jr NZ,l_op_get_cfg_desc_00105 +;source-doc/base-drv/enumerate.c:198: CHECK(adv_to_next_desc(working, USB_DESCR_INTERFACE)); + push bc + ld a,0x04 + push af + inc sp + ld l, c + ld h, b + call _adv_to_next_desc + pop bc + or a + jr NZ,l_op_get_cfg_desc_00105 +;source-doc/base-drv/enumerate.c:199: working->interface_count = working->config.desc.bNumInterfaces; ld hl,0x0016 add hl, bc ex de, hl @@ -804,21 +936,18 @@ l_op_get_cfg_desc_00113: add hl,bc ld a, (hl) ld (de), a -;source-doc/base-drv/enumerate.c:159: return op_id_class_drv(working); +;source-doc/base-drv/enumerate.c:201: return op_id_class_drv(working); ld l, c ld h, b call _op_id_class_drv - jr l_op_get_cfg_desc_00104 -;source-doc/base-drv/enumerate.c:160: done: -l_op_get_cfg_desc_00103: -;source-doc/base-drv/enumerate.c:161: return result; - ld a, (_result) -l_op_get_cfg_desc_00104: -;source-doc/base-drv/enumerate.c:162: } +;source-doc/base-drv/enumerate.c:203: done: +;source-doc/base-drv/enumerate.c:204: return result; +l_op_get_cfg_desc_00105: +;source-doc/base-drv/enumerate.c:205: } inc sp pop ix ret -;source-doc/base-drv/enumerate.c:164: usb_error read_all_configs(enumeration_state *const state) { +;source-doc/base-drv/enumerate.c:207: usb_error read_all_configs(enumeration_state *const state) { ; --------------------------------- ; Function read_all_configs ; --------------------------------- @@ -829,7 +958,7 @@ _read_all_configs: ld hl, -171 add hl, sp ld sp, hl -;source-doc/base-drv/enumerate.c:169: memset(&working, 0, sizeof(_working)); +;source-doc/base-drv/enumerate.c:212: memset(&working, 0, sizeof(_working)); ld hl,0 add hl, sp ld e,l @@ -843,7 +972,7 @@ l_read_all_configs_00150: ld (hl),0x00 inc hl djnz l_read_all_configs_00149 -;source-doc/base-drv/enumerate.c:170: working.state = state; +;source-doc/base-drv/enumerate.c:213: working.state = state; ld l, e ld h, d ld a,(ix+4) @@ -851,7 +980,7 @@ l_read_all_configs_00150: inc hl ld a,(ix+5) ld (hl), a -;source-doc/base-drv/enumerate.c:172: CHECK(usbtrn_get_descriptor(&working.desc)); +;source-doc/base-drv/enumerate.c:215: CHECK(usbtrn_get_descriptor(&working.desc)); push de ld hl,5 add hl, sp @@ -862,7 +991,7 @@ l_read_all_configs_00150: pop de or a jr NZ,l_read_all_configs_00108 -;source-doc/base-drv/enumerate.c:174: state->next_device_address++; +;source-doc/base-drv/enumerate.c:217: state->next_device_address++; ld b,(ix+5) ld a,(ix+4) ld l, a @@ -872,17 +1001,17 @@ l_read_all_configs_00150: ld l, a ld h, b ld (hl), c -;source-doc/base-drv/enumerate.c:175: working.current_device_address = state->next_device_address; +;source-doc/base-drv/enumerate.c:218: working.current_device_address = state->next_device_address; ld hl,0x0018 add hl, de ld (hl), c -;source-doc/base-drv/enumerate.c:176: CHECK(usbtrn_set_address(working.current_device_address)); +;source-doc/base-drv/enumerate.c:219: CHECK(usbtrn_set_address(working.current_device_address)); push de ld l, c call _usbtrn_set_address ld a, l pop de -;source-doc/base-drv/enumerate.c:178: for (uint8_t config_index = 0; config_index < working.desc.bNumConfigurations; config_index++) { +;source-doc/base-drv/enumerate.c:221: for (uint8_t config_index = 0; config_index < working.desc.bNumConfigurations; config_index++) { or a jr NZ,l_read_all_configs_00108 ld c,a @@ -893,11 +1022,11 @@ l_read_all_configs_00110: ld a, c sub b jr NC,l_read_all_configs_00107 -;source-doc/base-drv/enumerate.c:179: working.config_index = config_index; +;source-doc/base-drv/enumerate.c:222: working.config_index = config_index; ld hl,0x0015 add hl, de ld (hl), c -;source-doc/base-drv/enumerate.c:181: CHECK(op_get_cfg_desc(&working)); +;source-doc/base-drv/enumerate.c:224: CHECK(op_get_cfg_desc(&working)); ld l, e ld h, d push bc @@ -907,23 +1036,23 @@ l_read_all_configs_00110: pop bc or a jr NZ,l_read_all_configs_00108 -;source-doc/base-drv/enumerate.c:178: for (uint8_t config_index = 0; config_index < working.desc.bNumConfigurations; config_index++) { +;source-doc/base-drv/enumerate.c:221: for (uint8_t config_index = 0; config_index < working.desc.bNumConfigurations; config_index++) { inc c jr l_read_all_configs_00110 l_read_all_configs_00107: -;source-doc/base-drv/enumerate.c:184: return USB_ERR_OK; +;source-doc/base-drv/enumerate.c:227: return USB_ERR_OK; ld l,0x00 jr l_read_all_configs_00112 -;source-doc/base-drv/enumerate.c:185: done: +;source-doc/base-drv/enumerate.c:228: done: l_read_all_configs_00108: -;source-doc/base-drv/enumerate.c:186: return result; +;source-doc/base-drv/enumerate.c:229: return result; ld l, a l_read_all_configs_00112: -;source-doc/base-drv/enumerate.c:187: } +;source-doc/base-drv/enumerate.c:230: } ld sp, ix pop ix ret -;source-doc/base-drv/enumerate.c:189: usb_error enumerate_all_devices(void) { +;source-doc/base-drv/enumerate.c:232: usb_error enumerate_all_devices(void) { ; --------------------------------- ; Function enumerate_all_devices ; --------------------------------- @@ -932,8 +1061,8 @@ _enumerate_all_devices: ld ix,0 add ix,sp push af -;source-doc/base-drv/enumerate.c:190: _usb_state *const work_area = get_usb_work_area(); -;source-doc/base-drv/enumerate.c:192: memset(&state, 0, sizeof(enumeration_state)); +;source-doc/base-drv/enumerate.c:233: _usb_state *const work_area = get_usb_work_area(); +;source-doc/base-drv/enumerate.c:235: memset(&state, 0, sizeof(enumeration_state)); ld hl,0 add hl, sp ld e,l @@ -942,18 +1071,18 @@ _enumerate_all_devices: ld (hl), a inc hl ld (hl), a -;source-doc/base-drv/enumerate.c:194: usb_error result = read_all_configs(&state); +;source-doc/base-drv/enumerate.c:237: usb_error result = read_all_configs(&state); push de push de call _read_all_configs pop af pop de -;source-doc/base-drv/enumerate.c:196: work_area->count_of_detected_usb_devices = state.next_device_address; +;source-doc/base-drv/enumerate.c:239: work_area->count_of_detected_usb_devices = state.next_device_address; ld bc,_x + 1 ld a, (de) ld (bc), a -;source-doc/base-drv/enumerate.c:199: return result; -;source-doc/base-drv/enumerate.c:200: } +;source-doc/base-drv/enumerate.c:242: return result; +;source-doc/base-drv/enumerate.c:243: } ld sp, ix pop ix ret diff --git a/Source/HBIOS/ch376-native/source-doc/base-drv/enumerate.c b/Source/HBIOS/ch376-native/source-doc/base-drv/enumerate.c index f4131d8c..69b666f6 100644 --- a/Source/HBIOS/ch376-native/source-doc/base-drv/enumerate.c +++ b/Source/HBIOS/ch376-native/source-doc/base-drv/enumerate.c @@ -10,6 +10,30 @@ usb_error op_id_class_drv(_working *const working) __sdcccall(1); usb_error op_parse_endpoint(_working *const working) __sdcccall(1); +static usb_error adv_to_next_desc(_working *const working, const uint8_t descriptor_type) __sdcccall(1) { + usb_descriptor_t *d; + const uint8_t *buffer_end = working->config.buffer + MAX_CONFIG_SIZE; + + if (working->ptr >= buffer_end) + return USB_ERR_BUFF_TO_LARGE; + + d = (usb_descriptor_t *)working->ptr; + + do { + working->ptr += d->bLength; + + if (working->ptr >= buffer_end) + return USB_ERR_BUFF_TO_LARGE; + + d = (usb_descriptor_t *)working->ptr; + } while (d->bDescriptorType != descriptor_type); + + if (working->ptr + d->bLength >= buffer_end) + return USB_ERR_BUFF_TO_LARGE; + + return USB_ERR_OK; +} + void parse_endpoint_keyboard(device_config_keyboard *const keyboard_config, const endpoint_descriptor const *pEndpoint) __sdcccall(1) { endpoint_param *const ep = &keyboard_config->endpoints[0]; @@ -39,19 +63,30 @@ usb_device_type identify_class_driver(_working *const working) { } usb_error op_interface_next(_working *const working) __z88dk_fastcall { + uint8_t result; + if (--working->interface_count == 0) return USB_ERR_OK; + CHECK(adv_to_next_desc(working, USB_DESCR_INTERFACE)); return op_id_class_drv(working); + +done: + return result; } usb_error op_endpoint_next(_working *const working) __sdcccall(1) { + usb_error result; + if (working->endpoint_count != 0 && --working->endpoint_count > 0) { - working->ptr += ((endpoint_descriptor *)working->ptr)->bLength; + CHECK(adv_to_next_desc(working, USB_DESCR_ENDPOINT)); return op_parse_endpoint(working); } return op_interface_next(working); + +done: + return result; } usb_error op_parse_endpoint(_working *const working) __sdcccall(1) { @@ -103,8 +138,9 @@ usb_error op_cap_drv_intf(_working *const working) __z88dk_fastcall { _usb_state *const work_area = get_usb_work_area(); const interface_descriptor *const interface = (interface_descriptor *)working->ptr; - working->ptr += interface->bLength; - working->endpoint_count = interface->bNumEndpoints; + working->endpoint_count = interface->bNumEndpoints; + if (working->endpoint_count > 0) + CHECK(adv_to_next_desc(working, USB_DESCR_ENDPOINT)); working->p_current_device = NULL; switch (working->usb_device) { @@ -131,7 +167,7 @@ usb_error op_cap_drv_intf(_working *const working) __z88dk_fastcall { } } - result = op_parse_endpoint(working); + return op_parse_endpoint(working); done: return result; @@ -140,23 +176,30 @@ done: usb_error op_id_class_drv(_working *const working) __sdcccall(1) { const interface_descriptor *const ptr = (const interface_descriptor *)working->ptr; - working->usb_device = ptr->bLength > 5 ? identify_class_driver(working) : 0; + if (ptr->bDescriptorType != USB_DESCR_INTERFACE) + return USB_ERR_FAIL; + + working->usb_device = identify_class_driver(working); return op_cap_drv_intf(working); } usb_error op_get_cfg_desc(_working *const working) __sdcccall(1) { - memset(working->config.buffer, 0, MAX_CONFIG_SIZE); + usb_error result; const uint8_t max_packet_size = working->desc.bMaxPacketSize0; + memset(working->config.buffer, 0, MAX_CONFIG_SIZE); + working->ptr = working->config.buffer; + CHECK(usbtrn_gfull_cfg_desc(working->config_index, working->current_device_address, max_packet_size, MAX_CONFIG_SIZE, working->config.buffer)); - working->ptr = (working->config.buffer + sizeof(config_descriptor)); + CHECK(adv_to_next_desc(working, USB_DESCR_INTERFACE)); working->interface_count = working->config.desc.bNumInterfaces; return op_id_class_drv(working); + done: return result; } diff --git a/Source/HBIOS/ch376-native/source-doc/base-drv/protocol.h b/Source/HBIOS/ch376-native/source-doc/base-drv/protocol.h index df622b44..d0ec7091 100644 --- a/Source/HBIOS/ch376-native/source-doc/base-drv/protocol.h +++ b/Source/HBIOS/ch376-native/source-doc/base-drv/protocol.h @@ -6,6 +6,22 @@ #include "transfers.h" #include +typedef struct { + uint8_t bLength; + uint8_t bDescriptorType; +} usb_descriptor_t; + +#define USB_DESCR_DEVICE 1 +#define USB_DESCR_CONFIGURATION 2 +#define USB_DESCR_STRING 3 +#define USB_DESCR_INTERFACE 4 +#define USB_DESCR_ENDPOINT 5 +#define USB_DESCR_DEV_QUALIFIER 6 +#define USB_DESCR_OTHER_SPEED 7 +#define USB_DESCR_HID 33 +#define USB_DESCR_HID_REPORT 34 +#define USB_DESCR_HID_PHYSICAL_DESC 35 + typedef struct _device_descriptor { uint8_t bLength; uint8_t bDescriptorType; diff --git a/Source/HBIOS/ch376-native/source-doc/base-drv/transfers.c b/Source/HBIOS/ch376-native/source-doc/base-drv/transfers.c index a285685c..9705b89e 100644 --- a/Source/HBIOS/ch376-native/source-doc/base-drv/transfers.c +++ b/Source/HBIOS/ch376-native/source-doc/base-drv/transfers.c @@ -82,7 +82,7 @@ done: } /** - * @brief Perform a USB data in on the specififed endpoint + * @brief Perform a USB data in on the specified endpoint * * @param buffer the buffer to receive the data * @param buffer_size the maximum size of data to be received