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

SPI Updates #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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: 10 additions & 6 deletions firmware/Adafruit_SSD1306_mfGFX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,21 +129,24 @@ Adafruit_SSD1306::Adafruit_SSD1306(int8_t SID, int8_t SCLK, int8_t DC, int8_t RS
sclk = SCLK;
sid = SID;
hwSPI = false;
spiClass = NULL;
}

// constructor for hardware SPI - we indicate DataCommand, ChipSelect, Reset
Adafruit_SSD1306::Adafruit_SSD1306(int8_t DC, int8_t RST, int8_t CS) : Adafruit_GFX(SSD1306_LCDWIDTH, SSD1306_LCDHEIGHT) {
Adafruit_SSD1306::Adafruit_SSD1306(int8_t DC, int8_t RST, int8_t CS, bool USE_SPI1) : Adafruit_GFX(SSD1306_LCDWIDTH, SSD1306_LCDHEIGHT) {
dc = DC;
rst = RST;
cs = CS;
hwSPI = true;
spiClass = USE_SPI1 ? &SPI1 : &SPI;
}

// initializer for I2C - we only indicate the reset pin!
Adafruit_SSD1306::Adafruit_SSD1306(int8_t reset) :
Adafruit_GFX(SSD1306_LCDWIDTH, SSD1306_LCDHEIGHT) {
sclk = dc = cs = sid = -1;
rst = reset;
spiClass = NULL;
}


Expand All @@ -162,10 +165,11 @@ void Adafruit_SSD1306::begin(uint8_t vccstate, uint8_t i2caddr) {
}
if (hwSPI){
digitalWrite(cs, HIGH);
SPI.setBitOrder(MSBFIRST);
SPI.setClockDivider(SPI_CLOCK_DIV8); // 72MHz / 8 = 9Mhz
SPI.setDataMode(0);
SPI.begin();
spiClass->.setBitOrder(MSBFIRST);
spiClass->.setClockDivider(SPI_CLOCK_DIV8); // 72MHz / 8 = 9Mhz
spiClass->.setDataMode(0);
spiClass->.begin(cs); // Passing the chip-select here just sets the pin mode.
// The peripheral won't automatically assert/deassert the pin during operation.
}
}
else
Expand Down Expand Up @@ -451,7 +455,7 @@ void Adafruit_SSD1306::clearDisplay(void) {
inline void Adafruit_SSD1306::fastSPIwrite(uint8_t d) {

if(hwSPI) {
(void)SPI.transfer(d);
(void)spiClass->transfer(d);
} else {
shiftOut(sid, sclk, MSBFIRST, d); // SSD1306 specs show MSB out first
}
Expand Down
3 changes: 2 additions & 1 deletion firmware/Adafruit_SSD1306_mfGFX.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ All text above, and the splash screen must be included in any redistribution
class Adafruit_SSD1306 : public Adafruit_GFX {
public:
Adafruit_SSD1306(int8_t SID, int8_t SCLK, int8_t DC, int8_t RST, int8_t CS);
Adafruit_SSD1306(int8_t DC, int8_t RST, int8_t CS);
Adafruit_SSD1306(int8_t DC, int8_t RST, int8_t CS, bool USE_SPI1=false);
Adafruit_SSD1306(int8_t RST);

void begin(uint8_t switchvcc = SSD1306_SWITCHCAPVCC, uint8_t i2caddr = SSD1306_I2C_ADDRESS);
Expand All @@ -135,6 +135,7 @@ class Adafruit_SSD1306 : public Adafruit_GFX {

private:
int8_t _i2caddr, _vccstate, sid, sclk, dc, rst, cs;
SPIClass * spiClass;
void fastSPIwrite(uint8_t c);

boolean hwSPI;
Expand Down
Loading