Merge pull request #4498 from mysterywolf/mb9bf500r

[mb9bf500r] manual & auto formatted
This commit is contained in:
Bernard Xiong 2021-03-23 20:01:04 +08:00 committed by GitHub
commit 12673d37de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 950 additions and 976 deletions

View File

@ -1,17 +1,13 @@
/*
* File : adc.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2011, RT-Thread Develop Team
* Copyright (c) 2006-2021, 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
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2011-03-03 lgnq
* 2011-03-03 lgnq First version
*/
#include <rtthread.h>
#include <rthw.h>
#include "mb9bf506r.h"
@ -33,45 +29,45 @@ static rt_err_t rt_adc_init(rt_device_t dev)
if(!(dev->flag & RT_DEVICE_FLAG_ACTIVATED))
{
/* I/O setting AN08 - P18 */
/* I/O setting AN08 - P18 */
FM3_GPIO->ADE |= 0x100;
FM3_GPIO->PFR1 = 0x100;
/* A/DC setting */
FM3_ADC0->SCIS1 = 0x01;
FM3_ADC0->ADSS1 = 0x00; /* sampling timming ADST0 */
FM3_ADC0->ADST1 = 0x43;
FM3_ADC0->ADCT = 0x02;
FM3_ADC0->SCCR = 0x10; /* FIFO clear,single mode */
FM3_ADC0->CMPCR = 0x00; /* disable comparator */
/* starting A/DC */
FM3_ADC0->SCCR |= 0x01; /* A/DC start */
FM3_GPIO->PFR1 = 0x100;
/* A/DC setting */
FM3_ADC0->SCIS1 = 0x01;
FM3_ADC0->ADSS1 = 0x00; /* sampling timming ADST0 */
FM3_ADC0->ADST1 = 0x43;
FM3_ADC0->ADCT = 0x02;
FM3_ADC0->SCCR = 0x10; /* FIFO clear,single mode */
FM3_ADC0->CMPCR = 0x00; /* disable comparator */
/* starting A/DC */
FM3_ADC0->SCCR |= 0x01; /* A/DC start */
dev->flag |= RT_DEVICE_FLAG_ACTIVATED;
}
return RT_EOK;
}
return RT_EOK;
}
static rt_err_t rt_adc_control(rt_device_t dev, int cmd, void *args)
{
RT_ASSERT(dev != RT_NULL);
RT_ASSERT(dev != RT_NULL);
switch (cmd)
{
case RT_DEVICE_CTRL_ADC_START:
switch (cmd)
{
case RT_DEVICE_CTRL_ADC_START:
FM3_ADC0->SCCR |= 0x1;
break;
case RT_DEVICE_CTRL_ADC_RESULT:
break;
case RT_DEVICE_CTRL_ADC_RESULT:
while(FM3_ADC0->ADSR & 0x1)
;
*((rt_uint16_t*)args) = FM3_ADC0->SCFD;
*((rt_uint16_t*)args) = *((rt_uint16_t*)args) >> 6;
*((rt_uint16_t*)args) = (*((rt_uint16_t*)args)*3300)/1024;
break;
}
return RT_EOK;
break;
}
return RT_EOK;
}
extern struct rt_messagequeue mq;
@ -80,29 +76,29 @@ rt_uint16_t adc_value;
static void adc_thread_entry(void *parameter)
{
rt_device_t device;
#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;
#else
struct lcd_msg msg;
#endif
#endif
device = rt_device_find("adc");
while(1)
{
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);
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;
msg.adc_value = adc_value;
rt_mq_send(&mq, &msg, sizeof(msg));
#endif
rt_thread_delay(20);
@ -112,22 +108,22 @@ static void adc_thread_entry(void *parameter)
static rt_thread_t adc_thread;
void rt_hw_adc_init(void)
{
adc.type = RT_Device_Class_Char;
adc.rx_indicate = RT_NULL;
adc.tx_complete = RT_NULL;
adc.init = rt_adc_init;
adc.open = RT_NULL;
adc.close = RT_NULL;
adc.read = RT_NULL;
adc.write = RT_NULL;
adc.control = rt_adc_control;
adc.user_data = RT_NULL;
adc.type = RT_Device_Class_Char;
adc.rx_indicate = RT_NULL;
adc.tx_complete = RT_NULL;
adc.init = rt_adc_init;
adc.open = RT_NULL;
adc.close = RT_NULL;
adc.read = RT_NULL;
adc.write = RT_NULL;
adc.control = rt_adc_control;
adc.user_data = RT_NULL;
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);
/* register a character device */
rt_device_register(&adc, "adc", RT_DEVICE_FLAG_RDWR);
/* register a character device */
rt_device_register(&adc, "adc", RT_DEVICE_FLAG_RDWR);
}

