Peter Drescher / EaEpaper

Dependents:   epaper_mbed_130411_KL25Z epaper_mbed_test epaper_KL25Z_2 test_he10 ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers EaEpaper.h Source File

EaEpaper.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 EAEPAPER_H
00017 #define EAEPAPER_H
00018 
00019 /**
00020  * Includes
00021  */
00022 #include "mbed.h"
00023 #include "EPD.h"
00024 #include "GraphicsDisplay.h"
00025 
00026 // we have to double buffer the display  
00027 #define EA_IMG_BUF_SZ (5808) // 264 x 176 / 8 = 5808
00028 
00029 /** Draw mode
00030   * NORMAl
00031   * XOR set pixel by xor of the screen
00032   */
00033 enum {NORMAL,XOR};
00034 
00035 /** Bitmap
00036  */
00037 struct Bitmap{
00038     int xSize;
00039     int ySize;
00040     int Byte_in_Line;
00041     char* data;
00042     };
00043 
00044 /* color definitions   */
00045 #define Black           0x0
00046 #define White           0x1   
00047 
00048 /** Display control class, based on GraphicsDisplay and TextDisplay
00049  *
00050  * Example with pinning for KL25Z:
00051  * @code
00052  * #include "mbed.h"
00053  * #include "EaEpaper.h"
00054  * #include "Arial28x28.h" 
00055  * #include "Arial12x12.h"
00056  * #include "font_big.h"
00057  * #include "graphics.h"
00058 
00059  * // 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.
00060  * // The LM75 need a I2C -> 2 pins : sda and scl 
00061  * // The display data is written via SPI -> 3 pins : mosi,miso,sck
00062  * // There are also some control signals 
00063  * // The pwm pin has to be connected to a PWM enabled pin : pwm
00064  * // The other signals are connected to normal IO`s
00065  * //              
00066  * EaEpaper epaper(PTD7,            // PWR_CTRL
00067  *                 PTD6,            // BORDER
00068  *                 PTE31,           // DISCHARGE
00069  *                 PTA17,           // RESET_DISP
00070  *                 PTA16,           // BUSY
00071  *                 PTC17,           // SSEL
00072  *                 PTD4,            // PWM
00073  *                 PTD2,PTD3,PTD1,  // MOSI,MISO,SCLK
00074  *                 PTE0,PTE1);      // SDA,SCL 
00075  *
00076  * int main() {
00077  *
00078  *   epaper.cls();                                  // clear screen                        
00079  *   epaper.set_font((unsigned char*) Arial28x28);  // select the font
00080  *   epaper.locate(5,20);                           // set cursor
00081  *   epaper.printf("Hello Mbed");                   // print text
00082  *   epaper.rect(3,15,150,50,1);                    // draw frame
00083  *   epaper.write_disp();                           // update screen
00084  *
00085  * @endcode
00086  */
00087  
00088 
00089 class EaEpaper : public GraphicsDisplay  {
00090 
00091 public:
00092 
00093     /**
00094      * Constructor.
00095      */ 
00096     EaEpaper(PinName p_on, PinName border, PinName discharge, PinName reset, PinName busy, PinName cs,  // IO-Pins
00097              PinName pwm,                                                                               // PWM Pin        
00098              PinName mosi, PinName miso, PinName sck,                                                   // SPI
00099              PinName sda, PinName scl,                                                                  // I2C
00100              const char* name ="E_Paper");
00101     
00102     /** Get the width of the screen in pixel
00103       *
00104       * @param
00105       * @returns width of screen in pixel
00106       *
00107       */
00108     virtual int width();
00109 
00110     /** Get the height of the screen in pixel
00111      *
00112      * @returns height of screen in pixel
00113      *
00114      */
00115     virtual int height();
00116     
00117     
00118     /**
00119      * Clear the display
00120      */    
00121     void clear();
00122     
00123     /**
00124      * Write image buffer to display
00125      */    
00126     void write_disp(void);
00127     
00128     /**
00129      * set or reset a single pixel
00130      *
00131      * @param x horizontal position
00132      * @param y vertical position
00133      * @param color : 0 white, 1 black
00134      */ 
00135     virtual void pixel(int x, int y, int color);
00136     
00137     /** Fill the screen with white
00138      *
00139      */ 
00140     virtual void cls(void);
00141     
00142     /** draw a 1 pixel line
00143      *
00144      * @param x0,y0 start point
00145      * @param x1,y1 stop point
00146      * @param color  : 0 white, 1 black
00147      */  
00148     void line(int x0, int y0, int x1, int y1, int color);
00149     
00150     /** draw a rect
00151      *
00152      * @param x0,y0 top left corner
00153      * @param x1,y1 down right corner
00154      * @param color : 0 white, 1 black
00155      */    
00156     void rect(int x0, int y0, int x1, int y1, int color);
00157     
00158     /** draw a filled rect
00159      *
00160      * @param x0,y0 top left corner
00161      * @param x1,y1 down right corner
00162      * @param color : 0 white, 1 black
00163      */  
00164     void fillrect(int x0, int y0, int x1, int y1, int color);
00165     
00166     /** draw a circle
00167      *
00168      * @param x0,y0 center
00169      * @param r radius
00170      * @param color : 0 white, 1 black                                                          *
00171      */    
00172     void circle(int x0, int y0, int r, int color);
00173     
00174     /** draw a filled circle
00175      *
00176      * @param x0,y0 center
00177      * @param r radius
00178      * @param color : 0 white, 1 black                                                                 *
00179      */  
00180     void fillcircle(int x0, int y0, int r, int color);
00181     
00182     /** set drawing mode
00183      *  @param NORMAL : paint normal color, XOR : paint XOR of current pixels
00184      */
00185     void setmode(int mode);
00186     
00187     /** setup cursor position
00188      *
00189      * @param x x-position (top left)
00190      * @param y y-position 
00191      */   
00192     virtual void locate(int x, int y);
00193     
00194     /** calculate the max number of char in a line
00195      *
00196      * @returns max columns
00197      * depends on actual font size
00198      */ 
00199     virtual int columns();
00200     
00201     /** calculate the max number of columns
00202      *
00203      * @returns max column
00204      * depends on actual font size
00205      */   
00206     virtual int rows();
00207     
00208     /** put a char on the screen
00209      *
00210      * @param value char to print
00211      * @returns printed char
00212      */
00213     virtual int _putc(int value);
00214     
00215     /** paint a character on given position out of the active font to the screen buffer
00216      *
00217      * @param x x-position (top left)
00218      * @param y y-position 
00219      * @param c char code
00220      */
00221     virtual void character(int x, int y, int c);
00222     
00223     /** select the font to use
00224      *
00225      * @param f pointer to font array 
00226      *                                                                              
00227      *   font array can created with GLCD Font Creator from http://www.mikroe.com
00228      *   you have to add 4 parameter at the beginning of the font array to use: 
00229      *   - the number of byte / char
00230      *   - the vertial size in pixel
00231      *   - the horizontal size in pixel
00232      *   - the number of byte per vertical line
00233      *   you also have to change the array to char[]
00234      */  
00235     void set_font(unsigned char* f);
00236     
00237     /** print bitmap to buffer
00238       *
00239       * @param bm struct Bitmap in flash
00240       * @param x  x start
00241       * @param y  y start 
00242       *
00243       */
00244     void print_bm(Bitmap bm, int x, int y);
00245     
00246     
00247     unsigned char* font;
00248     unsigned int draw_mode;
00249     
00250  private:
00251     
00252     EPD_Class epd_;
00253     I2C i2c_;
00254     unsigned int char_x;
00255     unsigned int char_y;
00256     int32_t readTemperature();
00257     
00258 };
00259  
00260  #endif /* EAEPAPER_H */