154 lines
4.3 KiB
C
154 lines
4.3 KiB
C
#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输出寄存器的值缺省是0,因此会驱动LED点亮.
|
||
这是我不希望的,因此在改变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);
|
||
}
|