This is the final version of Mini Gateway for Automation and Security desgined for Renesas GR Peach Design Contest

Dependencies:   GR-PEACH_video GraphicsFramework HTTPServer R_BSP mbed-rpc mbed-rtos Socket lwip-eth lwip-sys lwip FATFileSystem

Fork of mbed-os-example-mbed5-blinky by mbed-os-examples

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) ;  wait(0.01) ; //    oled_delay(100000) ;
00138     reg_write(CMD_REDUCE_CURRENT, 0x00) ;  wait(0.01) ; //    oled_delay(100000) ;
00139     
00140     reg_write(CMD_OSC_CTL, 0x01) ;
00141     reg_write(CMD_CLOCK_DIV, 0x30) ;
00142 //    reg_write(CMD_PRECHARGE_TIME_R, 0x03) ;
00143 //    reg_write(CMD_PRECHARGE_TIME_G, 0x04) ;
00144 //    reg_write(CMD_PRECHARGE_TIME_B, 0x05) ;
00145   reg_write(CMD_PRECHARGE_TIME_R, 0x0E) ;
00146   reg_write(CMD_PRECHARGE_TIME_G, 0x0E) ;
00147   reg_write(CMD_PRECHARGE_TIME_B, 0x0E) ;
00148 //    reg_write(CMD_PRECHARGE_CURRENT_R, 0x0B) ;
00149 //    reg_write(CMD_PRECHARGE_CURRENT_G, 0x0B) ;
00150 //    reg_write(CMD_PRECHARGE_CURRENT_B, 0x0B) ;
00151     reg_write(CMD_PRECHARGE_CURRENT_R, 0x3E) ;
00152     reg_write(CMD_PRECHARGE_CURRENT_G, 0x32) ;
00153     reg_write(CMD_PRECHARGE_CURRENT_B, 0x3D) ;
00154   reg_write(CMD_DRIVING_CURRENT_R, 0x3E) ;
00155   reg_write(CMD_DRIVING_CURRENT_G, 0x32) ;
00156   reg_write(CMD_DRIVING_CURRENT_B, 0x3D) ;
00157 //    reg_write(CMD_DRIVING_CURRENT_R, 0x0B) ;
00158 //    reg_write(CMD_DRIVING_CURRENT_G, 0x0B) ;
00159 //    reg_write(CMD_DRIVING_CURRENT_B, 0x0B) ;
00160     // Memory Write Mode
00161     // 16bit * 1 transfer mode, R[5], G[6], B[5]
00162     // H:Inc, V:Inc, Method:V
00163 //    reg_write(CMD_MEMORY_WRITE_MODE, 0x27) ;
00164     reg_write(CMD_RGB_IF, 0x11) ;
00165 //    reg_write(CMD_MEMORY_WRITE_MODE, 0x66) ;
00166     reg_write(CMD_MEMORY_WRITE_MODE, 0x26) ;
00167     reg_write(CMD_IREF, 0x01) ; // Voltage ctrl by internal
00168     // 
00169     reg_write(CMD_MX1_ADDR, 0x00) ;
00170     reg_write(CMD_MX2_ADDR, 0x7F) ;
00171     reg_write(CMD_MY1_ADDR, 0x00) ;
00172     reg_write(CMD_MY2_ADDR, 0x7F) ;
00173     reg_write(CMD_SCR1_FX1, 0x00) ;
00174     reg_write(CMD_SCR1_FX2, 0x7F) ;
00175     reg_write(CMD_SCR1_FY1, 0x00) ;
00176     reg_write(CMD_SCR1_FY2, 0x7F) ;
00177     reg_write(CMD_DSL, 0x00) ; // display start line
00178     reg_write(CMD_DUTY, 0x7F) ; //
00179     reg_write(CMD_DISPLAY_MODE_SET, 0x04) ; // was 0x00
00180 //    reg_write(CMD_DISPLAY_MODE_SET, 0x00) ; // was 0x00
00181     reg_write(CMD_D1_DDRAM_FAC, 0x00) ;
00182     reg_write(CMD_D1_DDRAM_FAR, 0x00) ;
00183     // Clear
00184     // oled_lcd_clear() ;
00185     cls() ;
00186     
00187     // DISP_ON_OFF
00188 //  reg_write(CMD_DISP_ON_OFF, 0x01) ;
00189 }
00190 
00191 /** Draw a pixel in the specified color.
00192 * @param x is the horizontal offset to this pixel.
00193 * @param y is the vertical offset to this pixel.
00194 * @param color defines the color for the pixel.
00195 */
00196 void SEPS225::pixel(int x, int y, unsigned short color)
00197 {
00198     unsigned char data[2] ;
00199     data[0] = (unsigned char)((color & 0xFF00) >> 8) ;
00200     data[1] = (unsigned char)(color & 0x00FF) ;
00201   
00202     reg_write(CMD_MEMORY_ACCESS_POINTER_X, x) ;
00203     reg_write(CMD_MEMORY_ACCESS_POINTER_Y, y) ;
00204     *_cs = 0 ;
00205     *_rs = 0 ;
00206     wr_cmd8(CMD_DDRAM_DATA_ACCESS_PORT) ;
00207     *_rs = 1 ;  
00208 
00209     wr_data8(data[0]) ;
00210     wr_data8(data[1]) ;
00211     *_cs = 1 ;
00212 }
00213 
00214 void SEPS225::window(int x, int y, int w, int h)
00215 {
00216     reg_write(CMD_MX1_ADDR, x) ;
00217     reg_write(CMD_MX2_ADDR, x+w-1) ;
00218     reg_write(CMD_MY1_ADDR, y) ;
00219     reg_write(CMD_MY2_ADDR, y+h-1) ;
00220     reg_write(CMD_MEMORY_ACCESS_POINTER_X, x) ;
00221     reg_write(CMD_MEMORY_ACCESS_POINTER_Y, y) ;
00222 }
00223 
00224 void SEPS225::cls(void)
00225 {
00226     window(0, 0, OLED_WIDTH, OLED_HEIGHT) ;
00227     reg_write(CMD_MEMORY_ACCESS_POINTER_X, 0) ;
00228     reg_write(CMD_MEMORY_ACCESS_POINTER_Y, 0) ;
00229     *_cs = 0 ;
00230     *_rs = 0 ;  
00231     wr_cmd8(CMD_DDRAM_DATA_ACCESS_PORT) ;
00232     *_rs = 1 ;
00233     for (int i = 0 ; i < OLED_WIDTH * OLED_HEIGHT ; i++ ) {
00234         write16(COLOR_BLACK) ;
00235     }
00236     *_cs = 1 ;
00237 }
00238 
00239 unsigned short SEPS225::pixelread(int x, int y)
00240 {
00241     unsigned short value = 0x0000 ;
00242     //printf("SEPS225::pixelread not implemented\n\r") ;
00243     return(value) ;
00244 }
00245 
00246 void SEPS225::rect(int x0, int y0, int x1, int y1, unsigned short color)
00247 {
00248     float interval = 0.01 ;
00249 //    window(x0, y0, x1-x0+1, y1-y0+1) ;
00250     *_cs = 0 ;
00251     wait(interval) ;
00252     line(x0, y0, x1, y0, color) ;
00253     *_cs = 1 ;
00254     wait(interval) ;  
00255     *_cs = 0 ;
00256     line(x1, y0, x1, y1, color) ;
00257     *_cs = 1 ;
00258     wait(interval) ;
00259     *_cs = 0 ;
00260     line(x0, y0, x0, y1, color) ;
00261     *_cs = 1 ;
00262     wait(interval) ;
00263     *_cs = 0 ;
00264     line(x0, y1, x1, y1, color) ;
00265     wait(interval) ;
00266     *_cs = 1 ;
00267 //    *_cs = 1 ;
00268 }
00269     
00270 void SEPS225::window4read(int x, int y, int w, int h)
00271 {
00272     //printf("SEPS225::window4read not implemented\n\r") ;
00273 }
00274 
00275 void SEPS225::window_pushpixel(unsigned short color)
00276 {
00277     //printf("SEPS225::window_pushpixel(unsigned short color) not implemented\n\r") ;
00278     *_cs = 0 ;
00279     *_rs = 0 ;
00280      wr_cmd8(CMD_DDRAM_DATA_ACCESS_PORT) ;
00281     *_rs = 1 ;
00282     wr_data16(color) ;
00283 //    write16(color) ;
00284     *_cs = 1 ;
00285 }
00286 
00287 void SEPS225::window_pushpixel(unsigned short color, unsigned int count)
00288 {
00289     //printf("SEPS225::window_pushpixel(unsigned short color, unsigned int count) not implemented\n\r") ;
00290     *_cs = 0 ;
00291     *_rs = 0 ;
00292      wr_cmd8(CMD_DDRAM_DATA_ACCESS_PORT) ;
00293     *_rs = 1 ;
00294     for (unsigned int i = 0 ; i < count ; i++ ) {
00295  //       write16(color) ;
00296         wr_data16(color) ;
00297     }
00298     *_cs = 1 ;
00299 }
00300 
00301 void SEPS225::window_pushpixelbuf(unsigned short* color, unsigned int lenght)
00302 {
00303     //printf("SEPS225::window_pushpixelbuf(unsigned short color, unsigned int length) not implemented\n\r") ;
00304     *_cs = 0 ;
00305     *_rs = 0 ;
00306      wr_cmd8(CMD_DDRAM_DATA_ACCESS_PORT) ;
00307     *_rs = 1 ;
00308     for (unsigned int i = 0 ; i < lenght ; i++ ) {
00309   //      write16(color[i]) ;
00310         wr_data16(color[i]) ;
00311     }
00312     *_cs = 1 ;
00313 }
00314 
00315 void SEPS225::reg_write(unsigned char cmd, unsigned char data)
00316 {
00317    *_cs = 0 ;
00318    *_rs = 0 ;
00319     wr_cmd8(cmd) ;
00320     *_rs = 1 ;
00321     wr_data8(data) ;
00322     *_cs = 1 ;
00323 }
00324     
00325 void SEPS225::display(int onoff) 
00326 {
00327     reg_write(CMD_DISP_ON_OFF, onoff) ;
00328 } 
00329 
00330 void SEPS225::cmd_write(unsigned char cmd) 
00331 {
00332     *_cs = 0 ;
00333     *_rs = 0 ;
00334     wr_cmd8(cmd) ;
00335     *_rs = 1 ;
00336     *_cs = 1 ;
00337 }
00338 
00339 void SEPS225::data_write(unsigned char data)
00340 {
00341     *_cs = 0 ;
00342     wr_data8(data) ;
00343     *_cs = 1 ;
00344 }
00345 
00346 void SEPS225::write8(unsigned char data)
00347 {
00348     wr_data8(data) ;
00349 }
00350 
00351 void SEPS225::write16(unsigned short sdata)
00352 {
00353     wr_data8((sdata >> 8)&0xFF) ;
00354     wr_data8(sdata & 0xFF) ;
00355 }
00356 
00357 void SEPS225::bufwrite8(unsigned char *data, unsigned long len) 
00358 {
00359     unsigned long i;
00360     for (i = 0 ; i < len ; i++ ) {
00361         wr_data8(data[i]) ;
00362     }
00363 }
00364 
00365 void SEPS225::bufwrite16(unsigned short *sdata, unsigned long len)
00366 {
00367     unsigned long i ;
00368     for (i = 0 ; i < len ; i++) {
00369         write8((*sdata >> 8)&0xFF) ;
00370         write8(*sdata & 0xFF) ;
00371     }
00372 }