Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SPI support for the OLED Driver #16924

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion builddefs/common_features.mk
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,10 @@ endif

VALID_OLED_DRIVER_TYPES := SSD1306 custom
OLED_DRIVER ?= SSD1306

VALID_OLED_DRIVER_BUS_TYPES := spi i2c
OLED_DRIVER_BUS ?= i2c

ifeq ($(strip $(OLED_ENABLE)), yes)
ifeq ($(filter $(OLED_DRIVER),$(VALID_OLED_DRIVER_TYPES)),)
$(call CATASTROPHIC_ERROR,Invalid OLED_DRIVER,OLED_DRIVER="$(OLED_DRIVER)" is not a valid OLED driver)
Expand All @@ -668,7 +672,17 @@ ifeq ($(strip $(OLED_ENABLE)), yes)
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
ifeq ($(filter $(OLED_DRIVER_BUS),$(VALID_OLED_DRIVER_BUS_TYPES)),)
$(call CATASTROPHIC_ERROR,Invalid OLED_DRIVER_BUS,OLED_DRIVER_BUS="$(OLED_DRIVER_BUS)" is not a valid OLED driver)
else
ifeq ($(strip $(OLED_DRIVER_BUS)), i2c)
QUANTUM_LIB_SRC += i2c_master.c
OPT_DEFS += -DOLED_BUS=0
else
QUANTUM_LIB_SRC += spi_master.c
OPT_DEFS += -DOLED_BUS=1
endif
endif
endif
endif
endif
Expand Down
32 changes: 30 additions & 2 deletions docs/feature_oled_driver.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Supported Hardware

OLED modules using SSD1306 or SH1106 driver ICs, communicating over I2C.
OLED modules using SSD1306 or SH1106 driver ICs, communicating over I2C or SPI.
Tested combinations:

|IC |Size |Platform|Notes |
Expand All @@ -18,7 +18,7 @@ Hardware configurations using Arm-based microcontrollers or different sizes of O

## Usage

To enable the OLED feature, there are two steps. First, when compiling your keyboard, you'll need to add the following to your `rules.mk`:
To enable the OLED feature, there are typically two steps. First, when compiling your keyboard, you'll need to add the following to your `rules.mk`:

```make
OLED_ENABLE = yes
Expand All @@ -34,6 +34,17 @@ e.g.
OLED_DRIVER = SSD1306
```

## OLED bus
|OLED Bus |Tested Device |
|-------------------|---------------------------|
|I2C (default) |SSD1306 and SH1106 |
|SPI |SH1106 |

e.g.
```make
OLED_DRIVER_BUS = i2c
```

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
Expand Down Expand Up @@ -174,6 +185,23 @@ These configuration options should be placed in `config.h`. Example:
|`OLED_BRIGHTNESS` |`255` |The default brightness level of the OLED, from 0 to 255. |
|`OLED_UPDATE_INTERVAL` |`0` |Set the time interval for updating the OLED display in ms. This will improve the matrix scan rate. |


## Configuring a SPI OLED

If using a SPI OLED display, you'll need to define the following pins in your board's `config.h` and configure the (SPI Master Driver)[spi_driver.md]`

|Defines |Description |
|-------------------|----------------------------------------------------------------|
|OLED_DC_PIN |Pin that determines whether the data pins are data or command |
|OLED_CS_PIN |Pin that is used to select the chip |
|OLED_RST_PIN |Pin to reset the display |

You can also define the mode and divisor using the following defines:

|Define |Default |Description |
|---------------------------|-----------------|-----------------------------------------------------------|
|`OLED_SPI_MODE` |`3` |The SPI mode to use with the OLED Display |
|`OLED_SPI_DIVISOR` |`2` |The SPI clock divisoR to be used with the OLED Display |
## 128x64 & Custom sized OLED Displays

The default display size for this feature is 128x32 and all necessary defines are precalculated with that in mind. We have added a define, `OLED_DISPLAY_128X64`, to switch all the values to be used in a 128x64 display, as well as added a custom define, `OLED_DISPLAY_CUSTOM`, that allows you to provide the necessary values to the driver.
Expand Down
26 changes: 26 additions & 0 deletions drivers/oled/oled_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,32 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define OLED_IC_SSD1306 0
#define OLED_IC_SH1106 1

#define OLED_BUS_I2C 0
#define OLED_BUS_SPI 1

// Define the bus for the chip
#ifndef OLED_BUS
# define OLED_BUS OLED_BUS_I2C //Defaults to I2C
#endif

#if (OLED_BUS == OLED_BUS_SPI)
# ifndef OLED_DC_PIN
# error "The OLED driver in SPI needs a D/C pin defined"
# endif
# ifndef OLED_CS_PIN
# error "The OLED driver in SPI needs a CS pin defined"
# endif
# ifndef OLED_CS_PIN
# error "The OLED driver in SPI needs a CS pin defined"
# endif
# ifndef OLED_SPI_MODE
# define OLED_SPI_MODE 3
# endif
# ifndef OLED_SPI_DIVISOR
# define OLED_SPI_DIVISOR 2
# endif
#endif

#if defined(OLED_DISPLAY_CUSTOM)
// Expected user to implement the necessary defines
#elif defined(OLED_DISPLAY_128X64)
Expand Down
Loading