Rabbit Slide Show

PRK Firmware: Keyboard is Essentially Ruby

2021-09-10

Description

Presentation slide for RubyKaigi Takeout 2021

Text

Page: 1

PRK Firmware
Keyboard is
Essentially Ruby
Hitoshi HASUMI
RubyKaigi Takeout 2021 | Sep 10th

Page: 2

Acknowledgement

Page: 3

Acknowledgement
“You are able to build Ruby by yourself”
[cited from `YOU COULD SAY DIY-KEYBOARD IS ESSENTIALLY RUBY']

Page: 4

Acknowledgement
“You are able to build a keyboard by yourself”
[cited from `YOU COULD SAY DIY-KEYBOARD IS ESSENTIALLY RUBY']

Page: 5

Acknowledgement
“YOU COULD SAY
DIY-KEYBOARD IS
ESSENTIALLY RUBY”
[cited from `YOU COULD SAY DIY-KEYBOARD IS ESSENTIALLY RUBY']

Page: 6

Exactly one year ago

Page: 7

Exactly one year ago

Page: 8

Keyboard firmware ... language
QMK Firmware ... C
KMK Firmware ... Python
PRK Firmware ... Ruby

Page: 9

Keyboard firmware ... repository

Page: 10

Keyboard firmware

Page: 11

PRK Firmware - How to start
Buy a DIY Keyboard kit
Which uses Pro Micro
Pro Micro?
Arduino compatible board
PRK Firmware doesn't work on
"normal" Pro Micro (AVR processor)
https://www.switch-science.com/catalog/3914/

Page: 12

PRK Firmware - How to start
Instead, choose
SPARKFUN PRO MICRO - RP2040
[model no. DEV-17717]
https://www.sparkfun.com/products/17717

Page: 13

PRK Firmware - How to start
RP2040?
"Raspberry Silicon"
Implemented on Raspberry Pi Pico
The target chip of PRK Firmware
https://pc.watch.impress.co.jp/docs/news/1301670.html

Page: 14

Troubleshooting of Pro Micro RP2040
Logic level (depending on PCB)
Pro Micro RP2040 may crash
if VCC and RAW are connected
Ask keyboard lovers to check it
Shortage of conthrough's height
if you build an "upside down" type
Use XB-3-6-6P on akizukidenshi.com

Page: 15

PRK Firmware - How to start
Ask Rubyists on Twitter
@takkanm
@swan_match
@kakutani
@hasumikin (me), etc.
Join #keyboard in ruby-jp Slack

Page: 16

e.g.) picoruby/prk_pipigherkin
Gherkin for
the Raspberry Pi Pico
PCB available
on talpkeyboard.net
Easy to explain but
hard for newbies to build
https://www.40percent.club/2021/02/pipi-gherkin.html

Page: 17

e.g.) prk_pipigherkin/keymap.rb
# Initialize Keyboard
kbd = Keyboard.new
# Initialize GPIO pins
kbd.init_pins(
[ 12, 11, 10, 9, 8 ], # row0, row1,... respectively
[ 7, 6, 5, 4, 3, 2 ] # col0, col1,... respectively
)
# Default keymap
kbd.add_layer :default, %i(
KC_Q
KC_W
KC_E
KC_R
KC_T
KC_Y
KC_U
KC_I
KC_A
KC_S
KC_D
KC_F
KC_G
KC_H
KC_J
KC_K
Z_LSFT X_LGUI C_LALT V_LCTL SPC_LOWER ENT_RAISE B_RCTL N_RALT
)
# Mode keys
kbd.define_mode_key :Z_LSFT,
[ :KC_Z,
:KC_LSFT, 150, 150
# ...
kbd.define_mode_key :UNDS_RSFT, [ :KC_UNDS, :KC_RSFT, 200, 150
150, 150
kbd.define_mode_key :ENT_RAISE, [ :KC_ENTER, :raise,
kbd.define_mode_key :SPC_LOWER, [ :KC_SPACE, :lower,
300, 250
KC_O
KC_P
KC_L
KC_BSPACE
M_RGUI UNDS_RSFT
]
]
]
]

Page: 18

e.g.) prk_pipigherkin/keymap.rb
kbd.add_layer :raise,
KC_EXLM KC_AT
KC_LABK KC_LCBR
KC_RABK KC_RCBR
)
kbd.add_layer :lower,
KC_1
KC_2
KC_TAB
KC_NO
KC_ESCAPE KC_LGUI
)
%i(
KC_HASH
KC_DLR
KC_LBRACKET KC_LPRN
KC_RBRACKET KC_RPRN KC_PERC
KC_MINUS
ADJUST
%i(
KC_3
KC_QUOTE
KC_LALT KC_5
KC_6
KC_MINUS KC_GRAVE
SPC_LOWER ADJUST
KC_4
KC_DQUO
KC_LCTL
KC_CIRC
KC_AMPR KC_ASTER KC_EQUAL KC_PLUS
KC_LEFT
KC_DOWN KC_UP
KC_RIGHT KC_BSPACE
ENT_RAISE KC_BSLASH KC_COMMA KC_DOT
KC_SLASH
KC_7
KC_TILD
KC_RCTL
KC_8
KC_PIPE
KC_RALT
KC_9
KC_0
KC_COLON KC_SCOLON
KC_RGUI KC_RSFT

Page: 19

picoruby/prk_firmware/releases

Page: 20

Install uf2 into RP2040
Connect USB cable while
pressing "boot button"
RPI-RP2 will be mounted
as a storage, then
https://www.raspberrypi.org/documentation/rp2040/getting-started

Page: 21

Install uf2 into RP2040

Page: 22

Install uf2 into RP2040

Page: 23

Automatically mounts!!!!!!!!

Page: 24

Drag & drop -> Automatically reloads!

Page: 25

Unlike QMK Firmware,
You don't need
to compile
anything!

Page: 26

Technology behind PRK Firmware
Compiler and Virtual machine

Page: 27

Technology behind PRK Firmware
PicoRuby
PicoRuby compiler + mruby/c VM
Ruby Association Grant
https://www.ruby.or.jp/ja/news/20210715

Page: 28

e.g.) picoruby/prk_crkbd

Page: 29

e.g.) prk_crkbd/keymap.rb
kbd = Keyboard.new
# (init_pins, add_layer etc., then)
rgb = RGB.new(
# pin number
0,
6,
# size of underglow LED
21
# size of backlight LED
)
rgb.effect = :rainbow # or :breathing
kbd.append rgb
kbd.start!

Page: 30

e.g.) prk_crkbd/keymap.rb
If you wanna input ";" with SHIFT and ":" without SHIFT,
kbd.before_report do
kbd.invert_sft if kbd.keys_include?(:KC_SCOLON)
end
You no longer need to modify .vimrc

Page: 31

You can write invert_ctl in keymap.rb
class Keyboard
def invert_ctl
#
KC_LCTL: 0b00000001
#
KC_LSFT: 0b00000010
#
KC_LALT: 0b00000100
#
KC_LGUI: 0b00001000
#
KC_RCTL: 0b00010000
#
KC_RSFT: 0b00100000
#
KC_RALT: 0b01000000
#
KC_RGUI: 0b10000000
if (@modifier & 0b00010001) > 0
@modifier &= 0b11101110
else
@modifier |= 0b00000001
end
end
end
kbd.before_report do
kbd.invert_ctl if kbd.keys_include?(:KC_V)
end

Page: 32

Fibonacci number
(DEMO)

Page: 33

Fibonacci number
1
2
3
5
8
13
21
34
55
89
144
233
377
....

Page: 34

Fibonacci in keymap.rb
class Fibonacci
def initialize
@a = 0 ; @b = 1
end
# Omits F0 and F1
def take
result = @a + @b
@a = @b
@b = result
end
end
fibonacci = Fibonacci.new
kbd.define_mode_key :FIBONACCI,
[ Proc.new { kbd.macro fibonacci.take },
:KC_NO, 300, nil ]

Page: 35

Password generator in keymap.rb
class Password
def initialize
@c = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_!@#$%^&*()=-+/[]{}<>'
end
def generate
unless @srand
srand(board_millis) # generate rand()'s seed by board_millis
@srand = true
end
password = ""
while true
i = rand % 100
password << @c[i].to_s
break if password.length == 8
end
return password
end
end
password = Password.new
kbd.define_mode_key :PASSWD, [ Proc.new { kbd.macro password.generate, [] }, :KC_NO, 300, nil ]

Page: 36

By the way,

Page: 37

What do you think is
the No.1 text editor?

Page: 38

vim?

Page: 39

emacs?

Page: 40

textbringer?

Page: 41


        

Page: 42

Copyright © Microsoft

Page: 43

PicoRuby Compiler on Board
(DEMO)

Page: 44

PicoRuby Compiler on Board
Multitasking of mruby/c

Page: 45

PicoRuby Compiler on Board
Sandbox task is never freed!

Page: 46

So,

Page: 47

You could say

Page: 48

Keyboard is
Essentially
Ruby

Page: 49

Future work
WebUSB serial
(like Remap)
IoT, Robot
Smalruby
mruby Girls
https://remap-keys.app/catalog/gE11SshmfVPRGXEQZ6SC/keymap

Page: 50

Conclusion
PRK Firmware is the world's
first keyboard firmware in Ruby
You can not only write your keymap
but also make your keyboard
more than a keyboard

Page: 51

Code Ruby with
a keyboard that
runs on Ruby

Page: 52

Happy Coding!

Page: 53

Thank you!!!q

Other slides