diff --git a/plugins/Kaleidoscope-Hardware-Keyboardio-Spacecadet/examples/Spacecadet/Makefile b/plugins/Kaleidoscope-Hardware-Keyboardio-Spacecadet/examples/Spacecadet/Makefile new file mode 100644 index 00000000..19019b31 --- /dev/null +++ b/plugins/Kaleidoscope-Hardware-Keyboardio-Spacecadet/examples/Spacecadet/Makefile @@ -0,0 +1,48 @@ +# This makefile for a Kaleidoscope sketch pulls in all the targets +# required to build the example + + + + +ifneq ($(KALEIDOSCOPE_DIR),) +search_path += $(KALEIDOSCOPE_DIR) +endif + +ifneq ($(ARDUINO_DIRECTORIES_USER),) +search_path += $(ARDUINO_DIRECTORIES_USER)/hardware/keyboardio/avr/libraries/Kaleidoscope +endif + +ifeq ($(shell uname -s),Darwin) +search_path += $(HOME)/Documents/Arduino/hardware/keyboardio/avr/libraries/Kaleidoscope +else +search_path += $(HOME)/Arduino/hardware/keyboardio/avr/libraries/Kaleidoscope +endif + +sketch_makefile := etc/makefiles/sketch.mk + +$(foreach candidate, $(search_path), $(if $(wildcard $(candidate)/$(sketch_makefile)), $(eval ks_dir ?= $(candidate)))) + +ifneq ($(ks_dir),) + +$(info Using Kaleidoscope from $(ks_dir)) + +export KALEIDOSCOPE_DIR := $(ks_dir) +include $(ks_dir)/$(sketch_makefile) + +else + +$(info I can't find your Kaleidoscope installation.) +$(info ) +$(info I tried looking in:) +$(info ) +$(foreach candidate, $(search_path), $(info $(candidate))) +$(info ) +$(info The easiest way to fix this is to set the 'KALEIDOSCOPE_DIR' environment) +$(info variable to the location of your Kaleidoscope directory.) + +endif + + +null-target: + $(info You should never see this message) + @: diff --git a/plugins/Kaleidoscope-Hardware-Keyboardio-Spacecadet/examples/Spacecadet/Spacecadet.ino b/plugins/Kaleidoscope-Hardware-Keyboardio-Spacecadet/examples/Spacecadet/Spacecadet.ino index ee3541d1..56a37c40 100644 --- a/plugins/Kaleidoscope-Hardware-Keyboardio-Spacecadet/examples/Spacecadet/Spacecadet.ino +++ b/plugins/Kaleidoscope-Hardware-Keyboardio-Spacecadet/examples/Spacecadet/Spacecadet.ino @@ -60,9 +60,11 @@ enum { /* *INDENT-OFF* */ KEYMAPS( - [QWERTY] = KEYMAP_STACKED - ( - Key_Q ,Key_W ,Key_E ,Key_R ,Key_T + [QWERTY] = KEYMAP( + Key_Q ,Key_W ,Key_E ,Key_R ,Key_T ,Key_Y ,Key_U ,Key_I ,Key_O ,Key_P + ,Key_A ,Key_S ,Key_D ,Key_F ,Key_G ,Key_H ,Key_J ,Key_K ,Key_L ,Key_Semicolon + ,Key_Z ,Key_X ,Key_C ,Key_V ,Key_B, Key_Backtick ,Key_Backslash,Key_N ,Key_M ,Key_Comma ,Key_Period ,Key_Slash + ,Key_Esc ,Key_Tab ,Key_LeftGui ,Key_LeftShift ,Key_Backspace ,Key_LeftControl ,Key_LeftAlt ,Key_Space ,MO(FUN) ,Key_Minus ,Key_Quote ,Key_Enter, 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_Backtick ,Key_Esc ,Key_Tab ,Key_LeftGui ,Key_LeftShift ,Key_Backspace ,Key_LeftControl @@ -71,33 +73,10 @@ KEYMAPS( ,Key_H ,Key_J ,Key_K ,Key_L ,Key_Semicolon ,Key_Backslash,Key_N ,Key_M ,Key_Comma ,Key_Period ,Key_Slash ,Key_LeftAlt ,Key_Space ,MO(FUN) ,Key_Minus ,Key_Quote ,Key_Enter - ), - - [FUN] = KEYMAP_STACKED - ( - Key_Exclamation ,Key_At ,Key_UpArrow ,Key_Dollar ,Key_Percent - ,Key_LeftParen ,Key_LeftArrow ,Key_DownArrow ,Key_RightArrow ,Key_RightParen - ,Key_LeftBracket ,Key_RightBracket ,Key_Hash ,Key_LeftCurlyBracket ,Key_RightCurlyBracket ,Key_Caret - ,TG(UPPER) ,Key_Insert ,Key_LeftGui ,Key_LeftShift ,Key_Delete ,Key_LeftControl - - ,Key_PageUp ,Key_7 ,Key_8 ,Key_9 ,Key_Backspace - ,Key_PageDown ,Key_4 ,Key_5 ,Key_6 ,___ - ,Key_And ,Key_Star ,Key_1 ,Key_2 ,Key_3 ,Key_Plus - ,Key_LeftAlt ,Key_Space ,___ ,Key_Period ,Key_0 ,Key_Equals - ), - - [UPPER] = KEYMAP_STACKED - ( - Key_Insert ,Key_Home ,Key_UpArrow ,Key_End ,Key_PageUp - ,Key_Delete ,Key_LeftArrow ,Key_DownArrow ,Key_RightArrow ,Key_PageDown - ,M(MACRO_VERSION_INFO) ,Consumer_VolumeIncrement ,XXX ,XXX ,___ ,___ - ,MoveToLayer(QWERTY) ,Consumer_VolumeDecrement ,___ ,___ ,___ ,___ + ,Key_H ,Key_J ,Key_K ,Key_L ,Key_Semicolon + ,Key_Backslash,Key_N ,Key_M ,Key_Comma ,Key_Period ,Key_Slash, XXX, XXX + ) - ,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 - ,___ ,___ ,MoveToLayer(QWERTY) ,Key_PrintScreen ,Key_ScrollLock ,Consumer_PlaySlashPause - ) ) /* *INDENT-ON* */ diff --git a/plugins/Kaleidoscope-Hardware-Keyboardio-Spacecadet/examples/Spacecadet/sketch.json b/plugins/Kaleidoscope-Hardware-Keyboardio-Spacecadet/examples/Spacecadet/sketch.json new file mode 100644 index 00000000..52b79932 --- /dev/null +++ b/plugins/Kaleidoscope-Hardware-Keyboardio-Spacecadet/examples/Spacecadet/sketch.json @@ -0,0 +1,6 @@ +{ + "cpu": { + "fqbn": "keyboardio:gd32:keyboardio_spacecadet", + "port": "" + } +} diff --git a/plugins/Kaleidoscope-Hardware-Keyboardio-Spacecadet/src/Kaleidoscope-Hardware-Keyboardio-Spacecadet.h b/plugins/Kaleidoscope-Hardware-Keyboardio-Spacecadet/src/Kaleidoscope-Hardware-Keyboardio-Spacecadet.h index e19ed9d1..157687b0 100644 --- a/plugins/Kaleidoscope-Hardware-Keyboardio-Spacecadet/src/Kaleidoscope-Hardware-Keyboardio-Spacecadet.h +++ b/plugins/Kaleidoscope-Hardware-Keyboardio-Spacecadet/src/Kaleidoscope-Hardware-Keyboardio-Spacecadet.h @@ -16,4 +16,4 @@ #pragma once -#include "kaleidoscope/device/keyboardio/Spaceadet.h" +#include "kaleidoscope/device/keyboardio/Spacecadet.h" diff --git a/plugins/Kaleidoscope-Hardware-Keyboardio-Spacecadet/src/kaleidoscope/device/keyboardio/GD32Keyscanner.h b/plugins/Kaleidoscope-Hardware-Keyboardio-Spacecadet/src/kaleidoscope/device/keyboardio/GD32Keyscanner.h index c2c0df57..286a2573 100644 --- a/plugins/Kaleidoscope-Hardware-Keyboardio-Spacecadet/src/kaleidoscope/device/keyboardio/GD32Keyscanner.h +++ b/plugins/Kaleidoscope-Hardware-Keyboardio-Spacecadet/src/kaleidoscope/device/keyboardio/GD32Keyscanner.h @@ -30,7 +30,6 @@ namespace keyscanner { struct GD32Props: kaleidoscope::driver::keyscanner::BaseProps { static const uint16_t keyscan_interval = 1500; - static const uint16_t next_scan_after = 0; typedef uint32_t RowState; /* @@ -46,6 +45,7 @@ template class GD32: public kaleidoscope::driver::keyscanner::Base<_KeyScannerProps> { private: typedef GD32<_KeyScannerProps> ThisType; + uint16_t next_scan_after_ ; public: void setup() { @@ -59,7 +59,7 @@ class GD32: public kaleidoscope::driver::keyscanner::Base<_KeyScannerProps> { ); for (uint8_t i = 0; i < _KeyScannerProps::matrix_columns; i++) { - pinmode(_KeyScannerProps::matrix_col_pins[i], INPUT_PULLUP); + pinMode(_KeyScannerProps::matrix_col_pins[i], INPUT_PULLUP); } for (uint8_t i = 0; i < _KeyScannerProps::matrix_rows; i++) { @@ -68,6 +68,7 @@ class GD32: public kaleidoscope::driver::keyscanner::Base<_KeyScannerProps> { } setScanCycleTime(_KeyScannerProps::keyscan_interval); + next_scan_after_ = 0; } @@ -77,14 +78,6 @@ class GD32: public kaleidoscope::driver::keyscanner::Base<_KeyScannerProps> { */ void setScanCycleTime(uint16_t c) { - TCCR1B = _BV(WGM13); - TCCR1A = 0; - - const uint32_t cycles = (F_CPU / 2000000) * c; - - ICR1 = cycles; - TCCR1B = _BV(WGM13) | _BV(CS10); - TIMSK1 = _BV(TOIE1); } __attribute__((optimize(3))) @@ -108,8 +101,8 @@ class GD32: public kaleidoscope::driver::keyscanner::Base<_KeyScannerProps> { } void scanMatrix() { - if (micros() > _KeyScannerProps::next_scan_after || micros < _KeyScannerProps::keyscan_interval) { - _KeyScannerProps::next_scan_after = micros() + _KeyScannerProps::keyscan_interval; + if (micros() > next_scan_after_ || micros() < _KeyScannerProps::keyscan_interval) { + next_scan_after_ = micros() + _KeyScannerProps::keyscan_interval; readMatrix(); } actOnMatrixScan(); @@ -197,7 +190,7 @@ class GD32: public kaleidoscope::driver::keyscanner::Base<_KeyScannerProps> { for (uint8_t i = 0; i < _KeyScannerProps::matrix_columns; i++) { // TODO - do we need this on gd32? asm("NOP"); // We need to pause a beat before reading or we may read before the pin is hot - hot_pins |= (!READ_PIN(_KeyScannerProps::matrix_col_pins[i]) << i); + hot_pins |= (!digitalRead(_KeyScannerProps::matrix_col_pins[i]) << i); } return hot_pins; diff --git a/plugins/Kaleidoscope-Hardware-Keyboardio-Spacecadet/src/kaleidoscope/device/keyboardio/Spacecadet.cpp b/plugins/Kaleidoscope-Hardware-Keyboardio-Spacecadet/src/kaleidoscope/device/keyboardio/Spacecadet.cpp index 6a71abc4..1545b129 100644 --- a/plugins/Kaleidoscope-Hardware-Keyboardio-Spacecadet/src/kaleidoscope/device/keyboardio/Spacecadet.cpp +++ b/plugins/Kaleidoscope-Hardware-Keyboardio-Spacecadet/src/kaleidoscope/device/keyboardio/Spacecadet.cpp @@ -1,5 +1,5 @@ /* -*- mode: c++ -*- - * Kaleidoscope-Hardware-Spacecadet -- Keyboardio Model 100 hardware support for Kaleidoscope + * Kaleidoscope-Hardware-Spacecadet -- Keyboardio Spacecadet hardware support for Kaleidoscope * Copyright (C) 2021 Keyboard.io, Inc * * This program is free software: you can redistribute it and/or modify it under @@ -29,8 +29,8 @@ // Here, we set up aliases to the device's KeyScanner and KeyScannerProps // in the global namespace within the scope of this file. We'll use these // aliases to simplify some template initialization code below. -using KeyScannerProps = typename kaleidoscope::device::keyboardio::AtreusProps::KeyScannerProps; -using KeyScanner = typename kaleidoscope::device::keyboardio::AtreusProps::KeyScanner; +using KeyScannerProps = typename kaleidoscope::device::keyboardio::SpacecadetProps::KeyScannerProps; +using KeyScanner = typename kaleidoscope::device::keyboardio::SpacecadetProps::KeyScanner; @@ -52,29 +52,6 @@ constexpr uint8_t KeyScannerProps::matrix_col_pins[matrix_columns]; // `KeyScannerProps` case above. template<> KeyScanner::row_state_t KeyScanner::matrix_state_[KeyScannerProps::matrix_rows] = {}; -// We set up the TIMER1 interrupt vector here. Due to dependency reasons, this -// cannot be in a header-only driver, and must be placed here. -// -// Timer1 is responsible for setting a property on the KeyScanner, which will -// tell it to do a scan. We use this to make sure that scans happen at roughly -// the intervals we want. We do the scan outside of the interrupt scope for -// practical reasons: guarding every codepath against interrupts that can be -// reached from the scan is far too tedious, for very little gain. -ISR(TIMER1_OVF_vect) { - Runtime.device().keyScanner().do_scan_ = true; -} - - - - - -/********* Hardware plugin *********/ - -void Spacecadet::setup() { - SpacecadetKeyScanner::setup(); - kaleidoscope::device::Base::setup(); -} - } diff --git a/plugins/Kaleidoscope-Hardware-Keyboardio-Spacecadet/src/kaleidoscope/device/keyboardio/Spacecadet.h b/plugins/Kaleidoscope-Hardware-Keyboardio-Spacecadet/src/kaleidoscope/device/keyboardio/Spacecadet.h index 472988e0..a95eba14 100644 --- a/plugins/Kaleidoscope-Hardware-Keyboardio-Spacecadet/src/kaleidoscope/device/keyboardio/Spacecadet.h +++ b/plugins/Kaleidoscope-Hardware-Keyboardio-Spacecadet/src/kaleidoscope/device/keyboardio/Spacecadet.h @@ -1,5 +1,5 @@ /* -*- mode: c++ -*- - * Kaleidoscope-Hardware-Model100 -- Keyboardio Model100 hardware support for Kaleidoscope + * Kaleidoscope-Hardware-Spacecadet -- Keyboardio Spacecadet hardware support for Kaleidoscope * Copyright (C) 2017-2021 Keyboard.io, Inc * * This program is free software: you can redistribute it and/or modify it under @@ -28,24 +28,22 @@ #include "kaleidoscope/driver/keyscanner/Base.h" #include "kaleidoscope/driver/storage/GD32Flash.h" -#include "kaleidoscope/driver/keyboardio/Model100Side.h" -#include "kaleidoscope/driver/led/Base.h" #include "kaleidoscope/device/Base.h" #include "kaleidoscope/driver/hid/Keyboardio.h" #include "kaleidoscope/driver/bootloader/gd32/Base.h" +#include "kaleidoscope/device/keyboardio/GD32Keyscanner.h" namespace kaleidoscope { namespace device { namespace keyboardio { -struct Model100StorageProps: public kaleidoscope::driver::storage::GD32FlashProps { +struct SpacecadetStorageProps: public kaleidoscope::driver::storage::GD32FlashProps { static constexpr uint16_t length = EEPROM_EMULATION_SIZE; }; -class Model100LEDDriver; -struct Model100Props : public kaleidoscope::device::BaseProps { +struct SpacecadetProps : public kaleidoscope::device::BaseProps { typedef kaleidoscope::driver::hid::KeyboardioProps HIDProps; typedef kaleidoscope::driver::hid::Keyboardio HID; @@ -56,14 +54,14 @@ struct Model100Props : public kaleidoscope::device::BaseProps { static constexpr uint8_t matrix_columns = 21; typedef MatrixAddr KeyAddr; static constexpr uint8_t matrix_row_pins[matrix_rows] = {PB15, PB14, PB13, PB12, PB11, PB10}; - static constexpr uint8_t matrix_col_pins[matrix_columns] = {PB1, PB0,PA7,PA6,PA5,PA4,PA3,PA2,PA1,PA0,PD1,PD0,PC15,PC14,PC13, PA9,PA10, PB8, PB7, PB6,PB5, PB9}; + static constexpr uint8_t matrix_col_pins[matrix_columns] = {PB1, PB0,PA7,PA6,PA5,PA4,PA3,PA2,PA1,PA0,PD1,PD0,PC15,PC14,PC13, PA9,PA10, PB8, PB7, PB6,PB5}; }; typedef kaleidoscope::driver::keyscanner::GD32 KeyScanner; - typedef Model100StorageProps StorageProps; + typedef SpacecadetStorageProps StorageProps; typedef kaleidoscope::driver::storage::GD32Flash Storage; typedef kaleidoscope::driver::bootloader::gd32::Base BootLoader; @@ -71,18 +69,15 @@ struct Model100Props : public kaleidoscope::device::BaseProps { }; -class Model100 : public kaleidoscope::device::Base { +class Spacecadet : public kaleidoscope::device::Base { public: - void setup(); - - static void enableHardwareTestMode(); }; } // namespace keyboardio } // namespace device -EXPORT_DEVICE(kaleidoscope::device::keyboardio::Model100) +EXPORT_DEVICE(kaleidoscope::device::keyboardio::Spacecadet) } @@ -96,11 +91,11 @@ EXPORT_DEVICE(kaleidoscope::device::keyboardio::Model100) r5c0, r5c1, r5c2, r5c3, r5c9, r5c15, r5c17, r5c18, r5c19, ...) \ \ \ - r0c0, xxx, r0c2, r0c3, xxx, r0c5, xxx, r0c7, xxx, r0c9, xxx, r0c11, xxx, r0c13, xxx, r0c15, xxx, r0c17, r0c18, r0c19, xxx, \ + r0c0, XXX, r0c2, r0c3, XXX, r0c5, XXX, r0c7, XXX, r0c9, XXX, r0c11, XXX, r0c13, XXX, r0c15, XXX, r0c17, r0c18, r0c19, XXX, \ r1c0, r1c1, r1c2, r1c3, r1c4, r1c5, r1c6, r1c7, r1c8, r1c9, r1c10, r1c11, r1c12, r1c13, r1c14, r1c15, r1c16, r1c17, r1c18, r1c19, r1c20, \ - r2c0, r2c1, r2c2, r2c3, r2c4, r2c5, r2c6, r2c7, r2c8, r2c9, r2c10, r2c11, r2c12, r2c13, r2c14, r2c15, r2c16, r2c17, r2c18, r2c19, xxx, \ - r3c0, xxx, r3c2, r3c3, r3c4, r3c5, r3c6, r3c7, r3c8, r3c9, r3c10, r3c11, r3c12, r3c13, r3c14, r3c15, xxx, r3c17, r3c18, xxx, r3c20, \ - r4c0, r4c1, r4c2, r4c3, xxx, r4c5, r4c6, r4c7, r4c8, r4c9, r4c10, r4c11, r4c12, r4c13, r4c14, r4c15, xxx, r4c17, r4c18, r4c19, r4c20, \ - r5c0, r5c1, r5c2, r5c3, xxx, xxx, xxx, xxx, xxx, r5c9, xxx, xxx, xxx, xxx, xxx, xxx, r5c15, xxx, r5c17, r5c18, RESTRICT_ARGS_COUNT((r5c19), 99, KEYMAP, ##__VA_ARGS__) + r2c0, r2c1, r2c2, r2c3, r2c4, r2c5, r2c6, r2c7, r2c8, r2c9, r2c10, r2c11, r2c12, r2c13, r2c14, r2c15, r2c16, r2c17, r2c18, r2c19, XXX, \ + r3c0, XXX, r3c2, r3c3, r3c4, r3c5, r3c6, r3c7, r3c8, r3c9, r3c10, r3c11, r3c12, r3c13, r3c14, r3c15, XXX, r3c17, r3c18, XXX, r3c20, \ + r4c0, r4c1, r4c2, r4c3, XXX, r4c5, r4c6, r4c7, r4c8, r4c9, r4c10, r4c11, r4c12, r4c13, r4c14, r4c15, XXX, r4c17, r4c18, r4c19, r4c20, \ + r5c0, r5c1, r5c2, r5c3, XXX, XXX, XXX, XXX, XXX, r5c9, XXX, XXX, XXX, XXX, XXX, XXX, r5c15, XXX, r5c17, r5c18, r5c19 #endif