pull/427/head
commit
39d4e041b2
@ -0,0 +1,11 @@
|
||||
# Kaleidoscope-Hardware-Technomancy-Atreus
|
||||
|
||||
This is a plugin for [Kaleidoscope][fw], that adds hardware support for the
|
||||
[Atreus][atreus]. Supported models include post-2016 PCB variants with an A*
|
||||
MCU, and the hand-wired variant from [FalbaTech][falba] with a Teensy2.
|
||||
|
||||
PCBs prior to 2016, and the legacy teensy2 variants are not supported.
|
||||
|
||||
[fw]: https://github.com/keyboardio/Kaleidoscope
|
||||
[atreus]: https://atreus.technomancy.us/
|
||||
[falba]: https://falba.tech/
|
@ -0,0 +1,24 @@
|
||||
flash_over_usb() {
|
||||
sleep 1s
|
||||
|
||||
echo "Please reset your keyboard!"
|
||||
teensy_loader_cli --mcu "${MCU}" -w "${HEX_FILE_PATH}"
|
||||
}
|
||||
|
||||
flash () {
|
||||
prepare_to_flash
|
||||
|
||||
# This is defined in the (optional) user config.
|
||||
# shellcheck disable=SC2154
|
||||
${preFlash_HOOKS}
|
||||
|
||||
flash_over_usb || flash_over_usb
|
||||
|
||||
# This is defined in the (optional) user config.
|
||||
# shellcheck disable=SC2154
|
||||
${postFlash_HOOKS}
|
||||
}
|
||||
|
||||
NO_RESET=1
|
||||
DEFAULT_SKETCH="Atreus"
|
||||
BOARD="atreus"
|
@ -0,0 +1,101 @@
|
||||
/* -*- mode: c++ -*-
|
||||
* Atreus -- A very basic Kaleidoscope example for the Atreus
|
||||
* 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"
|
||||
|
||||
#define MO(n) ShiftToLayer(n)
|
||||
#define TG(n) LockLayer(n)
|
||||
|
||||
enum {
|
||||
RESET
|
||||
};
|
||||
|
||||
#define Key_Exclamation LSHIFT(Key_1)
|
||||
#define Key_At LSHIFT(Key_2)
|
||||
#define Key_Hash LSHIFT(Key_3)
|
||||
#define Key_Dollar LSHIFT(Key_4)
|
||||
#define Key_And LSHIFT(Key_7)
|
||||
#define Key_Star LSHIFT(Key_8)
|
||||
#define Key_Plus LSHIFT(Key_Equals)
|
||||
|
||||
/* *INDENT-OFF* */
|
||||
KEYMAPS(
|
||||
[0] = KEYMAP_STACKED
|
||||
(
|
||||
Key_Q ,Key_W ,Key_E ,Key_R ,Key_T
|
||||
,Key_A ,Key_S ,Key_D ,Key_F ,Key_G
|
||||
,Key_Z ,Key_X ,Key_C ,Key_V ,Key_B
|
||||
,Key_Esc ,Key_Tab ,Key_LeftGui ,Key_LeftShift ,Key_Backspace ,Key_LeftControl
|
||||
|
||||
,Key_Y ,Key_U ,Key_I ,Key_O ,Key_P
|
||||
,Key_H ,Key_J ,Key_K ,Key_L ,Key_Semicolon
|
||||
,Key_N ,Key_M ,Key_Comma ,Key_Period ,Key_Slash
|
||||
,Key_LeftAlt ,Key_Space ,MO(1) ,Key_Minus ,Key_Quote ,Key_Enter
|
||||
),
|
||||
|
||||
[1] = KEYMAP_STACKED
|
||||
(
|
||||
Key_Exclamation ,Key_At ,Key_UpArrow ,Key_LeftCurlyBracket ,Key_RightCurlyBracket
|
||||
,Key_Hash ,Key_LeftArrow ,Key_DownArrow ,Key_RightArrow ,Key_Dollar
|
||||
,Key_LeftBracket ,Key_RightBracket ,Key_LeftParen ,Key_RightParen ,Key_And
|
||||
,TG(2) ,Key_Insert ,Key_LeftGui ,Key_LeftShift ,Key_Backspace ,Key_LeftControl
|
||||
|
||||
,Key_PageUp ,Key_7 ,Key_8 ,Key_9 ,Key_Star
|
||||
,Key_PageDown ,Key_4 ,Key_5 ,Key_6 ,Key_Plus
|
||||
,Key_Backtick ,Key_1 ,Key_2 ,Key_3 ,Key_Backslash
|
||||
,Key_LeftAlt ,Key_Space ,MO(1) ,Key_Period ,Key_0 ,Key_Equals
|
||||
),
|
||||
|
||||
[2] = KEYMAP_STACKED
|
||||
(
|
||||
Key_Insert ,Key_Home ,Key_UpArrow ,Key_End ,Key_PageUp
|
||||
,Key_Delete ,Key_LeftArrow ,Key_DownArrow ,Key_RightArrow ,Key_PageDown
|
||||
,XXX ,Consumer_VolumeIncrement ,XXX ,XXX ,M(RESET)
|
||||
,XXX ,Consumer_VolumeDecrement ,___ ,___ ,___ ,___
|
||||
|
||||
,Key_UpArrow ,Key_F7 ,Key_F8 ,Key_F9 ,Key_F10
|
||||
,Key_DownArrow ,Key_F4 ,Key_F5 ,Key_F6 ,Key_F11
|
||||
,XXX ,Key_F1 ,Key_F2 ,Key_F3 ,Key_F12
|
||||
,___ ,___ ,___ ,Key_PrintScreen ,Key_ScrollLock ,Consumer_PlaySlashPause
|
||||
)
|
||||
)
|
||||
/* *INDENT-ON* */
|
||||
|
||||
KALEIDOSCOPE_INIT_PLUGINS(Macros);
|
||||
|
||||
const macro_t *macroAction(uint8_t macroIndex, uint8_t keyState) {
|
||||
switch (macroIndex) {
|
||||
case RESET:
|
||||
Atreus.resetDevice();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return MACRO_NONE;
|
||||
}
|
||||
|
||||
void setup() {
|
||||
Kaleidoscope.setup();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
Kaleidoscope.loop();
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
/* -*- mode: c++ -*-
|
||||
* Kaleidoscope-Hardware-Technomancy-Atreus -- Atreus 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/Atreus.h"
|
@ -0,0 +1,297 @@
|
||||
/* -*- mode: c++ -*-
|
||||
* Kaleidoscope-Hardware-Technomancy-Atreus -- Atreus hardware support for Kaleidoscope
|
||||
* Copyright (C) 2018 Keyboard.io, Inc
|
||||
*
|
||||
* Based on QMK (commit e9a67f8fd)
|
||||
* (C) Jack Humbert, Phil Hagelberg, and others
|
||||
* Original QMK sources:
|
||||
* - keyboards/atreus/atreus.h
|
||||
* - keyboards/atreus/config.h
|
||||
* - quantum/matrix.c
|
||||
* - tmk_core/common/avr/bootloader.c
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#ifdef ARDUINO_AVR_ATREUS
|
||||
|
||||
#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 {
|
||||
|
||||
uint16_t Atreus::previousKeyState_[ROWS];
|
||||
uint16_t Atreus::keyState_[ROWS];
|
||||
uint16_t Atreus::masks_[ROWS];
|
||||
|
||||
uint8_t Atreus::debounce_matrix_[ROWS][COLS];
|
||||
uint8_t Atreus::debounce = 3;
|
||||
|
||||
void Atreus::setup(void) {
|
||||
wdt_disable();
|
||||
delay(100);
|
||||
|
||||
for (uint8_t i = 0; i < ROWS; i++) {
|
||||
unselectRow(i);
|
||||
keyState_[i] = previousKeyState_[i] = 0;
|
||||
}
|
||||
|
||||
// Initialize columns
|
||||
DDRB &= ~(_BV(5) | _BV(4) | _BV(6) | _BV(7));
|
||||
PORTB |= (_BV(5) | _BV(4) | _BV(6) | _BV(7));
|
||||
|
||||
DDRD &= ~(_BV(7) | _BV(4) | _BV(6));
|
||||
PORTD |= (_BV(7) | _BV(4) | _BV(6));
|
||||
|
||||
DDRC &= ~(_BV(6));
|
||||
PORTC |= (_BV(6));
|
||||
|
||||
DDRE &= ~(_BV(6));
|
||||
PORTE |= (_BV(6));
|
||||
|
||||
DDRF &= ~(_BV(6) | _BV(7));
|
||||
PORTF |= (_BV(6) | _BV(7));
|
||||
|
||||
/* 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);
|
||||
}
|
||||
|
||||
void Atreus::selectRow(uint8_t row) {
|
||||
switch (row) {
|
||||
case 0:
|
||||
DDRD |= (_BV(0));
|
||||
PORTD &= ~(_BV(0));
|
||||
break;
|
||||
case 1:
|
||||
DDRD |= (_BV(1));
|
||||
PORTD &= ~(_BV(1));
|
||||
break;
|
||||
case 2:
|
||||
DDRD |= (_BV(3));
|
||||
PORTD &= ~(_BV(3));
|
||||
break;
|
||||
case 3:
|
||||
DDRD |= (_BV(2));
|
||||
PORTD &= ~(_BV(2));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Atreus::unselectRow(uint8_t row) {
|
||||
switch (row) {
|
||||
case 0:
|
||||
DDRD &= ~(_BV(0));
|
||||
PORTD |= (_BV(0));
|
||||
break;
|
||||
case 1:
|
||||
DDRD &= ~(_BV(1));
|
||||
PORTD |= (_BV(1));
|
||||
break;
|
||||
case 2:
|
||||
DDRD &= ~(_BV(3));
|
||||
PORTD |= (_BV(3));
|
||||
break;
|
||||
case 3:
|
||||
DDRD &= ~(_BV(2));
|
||||
PORTD |= (_BV(2));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t Atreus::readCols() {
|
||||
return ((PINB & (_BV(4)) ? 0 : (_BV(0))) |
|
||||
(PINB & (_BV(5)) ? 0 : (_BV(1))) |
|
||||
(PINB & (_BV(6)) ? 0 : (_BV(2))) |
|
||||
(PINB & (_BV(7)) ? 0 : (_BV(3))) |
|
||||
(PINC & (_BV(6)) ? 0 : (_BV(4))) |
|
||||
(PIND & (_BV(4)) ? 0 : (_BV(5))) |
|
||||
(PIND & (_BV(6)) ? 0 : (_BV(6))) |
|
||||
(PIND & (_BV(7)) ? 0 : (_BV(7))) |
|
||||
(PINE & (_BV(6)) ? 0 : (_BV(8))) |
|
||||
(PINF & (_BV(6)) ? 0 : (_BV(9))) |
|
||||
(PINF & (_BV(7)) ? 0 : (_BV(10))));
|
||||
}
|
||||
|
||||
void Atreus::readMatrixRow(uint8_t current_row) {
|
||||
uint16_t mask, cols;
|
||||
|
||||
previousKeyState_[current_row] = keyState_[current_row];
|
||||
|
||||
mask = debounceMaskForRow(current_row);
|
||||
|
||||
selectRow(current_row);
|
||||
cols = (readCols() & mask) | (keyState_[current_row] & ~mask);
|
||||
unselectRow(current_row);
|
||||
debounceRow(cols ^ keyState_[current_row], current_row);
|
||||
keyState_[current_row] = cols;
|
||||
}
|
||||
|
||||
void Atreus::readMatrix() {
|
||||
do_scan_ = false;
|
||||
|
||||
for (uint8_t current_row = 0; current_row < ROWS; current_row++) {
|
||||
readMatrixRow(current_row);
|
||||
}
|
||||
}
|
||||
|
||||
void Atreus::actOnMatrixScan() {
|
||||
for (byte row = 0; row < ROWS; row++) {
|
||||
for (byte col = 0; col < COLS; 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 Atreus::scanMatrix() {
|
||||
if (!do_scan_)
|
||||
return;
|
||||
|
||||
readMatrix();
|
||||
actOnMatrixScan();
|
||||
}
|
||||
|
||||
void Atreus::maskKey(byte row, byte col) {
|
||||
if (row >= ROWS || col >= COLS)
|
||||
return;
|
||||
|
||||
bitWrite(masks_[row], col, 1);
|
||||
}
|
||||
|
||||
void Atreus::unMaskKey(byte row, byte col) {
|
||||
if (row >= ROWS || col >= COLS)
|
||||
return;
|
||||
|
||||
bitWrite(masks_[row], col, 0);
|
||||
}
|
||||
|
||||
bool Atreus::isKeyMasked(byte row, byte col) {
|
||||
if (row >= ROWS || col >= COLS)
|
||||
return false;
|
||||
|
||||
return bitRead(masks_[row], col);
|
||||
}
|
||||
|
||||
// Atreus-specific stuff
|
||||
|
||||
void Atreus::resetDevice() {
|
||||
cli();
|
||||
UDCON = 1;
|
||||
USBCON = (1 << FRZCLK);
|
||||
UCSR1B = 0;
|
||||
_delay_ms(5);
|
||||
|
||||
EIMSK = 0;
|
||||
PCICR = 0;
|
||||
SPCR = 0;
|
||||
ACSR = 0;
|
||||
EECR = 0;
|
||||
ADCSRA = 0;
|
||||
TIMSK0 = 0;
|
||||
TIMSK1 = 0;
|
||||
TIMSK3 = 0;
|
||||
TIMSK4 = 0;
|
||||
UCSR1B = 0;
|
||||
TWCR = 0;
|
||||
DDRB = 0;
|
||||
DDRC = 0;
|
||||
DDRD = 0;
|
||||
DDRE = 0;
|
||||
DDRF = 0;
|
||||
TWCR = 0;
|
||||
PORTB = 0;
|
||||
PORTC = 0;
|
||||
PORTD = 0;
|
||||
PORTE = 0;
|
||||
PORTF = 0;
|
||||
asm volatile("jmp 0x7E00");
|
||||
}
|
||||
|
||||
void Atreus::detachFromHost() {
|
||||
UDCON |= (1 << DETACH);
|
||||
}
|
||||
|
||||
void Atreus::attachToHost() {
|
||||
UDCON &= ~(1 << DETACH);
|
||||
}
|
||||
|
||||
bool Atreus::isKeyswitchPressed(byte row, byte col) {
|
||||
return (bitRead(keyState_[row], col) != 0);
|
||||
}
|
||||
|
||||
bool Atreus::isKeyswitchPressed(uint8_t keyIndex) {
|
||||
keyIndex--;
|
||||
return isKeyswitchPressed(keyIndex / COLS, keyIndex % COLS);
|
||||
}
|
||||
|
||||
uint8_t Atreus::pressedKeyswitchCount() {
|
||||
uint8_t count = 0;
|
||||
|
||||
for (uint8_t r = 0; r < ROWS; r++) {
|
||||
count += __builtin_popcount(keyState_[r]);
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
uint16_t Atreus::debounceMaskForRow(uint8_t row) {
|
||||
uint16_t result = 0;
|
||||
|
||||
for (uint16_t c = 0; c < COLS; ++c) {
|
||||
if (debounce_matrix_[row][c]) {
|
||||
--debounce_matrix_[row][c];
|
||||
} else {
|
||||
result |= (1 << c);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void Atreus::debounceRow(uint16_t change, uint8_t row) {
|
||||
for (uint16_t i = 0; i < COLS; ++i) {
|
||||
if (change & (1 << i)) {
|
||||
debounce_matrix_[row][i] = debounce;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
HARDWARE_IMPLEMENTATION KeyboardHardware;
|
||||
kaleidoscope::hardware::Atreus &Atreus = KeyboardHardware;
|
||||
|
||||
#endif
|
@ -0,0 +1,240 @@
|
||||
/* -*- mode: c++ -*-
|
||||
* Kaleidoscope-Hardware-Technomancy-Atreus -- Atreus hardware support for Kaleidoscope
|
||||
* Copyright (C) 2018 Keyboard.io, Inc
|
||||
*
|
||||
* Based on QMK (commit e9a67f8fd)
|
||||
* (C) Jack Humbert, Jun Wako, Phil Hagelberg, and others
|
||||
* Original QMK sources:
|
||||
* - keyboards/atreus/atreus.h
|
||||
* - keyboards/atreus/config.h
|
||||
*
|
||||
* 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
|
||||
|
||||
#ifdef ARDUINO_AVR_ATREUS
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
#define HARDWARE_IMPLEMENTATION kaleidoscope::hardware::Atreus
|
||||
#include "Kaleidoscope-HIDAdaptor-KeyboardioHID.h"
|
||||
|
||||
#include "kaleidoscope/macro_helpers.h"
|
||||
|
||||
struct cRGB {
|
||||
uint8_t r, g, b;
|
||||
};
|
||||
|
||||
#define COLS 11
|
||||
#define ROWS 4
|
||||
#define LED_COUNT 0
|
||||
|
||||
#define CRGB(r,g,b) (cRGB){b, g, r}
|
||||
|
||||
namespace kaleidoscope {
|
||||
namespace hardware {
|
||||
|
||||
class Atreus {
|
||||
public:
|
||||
Atreus(void) {}
|
||||
|
||||
void syncLeds(void) {}
|
||||
void setCrgbAt(byte row, byte col, cRGB color) {}
|
||||
void setCrgbAt(uint8_t i, cRGB crgb) {}
|
||||
cRGB getCrgbAt(uint8_t i) {
|
||||
return CRGB(0, 0, 0);
|
||||
}
|
||||
uint8_t getLedIndex(byte row, byte col) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
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(byte row, byte col);
|
||||
void unMaskKey(byte row, byte col);
|
||||
bool isKeyMasked(byte 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(byte 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();
|
||||
|
||||
void resetDevice();
|
||||
|
||||
static uint8_t debounce;
|
||||
|
||||
private:
|
||||
static uint16_t previousKeyState_[ROWS];
|
||||
static uint16_t keyState_[ROWS];
|
||||
static uint16_t masks_[ROWS];
|
||||
|
||||
static void readMatrixRow(uint8_t row);
|
||||
static uint16_t readCols();
|
||||
static void selectRow(uint8_t row);
|
||||
static void unselectRow(uint8_t row);
|
||||
|
||||
static uint8_t debounce_matrix_[ROWS][COLS];
|
||||
static uint16_t debounceMaskForRow(uint8_t row);
|
||||
static void debounceRow(uint16_t change, uint8_t row);
|
||||
};
|
||||
|
||||
#define KEYMAP( \
|
||||
R0C0, R0C1, R0C2, R0C3, R0C4, R0C7, R0C8, R0C9, R0C10, R0C11, \
|
||||
R1C0, R1C1, R1C2, R1C3, R1C4, R1C7, R1C8, R1C9, R1C10, R1C11, \
|
||||
R2C0, R2C1, R2C2, R2C3, R2C4, R2C7, R2C8, R2C9, R2C10, R2C11, \
|
||||
R3C0, R3C1, R3C2, R3C3, R3C4, R3C5, R3C6, R3C7, R3C8, R3C9, R3C10, R3C11 \
|
||||
) \
|
||||
{ \
|
||||
{ R0C3, R0C2, R0C7, R0C11, R0C1, XXX, R0C10, R0C0, R0C4, R0C8, R0C9 }, \
|
||||
{ R1C3, R1C2, R1C7, R1C11, R1C1, XXX, R1C10, R1C0, R1C4, R1C8, R1C9 }, \
|
||||
{ R2C3, R2C2, R2C7, R2C11, R2C1, R3C5, R2C10, R2C0, R2C4, R2C8, R2C9 }, \
|
||||
{ R3C3, R3C2, R3C7, R3C11, R3C1, R3C6, R3C10, R3C0, R3C4, R3C8, R3C9 } \
|
||||
}
|
||||
|
||||
#define KEYMAP_STACKED( \
|
||||
R0C0, R0C1, R0C2, R0C3, R0C4, \
|
||||
R1C0, R1C1, R1C2, R1C3, R1C4, \
|
||||
R2C0, R2C1, R2C2, R2C3, R2C4, \
|
||||
R3C0, R3C1, R3C2, R3C3, R3C4, R3C5, \
|
||||
\
|
||||
R0C7, R0C8, R0C9, R0C10, R0C11, \
|
||||
R1C7, R1C8, R1C9, R1C10, R1C11, \
|
||||
R2C7, R2C8, R2C9, R2C10, R2C11, \
|
||||
R3C6, R3C7, R3C8, R3C9, R3C10, R3C11 \
|
||||
) \
|
||||
{ \
|
||||
{ R0C3, R0C2, R0C7, R0C11, R0C1, XXX, R0C10, R0C0, R0C4, R0C8, R0C9 }, \
|
||||
{ R1C3, R1C2, R1C7, R1C11, R1C1, XXX, R1C10, R1C0, R1C4, R1C8, R1C9 }, \
|
||||
{ R2C3, R2C2, R2C7, R2C11, R2C1, R3C5, R2C10, R2C0, R2C4, R2C8, R2C9 }, \
|
||||
{ R3C3, R3C2, R3C7, R3C11, R3C1, R3C6, R3C10, R3C0, R3C4, R3C8, R3C9 } \
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* 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 byte keyIndex(byte row, byte col) {
|
||||
return row * COLS + col + 1;
|
||||
}
|
||||
|
||||
constexpr byte R0C0 = keyIndex(0, 0);
|
||||
constexpr byte R0C1 = keyIndex(0, 1);
|
||||
constexpr byte R0C2 = keyIndex(0, 2);
|
||||
constexpr byte R0C3 = keyIndex(0, 3);
|
||||
constexpr byte R0C4 = keyIndex(0, 4);
|
||||
|
||||
constexpr byte R0C7 = keyIndex(0, 7);
|
||||
constexpr byte R0C8 = keyIndex(0, 8);
|
||||
constexpr byte R0C9 = keyIndex(0, 9);
|
||||
constexpr byte R0C10 = keyIndex(0, 10);
|
||||
constexpr byte R0C11 = keyIndex(0, 11);
|
||||
|
||||
constexpr byte R1C0 = keyIndex(1, 0);
|
||||
constexpr byte R1C1 = keyIndex(1, 1);
|
||||
constexpr byte R1C2 = keyIndex(1, 2);
|
||||
constexpr byte R1C3 = keyIndex(1, 3);
|
||||
constexpr byte R1C4 = keyIndex(1, 4);
|
||||
|
||||
constexpr byte R1C7 = keyIndex(1, 7);
|
||||
constexpr byte R1C8 = keyIndex(1, 8);
|
||||
constexpr byte R1C9 = keyIndex(1, 9);
|
||||
constexpr byte R1C10 = keyIndex(1, 10);
|
||||
constexpr byte R1C11 = keyIndex(1, 11);
|
||||
|
||||
constexpr byte R2C0 = keyIndex(2, 0);
|
||||
constexpr byte R2C1 = keyIndex(2, 1);
|
||||
constexpr byte R2C2 = keyIndex(2, 2);
|
||||
constexpr byte R2C3 = keyIndex(2, 3);
|
||||
constexpr byte R2C4 = keyIndex(2, 4);
|
||||
|
||||
constexpr byte R2C7 = keyIndex(2, 7);
|
||||
constexpr byte R2C8 = keyIndex(2, 8);
|
||||
constexpr byte R2C9 = keyIndex(2, 9);
|
||||
constexpr byte R2C10 = keyIndex(2, 10);
|
||||
constexpr byte R2C11 = keyIndex(2, 11);
|
||||
|
||||
constexpr byte R3C0 = keyIndex(3, 0);
|
||||
constexpr byte R3C1 = keyIndex(3, 1);
|
||||
constexpr byte R3C2 = keyIndex(3, 2);
|
||||
constexpr byte R3C3 = keyIndex(3, 3);
|
||||
constexpr byte R3C4 = keyIndex(3, 4);
|
||||
constexpr byte R3C5 = keyIndex(3, 5);
|
||||
constexpr byte R3C6 = keyIndex(3, 6);
|
||||
constexpr byte R3C7 = keyIndex(3, 7);
|
||||
constexpr byte R3C8 = keyIndex(3, 8);
|
||||
constexpr byte R3C9 = keyIndex(3, 9);
|
||||
constexpr byte R3C10 = keyIndex(3, 10);
|
||||
constexpr byte R3C11 = keyIndex(3, 11);
|
||||
|
||||
extern kaleidoscope::hardware::Atreus &Atreus;
|
||||
|
||||
#endif
|
Loading…
Reference in new issue