提交 c4b51ff7 编写于 作者: D dzzxzz

update Fujitsu FM3 easy kit IAR project:

add LCD/ADC/KEY/LED device support
using RTGUI to display the ADC and key status on the 128x64 LCD

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@1317 bbd45198-f89e-11dd-88c7-29a3b14d5316
上级 c5bc8e86
......@@ -19,18 +19,31 @@
#include <rtthread.h>
#include "board.h"
#include "led.h"
#ifdef RT_USING_RTGUI
#include "key.h"
#include "adc.h"
#include "lcd.h"
#include <rtgui/rtgui.h>
extern void rtgui_startup();
#endif
void rt_init_thread_entry(void *parameter)
{
while(1)
{
rt_hw_led_on(LED1);
rt_hw_led_off(LED2);
rt_thread_delay(100);
rt_hw_led_off(LED1);
rt_hw_led_on(LED2);
rt_thread_delay(100);
}
rt_hw_led_init();
#ifdef RT_USING_RTGUI
rt_hw_key_init();
rt_hw_adc_init();
rt_hw_lcd_init();
/* re-init device driver */
rt_device_init_all();
/* startup rtgui */
rtgui_startup();
#endif
}
int rt_application_init()
......@@ -40,7 +53,7 @@ int rt_application_init()
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);
return 0;
}
......
......@@ -42,58 +42,11 @@ void rt_hw_timer_handler(void)
rt_interrupt_leave();
}
void led_init(void)
{
/*Select CPIO function*/
LED_PFR &= ~LED_MASK;
/*Set Pin to turn off leds*/
LED_PDOR |= LED_MASK;
/*Make led pins outputs*/
LED_DDR |= LED_MASK;
}
void rt_hw_led_on(int n)
{
switch(n)
{
case LED1:
LED_PDOR &= ~LED1;
break;
case LED2:
LED_PDOR &= ~LED2;
break;
case LED3:
LED_PDOR &= ~LED3;
break;
default:
break;
}
}
void rt_hw_led_off(int n)
{
switch(n)
{
case LED1:
LED_PDOR |= LED1;
break;
case LED2:
LED_PDOR |= LED2;
break;
case LED3:
LED_PDOR |= LED3;
break;
default:
break;
}
}
/**
* This function will initial FM3 Easy Kit board.
*/
void rt_hw_board_init()
{
led_init();
/* init systick */
SysTick_Config(SystemFrequency/RT_TICK_PER_SECOND - 1);
}
......
......@@ -10,24 +10,12 @@
* Change Logs:
* Date Author Notes
* 2009-09-22 Bernard add board.h to this bsp
* 2010-02-04 Magicoe add board.h to LPC176x bsp
* 2011-03-04 lgnq add board.h to FM3 bsp
*/
#ifndef __BOARD_H__
#define __BOARD_H__
#include "mb9bf506r.h"
/*LEDs*/
#define LED1 (1UL<<10)
#define LED2 (1UL<<11)
#define LED3 (1UL<<12)
#define LED_MASK (LED1 | LED2 | LED3)
#define LED_PFR (FM3_GPIO->PFR3)
#define LED_DDR (FM3_GPIO->DDR3)
#define LED_PDOR (FM3_GPIO->PDOR3)
//Internal SRAM memory size[Kbytes] <8-64>
//MB9BF500 : 32
//MB9BF504 : 32
......@@ -36,8 +24,6 @@
#define FM3_SRAM_SIZE 32
#define FM3_SRAM_END (0x1FFFC000 + FM3_SRAM_SIZE * 1024)
void rt_hw_led_on(int n);
void rt_hw_led_off(int n);
void rt_hw_board_init(void);
#endif
......@@ -278,6 +278,7 @@
<state>$PROJ_DIR$\</state>
<state>$PROJ_DIR$\CMSIS</state>
<state>$PROJ_DIR$\..\..\include</state>
<state>$PROJ_DIR$\..\..\components\rtgui\include</state>
</option>
<option>
<name>CCStdIncCheck</name>
......@@ -1788,14 +1789,218 @@
<name>$PROJ_DIR$\..\..\src\timer.c</name>
</file>
</group>
<group>
<name>Rtgui</name>
<file>
<name>$PROJ_DIR$\..\..\components\rtgui\widgets\about_view.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\components\rtgui\common\asc12font.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\components\rtgui\common\asc16font.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\components\rtgui\common\blit.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\components\rtgui\widgets\box.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\components\rtgui\widgets\button.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\components\rtgui\widgets\checkbox.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\components\rtgui\common\color.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\components\rtgui\widgets\combobox.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\components\rtgui\widgets\container.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\components\rtgui\common\dc.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\components\rtgui\common\dc_buffer.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\components\rtgui\common\dc_client.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\components\rtgui\common\dc_hw.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\components\rtgui\server\driver.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\components\rtgui\widgets\filelist_view.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\components\rtgui\common\filerw.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\components\rtgui\common\font.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\components\rtgui\common\font_bmp.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\components\rtgui\common\font_freetype.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\components\rtgui\common\font_hz_bmp.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\components\rtgui\common\font_hz_file.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\components\rtgui\common\hz12font.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\components\rtgui\common\hz16font.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\components\rtgui\widgets\iconbox.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\components\rtgui\common\image.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\components\rtgui\common\image_bmp.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\components\rtgui\common\image_container.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\components\rtgui\common\image_hdc.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\components\rtgui\common\image_jpg.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\components\rtgui\common\image_png.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\components\rtgui\common\image_xpm.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\components\rtgui\widgets\label.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\components\rtgui\widgets\list_view.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\components\rtgui\widgets\listbox.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\components\rtgui\widgets\listctrl.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\components\rtgui\widgets\menu.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\components\rtgui\server\mouse.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\components\rtgui\server\mouse.h</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\components\rtgui\widgets\notebook.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\components\rtgui\server\panel.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\components\rtgui\server\panel.h</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\components\rtgui\widgets\progressbar.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\components\rtgui\widgets\radiobox.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\components\rtgui\common\region.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\components\rtgui\common\rtgui_object.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\components\rtgui\common\rtgui_system.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\components\rtgui\common\rtgui_theme.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\components\rtgui\common\rtgui_xml.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\components\rtgui\widgets\scrollbar.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\components\rtgui\server\server.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\components\rtgui\widgets\slider.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\components\rtgui\widgets\staticline.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\components\rtgui\widgets\textbox.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\components\rtgui\widgets\title.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\components\rtgui\widgets\toplevel.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\components\rtgui\server\topwin.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\components\rtgui\server\topwin.h</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\components\rtgui\widgets\view.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\components\rtgui\widgets\widget.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\components\rtgui\widgets\window.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\components\rtgui\widgets\workbench.c</name>
</file>
</group>
<group>
<name>Startup</name>
<file>
<name>$PROJ_DIR$\adc.c</name>
</file>
<file>
<name>$PROJ_DIR$\application.c</name>
</file>
<file>
<name>$PROJ_DIR$\board.c</name>
</file>
<file>
<name>$PROJ_DIR$\info.c</name>
</file>
<file>
<name>$PROJ_DIR$\key.c</name>
</file>
<file>
<name>$PROJ_DIR$\lcd.c</name>
</file>
<file>
<name>$PROJ_DIR$\led.c</name>
</file>
<file>
<name>$PROJ_DIR$\startup.c</name>
</file>
......
#include <rtgui/rtgui.h>
#include <rtgui/rtgui_server.h>
#include <rtgui/rtgui_system.h>
#include <rtgui/widgets/view.h>
#include <rtgui/widgets/workbench.h>
#include "adc.h"
#include <rtthread.h>
extern rt_uint16_t adc_value;
static rt_bool_t view_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
{
if(event->type == RTGUI_EVENT_PAINT)
{
struct rtgui_dc* dc;
struct rtgui_rect rect;
dc = rtgui_dc_begin_drawing(widget);
if(dc == RT_NULL)
return RT_FALSE;
rtgui_widget_get_rect(widget, &rect);
rtgui_dc_fill_rect(dc, &rect);
rect.x2 -= 1; rect.y2 -= 1;
rtgui_dc_draw_hline(dc, rect.x1, rect.x2, rect.y1);
rtgui_dc_draw_vline(dc, rect.x1, rect.y1, rect.y2);
rtgui_dc_draw_hline(dc, rect.x1, rect.x2, rect.y2);
rtgui_dc_draw_vline(dc, rect.x2, rect.y1, rect.y2 + 1);
/* shrink border */
rtgui_rect_inflate(&rect, -1);
/* draw text */
rtgui_widget_get_rect(widget, &rect);
rect.x1 += 1;
rect.y1 += 1;
rtgui_dc_draw_text(dc, "FM3 Easy Kit Demo", &rect);
rect.y1 += 10;
rtgui_dc_draw_text(dc, "[rt-thread/RTGUI]", &rect);
rtgui_dc_end_drawing(dc);
return RT_FALSE;
}
else if(event->type == RTGUI_EVENT_KBD)
{
struct rtgui_event_kbd* ekbd = (struct rtgui_event_kbd*)event;
if(ekbd->type == RTGUI_KEYDOWN)
{
char key_str[16];
struct rtgui_dc* dc;
struct rtgui_rect rect;
switch(ekbd->key)
{
case RTGUIK_LEFT:
rt_sprintf(key_str, "KEY = %s", "LEFT");
break;
case RTGUIK_RIGHT:
rt_sprintf(key_str, "KEY = %s", "RIGHT");
break;
case RTGUIK_DOWN:
rt_sprintf(key_str, "KEY = %s", "DOWN");
break;
case RTGUIK_UP:
rt_sprintf(key_str, "KEY = %s", "UP");
break;
default:
rt_sprintf(key_str, "KEY = %s", "UNKNOWN");
break;
}
dc = rtgui_dc_begin_drawing(widget);
if(dc == RT_NULL)
return RT_FALSE;
rect.x1 = 10;
rect.y1 = 30;
rect.x2 = 120;
rect.y2 = 40;
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)
{
char adc_str[10];
struct rtgui_dc* dc;
struct rtgui_rect rect;
dc = rtgui_dc_begin_drawing(widget);
if(dc == RT_NULL)
return RT_FALSE;
struct rtgui_event_command* ecmd = (struct rtgui_event_command*)event;
switch(ecmd->command_id)
{
case ADC_UPDATE:
rect.x1 = 10;
rect.y1 = 40;
rect.x2 = 120;
rect.y2 = 50;
rtgui_dc_fill_rect(dc, &rect);
rt_sprintf(adc_str, "ADC = %d mv", adc_value);
rtgui_dc_draw_text(dc, adc_str, &rect);
rtgui_dc_end_drawing(dc);
}
}
return rtgui_view_event_handler(widget, event);
}
static void info_entry(void* parameter)
{
rt_mq_t mq;
struct rtgui_view* view;
struct rtgui_workbench* workbench;
mq = rt_mq_create("qInfo", 256, 4, RT_IPC_FLAG_FIFO);
rtgui_thread_register(rt_thread_self(), mq);
workbench = rtgui_workbench_create("info", "workbench");
if(workbench == RT_NULL)
return;
view = rtgui_view_create("view");
RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(view)) = white;
RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(view)) = black;
rtgui_widget_set_event_handler(RTGUI_WIDGET(view), view_event_handler);
rtgui_workbench_add_view(workbench, view);
/* this view can be focused */
RTGUI_WIDGET(view)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
/* set widget focus */
rtgui_widget_focus(RTGUI_WIDGET(view));
rtgui_view_show(view, RT_FALSE);
rtgui_workbench_event_loop(workbench);
rtgui_thread_deregister(rt_thread_self());
rt_mq_delete(mq);
}
rt_thread_t info_tid;
void info_init()
{
info_tid = rt_thread_create("info",
info_entry, RT_NULL,
2048, 26, 10);
if (info_tid != RT_NULL) rt_thread_startup(info_tid);
}
void rtgui_startup()
{
rtgui_rect_t rect;
/* GUIϵͳʼ */
rtgui_system_server_init();
/* register dock panel */
rect.x1 = 0;
rect.y1 = 0;
rect.x2 = 128;
rect.y2 = 64;
rtgui_panel_register("info", &rect);
rtgui_panel_set_default_focused("info");
/* info workbench */
info_init();
}
#include <rtthread.h>
#include "key.h"
#include <rtgui/event.h>
#include <rtgui/rtgui_server.h>
static void key_io_init(void)
{
/*Select CPIO function*/
KEY_PFR &= ~KEY_MASK;
/*Set CPIO Pull-Up function*/
KEY_PCR |= KEY_MASK;
/*Make button pins inputs*/
KEY_DDR &= ~KEY_MASK;
}
static void key_thread_entry(void *parameter)
{
rt_time_t next_delay;
struct rtgui_event_kbd kbd_event;
rt_uint8_t i;
key_io_init();
/* init keyboard event */
RTGUI_EVENT_KBD_INIT(&kbd_event);
kbd_event.mod = RTGUI_KMOD_NONE;
kbd_event.unicode = 0;
while (1)
{
next_delay = RT_TICK_PER_SECOND/10;
kbd_event.key = RTGUIK_UNKNOWN;
kbd_event.type = RTGUI_KEYDOWN;
if(KEY_ENTER_GETVALUE() == 0 )
{
for(i=0; ; i++)
{
rt_thread_delay( next_delay );
if (KEY_ENTER_GETVALUE() == 0)
{
if(i>=4)
{
/* HOME key */
//rt_kprintf("key_home\n");
kbd_event.key = RTGUIK_HOME;
next_delay = RT_TICK_PER_SECOND/5;
break;
}
}
else
{
//rt_kprintf("key_enter\n");
kbd_event.key = RTGUIK_RETURN;
break;
}
}
}
if(KEY_DOWN_GETVALUE() == 0)
{
// rt_kprintf("key_down\n");
kbd_event.key = RTGUIK_DOWN;
}
if(KEY_UP_GETVALUE() == 0)
{
// rt_kprintf("key_up\n");
kbd_event.key = RTGUIK_UP;
}
if(KEY_RIGHT_GETVALUE() == 0)
{
// rt_kprintf("key_right\n");
kbd_event.key = RTGUIK_RIGHT;
}
if(KEY_LEFT_GETVALUE() == 0)
{
// rt_kprintf("key_left\n");
kbd_event.key = RTGUIK_LEFT;
}
if(kbd_event.key != RTGUIK_UNKNOWN)
{
/* post down event */
rtgui_server_post_event(&(kbd_event.parent), sizeof(kbd_event));
//next_delay = RT_TICK_PER_SECOND/10;
/* delay to post up event */
rt_thread_delay(next_delay);
/* post up event */
kbd_event.type = RTGUI_KEYUP;
rtgui_server_post_event(&(kbd_event.parent), sizeof(kbd_event));
}
/* wait next key press */
rt_thread_delay(next_delay);
}
}
static rt_thread_t key_thread;
void rt_hw_key_init(void)
{
key_thread = rt_thread_create("key", key_thread_entry, RT_NULL, 384, 30, 5);
if(key_thread != RT_NULL)
rt_thread_startup(key_thread);
}
/*
* File : key.h
* 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-06 lgnq
*/
#ifndef __KEY_H__
#define __KEY_H__
#include "mb9bf506r.h"
#define KEY_DOWN (1<<0)
#define KEY_ENTER (1<<1)
#define KEY_LEFT (1<<2)
#define KEY_RIGHT (1<<3)
#define KEY_UP (1<<4)
#define KEY_MASK (KEY_DOWN | KEY_ENTER | KEY_LEFT | KEY_RIGHT | KEY_UP)
#define KEY_PFR (FM3_GPIO->PFR7)
#define KEY_PCR (FM3_GPIO->PCR7)
#define KEY_PDIR (FM3_GPIO->PDIR7)
#define KEY_DDR (FM3_GPIO->DDR7)
#define RT_DEVICE_CTRL_KEY_SCAN 0
#define RT_DEVICE_CTRL_KEY_STATUS 1
#define SET_BIT(byte, bit) ((byte) |= (1<<(bit)))
#define CLR_BIT(byte, bit) ((byte) &= ~(1<<(bit)))
#define TST_BIT(byte, bit) (((byte) & (1<<(bit)))?1:0)
#define KEY_ENTER_GETVALUE() TST_BIT(KEY_PDIR, 1)
#define KEY_DOWN_GETVALUE() TST_BIT(KEY_PDIR, 0)
#define KEY_UP_GETVALUE() TST_BIT(KEY_PDIR, 4)
#define KEY_RIGHT_GETVALUE() TST_BIT(KEY_PDIR, 3)
#define KEY_LEFT_GETVALUE() TST_BIT(KEY_PDIR, 2)
void rt_hw_key_init(void);
#endif
\ No newline at end of file
/*
* File : lcd.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-05 lgnq ZYMG12864C3 LCD driver
*/
#include <rtthread.h>
#include "lcd.h"
static rt_uint8_t gui_disp_buf[GUI_LCM_YMAX/8][GUI_LCM_XMAX];
struct rtgui_lcd_device
{
struct rt_device parent;
/* screen width and height */
rt_uint16_t width;
rt_uint16_t height;
void* hw_framebuffer;
};
static struct rtgui_lcd_device *lcd = RT_NULL;
void Power_Delay(void)
{
rt_uint32_t i=0x4ffff;
while(i--)
;//asm("nop");
}
void Delay(void)
{
rt_uint8_t i=0x8;
while(i--)
;//asm("nop");
}
void Reset_Delay(void)
{
rt_uint8_t i=0xff;
while(i--)
;//asm("nop");
}
void LCD_WriteCmd(unsigned char command)
{
rt_uint8_t i;
LCD_PS_LOW();
LCD_CS_LOW();
LCD_CD_LOW();
for(i=0; i<8; i++)
{
if(command & (0x80 >> i))
LCD_DATA_HIGH();
else
LCD_DATA_LOW();
LCD_CLK_LOW();
Delay();
LCD_CLK_HIGH();
Delay();
}
LCD_CS_HIGH();
}
void LCD_WriteData(unsigned char data)
{
rt_uint8_t i;
LCD_PS_LOW();
LCD_CS_LOW();
LCD_CD_HIGH();
for(i=0; i<8; i++)
{
if(data & (0x80 >> i))
LCD_DATA_HIGH();
else
LCD_DATA_LOW();
LCD_CLK_LOW();
Delay();
LCD_CLK_HIGH();
Delay();
}
LCD_CS_HIGH();
}
#ifdef RT_USING_RTGUI
#include <rtgui/driver.h>
#include <rtgui/color.h>
static void rt_hw_lcd_update(rtgui_rect_t *rect)
{
rt_uint8_t i,j = GUI_LCM_XMAX;
rt_uint8_t* p = (rt_uint8_t*)gui_disp_buf;
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();
}
}
}
static rt_uint8_t * rt_hw_lcd_get_framebuffer(void)
{
return(rt_uint8_t *)gui_disp_buf;
}
static void rt_hw_lcd_set_pixel(rtgui_color_t *c, rt_base_t x, rt_base_t y)
{
rt_uint8_t page;
page = y/8;
if(*c == black)
gui_disp_buf[page][x] |= 1<<(y%8);
else
if(*c == white)
gui_disp_buf[page][x] &= ~(1<<(y%8));
}
static void rt_hw_lcd_get_pixel(rtgui_color_t *c, rt_base_t x, rt_base_t y)
{
rt_uint8_t page;
page = y/8;
if(gui_disp_buf[page][x] & (1<<(y%8)))
*c = black;
else
*c = white;
}
static void rt_hw_lcd_draw_hline(rtgui_color_t *c, rt_base_t x1, rt_base_t x2, rt_base_t y)
{
rt_uint8_t page;
rt_uint8_t i;
page = y/8;
for(i=x1; i<x2; i++)
{
if(*c == black)
gui_disp_buf[page][i] |= 1<<(y%8);
else
if(*c == white)
gui_disp_buf[page][i] &= ~(1<<(y%8));
}
}
static void rt_hw_lcd_draw_vline(rtgui_color_t *c, rt_base_t x, rt_base_t y1, rt_base_t y2)
{
rt_uint8_t y;
for(y = y1; y < y2; y ++)
{
rt_hw_lcd_set_pixel(c, x, y);
}
}
static void rt_hw_lcd_draw_raw_hline(rt_uint8_t *pixels, rt_base_t x1, rt_base_t x2, rt_base_t y)
{
rt_uint8_t coll;
rt_uint8_t colh;
rt_uint8_t page;
rt_uint8_t i;
page = y/8;
for(i=x1; i<x2; i++)
{
gui_disp_buf[page][i] |= 1<<(y%8);
coll = i & 0x0f;
colh = i >> 4;
LCD_WriteCmd(Set_Page_Addr_0 | page);
LCD_WriteCmd(Set_ColH_Addr_0 | colh);
LCD_WriteCmd(Set_ColL_Addr_0 | coll);
LCD_WriteData(gui_disp_buf[page][i]);
}
}
struct rtgui_graphic_driver _rtgui_lcd_driver =
{
"lcd",
1,
LCD_WIDTH,
LCD_HEIGHT,
rt_hw_lcd_update,
rt_hw_lcd_get_framebuffer,
rt_hw_lcd_set_pixel,
rt_hw_lcd_get_pixel,
rt_hw_lcd_draw_hline,
rt_hw_lcd_draw_vline,
rt_hw_lcd_draw_raw_hline
};
#endif
void lcd_io_init()
{
/* Release the analog input function*/
FM3_GPIO->ADE =0x03;
/*Select CPIO function*/
LCD_CS_PFR &= ~LCD_CS;
/*Make pin output*/
LCD_CS_DDR |= LCD_CS;
/*Select CPIO function*/
LCD_CD_PFR &= ~LCD_CD;
/*Make pin output*/
LCD_CD_DDR |= LCD_CD;
/*Select CPIO function*/
LCD_PS_PFR &= ~LCD_PS;
/*Make pin output*/
LCD_PS_DDR |= LCD_PS;
/*Select CPIO function*/
LCD_CLK_PFR &= ~LCD_CLK;
/*Make pin output*/
LCD_CLK_DDR |= LCD_CLK;
/*Select CPIO function*/
LCD_DATA_PFR &= ~LCD_DATA;
/*Make pin output*/
LCD_DATA_DDR |= LCD_DATA;
}
/* RT-Thread Device Interface */
static rt_err_t rt_lcd_init (rt_device_t dev)
{
lcd_io_init();
Power_Delay();
LCD_WriteCmd(Display_Off);
Reset_Delay();
// Resetting circuit
LCD_WriteCmd(Reset_LCD);
Reset_Delay();
// LCD bias setting
LCD_WriteCmd(Set_LCD_Bias_9);
Reset_Delay();
// ADC selection: display from left to right
LCD_WriteCmd(Set_ADC_Normal);
Reset_Delay();
// Common output state selection: display from up to down
LCD_WriteCmd(COM_Scan_Dir_Reverse);
Reset_Delay();
LCD_WriteCmd(Power_Booster_On);
Power_Delay(); // 50ms requried
LCD_WriteCmd(Power_Regulator_On);
Power_Delay(); // 50ms
LCD_WriteCmd(Power_Follower_On);
Power_Delay(); // 50ms
// Setting the built-in resistance radio for regulation of the V0 voltage
// Electronic volume control
// Power control setting
LCD_WriteCmd(Set_ElecVol_Reg|0x05);
Delay();
LCD_WriteCmd(Set_ElecVol_Mode);
Delay();
LCD_WriteCmd(Set_ElecVol_Reg);
Delay();
// LCD_Clear();
Delay();
LCD_WriteCmd(Set_Page_Addr_0);
Delay();
LCD_WriteCmd(Set_ColH_Addr_0);
Delay();
LCD_WriteCmd(Set_ColL_Addr_0);
Delay();
LCD_WriteCmd(Display_On);
Delay();
LCD_WriteCmd(Display_All_On);
Delay();
LCD_WriteCmd(Display_Off);
Delay();
LCD_WriteCmd(Display_On);
Delay();
LCD_WriteCmd(Display_All_Normal);
Delay();
return RT_EOK;
}
static rt_err_t rt_lcd_control (rt_device_t dev, rt_uint8_t cmd, void *args)
{
switch (cmd)
{
case RT_DEVICE_CTRL_LCD_GET_WIDTH:
*((rt_uint16_t*)args) = lcd->width;
break;
case RT_DEVICE_CTRL_LCD_GET_HEIGHT:
*((rt_uint16_t*)args) = lcd->height;
break;
case RT_DEVICE_CTRL_LCD_DISPLAY_ON:
LCD_WriteCmd(Display_On);
break;
case RT_DEVICE_CTRL_LCD_DISPLAY_OFF:
LCD_WriteCmd(Display_Off);
break;
}
return RT_EOK;
}
static rt_err_t rt_lcd_open(rt_device_t dev, rt_uint16_t oflag)
{
RT_ASSERT(dev != RT_NULL);
return RT_EOK;
}
static rt_err_t rt_lcd_close(rt_device_t dev)
{
RT_ASSERT(dev != RT_NULL);
return RT_EOK;
}
void rt_hw_lcd_init(void)
{
lcd = (struct rtgui_lcd_device*)rt_malloc(sizeof(struct rtgui_lcd_device));
if (lcd == RT_NULL)
return; /* no memory yet */
/* init device structure */
lcd->parent.type = RT_Device_Class_Unknown;
lcd->parent.init = rt_lcd_init;
lcd->parent.open = rt_lcd_open;
lcd->parent.close = rt_lcd_close;
lcd->parent.control = rt_lcd_control;
lcd->parent.user_data = RT_NULL;
lcd->width = LCD_WIDTH;
lcd->height = LCD_HEIGHT;
lcd->hw_framebuffer = (void*)gui_disp_buf;
/* register touch device to RT-Thread */
rt_device_register(&(lcd->parent), "lcd", RT_DEVICE_FLAG_RDWR);
#ifdef RT_USING_RTGUI
/* add lcd driver into graphic driver */
rtgui_graphic_driver_add(&_rtgui_lcd_driver);
#endif
}
/*
* File : lcd.h
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006, 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
* 2008-03-29 Yi.Qiu
*/
#ifndef __LCD_H__
#define __LCD_H__
#include <rtthread.h>
#include "mb9bf506r.h"
/********* LCD Hardward Interface *************
LCD_CS PORT1.7
LCD_CD PORT1.6
LCD_WR PORT1.5
LCD_RD PORT1.4
LCD_SCK PORT1.3
LCD_MOSI PORT1.2
LCD_C86 PORT1.1
LCD_PS PORT1.0
LCD_DATA[0..7] PORT5.[0..7]
***********************************************/
#define LCD_CS (1UL << 7)
#define LCD_CS_DDR (FM3_GPIO->DDR1)
#define LCD_CS_PFR (FM3_GPIO->PFR1)
#define LCD_CS_PDOR (FM3_GPIO->PDOR1)
#define LCD_CD (1UL << 6)
#define LCD_CD_DDR (FM3_GPIO->DDR1)
#define LCD_CD_PFR (FM3_GPIO->PFR1)
#define LCD_CD_PDOR (FM3_GPIO->PDOR1)
#define LCD_PS (1UL << 0)
#define LCD_PS_DDR (FM3_GPIO->DDR1)
#define LCD_PS_PFR (FM3_GPIO->PFR1)
#define LCD_PS_PDOR (FM3_GPIO->PDOR1)
#define LCD_CLK (1UL << 6)
#define LCD_CLK_DDR (FM3_GPIO->DDR5)
#define LCD_CLK_PFR (FM3_GPIO->PFR5)
#define LCD_CLK_PDOR (FM3_GPIO->PDOR5)
#define LCD_DATA (1UL << 7)
#define LCD_DATA_DDR (FM3_GPIO->DDR5)
#define LCD_DATA_PFR (FM3_GPIO->PFR5)
#define LCD_DATA_PDOR (FM3_GPIO->PDOR5)
/* LCD driver for ZYMG12864C3 */
#define LCD_WIDTH 128
#define LCD_HEIGHT 64
// Driver the LCD with Parallel or serial interface and the command/data control pin is gpio
#define LCD_CS_HIGH() LCD_CS_PDOR |= LCD_CS
#define LCD_CS_LOW() LCD_CS_PDOR &= ~LCD_CS
#define LCD_CD_HIGH() LCD_CD_PDOR |= LCD_CD
#define LCD_CD_LOW() LCD_CD_PDOR &= ~LCD_CD
#define LCD_PS_HIGH() LCD_PS_PDOR |= LCD_PS
#define LCD_PS_LOW() LCD_PS_PDOR &= ~LCD_PS
#define LCD_CLK_HIGH() LCD_CLK_PDOR |= LCD_CLK
#define LCD_CLK_LOW() LCD_CLK_PDOR &= ~LCD_CLK
#define LCD_DATA_HIGH() LCD_DATA_PDOR |= LCD_DATA
#define LCD_DATA_LOW() LCD_DATA_PDOR &= ~LCD_DATA
// define the arrtibute of ZYMG12864(LCM)
#define GUI_LCM_XMAX 128 // defined the lcd's line-number is 128
#define GUI_LCM_YMAX 64 // defined the lcd's column-number is 64
#define GUI_LCM_PAGE 8 // defined the lcd's page-number is 8(GUI_LCM_YMAX/8)
/* set LCD command */
#define Display_On 0xAF // A0,RD,WR:010
#define Display_Off 0xAE // A0,RD,WR:010
#define Set_Start_Line_0 0x40 // A0,RD,WR:010; line0~line63
#define Set_Page_Addr_0 0xB0 // A0,RD,WR:010; addr0~addr8
#define Set_ColH_Addr_0 0x10 // A0,RD,WR:010;
#define Set_ColL_Addr_0 0x00 // A0,RD,WR:010; addr0~addr131
#define Read_Status 0x-0 // A0,RD,WR:001; BUSY | ADC | ON/OFF | RESET | 0 0 0 0
#define Status_Busy 0x80
#define Status_ADC_Reverse 0x40 // column address 131-n : SEG n, else column address n : SEG n
#define Status_Display_Off 0x20
#define Status_Reset 0x80
#define Write_Data 0x-- // A0,RD,WR:110
#define Read_Date 0x-- // A0,RD,WR:101; spi mode is unavailable
#define Set_ADC_Normal 0xA0 // A0,RD,WR:010
#define Set_ADC_Reverse 0xA1 // A0,RD,WR:010
#define Display_Normal 0xA6 // A0,RD,WR:010
#define Display_Reverse 0xA7 // A0,RD,WR:010; reverse color
#define Display_All_On 0xA5 // A0,RD,WR:010
#define Display_All_Normal 0xA4 // A0,RD,WR:010
/*************************************************************
* bias: 1/65duty | 1/49duty | 1/33duty | 1/55duty | 1/53duty *
* ---------------|----------|----------|----------|--------- *
* A2: 1/9 bias | 1/8 bias | 1/6 bias | 1/8 bias | 1/8 bias *
* A3: 1/7 bias | 1/6 bias | 1/5 bias | 1/6 bias | 1/6 bias *
**************************************************************/
#define Set_LCD_Bias_7 0xA3 // A0,RD,WR:010
#define Set_LCD_Bias_9 0xA2 // A0,RD,WR:010
#define RMW_Mode_Enable 0xE0 // A0,RD,WR:010; the column address locked when read command operating
#define RMW_Mode_End 0xEE // A0,RD,WR:010; returns to the column address when RMW was entered.
#define Reset_LCD 0xE2 // A0,RD,WR:010
/**************************************************************************************
* Com Scan Dir: | 1/65duty | 1/49duty | 1/33duty | 1/55duty | 1/53duty *
* --------------|-------------|-------------|-------------|------------------------ *
* C0: Normal | COM0:COM63 | COM0:COM47 | COM0:COM31 | COM0:COM53 | COM0:COM51 *
* C8: Reverse | COM63:COM0 | COM47:COM0 | COM31:COM0 | COM53:COM0 | COM51:COM0 *
***************************************************************************************/
#define COM_Scan_Dir_Normal 0xC0 // A0,RD,WR:010
#define COM_Scan_Dir_Reverse 0xC8 // A0,RD,WR:010
// 0 0 1 0 1 | Booster On | Regulator On | Follower On
#define Power_Booster_On 0x2C // A0,RD,WR:010
#define Power_Regulator_On 0x2E // A0,RD,WR:010
#define Power_Follower_On 0x2F // A0,RD,WR:010
#define Set_Resistor_Ratio 0x20 // A0,RD,WR:010; 20~27:small~large
#define Set_ElecVol_Mode 0x81 // A0,RD,WR:010; double byte command
#define Set_ElecVol_Reg 0x20 // A0,RD,WR:010; the electronic volume(64 voltage levels:00~3F) function is not used.
#define Sleep_Mode_Enable 0xAC // A0,RD,WR:010; double byte command, preceding command
#define Sleep_Mode_Disable 0xAD // A0,RD,WR:010; preceding command
#define Sleep_Mode_Deliver 0x00 // A0,RD,WR:010; following command
#define Boost_Ratio_Set 0xF8 // A0,RD,WR:010; double byte command, preceding command
#define Boost_Ratio_234 0x00 // A0,RD,WR:010; following command
#define Boost_Ratio_5 0x01 // A0,RD,WR:010; following command
#define Boost_Ratio_6 0x03 // A0,RD,WR:010; following command
#define Command_Nop 0xE3 // A0,RD,WR:010
#define Command_IC_Test 0xFC // A0,RD,WR:010; don't use
#define RT_DEVICE_CTRL_LCD_GET_WIDTH 0
#define RT_DEVICE_CTRL_LCD_GET_HEIGHT 1
#define RT_DEVICE_CTRL_LCD_GET_BPP 2
#define RT_DEVICE_CTRL_LCD_GET_FRAMEBUFFER 3
#define RT_DEVICE_CTRL_LCD_POWER_ON 4
#define RT_DEVICE_CTRL_LCD_POWER_OFF 5
#define RT_DEVICE_CTRL_LCD_CLEAR_SCR 6
#define RT_DEVICE_CTRL_LCD_FILL_ALL 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
void rt_hw_lcd_init(void);
#endif
/*
* File : led.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 <rthw.h>
#include "mb9bf506r.h"
#include "led.h"
void rt_hw_led_on(rt_uint8_t num)
{
RT_ASSERT(num < LEDS_MAX_NUMBER);
switch(num)
{
case 1:
LED_PDOR &= ~LED1;
break;
case 2:
LED_PDOR &= ~LED2;
break;
case 3:
LED_PDOR &= ~LED3;
break;
default:
break;
}
}
void rt_hw_led_off(rt_uint8_t num)
{
RT_ASSERT(num < LEDS_MAX_NUMBER);
switch(num)
{
case 1:
LED_PDOR |= LED1;
break;
case 2:
LED_PDOR |= LED2;
break;
case 3:
LED_PDOR |= LED3;
break;
default:
break;
}
}
void rt_hw_led_toggle(rt_uint8_t num)
{
RT_ASSERT(num < LEDS_MAX_NUMBER);
switch(num)
{
case 1:
if(LED_PDOR&LED1)
LED_PDOR &= ~LED1;
else
LED_PDOR |= LED1;
break;
case 2:
if(LED_PDOR&LED2)
LED_PDOR &= ~LED2;
else
LED_PDOR |= LED2;
break;
case 3:
if(LED_PDOR&LED3)
LED_PDOR &= ~LED3;
else
LED_PDOR |= LED3;
break;
default:
break;
}
}
static rt_err_t led_io_init(void)
{
/*Select CPIO function*/
LED_PFR &= ~LED_MASK;
/*Set Pin to turn off leds*/
LED_PDOR |= LED_MASK;
/*Make led pins outputs*/
LED_DDR |= LED_MASK;
return RT_EOK;
}
static void led1_thread_entry(void *parameter)
{
while(1)
{
rt_hw_led_toggle(1);
rt_thread_delay(10);
}
}
static void led2_thread_entry(void *parameter)
{
while(1)
{
rt_hw_led_toggle(2);
rt_thread_delay(20);
}
}
static rt_thread_t led1_thread;
static rt_thread_t led2_thread;
void rt_hw_led_init(void)
{
led_io_init();
led1_thread = rt_thread_create("led1", led1_thread_entry, RT_NULL, 384, 31, 5);
if(led1_thread != RT_NULL)
rt_thread_startup(led1_thread);
led2_thread = rt_thread_create("led2", led2_thread_entry, RT_NULL, 384, 30, 5);
if(led2_thread != RT_NULL)
rt_thread_startup(led2_thread);
}
/*
* File : led.h
* 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 __LED_H__
#define __LED_H__
#include "mb9bf506r.h"
#define LEDS_MAX_NUMBER 4
/*LEDs*/
#define LED1 (1UL<<10)
#define LED2 (1UL<<11)
#define LED3 (1UL<<12)
#define LED_MASK (LED1 | LED2 | LED3)
#define LED_PFR (FM3_GPIO->PFR3)
#define LED_DDR (FM3_GPIO->DDR3)
#define LED_PDOR (FM3_GPIO->PDOR3)
#define RT_DEVICE_CTRL_LED_ON 0
#define RT_DEVICE_CTRL_LED_OFF 1
#define RT_DEVICE_CTRL_LED_TOGGLE 2
void rt_hw_led_init(void);
void rt_hw_led_on(rt_uint8_t num);
void rt_hw_led_off(rt_uint8_t num);
void rt_hw_led_toggle(rt_uint8_t num);
#endif
\ No newline at end of file
......@@ -61,4 +61,28 @@
/* the buffer size of console */
#define RT_CONSOLEBUF_SIZE 128
/* SECTION: RTGUI support */
/* using RTGUI support */
#define RT_USING_RTGUI
/* name length of RTGUI object */
#define RTGUI_NAME_MAX 16
/* support 16 weight font */
//#define RTGUI_USING_FONT16
/* support 12 weight font */
#define RTGUI_USING_FONT12
/* support Chinese font */
//#define RTGUI_USING_FONTHZ
/* use DFS as file interface */
//#define RTGUI_USING_DFS_FILERW
/* use font file as Chinese font */
/* #define RTGUI_USING_HZ_FILE */
/* use Chinese bitmap font */
//#define RTGUI_USING_HZ_BMP
/* use small size in RTGUI */
//#define RTGUI_USING_SMALL_SIZE
/* use mouse cursor */
/* #define RTGUI_USING_MOUSE_CURSOR */
#define RTGUI_DEFAULT_FONT_SIZE 12
#endif
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册