|
10 | 10 | #ifndef OLED_HPP_
|
11 | 11 | #define OLED_HPP_
|
12 | 12 | #include "Font.h"
|
| 13 | +#include "cmsis_os.h" |
13 | 14 | #include "configuration.h"
|
14 | 15 | #include <BSP.h>
|
15 | 16 | #include <stdbool.h>
|
16 | 17 | #include <string.h>
|
| 18 | + |
17 | 19 | #ifdef __cplusplus
|
18 | 20 | extern "C" {
|
19 | 21 | #endif
|
@@ -47,16 +49,29 @@ class OLED {
|
47 | 49 |
|
48 | 50 | static void initialize(); // Startup the I2C coms (brings screen out of reset etc)
|
49 | 51 | static bool isInitDone();
|
50 |
| - // Draw the buffer out to the LCD using the DMA Channel |
| 52 | + // Draw the buffer out to the LCD if any content has changed. |
51 | 53 | static void refresh() {
|
52 |
| - I2C_CLASS::Transmit(DEVICEADDR_OLED, screenBuffer, FRAMEBUFFER_START + (OLED_WIDTH * 2)); |
53 |
| - // DMA tx time is ~ 20mS Ensure after calling this you delay for at least 25ms |
54 |
| - // or we need to goto double buffering |
| 54 | + uint32_t hash = 0; |
| 55 | + const int len = FRAMEBUFFER_START + (OLED_WIDTH * 2); |
| 56 | + for (int i = 0; i < len; i++) { |
| 57 | + hash += (i * screenBuffer[i]); |
| 58 | + } |
| 59 | + if (hash != displayChecksum) { |
| 60 | + displayChecksum = hash; |
| 61 | + I2C_CLASS::Transmit(DEVICEADDR_OLED, screenBuffer, len); |
| 62 | + // DMA tx time is ~ 20mS Ensure after calling this you delay for at least 25ms |
| 63 | + // or we need to goto double buffering |
| 64 | + } |
55 | 65 | }
|
56 | 66 |
|
57 | 67 | static void setDisplayState(DisplayState state) {
|
58 |
| - displayState = state; |
59 |
| - screenBuffer[1] = (state == ON) ? 0xAF : 0xAE; |
| 68 | + if (state != displayState) { |
| 69 | + displayState = state; |
| 70 | + screenBuffer[1] = (state == ON) ? 0xAF : 0xAE; |
| 71 | + // Dump the screen state change out _now_ |
| 72 | + I2C_CLASS::Transmit(DEVICEADDR_OLED, screenBuffer, FRAMEBUFFER_START - 1); |
| 73 | + osDelay(TICKS_10MS); |
| 74 | + } |
60 | 75 | }
|
61 | 76 |
|
62 | 77 | static void setRotation(bool leftHanded); // Set the rotation for the screen
|
@@ -112,6 +127,7 @@ class OLED {
|
112 | 127 | static DisplayState displayState;
|
113 | 128 | static int16_t cursor_x, cursor_y;
|
114 | 129 | static uint8_t displayOffset;
|
| 130 | + static uint32_t displayChecksum; |
115 | 131 | static uint8_t screenBuffer[16 + (OLED_WIDTH * 2) + 10]; // The data buffer
|
116 | 132 | static uint8_t secondFrameBuffer[OLED_WIDTH * 2];
|
117 | 133 | };
|
|
0 commit comments