A lib to handle a E-Paper display from Pervasive Displays. There is a interface board from Embedded Artists. The lib can handle graphic and text drawing and is using external fonts.

Dependents:   epaper_mbed_130411_KL25Z epaper_mbed_test epaper_KL25Z_2 test_he10 ... more

/media/uploads/dreschpe/epaper.jpg

The E-Paper display from Pervasive Displays with a interface board is available from Embedded Artists : http://www.embeddedartists.com/products/displays/lcd_27_epaper.php The 2.7 inch display have 264*176 pixel, monochrome.

Technology

You can look at the webside from Pervasive to see how the display works. http://www.pervasivedisplays.com/technology/home

This type of display have ultra low power consumption - due to its bi-stable nature. It requires only very little power to update the display and needs no power to maintain an image. You can disconnect the display - the image is still there. The viewing angle is like real paper - near 180°.

There are also some disadvantages of this technology. To change the image, we have to rewrite the full display in 4 steps. Invert, clear, invert new, new image. This process is visible and take a while -2s at room temperature. If it gets colder the display reacts slower and the interface timing has to be slow down. To compensate this, there is a LM75 temp sensor on the interface board. We also need ram to double buffer the display. 264 * 176 / 8 = 5808 Byte. To double buffer we need 11616 byte of ram. This is no problem for most mbed devices, but it will not run on the LPC11U24 or LPC800-MAX.

Interface

The graphic data is transferred to the display via spi. The maximum speed is 12Mhz. There are also some control signal and the I2C for the temperature sensor. Together we need 12 signals.

Displaymbed LPC1768mbed KL25Zsignal type
1 GNDGNDGNDGND
2 3V3VOUTP3V33.3 V power
3 SCKp7PTD1SCK
4 MOSIp5PTD2MOSI
5 MISOp6PTD3MISO
6 SSELp8PTC17GPIO
7 Busyp13PTA16GPIO
8 Borderp10PTD6GPIO
9 SCLp27PTE1SCL
10 SDAp28PTE0SDA
11 PWMp26PTD4PWM
12 Resetp12PTA17GPIO
13 Power controlp9PTD7GPIO
14 Dischargep11PTE31GPIO

Software

Fonts

How to get nice looking fonts ?

To print characters to a graphic screen we need a font. To code a font by paper is ok for a small lcd, but for a 264*176 pixel display we need bigger fonts. A 12*12 pixel font is readable, but it a lot of work to construct it by hand.

Fonts can be made with the GLCD Font Creator also from http://www.mikroe.com .

With this program you can load a window font and convert it into a c-array. To use this Font with my lib you have to add 4 parameter at the beginning of the font array. - the number of byte / char - the vertial size in pixel - the horizontal size in pixel - the number of byte per vertical line (it is vertical size / 8 ) You also have to change the type of array to char[]. After that you can switch between different fonts with set_font(unsigned char* font); The horizontal size of each character is also stored in the font. It look better if you use bigger fonts or italic. The letter M is wider than a l.

Here are some Fonts from me : http://mbed.org/users/dreschpe/code/TFT_fonts/

The small made for the mbed lab board can also be used : http://mbed.org/users/dreschpe/code/LCD_fonts/

And from Peter Holzleitner : http://mbed.org/users/pholzleitner/code/SourceCodePro31-SB/

Text commands :

You can use the claim() function to redirect the output to stdout or stderr to the display. After claim(stdout) you can simply use the printf function without the classname to print to the display. All other printf from other libs are also redirected to the display if you use this.

  • printf(...); print text and variables to the buffer with format options.
  • locate(x,y); function is used to setup the cursor position. x,y are the pixel position.

Graphics

