aboutsummaryrefslogtreecommitdiff
path: root/embassy-stm32/src
diff options
context:
space:
mode:
authorAdam Greig <[email protected]>2024-04-29 02:28:20 +0100
committerAdam Greig <[email protected]>2024-04-29 02:28:20 +0100
commitcb60f06594bff074f6ead4284012fb3cc64ded47 (patch)
treef1ce754d1bfcfa1c4660188bb5c389e0a430e2b6 /embassy-stm32/src
parent51a4a73323880613988c9ac97544b505d738c859 (diff)
stm32: dac: fix new_internal not setting mode as documented
Diffstat (limited to 'embassy-stm32/src')
-rw-r--r--embassy-stm32/src/dac/mod.rs63
1 files changed, 41 insertions, 22 deletions
diff --git a/embassy-stm32/src/dac/mod.rs b/embassy-stm32/src/dac/mod.rs
index acfed8356..26298a08b 100644
--- a/embassy-stm32/src/dac/mod.rs
+++ b/embassy-stm32/src/dac/mod.rs
@@ -118,7 +118,7 @@ impl<'d, T: Instance, const N: u8, DMA> DacChannel<'d, T, N, DMA> {
118 /// 118 ///
119 /// If you're not using DMA, pass [`dma::NoDma`] for the `dma` argument. 119 /// If you're not using DMA, pass [`dma::NoDma`] for the `dma` argument.
120 /// 120 ///
121 /// The channel is enabled on creation and begins to drive the output pin. 121 /// The channel is enabled on creation and begin to drive the output pin.
122 /// Note that some methods, such as `set_trigger()` and `set_mode()`, will 122 /// Note that some methods, such as `set_trigger()` and `set_mode()`, will
123 /// disable the channel; you must re-enable it with `enable()`. 123 /// disable the channel; you must re-enable it with `enable()`.
124 /// 124 ///
@@ -382,7 +382,7 @@ impl<'d, T: Instance, DMACh1, DMACh2> Dac<'d, T, DMACh1, DMACh2> {
382 /// call `split()` to obtain separate `DacChannel`s, or use methods on `Dac` to use 382 /// call `split()` to obtain separate `DacChannel`s, or use methods on `Dac` to use
383 /// the two channels together. 383 /// the two channels together.
384 /// 384 ///
385 /// The channels are enabled on creation and begins to drive their output pins. 385 /// The channels are enabled on creation and begin to drive their output pins.
386 /// Note that some methods, such as `set_trigger()` and `set_mode()`, will 386 /// Note that some methods, such as `set_trigger()` and `set_mode()`, will
387 /// disable the channel; you must re-enable them with `enable()`. 387 /// disable the channel; you must re-enable them with `enable()`.
388 /// 388 ///
@@ -398,19 +398,28 @@ impl<'d, T: Instance, DMACh1, DMACh2> Dac<'d, T, DMACh1, DMACh2> {
398 into_ref!(dma_ch1, dma_ch2, pin_ch1, pin_ch2); 398 into_ref!(dma_ch1, dma_ch2, pin_ch1, pin_ch2);
399 pin_ch1.set_as_analog(); 399 pin_ch1.set_as_analog();
400 pin_ch2.set_as_analog(); 400 pin_ch2.set_as_analog();
401
401 // Enable twice to increment the DAC refcount for each channel. 402 // Enable twice to increment the DAC refcount for each channel.
402 T::enable_and_reset(); 403 T::enable_and_reset();
403 T::enable_and_reset(); 404 T::enable_and_reset();
404 Self { 405
405 ch1: DacCh1 { 406 let mut ch1 = DacCh1 {
406 phantom: PhantomData, 407 phantom: PhantomData,
407 dma: dma_ch1, 408 dma: dma_ch1,
408 }, 409 };
409 ch2: DacCh2 { 410 #[cfg(any(dac_v5, dac_v6, dac_v7))]
410 phantom: PhantomData, 411 ch1.set_hfsel();
411 dma: dma_ch2, 412 ch1.enable();
412 }, 413
413 } 414 let mut ch2 = DacCh2 {
415 phantom: PhantomData,
416 dma: dma_ch2,
417 };
418 #[cfg(any(dac_v5, dac_v6, dac_v7))]
419 ch2.set_hfsel();
420 ch2.enable();
421
422 Self { ch1, ch2 }
414 } 423 }
415 424
416 /// Create a new `Dac` instance where the external output pins are not used, 425 /// Create a new `Dac` instance where the external output pins are not used,
@@ -437,16 +446,26 @@ impl<'d, T: Instance, DMACh1, DMACh2> Dac<'d, T, DMACh1, DMACh2> {
437 // Enable twice to increment the DAC refcount for each channel. 446 // Enable twice to increment the DAC refcount for each channel.
438 T::enable_and_reset(); 447 T::enable_and_reset();
439 T::enable_and_reset(); 448 T::enable_and_reset();
440 Self { 449
441 ch1: DacCh1 { 450 let mut ch1 = DacCh1 {
442 phantom: PhantomData, 451 phantom: PhantomData,
443 dma: dma_ch1, 452 dma: dma_ch1,
444 }, 453 };
445 ch2: DacCh2 { 454 #[cfg(any(dac_v5, dac_v6, dac_v7))]
446 phantom: PhantomData, 455 ch1.set_hfsel();
447 dma: dma_ch2, 456 ch1.set_mode(Mode::NormalInternalUnbuffered);
448 }, 457 ch1.enable();
449 } 458
459 let mut ch2 = DacCh2 {
460 phantom: PhantomData,
461 dma: dma_ch2,
462 };
463 #[cfg(any(dac_v5, dac_v6, dac_v7))]
464 ch2.set_hfsel();
465 ch2.set_mode(Mode::NormalInternalUnbuffered);
466 ch2.enable();
467
468 Self { ch1, ch2 }
450 } 469 }
451 470
452 /// Split this `Dac` into separate channels. 471 /// Split this `Dac` into separate channels.