A derived version of the BSD licensed Adafrut GFX library for the SSD1351 controller for an OLED 128x 96or 128x128 display using SPI

Fork of Adafruit_GFX by Neal Horman

/media/uploads/Dzhafarkhanov/1673-09.jpg

You can print russian. (font edited).

class SPIPreInit : public SPI { public: SPIPreInit(PinName mosi, PinName miso, PinName clk) : SPI(mosi,miso,clk) { format(8,3); frequency(25000000); }; }; SPIPreInit gSpi(PB_15,NC,PB_13); PinName mosi(sda), PinName miso, PinName clk(scl) Adafruit_SSD1351_Spi oled(gSpi,PB_14,PB_1,PB_2); PinName DC, PinName RST, PinName CS

Committer:
Dzhafarkhanov
Date:
Wed Feb 24 12:24:42 2016 +0000
Revision:
17:56015e4834e6
Parent:
14:edb3c36aa1a7
SSD1351;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nkhorman 9:ddb97c9850a2 1 /***********************************
nkhorman 9:ddb97c9850a2 2 This is a our graphics core library, for all our displays.
nkhorman 9:ddb97c9850a2 3 We'll be adapting all the
nkhorman 9:ddb97c9850a2 4 existing libaries to use this core to make updating, support
nkhorman 9:ddb97c9850a2 5 and upgrading easier!
nkhorman 9:ddb97c9850a2 6
nkhorman 9:ddb97c9850a2 7 Adafruit invests time and resources providing this open source code,
nkhorman 9:ddb97c9850a2 8 please support Adafruit and open-source hardware by purchasing
nkhorman 9:ddb97c9850a2 9 products from Adafruit!
nkhorman 9:ddb97c9850a2 10
nkhorman 9:ddb97c9850a2 11 Written by Limor Fried/Ladyada for Adafruit Industries.
nkhorman 9:ddb97c9850a2 12 BSD license, check license.txt for more information
nkhorman 9:ddb97c9850a2 13 All text above must be included in any redistribution
nkhorman 9:ddb97c9850a2 14 ****************************************/
nkhorman 9:ddb97c9850a2 15
nkhorman 9:ddb97c9850a2 16 /*
nkhorman 9:ddb97c9850a2 17 * Modified by Neal Horman 7/14/2012 for use in mbed
nkhorman 9:ddb97c9850a2 18 */
nkhorman 9:ddb97c9850a2 19
nkhorman 9:ddb97c9850a2 20 #ifndef _ADAFRUIT_GFX_H_
nkhorman 9:ddb97c9850a2 21 #define _ADAFRUIT_GFX_H_
nkhorman 9:ddb97c9850a2 22
nkhorman 13:8f03f908f22a 23 #include "Adafruit_GFX_Config.h"
nkhorman 9:ddb97c9850a2 24
nkhorman 9:ddb97c9850a2 25 static inline void swap(int16_t &a, int16_t &b)
nkhorman 9:ddb97c9850a2 26 {
nkhorman 9:ddb97c9850a2 27 int16_t t = a;
nkhorman 9:ddb97c9850a2 28
nkhorman 9:ddb97c9850a2 29 a = b;
nkhorman 9:ddb97c9850a2 30 b = t;
nkhorman 9:ddb97c9850a2 31 }
nkhorman 9:ddb97c9850a2 32
nkhorman 9:ddb97c9850a2 33 #ifndef _BV
nkhorman 9:ddb97c9850a2 34 #define _BV(bit) (1<<(bit))
nkhorman 9:ddb97c9850a2 35 #endif
nkhorman 9:ddb97c9850a2 36
nkhorman 11:86909e6db3c8 37 /**
nkhorman 11:86909e6db3c8 38 * This is a Text and Graphics element drawing class.
nkhorman 11:86909e6db3c8 39 * These functions draw to the display buffer.
nkhorman 11:86909e6db3c8 40 *
Dzhafarkhanov 17:56015e4834e6 41
nkhorman 11:86909e6db3c8 42 */
nkhorman 9:ddb97c9850a2 43 class Adafruit_GFX : public Stream
nkhorman 9:ddb97c9850a2 44 {
nkhorman 9:ddb97c9850a2 45 public:
nkhorman 9:ddb97c9850a2 46 Adafruit_GFX(int16_t w, int16_t h)
nkhorman 9:ddb97c9850a2 47 : _rawWidth(w)
nkhorman 9:ddb97c9850a2 48 , _rawHeight(h)
nkhorman 9:ddb97c9850a2 49 , _width(w)
nkhorman 9:ddb97c9850a2 50 , _height(h)
nkhorman 9:ddb97c9850a2 51 , cursor_x(0)
nkhorman 9:ddb97c9850a2 52 , cursor_y(0)
Dzhafarkhanov 17:56015e4834e6 53 , textcolor(0xFFFF)
Dzhafarkhanov 17:56015e4834e6 54 , textbgcolor(0xFFFF)
nkhorman 9:ddb97c9850a2 55 , textsize(1)
nkhorman 9:ddb97c9850a2 56 , rotation(0)
nkhorman 9:ddb97c9850a2 57 , wrap(true)
nkhorman 9:ddb97c9850a2 58 {};
nkhorman 9:ddb97c9850a2 59
nkhorman 11:86909e6db3c8 60 /// Paint one BLACK or WHITE pixel in the display buffer
nkhorman 9:ddb97c9850a2 61 // this must be defined by the subclass
nkhorman 9:ddb97c9850a2 62 virtual void drawPixel(int16_t x, int16_t y, uint16_t color) = 0;
nkhorman 9:ddb97c9850a2 63 // this is optional
nkhorman 9:ddb97c9850a2 64 virtual void invertDisplay(bool i) {};
nkhorman 9:ddb97c9850a2 65
nkhorman 9:ddb97c9850a2 66 // Stream implementation - provides printf() interface
nkhorman 9:ddb97c9850a2 67 // You would otherwise be forced to use writeChar()
nkhorman 9:ddb97c9850a2 68 virtual int _putc(int value) { return writeChar(value); };
nkhorman 9:ddb97c9850a2 69 virtual int _getc() { return -1; };
nkhorman 9:ddb97c9850a2 70
nkhorman 9:ddb97c9850a2 71 #ifdef GFX_WANT_ABSTRACTS
nkhorman 9:ddb97c9850a2 72 // these are 'generic' drawing functions, so we can share them!
nkhorman 11:86909e6db3c8 73
nkhorman 11:86909e6db3c8 74 /** Draw a Horizontal Line
nkhorman 11:86909e6db3c8 75 * @note GFX_WANT_ABSTRACTS must be defined in Adafruit_GFX_config.h
nkhorman 11:86909e6db3c8 76 */
nkhorman 9:ddb97c9850a2 77 virtual void drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color);
nkhorman 11:86909e6db3c8 78 /** Draw a rectangle
nkhorman 11:86909e6db3c8 79 * @note GFX_WANT_ABSTRACTS must be defined in Adafruit_GFX_config.h
nkhorman 11:86909e6db3c8 80 */
nkhorman 9:ddb97c9850a2 81 virtual void drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);
nkhorman 11:86909e6db3c8 82 /** Fill the entire display
nkhorman 11:86909e6db3c8 83 * @note GFX_WANT_ABSTRACTS must be defined in Adafruit_GFX_config.h
nkhorman 11:86909e6db3c8 84 */
nkhorman 9:ddb97c9850a2 85 virtual void fillScreen(uint16_t color);
nkhorman 9:ddb97c9850a2 86
nkhorman 11:86909e6db3c8 87 /** Draw a circle
nkhorman 11:86909e6db3c8 88 * @note GFX_WANT_ABSTRACTS must be defined in Adafruit_GFX_config.h
nkhorman 11:86909e6db3c8 89 */
nkhorman 9:ddb97c9850a2 90 void drawCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color);
nkhorman 9:ddb97c9850a2 91 void drawCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername, uint16_t color);
nkhorman 11:86909e6db3c8 92
nkhorman 11:86909e6db3c8 93 /** Draw and fill a circle
nkhorman 11:86909e6db3c8 94 * @note GFX_WANT_ABSTRACTS must be defined in Adafruit_GFX_config.h
nkhorman 11:86909e6db3c8 95 */
nkhorman 9:ddb97c9850a2 96 void fillCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color);
nkhorman 9:ddb97c9850a2 97 void fillCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername, int16_t delta, uint16_t color);
nkhorman 9:ddb97c9850a2 98
nkhorman 11:86909e6db3c8 99 /** Draw a triangle
nkhorman 11:86909e6db3c8 100 * @note GFX_WANT_ABSTRACTS must be defined in Adafruit_GFX_config.h
nkhorman 11:86909e6db3c8 101 */
nkhorman 9:ddb97c9850a2 102 void drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color);
nkhorman 11:86909e6db3c8 103 /** Draw and fill a triangle
nkhorman 11:86909e6db3c8 104 * @note GFX_WANT_ABSTRACTS must be defined in Adafruit_GFX_config.h
nkhorman 11:86909e6db3c8 105 */
nkhorman 9:ddb97c9850a2 106 void fillTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color);
nkhorman 11:86909e6db3c8 107
nkhorman 11:86909e6db3c8 108 /** Draw a rounded rectangle
nkhorman 11:86909e6db3c8 109 * @note GFX_WANT_ABSTRACTS must be defined in Adafruit_GFX_config.h
nkhorman 11:86909e6db3c8 110 */
nkhorman 9:ddb97c9850a2 111 void drawRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, int16_t radius, uint16_t color);
nkhorman 11:86909e6db3c8 112 /** Draw and fill a rounded rectangle
nkhorman 11:86909e6db3c8 113 * @note GFX_WANT_ABSTRACTS must be defined in Adafruit_GFX_config.h
nkhorman 11:86909e6db3c8 114 */
nkhorman 9:ddb97c9850a2 115 void fillRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, int16_t radius, uint16_t color);
nkhorman 14:edb3c36aa1a7 116 /** Draw a bitmap
nkhorman 14:edb3c36aa1a7 117 * @note GFX_WANT_ABSTRACTS must be defined in Adafruit_GFX_config.h
nkhorman 14:edb3c36aa1a7 118 */
nkhorman 14:edb3c36aa1a7 119 void drawBitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint16_t color);
nkhorman 9:ddb97c9850a2 120 #endif
nkhorman 9:ddb97c9850a2 121
nkhorman 9:ddb97c9850a2 122 #if defined(GFX_WANT_ABSTRACTS) || defined(GFX_SIZEABLE_TEXT)
nkhorman 11:86909e6db3c8 123 /** Draw a line
nkhorman 11:86909e6db3c8 124 * @note GFX_WANT_ABSTRACTS or GFX_SIZEABLE_TEXT must be defined in Adafruit_GFX_config.h
nkhorman 11:86909e6db3c8 125 */
nkhorman 9:ddb97c9850a2 126 virtual void drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color);
nkhorman 11:86909e6db3c8 127 /** Draw a vertical line
nkhorman 11:86909e6db3c8 128 * @note GFX_WANT_ABSTRACTS or GFX_SIZEABLE_TEXT must be defined in Adafruit_GFX_config.h
nkhorman 11:86909e6db3c8 129 */
nkhorman 9:ddb97c9850a2 130 virtual void drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color);
nkhorman 11:86909e6db3c8 131 /** Draw and fill a rectangle
nkhorman 11:86909e6db3c8 132 * @note GFX_WANT_ABSTRACTS or GFX_SIZEABLE_TEXT must be defined in Adafruit_GFX_config.h
nkhorman 11:86909e6db3c8 133 */
nkhorman 9:ddb97c9850a2 134 virtual void fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);
nkhorman 9:ddb97c9850a2 135 #endif
nkhorman 9:ddb97c9850a2 136
nkhorman 11:86909e6db3c8 137 /// Draw a text character at a specified pixel location
nkhorman 9:ddb97c9850a2 138 void drawChar(int16_t x, int16_t y, unsigned char c, uint16_t color, uint16_t bg, uint8_t size);
nkhorman 11:86909e6db3c8 139 /// Draw a text character at the text cursor location
nkhorman 9:ddb97c9850a2 140 size_t writeChar(uint8_t);
nkhorman 9:ddb97c9850a2 141
nkhorman 11:86909e6db3c8 142 /// Get the width of the display in pixels
nkhorman 14:edb3c36aa1a7 143 inline int16_t width(void) { return _width; };
nkhorman 11:86909e6db3c8 144 /// Get the height of the display in pixels
nkhorman 14:edb3c36aa1a7 145 inline int16_t height(void) { return _height; };
nkhorman 9:ddb97c9850a2 146
nkhorman 11:86909e6db3c8 147 /// Set the text cursor location, based on the size of the text
nkhorman 14:edb3c36aa1a7 148 inline void setTextCursor(int16_t x, int16_t y) { cursor_x = x; cursor_y = y; };
nkhorman 14:edb3c36aa1a7 149 #if defined(GFX_WANT_ABSTRACTS) || defined(GFX_SIZEABLE_TEXT)
nkhorman 11:86909e6db3c8 150 /** Set the size of the text to be drawn
nkhorman 11:86909e6db3c8 151 * @note Make sure to enable either GFX_SIZEABLE_TEXT or GFX_WANT_ABSTRACTS
nkhorman 11:86909e6db3c8 152 */
nkhorman 14:edb3c36aa1a7 153 inline void setTextSize(uint8_t s) { textsize = (s > 0) ? s : 1; };
nkhorman 9:ddb97c9850a2 154 #endif
nkhorman 11:86909e6db3c8 155 /// Set the text foreground and background colors to be the same
nkhorman 14:edb3c36aa1a7 156 inline void setTextColor(uint16_t c) { textcolor = c; textbgcolor = c; }
nkhorman 11:86909e6db3c8 157 /// Set the text foreground and background colors independantly
nkhorman 14:edb3c36aa1a7 158 inline void setTextColor(uint16_t c, uint16_t b) { textcolor = c; textbgcolor = b; };
nkhorman 11:86909e6db3c8 159 /// Set text wraping mode true or false
nkhorman 14:edb3c36aa1a7 160 inline void setTextWrap(bool w) { wrap = w; };
nkhorman 9:ddb97c9850a2 161
nkhorman 11:86909e6db3c8 162 /// Set the display rotation, 1, 2, 3, or 4
nkhorman 9:ddb97c9850a2 163 void setRotation(uint8_t r);
nkhorman 11:86909e6db3c8 164 /// Get the current rotation
nkhorman 14:edb3c36aa1a7 165 inline uint8_t getRotation(void) { rotation %= 4; return rotation; };
nkhorman 9:ddb97c9850a2 166
nkhorman 9:ddb97c9850a2 167 protected:
nkhorman 9:ddb97c9850a2 168 int16_t _rawWidth, _rawHeight; // this is the 'raw' display w/h - never changes
nkhorman 9:ddb97c9850a2 169 int16_t _width, _height; // dependent on rotation
nkhorman 9:ddb97c9850a2 170 int16_t cursor_x, cursor_y;
nkhorman 9:ddb97c9850a2 171 uint16_t textcolor, textbgcolor;
nkhorman 9:ddb97c9850a2 172 uint8_t textsize;
nkhorman 9:ddb97c9850a2 173 uint8_t rotation;
nkhorman 9:ddb97c9850a2 174 bool wrap; // If set, 'wrap' text at right edge of display
nkhorman 9:ddb97c9850a2 175 };
nkhorman 9:ddb97c9850a2 176
nkhorman 9:ddb97c9850a2 177 #endif