SmartCar-V1/Code/bsp/src/bsp_led.c

254 lines
6.7 KiB
C
Raw Normal View History

/*
*********************************************************************************************************
*
* : LED指示灯驱动模块
* : bsp_led.c
* : V1.0
* : LED指示灯
*
* :
*
* V1.0 2013-02-01 armfly
*
* Copyright (C), 2013-2014, www.armfly.com
*
*********************************************************************************************************
*/
#include "bsp.h"
/*
STM32-X4STM32-F4开发板
GPIO定义和 IsKeyDown1 - IsKeyDown8
LED指示灯个数小于4个LED全部定义为和第1个LED一样
*/
#ifdef STM32F103C8T6 /* STM32F103C8T6 开发板 */
/*
STM32F103C8 LED口线分配
LED1 : PC13 ()
LED2 :
LED3 :
LED4 :
*/
/* 按键口对应的RCC时钟 */
#define RCC_ALL_LED (RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOB)
#define GPIO_PORT_LED1 GPIOC
#define GPIO_PIN_LED1 GPIO_Pin_13
#define GPIO_PORT_LED2 GPIOB
#define GPIO_PIN_LED2 GPIO_Pin_9
// #define GPIO_PORT_LED2 GPIOE
// #define GPIO_PIN_LED2 GPIO_Pin_3
// #define GPIO_PORT_LED3 GPIOE
// #define GPIO_PIN_LED3 GPIO_Pin_4
// #define GPIO_PORT_LED4 GPIOE
// #define GPIO_PIN_LED4 GPIO_Pin_5
#endif
#ifdef STM32_F4
/* STM32_F4 */
/*
STM32-V5 LED口线分配
LD1 : PI10/TP_NCS ()
LD2 : PF7/NRF24L01_CSN ()
LD3 : PF8/SF_CS ()
LD4 : PC2/NRF905_CSN/VS1053_XCS ()
*/
/* 按键口对应的RCC时钟 */
#define RCC_ALL_LED (RCC_AHB1Periph_GPIOC | RCC_AHB1Periph_GPIOF | RCC_AHB1Periph_GPIOI)
#define GPIO_PORT_LED1 GPIOI
#define GPIO_PIN_LED1 GPIO_Pin_10
#define GPIO_PORT_LED2 GPIOF
#define GPIO_PIN_LED2 GPIO_Pin_7
#define GPIO_PORT_LED3 GPIOF
#define GPIO_PIN_LED3 GPIO_Pin_8
#define GPIO_PORT_LED4 GPIOC
#define GPIO_PIN_LED4 GPIO_Pin_2
#endif
/*
*********************************************************************************************************
* : bsp_InitLed
* : LED指示灯相关的GPIO, bsp_Init()
* :
* :
*********************************************************************************************************
*/
void bsp_InitLed(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* 打开GPIO时钟 */
RCC_APB2PeriphClockCmd(RCC_ALL_LED, ENABLE);
/*
LED指示灯GPIO为推挽输出模式
GPIO设置为输出时GPIO输出寄存器的值缺省是0LED点亮.
GPIO为输出前LED指示灯
*/
bsp_LedOff(LED1);
bsp_LedOff(LED2);
/* LED 1*/
GPIO_InitStructure.GPIO_Pin = GPIO_PIN_LED1;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; /* 设为 输出推挽模式 */
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; /* IO口最大速度 */
GPIO_Init(GPIO_PORT_LED1, &GPIO_InitStructure);
/* LED 2*/
GPIO_InitStructure.GPIO_Pin = GPIO_PIN_LED2;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; /* 设为 输出推挽模式 */
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; /* IO口最大速度 */
GPIO_Init(GPIO_PORT_LED2, &GPIO_InitStructure);
}
/*
*********************************************************************************************************
* : bsp_LedOn
* : LED指示灯
* : _no : 1 - 4
* :
*********************************************************************************************************
*/
void bsp_LedOn(uint8_t _no)
{
_no--;
if (_no == (LED1-1))
{
// STM32F103C8T6开发板 1是亮0是灭
// GPIO_PORT_LED1->BRR = GPIO_PIN_LED1;
GPIO_PORT_LED1->BSRR |= GPIO_PIN_LED1;
}
// else if (_no == 1)
// {
// GPIO_PORT_LED2->BSRRH = GPIO_PIN_LED2;
// }
// else if (_no == 2)
// {
// GPIO_PORT_LED3->BSRRH = GPIO_PIN_LED3;
// }
// else if (_no == 3)
// {
// GPIO_PORT_LED4->BSRRH = GPIO_PIN_LED4;
// }
}
/*
*********************************************************************************************************
* : bsp_LedOff
* : LED指示灯
* : _no : 1 - 4
* :
*********************************************************************************************************
*/
void bsp_LedOff(uint8_t _no)
{
_no--;
if (_no == (LED1-1))
{
// STM32F103C8T6开发板 1是亮0是灭
GPIO_PORT_LED1->BRR = GPIO_PIN_LED1;
}
// else if (_no == 1)
// {
// GPIO_PORT_LED2->BSRRL = GPIO_PIN_LED2;
// }
// else if (_no == 2)
// {
// GPIO_PORT_LED3->BSRRL = GPIO_PIN_LED3;
// }
// else if (_no == 3)
// {
// GPIO_PORT_LED4->BSRRL = GPIO_PIN_LED4;
// }
}
/*
*********************************************************************************************************
* : bsp_LedToggle
* : LED指示灯
* : _no : 1 - 4
* :
*********************************************************************************************************
*/
void bsp_LedToggle(uint8_t _no)
{
if (_no == (LED1))
{
GPIO_PORT_LED1->ODR ^= GPIO_PIN_LED1;
}
else if (_no == 2)
{
GPIO_PORT_LED2->ODR ^= GPIO_PIN_LED2;
}
// else if (_no == 3)
// {
// GPIO_PORT_LED3->ODR ^= GPIO_PIN_LED3;
// }
// else if (_no == 4)
// {
// GPIO_PORT_LED4->ODR ^= GPIO_PIN_LED4;
// }
}
/*
*********************************************************************************************************
* : bsp_IsLedOn
* : LED指示灯是否已经点亮
* : _no : 1 - 4
* : 10
*********************************************************************************************************
*/
uint8_t bsp_IsLedOn(uint8_t _no)
{
if (_no == (LED1-1))
{
if ((GPIO_PORT_LED1->ODR & GPIO_PIN_LED1) == 0)
{
return 1;
}
return 0;
}
// else if (_no == 2)
// {
// if ((GPIO_PORT_LED2->ODR & GPIO_PIN_LED2) == 0)
// {
// return 1;
// }
// return 0;
// }
// else if (_no == 3)
// {
// if ((GPIO_PORT_LED3->ODR & GPIO_PIN_LED3) == 0)
// {
// return 1;
// }
// return 0;
// }
// else if (_no == 4)
// {
// if ((GPIO_PORT_LED4->ODR & GPIO_PIN_LED4) == 0)
// {
// return 1;
// }
// return 0;
// }
return 0;
}
/***************************** 安富莱电子 www.armfly.com (END OF FILE) *********************************/