Skip to content

Commit 82ec027

Browse files
committed
device info sketch displays to HDMI
1 parent 58f904d commit 82ec027

File tree

3 files changed

+74
-30
lines changed

3 files changed

+74
-30
lines changed

examples/DualRole/HID/hid_device_report/hid_device_report.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ void loop() {
5757
//------------- Core0 -------------//
5858
void setup() {
5959
Serial.begin(115200);
60-
//while ( !Serial ) delay(10); // wait for native usb
60+
while ( !Serial ) delay(10); // wait for native usb
6161
Serial.println("TinyUSB Dual: HID Device Report Example");
6262
}
6363

@@ -120,4 +120,4 @@ void tuh_hid_report_received_cb(uint8_t dev_addr, uint8_t instance, uint8_t cons
120120
}
121121
}
122122

123-
} // extern C
123+
} // extern C

examples/DualRole/Simple/device_info/device_info.ino

Lines changed: 63 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,21 @@
4848
*
4949
*/
5050

51+
#include "Adafruit_dvhstx.h"
52+
53+
DVHSTXText3 display(DVHSTX_PINOUT_DEFAULT);
54+
5155
// USBHost is defined in usbh_helper.h
5256
#include "usbh_helper.h"
5357

5458
// Language ID: English
5559
#define LANGUAGE_ID 0x0409
5660

