diff --git a/KeyboardConfig.cpp b/KeyboardConfig.cpp index 265da234..0eae54cb 100644 --- a/KeyboardConfig.cpp +++ b/KeyboardConfig.cpp @@ -13,28 +13,32 @@ static int left_initted = 0; WS2812 LED(LED_COUNT); -void implementation_leds_setup() { +KeyboardHardware_::KeyboardHardware_(void) { + +} + +void KeyboardHardware_::leds_setup() { LED.setOutput(LED_DATA_PIN); LED.setColorOrderGRB(); // Uncomment for RGB color order } -void implementation_led_set_crgb_at(byte row, byte col, cRGB color) { +void KeyboardHardware_::led_set_crgb_at(byte row, byte col, cRGB color) { LED.set_crgb_at(key_led_map[row][col], color); } -cRGB implementation_get_key_color(byte row, byte col) { +cRGB KeyboardHardware_::get_key_color(byte row, byte col) { return LED.get_crgb_at(key_led_map[row][col]); } -void implementation_led_set_crgb_at(uint8_t i, cRGB crgb) { +void KeyboardHardware_::led_set_crgb_at(uint8_t i, cRGB crgb) { LED.set_crgb_at(i, crgb); } -void implementation_led_sync() { +void KeyboardHardware_::led_sync() { LED.sync(); } -void implementation_scan_row(byte row) { +void KeyboardHardware_::scan_row(byte row) { if (left_initted) { leftsx1509.updatePinState(left_rowpins[row], LOW); leftsx1509.sendPinStates(); @@ -47,14 +51,14 @@ void implementation_scan_row(byte row) { } } -void implementation_finish_scanning_row(byte row) { +void KeyboardHardware_::finish_scanning_row(byte row) { if (left_initted) leftsx1509.updatePinState(left_rowpins[row], HIGH); if (right_initted) rightsx1509.updatePinState(right_rowpins[row], HIGH); } -void implementation_scan_left_col(byte row, byte col,uint8_t *state) { +void KeyboardHardware_::scan_left_col(byte row, byte col,uint8_t *state) { //If we see an electrical connection on I->J, @@ -68,7 +72,7 @@ void implementation_scan_left_col(byte row, byte col,uint8_t *state) { } } -void implementation_scan_right_col(byte row, byte col, uint8_t *state) { +void KeyboardHardware_::scan_right_col(byte row, byte col, uint8_t *state) { //If we see an electrical connection on I->J, @@ -86,7 +90,7 @@ void implementation_scan_right_col(byte row, byte col, uint8_t *state) { -boolean implementation_right_hand_connected(void) { +boolean KeyboardHardware_::right_hand_connected(void) { if (right_initted) { return true; } else { @@ -94,24 +98,24 @@ boolean implementation_right_hand_connected(void) { } } -void implementation_pins_setup() { +void KeyboardHardware_::pins_setup() { right_initted = setup_sx1509(rightsx1509, right_colpins, right_rowpins); left_initted = setup_sx1509(leftsx1509, left_colpins, left_rowpins); rightsx1509.fetchPinStates(); } -void make_input(sx1509Class sx1509, uint8_t pin) { +void KeyboardHardware_::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 make_output(sx1509Class sx1509, uint8_t pin) { +void KeyboardHardware_::make_output(sx1509Class sx1509, uint8_t pin) { sx1509.pinDir(pin, OUTPUT); sx1509.writePin(pin, HIGH); } -int setup_sx1509 (sx1509Class sx1509, uint8_t colpins[], uint8_t rowpins[]) { +int KeyboardHardware_::setup_sx1509 (sx1509Class sx1509, uint8_t colpins[], uint8_t rowpins[]) { byte initted; for (int counter = 0; counter < 10; counter++) { @@ -147,3 +151,5 @@ int setup_sx1509 (sx1509Class sx1509, uint8_t colpins[], uint8_t rowpins[]) { return initted; } + +KeyboardHardware_ KeyboardHardware; diff --git a/KeyboardConfig.h b/KeyboardConfig.h index 9c935c11..40e9aeb7 100644 --- a/KeyboardConfig.h +++ b/KeyboardConfig.h @@ -27,16 +27,32 @@ static uint8_t right_rowpins[]= {8,9,10,11}; #define NUMPAD_KEYMAP 2 #define KEYMAP_LIST KEYMAP_QWERTY KEYMAP_GENERIC_FN2 KEYMAP_NUMPAD -void implementation_scan_row(byte row); -void implementation_finish_scanning_row(byte row); -void implementation_scan_right_col(byte row, byte col, uint8_t *state); -void implementation_scan_left_col(byte row, byte col, uint8_t *state); -void implementation_pins_setup(); + +class KeyboardHardware_ { +public: + KeyboardHardware_(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); +cRGB get_key_color(byte row, byte col); + + +void scan_row(byte row); +void finish_scanning_row(byte row); +void scan_right_col(byte row, byte col, uint8_t *state); +void scan_left_col(byte row, byte col, uint8_t *state); +void pins_setup(); +boolean right_hand_connected(void); +void leds_setup(); + + +private: + void make_input(sx1509Class sx1509, uint8_t pin) ; void make_output(sx1509Class sx1509, uint8_t pin) ; -boolean implementation_right_hand_connected(void); int setup_sx1509 (sx1509Class sx1509, uint8_t colpins[], uint8_t rowpins[]); +}; #define LED_DATA_PIN 4 @@ -50,14 +66,6 @@ static const uint8_t key_led_map[4][16] = { }; -void implementation_leds_setup(); - -void implementation_led_set_crgb_at(byte row, byte col, cRGB color); - -cRGB implementation_get_key_color(byte row, byte col); -void implementation_led_set_crgb_at(uint8_t i, cRGB crgb); -void implementation_led_sync(); - #define LED_PGDN 0 #define LED_PGUP 1 #define LED_BACKTICK 2 @@ -122,3 +130,6 @@ void implementation_led_sync(); #define LED_EQUALS 61 #define LED_APOSTROPHE 62 #define LED_MINUS 63 + + +extern KeyboardHardware_ KeyboardHardware; diff --git a/KeyboardioFirmware.ino b/KeyboardioFirmware.ino index c9c0d5b4..204828ec 100644 --- a/KeyboardioFirmware.ino +++ b/KeyboardioFirmware.ino @@ -16,18 +16,18 @@ uint8_t temporary_keymap = 0; void scan_matrix() { //scan the Keyboard matrix looking for connections for (byte row = 0; row < LEFT_ROWS; row++) { - implementation_scan_row(row); + KeyboardHardware.scan_row(row); for (byte col = 0; col < LEFT_COLS; col++) { - implementation_scan_left_col(row,col,&matrixState[row][col]); + KeyboardHardware.scan_left_col(row,col,&matrixState[row][col]); handle_key_event(row, col); - if (implementation_right_hand_connected()) { - implementation_scan_right_col(row,col,&matrixState[row][(COLS - 1) - col]); + if (KeyboardHardware.right_hand_connected()) { + KeyboardHardware.scan_right_col(row,col,&matrixState[row][(COLS - 1) - col]); handle_key_event(row, (COLS - 1) - col); } } - implementation_finish_scanning_row(row); + KeyboardHardware.finish_scanning_row(row); } } @@ -35,9 +35,9 @@ void setup() { wdt_disable(); Keyboard.begin(); Mouse.begin(); - implementation_leds_setup(); + KeyboardHardware.leds_setup(); LEDControl.boot_animation(); - implementation_pins_setup(); + KeyboardHardware.pins_setup(); temporary_keymap = primary_keymap = Storage.load_primary_keymap(KEYMAPS); } diff --git a/LEDControl.cpp b/LEDControl.cpp index dc56162a..20aaa247 100644 --- a/LEDControl.cpp +++ b/LEDControl.cpp @@ -11,11 +11,11 @@ LEDControl_::LEDControl_(void) { void LEDControl_::set_key_color(byte row, byte col, cRGB color) { - implementation_led_set_crgb_at(row, col, color); + KeyboardHardware.led_set_crgb_at(row, col, color); } cRGB LEDControl_::get_key_color(byte row, byte col) { - return implementation_get_key_color(row, col); + return KeyboardHardware.get_key_color(row, col); } void LEDControl_::initialize_led_mode(uint8_t mode) { @@ -35,7 +35,7 @@ void LEDControl_::initialize_led_mode(uint8_t mode) { void LEDControl_::set_all_leds_to(cRGB color) { for (uint8_t i = 0; i < LED_COUNT; i++) { - implementation_led_set_crgb_at(i, color); + KeyboardHardware.led_set_crgb_at(i, color); } } @@ -94,18 +94,18 @@ void LEDControl_::update(uint8_t current_keymap) { void LEDControl_::effect_numlock_update() { for (uint8_t i = 0; i < 44; i++) { - implementation_led_set_crgb_at(i, led_off); + KeyboardHardware.led_set_crgb_at(i, led_off); } for (uint8_t i = 44; i < LED_COUNT; i++) { - implementation_led_set_crgb_at(i, led_bright_red); + KeyboardHardware.led_set_crgb_at(i, led_bright_red); } led_compute_breath(); - implementation_led_set_crgb_at(60, led_breathe); // make numlock breathe - implementation_led_sync(); + KeyboardHardware.led_set_crgb_at(60, led_breathe); // make numlock breathe + KeyboardHardware.led_sync(); } void LEDControl_::effect_steady_update() { - implementation_led_sync(); + KeyboardHardware.led_sync(); } void LEDControl_::led_compute_breath() { @@ -126,7 +126,7 @@ void LEDControl_::led_compute_breath() { void LEDControl_::effect_breathe_update() { led_compute_breath(); set_all_leds_to(led_breathe); - implementation_led_sync(); + KeyboardHardware.led_sync(); } void LEDControl_::effect_chase_update() { @@ -134,16 +134,16 @@ void LEDControl_::effect_chase_update() { return; } current_chase_counter = 0; - implementation_led_set_crgb_at(pos - chase_pixels, led_off); - implementation_led_set_crgb_at(pos, led_dark_blue); + KeyboardHardware.led_set_crgb_at(pos - chase_pixels, led_off); + KeyboardHardware.led_set_crgb_at(pos, led_dark_blue); pos += chase_pixels; if (pos > LED_COUNT || pos < 0) { chase_pixels = -chase_pixels; pos += chase_pixels; } - implementation_led_set_crgb_at(pos, led_blue); - implementation_led_sync(); + KeyboardHardware.led_set_crgb_at(pos, led_blue); + KeyboardHardware.led_sync(); } void LEDControl_::effect_rainbow_update() { @@ -158,7 +158,7 @@ void LEDControl_::effect_rainbow_update() { rainbow_hue %= 360; } set_all_leds_to(rainbow); - implementation_led_sync(); + KeyboardHardware.led_sync(); } void LEDControl_::effect_rainbow_wave_update() { @@ -174,13 +174,13 @@ void LEDControl_::effect_rainbow_wave_update() { key_hue %= 360; } rainbow.SetHSV(key_hue, rainbow_saturation, rainbow_value); - implementation_led_set_crgb_at(i,rainbow); + KeyboardHardware.led_set_crgb_at(i,rainbow); } rainbow_hue += rainbow_wave_steps; if (rainbow_hue >= 360) { rainbow_hue %= 360; } - implementation_led_sync(); + KeyboardHardware.led_sync(); } void LEDControl_::boot_animation() { @@ -206,11 +206,11 @@ void LEDControl_::boot_animation() { } void LEDControl_::type_letter(uint8_t letter) { - implementation_led_set_crgb_at(letter,led_bright_red); - implementation_led_sync(); + KeyboardHardware.led_set_crgb_at(letter,led_bright_red); + KeyboardHardware.led_sync(); delay(250); - implementation_led_set_crgb_at(letter,led_off); - implementation_led_sync(); + KeyboardHardware.led_set_crgb_at(letter,led_off); + KeyboardHardware.led_sync(); delay(10); }