View File

@ -1,28 +1,24 @@
/*
* File : adc.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2011, RT-Thread Develop Team
* Copyright (c) 2006-2021, 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
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2011-03-03 lgnq
*/
#ifndef __ADC_H__
#define __ADC_H__
/* Exported constants ---------------------------------------------------------*/
/* Exported macro -------------------------------------------------------------*/
#define ADC_MODE_SINGLE 0x00UL
#define ADC_MODE_SCAN 0x01UL
#define ADC_MODE_TAILGATE 0x02UL
#define ADC_MODE_SINGLE 0x00UL
#define ADC_MODE_SCAN 0x01UL
#define ADC_MODE_TAILGATE 0x02UL
#define RT_DEVICE_CTRL_ADC_START 0xF1 /* start ADC conversion */
#define RT_DEVICE_CTRL_ADC_RESULT 0xF2 /* get ADC result */
#define RT_DEVICE_CTRL_ADC_RESULT 0xF2 /* get ADC result */
#define ADC_UPDATE 0

View File

@ -1,11 +1,7 @@
/*
* File : application.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2009 - 2012, RT-Thread Development Team
* Copyright (c) 2006-2021, 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
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
@ -15,7 +11,7 @@
/**
* @addtogroup FM3
*/
/*@{*/
#include <rtthread.h>
@ -37,96 +33,96 @@ static char msg_pool[2048];
void rt_init_thread_entry(void *parameter)
{
rt_device_t lcd;
rt_device_t lcd;
rt_hw_led_init();
rt_hw_key_init();
rt_hw_adc_init();
rt_hw_lcd_init();
rt_hw_cpu_init();
rt_hw_key_init();
rt_hw_adc_init();
rt_hw_lcd_init();
rt_hw_cpu_init();
#ifdef RT_USING_RTGUI
extern void rtgui_system_server_init(void);
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);
/* find lcd device */
lcd = rt_device_find("lcd");
/* init rtgui system server */
rtgui_system_server_init();
/* startup rtgui */
rtgui_startup();
/* set lcd device as rtgui graphic driver */
rtgui_graphic_set_device(lcd);
/* init rtgui system server */
rtgui_system_server_init();
/* startup rtgui */
rtgui_startup();
#else
{
char buf[20] = {'\0'};
{
char buf[20] = {'\0'};
struct lcd_msg msg;
rt_device_t device;
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");
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.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;
}
{
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
}
@ -134,12 +130,12 @@ int rt_application_init(void)
{
rt_thread_t init_thread;
rt_mq_init(&mq, "mqt", &msg_pool[0], 128 - sizeof(void*), sizeof(msg_pool), RT_IPC_FLAG_FIFO);
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);
return 0;
}

View File

@ -1,11 +1,7 @@
/*
* File : board.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2009 - 2011 RT-Thread Develop Team
* Copyright (c) 2006-2021, 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
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
@ -33,13 +29,13 @@ extern const uint32_t SystemFrequency;
*/
void SysTick_Handler(void)
{
/* enter interrupt */
rt_interrupt_enter();
/* enter interrupt */
rt_interrupt_enter();
rt_tick_increase();
rt_tick_increase();
/* leave interrupt */
rt_interrupt_leave();
/* leave interrupt */
rt_interrupt_leave();
}
/**

View File

@ -1,11 +1,7 @@
/*
* File : board.h
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2009, RT-Thread Development Team
* Copyright (c) 2006-2021, 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
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes

View File

@ -1,3 +1,12 @@
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
*/
#include <rtthread.h>
#include <rthw.h>
#include "cpuusage.h"
@ -9,73 +18,73 @@
#include <rtgui/rtgui_system.h>
#endif
#define CPU_USAGE_CALC_TICK 10
#define CPU_USAGE_LOOP 100
#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;
rt_tick_t tick;
rt_uint32_t count;
volatile rt_uint32_t loop;
if (total_count == 0)
{
loop = 0;
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();
}
/* 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 ++;
}
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;
/* 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;
}
/* 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);
RT_ASSERT(major != RT_NULL);
RT_ASSERT(minor != RT_NULL);
*major = cpu_usage_major;
*minor = cpu_usage_minor;
*major = cpu_usage_major;
*minor = cpu_usage_minor;
}
void cpu_usage_init()
{
/* set idle thread hook */
rt_thread_idle_sethook(cpu_usage_idle_hook);
/* set idle thread hook */
rt_thread_idle_sethook(cpu_usage_idle_hook);
}
extern struct rt_messagequeue mq;
extern rt_thread_t info_tid;
@ -83,12 +92,12 @@ 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;
struct lcd_msg msg;
#endif
while (1)
@ -96,10 +105,10 @@ static void cpu_thread_entry(void *parameter)
#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));
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);
}
@ -110,6 +119,6 @@ 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)
if(cpu_thread != RT_NULL)
rt_thread_startup(cpu_thread);
}

