mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-15 17:02:53 +08:00
86 lines
2.2 KiB
C
86 lines
2.2 KiB
C
/***********************************************
|
||
* <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̵<EFBFBD><CCB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
|
||
* <20><><EFBFBD><EFBFBD> <09><EFBFBD><DEB8><EFBFBD> <09><EFBFBD><DEB8><EFBFBD>Ϣ
|
||
--20210409 Magnin <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
************************************************/
|
||
|
||
/**************<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>***************
|
||
RELAY -------------------------- PD2
|
||
***********************************************/
|
||
#include "relay.h"
|
||
#include "share.h"
|
||
#include "cm32m101a_conf.h"
|
||
|
||
//<2F><><EFBFBD><EFBFBD>Relay<61>Ʋ<EFBFBD><C6B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
typedef struct{
|
||
sp_relay_t relay;
|
||
GPIO_Module* GPIOx;
|
||
uint16_t Pin;
|
||
}sp_led_param_t;
|
||
|
||
//<2F><><EFBFBD><EFBFBD>Relay<61>Ʋ<EFBFBD><C6B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
static sp_led_param_t relayParam[] = {
|
||
{SP_RELAY1,GPIOD,GPIO_PIN_2}
|
||
};
|
||
//<2F><>ʼ<EFBFBD><CABC>Relay
|
||
void Relay_Init(void)
|
||
{
|
||
GPIO_InitType GPIO_InitStructure;
|
||
//<2F><><EFBFBD><EFBFBD>GPIO<49>˿<EFBFBD>ʱ<EFBFBD><CAB1>
|
||
RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOD, ENABLE);
|
||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
GPIO_InitStructure.GPIO_Current = GPIO_DC_4mA; //<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(relayParam);i++)
|
||
{
|
||
GPIO_InitStructure.Pin = relayParam[i].Pin;
|
||
GPIO_InitPeripheral(relayParam[i].GPIOx, &GPIO_InitStructure);
|
||
//<2F><>ʼ<EFBFBD><CABC><EFBFBD>ر<EFBFBD>Relay
|
||
Relay_SetState(relayParam[i].relay,SP_RELAY_STATE_CLOSE);
|
||
}
|
||
|
||
}
|
||
//<2F><><EFBFBD><EFBFBD>Relay״̬
|
||
void Relay_SetState(sp_relay_t relay,sp_relay_state_t state)
|
||
{
|
||
for(uint8_t i = 0;i < ARRAY_SIZE(relayParam);i++)
|
||
{
|
||
if(relayParam[i].relay == relay) //<2F>ҵ<EFBFBD><D2B5><EFBFBD>ӦLED
|
||
{
|
||
if(state == SP_RELAY_STATE_OPEN) GPIO_SetBits(relayParam[i].GPIOx,relayParam[i].Pin); //<2F>ߵ<EFBFBD>ƽ<EFBFBD><C6BD><EFBFBD><EFBFBD>
|
||
else GPIO_ResetBits(relayParam[i].GPIOx,relayParam[i].Pin);
|
||
}
|
||
}
|
||
}
|
||
//<2F><>תRelay
|
||
void Relay_Toggles(sp_relay_t relay)
|
||
{
|
||
for(uint8_t i = 0;i < ARRAY_SIZE(relayParam);i++)
|
||
{
|
||
if(relayParam[i].relay == relay) //<2F>ҵ<EFBFBD><D2B5><EFBFBD>ӦLED
|
||
{
|
||
relayParam[i].GPIOx->POD ^= relayParam[i].Pin; //<2F><>ת<EFBFBD><D7AA>ƽ
|
||
}
|
||
}
|
||
|
||
}
|
||
//<2F><>ȡRelayD״̬
|
||
sp_relay_state_t Relay_GetState(sp_relay_t relay)
|
||
{
|
||
for(uint8_t i = 0;i < ARRAY_SIZE(relayParam);i++)
|
||
{
|
||
if(relayParam[i].relay == relay) //<2F>ҵ<EFBFBD><D2B5><EFBFBD>ӦRelay
|
||
{
|
||
//<2F><>ȡRelay״̬
|
||
if(GPIO_ReadOutputDataBit(relayParam[i].GPIOx,relayParam[i].Pin)) return SP_RELAY_STATE_OPEN;
|
||
else return SP_RELAY_STATE_CLOSE;
|
||
}
|
||
}
|
||
//Relay<61><79><EFBFBD><EFBFBD><EFBFBD>ڷ<EFBFBD><DAB7>عر<D8B9>
|
||
return SP_RELAY_STATE_CLOSE;
|
||
}
|
||
|
||
|