diff options
| author | Dario Nieuwenhuis <[email protected]> | 2023-07-24 14:42:15 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-07-24 14:42:15 +0000 |
| commit | 8d50f8a3d3e5a50cd266ca45e221565e5982e744 (patch) | |
| tree | 4fbc1aaf5db6919a527fa32998f7ed4740b5f573 | |
| parent | 7fc138c91e0db51dc4afb3cd2610dcb72cd92d71 (diff) | |
| parent | 622fcb0e107923ad5c3537924a21769fd9d25c62 (diff) | |
Merge pull request #1678 from JuliDi/dac-v3
Add DAC v3
| -rw-r--r-- | embassy-stm32/src/dac/mod.rs | 57 | ||||
| -rw-r--r-- | embassy-stm32/src/dma/dma.rs | 19 | ||||
| -rw-r--r-- | embassy-stm32/src/sdmmc/mod.rs | 3 |
3 files changed, 65 insertions, 14 deletions
diff --git a/embassy-stm32/src/dac/mod.rs b/embassy-stm32/src/dac/mod.rs index 0f3c5f630..979748bb4 100644 --- a/embassy-stm32/src/dac/mod.rs +++ b/embassy-stm32/src/dac/mod.rs | |||
| @@ -38,11 +38,30 @@ impl Channel { | |||
| 38 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | 38 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] |
| 39 | /// Trigger sources for CH1 | 39 | /// Trigger sources for CH1 |
| 40 | pub enum Ch1Trigger { | 40 | pub enum Ch1Trigger { |
| 41 | Tim6, | 41 | #[cfg(dac_v3)] |
| 42 | Tim1, | ||
| 43 | Tim2, | ||
| 44 | #[cfg(not(dac_v3))] | ||
| 42 | Tim3, | 45 | Tim3, |
| 46 | #[cfg(dac_v3)] | ||
| 47 | Tim4, | ||
| 48 | #[cfg(dac_v3)] | ||
| 49 | Tim5, | ||
| 50 | Tim6, | ||
| 43 | Tim7, | 51 | Tim7, |
| 52 | #[cfg(dac_v3)] | ||
| 53 | Tim8, | ||
| 44 | Tim15, | 54 | Tim15, |
| 45 | Tim2, | 55 | #[cfg(dac_v3)] |
| 56 | Hrtim1Dactrg1, | ||
| 57 | #[cfg(dac_v3)] | ||
| 58 | Hrtim1Dactrg2, | ||
| 59 | #[cfg(dac_v3)] | ||
| 60 | Lptim1, | ||
| 61 | #[cfg(dac_v3)] | ||
| 62 | Lptim2, | ||
| 63 | #[cfg(dac_v3)] | ||
| 64 | Lptim3, | ||
| 46 | Exti9, | 65 | Exti9, |
| 47 | Software, | 66 | Software, |
| 48 | } | 67 | } |
| @@ -50,14 +69,30 @@ pub enum Ch1Trigger { | |||
| 50 | impl Ch1Trigger { | 69 | impl Ch1Trigger { |
| 51 | fn tsel(&self) -> dac::vals::Tsel1 { | 70 | fn tsel(&self) -> dac::vals::Tsel1 { |
| 52 | match self { | 71 | match self { |
| 53 | Ch1Trigger::Tim6 => dac::vals::Tsel1::TIM6_TRGO, | 72 | #[cfg(dac_v3)] |
| 73 | Ch1Trigger::Tim1 => dac::vals::Tsel1::TIM1_TRGO, | ||
| 74 | Ch1Trigger::Tim2 => dac::vals::Tsel1::TIM2_TRGO, | ||
| 54 | #[cfg(not(dac_v3))] | 75 | #[cfg(not(dac_v3))] |
| 55 | Ch1Trigger::Tim3 => dac::vals::Tsel1::TIM3_TRGO, | 76 | Ch1Trigger::Tim3 => dac::vals::Tsel1::TIM3_TRGO, |
| 56 | #[cfg(dac_v3)] | 77 | #[cfg(dac_v3)] |
| 57 | Ch1Trigger::Tim3 => dac::vals::Tsel1::TIM1_TRGO, | 78 | Ch1Trigger::Tim4 => dac::vals::Tsel1::TIM4_TRGO, |
| 79 | #[cfg(dac_v3)] | ||
| 80 | Ch1Trigger::Tim5 => dac::vals::Tsel1::TIM5_TRGO, | ||
| 81 | Ch1Trigger::Tim6 => dac::vals::Tsel1::TIM6_TRGO, | ||
| 58 | Ch1Trigger::Tim7 => dac::vals::Tsel1::TIM7_TRGO, | 82 | Ch1Trigger::Tim7 => dac::vals::Tsel1::TIM7_TRGO, |
| 83 | #[cfg(dac_v3)] | ||
| 84 | Ch1Trigger::Tim8 => dac::vals::Tsel1::TIM8_TRGO, | ||
| 59 | Ch1Trigger::Tim15 => dac::vals::Tsel1::TIM15_TRGO, | 85 | Ch1Trigger::Tim15 => dac::vals::Tsel1::TIM15_TRGO, |
| 60 | Ch1Trigger::Tim2 => dac::vals::Tsel1::TIM2_TRGO, | 86 | #[cfg(dac_v3)] |
| 87 | Ch1Trigger::Hrtim1Dactrg1 => dac::vals::Tsel1::HRTIM1_DACTRG1, | ||
| 88 | #[cfg(dac_v3)] | ||
| 89 | Ch1Trigger::Hrtim1Dactrg2 => dac::vals::Tsel1::HRTIM1_DACTRG2, | ||
| 90 | #[cfg(dac_v3)] | ||
| 91 | Ch1Trigger::Lptim1 => dac::vals::Tsel1::LPTIM1_OUT, | ||
| 92 | #[cfg(dac_v3)] | ||
| 93 | Ch1Trigger::Lptim2 => dac::vals::Tsel1::LPTIM2_OUT, | ||
| 94 | #[cfg(dac_v3)] | ||
| 95 | Ch1Trigger::Lptim3 => dac::vals::Tsel1::LPTIM3_OUT, | ||
| 61 | Ch1Trigger::Exti9 => dac::vals::Tsel1::EXTI9, | 96 | Ch1Trigger::Exti9 => dac::vals::Tsel1::EXTI9, |
| 62 | Ch1Trigger::Software => dac::vals::Tsel1::SOFTWARE, | 97 | Ch1Trigger::Software => dac::vals::Tsel1::SOFTWARE, |
| 63 | } | 98 | } |
| @@ -129,7 +164,7 @@ pub trait DacChannel<T: Instance, Tx> { | |||
| 129 | } | 164 | } |
| 130 | 165 | ||
| 131 | /// Set mode register of the given channel | 166 | /// Set mode register of the given channel |
| 132 | #[cfg(dac_v2)] | 167 | #[cfg(any(dac_v2, dac_v3))] |
| 133 | fn set_channel_mode(&mut self, val: u8) -> Result<(), Error> { | 168 | fn set_channel_mode(&mut self, val: u8) -> Result<(), Error> { |
| 134 | T::regs().mcr().modify(|reg| { | 169 | T::regs().mcr().modify(|reg| { |
| 135 | reg.set_mode(Self::CHANNEL.index(), val); | 170 | reg.set_mode(Self::CHANNEL.index(), val); |
| @@ -227,7 +262,7 @@ impl<'d, T: Instance, Tx> DacCh1<'d, T, Tx> { | |||
| 227 | 262 | ||
| 228 | // Configure each activated channel. All results can be `unwrap`ed since they | 263 | // Configure each activated channel. All results can be `unwrap`ed since they |
| 229 | // will only error if the channel is not configured (i.e. ch1, ch2 are false) | 264 | // will only error if the channel is not configured (i.e. ch1, ch2 are false) |
| 230 | #[cfg(dac_v2)] | 265 | #[cfg(any(dac_v2, dac_v3))] |
| 231 | dac.set_channel_mode(0).unwrap(); | 266 | dac.set_channel_mode(0).unwrap(); |
| 232 | dac.enable_channel().unwrap(); | 267 | dac.enable_channel().unwrap(); |
| 233 | dac.set_trigger_enable(true).unwrap(); | 268 | dac.set_trigger_enable(true).unwrap(); |
| @@ -253,7 +288,6 @@ impl<'d, T: Instance, Tx> DacCh1<'d, T, Tx> { | |||
| 253 | /// Note that for performance reasons in circular mode the transfer complete interrupt is disabled. | 288 | /// Note that for performance reasons in circular mode the transfer complete interrupt is disabled. |
| 254 | /// | 289 | /// |
| 255 | /// **Important:** Channel 1 has to be configured for the DAC instance! | 290 | /// **Important:** Channel 1 has to be configured for the DAC instance! |
| 256 | #[cfg(all(bdma, not(dma)))] // It currently only works with BDMA-only chips (DMA should theoretically work though) | ||
| 257 | pub async fn write(&mut self, data: ValueArray<'_>, circular: bool) -> Result<(), Error> | 291 | pub async fn write(&mut self, data: ValueArray<'_>, circular: bool) -> Result<(), Error> |
| 258 | where | 292 | where |
| 259 | Tx: DmaCh1<T>, | 293 | Tx: DmaCh1<T>, |
| @@ -342,7 +376,7 @@ impl<'d, T: Instance, Tx> DacCh2<'d, T, Tx> { | |||
| 342 | 376 | ||
| 343 | // Configure each activated channel. All results can be `unwrap`ed since they | 377 | // Configure each activated channel. All results can be `unwrap`ed since they |
| 344 | // will only error if the channel is not configured (i.e. ch1, ch2 are false) | 378 | // will only error if the channel is not configured (i.e. ch1, ch2 are false) |
| 345 | #[cfg(dac_v2)] | 379 | #[cfg(any(dac_v2, dac_v3))] |
| 346 | dac.set_channel_mode(0).unwrap(); | 380 | dac.set_channel_mode(0).unwrap(); |
| 347 | dac.enable_channel().unwrap(); | 381 | dac.enable_channel().unwrap(); |
| 348 | dac.set_trigger_enable(true).unwrap(); | 382 | dac.set_trigger_enable(true).unwrap(); |
| @@ -366,7 +400,6 @@ impl<'d, T: Instance, Tx> DacCh2<'d, T, Tx> { | |||
| 366 | /// Note that for performance reasons in circular mode the transfer complete interrupt is disabled. | 400 | /// Note that for performance reasons in circular mode the transfer complete interrupt is disabled. |
| 367 | /// | 401 | /// |
| 368 | /// **Important:** Channel 2 has to be configured for the DAC instance! | 402 | /// **Important:** Channel 2 has to be configured for the DAC instance! |
| 369 | #[cfg(all(bdma, not(dma)))] // It currently only works with BDMA-only chips (DMA should theoretically work though) | ||
| 370 | pub async fn write(&mut self, data: ValueArray<'_>, circular: bool) -> Result<(), Error> | 403 | pub async fn write(&mut self, data: ValueArray<'_>, circular: bool) -> Result<(), Error> |
| 371 | where | 404 | where |
| 372 | Tx: DmaCh2<T>, | 405 | Tx: DmaCh2<T>, |
| @@ -465,12 +498,12 @@ impl<'d, T: Instance, TxCh1, TxCh2> Dac<'d, T, TxCh1, TxCh2> { | |||
| 465 | 498 | ||
| 466 | // Configure each activated channel. All results can be `unwrap`ed since they | 499 | // Configure each activated channel. All results can be `unwrap`ed since they |
| 467 | // will only error if the channel is not configured (i.e. ch1, ch2 are false) | 500 | // will only error if the channel is not configured (i.e. ch1, ch2 are false) |
| 468 | #[cfg(dac_v2)] | 501 | #[cfg(any(dac_v2, dac_v3))] |
| 469 | dac_ch1.set_channel_mode(0).unwrap(); | 502 | dac_ch1.set_channel_mode(0).unwrap(); |
| 470 | dac_ch1.enable_channel().unwrap(); | 503 | dac_ch1.enable_channel().unwrap(); |
| 471 | dac_ch1.set_trigger_enable(true).unwrap(); | 504 | dac_ch1.set_trigger_enable(true).unwrap(); |
| 472 | 505 | ||
| 473 | #[cfg(dac_v2)] | 506 | #[cfg(any(dac_v2, dac_v3))] |
| 474 | dac_ch2.set_channel_mode(0).unwrap(); | 507 | dac_ch2.set_channel_mode(0).unwrap(); |
| 475 | dac_ch2.enable_channel().unwrap(); | 508 | dac_ch2.enable_channel().unwrap(); |
| 476 | dac_ch2.set_trigger_enable(true).unwrap(); | 509 | dac_ch2.set_trigger_enable(true).unwrap(); |
diff --git a/embassy-stm32/src/dma/dma.rs b/embassy-stm32/src/dma/dma.rs index 58d438af8..f14084599 100644 --- a/embassy-stm32/src/dma/dma.rs +++ b/embassy-stm32/src/dma/dma.rs | |||
| @@ -28,6 +28,12 @@ pub struct TransferOptions { | |||
| 28 | pub flow_ctrl: FlowControl, | 28 | pub flow_ctrl: FlowControl, |
| 29 | /// FIFO threshold for DMA FIFO mode. If none, direct mode is used. | 29 | /// FIFO threshold for DMA FIFO mode. If none, direct mode is used. |
| 30 | pub fifo_threshold: Option<FifoThreshold>, | 30 | pub fifo_threshold: Option<FifoThreshold>, |
| 31 | /// Enable circular DMA | ||
| 32 | pub circular: bool, | ||
| 33 | /// Enable half transfer interrupt | ||
| 34 | pub half_transfer_ir: bool, | ||
| 35 | /// Enable transfer complete interrupt | ||
| 36 | pub complete_transfer_ir: bool, | ||
| 31 | } | 37 | } |
| 32 | 38 | ||
| 33 | impl Default for TransferOptions { | 39 | impl Default for TransferOptions { |
| @@ -37,6 +43,9 @@ impl Default for TransferOptions { | |||
| 37 | mburst: Burst::Single, | 43 | mburst: Burst::Single, |
| 38 | flow_ctrl: FlowControl::Dma, | 44 | flow_ctrl: FlowControl::Dma, |
| 39 | fifo_threshold: None, | 45 | fifo_threshold: None, |
| 46 | circular: false, | ||
| 47 | half_transfer_ir: false, | ||
| 48 | complete_transfer_ir: true, | ||
| 40 | } | 49 | } |
| 41 | } | 50 | } |
| 42 | } | 51 | } |
| @@ -365,7 +374,13 @@ impl<'a, C: Channel> Transfer<'a, C> { | |||
| 365 | }); | 374 | }); |
| 366 | w.set_pinc(vals::Inc::FIXED); | 375 | w.set_pinc(vals::Inc::FIXED); |
| 367 | w.set_teie(true); | 376 | w.set_teie(true); |
| 368 | w.set_tcie(true); | 377 | w.set_tcie(options.complete_transfer_ir); |
| 378 | if options.circular { | ||
| 379 | w.set_circ(vals::Circ::ENABLED); | ||
| 380 | debug!("Setting circular mode"); | ||
| 381 | } else { | ||
| 382 | w.set_circ(vals::Circ::DISABLED); | ||
| 383 | } | ||
| 369 | #[cfg(dma_v1)] | 384 | #[cfg(dma_v1)] |
| 370 | w.set_trbuff(true); | 385 | w.set_trbuff(true); |
| 371 | 386 | ||
| @@ -646,7 +661,7 @@ impl<'a, C: Channel, W: Word> RingBuffer<'a, C, W> { | |||
| 646 | w.set_minc(vals::Inc::INCREMENTED); | 661 | w.set_minc(vals::Inc::INCREMENTED); |
| 647 | w.set_pinc(vals::Inc::FIXED); | 662 | w.set_pinc(vals::Inc::FIXED); |
| 648 | w.set_teie(true); | 663 | w.set_teie(true); |
| 649 | w.set_htie(true); | 664 | w.set_htie(options.half_transfer_ir); |
| 650 | w.set_tcie(true); | 665 | w.set_tcie(true); |
| 651 | w.set_circ(vals::Circ::ENABLED); | 666 | w.set_circ(vals::Circ::ENABLED); |
| 652 | #[cfg(dma_v1)] | 667 | #[cfg(dma_v1)] |
diff --git a/embassy-stm32/src/sdmmc/mod.rs b/embassy-stm32/src/sdmmc/mod.rs index 698292bff..434c56a48 100644 --- a/embassy-stm32/src/sdmmc/mod.rs +++ b/embassy-stm32/src/sdmmc/mod.rs | |||
| @@ -225,6 +225,9 @@ const DMA_TRANSFER_OPTIONS: crate::dma::TransferOptions = crate::dma::TransferOp | |||
| 225 | mburst: crate::dma::Burst::Incr4, | 225 | mburst: crate::dma::Burst::Incr4, |
| 226 | flow_ctrl: crate::dma::FlowControl::Peripheral, | 226 | flow_ctrl: crate::dma::FlowControl::Peripheral, |
| 227 | fifo_threshold: Some(crate::dma::FifoThreshold::Full), | 227 | fifo_threshold: Some(crate::dma::FifoThreshold::Full), |
| 228 | circular: false, | ||
| 229 | half_transfer_ir: false, | ||
| 230 | complete_transfer_ir: true, | ||
| 228 | }; | 231 | }; |
| 229 | #[cfg(all(sdmmc_v1, not(dma)))] | 232 | #[cfg(all(sdmmc_v1, not(dma)))] |
| 230 | const DMA_TRANSFER_OPTIONS: crate::dma::TransferOptions = crate::dma::TransferOptions { | 233 | const DMA_TRANSFER_OPTIONS: crate::dma::TransferOptions = crate::dma::TransferOptions { |
