Skip to content

Commit 48552e5

Browse files
committed
mb9bf560l usb added flag if we need to send a ack or not on the control endpoint
1 parent 2b78a2a commit 48552e5

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

  • targets/core/cypress/mb9bf560l

targets/core/cypress/mb9bf560l/usb.hpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define KLIB_CYPRESS_MB9BF560L_USB_HPP
33

44
#include <span>
5+
#include <atomic>
56

67
#include <klib/klib.hpp>
78
#include <klib/math.hpp>
@@ -132,6 +133,9 @@ namespace klib::core::mb9bf560l::io {
132133
// create a instance of the helper
133134
static inline auto helper = irq_helper();
134135

136+
// flag if the last request was a setup packet
137+
static inline std::atomic<bool> setup_packet_received = false;
138+
135139
/**
136140
* @brief Convert a mode to the correct raw value for the usb hardware
137141
*
@@ -651,10 +655,14 @@ namespace klib::core::mb9bf560l::io {
651655
if (const uint16_t ep_status = Usb::port->EP0OS; ep_status & (0x1 << 10)) [[likely]] {
652656
// check if we have a setup packet
653657
if (status & (0x1 << 1)) [[likely]] {
658+
setup_packet_received = true;
659+
654660
// we have a setup packet
655661
setup_packet_irq();
656662
}
657663
else if (ep_status & (0x1 << 14)) {
664+
setup_packet_received = false;
665+
658666
// get the amount of bytes we received
659667
const uint32_t count = get_endpoint_byte_count(0, klib::usb::usb::endpoint_mode::out);
660668

@@ -974,6 +982,17 @@ namespace klib::core::mb9bf560l::io {
974982
// This is handled in hardware. No need to send a ack again. In some
975983
// cases the hardware does not send a ack. For example the SET_IDLE.
976984
// We send this manually when we detect it.
985+
if (endpoint == 0 && setup_packet_received.load()) {
986+
// for endpoint 0 setup the hardware sends a ack automatically. Ignore these
987+
return;
988+
}
989+
990+
// get the endpoint status register
991+
volatile uint16_t *const ep_status = get_endpoint_status(endpoint, mode);
992+
993+
// clear the drq flag to mark we have written/read the data to read the
994+
// zlp or write the zlp
995+
(*ep_status) &= (~(0x1 << 10));
977996
}
978997

979998
/**

0 commit comments

Comments
 (0)