mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-06-19 04:24:17 +08:00
update FM3 easy kit IAR project
if define RT_USING_RTGUI in rtconfig.h must be compiled by full edition of IAR Embedded Workbench else can be compiled by 32KB KickStart edition git-svn-id: https://rt-thread.googlecode.com/svn/trunk@1377 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
+21
-5
@@ -14,13 +14,16 @@
|
||||
|
||||
#include <rtthread.h>
|
||||
#include <rthw.h>
|
||||
#include <rtgui/event.h>
|
||||
#include <rtgui/rtgui_server.h>
|
||||
#include <rtgui/rtgui_system.h>
|
||||
|
||||
#include "mb9bf506r.h"
|
||||
#include "adc.h"
|
||||
#include "led.h"
|
||||
#include "lcd.h"
|
||||
|
||||
#ifdef RT_USING_RTGUI
|
||||
#include <rtgui/event.h>
|
||||
#include <rtgui/rtgui_server.h>
|
||||
#include <rtgui/rtgui_system.h>
|
||||
#endif
|
||||
|
||||
static struct rt_device adc;
|
||||
|
||||
@@ -71,23 +74,36 @@ static rt_err_t rt_adc_control(rt_device_t dev, rt_uint8_t cmd, void *args)
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
extern struct rt_messagequeue mq;
|
||||
extern rt_thread_t info_tid;
|
||||
rt_uint16_t adc_value;
|
||||
static void adc_thread_entry(void *parameter)
|
||||
{
|
||||
rt_device_t device;
|
||||
device = rt_device_find("adc");
|
||||
|
||||
#ifdef RT_USING_RTGUI
|
||||
struct rtgui_event_command ecmd;
|
||||
|
||||
RTGUI_EVENT_COMMAND_INIT(&ecmd);
|
||||
ecmd.type = RTGUI_CMD_USER_INT;
|
||||
ecmd.command_id = ADC_UPDATE;
|
||||
device = rt_device_find("adc");
|
||||
#else
|
||||
struct lcd_msg msg;
|
||||
#endif
|
||||
|
||||
while(1)
|
||||
{
|
||||
rt_device_control(device, RT_DEVICE_CTRL_ADC_START, RT_NULL);
|
||||
rt_device_control(device, RT_DEVICE_CTRL_ADC_RESULT, &adc_value);
|
||||
pwm_update(adc_value/3);
|
||||
#ifdef RT_USING_RTGUI
|
||||
rtgui_thread_send(info_tid, &ecmd.parent, sizeof(ecmd));
|
||||
#else
|
||||
msg.type = ADC_MSG;
|
||||
msg.adc_value = adc_value;
|
||||
rt_mq_send(&mq, &msg, sizeof(msg));
|
||||
#endif
|
||||
rt_thread_delay(20);
|
||||
}
|
||||
}
|
||||
|
||||
+76
-6
@@ -20,21 +20,22 @@
|
||||
#include <rtthread.h>
|
||||
#include "board.h"
|
||||
#include "led.h"
|
||||
|
||||
#ifdef RT_USING_RTGUI
|
||||
#include "key.h"
|
||||
#include "adc.h"
|
||||
#include "lcd.h"
|
||||
#include "cpuusage.h"
|
||||
|
||||
#ifdef RT_USING_RTGUI
|
||||
#include <rtgui/rtgui.h>
|
||||
extern void rtgui_startup();
|
||||
#endif
|
||||
|
||||
struct rt_messagequeue mq;
|
||||
static char msg_pool[2048];
|
||||
|
||||
void rt_init_thread_entry(void *parameter)
|
||||
{
|
||||
rt_hw_led_init();
|
||||
|
||||
#ifdef RT_USING_RTGUI
|
||||
rt_hw_led_init();
|
||||
rt_hw_key_init();
|
||||
rt_hw_adc_init();
|
||||
rt_hw_lcd_init();
|
||||
@@ -42,9 +43,76 @@ void rt_init_thread_entry(void *parameter)
|
||||
|
||||
/* re-init device driver */
|
||||
rt_device_init_all();
|
||||
|
||||
|
||||
#ifdef RT_USING_RTGUI
|
||||
/* startup rtgui */
|
||||
rtgui_startup();
|
||||
#else
|
||||
char buf[20] = {'\0'};
|
||||
struct lcd_msg msg;
|
||||
rt_device_t device;
|
||||
device = rt_device_find("lcd");
|
||||
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");
|
||||
|
||||
while(1)
|
||||
{
|
||||
if (rt_mq_recv(&mq, &msg, sizeof(msg), RT_WAITING_FOREVER) == RT_EOK)
|
||||
{
|
||||
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));
|
||||
switch(msg.key)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -52,6 +120,8 @@ int rt_application_init()
|
||||
{
|
||||
rt_thread_t init_thread;
|
||||
|
||||
rt_mq_init(&mq, "mqt", &msg_pool[0], 128 - sizeof(void*), sizeof(msg_pool), RT_IPC_FLAG_FIFO);
|
||||
|
||||
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);
|
||||
|
||||
+18
-3
@@ -1,9 +1,13 @@
|
||||
#include <rtthread.h>
|
||||
#include <rthw.h>
|
||||
#include "cpuusage.h"
|
||||
#include "lcd.h"
|
||||
|
||||
#ifdef RT_USING_RTGUI
|
||||
#include <rtgui/event.h>
|
||||
#include <rtgui/rtgui_server.h>
|
||||
#include <rtgui/rtgui_system.h>
|
||||
#include "cpuusage.h"
|
||||
#endif
|
||||
|
||||
#define CPU_USAGE_CALC_TICK 10
|
||||
#define CPU_USAGE_LOOP 100
|
||||
@@ -73,19 +77,30 @@ void cpu_usage_init()
|
||||
/* set idle thread hook */
|
||||
rt_thread_idle_sethook(cpu_usage_idle_hook);
|
||||
}
|
||||
|
||||
extern struct rt_messagequeue mq;
|
||||
extern rt_thread_t info_tid;
|
||||
static void cpu_thread_entry(void *parameter)
|
||||
{
|
||||
#ifdef RT_USING_RTGUI
|
||||
struct rtgui_event_command ecmd;
|
||||
|
||||
RTGUI_EVENT_COMMAND_INIT(&ecmd);
|
||||
ecmd.type = RTGUI_CMD_USER_INT;
|
||||
ecmd.command_id = CPU_UPDATE;
|
||||
|
||||
#else
|
||||
struct lcd_msg msg;
|
||||
#endif
|
||||
|
||||
while (1)
|
||||
{
|
||||
#ifdef RT_USING_RTGUI
|
||||
rtgui_thread_send(info_tid, &ecmd.parent, sizeof(ecmd));
|
||||
#else
|
||||
msg.type = CPU_MSG;
|
||||
msg.major = cpu_usage_major;
|
||||
msg.minor = cpu_usage_minor;
|
||||
rt_mq_send(&mq, &msg, sizeof(msg));
|
||||
#endif
|
||||
rt_thread_delay(20);
|
||||
}
|
||||
}
|
||||
|
||||
+1615
-227
File diff suppressed because it is too large
Load Diff
@@ -45,7 +45,7 @@
|
||||
</option>
|
||||
<option>
|
||||
<name>MemFile</name>
|
||||
<state>$TOOLKIT_DIR$\CONFIG\debugger\Fujitsu\iomb9bf506.ddf</state>
|
||||
<state></state>
|
||||
</option>
|
||||
<option>
|
||||
<name>RunToEnable</name>
|
||||
@@ -117,7 +117,7 @@
|
||||
</option>
|
||||
<option>
|
||||
<name>FlashLoadersV3</name>
|
||||
<state>$TOOLKIT_DIR$\config\flashloader\Fujitsu\MB9BF506.board</state>
|
||||
<state>$TOOLKIT_DIR$\config\flashloader\</state>
|
||||
</option>
|
||||
<option>
|
||||
<name>OCImagesSuppressCheck1</name>
|
||||
|
||||
@@ -39,20 +39,20 @@
|
||||
<option>
|
||||
<name>Input variant</name>
|
||||
<version>1</version>
|
||||
<state>3</state>
|
||||
<state>0</state>
|
||||
</option>
|
||||
<option>
|
||||
<name>Input description</name>
|
||||
<state>No specifier n, no float nor long long, no scan set, no assignment suppressing.</state>
|
||||
<state>Full formatting.</state>
|
||||
</option>
|
||||
<option>
|
||||
<name>Output variant</name>
|
||||
<version>0</version>
|
||||
<state>3</state>
|
||||
<state>0</state>
|
||||
</option>
|
||||
<option>
|
||||
<name>Output description</name>
|
||||
<state>No specifier a, A, no specifier n, no float nor long long, no flags.</state>
|
||||
<state>Full formatting.</state>
|
||||
</option>
|
||||
<option>
|
||||
<name>GOutputBinary</name>
|
||||
|
||||
+961
File diff suppressed because it is too large
Load Diff
+54
-2
@@ -8,15 +8,18 @@
|
||||
* http://www.rt-thread.org/license/LICENSE
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* Date Author Notes
|
||||
* 2011-03-03 lgnq
|
||||
*/
|
||||
|
||||
#include <rtthread.h>
|
||||
#include "key.h"
|
||||
#include "lcd.h"
|
||||
|
||||
#ifdef RT_USING_RTGUI
|
||||
#include <rtgui/event.h>
|
||||
#include <rtgui/rtgui_server.h>
|
||||
#endif
|
||||
|
||||
static void key_io_init(void)
|
||||
{
|
||||
@@ -30,9 +33,11 @@ static void key_io_init(void)
|
||||
|
||||
static void key_thread_entry(void *parameter)
|
||||
{
|
||||
#ifdef RT_USING_RTGUI
|
||||
rt_time_t next_delay;
|
||||
struct rtgui_event_kbd kbd_event;
|
||||
rt_uint8_t i;
|
||||
|
||||
struct rtgui_event_kbd kbd_event;
|
||||
|
||||
key_io_init();
|
||||
|
||||
@@ -103,6 +108,53 @@ static void key_thread_entry(void *parameter)
|
||||
/* wait next key press */
|
||||
rt_thread_delay(next_delay);
|
||||
}
|
||||
#else
|
||||
extern struct rt_messagequeue mq;
|
||||
rt_time_t next_delay;
|
||||
rt_uint8_t i;
|
||||
struct lcd_msg msg;
|
||||
msg.type = KEY_MSG;
|
||||
|
||||
key_io_init();
|
||||
|
||||
while (1)
|
||||
{
|
||||
msg.key = NO_KEY;
|
||||
|
||||
next_delay = RT_TICK_PER_SECOND/10;
|
||||
|
||||
if (KEY_ENTER_GETVALUE() == 0 )
|
||||
{
|
||||
msg.key = KEY_ENTER;
|
||||
}
|
||||
|
||||
if (KEY_DOWN_GETVALUE() == 0)
|
||||
{
|
||||
msg.key = KEY_DOWN;
|
||||
}
|
||||
|
||||
if (KEY_UP_GETVALUE() == 0)
|
||||
{
|
||||
msg.key = KEY_UP;
|
||||
}
|
||||
|
||||
if (KEY_RIGHT_GETVALUE() == 0)
|
||||
{
|
||||
msg.key = KEY_RIGHT;
|
||||
}
|
||||
|
||||
if (KEY_LEFT_GETVALUE() == 0)
|
||||
{
|
||||
msg.key = KEY_LEFT;
|
||||
}
|
||||
|
||||
rt_mq_send(&mq, &msg, sizeof(msg));
|
||||
|
||||
/* wait next key press */
|
||||
rt_thread_delay(next_delay);
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
static rt_thread_t key_thread;
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#define KEY_LEFT (1<<2)
|
||||
#define KEY_RIGHT (1<<3)
|
||||
#define KEY_UP (1<<4)
|
||||
#define NO_KEY (1<<5)
|
||||
|
||||
#define KEY_MASK (KEY_DOWN | KEY_ENTER | KEY_LEFT | KEY_RIGHT | KEY_UP)
|
||||
#define KEY_PFR (FM3_GPIO->PFR7)
|
||||
|
||||
+146
@@ -14,8 +14,15 @@
|
||||
|
||||
#include <rtthread.h>
|
||||
#include "lcd.h"
|
||||
#include "font.h"
|
||||
|
||||
static rt_uint8_t gui_disp_buf[GUI_LCM_YMAX/8][GUI_LCM_XMAX];
|
||||
const unsigned char BIT_MASK[8] = {0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01};
|
||||
/* simple font: ' ', '0'~'9','a'~'z','A'~'Z' */
|
||||
extern const unsigned char FONTTYPE8_8[][8];
|
||||
|
||||
rt_uint32_t x;
|
||||
rt_uint32_t y;
|
||||
|
||||
struct rtgui_lcd_device
|
||||
{
|
||||
@@ -291,6 +298,139 @@ static rt_err_t rt_lcd_init (rt_device_t dev)
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : LCD_FillAll
|
||||
* Description : Fill the whole LCD.
|
||||
* Input : None
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void LCD_FillAll(unsigned char* buffer)
|
||||
{
|
||||
unsigned char i,j = GUI_LCM_XMAX;
|
||||
unsigned char* p = buffer;
|
||||
|
||||
for (i=0; i<GUI_LCM_PAGE; i++)
|
||||
{
|
||||
LCD_WriteCmd(Set_Page_Addr_0|i);
|
||||
LCD_WriteCmd(Set_ColH_Addr_0);
|
||||
LCD_WriteCmd(Set_ColL_Addr_0);
|
||||
j = GUI_LCM_XMAX;
|
||||
while (j--)
|
||||
{
|
||||
LCD_WriteData(*p++);
|
||||
Delay();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : LCD_ClearSCR
|
||||
* Description : clean screen
|
||||
* Input : None
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void LCD_ClearSCR(void)
|
||||
{
|
||||
for(unsigned char i=0; i<GUI_LCM_PAGE; i++)
|
||||
{
|
||||
for(unsigned char j = 0; j < GUI_LCM_XMAX; j++)
|
||||
gui_disp_buf[i][j] = 0;
|
||||
}
|
||||
LCD_FillAll((unsigned char*)gui_disp_buf);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Function Name : LCD_UpdatePoint
|
||||
* Description : refresh the point in screen
|
||||
* Input : x X-coordinate
|
||||
y Y-coordinate
|
||||
* Output : None
|
||||
* Return : None
|
||||
****************************************************************************/
|
||||
|
||||
void LCD_UpdatePoint(unsigned int x, unsigned int y)
|
||||
{
|
||||
unsigned char coll, colh, page;
|
||||
page = y / 8;
|
||||
coll = x & 0x0f;
|
||||
colh = x >> 4;
|
||||
|
||||
LCD_WriteCmd(Set_Page_Addr_0 | page); // page no.
|
||||
LCD_WriteCmd(Set_ColH_Addr_0 | colh); // fixed col first addr
|
||||
LCD_WriteCmd(Set_ColL_Addr_0 | coll);
|
||||
LCD_WriteData(gui_disp_buf[page][x]);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Function Name : LCD_PutChar
|
||||
* Description : output a char to screen
|
||||
(the char only can be ' ','0'~'9','A'~'Z','a'~'z')
|
||||
* Input : x X-coordinate
|
||||
y Y-coordinate
|
||||
ch character
|
||||
* Output : None
|
||||
* Return : 1 Success
|
||||
0 Fail
|
||||
****************************************************************************/
|
||||
unsigned char LCD_PutChar(unsigned long x, unsigned long y, unsigned char ch)
|
||||
{
|
||||
unsigned char data;
|
||||
|
||||
if( x >=(GUI_LCM_XMAX-8) ) return(0);
|
||||
if( y >=(GUI_LCM_YMAX-8) ) return(0);
|
||||
|
||||
if(ch == 0x20)
|
||||
ch -= 0x20;
|
||||
else if((ch >= 0x30)&&(ch <= 0x39))
|
||||
ch -= 0x2f;
|
||||
else if((ch >= 0x41)&&(ch <= 0x5a))
|
||||
ch -= 0x36;
|
||||
else if((ch >= 0x61)&&(ch <= 0x7a))
|
||||
ch -= 0x3C;
|
||||
else
|
||||
return(0);
|
||||
|
||||
for(unsigned char i = 0; i < 8; i++)
|
||||
{
|
||||
data = FONTTYPE8_8[ch][i];
|
||||
|
||||
for(unsigned char j = 0; j < 8; j++)
|
||||
{
|
||||
if( (data&BIT_MASK[j]) == 0)
|
||||
gui_disp_buf[y / 8][x] &= (~(0x01 << ( y % 8)));
|
||||
else
|
||||
gui_disp_buf[y / 8][x] |= (0x01 <<( y % 8));
|
||||
LCD_UpdatePoint(x, y);
|
||||
x ++;
|
||||
}
|
||||
x -= 8;
|
||||
y++;
|
||||
}
|
||||
|
||||
return(1);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Function Name : LCD_PutString
|
||||
* Description : output string to screen
|
||||
* Input : x X-coordinate
|
||||
y Y-coordinate
|
||||
str pointer to string
|
||||
* Output : None
|
||||
* Return : None
|
||||
****************************************************************************/
|
||||
void LCD_PutString(unsigned long x, unsigned long y, char *str)
|
||||
{
|
||||
while(1)
|
||||
{
|
||||
if( (*str)=='\0' ) break;
|
||||
if( LCD_PutChar(x, y, *str++) == 0 ) break;
|
||||
x += 6;
|
||||
}
|
||||
}
|
||||
|
||||
static rt_err_t rt_lcd_control (rt_device_t dev, rt_uint8_t cmd, void *args)
|
||||
{
|
||||
switch (cmd)
|
||||
@@ -307,6 +447,12 @@ static rt_err_t rt_lcd_control (rt_device_t dev, rt_uint8_t cmd, void *args)
|
||||
case RT_DEVICE_CTRL_LCD_DISPLAY_OFF:
|
||||
LCD_WriteCmd(Display_Off);
|
||||
break;
|
||||
case RT_DEVICE_CTRL_LCD_PUT_STRING:
|
||||
LCD_PutString(x, y, (rt_uint8_t*)args);
|
||||
break;
|
||||
case RT_DEVICE_CTRL_LCD_CLEAR_SCR:
|
||||
LCD_ClearSCR();
|
||||
break;
|
||||
}
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
@@ -161,6 +161,27 @@ LCD_DATA[0..7] PORT5.[0..7]
|
||||
#define RT_DEVICE_CTRL_LCD_UPDATE_POINT 8
|
||||
#define RT_DEVICE_CTRL_LCD_DISPLAY_ON 9
|
||||
#define RT_DEVICE_CTRL_LCD_DISPLAY_OFF 10
|
||||
#define RT_DEVICE_CTRL_LCD_PUT_STRING 11
|
||||
|
||||
enum
|
||||
{
|
||||
ADC_MSG,
|
||||
KEY_MSG,
|
||||
CPU_MSG,
|
||||
MAX_MSG,
|
||||
};
|
||||
|
||||
struct lcd_msg
|
||||
{
|
||||
rt_uint8_t type;
|
||||
rt_uint16_t adc_value;
|
||||
rt_uint8_t key;
|
||||
rt_uint16_t major;
|
||||
rt_uint16_t minor;
|
||||
};
|
||||
|
||||
extern rt_uint32_t x;
|
||||
extern rt_uint32_t y;
|
||||
|
||||
void rt_hw_lcd_init(void);
|
||||
|
||||
|
||||
+1
-1
@@ -63,7 +63,7 @@
|
||||
|
||||
/* SECTION: RTGUI support */
|
||||
/* using RTGUI support */
|
||||
#define RT_USING_RTGUI
|
||||
//#define RT_USING_RTGUI
|
||||
|
||||
/* name length of RTGUI object */
|
||||
#define RTGUI_NAME_MAX 16
|
||||
|
||||
Reference in New Issue
Block a user