summaryrefslogtreecommitdiff
path: root/drivers/oled/oled_driver.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/oled/oled_driver.c')
-rw-r--r--drivers/oled/oled_driver.c38
1 files changed, 32 insertions, 6 deletions
diff --git a/drivers/oled/oled_driver.c b/drivers/oled/oled_driver.c
index 92c64399e2..8e5ed5f070 100644
--- a/drivers/oled/oled_driver.c
+++ b/drivers/oled/oled_driver.c
@@ -24,6 +24,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "progmem.h"
+#include "keyboard.h"
+
// Used commands from spec sheet: https://cdn-shop.adafruit.com/datasheets/SSD1306.pdf
// for SH1106: https://www.velleman.eu/downloads/29/infosheets/sh1106_datasheet.pdf
@@ -71,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
@@ -108,7 +115,7 @@ bool oled_initialized = false;
bool oled_active = false;
bool oled_scrolling = false;
uint8_t oled_brightness = OLED_BRIGHTNESS;
-uint8_t oled_rotation = 0;
+oled_rotation_t oled_rotation = 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_start = 0;
@@ -151,7 +158,13 @@ static void InvertCharacter(uint8_t *cursor) {
}
}
-bool oled_init(uint8_t rotation) {
+bool oled_init(oled_rotation_t rotation) {
+#if defined(USE_I2C) && defined(SPLIT_KEYBOARD)
+ if (!is_keyboard_master()) {
+ return true;
+ }
+#endif
+
oled_rotation = oled_init_user(rotation);
if (!HAS_FLAGS(oled_rotation, OLED_ROTATION_90)) {
oled_rotation_width = OLED_DISPLAY_WIDTH;
@@ -478,8 +491,9 @@ void oled_write_raw(const char *data, uint16_t size) {
uint16_t cursor_start_index = oled_cursor - &oled_buffer[0];
if ((size + cursor_start_index) > OLED_MATRIX_SIZE) size = OLED_MATRIX_SIZE - cursor_start_index;
for (uint16_t i = cursor_start_index; i < cursor_start_index + size; i++) {
- if (oled_buffer[i] == data[i]) continue;
- oled_buffer[i] = data[i];
+ uint8_t c = *data++;
+ if (oled_buffer[i] == c) continue;
+ oled_buffer[i] = c;
oled_dirty |= ((OLED_BLOCK_TYPE)1 << (i / OLED_BLOCK_SIZE));
}
}
@@ -539,7 +553,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");
@@ -555,7 +575,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");