Signed-off-by: Jesse Vincent <jesse@keyboard.io>pull/459/head
parent
99fdc3776f
commit
d96ac86454
@ -0,0 +1,2 @@
|
|||||||
|
DEFAULT_SKETCH="Planck"
|
||||||
|
BOARD="planck"
|
@ -0,0 +1,55 @@
|
|||||||
|
# This stub makefile for a Kaleidoscope example pulls in all the targets
|
||||||
|
# required to build the example
|
||||||
|
|
||||||
|
UNAME_S := $(shell uname -s)
|
||||||
|
|
||||||
|
ifeq ($(UNAME_S),Darwin)
|
||||||
|
SKETCHBOOK_DIR ?= $(HOME)/Documents/Arduino
|
||||||
|
PACKAGE_DIR ?= $(HOME)/Library/Arduino15
|
||||||
|
else
|
||||||
|
SKETCHBOOK_DIR ?= $(HOME)/Arduino
|
||||||
|
PACKAGE_DIR ?= $(HOME)/.arduino15
|
||||||
|
endif
|
||||||
|
|
||||||
|
|
||||||
|
ARDUINO_INSTALLED_ENV=$(shell ls -dt $(PACKAGE_DIR)/packages/keyboardio/hardware/avr 2>/dev/null |head -n 1)
|
||||||
|
MANUALLY_INSTALLED_ENV=$(shell ls -dt $(SKETCHBOOK_DIR)/hardware/keyboardio/avr 2>/dev/null |head -n 1)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
ifneq ("$(wildcard $(ARDUINO_INSTALLED_ENV)/boards.txt)","")
|
||||||
|
|
||||||
|
ifneq ("$(wildcard $(MANUALLY_INSTALLED_ENV)/boards.txt)","")
|
||||||
|
|
||||||
|
$(info ***************************************************************************)
|
||||||
|
$(info It appears that you have installed two copies of Kaleidoscope. One copy was)
|
||||||
|
$(info installed using Arduino's "Board Manager", while the other was installed by)
|
||||||
|
$(info hand, probably using "git".)
|
||||||
|
$(info )
|
||||||
|
$(info This will likely cause some trouble as you try to build keyboard firmware)
|
||||||
|
$(info using Kaleidoscope. You may want to remove either: )
|
||||||
|
$(info )
|
||||||
|
$(info $(PACKAGE_DIR)/packages/keyboardio/ which was installed using Arduino)
|
||||||
|
$(info )
|
||||||
|
$(info or)
|
||||||
|
$(info )
|
||||||
|
$(info $(SKETCHBOOK_DIR)/hardware/keyboardio/ which was installed by hand.)
|
||||||
|
$(info )
|
||||||
|
$(info ***************************************************************************)
|
||||||
|
$(info )
|
||||||
|
|
||||||
|
endif
|
||||||
|
|
||||||
|
BOARD_HARDWARE_PATH = $(ARDUINO_INSTALLED_ENV)
|
||||||
|
KALEIDOSCOPE_PLUGIN_MAKEFILE_DIR ?= build-tools/makefiles/
|
||||||
|
KALEIDOSCOPE_BUILDER_DIR ?= $(ARDUINO_INSTALLED_ENV)/libraries/Kaleidoscope/bin/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
endif
|
||||||
|
|
||||||
|
|
||||||
|
BOARD_HARDWARE_PATH ?= $(SKETCHBOOK_DIR)/hardware
|
||||||
|
KALEIDOSCOPE_PLUGIN_MAKEFILE_DIR ?= keyboardio/avr/build-tools/makefiles/
|
||||||
|
|
||||||
|
include $(BOARD_HARDWARE_PATH)/$(KALEIDOSCOPE_PLUGIN_MAKEFILE_DIR)/rules.mk
|
@ -0,0 +1,175 @@
|
|||||||
|
/* -*- mode: c++ -*-
|
||||||
|
* Planck -- A very basic Kaleidoscope example for the OLKB Planck keyboard
|
||||||
|
* Copyright (C) 2018 Keyboard.io, Inc
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTabILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "Kaleidoscope.h"
|
||||||
|
#include "Kaleidoscope-Macros.h"
|
||||||
|
|
||||||
|
enum { _QWERTY,
|
||||||
|
_COLEMAK,
|
||||||
|
_DVORAK,
|
||||||
|
_LOWER,
|
||||||
|
_RAISE,
|
||||||
|
_PLOVER,
|
||||||
|
_ADJUST
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/* *INDENT-OFF* */
|
||||||
|
KEYMAPS(
|
||||||
|
|
||||||
|
/* Qwerty
|
||||||
|
* ,-----------------------------------------------------------------------------------.
|
||||||
|
* | Tab | Q | W | E | R | T | Y | U | I | O | P | Bksp |
|
||||||
|
* |------+------+------+------+------+-------------+------+------+------+------+------|
|
||||||
|
* | Esc | A | S | D | F | G | H | J | K | L | ; | " |
|
||||||
|
* |------+------+------+------+------+------|------+------+------+------+------+------|
|
||||||
|
* | Shift| Z | X | C | V | B | N | M | , | . | / |Enter |
|
||||||
|
* |------+------+------+------+------+------+------+------+------+------+------+------|
|
||||||
|
* | Brite| Ctrl | Alt | GUI |Lower | Space |Raise | Left | Down | Up |Right |
|
||||||
|
* `-----------------------------------------------------------------------------------'
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
[_QWERTY] = KEYMAP(
|
||||||
|
Key_Tab, Key_Q, Key_W, Key_E, Key_R, Key_T, Key_Y, Key_U, Key_I, Key_O, Key_P, Key_Backspace,
|
||||||
|
Key_Escape, Key_A, Key_S, Key_D, Key_F, Key_G, Key_H, Key_J, Key_K, Key_L, Key_Semicolon, Key_Quote,
|
||||||
|
Key_LeftShift, Key_Z, Key_X, Key_C, Key_V, Key_B, Key_N, Key_M, Key_Comma, Key_Period, Key_Slash, Key_Enter ,
|
||||||
|
___, Key_LeftControl, Key_LeftAlt, Key_LeftGui, LockLayer(_LOWER), Key_Space, Key_Space, LockLayer(_RAISE), Key_LeftArrow, Key_DownArrow, Key_UpArrow, Key_RightArrow
|
||||||
|
|
||||||
|
),
|
||||||
|
/* Colemak
|
||||||
|
* ,-----------------------------------------------------------------------------------.
|
||||||
|
* | Tab | Q | W | F | P | G | J | L | U | Y | ; | Bksp |
|
||||||
|
* |------+------+------+------+------+-------------+------+------+------+------+------|
|
||||||
|
* | Esc | A | R | S | T | D | H | N | E | I | O | " |
|
||||||
|
* |------+------+------+------+------+------|------+------+------+------+------+------|
|
||||||
|
* | Shift| Z | X | C | V | B | K | M | , | . | / |Enter |
|
||||||
|
* |------+------+------+------+------+------+------+------+------+------+------+------|
|
||||||
|
* | Brite| Ctrl | Alt | GUI |Lower | Space |Raise | Left | Down | Up |Right |
|
||||||
|
* `-----------------------------------------------------------------------------------'
|
||||||
|
*/
|
||||||
|
[_COLEMAK] = KEYMAP(
|
||||||
|
Key_Tab, Key_Q, Key_W, Key_F, Key_P, Key_G, Key_J, Key_L, Key_U, Key_Y, Key_Semicolon, Key_Backspace,
|
||||||
|
Key_Escape, Key_A, Key_R, Key_S, Key_T, Key_D, Key_H, Key_N, Key_E, Key_I, Key_O, Key_Quote,
|
||||||
|
Key_LeftShift, Key_Z, Key_X, Key_C, Key_V, Key_B, Key_K, Key_M, Key_Comma, Key_Period, Key_Slash, Key_Enter ,
|
||||||
|
___, Key_LeftControl, Key_LeftAlt, Key_LeftGui, ShiftToLayer(_LOWER), Key_Space, Key_Space, ShiftToLayer(_RAISE), Key_LeftArrow, Key_DownArrow, Key_UpArrow, Key_RightArrow
|
||||||
|
),
|
||||||
|
|
||||||
|
/* Dvorak
|
||||||
|
* ,-----------------------------------------------------------------------------------.
|
||||||
|
* | Tab | " | , | . | P | Y | F | G | C | R | L | Bksp |
|
||||||
|
* |------+------+------+------+------+-------------+------+------+------+------+------|
|
||||||
|
* | Esc | A | O | E | U | I | D | H | T | N | S | / |
|
||||||
|
* |------+------+------+------+------+------|------+------+------+------+------+------|
|
||||||
|
* | Shift| ; | Q | J | K | X | B | M | W | V | Z |Enter |
|
||||||
|
* |------+------+------+------+------+------+------+------+------+------+------+------|
|
||||||
|
* | Brite| Ctrl | Alt | GUI |Lower | Space |Raise | Left | Down | Up |Right |
|
||||||
|
* `-----------------------------------------------------------------------------------'
|
||||||
|
*/
|
||||||
|
[_DVORAK] = KEYMAP(
|
||||||
|
Key_Tab, Key_Quote, Key_Comma, Key_Period, Key_P, Key_Y, Key_F, Key_G, Key_C, Key_R, Key_L, Key_Backspace,
|
||||||
|
Key_Escape, Key_A, Key_O, Key_E, Key_U, Key_I, Key_D, Key_H, Key_T, Key_N, Key_S, Key_Slash,
|
||||||
|
Key_LeftShift, Key_Semicolon, Key_Q, Key_J, Key_K, Key_X, Key_B, Key_M, Key_W, Key_V, Key_Z, Key_Enter ,
|
||||||
|
___, Key_LeftControl, Key_LeftAlt, Key_LeftGui, LockLayer(_LOWER), Key_Space, Key_Space, LockLayer(_RAISE), Key_LeftArrow, Key_DownArrow, Key_UpArrow, Key_RightArrow
|
||||||
|
),
|
||||||
|
/* Lower
|
||||||
|
* ,-----------------------------------------------------------------------------------.
|
||||||
|
* | ~ | ! | @ | # | $ | % | ^ | & | * | ( | ) | Bksp |
|
||||||
|
* |------+------+------+------+------+-------------+------+------+------+------+------|
|
||||||
|
* | Del | F1 | F2 | F3 | F4 | F5 | F6 | _ | + | { | } | | |
|
||||||
|
* |------+------+------+------+------+------|------+------+------+------+------+------|
|
||||||
|
* | | F7 | F8 | F9 | F10 | F11 | F12 |ISO ~ |ISO | | Home | End | |
|
||||||
|
* |------+------+------+------+------+------+------+------+------+------+------+------|
|
||||||
|
* | | | | | | | | Next | Vol- | Vol+ | Play |
|
||||||
|
* `-----------------------------------------------------------------------------------'
|
||||||
|
*/
|
||||||
|
[_LOWER] = KEYMAP(
|
||||||
|
LSHIFT(Key_Backtick), LSHIFT(Key_1), LSHIFT(Key_2), LSHIFT(Key_3), LSHIFT(Key_4), LSHIFT(Key_5), LSHIFT(Key_6), LSHIFT(Key_7), LSHIFT(Key_8), LSHIFT(Key_9), LSHIFT(Key_0), Key_Backspace,
|
||||||
|
Key_Delete, Key_F1, Key_F2, Key_F3, Key_F4, Key_F5, Key_F6, LSHIFT(Key_Minus), LSHIFT(Key_Equals), Key_LeftBracket, Key_RightBracket, Key_Pipe,
|
||||||
|
___, Key_F7, Key_F8, Key_F9, Key_F10, Key_F11, Key_F12, LSHIFT(Key_NonUsPound), LSHIFT(Key_NonUsBackslashAndPipe), Key_Home, Key_End, ___,
|
||||||
|
___, ___, ___, ___, ___, ___, ___, ___, Consumer_ScanNextTrack, Consumer_VolumeDecrement, Consumer_VolumeIncrement, Consumer_PlaySlashPause
|
||||||
|
),
|
||||||
|
|
||||||
|
/* Raise
|
||||||
|
* ,-----------------------------------------------------------------------------------.
|
||||||
|
* | ` | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | Bksp |
|
||||||
|
* |------+------+------+------+------+-------------+------+------+------+------+------|
|
||||||
|
* | Del | F1 | F2 | F3 | F4 | F5 | F6 | - | = | [ | ] | \ |
|
||||||
|
* |------+------+------+------+------+------|------+------+------+------+------+------|
|
||||||
|
* | | F7 | F8 | F9 | F10 | F11 | F12 |ISO # |ISO / |Pg Up |Pg Dn | |
|
||||||
|
* |------+------+------+------+------+------+------+------+------+------+------+------|
|
||||||
|
* | | | | | | | | Next | Vol- | Vol+ | Play |
|
||||||
|
* `-----------------------------------------------------------------------------------'
|
||||||
|
*/
|
||||||
|
[_RAISE] = KEYMAP(
|
||||||
|
Key_Backtick, Key_1, Key_2, Key_3, Key_4, Key_5, Key_6, Key_7, Key_8, Key_9, Key_0, Key_Backspace,
|
||||||
|
Key_Delete, Key_F1, Key_F2, Key_F3, Key_F4, Key_F5, Key_F6, Key_Minus, Key_Equals, Key_LeftBracket, Key_RightBracket, Key_Backslash,
|
||||||
|
___, Key_F7, Key_F8, Key_F9, Key_F10, Key_F11, Key_F12, Key_NonUsPound, Key_NonUsBackslashAndPipe, Key_PageUp, Key_PageDown, ___,
|
||||||
|
___, ___, ___, ___, ___, ___, ___, ___, Consumer_ScanNextTrack, Consumer_VolumeDecrement, Consumer_VolumeIncrement, Consumer_PlaySlashPause
|
||||||
|
),
|
||||||
|
|
||||||
|
/* Plover layer (http://opensteno.org)
|
||||||
|
* ,-----------------------------------------------------------------------------------.
|
||||||
|
* | # | # | # | # | # | # | # | # | # | # | # | # |
|
||||||
|
* |------+------+------+------+------+-------------+------+------+------+------+------|
|
||||||
|
* | | S | T | P | H | * | * | F | P | L | T | D |
|
||||||
|
* |------+------+------+------+------+------|------+------+------+------+------+------|
|
||||||
|
* | | S | K | W | R | * | * | R | B | G | S | Z |
|
||||||
|
* |------+------+------+------+------+------+------+------+------+------+------+------|
|
||||||
|
* | Exit | | | A | O | | E | U | | | |
|
||||||
|
* `-----------------------------------------------------------------------------------'
|
||||||
|
*/
|
||||||
|
|
||||||
|
[_PLOVER] = KEYMAP(
|
||||||
|
LSHIFT(Key_1), LSHIFT(Key_1), LSHIFT(Key_1), LSHIFT(Key_1), LSHIFT(Key_1), LSHIFT(Key_1), LSHIFT(Key_1), LSHIFT(Key_1), LSHIFT(Key_1), LSHIFT(Key_1), LSHIFT(Key_1), LSHIFT(Key_1) ,
|
||||||
|
XXX, Key_Q, Key_W, Key_E, Key_R, Key_T, Key_Y, Key_U, Key_I, Key_O, Key_P, Key_LeftBracket,
|
||||||
|
XXX, Key_A, Key_S, Key_D, Key_F, Key_G, Key_H, Key_J, Key_K, Key_L, Key_Semicolon, Key_Quote,
|
||||||
|
LockLayer(_QWERTY), XXX, XXX, Key_C, Key_V, XXX, XXX, Key_N, Key_M, XXX, XXX, XXX
|
||||||
|
),
|
||||||
|
|
||||||
|
/* Adjust (Lower + Raise)
|
||||||
|
* ,-----------------------------------------------------------------------------------.
|
||||||
|
* | | Reset| | | | | | | | | | Del |
|
||||||
|
* |------+------+------+------+------+-------------+------+------+------+------+------|
|
||||||
|
* | | | |Aud on|Audoff|AGnorm|AGswap|Qwerty|Colemk|Dvorak|Plover| |
|
||||||
|
* |------+------+------+------+------+------|------+------+------+------+------+------|
|
||||||
|
* | |Voice-|Voice+|Mus on|Musoff|MIDIon|MIDIof| | | | | |
|
||||||
|
* |------+------+------+------+------+------+------+------+------+------+------+------|
|
||||||
|
* | | | | | | | | | | | |
|
||||||
|
* `-----------------------------------------------------------------------------------'
|
||||||
|
*/
|
||||||
|
//[_ADJUST] = KEYMAP(
|
||||||
|
// ___, RESET, DEBUG, RGB_TOG, RGB_MOD, RGB_HUI, RGB_HUD, RGB_SAI, RGB_SAD, RGB_VAI, RGB_VAD, Key_Delete ,
|
||||||
|
// ___, ___, MU_MOD, AU_ON, AU_OFF, AG_NORM, AG_SWAP, LockLayer(_QWERTY), LockLayer(_COLEMAK), LockLayer(_DVORAK), LockLayer(_PLOVER), ___,
|
||||||
|
// ___, MUV_DE, MUV_IN, MU_ON, MU_OFF, MI_ON, MI_OFF, TERM_ON, TERM_OFF, ___, ___, ___,
|
||||||
|
// ___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___
|
||||||
|
//)
|
||||||
|
);
|
||||||
|
/* *INDENT-ON* */
|
||||||
|
|
||||||
|
KALEIDOSCOPE_INIT_PLUGINS(Macros);
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
Kaleidoscope.setup();
|
||||||
|
Serial.begin(9600);
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
Kaleidoscope.loop();
|
||||||
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
/* -*- mode: c++ -*-
|
||||||
|
* Kaleidoscope-Hardware-OLKB-Planck -- OLKB Planck hardware support for Kaleidoscope
|
||||||
|
* Copyright (C) 2018 Keyboard.io, Inc
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "kaleidoscope/hardware/olkb/Planck.h"
|
@ -0,0 +1,192 @@
|
|||||||
|
/* -*- mode: c++ -*-
|
||||||
|
* Kaleidoscope-Hardware-Planck -- OLKB Planck hardware support for Kaleidoscope
|
||||||
|
* Copyright (C) 2018 Keyboard.io, Inc
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of version 3 of the GNU General Public License as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef ARDUINO_AVR_PLANCK
|
||||||
|
|
||||||
|
#include <Kaleidoscope.h>
|
||||||
|
#include <KeyboardioHID.h>
|
||||||
|
#include <avr/wdt.h>
|
||||||
|
|
||||||
|
static bool do_scan_ = true;
|
||||||
|
|
||||||
|
ISR(TIMER1_OVF_vect) {
|
||||||
|
do_scan_ = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace kaleidoscope {
|
||||||
|
namespace hardware {
|
||||||
|
namespace olkb {
|
||||||
|
|
||||||
|
constexpr uint8_t Planck::matrix_row_pins[matrix_rows];
|
||||||
|
constexpr uint8_t Planck::matrix_col_pins[matrix_columns];
|
||||||
|
uint16_t Planck::previousKeyState_[matrix_rows];
|
||||||
|
uint16_t Planck::keyState_[matrix_rows];
|
||||||
|
uint16_t Planck::masks_[matrix_rows];
|
||||||
|
uint8_t Planck::debounce_matrix_[matrix_rows][matrix_columns];
|
||||||
|
|
||||||
|
void Planck::setup(void) {
|
||||||
|
wdt_disable();
|
||||||
|
|
||||||
|
for (uint8_t i = 0; i < sizeof(matrix_col_pins); i++) {
|
||||||
|
DDR_INPUT(matrix_col_pins[i]);
|
||||||
|
ENABLE_PULLUP(matrix_col_pins[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (uint8_t i = 0; i < sizeof(matrix_row_pins); i++) {
|
||||||
|
DDR_OUTPUT(matrix_row_pins[i]);
|
||||||
|
OUTPUT_HIGH(matrix_row_pins[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Set up Timer1 for 500usec */
|
||||||
|
TCCR1B = _BV(WGM13);
|
||||||
|
TCCR1A = 0;
|
||||||
|
|
||||||
|
const uint32_t cycles = (F_CPU / 2000000) * 500;
|
||||||
|
|
||||||
|
ICR1 = cycles;
|
||||||
|
TCCR1B = _BV(WGM13) | _BV(CS10);
|
||||||
|
TIMSK1 = _BV(TOIE1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
uint16_t Planck::readCols() {
|
||||||
|
uint16_t results = 0x00 ;
|
||||||
|
for (uint8_t i = 0; i < matrix_columns; i++) {
|
||||||
|
results |= (!READ_PIN(matrix_col_pins[i]) << i);
|
||||||
|
}
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Planck::readMatrix() {
|
||||||
|
|
||||||
|
for (uint8_t current_row = 0; current_row < sizeof(matrix_row_pins); current_row++) {
|
||||||
|
uint16_t mask, cols;
|
||||||
|
|
||||||
|
previousKeyState_[current_row] = keyState_[current_row];
|
||||||
|
|
||||||
|
mask = debounceMaskForRow(current_row);
|
||||||
|
|
||||||
|
OUTPUT_TOGGLE(matrix_row_pins[current_row]);
|
||||||
|
cols = (readCols() & mask) | (keyState_[current_row] & ~mask);
|
||||||
|
OUTPUT_TOGGLE(matrix_row_pins[current_row]);
|
||||||
|
debounceRow(cols ^ keyState_[current_row], current_row);
|
||||||
|
keyState_[current_row] = cols;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Planck::actOnMatrixScan() {
|
||||||
|
for (byte row = 0; row < matrix_rows; row++) {
|
||||||
|
for (byte col = 0; col < matrix_columns; col++) {
|
||||||
|
uint8_t keyState = (bitRead(previousKeyState_[row], col) << 0) |
|
||||||
|
(bitRead(keyState_[row], col) << 1);
|
||||||
|
if (keyState) {
|
||||||
|
handleKeyswitchEvent(Key_NoKey, row, col, keyState);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
previousKeyState_[row] = keyState_[row];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Planck::scanMatrix() {
|
||||||
|
if (!do_scan_)
|
||||||
|
return;
|
||||||
|
|
||||||
|
do_scan_ = false;
|
||||||
|
|
||||||
|
readMatrix();
|
||||||
|
actOnMatrixScan();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Planck::maskKey(byte row, byte col) {
|
||||||
|
if (row >= matrix_rows || col >= matrix_columns)
|
||||||
|
return;
|
||||||
|
|
||||||
|
bitWrite(masks_[row], col, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Planck::unMaskKey(byte row, byte col) {
|
||||||
|
if (row >= matrix_rows || col >= matrix_columns)
|
||||||
|
return;
|
||||||
|
|
||||||
|
bitWrite(masks_[row], col, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Planck::isKeyMasked(byte row, byte col) {
|
||||||
|
if (row >= matrix_rows || col >= matrix_columns)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return bitRead(masks_[row], col);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Planck::detachFromHost() {
|
||||||
|
UDCON |= _BV(DETACH);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Planck::attachToHost() {
|
||||||
|
UDCON &= ~_BV(DETACH);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Planck::isKeyswitchPressed(byte row, byte col) {
|
||||||
|
return (bitRead(keyState_[row], col) != 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Planck::isKeyswitchPressed(uint8_t keyIndex) {
|
||||||
|
keyIndex--;
|
||||||
|
return isKeyswitchPressed(keyIndex / matrix_columns, keyIndex % matrix_columns);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t Planck::pressedKeyswitchCount() {
|
||||||
|
uint8_t count = 0;
|
||||||
|
|
||||||
|
for (uint8_t r = 0; r < matrix_rows; r++) {
|
||||||
|
count += __builtin_popcount(keyState_[r]);
|
||||||
|
}
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t Planck::debounceMaskForRow(uint8_t row) {
|
||||||
|
uint16_t result = 0;
|
||||||
|
|
||||||
|
for (uint16_t c = 0; c < matrix_columns; ++c) {
|
||||||
|
if (debounce_matrix_[row][c]) {
|
||||||
|
--debounce_matrix_[row][c];
|
||||||
|
} else {
|
||||||
|
result |= _BV(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Planck::debounceRow(uint16_t change, uint8_t row) {
|
||||||
|
for (uint16_t i = 0; i < matrix_columns; ++i) {
|
||||||
|
if (change & _BV(i)) {
|
||||||
|
debounce_matrix_[row][i] = debounce;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
HARDWARE_IMPLEMENTATION KeyboardHardware;
|
||||||
|
kaleidoscope::hardware::olkb::Planck &Planck = KeyboardHardware;
|
||||||
|
|
||||||
|
#endif
|
@ -0,0 +1,222 @@
|
|||||||
|
/* -*- mode: c++ -*-
|
||||||
|
* Kaleidoscope-Hardware-Planck -- OLKB Planck hardware support for Kaleidoscope
|
||||||
|
* Copyright (C) 2018 Keyboard.io, Inc
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of version 3 of the GNU General Public License as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifdef ARDUINO_AVR_PLANCK
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
#define HARDWARE_IMPLEMENTATION kaleidoscope::hardware::olkb::Planck
|
||||||
|
#include "Kaleidoscope-HIDAdaptor-KeyboardioHID.h"
|
||||||
|
|
||||||
|
#include "kaleidoscope/macro_helpers.h"
|
||||||
|
#include "kaleidoscope/hardware/avr/pins_and_ports.h"
|
||||||
|
|
||||||
|
struct cRGB {
|
||||||
|
uint8_t r, g, b;
|
||||||
|
};
|
||||||
|
|
||||||
|
#define CRGB(r,g,b) (cRGB){b, g, r}
|
||||||
|
|
||||||
|
|
||||||
|
namespace kaleidoscope {
|
||||||
|
namespace hardware {
|
||||||
|
namespace olkb {
|
||||||
|
class Planck {
|
||||||
|
public:
|
||||||
|
Planck(void) {}
|
||||||
|
static const uint8_t matrix_rows = 4;
|
||||||
|
static const uint8_t matrix_columns = 12;
|
||||||
|
static constexpr uint8_t matrix_row_pins[matrix_rows] = { PIN_D0, PIN_D5, PIN_B5, PIN_B6 };
|
||||||
|
static constexpr uint8_t matrix_col_pins[matrix_columns] = { PIN_F1, PIN_F0, PIN_B0, PIN_C7, PIN_F4, PIN_F5, PIN_F6, PIN_F7, PIN_D4, PIN_D6, PIN_B4, PIN_D7 };
|
||||||
|
static constexpr int8_t led_count = 0;
|
||||||
|
static const uint8_t debounce = 3;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void syncLeds(void) {}
|
||||||
|
void setCrgbAt(uint8_t row, byte col, cRGB color) {}
|
||||||
|
void setCrgbAt(int8_t i, cRGB crgb) {}
|
||||||
|
cRGB getCrgbAt(int8_t i) {
|
||||||
|
return CRGB(0, 0, 0);
|
||||||
|
}
|
||||||
|
int8_t getLedIndex(uint8_t row, byte col) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void scanMatrix(void);
|
||||||
|
void readMatrix(void);
|
||||||
|
void actOnMatrixScan(void);
|
||||||
|
void setup();
|
||||||
|
|
||||||
|
/** Detaching from / attaching to the host.
|
||||||
|
*
|
||||||
|
* These two functions should detach the device from (or attach it to) the
|
||||||
|
* host, preferably without rebooting the device. Their purpose is to allow
|
||||||
|
* one to do some configuration inbetween, so the re-attach happens with
|
||||||
|
* different properties. The device remains powered between these operations,
|
||||||
|
* only the connection to the host gets severed.
|
||||||
|
*/
|
||||||
|
void detachFromHost();
|
||||||
|
void attachToHost();
|
||||||
|
|
||||||
|
/* Key masking
|
||||||
|
* -----------
|
||||||
|
*
|
||||||
|
* There are situations when one wants to ignore key events for a while, and
|
||||||
|
* mask them out. These functions help do that. In isolation, they do nothing,
|
||||||
|
* plugins and the core firmware is expected to make use of these.
|
||||||
|
*
|
||||||
|
* See `handleKeyswitchEvent` in the Kaleidoscope sources for a use-case.
|
||||||
|
*/
|
||||||
|
void maskKey(uint8_t row, byte col);
|
||||||
|
void unMaskKey(uint8_t row, byte col);
|
||||||
|
bool isKeyMasked(uint8_t row, byte col);
|
||||||
|
|
||||||
|
/** Key switch states
|
||||||
|
*
|
||||||
|
* These methods offer a way to peek at the key switch states, for those cases
|
||||||
|
* where we need to deal with the state closest to the hardware. Some methods
|
||||||
|
* offer a way to check if a key is pressed, others return the number of
|
||||||
|
* pressed keys.
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* Check if a key is pressed at a given position.
|
||||||
|
*
|
||||||
|
* @param row is the row the key is located at in the matrix.
|
||||||
|
* @param col is the column the key is located at in the matrix.
|
||||||
|
*
|
||||||
|
* @returns true if the key is pressed, false otherwise.
|
||||||
|
*/
|
||||||
|
bool isKeyswitchPressed(uint8_t row, byte col);
|
||||||
|
/**
|
||||||
|
* Check if a key is pressed at a given position.
|
||||||
|
*
|
||||||
|
* @param keyIndex is the key index, as calculated by `keyIndex`.
|
||||||
|
*
|
||||||
|
* @note Key indexes start at 1, not 0!
|
||||||
|
*
|
||||||
|
* @returns true if the key is pressed, false otherwise.
|
||||||
|
*/
|
||||||
|
bool isKeyswitchPressed(uint8_t keyIndex);
|
||||||
|
/**
|
||||||
|
* Check the number of key switches currently pressed.
|
||||||
|
*
|
||||||
|
* @returns the number of keys pressed.
|
||||||
|
*/
|
||||||
|
uint8_t pressedKeyswitchCount();
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
static uint16_t previousKeyState_[matrix_rows];
|
||||||
|
static uint16_t keyState_[matrix_rows];
|
||||||
|
static uint16_t masks_[matrix_rows];
|
||||||
|
static uint8_t debounce_matrix_[matrix_rows][matrix_columns];
|
||||||
|
|
||||||
|
static uint16_t readCols();
|
||||||
|
|
||||||
|
static uint16_t debounceMaskForRow(uint8_t row);
|
||||||
|
static void debounceRow(uint16_t change, uint8_t row);
|
||||||
|
};
|
||||||
|
|
||||||
|
#define KEYMAP( \
|
||||||
|
R0C0, R0C1, R0C2, R0C3, R0C4, R0C5, R0C6, R0C7, R0C8, R0C9, R0C10, R0C11, \
|
||||||
|
R1C0, R1C1, R1C2, R1C3, R1C4, R1C5, R1C6, R1C7, R1C8, R1C9, R1C10, R1C11, \
|
||||||
|
R2C0, R2C1, R2C2, R2C3, R2C4, R2C5, R2C6, R2C7, R2C8, R2C9, R2C10, R2C11, \
|
||||||
|
R3C0, R3C1, R3C2, R3C3, R3C4, R3C5, R3C6, R3C7, R3C8, R3C9, R3C10, R3C11 \
|
||||||
|
) { \
|
||||||
|
{ R0C0, R0C1, R0C2, R0C3, R0C4, R0C5, R0C6, R0C7, R0C8, R0C9, R0C10, R0C11, }, \
|
||||||
|
{ R1C0, R1C1, R1C2, R1C3, R1C4, R1C5, R1C6, R1C7, R1C8, R1C9, R1C10, R1C11, }, \
|
||||||
|
{ R2C0, R2C1, R2C2, R2C3, R2C4, R2C5, R2C6, R2C7, R2C8, R2C9, R2C10, R2C11, }, \
|
||||||
|
{ R3C0, R3C1, R3C2, R3C3, R3C4, R3C5, R3C6, R3C7, R3C8, R3C9, R3C10, R3C11, } \
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* To be used by the hardware implementations, `keyIndex` tells us the index of
|
||||||
|
* a key, from which we can figure out the row and column as needed. The index
|
||||||
|
* starts at one, so that plugins that work with a list of key indexes can use
|
||||||
|
* zero as a sentinel. This is important, because when we initialize arrays with
|
||||||
|
* fewer elements than the declared array size, the remaining elements will be
|
||||||
|
* zero. We can use this to avoid having to explicitly add a sentinel in
|
||||||
|
* user-facing code.
|
||||||
|
*/
|
||||||
|
constexpr uint8_t keyIndex(byte row, byte col) {
|
||||||
|
return (row * kaleidoscope::hardware::olkb::Planck::matrix_columns) + col + 1;
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
This oneliner will generate these constexprs:
|
||||||
|
|
||||||
|
perl -e'for($i=0;$i<6;$i++) { for ($j=0; $j<16;$j++) { print "constexpr uint8_t R${i}C${j} = keyIndex($i, $j);\n"}};'
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
constexpr uint8_t R0C0 = keyIndex(0, 0);
|
||||||
|
constexpr uint8_t R0C1 = keyIndex(0, 1);
|
||||||
|
constexpr uint8_t R0C2 = keyIndex(0, 2);
|
||||||
|
constexpr uint8_t R0C3 = keyIndex(0, 3);
|
||||||
|
constexpr uint8_t R0C4 = keyIndex(0, 4);
|
||||||
|
constexpr uint8_t R0C5 = keyIndex(0, 5);
|
||||||
|
constexpr uint8_t R0C6 = keyIndex(0, 6);
|
||||||
|
constexpr uint8_t R0C7 = keyIndex(0, 7);
|
||||||
|
constexpr uint8_t R0C8 = keyIndex(0, 8);
|
||||||
|
constexpr uint8_t R0C9 = keyIndex(0, 9);
|
||||||
|
constexpr uint8_t R0C10 = keyIndex(0, 10);
|
||||||
|
constexpr uint8_t R0C11 = keyIndex(0, 11);
|
||||||
|
constexpr uint8_t R1C0 = keyIndex(1, 0);
|
||||||
|
constexpr uint8_t R1C1 = keyIndex(1, 1);
|
||||||
|
constexpr uint8_t R1C2 = keyIndex(1, 2);
|
||||||
|
constexpr uint8_t R1C3 = keyIndex(1, 3);
|
||||||
|
constexpr uint8_t R1C4 = keyIndex(1, 4);
|
||||||
|
constexpr uint8_t R1C5 = keyIndex(1, 5);
|
||||||
|
constexpr uint8_t R1C6 = keyIndex(1, 6);
|
||||||
|
constexpr uint8_t R1C7 = keyIndex(1, 7);
|
||||||
|
constexpr uint8_t R1C8 = keyIndex(1, 8);
|
||||||
|
constexpr uint8_t R1C9 = keyIndex(1, 9);
|
||||||
|
constexpr uint8_t R1C10 = keyIndex(1, 10);
|
||||||
|
constexpr uint8_t R1C11 = keyIndex(1, 11);
|
||||||
|
constexpr uint8_t R2C0 = keyIndex(2, 0);
|
||||||
|
constexpr uint8_t R2C1 = keyIndex(2, 1);
|
||||||
|
constexpr uint8_t R2C2 = keyIndex(2, 2);
|
||||||
|
constexpr uint8_t R2C3 = keyIndex(2, 3);
|
||||||
|
constexpr uint8_t R2C4 = keyIndex(2, 4);
|
||||||
|
constexpr uint8_t R2C5 = keyIndex(2, 5);
|
||||||
|
constexpr uint8_t R2C6 = keyIndex(2, 6);
|
||||||
|
constexpr uint8_t R2C7 = keyIndex(2, 7);
|
||||||
|
constexpr uint8_t R2C8 = keyIndex(2, 8);
|
||||||
|
constexpr uint8_t R2C9 = keyIndex(2, 9);
|
||||||
|
constexpr uint8_t R2C10 = keyIndex(2, 10);
|
||||||
|
constexpr uint8_t R2C11 = keyIndex(2, 11);
|
||||||
|
constexpr uint8_t R3C0 = keyIndex(3, 0);
|
||||||
|
constexpr uint8_t R3C1 = keyIndex(3, 1);
|
||||||
|
constexpr uint8_t R3C2 = keyIndex(3, 2);
|
||||||
|
constexpr uint8_t R3C3 = keyIndex(3, 3);
|
||||||
|
constexpr uint8_t R3C4 = keyIndex(3, 4);
|
||||||
|
constexpr uint8_t R3C5 = keyIndex(3, 5);
|
||||||
|
constexpr uint8_t R3C6 = keyIndex(3, 6);
|
||||||
|
constexpr uint8_t R3C7 = keyIndex(3, 7);
|
||||||
|
constexpr uint8_t R3C8 = keyIndex(3, 8);
|
||||||
|
constexpr uint8_t R3C9 = keyIndex(3, 9);
|
||||||
|
constexpr uint8_t R3C10 = keyIndex(3, 10);
|
||||||
|
constexpr uint8_t R3C11 = keyIndex(3, 11);
|
||||||
|
|
||||||
|
extern kaleidoscope::hardware::olkb::Planck &Planck;
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in new issue