Skip to content

Commit

Permalink
Merge pull request greatscottgadgets#15 from Qyriad/fixes/usb-manual-zlp
Browse files Browse the repository at this point in the history
firmware: allow for manual handling of zero-length-packets
  • Loading branch information
ktemkin authored Sep 16, 2019
2 parents edbfecb + 457b51b commit f21543a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
17 changes: 11 additions & 6 deletions firmware/platform/lpc43xx/drivers/usb/usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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);
}

Expand Down Expand Up @@ -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);

}

Expand Down
7 changes: 4 additions & 3 deletions firmware/platform/lpc43xx/include/drivers/usb/usb.h
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions firmware/platform/lpc43xx/include/drivers/usb/usb_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit f21543a

Please sign in to comment.