95 lines
2.3 KiB
C
Raw Normal View History

2021-10-24 10:19:26 +08:00
/***********************************************
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>LED<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD>޸<EFBFBD><EFBFBD><EFBFBD> <EFBFBD>޸<EFBFBD><EFBFBD><EFBFBD>Ϣ
--20210409 Magnin <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>޸<EFBFBD>
************************************************/
/**************<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>***************
LED1 -------------------------- PC12
LED2 -------------------------- PC11
LED3 -------------------------- PC10
LED4 -------------------------- PA15
***********************************************/
#include "led.h"
#include "cm32m101a_conf.h"
#include "share.h"
//<2F><><EFBFBD><EFBFBD>LED<45>Ʋ<EFBFBD><C6B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
typedef struct{
sp_led_t led;
GPIO_Module* GPIOx;
uint16_t Pin;
}sp_led_param_t;
//<2F><><EFBFBD><EFBFBD>LED<45>Ʋ<EFBFBD><C6B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
static sp_led_param_t ledParam[] = {
{SP_LED1,GPIOC,GPIO_PIN_12},
{SP_LED2,GPIOC,GPIO_PIN_11},
{SP_LED3,GPIOC,GPIO_PIN_10},
{SP_LED4,GPIOA,GPIO_PIN_15},
};
//<2F><>ʼ<EFBFBD><CABC>LED
void Led_Init(void)
{
GPIO_InitType GPIO_InitStructure;
//<2F><><EFBFBD><EFBFBD>GPIO<49>˿<EFBFBD>ʱ<EFBFBD><CAB1>
RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA, ENABLE);
RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOC, ENABLE);
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
GPIO_InitStructure.GPIO_Current = GPIO_DC_8mA; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С
GPIO_InitStructure.GPIO_Pull = GPIO_No_Pull; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
for(uint8_t i = 0;i < ARRAY_SIZE(ledParam);i++)
{
GPIO_InitStructure.Pin = ledParam[i].Pin;
GPIO_InitPeripheral(ledParam[i].GPIOx, &GPIO_InitStructure);
//<2F><>ʼ<EFBFBD><CABC><EFBFBD>ر<EFBFBD>LED
Led_SetState(ledParam[i].led,SP_LED_STATE_CLOSE);
}
}
//<2F><><EFBFBD><EFBFBD>LED״̬
void Led_SetState(sp_led_t led,sp_led_State_t state)
{
for(uint8_t i = 0;i < ARRAY_SIZE(ledParam);i++)
{
if(ledParam[i].led == led) //<2F>ҵ<EFBFBD><D2B5><EFBFBD>ӦLED
{
if(state == SP_LED_STATE_OPEN) GPIO_SetBits(ledParam[i].GPIOx,ledParam[i].Pin); //<2F>ߵ<EFBFBD>ƽ<EFBFBD><C6BD><EFBFBD><EFBFBD>
else GPIO_ResetBits(ledParam[i].GPIOx,ledParam[i].Pin);
}
}
}
//<2F><>תLED
void Led_Toggles(sp_led_t led)
{
for(uint8_t i = 0;i < ARRAY_SIZE(ledParam);i++)
{
if(ledParam[i].led == led) //<2F>ҵ<EFBFBD><D2B5><EFBFBD>ӦLED
{
ledParam[i].GPIOx->POD ^= ledParam[i].Pin; //<2F><>ת<EFBFBD><D7AA>ƽ
}
}
}
//<2F><>ȡLED״̬
sp_led_State_t Led_GetState(sp_led_t led)
{
for(uint8_t i = 0;i < ARRAY_SIZE(ledParam);i++)
{
if(ledParam[i].led == led) //<2F>ҵ<EFBFBD><D2B5><EFBFBD>ӦLED
{
//<2F><>ȡLED״̬
if(GPIO_ReadOutputDataBit(ledParam[i].GPIOx,ledParam[i].Pin)) return SP_LED_STATE_OPEN;
else return SP_LED_STATE_CLOSE;
}
}
//LED<45><44><EFBFBD><EFBFBD><EFBFBD>ڷ<EFBFBD><DAB7>عر<D8B9>
return SP_LED_STATE_CLOSE;
}