Basically i glued Peter Drescher and Simon Ford libs in a GraphicsDisplay class, then derived TFT or LCD class (which inherits Protocols class), then the most derived ones (Inits), which are per-display and are the only part needed to be adapted to diff hw.

Dependents:   Brew

Committer:
Geremia
Date:
Thu Feb 12 22:22:47 2015 +0000
Revision:
0:75ec1b3cde17
Child:
1:ff019d22b275
Initial tests, LCD par and spi ok

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Geremia 0:75ec1b3cde17 1 #include "Protocols.h"
Geremia 0:75ec1b3cde17 2 #include "UC1608.h"
Geremia 0:75ec1b3cde17 3
Geremia 0:75ec1b3cde17 4 //////////////////////////////////////////////////////////////////////////////////
Geremia 0:75ec1b3cde17 5 // display settings ///////////////////////////////////////////////////////
Geremia 0:75ec1b3cde17 6 /////////////////////////////////////////////////////////////////////////
Geremia 0:75ec1b3cde17 7 #define IC_X_SEGS 240 // UC1608 SEG has range 0-239 (239-0 if MX=1), check your datasheet, important for the orientation
Geremia 0:75ec1b3cde17 8 #define IC_Y_COMS 128 // UC1608 COM has range 0-127 (127-0 if MY=1), check your datasheet, important for the orientation
Geremia 0:75ec1b3cde17 9 #define LCDSIZE_X 240 // display X pixels
Geremia 0:75ec1b3cde17 10 #define LCDSIZE_Y 120 // display Y pixels, UC1608 is advertised as 240x128 but display size could be smaller
Geremia 0:75ec1b3cde17 11
Geremia 0:75ec1b3cde17 12
Geremia 0:75ec1b3cde17 13
Geremia 0:75ec1b3cde17 14 UC1608::UC1608(proto_t displayproto, PortName port, PinName CS, PinName reset, PinName DC, PinName WR, PinName RD, const char *name)
Geremia 0:75ec1b3cde17 15 : LCD(displayproto, port, CS, reset, DC, WR, RD, LCDSIZE_X, LCDSIZE_Y, IC_X_SEGS, IC_Y_COMS, name)
Geremia 0:75ec1b3cde17 16 {
Geremia 0:75ec1b3cde17 17 hw_reset();
Geremia 0:75ec1b3cde17 18 BusEnable(true);
Geremia 0:75ec1b3cde17 19 init();
Geremia 0:75ec1b3cde17 20 cls();
Geremia 0:75ec1b3cde17 21 set_orientation(1);
Geremia 0:75ec1b3cde17 22 locate(0,0);
Geremia 0:75ec1b3cde17 23 }
Geremia 0:75ec1b3cde17 24 UC1608::UC1608(proto_t displayproto, PinName mosi, PinName miso, PinName sclk, PinName CS, PinName reset, PinName DC, const char *name)
Geremia 0:75ec1b3cde17 25 : LCD(displayproto, mosi, miso, sclk, CS, reset, DC, LCDSIZE_X, LCDSIZE_Y, IC_X_SEGS, IC_Y_COMS, name)
Geremia 0:75ec1b3cde17 26 {
Geremia 0:75ec1b3cde17 27 hw_reset();
Geremia 0:75ec1b3cde17 28 BusEnable(true);
Geremia 0:75ec1b3cde17 29 init();
Geremia 0:75ec1b3cde17 30 cls();
Geremia 0:75ec1b3cde17 31 set_orientation(1);
Geremia 0:75ec1b3cde17 32 locate(0,0);
Geremia 0:75ec1b3cde17 33 }
Geremia 0:75ec1b3cde17 34 // reset and init the lcd controller
Geremia 0:75ec1b3cde17 35 void UC1608::init()
Geremia 0:75ec1b3cde17 36 {
Geremia 0:75ec1b3cde17 37 /* Start Initial Sequence ----------------------------------------------------*/
Geremia 0:75ec1b3cde17 38
Geremia 0:75ec1b3cde17 39 // wr_cmd(0xE2); // sw reset
Geremia 0:75ec1b3cde17 40 wait_ms(15);
Geremia 0:75ec1b3cde17 41
Geremia 0:75ec1b3cde17 42 wr_cmd(0x27); // Multiplex rate :128 set temperature consenpation 0%
Geremia 0:75ec1b3cde17 43 wr_cmd(0xEA); //set bias:1/12bias
Geremia 0:75ec1b3cde17 44
Geremia 0:75ec1b3cde17 45 wr_cmd(0xC4); // set mirror MX=1,MY=0 (controller->display SEGs wiring inverted)
Geremia 0:75ec1b3cde17 46 // wr_cmd(0xA0); // ADC select seg0-seg223
Geremia 0:75ec1b3cde17 47 //wr_cmd(0xA1); // ADC select seg223-seg0
Geremia 0:75ec1b3cde17 48 // wr_cmd(0xC8); // SHL select com63-com0
Geremia 0:75ec1b3cde17 49 //wr_cmd(0xC0); // SHL select com0-com63
Geremia 0:75ec1b3cde17 50
Geremia 0:75ec1b3cde17 51 wr_cmd(0x2F); // //Power Control:internal, LCD capacitance 60nf-90nf
Geremia 0:75ec1b3cde17 52 wait_ms(10);
Geremia 0:75ec1b3cde17 53
Geremia 0:75ec1b3cde17 54 // wr_cmd(0x81);//Set Gain and Potentiometer
Geremia 0:75ec1b3cde17 55 // wr_cmd(0x40|46);//Set Gain and Potentiometer xx xxxxxx
Geremia 0:75ec1b3cde17 56 set_contrast(46);
Geremia 0:75ec1b3cde17 57
Geremia 0:75ec1b3cde17 58 wr_cmd(0x88); //disable colum/page address wraparound
Geremia 0:75ec1b3cde17 59 wr_cmd(0xA4); // LCD display ram (EntireDisplayOn disable)
Geremia 0:75ec1b3cde17 60 wr_cmd(0x40); // start line = 0
Geremia 0:75ec1b3cde17 61 wr_cmd(0xA6); // display normal (1 = illuminated)
Geremia 0:75ec1b3cde17 62 wr_cmd(0xAF); // display ON
Geremia 0:75ec1b3cde17 63
Geremia 0:75ec1b3cde17 64 }
Geremia 0:75ec1b3cde17 65 ////////////////////////////////////////////////////////////////////
Geremia 0:75ec1b3cde17 66 // functions that overrides the standard ones implemented in LCD.cpp
Geremia 0:75ec1b3cde17 67 ////////////////////////////////////////////////////////////////////
Geremia 0:75ec1b3cde17 68 void UC1608::mirrorXY(mirror_t mode)
Geremia 0:75ec1b3cde17 69 {
Geremia 0:75ec1b3cde17 70 switch (mode)
Geremia 0:75ec1b3cde17 71 {
Geremia 0:75ec1b3cde17 72 case(NONE):
Geremia 0:75ec1b3cde17 73 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
Geremia 0:75ec1b3cde17 74 break;
Geremia 0:75ec1b3cde17 75 case(X):
Geremia 0:75ec1b3cde17 76 wr_cmd(0xC0);
Geremia 0:75ec1b3cde17 77 break;
Geremia 0:75ec1b3cde17 78 case(Y):
Geremia 0:75ec1b3cde17 79 wr_cmd(0xCC);
Geremia 0:75ec1b3cde17 80 break;
Geremia 0:75ec1b3cde17 81 case(XY):
Geremia 0:75ec1b3cde17 82 wr_cmd(0xC8);
Geremia 0:75ec1b3cde17 83 break;
Geremia 0:75ec1b3cde17 84 }
Geremia 0:75ec1b3cde17 85 }
Geremia 0:75ec1b3cde17 86 void UC1608::set_contrast(int o)
Geremia 0:75ec1b3cde17 87 {
Geremia 0:75ec1b3cde17 88 contrast = o;
Geremia 0:75ec1b3cde17 89 wr_cmd(0x81); // set volume
Geremia 0:75ec1b3cde17 90 wr_cmd(0x40|(o&0x3F));
Geremia 0:75ec1b3cde17 91 }
Geremia 0:75ec1b3cde17 92 void UC1608::BusEnable(bool enable)
Geremia 0:75ec1b3cde17 93 {
Geremia 0:75ec1b3cde17 94 LCD::BusEnable(!enable); // crap IC has CS not inverted (active HIGH)
Geremia 0:75ec1b3cde17 95 }