aboutsummaryrefslogtreecommitdiffstats
path: root/libmaple/dac.c
diff options
context:
space:
mode:
authorMarti Bolivar <mbolivar@leaflabs.com>2011-02-18 04:00:00 -0500
committerMarti Bolivar <mbolivar@leaflabs.com>2011-02-18 04:00:00 -0500
commit0d440118bd4e1ba64f92d3636302fbddeac5bef6 (patch)
treeda06d190cbcf54bdbe54ff484ac66ac924c3ce38 /libmaple/dac.c
parent3f76591b3616c07c5a02624aff8649d5fa7e9f4b (diff)
downloadlibrambutan-0d440118bd4e1ba64f92d3636302fbddeac5bef6.tar.gz
librambutan-0d440118bd4e1ba64f92d3636302fbddeac5bef6.zip
Basic DAC functionality (high-density devices only).
Diffstat (limited to 'libmaple/dac.c')
-rw-r--r--libmaple/dac.c16
1 files changed, 7 insertions, 9 deletions
diff --git a/libmaple/dac.c b/libmaple/dac.c
index 7f6101d..63a96ac 100644
--- a/libmaple/dac.c
+++ b/libmaple/dac.c
@@ -31,12 +31,11 @@
* @brief DAC peripheral routines.
*/
-/* Only one, so global to this file */
-DAC_Map *dac = (DAC_Map*)(DAC_BASE);
-
/* This numbering follows the registers (1-indexed) */
-#define DAC_CHA 1
-#define DAC_CHB 2
+#define DAC_CH1 1
+#define DAC_CH2 2
+
+DAC_Map *dac = (DAC_Map*)(DAC_BASE);
/* Sets up the DAC peripheral */
void dac_init(void) {
@@ -49,16 +48,15 @@ void dac_init(void) {
/* Then do register stuff. Default does no triggering, and
* buffered output, so all good. */
- dac->CR |= DAC_CR_EN1;
- dac->CR |= DAC_CR_EN2;
+ dac->CR = DAC_CR_EN1 | DAC_CR_EN2;
}
void dac_write(uint8 chan, uint16 val) {
switch(chan) {
- case DAC_CHA:
+ case DAC_CH1:
dac->DHR12R1 = 0x0FFF & val;
break;
- case DAC_CHB:
+ case DAC_CH2:
dac->DHR12R2 = 0x0FFF & val;
break;
default: