Y-con P020 Electric Paper Display

Dependents:   YconP020_USBIFEx

This is a library for Y-con P020 Electric Paper Display.

sample program is here.

詳しくはこちら(sorry only in Japanese)をご覧ください。

Committer:
jk1lot
Date:
Fri Jul 01 13:22:18 2016 +0000
Revision:
0:4dbc7e226777
Child:
1:a7e6ebc4cb72
create library

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jk1lot 0:4dbc7e226777 1 #ifndef YCONP020_H
jk1lot 0:4dbc7e226777 2 #define YCONP020_H
jk1lot 0:4dbc7e226777 3
jk1lot 0:4dbc7e226777 4 #include "Stream.h"
jk1lot 0:4dbc7e226777 5 #include "Serial.h"
jk1lot 0:4dbc7e226777 6 using namespace mbed;
jk1lot 0:4dbc7e226777 7 #include <string>
jk1lot 0:4dbc7e226777 8 #include <vector>
jk1lot 0:4dbc7e226777 9 #include <queue>
jk1lot 0:4dbc7e226777 10 using namespace std;
jk1lot 0:4dbc7e226777 11 #include "GraphicsDisplay.h"
jk1lot 0:4dbc7e226777 12
jk1lot 0:4dbc7e226777 13 class YconP020GBuf : public GraphicsDisplay {
jk1lot 0:4dbc7e226777 14 public:
jk1lot 0:4dbc7e226777 15 enum INTERNALBUF { MAX_X=200,MAX_Y=96 };
jk1lot 0:4dbc7e226777 16 YconP020GBuf(const char *name=NULL) : GraphicsDisplay(name) {
jk1lot 0:4dbc7e226777 17 setpixelsize();
jk1lot 0:4dbc7e226777 18 }
jk1lot 0:4dbc7e226777 19 virtual void pixel(int x, int y, int b) {
jk1lot 0:4dbc7e226777 20 if(x<0 || x>=MAX_X/pixelsizex || y<0 || y>=MAX_Y/pixelsizey) return;
jk1lot 0:4dbc7e226777 21 for(int i=0; i<pixelsizex; i++) {
jk1lot 0:4dbc7e226777 22 for(int j=0; j<pixelsizey; j++) {
jk1lot 0:4dbc7e226777 23 pixel1x1(x*pixelsizex+i, y*pixelsizey+j, b);
jk1lot 0:4dbc7e226777 24 }
jk1lot 0:4dbc7e226777 25 }
jk1lot 0:4dbc7e226777 26 }
jk1lot 0:4dbc7e226777 27 void setpixelsize(int x=1, int y=1) {
jk1lot 0:4dbc7e226777 28 pixelsizex=x;
jk1lot 0:4dbc7e226777 29 pixelsizey=y;
jk1lot 0:4dbc7e226777 30 }
jk1lot 0:4dbc7e226777 31 virtual int width() {return MAX_X;}
jk1lot 0:4dbc7e226777 32 virtual int height() {return MAX_Y;}
jk1lot 0:4dbc7e226777 33 int8_t get8(size_t x,size_t y) {return buffer[y][x];}
jk1lot 0:4dbc7e226777 34 protected:
jk1lot 0:4dbc7e226777 35 void pixel1x1(int x, int y, int b) {
jk1lot 0:4dbc7e226777 36 if(x<0 || x>=MAX_X || y<0 || y>=MAX_Y) return;
jk1lot 0:4dbc7e226777 37 if(!b) buffer[MAX_Y-1-y][x/8] |= 1<<(7-(x%8));
jk1lot 0:4dbc7e226777 38 else buffer[MAX_Y-1-y][x/8] &= ~(1<<(7-(x%8)));
jk1lot 0:4dbc7e226777 39 }
jk1lot 0:4dbc7e226777 40 private:
jk1lot 0:4dbc7e226777 41 int8_t buffer[MAX_Y][MAX_X/8];
jk1lot 0:4dbc7e226777 42 int pixelsizex;
jk1lot 0:4dbc7e226777 43 int pixelsizey;
jk1lot 0:4dbc7e226777 44 };
jk1lot 0:4dbc7e226777 45
jk1lot 0:4dbc7e226777 46 class YconP020 : public Stream {
jk1lot 0:4dbc7e226777 47 static const size_t MAXRECBUFSIZE=1000;
jk1lot 0:4dbc7e226777 48 public:
jk1lot 0:4dbc7e226777 49 typedef enum {
jk1lot 0:4dbc7e226777 50 NOERROR=0,FILEOPENERR=1,REGINDEXERR=2,FILENOTEXIST=3,DIROPENERR=4
jk1lot 0:4dbc7e226777 51 } error_t;
jk1lot 0:4dbc7e226777 52
jk1lot 0:4dbc7e226777 53 YconP020(PinName tx, PinName rx);
jk1lot 0:4dbc7e226777 54
jk1lot 0:4dbc7e226777 55 /// Similar to Serial::readable()
jk1lot 0:4dbc7e226777 56 bool readable() {return !recoutbuf.empty();}
jk1lot 0:4dbc7e226777 57 /// check ready to send command
jk1lot 0:4dbc7e226777 58 bool command_ready() const { return lastchar=='!'; }
jk1lot 0:4dbc7e226777 59 /// wait for ready to send command
jk1lot 0:4dbc7e226777 60 /// @return false timeout
jk1lot 0:4dbc7e226777 61 bool wait_command_ready(int ms=10000);
jk1lot 0:4dbc7e226777 62 /// change to command mode from normal(send file) mode
jk1lot 0:4dbc7e226777 63 /// @return flase timeout
jk1lot 0:4dbc7e226777 64 bool command_mode();
jk1lot 0:4dbc7e226777 65
jk1lot 0:4dbc7e226777 66 //commands
jk1lot 0:4dbc7e226777 67 string help_str() {return get_stringparam("?");} // (1)?
jk1lot 0:4dbc7e226777 68 void clear_screen(bool white=true) {void_command(white? "W":"B");} //(2)W, (3)B
jk1lot 0:4dbc7e226777 69 void negative_screen() {void_command("N");} //(4)N
jk1lot 0:4dbc7e226777 70 void dispstoredpict(int picnum); //(5)D
jk1lot 0:4dbc7e226777 71 error_t storepictfile(const string& filename, const int picnum); //(6)R
jk1lot 0:4dbc7e226777 72 string infomation_str() {return get_stringparam("I");}//(7)I
jk1lot 0:4dbc7e226777 73 void start_demo() {void_command("DEMO",false);} //(8)DEMO
jk1lot 0:4dbc7e226777 74 void stop_demo();
jk1lot 0:4dbc7e226777 75 int get_interval() {return get_intparam("INTERVAL","Interval");} //(9)INTERVAL
jk1lot 0:4dbc7e226777 76 void set_interval(int t) {set_intparam("INTERVAL", t);}
jk1lot 0:4dbc7e226777 77 //(10)LASTWAIT
jk1lot 0:4dbc7e226777 78 int get_lastwait() {return get_intparam("LASTWAIT","Wait");}
jk1lot 0:4dbc7e226777 79 void set_lastwait(int t) {return set_intparam("LASTWAIT", t);}
jk1lot 0:4dbc7e226777 80 //(11)STANDBY
jk1lot 0:4dbc7e226777 81 bool get_standby() {return get_boolparam("STANDBY");}
jk1lot 0:4dbc7e226777 82 void set_standby(bool f) {return set_intparam("STANDBY", f);}
jk1lot 0:4dbc7e226777 83 //(12)LED
jk1lot 0:4dbc7e226777 84 bool get_led() {return get_boolparam("LED");}
jk1lot 0:4dbc7e226777 85 void set_led(bool f) {return set_intparam("LED", f);}
jk1lot 0:4dbc7e226777 86 //(13)P37
jk1lot 0:4dbc7e226777 87 int get_p37() {return get_boolparam("P37");}
jk1lot 0:4dbc7e226777 88 void set_p37(bool f) {return set_intparam("P37", f);}
jk1lot 0:4dbc7e226777 89 void exit_commandmode() {void_command("EXIT",false);} //(14)EXIT
jk1lot 0:4dbc7e226777 90 void reset_screen() {void_command("RESET",false);} //(15)RESET
jk1lot 0:4dbc7e226777 91 string yslab_info() {return get_stringparam("YSLAB");} //(16)YSLAB
jk1lot 0:4dbc7e226777 92
jk1lot 0:4dbc7e226777 93 /// get file list of directories
jk1lot 0:4dbc7e226777 94 const vector<string>& getfilelist(const vector<string>& dirs);
jk1lot 0:4dbc7e226777 95 /// get file list of directory
jk1lot 0:4dbc7e226777 96 const vector<string>& getfilelist(const string& dir);
jk1lot 0:4dbc7e226777 97 /// return previous file list
jk1lot 0:4dbc7e226777 98 const vector<string>& getfilelist() const {return filelist;}
jk1lot 0:4dbc7e226777 99 /// get all file list
jk1lot 0:4dbc7e226777 100 const vector<string>& getfilelistall();
jk1lot 0:4dbc7e226777 101 /// display file
jk1lot 0:4dbc7e226777 102 error_t dispfile(const string& filename);
jk1lot 0:4dbc7e226777 103
jk1lot 0:4dbc7e226777 104 TextDisplay* text() {return &internalbuf;}
jk1lot 0:4dbc7e226777 105 void setpixelsize(int x=0, int y=0) {internalbuf.setpixelsize(x,y);}
jk1lot 0:4dbc7e226777 106 void pset(int x, int y, bool b=true) {internalbuf.pixel(x,y,b);}
jk1lot 0:4dbc7e226777 107 void clear_internalbuf(int8_t data=0) { internalbuf.cls(); }
jk1lot 0:4dbc7e226777 108 void display_internalbuf();
jk1lot 0:4dbc7e226777 109 protected:
jk1lot 0:4dbc7e226777 110 void uartint();
jk1lot 0:4dbc7e226777 111 void push_recbuf(char c);
jk1lot 0:4dbc7e226777 112 void push_recbuf(const string& s);
jk1lot 0:4dbc7e226777 113
jk1lot 0:4dbc7e226777 114 error_t sendfile(const string& filename);
jk1lot 0:4dbc7e226777 115
jk1lot 0:4dbc7e226777 116 //for command line intercept
jk1lot 0:4dbc7e226777 117 int putc_intercept(int c);
jk1lot 0:4dbc7e226777 118 bool commandline_D(const string &comline);
jk1lot 0:4dbc7e226777 119 bool commandline_L(const string &comline);
jk1lot 0:4dbc7e226777 120
jk1lot 0:4dbc7e226777 121 //sub-functions for execute commands
jk1lot 0:4dbc7e226777 122 void void_command(const string& command, bool waitready=true);
jk1lot 0:4dbc7e226777 123 void set_intparam(const string& command, int param);
jk1lot 0:4dbc7e226777 124 int get_intparam(const string& command, const string& retstr);
jk1lot 0:4dbc7e226777 125 bool get_boolparam(const string& command);
jk1lot 0:4dbc7e226777 126 string get_stringparam(const string& command);
jk1lot 0:4dbc7e226777 127
jk1lot 0:4dbc7e226777 128 private:
jk1lot 0:4dbc7e226777 129 Serial uart;
jk1lot 0:4dbc7e226777 130 volatile char lastchar;
jk1lot 0:4dbc7e226777 131 queue<char> recoutbuf;
jk1lot 0:4dbc7e226777 132 string recinbuf;
jk1lot 0:4dbc7e226777 133 bool use_recinbuf;
jk1lot 0:4dbc7e226777 134 vector<string> filelist;
jk1lot 0:4dbc7e226777 135 string localcomline;
jk1lot 0:4dbc7e226777 136 YconP020GBuf internalbuf;
jk1lot 0:4dbc7e226777 137
jk1lot 0:4dbc7e226777 138 virtual int _getc();
jk1lot 0:4dbc7e226777 139 virtual int _putc(int c);
jk1lot 0:4dbc7e226777 140 };
jk1lot 0:4dbc7e226777 141
jk1lot 0:4dbc7e226777 142 #endif