Adding support for the Micro Switch 8304 Hall Effect Keyboard
- Full support (NKRO, provided the USB module can handle it) - Full LED support (available to the macro modules per input signals) - Reset/Hold line support - Handles repeat rate issues (keyboard does not send key updates as most keyboards do...)
This commit is contained in:
parent
a017d2f270
commit
0c562995c7
@ -13,6 +13,10 @@ cmake_force_c_compiler ( avr-gcc AVRCCompiler )
|
||||
cmake_force_cxx_compiler( avr-g++ AVRCxxCompiler )
|
||||
|
||||
|
||||
#| Add Dependency Macro
|
||||
include( AddFileDependencies )
|
||||
|
||||
|
||||
###
|
||||
# Project Description
|
||||
#
|
||||
@ -38,7 +42,13 @@ cmake_minimum_required( VERSION 2.8 )
|
||||
|
||||
#| Instead, include the module source selector
|
||||
include( setup.cmake )
|
||||
set( SRCS main.c ${SCAN_SRCS} ${MACRO_SRCS} ${USB_SRCS} ${DEBUG_SRCS} )
|
||||
set( SRCS
|
||||
main.c
|
||||
${SCAN_SRCS}
|
||||
${MACRO_SRCS}
|
||||
${USB_SRCS}
|
||||
${DEBUG_SRCS}
|
||||
)
|
||||
|
||||
|
||||
|
||||
@ -54,7 +64,7 @@ set( SRCS main.c ${SCAN_SRCS} ${MACRO_SRCS} ${USB_SRCS} ${DEBUG_SRCS} )
|
||||
#| "atmega32u4" # Teensy 2.0
|
||||
#| "at90usb646" # Teensy++ 1.0
|
||||
#| "at90usb1286" # Teensy++ 2.0
|
||||
set( MCU "at90usb1286" )
|
||||
set( MCU "atmega32u4" )
|
||||
|
||||
|
||||
#| Compiler flag to set the C Standard level.
|
||||
|
@ -44,6 +44,7 @@
|
||||
#include "budkeypad.h"
|
||||
#include "heathzenith.h"
|
||||
#include "kaypro1.h"
|
||||
#include "microswitch8304.h"
|
||||
#include "tandy1000.h"
|
||||
|
||||
|
||||
|
296
Keymap/microswitch8304.h
Normal file
296
Keymap/microswitch8304.h
Normal file
@ -0,0 +1,296 @@
|
||||
/* Copyright (C) 2011 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 __TANDY1000_H
|
||||
#define __TANDY1000_H
|
||||
|
||||
// This file contains various key layouts for the Tandy 1000 keyboard
|
||||
|
||||
|
||||
// ----- Variables -----
|
||||
static uint8_t microswitch8304_ModifierMask[] = { 0x48, 0x49, 0x4C, 0x4D, 0x45, 0x14 };
|
||||
|
||||
static uint8_t microswitch8304_DefaultMap[] = {
|
||||
KEY_TILDE, // 0x00
|
||||
KEY_UP, // 0x01
|
||||
0, // 0x02
|
||||
0, // 0x03
|
||||
KEY_PRINTSCREEN, // 0x04
|
||||
KEY_PAGE_DOWN, // 0x05
|
||||
KEY_LEFT_BRACE, // 0x06
|
||||
KEY_F11, // 0x07
|
||||
KEY_BACKSPACE, // 0x08
|
||||
KEY_TAB, // 0x09
|
||||
KEY_ENTER, // 0x0A
|
||||
KEY_DOWN, // 0x0B
|
||||
KEY_PAGE_UP, // 0x0C
|
||||
KEYPAD_ENTER, // 0x0D
|
||||
KEY_LEFT, // 0x0E
|
||||
KEY_RIGHT, // 0x0F
|
||||
0, // 0x10
|
||||
KEY_PAGE_UP, // 0x11
|
||||
KEY_F12, // 0x12
|
||||
KEY_PAGE_DOWN, // 0x13
|
||||
KEY_GUI, // 0x14
|
||||
KEY_F1, // 0x15
|
||||
KEY_F2, // 0x16
|
||||
KEY_F3, // 0x17
|
||||
KEY_F4, // 0x18
|
||||
KEY_F5, // 0x19
|
||||
KEY_F6, // 0x1A
|
||||
KEY_ESC, // 0x1B
|
||||
KEY_F7, // 0x1C
|
||||
KEY_F8, // 0x1D
|
||||
KEY_F9, // 0x1E
|
||||
KEY_F10, // 0x1F
|
||||
KEY_SPACE, // 0x20
|
||||
KEYPAD_9, // 0x21
|
||||
0, // 0x22
|
||||
0, // 0x23
|
||||
0, // 0x24
|
||||
0, // 0x25
|
||||
0, // 0x26
|
||||
KEY_QUOTE, // 0x27
|
||||
0, // 0x28
|
||||
0, // 0x29
|
||||
0, // 0x2A
|
||||
KEY_EQUAL, // 0x2B
|
||||
KEY_COMMA, // 0x2C
|
||||
KEY_MINUS, // 0x2D
|
||||
KEY_PERIOD, // 0x2E
|
||||
KEY_SLASH, // 0x2F
|
||||
KEY_0, // 0x30
|
||||
KEY_1, // 0x31
|
||||
KEY_2, // 0x32
|
||||
KEY_3, // 0x33
|
||||
KEY_4, // 0x34
|
||||
KEY_5, // 0x35
|
||||
KEY_6, // 0x36
|
||||
KEY_7, // 0x37
|
||||
KEY_8, // 0x38
|
||||
KEY_9, // 0x39
|
||||
0, // 0x3A
|
||||
KEY_SEMICOLON, // 0x3B
|
||||
0, // 0x3C
|
||||
KEY_EQUAL, // 0x3D
|
||||
0, // 0x3E
|
||||
0, // 0x3F
|
||||
0, // 0x40
|
||||
KEYPAD_6, // 0x41
|
||||
KEYPAD_MINUS, // 0x42
|
||||
KEY_PAUSE, // 0x43
|
||||
KEY_INSERT, // 0x44
|
||||
KEY_CTRL, // 0x45
|
||||
KEYPAD_2, // 0x46
|
||||
KEYPAD_3, // 0x47
|
||||
KEY_LEFT_SHIFT, // 0x48
|
||||
KEY_RIGHT_SHIFT, // 0x49
|
||||
KEYPAD_0, // 0x4A
|
||||
KEYPAD_PERIOD, // 0x4B
|
||||
KEY_LEFT_ALT, // 0x4C
|
||||
KEY_RIGHT_ALT, // 0x4D
|
||||
0, // 0x4E
|
||||
0, // 0x4F
|
||||
0, // 0x50
|
||||
0, // 0x51
|
||||
0, // 0x52
|
||||
0, // 0x53
|
||||
0, // 0x54
|
||||
0, // 0x55
|
||||
0, // 0x56
|
||||
0, // 0x57
|
||||
0, // 0x58
|
||||
0, // 0x59
|
||||
0, // 0x5A
|
||||
KEY_RIGHT_BRACE, // 0x5B
|
||||
KEYPAD_7, // 0x5C
|
||||
KEY_BACKSLASH, // 0x5D
|
||||
KEY_ESC, // 0x5E
|
||||
0, // 0x5F
|
||||
KEYPAD_1, // 0x60
|
||||
KEY_A, // 0x61
|
||||
KEY_B, // 0x62
|
||||
KEY_C, // 0x63
|
||||
KEY_D, // 0x64
|
||||
KEY_E, // 0x65
|
||||
KEY_F, // 0x66
|
||||
KEY_G, // 0x67
|
||||
KEY_H, // 0x68
|
||||
KEY_I, // 0x69
|
||||
KEY_J, // 0x6A
|
||||
KEY_K, // 0x6B
|
||||
KEY_L, // 0x6C
|
||||
KEY_M, // 0x6D
|
||||
KEY_N, // 0x6E
|
||||
KEY_O, // 0x6F
|
||||
KEY_P, // 0x70
|
||||
KEY_Q, // 0x71
|
||||
KEY_R, // 0x72
|
||||
KEY_S, // 0x73
|
||||
KEY_T, // 0x74
|
||||
KEY_U, // 0x75
|
||||
KEY_V, // 0x76
|
||||
KEY_W, // 0x77
|
||||
KEY_X, // 0x78
|
||||
KEY_Y, // 0x79
|
||||
KEY_Z, // 0x7A
|
||||
KEYPAD_4, // 0x7B
|
||||
KEYPAD_8, // 0x7C
|
||||
KEYPAD_5, // 0x7D
|
||||
0, // 0x7E
|
||||
KEY_DELETE, // 0x7F
|
||||
};
|
||||
|
||||
static uint8_t microswitch8304_ColemakMap[] = {
|
||||
KEY_TILDE, // 0x00
|
||||
KEY_UP, // 0x01
|
||||
0, // 0x02
|
||||
0, // 0x03
|
||||
KEY_PRINTSCREEN, // 0x04
|
||||
KEY_PAGE_DOWN, // 0x05
|
||||
KEY_LEFT_BRACE, // 0x06
|
||||
KEY_F11, // 0x07
|
||||
KEY_BACKSPACE, // 0x08
|
||||
KEY_TAB, // 0x09
|
||||
KEY_ENTER, // 0x0A
|
||||
KEY_DOWN, // 0x0B
|
||||
KEY_PAGE_UP, // 0x0C
|
||||
KEYPAD_ENTER, // 0x0D
|
||||
KEY_LEFT, // 0x0E
|
||||
KEY_RIGHT, // 0x0F
|
||||
0, // 0x10
|
||||
KEY_PAGE_UP, // 0x11
|
||||
KEY_F12, // 0x12
|
||||
KEY_PAGE_DOWN, // 0x13
|
||||
KEY_GUI, // 0x14
|
||||
KEY_F1, // 0x15
|
||||
KEY_F2, // 0x16
|
||||
KEY_F3, // 0x17
|
||||
KEY_F4, // 0x18
|
||||
KEY_F5, // 0x19
|
||||
KEY_F6, // 0x1A
|
||||
KEY_ESC, // 0x1B
|
||||
KEY_F7, // 0x1C
|
||||
KEY_F8, // 0x1D
|
||||
KEY_F9, // 0x1E
|
||||
KEY_F10, // 0x1F
|
||||
KEY_SPACE, // 0x20
|
||||
KEYPAD_9, // 0x21
|
||||
0, // 0x22
|
||||
0, // 0x23
|
||||
0, // 0x24
|
||||
0, // 0x25
|
||||
0, // 0x26
|
||||
KEY_QUOTE, // 0x27
|
||||
0, // 0x28
|
||||
0, // 0x29
|
||||
0, // 0x2A
|
||||
KEY_EQUAL, // 0x2B
|
||||
KEY_COMMA, // 0x2C
|
||||
KEY_MINUS, // 0x2D
|
||||
KEY_PERIOD, // 0x2E
|
||||
KEY_SLASH, // 0x2F
|
||||
KEY_0, // 0x30
|
||||
KEY_1, // 0x31
|
||||
KEY_2, // 0x32
|
||||
KEY_3, // 0x33
|
||||
KEY_4, // 0x34
|
||||
KEY_5, // 0x35
|
||||
KEY_6, // 0x36
|
||||
KEY_7, // 0x37
|
||||
KEY_8, // 0x38
|
||||
KEY_9, // 0x39
|
||||
0, // 0x3A
|
||||
KEY_O, // 0x3B
|
||||
0, // 0x3C
|
||||
KEY_EQUAL, // 0x3D
|
||||
0, // 0x3E
|
||||
0, // 0x3F
|
||||
0, // 0x40
|
||||
KEYPAD_6, // 0x41
|
||||
KEYPAD_MINUS, // 0x42
|
||||
KEY_PAUSE, // 0x43
|
||||
KEY_INSERT, // 0x44
|
||||
KEY_CTRL, // 0x45
|
||||
KEYPAD_2, // 0x46
|
||||
KEYPAD_3, // 0x47
|
||||
KEY_LEFT_SHIFT, // 0x48
|
||||
KEY_RIGHT_SHIFT, // 0x49
|
||||
KEYPAD_0, // 0x4A
|
||||
KEYPAD_PERIOD, // 0x4B
|
||||
KEY_LEFT_ALT, // 0x4C
|
||||
KEY_RIGHT_ALT, // 0x4D
|
||||
0, // 0x4E
|
||||
0, // 0x4F
|
||||
0, // 0x50
|
||||
0, // 0x51
|
||||
0, // 0x52
|
||||
0, // 0x53
|
||||
0, // 0x54
|
||||
0, // 0x55
|
||||
0, // 0x56
|
||||
0, // 0x57
|
||||
0, // 0x58
|
||||
0, // 0x59
|
||||
0, // 0x5A
|
||||
KEY_RIGHT_BRACE, // 0x5B
|
||||
KEYPAD_7, // 0x5C
|
||||
KEY_BACKSLASH, // 0x5D
|
||||
KEY_ESC, // 0x5E
|
||||
0, // 0x5F
|
||||
KEYPAD_1, // 0x60
|
||||
KEY_A, // 0x61
|
||||
KEY_B, // 0x62
|
||||
KEY_C, // 0x63
|
||||
KEY_S, // 0x64
|
||||
KEY_F, // 0x65
|
||||
KEY_T, // 0x66
|
||||
KEY_D, // 0x67
|
||||
KEY_H, // 0x68
|
||||
KEY_U, // 0x69
|
||||
KEY_N, // 0x6A
|
||||
KEY_E, // 0x6B
|
||||
KEY_I, // 0x6C
|
||||
KEY_M, // 0x6D
|
||||
KEY_K, // 0x6E
|
||||
KEY_Y, // 0x6F
|
||||
KEY_SEMICOLON, // 0x70
|
||||
KEY_Q, // 0x71
|
||||
KEY_P, // 0x72
|
||||
KEY_R, // 0x73
|
||||
KEY_G, // 0x74
|
||||
KEY_L, // 0x75
|
||||
KEY_V, // 0x76
|
||||
KEY_W, // 0x77
|
||||
KEY_X, // 0x78
|
||||
KEY_J, // 0x79
|
||||
KEY_Z, // 0x7A
|
||||
KEYPAD_4, // 0x7B
|
||||
KEYPAD_8, // 0x7C
|
||||
KEYPAD_5, // 0x7D
|
||||
0, // 0x7E
|
||||
KEY_DELETE, // 0x7F
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
244
Macro/buffer/macro.c
Normal file
244
Macro/buffer/macro.c
Normal file
@ -0,0 +1,244 @@
|
||||
/* Copyright (C) 2011 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.
|
||||
*/
|
||||
|
||||
// ----- Includes -----
|
||||
|
||||
// AVR Includes
|
||||
#include <util/delay.h>
|
||||
#include <avr/interrupt.h>
|
||||
|
||||
// Project Includes
|
||||
#include <led.h>
|
||||
#include <print.h>
|
||||
#include <scan_loop.h>
|
||||
#include <usb_com.h>
|
||||
|
||||
// Keymaps
|
||||
#include <keymap.h>
|
||||
#include <usb_keys.h>
|
||||
|
||||
// Local Includes
|
||||
#include "macro.h"
|
||||
|
||||
|
||||
|
||||
// ----- Variables -----
|
||||
|
||||
// Keeps track of the sequence used to reflash the teensy in software
|
||||
static uint8_t Bootloader_ConditionSequence[] = {1,16,6,11};
|
||||
uint8_t Bootloader_ConditionState = 0;
|
||||
uint8_t Bootloader_NextPositionReady = 1;
|
||||
|
||||
|
||||
|
||||
// ----- Functions -----
|
||||
|
||||
void jumpToBootloader(void)
|
||||
{
|
||||
cli();
|
||||
// disable watchdog, if enabled
|
||||
// disable all peripherals
|
||||
UDCON = 1;
|
||||
USBCON = (1<<FRZCLK); // disable USB
|
||||
UCSR1B = 0;
|
||||
_delay_ms(5);
|
||||
|
||||
#if defined(__AVR_AT90USB162__) // Teensy 1.0
|
||||
EIMSK = 0; PCICR = 0; SPCR = 0; ACSR = 0; EECR = 0;
|
||||
TIMSK0 = 0; TIMSK1 = 0; UCSR1B = 0;
|
||||
DDRB = 0; DDRC = 0; DDRD = 0;
|
||||
PORTB = 0; PORTC = 0; PORTD = 0;
|
||||
asm volatile("jmp 0x3E00");
|
||||
#elif defined(__AVR_ATmega32U4__) // Teensy 2.0
|
||||
EIMSK = 0; PCICR = 0; SPCR = 0; ACSR = 0; EECR = 0; ADCSRA = 0;
|
||||
TIMSK0 = 0; TIMSK1 = 0; TIMSK3 = 0; TIMSK4 = 0; UCSR1B = 0; TWCR = 0;
|
||||
DDRB = 0; DDRC = 0; DDRD = 0; DDRE = 0; DDRF = 0; TWCR = 0;
|
||||
PORTB = 0; PORTC = 0; PORTD = 0; PORTE = 0; PORTF = 0;
|
||||
asm volatile("jmp 0x7E00");
|
||||
#elif defined(__AVR_AT90USB646__) // Teensy++ 1.0
|
||||
EIMSK = 0; PCICR = 0; SPCR = 0; ACSR = 0; EECR = 0; ADCSRA = 0;
|
||||
TIMSK0 = 0; TIMSK1 = 0; TIMSK2 = 0; TIMSK3 = 0; UCSR1B = 0; TWCR = 0;
|
||||
DDRA = 0; DDRB = 0; DDRC = 0; DDRD = 0; DDRE = 0; DDRF = 0;
|
||||
PORTA = 0; PORTB = 0; PORTC = 0; PORTD = 0; PORTE = 0; PORTF = 0;
|
||||
asm volatile("jmp 0xFC00");
|
||||
#elif defined(__AVR_AT90USB1286__) // Teensy++ 2.0
|
||||
EIMSK = 0; PCICR = 0; SPCR = 0; ACSR = 0; EECR = 0; ADCSRA = 0;
|
||||
TIMSK0 = 0; TIMSK1 = 0; TIMSK2 = 0; TIMSK3 = 0; UCSR1B = 0; TWCR = 0;
|
||||
DDRA = 0; DDRB = 0; DDRC = 0; DDRD = 0; DDRE = 0; DDRF = 0;
|
||||
PORTA = 0; PORTB = 0; PORTC = 0; PORTD = 0; PORTE = 0; PORTF = 0;
|
||||
asm volatile("jmp 0x1FC00");
|
||||
#endif
|
||||
}
|
||||
|
||||
// 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.
|
||||
/*
|
||||
inline void keyPressDetection( uint8_t *keys, uint8_t numberOfKeys, uint8_t *modifiers, uint8_t numberOfModifiers, uint8_t *map )
|
||||
{
|
||||
uint8_t Bootloader_KeyDetected = 0;
|
||||
uint8_t processed_keys = 0;
|
||||
|
||||
// Parse the detection array starting from 1 (all keys are purposefully mapped from 1 -> total as per typical PCB labels)
|
||||
for ( uint8_t key = 0; key < numberOfKeys + 1; key++ )
|
||||
{
|
||||
if ( keys[key] & (1 << 7) )
|
||||
{
|
||||
processed_keys++;
|
||||
|
||||
// Display the detected scancode
|
||||
char tmpStr[4];
|
||||
int8ToStr( key, tmpStr );
|
||||
dPrintStrs( tmpStr, " " );
|
||||
|
||||
// Is this a bootloader sequence key?
|
||||
if ( !Bootloader_KeyDetected
|
||||
&& Bootloader_NextPositionReady
|
||||
&& key == Bootloader_ConditionSequence[Bootloader_ConditionState] )
|
||||
{
|
||||
Bootloader_KeyDetected = 1;
|
||||
Bootloader_NextPositionReady = 0;
|
||||
Bootloader_ConditionState++;
|
||||
}
|
||||
else if ( Bootloader_ConditionState > 0 && key == Bootloader_ConditionSequence[Bootloader_ConditionState - 1] )
|
||||
{
|
||||
Bootloader_KeyDetected = 1;
|
||||
}
|
||||
|
||||
// Determine if the key is a modifier
|
||||
uint8_t modFound = 0;
|
||||
for ( uint8_t mod = 0; mod < numberOfModifiers; mod++ ) {
|
||||
// Modifier found
|
||||
if ( modifiers[mod] == key ) {
|
||||
USBKeys_Modifiers |= map[key];
|
||||
modFound = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Modifier, already done this loop
|
||||
if ( modFound )
|
||||
continue;
|
||||
|
||||
// Too many keys
|
||||
if ( USBKeys_Sent >= USBKeys_MaxSize )
|
||||
{
|
||||
info_print("USB Key limit reached");
|
||||
errorLED( 1 );
|
||||
break;
|
||||
}
|
||||
|
||||
// Allow ignoring keys with 0's
|
||||
if ( map[key] != 0 )
|
||||
USBKeys_Array[USBKeys_Sent++] = map[key];
|
||||
}
|
||||
}
|
||||
|
||||
// Boot loader sequence state handler
|
||||
switch ( processed_keys )
|
||||
{
|
||||
// The next bootloader key can now be pressed, if there were no keys processed
|
||||
case 0:
|
||||
Bootloader_NextPositionReady = 1;
|
||||
break;
|
||||
// If keys were detected, and it wasn't in the sequence (or there was multiple keys detected), start bootloader sequence over
|
||||
// This case purposely falls through
|
||||
case 1:
|
||||
if ( Bootloader_KeyDetected )
|
||||
break;
|
||||
default:
|
||||
Bootloader_ConditionState = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
// Add debug separator if keys sent via USB
|
||||
if ( USBKeys_Sent > 0 )
|
||||
print("\033[1;32m|\033[0m\n");
|
||||
}
|
||||
*/
|
||||
|
||||
// Given a list of keypresses, translate into the USB key codes
|
||||
// The buffer is cleared after running
|
||||
// If the buffer doesn't fit into the USB send array, the extra keys are dropped
|
||||
void keyPressBufferRead( uint8_t *modifiers, uint8_t numberOfModifiers, uint8_t *map )
|
||||
{
|
||||
// Loop through input buffer
|
||||
for ( uint8_t index = 0; index < KeyIndex_BufferUsed; index++ )
|
||||
{
|
||||
// Get the keycode from the buffer
|
||||
uint8_t key = KeyIndex_Buffer[index];
|
||||
|
||||
// Determine if the key is a modifier
|
||||
uint8_t modFound = 0;
|
||||
for ( uint8_t mod = 0; mod < numberOfModifiers; mod++ ) {
|
||||
// Modifier found
|
||||
if ( modifiers[mod] == key ) {
|
||||
USBKeys_Modifiers |= map[key];
|
||||
modFound = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Modifier, already done this loop
|
||||
if ( modFound )
|
||||
continue;
|
||||
|
||||
// Too many keys
|
||||
if ( USBKeys_Sent >= USBKeys_MaxSize )
|
||||
{
|
||||
info_print("USB Key limit reached");
|
||||
errorLED( 1 );
|
||||
break;
|
||||
}
|
||||
|
||||
// Allow ignoring keys with 0's
|
||||
if ( map[key] != 0 )
|
||||
{
|
||||
USBKeys_Array[USBKeys_Sent++] = map[key];
|
||||
}
|
||||
else
|
||||
{
|
||||
// Key was not mapped
|
||||
// TODO Add dead key map
|
||||
char tmpStr[6];
|
||||
hexToStr( key, tmpStr );
|
||||
erro_dPrint( "Key not mapped... - ", tmpStr );
|
||||
errorLED( 1 );
|
||||
}
|
||||
}
|
||||
|
||||
// Signal buffer that we've used it
|
||||
scan_finishedWithBuffer();
|
||||
}
|
||||
|
||||
inline void process_macros(void)
|
||||
{
|
||||
// Online process macros once (if some were found), until the next USB send
|
||||
if ( USBKeys_Sent != 0 )
|
||||
return;
|
||||
|
||||
// Query the input buffer for keypresses
|
||||
keyPressBufferRead( MODIFIER_MASK, sizeof(MODIFIER_MASK), KEYINDEX_MASK );
|
||||
|
||||
// Check for bootloader condition
|
||||
//if ( Bootloader_ConditionState == sizeof( Bootloader_ConditionSequence ) )
|
||||
// jumpToBootloader();
|
||||
}
|
||||
|
38
Macro/buffer/macro.h
Normal file
38
Macro/buffer/macro.h
Normal file
@ -0,0 +1,38 @@
|
||||
/* Copyright (C) 2011 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 __macro_h
|
||||
#define __macro_h
|
||||
|
||||
// ----- Includes -----
|
||||
|
||||
// Compiler Includes
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
|
||||
// ----- Functions -----
|
||||
|
||||
void keyPressDetection( uint8_t *keys, uint8_t numberOfKeys, uint8_t *modifiers, uint8_t numberOfModifiers, uint8_t *map );
|
||||
void process_macros(void);
|
||||
|
||||
#endif
|
||||
|
22
Macro/buffer/setup.cmake
Normal file
22
Macro/buffer/setup.cmake
Normal file
@ -0,0 +1,22 @@
|
||||
###| CMake Kiibohd Controller Macro Module |###
|
||||
#
|
||||
# Written by Jacob Alexander in 2011 for the Kiibohd Controller
|
||||
#
|
||||
# Released into the Public Domain
|
||||
#
|
||||
###
|
||||
|
||||
|
||||
###
|
||||
# Module C files
|
||||
#
|
||||
|
||||
set( MACRO_SRCS
|
||||
macro.c
|
||||
)
|
||||
|
||||
|
||||
###
|
||||
# Module Specific Options
|
||||
#
|
||||
|
225
Scan/MicroSwitch8304/scan_loop.c
Normal file
225
Scan/MicroSwitch8304/scan_loop.c
Normal file
@ -0,0 +1,225 @@
|
||||
/* Copyright (C) 2011 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.
|
||||
*/
|
||||
|
||||
// ----- Includes -----
|
||||
|
||||
// AVR Includes
|
||||
#include <avr/interrupt.h>
|
||||
#include <avr/io.h>
|
||||
#include <util/delay.h>
|
||||
|
||||
// Project Includes
|
||||
#include <led.h>
|
||||
#include <print.h>
|
||||
|
||||
// Local Includes
|
||||
#include "scan_loop.h"
|
||||
|
||||
|
||||
|
||||
// ----- Defines -----
|
||||
|
||||
// Pinout Defines
|
||||
#define RESET_PORT PORTB
|
||||
#define RESET_DDR DDRD
|
||||
#define RESET_PIN 0
|
||||
|
||||
|
||||
// ----- Macros -----
|
||||
|
||||
// Make sure we haven't overflowed the buffer
|
||||
#define bufferAdd(byte) \
|
||||
if ( KeyIndex_BufferUsed < KEYBOARD_BUFFER ) \
|
||||
KeyIndex_Buffer[KeyIndex_BufferUsed++] = byte
|
||||
|
||||
#define UNSET_RESET() RESET_DDR &= ~(1 << RESET_PIN)
|
||||
#define SET_RESET() RESET_DDR |= (1 << RESET_PIN)
|
||||
|
||||
|
||||
|
||||
// ----- Variables -----
|
||||
|
||||
// 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;
|
||||
|
||||
|
||||
// Buffer Signals
|
||||
volatile uint8_t BufferReadyToClear;
|
||||
|
||||
|
||||
|
||||
// ----- Functions -----
|
||||
|
||||
// Setup
|
||||
inline void scan_setup()
|
||||
{
|
||||
// Setup the the USART interface for keyboard data input
|
||||
// NOTE: The input data signal needs to be inverted for the Teensy USART to properly work
|
||||
|
||||
// Setup baud rate
|
||||
// 16 MHz / ( 16 * Baud ) = UBRR
|
||||
// Baud <- 0.82020 ms per bit, thus 1000 / 0.82020 = 1219.2
|
||||
// Thus baud = 820
|
||||
uint16_t baud = 820; // Max setting of 4095
|
||||
UBRR1H = (uint8_t)(baud >> 8);
|
||||
UBRR1L = (uint8_t)baud;
|
||||
|
||||
// Enable the receiver, transitter, and RX Complete Interrupt
|
||||
UCSR1B = 0x98;
|
||||
|
||||
// Set frame format: 8 data, no stop bits or parity
|
||||
// Asynchrounous USART mode
|
||||
// 8304 sends encoded scancodes (for example Alphanumeric 0-9 follows their keypad encoding scheme)
|
||||
// Separate line is for reset
|
||||
UCSR1C = 0x06;
|
||||
|
||||
// Initially buffer doesn't need to be cleared (it's empty...)
|
||||
BufferReadyToClear = 0;
|
||||
}
|
||||
|
||||
|
||||
// Main Detection Loop
|
||||
// Not needed for the Micro Switch 8304, this is just a busy loop
|
||||
inline uint8_t scan_loop()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void processKeyValue( uint8_t keyValue )
|
||||
{
|
||||
// Finalize output buffer
|
||||
// Mask 8th bit
|
||||
keyValue &= 0x7F;
|
||||
|
||||
// Interpret scan code
|
||||
switch ( keyValue )
|
||||
{
|
||||
case 0x40: // Clear buffer command
|
||||
info_print("CLEAR!");
|
||||
|
||||
BufferReadyToClear = 1;
|
||||
break;
|
||||
case 0x7F:
|
||||
scan_lockKeyboard();
|
||||
_delay_ms(3000);
|
||||
scan_unlockKeyboard();
|
||||
|
||||
default:
|
||||
// Make sure the key isn't already in the buffer
|
||||
for ( uint8_t c = 0; c < KeyIndex_BufferUsed + 1; c++ )
|
||||
{
|
||||
// Key isn't in the buffer yet
|
||||
if ( c == KeyIndex_BufferUsed )
|
||||
{
|
||||
bufferAdd( keyValue );
|
||||
break;
|
||||
}
|
||||
|
||||
// Key already in the buffer
|
||||
if ( KeyIndex_Buffer[c] == keyValue )
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// USART Receive Buffer Full Interrupt
|
||||
ISR(USART1_RX_vect)
|
||||
{
|
||||
cli(); // Disable Interrupts
|
||||
|
||||
uint8_t keyValue = 0x00;
|
||||
|
||||
// The interrupt is always for the first item of the packet set, reset the buffer
|
||||
KeyIndex_BufferUsed = 0;
|
||||
|
||||
// Only the first 7 bits have scancode data
|
||||
// The last packet of the packet set has the 8th bit high, all the others are low
|
||||
//
|
||||
// Interrupts are too slow for the rest of the packet set, poll for the rest
|
||||
while ( 1 )
|
||||
{
|
||||
// Read the raw packet from the USART
|
||||
keyValue = UDR1;
|
||||
|
||||
// Debug
|
||||
char tmpStr[6];
|
||||
hexToStr( keyValue, tmpStr );
|
||||
dPrintStrs( tmpStr, " " );
|
||||
|
||||
// Process the scancode
|
||||
processKeyValue( keyValue );
|
||||
|
||||
// Last packet of the set
|
||||
if ( keyValue & 0x80 )
|
||||
{
|
||||
dPrintStrs( "**" );
|
||||
break;
|
||||
}
|
||||
|
||||
// Delay enough so we don't run into the same packet (or the previous buffered packet)
|
||||
_delay_us(10000);
|
||||
}
|
||||
|
||||
sei(); // Re-enable Interrupts
|
||||
}
|
||||
|
||||
// Send data
|
||||
//
|
||||
// Keyboard Input Guide for Micro Switch 8304
|
||||
// 0xBX is for LED F1,F2,Over Type,Lock
|
||||
// 0xAX is for LED F3,F8,F9,F10
|
||||
// 0x92 resets keyboard (LED off, echo scancode mode off)
|
||||
// 0x9E sets echo scancode mode from (0x81 to 0xFF; translates to 0x01 to 0x7F)
|
||||
// Other echos: 0x15~0x19 send 0x15~0x19, 0x40 sends 0x40 (as well as 0x44,0x45, 0x80)
|
||||
// 0x8C Acks the keyboard and gets 0x70 sent back (delayed)
|
||||
uint8_t scan_sendData( uint8_t dataPayload )
|
||||
{
|
||||
UDR1 = dataPayload;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Signal KeyIndex_Buffer that it has been properly read
|
||||
// In the case of the Micro Switch 8304, we leave the buffer alone until more scancode data comes in
|
||||
void scan_finishedWithBuffer( void )
|
||||
{
|
||||
// We received a Clear code from the 8304, clear the buffer now that we've used it
|
||||
if ( BufferReadyToClear )
|
||||
{
|
||||
KeyIndex_BufferUsed = 0;
|
||||
BufferReadyToClear = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Reset/Hold keyboard
|
||||
// Warning! This will cause the keyboard to not send any data, so you can't disable with a keypress
|
||||
// The Micro Switch 8304 has a dedicated reset line
|
||||
void scan_lockKeyboard( void )
|
||||
{
|
||||
UNSET_RESET();
|
||||
}
|
||||
|
||||
void scan_unlockKeyboard( void )
|
||||
{
|
||||
SET_RESET();
|
||||
}
|
||||
|
64
Scan/MicroSwitch8304/scan_loop.h
Normal file
64
Scan/MicroSwitch8304/scan_loop.h
Normal file
@ -0,0 +1,64 @@
|
||||
/* Copyright (C) 2011 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 __SCAN_LOOP_H
|
||||
#define __SCAN_LOOP_H
|
||||
|
||||
// ----- Includes -----
|
||||
|
||||
// Compiler Includes
|
||||
#include <stdint.h>
|
||||
|
||||
// Local Includes
|
||||
|
||||
|
||||
|
||||
// ----- Defines -----
|
||||
|
||||
#define KEYBOARD_SIZE 0x62 // 76 - Size of the array space for the keyboard(max index)
|
||||
#define KEYBOARD_BUFFER 24 // Max number of key signals to buffer
|
||||
|
||||
|
||||
|
||||
// ----- Variables -----
|
||||
|
||||
extern volatile uint8_t KeyIndex_Buffer[KEYBOARD_BUFFER];
|
||||
extern volatile uint8_t KeyIndex_BufferUsed;
|
||||
|
||||
|
||||
|
||||
// ----- Functions -----
|
||||
|
||||
// Functions used by main.c
|
||||
void scan_setup( void );
|
||||
uint8_t scan_loop( void );
|
||||
|
||||
|
||||
// Functions available to macro.c
|
||||
uint8_t scan_sendData( uint8_t dataPayload );
|
||||
|
||||
void scan_finishedWithBuffer( void );
|
||||
void scan_lockKeyboard( void );
|
||||
void scan_unlockKeyboard( void );
|
||||
|
||||
|
||||
#endif // __SCAN_LOOP_H
|
||||
|
48
Scan/MicroSwitch8304/setup.cmake
Normal file
48
Scan/MicroSwitch8304/setup.cmake
Normal file
@ -0,0 +1,48 @@
|
||||
###| CMake Kiibohd Controller Scan Module |###
|
||||
#
|
||||
# Written by Jacob Alexander in 2011 for the Kiibohd Controller
|
||||
#
|
||||
# Released into the Public Domain
|
||||
#
|
||||
# For the Micro Switch 8304 Keyboard (No Branding)
|
||||
#
|
||||
###
|
||||
|
||||
|
||||
###
|
||||
# Module C files
|
||||
#
|
||||
|
||||
set( SCAN_SRCS
|
||||
scan_loop.c
|
||||
)
|
||||
|
||||
|
||||
###
|
||||
# Module H files
|
||||
#
|
||||
set( SCAN_HDRS
|
||||
scan_loop.h
|
||||
)
|
||||
|
||||
|
||||
###
|
||||
# File Dependency Setup
|
||||
#
|
||||
ADD_FILE_DEPENDENCIES( scan_loop.c ${SCAN_HDRS} )
|
||||
#add_file_dependencies( scan_loop.c ${SCAN_HDRS} )
|
||||
#add_file_dependencies( macro.c keymap.h microswitch8304.h )
|
||||
|
||||
|
||||
###
|
||||
# Module Specific Options
|
||||
#
|
||||
add_definitions( -I${HEAD_DIR}/Keymap )
|
||||
|
||||
#| Keymap Settings
|
||||
add_definitions(
|
||||
-DMODIFIER_MASK=microswitch8304_ModifierMask
|
||||
-DKEYINDEX_MASK=microswitch8304_ColemakMap
|
||||
#-DKEYINDEX_MASK=microswitch8304_DefaultMap
|
||||
)
|
||||
|
1
main.c
1
main.c
@ -146,6 +146,7 @@ int main(void)
|
||||
}
|
||||
}
|
||||
|
||||
// USB Keyboard Data Send Counter Interrupt
|
||||
ISR( TIMER0_OVF_vect )
|
||||
{
|
||||
sendKeypressCounter++;
|
||||
|
@ -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 "Kaypro1" )
|
||||
set( ScanModule "MicroSwitch8304" )
|
||||
|
||||
##| Uses the key index and potentially applies special conditions to it, mapping it to a usb key code
|
||||
set( MacroModule "buffer" )
|
||||
@ -78,6 +78,7 @@ macro( PathPrepend Output SourcesPath )
|
||||
|
||||
# Loop through items
|
||||
foreach( item ${ARGN} )
|
||||
# Set the path
|
||||
set( tmpSource ${tmpSource} "${SourcesPath}/${item}" )
|
||||
endforeach( item )
|
||||
|
||||
|
Reference in New Issue
Block a user