Skip to content

Commit 9a83b0b

Browse files
committed
change USBHost declaration with spi pin for esp32
1 parent 1c5cb1d commit 9a83b0b

File tree

12 files changed

+305
-361
lines changed

12 files changed

+305
-361
lines changed

examples/DualRole/CDC/serial_host_bridge/usbh_helper.h

Lines changed: 33 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,57 @@
1-
/*
2-
* The MIT License (MIT)
3-
*
4-
* Copyright (c) 2023 Ha Thach (tinyusb.org)
5-
*
6-
* Permission is hereby granted, free of charge, to any person obtaining a copy
7-
* of this software and associated documentation files (the "Software"), to deal
8-
* in the Software without restriction, including without limitation the rights
9-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10-
* copies of the Software, and to permit persons to whom the Software is
11-
* furnished to do so, subject to the following conditions:
12-
*
13-
* The above copyright notice and this permission notice shall be included in
14-
* all copies or substantial portions of the Software.
15-
*
16-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22-
* THE SOFTWARE.
23-
*
24-
* This file is part of the TinyUSB stack.
25-
*/
1+
/*********************************************************************
2+
Adafruit invests time and resources providing this open source code,
3+
please support Adafruit and open-source hardware by purchasing
4+
products from Adafruit!
5+
6+
MIT license, check LICENSE for more information
7+
Copyright (c) 2019 Ha Thach for Adafruit Industries
8+
All text above, and the splash screen below must be included in
9+
any redistribution
10+
*********************************************************************/
2611

2712
#ifndef USBH_HELPER_H
2813
#define USBH_HELPER_H
2914

3015
#ifdef ARDUINO_ARCH_RP2040
31-
// pio-usb is required for rp2040 host
32-
#include "pio_usb.h"
16+
// pio-usb is required for rp2040 host
17+
#include "pio_usb.h"
3318

34-
// Pin D+ for host, D- = D+ + 1
35-
#ifndef PIN_USB_HOST_DP
36-
#define PIN_USB_HOST_DP 16
37-
#endif
19+
// Pin D+ for host, D- = D+ + 1
20+
#ifndef PIN_USB_HOST_DP
21+
#define PIN_USB_HOST_DP 16
22+
#endif
3823

39-
// Pin for enabling Host VBUS. comment out if not used
40-
#ifndef PIN_5V_EN
41-
#define PIN_5V_EN 18
42-
#endif
24+
// Pin for enabling Host VBUS. comment out if not used
25+
#ifndef PIN_5V_EN
26+
#define PIN_5V_EN 18
27+
#endif
4328

44-
#ifndef PIN_5V_EN_STATE
45-
#define PIN_5V_EN_STATE 1
46-
#endif
29+
#ifndef PIN_5V_EN_STATE
30+
#define PIN_5V_EN_STATE 1
31+
#endif
4732
#endif // ARDUINO_ARCH_RP2040
4833

4934
#include "Adafruit_TinyUSB.h"
5035

5136
#if defined(CFG_TUH_MAX3421) && CFG_TUH_MAX3421
37+
// USB Host using MAX3421E: SPI, CS, INT
5238
#include "SPI.h"
5339

54-
#ifdef ARDUINO_ARCH_ESP32
55-
// ESP32 specify SCK, MOSI, MISO, CS, INT
56-
Adafruit_USBH_Host USBHost(36, 35, 37, 15, 14);
40+
#if defined(ARDUINO_METRO_ESP32S2)
41+
Adafruit_USBH_Host USBHost(&SPI, 15, 14);
5742
#else
58-
// USB Host using MAX3421E: SPI, CS, INT
59-
Adafruit_USBH_Host USBHost(&SPI, 10, 9);
43+
// Default use SPI and pin 10, 9 for CS and INT
44+
Adafruit_USBH_Host USBHost(&SPI, 10, 9);
6045
#endif
6146
#else
47+
// Native USB Host such as rp2040
6248
Adafruit_USBH_Host USBHost;
6349
#endif
6450

