i2c version has an offset due to wrong copy of temp buffer to display buffer, fixed in Adafruit_SSD1306.h
Dependents: ezSBC_MPU9250 Test_OLED_Display untodoenuno OledI2CDisplay ... more
Fork of Adafruit_GFX by
Revision 20:04822be0efcd, committed 2017-07-24
- Comitter:
- JojoS
- Date:
- Mon Jul 24 11:09:33 2017 +0000
- Parent:
- 19:73007a24ddaa
- Commit message:
- Added driver for UC1601S;
Changed in this revision
--- a/Adafruit_GFX_Config.h Sun Nov 06 15:31:50 2016 +0000 +++ b/Adafruit_GFX_Config.h Mon Jul 24 11:09:33 2017 +0000 @@ -2,13 +2,14 @@ #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 +// saves about 600 Bytes #define GFX_WANT_ABSTRACTS // Uncomment this to enable only runtime font scaling, without all the rest of the Abstracts //#define GFX_SIZEABLE_TEXT -#endif \ No newline at end of file +#endif
--- a/Adafruit_SSD1306.cpp Sun Nov 06 15:31:50 2016 +0000 +++ b/Adafruit_SSD1306.cpp Mon Jul 24 11:09:33 2017 +0000 @@ -50,18 +50,26 @@ #define SSD1306_CHARGEPUMP 0x8D #define SSD1306_SETPAGESTARTADDRESS 0xB0 +Adafruit_SSD1306::Adafruit_SSD1306(PinName reset, uint8_t rawHeight, uint8_t rawWidth, bool flipVertical) + : Adafruit_GFX(rawWidth,rawHeight) + , _reset(reset,false) + , _flipVertical(flipVertical) +{ + buffer.resize(rawHeight * rawWidth / 8); +} + void Adafruit_SSD1306::begin(uint8_t vccstate) { - if (rst.is_connected()) { // reset input is not present on every SSD1306 display board, so usage is optional - rst = 1; + if (_reset.is_connected()) { // reset input is not present on every SSD1306 display board, so usage is optional + _reset = 1; // VDD (3.3V) goes high at start, lets just chill for a ms wait_ms(1); // bring reset low - rst = 0; + _reset = 0; // wait 10ms wait_ms(10); // bring out of reset - rst = 1; + _reset = 1; // turn on VCC (9V?) } @@ -85,7 +93,7 @@ command(0x00); // 0x0 act like ks0108 - if (flipVertical) { + if (_flipVertical) { command(SSD1306_SEGREMAP | 0x0); command(SSD1306_COMSCANINC); } else { @@ -152,6 +160,19 @@ command(i ? SSD1306_INVERTDISPLAY : SSD1306_NORMALDISPLAY); } +void Adafruit_SSD1306::flipVertical(bool flip) +{ + _flipVertical = flip; + + if (_flipVertical) { + command(SSD1306_SEGREMAP | 0x0); + command(SSD1306_COMSCANINC); + } else { + command(SSD1306_SEGREMAP | 0x1); + command(SSD1306_COMSCANDEC); // flip vertically + } +} + // Send the display buffer out to the display void Adafruit_SSD1306::display(void) { @@ -170,7 +191,7 @@ void Adafruit_SSD1306::splash(void) { #ifndef NO_SPLASH_ADAFRUIT - uint8_t adaFruitLogo[64 * 128 / 8] = { + const uint8_t adaFruitLogo[64 * 128 / 8] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, @@ -245,3 +266,104 @@ ); #endif } + +/* + * + * SPI specific implementation + * + */ + +Adafruit_SSD1306_Spi::Adafruit_SSD1306_Spi(SPI &spi, PinName DC, PinName RST, PinName CS, uint8_t rawHieght, uint8_t rawWidth, bool flipVertical) +: Adafruit_SSD1306(RST, rawHieght, rawWidth, flipVertical) +, cs(CS,true) +, dc(DC,false) +, mspi(spi) +{ + begin(); + splash(); + display(); +} + +void Adafruit_SSD1306_Spi::command(uint8_t c) +{ + cs = 1; + dc = 0; + cs = 0; + mspi.write(c); + cs = 1; +} + +void Adafruit_SSD1306_Spi::data(uint8_t c) +{ + cs = 1; + dc = 1; + cs = 0; + mspi.write(c); + cs = 1; +}; + +void Adafruit_SSD1306_Spi::sendDisplayBuffer() +{ + cs = 1; + dc = 1; + cs = 0; + + for(uint16_t i=0, q=buffer.size(); i<q; i++) + mspi.write(buffer[i]); + + if(height() == 32) + { + for(uint16_t i=0, q=buffer.size(); i<q; i++) + mspi.write(0); + } + + cs = 1; +} + +/* + * + * I2C specific implementation + * + */ + +Adafruit_SSD1306_I2c::Adafruit_SSD1306_I2c(I2C &i2c, PinName RST, uint8_t i2cAddress, uint8_t rawHeight, uint8_t rawWidth, bool flipVertical) + : Adafruit_SSD1306(RST, rawHeight, rawWidth, flipVertical) + , mi2c(i2c) + , mi2cAddress(i2cAddress) +{ + begin(); + splash(); + display(); +} + +void Adafruit_SSD1306_I2c::command(uint8_t c) +{ + char buff[2]; + buff[0] = 0; // Command Mode + buff[1] = c; + mi2c.write(mi2cAddress, buff, sizeof(buff)); +} + +void Adafruit_SSD1306_I2c::data(uint8_t c) +{ + char buff[2]; + buff[0] = 0x40; // Data Mode + buff[1] = c; + mi2c.write(mi2cAddress, buff, sizeof(buff)); +} + +void Adafruit_SSD1306_I2c::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]; + mi2c.write(mi2cAddress, buff, sizeof(buff)); + } +}
--- a/Adafruit_SSD1306.h Sun Nov 06 15:31:50 2016 +0000 +++ b/Adafruit_SSD1306.h Mon Jul 24 11:09:33 2017 +0000 @@ -1,212 +1,133 @@ -/********************************************************************* -This is a library for our Monochrome OLEDs based on SSD1306 drivers - - Pick one up today in the adafruit shop! - ------> http://www.adafruit.com/category/63_98 - -These displays use SPI to communicate, 4 or 5 pins are required to -interface - -Adafruit invests time and resources providing this open source code, -please support Adafruit and open-source hardware by purchasing -products from Adafruit! - -Written by Limor Fried/Ladyada for Adafruit Industries. -BSD license, check license.txt for more information -All text above, and the splash screen must be included in any redistribution -*********************************************************************/ - -/* - * Modified by Neal Horman 7/14/2012 for use in mbed - */ - -#ifndef _ADAFRUIT_SSD1306_H_ -#define _ADAFRUIT_SSD1306_H_ - -#include "mbed.h" -#include "Adafruit_GFX.h" - -#include <vector> -#include <algorithm> - -#define SSD1306_EXTERNALVCC 0x1 -#define SSD1306_SWITCHCAPVCC 0x2 - -/** The pure base class for the SSD1306 display driver. - * - * You should derive from this for a new transport interface type, - * such as the SPI and I2C drivers. - */ -class Adafruit_SSD1306 : public Adafruit_GFX -{ -public: - Adafruit_SSD1306(PinName RST, uint8_t rawHeight = 32, uint8_t rawWidth = 128, bool _flipVertical=false) - : Adafruit_GFX(rawWidth,rawHeight) - , rst(RST,false) - , flipVertical(_flipVertical) - { - buffer.resize(rawHeight * rawWidth / 8); - }; - - void begin(uint8_t switchvcc = SSD1306_SWITCHCAPVCC); - - // These must be implemented in the derived transport driver - virtual void command(uint8_t c) = 0; - virtual void data(uint8_t c) = 0; - virtual void drawPixel(int16_t x, int16_t y, uint16_t color); - - /// Clear the display buffer - void clearDisplay(void); - virtual void invertDisplay(bool i); - - /// Cause the display to be updated with the buffer content. - void display(); - /// Fill the buffer with the AdaFruit splash screen. - virtual void splash(); - -protected: - virtual void sendDisplayBuffer() = 0; - DigitalOut rst; - bool flipVertical; - - // the memory buffer for the LCD - std::vector<uint8_t> buffer; -}; - - -/** This is the SPI SSD1306 display driver transport class - * - */ -class Adafruit_SSD1306_Spi : public Adafruit_SSD1306 -{ -public: - /** Create a SSD1306 SPI transport display driver instance with the specified DC, RST, and CS pins, as well as the display dimentions - * - * Required parameters - * @param spi - a reference to an initialized SPI object - * @param DC (Data/Command) pin name - * @param RST (Reset) pin name - * @param CS (Chip Select) pin name - * - * Optional parameters - * @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 - */ - Adafruit_SSD1306_Spi(SPI &spi, PinName DC, PinName RST, PinName CS, uint8_t rawHieght = 32, uint8_t rawWidth = 128, bool flipVertical = false) - : Adafruit_SSD1306(RST, rawHieght, rawWidth, flipVertical) - , cs(CS,true) - , dc(DC,false) - , mspi(spi) - { - begin(); - splash(); - display(); - }; - - virtual void command(uint8_t c) - { - cs = 1; - dc = 0; - cs = 0; - mspi.write(c); - cs = 1; - }; - - virtual void data(uint8_t c) - { - cs = 1; - dc = 1; - cs = 0; - mspi.write(c); - cs = 1; - }; - -protected: - virtual void sendDisplayBuffer() - { - cs = 1; - dc = 1; - cs = 0; - - for(uint16_t i=0, q=buffer.size(); i<q; i++) - mspi.write(buffer[i]); - - if(height() == 32) - { - for(uint16_t i=0, q=buffer.size(); i<q; i++) - mspi.write(0); - } - - cs = 1; - }; - - DigitalOut cs, dc; - SPI &mspi; -}; - -/** This is the I2C SSD1306 display driver transport class - * - */ -class Adafruit_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 - * - * 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 - */ - Adafruit_SSD1306_I2c(I2C &i2c, PinName RST, uint8_t i2cAddress = SSD_I2C_ADDRESS, uint8_t rawHeight = 32, uint8_t rawWidth = 128, bool flipVertical = false) - : Adafruit_SSD1306(RST, rawHeight, rawWidth, flipVertical) - , mi2c(i2c) - , mi2cAddress(i2cAddress) - { - begin(); - splash(); - display(); - }; - - virtual void command(uint8_t c) - { - char buff[2]; - buff[0] = 0; // Command Mode - buff[1] = c; - mi2c.write(mi2cAddress, buff, sizeof(buff)); - } - - virtual void data(uint8_t c) - { - char buff[2]; - buff[0] = 0x40; // Data Mode - buff[1] = c; - 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]; - mi2c.write(mi2cAddress, buff, sizeof(buff)); - } - }; - - I2C &mi2c; - uint8_t mi2cAddress; -}; - -#endif \ No newline at end of file +/********************************************************************* +This is a library for our Monochrome OLEDs based on SSD1306 drivers + + Pick one up today in the adafruit shop! + ------> http://www.adafruit.com/category/63_98 + +These displays use SPI to communicate, 4 or 5 pins are required to +interface + +Adafruit invests time and resources providing this open source code, +please support Adafruit and open-source hardware by purchasing +products from Adafruit! + +Written by Limor Fried/Ladyada for Adafruit Industries. +BSD license, check license.txt for more information +All text above, and the splash screen must be included in any redistribution +*********************************************************************/ + +/* + * Modified by Neal Horman 7/14/2012 for use in mbed + */ + +#ifndef _ADAFRUIT_SSD1306_H_ +#define _ADAFRUIT_SSD1306_H_ + +#include "mbed.h" +#include "Adafruit_GFX.h" + +#include <vector> +#include <algorithm> + +#define SSD1306_EXTERNALVCC 0x1 +#define SSD1306_SWITCHCAPVCC 0x2 + +/** The pure base class for the SSD1306 display driver. + * + * You should derive from this for a new transport interface type, + * such as the SPI and I2C drivers. + */ +class Adafruit_SSD1306 : public Adafruit_GFX +{ +public: + Adafruit_SSD1306(PinName reset, uint8_t rawHeight = 32, uint8_t rawWidth = 128, bool flipVertical=false); + + // start display sequence + void begin(uint8_t switchvcc = SSD1306_SWITCHCAPVCC); + + // These must be implemented in the derived transport driver + virtual void command(uint8_t c) = 0; + virtual void data(uint8_t c) = 0; + virtual void drawPixel(int16_t x, int16_t y, uint16_t color); + + /// Clear the display buffer + void clearDisplay(void); + virtual void invertDisplay(bool i); + void flipVertical(bool flip); + + /// Cause the display to be updated with the buffer content. + void display(); + /// Fill the buffer with the AdaFruit splash screen. + virtual void splash(); + +protected: + virtual void sendDisplayBuffer() = 0; + DigitalOut _reset; + bool _flipVertical; + + // the memory buffer for the LCD + std::vector<uint8_t> buffer; +}; + + +/** This is the SPI SSD1306 display driver transport class + * + */ +class Adafruit_SSD1306_Spi : public Adafruit_SSD1306 +{ +public: + /** Create a SSD1306 SPI transport display driver instance with the specified DC, RST, and CS pins, as well as the display dimentions + * + * Required parameters + * @param spi - a reference to an initialized SPI object + * @param DC (Data/Command) pin name + * @param RST (Reset) pin name + * @param CS (Chip Select) pin name + * + * Optional parameters + * @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 + */ + Adafruit_SSD1306_Spi(SPI &spi, PinName DC, PinName RST, PinName CS, uint8_t rawHieght = 32, uint8_t rawWidth = 128, bool flipVertical = false); + + virtual void command(uint8_t c); + virtual void data(uint8_t c); + +protected: + virtual void sendDisplayBuffer(); + + DigitalOut cs, dc; + SPI &mspi; +}; + +/** This is the I2C SSD1306 display driver transport class + * + */ +class Adafruit_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 + * + * 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 + */ + Adafruit_SSD1306_I2c(I2C &i2c, PinName RST, uint8_t i2cAddress = SSD_I2C_ADDRESS, uint8_t rawHeight = 32, uint8_t rawWidth = 128, bool flipVertical = false); + + virtual void command(uint8_t c); + virtual void data(uint8_t c); + +protected: + virtual void sendDisplayBuffer(); + + I2C &mi2c; + uint8_t mi2cAddress; +}; + +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Adafruit_UC1601S.cpp Mon Jul 24 11:09:33 2017 +0000 @@ -0,0 +1,237 @@ +/********************************************************************* + This is a library for our Monochrome OLEDs based on SSD1306 drivers + + Pick one up today in the adafruit shop! + ------> http://www.adafruit.com/category/63_98 + + These displays use SPI to communicate, 4 or 5 pins are required to + interface + + Adafruit invests time and resources providing this open source code, + please support Adafruit and open-source hardware by purchasing + products from Adafruit! + + Written by Limor Fried/Ladyada for Adafruit Industries. + BSD license, check license.txt for more information + All text above, and the splash screen below must be included in any redistribution + *********************************************************************/ + +/* + * Modified by JojoS 03/07/2015 + * add flipVertical option to constructor + * add use of 'rst' is optional, maybe NC in constructor + * add command SSD1306_SETPAGESTARTADDRESS to reset page start address (important when no hardware reset is uesed) + */ + +#include "mbed.h" +#include "Adafruit_UC1601S.h" + +Adafruit_UC1601S::Adafruit_UC1601S(PinName reset, uint8_t rawHeight, uint8_t rawWidth, bool flipVertical) + : Adafruit_GFX(rawWidth, rawHeight) + , _reset(reset, false) + , _flipVertical(flipVertical) +{ + // display memory is organized in 1 byte = 8 columns + int heightBytes = rawHeight / 8; + if (rawHeight % 8) // correction if height is not byte aligned + heightBytes++; + buffer.resize(rawWidth * heightBytes); +} + +void Adafruit_UC1601S::begin() { + if (_reset.is_connected()) {// reset input is not present on every UC1601S display board, so usage is optional + _reset = 1; + // VDD (3.3V) goes high at start, lets just chill for a ms + wait_ms(1); + // bring reset low + _reset = 0; + // wait 10ms + wait_ms(10); + // bring out of reset + _reset = 1; + // turn on VCC (9V?) + } + + command(LCD_SET_TEMP_COMP | 0b00); // Set Temperature Comp. TC[1:0] + command(LCD_SET_POWER_CTRL | 0b110); // Set Power Control PC[2:0] + command(LCD_SET_LINE_ADDR | 0); // Set Scroll Line SL[5:0] + command(LCD_SET_BIAS); // Set VBIAS Potentiometer (Double byte command) + command(0xC0); // BIAS value + command(LCD_SET_PARTITIAL_CTRL | 0); + command(LCD_SET_RAM_ADDRESS_CTRL | 0b001); // + command(LCD_SET_FRAME_RATE | 0); // Framerate 0: 80 fps 1: 100 fps + command(LCD_SET_MAPPING_CTRL | (_flipVertical ? 0b000 : 0b100));// flip vertical / horizontal + command(LCD_SET_BIAS_RATIO | 0); // 0: 6 1: 7 2: 8 3: 9 + command(LCD_SET_COM_END); + command(21); // Rows - 1 + command(LCD_ENABLE_DISPLAY | 1); // enable display) +} + +// Set a single pixel +void Adafruit_UC1601S::drawPixel(int16_t x, int16_t y, uint16_t color) { + if ((x < 0) || (x >= width()) || (y < 0) || (y >= height())) + return; + + // check rotation, move pixel around if necessary + switch (getRotation()) { + case 1: + swap(x, y); + x = _rawWidth - x - 1; + break; + case 2: + x = _rawWidth - x - 1; + y = _rawHeight - y - 1; + break; + case 3: + swap(x, y); + y = _rawHeight - y - 1; + break; + } + + // x is which column + if (color == WHITE) + buffer[x + (y / 8) * _rawWidth] |= _BV((y % 8)); + else + // else black + buffer[x + (y / 8) * _rawWidth] &= ~_BV((y % 8)); +} + +void Adafruit_UC1601S::invertDisplay(bool i) { + command(i ? LCD_INVERT_DISPLAY | 1 : LCD_INVERT_DISPLAY); +} + +void Adafruit_UC1601S::flipVertical(bool flip) { + _flipVertical = flip; + if (flip) { + command(LCD_SET_MAPPING_CTRL | 0b000);// flip vertical / horizontal + command(LCD_SET_RAM_ADDRESS_CTRL | 0b101); // + command(LCD_SET_COM_END); + command(21); // Rows - 1 + } else { + command(LCD_SET_MAPPING_CTRL | 0b100);// flip vertical / horizontal + command(LCD_SET_RAM_ADDRESS_CTRL | 0b001); // + command(LCD_SET_COM_END); + command(21); // Rows - 1 + } +} + +// Send the display buffer out to the display +void Adafruit_UC1601S::display(void) { + sendDisplayBuffer(); +} + +// Clear the display buffer. Requires a display() call at some point afterwards +void Adafruit_UC1601S::clearDisplay(void) { + std::fill(buffer.begin(), buffer.end(), 0); +} + +void Adafruit_UC1601S::splash(void) { +#ifndef NO_SPLASH_ADAFRUIT + const uint8_t adaFruitLogo[64 * 128 / 8] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, + 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x80, 0x80, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC, 0xF8, 0xE0, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, + 0x80, 0x80, 0x00, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0xFF, + 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00, + 0x80, 0xFF, 0xFF, 0x80, 0x80, 0x00, 0x80, 0x80, 0x00, 0x80, 0x80, 0x80, 0x80, 0x00, 0x80, 0x80, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00, 0x8C, 0x8E, 0x84, 0x00, 0x00, 0x80, 0xF8, + 0xF8, 0xF8, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xE0, 0xE0, 0xC0, 0x80, + 0x00, 0xE0, 0xFC, 0xFE, 0xFF, 0xFF, 0xFF, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0xFF, 0xC7, 0x01, 0x01, + 0x01, 0x01, 0x83, 0xFF, 0xFF, 0x00, 0x00, 0x7C, 0xFE, 0xC7, 0x01, 0x01, 0x01, 0x01, 0x83, 0xFF, + 0xFF, 0xFF, 0x00, 0x38, 0xFE, 0xC7, 0x83, 0x01, 0x01, 0x01, 0x83, 0xC7, 0xFF, 0xFF, 0x00, 0x00, + 0x01, 0xFF, 0xFF, 0x01, 0x01, 0x00, 0xFF, 0xFF, 0x07, 0x01, 0x01, 0x01, 0x00, 0x00, 0x7F, 0xFF, + 0x80, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x7F, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x01, 0xFF, + 0xFF, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x03, 0x0F, 0x3F, 0x7F, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xE7, 0xC7, 0xC7, 0x8F, + 0x8F, 0x9F, 0xBF, 0xFF, 0xFF, 0xC3, 0xC0, 0xF0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC, 0xFC, 0xFC, + 0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0xF8, 0xF8, 0xF0, 0xF0, 0xE0, 0xC0, 0x00, 0x01, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x01, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x03, 0x03, 0x01, 0x01, + 0x03, 0x01, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x03, 0x03, 0x01, 0x01, 0x03, 0x03, 0x00, 0x00, + 0x00, 0x03, 0x03, 0x00, 0x00, 0x00, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x01, 0x00, 0x00, 0x00, 0x01, 0x03, 0x01, 0x00, 0x00, 0x00, 0x03, + 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + // 128x32^^^ 128x64vvv + 0x00, 0x00, 0x00, 0x80, 0xC0, 0xE0, 0xF0, 0xF9, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x3F, 0x1F, 0x0F, + 0x87, 0xC7, 0xF7, 0xFF, 0xFF, 0x1F, 0x1F, 0x3D, 0xFC, 0xF8, 0xF8, 0xF8, 0xF8, 0x7C, 0x7D, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x3F, 0x0F, 0x07, 0x00, 0x30, 0x30, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xFE, 0xFE, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xC0, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0xC0, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x7F, 0x3F, 0x1F, + 0x0F, 0x07, 0x1F, 0x7F, 0xFF, 0xFF, 0xF8, 0xF8, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xF8, 0xE0, + 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0xFE, 0x00, 0x00, + 0x00, 0xFC, 0xFE, 0xFC, 0x0C, 0x06, 0x06, 0x0E, 0xFC, 0xF8, 0x00, 0x00, 0xF0, 0xF8, 0x1C, 0x0E, + 0x06, 0x06, 0x06, 0x0C, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xFE, 0xFE, 0x00, 0x00, 0x00, 0x00, 0xFC, + 0xFE, 0xFC, 0x00, 0x18, 0x3C, 0x7E, 0x66, 0xE6, 0xCE, 0x84, 0x00, 0x00, 0x06, 0xFF, 0xFF, 0x06, + 0x06, 0xFC, 0xFE, 0xFC, 0x0C, 0x06, 0x06, 0x06, 0x00, 0x00, 0xFE, 0xFE, 0x00, 0x00, 0xC0, 0xF8, + 0xFC, 0x4E, 0x46, 0x46, 0x46, 0x4E, 0x7C, 0x78, 0x40, 0x18, 0x3C, 0x76, 0xE6, 0xCE, 0xCC, 0x80, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x07, 0x0F, 0x1F, 0x1F, 0x3F, 0x3F, 0x3F, 0x3F, 0x1F, 0x0F, 0x03, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x00, 0x00, + 0x00, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x00, 0x00, 0x03, 0x07, 0x0E, 0x0C, + 0x18, 0x18, 0x0C, 0x06, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x01, 0x0F, 0x0E, 0x0C, 0x18, 0x0C, 0x0F, + 0x07, 0x01, 0x00, 0x04, 0x0E, 0x0C, 0x18, 0x0C, 0x0F, 0x07, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x00, + 0x00, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x07, + 0x07, 0x0C, 0x0C, 0x18, 0x1C, 0x0C, 0x06, 0x06, 0x00, 0x04, 0x0E, 0x0C, 0x18, 0x0C, 0x0F, 0x07, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + }; + + std::copy( + &adaFruitLogo[0] + , &adaFruitLogo[0] + (_rawHeight == 32 ? sizeof(adaFruitLogo)/2 : sizeof(adaFruitLogo)) + , buffer.begin() + ); +#endif +} + +/* + * + * I2C specific implementation + * +*/ + +Adafruit_UC1601S_I2c::Adafruit_UC1601S_I2c(I2C &i2c, PinName reset, + uint8_t i2cAddress, uint8_t rawHeight, + uint8_t rawWidth, bool flipVertical) : + Adafruit_UC1601S(reset, rawHeight, rawWidth, flipVertical), mi2c(i2c), mi2cAddress( + i2cAddress) { + begin(); + splash(); + display(); +} + +void Adafruit_UC1601S_I2c::sendDisplayBuffer() { + command(LCD_SET_PAGE_ADDR | 0); + command(LCD_SET_COLUMN_ADDR_LSB | 0); + command(LCD_SET_COLUMN_ADDR_MSB | 0); + + data(&buffer[0], buffer.size()); +} + +void Adafruit_UC1601S_I2c::command(uint8_t c) { + mi2c.write(mi2cAddress, (const char*) &c, 1); +} + +void Adafruit_UC1601S_I2c::data(const uint8_t *c, int count) { + mi2c.write(mi2cAddress + 2, (const char*) c, count); +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Adafruit_UC1601S.h Mon Jul 24 11:09:33 2017 +0000 @@ -0,0 +1,118 @@ +/********************************************************************* +This is a library for our Monochrome OLEDs based on SSD1306 drivers + + +Adafruit invests time and resources providing this open source code, +please support Adafruit and open-source hardware by purchasing +products from Adafruit! + +Written by Limor Fried/Ladyada for Adafruit Industries. +BSD license, check license.txt for more information +All text above, and the splash screen must be included in any redistribution +*********************************************************************/ + +/* + * Modified by JojoS for use in mbed + */ + +#ifndef _ADAFRUIT_UC1601S_H_ +#define _ADAFRUIT_UC1601S_H_ + +#include "mbed.h" +#include "Adafruit_GFX.h" + +#include <vector> +#include <algorithm> + +/** The pure base class for the UC1601S display driver. + * + * You should derive from this for a new transport interface type, + * such as the SPI and I2C drivers. + */ + +#define LCD_SET_COLUMN_ADDR_LSB 0x00 +#define LCD_SET_COLUMN_ADDR_MSB 0x10 +#define LCD_SET_TEMP_COMP 0x24 +#define LCD_SET_POWER_CTRL 0x28 +#define LCD_SET_LINE_ADDR 0x40 +#define LCD_SET_PAGE_ADDR 0xB0 +#define LCD_SET_BIAS 0x81 +#define LCD_SET_BIAS_RATIO 0xE8 +#define LCD_SET_PARTITIAL_CTRL 0x84 +#define LCD_ENABLE_DISPLAY 0xAE +#define LCD_ENABLE_ALL 0xA5 +#define LCD_INVERT_DISPLAY 0xA6 +#define LCD_SYSTEM_RESET 0xE2 +#define LCD_SET_RAM_ADDRESS_CTRL 0x88 +#define LCD_SET_FRAME_RATE 0xA0 +#define LCD_SET_MAPPING_CTRL 0xC0 +#define LCD_SET_COM_END 0xF1 + + +class Adafruit_UC1601S : public Adafruit_GFX +{ +public: + Adafruit_UC1601S(PinName reset, uint8_t rawHeight = 22, uint8_t rawWidth = 132, bool flipVertical=false); + + // start sequence + void begin(); + + // These must be implemented in the derived transport driver + virtual void command(uint8_t c) = 0; + virtual void data(const uint8_t *c, int count) = 0; + virtual void drawPixel(int16_t x, int16_t y, uint16_t color); + + /// Clear the display buffer + void clearDisplay(void); + virtual void invertDisplay(bool i); + void flipVertical(bool flip); + + /// Cause the display to be updated with the buffer content. + void display(); + /// Fill the buffer with the AdaFruit splash screen. + virtual void splash(); + +protected: + virtual void sendDisplayBuffer() = 0; + DigitalOut _reset; + bool _flipVertical; + + // the memory buffer for the LCD + std::vector<uint8_t> buffer; +}; + + + +/** This is the I2C UC1601S display driver transport class + * + */ + +#define I2C_ADDRESS_CMD (0x38 << 1) +#define I2C_ADDRESS_DATA (0x39 << 1) + +class Adafruit_UC1601S_I2c : public Adafruit_UC1601S +{ +public: + /** 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 + * + * Optional parameters + * @param i2cAddress - The i2c address of the display + * @param rawHeight - The vertical number of pixels for the display, defaults to 22 + * @param rawWidth - The horizonal number of pixels for the display, defaults to 128 + */ + Adafruit_UC1601S_I2c(I2C &i2c, PinName reset, uint8_t i2cAddress = I2C_ADDRESS_CMD, uint8_t rawHeight = 22, uint8_t rawWidth = 132, bool flipVertical = false); + + virtual void command(uint8_t c); + virtual void data(const uint8_t *c, int count); + +protected: + virtual void sendDisplayBuffer(); + I2C &mi2c; + uint8_t mi2cAddress; +}; + +#endif