2024-07-11 06:58:55 +00:00
|
|
|
|
/*
|
|
|
|
|
* gpio.c
|
|
|
|
|
*
|
|
|
|
|
* Created on: 2024<EFBFBD><EFBFBD>7<EFBFBD><EFBFBD>1<EFBFBD><EFBFBD>
|
|
|
|
|
* 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;
|
2024-07-13 02:12:30 +00:00
|
|
|
|
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2024-07-11 06:58:55 +00:00
|
|
|
|
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
|
|
|
|
GPIO_Init(GPIOA, &GPIO_InitStructure);
|
2024-08-17 03:14:19 +00:00
|
|
|
|
GPIO_WriteBit(GPIOA, GPIO_Pin_15, SET); //<2F>ر<EFBFBD>mos<6F>ܣ<EFBFBD><DCA3><EFBFBD><F2BFAAB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2024-07-11 06:58:55 +00:00
|
|
|
|
|
|
|
|
|
/* G_FFMOS_CON2 --> PB3 */
|
|
|
|
|
RCC_PB2PeriphClockCmd(RCC_PB2Periph_GPIOB, ENABLE);
|
|
|
|
|
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
|
|
|
|
|
GPIO_Init(GPIOB, &GPIO_InitStructure);
|
2024-08-17 03:14:19 +00:00
|
|
|
|
GPIO_WriteBit(GPIOB, GPIO_Pin_3, SET);
|
2024-07-11 06:58:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
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; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
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; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
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; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
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; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
GPIO_Init(DSG_PROT_GPIO, &GPIO_InitStructure);
|
|
|
|
|
|
|
|
|
|
/* GPIOB ----> EXTI_Line2 */
|
|
|
|
|
EXTI_InitTypeDef EXTI_InitStructure;
|
|
|
|
|
GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource2); //ָ<><D6B8><EFBFBD>ж<EFBFBD>/<2F>¼<EFBFBD><C2BC>ߵ<EFBFBD><DFB5><EFBFBD><EFBFBD><EFBFBD>Դ<EFBFBD><D4B4>ʵ<EFBFBD><CAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>趨<EFBFBD>ⲿ<EFBFBD>ж<EFBFBD><D0B6><EFBFBD><EFBFBD>üĴ<C3BC><C4B4><EFBFBD>AFIO_EXTICRx<52><78>ֵ<EFBFBD><D6B5><EFBFBD>˴<EFBFBD>ΪPB2
|
|
|
|
|
EXTI_InitStructure.EXTI_Line = EXTI_Line2; //EXTI<54>ж<EFBFBD>/<2F>¼<EFBFBD><C2BC><EFBFBD>ѡ<EFBFBD>˴<F1A3ACB4>ѡ<EFBFBD><D1A1>EXTI_Line2
|
|
|
|
|
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; //EXTIģʽѡ<CABD>˴<F1A3ACB4>ѡ<EFBFBD><D1A1>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>ģʽ
|
|
|
|
|
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; //EXTI<54><49><EFBFBD>ش<EFBFBD><D8B4><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD>˴<EFBFBD>ѡ<EFBFBD><D1A1>Ϊ<EFBFBD>½<EFBFBD><C2BD>ش<EFBFBD><D8B4><EFBFBD>
|
|
|
|
|
EXTI_InitStructure.EXTI_LineCmd = ENABLE; //ʹ<><CAB9>EXTI<54><49>
|
|
|
|
|
EXTI_Init(&EXTI_InitStructure);
|
|
|
|
|
|
|
|
|
|
NVIC_InitTypeDef NVIC_InitStructure;
|
|
|
|
|
NVIC_InitStructure.NVIC_IRQChannel = EXTI2_IRQn; //ʹ<><CAB9>EXTI2<49>ж<EFBFBD>ͨ<EFBFBD><CDA8>
|
|
|
|
|
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ռ<EFBFBD><D5BC><EFBFBD>ȼ<EFBFBD>Ϊ1
|
|
|
|
|
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȼ<EFBFBD>Ϊ2
|
|
|
|
|
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //ʹ<><CAB9><EFBFBD>ⲿ<EFBFBD>ж<EFBFBD>ͨ<EFBFBD><CDA8>
|
|
|
|
|
NVIC_Init(&NVIC_InitStructure); //<2F>ж<EFBFBD><D0B6><EFBFBD><EFBFBD>ȼ<EFBFBD><C8BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void EXTI2_IRQHandler(void)
|
|
|
|
|
{
|
|
|
|
|
if(EXTI_GetITStatus(EXTI_Line2)==SET) { //EXTI_GetITStatus<75><73><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD>жϱ<D0B6>־λ״̬<D7B4><CCAC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>EXTI<54>߲<EFBFBD><DFB2><EFBFBD><EFBFBD>ж<EFBFBD><D0B6><EFBFBD>SET<45><54><EFBFBD><EFBFBD><EFBFBD><EFBFBD>RESET
|
|
|
|
|
printf("Run at EXTI\r\n");
|
2024-07-13 02:12:30 +00:00
|
|
|
|
GPIO_WriteBit(DSG_PROT_GPIO, DSG_PROT_PIN, RESET);
|
2024-07-11 06:58:55 +00:00
|
|
|
|
EXTI_ClearITPendingBit(EXTI_Line2); //<2F><><EFBFBD><EFBFBD><EFBFBD>жϱ<D0B6>־λ
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-17 03:14:19 +00:00
|
|
|
|
void EnPowerSupply_Init(void)
|
2024-07-22 06:20:24 +00:00
|
|
|
|
{
|
|
|
|
|
RCC_PB2PeriphClockCmd(RCC_PB2Periph_GPIOB, ENABLE);
|
|
|
|
|
GPIO_InitTypeDef GPIO_InitStructure;
|
2024-08-17 03:14:19 +00:00
|
|
|
|
GPIO_InitStructure.GPIO_Pin = EnPowerSupply_PIN;
|
2024-07-22 06:20:24 +00:00
|
|
|
|
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
2024-08-17 03:14:19 +00:00
|
|
|
|
GPIO_Init(EnPowerSupply_GPIO, &GPIO_InitStructure);
|
2024-07-11 06:58:55 +00:00
|
|
|
|
|
2024-08-17 03:14:19 +00:00
|
|
|
|
GPIO_WriteBit(EnPowerSupply_GPIO, EnPowerSupply_PIN, RESET);
|
2024-07-22 06:20:24 +00:00
|
|
|
|
}
|
2024-07-11 06:58:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|