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