51+
//--------------------------------------------------------------------+
52+
// Helper Functions
53+
//--------------------------------------------------------------------+
54+
6555
#ifdef ARDUINO_ARCH_RP2040
6656
static void rp2040_configure_pio_usb(void) {
6757
//while ( !Serial ) delay(10); // wait for native usb

examples/DualRole/HID/hid_device_report/usbh_helper.h

Lines changed: 33 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,57 @@
1-
/*
2-
* The MIT License (MIT)
3-
*
4-
* Copyright (c) 2023 Ha Thach (tinyusb.org)
5-
*
6-
* Permission is hereby granted, free of charge, to any person obtaining a copy
7-
* of this software and associated documentation files (the "Software"), to deal
8-
* in the Software without restriction, including without limitation the rights
9-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10-
* copies of the Software, and to permit persons to whom the Software is
11-
* furnished to do so, subject to the following conditions:
12-
*
13-
* The above copyright notice and this permission notice shall be included in
14-
* all copies or substantial portions of the Software.
15-
*
16-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22-
* THE SOFTWARE.
23-
*
24-
* This file is part of the TinyUSB stack.
25-
*/
1+
/*********************************************************************
2+
Adafruit invests time and resources providing this open source code,
3+
please support Adafruit and open-source hardware by purchasing
4+
products from Adafruit!
5+
6+
MIT license, check LICENSE for more information
7+
Copyright (c) 2019 Ha Thach for Adafruit Industries
8+
All text above, and the splash screen below must be included in
9+
any redistribution
10+
*********************************************************************/
2611

2712
#ifndef USBH_HELPER_H
2813
#define USBH_HELPER_H
2914

3015
#ifdef ARDUINO_ARCH_RP2040
31-
// pio-usb is required for rp2040 host
32-
#include "pio_usb.h"
16+
// pio-usb is required for rp2040 host
17+
#include "pio_usb.h"
3318

34-
// Pin D+ for host, D- = D+ + 1
35-
#ifndef PIN_USB_HOST_DP
36-
#define PIN_USB_HOST_DP 16
37-
#endif
19+
// Pin D+ for host, D- = D+ + 1
20+
#ifndef PIN_USB_HOST_DP
21+
#define PIN_USB_HOST_DP 16
22+
#endif
3823

39-
// Pin for enabling Host VBUS. comment out if not used
40-
#ifndef PIN_5V_EN
41-
#define PIN_5V_EN 18
42-
#endif
24+
// Pin for enabling Host VBUS. comment out if not used
25+
#ifndef PIN_5V_EN
26+
#define PIN_5V_EN 18
27+
#endif
4328

44-
#ifndef PIN_5V_EN_STATE
45-
#define PIN_5V_EN_STATE 1
46-
#endif
29+
#ifndef PIN_5V_EN_STATE
30+
#define PIN_5V_EN_STATE 1
31+
#endif
4732
#endif // ARDUINO_ARCH_RP2040
4833

4934
#include "Adafruit_TinyUSB.h"
5035

5136
#if defined(CFG_TUH_MAX3421) && CFG_TUH_MAX3421
37+
// USB Host using MAX3421E: SPI, CS, INT
5238
#include "SPI.h"
5339

54-
#ifdef ARDUINO_ARCH_ESP32
55-
// ESP32 specify SCK, MOSI, MISO, CS, INT
56-
Adafruit_USBH_Host USBHost(36, 35, 37, 15, 14);
40+
#if defined(ARDUINO_METRO_ESP32S2)
41+
Adafruit_USBH_Host USBHost(&SPI, 15, 14);
5742
#else
58-
// USB Host using MAX3421E: SPI, CS, INT
59-
Adafruit_USBH_Host USBHost(&SPI, 10, 9);
43+
// Default use SPI and pin 10, 9 for CS and INT
44+
Adafruit_USBH_Host USBHost(&SPI, 10, 9);
6045
#endif
6146
#else
47+
// Native USB Host such as rp2040
6248
Adafruit_USBH_Host USBHost;
6349
#endif
6450

51+
//--------------------------------------------------------------------+
52+
// Helper Functions
53+
//--------------------------------------------------------------------+
54+
6555
#ifdef ARDUINO_ARCH_RP2040
6656
static void rp2040_configure_pio_usb(void) {
6757
//while ( !Serial ) delay(10); // wait for native usb

examples/DualRole/HID/hid_mouse_log_filter/usbh_helper.h

Lines changed: 33 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,57 @@
1-
/*
2-
* The MIT License (MIT)
3-
*
4-
* Copyright (c) 2023 Ha Thach (tinyusb.org)
5-
*
6-
* Permission is hereby granted, free of charge, to any person obtaining a copy
7-
* of this software and associated documentation files (the "Software"), to deal
8-
* in the Software without restriction, including without limitation the rights
9-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10-
* copies of the Software, and to permit persons to whom the Software is
11-
* furnished to do so, subject to the following conditions:
12-
*
13-
* The above copyright notice and this permission notice shall be included in
14-
* all copies or substantial portions of the Software.
15-
*
16-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22-
* THE SOFTWARE.
23-
*
24-
* This file is part of the TinyUSB stack.
25-
*/
1+
/*********************************************************************
2+
Adafruit invests time and resources providing this open source code,
3+
please support Adafruit and open-source hardware by purchasing
4+
products from Adafruit!
5+
6+
MIT license, check LICENSE for more information
7+
Copyright (c) 2019 Ha Thach for Adafruit Industries
8+
All text above, and the splash screen below must be included in
9+
any redistribution
10+
*********************************************************************/
2611

2712
#ifndef USBH_HELPER_H
2813
#define USBH_HELPER_H
2914

3015
#ifdef ARDUINO_ARCH_RP2040
31-
// pio-usb is required for rp2040 host
32-
#include "pio_usb.h"
16+
// pio-usb is required for rp2040 host
17+
#include "pio_usb.h"
3318

34-
// Pin D+ for host, D- = D+ + 1
35-
#ifndef PIN_USB_HOST_DP
36-
#define PIN_USB_HOST_DP 16
37-
#endif
19+
// Pin D+ for host, D- = D+ + 1
20+
#ifndef PIN_USB_HOST_DP
21+
#define PIN_USB_HOST_DP 16
22+
#endif
3823

39-
// Pin for enabling Host VBUS. comment out if not used
40-
#ifndef PIN_5V_EN
41-
#define PIN_5V_EN 18
42-
#endif
24+
// Pin for enabling Host VBUS. comment out if not used
25+
#ifndef PIN_5V_EN
26+
#define PIN_5V_EN 18
27+
#endif
4328

44-
#ifndef PIN_5V_EN_STATE
45-
#define PIN_5V_EN_STATE 1
46-
#endif
29+
#ifndef PIN_5V_EN_STATE
30+
#define PIN_5V_EN_STATE 1
31+
#endif
4732
#endif // ARDUINO_ARCH_RP2040
4833

4934
#include "Adafruit_TinyUSB.h"
5035

5136
#if defined(CFG_TUH_MAX3421) && CFG_TUH_MAX3421
37+
// USB Host using MAX3421E: SPI, CS, INT
5238
#include "SPI.h"
5339

54-
#ifdef ARDUINO_ARCH_ESP32
55-
// ESP32 specify SCK, MOSI, MISO, CS, INT
56-
Adafruit_USBH_Host USBHost(36, 35, 37, 15, 14);
40+
#if defined(ARDUINO_METRO_ESP32S2)
41+
Adafruit_USBH_Host USBHost(&SPI, 15, 14);
5742
#else
58-
// USB Host using MAX3421E: SPI, CS, INT
59-
Adafruit_USBH_Host USBHost(&SPI, 10, 9);
43+
// Default use SPI and pin 10, 9 for CS and INT
44+
Adafruit_USBH_Host USBHost(&SPI, 10, 9);
6045
#endif
6146
#else
47+
// Native USB Host such as rp2040
6248
Adafruit_USBH_Host USBHost;
6349
#endif
6450

51+
//--------------------------------------------------------------------+
52+
// Helper Functions
53+
//--------------------------------------------------------------------+
54+
6555
#ifdef ARDUINO_ARCH_RP2040
6656
static void rp2040_configure_pio_usb(void) {
6757
//while ( !Serial ) delay(10); // wait for native usb

0 commit comments

Comments
 (0)