update FM3 IAR project
add cpu usage displaying control LED3 by ADC git-svn-id: https://rt-thread.googlecode.com/svn/trunk@1326 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
parent
79696e8649
commit
46743c4f34
|
@ -20,6 +20,7 @@
|
||||||
|
|
||||||
#include "mb9bf506r.h"
|
#include "mb9bf506r.h"
|
||||||
#include "adc.h"
|
#include "adc.h"
|
||||||
|
#include "led.h"
|
||||||
|
|
||||||
static struct rt_device adc;
|
static struct rt_device adc;
|
||||||
|
|
||||||
|
@ -46,7 +47,6 @@ static rt_err_t rt_adc_init(rt_device_t dev)
|
||||||
|
|
||||||
dev->flag |= RT_DEVICE_FLAG_ACTIVATED;
|
dev->flag |= RT_DEVICE_FLAG_ACTIVATED;
|
||||||
}
|
}
|
||||||
|
|
||||||
return RT_EOK;
|
return RT_EOK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,7 +68,6 @@ static rt_err_t rt_adc_control(rt_device_t dev, rt_uint8_t cmd, void *args)
|
||||||
*((rt_uint16_t*)args) = (*((rt_uint16_t*)args)*3300)/1024;
|
*((rt_uint16_t*)args) = (*((rt_uint16_t*)args)*3300)/1024;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return RT_EOK;
|
return RT_EOK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,6 +86,7 @@ static void adc_thread_entry(void *parameter)
|
||||||
{
|
{
|
||||||
rt_device_control(device, RT_DEVICE_CTRL_ADC_START, RT_NULL);
|
rt_device_control(device, RT_DEVICE_CTRL_ADC_START, RT_NULL);
|
||||||
rt_device_control(device, RT_DEVICE_CTRL_ADC_RESULT, &adc_value);
|
rt_device_control(device, RT_DEVICE_CTRL_ADC_RESULT, &adc_value);
|
||||||
|
pwm_update(adc_value/3);
|
||||||
rtgui_thread_send(info_tid, &ecmd.parent, sizeof(ecmd));
|
rtgui_thread_send(info_tid, &ecmd.parent, sizeof(ecmd));
|
||||||
rt_thread_delay(20);
|
rt_thread_delay(20);
|
||||||
}
|
}
|
||||||
|
@ -95,7 +95,7 @@ static void adc_thread_entry(void *parameter)
|
||||||
static rt_thread_t adc_thread;
|
static rt_thread_t adc_thread;
|
||||||
void rt_hw_adc_init(void)
|
void rt_hw_adc_init(void)
|
||||||
{
|
{
|
||||||
adc.type = RT_Device_Class_Char; /* fixme: should be adc type */
|
adc.type = RT_Device_Class_Char;
|
||||||
adc.rx_indicate = RT_NULL;
|
adc.rx_indicate = RT_NULL;
|
||||||
adc.tx_complete = RT_NULL;
|
adc.tx_complete = RT_NULL;
|
||||||
adc.init = rt_adc_init;
|
adc.init = rt_adc_init;
|
||||||
|
@ -106,7 +106,7 @@ void rt_hw_adc_init(void)
|
||||||
adc.control = rt_adc_control;
|
adc.control = rt_adc_control;
|
||||||
adc.user_data = RT_NULL;
|
adc.user_data = RT_NULL;
|
||||||
|
|
||||||
adc_thread = rt_thread_create("adc", adc_thread_entry, RT_NULL, 384, 29, 5);
|
adc_thread = rt_thread_create("adc", adc_thread_entry, RT_NULL, 384, 26, 5);
|
||||||
if(adc_thread != RT_NULL)
|
if(adc_thread != RT_NULL)
|
||||||
rt_thread_startup(adc_thread);
|
rt_thread_startup(adc_thread);
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
#include "key.h"
|
#include "key.h"
|
||||||
#include "adc.h"
|
#include "adc.h"
|
||||||
#include "lcd.h"
|
#include "lcd.h"
|
||||||
|
#include "cpuusage.h"
|
||||||
#include <rtgui/rtgui.h>
|
#include <rtgui/rtgui.h>
|
||||||
extern void rtgui_startup();
|
extern void rtgui_startup();
|
||||||
#endif
|
#endif
|
||||||
|
@ -37,6 +38,7 @@ void rt_init_thread_entry(void *parameter)
|
||||||
rt_hw_key_init();
|
rt_hw_key_init();
|
||||||
rt_hw_adc_init();
|
rt_hw_adc_init();
|
||||||
rt_hw_lcd_init();
|
rt_hw_lcd_init();
|
||||||
|
rt_hw_cpu_init();
|
||||||
|
|
||||||
/* re-init device driver */
|
/* re-init device driver */
|
||||||
rt_device_init_all();
|
rt_device_init_all();
|
||||||
|
|
|
@ -0,0 +1,100 @@
|
||||||
|
#include <rtthread.h>
|
||||||
|
#include <rthw.h>
|
||||||
|
#include <rtgui/event.h>
|
||||||
|
#include <rtgui/rtgui_server.h>
|
||||||
|
#include <rtgui/rtgui_system.h>
|
||||||
|
#include "cpuusage.h"
|
||||||
|
|
||||||
|
#define CPU_USAGE_CALC_TICK 10
|
||||||
|
#define CPU_USAGE_LOOP 100
|
||||||
|
|
||||||
|
static rt_uint8_t cpu_usage_major = 0, cpu_usage_minor= 0;
|
||||||
|
static rt_uint32_t total_count = 0;
|
||||||
|
|
||||||
|
static void cpu_usage_idle_hook()
|
||||||
|
{
|
||||||
|
rt_tick_t tick;
|
||||||
|
rt_uint32_t count;
|
||||||
|
volatile rt_uint32_t loop;
|
||||||
|
|
||||||
|
if (total_count == 0)
|
||||||
|
{
|
||||||
|
loop = 0;
|
||||||
|
|
||||||
|
/* get total count */
|
||||||
|
rt_enter_critical();
|
||||||
|
tick = rt_tick_get();
|
||||||
|
while(rt_tick_get() - tick < CPU_USAGE_CALC_TICK)
|
||||||
|
{
|
||||||
|
total_count ++;
|
||||||
|
while (loop < CPU_USAGE_LOOP) loop ++;
|
||||||
|
}
|
||||||
|
rt_exit_critical();
|
||||||
|
}
|
||||||
|
|
||||||
|
count = 0;
|
||||||
|
loop = 0;
|
||||||
|
/* get CPU usage */
|
||||||
|
tick = rt_tick_get();
|
||||||
|
while (rt_tick_get() - tick < CPU_USAGE_CALC_TICK)
|
||||||
|
{
|
||||||
|
count ++;
|
||||||
|
while (loop < CPU_USAGE_LOOP) loop ++;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* calculate major and minor */
|
||||||
|
if (count < total_count)
|
||||||
|
{
|
||||||
|
count = total_count - count;
|
||||||
|
cpu_usage_major = (count * 100) / total_count;
|
||||||
|
cpu_usage_minor = ((count * 100) % total_count) * 100 / total_count;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
total_count = count;
|
||||||
|
|
||||||
|
/* no CPU usage */
|
||||||
|
cpu_usage_major = 0;
|
||||||
|
cpu_usage_minor = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void cpu_usage_get(rt_uint8_t *major, rt_uint8_t *minor)
|
||||||
|
{
|
||||||
|
RT_ASSERT(major != RT_NULL);
|
||||||
|
RT_ASSERT(minor != RT_NULL);
|
||||||
|
|
||||||
|
*major = cpu_usage_major;
|
||||||
|
*minor = cpu_usage_minor;
|
||||||
|
}
|
||||||
|
|
||||||
|
void cpu_usage_init()
|
||||||
|
{
|
||||||
|
/* set idle thread hook */
|
||||||
|
rt_thread_idle_sethook(cpu_usage_idle_hook);
|
||||||
|
}
|
||||||
|
|
||||||
|
extern rt_thread_t info_tid;
|
||||||
|
static void cpu_thread_entry(void *parameter)
|
||||||
|
{
|
||||||
|
struct rtgui_event_command ecmd;
|
||||||
|
|
||||||
|
RTGUI_EVENT_COMMAND_INIT(&ecmd);
|
||||||
|
ecmd.type = RTGUI_CMD_USER_INT;
|
||||||
|
ecmd.command_id = CPU_UPDATE;
|
||||||
|
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
rtgui_thread_send(info_tid, &ecmd.parent, sizeof(ecmd));
|
||||||
|
rt_thread_delay(20);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static rt_thread_t cpu_thread;
|
||||||
|
void rt_hw_cpu_init(void)
|
||||||
|
{
|
||||||
|
cpu_usage_init();
|
||||||
|
cpu_thread = rt_thread_create("cpu", cpu_thread_entry, RT_NULL, 384, 27, 5);
|
||||||
|
if(cpu_thread != RT_NULL)
|
||||||
|
rt_thread_startup(cpu_thread);
|
||||||
|
}
|
|
@ -0,0 +1,23 @@
|
||||||
|
/*
|
||||||
|
* File : cpuusage.c
|
||||||
|
* This file is part of RT-Thread RTOS
|
||||||
|
* COPYRIGHT (C) 2011, RT-Thread Develop 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
|
||||||
|
* 2011-03-03 lgnq
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __CPUUSAGE_H__
|
||||||
|
#define __CPUUSAGE_H__
|
||||||
|
|
||||||
|
#define CPU_UPDATE 1
|
||||||
|
|
||||||
|
void cpu_usage_get(rt_uint8_t *major, rt_uint8_t *minor);
|
||||||
|
void rt_hw_cpu_init(void);
|
||||||
|
|
||||||
|
#endif /*__ADC_H__ */
|
|
@ -1989,6 +1989,9 @@
|
||||||
<file>
|
<file>
|
||||||
<name>$PROJ_DIR$\board.c</name>
|
<name>$PROJ_DIR$\board.c</name>
|
||||||
</file>
|
</file>
|
||||||
|
<file>
|
||||||
|
<name>$PROJ_DIR$\cpuusage.c</name>
|
||||||
|
</file>
|
||||||
<file>
|
<file>
|
||||||
<name>$PROJ_DIR$\info.c</name>
|
<name>$PROJ_DIR$\info.c</name>
|
||||||
</file>
|
</file>
|
||||||
|
|
110
bsp/fm3/info.c
110
bsp/fm3/info.c
|
@ -6,19 +6,20 @@
|
||||||
#include <rtgui/widgets/workbench.h>
|
#include <rtgui/widgets/workbench.h>
|
||||||
|
|
||||||
#include "adc.h"
|
#include "adc.h"
|
||||||
|
#include "cpuusage.h"
|
||||||
#include <rtthread.h>
|
#include <rtthread.h>
|
||||||
|
|
||||||
extern rt_uint16_t adc_value;
|
extern rt_uint16_t adc_value;
|
||||||
|
static rt_uint8_t index = 0 ;
|
||||||
static rt_bool_t view_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
|
static rt_bool_t view_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
|
||||||
{
|
{
|
||||||
if(event->type == RTGUI_EVENT_PAINT)
|
if (event->type == RTGUI_EVENT_PAINT)
|
||||||
{
|
{
|
||||||
struct rtgui_dc* dc;
|
struct rtgui_dc* dc;
|
||||||
struct rtgui_rect rect;
|
struct rtgui_rect rect;
|
||||||
|
|
||||||
dc = rtgui_dc_begin_drawing(widget);
|
dc = rtgui_dc_begin_drawing(widget);
|
||||||
if(dc == RT_NULL)
|
if (dc == RT_NULL)
|
||||||
return RT_FALSE;
|
return RT_FALSE;
|
||||||
rtgui_widget_get_rect(widget, &rect);
|
rtgui_widget_get_rect(widget, &rect);
|
||||||
|
|
||||||
|
@ -35,77 +36,112 @@ static rt_bool_t view_event_handler(struct rtgui_widget* widget, struct rtgui_ev
|
||||||
|
|
||||||
/* draw text */
|
/* draw text */
|
||||||
rtgui_widget_get_rect(widget, &rect);
|
rtgui_widget_get_rect(widget, &rect);
|
||||||
rect.x1 += 1;
|
rect.y1 += 25;
|
||||||
rect.y1 += 1;
|
rtgui_dc_draw_text(dc, " FM3 Easy Kit Demo", &rect);
|
||||||
rtgui_dc_draw_text(dc, "FM3 Easy Kit Demo", &rect);
|
|
||||||
rect.y1 += 10;
|
rect.y1 += 10;
|
||||||
rtgui_dc_draw_text(dc, "[rt-thread/RTGUI]", &rect);
|
rtgui_dc_draw_text(dc, " rt-thread / RTGUI", &rect);
|
||||||
|
|
||||||
rtgui_dc_end_drawing(dc);
|
rtgui_dc_end_drawing(dc);
|
||||||
|
|
||||||
return RT_FALSE;
|
return RT_FALSE;
|
||||||
}
|
}
|
||||||
else if(event->type == RTGUI_EVENT_KBD)
|
else if (event->type == RTGUI_EVENT_KBD)
|
||||||
{
|
{
|
||||||
|
struct rtgui_dc* dc;
|
||||||
|
struct rtgui_rect rect;
|
||||||
struct rtgui_event_kbd* ekbd = (struct rtgui_event_kbd*)event;
|
struct rtgui_event_kbd* ekbd = (struct rtgui_event_kbd*)event;
|
||||||
if(ekbd->type == RTGUI_KEYDOWN)
|
if (ekbd->type == RTGUI_KEYDOWN)
|
||||||
{
|
{
|
||||||
char key_str[16];
|
char key_str[16];
|
||||||
struct rtgui_dc* dc;
|
switch (ekbd->key)
|
||||||
struct rtgui_rect rect;
|
|
||||||
|
|
||||||
switch(ekbd->key)
|
|
||||||
{
|
{
|
||||||
case RTGUIK_LEFT:
|
case RTGUIK_LEFT:
|
||||||
rt_sprintf(key_str, "KEY = %s", "LEFT");
|
rt_sprintf(key_str, "%s", "L");
|
||||||
break;
|
break;
|
||||||
case RTGUIK_RIGHT:
|
case RTGUIK_RIGHT:
|
||||||
rt_sprintf(key_str, "KEY = %s", "RIGHT");
|
rt_sprintf(key_str, "%s", "R");
|
||||||
break;
|
break;
|
||||||
case RTGUIK_DOWN:
|
case RTGUIK_DOWN:
|
||||||
rt_sprintf(key_str, "KEY = %s", "DOWN");
|
rt_sprintf(key_str, "%s", "D");
|
||||||
break;
|
break;
|
||||||
case RTGUIK_UP:
|
case RTGUIK_UP:
|
||||||
rt_sprintf(key_str, "KEY = %s", "UP");
|
rt_sprintf(key_str, "%s", "U");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
rt_sprintf(key_str, "KEY = %s", "UNKNOWN");
|
rt_sprintf(key_str, "%s", "S");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
dc = rtgui_dc_begin_drawing(widget);
|
dc = rtgui_dc_begin_drawing(widget);
|
||||||
if(dc == RT_NULL)
|
if (dc == RT_NULL)
|
||||||
return RT_FALSE;
|
return RT_FALSE;
|
||||||
rect.x1 = 10;
|
rect.x1 = 118;
|
||||||
rect.y1 = 30;
|
rect.y1 = 1;
|
||||||
rect.x2 = 120;
|
rect.x2 = 127;
|
||||||
rect.y2 = 40;
|
rect.y2 = 10;
|
||||||
rtgui_dc_fill_rect(dc, &rect);
|
rtgui_dc_fill_rect(dc, &rect);
|
||||||
rtgui_dc_draw_text(dc, key_str, &rect);
|
rtgui_dc_draw_text(dc, key_str, &rect);
|
||||||
rtgui_dc_end_drawing(dc);
|
rtgui_dc_end_drawing(dc);
|
||||||
}
|
}
|
||||||
|
else if (ekbd->type == RTGUI_KEYUP)
|
||||||
|
{
|
||||||
|
dc = rtgui_dc_begin_drawing(widget);
|
||||||
|
if (dc == RT_NULL)
|
||||||
|
return RT_FALSE;
|
||||||
|
rect.x1 = 118;
|
||||||
|
rect.y1 = 1;
|
||||||
|
rect.x2 = 127;
|
||||||
|
rect.y2 = 10;
|
||||||
|
rtgui_dc_fill_rect(dc, &rect);
|
||||||
|
//rtgui_dc_draw_text(dc, key_str, &rect);
|
||||||
|
rtgui_dc_end_drawing(dc);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if(event->type == RTGUI_EVENT_COMMAND)
|
else if (event->type == RTGUI_EVENT_COMMAND)
|
||||||
{
|
{
|
||||||
char adc_str[10];
|
char str[16];
|
||||||
struct rtgui_dc* dc;
|
struct rtgui_dc* dc;
|
||||||
struct rtgui_rect rect;
|
struct rtgui_rect rect;
|
||||||
dc = rtgui_dc_begin_drawing(widget);
|
dc = rtgui_dc_begin_drawing(widget);
|
||||||
if(dc == RT_NULL)
|
if (dc == RT_NULL)
|
||||||
return RT_FALSE;
|
return RT_FALSE;
|
||||||
|
|
||||||
struct rtgui_event_command* ecmd = (struct rtgui_event_command*)event;
|
struct rtgui_event_command* ecmd = (struct rtgui_event_command*)event;
|
||||||
switch(ecmd->command_id)
|
switch (ecmd->command_id)
|
||||||
{
|
{
|
||||||
case ADC_UPDATE:
|
case ADC_UPDATE:
|
||||||
rect.x1 = 10;
|
rect.x1 = 1;
|
||||||
rect.y1 = 40;
|
rect.y1 = 1;
|
||||||
rect.x2 = 120;
|
rect.x2 = 117;
|
||||||
rect.y2 = 50;
|
rect.y2 = 10;
|
||||||
rtgui_dc_fill_rect(dc, &rect);
|
rtgui_dc_fill_rect(dc, &rect);
|
||||||
rt_sprintf(adc_str, "ADC = %d mv", adc_value);
|
rt_sprintf(str, "ADC = %d mv", adc_value);
|
||||||
rtgui_dc_draw_text(dc, adc_str, &rect);
|
rtgui_dc_draw_text(dc, str, &rect);
|
||||||
rtgui_dc_end_drawing(dc);
|
break;
|
||||||
|
case CPU_UPDATE:
|
||||||
|
rt_uint8_t major,minor;
|
||||||
|
cpu_usage_get(&major, &minor);
|
||||||
|
rect.x1 = 1;
|
||||||
|
rect.y1 = 12;
|
||||||
|
rect.x2 = 127;
|
||||||
|
rect.y2 = 22;
|
||||||
|
rtgui_dc_fill_rect(dc, &rect);
|
||||||
|
rt_sprintf(str, "CPU : %d.%d%", major, minor);
|
||||||
|
rtgui_dc_draw_text(dc, str, &rect);
|
||||||
|
|
||||||
|
rect.y1 = 23;
|
||||||
|
rect.y2 = 63;
|
||||||
|
index++;
|
||||||
|
if (index == 127)
|
||||||
|
{
|
||||||
|
index = 1;
|
||||||
|
rtgui_dc_fill_rect(dc, &rect);
|
||||||
|
}
|
||||||
|
if (major>40)
|
||||||
|
rtgui_dc_draw_vline(dc, index, rect.y1, rect.y2);
|
||||||
|
else
|
||||||
|
rtgui_dc_draw_vline(dc, index, rect.y2-major, rect.y2);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
rtgui_dc_end_drawing(dc);
|
||||||
}
|
}
|
||||||
|
|
||||||
return rtgui_view_event_handler(widget, event);
|
return rtgui_view_event_handler(widget, event);
|
||||||
|
@ -148,7 +184,7 @@ void info_init()
|
||||||
{
|
{
|
||||||
info_tid = rt_thread_create("info",
|
info_tid = rt_thread_create("info",
|
||||||
info_entry, RT_NULL,
|
info_entry, RT_NULL,
|
||||||
2048, 26, 10);
|
2048, 25, 10);
|
||||||
|
|
||||||
if (info_tid != RT_NULL) rt_thread_startup(info_tid);
|
if (info_tid != RT_NULL) rt_thread_startup(info_tid);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,17 @@
|
||||||
|
/*
|
||||||
|
* File : key.c
|
||||||
|
* This file is part of RT-Thread RTOS
|
||||||
|
* COPYRIGHT (C) 2011, RT-Thread Develop 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
|
||||||
|
* 2011-03-03 lgnq
|
||||||
|
*/
|
||||||
|
|
||||||
#include <rtthread.h>
|
#include <rtthread.h>
|
||||||
#include "key.h"
|
#include "key.h"
|
||||||
|
|
||||||
|
@ -33,17 +47,16 @@ static void key_thread_entry(void *parameter)
|
||||||
kbd_event.key = RTGUIK_UNKNOWN;
|
kbd_event.key = RTGUIK_UNKNOWN;
|
||||||
kbd_event.type = RTGUI_KEYDOWN;
|
kbd_event.type = RTGUI_KEYDOWN;
|
||||||
|
|
||||||
if(KEY_ENTER_GETVALUE() == 0 )
|
if (KEY_ENTER_GETVALUE() == 0 )
|
||||||
{
|
{
|
||||||
for(i=0; ; i++)
|
for(i=0; ; i++)
|
||||||
{
|
{
|
||||||
rt_thread_delay( next_delay );
|
rt_thread_delay( next_delay );
|
||||||
if (KEY_ENTER_GETVALUE() == 0)
|
if (KEY_ENTER_GETVALUE() == 0)
|
||||||
{
|
{
|
||||||
if(i>=4)
|
if (i>=4)
|
||||||
{
|
{
|
||||||
/* HOME key */
|
/* HOME key */
|
||||||
//rt_kprintf("key_home\n");
|
|
||||||
kbd_event.key = RTGUIK_HOME;
|
kbd_event.key = RTGUIK_HOME;
|
||||||
next_delay = RT_TICK_PER_SECOND/5;
|
next_delay = RT_TICK_PER_SECOND/5;
|
||||||
break;
|
break;
|
||||||
|
@ -51,51 +64,42 @@ static void key_thread_entry(void *parameter)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//rt_kprintf("key_enter\n");
|
|
||||||
kbd_event.key = RTGUIK_RETURN;
|
kbd_event.key = RTGUIK_RETURN;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(KEY_DOWN_GETVALUE() == 0)
|
if (KEY_DOWN_GETVALUE() == 0)
|
||||||
{
|
{
|
||||||
// rt_kprintf("key_down\n");
|
|
||||||
kbd_event.key = RTGUIK_DOWN;
|
kbd_event.key = RTGUIK_DOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(KEY_UP_GETVALUE() == 0)
|
if (KEY_UP_GETVALUE() == 0)
|
||||||
{
|
{
|
||||||
// rt_kprintf("key_up\n");
|
|
||||||
kbd_event.key = RTGUIK_UP;
|
kbd_event.key = RTGUIK_UP;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(KEY_RIGHT_GETVALUE() == 0)
|
if (KEY_RIGHT_GETVALUE() == 0)
|
||||||
{
|
{
|
||||||
// rt_kprintf("key_right\n");
|
|
||||||
kbd_event.key = RTGUIK_RIGHT;
|
kbd_event.key = RTGUIK_RIGHT;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(KEY_LEFT_GETVALUE() == 0)
|
if (KEY_LEFT_GETVALUE() == 0)
|
||||||
{
|
{
|
||||||
// rt_kprintf("key_left\n");
|
|
||||||
kbd_event.key = RTGUIK_LEFT;
|
kbd_event.key = RTGUIK_LEFT;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(kbd_event.key != RTGUIK_UNKNOWN)
|
if (kbd_event.key != RTGUIK_UNKNOWN)
|
||||||
{
|
{
|
||||||
/* post down event */
|
/* post down event */
|
||||||
rtgui_server_post_event(&(kbd_event.parent), sizeof(kbd_event));
|
rtgui_server_post_event(&(kbd_event.parent), sizeof(kbd_event));
|
||||||
|
}
|
||||||
//next_delay = RT_TICK_PER_SECOND/10;
|
else
|
||||||
/* delay to post up event */
|
{
|
||||||
rt_thread_delay(next_delay);
|
|
||||||
|
|
||||||
/* post up event */
|
|
||||||
kbd_event.type = RTGUI_KEYUP;
|
kbd_event.type = RTGUI_KEYUP;
|
||||||
rtgui_server_post_event(&(kbd_event.parent), sizeof(kbd_event));
|
rtgui_server_post_event(&(kbd_event.parent), sizeof(kbd_event));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* wait next key press */
|
/* wait next key press */
|
||||||
rt_thread_delay(next_delay);
|
rt_thread_delay(next_delay);
|
||||||
}
|
}
|
||||||
|
@ -104,7 +108,7 @@ static void key_thread_entry(void *parameter)
|
||||||
static rt_thread_t key_thread;
|
static rt_thread_t key_thread;
|
||||||
void rt_hw_key_init(void)
|
void rt_hw_key_init(void)
|
||||||
{
|
{
|
||||||
key_thread = rt_thread_create("key", key_thread_entry, RT_NULL, 384, 30, 5);
|
key_thread = rt_thread_create("key", key_thread_entry, RT_NULL, 384, 28, 5);
|
||||||
if(key_thread != RT_NULL)
|
if (key_thread != RT_NULL)
|
||||||
rt_thread_startup(key_thread);
|
rt_thread_startup(key_thread);
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,11 +20,8 @@ static rt_uint8_t gui_disp_buf[GUI_LCM_YMAX/8][GUI_LCM_XMAX];
|
||||||
struct rtgui_lcd_device
|
struct rtgui_lcd_device
|
||||||
{
|
{
|
||||||
struct rt_device parent;
|
struct rt_device parent;
|
||||||
|
|
||||||
/* screen width and height */
|
|
||||||
rt_uint16_t width;
|
rt_uint16_t width;
|
||||||
rt_uint16_t height;
|
rt_uint16_t height;
|
||||||
|
|
||||||
void* hw_framebuffer;
|
void* hw_framebuffer;
|
||||||
};
|
};
|
||||||
static struct rtgui_lcd_device *lcd = RT_NULL;
|
static struct rtgui_lcd_device *lcd = RT_NULL;
|
||||||
|
@ -59,7 +56,7 @@ void LCD_WriteCmd(unsigned char command)
|
||||||
LCD_CD_LOW();
|
LCD_CD_LOW();
|
||||||
for(i=0; i<8; i++)
|
for(i=0; i<8; i++)
|
||||||
{
|
{
|
||||||
if(command & (0x80 >> i))
|
if (command & (0x80 >> i))
|
||||||
LCD_DATA_HIGH();
|
LCD_DATA_HIGH();
|
||||||
else
|
else
|
||||||
LCD_DATA_LOW();
|
LCD_DATA_LOW();
|
||||||
|
@ -81,7 +78,7 @@ void LCD_WriteData(unsigned char data)
|
||||||
LCD_CD_HIGH();
|
LCD_CD_HIGH();
|
||||||
for(i=0; i<8; i++)
|
for(i=0; i<8; i++)
|
||||||
{
|
{
|
||||||
if(data & (0x80 >> i))
|
if (data & (0x80 >> i))
|
||||||
LCD_DATA_HIGH();
|
LCD_DATA_HIGH();
|
||||||
else
|
else
|
||||||
LCD_DATA_LOW();
|
LCD_DATA_LOW();
|
||||||
|
@ -103,13 +100,13 @@ static void rt_hw_lcd_update(rtgui_rect_t *rect)
|
||||||
rt_uint8_t i,j = GUI_LCM_XMAX;
|
rt_uint8_t i,j = GUI_LCM_XMAX;
|
||||||
rt_uint8_t* p = (rt_uint8_t*)gui_disp_buf;
|
rt_uint8_t* p = (rt_uint8_t*)gui_disp_buf;
|
||||||
|
|
||||||
for(i=0; i<GUI_LCM_PAGE; i++)
|
for (i=0; i<GUI_LCM_PAGE; i++)
|
||||||
{
|
{
|
||||||
LCD_WriteCmd(Set_Page_Addr_0|i);
|
LCD_WriteCmd(Set_Page_Addr_0|i);
|
||||||
LCD_WriteCmd(Set_ColH_Addr_0);
|
LCD_WriteCmd(Set_ColH_Addr_0);
|
||||||
LCD_WriteCmd(Set_ColL_Addr_0);
|
LCD_WriteCmd(Set_ColL_Addr_0);
|
||||||
j = GUI_LCM_XMAX;
|
j = GUI_LCM_XMAX;
|
||||||
while(j--)
|
while (j--)
|
||||||
{
|
{
|
||||||
LCD_WriteData(*p++);
|
LCD_WriteData(*p++);
|
||||||
Delay();
|
Delay();
|
||||||
|
@ -127,10 +124,10 @@ static void rt_hw_lcd_set_pixel(rtgui_color_t *c, rt_base_t x, rt_base_t y)
|
||||||
rt_uint8_t page;
|
rt_uint8_t page;
|
||||||
page = y/8;
|
page = y/8;
|
||||||
|
|
||||||
if(*c == black)
|
if (*c == black)
|
||||||
gui_disp_buf[page][x] |= 1<<(y%8);
|
gui_disp_buf[page][x] |= 1<<(y%8);
|
||||||
else
|
else
|
||||||
if(*c == white)
|
if (*c == white)
|
||||||
gui_disp_buf[page][x] &= ~(1<<(y%8));
|
gui_disp_buf[page][x] &= ~(1<<(y%8));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,7 +136,7 @@ static void rt_hw_lcd_get_pixel(rtgui_color_t *c, rt_base_t x, rt_base_t y)
|
||||||
rt_uint8_t page;
|
rt_uint8_t page;
|
||||||
page = y/8;
|
page = y/8;
|
||||||
|
|
||||||
if(gui_disp_buf[page][x] & (1<<(y%8)))
|
if (gui_disp_buf[page][x] & (1<<(y%8)))
|
||||||
*c = black;
|
*c = black;
|
||||||
else
|
else
|
||||||
*c = white;
|
*c = white;
|
||||||
|
@ -151,12 +148,12 @@ static void rt_hw_lcd_draw_hline(rtgui_color_t *c, rt_base_t x1, rt_base_t x2, r
|
||||||
rt_uint8_t i;
|
rt_uint8_t i;
|
||||||
page = y/8;
|
page = y/8;
|
||||||
|
|
||||||
for(i=x1; i<x2; i++)
|
for (i=x1; i<x2; i++)
|
||||||
{
|
{
|
||||||
if(*c == black)
|
if (*c == black)
|
||||||
gui_disp_buf[page][i] |= 1<<(y%8);
|
gui_disp_buf[page][i] |= 1<<(y%8);
|
||||||
else
|
else
|
||||||
if(*c == white)
|
if (*c == white)
|
||||||
gui_disp_buf[page][i] &= ~(1<<(y%8));
|
gui_disp_buf[page][i] &= ~(1<<(y%8));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -165,7 +162,7 @@ static void rt_hw_lcd_draw_vline(rtgui_color_t *c, rt_base_t x, rt_base_t y1, rt
|
||||||
{
|
{
|
||||||
rt_uint8_t y;
|
rt_uint8_t y;
|
||||||
|
|
||||||
for(y = y1; y < y2; y ++)
|
for (y = y1; y < y2; y ++)
|
||||||
{
|
{
|
||||||
rt_hw_lcd_set_pixel(c, x, y);
|
rt_hw_lcd_set_pixel(c, x, y);
|
||||||
}
|
}
|
||||||
|
@ -180,7 +177,7 @@ static void rt_hw_lcd_draw_raw_hline(rt_uint8_t *pixels, rt_base_t x1, rt_base_t
|
||||||
|
|
||||||
page = y/8;
|
page = y/8;
|
||||||
|
|
||||||
for(i=x1; i<x2; i++)
|
for (i=x1; i<x2; i++)
|
||||||
{
|
{
|
||||||
gui_disp_buf[page][i] |= 1<<(y%8);
|
gui_disp_buf[page][i] |= 1<<(y%8);
|
||||||
coll = i & 0x0f;
|
coll = i & 0x0f;
|
||||||
|
@ -311,7 +308,6 @@ static rt_err_t rt_lcd_control (rt_device_t dev, rt_uint8_t cmd, void *args)
|
||||||
LCD_WriteCmd(Display_Off);
|
LCD_WriteCmd(Display_Off);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return RT_EOK;
|
return RT_EOK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ void rt_hw_led_on(rt_uint8_t num)
|
||||||
{
|
{
|
||||||
RT_ASSERT(num < LEDS_MAX_NUMBER);
|
RT_ASSERT(num < LEDS_MAX_NUMBER);
|
||||||
|
|
||||||
switch(num)
|
switch (num)
|
||||||
{
|
{
|
||||||
case 1:
|
case 1:
|
||||||
LED_PDOR &= ~LED1;
|
LED_PDOR &= ~LED1;
|
||||||
|
@ -42,7 +42,7 @@ void rt_hw_led_off(rt_uint8_t num)
|
||||||
{
|
{
|
||||||
RT_ASSERT(num < LEDS_MAX_NUMBER);
|
RT_ASSERT(num < LEDS_MAX_NUMBER);
|
||||||
|
|
||||||
switch(num)
|
switch (num)
|
||||||
{
|
{
|
||||||
case 1:
|
case 1:
|
||||||
LED_PDOR |= LED1;
|
LED_PDOR |= LED1;
|
||||||
|
@ -62,22 +62,22 @@ void rt_hw_led_toggle(rt_uint8_t num)
|
||||||
{
|
{
|
||||||
RT_ASSERT(num < LEDS_MAX_NUMBER);
|
RT_ASSERT(num < LEDS_MAX_NUMBER);
|
||||||
|
|
||||||
switch(num)
|
switch (num)
|
||||||
{
|
{
|
||||||
case 1:
|
case 1:
|
||||||
if(LED_PDOR&LED1)
|
if (LED_PDOR&LED1)
|
||||||
LED_PDOR &= ~LED1;
|
LED_PDOR &= ~LED1;
|
||||||
else
|
else
|
||||||
LED_PDOR |= LED1;
|
LED_PDOR |= LED1;
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
if(LED_PDOR&LED2)
|
if (LED_PDOR&LED2)
|
||||||
LED_PDOR &= ~LED2;
|
LED_PDOR &= ~LED2;
|
||||||
else
|
else
|
||||||
LED_PDOR |= LED2;
|
LED_PDOR |= LED2;
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
if(LED_PDOR&LED3)
|
if (LED_PDOR&LED3)
|
||||||
LED_PDOR &= ~LED3;
|
LED_PDOR &= ~LED3;
|
||||||
else
|
else
|
||||||
LED_PDOR |= LED3;
|
LED_PDOR |= LED3;
|
||||||
|
@ -96,24 +96,39 @@ static rt_err_t led_io_init(void)
|
||||||
/*Make led pins outputs*/
|
/*Make led pins outputs*/
|
||||||
LED_DDR |= LED_MASK;
|
LED_DDR |= LED_MASK;
|
||||||
|
|
||||||
|
//LED3 is controled by PWM
|
||||||
|
FM3_GPIO->PFR3 = 0x1000;
|
||||||
|
FM3_GPIO->EPFR04 = 0x00080000;
|
||||||
|
FM3_BT2_PWM->TMCR = 0x0018;
|
||||||
|
FM3_BT2_PWM->TMCR2 = 0x01; /* cks=0b1000 count clk 1/512 */
|
||||||
|
FM3_BT2_PWM->STC = 0x00;
|
||||||
|
FM3_BT2_PWM->PCSR = 0x61A; /* Down count = 1562 */
|
||||||
|
FM3_BT2_PWM->PDUT = 0x0; /* Duty count = 16/1562=10% */
|
||||||
|
|
||||||
|
FM3_BT2_PWM->TMCR |= 0x03; /* start base timer(softwere TRG) */
|
||||||
return RT_EOK;
|
return RT_EOK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void pwm_update(rt_uint16_t value)
|
||||||
|
{
|
||||||
|
FM3_BT2_PWM->PDUT = value;
|
||||||
|
}
|
||||||
|
|
||||||
static void led1_thread_entry(void *parameter)
|
static void led1_thread_entry(void *parameter)
|
||||||
{
|
{
|
||||||
while(1)
|
while (1)
|
||||||
{
|
{
|
||||||
rt_hw_led_toggle(1);
|
rt_hw_led_toggle(1);
|
||||||
rt_thread_delay(10);
|
rt_thread_delay(RT_TICK_PER_SECOND);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void led2_thread_entry(void *parameter)
|
static void led2_thread_entry(void *parameter)
|
||||||
{
|
{
|
||||||
while(1)
|
while (1)
|
||||||
{
|
{
|
||||||
rt_hw_led_toggle(2);
|
rt_hw_led_toggle(2);
|
||||||
rt_thread_delay(20);
|
rt_thread_delay(RT_TICK_PER_SECOND/2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,12 +138,12 @@ void rt_hw_led_init(void)
|
||||||
{
|
{
|
||||||
led_io_init();
|
led_io_init();
|
||||||
|
|
||||||
led1_thread = rt_thread_create("led1", led1_thread_entry, RT_NULL, 384, 31, 5);
|
led1_thread = rt_thread_create("led1", led1_thread_entry, RT_NULL, 384, 29, 5);
|
||||||
if(led1_thread != RT_NULL)
|
if (led1_thread != RT_NULL)
|
||||||
rt_thread_startup(led1_thread);
|
rt_thread_startup(led1_thread);
|
||||||
|
|
||||||
led2_thread = rt_thread_create("led2", led2_thread_entry, RT_NULL, 384, 30, 5);
|
led2_thread = rt_thread_create("led2", led2_thread_entry, RT_NULL, 384, 30, 5);
|
||||||
if(led2_thread != RT_NULL)
|
if (led2_thread != RT_NULL)
|
||||||
rt_thread_startup(led2_thread);
|
rt_thread_startup(led2_thread);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,5 +37,6 @@ void rt_hw_led_init(void);
|
||||||
void rt_hw_led_on(rt_uint8_t num);
|
void rt_hw_led_on(rt_uint8_t num);
|
||||||
void rt_hw_led_off(rt_uint8_t num);
|
void rt_hw_led_off(rt_uint8_t num);
|
||||||
void rt_hw_led_toggle(rt_uint8_t num);
|
void rt_hw_led_toggle(rt_uint8_t num);
|
||||||
|
void pwm_update(rt_uint16_t value);
|
||||||
|
|
||||||
#endif
|
#endif
|
Loading…
Reference in New Issue