summaryrefslogtreecommitdiff
path: root/src/portable
diff options
context:
space:
mode:
authorhathach <[email protected]>2024-04-02 16:38:40 +0700
committerhathach <[email protected]>2024-04-02 16:38:40 +0700
commit7d3d60f96de3f6e15291c9302463c294e2dc98de (patch)
tree9066cd077fd07703326391c46c3e55f165b1db5b /src/portable
parente802fe0677c901a444e7c9b5d67be2a1f400adee (diff)
add hcd_configure() to change max NAK dynamically
Diffstat (limited to 'src/portable')
-rw-r--r--src/portable/analog/max3421/hcd_max3421.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/src/portable/analog/max3421/hcd_max3421.c b/src/portable/analog/max3421/hcd_max3421.c
index 1b182e551..12d80e0b5 100644
--- a/src/portable/analog/max3421/hcd_max3421.c
+++ b/src/portable/analog/max3421/hcd_max3421.c
@@ -30,6 +30,7 @@
#include <stdatomic.h>
#include "host/hcd.h"
+#include "host/usbh.h"
//--------------------------------------------------------------------+
//
@@ -230,7 +231,9 @@ typedef struct {
} max3421_data_t;
static max3421_data_t _hcd_data;
-static uint8_t _max_nak = MAX_NAK_DEFAULT; // max NAK before giving up in a usb frame
+
+// max NAK before giving up in a frame. 0 means infinite NAKs
+static uint8_t _max_nak = MAX_NAK_DEFAULT;
//--------------------------------------------------------------------+
// API: SPI transfer with MAX3421E
@@ -409,10 +412,11 @@ static void free_ep(uint8_t daddr) {
}
}
-// Check if endpoint has an queued transfer
+// Check if endpoint has an queued transfer and not reach max NAK
TU_ATTR_ALWAYS_INLINE static inline bool is_ep_pending(max3421_ep_t const * ep) {
uint8_t const state = ep->state;
- return ep->packet_size && state >= EP_STATE_ATTEMPT_1 && state < EP_STATE_ATTEMPT_1 + _max_nak;
+ return ep->packet_size && (state >= EP_STATE_ATTEMPT_1) &&
+ (_max_nak == 0 || state < EP_STATE_ATTEMPT_1 + _max_nak);
}
// Find the next pending endpoint using round-robin scheduling, starting from next endpoint.
@@ -447,10 +451,11 @@ static max3421_ep_t * find_next_pending_ep(max3421_ep_t * cur_ep) {
// optional hcd configuration, called by tuh_configure()
bool hcd_configure(uint8_t rhport, uint32_t cfg_id, const void* cfg_param) {
(void) rhport;
- (void) cfg_id;
- (void) cfg_param;
+ TU_VERIFY(cfg_id == TUH_CFGID_MAX3421);
- return false;
+ tuh_configure_param_t const* cfg = (tuh_configure_param_t const*) cfg_param;
+ _max_nak = cfg->max3421.max_nak;
+ return true;
}
// Initialize controller to host mode