lib/unigraphic/SSD1322.cpp

changeset 66
48f29a1d43d6
parent 45
2da50a3d4e9f
equal deleted inserted replaced
65:d9c5eaf85fab 66:48f29a1d43d6
96 96
97 SSD1322::SSD1322(int Hz, PinName mosi, PinName miso, PinName sclk, PinName CS, PinName reset, PinName DC, 97 SSD1322::SSD1322(int Hz, PinName mosi, PinName miso, PinName sclk, PinName CS, PinName reset, PinName DC,
98 const char *name) 98 const char *name)
99 : GraphicsDisplay(name), 99 : GraphicsDisplay(name),
100 screensize_X(DISPLAY_WIDTH), screensize_Y(DISPLAY_HEIGHT), 100 screensize_X(DISPLAY_WIDTH), screensize_Y(DISPLAY_HEIGHT),
101 _BPP(BPP), _PAGES(DISPLAY_HEIGHT/8*BPP), 101 _PAGES(DISPLAY_HEIGHT/8*BPP), _BPP(BPP),
102 _IC_X_SEGS(IC_X_SEGS), _IC_Y_COMS(IC_Y_COMS), _IC_PAGES(IC_Y_COMS/8*BPP), 102 _IC_X_SEGS(IC_X_SEGS), _IC_Y_COMS(IC_Y_COMS), _IC_PAGES(IC_Y_COMS/8*BPP),
103 _spi(mosi, miso, sclk), 103 _spi(mosi, miso, sclk),
104 _DC(DC), _CS(CS), _RST(reset) 104 _DC(DC), _CS(CS), _RST(reset)
105 { 105 {
106 _RST = 1; 106 _RST = 1;
136 136
137 } 137 }
138 138
139 void SSD1322::hw_reset() 139 void SSD1322::hw_reset()
140 { 140 {
141 ThisThread::sleep_for(15); 141 ThisThread::sleep_for(15ms);
142 _DC = 1; 142 _DC = 1;
143 _CS = 1; 143 _CS = 1;
144 _RST = 0; // display reset 144 _RST = 0; // display reset
145 ThisThread::sleep_for(2); 145 ThisThread::sleep_for(2ms);
146 _RST = 1; // end reset 146 _RST = 1; // end reset
147 ThisThread::sleep_for(100); 147 ThisThread::sleep_for(100ms);
148 } 148 }
149 149
150 void SSD1322::bus_enable(bool enable) 150 void SSD1322::bus_enable(bool enable)
151 { 151 {
152 _CS = enable ? 0:1; 152 _CS = enable ? 0:1;
186 // Horizontal address increment, 186 // Horizontal address increment,
187 // Disable Column Address Re-map, 187 // Disable Column Address Re-map,
188 // Enable Nibble Re-map,Scan from COM[N-1] to COM0, 188 // Enable Nibble Re-map,Scan from COM[N-1] to COM0,
189 // Disable COM Split Odd Even 189 // Disable COM Split Odd Even
190 // Enable Dual COM mode 190 // Enable Dual COM mode
191 unsigned char d; 191 unsigned char d = 0;
192 switch (mode) 192 switch (mode)
193 { 193 {
194 case(NONE): 194 case(NONE):
195 d = 0x14; 195 d = 0x14;
196 break; 196 break;
322 if(!(orientation&1)) SWAP(x,y); 322 if(!(orientation&1)) SWAP(x,y);
323 // first check parameter 323 // first check parameter
324 if((x >= screensize_X) || (y >= screensize_Y)) return 0; 324 if((x >= screensize_X) || (y >= screensize_Y)) return 0;
325 325
326 unsigned short page = y * _BPP / 8; 326 unsigned short page = y * _BPP / 8;
327 /* to be used in correct implementation...
327 unsigned char pos = y & ((8 / _BPP) - 1); // position in page 328 unsigned char pos = y & ((8 / _BPP) - 1); // position in page
328 unsigned char mask = (( 1 << _BPP) - 1); 329 unsigned char mask = (( 1 << _BPP) - 1);
329 330 */
330 //FAUX 331 //FAUX
331 return (_pixelBuffer[(x + page*screensize_X)]); // = (_pixelBuffer[(x + page*screensize_X)] & ~(mask<<(pos*_BPP))) | ((color&mask)<<(pos*_BPP)); 332 return (_pixelBuffer[(x + page*screensize_X)]); // = (_pixelBuffer[(x + page*screensize_X)] & ~(mask<<(pos*_BPP))) | ((color&mask)<<(pos*_BPP));
332 } 333 }
333 334
334 335
353 wr_data8(end_col); 354 wr_data8(end_col);
354 } 355 }
355 356
356 void SSD1322::copy_to_lcd(void) 357 void SSD1322::copy_to_lcd(void)
357 { 358 {
358 unsigned int x, y;
359 unsigned int i;
360
361 pixel_buffer_mutex.lock(); 359 pixel_buffer_mutex.lock();
362 memcpy((void*)_trBuffer, 360 memcpy((void*)_trBuffer,
363 (const void*)_pixelBuffer, 361 (const void*)_pixelBuffer,
364 DISPLAY_BUFFER_ELEMENTS * sizeof(DISPLAY_BUFFER_TYPE)); 362 DISPLAY_BUFFER_ELEMENTS * sizeof(DISPLAY_BUFFER_TYPE));
365 pixel_buffer_mutex.unlock(); 363 pixel_buffer_mutex.unlock();
370 368
371 #ifdef DEVICE_SPI_ASYNCH 369 #ifdef DEVICE_SPI_ASYNCH
372 _CS = 0; 370 _CS = 0;
373 _spi.transfer((uint8_t*) _trBuffer, 64*128, (uint8_t*) NULL, 0, _spiEventCb); 371 _spi.transfer((uint8_t*) _trBuffer, 64*128, (uint8_t*) NULL, 0, _spiEventCb);
374 #else 372 #else
373 unsigned int x, y;
374 unsigned int i;
375
375 i = 0; 376 i = 0;
376 for(y=0; y<64; y++) 377 for(y=0; y<64; y++)
377 for(x=0; x<128; x++) 378 for(x=0; x<128; x++)
378 wr_data8(_trBuffer[i++]); 379 wr_data8(_trBuffer[i++]);
379 #endif 380 #endif

mercurial