Graphic commands :

  • cls(); Fill the screen with background color
  • pixel(x,y,color); set a single pixel at x,y with 1 : black or 0 : white
  • line(x0,y0,x1,y1,color); draw a line from x0,y0 to x1,y1 with color
  • rect(x0,y0,x1,y1,color); draw a rectangle x0,y0 to x1,y1 with color
  • fillrect(x0,y0,x1,y1,color); draw a filled rectangle
  • circle( x0,y0,radius ,color); draw a circle around x0,y0 with radius
  • fillcircle(x0,y0,radius ,color); draw a filled circle around x0,y0 with radius
  • setmode(mode); Set the drawing mode for all functions. mode can be NORMAL -> 0 is white and 1 is black or XOR -> the new pixel is a xor between the old display and the new. This mode will invert if a black pixel is draw over a black pixel.
  • print_bm(Bitmap ,x0,x0); Print a monochrome bitmap array. This graphic is defined by a Bitmap struct :

The pixel date array :

static char arm_logo[]={
0x00,0x00...
};

and a Bitmap struct:

Bitmap bitmARM = {
  48, // XSize
  48, // YSize 
  6,  // Bytes in Line
  arm_logo // Pointer to picture data 
};

To convert a graphic into a byte array we can use the tool Picture Converter 1bpp from http://www.embedded-tools.de.vu/ With this tool we load a image, press the convert button and save it as C-Header file. We have to save with horizontal orientation, so we have to press "No". Inside this file we find the data array which we can copy into a header file.

All this commands are writing to the frame buffer only ! To change the active display we have to call

  • write_disp(); This will refresh the display.

Sample code

test code for the LPC1768: http://mbed.org/users/dreschpe/code/epaper_mbed_test/

test code for KL25Z: http://mbed.org/users/dreschpe/code/epaper_mbed_130411_KL25Z/

#include "mbed.h"
#include "EaEpaper.h"
#include "Arial28x28.h"
#include "Arial12x12.h"
#include "font_big.h"
#include "graphics.h"

EaEpaper epaper(
                PTD7,            // PWR_CTRL
                PTD6,            // BORDER
                PTE31,           // DISCHARGE
                PTA17,           // RESET_DISP
                PTA16,           // BUSY
                PTC17,           // SSEL
                PTD4,            // PWM
                PTD2,PTD3,PTD1,  // MOSI,MISO,SCLK
                PTE0,PTE1);      // SDA,SDL 
 
int main() {

    epaper.cls();                                      // clear screen
    epaper.set_font((unsigned char*) Arial28x28);  // select the font
    epaper.locate(5,20);                           // set cursor
    epaper.printf("Hello Mbed");                  // print  text
    epaper.rect(3,15,150,50,1);                  // print a frame 
     
    epaper.set_font((unsigned char*) Arial12x12);  // change font
    epaper.locate(5,60);                               // set cursor
    epaper.printf("small Font");                    // print text
    epaper.set_font((unsigned char*) Neu42x35);  // change font
    epaper.locate(5,70);                               //set cursor
    epaper.printf("big Font");                        // change font
    
    epaper.write_disp(); // update screen       // update display
    
    wait(5);                                           // wait 5 s
    epaper.fillcircle(180,30,22,1);              // paint filled circle
    epaper.circle(160,150,20,1);               // paint circle
    epaper.write_disp(); // update screen      // update display
    
}
  
