Merge pull request #729 from CapeLeidokos/pr_led_index_fix

Key offset to LED index map made LED driver property
pull/734/head
Gergely Nagy 5 years ago committed by GitHub
commit 11a749b5f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -31,6 +31,8 @@ namespace kaleidoscope {
namespace device {
namespace keyboardio {
constexpr uint8_t ImagoLEDDriverProps::key_led_map[] PROGMEM;
static constexpr uint8_t CMD_SET_REGISTER = 0xFD;
static constexpr uint8_t CMD_WRITE_ENABLE = 0xFE;
static constexpr uint8_t WRITE_ENABLE_ONCE = 0b11000101;
@ -53,16 +55,6 @@ ATMEGA_KEYSCANNER_BOILERPLATE
bool ImagoLEDDriver::isLEDChanged = true;
cRGB ImagoLEDDriver::led_data[];
#define NOLED 254
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},
{ 91, 13, NOLED, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 102, 15, 103},
{ 78, 26, 27, 28, 29, 30, 31, NOLED, 33, 34, 35, 36, 37, 89, 38, NOLED},
{ 65, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, NOLED, 90},
{ 52, 66, 53, 54, NOLED, 56, 57, 71, 59, NOLED, 61, 62, 63, 64, NOLED, 77}
};
void ImagoLEDDriver::setup() {
setAllPwmTo(0xFF);
selectRegister(LED_REGISTER_CONTROL);
@ -96,10 +88,6 @@ void ImagoLEDDriver::setCrgbAt(uint8_t i, cRGB crgb) {
led_data[i] = crgb;
}
uint8_t ImagoLEDDriver::getLedIndex(uint8_t key_offset) {
return pgm_read_byte(key_led_map + key_offset);
}
cRGB ImagoLEDDriver::getCrgbAt(uint8_t i) {
if (!Kaleidoscope.device().LEDs().isValid(i))
return {0, 0, 0};

@ -38,8 +38,17 @@ namespace kaleidoscope {
namespace device {
namespace keyboardio {
using kaleidoscope::driver::led::no_led;
struct ImagoLEDDriverProps: public kaleidoscope::driver::led::BaseProps {
static constexpr uint8_t led_count = 78;
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,
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,
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
};
};
class ImagoLEDDriver : public kaleidoscope::driver::led::Base<ImagoLEDDriverProps> {
@ -48,7 +57,6 @@ class ImagoLEDDriver : public kaleidoscope::driver::led::Base<ImagoLEDDriverProp
static void syncLeds();
static void setCrgbAt(uint8_t i, cRGB crgb);
static cRGB getCrgbAt(uint8_t i);
static uint8_t getLedIndex(uint8_t key_offset);
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

@ -26,6 +26,8 @@ namespace kaleidoscope {
namespace device {
namespace keyboardio {
constexpr uint8_t Model01LEDDriverProps::key_led_map[] PROGMEM;
/********* Model01Hands *********/
struct Model01Hands {
@ -55,13 +57,6 @@ void Model01Hands::setup(void) {
/********* LED Driver *********/
bool Model01LEDDriver::isLEDChanged = true;
static constexpr int8_t key_led_map[Model01::led_count] PROGMEM = {
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,
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,
};
void Model01LEDDriver::setCrgbAt(uint8_t i, cRGB crgb) {
if (i < 32) {
cRGB oldColor = getCrgbAt(i);
@ -80,10 +75,6 @@ void Model01LEDDriver::setCrgbAt(uint8_t i, cRGB crgb) {
}
}
uint8_t Model01LEDDriver::getLedIndex(uint8_t key_offset) {
return pgm_read_byte(&(key_led_map[key_offset]));
}
cRGB Model01LEDDriver::getCrgbAt(uint8_t i) {
if (i >= 64)
return {0, 0, 0};

@ -37,6 +37,12 @@ namespace keyboardio {
struct Model01LEDDriverProps : public kaleidoscope::driver::led::BaseProps {
static constexpr uint8_t led_count = 64;
static constexpr uint8_t key_led_map[] PROGMEM = {
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,
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,
};
};
class Model01LEDDriver : public kaleidoscope::driver::led::Base<Model01LEDDriverProps> {
@ -45,8 +51,6 @@ class Model01LEDDriver : public kaleidoscope::driver::led::Base<Model01LEDDriver
static void setCrgbAt(uint8_t i, cRGB crgb);
static cRGB getCrgbAt(uint8_t i);
static uint8_t getLedIndex(uint8_t key_offset);
static void enableHighPowerLeds();
static boolean ledPowerFault();

@ -25,8 +25,14 @@ namespace kaleidoscope {
namespace driver {
namespace led {
constexpr uint8_t no_led = uint8_t(-1);
struct BaseProps {
static constexpr uint8_t led_count = 0;
// C++ does not allow empty constexpr arrays
//
static constexpr uint8_t key_led_map[] PROGMEM = { no_led };
};
template <typename _LEDDriverProps>
@ -43,8 +49,20 @@ class Base {
};
return c;
}
uint8_t getLedIndex(uint8_t key_offset) {
return 0;
static uint8_t getLedIndex(uint8_t key_offset) {
// Give the compiler the oportunity to optimize
// for boards without LEDs.
//
if (_LEDDriverProps::led_count == 0) {
return no_led;
}
if (key_offset >= sizeof(_LEDDriverProps::key_led_map)) {
return no_led;
}
return pgm_read_byte(&_LEDDriverProps::key_led_map[key_offset]);
}
static class LEDs {

Loading…
Cancel
Save