/**
  ******************************************************************************
  * @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
  *         
  ******************************************************************************
  * @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 Line Initialization Function
  * @param  None
  * @retval None
  */
void EXIT_Line_Init(void)
{
  MS32_EXTI_InitTypeDef EXTI_InitStruct = {0};

  MS32_AHB1_GRP1_EnableClock(KEY2_AHB_PERIPH_Port);

  // key2 pull up,input
  MS32_GPIO_SetPinPull(KEY2_GPIO_Port, KEY2_Pin, MS32_GPIO_PULL_UP);
  MS32_GPIO_SetPinMode(KEY2_GPIO_Port, KEY2_Pin, MS32_GPIO_MODE_INPUT);
  
  // line4 to PB4
  MS32_APB1_GRP2_EnableClock(MS32_APB1_GRP2_PERIPH_SYSCFG);
  MS32_SYSCFG_SetEXTISource(MS32_SYSCFG_EXTI_PORTB, MS32_SYSCFG_EXTI_LINE4);

  MS32_EXTI_StructInit(&EXTI_InitStruct);
  EXTI_InitStruct.Line_0_31 = MS32_EXTI_LINE_4;
  EXTI_InitStruct.LineCommand = ENABLE;
  EXTI_InitStruct.Mode = MS32_EXTI_MODE_IT;
  EXTI_InitStruct.Trigger = MS32_EXTI_TRIGGER_FALLING;
  MS32_EXTI_Init(&EXTI_InitStruct);

  // EXTI interrupt init
  NVIC_SetPriority(KEY2_EXTI_IRQn, 0);
  NVIC_EnableIRQ(KEY2_EXTI_IRQn); 
}

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