2009-12-25 20:18:53 +08:00
|
|
|
/*
|
|
|
|
* File : led.c
|
|
|
|
* This file is part of RT-Thread RTOS
|
|
|
|
* COPYRIGHT (C) 2009, RT-Thread Development Team
|
|
|
|
*
|
|
|
|
* The license and distribution terms for this file may be
|
|
|
|
* found in the file LICENSE in this distribution or at
|
|
|
|
* http://www.rt-thread.org/license/LICENSE
|
|
|
|
*
|
|
|
|
* Change Logs:
|
|
|
|
* Date Author Notes
|
|
|
|
* 2009-01-05 Bernard the first version
|
|
|
|
*/
|
2009-10-23 13:44:36 +08:00
|
|
|
#include <rtthread.h>
|
|
|
|
#include <stm32f10x.h>
|
|
|
|
|
2010-03-18 13:51:39 +08:00
|
|
|
#ifdef STM32_SIMULATOR
|
|
|
|
#define led1_rcc RCC_APB2Periph_GPIOA
|
|
|
|
#define led1_gpio GPIOA
|
|
|
|
#define led1_pin (GPIO_Pin_5)
|
|
|
|
|
|
|
|
#define led2_rcc RCC_APB2Periph_GPIOA
|
|
|
|
#define led2_gpio GPIOA
|
|
|
|
#define led2_pin (GPIO_Pin_6)
|
|
|
|
#else
|
2009-10-23 13:44:36 +08:00
|
|
|
#define led1_rcc RCC_APB2Periph_GPIOF
|
|
|
|
#define led1_gpio GPIOF
|
|
|
|
#define led1_pin (GPIO_Pin_6 | GPIO_Pin_7)
|
|
|
|
|
|
|
|
#define led2_rcc RCC_APB2Periph_GPIOF
|
|
|
|
#define led2_gpio GPIOF
|
|
|
|
#define led2_pin (GPIO_Pin_8)
|
2010-03-18 13:51:39 +08:00
|
|
|
#endif
|
2009-10-23 13:44:36 +08:00
|
|
|
|
|
|
|
void rt_hw_led_init(void)
|
|
|
|
{
|
|
|
|
GPIO_InitTypeDef GPIO_InitStructure;
|
|
|
|
|
|
|
|
RCC_APB2PeriphClockCmd(led1_rcc|led2_rcc,ENABLE);
|
|
|
|
|
|
|
|
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
|
|
|
|
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
|
|
|
|
|
|
|
GPIO_InitStructure.GPIO_Pin = led1_pin;
|
|
|
|
GPIO_Init(led1_gpio, &GPIO_InitStructure);
|
|
|
|
|
|
|
|
GPIO_InitStructure.GPIO_Pin = led2_pin;
|
|
|
|
GPIO_Init(led2_gpio, &GPIO_InitStructure);
|
|
|
|
}
|
|
|
|
|
|
|
|
void rt_hw_led_on(rt_uint32_t n)
|
|
|
|
{
|
|
|
|
switch (n)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
GPIO_SetBits(led1_gpio, led1_pin);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
GPIO_SetBits(led2_gpio, led2_pin);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void rt_hw_led_off(rt_uint32_t n)
|
|
|
|
{
|
|
|
|
switch (n)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
GPIO_ResetBits(led1_gpio, led1_pin);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
GPIO_ResetBits(led2_gpio, led2_pin);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef RT_USING_FINSH
|
|
|
|
#include <finsh.h>
|
2009-10-23 14:16:38 +08:00
|
|
|
static rt_uint8_t led_inited = 0;
|
2009-10-23 13:44:36 +08:00
|
|
|
void led(rt_uint32_t led, rt_uint32_t value)
|
|
|
|
{
|
2009-10-23 14:16:38 +08:00
|
|
|
/* init led configuration if it's not inited. */
|
|
|
|
if (!led_inited)
|
|
|
|
{
|
|
|
|
rt_hw_led_init();
|
|
|
|
led_inited = 1;
|
|
|
|
}
|
|
|
|
|
2009-10-23 13:44:36 +08:00
|
|
|
if ( led == 0 )
|
|
|
|
{
|
|
|
|
/* set led status */
|
|
|
|
switch (value)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
rt_hw_led_off(0);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
rt_hw_led_on(0);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( led == 1 )
|
|
|
|
{
|
|
|
|
/* set led status */
|
|
|
|
switch (value)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
rt_hw_led_off(1);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
rt_hw_led_on(1);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
FINSH_FUNCTION_EXPORT(led, set led[0 - 1] on[1] or off[0].)
|
|
|
|
#endif
|
|
|
|
|