From 29c243eda55646cf5ce01b84fa0b8177e00affe1 Mon Sep 17 00:00:00 2001 From: Michael Richters Date: Tue, 28 Nov 2017 13:47:22 -0600 Subject: [PATCH] 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. --- src/addr.h | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/addr.h diff --git a/src/addr.h b/src/addr.h new file mode 100644 index 00000000..048b4de9 --- /dev/null +++ b/src/addr.h @@ -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 . + */ + +#pragma once + +#include + +// 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 {