View File

@ -1,17 +1,13 @@
/*
* File : cpuusage.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2011, RT-Thread Develop Team
* Copyright (c) 2006-2021, 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
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2011-03-03 lgnq
*/
#ifndef __CPUUSAGE_H__
#define __CPUUSAGE_H__

File diff suppressed because it is too large Load Diff

View File

@ -1,3 +1,12 @@
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
*/
#include <rtthread.h>
#ifdef RT_USING_RTGUI
@ -15,37 +24,37 @@ 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)
{
if (event->type == RTGUI_EVENT_PAINT)
{
struct rtgui_dc* dc;
struct rtgui_rect rect;
if (event->type == RTGUI_EVENT_PAINT)
{
struct rtgui_dc* dc;
struct rtgui_rect rect;
dc = rtgui_dc_begin_drawing(widget);
if (dc == RT_NULL)
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.y1 += 25;
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.y1 += 25;
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, RT_TRUE);
rtgui_dc_end_drawing(dc, RT_TRUE);
return RT_FALSE;
}
return RT_FALSE;
}
else if (event->type == RTGUI_EVENT_KBD)
{
struct rtgui_dc* dc;
@ -67,18 +76,18 @@ static rt_bool_t view_event_handler(struct rtgui_widget* widget, struct rtgui_ev
break;
case RTGUIK_UP:
rt_sprintf(key_str, "%s", "U");
break;
break;
default:
rt_sprintf(key_str, "%s", "S");
break;
}
dc = rtgui_dc_begin_drawing(widget);
if (dc == RT_NULL)
if (dc == RT_NULL)
return RT_FALSE;
rect.x1 = 118;
rect.y1 = 1;
rect.y1 = 1;
rect.x2 = 127;
rect.y2 = 10;
rect.y2 = 10;
rtgui_dc_fill_rect(dc, &rect);
rtgui_dc_draw_text(dc, key_str, &rect);
rtgui_dc_end_drawing(dc, RT_TRUE);
@ -86,12 +95,12 @@ static rt_bool_t view_event_handler(struct rtgui_widget* widget, struct rtgui_ev
else if (ekbd->type == RTGUI_KEYUP)
{
dc = rtgui_dc_begin_drawing(widget);
if (dc == RT_NULL)
if (dc == RT_NULL)
return RT_FALSE;
rect.x1 = 118;
rect.y1 = 1;
rect.y1 = 1;
rect.x2 = 127;
rect.y2 = 10;
rect.y2 = 10;
rtgui_dc_fill_rect(dc, &rect);
//rtgui_dc_draw_text(dc, key_str, &rect);
rtgui_dc_end_drawing(dc, RT_TRUE);
@ -105,38 +114,38 @@ static rt_bool_t view_event_handler(struct rtgui_widget* widget, struct rtgui_ev
struct rtgui_event_command* ecmd;
rt_uint8_t major,minor;
dc = rtgui_dc_begin_drawing(widget);
if (dc == RT_NULL)
if (dc == RT_NULL)
return RT_FALSE;
ecmd = (struct rtgui_event_command*)event;
switch (ecmd->command_id)
{
{
case ADC_UPDATE:
rect.x1 = 1;
rect.y1 = 1;
rect.y1 = 1;
rect.x2 = 117;
rect.y2 = 10;
rtgui_dc_fill_rect(dc, &rect);
rt_sprintf(str, "ADC = %d mv", adc_value);
rtgui_dc_draw_text(dc, str, &rect);
rect.y2 = 10;
rtgui_dc_fill_rect(dc, &rect);
rt_sprintf(str, "ADC = %d mv", adc_value);
rtgui_dc_draw_text(dc, str, &rect);
break;
case CPU_UPDATE:
cpu_usage_get(&major, &minor);
rect.x1 = 1;
rect.y1 = 12;
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.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;
rect.y1 = 23;
rect.y2 = 63;
index++;
if (index == 127)
{
{
index = 1;
rtgui_dc_fill_rect(dc, &rect);
rtgui_dc_fill_rect(dc, &rect);
}
if (major>40)
rtgui_dc_draw_vline(dc, index, rect.y1, rect.y2);
@ -144,42 +153,42 @@ static rt_bool_t view_event_handler(struct rtgui_widget* widget, struct rtgui_ev
rtgui_dc_draw_vline(dc, index, rect.y2-major, rect.y2);
break;
}
rtgui_dc_end_drawing(dc, RT_TRUE);
rtgui_dc_end_drawing(dc, RT_TRUE);
}
return rtgui_view_event_handler(widget, event);
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;
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);
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)
workbench = rtgui_workbench_create("info", "workbench");
if(workbench == RT_NULL)
return;
view = rtgui_view_create("view");
RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(view)) = white;
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_widget_set_event_handler(RTGUI_WIDGET(view), view_event_handler);
rtgui_workbench_add_view(workbench, view);
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_widget_focus(RTGUI_WIDGET(view));
rtgui_view_show(view, RT_FALSE);
rtgui_view_show(view, RT_FALSE);
rtgui_workbench_event_loop(workbench);
rtgui_workbench_event_loop(workbench);
rtgui_thread_deregister(rt_thread_self());
rt_mq_delete(mq);
rtgui_thread_deregister(rt_thread_self());
rt_mq_delete(mq);
}
rt_thread_t info_tid;
@ -195,10 +204,9 @@ void info_init()
void rtgui_startup()
{
rtgui_rect_t rect;
/* GUIϵͳ³õʼ»¯ */
rtgui_system_server_init();
/* register dock panel */
rect.x1 = 0;
rect.y1 = 0;
@ -206,9 +214,9 @@ void rtgui_startup()
rect.y2 = 64;
rtgui_panel_register("info", &rect);
rtgui_panel_set_default_focused("info");
/* Æô¶¯info workbench */
info_init();
/*init info workbench */
info_init();
}
#endif

View File

@ -1,15 +1,11 @@
/*
* File : key.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2011, RT-Thread Develop Team
* Copyright (c) 2006-2021, 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
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2011-03-03 lgnq
* 2011-03-03 lgnq
*/
#include <rtthread.h>
@ -25,7 +21,7 @@ static void key_io_init(void)
{
/*Select CPIO function*/
KEY_PFR &= ~KEY_MASK;
/*Set CPIO Pull-Up function*/
/*Set CPIO Pull-Up function*/
KEY_PCR |= KEY_MASK;
/*Make button pins inputs*/
KEY_DDR &= ~KEY_MASK;
@ -38,7 +34,7 @@ static void key_thread_entry(void *parameter)
rt_uint8_t i;
struct rtgui_event_kbd kbd_event;
key_io_init();
/* init keyboard event */
@ -109,49 +105,49 @@ static void key_thread_entry(void *parameter)
rt_thread_delay(next_delay);
}
#else
extern struct rt_messagequeue mq;
rt_time_t next_delay;
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);
}
extern struct rt_messagequeue mq;
rt_time_t next_delay;
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
}
@ -159,6 +155,6 @@ static rt_thread_t key_thread;
void rt_hw_key_init(void)
{
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);
}

