Dmitry Dzhafarkhanov / Adafruit_GFX_SEPS114A
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Adafruit_SEPS114A.cpp Source File

Adafruit_SEPS114A.cpp

00001 
00002 
00003 #include "mbed.h"
00004 #include "Adafruit_SEPS114A.h"
00005 
00006 
00007 #define SEPS114A_SOFT_RESET 0x01
00008 #define SEPS114A_DISPLAY_ON_OFF 0x02
00009 #define SEPS114A_ANALOG_CONTROL 0x0F    //
00010 #define SEPS114A_STANDBY_ON_OFF 0x14
00011 #define SEPS114A_OSC_ADJUST 0x1A
00012 #define SEPS114A_ROW_SCAN_DIRECTION 0x09
00013 #define SEPS114A_DISPLAY_X1 0x30
00014 #define SEPS114A_DISPLAY_X2 0x31
00015 #define SEPS114A_DISPLAY_Y1 0x32
00016 #define SEPS114A_DISPLAY_Y2 0x33
00017 #define SEPS114A_DISPLAYSTART_X 0x38
00018 #define SEPS114A_DISPLAYSTART_Y 0x39
00019 #define SEPS114A_CPU_IF 0x0D
00020 #define SEPS114A_MEM_X1 0x34
00021 #define SEPS114A_MEM_X2 0x35
00022 #define SEPS114A_MEM_Y1 0x36
00023 #define SEPS114A_MEM_Y2 0x37
00024 #define SEPS114A_MEMORY_WRITE_READ 0x1D
00025 #define SEPS114A_DDRAM_DATA_ACCESS_PORT 0x08
00026 #define SEPS114A_DISCHARGE_TIME 0x18
00027 #define SEPS114A_PEAK_PULSE_DELAY 0x16
00028 #define SEPS114A_PEAK_PULSE_WIDTH_R 0x3A
00029 #define SEPS114A_PEAK_PULSE_WIDTH_G 0x3B
00030 #define SEPS114A_PEAK_PULSE_WIDTH_B 0x3C
00031 #define SEPS114A_PRECHARGE_CURRENT_R 0x3D
00032 #define SEPS114A_PRECHARGE_CURRENT_G 0x3E
00033 #define SEPS114A_PRECHARGE_CURRENT_B 0x3F
00034 #define SEPS114A_COLUMN_CURRENT_R 0x40
00035 #define SEPS114A_COLUMN_CURRENT_G 0x41
00036 #define SEPS114A_COLUMN_CURRENT_B 0x42
00037 #define SEPS114A_ROW_OVERLAP 0x48
00038 #define SEPS114A_SCAN_OFF_LEVEL 0x49
00039 #define SEPS114A_ROW_SCAN_ON_OFF 0x17
00040 #define SEPS114A_ROW_SCAN_MODE 0x13
00041 #define SEPS114A_SCREEN_SAVER_CONTEROL 0xD0
00042 #define SEPS114A_SS_SLEEP_TIMER 0xD1
00043 #define SEPS114A_SCREEN_SAVER_MODE 0xD2
00044 #define SEPS114A_SS_UPDATE_TIMER 0xD3
00045 #define SEPS114A_RGB_IF 0xE0
00046 #define SEPS114A_RGB_POL 0xE1
00047 #define SEPS114A_DISPLAY_MODE_CONTROL 0xE5
00048 
00049 
00050 
00051 void Adafruit_SEPS114A::set_region(int x, int y, int xs, int ys)
00052 {
00053   // draw region
00054   writeCommand(SEPS114A_MEM_X1,x);
00055   writeCommand(SEPS114A_MEM_X2,x+xs-1);
00056   writeCommand(SEPS114A_MEM_Y1,y);
00057   writeCommand(SEPS114A_MEM_Y2,y+ys-1);
00058   // start position
00059    writeCommand(SEPS114A_DISPLAYSTART_X,x);
00060    writeCommand(SEPS114A_DISPLAYSTART_Y,y); 
00061 }
00062 
00063 void Adafruit_SEPS114A::begin(void)//oled init
00064 {
00065   
00066  
00067     rst = 0;
00068     // wait 10ms
00069     wait_ms(10);
00070     // bring out of reset
00071     rst = 1;
00072     // turn on VCC (13V?)
00073     wait_ms(10);
00074                     /*  Soft reser */
00075                    writeCommand(SEPS114A_SOFT_RESET,0x00);      
00076                    /* Standby ON/OFF*/
00077                    writeCommand(SEPS114A_STANDBY_ON_OFF,0x01);          // Standby on
00078                    wait_ms(5);                                           // Wait for 5ms (1ms Delay Minimum)
00079                    writeCommand(SEPS114A_STANDBY_ON_OFF,0x00);          // Standby off
00080                    wait_ms(5);                                           // 1ms Delay Minimum (1ms Delay Minimum)
00081                    /* Display OFF */
00082                    writeCommand(SEPS114A_DISPLAY_ON_OFF,0x00);
00083                    /* Set Oscillator operation */
00084                    writeCommand(SEPS114A_ANALOG_CONTROL,0x40);          // using external resistor and internal OSC
00085                    /* Set frame rate */
00086                    writeCommand(SEPS114A_OSC_ADJUST,0x03);              // frame rate : 95Hz
00087              
00088                    /* Select the RGB data format and set the initial state of RGB interface port */
00089                   writeCommand(SEPS114A_RGB_IF,0x00);                 //0xE0   RGB 8bit interface
00090                    /* Set RGB polarity */
00091                    writeCommand(SEPS114A_RGB_POL,0x00);
00092                    /* Set display mode control */
00093                    writeCommand(SEPS114A_DISPLAY_MODE_CONTROL,0x80);   // SWAP:BGR, Reduce current : Normal, DC[1:0] : Normal
00094                   
00095                    /* Set MCU Interface */
00096                    writeCommand(SEPS114A_CPU_IF,0x00);                 // MPU External interface mode, 8bits
00097                    /* Set Memory Read/Write mode */
00098                    writeCommand(SEPS114A_MEMORY_WRITE_READ,0x00);
00099                    /* Set row scan direction */
00100                   // writeCommand(SEPS114A_ROW_SCAN_DIRECTION,0x00);     // Column : 0 --> Max, Row : 0 Ѓ--> Max
00101                     writeCommand(SEPS114A_ROW_SCAN_DIRECTION,0x02);     // Column : 0 --> Max, Row : 0 Ѓ--> Max
00102                    /* Set row scan mode */
00103                    writeCommand(SEPS114A_ROW_SCAN_MODE,0x00);          // Alternate scan mode
00104                    /* Set column current */
00105                                 
00106                   // writeCommand(SEPS114A_COLUMN_CURRENT_R,0x32);
00107                   // writeCommand(SEPS114A_COLUMN_CURRENT_G,0x31);
00108                   // writeCommand(SEPS114A_COLUMN_CURRENT_B,0x31);
00109                   writeCommand(SEPS114A_COLUMN_CURRENT_R,0x6E);
00110                   writeCommand(SEPS114A_COLUMN_CURRENT_G,0x4F);
00111                   writeCommand(SEPS114A_COLUMN_CURRENT_B,0x77);
00112                   
00113                    /* Set row overlap */
00114                    writeCommand(SEPS114A_ROW_OVERLAP,0x00);            // Band gap only
00115                    /* Set discharge time */
00116                    writeCommand(SEPS114A_DISCHARGE_TIME,0x01);         // Discharge time : normal discharge
00117                    /* Set peak pulse delay */
00118                    writeCommand(SEPS114A_PEAK_PULSE_DELAY,0x00);
00119                    /* Set peak pulse width */
00120                    writeCommand(SEPS114A_PEAK_PULSE_WIDTH_R,0x02);
00121                    writeCommand(SEPS114A_PEAK_PULSE_WIDTH_G,0x02);
00122                    writeCommand(SEPS114A_PEAK_PULSE_WIDTH_B,0x02);
00123                    /* Set precharge current */
00124                    
00125                    writeCommand(SEPS114A_PRECHARGE_CURRENT_R,0x14);
00126                    writeCommand(SEPS114A_PRECHARGE_CURRENT_G,0x50);
00127                    writeCommand(SEPS114A_PRECHARGE_CURRENT_B,0x19);
00128                    
00129                           
00130                    /* Set row scan on/off  */
00131                    writeCommand(SEPS114A_ROW_SCAN_ON_OFF,0x00);        // Normal row scan
00132                    /* Set scan off level */
00133                    writeCommand(SEPS114A_SCAN_OFF_LEVEL,0x04);         // VCC_C*0.75 //0x04
00134                   
00135                    writeCommand(SEPS114A_MEM_X1,0x00);
00136                    writeCommand(SEPS114A_MEM_X2,0x5F);
00137                    writeCommand(SEPS114A_MEM_Y1,0x00);
00138                    writeCommand(SEPS114A_MEM_Y2,0x5F);                 
00139                    
00140                    /* Set memory access point */
00141                    
00142                    writeCommand(SEPS114A_DISPLAYSTART_X,0x00);
00143                    writeCommand(SEPS114A_DISPLAYSTART_Y,0x00);
00144                    
00145                   // set_region(0, 0, 96, 96); 
00146                          /* Set active display area of panel */
00147                    writeCommand(SEPS114A_DISPLAY_X1,0x00);
00148                    writeCommand(SEPS114A_DISPLAY_X2,0x5F);
00149                    writeCommand(SEPS114A_DISPLAY_Y1,0x00);
00150                    writeCommand(SEPS114A_DISPLAY_Y2,0x5F);
00151                    
00152                    /* Display ON */
00153                    writeCommand(SEPS114A_DISPLAY_ON_OFF,0x01);
00154 }
00155 
00156 
00157 
00158 //Set memory area(address) to write a display data
00159 void Adafruit_SEPS114A::MemorySize(uint8_t X1, uint8_t X2, uint8_t Y1, uint8_t Y2){
00160     writeCommand(SEPS114A_MEM_X1,X1);
00161     writeCommand(SEPS114A_MEM_X2,X2);
00162     writeCommand(SEPS114A_MEM_Y1,Y1);
00163     writeCommand(SEPS114A_MEM_Y2,Y2);
00164 }
00165 
00166 uint16_t Adafruit_SEPS114A::Color565(uint8_t r, uint8_t g, uint8_t b) {
00167   uint16_t c;
00168   c = r >> 3;
00169   c <<= 6;
00170   c |= g >> 2;
00171   c <<= 5;
00172   c |= b >> 3;
00173 
00174   return c;
00175 }
00176 
00177 
00178 // Set a single pixel
00179 void Adafruit_SEPS114A::drawPixel(int16_t x, int16_t y, uint16_t color)
00180 {
00181            if ((x < 0) || (x >= width()) || (y < 0) || (y >= height()))  // Bounds check.
00182         return;
00183     
00184     // check rotation, move pixel around if necessary
00185     switch (getRotation())
00186     {
00187         case 1:                             // Rotated 90 degrees clockwise.
00188             swap(x, y);
00189             x = _rawWidth - x - 1;
00190             break;
00191         case 2:                             // Rotated 180 degrees clockwise.
00192             x = _rawWidth - x - 1;
00193             y = _rawHeight - y - 1;
00194             break;
00195         case 3:                             // Rotated 270 degrees clockwise.
00196             swap(x, y);
00197             y = _rawHeight - y - 1;
00198             break;
00199     }  
00200     
00201     MemorySize( x,  1,  y,  1);
00202     DDRAM_access();
00203     writeData(color >> 8) ;
00204     writeData(color);   
00205 }
00206 
00207 
00208 void Adafruit_SEPS114A::clearDisplay()
00209 {
00210     int j;
00211     MemorySize(0x00,0x5F,0x00,0x5F);
00212     DDRAM_access();
00213     
00214     for(j=0;j<9216;j++){                        // 
00215                     writeData(Black >> 8) ;
00216                     writeData(Black);           
00217                        }
00218 }
00219 
00220  void Adafruit_SEPS114A::setContrastControl(int brightness)
00221 {
00222     int r, g, b;
00223         r = 2 + 16*brightness;
00224         g = 1 + 10*brightness;
00225         b = 1 + (23*brightness)/2;
00226         writeCommand(SEPS114A_COLUMN_CURRENT_R,r);
00227         writeCommand(SEPS114A_COLUMN_CURRENT_G,g);
00228         writeCommand(SEPS114A_COLUMN_CURRENT_B,b);
00229 }
00230   
00231 
00232 
00233 
00234 
00235 
00236 
00237