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 Neal Horman

Committer:
JojoS
Date:
Mon Jul 24 11:09:33 2017 +0000
Revision:
20:04822be0efcd
Parent:
18:6aa925f254d6
Added driver for UC1601S;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
JojoS 20:04822be0efcd 1 /*********************************************************************
JojoS 20:04822be0efcd 2 This is a library for our Monochrome OLEDs based on SSD1306 drivers
JojoS 20:04822be0efcd 3
JojoS 20:04822be0efcd 4 Pick one up today in the adafruit shop!
JojoS 20:04822be0efcd 5 ------> http://www.adafruit.com/category/63_98
JojoS 20:04822be0efcd 6
JojoS 20:04822be0efcd 7 These displays use SPI to communicate, 4 or 5 pins are required to
JojoS 20:04822be0efcd 8 interface
JojoS 20:04822be0efcd 9
JojoS 20:04822be0efcd 10 Adafruit invests time and resources providing this open source code,
JojoS 20:04822be0efcd 11 please support Adafruit and open-source hardware by purchasing
JojoS 20:04822be0efcd 12 products from Adafruit!
JojoS 20:04822be0efcd 13
JojoS 20:04822be0efcd 14 Written by Limor Fried/Ladyada for Adafruit Industries.
JojoS 20:04822be0efcd 15 BSD license, check license.txt for more information
JojoS 20:04822be0efcd 16 All text above, and the splash screen must be included in any redistribution
JojoS 20:04822be0efcd 17 *********************************************************************/
JojoS 20:04822be0efcd 18
JojoS 20:04822be0efcd 19 /*
JojoS 20:04822be0efcd 20 * Modified by Neal Horman 7/14/2012 for use in mbed
JojoS 20:04822be0efcd 21 */
JojoS 20:04822be0efcd 22
JojoS 20:04822be0efcd 23 #ifndef _ADAFRUIT_SSD1306_H_
JojoS 20:04822be0efcd 24 #define _ADAFRUIT_SSD1306_H_
JojoS 20:04822be0efcd 25
JojoS 20:04822be0efcd 26 #include "mbed.h"
JojoS 20:04822be0efcd 27 #include "Adafruit_GFX.h"
JojoS 20:04822be0efcd 28
JojoS 20:04822be0efcd 29 #include <vector>
JojoS 20:04822be0efcd 30 #include <algorithm>
JojoS 20:04822be0efcd 31
JojoS 20:04822be0efcd 32 #define SSD1306_EXTERNALVCC 0x1
JojoS 20:04822be0efcd 33 #define SSD1306_SWITCHCAPVCC 0x2
JojoS 20:04822be0efcd 34
JojoS 20:04822be0efcd 35 /** The pure base class for the SSD1306 display driver.
JojoS 20:04822be0efcd 36 *
JojoS 20:04822be0efcd 37 * You should derive from this for a new transport interface type,
JojoS 20:04822be0efcd 38 * such as the SPI and I2C drivers.
JojoS 20:04822be0efcd 39 */
JojoS 20:04822be0efcd 40 class Adafruit_SSD1306 : public Adafruit_GFX
JojoS 20:04822be0efcd 41 {
JojoS 20:04822be0efcd 42 public:
JojoS 20:04822be0efcd 43 Adafruit_SSD1306(PinName reset, uint8_t rawHeight = 32, uint8_t rawWidth = 128, bool flipVertical=false);
JojoS 20:04822be0efcd 44
JojoS 20:04822be0efcd 45 // start display sequence
JojoS 20:04822be0efcd 46 void begin(uint8_t switchvcc = SSD1306_SWITCHCAPVCC);
JojoS 20:04822be0efcd 47
JojoS 20:04822be0efcd 48 // These must be implemented in the derived transport driver
JojoS 20:04822be0efcd 49 virtual void command(uint8_t c) = 0;
JojoS 20:04822be0efcd 50 virtual void data(uint8_t c) = 0;
JojoS 20:04822be0efcd 51 virtual void drawPixel(int16_t x, int16_t y, uint16_t color);
JojoS 20:04822be0efcd 52
JojoS 20:04822be0efcd 53 /// Clear the display buffer
JojoS 20:04822be0efcd 54 void clearDisplay(void);
JojoS 20:04822be0efcd 55 virtual void invertDisplay(bool i);
JojoS 20:04822be0efcd 56 void flipVertical(bool flip);
JojoS 20:04822be0efcd 57
JojoS 20:04822be0efcd 58 /// Cause the display to be updated with the buffer content.
JojoS 20:04822be0efcd 59 void display();
JojoS 20:04822be0efcd 60 /// Fill the buffer with the AdaFruit splash screen.
JojoS 20:04822be0efcd 61 virtual void splash();
JojoS 20:04822be0efcd 62
JojoS 20:04822be0efcd 63 protected:
JojoS 20:04822be0efcd 64 virtual void sendDisplayBuffer() = 0;
JojoS 20:04822be0efcd 65 DigitalOut _reset;
JojoS 20:04822be0efcd 66 bool _flipVertical;
JojoS 20:04822be0efcd 67
JojoS 20:04822be0efcd 68 // the memory buffer for the LCD
JojoS 20:04822be0efcd 69 std::vector<uint8_t> buffer;
JojoS 20:04822be0efcd 70 };
JojoS 20:04822be0efcd 71
JojoS 20:04822be0efcd 72
JojoS 20:04822be0efcd 73 /** This is the SPI SSD1306 display driver transport class
JojoS 20:04822be0efcd 74 *
JojoS 20:04822be0efcd 75 */
JojoS 20:04822be0efcd 76 class Adafruit_SSD1306_Spi : public Adafruit_SSD1306
JojoS 20:04822be0efcd 77 {
JojoS 20:04822be0efcd 78 public:
JojoS 20:04822be0efcd 79 /** Create a SSD1306 SPI transport display driver instance with the specified DC, RST, and CS pins, as well as the display dimentions
JojoS 20:04822be0efcd 80 *
JojoS 20:04822be0efcd 81 * Required parameters
JojoS 20:04822be0efcd 82 * @param spi - a reference to an initialized SPI object
JojoS 20:04822be0efcd 83 * @param DC (Data/Command) pin name
JojoS 20:04822be0efcd 84 * @param RST (Reset) pin name
JojoS 20:04822be0efcd 85 * @param CS (Chip Select) pin name
JojoS 20:04822be0efcd 86 *
JojoS 20:04822be0efcd 87 * Optional parameters
JojoS 20:04822be0efcd 88 * @param rawHeight - the vertical number of pixels for the display, defaults to 32
JojoS 20:04822be0efcd 89 * @param rawWidth - the horizonal number of pixels for the display, defaults to 128
JojoS 20:04822be0efcd 90 */
JojoS 20:04822be0efcd 91 Adafruit_SSD1306_Spi(SPI &spi, PinName DC, PinName RST, PinName CS, uint8_t rawHieght = 32, uint8_t rawWidth = 128, bool flipVertical = false);
JojoS 20:04822be0efcd 92
JojoS 20:04822be0efcd 93 virtual void command(uint8_t c);
JojoS 20:04822be0efcd 94 virtual void data(uint8_t c);
JojoS 20:04822be0efcd 95
JojoS 20:04822be0efcd 96 protected:
JojoS 20:04822be0efcd 97 virtual void sendDisplayBuffer();
JojoS 20:04822be0efcd 98
JojoS 20:04822be0efcd 99 DigitalOut cs, dc;
JojoS 20:04822be0efcd 100 SPI &mspi;
JojoS 20:04822be0efcd 101 };
JojoS 20:04822be0efcd 102
JojoS 20:04822be0efcd 103 /** This is the I2C SSD1306 display driver transport class
JojoS 20:04822be0efcd 104 *
JojoS 20:04822be0efcd 105 */
JojoS 20:04822be0efcd 106 class Adafruit_SSD1306_I2c : public Adafruit_SSD1306
JojoS 20:04822be0efcd 107 {
JojoS 20:04822be0efcd 108 public:
JojoS 20:04822be0efcd 109 #define SSD_I2C_ADDRESS 0x78
JojoS 20:04822be0efcd 110 /** Create a SSD1306 I2C transport display driver instance with the specified RST pin name, the I2C address, as well as the display dimensions
JojoS 20:04822be0efcd 111 *
JojoS 20:04822be0efcd 112 * Required parameters
JojoS 20:04822be0efcd 113 * @param i2c - A reference to an initialized I2C object
JojoS 20:04822be0efcd 114 * @param RST - The Reset pin name
JojoS 20:04822be0efcd 115 *
JojoS 20:04822be0efcd 116 * Optional parameters
JojoS 20:04822be0efcd 117 * @param i2cAddress - The i2c address of the display
JojoS 20:04822be0efcd 118 * @param rawHeight - The vertical number of pixels for the display, defaults to 32
JojoS 20:04822be0efcd 119 * @param rawWidth - The horizonal number of pixels for the display, defaults to 128
JojoS 20:04822be0efcd 120 */
JojoS 20:04822be0efcd 121 Adafruit_SSD1306_I2c(I2C &i2c, PinName RST, uint8_t i2cAddress = SSD_I2C_ADDRESS, uint8_t rawHeight = 32, uint8_t rawWidth = 128, bool flipVertical = false);
JojoS 20:04822be0efcd 122
JojoS 20:04822be0efcd 123 virtual void command(uint8_t c);
JojoS 20:04822be0efcd 124 virtual void data(uint8_t c);
JojoS 20:04822be0efcd 125
JojoS 20:04822be0efcd 126 protected:
JojoS 20:04822be0efcd 127 virtual void sendDisplayBuffer();
JojoS 20:04822be0efcd 128
JojoS 20:04822be0efcd 129 I2C &mi2c;
JojoS 20:04822be0efcd 130 uint8_t mi2cAddress;
JojoS 20:04822be0efcd 131 };
JojoS 20:04822be0efcd 132
JojoS 20:04822be0efcd 133 #endif