118 lines
4.3 KiB
C
118 lines
4.3 KiB
C
/*
|
||
* gpio.c
|
||
*
|
||
* Created on: 2024年7月1日
|
||
* Author: psx
|
||
*/
|
||
|
||
#include "gpio.h"
|
||
|
||
void G_FFMOS_CON_Init(void)
|
||
{
|
||
/* G_FFMOS_CON1 --> PA15 */
|
||
RCC_PB2PeriphClockCmd(RCC_PB2Periph_GPIOA, ENABLE);
|
||
GPIO_InitTypeDef GPIO_InitStructure;
|
||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15;
|
||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //推挽输出
|
||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||
GPIO_Init(GPIOA, &GPIO_InitStructure);
|
||
GPIO_WriteBit(GPIOA, GPIO_Pin_15, SET); //关闭mos管,打开光伏输入
|
||
|
||
/* G_FFMOS_CON2 --> PB3 */
|
||
RCC_PB2PeriphClockCmd(RCC_PB2Periph_GPIOB, ENABLE);
|
||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
|
||
GPIO_Init(GPIOB, &GPIO_InitStructure);
|
||
GPIO_WriteBit(GPIOB, GPIO_Pin_3, SET);
|
||
}
|
||
|
||
void RUN_LED_Init(void)
|
||
{
|
||
RCC_PB2PeriphClockCmd(RCC_PB2Periph_GPIOA, ENABLE);
|
||
GPIO_InitTypeDef GPIO_InitStructure;
|
||
GPIO_InitStructure.GPIO_Pin = RUN_LED_PIN;
|
||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //推挽输出
|
||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||
GPIO_Init(RUN_LED_GPIO, &GPIO_InitStructure);
|
||
}
|
||
|
||
void WDI_INPUT_Init(void)
|
||
{
|
||
RCC_PB2PeriphClockCmd(RCC_PB2Periph_GPIOC, ENABLE);
|
||
GPIO_InitTypeDef GPIO_InitStructure;
|
||
GPIO_InitStructure.GPIO_Pin = WDI_INPUT_PIN;
|
||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //推挽输出
|
||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||
GPIO_Init(WDI_INPUT_GPIO, &GPIO_InitStructure);
|
||
}
|
||
|
||
void BEEP_Init(void)
|
||
{
|
||
RCC_PB2PeriphClockCmd(RCC_PB2Periph_GPIOA, ENABLE);
|
||
GPIO_InitTypeDef GPIO_InitStructure;
|
||
GPIO_InitStructure.GPIO_Pin = BEEP_PIN;
|
||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //推挽输出
|
||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||
GPIO_Init(BEEP_GPIO, &GPIO_InitStructure);
|
||
}
|
||
|
||
void POW_OUT_CON_Init(void)
|
||
{
|
||
RCC_PB2PeriphClockCmd(RCC_PB2Periph_GPIOB, ENABLE);
|
||
GPIO_InitTypeDef GPIO_InitStructure;
|
||
GPIO_InitStructure.GPIO_Pin = POW_OUT_CON_PIN;
|
||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //推挽输出
|
||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||
GPIO_Init(POW_OUT_CON_GPIO, &GPIO_InitStructure);
|
||
}
|
||
|
||
void EXTI2_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
|
||
|
||
void DSG_PROT_Init(void)
|
||
{
|
||
RCC_PB2PeriphClockCmd(RCC_PB2Periph_AFIO | RCC_PB2Periph_GPIOB, ENABLE);
|
||
GPIO_InitTypeDef GPIO_InitStructure;
|
||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
|
||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; //上拉输入
|
||
GPIO_Init(DSG_PROT_GPIO, &GPIO_InitStructure);
|
||
|
||
/* GPIOB ----> EXTI_Line2 */
|
||
EXTI_InitTypeDef EXTI_InitStructure;
|
||
GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource2); //指定中断/事件线的输入源,实际上是设定外部中断配置寄存器AFIO_EXTICRx的值,此处为PB2
|
||
EXTI_InitStructure.EXTI_Line = EXTI_Line2; //EXTI中断/事件线选择,此处选择EXTI_Line2
|
||
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; //EXTI模式选择,此处选择为产生中断模式
|
||
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; //EXTI边沿触发事件,此处选择为下降沿触发
|
||
EXTI_InitStructure.EXTI_LineCmd = ENABLE; //使能EXTI线
|
||
EXTI_Init(&EXTI_InitStructure);
|
||
|
||
NVIC_InitTypeDef NVIC_InitStructure;
|
||
NVIC_InitStructure.NVIC_IRQChannel = EXTI2_IRQn; //使能EXTI2中断通道
|
||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; //设置抢占优先级为1
|
||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2; //设置子优先级为2
|
||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //使能外部中断通道
|
||
NVIC_Init(&NVIC_InitStructure); //中断优先级分组初始化
|
||
}
|
||
|
||
void EXTI2_IRQHandler(void)
|
||
{
|
||
if(EXTI_GetITStatus(EXTI_Line2)==SET) { //EXTI_GetITStatus用来获取中断标志位状态,如果EXTI线产生中断则返回SET,否则返回RESET
|
||
printf("Run at EXTI\r\n");
|
||
GPIO_WriteBit(DSG_PROT_GPIO, DSG_PROT_PIN, RESET);
|
||
EXTI_ClearITPendingBit(EXTI_Line2); //清除中断标志位
|
||
}
|
||
}
|
||
|
||
void EnPowerSupply_Init(void)
|
||
{
|
||
RCC_PB2PeriphClockCmd(RCC_PB2Periph_GPIOB, ENABLE);
|
||
GPIO_InitTypeDef GPIO_InitStructure;
|
||
GPIO_InitStructure.GPIO_Pin = EnPowerSupply_PIN;
|
||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //推挽输出
|
||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||
GPIO_Init(EnPowerSupply_GPIO, &GPIO_InitStructure);
|
||
|
||
GPIO_WriteBit(EnPowerSupply_GPIO, EnPowerSupply_PIN, RESET);
|
||
}
|
||
|
||
|
||
|