/**
 *******************************************************************************
 * @file  hc32_ll_def.h
 * @brief This file contains LL common definitions: enumeration, macros and
  *       structures definitions.
 @verbatim
   Change Logs:
   Date             Author          Notes
   2022-03-31       CDT             First version
 @endverbatim
 *******************************************************************************
 * Copyright (C) 2022-2023, Xiaohua Semiconductor Co., Ltd. All rights reserved.
 *
 * This software component is licensed by XHSC under BSD 3-Clause license
 * (the "License"); You may not use this file except in compliance with the
 * License. You may obtain a copy of the License at:
 *                    opensource.org/licenses/BSD-3-Clause
 *
 *******************************************************************************
 */
#ifndef __HC32F334_DRIVERS_H__
#define __HC32F334_DRIVERS_H__

/************************************ADC********************************/


/************************************TIMERA*****************************/
#define TMRA_UNIT                       (CM_TMRA_3)
#define TMRA_PERIPH_CLK                 (FCG2_PERIPH_TMRA_3)
#define TMRA_PWM_CH_AURIXPOWER          (TMRA_CH1)

#define TMRA_PWM_PORT_AURIXPOWER        (GPIO_PORT_A)
#define TMRA_PWM_PIN_AURIXPOWER         (GPIO_PIN_00)
#define TMRA_PWM_PIN_AURIXPOWER_FUNC    (GPIO_FUNC_17)

#define TMRA_PWM_CH_FAN                 (TMRA_CH2)
#define TMRA_PWM_PORT_FAN               (GPIO_PORT_A)
#define TMRA_PWM_PIN_FAN                (GPIO_PIN_01)
#define TMRA_PWM_PIN_FAN_FUNC           (GPIO_FUNC_17)

#define TMRA_MD                         (TMRA_MD_SAWTOOTH)
#define TMRA_DIR                        (TMRA_DIR_UP)
#define TMRA_PERIOD_VAL                 (1200U - 1U)
#define TMRA_PWM_CMP_AURIXPOWER_VAL     (600U - 1U)
#define TMRA_PWM_CMP_FAN_VAL            (500U - 1U)

/************************************DMA definition*****************************/

#define RX_DMA_UNIT                     (CM_DMA)
#define RX_DMA_CH                       (DMA_CH0)
#define RX_DMA_FCG_ENABLE()             (FCG_Fcg0PeriphClockCmd(FCG0_PERIPH_DMA, ENABLE))
#define RX_DMA_TRIG_SEL                 (AOS_DMA_0)
#define RX_DMA_TRIG_EVT_SRC             (EVT_SRC_USART2_RI)
#define RX_DMA_RECONF_TRIG_SEL          (AOS_DMA_RC)
#define RX_DMA_RECONF_TRIG_EVT_SRC      (EVT_SRC_AOS_STRG)
#define RX_DMA_TC_INT                   (DMA_INT_TC_CH0)
#define RX_DMA_TC_FLAG                  (DMA_FLAG_TC_CH0)
#define RX_DMA_TC_IRQn                  (INT000_IRQn)
#define RX_DMA_TC_INT_SRC               (INT_SRC_DMA_TC0)

#define TX_DMA_UNIT                     (CM_DMA)
#define TX_DMA_CH                       (DMA_CH1)
#define TX_DMA_FCG_ENABLE()             (FCG_Fcg0PeriphClockCmd(FCG0_PERIPH_DMA, ENABLE))
#define TX_DMA_TRIG_SEL                 (AOS_DMA_1)
#define TX_DMA_TRIG_EVT_SRC             (EVT_SRC_USART2_TI)
#define TX_DMA_TC_INT                   (DMA_INT_TC_CH1)
#define TX_DMA_TC_FLAG                  (DMA_FLAG_TC_CH1)
#define TX_DMA_TC_IRQn                  (INT001_IRQn)
#define TX_DMA_TC_INT_SRC               (INT_SRC_DMA_TC1)

/* Timer0 unit & channel definition */
//#define TMR0_UNIT                       (CM_TMR0_1)
//#define TMR0_CH                         (TMR0_CH_B)
//#define TMR0_FCG_ENABLE()               (FCG_Fcg2PeriphClockCmd(FCG2_PERIPH_TMR0_1, ENABLE))

/***************************************USART definition**************************************/
/* USART RX/TX pin definition */
#define USART_RX_PORT                   (GPIO_PORT_A)   /* PA15: USART2_RX */
#define USART_RX_PIN                    (GPIO_PIN_15)
#define USART_RX_GPIO_FUNC              (GPIO_FUNC_37)

#define USART_TX_PORT                   (GPIO_PORT_C)   /* PC10: USART2_TX */
#define USART_TX_PIN                    (GPIO_PIN_10)
#define USART_TX_GPIO_FUNC              (GPIO_FUNC_36)

/* USART unit definition */
#define USART_UNIT                      (CM_USART2)
#define USART_FCG_ENABLE()              (FCG_Fcg3PeriphClockCmd(FCG3_PERIPH_USART2, ENABLE))

/* USART baudrate definition */
#define USART_BAUDRATE                  (115200UL)

/* USART timeout bits definition */
#define USART_TIMEOUT_BITS              (2000U)

/* USART interrupt definition */
#define USART_TX_CPLT_IRQn              (INT002_IRQn)
#define USART_TX_CPLT_INT_SRC           (INT_SRC_USART2_TCI)

#define USART_RX_ERR_IRQn               (INT003_IRQn)
#define USART_RX_ERR_INT_SRC            (INT_SRC_USART2_EI)

#define USART_RX_TIMEOUT_IRQn           (INT004_IRQn)
#define USART_RX_TIMEOUT_INT_SRC        (INT_SRC_USART2_RTO)

/* Application frame length max definition */
#define APP_FRAME_LEN_MAX               (500U)



extern uint8_t m_au8TxBuf[128];
extern uint8_t m_au8RxBuf[64];

extern void Gpio_Init(void);
extern void Ctrl_TMR0_Config(void);
extern void EMB_Init(void);
extern void EventPort_Init(void);
extern void ADCx_Init(void);
extern void TmrAConfig(void);
extern void DMA_Config(void);
extern void USART2Config(void);
extern void Usart2_TxEnable(void);
extern void Usart2_RxEnable(void);
extern void DACx_ConversionInit(void);
extern void LLC_CmpConfig(void);
extern void WDT_Config(void);
extern void CalibrationRead(void);
extern void CalibrationWrite(void);
extern int16_t  TemperatureBaseLookUpTable(uint16_t u16ADCTemp);
#endif

