Skip to content

Commit 5837b38

Browse files
authored
Merge pull request #118 from picoruby/reduce_startup_time
Reduce startup time
2 parents 2dda391 + 9b21f1d commit 5837b38

File tree

10 files changed

+43
-37
lines changed

10 files changed

+43
-37
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Change log
22

3+
## 0.9.16 on 2022/07/20
4+
5+
### Improvement
6+
- [Experimental] Startup time reduced⌨💨
7+
We really hope all guys try this version and report to us if there's a problem of any kind🙏
8+
39
## 0.9.15 on 2022/07/19
410

511
### Joystick🕹

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pico_sdk_init()
2727

2828
execute_process (COMMAND date +%Y%m%d OUTPUT_VARIABLE CMAKE_BUILDDATE OUTPUT_STRIP_TRAILING_WHITESPACE)
2929
execute_process (COMMAND git rev-parse --short HEAD OUTPUT_VARIABLE CMAKE_REVISION OUTPUT_STRIP_TRAILING_WHITESPACE)
30-
set (PRK_VERSION 0.9.15)
30+
set (PRK_VERSION 0.9.16)
3131
set (PRK_BUILDDATE ${CMAKE_BUILDDATE})
3232
set (PRK_REVISION ${CMAKE_REVISION})
3333
configure_file ("${CMAKE_CURRENT_SOURCE_DIR}/src/version.h.in" "${CMAKE_CURRENT_SOURCE_DIR}/src/version.h")

