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 {