Commit 685c89f4 authored by Robey Pointer's avatar Robey Pointer
Browse files

adjust loc, pressed_bit, and pressed_byte on each iteration instead of...

adjust loc, pressed_bit, and pressed_byte on each iteration instead of recalculating -- this saves a fair amount of inner-loop time
parent d4444390
......@@ -214,9 +214,9 @@ const menu_item_t circle_menu[] = {
// after debouncing. this takes over half a millisecond.
static void scan_keyboard_matrix(void) {
static uint8_t debounce_history[MATRIX_COLUMNS * MATRIX_ROWS] = { 0, };
uint8_t count = 0;
// pull ROWs low one after the other
uint8_t pressed_byte = 0, pressed_bit = 1, loc = 0;
for (int y = 0; y < MATRIX_ROWS; y++) {
switch (y) {
case 0: output_low(PORTB, 6); break;
......@@ -250,9 +250,6 @@ static void scan_keyboard_matrix(void) {
}
// shift new state as bit into debounce "register"
uint8_t loc = y * 15 + x;
uint8_t pressed_byte = loc >> 3;
uint8_t pressed_bit = 1 << (loc & 7);
bool now_pressed = state[pressed_byte] & pressed_bit;
debounce_history[loc] = (debounce_history[loc] << 1) | pressed;
......@@ -264,6 +261,13 @@ static void scan_keyboard_matrix(void) {
} else if (debounce_history[loc] == 0x01 && !now_pressed) {
state[pressed_byte] |= pressed_bit;
}
loc++;
pressed_bit <<= 1;
if (!pressed_bit) {
pressed_byte++;
pressed_bit = 1;
}
}
switch (y) {
......@@ -374,8 +378,8 @@ int main(void) {
HID_Device_USBTask(&Keyboard_HID_Interface);
USB_USBTask();
// this turns out to spend < 50% of its time sleeping, even if we
// wake up only every 1ms, so it might not really be worth doing.
// wake up every 1ms: we only spend 50% of the time sleeping, but
// it's better than broccoli.
sleep_mode();
while ((timer_tick & 31) != 0) sleep_mode();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment