Skip to content

Commit

Permalink
[Core] Refactor OLED to allow easy addition of other types (qmk#13454)
Browse files Browse the repository at this point in the history
* add docs

* core changes

* update keyboards to new OLED

* updated users to new OLED

* update layouts to new OLED

* fixup docs

* drashna's suggestion

* fix up docs

* new keyboards with oled

* core split changes

* remaining keyboard files

* Fix The Helix keyboards oled options

* reflect develop

Co-authored-by: Drashna Jaelre <drashna@live.com>
Co-authored-by: mtei <2170248+mtei@users.noreply.github.com>
  • Loading branch information
3 people committed Aug 24, 2021
1 parent 6fd20ac commit 4e1c588
Show file tree
Hide file tree
Showing 500 changed files with 1,579 additions and 1,387 deletions.
20 changes: 15 additions & 5 deletions common_features.mk
Original file line number Diff line number Diff line change
Expand Up @@ -592,11 +592,21 @@ ifeq ($(strip $(HD44780_ENABLE)), yes)
OPT_DEFS += -DHD44780_ENABLE
endif

ifeq ($(strip $(OLED_DRIVER_ENABLE)), yes)
OPT_DEFS += -DOLED_DRIVER_ENABLE
COMMON_VPATH += $(DRIVER_PATH)/oled
QUANTUM_LIB_SRC += i2c_master.c
SRC += oled_driver.c
VALID_OLED_DRIVER_TYPES := SSD1306 custom
OLED_DRIVER ?= SSD1306
ifeq ($(strip $(OLED_ENABLE)), yes)
ifeq ($(filter $(OLED_DRIVER),$(VALID_OLED_DRIVER_TYPES)),)
$(error OLED_DRIVER="$(OLED_DRIVER)" is not a valid OLED driver)
else
OPT_DEFS += -DOLED_ENABLE
COMMON_VPATH += $(DRIVER_PATH)/oled

OPT_DEFS += -DOLED_DRIVER_$(strip $(shell echo $(OLED_DRIVER) | tr '[:lower:]' '[:upper:]'))
ifeq ($(strip $(OLED_DRIVER)), SSD1306)
SRC += ssd1306_sh1106.c
QUANTUM_LIB_SRC += i2c_master.c
endif
endif
endif

ifeq ($(strip $(ST7565_ENABLE)), yes)
Expand Down
16 changes: 13 additions & 3 deletions docs/feature_oled_driver.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,23 @@ Hardware configurations using Arm-based microcontrollers or different sizes of O
To enable the OLED feature, there are three steps. First, when compiling your keyboard, you'll need to add the following to your `rules.mk`:

```make
OLED_DRIVER_ENABLE = yes
OLED_ENABLE = yes
```

## OLED type
|OLED Driver |Supported Device |
|-------------------|---------------------------|
|SSD1306 (default) |For both SSD1306 and SH1106|

e.g.
```make
OLED_DRIVER = SSD1306
```

Then in your `keymap.c` file, implement the OLED task call. This example assumes your keymap has three layers named `_QWERTY`, `_FN` and `_ADJ`:

```c
#ifdef OLED_DRIVER_ENABLE
#ifdef OLED_ENABLE
void oled_task_user(void) {
// Host Keyboard Layer Status
oled_write_P(PSTR("Layer: "), false);
Expand Down Expand Up @@ -114,7 +124,7 @@ static void fade_display(void) {
In split keyboards, it is very common to have two OLED displays that each render different content and are oriented or flipped differently. You can do this by switching which content to render by using the return value from `is_keyboard_master()` or `is_keyboard_left()` found in `split_util.h`, e.g:

```c
#ifdef OLED_DRIVER_ENABLE
#ifdef OLED_ENABLE
oled_rotation_t oled_init_user(oled_rotation_t rotation) {
if (!is_keyboard_master()) {
return OLED_ROTATION_180; // flips the display 180 degrees if offhand
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion keyboards/0xcb/1337/keymaps/conor/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ bool encoder_update_user(uint8_t index, bool clockwise) {
#endif

/* oled stuff :) */
#ifdef OLED_DRIVER_ENABLE
#ifdef OLED_ENABLE
uint16_t startup_timer;

oled_rotation_t oled_init_user(oled_rotation_t rotation) {
Expand Down
2 changes: 1 addition & 1 deletion keyboards/0xcb/1337/keymaps/default/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ bool encoder_update_user(uint8_t index, bool clockwise) {
#endif

/* oled stuff :) */
#ifdef OLED_DRIVER_ENABLE
#ifdef OLED_ENABLE
uint16_t startup_timer;

oled_rotation_t oled_init_user(oled_rotation_t rotation) {
Expand Down
2 changes: 1 addition & 1 deletion keyboards/0xcb/1337/keymaps/jakob/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ bool encoder_update_user(uint8_t index, bool clockwise) {
#endif

/* oled stuff :) */
#ifdef OLED_DRIVER_ENABLE
#ifdef OLED_ENABLE
uint16_t startup_timer;

oled_rotation_t oled_init_user(oled_rotation_t rotation) {
Expand Down
2 changes: 1 addition & 1 deletion keyboards/0xcb/1337/keymaps/via/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ bool encoder_update_user(uint8_t index, bool clockwise) {
#endif

/* oled stuff :) */
#ifdef OLED_DRIVER_ENABLE
#ifdef OLED_ENABLE
uint16_t startup_timer;

oled_rotation_t oled_init_user(oled_rotation_t rotation) {
Expand Down
3 changes: 2 additions & 1 deletion keyboards/0xcb/1337/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ AUDIO_ENABLE = no # Audio output

ENCODER_ENABLE = yes
LTO_ENABLE = yes
OLED_DRIVER_ENABLE = yes
OLED_ENABLE = yes
OLED_DRIVER = SSD1306
2 changes: 1 addition & 1 deletion keyboards/0xcb/static/keymaps/default/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ bool encoder_update_user(uint8_t index, bool clockwise) {
#endif

/* oled stuff :) */
#ifdef OLED_DRIVER_ENABLE
#ifdef OLED_ENABLE
uint16_t startup_timer = 0;

oled_rotation_t oled_init_user(oled_rotation_t rotation) {
Expand Down
2 changes: 1 addition & 1 deletion keyboards/0xcb/static/keymaps/via/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ bool encoder_update_user(uint8_t index, bool clockwise) {
#endif

/* oled stuff :) */
#ifdef OLED_DRIVER_ENABLE
#ifdef OLED_ENABLE
uint16_t startup_timer = 0;

oled_rotation_t oled_init_user(oled_rotation_t rotation) {
Expand Down
3 changes: 2 additions & 1 deletion keyboards/0xcb/static/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ AUDIO_ENABLE = no # Audio output

ENCODER_ENABLE = yes
LTO_ENABLE = yes
OLED_DRIVER_ENABLE = yes
OLED_ENABLE = yes
OLED_DRIVER = SSD1306
2 changes: 1 addition & 1 deletion keyboards/10bleoledhub/keymaps/default/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ static void render_logo(void) {
oled_write_P(qmk_logo, false);
}

#ifdef OLED_DRIVER_ENABLE
#ifdef OLED_ENABLE
void oled_task_user(void) { render_logo(); }
#endif

Expand Down
2 changes: 1 addition & 1 deletion keyboards/10bleoledhub/keymaps/via/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ static void render_logo(void) {
oled_write_P(qmk_logo, false);
}

#ifdef OLED_DRIVER_ENABLE
#ifdef OLED_ENABLE
void oled_task_user(void) { render_logo(); }
#endif

Expand Down
3 changes: 2 additions & 1 deletion keyboards/10bleoledhub/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@ RGBLIGHT_ENABLE = no # Enable keyboard RGB underglow
BLUETOOTH_ENABLE = no # Enable Bluetooth
AUDIO_ENABLE = no # Audio output
BLUETOOTH = AdafruitBLE
OLED_DRIVER_ENABLE = yes
OLED_ENABLE = yes
OLED_DRIVER = SSD1306
ENCODER_ENABLE = yes
2 changes: 1 addition & 1 deletion keyboards/8pack/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ NKRO_ENABLE = no # USB Nkey Rollover - if this doesn't work, see here: htt
BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality
AUDIO_ENABLE = no
RGBLIGHT_ENABLE = yes
OLED_DRIVER_ENABLE = no
OLED_ENABLE = no

DEFAULT_FOLDER = 8pack/rev12
2 changes: 1 addition & 1 deletion keyboards/aeboards/ext65/keymaps/default/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
)
};

#ifdef OLED_DRIVER_ENABLE
#ifdef OLED_ENABLE

void render_layer_state(void) {
oled_write_ln(PSTR("LAYER"), false);
Expand Down
2 changes: 1 addition & 1 deletion keyboards/aeboards/ext65/keymaps/via/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
)
};

#ifdef OLED_DRIVER_ENABLE
#ifdef OLED_ENABLE

void render_layer_state(void) {
oled_write_ln(PSTR("LAYER"), false);
Expand Down
2 changes: 2 additions & 0 deletions keyboards/aeboards/ext65/keymaps/via/rules.mk
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
VIA_ENABLE = yes
OLED_ENABLE = yes
# OLED_DRIVER = not a real thing
2 changes: 1 addition & 1 deletion keyboards/aeboards/ext65/rev2/rev2.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Tested and verified working on ext65rev2
void matrix_io_delay(void) { __asm__ volatile("nop\nnop\nnop\n"); }

#ifdef OLED_DRIVER_ENABLE
#ifdef OLED_ENABLE
void board_init(void) {
SYSCFG->CFGR1 |= SYSCFG_CFGR1_I2C1_DMA_RMP;
SYSCFG->CFGR1 &= ~(SYSCFG_CFGR1_SPI2_DMA_RMP);
Expand Down
2 changes: 1 addition & 1 deletion keyboards/aleblazer/zodiark/keymaps/default/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once

#ifdef OLED_DRIVER_ENABLE
#ifdef OLED_ENABLE
#define OLED_DISPLAY_128X64
#define OLED_TIMEOUT 400000
#endif
2 changes: 1 addition & 1 deletion keyboards/aleblazer/zodiark/keymaps/default/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
)

};
#ifdef OLED_DRIVER_ENABLE
#ifdef OLED_ENABLE

static void render_logo(void) {
static const char PROGMEM qmk_logo[] = {
Expand Down
2 changes: 1 addition & 1 deletion keyboards/aleblazer/zodiark/keymaps/slimoled/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once

#ifdef OLED_DRIVER_ENABLE
#ifdef OLED_ENABLE
#define OLED_DISPLAY_128X32
#define OLED_TIMEOUT 400000
#endif
2 changes: 1 addition & 1 deletion keyboards/aleblazer/zodiark/keymaps/slimoled/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
)

};
#ifdef OLED_DRIVER_ENABLE
#ifdef OLED_ENABLE

static void render_logo(void) {
static const char PROGMEM qmk_logo[] = {
Expand Down
2 changes: 1 addition & 1 deletion keyboards/aleblazer/zodiark/keymaps/via/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once

#ifdef OLED_DRIVER_ENABLE
#ifdef OLED_ENABLE
#define OLED_DISPLAY_128X64
#define OLED_TIMEOUT 400000
#endif
2 changes: 1 addition & 1 deletion keyboards/aleblazer/zodiark/keymaps/via/oled.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifdef OLED_DRIVER_ENABLE
#ifdef OLED_ENABLE

static void render_logo(void) {
static const char PROGMEM qmk_logo[] = {
Expand Down
3 changes: 2 additions & 1 deletion keyboards/aleblazer/zodiark/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality
RGBLIGHT_ENABLE = no # Enable keyboard RGB underglow
BLUETOOTH_ENABLE = no # Enable Bluetooth
AUDIO_ENABLE = no # Audio output
OLED_DRIVER_ENABLE = yes # Enable Support for SSD1306 or SH1106 OLED Displays; Communicating over I2C
OLED_ENABLE = yes
OLED_DRIVER = SSD1306 # Enable Support for SSD1306 or SH1106 OLED Displays; Communicating over I2C
ENCODER_ENABLE = yes
SPLIT_KEYBOARD = yes
LTO_ENABLE = yes
Expand Down
2 changes: 1 addition & 1 deletion keyboards/anavi/macropad8/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
# define RGBLIGHT_LIMIT_VAL 255
#endif

#ifdef OLED_DRIVER_ENABLE
#ifdef OLED_ENABLE
# define OLED_DISPLAY_128X64
# define OLED_TIMEOUT 60000
# define OLED_FONT_H "keyboards/anavi/macropad8/glcdfont.c"
Expand Down
2 changes: 1 addition & 1 deletion keyboards/anavi/macropad8/keymaps/default/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
)
};

#ifdef OLED_DRIVER_ENABLE
#ifdef OLED_ENABLE
oled_rotation_t oled_init_user(oled_rotation_t rotation) {
return OLED_ROTATION_180; // flips the display 180 degrees if offhand
}
Expand Down
2 changes: 1 addition & 1 deletion keyboards/anavi/macropad8/keymaps/git/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
)
};

#ifdef OLED_DRIVER_ENABLE
#ifdef OLED_ENABLE
oled_rotation_t oled_init_user(oled_rotation_t rotation) {
return OLED_ROTATION_180; // flips the display 180 degrees if offhand
}
Expand Down
4 changes: 2 additions & 2 deletions keyboards/anavi/macropad8/keymaps/kicad/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const uint8_t RGBLED_RAINBOW_SWIRL_INTERVALS[] PROGMEM = {20, 10, 4};
* F1 - zoom in
* F2 - zoom out
* F4 - zoom center
*
*
*/

const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
Expand All @@ -70,7 +70,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
)
};

#ifdef OLED_DRIVER_ENABLE
#ifdef OLED_ENABLE
oled_rotation_t oled_init_user(oled_rotation_t rotation) {
return OLED_ROTATION_180; // flips the display 180 degrees if offhand
}
Expand Down
2 changes: 1 addition & 1 deletion keyboards/anavi/macropad8/keymaps/kodi/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
)
};

#ifdef OLED_DRIVER_ENABLE
#ifdef OLED_ENABLE
oled_rotation_t oled_init_user(oled_rotation_t rotation) {
return OLED_ROTATION_180; // flips the display 180 degrees if offhand
}
Expand Down
2 changes: 1 addition & 1 deletion keyboards/anavi/macropad8/keymaps/obs/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
)
};

#ifdef OLED_DRIVER_ENABLE
#ifdef OLED_ENABLE
oled_rotation_t oled_init_user(oled_rotation_t rotation) {
return OLED_ROTATION_180; // flips the display 180 degrees if offhand
}
Expand Down
2 changes: 1 addition & 1 deletion keyboards/anavi/macropad8/keymaps/zoom/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
)
};

#ifdef OLED_DRIVER_ENABLE
#ifdef OLED_ENABLE
oled_rotation_t oled_init_user(oled_rotation_t rotation) {
return OLED_ROTATION_180; // flips the display 180 degrees if offhand
}
Expand Down
3 changes: 2 additions & 1 deletion keyboards/anavi/macropad8/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality
AUDIO_ENABLE = no # Audio output on port C6
BLUETOOTH_ENABLE = no # Enable Bluetooth with the Adafruit EZ-Key HID
RGBLIGHT_ENABLE = yes # Enable WS2812 RGB underlight.
OLED_DRIVER_ENABLE = yes # Enable Support for SSD1306 or SH1106 OLED Displays; Communicating over I2C
OLED_ENABLE = yes
OLED_DRIVER = SSD1306 # Enable Support for SSD1306 or SH1106 OLED Displays; Communicating over I2C

# Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE
SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend
2 changes: 1 addition & 1 deletion keyboards/angel64/alpha/keymaps/default/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
KC_NO, KC_NO, KC_NO, _______, KC_NO, _______, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO),
};

#ifdef OLED_DRIVER_ENABLE
#ifdef OLED_ENABLE
void oled_task_user(void) {
oled_write_P(PSTR("Layer: "), false);
switch (biton32(layer_state)) {
Expand Down
2 changes: 1 addition & 1 deletion keyboards/angel64/rev1/keymaps/default/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
KC_LCTL, KC_LALT, KC_LGUI, KC_SPC, KC_SPC, KC_SPC, KC_SPC, KC_SPC, KC_RALT, KC_APP, KC_RCTL),
};

#ifdef OLED_DRIVER_ENABLE
#ifdef OLED_ENABLE
void oled_task_user(void) {
// Host Keyboard LED Status
oled_write_P(IS_HOST_LED_ON(USB_LED_NUM_LOCK) ? PSTR("NUMLCK ") : PSTR(" "), false);
Expand Down
2 changes: 1 addition & 1 deletion keyboards/angel64/rev1/keymaps/kakunpc/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ void matrix_scan_user(void) {
#endif
}

#ifdef OLED_DRIVER_ENABLE
#ifdef OLED_ENABLE
void oled_task_user(void) {
oled_write_P(PSTR("Layer: "), false);
switch (biton32(layer_state)) {
Expand Down
3 changes: 2 additions & 1 deletion keyboards/angel64/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ RGBLIGHT_ENABLE = yes # Enable keyboard RGB underglow
UNICODE_ENABLE = no # Unicode
BLUETOOTH_ENABLE = no # Enable Bluetooth with the Adafruit EZ-Key HID
AUDIO_ENABLE = no # Audio output on port C6
OLED_DRIVER_ENABLE = yes
OLED_ENABLE = yes
OLED_DRIVER = SSD1306
CUSTOM_MATRIX = yes

SRC += matrix.c
Expand Down
2 changes: 1 addition & 1 deletion keyboards/aplyard/aplx6/rev2/keymaps/default/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
)
};

#if defined(OLED_DRIVER_ENABLE)
#if defined(OLED_ENABLE)
static void render_logo(void) {
//Logo for _MEDIA
static const char PROGMEM logo1[] = {
Expand Down
3 changes: 2 additions & 1 deletion keyboards/aplyard/aplx6/rev2/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ RGBLIGHT_ENABLE = no # Enable keyboard RGB underglow
BLUETOOTH_ENABLE = no # Enable Bluetooth
AUDIO_ENABLE = no # Audio output
UNICODE_ENABLE = yes # Unicode
OLED_DRIVER_ENABLE = yes # Enable Support for Oled Display
OLED_ENABLE = yes
OLED_DRIVER = SSD1306 # Enable Support for Oled Display
ENCODER_ENABLE = yes # Enable Support for Encoder
Loading

0 comments on commit 4e1c588

Please sign in to comment.