Merge pull request #1143 from gedankenexperimenter/clang-format

Switch from `astyle` to `clang-format` for code formatting
pull/1149/head
Jesse Vincent 3 years ago committed by GitHub
commit aba8c9ee66
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,47 @@
# -*- mode: yaml -*-
---
BasedOnStyle: Google
---
Language: Cpp
AlignConsecutiveAssignments: Consecutive
## clang-format-15
# AlignConsecutiveAssignments:
# Enabled: true
# AlignCompound: true
# PadOperators: true
AlignConsecutiveDeclarations: None
AlignConsecutiveMacros: AcrossEmptyLines
AlignEscapedNewlines: Right
AllowShortBlocksOnASingleLine: Empty
AllowShortIfStatementsOnASingleLine: WithoutElse
AllowShortFunctionsOnASingleLine: Inline
AllowShortLoopsOnASingleLine: true
AttributeMacros:
- __attribute__((weak))
- __attribute__((always_inline))
- __attribute__((noinline))
- __attribute__((packed))
- __attribute__((optimize(3)))
- __attribute__((unused))
BinPackArguments: false
BinPackParameters: false
# BraceWrapping:
# SplitEmptyFunction: false
# SplitEmptyRecord: true
# SplitEmptyNamespace: true
# BreakBeforeBraces: Custom
ColumnLimit: 0
ConstructorInitializerIndentWidth: 2
ContinuationIndentWidth: 2
DerivePointerAlignment: false
FixNamespaceComments: true
IndentCaseLabels: false
KeepEmptyLinesAtTheStartOfBlocks: true
MaxEmptyLinesToKeep: 2
# PackConstructorInitializers: CurrentLine
PointerAlignment: Right
# ReferenceAlignment: Right
ReflowComments: false
SortIncludes: false
SpaceAfterTemplateKeyword: false

@ -6,6 +6,7 @@ env:
LC_ALL: C LC_ALL: C
KALEIDOSCOPE_CCACHE: 1 KALEIDOSCOPE_CCACHE: 1
ARDUINO_DIRECTORIES_USER: ${{ github.workspace }}/.arduino/user ARDUINO_DIRECTORIES_USER: ${{ github.workspace }}/.arduino/user
CLANG_FORMAT_CMD: clang-format-12
jobs: jobs:
smoke-sketches: smoke-sketches:
runs-on: ubuntu-latest runs-on: ubuntu-latest
@ -25,12 +26,11 @@ jobs:
- run: sudo apt-get install ccache - run: sudo apt-get install ccache
- run: make setup - run: make setup
- run: make -j $(nproc) simulator-tests - run: make -j $(nproc) simulator-tests
check-astyle: check-formatting:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- run: sudo apt-get install astyle
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- run: make check-astyle - run: make check-formatting
check-shellcheck: check-shellcheck:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:

@ -88,17 +88,13 @@ adjust-git-timestamps:
find-filename-conflicts: find-filename-conflicts:
bin/find-filename-conflicts bin/find-filename-conflicts
.PHONY: astyle test cpplint cpplint-noisy shellcheck smoke-examples find-filename-conflicts prepare-virtual checkout-platform adjust-git-timestamps docker-bash docker-simulator-tests run-tests simulator-tests setup .PHONY: format check-formatting cpplint cpplint-noisy shellcheck smoke-examples find-filename-conflicts prepare-virtual checkout-platform adjust-git-timestamps docker-bash docker-simulator-tests run-tests simulator-tests setup
astyle: format:
find ./* -type f \( -name '*.h' -o -name '*.cpp' -o -name '*.ino' \) | grep -v "testing/googletest" | xargs -n 1 astyle --project bin/format-code.sh
check-astyle: astyle check-formatting:
if ! git diff --exit-code; then \ bin/format-code.sh --check
>&2 echo "'astyle' found code style differences. Please make astyle and commit your changes"; \
exit 1; \
fi; \
exit 0;
cpplint-noisy: cpplint-noisy:
-bin/cpplint.py --filter=-legal/copyright,-build/include,-readability/namespace,-whitespace/line_length,-runtime/references --recursive --extensions=cpp,h,ino src examples -bin/cpplint.py --filter=-legal/copyright,-build/include,-readability/namespace,-whitespace/line_length,-runtime/references --recursive --extensions=cpp,h,ino src examples

@ -0,0 +1,25 @@
#!/usr/bin/env bash
# Allow the caller to specify a particular version of clang-format to use:
: "${CLANG_FORMAT_CMD:=clang-format}"
# Find all *.cpp and *.h files, except those in `testing/googletest/` and files
# generated by testcase scripts, and run `clang-format` on them:
find ./* -type f \( -name '*.h' -o -name '*.cpp' \) \
-not \( -path './testing/googletest/*' -o -name 'generated-testcase.cpp' \) \
-print0 | \
xargs -0 "${CLANG_FORMAT_CMD}" -i
# If we get the `--check` option, return an error if there are any changes to
# the git working tree after running `clang-format`:
if [[ $1 == '--check' ]]; then
if ! git diff --quiet; then
cat >&2 <<EOF
Differences found between git head and working tree. Either 'clang-format' made
formatting changes to your code, or you had uncommitted changes in your working
tree. Please remember to run 'bin/format-code.sh' before committing changes.
EOF
exit 1
fi
fi

@ -64,16 +64,16 @@ EventHandlerResult AppSwitcher::onKeyEvent(KeyEvent &event) {
// have any effect. Then we turn the event for that key's press into an // have any effect. Then we turn the event for that key's press into an
// event for the release of the AppSwitcher's modifier key. // event for the release of the AppSwitcher's modifier key.
live_keys.mask(event.addr); live_keys.mask(event.addr);
event.addr = active_addr_; event.addr = active_addr_;
event.state = WAS_PRESSED | INJECTED; event.state = WAS_PRESSED | INJECTED;
event.key = live_keys[event.addr]; event.key = live_keys[event.addr];
// Turn off AppSwitcher: // Turn off AppSwitcher:
active_addr_.clear(); active_addr_.clear();
} }
return EventHandlerResult::OK; return EventHandlerResult::OK;
} }
} // namespace plugin } // namespace plugin
} // namespace kaleidoscope } // namespace kaleidoscope
kaleidoscope::plugin::AppSwitcher AppSwitcher; kaleidoscope::plugin::AppSwitcher AppSwitcher;

@ -34,10 +34,9 @@ class AppSwitcher : public kaleidoscope::Plugin {
private: private:
KeyAddr active_addr_ = KeyAddr::none(); KeyAddr active_addr_ = KeyAddr::none();
}; };
} // namespace plugin } // namespace plugin
} // namespace kaleidoscope } // namespace kaleidoscope
extern kaleidoscope::plugin::AppSwitcher AppSwitcher; extern kaleidoscope::plugin::AppSwitcher AppSwitcher;

@ -34,8 +34,8 @@ namespace plugin {
// Configuration settings that can be saved to persistent storage. // Configuration settings that can be saved to persistent storage.
AutoShift::Settings AutoShift::settings_ = { AutoShift::Settings AutoShift::settings_ = {
.enabled = true, .enabled = true,
.timeout = 175, .timeout = 175,
.enabled_categories = AutoShift::Categories::printableKeys(), .enabled_categories = AutoShift::Categories::printableKeys(),
}; };
@ -62,8 +62,7 @@ void AutoShift::disable() {
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// Test for whether or not to apply AutoShift to a given `Key`. This function // Test for whether or not to apply AutoShift to a given `Key`. This function
// can be overridden from the user sketch. // can be overridden from the user sketch.
__attribute__((weak)) __attribute__((weak)) bool AutoShift::isAutoShiftable(Key key) {
bool AutoShift::isAutoShiftable(Key key) {
return enabledForKey(key); return enabledForKey(key);
} }
@ -207,7 +206,7 @@ void AutoShift::flushEvent(bool is_long_press) {
return; return;
KeyEvent event = queue_.event(0); KeyEvent event = queue_.event(0);
if (is_long_press) { if (is_long_press) {
event.key = Runtime.lookupKey(event.addr); event.key = Runtime.lookupKey(event.addr);
uint8_t flags = event.key.getFlags(); uint8_t flags = event.key.getFlags();
flags ^= SHIFT_HELD; flags ^= SHIFT_HELD;
event.key.setFlags(flags); event.key.setFlags(flags);
@ -216,7 +215,7 @@ void AutoShift::flushEvent(bool is_long_press) {
Runtime.handleKeyswitchEvent(event); Runtime.handleKeyswitchEvent(event);
} }
} // namespace plugin } // namespace plugin
} // namespace kaleidoscope } // namespace kaleidoscope
kaleidoscope::plugin::AutoShift AutoShift; kaleidoscope::plugin::AutoShift AutoShift;

@ -17,7 +17,7 @@
#pragma once #pragma once
#include <stdint.h> // for uint8_t, uint16_t #include <stdint.h> // for uint8_t, uint16_t
#include "kaleidoscope/KeyAddrEventQueue.h" // for KeyAddrEventQueue #include "kaleidoscope/KeyAddrEventQueue.h" // for KeyAddrEventQueue
#include "kaleidoscope/KeyEvent.h" // for KeyEvent #include "kaleidoscope/KeyEvent.h" // for KeyEvent
@ -63,16 +63,17 @@ class AutoShift : public Plugin {
uint8_t raw_bits_{0}; uint8_t raw_bits_{0};
// constants for bits in the `raw_bits_` bitfield // constants for bits in the `raw_bits_` bitfield
static constexpr uint8_t LETTERS = 1 << 0; static constexpr uint8_t LETTERS = 1 << 0;
static constexpr uint8_t NUMBERS = 1 << 1; static constexpr uint8_t NUMBERS = 1 << 1;
static constexpr uint8_t SYMBOLS = 1 << 2; static constexpr uint8_t SYMBOLS = 1 << 2;
static constexpr uint8_t ARROWS = 1 << 3; static constexpr uint8_t ARROWS = 1 << 3;
static constexpr uint8_t FUNCTIONS = 1 << 4; static constexpr uint8_t FUNCTIONS = 1 << 4;
static constexpr uint8_t ALL = 1 << 7; static constexpr uint8_t ALL = 1 << 7;
public: public:
// Basic un-checked constructor // Basic un-checked constructor
constexpr Categories(uint8_t raw_bits) : raw_bits_(raw_bits) {} constexpr Categories(uint8_t raw_bits)
: raw_bits_(raw_bits) {}
static constexpr Categories letterKeys() { static constexpr Categories letterKeys() {
return Categories(LETTERS); return Categories(LETTERS);
@ -276,8 +277,8 @@ class AutoShiftConfig : public Plugin {
static uint16_t settings_base_; static uint16_t settings_base_;
}; };
} // namespace plugin } // namespace plugin
} // namespace kaleidoscope } // namespace kaleidoscope
extern kaleidoscope::plugin::AutoShift AutoShift; extern kaleidoscope::plugin::AutoShift AutoShift;
extern kaleidoscope::plugin::AutoShiftConfig AutoShiftConfig; extern kaleidoscope::plugin::AutoShiftConfig AutoShiftConfig;

@ -17,10 +17,10 @@
#include "kaleidoscope/plugin/AutoShift.h" // IWYU pragma: associated #include "kaleidoscope/plugin/AutoShift.h" // IWYU pragma: associated
#include <Arduino.h> // for PSTR, strcmp_P, str... #include <Arduino.h> // for PSTR, strcmp_P, str...
#include <Kaleidoscope-EEPROM-Settings.h> // for EEPROMSettings #include <Kaleidoscope-EEPROM-Settings.h> // for EEPROMSettings
#include <Kaleidoscope-FocusSerial.h> // for Focus, FocusSerial #include <Kaleidoscope-FocusSerial.h> // for Focus, FocusSerial
#include <stdint.h> // for uint16_t, uint8_t #include <stdint.h> // for uint16_t, uint8_t
#include "kaleidoscope/Runtime.h" // for Runtime, Runtime_ #include "kaleidoscope/Runtime.h" // for Runtime, Runtime_
#include "kaleidoscope/device/Base.h" // for Base<>::Storage #include "kaleidoscope/device/Base.h" // for Base<>::Storage
@ -118,7 +118,7 @@ EventHandlerResult AutoShiftConfig::onFocusEvent(const char *command) {
return EventHandlerResult::EVENT_CONSUMED; return EventHandlerResult::EVENT_CONSUMED;
} }
} // namespace plugin } // namespace plugin
} // namespace kaleidoscope } // namespace kaleidoscope
kaleidoscope::plugin::AutoShiftConfig AutoShiftConfig; kaleidoscope::plugin::AutoShiftConfig AutoShiftConfig;

@ -17,9 +17,9 @@
#include "kaleidoscope/plugin/CharShift.h" #include "kaleidoscope/plugin/CharShift.h"
#include <Arduino.h> // for F, __FlashS... #include <Arduino.h> // for F, __FlashS...
#include <Kaleidoscope-FocusSerial.h> // for Focus, Focu... #include <Kaleidoscope-FocusSerial.h> // for Focus, Focu...
#include <Kaleidoscope-Ranges.h> // for CS_FIRST #include <Kaleidoscope-Ranges.h> // for CS_FIRST
#include "kaleidoscope/KeyAddrMap.h" // for KeyAddrMap<... #include "kaleidoscope/KeyAddrMap.h" // for KeyAddrMap<...
#include "kaleidoscope/KeyEvent.h" // for KeyEvent #include "kaleidoscope/KeyEvent.h" // for KeyEvent
@ -38,7 +38,7 @@ namespace plugin {
// ============================================================================= // =============================================================================
// CharShift class variables // CharShift class variables
CharShift::KeyPair const * CharShift::progmem_keypairs_{nullptr}; CharShift::KeyPair const *CharShift::progmem_keypairs_{nullptr};
uint8_t CharShift::num_keypairs_{0}; uint8_t CharShift::num_keypairs_{0};
bool CharShift::reverse_shift_state_{false}; bool CharShift::reverse_shift_state_{false};
@ -131,13 +131,15 @@ CharShift::KeyPair CharShift::decodeCharShiftKey(Key key) {
// This should be overridden if the KeyPairs array is stored in EEPROM // This should be overridden if the KeyPairs array is stored in EEPROM
__attribute__((weak)) __attribute__((weak))
uint8_t CharShift::numKeyPairs() { uint8_t
CharShift::numKeyPairs() {
return numProgmemKeyPairs(); return numProgmemKeyPairs();
} }
// This should be overridden if the KeyPairs array is stored in EEPROM // This should be overridden if the KeyPairs array is stored in EEPROM
__attribute__((weak)) __attribute__((weak))
CharShift::KeyPair CharShift::readKeyPair(uint8_t n) { CharShift::KeyPair
CharShift::readKeyPair(uint8_t n) {
return readKeyPairFromProgmem(n); return readKeyPairFromProgmem(n);
} }
@ -149,7 +151,7 @@ CharShift::KeyPair CharShift::readKeyPairFromProgmem(uint8_t n) {
return cloneFromProgmem(progmem_keypairs_[n]); return cloneFromProgmem(progmem_keypairs_[n]);
} }
} // namespace plugin } // namespace plugin
} // namespace kaleidoscope } // namespace kaleidoscope
kaleidoscope::plugin::CharShift CharShift; kaleidoscope::plugin::CharShift CharShift;

@ -17,8 +17,8 @@
#pragma once #pragma once
#include <Kaleidoscope-Ranges.h> // for CS_FIRST #include <Kaleidoscope-Ranges.h> // for CS_FIRST
#include <stdint.h> // for uint8_t #include <stdint.h> // for uint8_t
#include "Arduino.h" // for PROGMEM #include "Arduino.h" // for PROGMEM
#include "kaleidoscope/KeyEvent.h" // for KeyEvent #include "kaleidoscope/KeyEvent.h" // for KeyEvent
@ -59,7 +59,8 @@ class CharShift : public Plugin {
/// ///
/// This constructor is used when defining an array of `KeyPair` objects in /// This constructor is used when defining an array of `KeyPair` objects in
/// PROGMEM (though it can also be used elsewhere). /// PROGMEM (though it can also be used elsewhere).
constexpr KeyPair(Key lower, Key upper) : lower(lower), upper(upper) {} constexpr KeyPair(Key lower, Key upper)
: lower(lower), upper(upper) {}
/// Constructor for reading from PROGMEM /// Constructor for reading from PROGMEM
/// ///
@ -75,15 +76,15 @@ class CharShift : public Plugin {
/// `keypairs` array given, which must be a fixed-sized array, not a pointer. /// `keypairs` array given, which must be a fixed-sized array, not a pointer.
/// Generally, it will be called via the `KEYPAIRS()` preprocessor macro, not /// Generally, it will be called via the `KEYPAIRS()` preprocessor macro, not
/// directly by user code. /// directly by user code.
template <uint8_t _num_keypairs> template<uint8_t _num_keypairs>
static void setProgmemKeyPairs(KeyPair const(&keypairs)[_num_keypairs]) { static void setProgmemKeyPairs(KeyPair const (&keypairs)[_num_keypairs]) {
progmem_keypairs_ = keypairs; progmem_keypairs_ = keypairs;
num_keypairs_ = _num_keypairs; num_keypairs_ = _num_keypairs;
} }
private: private:
// A pointer to an array of `KeyPair` objects in PROGMEM // A pointer to an array of `KeyPair` objects in PROGMEM
static KeyPair const * progmem_keypairs_; static KeyPair const *progmem_keypairs_;
// The size of the PROGMEM array of `KeyPair` objects // The size of the PROGMEM array of `KeyPair` objects
static uint8_t num_keypairs_; static uint8_t num_keypairs_;
@ -114,8 +115,8 @@ class CharShift : public Plugin {
static KeyPair readKeyPairFromProgmem(uint8_t n); static KeyPair readKeyPairFromProgmem(uint8_t n);
}; };
} // namespace plugin } // namespace plugin
} // namespace kaleidoscope } // namespace kaleidoscope
extern kaleidoscope::plugin::CharShift CharShift; extern kaleidoscope::plugin::CharShift CharShift;
@ -125,12 +126,12 @@ extern kaleidoscope::plugin::CharShift CharShift;
/// defines them as an array in PROGMEM, and configures `CharShift` to use that /// defines them as an array in PROGMEM, and configures `CharShift` to use that
/// array, automatically setting the count correctly to prevent out-of-bounds /// array, automatically setting the count correctly to prevent out-of-bounds
/// lookups. /// lookups.
#define CS_KEYS(keypairs...) { \ #define CS_KEYS(keypairs...) \
{ \
static kaleidoscope::plugin::CharShift::KeyPair const kp_table[] PROGMEM = { \ static kaleidoscope::plugin::CharShift::KeyPair const kp_table[] PROGMEM = { \
keypairs \ keypairs}; \
}; \ CharShift.setProgmemKeyPairs(kp_table); \
CharShift.setProgmemKeyPairs(kp_table); \ }
}
/// Define an `KeyPair` entry in a keymap /// Define an `KeyPair` entry in a keymap
/// ///

@ -17,10 +17,10 @@
#include "kaleidoscope/plugin/Colormap.h" #include "kaleidoscope/plugin/Colormap.h"
#include <Arduino.h> // for F, PSTR, __FlashStrin... #include <Arduino.h> // for F, PSTR, __FlashStrin...
#include <Kaleidoscope-FocusSerial.h> // for Focus, FocusSerial #include <Kaleidoscope-FocusSerial.h> // for Focus, FocusSerial
#include <Kaleidoscope-LED-Palette-Theme.h> // for LEDPaletteTheme #include <Kaleidoscope-LED-Palette-Theme.h> // for LEDPaletteTheme
#include <stdint.h> // for uint8_t, uint16_t #include <stdint.h> // for uint8_t, uint16_t
#include "kaleidoscope/KeyAddr.h" // for KeyAddr #include "kaleidoscope/KeyAddr.h" // for KeyAddr
#include "kaleidoscope/Runtime.h" // for Runtime, Runtime_ #include "kaleidoscope/Runtime.h" // for Runtime, Runtime_
@ -40,7 +40,7 @@ void ColormapEffect::max_layers(uint8_t max_) {
return; return;
max_layers_ = max_; max_layers_ = max_;
map_base_ = ::LEDPaletteTheme.reserveThemes(max_layers_); map_base_ = ::LEDPaletteTheme.reserveThemes(max_layers_);
} }
EventHandlerResult ColormapEffect::onNameQuery() { EventHandlerResult ColormapEffect::onNameQuery() {
@ -68,8 +68,7 @@ EventHandlerResult ColormapEffect::onLayerChange() {
} }
EventHandlerResult ColormapEffect::onFocusEvent(const char *command) { EventHandlerResult ColormapEffect::onFocusEvent(const char *command) {
return ::LEDPaletteTheme.themeFocusEvent(command, PSTR("colormap.map"), return ::LEDPaletteTheme.themeFocusEvent(command, PSTR("colormap.map"), map_base_, max_layers_);
map_base_, max_layers_);
} }
} // namespace plugin } // namespace plugin

@ -17,7 +17,7 @@
#pragma once #pragma once
#include <stdint.h> // for uint8_t, uin... #include <stdint.h> // for uint8_t, uin...
#include "kaleidoscope/KeyAddr.h" // for KeyAddr #include "kaleidoscope/KeyAddr.h" // for KeyAddr
#include "kaleidoscope/event_handler_result.h" // for EventHandler... #include "kaleidoscope/event_handler_result.h" // for EventHandler...
@ -29,8 +29,8 @@
namespace kaleidoscope { namespace kaleidoscope {
namespace plugin { namespace plugin {
class ColormapEffect : public Plugin, class ColormapEffect : public Plugin,
public LEDModeInterface, public LEDModeInterface,
public AccessTransientLEDMode { public AccessTransientLEDMode {
public: public:
ColormapEffect(void) {} ColormapEffect(void) {}
@ -44,21 +44,20 @@ class ColormapEffect : public Plugin,
// //
class TransientLEDMode : public LEDMode { class TransientLEDMode : public LEDMode {
public: public:
// Please note that storing the parent ptr is only required // Please note that storing the parent ptr is only required
// for those LED modes that require access to // for those LED modes that require access to
// members of their parent class. Most LED modes can do without. // members of their parent class. Most LED modes can do without.
// //
explicit TransientLEDMode(const ColormapEffect *parent) : parent_(parent) {} explicit TransientLEDMode(const ColormapEffect *parent)
: parent_(parent) {}
protected: protected:
friend class ColormapEffect; friend class ColormapEffect;
void onActivate(void) final; void onActivate(void) final;
void refreshAt(KeyAddr key_addr) final; void refreshAt(KeyAddr key_addr) final;
private:
private:
const ColormapEffect *parent_; const ColormapEffect *parent_;
}; };

@ -17,10 +17,10 @@
#include "kaleidoscope/plugin/Cycle.h" #include "kaleidoscope/plugin/Cycle.h"
#include <Arduino.h> // for F, __FlashStringHelper #include <Arduino.h> // for F, __FlashStringHelper
#include <Kaleidoscope-FocusSerial.h> // for Focus, FocusSerial #include <Kaleidoscope-FocusSerial.h> // for Focus, FocusSerial
#include <Kaleidoscope-Ranges.h> // for CYCLE #include <Kaleidoscope-Ranges.h> // for CYCLE
#include <stdint.h> // for uint8_t #include <stdint.h> // for uint8_t
#include "kaleidoscope/KeyAddr.h" // for KeyAddr, MatrixAddr #include "kaleidoscope/KeyAddr.h" // for KeyAddr, MatrixAddr
#include "kaleidoscope/KeyEvent.h" // for KeyEvent #include "kaleidoscope/KeyEvent.h" // for KeyEvent
@ -113,8 +113,7 @@ uint8_t Cycle::toModFlag(uint8_t keyCode) {
} // namespace plugin } // namespace plugin
} // namespace kaleidoscope } // namespace kaleidoscope
__attribute__((weak)) __attribute__((weak)) void cycleAction(Key previous_key, uint8_t cycle_count) {
void cycleAction(Key previous_key, uint8_t cycle_count) {
} }
kaleidoscope::plugin::Cycle Cycle; kaleidoscope::plugin::Cycle Cycle;

@ -17,8 +17,8 @@
#pragma once #pragma once
#include <Kaleidoscope-Ranges.h> // for CYCLE #include <Kaleidoscope-Ranges.h> // for CYCLE
#include <stdint.h> // for uint8_t #include <stdint.h> // for uint8_t
#include "Arduino.h" // for PROGMEM #include "Arduino.h" // for PROGMEM
#include "kaleidoscope/KeyAddr.h" // for KeyAddr #include "kaleidoscope/KeyAddr.h" // for KeyAddr
@ -29,10 +29,10 @@
constexpr Key Key_Cycle = Key(kaleidoscope::ranges::CYCLE); constexpr Key Key_Cycle = Key(kaleidoscope::ranges::CYCLE);
#define cycleThrough(...) ({ \ #define cycleThrough(...) ({ \
static const Key __k[] PROGMEM = { __VA_ARGS__ }; \ static const Key __k[] PROGMEM = {__VA_ARGS__}; \
Cycle.replace(sizeof(__k) / sizeof(Key), &__k[0]); \ Cycle.replace(sizeof(__k) / sizeof(Key), &__k[0]); \
}) })
namespace kaleidoscope { namespace kaleidoscope {
namespace plugin { namespace plugin {

@ -17,9 +17,9 @@
#include "kaleidoscope/plugin/CycleTimeReport.h" #include "kaleidoscope/plugin/CycleTimeReport.h"
#include <Arduino.h> // for micros, F, __FlashStr... #include <Arduino.h> // for micros, F, __FlashStr...
#include <Kaleidoscope-FocusSerial.h> // for Focus, FocusSerial #include <Kaleidoscope-FocusSerial.h> // for Focus, FocusSerial
#include <stdint.h> // for uint16_t, uint32_t #include <stdint.h> // for uint16_t, uint32_t
#include "kaleidoscope/Runtime.h" // for Runtime, Runtime_ #include "kaleidoscope/Runtime.h" // for Runtime, Runtime_
#include "kaleidoscope/event_handler_result.h" // for EventHandlerResult #include "kaleidoscope/event_handler_result.h" // for EventHandlerResult
@ -62,8 +62,7 @@ EventHandlerResult CycleTimeReport::afterEachCycle() {
} // namespace kaleidoscope } // namespace kaleidoscope
__attribute__((weak)) void cycleTimeReport(void) { __attribute__((weak)) void cycleTimeReport(void) {
Focus.send(Focus.COMMENT, F("average loop time:"), CycleTimeReport.average_loop_time, Focus.send(Focus.COMMENT, F("average loop time:"), CycleTimeReport.average_loop_time, Focus.NEWLINE);
Focus.NEWLINE);
} }
kaleidoscope::plugin::CycleTimeReport CycleTimeReport; kaleidoscope::plugin::CycleTimeReport CycleTimeReport;

@ -17,7 +17,7 @@
#pragma once #pragma once
#include <stdint.h> // for uint32_t, uint16_t #include <stdint.h> // for uint32_t, uint16_t
#include "kaleidoscope/event_handler_result.h" // for EventHandlerResult #include "kaleidoscope/event_handler_result.h" // for EventHandlerResult
#include "kaleidoscope/plugin.h" // for Plugin #include "kaleidoscope/plugin.h" // for Plugin

@ -57,7 +57,7 @@ constexpr size_t strlen(const char *str) {
return str[0] ? strlen(str + 1) + 1 : 0; return str[0] ? strlen(str + 1) + 1 : 0;
} }
template <char... chars> template<char... chars>
struct string { struct string {
#if ARDUINOTRACE_ENABLE_PROGMEM #if ARDUINOTRACE_ENABLE_PROGMEM
const __FlashStringHelper *data() { const __FlashStringHelper *data() {
@ -72,52 +72,47 @@ struct string {
#endif #endif
}; };
template <typename TSourceString, size_t remainingLength, template<typename TSourceString, size_t remainingLength, char... collectedChars>
char... collectedChars>
struct string_maker { struct string_maker {
using result = using result =
typename string_maker < TSourceString, remainingLength - 1, typename string_maker<TSourceString, remainingLength - 1, TSourceString::data()[remainingLength - 1], collectedChars...>::result;
TSourceString::data()[remainingLength - 1],
collectedChars... >::result;
}; };
#if ARDUINOTRACE_ENABLE_FULLPATH == 0 #if ARDUINOTRACE_ENABLE_FULLPATH == 0
template <typename TSourceString, size_t remainingLength, template<typename TSourceString, size_t remainingLength, char... collectedChars>
char... collectedChars>
struct string_maker<TSourceString, remainingLength, '/', collectedChars...> { struct string_maker<TSourceString, remainingLength, '/', collectedChars...> {
using result = string<collectedChars..., '\0'>; using result = string<collectedChars..., '\0'>;
}; };
template <typename TSourceString, size_t remainingLength, template<typename TSourceString, size_t remainingLength, char... collectedChars>
char... collectedChars>
struct string_maker<TSourceString, remainingLength, '\\', collectedChars...> { struct string_maker<TSourceString, remainingLength, '\\', collectedChars...> {
using result = string<collectedChars..., '\0'>; using result = string<collectedChars..., '\0'>;
}; };
#endif #endif
template <typename TSourceString, char... collectedChars> template<typename TSourceString, char... collectedChars>
struct string_maker<TSourceString, 0, collectedChars...> { struct string_maker<TSourceString, 0, collectedChars...> {
using result = string<collectedChars..., '\0'>; using result = string<collectedChars..., '\0'>;
}; };
template <typename TStringSource> template<typename TStringSource>
using make_string = using make_string =
typename string_maker<TStringSource, strlen(TStringSource::data())>::result; typename string_maker<TStringSource, strlen(TStringSource::data())>::result;
struct Initializer { struct Initializer {
template <typename TSerial> template<typename TSerial>
Initializer(TSerial &serial, int bauds) { Initializer(TSerial &serial, int bauds) {
serial.begin(bauds); serial.begin(bauds);
while (!serial) continue; while (!serial) continue;
} }
}; };
template <typename TFilename, typename TPrefix> template<typename TFilename, typename TPrefix>
struct Printer { struct Printer {
template <typename TSerial, typename TValue> template<typename TSerial, typename TValue>
Printer(TSerial &serial, const TValue &content) { Printer(TSerial &serial, const TValue &content) {
serial.print(make_string<TFilename> {}.data()); serial.print(make_string<TFilename>{}.data());
serial.print(make_string<TPrefix> {}.data()); serial.print(make_string<TPrefix>{}.data());
serial.println(content); serial.println(content);
serial.flush(); serial.flush();
} }
@ -154,7 +149,7 @@ struct Printer {
#define ARDUINOTRACE_INITIALIZE(id, bauds) \ #define ARDUINOTRACE_INITIALIZE(id, bauds) \
ArduinoTrace::Initializer ARDUINOTRACE_CONCAT(__initializer, id)( \ ArduinoTrace::Initializer ARDUINOTRACE_CONCAT(__initializer, id)( \
ARDUINOTRACE_SERIAL, bauds); ARDUINOTRACE_SERIAL, bauds);
#define ARDUINOTRACE_TRACE_PREFIX(line) ":" ARDUINOTRACE_STRINGIFY(line) ": " #define ARDUINOTRACE_TRACE_PREFIX(line) ":" ARDUINOTRACE_STRINGIFY(line) ": "
@ -172,19 +167,16 @@ struct Printer {
// Call this macro anywhere, including at global scope. // Call this macro anywhere, including at global scope.
// However, if you use it at global scope, you need to call ARDUINOTRACE_INIT() // However, if you use it at global scope, you need to call ARDUINOTRACE_INIT()
// first, otherwise, the Serial port will not be ready. // first, otherwise, the Serial port will not be ready.
#define TRACE() \ #define TRACE() \
ARDUINOTRACE_PRINT(__COUNTER__, __FILE__, \ ARDUINOTRACE_PRINT(__COUNTER__, __FILE__, ARDUINOTRACE_TRACE_PREFIX(__LINE__), ARDUINOTRACE_FUNCTION_NAME)
ARDUINOTRACE_TRACE_PREFIX(__LINE__), \
ARDUINOTRACE_FUNCTION_NAME)
// Prints the value of a variable. // Prints the value of a variable.
// //
// This function will print the name and the value of the variable to the // This function will print the name and the value of the variable to the
// Serial. If you use it at global scope, you need to call ARDUINOTRACE_INIT() // Serial. If you use it at global scope, you need to call ARDUINOTRACE_INIT()
// first, otherwise, the Serial port will not be ready. // first, otherwise, the Serial port will not be ready.
#define DUMP(variable) \ #define DUMP(variable) \
ARDUINOTRACE_PRINT(__COUNTER__, __FILE__, \ ARDUINOTRACE_PRINT(__COUNTER__, __FILE__, ARDUINOTRACE_DUMP_PREFIX(__LINE__, variable), variable)
ARDUINOTRACE_DUMP_PREFIX(__LINE__, variable), variable)
#else // ie ARDUINOTRACE_ENABLE == 0 #else // ie ARDUINOTRACE_ENABLE == 0

@ -16,6 +16,6 @@
#pragma once #pragma once
#include <Kaleidoscope-Macros.h> // IWYU pragma: keep #include <Kaleidoscope-Macros.h> // IWYU pragma: keep
#include "kaleidoscope/plugin/DynamicMacros.h" // IWYU pragma: export #include "kaleidoscope/plugin/DynamicMacros.h" // IWYU pragma: export

@ -16,16 +16,16 @@
#include "kaleidoscope/plugin/DynamicMacros.h" #include "kaleidoscope/plugin/DynamicMacros.h"
#include <Arduino.h> // for delay, PSTR, strc... #include <Arduino.h> // for delay, PSTR, strc...
#include <Kaleidoscope-FocusSerial.h> // for Focus, FocusSerial #include <Kaleidoscope-FocusSerial.h> // for Focus, FocusSerial
#include <Kaleidoscope-Ranges.h> // for DYNAMIC_MACRO_FIRST #include <Kaleidoscope-Ranges.h> // for DYNAMIC_MACRO_FIRST
#include "kaleidoscope/KeyAddr.h" // for KeyAddr #include "kaleidoscope/KeyAddr.h" // for KeyAddr
#include "kaleidoscope/KeyEvent.h" // for KeyEvent #include "kaleidoscope/KeyEvent.h" // for KeyEvent
#include "kaleidoscope/Runtime.h" // for Runtime, Runtime_ #include "kaleidoscope/Runtime.h" // for Runtime, Runtime_
#include "kaleidoscope/device/device.h" // for VirtualProps::Sto... #include "kaleidoscope/device/device.h" // for VirtualProps::Sto...
#include "kaleidoscope/keyswitch_state.h" // for INJECTED, IS_PRESSED #include "kaleidoscope/keyswitch_state.h" // for INJECTED, IS_PRESSED
#include "kaleidoscope/plugin/EEPROM-Settings.h" // for EEPROMSettings #include "kaleidoscope/plugin/EEPROM-Settings.h" // for EEPROMSettings
// This is a special exception to the rule of only including a plugin's // This is a special exception to the rule of only including a plugin's
// top-level header file, because DynamicMacros doesn't depend on the Macros // top-level header file, because DynamicMacros doesn't depend on the Macros
@ -67,9 +67,9 @@ void DynamicMacros::tap(Key key) {
} }
void DynamicMacros::updateDynamicMacroCache() { void DynamicMacros::updateDynamicMacroCache() {
uint16_t pos = storage_base_; uint16_t pos = storage_base_;
uint8_t current_id = 0; uint8_t current_id = 0;
macro_t macro = MACRO_ACTION_END; macro_t macro = MACRO_ACTION_END;
bool previous_macro_ended = false; bool previous_macro_ended = false;
map_[0] = 0; map_[0] = 0;
@ -103,7 +103,7 @@ void DynamicMacros::updateDynamicMacroCache() {
previous_macro_ended = false; previous_macro_ended = false;
uint8_t keyCode, flags; uint8_t keyCode, flags;
do { do {
flags = Runtime.storage().read(pos++); flags = Runtime.storage().read(pos++);
keyCode = Runtime.storage().read(pos++); keyCode = Runtime.storage().read(pos++);
} while (!(flags == 0 && keyCode == 0)); } while (!(flags == 0 && keyCode == 0));
break; break;
@ -132,7 +132,7 @@ void DynamicMacros::updateDynamicMacroCache() {
// public // public
void DynamicMacros::play(uint8_t macro_id) { void DynamicMacros::play(uint8_t macro_id) {
macro_t macro = MACRO_ACTION_END; macro_t macro = MACRO_ACTION_END;
uint8_t interval = 0; uint8_t interval = 0;
uint16_t pos; uint16_t pos;
Key key; Key key;
@ -289,7 +289,7 @@ void DynamicMacros::reserve_storage(uint16_t size) {
updateDynamicMacroCache(); updateDynamicMacroCache();
} }
} // namespace plugin } // namespace plugin
} // namespace kaleidoscope } // namespace kaleidoscope
kaleidoscope::plugin::DynamicMacros DynamicMacros; kaleidoscope::plugin::DynamicMacros DynamicMacros;

@ -16,15 +16,15 @@
#pragma once #pragma once
#include <Kaleidoscope-Ranges.h> // for DYNAMIC_MACRO_FIRST #include <Kaleidoscope-Ranges.h> // for DYNAMIC_MACRO_FIRST
#include <stdint.h> // for uint16_t, uint8_t #include <stdint.h> // for uint16_t, uint8_t
#include "kaleidoscope/KeyEvent.h" // for KeyEvent #include "kaleidoscope/KeyEvent.h" // for KeyEvent
#include "kaleidoscope/event_handler_result.h" // for EventHandlerResult #include "kaleidoscope/event_handler_result.h" // for EventHandlerResult
#include "kaleidoscope/key_defs.h" // for Key #include "kaleidoscope/key_defs.h" // for Key
#include "kaleidoscope/plugin.h" // for Plugin #include "kaleidoscope/plugin.h" // for Plugin
#define DM(n) ::kaleidoscope::plugin::DynamicMacrosKey(n) #define DM(n) ::kaleidoscope::plugin::DynamicMacrosKey(n)
#define MAX_CONCURRENT_DYNAMIC_MACRO_KEYS 8 #define MAX_CONCURRENT_DYNAMIC_MACRO_KEYS 8
@ -56,7 +56,7 @@ class DynamicMacros : public kaleidoscope::Plugin {
static void tap(Key key); static void tap(Key key);
}; };
} // namespace plugin } // namespace plugin
} // namespace kaleidoscope } // namespace kaleidoscope
extern kaleidoscope::plugin::DynamicMacros DynamicMacros; extern kaleidoscope::plugin::DynamicMacros DynamicMacros;

@ -17,10 +17,10 @@
#include "kaleidoscope/plugin/DynamicTapDance.h" #include "kaleidoscope/plugin/DynamicTapDance.h"
#include <Arduino.h> // for PSTR, F, __FlashStrin... #include <Arduino.h> // for PSTR, F, __FlashStrin...
#include <Kaleidoscope-EEPROM-Settings.h> // for EEPROMSettings #include <Kaleidoscope-EEPROM-Settings.h> // for EEPROMSettings
#include <Kaleidoscope-FocusSerial.h> // for Focus, FocusSerial #include <Kaleidoscope-FocusSerial.h> // for Focus, FocusSerial
#include <stdint.h> // for uint16_t, uint8_t #include <stdint.h> // for uint16_t, uint8_t
#include "kaleidoscope/KeyAddr.h" // for KeyAddr #include "kaleidoscope/KeyAddr.h" // for KeyAddr
#include "kaleidoscope/KeyEvent.h" // for KeyEvent #include "kaleidoscope/KeyEvent.h" // for KeyEvent
@ -42,12 +42,12 @@ uint8_t DynamicTapDance::dance_count_;
constexpr uint8_t DynamicTapDance::reserved_tap_dance_key_count_; constexpr uint8_t DynamicTapDance::reserved_tap_dance_key_count_;
void DynamicTapDance::updateDynamicTapDanceCache() { void DynamicTapDance::updateDynamicTapDanceCache() {
uint16_t pos = storage_base_; uint16_t pos = storage_base_;
uint8_t current_id = 0; uint8_t current_id = 0;
bool previous_dance_ended = false; bool previous_dance_ended = false;
dance_count_ = 0; dance_count_ = 0;
map_[0] = 0; map_[0] = 0;
while (pos < storage_base_ + storage_size_) { while (pos < storage_base_ + storage_size_) {
uint16_t raw_key = Runtime.storage().read(pos); uint16_t raw_key = Runtime.storage().read(pos);
@ -68,9 +68,8 @@ void DynamicTapDance::updateDynamicTapDanceCache() {
} }
} }
bool DynamicTapDance::dance(uint8_t tap_dance_index, KeyAddr key_addr, bool DynamicTapDance::dance(uint8_t tap_dance_index, KeyAddr key_addr, uint8_t tap_count, TapDance::ActionType tap_dance_action) {
uint8_t tap_count, TapDance::ActionType tap_dance_action) { uint16_t pos = map_[tap_dance_index - offset_] + ((tap_count - 1) * 2);
uint16_t pos = map_[tap_dance_index - offset_] + ((tap_count - 1) * 2);
uint16_t next_pos = map_[tap_dance_index - offset_ + 1]; uint16_t next_pos = map_[tap_dance_index - offset_ + 1];
if (next_pos <= pos || (tap_dance_index > offset_ + dance_count_)) if (next_pos <= pos || (tap_dance_index > offset_ + dance_count_))
return false; return false;
@ -136,7 +135,7 @@ EventHandlerResult DynamicTapDance::onFocusEvent(const char *command) {
void DynamicTapDance::setup(uint8_t dynamic_offset, uint16_t size) { void DynamicTapDance::setup(uint8_t dynamic_offset, uint16_t size) {
storage_base_ = ::EEPROMSettings.requestSlice(size); storage_base_ = ::EEPROMSettings.requestSlice(size);
storage_size_ = size; storage_size_ = size;
offset_ = dynamic_offset; offset_ = dynamic_offset;
updateDynamicTapDanceCache(); updateDynamicTapDanceCache();
} }

@ -17,9 +17,9 @@
#pragma once #pragma once
#include <Kaleidoscope-Ranges.h> // for TD_FIRST, TD_LAST #include <Kaleidoscope-Ranges.h> // for TD_FIRST, TD_LAST
#include <Kaleidoscope-TapDance.h> // for TapDance, TapDance::A... #include <Kaleidoscope-TapDance.h> // for TapDance, TapDance::A...
#include <stdint.h> // for uint8_t, uint16_t #include <stdint.h> // for uint8_t, uint16_t
#include "kaleidoscope/KeyAddr.h" // for KeyAddr #include "kaleidoscope/KeyAddr.h" // for KeyAddr
#include "kaleidoscope/event_handler_result.h" // for EventHandlerResult #include "kaleidoscope/event_handler_result.h" // for EventHandlerResult
@ -28,7 +28,7 @@
namespace kaleidoscope { namespace kaleidoscope {
namespace plugin { namespace plugin {
class DynamicTapDance: public kaleidoscope::Plugin { class DynamicTapDance : public kaleidoscope::Plugin {
public: public:
DynamicTapDance() {} DynamicTapDance() {}
@ -37,8 +37,7 @@ class DynamicTapDance: public kaleidoscope::Plugin {
static void setup(uint8_t dynamic_offset, uint16_t size); static void setup(uint8_t dynamic_offset, uint16_t size);
static bool dance(uint8_t tap_dance_index, KeyAddr key_addr, uint8_t tap_count, static bool dance(uint8_t tap_dance_index, KeyAddr key_addr, uint8_t tap_count, TapDance::ActionType tap_dance_action);
TapDance::ActionType tap_dance_action);
private: private:
static uint16_t storage_base_; static uint16_t storage_base_;

@ -17,10 +17,10 @@
#include "kaleidoscope/plugin/EEPROM-Keymap-Programmer.h" #include "kaleidoscope/plugin/EEPROM-Keymap-Programmer.h"
#include <Arduino.h> // for PSTR, strcmp_P #include <Arduino.h> // for PSTR, strcmp_P
#include <Kaleidoscope-EEPROM-Keymap.h> // for EEPROMKeymap #include <Kaleidoscope-EEPROM-Keymap.h> // for EEPROMKeymap
#include <Kaleidoscope-FocusSerial.h> // for Focus, FocusSerial #include <Kaleidoscope-FocusSerial.h> // for Focus, FocusSerial
#include <stdint.h> // for uint16_t, uint8_t #include <stdint.h> // for uint16_t, uint8_t
#include "kaleidoscope/KeyAddr.h" // for KeyAddr #include "kaleidoscope/KeyAddr.h" // for KeyAddr
#include "kaleidoscope/KeyEvent.h" // for KeyEvent #include "kaleidoscope/KeyEvent.h" // for KeyEvent
@ -60,8 +60,8 @@ void EEPROMKeymapProgrammer::nextState(void) {
void EEPROMKeymapProgrammer::cancel(void) { void EEPROMKeymapProgrammer::cancel(void) {
update_position_ = 0; update_position_ = 0;
new_key_ = Key_NoKey; new_key_ = Key_NoKey;
state_ = INACTIVE; state_ = INACTIVE;
} }
EventHandlerResult EEPROMKeymapProgrammer::onKeyEvent(KeyEvent &event) { EventHandlerResult EEPROMKeymapProgrammer::onKeyEvent(KeyEvent &event) {

@ -17,7 +17,7 @@
#pragma once #pragma once
#include <stdint.h> // for uint16_t #include <stdint.h> // for uint16_t
#include "kaleidoscope/KeyEvent.h" // for KeyEvent #include "kaleidoscope/KeyEvent.h" // for KeyEvent
#include "kaleidoscope/event_handler_result.h" // for EventHandlerResult #include "kaleidoscope/event_handler_result.h" // for EventHandlerResult

@ -17,10 +17,10 @@
#include "kaleidoscope/plugin/EEPROM-Keymap.h" #include "kaleidoscope/plugin/EEPROM-Keymap.h"
#include <Arduino.h> // for PSTR, strcmp_P, F #include <Arduino.h> // for PSTR, strcmp_P, F
#include <Kaleidoscope-EEPROM-Settings.h> // for EEPROMSettings #include <Kaleidoscope-EEPROM-Settings.h> // for EEPROMSettings
#include <Kaleidoscope-FocusSerial.h> // for Focus, FocusSerial #include <Kaleidoscope-FocusSerial.h> // for Focus, FocusSerial
#include <stdint.h> // for uint8_t, uint16_t #include <stdint.h> // for uint8_t, uint16_t
#include "kaleidoscope/KeyAddr.h" // for KeyAddr, MatrixAddr #include "kaleidoscope/KeyAddr.h" // for KeyAddr, MatrixAddr
#include "kaleidoscope/Runtime.h" // for Runtime, Runtime_ #include "kaleidoscope/Runtime.h" // for Runtime, Runtime_
@ -57,7 +57,7 @@ void EEPROMKeymap::setup(uint8_t max) {
} }
void EEPROMKeymap::max_layers(uint8_t max) { void EEPROMKeymap::max_layers(uint8_t max) {
max_layers_ = max; max_layers_ = max;
keymap_base_ = ::EEPROMSettings.requestSlice(max_layers_ * Runtime.device().numKeys() * 2); keymap_base_ = ::EEPROMSettings.requestSlice(max_layers_ * Runtime.device().numKeys() * 2);
} }
@ -67,8 +67,8 @@ Key EEPROMKeymap::getKey(uint8_t layer, KeyAddr key_addr) {
uint16_t pos = ((layer * Runtime.device().numKeys()) + key_addr.toInt()) * 2; uint16_t pos = ((layer * Runtime.device().numKeys()) + key_addr.toInt()) * 2;
return Key(Runtime.storage().read(keymap_base_ + pos + 1), // key_code return Key(Runtime.storage().read(keymap_base_ + pos + 1), // key_code
Runtime.storage().read(keymap_base_ + pos)); // flags Runtime.storage().read(keymap_base_ + pos)); // flags
} }
Key EEPROMKeymap::getKeyExtended(uint8_t layer, KeyAddr key_addr) { Key EEPROMKeymap::getKeyExtended(uint8_t layer, KeyAddr key_addr) {
@ -91,7 +91,7 @@ void EEPROMKeymap::updateKey(uint16_t base_pos, Key key) {
Runtime.storage().update(keymap_base_ + base_pos * 2 + 1, key.getKeyCode()); Runtime.storage().update(keymap_base_ + base_pos * 2 + 1, key.getKeyCode());
} }
void EEPROMKeymap::dumpKeymap(uint8_t layers, Key(*getkey)(uint8_t, KeyAddr)) { void EEPROMKeymap::dumpKeymap(uint8_t layers, Key (*getkey)(uint8_t, KeyAddr)) {
for (uint8_t layer = 0; layer < layers; layer++) { for (uint8_t layer = 0; layer < layers; layer++) {
for (auto key_addr : KeyAddr::all()) { for (auto key_addr : KeyAddr::all()) {
Key k = (*getkey)(layer, key_addr); Key k = (*getkey)(layer, key_addr);
@ -134,7 +134,7 @@ EventHandlerResult EEPROMKeymap::onFocusEvent(const char *command) {
// we actully want. // we actully want.
// //
dumpKeymap(progmem_layers_, dumpKeymap(progmem_layers_,
static_cast<Key(*)(uint8_t, KeyAddr)>(Layer_::getKeyFromPROGMEM)); static_cast<Key (*)(uint8_t, KeyAddr)>(Layer_::getKeyFromPROGMEM));
return EventHandlerResult::EVENT_CONSUMED; return EventHandlerResult::EVENT_CONSUMED;
} }
@ -146,7 +146,7 @@ EventHandlerResult EEPROMKeymap::onFocusEvent(const char *command) {
// tell the compiler which overload of getKey // tell the compiler which overload of getKey
// we actually want. // we actually want.
// //
dumpKeymap(max_layers_, static_cast<Key(*)(uint8_t, KeyAddr)>(getKey)); dumpKeymap(max_layers_, static_cast<Key (*)(uint8_t, KeyAddr)>(getKey));
} else { } else {
uint16_t i = 0; uint16_t i = 0;

@ -17,7 +17,7 @@
#pragma once #pragma once
#include <stdint.h> // for uint8_t, uint16_t #include <stdint.h> // for uint8_t, uint16_t
#include "kaleidoscope/KeyAddr.h" // for KeyAddr #include "kaleidoscope/KeyAddr.h" // for KeyAddr
#include "kaleidoscope/event_handler_result.h" // for EventHandlerResult #include "kaleidoscope/event_handler_result.h" // for EventHandlerResult
@ -57,7 +57,7 @@ class EEPROMKeymap : public kaleidoscope::Plugin {
static Key parseKey(void); static Key parseKey(void);
static void printKey(Key key); static void printKey(Key key);
static void dumpKeymap(uint8_t layers, Key(*getkey)(uint8_t, KeyAddr)); static void dumpKeymap(uint8_t layers, Key (*getkey)(uint8_t, KeyAddr));
}; };
} // namespace plugin } // namespace plugin

@ -17,9 +17,9 @@
#include "kaleidoscope/plugin/EEPROM-Settings.h" #include "kaleidoscope/plugin/EEPROM-Settings.h"
#include <Arduino.h> // for PSTR, strcmp_P, F #include <Arduino.h> // for PSTR, strcmp_P, F
#include <Kaleidoscope-FocusSerial.h> // for Focus, FocusSerial #include <Kaleidoscope-FocusSerial.h> // for Focus, FocusSerial
#include <stdint.h> // for uint16_t, uint8_t #include <stdint.h> // for uint16_t, uint8_t
#include "kaleidoscope/Runtime.h" // for Runtime, Runtime_ #include "kaleidoscope/Runtime.h" // for Runtime, Runtime_
#include "kaleidoscope/device/device.h" // for VirtualProps::S... #include "kaleidoscope/device/device.h" // for VirtualProps::S...
@ -47,7 +47,7 @@ EventHandlerResult EEPROMSettings::onSetup() {
uninitialized state, we do not override them, to avoid overwriting user uninitialized state, we do not override them, to avoid overwriting user
settings. */ settings. */
settings_.ignore_hardcoded_layers = false; settings_.ignore_hardcoded_layers = false;
settings_.default_layer = 0; settings_.default_layer = 0;
} }
/* If the version is undefined, we'll set it to our current one. */ /* If the version is undefined, we'll set it to our current one. */

