diff options
| author | Ignaz Kevenaar <ignazkevenaar@gmail.com> | 2021-06-18 17:08:22 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-06-19 01:08:22 +1000 |
| commit | 0311c8036d693baf63ed4d3b7badf4257ffd5f46 (patch) | |
| tree | 90ea79a94aec8b5dcf160a5a323976b6e8dace2e /drivers/oled | |
| parent | 172e6a703041363decd6fc829542f33180c13beb (diff) | |
| download | qmk_firmware-0311c8036d693baf63ed4d3b7badf4257ffd5f46.tar.gz qmk_firmware-0311c8036d693baf63ed4d3b7badf4257ffd5f46.zip | |
Add oled_invert (#13172)
Co-authored-by: Drashna Jaelre <drashna@live.com>
Diffstat (limited to 'drivers/oled')
| -rw-r--r-- | drivers/oled/oled_driver.c | 26 | ||||
| -rw-r--r-- | drivers/oled/oled_driver.h | 4 |
2 files changed, 30 insertions, 0 deletions
diff --git a/drivers/oled/oled_driver.c b/drivers/oled/oled_driver.c index 8e5ed5f07..7d4197890 100644 --- a/drivers/oled/oled_driver.c +++ b/drivers/oled/oled_driver.c | |||
| @@ -34,6 +34,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 34 | #define DISPLAY_ALL_ON 0xA5 | 34 | #define DISPLAY_ALL_ON 0xA5 |
| 35 | #define DISPLAY_ALL_ON_RESUME 0xA4 | 35 | #define DISPLAY_ALL_ON_RESUME 0xA4 |
| 36 | #define NORMAL_DISPLAY 0xA6 | 36 | #define NORMAL_DISPLAY 0xA6 |
| 37 | #define INVERT_DISPLAY 0xA7 | ||
| 37 | #define DISPLAY_ON 0xAF | 38 | #define DISPLAY_ON 0xAF |
| 38 | #define DISPLAY_OFF 0xAE | 39 | #define DISPLAY_OFF 0xAE |
| 39 | #define NOP 0xE3 | 40 | #define NOP 0xE3 |
| @@ -114,6 +115,7 @@ OLED_BLOCK_TYPE oled_dirty = 0; | |||
| 114 | bool oled_initialized = false; | 115 | bool oled_initialized = false; |
| 115 | bool oled_active = false; | 116 | bool oled_active = false; |
| 116 | bool oled_scrolling = false; | 117 | bool oled_scrolling = false; |
| 118 | bool oled_inverted = false; | ||
| 117 | uint8_t oled_brightness = OLED_BRIGHTNESS; | 119 | uint8_t oled_brightness = OLED_BRIGHTNESS; |
| 118 | oled_rotation_t oled_rotation = 0; | 120 | oled_rotation_t oled_rotation = 0; |
| 119 | uint8_t oled_rotation_width = 0; | 121 | uint8_t oled_rotation_width = 0; |
| @@ -690,6 +692,30 @@ bool oled_scroll_off(void) { | |||
| 690 | return !oled_scrolling; | 692 | return !oled_scrolling; |
| 691 | } | 693 | } |
| 692 | 694 | ||
| 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 | |||
| 693 | uint8_t oled_max_chars(void) { | 719 | uint8_t oled_max_chars(void) { |
| 694 | if (!HAS_FLAGS(oled_rotation, OLED_ROTATION_90)) { | 720 | if (!HAS_FLAGS(oled_rotation, OLED_ROTATION_90)) { |
| 695 | return OLED_DISPLAY_WIDTH / OLED_FONT_WIDTH; | 721 | return OLED_DISPLAY_WIDTH / OLED_FONT_WIDTH; |
diff --git a/drivers/oled/oled_driver.h b/drivers/oled/oled_driver.h index a6b85f37e..fc68f0ec9 100644 --- a/drivers/oled/oled_driver.h +++ b/drivers/oled/oled_driver.h | |||
| @@ -313,6 +313,10 @@ bool oled_scroll_left(void); | |||
| 313 | // Returns true if the screen was not scrolling or stops scrolling | 313 | // Returns true if the screen was not scrolling or stops scrolling |
| 314 | bool oled_scroll_off(void); | 314 | bool oled_scroll_off(void); |
| 315 | 315 | ||
| 316 | // Inverts the display | ||
| 317 | // Returns true if the screen was or is inverted | ||
| 318 | bool oled_invert(bool invert); | ||
| 319 | |||
| 316 | // Returns the maximum number of characters that will fit on a line | 320 | // Returns the maximum number of characters that will fit on a line |
| 317 | uint8_t oled_max_chars(void); | 321 | uint8_t oled_max_chars(void); |
| 318 | 322 | ||
