mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-08-18 20:48:41 +08:00
*** 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
This commit is contained in:
@@ -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')
|
||||
|
||||
+306
-155
File diff suppressed because it is too large
Load Diff
+48
-25
@@ -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;
|
||||
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;
|
||||
|
||||
while(!(CMU->STATUS & CMU_STATUS_AUXHFRCORDY));
|
||||
/* 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;
|
||||
|
||||
/* Enable trace in core debug */
|
||||
CoreDebug->DHCSR |= 1;
|
||||
CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;
|
||||
while(!(CMU->STATUS & CMU_STATUS_AUXHFRCORDY));
|
||||
|
||||
/* 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;
|
||||
/* 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
|
||||
|
||||
}
|
||||
|
||||
/***************************************************************************//**
|
||||
|
||||
+3
-2
@@ -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)
|
||||
|
||||
@@ -0,0 +1,324 @@
|
||||
/***************************************************************************//**
|
||||
* @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) */
|
||||
/***************************************************************************//**
|
||||
* @}
|
||||
******************************************************************************/
|
||||
@@ -0,0 +1,40 @@
|
||||
/***************************************************************************//**
|
||||
* @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__ */
|
||||
+113
-50
@@ -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);
|
||||
|
||||
|
||||
+2
-4
@@ -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);
|
||||
|
||||
|
||||
+528
-517
File diff suppressed because it is too large
Load Diff
+38
-35
@@ -1,22 +1,23 @@
|
||||
/***************************************************************************//**
|
||||
* @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);
|
||||
|
||||
+70
-73
@@ -372,10 +372,10 @@ static rt_size_t rt_usart_read (
|
||||
void *buffer,
|
||||
rt_size_t size)
|
||||
{
|
||||
struct efm32_usart_device_t *usart;
|
||||
rt_uint8_t *ptr;
|
||||
rt_err_t err_code;
|
||||
rt_size_t read_len;
|
||||
struct efm32_usart_device_t *usart;
|
||||
rt_size_t read_len, len;
|
||||
rt_uint8_t *ptr;
|
||||
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
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
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('')
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
/***************************************************************************//**
|
||||
* @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__ */
|
||||
+2
-2
@@ -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
|
||||
|
||||
+3
-10
@@ -1,5 +1,5 @@
|
||||
/***************************************************************************//**
|
||||
* @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);
|
||||
|
||||
Reference in New Issue
Block a user