Using mbed USB-UART+alpha for Y-con P020(serialIF Electric Paper Display)

Dependencies:   SDFileSystem USBDevice YconP020 mbed

mbedを使って電子ペーパーの Y-con P020をUSBでPCと接続します。 単に USB-UART変換器で繋いだものと違って、mbedに接続した SDカードなどに置いた BMPファイルを表示することが出来ます。

mbed LPC1768、トラ技ARMライタで動作することを確認しました。
mbed LPC1768では localfilesystem(MBEDドライブ)を SDカード同様に使えます。

詳しくはこちらをご覧ください。

Files at this revision

API Documentation at this revision

Comitter:
jk1lot
Date:
Sun Jul 03 10:43:26 2016 +0000
Parent:
12:1ad828c0ec83
Commit message:
separated YconP020 library; added internal buffer and text out

Changed in this revision

GraphicsDisplay.cpp Show diff for this revision Revisions of this file
GraphicsDisplay.h Show diff for this revision Revisions of this file
TextDisplay.cpp Show diff for this revision Revisions of this file
TextDisplay.h Show diff for this revision Revisions of this file
YconP020.cpp Show diff for this revision Revisions of this file
YconP020.h Show diff for this revision Revisions of this file
YconP020.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 1ad828c0ec83 -r 7137c60fcb06 GraphicsDisplay.cpp
--- a/GraphicsDisplay.cpp	Thu Jun 30 14:49:11 2016 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,176 +0,0 @@
-/* mbed GraphicsDisplay Display Library Base Class
- * Copyright (c) 2007-2009 sford
- * Released under the MIT License: http://mbed.org/license/mit
- */
- 
-#include "GraphicsDisplay.h"
-
-const unsigned char FONT8x8[97][8] = {
-0x08,0x08,0x08,0x00,0x00,0x00,0x00,0x00, // columns, rows, num_bytes_per_char
-0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // space 0x20
-0x30,0x78,0x78,0x30,0x30,0x00,0x30,0x00, // !
-0x6C,0x6C,0x6C,0x00,0x00,0x00,0x00,0x00, // "
-0x6C,0x6C,0xFE,0x6C,0xFE,0x6C,0x6C,0x00, // #
-0x18,0x3E,0x60,0x3C,0x06,0x7C,0x18,0x00, // $
-0x00,0x63,0x66,0x0C,0x18,0x33,0x63,0x00, // %
-0x1C,0x36,0x1C,0x3B,0x6E,0x66,0x3B,0x00, // &
-0x30,0x30,0x60,0x00,0x00,0x00,0x00,0x00, // '
-0x0C,0x18,0x30,0x30,0x30,0x18,0x0C,0x00, // (
-0x30,0x18,0x0C,0x0C,0x0C,0x18,0x30,0x00, // )
-0x00,0x66,0x3C,0xFF,0x3C,0x66,0x00,0x00, // *
-0x00,0x30,0x30,0xFC,0x30,0x30,0x00,0x00, // +
-0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x30, // ,
-0x00,0x00,0x00,0x7E,0x00,0x00,0x00,0x00, // -
-0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x00, // .
-0x03,0x06,0x0C,0x18,0x30,0x60,0x40,0x00, // / (forward slash)
-0x3E,0x63,0x63,0x6B,0x63,0x63,0x3E,0x00, // 0 0x30
-0x18,0x38,0x58,0x18,0x18,0x18,0x7E,0x00, // 1
-0x3C,0x66,0x06,0x1C,0x30,0x66,0x7E,0x00, // 2
-0x3C,0x66,0x06,0x1C,0x06,0x66,0x3C,0x00, // 3
-0x0E,0x1E,0x36,0x66,0x7F,0x06,0x0F,0x00, // 4
-0x7E,0x60,0x7C,0x06,0x06,0x66,0x3C,0x00, // 5
-0x1C,0x30,0x60,0x7C,0x66,0x66,0x3C,0x00, // 6
-0x7E,0x66,0x06,0x0C,0x18,0x18,0x18,0x00, // 7
-0x3C,0x66,0x66,0x3C,0x66,0x66,0x3C,0x00, // 8
-0x3C,0x66,0x66,0x3E,0x06,0x0C,0x38,0x00, // 9
-0x00,0x18,0x18,0x00,0x00,0x18,0x18,0x00, // :
-0x00,0x18,0x18,0x00,0x00,0x18,0x18,0x30, // ;
-0x0C,0x18,0x30,0x60,0x30,0x18,0x0C,0x00, // <
-0x00,0x00,0x7E,0x00,0x00,0x7E,0x00,0x00, // =
-0x30,0x18,0x0C,0x06,0x0C,0x18,0x30,0x00, // >
-0x3C,0x66,0x06,0x0C,0x18,0x00,0x18,0x00, // ?
-0x3E,0x63,0x6F,0x69,0x6F,0x60,0x3E,0x00, // @ 0x40
-0x18,0x3C,0x66,0x66,0x7E,0x66,0x66,0x00, // A
-0x7E,0x33,0x33,0x3E,0x33,0x33,0x7E,0x00, // B
-0x1E,0x33,0x60,0x60,0x60,0x33,0x1E,0x00, // C
-0x7C,0x36,0x33,0x33,0x33,0x36,0x7C,0x00, // D
-0x7F,0x31,0x34,0x3C,0x34,0x31,0x7F,0x00, // E
-0x7F,0x31,0x34,0x3C,0x34,0x30,0x78,0x00, // F
-0x1E,0x33,0x60,0x60,0x67,0x33,0x1F,0x00, // G
-0x66,0x66,0x66,0x7E,0x66,0x66,0x66,0x00, // H
-0x3C,0x18,0x18,0x18,0x18,0x18,0x3C,0x00, // I
-0x0F,0x06,0x06,0x06,0x66,0x66,0x3C,0x00, // J
-0x73,0x33,0x36,0x3C,0x36,0x33,0x73,0x00, // K
-0x78,0x30,0x30,0x30,0x31,0x33,0x7F,0x00, // L
-0x63,0x77,0x7F,0x7F,0x6B,0x63,0x63,0x00, // M
-0x63,0x73,0x7B,0x6F,0x67,0x63,0x63,0x00, // N
-0x3E,0x63,0x63,0x63,0x63,0x63,0x3E,0x00, // O
-0x7E,0x33,0x33,0x3E,0x30,0x30,0x78,0x00, // P 0x50
-0x3C,0x66,0x66,0x66,0x6E,0x3C,0x0E,0x00, // Q
-0x7E,0x33,0x33,0x3E,0x36,0x33,0x73,0x00, // R
-0x3C,0x66,0x30,0x18,0x0C,0x66,0x3C,0x00, // S
-0x7E,0x5A,0x18,0x18,0x18,0x18,0x3C,0x00, // T
-0x66,0x66,0x66,0x66,0x66,0x66,0x7E,0x00, // U
-0x66,0x66,0x66,0x66,0x66,0x3C,0x18,0x00, // V
-0x63,0x63,0x63,0x6B,0x7F,0x77,0x63,0x00, // W
-0x63,0x63,0x36,0x1C,0x1C,0x36,0x63,0x00, // X
-0x66,0x66,0x66,0x3C,0x18,0x18,0x3C,0x00, // Y
-0x7F,0x63,0x46,0x0C,0x19,0x33,0x7F,0x00, // Z
-0x3C,0x30,0x30,0x30,0x30,0x30,0x3C,0x00, // [
-0x60,0x30,0x18,0x0C,0x06,0x03,0x01,0x00, // \ (back slash)
-0x3C,0x0C,0x0C,0x0C,0x0C,0x0C,0x3C,0x00, // ]
-0x08,0x1C,0x36,0x63,0x00,0x00,0x00,0x00, // ^
-0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF, // _
-0x18,0x18,0x0C,0x00,0x00,0x00,0x00,0x00, // ` 0x60
-0x00,0x00,0x3C,0x06,0x3E,0x66,0x3B,0x00, // a
-0x70,0x30,0x3E,0x33,0x33,0x33,0x6E,0x00, // b
-0x00,0x00,0x3C,0x66,0x60,0x66,0x3C,0x00, // c
-0x0E,0x06,0x3E,0x66,0x66,0x66,0x3B,0x00, // d
-0x00,0x00,0x3C,0x66,0x7E,0x60,0x3C,0x00, // e
-0x1C,0x36,0x30,0x78,0x30,0x30,0x78,0x00, // f
-0x00,0x00,0x3B,0x66,0x66,0x3E,0x06,0x7C, // g
-0x70,0x30,0x36,0x3B,0x33,0x33,0x73,0x00, // h
-0x18,0x00,0x38,0x18,0x18,0x18,0x3C,0x00, // i
-0x06,0x00,0x06,0x06,0x06,0x66,0x66,0x3C, // j
-0x70,0x30,0x33,0x36,0x3C,0x36,0x73,0x00, // k
-0x38,0x18,0x18,0x18,0x18,0x18,0x3C,0x00, // l
-0x00,0x00,0x66,0x7F,0x7F,0x6B,0x63,0x00, // m
-0x00,0x00,0x7C,0x66,0x66,0x66,0x66,0x00, // n
-0x00,0x00,0x3C,0x66,0x66,0x66,0x3C,0x00, // o
-0x00,0x00,0x6E,0x33,0x33,0x3E,0x30,0x78, // p
-0x00,0x00,0x3B,0x66,0x66,0x3E,0x06,0x0F, // q
-0x00,0x00,0x6E,0x3B,0x33,0x30,0x78,0x00, // r
-0x00,0x00,0x3E,0x60,0x3C,0x06,0x7C,0x00, // s
-0x08,0x18,0x3E,0x18,0x18,0x1A,0x0C,0x00, // t
-0x00,0x00,0x66,0x66,0x66,0x66,0x3B,0x00, // u
-0x00,0x00,0x66,0x66,0x66,0x3C,0x18,0x00, // v
-0x00,0x00,0x63,0x6B,0x7F,0x7F,0x36,0x00, // w
-0x00,0x00,0x63,0x36,0x1C,0x36,0x63,0x00, // x
-0x00,0x00,0x66,0x66,0x66,0x3E,0x06,0x7C, // y
-0x00,0x00,0x7E,0x4C,0x18,0x32,0x7E,0x00, // z
-0x0E,0x18,0x18,0x70,0x18,0x18,0x0E,0x00, // {
-0x0C,0x0C,0x0C,0x00,0x0C,0x0C,0x0C,0x00, // |
-0x70,0x18,0x18,0x0E,0x18,0x18,0x70,0x00, // }
-0x3B,0x6E,0x00,0x00,0x00,0x00,0x00,0x00, // ~
-0x1C,0x36,0x36,0x1C,0x00,0x00,0x00,0x00}; // DEL
-    
-GraphicsDisplay::GraphicsDisplay(const char *name):TextDisplay(name) {
-    foreground(0xFFFF);
-    background(0x0000);
-}
-    
-void GraphicsDisplay::character(int column, int row, int value) { 
-    blitbit(column * 8, row * 8, 8, 8, (char*)&(FONT8x8[value - 0x1F][0]));
-}
-
-void GraphicsDisplay::window(int x, int y, int w, int h) {
-    // current pixel location
-    _x = x;
-    _y = y;
-    // window settings
-    _x1 = x;
-    _x2 = x + w - 1;
-    _y1 = y;
-    _y2 = y + h - 1;
-}
-    
-void GraphicsDisplay::putp(int colour) {
-    // put pixel at current pixel location
-    pixel(_x, _y, colour);
-    // update pixel location based on window settings
-    _x++;
-    if(_x > _x2) {
-        _x = _x1;
-        _y++;
-        if(_y > _y2) {
-            _y = _y1;
-        }
-    }
-}
-
-void GraphicsDisplay::fill(int x, int y, int w, int h, int colour) { 
-    window(x, y, w, h);
-    for(int i=0; i<w*h; i++) {
-        putp(colour);
-    }
-}
-    
-void GraphicsDisplay::cls() {
-    fill(0, 0, width(), height(), _background);
-}
-    
-void GraphicsDisplay::blit(int x, int y, int w, int h, const int *colour) { 
-    window(x, y, w, h);
-    for(int i=0; i<w*h; i++) {
-        putp(colour[i]);
-    }
-}
-    
-void GraphicsDisplay::blitbit(int x, int y, int w, int h, const char* colour) {
-    window(x, y, w, h);
-    for(int i = 0; i < w*h; i++) {
-        char byte = colour[i >> 3];
-        int offset = i & 0x7;
-        int c = ((byte << offset) & 0x80) ? _foreground : _background;
-        putp(c);
-    }
-}
-    
-int GraphicsDisplay::columns() { 
-    return width() / 8; 
-}
-
-int GraphicsDisplay::rows() { 
-    return height() / 8; 
-}
-
diff -r 1ad828c0ec83 -r 7137c60fcb06 GraphicsDisplay.h
--- a/GraphicsDisplay.h	Thu Jun 30 14:49:11 2016 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,55 +0,0 @@
-/* mbed GraphicsDisplay Display Library Base Class
- * Copyright (c) 2007-2009 sford
- * Released under the MIT License: http://mbed.org/license/mit
- *
- * A library for providing a common base class for Graphics displays
- * To port a new display, derive from this class and implement
- * the constructor (setup the display), pixel (put a pixel
- * at a location), width and height functions. Everything else
- * (locate, printf, putc, cls, window, putp, fill, blit, blitbit) 
- * will come for free. You can also provide a specialised implementation
- * of window and putp to speed up the results
- */
-
-#ifndef MBED_GRAPHICSDISPLAY_H
-#define MBED_GRAPHICSDISPLAY_H
-
-#include "TextDisplay.h"
-
-class GraphicsDisplay : public TextDisplay {
-
-public:         
-          
-    GraphicsDisplay(const char* name);
-     
-    virtual void pixel(int x, int y, int colour) = 0;
-    virtual int width() = 0;
-    virtual int height() = 0;
-        
-    virtual void window(int x, int y, int w, int h);
-    virtual void putp(int colour);
-    
-    virtual void cls();
-    virtual void fill(int x, int y, int w, int h, int colour);
-    virtual void blit(int x, int y, int w, int h, const int *colour);    
-    virtual void blitbit(int x, int y, int w, int h, const char* colour);
-    
-    virtual void character(int column, int row, int value);
-    virtual int columns();
-    virtual int rows();
-    
-protected:
-
-    // pixel location
-    short _x;
-    short _y;
-    
-    // window location
-    short _x1;
-    short _x2;
-    short _y1;
-    short _y2;
-
-};
-
-#endif
diff -r 1ad828c0ec83 -r 7137c60fcb06 TextDisplay.cpp
--- a/TextDisplay.cpp	Thu Jun 30 14:49:11 2016 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,77 +0,0 @@
-/* mbed TextDisplay Display Library Base Class
- * Copyright (c) 2007-2009 sford
- * Released under the MIT License: http://mbed.org/license/mit
- */
- 
-#include "TextDisplay.h"
-
-TextDisplay::TextDisplay(const char *name) : Stream(name){
-    _row = 0;
-    _column = 0;
-    if (name == NULL) {
-        _path = NULL;
-    } else {
-        _path = new char[strlen(name) + 2];
-        sprintf(_path, "/%s", name);
-    }
-}
-    
-int TextDisplay::_putc(int value) {
-    if(value == '\n') {
-        _column = 0;
-        _row++;
-        if(_row >= rows()) {
-            _row = 0;
-        }
-    } else {
-        character(_column, _row, value);
-        _column++;
-        if(_column >= columns()) {
-            _column = 0;
-            _row++;
-            if(_row >= rows()) {
-                _row = 0;
-            }
-        }
-    }
-    return value;
-}
-
-// crude cls implementation, should generally be overwritten in derived class
-void TextDisplay::cls() {
-    locate(0, 0);
-    for(int i=0; i<columns()*rows(); i++) {
-        putc(' ');
-    }
-}
-
-void TextDisplay::locate(int column, int row) {
-    _column = column;
-    _row = row;
-}
-
-int TextDisplay::_getc() {
-    return -1;
-}
-        
-void TextDisplay::foreground(uint16_t colour) {
-    _foreground = colour;
-}
-
-void TextDisplay::background(uint16_t colour) {
-    _background = colour;
-}
-
-bool TextDisplay::claim (FILE *stream) {
-    if ( _path == NULL) {
-        fprintf(stderr, "claim requires a name to be given in the instantioator of the TextDisplay instance!\r\n");
-        return false;
-    }
-    if (freopen(_path, "w", stream) == NULL) {
-        // Failed, should not happen
-        return false;
-    }
-    // make sure we use line buffering
-    setvbuf(stdout, NULL, _IOLBF, columns());
-    return true;
-} 
diff -r 1ad828c0ec83 -r 7137c60fcb06 TextDisplay.h
--- a/TextDisplay.h	Thu Jun 30 14:49:11 2016 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,80 +0,0 @@
-/* mbed TextDisplay Library Base Class
- * Copyright (c) 2007-2009 sford
- * Released under the MIT License: http://mbed.org/license/mit
- *
- * A common base class for Text displays
- * To port a new display, derive from this class and implement
- * the constructor (setup the display), character (put a character
- * at a location), rows and columns (number of rows/cols) functions.
- * Everything else (locate, printf, putc, cls) will come for free
- *
- * The model is the display will wrap at the right and bottom, so you can
- * keep writing and will always get valid characters. The location is 
- * maintained internally to the class to make this easy
- */
-
-#ifndef MBED_TEXTDISPLAY_H
-#define MBED_TEXTDISPLAY_H
-
-#include "mbed.h"
-
-class TextDisplay : public Stream {
-public:
-
-  // functions needing implementation in derived implementation class
-  /** Create a TextDisplay interface
-     *
-     * @param name The name used in the path to access the strean through the filesystem
-     */
-    TextDisplay(const char *name = NULL);
-
-    /** output a character at the given position
-     *
-     * @param column column where charater must be written
-     * @param  row where character must be written
-     * @param c the character to be written to the TextDisplay
-     */
-    virtual void character(int column, int row, int c) = 0;
-
-    /** return number if rows on TextDisplay
-     * @result number of rows
-     */
-    virtual int rows() = 0;
-
-    /** return number if columns on TextDisplay
-    * @result number of rows
-    */
-    virtual int columns() = 0;
-    
-    // functions that come for free, but can be overwritten
-
-    /** redirect output from a stream (stoud, sterr) to  display
-    * @param stream stream that shall be redirected to the TextDisplay
-    */
-    virtual bool claim (FILE *stream);
-
-    /** clear screen
-    */
-    virtual void cls();
-    virtual void locate(int column, int row);
-    virtual void foreground(uint16_t colour);
-    virtual void background(uint16_t colour);
-    // putc (from Stream)
-    // printf (from Stream)
-    
-protected:
-
-    virtual int _putc(int value);
-    virtual int _getc();
-
-    // character location
-    uint16_t _column;
-    uint16_t _row;
-
-    // colours
-    uint16_t _foreground;
-    uint16_t _background;
-    char *_path;
-};
-
-#endif
diff -r 1ad828c0ec83 -r 7137c60fcb06 YconP020.cpp
--- a/YconP020.cpp	Thu Jun 30 14:49:11 2016 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,430 +0,0 @@
-#include "mbed.h"
-#include "YconP020.h"
-#ifdef TARGET_LPC11U35_501
-#include "DirHandle.h" //トラ技ARMライタでは何故かこれが必要
-#endif
-#include <cctype>
-
-YconP020::YconP020(PinName tx, PinName rx) : uart(tx,rx), use_recinbuf(false)
-{
-    uart.baud(115200);
-    uart.attach(this,&YconP020::uartint);
-}
-
-bool YconP020::wait_command_ready(int ms)
-{
-    for(int i=0; i<ms; i++) {
-        if(command_ready()) return true;
-        wait_ms(1);
-    }
-    return false; //timeout
-}
-bool YconP020::command_mode()
-{
-    for(int i=0; i<10; i++) {
-        if(command_ready()) return true;
-        uart.putc('\r');
-        wait_ms(300);
-        if(command_ready()) return true;
-        wait_ms(200);
-        for(int i=0; i<3; i++) {
-            uart.putc('+');
-            wait_ms(200);
-        }
-        wait(1);
-    }
-    return false; //timeout
-}
-
-void YconP020::stop_demo()
-{
-    use_recinbuf=true;
-    uart.putc(0x1a);
-    wait_command_ready();
-    use_recinbuf=false;
-    recinbuf.clear();
-}
-
-
-const vector<string>& YconP020::getfilelist(const vector<string>& dirs)
-{
-    filelist.clear();
-    for(vector<string>::const_iterator p=dirs.begin(); p<dirs.end(); p++) {
-        string dn;
-        if((*p)[0]!='/') dn='/';
-        dn += *p;
-        DIR *dir = opendir(dn.c_str());
-        if(dir==NULL) {
-            filelist.push_back("ERROR: filesystem "+ *p +" can't open");
-            return filelist;
-        }
-        string filename;
-        struct dirent *file;
-        while((file=readdir(dir))!=NULL) {
-            filename=file->d_name;
-            if(filename.size()<4) continue;
-            string extstr(4,' ');
-            transform(filename.end()-4, filename.end(), extstr.begin(), toupper);
-            if(extstr==".BMP") {
-                filelist.push_back('/'+ *p +'/'+filename);
-            }
-        }
-        closedir(dir);
-    }
-    return filelist;
-}
-const vector<string>& YconP020::getfilelist(const string& dir)
-{
-    vector<string> fslist;
-    fslist.push_back(dir);
-    return getfilelist(fslist);
-}
-const vector<string>& YconP020::getfilelistall()
-{
-    vector<string> fslist;
-    DIR *root = opendir("/");
-    if(root==NULL) {
-        filelist.clear();
-        filelist.push_back("ERROR: any filesystem not found");
-        return filelist;
-    }
-    struct dirent *file;
-    while((file=readdir(root))!=NULL) {
-        fslist.push_back(file->d_name);
-    }
-    closedir(root);
-    return getfilelist(fslist);
-}
-
-YconP020::error_t YconP020::dispfile(const string& filename)
-{
-    use_recinbuf=true;
-    command_mode();
-    uart.puts("exit\r");
-    while(lastchar!='>') wait_ms(1);
-    lastchar='\0';
-    error_t r=sendfile(filename);
-    if(r==NOERROR) while(lastchar!='>') wait_ms(1);
-    command_mode();
-    use_recinbuf=false;
-    recinbuf.clear();
-    return r;
-}
-void YconP020::dispstoredpict(int picnum)
-{
-    use_recinbuf=true;
-    command_mode();
-    uart.printf("D %d\r", picnum);
-    wait_command_ready();
-    use_recinbuf=false;
-    recinbuf.clear();
-}
-YconP020::error_t YconP020::storepictfile(const string& filename, const int picnum)
-{
-    if(picnum>6 || picnum<0) return REGINDEXERR;
-    use_recinbuf=true;
-    command_mode();
-    uart.printf("R %d\r", picnum);
-    wait_ms(500);
-    error_t r=sendfile(filename);
-    wait_command_ready();
-    use_recinbuf=false;
-    recinbuf.clear();
-    return r;
-}
-
-const size_t BMPHEADERSIZE = 62;
-const int8_t BMPHEADER[BMPHEADERSIZE]
-    = {0x42, 0x4d, 0xbd, 0x0a, 0x00, 0x00, 0x00, 0x00,
-       0x00, 0x00, 0x3e, 0x00, 0x00, 0x00, 0x28, 0x00,
-       0x00, 0x00, 0xc8, 0x00, 0x00, 0x00, 0x60, 0x00,
-       0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00,
-       0x00, 0x00, 0x80, 0x0a, 0x00, 0x00, 0x00, 0x00,
-       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-       0x00, 0x00, 0xff, 0xff, 0xff, 0x00};
-void YconP020::display_internalbuf()
-{
-    use_recinbuf=true;
-    command_mode();
-    uart.puts("exit\r");
-    while(lastchar!='>') wait_ms(1);
-    lastchar='\0';
-    for(size_t i=0; i<BMPHEADERSIZE; i++) {
-        uart.putc(BMPHEADER[i]);
-    }
-    for(size_t y=0; y<internalbuf.height(); y++) {
-        for(size_t x=0; x<internalbuf.width()/8; x++) uart.putc(internalbuf.get8(x,y));
-        uart.putc(0x00);
-        uart.putc(0x00);
-        uart.putc(0x00);
-    }
-    while(lastchar!='>') wait_ms(1);
-    command_mode();
-    use_recinbuf=false;
-    recinbuf.clear();
-}
-//protected:       
-void YconP020::uartint()
-{
-    if(uart.readable()) {
-        lastchar = uart.getc();
-        push_recbuf(lastchar);
-    }
-}
-void YconP020::push_recbuf(char c)
-{
-    if(use_recinbuf) {
-        recinbuf += c;
-        return;
-    }
-    __disable_irq();
-    if(recoutbuf.size()>MAXRECBUFSIZE) recoutbuf.pop();
-    recoutbuf.push(c);
-    __enable_irq();
-}
-void YconP020::push_recbuf(const string& s)
-{
-    for_each(s.begin(),s.end(),bind1st(
-        mem_fun<void,YconP020,char>(&YconP020::push_recbuf), this));
-}
-    
-YconP020::error_t YconP020::sendfile(const string& filename) {
-        FILE *fp=fopen(filename.c_str(),"r");
-        if(fp==NULL) return FILEOPENERR;
-        int c;
-        while((c=fgetc(fp)) != EOF) {
-            uart.putc(c);
-        }
-        fclose(fp);
-        return NOERROR;
-    }
-
-int YconP020::putc_intercept(int c)
-{
-    if(localcomline.size()) {
-        push_recbuf(c);
-        if(c!='\r') {
-            if(c=='\b') localcomline.resize(localcomline.size()-1);
-            else localcomline += c;
-            return c;
-        }
-        push_recbuf('\n');
-        switch(toupper(localcomline[0])) {
-            case 'D':
-                if(commandline_D(localcomline)) {
-                    localcomline.clear();
-                    push_recbuf('!');
-                    lastchar='!';
-                    return c;
-                }
-                break;
-            case 'L':
-                if(commandline_L(localcomline)) {
-                    localcomline.clear();
-                    push_recbuf('!');
-                    lastchar='!';
-                    return c;
-                }
-                break;
-            case 'T':
-                if(localcomline.size()>2 && localcomline[1]==' ') {
-                    for(string::const_iterator p=localcomline.begin()+2; p<localcomline.end(); p++) {
-                        switch(*p) {
-                        case '\\':
-                            if(++p==localcomline.end()) break;
-                            if(*p=='n') {
-                                text().putc('\n');
-                            } else if(*p=='\\') {
-                                text().putc('\\');
-                            }
-                            break;    
-                        default:
-                            text().putc(*p);
-                        }
-                    }
-                    localcomline.clear();
-                    push_recbuf('!');
-                    lastchar='!';
-                    return c;
-                }
-                break;
-            case 'W':
-                if(localcomline.size()>=2 && toupper(localcomline[1])=='I') {
-                    clear_internalbuf();
-                    text().locate(0,0);
-                    localcomline.clear();
-                    push_recbuf('!');
-                    lastchar='!';
-                    return c;
-                }
-                break;
-        }
-        uart.puts(localcomline.c_str());
-        uart.putc('\r');
-        localcomline.clear();
-        return c;
-    }
-    if(lastchar=='!' && c!='\r') {
-        lastchar=' ';
-        push_recbuf(c);
-        localcomline=c;
-    } else {
-        uart.putc(c);
-    }
-    return c;
-}
-bool skipspace(string::const_iterator &p, string::const_iterator end)
-{
-    while(*++p==' ') {
-        if(p==end) return false;
-    }
-    return true;
-}
-bool YconP020::commandline_D(const string &comline)
-{
-    string::const_iterator cp=comline.begin();
-    if(!skipspace(cp, comline.end())) return false;
-    switch(toupper(*cp)) {
-    case 'F':
-        if(*++cp==' ') {
-            while(*++cp==' ') {
-                if(cp==comline.end()) break;
-            }
-            if(cp<comline.end()) {
-                const string fn=comline.substr(cp-comline.begin());
-                if(dispfile(fn)!=NOERROR) push_recbuf("\r\n"+fn+" not found\r\n!");
-            }
-        } else {
-            const string fns=comline.substr(cp-comline.begin());
-            int fn=atoi(fns.c_str());
-            if(filelist.size()<fn || fn<0) push_recbuf("\r\nfile No."+fns+" not found\r\n!");
-            else dispfile(filelist[fn]);
-        }
-        return true;
-    case 'I':
-        display_internalbuf();
-        return true;
-    default:
-        return false;
-    }
-}
-bool YconP020::commandline_L(const string &comline)
-{
-    string::const_iterator cp=comline.begin();
-    if(toupper(*++cp)=='S') {
-        skipspace(cp,comline.end());
-        if(cp==comline.end()) {
-            //getfilelist();
-        } else if(*cp=='*') {
-            getfilelistall();
-        } else {
-            getfilelist(comline.substr(cp-comline.begin()));
-        }
-        for(vector<string>::const_iterator p=filelist.begin(); p<filelist.end(); p++) {
-            /* ostringstream を使うとメモリ(RAM)使用量が跳ね上がっちゃう
-            ostringstream s;
-            s << p-filelist.begin() <<": " << *p << "\r\n";
-            outputstr(s.str());
-            */
-            char buf[4];
-            sprintf(buf,"%3d",p-filelist.begin());
-            push_recbuf(string(buf)+": "+(*p)+"\r\n");
-        }
-        return true;
-    }
-    return false;
-}
-
-//sub-functions for execute commands
-void YconP020::void_command(const string& command, bool waitready)
-{
-    use_recinbuf=true;
-    command_mode();
-    lastchar=' ';
-    uart.puts(command.c_str());
-    uart.putc('\r');
-    if(waitready) wait_command_ready();
-    use_recinbuf=false;
-    recinbuf.clear();
-    push_recbuf('!');
-}
-void YconP020::set_intparam(const string& command, int param)
-{
-    use_recinbuf=true;
-    command_mode();
-    lastchar=' ';
-    uart.printf("%s %4d\r", command.c_str(), param);
-    wait_command_ready();
-    use_recinbuf=false;
-    recinbuf.clear();
-    push_recbuf('!');
-}
-int YconP020::get_intparam(const string& command, const string& retstr)
-{
-    int retval;
-    use_recinbuf=true;
-    command_mode();
-    lastchar=' ';
-    uart.puts(command.c_str());
-    uart.putc('\r');
-    wait_ms(100);
-    size_t i=recinbuf.find(retstr);
-    retval = atoi(recinbuf.substr(i+retstr.size()+1).c_str());
-    wait_command_ready();
-    use_recinbuf=false;
-    recinbuf.clear();
-    push_recbuf('!');
-    return retval;
-}
-bool YconP020::get_boolparam(const string& command)
-{
-    bool retval=false;
-    use_recinbuf=true;
-    command_mode();
-    lastchar=' ';
-    uart.puts(command.c_str());
-    uart.putc('\r');
-    wait_ms(100);
-    if(recinbuf.find("Enable")!=string::npos) retval=true;
-    wait_command_ready();
-    use_recinbuf=false;
-    recinbuf.clear();
-    push_recbuf('!');
-    return retval;
-}
-string YconP020::get_stringparam(const string& command)
-{
-    use_recinbuf=true;
-    command_mode();
-    lastchar=' ';
-    uart.puts(command.c_str());
-    uart.putc('\r');
-    wait_command_ready();
-    use_recinbuf=false;
-    string retval;
-    string::const_iterator p=recinbuf.begin()+recinbuf.find(command)+command.size();
-    while(p<recinbuf.end()) {
-        if(*p=='!') break;
-        retval += *p++;
-    }
-    recinbuf.clear();
-    push_recbuf('!');
-    return retval;
-}
-
-//private:
-int YconP020::_getc()
-{
-    while(recoutbuf.empty()) {}
-    __disable_irq();
-    int c=recoutbuf.front();
-    recoutbuf.pop();
-    __enable_irq();
-    return c;
-}
-int YconP020::_putc(int c)
-{
-    putc_intercept(c);
-    return c;
-}
diff -r 1ad828c0ec83 -r 7137c60fcb06 YconP020.h
--- a/YconP020.h	Thu Jun 30 14:49:11 2016 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,140 +0,0 @@
-#ifndef YCONP020_H
-#define YCONP020_H
-
-#include "Stream.h"
-#include "Serial.h"
-using namespace mbed;
-#include <string>
-#include <vector>
-#include <queue>
-using namespace std;
-#include "GraphicsDisplay.h"
-
-class YconP020GBuf : public GraphicsDisplay {
-public:
-    enum INTERNALBUF { MAX_X=200,MAX_Y=96 };
-    YconP020GBuf(const char *name=NULL) : GraphicsDisplay(name) {
-        setpixelsize();
-    }
-    virtual void pixel(int x, int y, int b) {
-        if(x<0 || x>=MAX_X/pixelsizex || y<0 || y>=MAX_Y/pixelsizey) return;
-        for(int i=0; i<pixelsizex; i++) {
-            for(int j=0; j<pixelsizey; j++) {
-                pixel1x1(x*pixelsizex+i, y*pixelsizey+j, b);
-            }
-        }
-    }
-    void pixel1x1(int x, int y, int b) {
-        if(x<0 || x>=MAX_X || y<0 || y>=MAX_Y) return;
-        if(!b) buffer[MAX_Y-1-y][x/8] |= 1<<(7-(x%8));
-        else buffer[MAX_Y-1-y][x/8] &= ~(1<<(7-(x%8)));
-    }
-    void setpixelsize(int x=1, int y=1) {
-        pixelsizex=x;
-        pixelsizey=y;
-    }
-    virtual int width() {return MAX_X;}
-    virtual int height() {return MAX_Y;}
-    int8_t get8(size_t x,size_t y) {return buffer[y][x];}
-private:
-    int8_t buffer[MAX_Y][MAX_X/8];
-    int pixelsizex;
-    int pixelsizey;
-};
-
-class YconP020 : public Stream {
-static const size_t MAXRECBUFSIZE=1000;
-public:
-    typedef enum {
-        NOERROR=0,FILEOPENERR=1,REGINDEXERR=2,FILENOTEXIST=3,DIROPENERR=4
-    } error_t;
-
-    YconP020(PinName tx, PinName rx);
- 
-    /// Similar to Serial::readable()
-    bool readable() {return !recoutbuf.empty();}
-    /// check ready to send command
-    bool command_ready() const { return lastchar=='!'; }
-    /// wait for ready to send command
-    /// @return false timeout
-    bool wait_command_ready(int ms=10000);
-    /// change to command mode from normal(send file) mode
-    /// @return flase timeout
-    bool command_mode();
-
-    //commands
-    string help_str() {return get_stringparam("?");} // (1)?
-    void clear_screen(bool white=true) {void_command(white? "W":"B");} //(2)W, (3)B
-    void negative_screen() {void_command("N");} //(4)N
-    void dispstoredpict(int picnum); //(5)D
-    error_t storepictfile(const string& filename, const int picnum); //(6)R
-    string infomation_str() {return get_stringparam("I");}//(7)I
-    void start_demo() {void_command("DEMO",false);} //(8)DEMO    
-    void stop_demo();
-    int get_interval() {return get_intparam("INTERVAL","Interval");} //(9)INTERVAL
-    void set_interval(int t) {set_intparam("INTERVAL", t);}
-    //(10)LASTWAIT
-    int get_lastwait() {return get_intparam("LASTWAIT","Wait");}
-    void set_lastwait(int t) {return set_intparam("LASTWAIT", t);}
-    //(11)STANDBY
-    bool get_standby() {return get_boolparam("STANDBY");}
-    void set_standby(bool f) {return set_intparam("STANDBY", f);}
-    //(12)LED
-    bool get_led() {return get_boolparam("LED");}
-    void set_led(bool f) {return set_intparam("LED", f);}
-    //(13)P37
-    int get_p37() {return get_boolparam("P37");}
-    void set_p37(bool f) {return set_intparam("P37", f);}
-    void exit_commandmode() {void_command("EXIT",false);} //(14)EXIT
-    void reset_screen() {void_command("RESET",false);} //(15)RESET
-    string yslab_info() {return get_stringparam("YSLAB");} //(16)YSLAB
-        
-    /// get file list of directories
-    const vector<string>& getfilelist(const vector<string>& dirs);
-    /// get file list of directory
-    const vector<string>& getfilelist(const string& dir);
-    /// return previous file list
-    const vector<string>& getfilelist() const {return filelist;}
-    /// get all file list
-    const vector<string>& getfilelistall();
-    /// display file
-    error_t dispfile(const string& filename);
-
-    YconP020GBuf& text() {return internalbuf;}
-    void pset(int x, int y, bool b=true) {internalbuf.pixel(x,y,b);}
-    void clear_internalbuf(int8_t data=0) { internalbuf.cls(); }
-    void display_internalbuf();
-protected:       
-    void uartint();
-    void push_recbuf(char c);
-    void push_recbuf(const string& s);
-    
-    error_t sendfile(const string& filename);
-
-    //for command line intercept
-    int putc_intercept(int c);
-    bool commandline_D(const string &comline);
-    bool commandline_L(const string &comline);
-
-    //sub-functions for execute commands
-    void void_command(const string& command, bool waitready=true);
-    void set_intparam(const string& command, int param);
-    int get_intparam(const string& command, const string& retstr);
-    bool get_boolparam(const string& command);
-    string get_stringparam(const string& command);
-        
-private:
-    Serial uart;
-    volatile char lastchar;
-    queue<char> recoutbuf;
-    string recinbuf;
-    bool use_recinbuf;
-    vector<string> filelist;
-    string localcomline;
-    YconP020GBuf internalbuf;
-
-    virtual int _getc();
-    virtual int _putc(int c);
-};
-
-#endif
\ No newline at end of file
diff -r 1ad828c0ec83 -r 7137c60fcb06 YconP020.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/YconP020.lib	Sun Jul 03 10:43:26 2016 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/users/jk1lot/code/YconP020/#a7e6ebc4cb72
diff -r 1ad828c0ec83 -r 7137c60fcb06 main.cpp
--- a/main.cpp	Thu Jun 30 14:49:11 2016 +0000
+++ b/main.cpp	Sun Jul 03 10:43:26 2016 +0000
@@ -5,8 +5,13 @@
 #include <vector>
 #include <queue>
 
