diff options
Diffstat (limited to 'firmware/src/dac.c')
-rw-r--r-- | firmware/src/dac.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/firmware/src/dac.c b/firmware/src/dac.c new file mode 100644 index 0000000..2773f00 --- /dev/null +++ b/firmware/src/dac.c @@ -0,0 +1,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; } + } +} |