/*!
 * @file        user_tmr_config.c
 *
 * @brief       TMR and SENT protocol configuration
 *
 * @version     V1.0.0
 *
 * @date        2026-03-27
 *
 * @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).
 */

/* Includes */
#include "user_tmr_config.h"

/** @addtogroup Examples
  @{
*/

/** @addtogroup TMR_Examples
@{
*/

/** @addtogroup TMR_InputCapture_SENT
  @{
*/

/** @defgroup TMR_InputCapture_SENT_Variables Variables
  @{
*/

Tmr_SentHandleType sent_typ = {
    .state = SENT_STATE_IDLE,
};
volatile uint32_t g_tick = 0;

/*!
 * @brief SENT RX GPIO configuration
 */
Gpio_ConfigType g_gpioSentRxConfig = {
    .mode    = GPIO_MODE_AF,
    .outtype = GPIO_OUT_TYPE_PP,
    .pin     = (uint16_t)SENT_RX_GPIO_PIN,
    .pupd    = GPIO_PUPD_PU,
    .speed   = GPIO_SPEED_50MHz
};

/*!
 * @brief SENT TX GPIO configuration
 */
Gpio_ConfigType g_gpioSentTxConfig = {
    .mode    = GPIO_MODE_AF,
    .outtype = GPIO_OUT_TYPE_PP,
    .pin     = (uint16_t)SENT_TX_GPIO_PIN,
    .pupd    = GPIO_PUPD_PU,
    .speed   = GPIO_SPEED_50MHz
};

/*!
 * @brief Tmr_Delay timer configuration
 */
Tmr_TimeBaseType g_tmrDelayConfig = {
    .clockDivision     = TMR_CKD_DIV1,
    .counterMode       = TMR_COUNTER_MODE_UP,
    .div               = 63,
    .period            = 999,
    .repetitionCounter = 0
};

/*!
 * @brief TMR3 configuration for SENT send
 */
Tmr_TimeBaseType g_tmr3SentBaseConfig = {
    .clockDivision     = TMR_CKD_DIV1,
    .counterMode       = TMR_COUNTER_MODE_UP,
    .div               = 63,
    .period            = 0x05,
    .repetitionCounter = 0
};

/*!
 * @brief TMR2 configuration for SENT receive
 */
Tmr_TimeBaseType g_tmr2SentBaseConfig = {
    .clockDivision     = TMR_CKD_DIV1,
    .counterMode       = TMR_COUNTER_MODE_UP,
    .div               = 63,
    .period            = 0xFFFF,
    .repetitionCounter = 0
};

/*!
 * @brief Input capture configuration for SENT receive
 */
Tmr_IcConfigType g_tmrSentIcConfig = {
    .ICfilter     = 0x03,
    .ICpolarity   = TMR_IC_POLARITY_FALLING,
    .ICprescaler  = TMR_ICPSC_DIV1,
    .ICselection  = TMR_IC_SELECTION_DIRECT_TI
};

/*!
 * @brief Output compare configuration for SENT send
 */
Tmr_OcConfigType g_tmrSentOcConfig = {
    .OC_Mode          = TMR_OC_MODE_PWM1,
    .OC_Idlestate     = TMR_OCIDLESTATE_SET,
    .OC_NIdlestate    = TMR_OCNIDLESTATE_SET,
    .OC_OutputNState  = TMR_OUTPUT_NSTATE_DISABLE,
    .OC_OutputState   = TMR_OUTPUT_STATE_ENABLE,
    .OC_Polarity      = TMR_OC_POLARITY_LOW,
    .Pulse            = 0
};

/*!
 * @brief DMA configuration for SENT send
 */
Dma_ConfigType g_dmaSentConfig = {
    .bufferSize        = 30,
    .memoryDataSize     = DMA_MEMORY_DATASIZE_HALFWORD,
    .peripheralDataSize = DMA_PERIPHERAL_DATASIZE_HALFWORD,
    .memoryInc          = DMA_MEMORY_INC_ENABLE,
    .peripheralInc      = DMA_PERIPHERAL_INC_DISABLE,
    .circular           = DMA_CIRCULAR_DISABLE,
    .priority           = DMA_PRIORITY_LEVEL_HIGHT,
    .direction          = DMA_DIR_MEMORY,
    .memoryTomemory     = DMA_M2M_DISABLE,
};

/**@} end of group TMR_InputCapture_SENT_Variables */
/**@} end of group TMR_InputCapture_SENT */
/**@} end of group TMR_Examples */
/**@} end of group Examples */
