Adding initial HP150 and IBMConvertible scan modules.

- HP150 is not ready
- IBMConvertible is ready to start testing
This commit is contained in:
Jacob Alexander 2012-11-15 01:28:31 -08:00
parent b8fddd61f5
commit 0c39927268
10 changed files with 969 additions and 1 deletions

239
Scan/HP150/scan_loop.c Normal file
View file

@ -0,0 +1,239 @@
/* 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.
*/
// ----- 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 DATA_PORT PORTC
#define DATA_DDR DDRC
#define DATA_PIN 7
#define CLOCK_PORT PORTC
#define CLOCK_DDR DDRC
#define CLOCK_PIN 6
#define RESET_PORT PORTF
#define RESET_DDR DDRF
#define RESET_PIN 7
// ----- Macros -----
// Make sure we haven't overflowed the buffer
#define bufferAdd(byte) \
if ( KeyIndex_BufferUsed < KEYBOARD_BUFFER ) \
KeyIndex_Buffer[KeyIndex_BufferUsed++] = byte
// ----- 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;
volatile uint8_t KeyIndex_Add_InputSignal; // Used to pass the (click/input value) to the keyboard for the clicker
volatile uint8_t currentWaveState = 0;
// Buffer Signals
volatile uint8_t BufferReadyToClear;
// ----- Function Declarations -----
void processKeyValue( uint8_t keyValue );
void removeKeyValue( uint8_t keyValue );
// ----- Interrupt Functions -----
// Generates a constant external clock
ISR( TIMER1_COMPA_vect )
{
if ( currentWaveState )
{
CLOCK_PORT &= ~(1 << CLOCK_PIN);
currentWaveState--;
}
else
{
CLOCK_PORT |= (1 << CLOCK_PIN);
currentWaveState++;
}
}
// ----- Functions -----
// Setup
inline void scan_setup()
{
// Setup Timer Pulse (16 bit)
// TODO Clock can be adjusted to whatever (read chip datasheets for limits)
// 16 MHz / (2 * Prescaler * (1 + OCR1A)) = 1200.1 baud
// Prescaler is 1
// Twice every 1200 baud (actually 1200.1, timer isn't accurate enough)
// This is close to 820 us, but a bit slower
cli();
TCCR1B = 0x09;
OCR1AH = 0x01;
OCR1AL = 0x09;
TIMSK1 = (1 << OCIE1A);
CLOCK_DDR = (1 << CLOCK_PIN);
sei();
// Initially buffer doesn't need to be cleared (it's empty...)
BufferReadyToClear = 0;
// InputSignal is off by default
KeyIndex_Add_InputSignal = 0x00;
// Reset the keyboard before scanning, we might be in a wierd state
scan_resetKeyboard();
}
// Main Detection Loop
// Since this function is non-interruptable, we can do checks here on what stage of the
// output clock we are at (0 or 1)
// We are looking for a start of packet
// If detected, all subsequent bits are then logged into a variable
// Once the end of the packet has been detected (always the same length), decode the pressed keys
inline uint8_t scan_loop()
{
return 0;
}
void processKeyValue( uint8_t keyValue )
{
// Interpret scan code
switch ( keyValue )
{
case 0x00: // Break code from input?
break;
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 );
// Only send data if enabled
if ( KeyIndex_Add_InputSignal )
scan_sendData( KeyIndex_Add_InputSignal );
break;
}
// Key already in the buffer
if ( KeyIndex_Buffer[c] == keyValue )
break;
}
break;
}
}
void removeKeyValue( uint8_t keyValue )
{
// Check for the released key, and shift the other keys lower on the buffer
uint8_t c;
for ( c = 0; c < KeyIndex_BufferUsed; c++ )
{
// Key to release found
if ( KeyIndex_Buffer[c] == keyValue )
{
// Shift keys from c position
for ( uint8_t k = c; k < KeyIndex_BufferUsed - 1; k++ )
KeyIndex_Buffer[k] = KeyIndex_Buffer[k + 1];
// Decrement Buffer
KeyIndex_BufferUsed--;
break;
}
}
// Error case (no key to release)
if ( c == KeyIndex_BufferUsed + 1 )
{
errorLED( 1 );
char tmpStr[6];
hexToStr( keyValue, tmpStr );
erro_dPrint( "Could not find key to release: ", tmpStr );
}
}
// Send data
uint8_t scan_sendData( uint8_t dataPayload )
{
return 0;
}
// Signal KeyIndex_Buffer that it has been properly read
void scan_finishedWithBuffer( void )
{
}
// Signal that the keys have been properly sent over USB
void scan_finishedWithUSBBuffer( void )
{
}
// Reset/Hold keyboard
// NOTE: Does nothing with the BETKB
void scan_lockKeyboard( void )
{
}
// NOTE: Does nothing with the BETKB
void scan_unlockKeyboard( void )
{
}
// Reset Keyboard
void scan_resetKeyboard( void )
{
// TODO Determine the scan period, and the interval to scan each bit
}

