-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #334 from adafruit/add-max3421e-support
Support max3421e (usb host shield) for nrf52 and samd21/samd51
- Loading branch information
Showing
52 changed files
with
1,645 additions
and
776 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
/.development | ||
.idea | ||
platformio.ini | ||
.pio/ |
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2023 Ha Thach (tinyusb.org) | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
* | ||
* This file is part of the TinyUSB stack. | ||
*/ | ||
|
||
#ifndef USBH_HELPER_H | ||
#define USBH_HELPER_H | ||
|
||
#ifdef ARDUINO_ARCH_RP2040 | ||
// pio-usb is required for rp2040 host | ||
#include "pio_usb.h" | ||
|
||
// Pin D+ for host, D- = D+ + 1 | ||
#ifndef PIN_USB_HOST_DP | ||
#define PIN_USB_HOST_DP 16 | ||
#endif | ||
|
||
// Pin for enabling Host VBUS. comment out if not used | ||
#ifndef PIN_5V_EN | ||
#define PIN_5V_EN 18 | ||
#endif | ||
|
||
#ifndef PIN_5V_EN_STATE | ||
#define PIN_5V_EN_STATE 1 | ||
#endif | ||
#endif // ARDUINO_ARCH_RP2040 | ||
|
||
#include "Adafruit_TinyUSB.h" | ||
|
||
#if defined(CFG_TUH_MAX3421) && CFG_TUH_MAX3421 | ||
#include "SPI.h" | ||
// USB Host using MAX3421E: SPI, CS, INT | ||
Adafruit_USBH_Host USBHost(&SPI, 10, 9); | ||
#else | ||
Adafruit_USBH_Host USBHost; | ||
#endif | ||
|
||
#ifdef ARDUINO_ARCH_RP2040 | ||
static void rp2040_configure_pio_usb(void) { | ||
//while ( !Serial ) delay(10); // wait for native usb | ||
Serial.println("Core1 setup to run TinyUSB host with pio-usb"); | ||
|
||
// Check for CPU frequency, must be multiple of 120Mhz for bit-banging USB | ||
uint32_t cpu_hz = clock_get_hz(clk_sys); | ||
if (cpu_hz != 120000000UL && cpu_hz != 240000000UL) { | ||
while (!Serial) { | ||
delay(10); // wait for native usb | ||
} | ||
Serial.printf("Error: CPU Clock = %lu, PIO USB require CPU clock must be multiple of 120 Mhz\r\n", cpu_hz); | ||
Serial.printf("Change your CPU Clock to either 120 or 240 Mhz in Menu->CPU Speed \r\n"); | ||
while (1) { | ||
delay(1); | ||
} | ||
} | ||
|
||
#ifdef PIN_5V_EN | ||
pinMode(PIN_5V_EN, OUTPUT); | ||
digitalWrite(PIN_5V_EN, PIN_5V_EN_STATE); | ||
#endif | ||
|
||
pio_usb_configuration_t pio_cfg = PIO_USB_DEFAULT_CONFIG; | ||
pio_cfg.pin_dp = PIN_USB_HOST_DP; | ||
|
||
#if defined(ARDUINO_RASPBERRY_PI_PICO_W) | ||
// For pico-w, PIO is also used to communicate with cyw43 | ||
// Therefore we need to alternate the pio-usb configuration | ||
// details https://github.com/sekigon-gonnoc/Pico-PIO-USB/issues/46 | ||
pio_cfg.sm_tx = 3; | ||
pio_cfg.sm_rx = 2; | ||
pio_cfg.sm_eop = 3; | ||
pio_cfg.pio_rx_num = 0; | ||
pio_cfg.pio_tx_num = 1; | ||
pio_cfg.tx_ch = 9; | ||
#endif | ||
|
||
USBHost.configure_pio_usb(1, &pio_cfg); | ||
} | ||
#endif | ||
|
||
#endif |
Empty file.
Empty file.
Empty file.
Oops, something went wrong.