/*
  board.c - Board funtions
*/

#include "board.h"
#include "sdac.h"

#if defined(DAC_TEST)
#define BOARD_ADC_FREQ 5000000

/* PIO pins to configure for DAC */
static const Pin pinsADC[] = {PINS_ADC};
#endif

int
boardInit(void)
{
  /* Configure peripherals used by the application */
  SDAC_Initialize();
#if defined(DAC_TEST)
  /* Configure ADC0 to read DAC values */
  PIO_Configure(pinsADC, PIO_LISTSIZE(pinsADC));

  ADC_Initialize( AT91C_BASE_ADC,
                  AT91C_ID_ADC,
                  AT91C_ADC_TRGEN_DIS,
                  0,
                  AT91C_ADC_SLEEP_NORMAL_MODE,
                  AT91C_ADC_LOWRES_10_BIT,
                  BOARD_MCK,
                  BOARD_ADC_FREQ,
                  10,
                  1200);

  ADC_EnableChannel(AT91C_BASE_ADC, ADC_CHANNEL_0);
#endif // DAC_TEST
  usleep(1000);

  return 0;
}
