-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvt100_kbd.h
110 lines (94 loc) · 3.14 KB
/
vt100_kbd.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
* VT100 to USB Converter.
*
* ------------------------------------------------------------------------
*
* The MIT License (MIT)
*
* Copyright (c) 2013 Seth Morabito.
*
* 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 __VT100_KBD_H
#define __VT100_KBD_H
#define CPU_PRESCALE(n) (CLKPR = 0x80, CLKPR = (n))
#define KBD_RD_L (1<<6)
#define KBD_WR_L (1<<7)
#define KBD_RESET_H (1<<4)
#define KBD_TBMT_H (1<<6)
#define START_SCAN (1<<6)
#define MODIFIER_ALT 0x31 // PF3
#define MODIFIER_GUI 0x41 // PF4
#define MODIFIER_SETUP 0x7b
#define MODIFIER_CTRL 0x7c
#define MODIFIER_SHIFT 0x7d
#define MODIFIER_CAPSLOCK 0x7e
#define END_OF_SCAN 0x7f
// Keyboard Status bits.
#define BELL_BIT 0x01
#define KEYCLICK_BIT 0x02
#define SETUP_BIT 0x04
#define SPEAKER_LED_BIT 0x08
#define CAPSLOCK_BIT 0x10
#define SPEAKER_BIT 0x80
#define CLOCK_PERIOD 8 /* microseconds */
/*
* Number of status updates between requests for keyboard scans.
*/
#define UPDATES_BETWEEN_SCANS 16
/*
* Number of trips through the status loop to take before deciding
* that a 0x7f "scan done" isn't going to appear. 16 is extremely
* generous, it really should never be > 4.
*/
#define SCAN_DONE_TIMEOUT 16
#define KEY_BUFFER_SIZE 3
#define LONG_REPEAT_TIMEOUT 400
#define SHORT_REPEAT_TIMEOUT 30
#define TRUE 1
#define FALSE 0
/*
* Typedefs
*/
struct key_struct {
unsigned int address : 7;
unsigned int sent : 1;
};
typedef struct key_struct key;
typedef unsigned int bool_t;
/*
* Function definitions
*/
static uint8_t kbd_read(void);
static void kbd_write(uint8_t val);
static inline void io_setup(void);
static inline void uart_reset(void);
static inline void update_modifier_state(void);
static inline void possibly_transmit_keys(void);
static inline void handle_setup(uint8_t, uint8_t);
static inline void clear_buf(key *, size_t);
static inline void copy_buf(key *, key *, size_t);
static inline void eeprom_init(void);
static inline void toggle_bell_state(void);
static inline void toggle_keyclick_state(void);
#endif