src/main.c

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -84,34 +84,36 @@ char const *string_desc_arr[STRING_DESC_ARR_SIZE] =
8484
* 0x1234:0xABCD:productName
8585
* ^^^^^^ ^^^^^^ ^^^^^^^^^^^
8686
* VID PID Name
87-
* - IDs' prefix should be `0x`, should NOT be `0X`
8887
* - Length of productName should be less than or equal 32 bytes
8988
* and any other letter must not be included in the file.
9089
*/
91-
#define PRK_CONF_LENGTH (7 + 7 + 32)
90+
#define PRK_CONF_MAX_LENGTH (7 + 7 + 33 + 2)
9291
static void
9392
configure_prk(void)
9493
{
94+
static char prk_conf[PRK_CONF_MAX_LENGTH] = {0};
9595
DirEnt entry;
96-
uint8_t buf[PRK_CONF_LENGTH + 1] = {0};
97-
uint8_t vid[7] = {0};
98-
uint8_t pid[7] = {0};
99-
static char name[PRK_CONF_LENGTH - 14] = {0};
10096
msc_findDirEnt("PRK-CONFTXT", &entry);
10197
if (entry.Name[0] != '\0') {
102-
if (entry.FileSize > PRK_CONF_LENGTH) return;
103-
msc_loadFile(buf, &entry);
104-
if (strncmp("0x", buf, 2) || strncmp(":0x", buf + 6, 3)) return;
105-
memcpy(vid, buf , 6);
106-
memcpy(pid, buf + 7, 6);
107-
memcpy(name, buf + 14, strlen(buf) - 14);
108-
for (int i = 0; ; i++) {
109-
if (name[i] == '\r' || name[i] == '\n') name[i] = '\0';
110-
if (name[i] == '\0') break;
98+
if (entry.FileSize > PRK_CONF_MAX_LENGTH) return;
99+
msc_loadFile(prk_conf, &entry);
100+
char *tok = strtok(prk_conf, ":");
101+
for (int i = 0; i < 3; i++) {
102+
if (tok == NULL) break;
103+
switch (i) {
104+
case 0:
105+
desc_device.idVendor = (uint16_t)strtol(tok, NULL, 16);
106+
tok = strtok(NULL, ":");
107+
break;
108+
case 1:
109+
desc_device.idProduct = (uint16_t)strtol(tok, NULL, 16);
110+
tok = strtok(NULL, ": \t\n\r");
111+
break;
112+
case 2:
113+
string_desc_arr[2] = (const char *)tok;
114+
break;
115+
}
111116
}
112-
desc_device.idVendor = (uint16_t)strtol(vid, NULL, 16);
113-
desc_device.idProduct = (uint16_t)strtol(pid, NULL, 16);
114-
string_desc_arr[2] = (const char *)name;
115117
}
116118
}
117119

@@ -210,7 +212,7 @@ create_keymap_task(mrbc_tcb *tcb)
210212
if (entry.Name[0] != '\0') {
211213
RotaryEncoder_reset();
212214
uint32_t fileSize = entry.FileSize;
213-
console_printf("Size of keymap.rb: %u\n", fileSize);
215+
console_printf("keymap.rb size: %u\n", fileSize);
214216
if (fileSize < MAX_KEYMAP_SIZE) {
215217
keymap_rb = malloc(KEYMAP_PREFIX_SIZE + fileSize + 1);
216218
keymap_rb[KEYMAP_PREFIX_SIZE + fileSize] = '\0';
@@ -222,7 +224,7 @@ create_keymap_task(mrbc_tcb *tcb)
222224
si = StreamInterface_new(NULL, SUSPEND_TASK, STREAM_TYPE_MEMORY);
223225
}
224226
} else {
225-
console_printf("No keymap.rb found.\n");
227+
console_printf("No keymap.rb found!\n");
226228
si = StreamInterface_new(NULL, SUSPEND_TASK, STREAM_TYPE_MEMORY);
227229
}
228230
if (!Compiler_compile(p, si, NULL)) {

src/ruby/app/models/debounce.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ class DebounceBase
44
DEFAULT_THRESHOLD = 40
55

66
def initialize
7-
puts "Initializing #{self.class}."
7+
puts "Init #{self.class}"
88
@threshold = DEFAULT_THRESHOLD
99
@now = 0
1010
end

src/ruby/app/models/keyboard.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ class Keyboard
443443
class Keyboard
444444

445445
def initialize
446-
puts "Initializing Keyboard."
446+
puts "Init Keyboard"
447447
# mruby/c VM doesn't work with a CONSTANT to make another CONSTANT
448448
# steep doesn't allow dynamic assignment of CONSTANT
449449
@SHIFT_LETTER_THRESHOLD_A = LETTER.index('A').to_i
@@ -595,7 +595,7 @@ def init_uart
595595
end
596596

597597
def init_matrix_pins(matrix)
598-
puts "Initializing GPIO."
598+
puts "Init GPIO"
599599
init_uart
600600
@cols_size = 0
601601
@rows_size = matrix.size
@@ -980,7 +980,7 @@ def start!
980980
# default debounce algorithm will be applied
981981
self.set_debounce(@scan_mode == :direct ? :per_key : :per_row) unless @debouncer
982982

983-
puts "Keyboard task started."
983+
puts "Keyboard started"
984984

985985
# To avoid unintentional report on startup
986986
# which happens only on Sparkfun Pro Micro RP2040

src/ruby/app/models/rgb.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
class RGB
22
def initialize(pin, underglow_size, backlight_size, is_rgbw = false)
3-
puts "Initializing RGB."
3+
puts "Init RGB"
44
turn_off
55
@fifo = Array.new
66
# TODO: @underglow_size, @backlight_size

src/ruby/app/models/rotary_encoder.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
class RotaryEncoder
22
def initialize(pin_a, pin_b)
3-
puts "Initializing RotaryEncoder ..."
3+
puts "Init RotaryEncoder"
44
@pin_a = pin_a
55
@pin_b = pin_b
66
@partner_keycode_cw = 0

src/ruby/app/models/via.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class VIA
3333
VIA_FILENAME = "VIA_MAP TXT"
3434

3535
def initialize
36-
puts "Initializing VIA."
36+
puts "Init VIA"
3737
@layer_count = 5
3838
@mode_keys = Hash.new
3939
@keymap_saved = true

src/ruby/app/tasks/rgb_task.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
puts "RGB task started."
1+
puts "RGB started"
22

3-
3.times { sleep 1 }
3+
sleep 0.5
44

55
while true
66
unless $rgb

src/ruby/app/tasks/usb_task.rb

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
2000.times do
1+
200.times do
22
tud_task
33
cdc_task
44
sleep_ms 2
55
end
66
print "\e[2J\e[1;1H" # clear all & home
7-
puts "Welcome to PRK Firmware!\n\nTUD task started.\n"
7+
puts "PRK Firmware started!\n\n"
88
autoreload_tick = 0
99

1010
$mutex = false
@@ -14,16 +14,14 @@
1414
cdc_task
1515
if autoreload_ready?
1616
if autoreload_tick == 0
17-
puts "Autoreload is ready."
17+
puts "Reloading keymap"
1818
$rgb.turn_off if $rgb
19-
puts "Suspending keymap."
2019
suspend_keymap
2120
report_hid(0, "\000\000\000\000\000\000")
22-
autoreload_tick = 500
21+
autoreload_tick = 200
2322
elsif autoreload_tick == 1
24-
puts "Trying to reload keymap."
2523
reload_keymap
26-
500.times do
24+
10.times do
2725
tud_task
2826
cdc_task
2927
sleep_ms 2

0 commit comments

Comments
 (0)