View File

@ -1,11 +1,7 @@
/*
* File : key.h
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2011, RT-Thread Develop Team
* Copyright (c) 2006-2021, 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
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes

View File

@ -1,11 +1,7 @@
/*
* File : lcd.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2011, RT-Thread Develop Team
* Copyright (c) 2006-2021, 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
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
@ -59,7 +55,7 @@ void lcd_write_cmd(unsigned char command)
LCD_DATA_HIGH();
else
LCD_DATA_LOW();
LCD_CLK_LOW();
delay();
LCD_CLK_HIGH();
@ -81,7 +77,7 @@ void lcd_write_data(unsigned char data)
LCD_DATA_HIGH();
else
LCD_DATA_LOW();
LCD_CLK_LOW();
delay();
LCD_CLK_HIGH();
@ -97,12 +93,12 @@ void lcd_write_data(unsigned char data)
static void rt_hw_lcd_update(struct rt_device_rect_info *rect_info)
{
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++)
{
lcd_write_cmd(SET_PAGE_ADDR_0|i);
lcd_write_cmd(SET_COLH_ADDR_0);
{
lcd_write_cmd(SET_PAGE_ADDR_0|i);
lcd_write_cmd(SET_COLH_ADDR_0);
lcd_write_cmd(SET_COLL_ADDR_0);
j = GUI_LCM_XMAX;
while (j--)
@ -125,7 +121,7 @@ static void rt_hw_lcd_set_pixel(rtgui_color_t *c, int x, int y)
if (*c == rtgui_color_to_565(black))
gui_disp_buf[page][x] |= 1<<(y%8);
else
else
if (*c == rtgui_color_to_565(white))
gui_disp_buf[page][x] &= ~(1<<(y%8));
}
@ -134,7 +130,7 @@ static void rt_hw_lcd_get_pixel(rtgui_color_t *c, int x, int y)
{
rt_uint8_t page;
page = y/8;
if (gui_disp_buf[page][x] & (1<<(y%8)))
*c = black;
else
@ -144,16 +140,16 @@ static void rt_hw_lcd_get_pixel(rtgui_color_t *c, int x, int y)
static void rt_hw_lcd_draw_hline(rtgui_color_t *c, int x1, int x2, int y)
{
rt_uint8_t page;
rt_uint8_t i;
rt_uint8_t i;
page = y/8;
for (i=x1; i<x2; i++)
{
if (*c == rtgui_color_to_565(black))
gui_disp_buf[page][i] |= 1<<(y%8);
else
else
if (*c == rtgui_color_to_565(white))
gui_disp_buf[page][i] &= ~(1<<(y%8));
gui_disp_buf[page][i] &= ~(1<<(y%8));
}
}
@ -169,13 +165,13 @@ static void rt_hw_lcd_draw_vline(rtgui_color_t *c, int x, int y1, int y2)
static void rt_hw_lcd_draw_raw_hline(rt_uint8_t *pixels, int x1, int x2, int y)
{
rt_uint8_t coll;
rt_uint8_t colh;
rt_uint8_t page;
rt_uint8_t i;
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);
@ -213,7 +209,7 @@ void lcd_io_init()
/*Select CPIO function*/
LCD_PS_PFR &= ~LCD_PS;
/*Make pin output*/
LCD_PS_DDR |= LCD_PS;
LCD_PS_DDR |= LCD_PS;
/*Select CPIO function*/
LCD_CLK_PFR &= ~LCD_CLK;
/*Make pin output*/
@ -228,7 +224,7 @@ void lcd_io_init()
static rt_err_t rt_lcd_init (rt_device_t dev)
{
lcd_io_init();
power_delay();
lcd_write_cmd(DISPLAY_OFF);
reset_delay();
@ -239,19 +235,19 @@ static rt_err_t rt_lcd_init (rt_device_t dev)
lcd_write_cmd(SET_LCD_BIAS_9);
reset_delay();
// ADC selection: display from left to right
lcd_write_cmd(SET_ADC_NORMAL);
lcd_write_cmd(SET_ADC_NORMAL);
reset_delay();
// Common output state selection: display from up to down
lcd_write_cmd(COM_SCAN_DIR_REVERSE);
reset_delay();
lcd_write_cmd(POWER_BOOSTER_ON);
power_delay(); // 50ms requried
lcd_write_cmd(POWER_REGULATOR_ON);
power_delay(); // 50ms
lcd_write_cmd(POWER_FOLLOWER_ON);
power_delay(); // 50ms
// Setting the built-in resistance radio for regulation of the V0 voltage
// Electronic volume control
// Power control setting
@ -271,7 +267,7 @@ static rt_err_t rt_lcd_init (rt_device_t dev)
delay();
lcd_write_cmd(DISPLAY_ON);
delay();
lcd_write_cmd(DISPLAY_ALL_ON);
delay();
lcd_write_cmd(DISPLAY_OFF);
@ -280,7 +276,7 @@ static rt_err_t rt_lcd_init (rt_device_t dev)
delay();
lcd_write_cmd(DISPLAY_ALL_NORMAL);
delay();
return RT_EOK;
}
@ -291,15 +287,15 @@ static rt_err_t rt_lcd_init (rt_device_t dev)
* Output : None
* Return : None
*******************************************************************************/
void LCD_FillAll(unsigned char* buffer)
void LCD_FillAll(unsigned char* buffer)
{
unsigned char i,j = GUI_LCM_XMAX;
unsigned char* p = buffer;
unsigned char* p = buffer;
for (i=0; i<GUI_LCM_PAGE; i++)
{
lcd_write_cmd(SET_PAGE_ADDR_0|i);
lcd_write_cmd(SET_COLH_ADDR_0);
{
lcd_write_cmd(SET_PAGE_ADDR_0|i);
lcd_write_cmd(SET_COLH_ADDR_0);
lcd_write_cmd(SET_COLL_ADDR_0);
j = GUI_LCM_XMAX;
while (j--)
@ -322,8 +318,8 @@ void LCD_ClearSCR(void)
unsigned char i, j;
for(i=0; i<GUI_LCM_PAGE; i++)
{
for(j = 0; j < GUI_LCM_XMAX; j++)
{
for(j = 0; j < GUI_LCM_XMAX; j++)
gui_disp_buf[i][j] = 0;
}
LCD_FillAll((unsigned char*)gui_disp_buf);
@ -331,7 +327,7 @@ void LCD_ClearSCR(void)
/****************************************************************************
* Function Name : LCD_UpdatePoint
* Description : refresh the point in screen
* Description : refresh the point in screen
* Input : x X-coordinate
y Y-coordinate
* Output : None
@ -344,16 +340,16 @@ void LCD_UpdatePoint(unsigned int x, unsigned int y)
page = y / 8;
coll = x & 0x0f;
colh = x >> 4;
lcd_write_cmd(SET_PAGE_ADDR_0 | page); // page no.
lcd_write_cmd(SET_COLH_ADDR_0 | colh); // fixed col first addr
lcd_write_cmd(SET_PAGE_ADDR_0 | page); // page no.
lcd_write_cmd(SET_COLH_ADDR_0 | colh); // fixed col first addr
lcd_write_cmd(SET_COLL_ADDR_0 | coll);
lcd_write_data(gui_disp_buf[page][x]);
}
/****************************************************************************
* Function Name : LCD_PutChar
* Description : output a char to screen
* Description : output a char to screen
(the char only can be ' ','0'~'9','A'~'Z','a'~'z')
* Input : x X-coordinate
y Y-coordinate
@ -363,13 +359,13 @@ void LCD_UpdatePoint(unsigned int x, unsigned int y)
0 Fail
****************************************************************************/
unsigned char LCD_PutChar(unsigned long x, unsigned long y, unsigned char ch)
{
{
unsigned char data;
unsigned char i, j;
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))
@ -380,30 +376,30 @@ unsigned char LCD_PutChar(unsigned long x, unsigned long y, unsigned char ch)
ch -= 0x3C;
else
return(0);
for(i = 0; i < 8; i++)
{
{
data = FONTTYPE8_8[ch][i];
for(j = 0; j < 8; j++)
{
{
if( (data&BIT_MASK[j]) == 0)
gui_disp_buf[y / 8][x] &= (~(0x01 << ( y % 8)));
else
else
gui_disp_buf[y / 8][x] |= (0x01 <<( y % 8));
LCD_UpdatePoint(x, y);
x ++;
}
x -= 8;
y++;
x -= 8;
y++;
}
return(1);
}
/****************************************************************************
* Function Name : LCD_PutString
* Description : output string to screen
* Description : output string to screen
* Input : x X-coordinate
y Y-coordinate
str pointer to string
@ -411,32 +407,32 @@ unsigned char LCD_PutChar(unsigned long x, unsigned long y, unsigned char ch)
* 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;
x += 6;
}
}
static rt_err_t rt_lcd_control (rt_device_t dev, int cmd, void *args)
{
switch (cmd)
{
#ifdef RT_USING_RTGUI
case RTGRAPHIC_CTRL_RECT_UPDATE:
rt_hw_lcd_update(args);
break;
case RTGRAPHIC_CTRL_POWERON:
break;
case RTGRAPHIC_CTRL_POWEROFF:
break;
case RTGRAPHIC_CTRL_GET_INFO:
rt_memcpy(args, &_lcd_info, sizeof(_lcd_info));
break;
case RTGRAPHIC_CTRL_SET_MODE:
break;
switch (cmd)
{
#ifdef RT_USING_RTGUI
case RTGRAPHIC_CTRL_RECT_UPDATE:
rt_hw_lcd_update(args);
break;
case RTGRAPHIC_CTRL_POWERON:
break;
case RTGRAPHIC_CTRL_POWEROFF:
break;
case RTGRAPHIC_CTRL_GET_INFO:
rt_memcpy(args, &_lcd_info, sizeof(_lcd_info));
break;
case RTGRAPHIC_CTRL_SET_MODE:
break;
#else
case RT_DEVICE_CTRL_LCD_DISPLAY_ON:
lcd_write_cmd(DISPLAY_ON);
@ -450,32 +446,32 @@ static rt_err_t rt_lcd_control (rt_device_t dev, int cmd, void *args)
case RT_DEVICE_CTRL_LCD_CLEAR_SCR:
LCD_ClearSCR();
break;
#endif
}
#endif
}
return RT_EOK;
return RT_EOK;
}
void rt_hw_lcd_init(void)
{
rt_device_t lcd = rt_malloc(sizeof(struct rt_device));
if (lcd == RT_NULL) return; /* no memory yet */
rt_device_t lcd = rt_malloc(sizeof(struct rt_device));
if (lcd == RT_NULL) return; /* no memory yet */
_lcd_info.bits_per_pixel = 16;
_lcd_info.pixel_format = RTGRAPHIC_PIXEL_FORMAT_RGB565;
_lcd_info.framebuffer = RT_NULL;
_lcd_info.width = LCD_WIDTH;
_lcd_info.height = LCD_HEIGHT;
_lcd_info.bits_per_pixel = 16;
_lcd_info.pixel_format = RTGRAPHIC_PIXEL_FORMAT_RGB565;
_lcd_info.framebuffer = RT_NULL;
_lcd_info.width = LCD_WIDTH;
_lcd_info.height = LCD_HEIGHT;
/* init device structure */
lcd->type = RT_Device_Class_Unknown;
lcd->init = rt_lcd_init;
lcd->open = RT_NULL;
lcd->close = RT_NULL;
lcd->control = rt_lcd_control;
/* init device structure */
lcd->type = RT_Device_Class_Unknown;
lcd->init = rt_lcd_init;
lcd->open = RT_NULL;
lcd->close = RT_NULL;
lcd->control = rt_lcd_control;
#ifdef RT_USING_RTGUI
lcd->user_data = (void*)&_lcd_ops;
#endif
/* register lcd device to RT-Thread */
rt_device_register(lcd, "lcd", RT_DEVICE_FLAG_RDWR);
lcd->user_data = (void*)&_lcd_ops;
#endif
/* register lcd device to RT-Thread */
rt_device_register(lcd, "lcd", RT_DEVICE_FLAG_RDWR);
}

View File

@ -1,11 +1,7 @@
/*
* File : lcd.h
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006, RT-Thread Develop Team
* Copyright (c) 2006-2021, 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
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
@ -19,166 +15,166 @@
#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]
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_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_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_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_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)
#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
#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_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_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_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_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 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)
#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 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 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 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 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
#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 *
* 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 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
#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 *
* 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
#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 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_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 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 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 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 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
#define RT_DEVICE_CTRL_LCD_PUT_STRING 11
#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
#define RT_DEVICE_CTRL_LCD_PUT_STRING 11
enum
enum
{
ADC_MSG,
KEY_MSG,
CPU_MSG,
MAX_MSG,
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;
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;

View File

@ -1,17 +1,13 @@
/*
* File : led.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2011, RT-Thread Develop Team
* Copyright (c) 2006-2021, 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
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2011-03-03 lgnq
*/
#include <rtthread.h>
#include <rthw.h>
@ -20,8 +16,8 @@
void rt_hw_led_on(rt_uint8_t num)
{
RT_ASSERT(num < LEDS_MAX_NUMBER);
RT_ASSERT(num < LEDS_MAX_NUMBER);
switch (num)
{
case 1:
@ -31,16 +27,16 @@ void rt_hw_led_on(rt_uint8_t num)
LED_PDOR &= ~LED2;
break;
case 3:
LED_PDOR &= ~LED3;
LED_PDOR &= ~LED3;
break;
default:
break;
}
}
}
void rt_hw_led_off(rt_uint8_t num)
{
RT_ASSERT(num < LEDS_MAX_NUMBER);
RT_ASSERT(num < LEDS_MAX_NUMBER);
switch (num)
{
@ -51,17 +47,17 @@ void rt_hw_led_off(rt_uint8_t num)
LED_PDOR |= LED2;
break;
case 3:
LED_PDOR |= LED3;
LED_PDOR |= LED3;
break;
default:
break;
}
}
}
void rt_hw_led_toggle(rt_uint8_t num)
{
RT_ASSERT(num < LEDS_MAX_NUMBER);
RT_ASSERT(num < LEDS_MAX_NUMBER);
switch (num)
{
case 1:
@ -80,11 +76,11 @@ void rt_hw_led_toggle(rt_uint8_t num)
if (LED_PDOR&LED3)
LED_PDOR &= ~LED3;
else
LED_PDOR |= LED3;
LED_PDOR |= LED3;
break;
default:
break;
}
}
}
static rt_err_t led_io_init(void)
@ -95,23 +91,23 @@ static rt_err_t led_io_init(void)
LED_PDOR |= LED_MASK;
/*Make led pins outputs*/
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->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) */
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;
}
void pwm_update(rt_uint16_t value)
{
FM3_BT2_PWM->PDUT = value;
FM3_BT2_PWM->PDUT = value;
}
static void led1_thread_entry(void *parameter)
@ -139,11 +135,11 @@ void rt_hw_led_init(void)
led_io_init();
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);
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);
}

