Archived
1
0

Intial commit of the SonyNEWS scan module

- Keyboard output fully working
- Not all of the features are implemented yet (input, speaker, or power
  detection)
- There is no plan for mouse support
This commit is contained in:
Jacob Alexander 2011-12-04 19:55:32 -08:00
parent ac5f6c015d
commit ea2654b662
9 changed files with 657 additions and 15 deletions

View File

@ -45,6 +45,7 @@
#include "heathzenith.h"
#include "kaypro1.h"
#include "microswitch8304.h"
#include "sonynews.h"
#include "tandy1000.h"

View File

@ -19,10 +19,10 @@
* THE SOFTWARE.
*/
#ifndef __TANDY1000_H
#define __TANDY1000_H
#ifndef __MICROSWITCH8304_H
#define __MICROSWITCH8304_H
// This file contains various key layouts for the Tandy 1000 keyboard
// This file contains various key layouts for the Convergent microswitch8304 keyboard
// ----- Variables -----

299
Keymap/sonynews.h Normal file
View File

@ -0,0 +1,299 @@
/* 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 __SONYNEWS_H
#define __SONYNEWS_H
// This file contains various key layouts for the Sony NEWS Topre Keyboard
// TODO
// ----- Variables -----
static uint8_t sonynews_ModifierMask[] = { 0x28, 0x36, 0x42, 0x43, 0x4A };
static uint8_t sonynews_DefaultMap[] = {
0x00, // 0x00
KEY_F1, // 0x01
KEY_F2, // 0x02
KEY_F3, // 0x03
KEY_F4, // 0x04
KEY_F5, // 0x05
KEY_F6, // 0x06
KEY_F7, // 0x07
KEY_F8, // 0x08
KEY_F9, // 0x09
KEY_F10, // 0x0A
KEY_ESC, // 0x0B
KEY_1, // 0x0C
KEY_2, // 0x0D
KEY_3, // 0x0E
KEY_4, // 0x0F
KEY_5, // 0x10
KEY_6, // 0x11
KEY_7, // 0x12
KEY_8, // 0x13
KEY_9, // 0x14
KEY_0, // 0x15
KEY_MINUS, // 0x16
KEY_EQUAL, // 0x17
KEY_INTER3, // 0x18 - Yen
KEY_BACKSPACE, // 0x19
KEY_TAB, // 0x1A
KEY_Q, // 0x1B
KEY_W, // 0x1C
KEY_E, // 0x1D
KEY_R, // 0x1E
KEY_T, // 0x1F
KEY_Y, // 0x20
KEY_U, // 0x21
KEY_I, // 0x22
KEY_O, // 0x23
KEY_P, // 0x24
KEY_LEFT_BRACE, // 0x25
KEY_RIGHT_BRACE, // 0x26
KEY_DELETE, // 0x27
KEY_CTRL, // 0x28
KEY_A, // 0x29
KEY_S, // 0x2A
KEY_D, // 0x2B
KEY_F, // 0x2C
KEY_G, // 0x2D
KEY_H, // 0x2E
KEY_J, // 0x2F
KEY_K, // 0x30
KEY_L, // 0x31
KEY_SEMICOLON, // 0x32
KEY_QUOTE, // 0x33
KEY_BACKSLASH, // 0x34
KEY_ENTER, // 0x35
KEY_LEFT_SHIFT, // 0x36
KEY_Z, // 0x37
KEY_X, // 0x38
KEY_C, // 0x39
KEY_V, // 0x3A
KEY_B, // 0x3B
KEY_N, // 0x3C
KEY_M, // 0x3D
KEY_COMMA, // 0x3E
KEY_PERIOD, // 0x3F
KEY_SLASH, // 0x40
KEY_INTER1, // 0x41 - "Ru" and "-"
KEY_RIGHT_SHIFT, // 0x42
KEY_ALT, // 0x43
KEY_CAPS_LOCK, // 0x44
KEY_INTER5, // 0x45 - Muhenkan
KEY_SPACE, // 0x46
KEY_INTER4, // 0x47 - Henkan
KEY_LANG2, // 0x48 - Eisu (English/Numbers) (I've seen references to this mapping)
KEY_INTER2, // 0x49 - Kana
KEY_EXEC, // 0x4A - Jikkou XXX Which means Execute, and since there is no Language key
KEYPAD_7, // 0x4B
KEYPAD_8, // 0x4C
KEYPAD_9, // 0x4D
KEYPAD_MINUS, // 0x4E
KEYPAD_4, // 0x4F
KEYPAD_5, // 0x50
KEYPAD_6, // 0x51
KEYPAD_PLUS, // 0x52
KEYPAD_1, // 0x53
KEYPAD_2, // 0x54
KEYPAD_3, // 0x55
KEYPAD_COMMA, // 0x56
KEYPAD_0, // 0x57
KEY_UP, // 0x58
KEYPAD_PERIOD, // 0x59
KEYPAD_ENTER, // 0x5A
KEY_LEFT, // 0x5B
KEY_DOWN, // 0x5C
KEY_RIGHT, // 0x5D
0, // 0x5E
0, // 0x5F
0, // 0x60
0, // 0x61
0, // 0x62
0, // 0x63
KEYPAD_ASTERIX, // 0x64
KEYPAD_SLASH, // 0x65
KEYPAD_TAB, // 0x66
0, // 0x67
KEY_F11, // 0x68
KEY_F12, // 0x69
KEY_HELP, // 0x6A
KEY_INSERT, // 0x6B
KEY_CLEAR, // 0x6C
KEY_PAGE_UP, // 0x6D
KEY_PAGE_DOWN, // 0x6E
0, // 0x6F
0, // 0x70
0, // 0x71
0, // 0x72
0, // 0x73
0, // 0x74
0, // 0x75
0, // 0x76
0, // 0x77
0, // 0x78
0, // 0x79
KEY_F13, // 0x7A
0, // 0x7B
0, // 0x7C
0, // 0x7D
0, // 0x7E
0, // 0x7F
};
static uint8_t sonynews_ColemakMap[] = {
0x00, // 0x00
KEY_F1, // 0x01
KEY_F2, // 0x02
KEY_F3, // 0x03
KEY_F4, // 0x04
KEY_F5, // 0x05
KEY_F6, // 0x06
KEY_F7, // 0x07
KEY_F8, // 0x08
KEY_F9, // 0x09
KEY_F10, // 0x0A
KEY_ESC, // 0x0B
KEY_1, // 0x0C
KEY_2, // 0x0D
KEY_3, // 0x0E
KEY_4, // 0x0F
KEY_5, // 0x10
KEY_6, // 0x11
KEY_7, // 0x12
KEY_8, // 0x13
KEY_9, // 0x14
KEY_0, // 0x15
KEY_MINUS, // 0x16
KEY_EQUAL, // 0x17
KEY_INTER3, // 0x18 - Yen
KEY_BACKSPACE, // 0x19
KEY_TAB, // 0x1A
KEY_Q, // 0x1B
KEY_W, // 0x1C
KEY_F, // 0x1D
KEY_P, // 0x1E
KEY_G, // 0x1F
KEY_J, // 0x20
KEY_L, // 0x21
KEY_U, // 0x22
KEY_Y, // 0x23
KEY_SEMICOLON, // 0x24
KEY_LEFT_BRACE, // 0x25
KEY_RIGHT_BRACE, // 0x26
KEY_DELETE, // 0x27
KEY_CTRL, // 0x28
KEY_A, // 0x29
KEY_R, // 0x2A
KEY_S, // 0x2B
KEY_T, // 0x2C
KEY_D, // 0x2D
KEY_H, // 0x2E
KEY_N, // 0x2F
KEY_E, // 0x30
KEY_I, // 0x31
KEY_O, // 0x32
KEY_QUOTE, // 0x33
KEY_BACKSLASH, // 0x34
KEY_ENTER, // 0x35
KEY_LEFT_SHIFT, // 0x36
KEY_Z, // 0x37
KEY_X, // 0x38
KEY_C, // 0x39
KEY_V, // 0x3A
KEY_B, // 0x3B
KEY_K, // 0x3C
KEY_M, // 0x3D
KEY_COMMA, // 0x3E
KEY_PERIOD, // 0x3F
KEY_SLASH, // 0x40
KEY_INTER1, // 0x41 - "Ru" and "-"
KEY_RIGHT_SHIFT, // 0x42
KEY_ALT, // 0x43
KEY_CAPS_LOCK, // 0x44
KEY_INTER5, // 0x45 - Muhenkan
KEY_SPACE, // 0x46
KEY_INTER4, // 0x47 - Henkan
KEY_LANG2, // 0x48 - Eisu (English/Numbers) (I've seen references to this mapping)
KEY_INTER2, // 0x49 - Kana
//KEY_EXEC, // 0x4A - Jikkou XXX Which means Execute, and since there is no Language key
KEY_GUI, // 0x4A - Using Jikkou as Windows Key
KEYPAD_7, // 0x4B
KEYPAD_8, // 0x4C
KEYPAD_9, // 0x4D
KEYPAD_MINUS, // 0x4E
KEYPAD_4, // 0x4F
KEYPAD_5, // 0x50
KEYPAD_6, // 0x51
KEYPAD_PLUS, // 0x52
KEYPAD_1, // 0x53
KEYPAD_2, // 0x54
KEYPAD_3, // 0x55
KEYPAD_COMMA, // 0x56
KEYPAD_0, // 0x57
KEY_UP, // 0x58
KEYPAD_PERIOD, // 0x59
KEYPAD_ENTER, // 0x5A
KEY_LEFT, // 0x5B
KEY_DOWN, // 0x5C
KEY_RIGHT, // 0x5D
0, // 0x5E
0, // 0x5F
0, // 0x60
0, // 0x61
0, // 0x62
0, // 0x63
KEYPAD_ASTERIX, // 0x64
KEYPAD_SLASH, // 0x65
KEYPAD_TAB, // 0x66
0, // 0x67
KEY_F11, // 0x68
KEY_F12, // 0x69
KEY_HELP, // 0x6A
KEY_INSERT, // 0x6B
KEY_CLEAR, // 0x6C
KEY_PAGE_UP, // 0x6D
KEY_PAGE_DOWN, // 0x6E
0, // 0x6F
0, // 0x70
0, // 0x71
0, // 0x72
0, // 0x73
0, // 0x74
0, // 0x75
0, // 0x76
0, // 0x77
0, // 0x78
0, // 0x79
KEY_F13, // 0x7A
0, // 0x7B
0, // 0x7C
0, // 0x7D
0, // 0x7E
0, // 0x7F
};
#endif

View File

@ -170,17 +170,17 @@
#define KEY_SCROLL_LLOCK 132
#define KEYPAD_COMMA 133 // Brazillian (See spec)
#define KEYPAD_EQUAL_AS 134 // AS/400 Keyboard (See spec)
#define KEY_INTER1 135 // Brazillian and Japanese "Ru"
#define KEY_INTER2 136 // Japanese Katakana/Hiragana
#define KEY_INTER3 137 // Japanese Yen
#define KEY_INTER4 138 // Japanese Henkan
#define KEY_INTER5 139 // Japanese Muhenkan
#define KEY_INTER6 140 // PC98 Comma (Ka-m-ma)
#define KEY_INTER7 141 // Double-Byte/Single-Byte Toggle
#define KEY_INTER8 142 // Undefined
#define KEY_INTER9 143 // Undefined
#define KEY_INTER1 135 // KANJI1 - Brazillian and Japanese "Ru" and "-"
#define KEY_INTER2 136 // KANJI2 - Japanese Katakana/Hiragana
#define KEY_INTER3 137 // KANJI3 - Japanese Yen
#define KEY_INTER4 138 // KANJI4 - Japanese Henkan
#define KEY_INTER5 139 // KANJI5 - Japanese Muhenkan
#define KEY_INTER6 140 // KANJI6 - PC98 Comma (Ka-m-ma)
#define KEY_INTER7 141 // KANJI7 - Double-Byte/Single-Byte Toggle
#define KEY_INTER8 142 // KANJI8 - Undefined
#define KEY_INTER9 143 // KANJI9 - Undefined
#define KEY_LANG1 144 // Korean Hangul/English Toggle
#define KEY_LANG2 145 // Korean Hanja Conversion
#define KEY_LANG2 145 // Korean Hanja Conversion - Japanese Eisu
#define KEY_LANG3 146 // Japanese Katakana Key (USB)
#define KEY_LANG4 147 // Japanese Hiragana Key (USB)
#define KEY_LANG5 148 // Japanese Zenkaku/Hankaku Key (USB)

View File

@ -74,7 +74,7 @@ inline void scan_setup()
// Setup baud rate
// 16 MHz / ( 16 * Baud ) = UBRR
// Baud <- 3.358 ms per bit, thus 1000 / 3.358 = 297.80
// Thus baud = 3357
// Thus USBRR = 3357
uint16_t baud = 3357; // Max setting of 4095
UBRR1H = (uint8_t)(baud >> 8);
UBRR1L = (uint8_t)baud;

View File

@ -78,7 +78,7 @@ inline void scan_setup()
// Setup baud rate
// 16 MHz / ( 16 * Baud ) = UBRR
// Baud <- 0.82020 ms per bit, thus 1000 / 0.82020 = 1219.2
// Thus baud = 820
// Thus baud setting = 820
uint16_t baud = 820; // Max setting of 4095
UBRR1H = (uint8_t)(baud >> 8);
UBRR1L = (uint8_t)baud;

229
Scan/SonyNEWS/scan_loop.c Normal file
View File

@ -0,0 +1,229 @@
/* 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;
// ----- Functions -----
// Setup
inline void scan_setup()
{
// Setup the the USART interface for keyboard data input
// Setup baud rate
// 16 MHz / ( 16 * Baud ) = UBRR
// Baud <- 0.10450 ms per bit, thus 1000 / 0.10450 = 9569.4
// Thus UBRR = 104.50
// To deal with the 0.5, setting to double speed, which means UBRR = 209
uint16_t baud = 209; // Max setting of 4095
UBRR1H = (uint8_t)(baud >> 8);
UBRR1L = (uint8_t)baud;
// Enable Double Read Speed
UCSR1A = 0x02;
// Enable the receiver, transitter, and RX Complete Interrupt
UCSR1B = 0x98;
// Set frame format: 8 data, no stop bits or parity
// Asynchrounous USART mode
UCSR1C = 0x06;
// Reset the keyboard before scanning, we might be in a wierd state
scan_resetKeyboard();
}
// Main Detection Loop
// Not needed for the Sony NEWS, this is just a busy loop
inline uint8_t scan_loop()
{
return 0;
}
void processKeyValue( uint8_t keyValue )
{
// Detect release condition
uint8_t release = keyValue & 0x80;
// Finalize output buffer
// Mask 8th bit
keyValue &= 0x7F;
// Key Release
if ( release )
{
// 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 );
}
}
// Press or Repeat Rate
else
{
// 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;
}
}
}
// USART Receive Buffer Full Interrupt
ISR(USART1_RX_vect)
{
cli(); // Disable Interrupts
uint8_t keyValue = 0x00;
// One scancode at a time (fastest interval ~3.95 ms - recorded, should still be ok for interrupt polling)
// Read the raw packet from the USART
keyValue = UDR1;
// Debug
char tmpStr[6];
hexToStr( keyValue, tmpStr );
dPrintStrs( tmpStr, " " );
// Process the scancode
processKeyValue( keyValue );
sei(); // Re-enable Interrupts
}
// Send data TODO
//
// 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
// Not needed as a signal is sent to remove key-presses
void scan_finishedWithBuffer( void )
{
return;
}
// Reset/Hold keyboard TODO
// 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();
}
// Reset Keyboard TODO
void scan_resetKeyboard( void )
{
// Reset command for the 8304
//scan_sendData( 0x92 );
// Empty buffer, now that keyboard has been reset
KeyIndex_BufferUsed = 0;
}

65
Scan/SonyNEWS/scan_loop.h Normal file
View File

@ -0,0 +1,65 @@
/* 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 0x68 // 104 - 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 );
void scan_resetKeyboard( void );
#endif // __SCAN_LOOP_H

48
Scan/SonyNEWS/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 Sony NEWS Topre Keyboard
#
###
###
# 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 sonynews.h )
###
# Module Specific Options
#
add_definitions( -I${HEAD_DIR}/Keymap )
#| Keymap Settings
add_definitions(
-DMODIFIER_MASK=sonynews_ModifierMask
-DKEYINDEX_MASK=sonynews_ColemakMap
#-DKEYINDEX_MASK=sonynews_DefaultMap
)