Skip to content

Commit

Permalink
Allow force flush of oled display (qmk#20953)
Browse files Browse the repository at this point in the history
Co-authored-by: Drashna Jaelre <drashna@live.com>
Co-authored-by: Ryan <fauxpark@gmail.com>
  • Loading branch information
3 people authored and Lorenzo Castoldi committed Dec 27, 2023
1 parent 2ea4135 commit 1aeb1a3
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 16 deletions.
56 changes: 50 additions & 6 deletions docs/feature_oled_driver.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,42 @@ bool oled_task_user(void) {
#endif
```

Render a message before booting into bootloader mode.
```c
void oled_render_boot(bool bootloader) {
oled_clear();
for (int i = 0; i < 16; i++) {
oled_set_cursor(0, i);
if (bootloader) {
oled_write_P(PSTR("Awaiting New Firmware "), false);
} else {
oled_write_P(PSTR("Rebooting "), false);
}
}

oled_render_dirty(true);
}

bool reboot = false;

bool uint16_t keycode, keyrecord_t *record) {
if (record->event.pressed) {

// Display a special message prior to rebooting...
if (keycode == QK_BOOT) {
reboot = true;
}
}

return true;
}

void shutdown_user(void) {
oled_render_boot(reboot);
}

```
## Basic Configuration
These configuration options should be placed in `config.h`. Example:
Expand Down Expand Up @@ -276,15 +312,15 @@ Rotation on SH1106 and SH1107 is noticeably less efficient than on SSD1306, beca
## OLED API

```c
// OLED rotation enum values are flags
// OLED Rotation enum values are flags
typedef enum {
OLED_ROTATION_0 = 0,
OLED_ROTATION_90 = 1,
OLED_ROTATION_180 = 2,
OLED_ROTATION_270 = 3, // OLED_ROTATION_90 | OLED_ROTATION_180
} oled_rotation_t;

// Initialize the OLED display, rotating the rendered output based on the define passed in.
// Initialize the oled display, rotating the rendered output based on the define passed in.
// Returns true if the OLED was initialized successfully
bool oled_init(oled_rotation_t rotation);

Expand All @@ -302,8 +338,12 @@ bool oled_send_data(const uint8_t *data, uint16_t size);
// Clears the display buffer, resets cursor position to 0, and sets the buffer to dirty for rendering
void oled_clear(void);

// Renders the dirty chunks of the buffer to OLED display
void oled_render(void);
// Alias to oled_render_dirty to avoid a change in api.
#define oled_render() oled_render_dirty(false)

// Renders all dirty blocks to the display at one time or a subset depending on the value of
// all.
void oled_render_dirty(bool all);

// Moves cursor to character position indicated by column and line, wraps if out of bounds
// Max column denoted by 'oled_max_chars()' and max lines by 'oled_max_lines()' functions
Expand Down Expand Up @@ -334,8 +374,6 @@ 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);

// Returns a pointer to the requested start index in the buffer plus remaining
Expand All @@ -352,6 +390,7 @@ void oled_write_raw_byte(const char data, uint16_t index);
// Coordinates start at top-left and go right and down for positive x and y
void oled_write_pixel(uint8_t x, uint8_t y, bool on);

#if defined(__AVR__)
// 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 @@ -365,6 +404,11 @@ void oled_write_ln_P(const char *data, bool invert);

// Writes a PROGMEM string to the buffer at current cursor position
void oled_write_raw_P(const char *data, uint16_t size);
#else
# define oled_write_P(data, invert) oled_write(data, invert)
# define oled_write_ln_P(data, invert) oled_write_ln(data, invert)
# define oled_write_raw_P(data, size) oled_write_raw(data, size)
#endif // defined(__AVR__)

// Can be used to manually turn on the screen if it is off
// Returns true if the screen was on or turns on
Expand Down
4 changes: 2 additions & 2 deletions drivers/oled/oled_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ static void rotate_90(const uint8_t *src, uint8_t *dest) {
}
}

void oled_render(void) {
void oled_render_dirty(bool all) {
// Do we have work to do?
oled_dirty &= OLED_ALL_BLOCKS_MASK;
if (!oled_dirty || !oled_initialized || oled_scrolling) {
Expand All @@ -463,7 +463,7 @@ void oled_render(void) {

uint8_t update_start = 0;
uint8_t num_processed = 0;
while (oled_dirty && num_processed++ < OLED_UPDATE_PROCESS_LIMIT) { // render all dirty blocks (up to the configured limit)
while (oled_dirty && (num_processed++ < OLED_UPDATE_PROCESS_LIMIT || all)) { // render all dirty blocks (up to the configured limit)
// Find next dirty block
while (!(oled_dirty & ((OLED_BLOCK_TYPE)1 << update_start))) {
++update_start;
Expand Down
20 changes: 12 additions & 8 deletions drivers/oled/oled_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -353,20 +353,24 @@ oled_rotation_t oled_init_user(oled_rotation_t rotation);
// Clears the display buffer, resets cursor position to 0, and sets the buffer to dirty for rendering
void oled_clear(void);

// Renders the dirty chunks of the buffer to oled display
void oled_render(void);
// Alias to oled_render_dirty to avoid a change in api.
#define oled_render() oled_render_dirty(false)

// Renders all dirty blocks to the display at one time or a subset depending on the value of
// all.
void oled_render_dirty(bool all);

// Moves cursor to character position indicated by column and line, wraps if out of bounds
// Max column denoted by 'oled_max_chars()' and max lines by 'oled_max_lines()' functions
void oled_set_cursor(uint8_t col, uint8_t line);

// Advances the cursor to the next page, writing ' ' if true
// Wraps to the begining when out of bounds
// Wraps to the beginning when out of bounds
void oled_advance_page(bool clearPageRemainder);

// Moves the cursor forward 1 character length
// Advance page if there is not enough room for the next character
// Wraps to the begining when out of bounds
// Wraps to the beginning when out of bounds
void oled_advance_char(void);

// Writes a single character to the buffer at current cursor position
Expand Down Expand Up @@ -433,10 +437,10 @@ bool oled_off(void);
// not
bool is_oled_on(void);

// Sets the brightness of the display
// Sets the brightness level of the display
uint8_t oled_set_brightness(uint8_t level);

// Gets the current brightness of the display
// Gets the current brightness level of the display
uint8_t oled_get_brightness(void);

// Basically it's oled_render, but with timeout management and oled_task_user calling!
Expand All @@ -458,12 +462,12 @@ void oled_scroll_set_area(uint8_t start_line, uint8_t end_line);
// 0=2, 1=3, 2=4, 3=5, 4=25, 5=64, 6=128, 7=256
void oled_scroll_set_speed(uint8_t speed);

// Scrolls the entire display right
// Begin scrolling the entire display right
// Returns true if the screen was scrolling or starts scrolling
// NOTE: display contents cannot be changed while scrolling
bool oled_scroll_right(void);

// Scrolls the entire display left
// Begin scrolling the entire display left
// Returns true if the screen was scrolling or starts scrolling
// NOTE: display contents cannot be changed while scrolling
bool oled_scroll_left(void);
Expand Down

0 comments on commit 1aeb1a3

Please sign in to comment.