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 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/hid.h"
#include "kaleidoscope/layers.h"
@ -47,8 +54,6 @@ void setup();
#define HOOK_MAX 64
extern HARDWARE_IMPLEMENTATION KeyboardHardware;
#ifndef VERSION
#define VERSION "locally-built"
#endif

@ -37,10 +37,6 @@ struct cRGB {
uint8_t r, g, b;
};
#define COLS 11
#define ROWS 4
#define LED_COUNT 0
#define CRGB(r,g,b) (cRGB){b, g, r}
namespace kaleidoscope {
@ -50,6 +46,10 @@ class Atreus {
public:
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 setCrgbAt(byte row, byte col, cRGB color) {}
void setCrgbAt(uint8_t i, cRGB crgb) {}
@ -127,16 +127,16 @@ class Atreus {
static uint8_t debounce;
private:
static uint16_t previousKeyState_[ROWS];
static uint16_t keyState_[ROWS];
static uint16_t masks_[ROWS];
static uint16_t previousKeyState_[matrix_rows];
static uint16_t keyState_[matrix_rows];
static uint16_t masks_[matrix_rows];
static void readMatrixRow(uint8_t row);
static uint16_t readCols();
static void selectRow(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 void debounceRow(uint16_t change, uint8_t row);
};
@ -183,7 +183,7 @@ class Atreus {
* user-facing code.
*/
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);

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

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

Loading…
Cancel
Save