application.c 3.9 KB
Newer Older
M
Ming, Bai 已提交
1 2 3 4 5 6 7 8 9 10 11 12
/*
 * File      : application.c
 * This file is part of RT-Thread RTOS
 * COPYRIGHT (C) 2006, RT-Thread Development Team
 *
 * The license and distribution terms for this file may be
 * found in the file LICENSE in this distribution or at
 * http://www.rt-thread.org/license/LICENSE
 *
 * Change Logs:
 * Date           Author       Notes
 * 2009-01-05     Bernard      the first version
wuyangyong's avatar
wuyangyong 已提交
13
 * 2013-07-12     aozima       update for auto initial.
M
Ming, Bai 已提交
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
 */

/**
 * @addtogroup STM32
 */
/*@{*/

#include <board.h>
#include <rtthread.h>

#ifdef RT_USING_DFS
/* dfs filesystem:ELM filesystem init */
#include <dfs_elm.h>
/* dfs Filesystem APIs */
#include <dfs_fs.h>
#endif

#ifdef RT_USING_RTGUI
#include <rtgui/rtgui.h>
#include <rtgui/rtgui_server.h>
#include <rtgui/rtgui_system.h>
#include <rtgui/driver.h>
36
#include <rtgui/calibration.h>
M
Ming, Bai 已提交
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
#endif

#include "led.h"

ALIGN(RT_ALIGN_SIZE)
static rt_uint8_t led_stack[ 512 ];
static struct rt_thread led_thread;
static void led_thread_entry(void* parameter)
{
    unsigned int count=0;

    rt_hw_led_init();

    while (1)
    {
        /* led1 on */
#ifndef RT_USING_FINSH
        rt_kprintf("led on, count : %d\r\n",count);
#endif
        count++;
        rt_hw_led_on(0);
        rt_thread_delay( RT_TICK_PER_SECOND/2 ); /* sleep 0.5 second and switch to other thread */

        /* led1 off */
#ifndef RT_USING_FINSH
        rt_kprintf("led off\r\n");
#endif
        rt_hw_led_off(0);
        rt_thread_delay( RT_TICK_PER_SECOND/2 );
    }
}

69 70 71 72 73 74 75 76 77 78
#ifdef RT_USING_RTGUI
rt_bool_t cali_setup(void)
{
    rt_kprintf("cali setup entered\n");
    return RT_FALSE;
}

void cali_store(struct calibration_data *data)
{
    rt_kprintf("cali finished (%d, %d), (%d, %d)\n",
wuyangyong's avatar
wuyangyong 已提交
79 80 81 82
               data->min_x,
               data->max_x,
               data->min_y,
               data->max_y);
83
}
wuyangyong's avatar
wuyangyong 已提交
84
#endif /* RT_USING_RTGUI */
85

M
Ming, Bai 已提交
86 87
void rt_init_thread_entry(void* parameter)
{
wuyangyong's avatar
wuyangyong 已提交
88 89 90
#ifdef RT_USING_COMPONENTS_INIT
    /* initialization RT-Thread Components */
    rt_components_init();
M
Ming, Bai 已提交
91 92
#endif

wuyangyong's avatar
wuyangyong 已提交
93 94 95 96 97 98 99 100 101 102
    /* Filesystem Initialization */
#if defined(RT_USING_DFS) && defined(RT_USING_DFS_ELMFAT)
    /* mount sd card fat partition 1 as root directory */
    if (dfs_mount("sd0", "/", "elm", 0, 0) == 0)
    {
        rt_kprintf("File System initialized!\n");
    }
    else
        rt_kprintf("File System initialzation failed!\n");
#endif  /* RT_USING_DFS */
M
Ming, Bai 已提交
103 104

#ifdef RT_USING_RTGUI
wuyangyong's avatar
wuyangyong 已提交
105 106 107
    {
        extern void rt_hw_lcd_init();
        extern void rtgui_touch_hw_init(void);
M
Ming, Bai 已提交
108

wuyangyong's avatar
wuyangyong 已提交
109
        rt_device_t lcd;
M
Ming, Bai 已提交
110

wuyangyong's avatar
wuyangyong 已提交
111 112
        /* init lcd */
        rt_hw_lcd_init();
M
Ming, Bai 已提交
113

wuyangyong's avatar
wuyangyong 已提交
114 115
        /* init touch panel */
        rtgui_touch_hw_init();
M
Ming, Bai 已提交
116

wuyangyong's avatar
wuyangyong 已提交
117 118
        /* find lcd device */
        lcd = rt_device_find("lcd");
M
Ming, Bai 已提交
119

wuyangyong's avatar
wuyangyong 已提交
120 121
        /* set lcd device as rtgui graphic driver */
        rtgui_graphic_set_device(lcd);
M
Ming, Bai 已提交
122

123
#ifndef RT_USING_COMPONENTS_INIT
wuyangyong's avatar
wuyangyong 已提交
124 125
        /* init rtgui system server */
        rtgui_system_server_init();
126
#endif
127 128 129 130

        calibration_set_restore(cali_setup);
        calibration_set_after(cali_store);
        calibration_init();
wuyangyong's avatar
wuyangyong 已提交
131
    }
M
Ming, Bai 已提交
132 133 134
#endif /* #ifdef RT_USING_RTGUI */
}

wuyangyong's avatar
wuyangyong 已提交
135
int rt_application_init(void)
M
Ming, Bai 已提交
136
{
wuyangyong's avatar
wuyangyong 已提交
137
    rt_thread_t init_thread;
M
Ming, Bai 已提交
138

wuyangyong's avatar
wuyangyong 已提交
139
    rt_err_t result;
M
Ming, Bai 已提交
140 141

    /* init led thread */
wuyangyong's avatar
wuyangyong 已提交
142 143 144 145 146 147 148 149 150 151
    result = rt_thread_init(&led_thread,
                            "led",
                            led_thread_entry,
                            RT_NULL,
                            (rt_uint8_t*)&led_stack[0],
                            sizeof(led_stack),
                            20,
                            5);
    if (result == RT_EOK)
    {
M
Ming, Bai 已提交
152
        rt_thread_startup(&led_thread);
wuyangyong's avatar
wuyangyong 已提交
153
    }
M
Ming, Bai 已提交
154 155

#if (RT_THREAD_PRIORITY_MAX == 32)
wuyangyong's avatar
wuyangyong 已提交
156 157 158
    init_thread = rt_thread_create("init",
                                   rt_init_thread_entry, RT_NULL,
                                   2048, 8, 20);
M
Ming, Bai 已提交
159
#else
wuyangyong's avatar
wuyangyong 已提交
160 161 162
    init_thread = rt_thread_create("init",
                                   rt_init_thread_entry, RT_NULL,
                                   2048, 80, 20);
M
Ming, Bai 已提交
163 164
#endif

wuyangyong's avatar
wuyangyong 已提交
165 166
    if (init_thread != RT_NULL)
        rt_thread_startup(init_thread);
M
Ming, Bai 已提交
167

wuyangyong's avatar
wuyangyong 已提交
168
    return 0;
M
Ming, Bai 已提交
169 170 171
}

/*@}*/