4444 #define WIRE_WRITE wire->send
4545#endif
4646
47- #if defined(__AVR__) || defined(ESP32)
47+ #if defined(__AVR__)
4848 #define WIRECLK 400000L
49+ #elif defined(ESP32)
50+ #define WIRECLK 800000L
4951#else
5052 #define WIRECLK 1000000L
5153#endif
7476 #define SPI_TRANSACTION_END SSD1306_DESELECT
7577#endif
7678
77- #define TRANSACTION_START \
79+ #if ARDUINO >= 157
80+ #define TRANSACTION_START \
7881 if (wire) wire->setClock (WIRECLK); \
7982 else { SPI_TRANSACTION_START }
80-
81- #define TRANSACTION_END \
83+ #define TRANSACTION_END \
8284 if (wire) wire->setClock (restoreClk); \
8385 else { SPI_TRANSACTION_END }
86+ #else
87+ #define TRANSACTION_START if (spi) { SPI_TRANSACTION_START }
88+ #define TRANSACTION_END if (spi) { SPI_TRANSACTION_END }
89+ #endif
8490
8591// CONSTRUCTORS, DESTRUCTOR ------------------------------------------------
8692
8793// New constructor for 'soft' SPI
8894Adafruit_SSD1306::Adafruit_SSD1306 (uint8_t w, uint8_t h,
89- int8_t MOSI, int8_t SCLK, int8_t DC, int8_t RST, int8_t CS) :
90- Adafruit_GFX(w, h), mosiPin(MOSI), clkPin(SCLK), dcPin(DC),
91- rstPin(RST), csPin(CS), spi(NULL ), wire(NULL ), buffer(NULL ) {
95+ int8_t mosi_pin, int8_t sclk_pin, int8_t dc_pin, int8_t rst_pin,
96+ int8_t cs_pin) : Adafruit_GFX(w, h), mosiPin(mosi_pin), clkPin(sclk_pin),
97+ dcPin(dc_pin), rstPin(rst_pin), csPin(cs_pin), spi(NULL ), wire(NULL ),
98+ buffer(NULL ) {
9299}
93100
94101// New constructor for hardware SPI
95- Adafruit_SSD1306::Adafruit_SSD1306 (uint8_t w, uint8_t h,
96- SPIClass *spi, int8_t DC , int8_t RST , int8_t CS , uint32_t bitrate) :
102+ Adafruit_SSD1306::Adafruit_SSD1306 (uint8_t w, uint8_t h, SPIClass *spi,
103+ int8_t dc_pin , int8_t rst_pin , int8_t cs_pin , uint32_t bitrate) :
97104 Adafruit_GFX(w, h), spi(spi ? spi : &SPI), wire(NULL ),
98- mosiPin(-1 ), clkPin(-1 ), dcPin(DC), rstPin(RST), csPin(CS), buffer(NULL ) {
105+ mosiPin(-1 ), clkPin(-1 ), dcPin(dc_pin), rstPin(rst_pin), csPin(cs_pin),
106+ buffer(NULL ) {
99107#ifdef SPI_HAS_TRANSACTION
100108 spiSettings = SPISettings (bitrate, MSBFIRST, SPI_MODE0);
101109#endif
102110}
103111
104112// New constructor for I2C
105- Adafruit_SSD1306::Adafruit_SSD1306 (
106- uint8_t w, uint8_t h, TwoWire *twi, int8_t RST , uint32_t res) :
107- Adafruit_GFX(w, h), wire(twi ? twi : &Wire), restoreClk(res), spi(NULL ),
108- rstPin(RST), mosiPin(-1 ), clkPin(-1 ), dcPin(-1 ), csPin(-1 ), buffer(NULL ) {
113+ Adafruit_SSD1306::Adafruit_SSD1306 (uint8_t w, uint8_t h, TwoWire *twi,
114+ int8_t rst_pin , uint32_t res) : Adafruit_GFX(w, h),
115+ wire(twi ? twi : &Wire), restoreClk(res), spi(NULL ), rstPin(rst_pin ),
116+ mosiPin(-1 ), clkPin(-1 ), dcPin(-1 ), csPin(-1 ), buffer(NULL ) {
109117}
110118
111119// Old constructor for 'soft' SPI (deprecated)
112- Adafruit_SSD1306::Adafruit_SSD1306 (
113- int8_t MOSI , int8_t SCLK , int8_t DC, int8_t RST, int8_t CS ) :
120+ Adafruit_SSD1306::Adafruit_SSD1306 (int8_t mosi_pin, int8_t sclk_pin,
121+ int8_t dc_pin , int8_t rst_pin , int8_t cs_pin ) :
114122 Adafruit_GFX(SSD1306_LCDWIDTH, SSD1306_LCDHEIGHT),
115- mosiPin(MOSI ), clkPin(SCLK ), dcPin(DC ), rstPin(RST), csPin(CS ),
116- spi(NULL ), wire(NULL ), buffer(NULL ) {
123+ mosiPin(mosi_pin ), clkPin(sclk_pin ), dcPin(dc_pin ), rstPin(rst_pin ),
124+ csPin(cs_pin), spi(NULL ), wire(NULL ), buffer(NULL ) {
117125}
118126
119127// Old constructor for hardware SPI (deprecated)
120- Adafruit_SSD1306::Adafruit_SSD1306 (int8_t DC , int8_t RST, int8_t CS) :
121- Adafruit_GFX(SSD1306_LCDWIDTH, SSD1306_LCDHEIGHT),
122- mosiPin(-1 ), clkPin(-1 ), dcPin(DC ), rstPin(RST ), csPin(CS ),
128+ Adafruit_SSD1306::Adafruit_SSD1306 (int8_t dc_pin , int8_t rst_pin,
129+ int8_t cs_pin) : Adafruit_GFX(SSD1306_LCDWIDTH, SSD1306_LCDHEIGHT),
130+ mosiPin(-1 ), clkPin(-1 ), dcPin(dc_pin ), rstPin(rst_pin ), csPin(cs_pin ),
123131 spi(&SPI), wire(NULL ), buffer(NULL ) {
124132#ifdef SPI_HAS_TRANSACTION
125133 spiSettings = SPISettings (8000000 , MSBFIRST, SPI_MODE0);
126134#endif
127135}
128136
129137// Old constructor for I2C (deprecated)
130- Adafruit_SSD1306::Adafruit_SSD1306 (int8_t RST ) :
138+ Adafruit_SSD1306::Adafruit_SSD1306 (int8_t rst_pin ) :
131139 Adafruit_GFX(SSD1306_LCDWIDTH, SSD1306_LCDHEIGHT),
132- rstPin(RST ), mosiPin(-1 ), clkPin(-1 ), dcPin(-1 ), csPin(-1 ),
140+ rstPin(rst_pin ), mosiPin(-1 ), clkPin(-1 ), dcPin(-1 ), csPin(-1 ),
133141 spi(NULL ), wire(&Wire), buffer(NULL ) {
134142}
135143
@@ -203,7 +211,7 @@ void Adafruit_SSD1306::ssd1306_commandList(const uint8_t *c, uint8_t n) {
203211
204212// ALLOCATE & INIT DISPLAY -------------------------------------------------
205213
206- bool Adafruit_SSD1306::begin (uint8_t vcs, uint8_t addr, bool reset) {
214+ boolean Adafruit_SSD1306::begin (uint8_t vcs, uint8_t addr, boolean reset) {
207215
208216 if ((!buffer) && !(buffer = (uint8_t *)malloc (WIDTH * ((HEIGHT + 7 ) / 8 ))))
209217 return false ;
@@ -418,7 +426,7 @@ void Adafruit_SSD1306::drawFastHLineInternal(
418426
419427void Adafruit_SSD1306::drawFastVLine (
420428 int16_t x, int16_t y, int16_t h, uint16_t color) {
421- bool bSwap = false ;
429+ boolean bSwap = false ;
422430 switch (rotation) {
423431 case 1 :
424432 // 90 degree rotation, swap x & y for rotation,
@@ -530,6 +538,32 @@ void Adafruit_SSD1306::drawFastVLineInternal(
530538 } // endif x in bounds
531539}
532540
541+ boolean Adafruit_SSD1306::getPixel (int16_t x, int16_t y) {
542+ if ((x >= 0 ) && (x < width ()) && (y >= 0 ) && (y < height ())) {
543+ // Pixel is in-bounds. Rotate coordinates if needed.
544+ switch (getRotation ()) {
545+ case 1 :
546+ ssd1306_swap (x, y);
547+ x = WIDTH - x - 1 ;
548+ break ;
549+ case 2 :
550+ x = WIDTH - x - 1 ;
551+ y = HEIGHT - y - 1 ;
552+ break ;
553+ case 3 :
554+ ssd1306_swap (x, y);
555+ y = HEIGHT - y - 1 ;
556+ break ;
557+ }
558+ return (buffer[x + (y / 8 ) * WIDTH] & (1 << (y & 7 )));
559+ }
560+ return false ; // Pixel out of bounds
561+ }
562+
563+ uint8_t *Adafruit_SSD1306::getBuffer (void ) {
564+ return buffer;
565+ }
566+
533567// REFRESH DISPLAY ---------------------------------------------------------
534568
535569// Push data currently in RAM to SSD1306 display
@@ -544,6 +578,9 @@ void Adafruit_SSD1306::display(void) {
544578 ssd1306_commandList (dlist1, sizeof (dlist1));
545579 ssd1306_command (WIDTH - 1 ); // Column end address
546580
581+ #if defined(ESP8266)
582+ yield ();
583+ #endif
547584 uint16_t count = WIDTH * ((HEIGHT + 7 ) / 8 );
548585 uint8_t *ptr = buffer;
549586 if (wire) { // I2C
@@ -573,7 +610,7 @@ void Adafruit_SSD1306::display(void) {
573610// startscrollright
574611// Activate a right handed scroll for rows start through stop
575612// Hint, the display is 16 rows tall. To scroll the whole display, run:
576- // display.scrollright (0x00, 0x0F)
613+ // display.startscrollright (0x00, 0x0F)
577614void Adafruit_SSD1306::startscrollright (uint8_t start, uint8_t stop){
578615 TRANSACTION_START
579616 static const uint8_t PROGMEM scrollList1a[] = {
@@ -592,9 +629,9 @@ void Adafruit_SSD1306::startscrollright(uint8_t start, uint8_t stop){
592629}
593630
594631// startscrollleft
595- // Activate a right handed scroll for rows start through stop
632+ // Activate a left handed scroll for rows start through stop
596633// Hint, the display is 16 rows tall. To scroll the whole display, run:
597- // display.scrollright (0x00, 0x0F)
634+ // display.startscrollleft (0x00, 0x0F)
598635void Adafruit_SSD1306::startscrollleft (uint8_t start, uint8_t stop){
599636 TRANSACTION_START
600637 static const uint8_t PROGMEM scrollList2a[] = {
@@ -615,7 +652,7 @@ void Adafruit_SSD1306::startscrollleft(uint8_t start, uint8_t stop){
615652// startscrolldiagright
616653// Activate a diagonal scroll for rows start through stop
617654// Hint, the display is 16 rows tall. To scroll the whole display, run:
618- // display.scrollright (0x00, 0x0F)
655+ // display.startscrolldiagright (0x00, 0x0F)
619656void Adafruit_SSD1306::startscrolldiagright (uint8_t start, uint8_t stop){
620657 TRANSACTION_START
621658 static const uint8_t PROGMEM scrollList3a[] = {
@@ -640,7 +677,7 @@ void Adafruit_SSD1306::startscrolldiagright(uint8_t start, uint8_t stop){
640677// startscrolldiagleft
641678// Activate a diagonal scroll for rows start through stop
642679// Hint, the display is 16 rows tall. To scroll the whole display, run:
643- // display.scrollright (0x00, 0x0F)
680+ // display.startscrolldiagleft (0x00, 0x0F)
644681void Adafruit_SSD1306::startscrolldiagleft (uint8_t start, uint8_t stop){
645682 TRANSACTION_START
646683 static const uint8_t PROGMEM scrollList4a[] = {
@@ -670,7 +707,7 @@ void Adafruit_SSD1306::stopscroll(void){
670707
671708// OTHER HARDWARE SETTINGS -------------------------------------------------
672709
673- void Adafruit_SSD1306::invertDisplay (bool i) {
710+ void Adafruit_SSD1306::invertDisplay (boolean i) {
674711 TRANSACTION_START
675712 ssd1306_command (i ? SSD1306_INVERTDISPLAY : SSD1306_NORMALDISPLAY);
676713 TRANSACTION_END
0 commit comments