diff -r 5cf4034ba4e0 -r 55021f3f1929 lib/unigraphic/SSD1322.cpp --- a/lib/unigraphic/SSD1322.cpp Fri Sep 23 21:12:43 2016 +0200 +++ b/lib/unigraphic/SSD1322.cpp Tue Oct 11 00:14:20 2016 +0200 @@ -94,70 +94,65 @@ #define SWAP(a, b) { a ^= b; b ^= a; a ^= b; } -SSD1322::SSD1322(proto_t displayproto, - int Hz, PinName mosi, PinName miso, PinName sclk, PinName CS, PinName reset, PinName DC, - const char *name, - const unsigned int lcdsize_x, const unsigned int lcdsize_y) +SSD1322::SSD1322(int Hz, PinName mosi, PinName miso, PinName sclk, PinName CS, PinName reset, PinName DC, + const char *name) : GraphicsDisplay(name), - screensize_X(lcdsize_x), screensize_Y(lcdsize_y), - _BPP(BPP), _PAGES(lcdsize_y/8*BPP), - _IC_X_SEGS(IC_X_SEGS), _IC_Y_COMS(IC_Y_COMS), _IC_PAGES(IC_Y_COMS/8*BPP) + screensize_X(DISPLAY_WIDTH), screensize_Y(DISPLAY_HEIGHT), + _BPP(BPP), _PAGES(DISPLAY_HEIGHT/8*BPP), + _IC_X_SEGS(IC_X_SEGS), _IC_Y_COMS(IC_Y_COMS), _IC_PAGES(IC_Y_COMS/8*BPP), + _spi(mosi, miso, sclk), + _DC(DC), _CS(CS), _RST(reset) { - proto = new SPI8(Hz, mosi, miso, sclk, CS, reset, DC); - buffer = (unsigned char*) malloc (screensize_X*_PAGES); + _RST = 1; + _DC = 1; + _CS = 1; + _spi.format(8, 0); // 8 bit spi mode 0 + _spi.frequency(Hz); set_auto_up(false); foreground(0xFFFF); background(0x0000); hw_reset(); - bus_enable(true); init(); set_orientation(1); cls(); locate(0,0); -} - -SSD1322::~SSD1322() -{ - free(buffer); + //_internalEventCallback.attach(this, &SSD1322::_cbHandler); } void SSD1322::wr_cmd8(unsigned char cmd) { - proto->wr_cmd8(cmd); + _CS = 0; + _DC.write(0); // 0=cmd + _spi.write(cmd); // write 8bit + _DC.write(1); // 1=data next + _CS = 1; } void SSD1322::wr_data8(unsigned char data) { - proto->wr_data8(data); -} - -void SSD1322::wr_cmd16(unsigned short cmd) -{ - proto->wr_cmd16(cmd); -} + _CS = 0; + _spi.write(data); // write 8bit + _CS = 1; -void SSD1322::wr_gram(unsigned short data, unsigned int count) -{ - proto->wr_gram(data, count); -} - -void SSD1322::wr_grambuf(unsigned short* data, unsigned int lenght) -{ - proto->wr_grambuf(data, lenght); } void SSD1322::hw_reset() { - proto->hw_reset(); + wait_ms(15); + _DC = 1; + _CS = 1; + _RST = 0; // display reset + wait_ms(2); + _RST = 1; // end reset + wait_ms(100); } void SSD1322::bus_enable(bool enable) { - proto->BusEnable(enable); + _CS = enable ? 0:1; } - // monochrome SSD1322 driver ICs does not have ram rotate in hw (swap raw<->columns) like TFT displays // for portrait views, XY swap will be done in sw in pixel() function void SSD1322::set_orientation(int o) @@ -216,8 +211,8 @@ void SSD1322::invert(unsigned char o) { - if(o == 0) wr_cmd8(0xA6); - else wr_cmd8(0xA7); + if(o == 0) wr_cmd8(SSD1322_CMD_SET_DISPLAY_MODE_NORMAL); + else wr_cmd8(SSD1322_CMD_SET_DISPLAY_MODE_INVERSE); } void SSD1322::set_contrast(int o) @@ -243,48 +238,48 @@ win_y2 = y + h - 1; } void SSD1322::window_pushpixel(unsigned short color) { - pixel(cur_x, cur_y, color); - cur_x++; - if(cur_x > win_x2) { - cur_x = win_x1; - cur_y++; - if(cur_y > win_y2) { - cur_y = win_y1; - } + pixel(cur_x, cur_y, color); + cur_x++; + if(cur_x > win_x2) { + cur_x = win_x1; + cur_y++; + if(cur_y > win_y2) { + cur_y = win_y1; } + } } void SSD1322::window_pushpixel(unsigned short color, unsigned int count) { - while(count) + while(count) { - pixel(cur_x, cur_y, color); - cur_x++; - if(cur_x > win_x2) + pixel(cur_x, cur_y, color); + cur_x++; + if(cur_x > win_x2) { - cur_x = win_x1; - cur_y++; - if(cur_y > win_y2) + cur_x = win_x1; + cur_y++; + if(cur_y > win_y2) { - cur_y = win_y1; + cur_y = win_y1; } } - count--; + count--; } } void SSD1322::window_pushpixelbuf(unsigned short* color, unsigned int lenght) { - while(lenght) + while(lenght) { - pixel(cur_x, cur_y, *color++); - cur_x++; - if(cur_x > win_x2) + pixel(cur_x, cur_y, *color++); + cur_x++; + if(cur_x > win_x2) { - cur_x = win_x1; - cur_y++; - if(cur_y > win_y2) + cur_x = win_x1; + cur_y++; + if(cur_y > win_y2) { - cur_y = win_y1; + cur_y = win_y1; } } - lenght--; + lenght--; } } @@ -312,13 +307,13 @@ buffer[(x + page*screensize_X)] = (buffer[(x + page*screensize_X)] & ~(mask<<(pos*_BPP))) | ((color&mask)<<(pos*_BPP)); */ - unsigned char cval = buffer[(y*128) + x/2]; + unsigned char cval = _pixelBuffer[(y*128) + x/2]; if (x&1) { cval = (cval & 0xF0) | (color & 0x0F); } else { cval = (cval & 0x0F) | (color & 0x0F)<<4; } - buffer[(y*128) + x/2] = cval; + _pixelBuffer[(y*128) + x/2] = cval; } unsigned short SSD1322::pixelread(int x, int y) @@ -332,7 +327,7 @@ unsigned char mask = (( 1 << _BPP) - 1); //FAUX - return (buffer[(x + page*screensize_X)]); // = (buffer[(x + page*screensize_X)] & ~(mask<<(pos*_BPP))) | ((color&mask)<<(pos*_BPP)); + return (_pixelBuffer[(x + page*screensize_X)]); // = (_pixelBuffer[(x + page*screensize_X)] & ~(mask<<(pos*_BPP))) | ((color&mask)<<(pos*_BPP)); } @@ -359,107 +354,69 @@ void SSD1322::copy_to_lcd(void) { + unsigned int x, y; unsigned int i; - unsigned char x, y; - set_row_address(0); set_column_address(0); + memcpy((void*)_trBuffer, + (const void*)_pixelBuffer, + DISPLAY_BUFFER_ELEMENTS * sizeof(DISPLAY_BUFFER_TYPE)); + wr_cmd8(SSD1322_CMD_WRITE_RAM); + i = 0; - wr_cmd8(SSD1322_CMD_WRITE_RAM); for(y=0; y<64; y++) for(x=0; x<128; x++) - wr_data8(buffer[i++]); + wr_data8(_trBuffer[i++]); } void SSD1322::copy_to_lcd(unsigned char from_col, unsigned char to_col, unsigned char from_row, unsigned char to_row) { - unsigned char x, y; - + unsigned int x, y; if (to_col>0x3F) to_col = 0x3F; if (to_row>0x3F) to_row = 0x3F; + + memcpy((void*)_trBuffer, + (const void*)_pixelBuffer, + DISPLAY_BUFFER_ELEMENTS * sizeof(DISPLAY_BUFFER_TYPE)); + set_row_address(from_row, to_row); set_column_address(from_col, to_col); wr_cmd8(SSD1322_CMD_WRITE_RAM); for(y=from_row; y<=to_row; y++) { for(x=from_col; x<=to_col; x++) { - wr_data8(buffer[y*128 + 2*x]); - wr_data8(buffer[y*128 + 2*x + 1]); + wr_data8(_trBuffer[y*128 + 2*x]); + wr_data8(_trBuffer[y*128 + 2*x + 1]); } } } unsigned long SSD1322::buffaddr(unsigned int i) { - return (unsigned long) &(buffer[i]); + return (unsigned long) &(_pixelBuffer[i]); } void SSD1322::clrbuff(const unsigned char value) { - memset(buffer, value, screensize_X*_PAGES); + memset((void*)_pixelBuffer, value, screensize_X*_PAGES); } void SSD1322::fills(const unsigned char value) { -clrbuff(value); -copy_to_lcd(); + clrbuff(value); + copy_to_lcd(); } void SSD1322::cls(void) { -clrbuff(); -copy_to_lcd(); + clrbuff(); + copy_to_lcd(); } -//void ll_fill(const unsigned char value=0xFF, const unsigned char w=0x78, const unsigned char=0x80); -void SSD1322::ll_fill(const unsigned char value, const unsigned char w, const unsigned char h) -{ - unsigned short x,y; - //w = 0x78; // 120 x 2px by byte => 240px - //h = 0x80; // 0x80 for 64 rows because 2 COMs mode - - wr_cmd8(0x15); // COL ADDR - wr_data8(0x00); - wr_data8(w-1); - - wr_cmd8(0x75); // ROW ADDR - wr_data8(0x00); - wr_data8(h-1); - - wr_cmd8(0x5C); // WRITE RAM - for(y=0; y= 64) - loop_pos = 0; - set_row_address(loop_pos); - set_column_address(0); - wr_cmd8(SSD1322_CMD_WRITE_RAM); - - for(uint8_t i=0; i<128; i++) - wr_data8(buffer[loop_pos*64+i]); -} - -void SSD1322::start_loop(float tick) { - loop_pos = 0; - bah.attach(this, &SSD1322::loop_event, tick); -} - -void SSD1322::stop_loop() { - bah.detach(); -}