Dependencies:   RemoteIR

Committer:
sb8718
Date:
Tue Jun 02 08:33:56 2020 +0000
Revision:
142:cb9e8d32d1b9
Parent:
136:53a83b91854c
un - new commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sb8718 136:53a83b91854c 1 /*********************************************************************
sb8718 136:53a83b91854c 2 This is a library for our Monochrome OLEDs based on SSD1306 drivers
sb8718 136:53a83b91854c 3
sb8718 136:53a83b91854c 4 Pick one up today in the adafruit shop!
sb8718 136:53a83b91854c 5 ------> http://www.adafruit.com/category/63_98
sb8718 136:53a83b91854c 6
sb8718 136:53a83b91854c 7 These displays use SPI to communicate, 4 or 5 pins are required to
sb8718 136:53a83b91854c 8 interface
sb8718 136:53a83b91854c 9
sb8718 136:53a83b91854c 10 Adafruit invests time and resources providing this open source code,
sb8718 136:53a83b91854c 11 please support Adafruit and open-source hardware by purchasing
sb8718 136:53a83b91854c 12 products from Adafruit!
sb8718 136:53a83b91854c 13
sb8718 136:53a83b91854c 14 Written by Limor Fried/Ladyada for Adafruit Industries.
sb8718 136:53a83b91854c 15 BSD license, check license.txt for more information
sb8718 136:53a83b91854c 16 All text above, and the splash screen must be included in any redistribution
sb8718 136:53a83b91854c 17 *********************************************************************/
sb8718 136:53a83b91854c 18
sb8718 136:53a83b91854c 19 /*
sb8718 136:53a83b91854c 20 * Modified by Neal Horman 7/14/2012 for use in mbed
sb8718 136:53a83b91854c 21 * Edited by Francesco Adamo 2015/09/03:
sb8718 136:53a83b91854c 22 * - code cleaned up in many points for a better readability
sb8718 136:53a83b91854c 23 * - removed SPIPreinit and I2CPreinit classes
sb8718 136:53a83b91854c 24 * - moved various method implementations from .h files to the corresponding .cpp ones
sb8718 136:53a83b91854c 25 * - the splash() and clearDisplay() methods now directly update the display; no more need to call the display() method after them
sb8718 136:53a83b91854c 26 *
sb8718 136:53a83b91854c 27 */
sb8718 136:53a83b91854c 28
sb8718 136:53a83b91854c 29 #ifndef _ADAFRUIT_SSD1306_H_
sb8718 136:53a83b91854c 30 #define _ADAFRUIT_SSD1306_H_
sb8718 136:53a83b91854c 31
sb8718 136:53a83b91854c 32 #include "mbed.h"
sb8718 136:53a83b91854c 33 #include "Adafruit_GFX.h"
sb8718 136:53a83b91854c 34
sb8718 136:53a83b91854c 35 #include <vector>
sb8718 136:53a83b91854c 36 #include <algorithm>
sb8718 136:53a83b91854c 37
sb8718 136:53a83b91854c 38 #define SSD1306_SETCONTRAST 0x81
sb8718 136:53a83b91854c 39 #define SSD1306_DISPLAYALLON_RESUME 0xA4
sb8718 136:53a83b91854c 40 #define SSD1306_DISPLAYALLON 0xA5
sb8718 136:53a83b91854c 41 #define SSD1306_NORMALDISPLAY 0xA6
sb8718 136:53a83b91854c 42 #define SSD1306_INVERTDISPLAY 0xA7
sb8718 136:53a83b91854c 43 #define SSD1306_DISPLAYOFF 0xAE
sb8718 136:53a83b91854c 44 #define SSD1306_DISPLAYON 0xAF
sb8718 136:53a83b91854c 45 #define SSD1306_SETDISPLAYOFFSET 0xD3
sb8718 136:53a83b91854c 46 #define SSD1306_SETCOMPINS 0xDA
sb8718 136:53a83b91854c 47 #define SSD1306_SETVCOMDETECT 0xDB
sb8718 136:53a83b91854c 48 #define SSD1306_SETDISPLAYCLOCKDIV 0xD5
sb8718 136:53a83b91854c 49 #define SSD1306_SETPRECHARGE 0xD9
sb8718 136:53a83b91854c 50 #define SSD1306_SETMULTIPLEX 0xA8
sb8718 136:53a83b91854c 51 #define SSD1306_SETLOWCOLUMN 0x00
sb8718 136:53a83b91854c 52 #define SSD1306_SETHIGHCOLUMN 0x10
sb8718 136:53a83b91854c 53 #define SSD1306_SETSTARTLINE 0x40
sb8718 136:53a83b91854c 54 #define SSD1306_MEMORYMODE 0x20
sb8718 136:53a83b91854c 55 #define SSD1306_COMSCANINC 0xC0
sb8718 136:53a83b91854c 56 #define SSD1306_COMSCANDEC 0xC8
sb8718 136:53a83b91854c 57 #define SSD1306_SEGREMAP 0xA0
sb8718 136:53a83b91854c 58 #define SSD1306_CHARGEPUMP 0x8D
sb8718 136:53a83b91854c 59
sb8718 136:53a83b91854c 60 #define SSD1306_EXTERNALVCC 0x1
sb8718 136:53a83b91854c 61 #define SSD1306_SWITCHCAPVCC 0x2
sb8718 136:53a83b91854c 62
sb8718 136:53a83b91854c 63 // A DigitalOut sub-class that provides a constructed default state
sb8718 136:53a83b91854c 64 class DigitalOut2 : public DigitalOut
sb8718 136:53a83b91854c 65 {
sb8718 136:53a83b91854c 66 public:
sb8718 136:53a83b91854c 67 DigitalOut2(PinName pin, bool active = false) : DigitalOut(pin) { write(active); };
sb8718 136:53a83b91854c 68 DigitalOut2& operator= (int value) { write(value); return *this; };
sb8718 136:53a83b91854c 69 DigitalOut2& operator= (DigitalOut2& rhs) { write(rhs.read()); return *this; };
sb8718 136:53a83b91854c 70 operator int() { return read(); };
sb8718 136:53a83b91854c 71 };
sb8718 136:53a83b91854c 72
sb8718 136:53a83b91854c 73
sb8718 136:53a83b91854c 74 /** The pure base class for the SSD1306 display driver.
sb8718 136:53a83b91854c 75 *
sb8718 136:53a83b91854c 76 * You should derive from this for a new transport interface type,
sb8718 136:53a83b91854c 77 * such as the SPI and I2C drivers.
sb8718 136:53a83b91854c 78 */
sb8718 136:53a83b91854c 79 class Adafruit_SSD1306 : public Adafruit_GFX
sb8718 136:53a83b91854c 80 {
sb8718 136:53a83b91854c 81 protected:
sb8718 136:53a83b91854c 82 virtual void sendDisplayBuffer() = 0;
sb8718 136:53a83b91854c 83 DigitalOut2 rst;
sb8718 136:53a83b91854c 84
sb8718 136:53a83b91854c 85 // the memory buffer for the LCD
sb8718 136:53a83b91854c 86 std::vector<uint8_t> buffer;
sb8718 136:53a83b91854c 87
sb8718 136:53a83b91854c 88 public:
sb8718 136:53a83b91854c 89 Adafruit_SSD1306(PinName RST, uint8_t rawHeight = 32, uint8_t rawWidth = 128);
sb8718 136:53a83b91854c 90 void begin(uint8_t switchvcc = SSD1306_SWITCHCAPVCC);
sb8718 136:53a83b91854c 91
sb8718 136:53a83b91854c 92 // These must be implemented in the derived transport driver
sb8718 136:53a83b91854c 93 virtual uint8_t command(uint8_t c) = 0;
sb8718 136:53a83b91854c 94 virtual void data(uint8_t c) = 0;
sb8718 136:53a83b91854c 95 virtual void drawPixel(int16_t x, int16_t y, uint16_t color);
sb8718 136:53a83b91854c 96
sb8718 136:53a83b91854c 97 // Clear the display buffer
sb8718 136:53a83b91854c 98 void clearDisplay(void);
sb8718 136:53a83b91854c 99 virtual void invertDisplay(bool i);
sb8718 136:53a83b91854c 100
sb8718 136:53a83b91854c 101 // Cause the display to be updated with the buffer content.
sb8718 136:53a83b91854c 102 void display();
sb8718 136:53a83b91854c 103
sb8718 136:53a83b91854c 104 // Fill the buffer with the AdaFruit splash screen.
sb8718 136:53a83b91854c 105 virtual void splash();
sb8718 136:53a83b91854c 106 };
sb8718 136:53a83b91854c 107
sb8718 136:53a83b91854c 108
sb8718 136:53a83b91854c 109 /** This is the SPI SSD1306 display driver transport class
sb8718 136:53a83b91854c 110 *
sb8718 136:53a83b91854c 111 */
sb8718 136:53a83b91854c 112 class Adafruit_SSD1306_SPI : public Adafruit_SSD1306
sb8718 136:53a83b91854c 113 {
sb8718 136:53a83b91854c 114 public:
sb8718 136:53a83b91854c 115 /*
sb8718 136:53a83b91854c 116 * Create a SSD1306 SPI transport display driver instance with the specified DC, RST, and CS pins, as well as the display dimensions
sb8718 136:53a83b91854c 117 *
sb8718 136:53a83b91854c 118 * Required parameters
sb8718 136:53a83b91854c 119 * @param MOSI (SPI MOSI pin name)
sb8718 136:53a83b91854c 120 * @param CLK (SPI clock pin name)
sb8718 136:53a83b91854c 121 * @param CS (Chip Select) pin name
sb8718 136:53a83b91854c 122 * @param DC (Data/Command) pin name
sb8718 136:53a83b91854c 123 * @param RST (Reset) pin name
sb8718 136:53a83b91854c 124 *
sb8718 136:53a83b91854c 125 * Optional parameters
sb8718 136:53a83b91854c 126 * @param rawHeight - the vertical number of pixels for the display, defaults to 32
sb8718 136:53a83b91854c 127 * @param rawWidth - the horizontal number of pixels for the display, defaults to 128
sb8718 136:53a83b91854c 128 */
sb8718 136:53a83b91854c 129 Adafruit_SSD1306_SPI(PinName MOSI, PinName CLK, PinName CS, PinName DC, PinName RST, uint8_t rawHeight = 32, uint8_t rawWidth = 128);
sb8718 136:53a83b91854c 130 virtual uint8_t command(uint8_t);
sb8718 136:53a83b91854c 131 virtual void data(uint8_t);
sb8718 136:53a83b91854c 132 virtual void sendDisplayBuffer(void);
sb8718 136:53a83b91854c 133
sb8718 136:53a83b91854c 134 protected:
sb8718 136:53a83b91854c 135 DigitalOut2 cs, dc;
sb8718 136:53a83b91854c 136 SPI mspi;
sb8718 136:53a83b91854c 137 };
sb8718 136:53a83b91854c 138
sb8718 136:53a83b91854c 139
sb8718 136:53a83b91854c 140 /*
sb8718 136:53a83b91854c 141 * This is the I2C SSD1306 display driver transport class
sb8718 136:53a83b91854c 142 *
sb8718 136:53a83b91854c 143 */
sb8718 136:53a83b91854c 144 class Adafruit_SSD1306_I2C : public Adafruit_SSD1306
sb8718 136:53a83b91854c 145 {
sb8718 136:53a83b91854c 146 public:
sb8718 136:53a83b91854c 147 #define SSD_I2C_ADDRESS 0x78
sb8718 136:53a83b91854c 148 /** Create a SSD1306 I2C transport display driver instance with the specified RST pin name, the I2C address, as well as the display dimensions
sb8718 136:53a83b91854c 149 *
sb8718 136:53a83b91854c 150 * Required parameters
sb8718 136:53a83b91854c 151 * @param i2c - A reference to an initialized I2C object
sb8718 136:53a83b91854c 152 * @param RST - The Reset pin name
sb8718 136:53a83b91854c 153 *
sb8718 136:53a83b91854c 154 * Optional parameters
sb8718 136:53a83b91854c 155 * @param i2cAddress - The i2c address of the display
sb8718 136:53a83b91854c 156 * @param rawHeight - The vertical number of pixels for the display, defaults to 32
sb8718 136:53a83b91854c 157 * @param rawWidth - The horizonal number of pixels for the display, defaults to 128
sb8718 136:53a83b91854c 158 */
sb8718 136:53a83b91854c 159 Adafruit_SSD1306_I2C(PinName SDA, PinName SCL, PinName RST, uint8_t i2cAddress = SSD_I2C_ADDRESS, uint8_t rawHeight = 32, uint8_t rawWidth = 128);
sb8718 136:53a83b91854c 160 virtual uint8_t command(uint8_t c);
sb8718 136:53a83b91854c 161 virtual void data(uint8_t c);
sb8718 136:53a83b91854c 162 virtual void sendDisplayBuffer();
sb8718 136:53a83b91854c 163
sb8718 136:53a83b91854c 164 protected:
sb8718 136:53a83b91854c 165 I2C mi2c;
sb8718 136:53a83b91854c 166 uint8_t mi2cAddress;
sb8718 136:53a83b91854c 167 };
sb8718 136:53a83b91854c 168
sb8718 136:53a83b91854c 169 #endif