67
Scan/HP150/scan_loop.h Normal file
View file

@ -0,0 +1,67 @@
/* 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 __SCAN_LOOP_H
#define __SCAN_LOOP_H
// ----- Includes -----
// Compiler Includes
#include <stdint.h>
// Local Includes
// ----- Defines -----
#define KEYBOARD_SIZE 0x7F // 127 - 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;
extern volatile uint8_t KeyIndex_Add_InputSignal;
// ----- 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_finishedWithUSBBuffer( void );
void scan_lockKeyboard( void );
void scan_unlockKeyboard( void );
void scan_resetKeyboard( void );
#endif // __SCAN_LOOP_H

48
Scan/HP150/setup.cmake Normal file
View 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 HP150 Keyboard (Fujitsu Leaf Spring)
#
###
###
# 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=hp150_ModifierMask
#-DKEYINDEX_MASK=hp150_ColemakMap
-DKEYINDEX_MASK=hp150_DefaultMap
)

View file

@ -0,0 +1,73 @@
/* 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 90 // # of keys (It actually has 78, but there are markings up to 81 on the PCB and scan lines enough for 90
#define MAX_ROW_SIZE 6 // # of rows
#define MAX_COL_SIZE 15 // # of columns
// ----- Matrix Configuration -----
static const uint8_t matrix_pinout[][MAX_COL_SIZE + 1] = {
// GND Pins
// Board Pins: 2, 8, 14, 20, 24
// OO2 Labels: 3, 7, 13, 19, 25
// IBM Convertible PCB Matrix
// Board Pins labeled as ()
// Board Pins: 26 25 23 22 21 19 17 15 13 11 9 7 5 3 1
// OO2 Labels: 1 2 4 5 6 8 10 12 14 16 18 20 22 24 26
// C1 C2 C3 C4 C5 C6 C7 C8 C9 C10 C11 C12 C13 C14 C15
{ scanMode, pinC0, pinC1, pinC2, pinC3, pinC4, pinC5, pinC6, pinC7, pinF0, pinF1, pinF2, pinF3, pinF4, pinF5, pinF6 },
{ pinE1, 80, 79, 78, 81, 77, 76, 75, 74, 73, 72, 71, 70, 69, 68, 67, }, // R1 - 9 (18)
{ pinE2, 14, 13, 12, 15, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, }, // R2 - 11 (16)
{ pinE3, 0, 28, 27, 0, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, }, // R3 - 15 (12)
{ pinE4, 43, 0, 41, 0, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, }, // R4 - 17 (10)
{ pinE5, 57, 0, 56, 0, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 44, }, // R5 - 21 (6)
{ pinE6, 65, 0, 64, 66, 63, 62, 0, 0, 0, 61, 0, 0, 60, 59, 58, }, // R6 - 23 (4)
};
#endif // __MATRIX_H

View file

@ -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=ibmconv_ModifierMask
#-DKEYINDEX_MASK=ibmconv_DefaultMap
-DKEYINDEX_MASK=ibmconv_ColemakMap
)

View file

@ -145,6 +145,8 @@ uint8_t ddrF = 0x00;
// ----- Functions -----
void matrix_debugPins(void);
// Pin Setup Debug
inline void matrix_debugPins()
{