提交 75405b62 编写于 作者: mysterywolf's avatar mysterywolf

[mb9bf500r] 手动-自动格式整理

上级 06118227
/* /*
* File : adc.c * Copyright (c) 2006-2021, RT-Thread Development Team
* 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 * SPDX-License-Identifier: Apache-2.0
* found in the file LICENSE in this distribution or at
* http://www.rt-thread.org/license/LICENSE
* *
* Change Logs: * Change Logs:
* Date Author Notes * Date Author Notes
* 2011-03-03 lgnq * 2011-03-03 lgnq First version
*/ */
#include <rtthread.h> #include <rtthread.h>
#include <rthw.h> #include <rthw.h>
#include "mb9bf506r.h" #include "mb9bf506r.h"
...@@ -33,45 +29,45 @@ static rt_err_t rt_adc_init(rt_device_t dev) ...@@ -33,45 +29,45 @@ static rt_err_t rt_adc_init(rt_device_t dev)
if(!(dev->flag & RT_DEVICE_FLAG_ACTIVATED)) if(!(dev->flag & RT_DEVICE_FLAG_ACTIVATED))
{ {
/* I/O setting AN08 - P18 */ /* I/O setting AN08 - P18 */
FM3_GPIO->ADE |= 0x100; FM3_GPIO->ADE |= 0x100;
FM3_GPIO->PFR1 = 0x100; FM3_GPIO->PFR1 = 0x100;
/* A/DC setting */ /* A/DC setting */
FM3_ADC0->SCIS1 = 0x01; FM3_ADC0->SCIS1 = 0x01;
FM3_ADC0->ADSS1 = 0x00; /* sampling timming ADST0 */ FM3_ADC0->ADSS1 = 0x00; /* sampling timming ADST0 */
FM3_ADC0->ADST1 = 0x43; FM3_ADC0->ADST1 = 0x43;
FM3_ADC0->ADCT = 0x02; FM3_ADC0->ADCT = 0x02;
FM3_ADC0->SCCR = 0x10; /* FIFO clear,single mode */ FM3_ADC0->SCCR = 0x10; /* FIFO clear,single mode */
FM3_ADC0->CMPCR = 0x00; /* disable comparator */ FM3_ADC0->CMPCR = 0x00; /* disable comparator */
/* starting A/DC */ /* starting A/DC */
FM3_ADC0->SCCR |= 0x01; /* A/DC start */ FM3_ADC0->SCCR |= 0x01; /* A/DC start */
dev->flag |= RT_DEVICE_FLAG_ACTIVATED; 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) 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) switch (cmd)
{ {
case RT_DEVICE_CTRL_ADC_START: case RT_DEVICE_CTRL_ADC_START:
FM3_ADC0->SCCR |= 0x1; FM3_ADC0->SCCR |= 0x1;
break; break;
case RT_DEVICE_CTRL_ADC_RESULT: case RT_DEVICE_CTRL_ADC_RESULT:
while(FM3_ADC0->ADSR & 0x1) while(FM3_ADC0->ADSR & 0x1)
; ;
*((rt_uint16_t*)args) = FM3_ADC0->SCFD; *((rt_uint16_t*)args) = FM3_ADC0->SCFD;
*((rt_uint16_t*)args) = *((rt_uint16_t*)args) >> 6; *((rt_uint16_t*)args) = *((rt_uint16_t*)args) >> 6;
*((rt_uint16_t*)args) = (*((rt_uint16_t*)args)*3300)/1024; *((rt_uint16_t*)args) = (*((rt_uint16_t*)args)*3300)/1024;
break; break;
} }
return RT_EOK; return RT_EOK;
} }
extern struct rt_messagequeue mq; extern struct rt_messagequeue mq;
...@@ -80,29 +76,29 @@ rt_uint16_t adc_value; ...@@ -80,29 +76,29 @@ rt_uint16_t adc_value;
static void adc_thread_entry(void *parameter) static void adc_thread_entry(void *parameter)
{ {
rt_device_t device; rt_device_t device;
#ifdef RT_USING_RTGUI #ifdef RT_USING_RTGUI
struct rtgui_event_command ecmd; struct rtgui_event_command ecmd;
RTGUI_EVENT_COMMAND_INIT(&ecmd); RTGUI_EVENT_COMMAND_INIT(&ecmd);
ecmd.type = RTGUI_CMD_USER_INT; ecmd.type = RTGUI_CMD_USER_INT;
ecmd.command_id = ADC_UPDATE; ecmd.command_id = ADC_UPDATE;
#else #else
struct lcd_msg msg; struct lcd_msg msg;
#endif #endif
device = rt_device_find("adc"); device = rt_device_find("adc");
while(1) 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); rt_device_control(device, RT_DEVICE_CTRL_ADC_RESULT, &adc_value);
pwm_update(adc_value/3); pwm_update(adc_value/3);
#ifdef RT_USING_RTGUI #ifdef RT_USING_RTGUI
rtgui_thread_send(info_tid, &ecmd.parent, sizeof(ecmd)); rtgui_thread_send(info_tid, &ecmd.parent, sizeof(ecmd));
#else #else
msg.type = ADC_MSG; msg.type = ADC_MSG;
msg.adc_value = adc_value; msg.adc_value = adc_value;
rt_mq_send(&mq, &msg, sizeof(msg)); rt_mq_send(&mq, &msg, sizeof(msg));
#endif #endif
rt_thread_delay(20); rt_thread_delay(20);
...@@ -112,22 +108,22 @@ static void adc_thread_entry(void *parameter) ...@@ -112,22 +108,22 @@ static void adc_thread_entry(void *parameter)
static rt_thread_t adc_thread; static rt_thread_t adc_thread;
void rt_hw_adc_init(void) void rt_hw_adc_init(void)
{ {
adc.type = RT_Device_Class_Char; adc.type = RT_Device_Class_Char;
adc.rx_indicate = RT_NULL; adc.rx_indicate = RT_NULL;
adc.tx_complete = RT_NULL; adc.tx_complete = RT_NULL;
adc.init = rt_adc_init; adc.init = rt_adc_init;
adc.open = RT_NULL; adc.open = RT_NULL;
adc.close = RT_NULL; adc.close = RT_NULL;
adc.read = RT_NULL; adc.read = RT_NULL;
adc.write = RT_NULL; adc.write = RT_NULL;
adc.control = rt_adc_control; adc.control = rt_adc_control;
adc.user_data = RT_NULL; adc.user_data = RT_NULL;
adc_thread = rt_thread_create("adc", adc_thread_entry, RT_NULL, 384, 26, 5); adc_thread = rt_thread_create("adc", adc_thread_entry, RT_NULL, 384, 26, 5);
if(adc_thread != RT_NULL) if(adc_thread != RT_NULL)
rt_thread_startup(adc_thread); rt_thread_startup(adc_thread);
/* register a character device */ /* register a character device */
rt_device_register(&adc, "adc", RT_DEVICE_FLAG_RDWR); rt_device_register(&adc, "adc", RT_DEVICE_FLAG_RDWR);
} }
/* /*
* File : adc.c * Copyright (c) 2006-2021, RT-Thread Development Team
* 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 * SPDX-License-Identifier: Apache-2.0
* found in the file LICENSE in this distribution or at
* http://www.rt-thread.org/license/LICENSE
* *
* Change Logs: * Change Logs:
* Date Author Notes * Date Author Notes
* 2011-03-03 lgnq * 2011-03-03 lgnq
*/ */
#ifndef __ADC_H__ #ifndef __ADC_H__
#define __ADC_H__ #define __ADC_H__
/* Exported constants ---------------------------------------------------------*/ /* Exported constants ---------------------------------------------------------*/
/* Exported macro -------------------------------------------------------------*/ /* Exported macro -------------------------------------------------------------*/
#define ADC_MODE_SINGLE 0x00UL #define ADC_MODE_SINGLE 0x00UL
#define ADC_MODE_SCAN 0x01UL #define ADC_MODE_SCAN 0x01UL
#define ADC_MODE_TAILGATE 0x02UL #define ADC_MODE_TAILGATE 0x02UL
#define RT_DEVICE_CTRL_ADC_START 0xF1 /* start ADC conversion */ #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 #define ADC_UPDATE 0
......
/* /*
* File : application.c * Copyright (c) 2006-2021, RT-Thread Development Team
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2009 - 2012, RT-Thread Development Team
* *
* The license and distribution terms for this file may be * SPDX-License-Identifier: Apache-2.0
* found in the file LICENSE in this distribution or at
* http://www.rt-thread.org/license/LICENSE
* *
* Change Logs: * Change Logs:
* Date Author Notes * Date Author Notes
...@@ -15,7 +11,7 @@ ...@@ -15,7 +11,7 @@
/** /**
* @addtogroup FM3 * @addtogroup FM3
*/ */
/*@{*/ /*@{*/
#include <rtthread.h> #include <rtthread.h>
...@@ -37,96 +33,96 @@ static char msg_pool[2048]; ...@@ -37,96 +33,96 @@ static char msg_pool[2048];
void rt_init_thread_entry(void *parameter) void rt_init_thread_entry(void *parameter)
{ {
rt_device_t lcd; rt_device_t lcd;
rt_hw_led_init(); rt_hw_led_init();
rt_hw_key_init(); rt_hw_key_init();
rt_hw_adc_init(); rt_hw_adc_init();
rt_hw_lcd_init(); rt_hw_lcd_init();
rt_hw_cpu_init(); rt_hw_cpu_init();
#ifdef RT_USING_RTGUI #ifdef RT_USING_RTGUI
extern void rtgui_system_server_init(void); extern void rtgui_system_server_init(void);
/* find lcd device */ /* find lcd device */
lcd = rt_device_find("lcd"); lcd = rt_device_find("lcd");
/* set lcd device as rtgui graphic driver */ /* set lcd device as rtgui graphic driver */
rtgui_graphic_set_device(lcd); rtgui_graphic_set_device(lcd);
/* init rtgui system server */ /* init rtgui system server */
rtgui_system_server_init(); rtgui_system_server_init();
/* startup rtgui */ /* startup rtgui */
rtgui_startup(); rtgui_startup();
#else #else
{ {
char buf[20] = {'\0'}; char buf[20] = {'\0'};
struct lcd_msg msg; struct lcd_msg msg;
rt_device_t device; rt_device_t device;
device = rt_device_find("lcd"); device = rt_device_find("lcd");
rt_device_control(device, RT_DEVICE_CTRL_LCD_CLEAR_SCR, RT_NULL); rt_device_control(device, RT_DEVICE_CTRL_LCD_CLEAR_SCR, RT_NULL);
x = 1; x = 1;
y = 1; y = 1;
rt_device_control(device, RT_DEVICE_CTRL_LCD_PUT_STRING, "ADC"); rt_device_control(device, RT_DEVICE_CTRL_LCD_PUT_STRING, "ADC");
x = 1; x = 1;
y = 20; y = 20;
rt_device_control(device, RT_DEVICE_CTRL_LCD_PUT_STRING, "CPU"); rt_device_control(device, RT_DEVICE_CTRL_LCD_PUT_STRING, "CPU");
x = 1; x = 1;
y = 40; y = 40;
rt_device_control(device, RT_DEVICE_CTRL_LCD_PUT_STRING, "KEY"); rt_device_control(device, RT_DEVICE_CTRL_LCD_PUT_STRING, "KEY");
while(1) while(1)
{ {
if (rt_mq_recv(&mq, &msg, sizeof(msg), RT_WAITING_FOREVER) == RT_EOK) if (rt_mq_recv(&mq, &msg, sizeof(msg), RT_WAITING_FOREVER) == RT_EOK)
{ {
switch(msg.type) switch(msg.type)
{ {
case ADC_MSG: case ADC_MSG:
x = 40; x = 40;
y = 1; y = 1;
rt_memset(buf, 0, sizeof(buf)); rt_memset(buf, 0, sizeof(buf));
rt_sprintf(buf, "%04d", msg.adc_value); rt_sprintf(buf, "%04d", msg.adc_value);
rt_device_control(device, RT_DEVICE_CTRL_LCD_PUT_STRING, buf); rt_device_control(device, RT_DEVICE_CTRL_LCD_PUT_STRING, buf);
break; break;
case CPU_MSG: case CPU_MSG:
x = 40; x = 40;
y = 20; y = 20;
rt_memset(buf, 0, sizeof(buf)); rt_memset(buf, 0, sizeof(buf));
rt_sprintf(buf, "%03d %03d", msg.major, msg.minor); rt_sprintf(buf, "%03d %03d", msg.major, msg.minor);
rt_device_control(device, RT_DEVICE_CTRL_LCD_PUT_STRING, buf); rt_device_control(device, RT_DEVICE_CTRL_LCD_PUT_STRING, buf);
break; break;
case KEY_MSG: case KEY_MSG:
x = 40; x = 40;
y = 40; y = 40;
rt_memset(buf, 0, sizeof(buf)); rt_memset(buf, 0, sizeof(buf));
switch(msg.key) switch(msg.key)
{ {
case KEY_DOWN: case KEY_DOWN:
rt_sprintf(buf, "DOWN KEY "); rt_sprintf(buf, "DOWN KEY ");
break; break;
case KEY_UP: case KEY_UP:
rt_sprintf(buf, "UP KEY "); rt_sprintf(buf, "UP KEY ");
break; break;
case KEY_RIGHT: case KEY_RIGHT:
rt_sprintf(buf, "RIGHT KEY"); rt_sprintf(buf, "RIGHT KEY");
break; break;
case KEY_LEFT: case KEY_LEFT:
rt_sprintf(buf, "LEFT KEY "); rt_sprintf(buf, "LEFT KEY ");
break; break;
case KEY_ENTER: case KEY_ENTER:
rt_sprintf(buf, "ENTER KEY"); rt_sprintf(buf, "ENTER KEY");
break; break;
default: default:
rt_sprintf(buf, "NO KEY "); rt_sprintf(buf, "NO KEY ");
break; break;
} }
rt_device_control(device, RT_DEVICE_CTRL_LCD_PUT_STRING, buf); rt_device_control(device, RT_DEVICE_CTRL_LCD_PUT_STRING, buf);
break; break;
} }
} }
} }
} }
#endif #endif
} }
...@@ -134,12 +130,12 @@ int rt_application_init(void) ...@@ -134,12 +130,12 @@ int rt_application_init(void)
{ {
rt_thread_t init_thread; 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); init_thread = rt_thread_create("init", rt_init_thread_entry, RT_NULL, 1024, 21, 20);
if(init_thread != RT_NULL) if(init_thread != RT_NULL)
rt_thread_startup(init_thread); rt_thread_startup(init_thread);
return 0; return 0;
} }
......
/* /*
* File : board.c * Copyright (c) 2006-2021, RT-Thread Development Team
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2009 - 2011 RT-Thread Develop Team
* *
* The license and distribution terms for this file may be * SPDX-License-Identifier: Apache-2.0
* found in the file LICENSE in this distribution or at
* http://www.rt-thread.org/license/LICENSE
* *
* Change Logs: * Change Logs:
* Date Author Notes * Date Author Notes
...@@ -33,13 +29,13 @@ extern const uint32_t SystemFrequency; ...@@ -33,13 +29,13 @@ extern const uint32_t SystemFrequency;
*/ */
void SysTick_Handler(void) void SysTick_Handler(void)
{ {
/* enter interrupt */ /* enter interrupt */
rt_interrupt_enter(); rt_interrupt_enter();
rt_tick_increase(); rt_tick_increase();
/* leave interrupt */ /* leave interrupt */
rt_interrupt_leave(); rt_interrupt_leave();
} }
/** /**
......
/* /*
* File : board.h * Copyright (c) 2006-2021, RT-Thread Development Team
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2009, RT-Thread Development Team
* *
* The license and distribution terms for this file may be * SPDX-License-Identifier: Apache-2.0
* found in the file LICENSE in this distribution or at
* http://www.rt-thread.org/license/LICENSE
* *
* Change Logs: * Change Logs:
* Date Author Notes * Date Author Notes
......
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
*/
#include <rtthread.h> #include <rtthread.h>
#include <rthw.h> #include <rthw.h>
#include "cpuusage.h" #include "cpuusage.h"
...@@ -9,73 +18,73 @@ ...@@ -9,73 +18,73 @@
#include <rtgui/rtgui_system.h> #include <rtgui/rtgui_system.h>
#endif #endif
#define CPU_USAGE_CALC_TICK 10 #define CPU_USAGE_CALC_TICK 10
#define CPU_USAGE_LOOP 100 #define CPU_USAGE_LOOP 100
static rt_uint8_t cpu_usage_major = 0, cpu_usage_minor= 0; static rt_uint8_t cpu_usage_major = 0, cpu_usage_minor= 0;
static rt_uint32_t total_count = 0; static rt_uint32_t total_count = 0;
static void cpu_usage_idle_hook() static void cpu_usage_idle_hook()
{ {
rt_tick_t tick; rt_tick_t tick;
rt_uint32_t count; rt_uint32_t count;
volatile rt_uint32_t loop; volatile rt_uint32_t loop;
if (total_count == 0) if (total_count == 0)
{ {
loop = 0; loop = 0;
/* get total count */ /* get total count */
rt_enter_critical(); rt_enter_critical();
tick = rt_tick_get(); tick = rt_tick_get();
while(rt_tick_get() - tick < CPU_USAGE_CALC_TICK) while(rt_tick_get() - tick < CPU_USAGE_CALC_TICK)
{ {
total_count ++; total_count ++;
while (loop < CPU_USAGE_LOOP) loop ++; while (loop < CPU_USAGE_LOOP) loop ++;
} }
rt_exit_critical(); rt_exit_critical();
} }
count = 0; count = 0;
loop = 0; loop = 0;
/* get CPU usage */ /* get CPU usage */
tick = rt_tick_get(); tick = rt_tick_get();
while (rt_tick_get() - tick < CPU_USAGE_CALC_TICK) while (rt_tick_get() - tick < CPU_USAGE_CALC_TICK)
{ {
count ++; count ++;
while (loop < CPU_USAGE_LOOP) loop ++; while (loop < CPU_USAGE_LOOP) loop ++;
} }
/* calculate major and minor */ /* calculate major and minor */
if (count < total_count) if (count < total_count)
{ {
count = total_count - count; count = total_count - count;
cpu_usage_major = (count * 100) / total_count; cpu_usage_major = (count * 100) / total_count;
cpu_usage_minor = ((count * 100) % total_count) * 100 / total_count; cpu_usage_minor = ((count * 100) % total_count) * 100 / total_count;
} }
else else
{ {
total_count = count; total_count = count;
/* no CPU usage */ /* no CPU usage */
cpu_usage_major = 0; cpu_usage_major = 0;
cpu_usage_minor = 0; cpu_usage_minor = 0;
} }
} }
void cpu_usage_get(rt_uint8_t *major, rt_uint8_t *minor) void cpu_usage_get(rt_uint8_t *major, rt_uint8_t *minor)
{ {
RT_ASSERT(major != RT_NULL); RT_ASSERT(major != RT_NULL);
RT_ASSERT(minor != RT_NULL); RT_ASSERT(minor != RT_NULL);
*major = cpu_usage_major; *major = cpu_usage_major;
*minor = cpu_usage_minor; *minor = cpu_usage_minor;
} }
void cpu_usage_init() void cpu_usage_init()
{ {
/* set idle thread hook */ /* set idle thread hook */
rt_thread_idle_sethook(cpu_usage_idle_hook); rt_thread_idle_sethook(cpu_usage_idle_hook);
} }
extern struct rt_messagequeue mq; extern struct rt_messagequeue mq;
extern rt_thread_t info_tid; extern rt_thread_t info_tid;
...@@ -83,12 +92,12 @@ static void cpu_thread_entry(void *parameter) ...@@ -83,12 +92,12 @@ static void cpu_thread_entry(void *parameter)
{ {
#ifdef RT_USING_RTGUI #ifdef RT_USING_RTGUI
struct rtgui_event_command ecmd; struct rtgui_event_command ecmd;
RTGUI_EVENT_COMMAND_INIT(&ecmd); RTGUI_EVENT_COMMAND_INIT(&ecmd);
ecmd.type = RTGUI_CMD_USER_INT; ecmd.type = RTGUI_CMD_USER_INT;
ecmd.command_id = CPU_UPDATE; ecmd.command_id = CPU_UPDATE;
#else #else
struct lcd_msg msg; struct lcd_msg msg;
#endif #endif
while (1) while (1)
...@@ -96,10 +105,10 @@ static void cpu_thread_entry(void *parameter) ...@@ -96,10 +105,10 @@ static void cpu_thread_entry(void *parameter)
#ifdef RT_USING_RTGUI #ifdef RT_USING_RTGUI
rtgui_thread_send(info_tid, &ecmd.parent, sizeof(ecmd)); rtgui_thread_send(info_tid, &ecmd.parent, sizeof(ecmd));
#else #else
msg.type = CPU_MSG; msg.type = CPU_MSG;
msg.major = cpu_usage_major; msg.major = cpu_usage_major;
msg.minor = cpu_usage_minor; msg.minor = cpu_usage_minor;
rt_mq_send(&mq, &msg, sizeof(msg)); rt_mq_send(&mq, &msg, sizeof(msg));
#endif #endif
rt_thread_delay(20); rt_thread_delay(20);
} }
...@@ -110,6 +119,6 @@ void rt_hw_cpu_init(void) ...@@ -110,6 +119,6 @@ void rt_hw_cpu_init(void)
{ {
cpu_usage_init(); cpu_usage_init();
cpu_thread = rt_thread_create("cpu", cpu_thread_entry, RT_NULL, 384, 27, 5); 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); rt_thread_startup(cpu_thread);
} }
/* /*
* File : cpuusage.c * Copyright (c) 2006-2021, RT-Thread Development Team
* 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 * SPDX-License-Identifier: Apache-2.0
* found in the file LICENSE in this distribution or at
* http://www.rt-thread.org/license/LICENSE
* *
* Change Logs: * Change Logs:
* Date Author Notes * Date Author Notes
* 2011-03-03 lgnq * 2011-03-03 lgnq
*/ */
#ifndef __CPUUSAGE_H__ #ifndef __CPUUSAGE_H__
#define __CPUUSAGE_H__ #define __CPUUSAGE_H__
......
此差异已折叠。
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
*/
#include <rtthread.h> #include <rtthread.h>
#ifdef RT_USING_RTGUI #ifdef RT_USING_RTGUI
...@@ -15,37 +24,37 @@ extern rt_uint16_t adc_value; ...@@ -15,37 +24,37 @@ extern rt_uint16_t adc_value;
static rt_uint8_t index = 0 ; static rt_uint8_t index = 0 ;
static rt_bool_t view_event_handler(struct rtgui_widget* widget, struct rtgui_event* event) static rt_bool_t view_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
{ {
if (event->type == RTGUI_EVENT_PAINT) if (event->type == RTGUI_EVENT_PAINT)
{ {
struct rtgui_dc* dc; struct rtgui_dc* dc;
struct rtgui_rect rect; struct rtgui_rect rect;
dc = rtgui_dc_begin_drawing(widget); dc = rtgui_dc_begin_drawing(widget);
if (dc == RT_NULL) if (dc == RT_NULL)
return RT_FALSE; return RT_FALSE;
rtgui_widget_get_rect(widget, &rect); rtgui_widget_get_rect(widget, &rect);
rtgui_dc_fill_rect(dc, &rect); rtgui_dc_fill_rect(dc, &rect);
rect.x2 -= 1; rect.y2 -= 1; rect.x2 -= 1; rect.y2 -= 1;
rtgui_dc_draw_hline(dc, rect.x1, rect.x2, rect.y1); 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_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);
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 */ /* shrink border */
rtgui_rect_inflate(&rect, -1); rtgui_rect_inflate(&rect, -1);
/* draw text */ /* draw text */
rtgui_widget_get_rect(widget, &rect); rtgui_widget_get_rect(widget, &rect);
rect.y1 += 25; rect.y1 += 25;
rtgui_dc_draw_text(dc, " FM3 Easy Kit Demo", &rect); rtgui_dc_draw_text(dc, " FM3 Easy Kit Demo", &rect);
rect.y1 += 10; rect.y1 += 10;
rtgui_dc_draw_text(dc, " rt-thread / RTGUI", &rect); rtgui_dc_draw_text(dc, " rt-thread / RTGUI", &rect);
rtgui_dc_end_drawing(dc, RT_TRUE); rtgui_dc_end_drawing(dc, RT_TRUE);
return RT_FALSE; return RT_FALSE;
} }
else if (event->type == RTGUI_EVENT_KBD) else if (event->type == RTGUI_EVENT_KBD)
{ {
struct rtgui_dc* dc; struct rtgui_dc* dc;
...@@ -67,18 +76,18 @@ static rt_bool_t view_event_handler(struct rtgui_widget* widget, struct rtgui_ev ...@@ -67,18 +76,18 @@ static rt_bool_t view_event_handler(struct rtgui_widget* widget, struct rtgui_ev
break; break;
case RTGUIK_UP: case RTGUIK_UP:
rt_sprintf(key_str, "%s", "U"); rt_sprintf(key_str, "%s", "U");
break; break;
default: default:
rt_sprintf(key_str, "%s", "S"); rt_sprintf(key_str, "%s", "S");
break; break;
} }
dc = rtgui_dc_begin_drawing(widget); dc = rtgui_dc_begin_drawing(widget);
if (dc == RT_NULL) if (dc == RT_NULL)
return RT_FALSE; return RT_FALSE;
rect.x1 = 118; rect.x1 = 118;
rect.y1 = 1; rect.y1 = 1;
rect.x2 = 127; rect.x2 = 127;
rect.y2 = 10; rect.y2 = 10;
rtgui_dc_fill_rect(dc, &rect); rtgui_dc_fill_rect(dc, &rect);
rtgui_dc_draw_text(dc, key_str, &rect); rtgui_dc_draw_text(dc, key_str, &rect);
rtgui_dc_end_drawing(dc, RT_TRUE); 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 ...@@ -86,12 +95,12 @@ static rt_bool_t view_event_handler(struct rtgui_widget* widget, struct rtgui_ev
else if (ekbd->type == RTGUI_KEYUP) else if (ekbd->type == RTGUI_KEYUP)
{ {
dc = rtgui_dc_begin_drawing(widget); dc = rtgui_dc_begin_drawing(widget);
if (dc == RT_NULL) if (dc == RT_NULL)
return RT_FALSE; return RT_FALSE;
rect.x1 = 118; rect.x1 = 118;
rect.y1 = 1; rect.y1 = 1;
rect.x2 = 127; rect.x2 = 127;
rect.y2 = 10; rect.y2 = 10;
rtgui_dc_fill_rect(dc, &rect); rtgui_dc_fill_rect(dc, &rect);
//rtgui_dc_draw_text(dc, key_str, &rect); //rtgui_dc_draw_text(dc, key_str, &rect);
rtgui_dc_end_drawing(dc, RT_TRUE); 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 ...@@ -105,38 +114,38 @@ static rt_bool_t view_event_handler(struct rtgui_widget* widget, struct rtgui_ev
struct rtgui_event_command* ecmd; struct rtgui_event_command* ecmd;
rt_uint8_t major,minor; rt_uint8_t major,minor;
dc = rtgui_dc_begin_drawing(widget); dc = rtgui_dc_begin_drawing(widget);
if (dc == RT_NULL) if (dc == RT_NULL)
return RT_FALSE; return RT_FALSE;
ecmd = (struct rtgui_event_command*)event; ecmd = (struct rtgui_event_command*)event;
switch (ecmd->command_id) switch (ecmd->command_id)
{ {
case ADC_UPDATE: case ADC_UPDATE:
rect.x1 = 1; rect.x1 = 1;
rect.y1 = 1; rect.y1 = 1;
rect.x2 = 117; rect.x2 = 117;
rect.y2 = 10; rect.y2 = 10;
rtgui_dc_fill_rect(dc, &rect); rtgui_dc_fill_rect(dc, &rect);
rt_sprintf(str, "ADC = %d mv", adc_value); rt_sprintf(str, "ADC = %d mv", adc_value);
rtgui_dc_draw_text(dc, str, &rect); rtgui_dc_draw_text(dc, str, &rect);
break; break;
case CPU_UPDATE: case CPU_UPDATE:
cpu_usage_get(&major, &minor); cpu_usage_get(&major, &minor);
rect.x1 = 1; rect.x1 = 1;
rect.y1 = 12; rect.y1 = 12;
rect.x2 = 127; rect.x2 = 127;
rect.y2 = 22; rect.y2 = 22;
rtgui_dc_fill_rect(dc, &rect); rtgui_dc_fill_rect(dc, &rect);
rt_sprintf(str, "CPU : %d.%d%", major, minor); rt_sprintf(str, "CPU : %d.%d%", major, minor);
rtgui_dc_draw_text(dc, str, &rect); rtgui_dc_draw_text(dc, str, &rect);
rect.y1 = 23; rect.y1 = 23;
rect.y2 = 63; rect.y2 = 63;
index++; index++;
if (index == 127) if (index == 127)
{ {
index = 1; index = 1;
rtgui_dc_fill_rect(dc, &rect); rtgui_dc_fill_rect(dc, &rect);
} }
if (major>40) if (major>40)
rtgui_dc_draw_vline(dc, index, rect.y1, rect.y2); 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 ...@@ -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); rtgui_dc_draw_vline(dc, index, rect.y2-major, rect.y2);
break; 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) static void info_entry(void* parameter)
{ {
rt_mq_t mq; rt_mq_t mq;
struct rtgui_view* view; struct rtgui_view* view;
struct rtgui_workbench* workbench; struct rtgui_workbench* workbench;
mq = rt_mq_create("qInfo", 256, 4, RT_IPC_FLAG_FIFO); mq = rt_mq_create("qInfo", 256, 4, RT_IPC_FLAG_FIFO);
rtgui_thread_register(rt_thread_self(), mq); rtgui_thread_register(rt_thread_self(), mq);
workbench = rtgui_workbench_create("info", "workbench"); workbench = rtgui_workbench_create("info", "workbench");
if(workbench == RT_NULL) if(workbench == RT_NULL)
return; return;
view = rtgui_view_create("view"); view = rtgui_view_create("view");
RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(view)) = white; RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(view)) = white;
RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(view)) = black; 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 */ /* this view can be focused */
RTGUI_WIDGET(view)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE; RTGUI_WIDGET(view)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
/* set widget focus */ /* 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()); rtgui_thread_deregister(rt_thread_self());
rt_mq_delete(mq); rt_mq_delete(mq);
} }
rt_thread_t info_tid; rt_thread_t info_tid;
...@@ -195,10 +204,10 @@ void info_init() ...@@ -195,10 +204,10 @@ void info_init()
void rtgui_startup() void rtgui_startup()
{ {
rtgui_rect_t rect; rtgui_rect_t rect;
/* GUIϵͳʼ */ /* GUIϵͳ��ʼ�� */
rtgui_system_server_init(); rtgui_system_server_init();
/* register dock panel */ /* register dock panel */
rect.x1 = 0; rect.x1 = 0;
rect.y1 = 0; rect.y1 = 0;
...@@ -206,9 +215,9 @@ void rtgui_startup() ...@@ -206,9 +215,9 @@ void rtgui_startup()
rect.y2 = 64; rect.y2 = 64;
rtgui_panel_register("info", &rect); rtgui_panel_register("info", &rect);
rtgui_panel_set_default_focused("info"); rtgui_panel_set_default_focused("info");
/* info workbench */ /* ����info workbench */
info_init(); info_init();
} }
#endif #endif
/* /*
* File : key.c * Copyright (c) 2006-2021, RT-Thread Development Team
* 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 * SPDX-License-Identifier: Apache-2.0
* found in the file LICENSE in this distribution or at
* http://www.rt-thread.org/license/LICENSE
* *
* Change Logs: * Change Logs:
* Date Author Notes * Date Author Notes
* 2011-03-03 lgnq * 2011-03-03 lgnq
*/ */
#include <rtthread.h> #include <rtthread.h>
...@@ -25,7 +21,7 @@ static void key_io_init(void) ...@@ -25,7 +21,7 @@ static void key_io_init(void)
{ {
/*Select CPIO function*/ /*Select CPIO function*/
KEY_PFR &= ~KEY_MASK; KEY_PFR &= ~KEY_MASK;
/*Set CPIO Pull-Up function*/ /*Set CPIO Pull-Up function*/
KEY_PCR |= KEY_MASK; KEY_PCR |= KEY_MASK;
/*Make button pins inputs*/ /*Make button pins inputs*/
KEY_DDR &= ~KEY_MASK; KEY_DDR &= ~KEY_MASK;
...@@ -38,7 +34,7 @@ static void key_thread_entry(void *parameter) ...@@ -38,7 +34,7 @@ static void key_thread_entry(void *parameter)
rt_uint8_t i; rt_uint8_t i;
struct rtgui_event_kbd kbd_event; struct rtgui_event_kbd kbd_event;
key_io_init(); key_io_init();
/* init keyboard event */ /* init keyboard event */
...@@ -109,49 +105,49 @@ static void key_thread_entry(void *parameter) ...@@ -109,49 +105,49 @@ static void key_thread_entry(void *parameter)
rt_thread_delay(next_delay); rt_thread_delay(next_delay);
} }
#else #else
extern struct rt_messagequeue mq; extern struct rt_messagequeue mq;
rt_time_t next_delay; rt_time_t next_delay;
struct lcd_msg msg; struct lcd_msg msg;
msg.type = KEY_MSG; msg.type = KEY_MSG;
key_io_init(); key_io_init();
while (1) while (1)
{ {
msg.key = NO_KEY; msg.key = NO_KEY;
next_delay = RT_TICK_PER_SECOND/10; next_delay = RT_TICK_PER_SECOND/10;
if (KEY_ENTER_GETVALUE() == 0 ) if (KEY_ENTER_GETVALUE() == 0 )
{ {
msg.key = KEY_ENTER; msg.key = KEY_ENTER;
} }
if (KEY_DOWN_GETVALUE() == 0) if (KEY_DOWN_GETVALUE() == 0)
{ {
msg.key = KEY_DOWN; msg.key = KEY_DOWN;
} }
if (KEY_UP_GETVALUE() == 0) if (KEY_UP_GETVALUE() == 0)
{ {
msg.key = KEY_UP; msg.key = KEY_UP;
} }
if (KEY_RIGHT_GETVALUE() == 0) if (KEY_RIGHT_GETVALUE() == 0)
{ {
msg.key = KEY_RIGHT; msg.key = KEY_RIGHT;
} }
if (KEY_LEFT_GETVALUE() == 0) if (KEY_LEFT_GETVALUE() == 0)
{ {
msg.key = KEY_LEFT; msg.key = KEY_LEFT;
} }
rt_mq_send(&mq, &msg, sizeof(msg)); rt_mq_send(&mq, &msg, sizeof(msg));
/* wait next key press */ /* wait next key press */
rt_thread_delay(next_delay); rt_thread_delay(next_delay);
} }
#endif #endif
} }
...@@ -159,6 +155,6 @@ static rt_thread_t key_thread; ...@@ -159,6 +155,6 @@ static rt_thread_t key_thread;
void rt_hw_key_init(void) void rt_hw_key_init(void)
{ {
key_thread = rt_thread_create("key", key_thread_entry, RT_NULL, 384, 28, 5); key_thread = rt_thread_create("key", key_thread_entry, RT_NULL, 384, 28, 5);
if (key_thread != RT_NULL) if (key_thread != RT_NULL)
rt_thread_startup(key_thread); rt_thread_startup(key_thread);
} }
/* /*
* File : key.h * Copyright (c) 2006-2021, RT-Thread Development Team
* 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 * SPDX-License-Identifier: Apache-2.0
* found in the file LICENSE in this distribution or at
* http://www.rt-thread.org/license/LICENSE
* *
* Change Logs: * Change Logs:
* Date Author Notes * Date Author Notes
......
/* /*
* File : lcd.c * Copyright (c) 2006-2021, RT-Thread Development Team
* 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 * SPDX-License-Identifier: Apache-2.0
* found in the file LICENSE in this distribution or at
* http://www.rt-thread.org/license/LICENSE
* *
* Change Logs: * Change Logs:
* Date Author Notes * Date Author Notes
...@@ -59,7 +55,7 @@ void lcd_write_cmd(unsigned char command) ...@@ -59,7 +55,7 @@ void lcd_write_cmd(unsigned char command)
LCD_DATA_HIGH(); LCD_DATA_HIGH();
else else
LCD_DATA_LOW(); LCD_DATA_LOW();
LCD_CLK_LOW(); LCD_CLK_LOW();
delay(); delay();
LCD_CLK_HIGH(); LCD_CLK_HIGH();
...@@ -81,7 +77,7 @@ void lcd_write_data(unsigned char data) ...@@ -81,7 +77,7 @@ void lcd_write_data(unsigned char data)
LCD_DATA_HIGH(); LCD_DATA_HIGH();
else else
LCD_DATA_LOW(); LCD_DATA_LOW();
LCD_CLK_LOW(); LCD_CLK_LOW();
delay(); delay();
LCD_CLK_HIGH(); LCD_CLK_HIGH();
...@@ -97,12 +93,12 @@ void lcd_write_data(unsigned char data) ...@@ -97,12 +93,12 @@ void lcd_write_data(unsigned char data)
static void rt_hw_lcd_update(struct rt_device_rect_info *rect_info) static void rt_hw_lcd_update(struct rt_device_rect_info *rect_info)
{ {
rt_uint8_t i,j = GUI_LCM_XMAX; rt_uint8_t i,j = GUI_LCM_XMAX;
rt_uint8_t* p = (rt_uint8_t*)gui_disp_buf; rt_uint8_t* p = (rt_uint8_t*)gui_disp_buf;
for (i=0; i<GUI_LCM_PAGE; i++) for (i=0; i<GUI_LCM_PAGE; i++)
{ {
lcd_write_cmd(SET_PAGE_ADDR_0|i); lcd_write_cmd(SET_PAGE_ADDR_0|i);
lcd_write_cmd(SET_COLH_ADDR_0); lcd_write_cmd(SET_COLH_ADDR_0);
lcd_write_cmd(SET_COLL_ADDR_0); lcd_write_cmd(SET_COLL_ADDR_0);
j = GUI_LCM_XMAX; j = GUI_LCM_XMAX;
while (j--) while (j--)
...@@ -125,7 +121,7 @@ static void rt_hw_lcd_set_pixel(rtgui_color_t *c, int x, int y) ...@@ -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)) if (*c == rtgui_color_to_565(black))
gui_disp_buf[page][x] |= 1<<(y%8); gui_disp_buf[page][x] |= 1<<(y%8);
else else
if (*c == rtgui_color_to_565(white)) if (*c == rtgui_color_to_565(white))
gui_disp_buf[page][x] &= ~(1<<(y%8)); 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) ...@@ -134,7 +130,7 @@ static void rt_hw_lcd_get_pixel(rtgui_color_t *c, int x, int y)
{ {
rt_uint8_t page; rt_uint8_t page;
page = y/8; page = y/8;
if (gui_disp_buf[page][x] & (1<<(y%8))) if (gui_disp_buf[page][x] & (1<<(y%8)))
*c = black; *c = black;
else else
...@@ -144,16 +140,16 @@ static void rt_hw_lcd_get_pixel(rtgui_color_t *c, int x, int y) ...@@ -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) static void rt_hw_lcd_draw_hline(rtgui_color_t *c, int x1, int x2, int y)
{ {
rt_uint8_t page; rt_uint8_t page;
rt_uint8_t i; rt_uint8_t i;
page = y/8; page = y/8;
for (i=x1; i<x2; i++) for (i=x1; i<x2; i++)
{ {
if (*c == rtgui_color_to_565(black)) if (*c == rtgui_color_to_565(black))
gui_disp_buf[page][i] |= 1<<(y%8); gui_disp_buf[page][i] |= 1<<(y%8);
else else
if (*c == rtgui_color_to_565(white)) 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) ...@@ -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) 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 coll;
rt_uint8_t colh; rt_uint8_t colh;
rt_uint8_t page; rt_uint8_t page;
rt_uint8_t i; rt_uint8_t i;
page = y/8; page = y/8;
for (i=x1; i<x2; i++) for (i=x1; i<x2; i++)
{ {
gui_disp_buf[page][i] |= 1<<(y%8); gui_disp_buf[page][i] |= 1<<(y%8);
...@@ -213,7 +209,7 @@ void lcd_io_init() ...@@ -213,7 +209,7 @@ void lcd_io_init()
/*Select CPIO function*/ /*Select CPIO function*/
LCD_PS_PFR &= ~LCD_PS; LCD_PS_PFR &= ~LCD_PS;
/*Make pin output*/ /*Make pin output*/
LCD_PS_DDR |= LCD_PS; LCD_PS_DDR |= LCD_PS;
/*Select CPIO function*/ /*Select CPIO function*/
LCD_CLK_PFR &= ~LCD_CLK; LCD_CLK_PFR &= ~LCD_CLK;
/*Make pin output*/ /*Make pin output*/
...@@ -228,7 +224,7 @@ void lcd_io_init() ...@@ -228,7 +224,7 @@ void lcd_io_init()
static rt_err_t rt_lcd_init (rt_device_t dev) static rt_err_t rt_lcd_init (rt_device_t dev)
{ {
lcd_io_init(); lcd_io_init();
power_delay(); power_delay();
lcd_write_cmd(DISPLAY_OFF); lcd_write_cmd(DISPLAY_OFF);
reset_delay(); reset_delay();
...@@ -239,19 +235,19 @@ static rt_err_t rt_lcd_init (rt_device_t dev) ...@@ -239,19 +235,19 @@ static rt_err_t rt_lcd_init (rt_device_t dev)
lcd_write_cmd(SET_LCD_BIAS_9); lcd_write_cmd(SET_LCD_BIAS_9);
reset_delay(); reset_delay();
// ADC selection: display from left to right // ADC selection: display from left to right
lcd_write_cmd(SET_ADC_NORMAL); lcd_write_cmd(SET_ADC_NORMAL);
reset_delay(); reset_delay();
// Common output state selection: display from up to down // Common output state selection: display from up to down
lcd_write_cmd(COM_SCAN_DIR_REVERSE); lcd_write_cmd(COM_SCAN_DIR_REVERSE);
reset_delay(); reset_delay();
lcd_write_cmd(POWER_BOOSTER_ON); lcd_write_cmd(POWER_BOOSTER_ON);
power_delay(); // 50ms requried power_delay(); // 50ms requried
lcd_write_cmd(POWER_REGULATOR_ON); lcd_write_cmd(POWER_REGULATOR_ON);
power_delay(); // 50ms power_delay(); // 50ms
lcd_write_cmd(POWER_FOLLOWER_ON); lcd_write_cmd(POWER_FOLLOWER_ON);
power_delay(); // 50ms power_delay(); // 50ms
// Setting the built-in resistance radio for regulation of the V0 voltage // Setting the built-in resistance radio for regulation of the V0 voltage
// Electronic volume control // Electronic volume control
// Power control setting // Power control setting
...@@ -271,7 +267,7 @@ static rt_err_t rt_lcd_init (rt_device_t dev) ...@@ -271,7 +267,7 @@ static rt_err_t rt_lcd_init (rt_device_t dev)
delay(); delay();
lcd_write_cmd(DISPLAY_ON); lcd_write_cmd(DISPLAY_ON);
delay(); delay();
lcd_write_cmd(DISPLAY_ALL_ON); lcd_write_cmd(DISPLAY_ALL_ON);
delay(); delay();
lcd_write_cmd(DISPLAY_OFF); lcd_write_cmd(DISPLAY_OFF);
...@@ -280,7 +276,7 @@ static rt_err_t rt_lcd_init (rt_device_t dev) ...@@ -280,7 +276,7 @@ static rt_err_t rt_lcd_init (rt_device_t dev)
delay(); delay();
lcd_write_cmd(DISPLAY_ALL_NORMAL); lcd_write_cmd(DISPLAY_ALL_NORMAL);
delay(); delay();
return RT_EOK; return RT_EOK;
} }
...@@ -291,15 +287,15 @@ static rt_err_t rt_lcd_init (rt_device_t dev) ...@@ -291,15 +287,15 @@ static rt_err_t rt_lcd_init (rt_device_t dev)
* Output : None * Output : None
* Return : None * Return : None
*******************************************************************************/ *******************************************************************************/
void LCD_FillAll(unsigned char* buffer) void LCD_FillAll(unsigned char* buffer)
{ {
unsigned char i,j = GUI_LCM_XMAX; unsigned char i,j = GUI_LCM_XMAX;
unsigned char* p = buffer; unsigned char* p = buffer;
for (i=0; i<GUI_LCM_PAGE; i++) for (i=0; i<GUI_LCM_PAGE; i++)
{ {
lcd_write_cmd(SET_PAGE_ADDR_0|i); lcd_write_cmd(SET_PAGE_ADDR_0|i);
lcd_write_cmd(SET_COLH_ADDR_0); lcd_write_cmd(SET_COLH_ADDR_0);
lcd_write_cmd(SET_COLL_ADDR_0); lcd_write_cmd(SET_COLL_ADDR_0);
j = GUI_LCM_XMAX; j = GUI_LCM_XMAX;
while (j--) while (j--)
...@@ -322,8 +318,8 @@ void LCD_ClearSCR(void) ...@@ -322,8 +318,8 @@ void LCD_ClearSCR(void)
unsigned char i, j; unsigned char i, j;
for(i=0; i<GUI_LCM_PAGE; i++) 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; gui_disp_buf[i][j] = 0;
} }
LCD_FillAll((unsigned char*)gui_disp_buf); LCD_FillAll((unsigned char*)gui_disp_buf);
...@@ -331,7 +327,7 @@ void LCD_ClearSCR(void) ...@@ -331,7 +327,7 @@ void LCD_ClearSCR(void)
/**************************************************************************** /****************************************************************************
* Function Name : LCD_UpdatePoint * Function Name : LCD_UpdatePoint
* Description : refresh the point in screen * Description : refresh the point in screen
* Input : x X-coordinate * Input : x X-coordinate
y Y-coordinate y Y-coordinate
* Output : None * Output : None
...@@ -344,16 +340,16 @@ void LCD_UpdatePoint(unsigned int x, unsigned int y) ...@@ -344,16 +340,16 @@ void LCD_UpdatePoint(unsigned int x, unsigned int y)
page = y / 8; page = y / 8;
coll = x & 0x0f; coll = x & 0x0f;
colh = x >> 4; colh = x >> 4;
lcd_write_cmd(SET_PAGE_ADDR_0 | page); // page no. 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_COLH_ADDR_0 | colh); // fixed col first addr
lcd_write_cmd(SET_COLL_ADDR_0 | coll); lcd_write_cmd(SET_COLL_ADDR_0 | coll);
lcd_write_data(gui_disp_buf[page][x]); lcd_write_data(gui_disp_buf[page][x]);
} }
/**************************************************************************** /****************************************************************************
* Function Name : LCD_PutChar * 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') (the char only can be ' ','0'~'9','A'~'Z','a'~'z')
* Input : x X-coordinate * Input : x X-coordinate
y Y-coordinate y Y-coordinate
...@@ -363,13 +359,13 @@ void LCD_UpdatePoint(unsigned int x, unsigned int y) ...@@ -363,13 +359,13 @@ void LCD_UpdatePoint(unsigned int x, unsigned int y)
0 Fail 0 Fail
****************************************************************************/ ****************************************************************************/
unsigned char LCD_PutChar(unsigned long x, unsigned long y, unsigned char ch) unsigned char LCD_PutChar(unsigned long x, unsigned long y, unsigned char ch)
{ {
unsigned char data; unsigned char data;
unsigned char i, j; unsigned char i, j;
if( x >=(GUI_LCM_XMAX-8) ) return(0); if( x >=(GUI_LCM_XMAX-8) ) return(0);
if( y >=(GUI_LCM_YMAX-8) ) return(0); if( y >=(GUI_LCM_YMAX-8) ) return(0);
if(ch == 0x20) if(ch == 0x20)
ch -= 0x20; ch -= 0x20;
else if((ch >= 0x30)&&(ch <= 0x39)) else if((ch >= 0x30)&&(ch <= 0x39))
...@@ -380,30 +376,30 @@ unsigned char LCD_PutChar(unsigned long x, unsigned long y, unsigned char ch) ...@@ -380,30 +376,30 @@ unsigned char LCD_PutChar(unsigned long x, unsigned long y, unsigned char ch)
ch -= 0x3C; ch -= 0x3C;
else else
return(0); return(0);
for(i = 0; i < 8; i++) for(i = 0; i < 8; i++)
{ {
data = FONTTYPE8_8[ch][i]; data = FONTTYPE8_8[ch][i];
for(j = 0; j < 8; j++) for(j = 0; j < 8; j++)
{ {
if( (data&BIT_MASK[j]) == 0) if( (data&BIT_MASK[j]) == 0)
gui_disp_buf[y / 8][x] &= (~(0x01 << ( y % 8))); gui_disp_buf[y / 8][x] &= (~(0x01 << ( y % 8)));
else else
gui_disp_buf[y / 8][x] |= (0x01 <<( y % 8)); gui_disp_buf[y / 8][x] |= (0x01 <<( y % 8));
LCD_UpdatePoint(x, y); LCD_UpdatePoint(x, y);
x ++; x ++;
} }
x -= 8; x -= 8;
y++; y++;
} }
return(1); return(1);
} }
/**************************************************************************** /****************************************************************************
* Function Name : LCD_PutString * Function Name : LCD_PutString
* Description : output string to screen * Description : output string to screen
* Input : x X-coordinate * Input : x X-coordinate
y Y-coordinate y Y-coordinate
str pointer to string str pointer to string
...@@ -411,32 +407,32 @@ unsigned char LCD_PutChar(unsigned long x, unsigned long y, unsigned char ch) ...@@ -411,32 +407,32 @@ unsigned char LCD_PutChar(unsigned long x, unsigned long y, unsigned char ch)
* Return : None * Return : None
****************************************************************************/ ****************************************************************************/
void LCD_PutString(unsigned long x, unsigned long y, char *str) void LCD_PutString(unsigned long x, unsigned long y, char *str)
{ {
while(1) while(1)
{ {
if( (*str)=='\0' ) break; if( (*str)=='\0' ) break;
if( LCD_PutChar(x, y, *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) static rt_err_t rt_lcd_control (rt_device_t dev, int cmd, void *args)
{ {
switch (cmd) switch (cmd)
{ {
#ifdef RT_USING_RTGUI #ifdef RT_USING_RTGUI
case RTGRAPHIC_CTRL_RECT_UPDATE: case RTGRAPHIC_CTRL_RECT_UPDATE:
rt_hw_lcd_update(args); rt_hw_lcd_update(args);
break; break;
case RTGRAPHIC_CTRL_POWERON: case RTGRAPHIC_CTRL_POWERON:
break; break;
case RTGRAPHIC_CTRL_POWEROFF: case RTGRAPHIC_CTRL_POWEROFF:
break; break;
case RTGRAPHIC_CTRL_GET_INFO: case RTGRAPHIC_CTRL_GET_INFO:
rt_memcpy(args, &_lcd_info, sizeof(_lcd_info)); rt_memcpy(args, &_lcd_info, sizeof(_lcd_info));
break; break;
case RTGRAPHIC_CTRL_SET_MODE: case RTGRAPHIC_CTRL_SET_MODE:
break; break;
#else #else
case RT_DEVICE_CTRL_LCD_DISPLAY_ON: case RT_DEVICE_CTRL_LCD_DISPLAY_ON:
lcd_write_cmd(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) ...@@ -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: case RT_DEVICE_CTRL_LCD_CLEAR_SCR:
LCD_ClearSCR(); LCD_ClearSCR();
break; break;
#endif #endif
} }
return RT_EOK; return RT_EOK;
} }
void rt_hw_lcd_init(void) void rt_hw_lcd_init(void)
{ {
rt_device_t lcd = rt_malloc(sizeof(struct rt_device)); rt_device_t lcd = rt_malloc(sizeof(struct rt_device));
if (lcd == RT_NULL) return; /* no memory yet */ if (lcd == RT_NULL) return; /* no memory yet */
_lcd_info.bits_per_pixel = 16; _lcd_info.bits_per_pixel = 16;
_lcd_info.pixel_format = RTGRAPHIC_PIXEL_FORMAT_RGB565; _lcd_info.pixel_format = RTGRAPHIC_PIXEL_FORMAT_RGB565;
_lcd_info.framebuffer = RT_NULL; _lcd_info.framebuffer = RT_NULL;
_lcd_info.width = LCD_WIDTH; _lcd_info.width = LCD_WIDTH;
_lcd_info.height = LCD_HEIGHT; _lcd_info.height = LCD_HEIGHT;
/* init device structure */ /* init device structure */
lcd->type = RT_Device_Class_Unknown; lcd->type = RT_Device_Class_Unknown;
lcd->init = rt_lcd_init; lcd->init = rt_lcd_init;
lcd->open = RT_NULL; lcd->open = RT_NULL;
lcd->close = RT_NULL; lcd->close = RT_NULL;
lcd->control = rt_lcd_control; lcd->control = rt_lcd_control;
#ifdef RT_USING_RTGUI #ifdef RT_USING_RTGUI
lcd->user_data = (void*)&_lcd_ops; lcd->user_data = (void*)&_lcd_ops;
#endif #endif
/* register lcd device to RT-Thread */ /* register lcd device to RT-Thread */
rt_device_register(lcd, "lcd", RT_DEVICE_FLAG_RDWR); rt_device_register(lcd, "lcd", RT_DEVICE_FLAG_RDWR);
} }
/* /*
* File : lcd.h * Copyright (c) 2006-2021, RT-Thread Development Team
* 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 * SPDX-License-Identifier: Apache-2.0
* found in the file LICENSE in this distribution or at
* http://www.rt-thread.org/license/LICENSE
* *
* Change Logs: * Change Logs:
* Date Author Notes * Date Author Notes
...@@ -19,166 +15,166 @@ ...@@ -19,166 +15,166 @@
#include "mb9bf506r.h" #include "mb9bf506r.h"
/********* LCD Hardward Interface ************* /********* LCD Hardward Interface *************
LCD_CS PORT1.7 LCD_CS PORT1.7
LCD_CD PORT1.6 LCD_CD PORT1.6
LCD_WR PORT1.5 LCD_WR PORT1.5
LCD_RD PORT1.4 LCD_RD PORT1.4
LCD_SCK PORT1.3 LCD_SCK PORT1.3
LCD_MOSI PORT1.2 LCD_MOSI PORT1.2
LCD_C86 PORT1.1 LCD_C86 PORT1.1
LCD_PS PORT1.0 LCD_PS PORT1.0
LCD_DATA[0..7] PORT5.[0..7] LCD_DATA[0..7] PORT5.[0..7]
***********************************************/ ***********************************************/
#define LCD_CS (1UL << 7) #define LCD_CS (1UL << 7)
#define LCD_CS_DDR (FM3_GPIO->DDR1) #define LCD_CS_DDR (FM3_GPIO->DDR1)
#define LCD_CS_PFR (FM3_GPIO->PFR1) #define LCD_CS_PFR (FM3_GPIO->PFR1)
#define LCD_CS_PDOR (FM3_GPIO->PDOR1) #define LCD_CS_PDOR (FM3_GPIO->PDOR1)
#define LCD_CD (1UL << 6) #define LCD_CD (1UL << 6)
#define LCD_CD_DDR (FM3_GPIO->DDR1) #define LCD_CD_DDR (FM3_GPIO->DDR1)
#define LCD_CD_PFR (FM3_GPIO->PFR1) #define LCD_CD_PFR (FM3_GPIO->PFR1)
#define LCD_CD_PDOR (FM3_GPIO->PDOR1) #define LCD_CD_PDOR (FM3_GPIO->PDOR1)
#define LCD_PS (1UL << 0) #define LCD_PS (1UL << 0)
#define LCD_PS_DDR (FM3_GPIO->DDR1) #define LCD_PS_DDR (FM3_GPIO->DDR1)
#define LCD_PS_PFR (FM3_GPIO->PFR1) #define LCD_PS_PFR (FM3_GPIO->PFR1)
#define LCD_PS_PDOR (FM3_GPIO->PDOR1) #define LCD_PS_PDOR (FM3_GPIO->PDOR1)
#define LCD_CLK (1UL << 6) #define LCD_CLK (1UL << 6)
#define LCD_CLK_DDR (FM3_GPIO->DDR5) #define LCD_CLK_DDR (FM3_GPIO->DDR5)
#define LCD_CLK_PFR (FM3_GPIO->PFR5) #define LCD_CLK_PFR (FM3_GPIO->PFR5)
#define LCD_CLK_PDOR (FM3_GPIO->PDOR5) #define LCD_CLK_PDOR (FM3_GPIO->PDOR5)
#define LCD_DATA (1UL << 7) #define LCD_DATA (1UL << 7)
#define LCD_DATA_DDR (FM3_GPIO->DDR5) #define LCD_DATA_DDR (FM3_GPIO->DDR5)
#define LCD_DATA_PFR (FM3_GPIO->PFR5) #define LCD_DATA_PFR (FM3_GPIO->PFR5)
#define LCD_DATA_PDOR (FM3_GPIO->PDOR5) #define LCD_DATA_PDOR (FM3_GPIO->PDOR5)
/* LCD driver for ZYMG12864C3 */ /* LCD driver for ZYMG12864C3 */
#define LCD_WIDTH 128 #define LCD_WIDTH 128
#define LCD_HEIGHT 64 #define LCD_HEIGHT 64
// Driver the LCD with Parallel or serial interface and the command/data control pin is gpio // 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_HIGH() LCD_CS_PDOR |= LCD_CS
#define LCD_CS_LOW() 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_HIGH() LCD_CD_PDOR |= LCD_CD
#define LCD_CD_LOW() 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_HIGH() LCD_PS_PDOR |= LCD_PS
#define LCD_PS_LOW() 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_HIGH() LCD_CLK_PDOR |= LCD_CLK
#define LCD_CLK_LOW() 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_HIGH() LCD_DATA_PDOR |= LCD_DATA
#define LCD_DATA_LOW() LCD_DATA_PDOR &= ~LCD_DATA #define LCD_DATA_LOW() LCD_DATA_PDOR &= ~LCD_DATA
// define the arrtibute of ZYMG12864(LCM) // define the arrtibute of ZYMG12864(LCM)
#define GUI_LCM_XMAX 128 // defined the lcd's line-number is 128 #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_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_PAGE 8 // defined the lcd's page-number is 8(GUI_LCM_YMAX/8)
/* set LCD command */ /* set LCD command */
#define DISPLAY_ON 0xAF // A0,RD,WR:010 #define DISPLAY_ON 0xAF // A0,RD,WR:010
#define DISPLAY_OFF 0xAE // 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_START_LINE_0 0x40 // A0,RD,WR:010; line0~line63
#define SET_PAGE_ADDR_0 0xB0 // A0,RD,WR:010; addr0~addr8 #define SET_PAGE_ADDR_0 0xB0 // A0,RD,WR:010; addr0~addr8
#define SET_COLH_ADDR_0 0x10 // A0,RD,WR:010; #define SET_COLH_ADDR_0 0x10 // A0,RD,WR:010;
#define SET_COLL_ADDR_0 0x00 // A0,RD,WR:010; addr0~addr131 #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 READ_STATUS 0x-0 // A0,RD,WR:001; BUSY | ADC | ON/OFF | RESET | 0 0 0 0
#define STATUS_BUSY 0x80 #define STATUS_BUSY 0x80
#define STATUS_ADC_REVERSE 0x40 // column address 131-n : SEG n, else column address n : SEG n #define STATUS_ADC_REVERSE 0x40 // column address 131-n : SEG n, else column address n : SEG n
#define STATUS_DISPLAY_OFF 0x20 #define STATUS_DISPLAY_OFF 0x20
#define STATUS_RESET 0x80 #define STATUS_RESET 0x80
#define WRITE_DATA 0x-- // A0,RD,WR:110 #define WRITE_DATA 0x-- // A0,RD,WR:110
#define READ_DATE 0x-- // A0,RD,WR:101; spi mode is unavailable #define READ_DATE 0x-- // A0,RD,WR:101; spi mode is unavailable
#define SET_ADC_NORMAL 0xA0 // A0,RD,WR:010 #define SET_ADC_NORMAL 0xA0 // A0,RD,WR:010
#define SET_ADC_REVERSE 0xA1 // A0,RD,WR:010 #define SET_ADC_REVERSE 0xA1 // A0,RD,WR:010
#define DISPLAY_NORMAL 0xA6 // A0,RD,WR:010 #define DISPLAY_NORMAL 0xA6 // A0,RD,WR:010
#define DISPLAY_REVERSE 0xA7 // A0,RD,WR:010; reverse color #define DISPLAY_REVERSE 0xA7 // A0,RD,WR:010; reverse color
#define DISPLAY_ALL_ON 0xA5 // A0,RD,WR:010 #define DISPLAY_ALL_ON 0xA5 // A0,RD,WR:010
#define DISPLAY_ALL_NORMAL 0xA4 // A0,RD,WR:010 #define DISPLAY_ALL_NORMAL 0xA4 // A0,RD,WR:010
/************************************************************* /*************************************************************
* bias: 1/65duty | 1/49duty | 1/33duty | 1/55duty | 1/53duty * * 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 * * 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 * * 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_7 0xA3 // A0,RD,WR:010
#define SET_LCD_BIAS_9 0xA2 // 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_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 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 RESET_LCD 0xE2 // A0,RD,WR:010
/************************************************************************************** /**************************************************************************************
* Com Scan Dir: | 1/65duty | 1/49duty | 1/33duty | 1/55duty | 1/53duty * * 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 * * C0: Normal | COM0:COM63 | COM0:COM47 | COM0:COM31 | COM0:COM53 | COM0:COM51 *
* C8: Reverse | COM63:COM0 | COM47:COM0 | COM31:COM0 | COM53:COM0 | COM51:COM0 * * 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_NORMAL 0xC0 // A0,RD,WR:010
#define COM_SCAN_DIR_REVERSE 0xC8 // 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 // 0 0 1 0 1 | Booster On | Regulator On | Follower On
#define POWER_BOOSTER_ON 0x2C // A0,RD,WR:010 #define POWER_BOOSTER_ON 0x2C // A0,RD,WR:010
#define POWER_REGULATOR_ON 0x2E // A0,RD,WR:010 #define POWER_REGULATOR_ON 0x2E // A0,RD,WR:010
#define POWER_FOLLOWER_ON 0x2F // 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_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_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_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_DISABLE 0xAD // A0,RD,WR:010; preceding command
#define SLEEP_MODE_DELIVER 0x00 // A0,RD,WR:010; following 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_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_234 0x00 // A0,RD,WR:010; following command
#define BOOST_RATIO_5 0x01 // 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_6 0x03 // A0,RD,WR:010; following command
#define COMMAND_NOP 0xE3 // A0,RD,WR:010 #define COMMAND_NOP 0xE3 // A0,RD,WR:010
#define COMMAND_IC_TEST 0xFC // A0,RD,WR:010; don't use #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_WIDTH 0
#define RT_DEVICE_CTRL_LCD_GET_HEIGHT 1 #define RT_DEVICE_CTRL_LCD_GET_HEIGHT 1
#define RT_DEVICE_CTRL_LCD_GET_BPP 2 #define RT_DEVICE_CTRL_LCD_GET_BPP 2
#define RT_DEVICE_CTRL_LCD_GET_FRAMEBUFFER 3 #define RT_DEVICE_CTRL_LCD_GET_FRAMEBUFFER 3
#define RT_DEVICE_CTRL_LCD_POWER_ON 4 #define RT_DEVICE_CTRL_LCD_POWER_ON 4
#define RT_DEVICE_CTRL_LCD_POWER_OFF 5 #define RT_DEVICE_CTRL_LCD_POWER_OFF 5
#define RT_DEVICE_CTRL_LCD_CLEAR_SCR 6 #define RT_DEVICE_CTRL_LCD_CLEAR_SCR 6
#define RT_DEVICE_CTRL_LCD_FILL_ALL 7 #define RT_DEVICE_CTRL_LCD_FILL_ALL 7
#define RT_DEVICE_CTRL_LCD_UPDATE_POINT 8 #define RT_DEVICE_CTRL_LCD_UPDATE_POINT 8
#define RT_DEVICE_CTRL_LCD_DISPLAY_ON 9 #define RT_DEVICE_CTRL_LCD_DISPLAY_ON 9
#define RT_DEVICE_CTRL_LCD_DISPLAY_OFF 10 #define RT_DEVICE_CTRL_LCD_DISPLAY_OFF 10
#define RT_DEVICE_CTRL_LCD_PUT_STRING 11 #define RT_DEVICE_CTRL_LCD_PUT_STRING 11
enum enum
{ {
ADC_MSG, ADC_MSG,
KEY_MSG, KEY_MSG,
CPU_MSG, CPU_MSG,
MAX_MSG, MAX_MSG,
}; };
struct lcd_msg struct lcd_msg
{ {
rt_uint8_t type; rt_uint8_t type;
rt_uint16_t adc_value; rt_uint16_t adc_value;
rt_uint8_t key; rt_uint8_t key;
rt_uint16_t major; rt_uint16_t major;
rt_uint16_t minor; rt_uint16_t minor;
}; };
extern rt_uint32_t x; extern rt_uint32_t x;
......
/* /*
* File : led.c * Copyright (c) 2006-2021, RT-Thread Development Team
* 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 * SPDX-License-Identifier: Apache-2.0
* found in the file LICENSE in this distribution or at
* http://www.rt-thread.org/license/LICENSE
* *
* Change Logs: * Change Logs:
* Date Author Notes * Date Author Notes
* 2011-03-03 lgnq * 2011-03-03 lgnq
*/ */
#include <rtthread.h> #include <rtthread.h>
#include <rthw.h> #include <rthw.h>
...@@ -20,8 +16,8 @@ ...@@ -20,8 +16,8 @@
void rt_hw_led_on(rt_uint8_t num) void rt_hw_led_on(rt_uint8_t num)
{ {
RT_ASSERT(num < LEDS_MAX_NUMBER); RT_ASSERT(num < LEDS_MAX_NUMBER);
switch (num) switch (num)
{ {
case 1: case 1:
...@@ -31,16 +27,16 @@ void rt_hw_led_on(rt_uint8_t num) ...@@ -31,16 +27,16 @@ void rt_hw_led_on(rt_uint8_t num)
LED_PDOR &= ~LED2; LED_PDOR &= ~LED2;
break; break;
case 3: case 3:
LED_PDOR &= ~LED3; LED_PDOR &= ~LED3;
break; break;
default: default:
break; break;
} }
} }
void rt_hw_led_off(rt_uint8_t num) void rt_hw_led_off(rt_uint8_t num)
{ {
RT_ASSERT(num < LEDS_MAX_NUMBER); RT_ASSERT(num < LEDS_MAX_NUMBER);
switch (num) switch (num)
{ {
...@@ -51,17 +47,17 @@ void rt_hw_led_off(rt_uint8_t num) ...@@ -51,17 +47,17 @@ void rt_hw_led_off(rt_uint8_t num)
LED_PDOR |= LED2; LED_PDOR |= LED2;
break; break;
case 3: case 3:
LED_PDOR |= LED3; LED_PDOR |= LED3;
break; break;
default: default:
break; break;
} }
} }
void rt_hw_led_toggle(rt_uint8_t num) void rt_hw_led_toggle(rt_uint8_t num)
{ {
RT_ASSERT(num < LEDS_MAX_NUMBER); RT_ASSERT(num < LEDS_MAX_NUMBER);
switch (num) switch (num)
{ {
case 1: case 1:
...@@ -80,11 +76,11 @@ void rt_hw_led_toggle(rt_uint8_t num) ...@@ -80,11 +76,11 @@ void rt_hw_led_toggle(rt_uint8_t num)
if (LED_PDOR&LED3) if (LED_PDOR&LED3)
LED_PDOR &= ~LED3; LED_PDOR &= ~LED3;
else else
LED_PDOR |= LED3; LED_PDOR |= LED3;
break; break;
default: default:
break; break;
} }
} }
static rt_err_t led_io_init(void) static rt_err_t led_io_init(void)
...@@ -95,23 +91,23 @@ static rt_err_t led_io_init(void) ...@@ -95,23 +91,23 @@ static rt_err_t led_io_init(void)
LED_PDOR |= LED_MASK; LED_PDOR |= LED_MASK;
/*Make led pins outputs*/ /*Make led pins outputs*/
LED_DDR |= LED_MASK; LED_DDR |= LED_MASK;
//LED3 is controled by PWM //LED3 is controled by PWM
FM3_GPIO->PFR3 = 0x1000; FM3_GPIO->PFR3 = 0x1000;
FM3_GPIO->EPFR04 = 0x00080000; FM3_GPIO->EPFR04 = 0x00080000;
FM3_BT2_PWM->TMCR = 0x0018; 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->STC = 0x00;
FM3_BT2_PWM->PCSR = 0x61A; /* Down count = 1562 */ FM3_BT2_PWM->PCSR = 0x61A; /* Down count = 1562 */
FM3_BT2_PWM->PDUT = 0x0; /* Duty count = 16/1562=10% */ FM3_BT2_PWM->PDUT = 0x0; /* Duty count = 16/1562=10% */
FM3_BT2_PWM->TMCR |= 0x03; /* start base timer(softwere TRG) */ FM3_BT2_PWM->TMCR |= 0x03; /* start base timer(softwere TRG) */
return RT_EOK; return RT_EOK;
} }
void pwm_update(rt_uint16_t value) void pwm_update(rt_uint16_t value)
{ {
FM3_BT2_PWM->PDUT = value; FM3_BT2_PWM->PDUT = value;
} }
static void led1_thread_entry(void *parameter) static void led1_thread_entry(void *parameter)
...@@ -139,11 +135,11 @@ void rt_hw_led_init(void) ...@@ -139,11 +135,11 @@ void rt_hw_led_init(void)
led_io_init(); led_io_init();
led1_thread = rt_thread_create("led1", led1_thread_entry, RT_NULL, 384, 29, 5); led1_thread = rt_thread_create("led1", led1_thread_entry, RT_NULL, 384, 29, 5);
if (led1_thread != RT_NULL) if (led1_thread != RT_NULL)
rt_thread_startup(led1_thread); rt_thread_startup(led1_thread);
led2_thread = rt_thread_create("led2", led2_thread_entry, RT_NULL, 384, 30, 5); led2_thread = rt_thread_create("led2", led2_thread_entry, RT_NULL, 384, 30, 5);
if (led2_thread != RT_NULL) if (led2_thread != RT_NULL)
rt_thread_startup(led2_thread); rt_thread_startup(led2_thread);
} }
......
/* /*
* File : led.h * Copyright (c) 2006-2021, RT-Thread Development Team
* 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 * SPDX-License-Identifier: Apache-2.0
* found in the file LICENSE in this distribution or at
* http://www.rt-thread.org/license/LICENSE
* *
* Change Logs: * Change Logs:
* Date Author Notes * Date Author Notes
* 2011-03-03 lgnq * 2011-03-03 lgnq
*/ */
#ifndef __LED_H__ #ifndef __LED_H__
#define __LED_H__ #define __LED_H__
#include "mb9bf506r.h" #include "mb9bf506r.h"
#define LEDS_MAX_NUMBER 4 #define LEDS_MAX_NUMBER 4
/*LEDs*/ /*LEDs*/
#define LED1 (1UL<<10) #define LED1 (1UL<<10)
...@@ -29,9 +25,9 @@ ...@@ -29,9 +25,9 @@
#define LED_DDR (FM3_GPIO->DDR3) #define LED_DDR (FM3_GPIO->DDR3)
#define LED_PDOR (FM3_GPIO->PDOR3) #define LED_PDOR (FM3_GPIO->PDOR3)
#define RT_DEVICE_CTRL_LED_ON 0 #define RT_DEVICE_CTRL_LED_ON 0
#define RT_DEVICE_CTRL_LED_OFF 1 #define RT_DEVICE_CTRL_LED_OFF 1
#define RT_DEVICE_CTRL_LED_TOGGLE 2 #define RT_DEVICE_CTRL_LED_TOGGLE 2
void rt_hw_led_init(void); void rt_hw_led_init(void);
void rt_hw_led_on(rt_uint8_t num); void rt_hw_led_on(rt_uint8_t num);
......
...@@ -3,16 +3,16 @@ ...@@ -3,16 +3,16 @@
#define __RTTHREAD_CFG_H__ #define __RTTHREAD_CFG_H__
/* RT_NAME_MAX*/ /* RT_NAME_MAX*/
#define RT_NAME_MAX 8 #define RT_NAME_MAX 8
/* RT_ALIGN_SIZE*/ /* RT_ALIGN_SIZE*/
#define RT_ALIGN_SIZE 4 #define RT_ALIGN_SIZE 4
/* PRIORITY_MAX */ /* PRIORITY_MAX */
#define RT_THREAD_PRIORITY_MAX 32 #define RT_THREAD_PRIORITY_MAX 32
/* Tick per Second */ /* Tick per Second */
#define RT_TICK_PER_SECOND 100 #define RT_TICK_PER_SECOND 100
/* SECTION: RT_DEBUG */ /* SECTION: RT_DEBUG */
/* Thread Debug */ /* Thread Debug */
...@@ -53,20 +53,20 @@ ...@@ -53,20 +53,20 @@
#define RT_USING_DEVICE #define RT_USING_DEVICE
/* RT_USING_UART */ /* RT_USING_UART */
#define RT_USING_UART0 #define RT_USING_UART0
#define RT_UART_RX_BUFFER_SIZE 64 #define RT_UART_RX_BUFFER_SIZE 64
/* SECTION: Console options */ /* SECTION: Console options */
#define RT_TINY_SIZE #define RT_TINY_SIZE
#define RT_USING_CONSOLE #define RT_USING_CONSOLE
/* the buffer size of console */ /* the buffer size of console */
#define RT_CONSOLEBUF_SIZE 128 #define RT_CONSOLEBUF_SIZE 128
/* SECTION: RTGUI support */ /* SECTION: RTGUI support */
/* using RTGUI support */ /* using RTGUI support */
/* #define RT_USING_RTGUI */ /* #define RT_USING_RTGUI */
/* name length of RTGUI object */ /* name length of RTGUI object */
#define RTGUI_NAME_MAX 16 #define RTGUI_NAME_MAX 16
/* support 16 weight font */ /* support 16 weight font */
//#define RTGUI_USING_FONT16 //#define RTGUI_USING_FONT16
/* support 12 weight font */ /* support 12 weight font */
......
/* /*
* File : startup.c * Copyright (c) 2006-2021, RT-Thread Development Team
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2009 - 2011, RT-Thread Development Team
* *
* The license and distribution terms for this file may be * SPDX-License-Identifier: Apache-2.0
* found in the file LICENSE in this distribution or at
* http://www.rt-thread.org/license/LICENSE
* *
* Change Logs: * Change Logs:
* Date Author Notes * Date Author Notes
...@@ -38,57 +34,57 @@ extern int __bss_end; ...@@ -38,57 +34,57 @@ extern int __bss_end;
*/ */
void rtthread_startup(void) void rtthread_startup(void)
{ {
/* init board */ /* init board */
rt_hw_board_init(); rt_hw_board_init();
/* show version */ /* show version */
rt_show_version(); rt_show_version();
/* init timer system */ /* init timer system */
rt_system_timer_init(); rt_system_timer_init();
#ifdef RT_USING_HEAP #ifdef RT_USING_HEAP
#ifdef __CC_ARM #ifdef __CC_ARM
rt_system_heap_init((void*)&Image$$RW_IRAM1$$ZI$$Limit, (void*)FM3_SRAM_END); rt_system_heap_init((void*)&Image$$RW_IRAM1$$ZI$$Limit, (void*)FM3_SRAM_END);
#elif __ICCARM__ #elif __ICCARM__
rt_system_heap_init(__segment_end("HEAP"), (void*)FM3_SRAM_END); rt_system_heap_init(__segment_end("HEAP"), (void*)FM3_SRAM_END);
#else #else
/* init memory system */ /* init memory system */
rt_system_heap_init((void*)&__bss_end, (void*)FM3_SRAM_END); rt_system_heap_init((void*)&__bss_end, (void*)FM3_SRAM_END);
#endif #endif
#endif #endif
/* init scheduler system */ /* init scheduler system */
rt_system_scheduler_init(); rt_system_scheduler_init();
/* init application */ /* init application */
rt_application_init(); rt_application_init();
/* init timer thread */ /* init timer thread */
rt_system_timer_thread_init(); rt_system_timer_thread_init();
/* init idle thread */ /* init idle thread */
rt_thread_idle_init(); rt_thread_idle_init();
/* start scheduler */ /* start scheduler */
rt_system_scheduler_start(); rt_system_scheduler_start();
/* never reach here */ /* never reach here */
return ; return ;
} }
int main(void) int main(void)
{ {
/* disable interrupt first */ /* disable interrupt first */
rt_hw_interrupt_disable(); rt_hw_interrupt_disable();
/* init system setting */ /* init system setting */
SystemInit(); SystemInit();
/* startup RT-Thread RTOS */
rtthread_startup();
return 0; /* startup RT-Thread RTOS */
rtthread_startup();
return 0;
} }
/*@}*/ /*@}*/
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册