/* 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) 2016. 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.
 */
 
#ifndef _INPUTCAPTURE_SINGLECHANNEL_H
#define _INPUTCAPTURE_SINGLECHANNEL_H
#include "ac780x.h"

#define PWM_PRES                            (1)     /*分频系数*/
#define FREQ                                (20000) /*PWM频率 freq = 20KHz*/
#define MOD_PWM0                            (APB_BUS_FREQ / FREQ / (PWM_PRES + 1)/2) /*PWM0中央对齐*/

#define PWM0CH0_GPIO    GPIOA
#define PWM0CH0_PIN     GPIO_PIN1
#define PWM0CH0_FUN     GPIO_FUN1

#define PWM0CH1_GPIO    GPIOA
#define PWM0CH1_PIN     GPIO_PIN0
#define PWM0CH1_FUN     GPIO_FUN1

#define PWM1CH2_GPIO    GPIOB
#define PWM1CH2_PIN     GPIO_PIN8
#define PWM1CH2_FUN     GPIO_FUN1

#define PWM1CH3_GPIO    GPIOB
#define PWM1CH3_PIN     GPIO_PIN7
#define PWM1CH3_FUN     GPIO_FUN1

 
typedef struct
{
    uint32_t freq;
    uint32_t dutyCycle;
    uint32_t positivePulseWidth;
    uint32_t negativePulseWidth;
    uint16_t captureValue;
    uint16_t captureValueLast;
    uint8_t  mutex;
} pwm_capture_t;

extern uint16_t g_captureFreq;          /*PWM频率*/
extern uint16_t g_captrueDuty;          /*PWM占空比*/
 
extern void PWM_GPIOInit(void);
extern void PWM0_Output_CentralAlign(void);
extern void PWM1_Capture_SingleChannel(void);
extern void PrintResults(pwm_capture_t *pwmCapture, char *str);

#endif

