upm  0.5.1
Sensor/Actuator repository for libmraa (v0.9.1)
 All Data Structures Files Functions Variables Enumerations Enumerator Macros Groups Pages
ssd1306.h
1 /*
2  * Author: Marc Graham <marc@m2ag.net>
3  * Copyright (c) 2015 Intel Corporation
4  *
5  * Adapted from ssd1308 library.
6  * Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
7  * Copyright (c) 2014 Intel Corporation.
8  *
9  * Permission is hereby granted, free of charge, to any person obtaining
10  * a copy of this software and associated documentation files (the
11  * "Software"), to deal in the Software without restriction, including
12  * without limitation the rights to use, copy, modify, merge, publish,
13  * distribute, sublicense, and/or sell copies of the Software, and to
14  * permit persons to whom the Software is furnished to do so, subject to
15  * the following conditions:
16  *
17  * The above copyright notice and this permission notice shall be
18  * included in all copies or substantial portions of the Software.
19  *
20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27  */
28 
29 #pragma once
30 
31 #include <string>
32 #include <mraa/i2c.hpp>
33 #include "lcd.h"
34 #include "ssd.h"
35 
36 namespace upm
37 {
38 const uint8_t DISPLAY_CMD_SET_NORMAL_1306 = 0xA6;
39 const uint8_t SSD1306_SETCONTRAST = 0x81;
40 const uint8_t SSD1306_DISPLAYALLON_RESUME =0xA4;
41 const uint8_t SSD1306_DISPLAYALLON = 0xA5;
42 const uint8_t DISPLAY_CMD_SET_INVERT_1306 = 0xA7;
43 
44 const uint8_t SSD1306_SETDISPLAYOFFSET =0xD3;
45 const uint8_t SSD1306_SETCOMPINS = 0xDA;
46 
47 const uint8_t SSD1306_SETVCOMDETECT = 0xDB;
48 
49 const uint8_t SSD1306_SETDISPLAYCLOCKDIV = 0xD5;
50 const uint8_t SSD1306_SETPRECHARGE = 0xD9;
51 
52 const uint8_t SSD1306_SETMULTIPLEX = 0xA8;
53 
54 const uint8_t SSD1306_SETLOWCOLUM = 0x00;
55 const uint8_t SSD1306_SETHIGHCOLUMN = 0x10;
56 
57 const uint8_t SSD1306_SETSTARTLINE = 0x40;
58 
59 const uint8_t SSD1306_MEMORYMODE = 0x20;
60 const uint8_t SSD1306_COLUMNADDR = 0x21;
61 const uint8_t SSD1306_PAGEADDR = 0x22;
62 
63 const uint8_t SSD1306_COMSCANINC = 0xC0;
64 const uint8_t SSD1306_COMSCANDEC = 0xC8;
65 
66 const uint8_t SSD1306_SEGREMAP = 0xA0;
67 
68 const uint8_t SSD1306_CHARGEPUMP = 0x8D;
69 
70 const uint8_t SSD1306_EXTERNALVCC = 0x1;
71 const uint8_t SSD1306_SWITCHCAPVCC = 0x2;
72 
73 // Scrolling const uint8_t s
74 const uint8_t SSD1306_ACTIVATE_SCROLL = 0x2F;
75 const uint8_t SSD1306_DEACTIVATE_SCROLL = 0x2E;
76 const uint8_t SSD1306_SET_VERTICAL_SCROLL_AREA = 0xA3;
77 const uint8_t SSD1306_RIGHT_HORIZONTAL_SCROLL = 0x26;
78 const uint8_t SSD1306_LEFT_HORIZONTAL_SCROLL = 0x27;
79 const uint8_t SSD1306_VERTICAL_AND_RIGHT_HORIZONTAL_SCROLL = 0x29;
80 const uint8_t SSD1306_VERTICAL_AND_LEFT_HORIZONTAL_SCROLL = 0x2A;
81 
82 const uint8_t SSD1306_BLACK = 0;
83 const uint8_t SSD1306_WHITE = 1;
84 const uint8_t SSD1306_LCDWIDTH = 128;
85 const uint8_t SSD1306_LCDHEIGHT = 64;
86 
108 class SSD1306 : public LCD
109 {
110  public:
117  SSD1306(int bus, int address = 0x3C);
121  ~SSD1306();
130  mraa::Result draw(uint8_t* data, int bytes);
138  mraa::Result write(std::string msg);
146  mraa::Result setCursor(int row, int column);
152  mraa::Result clear();
158  mraa::Result home();
165  mraa::Result invert(bool i);
175  void startscrollright(uint8_t start, uint8_t stop);
185  void startscrollleft(uint8_t start, uint8_t stop);
195  void startscrolldiagright(uint8_t start, uint8_t stop);
205  void startscrolldiagleft(uint8_t start, uint8_t stop);
211  void stopscroll(void);
218  void dim(bool dim);
219 
220  private:
221  mraa::Result writeChar(uint8_t value);
222  mraa::Result setNormalDisplay();
223  mraa::Result setAddressingMode(displayAddressingMode mode);
224 
225  int m_lcd_control_address;
226  mraa::I2c m_i2c_lcd_control;
227 
228  int _vccstate;
229 };
230 }
void dim(bool dim)
Definition: ssd1306.cxx:297
mraa::Result write(std::string msg)
Definition: ssd1306.cxx:135
mraa::Result invert(bool i)
Definition: ssd1306.cxx:229
void startscrollright(uint8_t start, uint8_t stop)
Definition: ssd1306.cxx:241
void startscrolldiagright(uint8_t start, uint8_t stop)
Definition: ssd1306.cxx:264
mraa::Result clear()
Definition: ssd1306.cxx:164
SSD1306(int bus, int address=0x3C)
Definition: ssd1306.cxx:37
~SSD1306()
Definition: ssd1306.cxx:112
Definition: lcd.h:37
mraa::Result draw(uint8_t *data, int bytes)
Definition: ssd1306.cxx:117
void stopscroll(void)
Definition: ssd1306.cxx:290
mraa::Result setCursor(int row, int column)
Definition: ssd1306.cxx:148
mraa::Result home()
Definition: ssd1306.cxx:185
void startscrolldiagleft(uint8_t start, uint8_t stop)
Definition: ssd1306.cxx:277
API for SSD1306 I2C-controlled OLED displays.
Definition: ssd1306.h:108
void startscrollleft(uint8_t start, uint8_t stop)
Definition: ssd1306.cxx:253