Skip to content

Commit

Permalink
add max3421e port for nrf52840
Browse files Browse the repository at this point in the history
  • Loading branch information
hathach committed Sep 14, 2023
1 parent 1429b5c commit 6829820
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 13 deletions.
6 changes: 2 additions & 4 deletions examples/DualRole/Simple/device_info/device_info.ino
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,8 @@
#include "Adafruit_TinyUSB.h"

#if defined(CFG_TUH_MAX3421) && CFG_TUH_MAX3421

#include "SPI.h"

// USB Host object using MAX3421E: SPI, CS, INT
// USB Host using MAX3421E: SPI, CS, INT
Adafruit_USBH_Host USBHost(&SPI, 10, 9);
#else
Adafruit_USBH_Host USBHost;
Expand Down Expand Up @@ -93,7 +91,7 @@ void setup() {
// init host stack on controller (rhport) 1
USBHost.begin(1);

while ( !Serial ) delay(10); // wait for native usb
// while ( !Serial ) delay(10); // wait for native usb
Serial.println("TinyUSB Dual Device Info Example");
}

Expand Down
8 changes: 8 additions & 0 deletions src/arduino/Adafruit_USBH_Host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,14 @@ void tuh_max3421_int_api(uint8_t rhport, bool enabled) {
NVIC_DisableIRQ(EIC_IRQn);
}
#endif

#elif defined(ARDUINO_NRF52_ADAFRUIT)
if (enabled) {
NVIC_EnableIRQ(GPIOTE_IRQn);
} else {
NVIC_DisableIRQ(GPIOTE_IRQn);
}

#endif
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/arduino/ports/nrf/Adafruit_TinyUSB_nrf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ static void usb_device_task(void *param) {
// 2 is highest for application
NVIC_SetPriority(USBD_IRQn, 2);

tusb_init();
// init device on rhport0
tud_init(0);

usb_hardware_init();

Expand Down
63 changes: 57 additions & 6 deletions src/arduino/ports/nrf/tusb_config_nrf.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,6 @@ extern "C" {
//--------------------------------------------------------------------
#define CFG_TUSB_MCU OPT_MCU_NRF5X

#ifdef USE_TINYUSB
#define CFG_TUSB_RHPORT0_MODE OPT_MODE_DEVICE
#else
#define CFG_TUSB_RHPORT0_MODE OPT_MODE_NONE
#endif

#define CFG_TUSB_OS OPT_OS_FREERTOS
#define CFG_TUSB_MEM_SECTION
#define CFG_TUSB_MEM_ALIGN __attribute__((aligned(4)))
Expand All @@ -48,6 +42,19 @@ extern "C" {
#define CFG_TUSB_DEBUG 0
#endif

#ifdef USE_TINYUSB
// Enable device stack
#define CFG_TUD_ENABLED 1

// Enable host stack with MAX3421E (host shield)
#define CFG_TUH_ENABLED 1
#define CFG_TUH_MAX3421 1

#else
#define CFG_TUD_ENABLED 0
#define CFG_TUH_ENABLED 0
#endif

//--------------------------------------------------------------------
// DEVICE CONFIGURATION
//--------------------------------------------------------------------
Expand Down Expand Up @@ -79,10 +86,54 @@ extern "C" {
#ifndef CFG_TUD_VENDOR_RX_BUFSIZE
#define CFG_TUD_VENDOR_RX_BUFSIZE 64
#endif

#ifndef CFG_TUD_VENDOR_TX_BUFSIZE
#define CFG_TUD_VENDOR_TX_BUFSIZE 64
#endif

//--------------------------------------------------------------------
// Host Configuration
//--------------------------------------------------------------------

// Size of buffer to hold descriptors and other data used for enumeration
#define CFG_TUH_ENUMERATION_BUFSIZE 256

// Number of hub devices
#define CFG_TUH_HUB 1

// max device support (excluding hub device): 1 hub typically has 4 ports
#define CFG_TUH_DEVICE_MAX (3 * CFG_TUH_HUB + 1)

// Enable tuh_edpt_xfer() API
// #define CFG_TUH_API_EDPT_XFER 1

// Number of mass storage
#define CFG_TUH_MSC 1

// Number of HIDs
// typical keyboard + mouse device can have 3,4 HID interfaces
#define CFG_TUH_HID (3 * CFG_TUH_DEVICE_MAX)

// Number of CDC interfaces
// FTDI and CP210x are not part of CDC class, only to re-use CDC driver API
#define CFG_TUH_CDC 1
#define CFG_TUH_CDC_FTDI 1
#define CFG_TUH_CDC_CP210X 1

// RX & TX fifo size
#define CFG_TUH_CDC_RX_BUFSIZE 64
#define CFG_TUH_CDC_TX_BUFSIZE 64

// Set Line Control state on enumeration/mounted:
// DTR ( bit 0), RTS (bit 1)
#define CFG_TUH_CDC_LINE_CONTROL_ON_ENUM 0x03

// Set Line Coding on enumeration/mounted, value for cdc_line_coding_t
// bit rate = 115200, 1 stop bit, no parity, 8 bit data width
// This need Pico-PIO-USB at least 0.5.1
#define CFG_TUH_CDC_LINE_CODING_ON_ENUM \
{ 115200, CDC_LINE_CONDING_STOP_BITS_1, CDC_LINE_CODING_PARITY_NONE, 8 }

#ifdef __cplusplus
}
#endif
Expand Down
4 changes: 2 additions & 2 deletions src/portable/analog/max3421/hcd_max3421.c
Original file line number Diff line number Diff line change
Expand Up @@ -428,8 +428,8 @@ bool hcd_init(uint8_t rhport) {
reg_write(rhport, PINCTL_ADDR, PINCTL_FDUPSPI, false);

// V1 is 0x01, V2 is 0x12, V3 is 0x13
// uint8_t const revision = reg_read(rhport, REVISION_ADDR, false);
// TU_LOG2_HEX(revision);
// uint8_t const revision = reg_read(rhport, REVISION_ADDR, false);
// TU_LOG2_HEX(revision);

// reset
reg_write(rhport, USBCTL_ADDR, USBCTL_CHIPRES, false);
Expand Down

0 comments on commit 6829820

Please sign in to comment.