Skip to content

Commit d6129c9

Browse files
Add oled_invert (qmk#13172)
Co-authored-by: Drashna Jaelre <[email protected]>
1 parent 61e06c4 commit d6129c9

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

docs/feature_oled_driver.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,10 @@ bool oled_scroll_left(void);
346346
// Returns true if the screen was not scrolling or stops scrolling
347347
bool oled_scroll_off(void);
348348

349+
// Inverts the display
350+
// Returns true if the screen was or is inverted
351+
bool oled_invert(bool invert);
352+
349353
// Returns the maximum number of characters that will fit on a line
350354
uint8_t oled_max_chars(void);
351355

drivers/oled/oled_driver.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
3434
#define DISPLAY_ALL_ON 0xA5
3535
#define DISPLAY_ALL_ON_RESUME 0xA4
3636
#define NORMAL_DISPLAY 0xA6
37+
#define INVERT_DISPLAY 0xA7
3738
#define DISPLAY_ON 0xAF
3839
#define DISPLAY_OFF 0xAE
3940
#define NOP 0xE3
@@ -114,6 +115,7 @@ OLED_BLOCK_TYPE oled_dirty = 0;
114115
bool oled_initialized = false;
115116
bool oled_active = false;
116117
bool oled_scrolling = false;
118+
bool oled_inverted = false;
117119
uint8_t oled_brightness = OLED_BRIGHTNESS;
118120
oled_rotation_t oled_rotation = 0;
119121
uint8_t oled_rotation_width = 0;
@@ -690,6 +692,30 @@ bool oled_scroll_off(void) {
690692
return !oled_scrolling;
691693
}
692694

695+
bool oled_invert(bool invert) {
696+
if (!oled_initialized) {
697+
return oled_inverted;
698+
}
699+
700+
if (invert && !oled_inverted) {
701+
static const uint8_t PROGMEM display_inverted[] = {I2C_CMD, INVERT_DISPLAY};
702+
if (I2C_TRANSMIT_P(display_inverted) != I2C_STATUS_SUCCESS) {
703+
print("oled_invert cmd failed\n");
704+
return oled_inverted;
705+
}
706+
oled_inverted = true;
707+
} else if (!invert && oled_inverted) {
708+
static const uint8_t PROGMEM display_normal[] = {I2C_CMD, NORMAL_DISPLAY};
709+
if (I2C_TRANSMIT_P(display_normal) != I2C_STATUS_SUCCESS) {
710+
print("oled_invert cmd failed\n");
711+
return oled_inverted;
712+
}
713+
oled_inverted = false;
714+
}
715+
716+
return oled_inverted;
717+
}
718+
693719
uint8_t oled_max_chars(void) {
694720
if (!HAS_FLAGS(oled_rotation, OLED_ROTATION_90)) {
695721
return OLED_DISPLAY_WIDTH / OLED_FONT_WIDTH;

drivers/oled/oled_driver.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,10 @@ bool oled_scroll_left(void);
313313
// Returns true if the screen was not scrolling or stops scrolling
314314
bool oled_scroll_off(void);
315315

316+
// Inverts the display
317+
// Returns true if the screen was or is inverted
318+
bool oled_invert(bool invert);
319+
316320
// Returns the maximum number of characters that will fit on a line
317321
uint8_t oled_max_chars(void);
318322

0 commit comments

Comments
 (0)