/*******************************************************************************
 *
 *
 * File:        tau_device_datatype.h
 * Description  device datatype
 * Version      V0.1
 * Date         2020-12-04
 * Author       kevin
 *******************************************************************************/

#ifndef _TAU_DEVICE_DATATYPE_H_
#define _TAU_DEVICE_DATATYPE_H_


/*******************************************************************************
* 1.Included files
*******************************************************************************/

#include "stdint.h"
#include "tau_common.h"

/*******************************************************************************
* 2.Global constant and macro definitions using #define
*******************************************************************************/

/*******************************************************************************
* 3.Global structures, unions and enumerations using typedef
*******************************************************************************/
/*! @brief 计算组状态码 */
#define MAKE_STATUS(group, code) ((((group)*100) + (code)))

/*******************************************************************************
* 3.Global structures, unions and enumerations using typedef
*******************************************************************************/
/*! @brief 分组状态值 */
enum _status_groups
{
    STATUS_GROUP_GENERIC    = 0,
    STATUS_GROUP_I2C        = 1,
    STATUS_GROUP_UART       = 2,
    STATUS_GROUP_SPI        = 3,
    STATUS_GROUP_TIMER      = 4,
};

/*! @brief 常用状态码 */
enum _generic_status
{
    STATUS_SUCCESS                     = MAKE_STATUS(STATUS_GROUP_GENERIC, 0),
    STATUS_FAIL                        = MAKE_STATUS(STATUS_GROUP_GENERIC, 1),
    STATUS_READ_ONLY                   = MAKE_STATUS(STATUS_GROUP_GENERIC, 2),
    STATUS_OUT_OF_RANGE                = MAKE_STATUS(STATUS_GROUP_GENERIC, 3),
    STATUS_INVALID_ARGUMENT            = MAKE_STATUS(STATUS_GROUP_GENERIC, 4),
    STATUS_TIME_OUT                    = MAKE_STATUS(STATUS_GROUP_GENERIC, 5),
    STATUS_NO_TRANSFER_IN_PROGRESS     = MAKE_STATUS(STATUS_GROUP_GENERIC, 6),
};

/**
* @brief UART状态枚举定义
*
*/
typedef enum
{
    STATUS_UART_TX_BUSY              = MAKE_STATUS(STATUS_GROUP_UART, 0),  /*!< Transmitter is busy. */
    STATUS_UART_RX_BUSY              = MAKE_STATUS(STATUS_GROUP_UART, 1),  /*!< Receiver is busy. */
    STATUS_UART_TX_IDLE              = MAKE_STATUS(STATUS_GROUP_UART, 2),  /*!< USART transmitter is idle. */
    STATUS_UART_RX_IDLE              = MAKE_STATUS(STATUS_GROUP_UART, 3),  /*!< USART receiver is idle. */
    STATUS_UART_TX_ERR               = MAKE_STATUS(STATUS_GROUP_UART, 7),  /*!< Error happens on txFIFO. */
    STATUS_UART_RX_ERR               = MAKE_STATUS(STATUS_GROUP_UART, 9),  /*!< Error happens on rxFIFO. */
    STATUS_UART_RX_RING_BUFF_OVERRUN = MAKE_STATUS(STATUS_GROUP_UART, 8),  /*!< Error happens on rx ring buffer */
    STATUS_UART_NOISE_ERR            = MAKE_STATUS(STATUS_GROUP_UART, 10), /*!< USART noise error. */
    STATUS_UART_FRAMING_ERR          = MAKE_STATUS(STATUS_GROUP_UART, 11), /*!< USART framing error. */
    STATUS_UART_PARITY_ERR           = MAKE_STATUS(STATUS_GROUP_UART, 12), /*!< USART parity error. */
    STATUS_UART_BAUDRATE_NOT_SPT     = MAKE_STATUS(STATUS_GROUP_UART, 13), /*!< Baudrate is not support in current clock source */
} uart_status_e;

/*!
 * @brief timer状态
 */
typedef enum
{
    STATUS_TIMER_IDLE            = MAKE_STATUS(STATUS_GROUP_TIMER, 0),    /*!< 空闲 */
    STATUS_TIMER_RUNNING         = MAKE_STATUS(STATUS_GROUP_TIMER, 1),    /*!< 运行中 */
    STATUS_TIMER_TIMEOUT         = MAKE_STATUS(STATUS_GROUP_TIMER, 2),    /*!< 超时 */
} timer_status_e;

