Add brightness level API to OLED driver (#10772)
* Add brightness level API to OLED driver * Set default brightness to 255
This commit is contained in:
@@ -107,6 +107,7 @@ OLED_BLOCK_TYPE oled_dirty = 0;
|
|||||||
bool oled_initialized = false;
|
bool oled_initialized = false;
|
||||||
bool oled_active = false;
|
bool oled_active = false;
|
||||||
bool oled_scrolling = false;
|
bool oled_scrolling = false;
|
||||||
|
uint8_t oled_brightness = OLED_BRIGHTNESS;
|
||||||
uint8_t oled_rotation = 0;
|
uint8_t oled_rotation = 0;
|
||||||
uint8_t oled_rotation_width = 0;
|
uint8_t oled_rotation_width = 0;
|
||||||
uint8_t oled_scroll_speed = 0; // this holds the speed after being remapped to ssd1306 internal values
|
uint8_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) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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};
|
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};
|
||||||
if (I2C_TRANSMIT_P(display_setup2) != I2C_STATUS_SUCCESS) {
|
if (I2C_TRANSMIT_P(display_setup2) != I2C_STATUS_SUCCESS) {
|
||||||
print("display_setup2 failed\n");
|
print("display_setup2 failed\n");
|
||||||
return false;
|
return false;
|
||||||
@@ -550,6 +551,20 @@ bool oled_off(void) {
|
|||||||
|
|
||||||
bool is_oled_on(void) { return oled_active; }
|
bool is_oled_on(void) { return oled_active; }
|
||||||
|
|
||||||
|
uint8_t oled_set_brightness(uint8_t level) {
|
||||||
|
uint8_t set_contrast[] = {I2C_CMD, CONTRAST, level};
|
||||||
|
if (oled_brightness != level) {
|
||||||
|
if (I2C_TRANSMIT(set_contrast) != I2C_STATUS_SUCCESS) {
|
||||||
|
print("set_brightness cmd failed\n");
|
||||||
|
return oled_brightness;
|
||||||
|
}
|
||||||
|
oled_brightness = level;
|
||||||
|
}
|
||||||
|
return oled_brightness;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t oled_get_brightness(void) { return oled_brightness; }
|
||||||
|
|
||||||
// Set the specific 8 lines rows of the screen to scroll.
|
// Set the specific 8 lines rows of the screen to scroll.
|
||||||
// 0 is the default for start, and 7 for end, which is the entire
|
// 0 is the default for start, and 7 for end, which is the entire
|
||||||
// height of the screen. For 128x32 screens, rows 4-7 are not used.
|
// height of the screen. For 128x32 screens, rows 4-7 are not used.
|
||||||
|
|||||||
@@ -141,6 +141,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
#if !defined(OLED_FONT_HEIGHT)
|
#if !defined(OLED_FONT_HEIGHT)
|
||||||
# define OLED_FONT_HEIGHT 8
|
# define OLED_FONT_HEIGHT 8
|
||||||
#endif
|
#endif
|
||||||
|
// Default brightness level
|
||||||
|
#if !defined(OLED_BRIGHTNESS)
|
||||||
|
# define OLED_BRIGHTNESS 255
|
||||||
|
#endif
|
||||||
|
|
||||||
#if !defined(OLED_TIMEOUT)
|
#if !defined(OLED_TIMEOUT)
|
||||||
# if defined(OLED_DISABLE_TIMEOUT)
|
# if defined(OLED_DISABLE_TIMEOUT)
|
||||||
@@ -261,6 +265,12 @@ bool oled_off(void);
|
|||||||
// not
|
// not
|
||||||
bool is_oled_on(void);
|
bool is_oled_on(void);
|
||||||
|
|
||||||
|
// Sets the brightness of the display
|
||||||
|
uint8_t oled_set_brightness(uint8_t level);
|
||||||
|
|
||||||
|
// Gets the current brightness of the display
|
||||||
|
uint8_t oled_get_brightness(void);
|
||||||
|
|
||||||
// Basically it's oled_render, but with timeout management and oled_task_user calling!
|
// Basically it's oled_render, but with timeout management and oled_task_user calling!
|
||||||
void oled_task(void);
|
void oled_task(void);
|
||||||
|
|
||||||
|
|||||||
@@ -1,23 +0,0 @@
|
|||||||
#include QMK_KEYBOARD_H
|
|
||||||
#include "audio.h"
|
|
||||||
|
|
||||||
/* THIS FILE WAS GENERATED AND IS EXPERIMENTAL!
|
|
||||||
*
|
|
||||||
* This file was generated by qmk-compile-json. You may or may not want to
|
|
||||||
* edit it directly.
|
|
||||||
*/
|
|
||||||
|
|
||||||
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
|
|
||||||
[0] = LAYOUT(KC_ENTER)
|
|
||||||
};
|
|
||||||
|
|
||||||
void encoder_update_user(uint8_t index, bool clockwise) {
|
|
||||||
if (index == 0) {
|
|
||||||
if (clockwise) {
|
|
||||||
tap_code(KC_UP);
|
|
||||||
} else {
|
|
||||||
tap_code(KC_DOWN);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
{
|
|
||||||
"documentation": "This file is a keymap.json file for handwired/onekey/pytest"
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user