Skip to content

Commit 5dc16e7

Browse files
committed
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.
1 parent 1f102c5 commit 5dc16e7

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

lib/pbio/drv/usb/usb_nxt.c

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

@@ -772,8 +779,7 @@ static void pbdrv_usb_nxt_isr(void) {
772779
}
773780

774781
/* and we will send the following data */
775-
if (pbdrv_usb_nxt_state.tx_len[endpoint] > 0
776-
&& pbdrv_usb_nxt_state.tx_data[endpoint] != NULL) {
782+
if (pbdrv_usb_nxt_state.tx_data[endpoint] != NULL) {
777783
pbdrv_usb_nxt_write_data(endpoint, pbdrv_usb_nxt_state.tx_data[endpoint],
778784
pbdrv_usb_nxt_state.tx_len[endpoint]);
779785
} else {

0 commit comments

Comments
 (0)