Base LCDPanel based, required for all LCDPanel drivers
Revision 2:ab4040a7e8c9, committed 2012-03-11
- Comitter:
- silviogissi
- Date:
- Sun Mar 11 01:33:10 2012 +0000
- Parent:
- 1:073d4f161f23
- Commit message:
Changed in this revision
diff -r 073d4f161f23 -r ab4040a7e8c9 LCDPanel.cpp --- a/LCDPanel.cpp Fri Mar 09 01:49:18 2012 +0000 +++ b/LCDPanel.cpp Sun Mar 11 01:33:10 2012 +0000 @@ -1,8 +1,6 @@ -/* -Placeholder for Copyright notice, etc +/* LCDPanel base library for LCD/TFT Panels + * Copyright (c) 2012, Silvio Gissi */ -Author: silviogissi -*/ #include "LCDPanel.h" LCDPanel::LCDPanel(unsigned int width, unsigned int height, PinName cs) @@ -13,16 +11,16 @@ } // Default implementation, pixel by pixel -void LCDPanel::fill(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2, unsigned int color) { - CsTransaction(this); +void LCDPanel::fill(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2, uint16_t color) { if (x1>x2) {unsigned int tmp=x1; x1=x2; x2=tmp;} if (y1>y2) {unsigned int tmp=y1; y1=y2; y2=tmp;} + CsTransaction(this); window(x1,y1,x2,y2); for(unsigned int i=0;i<(x2-x1)*(y2-y1);i++) { pixel(color); } } // Default implementation, pixel by pixel -void LCDPanel::fill(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2, const unsigned int* color) { +void LCDPanel::fill(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2, const uint16_t* color) { if (x1>x2) {unsigned int tmp=x1; x1=x2; x2=tmp;} if (y1>y2) {unsigned int tmp=y1; y1=y2; y2=tmp;} CsTransaction(this); @@ -30,7 +28,7 @@ for(unsigned int i=0;i<(x2-x1)*(y2-y1);i++) { pixel(color[i]); } } -void LCDPanel::set_pixel(unsigned int x, unsigned int y, unsigned int color) { +void LCDPanel::set_pixel(unsigned int x, unsigned int y, uint16_t color) { CsTransaction(this); window(x,y,1,1); pixel(color);
diff -r 073d4f161f23 -r ab4040a7e8c9 LCDPanel.h --- a/LCDPanel.h Fri Mar 09 01:49:18 2012 +0000 +++ b/LCDPanel.h Sun Mar 11 01:33:10 2012 +0000 @@ -1,7 +1,29 @@ -/* -Placeholder for Copyright notice, etc - -Author: silviogissi +/* LCDPanel base library for LCD/TFT Panels + * Copyright (c) 2012, Silvio Gissi + * + * License: + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * Author: Silvio Gissi + * Version: 0.1 Alfa + * */ #ifndef LCDPANEL_BASE_H @@ -14,10 +36,11 @@ public: LCDPanel(unsigned int width, unsigned int height, PinName cs); - virtual void fill(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2, unsigned int color); - virtual void fill(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2, const unsigned int* color); - virtual void set_pixel(unsigned int x, unsigned int y, unsigned int color); + virtual void fill(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2, uint16_t color); + virtual void fill(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2, const uint16_t* color); + virtual void set_pixel(unsigned int x, unsigned int y, uint16_t color); + inline void clear() { fill(0,0,_xmax,_ymax,(uint16_t)0x0000); } inline unsigned int height() { return _ymax+1; } inline unsigned int width() { return _xmax+1; } @@ -33,8 +56,9 @@ CsTransaction(LCDPanel *panel) : p(panel) { p->_cs=0; } ~CsTransaction() { p->_cs=1; } }; - - virtual void pixel(unsigned int color)=0; + virtual void command(unsigned int command,unsigned int size=0,...)=0; + virtual void data(unsigned int size,...)=0; + virtual void pixel(uint16_t color)=0; virtual void window(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2)=0; };
diff -r 073d4f161f23 -r ab4040a7e8c9 LCDPanel_SPI.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LCDPanel_SPI.cpp Sun Mar 11 01:33:10 2012 +0000 @@ -0,0 +1,36 @@ +/* LCDPanel base library for LCD/TFT Panels + * Copyright (c) 2012, Silvio Gissi */ + +#include "LCDPanel_SPI.h" +#include "stdarg.h" + +LCDPanel_SPI::LCDPanel_SPI(unsigned int width, unsigned int height, PinName cs, + PinName spi_data, PinName spi_clock, PinName rst, + unsigned int spi_bits, unsigned int spi_freq + ) : LCDPanel (width,height,cs), _rst(rst), _spi(spi_data,NC,spi_clock) + { + _spi.format(spi_bits); + _spi.frequency(spi_freq); + } + +void LCDPanel_SPI::command(unsigned int command, unsigned int size, ...) { + _spi.write(command&0xFF); + if (size) { + va_list m; + va_start (m,size); + this->data(size,m); + va_end(m); + } + +} + +void LCDPanel_SPI::data(unsigned int size, ...) { + va_list m; + va_start (m,size); + for(int i=0; i<size; i++) { _spi.write(va_arg(m,int)|0x100); } + va_end(m); +} + +void LCDPanel_SPI::pixel(uint16_t color) { + this->data(2,color>>8,color&0xff); +}
diff -r 073d4f161f23 -r ab4040a7e8c9 LCDPanel_SPI.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LCDPanel_SPI.h Sun Mar 11 01:33:10 2012 +0000 @@ -0,0 +1,62 @@ +/* LCDPanel SPI base library for LCD/TFT Panels + * Copyright (c) 2012, Silvio Gissi + * + * License: + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * Author: Silvio Gissi + * Version: 0.1 Alfa + * +*/ + +#ifndef LCDPANEL_SPI_H +#define LCDPANEL_SPI_H + +#include "mbed.h" +#include "LCDPanel.h" + +class LCDPanel_SPI : public LCDPanel { + + public: + /** LCDPanel SPI + * + * @param width LCDPanel width + * @param height LCDPanel height + * @param cs Chip Select (DigitalOut) + * @param spi_data SPI data pin (MOSI) (DigitalOut) + * @param spi_clock SPI clock pin (SCLK) (DigitalOut) + * @param rst Reset (DigitalOut) + * @param spi_bits Number of bits to be sent on each SPI write + * @param spi_freq SPI frequency + */ + LCDPanel_SPI(unsigned int width, unsigned int height, PinName cs, + PinName spi_data, PinName spi_clock, PinName rst, + unsigned int spi_bits, unsigned int spi_freq + ); + + protected: + DigitalOut _rst; + SPI _spi; + virtual void command(unsigned int command, unsigned int size=0, ...); + virtual void data(unsigned int size, ...); + virtual void pixel(uint16_t color); +}; + +#endif // LCDPANEL_SPI_H \ No newline at end of file