uboot基础(1)——uboot shell(RK3399)

39 篇文章 13 订阅

RK3399 进入uboot shell的默认键值是CTRL+C,改为space按键。

按键键码值

参考链接:
在线获取键盘按键值(keycode,ascii码)
https://www.bejson.com/othertools/keycodes/

CTRL+C的键值是0x03
spacebar的键值是0x20

查看一下uboot中读取ctrl+c键值的函数ctrlc(),如下:

ctrlc()

/* test if ctrl-c was pressed */
static int ctrlc_disabled = 0;  /* see disable_ctrl() */
static int ctrlc_was_pressed = 0;
int ctrlc(void)
{
#if defined(CONFIG_CONSOLE_DISABLE_CTRLC) && \
    defined(CONFIG_BOOTDELAY) && (CONFIG_BOOTDELAY <= 0)
        return 0;
#endif

#ifndef CONFIG_SANDBOX
        if (!ctrlc_disabled && gd->have_console) {
                if (tstc()) {							//调用tstc()函数
                        switch (getc()) {				//调用getc()函数
                        case 0x03:              /* ^C - Control C */	//判断键值
                                ctrlc_was_pressed = 1;
                                return 1;
                        default:
                                break;
                        }
                }
        }
#endif

        return 0;
}

(根据上面的内容推断CTRL+A的键值应该是0x01,以此类推)
再来看一下函数ctrlc()调用的两个函数tstc()和getc():

tstc()

int tstc(void)
{
#ifdef CONFIG_DISABLE_CONSOLE
        if (gd->flags & GD_FLG_DISABLE_CONSOLE)
                return 0;
#endif

        if (!gd->have_console)
                return 0;
#ifdef CONFIG_CONSOLE_RECORD
        if (gd->console_in.start) {
                if (membuff_peekbyte((struct membuff *)&gd->console_in) != -1)
                        return 1;
        }
#endif
        if (gd->flags & GD_FLG_DEVINIT) {
                /* Test the standard input */	//判断是否是标准输入
                return ftstc(stdin);
        }

        /* Send directly to the handler */
        return serial_tstc();
}

tstc()函数用到了gd->flags,gd的相关内容这里不做分析,可以参考如下链接:

gd->flags

uboot 之 gd分析
https://blog.csdn.net/qq_15715753/article/details/102658881

getc()

用于获取键盘输入的字符

int getc(void)
{
#ifdef CONFIG_DISABLE_CONSOLE
        if (gd->flags & GD_FLG_DISABLE_CONSOLE)
                return 0;
#endif

        if (!gd->have_console)
                return 0;

#ifdef CONFIG_CONSOLE_RECORD
        if (gd->console_in.start) {
                int ch;

                ch = membuff_getbyte((struct membuff *)&gd->console_in);
                if (ch != -1)
                        return 1;
        }
#endif
        if (gd->flags & GD_FLG_DEVINIT) {
                /* Get from the standard input */
                return fgetc(stdin);				//调用fgetc函数获取键盘的标准输入
        }

        /* Send directly to the handler */
        return serial_getc();
}

仿照ctrlc()函数编写spacebar键值检测函数

spacebar()

/* test if spacebar was pressed */
static int spacebar_disabled = 0;  /* see disable_ctrl() */
static int spacebar_was_pressed = 0;
int spacebar(void)
{
#if defined(CONFIG_CONSOLE_DISABLE_SPACEBAR) && \
    defined(CONFIG_BOOTDELAY) && (CONFIG_BOOTDELAY <= 0)
        return 0;
#endif

#ifndef CONFIG_SANDBOX
        if (!spacebar_disabled && gd->have_console) {
                if (tstc()) {
                        switch (getc()) {
                        case 0x20:          /* spacebar code */	//判断space按键的键值
                                spacebar_was_pressed = 1;
                                return 1;
                        default:
                                break;
                        }
                }
        }
#endif

        return 0;
}

将接口函数替换到对应的倒计时检测逻辑中即可。


fgetc()

int fgetc(int file)
{
        if (file < MAX_FILES) {
#if CONFIG_IS_ENABLED(CONSOLE_MUX)
                /*
                 * Effectively poll for input wherever it may be available.
                 */
                for (;;) {
                        WATCHDOG_RESET();
                        /*
                         * Upper layer may have already called tstc() so
                         * check for that first.
                         */
                        if (tstcdev != NULL)
                                return console_getc(file);
                        console_tstc(file);
#ifdef CONFIG_WATCHDOG
                        /*
                         * If the watchdog must be rate-limited then it should
                         * already be handled in board-specific code.
                         */
                         udelay(1);
#endif
                }
#else
                return console_getc(file);
#endif
        }

        return -1;
}
  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值