/* Copyright Statement:
 *
 * This software/firmware and related documentation ("AutoChips Software") are
 * protected under relevant copyright laws. The information contained herein is
 * confidential and proprietary to AutoChips Inc. and/or its licensors. Without
 * the prior written permission of AutoChips inc. and/or its licensors, any
 * reproduction, modification, use or disclosure of AutoChips Software, and
 * information contained herein, in whole or in part, shall be strictly
 * prohibited.
 *
 * AutoChips Inc. (C) 2023. All rights reserved.
 *
 * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
 * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("AUTOCHIPS SOFTWARE")
 * RECEIVED FROM AUTOCHIPS AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER
 * ON AN "AS-IS" BASIS ONLY. AUTOCHIPS EXPRESSLY DISCLAIMS ANY AND ALL
 * WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
 * NONINFRINGEMENT. NEITHER DOES AUTOCHIPS PROVIDE ANY WARRANTY WHATSOEVER WITH
 * RESPECT TO THE SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY,
 * INCORPORATED IN, OR SUPPLIED WITH THE AUTOCHIPS SOFTWARE, AND RECEIVER AGREES
 * TO LOOK ONLY TO SUCH THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO.
 * RECEIVER EXPRESSLY ACKNOWLEDGES THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO
 * OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES CONTAINED IN AUTOCHIPS
 * SOFTWARE. AUTOCHIPS SHALL ALSO NOT BE RESPONSIBLE FOR ANY AUTOCHIPS SOFTWARE
 * RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
 * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND AUTOCHIPS'S
 * ENTIRE AND CUMULATIVE LIABILITY WITH RESPECT TO THE AUTOCHIPS SOFTWARE
 * RELEASED HEREUNDER WILL BE, AT AUTOCHIPS'S OPTION, TO REVISE OR REPLACE THE
 * AUTOCHIPS SOFTWARE AT ISSUE, OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE
 * CHARGE PAID BY RECEIVER TO AUTOCHIPS FOR SUCH AUTOCHIPS SOFTWARE AT ISSUE.
 */
/******************************************************************************
 * @version: V1.0.0 demo
 ******************************************************************************/

/*!
 * @RoutineDescription
 *
 * Initialize PWM2 module and configure PWM0_CH0, PWM0_CH1, PWM0_CH2, and PWM0_CH3 as independent channel outputs for PWM. Set the counting mode as up-counting with a frequency of 1KHz.
 * Set the duty cycle of CH0 to 20%, CH1 to 50%, CH2 to 60%, and CH3 to 70%.
 *
 * In the main loop, mask the output of CH0 and CH1 for 10ms, then unmask them for 10ms. Control the output level of CH2 and CH3 using software for 10ms,
 * then release the software control for 10ms. Repeat this process with a 10ms interval.
 */

/*!
 * @file main.c
 *
 * @brief This file is main.c.
 *
 */

/* ===========================================  Includes  =========================================== */

#include "pwm.h"

/* ============================================  Define  ============================================ */

/* ===========================================  Typedef  ============================================ */

/* ==========================================  Variables  =========================================== */

/* ====================================  Functions declaration  ===================================== */

/* ======================================  Functions define  ======================================== */

/*!
 * @brief main function
 *
 * @param[in] none
 *
 * @return int
 */
int main(void)
{
    InitDelay();

    PWM2_OutputIndependent_Init();

    while (1)
    {
        mdelay(10);
        PWM_SetChannelOutputMask(PWM2, PWM_CH_0, ENABLE);                   /* Enable the masking function of PWM2_CH0, which will make the output of this channel become an invalid level. */
        PWM_SetChannelOutputMask(PWM2, PWM_CH_1, ENABLE);                   /* Enable the masking function of PWM2_CH1, which will make the output of this channel become an invalid level. */
        PWM_SoftControlChannelLevel(PWM2, PWM_CH_2, PWM_HIGH_LEVEL, ENABLE);/* Enable the software control function of PWM2_CH2 and set the output level of this channel to high. */
        PWM_SoftControlChannelLevel(PWM2, PWM_CH_3, PWM_LOW_LEVEL, ENABLE); /* Enable the software control function of PWM2_CH3 and set the output level of this channel to low. */

        mdelay(10);
        PWM_SetChannelOutputMask(PWM2, PWM_CH_0, DISABLE);   /* Disable the masking function of PWM2_CH0, and the output of this channel will return to normal PWM output. */
        PWM_SetChannelOutputMask(PWM2, PWM_CH_1, DISABLE);   /* Disable the masking function of PWM2_CH1, and the output of this channel will return to normal PWM output. */
        PWM_SetChannelSoftControl(PWM2, PWM_CH_2, DISABLE);  /* Disable the software control function of PWM2_CH2, and the output of this channel will return to normal PWM output. */
        PWM_SetChannelSoftControl(PWM2, PWM_CH_3, DISABLE);  /* Disable the software control function of PWM2_CH3, and the output of this channel will return to normal PWM output. */
    }
}

/* =============================================  EOF  ============================================== */
