Adding initial Teensy 3 support, compiles, but not fully functional yet.
- CDC Output seems to be working - USB Keyboard output has not been tested, but is "ready" - UART and Timers have not been tested, or fully utilized - Issues using Timer 0 - Initial template for MBC-55X Scan module (only module currently compatible with the arm build) - Updated the interface to the AVR usb module for symmetry with the ARM usb module - Much gutting was done to the Teensy 3 usb keyboard module, though not in an ideal state yet
This commit is contained in:
parent
6da1558b78
commit
c8b4baf652
29 changed files with 4501 additions and 34 deletions
236
Scan/MBC-55X/scan_loop.c
Normal file
236
Scan/MBC-55X/scan_loop.c
Normal file
|
@ -0,0 +1,236 @@
|
|||
/* Copyright (C) 2013 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 -----
|
||||
|
||||
// Compiler Includes
|
||||
#include <Lib/ScanLib.h>
|
||||
|
||||
// Project Includes
|
||||
#include <led.h>
|
||||
#include <print.h>
|
||||
|
||||
// Local Includes
|
||||
#include "scan_loop.h"
|
||||
|
||||
|
||||
|
||||
// ----- Defines -----
|
||||
|
||||
|
||||
// ----- 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;
|
||||
|
||||
|
||||
|
||||
// ----- Function Declarations -----
|
||||
|
||||
void processKeyValue( uint8_t valueType );
|
||||
void removeKeyValue( uint8_t keyValue );
|
||||
|
||||
|
||||
|
||||
// ----- Interrupt Functions -----
|
||||
|
||||
// UART Receive Buffer Full Interrupt
|
||||
#if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_) // AVR
|
||||
ISR(USART1_RX_vect)
|
||||
#elif defined(_mk20dx128_) // ARM
|
||||
void uart0_status_isr(void)
|
||||
#endif
|
||||
{
|
||||
cli(); // Disable Interrupts
|
||||
|
||||
// Read part of the scan code (3 8bit chunks) from USART
|
||||
#if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_) // AVR
|
||||
uint8_t tmp = UDR1;
|
||||
#elif defined(_mk20dx128_) // ARM
|
||||
// TODO
|
||||
uint8_t tmp = 0;
|
||||
#endif
|
||||
|
||||
// Debug
|
||||
char tmpStr[6];
|
||||
hexToStr( tmp, tmpStr );
|
||||
dPrintStrs( tmpStr, " " ); // Debug
|
||||
|
||||
// TODO
|
||||
|
||||
sei(); // Re-enable Interrupts
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ----- Functions -----
|
||||
|
||||
// Setup
|
||||
inline void scan_setup()
|
||||
#if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_) // AVR
|
||||
{
|
||||
// Setup the the USART interface for keyboard data input
|
||||
|
||||
// TODO
|
||||
// Setup baud rate
|
||||
// 16 MHz / ( 16 * Baud ) = UBRR
|
||||
// Baud: 4817 -> 16 MHz / ( 16 * 4817 ) = 207.5981
|
||||
// Thus baud setting = 208
|
||||
uint16_t baud = 208; // Max setting of 4095
|
||||
UBRR1H = (uint8_t)(baud >> 8);
|
||||
UBRR1L = (uint8_t)baud;
|
||||
|
||||
// Enable the receiver, transmitter, and RX Complete Interrupt
|
||||
UCSR1B = 0x98;
|
||||
|
||||
// Set frame format: 8 data, 1 stop bit, odd parity
|
||||
// Asynchrounous USART mode
|
||||
UCSR1C = 0x36;
|
||||
|
||||
// Reset the keyboard before scanning, we might be in a wierd state
|
||||
scan_resetKeyboard();
|
||||
}
|
||||
#elif defined(_mk20dx128_) // ARM
|
||||
{
|
||||
// Setup the the UART interface for keyboard data input
|
||||
|
||||
// Setup baud rate
|
||||
// TODO
|
||||
|
||||
// Reset the keyboard before scanning, we might be in a wierd state
|
||||
scan_resetKeyboard();
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
// Main Detection Loop
|
||||
inline uint8_t scan_loop()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void processKeyValue( uint8_t keyValue )
|
||||
{
|
||||
// TODO Process ASCII
|
||||
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
||||
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 )
|
||||
{
|
||||
// Debug
|
||||
char tmpStr[6];
|
||||
hexToStr( dataPayload, tmpStr );
|
||||
info_dPrint( "Sending - ", tmpStr );
|
||||
|
||||
#if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_) // AVR
|
||||
UDR1 = dataPayload;
|
||||
#elif defined(_mk20dx128_) // ARM
|
||||
// TODO
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Signal KeyIndex_Buffer that it has been properly read
|
||||
void scan_finishedWithBuffer( uint8_t sentKeys )
|
||||
{
|
||||
}
|
||||
|
||||
// Signal that the keys have been properly sent over USB
|
||||
void scan_finishedWithUSBBuffer( uint8_t sentKeys )
|
||||
{
|
||||
}
|
||||
|
||||
// Reset/Hold keyboard
|
||||
// NOTE: Does nothing with the FACOM6684
|
||||
void scan_lockKeyboard( void )
|
||||
{
|
||||
}
|
||||
|
||||
// NOTE: Does nothing with the FACOM6684
|
||||
void scan_unlockKeyboard( void )
|
||||
{
|
||||
}
|
||||
|
||||
// Reset Keyboard
|
||||
void scan_resetKeyboard( void )
|
||||
{
|
||||
// Not a calculated valued...
|
||||
_delay_ms( 50 );
|
||||
|
||||
KeyIndex_BufferUsed = 0;
|
||||
}
|
||||
|
67
Scan/MBC-55X/scan_loop.h
Normal file
67
Scan/MBC-55X/scan_loop.h
Normal file
|
@ -0,0 +1,67 @@
|
|||
/* Copyright (C) 2013 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_KEYS 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( uint8_t sentKeys );
|
||||
void scan_finishedWithUSBBuffer( uint8_t sentKeys );
|
||||
void scan_lockKeyboard( void );
|
||||
void scan_unlockKeyboard( void );
|
||||
void scan_resetKeyboard( void );
|
||||
|
||||
|
||||
#endif // __SCAN_LOOP_H
|
||||
|
48
Scan/MBC-55X/setup.cmake
Normal file
48
Scan/MBC-55X/setup.cmake
Normal file
|
@ -0,0 +1,48 @@
|
|||
###| CMake Kiibohd Controller Scan Module |###
|
||||
#
|
||||
# Written by Jacob Alexander in 2013 for the Kiibohd Controller
|
||||
#
|
||||
# Released into the Public Domain
|
||||
#
|
||||
# For the Sanyo MBC-55X Series of keyboards
|
||||
#
|
||||
###
|
||||
|
||||
|
||||
###
|
||||
# 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 facom6684.h )
|
||||
|
||||
|
||||
###
|
||||
# Module Specific Options
|
||||
#
|
||||
add_definitions( -I${HEAD_DIR}/Keymap )
|
||||
|
||||
#| Keymap Settings
|
||||
add_definitions(
|
||||
-DMODIFIER_MASK=facom6684_ModifierMask
|
||||
#-DKEYINDEX_MASK=facom6684_ColemakMap
|
||||
-DKEYINDEX_MASK=facom6684_DefaultMap
|
||||
)
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue