diff --git a/docs/feature_oled_driver.md b/docs/feature_oled_driver.md
index 9d19beedb2..623f1816ac 100644
--- a/docs/feature_oled_driver.md
+++ b/docs/feature_oled_driver.md
@@ -96,17 +96,19 @@ void oled_task_user(void) {
## Basic Configuration
-| Define | Default | Description |
-|------------------------|-------------------|----------------------------------------------------------------------------------------------------------------------------|
-| `OLED_DISPLAY_ADDRESS` | `0x3C` | The i2c address of the OLED Display |
-| `OLED_FONT_H` | `"glcdfont.c"` | The font code file to use for custom fonts |
-| `OLED_FONT_START` | `0` | The starting characer index for custom fonts |
-| `OLED_FONT_END` | `224` | The ending characer index for custom fonts |
-| `OLED_FONT_WIDTH` | `6` | The font width |
-| `OLED_FONT_HEIGHT` | `8` | The font height (untested) |
-| `OLED_DISABLE_TIMEOUT` | *Not defined* | Disables the built in OLED timeout feature. Useful when implementing custom timeout rules. |
-| `OLED_IC` | `OLED_IC_SSD1306` | Set to `OLED_IC_SH1106` if you're using the SH1106 OLED controller. |
-| `OLED_COLUMN_OFFSET` | `0` | (SH1106 only.) Shift output to the right this many pixels.
Useful for 128x64 displays centered on a 132x64 SH1106 IC. |
+| Define | Default | Description |
+|----------------------------|-------------------|----------------------------------------------------------------------------------------------------------------------------|
+| `OLED_DISPLAY_ADDRESS` | `0x3C` | The i2c address of the OLED Display |
+| `OLED_FONT_H` | `"glcdfont.c"` | The font code file to use for custom fonts |
+| `OLED_FONT_START` | `0` | The starting characer index for custom fonts |
+| `OLED_FONT_END` | `224` | The ending characer index for custom fonts |
+| `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_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. |
+| `OLED_COLUMN_OFFSET` | `0` | (SH1106 only.) Shift output to the right this many pixels.
Useful for 128x64 displays centered on a 132x64 SH1106 IC. |
## 128x64 & Custom sized OLED Displays
diff --git a/drivers/oled/oled_driver.c b/drivers/oled/oled_driver.c
index 2b3dd7ff2f..3dad72addb 100644
--- a/drivers/oled/oled_driver.c
+++ b/drivers/oled/oled_driver.c
@@ -114,8 +114,11 @@ bool oled_active = false;
bool oled_scrolling = false;
uint8_t oled_rotation = 0;
uint8_t oled_rotation_width = 0;
-#if !defined(OLED_DISABLE_TIMEOUT)
- uint16_t oled_last_activity;
+#if OLED_TIMEOUT > 0
+ uint32_t oled_timeout;
+#endif
+#if OLED_SCROLL_TIMEOUT > 0
+ uint32_t oled_scroll_timeout;
#endif
// Internal variables to reduce math instructions
@@ -209,6 +212,13 @@ bool oled_init(uint8_t rotation) {
return false;
}
+#if OLED_TIMEOUT > 0
+ oled_timeout = timer_read32() + OLED_TIMEOUT;
+#endif
+#if OLED_SCROLL_TIMEOUT > 0
+ oled_scroll_timeout = timer_read32() + OLED_SCROLL_TIMEOUT;
+#endif
+
oled_clear();
oled_initialized = true;
oled_active = true;
@@ -457,8 +467,8 @@ void oled_write_ln_P(const char *data, bool invert) {
#endif // defined(__AVR__)
bool oled_on(void) {
-#if !defined(OLED_DISABLE_TIMEOUT)
- oled_last_activity = timer_read();
+#if OLED_TIMEOUT > 0
+ oled_timeout = timer_read32() + OLED_TIMEOUT;
#endif
static const uint8_t PROGMEM display_on[] = { I2C_CMD, DISPLAY_ON };
@@ -522,6 +532,7 @@ bool oled_scroll_off(void) {
return oled_scrolling;
}
oled_scrolling = false;
+ oled_dirty = -1;
}
return !oled_scrolling;
}
@@ -549,15 +560,32 @@ void oled_task(void) {
oled_task_user();
+#if OLED_SCROLL_TIMEOUT > 0
+ if (oled_dirty && oled_scrolling) {
+ oled_scroll_timeout = timer_read32() + OLED_SCROLL_TIMEOUT;
+ oled_scroll_off();
+ }
+#endif
+
// Smart render system, no need to check for dirty
oled_render();
// Display timeout check
-#if !defined(OLED_DISABLE_TIMEOUT)
- if (oled_active && timer_elapsed(oled_last_activity) > OLED_TIMEOUT) {
+#if OLED_TIMEOUT > 0
+ if (oled_active && timer_expired32(timer_read32(), oled_timeout)) {
oled_off();
}
#endif
+
+#if OLED_SCROLL_TIMEOUT > 0
+ if (!oled_scrolling && timer_expired32(timer_read32(), oled_scroll_timeout)) {
+#ifdef OLED_SCROLL_TIMEOUT_RIGHT
+ oled_scroll_right();
+#else
+ oled_scroll_left();
+#endif
+ }
+#endif
}
__attribute__((weak))
diff --git a/drivers/oled/oled_driver.h b/drivers/oled/oled_driver.h
index 03dda2e64a..4f6254c98c 100644
--- a/drivers/oled/oled_driver.h
+++ b/drivers/oled/oled_driver.h
@@ -138,6 +138,14 @@ along with this program. If not, see .
#define OLED_FONT_HEIGHT 8
#endif
+#if !defined(OLED_TIMEOUT)
+ #if defined(OLED_DISABLE_TIMEOUT)
+ #define OLED_TIMEOUT 0
+ #else
+ #define OLED_TIMEOUT 60000
+ #endif
+#endif
+
// OLED Rotation enum values are flags
typedef enum {
OLED_ROTATION_0 = 0,
diff --git a/tmk_core/common/timer.h b/tmk_core/common/timer.h
index fe23f87aec..a8dd85663f 100644
--- a/tmk_core/common/timer.h
+++ b/tmk_core/common/timer.h
@@ -19,6 +19,7 @@ along with this program. If not, see .
#define TIMER_H 1
#include
+#include
#if defined(__AVR__)
#include "avr/timer_avr.h"
@@ -46,6 +47,16 @@ uint32_t timer_read32(void);
uint16_t timer_elapsed(uint16_t last);
uint32_t timer_elapsed32(uint32_t last);
+// Utility functions to check if a future time has expired & autmatically handle time wrapping if checked / reset frequently (half of max value)
+inline bool timer_expired(uint16_t current, uint16_t last)
+{
+ return current - last < 0x8000;
+}
+
+inline bool timer_expired32(uint32_t current, uint32_t future) {
+ return current - future < 0x80000000;
+}
+
#ifdef __cplusplus
}
#endif
diff --git a/tmk_core/protocol/usb_hid/override_wiring.c b/tmk_core/protocol/usb_hid/override_wiring.c
index 1e9a94ce26..52f03c300f 100644
--- a/tmk_core/protocol/usb_hid/override_wiring.c
+++ b/tmk_core/protocol/usb_hid/override_wiring.c
@@ -4,14 +4,13 @@
#define __DELAY_BACKWARD_COMPATIBLE__
#include
#include "common/timer.h"
-#include "Arduino.h"
-unsigned long millis()
+unsigned long millis(void)
{
return timer_read32();
}
-unsigned long micros()
+unsigned long micros(void)
{
return timer_read32() * 1000UL;
}
@@ -23,7 +22,7 @@ void delayMicroseconds(unsigned int us)
{
_delay_us(us);
}
-void init()
+void init(void)
{
timer_init();
}
diff --git a/users/xulkal/custom_tap_dance.c b/users/xulkal/custom_tap_dance.c
index e0f90ea110..2c5d145f1b 100644
--- a/users/xulkal/custom_tap_dance.c
+++ b/users/xulkal/custom_tap_dance.c
@@ -1,6 +1,5 @@
#include "custom_tap_dance.h"
#include "custom_keycodes.h"
-#include "timer_utils.h"
#ifdef TAP_DANCE_ENABLE
diff --git a/users/xulkal/layouts.h b/users/xulkal/layouts.h
index 89bdfb60d3..d4b7084186 100644
--- a/users/xulkal/layouts.h
+++ b/users/xulkal/layouts.h
@@ -18,7 +18,7 @@
#define _________________QWERTY_L2_________________ KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T
#define _________________QWERTY_L3_________________ RIS_CAPS, KC_A, KC_S, KC_D, KC_F, KC_G
#define _________________QWERTY_L4_________________ KC_LSPO, KC_Z, KC_X, KC_C, KC_V, KC_B
-#define _________________QWERTY_L5_________________ KC_LCPO, KC_LGUI, LOWER, RAISE, KC_LALT, KC_SPC
+#define _________________QWERTY_L5_________________ KC_LCPO, KC_LGUI, KC_LALT, LOWER, RAISE, KC_SPC
#define _________________QWERTY_R1_________________ KC_6, KC_7, KC_8, KC_9, KC_0, TD_BSPC
#define _________________QWERTY_R2_________________ KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSLS
diff --git a/users/xulkal/process_records.c b/users/xulkal/process_records.c
index 245d4955fb..9c0274823b 100644
--- a/users/xulkal/process_records.c
+++ b/users/xulkal/process_records.c
@@ -1,6 +1,5 @@
#include "process_records.h"
#include "custom_keycodes.h"
-#include "timer_utils.h"
#ifdef RGB_ENABLE
#include "custom_rgb.h"
@@ -34,7 +33,7 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record)
{
if (record->event.pressed)
reset_timer = timer_read() + 500;
- else if (timer_expired(reset_timer))
+ else if (timer_expired(timer_read(), reset_timer))
reset_keyboard();
}
return false;
diff --git a/users/xulkal/rules.mk b/users/xulkal/rules.mk
index c3834ff5f0..8f8365ea7e 100644
--- a/users/xulkal/rules.mk
+++ b/users/xulkal/rules.mk
@@ -1,7 +1,6 @@
SRC += xulkal.c \
process_records.c \
- custom_tap_dance.c \
- timer_utils.c
+ custom_tap_dance.c
# Some usual defaults
MOUSEKEY_ENABLE = no # Mouse keys (+4700)
diff --git a/users/xulkal/timer_utils.c b/users/xulkal/timer_utils.c
deleted file mode 100644
index 5f5d9a1ebf..0000000000
--- a/users/xulkal/timer_utils.c
+++ /dev/null
@@ -1,12 +0,0 @@
-#include "timer_utils.h"
-
-bool timer_expired(uint16_t last)
-{
- return timer_read() - last < 0x8000;
-}
-
-bool timer_expired32(uint32_t last)
-{
- return timer_read32() - last < 0x80000000;
-}
-
diff --git a/users/xulkal/timer_utils.h b/users/xulkal/timer_utils.h
deleted file mode 100644
index 7e2a0b74db..0000000000
--- a/users/xulkal/timer_utils.h
+++ /dev/null
@@ -1,6 +0,0 @@
-#pragma once
-#include "timer.h"
-#include
-
-bool timer_expired(uint16_t last);
-bool timer_expired32(uint32_t last);
diff --git a/users/xulkal/xulkal.h b/users/xulkal/xulkal.h
index 9bc83b7de7..32df8df0c6 100644
--- a/users/xulkal/xulkal.h
+++ b/users/xulkal/xulkal.h
@@ -2,6 +2,5 @@
#include "process_records.h"
#include "layouts.h"
-#include "timer_utils.h"
#include "custom_keycodes.h"
#include "custom_tap_dance.h"