463 lines
12 KiB
C
463 lines
12 KiB
C
/**
|
||
******************************************************************************
|
||
* @file
|
||
* @author
|
||
* @version
|
||
* @date
|
||
* @brief
|
||
* @function List:
|
||
******************************************************************************
|
||
* @attention
|
||
*
|
||
*
|
||
* <h2><center>© COPYRIGHT 2021 </center></h2>
|
||
******************************************************************************
|
||
* @History:
|
||
* @Author:
|
||
* @Data:
|
||
* @Version:
|
||
*/
|
||
|
||
#include "gpio.h"
|
||
#include "nvic.h"
|
||
#include "wdog.h"
|
||
#include "can_cfg.h"
|
||
#include "CanNm_Cfg.h"
|
||
#include "low_power_app.h"
|
||
|
||
static void gpio_ext_interrupt_init(void);
|
||
static void gpio_ext_interrupt_de_init(void);
|
||
static void gpio_pwm_init(void);
|
||
static void gpio_key_init(void);
|
||
static void gpio_adc_init(void);
|
||
static void gpio_can_init(void);
|
||
static void gpio_test_init(void);
|
||
static void gpio_idle_init(void);
|
||
|
||
typedef struct
|
||
{
|
||
u8 state;
|
||
u8 test[8];
|
||
}gpio_cfg_s;
|
||
static gpio_cfg_s g_gpio_cfg;
|
||
|
||
//void gpio_isr_callback(void *device, uint32_t wpara, uint32_t lpara);
|
||
|
||
/**
|
||
* @brief GPIO中断函数
|
||
* @param void
|
||
* @retval void
|
||
*/
|
||
void GPIO_IRQHandler(void)
|
||
{
|
||
g_gpio_cfg.test[0]++;
|
||
//can RX 中断
|
||
if(FL_GPIO_IsActiveFlag_EXTI(GPIO, FL_GPIO_EXTI_LINE_1))
|
||
{
|
||
(void)gpio_wakeup_flag_set();
|
||
g_gpio_cfg.test[1]++;
|
||
#ifdef CAN_AUTOSAR_NM_EN
|
||
//cannm_app_set_event(CANNM_EVENT_EXT_KEY);
|
||
#endif
|
||
FL_GPIO_ClearFlag_EXTI(GPIO, FL_GPIO_EXTI_LINE_1);
|
||
}
|
||
|
||
}
|
||
|
||
|
||
//普通输出io的配置
|
||
static void gpio_output_init(void)
|
||
{
|
||
FL_GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||
|
||
GPIO_InitStruct.pin = O_12V_CTR_PIN_MASK;
|
||
GPIO_InitStruct.mode = FL_GPIO_MODE_OUTPUT;
|
||
GPIO_InitStruct.outputType = FL_GPIO_OUTPUT_PUSHPULL;
|
||
GPIO_InitStruct.pull = FL_DISABLE;
|
||
GPIO_InitStruct.remapPin = FL_DISABLE;
|
||
GPIO_InitStruct.analogSwitch = FL_DISABLE;
|
||
//FL_GPIO_Init(O_MDT_CTR_GPIO, &GPIO_InitStruct);
|
||
//GPIO_InitStruct.pin = O_12V_CTR_PIN_MASK ;
|
||
FL_GPIO_Init(O_12V_CTR_GPIO, &GPIO_InitStruct);
|
||
GPIO_InitStruct.pin = O_5V_CTR_PIN_MASK ;
|
||
FL_GPIO_Init(O_5V_CTR_GPIO, &GPIO_InitStruct);
|
||
GPIO_InitStruct.pin = O_KIT_CTR_PIN_MASK ;
|
||
FL_GPIO_Init(O_KIT_CTR_GPIO, &GPIO_InitStruct);
|
||
GPIO_InitStruct.pin = O_DEN_CTR_PIN_MASK;
|
||
FL_GPIO_Init(O_DEN_CTR_GPIO, &GPIO_InitStruct);
|
||
|
||
//O_MDT_CTR_ENABLE();
|
||
O_12V_CTR_ENABLE();
|
||
O_5V_CTR_ENABLE();
|
||
O_KIT_CTR_ENABLE();
|
||
O_MDT_PWM_DISABLE();
|
||
O_DEN_CTR_ENABLE();
|
||
}
|
||
|
||
|
||
/**
|
||
* gpio_lin_init
|
||
*
|
||
* @param[in] none
|
||
* @return none
|
||
*
|
||
* @brief init led control gpio
|
||
*
|
||
*/
|
||
static void gpio_pwm_init(void)
|
||
{
|
||
FL_GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||
/* PA4 背景灯 PWM*/
|
||
GPIO_InitStruct.pin = GPIO_PIN4_MASK;
|
||
GPIO_InitStruct.mode = FL_GPIO_MODE_DIGITAL;
|
||
GPIO_InitStruct.outputType = FL_GPIO_OUTPUT_PUSHPULL;
|
||
GPIO_InitStruct.pull = FL_DISABLE;
|
||
GPIO_InitStruct.analogSwitch = FL_DISABLE;
|
||
|
||
GPIO_InitStruct.remapPin = 0;
|
||
FL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||
|
||
|
||
/* PB5 左拨片 低亮指示灯 */
|
||
GPIO_InitStruct.remapPin = 1;
|
||
GPIO_InitStruct.pin = GPIO_PIN5_MASK ;
|
||
FL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||
|
||
/* PB6 右拨片 低亮指示灯 */
|
||
GPIO_InitStruct.remapPin = 1;
|
||
GPIO_InitStruct.pin = GPIO_PIN6_MASK ;
|
||
FL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||
|
||
/* PC0 右拨片 背景灯 */
|
||
GPIO_InitStruct.remapPin = 0;
|
||
GPIO_InitStruct.pin = GPIO_PIN0_MASK ;
|
||
FL_GPIO_Init(GPIOC, &GPIO_InitStruct);
|
||
|
||
/* PC1 左拨片 背景灯 */
|
||
GPIO_InitStruct.remapPin = 0;
|
||
GPIO_InitStruct.pin = GPIO_PIN1_MASK ;
|
||
FL_GPIO_Init(GPIOC, &GPIO_InitStruct);
|
||
|
||
/* PB4 左拨片 高亮指示灯 */
|
||
GPIO_InitStruct.remapPin = 1;
|
||
GPIO_InitStruct.pin = GPIO_PIN4_MASK ;
|
||
FL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||
|
||
/* PB7 右拨片 高亮指示灯 */
|
||
GPIO_InitStruct.remapPin = 1;
|
||
GPIO_InitStruct.pin = GPIO_PIN7_MASK ;
|
||
FL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||
|
||
/* PB10 电加热输出 */
|
||
GPIO_InitStruct.remapPin = 1;
|
||
GPIO_InitStruct.pin = GPIO_PIN10_MASK ;
|
||
FL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||
}
|
||
|
||
/**
|
||
* GPIO_ADC_Init
|
||
*
|
||
* @param[in] none
|
||
* @return none
|
||
*
|
||
* @brief init key control gpio
|
||
*
|
||
*/
|
||
static void gpio_key_init(void)
|
||
{
|
||
|
||
FL_GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||
|
||
GPIO_InitStruct.pin = KEY_1_PIN_MASK;
|
||
GPIO_InitStruct.mode = FL_GPIO_MODE_INPUT;
|
||
GPIO_InitStruct.outputType = FL_GPIO_OUTPUT_PUSHPULL;
|
||
GPIO_InitStruct.pull = FL_DISABLE;
|
||
GPIO_InitStruct.remapPin = FL_DISABLE;
|
||
GPIO_InitStruct.analogSwitch = FL_DISABLE;
|
||
FL_GPIO_Init(KEY_1_GPIO, &GPIO_InitStruct);
|
||
GPIO_InitStruct.pin = KEY_2_PIN_MASK;
|
||
FL_GPIO_Init(KEY_2_GPIO, &GPIO_InitStruct);
|
||
GPIO_InitStruct.pin = KEY_3_PIN_MASK;
|
||
FL_GPIO_Init(KEY_3_GPIO, &GPIO_InitStruct);
|
||
GPIO_InitStruct.pin = KEY_4_PIN_MASK;
|
||
FL_GPIO_Init(KEY_4_GPIO, &GPIO_InitStruct);
|
||
GPIO_InitStruct.pin = KEY_5_PIN_MASK;
|
||
FL_GPIO_Init(KEY_5_GPIO, &GPIO_InitStruct);
|
||
GPIO_InitStruct.pin = KEY_6_PIN_MASK;
|
||
FL_GPIO_Init(KEY_6_GPIO, &GPIO_InitStruct);
|
||
GPIO_InitStruct.pin = KEY_7_PIN_MASK;
|
||
FL_GPIO_Init(KEY_7_GPIO, &GPIO_InitStruct);
|
||
GPIO_InitStruct.pin = KEY_1_ENCODE_PIN_MASK;
|
||
FL_GPIO_Init(KEY_1_ENCODE_GPIO, &GPIO_InitStruct);
|
||
|
||
GPIO_InitStruct.pin = KEY_2_ENCODE_PIN_MASK;
|
||
FL_GPIO_Init(KEY_2_ENCODE_GPIO, &GPIO_InitStruct);
|
||
|
||
|
||
}
|
||
|
||
|
||
/**
|
||
* GPIO_ADC_Init
|
||
*
|
||
* @param[in] none
|
||
* @return none
|
||
*
|
||
* @brief init led control gpio
|
||
*
|
||
*/
|
||
static void gpio_adc_init(void)
|
||
{
|
||
|
||
FL_GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||
/* 配置引脚为模拟功能 */
|
||
/* ADC ADC_1 引脚 PD1 */
|
||
GPIO_InitStruct.pin = ADC_CHANNEL_0_PIN_MASK;
|
||
GPIO_InitStruct.mode = FL_GPIO_MODE_ANALOG;
|
||
GPIO_InitStruct.outputType = FL_GPIO_OUTPUT_PUSHPULL;
|
||
GPIO_InitStruct.pull = FL_DISABLE;
|
||
GPIO_InitStruct.remapPin = FL_DISABLE;
|
||
GPIO_InitStruct.analogSwitch = FL_DISABLE;
|
||
FL_GPIO_Init(ADC_CHANNEL_0_GPIO, &GPIO_InitStruct);
|
||
|
||
GPIO_InitStruct.pin = ADC_CHANNEL_1_PIN_MASK;
|
||
FL_GPIO_Init(ADC_CHANNEL_1_GPIO, &GPIO_InitStruct);
|
||
|
||
GPIO_InitStruct.pin = ADC_CHANNEL_2_PIN_MASK;
|
||
FL_GPIO_Init(ADC_CHANNEL_2_GPIO, &GPIO_InitStruct);
|
||
|
||
#if 0
|
||
GPIO_InitStruct.pin = ADC_CHANNEL_3_PIN_MASK;
|
||
FL_GPIO_Init(ADC_CHANNEL_3_GPIO, &GPIO_InitStruct);
|
||
|
||
GPIO_InitStruct.pin = ADC_CHANNEL_4_PIN_MASK;
|
||
FL_GPIO_Init(ADC_CHANNEL_4_GPIO, &GPIO_InitStruct);
|
||
#endif
|
||
|
||
GPIO_InitStruct.pin = ADC_CHANNEL_5_PIN_MASK;
|
||
FL_GPIO_Init(ADC_CHANNEL_5_GPIO, &GPIO_InitStruct);
|
||
|
||
GPIO_InitStruct.pin = ADC_CHANNEL_6_PIN_MASK;
|
||
FL_GPIO_Init(ADC_CHANNEL_6_GPIO, &GPIO_InitStruct);
|
||
#if 0
|
||
GPIO_InitStruct.pin = ADC_CHANNEL_7_PIN_MASK;
|
||
FL_GPIO_Init(ADC_CHANNEL_7_GPIO, &GPIO_InitStruct);
|
||
#endif
|
||
|
||
GPIO_InitStruct.pin = ADC_CHANNEL_8_PIN_MASK;
|
||
FL_GPIO_Init(ADC_CHANNEL_8_GPIO, &GPIO_InitStruct);
|
||
|
||
}
|
||
|
||
|
||
/**
|
||
* GPIO_ADC_Init
|
||
*
|
||
* @param[in] none
|
||
* @return none
|
||
*
|
||
* @brief init led control gpio
|
||
*
|
||
*/
|
||
static void gpio_can_init(void)
|
||
{
|
||
FL_GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||
/* PC2.3配置成模拟功能,外接XTHF */
|
||
/*-----------------------------------GPIO初始化---------------------------------------*/
|
||
GPIO_InitStruct.pin = CAN0_TX_PIN_MASK; /* 48PIN开发板引脚定义 */
|
||
GPIO_InitStruct.mode = FL_GPIO_MODE_DIGITAL;
|
||
GPIO_InitStruct.pull = FL_ENABLE;
|
||
GPIO_InitStruct.outputType = FL_GPIO_OUTPUT_PUSHPULL;
|
||
GPIO_InitStruct.remapPin = FL_DISABLE;
|
||
GPIO_InitStruct.analogSwitch = FL_DISABLE;
|
||
FL_GPIO_Init(CAN0_TX_GPIO, &GPIO_InitStruct); /* 48PIN开发板引脚定义 */
|
||
|
||
GPIO_InitStruct.pin = CAN0_RX_PIN_MASK; /* 48PIN开发板引脚定义 */
|
||
GPIO_InitStruct.mode = FL_GPIO_MODE_DIGITAL;
|
||
GPIO_InitStruct.pull = FL_ENABLE;
|
||
GPIO_InitStruct.outputType = FL_GPIO_OUTPUT_PUSHPULL;
|
||
GPIO_InitStruct.remapPin = FL_DISABLE;
|
||
GPIO_InitStruct.analogSwitch = FL_DISABLE;
|
||
FL_GPIO_Init(CAN0_RX_GPIO, &GPIO_InitStruct); /* 48PIN开发板引脚定义 */
|
||
|
||
/* STB引脚初始化 */
|
||
GPIO_InitStruct.pin = CAN0_STB_PIN_MASK; /* 48PIN开发板引脚定义 */
|
||
GPIO_InitStruct.mode = FL_GPIO_MODE_OUTPUT;
|
||
GPIO_InitStruct.pull = FL_ENABLE;
|
||
GPIO_InitStruct.outputType = FL_GPIO_OUTPUT_PUSHPULL;
|
||
GPIO_InitStruct.remapPin = FL_DISABLE;
|
||
GPIO_InitStruct.analogSwitch = FL_DISABLE;
|
||
FL_GPIO_Init(CAN0_STB_GPIO, &GPIO_InitStruct);
|
||
|
||
CAN0_STB_ON();
|
||
}
|
||
|
||
|
||
/**
|
||
* gpio_led_init
|
||
*
|
||
* @param[in] none
|
||
* @return none
|
||
*
|
||
* @brief init led control gpio
|
||
*
|
||
*/
|
||
static void gpio_test_init(void)
|
||
{
|
||
FL_GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||
|
||
GPIO_InitStruct.pin = TEST1_PIN_MASK;
|
||
GPIO_InitStruct.mode = FL_GPIO_MODE_OUTPUT;
|
||
GPIO_InitStruct.outputType = FL_GPIO_OUTPUT_PUSHPULL;
|
||
GPIO_InitStruct.pull = FL_DISABLE;
|
||
GPIO_InitStruct.remapPin = FL_DISABLE;
|
||
GPIO_InitStruct.analogSwitch = FL_DISABLE;
|
||
FL_GPIO_Init(TEST1_GPIO, &GPIO_InitStruct);
|
||
GPIO_InitStruct.pin = TEST2_PIN_MASK;
|
||
FL_GPIO_Init(TEST2_GPIO, &GPIO_InitStruct);
|
||
|
||
//FL_GPIO_SetFOUT0(GPIO, FL_GPIO_FOUT0_SELECT_AHBCLK_DIV64);
|
||
//FL_GPIO_SetFOUT0(GPIO, FL_GPIO_FOUT0_SELECT_AHBCLK_DIV64);
|
||
/* init gpio as output mode */
|
||
// TEST1_OFF();
|
||
// TEST2_OFF();
|
||
}
|
||
|
||
|
||
|
||
//空闲io的配置
|
||
static void gpio_idle_init(void)
|
||
{
|
||
|
||
|
||
}
|
||
|
||
|
||
/**
|
||
* @brief
|
||
* @param input:
|
||
* @param output:
|
||
* @return none:
|
||
* @calls
|
||
* @calls by
|
||
* @others
|
||
*/
|
||
void gpio_cfg_init(void)
|
||
{
|
||
gpio_output_init();
|
||
gpio_pwm_init();
|
||
gpio_key_init();
|
||
gpio_adc_init();
|
||
gpio_can_init();
|
||
gpio_idle_init();
|
||
|
||
//gpio_lin_init();
|
||
//gpio_i2c_init();
|
||
|
||
//gpio_ext_interrupt_init();
|
||
}
|
||
|
||
|
||
//
|
||
static void gpio_ext_interrupt_init(void)
|
||
{
|
||
FL_GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||
FL_EXTI_InitTypeDef extiInitStruct = {0};
|
||
FL_EXTI_CommonInitTypeDef extiCommonInitStruct = {0};
|
||
|
||
FL_CMU_EnableEXTIOnSleep(); /* 休眠使能外部中断采样 */
|
||
|
||
/* EXTI中断采样时钟选择 */
|
||
extiCommonInitStruct.clockSource = FL_CMU_EXTI_CLK_SOURCE_LSCLK;
|
||
FL_EXTI_CommonInit(&extiCommonInitStruct);
|
||
|
||
/***********************CAN RX**************************/
|
||
GPIO_InitStruct.pin = CAN0_RX_PIN_MASK; /* 48PIN开发板引脚定义 */
|
||
GPIO_InitStruct.mode = FL_GPIO_MODE_INPUT;
|
||
GPIO_InitStruct.pull = FL_ENABLE;
|
||
GPIO_InitStruct.outputType = FL_GPIO_OUTPUT_PUSHPULL;
|
||
GPIO_InitStruct.remapPin = FL_DISABLE;
|
||
GPIO_InitStruct.analogSwitch = FL_DISABLE;
|
||
FL_GPIO_Init(CAN0_RX_GPIO, &GPIO_InitStruct); /* 48PIN开发板引脚定义 */
|
||
|
||
extiInitStruct.input = FL_GPIO_EXTI_INPUT_GROUP2; /* 中断线上对应的IO */
|
||
extiInitStruct.filter = FL_ENABLE; /* 使能数字滤波 */
|
||
extiInitStruct.triggerEdge = FL_GPIO_EXTI_TRIGGER_EDGE_FALLING; /* 设置触发边沿 */
|
||
FL_EXTI_Init(FL_GPIO_EXTI_LINE_1,&extiInitStruct);
|
||
|
||
// /***********************KEY B12**************************/
|
||
|
||
|
||
/* NVIC中断配置 */
|
||
NVIC_DisableIRQ(GPIO_IRQn);
|
||
NVIC_SetPriority(GPIO_IRQn, NVIC_PRIORITY_GPIO); /* 中断优先级配置 */
|
||
NVIC_EnableIRQ(GPIO_IRQn);
|
||
}
|
||
|
||
static void gpio_ext_interrupt_de_init(void)
|
||
{
|
||
FL_GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||
|
||
FL_CMU_DisableEXTIOnSleep(); /* 休眠使能外部中断采样 */
|
||
|
||
/* EXTI中断采样时钟选择 */
|
||
FL_EXTI_CommonDeinit();
|
||
|
||
/***********************FM33LG0X5A 48PIN**************************/
|
||
/* can rx GPIO外设 */
|
||
GPIO_InitStruct.pin = CAN0_RX_PIN_MASK; /* 48PIN开发板引脚定义 */
|
||
GPIO_InitStruct.mode = FL_GPIO_MODE_DIGITAL;
|
||
GPIO_InitStruct.pull = FL_ENABLE;
|
||
GPIO_InitStruct.outputType = FL_GPIO_OUTPUT_PUSHPULL;
|
||
GPIO_InitStruct.remapPin = FL_DISABLE;
|
||
GPIO_InitStruct.analogSwitch = FL_DISABLE;
|
||
FL_GPIO_Init(CAN0_RX_GPIO, &GPIO_InitStruct); /* 48PIN开发板引脚定义 */
|
||
|
||
FL_EXTI_DeInit(FL_GPIO_EXTI_LINE_1);
|
||
|
||
/* NVIC中断配置 */
|
||
NVIC_DisableIRQ(GPIO_IRQn);
|
||
//NVIC_SetPriority(GPIO_IRQn, NVIC_PRIORITY_EXTI0); /* 中断优先级配置 */
|
||
//NVIC_EnableIRQ(GPIO_IRQn);
|
||
}
|
||
|
||
//
|
||
void gpio_goto_sleep(void)
|
||
{
|
||
CAN0_STB_OFF();
|
||
|
||
// O_MDT_CTR_DISABLE();
|
||
O_12V_CTR_DISABLE();
|
||
O_5V_CTR_DISABLE();
|
||
O_KIT_CTR_DISABLE();
|
||
O_MDT_PWM_DISABLE();
|
||
O_DEN_CTR_DISABLE();
|
||
//FL_CAN_SetSoftwareReset(CAN,FL_CAN_SOFTWARE_RESET);
|
||
gpio_ext_interrupt_init();
|
||
}
|
||
|
||
void gpio_goto_wakeup(void)
|
||
{
|
||
gpio_ext_interrupt_de_init();
|
||
//TEST1_ON();
|
||
//TEST2_ON();
|
||
CAN0_STB_ON();
|
||
//LIN_SLP_ENABLE();
|
||
|
||
//O_MDT_CTR_ENABLE();
|
||
O_12V_CTR_ENABLE();
|
||
O_5V_CTR_ENABLE();
|
||
O_KIT_CTR_ENABLE();
|
||
O_DEN_CTR_ENABLE();
|
||
}
|
||
|
||
|
||
void gpio_cfg_re_init(void)
|
||
{
|
||
gpio_cfg_init();
|
||
}
|
||
|
||
|
||
/*end line*/
|
||
|