#ifndef BOARD_CONFIG_H
#define BOARD_CONFIG_H

#define GD32E23XF4          0x10
#define GD32E23XF6          0x20
#define GD32E23XF8          0x40

#define PROTOCOL_BOARD_TYPE       0x01  /**< 板卡类型标识 */

#include "version.h"

/* >>>>>>>>>>>>>>>>>>>>[IIC TYPE DEFINE]<<<<<<<<<<<<<<<<<<<< */

// #define SOFTWARE_IIC // IIC Type : Software IIC
#undef  SOFTWARE_IIC // IIC Type : Hardware IIC

/* >>>>>>>>>>>>>>>>>>>>[DEBUG MODE]<<<<<<<<<<<<<<<<<<<< */

// #define DEBUG_MODE // Operating Mode : Debug Mode
#undef  DEBUG_MODE // Operating Mode : Release Mode

/* >>>>>>>>>>>>>>>>>>>>[COMMAND DEBUG]<<<<<<<<<<<<<<<<<<<< */

// #define COM_DEBUG // Enable Command Debug Information
#undef  COM_DEBUG // Disable Command Debug Information

/* >>>>>>>>>>>>>>>>>>>>[DEBUG ASSERTIONS DEFINE]<<<<<<<<<<<<<<<<<<<< */

// #define DEBUG_VERBOSE // Debug Assertions Status : Debug Verbose Information
#undef  DEBUG_VERBOSE // Debug Assertions Status : No Debug Verbose Information

/******************************************************************************/

/* Dynamic USART Configuration Structure */
typedef struct {
    uint32_t rcu_usart;
    uint32_t usart_periph;
    IRQn_Type irq_type;
    void (*irq_handler)(void);  // 函数指针：指向中断处理函数
} usart_config_t;

extern usart_config_t g_usart_config;
extern uint8_t g_mcu_flash_size;

/* USART中断处理函数声明 */
void usart0_irq_handler(void);
void usart1_irq_handler(void);

/******************************************************************************/

#define RCU_GPIO_I2C         RCU_GPIOF
#define RCU_I2C              RCU_I2C0
#define I2C_SCL_PORT         GPIOF
#define I2C_SCL_PIN          GPIO_PIN_1
#define I2C_SDA_PORT         GPIOF
#define I2C_SDA_PIN          GPIO_PIN_0
#define I2C_GPIO_AF          GPIO_AF_1

/******************************************************************************/

#define LED_RCU              RCU_GPIOA
#define LED_PORT             GPIOA
#define LED_PIN              GPIO_PIN_7

/******************************************************************************/

#define UART_RCU             (g_usart_config.rcu_usart)
#define UART_PHY             (g_usart_config.usart_periph)
#define UART_IRQ             (g_usart_config.irq_type)
#define UART_GPIO_RCU        RCU_GPIOA
#define UART_GPIO_PORT       GPIOA
#define UART_TX_PIN          GPIO_PIN_2
#define UART_RX_PIN          GPIO_PIN_3
#define UART_BAUDRATE        115200U

/******************************************************************************/

#define FAN_T_GPIO_PORT_RCU  RCU_GPIOA
#define FAN_T_GPIO_PORT      GPIOA
#define FAN_T_PWR_EN         GPIO_PIN_5
#define FAN_T_PWM            GPIO_PIN_6
#define FAN_T_DETECT         GPIO_PIN_4

#define FAN_A_GPIO_PORT_RCU  RCU_GPIOA
#define FAN_A_PWR_PORT_RCU   RCU_GPIOB
#define FAN_A_GPIO_PORT      GPIOA
#define FAN_A_PWR_PORT       GPIOB
#define FAN_A_PWR_EN         GPIO_PIN_1
#define FAN_A_PWM            GPIO_PIN_9
#define FAN_A_DETECT         GPIO_PIN_10

/******************************************************************************/

// UV-LED NTC Temperature Sensor Definitions AD_CHANNEL_0
#define LAMP_TEMP_GPIO_PORT_RCU  RCU_GPIOA
#define LAMP_TEMP_GPIO_PORT      GPIOA
#define LAMP_TEMP_AD_PIN         GPIO_PIN_0

// DMD NTC Temperature Sensor Definitions AD_CHANNEL_1
#define DMD_TEMP_GPIO_PORT_RCU RCU_GPIOA
#define DMD_TEMP_GPIO_PORT     GPIOA
#define DMD_TEMP_AD_PIN        GPIO_PIN_1

/******************************************************************************/

#define DEBUG_UART              USART0

void mcu_detect_and_config(void);
uint8_t get_flash_size(void);

#endif //BOARD_CONFIG_H
