masking: use 4 8-bit uints instead of one 32bit one

Dealing with 32-bit numbers on Atmega32u4 is very costy, so lets try to avoid
that, and use four 8-bit uints instead. This save us about a hundred bytes of
progmem.

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
pull/365/head
Gergely Nagy 7 years ago
parent 0a566eb58f
commit 8e98e30f62

@ -5,8 +5,8 @@
KeyboardioScanner Model01::leftHand(0); KeyboardioScanner Model01::leftHand(0);
KeyboardioScanner Model01::rightHand(3); KeyboardioScanner Model01::rightHand(3);
bool Model01::isLEDChanged = true; bool Model01::isLEDChanged = true;
uint32_t Model01::leftHandMask; uint8_t Model01::leftHandMask[4];
uint32_t Model01::rightHandMask; uint8_t Model01::rightHandMask[4];
static constexpr uint8_t key_led_map[4][16] = { static constexpr uint8_t key_led_map[4][16] = {
{3, 4, 11, 12, 19, 20, 26, 27, 36, 37, 43, 44, 51, 52, 59, 60}, {3, 4, 11, 12, 19, 20, 26, 27, 36, 37, 43, 44, 51, 52, 59, 60},
@ -209,9 +209,9 @@ void Model01::maskKey(byte row, byte col) {
return; return;
if (col >= 8) { if (col >= 8) {
rightHandMask |= SCANBIT(row, col - 8); rightHandMask[row] |= 1 << (col - 8);
} else { } else {
leftHandMask |= SCANBIT(row, col); leftHandMask[row] |= 1 << (col);
} }
} }
@ -220,9 +220,9 @@ void Model01::unMaskKey(byte row, byte col) {
return; return;
if (col >= 8) { if (col >= 8) {
rightHandMask &= ~(SCANBIT(row, col - 8)); rightHandMask[row] &= ~(1 << (col - 8));
} else { } else {
leftHandMask &= ~(SCANBIT(row, col)); leftHandMask[row] &= ~(1 << col);
} }
} }
@ -231,15 +231,21 @@ bool Model01::isKeyMasked(byte row, byte col) {
return false; return false;
if (col >= 8) { if (col >= 8) {
return rightHandMask & SCANBIT(row, col - 8); return rightHandMask[row] & (1 << (col - 8));
} else { } else {
return leftHandMask & SCANBIT(row, col); return leftHandMask[row] & (1 << col);
} }
} }
void Model01::maskHeldKeys(void) { void Model01::maskHeldKeys(void) {
rightHandMask = rightHandState.all; for (byte row = 0; row < ROWS; row++) {
leftHandMask = leftHandState.all; for (byte col = 0; col < COLS / 2; col++) {
if (leftHandState.all & SCANBIT(row, col))
leftHandMask[row] |= 1 << col;
if (rightHandState.all & SCANBIT(row, col))
rightHandMask[row] |= 1 << col;
}
}
} }
HARDWARE_IMPLEMENTATION KeyboardHardware; HARDWARE_IMPLEMENTATION KeyboardHardware;

@ -54,8 +54,8 @@ class Model01 {
static KeyboardioScanner leftHand; static KeyboardioScanner leftHand;
static KeyboardioScanner rightHand; static KeyboardioScanner rightHand;
static uint32_t leftHandMask; static uint8_t leftHandMask[4];
static uint32_t rightHandMask; static uint8_t rightHandMask[4];
}; };
#define SCANBIT(row,col) ((uint32_t)1 << ((row) * 8 + (7 - (col)))) #define SCANBIT(row,col) ((uint32_t)1 << ((row) * 8 + (7 - (col))))

Loading…
Cancel
Save