Added addr.h with helper functions

This contains helper functions for converting (row,col) coordinates to
single-byte addresses, assuming the keyboard has fewer than 256 keys.
pull/389/head
Michael Richters 7 years ago
parent bba6cf878f
commit 29c243eda5

@ -0,0 +1,38 @@
/* -*- mode: c++ -*-
* Kaleidoscope-Qukeys -- Assign two keycodes to a single key
* Copyright (C) 2017 Michael Richters
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <Kaleidoscope.h>
// Helper functions for converting between separate (row,col)
// coordinates and a single-byte key number (addr). This works as long
// as the keyboard has fewer than 256 keys.
namespace kaleidoscope {
namespace addr {
inline uint8_t row(uint8_t key_addr) {
return (key_addr / COLS);
}
inline uint8_t col(uint8_t key_addr) {
return (key_addr % COLS);
}
inline uint8_t addr(uint8_t row, uint8_t col) {
return ((row * COLS) + col);
}
} // namespace addr {
} // namespace kaleidoscope {
Loading…
Cancel
Save