Skip to content

Commit

Permalink
Buffer based OLED panning, write byte to buffer at arbitrary index (q…
Browse files Browse the repository at this point in the history
…mk#8055)

* Add buffer based single line pan, arbitrary byte write to buffer

* Change dirty mask to inverse of OLED_BLOCK_TYPE for future proofing larger buffer sizes

* Updating docs to include new functions

* Updating to clarify scroll vs pan
  • Loading branch information
brickbots committed Mar 7, 2020
1 parent 57de9e6 commit 833c5ae
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
9 changes: 9 additions & 0 deletions docs/feature_oled_driver.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,12 @@ void oled_write(const char *data, bool invert);
// Advances the cursor to the next page, wiring ' ' to the remainder of the current page
void oled_write_ln(const char *data, bool invert);

// Pans the buffer to the right (or left by passing true) by moving contents of the buffer
// Useful for moving the screen in preparation for new drawing
// oled_scroll_left or oled_scroll_right should be preferred for all cases of moving a static
// image such as a logo or to avoid burn-in as it's much, much less cpu intensive
void oled_pan(bool left);

// Writes a PROGMEM string to the buffer at current cursor position
// Advances the cursor while writing, inverts the pixels if true
// Remapped to call 'void oled_write(const char *data, bool invert);' on ARM
Expand All @@ -235,6 +241,9 @@ void oled_write_ln_P(const char *data, bool invert);
// Writes a string to the buffer at current cursor position
void oled_write_raw(const char *data, uint16_t size);

// Writes a single byte into the buffer at the specified index
void oled_write_raw_byte(const char data, uint16_t index);

// Writes a PROGMEM string to the buffer at current cursor position
void oled_write_raw_P(const char *data, uint16_t size);

Expand Down
25 changes: 25 additions & 0 deletions drivers/oled/oled_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,31 @@ void oled_write_ln(const char *data, bool invert) {
oled_advance_page(true);
}

void oled_pan(bool left) {
uint16_t i = 0;
for (uint16_t y = 0; y < OLED_DISPLAY_HEIGHT/8; y++) {
if(left) {
for (uint16_t x = 0; x < OLED_DISPLAY_WIDTH - 1; x++) {
i = y * OLED_DISPLAY_WIDTH + x;
oled_buffer[i] = oled_buffer[i+1];
}
} else {
for (uint16_t x = OLED_DISPLAY_WIDTH -1; x > 0; x--) {
i = y * OLED_DISPLAY_WIDTH + x;
oled_buffer[i] = oled_buffer[i-1];
}
}
}
oled_dirty = ~((OLED_BLOCK_TYPE)0);
}

void oled_write_raw_byte(const char data, uint16_t index) {
if (index > OLED_MATRIX_SIZE) index = OLED_MATRIX_SIZE;
if (oled_buffer[index] == data) return;
oled_buffer[index] = data;
oled_dirty |= (1 << (index / OLED_BLOCK_SIZE));
}

void oled_write_raw(const char *data, uint16_t size) {
if (size > OLED_MATRIX_SIZE) size = OLED_MATRIX_SIZE;
for (uint16_t i = 0; i < size; i++) {
Expand Down
4 changes: 4 additions & 0 deletions drivers/oled/oled_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,11 @@ void oled_write(const char *data, bool invert);
// Advances the cursor to the next page, wiring ' ' to the remainder of the current page
void oled_write_ln(const char *data, bool invert);

// Pans the buffer to the right (or left by passing true) by moving contents of the buffer
void oled_pan(bool left);

void oled_write_raw(const char *data, uint16_t size);
void oled_write_raw_byte(const char data, uint16_t index);

#if defined(__AVR__)
// Writes a PROGMEM string to the buffer at current cursor position
Expand Down

0 comments on commit 833c5ae

Please sign in to comment.