diff options
author | XScorpion2 <rcalt2vt@gmail.com> | 2020-12-05 19:53:47 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-06 12:53:47 +1100 |
commit | cba76092ebab65b1b6ec964b2723b795dc6c0b08 (patch) | |
tree | 6ab451e314f0c782fca37d8ded44ce196258cbf3 | |
parent | 5cf70f3993ceecf24dc46c6791552f268d82ae91 (diff) | |
download | qmk_firmware-cba76092ebab65b1b6ec964b2723b795dc6c0b08.tar.gz qmk_firmware-cba76092ebab65b1b6ec964b2723b795dc6c0b08.zip |
Added OLED Initialized checks (#11129)
-rw-r--r-- | drivers/oled/oled_driver.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/drivers/oled/oled_driver.c b/drivers/oled/oled_driver.c index 53bb8ca3f..92c64399e 100644 --- a/drivers/oled/oled_driver.c +++ b/drivers/oled/oled_driver.c | |||
@@ -271,6 +271,10 @@ static void rotate_90(const uint8_t *src, uint8_t *dest) { | |||
271 | } | 271 | } |
272 | 272 | ||
273 | void oled_render(void) { | 273 | void oled_render(void) { |
274 | if (!oled_initialized) { | ||
275 | return; | ||
276 | } | ||
277 | |||
274 | // Do we have work to do? | 278 | // Do we have work to do? |
275 | oled_dirty &= OLED_ALL_BLOCKS_MASK; | 279 | oled_dirty &= OLED_ALL_BLOCKS_MASK; |
276 | if (!oled_dirty || oled_scrolling) { | 280 | if (!oled_dirty || oled_scrolling) { |
@@ -527,6 +531,10 @@ void oled_write_raw_P(const char *data, uint16_t size) { | |||
527 | #endif // defined(__AVR__) | 531 | #endif // defined(__AVR__) |
528 | 532 | ||
529 | bool oled_on(void) { | 533 | bool oled_on(void) { |
534 | if (!oled_initialized) { | ||
535 | return oled_active; | ||
536 | } | ||
537 | |||
530 | #if OLED_TIMEOUT > 0 | 538 | #if OLED_TIMEOUT > 0 |
531 | oled_timeout = timer_read32() + OLED_TIMEOUT; | 539 | oled_timeout = timer_read32() + OLED_TIMEOUT; |
532 | #endif | 540 | #endif |
@@ -543,6 +551,10 @@ bool oled_on(void) { | |||
543 | } | 551 | } |
544 | 552 | ||
545 | bool oled_off(void) { | 553 | bool oled_off(void) { |
554 | if (!oled_initialized) { | ||
555 | return !oled_active; | ||
556 | } | ||
557 | |||
546 | static const uint8_t PROGMEM display_off[] = {I2C_CMD, DISPLAY_OFF}; | 558 | static const uint8_t PROGMEM display_off[] = {I2C_CMD, DISPLAY_OFF}; |
547 | if (oled_active) { | 559 | if (oled_active) { |
548 | if (I2C_TRANSMIT_P(display_off) != I2C_STATUS_SUCCESS) { | 560 | if (I2C_TRANSMIT_P(display_off) != I2C_STATUS_SUCCESS) { |
@@ -557,6 +569,10 @@ bool oled_off(void) { | |||
557 | bool is_oled_on(void) { return oled_active; } | 569 | bool is_oled_on(void) { return oled_active; } |
558 | 570 | ||
559 | uint8_t oled_set_brightness(uint8_t level) { | 571 | uint8_t oled_set_brightness(uint8_t level) { |
572 | if (!oled_initialized) { | ||
573 | return oled_brightness; | ||
574 | } | ||
575 | |||
560 | uint8_t set_contrast[] = {I2C_CMD, CONTRAST, level}; | 576 | uint8_t set_contrast[] = {I2C_CMD, CONTRAST, level}; |
561 | if (oled_brightness != level) { | 577 | if (oled_brightness != level) { |
562 | if (I2C_TRANSMIT(set_contrast) != I2C_STATUS_SUCCESS) { | 578 | if (I2C_TRANSMIT(set_contrast) != I2C_STATUS_SUCCESS) { |
@@ -596,6 +612,10 @@ void oled_scroll_set_speed(uint8_t speed) { | |||
596 | } | 612 | } |
597 | 613 | ||
598 | bool oled_scroll_right(void) { | 614 | bool oled_scroll_right(void) { |
615 | if (!oled_initialized) { | ||
616 | return oled_scrolling; | ||
617 | } | ||
618 | |||
599 | // Dont enable scrolling if we need to update the display | 619 | // Dont enable scrolling if we need to update the display |
600 | // This prevents scrolling of bad data from starting the scroll too early after init | 620 | // This prevents scrolling of bad data from starting the scroll too early after init |
601 | if (!oled_dirty && !oled_scrolling) { | 621 | if (!oled_dirty && !oled_scrolling) { |
@@ -610,6 +630,10 @@ bool oled_scroll_right(void) { | |||
610 | } | 630 | } |
611 | 631 | ||
612 | bool oled_scroll_left(void) { | 632 | bool oled_scroll_left(void) { |
633 | if (!oled_initialized) { | ||
634 | return oled_scrolling; | ||
635 | } | ||
636 | |||
613 | // Dont enable scrolling if we need to update the display | 637 | // Dont enable scrolling if we need to update the display |
614 | // This prevents scrolling of bad data from starting the scroll too early after init | 638 | // This prevents scrolling of bad data from starting the scroll too early after init |
615 | if (!oled_dirty && !oled_scrolling) { | 639 | if (!oled_dirty && !oled_scrolling) { |
@@ -624,6 +648,10 @@ bool oled_scroll_left(void) { | |||
624 | } | 648 | } |
625 | 649 | ||
626 | bool oled_scroll_off(void) { | 650 | bool oled_scroll_off(void) { |
651 | if (!oled_initialized) { | ||
652 | return !oled_scrolling; | ||
653 | } | ||
654 | |||
627 | if (oled_scrolling) { | 655 | if (oled_scrolling) { |
628 | static const uint8_t PROGMEM display_scroll_off[] = {I2C_CMD, DEACTIVATE_SCROLL}; | 656 | static const uint8_t PROGMEM display_scroll_off[] = {I2C_CMD, DEACTIVATE_SCROLL}; |
629 | if (I2C_TRANSMIT_P(display_scroll_off) != I2C_STATUS_SUCCESS) { | 657 | if (I2C_TRANSMIT_P(display_scroll_off) != I2C_STATUS_SUCCESS) { |