hardware: Move keyIndex to key_indexes.h

Since `keyIndex` is pretty much the same for all boards, it makes sense to have
it in `key_indexes.h`. To be able to do that, we need to implement it as a
macro, otherwise `HARDWARE_IMPLEMENTATION` can't be resolved. With a macro, it
is evaluated on call-sites, where the compiler can resolve that symbol.

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

@ -187,18 +187,6 @@ class ErgoDox {
} }
} }
/* To be used by the hardware implementations, `keyIndex` tells us the index of
* a key, from which we can figure out the row and column as needed. The index
* starts at one, so that plugins that work with a list of key indexes can use
* zero as a sentinel. This is important, because when we initialize arrays with
* fewer elements than the declared array size, the remaining elements will be
* zero. We can use this to avoid having to explicitly add a sentinel in
* user-facing code.
*/
constexpr byte keyIndex(byte row, byte col) {
return row * kaleidoscope::hardware::ErgoDox::matrix_columns + col + 1;
}
#include "kaleidoscope/hardware/key_indexes.h" #include "kaleidoscope/hardware/key_indexes.h"
extern kaleidoscope::hardware::ErgoDox &ErgoDox; extern kaleidoscope::hardware::ErgoDox &ErgoDox;

@ -137,25 +137,8 @@ class Model01 {
} }
} }
#ifndef DOXYGEN_SHOULD_SKIP_THIS
/* To be used by the hardware implementations, `keyIndex` tells us the index of
* a key, from which we can figure out the row and column as needed. The index
* starts at one, so that plugins that work with a list of key indexes can use
* zero as a sentinel. This is important, because when we initialize arrays with
* fewer elements than the declared array size, the remaining elements will be
* zero. We can use this to avoid having to explicitly add a sentinel in
* user-facing code.
*/
constexpr byte keyIndex(byte row, byte col) {
return row * kaleidoscope::hardware::Model01::matrix_columns + col + 1;
}
#include "kaleidoscope/hardware/key_indexes.h" #include "kaleidoscope/hardware/key_indexes.h"
#endif /* DOXYGEN_SHOULD_SKIP_THIS */
#define KEYMAP_STACKED( \ #define KEYMAP_STACKED( \
r0c0, r0c1, r0c2, r0c3, r0c4, r0c5, r0c6, \ r0c0, r0c1, r0c2, r0c3, r0c4, r0c5, r0c6, \
r1c0, r1c1, r1c2, r1c3, r1c4, r1c5, r1c6, \ r1c0, r1c1, r1c2, r1c3, r1c4, r1c5, r1c6, \

@ -17,6 +17,20 @@
#pragma once #pragma once
/* To be used by the hardware implementations, `keyIndex` tells us the index of
* a key, from which we can figure out the row and column as needed. The index
* starts at one, so that plugins that work with a list of key indexes can use
* zero as a sentinel. This is important, because when we initialize arrays with
* fewer elements than the declared array size, the remaining elements will be
* zero. We can use this to avoid having to explicitly add a sentinel in
* user-facing code.
*
* We're using a macro instead of a constexpr so that it is evaluated lazily,
* when `HARDWARE_IMPLEMENTATION` can be properly resolved.
*/
#define keyIndex(row,col) \
(uint8_t)((row * HARDWARE_IMPLEMENTATION::matrix_columns) + col + 1)
constexpr uint8_t R0C0 = keyIndex(0, 0); constexpr uint8_t R0C0 = keyIndex(0, 0);
constexpr uint8_t R0C1 = keyIndex(0, 1); constexpr uint8_t R0C1 = keyIndex(0, 1);
constexpr uint8_t R0C2 = keyIndex(0, 2); constexpr uint8_t R0C2 = keyIndex(0, 2);

@ -59,18 +59,6 @@ class Planck: public kaleidoscope::hardware::ATMegaKeyboard {
} }
} }
/* To be used by the hardware implementations, `keyIndex` tells us the index of
* a key, from which we can figure out the row and column as needed. The index
* starts at one, so that plugins that work with a list of key indexes can use
* zero as a sentinel. This is important, because when we initialize arrays with
* fewer elements than the declared array size, the remaining elements will be
* zero. We can use this to avoid having to explicitly add a sentinel in
* user-facing code.
*/
constexpr uint8_t keyIndex(byte row, byte col) {
return (row * kaleidoscope::hardware::olkb::Planck::matrix_columns) + col + 1;
}
#include "kaleidoscope/hardware/key_indexes.h" #include "kaleidoscope/hardware/key_indexes.h"
extern kaleidoscope::hardware::olkb::Planck &Planck; extern kaleidoscope::hardware::olkb::Planck &Planck;

@ -89,18 +89,6 @@ class Atreus: public kaleidoscope::hardware::ATMegaKeyboard {
} }
} }
/* To be used by the hardware implementations, `keyIndex` tells us the index of
* a key, from which we can figure out the row and column as needed. The index
* starts at one, so that plugins that work with a list of key indexes can use
* zero as a sentinel. This is important, because when we initialize arrays with
* fewer elements than the declared array size, the remaining elements will be
* zero. We can use this to avoid having to explicitly add a sentinel in
* user-facing code.
*/
constexpr byte keyIndex(byte row, byte col) {
return row * kaleidoscope::hardware::technomancy::Atreus::matrix_columns + col + 1;
}
#include "kaleidoscope/hardware/key_indexes.h" #include "kaleidoscope/hardware/key_indexes.h"
extern kaleidoscope::hardware::technomancy::Atreus &Atreus; extern kaleidoscope::hardware::technomancy::Atreus &Atreus;

Loading…
Cancel
Save