/*!
 * @brief system触发事件(中断/复位)模式
 */
typedef enum
{
    DETECT_HIGH_LVL = 0,
    DETECT_LOW_LVL,
    DETECT_RISING_EDGE,
    DETECT_FALLING_EDGE,
    DETECT_DOUBLE_EDGE
} sys_cfg_trigger_e;

/**
* @brief  GPIO interrupt type
*/
typedef enum
{
    TIMER_NUM0 = 0,
    TIMER_NUM1,
    TIMER_NUM2,
    TIMER_NUM3,
    TIMER_NUM_MAX
} timer_num_e;

/**
* @brief  GPIO interrupt type
*/
typedef enum
{
    GPIO_INT_EXTI_INT0 = 0,
    GPIO_INT_EXTI_INT1,
    GPIO_INT_EXTI_INT2,
    GPIO_INT_EXTI_INT3,
    GPIO_INT_EXTI_INT4,
    GPIO_INT_EXTI_INT5,
    GPIO_INT_EXTI_INT6,
    GPIO_INT_EXTI_INT7,
    GPIO_INT_MAX
} gpio_int_e;

/*! @brief PWMI中断类型 */
typedef enum _pwm_int_type
{
    PWM_INT_HIGH_OVERFLOW = 0,
    PWM_INT_LOW_OVERFLOW,
    PWM_INT_TOTAL_OVERFLOW,
    PWM_INT_HIGH_DONE,
    PWM_INT_LOW_DONE,
    PWM_INT_TOTAL_DONE,
    PWM_INT_MAX
} pwm_int_type_e;

/**
* @brief  I2C chose
*/
typedef enum
{
    I2C_SELECT_0 = 0,    //常用slave
    I2C_SELECT_1,        //常用master
} i2c_select_e;

/*!
 * @brief 传输速度
 * @note
 */
typedef enum _i2c_rate
{
    I2C_RATE_STANDARD = 1, //100kHz
    I2C_RATE_FAST,         //400kHz
    I2C_RATE_HIGH,         //1MHz
} i2c_rate_e;

/*!
 * @brief I2C Index
 * @note
 */
typedef enum
{
    I2C_INDEX_0,
    I2C_INDEX_1,
    I2C_INDEX_2,
    I2C_INDEX_MAX
} i2c_index_e;

/*!
 * @brief DMA channel type
 * @note
 */
typedef enum
{
    AHB_DMA_CH0,
    AHB_DMA_CH1,
    AHB_DMA_CH2,
    AHB_DMA_CH3,
    AHB_DMA_CH4,
    AHB_DMA_CH5,
    AHB_DMA_CH6,
    AHB_DMA_CH7,
    AHB_DMA_CH_NUM
} dma_channel_type_e;

/*! @brief Type used for all status and error return values. */

typedef enum
{
    DISABLE = 0,
    ENABLE = !DISABLE
} function_state_e;

/**
* @brief The reversal types of the bit order of the input/output data
*/
typedef enum
{
    CRC_REV_NO_TRANSPOSE = 0,               /*!< No transposition */
    CRC_REV_ONLY_BITS_TRANSPOSE,            /*!< Bits in bytes are transposed; bytes are not transposed */
    CRC_REV_BOTH_TRANSPOSE,                 /*!< Both bits in bytes and bytes are transposed */
    CRC_REV_ONLY_BYTES_TRANSPOSE,           /*!< Only bytes are transposed; no bits in a byte are transposed */
} crc_reversal_type_e;

/**
* @brief Complement Read Of CRC Data Register
*/
typedef enum
{
    CRC_FXOR_DISABLE = 0,                   /*!< No XOR on reading */
    CRC_FXOR_ENABLE,                        /*!< Invert or complement the read value of the CRC Data register */
} crc_fxor_function_e;

/**
* @brief width of CRC protocol (polynomial)
*/
typedef enum
{
    CRC_16_BIT_PROTOCOL = 0,               /*!< 0: 16-bit CRC protocol */
    CRC_32_BIT_PROTOCOL,                   /*!< 1: 32-bit CRC protocol */
} crc_protocol_type_e;

/*******************************************************************************
* 4.Global variable extern declarations
*******************************************************************************/

#endif

