Dmitry Dzhafarkhanov / Adafruit_GFX_SEPS114A
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Adafruit_SEPS114A.h Source File

Adafruit_SEPS114A.h

00001 
00002 
00003 
00004 //#ifndef _Adafruit_SEPS114A_H_
00005 //#define _Adafruit_SEPS114A_H_
00006 
00007 #include "mbed.h"
00008 #include "Adafruit_GFX.h"
00009 
00010 #include <vector>
00011 #include <algorithm>
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 /* some 16bit RGB color definitions  */
00020 enum Color{                                             
00021  Black           = 0x0000,      /*   0,   0,   0 */
00022  Navy            = 0x000F,      /*   0,   0, 128 */
00023  DarkGreen       = 0x03E0,      /*   0, 128,   0 */
00024  DarkCyan        = 0x03EF,      /*   0, 128, 128 */
00025  Maroon          = 0x7800,      /* 128,   0,   0 */
00026  Purple          = 0x780F,      /* 128,   0, 128 */
00027  Olive           = 0x7BE0,      /* 128, 128,   0 */
00028  LightGrey       = 0xC618,      /* 192, 192, 192 */
00029  DarkGrey        = 0x7BEF,      /* 128, 128, 128 */
00030  Blue            = 0x001F,      /*   0,   0, 255 */
00031  Green           = 0x07E0,      /*   0, 255,   0 */
00032  Cyan            = 0x07FF,      /*   0, 255, 255 */
00033  Red             = 0xF800,      /* 255,   0,   0 */
00034  Magenta         = 0xF81F,      /* 255,   0, 255 */
00035  Yellow          = 0xFFE0,      /* 255, 255,   0 */
00036  White           = 0xFFFF,      /* 255, 255, 255 */
00037  Orange          = 0xFD20,      /* 255, 165,   0 */
00038  GreenYellow     = 0xAFE5,      /* 173, 255,  47 */
00039  Pink            = 0xF81F
00040 };
00041 
00042 
00043 // A DigitalOut sub-class that provides a constructed default state
00044 class DigitalOut2 : public DigitalOut
00045 {
00046 public:
00047     DigitalOut2(PinName pin, bool active = false) : DigitalOut(pin) { write(active); };
00048     DigitalOut2& operator= (int value) { write(value); return *this; };
00049     DigitalOut2& operator= (DigitalOut2& rhs) { write(rhs.read()); return *this; };
00050     operator int() { return read(); };
00051 };
00052 
00053 
00054 
00055 
00056 /** The pure base class for the SSD1351 display driver.
00057  *
00058  
00059  */
00060 class Adafruit_SEPS114A : public Adafruit_GFX
00061 {
00062 public:
00063     Adafruit_SEPS114A(PinName RST, uint8_t rawHeight = 96, uint8_t rawWidth = 96)
00064         : Adafruit_GFX(rawWidth,rawHeight)
00065         , rst(RST,false)
00066     {
00067         
00068         
00069         
00070     };
00071 
00072     void begin();
00073     
00074     void clearDisplay();
00075     void MemorySize(uint8_t X1, uint8_t X2, uint8_t Y1, uint8_t Y2);
00076     void set_region(int x, int y, int xs, int ys);
00077     uint16_t Color565(uint8_t r, uint8_t g, uint8_t b);
00078    
00079     
00080     // These must be implemented in the derived transport driver
00081     virtual void writeCommand(uint8_t reg_index,uint8_t reg_value) = 0;
00082     virtual void writeData(uint32_t data_value) = 0;
00083     virtual void DDRAM_access() = 0;
00084     virtual void drawPixel(int16_t x, int16_t y, uint16_t color);
00085      void setContrastControl(int brightness);
00086     
00087 protected:
00088     
00089     DigitalOut2 rst;
00090 
00091 
00092 
00093 };
00094 
00095 
00096 /** This is the SPI SSD1351 display driver transport class
00097  *
00098  */
00099 class Adafruit_SEPS114A_Spi : public Adafruit_SEPS114A
00100 {
00101 public:
00102     /** Create a SSD1351 SPI transport display driver instance with the specified DC, RST, and CS pins, as well as the display dimentions
00103      *
00104      * Required parameters
00105      * @param spi - a reference to an initialized SPI object
00106      * @param DC (Data/Command) pin name
00107      * @param RST (Reset) pin name
00108      * @param CS (Chip Select) pin name
00109      *
00110      * Optional parameters
00111      * @param rawHeight - the vertical number of pixels for the display, defaults to 96
00112      * @param rawWidth - the horizonal number of pixels for the display, defaults to 96
00113      */
00114     Adafruit_SEPS114A_Spi(SPI &spi, PinName DC, PinName RST, PinName CS, uint8_t rawHieght = 96, uint8_t rawWidth = 96)
00115         : Adafruit_SEPS114A(RST, rawHieght, rawWidth)
00116         , cs(CS,true)
00117         , dc(DC,false)    
00118         , mspi(spi)
00119         {
00120             begin();
00121             clearDisplay();
00122         };
00123 
00124     virtual void writeCommand(uint8_t reg_index,uint8_t reg_value)
00125     {
00126        
00127     //Select index addr
00128         cs = 0;
00129         dc = 0;         
00130         mspi.write(reg_index);
00131         cs = 1;
00132         //Write data to reg
00133         cs = 0;
00134         dc = 1; 
00135         mspi.write(reg_value);
00136         cs = 1;
00137     };
00138 
00139     virtual void writeData(uint32_t data_value)
00140     {
00141         cs = 0; 
00142         dc = 1;         
00143         mspi.write(data_value);  
00144         cs = 1;
00145     };
00146     virtual void DDRAM_access()
00147     {
00148             cs = 0;
00149             dc = 0;         
00150             mspi.write(0x08);
00151             cs = 1;
00152     };
00153 
00154 protected:
00155     
00156     DigitalOut2 cs, dc;
00157     SPI &mspi;
00158 };
00159