6
6
#include " pio_usb.h"
7
7
#include " Adafruit_TinyUSB.h"
8
8
#include " pico/stdlib.h"
9
- #include " Adafruit_dvhstx.h"
10
-
11
- DVHSTXText3 display (DVHSTX_PINOUT_DEFAULT);
12
9
13
10
// Pin D+ for host, D- = D+ + 1
14
11
#ifndef PIN_USB_HOST_DP
@@ -31,22 +28,16 @@ Adafruit_USBH_Host USBHost;
31
28
SerialPIO pio_serial (1 /* RX of the sibling board */ , SerialPIO::NOPIN);
32
29
33
30
void setup () {
34
- // ensure text generation interrupt takes place on core0
35
- display.begin ();
36
- display.println (" Hello hstx\n " );
37
31
}
38
32
39
33
void loop () {
40
34
}
41
35
42
36
void setup1 () {
43
- while (!display) ;
44
- delay (10 );
45
- display.println (" Hello hstx in setup1\n " );
37
+
46
38
// override tools menu CPU frequency setting
47
- // set_sys_clock_khz(264 '000, true);
39
+ set_sys_clock_khz (120 '000 , true );
48
40
49
- Serial.begin (115200 );
50
41
#if 0
51
42
while ( !Serial ) delay(10); // wait for native usb
52
43
Serial.println("Core1 setup to run TinyUSB host with pio-usb");
@@ -59,9 +50,6 @@ Serial.begin(115200);
59
50
60
51
pio_usb_configuration_t pio_cfg = PIO_USB_DEFAULT_CONFIG;
61
52
pio_cfg.pin_dp = PIN_USB_HOST_DP;
62
- pio_cfg.tx_ch = dma_claim_unused_channel (true );
63
- dma_channel_unclaim (pio_cfg.tx_ch );
64
-
65
53
USBHost.configure_pio_usb (1 , &pio_cfg);
66
54
67
55
// run host stack on controller (rhport) 1
@@ -71,8 +59,6 @@ Serial.begin(115200);
71
59
72
60
// this `begin` is a void function, no way to check for failure!
73
61
pio_serial.begin (115200 );
74
- display.println (" end of setup1\n " );
75
- display.show_cursor ();
76
62
}
77
63
78
64
int old_ascii = -1 ;
@@ -84,21 +70,16 @@ const uint32_t initial_repeat_time = 500;
84
70
void send_ascii (uint8_t code, uint32_t repeat_time=default_repeat_time) {
85
71
old_ascii = code;
86
72
repeat_timeout = millis () + repeat_time;
87
- if (code >= 32 && code < 127 ) {
88
- display .printf (" %c " , code);
73
+ if (code > 32 && code < 127 ) {
74
+ Serial .printf (" '%c' \r\n " , code);
89
75
} else {
90
- display .printf (" \\ x%02x" , code);
76
+ Serial .printf (" ' \\ x%02x' \r\n " , code);
91
77
}
92
78
pio_serial.write (code);
93
79
}
94
80
95
81
void loop1 ()
96
82
{
97
- static bool last_serial;
98
- if (!last_serial && Serial) {
99
- last_serial = true ;
100
- Serial.println (" Hello host serial" );
101
- }
102
83
uint32_t now = millis ();
103
84
uint32_t deadline = repeat_timeout - now;
104
85
if (old_ascii >= 0 && deadline > INT32_MAX) {
@@ -185,12 +166,12 @@ bool report_contains(const hid_keyboard_report_t &report, uint8_t key) {
185
166
186
167
hid_keyboard_report_t old_report;
187
168
188
- static bool caps, num;
189
- static uint8_t old_leds;
190
169
void process_event (uint8_t dev_addr, uint8_t instance, const hid_keyboard_report_t &report) {
191
170
bool alt = report.modifier & 0x44 ;
192
171
bool shift = report.modifier & 0x22 ;
193
172
bool ctrl = report.modifier & 0x11 ;
173
+ bool caps = old_report.reserved & 1 ;
174
+ bool num = old_report.reserved & 2 ;
194
175
uint8_t code = 0 ;
195
176
196
177
if (report.keycode [0 ] == 1 && report.keycode [1 ] == 1 ) {
@@ -207,10 +188,8 @@ void process_event(uint8_t dev_addr, uint8_t instance, const hid_keyboard_report
207
188
208
189
/* key is newly pressed */
209
190
if (keycode == HID_KEY_NUM_LOCK) {
210
- Serial.println (" toggle numlock" );
211
191
num = !num;
212
192
} else if (keycode == HID_KEY_CAPS_LOCK) {
213
- Serial.println (" toggle capslock" );
214
193
caps = !caps;
215
194
} else {
216
195
for (const auto &mapper : keycode_to_ascii) {
@@ -240,15 +219,15 @@ void process_event(uint8_t dev_addr, uint8_t instance, const hid_keyboard_report
240
219
}
241
220
}
242
221
243
- uint8_t leds = (caps << 1 ) | num;
244
- if (leds != old_leds) {
245
- old_leds = leds;
222
+ uint8_t leds = (caps | (num << 1 ));
223
+ if (leds != old_report.reserved ) {
246
224
Serial.printf (" Send LEDs report %d (dev:instance = %d:%d)\r\n " , leds, dev_addr, instance);
247
225
// no worky
248
- auto r = tuh_hid_set_report (dev_addr, instance/* idx*/ , 0 /* report_id*/ , HID_REPORT_TYPE_OUTPUT/* report_type*/ , &old_leds , sizeof (old_leds ));
226
+ auto r = tuh_hid_set_report (dev_addr, instance/* idx*/ , 0 /* report_id*/ , HID_REPORT_TYPE_OUTPUT/* report_type*/ , &leds , sizeof (leds ));
249
227
Serial.printf (" set_report() -> %d\n " , (int )r);
250
228
}
251
229
old_report = report;
230
+ old_report.reserved = leds;
252
231
}
253
232
254
233
// Invoked when received report from device via interrupt endpoint
0 commit comments