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
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Make the divisor and the mode configurable
  • Loading branch information
Jpe230 committed Apr 23, 2022
commit 7f68bfc20d42c64fd71c0566fd04d9ae39e9bf7d
7 changes: 7 additions & 0 deletions docs/feature_oled_driver.md
Original file line number Diff line number Diff line change
@@ -195,6 +195,13 @@ If using a SPI OLED display, you'll need to define the following pins in your bo
|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.
9 changes: 9 additions & 0 deletions drivers/oled/oled_driver.h
Original file line number Diff line number Diff line change
@@ -38,6 +38,15 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
# 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)
6 changes: 1 addition & 5 deletions drivers/oled/ssd1306_sh1106.c
Original file line number Diff line number Diff line change
@@ -117,12 +117,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.

setPinOutput(OLED_DC_PIN);
writePinLow(OLED_DC_PIN);

spi_start(OLED_CS_PIN, false, 2, 10);
}

void oled_spi_start(void) {
spi_start(OLED_CS_PIN, false, 3, 8); /* MSB first, mode 3 */
spi_start(OLED_CS_PIN, false, OLED_SPI_MODE, OLED_SPI_DIVISOR);
}

void oled_spi_stop(void) {
@@ -165,7 +163,6 @@ bool oled_cmd(const uint8_t *data, uint16_t size) {
oled_spi_start();
// Command Mode
writePinLow(OLED_DC_PIN);
wait_ms(10);
// Send the commands
if(spi_transmit(data, size) != OLED_STATUS_SUCCESS){
oled_spi_stop();
@@ -210,7 +207,6 @@ bool oled_write_reg(const uint8_t *data, uint16_t size)
oled_spi_start();
// Command Mode
writePinHigh(OLED_DC_PIN);
wait_ms(10);
// Send the commands
if(spi_transmit(data, size) != OLED_STATUS_SUCCESS){
oled_spi_stop();