16
16
*
17
17
* Requirements:
18
18
* - [Pico-PIO-USB](https://github.com/sekigon-gonnoc/Pico-PIO-USB) library
19
- * - 2 consecutive GPIOs: D+ is defined by HOST_PIN_DP (gpio2 ), D- = D+ +1 (gpio3 )
19
+ * - 2 consecutive GPIOs: D+ is defined by HOST_PIN_DP (gpio20 ), D- = D+ +1 (gpio21 )
20
20
* - Provide VBus (5v) and GND for peripheral
21
21
* - CPU Speed must be either 120 or 240 Mhz. Selected via "Menu -> CPU Speed"
22
22
*
43
43
44
44
// pio-usb is required for rp2040 host
45
45
#include " pio_usb.h"
46
- #define HOST_PIN_DP 2 // Pin used as D+ for host, D- = D+ + 1
47
-
48
46
#include " Adafruit_TinyUSB.h"
49
47
50
- #define LANGUAGE_ID 0x0409 // English
48
+ // Pin D+ for host, D- = D+ + 1
49
+ #define HOST_PIN_DP 20
50
+
51
+ // 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
+
55
+ // Language ID: English
56
+ #define LANGUAGE_ID 0x0409
51
57
52
58
// USB Host object
53
59
Adafruit_USBH_Host USBHost;
54
60
55
61
// holding device descriptor
56
62
tusb_desc_device_t desc_device;
57
63
64
+ // --------------------------------------------------------------------+
65
+ // Setup and Loop on Core0
66
+ // --------------------------------------------------------------------+
67
+
58
68
// the setup function runs once when you press reset or power the board
59
69
void setup ()
60
70
{
@@ -70,20 +80,32 @@ void loop()
70
80
{
71
81
}
72
82
73
- // core1's setup
83
+ // --------------------------------------------------------------------+
84
+ // Setup and Loop on Core1
85
+ // --------------------------------------------------------------------+
86
+
74
87
void setup1 () {
75
88
// while ( !Serial ) delay(10); // wait for native usb
76
89
Serial.println (" Core1 setup to run TinyUSB host with pio-usb" );
77
90
78
91
// Check for CPU frequency, must be multiple of 120Mhz for bit-banging USB
79
92
uint32_t cpu_hz = clock_get_hz (clk_sys);
80
93
if ( cpu_hz != 120000000UL && cpu_hz != 240000000UL ) {
81
- while ( !Serial ) delay (10 ); // wait for native usb
94
+ while ( !Serial ) {
95
+ delay (10 ); // wait for native usb
96
+ }
82
97
Serial.printf (" Error: CPU Clock = %u, PIO USB require CPU clock must be multiple of 120 Mhz\r\n " , cpu_hz);
83
98
Serial.printf (" Change your CPU Clock to either 120 or 240 Mhz in Menu->CPU Speed \r\n " , cpu_hz);
84
- while (1 ) delay (1 );
99
+ while (1 ) {
100
+ delay (1 );
101
+ }
85
102
}
86
103
104
+ #ifdef HOST_PIN_VBUS_EN
105
+ pinMode (HOST_PIN_VBUS_EN, OUTPUT);
106
+ digitalWrite (HOST_PIN_VBUS_EN, HOST_PIN_VBUS_EN_STATE);
107
+ #endif
108
+
87
109
pio_usb_configuration_t pio_cfg = PIO_USB_DEFAULT_CONFIG;
88
110
pio_cfg.pin_dp = HOST_PIN_DP;
89
111
USBHost.configure_pio_usb (1 , &pio_cfg);
@@ -94,7 +116,6 @@ void setup1() {
94
116
USBHost.begin (1 );
95
117
}
96
118
97
- // core1's loop
98
119
void loop1 ()
99
120
{
100
121
USBHost.task ();
0 commit comments