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:   testUniGraphic_150217 maze_TFT_MMA8451Q TFT_test_frdm-kl25z TFT_test_NUCLEO-F411RE ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers SEPS225.cpp Source File

SEPS225.cpp

00001 #include "mbed.h"
00002 
00003 #include "SEPS225.h"
00004 
00005 #ifndef OLED_LCD_REG_H_
00006 #define OLED_LCD_REG_H_
00007 
00008 #define CMD_INDEX                       0x00
00009 #define CMD_STATUS_RD                   0x01
00010 #define CMD_OSC_CTL                     0x02
00011 #define CMD_CLOCK_DIV                   0x03
00012 #define CMD_REDUCE_CURRENT              0x04
00013 #define CMD_SOFT_RST                    0x05
00014 #define CMD_DISP_ON_OFF                 0x06
00015 #define CMD_PRECHARGE_TIME_R            0x08
00016 #define CMD_PRECHARGE_TIME_G            0x09
00017 #define CMD_PRECHARGE_TIME_B            0x0A
00018 #define CMD_PRECHARGE_CURRENT_R         0x0B
00019 #define CMD_PRECHARGE_CURRENT_G         0x0C
00020 #define CMD_PRECHARGE_CURRENT_B         0x0D
00021 #define CMD_DRIVING_CURRENT_R           0x10
00022 #define CMD_DRIVING_CURRENT_G           0x11
00023 #define CMD_DRIVING_CURRENT_B           0x12
00024 #define CMD_DISPLAY_MODE_SET            0x13
00025 #define CMD_RGB_IF                      0x14
00026 #define CMD_RGB_POL                     0x15
00027 #define CMD_MEMORY_WRITE_MODE           0x16
00028 #define CMD_MX1_ADDR                    0x17
00029 #define CMD_MX2_ADDR                    0x18
00030 #define CMD_MY1_ADDR                    0x19
00031 #define CMD_MY2_ADDR                    0x1A
00032 #define CMD_MEMORY_ACCESS_POINTER_X     0x20
00033 #define CMD_MEMORY_ACCESS_POINTER_Y     0x21
00034 #define CMD_DDRAM_DATA_ACCESS_PORT      0x22
00035 #define CMD_DUTY                        0x28
00036 #define CMD_DSL                         0x29
00037 #define CMD_D1_DDRAM_FAC                0x2E
00038 #define CMD_D1_DDRAM_FAR                0x2F
00039 #define CMD_D2_DDRAM_SAC                0x31
00040 #define CMD_D2_DDRAM_SAR                0x32
00041 #define CMD_SCR1_FX1                    0x33
00042 #define CMD_SCR1_FX2                    0x34
00043 #define CMD_SCR1_FY1                    0x35
00044 #define CMD_SCR1_FY2                    0x36
00045 #define CMD_SCR2_SX1                    0x37
00046 #define CMD_SCR2_SX2                    0x38
00047 #define CMD_SCR2_SY1                    0x39
00048 #define CMD_SCR2_SY2                    0x3A
00049 #define CMD_SCREEN_SAVER_CONTEROL       0x3B
00050 #define CMD_SS_SLEEP_TIMER              0x3C
00051 #define CMD_SCREEN_SAVER_MODE           0x3D
00052 #define CMD_SS_SCR1_FU                  0x3E
00053 #define CMD_SS_SCR1_MXY                 0x3F
00054 #define CMD_SS_SCR2_FU                  0x40
00055 #define CMD_SS_SCR2_MXY                 0x41
00056 #define CMD_MOVING_DIRECTION            0x42
00057 #define CMD_SS_SCR2_SX1                 0x47
00058 #define CMD_SS_SCR2_SX2                 0x48
00059 #define CMD_SS_SCR2_SY1                 0x49
00060 #define CMD_SS_SCR2_SY2                 0x4A
00061 #define CMD_IREF                        0x80
00062 
00063 
00064 #define LCD_RESET   0
00065 #define LCD_CLEAR   1
00066 #define LCD_PRINT   2
00067 
00068 
00069 #define COLOR_RED     0xF100
00070 #define COLOR_GREEN   0x07E0
00071 #define COLOR_BLUE    0x001F
00072 #define COLOR_CYAN    0x07FF
00073 #define COLOR_MAGENTA 0xF11F
00074 #define COLOR_YELLOW  0xFFE0
00075 #define COLOR_BLACK   0x0000
00076 #define COLOR_WHITE   0xFFFF
00077 
00078 #define OLED_WIDTH   0x80
00079 #define OLED_HEIGHT  0x80
00080 
00081 #endif /* OLED_LCD_REG_H_ */
00082 
00083 SEPS225::SEPS225(proto_t displayproto, PortName port, PinName CS, PinName reset, PinName DC, PinName WR, PinName RD, const char *name, unsigned int LCDSIZE_X, unsigned  int LCDSIZE_Y)
00084     : TFT(displayproto, port, CS, reset, DC, WR, RD, LCDSIZE_X, LCDSIZE_Y, name)
00085 {
00086     hw_reset();
00087     BusEnable(true);
00088     identify(); // will collect tftID and set mipistd flag
00089     init();
00090     auto_gram_read_format();
00091     set_orientation(0);
00092     cls();
00093     FastWindow(true); // most but not all controllers support this, even if datasheet tells they should. 
00094     locate(0,0); 
00095 }
00096 SEPS225::SEPS225(proto_t displayproto, PinName* buspins, PinName CS, PinName reset, PinName DC, PinName WR, PinName RD, const char *name, unsigned int LCDSIZE_X, unsigned  int LCDSIZE_Y)
00097     : TFT(displayproto, buspins, CS, reset, DC, WR, RD, LCDSIZE_X, LCDSIZE_Y, name)
00098 {
00099     hw_reset();
00100     BusEnable(true);
00101     identify(); // will collect tftID and set mipistd flag
00102     init();
00103     auto_gram_read_format();
00104     set_orientation(0);
00105     cls();
00106     FastWindow(true); // most but not all controllers support this, even if datasheet tells they should. 
00107     locate(0,0); 
00108 }
00109 SEPS225::SEPS225(proto_t displayproto, int Hz, PinName mosi, PinName miso, PinName sclk, PinName CS, PinName reset, PinName DC, const char *name, unsigned int LCDSIZE_X , unsigned  int LCDSIZE_Y)
00110     : TFT(displayproto, Hz, mosi, miso, sclk, CS, reset, DC, LCDSIZE_X, LCDSIZE_Y, name)
00111 {
00112     _cs = new DigitalOut(CS, 1) ;
00113     _rs = new DigitalOut(DC, 1) ;
00114     
00115     hw_reset(); //TFT class forwards to Protocol class
00116     BusEnable(true); //TFT class forwards to Protocol class
00117     identify(); // will collect tftID and set mipistd flag
00118     init(); // per display custom init cmd sequence, implemented here
00119     auto_gram_read_format();// try to get read gram pixel format, could be 16bit or 18bit, RGB or BGR. Will set flags accordingly
00120     set_orientation(0); //TFT class does for MIPI standard and some ILIxxx
00121     FastWindow(true); // most but not all controllers support this, even if datasheet tells they should. 
00122     cls();
00123     locate(0,0); 
00124 }
00125 
00126 // reset and init the lcd controller
00127 void SEPS225::init()
00128 {
00129 #if 0
00130    oled = new SPI(PIN_OLED_MOSI, PIN_OLED_MISO, PIN_OLED_SCLK) ;
00131     oled_cs = new DigitalOut(PIN_OLED_CS, 1) ;
00132     oled_rs = new DigitalOut(PIN_OLED_RS, 1) ;
00133     oled->format(8, 0) ;
00134     oled->frequency(1000000) ;
00135 #endif 
00136      
00137     reg_write(CMD_REDUCE_CURRENT, 0x01) ;
00138     thread_sleep_for(100) ; //    oled_delay(100000) ;
00139     reg_write(CMD_REDUCE_CURRENT, 0x00) ;
00140     thread_sleep_for(100) ; //    oled_delay(100000) ;
00141     
00142     reg_write(CMD_OSC_CTL, 0x01) ;
00143     reg_write(CMD_CLOCK_DIV, 0x30) ;
00144 //    reg_write(CMD_PRECHARGE_TIME_R, 0x03) ;
00145 //    reg_write(CMD_PRECHARGE_TIME_G, 0x04) ;
00146 //    reg_write(CMD_PRECHARGE_TIME_B, 0x05) ;
00147   reg_write(CMD_PRECHARGE_TIME_R, 0x0E) ;
00148   reg_write(CMD_PRECHARGE_TIME_G, 0x0E) ;
00149   reg_write(CMD_PRECHARGE_TIME_B, 0x0E) ;
00150 //    reg_write(CMD_PRECHARGE_CURRENT_R, 0x0B) ;
00151 //    reg_write(CMD_PRECHARGE_CURRENT_G, 0x0B) ;
00152 //    reg_write(CMD_PRECHARGE_CURRENT_B, 0x0B) ;
00153     reg_write(CMD_PRECHARGE_CURRENT_R, 0x3E) ;
00154     reg_write(CMD_PRECHARGE_CURRENT_G, 0x32) ;
00155     reg_write(CMD_PRECHARGE_CURRENT_B, 0x3D) ;
00156   reg_write(CMD_DRIVING_CURRENT_R, 0x3E) ;
00157   reg_write(CMD_DRIVING_CURRENT_G, 0x32) ;
00158   reg_write(CMD_DRIVING_CURRENT_B, 0x3D) ;
00159 //    reg_write(CMD_DRIVING_CURRENT_R, 0x0B) ;
00160 //    reg_write(CMD_DRIVING_CURRENT_G, 0x0B) ;
00161 //    reg_write(CMD_DRIVING_CURRENT_B, 0x0B) ;
00162     // Memory Write Mode
00163     // 16bit * 1 transfer mode, R[5], G[6], B[5]
00164     // H:Inc, V:Inc, Method:V
00165 //    reg_write(CMD_MEMORY_WRITE_MODE, 0x27) ;
00166     reg_write(CMD_RGB_IF, 0x11) ;
00167 //    reg_write(CMD_MEMORY_WRITE_MODE, 0x66) ;
00168     reg_write(CMD_MEMORY_WRITE_MODE, 0x26) ;
00169     reg_write(CMD_IREF, 0x01) ; // Voltage ctrl by internal
00170     // 
00171     reg_write(CMD_MX1_ADDR, 0x00) ;
00172     reg_write(CMD_MX2_ADDR, 0x7F) ;
00173     reg_write(CMD_MY1_ADDR, 0x00) ;
00174     reg_write(CMD_MY2_ADDR, 0x7F) ;
00175     reg_write(CMD_SCR1_FX1, 0x00) ;
00176     reg_write(CMD_SCR1_FX2, 0x7F) ;
00177     reg_write(CMD_SCR1_FY1, 0x00) ;
00178     reg_write(CMD_SCR1_FY2, 0x7F) ;
00179     reg_write(CMD_DSL, 0x00) ; // display start line
00180     reg_write(CMD_DUTY, 0x7F) ; //
00181     reg_write(CMD_DISPLAY_MODE_SET, 0x04) ; // was 0x00
00182 //    reg_write(CMD_DISPLAY_MODE_SET, 0x00) ; // was 0x00
00183     reg_write(CMD_D1_DDRAM_FAC, 0x00) ;
00184     reg_write(CMD_D1_DDRAM_FAR, 0x00) ;
00185     // Clear
00186     // oled_lcd_clear() ;
00187     cls() ;
00188     
00189     // DISP_ON_OFF
00190 //  reg_write(CMD_DISP_ON_OFF, 0x01) ;
00191 }
00192 
00193 /** Draw a pixel in the specified color.
00194 * @param x is the horizontal offset to this pixel.
00195 * @param y is the vertical offset to this pixel.
00196 * @param color defines the color for the pixel.
00197 */
00198 void SEPS225::pixel(int x, int y, unsigned short color)
00199 {
00200     unsigned char data[2] ;
00201     data[0] = (unsigned char)((color & 0xFF00) >> 8) ;
00202     data[1] = (unsigned char)(color & 0x00FF) ;
00203   
00204     reg_write(CMD_MEMORY_ACCESS_POINTER_X, x) ;
00205     reg_write(CMD_MEMORY_ACCESS_POINTER_Y, y) ;
00206     *_cs = 0 ;
00207     *_rs = 0 ;
00208     wr_cmd8(CMD_DDRAM_DATA_ACCESS_PORT) ;
00209     *_rs = 1 ;  
00210 
00211     wr_data8(data[0]) ;
00212     wr_data8(data[1]) ;
00213     *_cs = 1 ;
00214 }
00215 
00216 void SEPS225::window(int x, int y, int w, int h)
00217 {
00218     reg_write(CMD_MX1_ADDR, x) ;
00219     reg_write(CMD_MX2_ADDR, x+w-1) ;
00220     reg_write(CMD_MY1_ADDR, y) ;
00221     reg_write(CMD_MY2_ADDR, y+h-1) ;
00222     reg_write(CMD_MEMORY_ACCESS_POINTER_X, x) ;
00223     reg_write(CMD_MEMORY_ACCESS_POINTER_Y, y) ;
00224 }
00225 
00226 void SEPS225::cls(void)
00227 {
00228     window(0, 0, OLED_WIDTH, OLED_HEIGHT) ;
00229     reg_write(CMD_MEMORY_ACCESS_POINTER_X, 0) ;
00230     reg_write(CMD_MEMORY_ACCESS_POINTER_Y, 0) ;
00231     *_cs = 0 ;
00232     *_rs = 0 ;  
00233     wr_cmd8(CMD_DDRAM_DATA_ACCESS_PORT) ;
00234     *_rs = 1 ;
00235     for (int i = 0 ; i < OLED_WIDTH * OLED_HEIGHT ; i++ ) {
00236         write16(COLOR_BLACK) ;
00237     }
00238     *_cs = 1 ;
00239 }
00240 
00241 unsigned short SEPS225::pixelread(int x, int y)
00242 {
00243     unsigned short value = 0x0000 ;
00244     //printf("SEPS225::pixelread not implemented\n\r") ;
00245     return(value) ;
00246 }
00247 
00248 void SEPS225::rect(int x0, int y0, int x1, int y1, unsigned short color)
00249 {
00250     int interval = 10 ;
00251 //    window(x0, y0, x1-x0+1, y1-y0+1) ;
00252     *_cs = 0 ;
00253     thread_sleep_for(interval) ;
00254     line(x0, y0, x1, y0, color) ;
00255     *_cs = 1 ;
00256     thread_sleep_for(interval) ;  
00257     *_cs = 0 ;
00258     line(x1, y0, x1, y1, color) ;
00259     *_cs = 1 ;
00260     thread_sleep_for(interval) ;
00261     *_cs = 0 ;
00262     line(x0, y0, x0, y1, color) ;
00263     *_cs = 1 ;
00264     thread_sleep_for(interval) ;
00265     *_cs = 0 ;
00266     line(x0, y1, x1, y1, color) ;
00267     thread_sleep_for(interval) ;
00268     *_cs = 1 ;
00269 //    *_cs = 1 ;
00270 }
00271     
00272 void SEPS225::window4read(int x, int y, int w, int h)
00273 {
00274     //printf("SEPS225::window4read not implemented\n\r") ;
00275 }
00276 
00277 void SEPS225::window_pushpixel(unsigned short color)
00278 {
00279     //printf("SEPS225::window_pushpixel(unsigned short color) not implemented\n\r") ;
00280     *_cs = 0 ;
00281     *_rs = 0 ;
00282      wr_cmd8(CMD_DDRAM_DATA_ACCESS_PORT) ;
00283     *_rs = 1 ;
00284     wr_data16(color) ;
00285 //    write16(color) ;
00286     *_cs = 1 ;
00287 }
00288 
00289 void SEPS225::window_pushpixel(unsigned short color, unsigned int count)
00290 {
00291     //printf("SEPS225::window_pushpixel(unsigned short color, unsigned int count) not implemented\n\r") ;
00292     *_cs = 0 ;
00293     *_rs = 0 ;
00294      wr_cmd8(CMD_DDRAM_DATA_ACCESS_PORT) ;
00295     *_rs = 1 ;
00296     for (unsigned int i = 0 ; i < count ; i++ ) {
00297  //       write16(color) ;
00298         wr_data16(color) ;
00299     }
00300     *_cs = 1 ;
00301 }
00302 
00303 void SEPS225::window_pushpixelbuf(unsigned short* color, unsigned int lenght)
00304 {
00305     //printf("SEPS225::window_pushpixelbuf(unsigned short color, unsigned int length) not implemented\n\r") ;
00306     *_cs = 0 ;
00307     *_rs = 0 ;
00308      wr_cmd8(CMD_DDRAM_DATA_ACCESS_PORT) ;
00309     *_rs = 1 ;
00310     for (unsigned int i = 0 ; i < lenght ; i++ ) {
00311   //      write16(color[i]) ;
00312         wr_data16(color[i]) ;
00313     }
00314     *_cs = 1 ;
00315 }
00316 
00317 void SEPS225::reg_write(unsigned char cmd, unsigned char data)
00318 {
00319    *_cs = 0 ;
00320    *_rs = 0 ;
00321     wr_cmd8(cmd) ;
00322     *_rs = 1 ;
00323     wr_data8(data) ;
00324     *_cs = 1 ;
00325 }
00326     
00327 void SEPS225::display(int onoff) 
00328 {
00329     reg_write(CMD_DISP_ON_OFF, onoff) ;
00330 } 
00331 
00332 void SEPS225::cmd_write(unsigned char cmd) 
00333 {
00334     *_cs = 0 ;
00335     *_rs = 0 ;
00336     wr_cmd8(cmd) ;
00337     *_rs = 1 ;
00338     *_cs = 1 ;
00339 }
00340 
00341 void SEPS225::data_write(unsigned char data)
00342 {
00343     *_cs = 0 ;
00344     wr_data8(data) ;
00345     *_cs = 1 ;
00346 }
00347 
00348 void SEPS225::write8(unsigned char data)
00349 {
00350     wr_data8(data) ;
00351 }
00352 
00353 void SEPS225::write16(unsigned short sdata)
00354 {
00355     wr_data8((sdata >> 8)&0xFF) ;
00356     wr_data8(sdata & 0xFF) ;
00357 }
00358 
00359 void SEPS225::bufwrite8(unsigned char *data, unsigned long len) 
00360 {
00361     unsigned long i;
00362     for (i = 0 ; i < len ; i++ ) {
00363         wr_data8(data[i]) ;
00364     }
00365 }
00366 
00367 void SEPS225::bufwrite16(unsigned short *sdata, unsigned long len)
00368 {
00369     unsigned long i ;
00370     for (i = 0 ; i < len ; i++) {
00371         write8((*sdata >> 8)&0xFF) ;
00372         write8(*sdata & 0xFF) ;
00373     }
00374 }