aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2023-04-14 22:59:49 +0000
committerGitHub <[email protected]>2023-04-14 22:59:49 +0000
commitbe0f93ff378c14595eac9d5a259ef6448c3ac3f7 (patch)
tree3645e8afb44a5903af7d4d2a55e527868efbf068
parenta3ecf5caf614e17b2e1cb3d1f79d8313f2e71a63 (diff)
parent224eaaf79792a04a25bf7d5e768da41b2a030f7a (diff)
Merge #1368
1368: AFIT cleanup r=Dirbaio a=Dirbaio bors r+ Co-authored-by: Dario Nieuwenhuis <[email protected]>
-rw-r--r--embassy-embedded-hal/src/adapter.rs42
-rw-r--r--embassy-nrf/src/uarte.rs77
-rw-r--r--embassy-rp/src/uart/buffered.rs55
-rw-r--r--embassy-rp/src/uart/mod.rs55
-rw-r--r--embassy-stm32/Cargo.toml2
-rw-r--r--embassy-stm32/src/sdmmc/mod.rs56
-rw-r--r--embassy-stm32/src/usart/mod.rs67
-rw-r--r--examples/stm32f4/Cargo.toml2
8 files changed, 23 insertions, 333 deletions
diff --git a/embassy-embedded-hal/src/adapter.rs b/embassy-embedded-hal/src/adapter.rs
index ee919bd84..171ff6c9f 100644
--- a/embassy-embedded-hal/src/adapter.rs
+++ b/embassy-embedded-hal/src/adapter.rs
@@ -131,48 +131,6 @@ where
131 type Error = E; 131 type Error = E;
132} 132}
133 133
134#[cfg(feature = "_todo_embedded_hal_serial")]
135impl<T, E> embedded_hal_async::serial::Read for BlockingAsync<T>
136where
137 T: serial::Read<u8, Error = E>,
138 E: embedded_hal_1::serial::Error + 'static,
139{
140 type ReadFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where T: 'a;
141 fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> Self::ReadFuture<'a> {
142 async move {
143 let mut pos = 0;
144 while pos < buf.len() {
145 match self.wrapped.read() {
146 Err(nb::Error::WouldBlock) => {}
147 Err(nb::Error::Other(e)) => return Err(e),
148 Ok(b) => {
149 buf[pos] = b;
150 pos += 1;
151 }
152 }
153 }
154 Ok(())
155 }
156 }
157}
158
159#[cfg(feature = "_todo_embedded_hal_serial")]
160impl<T, E> embedded_hal_async::serial::Write for BlockingAsync<T>
161where
162 T: blocking::serial::Write<u8, Error = E> + serial::Read<u8, Error = E>,
163 E: embedded_hal_1::serial::Error + 'static,
164{
165 type WriteFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where T: 'a;
166 fn write<'a>(&'a mut self, buf: &'a [u8]) -> Self::WriteFuture<'a> {
167 async move { self.wrapped.bwrite_all(buf) }
168 }
169
170 type FlushFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where T: 'a;
171 fn flush(&mut self) -> Result<(), Self::Error> {
172 async move { self.wrapped.bflush() }
173 }
174}
175
176/// NOR flash wrapper 134/// NOR flash wrapper
177use embedded_storage::nor_flash::{ErrorType, NorFlash, ReadNorFlash}; 135use embedded_storage::nor_flash::{ErrorType, NorFlash, ReadNorFlash};
178use embedded_storage_async::nor_flash::{NorFlash as AsyncNorFlash, ReadNorFlash as AsyncReadNorFlash}; 136use embedded_storage_async::nor_flash::{NorFlash as AsyncNorFlash, ReadNorFlash as AsyncReadNorFlash};
diff --git a/embassy-nrf/src/uarte.rs b/embassy-nrf/src/uarte.rs
index e59b2332a..586c88b2d 100644
--- a/embassy-nrf/src/uarte.rs
+++ b/embassy-nrf/src/uarte.rs
@@ -992,80 +992,3 @@ mod eh1 {
992 type Error = Error; 992 type Error = Error;
993 } 993 }
994} 994}
995
996#[cfg(all(
997 feature = "unstable-traits",
998 feature = "nightly",
999 feature = "_todo_embedded_hal_serial"
1000))]
1001mod eha {
1002 use core::future::Future;
1003
1004 use super::*;
1005
1006 impl<'d, T: Instance> embedded_hal_async::serial::Read for Uarte<'d, T> {
1007 type ReadFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a;
1008
1009 fn read<'a>(&'a mut self, buffer: &'a mut [u8]) -> Self::ReadFuture<'a> {
1010 self.read(buffer)
1011 }
1012 }
1013
1014 impl<'d, T: Instance> embedded_hal_async::serial::Write for Uarte<'d, T> {
1015 type WriteFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a;
1016
1017 fn write<'a>(&'a mut self, buffer: &'a [u8]) -> Self::WriteFuture<'a> {
1018 self.write(buffer)
1019 }
1020
1021 type FlushFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a;
1022
1023 fn flush(&mut self) -> Result<(), Self::Error> {
1024 async move { Ok(()) }
1025 }
1026 }
1027
1028 impl<'d, T: Instance> embedded_hal_async::serial::Write for UarteTx<'d, T> {
1029 type WriteFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a;
1030
1031 fn write<'a>(&'a mut self, buffer: &'a [u8]) -> Self::WriteFuture<'a> {
1032 self.write(buffer)
1033 }
1034
1035 type FlushFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a;
1036
1037 fn flush(&mut self) -> Result<(), Self::Error> {
1038 async move { Ok(()) }
1039 }
1040 }
1041
1042 impl<'d, T: Instance> embedded_hal_async::serial::Read for UarteRx<'d, T> {
1043 type ReadFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a;
1044
1045 fn read<'a>(&'a mut self, buffer: &'a mut [u8]) -> Self::ReadFuture<'a> {
1046 self.read(buffer)
1047 }
1048 }
1049
1050 impl<'d, U: Instance, T: TimerInstance> embedded_hal_async::serial::Read for UarteWithIdle<'d, U, T> {
1051 type ReadFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a;
1052
1053 fn read<'a>(&'a mut self, buffer: &'a mut [u8]) -> Self::ReadFuture<'a> {
1054 self.read(buffer)
1055 }
1056 }
1057
1058 impl<'d, U: Instance, T: TimerInstance> embedded_hal_async::serial::Write for UarteWithIdle<'d, U, T> {
1059 type WriteFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a;
1060
1061 fn write<'a>(&'a mut self, buffer: &'a [u8]) -> Self::WriteFuture<'a> {
1062 self.write(buffer)
1063 }
1064
1065 type FlushFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a;
1066
1067 fn flush(&mut self) -> Result<(), Self::Error> {
1068 async move { Ok(()) }
1069 }
1070 }
1071}
diff --git a/embassy-rp/src/uart/buffered.rs b/embassy-rp/src/uart/buffered.rs
index c620ed08c..cb0461930 100644
--- a/embassy-rp/src/uart/buffered.rs
+++ b/embassy-rp/src/uart/buffered.rs
@@ -726,58 +726,3 @@ mod eh1 {
726 } 726 }
727 } 727 }
728} 728}
729
730#[cfg(all(
731 feature = "unstable-traits",
732 feature = "nightly",
733 feature = "_todo_embedded_hal_serial"
734))]
735mod eha {
736 use core::future::Future;
737
738 use super::*;
739
740 impl<'d, T: Instance> embedded_hal_async::serial::Write for BufferedUartTx<'d, T> {
741 type WriteFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a;
742
743 fn write<'a>(&'a mut self, buf: &'a [u8]) -> Self::WriteFuture<'a> {
744 Self::write(buf)
745 }
746
747 type FlushFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a;
748
749 fn flush<'a>(&'a mut self) -> Self::FlushFuture<'a> {
750 Self::flush()
751 }
752 }
753
754 impl<'d, T: Instance> embedded_hal_async::serial::Read for BufferedUartRx<'d, T> {
755 type ReadFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a;
756
757 fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> Self::ReadFuture<'a> {
758 Self::read(buf)
759 }
760 }
761
762 impl<'d, T: Instance> embedded_hal_async::serial::Write for BufferedUart<'d, T> {
763 type WriteFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a;
764
765 fn write<'a>(&'a mut self, buf: &'a [u8]) -> Self::WriteFuture<'a> {
766 BufferedUartTx::<'d, T>::write(buf)
767 }
768
769 type FlushFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a;
770
771 fn flush<'a>(&'a mut self) -> Self::FlushFuture<'a> {
772 BufferedUartTx::<'d, T>::flush()
773 }
774 }
775
776 impl<'d, T: Instance> embedded_hal_async::serial::Read for BufferedUart<'d, T> {
777 type ReadFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a;
778
779 fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> Self::ReadFuture<'a> {
780 BufferedUartRx::<'d, T>::read(buf)
781 }
782 }
783}
diff --git a/embassy-rp/src/uart/mod.rs b/embassy-rp/src/uart/mod.rs
index a945f2295..7122930f5 100644
--- a/embassy-rp/src/uart/mod.rs
+++ b/embassy-rp/src/uart/mod.rs
@@ -651,61 +651,6 @@ mod eh1 {
651 } 651 }
652} 652}
653 653
654#[cfg(all(
655 feature = "unstable-traits",
656 feature = "nightly",
657 feature = "_todo_embedded_hal_serial"
658))]
659mod eha {
660 use core::future::Future;
661
662 use super::*;
663
664 impl<'d, T: Instance, M: Mode> embedded_hal_async::serial::Write for UartTx<'d, T, M> {
665 type WriteFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a;
666
667 fn write<'a>(&'a mut self, buf: &'a [u8]) -> Self::WriteFuture<'a> {
668 self.write(buf)
669 }
670
671 type FlushFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a;
672
673 fn flush<'a>(&'a mut self) -> Self::FlushFuture<'a> {
674 async move { Ok(()) }
675 }
676 }
677
678 impl<'d, T: Instance, M: Mode> embedded_hal_async::serial::Read for UartRx<'d, T, M> {
679 type ReadFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a;
680
681 fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> Self::ReadFuture<'a> {
682 self.read(buf)
683 }
684 }
685
686 impl<'d, T: Instance, M: Mode> embedded_hal_async::serial::Write for Uart<'d, T, M> {
687 type WriteFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a;
688
689 fn write<'a>(&'a mut self, buf: &'a [u8]) -> Self::WriteFuture<'a> {
690 self.write(buf)
691 }
692
693 type FlushFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a;
694
695 fn flush<'a>(&'a mut self) -> Self::FlushFuture<'a> {
696 async move { Ok(()) }
697 }
698 }
699
700 impl<'d, T: Instance, M: Mode> embedded_hal_async::serial::Read for Uart<'d, T, M> {
701 type ReadFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a;
702
703 fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> Self::ReadFuture<'a> {
704 self.read(buf)
705 }
706 }
707}
708
709mod sealed { 654mod sealed {
710 use super::*; 655 use super::*;
711 656
diff --git a/embassy-stm32/Cargo.toml b/embassy-stm32/Cargo.toml
index 969dc3b70..18b1d4d0e 100644
--- a/embassy-stm32/Cargo.toml
+++ b/embassy-stm32/Cargo.toml
@@ -55,7 +55,7 @@ cortex-m = "0.7.6"
55futures = { version = "0.3.17", default-features = false, features = ["async-await"] } 55futures = { version = "0.3.17", default-features = false, features = ["async-await"] }
56rand_core = "0.6.3" 56rand_core = "0.6.3"
57sdio-host = "0.5.0" 57sdio-host = "0.5.0"
58embedded-sdmmc = { git = "https://github.com/embassy-rs/embedded-sdmmc-rs", rev = "46d1b1c2ff13e31e282ec1e352421721694f126a", optional = true } 58embedded-sdmmc = { git = "https://github.com/embassy-rs/embedded-sdmmc-rs", rev = "a4f293d3a6f72158385f79c98634cb8a14d0d2fc", optional = true }
59critical-section = "1.1" 59critical-section = "1.1"
60atomic-polyfill = "1.0.1" 60atomic-polyfill = "1.0.1"
61stm32-metapac = "6" 61stm32-metapac = "6"
diff --git a/embassy-stm32/src/sdmmc/mod.rs b/embassy-stm32/src/sdmmc/mod.rs
index 03d24dcb1..ac00b5176 100644
--- a/embassy-stm32/src/sdmmc/mod.rs
+++ b/embassy-stm32/src/sdmmc/mod.rs
@@ -1651,8 +1651,6 @@ foreach_peripheral!(
1651 1651
1652#[cfg(feature = "embedded-sdmmc")] 1652#[cfg(feature = "embedded-sdmmc")]
1653mod sdmmc_rs { 1653mod sdmmc_rs {
1654 use core::future::Future;
1655
1656 use embedded_sdmmc::{Block, BlockCount, BlockDevice, BlockIdx}; 1654 use embedded_sdmmc::{Block, BlockCount, BlockDevice, BlockIdx};
1657 1655
1658 use super::*; 1656 use super::*;
@@ -1660,49 +1658,37 @@ mod sdmmc_rs {
1660 impl<'d, T: Instance, Dma: SdmmcDma<T>> BlockDevice for Sdmmc<'d, T, Dma> { 1658 impl<'d, T: Instance, Dma: SdmmcDma<T>> BlockDevice for Sdmmc<'d, T, Dma> {
1661 type Error = Error; 1659 type Error = Error;
1662 1660
1663 type ReadFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a 1661 async fn read(
1664 where 1662 &mut self,
1665 Self: 'a; 1663 blocks: &mut [Block],
1666
1667 type WriteFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a
1668 where
1669 Self: 'a;
1670
1671 fn read<'a>(
1672 &'a mut self,
1673 blocks: &'a mut [Block],
1674 start_block_idx: BlockIdx, 1664 start_block_idx: BlockIdx,
1675 _reason: &str, 1665 _reason: &str,
1676 ) -> Self::ReadFuture<'a> { 1666 ) -> Result<(), Self::Error> {
1677 async move { 1667 let mut address = start_block_idx.0;
1678 let mut address = start_block_idx.0;
1679 1668
1680 for block in blocks.iter_mut() { 1669 for block in blocks.iter_mut() {
1681 let block: &mut [u8; 512] = &mut block.contents; 1670 let block: &mut [u8; 512] = &mut block.contents;
1682 1671
1683 // NOTE(unsafe) Block uses align(4) 1672 // NOTE(unsafe) Block uses align(4)
1684 let block = unsafe { &mut *(block as *mut _ as *mut DataBlock) }; 1673 let block = unsafe { &mut *(block as *mut _ as *mut DataBlock) };
1685 self.read_block(address, block).await?; 1674 self.read_block(address, block).await?;
1686 address += 1; 1675 address += 1;
1687 }
1688 Ok(())
1689 } 1676 }
1677 Ok(())
1690 } 1678 }
1691 1679
1692 fn write<'a>(&'a mut self, blocks: &'a [Block], start_block_idx: BlockIdx) -> Self::WriteFuture<'a> { 1680 async fn write(&mut self, blocks: &[Block], start_block_idx: BlockIdx) -> Result<(), Self::Error> {
1693 async move { 1681 let mut address = start_block_idx.0;
1694 let mut address = start_block_idx.0;
1695 1682
1696 for block in blocks.iter() { 1683 for block in blocks.iter() {
1697 let block: &[u8; 512] = &block.contents; 1684 let block: &[u8; 512] = &block.contents;
1698 1685
1699 // NOTE(unsafe) DataBlock uses align 4 1686 // NOTE(unsafe) DataBlock uses align 4
1700 let block = unsafe { &*(block as *const _ as *const DataBlock) }; 1687 let block = unsafe { &*(block as *const _ as *const DataBlock) };
1701 self.write_block(address, block).await?; 1688 self.write_block(address, block).await?;
1702 address += 1; 1689 address += 1;
1703 }
1704 Ok(())
1705 } 1690 }
1691 Ok(())
1706 } 1692 }
1707 1693
1708 fn num_blocks(&self) -> Result<BlockCount, Self::Error> { 1694 fn num_blocks(&self) -> Result<BlockCount, Self::Error> {
diff --git a/embassy-stm32/src/usart/mod.rs b/embassy-stm32/src/usart/mod.rs
index a42eede18..8bbba305b 100644
--- a/embassy-stm32/src/usart/mod.rs
+++ b/embassy-stm32/src/usart/mod.rs
@@ -973,73 +973,6 @@ mod eio {
973 } 973 }
974} 974}
975 975
976#[cfg(all(
977 feature = "unstable-traits",
978 feature = "nightly",
979 feature = "_todo_embedded_hal_serial"
980))]
981mod eha {
982 use core::future::Future;
983
984 use super::*;
985
986 impl<'d, T: BasicInstance, TxDma> embedded_hal_async::serial::Write for UartTx<'d, T, TxDma>
987 where
988 TxDma: crate::usart::TxDma<T>,
989 {
990 type WriteFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a;
991
992 fn write<'a>(&'a mut self, buf: &'a [u8]) -> Self::WriteFuture<'a> {
993 self.write(buf)
994 }
995
996 type FlushFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a;
997
998 fn flush<'a>(&'a mut self) -> Self::FlushFuture<'a> {
999 async move { Ok(()) }
1000 }
1001 }
1002
1003 impl<'d, T: BasicInstance, RxDma> embedded_hal_async::serial::Read for UartRx<'d, T, RxDma>
1004 where
1005 RxDma: crate::usart::RxDma<T>,
1006 {
1007 type ReadFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a;
1008
1009 fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> Self::ReadFuture<'a> {
1010 self.read(buf)
1011 }
1012 }
1013
1014 impl<'d, T: BasicInstance, TxDma, RxDma> embedded_hal_async::serial::Write for Uart<'d, T, TxDma, RxDma>
1015 where
1016 TxDma: crate::usart::TxDma<T>,
1017 {
1018 type WriteFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a;
1019
1020 fn write<'a>(&'a mut self, buf: &'a [u8]) -> Self::WriteFuture<'a> {
1021 self.write(buf)
1022 }
1023
1024 type FlushFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a;
1025
1026 fn flush<'a>(&'a mut self) -> Self::FlushFuture<'a> {
1027 async move { Ok(()) }
1028 }
1029 }
1030
1031 impl<'d, T: BasicInstance, TxDma, RxDma> embedded_hal_async::serial::Read for Uart<'d, T, TxDma, RxDma>
1032 where
1033 RxDma: crate::usart::RxDma<T>,
1034 {
1035 type ReadFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a;
1036
1037 fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> Self::ReadFuture<'a> {
1038 self.read(buf)
1039 }
1040 }
1041}
1042
1043#[cfg(feature = "nightly")] 976#[cfg(feature = "nightly")]
1044pub use buffered::*; 977pub use buffered::*;
1045#[cfg(feature = "nightly")] 978#[cfg(feature = "nightly")]
diff --git a/examples/stm32f4/Cargo.toml b/examples/stm32f4/Cargo.toml
index 4b2f3d21c..1736769ef 100644
--- a/examples/stm32f4/Cargo.toml
+++ b/examples/stm32f4/Cargo.toml
@@ -8,7 +8,7 @@ license = "MIT OR Apache-2.0"
8embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } 8embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] }
9embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "executor-interrupt", "defmt", "integrated-timers", "arch-cortex-m", "executor-thread", "executor-interrupt"] } 9embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "executor-interrupt", "defmt", "integrated-timers", "arch-cortex-m", "executor-thread", "executor-interrupt"] }
10embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "unstable-traits", "tick-hz-32_768"] } 10embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "unstable-traits", "tick-hz-32_768"] }
11embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "unstable-traits", "defmt", "stm32f429zi", "unstable-pac", "memory-x", "time-driver-any", "exti"] } 11embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "unstable-traits", "defmt", "stm32f429zi", "unstable-pac", "memory-x", "time-driver-any", "exti", "embedded-sdmmc"] }
12embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } 12embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] }
13embassy-net = { version = "0.1.0", path = "../../embassy-net", features = ["defmt", "tcp", "dhcpv4", "medium-ethernet", "nightly"] } 13embassy-net = { version = "0.1.0", path = "../../embassy-net", features = ["defmt", "tcp", "dhcpv4", "medium-ethernet", "nightly"] }
14 14