/*FUNCTION**********************************************************************
 *
 * Function Name : FTM_DRV_QuadDecodeStart
 * Description   : Configures the parameters needed and activates quadrature
 * decode mode.
 *
 *END**************************************************************************/
void FTM_DRV_QuadDecodeStart(uint32_t instance, ftm_phase_params_t *phaseAParams,
                                      ftm_phase_params_t *phaseBParams, ftm_quad_decode_mode_t quadMode)
{
    assert(instance < FTM_INSTANCE_COUNT);
    assert(phaseAParams);
    assert(phaseBParams);

    FTM_Type *ftmBase = g_ftmBase[instance];

    FTM_HAL_SetQuadMode(ftmBase, quadMode);
    FTM_HAL_SetQuadPhaseAFilterCmd(ftmBase, phaseAParams->kFtmPhaseInputFilter);
    if (phaseAParams->kFtmPhaseInputFilter)
    {
        /* Set Phase A filter value if phase filter is enabled */
        FTM_HAL_SetChnInputCaptureFilter(ftmBase, CHAN0_IDX, phaseAParams->kFtmPhaseFilterVal);
    }
    FTM_HAL_SetQuadPhaseBFilterCmd(ftmBase, phaseBParams->kFtmPhaseInputFilter);
    if (phaseBParams->kFtmPhaseInputFilter)
    {
        /* Set Phase B filter value if phase filter is enabled */
        FTM_HAL_SetChnInputCaptureFilter(ftmBase, CHAN1_IDX, phaseBParams->kFtmPhaseFilterVal);
    }
    FTM_HAL_SetQuadPhaseAPolarity(ftmBase, phaseAParams->kFtmPhasePolarity);
    FTM_HAL_SetQuadPhaseBPolarity(ftmBase, phaseBParams->kFtmPhasePolarity);

    FTM_HAL_SetQuadDecoderCmd(ftmBase, true);

    /* Set clock source to start the counter */
    FTM_HAL_SetClockSource(ftmBase, s_ftmClockSource);
}
void FTM_DRV_QuadDecodeStart(uint8_t instance, ftm_phase_params_t *phaseAParams,
                                      ftm_phase_params_t *phaseBParams, ftm_quad_decode_mode_t quadMode)
{
    assert(instance < HW_FTM_INSTANCE_COUNT);
    assert(phaseAParams);
    assert(phaseBParams);

    uint32_t ftmBaseAddr = g_ftmBaseAddr[instance];

    FTM_HAL_SetQuadMode(ftmBaseAddr, quadMode);
    FTM_HAL_SetQuadPhaseAFilterCmd(ftmBaseAddr, phaseAParams->kFtmPhaseInputFilter);
    if (phaseAParams->kFtmPhaseInputFilter)
    {
        /* Set Phase A filter value if phase filter is enabled */
        FTM_HAL_SetChnInputCaptureFilter(ftmBaseAddr, HW_CHAN0, phaseAParams->kFtmPhaseFilterVal);
    }
    FTM_HAL_SetQuadPhaseBFilterCmd(ftmBaseAddr, phaseBParams->kFtmPhaseInputFilter);
    if (phaseBParams->kFtmPhaseInputFilter)
    {
        /* Set Phase B filter value if phase filter is enabled */
        FTM_HAL_SetChnInputCaptureFilter(ftmBaseAddr, HW_CHAN1, phaseBParams->kFtmPhaseFilterVal);
    }
    FTM_HAL_SetQuadPhaseAPolarity(ftmBaseAddr, phaseAParams->kFtmPhasePolarity);
    FTM_HAL_SetQuadPhaseBPolarity(ftmBaseAddr, phaseBParams->kFtmPhasePolarity);

    FTM_HAL_SetQuadDecoderCmd(ftmBaseAddr, true);

    /* Set clock source to start the counter */
    FTM_HAL_SetClockSource(ftmBaseAddr, kClock_source_FTM_SystemClk);
}