Modified Adafruit GFX library with support for selecting displays using an 74HC4067 Analog Multiplexer
Fork of Adafruit_GFX by
Revision 17:bf0e4072b06d, committed 2015-01-30
- Comitter:
- jimconner
- Date:
- Fri Jan 30 00:00:56 2015 +0000
- Parent:
- 16:7fb1d4d3525d
- Child:
- 18:45467135ad3b
- Commit message:
- Added support for I2C mux using a single IO pin... Will add support for more channels later.
Changed in this revision
--- a/Adafruit_GFX_Config.h Tue Nov 11 22:08:20 2014 +0000 +++ b/Adafruit_GFX_Config.h Fri Jan 30 00:00:56 2015 +0000 @@ -2,10 +2,10 @@ #define _ADAFRUIT_GFX_CONFIG_H_ // Uncomment this to turn off the builtin splash -//#define NO_SPLASH_ADAFRUIT +#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 Fri Jan 30 00:00:56 2015 +0000 @@ -59,6 +59,7 @@ // turn on VCC (9V?) command(SSD1306_DISPLAYOFF); + command(SSD1306_SETDISPLAYCLOCKDIV); command(0x80); // the suggested ratio 0x80 @@ -97,6 +98,7 @@ command(SSD1306_NORMALDISPLAY); command(SSD1306_DISPLAYON); + } // Set a single pixel
--- a/Adafruit_SSD1306.h Tue Nov 11 22:08:20 2014 +0000 +++ b/Adafruit_SSD1306.h Fri Jan 30 00:00:56 2015 +0000 @@ -215,6 +215,81 @@ I2C &mi2c; uint8_t mi2cAddress; + +}; + +/** Jim's modified I2C SSD1306 display driver transport class + * which also toggles some gpio lines to control an CD4067 analog mux + */ +class mux_SSD1306_I2c : public Adafruit_SSD1306 +{ +public: + #define SSD_I2C_ADDRESS 0x78 + /** Create a SSD1306 I2C transport display driver instance with the specified RST pin name, the I2C address, as well as the display dimensions + * + * Required parameters + * @param i2c - A reference to an initialized I2C object + * @param RST - The Reset pin name + * @param MUX - The pin for controlling the CD4067 multiplier + * @param MUXVal - The value that the MUX pin should be set to for a given display + * + * Optional parameters + * @param i2cAddress - The i2c address of the display + * @param rawHeight - The vertical number of pixels for the display, defaults to 32 + * @param rawWidth - The horizonal number of pixels for the display, defaults to 128 + */ + mux_SSD1306_I2c(I2C &i2c, PinName RST, PinName MUX, uint8_t MUXval = 1, uint8_t i2cAddress = SSD_I2C_ADDRESS, uint8_t rawHeight = 32, uint8_t rawWidth = 128) + : Adafruit_SSD1306(RST, rawHeight, rawWidth) + , mi2c(i2c) + , mi2cAddress(i2cAddress) + , mux(MUX) + , muxval(MUXval) + { + begin(); + splash(); + display(); + }; + + virtual void command(uint8_t c) + { + char buff[2]; + buff[0] = 0; // Command Mode + buff[1] = c; + mux = muxval; + mi2c.write(mi2cAddress, buff, sizeof(buff)); + } + + virtual void data(uint8_t c) + { + char buff[2]; + buff[0] = 0x40; // Data Mode + buff[1] = c; + mux = muxval; + mi2c.write(mi2cAddress, buff, sizeof(buff)); + }; + +protected: + virtual void sendDisplayBuffer() + { + char buff[17]; + buff[0] = 0x40; // Data Mode + + // send display buffer in 16 byte chunks + for(uint16_t i=0, q=buffer.size(); i<q; i+=16 ) + { uint8_t x ; + + // TODO - this will segfault if buffer.size() % 16 != 0 + for(x=1; x<sizeof(buff); x++) + buff[x] = buffer[i+x-1]; + mux = muxval; + mi2c.write(mi2cAddress, buff, sizeof(buff)); + } + }; + + I2C &mi2c; + uint8_t mi2cAddress; + DigitalOut mux; + uint8_t muxval; }; #endif \ No newline at end of file