Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow force flush of oled display. #20953

Merged
merged 10 commits into from
Sep 14, 2023
68 changes: 56 additions & 12 deletions docs/feature_oled_driver.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,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 @@ -275,15 +311,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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recopied the relevant chunk of the .h file. That's where the other changes came from.

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 @@ -301,20 +337,24 @@ 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
void oled_set_cursor(uint8_t col, uint8_t line);

// Advances the cursor to the next page, writing ' ' if true
// Wraps to the beginning when out of bounds
// Wraps to the begining when out of bounds
arlaneenalra marked this conversation as resolved.
Show resolved Hide resolved
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 beginning when out of bounds
// Wraps to the begining when out of bounds
arlaneenalra marked this conversation as resolved.
Show resolved Hide resolved
void oled_advance_char(void);

// Writes a single character to the buffer at current cursor position
Expand All @@ -333,8 +373,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 @@ -351,6 +389,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 @@ -364,6 +403,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 All @@ -377,10 +421,10 @@ bool oled_off(void);
// not
bool is_oled_on(void);

// Sets the brightness level of the display
// Sets the brightness of the display
arlaneenalra marked this conversation as resolved.
Show resolved Hide resolved
uint8_t oled_set_brightness(uint8_t level);

// Gets the current brightness level of the display
// Gets the current brightness of the display
arlaneenalra marked this conversation as resolved.
Show resolved Hide resolved
uint8_t oled_get_brightness(void);

// Basically it's oled_render, but with timeout management and oled_task_user calling!
Expand All @@ -402,12 +446,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);

// Begin scrolling the entire display right
// Scrolls the entire display right
arlaneenalra marked this conversation as resolved.
Show resolved Hide resolved
// Returns true if the screen was scrolling or starts scrolling
// NOTE: display contents cannot be changed while scrolling
bool oled_scroll_right(void);

// Begin scrolling the entire display left
// Scrolls the entire display left
arlaneenalra marked this conversation as resolved.
Show resolved Hide resolved
// 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
4 changes: 2 additions & 2 deletions drivers/oled/oled_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,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 @@ -460,7 +460,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
8 changes: 6 additions & 2 deletions drivers/oled/oled_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,12 @@ 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
Expand Down