#include "stdio.h"
#include "OB6621.h"
#include "uart.h"
#include "gpio.h"
#include "adc.h"


int main(void)
{
    uint32_t Result[8], nLength;

    SystemCoreClockUpdate();

    // Open UART
    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);

    //--------------------------------
    GPIO_SetPinMFType(OB_GPIO1, GPIO_PIN2, GPIO_MF_ADC);   //P1.2 = ADC channel 2

    printf("\nThis sample code demonstrate ADC channel 2 and channel 16 conversion \n\r");

    // Enable ADC
    ADC_Open(OB_ADC,  ADC_MODE_12BIT);

    // lst Input Source = Channel-2
    // 2nd Input Source = Channel-3
    ADC_SetInputSource(OB_ADC,  ADC_INPUT_1ST, ADC_CHANNEL_2);
    ADC_SetInputSource(OB_ADC,  ADC_INPUT_2ND, ADC_CHANNEL_16);

    nLength = 0x02; //Channel-2 and Channel-3
    ADC_StartConvert(OB_ADC,  nLength);
    ADC_GetSampleResult(OB_ADC,  Result, nLength);
    printf(" ADC Value (Channel 2) = 0x%04X \n\r", Result[0]);
    printf(" ADC Value (Channel 16) = 0x%04X \n\r", Result[1]);
    while(1);
}
