提交 3c3353ee 编写于 作者: O onelife.real

*** EFM32 branch ***

1. Add keys and joystick driver
2. Add direct drive (frame buffer) method support in LCD driver

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@1973 bbd45198-f89e-11dd-88c7-29a3b14d5316
上级 9e884249
......@@ -7,13 +7,13 @@ if rtconfig.PLATFORM == 'gcc':
src_bsp.append('start_gcc.S')
src_drv1 = ['drv_dma.c', 'drv_rtc.c', 'drv_adc.c', 'drv_acmp.c', 'drv_usart.c', 'drv_leuart.c', 'drv_iic.c', 'drv_timer.c']
src_drv2 = ['drv_sdcard.c', 'drv_ethernet.c']
src_dev = ['dev_misc.c', 'dev_led.c', 'dev_accel.c', 'dev_sflash.c', 'dev_lcd.c']
src_dev = ['dev_misc.c', 'dev_led.c', 'dev_accel.c', 'dev_sflash.c', 'dev_lcd.c', 'dev_keys.c']
src_hdl = ['hdl_interrupt.c']
src_app = ['httpd.c']
src = src_bsp + src_drv1 + src_drv2 + src_dev + src_hdl + src_app
CPPPATH = [RTT_ROOT + '/bsp/efm32']
CPPDEFINES = [rtconfig.EFM32_BOARD, rtconfig.EFM32_TYPE]
CPPDEFINES = [rtconfig.EFM32_BOARD, rtconfig.EFM32_LCD, rtconfig.EFM32_TYPE]
group = DefineGroup('Startup', src, depend = [''], CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES)
Return('group')
/***************************************************************************//**
* @file application.c
* @brief application tasks
* @brief Demo application
* COPYRIGHT (C) 2011, RT-Thread Development Team
* @author Bernard, onelife
* @version 0.4 beta
......@@ -19,6 +19,7 @@
* 2011-08-23 onelife Modify Ethernet DEMO according to the changes of
* lwIP API in reversion 1668
* 2011-12-20 onelife Add LCD DEMO
* 2012-02-16 onelife Add photo frame DEMO
******************************************************************************/
/***************************************************************************//**
......@@ -62,168 +63,34 @@
#include <rtgui/widgets/label.h>
#include <rtgui/widgets/window.h>
#include <rtgui/widgets/box.h>
#include <rtgui/image.h>
#if defined(RTGUI_USING_DFS_FILERW)
#include <dfs_posix.h>
#define PATH_SEPARATOR '/'
#endif
#define APP_PHOTO_FRAME
#endif
/* Private typedef -----------------------------------------------------------*/
struct photo_event
{
struct rtgui_event parent;
rt_uint32_t cmd;
rt_uint8_t* path;
rt_uint8_t* format;
};
/* Private define ------------------------------------------------------------*/
#define APP_CMD_PHOTO_FRAME 0x00000001
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
volatile rt_uint32_t rt_system_status = 0;
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
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;
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_draw_text(dc, " EFM3 EFM32GG_DK3750 Kit", &rect);
rect.y1 += 10;
rtgui_dc_draw_text(dc, " RT-Thread & RTGUI", &rect);
rect.y1 += 10;
rtgui_dc_draw_text(dc, " Ҳ!", &rect);
rtgui_dc_end_drawing(dc);
return RT_FALSE;
}
else if (event->type == RTGUI_EVENT_KBD)
{
struct rtgui_dc* dc;
struct rtgui_rect rect;
struct rtgui_event_kbd* ekbd = (struct rtgui_event_kbd*)event;
if (ekbd->type == RTGUI_KEYDOWN)
{
char key_str[16];
switch (ekbd->key)
{
case RTGUIK_LEFT:
rt_sprintf(key_str, "%s", "L");
break;
case RTGUIK_RIGHT:
rt_sprintf(key_str, "%s", "R");
break;
case RTGUIK_DOWN:
rt_sprintf(key_str, "%s", "D");
break;
case RTGUIK_UP:
rt_sprintf(key_str, "%s", "U");
break;
default:
rt_sprintf(key_str, "%s", "S");
break;
}
dc = rtgui_dc_begin_drawing(widget);
if (dc == RT_NULL)
return RT_FALSE;
rect.x1 = 118;
rect.y1 = 1;
rect.x2 = 127;
rect.y2 = 10;
rtgui_dc_fill_rect(dc, &rect);
rtgui_dc_draw_text(dc, key_str, &rect);
rtgui_dc_end_drawing(dc);
}
else if (ekbd->type == RTGUI_KEYUP)
{
dc = rtgui_dc_begin_drawing(widget);
if (dc == RT_NULL)
return RT_FALSE;
rect.x1 = 118;
rect.y1 = 1;
rect.x2 = 127;
rect.y2 = 10;
rtgui_dc_fill_rect(dc, &rect);
//rtgui_dc_draw_text(dc, key_str, &rect);
rtgui_dc_end_drawing(dc);
}
}
else if (event->type == RTGUI_EVENT_COMMAND)
{
char str[16];
struct rtgui_dc* dc;
struct rtgui_rect rect;
struct rtgui_event_command* ecmd;
rt_uint8_t major,minor;
dc = rtgui_dc_begin_drawing(widget);
if (dc == RT_NULL)
return RT_FALSE;
ecmd = (struct rtgui_event_command*)event;
switch (ecmd->command_id)
{
default:
rect.x1 = 1;
rect.y1 = 1;
rect.x2 = 117;
rect.y2 = 10;
rtgui_dc_fill_rect(dc, &rect);
rt_sprintf(str, "ADC = %d mv", 123);
rtgui_dc_draw_text(dc, str, &rect);
break;
/* case ADC_UPDATE:
rect.x1 = 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);
break;
case CPU_UPDATE:
cpu_usage_get(&major, &minor);
rect.x1 = 1;
rect.y1 = 12;
rect.x2 = 127;
rect.y2 = 22;
rtgui_dc_fill_rect(dc, &rect);
rt_sprintf(str, "CPU : %d.%d%", major, minor);
rtgui_dc_draw_text(dc, str, &rect);
rect.y1 = 23;
rect.y2 = 63;
index++;
if (index == 127)
{
index = 1;
rtgui_dc_fill_rect(dc, &rect);
}
if (major>40)
rtgui_dc_draw_vline(dc, index, rect.y1, rect.y2);
else
rtgui_dc_draw_vline(dc, index, rect.y2-major, rect.y2);
break;
*/ }
rtgui_dc_end_drawing(dc);
}
return rtgui_view_event_handler(widget, event);
}
static void wb_info(void* parameter)
{
rt_mq_t mq;
......@@ -258,7 +125,7 @@ static void wb_info(void* parameter)
// rtgui_widget_set_event_handler(RTGUI_WIDGET(view), view_event_handler);
/* Create a lable */
rtgui_label_t *label = rtgui_label_create("R-Thread & RTGUI");
rtgui_label_t *label = rtgui_label_create("RT-Thread & RTGUI");
if(label == RT_NULL)
{
rt_kprintf("Create lable failed!\n");
......@@ -293,6 +160,65 @@ static void wb_info(void* parameter)
rt_mq_delete(mq);
}
static rt_bool_t pic_view_event_handler(rtgui_widget_t* widget, rtgui_event_t *event)
{
rt_bool_t result;
rt_bool_t load = RT_FALSE;
result = rtgui_view_event_handler(widget, event);
switch(event->type)
{
case RTGUI_EVENT_PAINT:
load = RT_TRUE;
break;
case RTGUI_EVENT_MOUSE_BUTTON:
{
struct rtgui_event_mouse *mouse = (struct rtgui_event_mouse *)event;
if (mouse->button == RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_UP)
{
rt_kprintf("APP: left click (%x)\n", mouse->button);
}
}
break;
}
if (load)
{
struct rtgui_dc* dc;
rtgui_rect_t rect;
rtgui_image_t* image;
// image = rtgui_image_create_from_file("jpg", "/test9.jpg", RT_FALSE);
image = rtgui_image_create_from_file("bmp", "/test_565.bmp", RT_FALSE);
dc = rtgui_dc_begin_drawing(widget);
if (dc == RT_NULL)
{
return result;
}
rtgui_widget_get_rect(widget, &rect);
rtgui_widget_rect_to_device(widget, &rect);
rect.y1 +=20; rect.y2 +=20;
if (image != RT_NULL)
{
rtgui_image_blit(image, dc, &rect);
rtgui_image_destroy(image);
}
else
{
rt_kprintf("APP err: no image found!\n");
}
rtgui_dc_end_drawing(dc);
}
return result;
}
static void wb_main(void* parameter)
{
......@@ -317,7 +243,7 @@ static void wb_main(void* parameter)
return;
}
/* Create a view */
view = rtgui_view_create("view_2");
view = rtgui_view_create("pic_view");
if(view == RT_NULL)
{
rt_kprintf("Create view failed!\n");
......@@ -325,7 +251,7 @@ static void wb_main(void* parameter)
}
RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(view)) = white;
RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(view)) = red;
// rtgui_widget_set_event_handler(RTGUI_WIDGET(view), view_event_handler);
rtgui_widget_set_event_handler(RTGUI_WIDGET(view), pic_view_event_handler);
/* Create a lable */
rtgui_label_t* label = rtgui_label_create("EFM32GG_DK3750 Kit");
......@@ -426,6 +352,128 @@ static void win_hello(void* parameter)
rt_mq_delete(mq);
}
static rt_bool_t photo_view_event_handler(rtgui_widget_t* widget, rtgui_event_t *event)
{
rt_bool_t result = RT_FALSE;
struct photo_event *photo_event = (struct photo_event *)event;
result = rtgui_view_event_handler(widget, event);
rt_kprintf("view event %x\n", event->type);
if ((event->type == RTGUI_EVENT_COMMAND) && \
(photo_event->cmd == APP_CMD_PHOTO_FRAME))
{
rtgui_rect_t rect;
rtgui_image_t* image;
struct rtgui_dc* dc;
rtgui_widget_get_rect(widget, &rect);
rtgui_widget_rect_to_device(widget, &rect);
rect.y1 +=20; rect.y2 +=20;
dc = rtgui_dc_begin_drawing(widget);
if (dc == RT_NULL)
{
return result;
}
image = rtgui_image_create_from_file(photo_event->format,
photo_event->path, RT_TRUE);
if (image != RT_NULL)
{
rtgui_image_blit(image, dc, &rect);
rtgui_image_destroy(image);
return result;
}
return RT_TRUE;
}
return result;
}
static rt_bool_t photo_lable_event_handler(rtgui_widget_t* widget, rtgui_event_t *event)
{
rt_bool_t result = RT_FALSE;
rt_kprintf("lable event %x\n", event->type);
if (event->type == RTGUI_EVENT_COMMAND)
{
struct photo_event *photo = (struct photo_event *)event;
rtgui_label_set_text((rtgui_label_t *)widget, photo->path);
}
return result;
}
static void wb_photo(void* parameter)
{
rt_mq_t mq;
rtgui_view_t *view;
rtgui_workbench_t *workbench;
/* Create message queue for self */
mq = rt_mq_create("photo", 256, 4, RT_IPC_FLAG_FIFO);
if(mq == RT_NULL)
{
rt_kprintf("Create mq failed!\n");
return;
}
rtgui_thread_register(rt_thread_self(), mq);
/* Create workbench */
workbench = rtgui_workbench_create("main", "photo");
if(workbench == RT_NULL)
{
rt_kprintf("Create wb failed!\n");
return;
}
/* Create a view */
view = rtgui_view_create("view");
if(view == RT_NULL)
{
rt_kprintf("Create view failed!\n");
return;
}
RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(view)) = white;
RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(view)) = blue;
rtgui_widget_set_event_handler(RTGUI_WIDGET(view), photo_view_event_handler);
// rtgui_widget_set_oncommand(RTGUI_WIDGET(view), photo_view_event_handler);
/* Create a lable */
rtgui_label_t* label = rtgui_label_create("Photo Frame Demo");
if(label == RT_NULL)
{
rt_kprintf("Create lable failed!\n");
return;
}
RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(label)) = white;
RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(label)) = blue;
/* Set lable position */
rtgui_rect_t rect;
rect.x1 = 0; rect.y1 = 2;
rect.x2 = 300; rect.y2 = 20;
rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
rtgui_widget_set_event_handler(RTGUI_WIDGET(label), photo_lable_event_handler);
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label));
/* Add view to workbench */
rtgui_workbench_add_view(workbench, view);
/* Show view */
rtgui_view_show(view, RT_FALSE);
/* Workbench loop */
rtgui_workbench_event_loop(workbench);
/* Prepare for exit */
rtgui_thread_deregister(rt_thread_self());
rt_mq_delete(mq);
}
void rt_demo_thread_entry(void* parameter)
{
#if 0 //defined(EFM32_USING_ACCEL)
......@@ -530,7 +578,7 @@ void rt_demo_thread_entry(void* parameter)
}
#endif /* defined(EFM32_USING_ETHERNET) */
#if defined(EFM32_USING_LCD)
#if (defined(EFM32_USING_LCD) && !defined(APP_PHOTO_FRAME))
{
rt_kprintf("LCD DEMO start...\n");
......@@ -613,6 +661,109 @@ void rt_demo_thread_entry(void* parameter)
rt_kprintf("LCD DEMO end.\n");
}
#endif
#if defined(APP_PHOTO_FRAME)
{
rt_kprintf("Photo frame DEMO start...\n");
/* find lcd device */
rt_device_t lcd = rt_device_find(LCD_DEVICE_NAME);
if (lcd == RT_NULL)
{
rt_kprintf("Can't find LCD\n");
}
/* read LCD info */
struct rt_device_graphic_info lcd_info;
lcd->control(lcd, RTGRAPHIC_CTRL_GET_INFO, (void *)&lcd_info);
rt_kprintf("LCD size: %dX%d\n", lcd_info.width, lcd_info.height);
/* register panels */
rtgui_rect_t rect;
rect.x1 = 0;
rect.y1 = 0;
rect.x2 = lcd_info.width;
rect.y2 = lcd_info.height;
rtgui_panel_register("main", &rect);
rtgui_panel_set_default_focused("main");
/* Creat thread */
rt_thread_t photo = rt_thread_create(
"photo",
wb_photo,
RT_NULL,
2048,
25,
10);
if (photo != RT_NULL)
{
rt_thread_startup(photo);
}
else
{
rt_kprintf("Create workbench \"photo\" failed!\n");
}
/* start display photos */
DIR* dir = opendir("/photo");
struct photo_event event;
struct dirent* dirent;
rt_uint8_t path[100];
const rt_uint8_t bmp[] = "bmp";
const rt_uint8_t jpeg[] = "jpeg";
event.parent.type = RTGUI_EVENT_COMMAND;
event.parent.user = sizeof(struct photo_event);
event.parent.sender = RT_NULL;
event.parent.ack = RT_NULL;
event.cmd = APP_CMD_PHOTO_FRAME;
event.path = path;
rt_thread_sleep(100);
do
{
/* get a photo */
dirent = readdir(dir);
if (dirent == RT_NULL)
{
break;
}
if ((strcmp(dirent->d_name, ".") == 0) || \
(strcmp(dirent->d_name, "..") == 0))
{
continue;
}
rt_sprintf(path, "%s%c%s", "/photo", PATH_SEPARATOR, dirent->d_name);
/* display it */
if ((rt_strstr(path, ".bmp") != RT_NULL) || \
(rt_strstr(path, ".BMP") != RT_NULL))
{
event.format = &bmp[0];
rt_kprintf("bmp: %s\n", path);
}
else if ((rt_strstr(path, ".jpg") != RT_NULL) || \
(rt_strstr(path, ".JPG") != RT_NULL))
{
event.format = &jpeg[0];
rt_kprintf("jpeg: %s\n", path);
}
else
{
rt_kprintf("skip: %s\n", path);
continue;
}
rtgui_server_post_event((&event.parent), sizeof(event));
rt_thread_sleep(1000);
} while (dirent != RT_NULL);
closedir(dir);
rt_kprintf("Photo frame end.\n");
}
#endif
rt_kprintf("All Demo end.\n");
while(1)
......
......@@ -19,9 +19,11 @@
* 2011-12-09 onelife Add LEUART module support
* 2011-12-14 onelife Add LFXO enabling routine in driver initialization
* function
* 2011-12-15 onelife Add MicroSD enabling routine in driver
* 2011-12-15 onelife Add MicroSD initialization routine in driver
* initialization function
* 2011-12-20 onelife Add LCD driver initialization routine
* 2011-12-29 onelife Add keys and joystick initialization routine in
* driver initialization function
* 2012-02-15 onelife Modify SWO setup function to support giant gecko
******************************************************************************/
/***************************************************************************//**
......@@ -203,32 +205,41 @@ void efm_swo_setup(void)
rt_uint32_t *tpiu_prescaler = (rt_uint32_t *) 0xE0040010;
rt_uint32_t *tpiu_protocol = (rt_uint32_t *) 0xE00400F0;
CMU->HFPERCLKEN0 |= CMU_HFPERCLKEN0_GPIO;
/* Enable Serial wire output pin */
GPIO->ROUTE |= GPIO_ROUTE_SWOPEN;
/* Set location 1 */
GPIO->ROUTE = (GPIO->ROUTE & ~(_GPIO_ROUTE_SWLOCATION_MASK)) | GPIO_ROUTE_SWLOCATION_LOC1;
/* Enable output on pin */
GPIO->P[2].MODEH &= ~(_GPIO_P_MODEH_MODE15_MASK);
GPIO->P[2].MODEH |= GPIO_P_MODEH_MODE15_PUSHPULL;
/* Enable debug clock AUXHFRCO */
CMU->OSCENCMD = CMU_OSCENCMD_AUXHFRCOEN;
while(!(CMU->STATUS & CMU_STATUS_AUXHFRCORDY));
/* Enable trace in core debug */
CoreDebug->DHCSR |= 1;
CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;
/* Enable PC and IRQ sampling output */
*dwt_ctrl = 0x400113FF;
/* Set TPIU prescaler to 16. */
*tpiu_prescaler = 0xf;
/* Set protocol to NRZ */
*tpiu_protocol = 2;
/* Unlock ITM and output data */
ITM->LAR = 0xC5ACCE55;
ITM->TCR = 0x10009;
CMU->HFPERCLKEN0 |= CMU_HFPERCLKEN0_GPIO;
/* Enable Serial wire output pin */
GPIO->ROUTE |= GPIO_ROUTE_SWOPEN;
#if defined(_EFM32_GIANT_FAMILY)
/* Set location 0 */
GPIO->ROUTE = (GPIO->ROUTE & ~(_GPIO_ROUTE_SWLOCATION_MASK)) | GPIO_ROUTE_SWLOCATION_LOC0;
/* Enable output on pin - GPIO Port F, Pin 2 */
GPIO->P[5].MODEL &= ~(_GPIO_P_MODEL_MODE2_MASK);
GPIO->P[5].MODEL |= GPIO_P_MODEL_MODE2_PUSHPULL;
#else
/* Set location 1 */
GPIO->ROUTE = (GPIO->ROUTE & ~(_GPIO_ROUTE_SWLOCATION_MASK)) | GPIO_ROUTE_SWLOCATION_LOC1;
/* Enable output on pin */
GPIO->P[2].MODEH &= ~(_GPIO_P_MODEH_MODE15_MASK);
GPIO->P[2].MODEH |= GPIO_P_MODEH_MODE15_PUSHPULL;
#endif
/* Enable debug clock AUXHFRCO */
CMU->OSCENCMD = CMU_OSCENCMD_AUXHFRCOEN;
while(!(CMU->STATUS & CMU_STATUS_AUXHFRCORDY));
/* Enable trace in core debug */
CoreDebug->DHCSR |= 1;
CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;
/* Enable PC and IRQ sampling output */
*dwt_ctrl = 0x400113FF;
/* Set TPIU prescaler to 16. */
*tpiu_prescaler = 0xf;
/* Set protocol to NRZ */
*tpiu_protocol = 2;
/* Unlock ITM and output data */
ITM->LAR = 0xC5ACCE55;
ITM->TCR = 0x10009;
}
/***************************************************************************//**
......@@ -250,6 +261,10 @@ void rt_hw_board_init(void)
DVK_init();
#elif defined(EFM32GG_DK3750)
DVK_init(DVK_Init_EBI);
/* Disable all DVK interrupts */
DVK_disableInterrupt(BC_INTEN_MASK);
DVK_clearInterruptFlags(BC_INTFLAG_MASK);
#endif
/* NVIC Configuration */
......@@ -370,6 +385,14 @@ void rt_hw_driver_init(void)
#if defined(EFM32_USING_LCD)
efm32_spiLcd_init();
#endif
/* Initialize Keys */
#if defined(EFM32_USING_KEYS)
#if defined(EFM32GG_DK3750)
efm32_hw_keys_init();
#endif
#endif
}
/***************************************************************************//**
......
......@@ -39,6 +39,7 @@
#include <efm32_cmu.h>
#include <efm32_rmu.h>
#include <efm32_dma.h>
#include <efm32_ebi.h>
#include <efm32_rtc.h>
#include <efm32_timer.h>
#include <efm32_gpio.h>
......@@ -155,8 +156,8 @@ extern volatile rt_uint32_t rt_system_status;
#endif
/* SECTION: ADC */
#define ADC_CALI_REF adcRef2V5
#define ADC_CALI_CH adcSingleInpCh5
#define ADC_CALI_REF (adcRef2V5)
#define ADC_CALI_CH (adcSingleInpCh5)
#define ADC_CONVERT_FREQUENCY (7000000)
#if (RT_CONSOLE_DEVICE == EFM_USART0)
......
/***************************************************************************//**
* @file dev_keys.c
* @brief Keys driver of RT-Thread RTOS for EFM32
* COPYRIGHT (C) 2011, RT-Thread Development Team
* @author onelife
* @version 0.4 beta
*******************************************************************************
* @section License
* 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
*******************************************************************************
* @section Change Logs
* Date Author Notes
* 2011-12-29 onelife Initial creation for EFM32GG_DK3750 board
******************************************************************************/
/***************************************************************************//**
* @addtogroup EFM32GG_DK3750
* @{
******************************************************************************/
/* Includes ------------------------------------------------------------------*/
#include "board.h"
#include "hdl_interrupt.h"
#include "dev_keys.h"
#if defined(EFM32_USING_KEYS)
#include <rtgui/event.h>
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
#ifdef EFM32_KEYS_DEBUG
#define keys_debug(format,args...) rt_kprintf(format, ##args)
#else
#define keys_debug(format,args...)
#endif
/* Private function prototypes -----------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
static struct efm32_joy_device joy;
static struct rt_device joy_dev;
static struct rtgui_event_mouse mouse;
static rt_bool_t click;
/* Private functions ---------------------------------------------------------*/
/***************************************************************************//**
* @brief
* Keys interrupt handler
*
* @details
*
* @note
*
* @param[in] device
* Pointer to device descriptor
******************************************************************************/
static void efm32_keys_isr(rt_device_t dev)
{
rt_uint16_t flag, joystick;
/* Clear DEK interrupt */
flag = DVK_getInterruptFlags();
DVK_clearInterruptFlags(flag);
if (flag & BC_INTFLAG_PB)
{
}
if (flag & BC_INTFLAG_DIP)
{
}
if (flag & BC_INTFLAG_JOYSTICK)
{
joystick = DVK_getJoystick();
keys_debug("Keys: joystick %x\n", joystick);
#ifdef RT_USING_RTGUI
switch (joystick)
{
case BC_UIF_JOYSTICK_RIGHT:
joy.x += 2;
if (joy.x > joy.max_x)
{
joy.x = joy.max_x;
}
break;
case BC_UIF_JOYSTICK_LEFT:
joy.x -= 2;
if (joy.x < joy.min_x)
{
joy.x = joy.min_x;
}
break;
case BC_UIF_JOYSTICK_DOWN:
joy.y += 2;
if (joy.y > joy.max_y)
{
joy.y = joy.max_y;
}
break;
case BC_UIF_JOYSTICK_UP:
joy.y -= 2;
if (joy.y < joy.min_y)
{
joy.y = joy.min_y;
}
break;
case BC_UIF_JOYSTICK_CENTER:
break;
default:
break;
}
#endif
if (joystick)
{
if (joystick != BC_UIF_JOYSTICK_CENTER)
{
mouse.parent.type = RTGUI_EVENT_MOUSE_MOTION;
mouse.x = joy.x;
mouse.y = joy.y;
rtgui_server_post_event((&mouse.parent), sizeof(mouse));
rt_timer_start(&joy.timer);
}
else
{
click = RT_TRUE;
mouse.parent.type = RTGUI_EVENT_MOUSE_BUTTON;
mouse.button = RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_DOWN;
rtgui_server_post_event((&mouse.parent), sizeof(mouse));
}
}
else
{
if (click)
{
click = RT_FALSE;
mouse.parent.type = RTGUI_EVENT_MOUSE_BUTTON;
mouse.button = RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_UP;
rtgui_server_post_event((&mouse.parent), sizeof(mouse));
}
else
{
rt_timer_stop(&joy.timer);
}
}
}
if (flag & BC_INTFLAG_AEM)
{
}
}
/***************************************************************************//**
* @brief
* Keys timeout handler
*
* @details
*
* @note
*
* @param[in] param
* Parameter
******************************************************************************/
static void efm32_keys_timer_isr(void *param)
{
rt_uint16_t joystick;
joystick = DVK_getJoystick();
#ifdef RT_USING_RTGUI
switch (joystick)
{
case BC_UIF_JOYSTICK_RIGHT:
joy.x += 2;
if (joy.x > joy.max_x)
{
joy.x = joy.max_x;
}
break;
case BC_UIF_JOYSTICK_LEFT:
joy.x -= 2;
if (joy.x < joy.min_x)
{
joy.x = joy.min_x;
}
break;
case BC_UIF_JOYSTICK_DOWN:
joy.y += 2;
if (joy.y > joy.max_y)
{
joy.y = joy.max_y;
}
break;
case BC_UIF_JOYSTICK_UP:
joy.y -= 2;
if (joy.y < joy.min_y)
{
joy.y = joy.min_y;
}
break;
}
if (joystick)
{
mouse.parent.type = RTGUI_EVENT_MOUSE_MOTION;
mouse.x = joy.x;
mouse.y = joy.y;
rtgui_server_post_event((&mouse.parent), sizeof(mouse));
}
#endif
}
/***************************************************************************//**
* @brief
* Initialize keys device
*
* @details
*
* @note
*
* @param[in] dev
* Pointer to device descriptor
*
* @return
* Error code
******************************************************************************/
static rt_err_t efm32_keys_init (rt_device_t dev)
{
struct rt_device_graphic_info lcd_info;
rt_device_t lcd;
lcd = rt_device_find(LCD_DEVICE_NAME);
if (lcd == RT_NULL)
{
keys_debug("Keys err: Can't find LCD\n");
return -RT_ERROR;
}
lcd->control(lcd, RTGRAPHIC_CTRL_GET_INFO, (void *)&lcd_info);
click = RT_FALSE;
joy.x = 0;
joy.y = 0;
joy.min_x = 0;
joy.max_x = lcd_info.width;
joy.min_y = 0;
joy.max_y = lcd_info.height;
mouse.parent.sender = RT_NULL;
mouse.wid = RT_NULL;
mouse.button = 0;
return RT_EOK;
}
/***************************************************************************//**
* @brief
* Initialize keys related hardware and register joystic device to kernel
*
* @details
*
* @note
*
******************************************************************************/
void efm32_hw_keys_init(void)
{
/* Configure joystick interrupt pin */
GPIO_PinModeSet(KEYS_INT_PORT, KEYS_INT_PIN, gpioModeInputPullFilter, 1);
/* Enable joystick interrupt */
GPIO_IntConfig(KEYS_INT_PORT, KEYS_INT_PIN, true, true, true);
efm32_irq_hook_init_t hook;
hook.type = efm32_irq_type_gpio;
hook.unit = KEYS_INT_PIN;
hook.cbFunc = efm32_keys_isr;
hook.userPtr = RT_NULL;
efm32_irq_hook_register(&hook);
if ((rt_uint8_t)KEYS_INT_PIN % 2)
{
NVIC_ClearPendingIRQ(GPIO_ODD_IRQn);
NVIC_SetPriority(GPIO_ODD_IRQn, EFM32_IRQ_PRI_DEFAULT);
NVIC_EnableIRQ(GPIO_ODD_IRQn);
}
else
{
NVIC_ClearPendingIRQ(GPIO_EVEN_IRQn);
NVIC_SetPriority(GPIO_EVEN_IRQn, EFM32_IRQ_PRI_DEFAULT);
NVIC_EnableIRQ(GPIO_EVEN_IRQn);
}
/* Enable DVK joystick interrupt */
DVK_enableInterrupt(BC_INTEN_JOYSTICK);
rt_timer_init(&joy.timer,
"joy_tmr",
efm32_keys_timer_isr,
RT_NULL,
KEYS_POLL_TIME,
RT_TIMER_FLAG_PERIODIC);
joy_dev.init = efm32_keys_init;
joy_dev.open = RT_NULL;
joy_dev.close = RT_NULL;
joy_dev.read = RT_NULL;
joy_dev.write = RT_NULL;
joy_dev.control = RT_NULL;
joy_dev.user_data = (void *)&joy;
/* register joy stick device */
rt_device_register(&joy_dev, "joy", RT_DEVICE_FLAG_RDWR);
keys_debug("Keys: H/W init OK!\n");
}
#endif /* defined(EFM32_USING_KEYS) */
/***************************************************************************//**
* @}
******************************************************************************/
/***************************************************************************//**
* @file dev_keys.h
* @brief Keys driver of RT-Thread RTOS for EFM32
* COPYRIGHT (C) 2011, RT-Thread Development Team
* @author onelife
* @version 0.4 beta
*******************************************************************************
* @section License
* 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
*******************************************************************************
* @section Change Logs
* Date Author Notes
* 2011-12-29 onelife Initial creation for EFM32GG_DK3750 board
******************************************************************************/
#ifndef __DEV_KEYS_H__
#define __DEV_KEYS_H__
/* Includes ------------------------------------------------------------------*/
/* Exported defines ----------------------------------------------------------*/
#define KEYS_INT_PORT (gpioPortE)
#define KEYS_INT_PIN (0)
#define KEYS_POLL_TIME (RT_TICK_PER_SECOND / 10)
/* Exported types ------------------------------------------------------------*/
struct efm32_joy_device
{
rt_int16_t x, y;
rt_uint16_t min_x, max_x;
rt_uint16_t min_y, max_y;
struct rt_timer timer;
};
/* Exported constants --------------------------------------------------------*/
/* Exported macro ------------------------------------------------------------*/
/* Exported functions ------------------------------------------------------- */
void efm32_hw_keys_init(void);
#endif /* __DEV_KEYS_H__ */
......@@ -11,11 +11,13 @@
*******************************************************************************
* @section Change Logs
* Date Author Notes
* 2011-12-16 onelife Initial creation for EFM32
* 2011-12-16 onelife Initial creation of address mapped method (pixel
* drive) for EFM32GG_DK3750 board
* 2011-12-29 onelife Add direct drive method (frame buffer) support
******************************************************************************/
/***************************************************************************//**
* @addtogroup efm32
* @addtogroup EFM32GG_DK3750
* @{
******************************************************************************/
......@@ -25,6 +27,9 @@
#include "dev_lcd.h"
#if defined(EFM32_USING_LCD)
#if (!defined(LCD_MAPPED) && !defined(LCD_DIRECT))
#error "Unknown LCD access mode"
#endif
#include <rtgui/rtgui.h>
#include <rtgui/driver.h>
......@@ -40,16 +45,20 @@
#endif
/* Private function prototypes -----------------------------------------------*/
#if defined(LCD_MAPPED)
static void efm32_spiLcd_setPixel(rtgui_color_t *c, int x, int y);
static void efm32_spiLcd_getPixel(rtgui_color_t *c, int x, int y);
static void efm32_spiLcd_drawRawHLine(rt_uint8_t *pixels, int x1, int x2, int y);
static void efm32_spiLcd_drawHLine(rtgui_color_t *c, int x1, int x2, int y);
static void efm32_spiLcd_drawVLine(rtgui_color_t *c, int x1, int x2, int y);
#endif
/* Private variables ---------------------------------------------------------*/
static rt_device_t lcd;
static struct rt_device lcd_device;
static rt_bool_t lcdAutoCs = true;
static struct rt_device_graphic_info lcd_info;
#if defined(LCD_MAPPED)
static const struct rtgui_graphic_driver_ops lcd_ops =
{
efm32_spiLcd_setPixel,
......@@ -58,35 +67,8 @@ static const struct rtgui_graphic_driver_ops lcd_ops =
efm32_spiLcd_drawVLine,
efm32_spiLcd_drawRawHLine
};
static rt_bool_t lcdAutoCs = true;
/* Private functions ---------------------------------------------------------*/
/***************************************************************************//**
* @brief
* Set/Clear chip select
*
* @details
*
* @note
*
* @param[in] enable
* Chip select pin setting
******************************************************************************/
static void efm32_spiLcd_cs(rt_uint8_t enable)
{
if (!lcdAutoCs)
{
if (enable)
{
GPIO_PinOutClear(LCD_CS_PORT, LCD_CS_PIN);
}
else
{
GPIO_PinOutSet(LCD_CS_PORT, LCD_CS_PIN);
}
}
}
/***************************************************************************//**
* @brief
* Draw a pixel with specified color
......@@ -129,8 +111,7 @@ static void efm32_spiLcd_setPixel(rtgui_color_t *c, int x, int y)
return;
} while(0);
lcd_debug("LCD err: Set pixel at (%d,%d: %x) failed (%x)!\n",
x, y, *c, ret);
// lcd_debug("LCD err: Set pixel at (%d,%d: %x) failed (%x)!\n", x, y, *c, ret);
}
/***************************************************************************//**
......@@ -273,8 +254,7 @@ static void efm32_spiLcd_drawHLine(rtgui_color_t *c, int x1, int x2, int y)
return;
} while(0);
lcd_debug("LCD err: Draw hline at (%d-%d,%d: %x) failed (%x)!\n",
x1, x2, y, *c, ret);
// lcd_debug("LCD err: Draw hline at (%d-%d,%d: %x) failed (%x)!\n", x1, x2, y, *c, ret);
}
/***************************************************************************//**
......@@ -360,9 +340,9 @@ static void efm32_spiLcd_drawVLine(rtgui_color_t *c, int x , int y1, int y2)
return;
} while(0);
lcd_debug("LCD err: Draw vline at (%d,%d-%d: %x) failed (%x)!\n",
x, y1, y2, *c, ret);
// lcd_debug("LCD err: Draw vline at (%d,%d-%d: %x) failed (%x)!\n", x, y1, y2, *c, ret);
}
#endif
/***************************************************************************//**
* @brief
......@@ -404,6 +384,32 @@ static rt_err_t efm32_spiLcd_control (rt_device_t dev, rt_uint8_t cmd, void *arg
return RT_EOK;
}
/***************************************************************************//**
* @brief
* Set/Clear chip select
*
* @details
*
* @note
*
* @param[in] enable
* Chip select pin setting
******************************************************************************/
static void efm32_spiLcd_cs(rt_uint8_t enable)
{
if (!lcdAutoCs)
{
if (enable)
{
GPIO_PinOutClear(LCD_CS_PORT, LCD_CS_PIN);
}
else
{
GPIO_PinOutSet(LCD_CS_PORT, LCD_CS_PIN);
}
}
}
/***************************************************************************//**
* @brief
* Write data to SSD2119 controller
......@@ -417,7 +423,7 @@ static rt_err_t efm32_spiLcd_control (rt_device_t dev, rt_uint8_t cmd, void *arg
* @note
* It's not possible to read back register value through SSD2119 SPI interface
******************************************************************************/
rt_err_t efm32_spiLed_writeRegister(rt_uint8_t reg, rt_uint16_t data)
rt_err_t efm32_spiLcd_writeRegister(rt_uint8_t reg, rt_uint16_t data)
{
struct efm32_usart_device_t *usart;
rt_uint8_t buf_ins[3];
......@@ -518,20 +524,16 @@ void efm32_spiLcd_init(void)
}
lcd_debug("LCD: Find device %s\n", LCD_USING_DEVICE_NAME);
/* Reconfig speed */
usart = (struct efm32_usart_device_t *)(lcd->user_data);
USART_BaudrateSyncSet(usart->usart_device, 0, EFM32_LCD_SPICLK);
/* Config CS pin */
usart = (struct efm32_usart_device_t *)(lcd->user_data);
if (!(usart->state & USART_STATE_AUTOCS))
{
GPIO_PinModeSet(LCD_CS_PORT, LCD_CS_PIN, gpioModePushPull, 1);
lcdAutoCs = false;
}
// TODO: add another method
/* TFT initialize or reinitialize to Address Mapped Mode
Assumes EBI has been configured correctly in DVK_init(DVK_Init_EBI) */
/* TFT initialize or reinitialize. Assumes EBI has been configured
correctly in DVK_init(DVK_Init_EBI) */
rt_uint32_t freq = SystemCoreClockGet();
rt_uint32_t i;
rt_bool_t warning = RT_FALSE;
......@@ -561,7 +563,8 @@ void efm32_spiLcd_init(void)
{
__NOP();
}
/* Configure display for Direct Drive + SPI mode */
#if defined(LCD_MAPPED)
/* Configure display for address mapped method + 3-wire SPI mode */
DVK_displayControl(DVK_Display_Mode8080);
DVK_displayControl(DVK_Display_PowerEnable);
DVK_displayControl(DVK_Display_ResetRelease);
......@@ -578,6 +581,61 @@ void efm32_spiLcd_init(void)
lcd_debug("LCD err: driver init failed %x\n", ret);
break;
}
#elif defined(LCD_DIRECT)
/* Configure TFT direct drive method from EBI BANK2 */
const EBI_TFTInit_TypeDef tftInit =
{
ebiTFTBank2, /* Select EBI Bank 2 */
ebiTFTWidthHalfWord, /* Select 2-byte (16-bit RGB565) increments */
ebiTFTColorSrcMem, /* Use memory as source for mask/blending */
ebiTFTInterleaveUnlimited, /* Unlimited interleaved accesses */
ebiTFTFrameBufTriggerVSync, /* VSYNC as frame buffer update trigger */
false, /* Drive DCLK from negative edge of internal clock */
ebiTFTMBDisabled, /* No masking and alpha blending enabled */
ebiTFTDDModeExternal, /* Drive from external memory */
ebiActiveLow, /* CS Active Low polarity */
ebiActiveHigh, /* DCLK Active High polarity */
ebiActiveLow, /* DATAEN Active Low polarity */
ebiActiveLow, /* HSYNC Active Low polarity */
ebiActiveLow, /* VSYNC Active Low polarity */
320, /* Horizontal size in pixels */
1, /* Horizontal Front Porch */
30, /* Horizontal Back Porch */
2, /* Horizontal Synchronization Pulse Width */
240, /* Vertical size in pixels */
1, /* Vertical Front Porch */
4, /* Vertical Back Porch */
2, /* Vertical Synchronization Pulse Width */
0x0000, /* Frame Address pointer offset to EBI memory base */
4, /* DCLK Period */
0, /* DCLK Start cycles */
0, /* DCLK Setup cycles */
0, /* DCLK Hold cycles */
};
DVK_enablePeripheral(DVK_TFT);
/* Configure display for Direct Drive + 3-wire SPI mode */
DVK_displayControl(DVK_Display_ModeGeneric);
DVK_displayControl(DVK_Display_PowerEnable);
DVK_displayControl(DVK_Display_ResetRelease);
/* Configure GPIO for EBI and TFT */
/* EBI TFT DCLK/Dot Clock */
GPIO_PinModeSet(gpioPortA, 8, gpioModePushPull, 0);
/* EBI TFT DATAEN */
GPIO_PinModeSet(gpioPortA, 9, gpioModePushPull, 0);
/* EBI TFT VSYNC */
GPIO_PinModeSet(gpioPortA, 10, gpioModePushPull, 0);
/* EBI TFT HSYNC */
GPIO_PinModeSet(gpioPortA, 11, gpioModePushPull, 0);
/* Initialize display */
DMD_init(0, (rt_uint32_t)EBI_BankAddress(EBI_BANK2));
/* Configure EBI TFT direct drive */
EBI_TFTInit(&tftInit);
#endif
}
/* Get LCD geometry */
......@@ -589,14 +647,18 @@ void efm32_spiLcd_init(void)
}
/* Init LCD info */
flag = RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_DMA_TX;
lcd_info.pixel_format = RTGRAPHIC_PIXEL_FORMAT_RGB565P;
lcd_info.bits_per_pixel = 16;
lcd_info.width = geometry->xSize - 1;
lcd_info.height = geometry->ySize - 1;
lcd_info.width = geometry->xSize;
lcd_info.height = geometry->ySize;
#if defined(LCD_MAPPED)
lcd_info.framebuffer = RT_NULL;
flag = RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_DMA_TX;
efm32_spiLcd_register(&lcd_device, LCD_DEVICE_NAME, flag, (void *)&lcd_ops);
#elif defined(LCD_DIRECT)
lcd_info.framebuffer = (rt_uint8_t *)EBI_BankAddress(EBI_BANK2);
efm32_spiLcd_register(&lcd_device, LCD_DEVICE_NAME, flag, RT_NULL);
#endif
/* Set clipping area */
ret = DMD_setClippingArea(0, 0, geometry->xSize, geometry->ySize);
......@@ -607,12 +669,13 @@ void efm32_spiLcd_init(void)
}
/* Read device code */
rt_uint16_t code = 0xFFFF;
#if defined(LCD_MAPPED)
code = DMDIF_readDeviceCode();
#endif
/* Set as rtgui graphic driver */
rtgui_graphic_set_device(&lcd_device);
lcd_debug("LCD: H/W (%x) init OK!\n", code);
lcd_debug("LCD: H/W init OK!\n");
return;
} while(0);
......
......@@ -11,7 +11,8 @@
*******************************************************************************
* @section Change Logs
* Date Author Notes
* 2011-12-16 onelife Initial creation for EFM32
* 2011-12-16 onelife Initial creation of address mapped method (pixel
* drive) for EFM32GG_DK3750 board
******************************************************************************/
#ifndef __DEV_LCD_H__
#define __DEV_LCD_H__
......@@ -20,9 +21,6 @@
/* Exported types ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
/* Exported macro ------------------------------------------------------------*/
#define EFM32_LCD_SPICLK (1000000)
#define SPI_TFT_WriteRegister efm32_spiLed_writeRegister
/* Exported functions ------------------------------------------------------- */
void efm32_spiLcd_init(void);
......
此差异已折叠。
/***************************************************************************//**
* @file drv_iic.h
* @brief IIC driver of RT-Thread RTOS for EFM32
* COPYRIGHT (C) 2011, RT-Thread Development Team
* @author onelife
* @file drv_iic.h
* @brief IIC driver of RT-Thread RTOS for EFM32
* COPYRIGHT (C) 2011, RT-Thread Development Team
* @author onelife
* @version 0.4 beta
*******************************************************************************
* @section License
* The license and distribution terms for this file may be found in the file
* 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
*******************************************************************************
* @section Change Logs
* Date Author Notes
* 2011-01-07 onelife Initial creation for EFM32
* 2011-07-11 onelife Add lock (semaphore) to prevent simultaneously
* Date Author Notes
* 2011-01-07 onelife Initial creation for EFM32
* 2011-07-11 onelife Add lock (semaphore) to prevent simultaneously
* access
* 2011-08-04 onelife Change the usage of the second parameter of Read
* 2011-08-04 onelife Change the usage of the second parameter of Read
* and Write functions from (seldom used) "Offset" to "Slave address"
* 2011-08-04 onelife Add a timer to prevent from forever waiting
* 2011-08-04 onelife Add a timer to prevent from forever waiting
* 2011-12-27 onelife Change IIC read format
******************************************************************************/
#ifndef __DRV_IIC_H__
#define __DRV_IIC_H__
......@@ -25,44 +26,46 @@
/* Exported types ------------------------------------------------------------*/
struct efm32_iic_int_mode_t
{
rt_uint8_t *data_ptr;
rt_uint8_t data_size;
rt_uint32_t read_index, save_index;
rt_uint8_t *data_ptr;
rt_uint8_t data_size;
rt_uint32_t read_index, save_index;
};
struct efm32_iic_device_t
{
/* Counter */
rt_uint32_t counter;
/* Lock */
struct rt_semaphore *lock;
/* Pointer to timer */
rt_timer_t timer;
/* Timeout flag */
volatile rt_bool_t timeout;
/* State */
rt_uint8_t state;
/* Pointer to IIC device structure */
I2C_TypeDef *iic_device;
/* Self address */
rt_uint16_t address;
/* RX structure */
struct efm32_iic_int_mode_t *rx_buffer;
/* Counter */
rt_uint32_t counter;
/* Lock */
struct rt_semaphore *lock;
/* Pointer to timer */
rt_timer_t timer;
/* Timeout flag */
volatile rt_bool_t timeout;
/* State */
rt_uint8_t state;
/* Pointer to IIC device structure */
I2C_TypeDef *iic_device;
/* Self address */
rt_uint16_t address;
/* RX structure */
struct efm32_iic_int_mode_t *rx_buffer;
};
struct efm32_iic_control_t
{
rt_uint8_t config;
rt_uint16_t address;
rt_uint8_t config;
rt_uint16_t address;
};
/* Exported constants --------------------------------------------------------*/
/* Exported macro ------------------------------------------------------------*/
#define IIC_STATE_MASTER (1 << 0)
#define IIC_STATE_MASTER (1 << 0)
#define IIC_STATE_BROADCAST (1 << 1)
//#define IIC_STATE_TX_BUSY (1 << 2)
#define IIC_STATE_RX_BUSY (1 << 3)
#define IIC_TIMEOUT_PERIOD (RT_TICK_PER_SECOND)
//#define IIC_STATE_TX_BUSY (1 << 2)
#define IIC_STATE_RX_BUSY (1 << 3)
#define IIC_TIMEOUT_PERIOD (RT_TICK_PER_SECOND)
#define IIC_OP_READ_ONLY (0xFF)
/* Exported functions --------------------------------------------------------*/
void rt_hw_iic_init(void);
......
......@@ -372,10 +372,10 @@ static rt_size_t rt_usart_read (
void *buffer,
rt_size_t size)
{
rt_err_t err_code;
struct efm32_usart_device_t *usart;
rt_size_t read_len, len;
rt_uint8_t *ptr;
rt_err_t err_code;
rt_size_t read_len;
rt_uint32_t rx_flag, tx_flag, b8_flag;
usart = (struct efm32_usart_device_t *)(dev->user_data);
......@@ -411,9 +411,8 @@ static rt_size_t rt_usart_read (
if (dev->flag & RT_DEVICE_FLAG_INT_RX)
{
rt_size_t len = size;
len = size;
ptr = buffer;
/* interrupt mode Rx */
while (len)
{
......@@ -457,13 +456,6 @@ static rt_size_t rt_usart_read (
}
else
{
struct efm32_usart_device_t *usart;
USART_TypeDef *usart_device;
rt_size_t len;
usart = (struct efm32_usart_device_t *)(dev->user_data);
usart_device = ((struct efm32_usart_device_t *)(dev->user_data))->usart_device;
if (usart->state & USART_STATE_SYNC)
{
/* SPI read */
......@@ -472,67 +464,70 @@ static rt_size_t rt_usart_read (
rt_uint8_t *rx_buf = *((rt_uint8_t **)(buffer + inst_len + 1));
rt_off_t i;
ptr = rx_buf;
ptr = inst_ptr;
len = inst_len;
/* Write instructions */
if (len)
{
if (usart->state & USART_STATE_9BIT)
{
usart_device->CTRL &= ~b8_flag;
usart->usart_device->CTRL &= ~b8_flag;
}
while (len)
{
while (!(usart->usart_device->STATUS & tx_flag));
usart->usart_device->TXDATA = (rt_uint32_t)*inst_ptr;
++inst_ptr; --len;
usart->usart_device->TXDATA = (rt_uint32_t)*(ptr++);
len--;
}
if (usart->state & USART_STATE_9BIT)
{
usart_device->CTRL |= b8_flag;
usart->usart_device->CTRL |= b8_flag;
}
}
/* Flushing RX */
usart_device->CMD = USART_CMD_CLEARRX;
usart->usart_device->CMD = USART_CMD_CLEARRX;
/* Skip some bytes if necessary */
for (i = 0; i < pos; i++)
{
/* dummy write */
while (!(usart_device->STATUS & tx_flag));
usart_device->TXDATA = (rt_uint32_t)0xff;
while (!(usart->usart_device->STATUS & tx_flag));
usart->usart_device->TXDATA = (rt_uint32_t)0xff;
/* dummy read */
while (!(usart_device->STATUS & rx_flag));
*((rt_uint32_t *)0x00) = usart_device->RXDATA;
while (!(usart->usart_device->STATUS & rx_flag));
*((rt_uint32_t *)0x00) = usart->usart_device->RXDATA;
}
ptr = rx_buf;
len = size;
/* Read data */
while (((rt_uint32_t)ptr - (rt_uint32_t)rx_buf) < size)
while (len)
{
/* dummy write */
while (!(usart_device->STATUS & tx_flag));
usart_device->TXDATA = (rt_uint32_t)0xff;
while (!(usart->usart_device->STATUS & tx_flag));
usart->usart_device->TXDATA = (rt_uint32_t)0xff;
/* read a byte of data */
while (!(usart_device->STATUS & rx_flag));
*ptr = usart_device->RXDATA & 0xff;
ptr ++;
while (!(usart->usart_device->STATUS & rx_flag));
*(ptr++) = usart->usart_device->RXDATA & 0xff;
len--;
}
}
else
{
ptr = buffer;
len = size;
/* polling mode */
while ((rt_uint32_t)ptr - (rt_uint32_t)buffer < size)
while (len)
{
while (usart_device->STATUS & rx_flag)
while (usart->usart_device->STATUS & rx_flag)
{
*ptr = usart_device->RXDATA & 0xff;
ptr ++;
*(ptr++) = usart->usart_device->RXDATA & 0xff;
}
}
len--;
}
read_len = size;
read_len = size - len;
}
/* Unlock device */
......@@ -540,6 +535,7 @@ static rt_size_t rt_usart_read (
/* set error code */
rt_set_errno(err_code);
return read_len;
}
......@@ -573,9 +569,10 @@ static rt_size_t rt_usart_write (
rt_size_t size)
{
rt_err_t err_code;
rt_size_t write_size = 0;
struct efm32_usart_device_t* usart = (struct efm32_usart_device_t*)(dev->user_data);
rt_uint8_t *tx_buf;
rt_size_t read_len, len;
rt_uint8_t *ptr;
rt_size_t write_size = 0;
rt_uint32_t tx_flag, b8_flag;
#if defined(UART_PRESENT)
......@@ -610,23 +607,25 @@ static rt_size_t rt_usart_write (
{ /* SPI write */
rt_uint8_t inst_len = *((rt_uint8_t *)buffer);
rt_uint8_t *inst_ptr = (rt_uint8_t *)(buffer + 1);
tx_buf = *((rt_uint8_t **)(buffer + inst_len + 1));
rt_uint8_t *tx_buf = *((rt_uint8_t **)(buffer + inst_len + 1));
ptr = inst_ptr;
len = inst_len;
/* Write instructions */
if (inst_len)
if (len)
{
if (usart->state & USART_STATE_9BIT)
{
usart->usart_device->CTRL &= ~b8_flag;
}
if ((dev->flag & RT_DEVICE_FLAG_DMA_TX) && (inst_len > 2))
if ((dev->flag & RT_DEVICE_FLAG_DMA_TX) && (len > 2))
{ /* DMA mode Tx */
struct efm32_usart_dma_mode_t *dma_tx;
usart_debug("USART: DMA TX INS (%d)\n", inst_len);
usart_debug("USART: DMA TX INS (%d)\n", len);
dma_tx = (struct efm32_usart_dma_mode_t *)(usart->tx_mode);
dma_tx->data_ptr = (rt_uint32_t *)inst_ptr;
dma_tx->data_size = inst_len;
dma_tx->data_ptr = (rt_uint32_t *)ptr;
dma_tx->data_size = len;
usart->state |= USART_STATE_TX_BUSY;
DMA_ActivateBasic(
......@@ -634,8 +633,8 @@ static rt_size_t rt_usart_write (
true,
false,
(void *)&(usart->usart_device->TXDATA),
(void *)inst_ptr,
(rt_uint32_t)(inst_len - 1));
(void *)ptr,
(rt_uint32_t)(len - 1));
/* Wait, otherwise the TX buffer is overwrite */
// TODO: This function blocks the process => goto low power mode?
// if (usart->state & USART_STATE_CONSOLE)
......@@ -652,15 +651,12 @@ static rt_size_t rt_usart_write (
}
else
{ /* polling mode */
rt_uint8_t *ptr = (rt_uint8_t *)inst_ptr;
rt_size_t len = inst_len;
usart_debug("USART: Polling TX INS (%d)\n", inst_len);
usart_debug("USART: Polling TX INS (%d)\n", len);
while (len)
{
while (!(usart->usart_device->STATUS & tx_flag));
usart->usart_device->TXDATA = (rt_uint32_t)*ptr;
++ptr; --len;
usart->usart_device->TXDATA = (rt_uint32_t)*(ptr++);
len--;
}
}
if (usart->state & USART_STATE_9BIT)
......@@ -668,30 +664,33 @@ static rt_size_t rt_usart_write (
usart->usart_device->CTRL |= b8_flag;
}
}
ptr = tx_buf;
}
else
{
tx_buf = (rt_uint8_t *)buffer;
ptr = (rt_uint8_t *)buffer;
}
len = size;
/* Write data */
if (dev->flag & RT_DEVICE_FLAG_STREAM)
{
if (*(tx_buf + size - 1) == '\n')
if (*(ptr + len - 1) == '\n')
{
*(tx_buf + size - 1) = '\r';
*(tx_buf + size++) = '\n';
*(tx_buf + size) = 0;
*(ptr + len - 1) = '\r';
*(ptr + len++) = '\n';
*(ptr + len) = 0;
}
}
if ((dev->flag & RT_DEVICE_FLAG_DMA_TX) && (size > 2))
if ((dev->flag & RT_DEVICE_FLAG_DMA_TX) && (len > 2))
{ /* DMA mode Tx */
struct efm32_usart_dma_mode_t *dma_tx;
usart_debug("USART: DMA TX data (%d)\n", size);
usart_debug("USART: DMA TX data (%d)\n", len);
dma_tx = (struct efm32_usart_dma_mode_t *)(usart->tx_mode);
dma_tx->data_ptr = (rt_uint32_t *)tx_buf;
dma_tx->data_size = size;
dma_tx->data_ptr = (rt_uint32_t *)ptr;
dma_tx->data_size = len;
usart->state |= USART_STATE_TX_BUSY;
DMA_ActivateBasic(
......@@ -699,8 +698,8 @@ static rt_size_t rt_usart_write (
true,
false,
(void *)&(usart->usart_device->TXDATA),
(void *)tx_buf,
(rt_uint32_t)(size - 1));
(void *)ptr,
(rt_uint32_t)(len - 1));
/* Wait, otherwise the TX buffer is overwrite */
// TODO: This function blocks the process => goto low power mode?
......@@ -719,18 +718,15 @@ static rt_size_t rt_usart_write (
}
else
{ /* polling mode */
rt_uint8_t *ptr = (rt_uint8_t *)tx_buf;
rt_size_t len = size;
usart_debug("USART: Polling TX data (%d)\n", size);
usart_debug("USART: Polling TX data (%d)\n", len);
while (len)
{
while (!(usart->usart_device->STATUS & tx_flag));
usart->usart_device->TXDATA = (rt_uint32_t)*ptr;
++ptr; --len;
usart->usart_device->TXDATA = (rt_uint32_t)*(ptr++);
len--;
}
write_size = (rt_size_t)ptr - (rt_size_t)tx_buf;
write_size = size - len;
}
/* Unlock device */
......@@ -738,6 +734,7 @@ static rt_size_t rt_usart_write (
/* set error code */
rt_set_errno(err_code);
return write_size;
}
......@@ -1396,7 +1393,7 @@ static struct efm32_usart_device_t *rt_hw_usart_unit_init(
}
if (callback)
{
rt_free(usart);
rt_free(callback);
}
#if defined(UART_PRESENT)
......@@ -1436,7 +1433,7 @@ void rt_hw_usart_init(void)
#ifdef RT_USART0_SYNC_MODE
config |= USART_STATE_SYNC;
config |= (RT_USART0_SYNC_MODE & SYNC_SETTING_MASK) << SYNC_SETTING_SHIFT;
#if (!(RT_USART0_SYNC_MODE & EFM32_SPI_MASTER))
#if (!((RT_USART0_SYNC_MODE << SYNC_SETTING_SHIFT) & USART_STATE_MASTER))
flag |= RT_DEVICE_FLAG_INT_RX;
#endif
#else
......@@ -1485,7 +1482,7 @@ void rt_hw_usart_init(void)
#ifdef RT_USART1_SYNC_MODE
config |= USART_STATE_SYNC;
config |= (RT_USART1_SYNC_MODE & SYNC_SETTING_MASK) << SYNC_SETTING_SHIFT;
#if (!(RT_USART1_SYNC_MODE & EFM32_SPI_MASTER))
#if (!((RT_USART1_SYNC_MODE << SYNC_SETTING_SHIFT) & USART_STATE_MASTER))
flag |= RT_DEVICE_FLAG_INT_RX;
#endif
#else
......@@ -1535,7 +1532,7 @@ void rt_hw_usart_init(void)
#ifdef RT_USART2_SYNC_MODE
config |= USART_STATE_SYNC;
config |= (RT_USART1_SYNC_MODE & SYNC_SETTING_MASK) << SYNC_SETTING_SHIFT;
#if (!(RT_USART2_SYNC_MODE & EFM32_SPI_MASTER))
#if (!((RT_USART2_SYNC_MODE << SYNC_SETTING_SHIFT) & USART_STATE_MASTER))
flag |= RT_DEVICE_FLAG_INT_RX;
#endif
#else
......
import rtconfig
from building import *
if rtconfig.EFM32_LCD == 'Mapped':
if rtconfig.EFM32_LCD == 'LCD_MAPPED':
src = Split("""
dmd/ssd2119/dmd_ssd2119_16bit.c
dmd/ssd2119/dmdif_ssd2119_ebi16.c
......@@ -10,5 +10,13 @@ if rtconfig.EFM32_LCD == 'Mapped':
CPPPATH.append(GetCurrentDir() + '/dmd/ssd2119')
group = DefineGroup('EFM32GG_DK3750_LCD', src, depend = [''], CPPPATH = CPPPATH)
Return('group')
elif rtconfig.EFM32_LCD == 'LCD_DIRECT':
src = Split("""
dmd/ssd2119/dmd_ssd2119_direct.c
""")
CPPPATH = [GetCurrentDir()]
CPPPATH.append(GetCurrentDir() + '/dmd/ssd2119')
group = DefineGroup('EFM32GG_DK3750_LCD', src, depend = [''], CPPPATH = CPPPATH)
Return('group')
else:
Return('')
/***************************************************************************//**
* @file tftspi.h
* @brief Stub functions of EFM32 LCD driver
* COPYRIGHT (C) 2011, RT-Thread Development Team
* @author onelife
* @version 0.4 beta
*******************************************************************************
* @section License
* 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
*******************************************************************************
* @section Change Logs
* Date Author Notes
* 2011-12-20 onelife Initial creation for EFM32
******************************************************************************/
#ifndef __TFTSPI_H__
#define __TFTSPI_H__
/* Includes ------------------------------------------------------------------*/
/* Exported types ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
/* Exported macro ------------------------------------------------------------*/
#define SPI_TFT_Init()
#define SPI_TFT_WriteRegister(reg, data) efm32_spiLcd_writeRegister(reg, data)
/* Exported functions ------------------------------------------------------- */
extern rt_err_t efm32_spiLcd_writeRegister(rt_uint8_t reg, rt_uint16_t data);
#endif /* __TFTSPI_H__ */
......@@ -83,8 +83,8 @@
#include "dev_misc.h"
#if defined(RT_USING_LWIP) && defined(EFM32_USING_ETH_HTTPD)
#include "lwip\tcp.h"
#include "lwip\ip_addr.h"
#include "lwip/tcp.h"
#include "lwip/ip_addr.h"
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
......
......@@ -55,7 +55,7 @@
//#define EFM32_SDCARD_DEBUG
#define EFM32_ETHERNET_DEBUG
#define EFM32_LCD_DEBUG
//#define EFM32_KEYS_DEBUG
/* Using Hook */
//#define RT_USING_HOOK
......@@ -106,7 +106,7 @@
#if defined(EFM32GG_DK3750_USING_LEUART1)
#define RT_USING_LEUART1 (0x0UL)
#define RT_LEUART1_NAME "debug0"
#define RT_LEUART1_USING_DMA (0x0UL)
//#define RT_LEUART1_USING_DMA (0x0UL)
#else
#define RT_USING_UART1 (0x2UL)
#define RT_UART1_NAME "debug"
......@@ -228,6 +228,7 @@
#define EFM32_USING_SPISD /* MicroSD card */
//#define EFM32_USING_ETHERNET /* Ethernet controller */
#define EFM32_USING_LCD /* TFT LCD */
#define EFM32_USING_KEYS /* Keys and joystick */
#endif
#if defined(EFM32_USING_ACCEL)
......@@ -333,7 +334,7 @@
/* SECTION: RTGUI support */
#if defined(EFM32_USING_LCD)
#define LCD_USING_DEVICE_NAME RT_USART1_NAME
#define LCD_DEVICE_NAME "spiLcd"
#define LCD_DEVICE_NAME "lcd"
/* using RTGUI support */
#define RT_USING_RTGUI
......@@ -354,10 +355,11 @@
/* use small size in RTGUI */
/* #define RTGUI_USING_SMALL_SIZE */
/* use mouse cursor */
/* #define RTGUI_USING_MOUSE_CURSOR */
#define RTGUI_USING_MOUSE_CURSOR
/* RTGUI image options */
#define RTGUI_IMAGE_XPM
//#define RTGUI_IMAGE_JPEG
#define RTGUI_IMAGE_TJPGD
//#define RTGUI_IMAGE_PNG
#define RTGUI_IMAGE_BMP
#endif /* defined(EFM32_USING_LCD) */
......
......@@ -8,7 +8,7 @@ if CROSS_TOOL == 'gcc':
EXEC_PATH = 'C:\Program Files (x86)\CodeSourcery\Sourcery G++ Lite\bin'
#EXEC_PATH = 'C:\Program Files (x86)\yagarto\bin'
BUILD = 'run'
BUILD = 'debug'
# EFM32_BOARD = 'EFM32_G8XX_STK'
# EFM32_BOARD = 'EFM32_GXXX_DK'
EFM32_BOARD = 'EFM32GG_DK3750'
......@@ -22,8 +22,8 @@ elif EFM32_BOARD == 'EFM32_GXXX_DK':
elif EFM32_BOARD == 'EFM32GG_DK3750':
EFM32_FAMILY = 'Giant Gecko'
EFM32_TYPE = 'EFM32GG990F1024'
EFM32_LCD = 'Mapped'
# EFM32_LCD = 'Direct'
# EFM32_LCD = 'LCD_MAPPED'
EFM32_LCD = 'LCD_DIRECT'
if PLATFORM == 'gcc':
# toolchains
......
/***************************************************************************//**
* @file interrupt.c
* @file startup.c
* @brief This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2011, RT-Thread Development Team
* @author Bernard, onelife
......@@ -23,7 +23,6 @@
/* Includes ------------------------------------------------------------------*/
#include "board.h"
#include <rtthread.h>
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
......@@ -39,15 +38,9 @@ extern int __bss_end;
/* Private variables ---------------------------------------------------------*/
/* External function prototypes ----------------------------------------------*/
extern int rt_application_init(void);
#ifdef RT_USING_FINSH
extern void finsh_system_init(void);
extern void finsh_set_device(const char* device);
#endif
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
#ifdef DEBUG
#ifdef RT_DEBUG
/***************************************************************************//**
* @brief
* Reports the name of the source file and the source line number where the
......@@ -63,7 +56,7 @@ extern void finsh_set_device(const char* device);
* @param[in] line
* Assert error line source number
******************************************************************************/
void assert_failed(u8* file, u32 line)
void assert_failed(uint8_t * file, uint32_t line)
{
rt_kprintf("\n\r Wrong parameter value detected on\r\n");
rt_kprintf(" file %s\r\n", file);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册