UniGraphic-Fork for ST7920-LCD-controller and SH1106. Tested with 128x64 LCD with SPI and 128x64-OLED with IIC
Dependents: UniGraphic-St7920-Test AfficheurUTILECO
Fork of UniGraphic by
Fork of the UniGraphic-Library for monochrome LCDs with ST7920 controller and 128x64-IIC-OLED-Display with SH1106-Controller

Had to adapt LCD for following reasons:
- Give access to screenbuffer buffer[] to parent class
- pixel() and pixel_read() as they are hardware-dependent
- added reset-pin to IIC-Interface
GraphicDisplay:: sends buffer to LCD when auto_update is set to true.
Testprogram for ST7920 can be found here:
https://developer.mbed.org/users/charly/code/UniGraphic-St7920-Test/
Revision 1:ff019d22b275, committed 2015-02-13
- Comitter:
- Geremia
- Date:
- Fri Feb 13 15:25:10 2015 +0000
- Parent:
- 0:75ec1b3cde17
- Child:
- 2:713844a55c4e
- Commit message:
- Added SPI_16, LCD done
Changed in this revision
--- a/Display/LCD.cpp Thu Feb 12 22:22:47 2015 +0000
+++ b/Display/LCD.cpp Fri Feb 13 15:25:10 2015 +0000
@@ -4,7 +4,8 @@
//#define LCDPAGES (LCDSIZE_Y>>3) // 8raws per page
//#define IC_PAGES (IC_Y_COMS>>3) // max pages in IC ddram, 8raws per page
#define SWAP(a, b) { a ^= b; b ^= a; a ^= b; }
-#define USEFRAMEBUFFER
+//#define USEFRAMEBUFFER
+#define NOPCMD 0xE300
//#define FRAMEBUFSIZE (LCDSIZE_X*LCDPAGES)
Protocols* proto;
@@ -16,46 +17,72 @@
// buffer = new unsigned char [LCDSIZE_X*LCDPAGES];
// PAR8 par8proto(port, CS, reset, DC, WR, RD);
if(displayproto==PAR_8) proto = new PAR8(port, CS, reset, DC, WR, RD);
+ useNOP=false;
buffer = (unsigned char*) malloc (LCDSIZE_X*LCDPAGES);
+ buffer16 = (unsigned short*)buffer;
draw_mode = NORMAL;
set_orientation(1);
// cls();
// locate(0,0);
}
-LCD::LCD(proto_t displayproto,PinName mosi, PinName miso, PinName sclk, PinName CS, PinName reset, PinName DC, const int lcdsize_x, const int lcdsize_y, const int ic_x_segs, const int ic_y_coms, const char *name)
+LCD::LCD(proto_t displayproto, int Hz, PinName mosi, PinName miso, PinName sclk, PinName CS, PinName reset, PinName DC, const int lcdsize_x, const int lcdsize_y, const int ic_x_segs, const int ic_y_coms, const char *name)
: GraphicsDisplay(name), LCDSIZE_X(lcdsize_x), LCDSIZE_Y(lcdsize_y), LCDPAGES(lcdsize_y>>3), IC_X_SEGS(ic_x_segs), IC_Y_COMS(ic_y_coms), IC_PAGES(ic_y_coms>>3)
{
// LCDPAGES = LCDSIZE_Y>>3;
// IC_PAGES = IC_Y_COMS>>3;
// buffer = new unsigned char [LCDSIZE_X*LCDPAGES];
// PAR8 par8proto(port, CS, reset, DC, WR, RD);
- if(displayproto==SPI_8) proto = new SPI8(mosi, miso, sclk, CS, reset, DC);
+ if(displayproto==SPI_8)
+ {
+ proto = new SPI8(Hz, mosi, miso, sclk, CS, reset, DC);
+ useNOP=false;
+ }
+ else if(displayproto==SPI_16)
+ {
+ proto = new SPI16(Hz, mosi, miso, sclk, CS, reset, DC);
+ useNOP=true;
+ }
buffer = (unsigned char*) malloc (LCDSIZE_X*LCDPAGES);
+ buffer16 = (unsigned short*)buffer;
draw_mode = NORMAL;
// cls();
set_orientation(1);
// locate(0,0);
+
}
LCD::~LCD()
{
free(buffer);
}
-void LCD::wr_cmd(unsigned char cmd)
+void LCD::wr_cmd8(unsigned char cmd)
{
- proto->wr_cmd(cmd);
+ if(useNOP) proto->wr_cmd16(NOPCMD|cmd);
+ else proto->wr_cmd8(cmd);
}
-void LCD::wr_data8(unsigned char data8)
+void LCD::wr_data8(unsigned char data)
{
- proto->wr_data8(data8);
+ proto->wr_data8(data);
+ }
+void LCD::wr_data8(unsigned char data, unsigned int count)
+ {
+ proto->wr_data8(data, count);
}
-void LCD::wr_data8(unsigned char data8, unsigned int count)
+void LCD::wr_data8buf(unsigned char* data, unsigned int lenght)
{
- proto->wr_data8(data8, count);
+ proto->wr_data8buf(data, lenght);
+ }
+void LCD::wr_cmd16(unsigned short cmd)
+ {
+ proto->wr_cmd16(cmd);
}
-void LCD::wr_data8buf(unsigned char* data8, unsigned int lenght)
+void LCD::wr_data16(unsigned short data, unsigned int count)
{
- proto->wr_data8buf(data8, lenght);
+ proto->wr_data16(data, count);
+ }
+void LCD::wr_data16buf(unsigned short* data, unsigned int lenght)
+ {
+ proto->wr_data16buf(data, lenght);
}
void LCD::hw_reset()
{
@@ -113,34 +140,34 @@
switch (mode)
{
case(NONE):
- wr_cmd(0xA0);
- wr_cmd(0xC8); // this is in real Y mirror command, but seems most displays have COMs wired inverted, so assume this is the default no-y-mirror
+ // wr_cmd8(0xA0);
+ wr_cmd16(0xA0C8); // this is in real Y mirror command, but seems most displays have COMs wired inverted, so assume this is the default no-y-mirror
break;
case(X):
- wr_cmd(0xA1);
- wr_cmd(0xC8);
+ // wr_cmd8(0xA1);
+ wr_cmd16(0xA1C8);
break;
case(Y):
- wr_cmd(0xA0);
- wr_cmd(0xC0);
+ // wr_cmd8(0xA0);
+ wr_cmd16(0xA0C0);
break;
case(XY):
- wr_cmd(0xA1);
- wr_cmd(0xC0);
+ // wr_cmd8(0xA1);
+ wr_cmd16(0xA1C0);
break;
}
}
void LCD::invert(unsigned char o)
{
- if(o == 0) wr_cmd(0xA6);
- else wr_cmd(0xA7);
+ if(o == 0) wr_cmd8(0xA6);
+ else wr_cmd8(0xA7);
}
void LCD::set_contrast(int o)
{
contrast = o;
- wr_cmd(0x81); // set volume
- wr_cmd(o & 0x3F);
+ // wr_cmd8(0x81); // set volume
+ wr_cmd16(0x8100|(o&0x3F));
}
void LCD::set_auto_up(bool up)
{
@@ -184,8 +211,8 @@
// if(draw_mode == NORMAL)
// {
- if(color == 0) buffer[x + ((y>>3) * LCDSIZE_X)] &= ~(1 << (y&7)); // erase pixel
- else buffer[x + ((y>>3) * LCDSIZE_X)] |= (1 << (y&7)); // set pixel
+ if(color == 0) buffer[(x + ((y>>3)*LCDSIZE_X))^1] &= ~(1 << (y&7)); // erase pixel
+ else buffer[(x + ((y>>3)*LCDSIZE_X))^1] |= (1 << (y&7)); // set pixel
// }
// else
// { // XOR mode
@@ -195,23 +222,27 @@
void LCD::copy_to_lcd(void)
{
unsigned short i=0;
+ unsigned short setcolcmd = 0x0010 | ((col_offset&0xF)<<8) | (col_offset>>4);
for(int page=0; page<LCDPAGES; page++)
{
- wr_cmd((unsigned char)col_offset&0xF); // set column low nibble
- wr_cmd(0x10|(col_offset>>4)); // set column hi nibble
- wr_cmd(0xB0|(page+page_offset)); // set page
- wr_data8buf(buffer+i, LCDSIZE_X); // send whole page pixels
- i+=LCDSIZE_X;
+ // wr_cmd8(col_offset&0xF); // set column low nibble
+ // wr_cmd8(0x10|(col_offset>>4)); // set column hi nibble
+ wr_cmd16(setcolcmd);
+ wr_cmd8(0xB0|(page+page_offset)); // set page
+ wr_data16buf(buffer16+i, LCDSIZE_X>>1); // send whole page pixels
+ i+=LCDSIZE_X>>1;
}
}
void LCD::cls(void)
{
memset(buffer,0x00,LCDSIZE_X*LCDPAGES); // clear display buffer
+ unsigned short setcolcmd = 0x0010 | ((col_offset&0xF)<<8) | (col_offset>>4);
for(int page=0; page<LCDPAGES; page++)
{
- wr_cmd((unsigned char)col_offset&0xF); // set column low nibble
- wr_cmd(0x10|(col_offset>>4)); // set column hi nibble
- wr_cmd(0xB0|(page+page_offset)); // set page
- wr_data8(0, LCDSIZE_X); // send whole page pixels =0
+ // wr_cmd8((unsigned char)col_offset&0xF); // set column low nibble
+ // wr_cmd8(0x10|(col_offset>>4)); // set column hi nibble
+ wr_cmd16(setcolcmd);
+ wr_cmd8(0xB0|(page+page_offset)); // set page
+ wr_data16(0, LCDSIZE_X>>1); // send whole page pixels =0
}
}
\ No newline at end of file
--- a/Display/LCD.h Thu Feb 12 22:22:47 2015 +0000
+++ b/Display/LCD.h Fri Feb 13 15:25:10 2015 +0000
@@ -5,11 +5,14 @@
#include "GraphicsDisplay.h"
#include "PAR8.h"
#include "SPI8.h"
+#include "SPI16.h"
#include "Protocols.h"
#define Black 1
#define White 0
+
+
/** Draw mode
* NORMAl
* XOR set pixel by xor the screen
@@ -35,7 +38,7 @@
/** Create a monochrome LCD SPI interface
* @param name The name used by the parent class to access the interface
*/
- LCD(proto_t displayproto,PinName mosi, PinName miso, PinName sclk, PinName CS, PinName reset, PinName DC, const int lcdsize_x, const int lcdsize_y, const int ic_x_segs, const int ic_y_coms, const char* name);
+ LCD(proto_t displayproto, int Hz, PinName mosi, PinName miso, PinName sclk, PinName CS, PinName reset, PinName DC, const int lcdsize_x, const int lcdsize_y, const int ic_x_segs, const int ic_y_coms, const char* name);
/** Destructor
* will free framebuffer
@@ -147,31 +150,65 @@
////// functions needed by parent class ///////////////////////////////////////
////// -------------------------------- ///////////////////////////////////////
- /** Send command byte to display
- * @param cmd is the command
- */
- void wr_cmd(unsigned char cmd);
+ /** Send 8bit command to display controller
+ *
+ * @param cmd: byte to send
+ * @note if protocol is SPI16, it will insert NOP cmd before, so if cmd is a 2byte cmd, the second cmd will be broken. Use wr_cmd16 for 2bytes cmds
+ */
+ void wr_cmd8(unsigned char cmd);
- /** Send data byte to display
- * @param data8 is the byte
- */
- void wr_data8(unsigned char data8);
+ /** Send 8bit data to display controller
+ *
+ * @param data: byte to send
+ *
+ */
+ void wr_data8(unsigned char data);
- /** Send same data byte to display controller multiple times
+ /** Send same 8bit data to display controller multiple times
*
- * @param data8: byte to send
+ * @param data: byte to send
* @param count: how many
*
*/
- virtual void wr_data8(unsigned char data8, unsigned int count);
+ void wr_data8(unsigned char data, unsigned int count);
/** Send array of data bytes to display controller
*
- * @param data8: unsigned char data array
+ * @param data: unsigned char data array
* @param lenght: lenght of array
*
*/
- virtual void wr_data8buf(unsigned char* data8, unsigned int lenght);
+ void wr_data8buf(unsigned char* data, unsigned int lenght);
+
+ /** Send 16bit command to display controller
+ *
+ * @param cmd: halfword to send
+ *
+ */
+ void wr_cmd16(unsigned short cmd);
+
+ /** Send 16bit data to display controller
+ *
+ * @param data: halfword to send
+ *
+ */
+ //void wr_data16(unsigned short data);
+
+ /** Send same 16bit data to display controller multiple times
+ *
+ * @param data: halfword to send
+ * @param count: how many
+ *
+ */
+ void wr_data16(unsigned short data, unsigned int count);
+
+ /** Send array of data shorts to display controller
+ *
+ * @param data: unsigned short data array
+ * @param lenght: lenght (in shorts)
+ *
+ */
+ void wr_data16buf(unsigned short* data, unsigned int lenght);
/** HW reset sequence (without display init commands)
*/
@@ -184,6 +221,7 @@
unsigned char *buffer;
+ unsigned short *buffer16;
const int LCDSIZE_X;
const int LCDSIZE_Y;
const int LCDPAGES;
@@ -202,7 +240,7 @@
int win_y1;
int win_y2;
int orientation;
- // bool portrait;
+ bool useNOP;
};
#endif
\ No newline at end of file
--- a/Inits/IST3020.cpp Thu Feb 12 22:22:47 2015 +0000
+++ b/Inits/IST3020.cpp Fri Feb 13 15:25:10 2015 +0000
@@ -18,8 +18,8 @@
BusEnable(true);
init();
}
-IST3020::IST3020(proto_t displayproto, PinName mosi, PinName miso, PinName sclk, PinName CS, PinName reset, PinName DC, const char *name)
- : LCD(displayproto, mosi, miso, sclk, CS, reset, DC, LCDSIZE_X, LCDSIZE_Y, IC_X_SEGS, IC_Y_COMS, name)
+IST3020::IST3020(proto_t displayproto, int Hz, PinName mosi, PinName miso, PinName sclk, PinName CS, PinName reset, PinName DC, const char *name)
+ : LCD(displayproto, Hz, mosi, miso, sclk, CS, reset, DC, LCDSIZE_X, LCDSIZE_Y, IC_X_SEGS, IC_Y_COMS, name)
{
hw_reset();
init();
@@ -29,35 +29,35 @@
{
/* Start Initial Sequence ----------------------------------------------------*/
- wr_cmd(0xE2); // sw reset
+ wr_cmd8(0xE2); // sw reset
wait_ms(10);
- wr_cmd(0xAE); // display off
- wr_cmd(0xAB); // built-in OSC on
- wr_cmd(0xA2); // bias voltage (1/9)
- // wr_cmd(0xA3); // bias voltage (1/7)
+ wr_cmd8(0xAE); // display off
+ wr_cmd8(0xAB); // built-in OSC on
+ wr_cmd8(0xA2); // bias voltage (1/9)
+ // wr_cmd8(0xA3); // bias voltage (1/7)
- wr_cmd(0xA0); // ADC select seg0-seg223
- //wr_cmd(0xA1); // ADC select seg223-seg0
- wr_cmd(0xC8); // SHL select com63-com0
- //wr_cmd(0xC0); // SHL select com0-com63
+ wr_cmd8(0xA0); // ADC select seg0-seg223
+ //wr_cmd8(0xA1); // ADC select seg223-seg0
+ wr_cmd8(0xC8); // SHL select com63-com0
+ //wr_cmd8(0xC0); // SHL select com0-com63
- wr_cmd(0x2C); // Internal Voltage Converter ON
+ wr_cmd8(0x2C); // Internal Voltage Converter ON
wait_ms(10);
- wr_cmd(0x2E); // Internal Voltage Regulator ON
+ wr_cmd8(0x2E); // Internal Voltage Regulator ON
wait_ms(10);
- wr_cmd(0x2F); // Internal Voltage Follower ON
+ wr_cmd8(0x2F); // Internal Voltage Follower ON
wait_ms(10);
- wr_cmd(0x20); // Regulor_Resistor_Select resistor ratio 20-27 20=4.5(default) 27=8.0, 0.5 steps
+ wr_cmd8(0x20); // Regulor_Resistor_Select resistor ratio 20-27 20=4.5(default) 27=8.0, 0.5 steps
set_contrast(48);
- //wr_cmd(0x81); // set contrast (reference voltage register set)
- //wr_cmd(0x20); // contrast 00-3F default 20
+ //wr_cmd8(0x81); // set contrast (reference voltage register set)
+ //wr_cmd8(0x20); // contrast 00-3F default 20
- wr_cmd(0xA4); // LCD display ram (EntireDisplayOn disable)
- //wr_cmd(0x70); // External Capacitors Discharge function enable (should be enabled by default)
- //wr_cmd(0x77); // External Capacitors Discharge function disable
- wr_cmd(0x40); // start line = 0
- wr_cmd(0xA6); // display normal (1 = illuminated)
- wr_cmd(0xAF); // display ON
+ wr_cmd8(0xA4); // LCD display ram (EntireDisplayOn disable)
+ //wr_cmd8(0x70); // External Capacitors Discharge function enable (should be enabled by default)
+ //wr_cmd8(0x77); // External Capacitors Discharge function disable
+ wr_cmd8(0x40); // start line = 0
+ wr_cmd8(0xA6); // display normal (1 = illuminated)
+ wr_cmd8(0xAF); // display ON
}
\ No newline at end of file
--- a/Inits/IST3020.h Thu Feb 12 22:22:47 2015 +0000
+++ b/Inits/IST3020.h Fri Feb 13 15:25:10 2015 +0000
@@ -14,8 +14,8 @@
public:
- /** Create a PAR_8 display interface
- * @param displayproto PAR_8 or PAR_16
+ /** Create a PAR display interface
+ * @param displayproto only supports PAR_8
* @param port GPIO port name to use
* @param CS pin connected to CS of display
* @param reset pin connected to RESET of display
@@ -26,8 +26,9 @@
*/
IST3020(proto_t displayproto, PortName port, PinName CS, PinName reset, PinName DC, PinName WR, PinName RD, const char* name);
- /** Create an SPI_8 display interface
- * @param displayproto SPI_8 or SPI_16
+ /** Create an SPI display interface
+ * @param displayproto only supports SPI_8
+ * @param Hz SPI speed in Hz
* @param mosi SPI pin
* @param miso SPI pin
* @param sclk SPI pin
@@ -36,7 +37,7 @@
* @param DC pin connected to data/command of display
* @param name The name used by the parent class to access the interface
*/
- IST3020(proto_t displayproto, PinName mosi, PinName miso, PinName sclk, PinName CS, PinName reset, PinName DC, const char* name);
+ IST3020(proto_t displayproto, int Hz, PinName mosi, PinName miso, PinName sclk, PinName CS, PinName reset, PinName DC, const char* name);
--- a/Inits/UC1608.cpp Thu Feb 12 22:22:47 2015 +0000
+++ b/Inits/UC1608.cpp Fri Feb 13 15:25:10 2015 +0000
@@ -21,8 +21,8 @@
set_orientation(1);
locate(0,0);
}
-UC1608::UC1608(proto_t displayproto, PinName mosi, PinName miso, PinName sclk, PinName CS, PinName reset, PinName DC, const char *name)
- : LCD(displayproto, mosi, miso, sclk, CS, reset, DC, LCDSIZE_X, LCDSIZE_Y, IC_X_SEGS, IC_Y_COMS, name)
+UC1608::UC1608(proto_t displayproto, int Hz, PinName mosi, PinName miso, PinName sclk, PinName CS, PinName reset, PinName DC, const char *name)
+ : LCD(displayproto, Hz, mosi, miso, sclk, CS, reset, DC, LCDSIZE_X, LCDSIZE_Y, IC_X_SEGS, IC_Y_COMS, name)
{
hw_reset();
BusEnable(true);
@@ -36,30 +36,30 @@
{
/* Start Initial Sequence ----------------------------------------------------*/
- // wr_cmd(0xE2); // sw reset
+ // wr_cmd8(0xE2); // sw reset
wait_ms(15);
- wr_cmd(0x27); // Multiplex rate :128 set temperature consenpation 0%
- wr_cmd(0xEA); //set bias:1/12bias
+ wr_cmd8(0x27); // Multiplex rate :128 set temperature consenpation 0%
+ wr_cmd8(0xEA); //set bias:1/12bias
- wr_cmd(0xC4); // set mirror MX=1,MY=0 (controller->display SEGs wiring inverted)
- // wr_cmd(0xA0); // ADC select seg0-seg223
- //wr_cmd(0xA1); // ADC select seg223-seg0
- // wr_cmd(0xC8); // SHL select com63-com0
- //wr_cmd(0xC0); // SHL select com0-com63
+ wr_cmd8(0xC4); // set mirror MX=1,MY=0 (controller->display SEGs wiring inverted)
+ // wr_cmd8(0xA0); // ADC select seg0-seg223
+ //wr_cmd8(0xA1); // ADC select seg223-seg0
+ // wr_cmd8(0xC8); // SHL select com63-com0
+ //wr_cmd8(0xC0); // SHL select com0-com63
- wr_cmd(0x2F); // //Power Control:internal, LCD capacitance 60nf-90nf
+ wr_cmd8(0x2F); // //Power Control:internal, LCD capacitance 60nf-90nf
wait_ms(10);
- // wr_cmd(0x81);//Set Gain and Potentiometer
- // wr_cmd(0x40|46);//Set Gain and Potentiometer xx xxxxxx
+ // wr_cmd8(0x81);//Set Gain and Potentiometer
+ // wr_cmd8(0x40|46);//Set Gain and Potentiometer xx xxxxxx
set_contrast(46);
- wr_cmd(0x88); //disable colum/page address wraparound
- wr_cmd(0xA4); // LCD display ram (EntireDisplayOn disable)
- wr_cmd(0x40); // start line = 0
- wr_cmd(0xA6); // display normal (1 = illuminated)
- wr_cmd(0xAF); // display ON
+ wr_cmd8(0x88); //disable colum/page address wraparound
+ wr_cmd8(0xA4); // LCD display ram (EntireDisplayOn disable)
+ wr_cmd8(0x40); // start line = 0
+ wr_cmd8(0xA6); // display normal (1 = illuminated)
+ wr_cmd8(0xAF); // display ON
}
////////////////////////////////////////////////////////////////////
@@ -70,24 +70,25 @@
switch (mode)
{
case(NONE):
- wr_cmd(0xC4); // this is in real X mirror command, but my display have SEGs wired inverted, so assume this is the default no-x-mirror
+ wr_cmd8(0xC4); // this is in real X mirror command, but my display have SEGs wired inverted, so assume this is the default no-x-mirror
break;
case(X):
- wr_cmd(0xC0);
+ wr_cmd8(0xC0);
break;
case(Y):
- wr_cmd(0xCC);
+ wr_cmd8(0xCC);
break;
case(XY):
- wr_cmd(0xC8);
+ wr_cmd8(0xC8);
break;
}
}
void UC1608::set_contrast(int o)
{
contrast = o;
- wr_cmd(0x81); // set volume
- wr_cmd(0x40|(o&0x3F));
+ // wr_cmd8(0x81); // set volume
+ // wr_cmd8(0x40|(o&0x3F));
+ wr_cmd16(0x8140|(o&0x3F));
}
void UC1608::BusEnable(bool enable)
{
--- a/Inits/UC1608.h Thu Feb 12 22:22:47 2015 +0000
+++ b/Inits/UC1608.h Fri Feb 13 15:25:10 2015 +0000
@@ -14,8 +14,8 @@
public:
- /** Create a PAR_8 display interface
- * @param displayproto PAR_8 or PAR_16
+ /** Create a PAR display interface
+ * @param displayproto only supports PAR_8
* @param port GPIO port name to use
* @param CS pin connected to CS of display
* @param reset pin connected to RESET of display
@@ -26,8 +26,9 @@
*/
UC1608(proto_t displayproto, PortName port, PinName CS, PinName reset, PinName DC, PinName WR, PinName RD, const char* name);
- /** Create an SPI_8 display interface
- * @param displayproto SPI_8 or SPI_16
+ /** Create an SPI display interface
+ * @param displayproto only supports SPI_8
+ * @param Hz SPI speed in Hz
* @param mosi SPI pin
* @param miso SPI pin
* @param sclk SPI pin
@@ -36,7 +37,7 @@
* @param DC pin connected to data/command of display
* @param name The name used by the parent class to access the interface
*/
- UC1608(proto_t displayproto, PinName mosi, PinName miso, PinName sclk, PinName CS, PinName reset, PinName DC, const char* name);
+ UC1608(proto_t displayproto, int Hz, PinName mosi, PinName miso, PinName sclk, PinName CS, PinName reset, PinName DC, const char* name);
/** set the contrast of the screen
* @note here overrided because of not standard command
--- a/Protocols/PAR8.cpp Thu Feb 12 22:22:47 2015 +0000
+++ b/Protocols/PAR8.cpp Fri Feb 13 15:25:10 2015 +0000
@@ -27,7 +27,7 @@
// debug("out 0x%.8X in 0x%.8X\r\n", outreg, inreg);
}
#endif
-void PAR8::wr_cmd(unsigned char cmd)
+void PAR8::wr_cmd8(unsigned char cmd)
{
#ifdef USE_CS
_CS = 0;
@@ -40,26 +40,26 @@
_CS = 1;
#endif
}
-void PAR8::wr_data8(unsigned char data8)
+void PAR8::wr_data8(unsigned char data)
{
#ifdef USE_CS
_CS = 0;
#endif
_DC = 1; // 1=data
_WR=0;
- _port.write(data8); // write 8bit
+ _port.write(data); // write 8bit
_WR=1;
#ifdef USE_CS
_CS = 1;
#endif
}
-void PAR8::wr_data8(unsigned char data8, unsigned int count)
+void PAR8::wr_data8(unsigned char data, unsigned int count)
{
#ifdef USE_CS
_CS = 0;
#endif
_DC = 1; // 1=data
- _port.write(data8); // write 8bit
+ _port.write(data); // write 8bit
while(count)
{
_WR=0;
@@ -71,7 +71,7 @@
_CS = 1;
#endif
}
-void PAR8::wr_data8buf(unsigned char* data8, unsigned int lenght)
+void PAR8::wr_data8buf(unsigned char* data, unsigned int lenght)
{
#ifdef USE_CS
_CS = 0;
@@ -80,7 +80,7 @@
while(lenght)
{
_WR=0;
- _port.write(*data8++); // write 8bit
+ _port.write(*data++); // write 8bit
_WR=1;
lenght--;
}
@@ -88,6 +88,93 @@
_CS = 1;
#endif
}
+void PAR8::wr_cmd16(unsigned short cmd)
+{
+#ifdef USE_CS
+ _CS = 0;
+#endif
+ _DC = 0; // 0=cmd
+ _WR=0;
+ _port.write(cmd>>8); // write 8bit
+ _WR=1;
+ _WR=0;
+ _port.write(cmd&0xFF); // write 8bit
+ _WR=1;
+#ifdef USE_CS
+ _CS = 1;
+#endif
+}
+void PAR8::wr_data16(unsigned short data)
+{
+#ifdef USE_CS
+ _CS = 0;
+#endif
+ _DC = 1; // 1=data
+ _WR=0;
+ _port.write(data>>8); // write 8bit
+ _WR=1;
+ _WR=0;
+ _port.write(data&0xFF); // write 8bit
+ _WR=1;
+#ifdef USE_CS
+ _CS = 1;
+#endif
+}
+void PAR8::wr_data16(unsigned short data, unsigned int count)
+{
+#ifdef USE_CS
+ _CS = 0;
+#endif
+ _DC = 1; // 1=data
+ if((data>>8)==(data&0xFF))
+ {
+ count<<=1;
+ _port.write(data); // write 8bit
+ while(count)
+ {
+ _WR=0;
+ _WR=1;
+ count--;
+ }
+ }
+ else
+ {
+ while(count)
+ {
+ _WR=0;
+ _port.write(data>>8); // write 8bit
+ _WR=1;
+ _WR=0;
+ _port.write(data&0xFF); // write 8bit
+ _WR=1;
+ count--;
+ }
+ }
+#ifdef USE_CS
+ _CS = 1;
+#endif
+}
+void PAR8::wr_data16buf(unsigned short* data, unsigned int lenght)
+{
+#ifdef USE_CS
+ _CS = 0;
+#endif
+ _DC = 1; // 1=data
+ while(lenght)
+ {
+ _WR=0;
+ _port.write((*data)>>8); // write 8bit
+ _WR=1;
+ _WR=0;
+ _port.write((*data)&0xFF); // write 8bit
+ _WR=1;
+ data++;
+ lenght--;
+ }
+#ifdef USE_CS
+ _CS = 1;
+#endif
+}
void PAR8::hw_reset()
{
wait_ms(15);
--- a/Protocols/PAR8.h Thu Feb 12 22:22:47 2015 +0000
+++ b/Protocols/PAR8.h Fri Feb 13 15:25:10 2015 +0000
@@ -22,35 +22,65 @@
protected:
- /** Send command byte to display controller
+ /** Send 8bit command to display controller
*
* @param cmd: byte to send
*
*/
- virtual void wr_cmd(unsigned char cmd);
+ virtual void wr_cmd8(unsigned char cmd);
- /** Send data byte to display controller
+ /** Send 8bit data to display controller
*
- * @param data8: byte to send
+ * @param data: byte to send
*
*/
- virtual void wr_data8(unsigned char data8);
+ virtual void wr_data8(unsigned char data);
- /** Send same data byte to display controller multiple times
+ /** Send same 8bit data to display controller multiple times
*
- * @param data8: byte to send
+ * @param data: byte to send
* @param count: how many
*
*/
- virtual void wr_data8(unsigned char data8, unsigned int count);
+ virtual void wr_data8(unsigned char data, unsigned int count);
/** Send array of data bytes to display controller
*
- * @param data8: unsigned char data array
+ * @param data: unsigned char data array
* @param lenght: lenght of array
*
*/
- virtual void wr_data8buf(unsigned char* data8, unsigned int lenght);
+ virtual void wr_data8buf(unsigned char* data, unsigned int lenght);
+
+ /** Send 16bit command to display controller
+ *
+ * @param cmd: halfword to send
+ *
+ */
+ virtual void wr_cmd16(unsigned short cmd);
+
+ /** Send 16bit data to display controller
+ *
+ * @param data: halfword to send
+ *
+ */
+ virtual void wr_data16(unsigned short data);
+
+ /** Send same 16bit data to display controller multiple times
+ *
+ * @param data: halfword to send
+ * @param count: how many
+ *
+ */
+ virtual void wr_data16(unsigned short data, unsigned int count);
+
+ /** Send array of data shorts to display controller
+ *
+ * @param data: unsigned short data array
+ * @param lenght: lenght (in shorts)
+ *
+ */
+ virtual void wr_data16buf(unsigned short* data, unsigned int lenght);
/** HW reset sequence (without display init commands)
*/
--- a/Protocols/Protocols.h Thu Feb 12 22:22:47 2015 +0000
+++ b/Protocols/Protocols.h Fri Feb 13 15:25:10 2015 +0000
@@ -21,35 +21,65 @@
{
public:
- /** Send command byte to display controller
+ /** Send 8bit command to display controller
*
* @param cmd: byte to send
*
*/
- virtual void wr_cmd(unsigned char cmd) = 0;
+ virtual void wr_cmd8(unsigned char cmd) = 0;
- /** Send data byte to display controller
+ /** Send 8bit data to display controller
*
- * @param data8: byte to send
+ * @param data: byte to send
*
*/
- virtual void wr_data8(unsigned char data8) = 0;
+ virtual void wr_data8(unsigned char data) = 0;
- /** Send same data byte to display controller multiple times
+ /** Send same 8bit data to display controller multiple times
*
- * @param data8: byte to send
+ * @param data: byte to send
* @param count: how many
*
*/
- virtual void wr_data8(unsigned char data8, unsigned int count) = 0;
+ virtual void wr_data8(unsigned char data, unsigned int count) = 0;
/** Send array of data bytes to display controller
*
- * @param data8: unsigned char data array
- * @param lenght: lenght of array
+ * @param data: unsigned char data array
+ * @param lenght: lenght
+ *
+ */
+ virtual void wr_data8buf(unsigned char* data, unsigned int lenght) = 0;
+
+ /** Send 16bit command to display controller
+ *
+ * @param cmd: halfword to send
+ *
+ */
+ virtual void wr_cmd16(unsigned short cmd) = 0;
+
+ /** Send 16bit data to display controller
+ *
+ * @param data: halfword to send
*
*/
- virtual void wr_data8buf(unsigned char* data8, unsigned int lenght) = 0;
+ virtual void wr_data16(unsigned short data) = 0;
+
+ /** Send same 16bit data to display controller multiple times
+ *
+ * @param data: halfword to send
+ * @param count: how many
+ *
+ */
+ virtual void wr_data16(unsigned short data, unsigned int count) = 0;
+
+ /** Send array of data shorts to display controller
+ *
+ * @param data: unsigned short data array
+ * @param lenght: lenght (in shorts)
+ *
+ */
+ virtual void wr_data16buf(unsigned short* data, unsigned int lenght) = 0;
/** HW reset sequence (without display init commands)
*/
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Protocols/SPI16.cpp Fri Feb 13 15:25:10 2015 +0000
@@ -0,0 +1,147 @@
+#include "SPI16.h"
+//#define USE_CS
+
+SPI16::SPI16(int Hz, PinName mosi, PinName miso, PinName sclk, PinName CS, PinName reset, PinName DC)
+ : _CS(CS), _spi(mosi, miso, sclk), _reset(reset), _DC(DC)
+{
+ _reset = 1;
+ _DC=1;
+ _CS=1;
+ _spi.format(16,0); // 8 bit spi mode 0
+ // _spi.frequency(12000000); // 10 Mhz SPI clock, 12mhz for F411
+ _spi.frequency(Hz);
+ hw_reset();
+}
+
+void SPI16::wr_cmd8(unsigned char cmd)
+{
+#ifdef USE_CS
+ _CS = 0;
+#endif
+ _spi.format(8,0); // it takes time, better use wr_cmd16 with NOP cmd
+ _DC.write(0); // 0=cmd
+ _spi.write(cmd); // write 8bit
+ _spi.format(16,0);
+#ifdef USE_CS
+ _CS = 1;
+#endif
+}
+void SPI16::wr_data8(unsigned char data)
+{
+#ifdef USE_CS
+ _CS = 0;
+#endif
+ _spi.format(8,0); // it takes time, check prev cmd parameter, in case use wr_data16 with repeated byte
+ _DC.write(1); // 1=data
+ _spi.write(data); // write 8bit
+ _spi.format(16,0);
+#ifdef USE_CS
+ _CS = 1;
+#endif
+}
+void SPI16::wr_data8(unsigned char data, unsigned int count)
+{
+#ifdef USE_CS
+ _CS = 0;
+#endif
+ _spi.format(8,0);
+ _DC.write(1); // 1=data
+ while(count)
+ {
+ _spi.write(data); // write 8bit
+ count--;
+ }
+ _spi.format(16,0);
+#ifdef USE_CS
+ _CS = 1;
+#endif
+}
+void SPI16::wr_data8buf(unsigned char* data, unsigned int lenght)
+{
+#ifdef USE_CS
+ _CS = 0;
+#endif
+ _spi.format(8,0);
+ _DC.write(1); // 1=data
+ while(lenght)
+ {
+ _spi.write(*data++); // write 8bit
+ // data++;
+ lenght--;
+ }
+ _spi.format(16,0);
+#ifdef USE_CS
+ _CS = 1;
+#endif
+}
+void SPI16::wr_cmd16(unsigned short cmd)
+{
+#ifdef USE_CS
+ _CS = 0;
+#endif
+ _DC.write(0); // 0=cmd
+ _spi.write(cmd); // write 16bit
+#ifdef USE_CS
+ _CS = 1;
+#endif
+}
+void SPI16::wr_data16(unsigned short data)
+{
+#ifdef USE_CS
+ _CS = 0;
+#endif
+ _DC.write(1); // 1=data
+ _spi.write(data); // write 16bit
+#ifdef USE_CS
+ _CS = 1;
+#endif
+}
+void SPI16::wr_data16(unsigned short data, unsigned int count)
+{
+#ifdef USE_CS
+ _CS = 0;
+#endif
+ _DC.write(1); // 1=data
+ while(count)
+ {
+ _spi.write(data);
+ count--;
+ }
+#ifdef USE_CS
+ _CS = 1;
+#endif
+}
+void SPI16::wr_data16buf(unsigned short* data, unsigned int lenght)
+{
+#ifdef USE_CS
+ _CS = 0;
+#endif
+ _DC.write(1); // 1=data
+ while(lenght)
+ {
+ _spi.write(*data);
+ data++;
+ lenght--;
+ }
+#ifdef USE_CS
+ _CS = 1;
+#endif
+}
+void SPI16::hw_reset()
+{
+ wait_ms(15);
+ _DC = 1;
+ // _CS = 1;
+ _CS = 0;
+ _reset = 0; // display reset
+ wait_us(50);
+ _reset = 1; // end reset
+ wait_ms(15);
+#ifndef USE_CS
+ _CS=0; // put CS low now and forever
+#endif
+}
+void SPI16::BusEnable(bool enable)
+{
+ _CS = enable ? 0:1;
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Protocols/SPI16.h Fri Feb 13 15:25:10 2015 +0000
@@ -0,0 +1,107 @@
+#ifndef SPI16_H
+#define SPI16_H
+
+#include "mbed.h"
+#include "Protocols.h"
+//#include "GraphicsDisplay.h"
+
+class SPI16 : public Protocols
+{
+ public:
+
+ /** Create an SPI 8bit display interface with 3 control pins
+ *
+ * @param SPI mosi
+ * @param SPI miso
+ * @param SPI sclk
+ * @param CS pin connected to CS of display
+ * @param reset pin connected to RESET of display
+ * @param DC pin connected to data/command of display
+ */
+ SPI16(int Hz, PinName mosi, PinName miso, PinName sclk, PinName CS, PinName reset, PinName DC);
+
+protected:
+
+ /** Send 8bit command to display controller
+ *
+ * @note switches spi format 16->8->16, better use wr_cmd16 with NOP in front
+ * @param cmd: byte to send
+ *
+ */
+ virtual void wr_cmd8(unsigned char cmd);
+
+ /** Send 8bit data to display controller
+ *
+ * @note switches spi format 16->8->16, better use wr_data16 with repeated byte (if does not hurt)
+ * @param data: byte to send
+ *
+ */
+ virtual void wr_data8(unsigned char data);
+
+ /** Send same 8bit data to display controller multiple times
+ *
+ * @note switches spi format 16->8->16, better use wr_data16
+ * @param data: byte to send
+ * @param count: how many
+ *
+ */
+ virtual void wr_data8(unsigned char data, unsigned int count);
+
+ /** Send array of data bytes to display controller
+ *
+ * @note switches spi format 16->8->16, better use wr_data16
+ * @param data: unsigned char data array
+ * @param lenght: lenght of array
+ *
+ */
+ virtual void wr_data8buf(unsigned char* data, unsigned int lenght);
+
+ /** Send 16bit command to display controller
+ *
+ * @param cmd: halfword to send
+ *
+ */
+ virtual void wr_cmd16(unsigned short cmd);
+
+ /** Send 16bit data to display controller
+ *
+ * @param data: halfword to send
+ *
+ */
+ virtual void wr_data16(unsigned short data);
+
+ /** Send same 16bit data to display controller multiple times
+ *
+ * @param data: halfword to send
+ * @param count: how many
+ *
+ */
+ virtual void wr_data16(unsigned short data, unsigned int count);
+
+ /** Send array of data shorts to display controller
+ *
+ * @param data: unsigned short data array
+ * @param lenght: lenght (in shorts)
+ *
+ */
+ virtual void wr_data16buf(unsigned short* data, unsigned int lenght);
+
+ /** HW reset sequence (without display init commands)
+ */
+ virtual void hw_reset();
+
+ /** Set ChipSelect high or low
+ * @param enable 0/1
+ */
+ virtual void BusEnable(bool enable);
+
+ DigitalOut _CS;
+
+private:
+
+ SPI _spi;
+ DigitalOut _reset;
+ DigitalOut _DC;
+
+};
+#endif
\ No newline at end of file
--- a/Protocols/SPI8.cpp Thu Feb 12 22:22:47 2015 +0000
+++ b/Protocols/SPI8.cpp Fri Feb 13 15:25:10 2015 +0000
@@ -2,7 +2,7 @@
//#define USE_CS
-SPI8::SPI8(PinName mosi, PinName miso, PinName sclk, PinName CS, PinName reset, PinName DC)
+SPI8::SPI8(int Hz, PinName mosi, PinName miso, PinName sclk, PinName CS, PinName reset, PinName DC)
: _CS(CS), _spi(mosi, miso, sclk), _reset(reset), _DC(DC)
{
_reset = 1;
@@ -10,11 +10,11 @@
_CS=1;
_spi.format(8,0); // 8 bit spi mode 0
// _spi.frequency(12000000); // 10 Mhz SPI clock, 12mhz for F411
- _spi.frequency(10000000);
+ _spi.frequency(Hz);
hw_reset();
}
-void SPI8::wr_cmd(unsigned char cmd)
+void SPI8::wr_cmd8(unsigned char cmd)
{
#ifdef USE_CS
_CS = 0;
@@ -25,18 +25,18 @@
_CS = 1;
#endif
}
-void SPI8::wr_data8(unsigned char data8)
+void SPI8::wr_data8(unsigned char data)
{
#ifdef USE_CS
_CS = 0;
#endif
_DC.write(1); // 1=data
- _spi.write(data8); // write 8bit
+ _spi.write(data); // write 8bit
#ifdef USE_CS
_CS = 1;
#endif
}
-void SPI8::wr_data8(unsigned char data8, unsigned int count)
+void SPI8::wr_data8(unsigned char data, unsigned int count)
{
#ifdef USE_CS
_CS = 0;
@@ -44,14 +44,14 @@
_DC.write(1); // 1=data
while(count)
{
- _spi.write(data8); // write 8bit
+ _spi.write(data); // write 8bit
count--;
}
#ifdef USE_CS
_CS = 1;
#endif
}
-void SPI8::wr_data8buf(unsigned char* data8, unsigned int lenght)
+void SPI8::wr_data8buf(unsigned char* data, unsigned int lenght)
{
#ifdef USE_CS
_CS = 0;
@@ -59,8 +59,77 @@
_DC.write(1); // 1=data
while(lenght)
{
- _spi.write(*data8++); // write 8bit
- // data8++;
+ _spi.write(*data++); // write 8bit
+ // data++;
+ lenght--;
+ }
+#ifdef USE_CS
+ _CS = 1;
+#endif
+}
+void SPI8::wr_cmd16(unsigned short cmd)
+{
+#ifdef USE_CS
+ _CS = 0;
+#endif
+ _DC.write(0); // 0=cmd
+ _spi.write(cmd>>8); // write 8bit
+ _spi.write(cmd&0xFF); // write 8bit
+#ifdef USE_CS
+ _CS = 1;
+#endif
+}
+void SPI8::wr_data16(unsigned short data)
+{
+#ifdef USE_CS
+ _CS = 0;
+#endif
+ _DC.write(1); // 1=data
+ _spi.write(data>>8); // write 8bit
+ _spi.write(data&0xFF); // write 8bit
+#ifdef USE_CS
+ _CS = 1;
+#endif
+}
+void SPI8::wr_data16(unsigned short data, unsigned int count)
+{
+#ifdef USE_CS
+ _CS = 0;
+#endif
+ _DC.write(1); // 1=data
+ if((data>>8)==(data&0xFF))
+ {
+ count<<=1;
+ while(count)
+ {
+ _spi.write(data); // write 8bit
+ count--;
+ }
+ }
+ else
+ {
+ while(count)
+ {
+ _spi.write(data>>8); // write 8bit
+ _spi.write(data&0xFF); // write 8bit
+ count--;
+ }
+ }
+#ifdef USE_CS
+ _CS = 1;
+#endif
+}
+void SPI8::wr_data16buf(unsigned short* data, unsigned int lenght)
+{
+#ifdef USE_CS
+ _CS = 0;
+#endif
+ _DC.write(1); // 1=data
+ while(lenght)
+ {
+ _spi.write((*data)>>8); // write 8bit
+ _spi.write((*data)&0xFF); // write 8bit
+ data++;
lenght--;
}
#ifdef USE_CS
--- a/Protocols/SPI8.h Thu Feb 12 22:22:47 2015 +0000
+++ b/Protocols/SPI8.h Fri Feb 13 15:25:10 2015 +0000
@@ -18,39 +18,69 @@
* @param reset pin connected to RESET of display
* @param DC pin connected to data/command of display
*/
- SPI8(PinName mosi, PinName miso, PinName sclk, PinName CS, PinName reset, PinName DC);
+ SPI8(int Hz, PinName mosi, PinName miso, PinName sclk, PinName CS, PinName reset, PinName DC);
protected:
- /** Send command byte to display controller
+ /** Send 8bit command to display controller
*
* @param cmd: byte to send
*
*/
- virtual void wr_cmd(unsigned char cmd);
+ virtual void wr_cmd8(unsigned char cmd);
- /** Send data byte to display controller
+ /** Send 8bit data to display controller
*
- * @param data8: byte to send
+ * @param data: byte to send
*
*/
- virtual void wr_data8(unsigned char data8);
+ virtual void wr_data8(unsigned char data);
- /** Send same data byte to display controller multiple times
+ /** Send same 8bit data to display controller multiple times
*
- * @param data8: byte to send
+ * @param data: byte to send
* @param count: how many
*
*/
- virtual void wr_data8(unsigned char data8, unsigned int count);
+ virtual void wr_data8(unsigned char data, unsigned int count);
/** Send array of data bytes to display controller
*
- * @param data8: unsigned char data array
+ * @param data: unsigned char data array
* @param lenght: lenght of array
*
*/
- virtual void wr_data8buf(unsigned char* data8, unsigned int lenght);
+ virtual void wr_data8buf(unsigned char* data, unsigned int lenght);
+
+ /** Send 16bit command to display controller
+ *
+ * @param cmd: halfword to send
+ *
+ */
+ virtual void wr_cmd16(unsigned short cmd);
+
+ /** Send 16bit data to display controller
+ *
+ * @param data: halfword to send
+ *
+ */
+ virtual void wr_data16(unsigned short data);
+
+ /** Send same 16bit data to display controller multiple times
+ *
+ * @param data: halfword to send
+ * @param count: how many
+ *
+ */
+ virtual void wr_data16(unsigned short data, unsigned int count);
+
+ /** Send array of data shorts to display controller
+ *
+ * @param data: unsigned short data array
+ * @param lenght: lenght (in shorts)
+ *
+ */
+ virtual void wr_data16buf(unsigned short* data, unsigned int lenght);
/** HW reset sequence (without display init commands)
*/
