upm  0.5.1
Sensor/Actuator repository for libmraa (v0.9.1)
 All Data Structures Files Functions Variables Enumerations Enumerator Macros Groups Pages
eboled.h
1 /*
2  * Author: Jon Trulson <jtrulson@ics.com>
3  * Copyright (c) 2015 Intel Corporation.
4  *
5  * Author: Tyler Gibson <tgibson@microsoft.com>
6  * Copyright (c) 2015 Microsoft Corporation.
7  *
8  * Credits to Adafruit.
9  * Based on Adafruit ST7735 library, see original license in license.txt file.
10  *
11  * Permission is hereby granted, free of charge, to any person obtaining
12  * a copy of this software and associated documentation files (the
13  * "Software"), to deal in the Software without restriction, including
14  * without limitation the rights to use, copy, modify, merge, publish,
15  * distribute, sublicense, and/or sell copies of the Software, and to
16  * permit persons to whom the Software is furnished to do so, subject to
17  * the following conditions:
18  *
19  * The above copyright notice and this permission notice shall be
20  * included in all copies or substantial portions of the Software.
21  *
22  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29  */
30 #pragma once
31 
32 #include <string>
33 #include <mraa/spi.hpp>
34 
35 #include <mraa/gpio.hpp>
36 
37 #include "lcd.h"
38 #include "ssd.h"
39 
40 #define EBOLED_DEFAULT_SPI_BUS 0
41 #define EBOLED_DEFAULT_CD 36
42 #define EBOLED_DEFAULT_RESET 48
43 
44 #define swap(a, b) { uint8_t t = a; a = b; b = t; }
45 
46 namespace upm
47 {
48  const uint8_t COLOR_WHITE = 0x01;
49  const uint8_t COLOR_BLACK = 0x00;
50  const uint8_t COLOR_XOR = 0x02;
51  const uint8_t OLED_WIDTH = 0x40; // 64 pixels
52  const uint8_t VERT_COLUMNS = 0x20; // half width for hi/lo 16bit writes.
53  const uint8_t OLED_HEIGHT = 0x30; // 48 pixels
54  const int BUFFER_SIZE = 192;
55 
84  class EBOLED : public LCD
85  {
86  // SSD commands
87  typedef enum {
88  CMD_SETLOWCOLUMN = 0x00,
89  CMD_EXTERNALVCC = 0x01,
90  CMD_SWITCHCAPVCC = 0x02,
91  CMD_SETHIGHCOLUMN = 0x10,
92  CMD_MEMORYADDRMODE = 0x20,
93  CMD_SETCOLUMNADDRESS = 0x21,
94  CMD_SETPAGEADDRESS = 0x22,
95  CMD_SETSTARTLINE = 0x40, // 0x40 - 0x7f
96  CMD_SETCONTRAST = 0x81,
97  CMD_CHARGEPUMP = 0x8d,
98  CMD_SEGREMAP = 0xa0,
99  CMD_DISPLAYALLONRESUME = 0xa4,
100  CMD_DISPLAYALLON = 0xa5,
101  CMD_NORMALDISPLAY = 0xa6,
102  CMD_INVERTDISPLAY = 0xa7,
103  CMD_SETMULTIPLEX = 0xa8,
104  CMD_DISPLAYOFF = 0xae,
105  CMD_DISPLAYON = 0xaf,
106  CMD_SETPAGESTARTADDR = 0xb0, // 0xb0-0xb7
107  CMD_COMSCANINC = 0xc0,
108  CMD_COMSCANDEC = 0xc8,
109  CMD_SETDISPLAYOFFSET = 0xd3,
110  CMD_SETDISPLAYCLOCKDIV = 0xd5,
111  CMD_SETPRECHARGE = 0xd9,
112  CMD_SETCOMPINS = 0xda,
113  CMD_SETVCOMDESELECT = 0xdb
114  } SSD_CMDS_T;
115 
116  public:
126  EBOLED(int spi=EBOLED_DEFAULT_SPI_BUS, int CD=EBOLED_DEFAULT_CD,
127  int reset=EBOLED_DEFAULT_RESET);
128 
132  ~EBOLED();
133 
139  mraa::Result refresh();
140 
148  mraa::Result write(std::string msg);
149 
158  mraa::Result setCursor (int row, int column);
159 
165  void setTextColor (uint8_t textColor);
166 
172  void setTextSize (uint8_t size);
173 
179  void setTextWrap (uint8_t wrap);
180 
191  void drawChar (uint8_t x, uint8_t y, uint8_t data, uint8_t color, uint8_t size);
192 
198  mraa::Result clear();
199 
200  void clearScreenBuffer();
201 
207  mraa::Result home();
208 
217  void drawPixel (int8_t x, int8_t y, uint8_t color=COLOR_WHITE);
218 
228  void drawLine (int8_t x0, int8_t y0, int8_t x1, int8_t y1, uint8_t color = COLOR_WHITE);
229 
238  void drawLineHorizontal (int8_t x, int8_t y, uint8_t width, uint8_t color = COLOR_WHITE);
239 
248  void drawLineVertical (int8_t x, int8_t y, uint8_t height, uint8_t color = COLOR_WHITE);
249 
259  void drawRectangle (int8_t x, int8_t y, uint8_t width, uint8_t height, uint8_t color = COLOR_WHITE);
260 
271  void drawRoundedRectangle(int8_t x, int8_t y, int8_t width, int8_t height, int16_t radius, uint8_t color);
272 
282  void drawRectangleFilled (int8_t x, int8_t y, uint8_t width, uint8_t height, uint8_t color = COLOR_WHITE);
283 
295  void drawTriangle (int8_t x0, int8_t y0, int8_t x1, int8_t y1, int8_t x2, int8_t y2, uint8_t color = COLOR_WHITE);
296 
308  void drawTriangleFilled ( int8_t x0, int8_t y0, int8_t x1, int8_t y1, int8_t x2, int8_t y2, uint8_t color);
309 
318  void drawCircle (int16_t x0, int16_t y0, int16_t radius, uint8_t color = COLOR_WHITE);
319 
329  void drawRoundCorners( int8_t x0, int8_t y0, int16_t radius, uint8_t cornername, uint8_t color);
330 
339  void drawCircleFilled(int8_t x0, int8_t y0, int16_t radius, uint8_t color);
340 
350  void drawRoundedCornersFilled(int8_t x0, int8_t y0, int16_t radius, uint8_t cornername, int16_t delta, uint8_t color);
351 
357  void fillScreen (uint8_t color=COLOR_WHITE);
358 
359 
360  protected:
361  mraa::Result command(uint8_t cmd);
362  mraa::Result data(uint16_t data);
363  mraa::Result writeChar(uint8_t value);
364  mraa::Result setAddressingMode(displayAddressingMode mode);
365 
366  private:
367  mraa::Gpio m_gpioCD; // command(0)/data(1)
368  mraa::Gpio m_gpioRST; // reset pin
369 
370  mraa::Spi m_spi;
371 
372  uint8_t m_cursorX;
373  uint8_t m_cursorY;
374  uint8_t m_textSize;
375  uint8_t m_textColor;
376  uint8_t m_textWrap;
377  };
378 }
void setTextWrap(uint8_t wrap)
Definition: eboled.cxx:176
mraa::Result write(std::string msg)
Definition: eboled.cxx:131
mraa::Result clear()
Definition: eboled.cxx:214
void drawTriangleFilled(int8_t x0, int8_t y0, int8_t x1, int8_t y1, int8_t x2, int8_t y2, uint8_t color)
Definition: eboled.cxx:353
void drawLineHorizontal(int8_t x, int8_t y, uint8_t width, uint8_t color=COLOR_WHITE)
Definition: eboled.cxx:303
void drawLine(int8_t x0, int8_t y0, int8_t x1, int8_t y1, uint8_t color=COLOR_WHITE)
Definition: eboled.cxx:262
void drawCircleFilled(int8_t x0, int8_t y0, int16_t radius, uint8_t color)
Definition: eboled.cxx:501
void drawCircle(int16_t x0, int16_t y0, int16_t radius, uint8_t color=COLOR_WHITE)
Definition: eboled.cxx:429
void setTextColor(uint8_t textColor)
Definition: eboled.cxx:168
mraa::Result setCursor(int row, int column)
Definition: eboled.cxx:162
void drawPixel(int8_t x, int8_t y, uint8_t color=COLOR_WHITE)
Definition: eboled.cxx:234
mraa::Result refresh()
Definition: eboled.cxx:116
~EBOLED()
Definition: eboled.cxx:111
void drawRectangleFilled(int8_t x, int8_t y, uint8_t width, uint8_t height, uint8_t color=COLOR_WHITE)
Definition: eboled.cxx:339
Definition: lcd.h:37
void drawChar(uint8_t x, uint8_t y, uint8_t data, uint8_t color, uint8_t size)
Definition: eboled.cxx:180
void drawRectangle(int8_t x, int8_t y, uint8_t width, uint8_t height, uint8_t color=COLOR_WHITE)
Definition: eboled.cxx:313
void drawRoundedCornersFilled(int8_t x0, int8_t y0, int16_t radius, uint8_t cornername, int16_t delta, uint8_t color)
Definition: eboled.cxx:506
API for EBOLED spi controlled OLED display.
Definition: eboled.h:84
void fillScreen(uint8_t color=COLOR_WHITE)
Definition: eboled.cxx:535
void drawLineVertical(int8_t x, int8_t y, uint8_t height, uint8_t color=COLOR_WHITE)
Definition: eboled.cxx:308
void drawTriangle(int8_t x0, int8_t y0, int8_t x1, int8_t y1, int8_t x2, int8_t y2, uint8_t color=COLOR_WHITE)
Definition: eboled.cxx:346
void drawRoundCorners(int8_t x0, int8_t y0, int16_t radius, uint8_t cornername, uint8_t color)
Definition: eboled.cxx:466
void drawRoundedRectangle(int8_t x, int8_t y, int8_t width, int8_t height, int16_t radius, uint8_t color)
Definition: eboled.cxx:326
mraa::Result home()
Definition: eboled.cxx:229
EBOLED(int spi=EBOLED_DEFAULT_SPI_BUS, int CD=EBOLED_DEFAULT_CD, int reset=EBOLED_DEFAULT_RESET)
Definition: eboled.cxx:37
void setTextSize(uint8_t size)
Definition: eboled.cxx:172