2808 views|0 replies

3836

Posts

19

Resources
The OP
 

MCU driver GEC6818 program development record [Copy link]

JPG format images can be displayed on the GEC6818 development platform

I. Task: Display RGB color LCD screen --> For example: Fill the LCD with purple.
1. Analysis of technical points
1) Understand the composition and architecture of LCD screen?
2) How to handle LCD screen on embedded platform?
3) How to access LCD screen in engineering?
4) How to write data to LCD screen? What is data? How to represent color?

II. Study LCD screen parameters
1. What is resolution? What is the resolution of LCD screen on GEC6818 platform?
Resolution refers to the total number of pixels of the device, for example: TV 1080*720 -> There are 1080*720 pixels in total
GEC6818 platform resolution -> 800*480

2. What is a pixel?
Pixel is an image element, which refers to a point composed of RGB colors.

3. How is each pixel composed?
How many bytes does a pixel occupy? --> By entering the command on the GEC6818 platform, we know
[root@GEC6818 /]#cat /sys/class/graphics/fb0/bits_per_pixel
32

---> 1 pixel --> 32 bits
Known: 1 byte = 8 bits
---> 1 pixel --> 4 bytes

Conclusion: Each pixel --> transparency, red, green, blue

III. How to handle LCD screens on embedded platforms?
Principle: Under Linux, everything is a file. ---> Under Linux, the LCD screen is regarded as a file.
What is the file name corresponding to the LCD screen?
---> Rule: The file name of the embedded platform hardware device is stored in the dev directory dev->device

1. Switch to the /dev directory
[root@GEC6818 /]#cd /dev/
[root@GEC6818 /dev]#

2. What are all the file names in the current directory?
[root@GEC6818 /dev]#ls
fb0 --> The file name of the LCD screen

IV. How to access/close the LCD screen in a project? --> New function: open
1. In Ubuntu, enter the command to view the usage of the open function
gec@ubuntu:~$ man 2 open --> End the query-> Press 'q'

What is the header file?
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

What is the function prototype?
int open(const char *pathname, int flags);

What are the parameters?
pathname: The path name of the file to be opened -> Where is the file?
flags: The permission to operate the file
O_RDONLY --> read only -> read only
O_WRONLY --> write only -> write only
O_RDWR --> read write -> readable and writable

What is the return value?
Success: new file descriptor -> new file descriptor --> Actually greater than or equal to 0 >=0
Failure: -1

2. How to close?
In Ubuntu, enter the command to view the usage of the close function:
What is the header file?
#include <unistd.h>

What is the function prototype? What is the parameter of
int close(int fd);? fd: -> file descriptor -> file descriptor What is the return value? Success: 0 Failure: -1 Exercise: Write a program --> LCD device name: /dev/fb0 1. First access the LCD screen. If the access is successful, print open lcd ok in the terminal! If the access fails, print open lcd error! 2. Then close the LCD screen. If the closure is successful, print close lcd ok in the terminal! If the closure fails, print close lcd error! Reference code: ------------------------------------------ #include <stdio.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <unistd.h> int main() //->Function header { //->Function body, write some executable content //->Use printf to include the header file printf("this is first program!\n"); int lcd_fd; //File descriptor for LCD screen lcd_fd = open("/dev/fb0",O_RDWR);
































if(lcd_fd >= 0)
{
printf("open lcd ok!\n");
}
else{
printf("open lcd error!\n");
}

int ret;
ret = close(lcd_fd);
if(ret == 0)
{
printf("close lcd ok!\n");
}
else{
printf("close lcd error!\n");
}

return 0; //->Return value Success: 0 Failure: non-0
}
---------------------------------------

V. How to write data to the LCD screen? What is the data? How to represent the color?
1. How to write? --> New function: write()
Input query command in Ubuntu:
gec@ubuntu:/mnt/hgfs/zdnf/02$ man 2

What is the write header file?
#include <unistd.h>

What is the function prototype?
ssize_t write(int fd, const void *buf, size_t count);

What should be filled in the parameter?
fd: -> file descriptor -> file descriptor
buf: -> buffer --> buffer for written data --> RGB color
count: --> total number of bytes written

What is the return value?
Success: number of bytes written
Failure: -1

2. What is the data?
Since the task is to fill the LCD screen with RGB color, the data should be RGB color.

write()
color--------> LCD liquid crystal

3. How to represent color?
Conclusion: Each pixel --> transparency, red, green, blue

Example: How to represent red?
1 pixel = 32 bits000000001111111100000000000000000
--> red
0x00FF0000 --> red
0x00FF00FF --> purple
0x00FFFF00 --> yellow

---------------------Fill with redSample code-------------------------------
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>

