/*
  board.c - Board funtions
*/

#include "board.h"

#define BOARD_ADC_FREQ 5000000

// Pio pins to configure.
#ifdef PINS_ADC
static const Pin pinsADC[] = {PINS_ADC};
#endif

int
boardInit(void)
{
  /* Configure peripherals used by the application */
#ifdef PINS_ADC
  PIO_Configure(pinsADC, PIO_LISTSIZE(pinsADC));
#endif

  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);
  usleep(1000);

  return 0;
}
