Content-Length: 377921 | pFad | http://github.com/stm32-rs/stm32f4xx-hal/commit/#start-of-content

6843523D Merge pull request #838 from X-yl/i2c-dma · stm32-rs/stm32f4xx-hal@4e0f0cd · GitHub
Skip to content

Commit 4e0f0cd

Browse files
authored
Merge pull request #838 from X-yl/i2c-dma
i2c: Implement embedded_hal::i2c::I2c for I2CMasterDMA
2 parents b4eef7d + 2cd553e commit 4e0f0cd

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [Unreleased]
99

10+
- Implement `embedded_hal::i2c::I2c` for `I2cMasterDma` [#838]
1011
- Back to `stm32f4`
1112
- Implement `Ptr`, `Sealed`, `Steal` for generic `Periph` [#834]
1213
- Unmacro `Adc` [#832]
@@ -23,6 +24,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
2324
[#832]: https://github.com/stm32-rs/stm32f4xx-hal/pull/832
2425
[#833]: https://github.com/stm32-rs/stm32f4xx-hal/pull/833
2526
[#834]: https://github.com/stm32-rs/stm32f4xx-hal/pull/834
27+
[#838]: https://github.com/stm32-rs/stm32f4xx-hal/pull/838
2628

2729
## [v0.22.1] - 2024-11-03
2830

src/i2c/dma.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ use crate::dma::{
66
traits::{Channel, DMASet, DmaFlagExt, PeriAddress, Stream, StreamISR},
77
ChannelX, MemoryToPeripheral, PeripheralToMemory, Transfer,
88
};
9+
use crate::hal::i2c;
10+
use crate::i2c::dma::i2c::{ErrorType, Operation};
911
use crate::ReadFlags;
1012

1113
use nb;
@@ -601,6 +603,36 @@ where
601603
}
602604
}
603605

606+
impl<I2C, TX_TRANSFER, RX_TRANSFER> ErrorType for I2CMasterDma<I2C, TX_TRANSFER, RX_TRANSFER>
607+
where
608+
I2C: Instance,
609+
TX_TRANSFER: DMATransfer<&'static [u8]>,
610+
RX_TRANSFER: DMATransfer<&'static mut [u8]>,
611+
{
612+
type Error = super::Error;
613+
}
614+
615+
impl<I2C, TX_TRANSFER, RX_TRANSFER> i2c::I2c for I2CMasterDma<I2C, TX_TRANSFER, RX_TRANSFER>
616+
where
617+
I2C: Instance,
618+
TX_TRANSFER: DMATransfer<&'static [u8]>,
619+
RX_TRANSFER: DMATransfer<&'static mut [u8]>,
620+
{
621+
fn transaction(
622+
&mut self,
623+
addr: u8,
624+
operations: &mut [Operation<'_>],
625+
) -> Result<(), Self::Error> {
626+
for operation in operations {
627+
match operation {
628+
Operation::Read(dest) => self.hal_i2c.read(addr, dest),
629+
Operation::Write(data) => self.hal_i2c.write(addr, data),
630+
}?;
631+
}
632+
Ok(())
633+
}
634+
}
635+
604636
impl<I2C, TX_STREAM, const TX_CH: u8> I2CMasterHandleIT
605637
for I2CMasterDma<I2C, TxDMA<I2C, TX_STREAM, TX_CH>, NoDMA>
606638
where

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/stm32-rs/stm32f4xx-hal/commit/#start-of-content

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy