1.8" display and drawChar function

EL Wire/Tape/Panels, LEDs, pixels and strips, LCDs and TFTs, etc products from Adafruit

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
Andy_123
 
Posts: 11
Joined: Sun Jan 27, 2013 2:29 pm

1.8" display and drawChar function

Post by Andy_123 »

I am not sure if this is a right place to post, if not point me to the correct place please

it appears that default GFX library function drawChar updates one pixel at the time, setting window for each pixel individulally in drawPixel routine.

this causes a lot of overhead, as it is setting "window" 48 times instead of 1 for each character (size 1)
Set Window takes 7 SPI writes for each pixel, that we can avoid
Overhead is even greater for the font sizes 2 or larger.


I think it would be more efficient to set window for whole character once (6x8 size) and then push all pixels directly writing spidata
Hardware will take care of shifting to the next pixel and setting next row in this case.

But this will require to read all five bytes of each character before displaying and as a result 6 bytes of RAM instead of 1 for the "line" variable.

I did not write whole new routine, just made quick test for font size 1 and it works much faster, making text appearance almost instant.

Any comments or ideas?

User avatar
AnneBarela
Learn User Page
 
Posts: 757
Joined: Sat Mar 24, 2012 8:56 pm

Re: 1.8" display and drawChar function

Post by AnneBarela »

COuld you put your test code snippet in a code window on a reply post? I'd be interested in your technique.

Andy_123
 
Posts: 11
Joined: Sun Jan 27, 2013 2:29 pm

Re: 1.8" display and drawChar function

Post by Andy_123 »

Code that I am using right now is implemented in my library conversion from Arduino to PIC18 and PIC32
Last night I got fully finctional code for any size not just size=1 that I initially did.
if you want to see PIC code - I can post it tonight

LAter on I am planning to go back to Arduino ST7735R libraries and add my drawChar code using low level direct SPI write routines setting Window only once per char

Once changed, I will post it here
Last edited by Andy_123 on Thu Feb 14, 2013 10:18 pm, edited 1 time in total.

Andy_123
 
Posts: 11
Joined: Sun Jan 27, 2013 2:29 pm

Re: 1.8" display and drawChar function

Post by Andy_123 »

Here is updated Arduino code

But, I guess my code works only if text background color is set, because it writes all pixels of the char
Original code only sets active pixels, alowing transaprent background

As a result, code below requires use of tft.setTextColor(color, bg); instead of tft.setTextColor(color);

Code: Select all

// draw a character fast
void Adafruit_ST7735::drawChar(int16_t x, int16_t y, unsigned char c,
			    uint16_t color, uint16_t bg, uint8_t size) {
 uint8_t line[6], i,ii,j,jj;
 
  if((x >= _width)            ||					// Clip right
     (y >= _height)           ||					// Clip bottom
     ((x + 5 * size - 1) < 0) ||					// Clip left
     ((y + 8 * size - 1) < 0))						// Clip top
     return;
    												//read 6 columns first: 5 from ROM, last=0
  for (i=0; i<5; i++ ){ 
	  line[i] = pgm_read_byte(font+(c*5)+i);
 }
	line[5]=0;									    // blank column
													// prepare colors
	uint8_t fHi =color>>8;
	uint8_t fLo =color;
	uint8_t bHi =bg>>8;
	uint8_t bLo =bg;


    setAddrWindow(x, y, x+6*size-1, y+8*size-1);	// set window for the full character
	*rsport |=  rspinmask;							// prepare data connection
	*csport &= ~cspinmask;							// set CS low, since setAddrWindow will set it high

	for (j = 0; j<8; j++) {					// row in character 
		for (jj = 0; jj<size; jj++) {			// pixel row in each row
			for (i = 0; i<6; i++) {					// column in character
				for (ii = 0; ii<size; ii++) {// pixel column
				  if (line[i] & 0x1)  {				// write color pixel
					  spiwrite(fHi);
					  spiwrite(fLo);
				  } else {			
					  spiwrite(bHi);				// or write background color
					  spiwrite(bLo);
				  }
				}									// ii - pixel of a column done
				if(jj==(size-1)) line[i] >>= 1;		// shift source only if we did all pixel rows
			}										// i - all columns in the row done
		}											// jj - all pixel in the row done
	}												// j - all rows done
	*csport |= cspinmask;							// set cs high
}

Locked
Please be positive and constructive with your questions and comments.

Return to “Glowy things (LCD, LED, TFT, EL) purchased at Adafruit”