LCD graphic microprocessor controller and its working flow
Patent Information
- Application Number
- CN202310392817.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-04-12
- Publication Date
- 2026-09-04
- Estimated Expiration
- 2043-04-12
AI Technical Summary
[0009]针对现有技术中所存在的不足,本发明提供了一种LCD图形微处理控制器及其工作流程,其解决了现有的TFT LCD文字图形控制器存在生产制造成本较高的技术问题
[0015] Compared with existing technologies, the present invention has the following advantages: by combining a microprocessor with peripheral hardware such as serial FLASH and serial character library, SDRAM, LCD display, debugging port, CONSOLE port, spare serial port and MCU interface to form an LCD graphics microprocessor controller, and by using RT-Thread as the real-time operating system of the LCD graphics microprocessor controller, that is, simulating the original TFT text graphics controller in the microprocessor, it solves the technical problem of high manufacturing cost of existing TFT LCD text graphics controllers.
Smart Images

Figure CN116386562B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of display technology, and more particularly to an LCD graphics microprocessor controller and its workflow. Background Technology
[0002] TFT LCD, also known as liquid crystal display, is mainly used to display text, graphics, images, videos and other information. For a TFT LCD to display text and graphics normally, it requires the joint operation of an LCD driver and an LCD controller.
[0003] The function of an LCD driver is to control the display of each pixel. The color data of each pixel written through the interface is controlled by the LCD driver to display the three primary colors R / G / B of that pixel. An 800*480 dot matrix TFT panel has 800 pixels per row and 480 pixels per column. Each pixel has three bytes of RGB. If the refresh rate is 60Hz, the amount of data per second is 800*480*3*60, which is a very large amount of data. Furthermore, since the control of each pixel involves the control of analog voltage, the LCD driver uses a dedicated ASIC chip.
[0004] The LCD controller is a computer peripheral that interacts with low-level programmers. Its most basic function is to transmit data from the computer's video memory to the LCD driver via outputting horizontal synchronization, vertical synchronization, pixel parallel data, and data enable signals, allowing the LCD screen to display the video memory data. Typically, chips based on ARM9 and above integrate an LCD controller as a standard peripheral. High integration is beneficial for size and power consumption control. Devices like mobile phones, tablets, and some handheld devices are very sensitive to power consumption and size, while also requiring a certain level of processing speed. These chips are powerful and fast, but also relatively expensive.
[0005] There are also some applications such as the control of small home appliances and industrial instruments, which are all embedded devices that use low-end processors with 8051 or Cortex-M3 cores. These microcontrollers (MCUs) do not integrate LCD controller peripherals, and the processor's built-in memory is generally only a few tens of kilobytes, which is not large enough to allocate to the display cache. Therefore, they cannot directly drive TFT LCD screens. With the upgrading of consumption, these small home appliances and some embedded industrial equipment need more user-friendly human-machine interfaces to replace the early segment and monochrome TN LCD displays.
[0006] When such embedded devices are designed to use TFT LCD displays, the typical approach is to use an MCU plus a separate LCD controller chip. The MCU is responsible for calculating the display content and storing it in the video memory, while the LCD controller is responsible for transmitting the data from the video memory to the LCD display.
[0007] An independent LCD controller is usually a dedicated ASIC chip. With the advancement of computer technology, modern LCD controllers, in addition to having the basic functions of an LCD controller, such as outputting video memory data to the LCD driver through the RGB interface, also implement many features, such as multi-layer display, text engine, 2D drawing, DMA video memory transfer acceleration, and image display. This greatly reduces the workload of the MCU. We call this type of LCD controller with text display and 2D drawing functions a TFT LCD text and graphics controller.
[0008] Because existing TFT LCD text and graphics controllers, such as the RA8875, integrate powerful functions, such as screen scrolling, floating window display, graphic pattern and text magnification, they can save users a lot of software development time and improve the execution efficiency of MCU software. However, TFT LCD text and graphics controllers are actually ASIC chips, and the manufacturing cost of ASIC chips is relatively high. Summary of the Invention
[0009] To address the shortcomings of existing technologies, this invention provides an LCD graphics microprocessor controller and its workflow, which solves the technical problem of high manufacturing costs in existing TFT LCD text graphics controllers.
[0010] An LCD graphics microprocessor controller according to an embodiment of the present invention includes a microprocessor and peripheral hardware connected thereto. The peripheral hardware includes a serial FLASH and a serial character library, SDRAM, an LCD display, a debug port, a CONSOLE port, a spare serial port, and an interface with the MCU.
[0011] The microprocessor includes a TFT LCD controller, the CONSOLE port is connected to a console, the MCU interface is used to connect to a user MCU, and the LCD graphics microprocessor controller uses the RT-Thread real-time operating system.
[0012] The technical principle of this invention is as follows: a microprocessor is used to simulate the function of a TFT LCD text and graphics controller. The microprocessor uses software to parse functions such as drawing points, drawing lines, drawing rectangles, drawing rectangle fills, drawing circles, and drawing ellipses, thereby achieving the function of the original TFT LCD text and graphics controller using a microprocessor. Moreover, because the cost of microprocessors is low, the cost can be effectively reduced, specifically saving about 10 yuan per device.
[0013] The purpose of the external SDRAM is that the internal storage space of a microprocessor is generally less than 512Kbyte, while driving an 800*480 resolution LCD screen with 16-bit color depth requires 800*480*2Byte, or about 748Kbyte, so an external SDRAM is needed.
[0014] The purpose of including a TFT LCD controller within the microprocessor is as follows: The GenericTFT Driver I / F function of the TFT LCD controller transmits data from the display memory to the LCD screen, including control signals such as horizontal synchronization, vertical synchronization, pixel parallel data, pixel pulse, and data enable. The LCD screen needs to refresh the image at a certain refresh rate, so these signals are periodically issued according to a specified timing sequence. This function cannot be implemented solely through software, therefore a TFT LCD controller needs to be added within the microprocessor.
[0015] Compared with existing technologies, the present invention has the following advantages: by combining a microprocessor with peripheral hardware such as serial FLASH and serial character library, SDRAM, LCD display, debugging port, CONSOLE port, spare serial port and MCU interface to form an LCD graphics microprocessor controller, and by using RT-Thread as the real-time operating system of the LCD graphics microprocessor controller, that is, simulating the original TFT text graphics controller in the microprocessor, it solves the technical problem of high manufacturing cost of existing TFT LCD text graphics controllers.
[0016] Furthermore, when the microprocessor needs to exchange data with the serial FLASH and serial character library, SDRAM, LCD display, debug port, CONSOLE port, spare serial port and MCU interface, the microprocessor will send the corresponding external resource number.
[0017] Furthermore, the peripheral resource number SPI1 of the microprocessor corresponds to the MCU interface;
[0018] The peripheral resource number SPI3 corresponds to the serial FLASH and serial character library;
[0019] The peripheral resource number SDRAM corresponds to SDRAM;
[0020] The peripheral resource number TIM0_CH0 corresponds to the LCD display screen;
[0021] The peripheral resource number JTAG corresponds to the debug port;
[0022] The peripheral resource number USART0 corresponds to the CONSOLE port;
[0023] The peripheral resource number USART1 corresponds to the spare serial port.
[0024] Furthermore, the core components of the microprocessor include 512KByte of FLASH, 256KByte of RAM, 6 SPIs, 1 TFT LCD controller, 1 IPA graphics accelerator, 1 EXMC / SDRAM, and 14 timers.
[0025] Furthermore, the microprocessor peripheral resource number TLI corresponds to the TFT LCD controller.
[0026] The workflow of the LCD graphics microprocessor controller described in an embodiment of the present invention includes:
[0027] S1. After power-on, according to the code structure of RT-Thread, the $Super$$Main() function is first called to initialize the various core components of the microprocessor;
[0028] S2. Call the $SubMain() function and then call the Bsp() function to initialize the peripheral hardware of the microprocessor;
[0029] S3. Use the rt_thread_init function to create the QueueThread() thread, and then call rt_thread_startup() to start the QueueThread() thread.
[0030] S4. After the QueueThread() thread starts and the main() function finishes execution, RT-Thread executes the main() thread to destroy the program and reclaim memory space.
[0031] Furthermore, in step S2, SPI1 is initialized to SPI Slave mode in the Bsp() function, and the receive interrupt of SPI1 is configured.
[0032] Furthermore, when the user MCU sends a drawing instruction, which is a frame of several bytes of data, when the SPI1 receives this frame of data, it will generate a receive interrupt for each byte. The system interrupt vector table will jump to the interrupt entry of the SPI1. In the interrupt function, it will first check whether the receive queue is full.
[0033] If the receive queue is not full, add one byte of data received by SPI1 to the queue, which is called enqueueing:
[0034] If the receive queue is full, the received data is discarded, and the function execution is interrupted and returns.
[0035] Furthermore, in step S3, the QueueThread() thread is an infinite loop thread;
[0036] a. After a one-tick operating system delay, the program checks if the received data queue is empty:
[0037] If the queue is empty, it means that SPI1 has not received any bytes of data during the period from the previous cycle to the current cycle. The program returns and waits for the next cycle to check if the queue is empty.
[0038] If it is not empty, it means that data has been received at the SPI1 port during the period from the previous cycle to the current cycle. The data is dequeued and added to the instruction BUFF.
[0039] b. Determine if the instruction BUFF is a complete drawing instruction:
[0040] If not, clear the instruction BUFF and reread the queue data;
[0041] If yes, then this instruction is considered a correct instruction, and the drawing instruction is parsed from the queue;
[0042] c. Each instruction calls the corresponding function to perform the corresponding operation;
[0043] d. After the drawing function finishes executing, clear the BUFF of this instruction.
[0044] The QueueThread() thread implements complete drawing commands, such as functions for drawing points, lines, rectangles, rectangle fills, circles, and ellipses.
[0045] Furthermore, the method for determining whether the instruction BUFF is a drawing instruction is as follows:
[0046] Determine if the first two bytes of the BUFF are 0x55aa and the last two bytes are 0x5aa5;
[0047] Determine the drawing instruction code identifier, and based on the code identifier, determine the number of bytes required for this drawing instruction. Then, determine whether the number of bytes required is consistent with the number of bytes parsed from the queue.
[0048] If any of the above conditions are not met, it means that the drawing command is incorrect. Clear the command BUFF and reread the queue data.
[0049] If all conditions are met, this instruction is considered a correct instruction.
[0050] We use a self-checking method to ensure that every drawing instruction is correct. Attached Figure Description
[0051] Figure 1 This is a block diagram of the TFT LCD text and graphics controller of the RA8875 in the prior art.
[0052] Figure 2 This is a block diagram of the LCD graphics microprocessor controller according to an embodiment of the present invention.
[0053] Figure 3 This is a block diagram of the microprocessor structure according to an embodiment of the present invention.
[0054] Figure 4 This is a flowchart illustrating the operation of the LCD graphics microprocessor controller according to an embodiment of the present invention.
[0055] Figure 5 This is a flowchart of the interrupt routine for the SPI1 interface of the user MCU in an embodiment of the present invention.
[0056] Figure 6 This is a flowchart of the QueueThread() thread in an embodiment of the present invention. Detailed Implementation
[0057] The technical solutions of the present invention will be further described below with reference to the accompanying drawings and embodiments.
[0058] like Figure 2 The LCD graphics microprocessor controller shown includes a microprocessor and its connected peripheral hardware, which includes a serial FLASH and serial character library, SDRAM, an LCD display, a debug port, a CONSOLE port, a spare serial port, and an MCU interface; the CONSOLE port is connected to a console, and the MCU interface is used to connect to a user MCU.
[0059] The specific microprocessor used is the GD32F450ZET6. When the microprocessor needs to exchange data with the serial FLASH and serial character library, SDRAM, LCD display, debug port, CONSOLE port, spare serial port and MCU interface, the microprocessor will send the corresponding external resource number.
[0060] The microprocessor's peripheral resource number SPI1 corresponds to the MCU interface; peripheral resource number SPI3 corresponds to the serial FLASH and serial word library; peripheral resource number SDRAM corresponds to SDRAM; peripheral resource number TIM0_CH0 corresponds to the LCD display; peripheral resource number JTAG corresponds to the debug port; peripheral resource number USART0 corresponds to the CONSOLE port; and peripheral resource number USART1 corresponds to the spare serial port. This effectively avoids resource conflicts and reuse issues in the microprocessor.
[0061] like Figure 3As shown, the core components of the microprocessor include 512KByte of FLASH, 256KByte of RAM, 6 SPIs, 1 TFT LCD controller, 1 IPA graphics acceleration, 1 EXMC / SDRAM, and 14 timers, which provide hardware support for software functions such as drawing points, lines, rectangles, rectangle filling, circles, and ellipses. The microprocessor peripheral resource number TLI corresponds to the TFT LCD controller, which also helps to avoid resource conflicts and duplication issues in the microprocessor.
[0062] like Figure 4 As shown, the LCD graphics microprocessor controller uses the RT-Thread real-time operating system. The specific workflow of the LCD graphics microprocessor controller includes:
[0063] S1. After power-on, according to the code structure of RT-Thread, the $Super$$Main() function is first called to initialize the various core components of the microprocessor.
[0064] Specifically, the microprocessor's timer is initialized as the operating system's clock, and USART0 is initialized as the console port for RT-Thread.
[0065] S2. By calling the goto statement to the $SubMain() function and then calling the Bsp() function, the peripheral hardware of the microprocessor is initialized. The $SubMain() function is actually the main() function in our regular program structure. The Bsp() function is called first in the main() function.
[0066] Specifically, this involves initializing SPI1 to SPI Slave mode, SPI3 to SPI Master mode, initializing the TLI and IPA controllers, and initializing the SDRAM controller to set CAS and RAS delays, among other things.
[0067] S3. Use the rt_thread_init function to create the QueueThread() thread, and then call rt_thread_startup() to start the QueueThread() thread.
[0068] The specific thread creation function for RT-Thread is rt_thread_init. When creating a thread, you need to specify parameters such as stack size, thread priority, and thread time slice.
[0069] The task of the thread that creates QueueThread() is to continuously read data from the command queue, combine it into a complete command, parse the command, and execute the command.
[0070] S4. After the QueueThread() thread starts and the main() function finishes execution, RT-Thread executes the main() thread to destroy the program and reclaim memory space.
[0071] like Figure 5 As shown, the above S2 step also configures the SPI1 receive interrupt. Specifically, when the user MCU sends a drawing instruction, which is a frame of several bytes of data, the SPI1 will generate a receive interrupt for each byte when receiving this frame of data. The system interrupt vector table jumps to the SPI1 interrupt entry point. In the interrupt function, it first checks whether the receive queue is full.
[0072] If the receive queue is not full, then add one byte of data received by SPI1 to the queue, which is called enqueueing.
[0073] If the receive queue is full, the received data is discarded, and the function execution is interrupted and returns. A full receive queue is an abnormal situation. Since some received data is discarded, the final consequence is incomplete drawing instructions. As the LCD graphics controller simulated in this solution will miss executing a drawing instruction, which is obviously undesirable. Therefore, we need to set the length of the receive queue to the maximum extent and optimize the dequeue speed. When the dequeue speed is greater than the enqueue speed, the queue will not be full, thus ensuring that no data is lost. Therefore, this application defines a queue length of 100kbyte.
[0074] like Figure 6 As shown, in step S3, the QueueThread() thread is an infinite loop thread;
[0075] a. First, after a one-tick operating system delay, the program checks if the received data queue is empty. If empty, it means that SPI1 has not received any bytes of data from the previous tick to the current tick, and the program returns to wait for the next tick to check if the queue is empty again. If not empty, it means that SPI1 port has received data from the previous tick to the current tick, so the program executes data dequeue and adds the dequeueed data to the instruction BUFF.
[0076] b. Determine if the instruction BUFF is a complete drawing instruction:
[0077] If not, clear the instruction BUFF and reread the queue data; if yes, consider this instruction to be correct and parse the drawing instruction from the queue.
[0078] The specific method for determining whether the instruction BUFF is a drawing instruction is as follows:
[0079] 1. Determine if the first two bytes of the BUFF are 0x55aa and the last two bytes are 0x5aa5.
[0080] 2. Determine the drawing instruction code identifier, and based on the code identifier, determine the number of bytes required for this drawing instruction. Then, determine whether the required number of bytes is consistent with the number of bytes parsed from the queue.
[0081] If any of the above conditions are not met, the drawing command is incorrect; clear the command buffer and reread the queue data. If all conditions are met, the command is considered correct.
[0082] c. Each instruction calls the corresponding function to perform the corresponding operation; there can be many kinds of drawing instructions parsed from the queue. This application defines text-related instructions, 2D graphics drawing-related instructions, color-related instructions, window operation instructions for the screen, continuous writing instructions for video memory data, and backlight control instructions.
[0083] d. After the drawing function finishes executing, clear the BUFF of this instruction.
[0084] The GD32F450ZET6 microcontroller must internally implement the functions listed in the table below:
[0085]
[0086] Specific plotting functions
[0087] Point drawing function declaration: void point(uint16_t x, uint16_t, uint32_t color);
[0088] The function of drawing points is to write color data at specified coordinates on the screen. It requires three parameters: X coordinate, Y coordinate, and color. It has no return value. It should be noted that the origin of the screen is at the top left corner, not the bottom left corner of the Cartesian coordinate system. The video memory is defined in the SDRAM space as an array BUFF_SDRAM_TFTLAY0[640*480*2]. The size of the array is 640*480*2 (640*480 resolution, 16-bit color). BUFF_SDRAM_TFTLAY0[0] corresponds to the pixel at the origin of the screen coordinates. The main algorithm here is to calculate the index of the video memory array based on the X and Y coordinate values. The Y coordinate value multiplied by the display row dot matrix plus the X coordinate is the index of the video memory array. Since the point drawing function is a frequently called function in the LCD controller, optimization is needed here. Instead of calling it as a function, a parameterized macro definition is used: `#define TFT_POINT(X,Y,COLOR)BUFF_SDRAM_TFTLAY0[(uint32_t)(Y)*TFT_WINDOWS_WIDTH+(uint32_t)(X)]=COLOR`. To draw a green point at screen coordinates (100,100), `TFT_POINT(100,100,clGreen)` is called.
[0089] Plotting Linear Functions
[0090] The function declaration for drawing a straight line is: void gui_line(uint16_t x0,uint16_t y0,uint16_t x1,uint16_t y1,TCOLOR color);
[0091] The function to draw a straight line connects any two coordinate points on the screen. Its two-point mathematical expression is (y-y0) / (y1-y0)=(x-x0) / (x1-x0). Based on this expression, we need to perform a line scan transformation, determining the optimal set of pixels closest to the line within a finite pixel matrix. When drawing a straight line, the quality of the line drawing must be considered. First, the line must be straight. Second, the endpoints of the line must be accurate to ensure non-directional drawing; that is, a line drawn from point A to point B and a line drawn from point B to point A should coincide. Third, the density of the line should be uniform, avoiding visually alternating bright and dark sections. Fourth, the line drawing algorithm must be fast, especially since microprocessors generally do not have an FPU, so floating-point operations should be avoided as much as possible. The algorithm for drawing straight lines in this application uses the Bresenham algorithm. The basic principle of the Bresenham algorithm is to move one step in the direction of maximum displacement each time. Whether to move in the other direction or not depends on the error term. Assuming 0 ≤ k ≤ 1, since x is the direction of maximum displacement, 1 is added to the x-axis each time, and either 1 or 0 is added to the y-axis. Assuming the current point is P(Xi, Yi), the next point is chosen between Pu(Xi+1, Yi+1) and Pd(Xi+1, Yi). Let M represent the midpoint between Pu and Pd, i.e., M(Xi+1, Yi+0.5). Let Q be the intersection of the ideal straight line and the vertical line X = Xi+1. Obviously, if M is below Q, then Pu(Xi+1, Yi+1) is closer to the line and should be the next pixel; otherwise, Pd(Xi+Yi) should be used. The process of drawing using the Bresenham algorithm is as follows:
[0092] 1. Input the two endpoints of the line, P0(X0,Y0) and P1(X1,Y1).
[0093] 2. Calculate the initial values Δx and Δy, d = Δx - 2Δy, x = x0, y = y0.
[0094] 3. Plot the point (x, y). Determine the sign of d. If d < 0, then update (x, y) to (x+1, y+1) and d to d+2△x-2△y; otherwise, update (x, y) to (x+1, y) and d to d-2△y.
[0095] 4. If the line is not finished, repeat step 3; otherwise, end the process.
[0096] The code implementation of the function to draw a straight line is as follows:
[0097]
[0098]
[0099]
[0100]
[0101]
[0102] Drawing rectangle function
[0103] Declaration of the function to draw a rectangle: void gui_rectangle(uint16_t x0,uint16_t y0,uint16_tx1,uint16_t y1,TCOLOR color);
[0104] We've already implemented the function for drawing lines, so implementing the function for drawing rectangles is relatively simple. The coordinates of a rectangle are the coordinates of two points on its diagonals. We just need to draw two horizontal lines and two vertical lines using the coordinates of the diagonals.
[0105] The code implementation of the function to draw a rectangle is as follows:
[0106]
[0107] Draw rectangle fill function
[0108] Declaration of the rectangle fill function: void gui_gui_rectanglefill(uint16_t x0,uint16_ty0,uint16_t x1,uint16_t y1,TCOLOR color);
[0109] The implementation idea of the rectangle fill function is to fill individual points sequentially within a region defined by x0, y0, x1, y1. This can be achieved with just a nested loop structure. The main code for rectangle fill is as follows:
[0110] for(j=y0;j<=y1;j++)
[0111] for(i=x0;i<=x1;i++)
[0112] TFT_POINT(i,j,color);
[0113] The rectangular filling algorithm has been optimized in this application. The selected processor, GD32F450ZET6, includes an IPA (Image Processing Accelerator). The main functions of the IPA are copying the source and target images, color format conversion, color mixing, and filling the target area with a specific color. For the rectangular filling algorithm, we use the IPA's specific color filling function to implement the algorithm. IPA color filling is a DMA transfer, meaning the entire color filling process does not require CPU operation. The CPU only needs to check the IPA's BUSY flag to determine when filling is complete, significantly speeding up the filling process. The IPA color filling function is encapsulated in the function `ipa_fill()`, and its detailed implementation is available in the source code; the underlying details will not be explained further in this application.
[0114]
[0115]
[0116]
[0117] Circle function
[0118] Circle drawing function declaration: void gui_circle(uint16_t x0,uint16_t y0,uint16_t r,TCOLOR color);
[0119] The function implemented by the circle drawing function is to draw a circle with a radius R at a given circular (X, Y) position. In analytic geometry, for a circle with the center at the origin and an integer radius R, its equation is X²+Y²=R². Construct the function F(X,Y)=X²+Y²-R². For points on the circle, F(X,Y)=0; for points outside the circle, F(X,Y)>0; for points inside the circle, F(X,Y)<0. It is assumed that the midpoint Bresenham circle drawing algorithm clockwise determines the pixel sequence that best approximates the circular arc from the point (0,R) to the point (), for this circular arc, since the maximum displacement direction is X, the basic principle is as follows: each step is taken along the X direction, and Y is either decreased by 1 or decreased by 0. Assuming that the current pixel closest to the circular arc has been determined as P(Xi,Yi), then the next candidate pixel can only be Pu(Xi+1,Yi) directly to the right and Pd(Xi+1,Yi-1) to the lower right. The next candidate point is still discriminated using the midpoint. Suppose M is the midpoint of Pu and Pd, that is, M(Xi+1, Yi-0.5). Then when F(Xm,Ym)<0, M is inside the circle, and Pu is closer to the circular arc at this time, so Pu(Xi+1,Yi) should be selected as the next pixel point. When F(Xm,Ym)>0, it indicates that Pd is closer to the circular arc, so Pd(Xi+1,Yi-1) should be selected. When F(Xm,Ym)=0, either Pu or Pd can be selected arbitrarily, and Pu is conventionally selected. According to the mathematical theory described above, the steps of the midpoint Bresenham circle drawing algorithm are as follows:
[0120] Input the radius R of the circle;
[0121] 1. Calculate the initial values d=1-R, X=0, Y=R;
[0122] 2. Draw the point (X,Y) and its other seven symmetric points in the octant circle;
[0123] 3. Determine the sign of d. If d<0, first update d to d+2X+3, then update (X,Y) to (X+1, Y); otherwise, first update d to d+2(X-Y)+5, then update (X,Y) to (X+1,Y-1);
[0124] 4. When X<Y, repeat steps 3 and 4, otherwise end the process.
[0125] According to the foregoing algorithm description, the final implementation code for drawing a circle is as follows:
[0126]
[0127]
[0128]
[0129]
[0130] The above content is the detailed description and code implementation of the 2D drawing function. The 2D drawing function is a key function of the graphics controller. The technical point of the present application is how to use a general-purpose microprocessor to simulate and replace the RA8875 text and graphics controller available on the market. The highlight function of RA8875 is 2D drawing, that is, the user's MCU does not need to consider the drawing details, and only needs to send the drawing instruction to the controller, which then completes the drawing. The 2D drawing of RA8875 is implemented at the gate circuit level, while the present invention implements all drawing functions by means of coding. For example, the rectangular filling function also uses the internal IPA graphics accelerator of GD32F450ZET6 to execute with higher efficiency. Therefore, the overall drawing speed fully meets the design requirements, and the performance is almost the same as that of RA8875.
[0131] Implementation of Text Display Function
[0132] RA8875 includes a text engine module, whose main function is to call the font chip, extract the glyph from the font chip, and display it at the specified coordinate on the screen according to the set foreground color and background color. The text engine module of RA8875 is also the function to be implemented in the present application. The font chip GT30L32S4W is connected to the microprocessor through the SPI3 interface. The character set of GT30L32S4W is GB2312, which internally contains dot matrix glyphs of 12*12, 16*16, 24*24 and 32*32 font sizes, and the arrangement of glyphs is horizontal dot matrix in horizontal rows. The underlying driver of the program encapsulates the function `void spi_font_buffer_read(uint8_t *pbuffer, uint32_t read_addr, uint16_t num_byte_to_read)`, which is used to read N bytes of glyph data from the specified address of the font chip. A string usually includes Chinese characters and ASCII. For example, in the string "你好世界HELLO WORLD!", each Chinese character "你好世界" occupies 2 bytes, and each character in "HELLO WORLD!" occupies one byte. They are stored together in the computer. GB2312 internal code and ASCII code are distinguished by the highest bit of the byte: if the highest bit is 0, it is ASCII; if the highest bit is 1, it is GB2312 encoding in the solution of the present application. The following is one of the functions in this program. Its function is to display a 16*16 dot matrix string at the specified coordinate (X, Y). The ASCII code and Chinese characters in the string are jumped to the pure ASCII text display function and the GB2312 text display function through judgment conditions.
[0133]
[0134]
[0135] In the GT30L32S4W font library, the absolute storage address of the dot matrix font pattern is first calculated based on the ASCII code and GB2312 Chinese character encoding. Then, the `spi_font_buffer_read` function is called to read the font pattern from the absolute storage address. The number of bytes for the font pattern is related to its dot matrix. For example, for a 16*16 dot matrix, 16*2 bytes need to be read. The read font pattern is horizontally arranged, and the read font pattern data is a black and white dot matrix, excluding the foreground and background colors. Therefore, the font pattern data cannot be directly sent to the display memory and needs to be converted by a function. The conversion principle is that if the value of the current point of the font pattern is 1, the point is drawn at the current coordinate using the foreground color; if the value of the current point is 0, the point is drawn at the current coordinate using the background color. The function for displaying 16*16 dot matrix GB2312 text is given below. For the remaining 24*24 and 32*32 dot matrix fonts, please refer to the attached source code.
[0136]
[0137]
[0138] Implementation of color functions
[0139] Another function of the LCD controller is color management. Generally, graphics have foreground and background colors. We can set the foreground and background colors separately, and we can also swap them. Before calling the "Display Text" function to show text, we need to set the foreground and background colors. This requires calling functions to set the foreground and background colors. When we want the text to be highlighted, we need to call the color swap function before calling the "Display Text" function, resulting in highlighted text. The implementation of colors is simple: define global variables `TCOLOR Front_Color` and `Back_Color` for the foreground and background colors.
[0140] The functionality of the foreground color function is as follows: simply copy the passed-in parameter `color` directly to the global variable `Front_Color`.
[0141]
[0142] Similarly, the background color function copies the passed-in parameter `color` directly to the global variable `Back_Color`.
[0143]
[0144]
[0145] The function for swapping the foreground and background colors works as follows: it creates a temporary variable and swaps the values of Front_Color and Back_Color.
[0146]
[0147] The above describes the program structure of the TFT LCD text and graphics controller, analyzes the functions and algorithms of most of the instructions, and details the code implementation process.
[0148] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and are not intended to limit it. Although the present invention has been described in detail with reference to preferred embodiments, those skilled in the art should understand that modifications or equivalent substitutions can be made to the technical solutions of the present invention without departing from the spirit and scope of the technical solutions of the present invention, and all such modifications or substitutions should be covered within the scope of the claims of the present invention.
Claims
1. An LCD graphics microprocessor controller, characterized in that: It includes a microprocessor and its connected peripheral hardware, the peripheral hardware including serial FLASH and serial character library, SDRAM, LCD display, debug port, CONSOLE port, spare serial port and MCU interface; The microprocessor contains a TFT LCD controller, the CONSOLE port is connected to a console, the MCU interface is used to connect to a user MCU, and the LCD graphics microprocessor controller uses the RT-Thread real-time operating system. The core components of the microprocessor include one IPA graphics acceleration; The workflow of the LCD graphics microprocessor controller includes: S1. After power-on, according to the code structure of RT-Thread, the $Super$$Main() function is first called to initialize the various core components of the microprocessor; S2. Call the $SubMain() function and then call the Bsp() function to initialize the peripheral hardware of the microprocessor; The microprocessor's peripheral resource number SPI1 is initialized to SPI Slave mode in the Bsp() function, and the SPI1 receive interrupt is configured. When the user MCU sends a drawing instruction, which is a frame of several bytes of data, the SPI1 will generate a receive interrupt for each byte when receiving this frame of data. The system interrupt vector table will jump to the interrupt entry of the SPI1. In the interrupt function, the first thing to do is to check whether the receive queue is full. If the receive queue is not full, add one byte of data received by SPI1 to the queue, which is called enqueueing: If the receive queue is full, the received data is discarded, and the function execution is interrupted and returns. S3. Use the rt_thread_init function to create the QueueThread() thread, and then call rt_thread_startup() to start the QueueThread() thread. The QueueThread() thread is an infinite loop thread; a. After a one-tick operating system delay, the program checks if the received data queue is empty: If the queue is empty, it means that SPI1 has not received any bytes of data during the period from the previous cycle to the current cycle. The program returns and waits for the next cycle to check if the queue is empty. If it is not empty, it means that data has been received at the SPI1 port during the period from the previous cycle to the current cycle. The data is dequeued and added to the instruction BUFF. b. Determine if the instruction BUFF is a complete drawing instruction: If not, clear the instruction BUFF and reread the queue data; If yes, then this instruction is considered a correct instruction, and the drawing instruction is parsed from the queue; The method to determine whether the instruction BUFF is a drawing instruction is as follows: Determine if the first two bytes of the BUFF are 0x55aa and the last two bytes are 0x5aa5; Determine the drawing instruction code identifier, and based on the code identifier, determine the number of bytes required for this drawing instruction. Then, determine whether the number of bytes required is consistent with the number of bytes parsed from the queue. If any of the above conditions are not met, it means that the drawing command is incorrect. Clear the command BUFF and reread the queue data. If all conditions are met, this instruction is considered a correct instruction. c. Each instruction calls the corresponding function to perform the corresponding operation; d. After the drawing function finishes executing, clear the BUFF of this instruction; S4. After the QueueThread() thread starts and the main() function finishes execution, RT-Thread executes the main() thread to destroy the program and reclaim memory space.
2. The LCD graphics microprocessor controller as described in claim 1, characterized in that: When the microprocessor needs to exchange data with the serial FLASH and serial character library, SDRAM, LCD display, debug port, CONSOLE port, spare serial port and MCU interface, the microprocessor will send the corresponding external resource number.
3. The LCD graphics microprocessor controller as described in claim 2, characterized in that: The peripheral resource number SPI1 of the microprocessor corresponds to the MCU interface; The peripheral resource number SPI3 corresponds to the serial FLASH and serial character library; The peripheral resource number SDRAM corresponds to SDRAM; The peripheral resource number TIM0_CH0 corresponds to the LCD display screen; The peripheral resource number JTAG corresponds to the debug port; The peripheral resource number USART0 corresponds to the CONSOLE port; The peripheral resource number USART1 corresponds to the spare serial port.
4. The LCD graphics microprocessor controller as described in claim 3, characterized in that: The core components of the microprocessor also include 512KByte of FLASH, 256KByte of RAM, 6 SPIs, 1 TFT LCD controller, 1 EXMC / SDRAM, and 14 timers.
5. The LCD graphics microprocessor controller as described in claim 4, characterized in that: The microprocessor peripheral resource number TLI corresponds to the TFT LCD controller.
Citation Information
Patent Citations
12864 serial port configuration screen device and control method thereof
CN108710594A
Embedded platform display system
CN115080478A
Serial intelligent color-screen terminal
CN203179481U