Skip to content

Commit 6829820

Browse files
committed
add max3421e port for nrf52840
1 parent 1429b5c commit 6829820

File tree

5 files changed

+71
-13
lines changed

5 files changed

+71
-13
lines changed

examples/DualRole/Simple/device_info/device_info.ino

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,8 @@
6262
#include "Adafruit_TinyUSB.h"
6363

6464
#if defined(CFG_TUH_MAX3421) && CFG_TUH_MAX3421
65-
6665
#include "SPI.h"
67-
68-
// USB Host object using MAX3421E: SPI, CS, INT
66+
// USB Host using MAX3421E: SPI, CS, INT
6967
Adafruit_USBH_Host USBHost(&SPI, 10, 9);
7068
#else
7169
Adafruit_USBH_Host USBHost;
@@ -93,7 +91,7 @@ void setup() {
9391
// init host stack on controller (rhport) 1
9492
USBHost.begin(1);
9593

96-
while ( !Serial ) delay(10); // wait for native usb
94+
// while ( !Serial ) delay(10); // wait for native usb
9795
Serial.println("TinyUSB Dual Device Info Example");
9896
}
9997

src/arduino/Adafruit_USBH_Host.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,14 @@ void tuh_max3421_int_api(uint8_t rhport, bool enabled) {
199199
NVIC_DisableIRQ(EIC_IRQn);
200200
}
201201
#endif
202+
203+
#elif defined(ARDUINO_NRF52_ADAFRUIT)
204+
if (enabled) {
205+
NVIC_EnableIRQ(GPIOTE_IRQn);
206+
} else {
207+
NVIC_DisableIRQ(GPIOTE_IRQn);
208+
}
209+
202210
#endif
203211
}
204212
}

src/arduino/ports/nrf/Adafruit_TinyUSB_nrf.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ static void usb_device_task(void *param) {
6868
// 2 is highest for application
6969
NVIC_SetPriority(USBD_IRQn, 2);
7070

71-
tusb_init();
71+
// init device on rhport0
72+
tud_init(0);
7273

7374
usb_hardware_init();
7475

src/arduino/ports/nrf/tusb_config_nrf.h

Lines changed: 57 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,6 @@ extern "C" {
3434
//--------------------------------------------------------------------
3535
#define CFG_TUSB_MCU OPT_MCU_NRF5X
3636

37-
#ifdef USE_TINYUSB
38-
#define CFG_TUSB_RHPORT0_MODE OPT_MODE_DEVICE
39-
#else
40-
#define CFG_TUSB_RHPORT0_MODE OPT_MODE_NONE
41-
#endif
42-
4337
#define CFG_TUSB_OS OPT_OS_FREERTOS
4438
#define CFG_TUSB_MEM_SECTION
4539
#define CFG_TUSB_MEM_ALIGN __attribute__((aligned(4)))
@@ -48,6 +42,19 @@ extern "C" {
4842
#define CFG_TUSB_DEBUG 0
4943
#endif
5044

45+
#ifdef USE_TINYUSB
46+
// Enable device stack
47+
#define CFG_TUD_ENABLED 1
48+
49+
// Enable host stack with MAX3421E (host shield)
50+
#define CFG_TUH_ENABLED 1
51+
#define CFG_TUH_MAX3421 1
52+
53+
#else
54+
#define CFG_TUD_ENABLED 0
55+
#define CFG_TUH_ENABLED 0
56+
#endif
57+
5158
//--------------------------------------------------------------------
5259
// DEVICE CONFIGURATION
5360
//--------------------------------------------------------------------
@@ -79,10 +86,54 @@ extern "C" {
7986
#ifndef CFG_TUD_VENDOR_RX_BUFSIZE
8087
#define CFG_TUD_VENDOR_RX_BUFSIZE 64
8188
#endif
89+
8290
#ifndef CFG_TUD_VENDOR_TX_BUFSIZE
8391
#define CFG_TUD_VENDOR_TX_BUFSIZE 64
8492
#endif
8593

94+
//--------------------------------------------------------------------
95+
// Host Configuration
96+
//--------------------------------------------------------------------
97+
98+
// Size of buffer to hold descriptors and other data used for enumeration
99+
#define CFG_TUH_ENUMERATION_BUFSIZE 256
100+
101+
// Number of hub devices
102+
#define CFG_TUH_HUB 1
103+
104+
// max device support (excluding hub device): 1 hub typically has 4 ports
105+
#define CFG_TUH_DEVICE_MAX (3 * CFG_TUH_HUB + 1)
106+
107+
// Enable tuh_edpt_xfer() API
108+
// #define CFG_TUH_API_EDPT_XFER 1
109+
110+
// Number of mass storage
111+
#define CFG_TUH_MSC 1
112+
113+
// Number of HIDs
114+
// typical keyboard + mouse device can have 3,4 HID interfaces
115+
#define CFG_TUH_HID (3 * CFG_TUH_DEVICE_MAX)
116+
117+
// Number of CDC interfaces
118+
// FTDI and CP210x are not part of CDC class, only to re-use CDC driver API
119+
#define CFG_TUH_CDC 1
120+
#define CFG_TUH_CDC_FTDI 1
121+
#define CFG_TUH_CDC_CP210X 1
122+
123+
// RX & TX fifo size
124+
#define CFG_TUH_CDC_RX_BUFSIZE 64
125+
#define CFG_TUH_CDC_TX_BUFSIZE 64
126+
127+
// Set Line Control state on enumeration/mounted:
128+
// DTR ( bit 0), RTS (bit 1)
129+
#define CFG_TUH_CDC_LINE_CONTROL_ON_ENUM 0x03
130+
131+
// Set Line Coding on enumeration/mounted, value for cdc_line_coding_t
132+
// bit rate = 115200, 1 stop bit, no parity, 8 bit data width
133+
// This need Pico-PIO-USB at least 0.5.1
134+
#define CFG_TUH_CDC_LINE_CODING_ON_ENUM \
135+
{ 115200, CDC_LINE_CONDING_STOP_BITS_1, CDC_LINE_CODING_PARITY_NONE, 8 }
136+
86137
#ifdef __cplusplus
87138
}
88139
#endif

src/portable/analog/max3421/hcd_max3421.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,8 +428,8 @@ bool hcd_init(uint8_t rhport) {
428428
reg_write(rhport, PINCTL_ADDR, PINCTL_FDUPSPI, false);
429429

430430
// V1 is 0x01, V2 is 0x12, V3 is 0x13
431-
// uint8_t const revision = reg_read(rhport, REVISION_ADDR, false);
432-
// TU_LOG2_HEX(revision);
431+
// uint8_t const revision = reg_read(rhport, REVISION_ADDR, false);
432+
// TU_LOG2_HEX(revision);
433433

434434
// reset
435435
reg_write(rhport, USBCTL_ADDR, USBCTL_CHIPRES, false);

0 commit comments

Comments
 (0)