diff --git a/firmware/platform/lpc43xx/drivers/usb/usb.c b/firmware/platform/lpc43xx/drivers/usb/usb.c index 2a4a678..29c322d 100644 --- a/firmware/platform/lpc43xx/drivers/usb/usb.c +++ b/firmware/platform/lpc43xx/drivers/usb/usb.c @@ -833,10 +833,13 @@ void usb_copy_setup(usb_setup_t* const dst, const volatile uint8_t* const src) { void usb_endpoint_init_without_descriptor( - const usb_endpoint_t* const endpoint, - uint_fast16_t max_packet_size, - usb_transfer_type_t transfer_type -) { + usb_endpoint_t* const endpoint, + uint_fast16_t max_packet_size, + usb_transfer_type_t transfer_type, + bool manual_zlps) +{ + bool zero_length_terminate = (transfer_type == USB_TRANSFER_TYPE_CONTROL) && !manual_zlps; + usb_endpoint_flush(endpoint); // TODO: There are more capabilities to adjust based on the endpoint @@ -846,7 +849,7 @@ void usb_endpoint_init_without_descriptor( = USB_QH_CAPABILITIES_MULT(0) | USB_QH_CAPABILITIES_MPL(max_packet_size) | ((transfer_type == USB_TRANSFER_TYPE_CONTROL) ? USB_QH_CAPABILITIES_IOS : 0) - | ((transfer_type == USB_TRANSFER_TYPE_CONTROL) ? 0 : USB_QH_CAPABILITIES_ZLT); + | ((zero_length_terminate) ? 0 : USB_QH_CAPABILITIES_ZLT); qh->current_dtd_pointer = 0; qh->next_dtd_pointer = USB_TD_NEXT_DTD_POINTER_TERMINATE; qh->total_bytes @@ -864,6 +867,8 @@ void usb_endpoint_init_without_descriptor( usb_endpoint_set_type(endpoint, transfer_type); + endpoint->max_packet_size = max_packet_size; + usb_endpoint_enable(endpoint); } @@ -905,7 +910,7 @@ void usb_endpoint_init( transfer_type = usb_endpoint_descriptor_transfer_type(endpoint_descriptor); } - usb_endpoint_init_without_descriptor(endpoint, max_packet_size, transfer_type); + usb_endpoint_init_without_descriptor(endpoint, max_packet_size, transfer_type, false); } diff --git a/firmware/platform/lpc43xx/include/drivers/usb/usb.h b/firmware/platform/lpc43xx/include/drivers/usb/usb.h index 5a5f0ed..9c4cfe3 100644 --- a/firmware/platform/lpc43xx/include/drivers/usb/usb.h +++ b/firmware/platform/lpc43xx/include/drivers/usb/usb.h @@ -113,9 +113,10 @@ void usb_set_address_deferred( ); void usb_endpoint_init_without_descriptor( - const usb_endpoint_t* const endpoint, - uint_fast16_t max_packet_size, - usb_transfer_type_t transfer_type + usb_endpoint_t* const endpoint, + uint_fast16_t max_packet_size, + usb_transfer_type_t transfer_type, + bool manual_zlps ); void usb_in_endpoint_enable_nak_interrupt( diff --git a/firmware/platform/lpc43xx/include/drivers/usb/usb_type.h b/firmware/platform/lpc43xx/include/drivers/usb/usb_type.h index 2f98809..c3a9589 100644 --- a/firmware/platform/lpc43xx/include/drivers/usb/usb_type.h +++ b/firmware/platform/lpc43xx/include/drivers/usb/usb_type.h @@ -270,6 +270,7 @@ struct usb_endpoint_t { usb_setup_t setup; uint8_t buffer[8]; // Buffer for use during IN stage. const uint_fast8_t address; + uint16_t max_packet_size; usb_peripheral_t* device; usb_endpoint_t* const in; usb_endpoint_t* const out;