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
24 #define REG_SET(reg) reg |= (1 << ( matrix[row][col] % 10 ) )
26 #define PIN_SET_COL(pin) \
27 switch ( scanMode ) { \
29 case scanCol_powrRow: \
31 REG_SET(port##pin); break; \
32 case scanRow_powrCol: REG_SET(ddr##pin); REG_SET(port##pin); break; \
36 #define PIN_SET_ROW(pin) \
37 switch ( scanMode ) { \
39 case scanRow_powrCol: \
41 REG_SET(port##pin); break; \
42 case scanCol_powrRow: REG_SET(ddr##pin); REG_SET(port##pin); break; \
46 #define PIN_CASE(pinLetter) \
47 case pin##pinLetter##0: \
48 case pin##pinLetter##1: \
49 case pin##pinLetter##2: \
50 case pin##pinLetter##3: \
51 case pin##pinLetter##4: \
52 case pin##pinLetter##5: \
53 case pin##pinLetter##6: \
54 case pin##pinLetter##7
56 #define PIN_TEST_COL(pin) \
57 if ( !( pin & ( 1 << ( matrix[0][col] % 10 ) ) \
58 detectArray[matrix[row][col]]++; \
62 void matrix_pinSetup( uint8_t *matrix )
64 // Setup the variables
79 // Loop through all the pin assignments, for the initial pin settings
83 for ( row = 1; row < sizeof(matrix); row++ ) {
84 switch ( matrix[row][col] ) {
104 for ( col = 1; col < sizeof(matrix[0]); row++ ) {
105 switch ( matrix[row][col] ) {
140 // TODO Proper matrix scanning
141 void matrix_scan( uint8_t *matrix, uint8_t *detectArray )
144 #if scanMode == scanCol
147 for ( ; col < sizeof(matrix[1]); col++ ) {
148 switch ( matrix[0][col] / 10 ) {
166 #if scanMode == scanRow
169 // Column Scan, Power Row
170 #if scanMode == scanCol_powrRow
173 // Row Scan, Power Column
174 #if scanMode == scanRow_powrCol
178 #if scanMode == scanDual