]> git.donarmstrong.com Git - kiibohd-controller.git/commitdiff
Adding SKM67001 scan module.
authorJacob Alexander <triplehaata@gmail.com>
Thu, 4 Oct 2012 19:07:06 +0000 (12:07 -0700)
committerJacob Alexander <triplehaata@gmail.com>
Thu, 4 Oct 2012 19:07:06 +0000 (12:07 -0700)
- Uses the matrix module, which is now moderately working now for NKRO diode keyboards

Keymap/keymap.h
Keymap/skm67001.h [new file with mode: 0644]
Scan/SKM67001/matrix.h [new file with mode: 0644]
Scan/SKM67001/setup.cmake [new file with mode: 0644]
Scan/matrix/matrix_scan.c
Scan/matrix/matrix_scan.h
Scan/matrix/scan_loop.c
Scan/matrix/scan_loop.h
setup.cmake

index 121acae4825e1eda62635f4912776d0244299d8e..1fbb0680b9ca780043027e359506400da6e64bf6 100644 (file)
@@ -47,6 +47,7 @@
 #include "heathzenith.h"
 #include "kaypro1.h"
 #include "microswitch8304.h"
+#include "skm67001.h"
 #include "sonynews.h"
 #include "sonyoas3400.h"
 #include "tandy1000.h"
