Skip to content

Commit 32e0862

Browse files
committed
update dualrole examples to support rp2040 brain with vbus = 22 and change host dp to 20
1 parent af1451b commit 32e0862

File tree

2 files changed

+51
-37
lines changed

2 files changed

+51
-37
lines changed

examples/DualRole/HID_device_report/HID_device_report.ino

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,46 +16,32 @@
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 (gpio2), D- = D+ +1 (gpio3)
19+
* - 2 consecutive GPIOs: D+ is defined by HOST_PIN_DP (gpio20), D- = D+ +1 (gpio21)
2020
* - Provide VBus (5v) and GND for peripheral
2121
* - CPU Speed must be either 120 or 240 Mhz. Selected via "Menu -> CPU Speed"
22-
*
23-
* RP2040 host stack will get device descriptors of attached devices and print it out via
24-
* device cdc (Serial) as follows:
25-
* Device 1: ID 046d:c52f
26-
Device Descriptor:
27-
bLength 18
28-
bDescriptorType 1
29-
bcdUSB 0200
30-
bDeviceClass 0
31-
bDeviceSubClass 0
32-
bDeviceProtocol 0
33-
bMaxPacketSize0 8
34-
idVendor 0x046d
35-
idProduct 0xc52f
36-
bcdDevice 2200
37-
iManufacturer 1 Logitech
38-
iProduct 2 USB Receiver
39-
iSerialNumber 0
40-
bNumConfigurations 1
41-
*
4222
*/
4323

4424
// pio-usb is required for rp2040 host
4525
#include "pio_usb.h"
46-
#define HOST_PIN_DP 2 // Pin used as D+ for host, D- = D+ + 1
47-
4826
#include "Adafruit_TinyUSB.h"
4927

50-
#define LANGUAGE_ID 0x0409 // English
28+
// Pin D+ for host, D- = D+ + 1
29+
#define HOST_PIN_DP 20
30+
31+
// 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+
35+
// Language ID: English
36+
#define LANGUAGE_ID 0x0409
5137

5238
// USB Host object
5339
Adafruit_USBH_Host USBHost;
5440

55-
// holding device descriptor
56-
tusb_desc_device_t desc_device;
41+
//--------------------------------------------------------------------+
42+
// Setup and Loop on Core0
43+
//--------------------------------------------------------------------+
5744

58-
// the setup function runs once when you press reset or power the board
5945
void setup()
6046
{
6147
Serial1.begin(115200);
@@ -70,7 +56,10 @@ void loop()
7056
{
7157
}
7258

73-
// core1's setup
59+
//--------------------------------------------------------------------+
60+
// Setup and Loop on Core1
61+
//--------------------------------------------------------------------+
62+
7463
void setup1() {
7564
//while ( !Serial ) delay(10); // wait for native usb
7665
Serial.println("Core1 setup to run TinyUSB host with pio-usb");
@@ -84,6 +73,11 @@ void setup1() {
8473
while(1) delay(1);
8574
}
8675

76+
#ifdef HOST_PIN_VBUS_EN
77+
pinMode(HOST_PIN_VBUS_EN, OUTPUT);
78+
digitalWrite(HOST_PIN_VBUS_EN, HOST_PIN_VBUS_EN_STATE);
79+
#endif
80+
8781
pio_usb_configuration_t pio_cfg = PIO_USB_DEFAULT_CONFIG;
8882
pio_cfg.pin_dp = HOST_PIN_DP;
8983
USBHost.configure_pio_usb(1, &pio_cfg);
@@ -94,7 +88,6 @@ void setup1() {
9488
USBHost.begin(1);
9589
}
9690

97-
// core1's loop
9891
void loop1()
9992
{
10093
USBHost.task();

examples/DualRole/device_info_rp2040/device_info_rp2040.ino

Lines changed: 29 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 (gpio2), D- = D+ +1 (gpio3)
19+
* - 2 consecutive GPIOs: D+ is defined by HOST_PIN_DP (gpio20), D- = D+ +1 (gpio21)
2020
* - Provide VBus (5v) and GND for peripheral
2121
* - CPU Speed must be either 120 or 240 Mhz. Selected via "Menu -> CPU Speed"
2222
*
@@ -43,18 +43,28 @@
4343

4444
// pio-usb is required for rp2040 host
4545
#include "pio_usb.h"
46-
#define HOST_PIN_DP 2 // Pin used as D+ for host, D- = D+ + 1
47-
4846
#include "Adafruit_TinyUSB.h"
4947

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
5157

5258
// USB Host object
5359
Adafruit_USBH_Host USBHost;
5460

5561
// holding device descriptor
5662
tusb_desc_device_t desc_device;
5763

64+
//--------------------------------------------------------------------+
65+
// Setup and Loop on Core0
66+
//--------------------------------------------------------------------+
67+
5868
// the setup function runs once when you press reset or power the board
5969
void setup()
6070
{
@@ -70,20 +80,32 @@ void loop()
7080
{
7181
}
7282

73-
// core1's setup
83+
//--------------------------------------------------------------------+
84+
// Setup and Loop on Core1
85+
//--------------------------------------------------------------------+
86+
7487
void setup1() {
7588
//while ( !Serial ) delay(10); // wait for native usb
7689
Serial.println("Core1 setup to run TinyUSB host with pio-usb");
7790

7891
// Check for CPU frequency, must be multiple of 120Mhz for bit-banging USB
7992
uint32_t cpu_hz = clock_get_hz(clk_sys);
8093
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+
}
8297
Serial.printf("Error: CPU Clock = %u, PIO USB require CPU clock must be multiple of 120 Mhz\r\n", cpu_hz);
8398
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+
}
85102
}
86103

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+
87109
pio_usb_configuration_t pio_cfg = PIO_USB_DEFAULT_CONFIG;
88110
pio_cfg.pin_dp = HOST_PIN_DP;
89111
USBHost.configure_pio_usb(1, &pio_cfg);
@@ -94,7 +116,6 @@ void setup1() {
94116
USBHost.begin(1);
95117
}
96118

97-
// core1's loop
98119
void loop1()
99120
{
100121
USBHost.task();

0 commit comments

Comments
 (0)