Skip to content

Commit 9dde8ce

Browse files
committed
rename and wrap #ifndef to make it easier to use with feather usb host later on
1 parent 421d053 commit 9dde8ce

File tree

6 files changed

+91
-49
lines changed

6 files changed

+91
-49
lines changed

examples/DualRole/CDC/serial_host_bridge/serial_host_bridge.ino

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
2121
* Requirements:
2222
* - [Pico-PIO-USB](https://github.com/sekigon-gonnoc/Pico-PIO-USB) library
23-
* - 2 consecutive GPIOs: D+ is defined by HOST_PIN_DP (gpio20), D- = D+ +1 (gpio21)
23+
* - 2 consecutive GPIOs: D+ is defined by PIN_PIO_USB_HOST_DP, D- = D+ +1
2424
* - Provide VBus (5v) and GND for peripheral
2525
* - CPU Speed must be either 120 or 240 Mhz. Selected via "Menu -> CPU Speed"
2626
*/
@@ -32,11 +32,18 @@
3232
#include "Adafruit_TinyUSB.h"
3333

3434
// Pin D+ for host, D- = D+ + 1
35-
#define HOST_PIN_DP 20
35+
#ifndef PIN_PIO_USB_HOST_DP
36+
#define PIN_PIO_USB_HOST_DP 20
37+
#endif
3638

3739
// Pin for enabling Host VBUS. comment out if not used
38-
#define HOST_PIN_VBUS_EN 22
39-
#define HOST_PIN_VBUS_EN_STATE 1
40+
#ifndef PIN_PIO_USB_HOST_VBUSEN
41+
#define PIN_PIO_USB_HOST_VBUSEN 22
42+
#endif
43+
44+
#ifndef PIN_PIO_USB_HOST_VBUSEN_STATE
45+
#define PIN_PIO_USB_HOST_VBUSEN_STATE 1
46+
#endif
4047

4148
// USB Host object
4249
Adafruit_USBH_Host USBHost;
@@ -98,20 +105,20 @@ void setup1() {
98105
}
99106
}
100107

101-
#ifdef HOST_PIN_VBUS_EN
102-
pinMode(HOST_PIN_VBUS_EN, OUTPUT);
108+
#ifdef PIN_PIO_USB_HOST_VBUSEN
109+
pinMode(PIN_PIO_USB_HOST_VBUSEN, OUTPUT);
103110

104111
// power off first
105-
digitalWrite(HOST_PIN_VBUS_EN, 1-HOST_PIN_VBUS_EN_STATE);
112+
digitalWrite(PIN_PIO_USB_HOST_VBUSEN, 1-PIN_PIO_USB_HOST_VBUSEN_STATE);
106113
delay(1);
107114

108115
// power on
109-
digitalWrite(HOST_PIN_VBUS_EN, HOST_PIN_VBUS_EN_STATE);
116+
digitalWrite(PIN_PIO_USB_HOST_VBUSEN, PIN_PIO_USB_HOST_VBUSEN_STATE);
110117
delay(10);
111118
#endif
112119

113120
pio_usb_configuration_t pio_cfg = PIO_USB_DEFAULT_CONFIG;
114-
pio_cfg.pin_dp = HOST_PIN_DP;
121+
pio_cfg.pin_dp = PIN_PIO_USB_HOST_DP;
115122
USBHost.configure_pio_usb(1, &pio_cfg);
116123

117124
// run host stack on controller (rhport) 1

