Skip to content

Commit

Permalink
Added OLED fade out support (qmk#12086)
Browse files Browse the repository at this point in the history
  • Loading branch information
Barabas5532 authored and nhongooi committed Dec 5, 2021
1 parent 721a870 commit 3462d08
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
2 changes: 2 additions & 0 deletions docs/feature_oled_driver.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ void oled_task_user(void) {
|`OLED_FONT_WIDTH` |`6` |The font width |
|`OLED_FONT_HEIGHT` |`8` |The font height (untested) |
|`OLED_TIMEOUT` |`60000` |Turns off the OLED screen after 60000ms of keyboard inactivity. Helps reduce OLED Burn-in. Set to 0 to disable. |
|`OLED_FADE_OUT` |*Not defined* |Enables fade out animation. Use together with `OLED_TIMEOUT`. |
|`OLED_FADE_OUT_INTERVAL` |`0` |The speed of fade out animation, from 0 to 15. Larger values are slower. |
|`OLED_SCROLL_TIMEOUT` |`0` |Scrolls the OLED screen after 0ms of OLED inactivity. Helps reduce OLED Burn-in. Set to 0 to disable. |
|`OLED_SCROLL_TIMEOUT_RIGHT`|*Not defined* |Scroll timeout direction is right when defined, left when undefined. |
|`OLED_IC` |`OLED_IC_SSD1306`|Set to `OLED_IC_SH1106` if you're using the SH1106 OLED controller. |
Expand Down
21 changes: 19 additions & 2 deletions drivers/oled/oled_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define PRE_CHARGE_PERIOD 0xD9
#define VCOM_DETECT 0xDB

// Advance Graphic Commands
#define FADE_BLINK 0x23
#define ENABLE_FADE 0x20
#define ENABLE_BLINK 0x30

// Charge Pump Commands
#define CHARGE_PUMP 0x8D

Expand Down Expand Up @@ -547,7 +552,13 @@ bool oled_on(void) {
oled_timeout = timer_read32() + OLED_TIMEOUT;
#endif

static const uint8_t PROGMEM display_on[] = {I2C_CMD, DISPLAY_ON};
static const uint8_t PROGMEM display_on[] =
#ifdef OLED_FADE_OUT
{I2C_CMD, FADE_BLINK, 0x00};
#else
{I2C_CMD, DISPLAY_ON};
#endif

if (!oled_active) {
if (I2C_TRANSMIT_P(display_on) != I2C_STATUS_SUCCESS) {
print("oled_on cmd failed\n");
Expand All @@ -563,7 +574,13 @@ bool oled_off(void) {
return !oled_active;
}

static const uint8_t PROGMEM display_off[] = {I2C_CMD, DISPLAY_OFF};
static const uint8_t PROGMEM display_off[] =
#ifdef OLED_FADE_OUT
{I2C_CMD, FADE_BLINK, ENABLE_FADE | OLED_FADE_OUT_INTERVAL};
#else
{I2C_CMD, DISPLAY_OFF};
#endif

if (oled_active) {
if (I2C_TRANSMIT_P(display_off) != I2C_STATUS_SUCCESS) {
print("oled_off cmd failed\n");
Expand Down
8 changes: 8 additions & 0 deletions drivers/oled/oled_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
# endif
#endif

#if !defined(OLED_FADE_OUT_INTERVAL)
# define OLED_FADE_OUT_INTERVAL 0x00
#endif

#if OLED_FADE_OUT_INTERVAL > 0x0F || OLED_FADE_OUT_INTERVAL < 0x00
# error OLED_FADE_OUT_INTERVAL must be between 0x00 and 0x0F
#endif

#if !defined(OLED_I2C_TIMEOUT)
# define OLED_I2C_TIMEOUT 100
#endif
Expand Down

0 comments on commit 3462d08

Please sign in to comment.