-
Notifications
You must be signed in to change notification settings - Fork 9
/
keyboard.go
66 lines (52 loc) · 1.08 KB
/
keyboard.go
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
package main
type Keystate struct {
Keycode uint8
}
// -------------------
// Keyboard Ringbuffer
// -------------------
type KeyboardRing struct {
Ring GenericRing
Buffer [32]Keystate
}
func (r *KeyboardRing) Init() {
r.Ring.Cap = r.Cap()
}
func (r *KeyboardRing) Len() int {
return r.Ring.Len()
}
func (r *KeyboardRing) Cap() int {
return len(r.Buffer)
}
func (r *KeyboardRing) Push(s Keystate) {
// Not thread safe
if i := r.Ring.Push(); i != -1 {
r.Buffer[i] = s
}
}
func (r *KeyboardRing) Pop() *Keystate {
// Not thread safe
if i := r.Ring.Pop(); i != -1 {
return &r.Buffer[i]
}
return nil
}
// End keyboard ring buffer
const (
keyboardInputPort = 0x60
)
var buffer KeyboardRing = KeyboardRing{
Ring: GenericRing{}, // Important to prevent initialization at runtime
}
var tempKeystate Keystate = Keystate{}
//go:nospilt
func handleKeyboard() {
keycode := Inb(keyboardInputPort) // TODO: constant Where to get this?
tempKeystate.Keycode = keycode
buffer.Push(tempKeystate)
}
func InitKeyboard() {
RegisterPICHandler(1, handleKeyboard)
EnableIRQ(1)
buffer.Init()
}