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

154 lines
4.3 KiB
C
Raw Normal View History

#include "bsp_gpio.h"
#include "stm32f10x_gpio.h"
#include "stm32f10x_rcc.h"
#include "stm32f10x.h"
#include "stdint.h"
#include "public_diy.h"
/* led define */
/*
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
/*************************************************************************************
* @brief led
* @param[in/out] led_no
*
* @warning ,
* @note
*************************************************************************************/
void bsp_led_on(uint8_t led_no)
{
if (led_no == (LED1))
{
// STM32F103C8T6开发板 1是亮0是灭
// GPIO_PORT_LED1->BRR = GPIO_PIN_LED1;
GPIO_PORT_LED1->BSRR |= GPIO_PIN_LED1;
}
if (led_no == (LED2))
{
// STM32F103C8T6开发板 1是亮0是灭
GPIO_PORT_LED2->BSRR |= 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;
// }
}
/*************************************************************************************
* @brief Led
* @param[in/out] _no
*
* @warning ,
* @note
*************************************************************************************/
void bsp_led_off(uint8_t led_no)
{
if(led_no == LED1)
{
// STM32F103C8T6开发板 1是亮0是灭
GPIO_PORT_LED1->BRR = GPIO_PIN_LED1;
}
else if(led_no == LED2)
{
GPIO_PORT_LED2->BRR = GPIO_PIN_LED2;
}
else
{
;
}
}
/*************************************************************************************
* @brief led状态切换
* @param[in/out] led_no
*
* @warning ,
* @note
*************************************************************************************/
void bsp_led_toggle(uint8_t led_no)
{
if (led_no == LED1))
{
GPIO_PORT_LED1->ODR ^= GPIO_PIN_LED1;
}
else if (led_no == LED2)
{
GPIO_PORT_LED2->ODR ^= GPIO_PIN_LED2;
}
else
{
;
}
}
/*************************************************************************************
* @brief led当前的电平状态
* @return uint8_t
*
* @warning ,
* @note
*************************************************************************************/
uint8_t bsp_get_led_ttlState(void)
{
if(led_no == (LED1))
{
// STM32F103C8T6开发板 1是亮0是灭
// GPIO_PORT_LED1->BRR = GPIO_PIN_LED1;
GPIO_PORT_LED1->BSRR |= GPIO_PIN_LED1;
}
if(led_no == (LED2))
{
// STM32F103C8T6开发板 1是亮0是灭
GPIO_PORT_LED2->BSRR |= GPIO_PIN_LED2;
}
}
/*************************************************************************************
* @brief Led
*
* @warning ,
* @note
*************************************************************************************/
void bsp_InitLed(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* 打开GPIO时钟 */
RCC_APB2PeriphClockCmd(RCC_ALL_LED, ENABLE);
/*
LED指示灯GPIO为推挽输出模式
GPIO设置为输出时GPIO输出寄存器的值缺省是0LED点亮.
GPIO为输出前LED指示灯
*/
bsp_led_off(LED1);
bsp_led_off(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);
}