"1 Introduction
In recent years, with the popularity of digital cameras, a product of digital photos, playback, and browsing is a function of digital photo frames, it is popular with its unique design concept and wonderful appreciation effect. The digital photo frame uses the appearance of the traditional ordinary photo frame to convert the intermediate photo portion of the traditional ordinary photo frame to a liquid crystal display, with a power supply, controller, storage medium, etc., and can directly display digital photos. At the same time, digital photo frames can also be circulated in the same photo frame to display different photos, solve the shortcomings that you need to use the computer to view digital photos, and provide a better display photo of the photo and space for people who are increasing digital photos and preferred photos. . Based on this, the system designs the digital photo frame based on RT-Thread and STM32.
The system uses STM32 as the master chip, and the digital photo frame system is designed with a platform-established platform with the source code open embedded RT-Thread operating system and human machine interaction interface μC / GUI. The system mainly implements the JPEG format image browsing on the touch LCD screen, the USB host read function, SPIFLASH storage and other functions.
2. System overall design
This system consists of partially embedded processors, peripherals, embedded operating systems and applications. The system is based on embedded RT-Thread and embedded microcontroller STM32, and the human-machine intersection interface is established by μC / GUI. Use the USB host read function to write pictures and font files to external SPI Flash, and use the file system to read the image file. After the picture decoding algorithm is processed, displayed on the touch LCD screen, through the touch, the browsing function of the picture is completed. The overall system of the system is shown in Figure 1.
3. System hardware design
The system is the main hardware platform with STM32, and the system integral hardware structure diagram is shown in Figure 2. The system hardware mainly has a power module, the STM32 system, the JTAG debug interface, the USB drive circuit, the SPI flash drive module, and the touch LCD drive circuit.
3.1 Power Module
The microcontroller and its peripheral circuit drive modules are required to 3.3V, and the power battery selected by the system is 3.3V voltage through the regulator chip.
For generated 3.3V voltage, the LM1117 regulator chip output of the National Semiconductor is 3.3V, and the LM1117 provides current limits and thermal protection. The circuit contains 1 iematled bandgap reference voltage to ensure that the output voltage is within ± 1%.
The output requires a tantalum capacitance at least 10uF to improve transient response and stability. The LM1117 regulator chip output 3.3V circuit is shown in Figure 3.
3.2 USB driver circuit
The STM32 chip integrates USB peripherals, mitigating the design burden of the USB circuit, and the system is designed with the USB interface circuit and the ESD protection circuit.
3.2.1 USB Interface Circuit
In the USB interface circuit, the USB pull-up voltage is connected to D +, and the USB full-speed communication, the triode is switching, and when the switch is turned on, the PC begins to enumerate the USB storage device. USB's VCC pin does not have a power supply on the board, powered by the PC.
3.2.2 ESD protection circuit
Using the USBLC6-2P6 of STMicroelectronics, the chip makes USB's D + / D-signal fully balanced, and the matching toave of the I / O interface is only 0.04 pF, which is completely within the tolerance range of USB 2.01PF. If an ESD phenomenon occurs on the USB data line, the ESD protection function of the chip will lead the current to the ground, in order to ensure the effectiveness of the ESD protection, the data line adopts track-to-rail protection topology, in order to improve the output power, the VCC line adopts clamp protection structure. The USB drive protection circuit schematic is shown in Figure 4.
3.3 SPI Flash drive circuit
The system uses SPI serial flash chip W25Q64, which has the advantages of simple circuit design, fast data reading speed, and reduces system circuit switching noise, reducing system power consumption and development costs. Its application circuit is shown in Figure 5.
3.4 LCD Touch Driver Circuit
The touch controller of the system selects TSC2046, TSC2046 is a four-wire resistive touch screen controller, which is a 12-bit moving proximity A / D converter with sampling and holding functions. The system drives the TSC2046 controller through the SPI interface of STM32, and the typical drive circuit is shown in FIG.
4. System software design
The software of this system is mainly initialized by the system module, and the μC / GUI establishes human-machine interaction interface, and the file system reads pictures and font files, and the image decoding algorithm implementation, touch browsing features, and slide playback function.
4.1 μC / GUI establishes human-machine interaction interface The system uses μC / GUI Builder to establish a μC / GUI human machine interaction interface, establish a form, text box, control, etc. in μC / GUI Builder, add C files generated after compiling to In the project catalog. The application of μC / GUI Builder shortens interface development cycle, flexible and convenient, and then modify the interface later, only need to modify the relevant components in μC / GUI Builder, and the compilation can be modified.
4.2 μC / GUI shows Chinese characters
The display of the font is realized by looking for a word mode in the μC / GUI. Each letter in the font library has its corresponding word, the word mold is managed by the structural GUI_FONT and GUI_FONT_PROP. However, μC / GUI itself only supports English, and does not provide Chinese font library source file files. The system implements the display of Chinese characters on the basis of modifying the μC / GUI font library display driving function to display 12 * 12 o'clock Chinese characters as an example. The specific modification steps are as follows:
Step: Declare the global structure object Gui_Font12_Hz in gui.h;
Step 2: Define an array of tanked data;
Step 3: Define the structural body used to illustrate the word model data of each letter in the block storage method;
Step 4: Define a plurality of structures based on the Hanban internal code high, for the storage of the word library word mode encoding and the word mode data storage address;
Step 5: Add the Hanzhu file HZK12.c created to the μC / GUI project to call the display function in the main function.
Through the above steps, Chinese Chinese characters are displayed in the μC / GUI interface. After testing, Chinese characters are smooth and stable.
4.3 Picture Decoding Algorithm
JPEG picture decoding display includes parsing JPEG header file information, based on consecutive DCT encoded JPEG decoding algorithm processing, conversion image format, liquid crystal display, etc., the overall flow chart is shown in Figure 7.
4.3.1 Analysis of JPEG Head File Information
The process of JPEG decoding is initialized, obtaining related information in the JPEG header file, the method of this system is to design a series of structural corresponding header files, and store information represented by the tag, such as color information, sampling Comparison, picture size, quantization table, Huffman decoding table and other important information.
4.3.2 JPEG decoding algorithm based on continuous DCT encoding
The JPEG decoding algorithm based on continuous DCT encoding includes a total of three steps of entropy decoding, inverse quantization, and reverse discrete cosine transform (IDCT). The decoder structure diagram of the JPEG basic system is shown in Figure 8.
1) Entropy decoding. The input signal of the entropy decoding is a compressed bit stream, and the output is a quantization value of the decoded DCT transform coefficient. Restore the compressed image data to the quantization data block composed of the compressed image data to reduce the compressed AC coefficient and DC DC coefficients by finding the HUFFMAN decoding table.
Entropy Ethics performs DC DC Coefficient and the HUFFMAN Decoding of the AC AC Coefficient for read image data. The JPEG algorithm provides a standard Huffman code table. It has its own different features for each image, and the system entropy decoding adopts an adaptive HUFFMAN code table. Adaptive Huffman code tables, first, the characteristics of the image data are first, generate the code tree, and then push it to the HUFFMAN code table at all levels.
In the tag of the JPEG header file information, a table is defined to record the HUFFMAN tree its code length is limited to 16bits. JPEG header information typically contains four huffman code: The HUFFMAN code table for decoding the DC DC coefficient, which includes a brightness table and a chromatic table; for decoding the HUFFMAN code table for the AC AC coefficient, including a brightness table and A chromatic table. According to the save form of the Huffman code table, the program flow chart is shown in Figure 9 in the save form of the HUFFMAN code table.
When decoding, enter the image compressed data stream, read the code word composed of bit data in the data stream, search the code of the codeword in the HUFFMAN tree, determine the decoded value according to the position of the codeword, decoding the output result is an 8 Bit value. During the Huffman decoding process, if an 0xFF is generated, use 0xFF0x00 instead, and the 0xFF0x00 is processed when doing 0xFF.
(2) Inverse quantization. The inverse input signal is the data after entropy decoding, and the calculation is calculated by checking the quantitative table, and the frequency coefficient after the DCT transformation is reduced during the compression process, and the inverse amount is DCT coefficient.
In the JPEG file, two quantization tables are included in the JPEG file, and the coefficient matrix decoded by the HUFFMAN is multiplied by the corresponding quantization matrix.
Since the data is "Z"-shaped rocking according to the 8 × 8 matrix, the results of the counter quantization operation are reversed zig-zag transform.
(3) Reverse discrete cosine transform (IDCT). Reverse discrete cosine transform turns the frequency domain DCT component coefficient to the image data represented by the color space domain. The DCT transform coefficient obtained after the reaction is reversed to obtain a pixel of the image. The input of the anti-extraction cosine conversion is an 8 × 8 component coefficient block in the frequency domain, and the output obtains an 8 × 8 pixel block in the spatial domain.
During the operation of the program, the IDCT is large, there is a large floating point multiplication and addition operation, and the program execution speed is slow, which has a great impact on whether the image can be smooth. Based on this practice, the IDCT algorithm is optimized, using a fast IDCT algorithm [5], decomposes two-dimensional IDCT into row and column two one-dimensional IDCT, and then converts the IDCT algorithm into the discrete Fourier transform (IDFT), simplifying the matrix transformation. When starting a two-dimensional IDCT conversion, first perform 8 single-dimensional row transformation on the input in quantization, and will store the result of the operation, and then the result of the result 8 times one-dimensional column transform, after twice Transform, resulting is the result of two-dimensional IDCT operation transformation. The program flow chart is shown in Figure 10.
4.3.3 Color mode conversion
Since the liquid crystal supports image data in the RGB format, it is necessary to convert the data of the YCRCB format obtained by the complete decoding process into the RGB mode, convert the 256-stage YCRCB color model to the RGB color model, as the formula (1).
Because R, G, B ranges [0, 255], it is necessary to threshold protection for the calculation result, the value of more than 255, which is limited to 255, less than 0, is limited to 0. The end of the end of the RGB. The image data of the mode is completed.
4.4 Picture Browse Mode
The image browsing mode of this system has a touch manual browsing and timing automatically browsing two modes. In the touch manual browsing mode, there is "Next", "Previous", "Exit" control. Implement the function of browsing the picture by operating a control on the touch screen. When browsing, the system will automatically jump to Zhang. In the timing automatic browsing mode, the interface only exits the control, every 3 seconds, automatically performs the next picture browsing, and circulates.
5. System debugging
5.1 Hardware debugging
With the hardware circuit design, check the electrical connection between the components, the basic debugger, the system board operation, when testing the USB enumeration, connected to the computer via the USB data cable, can read and write the Flash storage device.
5.2 Software Debugging
5.2.1 Compilation of the LIB library
The software development environment of this system is MDK. After the underlying driver of the basic module of the program, the STM32's underlying peripheral drive library and the μC / GUI library function are compiled into a lib library. When the post-program is developed, the program is greatly improved. Compiling efficiency, shorten the software development cycle.
5.2.2 FINSH Shell Debug Components This system uses the RT-THREAD embedded operating system to view the system health through its own user command line components FINSH shell. Enter the corresponding command through the HyperTermat Unit to use the FINSH shell.finsh shell in the RT-Thread into a separate thread. Enter the corresponding command via the serial port device, and the system parsed the user command to obtain system runtime information. The read and write operations for any register and memory address can also be called directly to call the system variable directly to the SHELL. The use of the FINSHSHELL component has largely improved the efficiency of the debugging program.
5.2.3 Picture Decoding Debug
Since the picture decoding algorithm takes up memory, consider that the image decoding algorithm may not function properly in STM32, when the correctness of the memory is not insufficient, the correctness of the picture decoding function is first running on the VC emulator of the PC. To provide a picture decoding algorithm to provide an ideal running platform. In the simulator, the image binary source code is stored with an array, and the array data of the image is decoded with the decoding algorithm to verify the correctness of the decoding algorithm. After the simulator is running correctly, port the image decoding algorithm to the system running, and the practice proves that STM32's memory is sufficient to support the image decoding algorithm. The effect map of the experiment runs in the VC simulator is shown in Figure 11.
6 Conclusion
This article describes the design scheme of the digital photo frame based on RT-Thread and STM32, and the browsing feature of the JPEG format image file is implemented by designing the related hardware circuit and software algorithm. The JPEG decoding algorithm based on continuous IDCT transformations in this system can correctly and stabilize the JPEG format image.Decoding, the decoding speed is faster, and the quality of the recovery image is good. Actual test shows that this program has strong practicability.
Source: Wiku Electronic Market Network
Our other product: