summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHa Thach <[email protected]>2024-04-08 14:24:16 +0700
committerGitHub <[email protected]>2024-04-08 14:24:16 +0700
commitbc10394e66f9658a696fee11d15cdc8ff1d66432 (patch)
tree163091ac4b1dbef5a5d76e874f1350022602a01b
parentaf1346c74878aaec8549483ae6371614f550c863 (diff)
parentcbbfbbb57ea8b4ea97ce4f2e2d157da9c25019fe (diff)
Merge pull request #2577 from hathach/max3421-configuration
add cpuctl and pinctl to tuh_configure() option for max3421
-rw-r--r--.github/workflows/build_iar.yml1
-rw-r--r--src/host/usbh.h10
-rw-r--r--src/portable/analog/max3421/hcd_max3421.c18
3 files changed, 19 insertions, 10 deletions
diff --git a/.github/workflows/build_iar.yml b/.github/workflows/build_iar.yml
index a0a022ecc..499349904 100644
--- a/.github/workflows/build_iar.yml
+++ b/.github/workflows/build_iar.yml
@@ -28,6 +28,7 @@ concurrency:
jobs:
cmake:
+ if: github.repository_owner == 'hathach'
runs-on: [self-hosted, Linux, X64, hifiphile]
strategy:
fail-fast: false
diff --git a/src/host/usbh.h b/src/host/usbh.h
index 57362c778..359684169 100644
--- a/src/host/usbh.h
+++ b/src/host/usbh.h
@@ -80,12 +80,16 @@ enum {
TUH_CFGID_MAX3421 = 200,
};
+typedef struct {
+ uint8_t max_nak; // max NAK per endpoint per frame
+ uint8_t cpuctl; // R16: CPU Control Register
+ uint8_t pinctl; // R17: Pin Control Register. FDUPSPI bit is ignored
+} tuh_configure_max3421_t;
+
typedef union {
// For TUH_CFGID_RPI_PIO_USB_CONFIGURATION use pio_usb_configuration_t
- struct {
- uint8_t max_nak;
- } max3421;
+ tuh_configure_max3421_t max3421;
} tuh_configure_param_t;
//--------------------------------------------------------------------+
diff --git a/src/portable/analog/max3421/hcd_max3421.c b/src/portable/analog/max3421/hcd_max3421.c
index 059f674cd..39afb7505 100644
--- a/src/portable/analog/max3421/hcd_max3421.c
+++ b/src/portable/analog/max3421/hcd_max3421.c
@@ -233,7 +233,11 @@ typedef struct {
static max3421_data_t _hcd_data;
// max NAK before giving up in a frame. 0 means infinite NAKs
-static uint8_t _max_nak = MAX_NAK_DEFAULT;
+static tuh_configure_max3421_t _tuh_cfg = {
+ .max_nak = MAX_NAK_DEFAULT,
+ .cpuctl = 0, // default: INT pulse width = 10.6 us
+ .pinctl = 0, // default: negative edge interrupt
+};
//--------------------------------------------------------------------+
// API: SPI transfer with MAX3421E
@@ -416,7 +420,7 @@ static void free_ep(uint8_t daddr) {
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) &&
- (_max_nak == 0 || state < EP_STATE_ATTEMPT_1 + _max_nak);
+ (_tuh_cfg.max_nak == 0 || state < EP_STATE_ATTEMPT_1 + _tuh_cfg.max_nak);
}
// Find the next pending endpoint using round-robin scheduling, starting from next endpoint.
@@ -454,7 +458,7 @@ bool hcd_configure(uint8_t rhport, uint32_t cfg_id, const void* cfg_param) {
TU_VERIFY(cfg_id == TUH_CFGID_MAX3421 && cfg_param != NULL);
tuh_configure_param_t const* cfg = (tuh_configure_param_t const*) cfg_param;
- _max_nak = tu_min8(cfg->max3421.max_nak, EP_STATE_ATTEMPT_MAX-EP_STATE_ATTEMPT_1);
+ _tuh_cfg = cfg->max3421;
return true;
}
@@ -476,7 +480,7 @@ bool hcd_init(uint8_t rhport) {
#endif
// full duplex, interrupt negative edge
- reg_write(rhport, PINCTL_ADDR, PINCTL_FDUPSPI, false);
+ reg_write(rhport, PINCTL_ADDR, _tuh_cfg.pinctl | PINCTL_FDUPSPI, false);
// v1 is 0x01, v2 is 0x12, v3 is 0x13
uint8_t const revision = reg_read(rhport, REVISION_ADDR, false);
@@ -505,7 +509,7 @@ bool hcd_init(uint8_t rhport) {
tuh_max3421_int_api(rhport, true);
// Enable Interrupt pin
- reg_write(rhport, CPUCTL_ADDR, CPUCTL_IE, false);
+ reg_write(rhport, CPUCTL_ADDR, _tuh_cfg.cpuctl | CPUCTL_IE, false);
return true;
}
@@ -516,9 +520,9 @@ bool hcd_deinit(uint8_t rhport) {
// disable interrupt
tuh_max3421_int_api(rhport, false);
- // reset max3421
+ // reset max3421 and power down
reg_write(rhport, USBCTL_ADDR, USBCTL_CHIPRES, false);
- reg_write(rhport, USBCTL_ADDR, 0, false);
+ reg_write(rhport, USBCTL_ADDR, USBCTL_PWRDOWN, false);
#if OSAL_MUTEX_REQUIRED
osal_mutex_delete(_hcd_data.spi_mutex);