You are reading a single comment by @DaveNI and its replies. Click here to read the full conversation.
  • Hi

    I got a 2.2" 240*320 ILI9341 controlled display and have been really pleased with it (considering its low price) but the current ILI9341 module uses a Graphics Callback to display every pixel which is a bit too slow.

    I have implemented a new method in the Controller module:

    LCD.drawStringBuffered(str, x, y, fontSize, r, g, b)

    This creates a buffer for the string being drawn then sends it to the display all at once. It is working (much faster than pixel by pixel) but I am having issues with the colour (wrong colours being displayed). I think it is something to do with the endianness of the 16bit colour data.

    The current module uses the following code when writing 16 bit values (e.g. pixel colour) to the SPI:

    spi.write(c>>8,c);

    Could this be achieved by changing modifying the spi setup to use an order of 'lsb'. (I did try this but nothing was displayed!)

    Anyway I'm pleased with how the screen performs & can work around the invalid colors but it would be great if I could get it functioning correctly. My method is as follows:

      LCD.drawStringBuffered = function(str, x, y, fontSize, r, g, b){
    	//Create a dummy Graphics object to get size of string in fontSize
       var g = Graphics.createArrayBuffer(1, 1, 1);
    	g.setFontVector(fontSize);
    	var width = g.stringWidth(str)
    	
    	var height = fontSize * 1.3; // this works but not sure how height is related to size for vector font
    	var x2 = x + width-1;
    	var y2 = y + height-1;
    	
    	//now the width/height is known actual Graghics object can be created
    	g = Graphics.createArrayBuffer(width, height, 16);	
        g.setFontVector(fontSize);
    	g.setColor(r, g, b);
    	g.drawString(str,0,0);
    	
    	//write buffer to spi
    	ce.reset();
        spi.write(0x2A,dc);
        spi.write(x>>8,x,x2>>8,x2);
        spi.write(0x2B,dc);
        spi.write(y>>8,y,y2>>8,y2);
        spi.write(0x2C,dc);
        spi.write(g.buffer);
        ce.set();
    	
    	//I tried shifting the buffer by 8 bits - some colors correct but others lost
    	//offsetBuffer = new Uint8Array(g.buffer, 1);
    	//spi.write(offsetBuffer);
      }
    
About

Avatar for DaveNI @DaveNI started