5
5
// pio-usb is required for rp2040 host
6
6
#include " pio_usb.h"
7
7
#include " Adafruit_TinyUSB.h"
8
+ #include " pico/stdlib.h"
8
9
9
10
// Pin D+ for host, D- = D+ + 1
10
11
#ifndef PIN_USB_HOST_DP
@@ -34,20 +35,14 @@ void loop() {
34
35
35
36
void setup1 () {
36
37
38
+ // override tools menu CPU frequency setting
39
+ set_sys_clock_khz (120'000 , true );
40
+
37
41
#if 0
38
42
while ( !Serial ) delay(10); // wait for native usb
39
43
Serial.println("Core1 setup to run TinyUSB host with pio-usb");
40
44
#endif
41
45
42
- // Check for CPU frequency, must be multiple of 120Mhz for bit-banging USB
43
- uint32_t cpu_hz = clock_get_hz (clk_sys);
44
- if ( cpu_hz != 120000000UL && cpu_hz != 240000000UL ) {
45
- while ( !Serial ) delay (10 ); // wait for native usb
46
- Serial.printf (" Error: CPU Clock = %lu, PIO USB require CPU clock must be multiple of 120 Mhz\r\n " , cpu_hz);
47
- Serial.printf (" Change your CPU Clock to either 120 or 240 Mhz in Menu->CPU Speed \r\n " );
48
- while (1 ) delay (1 );
49
- }
50
-
51
46
#ifdef PIN_5V_EN
52
47
pinMode (PIN_5V_EN, OUTPUT);
53
48
digitalWrite (PIN_5V_EN, PIN_5V_EN_STATE);
@@ -68,9 +63,11 @@ void setup1() {
68
63
69
64
int old_ascii = -1 ;
70
65
uint32_t repeat_timeout;
71
- const uint32_t repeat_time = 150 ;
66
+ // this matches Linux default of 500ms to first repeat, 1/20s thereafter
67
+ const uint32_t default_repeat_time = 50 ;
68
+ const uint32_t initial_repeat_time = 500 ;
72
69
73
- void send_ascii (uint8_t code) {
70
+ void send_ascii (uint8_t code, uint32_t repeat_time=default_repeat_time ) {
74
71
old_ascii = code;
75
72
repeat_timeout = millis () + repeat_time;
76
73
if (code > 32 && code < 127 ) {
@@ -86,9 +83,8 @@ void loop1()
86
83
uint32_t now = millis ();
87
84
uint32_t deadline = repeat_timeout - now;
88
85
if (old_ascii >= 0 && deadline > INT32_MAX) {
89
- repeat_timeout += repeat_time;
90
- deadline = repeat_timeout - now;
91
86
send_ascii (old_ascii);
87
+ deadline = repeat_timeout - now;
92
88
} else if (old_ascii < 0 ) {
93
89
deadline = UINT32_MAX;
94
90
}
@@ -217,7 +213,7 @@ void process_event(uint8_t dev_addr, uint8_t instance, const hid_keyboard_report
217
213
}
218
214
if (ctrl) code &= 0x1f ;
219
215
if (alt) code ^= 0x80 ;
220
- send_ascii (code);
216
+ send_ascii (code, initial_repeat_time );
221
217
break ;
222
218
}
223
219
}
0 commit comments