Committer:
dreschpe
Date:
Wed Jun 25 17:43:32 2014 +0000
Revision:
3:1371614703cd
Parent:
0:fedcef5319f5
remove the use of the BurstSPI driver to make the lib compatible with all platforms. There is no time difference, because the display itself need so much time.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dreschpe 0:fedcef5319f5 1
dreschpe 0:fedcef5319f5 2 #include "EaEpaper.h"
dreschpe 0:fedcef5319f5 3
dreschpe 0:fedcef5319f5 4 #define EA_IMG_BUF_SZ (5808) // 264 x 176 / 8 = 5808
dreschpe 0:fedcef5319f5 5
dreschpe 0:fedcef5319f5 6 #define LM75A_ADDRESS (0x92) // 0x49 << 1
dreschpe 0:fedcef5319f5 7 #define LM75A_CMD_TEMP 0x00
dreschpe 0:fedcef5319f5 8
dreschpe 0:fedcef5319f5 9 static uint8_t _oldImage[EA_IMG_BUF_SZ];
dreschpe 0:fedcef5319f5 10 static uint8_t _newImage[EA_IMG_BUF_SZ];
dreschpe 0:fedcef5319f5 11
dreschpe 0:fedcef5319f5 12 EaEpaper::EaEpaper(PinName p_on, PinName border, PinName discharge, PinName reset, PinName busy, PinName cs,
dreschpe 0:fedcef5319f5 13 PinName pwm,
dreschpe 0:fedcef5319f5 14 PinName mosi, PinName miso, PinName sck,
dreschpe 0:fedcef5319f5 15 PinName sda, PinName scl,
dreschpe 0:fedcef5319f5 16 const char* name):
dreschpe 0:fedcef5319f5 17 epd_(EPD_2_7,
dreschpe 0:fedcef5319f5 18 p_on, // panel_on_pin
dreschpe 0:fedcef5319f5 19 border, // border_pin
dreschpe 0:fedcef5319f5 20 discharge, // discharge_pin
dreschpe 0:fedcef5319f5 21 pwm, // pwm_pin
dreschpe 0:fedcef5319f5 22 reset, // reset_pin
dreschpe 0:fedcef5319f5 23 busy, // busy_pin
dreschpe 0:fedcef5319f5 24 cs, // chip_select_pin
dreschpe 0:fedcef5319f5 25 mosi, // mosi
dreschpe 0:fedcef5319f5 26 miso, // miso
dreschpe 0:fedcef5319f5 27 sck), // sck
dreschpe 0:fedcef5319f5 28 i2c_(sda, scl),
dreschpe 0:fedcef5319f5 29 GraphicsDisplay(name)
dreschpe 0:fedcef5319f5 30 {
dreschpe 0:fedcef5319f5 31 draw_mode = NORMAL;
dreschpe 0:fedcef5319f5 32 memset(_oldImage, 0, EA_IMG_BUF_SZ);
dreschpe 0:fedcef5319f5 33 memset(_newImage, 0, EA_IMG_BUF_SZ);
dreschpe 0:fedcef5319f5 34 }
dreschpe 0:fedcef5319f5 35
dreschpe 0:fedcef5319f5 36
dreschpe 0:fedcef5319f5 37 int EaEpaper::width()
dreschpe 0:fedcef5319f5 38 {
dreschpe 0:fedcef5319f5 39 return 264;
dreschpe 0:fedcef5319f5 40 }
dreschpe 0:fedcef5319f5 41
dreschpe 0:fedcef5319f5 42 int EaEpaper::height()
dreschpe 0:fedcef5319f5 43 {
dreschpe 0:fedcef5319f5 44 return 176;
dreschpe 0:fedcef5319f5 45 }
dreschpe 0:fedcef5319f5 46
dreschpe 0:fedcef5319f5 47
dreschpe 0:fedcef5319f5 48 // erase pixel after power up
dreschpe 0:fedcef5319f5 49 void EaEpaper::clear()
dreschpe 0:fedcef5319f5 50 {
dreschpe 0:fedcef5319f5 51 epd_.begin();
dreschpe 0:fedcef5319f5 52 epd_.setFactor(readTemperature()/100);
dreschpe 0:fedcef5319f5 53 epd_.clear();
dreschpe 0:fedcef5319f5 54 epd_.end();
dreschpe 0:fedcef5319f5 55
dreschpe 0:fedcef5319f5 56 memset(_oldImage, 0, EA_IMG_BUF_SZ);
dreschpe 0:fedcef5319f5 57 memset(_newImage, 0, EA_IMG_BUF_SZ);
dreschpe 0:fedcef5319f5 58 }
dreschpe 0:fedcef5319f5 59
dreschpe 0:fedcef5319f5 60 // update screen _newImage -> _oldImage
dreschpe 0:fedcef5319f5 61 void EaEpaper::write_disp(void)
dreschpe 0:fedcef5319f5 62 {
dreschpe 0:fedcef5319f5 63 epd_.begin();
dreschpe 0:fedcef5319f5 64 epd_.setFactor(readTemperature()/100);
dreschpe 0:fedcef5319f5 65 epd_.image(_oldImage, _newImage);
dreschpe 0:fedcef5319f5 66 epd_.end();
dreschpe 0:fedcef5319f5 67
dreschpe 0:fedcef5319f5 68 memcpy(_oldImage, _newImage, EA_IMG_BUF_SZ);
dreschpe 0:fedcef5319f5 69 }
dreschpe 0:fedcef5319f5 70
dreschpe 0:fedcef5319f5 71 // read LM75A sensor on board to calculate display speed
dreschpe 0:fedcef5319f5 72 int32_t EaEpaper::readTemperature()
dreschpe 0:fedcef5319f5 73 {
dreschpe 0:fedcef5319f5 74 char buf[2];
dreschpe 0:fedcef5319f5 75 int32_t t = 0;
dreschpe 0:fedcef5319f5 76 char reg = LM75A_CMD_TEMP;
dreschpe 0:fedcef5319f5 77
dreschpe 0:fedcef5319f5 78 i2c_.write(LM75A_ADDRESS, &reg, 1);
dreschpe 0:fedcef5319f5 79 i2c_.read(LM75A_ADDRESS, buf, 2);
dreschpe 0:fedcef5319f5 80
dreschpe 0:fedcef5319f5 81 t = ((buf[0] << 8) | (buf[1]));
dreschpe 0:fedcef5319f5 82
dreschpe 0:fedcef5319f5 83 return ((t * 100) >> 8);
dreschpe 0:fedcef5319f5 84 }
dreschpe 0:fedcef5319f5 85
dreschpe 0:fedcef5319f5 86 // set one pixel in buffer _newImage
dreschpe 0:fedcef5319f5 87
dreschpe 0:fedcef5319f5 88 void EaEpaper::pixel(int x, int y, int color)
dreschpe 0:fedcef5319f5 89 {
dreschpe 0:fedcef5319f5 90 // first check parameter
dreschpe 0:fedcef5319f5 91 if(x > 263 || y > 175 || x < 0 || y < 0) return;
dreschpe 0:fedcef5319f5 92
dreschpe 0:fedcef5319f5 93 if(draw_mode == NORMAL) {
dreschpe 0:fedcef5319f5 94 if(color == 0)
dreschpe 0:fedcef5319f5 95 _newImage[(x / 8) + ((y-1) * 33)] &= ~(1 << (x%8)); // erase pixel
dreschpe 0:fedcef5319f5 96 else
dreschpe 0:fedcef5319f5 97 _newImage[(x / 8) + ((y-1) * 33)] |= (1 << (x%8)); // set pixel
dreschpe 0:fedcef5319f5 98 } else { // XOR mode
dreschpe 0:fedcef5319f5 99 if(color == 1)
dreschpe 0:fedcef5319f5 100 _newImage[(x / 8) + ((y-1) * 33)] ^= (1 << (x%8)); // xor pixel
dreschpe 0:fedcef5319f5 101 }
dreschpe 0:fedcef5319f5 102 }
dreschpe 0:fedcef5319f5 103
dreschpe 0:fedcef5319f5 104 // clear screen
dreschpe 0:fedcef5319f5 105 void EaEpaper::cls(void)
dreschpe 0:fedcef5319f5 106 {
dreschpe 0:fedcef5319f5 107 memset(_newImage, 0, EA_IMG_BUF_SZ); // clear display buffer
dreschpe 0:fedcef5319f5 108 }
dreschpe 0:fedcef5319f5 109
dreschpe 0:fedcef5319f5 110 // print line
dreschpe 0:fedcef5319f5 111 void EaEpaper::line(int x0, int y0, int x1, int y1, int color)
dreschpe 0:fedcef5319f5 112 {
dreschpe 0:fedcef5319f5 113 int dx = 0, dy = 0;
dreschpe 0:fedcef5319f5 114 int dx_sym = 0, dy_sym = 0;
dreschpe 0:fedcef5319f5 115 int dx_x2 = 0, dy_x2 = 0;
dreschpe 0:fedcef5319f5 116 int di = 0;
dreschpe 0:fedcef5319f5 117
dreschpe 0:fedcef5319f5 118 dx = x1-x0;
dreschpe 0:fedcef5319f5 119 dy = y1-y0;
dreschpe 0:fedcef5319f5 120
dreschpe 0:fedcef5319f5 121 if (dx > 0) {
dreschpe 0:fedcef5319f5 122 dx_sym = 1;
dreschpe 0:fedcef5319f5 123 } else {
dreschpe 0:fedcef5319f5 124 dx_sym = -1;
dreschpe 0:fedcef5319f5 125 }
dreschpe 0:fedcef5319f5 126
dreschpe 0:fedcef5319f5 127 if (dy > 0) {
dreschpe 0:fedcef5319f5 128 dy_sym = 1;
dreschpe 0:fedcef5319f5 129 } else {
dreschpe 0:fedcef5319f5 130 dy_sym = -1;
dreschpe 0:fedcef5319f5 131 }
dreschpe 0:fedcef5319f5 132
dreschpe 0:fedcef5319f5 133 dx = dx_sym*dx;
dreschpe 0:fedcef5319f5 134 dy = dy_sym*dy;
dreschpe 0:fedcef5319f5 135
dreschpe 0:fedcef5319f5 136 dx_x2 = dx*2;
dreschpe 0:fedcef5319f5 137 dy_x2 = dy*2;
dreschpe 0:fedcef5319f5 138
dreschpe 0:fedcef5319f5 139 if (dx >= dy) {
dreschpe 0:fedcef5319f5 140 di = dy_x2 - dx;
dreschpe 0:fedcef5319f5 141 while (x0 != x1) {
dreschpe 0:fedcef5319f5 142
dreschpe 0:fedcef5319f5 143 pixel(x0, y0, color);
dreschpe 0:fedcef5319f5 144 x0 += dx_sym;
dreschpe 0:fedcef5319f5 145 if (di<0) {
dreschpe 0:fedcef5319f5 146 di += dy_x2;
dreschpe 0:fedcef5319f5 147 } else {
dreschpe 0:fedcef5319f5 148 di += dy_x2 - dx_x2;
dreschpe 0:fedcef5319f5 149 y0 += dy_sym;
dreschpe 0:fedcef5319f5 150 }
dreschpe 0:fedcef5319f5 151 }
dreschpe 0:fedcef5319f5 152 pixel(x0, y0, color);
dreschpe 0:fedcef5319f5 153 } else {
dreschpe 0:fedcef5319f5 154 di = dx_x2 - dy;
dreschpe 0:fedcef5319f5 155 while (y0 != y1) {
dreschpe 0:fedcef5319f5 156 pixel(x0, y0, color);
dreschpe 0:fedcef5319f5 157 y0 += dy_sym;
dreschpe 0:fedcef5319f5 158 if (di < 0) {
dreschpe 0:fedcef5319f5 159 di += dx_x2;
dreschpe 0:fedcef5319f5 160 } else {
dreschpe 0:fedcef5319f5 161 di += dx_x2 - dy_x2;
dreschpe 0:fedcef5319f5 162 x0 += dx_sym;
dreschpe 0:fedcef5319f5 163 }
dreschpe 0:fedcef5319f5 164 }
dreschpe 0:fedcef5319f5 165 pixel(x0, y0, color);
dreschpe 0:fedcef5319f5 166 }
dreschpe 0:fedcef5319f5 167 }
dreschpe 0:fedcef5319f5 168
dreschpe 0:fedcef5319f5 169 // print rect
dreschpe 0:fedcef5319f5 170 void EaEpaper::rect(int x0, int y0, int x1, int y1, int color)
dreschpe 0:fedcef5319f5 171 {
dreschpe 0:fedcef5319f5 172
dreschpe 0:fedcef5319f5 173 if (x1 > x0) line(x0,y0,x1,y0,color);
dreschpe 0:fedcef5319f5 174 else line(x1,y0,x0,y0,color);
dreschpe 0:fedcef5319f5 175
dreschpe 0:fedcef5319f5 176 if (y1 > y0) line(x0,y0,x0,y1,color);
dreschpe 0:fedcef5319f5 177 else line(x0,y1,x0,y0,color);
dreschpe 0:fedcef5319f5 178
dreschpe 0:fedcef5319f5 179 if (x1 > x0) line(x0,y1,x1,y1,color);
dreschpe 0:fedcef5319f5 180 else line(x1,y1,x0,y1,color);
dreschpe 0:fedcef5319f5 181
dreschpe 0:fedcef5319f5 182 if (y1 > y0) line(x1,y0,x1,y1,color);
dreschpe 0:fedcef5319f5 183 else line(x1,y1,x1,y0,color);
dreschpe 0:fedcef5319f5 184 }
dreschpe 0:fedcef5319f5 185
dreschpe 0:fedcef5319f5 186 // print filled rect
dreschpe 0:fedcef5319f5 187 void EaEpaper::fillrect(int x0, int y0, int x1, int y1, int color)
dreschpe 0:fedcef5319f5 188 {
dreschpe 0:fedcef5319f5 189 int l,c,i;
dreschpe 0:fedcef5319f5 190 if(x0 > x1) {
dreschpe 0:fedcef5319f5 191 i = x0;
dreschpe 0:fedcef5319f5 192 x0 = x1;
dreschpe 0:fedcef5319f5 193 x1 = i;
dreschpe 0:fedcef5319f5 194 }
dreschpe 0:fedcef5319f5 195
dreschpe 0:fedcef5319f5 196 if(y0 > y1) {
dreschpe 0:fedcef5319f5 197 i = y0;
dreschpe 0:fedcef5319f5 198 y0 = y1;
dreschpe 0:fedcef5319f5 199 y1 = i;
dreschpe 0:fedcef5319f5 200 }
dreschpe 0:fedcef5319f5 201
dreschpe 0:fedcef5319f5 202 for(l = x0; l<= x1; l ++) {
dreschpe 0:fedcef5319f5 203 for(c = y0; c<= y1; c++) {
dreschpe 0:fedcef5319f5 204 pixel(l,c,color);
dreschpe 0:fedcef5319f5 205 }
dreschpe 0:fedcef5319f5 206 }
dreschpe 0:fedcef5319f5 207 }
dreschpe 0:fedcef5319f5 208
dreschpe 0:fedcef5319f5 209 // print circle
dreschpe 0:fedcef5319f5 210 void EaEpaper::circle(int x0, int y0, int r, int color)
dreschpe 0:fedcef5319f5 211 {
dreschpe 0:fedcef5319f5 212 int x = -r, y = 0, err = 2-2*r, e2;
dreschpe 0:fedcef5319f5 213 do {
dreschpe 0:fedcef5319f5 214 pixel(x0-x, y0+y,color);
dreschpe 0:fedcef5319f5 215 pixel(x0+x, y0+y,color);
dreschpe 0:fedcef5319f5 216 pixel(x0+x, y0-y,color);
dreschpe 0:fedcef5319f5 217 pixel(x0-x, y0-y,color);
dreschpe 0:fedcef5319f5 218 e2 = err;
dreschpe 0:fedcef5319f5 219 if (e2 <= y) {
dreschpe 0:fedcef5319f5 220 err += ++y*2+1;
dreschpe 0:fedcef5319f5 221 if (-x == y && e2 <= x) e2 = 0;
dreschpe 0:fedcef5319f5 222 }
dreschpe 0:fedcef5319f5 223 if (e2 > x) err += ++x*2+1;
dreschpe 0:fedcef5319f5 224 } while (x <= 0);
dreschpe 0:fedcef5319f5 225
dreschpe 0:fedcef5319f5 226 }
dreschpe 0:fedcef5319f5 227
dreschpe 0:fedcef5319f5 228 // print filled circle
dreschpe 0:fedcef5319f5 229 void EaEpaper::fillcircle(int x0, int y0, int r, int color)
dreschpe 0:fedcef5319f5 230 {
dreschpe 0:fedcef5319f5 231 int x = -r, y = 0, err = 2-2*r, e2;
dreschpe 0:fedcef5319f5 232 do {
dreschpe 0:fedcef5319f5 233 line(x0-x, y0-y, x0-x, y0+y, color);
dreschpe 0:fedcef5319f5 234 line(x0+x, y0-y, x0+x, y0+y, color);
dreschpe 0:fedcef5319f5 235 e2 = err;
dreschpe 0:fedcef5319f5 236 if (e2 <= y) {
dreschpe 0:fedcef5319f5 237 err += ++y*2+1;
dreschpe 0:fedcef5319f5 238 if (-x == y && e2 <= x) e2 = 0;
dreschpe 0:fedcef5319f5 239 }
dreschpe 0:fedcef5319f5 240 if (e2 > x) err += ++x*2+1;
dreschpe 0:fedcef5319f5 241 } while (x <= 0);
dreschpe 0:fedcef5319f5 242 }
dreschpe 0:fedcef5319f5 243
dreschpe 0:fedcef5319f5 244 // set drawing mode
dreschpe 0:fedcef5319f5 245 void EaEpaper::setmode(int mode)
dreschpe 0:fedcef5319f5 246 {
dreschpe 0:fedcef5319f5 247 draw_mode = mode;
dreschpe 0:fedcef5319f5 248 }
dreschpe 0:fedcef5319f5 249
dreschpe 0:fedcef5319f5 250 // set cursor position
dreschpe 0:fedcef5319f5 251 void EaEpaper::locate(int x, int y)
dreschpe 0:fedcef5319f5 252 {
dreschpe 0:fedcef5319f5 253 char_x = x;
dreschpe 0:fedcef5319f5 254 char_y = y;
dreschpe 0:fedcef5319f5 255 }
dreschpe 0:fedcef5319f5 256
dreschpe 0:fedcef5319f5 257 // calc char columns
dreschpe 0:fedcef5319f5 258 int EaEpaper::columns()
dreschpe 0:fedcef5319f5 259 {
dreschpe 0:fedcef5319f5 260 return width() / font[1];
dreschpe 0:fedcef5319f5 261 }
dreschpe 0:fedcef5319f5 262
dreschpe 0:fedcef5319f5 263 // calc char rows
dreschpe 0:fedcef5319f5 264 int EaEpaper::rows()
dreschpe 0:fedcef5319f5 265 {
dreschpe 0:fedcef5319f5 266 return height() / font[2];
dreschpe 0:fedcef5319f5 267 }
dreschpe 0:fedcef5319f5 268
dreschpe 0:fedcef5319f5 269 // print char
dreschpe 0:fedcef5319f5 270 int EaEpaper::_putc(int value)
dreschpe 0:fedcef5319f5 271 {
dreschpe 0:fedcef5319f5 272 if (value == '\n') { // new line
dreschpe 0:fedcef5319f5 273 char_x = 0;
dreschpe 0:fedcef5319f5 274 char_y = char_y + font[2];
dreschpe 0:fedcef5319f5 275 if (char_y >= height() - font[2]) {
dreschpe 0:fedcef5319f5 276 char_y = 0;
dreschpe 0:fedcef5319f5 277 }
dreschpe 0:fedcef5319f5 278 } else {
dreschpe 0:fedcef5319f5 279 character(char_x, char_y, value);
dreschpe 0:fedcef5319f5 280 }
dreschpe 0:fedcef5319f5 281 return value;
dreschpe 0:fedcef5319f5 282 }
dreschpe 0:fedcef5319f5 283
dreschpe 0:fedcef5319f5 284 // paint char out of font
dreschpe 0:fedcef5319f5 285 void EaEpaper::character(int x, int y, int c)
dreschpe 0:fedcef5319f5 286 {
dreschpe 0:fedcef5319f5 287 unsigned int hor,vert,offset,bpl,j,i,b;
dreschpe 0:fedcef5319f5 288 unsigned char* zeichen;
dreschpe 0:fedcef5319f5 289 unsigned char z,w;
dreschpe 0:fedcef5319f5 290
dreschpe 0:fedcef5319f5 291 if ((c < 31) || (c > 127)) return; // test char range
dreschpe 0:fedcef5319f5 292
dreschpe 0:fedcef5319f5 293 // read font parameter from start of array
dreschpe 0:fedcef5319f5 294 offset = font[0]; // bytes / char
dreschpe 0:fedcef5319f5 295 hor = font[1]; // get hor size of font
dreschpe 0:fedcef5319f5 296 vert = font[2]; // get vert size of font
dreschpe 0:fedcef5319f5 297 bpl = font[3]; // bytes per line
dreschpe 0:fedcef5319f5 298
dreschpe 0:fedcef5319f5 299 if (char_x + hor > width()) {
dreschpe 0:fedcef5319f5 300 char_x = 0;
dreschpe 0:fedcef5319f5 301 char_y = char_y + vert;
dreschpe 0:fedcef5319f5 302 if (char_y >= height() - font[2]) {
dreschpe 0:fedcef5319f5 303 char_y = 0;
dreschpe 0:fedcef5319f5 304 }
dreschpe 0:fedcef5319f5 305 }
dreschpe 0:fedcef5319f5 306
dreschpe 0:fedcef5319f5 307 zeichen = &font[((c -32) * offset) + 4]; // start of char bitmap
dreschpe 0:fedcef5319f5 308 w = zeichen[0]; // width of actual char
dreschpe 0:fedcef5319f5 309 // construct the char into the buffer
dreschpe 0:fedcef5319f5 310 for (j=0; j<vert; j++) { // vert line
dreschpe 0:fedcef5319f5 311 for (i=0; i<hor; i++) { // horz line
dreschpe 0:fedcef5319f5 312 z = zeichen[bpl * i + ((j & 0xF8) >> 3)+1];
dreschpe 0:fedcef5319f5 313 b = 1 << (j & 0x07);
dreschpe 0:fedcef5319f5 314 if (( z & b ) == 0x00) {
dreschpe 0:fedcef5319f5 315 pixel(x+i,y+j,0);
dreschpe 0:fedcef5319f5 316 } else {
dreschpe 0:fedcef5319f5 317 pixel(x+i,y+j,1);
dreschpe 0:fedcef5319f5 318 }
dreschpe 0:fedcef5319f5 319
dreschpe 0:fedcef5319f5 320 }
dreschpe 0:fedcef5319f5 321 }
dreschpe 0:fedcef5319f5 322
dreschpe 0:fedcef5319f5 323 char_x += w;
dreschpe 0:fedcef5319f5 324 }
dreschpe 0:fedcef5319f5 325
dreschpe 0:fedcef5319f5 326 // set actual font
dreschpe 0:fedcef5319f5 327 void EaEpaper::set_font(unsigned char* f)
dreschpe 0:fedcef5319f5 328 {
dreschpe 0:fedcef5319f5 329 font = f;
dreschpe 0:fedcef5319f5 330 }
dreschpe 0:fedcef5319f5 331
dreschpe 0:fedcef5319f5 332 void EaEpaper::print_bm(Bitmap bm, int x, int y)
dreschpe 0:fedcef5319f5 333 {
dreschpe 0:fedcef5319f5 334 int h,v,b;
dreschpe 0:fedcef5319f5 335 char d;
dreschpe 0:fedcef5319f5 336
dreschpe 0:fedcef5319f5 337 for(v=0; v < bm.ySize; v++) { // lines
dreschpe 0:fedcef5319f5 338 for(h=0; h < bm.xSize; h++) { // pixel
dreschpe 0:fedcef5319f5 339 if(h + x > width()) break;
dreschpe 0:fedcef5319f5 340 if(v + y > height()) break;
dreschpe 0:fedcef5319f5 341 d = bm.data[bm.Byte_in_Line * v + ((h & 0xF8) >> 3)];
dreschpe 0:fedcef5319f5 342 b = 0x80 >> (h & 0x07);
dreschpe 0:fedcef5319f5 343 if((d & b) == 0) {
dreschpe 0:fedcef5319f5 344 pixel(x+h,y+v,0);
dreschpe 0:fedcef5319f5 345 } else {
dreschpe 0:fedcef5319f5 346 pixel(x+h,y+v,1);
dreschpe 0:fedcef5319f5 347 }
dreschpe 0:fedcef5319f5 348 }
dreschpe 0:fedcef5319f5 349 }
dreschpe 0:fedcef5319f5 350
dreschpe 0:fedcef5319f5 351 }
dreschpe 0:fedcef5319f5 352
dreschpe 0:fedcef5319f5 353