KeyMapper

From Wiki
Jump to: navigation, search
Finished KeyMapper

Feature Set

  • 8 bit parallel out + strobe
  • Strobe polarity programmable
  • Data output polarity programmable
  • RS-232 serial output
  • Otrona serial output
  • Selectable keymaps
    • 0 - Raw
    • 1 - VT-100
    • 2 - TVI-950
    • 3 - AY5-1015
    • 4 - ASCII
    • 5 - Apple II
    • 6 - Otrona
    • 7 - EEPROM keymap
  • 4 external triggers with buffers
  • Configurable over serial port
  • On-board voltage regulator

I/O Requirements

  • 8 I/O lines
  • 8 switch selects
  • 1 strobe line
  • 4 JTAG programming
  • 2 serial Rx/Tx
  • 4 keyboard Rx/Tx
  • 4 external trigger inputs

I/O Assignments

  • PA0 - DOUT0
  • PA1 - DOUT1
  • PA2 - DOUT2
  • PA3 - DOUT3
  • PA4 - DOUT4
  • PA5 - DOUT5
  • PA6 - DOUT6
  • PA7 - DOUT7
  • PB0 - SWITCH 0
  • PB1 - SWITCH 1
  • PB2 - SWITCH 2
  • PB3 - SWITCH 3
  • PB4 - SWITCH 4
  • PB5 - SWITCH 5
  • PB6 - SWITCH 6
  • PB7 - SWITCH 7
  • PC0 - STROBE
  • PC1 - Reserved
  • PC2 - TCK (JTAG)
  • PC3 - TMS (JTAG)
  • PC4 - TDO (JTAG)
  • PC5 - TDI (JTAG)
  • PC6 - Ext Trigger 0
  • PC7 - Ext Trigger 1
  • PD0 - RXD
  • PD1 - TXD
  • PD2 - KBD Rx Clock
  • PD3 - KBD Rx Data
  • PD4 - KBD Tx Clock
  • PD5 - KBD Tx Data
  • PD6 - Ext Trigger 2
  • PD7 - Ext Trigger 3

Switch Settings

  • 1 - Keymap bit 2
  • 2 - Keymap bit 1
  • 3 - Keymap bit 0
    • 0 - Raw
    • 1 - VT-100
    • 2 - TVI-950
    • 3 - AY5-1015
    • 4 - ASCII
    • 5 - Apple II
    • 6 - Otrona
    • 7 - EEPROM keymap
  • 4 - Interface mode bit 2
  • 5 - Interface mode bit 1
  • 6 - Interface mode bit 0
    • 0 - Parallel, positive data, active low strobe
    • 1 - Parallel, positive data, active high strobe
    • 2 - Parallel, inverted data, active low strobe
    • 3 - Parallel, inverted data, active high strobe
    • 4 - RS-232 serial @ 9600
    • 5 - Otrona serial
    • 6 - Reserved
    • 7 - EEPROM configuration
  • 7 - Reserved
  • 8 - Serial configuration mode @ 9600 baud

Monitor commands

  • HELP - This help list
  • SCAN - Display scan codes from keyboard until ESC typed
  • UKEYMAP - Change EEPROM user keymap byte (details to come)
  • KEYMAP 0..7 - Select keymap to be used when interface switches == 7
  • INTFACE - Interface to be used when interface switches == 7
  • RESET - Reset to factory defaults (asks for confirmation)
  • PF - Program PF key strings
  • STATUS - Displays KEYMAP, INTFACE values, PF key usage
  • CCSWAP [0|1] - Disable/enable swapping left CTRL and CAPSLOCK key
  • VERSION - Display firmware version


