#include "stdio.h"
#include "OB6627.h"
#include "gpio.h"
#include "pwm.h"
#include "uart.h"

int main(void)
{
    PWM_OUT_CONFIG  pwm_out;

    SystemCoreClockUpdate();
    GPIO_SetPinMFType(OB_GPIO2, GPIO_PIN0, GPIO_MF_UART1_RX);
    GPIO_SetPinMFType(OB_GPIO2, GPIO_PIN1, GPIO_MF_UART1_TX);
    UART_Open(OB_UART1, 19200);

    printf("\nThis sample code will output PWM channel 0A and channel 0B\n\r");
    printf(" PWM channel 0A Output ,low plus = 250us, High plus = 750u  \n\r");
    printf(" PWM channel 0B Output ,low plus = 150us, High plus = 2650u \n\r");
    printf(" Dead Band = 50 (unit: system clock) \n\r");

    //--------------------------------channel 0A--------------------
    GPIO_SetPinMFType(OB_GPIO0, GPIO_PIN13, GPIO_MF_PWM); // channel 0A
    GPIO_SetPinMFType(OB_GPIO0, GPIO_PIN12, GPIO_MF_PWM); // channel 0B

    pwm_out.Channel       = PWM_CH0A | PWM_CH0B;
    pwm_out.CounterSource = PWM_COUNTER0;
    pwm_out.Duty          = 250;    // low plus = 250us, High plus = 750us,
    pwm_out.Period        = 1000;   // Period = low plus + High plus = 1000us
    pwm_out.Comparator    = PWM_COMPARATOR0;
    pwm_out.Invert        = 0x00;
    pwm_out.Interrupt     = 0x00;

    pwm_out.DBEnable      = 0x01;
    pwm_out.DBDelay       = 50;
    pwm_out.DBMode        = PWM_DEADBAND_MODE_LL;

    PWM_OutputDuty(&pwm_out);
    PWM_Start(pwm_out.MODE0, pwm_out.MODE1);
    while(1);

}
