-#define DD_CASE_END(number,var) \
- DD_CASE(number) \
- var = -1; \
- break;
-
-
-// Updates the current detection sample and last sample bit
-// Detection Macros (Probably don't need to be changed, but depending the matrix, may have to be)
-// Determine if key is either normal or a modifier
-#define DET_GROUP_CHECK(index,test) \
- if ( test ) { \
- keyDetectArray[groupArray[index]]++; \
- }
-
-
-// XXX - Detection Groups
-// Checks each of the specified pins, and then if press detected, determine if the key is normal or a modifier
-// Inverse logic applies for the PINs
-
-// Used for 1 detection group (Special group)
-#define DET_GROUP_1 \
- DET_GROUP_CHECK(0,!( PINB & (1 << 7) )) \
- DET_GROUP_CHECK(1,!( PINC & (1 << 0) )) \
- DET_GROUP_CHECK(2,!( PIND & (1 << 0) )) \
- DET_GROUP_CHECK(3,!( PIND & (1 << 1) )) \
-
-// Used for 4 detection groups (Skips J1 P9)
-#define DET_GROUP_2 \
- DET_GROUP_CHECK(0,!( PINE & (1 << 7) )) \
- DET_GROUP_CHECK(1,!( PINB & (1 << 0) )) \
- DET_GROUP_CHECK(2,!( PINB & (1 << 1) )) \
- DET_GROUP_CHECK(3,!( PINB & (1 << 2) )) \
- DET_GROUP_CHECK(4,!( PINB & (1 << 3) )) \
- DET_GROUP_CHECK(5,!( PINB & (1 << 4) )) \
- DET_GROUP_CHECK(6,!( PINB & (1 << 5) )) \
-
-// Used for 1 detection group (Skips J1 P6 and J1 P9)
-#define DET_GROUP_3 \
- DET_GROUP_CHECK(0,!( PINE & (1 << 7) )) \
- DET_GROUP_CHECK(1,!( PINB & (1 << 0) )) \
- DET_GROUP_CHECK(2,!( PINB & (1 << 1) )) \
- DET_GROUP_CHECK(3,!( PINB & (1 << 2) )) \
- DET_GROUP_CHECK(4,!( PINB & (1 << 4) )) \
- DET_GROUP_CHECK(5,!( PINB & (1 << 5) )) \
-
-// Used for 3 detection groups (No skips, except special group 1)
-#define DET_GROUP_4 \
- DET_GROUP_CHECK(0,!( PINE & (1 << 7) )) \
- DET_GROUP_CHECK(1,!( PINB & (1 << 0) )) \
- DET_GROUP_CHECK(2,!( PINB & (1 << 1) )) \
- DET_GROUP_CHECK(3,!( PINB & (1 << 2) )) \
- DET_GROUP_CHECK(4,!( PINB & (1 << 3) )) \
- DET_GROUP_CHECK(5,!( PINB & (1 << 4) )) \
- DET_GROUP_CHECK(6,!( PINB & (1 << 5) )) \
- DET_GROUP_CHECK(7,!( PINB & (1 << 6) )) \
-
-// Combines the DET_GROUP_Xs above for the given groupArray
-#define DET_GROUP(group,det_group) \
- case group: \
- { \
- uint8_t groupArray[DETECT_group_size_##group] = DETECT_group_array_##group; \
- _delay_us(1); \
- DET_GROUP_##det_group \
- } \
- break;
-
-
-// Loop over all of the sampled keys of the given array
-// If the number of samples is higher than the sample threshold, flag the high bit, clear otherwise
-// This should be resetting VERY quickly, cutting off a potentially valid keypress is not an issue
-#define DEBOUNCE_ASSESS(table,size) \
- for ( uint8_t key = 1; key < size + 1; key++ ) {\
- table[key] = ( table[key] & ~(1 << 7) ) > SAMPLE_THRESHOLD ? (1 << 7) : 0x00; \
- } \
-
-
-// Keypad detection
-// Each switch has it's own detection line
-#define KEYPAD_DETECT(test,switch_code) \
- if ( test ) { \
- keypadDetectArray[switch_code]++; \
- } \
-
-
-// NOTE: Highest Bit: Valid keypress (0x80 is valid keypress)
-// Other Bits: Pressed state sample counter
-uint8_t keyDetectArray[KEYBOARD_SIZE + 1];
-uint8_t keypadDetectArray[KEYPAD_SIZE + 1];
-
-uint16_t sendKeypressCounter = 0;
-volatile uint8_t sendKeypresses = 0;
-
-static const uint8_t defaultMap[] = { 0,
- KEY_INSERT,
- KEY_1,
- KEY_2,
- KEY_3,
- KEY_4,
- KEY_5,
- KEY_6,
- KEY_7,
- KEY_8,
- KEY_9,
- KEY_0,
- KEY_MINUS,
- KEY_EQUAL,
- KEY_BACKSLASH,
- KEY_ALT,
- KEY_TAB,
- KEY_Q,
- KEY_W,
- KEY_E,
- KEY_R,
- KEY_T,
- KEY_Y,
- KEY_U,
- KEY_I,
- KEY_O,
- KEY_P,
- KEY_LEFT_BRACE,
- KEY_RIGHT_BRACE,
- KEY_DELETE,
- KEY_UP,
- KEY_CTRL,
- KEY_CAPS_LOCK,
- KEY_A,
- KEY_S,
- KEY_D,
- KEY_F,
- KEY_G,
- KEY_H,
- KEY_J,
- KEY_K,
- KEY_L,
- KEY_SEMICOLON,
- KEY_QUOTE,
- KEY_ENTER,
- KEY_DOWN,
- KEY_ESC,
- KEY_LEFT_SHIFT,
- KEY_Z,
- KEY_X,
- KEY_C,
- KEY_V,
- KEY_B,
- KEY_N,
- KEY_M,
- KEY_COMMA,
- KEY_PERIOD,
- KEY_SLASH,
- KEY_RIGHT_SHIFT,
- KEY_LEFT,
- KEY_RIGHT,
- KEY_SPACE };
-
-// Scan Code Decoder (for debug)
-void printDecodeScancode( int code )
-{
-
- static const char* decodeArray[] = { "", "", "", "", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "Enter", "Esc", "Backspace", "Tab", "Space", "-_", "=+", "[{", "]}", "\\", "#", ";:", "'\"", "`~", ",<", ".>", "/?", "Caps Lock", "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", "F11", "F12", "Print Screen", "Scroll Lock", "Pause", "Insert", "Home", "Page Up", "Delete", "End", "Page Down", "Right", "Left", "Down", "Up", "Num Lock", "K1", "K2", "K3", "K4", "K5", "K6", "K7", "K8", "K9", "K0", "K." };
- print_P( decodeArray[ defaultMap[code] ] );
-}
-
-void detection( int group )
-{
- // XXX Modify for different detection groups <-> groupArray mappings
- switch ( group ) {
- DET_GROUP(1,2)
- DET_GROUP(2,2)
- DET_GROUP(3,3)
- DET_GROUP(4,4)
- DET_GROUP(5,2)
- DET_GROUP(6,2)
- DET_GROUP(7,4)
- DET_GROUP(8,4)
- DET_GROUP(9,1)
- }
-}
-
-
-
-// XXX This part is configurable
-inline void pinSetup(void)
-{
- // For each pin, 0=input, 1=output
- DDRA = 0x00;
- DDRB = 0x00;
- DDRC = 0x00;
- DDRD = 0xFC;
- DDRE = 0x43;
- DDRF = 0x00;