-
Notifications
You must be signed in to change notification settings - Fork 37
/
controller.go
99 lines (76 loc) · 2.41 KB
/
controller.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
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
// Copyright 2021 The Periph Authors. All rights reserved.
// Use of this source code is governed under the Apache License, Version 2.0
// that can be found in the LICENSE file.
package waveshare2in13v2
type controller interface {
sendCommand(byte)
sendData([]byte)
waitUntilIdle()
}
func initDisplay(ctrl controller, opts *Opts) {
ctrl.waitUntilIdle()
ctrl.sendCommand(swReset)
ctrl.waitUntilIdle()
ctrl.sendCommand(setAnalogBlockControl)
ctrl.sendData([]byte{0x54})
ctrl.sendCommand(setDigitalBlockControl)
ctrl.sendData([]byte{0x3B})
ctrl.sendCommand(driverOutputControl)
ctrl.sendData([]byte{
byte((opts.Height - 1) % 0xFF),
byte((opts.Height - 1) / 0xFF),
0x00,
})
ctrl.sendCommand(gateDrivingVoltageControl)
ctrl.sendData([]byte{gateDrivingVoltage19V})
ctrl.sendCommand(sourceDrivingVoltageControl)
ctrl.sendData([]byte{sourceDrivingVoltageVSH1_15V, sourceDrivingVoltageVSH2_5V, sourceDrivingVoltageVSL_neg15V})
ctrl.sendCommand(setDummyLinePeriod)
ctrl.sendData([]byte{0x30})
ctrl.sendCommand(setGateTime)
ctrl.sendData([]byte{0x0A})
}
func configDisplayMode(ctrl controller, mode PartialUpdate, lut LUT) {
var vcom byte
var borderWaveformControlValue byte
switch mode {
case Full:
vcom = 0x55
borderWaveformControlValue = 0x03
case Partial:
vcom = 0x24
borderWaveformControlValue = 0x01
}
ctrl.sendCommand(writeVcomRegister)
ctrl.sendData([]byte{vcom})
ctrl.sendCommand(borderWaveformControl)
ctrl.sendData([]byte{borderWaveformControlValue})
ctrl.sendCommand(writeLutRegister)
ctrl.sendData(lut[:70])
ctrl.sendCommand(writeDisplayOptionRegister)
ctrl.sendData([]byte{0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00})
// Start up the parts likely used by a draw operation soon.
ctrl.sendCommand(displayUpdateControl2)
ctrl.sendData([]byte{displayUpdateEnableClock | displayUpdateEnableAnalog})
ctrl.sendCommand(masterActivation)
ctrl.waitUntilIdle()
}
func updateDisplay(ctrl controller, mode PartialUpdate) {
var displayUpdateFlags byte
if mode == Partial {
// Make use of red buffer
displayUpdateFlags = 0b1000_0000
}
ctrl.sendCommand(displayUpdateControl1)
ctrl.sendData([]byte{displayUpdateFlags})
ctrl.sendCommand(displayUpdateControl2)
ctrl.sendData([]byte{
displayUpdateDisableClock |
displayUpdateDisableAnalog |
displayUpdateDisplay |
displayUpdateEnableClock |
displayUpdateEnableAnalog,
})
ctrl.sendCommand(masterActivation)
ctrl.waitUntilIdle()
}