View File

@ -1,23 +1,19 @@
/*
* File : led.h
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2011, RT-Thread Develop Team
* Copyright (c) 2006-2021, 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
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2011-03-03 lgnq
*/
#ifndef __LED_H__
#define __LED_H__
#include "mb9bf506r.h"
#define LEDS_MAX_NUMBER 4
#define LEDS_MAX_NUMBER 4
/*LEDs*/
#define LED1 (1UL<<10)
@ -29,9 +25,9 @@
#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
#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);

View File

@ -3,16 +3,16 @@
#define __RTTHREAD_CFG_H__
/* RT_NAME_MAX*/
#define RT_NAME_MAX 8
#define RT_NAME_MAX 8
/* RT_ALIGN_SIZE*/
#define RT_ALIGN_SIZE 4
#define RT_ALIGN_SIZE 4
/* PRIORITY_MAX */
#define RT_THREAD_PRIORITY_MAX 32
#define RT_THREAD_PRIORITY_MAX 32
/* Tick per Second */
#define RT_TICK_PER_SECOND 100
#define RT_TICK_PER_SECOND 100
/* SECTION: RT_DEBUG */
/* Thread Debug */
@ -53,20 +53,20 @@
#define RT_USING_DEVICE
/* RT_USING_UART */
#define RT_USING_UART0
#define RT_UART_RX_BUFFER_SIZE 64
#define RT_UART_RX_BUFFER_SIZE 64
/* SECTION: Console options */
#define RT_TINY_SIZE
#define RT_USING_CONSOLE
/* the buffer size of console */
#define RT_CONSOLEBUF_SIZE 128
#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
#define RTGUI_NAME_MAX 16
/* support 16 weight font */
//#define RTGUI_USING_FONT16
/* support 12 weight font */

