Skip to content

Commit 112f1ff

Browse files
author
Jonas Schievink
committed
Make DAC work on all chips
1 parent 104515f commit 112f1ff

File tree

2 files changed

+25
-14
lines changed

2 files changed

+25
-14
lines changed

src/dac.rs

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,29 @@
22
33
// Based on stm32hal by David-OConnor
44

5-
use cortex_m::asm;
5+
use crate::rcc::{Enable, Reset, APB1};
66

7-
use crate::{
8-
gpio::{self, Analog},
9-
pac::{dac1, DAC1},
10-
rcc::{Clocks, Enable, Rcc, Reset, AHB, APB1},
11-
};
7+
#[cfg(any(feature = "svd-f302",))]
8+
use crate::pac::DAC;
129

13-
use crate::pac::DMA1;
14-
15-
use crate::pac::{self, rcc, RCC};
10+
#[cfg(any(
11+
feature = "svd-f301",
12+
feature = "svd-f303",
13+
feature = "svd-f373",
14+
feature = "svd-f3x4",
15+
))]
16+
use crate::pac::DAC1 as DAC;
1617

1718
/// Represents a Digital to Analog Converter (DAC) peripheral.
1819
pub struct Dac {
19-
regs: DAC1,
20+
regs: DAC,
2021
}
2122

2223
impl Dac {
2324
/// Initializes the DAC peripheral.
24-
pub fn new(regs: DAC1, apb1: &mut APB1) -> Self {
25-
DAC1::enable(apb1);
26-
DAC1::reset(apb1);
25+
pub fn new(regs: DAC, apb1: &mut APB1) -> Self {
26+
DAC::enable(apb1);
27+
DAC::reset(apb1);
2728

2829
// Enable channel 1.
2930
regs.cr.modify(|_, w| w.en1().set_bit());
@@ -35,6 +36,11 @@ impl Dac {
3536
///
3637
/// Only the low 12 bits of `data` will be used, the rest is ignored.
3738
pub fn write_data(&mut self, data: u16) {
38-
self.regs.dhr12r1.write(|w| w.dacc1dhr().bits(data))
39+
self.regs.dhr12r1.write(|w| {
40+
#[allow(unused_unsafe)]
41+
unsafe {
42+
w.dacc1dhr().bits(data)
43+
}
44+
})
3945
}
4046
}

src/rcc/enable.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,11 @@ bus! {
157157
DAC1 => (APB1, dac1en, dac1rst), // 29
158158
}
159159

160+
#[cfg(any(feature = "svd-f302",))]
161+
bus! {
162+
DAC => (APB1, dac1en, dac1rst), // 29
163+
}
164+
160165
#[cfg(any(feature = "svd-f303", feature = "svd-f373", feature = "svd-f3x4"))]
161166
bus! {
162167
TIM7 => (APB1, tim7en, tim7rst), // 5

0 commit comments

Comments
 (0)