steeven lee / GraphicUtil

Dependents:   EPD_GDE021A1_demo

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Graphic.h Source File

Graphic.h

00001 /* mbed library for 264*176 pixel 2.7 INCH E-PAPER DISPLAY from Pervasive Displays
00002  * Copyright (c) 2013 Peter Drescher - DC2PD
00003  *
00004  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00005  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00006  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00007  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00008  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00009  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00010  * THE SOFTWARE.
00011  */
00012 
00013 
00014 // 09.11.2013   initial Version
00015 
00016 #ifndef Graphic_H
00017 #define Graphic_H
00018 
00019 /**
00020  * Includes
00021  */
00022 #include "mbed.h"
00023 
00024 /** Bitmap
00025  */
00026 struct Bitmap{
00027     int xSize;
00028     int ySize;
00029     int Byte_in_Line;
00030     char* data;
00031     };
00032 
00033 /* color definitions   */
00034 #define Black           0x0
00035 #define White           0x3
00036 
00037 /** Display control class, based on sDisplay and TextDisplay
00038  *
00039  * Example with pinning for KL25Z:
00040  * @code
00041  * #include "mbed.h"
00042  * #include "Graphic.h"
00043  * #include "Arial28x28.h" 
00044  * #include "Arial12x12.h"
00045  * #include "font_big.h"
00046  * #include "s.h"
00047 
00048  * // the E-Paper board from embedded artists has a LM75 temp sensor to compensate the temperature effect. If it is cold the display reacts slower.
00049  * // The LM75 need a I2C -> 2 pins : sda and scl 
00050  * // The display data is written via SPI -> 3 pins : mosi,miso,sck
00051  * // There are also some control signals 
00052  * // The pwm pin has to be connected to a PWM enabled pin : pwm
00053  * // The other signals are connected to normal IO`s
00054  * //              
00055  * Graphic epaper(PTD7,            // PWR_CTRL
00056  *                 PTD6,            // BORDER
00057  *                 PTE31,           // DISCHARGE
00058  *                 PTA17,           // RESET_DISP
00059  *                 PTA16,           // BUSY
00060  *                 PTC17,           // SSEL
00061  *                 PTD4,            // PWM
00062  *                 PTD2,PTD3,PTD1,  // MOSI,MISO,SCLK
00063  *                 PTE0,PTE1);      // SDA,SCL 
00064  *
00065  * int main() {
00066  *
00067  *   epaper.cls();                                  // clear screen                        
00068  *   epaper.set_font((unsigned char*) Arial28x28);  // select the font
00069  *   epaper.locate(5,20);                           // set cursor
00070  *   epaper.printf("Hello Mbed");                   // print text
00071  *   epaper.rect(3,15,150,50,1);                    // draw frame
00072  *   epaper.write_disp();                           // update screen
00073  *
00074  * @endcode
00075  */
00076  
00077 
00078 class Graphic {
00079 
00080 public:
00081 
00082     /**
00083      * Constructor.
00084      */ 
00085     Graphic(uint8_t *buf, int w, int h, int bits = 1);
00086     
00087     /**
00088      * Set color
00089      */
00090     void color(int foreground, int background);
00091 
00092     /**
00093      * Clear the display
00094      */    
00095     void clear();
00096     
00097     /**
00098      * set or reset a single pixel
00099      *
00100      * @param x horizontal position
00101      * @param y vertical position
00102      */ 
00103     void pixel(int x, int y, unsigned int color);
00104     
00105     
00106     /** draw a 1 pixel line
00107      *
00108      * @param x0,y0 start point
00109      * @param x1,y1 stop point
00110      */  
00111     void line(int x0, int y0, int x1, int y1);
00112     
00113     /** draw a rect
00114      *
00115      * @param x0,y0 top left corner
00116      * @param x1,y1 down right corner
00117      */    
00118     void rect(int x0, int y0, int x1, int y1);
00119     
00120     /** draw a filled rect
00121      *
00122      * @param x0,y0 top left corner
00123      * @param x1,y1 down right corner
00124      */  
00125     void fillrect(int x0, int y0, int x1, int y1);
00126     
00127     /** draw a circle
00128      *
00129      * @param x0,y0 center
00130      * @param r radius
00131      */    
00132     void circle(int x0, int y0, int r);
00133     
00134     /** draw a filled circle
00135      *
00136      * @param x0,y0 center
00137      * @param r radius
00138      */  
00139     void fillcircle(int x0, int y0, int r);
00140     
00141     /** setup cursor position
00142      *
00143      * @param x x-position (top left)
00144      * @param y y-position 
00145      */   
00146     void locate(int x, int y);
00147     
00148     /** calculate the max number of char in a line
00149      *
00150      * @returns max columns
00151      * depends on actual font size
00152      */ 
00153     int columns();
00154     
00155     /** calculate the max number of columns
00156      *
00157      * @returns max column
00158      * depends on actual font size
00159      */   
00160     int rows();
00161     
00162     /** put a char on the screen
00163      *
00164      * @param value char to print
00165      * @returns printed char
00166      */
00167     void putc(int value);
00168     
00169     /** print a string on the screen
00170      *
00171      * @param str string to print
00172      */
00173     void print(const char *str);
00174 
00175     /** select the font to use
00176      *
00177      * @param f pointer to font array 
00178      *                                                                              
00179      *   font array can created with GLCD Font Creator from http://www.mikroe.com
00180      *   you have to add 4 parameter at the beginning of the font array to use: 
00181      *   - the number of byte / char
00182      *   - the vertial size in pixel
00183      *   - the horizontal size in pixel
00184      *   - the number of byte per vertical line
00185      *   you also have to change the array to char[]
00186      */  
00187     void font(const unsigned char* f);
00188     
00189     /** print bitmap to buffer
00190       *
00191       * @param bm struct Bitmap in flash
00192       * @param x  x start
00193       * @param y  y start 
00194       *
00195       */
00196     void print_bm(Bitmap bm, int x, int y);
00197     
00198     
00199 
00200 protected:
00201 
00202 
00203     uint8_t *_buf; //drawing buffer
00204 
00205     int _w; //screen width
00206     int _h; //screeen height
00207     char _bits; //per pix
00208 
00209     int _foreColor;
00210     int _backgroundColor;
00211 
00212     unsigned char* _font;
00213     int _charX;
00214     int _charY;
00215 
00216 };
00217  
00218  #endif /* Graphic_H */