int main() //->Function header
{
//->Function body, write some executable content
//->Use printf only when header file is includedprintf
("this is first program!\n");

int lcd_fd;//File descriptor for LCD screenlcd_fd
= open("/dev/fb0",O_RDWR);
if(lcd_fd >= 0)
{
printf("open lcd ok!\n");
}
else{
printf("open lcd error!\n");
}

int color = 0x00FF0000;

int i;
for(i=0;i<800*480;i++)
{
write(lcd_fd,&color,4);
}

int ret;
ret = close(lcd_fd);
if(ret == 0)
{
printf("close lcd ok!\n");
}
else{
printf("close lcd error!\n");
}

return 0; //->Return value Success: 0 Failure: non-zero
}
-----------------------------------------------

Exercise: Fill the LCD screen with purple.


I.Project: Network-based remote control multimedia system
socket communication
client <------------> server
UI interface Play video
touch screen Control video status

II. How to design UI interface? JPG format graphic features? How to display JPG images on LCD screen?
1. How to design UI interface?
Known GEC6818 platform LCD screen resolution->800*480 --> Horizontal: 800 pixels Vertical: 480 pixels
Want to display JPG format images on LCD full screen-> UI interface-> Resolution: 800*480

2. Design UI interface according to project requirements
1) Button content
Control video status: fast forward, fast rewind, volume +, volume -, pause/resume, mute/resume, exit.

2) Button size-> Since the touch screen controls the button in the client, the range of the button must be clearly known!
Drawing software:
Resize-> Pixels-> Remove the "Keep aspect ratio" option
Horizontal: 800
Vertical: 480

3. Why choose to use jpg format images?
Since jpg format files are compressed, the file size is smaller than other format images, which is convenient for data transmission during development.
And to display jpg images, compile and transplant the jpg library, and then the jpg source code calls the interface in the library.

3. How to display JPG images on the LCD screen?
Task: UI.jpg --> Display on the GEC6818 platform
First get two files:
jpeg_show.c --> Display the source code of jpg images
jpegsrc.v9a.tar.gz --> jpg library

1. In Ubuntu, switch to the path where the source code is located
gec@ubuntu:~$ cd /mnt/hgfs/zdnf/02/

2. Try to compile the source code in the Ubuntu Linux system:
gec@ubuntu:/mnt/hgfs/zdnf/02$ arm-linux-gcc jpeg_show.c -o jpeg_show
compilation error:
error: jpeglib.h: No such file or directory -> The header file jpeglib.h cannot be found.

jpeglib.h-> Actually exists in the jpg library, so before compiling, you must first compile and transplant the jpg library.

4. Compile and transplant the jpg library?
1. What is compilation and transplantation?
Actually, it is to install the files of jpg library into Ubuntu linux system.

2. How to compile and transplant?
jpegsrc.v9a.tar.gz --> jpg library: Open source and free

1) First put the jpg library in a shared directory
2) In linux, switch to the path where the jpg library is located
gec@ubuntu:~$ cd /mnt/hgfs/zdnf/02/

3) Unzip the jpg library in linux, usually unzip it to the home directory --> Because the home directory has all permissions.
gec@ubuntu:/mnt/hgfs/zdnf/02$ tar zxvf jpegsrc.v9a.tar.gz -C ~

tar: Linux command for decompression/compression
z: Processing compressed packages ending with .gz
x: Decompression c: Compression
v: Decompression in a visible way, this parameter is not required.
f: file
-C: specifies the path after decompression
~: home directory

If there is a v option, the decompression process will be printed
jpeg-9a/
jpeg-9a/wrppm.c
jpeg-9a/wrrle.c
jpeg-9a/maketdsp.vc6
jpeg-9a/jdinput.c

4) Go back to the home directory and see if there is a new directory called jpeg-9a/
gec@ubuntu:/mnt/hgfs/zdnf/02$ cd ~
gec@ubuntu:~$ ls --> see the jpeg-9a/ directory

5) Create a new directory in the home directory as the directory after installation and give it permissions
Create directory linux command: mkdir --> make diretcory

gec@ubuntu:~$ mkdir jpgbuf --> create directory
gec@ubuntu:~$ chmod 777 jpgbuf --> modify directory permissions

Why modify directory permissions?
Because in Windows, a new folder is created, we can directly drop the file into it.
But in Linux, when you create a new directory, there is no write permission by default, and we cannot drop files into it, so there is no way to install it in the directory

--> Conclusion: After creating the directory, give permissions through the chmod command.

6) Switch to the unzipped directory
gec@ubuntu:~$ cd ~/jpeg-9a/
gec@ubuntu:~/jpeg-9a$ ls --> See a file called configure -> configuration file.

7) Configure
gec@ubuntu:~/jpeg-9a$ ./configure --host=arm-linux --prefix=/home/gec/jpgbuf

Among them:
./configure --> Execute the configure file in the current directory
--host=arm-linux --> Specify cross compilation
--prefix=/home/gec/jpgbuf --> Specify the installation path

8) Compile
gec@ubuntu:~/jpeg-9a$ make
make all-am
make[1]: Entering directory `/home/gec/jpeg-9a'
make[1]: Leaving directory `/home/gec/jpeg-9a' --> You need to clear the link file

