aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXScorpion2 <rcalt2vt@gmail.com>2019-08-25 14:37:55 -0500
committerDrashna Jaelre <drashna@live.com>2019-08-25 12:37:55 -0700
commit957070a6b5886719557b6880afa7e3716548c18a (patch)
tree68adde454ad00f5c74538b0927f76b7db7afcb09
parentf22c5c17b6fe069bec1241262a1c27eb89d3d3af (diff)
downloadqmk_firmware-957070a6b5886719557b6880afa7e3716548c18a.tar.gz
qmk_firmware-957070a6b5886719557b6880afa7e3716548c18a.zip
Added OLED Display autoscroll during periods of OLED data inactivity (#6546)
* Added OLED Display autoscroll during periods of OLED data inactivity. * Fixing compile errors * Feedback from review
-rw-r--r--docs/feature_oled_driver.md24
-rw-r--r--drivers/oled/oled_driver.c40
-rw-r--r--drivers/oled/oled_driver.h8
-rw-r--r--tmk_core/common/timer.h11
-rw-r--r--tmk_core/protocol/usb_hid/override_wiring.c7
-rw-r--r--users/xulkal/custom_tap_dance.c1
-rw-r--r--users/xulkal/layouts.h2
-rw-r--r--users/xulkal/process_records.c3
-rw-r--r--users/xulkal/rules.mk3
-rw-r--r--users/xulkal/timer_utils.c12
-rw-r--r--users/xulkal/timer_utils.h6
-rw-r--r--users/xulkal/xulkal.h1
12 files changed, 72 insertions, 46 deletions
diff --git a/docs/feature_oled_driver.md b/docs/feature_oled_driver.md
index 9d19beedb..623f1816a 100644
--- a/docs/feature_oled_driver.md
+++ b/docs/feature_oled_driver.md
@@ -96,17 +96,19 @@ void oled_task_user(void) {
96 96
97 ## Basic Configuration 97 ## Basic Configuration
98 98
99| Define | Default | Description | 99| Define | Default | Description |
100|------------------------|-------------------|----------------------------------------------------------------------------------------------------------------------------| 100|----------------------------|-------------------|----------------------------------------------------------------------------------------------------------------------------|
101| `OLED_DISPLAY_ADDRESS` | `0x3C` | The i2c address of the OLED Display | 101| `OLED_DISPLAY_ADDRESS` | `0x3C` | The i2c address of the OLED Display |
102| `OLED_FONT_H` | `"glcdfont.c"` | The font code file to use for custom fonts | 102| `OLED_FONT_H` | `"glcdfont.c"` | The font code file to use for custom fonts |
103| `OLED_FONT_START` | `0` | The starting characer index for custom fonts | 103| `OLED_FONT_START` | `0` | The starting characer index for custom fonts |
104| `OLED_FONT_END` | `224` | The ending characer index for custom fonts | 104| `OLED_FONT_END` | `224` | The ending characer index for custom fonts |
105| `OLED_FONT_WIDTH` | `6` | The font width | 105| `OLED_FONT_WIDTH` | `6` | The font width |
106| `OLED_FONT_HEIGHT` | `8` | The font height (untested) | 106| `OLED_FONT_HEIGHT` | `8` | The font height (untested) |
107| `OLED_DISABLE_TIMEOUT` | *Not defined* | Disables the built in OLED timeout feature. Useful when implementing custom timeout rules. | 107| `OLED_TIMEOUT` | `60000` | Turns off the OLED screen after 60000ms of keyboard inactivity. Helps reduce OLED Burn-in. Set to 0 to disable. |
108| `OLED_IC` | `OLED_IC_SSD1306` | Set to `OLED_IC_SH1106` if you're using the SH1106 OLED controller. | 108| `OLED_SCROLL_TIMEOUT` | `0` | Scrolls the OLED screen after 0ms of OLED inactivity. Helps reduce OLED Burn-in. Set to 0 to disable. |
109| `OLED_COLUMN_OFFSET` | `0` | (SH1106 only.) Shift output to the right this many pixels.<br />Useful for 128x64 displays centered on a 132x64 SH1106 IC. | 109| `OLED_SCROLL_TIMEOUT_RIGHT`| *Not defined* | Scroll timeout direction is right when defined, left when undefined. |
110| `OLED_IC` | `OLED_IC_SSD1306` | Set to `OLED_IC_SH1106` if you're using the SH1106 OLED controller. |
111| `OLED_COLUMN_OFFSET` | `0` | (SH1106 only.) Shift output to the right this many pixels.<br />Useful for 128x64 displays centered on a 132x64 SH1106 IC. |
110 112
111 ## 128x64 & Custom sized OLED Displays 113 ## 128x64 & Custom sized OLED Displays
112 114
diff --git a/drivers/oled/oled_driver.c b/drivers/oled/oled_driver.c
index 2b3dd7ff2..3dad72add 100644
--- a/drivers/oled/oled_driver.c
+++ b/drivers/oled/oled_driver.c
@@ -114,8 +114,11 @@ bool oled_active = false;
114bool oled_scrolling = false; 114bool oled_scrolling = false;
115uint8_t oled_rotation = 0; 115uint8_t oled_rotation = 0;
116uint8_t oled_rotation_width = 0; 116uint8_t oled_rotation_width = 0;
117#if !defined(OLED_DISABLE_TIMEOUT) 117#if OLED_TIMEOUT > 0
118 uint16_t oled_last_activity; 118 uint32_t oled_timeout;
119#endif
120#if OLED_SCROLL_TIMEOUT > 0
121 uint32_t oled_scroll_timeout;
119#endif 122#endif
120 123
121// Internal variables to reduce math instructions 124// Internal variables to reduce math instructions
@@ -209,6 +212,13 @@ bool oled_init(uint8_t rotation) {
209 return false; 212 return false;
210 } 213 }
211 214
215#if OLED_TIMEOUT > 0
216 oled_timeout = timer_read32() + OLED_TIMEOUT;
217#endif
218#if OLED_SCROLL_TIMEOUT > 0
219 oled_scroll_timeout = timer_read32() + OLED_SCROLL_TIMEOUT;
220#endif
221
212 oled_clear(); 222 oled_clear();
213 oled_initialized = true; 223 oled_initialized = true;
214 oled_active = true; 224 oled_active = true;
@@ -457,8 +467,8 @@ void oled_write_ln_P(const char *data, bool invert) {
457#endif // defined(__AVR__) 467#endif // defined(__AVR__)
458 468
459bool oled_on(void) { 469bool oled_on(void) {
460#if !defined(OLED_DISABLE_TIMEOUT) 470#if OLED_TIMEOUT > 0
461 oled_last_activity = timer_read(); 471 oled_timeout = timer_read32() + OLED_TIMEOUT;
462#endif 472#endif
463 473
464 static const uint8_t PROGMEM display_on[] = { I2C_CMD, DISPLAY_ON }; 474 static const uint8_t PROGMEM display_on[] = { I2C_CMD, DISPLAY_ON };
@@ -522,6 +532,7 @@ bool oled_scroll_off(void) {
522 return oled_scrolling; 532 return oled_scrolling;
523 } 533 }
524 oled_scrolling = false; 534 oled_scrolling = false;
535 oled_dirty = -1;
525 } 536 }
526 return !oled_scrolling; 537 return !oled_scrolling;
527} 538}
@@ -549,15 +560,32 @@ void oled_task(void) {
549 560
550 oled_task_user(); 561 oled_task_user();
551 562
563#if OLED_SCROLL_TIMEOUT > 0
564 if (oled_dirty && oled_scrolling) {
565 oled_scroll_timeout = timer_read32() + OLED_SCROLL_TIMEOUT;
566 oled_scroll_off();
567 }
568#endif
569
552 // Smart render system, no need to check for dirty 570 // Smart render system, no need to check for dirty
553 oled_render(); 571 oled_render();
554 572
555 // Display timeout check 573 // Display timeout check
556#if !defined(OLED_DISABLE_TIMEOUT) 574#if OLED_TIMEOUT > 0
557 if (oled_active && timer_elapsed(oled_last_activity) > OLED_TIMEOUT) { 575 if (oled_active && timer_expired32(timer_read32(), oled_timeout)) {
558 oled_off(); 576 oled_off();
559 } 577 }
560#endif 578#endif
579
580#if OLED_SCROLL_TIMEOUT > 0
581 if (!oled_scrolling && timer_expired32(timer_read32(), oled_scroll_timeout)) {
582#ifdef OLED_SCROLL_TIMEOUT_RIGHT
583 oled_scroll_right();
584#else
585 oled_scroll_left();
586#endif
587 }
588#endif
561} 589}
562 590
563__attribute__((weak)) 591__attribute__((weak))
diff --git a/drivers/oled/oled_driver.h b/drivers/oled/oled_driver.h
index 03dda2e64..4f6254c98 100644
--- a/drivers/oled/oled_driver.h
+++ b/drivers/oled/oled_driver.h
@@ -138,6 +138,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
138 #define OLED_FONT_HEIGHT 8 138 #define OLED_FONT_HEIGHT 8
139#endif 139#endif
140 140
141#if !defined(OLED_TIMEOUT)
142 #if defined(OLED_DISABLE_TIMEOUT)
143 #define OLED_TIMEOUT 0
144 #else
145 #define OLED_TIMEOUT 60000
146 #endif
147#endif
148
141// OLED Rotation enum values are flags 149// OLED Rotation enum values are flags
142typedef enum { 150typedef enum {
143 OLED_ROTATION_0 = 0, 151 OLED_ROTATION_0 = 0,
diff --git a/tmk_core/common/timer.h b/tmk_core/common/timer.h
index fe23f87ae..a8dd85663 100644
--- a/tmk_core/common/timer.h
+++ b/tmk_core/common/timer.h
@@ -19,6 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
19#define TIMER_H 1 19#define TIMER_H 1
20 20
21#include <stdint.h> 21#include <stdint.h>
22#include <stdbool.h>
22 23
23#if defined(__AVR__) 24#if defined(__AVR__)
24#include "avr/timer_avr.h" 25#include "avr/timer_avr.h"
@@ -46,6 +47,16 @@ uint32_t timer_read32(void);
46uint16_t timer_elapsed(uint16_t last); 47uint16_t timer_elapsed(uint16_t last);
47uint32_t timer_elapsed32(uint32_t last); 48uint32_t timer_elapsed32(uint32_t last);
48 49
50// Utility functions to check if a future time has expired & autmatically handle time wrapping if checked / reset frequently (half of max value)
51inline bool timer_expired(uint16_t current, uint16_t last)
52{
53 return current - last < 0x8000;
54}
55
56inline bool timer_expired32(uint32_t current, uint32_t future) {
57 return current - future < 0x80000000;
58}
59
49#ifdef __cplusplus 60#ifdef __cplusplus
50} 61}
51#endif 62#endif
diff --git a/tmk_core/protocol/usb_hid/override_wiring.c b/tmk_core/protocol/usb_hid/override_wiring.c
index 1e9a94ce2..52f03c300 100644
--- a/tmk_core/protocol/usb_hid/override_wiring.c
+++ b/tmk_core/protocol/usb_hid/override_wiring.c
@@ -4,14 +4,13 @@
4#define __DELAY_BACKWARD_COMPATIBLE__ 4#define __DELAY_BACKWARD_COMPATIBLE__
5#include <util/delay.h> 5#include <util/delay.h>
6#include "common/timer.h" 6#include "common/timer.h"
7#include "Arduino.h"
8 7
9 8
10unsigned long millis() 9unsigned long millis(void)
11{ 10{
12 return timer_read32(); 11 return timer_read32();
13} 12}
14unsigned long micros() 13unsigned long micros(void)
15{ 14{
16 return timer_read32() * 1000UL; 15 return timer_read32() * 1000UL;
17} 16}
@@ -23,7 +22,7 @@ void delayMicroseconds(unsigned int us)
23{ 22{
24 _delay_us(us); 23 _delay_us(us);
25} 24}
26void init() 25void init(void)
27{ 26{
28 timer_init(); 27 timer_init();
29} 28}
diff --git a/users/xulkal/custom_tap_dance.c b/users/xulkal/custom_tap_dance.c
index e0f90ea11..2c5d145f1 100644
--- a/users/xulkal/custom_tap_dance.c
+++ b/users/xulkal/custom_tap_dance.c
@@ -1,6 +1,5 @@
1#include "custom_tap_dance.h" 1#include "custom_tap_dance.h"
2#include "custom_keycodes.h" 2#include "custom_keycodes.h"
3#include "timer_utils.h"
4 3
5#ifdef TAP_DANCE_ENABLE 4#ifdef TAP_DANCE_ENABLE
6 5
diff --git a/users/xulkal/layouts.h b/users/xulkal/layouts.h
index 89bdfb60d..d4b708418 100644
--- a/users/xulkal/layouts.h
+++ b/users/xulkal/layouts.h
@@ -18,7 +18,7 @@
18#define _________________QWERTY_L2_________________ KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T 18#define _________________QWERTY_L2_________________ KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T
19#define _________________QWERTY_L3_________________ RIS_CAPS, KC_A, KC_S, KC_D, KC_F, KC_G 19#define _________________QWERTY_L3_________________ RIS_CAPS, KC_A, KC_S, KC_D, KC_F, KC_G
20#define _________________QWERTY_L4_________________ KC_LSPO, KC_Z, KC_X, KC_C, KC_V, KC_B 20#define _________________QWERTY_L4_________________ KC_LSPO, KC_Z, KC_X, KC_C, KC_V, KC_B
21#define _________________QWERTY_L5_________________ KC_LCPO, KC_LGUI, LOWER, RAISE, KC_LALT, KC_SPC 21#define _________________QWERTY_L5_________________ KC_LCPO, KC_LGUI, KC_LALT, LOWER, RAISE, KC_SPC
22 22
23#define _________________QWERTY_R1_________________ KC_6, KC_7, KC_8, KC_9, KC_0, TD_BSPC 23#define _________________QWERTY_R1_________________ KC_6, KC_7, KC_8, KC_9, KC_0, TD_BSPC
24#define _________________QWERTY_R2_________________ KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSLS 24#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 245d4955f..9c0274823 100644
--- a/users/xulkal/process_records.c
+++ b/users/xulkal/process_records.c
@@ -1,6 +1,5 @@
1#include "process_records.h" 1#include "process_records.h"
2#include "custom_keycodes.h" 2#include "custom_keycodes.h"
3#include "timer_utils.h"
4 3
5#ifdef RGB_ENABLE 4#ifdef RGB_ENABLE
6#include "custom_rgb.h" 5#include "custom_rgb.h"
@@ -34,7 +33,7 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record)
34 { 33 {
35 if (record->event.pressed) 34 if (record->event.pressed)
36 reset_timer = timer_read() + 500; 35 reset_timer = timer_read() + 500;
37 else if (timer_expired(reset_timer)) 36 else if (timer_expired(timer_read(), reset_timer))
38 reset_keyboard(); 37 reset_keyboard();
39 } 38 }
40 return false; 39 return false;
diff --git a/users/xulkal/rules.mk b/users/xulkal/rules.mk
index c3834ff5f..8f8365ea7 100644
--- a/users/xulkal/rules.mk
+++ b/users/xulkal/rules.mk
@@ -1,7 +1,6 @@
1SRC += xulkal.c \ 1SRC += xulkal.c \
2 process_records.c \ 2 process_records.c \
3 custom_tap_dance.c \ 3 custom_tap_dance.c
4 timer_utils.c
5 4
6# Some usual defaults 5# Some usual defaults
7MOUSEKEY_ENABLE = no # Mouse keys (+4700) 6MOUSEKEY_ENABLE = no # Mouse keys (+4700)
diff --git a/users/xulkal/timer_utils.c b/users/xulkal/timer_utils.c
deleted file mode 100644
index 5f5d9a1eb..000000000
--- a/users/xulkal/timer_utils.c
+++ /dev/null
@@ -1,12 +0,0 @@
1#include "timer_utils.h"
2
3bool timer_expired(uint16_t last)
4{
5 return timer_read() - last < 0x8000;
6}
7
8bool timer_expired32(uint32_t last)
9{
10 return timer_read32() - last < 0x80000000;
11}
12
diff --git a/users/xulkal/timer_utils.h b/users/xulkal/timer_utils.h
deleted file mode 100644
index 7e2a0b74d..000000000
--- a/users/xulkal/timer_utils.h
+++ /dev/null
@@ -1,6 +0,0 @@
1#pragma once
2#include "timer.h"
3#include <stdbool.h>
4
5bool timer_expired(uint16_t last);
6bool timer_expired32(uint32_t last);
diff --git a/users/xulkal/xulkal.h b/users/xulkal/xulkal.h
index 9bc83b7de..32df8df0c 100644
--- a/users/xulkal/xulkal.h
+++ b/users/xulkal/xulkal.h
@@ -2,6 +2,5 @@
2 2
3#include "process_records.h" 3#include "process_records.h"
4#include "layouts.h" 4#include "layouts.h"
5#include "timer_utils.h"
6#include "custom_keycodes.h" 5#include "custom_keycodes.h"
7#include "custom_tap_dance.h" 6#include "custom_tap_dance.h"