application.c 3.7 KB
Newer Older
M
Ming, Bai 已提交
1
/*
2
 * Copyright (c) 2006-2021, RT-Thread Development Team
M
Ming, Bai 已提交
3
 *
4
 * SPDX-License-Identifier: Apache-2.0
M
Ming, Bai 已提交
5 6 7 8 9 10 11 12 13
 *
 * Change Logs:
 * Date           Author       Notes
 * 2011-02-24     Bernard      the first version
 */

/**
 * @addtogroup FM3
 */
14

M
Ming, Bai 已提交
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
/*@{*/

#include <rtthread.h>
#include "board.h"
#include "led.h"
#include "key.h"
#include "adc.h"
#include "lcd.h"
#include "cpuusage.h"

#ifdef RT_USING_RTGUI
#include <rtgui/rtgui.h>
#include <rtgui/driver.h>
extern void rtgui_startup();
#endif

struct rt_messagequeue mq;
static char msg_pool[2048];

void rt_init_thread_entry(void *parameter)
{
36 37
    rt_device_t lcd;

M
Ming, Bai 已提交
38
    rt_hw_led_init();
39 40 41 42
    rt_hw_key_init();
    rt_hw_adc_init();
    rt_hw_lcd_init();
    rt_hw_cpu_init();
43

M
Ming, Bai 已提交
44
#ifdef RT_USING_RTGUI
45 46 47 48 49 50 51 52 53 54 55 56 57
    extern void rtgui_system_server_init(void);

    /* find lcd device */
    lcd = rt_device_find("lcd");

    /* set lcd device as rtgui graphic driver */
    rtgui_graphic_set_device(lcd);

    /* init rtgui system server */
    rtgui_system_server_init();

    /* startup rtgui */
    rtgui_startup();
M
Ming, Bai 已提交
58
#else
59 60
    {
    char buf[20] = {'\0'};
M
Ming, Bai 已提交
61
    struct lcd_msg msg;
62
    rt_device_t device;
M
Ming, Bai 已提交
63
    device = rt_device_find("lcd");
64 65 66 67 68 69 70 71 72 73 74
    rt_device_control(device, RT_DEVICE_CTRL_LCD_CLEAR_SCR, RT_NULL);
    x = 1;
    y = 1;
    rt_device_control(device, RT_DEVICE_CTRL_LCD_PUT_STRING, "ADC");
    x = 1;
    y = 20;
    rt_device_control(device, RT_DEVICE_CTRL_LCD_PUT_STRING, "CPU");
    x = 1;
    y = 40;
    rt_device_control(device, RT_DEVICE_CTRL_LCD_PUT_STRING, "KEY");

M
Ming, Bai 已提交
75 76 77 78
    while(1)
    {
        if (rt_mq_recv(&mq, &msg, sizeof(msg), RT_WAITING_FOREVER) == RT_EOK)
        {
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
            switch(msg.type)
            {
                case ADC_MSG:
                    x = 40;
                    y = 1;
                    rt_memset(buf, 0, sizeof(buf));
                    rt_sprintf(buf, "%04d", msg.adc_value);
                    rt_device_control(device, RT_DEVICE_CTRL_LCD_PUT_STRING, buf);
                    break;
                case CPU_MSG:
                    x = 40;
                    y = 20;
                    rt_memset(buf, 0, sizeof(buf));
                    rt_sprintf(buf, "%03d %03d", msg.major, msg.minor);
                    rt_device_control(device, RT_DEVICE_CTRL_LCD_PUT_STRING, buf);
                    break;
                case KEY_MSG:
                    x = 40;
                    y = 40;
                    rt_memset(buf, 0, sizeof(buf));
M
Ming, Bai 已提交
99
                    switch(msg.key)
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
                    {
                        case KEY_DOWN:
                            rt_sprintf(buf, "DOWN KEY ");
                            break;
                        case KEY_UP:
                            rt_sprintf(buf, "UP KEY   ");
                            break;
                        case KEY_RIGHT:
                            rt_sprintf(buf, "RIGHT KEY");
                            break;
                        case KEY_LEFT:
                            rt_sprintf(buf, "LEFT KEY ");
                            break;
                        case KEY_ENTER:
                            rt_sprintf(buf, "ENTER KEY");
                            break;
                        default:
                            rt_sprintf(buf, "NO KEY   ");
                            break;
                    }
                    rt_device_control(device, RT_DEVICE_CTRL_LCD_PUT_STRING, buf);
                    break;
            }
M
Ming, Bai 已提交
123 124
        }
    }
125
    }
M
Ming, Bai 已提交
126 127 128 129 130 131 132
#endif
}

int rt_application_init(void)
{
    rt_thread_t init_thread;

133 134
    rt_mq_init(&mq, "mqt", &msg_pool[0], 128 - sizeof(void*), sizeof(msg_pool), RT_IPC_FLAG_FIFO);

M
Ming, Bai 已提交
135 136 137
    init_thread = rt_thread_create("init", rt_init_thread_entry, RT_NULL, 1024, 21, 20);
    if(init_thread != RT_NULL)
        rt_thread_startup(init_thread);
138

M
Ming, Bai 已提交
139 140 141 142
    return 0;
}

/*@}*/