Skip to content

Commit

Permalink
Reduce startup time & refactor prk-conf
Browse files Browse the repository at this point in the history
  • Loading branch information
hasumikin committed Jul 20, 2022
1 parent 2dda391 commit c9c8892
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 36 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Change log

## 0.9.16 on 2022/07/20

### Improvement
- [Experimental] Startup time reduced⌨💨
We really hope all guys try this version and report to us if there's a problem of any kind🙏

## 0.9.15 on 2022/07/19

### Joystick🕹
Expand Down
42 changes: 22 additions & 20 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,34 +84,36 @@ char const *string_desc_arr[STRING_DESC_ARR_SIZE] =
* 0x1234:0xABCD:productName
* ^^^^^^ ^^^^^^ ^^^^^^^^^^^
* VID PID Name
* - IDs' prefix should be `0x`, should NOT be `0X`
* - Length of productName should be less than or equal 32 bytes
* and any other letter must not be included in the file.
*/
#define PRK_CONF_LENGTH (7 + 7 + 32)
#define PRK_CONF_MAX_LENGTH (7 + 7 + 33 + 2)
static void
configure_prk(void)
{
static char prk_conf[PRK_CONF_MAX_LENGTH] = {0};
DirEnt entry;
uint8_t buf[PRK_CONF_LENGTH + 1] = {0};
uint8_t vid[7] = {0};
uint8_t pid[7] = {0};
static char name[PRK_CONF_LENGTH - 14] = {0};
msc_findDirEnt("PRK-CONFTXT", &entry);
if (entry.Name[0] != '\0') {
if (entry.FileSize > PRK_CONF_LENGTH) return;
msc_loadFile(buf, &entry);
if (strncmp("0x", buf, 2) || strncmp(":0x", buf + 6, 3)) return;
memcpy(vid, buf , 6);
memcpy(pid, buf + 7, 6);
memcpy(name, buf + 14, strlen(buf) - 14);
for (int i = 0; ; i++) {
if (name[i] == '\r' || name[i] == '\n') name[i] = '\0';
if (name[i] == '\0') break;
if (entry.FileSize > PRK_CONF_MAX_LENGTH) return;
msc_loadFile(prk_conf, &entry);
char *tok = strtok(prk_conf, ":");
for (int i = 0; i < 3; i++) {
if (tok == NULL) break;
switch (i) {
case 0:
desc_device.idVendor = (uint16_t)strtol(tok, NULL, 16);
tok = strtok(NULL, ":");
break;
case 1:
desc_device.idProduct = (uint16_t)strtol(tok, NULL, 16);
tok = strtok(NULL, ": \t\n\r");
break;
case 2:
string_desc_arr[2] = (const char *)tok;
break;
}
}
desc_device.idVendor = (uint16_t)strtol(vid, NULL, 16);
desc_device.idProduct = (uint16_t)strtol(pid, NULL, 16);
string_desc_arr[2] = (const char *)name;
}
}

Expand Down Expand Up @@ -210,7 +212,7 @@ create_keymap_task(mrbc_tcb *tcb)
if (entry.Name[0] != '\0') {
RotaryEncoder_reset();
uint32_t fileSize = entry.FileSize;
console_printf("Size of keymap.rb: %u\n", fileSize);
console_printf("keymap.rb size: %u\n", fileSize);
if (fileSize < MAX_KEYMAP_SIZE) {
keymap_rb = malloc(KEYMAP_PREFIX_SIZE + fileSize + 1);
keymap_rb[KEYMAP_PREFIX_SIZE + fileSize] = '\0';
Expand All @@ -222,7 +224,7 @@ create_keymap_task(mrbc_tcb *tcb)
si = StreamInterface_new(NULL, SUSPEND_TASK, STREAM_TYPE_MEMORY);
}
} else {
console_printf("No keymap.rb found.\n");
console_printf("No keymap.rb found!\n");
si = StreamInterface_new(NULL, SUSPEND_TASK, STREAM_TYPE_MEMORY);
}
if (!Compiler_compile(p, si, NULL)) {
Expand Down
2 changes: 1 addition & 1 deletion src/ruby/app/models/debounce.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class DebounceBase
DEFAULT_THRESHOLD = 40

def initialize
puts "Initializing #{self.class}."
puts "Init #{self.class}"
@threshold = DEFAULT_THRESHOLD
@now = 0
end
Expand Down
6 changes: 3 additions & 3 deletions src/ruby/app/models/keyboard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ class Keyboard
class Keyboard

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

def init_matrix_pins(matrix)
puts "Initializing GPIO."
puts "Init GPIO"
init_uart
@cols_size = 0
@rows_size = matrix.size
Expand Down Expand Up @@ -980,7 +980,7 @@ def start!
# default debounce algorithm will be applied
self.set_debounce(@scan_mode == :direct ? :per_key : :per_row) unless @debouncer

puts "Keyboard task started."
puts "Keyboard started"

# To avoid unintentional report on startup
# which happens only on Sparkfun Pro Micro RP2040
Expand Down
2 changes: 1 addition & 1 deletion src/ruby/app/models/rgb.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class RGB
def initialize(pin, underglow_size, backlight_size, is_rgbw = false)
puts "Initializing RGB."
puts "Init RGB"
turn_off
@fifo = Array.new
# TODO: @underglow_size, @backlight_size
Expand Down
2 changes: 1 addition & 1 deletion src/ruby/app/models/rotary_encoder.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class RotaryEncoder
def initialize(pin_a, pin_b)
puts "Initializing RotaryEncoder ..."
puts "Init RotaryEncoder"
@pin_a = pin_a
@pin_b = pin_b
@partner_keycode_cw = 0
Expand Down
2 changes: 1 addition & 1 deletion src/ruby/app/models/via.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class VIA
VIA_FILENAME = "VIA_MAP TXT"

def initialize
puts "Initializing VIA."
puts "Init VIA"
@layer_count = 5
@mode_keys = Hash.new
@keymap_saved = true
Expand Down
4 changes: 2 additions & 2 deletions src/ruby/app/tasks/rgb_task.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
puts "RGB task started."
puts "RGB started"

3.times { sleep 1 }
sleep 0.5

while true
unless $rgb
Expand Down
12 changes: 5 additions & 7 deletions src/ruby/app/tasks/usb_task.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
2000.times do
200.times do
tud_task
cdc_task
sleep_ms 2
end
print "\e[2J\e[1;1H" # clear all & home
puts "Welcome to PRK Firmware!\n\nTUD task started.\n"
puts "PRK Firmware started!\n\n"
autoreload_tick = 0

$mutex = false
Expand All @@ -14,16 +14,14 @@
cdc_task
if autoreload_ready?
if autoreload_tick == 0
puts "Autoreload is ready."
puts "Reloading keymap"
$rgb.turn_off if $rgb
puts "Suspending keymap."
suspend_keymap
report_hid(0, "\000\000\000\000\000\000")
autoreload_tick = 500
autoreload_tick = 200
elsif autoreload_tick == 1
puts "Trying to reload keymap."
reload_keymap
500.times do
10.times do
tud_task
cdc_task
sleep_ms 2
Expand Down

0 comments on commit c9c8892

Please sign in to comment.