Come from standard seeed epaper, but adding SPI signal in construtor
Fork of seeedstudio-epaper by
Revision 2:c5bb7d34974d, committed 2015-11-13
- Comitter:
- thierryc49
- Date:
- Fri Nov 13 20:46:53 2015 +0000
- Parent:
- 1:2f62e2b80305
- Commit message:
- lib from seedstudio-epaper, Add SPI in parameter's constructor
Changed in this revision
diff -r 2f62e2b80305 -r c5bb7d34974d EPD.cpp --- a/EPD.cpp Fri Jul 18 09:20:24 2014 +0000 +++ b/EPD.cpp Fri Nov 13 20:46:53 2015 +0000 @@ -26,23 +26,24 @@ #define CU8(...) (ARRAY(const uint8_t, __VA_ARGS__)) Timer timer; -SPI spi(p20, p22, p25); -static void SPI_put(uint8_t c); -static void SPI_put_wait(uint8_t c, DigitalIn busy_pin); -static void SPI_send(DigitalOut cs_pin, const uint8_t *buffer, uint16_t length); -static void SPI_on(); +//thierry +//--origine SPI spi(p20, p22, p25); +//SPI spi(P0_25,P0_28,P0_29); -EPD_Class::EPD_Class(PinName Pin_EPD_CS, PinName Pin_PANEL_ON, PinName Pin_BORDER, PinName Pin_DISCHARGE, PinName Pin_PWM, PinName Pin_RESET, PinName Pin_BUSY) : + +EPD_Class::EPD_Class(PinName Pin_EPD_CS, PinName Pin_PANEL_ON, PinName Pin_BORDER, PinName Pin_DISCHARGE, PinName Pin_PWM, PinName Pin_RESET, PinName Pin_BUSY,PinName Pin_MOSI,PinName Pin_MISO,PinName Pin_CLK) : EPD_Pin_EPD_CS(Pin_EPD_CS), EPD_Pin_PANEL_ON(Pin_PANEL_ON), EPD_Pin_BORDER(Pin_BORDER), EPD_Pin_DISCHARGE(Pin_DISCHARGE), EPD_Pin_PWM(Pin_PWM), EPD_Pin_RESET(Pin_RESET), - EPD_Pin_BUSY(Pin_BUSY) { - + EPD_Pin_BUSY(Pin_BUSY), + spi (Pin_MOSI,Pin_MISO,Pin_CLK) + { + } void EPD_Class::begin(EPD_size sz) @@ -537,17 +538,17 @@ SPI_send(this->EPD_Pin_EPD_CS, CU8(0x72, 0x2f), 2); } -static void SPI_on() { +void EPD_Class::SPI_on() { wait_us(10); } -static void SPI_put(uint8_t c) { +void EPD_Class::SPI_put(uint8_t c) { spi.write(c); } -static void SPI_put_wait(uint8_t c, DigitalIn busy_pin) { +void EPD_Class::SPI_put_wait(uint8_t c, DigitalIn busy_pin) { SPI_put(c); @@ -557,7 +558,7 @@ } -static void SPI_send(DigitalOut cs_pin, const uint8_t *buffer, uint16_t length) { +void EPD_Class::SPI_send(DigitalOut cs_pin, const uint8_t *buffer, uint16_t length) { // CS low cs_pin = 0;
diff -r 2f62e2b80305 -r c5bb7d34974d EPD.h --- a/EPD.h Fri Jul 18 09:20:24 2014 +0000 +++ b/EPD.h Fri Nov 13 20:46:53 2015 +0000 @@ -47,7 +47,7 @@ PwmOut EPD_Pin_PWM; DigitalOut EPD_Pin_RESET; DigitalIn EPD_Pin_BUSY; - + SPI spi; EPD_size size; uint16_t stage_time; @@ -62,11 +62,17 @@ bool filler; + void SPI_put(uint8_t c); + void SPI_put_wait(uint8_t c, DigitalIn busy_pin); + void SPI_send(DigitalOut cs_pin, const uint8_t *buffer, uint16_t length); + void SPI_on(); + public: unsigned char lineDta[33]; public: EPD_Class(PinName Pin_EPD_CS, PinName Pin_PANEL_ON, PinName Pin_BORDER, PinName Pin_DISCHARGE, PinName Pin_PWM, PinName Pin_RESET, PinName Pin_BUSY); + EPD_Class(PinName Pin_EPD_CS, PinName Pin_PANEL_ON, PinName Pin_BORDER, PinName Pin_DISCHARGE, PinName Pin_PWM, PinName Pin_RESET, PinName Pin_BUSY,PinName Pin_MOSI,PinName Pin_MISO,PinName Pin_CLK); // power up and power down the EPD panel void begin(EPD_size sz); void start();
diff -r 2f62e2b80305 -r c5bb7d34974d TextDisplay.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TextDisplay.cpp Fri Nov 13 20:46:53 2015 +0000 @@ -0,0 +1,77 @@ +/* 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 2f62e2b80305 -r c5bb7d34974d TextDisplay.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TextDisplay.h Fri Nov 13 20:46:53 2015 +0000 @@ -0,0 +1,80 @@ +/* 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