-//トラ技ARMライタではPCとの通信でUSBシリアルを使うにはUSBDeviceライブラリが必要
+//このプログラムは YconP020ライブラリの使い方の例も含んでいます。
+//使用例を取り除いて純粋に「USB-UART変換器+コマンド拡張」として
+//使う場合は以下の #define を 0 に設定してください。
+#define SAMPLECODE 1
+
 #ifdef TARGET_LPC11U35_501
+//トラ技ARMライタではPCとの通信にUSBシリアルを使うにはUSBDeviceライブラリが必要
 #include "USBSerial.h"
 USBSerial pc;
 #define USE_USBSerial
@@ -22,12 +27,6 @@
 YconP020 epd(p9, p10);
 
 DigitalOut ledcommode(LED1);
-//トラ技ARMライタのボード上LEDは0で点灯
-inline bool ledon(bool b) {return 
-#ifdef TARGET_LPC11U35_501
-!
-#endif
-b;}
 
 queue<char> pcrecbuf;
 void pcint() {
@@ -47,33 +46,48 @@
     pc.baud(115200);
 #endif
     pc.attach(pcint);
-    pc.printf("\r\nY-Con P020 Extend mode by mbed\r\n");
-    //epd.command_mode(); //コメントを外すと PowerON でコマンドモード
+    pc.puts("\r\nY-Con P020 Extend mode by mbed\r\n");
+#if SAMPLECODE == 1
     //こんな使い方も出来ますよという例
-    //epd.printf("d %d\r", 3);
-    //epdtopc();
-    //epd.wait_command_ready();
-
+    //例1 epd.printf()でコマンドを実行する
+    epd.command_mode();
+    epd.printf("d %d\r", 3);
+    epdtopc();
+    epd.wait_command_ready();
+    wait(2);
+    //例2 メンバ関数でコマンドを実行する
     pc.printf("%s", epd.yslab_info().c_str());
-    //epd.yslab_info();
-
-    epd.text().cls();
-    epd.text().setpixelsize(2,3);
-    epd.text().printf("Hello World\nYconP020\n");
-    epd.text().setpixelsize();
+    //例3 epd.text() を使って文字を表示する
+    epd.text()->cls();
+    epd.setfontscale(2,3);
+    epd.text()->puts("Hello World\n");
+    epd.setfontscale(1,2);
+    epd.text()->puts("YconP020 ");
+    epd.setfontscale(1,3);
+    epd.text()->printf("LED: %d ", epd.command_led());
+    epd.command_led(false);
+    epd.text()->printf("%d ", epd.command_led());
+    epd.command_led(!epd.command_led());
+    epd.text()->printf("%d\n", epd.command_led());
+    epd.command_interval(2560);
+    epd.text()->printf("Interval=%d\n",epd.command_interval());
+    epd.command_interval(3000);
     epd.display_internalbuf();
     wait(3);
-    epd.clear_internalbuf();    
-    for(int x=0; x<YconP020GBuf::MAX_X; x++) {
-        epd.pset(x,(sin(2*3.14/200*x)+1)*YconP020GBuf::MAX_Y/2);
-        epd.pset(x,YconP020GBuf::MAX_Y/2);
+    //例4 epd.pset() でグラフィック表示
+    epd.clear_internalbuf();
+    for(int x=0; x<epd.width(); x++) {
+        epd.pset(x,(sin(2*3.14/200*x)+1)*epd.height()/2);
+        epd.pset(x,epd.height()/2);
     }
-    epd.text().locate(0,0);
-    epd.text().puts("Display Graphics\nand Text at\nthe same time\n");
     epd.display_internalbuf();
-    
+    wait(1);
+    //例5 グラフィックをクリアせずに重ねて文字表示
+    epd.text()->puts("Display Graphics\nand Text at\nthe same time\n");
+    epd.display_internalbuf();
+#endif //SAMPLECODE==1
     while(1) {
-        ledcommode = ledon(epd.command_ready());
+        ledcommode = epd.command_ready();
         __disable_irq();
         while(!pcrecbuf.empty() && !pc.readable()) {
             char c=pcrecbuf.front();