From bd913cde2bd473f2e91b6df3bc5307ae9366e0c2 Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Fri, 18 May 2018 12:18:42 +0200 Subject: [PATCH] Add support for the status LEDs Fixes #2. Signed-off-by: Gergely Nagy --- src/kaleidoscope/hardware/ErgoDox.cpp | 21 +++++++++++++++++++++ src/kaleidoscope/hardware/ErgoDox.h | 4 ++++ 2 files changed, 25 insertions(+) diff --git a/src/kaleidoscope/hardware/ErgoDox.cpp b/src/kaleidoscope/hardware/ErgoDox.cpp index 4bed81af..63c064aa 100644 --- a/src/kaleidoscope/hardware/ErgoDox.cpp +++ b/src/kaleidoscope/hardware/ErgoDox.cpp @@ -47,6 +47,10 @@ void ErgoDox::setup(void) { PORTE |= (1 << 6); scanner_.begin(); + + setStatusLEDBrightness(1, 15); + setStatusLEDBrightness(2, 15); + setStatusLEDBrightness(3, 15); } void ErgoDox::readMatrix() { @@ -104,6 +108,23 @@ bool ErgoDox::isKeyMasked(byte row, byte col) { return bitRead(masks_[row], col); } +// ErgoDox-specific stuff +void ErgoDox::setStatusLED(uint8_t led, bool state) { + if (state) { + DDRB |= (1 << (led + 4)); + PORTB |= (1 << (led + 4)); + } else { + DDRB &= ~(1 << (led + 4)); + PORTB &= ~(1 << (led + 4)); + } +} + +void ErgoDox::setStatusLEDBrightness(uint8_t led, uint8_t brightness) { + (led == 1) ? (OCR1A = brightness) : + (led == 2) ? (OCR1B = brightness) : + (OCR1C = brightness); +} + } } diff --git a/src/kaleidoscope/hardware/ErgoDox.h b/src/kaleidoscope/hardware/ErgoDox.h index 18e974db..553205f1 100644 --- a/src/kaleidoscope/hardware/ErgoDox.h +++ b/src/kaleidoscope/hardware/ErgoDox.h @@ -69,6 +69,10 @@ class ErgoDox { void unMaskKey(byte row, byte col); bool isKeyMasked(byte row, byte col); + // ErgoDox-specific stuff + void setStatusLED(uint8_t led, bool state = true); + void setStatusLEDBrightness(uint8_t led, uint8_t brightness); + private: static ErgoDoxScanner scanner_; static uint8_t previousKeyState_[ROWS];