summaryrefslogtreecommitdiff
path: root/firmware/src/dac.c
blob: 2773f003c9be892067d0205b92f891f8e99374cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include "dac.h"

//#include "api.h"
#include <LPC17xx.h>

void dac_init()
{
  // setup the related pin to DAC output 
  LPC_PINCON->PINSEL1 = 0x00200000;	// set p0.26 to DAC output   
	
	// Clock tick pr. sample delay (DAC clock)
  LPC_DAC->DACCNTVAL = 2267; // 44111Hz
  LPC_DAC->DACCTRL = (0x1<<1)|(0x1<<2);
	LPC_SC->PCLKSEL0 |= (0x1 << 22); // Use full 100MHz clock 
}

#define VOL 1
void dac_play_samples(const short int *samples, int size)
{
  for(int i = 0; i < size; i++) {
		LPC_DAC->DACR = ((unsigned short)(samples[i] * VOL)<< 6);// | DAC_BIAS;
		for(int j = 0; j < 100; j++) { if(!LPC_DAC->DACR) LPC_DAC->DACR = 0; }
  }
}