The INTFACE command will probably work something like this: INTFACE P+ S-. INTFACE starts by assuming no options are enabled, and then enables options as they are parsed. This would indicate to use positive parallel data and an active low strobe, with no serial options. Using R,19200 would enable the RS-232 serial port at 19200 baud. O would enable the Otrona interface. Interfaces are mutually exclusive, so parallel cannot be used at the same time as the Otrona.
PF might work like this: PF 1 0x44 0x49 0x52 0x0d would program PF1 to send DIR^m. PF keys would support all combinations, so SHIFT+CTRL+F1 sould be PF SC1 [...]. Specifying no content would display the current value programmed. Erasing a PF key entry might be done by specifying a '-' as part of the key modifier, such as 'PF -1' or 'PF SC1-'. Since there are 12 PF keys, and 8 modifiers (Ctrl,Shift,Alt. Left vs. right shift, etc, are ignored), this gives 96 PF key combinations. Rather than fixing the size each PF key can send, space would be allocated from whatever EEPROM is left over after the keymap is implemented, which would likely be 90 bytes or so.
UKEYMAP might work like this: UKEYMAP S 0x1C 0x42 This would say that for the shifted keypress of the 'A' key on the keyboard, the letter 'B' would be sent. Initially, there would be the unshifted table and the shifted table. Control falls out pretty naturally, applying the control character to the unshifted or shifted key (Ctrl-| vs Ctrl-\). ALT keys are a little undefined at the moment. Perhaps that would set the high bit on the shifted, unshifted, or control character going out. Since the translation map is 1:1 (i.e., we won't be sending multiple characters out for ALT-A, we're sort of limited. There are only 512 bytes of EEPROM, and we need a few for configuration data. In theory, we could get 4 keymaps, since there are a maximum of 104 keys (that I know about). This is 416 complete entries, although it may be possible to pare this down a little, and get 5 maps in.
The mappings are based entirely on scancodes, and as such, key numbers are irrelevant to this system. Since certain scancodes map to the same keys across all systems, certain scan codes are protected, and cannot be mapped. These are primarily the LSHIFT, RSHIFT, LCTRL, RCTRL, LALT, RALT, CAPSLOCK, NUMLOCK, and SCROLLOCK keys. Everything else is available for remapping. All basic ASCII values are generated by scan codes under 0x60. As such, scan codes below <= 0x5f are limited to a one character remap. Scan code 0x1c (the 'A' key) can be remapped to 'Z', but not 'DIR'. Scan codes for the PF keys are excepted from this list, see below.
Scan codes 0x60 to 0x7f can be mapped to up to 4 bytes of output. This means that scan code 0x63 (up arrow) could be mapped to send [A, which is what a VT-100 sends when up-arrow is pressed (when "cursor key mode is reset", whatever that exactly means). The numeric keypad is affected by the NUMLOCK status. If NUMLOCK is active, the scancodes will be remapped corresponding numeric and decimal point scan codes. When NUMLOCK is inactive, they are considered to be different keys than the corresponding up arrows, page up/down, etc, and may be assigned their own unique remappings. ALT, CTRL, and SHIFTs are not applied to these scan codes >= 0x60 (this isn't emacs...)
At this point, our memory allocation looks like this:
  • 16 bytes - system configuration information
  • 96 bytes - unshifted remap
  • 96 bytes - shifted remap
  • 128 bytes - scan codes >= 0x60 (32 scan codes * 4 bytes)
  • 176 bytes - available for PF keys (688 with an ATMega32)

Resources

Keyboard Stuff

Key Positions and Their Scan Codes
1 0x0e `~ 23 0x3c U 45 N/A N/A 67 N/A  ! 89 0xe0,0x74 RIGHT 111 N/A N/A
2 0x16 1! 24 0x43 I 46 0x1a Z 68 N/A N/A 90 0x77 NUMLOCK 112 0x05 F1
3 0x1e 2@ 25 0x44 O 47 0x22 X 69 N/A N/A 91 0x6c KP-4 113 0x06 F2
4 0x26 3# 26 0x4d P 48 0x21 C 70 N/A N/A 92 0x6b KP-4 114 0x04 F3
5 0x25 4$ 27 0x54 [{ 49 0x2a V 71 N/A N/A 93 0x69 KP-1 115 0x0c F4
6 0x2e 5% 28 0x5b ]} 50 0x32 B 72 N/A N/A 94 N/A N/A 116 0x03 F5
7 0x36 6^ 29 0x5d 51 0x31 N 73 N/A N/A 95 0xe0,0x4a KP-/ 117 0x0b F6
8 0x3d 7& 30 0x58 CAPSL 52 0x3a M 74 N/A N/A 96 0x75 KP-8 118 0x83 F7
9 0x3e 8* 31 0x1c A 53 0x41 ,< 75 0xe0,0x70 INS 97 0x73 KP-5 119 0x0a F8
10 0x46 9( 32 0x1b S 54 0x49 .> 76 0xe0,0x71 DEL 98 0x72 KP-2 120 0x01 F9
11 0x45 0) 33 0x23 D 55 0x4a /? 77 N/A N/A 99 0x70 KP-0 121 0x09 F10
12 0x4e -_ 34 0x2b F 56 N/A N/A 78 N/A N/A 100 0x7c KP-* 122 0x78 F11
13 0x55 =+ 35 0x34 G 57 0x59 RSHIFT 79 0xe0,0x6b LEFT 101 0x7d KP-9 123 0x07 F12
14 0x5d 36 0x33 H 58 0x14 LCTRL 80 0xe0,0x6c HOME 102 0x74 KP-6 124  ! PRTSCR
15 0x66 BS 37 0x3b J 59 N/A N/A 81 0xe0,0x69 END 103 0x7a KP-3 125 0x7e SCRLLK
16 0x0d TAB 38 0x42 K 60 0x11 LALT 82 N/A N/A 104 0x71 KP-. 126  ! PAUSE
17 0x15 Q 39 0x4b L 61 0x29 SPACE 83 0xe0,0x75 UP 105 0x7b KP-- 127 N/A N/A
18 0x1d W 40 0x4c  ;: 62 0xe0,0x11 RALT 84 0xe0,0x72 DOWN 106 0x79 KP-+ 128 N/A N/A
19 0x24 E 41 0x52 '" 63 N/A N/A 85 0xe0,0x7d PGUP 107 N/A N/A 129  ?  ?
20 0x2d R 42 N/A N/A 64 0xe0,0x14 RCTRL 86 0xe0,0x7a PGDN 108 0xe0,0x5a KP-ENTER 130  ?  ?
21 0x2c T 43 0x5a ENTER 65 N/A N/A 87 N/A N/A 109 N/A N/A 131  ?  ?
22 0x35 Y 44 0x12 LSHIFT 66 N/A N/A 88 N/A N/A 110 0x76 ESC 132  ?  ?
133 0x30  !


Scan Codes and their ASCII values
Scan Code ASCII Value
 ? PAUSE
 ? PRTSCR
0x01 F9
0x03 F5
0x04 F3
0x05 F1
0x06 F2
0x07 F12
0x09 F10
0x0a F8
0x0b F6
0x0c F4
0x0d TAB
0x0e `~
0x11 LALT
0x12 LSHIFT
0x14 LCTRL
0x15 Q
0x16 1!
0x1a Z
0x1b S
0x1c A
0x1d W
0x1e 2@
0x21 C
0x22 X
0x23 D
0x24 E
0x25 4$
0x26 3#
0x29 SPACE
0x2a V
0x2b F
0x2c T
0x2d R
0x2e 5%
0x31 N
0x32 B
0x33 H
0x34 G
0x35 Y
0x36 6^
0x3a M
0x3b J
0x3c U
0x3d 7&
0x3e 8*
0x41 ,<
0x42 K
0x43 I
0x44 O
0x45 0)
0x46 9(
0x49 .>
0x4a /?
0x4b L
0x4c  ;:
0x4d P
0x4e -_
0x52 '"
0x54 [{
0x55 =+
0x58 CAPSL
0x59 RSHIFT
0x5a ENTER
0x5b ]}
0x5d
0x66 BS
0x69 KP-1
0x6b KP-4
0x6c KP-7
0x70 KP-0
0x71 KP-.
0x72 KP-2
0x73 KP-5
0x74 KP-6
0x75 KP-8
0x76 ESC
0x77 NUMLOCK
0x78 F11
0x79 KP-+
0x7a KP-3
0x7b KP--
0x7c KP-*
0x7d KP-9
0x7e SCRLLK
0x83 F7
0xe0,0x11 RALT
0xe0,0x14 RCTRL
0xe0,0x4a KP-/
0xe0,0x5a KP-ENTER
0xe0,0x69 END
0xe0,0x6b LEFT
0xe0,0x6c HOME
0xe0,0x70 INS
0xe0,0x71 DEL
0xe0,0x72 DOWN
0xe0,0x74 RIGHT
0xe0,0x75 UP
0xe0,0x7a PGDN
0xe0,0x7d PGUP


,-------,---,---,---,---,,---,---,---,---,,---,---,---,---,
|ESC    |F1 |F2 |F3 |F4 ||F5 |F6 |F7 |F8 ||F9 |F10|F11|F12|
|110    |112|113|114|115||116|117|118|119||120|121|122|123|
'-------'---'---'---'---''---'---'---'---''---'---'---'---'
,---,---,---,---,---,---,---,---,---,---,---,---,---,-----,
|~  |1  |2  |3  |4  |5  |6  |7  |8  |9  |0  |-  |=  |<-   |
|1  |2  |3  |4  |5  |6  |7  |8  |9  |10 |11 |12 |13 |15   |
|---',--',--',--',--',--',--',--',--',--',--',--',--',----|
|TAB |Q  |W  |E  |R  |T  |Y  |U  |I  |O  |P  |[  |]  |\   |
|16  |17 |18 |19 |20 |21 |22 |23 |24 |25 |26 |27 |28 |29  |
|----',--',--',--',--',--',--',--',--',--',--',--',--'----|
|CAPS |A  |S  |D  |F  |G  |H  |J  |K  |L  |;  |,  |ENTER  |
|30   |31 |32 |33 |34 |35 |36 |37 |38 |39 |40 |41 |43     |
|-----',--',--',--',--',--',--',--',--',--',--',----------|
|SHIFT |Z  |X  |C  |V  |B  |N  |M  |,  |.  |/  |SHIFT     |
|44    |46 |47 |48 |49 |50 |51 |52 |53 |54 |55 |57        |
|----,-',--'--,'---'---'---'---'---'---'--,'--,'-----,----|
|CTRL|  |ALT  |          SPACE            |ALT|      |CTRL|
|58  |  |60   |          61               |62 |      |64  |
'----'--'-----'---------------------------'---'------'----'

,-----,-----,-----,
|PSCRN|SLOCK|BREAK|
|124  |125  |126  |
'-----'-----'-----'
,-----,-----,-----,  ,-----,-----,-----,-----,
|INS  |HOME |PGUP |  |NLOCK|/    |*    |-    |
|75   |80   |85   |  |90   |95   |100  |105  |
|-----|-----|-----|  |-----|-----|-----|-----|
|DEL  |END  |PGDN |  |7    |8    |9    |+    |
|76   |81   |86   |  |91   |96   |101  |106  |
'-----'-----'-----'  |-----|-----|-----|-----|
                     |4    |5    |6    |     |
                     |92   |97   |102  |     |
      ,-----,        |-----|-----|-----|-----|
      |UP   |        |1    |2    |3    |ENTER|
      |83   |        |93   |98   |103  |108  |
,-----|-----|-----,  |-----------|-----|     |
|LEFT |DOWN |RIGHT|  |0          |.    |     |
|79   |84   |89   |  |99         |104  |     |
'-----'-----'-----'  '-----------'-----'-----'
There are at least three options for the mapping of key numberss to keycodes. The common usage seems to be as follows:


,---,-----, ,---,-----, ,---,-----, ,---,-----,
|KEY|AT   | |KEY|AT   | |KEY|AT   | |KEY|AT   |
|#  |(HEX)| |#  |(HEX)| |#  |(HEX)| |#  |(HEX)|
|---|-----| |---|-----| |---|-----| |---|-----|
|1  |0E   | |2  |16   | |3  |1E   | |4  |26   |
|5  |26   | |6  |25   | |7  |2E   | |8  |36   |
|9  |3D   | |10 |46   | |11 |45   | |12 |4E   |
|13 |55   | |14 |--   | |15 |66   | |16 |0D   |
|17 |15   | |18 |1D   | |19 |24   | |20 |2D   |
|21 |2C   | |22 |35   | |23 |3C   | |24 |43   |
|25 |44   | |26 |4D   | |27 |54   | |28 |5B   |
|29 |5D   | |30 |58   | |31 |1C   | |32 |1B   |
|33 |23   | |34 |2B   | |35 |34   | |36 |33   |
|37 |3B   | |38 |42   | |39 |4B   | |40 |4C   |
|41 |52   | |42 |--   | |43 |5A   | |44 |12   |
|45 |--   | |46 |1A   | |47 |22   | |48 |21   |
|49 |2A   | |50 |32   | |51 |31   | |52 |3A   |
|53 |41   | |54 |49   | |55 |4A   | |56 |--   |
|57 |59   | |58 |14   | |59 |--   | |60 |11   |
|61 |29   | |62 |E011 | |63 |--   | |64 |E014 |
|65 |--   | |66 |--   | |67 |--   | |68 |--   |
|69 |--   | |70 |--   | |71 |--   | |72 |--   |
|73 |--   | |74 |--   | |75 |E070 | |76 |E071 |
|77 |--   | |78 |--   | |79 |E06B | |80 |E06C |
|81 |E069 | |82 |--   | |83 |E075 | |84 |E072 |
|85 |E07D | |86 |E07A | |87 |--   | |88 |--   |
|89 |E074 | |90 |77   | |91 |6C   | |92 |6B   |
|93 |69   | |94 |--   | |95 |E04A | |96 |75   |
|97 |73   | |98 |72   | |99 |70   | |100|7C   |
|101|7D   | |102|74   | |103|7A   | |104|71   |
|105|7B   | |106|79   | |107|--   | |108|E05A |
|109|--   | |110|76   | |111|--   | |112|05   |
|113|06   | |114|04   | |115|0C   | |116|03   |
|117|0B   | |118|83   | |119|0A   | |120|01   |
|121|09   | |122|78   | |123|07   | |124|*2   |
|125|7E   | |126|*4   | |127|--   | |128|--   |
'---'-----' '---'-----' '---'-----' '---'-----'

*1 is E02AE037
*2 is E012E07C
*3 is E11D45E19DC5
*4 is E11477E1F014F077

Bugs In 2007/02/07 Board

  • 2x5 connector for serial port is miswired (PCB)
  • Keyboard connector is mirrored (PCB)
  • Base and collector reversed on Q1, Q2, Q3, Q4 (PCB)
  • PS2DAT should be on PD6, PS2CLK should be on PD2 (SCH)
  • EXT net has two net names (SCH)