61+
#if defined(ARDUINO_ARCH_RP2040)
62+
#include "hardware/vreg.h"
63+
#include "hardware/clocks.h"
64+
#endif
65+
5766
typedef struct {
5867
tusb_desc_device_t desc_device;
5968
uint16_t manufacturer[32];
@@ -65,8 +74,23 @@ typedef struct {
6574
// CFG_TUH_DEVICE_MAX is defined by tusb_config header
6675
dev_info_t dev_info[CFG_TUH_DEVICE_MAX] = { 0 };
6776

77+
volatile bool start1 = false;
78+
6879
void setup() {
80+
display.begin();
6981
Serial.begin(115200);
82+
while ( !Serial ) delay(10); // wait for native usb
83+
84+
#if 0 // defined(ARDUINO_ARCH_RP2040)
85+
Serial.println("About to overclock to 264MHz"); Serial.flush();
86+
// We're going to go fast, boost the voltage a little
87+
vreg_set_voltage(VREG_VOLTAGE_1_15);
88+
delay(10);
89+
90+
set_sys_clock_khz(240000, true);
91+
Serial.println("Overclocking complete (LIE)"); Serial.flush();
92+
#endif
93+
7094

7195
#if defined(CFG_TUH_MAX3421) && CFG_TUH_MAX3421
7296
// init host stack on controller (rhport) 1
@@ -75,7 +99,13 @@ void setup() {
7599
#endif
76100

77101
// while ( !Serial ) delay(10); // wait for native usb
78-
Serial.println("TinyUSB Dual Device Info Example");
102+
Serial.println("TinyUSB Dual Device Info Example"); Serial.flush();
103+
display.println("TinyUSB Dual Device Info Example"); display.flush();
104+
display.printf("CFG_TUH_DEVICE_MAX=%u\n", CFG_TUH_DEVICE_MAX);
105+
display.printf("systick CSR=%08x RVR=%08x CVR=%08x\r\n", systick_hw->csr, systick_hw->rvr, systick_hw->cvr);
106+
delay(10);
107+
display.printf("systick CSR=%08x RVR=%08x CVR=%08x\r\n", systick_hw->csr, systick_hw->rvr, systick_hw->cvr);
108+
start1=true;
79109
}
80110

81111
#if defined(CFG_TUH_MAX3421) && CFG_TUH_MAX3421
@@ -88,6 +118,9 @@ void loop() {
88118
}
89119

90120
#elif defined(ARDUINO_ARCH_RP2040)
121+
#include "hardware/vreg.h"
122+
#include "hardware/clocks.h"
123+
91124
//--------------------------------------------------------------------+
92125
// For RP2040 use both core0 for device stack, core1 for host stack
93126
//--------------------------------------------------------------------+
@@ -98,6 +131,7 @@ void loop() {
98131

99132
//------------- Core1 -------------//
100133
void setup1() {
134+
while (!start1) delay(10);
101135
//while ( !Serial ) delay(10); // wait for native usb
102136
// configure pio-usb: defined in usbh_helper.h
103137
rp2040_configure_pio_usb();
@@ -106,6 +140,7 @@ void setup1() {
106140
// Note: For rp2040 pico-pio-usb, calling USBHost.begin() on core1 will have most of the
107141
// host bit-banging processing works done in core1 to free up core0 for other works
108142
USBHost.begin(1);
143+
Serial.printf("%s:%d\r\n", __FILE__, __LINE__);
109144
}
110145

111146
void loop1() {
@@ -128,7 +163,7 @@ void print_lsusb(void) {
128163
// use local connected flag instead
129164
dev_info_t *dev = &dev_info[daddr - 1];
130165
if (dev->mounted) {
131-
Serial.printf("Device %u: ID %04x:%04x %s %s\r\n", daddr,
166+
display.printf("Device %u: ID %04x:%04x %s %s\r\n", daddr,
132167
dev->desc_device.idVendor, dev->desc_device.idProduct,
133168
(char *) dev->manufacturer, (char *) dev->product);
134169

@@ -137,13 +172,13 @@ void print_lsusb(void) {
137172
}
138173

139174
if (no_device) {
140-
Serial.println("No device connected (except hub)");
175+
display.println("No device connected (except hub)");
141176
}
142177
}
143178

144179
// Invoked when device is mounted (configured)
145180
void tuh_mount_cb(uint8_t daddr) {
146-
Serial.printf("Device attached, address = %d\r\n", daddr);
181+
display.printf("Device attached, address = %d\r\n", daddr);
147182

148183
dev_info_t *dev = &dev_info[daddr - 1];
149184
dev->mounted = true;
@@ -154,7 +189,7 @@ void tuh_mount_cb(uint8_t daddr) {
154189

155190
/// Invoked when device is unmounted (bus reset/unplugged)
156191
void tuh_umount_cb(uint8_t daddr) {
157-
Serial.printf("Device removed, address = %d\r\n", daddr);
192+
display.printf("Device removed, address = %d\r\n", daddr);
158193
dev_info_t *dev = &dev_info[daddr - 1];
159194
dev->mounted = false;
160195

@@ -164,53 +199,53 @@ void tuh_umount_cb(uint8_t daddr) {
164199

165200
void print_device_descriptor(tuh_xfer_t *xfer) {
166201
if (XFER_RESULT_SUCCESS != xfer->result) {
167-
Serial.printf("Failed to get device descriptor\r\n");
202+
display.printf("Failed to get device descriptor\r\n");
168203
return;
169204
}
170205

171206
uint8_t const daddr = xfer->daddr;
172207
dev_info_t *dev = &dev_info[daddr - 1];
173208
tusb_desc_device_t *desc = &dev->desc_device;
174209

175-
Serial.printf("Device %u: ID %04x:%04x\r\n", daddr, desc->idVendor, desc->idProduct);
176-
Serial.printf("Device Descriptor:\r\n");
177-
Serial.printf(" bLength %u\r\n" , desc->bLength);
178-
Serial.printf(" bDescriptorType %u\r\n" , desc->bDescriptorType);
179-
Serial.printf(" bcdUSB %04x\r\n" , desc->bcdUSB);
180-
Serial.printf(" bDeviceClass %u\r\n" , desc->bDeviceClass);
181-
Serial.printf(" bDeviceSubClass %u\r\n" , desc->bDeviceSubClass);
182-
Serial.printf(" bDeviceProtocol %u\r\n" , desc->bDeviceProtocol);
183-
Serial.printf(" bMaxPacketSize0 %u\r\n" , desc->bMaxPacketSize0);
184-
Serial.printf(" idVendor 0x%04x\r\n" , desc->idVendor);
185-
Serial.printf(" idProduct 0x%04x\r\n" , desc->idProduct);
186-
Serial.printf(" bcdDevice %04x\r\n" , desc->bcdDevice);
210+
display.printf("Device %u: ID %04x:%04x\r\n", daddr, desc->idVendor, desc->idProduct);
211+
display.printf("Device Descriptor:\r\n");
212+
display.printf(" bLength %u\r\n" , desc->bLength);
213+
display.printf(" bDescriptorType %u\r\n" , desc->bDescriptorType);
214+
display.printf(" bcdUSB %04x\r\n" , desc->bcdUSB);
215+
display.printf(" bDeviceClass %u\r\n" , desc->bDeviceClass);
216+
display.printf(" bDeviceSubClass %u\r\n" , desc->bDeviceSubClass);
217+
display.printf(" bDeviceProtocol %u\r\n" , desc->bDeviceProtocol);
218+
display.printf(" bMaxPacketSize0 %u\r\n" , desc->bMaxPacketSize0);
219+
display.printf(" idVendor 0x%04x\r\n" , desc->idVendor);
220+
display.printf(" idProduct 0x%04x\r\n" , desc->idProduct);
221+
display.printf(" bcdDevice %04x\r\n" , desc->bcdDevice);
187222

188223
// Get String descriptor using Sync API
189-
Serial.printf(" iManufacturer %u ", desc->iManufacturer);
224+
display.printf(" iManufacturer %u ", desc->iManufacturer);
190225
if (XFER_RESULT_SUCCESS ==
191226
tuh_descriptor_get_manufacturer_string_sync(daddr, LANGUAGE_ID, dev->manufacturer, sizeof(dev->manufacturer))) {
192227
utf16_to_utf8(dev->manufacturer, sizeof(dev->manufacturer));
193-
Serial.printf((char *) dev->manufacturer);
228+
display.printf((char *) dev->manufacturer);
194229
}
195-
Serial.printf("\r\n");
230+
display.printf("\r\n");
196231

197-
Serial.printf(" iProduct %u ", desc->iProduct);
232+
display.printf(" iProduct %u ", desc->iProduct);
198233
if (XFER_RESULT_SUCCESS ==
199234
tuh_descriptor_get_product_string_sync(daddr, LANGUAGE_ID, dev->product, sizeof(dev->product))) {
200235
utf16_to_utf8(dev->product, sizeof(dev->product));
201-
Serial.printf((char *) dev->product);
236+
display.printf((char *) dev->product);
202237
}
203-
Serial.printf("\r\n");
238+
display.printf("\r\n");
204239

205-
Serial.printf(" iSerialNumber %u ", desc->iSerialNumber);
240+
display.printf(" iSerialNumber %u ", desc->iSerialNumber);
206241
if (XFER_RESULT_SUCCESS ==
207242
tuh_descriptor_get_serial_string_sync(daddr, LANGUAGE_ID, dev->serial, sizeof(dev->serial))) {
208243
utf16_to_utf8(dev->serial, sizeof(dev->serial));
209-
Serial.printf((char *) dev->serial);
244+
display.printf((char *) dev->serial);
210245
}
211-
Serial.printf("\r\n");
246+
display.printf("\r\n");
212247

213-
Serial.printf(" bNumConfigurations %u\r\n", desc->bNumConfigurations);
248+
display.printf(" bNumConfigurations %u\r\n", desc->bNumConfigurations);
214249

215250
// print device summary
216251
print_lsusb();

examples/DualRole/Simple/device_info/usbh_helper.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
#ifndef PIN_5V_EN_STATE
3030
#define PIN_5V_EN_STATE 1
3131
#endif
32+
33+
#include "hardware/dma.h"
3234
#endif // ARDUINO_ARCH_RP2040
3335

3436
#include "Adafruit_TinyUSB.h"
@@ -61,6 +63,7 @@ static void rp2040_configure_pio_usb(void) {
6163

6264
// Check for CPU frequency, must be multiple of 120Mhz for bit-banging USB
6365
uint32_t cpu_hz = clock_get_hz(clk_sys);
66+
Serial.printf("Core speed is %fMHz\r\n", cpu_hz * 1e-6);
6467
if (cpu_hz % 12000000UL) {
6568
while (!Serial) {
6669
delay(10); // wait for native usb
@@ -72,6 +75,7 @@ static void rp2040_configure_pio_usb(void) {
7275
}
7376
}
7477

78+
Serial.printf("%s:%d\r\n", __FILE__, __LINE__);
7579
#ifdef PIN_5V_EN
7680
pinMode(PIN_5V_EN, OUTPUT);
7781
digitalWrite(PIN_5V_EN, PIN_5V_EN_STATE);
@@ -91,8 +95,13 @@ static void rp2040_configure_pio_usb(void) {
9195
pio_cfg.pio_tx_num = 1;
9296
pio_cfg.tx_ch = 9;
9397
#endif
98+
Serial.printf("%s:%d\r\n", __FILE__, __LINE__);
99+
pio_cfg.tx_ch = dma_claim_unused_channel(true);
100+
dma_channel_unclaim(pio_cfg.tx_ch);
94101

102+
Serial.printf("%s:%d: using dma channel %d\r\n", __FILE__, __LINE__, pio_cfg.tx_ch);
95103
USBHost.configure_pio_usb(1, &pio_cfg);
104+
Serial.printf("%s:%d\r\n", __FILE__, __LINE__);
96105
}
97106
#endif
98107

0 commit comments

Comments
 (0)