1
1
#include " drivers/St7789.h"
2
- #include < hal/nrf_gpio.h>
3
- #include < nrfx_log.h>
4
- #include " drivers/Spi.h"
5
2
6
3
using namespace Pinetime ::Drivers;
7
4
@@ -43,22 +40,52 @@ void St7789::WriteSpi(const uint8_t* data, size_t size) {
43
40
}
44
41
45
42
void St7789::SoftwareReset () {
43
+ EnsureSleepOutPostDelay ();
46
44
WriteCommand (static_cast <uint8_t >(Commands::SoftwareReset));
47
- vTaskDelay (pdMS_TO_TICKS (150 ));
45
+ // If sleep in: must wait 120ms before sleep out can sent (see driver datasheet)
46
+ // Unconditionally wait as software reset doesn't need to be performant
47
+ sleepIn = true ;
48
+ lastSleepExit = xTaskGetTickCount ();
49
+ vTaskDelay (pdMS_TO_TICKS (125 ));
48
50
}
49
51
50
52
void St7789::SleepOut () {
53
+ if (!sleepIn) {
54
+ return ;
55
+ }
51
56
WriteCommand (static_cast <uint8_t >(Commands::SleepOut));
57
+ // Wait 5ms for clocks to stabilise
58
+ // pdMS rounds down => 6 used here
59
+ vTaskDelay (pdMS_TO_TICKS (6 ));
60
+ // Cannot send sleep in or software reset for 120ms
61
+ lastSleepExit = xTaskGetTickCount ();
62
+ sleepIn = false ;
63
+ }
64
+
65
+ void St7789::EnsureSleepOutPostDelay () {
66
+ TickType_t delta = xTaskGetTickCount () - lastSleepExit;
67
+ // Due to timer wraparound, there is a chance of delaying when not necessary
68
+ // It is very low (pdMS_TO_TICKS(125)/2^32) and waiting an extra 125ms isn't too bad
69
+ if (delta >= 0 && delta < pdMS_TO_TICKS (125 )) {
70
+ vTaskDelay (pdMS_TO_TICKS (125 ) - delta);
71
+ }
52
72
}
53
73
54
74
void St7789::SleepIn () {
75
+ if (sleepIn) {
76
+ return ;
77
+ }
78
+ EnsureSleepOutPostDelay ();
55
79
WriteCommand (static_cast <uint8_t >(Commands::SleepIn));
80
+ // Wait 5ms for clocks to stabilise
81
+ // pdMS rounds down => 6 used here
82
+ vTaskDelay (pdMS_TO_TICKS (6 ));
83
+ sleepIn = true ;
56
84
}
57
85
58
86
void St7789::ColMod () {
59
87
WriteCommand (static_cast <uint8_t >(Commands::ColMod));
60
88
WriteData (0x55 );
61
- vTaskDelay (pdMS_TO_TICKS (10 ));
62
89
}
63
90
64
91
void St7789::MemoryDataAccessControl () {
@@ -95,12 +122,10 @@ void St7789::RowAddressSet() {
95
122
96
123
void St7789::DisplayInversionOn () {
97
124
WriteCommand (static_cast <uint8_t >(Commands::DisplayInversionOn));
98
- vTaskDelay (pdMS_TO_TICKS (10 ));
99
125
}
100
126
101
127
void St7789::NormalModeOn () {
102
128
WriteCommand (static_cast <uint8_t >(Commands::NormalModeOn));
103
- vTaskDelay (pdMS_TO_TICKS (10 ));
104
129
}
105
130
106
131
void St7789::DisplayOn () {
@@ -136,7 +161,6 @@ void St7789::SetVdv() {
136
161
137
162
void St7789::DisplayOff () {
138
163
WriteCommand (static_cast <uint8_t >(Commands::DisplayOff));
139
- vTaskDelay (pdMS_TO_TICKS (500 ));
140
164
}
141
165
142
166
void St7789::VerticalScrollStartAddress (uint16_t line) {
@@ -157,8 +181,13 @@ void St7789::DrawBuffer(uint16_t x, uint16_t y, uint16_t width, uint16_t height,
157
181
158
182
void St7789::HardwareReset () {
159
183
nrf_gpio_pin_clear (pinReset);
160
- vTaskDelay (pdMS_TO_TICKS (10 ));
184
+ vTaskDelay (pdMS_TO_TICKS (1 ));
161
185
nrf_gpio_pin_set (pinReset);
186
+ // If hardware reset started while sleep out, reset time may be up to 120ms
187
+ // Unconditionally wait as hardware reset doesn't need to be performant
188
+ sleepIn = true ;
189
+ lastSleepExit = xTaskGetTickCount ();
190
+ vTaskDelay (pdMS_TO_TICKS (125 ));
162
191
}
163
192
164
193
void St7789::Sleep () {
0 commit comments