Skip to content

Commit 85b7340

Browse files
ArcaneNibbledlech
authored andcommitted
pbio/drv/usb/usb_nxt.c: Fix ZLPs on the control pipe
This is needed to correctly indicate end of descriptor when the descriptor size is an exact multiple of the endpoint packet size. This fixes enumeration issues on Windows. Removes the former TODO in the configuration descriptor handling. It is not needed and was masking this issue.
1 parent 30b9e94 commit 85b7340

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

lib/pbio/drv/usb/usb_nxt.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,14 @@ static void pbdrv_usb_nxt_write_data(int endpoint, const void *ptr_, uint32_t le
291291
pbdrv_usb_nxt_state.tx_data[tx] = (uint8_t *)(ptr + packet_size);
292292
pbdrv_usb_nxt_state.tx_len[tx] = length;
293293
} else {
294-
pbdrv_usb_nxt_state.tx_data[tx] = NULL;
294+
if (length == packet_size && endpoint == 0) {
295+
// If we are sending data to the control pipe, we must terminate the data
296+
// with a ZLP. In order to do so, we set the data pointer to non-NULL
297+
// but the length to 0. We do not want to send ZLPs on the Pybricks bulk pipe.
298+
pbdrv_usb_nxt_state.tx_data[tx] = (uint8_t *)(ptr);
299+
} else {
300+
pbdrv_usb_nxt_state.tx_data[tx] = NULL;
301+
}
295302
pbdrv_usb_nxt_state.tx_len[tx] = 0;
296303
}
297304

@@ -447,11 +454,6 @@ static void pbdrv_usb_handle_std_request(pbdrv_usb_nxt_setup_packet_t *packet) {
447454
size = sizeof(pbdrv_usb_nxt_full_config);
448455
pbdrv_usb_nxt_write_data(0, &pbdrv_usb_nxt_full_config,
449456
MIN(size, packet->length));
450-
451-
/* TODO: Why? This is not specified in the USB specs. */
452-
if (pbdrv_usb_nxt_full_config.conf_desc.wTotalLength < packet->length) {
453-
pbdrv_usb_nxt_send_null();
454-
}
455457
break;
456458

457459
case USB_DESC_TYPE_STR: /* String or language info. */
@@ -776,8 +778,7 @@ static void pbdrv_usb_nxt_isr(void) {
776778
}
777779

778780
/* and we will send the following data */
779-
if (pbdrv_usb_nxt_state.tx_len[endpoint] > 0
780-
&& pbdrv_usb_nxt_state.tx_data[endpoint] != NULL) {
781+
if (pbdrv_usb_nxt_state.tx_data[endpoint] != NULL) {
781782
pbdrv_usb_nxt_write_data(endpoint, pbdrv_usb_nxt_state.tx_data[endpoint],
782783
pbdrv_usb_nxt_state.tx_len[endpoint]);
783784
} else {

0 commit comments

Comments
 (0)