I added some member functions to the OLED library.

Dependents:   OLED_graph_Hongli

Committer:
wim
Date:
Mon Jul 23 20:03:18 2012 +0000
Revision:
2:16c84a134393
Parent:
1:b7e8f5139026
Child:
3:fa18169dd7e6
Updated methods

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 0:300d08d9b058 173 class SSD1308 : public Stream {
wim 0:300d08d9b058 174 public:
wim 0:300d08d9b058 175
wim 2:16c84a134393 176 /**
wim 2:16c84a134393 177 *@brief Constructor
wim 2:16c84a134393 178 *@param I2C &i2c reference to i2c,
wim 2:16c84a134393 179 *@param uint8_t deviceAddress slaveaddress (8bit to use for the controller (0x78 by default, assumes D/C# (pin 13) grounded)
wim 2:16c84a134393 180 */
wim 0:300d08d9b058 181 SSD1308(I2C &i2c, uint8_t address = SSD1308_DEF_SA);
wim 0:300d08d9b058 182
wim 0:300d08d9b058 183 // High Level methods
wim 2:16c84a134393 184
wim 2:16c84a134393 185 /** @brief High level Init, most settings remain at Power-On reset value
wim 2:16c84a134393 186 */
wim 0:300d08d9b058 187 void initialize();
wim 0:300d08d9b058 188
wim 2:16c84a134393 189 /** @brief clear the display
wim 2:16c84a134393 190 */
wim 0:300d08d9b058 191 void clearDisplay();
wim 2:16c84a134393 192
wim 2:16c84a134393 193
wim 2:16c84a134393 194 /** @brief fill the display
wim 2:16c84a134393 195 * @param uint8_t pattern fillpattern vertical patch or 8 bits
wim 2:16c84a134393 196 */
wim 0:300d08d9b058 197 void fillDisplay(uint8_t pattern = 0x00,
wim 0:300d08d9b058 198 uint8_t start_page=0, uint8_t end_page=MAX_PAGE,
wim 0:300d08d9b058 199 uint8_t start_col=0, uint8_t end_col=MAX_COL);
wim 2:16c84a134393 200
wim 2:16c84a134393 201
wim 2:16c84a134393 202 /** @brief write a bitmap to the display
wim 2:16c84a134393 203 * @param uint8_t* data pointer to bitmap
wim 2:16c84a134393 204 * @param uint8_t start_page begin page (0..MAX_PAGE)
wim 2:16c84a134393 205 * @param uint8_t end_page end page (start_page..MAX_PAGE)
wim 2:16c84a134393 206 * @param uint8_t start_col begin column (0..MAX_COL)
wim 2:16c84a134393 207 * @param uint8_t end_col end column (start_col..MAX_COL)
wim 2:16c84a134393 208 */
wim 0:300d08d9b058 209 void writeBitmap(uint8_t* data,
wim 0:300d08d9b058 210 uint8_t start_page=0, uint8_t end_page=MAX_PAGE,
wim 0:300d08d9b058 211 uint8_t start_col=0, uint8_t end_col=MAX_COL);
wim 0:300d08d9b058 212
wim 2:16c84a134393 213 /** @brief write a level meter to the display, Width is (PRG_MAX_SCALE + 2) pixels
wim 2:16c84a134393 214 * @param uint8_t page begin page (0..MAX_PAGE)
wim 2:16c84a134393 215 * @param uint8_t col begin column (0..MAX_COL)
wim 2:16c84a134393 216 * @param int percentage value (0..100)
wim 2:16c84a134393 217 */
wim 2:16c84a134393 218 void writeProgressBar(uint8_t page, uint8_t col, int percentage);
wim 1:b7e8f5139026 219
wim 2:16c84a134393 220
wim 2:16c84a134393 221 /** @brief write a level meter to the display, Width is (PRG_MAX_SCALE + 2) pixels
wim 2:16c84a134393 222 * @param uint8_t page begin page (0..MAX_PAGE)
wim 2:16c84a134393 223 * @param uint8_t col begin column (0..MAX_COL)
wim 2:16c84a134393 224 * @param int percentage value (0..100)
wim 2:16c84a134393 225 */
wim 2:16c84a134393 226 void writeLevelBar(uint8_t page, uint8_t col, int percentage);
wim 1:b7e8f5139026 227
wim 0:300d08d9b058 228 //void setXY(uint8_t, uint8_t y);
wim 0:300d08d9b058 229
wim 0:300d08d9b058 230 // Select inverted or normal text
wim 0:300d08d9b058 231 void setInverted(bool inverted) { _inverted = inverted; };
wim 0:300d08d9b058 232
wim 2:16c84a134393 233 /** @brief Write single character to the display using the 8x8 fontable
wim 2:16c84a134393 234 * @brief Start at current cursor location
wim 2:16c84a134393 235 * @param char chr character to write
wim 2:16c84a134393 236 */
wim 0:300d08d9b058 237 void writeChar(char chr);
wim 0:300d08d9b058 238
wim 2:16c84a134393 239 /** @brief Write large character (16x24 font)
wim 2:16c84a134393 240 * @param uint8_t row row number (0...MAX_ROW)
wim 2:16c84a134393 241 * @param uint8_t col column number (0...MAX_COL)
wim 2:16c84a134393 242 * @param char chr Used for displaying numbers 0 - 9 and '+', '-', '.'
wim 2:16c84a134393 243 */
wim 0:300d08d9b058 244 void writeBigChar(uint8_t row, uint8_t col, char chr);
wim 0:300d08d9b058 245
wim 2:16c84a134393 246 /** @brief Write a string to the display using the 8x8 font
wim 2:16c84a134393 247 * @brief Start at selected cursor location, text will wrap around until it is done
wim 2:16c84a134393 248 * @param uint8_t row row number (0...ROWS/FONT_HEIGHT)
wim 2:16c84a134393 249 * @param uint8_t col column number (0...COLUMNS/FONT_WIDTH)
wim 2:16c84a134393 250 * @param uint16_t len number of chars in text
wim 2:16c84a134393 251 * @param const char * text pointer to text
wim 2:16c84a134393 252 */
wim 2:16c84a134393 253 // void writeString(uint8_t row, uint8_t col, uint16_t len, const char* txt);
wim 2:16c84a134393 254 void writeString(uint8_t row, uint8_t col, const char* txt);
wim 2:16c84a134393 255
wim 0:300d08d9b058 256 // Stream implementation - provides printf() interface
wim 0:300d08d9b058 257 // You would otherwise be forced to use writeChar() or writeString()
wim 0:300d08d9b058 258 virtual int _putc(int value) { writeChar(value); return 1; };
wim 0:300d08d9b058 259 virtual int _getc() { return -1; };
wim 0:300d08d9b058 260
wim 0:300d08d9b058 261 // Future extension with graphics features
wim 0:300d08d9b058 262 // this must be defined by the subclass
wim 0:300d08d9b058 263 // virtual void drawPixel(int16_t x, int16_t y, uint16_t color) = 0;
wim 0:300d08d9b058 264
wim 0:300d08d9b058 265 // Medium Level methods
wim 2:16c84a134393 266
wim 2:16c84a134393 267 /** @brief Set Horizontal Addressing Mode (cursor incr left-to-right, top-to-bottom)
wim 2:16c84a134393 268 *
wim 2:16c84a134393 269 */
wim 0:300d08d9b058 270 void setHorizontalAddressingMode();
wim 2:16c84a134393 271
wim 2:16c84a134393 272 /** @brief Set Vertical Addressing Mode (cursor incr top-to-bottom, left-to-right)
wim 2:16c84a134393 273 *
wim 2:16c84a134393 274 */
wim 0:300d08d9b058 275 void setVerticalAddressingMode();
wim 0:300d08d9b058 276
wim 2:16c84a134393 277 /** @brief Set Page Addressing Mode (cursor incr left-to-right)
wim 2:16c84a134393 278 *
wim 2:16c84a134393 279 */
wim 2:16c84a134393 280 void setPageAddressingMode();
wim 2:16c84a134393 281
wim 2:16c84a134393 282 /** @brief Set Addressing Mode
wim 2:16c84a134393 283 * @param uint8_t mode
wim 2:16c84a134393 284 */
wim 2:16c84a134393 285 void setMemoryAddressingMode(uint8_t mode);
wim 2:16c84a134393 286
wim 2:16c84a134393 287
wim 2:16c84a134393 288 /**
wim 2:16c84a134393 289 * @brief Set Column Start (for Page Addressing Mode only)
wim 2:16c84a134393 290 * @param uint8_t column column start (valid range 0..MAX_COLS)
wim 2:16c84a134393 291 */
wim 2:16c84a134393 292 void setColumnStartForPageAddressingMode(uint8_t column);
wim 0:300d08d9b058 293
wim 2:16c84a134393 294 /**
wim 2:16c84a134393 295 * @brief Set Page Start (for Page Addressing Mode only)
wim 2:16c84a134393 296 * @param uint8_t page page start (valid range PAGE0 - PAGE7)
wim 2:16c84a134393 297 */
wim 2:16c84a134393 298 void setPageStartForPageAddressingMode(uint8_t page);
wim 2:16c84a134393 299
wim 2:16c84a134393 300
wim 2:16c84a134393 301
wim 2:16c84a134393 302 /** @param uint8_t start startcolumn (valid range 0..MAX_COL)
wim 2:16c84a134393 303 * @param uint8_t end endcolumn (valid range start..MAX_COL)
wim 2:16c84a134393 304 */
wim 0:300d08d9b058 305 void setColumnAddress(uint8_t start, uint8_t end);
wim 0:300d08d9b058 306
wim 2:16c84a134393 307 /** @param uint8_t start startpage (valid range 0..MAX_PAGE)
wim 2:16c84a134393 308 * @param uint8_t end endpage (valid range start..MAX_PAGE)
wim 2:16c84a134393 309 */
wim 0:300d08d9b058 310 void setPageAddress(uint8_t start, uint8_t end);
wim 0:300d08d9b058 311
wim 2:16c84a134393 312
wim 2:16c84a134393 313 /**
wim 2:16c84a134393 314 * @brief Set Display StartLine, takes one byte, 0x00-0x3F
wim 2:16c84a134393 315 * @param uint8_t line startline (valid range 0..MAX_ROWS)
wim 2:16c84a134393 316 */
wim 0:300d08d9b058 317 void setDisplayStartLine(uint8_t line);
wim 0:300d08d9b058 318
wim 2:16c84a134393 319 /** @brief Set Contrast
wim 2:16c84a134393 320 * @param uint8_t contrast (valid range 0x00 (lowest) - 0xFF (highest))
wim 2:16c84a134393 321 */
wim 0:300d08d9b058 322 void setContrastControl(uint8_t contrast);
wim 2:16c84a134393 323
wim 2:16c84a134393 324
wim 2:16c84a134393 325 /** @brief Shows All Pixels On
wim 2:16c84a134393 326 */
wim 2:16c84a134393 327 void setEntireDisplayOn();
wim 0:300d08d9b058 328
wim 2:16c84a134393 329 /** @brief Shows Pixels as RAM content
wim 2:16c84a134393 330 */
wim 0:300d08d9b058 331 void setEntireDisplayRAM();
wim 2:16c84a134393 332
wim 2:16c84a134393 333 /** @brief Shows Pixels On or as RAM content
wim 2:16c84a134393 334 * @param bool on (true is All on, false is RAM content)
wim 2:16c84a134393 335 */
wim 0:300d08d9b058 336 void setEntireDisplay(bool on);
wim 0:300d08d9b058 337
wim 2:16c84a134393 338
wim 2:16c84a134393 339 // @brief Set Display line MPX Ratio, takes one byte, 0x00-0x3F
wim 2:16c84a134393 340 // @param uint8_t lines (valid range 0..MAX_ROWS)
wim 2:16c84a134393 341 void setMultiplexRatio(uint8_t lines);
wim 2:16c84a134393 342
wim 2:16c84a134393 343
wim 2:16c84a134393 344 /** @brief Sets Internal Iref
wim 2:16c84a134393 345 */
wim 0:300d08d9b058 346 void setInternalIref();
wim 2:16c84a134393 347
wim 2:16c84a134393 348 /** @brief Sets External Iref (default)
wim 2:16c84a134393 349 */
wim 0:300d08d9b058 350 void setExternalIref();
wim 2:16c84a134393 351
wim 2:16c84a134393 352
wim 2:16c84a134393 353 /** @brief Enable Display
wim 2:16c84a134393 354 */
wim 0:300d08d9b058 355 void setDisplayOn();
wim 2:16c84a134393 356
wim 2:16c84a134393 357 /** @brief Disable Display
wim 2:16c84a134393 358 */
wim 0:300d08d9b058 359 void setDisplayOff();
wim 2:16c84a134393 360
wim 2:16c84a134393 361 /** @brief Enable or Disable Display
wim 2:16c84a134393 362 * @param bool on
wim 2:16c84a134393 363 */
wim 0:300d08d9b058 364 void setDisplayPower(bool on);
wim 0:300d08d9b058 365
wim 2:16c84a134393 366 /** @brief Show White pixels on Black background
wim 2:16c84a134393 367 */
wim 0:300d08d9b058 368 void setDisplayNormal();
wim 2:16c84a134393 369
wim 2:16c84a134393 370 /** @brief Show Black pixels on White background
wim 2:16c84a134393 371 */
wim 0:300d08d9b058 372 void setDisplayInverse();
wim 2:16c84a134393 373
wim 2:16c84a134393 374 /** @brief Blink display by fading in and out over a set number of frames
wim 2:16c84a134393 375 * @param bool on
wim 2:16c84a134393 376 */
wim 2:16c84a134393 377 void setDisplayBlink(bool on);
wim 0:300d08d9b058 378
wim 2:16c84a134393 379 /** @brief Fade out display in set number of frames
wim 2:16c84a134393 380 * @param bool on
wim 2:16c84a134393 381 */
wim 0:300d08d9b058 382 void setDisplayFade(bool on);
wim 0:300d08d9b058 383
wim 2:16c84a134393 384 /** @brief Display Flip (Left/Right, Up/Down)
wim 2:16c84a134393 385 * @param bool left flip Left/Right
wim 2:16c84a134393 386 * @param bool down flip Up/Down
wim 2:16c84a134393 387 */
wim 0:300d08d9b058 388 void setDisplayFlip(bool left, bool down);
wim 0:300d08d9b058 389
wim 2:16c84a134393 390 // Set vertical shift by COM from 0 - 63 (0x00 - 0x3F) (Reset = 0x00)
wim 0:300d08d9b058 391 void setDisplayOffset(uint8_t offset);
wim 0:300d08d9b058 392
wim 2:16c84a134393 393 // Oscillator freq 0x00-0x0F (reset 0x08)
wim 0:300d08d9b058 394 // Divide ratio 0x00-0x0F, value +1 (reset 0x00)
wim 0:300d08d9b058 395 void setDisplayClock(uint8_t divideRatio, uint8_t oscFreq);
wim 0:300d08d9b058 396
wim 0:300d08d9b058 397 // Phase1 0x01-0x0F period of up to 15 DCLK clocks (reset 0x02, 0 is invalid)
wim 0:300d08d9b058 398 // Phase2 0x01-0x0F period of up to 15 DCLK clocks (reset 0x02, 0 is invalid)
wim 0:300d08d9b058 399 void setPrechargePeriod(uint8_t phase1, uint8_t phase2);
wim 0:300d08d9b058 400
wim 2:16c84a134393 401 // See defines above for levels
wim 0:300d08d9b058 402 void setVcomhDeselectLevel(uint8_t level);
wim 2:16c84a134393 403
wim 2:16c84a134393 404
wim 0:300d08d9b058 405 // Command for no-operation
wim 0:300d08d9b058 406 void nop();
wim 0:300d08d9b058 407
wim 2:16c84a134393 408
wim 2:16c84a134393 409 /** @brief Horizontal scroll by one column per interval
wim 2:16c84a134393 410 * @param bool left select Left/Right scroll
wim 2:16c84a134393 411 * @param uint8_t start_page begin page (0..MAX_PAGE)
wim 2:16c84a134393 412 * @param uint8_t end_page end page (start_page..MAX_PAGE)
wim 2:16c84a134393 413 * @param uint8_t interval scroll interval in frames (see codes above)
wim 2:16c84a134393 414 */
wim 2:16c84a134393 415 void setContinuousHorizontalScroll(bool left, uint8_t start_page, uint8_t end_page, uint8_t interval);
wim 2:16c84a134393 416
wim 2:16c84a134393 417
wim 2:16c84a134393 418 /** @brief Horizontal and Vertical scroll by one column per interval
wim 2:16c84a134393 419 * @param bool left select Left/Right scroll
wim 2:16c84a134393 420 * @param uint8_t start_page begin page (0..MAX_PAGE)
wim 2:16c84a134393 421 * @param uint8_t end_page end page (start_page..MAX_PAGE)
wim 2:16c84a134393 422 * @param uint8_t offset vert offset (0x01..0x63)
wim 2:16c84a134393 423 * @param uint8_t interval scroll interval in frames (see codes above)
wim 2:16c84a134393 424 */
wim 2:16c84a134393 425 void setContinuousVerticalAndHorizontalScroll(bool left, uint8_t start_page, uint8_t end_page,
wim 2:16c84a134393 426 uint8_t offset, uint8_t interval);
wim 0:300d08d9b058 427
wim 2:16c84a134393 428 /** @brief Activate or Deactivate Horizontal and Vertical scroll
wim 2:16c84a134393 429 * @brief Note: after deactivating scrolling, the RAM data needs to be rewritten
wim 2:16c84a134393 430 * @param bool on activate scroll
wim 2:16c84a134393 431 */
wim 2:16c84a134393 432 void setDisplayScroll(bool on);
wim 0:300d08d9b058 433
wim 2:16c84a134393 434
wim 2:16c84a134393 435 /** @brief Set Vertical scroll area
wim 2:16c84a134393 436 * @param uint8_t topRowsFixed fixed rows (0..MAX_ROW)
wim 2:16c84a134393 437 * @param uint8_t scrollRowsoffset scroll rows (topRowsFixed..MAX_ROW)
wim 2:16c84a134393 438 */
wim 0:300d08d9b058 439 void setVerticalScrollArea(uint8_t topRowsFixed, uint8_t scrollRows);
wim 0:300d08d9b058 440
wim 0:300d08d9b058 441 private:
wim 0:300d08d9b058 442
wim 0:300d08d9b058 443 // Low Level methods
wim 2:16c84a134393 444
wim 2:16c84a134393 445 /** @brief Write command that has no parameters
wim 2:16c84a134393 446 */
wim 2:16c84a134393 447 void _sendCommand(uint8_t command);
wim 2:16c84a134393 448
wim 2:16c84a134393 449 /** @brief Write command that has one parameter
wim 2:16c84a134393 450 */
wim 0:300d08d9b058 451 void _sendCommand(uint8_t command, uint8_t param1);
wim 2:16c84a134393 452
wim 2:16c84a134393 453 /** @brief Write command that has two parameters
wim 2:16c84a134393 454 */
wim 0:300d08d9b058 455 void _sendCommand(uint8_t command, uint8_t param1, uint8_t param2);
wim 0:300d08d9b058 456 // void sendCommands(uint8_t len, uint8_t* buf);
wim 2:16c84a134393 457
wim 2:16c84a134393 458 /** @brief Write command that has five parameters
wim 2:16c84a134393 459 */
wim 2:16c84a134393 460 void _sendCommand(uint8_t command, uint8_t param1, uint8_t param2,
wim 2:16c84a134393 461 uint8_t param3, uint8_t param4,
wim 2:16c84a134393 462 uint8_t param5);
wim 2:16c84a134393 463
wim 2:16c84a134393 464 /** @brief Write command that has six parameters
wim 2:16c84a134393 465 */
wim 2:16c84a134393 466 void _sendCommand(uint8_t command, uint8_t param1, uint8_t param2,
wim 2:16c84a134393 467 uint8_t param3, uint8_t param4,
wim 2:16c84a134393 468 uint8_t param5, uint8_t param6);
wim 0:300d08d9b058 469
wim 2:16c84a134393 470 /** @brief Write databyte to display
wim 2:16c84a134393 471 * @brief Start at current cursor location
wim 2:16c84a134393 472 * @param uint8_t data databyte to write
wim 2:16c84a134393 473 */
wim 0:300d08d9b058 474 void _sendData(uint8_t data);
wim 2:16c84a134393 475
wim 2:16c84a134393 476 /** @brief Write len bytes from buffer data to display,
wim 2:16c84a134393 477 * @brief Start at current cursor location
wim 2:16c84a134393 478 * @param uint8_t len number of bytes to write
wim 2:16c84a134393 479 * @param uint8_t* data pointer to data
wim 2:16c84a134393 480 */
wim 0:300d08d9b058 481 void _sendData(uint8_t len, uint8_t* data);
wim 0:300d08d9b058 482
wim 2:16c84a134393 483 /** @brief Low level Init
wim 2:16c84a134393 484 * @brief Init the configuration registers in accordance with the datasheet
wim 2:16c84a134393 485 */
wim 0:300d08d9b058 486 void _init();
wim 0:300d08d9b058 487
wim 1:b7e8f5139026 488 I2C _i2c; // I2C bus reference
wim 1:b7e8f5139026 489 uint8_t _readOpcode; // contains the I2C address of the device
wim 1:b7e8f5139026 490 uint8_t _writeOpcode; // contains the I2C address of the device
wim 0:300d08d9b058 491
wim 0:300d08d9b058 492 bool _inverted; // inverted or normal text
wim 0:300d08d9b058 493 };
wim 0:300d08d9b058 494
wim 0:300d08d9b058 495 #endif