/*!
 * @file        main.c
 *
 * @brief       Main program body
 *
 * @version     V1.0.0
 *
 * @date        2023-03-31
 *
 * @attention
 *
 *  Copyright (C) 2023 Geehy Semiconductor
 *
 *  You may not use this file except in compliance with the
 *  GEEHY COPYRIGHT NOTICE (GEEHY SOFTWARE PACKAGE LICENSE).
 *
 *  The program is only for reference, which is distributed in the hope
 *  that it will be useful and instructional for customers to develop
 *  their software. Unless required by applicable law or agreed to in
 *  writing, the program is distributed on an "AS IS" BASIS, WITHOUT
 *  ANY WARRANTY OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the GEEHY SOFTWARE PACKAGE LICENSE for the governing permissions
 *  and limitations under the License.
 */

/* Includes */
#include "main.h"

/** @addtogroup Examples
  @{
*/

/** @addtogroup NVIC
  @{
*/

/** @defgroup NVIC_Functions Functions
  @{
*/

void Delay(void);
/*!
 * @brief       Main program
 *
 * @param       None
 *
 * @retval      None
 */
int main(void)
{
    GPIO_Config_T gpioConfig;

    APM_MINI_LEDInit(LED2);
    APM_MINI_LEDInit(LED3);
    APM_MINI_PBInit(BUTTON_KEY1, BUTTON_MODE_EINT);

    gpioConfig.mode = GPIO_MODE_IN_PU;
    gpioConfig.speed = GPIO_SPEED_10MHz;
    gpioConfig.pin = GPIO_PIN_3;
    gpioConfig.intEn = GPIO_EINT_ENABLE; 
    GPIO_Config(GPIOA, &gpioConfig);
    /* Set PA3 falling interrupt */
    EINT_Config(EINT_PORT_A, EINT_TRIGGER_FALLING);  
    /* KEY priority higher than PA3 */
    NVIC_EnableIRQRequest(EINTA_IRQn, 0X02);
    NVIC_EnableIRQRequest(EINTD_IRQn, 0X01);

    APM_MINI_LEDOff(LED2);
    APM_MINI_LEDOff(LED3);

    while(1)
    {
    }
}

/*!
 * @brief       EINTD program
 *
 * @param       None
 *
 * @retval      None
 */
void EINTD_Isr(void)
{
    uint8_t num = 10;
    while(num--)
    {
        APM_MINI_LEDToggle(LED2);
        Delay();
    }
}

/*!
 * @brief       EINTA program
 *
 * @param       None
 *
 * @retval      None
 */
void EINTA_Isr(void)
{
    uint8_t num = 10;
    while(num--)
    {
        APM_MINI_LEDToggle(LED3);
        Delay();
    }
}

/*!
 * @brief       delay program
 *
 * @param       None
 *
 * @retval      None
 */
void Delay(void)
{
    uint32_t num = 0xfffff;
    while(num--);
}
/**@} end of group NVIC_Functions */
/**@} end of group NVIC */
/**@} end of group Examples */
