aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan <fauxpark@gmail.com>2020-10-29 18:12:50 +1100
committerGitHub <noreply@github.com>2020-10-29 00:12:50 -0700
commit5cecc1ea1ec8df3b74d01f96336dee2c2f5c6f4e (patch)
treec5abcb14e22e0a9ce2476162208b45bcf6a6d77a
parentb9ed9d33d3b57627e919e771f62ff1cbecf0c8d4 (diff)
downloadqmk_firmware-5cecc1ea1ec8df3b74d01f96336dee2c2f5c6f4e.tar.gz
qmk_firmware-5cecc1ea1ec8df3b74d01f96336dee2c2f5c6f4e.zip
Add brightness level API to OLED driver (#10772)
* Add brightness level API to OLED driver * Set default brightness to 255
-rw-r--r--docs/feature_oled_driver.md11
-rw-r--r--drivers/oled/oled_driver.c17
-rw-r--r--drivers/oled/oled_driver.h10
-rw-r--r--keyboards/handwired/onekey/keymaps/oled/keymap.c6
4 files changed, 41 insertions, 3 deletions
diff --git a/docs/feature_oled_driver.md b/docs/feature_oled_driver.md
index 9e33a321c..9f0ef1664 100644
--- a/docs/feature_oled_driver.md
+++ b/docs/feature_oled_driver.md
@@ -140,8 +140,8 @@ void oled_task_user(void) {
140|---------------------------|-----------------|--------------------------------------------------------------------------------------------------------------------------| 140|---------------------------|-----------------|--------------------------------------------------------------------------------------------------------------------------|
141|`OLED_DISPLAY_ADDRESS` |`0x3C` |The i2c address of the OLED Display | 141|`OLED_DISPLAY_ADDRESS` |`0x3C` |The i2c address of the OLED Display |
142|`OLED_FONT_H` |`"glcdfont.c"` |The font code file to use for custom fonts | 142|`OLED_FONT_H` |`"glcdfont.c"` |The font code file to use for custom fonts |
143|`OLED_FONT_START` |`0` |The starting characer index for custom fonts | 143|`OLED_FONT_START` |`0` |The starting character index for custom fonts |
144|`OLED_FONT_END` |`223` |The ending characer index for custom fonts | 144|`OLED_FONT_END` |`223` |The ending character index for custom fonts |
145|`OLED_FONT_WIDTH` |`6` |The font width | 145|`OLED_FONT_WIDTH` |`6` |The font width |
146|`OLED_FONT_HEIGHT` |`8` |The font height (untested) | 146|`OLED_FONT_HEIGHT` |`8` |The font height (untested) |
147|`OLED_TIMEOUT` |`60000` |Turns off the OLED screen after 60000ms of keyboard inactivity. Helps reduce OLED Burn-in. Set to 0 to disable. | 147|`OLED_TIMEOUT` |`60000` |Turns off the OLED screen after 60000ms of keyboard inactivity. Helps reduce OLED Burn-in. Set to 0 to disable. |
@@ -149,6 +149,7 @@ void oled_task_user(void) {
149|`OLED_SCROLL_TIMEOUT_RIGHT`|*Not defined* |Scroll timeout direction is right when defined, left when undefined. | 149|`OLED_SCROLL_TIMEOUT_RIGHT`|*Not defined* |Scroll timeout direction is right when defined, left when undefined. |
150|`OLED_IC` |`OLED_IC_SSD1306`|Set to `OLED_IC_SH1106` if you're using the SH1106 OLED controller. | 150|`OLED_IC` |`OLED_IC_SSD1306`|Set to `OLED_IC_SH1106` if you're using the SH1106 OLED controller. |
151|`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.| 151|`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.|
152|`OLED_BRIGHTNESS` |`255` |The default brightness level of the OLED, from 0 to 255. |
152 153
153 ## 128x64 & Custom sized OLED Displays 154 ## 128x64 & Custom sized OLED Displays
154 155
@@ -304,6 +305,12 @@ bool oled_off(void);
304// not 305// not
305bool is_oled_on(void); 306bool is_oled_on(void);
306 307
308// Sets the brightness level of the display
309uint8_t oled_set_brightness(uint8_t level);
310
311// Gets the current brightness level of the display
312uint8_t oled_get_brightness(void);
313
307// Basically it's oled_render, but with timeout management and oled_task_user calling! 314// Basically it's oled_render, but with timeout management and oled_task_user calling!
308void oled_task(void); 315void oled_task(void);
309 316
diff --git a/drivers/oled/oled_driver.c b/drivers/oled/oled_driver.c
index 0b24a987d..ba11db1d2 100644
--- a/drivers/oled/oled_driver.c
+++ b/drivers/oled/oled_driver.c
@@ -107,6 +107,7 @@ OLED_BLOCK_TYPE oled_dirty = 0;
107bool oled_initialized = false; 107bool oled_initialized = false;
108bool oled_active = false; 108bool oled_active = false;
109bool oled_scrolling = false; 109bool oled_scrolling = false;
110uint8_t oled_brightness = OLED_BRIGHTNESS;
110uint8_t oled_rotation = 0; 111uint8_t oled_rotation = 0;
111uint8_t oled_rotation_width = 0; 112uint8_t oled_rotation_width = 0;
112uint8_t oled_scroll_speed = 0; // this holds the speed after being remapped to ssd1306 internal values 113uint8_t oled_scroll_speed = 0; // this holds the speed after being remapped to ssd1306 internal values
@@ -193,7 +194,7 @@ bool oled_init(uint8_t rotation) {
193 } 194 }
194 } 195 }
195 196
196 static const uint8_t PROGMEM display_setup2[] = {I2C_CMD, COM_PINS, OLED_COM_PINS, CONTRAST, 0x8F, PRE_CHARGE_PERIOD, 0xF1, VCOM_DETECT, 0x40, DISPLAY_ALL_ON_RESUME, NORMAL_DISPLAY, DEACTIVATE_SCROLL, DISPLAY_ON}; 197 static const uint8_t PROGMEM display_setup2[] = {I2C_CMD, COM_PINS, OLED_COM_PINS, CONTRAST, OLED_BRIGHTNESS, PRE_CHARGE_PERIOD, 0xF1, VCOM_DETECT, 0x20, DISPLAY_ALL_ON_RESUME, NORMAL_DISPLAY, DEACTIVATE_SCROLL, DISPLAY_ON};
197 if (I2C_TRANSMIT_P(display_setup2) != I2C_STATUS_SUCCESS) { 198 if (I2C_TRANSMIT_P(display_setup2) != I2C_STATUS_SUCCESS) {
198 print("display_setup2 failed\n"); 199 print("display_setup2 failed\n");
199 return false; 200 return false;
@@ -550,6 +551,20 @@ bool oled_off(void) {
550 551
551bool is_oled_on(void) { return oled_active; } 552bool is_oled_on(void) { return oled_active; }
552 553
554uint8_t oled_set_brightness(uint8_t level) {
555 uint8_t set_contrast[] = {I2C_CMD, CONTRAST, level};
556 if (oled_brightness != level) {
557 if (I2C_TRANSMIT(set_contrast) != I2C_STATUS_SUCCESS) {
558 print("set_brightness cmd failed\n");
559 return oled_brightness;
560 }
561 oled_brightness = level;
562 }
563 return oled_brightness;
564}
565
566uint8_t oled_get_brightness(void) { return oled_brightness; }
567
553// Set the specific 8 lines rows of the screen to scroll. 568// Set the specific 8 lines rows of the screen to scroll.
554// 0 is the default for start, and 7 for end, which is the entire 569// 0 is the default for start, and 7 for end, which is the entire
555// height of the screen. For 128x32 screens, rows 4-7 are not used. 570// height of the screen. For 128x32 screens, rows 4-7 are not used.
diff --git a/drivers/oled/oled_driver.h b/drivers/oled/oled_driver.h
index 58e2bb738..72ab21247 100644
--- a/drivers/oled/oled_driver.h
+++ b/drivers/oled/oled_driver.h
@@ -141,6 +141,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
141#if !defined(OLED_FONT_HEIGHT) 141#if !defined(OLED_FONT_HEIGHT)
142# define OLED_FONT_HEIGHT 8 142# define OLED_FONT_HEIGHT 8
143#endif 143#endif
144// Default brightness level
145#if !defined(OLED_BRIGHTNESS)
146# define OLED_BRIGHTNESS 255
147#endif
144 148
145#if !defined(OLED_TIMEOUT) 149#if !defined(OLED_TIMEOUT)
146# if defined(OLED_DISABLE_TIMEOUT) 150# if defined(OLED_DISABLE_TIMEOUT)
@@ -261,6 +265,12 @@ bool oled_off(void);
261// not 265// not
262bool is_oled_on(void); 266bool is_oled_on(void);
263 267
268// Sets the brightness of the display
269uint8_t oled_set_brightness(uint8_t level);
270
271// Gets the current brightness of the display
272uint8_t oled_get_brightness(void);
273
264// Basically it's oled_render, but with timeout management and oled_task_user calling! 274// Basically it's oled_render, but with timeout management and oled_task_user calling!
265void oled_task(void); 275void oled_task(void);
266 276
diff --git a/keyboards/handwired/onekey/keymaps/oled/keymap.c b/keyboards/handwired/onekey/keymaps/oled/keymap.c
index b6e66ace7..1c120d01c 100644
--- a/keyboards/handwired/onekey/keymaps/oled/keymap.c
+++ b/keyboards/handwired/onekey/keymaps/oled/keymap.c
@@ -144,6 +144,12 @@ static void dance_oled_finished(qk_tap_dance_state_t *state, void *user_data) {
144 } 144 }
145 } 145 }
146 break; 146 break;
147 case 4:
148 if (!state->pressed) {
149 // quadruple tap - step through brightness levels
150 oled_set_brightness(oled_get_brightness() + 0x10);
151 }
152 break;
147 default: 153 default:
148 break; 154 break;
149 } 155 }