/*!
 * @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 GPIO_Interrupt
  @{
*/

volatile uint8_t i = 0, j = 0;

/** @defgroup GPIO_Interrupt_Macros Macros
  @{
*/

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

    /* PB4 PB5 configuration */
    gpioConfig.mode = GPIO_MODE_IN_FLOATING;
    gpioConfig.pin = GPIO_PIN_4 | GPIO_PIN_5;
    gpioConfig.speed = GPIO_SPEED_10MHz;
    gpioConfig.intEn = GPIO_EINT_ENABLE;
    GPIO_Config(GPIOB, &gpioConfig);

    NVIC_EnableIRQRequest(EINTB_IRQn, 0x03);
    EINT_Config(EINT_PORT_B, EINT_TRIGGER_FALLING_RISING);
    EINT_ClearIntFlag(EINT_PORT_B);

    while (1)
    {
    }
}

/*!
 * @brief       EINTB interrupt
 *
 * @param       None
 *
 * @retval      None
 */
void EINTB_irq()
{
    if(GPIO_ReadInputBit(GPIOB, GPIO_PIN_4) == RESET)
    {
        i++;
    }
    if(GPIO_ReadInputBit(GPIOB, GPIO_PIN_5) == RESET)
    {
        j++;
    }
    if(GPIO_ReadInputBit(GPIOB, GPIO_PIN_4) == SET)
    {
        i++;
    }
    if(GPIO_ReadInputBit(GPIOB, GPIO_PIN_5) == SET)
    {
        j++;
    }
    EINT_ClearIntFlag(EINT_PORT_B);
}

/**@} end of group GPIO_Interrupt_Functions */
/**@} end of group GPIO_Interrupt */
/**@} end of group Examples */
