Sunday, June 11, 2023

Drawing on the LCD screen to test functions I need - part 6

CORRECTING INITIALIZATION TO ALLOW DRAWING ON THE SCREEN

I found a simple error in my porting changes to the function that should have been initializing the screen dimensions. It is now corrected and the previous error situations in routines to clear screens or draw objects have been rectified. 

DEEPER DIVE INTO THE SEQUENCE INITIALIZING THE LCD CONTROLLER CHIP

While I feel that the code is correctly sending commands, that is 8 bit transmissions with the proper control signal activated, I have not fully checked how this is handling data which is either a single frame of 16 bits bounded by my LCD Select or multiple 16 bit words sent under a single LCD Select session. If either of these is not operating correctly then it won't initialize properly. 

I did monitor such sequences and was satisfied that the LCD Select, my falsified slave select to the LCD Module, is working as intended to clock in 8 or 16 bits, triggering the LCD controller chip to accept the command or data, as well as toggling as each 16 bit word arrives in a stream of them. 

GAINING UNDERSTANDING OF HOW TO WRITE TO THE LCD SCREEN

The LCD controller has a memory that is 480 x 320 pixels in size, each pixel being a 16 bit color quantity. The controller can scan through the memory in multiple ways. It can advance horizontally along a line from left to right, then drop down to the next line which again runs left to right. This is called L2F U2D mode. There are modes that scan right to left, modes that bottom to top, and one can instead scan down or up columns first, then advance horizontally to the next column either right or left. Many combinations of modes exist. 

Commands configure the mode of the controller chip. For my purposes I will always operate in the L2R U2D mode. The method of transmitting pixels to the screen in any mode involves starting or restarting a write to memory using commands 0x2C (and 0x3C). Every data word following that command up until the next command byte is received will be entered into the memory, left to right rows moving from top to bottom. 

The decision for when the right end of a line is reached, so that the next pixel is put in the leftmost position one row down, is based on a window that is set up by commands. The command 0x2A defines the leftmost and rightmost coordinate of the window. If that is set to 0 and 479, for example, then when we stream in pixels they will start at the left edge of the screen and continue all the way to the right edge. If we instead issue 0x2A with an extent of 100 and 199, then we stream pixels in which are placed starting at X position 100, continuing to X position 199, then back to X position 100 on Y position + 1. 

Similarly, the command 0x2B will set the top and bottom coordinates of the window. If set to 0 and 319, then when we start streaming pixel data it begins on the top edge of the screen and after reaching the right end of a line, drops down 1 line until finally reaching the bottom edge. If we instead issue 0x2B with an extent of 50 and 59, then our first pixel is on the left edge of the window at Y coordinate 50 and once the pixels reach the right edge of the window, we drop down to Y coordinate 51 and eventually get down to the right edge at Y coordinate 59. 

Routines that draw objects make use of these commands - we set a window where we want to draw an object and then stream in the number of pixels needed to fill that window. They can be pixels of a common value, in order to clear an area to a uniform color. They can be uniform color pixels to draw a rectangle or square inside a larger area. They can be areas where patterns from the pixels form arcs, circles, lines and even font characters. 

SCREEN OPERATION COMMANDS

There are commands to put the controller to sleep (power conserving mode) and bring it out of sleep. Commands turn on the display or turn it off. Commands can flip on all pixels or flip off all pixels. Commands can set the display into inverse mode - i.e a font character can look like black ink on white paper or like white phosphors on a black (or green) screen. 

I will be experimenting with these commands as they are simple sequences that should produce visible results on the monitor to quickly confirm my understanding. That will take place next. 


No comments:

Post a Comment