aboutsummaryrefslogtreecommitdiffstats
path: root/libmaple/dac.c
diff options
context:
space:
mode:
authorMarti Bolivar <mbolivar@leaflabs.com>2011-04-21 17:24:57 -0400
committerMarti Bolivar <mbolivar@leaflabs.com>2011-04-21 17:24:57 -0400
commitd64c13caf100c7fa638596bd568cce3ce2ffce0a (patch)
treeebb5a3c31726f514403374792571b3d3a6fedb8d /libmaple/dac.c
parent7fdb4c986452756801eb8ba5eec94f9823e0b1c0 (diff)
downloadlibrambutan-d64c13caf100c7fa638596bd568cce3ce2ffce0a.tar.gz
librambutan-d64c13caf100c7fa638596bd568cce3ce2ffce0a.zip
Requiring dac_dev* argument in DAC convenience functions.
Diffstat (limited to 'libmaple/dac.c')
-rw-r--r--libmaple/dac.c28
1 files changed, 16 insertions, 12 deletions
diff --git a/libmaple/dac.c b/libmaple/dac.c
index 0f44bb4..1726d19 100644
--- a/libmaple/dac.c
+++ b/libmaple/dac.c
@@ -39,47 +39,50 @@ const dac_dev *DAC = &dac;
/**
* @brief Initialize the digital to analog converter
+ * @param dev DAC device
* @param flags Flags:
* DAC_CH1: Enable channel 1
* DAC_CH2: Enable channel 2
* @sideeffect May set PA4 or PA5 to INPUT_ANALOG
*/
-void dac_init(uint32 flags) {
+void dac_init(const dac_dev *dev, uint32 flags) {
/* First turn on the clock */
rcc_clk_enable(RCC_DAC);
rcc_reset_dev(RCC_DAC);
if (flags & DAC_CH1) {
- dac_enable_channel(1);
+ dac_enable_channel(dev, 1);
}
if (flags & DAC_CH2) {
- dac_enable_channel(2);
+ dac_enable_channel(dev, 2);
}
}
/**
* @brief Write a 12-bit value to the DAC to output
+ * @param dev DAC device
* @param channel channel to select (1 or 2)
* @param val value to write
*/
-void dac_write_channel(uint8 channel, uint16 val) {
+void dac_write_channel(const dac_dev *dev, uint8 channel, uint16 val) {
switch(channel) {
case 1:
- DAC->regs->DHR12R1 = DAC_DHR12R1_DACC1DHR & val;
+ dev->regs->DHR12R1 = DAC_DHR12R1_DACC1DHR & val;
break;
case 2:
- DAC->regs->DHR12R2 = DAC_DHR12R2_DACC2DHR & val;
+ dev->regs->DHR12R2 = DAC_DHR12R2_DACC2DHR & val;
break;
}
}
/**
* @brief Enable a DAC channel
+ * @param dev DAC device
* @param channel channel to enable, either 1 or 2
* @sideeffect May change pin mode of PA4 or PA5
*/
-void dac_enable_channel(uint8 channel) {
+void dac_enable_channel(const dac_dev *dev, uint8 channel) {
/*
* Setup ANALOG mode on PA4 and PA5. This mapping is consistent across
* all STM32 chips with a DAC. See RM0008 12.2.
@@ -87,26 +90,27 @@ void dac_enable_channel(uint8 channel) {
switch (channel) {
case 1:
gpio_set_mode(GPIOA, 4, GPIO_INPUT_ANALOG);
- DAC->regs->CR |= DAC_CR_EN1;
+ dev->regs->CR |= DAC_CR_EN1;
break;
case 2:
gpio_set_mode(GPIOA, 5, GPIO_INPUT_ANALOG);
- DAC->regs->CR |= DAC_CR_EN2;
+ dev->regs->CR |= DAC_CR_EN2;
break;
}
}
/**
* @brief Disable a DAC channel
+ * @param dev DAC device
* @param channel channel to disable, either 1 or 2
*/
-void dac_disable_channel(uint8 channel) {
+void dac_disable_channel(const dac_dev *dev, uint8 channel) {
switch (channel) {
case 1:
- DAC->regs->CR &= ~DAC_CR_EN1;
+ dev->regs->CR &= ~DAC_CR_EN1;
break;
case 2:
- DAC->regs->CR &= ~DAC_CR_EN2;
+ dev->regs->CR &= ~DAC_CR_EN2;
break;
}
}