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