From 47a54d654dbad952e60cebf8798771e81da11923 Mon Sep 17 00:00:00 2001 From: Jacob Alexander Date: Thu, 22 Sep 2011 23:33:56 -0700 Subject: [PATCH] Parts of the upcoming rewrite --- layouts.h | 226 ------------------------------------------------------ main.c | 63 +++++++++++---- 2 files changed, 46 insertions(+), 243 deletions(-) delete mode 100644 layouts.h diff --git a/layouts.h b/layouts.h deleted file mode 100644 index 7b477df..0000000 --- a/layouts.h +++ /dev/null @@ -1,226 +0,0 @@ -#ifndef __layouts_h -#define __layouts_h - -// Modifier Mask -#define MODIFIERS_KEYPAD 0 -#define MODIFIERS_KEYBOARD 4 -static uint8_t keypad_modifierMask[] = {}; -static uint8_t keyboard_modifierMask[] = { 1, 17, 33, 49 }; -static uint8_t alternate_modifierMask[] = { 1, 17, 33, 49, 62 }; - -// Default 1-indexed key mappings -static uint8_t keypadDefaultMap[] = { 0, - KEYPAD_ASTERIX, - KEYPAD_MINUS, - KEYPAD_PLUS, - KEYPAD_ENTER, - KEYPAD_9, - KEYPAD_6, - KEYPAD_3, - KEYPAD_0, - KEYPAD_8, - KEYPAD_5, - KEYPAD_2, - KEYPAD_PERIOD, - KEYPAD_7, - KEYPAD_4, - KEYPAD_1, - KEYPAD_SLASH }; - -static uint8_t defaultMap[] = { 0, - KEY_GUI, - 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_TILDE, - KEY_BACKSPACE, - 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_LLOCK, - 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 }; - -static uint8_t navigationMap[] = { 0, - KEY_GUI, - KEY_F1, - KEY_F2, - KEY_F3, - KEY_F4, - KEY_F5, - KEY_F6, - KEY_F7, - KEY_F8, - KEY_F9, - KEY_F10, - KEY_F11, - KEY_F12, - KEY_INSERT, - KEY_DELETE, - KEY_BACKSPACE, - KEY_ALT, - KEY_CAPS_LOCK, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - KEY_SYSREQ_ATT, - KEY_SCROLL_LOCK, - KEY_PAUSE, - KEY_UP, - 0, - 0, - 0, - KEY_CTRL, - KEY_CAPS_LLOCK, - 0, - 0, - 0, - 0, - 0, - KEYPAD_ASTERIX, - KEYPAD_SLASH, - KEY_HOME, - KEY_PAGE_UP, - KEY_LEFT, - KEY_RIGHT, - KEY_ENTER, - 0, - KEY_ESC, - KEY_LEFT_SHIFT, - 0, - 0, - 0, - 0, - 0, - KEYPAD_PLUS, - KEYPAD_MINUS, - KEY_END, - KEY_PAGE_DOWN, - KEY_DOWN, - KEY_RIGHT_SHIFT, - 165, - KEY_RIGHT_ALT, - KEY_SPACE }; - -static uint8_t colemakMap[] = { 0, - KEY_GUI, - 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_TILDE, - KEY_BACKSPACE, - KEY_ALT, - KEY_TAB, - KEY_Q, - KEY_W, - KEY_F, - KEY_P, - KEY_G, - KEY_J, - KEY_L, - KEY_U, - KEY_Y, - KEY_SEMICOLON, - KEY_LEFT_BRACE, - KEY_RIGHT_BRACE, - KEY_DELETE, - KEY_PAGE_UP, - KEY_CTRL, - KEY_CAPS_LLOCK, - KEY_A, - KEY_R, - KEY_S, - KEY_T, - KEY_D, - KEY_H, - KEY_N, - KEY_E, - KEY_I, - KEY_O, - KEY_QUOTE, - KEY_ENTER, - KEY_PAGE_DOWN, - KEY_ESC, - KEY_LEFT_SHIFT, - KEY_Z, - KEY_X, - KEY_C, - KEY_V, - KEY_B, - KEY_K, - KEY_M, - KEY_COMMA, - KEY_PERIOD, - KEY_SLASH, - KEY_RIGHT_SHIFT, - 165, - KEY_RIGHT_ALT, - KEY_SPACE }; - -#endif - diff --git a/main.c b/main.c index 204224c..1689a9b 100644 --- a/main.c +++ b/main.c @@ -24,7 +24,8 @@ #include #include #include "usb_keys.h" -#include "layouts.h" +#include "scan_loop.h" +//#include "layouts.h" //#include "usb_keyboard.h" // TEMP INCLUDES @@ -33,10 +34,6 @@ #define CPU_PRESCALE(n) (CLKPR = 0x80, CLKPR = (n)) -// Number of keys -#define KEYBOARD_SIZE 63 -#define KEYPAD_SIZE 16 - // Debouncing Defines #define SAMPLE_THRESHOLD 110 @@ -46,6 +43,10 @@ // Verified Keypress Defines #define USB_TRANSFER_DIVIDER 10 // 1024 == 1 Send of keypresses per second, 1 == 1 Send of keypresses per ~1 millisecond +/* +// Number of keys +#define KEYBOARD_SIZE 63 +#define KEYPAD_SIZE 16 // Drive Pin Defines #define DRIVE_reg_1 PORTD @@ -219,8 +220,7 @@ // 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]; +uint8_t keyboardDetectArray[KEYBOARD_SIZE + 1]; // Interrupt Variables uint16_t sendKeypressCounter = 0; @@ -242,30 +242,47 @@ void detection( int group ) DET_GROUP(9,1) } } +*/ + +// Error LED Control +void errorLED( uint8_t on ) +{ + // Error LED On + if ( on ) { + DDRD |= (1<<6); + PORTD |= (1<<6); + } + // Error LED Off + else { + DDRD &= ~(1<<6); + PORTD &= ~(1<<6); + } +} -// XXX This part is configurable +// Initial Pin Setup +// If the matrix is properly set, this function does not need to be changed inline void pinSetup(void) { // For each pin, 0=input, 1=output DDRA = 0x00; DDRB = 0x00; DDRC = 0x00; - DDRD = 0xFC; - DDRE = 0x43; + DDRD = 0x40; // LED Setup + DDRE = 0x00; DDRF = 0x00; // Setting pins to either high or pull-up resistor - PORTA = 0xFF; - PORTB = 0xFF; - PORTC = 0x01; - PORTD = 0xFF; - PORTE = 0xC3; - PORTF = 0xFF; + PORTA = 0x00; + PORTB = 0x00; + PORTC = 0x00; + PORTD = 0x40; // LED Enable + PORTE = 0x00; + PORTF = 0x00; } - +/* // Given a sampling array, and the current number of detected keypress // Add as many keypresses from the sampling array to the USB key send array as possible. void keyPressDetection( uint8_t *keys, uint8_t *validKeys, uint8_t numberOfKeys, uint8_t *modifiers, uint8_t numberOfModifiers, uint8_t *map ) { @@ -297,6 +314,7 @@ void keyPressDetection( uint8_t *keys, uint8_t *validKeys, uint8_t numberOfKeys, } } } +*/ int main( void ) { @@ -323,6 +341,16 @@ int main( void ) TIMSK0 = (1 << TOIE0); // Main Detection Loop + while ( 1 ) { + scan_loop(); + + // Loop should never get here (indicate error) + errorLED( 1 ); + + // TODO HID Debug message + } +} +/* int8_t group = 1; uint8_t count = 0; for ( ;;group++ ) { @@ -420,6 +448,7 @@ int main( void ) return 0; } +*/ // Timer Interrupt for flagging a send of the sampled key detection data to the USB host ISR( TIMER0_OVF_vect )