diff --git a/firmware/asdf/src/Keymaps/asdf_all_keymap_defs_production.h b/firmware/asdf/src/Keymaps/asdf_all_keymap_defs_production.h
new file mode 100644
index 0000000..ebc3203
--- /dev/null
+++ b/firmware/asdf/src/Keymaps/asdf_all_keymap_defs_production.h
@@ -0,0 +1,49 @@
+// -*- mode: C; tab-width: 4 ; indent-tabs-mode: nil -*-
+//
+// Unfified Keyboard Project
+// ASDF keyboard firmware
+//
+// asdf_keymap_defs.h
+//
+// gathers up all the keymap definitions to be included in the firmware.
+//
+// Copyright 2019 David Fenyes
+//
+// 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 .
+
+// While there is nothing preventing a standard keyboard from having both a
+// "Shift Lock" key and a "Caps Lock" key, usually only one will be present. For
+// testing, both must be present to test their functionality.
+
+#if !defined(ASDF_KEYMAP_DEFS_H)
+#define ASDF_KEYMAP_DEFS_H
+
+#include "asdf.h"
+#include "asdf_ascii.h"
+#include "asdf_modifiers.h"
+
+#include "Keymaps/asdf_keymap_defs_ascii.h"
+
+#define ASDF_NUM_KEYMAPS (ASDF_ASCII_ALL_MAPS_COUNT)
+#define ASDF_KEYMAP_DEFS { ASDF_ASCII_ALL_MAPS }
+#define ASDF_KEYMAP_DECLARATIONS ASDF_ASCII_MAP_DECLARATIONS
+
+typedef asdf_keycode_t keycode_matrix_t[ASDF_NUM_ROWS][ASDF_NUM_COLS];
+
+
+
+#endif /* !defined (ASDF_KEYMAP_DEFS_H) */
+
+//-------|---------|---------+---------+---------+---------+---------+---------+
+// Above line is 80 columns, and should display completely in the editor.
diff --git a/firmware/asdf/src/Keymaps/asdf_all_keymap_defs_test.h b/firmware/asdf/src/Keymaps/asdf_all_keymap_defs_test.h
new file mode 100644
index 0000000..112de82
--- /dev/null
+++ b/firmware/asdf/src/Keymaps/asdf_all_keymap_defs_test.h
@@ -0,0 +1,56 @@
+// -*- mode: C; tab-width: 4 ; indent-tabs-mode: nil -*-
+//
+// Unfified Keyboard Project
+// ASDF keyboard firmware
+//
+// asdf_keymap_defs.h
+//
+// gathers up all the keymap definitions to be included in the firmware.
+//
+// Copyright 2019 David Fenyes
+//
+// 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 .
+
+// While there is nothing preventing a standard keyboard from having both a
+// "Shift Lock" key and a "Caps Lock" key, usually only one will be present. For
+// testing, both must be present to test their functionality.
+
+#if !defined(ASDF_KEYMAP_DEFS_H)
+#define ASDF_KEYMAP_DEFS_H
+
+#include "asdf.h"
+#include "asdf_ascii.h"
+#include "asdf_modifiers.h"
+#include "Keymaps/asdf_keymap_defs_test.h"
+#include "Keymaps/asdf_keymap_defs_test2.h"
+
+
+#define ASDF_TEST_BASE 0
+#define ASDF_TEST2_BASE (ASDF_TEST_BASE + ASDF_TEST_KEYMAPS_COUNT)
+
+#define ASDF_NUM_KEYMAPS (ASDF_TEST_BASE + ASDF_TEST_KEYMAPS_COUNT + ASDF_TEST2_KEYMAPS_COUNT)
+
+#define ASDF_KEYMAP_DEFS { ASDF_TEST_KEYMAPS, ASDF_TEST2_KEYMAPS }
+
+#define ASDF_KEYMAP_DECLARATIONS ASDF_TEST_DECLARATIONS ASDF_TEST2_DECLARATIONS
+
+
+typedef asdf_keycode_t keycode_matrix_t[ASDF_NUM_ROWS][ASDF_NUM_COLS];
+
+
+
+#endif /* !defined (ASDF_KEYMAP_DEFS_H) */
+
+//-------|---------|---------+---------+---------+---------+---------+---------+
+// Above line is 80 columns, and should display completely in the editor.
diff --git a/firmware/asdf/src/Keymaps/asdf_keymap_defs_ascii.h b/firmware/asdf/src/Keymaps/asdf_keymap_defs_ascii.h
index b22c922..352e78f 100644
--- a/firmware/asdf/src/Keymaps/asdf_keymap_defs_ascii.h
+++ b/firmware/asdf/src/Keymaps/asdf_keymap_defs_ascii.h
@@ -3,10 +3,9 @@
// Unfified Keyboard Project
// ASDF keyboard firmware
//
-// asdf_keymaps.h -- Swapped 'O' and '0' version.
+// asdf_keymaps_ascii.h
//
-// This keymap is for use with rev 1.2 or earlier of the starndard ASCII key
-// matrix. That version has swapped position of the 'O' and '0' keys.
+// Ascii keymaps
//
// Copyright 2019 David Fenyes
//
@@ -24,118 +23,144 @@
// this program. If not, see .
-#if !defined(ASDF_KEYMAP_DEFS_H)
-#define ASDF_KEYMAP_DEFS_H
+// To use this ascii for a new keymap, edit the keymaps definitions as
+// desired. The keymaps are organized from row 0, counting upward, and each row
+// includes the columns from 0-NUM_COLS.
+//
-#include "asdf.h"
-#include "asdf_ascii.h"
-#include "asdf_modifiers.h"
+#if !defined(ASDF_KEYMAP_DEFS_ASCII_H)
+#define ASDF_KEYMAP_DEFS_ASCII_H
+
+#include "../asdf_modifiers.h"
+
+// Edit the number of rows and columns used in this map. If the number is less
+// than the maxium, the unused elements will be initialized to 0.
+
+#define ASDF_ASCII_NUM_ROWS 16 // DIP switches are row 15.
+#define ASDF_ASCII_NUM_COLS 8
+
+#if !defined(ASDF_NUM_ROWS) || (ASDF_NUM_ROWS < ASDF_ASCII_NUM_ROWS)
+#undef ASDF_NUM_ROWS
+#define ASDF_NUM_ROWS ASDF_ASCII_NUM_ROWS
+#endif
+
+#if !defined(ASDF_NUM_COLS) || (ASDF_NUM_COLS < ASDF_ASCII_NUM_COLS)
+#undef ASDF_NUM_COLS
+#define ASDF_NUM_COLS ASDF_ASCII_NUM_COLS
+#endif
+
+// TO ensure consistent DIP switch operation within the keymap, a
+// ASDF_ASCII_DIP_SWITCHES macro is defined. Keeping the ACTION_MAPSEL0-3
+// definitions in positions 0-3 ensures consistent map selection among all
+// keymaps.
-#define ASDF_NUM_ROWS 8
-#define ASDF_NUM_COLS 8
+#define ASDF_ASCII_DIP_SWITCHES [ASDF_NUM_ROWS - 1] = { ACTION_MAPSEL_0, ACTION_MAPSEL_1, ACTION_MAPSEL_2, ACTION_MAPSEL_3 }
-#define ASCII_PLAIN_MAP \
- { \
- { ACTION_NOTHING, ACTION_SHIFT, ACTION_SHIFT, ACTION_NOTHING, \
- ACTION_NOTHING, ASCII_ESC, ACTION_CTRL, ASCII_BACKSLASH }, \
- { ASCII_DEL, 'p', ';', '/', ASCII_SPACE, 'z', 'a', 'q' }, \
- { ACTION_BREAK, ASCII_COMMA, 'm', 'n', 'b', 'v', 'c', 'x' }, \
- { ACTION_NOTHING, 'k', 'j', 'h', 'g', 'f', 'd', 's' }, \
- { ACTION_CLEAR, 'i', 'u', 'y', 't', 'r', 'e', 'w' }, { ACTION_REPEAT, \
- ACTION_HERE_IS, \
- ACTION_CAPS, \
- ASCII_CR, \
- ASCII_LF, \
- 'O', \
- 'l', \
- ASCII_PERIOD }, \
- { ASCII_TILDE, ASCII_RT_SQUARE_BRACE, ASCII_LT_SQUARE_BRACE, '-', ':', 'o', '9', '8' }, \
- { \
- ASCII_AT, '7', '6', '5', '4', '3', '2', '1' \
- } \
+#define ASDF_ASCII_PLAIN_MAP \
+ { \
+ [0] = { ACTION_NOTHING, ACTION_SHIFT, ACTION_SHIFT, ACTION_NOTHING, \
+ ACTION_NOTHING, ASCII_ESC, ACTION_CTRL, ASCII_BACKSLASH }, \
+ [1] = { ASCII_DEL, 'p', ';', '/', ASCII_SPACE, 'z', 'a', 'q' }, \
+ [2] = { ACTION_BREAK, ASCII_COMMA, 'm', 'n', 'b', 'v', 'c', 'x' }, \
+ [3] = { ACTION_NOTHING, 'k', 'j', 'h', 'g', 'f', 'd', 's' }, \
+ [4] = { ACTION_CLEAR, 'i', 'u', 'y', 't', 'r', 'e', 'w' }, \
+ [5] = { ACTION_REPEAT, ACTION_HERE_IS, ACTION_CAPS, ASCII_CR, ASCII_LF, 'o', 'l', ASCII_PERIOD }, \
+ [6] = { ASCII_TILDE, ASCII_RT_SQUARE_BRACE, ASCII_LT_SQUARE_BRACE, '-', ':', ASCII_ZERO, '9', '8' }, \
+ [7] = { ASCII_AT, '7', '6', '5', '4', '3', '2', '1' }, \
+ ASDF_ASCII_DIP_SWITCHES \
}
-#define ASCII_CAPS_MAP \
- { \
- { ACTION_NOTHING, ACTION_SHIFT, ACTION_SHIFT, ACTION_NOTHING, \
- ACTION_NOTHING, ASCII_ESC, ACTION_CTRL, ASCII_BACKSLASH }, \
- { ASCII_DEL, 'P', ';', '/', ASCII_SPACE, 'Z', 'A', 'Q' }, \
- { ACTION_BREAK, ASCII_COMMA, 'M', 'N', 'B', 'V', 'C', 'X' }, \
- { ACTION_NOTHING, 'K', 'J', 'H', 'G', 'F', 'D', 'S' }, \
- { ACTION_CLEAR, 'I', 'U', 'Y', 'T', 'R', 'E', 'W' }, { ACTION_REPEAT, \
- ACTION_HERE_IS, \
- ACTION_CAPS, \
- ASCII_CR, \
- ASCII_LF, \
- 'O', \
- 'L', \
- ASCII_PERIOD }, \
- { ASCII_TILDE, ASCII_RT_SQUARE_BRACE, ASCII_LT_SQUARE_BRACE, '-', ':', ASCII_ZERO, '9', '8' }, \
- { \
- ASCII_AT, '7', '6', '5', '4', '3', '2', '1' \
- } \
+#define ASDF_ASCII_CAPS_MAP \
+ { \
+ [0] = { ACTION_NOTHING, ACTION_SHIFT, ACTION_SHIFT, ACTION_NOTHING, \
+ ACTION_NOTHING, ASCII_ESC, ACTION_CTRL, ASCII_BACKSLASH }, \
+ [1] = { ASCII_DEL, 'P', ';', '/', ASCII_SPACE, 'Z', 'A', 'Q' }, \
+ [2] = { ACTION_BREAK, ASCII_COMMA, 'M', 'N', 'B', 'V', 'C', 'X' }, \
+ [3] = { ACTION_NOTHING, 'K', 'J', 'H', 'G', 'F', 'D', 'S' }, \
+ [4] = { ACTION_CLEAR, 'I', 'U', 'Y', 'T', 'R', 'E', 'W' }, \
+ [5] = { ACTION_REPEAT, ACTION_HERE_IS, ACTION_CAPS, ASCII_CR, ASCII_LF, 'O', 'L', ASCII_PERIOD }, \
+ [6] = { ASCII_TILDE, ASCII_RT_SQUARE_BRACE, ASCII_LT_SQUARE_BRACE, '-', ':', ASCII_ZERO, '9', '8' }, \
+ [7] = { ASCII_AT, '7', '6', '5', '4', '3', '2', '1' }, \
+ ASDF_ASCII_DIP_SWITCHES \
}
-#define ASCII_SHIFT_MAP \
- { \
- { ACTION_NOTHING, ACTION_SHIFT, ACTION_SHIFT, ACTION_NOTHING, \
- ACTION_NOTHING, ASCII_ESC, ACTION_CTRL, ASCII_VERT_BAR }, \
- { ASCII_DEL, 'P', '+', '?', ASCII_SPACE, 'Z', 'A', 'Q' }, \
- { ACTION_BREAK, '<', 'M', 'N', 'B', 'V', 'C', 'X' }, \
- { ACTION_NOTHING, 'K', 'J', 'H', 'G', 'F', 'D', 'S' }, \
- { ACTION_CLEAR, 'I', 'U', 'Y', 'T', 'R', 'E', 'W' }, \
- { ACTION_REPEAT, ACTION_HERE_IS, ACTION_CAPS, ASCII_CR, ASCII_LF, 'O', 'L', '>' }, \
- { ASCII_TILDE, ASCII_RT_CURLY_BRACE, ASCII_LT_CURLY_BRACE, '=', '*', \
- ASCII_ZERO, ASCII_RT_PAREN, ASCII_LT_PAREN }, \
- { \
- ASCII_GRAVE_ACCENT, ASCII_SINGLE_QUOTE, '&', '%', '$', '#', ASCII_DOUBLE_QUOTE, '!' \
- } \
+#define ASDF_ASCII_SHIFT_MAP \
+ { \
+ [0] = { ACTION_NOTHING, ACTION_SHIFT, ACTION_SHIFT, ACTION_NOTHING, \
+ ACTION_NOTHING, ASCII_ESC, ACTION_CTRL, ASCII_VERT_BAR }, \
+ [1] = { ASCII_DEL, 'P', '+', '?', ASCII_SPACE, 'Z', 'A', 'Q' }, \
+ [2] = { ACTION_BREAK, '<', 'M', 'N', 'B', 'V', 'C', 'X' }, \
+ [3] = { ACTION_NOTHING, 'K', 'J', 'H', 'G', 'F', 'D', 'S' }, \
+ [4] = { ACTION_CLEAR, 'I', 'U', 'Y', 'T', 'R', 'E', 'W' }, \
+ [5] = { ACTION_REPEAT, ACTION_HERE_IS, ACTION_CAPS, ASCII_CR, ASCII_LF, 'O', 'L', '>' }, \
+ [6] = { ASCII_TILDE, ASCII_RT_CURLY_BRACE, ASCII_LT_CURLY_BRACE, '=', \
+ '*', ASCII_ZERO, ASCII_RT_PAREN, ASCII_LT_PAREN }, \
+ [7] = { ASCII_GRAVE_ACCENT, ASCII_SINGLE_QUOTE, '&', '%', '$', '#', ASCII_DOUBLE_QUOTE, '!' }, \
+ ASDF_ASCII_DIP_SWITCHES \
}
-#define ASCII_CTRL_MAP \
- { \
- { ACTION_NOTHING, ACTION_SHIFT, ACTION_SHIFT, ACTION_NOTHING, \
+#define ASDF_ASCII_CTRL_MAP \
+ { \
+ [0] = { ACTION_NOTHING, ACTION_SHIFT, ACTION_SHIFT, ACTION_NOTHING, \
ACTION_NOTHING, ASCII_ESC, ACTION_CTRL, 0x1c }, \
- { ACTION_NOTHING, ASCII_CTRL_P, ACTION_NOTHING, ACTION_NOTHING, \
+ [1] = { ACTION_NOTHING, ASCII_CTRL_P, ACTION_NOTHING, ACTION_NOTHING, \
ASCII_SPACE, ASCII_CTRL_Z, ASCII_CTRL_A, ASCII_CTRL_Q }, \
- { ACTION_RESET /*ctrl-break is RESET*/, \
- ASCII_COMMA, \
- ASCII_CTRL_M, \
- ASCII_CTRL_N, \
- ASCII_CTRL_B, \
- ASCII_CTRL_V, \
- ASCII_CTRL_C, \
- ASCII_CTRL_X }, \
- { ACTION_CLEAR, ASCII_CTRL_I, ASCII_CTRL_U, ASCII_CTRL_Y, \
+ [2] = { ACTION_RESET, ASCII_COMMA, ASCII_CTRL_M, ASCII_CTRL_N, \
+ ASCII_CTRL_B, ASCII_CTRL_V, ASCII_CTRL_C, ASCII_CTRL_X }, \
+ [3] = { ACTION_NOTHING, ASCII_CTRL_K, ASCII_CTRL_J, ASCII_CTRL_H, \
+ ASCII_CTRL_G, ASCII_CTRL_F, ASCII_CTRL_D, ASCII_CTRL_S }, \
+ [4] = { ACTION_CLEAR, ASCII_CTRL_I, ASCII_CTRL_U, ASCII_CTRL_Y, \
ASCII_CTRL_T, ASCII_CTRL_R, ASCII_CTRL_E, ASCII_CTRL_W }, \
- { ACTION_REPEAT, ACTION_HERE_IS, ACTION_CAPS, ASCII_CR, \
- ASCII_LF, ACTION_FN_10, ASCII_CTRL_L, ACTION_NOTHING }, \
- { ACTION_NOTHING, 0x1d, ASCII_ESC, ACTION_NOTHING, \
- ACTION_NOTHING, ASCII_CTRL_O, ACTION_FN_9, ACTION_FN_8 }, \
- { \
- ACTION_NOTHING, ACTION_FN_7, ACTION_FN_6, ACTION_FN_5, ACTION_FN_4, ACTION_FN_3, \
- ACTION_FN_2, ACTION_FN_2 \
- } \
+ [5] = { ACTION_REPEAT, ACTION_HERE_IS, ACTION_CAPS, ASCII_CR, \
+ ASCII_LF, ASCII_CTRL_O, ASCII_CTRL_L, ACTION_NOTHING }, \
+ [6] = { ACTION_NOTHING, 0x1d, ASCII_ESC, ACTION_NOTHING, \
+ ACTION_NOTHING, ACTION_FN_10, ACTION_FN_9, ACTION_FN_8 }, \
+ [7] = { ACTION_NOTHING, ACTION_FN_7, ACTION_FN_6, ACTION_FN_5, \
+ ACTION_FN_4, ACTION_FN_3, ACTION_FN_2, ACTION_FN_1 }, \
+ ASDF_ASCII_DIP_SWITCHES \
}
-// PROCEDURE: asdf_keymaps_init
-// INPUTS: none
-// OUTPUTS: none
-// DESCRIPTION: Assigns the keymaps to the indices specified by the modifier
-// index, to avoid hard-coding constant index values.
-void asdf_keymaps_init(void);
-
-// PROCEDURE: asdf_keymaps_get_code
-// INPUTS: row, col: row and column of key that has been pressed
-// modifiers_index: index into the keymap array, based on modifier state
-// OUTPUTS: returns a key code.
-// DESCRIPTION: Given a key row and column, and an index based on modifier
-// state, return the appropriate keycode.
-asdf_keycode_t asdf_keymaps_get_code(uint8_t row, uint8_t col, uint8_t modifier_index);
+#define ASDF_ASCII_MAP_DECLARATIONS \
+ static const FLASH keycode_matrix_t ascii_plain_matrix = ASDF_ASCII_PLAIN_MAP; \
+ static const FLASH keycode_matrix_t ascii_shift_matrix = ASDF_ASCII_SHIFT_MAP; \
+ static const FLASH keycode_matrix_t ascii_caps_matrix = ASDF_ASCII_CAPS_MAP; \
+ static const FLASH keycode_matrix_t ascii_ctrl_matrix = ASDF_ASCII_CTRL_MAP;
-#endif /* !defined (ASDF_KEYMAP_DEFS_H) */
+// Here, you can specify which maps are associated with which modifier keys.
+// There can be multiple definitions. For example, as shown here, an ALL CAPS
+// keymap can be made by assigning the caps map to the "no modifier" position.
+// Or, more additional keymaps can be defined above, and keymap sets can be
+// defined below that pick and choose between them. The modifiers are assigned as follows:
+//
+// [0]: plain (no modifiers)
+// [1]: shift (shift key or shift lock active)
+// [2]: caps (caps lock active)
+// [3]: ctrl: (control key active)
+
+#define ASDF_ASCII_PLAIN_MAP_DEFS \
+ { \
+ [MOD_PLAIN_MAP] = &ascii_plain_matrix, \
+ [MOD_SHIFT_MAP] = &ascii_shift_matrix, \
+ [MOD_CAPS_MAP] = &ascii_caps_matrix, \
+ [MOD_CTRL_MAP] = &ascii_ctrl_matrix \
+ }
+
+#define ASDF_ASCII_CAPS_MAP_DEFS \
+ { \
+ [MOD_PLAIN_MAP] = &ascii_caps_matrix, \
+ [MOD_SHIFT_MAP] = &ascii_shift_matrix, \
+ [MOD_CAPS_MAP] = &ascii_caps_matrix, \
+ [MOD_CTRL_MAP] = &ascii_ctrl_matrix \
+ }
+
+#define ASDF_ASCII_ALL_MAPS ASDF_ASCII_PLAIN_MAP_DEFS, ASDF_ASCII_CAPS_MAP_DEFS
+
+#define ASDF_ASCII_ALL_MAPS_COUNT 2
+
+#endif /* !defined (ASDF_KEYMAP_DEFS_ASCII_H) */
//-------|---------|---------+---------+---------+---------+---------+---------+
// Above line is 80 columns, and should display completely in the editor.
+
diff --git a/firmware/asdf/src/Keymaps/asdf_keymap_defs_template.h b/firmware/asdf/src/Keymaps/asdf_keymap_defs_template.h
new file mode 100644
index 0000000..46a34cc
--- /dev/null
+++ b/firmware/asdf/src/Keymaps/asdf_keymap_defs_template.h
@@ -0,0 +1,166 @@
+// -*- mode: C; tab-width: 4 ; indent-tabs-mode: nil -*-
+//
+// Unfified Keyboard Project
+// ASDF keyboard firmware
+//
+// asdf_keymaps_template.h
+//
+// Template file for adding new keymaps.
+//
+// Copyright 2019 David Fenyes
+//
+// 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 .
+
+
+// To use this template for a new keymap, edit the keymaps definitions as
+// desired. The keymaps are organized from row 0, counting upward, and each row
+// includes the columns from 0-NUM_COLS.
+//
+
+#if !defined(ASDF_KEYMAP_DEFS_TEMPLATE_H)
+#define ASDF_KEYMAP_DEFS_TEMPLATE_H
+
+#include "asdf_modifier.h"
+
+// Edit the number of rows and columns used in this map. If the number is less
+// than the maxium, the unused elements will be initialized to 0.
+
+#define ASDF_TEMPLATE_NUM_ROWS 16 // DIP switches are row 15.
+#define ASDF_TEMPLATE_NUM_COLS 8
+
+#if !defined(ASDF_NUM_ROWS) || (ASDF_NUM_ROWS < ASDF_TEMPLATE_NUM_ROWS)
+#undef ASDF_NUM_ROWS
+#define ASDF_NUM_ROWS ASDF_TEMPLATE_NUM_ROWS
+#endif
+
+#if !defined(ASDF_NUM_COLS) || (ASDF_NUM_COLS < ASDF_ASCII_NUM_COLS)
+#undef ASDF_NUM_COLS
+#define ASDF_NUM_COLS ASDF_TEMPLATE_NUM_COLS
+#endif
+
+// TO ensure consistent DIP switch operation within the keymap, a
+// ASDF_TEMPLATE_DIP_SWITCHES macro is defined. Keeping the ACTION_MAPSEL0-3
+// definitions in positions 0-3 ensures consistent map selection among all
+// keymaps.
+
+#define ASDF_TEMPLATE_DIP_SWITCHES \
+ [ASDF_LAST_ROW] = { ACTION_MAPSEL_0, ACTION_MAPSEL_1, ACTION_MAPSEL_2, ACTION_MAPSEL_3 }
+
+#define ASDF_TEMPLATE_PLAIN_MAP \
+ { \
+ [0] = { ACTION_NOTHING, ACTION_SHIFT, ACTION_SHIFT, ACTION_NOTHING, \
+ ACTION_NOTHING, ASCII_ESC, ACTION_CTRL, ASCII_BACKSLASH }, \
+ [1] = { ASCII_DEL, 'p', ';', '/', ASCII_SPACE, 'z', 'a', 'q' }, \
+ [2] = { ACTION_BREAK, ASCII_COMMA, 'm', 'n', 'b', 'v', 'c', 'x' }, \
+ [3] = { ACTION_NOTHING, 'k', 'j', 'h', 'g', 'f', 'd', 's' }, \
+ [4] = { ACTION_CLEAR, 'i', 'u', 'y', 't', 'r', 'e', 'w' }, \
+ [5] = { ACTION_REPEAT, ACTION_HERE_IS, ACTION_CAPS, ASCII_CR, ASCII_LF, 'o', 'l', ASCII_PERIOD }, \
+ [6] = { ASCII_TILDE, ASCII_RT_SQUARE_BRACE, ASCII_LT_SQUARE_BRACE, '-', ':', ASCII_ZERO, '9', '8' }, \
+ [7] = { ASCII_AT, '7', '6', '5', '4', '3', '2', '1' },
+ ASDF_TEMPLATE_DIP_SWITCHES \
+ }
+
+#define ASDF_TEMPLATE_CAPS_MAP \
+ { \
+ [0] = { ACTION_NOTHING, ACTION_SHIFT, ACTION_SHIFT, ACTION_NOTHING, \
+ ACTION_NOTHING, ASCII_ESC, ACTION_CTRL, ASCII_BACKSLASH }, \
+ [1] = { ASCII_DEL, 'P', ';', '/', ASCII_SPACE, 'Z', 'A', 'Q' }, \
+ [2] = { ACTION_BREAK, ASCII_COMMA, 'M', 'N', 'B', 'V', 'C', 'X' }, \
+ [3] = { ACTION_NOTHING, 'K', 'J', 'H', 'G', 'F', 'D', 'S' }, \
+ [4] = { ACTION_CLEAR, 'I', 'U', 'Y', 'T', 'R', 'E', 'W' }, \
+ [5] = { ACTION_REPEAT, ACTION_HERE_IS, ACTION_CAPS, ASCII_CR, ASCII_LF, 'O', 'L', ASCII_PERIOD }, \
+ [6] = { ASCII_TILDE, ASCII_RT_SQUARE_BRACE, ASCII_LT_SQUARE_BRACE, '-', ':', ASCII_ZERO, '9', '8' }, \
+ [7] = { ASCII_AT, '7', '6', '5', '4', '3', '2', '1' }, \
+ ASDF_TEMPLATE_DIP_SWITCHES \
+ }
+
+#define ASDF_TEMPLATE_SHIFT_MAP \
+ { \
+ [0] = { ACTION_NOTHING, ACTION_SHIFT, ACTION_SHIFT, ACTION_NOTHING, \
+ ACTION_NOTHING, ASCII_ESC, ACTION_CTRL, ASCII_VERT_BAR }, \
+ [1] = { ASCII_DEL, 'P', '+', '?', ASCII_SPACE, 'Z', 'A', 'Q' }, \
+ [2] = { ACTION_BREAK, '<', 'M', 'N', 'B', 'V', 'C', 'X' }, \
+ [3] = { ACTION_NOTHING, 'K', 'J', 'H', 'G', 'F', 'D', 'S' }, \
+ [4] = { ACTION_CLEAR, 'I', 'U', 'Y', 'T', 'R', 'E', 'W' }, \
+ [5] = { ACTION_REPEAT, ACTION_HERE_IS, ACTION_CAPS, ASCII_CR, ASCII_LF, 'O', 'L', '>' }, \
+ [6] = { ASCII_TILDE, ASCII_RT_CURLY_BRACE, ASCII_LT_CURLY_BRACE, '=', \
+ '*', ASCII_ZERO, ASCII_RT_PAREN, ASCII_LT_PAREN }, \
+ [7] = { ASCII_GRAVE_ACCENT, ASCII_SINGLE_QUOTE, '&', '%', '$', '#', ASCII_DOUBLE_QUOTE, '!' }, \
+ ASDF_TEMPLATE_DIP_SWITCHES \
+ }
+
+#define ASDF_TEMPLATE_CTRL_MAP \
+ { \
+ [0] = { ACTION_NOTHING, ACTION_SHIFT, ACTION_SHIFT, ACTION_NOTHING, \
+ ACTION_NOTHING, ASCII_ESC, ACTION_CTRL, 0x1c }, \
+ [1] = { ACTION_NOTHING, ASCII_CTRL_P, ACTION_NOTHING, ACTION_NOTHING, \
+ ASCII_SPACE, ASCII_CTRL_Z, ASCII_CTRL_A, ASCII_CTRL_Q }, \
+ [2] = { ACTION_RESET, ASCII_COMMA, ASCII_CTRL_M, ASCII_CTRL_N, \
+ ASCII_CTRL_B, ASCII_CTRL_V, ASCII_CTRL_C, ASCII_CTRL_X }, \
+ [3] = { ACTION_NOTHING, ASCII_CTRL_K, ASCII_CTRL_J, ASCII_CTRL_H, \
+ ASCII_CTRL_G, ASCII_CTRL_F, ASCII_CTRL_D, ASCII_CTRL_S },
+ [4] = { ACTION_CLEAR, ASCII_CTRL_I, ASCII_CTRL_U, ASCII_CTRL_Y, \
+ ASCII_CTRL_T, ASCII_CTRL_R, ASCII_CTRL_E, ASCII_CTRL_W }, \
+ [5] = { ACTION_REPEAT, ACTION_HERE_IS, ACTION_CAPS, ASCII_CR, \
+ ASCII_LF, ASCII_CTRL_O, ASCII_CTRL_L, ACTION_NOTHING }, \
+ [6] = { ACTION_NOTHING, 0x1d, ASCII_ESC, ACTION_NOTHING, \
+ ACTION_NOTHING, ACTION_FN_10, ACTION_FN_9, ACTION_FN_8 }, \
+ [7] = { ACTION_NOTHING, ACTION_FN_7, ACTION_FN_6, ACTION_FN_5, \
+ ACTION_FN_4, ACTION_FN_3, ACTION_FN_2, ACTION_FN_2 }, \
+ }, ASDF_TEMPLATE_DIP_SWITCHES \
+ }
+
+#define ASDF_TEMPLATE_MAP_DECLARATIONS \
+ static const FLASH keycode_matrix_t template_plain_matrix = ASDF_TEMPLATE_PLAIN_MAP; \
+ static const FLASH keycode_matrix_t template_shift_matrix = ASDF_TEMPLATE_SHIFT_MAP; \
+ static const FLASH keycode_matrix_t template_caps_matrix = ASDF_TEMPLATE_CAPS_MAP; \
+ static const FLASH keycode_matrix_t template_ctrl_matrix = ASDF_TEMPLATE_CTRL_MAP;
+
+
+// Here, you can specify which maps are associated with which modifier keys.
+// There can be multiple definitions. For example, as shown here, an ALL CAPS
+// keymap can be made by assigning the caps map to the "no modifier" position.
+// Or, more additional keymaps can be defined above, and keymap sets can be
+// defined below that pick and choose between them. The modifiers are assigned as follows:
+//
+// [0]: plain (no modifiers)
+// [1]: shift (shift key or shift lock active)
+// [2]: caps (caps lock active)
+// [3]: ctrl: (control key active)
+
+#define ASDF_TEMPLATE_PLAIN_MAP_DEFS \
+ { \
+ [MOD_PLAIN_MAP] = &template_plain_matrix, \
+ [MOD_SHIFT_MAP] = &template_shift_matrix, \
+ [MOD_CAPS_MAP] = &template_caps_matrix, \
+ [MOD_CTRL_MAP] = &template_ctrl_matrix \
+ }
+
+#define ASDF_TEMPLATE_CAPS_MAP_DEFS \
+ { \
+ [MOD_PLAIN_MAP] = &template_caps_matrix, \
+ [MOD_SHIFT_MAP] = &template_shift_matrix, \
+ [MOD_CAPS_MAP] = &template_caps_matrix, \
+ [MOD_CTRL_MAP] = &template_ctrl_matrix \
+ }
+
+#define ASDF_TEMPLATE_ALL_MAPS ASDF_TEMPLATE_PLAIN_MAP_DEFS, ASDF_TEMPLATE_CAPS_MAP_DEFS
+
+#define ASDF_TEMPLATE_ALL_MAPS_COUNT 2
+
+#endif /* !defined (ASDF_KEYMAP_DEFS_TEMPLATE_H) */
+
+//-------|---------|---------+---------+---------+---------+---------+---------+
+// Above line is 80 columns, and should display completely in the editor.
+ P
diff --git a/firmware/asdf/src/Keymaps/asdf_keymap_defs_test.h b/firmware/asdf/src/Keymaps/asdf_keymap_defs_test.h
index b596907..8f8830d 100644
--- a/firmware/asdf/src/Keymaps/asdf_keymap_defs_test.h
+++ b/firmware/asdf/src/Keymaps/asdf_keymap_defs_test.h
@@ -24,61 +24,72 @@
// "Shift Lock" key and a "Caps Lock" key, usually only one will be present. For
// testing, both must be present to test their functionality.
-#if !defined(ASDF_KEYMAP_DEFS_H)
-#define ASDF_KEYMAP_DEFS_H
+#if !defined(ASDF_KEYMAP_DEFS_TEST_H)
+#define ASDF_KEYMAP_DEFS_TEST_H
-#include "asdf.h"
-#include "asdf_ascii.h"
-#include "asdf_modifiers.h"
+#define ASDF_TEST_NUM_ROWS 9
+#define ASDF_TEST_NUM_COLS 8
-#define ASDF_NUM_ROWS 8
-#define ASDF_NUM_COLS 8
+// The first value in each row serves two purposes:
+//
+// 1) Indicate a valid row of codes if the value is nonzero.
+// 2) Indicate the physical row number corresponding to the keymap row.
+//
+// Multiple keymaps may be combined, some of which use more rows than other
+// keymaps. The keymap with the most rows determines how many rows are allocated
+// for each keymap. Since each keymap only initializes the rows it uses, then
+// the shorter keymaps may have multiple uninitialized rows that should not be
+// scanned. The C99 standard guarantees that all elements no explicitly
+// initialized shall be initialized to 0 (C99 Standard 6.7.8.21). Therefore,
+// keymap rows starting with a 0 are not valid and are not scanned.
+//
+// Some hardware may contain blank physical rows To avoid having unused empty
+// rows, the first column of each row indicates the physical row. For example, 8
+// rows of switches (0-7), and a bank of DIP switches on row 15. In this case,
+// only 9 rows need be allocated.
-#define ASCII_PLAIN_MAP \
+
+#define PLAIN_MATRIX_1 RESERVED_1
+#define CAPS_MATRIX_1 RESERVED_2
+#define SHIFT_MATRIX_1 RESERVED_3
+#define CTRL_MATRIX_1 RESERVED_4
+
+#define ASDF_LAST_ROW (ASDF_NUM_ROWS - 1)
+#define ASDF_TEST_MAP_DIP_SWITCHES \
+ [ASDF_LAST_ROW] = { ACTION_MAPSEL_0, ACTION_MAPSEL_1, ACTION_MAPSEL_2, ACTION_MAPSEL_3 }
+
+#define ASDF_TEST_PLAIN_MAP \
{ \
- { ACTION_CAPS, ACTION_SHIFT, ACTION_SHIFT, ACTION_NOTHING, \
- ACTION_NOTHING, ASCII_ESC, ACTION_CTRL, ASCII_BACKSLASH }, \
+ { PLAIN_MATRIX_1, ACTION_SHIFT, ACTION_SHIFT, ACTION_NOTHING, \
+ ACTION_CAPS, ASCII_ESC, ACTION_CTRL, ASCII_BACKSLASH }, \
{ ACTION_NOTHING, 'p', ';', '/', ASCII_SPACE, 'z', 'a', 'q' }, \
{ ACTION_BREAK, ASCII_COMMA, 'm', 'n', 'b', 'v', 'c', 'x' }, \
{ ACTION_NOTHING, 'k', 'j', 'h', 'g', 'f', 'd', 's' }, \
- { ACTION_CLEAR, 'i', 'u', 'y', 't', 'r', 'e', 'w' }, { ACTION_REPEAT, \
- ACTION_HERE_IS, \
- ACTION_SHIFT_LOCK, \
- ASCII_CR, \
- ASCII_LF, \
- 'o', \
- 'l', \
- ASCII_PERIOD }, \
+ { ACTION_CLEAR, 'i', 'u', 'y', 't', 'r', 'e', 'w' }, \
+ /**/ { ACTION_REPEAT, ACTION_HERE_IS, ACTION_SHIFT_LOCK, ASCII_CR, ASCII_LF, 'o', \
+ 'l', ASCII_PERIOD }, \
{ ASCII_TILDE, ASCII_RT_SQUARE_BRACE, ASCII_LT_SQUARE_BRACE, '-', ':', '0', '9', '8' }, \
- { \
- ACTION_NOTHING, '7', '6', '5', '4', '3', '2', '1' \
- } \
+ { ACTION_NOTHING, '7', '6', '5', '4', '3', '2', '1' }, ASDF_TEST_MAP_DIP_SWITCHES \
}
-#define ASCII_CAPS_MAP \
+#define ASDF_TEST_CAPS_MAP \
{ \
- { ACTION_NOTHING, ACTION_SHIFT, ACTION_SHIFT, ACTION_NOTHING, \
+ { CAPS_MATRIX_1, ACTION_SHIFT, ACTION_SHIFT, ACTION_NOTHING, \
ACTION_NOTHING, ASCII_ESC, ACTION_CTRL, ASCII_BACKSLASH }, \
{ ACTION_NOTHING, 'P', ';', '/', ASCII_SPACE, 'Z', 'A', 'Q' }, \
{ ACTION_BREAK, ASCII_COMMA, 'M', 'N', 'B', 'V', 'C', 'X' }, \
{ ACTION_NOTHING, 'K', 'J', 'H', 'G', 'F', 'D', 'S' }, \
- { ACTION_CLEAR, 'I', 'U', 'Y', 'T', 'R', 'E', 'W' }, { ACTION_REPEAT, \
- ACTION_HERE_IS, \
- ACTION_SHIFT_LOCK, \
- ASCII_CR, \
- ASCII_LF, \
- 'O', \
- 'L', \
- ASCII_PERIOD }, \
+ { ACTION_CLEAR, 'I', 'U', 'Y', 'T', 'R', 'E', 'W' }, \
+ /**/ { ACTION_REPEAT, ACTION_HERE_IS, ACTION_SHIFT_LOCK, ASCII_CR, ASCII_LF, 'O', \
+ 'L', ASCII_PERIOD }, \
{ ASCII_TILDE, ASCII_RT_SQUARE_BRACE, ASCII_LT_SQUARE_BRACE, '-', ':', '0', '9', '8' }, \
- { \
- ACTION_NOTHING, '7', '6', '5', '4', '3', '2', '1' \
- } \
+ { ACTION_NOTHING, '7', '6', '5', '4', '3', '2', '1' }, ASDF_TEST_MAP_DIP_SWITCHES \
}
-#define ASCII_SHIFT_MAP \
+#define ASDF_TEST_SHIFT_MAP \
{ \
- { ACTION_NOTHING, ACTION_SHIFT, ACTION_SHIFT, ACTION_NOTHING, \
+ \
+ { SHIFT_MATRIX_1, ACTION_SHIFT, ACTION_SHIFT, ACTION_NOTHING, \
ACTION_NOTHING, ASCII_ESC, ACTION_CTRL, ASCII_VERT_BAR }, \
{ ACTION_NOTHING, 'P', '+', '?', ASCII_SPACE, 'Z', 'A', 'Q' }, \
{ ACTION_BREAK, '>', 'M', 'N', 'B', 'V', 'C', 'X' }, \
@@ -87,48 +98,75 @@
{ ACTION_REPEAT, ACTION_HERE_IS, ACTION_SHIFT_LOCK, ASCII_CR, ASCII_LF, 'O', 'L', '<' }, \
{ ASCII_TILDE, ASCII_RT_CURLY_BRACE, ASCII_LT_CURLY_BRACE, '=', '*', \
'0', ASCII_RT_PAREN, ASCII_LT_PAREN }, \
- { \
- ACTION_NOTHING, ASCII_SINGLE_QUOTE, '&', '%', '$', '#', ASCII_DOUBLE_QUOTE, '!' \
- } \
+ { ACTION_NOTHING, ASCII_SINGLE_QUOTE, '&', '%', '$', '#', ASCII_DOUBLE_QUOTE, '!' }, \
+ ASDF_TEST_MAP_DIP_SWITCHES \
}
-#define ASCII_CTRL_MAP \
+
+#define ASDF_TEST_CTRL_MAP \
{ \
- { ACTION_NOTHING, ACTION_SHIFT, ACTION_SHIFT, ACTION_NOTHING, \
+ { CTRL_MATRIX_1, ACTION_SHIFT, ACTION_SHIFT, ACTION_NOTHING, \
ACTION_NOTHING, ASCII_ESC, ACTION_CTRL, 0x1c }, \
{ ACTION_NOTHING, ASCII_CTRL_P, ACTION_NOTHING, ACTION_NOTHING, \
ASCII_SPACE, ASCII_CTRL_Z, ASCII_CTRL_A, ASCII_CTRL_Q }, \
{ ACTION_BREAK, ASCII_COMMA, ASCII_CTRL_M, ASCII_CTRL_N, \
ASCII_CTRL_B, ASCII_CTRL_V, ASCII_CTRL_C, ASCII_CTRL_X }, \
+ { ACTION_NOTHING, ASCII_CTRL_K, ASCII_CTRL_J, ASCII_CTRL_H, \
+ ASCII_CTRL_G, ASCII_CTRL_F, ASCII_CTRL_D, ASCII_CTRL_S }, \
{ ACTION_CLEAR, ASCII_CTRL_I, ASCII_CTRL_U, ASCII_CTRL_Y, \
ASCII_CTRL_T, ASCII_CTRL_R, ASCII_CTRL_E, ASCII_CTRL_W }, \
{ ACTION_REPEAT, ACTION_HERE_IS, ACTION_SHIFT_LOCK, ASCII_CR, \
ASCII_LF, ASCII_CTRL_O, ASCII_CTRL_L, ACTION_NOTHING }, \
{ ACTION_NOTHING, 0x1d, ASCII_ESC, ACTION_NOTHING, \
ACTION_NOTHING, ACTION_FN_1, ACTION_FN_9, ACTION_FN_8 }, \
- { \
- ACTION_NOTHING, ACTION_FN_7, ACTION_FN_6, ACTION_FN_5, ACTION_FN_4, ACTION_FN_3, \
- ACTION_FN_2, ACTION_FN_2 \
- } \
+ { ACTION_NOTHING, ACTION_FN_7, ACTION_FN_6, ACTION_FN_5, \
+ ACTION_FN_4, ACTION_FN_3, ACTION_FN_2, ACTION_FN_2 }, \
+ ASDF_TEST_MAP_DIP_SWITCHES \
}
-// PROCEDURE: asdf_keymaps_init
-// INPUTS: none
-// OUTPUTS: none
-// DESCRIPTION: Assigns the keymaps to the indices specified by the modifier
-// index, to avoid hard-coding constant index values.
-void asdf_keymaps_init(void);
-// PROCEDURE: asdf_keymaps_get_code
-// INPUTS: row, col: row and column of key that has been pressed
-// modifiers_index: index into the keymap array, based on modifier state
-// OUTPUTS: returns a key code.
-// DESCRIPTION: Given a key row and column, and an index based on modifier
-// state, return the appropriate keycode.
-asdf_keycode_t asdf_keymaps_get_code(uint8_t row, uint8_t col, uint8_t modifier_index);
+#define ASDF_TEST_DECLARATIONS \
+ static const FLASH keycode_matrix_t test_PLAIN_matrix = ASDF_TEST_PLAIN_MAP; \
+ static const FLASH keycode_matrix_t test_SHIFT_matrix = ASDF_TEST_SHIFT_MAP; \
+ static const FLASH keycode_matrix_t test_CAPS_matrix = ASDF_TEST_CAPS_MAP; \
+ static const FLASH keycode_matrix_t test_CTRL_matrix = ASDF_TEST_CTRL_MAP;
+
+#define ASDF_TEST_MAP_DEFS \
+ { \
+ &test_PLAIN_matrix, &test_SHIFT_matrix, &test_CAPS_matrix, &test_CTRL_matrix \
+ }
+
+#define ASDF_TEST_CAPS_MAP_DEFS \
+ { \
+ &test_CAPS_matrix, &test_SHIFT_matrix, &test_CAPS_matrix, &test_CTRL_matrix \
+ }
+
+#define ASDF_TEST_KEYMAPS ASDF_TEST_MAP_DEFS, ASDF_TEST_CAPS_MAP_DEFS
+
+#define ASDF_TEST_KEYMAPS_COUNT 2
+#define ASDF_TEST_PLAIN_MAP_INDEX ASDF_TEST_BASE + 0
+#define ASDF_TEST_CAPS_MAP_INDEX ASDF_TEST_BASE + 1
+
+// The following preprocessor "code" permits various keymaps to be created and
+// included without generating a lot of complicating code dependencies. The use
+// of macros in this way is a bit ugly, I realize, and stretches the intention
+// of the C preprocessor. The C preprocessor is used to store a bit of state to
+// keep track of the number and ordering of the keymaps as they are added, and
+// to keep track of the array sizes to be allocated at compile time.
-#endif /* !defined (ASDF_KEYMAP_DEFS_H) */
+#if !defined(ASDF_NUM_ROWS) || (ASDF_NUM_ROWS < ASDF_TEST_NUM_ROWS)
+#undef ASDF_NUM_ROWS
+#define ASDF_NUM_ROWS ASDF_TEST_NUM_ROWS
+#endif
+
+#if !defined(ASDF_NUM_COLS) || (ASDF_NUM_COLS < ASDF_TEST_NUM_COLS)
+#undef ASDF_NUM_COLS
+#define ASDF_NUM_COLS ASDF_TEST_NUM_COLS
+#endif
+
+
+#endif /* !defined (ASDF_KEYMAP_DEFS_TEST_H) */
//-------|---------|---------+---------+---------+---------+---------+---------+
// Above line is 80 columns, and should display completely in the editor.
diff --git a/firmware/asdf/src/Keymaps/asdf_keymap_defs_test2.h b/firmware/asdf/src/Keymaps/asdf_keymap_defs_test2.h
new file mode 100644
index 0000000..2213424
--- /dev/null
+++ b/firmware/asdf/src/Keymaps/asdf_keymap_defs_test2.h
@@ -0,0 +1,173 @@
+// -*- mode: C; tab-width: 4 ; indent-tabs-mode: nil -*-
+//
+// Unfified Keyboard Project
+// ASDF keyboard firmware
+//
+// asdf_keymaps.h
+//
+// Copyright 2019 David Fenyes
+//
+// 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 .
+
+// While there is nothing preventing a standard keyboard from having both a
+// "Shift Lock" key and a "Caps Lock" key, usually only one will be present. For
+// testing, both must be present to test their functionality.
+
+#if !defined(ASDF_KEYMAP_DEFS_TEST2_H)
+#define ASDF_KEYMAP_DEFS_TEST2_H
+
+#define ASDF_TEST2_NUM_ROWS 16
+#define ASDF_TEST2_NUM_COLS 8
+
+// The first value in each row serves two purposes:
+//
+// 1) Indicate a valid row of codes if the value is nonzero.
+// 2) Indicate the physical row number corresponding to the keymap row.
+//
+// Multiple keymaps may be combined, some of which use more rows than other
+// keymaps. The keymap with the most rows determines how many rows are allocated
+// for each keymap. Since each keymap only initializes the rows it uses, then
+// the shorter keymaps may have multiple uninitialized rows that should not be
+// scanned. The C99 standard guarantees that all elements no explicitly
+// initialized shall be initialized to 0 (C99 Standard 6.7.8.21). Therefore,
+// keymap rows starting with a 0 are not valid and are not scanned.
+//
+// Some hardware may contain blank physical rows To avoid having unused empty
+// rows, the first column of each row indicates the physical row. For example, 8
+// rows of switches (0-7), and a bank of DIP switches on row 15. In this case,
+// only 9 rows need be allocated.
+
+
+#define PLAIN_MATRIX_2 RESERVED_5
+#define CAPS_MATRIX_2 RESERVED_6
+#define SHIFT_MATRIX_2 RESERVED_7
+#define CTRL_MATRIX_2 RESERVED_8
+
+#define ASDF_LAST_ROW (ASDF_NUM_ROWS - 1)
+
+#define ASDF_TEST_MAP_DIP_SWITCHES \
+ [ASDF_LAST_ROW] = { ACTION_MAPSEL_0, ACTION_MAPSEL_1, ACTION_MAPSEL_2, ACTION_MAPSEL_3 }
+
+#define ASDF_TEST2_PLAIN_MAP \
+ { \
+ { PLAIN_MATRIX_2, ACTION_SHIFT, ACTION_SHIFT, ACTION_NOTHING, \
+ ACTION_CAPS, ASCII_ESC, ACTION_CTRL, ASCII_BACKSLASH }, \
+ { ACTION_NOTHING, 'p', ';', '/', ASCII_SPACE, 'z', 'a', 'q' }, \
+ { ACTION_BREAK, ASCII_COMMA, 'm', 'n', 'b', 'v', 'c', 'x' }, \
+ { ACTION_NOTHING, 'k', 'j', 'h', 'g', 'f', 'd', 's' }, \
+ { ACTION_CLEAR, 'i', 'u', 'y', 't', 'r', 'e', 'w' }, \
+ /**/ { ACTION_REPEAT, ACTION_HERE_IS, ACTION_SHIFT_LOCK, ASCII_CR, ASCII_LF, 'o', \
+ 'l', ASCII_PERIOD }, \
+ { ASCII_TILDE, ASCII_RT_SQUARE_BRACE, ASCII_LT_SQUARE_BRACE, '-', ':', '0', '9', '8' }, \
+ { ACTION_NOTHING, '7', '6', '5', '4', '3', '2', '1' }, ASDF_TEST_MAP_DIP_SWITCHES \
+ }
+
+#define ASDF_TEST2_CAPS_MAP \
+ { \
+ { CAPS_MATRIX_2, ACTION_SHIFT, ACTION_SHIFT, ACTION_NOTHING, \
+ ACTION_NOTHING, ASCII_ESC, ACTION_CTRL, ASCII_BACKSLASH }, \
+ { ACTION_NOTHING, 'P', ';', '/', ASCII_SPACE, 'Z', 'A', 'Q' }, \
+ { ACTION_BREAK, ASCII_COMMA, 'M', 'N', 'B', 'V', 'C', 'X' }, \
+ { ACTION_NOTHING, 'K', 'J', 'H', 'G', 'F', 'D', 'S' }, \
+ { ACTION_CLEAR, 'I', 'U', 'Y', 'T', 'R', 'E', 'W' }, \
+ /**/ { ACTION_REPEAT, ACTION_HERE_IS, ACTION_SHIFT_LOCK, ASCII_CR, ASCII_LF, 'O', \
+ 'L', ASCII_PERIOD }, \
+ { ASCII_TILDE, ASCII_RT_SQUARE_BRACE, ASCII_LT_SQUARE_BRACE, '-', ':', '0', '9', '8' }, \
+ { ACTION_NOTHING, '7', '6', '5', '4', '3', '2', '1' }, ASDF_TEST_MAP_DIP_SWITCHES \
+ }
+
+#define ASDF_TEST2_SHIFT_MAP \
+ { \
+ \
+ { SHIFT_MATRIX_2, ACTION_SHIFT, ACTION_SHIFT, ACTION_NOTHING, \
+ ACTION_NOTHING, ASCII_ESC, ACTION_CTRL, ASCII_VERT_BAR }, \
+ { ACTION_NOTHING, 'P', '+', '?', ASCII_SPACE, 'Z', 'A', 'Q' }, \
+ { ACTION_BREAK, '>', 'M', 'N', 'B', 'V', 'C', 'X' }, \
+ { ACTION_NOTHING, 'K', 'J', 'H', 'G', 'F', 'D', 'S' }, \
+ { ACTION_CLEAR, 'I', 'U', 'Y', 'T', 'R', 'E', 'W' }, \
+ { ACTION_REPEAT, ACTION_HERE_IS, ACTION_SHIFT_LOCK, ASCII_CR, ASCII_LF, 'O', 'L', '<' }, \
+ { ASCII_TILDE, ASCII_RT_CURLY_BRACE, ASCII_LT_CURLY_BRACE, '=', '*', \
+ '0', ASCII_RT_PAREN, ASCII_LT_PAREN }, \
+ { ACTION_NOTHING, ASCII_SINGLE_QUOTE, '&', '%', '$', '#', ASCII_DOUBLE_QUOTE, '!' }, \
+ ASDF_TEST_MAP_DIP_SWITCHES \
+ }
+
+
+#define ASDF_TEST2_CTRL_MAP \
+ { \
+ { CTRL_MATRIX_2, ACTION_SHIFT, ACTION_SHIFT, ACTION_NOTHING, \
+ ACTION_NOTHING, ASCII_ESC, ACTION_CTRL, 0x1c }, \
+ { ACTION_NOTHING, ASCII_CTRL_P, ACTION_NOTHING, ACTION_NOTHING, \
+ ASCII_SPACE, ASCII_CTRL_Z, ASCII_CTRL_A, ASCII_CTRL_Q }, \
+ { ACTION_BREAK, ASCII_COMMA, ASCII_CTRL_M, ASCII_CTRL_N, \
+ ASCII_CTRL_B, ASCII_CTRL_V, ASCII_CTRL_C, ASCII_CTRL_X }, \
+ { ACTION_NOTHING, ASCII_CTRL_K, ASCII_CTRL_J, ASCII_CTRL_H, \
+ ASCII_CTRL_G, ASCII_CTRL_F, ASCII_CTRL_D, ASCII_CTRL_S }, \
+ { ACTION_CLEAR, ASCII_CTRL_I, ASCII_CTRL_U, ASCII_CTRL_Y, \
+ ASCII_CTRL_T, ASCII_CTRL_R, ASCII_CTRL_E, ASCII_CTRL_W }, \
+ { ACTION_REPEAT, ACTION_HERE_IS, ACTION_SHIFT_LOCK, ASCII_CR, \
+ ASCII_LF, ASCII_CTRL_O, ASCII_CTRL_L, ACTION_NOTHING }, \
+ { ACTION_NOTHING, 0x1d, ASCII_ESC, ACTION_NOTHING, \
+ ACTION_NOTHING, ACTION_FN_1, ACTION_FN_9, ACTION_FN_8 }, \
+ { ACTION_NOTHING, ACTION_FN_7, ACTION_FN_6, ACTION_FN_5, \
+ ACTION_FN_4, ACTION_FN_3, ACTION_FN_2, ACTION_FN_2 }, \
+ ASDF_TEST_MAP_DIP_SWITCHES \
+ }
+
+
+#define ASDF_TEST2_DECLARATIONS \
+ static const FLASH keycode_matrix_t test2_PLAIN_matrix = ASDF_TEST2_PLAIN_MAP; \
+ static const FLASH keycode_matrix_t test2_SHIFT_matrix = ASDF_TEST2_SHIFT_MAP; \
+ static const FLASH keycode_matrix_t test2_CAPS_matrix = ASDF_TEST2_CAPS_MAP; \
+ static const FLASH keycode_matrix_t test2_CTRL_matrix = ASDF_TEST2_CTRL_MAP;
+
+#define ASDF_TEST2_MAP_DEFS \
+ { \
+ &test2_PLAIN_matrix, &test2_SHIFT_matrix, &test2_CAPS_matrix, &test2_CTRL_matrix \
+ }
+
+#define ASDF_TEST2_CAPS_MAP_DEFS \
+ { \
+ &test2_CAPS_matrix, &test2_SHIFT_matrix, &test2_CAPS_matrix, &test2_CTRL_matrix \
+ }
+
+#define ASDF_TEST2_KEYMAPS ASDF_TEST2_MAP_DEFS, ASDF_TEST2_CAPS_MAP_DEFS
+
+#define ASDF_TEST2_KEYMAPS_COUNT 2
+#define ASDF_TEST2_PLAIN_MAP_INDEX (ASDF_TEST2_BASE + 0)
+#define ASDF_TEST2_CAPS_MAP_INDEX (ASDF_TEST2_BASE + 1)
+
+// The following preprocessor "code" permits various keymaps to be created and
+// included without generating a lot of complicating code dependencies. The use
+// of macros in this way is a bit ugly, I realize, and stretches the intention
+// of the C preprocessor. The C preprocessor is used to store a bit of state to
+// keep track of the number and ordering of the keymaps as they are added, and
+// to keep track of the array sizes to be allocated at compile time.
+
+
+#if !defined(ASDF_NUM_ROWS) || (ASDF_NUM_ROWS < ASDF_TEST2_NUM_ROWS)
+#undef ASDF_NUM_ROWS
+#define ASDF_NUM_ROWS ASDF_TEST2_NUM_ROWS
+#endif
+
+#if !defined(ASDF_NUM_COLS) || (ASDF_NUM_COLS < ASDF_TEST2_NUM_COLS)
+#undef ASDF_NUM_COLS
+#define ASDF_NUM_COLS ASDF_TEST2_NUM_COLS
+#endif
+
+
+#endif /* !defined (ASDF_KEYMAP_DEFS_TEST2_H) */
+
+//-------|---------|---------+---------+---------+---------+---------+---------+
+// Above line is 80 columns, and should display completely in the editor.
diff --git a/firmware/asdf/src/Makefile.app b/firmware/asdf/src/Makefile.app
index e88dfeb..83a7aa0 100644
--- a/firmware/asdf/src/Makefile.app
+++ b/firmware/asdf/src/Makefile.app
@@ -1,7 +1,7 @@
# -*- makefile -*-
ARCH ?= atmega328p
-KEYMAP ?= ascii
+KEYMAP ?= production
ARCH_TOKEN = _Arch_$(ARCH)
@@ -67,7 +67,9 @@ MAKEDEPEND = $(CPP) $(DEPFLAGS) $(CPPFLAGS) $< \
| sed -n 's,^\# *[0-9][0-9]* *"\([^"<]*\)".*,$@: \1\n\1:,p' \
| sort -u > $*.d
-SRC_FILES = main.c asdf.c asdf_modifiers.c asdf_repeat.c asdf_keymaps.c asdf_buffer.c asdf_arch.c asdf_actions.c
+SRC_FILES = main.c asdf.c asdf_modifiers.c asdf_repeat.c asdf_keymaps.c
+SRC_FILES += asdf_buffer.c asdf_arch.c asdf_actions.c
+
OBJ_FILES := $(SRC_FILES:.c=.o)
DEP_FILES := $(SRC_FILES:%.c=$(DEP_DIR)/%.d)
MAP_FILE = $(TARGET).map
@@ -100,7 +102,7 @@ include $(wildcard $(DEPFILES))
%.o: %.c $(DEP_DIR)/%.d | $(DEP_DIR)
$(CC) -c $(CPPFLAGS) $(CFLAGS) $(DEPFLAGS) $<
-asdf_keymap_defs.h: $(KEYMAPS_DIR)/asdf_keymap_defs_$(KEYMAP).h $(KEYMAPDEFS_H_TOKEN)
+asdf_keymap_defs.h: $(KEYMAPS_DIR)/asdf_all_keymap_defs_$(KEYMAP).h $(KEYMAPDEFS_H_TOKEN)
cp $< $@
GENERATED_FILES += asdf_keymap_defs.h
diff --git a/firmware/asdf/src/Makefile.test b/firmware/asdf/src/Makefile.test
index 8c21642..f99d407 100644
--- a/firmware/asdf/src/Makefile.test
+++ b/firmware/asdf/src/Makefile.test
@@ -76,7 +76,7 @@ TEST5_BUILD = $(BUILD_DIR)/test_$(TEST5)
all: test
-asdf_keymap_defs.h: Keymaps/asdf_keymap_defs_$(KEYMAP).h
+asdf_keymap_defs.h: $(KEYMAPS_DIR)/asdf_all_keymap_defs_$(KEYMAP).h $(KEYMAPDEFS_H_TOKEN)
cp $< $@
GENERATED_FILES += asdf_keymap_defs.h
diff --git a/firmware/asdf/src/asdf_keymaps.c b/firmware/asdf/src/asdf_keymaps.c
index e78d52b..9da3952 100644
--- a/firmware/asdf/src/asdf_keymaps.c
+++ b/firmware/asdf/src/asdf_keymaps.c
@@ -26,15 +26,44 @@
#include "asdf_keymaps.h"
#include "asdf_keymap_defs.h"
-typedef asdf_keycode_t keycode_matrix_t[ASDF_NUM_ROWS][ASDF_NUM_COLS];
+// ASDF_KEYMAP_DECLARATIONS is defined in asdf_keymap_defs.h, agregated from all
+// the included keymap definition files.
+//
+// This is a terrible practice, but defining the declarations as a macro permits
+// the keymap definitions to be incorporated in a fairly modular fashion, using
+// the limited capabilities of the C preprocessor. One alternative is to use a
+// program (in C or at the expense of additional build dependencies, in python
+// or bash) to generate the keymap definitions and declarations. But then the
+// keymap declarations would not be private. constexpr in C++ may be an
+// alternative option as well.
+ASDF_KEYMAP_DECLARATIONS;
-static const FLASH keycode_matrix_t plain_matrix = ASCII_PLAIN_MAP;
-static const FLASH keycode_matrix_t shift_matrix = ASCII_SHIFT_MAP;
-static const FLASH keycode_matrix_t caps_matrix = ASCII_CAPS_MAP;
-static const FLASH keycode_matrix_t ctrl_matrix = ASCII_CTRL_MAP;
+static keycode_matrix_t const *keymap_matrix[ASDF_NUM_KEYMAPS][ASDF_MOD_NUM_MODIFIERS] =
+ ASDF_KEYMAP_DEFS;
-static keycode_matrix_t const *modifier_matrix[MOD_NUM_MAPS];
+static uint8_t keymap_index;
+// PROCEDURE: asdf_keymaps_select_keymap
+// INPUTS: (uint8_t) index - index of the keymap number to select
+// OUTPUTS: none
+//
+// DESCRIPTION: accepts a index value. If the requested keymap index is valid,
+// then assign the value to the global (to the module) keymap_index variable.
+//
+// SIDE EFFECTS: May change the module-global keymap_index variable.
+//
+// NOTES: If the requested index is not valid, then no action is performed.
+//
+// SCOPE: public
+//
+// COMPLEXITY: 2
+//
+void asdf_keymaps_select_keymap(uint8_t index)
+{
+ if (index < ASDF_NUM_KEYMAPS) {
+ keymap_index = index;
+ }
+}
// PROCEDURE: asdf_keymaps_init
// INPUTS: none
@@ -51,10 +80,6 @@ static keycode_matrix_t const *modifier_matrix[MOD_NUM_MAPS];
//
void asdf_keymaps_init(void)
{
- modifier_matrix[MOD_PLAIN_MAP] = &plain_matrix;
- modifier_matrix[MOD_SHIFT_MAP] = &shift_matrix;
- modifier_matrix[MOD_CAPS_MAP] = &caps_matrix;
- modifier_matrix[MOD_CTRL_MAP] = &ctrl_matrix;
}
// PROCEDURE: asdf_keymaps_get_code
diff --git a/firmware/asdf/src/asdf_modifiers.h b/firmware/asdf/src/asdf_modifiers.h
index 3d1cb05..110b0a1 100644
--- a/firmware/asdf/src/asdf_modifiers.h
+++ b/firmware/asdf/src/asdf_modifiers.h
@@ -53,7 +53,7 @@ typedef enum {
MOD_SHIFT_MAP,
MOD_CAPS_MAP,
MOD_CTRL_MAP,
- MOD_NUM_MAPS
+ ASDF_MOD_NUM_MODIFIERS
} modifier_index_t;
typedef enum { TOGGLE_SHIFTLOCK = 0, HOLD_SHIFTLOCK = 1 } shiftlock_mode_t;