Skip to content

Commit c07f8ff

Browse files
authored
Merge pull request #19 from makermelissa/master
Implemented sendCommand, fixed an init commands and fixed test example
2 parents 968a5e6 + bc72d3c commit c07f8ff

File tree

6 files changed

+132
-366
lines changed

6 files changed

+132
-366
lines changed

Adafruit_SSD1331.cpp

Lines changed: 70 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
/***************************************************
1+
/***************************************************
22
This is a library for the 0.96" 16-bit Color OLED with SSD1331 driver chip
33
44
Pick one up today in the adafruit shop!
55
------> http://www.adafruit.com/products/684
66
7-
These displays use SPI to communicate, 4 or 5 pins are required to
7+
These displays use SPI to communicate, 4 or 5 pins are required to
88
interface
9-
Adafruit invests time and resources providing this open source code,
10-
please support Adafruit and open-source hardware by purchasing
9+
Adafruit invests time and resources providing this open source code,
10+
please support Adafruit and open-source hardware by purchasing
1111
products from Adafruit!
1212
13-
Written by Limor Fried/Ladyada for Adafruit Industries.
13+
Written by Limor Fried/Ladyada for Adafruit Industries.
1414
BSD license, all text above must be included in any redistribution
1515
****************************************************/
1616

@@ -51,21 +51,15 @@ void Adafruit_SSD1331::setAddrWindow(uint16_t x, uint16_t y, uint16_t w, uint16_
5151
y1 = t;
5252
}
5353

54+
sendCommand(0x15); // Column addr set
55+
sendCommand(x1);
56+
sendCommand(x2);
5457

55-
startWrite();
56-
writeCommand(0x15); // Column addr set
57-
writeCommand(x1);
58-
writeCommand(x2);
59-
endWrite();
60-
61-
startWrite();
62-
writeCommand(0x75); // Column addr set
63-
writeCommand(y1);
64-
writeCommand(y2);
65-
endWrite();
58+
sendCommand(0x75); // Column addr set
59+
sendCommand(y1);
60+
sendCommand(y2);
6661

6762
startWrite();
68-
6963
}
7064

7165

