From e3042a3526f59d767cfa276231668382ead758e4 Mon Sep 17 00:00:00 2001
From: Jacob Alexander <triplehaata@gmail.com>
Date: Sun, 16 Oct 2011 21:38:56 -0700
Subject: [PATCH] Making sub-modules of matrix for HeathZenith and BudKeypad

- Parent module no longer allows for a stand-alone compile
- Added HeathZenith matrix (pinout still needs to be done)
- Updated the HeathZenith keymaps
- Changed the original example matrix.h to matrix_template.h
---
 Keymap/heathzenith.h                        | 10 +--
 Scan/BudKeypad/matrix.h                     | 80 +++++++++++++++++++++
 Scan/BudKeypad/setup.cmake                  | 35 +++++++++
 Scan/HeathZenith/matrix.h                   | 69 ++++++++++++++++++
 Scan/HeathZenith/setup.cmake                | 35 +++++++++
 Scan/matrix/{matrix.h => matrix_template.h} |  4 ++
 Scan/matrix/setup.cmake                     | 13 ++--
 setup.cmake                                 |  2 +-
 8 files changed, 238 insertions(+), 10 deletions(-)
 create mode 100644 Scan/BudKeypad/matrix.h
 create mode 100644 Scan/BudKeypad/setup.cmake
 create mode 100644 Scan/HeathZenith/matrix.h
 create mode 100644 Scan/HeathZenith/setup.cmake
 rename Scan/matrix/{matrix.h => matrix_template.h} (99%)

diff --git a/Keymap/heathzenith.h b/Keymap/heathzenith.h
index 559ef8c..848aebe 100644
--- a/Keymap/heathzenith.h
+++ b/Keymap/heathzenith.h
@@ -27,11 +27,11 @@
 
 // ----- Variables -----
 
-static uint8_t  keyboard_modifierMask[] = { 1, 17, 33, 49 };
-static uint8_t alternate_modifierMask[] = { 1, 17, 33, 49, 62 };
+static uint8_t  heathzenith_ModifierMask [] = { 1, 17, 33, 49 };
+static uint8_t  heathzenith_AlternateMask[] = { 1, 17, 33, 49, 62 };
 
 // Default 1-indexed key mappings
