Driver Library for our displays

Dependents:   dm_bubbles dm_calc dm_paint dm_sdcard_with_adapter ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers DmTftBase.h Source File

DmTftBase.h

00001 /**********************************************************************************************
00002  Copyright (c) 2014 DisplayModule. All rights reserved.
00003 
00004  Redistribution and use of this source code, part of this source code or any compiled binary
00005  based on this source code is permitted as long as the above copyright notice and following
00006  disclaimer is retained.
00007 
00008  DISCLAIMER:
00009  THIS SOFTWARE IS SUPPLIED "AS IS" WITHOUT ANY WARRANTIES AND SUPPORT. DISPLAYMODULE ASSUMES
00010  NO RESPONSIBILITY OR LIABILITY FOR THE USE OF THE SOFTWARE.
00011  ********************************************************************************************/
00012 #ifndef DMTFTBASE_h
00013 #define DMTFTBASE_h
00014 
00015 #include "dm_platform.h"
00016 
00017 
00018 //Basic Colors
00019 #define RED     0xf800
00020 #define GREEN   0x07e0
00021 #define BLUE    0x001f
00022 #define BLACK   0x0000
00023 #define YELLOW  0xffe0
00024 #define WHITE   0xffff
00025 
00026 //Other Colors
00027 #define CYAN        0x07ff
00028 #define BRIGHT_RED  0xf810
00029 #define GRAY1       0x8410
00030 #define GRAY2       0x4208
00031 
00032 
00033 class DmTftBase {
00034 public:
00035   DmTftBase(const uint16_t width, const uint16_t height) : _width(width), _height(height){};
00036   virtual ~DmTftBase() { };
00037 
00038   virtual void init(void) = 0;
00039 
00040   uint16_t width() { return _width; }
00041   uint16_t height() { return _height; }
00042   void setWidth(uint16_t width) {  _width = width; }
00043   void setHeight(uint16_t height) {  _height = height; }
00044 
00045   void setTextColor(uint16_t background, uint16_t foreground) { _bgColor = background; _fgColor = foreground; }
00046 
00047   virtual void setPixel(uint16_t x, uint16_t y, uint16_t color);
00048   virtual void setAddress(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) = 0;
00049   virtual void sendData(uint16_t data) = 0;
00050   
00051   void clearScreen(uint16_t color = BLACK);
00052 
00053   void drawLine(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t color);
00054   void drawVerticalLine(uint16_t x, uint16_t y, uint16_t length, uint16_t color);
00055   void drawHorizontalLine(uint16_t x, uint16_t y, uint16_t length, uint16_t color);
00056 
00057   void drawRectangle(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t color);
00058   void fillRectangle(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t color);
00059 
00060   void drawCircle(uint16_t x0, uint16_t y0, uint16_t r, uint16_t color);
00061   void fillCircle(uint16_t x0, uint16_t y0, uint16_t r, uint16_t color);
00062 
00063   void drawTriangle(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color);
00064 
00065   void drawPoint(uint16_t x, uint16_t y, uint16_t radius=0);
00066 
00067   void drawChar(uint16_t x, uint16_t y, char ch, bool transparent);
00068   void drawNumber(uint16_t x, uint16_t y, int num, int digitsToShow, bool leadingZeros=false);
00069   void drawString(uint16_t x, uint16_t y, const char *p);
00070   void drawStringCentered(uint16_t x, uint16_t y, uint16_t width, uint16_t height, const char *p);
00071 
00072   void drawImage(uint16_t x, uint16_t y, uint16_t width, uint16_t height, const uint16_t* data);
00073   
00074   void select();
00075   void unSelect();
00076 protected:
00077   virtual void sendCommand(uint8_t index) = 0;
00078 
00079 #if defined (DM_TOOLCHAIN_ARDUINO)
00080   regtype *_pinCS;
00081   regsize _bitmaskCS;
00082 #elif defined (DM_TOOLCHAIN_MBED)
00083   DigitalOut* _pinCS;
00084   uint8_t _bitmaskCS;
00085 #endif
00086 
00087 private:
00088   uint16_t _width;
00089   uint16_t _height;
00090 
00091   uint16_t _bgColor;
00092   uint16_t _fgColor;
00093 };
00094 #endif