@@ -79,52 +73,48 @@ void Adafruit_SSD1331::setAddrWindow(uint16_t x, uint16_t y, uint16_t w, uint16_
7973
void Adafruit_SSD1331::begin(uint32_t freq) {
8074
initSPI(freq);
8175

82-
startWrite();
83-
8476
// Initialization Sequence
85-
writeCommand(SSD1331_CMD_DISPLAYOFF); // 0xAE
86-
writeCommand(SSD1331_CMD_SETREMAP); // 0xA0
77+
sendCommand(SSD1331_CMD_DISPLAYOFF); // 0xAE
78+
sendCommand(SSD1331_CMD_SETREMAP); // 0xA0
8779
#if defined SSD1331_COLORORDER_RGB
88-
writeCommand(0x72); // RGB Color
80+
sendCommand(0x72); // RGB Color
8981
#else
90-
writeCommand(0x76); // BGR Color
82+
sendCommand(0x76); // BGR Color
9183
#endif
92-
writeCommand(SSD1331_CMD_STARTLINE); // 0xA1
93-
writeCommand(0x0);
94-
writeCommand(SSD1331_CMD_DISPLAYOFFSET); // 0xA2
95-
writeCommand(0x0);
96-
writeCommand(SSD1331_CMD_NORMALDISPLAY); // 0xA4
97-
writeCommand(SSD1331_CMD_SETMULTIPLEX); // 0xA8
98-
writeCommand(0x3F); // 0x3F 1/64 duty
99-
writeCommand(SSD1331_CMD_SETMASTER); // 0xAD
100-
writeCommand(0x8E);
101-
writeCommand(SSD1331_CMD_POWERMODE); // 0xB0
102-
writeCommand(0x0B);
103-
writeCommand(SSD1331_CMD_PRECHARGE); // 0xB1
104-
writeCommand(0x31);
105-
writeCommand(SSD1331_CMD_CLOCKDIV); // 0xB3
106-
writeCommand(0xF0); // 7:4 = Oscillator Frequency, 3:0 = CLK Div Ratio (A[3:0]+1 = 1..16)
107-
writeCommand(SSD1331_CMD_PRECHARGEA); // 0x8A
108-
writeCommand(0x64);
109-
writeCommand(SSD1331_CMD_PRECHARGEB); // 0x8B
110-
writeCommand(0x78);
111-
writeCommand(SSD1331_CMD_PRECHARGEA); // 0x8C
112-
writeCommand(0x64);
113-
writeCommand(SSD1331_CMD_PRECHARGELEVEL); // 0xBB
114-
writeCommand(0x3A);
115-
writeCommand(SSD1331_CMD_VCOMH); // 0xBE
116-
writeCommand(0x3E);
117-
writeCommand(SSD1331_CMD_MASTERCURRENT); // 0x87
118-
writeCommand(0x06);
119-
writeCommand(SSD1331_CMD_CONTRASTA); // 0x81
120-
writeCommand(0x91);
121-
writeCommand(SSD1331_CMD_CONTRASTB); // 0x82
122-
writeCommand(0x50);
123-
writeCommand(SSD1331_CMD_CONTRASTC); // 0x83
124-
writeCommand(0x7D);
125-
writeCommand(SSD1331_CMD_DISPLAYON); //--turn on oled panel
126-
127-
endWrite();
84+
sendCommand(SSD1331_CMD_STARTLINE); // 0xA1
85+
sendCommand(0x0);
86+
sendCommand(SSD1331_CMD_DISPLAYOFFSET); // 0xA2
87+
sendCommand(0x0);
88+
sendCommand(SSD1331_CMD_NORMALDISPLAY); // 0xA4
89+
sendCommand(SSD1331_CMD_SETMULTIPLEX); // 0xA8
90+
sendCommand(0x3F); // 0x3F 1/64 duty
91+
sendCommand(SSD1331_CMD_SETMASTER); // 0xAD
92+
sendCommand(0x8E);
93+
sendCommand(SSD1331_CMD_POWERMODE); // 0xB0
94+
sendCommand(0x0B);
95+
sendCommand(SSD1331_CMD_PRECHARGE); // 0xB1
96+
sendCommand(0x31);
97+
sendCommand(SSD1331_CMD_CLOCKDIV); // 0xB3
98+
sendCommand(0xF0); // 7:4 = Oscillator Frequency, 3:0 = CLK Div Ratio (A[3:0]+1 = 1..16)
99+
sendCommand(SSD1331_CMD_PRECHARGEA); // 0x8A
100+
sendCommand(0x64);
101+
sendCommand(SSD1331_CMD_PRECHARGEB); // 0x8B
102+
sendCommand(0x78);
103+
sendCommand(SSD1331_CMD_PRECHARGEC); // 0x8C
104+
sendCommand(0x64);
105+
sendCommand(SSD1331_CMD_PRECHARGELEVEL); // 0xBB
106+
sendCommand(0x3A);
107+
sendCommand(SSD1331_CMD_VCOMH); // 0xBE
108+
sendCommand(0x3E);
109+
sendCommand(SSD1331_CMD_MASTERCURRENT); // 0x87
110+
sendCommand(0x06);
111+
sendCommand(SSD1331_CMD_CONTRASTA); // 0x81
112+
sendCommand(0x91);
113+
sendCommand(SSD1331_CMD_CONTRASTB); // 0x82
114+
sendCommand(0x50);
115+
sendCommand(SSD1331_CMD_CONTRASTC); // 0x83
116+
sendCommand(0x7D);
117+
sendCommand(SSD1331_CMD_DISPLAYON); //--turn on oled panel
128118
_width = TFTWIDTH;
129119
_height = TFTHEIGHT;
130120
}
@@ -134,26 +124,42 @@ void Adafruit_SSD1331::begin(uint32_t freq) {
134124

135125
/**************************************************************************/
136126
/*!
137-
@brief Instantiate Adafruit ILI9341 driver with software SPI
127+
@brief Instantiate Adafruit SSD1331 driver with software SPI
138128
@param cs Chip select pin #
139129
@param dc Data/Command pin #
140130
@param mosi SPI MOSI pin #
141131
@param sclk SPI Clock pin #
142132
@param rst Reset pin # (optional, pass -1 if unused)
143133
*/
144134
/**************************************************************************/
145-
Adafruit_SSD1331::Adafruit_SSD1331(uint8_t cs, uint8_t dc, uint8_t mosi, uint8_t sclk, uint8_t rst) : Adafruit_SPITFT(TFTWIDTH, TFTHEIGHT, cs, dc, mosi, sclk, rst, -1) {
135+
Adafruit_SSD1331::Adafruit_SSD1331(int8_t cs, int8_t dc, int8_t mosi, int8_t sclk, int8_t rst) : Adafruit_SPITFT(TFTWIDTH, TFTHEIGHT, cs, dc, mosi, sclk, rst, -1) {
146136
}
147137

148138
/**************************************************************************/
149139
/*!
150-
@brief Instantiate Adafruit ILI9341 driver with hardware SPI
140+
@brief Instantiate Adafruit SSD1331 driver with hardware SPI
151141
@param cs Chip select pin #
152142
@param dc Data/Command pin #
153143
@param rst Reset pin # (optional, pass -1 if unused)
154144
*/
155145
/**************************************************************************/
156-
Adafruit_SSD1331::Adafruit_SSD1331(uint8_t cs, uint8_t dc, uint8_t rst) : Adafruit_SPITFT(TFTWIDTH, TFTHEIGHT, cs, dc, rst) {
157-
146+
Adafruit_SSD1331::Adafruit_SSD1331(int8_t cs, int8_t dc, int8_t rst) : Adafruit_SPITFT(TFTWIDTH, TFTHEIGHT, cs, dc, rst) {
158147
}
159148

149+
/**************************************************************************/
150+
/*!
151+
@brief Instantiate Adafruit SSD1331 driver with hardware SPI
152+
@param spi Pointer to an existing SPIClass instance (e.g. &SPI, the
153+
microcontroller's primary SPI bus).
154+
@param cs Chip select pin #
155+
@param dc Data/Command pin #
156+
@param rst Reset pin # (optional, pass -1 if unused)
157+
*/
158+
/**************************************************************************/
159+
Adafruit_SSD1331::Adafruit_SSD1331(SPIClass *spi, int8_t cs, int8_t dc, int8_t rst) :
160+
#if defined(ESP8266)
161+
Adafruit_SPITFT(TFTWIDTH, TFTWIDTH, cs, dc, rst) {
162+
#else
163+
Adafruit_SPITFT(TFTWIDTH, TFTWIDTH, spi, cs, dc, rst) {
164+
#endif
165+
}

Adafruit_SSD1331.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
/***************************************************
1+
/***************************************************
22
This is a library for the 0.96" 16-bit Color OLED with SSD1331 driver chip
33
Pick one up today in the adafruit shop!
44
------> http://www.adafruit.com/products/684
5-
These displays use SPI to communicate, 4 or 5 pins are required to
5+
These displays use SPI to communicate, 4 or 5 pins are required to
66
interface
7-
Adafruit invests time and resources providing this open source code,
8-
please support Adafruit and open-source hardware by purchasing
7+
Adafruit invests time and resources providing this open source code,
8+
please support Adafruit and open-source hardware by purchasing
99
products from Adafruit!
10-
Written by Limor Fried/Ladyada for Adafruit Industries.
10+
Written by Limor Fried/Ladyada for Adafruit Industries.
1111
BSD license, all text above must be included in any redistribution
1212
****************************************************/
1313

@@ -63,8 +63,10 @@
6363
/// Class to manage hardware interface with SSD1331 chipset
6464
class Adafruit_SSD1331 : public Adafruit_SPITFT {
6565
public:
66-
Adafruit_SSD1331(uint8_t _CS, uint8_t _DC, uint8_t _MOSI, uint8_t _SCLK, uint8_t _RST);
67-
Adafruit_SSD1331(uint8_t _CS, uint8_t _DC, uint8_t _RST);
66+
Adafruit_SSD1331(int8_t cs, int8_t dc, int8_t mosi, int8_t sclk, int8_t rst);
67+
Adafruit_SSD1331(int8_t cs, int8_t dc, int8_t rst);
68+
// 3-4 args using hardware SPI (must specify peripheral) (reset optional)
69+
Adafruit_SSD1331(SPIClass *spi, int8_t cs, int8_t dc, int8_t rst = -1);
6870

6971
// commands
7072
void begin(uint32_t begin=8000000);

0 commit comments

Comments
 (0)