/*!
 * @file        Board.h
 *
 * @brief       This file contains definitions for G32A10xx_TINYBOARD's Leds, push-buttons hardware resources
 *
 * @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.
 */

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

#ifdef __cplusplus
extern "C" {
#endif

/* Includes */
#include "g32a10xx.h"
#include "stdio.h"
#include "g32a10xx_gpio.h"
#include "g32a10xx_usart.h"
#include "g32a10xx_rcm.h"
#include "g32a10xx_eint.h"
#include "g32a10xx_syscfg.h"
#include "g32a10xx_misc.h"

/* @addtogroup Boards
  @{
*/

/* @addtogroup Board_G32A10xx_EVAL
  @{
*/

/* @defgroup G32A10xx_EVAL_Marcos Marcos
  @{
  */
#define LEDn                             4

#define LED1_PIN                         GPIO_PIN_10
#define LED1_GPIO_PORT                   GPIOC
#define LED1_GPIO_CLK                    RCM_AHB_PERIPH_GPIOC

#define LED2_PIN                         GPIO_PIN_11
#define LED2_GPIO_PORT                   GPIOC
#define LED2_GPIO_CLK                    RCM_AHB_PERIPH_GPIOC

#define LED3_PIN                         GPIO_PIN_12
#define LED3_GPIO_PORT                   GPIOC
#define LED3_GPIO_CLK                    RCM_AHB_PERIPH_GPIOC

#define LED4_PIN                         GPIO_PIN_2
#define LED4_GPIO_PORT                   GPIOD
#define LED4_GPIO_CLK                    RCM_AHB_PERIPH_GPIOD

#define BUTTONn                          4

/**
 * @brief Key1 push-button
 */
#define KEY1_BUTTON_PIN                   GPIO_PIN_0
#define KEY1_BUTTON_GPIO_PORT             GPIOC
#define KEY1_BUTTON_GPIO_CLK              RCM_AHB_PERIPH_GPIOC
#define KEY1_BUTTON_SYSCFG_PORT           SYSCFG_PORT_GPIOC
#define KEY1_BUTTON_SYSCFG_PIN            SYSCFG_PIN_0
#define KEY1_BUTTON_EXTI_LINE             EINT_LINE0
/**
 * @brief Key2 push-button
 */
#define KEY2_BUTTON_PIN                   GPIO_PIN_1
#define KEY2_BUTTON_GPIO_PORT             GPIOC
#define KEY2_BUTTON_GPIO_CLK              RCM_AHB_PERIPH_GPIOC
#define KEY2_BUTTON_SYSCFG_PORT           SYSCFG_PORT_GPIOC
#define KEY2_BUTTON_SYSCFG_PIN            SYSCFG_PIN_1
#define KEY2_BUTTON_EXTI_LINE             EINT_LINE1
/**
 * @brief Key3 push-button
 */
#define KEY3_BUTTON_PIN                   GPIO_PIN_2
#define KEY3_BUTTON_GPIO_PORT             GPIOC
#define KEY3_BUTTON_GPIO_CLK              RCM_AHB_PERIPH_GPIOC
#define KEY3_BUTTON_SYSCFG_PORT           SYSCFG_PORT_GPIOC
#define KEY3_BUTTON_SYSCFG_PIN            SYSCFG_PIN_2
#define KEY3_BUTTON_EXTI_LINE             EINT_LINE2
/**
 * @brief Key4 push-button
 */
#define KEY4_BUTTON_PIN                   GPIO_PIN_3
#define KEY4_BUTTON_GPIO_PORT             GPIOC
#define KEY4_BUTTON_GPIO_CLK              RCM_AHB_PERIPH_GPIOC
#define KEY4_BUTTON_SYSCFG_PORT           SYSCFG_PORT_GPIOC
#define KEY4_BUTTON_SYSCFG_PIN            SYSCFG_PIN_3
#define KEY4_BUTTON_EXTI_LINE             EINT_LINE3

#define COMn                             2

/**
 * @brief Definition for COM port1, connected to USART1
 */
#define EVAL_COM1                        USART1
#define EVAL_COM1_CLK                    RCM_APB2_PERIPH_USART1

#define EVAL_COM1_TX_PIN                 GPIO_PIN_9
#define EVAL_COM1_TX_GPIO_PORT           GPIOA
#define EVAL_COM1_TX_GPIO_CLK            RCM_AHB_PERIPH_GPIOA
#define EVAL_COM1_TX_SOURCE              GPIO_PIN_SOURCE_9
#define EVAL_COM1_TX_AF                  GPIO_AF_PIN1

#define EVAL_COM1_RX_PIN                 GPIO_PIN_10
#define EVAL_COM1_RX_GPIO_PORT           GPIOA
#define EVAL_COM1_RX_GPIO_CLK            RCM_AHB_PERIPH_GPIOA
#define EVAL_COM1_RX_SOURCE              GPIO_PIN_SOURCE_10
#define EVAL_COM1_RX_AF                  GPIO_AF_PIN1

#define EVAL_COM1_IRQn                   USART1_IRQn

/**
 * @brief Definition for COM port2, connected to USART2
 */
#define EVAL_COM2                        USART2
#define EVAL_COM2_CLK                    RCM_APB1_PERIPH_USART2

#define EVAL_COM2_TX_PIN                 GPIO_PIN_2
#define EVAL_COM2_TX_GPIO_PORT           GPIOA
#define EVAL_COM2_TX_GPIO_CLK            RCM_AHB_PERIPH_GPIOA
#define EVAL_COM2_TX_SOURCE              GPIO_PIN_SOURCE_2
#define EVAL_COM2_TX_AF                  GPIO_AF_PIN1

#define EVAL_COM2_RX_PIN                 GPIO_PIN_3
#define EVAL_COM2_RX_GPIO_PORT           GPIOA
#define EVAL_COM2_RX_GPIO_CLK            RCM_AHB_PERIPH_GPIOA
#define EVAL_COM2_RX_SOURCE              GPIO_PIN_SOURCE_3
#define EVAL_COM2_RX_AF                  GPIO_AF_PIN1

#define EVAL_COM2_IRQn                   USART2_IRQn

/**@} end of group G32A10xx_EVAL_Marcos */

/* @defgroup G32A10xx_EVAL_Emumerations Enumerations
  @{
  */

typedef enum
{
    LED1 = 0,
    LED2 = 1,
    LED3 = 2,
    LED4 = 3
} Board_LedTypes;

typedef enum
{
    BUTTON_KEY1 = 0,
    BUTTON_KEY2 = 1,
    BUTTON_KEY3 = 2,
    BUTTON_KEY4 = 3
} Board_ButtonTypes;

typedef enum
{
    BUTTON_MODE_GPIO = 0,
    BUTTON_MODE_EINT = 1
} Board_ButtonmodeTypes;

typedef enum
{
    COM1 = 0,
    COM2 = 1
} Board_ComTypes;

/**@} end of group G32A10xx_EVAL_Emumerations */

/* @defgroup G32A10xx_EVAL_Variables Variables
  @{
  */

extern GPIO_T* GPIO_PORT[LEDn];
extern const Gpio_PinType GPIO_PIN[LEDn];
extern const Rcm_AhbPeriphType GPIO_CLK[LEDn];
extern GPIO_T* BUTTON_PORT[BUTTONn];
extern const Gpio_PinType BUTTON_PIN[BUTTONn];
extern const Rcm_AhbPeriphType BUTTON_CLK[BUTTONn];
extern const Syscfg_PortTypes BUTTON_SYSCFG_PORT[BUTTONn];
extern const Syscfg_PinTypes BUTTON_SYSCFG_PIN[BUTTONn];
extern USART_T* COM_USART[COMn];
extern GPIO_T* COM_TX_PORT[COMn];
extern GPIO_T* COM_RX_PORT[COMn];
extern const Rcm_Apb2PeriphType COM_USART1_CLK[COMn];
extern const Rcm_Apb1PeriphType COM_USART2_CLK[COMn];
extern const Rcm_AhbPeriphType COM_TX_PORT_CLK[COMn];
extern const Rcm_AhbPeriphType COM_RX_PORT_CLK[COMn];
extern const Gpio_PinType COM_TX_PIN[COMn];
extern const Gpio_PinType COM_RX_PIN[COMn];
extern const Gpio_PinSourceType COM_TX_PIN_SOURCE[COMn];
extern const Gpio_PinSourceType COM_RX_PIN_SOURCE[COMn];
extern const Gpio_AfType COM_TX_AF[COMn];
extern const Gpio_AfType COM_RX_AF[COMn];

/**@} end of group G32A10xx_EVAL_Variables */

/* @defgroup G32A10xx_EVAL_Functions Functions
  @{
  */

/* LED */
void Board_LedInit(Board_LedTypes Led);
void Board_LedOn(Board_LedTypes Led);
void Board_LedOff(Board_LedTypes Led);
void Board_LedToggle(Board_LedTypes Led);

/* Key button */
void Board_ButtonInit(Board_ButtonTypes Button, Board_ButtonmodeTypes Button_Mode);
uint32_t Board_GetButtonState(Board_ButtonTypes Button);
/* COM */
void Board_ComInit(Board_ComTypes COM);

#ifdef __cplusplus
}
#endif

#endif /* BOARD_G32A10xx_EVAL */

/**@} end of group G32A10xx_EVAL_Functions */
/**@} end of group Board_G32A10xx_EVAL */
/**@} end of group Boards */
