hardware: Move ROWS, COLS, and LED_COUNT to KeyboardHardware

In an attempt to move away from magic, global defines, move the `ROWS`, `COLS`,
and `LED_COUNT` defines to the hardware class. Backwards-compatible defines are
provided by `<Kaleidoscope.h>`.

This is just a first step, no users are updated just yet.

Signed-off-by: Gergely Nagy <algernon@keyboard.io>
pull/432/head
Gergely Nagy 6 years ago
parent f3594c5036
commit 3a015d2094
No known key found for this signature in database
GPG Key ID: AC1E90BAC433F68F

@ -37,6 +37,13 @@ void setup();
#include <stdint.h> #include <stdint.h>
#include KALEIDOSCOPE_HARDWARE_H #include KALEIDOSCOPE_HARDWARE_H
extern HARDWARE_IMPLEMENTATION KeyboardHardware;
#define ROWS (KeyboardHardware.matrix_rows)
#define COLS (KeyboardHardware.matrix_columns)
#define LED_COUNT (KeyboardHardware.led_count)
#include "kaleidoscope/key_events.h" #include "kaleidoscope/key_events.h"
#include "kaleidoscope/hid.h" #include "kaleidoscope/hid.h"
#include "kaleidoscope/layers.h" #include "kaleidoscope/layers.h"
@ -47,8 +54,6 @@ void setup();
#define HOOK_MAX 64 #define HOOK_MAX 64
extern HARDWARE_IMPLEMENTATION KeyboardHardware;
#ifndef VERSION #ifndef VERSION
#define VERSION "locally-built" #define VERSION "locally-built"
#endif #endif

