upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
ssd1351.hpp
1 /*
2  * Author: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
3  * Copyright (c) 2016 Intel Corporation.
4  *
5  * Based on Adafruit SSD1351 library.
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining
8  * a copy of this software and associated documentation files (the
9  * "Software"), to deal in the Software without restriction, including
10  * without limitation the rights to use, copy, modify, merge, publish,
11  * distribute, sublicense, and/or sell copies of the Software, and to
12  * permit persons to whom the Software is furnished to do so, subject to
13  * the following conditions:
14  *
15  * The above copyright notice and this permission notice shall be
16  * included in all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25  */
26 #pragma once
27 
28 #include <string>
29 
30 #include <mraa/gpio.hpp>
31 #include <mraa/spi.hpp>
32 #include "ssd1351_gfx.hpp"
33 
34 // Display Size
35 #define SSD1351WIDTH 128
36 #define SSD1351HEIGHT 128 // Set this to 96 for 1.27"
37 
38 // SSD1351 Commands
39 #define SSD1351_CMD_SETCOLUMN 0x15
40 #define SSD1351_CMD_SETROW 0x75
41 #define SSD1351_CMD_WRITERAM 0x5C
42 #define SSD1351_CMD_READRAM 0x5D
43 #define SSD1351_CMD_SETREMAP 0xA0
44 #define SSD1351_CMD_STARTLINE 0xA1
45 #define SSD1351_CMD_DISPLAYOFFSET 0xA2
46 #define SSD1351_CMD_DISPLAYALLOFF 0xA4
47 #define SSD1351_CMD_DISPLAYALLON 0xA5
48 #define SSD1351_CMD_NORMALDISPLAY 0xA6
49 #define SSD1351_CMD_INVERTDISPLAY 0xA7
50 #define SSD1351_CMD_FUNCTIONSELECT 0xAB
51 #define SSD1351_CMD_DISPLAYOFF 0xAE
52 #define SSD1351_CMD_DISPLAYON 0xAF
53 #define SSD1351_CMD_PRECHARGE 0xB1
54 #define SSD1351_CMD_DISPLAYENHANCE 0xB2
55 #define SSD1351_CMD_CLOCKDIV 0xB3
56 #define SSD1351_CMD_SETVSL 0xB4
57 #define SSD1351_CMD_SETGPIO 0xB5
58 #define SSD1351_CMD_PRECHARGE2 0xB6
59 #define SSD1351_CMD_SETGRAY 0xB8
60 #define SSD1351_CMD_USELUT 0xB9
61 #define SSD1351_CMD_PRECHARGELEVEL 0xBB
62 #define SSD1351_CMD_VCOMH 0xBE
63 #define SSD1351_CMD_CONTRASTABC 0xC1
64 #define SSD1351_CMD_CONTRASTMASTER 0xC7
65 #define SSD1351_CMD_MUXRATIO 0xCA
66 #define SSD1351_CMD_COMMANDLOCK 0xFD
67 #define SSD1351_CMD_HORIZSCROLL 0x96
68 #define SSD1351_CMD_STOPSCROLL 0x9E
69 #define SSD1351_CMD_STARTSCROLL 0x9F
70 
71 #define HIGH 1
72 #define LOW 0
73 
74 // Number of blocks for SPI transfer of buffer
75 #define BLOCKS 8
76 
77 namespace upm {
105 class SSD1351 : public GFX{
106  public:
114  SSD1351 (int oc, int dc, int rst);
115 
119  ~SSD1351();
120 
124  std::string name()
125  {
126  return m_name;
127  }
128 
134  void writeCommand (uint8_t value);
135 
141  void writeData (uint8_t value);
149  void drawPixel (int16_t x, int16_t y, uint16_t color);
150 
154  void refresh ();
155 
159  void ocLow ();
160 
164  void ocHigh ();
165 
169  void dcLow ();
170 
174  void dcHigh ();
175 
181  void useMemoryMap (bool var);
182  private:
183  mraa::Spi m_spi;
184  uint8_t m_map[SSD1351HEIGHT * SSD1351WIDTH * 2];
185  bool m_usemap;
186 
187  mraa::Gpio m_oc;
188  mraa::Gpio m_dc;
189  mraa::Gpio m_rst;
190 
191  std::string m_name;
192 };
193 }
SSD1351(int oc, int dc, int rst)
Definition: ssd1351.cxx:38
~SSD1351()
Definition: ssd1351.cxx:145
GFX helper class.
Definition: ili9341_gfx.hpp:39
void ocLow()
Definition: ssd1351.cxx:193
void dcHigh()
Definition: ssd1351.cxx:214
void drawPixel(int16_t x, int16_t y, uint16_t color)
Definition: ssd1351.cxx:161
C++ API wrapper for the bh1749 driver.
Definition: a110x.hpp:29
void refresh()
Definition: ssd1351.cxx:184
API for SSD1351 OLED displays.
Definition: ssd1351.hpp:105
void ocHigh()
Definition: ssd1351.cxx:200
void dcLow()
Definition: ssd1351.cxx:207
std::string name()
Definition: ssd1351.hpp:124
void writeData(uint8_t value)
Definition: ssd1351.cxx:155
void writeCommand(uint8_t value)
Definition: ssd1351.cxx:149
void useMemoryMap(bool var)
Definition: ssd1351.cxx:221