gec@ubuntu: ~/jpeg-9a$ make clean -> Clear link files
rm -f cjpeg djpeg jpegtran rdjpgcom wrjpgcom
test -z "testout.ppm testout.bmp testout.jpg testoutp.ppm testoutp.jpg testoutt.jpg" || rm -f testout .ppm testout.bmp testout.jpg testoutp.ppm testoutp.jpg testoutt.jpg
test -z "libjpeg.la" || rm -f libjpeg.la
rm -f ./so_locations
rm -rf .libs _libs
rm -f *. o
rm -f *.lo

gec@ubuntu:~/jpeg-9a$ make --> Recompile
CC jaricom.lo
CC jcapimin.lo
CC jcapistd.lo --> Compiling

9) Install
gec@ubuntu:~/jpeg-9a$ make install

Installation result :Switch to the jpgbuf path and look at
gec@ubuntu:~/jpeg-9a$ cd ~/jpgbuf
gec@ubuntu:~/jpgbuf$ ls
bin include lib share --> If you see 4 directories, compile and transplant the jpg library Success!

5. What are the files after analyzing the jpg library compilation and transplantation?
bin:
cjpeg djpeg jpegtran rdjpgcom wrjpgcom --> binary files

include:
jconfig.h jerror.h jmorecfg.h jpeglib.h --> jpg library header files

lib:
libjpeg.a libjpeg.la libjpeg.so libjpeg.so.9 libjpeg .so.9.1.0 --> Library file

share:
man --> Help document

Six. The compilation and porting have been completed. Next, let the source code call the contents of the library.
1. Switch to the source code location
gec@ubuntu:~/jpgbuf /share$ cd /mnt/hgfs/zdnf/02/

2. Recompile
gec@ubuntu:/mnt/hgfs/zdnf/02$ arm-linux-gcc jpeg_show.c -o jpeg_show
Compilation error: error: jpeglib.h: No such file or directory

Why can't I find it after compiling and transplanting?
After the user compiles and transplants the jpg library, the compiler does not know that the compilation has been completed, so we need to tell the compiler where the header file is.

How to tell the compiler where the header file is? --> Use compiler options: -I header file pathgec

@ubuntu:/mnt/hgfs/zdnf/02$ arm-linux-gcc jpeg_show.c -o jpeg_show -I /home/gec/jpgbuf/include
Compilation error :
/tmp/cc2O0oBN.o: In function `main':
jpeg_show.c:(.text+0x440): undefined reference to `jpeg_std_error'
jpeg_show.c:(.text+0x45c): undefined reference to `jpeg_CreateDecompress'
jpeg_show. c:(.text+0x474): undefined reference to `jpeg_mem_src'

Reason: The corresponding function definition cannot be found. The function definition is actually in the library file. If the function definition cannot be found, it means that the library file cannot be found. The library file is in lib.

How to tell the compiler where the library file is? --> Use compiler options: -L library file path -l library name

gec@ubuntu:/mnt/hgfs/zdnf/02$ arm-linux-gcc jpeg_show.c -o jpeg_show -I /home/gec/ jpgbuf/include -L /home/gec/jpgbuf/lib
compilation error:
/tmp/cc2O0oBN.o: In function `main':
jpeg_show.c:(.text+0x440): undefined reference to `jpeg_std_error'
jpeg_show.c: (.text+0x45c): undefined reference to `jpeg_CreateDecompress'
jpeg_show.c:(.text+0x474): undefined reference to `jpeg_mem_src'

-l library name --> -l is followed by
libjpeg.so.9.1 without a space .0 --> The library name is lib and .so middle name
--> -ljpeg

gec@ubuntu:/mnt/hgfs/zdnf/02$ arm-linux-gcc jpeg_show.c -o jpeg_show -I /home/gec/jpgbuf/include -L /home/gec/jpgbuf/lib -ljpeg
The compilation is successful and a new file is generated: jpeg_show

VII. Burn the program to the development board
1. Burn the executable program and enter the burn command
[root@GEC6818 /]#cd /
[root@GEC6818 /]#rx jpeg_show
C

2. Transfer->Send Xmodom->Select jpeg_show file->Send
3. Modify permissions
[root@GEC6818 /]#chmod 777 jpeg_show

4. Execute
[root@GEC6818 /]#./jpeg_show
./jpeg_show: error while loading shared libraries: libjpeg.so.9: cannot open shared object file: No such file or directorySolution

: Download the missing library libjpeg.so.9 to the /lib of the development board5

. Download libjpeg.so.9 to the development board
[root@GEC6818 /]#cd /lib
[root@GEC6818 /lib]#rx libjpeg.so.9
C

transfer->Send Xmodom->Select libjpeg.so.9 file->Send6

. Return to the root directory and download the image to the development board
[root@GEC6818 /]#cd /
[root@GEC6818 /]#rx UI.jpg
C

transfer->Send Xmodom->Select UI.jpg file->Send

This post is from Microcontroller MCU
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list