/*!
 * @file        main.c
 *
 * @brief       Main program body
 *
 * @version     V1.0.0
 *
 * @date        2026-02-25
 *
 * @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).
 *
 *  The program is only for reference, which is distributed in the hope
 *  that it will be useful and instructional for customers to develop
 *  their software. Unless required by applicable law or agreed to in
 *  writing, the program is distributed on an "AS IS" BASIS, WITHOUT
 *  ANY WARRANTY OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the Geehy Semiconductor Software License Agreement for the governing permissions
 *  and limitations under the License.
 */

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

/** @addtogroup Examples
  @{
*/

/** @addtogroup TMR_Examples
@{
*/

/** @addtogroup TMR_PWMOutput
  @{
*/

/** @defgroup TMR_PWMOutput_Macros Macros
  @{
*/

/**@} end of group TMR_PWMOutput_Macros */

/** @defgroup TMR_PWMOutput_Enumerations Enumerations
  @{
*/

/**@} end of group TMR_PWMOutput_Enumerations */

/** @defgroup TMR_PWMOutput_Structures Structures
  @{
*/

/**@} end of group TMR_PWMOutput_Structures */

/** @defgroup TMR_PWMOutput_Variables Variables
  @{
*/

/**@} end of group TMR_PWMOutput_Variables */

/** @defgroup TMR_PWMOutput_Functions Functions
  @{
*/

/* TMR1 PWM Output Init*/
void Tmr1_PWMOutPutInit(void);
/* Tmr_Delay */
void Tmr_Delay(void);

/*!
 * @brief       Main program
 *
 * @param       None
 *
 * @retval      None
 *
 * @note
 */
int main(void)
{
    Board_LedInit(LED2);
    Tmr1_PWMOutPutInit();

    for (;;)
    {
        Tmr_Delay();

        Board_LedToggle(LED2);
    }
}

/*!
 * @brief       TMR1 PWM Output Init
 *
 * @param       None
 *
 * @retval      None
 *
 * @note
 */
void Tmr1_PWMOutPutInit(void)
{
    /* Enable Clock */
    Rcm_EnableAhbPeriphClock(RCM_AHB_PERIPH_GPIOA);
    Rcm_EnableApb2PeriphClock(RCM_APB2_PERIPH_SYSCFG);
    Rcm_EnableApb2PeriphClock(RCM_APB2_PERIPH_TMR1);

    /*  Connect TMR1 to CH1 */
    Gpio_ConfigPinAF(TMR1_CH1_GPIO_PORT, TMR1_CH1_PIN_SOURCE, TMR1_CH1_GPIO_AF);
    Gpio_Config(TMR1_CH1_GPIO_PORT, &g_tmr1_Ch1GpioConfig);

    /* Config TimeBase */
    Tmr_ConfigTimeBase(TMR1, &g_tmr1_BaseConfig);

    /* Config PWM Output */
    Tmr_OC1Config(TMR1, &g_tmr1_OC1PWMConfig);

    /* Enable PWM output */
    Tmr1_EnablePWMOutputs();
    /*  Enable TMR1  */
    Tmr_Enable(TMR1);
}

/*!
 * @brief       Tmr_Delay
 *
 * @param       None
 *
 * @retval      None
 *
 * @note
 */
void Tmr_Delay(void)
{
    volatile uint32_t delay = 0xfffff;

    while ((uint32_t)0u != delay)
    {
        delay = delay - (uint32_t)1u;
    };
}

/**@} end of group TMR_PWMOutput_Functions */
/**@} end of group TMR_PWMOutput */
/**@} end of group TMR_Examples */
/**@} end of group Examples */
