upm  0.8.0
Sensor/Actuator repository for libmraa (v1.1.1)
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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/common.hpp>
31 #include <mraa/gpio.hpp>
32 #include <mraa/spi.hpp>
33 #include "ssd1351_gfx.hpp"
34 
35 // Display Size
36 #define SSD1351WIDTH 128
37 #define SSD1351HEIGHT 128 // Set this to 96 for 1.27"
38 
39 // SSD1351 Commands
40 #define SSD1351_CMD_SETCOLUMN 0x15
41 #define SSD1351_CMD_SETROW 0x75
42 #define SSD1351_CMD_WRITERAM 0x5C
43 #define SSD1351_CMD_READRAM 0x5D
44 #define SSD1351_CMD_SETREMAP 0xA0
45 #define SSD1351_CMD_STARTLINE 0xA1
46 #define SSD1351_CMD_DISPLAYOFFSET 0xA2
47 #define SSD1351_CMD_DISPLAYALLOFF 0xA4
48 #define SSD1351_CMD_DISPLAYALLON 0xA5
49 #define SSD1351_CMD_NORMALDISPLAY 0xA6
50 #define SSD1351_CMD_INVERTDISPLAY 0xA7
51 #define SSD1351_CMD_FUNCTIONSELECT 0xAB
52 #define SSD1351_CMD_DISPLAYOFF 0xAE
53 #define SSD1351_CMD_DISPLAYON 0xAF
54 #define SSD1351_CMD_PRECHARGE 0xB1
55 #define SSD1351_CMD_DISPLAYENHANCE 0xB2
56 #define SSD1351_CMD_CLOCKDIV 0xB3
57 #define SSD1351_CMD_SETVSL 0xB4
58 #define SSD1351_CMD_SETGPIO 0xB5
59 #define SSD1351_CMD_PRECHARGE2 0xB6
60 #define SSD1351_CMD_SETGRAY 0xB8
61 #define SSD1351_CMD_USELUT 0xB9
62 #define SSD1351_CMD_PRECHARGELEVEL 0xBB
63 #define SSD1351_CMD_VCOMH 0xBE
64 #define SSD1351_CMD_CONTRASTABC 0xC1
65 #define SSD1351_CMD_CONTRASTMASTER 0xC7
66 #define SSD1351_CMD_MUXRATIO 0xCA
67 #define SSD1351_CMD_COMMANDLOCK 0xFD
68 #define SSD1351_CMD_HORIZSCROLL 0x96
69 #define SSD1351_CMD_STOPSCROLL 0x9E
70 #define SSD1351_CMD_STARTSCROLL 0x9F
71 
72 #define HIGH 1
73 #define LOW 0
74 
75 // Number of blocks for SPI transfer of buffer
76 #define BLOCKS 8
77 
78 namespace upm {
106 class SSD1351 : public GFX{
107  public:
115  SSD1351 (uint8_t oc, uint8_t dc, uint8_t rst);
116 
120  ~SSD1351();
121 
125  std::string name()
126  {
127  return m_name;
128  }
129 
135  void writeCommand (uint8_t value);
136 
142  void writeData (uint8_t value);
150  void drawPixel (int16_t x, int16_t y, uint16_t color);
151 
155  void refresh ();
156 
160  void ocLow ();
161 
165  void ocHigh ();
166 
170  void dcLow ();
171 
175  void dcHigh ();
176 
182  void useMemoryMap (bool var);
183  private:
184  mraa::Spi m_spi;
185  uint8_t m_map[SSD1351HEIGHT * SSD1351WIDTH * 2];
186  bool m_usemap;
187 
188  mraa::Gpio m_oc;
189  mraa::Gpio m_dc;
190  mraa::Gpio m_rst;
191 
192  std::string m_name;
193 };
194 }
~SSD1351()
Definition: ssd1351.cxx:147
GFX helper class.
Definition: ili9341_gfx.hpp:38
void ocLow()
Definition: ssd1351.cxx:195
void dcHigh()
Definition: ssd1351.cxx:216
void drawPixel(int16_t x, int16_t y, uint16_t color)
Definition: ssd1351.cxx:163
void refresh()
Definition: ssd1351.cxx:186
API for SSD1351 OLED displays.
Definition: ssd1351.hpp:106
void ocHigh()
Definition: ssd1351.cxx:202
void dcLow()
Definition: ssd1351.cxx:209
std::string name()
Definition: ssd1351.hpp:125
SSD1351(uint8_t oc, uint8_t dc, uint8_t rst)
Definition: ssd1351.cxx:38
void writeData(uint8_t value)
Definition: ssd1351.cxx:157
void writeCommand(uint8_t value)
Definition: ssd1351.cxx:151
void useMemoryMap(bool var)
Definition: ssd1351.cxx:223