/** ########################################################################## ** Filename : ** Project : ** Module : ** Processor : ** Version : ** Compiler : ** Date/Time : ** Abstract : ** Contents : ** Note : ** ** (c) Copyright dmdz Co.,Ltd ** -------------------------------------------------------------------------- ** R E V I S I O N H I S T O R Y ** -------------------------------------------------------------------------- ** Date Ver Author Description ** -20230602- --V1.0-- --mingyea--- --修改-- ** #########################################################################*/ /*--------------------------------------------------------------------------- - I N C L U D E F I L E S ----------------------------------------------------------------------------*/ #include "gpio.h" #include "nvic.h" #include "wdog.h" //#include "power_manager_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)) { g_gpio_cfg.test[1]++; #ifdef CAN_AUTOSAR_NM_EN //cannm_app_set_event(CANNM_EVENT_EXT_KEY); #endif //power_manage_app_set_wakeup(); //TO MODIFY FL_GPIO_ClearFlag_EXTI(GPIO, FL_GPIO_EXTI_LINE_1); } } #if 0 /** * gpio_led_init * * @param[in] none * @return none * * @brief init led control gpio * */ void gpio_i2c_init(void) { FL_GPIO_InitTypeDef GPIO_InitStruct = {0}; GPIO_InitStruct.pin = I2C0_SCL_PIN_MASK; GPIO_InitStruct.mode = FL_GPIO_MODE_DIGITAL; GPIO_InitStruct.outputType = FL_GPIO_OUTPUT_OPENDRAIN; //FL_GPIO_OUTPUT_OPENDRAIN GPIO_InitStruct.pull = FL_DISABLE; GPIO_InitStruct.remapPin = FL_DISABLE; GPIO_InitStruct.analogSwitch = FL_DISABLE; FL_GPIO_Init(I2C0_SCL_GPIO, &GPIO_InitStruct); GPIO_InitStruct.pin = I2C0_SDA_PIN_MASK; GPIO_InitStruct.outputType = FL_GPIO_OUTPUT_OPENDRAIN; FL_GPIO_Init(I2C0_SDA_GPIO, &GPIO_InitStruct); } /** * gpio_lin_init * * @param[in] none * @return none * * @brief init led control gpio * */ void gpio_lin_init(void) { #if PROJECT_NAME_CURRENT == PROJECT_NAME_DEMO FL_GPIO_InitTypeDef GPIO_InitStruct = {0}; LIN_SLP_DISABLE(); GPIO_InitStruct.pin = LIN_SLP_PIN_MASK; GPIO_InitStruct.mode = FL_GPIO_MODE_OUTPUT; GPIO_InitStruct.outputType = FL_GPIO_OUTPUT_PUSHPULL; GPIO_InitStruct.pull = FL_DISABLE; FL_GPIO_Init(LIN_SLP_GPIO, &GPIO_InitStruct); /* PA13:UART0-RX PA14:UART0-TX */ GPIO_InitStruct.pin = LIN_RX_PIN_MASK | LIN_TX_PIN_MASK; GPIO_InitStruct.mode = FL_GPIO_MODE_DIGITAL; GPIO_InitStruct.outputType = FL_GPIO_OUTPUT_OPENDRAIN; /* 推挽输出 */ GPIO_InitStruct.pull = FL_ENABLE; GPIO_InitStruct.remapPin = FL_DISABLE; GPIO_InitStruct.analogSwitch = FL_DISABLE; FL_GPIO_Init(LIN_RX_GPIO, &GPIO_InitStruct); #else #endif } #endif //普通输出io的配置 static void gpio_output_init(void) { FL_GPIO_InitTypeDef GPIO_InitStruct = {0}; GPIO_InitStruct.pin = O_MDT_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); O_MDT_CTR_DISABLE(); O_12V_CTR_DISABLE(); O_5V_CTR_DISABLE(); O_KIT_CTR_DISABLE(); O_MDT_PWM_DISABLE(); O_DEN_CTR_DISABLE(); } /** * 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}; GPIO_InitStruct.pin = PWM_LED_PIN_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 = PWM_LED_REPIN; FL_GPIO_Init(PWM_LED_GPIO, &GPIO_InitStruct); GPIO_InitStruct.remapPin = PWM_HS_REPIN; GPIO_InitStruct.pin = PWM_HS_PIN_MASK ; FL_GPIO_Init(PWM_HS_GPIO, &GPIO_InitStruct); GPIO_InitStruct.remapPin = PWM_L1_REPIN; GPIO_InitStruct.pin = PWM_L1_PIN_MASK ; FL_GPIO_Init(PWM_L1_GPIO, &GPIO_InitStruct); GPIO_InitStruct.remapPin = PWM_L2_REPIN; GPIO_InitStruct.pin = PWM_L2_PIN_MASK ; FL_GPIO_Init(PWM_L2_GPIO, &GPIO_InitStruct); GPIO_InitStruct.remapPin = PWM_R1_REPIN; GPIO_InitStruct.pin = PWM_R1_PIN_MASK ; FL_GPIO_Init(PWM_R1_GPIO, &GPIO_InitStruct); GPIO_InitStruct.remapPin = PWM_R2_REPIN; GPIO_InitStruct.pin = PWM_R2_PIN_MASK ; FL_GPIO_Init(PWM_R2_GPIO, &GPIO_InitStruct); GPIO_InitStruct.remapPin = PWM_LH_REPIN; GPIO_InitStruct.pin = PWM_LH_PIN_MASK ; FL_GPIO_Init(PWM_LH_GPIO, &GPIO_InitStruct); GPIO_InitStruct.remapPin = PWM_RH_REPIN; GPIO_InitStruct.pin = PWM_RH_PIN_MASK ; FL_GPIO_Init(PWM_RH_GPIO, &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_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); GPIO_InitStruct.pin = ADC_CHANNEL_7_PIN_MASK; FL_GPIO_Init(ADC_CHANNEL_7_GPIO, &GPIO_InitStruct); 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_test_init(); //gpio_lin_init(); //gpio_i2c_init(); //gpio_ext_interrupt_init(); } /*--------------------------------------------------------------------------- |Prototype : |Called by : None |Preconditions : None |Input parameters : None |Output parameters : None |Return value : None |Description : ----------------------------------------------------------------------------*/ 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 = (uint32_t)CAN0_RX_PIN_MASK; /* 48PIN开发板引脚定义 */ GPIO_InitStruct.mode = (uint32_t)FL_GPIO_MODE_INPUT; GPIO_InitStruct.pull = (uint32_t)FL_ENABLE; GPIO_InitStruct.outputType = (uint32_t)FL_GPIO_OUTPUT_PUSHPULL; GPIO_InitStruct.remapPin = (uint32_t)FL_DISABLE; GPIO_InitStruct.analogSwitch = (uint32_t)FL_DISABLE; FL_GPIO_Init(CAN0_RX_GPIO, &GPIO_InitStruct); /* 48PIN开发板引脚定义 */ extiInitStruct.input = (uint32_t)CAN0_RX_EXIT_GROUP; /* 中断线上对应的IO */ extiInitStruct.filter = (uint32_t)FL_ENABLE; /* 使能数字滤波 */ extiInitStruct.triggerEdge = (uint32_t)FL_GPIO_EXTI_TRIGGER_EDGE_FALLING; /* 设置触发边沿 */ FL_EXTI_Init(CAN0_RX_EXIT_LINE,&extiInitStruct); /* NVIC中断配置 */ NVIC_ClearPendingIRQ(GPIO_IRQn); NVIC_DisableIRQ(GPIO_IRQn); NVIC_SetPriority(GPIO_IRQn, NVIC_PRIORITY_GPIO); /* 中断优先级配置 */ NVIC_EnableIRQ(GPIO_IRQn); } /*--------------------------------------------------------------------------- |Prototype : |Called by : None |Preconditions : None |Input parameters : None |Output parameters : None |Return value : None |Description : ----------------------------------------------------------------------------*/ 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 = (uint32_t)CAN0_RX_PIN_MASK; /* 48PIN开发板引脚定义 */ GPIO_InitStruct.mode = (uint32_t)FL_GPIO_MODE_DIGITAL; GPIO_InitStruct.pull = (uint32_t)FL_ENABLE; GPIO_InitStruct.outputType = (uint32_t)FL_GPIO_OUTPUT_PUSHPULL; GPIO_InitStruct.remapPin = (uint32_t)FL_DISABLE; GPIO_InitStruct.analogSwitch = (uint32_t)FL_DISABLE; FL_GPIO_Init(CAN0_RX_GPIO, &GPIO_InitStruct); /* 48PIN开发板引脚定义 */ FL_EXTI_DeInit(CAN0_RX_EXIT_LINE); /* NVIC中断配置 */ NVIC_DisableIRQ(GPIO_IRQn); //NVIC_SetPriority(GPIO_IRQn, NVIC_PRIORITY_EXTI0); /* 中断优先级配置 */ //NVIC_EnableIRQ(GPIO_IRQn); } // /*--------------------------------------------------------------------------- |Prototype : |Called by : None |Preconditions : None |Input parameters : None |Output parameters : None |Return value : None |Description : ----------------------------------------------------------------------------*/ void gpio_goto_sleep(void) { TEST1_OFF(); TEST2_OFF(); 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(); } /*--------------------------------------------------------------------------- |Prototype : |Called by : None |Preconditions : None |Input parameters : None |Output parameters : None |Return value : None |Description : ----------------------------------------------------------------------------*/ void gpio_goto_wakeup(void) { gpio_ext_interrupt_de_init(); TEST1_ON(); TEST2_ON(); CAN0_STB_ON(); //LIN_SLP_ENABLE(); } /*--------------------------------------------------------------------------- |Prototype : |Called by : None |Preconditions : None |Input parameters : None |Output parameters : None |Return value : None |Description : ----------------------------------------------------------------------------*/ void gpio_cfg_re_init(void) { gpio_cfg_init(); } /*--------------------------------------------------------------------------- |Prototype : lpt32_ch1_set_gpio |Called by : |Preconditions : |Input parameters : |Output parameters : |Return value : |Description : ----------------------------------------------------------------------------*/ void lpt32_ch1_set_gpio(void) { FL_GPIO_InitTypeDef GPIO_InitStruct = {0}; GPIO_InitStruct.pin = GPIO_PIN8_MASK; GPIO_InitStruct.mode = FL_GPIO_MODE_OUTPUT; GPIO_InitStruct.outputType = FL_GPIO_OUTPUT_PUSHPULL; //FL_GPIO_OUTPUT_OPENDRAIN GPIO_InitStruct.pull = FL_DISABLE; GPIO_InitStruct.remapPin = FL_DISABLE; //注意 GPIO_InitStruct.analogSwitch = FL_DISABLE; FL_GPIO_Init(GPIOA, &GPIO_InitStruct); FL_GPIO_ResetOutputPin(GPIOB, GPIO_PIN8_MASK); } /*--------------------------------------------------------------------------- |Prototype : lpt32_ch1_set_pwm |Called by : |Preconditions : |Input parameters : |Output parameters : |Return value : |Description : ----------------------------------------------------------------------------*/ void lpt32_ch1_set_pwm(void) { FL_GPIO_InitTypeDef GPIO_InitStruct = {0}; GPIO_InitStruct.pin = GPIO_PIN8_MASK; GPIO_InitStruct.mode = FL_GPIO_MODE_DIGITAL; GPIO_InitStruct.outputType = FL_GPIO_OUTPUT_PUSHPULL; //FL_GPIO_OUTPUT_OPENDRAIN GPIO_InitStruct.pull = FL_DISABLE; GPIO_InitStruct.remapPin = FL_ENABLE; //注意 GPIO_InitStruct.analogSwitch = FL_DISABLE; FL_GPIO_Init(GPIOA, &GPIO_InitStruct); } /*--------------------------------------------------------------------------- |Prototype : lpt32_ch2_set_gpio |Called by : |Preconditions : |Input parameters : |Output parameters : |Return value : |Description : ----------------------------------------------------------------------------*/ void lpt32_ch2_set_gpio(void) { FL_GPIO_InitTypeDef GPIO_InitStruct = {0}; GPIO_InitStruct.pin = GPIO_PIN9_MASK; GPIO_InitStruct.mode = FL_GPIO_MODE_OUTPUT; GPIO_InitStruct.outputType = FL_GPIO_OUTPUT_PUSHPULL; //FL_GPIO_OUTPUT_OPENDRAIN GPIO_InitStruct.pull = FL_DISABLE; GPIO_InitStruct.remapPin = FL_DISABLE; //注意 GPIO_InitStruct.analogSwitch = FL_DISABLE; FL_GPIO_Init(GPIOA, &GPIO_InitStruct); FL_GPIO_ResetOutputPin(GPIOB, GPIO_PIN8_MASK); } /*--------------------------------------------------------------------------- |Prototype : lpt32_ch2_set_pwm |Called by : |Preconditions : |Input parameters : |Output parameters : |Return value : |Description : ----------------------------------------------------------------------------*/ void lpt32_ch2_set_pwm(void) { FL_GPIO_InitTypeDef GPIO_InitStruct = {0}; GPIO_InitStruct.pin = GPIO_PIN9_MASK; GPIO_InitStruct.mode = FL_GPIO_MODE_DIGITAL; GPIO_InitStruct.outputType = FL_GPIO_OUTPUT_PUSHPULL; //FL_GPIO_OUTPUT_OPENDRAIN GPIO_InitStruct.pull = FL_DISABLE; GPIO_InitStruct.remapPin = FL_ENABLE; //注意 GPIO_InitStruct.analogSwitch = FL_DISABLE; FL_GPIO_Init(GPIOA, &GPIO_InitStruct); } /*end line*/