3
3
#include < libraries/delay/nrf_delay.h>
4
4
#include < nrfx_log.h>
5
5
#include " drivers/Spi.h"
6
+ #include " drivers/PinMap.h"
6
7
7
8
using namespace Pinetime ::Drivers;
8
9
9
- St7789::St7789 (Spi& spi, uint8_t pinDataCommand, uint8_t pinReset ) : spi {spi}, pinDataCommand {pinDataCommand}, pinReset {pinReset } {
10
+ St7789::St7789 (Spi& spi) : spi {spi} {
10
11
}
11
12
12
13
void St7789::Init () {
13
- nrf_gpio_cfg_output (pinDataCommand );
14
- nrf_gpio_cfg_output (pinReset );
15
- nrf_gpio_pin_set (pinReset );
14
+ nrf_gpio_cfg_output (PinMap::LcdDataCommand );
15
+ nrf_gpio_cfg_output (PinMap::LcdReset );
16
+ nrf_gpio_pin_set (PinMap::LcdReset );
16
17
HardwareReset ();
17
18
SoftwareReset ();
18
19
SleepOut ();
@@ -29,18 +30,28 @@ void St7789::Init() {
29
30
DisplayOn ();
30
31
}
31
32
33
+ void St7789::EnableDataMode (bool isStart) {
34
+ if (isStart) {
35
+ nrf_gpio_pin_set (PinMap::LcdDataCommand);
36
+ }
37
+ }
38
+
39
+ void St7789::EnableCommandMode (bool isStart) {
40
+ if (isStart) {
41
+ nrf_gpio_pin_clear (PinMap::LcdDataCommand);
42
+ }
43
+ }
44
+
32
45
void St7789::WriteCommand (uint8_t cmd) {
33
- nrf_gpio_pin_clear (pinDataCommand);
34
- WriteSpi (&cmd, 1 );
46
+ WriteSpi (&cmd, 1 , EnableCommandMode);
35
47
}
36
48
37
49
void St7789::WriteData (uint8_t data) {
38
- nrf_gpio_pin_set (pinDataCommand);
39
- WriteSpi (&data, 1 );
50
+ WriteSpi (&data, 1 , EnableDataMode);
40
51
}
41
52
42
- void St7789::WriteSpi (const uint8_t * data, size_t size) {
43
- spi.Write (data, size);
53
+ void St7789::WriteSpi (const uint8_t * data, size_t size, void (*TransactionHook)( bool ) ) {
54
+ spi.Write (data, size, TransactionHook );
44
55
}
45
56
46
57
void St7789::SoftwareReset () {
@@ -152,24 +163,23 @@ void St7789::Uninit() {
152
163
153
164
void St7789::DrawBuffer (uint16_t x, uint16_t y, uint16_t width, uint16_t height, const uint8_t * data, size_t size) {
154
165
SetAddrWindow (x, y, x + width - 1 , y + height - 1 );
155
- nrf_gpio_pin_set (pinDataCommand);
156
- WriteSpi (data, size);
166
+ WriteSpi (data, size, EnableDataMode);
157
167
}
158
168
159
169
void St7789::HardwareReset () {
160
- nrf_gpio_pin_clear (pinReset );
170
+ nrf_gpio_pin_clear (PinMap::LcdReset );
161
171
nrf_delay_ms (10 );
162
- nrf_gpio_pin_set (pinReset );
172
+ nrf_gpio_pin_set (PinMap::LcdReset );
163
173
}
164
174
165
175
void St7789::Sleep () {
166
176
SleepIn ();
167
- nrf_gpio_cfg_default (pinDataCommand );
177
+ nrf_gpio_cfg_default (PinMap::LcdDataCommand );
168
178
NRF_LOG_INFO (" [LCD] Sleep" );
169
179
}
170
180
171
181
void St7789::Wakeup () {
172
- nrf_gpio_cfg_output (pinDataCommand );
182
+ nrf_gpio_cfg_output (PinMap::LcdDataCommand );
173
183
SleepOut ();
174
184
VerticalScrollStartAddress (verticalScrollingStartAddress);
175
185
DisplayOn ();
0 commit comments