1 /* Copyright (C) 2011 by Jacob Alexander
3 * Permission is hereby granted, free of charge, to any person obtaining a copy
4 * of this software and associated documentation files (the "Software"), to deal
5 * in the Software without restriction, including without limitation the rights
6 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 * copies of the Software, and to permit persons to whom the Software is
8 * furnished to do so, subject to the following conditions:
10 * The above copyright notice and this permission notice shall be included in
11 * all copies or substantial portions of the Software.
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 // ----- Includes -----
31 #define REG_SET(reg) reg |= (1 << ( matrix[row][col] % 10 ) )
33 #define PIN_SET_COL(pin) \
34 switch ( scanMode ) { \
36 case scanCol_powrRow: \
38 REG_SET(port##pin); break; \
39 case scanRow_powrCol: REG_SET(ddr##pin); REG_SET(port##pin); break; \
43 #define PIN_SET_ROW(pin) \
44 switch ( scanMode ) { \
46 case scanRow_powrCol: \
48 REG_SET(port##pin); break; \
49 case scanCol_powrRow: REG_SET(ddr##pin); REG_SET(port##pin); break; \
53 #define PIN_CASE(pinLetter) \
54 case pin##pinLetter##0: \
55 case pin##pinLetter##1: \
56 case pin##pinLetter##2: \
57 case pin##pinLetter##3: \
58 case pin##pinLetter##4: \
59 case pin##pinLetter##5: \
60 case pin##pinLetter##6: \
61 case pin##pinLetter##7
63 #define PIN_TEST_COL(pin) \
64 if ( !( pin & ( 1 << ( matrix[0][col] % 10 ) ) \
65 detectArray[matrix[row][col]]++; \
70 // ----- Variables -----
72 uint8_t KeyIndex_Array[KEYBOARD_SIZE + 1];
76 // ----- Functions -----
78 void matrix_pinSetup( uint8_t *matrix )
80 // Setup the variables
95 // Loop through all the pin assignments, for the initial pin settings
99 for ( row = 1; row < sizeof(matrix); row++ ) {
100 switch ( matrix[row][col] ) {
120 for ( col = 1; col < sizeof(matrix[0]); row++ ) {
121 switch ( matrix[row][col] ) {
156 // TODO Proper matrix scanning
157 void matrix_scan( uint8_t *matrix, uint8_t *detectArray )
160 #if scanMode == scanCol
163 for ( ; col < sizeof(matrix[1]); col++ ) {
164 switch ( matrix[0][col] / 10 ) {
182 #if scanMode == scanRow
185 // Column Scan, Power Row
186 #if scanMode == scanCol_powrRow
189 // Row Scan, Power Column
190 #if scanMode == scanRow_powrCol
194 #if scanMode == scanDual