basic layout generator

master
Stefan Dorn 2015-12-14 00:28:13 +00:00
parent 1cf945909d
commit 3121420267
3 changed files with 343 additions and 10 deletions

337
generate_layout.rb Executable file
View File

@ -0,0 +1,337 @@
#!/usr/bin/env ruby
# -*- encoding: utf-8 -*-
# Copyright muflax <mail@muflax.com>, 2015
# License: GNU GPLv3 (or later) <http://www.gnu.org/copyleft/gpl.html>
require "muflax"
LayoutDir = "src/keyboard/ergodox/layout"
LayoutFile = "#{LayoutDir}/saneo-mod_generated.c"
puts "generating #{LayoutFile}..."
Layer = Struct.new :code, :up, :down
class Key
attr_reader :layers
Layers = [ :basic, :mod3, :mod4, :mod5 ]
Functions = {
# down up
"basic" => [ "&kbfun_press_release", ],
"toggle" => [ "&kbfun_toggle", ],
"transparent" => [ "&kbfun_transparent", ],
# down up
"mod3" => [ "&kbfun_layer_push_1", "&kbfun_layer_pop_1" ],
"mod4" => [ "&kbfun_layer_push_2", "&kbfun_layer_pop_2" ],
"mod5" => [ "&kbfun_layer_push_3", "&kbfun_layer_pop_3" ],
"latch_mod3" => [ "&kbfun_layer_sticky_1", ],
"latch_mod4" => [ "&kbfun_layer_sticky_2", ],
"latch_mod5" => [ "&kbfun_layer_sticky_3", ],
# down up
"shifted" => [ "&kbfun_shift_press_release", ],
"ctrled" => [ "&kbfun_control_press_release", ],
"capslock" => [ "&kbfun_2_keys_capslock_press_release", ],
}
Keys = {
"a" => "KEY_a_A",
"b" => "KEY_b_B",
"c" => "KEY_c_C",
"d" => "KEY_d_D",
"e" => "KEY_e_E",
"f" => "KEY_f_F",
"g" => "KEY_g_G",
"h" => "KEY_h_H",
"i" => "KEY_i_I",
"j" => "KEY_j_J",
"k" => "KEY_k_K",
"l" => "KEY_l_L",
"m" => "KEY_m_M",
"n" => "KEY_n_N",
"o" => "KEY_o_O",
"p" => "KEY_p_P",
"q" => "KEY_q_Q",
"r" => "KEY_r_R",
"s" => "KEY_s_S",
"t" => "KEY_t_T",
"u" => "KEY_u_U",
"v" => "KEY_v_V",
"w" => "KEY_w_W",
"x" => "KEY_x_X",
"y" => "KEY_y_Y",
"z" => "KEY_z_Z",
#
"0" => "KEY_0_RightParenthesis",
"1" => "KEY_1_Exclamation",
"2" => "KEY_2_At",
"3" => "KEY_3_Pound",
"4" => "KEY_4_Dollar",
"5" => "KEY_5_Percent",
"6" => "KEY_6_Caret",
"7" => "KEY_7_Ampersand",
"8" => "KEY_8_Asterisk",
"9" => "KEY_9_LeftParenthesis",
#
"f1" => "KEY_F1",
"f2" => "KEY_F2",
"f3" => "KEY_F3",
"f4" => "KEY_F4",
"f5" => "KEY_F5",
"f6" => "KEY_F6",
"f7" => "KEY_F7",
"f8" => "KEY_F8",
"f9" => "KEY_F9",
"f10" => "KEY_F10",
"f11" => "KEY_F11",
"f12" => "KEY_F12",
"f13" => "KEY_F13",
"f14" => "KEY_F14",
"f15" => "KEY_F15",
"f16" => "KEY_F16",
"f17" => "KEY_F17",
"f18" => "KEY_F18",
"f19" => "KEY_F19",
"f20" => "KEY_F20",
"f21" => "KEY_F21",
"f22" => "KEY_F22",
"f23" => "KEY_F23",
"f24" => "KEY_F24",
#
"\\" => "KEY_Backslash_Pipe",
"[" => "KEY_LeftBracket_LeftBrace",
"]" => "KEY_RightBracket_RightBrace",
"," => "KEY_Comma_LessThan",
"-" => "KEY_Dash_Underscore",
"=" => "KEY_Equal_Plus",
"`" => "KEY_GraveAccent_Tilde",
"." => "KEY_Period_GreaterThan",
"\'" => "KEY_SingleQuote_DoubleQuote",
";" => "KEY_Semicolon_Colon",
"/" => "KEY_Slash_Question",
"~" => "KEY_GraveAccent_Tilde",
"%" => "KEY_5_Percent",
"*" => "KEY_8_Asterisk",
":" => "KEY_Semicolon_Colon",
#
"enter" => "KEY_ReturnEnter",
"space" => "KEY_Spacebar",
"tab" => "KEY_Tab",
"backspace" => "KEY_DeleteBackspace",
"delete" => "KEY_DeleteForward",
"home" => "KEY_Home",
"end" => "KEY_End",
"page_up" => "KEY_PageUp",
"page_down" => "KEY_PageDown",
"up" => "KEY_UpArrow",
"down" => "KEY_DownArrow",
"left" => "KEY_LeftArrow",
"right" => "KEY_RightArrow",
"escape" => "KEY_Escape",
"insert" => "KEY_Insert",
"menu" => "KEY_Application",
#
"alt" => "KEY_LeftAlt",
"alt_gr" => "KEY_RightAlt",
"umlaut" => "KEY_RightAlt",
"control" => "KEY_LeftControl",
"control_l" => "KEY_LeftControl",
"control_r" => "KEY_RightControl",
"win" => "KEY_LeftGUI",
"shift_l" => "KEY_LeftShift",
"shift_r" => "KEY_RightShift",
"scroll_lock" => "KEY_ScrollLock",
#
"mod3" => "NULL",
"mod4" => "NULL",
"mod5" => "NULL",
}
def initialize layers
@layers = layers.map do |key, type|
raise "key not found: #{key}" if not Keys.include? key and not key.nil?
raise "type not found: #{type}" if not Functions.include? type and not type.nil?
key = Keys[key] || "NULL"
up, down = Functions[type] || Functions["basic"]
down ||= up
Layer.new key, down, up
end
end
end
class Layout
def initialize name, keys
@name = name
@keys = keys
end
def keys_to_matrix method
Key::Layers.map.with_index do |_, layer|
"KB_MATRIX_LAYER(\n#{@keys.map{|key| key.layers[layer].send(method)}.join(",\n")}),\n"
end.join("\n")
end
def save! file
puts "saving #{@name}..."
header =<<HEADER
// ----------------------------------------------------------------------------
// ergoDOX layout : saneo (generated)
// ----------------------------------------------------------------------------
#include <stdint.h>
#include <stddef.h>
#include <avr/pgmspace.h>
#include "../../../lib/data-types/misc.h"
#include "../../../lib/usb/usage-page/keyboard--short-names.h"
#include "../../../lib/key-functions/public.h"
#include "../matrix.h"
#include "../layout.h"
// ----------------------------------------------------------------------------
HEADER
keys = keys_to_matrix :code
downs = keys_to_matrix :down
ups = keys_to_matrix :up
File.save(LayoutFile) do |f|
f.puts header
f.puts "const uint8_t PROGMEM _kb_layout[KB_LAYERS][KB_ROWS][KB_COLUMNS] = { #{keys} };"
f.puts "const void_funptr_t PROGMEM _kb_layout_press[KB_LAYERS][KB_ROWS][KB_COLUMNS] = { #{downs} };"
f.puts "const void_funptr_t PROGMEM _kb_layout_release[KB_LAYERS][KB_ROWS][KB_COLUMNS] = { #{ups} };"
end
end
end
keys = [
# letter type mod3 type mod4 type mod5 type
%w{ }, %w{ }, %w{ }, %w{ }, # dummy key
#
# left hand
# number
# letter type mod3 type mod4 type mod5 type
%w{ 0 }, %w{ }, %w{ }, %w{ }, # 1.5
%w{ 1 }, %w{ }, %w{ }, %w{ },
%w{ 2 }, %w{ }, %w{ }, %w{ },
%w{ 3 }, %w{ }, %w{ }, %w{ },
%w{ 4 }, %w{ }, %w{ }, %w{ },
%w{ 5 }, %w{ }, %w{ }, %w{ },
%w{ 6 }, %w{ }, %w{ }, %w{ },
# top
# letter type mod3 type mod4 type mod5 type
%w{ x }, %w{ }, %w{ }, %w{ }, # 1.5
%w{ x }, %w{ ~ }, %w{ escape }, %w{ },
%w{ v }, %w{ }, %w{ }, %w{ },
%w{ l }, %w{ }, %w{ }, %w{ },
%w{ c }, %w{ }, %w{ }, %w{ },
%w{ w }, %w{ }, %w{ }, %w{ },
%w{ }, %w{ }, %w{ }, %w{ }, # 1.5
# home
# letter type mod3 type mod4 type mod5 type
%w{ umlaut }, %w{ }, %w{ }, %w{ }, # 1.5
%w{ u }, %w{ }, %w{ }, %w{ },
%w{ i }, %w{ }, %w{ }, %w{ },
%w{ a }, %w{ }, %w{ }, %w{ },
%w{ e }, %w{ }, %w{ }, %w{ },
%w{ o }, %w{ }, %w{ }, %w{ },
# bottom
# letter type mod3 type mod4 type mod5 type
%w{ shift_l }, %w{ }, %w{ }, %w{ }, # 1.5
%w{ % }, %w{ }, %w{ }, %w{ },
%w{ * }, %w{ }, %w{ }, %w{ },
%w{ : }, %w{ }, %w{ }, %w{ },
%w{ p }, %w{ }, %w{ }, %w{ },
%w{ z }, %w{ }, %w{ }, %w{ },
%w{ enter }, %w{ }, %w{ }, %w{ }, # 1.5
# underbottom
# letter type mod3 type mod4 type mod5 type
%w{ left }, %w{ }, %w{ }, %w{ },
%w{ up }, %w{ }, %w{ }, %w{ },
%w{ down }, %w{ }, %w{ }, %w{ },
%w{ right }, %w{ }, %w{ }, %w{ },
%w{ win }, %w{ }, %w{ }, %w{ },
# thumb-top
# letter type mod3 type mod4 type mod5 type
%w{ scroll_lock }, %w{ }, %w{ }, %w{ },
%w{ scroll_lock }, %w{ }, %w{ }, %w{ },
# thumb-double
# letter type mod3 type mod4 type mod5 type
%w{ space }, %w{ }, %w{ }, %w{ },
%w{ control }, %w{ }, %w{ }, %w{ },
%w{ alt }, %w{ }, %w{ }, %w{ },
# thumb-home
# letter type mod3 type mod4 type mod5 type
%w{ space }, %w{ }, %w{ }, %w{ },
%w{ control }, %w{ }, %w{ }, %w{ },
%w{ alt }, %w{ }, %w{ }, %w{ },
#
# right hand
#
# number
# letter type mod3 type mod4 type mod5 type
%w{ 5 }, %w{ }, %w{ }, %w{ }, # 1.5
%w{ 6 }, %w{ }, %w{ }, %w{ },
%w{ 7 }, %w{ }, %w{ }, %w{ },
%w{ 8 }, %w{ }, %w{ }, %w{ },
%w{ 9 }, %w{ }, %w{ }, %w{ },
%w{ 0 }, %w{ }, %w{ }, %w{ },
%w{ 0 }, %w{ }, %w{ }, %w{ },
# top
# letter type mod3 type mod4 type mod5 type
%w{ }, %w{ }, %w{ }, %w{ }, # 1.5
%w{ k }, %w{ }, %w{ }, %w{ },
%w{ h }, %w{ }, %w{ }, %w{ },
%w{ g }, %w{ }, %w{ }, %w{ },
%w{ f }, %w{ }, %w{ }, %w{ },
%w{ q }, %w{ }, %w{ }, %w{ },
%w{ q }, %w{ }, %w{ }, %w{ }, # 1.5
# home
# letter type mod3 type mod4 type mod5 type
%w{ s }, %w{ }, %w{ }, %w{ },
%w{ n }, %w{ }, %w{ }, %w{ },
%w{ r }, %w{ }, %w{ }, %w{ },
%w{ t }, %w{ }, %w{ }, %w{ },
%w{ d }, %w{ }, %w{ }, %w{ },
%w{ umlaut }, %w{ }, %w{ }, %w{ }, # 1.5
# bottom
# letter type mod3 type mod4 type mod5 type
%w{ enter }, %w{ }, %w{ }, %w{ }, # 1.5
%w{ b }, %w{ }, %w{ }, %w{ },
%w{ m }, %w{ }, %w{ }, %w{ },
%w{ j }, %w{ }, %w{ }, %w{ },
%w{ y }, %w{ }, %w{ }, %w{ },
%w{ ; }, %w{ }, %w{ }, %w{ },
%w{ shift_r }, %w{ }, %w{ }, %w{ }, # 1.5
# underbottom
# letter type mod3 type mod4 type mod5 type
%w{ mod4 }, %w{ }, %w{ }, %w{ },
%w{ left }, %w{ }, %w{ }, %w{ },
%w{ up }, %w{ }, %w{ }, %w{ },
%w{ down }, %w{ }, %w{ }, %w{ },
%w{ right }, %w{ }, %w{ }, %w{ },
# thumb-top
# letter type mod3 type mod4 type mod5 type
%w{ }, %w{ }, %w{ }, %w{ },
%w{ }, %w{ }, %w{ }, %w{ },
# thumb-double
# letter type mod3 type mod4 type mod5 type
%w{ menu }, %w{ }, %w{ }, %w{ },
%w{ alt }, %w{ }, %w{ }, %w{ },
%w{ mod3 }, %w{ }, %w{ }, %w{ },
# thumb-home
# letter type mod3 type mod4 type mod5 type
%w{ menu }, %w{ }, %w{ }, %w{ },
%w{ alt }, %w{ }, %w{ }, %w{ },
%w{ mod3 }, %w{ }, %w{ }, %w{ },
].each_slice(Key::Layers.size).map do |layers|
Key.new layers
end
ap keys
saneo = Layout.new :saneo, keys
saneo.save! LayoutFile

View File

@ -2,20 +2,15 @@
# makefile for the ergoDOX project
# -----------------------------------------------------------------------------
# directories
BUILD := build
ROOT := $(BUILD)/$(TARGET)
SCRIPTS := build-scripts
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
.PHONY: all clean firmware
.PHONY: all clean firmware layout
all: firmware
clean:
cd src; $(MAKE) clean
firmware: clean
firmware: clean layout
cd src; $(MAKE) all
layout:
./generate_layout.rb

View File

@ -0,0 +1 @@
saneo-mod.h