View File

@ -1,11 +1,7 @@
/*
* File : startup.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2009 - 2011, RT-Thread Development Team
* Copyright (c) 2006-2021, 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
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
@ -38,57 +34,57 @@ extern int __bss_end;
*/
void rtthread_startup(void)
{
/* init board */
rt_hw_board_init();
/* init board */
rt_hw_board_init();
/* show version */
rt_show_version();
/* show version */
rt_show_version();
/* init timer system */
rt_system_timer_init();
/* init timer system */
rt_system_timer_init();
#ifdef RT_USING_HEAP
#ifdef __CC_ARM
rt_system_heap_init((void*)&Image$$RW_IRAM1$$ZI$$Limit, (void*)FM3_SRAM_END);
#elif __ICCARM__
rt_system_heap_init(__segment_end("HEAP"), (void*)FM3_SRAM_END);
#else
/* init memory system */
rt_system_heap_init((void*)&__bss_end, (void*)FM3_SRAM_END);
#endif
#ifdef __CC_ARM
rt_system_heap_init((void*)&Image$$RW_IRAM1$$ZI$$Limit, (void*)FM3_SRAM_END);
#elif __ICCARM__
rt_system_heap_init(__segment_end("HEAP"), (void*)FM3_SRAM_END);
#else
/* init memory system */
rt_system_heap_init((void*)&__bss_end, (void*)FM3_SRAM_END);
#endif
#endif
/* init scheduler system */
rt_system_scheduler_init();
/* init scheduler system */
rt_system_scheduler_init();
/* init application */
rt_application_init();
/* init application */
rt_application_init();
/* init timer thread */
rt_system_timer_thread_init();
/* init idle thread */
rt_thread_idle_init();
/* init idle thread */
rt_thread_idle_init();
/* start scheduler */
rt_system_scheduler_start();
/* start scheduler */
rt_system_scheduler_start();
/* never reach here */
return ;
/* never reach here */
return ;
}
int main(void)
{
/* disable interrupt first */
rt_hw_interrupt_disable();
/* disable interrupt first */
rt_hw_interrupt_disable();
/* init system setting */
SystemInit();
/* startup RT-Thread RTOS */
rtthread_startup();
/* init system setting */
SystemInit();
return 0;
/* startup RT-Thread RTOS */
rtthread_startup();
return 0;
}
/*@}*/