A derived version of the BSD licensed Adafrut GFX library for the SSD1306 controller for an OLED 128x32 or 128x64 display using SPI or I2C.
Fork of Adafruit_GFX by
Revision 17:bbd6430a27ca, committed 2016-08-15
- Comitter:
- renanlino
- Date:
- Mon Aug 15 18:38:35 2016 +0000
- Parent:
- 16:7fb1d4d3525d
- Commit message:
- working: basic oled, RTC w/r, basic nodeMCU comm, drawXBM
Changed in this revision
--- a/Adafruit_GFX_Config.h Tue Nov 11 22:08:20 2014 +0000 +++ b/Adafruit_GFX_Config.h Mon Aug 15 18:38:35 2016 +0000 @@ -5,7 +5,7 @@ //#define NO_SPLASH_ADAFRUIT // Uncomment this to enable all functionality -//#define GFX_WANT_ABSTRACTS +#define GFX_WANT_ABSTRACTS // Uncomment this to enable only runtime font scaling, without all the rest of the Abstracts //#define GFX_SIZEABLE_TEXT
--- a/Adafruit_SSD1306.cpp Tue Nov 11 22:08:20 2014 +0000 +++ b/Adafruit_SSD1306.cpp Mon Aug 15 18:38:35 2016 +0000 @@ -149,6 +149,10 @@ std::fill(buffer.begin(),buffer.end(),0); } +void Adafruit_SSD1306::print(string text) { + for (string::iterator c = text.begin(); c != text.end(); c++) this->writeChar( (uint8_t) *c ); +} + void Adafruit_SSD1306::splash(void) { #ifndef NO_SPLASH_ADAFRUIT @@ -228,3 +232,18 @@ ); #endif } + +void Adafruit_SSD1306::drawXBitmap(int16_t x, int16_t y, + const uint8_t *bitmap, int16_t w, int16_t h, uint16_t color) { + + int16_t i, j, byteWidth = (w + 7) / 8; + uint8_t byte; + + for(j=0; j<h; j++) { + for(i=0; i<w; i++ ) { + if(i & 7) byte >>= 1; + else byte = pgm_read_byte(bitmap + j * byteWidth + i / 8); + if(byte & 0x01) drawPixel(x+i, y+j, color); + } + } +}
--- a/Adafruit_SSD1306.h Tue Nov 11 22:08:20 2014 +0000 +++ b/Adafruit_SSD1306.h Mon Aug 15 18:38:35 2016 +0000 @@ -25,10 +25,15 @@ #include "mbed.h" #include "Adafruit_GFX.h" +#include <string> #include <vector> #include <algorithm> +#ifndef pgm_read_byte + #define pgm_read_byte(addr) (*(const unsigned char *)(addr)) +#endif + // A DigitalOut sub-class that provides a constructed default state class DigitalOut2 : public DigitalOut { @@ -58,6 +63,9 @@ }; void begin(uint8_t switchvcc = SSD1306_SWITCHCAPVCC); + void print(string c); + void drawXBitmap(int16_t x, int16_t y, const uint8_t *bitmap, + int16_t w, int16_t h, uint16_t color); // These must be implemented in the derived transport driver virtual void command(uint8_t c) = 0; @@ -72,6 +80,8 @@ void display(); /// Fill the buffer with the AdaFruit splash screen. virtual void splash(); + + protected: virtual void sendDisplayBuffer() = 0; @@ -195,6 +205,7 @@ buff[1] = c; mi2c.write(mi2cAddress, buff, sizeof(buff)); }; + protected: virtual void sendDisplayBuffer()