kbdfans/KBD4x: Stop using opaque macros

Instead of using opaque macros which aren't even extensible, just expand them,
and use the raw data structures for the hardware definition. While this is more
verbose than the macros, it is more future proof, and clearer for the reader
too, because they don't need to understand the magic macros.

Signed-off-by: Gergely Nagy <algernon@keyboard.io>
pull/868/head
Gergely Nagy 5 years ago committed by Jesse Vincent
parent 07213d9f7e
commit 7dbf1d4c20
No known key found for this signature in database
GPG Key ID: CC228463465E40BC

@ -1,6 +1,6 @@
/* -*- mode: c++ -*- /* -*- mode: c++ -*-
* Kaleidoscope-Hardware-KBDFans-KBD4x -- KBD4x hardware support for Kaleidoscope * Kaleidoscope-Hardware-KBDFans-KBD4x -- KBD4x hardware support for Kaleidoscope
* Copyright (C) 2019 Keyboard.io, Inc * Copyright (C) 2019, 2020 Keyboard.io, Inc
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of version 3 of the GNU General Public License as * it under the terms of version 3 of the GNU General Public License as
@ -18,20 +18,55 @@
#ifndef KALEIDOSCOPE_VIRTUAL_BUILD #ifndef KALEIDOSCOPE_VIRTUAL_BUILD
#ifdef ARDUINO_AVR_KBD4X #ifdef ARDUINO_AVR_KBD4X
#include "kaleidoscope/key_events.h"
#include "kaleidoscope/driver/keyscanner/ATmega.h"
#include "kaleidoscope/driver/keyscanner/Base_Impl.h"
#include "kaleidoscope/Runtime.h" #include "kaleidoscope/Runtime.h"
#include "kaleidoscope/driver/keyscanner/Base_Impl.h"
// Here, we set up aliases to the device's KeyScanner and KeyScannerProps
// in the global namespace within the scope of this file. We'll use these
// aliases to simplify some template initialization code below.
using KeyScannerProps = typename kaleidoscope::device::kbdfans::KBD4xProps::KeyScannerProps;
using KeyScanner = typename kaleidoscope::device::kbdfans::KBD4xProps::KeyScanner;
namespace kaleidoscope { namespace kaleidoscope {
namespace device { namespace device {
namespace kbdfans { namespace kbdfans {
ATMEGA_KEYSCANNER_BOILERPLATE // `KeyScannerProps` here refers to the alias set up above. We do not need to
// prefix the `matrix_rows` and `matrix_columns` names within the array
// declaration, because those are resolved within the context of the class, so
// the `matrix_rows` in `KeyScannerProps::matrix_row_pins[matrix_rows]` gets
// resolved as `KeyScannerProps::matrix_rows`.
const uint8_t KeyScannerProps::matrix_rows;
const uint8_t KeyScannerProps::matrix_columns;
constexpr uint8_t KeyScannerProps::matrix_row_pins[matrix_rows];
constexpr uint8_t KeyScannerProps::matrix_col_pins[matrix_columns];
// Resolving is a bit different in case of templates, however: the name of the
// array is resolved within the scope of the namespace and the class, but the
// array size is not - because it is a template. Therefore, we need a fully
// qualified name there - or an alias in the global scope, which we set up just
// above.
template<> uint16_t KeyScanner::previousKeyState_[KeyScannerProps::matrix_rows] = {};
template<> uint16_t KeyScanner::keyState_[KeyScannerProps::matrix_rows] = {};
template<> uint16_t KeyScanner::masks_[KeyScannerProps::matrix_rows] = {};
template<> uint8_t KeyScanner::debounce_matrix_[KeyScannerProps::matrix_rows][KeyScannerProps::matrix_columns] = {};
// We set up the TIMER1 interrupt vector here. Due to dependency reasons, this
// cannot be in a header-only driver, and must be placed here.
//
// Timer1 is responsible for setting a property on the KeyScanner, which will
// tell it to do a scan. We use this to make sure that scans happen at roughly
// the intervals we want. We do the scan outside of the interrupt scope for
// practical reasons: guarding every codepath against interrupts that can be
// reached from the scan is far too tedious, for very little gain.
ISR(TIMER1_OVF_vect) {
Runtime.device().keyScanner().do_scan_ = true;
} }
}
} } // namespace kbdfans
} // namespace device
} // namespace kaleidoscope
#endif #endif
#endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD #endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD

@ -1,6 +1,6 @@
/* -*- mode: c++ -*- /* -*- mode: c++ -*-
* Kaleidoscope-Hardware-KBDFans-KBD4x -- KBD4x hardware support for Kaleidoscope * Kaleidoscope-Hardware-KBDFans-KBD4x -- KBD4x hardware support for Kaleidoscope
* Copyright (C) 2019 Keyboard.io, Inc * Copyright (C) 2019, 2020 Keyboard.io, Inc
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of version 3 of the GNU General Public License as * it under the terms of version 3 of the GNU General Public License as
@ -38,10 +38,13 @@ struct KBD4xProps : kaleidoscope::device::ATmega32U4KeyboardProps {
}; };
typedef kaleidoscope::driver::mcu::ATmega32U4<MCUProps> MCU; typedef kaleidoscope::driver::mcu::ATmega32U4<MCUProps> MCU;
struct KeyScannerProps : public kaleidoscope::driver::keyscanner::ATmegaProps { struct KeyScannerProps : public kaleidoscope::driver::keyscanner::ATmegaProps {
ATMEGA_KEYSCANNER_PROPS( static constexpr uint8_t matrix_rows = 4;
ROW_PIN_LIST({ PIN_D0, PIN_D1, PIN_D2, PIN_D3 }), static constexpr uint8_t matrix_columns = 12;
COL_PIN_LIST({ PIN_F0, PIN_F1, PIN_F4, PIN_F5, PIN_F6, PIN_F7, PIN_B3, PIN_B1, PIN_B0, PIN_D5, PIN_B7, PIN_C7 }) typedef MatrixAddr<matrix_rows, matrix_columns> KeyAddr;
); #ifndef KALEIDOSCOPE_VIRTUAL_BUILD
static constexpr uint8_t matrix_row_pins[matrix_rows] = {PIN_D0, PIN_D1, PIN_D2, PIN_D3};
static constexpr uint8_t matrix_col_pins[matrix_columns] = { PIN_F0, PIN_F1, PIN_F4, PIN_F5, PIN_F6, PIN_F7, PIN_B3, PIN_B1, PIN_B0, PIN_D5, PIN_B7, PIN_C7 };
#endif // KALEIDOSCOPE_VIRTUAL_BUILD
}; };
typedef kaleidoscope::driver::keyscanner::ATmega<KeyScannerProps> KeyScanner; typedef kaleidoscope::driver::keyscanner::ATmega<KeyScannerProps> KeyScanner;
typedef kaleidoscope::driver::bootloader::avr::FLIP Bootloader; typedef kaleidoscope::driver::bootloader::avr::FLIP Bootloader;
@ -49,9 +52,15 @@ struct KBD4xProps : kaleidoscope::device::ATmega32U4KeyboardProps {
}; };
#ifndef KALEIDOSCOPE_VIRTUAL_BUILD #ifndef KALEIDOSCOPE_VIRTUAL_BUILD
ATMEGA32U4_DEVICE(KBD4x); class KBD4x: public kaleidoscope::device::ATmega32U4Keyboard<KBD4xProps> {};
#else // ifndef KALEIDOSCOPE_VIRTUAL_BUILD #else // ifndef KALEIDOSCOPE_VIRTUAL_BUILD
/* Device definition omitted for virtual device builds.
* We need to forward declare the device name, though, as there are
* some legacy extern references to boards whose definition
* depends on this.
*/
class KBD4x; class KBD4x;
#endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD #endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD
#define PER_KEY_DATA(dflt, \ #define PER_KEY_DATA(dflt, \

Loading…
Cancel
Save