summaryrefslogtreecommitdiff
path: root/firmware/src/dac.c
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2013-06-02 18:25:46 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2013-06-02 18:25:46 +0200
commitb2df34e622ddee5d51beb1e9e93d4ecbb1745e55 (patch)
tree88822c96df5c98c74130ae532936f5d2f034c5b6 /firmware/src/dac.c
parentf547775b5a8c60f655bcdb0d10bbcdb1417f3890 (diff)
Initial experiments with SPI.
Diffstat (limited to 'firmware/src/dac.c')
-rw-r--r--firmware/src/dac.c24
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; }
+ }
+}