diff --git a/Keymap/skm67001.h b/Keymap/skm67001.h
new file mode 100644 (file)
index 0000000..f5d07f0
--- /dev/null
@@ -0,0 +1,214 @@
+/* Copyright (C) 2012 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 __SKM67001_H
+#define __SKM67001_H
+
+// This file contains various key layouts for the SKM 67001 Keyboard from the Olympia Professional ES 105 Typewriter
+
+
+// ----- Variables -----
+
+static uint8_t  skm67001_ModifierMask [] = { 0x34, 0x38, 0x3A, 0x40 };
+
+// Default 1-indexed key mappings
+static uint8_t skm67001_DefaultMap[] = {
+                               0, // 0x00
+                               KEY_1, // 0x01
+                               KEY_Q, // 0x02
+                               KEY_A, // 0x03
+                               KEY_2, // 0x04
+                               KEY_Z, // 0x05
+                               KEY_W, // 0x06
+                               KEY_S, // 0x07
+                               KEY_3, // 0x08
+                               KEY_X, // 0x09
+                               KEY_E, // 0x0A
+                               KEY_D, // 0x0B
+                               KEY_4, // 0x0C
+                               KEY_C, // 0x0D
+                               KEY_R, // 0x0E
+                               KEY_F, // 0x0F
+                               KEY_5, // 0x10
+                               KEY_V, // 0x11
+                               KEY_T, // 0x12
+                               KEY_G, // 0x13
+                               KEY_6, // 0x14
+                               KEY_B, // 0x15
+                               KEY_Y, // 0x16
+                               KEY_H, // 0x17
+                               KEY_7, // 0x18
+                               KEY_N, // 0x19
+                               KEY_U, // 0x1A
+                               KEY_J, // 0x1B
+                               KEY_8, // 0x1C
+                               KEY_M, // 0x1D
+                               KEY_I, // 0x1E
+                               KEY_K, // 0x1F
+                               KEY_9, // 0x20
+                               KEY_COMMA, // 0x21
+                               KEY_O, // 0x22
+                               KEY_L, // 0x23
+                               KEY_0, // 0x24
+                               KEY_PERIOD, // 0x25
+                               KEY_P, // 0x26
+                               KEY_SEMICOLON, // 0x27
+                               KEY_MINUS, // 0x28
+                               KEY_SLASH, // 0x29
+                               KEY_LEFT_BRACE, // 0x2A (1/4)
+                               KEY_QUOTE, // 0x2B
+                               KEY_EQUAL, // 0x2C
+                               KEY_RIGHT_BRACE, // 0x2D
+                               0, // 0x2E
+                               0, // 0x2F
+                               KEY_TILDE, // 0x30
+                               KEY_TAB, // 0x31
+                               0, // 0x32
+                               0, // 0x33
+                               KEY_SHIFT, // 0x34
+                               KEY_ENTER, // 0x35
+                               KEY_BACKSPACE, // 0x36
+                               KEY_DELETE, // 0x37
+                               KEY_CTRL, // 0x38 (MAR LEFT)
+                               KEY_SPACE, // 0x39
+                               KEY_ALT, // 0x3A (EXPRESS / MAR RIGHT)
+                               0, // 0x3B
+                               0, // 0x3C
+                               KEY_ESC, // 0x3D (MAR REL)
+                               0, // 0x3E (STORE)
+                               0, // 0x3F (RECALL)
+                               KEY_GUI, // 0x40 (CODE)
+                               0, // 0x41
+                               0, // 0x42
+                               0, // 0x43
+                               0, // 0x44
+                               0, // 0x45
+                               0, // 0x46
+                               0, // 0x47
+                               0, // 0x48 (DEC TAB)
+                               0, // 0x49 (SET TAB)
+                               0, // 0x4A (TAB CLEAR)
+                               0, // 0x4B (INDEX)
+                               0, // 0x4C (RELOC)
+                               0, // 0x4D
+                               0, // 0x4E
+                               0, // 0x4F
+                               0, // 0x50 (REV INDEX)
+                               0, // 0x51
+                               0, // 0x52
+                               0, // 0x53
+                               0, // 0x54
+                               0, // 0x55
+};
+
+static uint8_t skm67001_ColemakMap[] = {
+                               0, // 0x00
+                               KEY_1, // 0x01
+                               KEY_Q, // 0x02
+                               KEY_A, // 0x03
+                               KEY_2, // 0x04
+                               KEY_Z, // 0x05
+                               KEY_W, // 0x06
+                               KEY_R, // 0x07
+                               KEY_3, // 0x08
+                               KEY_X, // 0x09
+                               KEY_F, // 0x0A
+                               KEY_S, // 0x0B
+                               KEY_4, // 0x0C
+                               KEY_C, // 0x0D
+                               KEY_P, // 0x0E
+                               KEY_T, // 0x0F
+                               KEY_5, // 0x10
+                               KEY_V, // 0x11
+                               KEY_G, // 0x12
+                               KEY_D, // 0x13
+                               KEY_6, // 0x14
+                               KEY_B, // 0x15
+                               KEY_J, // 0x16
+                               KEY_H, // 0x17
+                               KEY_7, // 0x18
+                               KEY_K, // 0x19
+                               KEY_L, // 0x1A
+                               KEY_N, // 0x1B
+                               KEY_8, // 0x1C
+                               KEY_M, // 0x1D
+                               KEY_U, // 0x1E
+                               KEY_E, // 0x1F
+                               KEY_9, // 0x20
+                               KEY_COMMA, // 0x21
+                               KEY_Y, // 0x22
+                               KEY_I, // 0x23
+                               KEY_0, // 0x24
+                               KEY_PERIOD, // 0x25
+                               KEY_SEMICOLON, // 0x26
+                               KEY_O, // 0x27
+                               KEY_MINUS, // 0x28
+                               KEY_SLASH, // 0x29
+                               KEY_LEFT_BRACE, // 0x2A (1/4)
+                               KEY_QUOTE, // 0x2B
+                               KEY_EQUAL, // 0x2C
+                               KEY_RIGHT_BRACE, // 0x2D
+                               0, // 0x2E
+                               0, // 0x2F
+                               KEY_TILDE, // 0x30
+                               KEY_TAB, // 0x31
+                               0, // 0x32
+                               0, // 0x33
+                               KEY_SHIFT, // 0x34
+                               KEY_ENTER, // 0x35
+                               KEY_BACKSPACE, // 0x36
+                               KEY_DELETE, // 0x37
+                               KEY_CTRL, // 0x38 (MAR LEFT)
+                               KEY_SPACE, // 0x39
+                               KEY_ALT, // 0x3A (EXPRESS / MAR RIGHT)
+                               0, // 0x3B
+                               0, // 0x3C
+                               KEY_ESC, // 0x3D (MAR REL)
+                               0, // 0x3E (STORE)
+                               0, // 0x3F (RECALL)
+                               KEY_GUI, // 0x40 (CODE)
+                               0, // 0x41
+                               0, // 0x42
+                               0, // 0x43
+                               0, // 0x44
+                               0, // 0x45
+                               0, // 0x46
+                               0, // 0x47
+                               0, // 0x48 (DEC TAB)
+                               0, // 0x49 (SET TAB)
+                               0, // 0x4A (TAB CLEAR)
+                               0, // 0x4B (INDEX)
+                               0, // 0x4C (RELOC)
+                               0, // 0x4D
+                               0, // 0x4E
+                               0, // 0x4F
+                               0, // 0x50 (REV INDEX)
+                               0, // 0x51
+                               0, // 0x52
+                               0, // 0x53
+                               0, // 0x54
+                               0, // 0x55
+};
+
+
+
+#endif
+
diff --git a/Scan/SKM67001/matrix.h b/Scan/SKM67001/matrix.h
new file mode 100644 (file)
index 0000000..ebb2833
--- /dev/null
@@ -0,0 +1,79 @@
+/* Copyright (C) 2012 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_powrRow
+
+
+
+// ----- Key Settings -----
+
+#define KEYBOARD_SIZE 85 // # of keys (It actually has 66, but there are markings up to 80 on the PCB); 85 due to there being 5 "switch" keys, that have no numbers
+#define MAX_ROW_SIZE   9 // # 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] = {
+
+
+// SKM Typewriter PCB Matrix
+// Note: Pins 50, 51, and 52 are connected together (LShift, RShift, and Lock)
+// Board Pins: 13      5     12      6     11      9      8      7     10
+  { scanMode, pinC0, pinC7, pinC4, pinC2, pinC6, pinC5, pinC3, pinE1, pinC1, },
+  { pinE6,    71,    72,    73,    74,    75,    76,    80,    55,    53,    }, //  1 - White
+  { pinF7,    43,    81,    45,    41,    54,    44,    46,    58,    42,    }, //  2 - Red
+  { pinF4,    37,    82,    39,    35,    34,    38,    33,    36,    40,    }, //  3 - Pink
+  { pinF5,    31,    83,    25,    28,    27,    32,    26,    30,    29,    }, //  4 - Black
+//{ pinXX,    0,     0,     0,     0,     0,     0,     0,     0,     0,     }, //  5 - Blue
+//{ pinXX,    0,     0,     0,     0,     0,     0,     0,     0,     0,     }, //  6 - Red / Blue
+//{ pinXX,    0,     0,     0,     0,     0,     0,     0,     0,     0,     }, //  7 - White / Green
+//{ pinXX,    0,     0,     0,     0,     0,     0,     0,     0,     0,     }, //  8 - Grey / Pink
+//{ pinXX,    0,     0,     0,     0,     0,     0,     0,     0,     0,     }, //  9 - Brown / Green
+//{ pinXX,    0,     0,     0,     0,     0,     0,     0,     0,     0,     }, // 10 - Brown / Grey
+//{ pinXX,    0,     0,     0,     0,     0,     0,     0,     0,     0,     }, // 11 - White / Grey
+//{ pinXX,    0,     0,     0,     0,     0,     0,     0,     0,     0,     }, // 12 - Yellow / White
+//{ pinXX,    0,     0,     0,     0,     0,     0,     0,     0,     0,     }, // 13 - Brown / Yellow
+  { pinF2,    0,     0,     0,     0,     0,     0,     0,     0,     0,     }, // 14 - Yellow
+  { pinF0,    23,    84,    19,    20,    64,    24,    57,    22,    21,    }, // 15 - Purple
+  { pinF1,    17,    85,    12,    14,    13,    11,    18,    16,    15,    }, // 16 - Brown
+  { pinF3,    62,    52,    49,    1,     47,    61,    48,    3,     2,     }, // 17 - Green
+  { pinF6,    4,     63,    6,     8,     7,     5,     56,    9,     10,    }, // 18 - Grey
+
+
+
+};
+
+
+
+#endif // __MATRIX_H
+
diff --git a/Scan/SKM67001/setup.cmake b/Scan/SKM67001/setup.cmake
new file mode 100644 (file)
index 0000000..eefca04
--- /dev/null
@@ -0,0 +1,35 @@
+###| CMake Kiibohd Controller Scan Module |###
+#
+# Written by Jacob Alexander in 2012 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=skm67001_ModifierMask
+       #-DKEYINDEX_MASK=skm67001_DefaultMap
+       -DKEYINDEX_MASK=skm67001_ColemakMap
+)
+
index 605d9e943c84f086d4825744c9bfde8a6cef8c6c..7e1e1042f3a97d0a2c09d96e30e06901310b0ac2 100644 (file)
 // ----- Macros -----
 
 // -- pinSetup Macros --
-#define REG_SET(reg)   reg |= (1 << ( matrix[row*(MAX_ROW_SIZE+1)+col] % 10 ) )
-                       
+#define REG_SET(reg)   reg |=  (1 << ( matrix[row*(MAX_ROW_SIZE+1)+col] % 10 ) ) // Modulo 10 for the define offset for each pin set 12 or 32 -> shift of 2
+#define REG_UNSET(reg)  reg &= ~(1 << ( matrix[row*(MAX_ROW_SIZE+1)+col] % 10 ) )
+
+#define PIN_SET(pin,scan,direction) \
+                       switch ( direction ) { \
+                       case columnSet: PIN_SET_COL(pin,scan); \
+                       case rowSet:    PIN_SET_ROW(pin,scan); \
+                       } \
+                       break
+
+// TODO Only scanCol_powrRow Tested (and powrRow)
 #define PIN_SET_COL(pin,scan) \
                        switch ( scan ) { \
                        case scanCol: \
                        case scanRow_powrCol: \
                        case scanDual: \
                                REG_SET(port##pin); break; \
-                       case scanCol_powrRow: REG_SET(ddr##pin); REG_SET(port##pin); break; \
+                       case scanCol_powrRow: REG_UNSET(ddr##pin); REG_UNSET(DDR##pin); \
+                                             REG_SET(port##pin);  REG_SET(PORT##pin); break; \
+                       case powrRow: break; \
+                       case powrCol: REG_SET(ddr##pin);  REG_SET(DDR##pin); \
+                                     REG_SET(port##pin); REG_SET(PORT##pin); break; \
                        } \
                        break
 
+// TODO Only scanCol_powrRow Tested (and powrRow)
 #define PIN_SET_ROW(pin,scan) \
                        switch ( scan ) { \
+                       case scanRow_powrCol: REG_UNSET(ddr##pin); REG_SET(port##pin); break; \
                        case scanRow: \
-                       case scanCol_powrRow: \
                        case scanDual: \
                                REG_SET(port##pin); break; \
-                       case scanRow_powrCol: REG_SET(ddr##pin); REG_SET(port##pin); break; \
+                       case scanCol_powrRow: REG_SET(ddr##pin);    REG_SET(DDR##pin); \
+                                             REG_UNSET(port##pin); REG_UNSET(PORT##pin); break; \
+                       case powrRow: REG_SET(ddr##pin);  REG_SET(DDR##pin); \
+                                     REG_SET(port##pin); REG_SET(PORT##pin); break; \
+                       case powrCol: break; \
                        } \
                        break
 
 #define PIN_TEST_ROW(pin) \
                        scanCode = matrix[row*(MAX_ROW_SIZE+1)+col]; \
                        if ( scanCode && !( pin & ( 1 << ( matrix[row*(MAX_ROW_SIZE+1)+0] % 10 ) ) ) ) \
+                       { \
                                detectArray[scanCode]++; \
+                       } \
                        break
 
 // -- Scan Dual Macros --
 
 
 // ----- Variables -----
+uint8_t showDebug = 0;
+
+// Debug Variables for GPIO setting
+uint8_t portA = 0x00;
+uint8_t portB = 0x00;
+uint8_t portC = 0x00;
+uint8_t portD = 0x00;
+uint8_t portE = 0x00;
+uint8_t portF = 0x00;
 
+uint8_t ddrA = 0x00;
+uint8_t ddrB = 0x00;
+uint8_t ddrC = 0x00;
+uint8_t ddrD = 0x00;
+uint8_t ddrE = 0x00;
+uint8_t ddrF = 0x00;
 
 
 // ----- Functions -----
+// Pin Setup Debug
+inline void matrix_debugPins()
+{
+       char tmpStr[6];
+       info_print("Initial Matrix Pin Setup");
+       info_print(" ddrA  ddrB  ddrC  ddrD  ddrE  ddrF");
+       print("      ");
+       hexToStr_op( ddrA, tmpStr, 2 ); dPrintStrs( "  0x", tmpStr );
+       hexToStr_op( ddrB, tmpStr, 2 ); dPrintStrs( "  0x", tmpStr );
+       hexToStr_op( ddrC, tmpStr, 2 ); dPrintStrs( "  0x", tmpStr );
+       hexToStr_op( ddrD, tmpStr, 2 ); dPrintStrs( "  0x", tmpStr );
+       hexToStr_op( ddrE, tmpStr, 2 ); dPrintStrs( "  0x", tmpStr );
+       hexToStr_op( ddrF, tmpStr, 2 ); dPrintStrs( "  0x", tmpStr );
+       print("\n");
+       info_print("portA portB portC portD portE portF");
+       print("      ");
+       hexToStr_op( portA, tmpStr, 2 ); dPrintStrs( "  0x", tmpStr );
+       hexToStr_op( portB, tmpStr, 2 ); dPrintStrs( "  0x", tmpStr );
+       hexToStr_op( portC, tmpStr, 2 ); dPrintStrs( "  0x", tmpStr );
+       hexToStr_op( portD, tmpStr, 2 ); dPrintStrs( "  0x", tmpStr );
+       hexToStr_op( portE, tmpStr, 2 ); dPrintStrs( "  0x", tmpStr );
+       hexToStr_op( portF, tmpStr, 2 ); dPrintStrs( "  0x", tmpStr );
+       print("\n");
+
+       showDebug++;
+}
 
-// Goes through the defined matrix and matrix mode, and sets the initial state of all of the available pins
-void matrix_pinSetup( uint8_t *matrix, uint8_t scanType )
+
+// Column Setup
+inline void matrix_columnSet( uint8_t *matrix, uint8_t scanType, uint16_t startIndex, uint16_t colsToIterate )
 {
-       // Setup the variables
-       uint8_t portA = 0x00;
-       uint8_t portB = 0x00;
-       uint8_t portC = 0x00;
-       uint8_t portD = 0x00;
-       uint8_t portE = 0x00;
-       uint8_t portF = 0x00;
-
-       uint8_t ddrA = 0x00;
-       uint8_t ddrB = 0x00;
-       uint8_t ddrC = 0x00;
-       uint8_t ddrD = 0x00;
-       uint8_t ddrE = 0x00;
-       uint8_t ddrF = 0x00;
+       // Calculate the number of pins to iterate over
+       uint8_t maxColumns = startIndex + colsToIterate - 1;
+       if ( maxColumns > MAX_COL_SIZE )
+               maxColumns = MAX_COL_SIZE;
 
-       // Loop through all the pin assignments, for the initial pin settings
        uint16_t row, col;
 
-       // Rows
-       for ( col = 0, row = 1; row < MAX_COL_SIZE + 1; row++ )
+       // Columns
+       for ( col = startIndex, row = 0; col <= maxColumns; col++ )
        {
                // We can't pass 2D arrays, so just point to the first element and calculate directly
                switch ( matrix[row*(MAX_ROW_SIZE+1)+col] )
                {
+#if defined(__AVR_AT90USB1286__)
                PIN_CASE(A):
-                       PIN_SET_ROW(A, scanType);
+                       PIN_SET(A, scanType, columnSet);
+#endif
                PIN_CASE(B):
-                       PIN_SET_ROW(B, scanType);
+                       PIN_SET(B, scanType, columnSet);
                PIN_CASE(C):
-                       PIN_SET_ROW(C, scanType);
+                       PIN_SET(C, scanType, columnSet);
                PIN_CASE(D):
-                       PIN_SET_ROW(D, scanType);
+                       PIN_SET(D, scanType, columnSet);
                PIN_CASE(E):
-                       PIN_SET_ROW(E, scanType);
+                       PIN_SET(E, scanType, columnSet);
                PIN_CASE(F):
-                       PIN_SET_ROW(F, scanType);
+                       PIN_SET(F, scanType, columnSet);
 
                default:
                        continue;
                }
        }
+}
 
-       // Columns
-       for ( col = 1, row = 0; col < (MAX_ROW_SIZE+1) + 1; col++ )
+// Row Setup
+inline void matrix_rowSet( uint8_t *matrix, uint8_t scanType, uint16_t startIndex, uint8_t rowsToIterate )
+{
+       // Calculate the number of pins to iterate over
+       uint16_t maxRows = startIndex + rowsToIterate - 1;
+       if ( maxRows > MAX_ROW_SIZE )
+               maxRows = MAX_ROW_SIZE;
+
+       uint16_t row, col;
+
+       // Rows
+       for ( col = 0, row = startIndex; row <= maxRows; row++ )
        {
                // We can't pass 2D arrays, so just point to the first element and calculate directly
                switch ( matrix[row*(MAX_ROW_SIZE+1)+col] )
                {
+#if defined(__AVR_AT90USB1286__)
                PIN_CASE(A):
-                       PIN_SET_COL(A, scanType);
+                       PIN_SET(A, scanType, rowSet);
+#endif
                PIN_CASE(B):
-                       PIN_SET_COL(B, scanType);
+                       PIN_SET(B, scanType, rowSet);
                PIN_CASE(C):
-                       PIN_SET_COL(C, scanType);
+                       PIN_SET(C, scanType, rowSet);
                PIN_CASE(D):
-                       PIN_SET_COL(D, scanType);
+                       PIN_SET(D, scanType, rowSet);
                PIN_CASE(E):
-                       PIN_SET_COL(E, scanType);
+                       PIN_SET(E, scanType, rowSet);
                PIN_CASE(F):
-                       PIN_SET_COL(F, scanType);
+                       PIN_SET(F, scanType, rowSet);
 
                default:
                        continue;
                }
        }
+}
+
+
+// Goes through the defined matrix and matrix mode, and sets the initial state of all of the available pins
+void matrix_pinSetup( uint8_t *matrix, uint8_t scanType )
+{
+       // Loop through all the pin assignments, for the initial pin settings
+       matrix_rowSet   ( matrix, scanType, 1, MAX_ROW_SIZE );
+       matrix_columnSet( matrix, scanType, 1, MAX_COL_SIZE );
 
        // Pin Status
-       if ( scanType == scanMode )
+       if ( showDebug == 0 ) // Only show once
        {
-               char tmpStr[6];
-               info_print("Initial Matrix Pin Setup");
-               info_print(" ddrA  ddrB  ddrC  ddrD  ddrE  ddrF");
-               print("      ");
-               hexToStr_op( ddrA, tmpStr, 2 ); dPrintStrs( "  0x", tmpStr );
-               hexToStr_op( ddrB, tmpStr, 2 ); dPrintStrs( "  0x", tmpStr );
-               hexToStr_op( ddrC, tmpStr, 2 ); dPrintStrs( "  0x", tmpStr );
-               hexToStr_op( ddrD, tmpStr, 2 ); dPrintStrs( "  0x", tmpStr );
-               hexToStr_op( ddrE, tmpStr, 2 ); dPrintStrs( "  0x", tmpStr );
-               hexToStr_op( ddrF, tmpStr, 2 ); dPrintStrs( "  0x", tmpStr );
-               print("\n");
-               info_print("portA portB portC portD portE portF");
-               print("      ");
-               hexToStr_op( portA, tmpStr, 2 ); dPrintStrs( "  0x", tmpStr );
-               hexToStr_op( portB, tmpStr, 2 ); dPrintStrs( "  0x", tmpStr );
-               hexToStr_op( portC, tmpStr, 2 ); dPrintStrs( "  0x", tmpStr );
-               hexToStr_op( portD, tmpStr, 2 ); dPrintStrs( "  0x", tmpStr );
-               hexToStr_op( portE, tmpStr, 2 ); dPrintStrs( "  0x", tmpStr );
-               hexToStr_op( portF, tmpStr, 2 ); dPrintStrs( "  0x", tmpStr );
-               print("\n");
-               int8ToStr( scanType, tmpStr );
+               matrix_debugPins();
        }
-
-       // Setting the pins
-#if defined(__AVR_AT90USB1286__)
-       DDRA = ddrA;
-#endif
-       DDRB = ddrB;
-       DDRC = ddrC;
-       DDRD = ddrD;
-       DDRE = ddrE;
-       DDRF = ddrF;
-
-#if defined(__AVR_AT90USB1286__)
-       PORTA = portA;
-#endif
-       PORTB = portB;
-       PORTC = portC;
-       PORTD = portD;
-       PORTE = portE;
-       PORTF = portF;
 }
 
 // Scans the given matrix determined by the scanMode method
@@ -235,56 +271,75 @@ inline void matrix_scan( uint8_t *matrix, uint8_t *detectArray )
        uint16_t scanCode = 0;
 
 
+       // TODO Only scanCol_powrRow tested
        // Column Scan and Column Scan, Power Row
 #if scanMode == scanCol || scanMode == scanCol_powrRow
-       for ( ; row < (MAX_COL_SIZE+1); row++ ) for ( ; col < (MAX_ROW_SIZE+1); col++ )
+       for ( ; row <= MAX_ROW_SIZE; row++ )
        {
-               // Scan over the pins for each of the columns, and using the pin alias to determine which pin to set
-               // (e.g. / 10 is for the pin name (A,B,C,etc.) and % 10 is for the position of the pin (A1,A2,etc.))
-               switch ( matrix[0*(MAX_ROW_SIZE+1)+col] / 10 )
+               // Power each row separately
+               matrix_rowSet( matrix, powrRow, row, 1 );
+
+               for ( col = 1; col <= MAX_COL_SIZE; col++ )
                {
+                       // Scan over the pins for each of the columns, and using the pin alias to determine which pin to set
+                       // (e.g. / 10 is for the pin name (A,B,C,etc.) and % 10 is for the position of the pin (A1,A2,etc.))
+                       switch ( matrix[0*(MAX_ROW_SIZE+1)+col] / 10 )
+                       {
 #if defined(__AVR_AT90USB1286__)
-               case 0: // PINA
-                       PIN_TEST_COL(PINA);
+                       case 0: // PINA
+                               PIN_TEST_COL(PINA);
 #endif
-               case 1: // PINB
-                       PIN_TEST_COL(PINB);
-               case 2: // PINC
-                       PIN_TEST_COL(PINC);
-               case 3: // PIND
-                       PIN_TEST_COL(PIND);
-               case 4: // PINE
-                       PIN_TEST_COL(PINE);
-               case 5: // PINF
-                       PIN_TEST_COL(PINF);
+                       case 1: // PINB
+                               PIN_TEST_COL(PINB);
+                       case 2: // PINC
+                               PIN_TEST_COL(PINC);
+                       case 3: // PIND
+                               PIN_TEST_COL(PIND);
+                       case 4: // PINE
+                               PIN_TEST_COL(PINE);
+                       case 5: // PINF
+                               PIN_TEST_COL(PINF);
+                       }
                }
+
+               // Unset the row power
+               matrix_rowSet( matrix, scanMode, row, 1 );
        }
 #endif // scanMode
 
 
        // Row Scan and Row Scan, Power Row
 #if scanMode == scanRow || scanMode == scanRow_powrCol
-       for ( ; col < (MAX_ROW_SIZE+1); col++ ) for ( ; row < (MAX_COL_SIZE+1); row++ ) 
+       for ( ; col <= MAX_COL_SIZE; col++ )
        {
-               // Scan over the pins for each of the rows, and using the pin alias to determine which pin to set
-               // (e.g. / 10 is for the pin name (A,B,C,etc.) and % 10 is for the position of the pin (A1,A2,etc.))
-               switch ( matrix[row*(MAX_ROW_SIZE+1)+0] / 10 )
+               // Power each column separately
+               matrix_columnSet( matrix, powrCol, col, 1 );
+
+               for ( row = 1; row <= MAX_ROW_SIZE; row++ )
                {
+                       // Scan over the pins for each of the rows, and using the pin alias to determine which pin to set
+                       // (e.g. / 10 is for the pin name (A,B,C,etc.) and % 10 is for the position of the pin (A1,A2,etc.))
+                       switch ( matrix[row*(MAX_ROW_SIZE+1)+0] / 10 )
+                       {
 #if defined(__AVR_AT90USB1286__)
-               case 0: // PINA
-                       PIN_TEST_ROW(PINA);
+                       case 0: // PINA
+                               PIN_TEST_ROW(PINA);
 #endif
-               case 1: // PINB
-                       PIN_TEST_ROW(PINB);
-               case 2: // PINC
-                       PIN_TEST_ROW(PINC);
-               case 3: // PIND
-                       PIN_TEST_ROW(PIND);
-               case 4: // PINE
-                       PIN_TEST_ROW(PINE);
-               case 5: // PINF
-                       PIN_TEST_ROW(PINF);
+                       case 1: // PINB
+                               PIN_TEST_ROW(PINB);
+                       case 2: // PINC
+                               PIN_TEST_ROW(PINC);
+                       case 3: // PIND
+                               PIN_TEST_ROW(PIND);
+                       case 4: // PINE
+                               PIN_TEST_ROW(PINE);
+                       case 5: // PINF
+                               PIN_TEST_ROW(PINF);
+                       }
                }
+
+               // Unset the column power
+               matrix_columnSet( matrix, scanMode, col, 1 );
        }
 #endif // scanMode
 
@@ -292,7 +347,7 @@ inline void matrix_scan( uint8_t *matrix, uint8_t *detectArray )
        // Dual Scan
 #if scanMode == scanDual
        // First do a scan of all of the columns, marking each one
-       matrix_pinSetup( matrix, scanCol_powrRow );
+       matrix_pinSetup( matrix, scanCol_powrRow, 0, MAX_ROW_SIZE, MAX_COL_SIZE );
        _delay_us( 1 );
        for ( ; row < (MAX_COL_SIZE+1); row++ ) for ( ; col < (MAX_ROW_SIZE+1); col++ )
        {
@@ -319,7 +374,7 @@ inline void matrix_scan( uint8_t *matrix, uint8_t *detectArray )
 
        // Next, do a scan of all of the rows, clearing any "vague" keys (only detected on row, but not column, or vice-versa)
        // And marking any keys that are detected on the row and column
-       matrix_pinSetup( matrix, scanRow_powrCol );
+       matrix_pinSetup( matrix, scanRow_powrCol, 0, MAX_ROW_SIZE, MAX_COL_SIZE );
        _delay_us( 1 );
        col = 1;
        row = 1;
index 0fdaeae9e3efa352dd5d42be70bd3fbca5efd7de..df5202d3c70fa742078be37f4dbf1eca26650564 100644 (file)
 #define scanCol_powrRow 3  // Opposite of scanRow_powrCol
 #define scanDual        4  // Typical ~2KRO matrix
 
+#define powrRow         5  // Matrix setup for powering a row, initially the row would be set low
+#define powrCol         6  // Like powrRow but for columns
+
+
+// ----- Direction -----
+#define columnSet       0  // PIN_SET_COL for PIN_SET
+#define rowSet          1  // PIN_SET_ROW for PIN_SET
+
 
 
 // ----- Variables -----
index ead13755984d1a741f931365a6c5af62d84ae7fd..f385295eab89802a33675162f628184a7d091039 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2011 by Jacob Alexander
+/* Copyright (C) 2011-2012 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
 // ----- Defines -----
 
 // Debouncing Defines
-#define SAMPLE_THRESHOLD 110
-#define MAX_SAMPLES      127 // Max is 127, reaching 128 is very bad
+// Old
+//#define SAMPLE_THRESHOLD 110
+//#define MAX_SAMPLES      127 // Max is 127, reaching 128 is very bad
+#define SAMPLE_THRESHOLD 6
+#define MAX_SAMPLES      10 // Max is 127, reaching 128 is very bad
 
 
 
@@ -56,6 +59,7 @@
 // Buffer used to inform the macro processing module which keys have been detected as pressed
 volatile uint8_t KeyIndex_Buffer[KEYBOARD_BUFFER];
 volatile uint8_t KeyIndex_BufferUsed;
+volatile uint8_t KeyIndex_Add_InputSignal; // Used to pass the (click/input value) to the keyboard for the clicker
 
 
 // Keeps track of the number of scans, so we only do a debounce assess when it would be valid (as it throws away data)
@@ -169,3 +173,10 @@ inline void scan_finishedWithBuffer( void )
        return;
 }
 
+// Send data to keyboard
+// Not used in this module
+uint8_t scan_sendData( uint8_t dataPayload )
+{
+       return 0;
+}
+
index f78e71c4910fe2a36c4d75311dc524dc3bdf8f9a..eaff7a08eef79f8868d305768f0606fc6bf01bda 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2011 by Jacob Alexander
+/* Copyright (C) 2011-2012 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
@@ -50,6 +50,7 @@ extern                       uint8_t KeyIndex_Array [KEYBOARD_SIZE + 1];
 
 extern volatile              uint8_t KeyIndex_Buffer[KEYBOARD_BUFFER];
 extern volatile              uint8_t KeyIndex_BufferUsed;
+extern volatile     uint8_t KeyIndex_Add_InputSignal;
 
 
 
index 5f7450348259e66315ef70beb505c4a17ff44c10..9b5450fd472b1deb51e0f713a4ac805df179bb2b 100644 (file)
@@ -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  "SonyOA-S3400" )
+set(  ScanModule  "SKM67001" )
 
 ##| Uses the key index and potentially applies special conditions to it, mapping it to a usb key code
 set( MacroModule  "buffer"  )