ILI9341 Vertical scrolling bug in software - but where?

Go To Last Post
3 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm writing text to an LCD, new text appears on the last line of the LCD. The content is shifted upwards by the same number of lines as the new text. In order to make sure the line we're going to overwrite is empty I draw a rectangle over it which hides the text, otherwise it might show up if the new text is not as long.

 

The vertical shift function:

void LCDScrollLine(void)
{
	static uint16_t VscrlAddr = 0;
	VscrlAddr += LCDTextData.textSize * 8;
	 
	if (VscrlAddr >= LCD_H) 
		VscrlAddr -= LCD_H;

	LCDWriteCommand(ILI9341_VSCRSADD);
	LCDWriteData(VscrlAddr >> 8);
	LCDWriteData(VscrlAddr);
}

And the function that uses this during LCD update:

void LCDGWriteChar(char c)
{
	if (c == '\n') // New line
	{
		LCDTextData.cursorY += LCDTextData.textSize * 8;
		LCDTextData.cursorX = 0;
		
		if (LCDTextData.cursorY > LCD_H)
			LCDSetCursor(0, 0);
		
		LCDDrawRectFill(LCDTextData.cursorX, LCDTextData.cursorY, LCD_W, LCDTextData.textSize * 8, RED);
		LCDScrollLine();
	} 
	else if (c != '\r') // Standard char
	{
		LCDGDrawChar(LCDTextData.cursorX, LCDTextData.cursorY, c, LCDTextData.textColor, LCDTextData.textBGColor, LCDTextData.textSize);
		LCDTextData.cursorX += LCDTextData.textSize * 6;
		
		// If end of line, skip to the next line
		if (LCDTextData.cursorX >= LCD_W)
		{
			LCDTextData.cursorY += LCDTextData.textSize * 8;
			LCDTextData.cursorX = 0;
		}
		
		if (LCDTextData.cursorY > LCD_H)
			LCDSetCursor(0, 0);
	}
}

As you can see, when a new line character is detected, X & Y parameters are update the position the next write at the beginning of the next line. In case the vertical position is over LCD's height it is set back to 1st line (NOTE - perhaps this should be >= and not only >). Afterwards the lines are cleared by drawing a rectangle over them. Finally the LCD is scrolled. The rest takes care of character writing to the LCD.

 

The screen seems to be scrolling OK, however after a while some rows are missing, Can anyone spot an obvious bug?

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am working with some old code and these types of LCDs.  I had a rather nasty bug in my scroll routine too.  My code, however is written in Assembler.   I was dedicating a register to the hardware scroll parameter.   As these displays are slow, I did not want to redraw the whole screen with the drawchar function.  The screen is buffered, So I change the redraw point, then call a refresh screen function that simply looks at each char cell and draws it shifted.   Anyway turns out that I was compensating for the "hardware scroll" in both the cursor function and the drawchar function.   These were working at cross purposes and I was having results similar to yours.

The ILI9341 is almost fast enough for the scroll illusion to work.  The HX8357B is dog slow as it uses 9 bit spi and has twice the resolution.  So the scroll illusion on that looks funny as one can see the blanking line travel up the page.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

From whatever reason I could not find a working library for this driver that uses the scrolling feature, perhaps I am looking at all the wrong places?