Skip to content

Commit 1444f94

Browse files
authored
Merge pull request Ralim#1464 from Ralim/only-send-screen-on-change
Only send on display change
2 parents f11f550 + 80e7ab3 commit 1444f94

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

source/Core/Drivers/OLED.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ bool OLED::initDone = false;
2525
uint8_t OLED::displayOffset;
2626
uint8_t OLED::screenBuffer[16 + (OLED_WIDTH * 2) + 10]; // The data buffer
2727
uint8_t OLED::secondFrameBuffer[OLED_WIDTH * 2];
28-
28+
uint32_t OLED::displayChecksum;
2929
/*Setup params for the OLED screen*/
3030
/*http://www.displayfuture.com/Display/datasheet/controller/SSD1307.pdf*/
3131
/*All commands are prefixed with 0x80*/
@@ -222,7 +222,7 @@ void OLED::maskScrollIndicatorOnOLED() {
222222
// it from the screen buffer which is updated by `OLED::setRotation`.
223223
uint8_t rightmostColumn = screenBuffer[7];
224224
uint8_t maskCommands[] = {
225-
// Set column address:
225+
// Set column address:
226226
// A[6:0] - Column start address = rightmost column
227227
// B[6:0] - Column end address = rightmost column
228228
0x80,

source/Core/Drivers/OLED.hpp

+22-6
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@
1010
#ifndef OLED_HPP_
1111
#define OLED_HPP_
1212
#include "Font.h"
13+
#include "cmsis_os.h"
1314
#include "configuration.h"
1415
#include <BSP.h>
1516
#include <stdbool.h>
1617
#include <string.h>
18+
1719
#ifdef __cplusplus
1820
extern "C" {
1921
#endif
@@ -47,16 +49,29 @@ class OLED {
4749

4850
static void initialize(); // Startup the I2C coms (brings screen out of reset etc)
4951
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.
5153
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+
}
5565
}
5666

5767
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+
}
6075
}
6176

6277
static void setRotation(bool leftHanded); // Set the rotation for the screen
@@ -112,6 +127,7 @@ class OLED {
112127
static DisplayState displayState;
113128
static int16_t cursor_x, cursor_y;
114129
static uint8_t displayOffset;
130+
static uint32_t displayChecksum;
115131
static uint8_t screenBuffer[16 + (OLED_WIDTH * 2) + 10]; // The data buffer
116132
static uint8_t secondFrameBuffer[OLED_WIDTH * 2];
117133
};

0 commit comments

Comments
 (0)