Chapter 20, Tiny4412 U-BOOT transplant 20 Add cleanlcd command

Publisher:Blissful567Latest update time:2021-12-09 Source: eefocusKeywords:Tiny4412 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1. Command format description

There is a lot of information on how to use the command on the Internet. I will just briefly explain it here:

Each command of U-Boot is defined by the U_Boot_CMD macro. This macro is defined in the header file. As shown below:

#ifdef CFG_LONGHELP

#define U_BOOT_CMD(name,maxargs,rep,cmd,usage,help)

cmd_tbl_t __u_boot_cmd_##name Struct_Section = {#name, maxargs, rep,cmd, usage, help}

#else    / no long help info*/

 

#define U_BOOT_CMD(name,maxargs,rep,cmd,usage,help)

cmd_tbl_t __u_boot_cmd_##name Struct_Section = {#name, maxargs, rep,cmd, usage}

#endif    / CFG_LONGHELP */

 

Each command defines a cmd_tbl_t structure, and cmd_tbl_t is just a typedef of cmd_tbl_s, as shown below:

typedef struct cmd_tbl_s cmd_tbl_t;

 

The definition of cmd_tbl_s is in the same file as shown below:

 

struct cmd_tbl_s {

    char       *name;        / Command Name  */

    int        maxargs;       /maximum number of arguments */

    int        repeatable;    / autorepeat allowed?   */

                    /Implementation function  */

    int        (*cmd)(struct cmd_tbl_s *, int, int,char *[]);

    char       *usage;        / Usage message    (short) */

#ifdef    CFG_LONGHELP

    char       *help;        / Help message    (long) */

#endif

 

#ifdef CONFIG_AUTO_COMPLETE

    / do auto completion onthe arguments */

    Int  (*complete)(int argc, char *argv[], charlast_char, nt maxv, char *cmdv[]);

#endif

};

 

Let's briefly explain the meaning of each variable in U_BOOT_CMD, or cmd_tbl_s structure:

1. name: the name of the command. Note that it is not a string (do not enclose it in commas).

2. maxargs: the maximum number of parameters.

2. Repeatable: Whether the command can be repeated. Repeatable means that after running a command, you can run it again by pressing Enter next time.

4. cmd: corresponding function pointer, type is (*cmd)(strunt cmd_tbl_s *, int,int,char *[]).

5. usage: a brief description of usage, this is a string

6. help: more detailed instructions for use, which is also a string.

 

In this way, each U-Boot command has a structure to describe it. The member variables of the structure include: command name, maximum number of parameters, number of repetitions, command execution function, usage, and help.

The commands entered from the console are interpreted and executed by the program in common/command.c. find_cmd() is responsible for matching the entered command, finding the corresponding command structure from the list and returning a pointer to this structure.

Based on the basic framework of U-Boot commands, the following briefly describes how to add Cleanlcd operation commands.


2. Add the cleanlcd command

1. Define the cleanlcd command

The flags of all commands supported by UBOOT are defined in and . Below we only add one line of command definition in config_cmd_all.h:

#define CONFIG_CMD_CLEANLCD /*add by zth*/

 

Among them, the commands defined in are supported by the board by default. This is because the header file is included in the board configuration file. If the board supports commands that are not in but in , relevant definitions must be made in the board configuration file. Therefore, if I do not define the cleanlcd command in , I must support the cleanlcd command in my . Therefore, open zthtiny4412.h and add the following commands:

#define CONFIG_CMD_CLEANLCD /*add by zth*/

Of course, you can also write this definition statement directly in .


2. Add cmd_cleanlcd.c file

The content is as follows:

/*

add by zth

this command use to clean the LcD

*/

#include

#include

#include

#include

#include

#include

 

#if defined(CONFIG_CMD_CLEANLCD)

static int do_clean_lcd(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])

{

 

         unsigned intcolour_value;

         if (argc < 2)

         {

                   printf("Yourcommand not right! Please chcek help; n");

                 return -1;

         }

 

         colour_value =simple_strtoul(argv[1], NULL, 16);

         colour_value=colour_value & 0xFFFFFF;

         //printf("colour_value=%sn",argv[1]);

         //printf("colour_value=%xn",colour_value);

          memset_int(LCD_VIDEO_ADDR, colour_value,VIDEO_MEM_SIZE);

          

          return 0;

}

 

U_BOOT_CMD(

         cleanlcd,  5,      1,      do_clean_lcd,

         "this just use toclean the lcd with a colour",

         "add by zth n"

         "commandformat:n"

         "cleanlcdcolour_valuen "

         "colour_value youcan use an 24bit valuen"

);

 

#endif

 

The first line of code in the file is:

memset_int(LCD_VIDEO_ADDR, colour_value,VIDEO_MEM_SIZE);

Why didn't I use memset()?

This is because when I debugged, I found that the program called

void * memset(void * s,char c,size_t count)

instead of:

void * memset(void * s,int c,size_t count)

In this case, the LCD display result is not what we want. In order to solve this problem, I directly used the memset_int in the bare metal program I wrote before. Here we need to define this function. In fact, it has already been written in our code, but it has been commented. The following two lines of code define it.


3. Modify zth_tiny4412_lcd.h and zth_tiny4412_lcd.c and files

Open zth_tiny4412_lcd.h, locate around line 24: remove the comments and modify it to:

extern void memset_int(unsigned int * s, int c,unsigned int count);

 

Open zth_tiny4412_lcd.c and locate around line 46: remove the comments and modify it to

void memset_int(unsigned int * s, int c,unsigned int count)

{

         unsigned int *xs =(unsigned int *) s;

         while (count--)

                   *xs++ = c;

         //return s;

}

Then locate around line 262 and modify it to:

memset_int((void *)pGD->frameAdrs, 0xFF00, pGD->memSize);

 

4. Modify /common/makefile

Open /common/makefile, locate around line 83, and add:

COBJS-$(CONFIG_CMD_CLEANLCD) +=cmd_cleanlcd.o

After completing the above 4 steps, you can compile, burn and run. The following commands are provided for reference:

cp -R /media/sf_share/u-boot_zth .

chmod 777 -R u-boot_zth /

cd u-boot_zth

make distclean

make zthtiny4412_config

make

cd sd_fuse/

make

cd zthtiny4412/

./sd_fusing.sh /dev/sdb

After running, enter the help command in the serial debugging terminal, and you can find the newly added cleanlcd command, as shown in the following figure:


Figure 20-1. Newly added command running effect diagram


Use the cleanlcd command to display a color, for example, the command: cleanlcd0x995500, the running effect is as shown in the figure below:


Figure 20-2 LCD effect of command execution

Keywords:Tiny4412 Reference address:Chapter 20, Tiny4412 U-BOOT transplant 20 Add cleanlcd command

Previous article:Chapter 8. Timing and Principle of Eight SDRAM Transplantation in Tiny4412 U-BOOT
Next article:tiny4412 UART sends and receives data

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号