/**
  ******************************************************************************
  * @file     EXTI_CFG.c
  * @author   SINOMCU-AE
  * @brief    EXIT pin config
  *    
  *          This file provides functions to EXTI pin config:
  *              KEY2 (PB4) pin input,Pull up,EXTI line 4 Event
  *         
  ******************************************************************************
  * @attention 
  *                           DISCLAIMER
  * The present firmware which is for guidance only aims at providing customers
  * with coding information regarding their products in order for them to save
  * time. As a result, SinoMCU shall not be held liable for any direct,indirect
  * or consequential damages with respect to any claims arising from the content 
  * of such firmware and/or the use made by customers of the coding information 
  * contained herein in connection with their products.
  *
  * <h2><center>&copy; Copyright (c) 2021 sinomcu All rights reserved.</center></h2>
  *
  ******************************************************************************
  */
    
#include "EXTI_CFG.h"

/**
  * @brief  exit pin init
  * @param  None
  * @retval None
  */
void exit_line_pin_init(void) {
  MS32_GPIO_InitTypeDef  GpioInitStruct;
  
  // PB4 Input,PullUp 
  MS32_GPIO_StructInit(&GpioInitStruct);  
  GpioInitStruct.Pin  = KEY2_Pin;
  GpioInitStruct.Mode = MS32_GPIO_MODE_INPUT;
  GpioInitStruct.OutputType = MS32_GPIO_OUTPUT_PUSHPULL;
  GpioInitStruct.Speed = MS32_GPIO_SPEED_LOW;
  GpioInitStruct.Pull  = MS32_GPIO_PULL_UP;
  GpioInitStruct.Alternate = MS32_GPIO_AF_0;
  MS32_GPIO_Init(KEY2_GPIO_Port,&GpioInitStruct);     // init function had enable clock
}

/**
  * @brief  EXIT Line Initialization Function
  * @param  None
  * @retval None
  */
void exit_line_init(void)
{
  MS32_EXTI_InitTypeDef ExitInitStruct = {0};

  exit_line_pin_init();
  
  MS32_EXTI_StructInit(&ExitInitStruct);
  ExitInitStruct.Line_0_31   = MS32_EXTI_LINE_4;
  ExitInitStruct.LineCommand = ENABLE;
  ExitInitStruct.Mode        = MS32_EXTI_MODE_EVENT;
  ExitInitStruct.Trigger     = MS32_EXTI_TRIGGER_FALLING;
  MS32_EXTI_Init(&ExitInitStruct);

  // line4 to PB4
  MS32_APB1_GRP2_EnableClock(MS32_APB1_GRP2_PERIPH_SYSCFG);
  MS32_SYSCFG_SetEXTISource(MS32_SYSCFG_EXTI_PORTB, MS32_SYSCFG_EXTI_LINE4);
}

/******************************** END OF FILE *********************************/