-static uint8_t defaultMap[] = { 0,
+static uint8_t heathzenith_DefaultMap[] = { 0,
 				KEY_GUI,
 				KEY_1,
 				KEY_2,
@@ -96,7 +96,7 @@ static uint8_t defaultMap[] = { 0,
 				KEY_RIGHT,
 				KEY_SPACE
 };
-static uint8_t navigationMap[] = { 0,
+static uint8_t heathzenith_NavigationMap[] = { 0,
 				KEY_GUI,
 				KEY_F1,
 				KEY_F2,
@@ -162,7 +162,7 @@ static uint8_t navigationMap[] = { 0,
 				KEY_SPACE
 };
 
-static uint8_t colemakMap[] = { 0,
+static uint8_t heathzenith_ColemakMap[] = { 0,
 				KEY_GUI,
 				KEY_1,
 				KEY_2,
diff --git a/Scan/BudKeypad/matrix.h b/Scan/BudKeypad/matrix.h
new file mode 100644
index 0000000..1430623
--- /dev/null
+++ b/Scan/BudKeypad/matrix.h
@@ -0,0 +1,80 @@
+/* Copyright (C) 2011 by Jacob Alexander
+ * 
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ * 
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#ifndef __MATRIX_H
+#define __MATRIX_H
+
+// ----- Includes -----
+
+// Compiler Includes
+#include <stdint.h>
+
+
+
+// ----- Scan Mode Setting (See matrix_scan.h for more details) -----
+#define scanMode scanCol
+
+
+
+// ----- Key Settings -----
+
+#define KEYBOARD_SIZE 16 // # of keys
+#define MAX_ROW_SIZE  16 // # of keys in the largest row
+#define MAX_COL_SIZE   1 // # of keys in the largest column
+
+
+
+// ----- Matrix Configuration -----
+static const uint8_t matrix_pinout[][MAX_ROW_SIZE + 1] = {
+
+
+
+// Just layout the matrix by rows and columns
+// Usually you'll want to set the scanMode above to scanDual or scanCol_powrRow/scanRow_powrCol
+// The mode allows for optimization in the kind of scanning algorithms that are done
+// 
+// The key numbers are used to translate into the keymap table (array) (and always start from 1, not 0).
+// Thus if a row doesn't use all the key positions, you can denote it as 0, which will be ignored/skipped on each scan
+// See the keymap.h file for the various preconfigured arrays.
+
+// Scan Mode | Col 1 | Col 2 | Col 3 | Col 4 | Col 5 | ...
+// -------------------------------------------------------
+//     Row 1 | Key 1   Key 7   Key32    ...
+//     Row 2 | Key 3   Key92    ...
+//     Row 3 | Key23    ...
+//     Row 4 |  ...
+//     Row 5 |
+//      ...  |
+
+// See Scan/matrix/matrix_template.h for more details
+
+
+  { scanMode, pinF0, pinF4, pinB7, pinD3, pinF5, pinF1, pinD1, pinD2, pinF6, pinF7, pinB2, pinD0, pinB0, pinB6, pinB1, pinB3 },
+  { pinNULL,  1,     2,     3,     4,     5,     6,     7,     8,     9,     10,    11,    12,    13,    14,    15,    16    },
+
+
+
+};
+
+
+
+#endif // __MATRIX_H
+
diff --git a/Scan/BudKeypad/setup.cmake b/Scan/BudKeypad/setup.cmake
new file mode 100644
index 0000000..25493f0
--- /dev/null
+++ b/Scan/BudKeypad/setup.cmake
@@ -0,0 +1,35 @@
+###| CMake Kiibohd Controller Scan Module |###
+#
+# Written by Jacob Alexander in 2011 for the Kiibohd Controller
+#
+# Released into the Public Domain
+#
+###
+
+
+###
+# Module C files
+#
+
+#| XXX Requires the ../ due to how the paths are constructed
+set( SCAN_SRCS
+	../matrix/matrix_scan.c
+	../matrix/scan_loop.c
+)
+
+
+###
+# Module Specific Options
+#
+add_definitions( -I${HEAD_DIR}/Keymap )
+add_definitions(
+	-I${HEAD_DIR}/Scan/matrix
+)	
+
+#| Keymap Settings
+add_definitions(
+	-DMODIFIER_MASK=budkeypad_ModifierMask
+	#-DKEYINDEX_MASK=budkeypad_TheProfosistMap
+	-DKEYINDEX_MASK=budkeypad_DefaultMap
+)
+
diff --git a/Scan/HeathZenith/matrix.h b/Scan/HeathZenith/matrix.h
new file mode 100644
index 0000000..5792661
--- /dev/null
+++ b/Scan/HeathZenith/matrix.h
@@ -0,0 +1,69 @@
+/* Copyright (C) 2011 by Jacob Alexander
+ * 
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ * 
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#ifndef __MATRIX_H
+#define __MATRIX_H
+
+// ----- Includes -----
+
+// Compiler Includes
+#include <stdint.h>
+
+
+
+// ----- Scan Mode Setting (See matrix_scan.h for more details) -----
+#define scanMode scanDual
+
+
+
+// ----- Key Settings -----
+
+#define KEYBOARD_SIZE 63 // # of keys
+#define MAX_ROW_SIZE  12 // # of keys in the largest row
+#define MAX_COL_SIZE   9 // # of keys in the largest column
+
+
+
+// ----- Matrix Configuration -----
+static const uint8_t matrix_pinout[][MAX_ROW_SIZE + 1] = {
+
+
+// TODO Pinout
+// Note: Pins 49 and 60 are connected together, by row AND column, why? dunno...(shift)
+  { scanMode, pinF0, pinF4, pinB7, pinD3, pinF5, pinF1, pinD1, pinD2, pinE0, pinE1, pinE2, pinE3 },
+  { pinF6,    1,     2,     3,     4,     5,     6,     7,     8,     0,     0,     0,     0     },
+  { pinF7,    16,    15,    14,    13,    12,    11,    10,    9,     0,     0,     0,     0     },
+  { pinB2,    17,    18,    19,    20,    21,    22,    23,    24,    0,     0,     0,     0     },
+  { pinD0,    32,    31,    30,    29,    28,    27,    26,    25,    0,     0,     0,     0     },
+  { pinB6,    35,    36,    37,    38,    39,    40,    41,    42,    0,     0,     0,     0     },
+  { pinB3,    47,    61,    46,    45,    44,    43,    58,    0,     0,     0,     0,     0     },
+  { pinA0,    50,    51,    52,    53,    54,    55,    56,    57,    0,     0,     0,     0     },
+  { pinB0,    62,    63,    0,     0,     59,    0,     0,     0,     0,     0,     0,     0     },
+  { pinB0,    0,     0,     0,     0,     0,     0,     0,     0,     33,    34,    48,    49    },
+
+
+
+};
+
+
+
+#endif // __MATRIX_H
+
diff --git a/Scan/HeathZenith/setup.cmake b/Scan/HeathZenith/setup.cmake
new file mode 100644
index 0000000..e95e10a
--- /dev/null
+++ b/Scan/HeathZenith/setup.cmake
@@ -0,0 +1,35 @@
+###| CMake Kiibohd Controller Scan Module |###
+#
+# Written by Jacob Alexander in 2011 for the Kiibohd Controller
+#
+# Released into the Public Domain
+#
+###
+
+
+###
+# Module C files
+#
+
+#| XXX Requires the ../ due to how the paths are constructed
+set( SCAN_SRCS
+	../matrix/matrix_scan.c
+	../matrix/scan_loop.c
+)
+
+
+###
+# Module Specific Options
+#
+add_definitions( -I${HEAD_DIR}/Keymap )
+add_definitions(
+	-I${HEAD_DIR}/Scan/matrix
+)	
+
+#| Keymap Settings
+add_definitions(
+	-DMODIFIER_MASK=heathzenith_ModifierMask
+	-DKEYINDEX_MASK=heathzenith_DefaultMap
+	#-DKEYINDEX_MASK=heathzenith_ColemakMap
+)
+
diff --git a/Scan/matrix/matrix.h b/Scan/matrix/matrix_template.h
similarity index 99%
rename from Scan/matrix/matrix.h
rename to Scan/matrix/matrix_template.h
index 69904ee..1573af4 100644
--- a/Scan/matrix/matrix.h
+++ b/Scan/matrix/matrix_template.h
@@ -53,9 +53,11 @@
 
 
 // -- Example for scanRow_powrCol, scanCol_powrRow, and scanDual --
+/*
 #define KEYBOARD_SIZE 69 // # of keys
 #define MAX_ROW_SIZE   8 // # of keys in the largest row
 #define MAX_COL_SIZE   9 // # of keys in the largest column
+*/
 
 
 
@@ -113,6 +115,7 @@ static const uint8_t matrix_pinout[][MAX_ROW_SIZE + 1] = {
 
 // -- scanRow_powrCol Example and scanCol_powrRow Example --
 // The example is the same, as the difference is whether the row or col is powered, and the other is used to detect the signal
+/*
   { scanMode, pinF0, pinF4, pinB7, pinD3, pinF5, pinF1, pinD1, pinD2 },
   { pinF6,    1,     2,     3,     4,     5,     6,     7,     8     },
   { pinF7,    9,     10,    11,    12,    13,    14,    15,    16    },
@@ -123,6 +126,7 @@ static const uint8_t matrix_pinout[][MAX_ROW_SIZE + 1] = {
   { pinB1,    28,    24,    34,    44,    54,    64,    0,     49    }, // 0 signifies no key at that location
   { pinB3,    29,    25,    35,    45,    55,    65,    0,     57    },
   { pinA0,    37,    26,    36,    46,    56,    66,    0,     58    },
+*/
 
 
 // -- scanDual Example --
diff --git a/Scan/matrix/setup.cmake b/Scan/matrix/setup.cmake
index e7e52af..38d6d1d 100644
--- a/Scan/matrix/setup.cmake
+++ b/Scan/matrix/setup.cmake
@@ -6,6 +6,13 @@
 #
 ###
 
+###
+# Warning, that this module is not meant to be built stand-alone
+#
+message( FATAL_ERROR
+"The 'matrix' module is not a stand-alone module, and requires further setup.
+See BudKeypad module for as an example module."
+)
 
 ###
 # Module C files
@@ -22,10 +29,8 @@ set( SCAN_SRCS
 #
 add_definitions( -I${HEAD_DIR}/Keymap )
 
-#| Keymap Settings
 add_definitions(
-	-DMODIFIER_MASK=budkeypad_ModifierMask
-	#-DKEYINDEX_MASK=budkeypad_TheProfosistMap
-	-DKEYINDEX_MASK=budkeypad_DefaultMap
+	#-DMODIFIER_MASK=
+	#-DKEYINDEX_MASK=
 )
 
diff --git a/setup.cmake b/setup.cmake
index f841284..719d5a7 100644
--- a/setup.cmake
+++ b/setup.cmake
@@ -20,7 +20,7 @@
 #| Please the {Scan,Macro,USB,Debug}/module.txt for information on the modules and how to create new ones
 
 ##| Deals with acquiring the keypress information and turning it into a key index
-set(  ScanModule  "matrix" )
+set(  ScanModule  "HeathZenith" )
 
 ##| Uses the key index and potentially applies special conditions to it, mapping it to a usb key code
 set( MacroModule  "basic"  )
-- 
2.39.5