Skip to content

Commit

Permalink
makes keymap submodule
Browse files Browse the repository at this point in the history
  • Loading branch information
hasumikin committed Apr 5, 2021
1 parent 3a28015 commit 400ed72
Show file tree
Hide file tree
Showing 12 changed files with 105 additions and 133 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
tags
build/*
!build/.keep
22 changes: 11 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,27 @@ pico_sdk_init()

# rest of your project

add_subdirectory(./lib)
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/lib)

add_executable(prk_firmware src/main.c src/usb.c)

set(RBC ${CMAKE_CURRENT_SOURCE_DIR}/lib/picoruby/build/host-production/bin/picorbc)
#set(RBC RBENV_VERSION=mruby-2.1.1 mrbc -E)

add_custom_target(ruby
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/lib/picoruby/build/host-production/bin/picorbc -Bled led.rb
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/lib/picoruby/build/host-production/bin/picorbc -Bkeyboard keyboard.rb
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/lib/picoruby/build/host-production/bin/picorbc -Btud tud.rb
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/lib/picoruby/build/host-production/bin/picorbc -Bkeymap keymap.rb
#COMMAND RBENV_VERSION=mruby-2.1.1 mrbc -E -Bled led.rb
#COMMAND RBENV_VERSION=mruby-2.1.1 mrbc -E -Bkeyboard keyboard.rb
#COMMAND RBENV_VERSION=mruby-2.1.1 mrbc -E -Btud tud.rb
#COMMAND RBENV_VERSION=mruby-2.1.1 mrbc -E -Bkeymap keymap.rb
WORKING_DIRECTORY ../src/ruby
COMMAND ${RBC} -Bled led.rb
COMMAND ${RBC} -Bkeyboard keyboard.rb
COMMAND ${RBC} -Btud tud.rb
COMMAND ${RBC} -Bkeymap ${PROJECT_BINARY_DIR}/keymap.rb
COMMAND cp ${PROJECT_BINARY_DIR}/keymap.c ./
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/src/ruby
)

add_dependencies(prk_firmware picoruby ruby)

target_link_libraries(prk_firmware pico_stdlib tinyusb_device tinyusb_board picoruby)

include_directories(prk_firmware PRIVATE ${CMAKE_CURRENT_LIST_DIR} ./lib/picoruby/src/mrubyc/src)
include_directories(prk_firmware PRIVATE ${CMAKE_CURRENT_LIST_DIR} ${CMAKE_CURRENT_LIST_DIR}/include ${CMAKE_CURRENT_LIST_DIR}/lib/picoruby/src/mrubyc/src)

# create map/bin/hex/uf2 file in addition to ELF.
pico_add_extra_outputs(prk_firmware)
45 changes: 45 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
## PRK firmware (public beta)

PRK is a keyboard firmware written and configured in [PicoRuby](https://github.com/hasumikin/picoruby) which is an alternative mruby implementation targeting on one-chip microcontroller.

### Features

- A "keymap" can be configured in Ruby which is a concise, readable and happy language
- Raspberry Pi Pico is the platform microcontroller
- You can write your own "action" which will be invoked when you tap or hold a key ([example]()(TBD))

### Getting started

- Setup Raspberry Pi Pico C/C++ SDK

- Follow the instructions on [https://github.com/raspberrypi/pico-sdk#quick-start-your-own-project](https://github.com/raspberrypi/pico-sdk#quick-start-your-own-project)

- Be knowledgeable how to install a UF2 file into Raspi Pico on [https://www.raspberrypi.org/documentation/rp2040/getting-started/#getting-started-with-c](https://www.raspberrypi.org/documentation/rp2040/getting-started/#getting-started-with-c)

- Clone the `prk_firmware` (this repository) wherever you like

```
git clone --recursive https://github.com/hasumikin/prk_firmware.git # Don't forget --recursive
cd prk_firmware
```
- Clone a keymap repository, for example, "meishi2" which is a 2x2 matrix card-shaped keyboard in `keyboards` directory
```
cd keyboards
git clone https://github.com/hasumikin/prk_meishi2.git
```
- Build with `cmake`
```
cd prk_meishi2
cmake ../..
build
```
Now you should have `prk_firmware.uf2` file in `prk_firmware/keyboards/prk_meishi2` directory.
### License
Copyright © 2021 HASUMI Hitoshi. See MIT-LICENSE for further details.
Empty file removed build/.keep
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions keyboards/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore
10 changes: 3 additions & 7 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,17 @@ add_library(picoruby STATIC

add_custom_target(picorbc
COMMAND make host_production
WORKING_DIRECTORY ../../lib/picoruby
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/picoruby
)

add_custom_target(ptr_size
COMMAND make
WORKING_DIRECTORY ../../lib/picoruby/src/include
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/picoruby/src/include
)
add_custom_target(tokenizer_helper
COMMAND make tokenizer_helper.h
WORKING_DIRECTORY ../../lib/picoruby/src
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/picoruby/src
)
#add_custom_target(parse
# COMMAND make
# WORKING_DIRECTORY ../../lib/picoruby/src/ruby-lemon-parse
#)
add_dependencies(picoruby picorbc ptr_size tokenizer_helper)

target_link_libraries(picoruby pico_stdlib)
Expand Down
74 changes: 44 additions & 30 deletions src/ruby/keyboard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -222,24 +222,6 @@ def add_layer(name, map)
@layer_names << name
end

def raise_layer
current_index = @layer_names.index(@locked_layer_name)
if current_index < @layer_names.size - 1
@locked_layer_name = @layer_names[current_index + 1]
else
@locked_layer_name = @layer_names.first
end
end

def lower_layer
current_index = @layer_names.index(@locked_layer_name)
if current_index == 0
@locked_layer_name = @layer_names.last
else
@locked_layer_name = @layer_names[current_index - 1]
end
end

# param[0] :on_release
# param[1] :on_hold
# param[2] :release_threshold
Expand All @@ -249,16 +231,12 @@ def define_mode_key(key_name, param)
map.each_with_index do |row, row_index|
row.each_with_index do |key_symbol, col_index|
if key_name == key_symbol
on_release = nil
if KEYCODE[param[0]]
on_release = KEYCODE[param[0]] * -1
else
on_release = param[0]
end
on_release = KEYCODE[param[0]] ? (KEYCODE[param[0]] * -1) : param[0]
on_hold = MOD_KEYCODE[param[1]] ? MOD_KEYCODE[param[1]] : param[1]
@mode_keys << {
layer_name: layer_name,
on_release: on_release,
on_hold: param[1],
on_hold: on_hold,
release_threshold: (param[2] || 0),
repush_threshold: (param[3] || 0),
switch: [row_index, col_index],
Expand Down Expand Up @@ -301,18 +279,19 @@ def before_report(&block)

def action_on_release(mode_key)
case mode_key.class
when Fixnum
when Fixnum # should be a normal key
@keycodes << (mode_key * -1).chr
when Proc
mode_key.call
end
end

def action_on_hold(mode_key)
if MOD_KEYCODE[mode_key]
@modifier |= MOD_KEYCODE[mode_key]
else # assumes layer key
@layer_name = mode_key
case mode_key.class
when Fixnum # should be a modifier key
@modifier |= mode_key
when Proc
mode_key.call
end
end

Expand Down Expand Up @@ -402,6 +381,41 @@ def start!
end
end

#
# Actions can be used in keymap.rb
#

# Raises layer and keeps it
def raise_layer
current_index = @layer_names.index(@locked_layer_name)
if current_index < @layer_names.size - 1
@locked_layer_name = @layer_names[current_index + 1]
else
@locked_layer_name = @layer_names.first
end
end

# Lowers layer and keeps it
def lower_layer
current_index = @layer_names.index(@locked_layer_name)
if current_index == 0
@locked_layer_name = @layer_names.last
else
@locked_layer_name = @layer_names[current_index - 1]
end
end

# Holds specified layer while pressed
def hold_layer(layer_name)
@layer_name = layer_name
end

# Switch to specified layer
def switch_layer(layer_name)
@locked_layer_name = layer_name
end


end

$mutex.unlock
76 changes: 0 additions & 76 deletions src/ruby/keymap.rb

This file was deleted.

7 changes: 0 additions & 7 deletions src/usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,6 @@ c_tud_task(mrb_vm *vm, mrb_value *v, int argc)
void
c_report_hid(mrb_vm *vm, mrb_value *v, int argc)
{
// // Poll every 10ms
// const uint32_t interval_ms = 10;
// static uint32_t start_ms = 0;
//
// if (board_millis() - start_ms < interval_ms) return; // not enough time
// start_ms += interval_ms;

uint32_t const btn = 1;

// Remote wakeup
Expand Down

0 comments on commit 400ed72

Please sign in to comment.