Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: BLE_TemperatureObserver
Adafruit_SSD1306.h
00001 /********************************************************************* 00002 This is a library for our Monochrome OLEDs based on SSD1306 drivers 00003 00004 Pick one up today in the adafruit shop! 00005 ------> http://www.adafruit.com/category/63_98 00006 00007 These displays use SPI to communicate, 4 or 5 pins are required to 00008 interface 00009 00010 Adafruit invests time and resources providing this open source code, 00011 please support Adafruit and open-source hardware by purchasing 00012 products from Adafruit! 00013 00014 Written by Limor Fried/Ladyada for Adafruit Industries. 00015 BSD license, check license.txt for more information 00016 All text above, and the splash screen must be included in any redistribution 00017 *********************************************************************/ 00018 00019 /* 00020 * Modified by Neal Horman 7/14/2012 for use in mbed 00021 */ 00022 00023 #ifndef _ADAFRUIT_SSD1306_H_ 00024 #define _ADAFRUIT_SSD1306_H_ 00025 00026 #include "mbed.h" 00027 #include "Adafruit_GFX.h" 00028 00029 #include <vector> 00030 #include <algorithm> 00031 00032 #define SSD1306_EXTERNALVCC 0x1 00033 #define SSD1306_SWITCHCAPVCC 0x2 00034 00035 /** The pure base class for the SSD1306 display driver. 00036 * 00037 * You should derive from this for a new transport interface type, 00038 * such as the SPI and I2C drivers. 00039 */ 00040 class Adafruit_SSD1306 : public Adafruit_GFX 00041 { 00042 public: 00043 Adafruit_SSD1306(PinName reset, uint8_t rawHeight = 32, uint8_t rawWidth = 128, bool flipVertical=false); 00044 00045 // start display sequence 00046 void begin(uint8_t switchvcc = SSD1306_SWITCHCAPVCC); 00047 00048 // These must be implemented in the derived transport driver 00049 virtual void command(uint8_t c) = 0; 00050 virtual void data(uint8_t c) = 0; 00051 virtual void drawPixel(int16_t x, int16_t y, uint16_t color); 00052 00053 /// Clear the display buffer 00054 void clearDisplay(void); 00055 virtual void invertDisplay(bool i); 00056 void flipVertical(bool flip); 00057 00058 /// Cause the display to be updated with the buffer content. 00059 void display(); 00060 /// Fill the buffer with the AdaFruit splash screen. 00061 virtual void splash(); 00062 00063 protected: 00064 virtual void sendDisplayBuffer() = 0; 00065 DigitalOut _reset; 00066 bool _flipVertical; 00067 00068 // the memory buffer for the LCD 00069 std::vector<uint8_t> buffer; 00070 }; 00071 00072 00073 /** This is the SPI SSD1306 display driver transport class 00074 * 00075 */ 00076 class Adafruit_SSD1306_Spi : public Adafruit_SSD1306 00077 { 00078 public: 00079 /** Create a SSD1306 SPI transport display driver instance with the specified DC, RST, and CS pins, as well as the display dimentions 00080 * 00081 * Required parameters 00082 * @param spi - a reference to an initialized SPI object 00083 * @param DC (Data/Command) pin name 00084 * @param RST (Reset) pin name 00085 * @param CS (Chip Select) pin name 00086 * 00087 * Optional parameters 00088 * @param rawHeight - the vertical number of pixels for the display, defaults to 32 00089 * @param rawWidth - the horizonal number of pixels for the display, defaults to 128 00090 */ 00091 Adafruit_SSD1306_Spi(SPI &spi, PinName DC, PinName RST, PinName CS, uint8_t rawHieght = 32, uint8_t rawWidth = 128, bool flipVertical = false); 00092 00093 virtual void command(uint8_t c); 00094 virtual void data(uint8_t c); 00095 00096 protected: 00097 virtual void sendDisplayBuffer(); 00098 00099 DigitalOut cs, dc; 00100 SPI &mspi; 00101 }; 00102 00103 /** This is the I2C SSD1306 display driver transport class 00104 * 00105 */ 00106 class Adafruit_SSD1306_I2c : public Adafruit_SSD1306 00107 { 00108 public: 00109 #define SSD_I2C_ADDRESS 0x78 00110 /** Create a SSD1306 I2C transport display driver instance with the specified RST pin name, the I2C address, as well as the display dimensions 00111 * 00112 * Required parameters 00113 * @param i2c - A reference to an initialized I2C object 00114 * @param RST - The Reset pin name 00115 * 00116 * Optional parameters 00117 * @param i2cAddress - The i2c address of the display 00118 * @param rawHeight - The vertical number of pixels for the display, defaults to 32 00119 * @param rawWidth - The horizonal number of pixels for the display, defaults to 128 00120 */ 00121 Adafruit_SSD1306_I2c(I2C &i2c, PinName RST, uint8_t i2cAddress = SSD_I2C_ADDRESS, uint8_t rawHeight = 32, uint8_t rawWidth = 128, bool flipVertical = false); 00122 00123 virtual void command(uint8_t c); 00124 virtual void data(uint8_t c); 00125 00126 protected: 00127 virtual void sendDisplayBuffer(); 00128 00129 I2C &mi2c; 00130 uint8_t mi2cAddress; 00131 }; 00132 00133 #endif
Generated on Sun Jul 17 2022 14:37:15 by
1.7.2