66#include " pio_usb.h"
77#include " Adafruit_TinyUSB.h"
88#include " pico/stdlib.h"
9- #include " Adafruit_dvhstx.h"
10-
11- DVHSTXText3 display (DVHSTX_PINOUT_DEFAULT);
129
1310// Pin D+ for host, D- = D+ + 1
1411#ifndef PIN_USB_HOST_DP
@@ -31,22 +28,16 @@ Adafruit_USBH_Host USBHost;
3128SerialPIO pio_serial (1 /* RX of the sibling board */ , SerialPIO::NOPIN);
3229
3330void setup () {
34- // ensure text generation interrupt takes place on core0
35- display.begin ();
36- display.println (" Hello hstx\n " );
3731}
3832
3933void loop () {
4034}
4135
4236void setup1 () {
43- while (!display) ;
44- delay (10 );
45- display.println (" Hello hstx in setup1\n " );
37+
4638 // override tools menu CPU frequency setting
47- // set_sys_clock_khz(264 '000, true);
39+ set_sys_clock_khz (120 '000 , true );
4840
49- Serial.begin (115200 );
5041#if 0
5142 while ( !Serial ) delay(10); // wait for native usb
5243 Serial.println("Core1 setup to run TinyUSB host with pio-usb");
@@ -59,9 +50,6 @@ Serial.begin(115200);
5950
6051 pio_usb_configuration_t pio_cfg = PIO_USB_DEFAULT_CONFIG;
6152 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-
6553 USBHost.configure_pio_usb (1 , &pio_cfg);
6654
6755 // run host stack on controller (rhport) 1
@@ -71,8 +59,6 @@ Serial.begin(115200);
7159
7260 // this `begin` is a void function, no way to check for failure!
7361 pio_serial.begin (115200 );
74- display.println (" end of setup1\n " );
75- display.show_cursor ();
7662}
7763
7864int old_ascii = -1 ;
@@ -84,21 +70,16 @@ const uint32_t initial_repeat_time = 500;
8470void send_ascii (uint8_t code, uint32_t repeat_time=default_repeat_time) {
8571 old_ascii = code;
8672 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);
8975 } else {
90- display .printf (" \\ x%02x" , code);
76+ Serial .printf (" ' \\ x%02x' \r\n " , code);
9177 }
9278 pio_serial.write (code);
9379}
9480
9581void loop1 ()
9682{
97- static bool last_serial;
98- if (!last_serial && Serial) {
99- last_serial = true ;
100- Serial.println (" Hello host serial" );
101- }
10283 uint32_t now = millis ();
10384 uint32_t deadline = repeat_timeout - now;
10485 if (old_ascii >= 0 && deadline > INT32_MAX) {
@@ -185,12 +166,12 @@ bool report_contains(const hid_keyboard_report_t &report, uint8_t key) {
185166
186167hid_keyboard_report_t old_report;
187168
188- static bool caps, num;
189- static uint8_t old_leds;
190169void process_event (uint8_t dev_addr, uint8_t instance, const hid_keyboard_report_t &report) {
191170 bool alt = report.modifier & 0x44 ;
192171 bool shift = report.modifier & 0x22 ;
193172 bool ctrl = report.modifier & 0x11 ;
173+ bool caps = old_report.reserved & 1 ;
174+ bool num = old_report.reserved & 2 ;
194175 uint8_t code = 0 ;
195176
196177 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
207188
208189 /* key is newly pressed */
209190 if (keycode == HID_KEY_NUM_LOCK) {
210- Serial.println (" toggle numlock" );
211191 num = !num;
212192 } else if (keycode == HID_KEY_CAPS_LOCK) {
213- Serial.println (" toggle capslock" );
214193 caps = !caps;
215194 } else {
216195 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
240219 }
241220 }
242221
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 ) {
246224 Serial.printf (" Send LEDs report %d (dev:instance = %d:%d)\r\n " , leds, dev_addr, instance);
247225 // 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 ));
249227 Serial.printf (" set_report() -> %d\n " , (int )r);
250228 }
251229 old_report = report;
230+ old_report.reserved = leds;
252231}
253232
254233// Invoked when received report from device via interrupt endpoint
0 commit comments