From 70d892f2c7e48f744110e9cb4bf920b546af4913 Mon Sep 17 00:00:00 2001 From: Jesse Vincent Date: Mon, 1 Feb 2016 14:42:18 -0800 Subject: [PATCH 1/3] wip implementation select --- KeyboardConfig.h | 2 ++ KeyboardioFirmware.h | 1 + LEDControl.h | 1 + implementation/Model01Beta.h | 3 +-- 4 files changed, 5 insertions(+), 2 deletions(-) diff --git a/KeyboardConfig.h b/KeyboardConfig.h index a9b4aedc..08aa1b7f 100644 --- a/KeyboardConfig.h +++ b/KeyboardConfig.h @@ -2,6 +2,7 @@ #include "implementation/Model01Beta.h" + // These global proxy functions are a cheap hack to avoid // a circular dependency between the keyboard hardware class // and the 'userspace' LED implementation. If my C++ were stronger, there woudl @@ -10,3 +11,4 @@ void led_set_crgb_at(uint8_t i, cRGB crgb); void led_sync(void); + diff --git a/KeyboardioFirmware.h b/KeyboardioFirmware.h index 68a04b04..934b42c4 100644 --- a/KeyboardioFirmware.h +++ b/KeyboardioFirmware.h @@ -25,6 +25,7 @@ void setup(); #include "generated/keymaps.h" #include "key_events.h" +extern Model01Beta_ KeyboardHardware; extern uint8_t matrixState[ROWS][COLS]; extern const Key keymaps[KEYMAPS][ROWS][COLS]; diff --git a/LEDControl.h b/LEDControl.h index 9eb143e9..9f4e9d3b 100644 --- a/LEDControl.h +++ b/LEDControl.h @@ -4,6 +4,7 @@ #include "cRGB.h" #include "KeyboardConfig.h" + #define LED_MODES 7 #define LED_MODE_OFF 0 #define LED_MODE_STEADY 1 diff --git a/implementation/Model01Beta.h b/implementation/Model01Beta.h index 7a715bcd..02ce0d50 100644 --- a/implementation/Model01Beta.h +++ b/implementation/Model01Beta.h @@ -19,7 +19,6 @@ #define LEFT_COLS 8 #define LEFT_ROWS 4 -//class Model01Beta_; class Model01Beta_ { public: @@ -136,4 +135,4 @@ class Model01Beta_ { #define LED_APOSTROPHE 62 #define LED_MINUS 63 -extern Model01Beta_ KeyboardHardware; + From 28765090768174b1809d1ef2cb4b8728dbe82846 Mon Sep 17 00:00:00 2001 From: Jesse Vincent Date: Mon, 1 Feb 2016 15:49:34 -0800 Subject: [PATCH 2/3] Selectable implementations that appear to work. --- KeyboardConfig.cpp | 2 +- KeyboardConfig.h | 6 +++++- KeyboardioFirmware.h | 2 +- implementation/Model01.cpp | 14 ++++++------- implementation/Model01.h | 4 ++-- implementation/Model01Beta.cpp | 38 +++++++++++++++++----------------- implementation/Model01Beta.h | 4 ++-- 7 files changed, 37 insertions(+), 33 deletions(-) diff --git a/KeyboardConfig.cpp b/KeyboardConfig.cpp index e0fb1830..36e3d94c 100644 --- a/KeyboardConfig.cpp +++ b/KeyboardConfig.cpp @@ -1,6 +1,6 @@ #include "KeyboardConfig.h" -Model01Beta_ KeyboardHardware; +HARDWARE_IMPLEMENTATION KeyboardHardware; // These global proxy functions are a cheap hack to avoid void led_set_crgb_at(uint8_t i, cRGB crgb) { diff --git a/KeyboardConfig.h b/KeyboardConfig.h index 08aa1b7f..30391564 100644 --- a/KeyboardConfig.h +++ b/KeyboardConfig.h @@ -1,6 +1,10 @@ #pragma once -#include "implementation/Model01Beta.h" + +#define HARDWARE_IMPLEMENTATION Model01 +#define HARDWARE_IMPLEMENTATION_HEADER "implementation/Model01.h" + +#include HARDWARE_IMPLEMENTATION_HEADER // These global proxy functions are a cheap hack to avoid diff --git a/KeyboardioFirmware.h b/KeyboardioFirmware.h index 934b42c4..abef7126 100644 --- a/KeyboardioFirmware.h +++ b/KeyboardioFirmware.h @@ -25,7 +25,7 @@ void setup(); #include "generated/keymaps.h" #include "key_events.h" -extern Model01Beta_ KeyboardHardware; +extern HARDWARE_IMPLEMENTATION KeyboardHardware; extern uint8_t matrixState[ROWS][COLS]; extern const Key keymaps[KEYMAPS][ROWS][COLS]; diff --git a/implementation/Model01.cpp b/implementation/Model01.cpp index 16df6ecf..bbe90fa8 100644 --- a/implementation/Model01.cpp +++ b/implementation/Model01.cpp @@ -2,28 +2,28 @@ #include "WS2812.h" #include "Model01.h" -Model01_::Model01_(void) { +Model01::Model01(void) { } -void Model01_::setup(void) { +void Model01::setup(void) { } -void Model01_::led_set_crgb_at(byte row, byte col, cRGB color) { +void Model01::led_set_crgb_at(byte row, byte col, cRGB color) { } -cRGB Model01_::get_key_color(byte row, byte col) { +cRGB Model01::get_key_color(byte row, byte col) { } -void Model01_::led_set_crgb_at(uint8_t i, cRGB crgb) { +void Model01::led_set_crgb_at(uint8_t i, cRGB crgb) { } -void Model01_::led_sync() { +void Model01::led_sync() { } -void Model01_::scan_matrix() { +void Model01::scan_matrix() { //scan the Keyboard matrix looking for connections for (byte row = 0; row < LEFT_ROWS; row++) { diff --git a/implementation/Model01.h b/implementation/Model01.h index 0571f0e5..b07c65df 100644 --- a/implementation/Model01.h +++ b/implementation/Model01.h @@ -13,9 +13,9 @@ -class Model01_ { +class Model01 { public: - Model01_(void); + Model01(void); void led_sync(void); void led_set_crgb_at(byte row, byte col, cRGB color); void led_set_crgb_at(uint8_t i, cRGB crgb); diff --git a/implementation/Model01Beta.cpp b/implementation/Model01Beta.cpp index 9fcef635..78453c08 100644 --- a/implementation/Model01Beta.cpp +++ b/implementation/Model01Beta.cpp @@ -1,41 +1,41 @@ #include "Model01Beta.h" -sx1509Class Model01Beta_::leftsx1509(LEFT_SX1509_ADDRESS); -sx1509Class Model01Beta_::rightsx1509(RIGHT_SX1509_ADDRESS); +sx1509Class Model01Beta::leftsx1509(LEFT_SX1509_ADDRESS); +sx1509Class Model01Beta::rightsx1509(RIGHT_SX1509_ADDRESS); -WS2812 Model01Beta_::LED(LED_COUNT); +WS2812 Model01Beta::LED(LED_COUNT); -Model01Beta_::Model01Beta_(void) { +Model01Beta::Model01Beta(void) { } -void Model01Beta_::setup(void) { +void Model01Beta::setup(void) { pins_setup(); leds_setup(); } -void Model01Beta_::leds_setup() { +void Model01Beta::leds_setup() { LED.setOutput(LED_DATA_PIN); LED.setColorOrderGRB(); // Uncomment for RGB color order } -cRGB Model01Beta_::get_key_color(byte row, byte col) { +cRGB Model01Beta::get_key_color(byte row, byte col) { return LED.get_crgb_at(key_led_map[row][col]); } -void Model01Beta_::led_set_crgb_at(uint8_t i, cRGB crgb) { +void Model01Beta::led_set_crgb_at(uint8_t i, cRGB crgb) { LED.set_crgb_at(i, crgb); } -void Model01Beta_::led_sync() { +void Model01Beta::led_sync() { LED.sync(); } -void Model01Beta_::scan_matrix() { +void Model01Beta::scan_matrix() { //scan the Keyboard matrix looking for connections for (byte row = 0; row < LEFT_ROWS; row++) { scan_row(row); @@ -59,7 +59,7 @@ void Model01Beta_::scan_matrix() { -void Model01Beta_::scan_row(byte row) { +void Model01Beta::scan_row(byte row) { if (left_initted) { leftsx1509.updatePinState(left_rowpins[row], LOW); leftsx1509.sendPinStates(); @@ -72,14 +72,14 @@ void Model01Beta_::scan_row(byte row) { } } -void Model01Beta_::finish_scanning_row(byte row) { +void Model01Beta::finish_scanning_row(byte row) { if (left_initted) leftsx1509.updatePinState(left_rowpins[row], HIGH); if (right_initted) rightsx1509.updatePinState(right_rowpins[row], HIGH); } -void Model01Beta_::scan_left_col(byte row, byte col,uint8_t *state) { +void Model01Beta::scan_left_col(byte row, byte col,uint8_t *state) { //If we see an electrical connection on I->J, @@ -93,7 +93,7 @@ void Model01Beta_::scan_left_col(byte row, byte col,uint8_t *state) { } } -void Model01Beta_::scan_right_col(byte row, byte col, uint8_t *state) { +void Model01Beta::scan_right_col(byte row, byte col, uint8_t *state) { //If we see an electrical connection on I->J, @@ -111,7 +111,7 @@ void Model01Beta_::scan_right_col(byte row, byte col, uint8_t *state) { -boolean Model01Beta_::right_hand_connected(void) { +boolean Model01Beta::right_hand_connected(void) { if (right_initted) { return true; } else { @@ -119,24 +119,24 @@ boolean Model01Beta_::right_hand_connected(void) { } } -void Model01Beta_::pins_setup() { +void Model01Beta::pins_setup() { right_initted = setup_sx1509(rightsx1509, right_colpins, right_rowpins); left_initted = setup_sx1509(leftsx1509, left_colpins, left_rowpins); rightsx1509.fetchPinStates(); } -void Model01Beta_::make_input(sx1509Class sx1509, uint8_t pin) { +void Model01Beta::make_input(sx1509Class sx1509, uint8_t pin) { sx1509.pinDir(pin, INPUT); // Set SX1509 pin 1 as an input sx1509.writePin(pin, HIGH); // Activate pull-up } -void Model01Beta_::make_output(sx1509Class sx1509, uint8_t pin) { +void Model01Beta::make_output(sx1509Class sx1509, uint8_t pin) { sx1509.pinDir(pin, OUTPUT); sx1509.writePin(pin, HIGH); } -int Model01Beta_::setup_sx1509 (sx1509Class sx1509, uint8_t colpins[], uint8_t rowpins[]) { +int Model01Beta::setup_sx1509 (sx1509Class sx1509, uint8_t colpins[], uint8_t rowpins[]) { byte initted; for (int counter = 0; counter < 10; counter++) { diff --git a/implementation/Model01Beta.h b/implementation/Model01Beta.h index 02ce0d50..120c2f1f 100644 --- a/implementation/Model01Beta.h +++ b/implementation/Model01Beta.h @@ -20,9 +20,9 @@ #define LEFT_ROWS 4 -class Model01Beta_ { +class Model01Beta { public: - Model01Beta_(void); + Model01Beta(void); void led_sync(void); void led_set_crgb_at(uint8_t i, cRGB crgb); cRGB get_key_color(byte row, byte col); From a95308cc47c4c123a84443511c65890fcddeca51 Mon Sep 17 00:00:00 2001 From: Jesse Vincent Date: Mon, 1 Feb 2016 16:09:52 -0800 Subject: [PATCH 3/3] Move the HARDWARE_IMPLEMENTATION macro into the implementation defintion --- KeyboardConfig.h | 4 +--- implementation/Model01.h | 3 +++ implementation/Model01Beta.h | 4 ++++ 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/KeyboardConfig.h b/KeyboardConfig.h index 30391564..da65789a 100644 --- a/KeyboardConfig.h +++ b/KeyboardConfig.h @@ -1,10 +1,8 @@ #pragma once -#define HARDWARE_IMPLEMENTATION Model01 -#define HARDWARE_IMPLEMENTATION_HEADER "implementation/Model01.h" -#include HARDWARE_IMPLEMENTATION_HEADER +#include "implementation/Model01Beta.h" // These global proxy functions are a cheap hack to avoid diff --git a/implementation/Model01.h b/implementation/Model01.h index b07c65df..71fdb5c2 100644 --- a/implementation/Model01.h +++ b/implementation/Model01.h @@ -1,5 +1,8 @@ #pragma once +#define HARDWARE_IMPLEMENTATION Model01 + + #include "../keymaps.h" #include "../generated/keymaps.h" #include "../key_events.h" diff --git a/implementation/Model01Beta.h b/implementation/Model01Beta.h index 120c2f1f..a3e56e33 100644 --- a/implementation/Model01Beta.h +++ b/implementation/Model01Beta.h @@ -7,6 +7,10 @@ #include "KeyboardioSX1509.h" #include "../key_events.h" + + +#define HARDWARE_IMPLEMENTATION Model01Beta + #define USE_HSV_CURVE 1 // SX1509 I2C address (10)