diff options
| author | JuliDi <[email protected]> | 2023-06-27 21:23:47 +0200 |
|---|---|---|
| committer | JuliDi <[email protected]> | 2023-06-27 21:23:47 +0200 |
| commit | 56dd22f0ac49be2b824e88026d38b69843b56972 (patch) | |
| tree | 8cb77d9a5f4813e5f7c66dc627a8c21965ec5ca8 | |
| parent | afec1b439bb40b769c8ccd1c1b19d58edd034c3d (diff) | |
feature-gate set_channel_mode, undo dma.rs changes
| -rw-r--r-- | embassy-stm32/src/dac/mod.rs | 17 | ||||
| -rw-r--r-- | embassy-stm32/src/dma/dma.rs | 18 |
2 files changed, 11 insertions, 24 deletions
diff --git a/embassy-stm32/src/dac/mod.rs b/embassy-stm32/src/dac/mod.rs index 3e48d558a..b53083524 100644 --- a/embassy-stm32/src/dac/mod.rs +++ b/embassy-stm32/src/dac/mod.rs | |||
| @@ -127,6 +127,7 @@ pub trait DacChannel<T: Instance, Tx> { | |||
| 127 | } | 127 | } |
| 128 | 128 | ||
| 129 | /// Set mode register of the given channel | 129 | /// Set mode register of the given channel |
| 130 | #[cfg(dac_v2)] | ||
| 130 | fn set_channel_mode(&mut self, val: u8) -> Result<(), Error> { | 131 | fn set_channel_mode(&mut self, val: u8) -> Result<(), Error> { |
| 131 | T::regs().mcr().modify(|reg| { | 132 | T::regs().mcr().modify(|reg| { |
| 132 | reg.set_mode(Self::CHANNEL.index(), val); | 133 | reg.set_mode(Self::CHANNEL.index(), val); |
| @@ -221,6 +222,7 @@ impl<'d, T: Instance, Tx> DacCh1<'d, T, Tx> { | |||
| 221 | 222 | ||
| 222 | // Configure each activated channel. All results can be `unwrap`ed since they | 223 | // Configure each activated channel. All results can be `unwrap`ed since they |
| 223 | // will only error if the channel is not configured (i.e. ch1, ch2 are false) | 224 | // will only error if the channel is not configured (i.e. ch1, ch2 are false) |
| 225 | #[cfg(dac_v2)] | ||
| 224 | dac.set_channel_mode(0).unwrap(); | 226 | dac.set_channel_mode(0).unwrap(); |
| 225 | dac.enable_channel().unwrap(); | 227 | dac.enable_channel().unwrap(); |
| 226 | dac.set_trigger_enable(true).unwrap(); | 228 | dac.set_trigger_enable(true).unwrap(); |
| @@ -334,6 +336,7 @@ impl<'d, T: Instance, Tx> DacCh2<'d, T, Tx> { | |||
| 334 | 336 | ||
| 335 | // Configure each activated channel. All results can be `unwrap`ed since they | 337 | // Configure each activated channel. All results can be `unwrap`ed since they |
| 336 | // will only error if the channel is not configured (i.e. ch1, ch2 are false) | 338 | // will only error if the channel is not configured (i.e. ch1, ch2 are false) |
| 339 | #[cfg(dac_v2)] | ||
| 337 | dac.set_channel_mode(0).unwrap(); | 340 | dac.set_channel_mode(0).unwrap(); |
| 338 | dac.enable_channel().unwrap(); | 341 | dac.enable_channel().unwrap(); |
| 339 | dac.set_trigger_enable(true).unwrap(); | 342 | dac.set_trigger_enable(true).unwrap(); |
| @@ -454,10 +457,12 @@ impl<'d, T: Instance, TxCh1, TxCh2> Dac<'d, T, TxCh1, TxCh2> { | |||
| 454 | 457 | ||
| 455 | // Configure each activated channel. All results can be `unwrap`ed since they | 458 | // Configure each activated channel. All results can be `unwrap`ed since they |
| 456 | // will only error if the channel is not configured (i.e. ch1, ch2 are false) | 459 | // will only error if the channel is not configured (i.e. ch1, ch2 are false) |
| 460 | #[cfg(dac_v2)] | ||
| 457 | dac_ch1.set_channel_mode(0).unwrap(); | 461 | dac_ch1.set_channel_mode(0).unwrap(); |
| 458 | dac_ch1.enable_channel().unwrap(); | 462 | dac_ch1.enable_channel().unwrap(); |
| 459 | dac_ch1.set_trigger_enable(true).unwrap(); | 463 | dac_ch1.set_trigger_enable(true).unwrap(); |
| 460 | 464 | ||
| 465 | #[cfg(dac_v2)] | ||
| 461 | dac_ch2.set_channel_mode(0).unwrap(); | 466 | dac_ch2.set_channel_mode(0).unwrap(); |
| 462 | dac_ch2.enable_channel().unwrap(); | 467 | dac_ch2.enable_channel().unwrap(); |
| 463 | dac_ch2.set_trigger_enable(true).unwrap(); | 468 | dac_ch2.set_trigger_enable(true).unwrap(); |
| @@ -521,27 +526,25 @@ foreach_peripheral!( | |||
| 521 | #[cfg(rcc_h7)] | 526 | #[cfg(rcc_h7)] |
| 522 | impl crate::rcc::sealed::RccPeripheral for peripherals::$inst { | 527 | impl crate::rcc::sealed::RccPeripheral for peripherals::$inst { |
| 523 | fn frequency() -> crate::time::Hertz { | 528 | fn frequency() -> crate::time::Hertz { |
| 524 | critical_section::with(|_| unsafe { | 529 | critical_section::with(|_| crate::rcc::get_freqs().apb1) |
| 525 | crate::rcc::get_freqs().apb1 | ||
| 526 | }) | ||
| 527 | } | 530 | } |
| 528 | 531 | ||
| 529 | fn reset() { | 532 | fn reset() { |
| 530 | critical_section::with(|_| unsafe { | 533 | critical_section::with(|_| { |
| 531 | crate::pac::RCC.apb1lrstr().modify(|w| w.set_dac12rst(true)); | 534 | crate::pac::RCC.apb1lrstr().modify(|w| w.set_dac12rst(true)); |
| 532 | crate::pac::RCC.apb1lrstr().modify(|w| w.set_dac12rst(false)); | 535 | crate::pac::RCC.apb1lrstr().modify(|w| w.set_dac12rst(false)); |
| 533 | }) | 536 | }) |
| 534 | } | 537 | } |
| 535 | 538 | ||
| 536 | fn enable() { | 539 | fn enable() { |
| 537 | critical_section::with(|_| unsafe { | 540 | critical_section::with(|_| { |
| 538 | crate::pac::RCC.apb1lenr().modify(|w| w.set_dac12en(true)); | 541 | crate::pac::RCC.apb1lenr().modify(|w| w.set_dac12en(true)); |
| 539 | }) | 542 | }) |
| 540 | } | 543 | } |
| 541 | 544 | ||
| 542 | fn disable() { | 545 | fn disable() { |
| 543 | critical_section::with(|_| unsafe { | 546 | critical_section::with(|_| { |
| 544 | crate::pac::RCC.apb1lenr().modify(|w| w.set_dac12en(false)); | 547 | crate::pac::RCC.apb1lenr().modify(|w| w.set_dac12en(false)) |
| 545 | }) | 548 | }) |
| 546 | } | 549 | } |
| 547 | } | 550 | } |
diff --git a/embassy-stm32/src/dma/dma.rs b/embassy-stm32/src/dma/dma.rs index a5f828948..0b7b60789 100644 --- a/embassy-stm32/src/dma/dma.rs +++ b/embassy-stm32/src/dma/dma.rs | |||
| @@ -29,12 +29,6 @@ pub struct TransferOptions { | |||
| 29 | pub flow_ctrl: FlowControl, | 29 | pub flow_ctrl: FlowControl, |
| 30 | /// FIFO threshold for DMA FIFO mode. If none, direct mode is used. | 30 | /// FIFO threshold for DMA FIFO mode. If none, direct mode is used. |
| 31 | pub fifo_threshold: Option<FifoThreshold>, | 31 | pub fifo_threshold: Option<FifoThreshold>, |
| 32 | /// Enable circular DMA | ||
| 33 | pub circular: bool, | ||
| 34 | /// Enable half transfer interrupt | ||
| 35 | pub half_transfer_ir: bool, | ||
| 36 | /// Enable transfer complete interrupt | ||
| 37 | pub complete_transfer_ir: bool, | ||
| 38 | } | 32 | } |
| 39 | 33 | ||
| 40 | impl Default for TransferOptions { | 34 | impl Default for TransferOptions { |
| @@ -44,9 +38,6 @@ impl Default for TransferOptions { | |||
| 44 | mburst: Burst::Single, | 38 | mburst: Burst::Single, |
| 45 | flow_ctrl: FlowControl::Dma, | 39 | flow_ctrl: FlowControl::Dma, |
| 46 | fifo_threshold: None, | 40 | fifo_threshold: None, |
| 47 | circular: false, | ||
| 48 | half_transfer_ir: false, | ||
| 49 | complete_transfer_ir: true, | ||
| 50 | } | 41 | } |
| 51 | } | 42 | } |
| 52 | } | 43 | } |
| @@ -375,20 +366,13 @@ impl<'a, C: Channel> Transfer<'a, C> { | |||
| 375 | }); | 366 | }); |
| 376 | w.set_pinc(vals::Inc::FIXED); | 367 | w.set_pinc(vals::Inc::FIXED); |
| 377 | w.set_teie(true); | 368 | w.set_teie(true); |
| 378 | w.set_tcie(options.complete_transfer_ir); | 369 | w.set_tcie(true); |
| 379 | w.set_htie(options.half_transfer_ir); | ||
| 380 | #[cfg(dma_v1)] | 370 | #[cfg(dma_v1)] |
| 381 | w.set_trbuff(true); | 371 | w.set_trbuff(true); |
| 382 | 372 | ||
| 383 | #[cfg(dma_v2)] | 373 | #[cfg(dma_v2)] |
| 384 | w.set_chsel(_request); | 374 | w.set_chsel(_request); |
| 385 | 375 | ||
| 386 | if options.circular { | ||
| 387 | w.set_circ(vals::Circ::ENABLED); | ||
| 388 | debug!("Setting circular mode"); | ||
| 389 | } else { | ||
| 390 | w.set_circ(vals::Circ::DISABLED); | ||
| 391 | } | ||
| 392 | w.set_pburst(options.pburst.into()); | 376 | w.set_pburst(options.pburst.into()); |
| 393 | w.set_mburst(options.mburst.into()); | 377 | w.set_mburst(options.mburst.into()); |
| 394 | w.set_pfctrl(options.flow_ctrl.into()); | 378 | w.set_pfctrl(options.flow_ctrl.into()); |
