Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of Adafruit_GFX by
Adafruit_SSD1351.h
00001 /*************************************************** 00002 This is a library for the 1.5" & 1.27" 16-bit Color OLEDs 00003 with SSD1331 driver chip 00004 00005 Pick one up today in the adafruit shop! 00006 ------> http://www.adafruit.com/products/1431 00007 ------> http://www.adafruit.com/products/1673 00008 00009 These displays use SPI to communicate, 4 or 5 pins are required to 00010 interface 00011 Adafruit invests time and resources providing this open source code, 00012 please support Adafruit and open-source hardware by purchasing 00013 products from Adafruit! 00014 00015 Written by Limor Fried/Ladyada for Adafruit Industries. 00016 BSD license, all text above must be included in any redistribution 00017 ****************************************************/ 00018 00019 00020 00021 //#ifndef _ADAFRUIT_SSD1351_H_ 00022 //#define _ADAFRUIT_SSD1351_H_ 00023 00024 #include "mbed.h" 00025 #include "Adafruit_GFX.h" 00026 00027 #include <vector> 00028 #include <algorithm> 00029 00030 00031 00032 00033 00034 00035 /* some 16bit RGB color definitions */ 00036 enum Color{ 00037 Black = 0x0000, /* 0, 0, 0 */ 00038 Navy = 0x000F, /* 0, 0, 128 */ 00039 DarkGreen = 0x03E0, /* 0, 128, 0 */ 00040 DarkCyan = 0x03EF, /* 0, 128, 128 */ 00041 Maroon = 0x7800, /* 128, 0, 0 */ 00042 Purple = 0x780F, /* 128, 0, 128 */ 00043 Olive = 0x7BE0, /* 128, 128, 0 */ 00044 LightGrey = 0xC618, /* 192, 192, 192 */ 00045 DarkGrey = 0x7BEF, /* 128, 128, 128 */ 00046 Blue = 0x001F, /* 0, 0, 255 */ 00047 Green = 0x07E0, /* 0, 255, 0 */ 00048 Cyan = 0x07FF, /* 0, 255, 255 */ 00049 Red = 0xF800, /* 255, 0, 0 */ 00050 Magenta = 0xF81F, /* 255, 0, 255 */ 00051 Yellow = 0xFFE0, /* 255, 255, 0 */ 00052 White = 0xFFFF, /* 255, 255, 255 */ 00053 Orange = 0xFD20, /* 255, 165, 0 */ 00054 GreenYellow = 0xAFE5, /* 173, 255, 47 */ 00055 Pink = 0xF81F 00056 }; 00057 00058 00059 // A DigitalOut sub-class that provides a constructed default state 00060 class DigitalOut2 : public DigitalOut 00061 { 00062 public: 00063 DigitalOut2(PinName pin, bool active = false) : DigitalOut(pin) { write(active); }; 00064 DigitalOut2& operator= (int value) { write(value); return *this; }; 00065 DigitalOut2& operator= (DigitalOut2& rhs) { write(rhs.read()); return *this; }; 00066 operator int() { return read(); }; 00067 }; 00068 00069 00070 00071 00072 /** The pure base class for the SSD1351 display driver. 00073 * 00074 00075 */ 00076 class Adafruit_SSD1351 : public Adafruit_GFX 00077 { 00078 public: 00079 Adafruit_SSD1351(PinName RST, uint8_t rawHeight = 96, uint8_t rawWidth = 128) 00080 : Adafruit_GFX(rawWidth,rawHeight) 00081 , rst(RST,false) 00082 { 00083 00084 00085 00086 }; 00087 00088 void begin(); 00089 void goTo(int x, int y); 00090 uint16_t Color565(uint8_t r, uint8_t g, uint8_t b); 00091 virtual void fillScreen(uint16_t fillcolor); 00092 virtual void rawFillRect(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t fillcolor); 00093 void fillRect(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t fillcolor); 00094 void rawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color); 00095 void rawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color); 00096 virtual void drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color); 00097 virtual void drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color); 00098 void setContrastControl(uint8_t contrast); 00099 00100 00101 virtual void invert(bool v); 00102 00103 00104 // These must be implemented in the derived transport driver 00105 virtual void writeCommand(uint8_t c) = 0; 00106 virtual void writeData(uint8_t c) = 0; 00107 virtual void drawPixel(int16_t x, int16_t y, uint16_t color); 00108 00109 00110 protected: 00111 00112 DigitalOut2 rst; 00113 00114 00115 00116 }; 00117 00118 00119 /** This is the SPI SSD1351 display driver transport class 00120 * 00121 */ 00122 class Adafruit_SSD1351_Spi : public Adafruit_SSD1351 00123 { 00124 public: 00125 /** Create a SSD1351 SPI transport display driver instance with the specified DC, RST, and CS pins, as well as the display dimentions 00126 * 00127 * Required parameters 00128 * @param spi - a reference to an initialized SPI object 00129 * @param DC (Data/Command) pin name 00130 * @param RST (Reset) pin name 00131 * @param CS (Chip Select) pin name 00132 * 00133 * Optional parameters 00134 * @param rawHeight - the vertical number of pixels for the display, defaults to 96 00135 * @param rawWidth - the horizonal number of pixels for the display, defaults to 128 00136 */ 00137 Adafruit_SSD1351_Spi(SPI &spi, PinName DC, PinName RST, PinName CS, uint8_t rawHieght = 96, uint8_t rawWidth = 128) 00138 : Adafruit_SSD1351(RST, rawHieght, rawWidth) 00139 , cs(CS,true) 00140 , dc(DC,false) 00141 , mspi(spi) 00142 { 00143 begin(); 00144 00145 00146 }; 00147 00148 virtual void writeCommand(uint8_t c) 00149 { 00150 00151 dc = 0; 00152 cs = 0; 00153 mspi.write(c); 00154 cs = 1; 00155 }; 00156 00157 virtual void writeData(uint8_t c) 00158 { 00159 00160 dc = 1; 00161 cs = 0; 00162 00163 mspi.write(c); 00164 00165 cs = 1; 00166 }; 00167 00168 00169 protected: 00170 00171 DigitalOut2 cs, dc; 00172 SPI &mspi; 00173 }; 00174
Generated on Thu Jul 14 2022 20:18:09 by
1.7.2