@ -37,10 +37,6 @@ struct cRGB {
uint8_t r, g, b; uint8_t r, g, b;
}; };
#define COLS 11
#define ROWS 4
#define LED_COUNT 0
#define CRGB(r,g,b) (cRGB){b, g, r} #define CRGB(r,g,b) (cRGB){b, g, r}
namespace kaleidoscope { namespace kaleidoscope {
@ -50,6 +46,10 @@ class Atreus {
public: public:
Atreus(void) {} Atreus(void) {}
static constexpr byte matrix_columns = 11;
static constexpr byte matrix_rows = 4;
static constexpr uint8_t led_count = 0;
void syncLeds(void) {} void syncLeds(void) {}
void setCrgbAt(byte row, byte col, cRGB color) {} void setCrgbAt(byte row, byte col, cRGB color) {}
void setCrgbAt(uint8_t i, cRGB crgb) {} void setCrgbAt(uint8_t i, cRGB crgb) {}
@ -127,16 +127,16 @@ class Atreus {
static uint8_t debounce; static uint8_t debounce;
private: private:
static uint16_t previousKeyState_[ROWS]; static uint16_t previousKeyState_[matrix_rows];
static uint16_t keyState_[ROWS]; static uint16_t keyState_[matrix_rows];
static uint16_t masks_[ROWS]; static uint16_t masks_[matrix_rows];
static void readMatrixRow(uint8_t row); static void readMatrixRow(uint8_t row);
static uint16_t readCols(); static uint16_t readCols();
static void selectRow(uint8_t row); static void selectRow(uint8_t row);
static void unselectRow(uint8_t row); static void unselectRow(uint8_t row);
static uint8_t debounce_matrix_[ROWS][COLS]; static uint8_t debounce_matrix_[matrix_rows][matrix_columns];
static uint16_t debounceMaskForRow(uint8_t row); static uint16_t debounceMaskForRow(uint8_t row);
static void debounceRow(uint16_t change, uint8_t row); static void debounceRow(uint16_t change, uint8_t row);
}; };
@ -183,7 +183,7 @@ class Atreus {
* user-facing code. * user-facing code.
*/ */
constexpr byte keyIndex(byte row, byte col) { constexpr byte keyIndex(byte row, byte col) {
return row * COLS + col + 1; return row * kaleidoscope::hardware::Atreus::matrix_columns + col + 1;
} }
constexpr byte R0C0 = keyIndex(0, 0); constexpr byte R0C0 = keyIndex(0, 0);

@ -40,10 +40,6 @@ struct cRGB {
uint8_t r, g, b; uint8_t r, g, b;
}; };
#define COLS 6
#define ROWS 14
#define LED_COUNT 0
#define CRGB(r,g,b) (cRGB){b, g, r} #define CRGB(r,g,b) (cRGB){b, g, r}
namespace kaleidoscope { namespace kaleidoscope {
@ -53,6 +49,10 @@ class ErgoDox {
public: public:
ErgoDox(void) {} ErgoDox(void) {}
static constexpr byte matrix_columns = 6;
static constexpr byte matrix_rows = 14;
static constexpr uint8_t led_count = 0;
void syncLeds(void) {} void syncLeds(void) {}
void setCrgbAt(byte row, byte col, cRGB color) {} void setCrgbAt(byte row, byte col, cRGB color) {}
void setCrgbAt(uint8_t i, cRGB crgb) {} void setCrgbAt(uint8_t i, cRGB crgb) {}
@ -135,10 +135,10 @@ class ErgoDox {
private: private:
static ErgoDoxScanner scanner_; static ErgoDoxScanner scanner_;
static uint8_t previousKeyState_[ROWS]; static uint8_t previousKeyState_[matrix_rows];
static uint8_t keyState_[ROWS]; static uint8_t keyState_[matrix_rows];
static uint8_t masks_[ROWS]; static uint8_t masks_[matrix_rows];
static uint8_t debounce_matrix_[ROWS][COLS]; static uint8_t debounce_matrix_[matrix_rows][matrix_columns];
static uint8_t debounceMaskForRow(uint8_t row); static uint8_t debounceMaskForRow(uint8_t row);
static void debounceRow(uint8_t change, uint8_t row); static void debounceRow(uint8_t change, uint8_t row);
@ -196,7 +196,7 @@ class ErgoDox {
* user-facing code. * user-facing code.
*/ */
constexpr byte keyIndex(byte row, byte col) { constexpr byte keyIndex(byte row, byte col) {
return row * COLS + col + 1; return row * kaleidoscope::hardware::ErgoDox::matrix_columns + col + 1;
} }
constexpr byte R0C0 = keyIndex(0, 0); constexpr byte R0C0 = keyIndex(0, 0);

@ -27,9 +27,6 @@
#include "kaleidoscope/macro_helpers.h" #include "kaleidoscope/macro_helpers.h"
#define COLS 16
#define ROWS 4
#define CRGB(r,g,b) (cRGB){b, g, r} #define CRGB(r,g,b) (cRGB){b, g, r}
namespace kaleidoscope { namespace kaleidoscope {
@ -38,6 +35,11 @@ namespace hardware {
class Model01 { class Model01 {
public: public:
Model01(void); Model01(void);
static constexpr byte matrix_rows = 4;
static constexpr byte matrix_columns = 16;
static constexpr uint8_t led_count = 64;
void syncLeds(void); void syncLeds(void);
void setCrgbAt(byte row, byte col, cRGB color); void setCrgbAt(byte row, byte col, cRGB color);
void setCrgbAt(uint8_t i, cRGB crgb); void setCrgbAt(uint8_t i, cRGB crgb);
@ -50,7 +52,6 @@ class Model01 {
void setup(); void setup();
void rebootBootloader(); void rebootBootloader();
/** Detaching from / attaching to the host. /** Detaching from / attaching to the host.
* *
* These two functions should detach the device from (or attach it to) the * These two functions should detach the device from (or attach it to) the
@ -147,7 +148,7 @@ class Model01 {
* user-facing code. * user-facing code.
*/ */
constexpr byte keyIndex(byte row, byte col) { constexpr byte keyIndex(byte row, byte col) {
return row * COLS + col + 1; return row * kaleidoscope::hardware::Model01::matrix_columns + col + 1;
} }
constexpr byte R0C0 = keyIndex(0, 0); constexpr byte R0C0 = keyIndex(0, 0);
@ -216,9 +217,6 @@ constexpr byte R3C13 = keyIndex(3, 13);
constexpr byte R3C14 = keyIndex(3, 14); constexpr byte R3C14 = keyIndex(3, 14);
constexpr byte R3C15 = keyIndex(3, 15); constexpr byte R3C15 = keyIndex(3, 15);
#define LED_COUNT 64
#endif /* DOXYGEN_SHOULD_SKIP_THIS */ #endif /* DOXYGEN_SHOULD_SKIP_THIS */

Loading…
Cancel
Save