SSD1308 128x64 OLED Driver with I2C interface

Dependents:   sense xadow_m0_ada_gps xadow_m0_SD_Hello sense-DHT11 ... more

See http://mbed.org/users/wim/notebook/oled-display-with-ssd1308-driver/#c6729

Committer:
wim
Date:
Mon Jul 23 20:24:11 2012 +0000
Revision:
3:fa18169dd7e6
Parent:
2:16c84a134393
Child:
4:df92b0c0cb92
Added Docs

Who changed what in which revision?

UserRevisionLine numberNew contents of line
wim 1:b7e8f5139026 1 /** @file SSD1308 I2C device class header file
wim 1:b7e8f5139026 2 * Based on Solomon Systech SSD1308 datasheet, rev. 1, 10/2008
wim 1:b7e8f5139026 3 * The SSD1308 is used for example in the Seeed 128x64 OLED Display
wim 1:b7e8f5139026 4 * http://www.seeedstudio.com/depot/grove-oled-display-12864-p-781.html?cPath=163_167
wim 1:b7e8f5139026 5 */
wim 0:300d08d9b058 6 // The original code by Andrew Schamp is using (and has been submitted as a part of) Jeff Rowberg's I2Cdevlib library,
wim 0:300d08d9b058 7 // which should (hopefully) always be available at https://github.com/jrowberg/i2cdevlib
wim 0:300d08d9b058 8 // Some parts also mashed up from Graphic Library for driving monochrome displays based on the PCD8544,
wim 0:300d08d9b058 9 // Copyright (c) 2011, Wim De Roeve, who in turn did partial port of code found on
wim 0:300d08d9b058 10 // http://serdisplib.sourceforge.net/ser/pcd8544.html#links and by Petras Saduikis <petras@petras.co.uk>
wim 0:300d08d9b058 11 //
wim 0:300d08d9b058 12 // Changelog:
wim 0:300d08d9b058 13 // 2011-08-25 - Initial release by Andrew Schamp <schamp@gmail.com>
wim 0:300d08d9b058 14 // 2012-06-19 - Ported to mbed and optimised (WH)
wim 0:300d08d9b058 15 //
wim 0:300d08d9b058 16 /* ============================================
wim 0:300d08d9b058 17 I2Cdev device library code is placed under the MIT license
wim 0:300d08d9b058 18 Copyright (c) 2011 Andrew Schamp
wim 0:300d08d9b058 19 Copyright (c) 2012 WH (mbed port)
wim 0:300d08d9b058 20
wim 0:300d08d9b058 21 Permission is hereby granted, free of charge, to any person obtaining a copy
wim 0:300d08d9b058 22 of this software and associated documentation files (the "Software"), to deal
wim 0:300d08d9b058 23 in the Software without restriction, including without limitation the rights
wim 0:300d08d9b058 24 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
wim 0:300d08d9b058 25 copies of the Software, and to permit persons to whom the Software is
wim 0:300d08d9b058 26 furnished to do so, subject to the following conditions:
wim 0:300d08d9b058 27
wim 0:300d08d9b058 28 The above copyright notice and this permission notice shall be included in
wim 0:300d08d9b058 29 all copies or substantial portions of the Software.
wim 0:300d08d9b058 30
wim 0:300d08d9b058 31 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
wim 0:300d08d9b058 32 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
wim 0:300d08d9b058 33 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
wim 0:300d08d9b058 34 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
wim 0:300d08d9b058 35 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
wim 0:300d08d9b058 36 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
wim 0:300d08d9b058 37 THE SOFTWARE.
wim 0:300d08d9b058 38 ===============================================
wim 0:300d08d9b058 39 */
wim 0:300d08d9b058 40
wim 0:300d08d9b058 41 #ifndef SSD1308_H
wim 0:300d08d9b058 42 #define SSD1308_H
wim 0:300d08d9b058 43
wim 0:300d08d9b058 44 // This is the I2C address (8 bit)
wim 0:300d08d9b058 45 // There are two possible addresses: with D/C# (pin 13) grounded, the address is 0x78,
wim 0:300d08d9b058 46 // with D/C# tied high it is 0x7A. Assume grounded by default.
wim 0:300d08d9b058 47 #define SSD1308_SA0 0x78
wim 0:300d08d9b058 48 #define SSD1308_SA1 0x7A
wim 0:300d08d9b058 49 #define SSD1308_DEF_SA SSD1308_SA0
wim 0:300d08d9b058 50
wim 0:300d08d9b058 51 // Display dimensions
wim 0:300d08d9b058 52 #define ROWS 64
wim 0:300d08d9b058 53 #define COLUMNS 128
wim 0:300d08d9b058 54 #define PAGES (ROWS / 8)
wim 0:300d08d9b058 55 #define MAX_PAGE (PAGES - 1)
wim 2:16c84a134393 56 #define MAX_ROW (ROWS - 1)
wim 0:300d08d9b058 57 #define MAX_COL (COLUMNS - 1)
wim 0:300d08d9b058 58
wim 0:300d08d9b058 59 // Character dimensions 8x8 font
wim 0:300d08d9b058 60 #define CHARS (COLUMNS / FONT8x8_WIDTH)
wim 0:300d08d9b058 61
wim 0:300d08d9b058 62 // Command and Datamode
wim 0:300d08d9b058 63 #define COMMAND_MODE 0x80 // continuation bit is set!
wim 0:300d08d9b058 64 #define DATA_MODE 0x40
wim 0:300d08d9b058 65
wim 0:300d08d9b058 66 // Commands and Parameter defines
wim 2:16c84a134393 67 #define SET_LOWER_COLUMN 0x00 // | with lower nibble (Page mode only)
wim 2:16c84a134393 68 #define SET_HIGHER_COLUMN 0x10 // | with higher nibble (Page mode only)
wim 2:16c84a134393 69
wim 0:300d08d9b058 70 #define HORIZONTAL_ADDRESSING_MODE 0x00
wim 0:300d08d9b058 71 #define VERTICAL_ADDRESSING_MODE 0x01
wim 0:300d08d9b058 72 #define PAGE_ADDRESSING_MODE 0x02
wim 0:300d08d9b058 73 #define SET_MEMORY_ADDRESSING_MODE 0x20 // takes one byte as given above
wim 0:300d08d9b058 74
wim 0:300d08d9b058 75 #define SET_COLUMN_ADDRESS 0x21 // takes two bytes, start address and end address of display data RAM
wim 0:300d08d9b058 76 #define SET_PAGE_ADDRESS 0x22 // takes two bytes, start address and end address of display data RAM
wim 0:300d08d9b058 77
wim 0:300d08d9b058 78 // Command maybe unsupported by SSD1308
wim 0:300d08d9b058 79 #define FADE_INTERVAL_8_FRAMES 0x00
wim 0:300d08d9b058 80 #define FADE_INTERVAL_16_FRAMES 0x01
wim 0:300d08d9b058 81 #define FADE_INTERVAL_24_FRAMES 0x02
wim 0:300d08d9b058 82 #define FADE_INTERVAL_32_FRAMES 0x03
wim 0:300d08d9b058 83 #define FADE_INTERVAL_64_FRAMES 0x07
wim 0:300d08d9b058 84 #define FADE_INTERVAL_128_FRAMES 0x0F
wim 0:300d08d9b058 85 #define FADE_BLINK_DISABLE 0x00
wim 0:300d08d9b058 86 #define FADE_OUT_ENABLE 0x20
wim 0:300d08d9b058 87 #define BLINK_ENABLE 0x30
wim 0:300d08d9b058 88 #define SET_FADE_BLINK 0x23 // takes one byte
wim 0:300d08d9b058 89 // bit5-4 = 0, fade/blink mode
wim 0:300d08d9b058 90 // bit3-0 = Time interval in frames
wim 0:300d08d9b058 91
wim 2:16c84a134393 92 #define SET_DISPLAY_START_LINE 0x40 // | with a row number 0-63 to set start row. (Reset = 0)
wim 0:300d08d9b058 93
wim 0:300d08d9b058 94 #define SET_CONTRAST 0x81 // takes one byte, 0x00 - 0xFF
wim 0:300d08d9b058 95
wim 0:300d08d9b058 96 #define SET_SEGMENT_REMAP_0 0xA0 // column address 0 is mapped to SEG0 (Reset)
wim 0:300d08d9b058 97 #define SET_SEGMENT_REMAP_127 0xA1 // column address 127 is mapped to SEG0
wim 0:300d08d9b058 98
wim 0:300d08d9b058 99 #define SET_DISPLAY_GDDRAM 0xA4 // restores display to contents of RAM
wim 0:300d08d9b058 100 #define SET_ENTIRE_DISPLAY_ON 0xA5 // turns all pixels on, does not affect RAM
wim 0:300d08d9b058 101
wim 0:300d08d9b058 102 #define SET_NORMAL_DISPLAY 0xA6 // a databit of 1 indicates pixel 'ON'
wim 0:300d08d9b058 103 #define SET_INVERSE_DISPLAY 0xA7 // a databit of 1 indicates pixel 'OFF'
wim 0:300d08d9b058 104
wim 0:300d08d9b058 105 #define SET_MULTIPLEX_RATIO 0xA8 // takes one byte, from 16xMUX to 64xMUX (MUX Ratio = byte+1; Default 64)
wim 0:300d08d9b058 106
wim 0:300d08d9b058 107 #define EXTERNAL_IREF 0x10
wim 0:300d08d9b058 108 #define INTERNAL_IREF 0x00
wim 0:300d08d9b058 109 #define SET_IREF_SELECTION 0xAD // sets internal or external Iref
wim 0:300d08d9b058 110
wim 0:300d08d9b058 111 #define SET_DISPLAY_POWER_OFF 0xAE
wim 0:300d08d9b058 112 #define SET_DISPLAY_POWER_ON 0xAF
wim 0:300d08d9b058 113
wim 0:300d08d9b058 114 #define PAGE0 0x00
wim 0:300d08d9b058 115 #define PAGE1 0x01
wim 0:300d08d9b058 116 #define PAGE2 0x02
wim 0:300d08d9b058 117 #define PAGE3 0x03
wim 0:300d08d9b058 118 #define PAGE4 0x04
wim 0:300d08d9b058 119 #define PAGE5 0x05
wim 0:300d08d9b058 120 #define PAGE6 0x06
wim 0:300d08d9b058 121 #define PAGE7 0x07
wim 2:16c84a134393 122 #define SET_PAGE_START_ADDRESS 0xB0 // | with a page number to get start address (Page mode only)
wim 0:300d08d9b058 123
wim 0:300d08d9b058 124 #define SET_COMMON_REMAP_0 0xC0 // row address 0 is mapped to COM0 (Reset)
wim 0:300d08d9b058 125 #define SET_COMMON_REMAP_63 0xC8 // row address 63 is mapped to COM0
wim 0:300d08d9b058 126
wim 0:300d08d9b058 127 #define SET_DISPLAY_OFFSET 0xD3 // takes one byte from 0-63 for vertical shift, Reset = 0
wim 0:300d08d9b058 128
wim 0:300d08d9b058 129 #define SET_DISPLAY_CLOCK 0xD5 // takes one byte
wim 0:300d08d9b058 130 // bit7-4 = Osc Freq DCLK (Reset = 1000b)
wim 0:300d08d9b058 131 // bit3-0 = Divide ration (Reset = oooob, Ratio = 1)
wim 0:300d08d9b058 132
wim 0:300d08d9b058 133 #define SET_PRECHARGE_TIME 0xD9 // takes one byte
wim 0:300d08d9b058 134 // bit7-4 = Phase2, upto 15 DCLKs (Reset = 0010b)
wim 0:300d08d9b058 135 // bit3-0 = Phase1, upto 15 DCLKs (Reset = 0010b)
wim 0:300d08d9b058 136
wim 0:300d08d9b058 137
wim 0:300d08d9b058 138 #define COMMON_BASE 0x02 //
wim 0:300d08d9b058 139 #define COMMON_SEQUENTIAL 0x00 // Sequential common pins config
wim 0:300d08d9b058 140 #define COMMON_ALTERNATIVE 0x10 // Odd/Even common pins config (Reset)
wim 0:300d08d9b058 141 #define COMMON_LEFTRIGHT_NORMAL 0x00 // LeftRight Normal (Reset)
wim 0:300d08d9b058 142 #define COMMON_LEFTRIGHT_FLIP 0x20 // LeftRight Flip
wim 0:300d08d9b058 143 #define SET_COMMON_CONF 0xDA // takes one byte as given above
wim 0:300d08d9b058 144
wim 0:300d08d9b058 145
wim 0:300d08d9b058 146 #define VCOMH_DESELECT_0_65_CODE 0x00
wim 0:300d08d9b058 147 #define VCOMH_DESELECT_0_77_CODE 0x20
wim 0:300d08d9b058 148 #define VCOMH_DESELECT_0_83_CODE 0x30
wim 0:300d08d9b058 149 #define SET_VCOMH_DESELECT_LEVEL 0xDB // takes one byte as given above
wim 0:300d08d9b058 150
wim 0:300d08d9b058 151 #define NOP 0xE3
wim 0:300d08d9b058 152
wim 0:300d08d9b058 153 #define SCROLL_INTERVAL_5_FRAMES 0x00
wim 0:300d08d9b058 154 #define SCROLL_INTERVAL_64_FRAMES 0x01
wim 0:300d08d9b058 155 #define SCROLL_INTERVAL_128_FRAMES 0x02
wim 0:300d08d9b058 156 #define SCROLL_INTERVAL_256_FRAMES 0x03
wim 0:300d08d9b058 157 #define SCROLL_INTERVAL_3_FRAMES 0x04
wim 0:300d08d9b058 158 #define SCROLL_INTERVAL_4_FRAMES 0x05
wim 0:300d08d9b058 159 #define SCROLL_INTERVAL_25_FRAMES 0x06
wim 0:300d08d9b058 160 #define SCROLL_INTERVAL_2_FRAMES 0x07
wim 0:300d08d9b058 161
wim 0:300d08d9b058 162 #define SET_RIGHT_HOR_SCROLL 0x26 // takes 6 bytes: 0x00, PageStart, Scroll_Interval, PageEnd, 0x00, 0xFF
wim 0:300d08d9b058 163 #define SET_LEFT_HOR_SCROLL 0x27 // takes 6 bytes: 0x00, PageStart, Scroll_Interval, PageEnd, 0x00, 0xFF
wim 0:300d08d9b058 164
wim 0:300d08d9b058 165 #define SET_VERT_RIGHT_HOR_SCROLL 0x29 // takes 5 bytes: 0x00, PageStart, Scroll_Interval, PageEnd, VertOffset
wim 0:300d08d9b058 166 #define SET_VERT_LEFT_HOR_SCROLL 0x2A // takes 5 bytes: 0x00, PageStart, Scroll_Interval, PageEnd, VertOffset
wim 0:300d08d9b058 167
wim 0:300d08d9b058 168 #define SET_DEACTIVATE_SCROLL 0x2E
wim 0:300d08d9b058 169 #define SET_ACTIVATE_SCROLL 0x2F
wim 0:300d08d9b058 170
wim 0:300d08d9b058 171 #define SET_VERTICAL_SCROLL_AREA 0xA3 // takes 2 bytes: Rows in Top Area (Reset=0), Rows in Scroll Area (Reset=64)
wim 0:300d08d9b058 172
wim 3:fa18169dd7e6 173
wim 3:fa18169dd7e6 174
wim 3:fa18169dd7e6 175 /** Class to control an SSD1308 based oled Display
wim 3:fa18169dd7e6 176 *
wim 3:fa18169dd7e6 177 * Example:
wim 3:fa18169dd7e6 178 * @code
wim 3:fa18169dd7e6 179 * #include "mbed.h"
wim 3:fa18169dd7e6 180 * #include "mbed_logo.h"
wim 3:fa18169dd7e6 181 * #include "SSD1308.h"
wim 3:fa18169dd7e6 182
wim 3:fa18169dd7e6 183 * //Pin Defines for I2C Bus
wim 3:fa18169dd7e6 184 * #define D_SDA p28
wim 3:fa18169dd7e6 185 * #define D_SCL p27
wim 3:fa18169dd7e6 186 * I2C i2c(D_SDA, D_SCL);
wim 3:fa18169dd7e6 187 *
wim 3:fa18169dd7e6 188 * // Host PC Communication channels
wim 3:fa18169dd7e6 189 * Serial pc(USBTX, USBRX); // tx, rx
wim 3:fa18169dd7e6 190 *
wim 3:fa18169dd7e6 191 * // Instantiate OLED
wim 3:fa18169dd7e6 192 * SSD1308 oled = SSD1308(i2c, SSD1308_SA0);
wim 3:fa18169dd7e6 193 *
wim 3:fa18169dd7e6 194 * int main() {
wim 3:fa18169dd7e6 195 * pc.printf("OLED test start\r");
wim 3:fa18169dd7e6 196 * oled.writeString(0, 0, "Hello World !");
wim 3:fa18169dd7e6 197 * // oled.printf("Hello World !");
wim 3:fa18169dd7e6 198 *
wim 3:fa18169dd7e6 199 * oled.fillDisplay(0xAA);
wim 3:fa18169dd7e6 200 * oled.setDisplayOff();
wim 3:fa18169dd7e6 201 * wait(1);
wim 3:fa18169dd7e6 202 * oled.setDisplayOn();
wim 3:fa18169dd7e6 203 *
wim 3:fa18169dd7e6 204 * oled.clearDisplay();
wim 3:fa18169dd7e6 205 * oled.setDisplayInverse();
wim 3:fa18169dd7e6 206 * wait(0.5);
wim 3:fa18169dd7e6 207 * oled.setDisplayNormal();
wim 3:fa18169dd7e6 208 *
wim 3:fa18169dd7e6 209 * oled.writeBitmap((uint8_t*) mbed_logo);
wim 3:fa18169dd7e6 210 *
wim 3:fa18169dd7e6 211 * pc.printf("OLED test done\r\n");
wim 3:fa18169dd7e6 212 * }
wim 3:fa18169dd7e6 213 *
wim 3:fa18169dd7e6 214 * @endcode
wim 3:fa18169dd7e6 215 */
wim 0:300d08d9b058 216 class SSD1308 : public Stream {
wim 0:300d08d9b058 217 public:
wim 0:300d08d9b058 218
wim 2:16c84a134393 219 /**
wim 2:16c84a134393 220 *@brief Constructor
wim 2:16c84a134393 221 *@param I2C &i2c reference to i2c,
wim 2:16c84a134393 222 *@param uint8_t deviceAddress slaveaddress (8bit to use for the controller (0x78 by default, assumes D/C# (pin 13) grounded)
wim 2:16c84a134393 223 */
wim 0:300d08d9b058 224 SSD1308(I2C &i2c, uint8_t address = SSD1308_DEF_SA);
wim 0:300d08d9b058 225
wim 0:300d08d9b058 226 // High Level methods
wim 2:16c84a134393 227
wim 2:16c84a134393 228 /** @brief High level Init, most settings remain at Power-On reset value
wim 2:16c84a134393 229 */
wim 0:300d08d9b058 230 void initialize();
wim 0:300d08d9b058 231
wim 2:16c84a134393 232 /** @brief clear the display
wim 2:16c84a134393 233 */
wim 0:300d08d9b058 234 void clearDisplay();
wim 2:16c84a134393 235
wim 2:16c84a134393 236
wim 2:16c84a134393 237 /** @brief fill the display
wim 2:16c84a134393 238 * @param uint8_t pattern fillpattern vertical patch or 8 bits
wim 2:16c84a134393 239 */
wim 0:300d08d9b058 240 void fillDisplay(uint8_t pattern = 0x00,
wim 0:300d08d9b058 241 uint8_t start_page=0, uint8_t end_page=MAX_PAGE,
wim 0:300d08d9b058 242 uint8_t start_col=0, uint8_t end_col=MAX_COL);
wim 2:16c84a134393 243
wim 2:16c84a134393 244
wim 2:16c84a134393 245 /** @brief write a bitmap to the display
wim 2:16c84a134393 246 * @param uint8_t* data pointer to bitmap
wim 2:16c84a134393 247 * @param uint8_t start_page begin page (0..MAX_PAGE)
wim 2:16c84a134393 248 * @param uint8_t end_page end page (start_page..MAX_PAGE)
wim 2:16c84a134393 249 * @param uint8_t start_col begin column (0..MAX_COL)
wim 2:16c84a134393 250 * @param uint8_t end_col end column (start_col..MAX_COL)
wim 2:16c84a134393 251 */
wim 0:300d08d9b058 252 void writeBitmap(uint8_t* data,
wim 0:300d08d9b058 253 uint8_t start_page=0, uint8_t end_page=MAX_PAGE,
wim 0:300d08d9b058 254 uint8_t start_col=0, uint8_t end_col=MAX_COL);
wim 0:300d08d9b058 255
wim 2:16c84a134393 256 /** @brief write a level meter to the display, Width is (PRG_MAX_SCALE + 2) pixels
wim 2:16c84a134393 257 * @param uint8_t page begin page (0..MAX_PAGE)
wim 2:16c84a134393 258 * @param uint8_t col begin column (0..MAX_COL)
wim 2:16c84a134393 259 * @param int percentage value (0..100)
wim 2:16c84a134393 260 */
wim 2:16c84a134393 261 void writeProgressBar(uint8_t page, uint8_t col, int percentage);
wim 1:b7e8f5139026 262
wim 2:16c84a134393 263
wim 2:16c84a134393 264 /** @brief write a level meter to the display, Width is (PRG_MAX_SCALE + 2) pixels
wim 2:16c84a134393 265 * @param uint8_t page begin page (0..MAX_PAGE)
wim 2:16c84a134393 266 * @param uint8_t col begin column (0..MAX_COL)
wim 2:16c84a134393 267 * @param int percentage value (0..100)
wim 2:16c84a134393 268 */
wim 2:16c84a134393 269 void writeLevelBar(uint8_t page, uint8_t col, int percentage);
wim 1:b7e8f5139026 270
wim 0:300d08d9b058 271 //void setXY(uint8_t, uint8_t y);
wim 0:300d08d9b058 272
wim 0:300d08d9b058 273 // Select inverted or normal text
wim 0:300d08d9b058 274 void setInverted(bool inverted) { _inverted = inverted; };
wim 0:300d08d9b058 275
wim 2:16c84a134393 276 /** @brief Write single character to the display using the 8x8 fontable
wim 2:16c84a134393 277 * @brief Start at current cursor location
wim 2:16c84a134393 278 * @param char chr character to write
wim 2:16c84a134393 279 */
wim 0:300d08d9b058 280 void writeChar(char chr);
wim 0:300d08d9b058 281
wim 2:16c84a134393 282 /** @brief Write large character (16x24 font)
wim 2:16c84a134393 283 * @param uint8_t row row number (0...MAX_ROW)
wim 2:16c84a134393 284 * @param uint8_t col column number (0...MAX_COL)
wim 2:16c84a134393 285 * @param char chr Used for displaying numbers 0 - 9 and '+', '-', '.'
wim 2:16c84a134393 286 */
wim 0:300d08d9b058 287 void writeBigChar(uint8_t row, uint8_t col, char chr);
wim 0:300d08d9b058 288
wim 2:16c84a134393 289 /** @brief Write a string to the display using the 8x8 font
wim 2:16c84a134393 290 * @brief Start at selected cursor location, text will wrap around until it is done
wim 2:16c84a134393 291 * @param uint8_t row row number (0...ROWS/FONT_HEIGHT)
wim 2:16c84a134393 292 * @param uint8_t col column number (0...COLUMNS/FONT_WIDTH)
wim 2:16c84a134393 293 * @param uint16_t len number of chars in text
wim 2:16c84a134393 294 * @param const char * text pointer to text
wim 2:16c84a134393 295 */
wim 2:16c84a134393 296 // void writeString(uint8_t row, uint8_t col, uint16_t len, const char* txt);
wim 2:16c84a134393 297 void writeString(uint8_t row, uint8_t col, const char* txt);
wim 2:16c84a134393 298
wim 0:300d08d9b058 299 // Stream implementation - provides printf() interface
wim 0:300d08d9b058 300 // You would otherwise be forced to use writeChar() or writeString()
wim 0:300d08d9b058 301 virtual int _putc(int value) { writeChar(value); return 1; };
wim 0:300d08d9b058 302 virtual int _getc() { return -1; };
wim 0:300d08d9b058 303
wim 0:300d08d9b058 304 // Future extension with graphics features
wim 0:300d08d9b058 305 // this must be defined by the subclass
wim 0:300d08d9b058 306 // virtual void drawPixel(int16_t x, int16_t y, uint16_t color) = 0;
wim 0:300d08d9b058 307
wim 0:300d08d9b058 308 // Medium Level methods
wim 2:16c84a134393 309
wim 2:16c84a134393 310 /** @brief Set Horizontal Addressing Mode (cursor incr left-to-right, top-to-bottom)
wim 2:16c84a134393 311 *
wim 2:16c84a134393 312 */
wim 0:300d08d9b058 313 void setHorizontalAddressingMode();
wim 2:16c84a134393 314
wim 2:16c84a134393 315 /** @brief Set Vertical Addressing Mode (cursor incr top-to-bottom, left-to-right)
wim 2:16c84a134393 316 *
wim 2:16c84a134393 317 */
wim 0:300d08d9b058 318 void setVerticalAddressingMode();
wim 0:300d08d9b058 319
wim 2:16c84a134393 320 /** @brief Set Page Addressing Mode (cursor incr left-to-right)
wim 2:16c84a134393 321 *
wim 2:16c84a134393 322 */
wim 2:16c84a134393 323 void setPageAddressingMode();
wim 2:16c84a134393 324
wim 2:16c84a134393 325 /** @brief Set Addressing Mode
wim 2:16c84a134393 326 * @param uint8_t mode
wim 2:16c84a134393 327 */
wim 2:16c84a134393 328 void setMemoryAddressingMode(uint8_t mode);
wim 2:16c84a134393 329
wim 2:16c84a134393 330
wim 2:16c84a134393 331 /**
wim 2:16c84a134393 332 * @brief Set Column Start (for Page Addressing Mode only)
wim 2:16c84a134393 333 * @param uint8_t column column start (valid range 0..MAX_COLS)
wim 2:16c84a134393 334 */
wim 2:16c84a134393 335 void setColumnStartForPageAddressingMode(uint8_t column);
wim 0:300d08d9b058 336
wim 2:16c84a134393 337 /**
wim 2:16c84a134393 338 * @brief Set Page Start (for Page Addressing Mode only)
wim 2:16c84a134393 339 * @param uint8_t page page start (valid range PAGE0 - PAGE7)
wim 2:16c84a134393 340 */
wim 2:16c84a134393 341 void setPageStartForPageAddressingMode(uint8_t page);
wim 2:16c84a134393 342
wim 2:16c84a134393 343
wim 2:16c84a134393 344
wim 2:16c84a134393 345 /** @param uint8_t start startcolumn (valid range 0..MAX_COL)
wim 2:16c84a134393 346 * @param uint8_t end endcolumn (valid range start..MAX_COL)
wim 2:16c84a134393 347 */
wim 0:300d08d9b058 348 void setColumnAddress(uint8_t start, uint8_t end);
wim 0:300d08d9b058 349
wim 2:16c84a134393 350 /** @param uint8_t start startpage (valid range 0..MAX_PAGE)
wim 2:16c84a134393 351 * @param uint8_t end endpage (valid range start..MAX_PAGE)
wim 2:16c84a134393 352 */
wim 0:300d08d9b058 353 void setPageAddress(uint8_t start, uint8_t end);
wim 0:300d08d9b058 354
wim 2:16c84a134393 355
wim 2:16c84a134393 356 /**
wim 2:16c84a134393 357 * @brief Set Display StartLine, takes one byte, 0x00-0x3F
wim 2:16c84a134393 358 * @param uint8_t line startline (valid range 0..MAX_ROWS)
wim 2:16c84a134393 359 */
wim 0:300d08d9b058 360 void setDisplayStartLine(uint8_t line);
wim 0:300d08d9b058 361
wim 2:16c84a134393 362 /** @brief Set Contrast
wim 2:16c84a134393 363 * @param uint8_t contrast (valid range 0x00 (lowest) - 0xFF (highest))
wim 2:16c84a134393 364 */
wim 0:300d08d9b058 365 void setContrastControl(uint8_t contrast);
wim 2:16c84a134393 366
wim 2:16c84a134393 367
wim 2:16c84a134393 368 /** @brief Shows All Pixels On
wim 2:16c84a134393 369 */
wim 2:16c84a134393 370 void setEntireDisplayOn();
wim 0:300d08d9b058 371
wim 2:16c84a134393 372 /** @brief Shows Pixels as RAM content
wim 2:16c84a134393 373 */
wim 0:300d08d9b058 374 void setEntireDisplayRAM();
wim 2:16c84a134393 375
wim 2:16c84a134393 376 /** @brief Shows Pixels On or as RAM content
wim 2:16c84a134393 377 * @param bool on (true is All on, false is RAM content)
wim 2:16c84a134393 378 */
wim 0:300d08d9b058 379 void setEntireDisplay(bool on);
wim 0:300d08d9b058 380
wim 2:16c84a134393 381
wim 2:16c84a134393 382 // @brief Set Display line MPX Ratio, takes one byte, 0x00-0x3F
wim 2:16c84a134393 383 // @param uint8_t lines (valid range 0..MAX_ROWS)
wim 2:16c84a134393 384 void setMultiplexRatio(uint8_t lines);
wim 2:16c84a134393 385
wim 2:16c84a134393 386
wim 2:16c84a134393 387 /** @brief Sets Internal Iref
wim 2:16c84a134393 388 */
wim 0:300d08d9b058 389 void setInternalIref();
wim 2:16c84a134393 390
wim 2:16c84a134393 391 /** @brief Sets External Iref (default)
wim 2:16c84a134393 392 */
wim 0:300d08d9b058 393 void setExternalIref();
wim 2:16c84a134393 394
wim 2:16c84a134393 395
wim 2:16c84a134393 396 /** @brief Enable Display
wim 2:16c84a134393 397 */
wim 0:300d08d9b058 398 void setDisplayOn();
wim 2:16c84a134393 399
wim 2:16c84a134393 400 /** @brief Disable Display
wim 2:16c84a134393 401 */
wim 0:300d08d9b058 402 void setDisplayOff();
wim 2:16c84a134393 403
wim 2:16c84a134393 404 /** @brief Enable or Disable Display
wim 2:16c84a134393 405 * @param bool on
wim 2:16c84a134393 406 */
wim 0:300d08d9b058 407 void setDisplayPower(bool on);
wim 0:300d08d9b058 408
wim 2:16c84a134393 409 /** @brief Show White pixels on Black background
wim 2:16c84a134393 410 */
wim 0:300d08d9b058 411 void setDisplayNormal();
wim 2:16c84a134393 412
wim 2:16c84a134393 413 /** @brief Show Black pixels on White background
wim 2:16c84a134393 414 */
wim 0:300d08d9b058 415 void setDisplayInverse();
wim 2:16c84a134393 416
wim 2:16c84a134393 417 /** @brief Blink display by fading in and out over a set number of frames
wim 2:16c84a134393 418 * @param bool on
wim 2:16c84a134393 419 */
wim 2:16c84a134393 420 void setDisplayBlink(bool on);
wim 0:300d08d9b058 421
wim 2:16c84a134393 422 /** @brief Fade out display in set number of frames
wim 2:16c84a134393 423 * @param bool on
wim 2:16c84a134393 424 */
wim 0:300d08d9b058 425 void setDisplayFade(bool on);
wim 0:300d08d9b058 426
wim 2:16c84a134393 427 /** @brief Display Flip (Left/Right, Up/Down)
wim 2:16c84a134393 428 * @param bool left flip Left/Right
wim 2:16c84a134393 429 * @param bool down flip Up/Down
wim 2:16c84a134393 430 */
wim 0:300d08d9b058 431 void setDisplayFlip(bool left, bool down);
wim 0:300d08d9b058 432
wim 2:16c84a134393 433 // Set vertical shift by COM from 0 - 63 (0x00 - 0x3F) (Reset = 0x00)
wim 0:300d08d9b058 434 void setDisplayOffset(uint8_t offset);
wim 0:300d08d9b058 435
wim 2:16c84a134393 436 // Oscillator freq 0x00-0x0F (reset 0x08)
wim 0:300d08d9b058 437 // Divide ratio 0x00-0x0F, value +1 (reset 0x00)
wim 0:300d08d9b058 438 void setDisplayClock(uint8_t divideRatio, uint8_t oscFreq);
wim 0:300d08d9b058 439
wim 0:300d08d9b058 440 // Phase1 0x01-0x0F period of up to 15 DCLK clocks (reset 0x02, 0 is invalid)
wim 0:300d08d9b058 441 // Phase2 0x01-0x0F period of up to 15 DCLK clocks (reset 0x02, 0 is invalid)
wim 0:300d08d9b058 442 void setPrechargePeriod(uint8_t phase1, uint8_t phase2);
wim 0:300d08d9b058 443
wim 2:16c84a134393 444 // See defines above for levels
wim 0:300d08d9b058 445 void setVcomhDeselectLevel(uint8_t level);
wim 2:16c84a134393 446
wim 2:16c84a134393 447
wim 0:300d08d9b058 448 // Command for no-operation
wim 0:300d08d9b058 449 void nop();
wim 0:300d08d9b058 450
wim 2:16c84a134393 451
wim 2:16c84a134393 452 /** @brief Horizontal scroll by one column per interval
wim 2:16c84a134393 453 * @param bool left select Left/Right scroll
wim 2:16c84a134393 454 * @param uint8_t start_page begin page (0..MAX_PAGE)
wim 2:16c84a134393 455 * @param uint8_t end_page end page (start_page..MAX_PAGE)
wim 2:16c84a134393 456 * @param uint8_t interval scroll interval in frames (see codes above)
wim 2:16c84a134393 457 */
wim 2:16c84a134393 458 void setContinuousHorizontalScroll(bool left, uint8_t start_page, uint8_t end_page, uint8_t interval);
wim 2:16c84a134393 459
wim 2:16c84a134393 460
wim 2:16c84a134393 461 /** @brief Horizontal and Vertical scroll by one column per interval
wim 2:16c84a134393 462 * @param bool left select Left/Right scroll
wim 2:16c84a134393 463 * @param uint8_t start_page begin page (0..MAX_PAGE)
wim 2:16c84a134393 464 * @param uint8_t end_page end page (start_page..MAX_PAGE)
wim 2:16c84a134393 465 * @param uint8_t offset vert offset (0x01..0x63)
wim 2:16c84a134393 466 * @param uint8_t interval scroll interval in frames (see codes above)
wim 2:16c84a134393 467 */
wim 2:16c84a134393 468 void setContinuousVerticalAndHorizontalScroll(bool left, uint8_t start_page, uint8_t end_page,
wim 2:16c84a134393 469 uint8_t offset, uint8_t interval);
wim 0:300d08d9b058 470
wim 2:16c84a134393 471 /** @brief Activate or Deactivate Horizontal and Vertical scroll
wim 2:16c84a134393 472 * @brief Note: after deactivating scrolling, the RAM data needs to be rewritten
wim 2:16c84a134393 473 * @param bool on activate scroll
wim 2:16c84a134393 474 */
wim 2:16c84a134393 475 void setDisplayScroll(bool on);
wim 0:300d08d9b058 476
wim 2:16c84a134393 477
wim 2:16c84a134393 478 /** @brief Set Vertical scroll area
wim 2:16c84a134393 479 * @param uint8_t topRowsFixed fixed rows (0..MAX_ROW)
wim 2:16c84a134393 480 * @param uint8_t scrollRowsoffset scroll rows (topRowsFixed..MAX_ROW)
wim 2:16c84a134393 481 */
wim 0:300d08d9b058 482 void setVerticalScrollArea(uint8_t topRowsFixed, uint8_t scrollRows);
wim 0:300d08d9b058 483
wim 0:300d08d9b058 484 private:
wim 0:300d08d9b058 485
wim 0:300d08d9b058 486 // Low Level methods
wim 2:16c84a134393 487
wim 2:16c84a134393 488 /** @brief Write command that has no parameters
wim 2:16c84a134393 489 */
wim 2:16c84a134393 490 void _sendCommand(uint8_t command);
wim 2:16c84a134393 491
wim 2:16c84a134393 492 /** @brief Write command that has one parameter
wim 2:16c84a134393 493 */
wim 0:300d08d9b058 494 void _sendCommand(uint8_t command, uint8_t param1);
wim 2:16c84a134393 495
wim 2:16c84a134393 496 /** @brief Write command that has two parameters
wim 2:16c84a134393 497 */
wim 0:300d08d9b058 498 void _sendCommand(uint8_t command, uint8_t param1, uint8_t param2);
wim 0:300d08d9b058 499 // void sendCommands(uint8_t len, uint8_t* buf);
wim 2:16c84a134393 500
wim 2:16c84a134393 501 /** @brief Write command that has five parameters
wim 2:16c84a134393 502 */
wim 2:16c84a134393 503 void _sendCommand(uint8_t command, uint8_t param1, uint8_t param2,
wim 2:16c84a134393 504 uint8_t param3, uint8_t param4,
wim 2:16c84a134393 505 uint8_t param5);
wim 2:16c84a134393 506
wim 2:16c84a134393 507 /** @brief Write command that has six parameters
wim 2:16c84a134393 508 */
wim 2:16c84a134393 509 void _sendCommand(uint8_t command, uint8_t param1, uint8_t param2,
wim 2:16c84a134393 510 uint8_t param3, uint8_t param4,
wim 2:16c84a134393 511 uint8_t param5, uint8_t param6);
wim 0:300d08d9b058 512
wim 2:16c84a134393 513 /** @brief Write databyte to display
wim 2:16c84a134393 514 * @brief Start at current cursor location
wim 2:16c84a134393 515 * @param uint8_t data databyte to write
wim 2:16c84a134393 516 */
wim 0:300d08d9b058 517 void _sendData(uint8_t data);
wim 2:16c84a134393 518
wim 2:16c84a134393 519 /** @brief Write len bytes from buffer data to display,
wim 2:16c84a134393 520 * @brief Start at current cursor location
wim 2:16c84a134393 521 * @param uint8_t len number of bytes to write
wim 2:16c84a134393 522 * @param uint8_t* data pointer to data
wim 2:16c84a134393 523 */
wim 0:300d08d9b058 524 void _sendData(uint8_t len, uint8_t* data);
wim 0:300d08d9b058 525
wim 2:16c84a134393 526 /** @brief Low level Init
wim 2:16c84a134393 527 * @brief Init the configuration registers in accordance with the datasheet
wim 2:16c84a134393 528 */
wim 0:300d08d9b058 529 void _init();
wim 0:300d08d9b058 530
wim 1:b7e8f5139026 531 I2C _i2c; // I2C bus reference
wim 1:b7e8f5139026 532 uint8_t _readOpcode; // contains the I2C address of the device
wim 1:b7e8f5139026 533 uint8_t _writeOpcode; // contains the I2C address of the device
wim 0:300d08d9b058 534
wim 0:300d08d9b058 535 bool _inverted; // inverted or normal text
wim 0:300d08d9b058 536 };
wim 0:300d08d9b058 537
wim 0:300d08d9b058 538 #endif