@ -17,7 +17,7 @@
#pragma once #pragma once
#include <stdint.h> // for uint8_t, uint16_t #include <stdint.h> // for uint8_t, uint16_t
#include "kaleidoscope/event_handler_result.h" // for EventHandlerResult #include "kaleidoscope/event_handler_result.h" // for EventHandlerResult
#include "kaleidoscope/plugin.h" // for Plugin #include "kaleidoscope/plugin.h" // for Plugin
@ -74,8 +74,8 @@ class EEPROMSettings : public kaleidoscope::Plugin {
static bool sealed_; static bool sealed_;
static struct settings { static struct settings {
uint8_t default_layer: 7; uint8_t default_layer : 7;
bool ignore_hardcoded_layers: 1; bool ignore_hardcoded_layers : 1;
uint8_t version; uint8_t version;
uint16_t crc; uint16_t crc;
} settings_; } settings_;

@ -28,8 +28,7 @@
#include "crc.h" #include "crc.h"
void void CRC_::reflect(uint8_t len) {
CRC_::reflect(uint8_t len) {
uint8_t i; uint8_t i;
uint16_t newCRC; uint16_t newCRC;
@ -42,8 +41,7 @@ CRC_::reflect(uint8_t len) {
crc = newCRC; crc = newCRC;
} }
void void CRC_::update(const void *data, uint8_t len) {
CRC_::update(const void *data, uint8_t len) {
const uint8_t *d = (const uint8_t *)data; const uint8_t *d = (const uint8_t *)data;
uint8_t i; uint8_t i;
bool bit; bool bit;

@ -34,7 +34,7 @@ class CRC_ {
public: public:
uint16_t crc = 0; uint16_t crc = 0;
CRC_(void) {}; CRC_(void){};
void update(const void *data, uint8_t len); void update(const void *data, uint8_t len);
void finalize(void) { void finalize(void) {

@ -17,10 +17,10 @@
#include "kaleidoscope/plugin/Escape-OneShot.h" // IWYU pragma: associated #include "kaleidoscope/plugin/Escape-OneShot.h" // IWYU pragma: associated
#include <Arduino.h> // for PSTR, F, __FlashStrin... #include <Arduino.h> // for PSTR, F, __FlashStrin...
#include <Kaleidoscope-EEPROM-Settings.h> // for EEPROMSettings #include <Kaleidoscope-EEPROM-Settings.h> // for EEPROMSettings
#include <Kaleidoscope-FocusSerial.h> // for Focus, FocusSerial #include <Kaleidoscope-FocusSerial.h> // for Focus, FocusSerial
#include <stdint.h> // for uint16_t #include <stdint.h> // for uint16_t
#include "kaleidoscope/Runtime.h" // for Runtime, Runtime_ #include "kaleidoscope/Runtime.h" // for Runtime, Runtime_
#include "kaleidoscope/device/device.h" // for VirtualProps::Storage #include "kaleidoscope/device/device.h" // for VirtualProps::Storage
@ -71,7 +71,7 @@ EventHandlerResult EscapeOneShotConfig::onFocusEvent(const char *command) {
return EventHandlerResult::EVENT_CONSUMED; return EventHandlerResult::EVENT_CONSUMED;
} }
} // namespace plugin } // namespace plugin
} // namespace kaleidoscope } // namespace kaleidoscope
kaleidoscope::plugin::EscapeOneShotConfig EscapeOneShotConfig; kaleidoscope::plugin::EscapeOneShotConfig EscapeOneShotConfig;

@ -17,7 +17,7 @@
#include "kaleidoscope/plugin/Escape-OneShot.h" #include "kaleidoscope/plugin/Escape-OneShot.h"
#include <Kaleidoscope-OneShot.h> // for OneShot #include <Kaleidoscope-OneShot.h> // for OneShot
#include "kaleidoscope/KeyEvent.h" // for KeyEvent #include "kaleidoscope/KeyEvent.h" // for KeyEvent
#include "kaleidoscope/event_handler_result.h" // for EventHandlerResult #include "kaleidoscope/event_handler_result.h" // for EventHandlerResult
@ -28,8 +28,7 @@ namespace kaleidoscope {
namespace plugin { namespace plugin {
EscapeOneShot::Settings EscapeOneShot::settings_ = { EscapeOneShot::Settings EscapeOneShot::settings_ = {
.cancel_oneshot_key = Key_Escape .cancel_oneshot_key = Key_Escape};
};
EventHandlerResult EscapeOneShot::onKeyEvent(KeyEvent &event) { EventHandlerResult EscapeOneShot::onKeyEvent(KeyEvent &event) {
// We only act on an escape key (or `cancel_oneshot_key_`, if that has been // We only act on an escape key (or `cancel_oneshot_key_`, if that has been

@ -17,8 +17,8 @@
#pragma once #pragma once
#include <Kaleidoscope-Ranges.h> // for OS_CANCEL #include <Kaleidoscope-Ranges.h> // for OS_CANCEL
#include <stdint.h> // for uint16_t #include <stdint.h> // for uint16_t
#include "kaleidoscope/KeyEvent.h" // for KeyEvent #include "kaleidoscope/KeyEvent.h" // for KeyEvent
#include "kaleidoscope/event_handler_result.h" // for EventHandlerResult #include "kaleidoscope/event_handler_result.h" // for EventHandlerResult
@ -27,8 +27,8 @@
// DEPRECATED: `OneShotCancelKey` doesn't match our normal naming, and should // DEPRECATED: `OneShotCancelKey` doesn't match our normal naming, and should
// eventually be removed. // eventually be removed.
constexpr Key OneShotCancelKey {kaleidoscope::ranges::OS_CANCEL}; constexpr Key OneShotCancelKey{kaleidoscope::ranges::OS_CANCEL};
constexpr Key Key_OneShotCancel {kaleidoscope::ranges::OS_CANCEL}; constexpr Key Key_OneShotCancel{kaleidoscope::ranges::OS_CANCEL};
namespace kaleidoscope { namespace kaleidoscope {
namespace plugin { namespace plugin {

@ -17,11 +17,11 @@
#include "kaleidoscope/plugin/FingerPainter.h" #include "kaleidoscope/plugin/FingerPainter.h"
#include <Arduino.h> // for PSTR, strcmp_P, F #include <Arduino.h> // for PSTR, strcmp_P, F
#include <Kaleidoscope-FocusSerial.h> // for Focus, FocusSerial #include <Kaleidoscope-FocusSerial.h> // for Focus, FocusSerial
#include <Kaleidoscope-LED-Palette-Theme.h> // for LEDPaletteTheme #include <Kaleidoscope-LED-Palette-Theme.h> // for LEDPaletteTheme
#include <stdint.h> // for uint16_t, uint8_t #include <stdint.h> // for uint16_t, uint8_t
#include <string.h> // for memcmp #include <string.h> // for memcmp
#include "kaleidoscope/KeyAddr.h" // for KeyAddr #include "kaleidoscope/KeyAddr.h" // for KeyAddr
#include "kaleidoscope/KeyEvent.h" // for KeyEvent #include "kaleidoscope/KeyEvent.h" // for KeyEvent
@ -71,8 +71,8 @@ EventHandlerResult FingerPainter::onKeyEvent(KeyEvent &event) {
// TODO(anyone): The following works only for keyboards with LEDs for each key. // TODO(anyone): The following works only for keyboards with LEDs for each key.
uint8_t color_index = ::LEDPaletteTheme uint8_t color_index = ::LEDPaletteTheme
.lookupColorIndexAtPosition(color_base_, .lookupColorIndexAtPosition(color_base_,
Runtime.device().getLedIndex(event.addr)); Runtime.device().getLedIndex(event.addr));
// Find the next color in the palette that is different. // Find the next color in the palette that is different.
// But do not loop forever! // But do not loop forever!

@ -17,7 +17,7 @@
#pragma once #pragma once
#include <stdint.h> // for uint16_t #include <stdint.h> // for uint16_t
#include "kaleidoscope/KeyAddr.h" // for KeyAddr #include "kaleidoscope/KeyAddr.h" // for KeyAddr
#include "kaleidoscope/KeyEvent.h" // for KeyEvent #include "kaleidoscope/KeyEvent.h" // for KeyEvent

@ -23,7 +23,7 @@
#ifdef __AVR__ #ifdef __AVR__
#include <stdint.h> // for uint16_t #include <stdint.h> // for uint16_t
#include "kaleidoscope/event_handler_result.h" // for EventHandlerResult #include "kaleidoscope/event_handler_result.h" // for EventHandlerResult
#include "kaleidoscope/plugin.h" // for Plugin #include "kaleidoscope/plugin.h" // for Plugin
@ -37,6 +37,7 @@ class FirmwareDump : public kaleidoscope::Plugin {
EventHandlerResult onSetup(); EventHandlerResult onSetup();
EventHandlerResult onFocusEvent(const char *command); EventHandlerResult onFocusEvent(const char *command);
private: private:
uint16_t bootloader_size_; uint16_t bootloader_size_;
}; };

@ -17,10 +17,10 @@
#include "kaleidoscope/plugin/FocusSerial.h" #include "kaleidoscope/plugin/FocusSerial.h"
#include <Arduino.h> // for __FlashStringHelper, F #include <Arduino.h> // for __FlashStringHelper, F
#include <HardwareSerial.h> // for HardwareSerial #include <HardwareSerial.h> // for HardwareSerial
#include <stdint.h> // for uint8_t #include <stdint.h> // for uint8_t
#include <string.h> // for memset #include <string.h> // for memset
#include "kaleidoscope/Runtime.h" // for Runtime, Runtime_ #include "kaleidoscope/Runtime.h" // for Runtime, Runtime_
#include "kaleidoscope/event_handler_result.h" // for EventHandlerResult #include "kaleidoscope/event_handler_result.h" // for EventHandlerResult
@ -44,10 +44,7 @@ EventHandlerResult FocusSerial::afterEachCycle() {
do { do {
command_[buf_cursor_++] = Runtime.serialPort().read(); command_[buf_cursor_++] = Runtime.serialPort().read();
} while (command_[buf_cursor_ - 1] != SEPARATOR } while (command_[buf_cursor_ - 1] != SEPARATOR && buf_cursor_ < sizeof(command_) && Runtime.serialPort().available() && (Runtime.serialPort().peek() != NEWLINE));
&& buf_cursor_ < sizeof(command_)
&& Runtime.serialPort().available()
&& (Runtime.serialPort().peek() != NEWLINE));
// If there was no command, there's nothing to do // If there was no command, there's nothing to do
@ -57,9 +54,7 @@ EventHandlerResult FocusSerial::afterEachCycle() {
return EventHandlerResult::OK; return EventHandlerResult::OK;
} }
if ((command_[buf_cursor_ - 1] != SEPARATOR) && (Runtime.serialPort().peek() != NEWLINE) if ((command_[buf_cursor_ - 1] != SEPARATOR) && (Runtime.serialPort().peek() != NEWLINE) && buf_cursor_ < sizeof(command_)) {
&& buf_cursor_ < sizeof(command_)
) {
// We don't have enough command to work with yet. // We don't have enough command to work with yet.
// Let's leave the buffer around for another cycle // Let's leave the buffer around for another cycle
return EventHandlerResult::OK; return EventHandlerResult::OK;
@ -74,7 +69,7 @@ EventHandlerResult FocusSerial::afterEachCycle() {
// Then process the command // Then process the command
Runtime.onFocusEvent(command_); Runtime.onFocusEvent(command_);
while (Runtime.serialPort().available()) { while (Runtime.serialPort().available()) {
char c = Runtime.serialPort().read(); char c = Runtime.serialPort().read();
if (c == NEWLINE) { if (c == NEWLINE) {
// newline serves as an end-of-command marker // newline serves as an end-of-command marker
// don't drain the buffer past there // don't drain the buffer past there
@ -86,7 +81,6 @@ EventHandlerResult FocusSerial::afterEachCycle() {
buf_cursor_ = 0; buf_cursor_ = 0;
memset(command_, 0, sizeof(command_)); memset(command_, 0, sizeof(command_));
return EventHandlerResult::OK; return EventHandlerResult::OK;
} }
bool FocusSerial::handleHelp(const char *command, bool FocusSerial::handleHelp(const char *command,

@ -17,9 +17,9 @@
#pragma once #pragma once
#include <Arduino.h> // for __FlashStringHelper #include <Arduino.h> // for __FlashStringHelper
#include <HardwareSerial.h> // for HardwareSerial #include <HardwareSerial.h> // for HardwareSerial
#include <stdint.h> // for uint8_t, uint16_t #include <stdint.h> // for uint8_t, uint16_t
#include "kaleidoscope/Runtime.h" // for Runtime, Runtime_ #include "kaleidoscope/Runtime.h" // for Runtime, Runtime_
#include "kaleidoscope/device/device.h" // for cRGB #include "kaleidoscope/device/device.h" // for cRGB
@ -33,9 +33,9 @@ class FocusSerial : public kaleidoscope::Plugin {
public: public:
FocusSerial(void) {} FocusSerial(void) {}
static constexpr char COMMENT = '#'; static constexpr char COMMENT = '#';
static constexpr char SEPARATOR = ' '; static constexpr char SEPARATOR = ' ';
static constexpr char NEWLINE = '\n'; static constexpr char NEWLINE = '\n';
bool handleHelp(const char *command, bool handleHelp(const char *command,
const char *help_message); const char *help_message);
@ -57,19 +57,19 @@ class FocusSerial : public kaleidoscope::Plugin {
printBool(b); printBool(b);
Runtime.serialPort().print(SEPARATOR); Runtime.serialPort().print(SEPARATOR);
} }
template <typename V> template<typename V>
void send(V v) { void send(V v) {
Runtime.serialPort().print(v); Runtime.serialPort().print(v);
Runtime.serialPort().print(SEPARATOR); Runtime.serialPort().print(SEPARATOR);
} }
template <typename Var, typename... Vars> template<typename Var, typename... Vars>
void send(Var v, Vars... vars) { void send(Var v, Vars... vars) {
send(v); send(v);
send(vars...); send(vars...);
} }
void sendRaw() {} void sendRaw() {}
template <typename Var, typename... Vars> template<typename Var, typename... Vars>
void sendRaw(Var v, Vars... vars) { void sendRaw(Var v, Vars... vars) {
Runtime.serialPort().print(v); Runtime.serialPort().print(v);
sendRaw(vars...); sendRaw(vars...);

@ -17,7 +17,7 @@
#include "kaleidoscope/plugin/GhostInTheFirmware.h" #include "kaleidoscope/plugin/GhostInTheFirmware.h"
#include <stdint.h> // for uint16_t #include <stdint.h> // for uint16_t
#include "kaleidoscope/KeyAddr.h" // for KeyAddr #include "kaleidoscope/KeyAddr.h" // for KeyAddr
#include "kaleidoscope/KeyEvent.h" // for KeyEvent #include "kaleidoscope/KeyEvent.h" // for KeyEvent
@ -29,7 +29,7 @@
namespace kaleidoscope { namespace kaleidoscope {
namespace plugin { namespace plugin {
const GhostInTheFirmware::GhostKey *GhostInTheFirmware::ghost_keys; const GhostInTheFirmware::GhostKey *GhostInTheFirmware::ghost_keys;
bool GhostInTheFirmware::is_active_ = false; bool GhostInTheFirmware::is_active_ = false;
uint16_t GhostInTheFirmware::current_pos_ = 0; uint16_t GhostInTheFirmware::current_pos_ = 0;
uint16_t GhostInTheFirmware::start_time_; uint16_t GhostInTheFirmware::start_time_;
@ -53,9 +53,9 @@ EventHandlerResult GhostInTheFirmware::afterEachCycle() {
// value (i.e. KeyAddr::none()). If we read this sentinel value, reset and // value (i.e. KeyAddr::none()). If we read this sentinel value, reset and
// deactivate. // deactivate.
if (!ghost_key.addr.isValid()) { if (!ghost_key.addr.isValid()) {
current_pos_ = 0; current_pos_ = 0;
ghost_key.delay = 0; ghost_key.delay = 0;
is_active_ = false; is_active_ = false;
return EventHandlerResult::OK; return EventHandlerResult::OK;
} }
// If we're not at the end of the sequence, send the first keypress event, // If we're not at the end of the sequence, send the first keypress event,

@ -17,7 +17,7 @@
#pragma once #pragma once
#include <stdint.h> // for uint16_t #include <stdint.h> // for uint16_t
#include "kaleidoscope/KeyAddr.h" // for KeyAddr #include "kaleidoscope/KeyAddr.h" // for KeyAddr
#include "kaleidoscope/event_handler_result.h" // for EventHandlerResult #include "kaleidoscope/event_handler_result.h" // for EventHandlerResult

@ -28,13 +28,13 @@
#include "kaleidoscope/driver/keyscanner/Base_Impl.h" #include "kaleidoscope/driver/keyscanner/Base_Impl.h"
#include "kaleidoscope/util/crc16.h" #include "kaleidoscope/util/crc16.h"
#define I2C_CLOCK_KHZ 100 #define I2C_CLOCK_KHZ 100
#define I2C_FLASH_CLOCK_KHZ 100 // flashing doesn't work reliably at higher clock speeds #define I2C_FLASH_CLOCK_KHZ 100 // flashing doesn't work reliably at higher clock speeds
#define SIDE_POWER 1 // side power switch pa10 #define SIDE_POWER 1 // side power switch pa10
#define LAYOUT_ISO 0 #define LAYOUT_ISO 0
#define LAYOUT_ANSI 1 #define LAYOUT_ANSI 1
namespace kaleidoscope { namespace kaleidoscope {
namespace device { namespace device {
@ -148,7 +148,7 @@ void RaiseLEDDriver::setBrightness(uint8_t brightness) {
RaiseHands::leftHand.setBrightness(brightness); RaiseHands::leftHand.setBrightness(brightness);
RaiseHands::rightHand.setBrightness(brightness); RaiseHands::rightHand.setBrightness(brightness);
for (uint8_t i = 0; i < LED_BANKS; i++) { for (uint8_t i = 0; i < LED_BANKS; i++) {
isLEDChangedLeft[i] = true; isLEDChangedLeft[i] = true;
isLEDChangedRight[i] = true; isLEDChangedRight[i] = true;
} }
} }
@ -159,7 +159,7 @@ uint8_t RaiseLEDDriver::getBrightness() {
void RaiseLEDDriver::syncLeds() { void RaiseLEDDriver::syncLeds() {
// left and right sides // left and right sides
for (uint8_t i = 0; i < LED_BANKS; i ++) { for (uint8_t i = 0; i < LED_BANKS; i++) {
// only send the banks that have changed - try to improve jitter performance // only send the banks that have changed - try to improve jitter performance
if (isLEDChangedLeft[i]) { if (isLEDChangedLeft[i]) {
RaiseHands::leftHand.sendLEDBank(i); RaiseHands::leftHand.sendLEDBank(i);
@ -180,7 +180,7 @@ void RaiseLEDDriver::syncLeds() {
void RaiseLEDDriver::updateNeuronLED() { void RaiseLEDDriver::updateNeuronLED() {
static constexpr struct { static constexpr struct {
uint8_t r, g, b; uint8_t r, g, b;
} pins = { 3, 5, 4 }; } pins = {3, 5, 4};
auto constexpr gamma8 = kaleidoscope::driver::color::gamma_correction; auto constexpr gamma8 = kaleidoscope::driver::color::gamma_correction;
// invert as these are common anode, and make sure we reach 65535 to be able // invert as these are common anode, and make sure we reach 65535 to be able
@ -207,13 +207,13 @@ void RaiseLEDDriver::setCrgbAt(uint8_t i, cRGB crgb) {
// get the SLED index // get the SLED index
uint8_t sled_num = led_map[RaiseHands::layout][i]; uint8_t sled_num = led_map[RaiseHands::layout][i];
if (sled_num < LEDS_PER_HAND) { if (sled_num < LEDS_PER_HAND) {
cRGB oldColor = RaiseHands::leftHand.led_data.leds[sled_num]; cRGB oldColor = RaiseHands::leftHand.led_data.leds[sled_num];
RaiseHands::leftHand.led_data.leds[sled_num] = crgb; RaiseHands::leftHand.led_data.leds[sled_num] = crgb;
isLEDChangedLeft[uint8_t(sled_num / 8)] |= !(oldColor.r == crgb.r && isLEDChangedLeft[uint8_t(sled_num / 8)] |= !(oldColor.r == crgb.r &&
oldColor.g == crgb.g && oldColor.g == crgb.g &&
oldColor.b == crgb.b); oldColor.b == crgb.b);
} else if (sled_num < 2 * LEDS_PER_HAND) { } else if (sled_num < 2 * LEDS_PER_HAND) {
cRGB oldColor = RaiseHands::rightHand.led_data.leds[sled_num - LEDS_PER_HAND]; cRGB oldColor = RaiseHands::rightHand.led_data.leds[sled_num - LEDS_PER_HAND];
RaiseHands::rightHand.led_data.leds[sled_num - LEDS_PER_HAND] = crgb; RaiseHands::rightHand.led_data.leds[sled_num - LEDS_PER_HAND] = crgb;
isLEDChangedRight[uint8_t((sled_num - LEDS_PER_HAND) / 8)] |= isLEDChangedRight[uint8_t((sled_num - LEDS_PER_HAND) / 8)] |=
!(oldColor.r == crgb.r && !(oldColor.r == crgb.r &&
@ -253,7 +253,7 @@ void RaiseLEDDriver::setup() {
delay(10); delay(10);
RaiseHands::setSidePower(true); RaiseHands::setSidePower(true);
delay(500); // wait for sides to power up and finish bootloader delay(500); // wait for sides to power up and finish bootloader
} }
/********* Key scanner *********/ /********* Key scanner *********/
@ -266,7 +266,7 @@ bool RaiseKeyScanner::lastLeftOnline;
bool RaiseKeyScanner::lastRightOnline; bool RaiseKeyScanner::lastRightOnline;
void RaiseKeyScanner::readMatrix() { void RaiseKeyScanner::readMatrix() {
previousLeftHandState = leftHandState; previousLeftHandState = leftHandState;
previousRightHandState = rightHandState; previousRightHandState = rightHandState;
if (RaiseHands::leftHand.readKeys()) { if (RaiseHands::leftHand.readKeys()) {
@ -275,8 +275,8 @@ void RaiseKeyScanner::readMatrix() {
if (RaiseHands::layout == LAYOUT_ANSI) { if (RaiseHands::layout == LAYOUT_ANSI) {
// only swap if bits are different // only swap if bits are different
if ((leftHandState.rows[3] & (1 << 0)) ^ leftHandState.rows[3] & (1 << 1)) { if ((leftHandState.rows[3] & (1 << 0)) ^ leftHandState.rows[3] & (1 << 1)) {
leftHandState.rows[3] ^= (1 << 0); // flip the bit leftHandState.rows[3] ^= (1 << 0); // flip the bit
leftHandState.rows[3] ^= (1 << 1); // flip the bit leftHandState.rows[3] ^= (1 << 1); // flip the bit
} }
} }
} }
@ -305,7 +305,7 @@ void RaiseKeyScanner::readMatrix() {
rightHandState.all = 0; rightHandState.all = 0;
// store previous state of whether the sides are plugged in // store previous state of whether the sides are plugged in
lastLeftOnline = RaiseHands::leftHand.online; lastLeftOnline = RaiseHands::leftHand.online;
lastRightOnline = RaiseHands::rightHand.online; lastRightOnline = RaiseHands::rightHand.online;
} }
@ -371,9 +371,11 @@ void RaiseKeyScanner::setKeyscanInterval(uint8_t interval) {
} }
void RaiseKeyScanner::setup() { void RaiseKeyScanner::setup() {
// clang-format off
static constexpr uint8_t keyscanner_pins[] = { static constexpr uint8_t keyscanner_pins[] = {
2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
}; 21, 22, 23, 24, 25, 26, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42,
}; // clang-format on
for (int i = 0; i < sizeof(keyscanner_pins); i++) { for (int i = 0; i < sizeof(keyscanner_pins); i++) {
pinMode(keyscanner_pins[i], OUTPUT); pinMode(keyscanner_pins[i], OUTPUT);
digitalWrite(keyscanner_pins[i], LOW); digitalWrite(keyscanner_pins[i], LOW);
@ -381,7 +383,7 @@ void RaiseKeyScanner::setup() {
} }
void RaiseKeyScanner::reset() { void RaiseKeyScanner::reset() {
leftHandState.all = 0; leftHandState.all = 0;
rightHandState.all = 0; rightHandState.all = 0;
Runtime.hid().keyboard().releaseAllKeys(); Runtime.hid().keyboard().releaseAllKeys();
Runtime.hid().keyboard().sendReport(); Runtime.hid().keyboard().sendReport();

@ -23,7 +23,8 @@
#include "kaleidoscope/device/dygma/raise/RaiseSide.h" #include "kaleidoscope/device/dygma/raise/RaiseSide.h"
#define CRGB(r,g,b) (cRGB){b, g, r} #define CRGB(r, g, b) \
(cRGB) { b, g, r }
#include "kaleidoscope/device/Base.h" #include "kaleidoscope/device/Base.h"
#include "kaleidoscope/driver/bootloader/samd/Bossac.h" #include "kaleidoscope/driver/bootloader/samd/Bossac.h"
@ -44,6 +45,7 @@ using kaleidoscope::driver::led::no_led;
struct RaiseLEDDriverProps : public kaleidoscope::driver::led::BaseProps { struct RaiseLEDDriverProps : public kaleidoscope::driver::led::BaseProps {
static constexpr uint8_t led_count = 132; static constexpr uint8_t led_count = 132;
// clang-format off
static constexpr uint8_t key_led_map[] = { static constexpr uint8_t key_led_map[] = {
// ISO & ANSI (ANSI has no LED at 20, but this key can never be pressed so we can have just one map). // ISO & ANSI (ANSI has no LED at 20, but this key can never be pressed so we can have just one map).
0, 1, 2, 3, 4, 5, 6, no_led, no_led, 6 + LHK, 5 + LHK, 4 + LHK, 3 + LHK, 2 + LHK, 1 + LHK, 0 + LHK, 0, 1, 2, 3, 4, 5, 6, no_led, no_led, 6 + LHK, 5 + LHK, 4 + LHK, 3 + LHK, 2 + LHK, 1 + LHK, 0 + LHK,
@ -51,7 +53,7 @@ struct RaiseLEDDriverProps : public kaleidoscope::driver::led::BaseProps {
13, 14, 15, 16, 17, 18, no_led, no_led, no_led, 21 + LHK, 20 + LHK, 19 + LHK, 18 + LHK, 17 + LHK, 16 + LHK, 15 + LHK, 13, 14, 15, 16, 17, 18, no_led, no_led, no_led, 21 + LHK, 20 + LHK, 19 + LHK, 18 + LHK, 17 + LHK, 16 + LHK, 15 + LHK,
19, 20, 21, 22, 23, 24, 25, no_led, no_led, no_led, 27 + LHK, 26 + LHK, 25 + LHK, 24 + LHK, 23 + LHK, 22 + LHK, 19, 20, 21, 22, 23, 24, 25, no_led, no_led, no_led, 27 + LHK, 26 + LHK, 25 + LHK, 24 + LHK, 23 + LHK, 22 + LHK,
26, 27, 28, 29, 30, no_led, 31, 32, 35 + LHK, 34 + LHK, 33 + LHK, 32 + LHK, 31 + LHK, 30 + LHK, 29 + LHK, 28 + LHK 26, 27, 28, 29, 30, no_led, 31, 32, 35 + LHK, 34 + LHK, 33 + LHK, 32 + LHK, 31 + LHK, 30 + LHK, 29 + LHK, 28 + LHK
}; }; // clang-format on
}; };
#undef LHK #undef LHK
@ -66,6 +68,7 @@ class RaiseLEDDriver : public kaleidoscope::driver::led::Base<RaiseLEDDriverProp
static uint8_t getBrightness(); static uint8_t getBrightness();
static void updateNeuronLED(); static void updateNeuronLED();
private: private:
static bool isLEDChangedNeuron; static bool isLEDChangedNeuron;
static uint8_t isLEDChangedLeft[LED_BANKS]; static uint8_t isLEDChangedLeft[LED_BANKS];
@ -76,6 +79,7 @@ class RaiseLEDDriver : public kaleidoscope::driver::led::Base<RaiseLEDDriverProp
// led_count + 1, to account for the Neuron's LED. The last one is the // led_count + 1, to account for the Neuron's LED. The last one is the
// Neuron's LED, never send that to SLED. // Neuron's LED, never send that to SLED.
static constexpr uint8_t led_map[][RaiseLEDDriverProps::led_count + 1] = { static constexpr uint8_t led_map[][RaiseLEDDriverProps::led_count + 1] = {
// clang-format off
// ISO // ISO
{ {
// left side - 33 keys includes LP // left side - 33 keys includes LP
@ -108,15 +112,15 @@ class RaiseLEDDriver : public kaleidoscope::driver::led::Base<RaiseLEDDriverProp
34 + LPH, 35 + LPH, 36 + LPH, 37 + LPH, 38 + LPH, 39 + LPH, 40 + LPH, 41 + LPH, 42 + LPH, 43 + LPH, 44 + LPH, 45 + LPH, 46 + LPH, 47 + LPH, 48 + LPH, 49 + LPH, 50 + LPH, 51 + LPH, 34 + LPH, 35 + LPH, 36 + LPH, 37 + LPH, 38 + LPH, 39 + LPH, 40 + LPH, 41 + LPH, 42 + LPH, 43 + LPH, 44 + LPH, 45 + LPH, 46 + LPH, 47 + LPH, 48 + LPH, 49 + LPH, 50 + LPH, 51 + LPH,
52 + LPH, 53 + LPH, 54 + LPH, 55 + LPH, 56 + LPH, 57 + LPH, 58 + LPH, 59 + LPH, 60 + LPH, 61 + LPH, 62 + LPH, 63 + LPH, 64 + LPH, 65 + LPH, 0xff 52 + LPH, 53 + LPH, 54 + LPH, 55 + LPH, 56 + LPH, 57 + LPH, 58 + LPH, 59 + LPH, 60 + LPH, 61 + LPH, 62 + LPH, 63 + LPH, 64 + LPH, 65 + LPH, 0xff
} }
}; }; // clang-format on
}; };
struct RaiseKeyScannerProps : public kaleidoscope::driver::keyscanner::BaseProps { struct RaiseKeyScannerProps : public kaleidoscope::driver::keyscanner::BaseProps {
static constexpr uint8_t matrix_rows = 5; static constexpr uint8_t matrix_rows = 5;
static constexpr uint8_t matrix_columns = 16; static constexpr uint8_t matrix_columns = 16;
typedef MatrixAddr<matrix_rows, matrix_columns> KeyAddr; typedef MatrixAddr<matrix_rows, matrix_columns> KeyAddr;
static constexpr uint8_t left_columns = 8; static constexpr uint8_t left_columns = 8;
static constexpr uint8_t right_columns = matrix_columns - left_columns; static constexpr uint8_t right_columns = matrix_columns - left_columns;
}; };
@ -124,6 +128,7 @@ class RaiseKeyScanner : public kaleidoscope::driver::keyscanner::Base<RaiseKeySc
private: private:
typedef RaiseKeyScanner ThisType; typedef RaiseKeyScanner ThisType;
typedef RaiseKeyScannerProps Props_; typedef RaiseKeyScannerProps Props_;
public: public:
static void setup(); static void setup();
static void scanMatrix(); static void scanMatrix();
@ -159,7 +164,7 @@ struct RaiseSideFlasherProps : public kaleidoscope::util::flasher::BaseProps {};
struct RaiseProps : kaleidoscope::device::BaseProps { struct RaiseProps : kaleidoscope::device::BaseProps {
typedef kaleidoscope::driver::hid::KeyboardioProps HIDProps; typedef kaleidoscope::driver::hid::KeyboardioProps HIDProps;
typedef kaleidoscope::driver::hid::Keyboardio<HIDProps> HID; typedef kaleidoscope::driver::hid::Keyboardio<HIDProps> HID;
typedef RaiseLEDDriverProps LEDDriverProps; typedef RaiseLEDDriverProps LEDDriverProps;
typedef RaiseLEDDriver LEDDriver; typedef RaiseLEDDriver LEDDriver;
typedef RaiseKeyScannerProps KeyScannerProps; typedef RaiseKeyScannerProps KeyScannerProps;
typedef RaiseKeyScanner KeyScanner; typedef RaiseKeyScanner KeyScanner;
@ -172,9 +177,10 @@ struct RaiseProps : kaleidoscope::device::BaseProps {
static constexpr const char *short_name = "raise"; static constexpr const char *short_name = "raise";
}; };
class Raise: public kaleidoscope::device::Base<RaiseProps> { class Raise : public kaleidoscope::device::Base<RaiseProps> {
private: private:
static RaiseProps::SideFlasher SideFlasher; static RaiseProps::SideFlasher SideFlasher;
public: public:
static void setup(); static void setup();
@ -206,7 +212,7 @@ class Raise: public kaleidoscope::device::Base<RaiseProps> {
void prepareForFlash(); void prepareForFlash();
// Side bootloader addresses // Side bootloader addresses
static constexpr uint8_t left_boot_address = 0x50; static constexpr uint8_t left_boot_address = 0x50;
static constexpr uint8_t right_boot_address = 0x51; static constexpr uint8_t right_boot_address = 0x51;
} side; } side;
@ -230,6 +236,8 @@ typedef kaleidoscope::device::dygma::Raise Device;
} // namespace kaleidoscope } // namespace kaleidoscope
// clang-format off
#define PER_KEY_DATA(dflt, \ #define PER_KEY_DATA(dflt, \
r0c0, r0c1, r0c2, r0c3, r0c4, r0c5, r0c6, r0c9, r0c10, r0c11, r0c12, r0c13, r0c14, r0c15, \ r0c0, r0c1, r0c2, r0c3, r0c4, r0c5, r0c6, r0c9, r0c10, r0c11, r0c12, r0c13, r0c14, r0c15, \
r1c0, r1c1, r1c2, r1c3, r1c4, r1c5, r1c8, r1c9, r1c10, r1c11, r1c12, r1c13, r1c14, r1c15, \ r1c0, r1c1, r1c2, r1c3, r1c4, r1c5, r1c8, r1c9, r1c10, r1c11, r1c12, r1c13, r1c14, r1c15, \

@ -29,42 +29,42 @@ namespace device {
namespace dygma { namespace dygma {
namespace raise { namespace raise {
#define TWI_CMD_NONE 0x00 #define TWI_CMD_NONE 0x00
#define TWI_CMD_VERSION 0x01 #define TWI_CMD_VERSION 0x01
#define TWI_CMD_KEYSCAN_INTERVAL 0x02 #define TWI_CMD_KEYSCAN_INTERVAL 0x02
#define TWI_CMD_LED_SET_ALL_TO 0x03 #define TWI_CMD_LED_SET_ALL_TO 0x03
#define TWI_CMD_LED_SET_ONE_TO 0x04 #define TWI_CMD_LED_SET_ONE_TO 0x04
#define TWI_CMD_COLS_USE_PULLUPS 0x05 #define TWI_CMD_COLS_USE_PULLUPS 0x05
#define TWI_CMD_LED_SPI_FREQUENCY 0x06 #define TWI_CMD_LED_SPI_FREQUENCY 0x06
#define TWI_CMD_LED_GLOBAL_BRIGHTNESS 0x07 #define TWI_CMD_LED_GLOBAL_BRIGHTNESS 0x07
#define TWI_CMD_SLED_STATUS 0x08 #define TWI_CMD_SLED_STATUS 0x08
#define TWI_CMD_LED_OPEN 0x09 #define TWI_CMD_LED_OPEN 0x09
#define TWI_CMD_LED_SHORT 0x0A #define TWI_CMD_LED_SHORT 0x0A
#define TWI_CMD_JOINED 0x0B #define TWI_CMD_JOINED 0x0B
#define TWI_CMD_LAYOUT 0x0C #define TWI_CMD_LAYOUT 0x0C
#define TWI_CMD_SLED_CURRENT 0x0D #define TWI_CMD_SLED_CURRENT 0x0D
#define TWI_CMD_SLED_SELF_TEST 0x0E #define TWI_CMD_SLED_SELF_TEST 0x0E
#define LED_SPI_FREQUENCY_4MHZ 0x07 #define LED_SPI_FREQUENCY_4MHZ 0x07
#define LED_SPI_FREQUENCY_2MHZ 0x06 #define LED_SPI_FREQUENCY_2MHZ 0x06
#define LED_SPI_FREQUENCY_1MHZ 0x05 #define LED_SPI_FREQUENCY_1MHZ 0x05
#define LED_SPI_FREQUENCY_512KHZ 0x04 #define LED_SPI_FREQUENCY_512KHZ 0x04
#define LED_SPI_FREQUENCY_256KHZ 0x03 #define LED_SPI_FREQUENCY_256KHZ 0x03
#define LED_SPI_FREQUENCY_128KHZ 0x02 #define LED_SPI_FREQUENCY_128KHZ 0x02
#define LED_SPI_FREQUENCY_64KHZ 0x01 #define LED_SPI_FREQUENCY_64KHZ 0x01
#define LED_SPI_OFF 0x00 #define LED_SPI_OFF 0x00
// 512KHZ seems to be the sweet spot in early testing // 512KHZ seems to be the sweet spot in early testing
// so make it the default // so make it the default
#define LED_SPI_FREQUENCY_DEFAULT LED_SPI_FREQUENCY_512KHZ #define LED_SPI_FREQUENCY_DEFAULT LED_SPI_FREQUENCY_512KHZ
#define TWI_CMD_LED_BASE 0x80 #define TWI_CMD_LED_BASE 0x80
#define TWI_REPLY_NONE 0x00 #define TWI_REPLY_NONE 0x00
#define TWI_REPLY_KEYDATA 0x01 #define TWI_REPLY_KEYDATA 0x01
#define ELEMENTS(arr) (sizeof(arr) / sizeof((arr)[0])) #define ELEMENTS(arr) (sizeof(arr) / sizeof((arr)[0]))
// Returns the relative controller addresss. The expected range is 0-3 // Returns the relative controller addresss. The expected range is 0-3
uint8_t RaiseSide::controllerAddress() { uint8_t RaiseSide::controllerAddress() {
@ -221,9 +221,9 @@ void RaiseSide::sendLEDData() {
auto constexpr gamma8 = kaleidoscope::driver::color::gamma_correction; auto constexpr gamma8 = kaleidoscope::driver::color::gamma_correction;
void RaiseSide::sendLEDBank(uint8_t bank) { void RaiseSide::sendLEDBank(uint8_t bank) {
uint8_t data[LED_BYTES_PER_BANK + 1]; // + 1 for the update LED command itself uint8_t data[LED_BYTES_PER_BANK + 1]; // + 1 for the update LED command itself
data[0] = TWI_CMD_LED_BASE + bank; data[0] = TWI_CMD_LED_BASE + bank;
for (uint8_t i = 0 ; i < LED_BYTES_PER_BANK; i++) { for (uint8_t i = 0; i < LED_BYTES_PER_BANK; i++) {
uint8_t c = led_data.bytes[bank][i]; uint8_t c = led_data.bytes[bank][i];
if (c > brightness_adjustment_) if (c > brightness_adjustment_)
c -= brightness_adjustment_; c -= brightness_adjustment_;

@ -35,11 +35,11 @@ namespace device {
namespace dygma { namespace dygma {
namespace raise { namespace raise {
#define LED_BANKS 9 #define LED_BANKS 9
#define LEDS_PER_HAND 72 #define LEDS_PER_HAND 72
#define LPH LEDS_PER_HAND #define LPH LEDS_PER_HAND
#define LEDS_PER_BANK 8 #define LEDS_PER_BANK 8
#define LED_BYTES_PER_BANK (sizeof(cRGB) * LEDS_PER_BANK) #define LED_BYTES_PER_BANK (sizeof(cRGB) * LEDS_PER_BANK)
typedef union { typedef union {
@ -57,7 +57,8 @@ typedef union {
class RaiseSide { class RaiseSide {
public: public:
explicit RaiseSide(uint8_t ad01) : ad01_(ad01), twi_(i2c_addr_base_ | ad01) {} explicit RaiseSide(uint8_t ad01)
: ad01_(ad01), twi_(i2c_addr_base_ | ad01) {}
int readVersion(); int readVersion();
int readSLEDVersion(); int readSLEDVersion();

@ -28,10 +28,11 @@ namespace device {
namespace dygma { namespace dygma {
namespace raise { namespace raise {
template <typename _Firmware> template<typename _Firmware>
class SideFlash : public kaleidoscope::Plugin { class SideFlash : public kaleidoscope::Plugin {
private: private:
_Firmware firmware; _Firmware firmware;
public: public:
EventHandlerResult onFocusEvent(const char *command) { EventHandlerResult onFocusEvent(const char *command) {
if (::Focus.handleHelp(command, PSTR("hardware.flash_left_side\nhardware.flash_right_side\nhardware.verify_left_side\nhardware.verify_right_side"))) if (::Focus.handleHelp(command, PSTR("hardware.flash_left_side\nhardware.flash_right_side\nhardware.verify_left_side\nhardware.verify_right_side")))
@ -40,8 +41,8 @@ class SideFlash : public kaleidoscope::Plugin {
if (strncmp_P(command, PSTR("hardware."), 9) != 0) if (strncmp_P(command, PSTR("hardware."), 9) != 0)
return EventHandlerResult::OK; return EventHandlerResult::OK;
auto sideFlasher = Runtime.device().sideFlasher(); auto sideFlasher = Runtime.device().sideFlasher();
uint8_t left_boot_address = Runtime.device().side.left_boot_address; uint8_t left_boot_address = Runtime.device().side.left_boot_address;
uint8_t right_boot_address = Runtime.device().side.right_boot_address; uint8_t right_boot_address = Runtime.device().side.right_boot_address;
enum { enum {
FLASH, FLASH,
@ -51,16 +52,16 @@ class SideFlash : public kaleidoscope::Plugin {
if (strcmp_P(command + 9, PSTR("flash_left_side")) == 0) { if (strcmp_P(command + 9, PSTR("flash_left_side")) == 0) {
sub_command = FLASH; sub_command = FLASH;
address = left_boot_address; address = left_boot_address;
} else if (strcmp_P(command + 9, PSTR("flash_right_side")) == 0) { } else if (strcmp_P(command + 9, PSTR("flash_right_side")) == 0) {
sub_command = FLASH; sub_command = FLASH;
address = right_boot_address; address = right_boot_address;
} else if (strcmp_P(command + 9, PSTR("verify_left_side")) == 0) { } else if (strcmp_P(command + 9, PSTR("verify_left_side")) == 0) {
sub_command = VERIFY; sub_command = VERIFY;
address = left_boot_address; address = left_boot_address;
} else if (strcmp_P(command + 9, PSTR("verify_right_side")) == 0) { } else if (strcmp_P(command + 9, PSTR("verify_right_side")) == 0) {
sub_command = VERIFY; sub_command = VERIFY;
address = right_boot_address; address = right_boot_address;
} else { } else {
return EventHandlerResult::OK; return EventHandlerResult::OK;
} }

@ -32,7 +32,7 @@ uint8_t TWI::writeTo(uint8_t *data, size_t length) {
Wire.beginTransmission(addr_); Wire.beginTransmission(addr_);
// calc cksum // calc cksum
uint16_t crc16 = 0xffff; uint16_t crc16 = 0xffff;
uint8_t *buffer = data; uint8_t *buffer = data;
for (uint8_t i = 0; i < length; i++) { for (uint8_t i = 0; i < length; i++) {
crc16 = _crc_ccitt_update(crc16, *buffer); crc16 = _crc_ccitt_update(crc16, *buffer);
@ -50,12 +50,12 @@ uint8_t TWI::writeTo(uint8_t *data, size_t length) {
return 0; return 0;
} }
uint8_t TWI::readFrom(uint8_t* data, size_t length) { uint8_t TWI::readFrom(uint8_t *data, size_t length) {
uint8_t counter = 0; uint8_t counter = 0;
uint32_t timeout; uint32_t timeout;
uint8_t *buffer = data; uint8_t *buffer = data;
if (!Wire.requestFrom(addr_, length + 2, true)) { // + 2 for the cksum if (!Wire.requestFrom(addr_, length + 2, true)) { // + 2 for the cksum
// in case slave is not responding - return 0 (0 length of received data). // in case slave is not responding - return 0 (0 length of received data).
return 0; return 0;
} }
@ -65,7 +65,7 @@ uint8_t TWI::readFrom(uint8_t* data, size_t length) {
counter++; counter++;
} }
uint16_t crc16 = 0xffff; uint16_t crc16 = 0xffff;
uint16_t rx_cksum = (Wire.read() << 8) + Wire.read(); uint16_t rx_cksum = (Wire.read() << 8) + Wire.read();
for (uint8_t i = 0; i < length; i++) { for (uint8_t i = 0; i < length; i++) {
crc16 = _crc_ccitt_update(crc16, *buffer); crc16 = _crc_ccitt_update(crc16, *buffer);

@ -29,10 +29,11 @@ namespace raise {
class TWI { class TWI {
public: public:
explicit TWI(int addr) : addr_(addr), crc_errors_(0) {} explicit TWI(int addr)
: addr_(addr), crc_errors_(0) {}
uint8_t writeTo(uint8_t *data, size_t length); uint8_t writeTo(uint8_t *data, size_t length);
uint8_t readFrom(uint8_t* data, size_t length); uint8_t readFrom(uint8_t *data, size_t length);
void disable(); void disable();
void init(uint16_t clock_khz); void init(uint16_t clock_khz);
uint8_t crc_errors() { uint8_t crc_errors() {

@ -53,12 +53,12 @@ void ErgoDox::setup(void) {
TCCR1A = 0b10101001; TCCR1A = 0b10101001;
TCCR1B = 0b00001001; TCCR1B = 0b00001001;
DDRB &= ~(1 << 4); DDRB &= ~(1 << 4);
PORTB &= ~(1 << 4); PORTB &= ~(1 << 4);
DDRC &= ~(1 << 7); DDRC &= ~(1 << 7);
DDRD &= ~(1 << 5 | 1 << 4); DDRD &= ~(1 << 5 | 1 << 4);
DDRE &= ~(1 << 6); DDRE &= ~(1 << 6);
PORTC |= (1 << 7); PORTC |= (1 << 7);
PORTD |= (1 << 5 | 1 << 4); PORTD |= (1 << 5 | 1 << 4);
PORTE |= (1 << 6); PORTE |= (1 << 6);
@ -75,7 +75,7 @@ void ErgoDox::setup(void) {
const uint32_t cycles = (F_CPU / 2000000) * 1700; const uint32_t cycles = (F_CPU / 2000000) * 1700;
ICR1 = cycles; ICR1 = cycles;
TCCR1B = _BV(WGM13) | _BV(CS10); TCCR1B = _BV(WGM13) | _BV(CS10);
TIMSK1 = _BV(TOIE1); TIMSK1 = _BV(TOIE1);
@ -148,9 +148,8 @@ void ErgoDox::setStatusLED(uint8_t led, bool state) {
} }
void ErgoDox::setStatusLEDBrightness(uint8_t led, uint8_t brightness) { void ErgoDox::setStatusLEDBrightness(uint8_t led, uint8_t brightness) {
(led == 1) ? (OCR1A = brightness) : (led == 1) ? (OCR1A = brightness) : (led == 2) ? (OCR1B = brightness)
(led == 2) ? (OCR1B = brightness) : : (OCR1C = brightness);
(OCR1C = brightness);
} }
uint8_t ErgoDox::debounceMaskForRow(uint8_t row) { uint8_t ErgoDox::debounceMaskForRow(uint8_t row) {
@ -215,4 +214,4 @@ uint8_t ErgoDox::pressedKeyswitchCount() {
} // namespace kaleidoscope } // namespace kaleidoscope
#endif #endif
#endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD #endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD

@ -33,14 +33,15 @@ struct cRGB {
uint8_t r, g, b; uint8_t r, g, b;
}; };
#define CRGB(r,g,b) (cRGB){b, g, r} #define CRGB(r, g, b) \
(cRGB) { b, g, r }
#include "kaleidoscope/device/ATmega32U4Keyboard.h" #include "kaleidoscope/device/ATmega32U4Keyboard.h"
#include "kaleidoscope/driver/bootloader/avr/HalfKay.h" #include "kaleidoscope/driver/bootloader/avr/HalfKay.h"
#include "kaleidoscope/driver/keyscanner/Base.h" #include "kaleidoscope/driver/keyscanner/Base.h"
#ifndef KALEIDOSCOPE_VIRTUAL_BUILD #ifndef KALEIDOSCOPE_VIRTUAL_BUILD
#include "kaleidoscope/device/ez/ErgoDox/ErgoDoxScanner.h" #include "kaleidoscope/device/ez/ErgoDox/ErgoDoxScanner.h"
#endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD #endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD
namespace kaleidoscope { namespace kaleidoscope {
namespace device { namespace device {
@ -48,10 +49,9 @@ namespace ez {
struct ErgoDoxProps : public kaleidoscope::device::ATmega32U4KeyboardProps { struct ErgoDoxProps : public kaleidoscope::device::ATmega32U4KeyboardProps {
struct KeyScannerProps : kaleidoscope::driver::keyscanner::BaseProps { struct KeyScannerProps : kaleidoscope::driver::keyscanner::BaseProps {
static constexpr uint8_t matrix_rows = 14; static constexpr uint8_t matrix_rows = 14;
static constexpr uint8_t matrix_columns = 6; static constexpr uint8_t matrix_columns = 6;
typedef MatrixAddr<matrix_rows, matrix_columns> KeyAddr; typedef MatrixAddr<matrix_rows, matrix_columns> KeyAddr;
}; };
typedef kaleidoscope::driver::bootloader::avr::HalfKay Bootloader; typedef kaleidoscope::driver::bootloader::avr::HalfKay Bootloader;
static constexpr const char *short_name = "ErgoDox-EZ"; static constexpr const char *short_name = "ErgoDox-EZ";
@ -92,9 +92,11 @@ class ErgoDox : public kaleidoscope::device::ATmega32U4Keyboard<ErgoDoxProps> {
static void debounceRow(uint8_t change, uint8_t row); static void debounceRow(uint8_t change, uint8_t row);
static void readMatrixRow(uint8_t row); static void readMatrixRow(uint8_t row);
}; };
#else // ifndef KALEIDOSCOPE_VIRTUAL_BUILD #else // ifndef KALEIDOSCOPE_VIRTUAL_BUILD
class ErgoDox; class ErgoDox;
#endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD #endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD
// clang-format off
#define PER_KEY_DATA_STACKED(dflt, \ #define PER_KEY_DATA_STACKED(dflt, \
/* left hand, spatial positions */ \ /* left hand, spatial positions */ \

@ -34,17 +34,17 @@
#include "kaleidoscope/device/avr/pins_and_ports.h" #include "kaleidoscope/device/avr/pins_and_ports.h"
#include "kaleidoscope/device/ez/ErgoDox/i2cmaster.h" #include "kaleidoscope/device/ez/ErgoDox/i2cmaster.h"
#define I2C_ADDR 0b0100000 #define I2C_ADDR 0b0100000
#define I2C_ADDR_WRITE ( (I2C_ADDR<<1) | I2C_WRITE ) #define I2C_ADDR_WRITE ((I2C_ADDR << 1) | I2C_WRITE)
#define I2C_ADDR_READ ( (I2C_ADDR<<1) | I2C_READ ) #define I2C_ADDR_READ ((I2C_ADDR << 1) | I2C_READ)
#define IODIRA 0x00 #define IODIRA 0x00
#define IODIRB 0x01 #define IODIRB 0x01
#define GPPUA 0x0C #define GPPUA 0x0C
#define GPPUB 0x0D #define GPPUB 0x0D
#define GPIOA 0x12 #define GPIOA 0x12
#define GPIOB 0x13 #define GPIOB 0x13
#define OLATA 0x14 #define OLATA 0x14
#define OLATB 0x15 #define OLATB 0x15
namespace kaleidoscope { namespace kaleidoscope {
namespace device { namespace device {
@ -90,20 +90,19 @@ out:
return status; return status;
} }
void void ErgoDoxScanner::begin() {
ErgoDoxScanner::begin() {
expander_error_ = initExpander(); expander_error_ = initExpander();
// Init columns // Init columns
DDRF &= ~(1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 1 | 1 << 0); DDRF &= ~(1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 1 | 1 << 0);
PORTF |= (1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 1 | 1 << 0); PORTF |= (1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 1 | 1 << 0);
// Init rows // Init rows
DDRB |= (1 << 0 | 1 << 1 | 1 << 2 | 1 << 3); DDRB |= (1 << 0 | 1 << 1 | 1 << 2 | 1 << 3);
PORTB |= (1 << 0 | 1 << 1 | 1 << 2 | 1 << 3); PORTB |= (1 << 0 | 1 << 1 | 1 << 2 | 1 << 3);
DDRD |= (1 << 2 | 1 << 3); DDRD |= (1 << 2 | 1 << 3);
PORTD |= (1 << 2 | 1 << 3); PORTD |= (1 << 2 | 1 << 3);
DDRC |= (1 << 6); DDRC |= (1 << 6);
PORTC |= (1 << 6); PORTC |= (1 << 6);
} }
@ -118,13 +117,13 @@ void __attribute__((optimize(3))) ErgoDoxScanner::selectExtenderRow(int row) {
expander_error_ = i2c_write(0xFF & ~(1 << row)); expander_error_ = i2c_write(0xFF & ~(1 << row));
if (expander_error_) if (expander_error_)
goto out; goto out;
out: out:
i2c_stop(); i2c_stop();
} }
} }
void __attribute__((optimize(3))) ErgoDoxScanner::toggleATMegaRow(int row) { void __attribute__((optimize(3))) ErgoDoxScanner::toggleATMegaRow(int row) {
static uint8_t row_pins[] = { PIN_B0, PIN_B1, PIN_B2, PIN_B3, PIN_D2, PIN_D3, PIN_C6 }; static uint8_t row_pins[] = {PIN_B0, PIN_B1, PIN_B2, PIN_B3, PIN_D2, PIN_D3, PIN_C6};
OUTPUT_TOGGLE(row_pins[row]); OUTPUT_TOGGLE(row_pins[row]);
} }
@ -148,7 +147,7 @@ ErgoDoxScanner::readCols(int row) {
data = i2c_readNak(); data = i2c_readNak();
data = ~data; data = ~data;
out: out:
i2c_stop(); i2c_stop();
return data; return data;
} else { } else {
@ -156,8 +155,7 @@ out:
} }
} }
void void ErgoDoxScanner::reattachExpanderOnError() {
ErgoDoxScanner::reattachExpanderOnError() {
static uint32_t start_time = millis(); static uint32_t start_time = millis();
if (!expander_error_) if (!expander_error_)
@ -167,7 +165,7 @@ ErgoDoxScanner::reattachExpanderOnError() {
return; return;
expander_error_ = initExpander(); expander_error_ = initExpander();
start_time = millis(); start_time = millis();
} }
} // namespace ez } // namespace ez
@ -175,4 +173,4 @@ ErgoDoxScanner::reattachExpanderOnError() {
} // namespace kaleidoscope } // namespace kaleidoscope
#endif #endif
#endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD #endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD

@ -21,7 +21,7 @@
#endif #endif
/* I2C clock in Hz */ /* I2C clock in Hz */
#define SCL_CLOCK 400000L #define SCL_CLOCK 400000L
/************************************************************************* /*************************************************************************
@ -36,10 +36,10 @@ void i2c_init(void) {
* for more details, see 20.5.2 in ATmega16/32 secification * for more details, see 20.5.2 in ATmega16/32 secification
*/ */
TWSR = 0; /* no prescaler */ TWSR = 0; /* no prescaler */
TWBR = 10; /* must be >= 10 for stable operation */ TWBR = 10; /* must be >= 10 for stable operation */
}/* i2c_init */ } /* i2c_init */
/************************************************************************* /*************************************************************************
@ -47,13 +47,14 @@ void i2c_init(void) {
return 0 = device accessible, 1= failed to access device return 0 = device accessible, 1= failed to access device
*************************************************************************/ *************************************************************************/
unsigned char i2c_start(unsigned char address) { unsigned char i2c_start(unsigned char address) {
uint8_t twst; uint8_t twst;
// send START condition // send START condition
TWCR = (1 << TWINT) | (1 << TWSTA) | (1 << TWEN); TWCR = (1 << TWINT) | (1 << TWSTA) | (1 << TWEN);
// wait until transmission completed // wait until transmission completed
while (!(TWCR & (1 << TWINT))); while (!(TWCR & (1 << TWINT)))
;
// check value of TWI Status Register. Mask prescaler bits. // check value of TWI Status Register. Mask prescaler bits.
twst = TW_STATUS & 0xF8; twst = TW_STATUS & 0xF8;
@ -64,7 +65,8 @@ unsigned char i2c_start(unsigned char address) {
TWCR = (1 << TWINT) | (1 << TWEN); TWCR = (1 << TWINT) | (1 << TWEN);
// wail until transmission completed and ACK/NACK has been received // wail until transmission completed and ACK/NACK has been received
while (!(TWCR & (1 << TWINT))); while (!(TWCR & (1 << TWINT)))
;
// check value of TWI Status Register. Mask prescaler bits. // check value of TWI Status Register. Mask prescaler bits.
twst = TW_STATUS & 0xF8; twst = TW_STATUS & 0xF8;
@ -72,7 +74,7 @@ unsigned char i2c_start(unsigned char address) {
return 0; return 0;
}/* i2c_start */ } /* i2c_start */
/************************************************************************* /*************************************************************************
@ -82,7 +84,7 @@ unsigned char i2c_start(unsigned char address) {
Input: address and transfer direction of I2C device Input: address and transfer direction of I2C device
*************************************************************************/ *************************************************************************/
void i2c_start_wait(unsigned char address) { void i2c_start_wait(unsigned char address) {
uint8_t twst; uint8_t twst;
while (1) { while (1) {
@ -90,7 +92,8 @@ void i2c_start_wait(unsigned char address) {
TWCR = (1 << TWINT) | (1 << TWSTA) | (1 << TWEN); TWCR = (1 << TWINT) | (1 << TWSTA) | (1 << TWEN);
// wait until transmission completed // wait until transmission completed
while (!(TWCR & (1 << TWINT))); while (!(TWCR & (1 << TWINT)))
;
// check value of TWI Status Register. Mask prescaler bits. // check value of TWI Status Register. Mask prescaler bits.
twst = TW_STATUS & 0xF8; twst = TW_STATUS & 0xF8;
@ -101,7 +104,8 @@ void i2c_start_wait(unsigned char address) {
TWCR = (1 << TWINT) | (1 << TWEN); TWCR = (1 << TWINT) | (1 << TWEN);
// wail until transmission completed // wail until transmission completed
while (!(TWCR & (1 << TWINT))); while (!(TWCR & (1 << TWINT)))
;
// check value of TWI Status Register. Mask prescaler bits. // check value of TWI Status Register. Mask prescaler bits.
twst = TW_STATUS & 0xF8; twst = TW_STATUS & 0xF8;
@ -110,7 +114,8 @@ void i2c_start_wait(unsigned char address) {
TWCR = (1 << TWINT) | (1 << TWEN) | (1 << TWSTO); TWCR = (1 << TWINT) | (1 << TWEN) | (1 << TWSTO);
// wait until stop condition is executed and bus released // wait until stop condition is executed and bus released
while (TWCR & (1 << TWSTO)); while (TWCR & (1 << TWSTO))
;
continue; continue;
} }
@ -118,7 +123,7 @@ void i2c_start_wait(unsigned char address) {
break; break;
} }
}/* i2c_start_wait */ } /* i2c_start_wait */
/************************************************************************* /*************************************************************************
@ -132,7 +137,7 @@ void i2c_start_wait(unsigned char address) {
unsigned char i2c_rep_start(unsigned char address) { unsigned char i2c_rep_start(unsigned char address) {
return i2c_start(address); return i2c_start(address);
}/* i2c_rep_start */ } /* i2c_rep_start */
/************************************************************************* /*************************************************************************
@ -143,9 +148,10 @@ void i2c_stop(void) {
TWCR = (1 << TWINT) | (1 << TWEN) | (1 << TWSTO); TWCR = (1 << TWINT) | (1 << TWEN) | (1 << TWSTO);
// wait until stop condition is executed and bus released // wait until stop condition is executed and bus released
while (TWCR & (1 << TWSTO)); while (TWCR & (1 << TWSTO))
;
}/* i2c_stop */ } /* i2c_stop */
/************************************************************************* /*************************************************************************
@ -156,21 +162,22 @@ void i2c_stop(void) {
1 write failed 1 write failed
*************************************************************************/ *************************************************************************/
unsigned char i2c_write(unsigned char data) { unsigned char i2c_write(unsigned char data) {
uint8_t twst; uint8_t twst;
// send data to the previously addressed device // send data to the previously addressed device
TWDR = data; TWDR = data;
TWCR = (1 << TWINT) | (1 << TWEN); TWCR = (1 << TWINT) | (1 << TWEN);
// wait until transmission completed // wait until transmission completed
while (!(TWCR & (1 << TWINT))); while (!(TWCR & (1 << TWINT)))
;
// check value of TWI Status Register. Mask prescaler bits // check value of TWI Status Register. Mask prescaler bits
twst = TW_STATUS & 0xF8; twst = TW_STATUS & 0xF8;
if (twst != TW_MT_DATA_ACK) return 1; if (twst != TW_MT_DATA_ACK) return 1;
return 0; return 0;
}/* i2c_write */ } /* i2c_write */
/************************************************************************* /*************************************************************************
@ -180,11 +187,12 @@ unsigned char i2c_write(unsigned char data) {
*************************************************************************/ *************************************************************************/
unsigned char i2c_readAck(void) { unsigned char i2c_readAck(void) {
TWCR = (1 << TWINT) | (1 << TWEN) | (1 << TWEA); TWCR = (1 << TWINT) | (1 << TWEN) | (1 << TWEA);
while (!(TWCR & (1 << TWINT))); while (!(TWCR & (1 << TWINT)))
;
return TWDR; return TWDR;
}/* i2c_readAck */ } /* i2c_readAck */
/************************************************************************* /*************************************************************************
@ -194,11 +202,12 @@ unsigned char i2c_readAck(void) {
*************************************************************************/ *************************************************************************/
unsigned char i2c_readNak(void) { unsigned char i2c_readNak(void) {
TWCR = (1 << TWINT) | (1 << TWEN); TWCR = (1 << TWINT) | (1 << TWEN);
while (!(TWCR & (1 << TWINT))); while (!(TWCR & (1 << TWINT)))
;
return TWDR; return TWDR;
}/* i2c_readNak */ } /* i2c_readNak */
#endif #endif
#endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD #endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD

@ -89,10 +89,10 @@
#include <avr/io.h> #include <avr/io.h>
/** defines the data direction (reading from I2C device) in i2c_start(),i2c_rep_start() */ /** defines the data direction (reading from I2C device) in i2c_start(),i2c_rep_start() */
#define I2C_READ 1 #define I2C_READ 1
/** defines the data direction (writing to I2C device) in i2c_start(),i2c_rep_start() */ /** defines the data direction (writing to I2C device) in i2c_start(),i2c_rep_start() */
#define I2C_WRITE 0 #define I2C_WRITE 0
/** /**
@ -172,7 +172,7 @@ extern unsigned char i2c_readNak(void);
@return byte read from I2C device @return byte read from I2C device
*/ */
extern unsigned char i2c_read(unsigned char ack); extern unsigned char i2c_read(unsigned char ack);
#define i2c_read(ack) (ack) ? i2c_readAck() : i2c_readNak(); #define i2c_read(ack) (ack) ? i2c_readAck() : i2c_readNak();
/**@}*/ /**@}*/

@ -24,8 +24,8 @@ namespace kaleidoscope {
namespace device { namespace device {
namespace gd32 { namespace gd32 {
} // namespace gd32 } // namespace gd32
} // namespace device } // namespace device
} // namespace kaleidoscope } // namespace kaleidoscope
#endif // ifdef ARDUINO_GD32F303ZE_EVAL #endif // ifdef ARDUINO_GD32F303ZE_EVAL

@ -30,9 +30,9 @@ namespace kaleidoscope {
namespace device { namespace device {
namespace gd32 { namespace gd32 {
struct EvalStorageProps: kaleidoscope::driver::storage::GD32FlashProps {}; struct EvalStorageProps : kaleidoscope::driver::storage::GD32FlashProps {};
struct EvalProps: kaleidoscope::device::BaseProps { struct EvalProps : kaleidoscope::device::BaseProps {
typedef kaleidoscope::driver::bootloader::gd32::Base BootLoader; typedef kaleidoscope::driver::bootloader::gd32::Base BootLoader;
typedef eval::KeyScannerProps KeyScannerProps; typedef eval::KeyScannerProps KeyScannerProps;
typedef eval::KeyScanner KeyScanner; typedef eval::KeyScanner KeyScanner;
@ -41,18 +41,20 @@ struct EvalProps: kaleidoscope::device::BaseProps {
static constexpr const char *short_name = "GD32Eval"; static constexpr const char *short_name = "GD32Eval";
}; };
class Eval: public kaleidoscope::device::Base<EvalProps> {}; class Eval : public kaleidoscope::device::Base<EvalProps> {};
// clang-format off
#define PER_KEY_DATA(dflt, \ #define PER_KEY_DATA(dflt, \
R0C0, R0C1 \ R0C0, R0C1 \
) \ ) \
R0C0, R0C1 R0C0, R0C1
// clang-format on
} // namespace gd32 } // namespace gd32
} // namespace device } // namespace device
EXPORT_DEVICE(kaleidoscope::device::gd32::Eval) EXPORT_DEVICE(kaleidoscope::device::gd32::Eval)
} // namespace kaleidoscope } // namespace kaleidoscope
#endif #endif

@ -160,9 +160,9 @@ uint8_t KeyScanner::previousPressedKeyswitchCount() {
return count; return count;
} }
} // namespace eval } // namespace eval
} // namespace gd32 } // namespace gd32
} // namespace device } // namespace device
} // namespace kaleidoscope } // namespace kaleidoscope
#endif #endif

@ -29,19 +29,20 @@ namespace gd32 {
namespace eval { namespace eval {
struct KeyScannerProps : public kaleidoscope::driver::keyscanner::BaseProps { struct KeyScannerProps : public kaleidoscope::driver::keyscanner::BaseProps {
static constexpr uint8_t matrix_rows = 1; static constexpr uint8_t matrix_rows = 1;
static constexpr uint8_t matrix_columns = 2; static constexpr uint8_t matrix_columns = 2;
static constexpr uint8_t matrix_row_pins[] = { PA3 }; static constexpr uint8_t matrix_row_pins[] = {PA3};
static constexpr uint8_t matrix_col_pins[] = { PE4, PD12 }; static constexpr uint8_t matrix_col_pins[] = {PE4, PD12};
typedef MatrixAddr<matrix_rows, matrix_columns> KeyAddr; typedef MatrixAddr<matrix_rows, matrix_columns> KeyAddr;
}; };
class KeyScanner: public kaleidoscope::driver::keyscanner::Base<KeyScannerProps> { class KeyScanner : public kaleidoscope::driver::keyscanner::Base<KeyScannerProps> {
private: private:
typedef KeyScanner ThisType; typedef KeyScanner ThisType;
typedef KeyScannerProps Props_; typedef KeyScannerProps Props_;
public: public:
static bool do_scan; static bool do_scan;
@ -55,6 +56,7 @@ class KeyScanner: public kaleidoscope::driver::keyscanner::Base<KeyScannerProps>
static bool wasKeyswitchPressed(KeyAddr key_addr); static bool wasKeyswitchPressed(KeyAddr key_addr);
static uint8_t previousPressedKeyswitchCount(); static uint8_t previousPressedKeyswitchCount();
private: private:
/* /*
each of these variables are storing the state for a row of keys each of these variables are storing the state for a row of keys
@ -63,8 +65,8 @@ class KeyScanner: public kaleidoscope::driver::keyscanner::Base<KeyScannerProps>
and the state in debounced_state[0]. and the state in debounced_state[0].
*/ */
struct debounce_t { struct debounce_t {
uint16_t db0; // counter bit 0 uint16_t db0; // counter bit 0
uint16_t db1; // counter bit 1 uint16_t db1; // counter bit 1
uint16_t debounced_state; // debounced state uint16_t debounced_state; // debounced state
}; };
@ -79,9 +81,9 @@ class KeyScanner: public kaleidoscope::driver::keyscanner::Base<KeyScannerProps>
static uint16_t readRows(); static uint16_t readRows();
}; };
} // namespace eval } // namespace eval
} // namespace gd32 } // namespace gd32
} // namespace device } // namespace device
} // namespace kaleidoscope } // namespace kaleidoscope
#endif #endif

@ -26,7 +26,7 @@
// in the global namespace within the scope of this file. We'll use these // in the global namespace within the scope of this file. We'll use these
// aliases to simplify some template initialization code below. // aliases to simplify some template initialization code below.
using KeyScannerProps = typename kaleidoscope::device::kbdfans::KBD4xProps::KeyScannerProps; using KeyScannerProps = typename kaleidoscope::device::kbdfans::KBD4xProps::KeyScannerProps;
using KeyScanner = typename kaleidoscope::device::kbdfans::KBD4xProps::KeyScanner; using KeyScanner = typename kaleidoscope::device::kbdfans::KBD4xProps::KeyScanner;
namespace kaleidoscope { namespace kaleidoscope {
namespace device { namespace device {
@ -44,7 +44,8 @@ constexpr uint8_t KeyScannerProps::matrix_col_pins[matrix_columns];
// `KeyScanner` here refers to the alias set up above, just like in the // `KeyScanner` here refers to the alias set up above, just like in the
// `KeyScannerProps` case above. // `KeyScannerProps` case above.
template<> KeyScanner::row_state_t KeyScanner::matrix_state_[KeyScannerProps::matrix_rows] = {}; template<>
KeyScanner::row_state_t KeyScanner::matrix_state_[KeyScannerProps::matrix_rows] = {};
// We set up the TIMER1 interrupt vector here. Due to dependency reasons, this // 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. // cannot be in a header-only driver, and must be placed here.
@ -58,9 +59,9 @@ ISR(TIMER1_OVF_vect) {
Runtime.device().keyScanner().do_scan_ = true; Runtime.device().keyScanner().do_scan_ = true;
} }
} // namespace kbdfans } // namespace kbdfans
} // namespace device } // namespace device
} // namespace kaleidoscope } // namespace kaleidoscope
#endif #endif
#endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD #endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD

@ -32,19 +32,19 @@ namespace device {
namespace kbdfans { namespace kbdfans {
struct KBD4xProps : kaleidoscope::device::ATmega32U4KeyboardProps { struct KBD4xProps : kaleidoscope::device::ATmega32U4KeyboardProps {
struct MCUProps: public kaleidoscope::driver::mcu::ATmega32U4Props { struct MCUProps : public kaleidoscope::driver::mcu::ATmega32U4Props {
static constexpr bool disable_jtag = true; static constexpr bool disable_jtag = true;
static constexpr bool disable_clock_division = true; static constexpr bool disable_clock_division = true;
}; };
typedef kaleidoscope::driver::mcu::ATmega32U4<MCUProps> MCU; typedef kaleidoscope::driver::mcu::ATmega32U4<MCUProps> MCU;
struct KeyScannerProps : public kaleidoscope::driver::keyscanner::ATmegaProps { struct KeyScannerProps : public kaleidoscope::driver::keyscanner::ATmegaProps {
static constexpr uint8_t matrix_rows = 4; static constexpr uint8_t matrix_rows = 4;
static constexpr uint8_t matrix_columns = 12; static constexpr uint8_t matrix_columns = 12;
typedef MatrixAddr<matrix_rows, matrix_columns> KeyAddr; typedef MatrixAddr<matrix_rows, matrix_columns> KeyAddr;
#ifndef KALEIDOSCOPE_VIRTUAL_BUILD #ifndef KALEIDOSCOPE_VIRTUAL_BUILD
static constexpr uint8_t matrix_row_pins[matrix_rows] = {PIN_D0, PIN_D1, PIN_D2, PIN_D3}; static constexpr uint8_t matrix_row_pins[matrix_rows] = {PIN_D0, PIN_D1, PIN_D2, PIN_D3};
static constexpr uint8_t matrix_col_pins[matrix_columns] = { PIN_F0, PIN_F1, PIN_F4, PIN_F5, PIN_F6, PIN_F7, PIN_B3, PIN_B1, PIN_B0, PIN_D5, PIN_B7, PIN_C7 }; static constexpr uint8_t matrix_col_pins[matrix_columns] = {PIN_F0, PIN_F1, PIN_F4, PIN_F5, PIN_F6, PIN_F7, PIN_B3, PIN_B1, PIN_B0, PIN_D5, PIN_B7, PIN_C7};
#endif // KALEIDOSCOPE_VIRTUAL_BUILD #endif // KALEIDOSCOPE_VIRTUAL_BUILD
}; };
typedef kaleidoscope::driver::keyscanner::ATmega<KeyScannerProps> KeyScanner; typedef kaleidoscope::driver::keyscanner::ATmega<KeyScannerProps> KeyScanner;
typedef kaleidoscope::driver::bootloader::avr::FLIP Bootloader; typedef kaleidoscope::driver::bootloader::avr::FLIP Bootloader;
@ -52,8 +52,8 @@ struct KBD4xProps : kaleidoscope::device::ATmega32U4KeyboardProps {
}; };
#ifndef KALEIDOSCOPE_VIRTUAL_BUILD #ifndef KALEIDOSCOPE_VIRTUAL_BUILD
class KBD4x: public kaleidoscope::device::ATmega32U4Keyboard<KBD4xProps> {}; class KBD4x : public kaleidoscope::device::ATmega32U4Keyboard<KBD4xProps> {};
#else // ifndef KALEIDOSCOPE_VIRTUAL_BUILD #else // ifndef KALEIDOSCOPE_VIRTUAL_BUILD
/* Device definition omitted for virtual device builds. /* Device definition omitted for virtual device builds.
* We need to forward declare the device name, though, as there are * We need to forward declare the device name, though, as there are
* some legacy extern references to boards whose definition * some legacy extern references to boards whose definition
@ -61,8 +61,9 @@ class KBD4x: public kaleidoscope::device::ATmega32U4Keyboard<KBD4xProps> {};
*/ */
class KBD4x; class KBD4x;
#endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD #endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD
// clang-format off
#define PER_KEY_DATA(dflt, \ #define PER_KEY_DATA(dflt, \
R0C0, R0C1, R0C2, R0C3, R0C4, R0C5, R0C6, R0C7, R0C8, R0C9, R0C10, R0C11, \ R0C0, R0C1, R0C2, R0C3, R0C4, R0C5, R0C6, R0C7, R0C8, R0C9, R0C10, R0C11, \
R1C0, R1C1, R1C2, R1C3, R1C4, R1C5, R1C6, R1C7, R1C8, R1C9, R1C10, R1C11, \ R1C0, R1C1, R1C2, R1C3, R1C4, R1C5, R1C6, R1C7, R1C8, R1C9, R1C10, R1C11, \
@ -73,6 +74,7 @@ class KBD4x;
R1C0, R1C1, R1C2, R1C3, R1C4, R1C5, R1C6, R1C7, R1C8, R1C9, R1C10, R1C11, \ R1C0, R1C1, R1C2, R1C3, R1C4, R1C5, R1C6, R1C7, R1C8, R1C9, R1C10, R1C11, \
R2C0, R2C1, R2C2, R2C3, R2C4, R2C5, R2C6, R2C7, R2C8, R2C9, R2C10, R2C11, \ R2C0, R2C1, R2C2, R2C3, R2C4, R2C5, R2C6, R2C7, R2C8, R2C9, R2C10, R2C11, \
R3C0, R3C1, R3C2, R3C3, R3C4, R3C5, R3C5, R3C7, R3C8, R3C9, R3C10, R3C11 R3C0, R3C1, R3C2, R3C3, R3C4, R3C5, R3C5, R3C7, R3C8, R3C9, R3C10, R3C11
// clang-format on
} // namespace kbdfans } // namespace kbdfans
} // namespace device } // namespace device

@ -27,7 +27,7 @@
// in the global namespace within the scope of this file. We'll use these // in the global namespace within the scope of this file. We'll use these
// aliases to simplify some template initialization code below. // aliases to simplify some template initialization code below.
using KeyScannerProps = typename kaleidoscope::device::keyboardio::AtreusProps::KeyScannerProps; using KeyScannerProps = typename kaleidoscope::device::keyboardio::AtreusProps::KeyScannerProps;
using KeyScanner = typename kaleidoscope::device::keyboardio::AtreusProps::KeyScanner; using KeyScanner = typename kaleidoscope::device::keyboardio::AtreusProps::KeyScanner;
namespace kaleidoscope { namespace kaleidoscope {
namespace device { namespace device {
@ -45,7 +45,8 @@ constexpr uint8_t KeyScannerProps::matrix_col_pins[matrix_columns];
// `KeyScanner` here refers to the alias set up above, just like in the // `KeyScanner` here refers to the alias set up above, just like in the
// `KeyScannerProps` case above. // `KeyScannerProps` case above.
template<> KeyScanner::row_state_t KeyScanner::matrix_state_[KeyScannerProps::matrix_rows] = {}; template<>
KeyScanner::row_state_t KeyScanner::matrix_state_[KeyScannerProps::matrix_rows] = {};
// We set up the TIMER1 interrupt vector here. Due to dependency reasons, this // 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. // cannot be in a header-only driver, and must be placed here.
@ -64,4 +65,4 @@ ISR(TIMER1_OVF_vect) {
} // namespace kaleidoscope } // namespace kaleidoscope
#endif #endif
#endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD #endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD

@ -35,13 +35,13 @@ struct AtreusProps : kaleidoscope::device::ATmega32U4KeyboardProps {
struct KeyScannerProps : public kaleidoscope::driver::keyscanner::ATmegaProps { struct KeyScannerProps : public kaleidoscope::driver::keyscanner::ATmegaProps {
static constexpr uint8_t matrix_rows = 4; static constexpr uint8_t matrix_rows = 4;
static constexpr uint8_t matrix_columns = 12; static constexpr uint8_t matrix_columns = 12;
typedef MatrixAddr<matrix_rows, matrix_columns> KeyAddr; typedef MatrixAddr<matrix_rows, matrix_columns> KeyAddr;
#ifndef KALEIDOSCOPE_VIRTUAL_BUILD #ifndef KALEIDOSCOPE_VIRTUAL_BUILD
static constexpr uint8_t matrix_row_pins[matrix_rows] = {PIN_F6, PIN_F5, PIN_F4, PIN_F1}; static constexpr uint8_t matrix_row_pins[matrix_rows] = {PIN_F6, PIN_F5, PIN_F4, PIN_F1};
static constexpr uint8_t matrix_col_pins[matrix_columns] = {PIN_F7, PIN_E2, PIN_C7, PIN_C6, PIN_B6, PIN_B5, PIN_D7, PIN_D6, PIN_D4, PIN_D5, PIN_D3, PIN_D2}; static constexpr uint8_t matrix_col_pins[matrix_columns] = {PIN_F7, PIN_E2, PIN_C7, PIN_C6, PIN_B6, PIN_B5, PIN_D7, PIN_D6, PIN_D4, PIN_D5, PIN_D3, PIN_D2};
#endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD #endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD
}; };
typedef kaleidoscope::driver::keyscanner::ATmega<KeyScannerProps> KeyScanner; typedef kaleidoscope::driver::keyscanner::ATmega<KeyScannerProps> KeyScanner;
@ -50,8 +50,8 @@ struct AtreusProps : kaleidoscope::device::ATmega32U4KeyboardProps {
}; };
#ifndef KALEIDOSCOPE_VIRTUAL_BUILD #ifndef KALEIDOSCOPE_VIRTUAL_BUILD
class Atreus: public kaleidoscope::device::ATmega32U4Keyboard<AtreusProps> {}; class Atreus : public kaleidoscope::device::ATmega32U4Keyboard<AtreusProps> {};
#else // ifndef KALEIDOSCOPE_VIRTUAL_BUILD #else // ifndef KALEIDOSCOPE_VIRTUAL_BUILD
/* Device definition omitted for virtual device builds. /* Device definition omitted for virtual device builds.
* We need to forward declare the device name, though, as there are * We need to forward declare the device name, though, as there are
* some legacy extern references to boards whose definition * some legacy extern references to boards whose definition
@ -59,8 +59,9 @@ class Atreus: public kaleidoscope::device::ATmega32U4Keyboard<AtreusProps> {};
*/ */
class Atreus; class Atreus;
#endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD #endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD
// clang-format off
#define PER_KEY_DATA(dflt, \ #define PER_KEY_DATA(dflt, \
R0C0, R0C1, R0C2, R0C3, R0C4, R0C7, R0C8, R0C9, R0C10, R0C11, \ R0C0, R0C1, R0C2, R0C3, R0C4, R0C7, R0C8, R0C9, R0C10, R0C11, \
@ -89,6 +90,8 @@ class Atreus;
R2C0, R2C1, R2C2, R2C3, R2C4, R2C5, R2C6, R2C7, R2C8, R2C9, R2C10, R2C11, \ R2C0, R2C1, R2C2, R2C3, R2C4, R2C5, R2C6, R2C7, R2C8, R2C9, R2C10, R2C11, \
R3C0, R3C1, R3C2, R3C3, R3C4, R3C5, R3C6, R3C7, R3C8, R3C9, R3C10, R3C11 R3C0, R3C1, R3C2, R3C3, R3C4, R3C5, R3C6, R3C7, R3C8, R3C9, R3C10, R3C11
// clang-format on
} // namespace keyboardio } // namespace keyboardio
} // namespace device } // namespace device

@ -24,7 +24,7 @@ extern "C" {
#include "twi.h" #include "twi.h"
} }
#define ELEMENTS(arr) (sizeof(arr) / sizeof((arr)[0])) #define ELEMENTS(arr) (sizeof(arr) / sizeof((arr)[0]))
#define LED_DRIVER_ADDR 0x30 #define LED_DRIVER_ADDR 0x30
@ -32,7 +32,7 @@ extern "C" {
// in the global namespace within the scope of this file. We'll use these // in the global namespace within the scope of this file. We'll use these
// aliases to simplify some template initialization code below. // aliases to simplify some template initialization code below.
using KeyScannerProps = typename kaleidoscope::device::keyboardio::ImagoProps::KeyScannerProps; using KeyScannerProps = typename kaleidoscope::device::keyboardio::ImagoProps::KeyScannerProps;
using KeyScanner = typename kaleidoscope::device::keyboardio::ImagoProps::KeyScanner; using KeyScanner = typename kaleidoscope::device::keyboardio::ImagoProps::KeyScanner;
namespace kaleidoscope { namespace kaleidoscope {
namespace device { namespace device {
@ -42,18 +42,18 @@ constexpr uint8_t ImagoLEDDriverProps::key_led_map[] PROGMEM;
#ifndef KALEIDOSCOPE_VIRTUAL_BUILD #ifndef KALEIDOSCOPE_VIRTUAL_BUILD
static constexpr uint8_t CMD_SET_REGISTER = 0xFD; static constexpr uint8_t CMD_SET_REGISTER = 0xFD;
static constexpr uint8_t CMD_WRITE_ENABLE = 0xFE; static constexpr uint8_t CMD_WRITE_ENABLE = 0xFE;
static constexpr uint8_t WRITE_ENABLE_ONCE = 0b11000101; static constexpr uint8_t WRITE_ENABLE_ONCE = 0b11000101;
static constexpr uint8_t LED_REGISTER_PWM0 = 0x00; static constexpr uint8_t LED_REGISTER_PWM0 = 0x00;
static constexpr uint8_t LED_REGISTER_PWM1 = 0x01; static constexpr uint8_t LED_REGISTER_PWM1 = 0x01;
static constexpr uint8_t LED_REGISTER_DATA0 = 0x02; static constexpr uint8_t LED_REGISTER_DATA0 = 0x02;
static constexpr uint8_t LED_REGISTER_DATA1 = 0x03; static constexpr uint8_t LED_REGISTER_DATA1 = 0x03;
static constexpr uint8_t LED_REGISTER_CONTROL = 0x04; static constexpr uint8_t LED_REGISTER_CONTROL = 0x04;
static constexpr uint8_t LED_REGISTER_PWM0_SIZE = 0xB4; static constexpr uint8_t LED_REGISTER_PWM0_SIZE = 0xB4;
static constexpr uint8_t LED_REGISTER_PWM1_SIZE = 0xAB; static constexpr uint8_t LED_REGISTER_PWM1_SIZE = 0xAB;
static constexpr uint8_t LED_REGISTER_DATA0_SIZE = 0xB4; static constexpr uint8_t LED_REGISTER_DATA0_SIZE = 0xB4;
static constexpr uint8_t LED_REGISTER_DATA1_SIZE = 0xAB; static constexpr uint8_t LED_REGISTER_DATA1_SIZE = 0xAB;
@ -71,7 +71,8 @@ constexpr uint8_t KeyScannerProps::matrix_col_pins[matrix_columns];
// `KeyScanner` here refers to the alias set up above, just like in the // `KeyScanner` here refers to the alias set up above, just like in the
// `KeyScannerProps` case above. // `KeyScannerProps` case above.
template<> KeyScanner::row_state_t KeyScanner::matrix_state_[KeyScannerProps::matrix_rows] = {}; template<>
KeyScanner::row_state_t KeyScanner::matrix_state_[KeyScannerProps::matrix_rows] = {};
// We set up the TIMER1 interrupt vector here. Due to dependency reasons, this // 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. // cannot be in a header-only driver, and must be placed here.
@ -92,17 +93,17 @@ uint8_t ImagoLEDDriver::brightness_adjustment_;
void ImagoLEDDriver::setup() { void ImagoLEDDriver::setup() {
setAllPwmTo(0xFF); setAllPwmTo(0xFF);
selectRegister(LED_REGISTER_CONTROL); selectRegister(LED_REGISTER_CONTROL);
twiSend(LED_DRIVER_ADDR, 0x01, 0xFF); //global current twiSend(LED_DRIVER_ADDR, 0x01, 0xFF); //global current
twiSend(LED_DRIVER_ADDR, 0x00, 0x01); //normal operation twiSend(LED_DRIVER_ADDR, 0x00, 0x01); //normal operation
} }
void ImagoLEDDriver::twiSend(uint8_t addr, uint8_t Reg_Add, uint8_t Reg_Dat) { void ImagoLEDDriver::twiSend(uint8_t addr, uint8_t Reg_Add, uint8_t Reg_Dat) {
uint8_t data[] = {Reg_Add, Reg_Dat }; uint8_t data[] = {Reg_Add, Reg_Dat};
uint8_t result = twi_writeTo(addr, data, ELEMENTS(data), 1, 0); uint8_t result = twi_writeTo(addr, data, ELEMENTS(data), 1, 0);
} }
void ImagoLEDDriver::unlockRegister(void) { void ImagoLEDDriver::unlockRegister(void) {
twiSend(LED_DRIVER_ADDR, CMD_WRITE_ENABLE, WRITE_ENABLE_ONCE); //unlock twiSend(LED_DRIVER_ADDR, CMD_WRITE_ENABLE, WRITE_ENABLE_ONCE); //unlock
} }
void ImagoLEDDriver::selectRegister(uint8_t page) { void ImagoLEDDriver::selectRegister(uint8_t page) {
@ -139,18 +140,18 @@ uint8_t ImagoLEDDriver::adjustBrightness(uint8_t value) {
} }
void ImagoLEDDriver::syncLeds() { void ImagoLEDDriver::syncLeds() {
// if (!isLEDChanged) // if (!isLEDChanged)
// return; // return;
uint8_t data[LED_REGISTER_DATA_LARGEST + 1]; uint8_t data[LED_REGISTER_DATA_LARGEST + 1];
data[0] = 0;// the address of the first byte to copy in data[0] = 0; // the address of the first byte to copy in
uint8_t last_led = 0; uint8_t last_led = 0;
// Write the first LED bank // Write the first LED bank
selectRegister(LED_REGISTER_DATA0); selectRegister(LED_REGISTER_DATA0);
for (auto i = 1; i < LED_REGISTER_DATA0_SIZE; i += 3) { for (auto i = 1; i < LED_REGISTER_DATA0_SIZE; i += 3) {
data[i] = adjustBrightness(led_data[last_led].b); data[i] = adjustBrightness(led_data[last_led].b);
data[i + 1] = adjustBrightness(led_data[last_led].g); data[i + 1] = adjustBrightness(led_data[last_led].g);
data[i + 2] = adjustBrightness(led_data[last_led].r); data[i + 2] = adjustBrightness(led_data[last_led].r);
last_led++; last_led++;
@ -170,7 +171,7 @@ void ImagoLEDDriver::syncLeds() {
selectRegister(LED_REGISTER_DATA1); selectRegister(LED_REGISTER_DATA1);
for (auto i = 1; i < LED_REGISTER_DATA1_SIZE; i += 3) { for (auto i = 1; i < LED_REGISTER_DATA1_SIZE; i += 3) {
data[i] = adjustBrightness(led_data[last_led].b); data[i] = adjustBrightness(led_data[last_led].b);
data[i + 1] = adjustBrightness(led_data[last_led].g); data[i + 1] = adjustBrightness(led_data[last_led].g);
data[i + 2] = adjustBrightness(led_data[last_led].r); data[i + 2] = adjustBrightness(led_data[last_led].r);
last_led++; last_led++;
@ -186,11 +187,10 @@ void ImagoLEDDriver::setAllPwmTo(uint8_t step) {
selectRegister(LED_REGISTER_PWM0); selectRegister(LED_REGISTER_PWM0);
uint8_t data[0xB5] = {}; uint8_t data[0xB5] = {};
data[0] = 0; data[0] = 0;
// PWM Register 0 is 0x00 to 0xB3 // PWM Register 0 is 0x00 to 0xB3
for (auto i = 1; i <= 0xB4; i++) { for (auto i = 1; i <= 0xB4; i++) {
data[i] = step; data[i] = step;
} }
twi_writeTo(LED_DRIVER_ADDR, data, 0xB5, 1, 0); twi_writeTo(LED_DRIVER_ADDR, data, 0xB5, 1, 0);
@ -198,7 +198,6 @@ void ImagoLEDDriver::setAllPwmTo(uint8_t step) {
// PWM Register 1 is 0x00 to 0xAA // PWM Register 1 is 0x00 to 0xAA
for (auto i = 1; i <= LED_REGISTER_PWM1_SIZE; i++) { for (auto i = 1; i <= LED_REGISTER_PWM1_SIZE; i++) {
data[i] = step; data[i] = step;
} }
twi_writeTo(LED_DRIVER_ADDR, data, 0xAC, 1, 0); twi_writeTo(LED_DRIVER_ADDR, data, 0xAC, 1, 0);
} }
@ -215,7 +214,7 @@ void Imago::setup() {
kaleidoscope::device::ATmega32U4Keyboard<ImagoProps>::setup(); kaleidoscope::device::ATmega32U4Keyboard<ImagoProps>::setup();
} }
#endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD #endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD
} // namespace keyboardio } // namespace keyboardio
} // namespace device } // namespace device

@ -27,7 +27,8 @@ struct cRGB {
uint8_t r; uint8_t r;
}; };
#define CRGB(r,g,b) (cRGB){b, g, r} #define CRGB(r, g, b) \
(cRGB) { b, g, r }
#include "kaleidoscope/device/ATmega32U4Keyboard.h" #include "kaleidoscope/device/ATmega32U4Keyboard.h"
#include "kaleidoscope/driver/bootloader/avr/Caterina.h" #include "kaleidoscope/driver/bootloader/avr/Caterina.h"
@ -40,14 +41,16 @@ namespace keyboardio {
using kaleidoscope::driver::led::no_led; using kaleidoscope::driver::led::no_led;
struct ImagoLEDDriverProps: public kaleidoscope::driver::led::BaseProps { struct ImagoLEDDriverProps : public kaleidoscope::driver::led::BaseProps {
static constexpr uint8_t led_count = 78; static constexpr uint8_t led_count = 78;
static constexpr uint8_t key_led_map[/* 5*16 */] PROGMEM = { static constexpr uint8_t key_led_map[/* 5*16 */] PROGMEM = {
104, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 115, 12, 116, // clang-format off
104, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 115, 12, 116,
91, 13, no_led, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 102, 15, 103, 91, 13, no_led, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 102, 15, 103,
78, 26, 27, 28, 29, 30, 31, no_led, 33, 34, 35, 36, 37, 89, 38, no_led, 78, 26, 27, 28, 29, 30, 31, no_led, 33, 34, 35, 36, 37, 89, 38, no_led,
65, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, no_led, 90, 65, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, no_led, 90,
52, 66, 53, 54, no_led, 56, 57, 71, 59, no_led, 61, 62, 63, 64, no_led, 77 52, 66, 53, 54, no_led, 56, 57, 71, 59, no_led, 61, 62, 63, 64, no_led, 77
// clang-format on
}; };
}; };
@ -60,14 +63,14 @@ class ImagoLEDDriver : public kaleidoscope::driver::led::Base<ImagoLEDDriverProp
static cRGB getCrgbAt(uint8_t i); static cRGB getCrgbAt(uint8_t i);
static void setBrightness(uint8_t brightness) { static void setBrightness(uint8_t brightness) {
brightness_adjustment_ = 255 - brightness; brightness_adjustment_ = 255 - brightness;
isLEDChanged = true; isLEDChanged = true;
} }
static uint8_t getBrightness() { static uint8_t getBrightness() {
return 255 - brightness_adjustment_; return 255 - brightness_adjustment_;
} }
static cRGB led_data[117]; // 117 is the number of LEDs the chip drives static cRGB led_data[117]; // 117 is the number of LEDs the chip drives
// until we clean stuff up a bit, it's easiest to just have the whole struct around // until we clean stuff up a bit, it's easiest to just have the whole struct around
private: private:
static uint8_t brightness_adjustment_; static uint8_t brightness_adjustment_;
@ -79,19 +82,19 @@ class ImagoLEDDriver : public kaleidoscope::driver::led::Base<ImagoLEDDriverProp
static void setAllPwmTo(uint8_t); static void setAllPwmTo(uint8_t);
static void twiSend(uint8_t addr, uint8_t Reg_Add, uint8_t Reg_Dat); static void twiSend(uint8_t addr, uint8_t Reg_Add, uint8_t Reg_Dat);
}; };
#else // ifndef KALEIDOSCOPE_VIRTUAL_BUILD #else // ifndef KALEIDOSCOPE_VIRTUAL_BUILD
class ImagoLEDDriver; class ImagoLEDDriver;
#endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD #endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD
struct ImagoProps : kaleidoscope::device::ATmega32U4KeyboardProps { struct ImagoProps : kaleidoscope::device::ATmega32U4KeyboardProps {
struct KeyScannerProps : public kaleidoscope::driver::keyscanner::ATmegaProps { struct KeyScannerProps : public kaleidoscope::driver::keyscanner::ATmegaProps {
static constexpr uint8_t matrix_rows = 5; static constexpr uint8_t matrix_rows = 5;
static constexpr uint8_t matrix_columns = 16; static constexpr uint8_t matrix_columns = 16;
typedef MatrixAddr<matrix_rows, matrix_columns> KeyAddr; typedef MatrixAddr<matrix_rows, matrix_columns> KeyAddr;
#ifndef KALEIDOSCOPE_VIRTUAL_BUILD #ifndef KALEIDOSCOPE_VIRTUAL_BUILD
static constexpr uint8_t matrix_row_pins[matrix_rows] = {PIN_F6, PIN_F5, PIN_F4, PIN_F1, PIN_F0}; static constexpr uint8_t matrix_row_pins[matrix_rows] = {PIN_F6, PIN_F5, PIN_F4, PIN_F1, PIN_F0};
static constexpr uint8_t matrix_col_pins[matrix_columns] = {PIN_B2, PIN_B7, PIN_E2, PIN_C7, PIN_C6, PIN_B6, PIN_B5, PIN_B4, PIN_D7, PIN_D6, PIN_D4, PIN_D5, PIN_D3, PIN_D2, PIN_E6, PIN_F7}; static constexpr uint8_t matrix_col_pins[matrix_columns] = {PIN_B2, PIN_B7, PIN_E2, PIN_C7, PIN_C6, PIN_B6, PIN_B5, PIN_B4, PIN_D7, PIN_D6, PIN_D4, PIN_D5, PIN_D3, PIN_D2, PIN_E6, PIN_F7};
#endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD #endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD
}; };
typedef kaleidoscope::driver::keyscanner::ATmega<KeyScannerProps> KeyScanner; typedef kaleidoscope::driver::keyscanner::ATmega<KeyScannerProps> KeyScanner;
typedef ImagoLEDDriverProps LEDDriverProps; typedef ImagoLEDDriverProps LEDDriverProps;
@ -101,12 +104,13 @@ struct ImagoProps : kaleidoscope::device::ATmega32U4KeyboardProps {
}; };
#ifndef KALEIDOSCOPE_VIRTUAL_BUILD #ifndef KALEIDOSCOPE_VIRTUAL_BUILD
class Imago: public kaleidoscope::device::ATmega32U4Keyboard<ImagoProps> { class Imago : public kaleidoscope::device::ATmega32U4Keyboard<ImagoProps> {
public: public:
void setup(); void setup();
}; };
#endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD #endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD
// clang-format off
#define PER_KEY_DATA(dflt, \ #define PER_KEY_DATA(dflt, \
R0C0, R0C1, R0C2, R0C3, R0C4, R0C5, R0C6, R0C7, R0C8, R0C9, R0C10, R0C11, R0C12, R0C13, R0C14, R0C15, \ R0C0, R0C1, R0C2, R0C3, R0C4, R0C5, R0C6, R0C7, R0C8, R0C9, R0C10, R0C11, R0C12, R0C13, R0C14, R0C15, \
R1C0, R1C1, R1C3, R1C4, R1C5, R1C6, R1C7, R1C8, R1C9, R1C10, R1C11, R1C12, R1C13, R1C14, R1C15, \ R1C0, R1C1, R1C3, R1C4, R1C5, R1C6, R1C7, R1C8, R1C9, R1C10, R1C11, R1C12, R1C13, R1C14, R1C15, \
@ -119,6 +123,7 @@ class Imago: public kaleidoscope::device::ATmega32U4Keyboard<ImagoProps> {
R2C0, R2C1, R2C2, R2C3, R2C4, R2C5, R2C6, XXX, R2C8, R2C9, R2C10, R2C11, R2C12, R2C13, R2C14, XXX , \ R2C0, R2C1, R2C2, R2C3, R2C4, R2C5, R2C6, XXX, R2C8, R2C9, R2C10, R2C11, R2C12, R2C13, R2C14, XXX , \
R3C0, R3C1, R3C2, R3C3, R3C4, R3C5, R3C6, R3C7, R3C8, R3C9, R3C10, R3C11, R3C12, R3C13, XXX, R3C15, \ R3C0, R3C1, R3C2, R3C3, R3C4, R3C5, R3C6, R3C7, R3C8, R3C9, R3C10, R3C11, R3C12, R3C13, XXX, R3C15, \
R4C0, R4C1, R4C2, R4C3, XXX, R4C5, R4C6, R4C7, R4C8, XXX, R4C10, R4C11, R4C12, R4C13, XXX, R4C15 R4C0, R4C1, R4C2, R4C3, XXX, R4C5, R4C6, R4C7, R4C8, XXX, R4C10, R4C11, R4C12, R4C13, XXX, R4C15
// clang-format on
} // namespace keyboardio } // namespace keyboardio
} // namespace device } // namespace device

@ -44,14 +44,14 @@ void twi_init(void);
void twi_disable(void); void twi_disable(void);
void twi_setAddress(uint8_t); void twi_setAddress(uint8_t);
void twi_setFrequency(uint32_t); void twi_setFrequency(uint32_t);
uint8_t twi_readFrom(uint8_t, uint8_t*, uint8_t, uint8_t); uint8_t twi_readFrom(uint8_t, uint8_t *, uint8_t, uint8_t);
uint8_t twi_writeTo(uint8_t, uint8_t*, uint8_t, uint8_t, uint8_t); uint8_t twi_writeTo(uint8_t, uint8_t *, uint8_t, uint8_t, uint8_t);
uint8_t twi_transmit(const uint8_t*, uint8_t); uint8_t twi_transmit(const uint8_t *, uint8_t);
void twi_attachSlaveRxEvent(void (*)(uint8_t*, int)); void twi_attachSlaveRxEvent(void (*)(uint8_t *, int));
void twi_attachSlaveTxEvent(void (*)(void)); void twi_attachSlaveTxEvent(void (*)(void));
void twi_reply(uint8_t); void twi_reply(uint8_t);
void twi_stop(void); void twi_stop(void);
void twi_releaseBus(void); void twi_releaseBus(void);
#endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD #endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD
#endif #endif

@ -20,15 +20,15 @@
#include "kaleidoscope/device/keyboardio/Model01.h" #include "kaleidoscope/device/keyboardio/Model01.h"
// System headers // System headers
#include <stdint.h> // for uint8_t #include <stdint.h> // for uint8_t
// Arduino headers // Arduino headers
#include <Arduino.h> // for PROGMEM #include <Arduino.h> // for PROGMEM
#ifndef KALEIDOSCOPE_VIRTUAL_BUILD #ifndef KALEIDOSCOPE_VIRTUAL_BUILD
#include <KeyboardioHID.h> #include <KeyboardioHID.h>
#include <avr/wdt.h> #include <avr/wdt.h>
#endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD #endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD
// Kaleidoscope headers // Kaleidoscope headers
#include "kaleidoscope/driver/keyscanner/Base_Impl.h" // IWYU pragma: keep #include "kaleidoscope/driver/keyscanner/Base_Impl.h" // IWYU pragma: keep
@ -63,8 +63,8 @@ void Model01Hands::setup(void) {
PORTE &= ~_BV(6); PORTE &= ~_BV(6);
// Set B4, the overcurrent check to an input with an internal pull-up // Set B4, the overcurrent check to an input with an internal pull-up
DDRB &= ~_BV(4); // set bit, input DDRB &= ~_BV(4); // set bit, input
PORTB &= ~_BV(4); // set bit, enable pull-up resistor PORTB &= ~_BV(4); // set bit, enable pull-up resistor
} }
/********* LED Driver *********/ /********* LED Driver *********/
@ -163,7 +163,7 @@ void Model01KeyScanner::setup() {
void Model01KeyScanner::readMatrix() { void Model01KeyScanner::readMatrix() {
//scan the Keyboard matrix looking for connections //scan the Keyboard matrix looking for connections
previousLeftHandState = leftHandState; previousLeftHandState = leftHandState;
previousRightHandState = rightHandState; previousRightHandState = rightHandState;
if (Model01Hands::leftHand.readKeys()) { if (Model01Hands::leftHand.readKeys()) {
@ -180,12 +180,12 @@ void Model01KeyScanner::actOnHalfRow(uint8_t row, uint8_t colState, uint8_t colP
for (uint8_t col = 0; col < 8; col++) { for (uint8_t col = 0; col < 8; col++) {
// Build up the key state for row, col // Build up the key state for row, col
uint8_t keyState = ((bitRead(colPrevState, 0) << 0) | uint8_t keyState = ((bitRead(colPrevState, 0) << 0) |
(bitRead(colState, 0) << 1)); (bitRead(colState, 0) << 1));
if (keyState) if (keyState)
ThisType::handleKeyswitchEvent(Key_NoKey, KeyAddr(row, startPos - col), keyState); ThisType::handleKeyswitchEvent(Key_NoKey, KeyAddr(row, startPos - col), keyState);
// Throw away the data we've just used, so we can read the next column // Throw away the data we've just used, so we can read the next column
colState = colState >> 1; colState = colState >> 1;
colPrevState = colPrevState >> 1; colPrevState = colPrevState >> 1;
} }
} }
@ -243,7 +243,7 @@ void Model01::setup() {
Model01Hands::setup(); Model01Hands::setup();
kaleidoscope::device::Base<Model01Props>::setup(); kaleidoscope::device::Base<Model01Props>::setup();
TWBR = 12; // This is 400mhz, which is the fastest we can drive the ATTiny TWBR = 12; // This is 400mhz, which is the fastest we can drive the ATTiny
} }
void Model01::enableHardwareTestMode() { void Model01::enableHardwareTestMode() {

@ -22,15 +22,16 @@
#ifdef ARDUINO_AVR_MODEL01 #ifdef ARDUINO_AVR_MODEL01
// System headers // System headers
#include <stdint.h> // for uint8_t #include <stdint.h> // for uint8_t
// Arduino headers // Arduino headers
#include <Arduino.h> // for PROGMEM #include <Arduino.h> // for PROGMEM
// Kaleidoscope headers // Kaleidoscope headers
#include "kaleidoscope/MatrixAddr.h" // for MatrixAddr #include "kaleidoscope/MatrixAddr.h" // for MatrixAddr
#include "kaleidoscope/macro_helpers.h" // for RESTRICT_AR... #include "kaleidoscope/macro_helpers.h" // for RESTRICT_AR...
#define CRGB(r,g,b) (cRGB){b, g, r} #define CRGB(r, g, b) \
(cRGB) { b, g, r }
struct cRGB { struct cRGB {
uint8_t b; uint8_t b;
@ -44,19 +45,21 @@ struct cRGB {
#include "kaleidoscope/driver/led/Base.h" // for BaseProps #include "kaleidoscope/driver/led/Base.h" // for BaseProps
// Kaleidoscope-Hardware-Keyboardio-Model01 headers // Kaleidoscope-Hardware-Keyboardio-Model01 headers
#include "kaleidoscope/driver/keyboardio/Model01Side.h" // for keydata_t #include "kaleidoscope/driver/keyboardio/Model01Side.h" // for keydata_t
namespace kaleidoscope { namespace kaleidoscope {
namespace device { namespace device {
namespace keyboardio { namespace keyboardio {
struct Model01LEDDriverProps : public kaleidoscope::driver::led::BaseProps { struct Model01LEDDriverProps : public kaleidoscope::driver::led::BaseProps {
static constexpr uint8_t led_count = 64; static constexpr uint8_t led_count = 64;
static constexpr uint8_t key_led_map[] PROGMEM = { static constexpr uint8_t key_led_map[] PROGMEM = {
// clang-format off
3, 4, 11, 12, 19, 20, 26, 27, 36, 37, 43, 44, 51, 52, 59, 60, 3, 4, 11, 12, 19, 20, 26, 27, 36, 37, 43, 44, 51, 52, 59, 60,
2, 5, 10, 13, 18, 21, 25, 28, 35, 38, 42, 45, 50, 53, 58, 61, 2, 5, 10, 13, 18, 21, 25, 28, 35, 38, 42, 45, 50, 53, 58, 61,
1, 6, 9, 14, 17, 22, 24, 29, 34, 39, 41, 46, 49, 54, 57, 62, 1, 6, 9, 14, 17, 22, 24, 29, 34, 39, 41, 46, 49, 54, 57, 62,
0, 7, 8, 15, 16, 23, 31, 30, 33, 32, 40, 47, 48, 55, 56, 63, 0, 7, 8, 15, 16, 23, 31, 30, 33, 32, 40, 47, 48, 55, 56, 63,
// clang-format on
}; };
}; };
@ -75,12 +78,12 @@ class Model01LEDDriver : public kaleidoscope::driver::led::Base<Model01LEDDriver
private: private:
static bool isLEDChanged; static bool isLEDChanged;
}; };
#else // ifndef KALEIDOSCOPE_VIRTUAL_BUILD #else // ifndef KALEIDOSCOPE_VIRTUAL_BUILD
class Model01LEDDriver; class Model01LEDDriver;
#endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD #endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD
struct Model01KeyScannerProps : public kaleidoscope::driver::keyscanner::BaseProps { struct Model01KeyScannerProps : public kaleidoscope::driver::keyscanner::BaseProps {
static constexpr uint8_t matrix_rows = 4; static constexpr uint8_t matrix_rows = 4;
static constexpr uint8_t matrix_columns = 16; static constexpr uint8_t matrix_columns = 16;
typedef MatrixAddr<matrix_rows, matrix_columns> KeyAddr; typedef MatrixAddr<matrix_rows, matrix_columns> KeyAddr;
}; };
@ -89,6 +92,7 @@ struct Model01KeyScannerProps : public kaleidoscope::driver::keyscanner::BasePro
class Model01KeyScanner : public kaleidoscope::driver::keyscanner::Base<Model01KeyScannerProps> { class Model01KeyScanner : public kaleidoscope::driver::keyscanner::Base<Model01KeyScannerProps> {
private: private:
typedef Model01KeyScanner ThisType; typedef Model01KeyScanner ThisType;
public: public:
static void setup(); static void setup();
static void scanMatrix(); static void scanMatrix();
@ -112,12 +116,12 @@ class Model01KeyScanner : public kaleidoscope::driver::keyscanner::Base<Model01K
static void actOnHalfRow(byte row, byte colState, byte colPrevState, byte startPos); static void actOnHalfRow(byte row, byte colState, byte colPrevState, byte startPos);
static void enableScannerPower(); static void enableScannerPower();
}; };
#else // ifndef KALEIDOSCOPE_VIRTUAL_BUILD #else // ifndef KALEIDOSCOPE_VIRTUAL_BUILD
class Model01KeyScanner; class Model01KeyScanner;
#endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD #endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD
struct Model01Props : public kaleidoscope::device::ATmega32U4KeyboardProps { struct Model01Props : public kaleidoscope::device::ATmega32U4KeyboardProps {
typedef Model01LEDDriverProps LEDDriverProps; typedef Model01LEDDriverProps LEDDriverProps;
typedef Model01LEDDriver LEDDriver; typedef Model01LEDDriver LEDDriver;
typedef Model01KeyScannerProps KeyScannerProps; typedef Model01KeyScannerProps KeyScannerProps;
typedef Model01KeyScanner KeyScanner; typedef Model01KeyScanner KeyScanner;
@ -134,15 +138,17 @@ class Model01 : public kaleidoscope::device::ATmega32U4Keyboard<Model01Props> {
static void enableHardwareTestMode(); static void enableHardwareTestMode();
}; };
#endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD #endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD
} // namespace keyboardio } // namespace keyboardio
} // namespace device } // namespace device
EXPORT_DEVICE(kaleidoscope::device::keyboardio::Model01) EXPORT_DEVICE(kaleidoscope::device::keyboardio::Model01)
} // namespace kaleidoscope } // namespace kaleidoscope
// clang-format off
#define PER_KEY_DATA_STACKED(dflt, \ #define PER_KEY_DATA_STACKED(dflt, \
r0c0, r0c1, r0c2, r0c3, r0c4, r0c5, r0c6, \ r0c0, r0c1, r0c2, r0c3, r0c4, r0c5, r0c6, \
r1c0, r1c1, r1c2, r1c3, r1c4, r1c5, r1c6, \ r1c0, r1c1, r1c2, r1c3, r1c4, r1c5, r1c6, \

@ -44,14 +44,14 @@ void twi_init(void);
void twi_disable(void); void twi_disable(void);
void twi_setAddress(uint8_t); void twi_setAddress(uint8_t);
void twi_setFrequency(uint32_t); void twi_setFrequency(uint32_t);
uint8_t twi_readFrom(uint8_t, uint8_t*, uint8_t, uint8_t); uint8_t twi_readFrom(uint8_t, uint8_t *, uint8_t, uint8_t);
uint8_t twi_writeTo(uint8_t, uint8_t*, uint8_t, uint8_t, uint8_t); uint8_t twi_writeTo(uint8_t, uint8_t *, uint8_t, uint8_t, uint8_t);
uint8_t twi_transmit(const uint8_t*, uint8_t); uint8_t twi_transmit(const uint8_t *, uint8_t);
void twi_attachSlaveRxEvent(void (*)(uint8_t*, int)); void twi_attachSlaveRxEvent(void (*)(uint8_t *, int));
void twi_attachSlaveTxEvent(void (*)(void)); void twi_attachSlaveTxEvent(void (*)(void));
void twi_reply(uint8_t); void twi_reply(uint8_t);
void twi_stop(void); void twi_stop(void);
void twi_releaseBus(void); void twi_releaseBus(void);
#endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD #endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD
#endif #endif

@ -40,7 +40,7 @@ namespace driver {
namespace keyboardio { namespace keyboardio {
#define SCANNER_I2C_ADDR_BASE 0x58 #define SCANNER_I2C_ADDR_BASE 0x58
#define ELEMENTS(arr) (sizeof(arr) / sizeof((arr)[0])) #define ELEMENTS(arr) (sizeof(arr) / sizeof((arr)[0]))
uint8_t twi_uninitialized = 1; uint8_t twi_uninitialized = 1;
@ -82,8 +82,6 @@ uint8_t Model01Side::setKeyscanInterval(uint8_t delay) {
} }
// returns -1 on error, otherwise returns the scanner version integer // returns -1 on error, otherwise returns the scanner version integer
int Model01Side::readVersion() { int Model01Side::readVersion() {
return readRegister(TWI_CMD_VERSION); return readRegister(TWI_CMD_VERSION);
@ -113,7 +111,6 @@ uint8_t Model01Side::setLEDSPIFrequency(uint8_t frequency) {
} }
int Model01Side::readRegister(uint8_t cmd) { int Model01Side::readRegister(uint8_t cmd) {
uint8_t return_value = 0; uint8_t return_value = 0;
@ -122,8 +119,7 @@ int Model01Side::readRegister(uint8_t cmd) {
uint8_t result = twi_writeTo(addr, data, ELEMENTS(data), 1, 0); uint8_t result = twi_writeTo(addr, data, ELEMENTS(data), 1, 0);
delayMicroseconds(15); // We may be able to drop this in the future
delayMicroseconds(15); // We may be able to drop this in the future
// but will need to verify with correctly // but will need to verify with correctly
// sized pull-ups on both the left and right // sized pull-ups on both the left and right
// hands' i2c SDA and SCL lines // hands' i2c SDA and SCL lines
@ -137,7 +133,6 @@ int Model01Side::readRegister(uint8_t cmd) {
} else { } else {
return -1; return -1;
} }
} }
@ -174,8 +169,8 @@ auto constexpr gamma8 = kaleidoscope::driver::color::gamma_correction;
void Model01Side::sendLEDBank(uint8_t bank) { void Model01Side::sendLEDBank(uint8_t bank) {
uint8_t data[LED_BYTES_PER_BANK + 1]; uint8_t data[LED_BYTES_PER_BANK + 1];
data[0] = TWI_CMD_LED_BASE + bank; data[0] = TWI_CMD_LED_BASE + bank;
for (uint8_t i = 0 ; i < LED_BYTES_PER_BANK; i++) { for (uint8_t i = 0; i < LED_BYTES_PER_BANK; i++) {
/* While the ATTiny controller does have a global brightness command, it is /* While the ATTiny controller does have a global brightness command, it is
* limited to 32 levels, and those aren't nicely spread out either. For this * limited to 32 levels, and those aren't nicely spread out either. For this
* reason, we're doing our own brightness adjustment on this side, because * reason, we're doing our own brightness adjustment on this side, because
@ -195,8 +190,7 @@ void Model01Side::setAllLEDsTo(cRGB color) {
uint8_t data[] = {TWI_CMD_LED_SET_ALL_TO, uint8_t data[] = {TWI_CMD_LED_SET_ALL_TO,
pgm_read_byte(&gamma8[color.b]), pgm_read_byte(&gamma8[color.b]),
pgm_read_byte(&gamma8[color.g]), pgm_read_byte(&gamma8[color.g]),
pgm_read_byte(&gamma8[color.r]) pgm_read_byte(&gamma8[color.r])};
};
uint8_t result = twi_writeTo(addr, data, ELEMENTS(data), 1, 0); uint8_t result = twi_writeTo(addr, data, ELEMENTS(data), 1, 0);
} }
@ -205,14 +199,12 @@ void Model01Side::setOneLEDTo(uint8_t led, cRGB color) {
led, led,
pgm_read_byte(&gamma8[color.b]), pgm_read_byte(&gamma8[color.b]),
pgm_read_byte(&gamma8[color.g]), pgm_read_byte(&gamma8[color.g]),
pgm_read_byte(&gamma8[color.r]) pgm_read_byte(&gamma8[color.r])};
};
uint8_t result = twi_writeTo(addr, data, ELEMENTS(data), 1, 0); uint8_t result = twi_writeTo(addr, data, ELEMENTS(data), 1, 0);
} }
} // namespace keyboardio } // namespace keyboardio
} // namespace driver } // namespace driver
} // namespace kaleidoscope } // namespace kaleidoscope
#endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD #endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD

@ -34,13 +34,14 @@ struct cRGB {
uint8_t g; uint8_t g;
uint8_t r; uint8_t r;
}; };
#define CRGB(r,g,b) (cRGB){b, g, r} #define CRGB(r, g, b) \
(cRGB) { b, g, r }
#endif #endif
#define LED_BANKS 4 #define LED_BANKS 4
#define LEDS_PER_HAND 32 #define LEDS_PER_HAND 32
#define LED_BYTES_PER_BANK sizeof(cRGB) * LEDS_PER_HAND/LED_BANKS #define LED_BYTES_PER_BANK sizeof(cRGB) * LEDS_PER_HAND / LED_BANKS
namespace kaleidoscope { namespace kaleidoscope {
namespace driver { namespace driver {
@ -97,8 +98,8 @@ class Model01Side {
void sendLEDBank(uint8_t bank); void sendLEDBank(uint8_t bank);
int readRegister(uint8_t cmd); int readRegister(uint8_t cmd);
}; };
#endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD #endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD
} // namespace keyboardio } // namespace keyboardio
} // namespace driver } // namespace driver
} // namespace kaleidoscope } // namespace kaleidoscope

@ -22,22 +22,22 @@
#pragma once #pragma once
#define TWI_CMD_NONE 0x00 #define TWI_CMD_NONE 0x00
#define TWI_CMD_VERSION 0x01 #define TWI_CMD_VERSION 0x01
#define TWI_CMD_KEYSCAN_INTERVAL 0x02 #define TWI_CMD_KEYSCAN_INTERVAL 0x02
#define TWI_CMD_LED_SET_ALL_TO 0x03 #define TWI_CMD_LED_SET_ALL_TO 0x03
#define TWI_CMD_LED_SET_ONE_TO 0x04 #define TWI_CMD_LED_SET_ONE_TO 0x04
#define TWI_CMD_COLS_USE_PULLUPS 0x05 #define TWI_CMD_COLS_USE_PULLUPS 0x05
#define TWI_CMD_LED_SPI_FREQUENCY 0x06 #define TWI_CMD_LED_SPI_FREQUENCY 0x06
#define LED_SPI_FREQUENCY_4MHZ 0x07 #define LED_SPI_FREQUENCY_4MHZ 0x07
#define LED_SPI_FREQUENCY_2MHZ 0x06 #define LED_SPI_FREQUENCY_2MHZ 0x06
#define LED_SPI_FREQUENCY_1MHZ 0x05 #define LED_SPI_FREQUENCY_1MHZ 0x05
#define LED_SPI_FREQUENCY_512KHZ 0x04 #define LED_SPI_FREQUENCY_512KHZ 0x04
#define LED_SPI_FREQUENCY_256KHZ 0x03 #define LED_SPI_FREQUENCY_256KHZ 0x03
#define LED_SPI_FREQUENCY_128KHZ 0x02 #define LED_SPI_FREQUENCY_128KHZ 0x02
#define LED_SPI_FREQUENCY_64KHZ 0x01 #define LED_SPI_FREQUENCY_64KHZ 0x01
#define LED_SPI_OFF 0x00 #define LED_SPI_OFF 0x00
// 512KHZ seems to be the sweet spot in early testing // 512KHZ seems to be the sweet spot in early testing
@ -45,7 +45,7 @@
#define LED_SPI_FREQUENCY_DEFAULT LED_SPI_FREQUENCY_512KHZ #define LED_SPI_FREQUENCY_DEFAULT LED_SPI_FREQUENCY_512KHZ
#define TWI_CMD_LED_BASE 0x80 #define TWI_CMD_LED_BASE 0x80
#define TWI_REPLY_NONE 0x00 #define TWI_REPLY_NONE 0x00
#define TWI_REPLY_KEYDATA 0x01 #define TWI_REPLY_KEYDATA 0x01

@ -19,8 +19,8 @@
#include "kaleidoscope/device/keyboardio/Model100.h" #include "kaleidoscope/device/keyboardio/Model100.h"
#include <Arduino.h> // for PROGMEM #include <Arduino.h> // for PROGMEM
#include <Wire.h> // for Wire #include <Wire.h> // for Wire
#include "kaleidoscope/driver/keyscanner/Base_Impl.h" // For Base<> #include "kaleidoscope/driver/keyscanner/Base_Impl.h" // For Base<>
@ -48,7 +48,6 @@ void Model100Hands::setup(void) {
Model100KeyScanner::enableScannerPower(); Model100KeyScanner::enableScannerPower();
Wire.begin(); Wire.begin();
Wire.setClock(400000); Wire.setClock(400000);
} }
/********* LED Driver *********/ /********* LED Driver *********/
@ -125,9 +124,9 @@ driver::keyboardio::keydata_t Model100KeyScanner::previousLeftHandState;
driver::keyboardio::keydata_t Model100KeyScanner::previousRightHandState; driver::keyboardio::keydata_t Model100KeyScanner::previousRightHandState;
void Model100KeyScanner::enableScannerPower(void) { void Model100KeyScanner::enableScannerPower(void) {
// Turn on the switched 5V network. // Turn on the switched 5V network.
// make sure this happens at least 100ms after USB connect // make sure this happens at least 100ms after USB connect
// to satisfy inrush limits // to satisfy inrush limits
// //
pinMode(PB9, OUTPUT_OPEN_DRAIN); pinMode(PB9, OUTPUT_OPEN_DRAIN);
digitalWrite(PB9, LOW); digitalWrite(PB9, LOW);
@ -141,7 +140,6 @@ void Model100KeyScanner::disableScannerPower(void) {
} }
void Model100KeyScanner::setup() { void Model100KeyScanner::setup() {
enableScannerPower(); enableScannerPower();
delay(250); delay(250);
@ -149,7 +147,7 @@ void Model100KeyScanner::setup() {
void Model100KeyScanner::readMatrix() { void Model100KeyScanner::readMatrix() {
//scan the Keyboard matrix looking for connections //scan the Keyboard matrix looking for connections
previousLeftHandState = leftHandState; previousLeftHandState = leftHandState;
previousRightHandState = rightHandState; previousRightHandState = rightHandState;
if (Model100Hands::leftHand.readKeys()) { if (Model100Hands::leftHand.readKeys()) {
@ -166,12 +164,12 @@ void Model100KeyScanner::actOnHalfRow(uint8_t row, uint8_t colState, uint8_t col
for (uint8_t col = 0; col < 8; col++) { for (uint8_t col = 0; col < 8; col++) {
// Build up the key state for row, col // Build up the key state for row, col
uint8_t keyState = ((bitRead(colPrevState, 0) << 0) | uint8_t keyState = ((bitRead(colPrevState, 0) << 0) |
(bitRead(colState, 0) << 1)); (bitRead(colState, 0) << 1));
if (keyState) if (keyState)
ThisType::handleKeyswitchEvent(Key_NoKey, KeyAddr(row, startPos - col), keyState); ThisType::handleKeyswitchEvent(Key_NoKey, KeyAddr(row, startPos - col), keyState);
// Throw away the data we've just used, so we can read the next column // Throw away the data we've just used, so we can read the next column
colState = colState >> 1; colState = colState >> 1;
colPrevState = colPrevState >> 1; colPrevState = colPrevState >> 1;
} }
} }

@ -25,7 +25,8 @@
#include <Arduino.h> #include <Arduino.h>
#define CRGB(r,g,b) (cRGB){b, g, r} #define CRGB(r, g, b) \
(cRGB) { b, g, r }
struct cRGB { struct cRGB {
uint8_t b; uint8_t b;
@ -47,18 +48,20 @@ namespace kaleidoscope {
namespace device { namespace device {
namespace keyboardio { namespace keyboardio {
struct Model100StorageProps: public kaleidoscope::driver::storage::GD32FlashProps { struct Model100StorageProps : public kaleidoscope::driver::storage::GD32FlashProps {
static constexpr uint16_t length = EEPROM_EMULATION_SIZE; static constexpr uint16_t length = EEPROM_EMULATION_SIZE;
}; };
struct Model100LEDDriverProps : public kaleidoscope::driver::led::BaseProps { struct Model100LEDDriverProps : public kaleidoscope::driver::led::BaseProps {
static constexpr uint8_t led_count = 64; static constexpr uint8_t led_count = 64;
static constexpr uint8_t key_led_map[] PROGMEM = { static constexpr uint8_t key_led_map[] PROGMEM = {
// clang-format off
3, 4, 11, 12, 19, 20, 26, 27, 36, 37, 43, 44, 51, 52, 59, 60, 3, 4, 11, 12, 19, 20, 26, 27, 36, 37, 43, 44, 51, 52, 59, 60,
2, 5, 10, 13, 18, 21, 25, 28, 35, 38, 42, 45, 50, 53, 58, 61, 2, 5, 10, 13, 18, 21, 25, 28, 35, 38, 42, 45, 50, 53, 58, 61,
1, 6, 9, 14, 17, 22, 24, 29, 34, 39, 41, 46, 49, 54, 57, 62, 1, 6, 9, 14, 17, 22, 24, 29, 34, 39, 41, 46, 49, 54, 57, 62,
0, 7, 8, 15, 16, 23, 31, 30, 33, 32, 40, 47, 48, 55, 56, 63, 0, 7, 8, 15, 16, 23, 31, 30, 33, 32, 40, 47, 48, 55, 56, 63,
// clang-format on
}; };
}; };
@ -76,12 +79,12 @@ class Model100LEDDriver : public kaleidoscope::driver::led::Base<Model100LEDDriv
private: private:
static bool isLEDChanged; static bool isLEDChanged;
}; };
#else // ifndef KALEIDOSCOPE_VIRTUAL_BUILD #else // ifndef KALEIDOSCOPE_VIRTUAL_BUILD
class Model100LEDDriver; class Model100LEDDriver;
#endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD #endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD
struct Model100KeyScannerProps : public kaleidoscope::driver::keyscanner::BaseProps { struct Model100KeyScannerProps : public kaleidoscope::driver::keyscanner::BaseProps {
static constexpr uint8_t matrix_rows = 4; static constexpr uint8_t matrix_rows = 4;
static constexpr uint8_t matrix_columns = 16; static constexpr uint8_t matrix_columns = 16;
typedef MatrixAddr<matrix_rows, matrix_columns> KeyAddr; typedef MatrixAddr<matrix_rows, matrix_columns> KeyAddr;
}; };
@ -90,6 +93,7 @@ struct Model100KeyScannerProps : public kaleidoscope::driver::keyscanner::BasePr
class Model100KeyScanner : public kaleidoscope::driver::keyscanner::Base<Model100KeyScannerProps> { class Model100KeyScanner : public kaleidoscope::driver::keyscanner::Base<Model100KeyScannerProps> {
private: private:
typedef Model100KeyScanner ThisType; typedef Model100KeyScanner ThisType;
public: public:
static void setup(); static void setup();
static void scanMatrix(); static void scanMatrix();
@ -114,13 +118,13 @@ class Model100KeyScanner : public kaleidoscope::driver::keyscanner::Base<Model10
static void actOnHalfRow(uint8_t row, uint8_t colState, uint8_t colPrevState, uint8_t startPos); static void actOnHalfRow(uint8_t row, uint8_t colState, uint8_t colPrevState, uint8_t startPos);
}; };
#else // ifndef KALEIDOSCOPE_VIRTUAL_BUILD #else // ifndef KALEIDOSCOPE_VIRTUAL_BUILD
class Model100KeyScanner; class Model100KeyScanner;
#endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD #endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD
// If we need to override HID props: // If we need to override HID props:
struct Model100HIDProps: public kaleidoscope::driver::hid::KeyboardioProps { struct Model100HIDProps : public kaleidoscope::driver::hid::KeyboardioProps {
//typedef kaleidoscope::driver::hid::base::AbsoluteMouseProps AbsoluteMouseProps; //typedef kaleidoscope::driver::hid::base::AbsoluteMouseProps AbsoluteMouseProps;
//typedef kaleidoscope::driver::hid::base::AbsoluteMouse<AbsoluteMouseProps> AbsoluteMouse; //typedef kaleidoscope::driver::hid::base::AbsoluteMouse<AbsoluteMouseProps> AbsoluteMouse;
}; };
@ -130,7 +134,7 @@ struct Model100Props : public kaleidoscope::device::BaseProps {
typedef Model100HIDProps HIDProps; typedef Model100HIDProps HIDProps;
typedef kaleidoscope::driver::hid::Keyboardio<HIDProps> HID; typedef kaleidoscope::driver::hid::Keyboardio<HIDProps> HID;
typedef Model100LEDDriverProps LEDDriverProps; typedef Model100LEDDriverProps LEDDriverProps;
typedef Model100LEDDriver LEDDriver; typedef Model100LEDDriver LEDDriver;
typedef Model100KeyScannerProps KeyScannerProps; typedef Model100KeyScannerProps KeyScannerProps;
@ -156,15 +160,17 @@ class Model100 : public kaleidoscope::device::Base<Model100Props> {
static void enableHardwareTestMode(); static void enableHardwareTestMode();
}; };
#endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD #endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD
} // namespace keyboardio } // namespace keyboardio
} // namespace device } // namespace device
EXPORT_DEVICE(kaleidoscope::device::keyboardio::Model100) EXPORT_DEVICE(kaleidoscope::device::keyboardio::Model100)
} // namespace kaleidoscope } // namespace kaleidoscope
// clang-format off
#define PER_KEY_DATA_STACKED(dflt, \ #define PER_KEY_DATA_STACKED(dflt, \
r0c0, r0c1, r0c2, r0c3, r0c4, r0c5, r0c6, \ r0c0, r0c1, r0c2, r0c3, r0c4, r0c5, r0c6, \
r1c0, r1c1, r1c2, r1c3, r1c4, r1c5, r1c6, \ r1c0, r1c1, r1c2, r1c3, r1c4, r1c5, r1c6, \

@ -36,7 +36,7 @@ namespace driver {
namespace keyboardio { namespace keyboardio {
#define SCANNER_I2C_ADDR_BASE 0x58 #define SCANNER_I2C_ADDR_BASE 0x58
#define ELEMENTS(arr) (sizeof(arr) / sizeof((arr)[0])) #define ELEMENTS(arr) (sizeof(arr) / sizeof((arr)[0]))
uint8_t twi_uninitialized = 1; uint8_t twi_uninitialized = 1;
@ -75,8 +75,6 @@ uint8_t Model100Side::setKeyscanInterval(uint8_t delay) {
} }
// returns -1 on error, otherwise returns the scanner version integer // returns -1 on error, otherwise returns the scanner version integer
int Model100Side::readVersion() { int Model100Side::readVersion() {
return readRegister(TWI_CMD_VERSION); return readRegister(TWI_CMD_VERSION);
@ -100,7 +98,7 @@ int Model100Side::readLEDSPIFrequency() {
// https://www.arduino.cc/en/Reference/WireEndTransmission // https://www.arduino.cc/en/Reference/WireEndTransmission
uint8_t Model100Side::setLEDSPIFrequency(uint8_t frequency) { uint8_t Model100Side::setLEDSPIFrequency(uint8_t frequency) {
uint8_t data[] = {TWI_CMD_LED_SPI_FREQUENCY, frequency}; uint8_t data[] = {TWI_CMD_LED_SPI_FREQUENCY, frequency};
uint8_t result = writeData(data, ELEMENTS(data)); uint8_t result = writeData(data, ELEMENTS(data));
return result; return result;
} }
@ -134,11 +132,10 @@ bool Model100Side::isDeviceAvailable() {
// we've decremented the counter, but it's not time to probe for the device yet. // we've decremented the counter, but it's not time to probe for the device yet.
return false; return false;
} }
} }
void Model100Side::markDeviceUnavailable() { void Model100Side::markDeviceUnavailable() {
unavailable_device_check_countdown_ = 1; // We think there was a comms problem. Check on the next cycle unavailable_device_check_countdown_ = 1; // We think there was a comms problem. Check on the next cycle
} }
uint8_t Model100Side::writeData(uint8_t *data, uint8_t length) { uint8_t Model100Side::writeData(uint8_t *data, uint8_t length) {
@ -156,15 +153,15 @@ uint8_t Model100Side::writeData(uint8_t *data, uint8_t length) {
int Model100Side::readRegister(uint8_t cmd) { int Model100Side::readRegister(uint8_t cmd) {
uint8_t return_value = 0; uint8_t return_value = 0;
uint8_t data[] = {cmd}; uint8_t data[] = {cmd};
uint8_t result = writeData(data, ELEMENTS(data)); uint8_t result = writeData(data, ELEMENTS(data));
// If the setup failed, return. This means there was a problem asking for the register // If the setup failed, return. This means there was a problem asking for the register
if (result) { if (result) {
return -1; return -1;
} }
delayMicroseconds(50); // TODO We may be able to drop this in the future delayMicroseconds(50); // TODO We may be able to drop this in the future
// but will need to verify with correctly // but will need to verify with correctly
// sized pull-ups on both the left and right // sized pull-ups on both the left and right
// hands' i2c SDA and SCL lines // hands' i2c SDA and SCL lines
@ -173,14 +170,13 @@ int Model100Side::readRegister(uint8_t cmd) {
// perform blocking read into buffer // perform blocking read into buffer
Wire.requestFrom(addr, 1); // request 1 byte from the keyscanner Wire.requestFrom(addr, 1); // request 1 byte from the keyscanner
if (Wire.available()) { if (Wire.available()) {
return Wire.read(); return Wire.read();
} else { } else {
markDeviceUnavailable(); markDeviceUnavailable();
return -1; return -1;
} }
} }
@ -192,9 +188,9 @@ bool Model100Side::readKeys() {
uint8_t row_counter = 0; uint8_t row_counter = 0;
// perform blocking read into buffer // perform blocking read into buffer
uint8_t read = 0; uint8_t read = 0;
uint8_t bytes_returned = 0; uint8_t bytes_returned = 0;
bytes_returned = Wire.requestFrom(addr, 5); // request 5 bytes from the keyscanner bytes_returned = Wire.requestFrom(addr, 5); // request 5 bytes from the keyscanner
if (bytes_returned < 5) { if (bytes_returned < 5) {
return false; return false;
} }
@ -224,8 +220,8 @@ void Model100Side::sendLEDData() {
void Model100Side::sendLEDBank(uint8_t bank) { void Model100Side::sendLEDBank(uint8_t bank) {
uint8_t data[LED_BYTES_PER_BANK + 1]; uint8_t data[LED_BYTES_PER_BANK + 1];
data[0] = TWI_CMD_LED_BASE + bank; data[0] = TWI_CMD_LED_BASE + bank;
for (uint8_t i = 0 ; i < LED_BYTES_PER_BANK; i++) { for (uint8_t i = 0; i < LED_BYTES_PER_BANK; i++) {
/* While the ATTiny controller does have a global brightness command, it is /* While the ATTiny controller does have a global brightness command, it is
* limited to 32 levels, and those aren't nicely spread out either. For this * limited to 32 levels, and those aren't nicely spread out either. For this
* reason, we're doing our own brightness adjustment on this side, because * reason, we're doing our own brightness adjustment on this side, because
@ -238,16 +234,15 @@ void Model100Side::sendLEDBank(uint8_t bank) {
data[i + 1] = c; data[i + 1] = c;
} }
uint8_t result = writeData(data, ELEMENTS(data)); uint8_t result = writeData(data, ELEMENTS(data));
} }
void Model100Side::setAllLEDsTo(cRGB color) { void Model100Side::setAllLEDsTo(cRGB color) {
uint8_t data[] = {TWI_CMD_LED_SET_ALL_TO, uint8_t data[] = {TWI_CMD_LED_SET_ALL_TO,
color.b, color.b,
color.g, color.g,
color.r color.r};
}; uint8_t result = writeData(data, ELEMENTS(data));
uint8_t result = writeData(data, ELEMENTS(data));
} }
void Model100Side::setOneLEDTo(uint8_t led, cRGB color) { void Model100Side::setOneLEDTo(uint8_t led, cRGB color) {
@ -255,14 +250,12 @@ void Model100Side::setOneLEDTo(uint8_t led, cRGB color) {
led, led,
color.b, color.b,
color.g, color.g,
color.r color.r};
}; uint8_t result = writeData(data, ELEMENTS(data));
uint8_t result = writeData(data, ELEMENTS(data));
} }
} // namespace keyboardio } // namespace keyboardio
} // namespace driver } // namespace driver
} // namespace kaleidoscope } // namespace kaleidoscope
#endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD #endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD

@ -34,13 +34,14 @@ struct cRGB {
uint8_t g; uint8_t g;
uint8_t r; uint8_t r;
}; };
#define CRGB(r,g,b) (cRGB){b, g, r} #define CRGB(r, g, b) \
(cRGB) { b, g, r }
#endif #endif
#define LED_BANKS 4 #define LED_BANKS 4
#define LEDS_PER_HAND 32 #define LEDS_PER_HAND 32
#define LED_BYTES_PER_BANK sizeof(cRGB) * LEDS_PER_HAND/LED_BANKS #define LED_BYTES_PER_BANK sizeof(cRGB) * LEDS_PER_HAND / LED_BANKS
namespace kaleidoscope { namespace kaleidoscope {
namespace driver { namespace driver {
@ -98,15 +99,15 @@ class Model100Side {
keydata_t keyData; keydata_t keyData;
// a value of 0 is "device seen" - anything else is how many cycles before we should // a value of 0 is "device seen" - anything else is how many cycles before we should
// check for the device // check for the device
uint16_t unavailable_device_check_countdown_ = 0; uint16_t unavailable_device_check_countdown_ = 0;
static const uint16_t UNAVAILABLE_DEVICE_COUNTDOWN_MAX = 0x00FFU; static const uint16_t UNAVAILABLE_DEVICE_COUNTDOWN_MAX = 0x00FFU;
byte nextLEDBank = 0; byte nextLEDBank = 0;
void sendLEDBank(byte bank); void sendLEDBank(byte bank);
int readRegister(uint8_t cmd); int readRegister(uint8_t cmd);
uint8_t writeData(uint8_t* data, uint8_t length); uint8_t writeData(uint8_t *data, uint8_t length);
}; };
#endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD #endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD
} // namespace keyboardio } // namespace keyboardio
} // namespace driver } // namespace driver
} // namespace kaleidoscope } // namespace kaleidoscope

@ -22,22 +22,22 @@
#pragma once #pragma once
#define TWI_CMD_NONE 0x00 #define TWI_CMD_NONE 0x00
#define TWI_CMD_VERSION 0x01 #define TWI_CMD_VERSION 0x01
#define TWI_CMD_KEYSCAN_INTERVAL 0x02 #define TWI_CMD_KEYSCAN_INTERVAL 0x02
#define TWI_CMD_LED_SET_ALL_TO 0x03 #define TWI_CMD_LED_SET_ALL_TO 0x03
#define TWI_CMD_LED_SET_ONE_TO 0x04 #define TWI_CMD_LED_SET_ONE_TO 0x04
#define TWI_CMD_COLS_USE_PULLUPS 0x05 #define TWI_CMD_COLS_USE_PULLUPS 0x05
#define TWI_CMD_LED_SPI_FREQUENCY 0x06 #define TWI_CMD_LED_SPI_FREQUENCY 0x06
#define LED_SPI_FREQUENCY_4MHZ 0x07 #define LED_SPI_FREQUENCY_4MHZ 0x07
#define LED_SPI_FREQUENCY_2MHZ 0x06 #define LED_SPI_FREQUENCY_2MHZ 0x06
#define LED_SPI_FREQUENCY_1MHZ 0x05 #define LED_SPI_FREQUENCY_1MHZ 0x05
#define LED_SPI_FREQUENCY_512KHZ 0x04 #define LED_SPI_FREQUENCY_512KHZ 0x04
#define LED_SPI_FREQUENCY_256KHZ 0x03 #define LED_SPI_FREQUENCY_256KHZ 0x03
#define LED_SPI_FREQUENCY_128KHZ 0x02 #define LED_SPI_FREQUENCY_128KHZ 0x02
#define LED_SPI_FREQUENCY_64KHZ 0x01 #define LED_SPI_FREQUENCY_64KHZ 0x01
#define LED_SPI_OFF 0x00 #define LED_SPI_OFF 0x00
// 512KHZ seems to be the sweet spot in early testing // 512KHZ seems to be the sweet spot in early testing
@ -45,7 +45,7 @@
#define LED_SPI_FREQUENCY_DEFAULT LED_SPI_FREQUENCY_512KHZ #define LED_SPI_FREQUENCY_DEFAULT LED_SPI_FREQUENCY_512KHZ
#define TWI_CMD_LED_BASE 0x80 #define TWI_CMD_LED_BASE 0x80
#define TWI_REPLY_NONE 0x00 #define TWI_REPLY_NONE 0x00
#define TWI_REPLY_KEYDATA 0x01 #define TWI_REPLY_KEYDATA 0x01

@ -27,7 +27,7 @@
// in the global namespace within the scope of this file. We'll use these // in the global namespace within the scope of this file. We'll use these
// aliases to simplify some template initialization code below. // aliases to simplify some template initialization code below.
using KeyScannerProps = typename kaleidoscope::device::olkb::PlanckProps::KeyScannerProps; using KeyScannerProps = typename kaleidoscope::device::olkb::PlanckProps::KeyScannerProps;
using KeyScanner = typename kaleidoscope::device::olkb::PlanckProps::KeyScanner; using KeyScanner = typename kaleidoscope::device::olkb::PlanckProps::KeyScanner;
namespace kaleidoscope { namespace kaleidoscope {
namespace device { namespace device {
@ -45,7 +45,8 @@ constexpr uint8_t KeyScannerProps::matrix_col_pins[matrix_columns];
// `KeyScanner` here refers to the alias set up above, just like in the // `KeyScanner` here refers to the alias set up above, just like in the
// `KeyScannerProps` case above. // `KeyScannerProps` case above.
template<> KeyScanner::row_state_t KeyScanner::matrix_state_[KeyScannerProps::matrix_rows] = {}; template<>
KeyScanner::row_state_t KeyScanner::matrix_state_[KeyScannerProps::matrix_rows] = {};
// We set up the TIMER1 interrupt vector here. Due to dependency reasons, this // 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. // cannot be in a header-only driver, and must be placed here.
@ -59,9 +60,9 @@ ISR(TIMER1_OVF_vect) {
Runtime.device().keyScanner().do_scan_ = true; Runtime.device().keyScanner().do_scan_ = true;
} }
} // namespace olkb } // namespace olkb
} // namespace device } // namespace device
} // namespace kaleidoscope } // namespace kaleidoscope
#endif #endif
#endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD #endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD

@ -31,13 +31,13 @@ namespace olkb {
struct PlanckProps : kaleidoscope::device::ATmega32U4KeyboardProps { struct PlanckProps : kaleidoscope::device::ATmega32U4KeyboardProps {
struct KeyScannerProps : public kaleidoscope::driver::keyscanner::ATmegaProps { struct KeyScannerProps : public kaleidoscope::driver::keyscanner::ATmegaProps {
static constexpr uint8_t matrix_rows = 4; static constexpr uint8_t matrix_rows = 4;
static constexpr uint8_t matrix_columns = 12; static constexpr uint8_t matrix_columns = 12;
typedef MatrixAddr<matrix_rows, matrix_columns> KeyAddr; typedef MatrixAddr<matrix_rows, matrix_columns> KeyAddr;
#ifndef KALEIDOSCOPE_VIRTUAL_BUILD #ifndef KALEIDOSCOPE_VIRTUAL_BUILD
static constexpr uint8_t matrix_row_pins[matrix_rows] = {PIN_D0, PIN_D5, PIN_B5, PIN_B6}; 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_F0, PIN_F1, PIN_F4, PIN_F5, PIN_F6, PIN_F7, PIN_B3, PIN_B1, PIN_B0, PIN_D5, PIN_B7, PIN_C7}; static constexpr uint8_t matrix_col_pins[matrix_columns] = {PIN_F0, PIN_F1, PIN_F4, PIN_F5, PIN_F6, PIN_F7, PIN_B3, PIN_B1, PIN_B0, PIN_D5, PIN_B7, PIN_C7};
#endif // KALEIDOSCOPE_VIRTUAL_BUILD #endif // KALEIDOSCOPE_VIRTUAL_BUILD
}; };
typedef kaleidoscope::driver::keyscanner::ATmega<KeyScannerProps> KeyScanner; typedef kaleidoscope::driver::keyscanner::ATmega<KeyScannerProps> KeyScanner;
typedef kaleidoscope::driver::bootloader::avr::HalfKay Bootloader; typedef kaleidoscope::driver::bootloader::avr::HalfKay Bootloader;
@ -45,8 +45,8 @@ struct PlanckProps : kaleidoscope::device::ATmega32U4KeyboardProps {
}; };
#ifndef KALEIDOSCOPE_VIRTUAL_BUILD #ifndef KALEIDOSCOPE_VIRTUAL_BUILD
class Planck: public kaleidoscope::device::ATmega32U4Keyboard<PlanckProps> {}; class Planck : public kaleidoscope::device::ATmega32U4Keyboard<PlanckProps> {};
#else // ifndef KALEIDOSCOPE_VIRTUAL_BUILD #else // ifndef KALEIDOSCOPE_VIRTUAL_BUILD
/* Device definition omitted for virtual device builds. /* Device definition omitted for virtual device builds.
* We need to forward declare the device name, though, as there are * We need to forward declare the device name, though, as there are
* some legacy extern references to boards whose definition * some legacy extern references to boards whose definition
@ -54,8 +54,9 @@ class Planck: public kaleidoscope::device::ATmega32U4Keyboard<PlanckProps> {};
*/ */
class Planck; class Planck;
#endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD #endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD
// clang-format off
#define PER_KEY_DATA(dflt, \ #define PER_KEY_DATA(dflt, \
R0C0, R0C1, R0C2, R0C3, R0C4, R0C5, R0C6, R0C7, R0C8, R0C9, R0C10, R0C11, \ R0C0, R0C1, R0C2, R0C3, R0C4, R0C5, R0C6, R0C7, R0C8, R0C9, R0C10, R0C11, \
R1C0, R1C1, R1C2, R1C3, R1C4, R1C5, R1C6, R1C7, R1C8, R1C9, R1C10, R1C11, \ R1C0, R1C1, R1C2, R1C3, R1C4, R1C5, R1C6, R1C7, R1C8, R1C9, R1C10, R1C11, \
@ -66,6 +67,7 @@ class Planck;
R1C0, R1C1, R1C2, R1C3, R1C4, R1C5, R1C6, R1C7, R1C8, R1C9, R1C10, R1C11, \ R1C0, R1C1, R1C2, R1C3, R1C4, R1C5, R1C6, R1C7, R1C8, R1C9, R1C10, R1C11, \
R2C0, R2C1, R2C2, R2C3, R2C4, R2C5, R2C6, R2C7, R2C8, R2C9, R2C10, R2C11, \ R2C0, R2C1, R2C2, R2C3, R2C4, R2C5, R2C6, R2C7, R2C8, R2C9, R2C10, R2C11, \
R3C0, R3C1, R3C2, R3C3, R3C4, R3C5, R3C6, R3C7, R3C8, R3C9, R3C10, R3C11 R3C0, R3C1, R3C2, R3C3, R3C4, R3C5, R3C6, R3C7, R3C8, R3C9, R3C10, R3C11
// clang-format on
} // namespace olkb } // namespace olkb
} // namespace device } // namespace device

@ -34,7 +34,7 @@
// in the global namespace within the scope of this file. We'll use these // in the global namespace within the scope of this file. We'll use these
// aliases to simplify some template initialization code below. // aliases to simplify some template initialization code below.
using KeyScannerProps = typename kaleidoscope::device::softhruf::SplitographyProps::KeyScannerProps; using KeyScannerProps = typename kaleidoscope::device::softhruf::SplitographyProps::KeyScannerProps;
using KeyScanner = typename kaleidoscope::device::softhruf::SplitographyProps::KeyScanner; using KeyScanner = typename kaleidoscope::device::softhruf::SplitographyProps::KeyScanner;
namespace kaleidoscope { namespace kaleidoscope {
namespace device { namespace device {
@ -52,7 +52,8 @@ constexpr uint8_t KeyScannerProps::matrix_col_pins[matrix_columns];
// `KeyScanner` here refers to the alias set up above, just like in the // `KeyScanner` here refers to the alias set up above, just like in the
// `KeyScannerProps` case above. // `KeyScannerProps` case above.
template<> KeyScanner::row_state_t KeyScanner::matrix_state_[KeyScannerProps::matrix_rows] = {}; template<>
KeyScanner::row_state_t KeyScanner::matrix_state_[KeyScannerProps::matrix_rows] = {};
// We set up the TIMER1 interrupt vector here. Due to dependency reasons, this // 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. // cannot be in a header-only driver, and must be placed here.
@ -66,9 +67,9 @@ ISR(TIMER1_OVF_vect) {
Runtime.device().keyScanner().do_scan_ = true; Runtime.device().keyScanner().do_scan_ = true;
} }
} // namespace softhruf } // namespace softhruf
} // namespace device } // namespace device
} // namespace kaleidoscope } // namespace kaleidoscope
#endif #endif
#endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD #endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD

@ -39,18 +39,18 @@ namespace device {
namespace softhruf { namespace softhruf {
struct SplitographyProps : kaleidoscope::device::ATmega32U4KeyboardProps { struct SplitographyProps : kaleidoscope::device::ATmega32U4KeyboardProps {
struct MCUProps: kaleidoscope::driver::mcu::ATmega32U4Props { struct MCUProps : kaleidoscope::driver::mcu::ATmega32U4Props {
static constexpr bool disable_jtag = true; static constexpr bool disable_jtag = true;
}; };
typedef kaleidoscope::driver::mcu::ATmega32U4<MCUProps> MCU; typedef kaleidoscope::driver::mcu::ATmega32U4<MCUProps> MCU;
struct KeyScannerProps : public kaleidoscope::driver::keyscanner::ATmegaProps { struct KeyScannerProps : public kaleidoscope::driver::keyscanner::ATmegaProps {
static constexpr uint8_t matrix_rows = 4; static constexpr uint8_t matrix_rows = 4;
static constexpr uint8_t matrix_columns = 12; static constexpr uint8_t matrix_columns = 12;
typedef MatrixAddr<matrix_rows, matrix_columns> KeyAddr; typedef MatrixAddr<matrix_rows, matrix_columns> KeyAddr;
#ifndef KALEIDOSCOPE_VIRTUAL_BUILD #ifndef KALEIDOSCOPE_VIRTUAL_BUILD
static constexpr uint8_t matrix_row_pins[matrix_rows] = {PIN_D0, PIN_D1, PIN_D2, PIN_D3}; static constexpr uint8_t matrix_row_pins[matrix_rows] = {PIN_D0, PIN_D1, PIN_D2, PIN_D3};
static constexpr uint8_t matrix_col_pins[matrix_columns] = { PIN_F0, PIN_F1, PIN_F4, PIN_F5, PIN_F6, PIN_F7, PIN_C7, PIN_C6, PIN_B6, PIN_B5, PIN_B4, PIN_D7 }; static constexpr uint8_t matrix_col_pins[matrix_columns] = {PIN_F0, PIN_F1, PIN_F4, PIN_F5, PIN_F6, PIN_F7, PIN_C7, PIN_C6, PIN_B6, PIN_B5, PIN_B4, PIN_D7};
#endif // KALEIDOSCOPE_VIRTUAL_BUILD #endif // KALEIDOSCOPE_VIRTUAL_BUILD
}; };
typedef kaleidoscope::driver::keyscanner::ATmega<KeyScannerProps> KeyScanner; typedef kaleidoscope::driver::keyscanner::ATmega<KeyScannerProps> KeyScanner;
typedef kaleidoscope::driver::bootloader::avr::FLIP BootLoader; typedef kaleidoscope::driver::bootloader::avr::FLIP BootLoader;
@ -58,15 +58,17 @@ struct SplitographyProps : kaleidoscope::device::ATmega32U4KeyboardProps {
}; };
#ifndef KALEIDOSCOPE_VIRTUAL_BUILD #ifndef KALEIDOSCOPE_VIRTUAL_BUILD
class Splitography: public kaleidoscope::device::ATmega32U4Keyboard<SplitographyProps> {}; class Splitography : public kaleidoscope::device::ATmega32U4Keyboard<SplitographyProps> {};
#else // ifndef KALEIDOSCOPE_VIRTUAL_BUILD #else // ifndef KALEIDOSCOPE_VIRTUAL_BUILD
/* Device definition omitted for virtual device builds. /* Device definition omitted for virtual device builds.
* We need to forward declare the device name, though, as there are * We need to forward declare the device name, though, as there are
* some legacy extern references to boards whose definition * some legacy extern references to boards whose definition
* depends on this. * depends on this.
*/ */
class Splitography; class Splitography;
#endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD #endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD
// clang-format off
#define PER_KEY_DATA(dflt, \ #define PER_KEY_DATA(dflt, \
r0c0 ,r0c1 ,r0c2 ,r0c3 ,r0c4 ,r0c5 ,r0c6 ,r0c7 ,r0c8 ,r0c9 ,r0c10 ,r0c11 \ r0c0 ,r0c1 ,r0c2 ,r0c3 ,r0c4 ,r0c5 ,r0c6 ,r0c7 ,r0c8 ,r0c9 ,r0c10 ,r0c11 \
@ -96,6 +98,8 @@ class Splitography;
r2c0 ,r2c1 ,r2c2 ,r2c3 ,r2c4 ,r2c5 ,r2c6 ,r2c7 ,r2c8 ,r2c9 ,r2c10 ,r2c11, \ r2c0 ,r2c1 ,r2c2 ,r2c3 ,r2c4 ,r2c5 ,r2c6 ,r2c7 ,r2c8 ,r2c9 ,r2c10 ,r2c11, \
dflt ,dflt ,dflt ,dflt ,r3c4 ,r3c5 ,r3c6 ,r3c7 ,dflt ,dflt ,dflt ,dflt dflt ,dflt ,dflt ,dflt ,r3c4 ,r3c5 ,r3c6 ,r3c7 ,dflt ,dflt ,dflt ,dflt
// clang-format on
} // namespace softhruf } // namespace softhruf
} // namespace device } // namespace device

@ -18,7 +18,7 @@
#pragma once #pragma once
#if !defined(KALEIDOSCOPE_HARDWARE_ATREUS_PINOUT_ASTAR) && \ #if !defined(KALEIDOSCOPE_HARDWARE_ATREUS_PINOUT_ASTAR) && \
!defined(KALEIDOSCOPE_HARDWARE_ATREUS_PINOUT_ASTAR_DOWN) && \ !defined(KALEIDOSCOPE_HARDWARE_ATREUS_PINOUT_ASTAR_DOWN) && \
!defined(KALEIDOSCOPE_HARDWARE_ATREUS_PINOUT_LEGACY_TEENSY2) !defined(KALEIDOSCOPE_HARDWARE_ATREUS_PINOUT_LEGACY_TEENSY2)
#define KALEIDOSCOPE_HARDWARE_ATREUS_PINOUT_ASTAR 1 #define KALEIDOSCOPE_HARDWARE_ATREUS_PINOUT_ASTAR 1

@ -36,7 +36,7 @@
// in the global namespace within the scope of this file. We'll use these // in the global namespace within the scope of this file. We'll use these
// aliases to simplify some template initialization code below. // aliases to simplify some template initialization code below.
using KeyScannerProps = typename kaleidoscope::device::technomancy::AtreusProps::KeyScannerProps; using KeyScannerProps = typename kaleidoscope::device::technomancy::AtreusProps::KeyScannerProps;
using KeyScanner = typename kaleidoscope::device::technomancy::AtreusProps::KeyScanner; using KeyScanner = typename kaleidoscope::device::technomancy::AtreusProps::KeyScanner;
namespace kaleidoscope { namespace kaleidoscope {
@ -55,7 +55,8 @@ constexpr uint8_t KeyScannerProps::matrix_col_pins[matrix_columns];
// `KeyScanner` here refers to the alias set up above, just like in the // `KeyScanner` here refers to the alias set up above, just like in the
// `KeyScannerProps` case above. // `KeyScannerProps` case above.
template<> KeyScanner::row_state_t KeyScanner::matrix_state_[KeyScannerProps::matrix_rows] = {}; template<>
KeyScanner::row_state_t KeyScanner::matrix_state_[KeyScannerProps::matrix_rows] = {};
// We set up the TIMER1 interrupt vector here. Due to dependency reasons, this // 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. // cannot be in a header-only driver, and must be placed here.
@ -69,9 +70,9 @@ ISR(TIMER1_OVF_vect) {
Runtime.device().keyScanner().do_scan_ = true; Runtime.device().keyScanner().do_scan_ = true;
} }
} // namespace technomancy } // namespace technomancy
} // namespace device } // namespace device
} // namespace kaleidoscope } // namespace kaleidoscope
#endif #endif
#endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD #endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD

@ -40,28 +40,28 @@ namespace technomancy {
struct AtreusProps : kaleidoscope::device::ATmega32U4KeyboardProps { struct AtreusProps : kaleidoscope::device::ATmega32U4KeyboardProps {
struct KeyScannerProps : public kaleidoscope::driver::keyscanner::ATmegaProps { struct KeyScannerProps : public kaleidoscope::driver::keyscanner::ATmegaProps {
static constexpr uint8_t matrix_rows = 4; static constexpr uint8_t matrix_rows = 4;
static constexpr uint8_t matrix_columns = 12; static constexpr uint8_t matrix_columns = 12;
typedef MatrixAddr<matrix_rows, matrix_columns> KeyAddr; typedef MatrixAddr<matrix_rows, matrix_columns> KeyAddr;
#ifndef KALEIDOSCOPE_VIRTUAL_BUILD #ifndef KALEIDOSCOPE_VIRTUAL_BUILD
#ifdef KALEIDOSCOPE_HARDWARE_ATREUS_PINOUT_ASTAR #ifdef KALEIDOSCOPE_HARDWARE_ATREUS_PINOUT_ASTAR
static constexpr uint8_t matrix_row_pins[matrix_rows] = {PIN_D0, PIN_D1, PIN_D3, PIN_D2}; static constexpr uint8_t matrix_row_pins[matrix_rows] = {PIN_D0, PIN_D1, PIN_D3, PIN_D2};
static constexpr uint8_t matrix_col_pins[matrix_columns] = {PIN_D7, PIN_C6, PIN_B5, PIN_B4, PIN_E6, PIN_D4, PIN_B6, PIN_F6, PIN_F7, PIN_D6, PIN_B7}; static constexpr uint8_t matrix_col_pins[matrix_columns] = {PIN_D7, PIN_C6, PIN_B5, PIN_B4, PIN_E6, PIN_D4, PIN_B6, PIN_F6, PIN_F7, PIN_D6, PIN_B7};
#endif #endif
#ifdef KALEIDOSCOPE_HARDWARE_ATREUS_PINOUT_ASTAR_DOWN #ifdef KALEIDOSCOPE_HARDWARE_ATREUS_PINOUT_ASTAR_DOWN
static constexpr uint8_t matrix_row_pins[matrix_rows] = {PIN_D0, PIN_D1, PIN_D3, PIN_D2}; static constexpr uint8_t matrix_row_pins[matrix_rows] = {PIN_D0, PIN_D1, PIN_D3, PIN_D2};
static constexpr uint8_t matrix_col_pins[matrix_columns] = {PIN_B7, PIN_D6, PIN_F7, PIN_F6, PIN_B6, PIN_D4, PIN_E6, PIN_B4, PIN_B5, PIN_C6, PIN_D7}; static constexpr uint8_t matrix_col_pins[matrix_columns] = {PIN_B7, PIN_D6, PIN_F7, PIN_F6, PIN_B6, PIN_D4, PIN_E6, PIN_B4, PIN_B5, PIN_C6, PIN_D7};
#endif #endif
#ifdef KALEIDOSCOPE_HARDWARE_ATREUS_PINOUT_LEGACY_TEENSY2 #ifdef KALEIDOSCOPE_HARDWARE_ATREUS_PINOUT_LEGACY_TEENSY2
static constexpr uint8_t matrix_row_pins[matrix_rows] = {PIN_D0, PIN_D1, PIN_D2, PIN_D3}; static constexpr uint8_t matrix_row_pins[matrix_rows] = {PIN_D0, PIN_D1, PIN_D2, PIN_D3};
static constexpr uint8_t matrix_col_pins[matrix_columns] = {PIN_F6, PIN_F5, PIN_F4, PIN_B7, PIN_B6, PIN_B5, PIN_B4, PIN_B3, PIN_B2, PIN_B1, PIN_B0}; static constexpr uint8_t matrix_col_pins[matrix_columns] = {PIN_F6, PIN_F5, PIN_F4, PIN_B7, PIN_B6, PIN_B5, PIN_B4, PIN_B3, PIN_B2, PIN_B1, PIN_B0};
#endif #endif
#endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD #endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD
}; };
typedef kaleidoscope::driver::keyscanner::ATmega<KeyScannerProps> KeyScanner; typedef kaleidoscope::driver::keyscanner::ATmega<KeyScannerProps> KeyScanner;
@ -75,15 +75,17 @@ struct AtreusProps : kaleidoscope::device::ATmega32U4KeyboardProps {
}; };
#ifndef KALEIDOSCOPE_VIRTUAL_BUILD #ifndef KALEIDOSCOPE_VIRTUAL_BUILD
class Atreus: public kaleidoscope::device::ATmega32U4Keyboard<AtreusProps> {}; class Atreus : public kaleidoscope::device::ATmega32U4Keyboard<AtreusProps> {};
#else // ifndef KALEIDOSCOPE_VIRTUAL_BUILD #else // ifndef KALEIDOSCOPE_VIRTUAL_BUILD
/* Device definition omitted for virtual device builds. /* Device definition omitted for virtual device builds.
* We need to forward declare the device name, though, as there are * We need to forward declare the device name, though, as there are
* some legacy extern references to boards whose definition * some legacy extern references to boards whose definition
* depends on this. * depends on this.
*/ */
class Atreus; class Atreus;
#endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD #endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD
// clang-format off
#define PER_KEY_DATA(dflt, \ #define PER_KEY_DATA(dflt, \
R0C0, R0C1, R0C2, R0C3, R0C4, R0C7, R0C8, R0C9, R0C10, R0C11, \ R0C0, R0C1, R0C2, R0C3, R0C4, R0C7, R0C8, R0C9, R0C10, R0C11, \
@ -113,6 +115,8 @@ class Atreus;
R2C0, R2C1, R2C2, R2C3, R2C4, R3C5, R2C7, R2C8, R2C9, R2C10, R2C11, \ R2C0, R2C1, R2C2, R2C3, R2C4, R3C5, R2C7, R2C8, R2C9, R2C10, R2C11, \
R3C0, R3C1, R3C2, R3C3, R3C4, R3C6, R3C7, R3C8, R3C9, R3C10, R3C11 R3C0, R3C1, R3C2, R3C3, R3C4, R3C6, R3C7, R3C8, R3C9, R3C10, R3C11
// clang-format on
} // namespace technomancy } // namespace technomancy
} // namespace device } // namespace device

@ -27,7 +27,7 @@
// in the global namespace within the scope of this file. We'll use these // in the global namespace within the scope of this file. We'll use these
// aliases to simplify some template initialization code below. // aliases to simplify some template initialization code below.
using KeyScannerProps = typename kaleidoscope::device::gheavy::ButterStickProps::KeyScannerProps; using KeyScannerProps = typename kaleidoscope::device::gheavy::ButterStickProps::KeyScannerProps;
using KeyScanner = typename kaleidoscope::device::gheavy::ButterStickProps::KeyScanner; using KeyScanner = typename kaleidoscope::device::gheavy::ButterStickProps::KeyScanner;
namespace kaleidoscope { namespace kaleidoscope {
namespace device { namespace device {
@ -45,7 +45,8 @@ constexpr uint8_t KeyScannerProps::matrix_col_pins[matrix_columns];
// `KeyScanner` here refers to the alias set up above, just like in the // `KeyScanner` here refers to the alias set up above, just like in the
// `KeyScannerProps` case above. // `KeyScannerProps` case above.
template<> KeyScanner::row_state_t KeyScanner::matrix_state_[KeyScannerProps::matrix_rows] = {}; template<>
KeyScanner::row_state_t KeyScanner::matrix_state_[KeyScannerProps::matrix_rows] = {};
// We set up the TIMER1 interrupt vector here. Due to dependency reasons, this // 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. // cannot be in a header-only driver, and must be placed here.
@ -59,9 +60,9 @@ ISR(TIMER1_OVF_vect) {
Runtime.device().keyScanner().do_scan_ = true; Runtime.device().keyScanner().do_scan_ = true;
} }
} // namespace gheavy } // namespace gheavy
} // namespace device } // namespace device
} // namespace kaleidoscope } // namespace kaleidoscope
#endif #endif
#endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD #endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD

@ -33,13 +33,13 @@ namespace gheavy {
struct ButterStickProps : kaleidoscope::device::ATmega32U4KeyboardProps { struct ButterStickProps : kaleidoscope::device::ATmega32U4KeyboardProps {
struct KeyScannerProps : public kaleidoscope::driver::keyscanner::ATmegaProps { struct KeyScannerProps : public kaleidoscope::driver::keyscanner::ATmegaProps {
static constexpr uint8_t matrix_rows = 2; static constexpr uint8_t matrix_rows = 2;
static constexpr uint8_t matrix_columns = 10; static constexpr uint8_t matrix_columns = 10;
typedef MatrixAddr<matrix_rows, matrix_columns> KeyAddr; typedef MatrixAddr<matrix_rows, matrix_columns> KeyAddr;
#ifndef KALEIDOSCOPE_VIRTUAL_BUILD #ifndef KALEIDOSCOPE_VIRTUAL_BUILD
static constexpr uint8_t matrix_row_pins[matrix_rows] = { PIN_F4, PIN_F5 }; static constexpr uint8_t matrix_row_pins[matrix_rows] = {PIN_F4, PIN_F5};
static constexpr uint8_t matrix_col_pins[matrix_columns] = { PIN_B0, PIN_B1, PIN_B2, PIN_B3, PIN_B4, PIN_B5, PIN_B6, PIN_B7, PIN_C6, PIN_C7 }; static constexpr uint8_t matrix_col_pins[matrix_columns] = {PIN_B0, PIN_B1, PIN_B2, PIN_B3, PIN_B4, PIN_B5, PIN_B6, PIN_B7, PIN_C6, PIN_C7};
#endif // KALEIDOSCOPE_VIRTUAL_BUILD #endif // KALEIDOSCOPE_VIRTUAL_BUILD
}; };
typedef kaleidoscope::driver::keyscanner::ATmega<KeyScannerProps> KeyScanner; typedef kaleidoscope::driver::keyscanner::ATmega<KeyScannerProps> KeyScanner;
typedef kaleidoscope::driver::bootloader::avr::FLIP Bootloader; typedef kaleidoscope::driver::bootloader::avr::FLIP Bootloader;
@ -47,8 +47,8 @@ struct ButterStickProps : kaleidoscope::device::ATmega32U4KeyboardProps {
}; };
#ifndef KALEIDOSCOPE_VIRTUAL_BUILD #ifndef KALEIDOSCOPE_VIRTUAL_BUILD
class ButterStick: public kaleidoscope::device::ATmega32U4Keyboard<ButterStickProps> {}; class ButterStick : public kaleidoscope::device::ATmega32U4Keyboard<ButterStickProps> {};
#else // ifndef KALEIDOSCOPE_VIRTUAL_BUILD #else // ifndef KALEIDOSCOPE_VIRTUAL_BUILD
/* Device definition omitted for virtual device builds. /* Device definition omitted for virtual device builds.
* We need to forward declare the device name, though, as there are * We need to forward declare the device name, though, as there are
* some legacy extern references to boards whose definition * some legacy extern references to boards whose definition
@ -56,19 +56,22 @@ class ButterStick: public kaleidoscope::device::ATmega32U4Keyboard<ButterStickPr
*/ */
class ButterStick; class ButterStick;
#endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD #endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD
// clang-format off
#define PER_KEY_DATA(dflt, \ #define PER_KEY_DATA(dflt, \
R0C0, R0C1, R0C2, R0C3, R0C4, R0C5, R0C6, R0C7, R0C8, R0C9, \ R0C0, R0C1, R0C2, R0C3, R0C4, R0C5, R0C6, R0C7, R0C8, R0C9, \
R1C0, R1C1, R1C2, R1C3, R1C4, R1C5, R1C6, R1C7, R1C8, R1C9 \ R1C0, R1C1, R1C2, R1C3, R1C4, R1C5, R1C6, R1C7, R1C8, R1C9 \
) \ ) \
R0C9, R0C8, R0C7, R0C6, R0C5, R0C4, R0C3, R0C2, R0C1, R0C0, \ R0C9, R0C8, R0C7, R0C6, R0C5, R0C4, R0C3, R0C2, R0C1, R0C0, \
R1C9, R1C8, R1C7, R1C6, R1C5, R1C4, R1C3, R1C2, R1C1, R1C0 R1C9, R1C8, R1C7, R1C6, R1C5, R1C4, R1C3, R1C2, R1C1, R1C0
} // namespace gheavy // clang-format on
} // namespace device
} // namespace gheavy
} // namespace device
EXPORT_DEVICE(kaleidoscope::device::gheavy::ButterStick) EXPORT_DEVICE(kaleidoscope::device::gheavy::ButterStick)
} // namespace kaleidoscope } // namespace kaleidoscope
#endif #endif

@ -27,7 +27,7 @@
// in the global namespace within the scope of this file. We'll use these // in the global namespace within the scope of this file. We'll use these
// aliases to simplify some template initialization code below. // aliases to simplify some template initialization code below.
using KeyScannerProps = typename kaleidoscope::device::gheavy::FaunchPadProps::KeyScannerProps; using KeyScannerProps = typename kaleidoscope::device::gheavy::FaunchPadProps::KeyScannerProps;
using KeyScanner = typename kaleidoscope::device::gheavy::FaunchPadProps::KeyScanner; using KeyScanner = typename kaleidoscope::device::gheavy::FaunchPadProps::KeyScanner;
namespace kaleidoscope { namespace kaleidoscope {
namespace device { namespace device {
@ -45,7 +45,8 @@ constexpr uint8_t KeyScannerProps::matrix_col_pins[matrix_columns];
// `KeyScanner` here refers to the alias set up above, just like in the // `KeyScanner` here refers to the alias set up above, just like in the
// `KeyScannerProps` case above. // `KeyScannerProps` case above.
template<> KeyScanner::row_state_t KeyScanner::matrix_state_[KeyScannerProps::matrix_rows] = {}; template<>
KeyScanner::row_state_t KeyScanner::matrix_state_[KeyScannerProps::matrix_rows] = {};
// We set up the TIMER1 interrupt vector here. Due to dependency reasons, this // 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. // cannot be in a header-only driver, and must be placed here.
@ -59,9 +60,9 @@ ISR(TIMER1_OVF_vect) {
Runtime.device().keyScanner().do_scan_ = true; Runtime.device().keyScanner().do_scan_ = true;
} }
} // namespace gheavy } // namespace gheavy
} // namespace device } // namespace device
} // namespace kaleidoscope } // namespace kaleidoscope
#endif #endif
#endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD #endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD

@ -33,13 +33,13 @@ namespace gheavy {
struct FaunchPadProps : kaleidoscope::device::ATmega32U4KeyboardProps { struct FaunchPadProps : kaleidoscope::device::ATmega32U4KeyboardProps {
struct KeyScannerProps : public kaleidoscope::driver::keyscanner::ATmegaProps { struct KeyScannerProps : public kaleidoscope::driver::keyscanner::ATmegaProps {
static constexpr uint8_t matrix_rows = 2; static constexpr uint8_t matrix_rows = 2;
static constexpr uint8_t matrix_columns = 4; static constexpr uint8_t matrix_columns = 4;
typedef MatrixAddr<matrix_rows, matrix_columns> KeyAddr; typedef MatrixAddr<matrix_rows, matrix_columns> KeyAddr;
#ifndef KALEIDOSCOPE_VIRTUAL_BUILD #ifndef KALEIDOSCOPE_VIRTUAL_BUILD
static constexpr uint8_t matrix_row_pins[matrix_rows] = { PIN_F4, PIN_F5 }; static constexpr uint8_t matrix_row_pins[matrix_rows] = {PIN_F4, PIN_F5};
static constexpr uint8_t matrix_col_pins[matrix_columns] = { PIN_B3, PIN_B2, PIN_B1, PIN_B0 }; static constexpr uint8_t matrix_col_pins[matrix_columns] = {PIN_B3, PIN_B2, PIN_B1, PIN_B0};
#endif // KALEIDOSCOPE_VIRTUAL_BUILD #endif // KALEIDOSCOPE_VIRTUAL_BUILD
}; };
typedef kaleidoscope::driver::keyscanner::ATmega<KeyScannerProps> KeyScanner; typedef kaleidoscope::driver::keyscanner::ATmega<KeyScannerProps> KeyScanner;
typedef kaleidoscope::driver::bootloader::avr::FLIP Bootloader; typedef kaleidoscope::driver::bootloader::avr::FLIP Bootloader;
@ -47,8 +47,8 @@ struct FaunchPadProps : kaleidoscope::device::ATmega32U4KeyboardProps {
}; };
#ifndef KALEIDOSCOPE_VIRTUAL_BUILD #ifndef KALEIDOSCOPE_VIRTUAL_BUILD
class FaunchPad: public kaleidoscope::device::ATmega32U4Keyboard<FaunchPadProps> {}; class FaunchPad : public kaleidoscope::device::ATmega32U4Keyboard<FaunchPadProps> {};
#else // ifndef KALEIDOSCOPE_VIRTUAL_BUILD #else // ifndef KALEIDOSCOPE_VIRTUAL_BUILD
/* Device definition omitted for virtual device builds. /* Device definition omitted for virtual device builds.
* We need to forward declare the device name, though, as there are * We need to forward declare the device name, though, as there are
* some legacy extern references to boards whose definition * some legacy extern references to boards whose definition
@ -56,18 +56,21 @@ class FaunchPad: public kaleidoscope::device::ATmega32U4Keyboard<FaunchPadProps>
*/ */
class FaunchPad; class FaunchPad;
#endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD #endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD
// clang-format off
#define PER_KEY_DATA(dflt, \ #define PER_KEY_DATA(dflt, \
R0C0, R0C1, R0C2, R0C3, R0C4, R0C5, R0C6, R0C7 \ R0C0, R0C1, R0C2, R0C3, R0C4, R0C5, R0C6, R0C7 \
) \ ) \
R0C0, R0C1, R0C2, R0C3, \ R0C0, R0C1, R0C2, R0C3, \
R0C4, R0C5, R0C6, R0C7 R0C4, R0C5, R0C6, R0C7
} // namespace gheavy // clang-format on
} // namespace device
} // namespace gheavy
} // namespace device
EXPORT_DEVICE(kaleidoscope::device::gheavy::FaunchPad) EXPORT_DEVICE(kaleidoscope::device::gheavy::FaunchPad)
} // namespace kaleidoscope } // namespace kaleidoscope
#endif #endif

@ -16,7 +16,7 @@
#include "kaleidoscope/plugin/HardwareTestMode.h" #include "kaleidoscope/plugin/HardwareTestMode.h"
#include <stdint.h> // for uint8_t #include <stdint.h> // for uint8_t
#include "kaleidoscope/KeyAddr.h" // for MatrixAddr #include "kaleidoscope/KeyAddr.h" // for MatrixAddr
#include "kaleidoscope/Runtime.h" // for Runtime #include "kaleidoscope/Runtime.h" // for Runtime
@ -41,7 +41,7 @@ void HardwareTestMode::waitForKeypress() {
while (1) { while (1) {
Runtime.device().readMatrix(); Runtime.device().readMatrix();
if (Runtime.device().isKeyswitchPressed(actionKey) && if (Runtime.device().isKeyswitchPressed(actionKey) &&
! Runtime.device().wasKeyswitchPressed(actionKey)) { !Runtime.device().wasKeyswitchPressed(actionKey)) {
break; break;
} }
} }
@ -54,9 +54,9 @@ void HardwareTestMode::setLeds(cRGB color) {
} }
void HardwareTestMode::testLeds(void) { void HardwareTestMode::testLeds(void) {
constexpr cRGB red = CRGB(255, 0, 0); constexpr cRGB red = CRGB(255, 0, 0);
constexpr cRGB blue = CRGB(0, 0, 255); constexpr cRGB blue = CRGB(0, 0, 255);
constexpr cRGB green = CRGB(0, 255, 0); constexpr cRGB green = CRGB(0, 255, 0);
constexpr cRGB brightWhite = CRGB(160, 160, 160); constexpr cRGB brightWhite = CRGB(160, 160, 160);
// rainbow for 10 seconds // rainbow for 10 seconds
@ -75,18 +75,16 @@ void HardwareTestMode::testLeds(void) {
setLeds(blue); setLeds(blue);
setLeds(green); setLeds(green);
setLeds(red); setLeds(red);
} }
void HardwareTestMode::testMatrix() { void HardwareTestMode::testMatrix() {
// Reset bad keys from previous tests. // Reset bad keys from previous tests.
chatter_data state[Runtime.device().numKeys()] = {{0, 0, 0}}; chatter_data state[Runtime.device().numKeys()] = {{0, 0, 0}};
constexpr cRGB red = CRGB(201, 0, 0); constexpr cRGB red = CRGB(201, 0, 0);
constexpr cRGB blue = CRGB(0, 0, 201); constexpr cRGB blue = CRGB(0, 0, 201);
constexpr cRGB green = CRGB(0, 201, 0); constexpr cRGB green = CRGB(0, 201, 0);
constexpr cRGB yellow = CRGB(201, 100, 0); constexpr cRGB yellow = CRGB(201, 100, 0);
while (1) { while (1) {
@ -95,7 +93,7 @@ void HardwareTestMode::testMatrix() {
uint8_t keynum = key_addr.toInt(); uint8_t keynum = key_addr.toInt();
// If the key is toggled on // If the key is toggled on
if (Runtime.device().isKeyswitchPressed(key_addr) && ! Runtime.device().wasKeyswitchPressed(key_addr)) { if (Runtime.device().isKeyswitchPressed(key_addr) && !Runtime.device().wasKeyswitchPressed(key_addr)) {
// And it's too soon (in terms of cycles between changes) // And it's too soon (in terms of cycles between changes)
state[keynum].tested = 1; state[keynum].tested = 1;
if (state[keynum].cyclesSinceStateChange < CHATTER_CYCLE_LIMIT) { if (state[keynum].cyclesSinceStateChange < CHATTER_CYCLE_LIMIT) {
@ -113,7 +111,7 @@ void HardwareTestMode::testMatrix() {
Runtime.device().setCrgbAt(key_addr, red); Runtime.device().setCrgbAt(key_addr, red);
} else if (state[keynum].tested == 0) { } else if (state[keynum].tested == 0) {
Runtime.device().setCrgbAt(key_addr, yellow); Runtime.device().setCrgbAt(key_addr, yellow);
} else if (! Runtime.device().isKeyswitchPressed(key_addr)) { } else if (!Runtime.device().isKeyswitchPressed(key_addr)) {
// If the key is not currently pressed and was not just released and is not marked bad // If the key is not currently pressed and was not just released and is not marked bad
Runtime.device().setCrgbAt(key_addr, blue); Runtime.device().setCrgbAt(key_addr, blue);
} }

@ -16,7 +16,7 @@
#pragma once #pragma once
#include <stdint.h> // for uint8_t #include <stdint.h> // for uint8_t
#include "kaleidoscope/device/device.h" // for cRGB #include "kaleidoscope/device/device.h" // for cRGB
#include "kaleidoscope/plugin.h" // for Plugin #include "kaleidoscope/plugin.h" // for Plugin
@ -26,11 +26,10 @@ namespace plugin {
class HardwareTestMode : public kaleidoscope::Plugin { class HardwareTestMode : public kaleidoscope::Plugin {
public: public:
typedef struct { typedef struct {
uint8_t bad : 1, uint8_t bad : 1,
tested : 1, tested : 1,
cyclesSinceStateChange: 6; cyclesSinceStateChange : 6;
} chatter_data; } chatter_data;
static uint8_t actionKey; static uint8_t actionKey;
@ -38,6 +37,7 @@ class HardwareTestMode : public kaleidoscope::Plugin {
static void runTests(); static void runTests();
static void setActionKey(uint8_t key); static void setActionKey(uint8_t key);
private: private:
static void testLeds(); static void testLeds();
static void testMatrix(); static void testMatrix();

@ -17,8 +17,8 @@
#include "kaleidoscope/plugin/Heatmap.h" #include "kaleidoscope/plugin/Heatmap.h"
#include <Arduino.h> // for pgm_read_byte, PROGMEM #include <Arduino.h> // for pgm_read_byte, PROGMEM
#include <stdint.h> // for uint16_t, uint8_t #include <stdint.h> // for uint16_t, uint8_t
#include "kaleidoscope/KeyAddr.h" // for MatrixAddr, MatrixAdd... #include "kaleidoscope/KeyAddr.h" // for MatrixAddr, MatrixAdd...
#include "kaleidoscope/KeyEvent.h" // for KeyEvent #include "kaleidoscope/KeyEvent.h" // for KeyEvent
@ -36,19 +36,18 @@ namespace plugin {
static const cRGB heat_colors_default_[] PROGMEM = {{0, 0, 0}, {25, 255, 25}, {25, 255, 255}, {25, 25, 255}}; static const cRGB heat_colors_default_[] PROGMEM = {{0, 0, 0}, {25, 255, 25}, {25, 255, 255}, {25, 25, 255}};
// colors from cold to hot // colors from cold to hot
const cRGB *Heatmap::heat_colors = heat_colors_default_; const cRGB *Heatmap::heat_colors = heat_colors_default_;
uint8_t Heatmap::heat_colors_length = 4; uint8_t Heatmap::heat_colors_length = 4;
// number of millisecond to wait between each heatmap computation // number of millisecond to wait between each heatmap computation
uint16_t Heatmap::update_delay = 1000; uint16_t Heatmap::update_delay = 1000;
Heatmap::TransientLEDMode::TransientLEDMode(const Heatmap *parent) Heatmap::TransientLEDMode::TransientLEDMode(const Heatmap *parent)
: // store the number of times each key has been strock : // store the number of times each key has been strock
heatmap_{}, heatmap_{},
// max of heatmap_ (we divide by it so we start at 1) // max of heatmap_ (we divide by it so we start at 1)
highest_(1), highest_(1),
// last heatmap computation time // last heatmap computation time
last_heatmap_comp_time_(Runtime.millisAtCycleStart()) last_heatmap_comp_time_(Runtime.millisAtCycleStart()) {}
{}
cRGB Heatmap::TransientLEDMode::computeColor(float v) { cRGB Heatmap::TransientLEDMode::computeColor(float v) {
// compute the color corresponding to a value between 0 and 1 // compute the color corresponding to a value between 0 and 1
@ -98,7 +97,7 @@ cRGB Heatmap::TransientLEDMode::computeColor(float v) {
// static_cast<int>(5.9) → 5 // static_cast<int>(5.9) → 5
idx1 = static_cast<int>(val); idx1 = static_cast<int>(val);
idx2 = idx1 + 1; idx2 = idx1 + 1;
fb = val - static_cast<float>(idx1); fb = val - static_cast<float>(idx1);
} }
uint8_t r = static_cast<uint8_t>((pgm_read_byte(&(heat_colors[idx2].r)) - pgm_read_byte(&(heat_colors[idx1].r))) * fb + pgm_read_byte(&(heat_colors[idx1].r))); uint8_t r = static_cast<uint8_t>((pgm_read_byte(&(heat_colors[idx2].r)) - pgm_read_byte(&(heat_colors[idx1].r))) * fb + pgm_read_byte(&(heat_colors[idx1].r)));

@ -17,7 +17,7 @@
#pragma once #pragma once
#include <stdint.h> // for uint16_t #include <stdint.h> // for uint16_t
#include "kaleidoscope/KeyEvent.h" // for KeyEvent #include "kaleidoscope/KeyEvent.h" // for KeyEvent
#include "kaleidoscope/Runtime.h" // for Runtime, Run... #include "kaleidoscope/Runtime.h" // for Runtime, Run...
@ -31,8 +31,8 @@
namespace kaleidoscope { namespace kaleidoscope {
namespace plugin { namespace plugin {
class Heatmap : public Plugin, class Heatmap : public Plugin,
public LEDModeInterface, public LEDModeInterface,
public AccessTransientLEDMode { public AccessTransientLEDMode {
public: public:
Heatmap(void) {} Heatmap(void) {}
@ -48,7 +48,6 @@ class Heatmap : public Plugin,
// //
class TransientLEDMode : public LEDMode { class TransientLEDMode : public LEDMode {
public: public:
// Please note that storing the parent ptr is only required // Please note that storing the parent ptr is only required
// for those LED modes that require access to // for those LED modes that require access to
// members of their parent class. Most LED modes can do without. // members of their parent class. Most LED modes can do without.
@ -60,11 +59,9 @@ class Heatmap : public Plugin,
EventHandlerResult beforeEachCycle(); EventHandlerResult beforeEachCycle();
protected: protected:
void update() final; void update() final;
private: private:
uint16_t heatmap_[Runtime.device().numKeys()]; uint16_t heatmap_[Runtime.device().numKeys()];
uint16_t highest_; uint16_t highest_;
uint16_t last_heatmap_comp_time_; uint16_t last_heatmap_comp_time_;

@ -18,4 +18,4 @@
#pragma once #pragma once
#include "kaleidoscope/plugin/HostOS-Focus.h" // IWYU pragma: export #include "kaleidoscope/plugin/HostOS-Focus.h" // IWYU pragma: export
#include "kaleidoscope/plugin/HostOS.h" // IWYU pragma: export #include "kaleidoscope/plugin/HostOS.h" // IWYU pragma: export

@ -17,9 +17,9 @@
#include "kaleidoscope/plugin/HostOS-Focus.h" #include "kaleidoscope/plugin/HostOS-Focus.h"
#include <Arduino.h> // for PSTR, strcmp_P #include <Arduino.h> // for PSTR, strcmp_P
#include <Kaleidoscope-FocusSerial.h> // for Focus, FocusSerial #include <Kaleidoscope-FocusSerial.h> // for Focus, FocusSerial
#include <stdint.h> // for uint8_t #include <stdint.h> // for uint8_t
#include "kaleidoscope/event_handler_result.h" // for EventHandlerResult #include "kaleidoscope/event_handler_result.h" // for EventHandlerResult
#include "kaleidoscope/plugin/HostOS.h" // for HostOS, Type #include "kaleidoscope/plugin/HostOS.h" // for HostOS, Type
@ -40,7 +40,7 @@ EventHandlerResult FocusHostOSCommand::onFocusEvent(const char *command) {
} else { } else {
uint8_t new_os; uint8_t new_os;
::Focus.read(new_os); ::Focus.read(new_os);
::HostOS.os((hostos::Type) new_os); ::HostOS.os((hostos::Type)new_os);
} }
return EventHandlerResult::EVENT_CONSUMED; return EventHandlerResult::EVENT_CONSUMED;

@ -17,7 +17,7 @@
#include "kaleidoscope/plugin/HostOS.h" #include "kaleidoscope/plugin/HostOS.h"
#include <Kaleidoscope-EEPROM-Settings.h> // for EEPROMSettings #include <Kaleidoscope-EEPROM-Settings.h> // for EEPROMSettings
#include "kaleidoscope/Runtime.h" // for Runtime, Runtime_ #include "kaleidoscope/Runtime.h" // for Runtime, Runtime_
#include "kaleidoscope/device/device.h" // for VirtualProps::Storage #include "kaleidoscope/device/device.h" // for VirtualProps::Storage

@ -17,7 +17,7 @@
#pragma once #pragma once
#include <stdint.h> // for uint16_t #include <stdint.h> // for uint16_t
#include "kaleidoscope/event_handler_result.h" // for EventHandlerResult #include "kaleidoscope/event_handler_result.h" // for EventHandlerResult
#include "kaleidoscope/plugin.h" // for Plugin #include "kaleidoscope/plugin.h" // for Plugin
@ -34,7 +34,7 @@ typedef enum {
OTHER, OTHER,
UNKNOWN = 0xff, UNKNOWN = 0xff,
AUTO = UNKNOWN AUTO = UNKNOWN
} Type; } Type;
} }

@ -18,7 +18,7 @@
#include "kaleidoscope/plugin/HostPowerManagement.h" #include "kaleidoscope/plugin/HostPowerManagement.h"
#include <Arduino.h> // IWYU pragma: keep #include <Arduino.h> // IWYU pragma: keep
#include <stdint.h> // for uint8_t #include <stdint.h> // for uint8_t
#include "kaleidoscope/event_handler_result.h" // for EventHandlerResult #include "kaleidoscope/event_handler_result.h" // for EventHandlerResult
@ -29,7 +29,7 @@ extern uint8_t _usbSuspendState;
namespace kaleidoscope { namespace kaleidoscope {
namespace plugin { namespace plugin {
bool HostPowerManagement::was_suspended_ = false; bool HostPowerManagement::was_suspended_ = false;
bool HostPowerManagement::initial_suspend_ = true; bool HostPowerManagement::initial_suspend_ = true;
EventHandlerResult HostPowerManagement::beforeEachCycle() { EventHandlerResult HostPowerManagement::beforeEachCycle() {

@ -18,10 +18,10 @@
#include "kaleidoscope/plugin/IdleLEDs.h" #include "kaleidoscope/plugin/IdleLEDs.h"
#include <Arduino.h> // for F, PSTR, __FlashStrin... #include <Arduino.h> // for F, PSTR, __FlashStrin...
#include <Kaleidoscope-EEPROM-Settings.h> // for EEPROMSettings #include <Kaleidoscope-EEPROM-Settings.h> // for EEPROMSettings
#include <Kaleidoscope-FocusSerial.h> // for Focus, FocusSerial #include <Kaleidoscope-FocusSerial.h> // for Focus, FocusSerial
#include <stdint.h> // for uint32_t, uint16_t #include <stdint.h> // for uint32_t, uint16_t
#include "kaleidoscope/KeyEvent.h" // for KeyEvent #include "kaleidoscope/KeyEvent.h" // for KeyEvent
#include "kaleidoscope/Runtime.h" // for Runtime, Runtime_ #include "kaleidoscope/Runtime.h" // for Runtime, Runtime_
@ -32,7 +32,7 @@
namespace kaleidoscope { namespace kaleidoscope {
namespace plugin { namespace plugin {
uint32_t IdleLEDs::idle_time_limit = 600000; // 10 minutes uint32_t IdleLEDs::idle_time_limit = 600000; // 10 minutes
uint32_t IdleLEDs::start_time_ = 0; uint32_t IdleLEDs::start_time_ = 0;
bool IdleLEDs::idle_; bool IdleLEDs::idle_;

@ -18,7 +18,7 @@
#pragma once #pragma once
#include <stdint.h> // for uint32_t, uint16_t #include <stdint.h> // for uint32_t, uint16_t
#include "kaleidoscope/KeyEvent.h" // for KeyEvent #include "kaleidoscope/KeyEvent.h" // for KeyEvent
#include "kaleidoscope/event_handler_result.h" // for EventHandlerResult #include "kaleidoscope/event_handler_result.h" // for EventHandlerResult
@ -27,7 +27,7 @@
namespace kaleidoscope { namespace kaleidoscope {
namespace plugin { namespace plugin {
class IdleLEDs: public kaleidoscope::Plugin { class IdleLEDs : public kaleidoscope::Plugin {
public: public:
IdleLEDs(void) {} IdleLEDs(void) {}
@ -51,6 +51,7 @@ class PersistentIdleLEDs : public IdleLEDs {
EventHandlerResult onFocusEvent(const char *command); EventHandlerResult onFocusEvent(const char *command);
static void setIdleTimeoutSeconds(uint32_t new_limit); static void setIdleTimeoutSeconds(uint32_t new_limit);
private: private:
static uint16_t settings_base_; static uint16_t settings_base_;
}; };

@ -17,8 +17,8 @@
#include "kaleidoscope/plugin/LED-ActiveLayerColor.h" #include "kaleidoscope/plugin/LED-ActiveLayerColor.h"
#include <Arduino.h> // for pgm_read_byte #include <Arduino.h> // for pgm_read_byte
#include <stdint.h> // for uint8_t #include <stdint.h> // for uint8_t
#include "kaleidoscope/KeyAddr.h" // for KeyAddr #include "kaleidoscope/KeyAddr.h" // for KeyAddr
#include "kaleidoscope/Runtime.h" // for Runtime, Runtime_ #include "kaleidoscope/Runtime.h" // for Runtime, Runtime_
@ -34,8 +34,7 @@ const cRGB *LEDActiveLayerColorEffect::colormap_;
LEDActiveLayerColorEffect::TransientLEDMode::TransientLEDMode( LEDActiveLayerColorEffect::TransientLEDMode::TransientLEDMode(
const LEDActiveLayerColorEffect *parent) const LEDActiveLayerColorEffect *parent)
: parent_(parent), : parent_(parent),
active_color_{0, 0, 0} active_color_{0, 0, 0} {}
{}
void LEDActiveLayerColorEffect::setColormap(const cRGB colormap[]) { void LEDActiveLayerColorEffect::setColormap(const cRGB colormap[]) {
colormap_ = colormap; colormap_ = colormap;

@ -28,8 +28,8 @@
namespace kaleidoscope { namespace kaleidoscope {
namespace plugin { namespace plugin {
class LEDActiveLayerColorEffect : public Plugin, class LEDActiveLayerColorEffect : public Plugin,
public LEDModeInterface, public LEDModeInterface,
public AccessTransientLEDMode { public AccessTransientLEDMode {
public: public:
LEDActiveLayerColorEffect(void) {} LEDActiveLayerColorEffect(void) {}
@ -40,7 +40,6 @@ class LEDActiveLayerColorEffect : public Plugin,
// //
class TransientLEDMode : public LEDMode { class TransientLEDMode : public LEDMode {
public: public:
// Please note that storing the parent ptr is only required // Please note that storing the parent ptr is only required
// for those LED modes that require access to // for those LED modes that require access to
// members of their parent class. Most LED modes can do without. // members of their parent class. Most LED modes can do without.
@ -48,12 +47,10 @@ class LEDActiveLayerColorEffect : public Plugin,
explicit TransientLEDMode(const LEDActiveLayerColorEffect *parent); explicit TransientLEDMode(const LEDActiveLayerColorEffect *parent);
protected: protected:
void onActivate(void) final; void onActivate(void) final;
void refreshAt(KeyAddr key_addr) final; void refreshAt(KeyAddr key_addr) final;
private: private:
const LEDActiveLayerColorEffect *parent_; const LEDActiveLayerColorEffect *parent_;
cRGB active_color_; cRGB active_color_;
@ -64,7 +61,6 @@ class LEDActiveLayerColorEffect : public Plugin,
}; };
private: private:
static const cRGB *colormap_; static const cRGB *colormap_;
}; };

@ -17,8 +17,8 @@
#include "kaleidoscope/plugin/LED-ActiveModColor.h" #include "kaleidoscope/plugin/LED-ActiveModColor.h"
#include <Kaleidoscope-OneShot.h> // for OneShot #include <Kaleidoscope-OneShot.h> // for OneShot
#include <Kaleidoscope-OneShotMetaKeys.h> // for OneShot_ActiveStickyKey #include <Kaleidoscope-OneShotMetaKeys.h> // for OneShot_ActiveStickyKey
#include "kaleidoscope/KeyAddr.h" // for KeyAddr, MatrixAddr #include "kaleidoscope/KeyAddr.h" // for KeyAddr, MatrixAddr
#include "kaleidoscope/KeyAddrBitfield.h" // for KeyAddrBitfield, KeyA... #include "kaleidoscope/KeyAddrBitfield.h" // for KeyAddrBitfield, KeyA...
@ -37,14 +37,14 @@ KeyAddrBitfield ActiveModColorEffect::mod_key_bits_;
bool ActiveModColorEffect::highlight_normal_modifiers_ = true; bool ActiveModColorEffect::highlight_normal_modifiers_ = true;
cRGB ActiveModColorEffect::highlight_color_ = CRGB(160, 160, 160); cRGB ActiveModColorEffect::highlight_color_ = CRGB(160, 160, 160);
cRGB ActiveModColorEffect::oneshot_color_ = CRGB(160, 160, 0); cRGB ActiveModColorEffect::oneshot_color_ = CRGB(160, 160, 0);
cRGB ActiveModColorEffect::sticky_color_ = CRGB(160, 0, 0); cRGB ActiveModColorEffect::sticky_color_ = CRGB(160, 0, 0);
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
EventHandlerResult ActiveModColorEffect::onKeyEvent(KeyEvent &event) { EventHandlerResult ActiveModColorEffect::onKeyEvent(KeyEvent &event) {
// If `event.addr` is not a physical key address, ignore it: // If `event.addr` is not a physical key address, ignore it:
if (! event.addr.isValid()) { if (!event.addr.isValid()) {
return EventHandlerResult::OK; return EventHandlerResult::OK;
} }
@ -70,7 +70,7 @@ EventHandlerResult ActiveModColorEffect::onKeyEvent(KeyEvent &event) {
mod_key_bits_.set(entry_addr); mod_key_bits_.set(entry_addr);
} }
} }
} else { // if (keyToggledOff(event.state)) } else { // if (keyToggledOff(event.state))
// Things get a bit ugly here because this plugin might come before OneShot // Things get a bit ugly here because this plugin might come before OneShot
// in the order, so we can't just count on OneShot stopping the suppressed // in the order, so we can't just count on OneShot stopping the suppressed
// release event before we see it here. // release event before we see it here.
@ -104,7 +104,7 @@ EventHandlerResult ActiveModColorEffect::beforeSyncingLeds() {
return EventHandlerResult::OK; return EventHandlerResult::OK;
} }
} // namespace plugin } // namespace plugin
} // namespace kaleidoscope } // namespace kaleidoscope
kaleidoscope::plugin::ActiveModColorEffect ActiveModColorEffect; kaleidoscope::plugin::ActiveModColorEffect ActiveModColorEffect;

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save