Skip to content

Commit

Permalink
Only send on display change
Browse files Browse the repository at this point in the history
  • Loading branch information
Ralim committed Nov 6, 2022
1 parent f11f550 commit 7eb9f3f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
4 changes: 2 additions & 2 deletions source/Core/Drivers/OLED.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ bool OLED::initDone = false;
uint8_t OLED::displayOffset;
uint8_t OLED::screenBuffer[16 + (OLED_WIDTH * 2) + 10]; // The data buffer
uint8_t OLED::secondFrameBuffer[OLED_WIDTH * 2];

uint32_t OLED::displayChecksum;
/*Setup params for the OLED screen*/
/*http://www.displayfuture.com/Display/datasheet/controller/SSD1307.pdf*/
/*All commands are prefixed with 0x80*/
Expand Down Expand Up @@ -222,7 +222,7 @@ void OLED::maskScrollIndicatorOnOLED() {
// it from the screen buffer which is updated by `OLED::setRotation`.
uint8_t rightmostColumn = screenBuffer[7];
uint8_t maskCommands[] = {
// Set column address:
// Set column address:
// A[6:0] - Column start address = rightmost column
// B[6:0] - Column end address = rightmost column
0x80,
Expand Down
17 changes: 13 additions & 4 deletions source/Core/Drivers/OLED.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,19 @@ class OLED {

static void initialize(); // Startup the I2C coms (brings screen out of reset etc)
static bool isInitDone();
// Draw the buffer out to the LCD using the DMA Channel
// Draw the buffer out to the LCD if any content has changed.
static void refresh() {
I2C_CLASS::Transmit(DEVICEADDR_OLED, screenBuffer, FRAMEBUFFER_START + (OLED_WIDTH * 2));
// DMA tx time is ~ 20mS Ensure after calling this you delay for at least 25ms
// or we need to goto double buffering
uint32_t hash = 0;
const int len = FRAMEBUFFER_START + (OLED_WIDTH * 2);
for (int i = 0; i < len; i++) {
hash += (i * screenBuffer[i]);
}
if (hash != displayChecksum) {
displayChecksum = hash;
I2C_CLASS::Transmit(DEVICEADDR_OLED, screenBuffer, len);
// DMA tx time is ~ 20mS Ensure after calling this you delay for at least 25ms
// or we need to goto double buffering
}
}

static void setDisplayState(DisplayState state) {
Expand Down Expand Up @@ -112,6 +120,7 @@ class OLED {
static DisplayState displayState;
static int16_t cursor_x, cursor_y;
static uint8_t displayOffset;
static uint32_t displayChecksum;
static uint8_t screenBuffer[16 + (OLED_WIDTH * 2) + 10]; // The data buffer
static uint8_t secondFrameBuffer[OLED_WIDTH * 2];
};
Expand Down

0 comments on commit 7eb9f3f

Please sign in to comment.