/**
 * @file        board_apm32f403_tiny.h
 *
 * @brief       This file contains definitions for APM32F403_TINY's Leds, push-buttons hardware resources
 *
 * @version     V1.0.0
 *
 * @date        2024-12-01
 *
 * @attention
 *
 *  Copyright (C) 2024-2025 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.
 */

/* Define to prevent recursive inclusion */
#ifndef BOARD_APM32F403_TINY_H
#define BOARD_APM32F403_TINY_H

#ifdef __cplusplus
  extern "C" {
#endif

/* Includes ***************************************************************/
#include "apm32f402_403.h"
#include "apm32f402_403_gpio.h"
#include "apm32f402_403_rcm.h"
#include "apm32f402_403_eint.h"
#include "apm32f402_403_usart.h"
#include "apm32f402_403_misc.h"

/* Exported macro *********************************************************/

/**
 * @brief LED2
 */
#define LED2_PIN                        GPIO_PIN_6
#define LED2_GPIO_PORT                  GPIOB
#define LED2_GPIO_CLK                   RCM_APB2_PERIPH_GPIOB
/**
 * @brief LED3
 */
#define LED3_PIN                        GPIO_PIN_7
#define LED3_GPIO_PORT                  GPIOB
#define LED3_GPIO_CLK                   RCM_APB2_PERIPH_GPIOB

/**
 * @brief Key1 push-button
 */
#define KEY1_BUTTON_PIN                 GPIO_PIN_1
#define KEY1_BUTTON_GPIO_PORT           GPIOA
#define KEY1_BUTTON_GPIO_CLK            RCM_APB2_PERIPH_GPIOA
#define KEY1_BUTTON_EINT_LINE           EINT_LINE_1
#define KEY1_BUTTON_EINT_PORT_SOURCE    GPIO_PORT_SOURCE_A
#define KEY1_BUTTON_EINT_PIN_SOURCE     GPIO_PIN_SOURCE_1
#define KEY1_BUTTON_EINT_IRQ_NUM        EINT1_IRQn

/**
 * @brief Key2 push-button
 */
#define KEY2_BUTTON_PIN                 GPIO_PIN_0
#define KEY2_BUTTON_GPIO_PORT           GPIOA
#define KEY2_BUTTON_GPIO_CLK            RCM_APB2_PERIPH_GPIOA
#define KEY2_BUTTON_EINT_LINE           EINT_LINE_0
#define KEY2_BUTTON_EINT_PORT_SOURCE    GPIO_PORT_SOURCE_A
#define KEY2_BUTTON_EINT_PIN_SOURCE     GPIO_PIN_SOURCE_0
#define KEY2_BUTTON_EINT_IRQ_NUM        EINT0_IRQn

/**
 * @brief COM1 USART1 port
 */
#define COM1_PORT                       USART1
#define COM1_PORT_CLK                   RCM_APB2_PERIPH_USART1
#define COM1_PORT_IRQ_NUM               USART1_IRQn
#define COM1_TX_PIN                     GPIO_PIN_9
#define COM1_TX_GPIO_PORT               GPIOA
#define COM1_TX_GPIO_CLK                RCM_APB2_PERIPH_GPIOA
#define COM1_RX_PIN                     GPIO_PIN_10
#define COM1_RX_GPIO_PORT               GPIOA
#define COM1_RX_GPIO_CLK                RCM_APB2_PERIPH_GPIOA

/**
 * @brief COM2 USART2 port
 */
#define COM2_PORT                       USART2
#define COM2_PORT_CLK                   RCM_APB1_PERIPH_USART2
#define COM2_PORT_IRQ_NUM               USART2_IRQn
#define COM2_TX_PIN                     GPIO_PIN_2
#define COM2_TX_GPIO_PORT               GPIOA
#define COM2_TX_GPIO_CLK                RCM_APB2_PERIPH_GPIOA
#define COM2_RX_PIN                     GPIO_PIN_3
#define COM2_RX_GPIO_PORT               GPIOA
#define COM2_RX_GPIO_CLK                RCM_APB2_PERIPH_GPIOA

/* Exported typedef *******************************************************/

/**
 * @brief LED type
 */
typedef enum
{
    LED2 = 0U,
    LED3 = 1U,
} BOARD_LED_T;

/**
 * @brief Button type
 */
typedef enum
{
    BUTTON_KEY1 = 0U,
    BUTTON_KEY2 = 1U,
} BOARD_BUTTON_T;

/**
 * @brief Button mode
 */
typedef enum
{
    BUTTON_MODE_GPIO = 0U,
    BUTTON_MODE_EINT = 1U
} BOARD_BUTTON_MODE_T;

/**
 * @brief COM type
 */
typedef enum
{
    COM1 = 0U,
    COM2 = 1U,
} BOARD_COM_T;

/* Exported function prototypes *******************************************/

/* Peripheral initialization functions */
void BOARD_LED_Config(BOARD_LED_T led);
void BOARD_BUTTON_Config(BOARD_BUTTON_T button, BOARD_BUTTON_MODE_T mode);
void BOARD_COM_Config(BOARD_COM_T com, USART_Config_T* configStruct);

/* Peripheral control functions */
void BOARD_LED_On(BOARD_LED_T led);
void BOARD_LED_Off(BOARD_LED_T led);
void BOARD_LED_Toggle(BOARD_LED_T led);
uint32_t BOARD_BUTTON_GetState(BOARD_BUTTON_T button);

#ifdef __cplusplus
}
#endif

#endif /* BOARD_APM32F403_TINY_H */