examples/DualRole/HID/hid_device_report/hid_device_report.ino

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*
1717
* Requirements:
1818
* - [Pico-PIO-USB](https://github.com/sekigon-gonnoc/Pico-PIO-USB) library
19-
* - 2 consecutive GPIOs: D+ is defined by HOST_PIN_DP (gpio20), D- = D+ +1 (gpio21)
19+
* - 2 consecutive GPIOs: D+ is defined by PIN_PIO_USB_HOST_DP, D- = D+ +1
2020
* - Provide VBus (5v) and GND for peripheral
2121
* - CPU Speed must be either 120 or 240 Mhz. Selected via "Menu -> CPU Speed"
2222
*/
@@ -26,11 +26,18 @@
2626
#include "Adafruit_TinyUSB.h"
2727

2828
// Pin D+ for host, D- = D+ + 1
29-
#define HOST_PIN_DP 20
29+
#ifndef PIN_PIO_USB_HOST_DP
30+
#define PIN_PIO_USB_HOST_DP 20
31+
#endif
3032

3133
// Pin for enabling Host VBUS. comment out if not used
32-
#define HOST_PIN_VBUS_EN 22
33-
#define HOST_PIN_VBUS_EN_STATE 1
34+
#ifndef PIN_PIO_USB_HOST_VBUSEN
35+
#define PIN_PIO_USB_HOST_VBUSEN 22
36+
#endif
37+
38+
#ifndef PIN_PIO_USB_HOST_VBUSEN_STATE
39+
#define PIN_PIO_USB_HOST_VBUSEN_STATE 1
40+
#endif
3441

3542
// Language ID: English
3643
#define LANGUAGE_ID 0x0409
@@ -73,13 +80,13 @@ void setup1() {
7380
while(1) delay(1);
7481
}
7582

76-
#ifdef HOST_PIN_VBUS_EN
77-
pinMode(HOST_PIN_VBUS_EN, OUTPUT);
78-
digitalWrite(HOST_PIN_VBUS_EN, HOST_PIN_VBUS_EN_STATE);
83+
#ifdef PIN_PIO_USB_HOST_VBUSEN
84+
pinMode(PIN_PIO_USB_HOST_VBUSEN, OUTPUT);
85+
digitalWrite(PIN_PIO_USB_HOST_VBUSEN, PIN_PIO_USB_HOST_VBUSEN_STATE);
7986
#endif
8087

8188
pio_usb_configuration_t pio_cfg = PIO_USB_DEFAULT_CONFIG;
82-
pio_cfg.pin_dp = HOST_PIN_DP;
89+
pio_cfg.pin_dp = PIN_PIO_USB_HOST_DP;
8390
USBHost.configure_pio_usb(1, &pio_cfg);
8491

8592
// run host stack on controller (rhport) 1

examples/DualRole/HID/hid_remapper/hid_remapper.ino

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
*
2323
* Requirements:
2424
* - [Pico-PIO-USB](https://github.com/sekigon-gonnoc/Pico-PIO-USB) library
25-
* - 2 consecutive GPIOs: D+ is defined by HOST_PIN_DP (gpio20), D- = D+ +1 (gpio21)
25+
* - 2 consecutive GPIOs: D+ is defined by PIN_PIO_USB_HOST_DP, D- = D+ +1
2626
* - Provide VBus (5v) and GND for peripheral
2727
* - CPU Speed must be either 120 or 240 Mhz. Selected via "Menu -> CPU Speed"
2828
*/
@@ -32,11 +32,18 @@
3232
#include "Adafruit_TinyUSB.h"
3333

3434
// Pin D+ for host, D- = D+ + 1
35-
#define HOST_PIN_DP 20
35+
#ifndef PIN_PIO_USB_HOST_DP
36+
#define PIN_PIO_USB_HOST_DP 20
37+
#endif
3638

3739
// Pin for enabling Host VBUS. comment out if not used
38-
#define HOST_PIN_VBUS_EN 22
39-
#define HOST_PIN_VBUS_EN_STATE 1
40+
#ifndef PIN_PIO_USB_HOST_VBUSEN
41+
#define PIN_PIO_USB_HOST_VBUSEN 22
42+
#endif
43+
44+
#ifndef PIN_PIO_USB_HOST_VBUSEN_STATE
45+
#define PIN_PIO_USB_HOST_VBUSEN_STATE 1
46+
#endif
4047

4148
// Language ID: English
4249
#define LANGUAGE_ID 0x0409
@@ -91,13 +98,13 @@ void setup1() {
9198
while(1) delay(1);
9299
}
93100

94-
#ifdef HOST_PIN_VBUS_EN
95-
pinMode(HOST_PIN_VBUS_EN, OUTPUT);
96-
digitalWrite(HOST_PIN_VBUS_EN, HOST_PIN_VBUS_EN_STATE);
101+
#ifdef PIN_PIO_USB_HOST_VBUSEN
102+
pinMode(PIN_PIO_USB_HOST_VBUSEN, OUTPUT);
103+
digitalWrite(PIN_PIO_USB_HOST_VBUSEN, PIN_PIO_USB_HOST_VBUSEN_STATE);
97104
#endif
98105

99106
pio_usb_configuration_t pio_cfg = PIO_USB_DEFAULT_CONFIG;
100-
pio_cfg.pin_dp = HOST_PIN_DP;
107+
pio_cfg.pin_dp = PIN_PIO_USB_HOST_DP;
101108
USBHost.configure_pio_usb(1, &pio_cfg);
102109

103110
// run host stack on controller (rhport) 1

examples/DualRole/MassStorage/msc_data_logger/msc_data_logger.ino

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*
1919
* Requirements:
2020
* - [Pico-PIO-USB](https://github.com/sekigon-gonnoc/Pico-PIO-USB) library
21-
* - 2 consecutive GPIOs: D+ is defined by HOST_PIN_DP (gpio20), D- = D+ +1 (gpio21)
21+
* - 2 consecutive GPIOs: D+ is defined by PIN_PIO_USB_HOST_DP, D- = D+ +1
2222
* - Provide VBus (5v) and GND for peripheral
2323
* - CPU Speed must be either 120 or 240 Mhz. Selected via "Menu -> CPU Speed"
2424
*/
@@ -33,11 +33,18 @@
3333
#include "Adafruit_TinyUSB.h"
3434

3535
// Pin D+ for host, D- = D+ + 1
36-
#define HOST_PIN_DP 20
36+
#ifndef PIN_PIO_USB_HOST_DP
37+
#define PIN_PIO_USB_HOST_DP 20
38+
#endif
3739

3840
// Pin for enabling Host VBUS. comment out if not used
39-
#define HOST_PIN_VBUS_EN 22
40-
#define HOST_PIN_VBUS_EN_STATE 1
41+
#ifndef PIN_PIO_USB_HOST_VBUSEN
42+
#define PIN_PIO_USB_HOST_VBUSEN 22
43+
#endif
44+
45+
#ifndef PIN_PIO_USB_HOST_VBUSEN_STATE
46+
#define PIN_PIO_USB_HOST_VBUSEN_STATE 1
47+
#endif
4148

4249

4350
#define LOG_FILE "cpu_temp.csv"
@@ -119,13 +126,13 @@ void setup1() {
119126
}
120127
}
121128

122-
#ifdef HOST_PIN_VBUS_EN
123-
pinMode(HOST_PIN_VBUS_EN, OUTPUT);
124-
digitalWrite(HOST_PIN_VBUS_EN, HOST_PIN_VBUS_EN_STATE);
129+
#ifdef PIN_PIO_USB_HOST_VBUSEN
130+
pinMode(PIN_PIO_USB_HOST_VBUSEN, OUTPUT);
131+
digitalWrite(PIN_PIO_USB_HOST_VBUSEN, PIN_PIO_USB_HOST_VBUSEN_STATE);
125132
#endif
126133

127134
pio_usb_configuration_t pio_cfg = PIO_USB_DEFAULT_CONFIG;
128-
pio_cfg.pin_dp = HOST_PIN_DP;
135+
pio_cfg.pin_dp = PIN_PIO_USB_HOST_DP;
129136
USBHost.configure_pio_usb(1, &pio_cfg);
130137

131138
// run host stack on controller (rhport) 1

examples/DualRole/MassStorage/msc_file_explorer/msc_file_explorer.ino

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*
1717
* Requirements:
1818
* - [Pico-PIO-USB](https://github.com/sekigon-gonnoc/Pico-PIO-USB) library
19-
* - 2 consecutive GPIOs: D+ is defined by HOST_PIN_DP (gpio20), D- = D+ +1 (gpio21)
19+
* - 2 consecutive GPIOs: D+ is defined by PIN_PIO_USB_HOST_DP, D- = D+ +1
2020
* - Provide VBus (5v) and GND for peripheral
2121
* - CPU Speed must be either 120 or 240 Mhz. Selected via "Menu -> CPU Speed"
2222
*/
@@ -31,11 +31,18 @@
3131
#include "Adafruit_TinyUSB.h"
3232

3333
// Pin D+ for host, D- = D+ + 1
34-
#define HOST_PIN_DP 20
34+
#ifndef PIN_PIO_USB_HOST_DP
35+
#define PIN_PIO_USB_HOST_DP 20
36+
#endif
3537

3638
// Pin for enabling Host VBUS. comment out if not used
37-
#define HOST_PIN_VBUS_EN 22
38-
#define HOST_PIN_VBUS_EN_STATE 1
39+
#ifndef PIN_PIO_USB_HOST_VBUSEN
40+
#define PIN_PIO_USB_HOST_VBUSEN 22
41+
#endif
42+
43+
#ifndef PIN_PIO_USB_HOST_VBUSEN_STATE
44+
#define PIN_PIO_USB_HOST_VBUSEN_STATE 1
45+
#endif
3946

4047
// USB Host object
4148
Adafruit_USBH_Host USBHost;
@@ -86,13 +93,13 @@ void setup1() {
8693
}
8794
}
8895

89-
#ifdef HOST_PIN_VBUS_EN
90-
pinMode(HOST_PIN_VBUS_EN, OUTPUT);
91-
digitalWrite(HOST_PIN_VBUS_EN, HOST_PIN_VBUS_EN_STATE);
96+
#ifdef PIN_PIO_USB_HOST_VBUSEN
97+
pinMode(PIN_PIO_USB_HOST_VBUSEN, OUTPUT);
98+
digitalWrite(PIN_PIO_USB_HOST_VBUSEN, PIN_PIO_USB_HOST_VBUSEN_STATE);
9299
#endif
93100

94101
pio_usb_configuration_t pio_cfg = PIO_USB_DEFAULT_CONFIG;
95-
pio_cfg.pin_dp = HOST_PIN_DP;
102+
pio_cfg.pin_dp = PIN_PIO_USB_HOST_DP;
96103
USBHost.configure_pio_usb(1, &pio_cfg);
97104

98105
// run host stack on controller (rhport) 1

examples/DualRole/device_info_rp2040/device_info_rp2040.ino

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*
1717
* Requirements:
1818
* - [Pico-PIO-USB](https://github.com/sekigon-gonnoc/Pico-PIO-USB) library
19-
* - 2 consecutive GPIOs: D+ is defined by HOST_PIN_DP (gpio20), D- = D+ +1 (gpio21)
19+
* - 2 consecutive GPIOs: D+ is defined by PIN_PIO_USB_HOST_DP, D- = D+ +1
2020
* - Provide VBus (5v) and GND for peripheral
2121
* - CPU Speed must be either 120 or 240 Mhz. Selected via "Menu -> CPU Speed"
2222
*
@@ -46,11 +46,18 @@
4646
#include "Adafruit_TinyUSB.h"
4747

4848
// Pin D+ for host, D- = D+ + 1
49-
#define HOST_PIN_DP 20
49+
#ifndef PIN_PIO_USB_HOST_DP
50+
#define PIN_PIO_USB_HOST_DP 20
51+
#endif
5052

5153
// Pin for enabling Host VBUS. comment out if not used
52-
#define HOST_PIN_VBUS_EN 22
53-
#define HOST_PIN_VBUS_EN_STATE 1
54+
#ifndef PIN_PIO_USB_HOST_VBUSEN
55+
#define PIN_PIO_USB_HOST_VBUSEN 22
56+
#endif
57+
58+
#ifndef PIN_PIO_USB_HOST_VBUSEN_STATE
59+
#define PIN_PIO_USB_HOST_VBUSEN_STATE 1
60+
#endif
5461

5562
// Language ID: English
5663
#define LANGUAGE_ID 0x0409
@@ -101,13 +108,13 @@ void setup1() {
101108
}
102109
}
103110

104-
#ifdef HOST_PIN_VBUS_EN
105-
pinMode(HOST_PIN_VBUS_EN, OUTPUT);
106-
digitalWrite(HOST_PIN_VBUS_EN, HOST_PIN_VBUS_EN_STATE);
111+
#ifdef PIN_PIO_USB_HOST_VBUSEN
112+
pinMode(PIN_PIO_USB_HOST_VBUSEN, OUTPUT);
113+
digitalWrite(PIN_PIO_USB_HOST_VBUSEN, PIN_PIO_USB_HOST_VBUSEN_STATE);
107114
#endif
108115

109116
pio_usb_configuration_t pio_cfg = PIO_USB_DEFAULT_CONFIG;
110-
pio_cfg.pin_dp = HOST_PIN_DP;
117+
pio_cfg.pin_dp = PIN_PIO_USB_HOST_DP;
111118
USBHost.configure_pio_usb(1, &pio_cfg);
112119

113120
// run host stack on controller (rhport) 1

0 commit comments

Comments
 (0)