/*!
 * @file        g32a10xx_int.c
 *
 * @brief       Main Interrupt Service Routines
 *
 * @version     V1.0.0
 *
 * @date        2026-02-25
 *
 * @attention
 *
 *  Copyright (C) 2026 Geehy Semiconductor
 *
 *  You may not use this file except in compliance with the
 *  GEEHY COPYRIGHT NOTICE (Geehy Semiconductor Software License Agreement).
 *
 *  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 Semiconductor Software License Agreement for the governing permissions
 *  and limitations under the License.
 */

/* Includes */
#include "g32a10xx_int.h"
#include "g32a10xx_gpio.h"
#include "g32a10xx_eint.h"
#include "Board.h"

/** @addtogroup Examples
  @{
*/

/** @addtogroup SPI_Examples
  @{
*/

/** @addtogroup SPI_TwoBoards_Master
  @{
  */
/** @defgroup SPI_TwoBoards_Master_Variables Variables
  @{
*/
volatile int8_t g_keyPress = -1;

/**@} end of group SPI_TwoBoards_Master_Variables */

/** @defgroup SPI_TwoBoards_Master_INT_Functions INT_Functions
  @{
*/



/*!
 * @brief        This function handles Hard Fault exception
 *
 * @param        None
 *
 * @retval       None
 *
 * @note
 */
void HardFault_Handler(void)
{
}

/*!
 * @brief        This function handles SVCall exception
 *
 * @param        None
 *
 * @retval       None
 *
 * @note
 */
void SVC_Handler(void)
{
}

/*!
 * @brief        This function handles PendSV_Handler exception
 *
 * @param        None
 *
 * @retval       None
 *
 * @note
 */
void PendSV_Handler(void)
{
}

/*!
 * @brief        This function handles SysTick Handler
 *
 * @param        None
 *
 * @retval       None
 *
 * @note
 */
void SysTick_Handler(void)
{
}

/*!
 * @brief        This function handles EINT0_1 interrupt Handler
 *
 * @param        None
 *
 * @retval       None
 *
 * @note
 */
void EINT0_1_IRQHandler(void)
{
    Board_LedOff(LED1);
    Board_LedOff(LED2);
    Board_LedOff(LED3);
    Board_LedOff(LED4);
    if (Eint_ReadStatusFlag((uint32_t)KEY1_BUTTON_EXTI_LINE) == (uint8_t)SET)
    {
        /* The interrupt flag bit must be cleared first. */
        Eint_ClearStatusFlag((uint32_t)KEY1_BUTTON_EXTI_LINE);
        g_keyPress = (int8_t)BUTTON_KEY1;
    }
    else
    {
         /*  nothing */
    }

    if (Eint_ReadStatusFlag((uint32_t)KEY2_BUTTON_EXTI_LINE) == (uint8_t)SET)
    {
        /* The interrupt flag bit must be cleared first. */
        Eint_ClearStatusFlag((uint32_t)KEY2_BUTTON_EXTI_LINE);
        g_keyPress = (int8_t)BUTTON_KEY2;
    }
    else
    {
         /*  nothing */
    }

    if (Eint_ReadStatusFlag((uint32_t)KEY3_BUTTON_EXTI_LINE) == (uint8_t)SET)
    {
        /* The interrupt flag bit must be cleared first. */
        Eint_ClearStatusFlag((uint32_t)KEY3_BUTTON_EXTI_LINE);
        g_keyPress = (int8_t)BUTTON_KEY3;
    }
    else
    {
         /*  nothing */
    }

    if (Eint_ReadStatusFlag((uint32_t)KEY4_BUTTON_EXTI_LINE) == (uint8_t)SET)
    {
        /* The interrupt flag bit must be cleared first. */
        Eint_ClearStatusFlag((uint32_t)KEY4_BUTTON_EXTI_LINE);
        g_keyPress = (int8_t)BUTTON_KEY4;
    }
    else
    {
         /*  nothing */
    }
}

/*!
 * @brief        This function handles EINT2_3 interrupt Handler
 *
 * @param        None
 *
 * @retval       None
 *
 * @note
 */
void EINT2_3_IRQHandler(void)
{
    Board_LedOff(LED1);
    Board_LedOff(LED2);
    Board_LedOff(LED3);
    Board_LedOff(LED4);
    if (Eint_ReadStatusFlag((uint32_t)KEY1_BUTTON_EXTI_LINE) == (uint8_t)SET)
    {
        /* The interrupt flag bit must be cleared first. */
        Eint_ClearStatusFlag((uint32_t)KEY1_BUTTON_EXTI_LINE);
        g_keyPress = (int8_t)BUTTON_KEY1;
    }
    else
    {
         /*  nothing */
    }

    if (Eint_ReadStatusFlag((uint32_t)KEY2_BUTTON_EXTI_LINE) == (uint8_t)SET)
    {
        /* The interrupt flag bit must be cleared first. */
        Eint_ClearStatusFlag((uint32_t)KEY2_BUTTON_EXTI_LINE);
        g_keyPress = (int8_t)BUTTON_KEY2;
    }
    else
    {
         /*  nothing */
    }

    if (Eint_ReadStatusFlag((uint32_t)KEY3_BUTTON_EXTI_LINE) == (uint8_t)SET)
    {
        /* The interrupt flag bit must be cleared first. */
        Eint_ClearStatusFlag((uint32_t)KEY3_BUTTON_EXTI_LINE);
        g_keyPress = (int8_t)BUTTON_KEY3;
    }
    else
    {
         /*  nothing */
    }

    if (Eint_ReadStatusFlag((uint32_t)KEY4_BUTTON_EXTI_LINE) == (uint8_t)SET)
    {
        /* The interrupt flag bit must be cleared first. */
        Eint_ClearStatusFlag((uint32_t)KEY4_BUTTON_EXTI_LINE);
        g_keyPress = (int8_t)BUTTON_KEY4;
    }
    else
    {
         /*  nothing */
    }
}

/**@} end of group SPI_TwoBoards_Master_INT_Functions */
/**@} end of group SPI_TwoBoards_Master */
/**@} end of group SPI_Examples */
/**@} end of group Examples */
