diff options
340 files changed, 1318 insertions, 3012 deletions
diff --git a/docs/modules/ROOT/examples/basic/src/main.rs b/docs/modules/ROOT/examples/basic/src/main.rs index 8394f73b7..461741fd7 100644 --- a/docs/modules/ROOT/examples/basic/src/main.rs +++ b/docs/modules/ROOT/examples/basic/src/main.rs | |||
| @@ -2,18 +2,13 @@ | |||
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | use defmt_rtt as _; // global logger | ||
| 6 | use panic_probe as _; | ||
| 7 | |||
| 8 | use defmt::*; | 5 | use defmt::*; |
| 9 | |||
| 10 | use embassy::executor::Spawner; | 6 | use embassy::executor::Spawner; |
| 11 | use embassy::time::{Duration, Timer}; | 7 | use embassy::time::{Duration, Timer}; |
| 12 | use embassy_nrf::{ | 8 | use embassy_nrf::gpio::{Level, Output, OutputDrive}; |
| 13 | gpio::{Level, Output, OutputDrive}, | 9 | use embassy_nrf::peripherals::P0_13; |
| 14 | peripherals::P0_13, | 10 | use embassy_nrf::Peripherals; |
| 15 | Peripherals, | 11 | use {defmt_rtt as _, panic_probe as _}; // global logger |
| 16 | }; | ||
| 17 | 12 | ||
| 18 | #[embassy::task] | 13 | #[embassy::task] |
| 19 | async fn blinker(mut led: Output<'static, P0_13>, interval: Duration) { | 14 | async fn blinker(mut led: Output<'static, P0_13>, interval: Duration) { |
diff --git a/docs/modules/ROOT/examples/layer-by-layer/blinky-async/src/main.rs b/docs/modules/ROOT/examples/layer-by-layer/blinky-async/src/main.rs index 35726be64..56bc698da 100644 --- a/docs/modules/ROOT/examples/layer-by-layer/blinky-async/src/main.rs +++ b/docs/modules/ROOT/examples/layer-by-layer/blinky-async/src/main.rs | |||
| @@ -2,15 +2,11 @@ | |||
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | use defmt_rtt as _; | ||
| 6 | use panic_probe as _; | ||
| 7 | |||
| 8 | use embassy::executor::Spawner; | 5 | use embassy::executor::Spawner; |
| 9 | use embassy_stm32::{ | 6 | use embassy_stm32::exti::ExtiInput; |
| 10 | exti::ExtiInput, | 7 | use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; |
| 11 | gpio::{Input, Level, Output, Pull, Speed}, | 8 | use embassy_stm32::Peripherals; |
| 12 | Peripherals, | 9 | use {defmt_rtt as _, panic_probe as _}; |
| 13 | }; | ||
| 14 | 10 | ||
| 15 | #[embassy::main] | 11 | #[embassy::main] |
| 16 | async fn main(_s: Spawner, p: Peripherals) { | 12 | async fn main(_s: Spawner, p: Peripherals) { |
diff --git a/docs/modules/ROOT/examples/layer-by-layer/blinky-hal/src/main.rs b/docs/modules/ROOT/examples/layer-by-layer/blinky-hal/src/main.rs index 2064ea616..d0c9f4907 100644 --- a/docs/modules/ROOT/examples/layer-by-layer/blinky-hal/src/main.rs +++ b/docs/modules/ROOT/examples/layer-by-layer/blinky-hal/src/main.rs | |||
| @@ -2,10 +2,8 @@ | |||
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | 3 | ||
| 4 | use cortex_m_rt::entry; | 4 | use cortex_m_rt::entry; |
| 5 | use defmt_rtt as _; | ||
| 6 | use panic_probe as _; | ||
| 7 | |||
| 8 | use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; | 5 | use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; |
| 6 | use {defmt_rtt as _, panic_probe as _}; | ||
| 9 | 7 | ||
| 10 | #[entry] | 8 | #[entry] |
| 11 | fn main() -> ! { | 9 | fn main() -> ! { |
diff --git a/docs/modules/ROOT/examples/layer-by-layer/blinky-irq/src/main.rs b/docs/modules/ROOT/examples/layer-by-layer/blinky-irq/src/main.rs index 6a75384c4..743d0c342 100644 --- a/docs/modules/ROOT/examples/layer-by-layer/blinky-irq/src/main.rs +++ b/docs/modules/ROOT/examples/layer-by-layer/blinky-irq/src/main.rs | |||
| @@ -1,18 +1,15 @@ | |||
| 1 | #![no_std] | 1 | #![no_std] |
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | 3 | ||
| 4 | use defmt_rtt as _; | ||
| 5 | use panic_probe as _; | ||
| 6 | |||
| 7 | use core::cell::RefCell; | 4 | use core::cell::RefCell; |
| 5 | |||
| 8 | use cortex_m::interrupt::Mutex; | 6 | use cortex_m::interrupt::Mutex; |
| 9 | use cortex_m::peripheral::NVIC; | 7 | use cortex_m::peripheral::NVIC; |
| 10 | use cortex_m_rt::entry; | 8 | use cortex_m_rt::entry; |
| 11 | use embassy_stm32::{ | 9 | use embassy_stm32::gpio::{Input, Level, Output, Pin, Pull, Speed}; |
| 12 | gpio::{Input, Level, Output, Pin, Pull, Speed}, | 10 | use embassy_stm32::peripherals::{PB14, PC13}; |
| 13 | interrupt, pac, | 11 | use embassy_stm32::{interrupt, pac}; |
| 14 | peripherals::{PB14, PC13}, | 12 | use {defmt_rtt as _, panic_probe as _}; |
| 15 | }; | ||
| 16 | 13 | ||
| 17 | static BUTTON: Mutex<RefCell<Option<Input<'static, PC13>>>> = Mutex::new(RefCell::new(None)); | 14 | static BUTTON: Mutex<RefCell<Option<Input<'static, PC13>>>> = Mutex::new(RefCell::new(None)); |
| 18 | static LED: Mutex<RefCell<Option<Output<'static, PB14>>>> = Mutex::new(RefCell::new(None)); | 15 | static LED: Mutex<RefCell<Option<Output<'static, PB14>>>> = Mutex::new(RefCell::new(None)); |
diff --git a/docs/modules/ROOT/examples/layer-by-layer/blinky-pac/src/main.rs b/docs/modules/ROOT/examples/layer-by-layer/blinky-pac/src/main.rs index 239eac188..990d46cb6 100644 --- a/docs/modules/ROOT/examples/layer-by-layer/blinky-pac/src/main.rs +++ b/docs/modules/ROOT/examples/layer-by-layer/blinky-pac/src/main.rs | |||
| @@ -1,12 +1,8 @@ | |||
| 1 | #![no_std] | 1 | #![no_std] |
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | 3 | ||
| 4 | use defmt_rtt as _; | ||
| 5 | use panic_probe as _; | ||
| 6 | |||
| 7 | use stm32_metapac as pac; | ||
| 8 | |||
| 9 | use pac::gpio::vals; | 4 | use pac::gpio::vals; |
| 5 | use {defmt_rtt as _, panic_probe as _, stm32_metapac as pac}; | ||
| 10 | 6 | ||
| 11 | #[cortex_m_rt::entry] | 7 | #[cortex_m_rt::entry] |
| 12 | fn main() -> ! { | 8 | fn main() -> ! { |
| @@ -30,30 +26,18 @@ fn main() -> ! { | |||
| 30 | let gpioc = pac::GPIOC; | 26 | let gpioc = pac::GPIOC; |
| 31 | const BUTTON_PIN: usize = 13; | 27 | const BUTTON_PIN: usize = 13; |
| 32 | unsafe { | 28 | unsafe { |
| 33 | gpioc | 29 | gpioc.pupdr().modify(|w| w.set_pupdr(BUTTON_PIN, vals::Pupdr::PULLUP)); |
| 34 | .pupdr() | 30 | gpioc.otyper().modify(|w| w.set_ot(BUTTON_PIN, vals::Ot::PUSHPULL)); |
| 35 | .modify(|w| w.set_pupdr(BUTTON_PIN, vals::Pupdr::PULLUP)); | 31 | gpioc.moder().modify(|w| w.set_moder(BUTTON_PIN, vals::Moder::INPUT)); |
| 36 | gpioc | ||
| 37 | .otyper() | ||
| 38 | .modify(|w| w.set_ot(BUTTON_PIN, vals::Ot::PUSHPULL)); | ||
| 39 | gpioc | ||
| 40 | .moder() | ||
| 41 | .modify(|w| w.set_moder(BUTTON_PIN, vals::Moder::INPUT)); | ||
| 42 | } | 32 | } |
| 43 | 33 | ||
| 44 | // Setup LED | 34 | // Setup LED |
| 45 | let gpiob = pac::GPIOB; | 35 | let gpiob = pac::GPIOB; |
| 46 | const LED_PIN: usize = 14; | 36 | const LED_PIN: usize = 14; |
| 47 | unsafe { | 37 | unsafe { |
| 48 | gpiob | 38 | gpiob.pupdr().modify(|w| w.set_pupdr(LED_PIN, vals::Pupdr::FLOATING)); |
| 49 | .pupdr() | 39 | gpiob.otyper().modify(|w| w.set_ot(LED_PIN, vals::Ot::PUSHPULL)); |
| 50 | .modify(|w| w.set_pupdr(LED_PIN, vals::Pupdr::FLOATING)); | 40 | gpiob.moder().modify(|w| w.set_moder(LED_PIN, vals::Moder::OUTPUT)); |
| 51 | gpiob | ||
| 52 | .otyper() | ||
| 53 | .modify(|w| w.set_ot(LED_PIN, vals::Ot::PUSHPULL)); | ||
| 54 | gpiob | ||
| 55 | .moder() | ||
| 56 | .modify(|w| w.set_moder(LED_PIN, vals::Moder::OUTPUT)); | ||
| 57 | } | 41 | } |
| 58 | 42 | ||
| 59 | // Main loop | 43 | // Main loop |
diff --git a/embassy-boot/boot/src/lib.rs b/embassy-boot/boot/src/lib.rs index 87bb973a7..b18c88a6b 100644 --- a/embassy-boot/boot/src/lib.rs +++ b/embassy-boot/boot/src/lib.rs | |||
| @@ -202,8 +202,7 @@ impl<const PAGE_SIZE: usize> BootLoader<PAGE_SIZE> { | |||
| 202 | // Ensure we have enough progress pages to store copy progress | 202 | // Ensure we have enough progress pages to store copy progress |
| 203 | assert!( | 203 | assert!( |
| 204 | self.active.len() / PAGE_SIZE | 204 | self.active.len() / PAGE_SIZE |
| 205 | <= (self.state.len() | 205 | <= (self.state.len() - <<P as FlashProvider>::STATE as FlashConfig>::FLASH::WRITE_SIZE) |
| 206 | - <<P as FlashProvider>::STATE as FlashConfig>::FLASH::WRITE_SIZE) | ||
| 207 | / <<P as FlashProvider>::STATE as FlashConfig>::FLASH::WRITE_SIZE | 206 | / <<P as FlashProvider>::STATE as FlashConfig>::FLASH::WRITE_SIZE |
| 208 | ); | 207 | ); |
| 209 | 208 | ||
| @@ -226,15 +225,12 @@ impl<const PAGE_SIZE: usize> BootLoader<PAGE_SIZE> { | |||
| 226 | // Overwrite magic and reset progress | 225 | // Overwrite magic and reset progress |
| 227 | let fstate = p.state().flash(); | 226 | let fstate = p.state().flash(); |
| 228 | let aligned = Aligned( | 227 | let aligned = Aligned( |
| 229 | [!P::STATE::ERASE_VALUE; | 228 | [!P::STATE::ERASE_VALUE; <<P as FlashProvider>::STATE as FlashConfig>::FLASH::WRITE_SIZE], |
| 230 | <<P as FlashProvider>::STATE as FlashConfig>::FLASH::WRITE_SIZE], | ||
| 231 | ); | 229 | ); |
| 232 | fstate.write(self.state.from as u32, &aligned.0)?; | 230 | fstate.write(self.state.from as u32, &aligned.0)?; |
| 233 | fstate.erase(self.state.from as u32, self.state.to as u32)?; | 231 | fstate.erase(self.state.from as u32, self.state.to as u32)?; |
| 234 | let aligned = Aligned( | 232 | let aligned = |
| 235 | [BOOT_MAGIC; | 233 | Aligned([BOOT_MAGIC; <<P as FlashProvider>::STATE as FlashConfig>::FLASH::WRITE_SIZE]); |
| 236 | <<P as FlashProvider>::STATE as FlashConfig>::FLASH::WRITE_SIZE], | ||
| 237 | ); | ||
| 238 | fstate.write(self.state.from as u32, &aligned.0)?; | 234 | fstate.write(self.state.from as u32, &aligned.0)?; |
| 239 | } | 235 | } |
| 240 | } | 236 | } |
| @@ -262,10 +258,7 @@ impl<const PAGE_SIZE: usize> BootLoader<PAGE_SIZE> { | |||
| 262 | let flash = p.flash(); | 258 | let flash = p.flash(); |
| 263 | let mut aligned = Aligned([!P::ERASE_VALUE; P::FLASH::WRITE_SIZE]); | 259 | let mut aligned = Aligned([!P::ERASE_VALUE; P::FLASH::WRITE_SIZE]); |
| 264 | for i in 0..max_index { | 260 | for i in 0..max_index { |
| 265 | flash.read( | 261 | flash.read((self.state.from + write_size + i * write_size) as u32, &mut aligned.0)?; |
| 266 | (self.state.from + write_size + i * write_size) as u32, | ||
| 267 | &mut aligned.0, | ||
| 268 | )?; | ||
| 269 | if aligned.0 == [P::ERASE_VALUE; P::FLASH::WRITE_SIZE] { | 262 | if aligned.0 == [P::ERASE_VALUE; P::FLASH::WRITE_SIZE] { |
| 270 | return Ok(i); | 263 | return Ok(i); |
| 271 | } | 264 | } |
| @@ -311,9 +304,7 @@ impl<const PAGE_SIZE: usize> BootLoader<PAGE_SIZE> { | |||
| 311 | offset += chunk.len(); | 304 | offset += chunk.len(); |
| 312 | } | 305 | } |
| 313 | 306 | ||
| 314 | p.active() | 307 | p.active().flash().erase(to_page as u32, (to_page + PAGE_SIZE) as u32)?; |
| 315 | .flash() | ||
| 316 | .erase(to_page as u32, (to_page + PAGE_SIZE) as u32)?; | ||
| 317 | 308 | ||
| 318 | let mut offset = to_page; | 309 | let mut offset = to_page; |
| 319 | for chunk in buf.chunks(P::ACTIVE::BLOCK_SIZE) { | 310 | for chunk in buf.chunks(P::ACTIVE::BLOCK_SIZE) { |
| @@ -343,9 +334,7 @@ impl<const PAGE_SIZE: usize> BootLoader<PAGE_SIZE> { | |||
| 343 | offset += chunk.len(); | 334 | offset += chunk.len(); |
| 344 | } | 335 | } |
| 345 | 336 | ||
| 346 | p.dfu() | 337 | p.dfu().flash().erase(to_page as u32, (to_page + PAGE_SIZE) as u32)?; |
| 347 | .flash() | ||
| 348 | .erase(to_page as u32, (to_page + PAGE_SIZE) as u32)?; | ||
| 349 | 338 | ||
| 350 | let mut offset = to_page; | 339 | let mut offset = to_page; |
| 351 | for chunk in buf.chunks(P::DFU::BLOCK_SIZE) { | 340 | for chunk in buf.chunks(P::DFU::BLOCK_SIZE) { |
| @@ -609,9 +598,7 @@ impl FirmwareUpdater { | |||
| 609 | aligned[i] = 0; | 598 | aligned[i] = 0; |
| 610 | } | 599 | } |
| 611 | flash.write(self.state.from as u32, aligned).await?; | 600 | flash.write(self.state.from as u32, aligned).await?; |
| 612 | flash | 601 | flash.erase(self.state.from as u32, self.state.to as u32).await?; |
| 613 | .erase(self.state.from as u32, self.state.to as u32) | ||
| 614 | .await?; | ||
| 615 | 602 | ||
| 616 | for i in 0..aligned.len() { | 603 | for i in 0..aligned.len() { |
| 617 | aligned[i] = magic; | 604 | aligned[i] = magic; |
| @@ -677,13 +664,15 @@ impl FirmwareUpdater { | |||
| 677 | 664 | ||
| 678 | #[cfg(test)] | 665 | #[cfg(test)] |
| 679 | mod tests { | 666 | mod tests { |
| 680 | use super::*; | ||
| 681 | use core::convert::Infallible; | 667 | use core::convert::Infallible; |
| 682 | use core::future::Future; | 668 | use core::future::Future; |
| 669 | |||
| 683 | use embedded_storage::nor_flash::ErrorType; | 670 | use embedded_storage::nor_flash::ErrorType; |
| 684 | use embedded_storage_async::nor_flash::AsyncReadNorFlash; | 671 | use embedded_storage_async::nor_flash::AsyncReadNorFlash; |
| 685 | use futures::executor::block_on; | 672 | use futures::executor::block_on; |
| 686 | 673 | ||
| 674 | use super::*; | ||
| 675 | |||
| 687 | /* | 676 | /* |
| 688 | #[test] | 677 | #[test] |
| 689 | fn test_bad_magic() { | 678 | fn test_bad_magic() { |
| @@ -810,11 +799,7 @@ mod tests { | |||
| 810 | assert_eq!( | 799 | assert_eq!( |
| 811 | State::Swap, | 800 | State::Swap, |
| 812 | bootloader | 801 | bootloader |
| 813 | .prepare_boot(&mut MultiFlashProvider::new( | 802 | .prepare_boot(&mut MultiFlashProvider::new(&mut active, &mut state, &mut dfu,)) |
| 814 | &mut active, | ||
| 815 | &mut state, | ||
| 816 | &mut dfu, | ||
| 817 | )) | ||
| 818 | .unwrap() | 803 | .unwrap() |
| 819 | ); | 804 | ); |
| 820 | 805 | ||
| @@ -858,11 +843,7 @@ mod tests { | |||
| 858 | assert_eq!( | 843 | assert_eq!( |
| 859 | State::Swap, | 844 | State::Swap, |
| 860 | bootloader | 845 | bootloader |
| 861 | .prepare_boot(&mut MultiFlashProvider::new( | 846 | .prepare_boot(&mut MultiFlashProvider::new(&mut active, &mut state, &mut dfu,)) |
| 862 | &mut active, | ||
| 863 | &mut state, | ||
| 864 | &mut dfu, | ||
| 865 | )) | ||
| 866 | .unwrap() | 847 | .unwrap() |
| 867 | ); | 848 | ); |
| 868 | 849 | ||
| @@ -876,9 +857,7 @@ mod tests { | |||
| 876 | } | 857 | } |
| 877 | } | 858 | } |
| 878 | 859 | ||
| 879 | struct MemFlash<const SIZE: usize, const ERASE_SIZE: usize, const WRITE_SIZE: usize>( | 860 | struct MemFlash<const SIZE: usize, const ERASE_SIZE: usize, const WRITE_SIZE: usize>([u8; SIZE]); |
| 880 | [u8; SIZE], | ||
| 881 | ); | ||
| 882 | 861 | ||
| 883 | impl<const SIZE: usize, const ERASE_SIZE: usize, const WRITE_SIZE: usize> NorFlash | 862 | impl<const SIZE: usize, const ERASE_SIZE: usize, const WRITE_SIZE: usize> NorFlash |
| 884 | for MemFlash<SIZE, ERASE_SIZE, WRITE_SIZE> | 863 | for MemFlash<SIZE, ERASE_SIZE, WRITE_SIZE> |
| @@ -889,12 +868,7 @@ mod tests { | |||
| 889 | let from = from as usize; | 868 | let from = from as usize; |
| 890 | let to = to as usize; | 869 | let to = to as usize; |
| 891 | assert!(from % ERASE_SIZE == 0); | 870 | assert!(from % ERASE_SIZE == 0); |
| 892 | assert!( | 871 | assert!(to % ERASE_SIZE == 0, "To: {}, erase size: {}", to, ERASE_SIZE); |
| 893 | to % ERASE_SIZE == 0, | ||
| 894 | "To: {}, erase size: {}", | ||
| 895 | to, | ||
| 896 | ERASE_SIZE | ||
| 897 | ); | ||
| 898 | for i in from..to { | 872 | for i in from..to { |
| 899 | self.0[i] = 0xFF; | 873 | self.0[i] = 0xFF; |
| 900 | } | 874 | } |
diff --git a/embassy-boot/nrf/src/lib.rs b/embassy-boot/nrf/src/lib.rs index 9f891887c..2d6b837cb 100644 --- a/embassy-boot/nrf/src/lib.rs +++ b/embassy-boot/nrf/src/lib.rs | |||
| @@ -6,14 +6,10 @@ | |||
| 6 | 6 | ||
| 7 | mod fmt; | 7 | mod fmt; |
| 8 | 8 | ||
| 9 | pub use embassy_boot::{ | 9 | pub use embassy_boot::{FirmwareUpdater, FlashConfig, FlashProvider, Partition, SingleFlashProvider}; |
| 10 | FirmwareUpdater, FlashConfig, FlashProvider, Partition, SingleFlashProvider, | 10 | use embassy_nrf::nvmc::{Nvmc, PAGE_SIZE}; |
| 11 | }; | 11 | use embassy_nrf::peripherals::WDT; |
| 12 | use embassy_nrf::{ | 12 | use embassy_nrf::wdt; |
| 13 | nvmc::{Nvmc, PAGE_SIZE}, | ||
| 14 | peripherals::WDT, | ||
| 15 | wdt, | ||
| 16 | }; | ||
| 17 | use embedded_storage::nor_flash::{ErrorType, NorFlash, ReadNorFlash}; | 13 | use embedded_storage::nor_flash::{ErrorType, NorFlash, ReadNorFlash}; |
| 18 | 14 | ||
| 19 | pub struct BootLoader { | 15 | pub struct BootLoader { |
| @@ -95,9 +91,7 @@ impl BootLoader { | |||
| 95 | let mut cmd = mbr::sd_mbr_command_t { | 91 | let mut cmd = mbr::sd_mbr_command_t { |
| 96 | command: mbr::NRF_MBR_COMMANDS_SD_MBR_COMMAND_IRQ_FORWARD_ADDRESS_SET, | 92 | command: mbr::NRF_MBR_COMMANDS_SD_MBR_COMMAND_IRQ_FORWARD_ADDRESS_SET, |
| 97 | params: mbr::sd_mbr_command_t__bindgen_ty_1 { | 93 | params: mbr::sd_mbr_command_t__bindgen_ty_1 { |
| 98 | irq_forward_address_set: mbr::sd_mbr_command_irq_forward_address_set_t { | 94 | irq_forward_address_set: mbr::sd_mbr_command_irq_forward_address_set_t { address: addr }, |
| 99 | address: addr, | ||
| 100 | }, | ||
| 101 | }, | 95 | }, |
| 102 | }; | 96 | }; |
| 103 | let ret = mbr::sd_mbr_command(&mut cmd); | 97 | let ret = mbr::sd_mbr_command(&mut cmd); |
diff --git a/embassy-boot/nrf/src/main.rs b/embassy-boot/nrf/src/main.rs index 0ccd3774d..bc7e0755f 100644 --- a/embassy-boot/nrf/src/main.rs +++ b/embassy-boot/nrf/src/main.rs | |||
| @@ -2,10 +2,8 @@ | |||
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | 3 | ||
| 4 | use cortex_m_rt::{entry, exception}; | 4 | use cortex_m_rt::{entry, exception}; |
| 5 | |||
| 6 | #[cfg(feature = "defmt")] | 5 | #[cfg(feature = "defmt")] |
| 7 | use defmt_rtt as _; | 6 | use defmt_rtt as _; |
| 8 | |||
| 9 | use embassy_boot_nrf::*; | 7 | use embassy_boot_nrf::*; |
| 10 | use embassy_nrf::nvmc::Nvmc; | 8 | use embassy_nrf::nvmc::Nvmc; |
| 11 | 9 | ||
diff --git a/embassy-boot/stm32/src/lib.rs b/embassy-boot/stm32/src/lib.rs index 8c6e65507..5a4f2d058 100644 --- a/embassy-boot/stm32/src/lib.rs +++ b/embassy-boot/stm32/src/lib.rs | |||
| @@ -6,9 +6,7 @@ | |||
| 6 | 6 | ||
| 7 | mod fmt; | 7 | mod fmt; |
| 8 | 8 | ||
| 9 | pub use embassy_boot::{ | 9 | pub use embassy_boot::{FirmwareUpdater, FlashConfig, FlashProvider, Partition, SingleFlashProvider, State}; |
| 10 | FirmwareUpdater, FlashConfig, FlashProvider, Partition, SingleFlashProvider, State, | ||
| 11 | }; | ||
| 12 | use embedded_storage::nor_flash::NorFlash; | 10 | use embedded_storage::nor_flash::NorFlash; |
| 13 | 11 | ||
| 14 | pub struct BootLoader<const PAGE_SIZE: usize> { | 12 | pub struct BootLoader<const PAGE_SIZE: usize> { |
diff --git a/embassy-boot/stm32/src/main.rs b/embassy-boot/stm32/src/main.rs index d79b14c67..45c511ced 100644 --- a/embassy-boot/stm32/src/main.rs +++ b/embassy-boot/stm32/src/main.rs | |||
| @@ -2,10 +2,8 @@ | |||
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | 3 | ||
| 4 | use cortex_m_rt::{entry, exception}; | 4 | use cortex_m_rt::{entry, exception}; |
| 5 | |||
| 6 | #[cfg(feature = "defmt")] | 5 | #[cfg(feature = "defmt")] |
| 7 | use defmt_rtt as _; | 6 | use defmt_rtt as _; |
| 8 | |||
| 9 | use embassy_boot_stm32::*; | 7 | use embassy_boot_stm32::*; |
| 10 | use embassy_stm32::flash::{Flash, ERASE_SIZE}; | 8 | use embassy_stm32::flash::{Flash, ERASE_SIZE}; |
| 11 | 9 | ||
diff --git a/embassy-cortex-m/src/executor.rs b/embassy-cortex-m/src/executor.rs index 63a1519cf..34f3ec236 100644 --- a/embassy-cortex-m/src/executor.rs +++ b/embassy-cortex-m/src/executor.rs | |||
| @@ -1,9 +1,9 @@ | |||
| 1 | use core::marker::PhantomData; | 1 | use core::marker::PhantomData; |
| 2 | 2 | ||
| 3 | use crate::interrupt::{Interrupt, InterruptExt}; | 3 | pub use embassy::executor::Executor; |
| 4 | use embassy::executor::{raw, SendSpawner}; | 4 | use embassy::executor::{raw, SendSpawner}; |
| 5 | 5 | ||
| 6 | pub use embassy::executor::Executor; | 6 | use crate::interrupt::{Interrupt, InterruptExt}; |
| 7 | 7 | ||
| 8 | fn pend_by_number(n: u16) { | 8 | fn pend_by_number(n: u16) { |
| 9 | #[derive(Clone, Copy)] | 9 | #[derive(Clone, Copy)] |
diff --git a/embassy-cortex-m/src/interrupt.rs b/embassy-cortex-m/src/interrupt.rs index df2aad0ec..72686b402 100644 --- a/embassy-cortex-m/src/interrupt.rs +++ b/embassy-cortex-m/src/interrupt.rs | |||
| @@ -1,9 +1,8 @@ | |||
| 1 | use core::{mem, ptr}; | ||
| 2 | |||
| 1 | use atomic_polyfill::{compiler_fence, AtomicPtr, Ordering}; | 3 | use atomic_polyfill::{compiler_fence, AtomicPtr, Ordering}; |
| 2 | use core::mem; | ||
| 3 | use core::ptr; | ||
| 4 | use cortex_m::peripheral::NVIC; | 4 | use cortex_m::peripheral::NVIC; |
| 5 | use embassy_hal_common::Unborrow; | 5 | use embassy_hal_common::Unborrow; |
| 6 | |||
| 7 | pub use embassy_macros::cortex_m_interrupt_take as take; | 6 | pub use embassy_macros::cortex_m_interrupt_take as take; |
| 8 | 7 | ||
| 9 | /// Implementation detail, do not use outside embassy crates. | 8 | /// Implementation detail, do not use outside embassy crates. |
diff --git a/embassy-cortex-m/src/peripheral.rs b/embassy-cortex-m/src/peripheral.rs index 40277691c..5ff690831 100644 --- a/embassy-cortex-m/src/peripheral.rs +++ b/embassy-cortex-m/src/peripheral.rs | |||
| @@ -1,5 +1,6 @@ | |||
| 1 | use core::marker::PhantomData; | 1 | use core::marker::PhantomData; |
| 2 | use core::mem::MaybeUninit; | 2 | use core::mem::MaybeUninit; |
| 3 | |||
| 3 | use cortex_m::peripheral::scb::VectActive; | 4 | use cortex_m::peripheral::scb::VectActive; |
| 4 | use cortex_m::peripheral::{NVIC, SCB}; | 5 | use cortex_m::peripheral::{NVIC, SCB}; |
| 5 | 6 | ||
| @@ -53,13 +54,11 @@ impl<'a, S: PeripheralState> PeripheralMutex<'a, S> { | |||
| 53 | /// Create a new `PeripheralMutex` wrapping `irq`, with `init` initializing the initial state. | 54 | /// Create a new `PeripheralMutex` wrapping `irq`, with `init` initializing the initial state. |
| 54 | /// | 55 | /// |
| 55 | /// Registers `on_interrupt` as the `irq`'s handler, and enables it. | 56 | /// Registers `on_interrupt` as the `irq`'s handler, and enables it. |
| 56 | pub fn new( | 57 | pub fn new(irq: S::Interrupt, storage: &'a mut StateStorage<S>, init: impl FnOnce() -> S) -> Self { |
| 57 | irq: S::Interrupt, | ||
| 58 | storage: &'a mut StateStorage<S>, | ||
| 59 | init: impl FnOnce() -> S, | ||
| 60 | ) -> Self { | ||
| 61 | if can_be_preempted(&irq) { | 58 | if can_be_preempted(&irq) { |
| 62 | panic!("`PeripheralMutex` cannot be created in an interrupt with higher priority than the interrupt it wraps"); | 59 | panic!( |
| 60 | "`PeripheralMutex` cannot be created in an interrupt with higher priority than the interrupt it wraps" | ||
| 61 | ); | ||
| 63 | } | 62 | } |
| 64 | 63 | ||
| 65 | let state_ptr = storage.0.as_mut_ptr(); | 64 | let state_ptr = storage.0.as_mut_ptr(); |
diff --git a/embassy-embedded-hal/src/adapter.rs b/embassy-embedded-hal/src/adapter.rs index 033efb7ef..7d25d89fc 100644 --- a/embassy-embedded-hal/src/adapter.rs +++ b/embassy-embedded-hal/src/adapter.rs | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | use core::future::Future; | 1 | use core::future::Future; |
| 2 | use embedded_hal_02::blocking; | 2 | |
| 3 | use embedded_hal_02::serial; | 3 | use embedded_hal_02::{blocking, serial}; |
| 4 | 4 | ||
| 5 | /// BlockingAsync is a wrapper that implements async traits using blocking peripherals. This allows | 5 | /// BlockingAsync is a wrapper that implements async traits using blocking peripherals. This allows |
| 6 | /// driver writers to depend on the async traits while still supporting embedded-hal peripheral implementations. | 6 | /// driver writers to depend on the async traits while still supporting embedded-hal peripheral implementations. |
| @@ -25,9 +25,7 @@ impl<T> BlockingAsync<T> { | |||
| 25 | impl<T, E> embedded_hal_1::i2c::ErrorType for BlockingAsync<T> | 25 | impl<T, E> embedded_hal_1::i2c::ErrorType for BlockingAsync<T> |
| 26 | where | 26 | where |
| 27 | E: embedded_hal_1::i2c::Error + 'static, | 27 | E: embedded_hal_1::i2c::Error + 'static, |
| 28 | T: blocking::i2c::WriteRead<Error = E> | 28 | T: blocking::i2c::WriteRead<Error = E> + blocking::i2c::Read<Error = E> + blocking::i2c::Write<Error = E>, |
| 29 | + blocking::i2c::Read<Error = E> | ||
| 30 | + blocking::i2c::Write<Error = E>, | ||
| 31 | { | 29 | { |
| 32 | type Error = E; | 30 | type Error = E; |
| 33 | } | 31 | } |
| @@ -35,9 +33,7 @@ where | |||
| 35 | impl<T, E> embedded_hal_async::i2c::I2c for BlockingAsync<T> | 33 | impl<T, E> embedded_hal_async::i2c::I2c for BlockingAsync<T> |
| 36 | where | 34 | where |
| 37 | E: embedded_hal_1::i2c::Error + 'static, | 35 | E: embedded_hal_1::i2c::Error + 'static, |
| 38 | T: blocking::i2c::WriteRead<Error = E> | 36 | T: blocking::i2c::WriteRead<Error = E> + blocking::i2c::Read<Error = E> + blocking::i2c::Write<Error = E>, |
| 39 | + blocking::i2c::Read<Error = E> | ||
| 40 | + blocking::i2c::Write<Error = E>, | ||
| 41 | { | 37 | { |
| 42 | type WriteFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a; | 38 | type WriteFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a; |
| 43 | type ReadFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a; | 39 | type ReadFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a; |
| @@ -51,12 +47,7 @@ where | |||
| 51 | async move { self.wrapped.write(address, bytes) } | 47 | async move { self.wrapped.write(address, bytes) } |
| 52 | } | 48 | } |
| 53 | 49 | ||
| 54 | fn write_read<'a>( | 50 | fn write_read<'a>(&'a mut self, address: u8, bytes: &'a [u8], buffer: &'a mut [u8]) -> Self::WriteReadFuture<'a> { |
| 55 | &'a mut self, | ||
| 56 | address: u8, | ||
| 57 | bytes: &'a [u8], | ||
| 58 | buffer: &'a mut [u8], | ||
| 59 | ) -> Self::WriteReadFuture<'a> { | ||
| 60 | async move { self.wrapped.write_read(address, bytes, buffer) } | 51 | async move { self.wrapped.write_read(address, bytes, buffer) } |
| 61 | } | 52 | } |
| 62 | 53 | ||
diff --git a/embassy-embedded-hal/src/shared_bus/i2c.rs b/embassy-embedded-hal/src/shared_bus/i2c.rs index 5a180e897..e8131288a 100644 --- a/embassy-embedded-hal/src/shared_bus/i2c.rs +++ b/embassy-embedded-hal/src/shared_bus/i2c.rs | |||
| @@ -22,7 +22,9 @@ | |||
| 22 | //! let i2c_dev2 = I2cBusDevice::new(i2c_bus); | 22 | //! let i2c_dev2 = I2cBusDevice::new(i2c_bus); |
| 23 | //! let mpu = Mpu6050::new(i2c_dev2); | 23 | //! let mpu = Mpu6050::new(i2c_dev2); |
| 24 | //! ``` | 24 | //! ``` |
| 25 | use core::{fmt::Debug, future::Future}; | 25 | use core::fmt::Debug; |
| 26 | use core::future::Future; | ||
| 27 | |||
| 26 | use embassy::blocking_mutex::raw::RawMutex; | 28 | use embassy::blocking_mutex::raw::RawMutex; |
| 27 | use embassy::mutex::Mutex; | 29 | use embassy::mutex::Mutex; |
| 28 | use embedded_hal_async::i2c; | 30 | use embedded_hal_async::i2c; |
| @@ -70,9 +72,7 @@ where | |||
| 70 | fn read<'a>(&'a mut self, address: u8, buffer: &'a mut [u8]) -> Self::ReadFuture<'a> { | 72 | fn read<'a>(&'a mut self, address: u8, buffer: &'a mut [u8]) -> Self::ReadFuture<'a> { |
| 71 | async move { | 73 | async move { |
| 72 | let mut bus = self.bus.lock().await; | 74 | let mut bus = self.bus.lock().await; |
| 73 | bus.read(address, buffer) | 75 | bus.read(address, buffer).await.map_err(I2cBusDeviceError::I2c)?; |
| 74 | .await | ||
| 75 | .map_err(I2cBusDeviceError::I2c)?; | ||
| 76 | Ok(()) | 76 | Ok(()) |
| 77 | } | 77 | } |
| 78 | } | 78 | } |
| @@ -82,9 +82,7 @@ where | |||
| 82 | fn write<'a>(&'a mut self, address: u8, bytes: &'a [u8]) -> Self::WriteFuture<'a> { | 82 | fn write<'a>(&'a mut self, address: u8, bytes: &'a [u8]) -> Self::WriteFuture<'a> { |
| 83 | async move { | 83 | async move { |
| 84 | let mut bus = self.bus.lock().await; | 84 | let mut bus = self.bus.lock().await; |
| 85 | bus.write(address, bytes) | 85 | bus.write(address, bytes).await.map_err(I2cBusDeviceError::I2c)?; |
| 86 | .await | ||
| 87 | .map_err(I2cBusDeviceError::I2c)?; | ||
| 88 | Ok(()) | 86 | Ok(()) |
| 89 | } | 87 | } |
| 90 | } | 88 | } |
diff --git a/embassy-embedded-hal/src/shared_bus/spi.rs b/embassy-embedded-hal/src/shared_bus/spi.rs index 3ec064ba7..fd4b6d565 100644 --- a/embassy-embedded-hal/src/shared_bus/spi.rs +++ b/embassy-embedded-hal/src/shared_bus/spi.rs | |||
| @@ -25,10 +25,11 @@ | |||
| 25 | //! let spi_dev2 = SpiBusDevice::new(spi_bus, cs_pin2); | 25 | //! let spi_dev2 = SpiBusDevice::new(spi_bus, cs_pin2); |
| 26 | //! let display2 = ST7735::new(spi_dev2, dc2, rst2, Default::default(), 160, 128); | 26 | //! let display2 = ST7735::new(spi_dev2, dc2, rst2, Default::default(), 160, 128); |
| 27 | //! ``` | 27 | //! ``` |
| 28 | use core::{fmt::Debug, future::Future}; | 28 | use core::fmt::Debug; |
| 29 | use core::future::Future; | ||
| 30 | |||
| 29 | use embassy::blocking_mutex::raw::RawMutex; | 31 | use embassy::blocking_mutex::raw::RawMutex; |
| 30 | use embassy::mutex::Mutex; | 32 | use embassy::mutex::Mutex; |
| 31 | |||
| 32 | use embedded_hal_1::digital::blocking::OutputPin; | 33 | use embedded_hal_1::digital::blocking::OutputPin; |
| 33 | use embedded_hal_1::spi::ErrorType; | 34 | use embedded_hal_1::spi::ErrorType; |
| 34 | use embedded_hal_async::spi; | 35 | use embedded_hal_async::spi; |
diff --git a/embassy-hal-common/src/drop.rs b/embassy-hal-common/src/drop.rs index 3a90dd509..6ef716f99 100644 --- a/embassy-hal-common/src/drop.rs +++ b/embassy-hal-common/src/drop.rs | |||
| @@ -7,9 +7,7 @@ pub struct OnDrop<F: FnOnce()> { | |||
| 7 | 7 | ||
| 8 | impl<F: FnOnce()> OnDrop<F> { | 8 | impl<F: FnOnce()> OnDrop<F> { |
| 9 | pub fn new(f: F) -> Self { | 9 | pub fn new(f: F) -> Self { |
| 10 | Self { | 10 | Self { f: MaybeUninit::new(f) } |
| 11 | f: MaybeUninit::new(f), | ||
| 12 | } | ||
| 13 | } | 11 | } |
| 14 | 12 | ||
| 15 | pub fn defuse(self) { | 13 | pub fn defuse(self) { |
diff --git a/embassy-hal-common/src/ratio.rs b/embassy-hal-common/src/ratio.rs index ce7e4b1b9..9a8808a33 100644 --- a/embassy-hal-common/src/ratio.rs +++ b/embassy-hal-common/src/ratio.rs | |||
| @@ -1,4 +1,5 @@ | |||
| 1 | use core::ops::{Add, Div, Mul}; | 1 | use core::ops::{Add, Div, Mul}; |
| 2 | |||
| 2 | use num_traits::{CheckedAdd, CheckedDiv, CheckedMul}; | 3 | use num_traits::{CheckedAdd, CheckedDiv, CheckedMul}; |
| 3 | 4 | ||
| 4 | /// Represents the ratio between two numbers. | 5 | /// Represents the ratio between two numbers. |
diff --git a/embassy-lora/src/stm32wl/mod.rs b/embassy-lora/src/stm32wl/mod.rs index b5ce278dc..5f3dc17a7 100644 --- a/embassy-lora/src/stm32wl/mod.rs +++ b/embassy-lora/src/stm32wl/mod.rs | |||
| @@ -1,25 +1,20 @@ | |||
| 1 | //! A radio driver integration for the radio found on STM32WL family devices. | 1 | //! A radio driver integration for the radio found on STM32WL family devices. |
| 2 | use core::future::Future; | 2 | use core::future::Future; |
| 3 | use core::mem::MaybeUninit; | 3 | use core::mem::MaybeUninit; |
| 4 | |||
| 4 | use embassy::channel::signal::Signal; | 5 | use embassy::channel::signal::Signal; |
| 5 | use embassy_hal_common::unborrow; | 6 | use embassy_hal_common::unborrow; |
| 6 | use embassy_stm32::interrupt::InterruptExt; | 7 | use embassy_stm32::dma::NoDma; |
| 7 | use embassy_stm32::Unborrow; | 8 | use embassy_stm32::gpio::{AnyPin, Output}; |
| 8 | use embassy_stm32::{ | 9 | use embassy_stm32::interrupt::{InterruptExt, SUBGHZ_RADIO}; |
| 9 | dma::NoDma, | 10 | use embassy_stm32::subghz::{ |
| 10 | gpio::{AnyPin, Output}, | 11 | CalibrateImage, CfgIrq, CodingRate, HeaderType, Irq, LoRaBandwidth, LoRaModParams, LoRaPacketParams, LoRaSyncWord, |
| 11 | interrupt::SUBGHZ_RADIO, | 12 | Ocp, PaConfig, PaSel, PacketType, RampTime, RegMode, RfFreq, SpreadingFactor as SF, StandbyClk, Status, SubGhz, |
| 12 | subghz::{ | 13 | TcxoMode, TcxoTrim, Timeout, TxParams, |
| 13 | CalibrateImage, CfgIrq, CodingRate, HeaderType, Irq, LoRaBandwidth, LoRaModParams, | ||
| 14 | LoRaPacketParams, LoRaSyncWord, Ocp, PaConfig, PaSel, PacketType, RampTime, RegMode, | ||
| 15 | RfFreq, SpreadingFactor as SF, StandbyClk, Status, SubGhz, TcxoMode, TcxoTrim, Timeout, | ||
| 16 | TxParams, | ||
| 17 | }, | ||
| 18 | }; | ||
| 19 | use lorawan_device::async_device::{ | ||
| 20 | radio::{Bandwidth, PhyRxTx, RfConfig, RxQuality, SpreadingFactor, TxConfig}, | ||
| 21 | Timings, | ||
| 22 | }; | 14 | }; |
| 15 | use embassy_stm32::Unborrow; | ||
| 16 | use lorawan_device::async_device::radio::{Bandwidth, PhyRxTx, RfConfig, RxQuality, SpreadingFactor, TxConfig}; | ||
| 17 | use lorawan_device::async_device::Timings; | ||
| 23 | 18 | ||
| 24 | #[derive(Debug, Copy, Clone)] | 19 | #[derive(Debug, Copy, Clone)] |
| 25 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | 20 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] |
| @@ -98,9 +93,7 @@ impl<'a> StateInner<'a> { | |||
| 98 | self.radio.set_standby(StandbyClk::Rc)?; | 93 | self.radio.set_standby(StandbyClk::Rc)?; |
| 99 | let tcxo_mode = TcxoMode::new() | 94 | let tcxo_mode = TcxoMode::new() |
| 100 | .set_txco_trim(TcxoTrim::Volts1pt7) | 95 | .set_txco_trim(TcxoTrim::Volts1pt7) |
| 101 | .set_timeout(Timeout::from_duration_sat( | 96 | .set_timeout(Timeout::from_duration_sat(core::time::Duration::from_millis(40))); |
| 102 | core::time::Duration::from_millis(40), | ||
| 103 | )); | ||
| 104 | 97 | ||
| 105 | self.radio.set_tcxo_mode(&tcxo_mode)?; | 98 | self.radio.set_tcxo_mode(&tcxo_mode)?; |
| 106 | self.radio.set_regulator_mode(RegMode::Ldo)?; | 99 | self.radio.set_regulator_mode(RegMode::Ldo)?; |
| @@ -109,21 +102,14 @@ impl<'a> StateInner<'a> { | |||
| 109 | 102 | ||
| 110 | self.radio.set_buffer_base_address(0, 0)?; | 103 | self.radio.set_buffer_base_address(0, 0)?; |
| 111 | 104 | ||
| 112 | self.radio.set_pa_config( | 105 | self.radio |
| 113 | &PaConfig::new() | 106 | .set_pa_config(&PaConfig::new().set_pa_duty_cycle(0x1).set_hp_max(0x0).set_pa(PaSel::Lp))?; |
| 114 | .set_pa_duty_cycle(0x1) | ||
| 115 | .set_hp_max(0x0) | ||
| 116 | .set_pa(PaSel::Lp), | ||
| 117 | )?; | ||
| 118 | 107 | ||
| 119 | self.radio.set_pa_ocp(Ocp::Max140m)?; | 108 | self.radio.set_pa_ocp(Ocp::Max140m)?; |
| 120 | 109 | ||
| 121 | // let tx_params = TxParams::LP_14.set_ramp_time(RampTime::Micros40); | 110 | // let tx_params = TxParams::LP_14.set_ramp_time(RampTime::Micros40); |
| 122 | self.radio.set_tx_params( | 111 | self.radio |
| 123 | &TxParams::new() | 112 | .set_tx_params(&TxParams::new().set_ramp_time(RampTime::Micros40).set_power(0x0A))?; |
| 124 | .set_ramp_time(RampTime::Micros40) | ||
| 125 | .set_power(0x0A), | ||
| 126 | )?; | ||
| 127 | 113 | ||
| 128 | self.radio.set_packet_type(PacketType::LoRa)?; | 114 | self.radio.set_packet_type(PacketType::LoRa)?; |
| 129 | self.radio.set_lora_sync_word(LoRaSyncWord::Public)?; | 115 | self.radio.set_lora_sync_word(LoRaSyncWord::Public)?; |
| @@ -193,19 +179,14 @@ impl<'a> StateInner<'a> { | |||
| 193 | 179 | ||
| 194 | /// Perform a radio receive operation with the radio config and receive buffer. The receive buffer must | 180 | /// Perform a radio receive operation with the radio config and receive buffer. The receive buffer must |
| 195 | /// be able to hold a single LoRaWAN packet. | 181 | /// be able to hold a single LoRaWAN packet. |
| 196 | async fn do_rx( | 182 | async fn do_rx(&mut self, config: RfConfig, buf: &mut [u8]) -> Result<(usize, RxQuality), RadioError> { |
| 197 | &mut self, | ||
| 198 | config: RfConfig, | ||
| 199 | buf: &mut [u8], | ||
| 200 | ) -> Result<(usize, RxQuality), RadioError> { | ||
| 201 | assert!(buf.len() >= 255); | 183 | assert!(buf.len() >= 255); |
| 202 | trace!("RX START"); | 184 | trace!("RX START"); |
| 203 | // trace!("Starting RX: {}", config); | 185 | // trace!("Starting RX: {}", config); |
| 204 | self.switch.set_rx(); | 186 | self.switch.set_rx(); |
| 205 | self.configure()?; | 187 | self.configure()?; |
| 206 | 188 | ||
| 207 | self.radio | 189 | self.radio.set_rf_frequency(&RfFreq::from_frequency(config.frequency))?; |
| 208 | .set_rf_frequency(&RfFreq::from_frequency(config.frequency))?; | ||
| 209 | 190 | ||
| 210 | let mod_params = LoRaModParams::new() | 191 | let mod_params = LoRaModParams::new() |
| 211 | .set_sf(convert_spreading_factor(config.spreading_factor)) | 192 | .set_sf(convert_spreading_factor(config.spreading_factor)) |
| @@ -315,16 +296,8 @@ pub struct RadioSwitch<'a> { | |||
| 315 | } | 296 | } |
| 316 | 297 | ||
| 317 | impl<'a> RadioSwitch<'a> { | 298 | impl<'a> RadioSwitch<'a> { |
| 318 | pub fn new( | 299 | pub fn new(ctrl1: Output<'a, AnyPin>, ctrl2: Output<'a, AnyPin>, ctrl3: Output<'a, AnyPin>) -> Self { |
| 319 | ctrl1: Output<'a, AnyPin>, | 300 | Self { ctrl1, ctrl2, ctrl3 } |
| 320 | ctrl2: Output<'a, AnyPin>, | ||
| 321 | ctrl3: Output<'a, AnyPin>, | ||
| 322 | ) -> Self { | ||
| 323 | Self { | ||
| 324 | ctrl1, | ||
| 325 | ctrl2, | ||
| 326 | ctrl3, | ||
| 327 | } | ||
| 328 | } | 301 | } |
| 329 | 302 | ||
| 330 | pub(crate) fn set_rx(&mut self) { | 303 | pub(crate) fn set_rx(&mut self) { |
diff --git a/embassy-lora/src/sx127x/mod.rs b/embassy-lora/src/sx127x/mod.rs index c70f33582..f47a9eb55 100644 --- a/embassy-lora/src/sx127x/mod.rs +++ b/embassy-lora/src/sx127x/mod.rs | |||
| @@ -1,11 +1,10 @@ | |||
| 1 | use core::future::Future; | 1 | use core::future::Future; |
| 2 | |||
| 2 | use embedded_hal::digital::v2::OutputPin; | 3 | use embedded_hal::digital::v2::OutputPin; |
| 3 | use embedded_hal_async::digital::Wait; | 4 | use embedded_hal_async::digital::Wait; |
| 4 | use embedded_hal_async::spi::*; | 5 | use embedded_hal_async::spi::*; |
| 5 | use lorawan_device::async_device::{ | 6 | use lorawan_device::async_device::radio::{Bandwidth, PhyRxTx, RfConfig, RxQuality, SpreadingFactor, TxConfig}; |
| 6 | radio::{Bandwidth, PhyRxTx, RfConfig, RxQuality, SpreadingFactor, TxConfig}, | 7 | use lorawan_device::async_device::Timings; |
| 7 | Timings, | ||
| 8 | }; | ||
| 9 | 8 | ||
| 10 | mod sx127x_lora; | 9 | mod sx127x_lora; |
| 11 | use sx127x_lora::{Error as RadioError, LoRa, RadioMode, IRQ}; | 10 | use sx127x_lora::{Error as RadioError, LoRa, RadioMode, IRQ}; |
diff --git a/embassy-lora/src/sx127x/sx127x_lora/mod.rs b/embassy-lora/src/sx127x/sx127x_lora/mod.rs index 62eaf0a95..8b937ec2f 100644 --- a/embassy-lora/src/sx127x/sx127x_lora/mod.rs +++ b/embassy-lora/src/sx127x/sx127x_lora/mod.rs | |||
| @@ -11,9 +11,8 @@ use embedded_hal::digital::v2::OutputPin; | |||
| 11 | use embedded_hal_async::spi::SpiBus; | 11 | use embedded_hal_async::spi::SpiBus; |
| 12 | 12 | ||
| 13 | mod register; | 13 | mod register; |
| 14 | use self::register::PaConfig; | ||
| 15 | use self::register::Register; | ||
| 16 | pub use self::register::IRQ; | 14 | pub use self::register::IRQ; |
| 15 | use self::register::{PaConfig, Register}; | ||
| 17 | 16 | ||
| 18 | /// Provides high-level access to Semtech SX1276/77/78/79 based boards connected to a Raspberry Pi | 17 | /// Provides high-level access to Semtech SX1276/77/78/79 based boards connected to a Raspberry Pi |
| 19 | pub struct LoRa<SPI, CS, RESET> { | 18 | pub struct LoRa<SPI, CS, RESET> { |
| @@ -72,15 +71,11 @@ where | |||
| 72 | let version = self.read_register(Register::RegVersion.addr()).await?; | 71 | let version = self.read_register(Register::RegVersion.addr()).await?; |
| 73 | if version == VERSION_CHECK { | 72 | if version == VERSION_CHECK { |
| 74 | self.set_mode(RadioMode::Sleep).await?; | 73 | self.set_mode(RadioMode::Sleep).await?; |
| 75 | self.write_register(Register::RegFifoTxBaseAddr.addr(), 0) | 74 | self.write_register(Register::RegFifoTxBaseAddr.addr(), 0).await?; |
| 76 | .await?; | 75 | self.write_register(Register::RegFifoRxBaseAddr.addr(), 0).await?; |
| 77 | self.write_register(Register::RegFifoRxBaseAddr.addr(), 0) | ||
| 78 | .await?; | ||
| 79 | let lna = self.read_register(Register::RegLna.addr()).await?; | 76 | let lna = self.read_register(Register::RegLna.addr()).await?; |
| 80 | self.write_register(Register::RegLna.addr(), lna | 0x03) | 77 | self.write_register(Register::RegLna.addr(), lna | 0x03).await?; |
| 81 | .await?; | 78 | self.write_register(Register::RegModemConfig3.addr(), 0x04).await?; |
| 82 | self.write_register(Register::RegModemConfig3.addr(), 0x04) | ||
| 83 | .await?; | ||
| 84 | self.set_tcxo(true).await?; | 79 | self.set_tcxo(true).await?; |
| 85 | self.set_mode(RadioMode::Stdby).await?; | 80 | self.set_mode(RadioMode::Stdby).await?; |
| 86 | self.cs.set_high().map_err(CS)?; | 81 | self.cs.set_high().map_err(CS)?; |
| @@ -106,10 +101,7 @@ where | |||
| 106 | .await | 101 | .await |
| 107 | } | 102 | } |
| 108 | 103 | ||
| 109 | pub async fn transmit_start( | 104 | pub async fn transmit_start(&mut self, buffer: &[u8]) -> Result<(), Error<E, CS::Error, RESET::Error>> { |
| 110 | &mut self, | ||
| 111 | buffer: &[u8], | ||
| 112 | ) -> Result<(), Error<E, CS::Error, RESET::Error>> { | ||
| 113 | assert!(buffer.len() < 255); | 105 | assert!(buffer.len() < 255); |
| 114 | if self.transmitting().await? { | 106 | if self.transmitting().await? { |
| 115 | //trace!("ALREADY TRANSMNITTING"); | 107 | //trace!("ALREADY TRANSMNITTING"); |
| @@ -123,10 +115,8 @@ where | |||
| 123 | } | 115 | } |
| 124 | 116 | ||
| 125 | self.write_register(Register::RegIrqFlags.addr(), 0).await?; | 117 | self.write_register(Register::RegIrqFlags.addr(), 0).await?; |
| 126 | self.write_register(Register::RegFifoAddrPtr.addr(), 0) | 118 | self.write_register(Register::RegFifoAddrPtr.addr(), 0).await?; |
| 127 | .await?; | 119 | self.write_register(Register::RegPayloadLength.addr(), 0).await?; |
| 128 | self.write_register(Register::RegPayloadLength.addr(), 0) | ||
| 129 | .await?; | ||
| 130 | for byte in buffer.iter() { | 120 | for byte in buffer.iter() { |
| 131 | self.write_register(Register::RegFifo.addr(), *byte).await?; | 121 | self.write_register(Register::RegFifo.addr(), *byte).await?; |
| 132 | } | 122 | } |
| @@ -138,10 +128,7 @@ where | |||
| 138 | } | 128 | } |
| 139 | 129 | ||
| 140 | pub async fn packet_ready(&mut self) -> Result<bool, Error<E, CS::Error, RESET::Error>> { | 130 | pub async fn packet_ready(&mut self) -> Result<bool, Error<E, CS::Error, RESET::Error>> { |
| 141 | Ok(self | 131 | Ok(self.read_register(Register::RegIrqFlags.addr()).await?.get_bit(6)) |
| 142 | .read_register(Register::RegIrqFlags.addr()) | ||
| 143 | .await? | ||
| 144 | .get_bit(6)) | ||
| 145 | } | 132 | } |
| 146 | 133 | ||
| 147 | pub async fn irq_flags_mask(&mut self) -> Result<u8, Error<E, CS::Error, RESET::Error>> { | 134 | pub async fn irq_flags_mask(&mut self) -> Result<u8, Error<E, CS::Error, RESET::Error>> { |
| @@ -159,37 +146,26 @@ where | |||
| 159 | 146 | ||
| 160 | /// Returns the contents of the fifo as a fixed 255 u8 array. This should only be called is there is a | 147 | /// Returns the contents of the fifo as a fixed 255 u8 array. This should only be called is there is a |
| 161 | /// new packet ready to be read. | 148 | /// new packet ready to be read. |
| 162 | pub async fn read_packet( | 149 | pub async fn read_packet(&mut self, buffer: &mut [u8]) -> Result<(), Error<E, CS::Error, RESET::Error>> { |
| 163 | &mut self, | ||
| 164 | buffer: &mut [u8], | ||
| 165 | ) -> Result<(), Error<E, CS::Error, RESET::Error>> { | ||
| 166 | self.clear_irq().await?; | 150 | self.clear_irq().await?; |
| 167 | let size = self.read_register(Register::RegRxNbBytes.addr()).await?; | 151 | let size = self.read_register(Register::RegRxNbBytes.addr()).await?; |
| 168 | assert!(size as usize <= buffer.len()); | 152 | assert!(size as usize <= buffer.len()); |
| 169 | let fifo_addr = self | 153 | let fifo_addr = self.read_register(Register::RegFifoRxCurrentAddr.addr()).await?; |
| 170 | .read_register(Register::RegFifoRxCurrentAddr.addr()) | 154 | self.write_register(Register::RegFifoAddrPtr.addr(), fifo_addr).await?; |
| 171 | .await?; | ||
| 172 | self.write_register(Register::RegFifoAddrPtr.addr(), fifo_addr) | ||
| 173 | .await?; | ||
| 174 | for i in 0..size { | 155 | for i in 0..size { |
| 175 | let byte = self.read_register(Register::RegFifo.addr()).await?; | 156 | let byte = self.read_register(Register::RegFifo.addr()).await?; |
| 176 | buffer[i as usize] = byte; | 157 | buffer[i as usize] = byte; |
| 177 | } | 158 | } |
| 178 | self.write_register(Register::RegFifoAddrPtr.addr(), 0) | 159 | self.write_register(Register::RegFifoAddrPtr.addr(), 0).await?; |
| 179 | .await?; | ||
| 180 | Ok(()) | 160 | Ok(()) |
| 181 | } | 161 | } |
| 182 | 162 | ||
| 183 | /// Returns true if the radio is currently transmitting a packet. | 163 | /// Returns true if the radio is currently transmitting a packet. |
| 184 | pub async fn transmitting(&mut self) -> Result<bool, Error<E, CS::Error, RESET::Error>> { | 164 | pub async fn transmitting(&mut self) -> Result<bool, Error<E, CS::Error, RESET::Error>> { |
| 185 | if (self.read_register(Register::RegOpMode.addr()).await?) & RadioMode::Tx.addr() | 165 | if (self.read_register(Register::RegOpMode.addr()).await?) & RadioMode::Tx.addr() == RadioMode::Tx.addr() { |
| 186 | == RadioMode::Tx.addr() | ||
| 187 | { | ||
| 188 | Ok(true) | 166 | Ok(true) |
| 189 | } else { | 167 | } else { |
| 190 | if (self.read_register(Register::RegIrqFlags.addr()).await? & IRQ::IrqTxDoneMask.addr()) | 168 | if (self.read_register(Register::RegIrqFlags.addr()).await? & IRQ::IrqTxDoneMask.addr()) == 1 { |
| 191 | == 1 | ||
| 192 | { | ||
| 193 | self.write_register(Register::RegIrqFlags.addr(), IRQ::IrqTxDoneMask.addr()) | 169 | self.write_register(Register::RegIrqFlags.addr(), IRQ::IrqTxDoneMask.addr()) |
| 194 | .await?; | 170 | .await?; |
| 195 | } | 171 | } |
| @@ -200,8 +176,7 @@ where | |||
| 200 | /// Clears the radio's IRQ registers. | 176 | /// Clears the radio's IRQ registers. |
| 201 | pub async fn clear_irq(&mut self) -> Result<u8, Error<E, CS::Error, RESET::Error>> { | 177 | pub async fn clear_irq(&mut self) -> Result<u8, Error<E, CS::Error, RESET::Error>> { |
| 202 | let irq_flags = self.read_register(Register::RegIrqFlags.addr()).await?; | 178 | let irq_flags = self.read_register(Register::RegIrqFlags.addr()).await?; |
| 203 | self.write_register(Register::RegIrqFlags.addr(), 0xFF) | 179 | self.write_register(Register::RegIrqFlags.addr(), 0xFF).await?; |
| 204 | .await?; | ||
| 205 | Ok(irq_flags) | 180 | Ok(irq_flags) |
| 206 | } | 181 | } |
| 207 | 182 | ||
| @@ -243,11 +218,8 @@ where | |||
| 243 | self.set_ocp(100).await?; | 218 | self.set_ocp(100).await?; |
| 244 | } | 219 | } |
| 245 | level -= 2; | 220 | level -= 2; |
| 246 | self.write_register( | 221 | self.write_register(Register::RegPaConfig.addr(), PaConfig::PaBoost.addr() | level as u8) |
| 247 | Register::RegPaConfig.addr(), | 222 | .await |
| 248 | PaConfig::PaBoost.addr() | level as u8, | ||
| 249 | ) | ||
| 250 | .await | ||
| 251 | } | 223 | } |
| 252 | } | 224 | } |
| 253 | 225 | ||
| @@ -269,10 +241,7 @@ where | |||
| 269 | } | 241 | } |
| 270 | 242 | ||
| 271 | /// Sets the state of the radio. Default mode after initiation is `Standby`. | 243 | /// Sets the state of the radio. Default mode after initiation is `Standby`. |
| 272 | pub async fn set_mode( | 244 | pub async fn set_mode(&mut self, mode: RadioMode) -> Result<(), Error<E, CS::Error, RESET::Error>> { |
| 273 | &mut self, | ||
| 274 | mode: RadioMode, | ||
| 275 | ) -> Result<(), Error<E, CS::Error, RESET::Error>> { | ||
| 276 | if self.explicit_header { | 245 | if self.explicit_header { |
| 277 | self.set_explicit_header_mode().await?; | 246 | self.set_explicit_header_mode().await?; |
| 278 | } else { | 247 | } else { |
| @@ -289,25 +258,18 @@ where | |||
| 289 | } | 258 | } |
| 290 | 259 | ||
| 291 | pub async fn reset_payload_length(&mut self) -> Result<(), Error<E, CS::Error, RESET::Error>> { | 260 | pub async fn reset_payload_length(&mut self) -> Result<(), Error<E, CS::Error, RESET::Error>> { |
| 292 | self.write_register(Register::RegPayloadLength.addr(), 0xFF) | 261 | self.write_register(Register::RegPayloadLength.addr(), 0xFF).await |
| 293 | .await | ||
| 294 | } | 262 | } |
| 295 | 263 | ||
| 296 | /// Sets the frequency of the radio. Values are in megahertz. | 264 | /// Sets the frequency of the radio. Values are in megahertz. |
| 297 | /// I.E. 915 MHz must be used for North America. Check regulation for your area. | 265 | /// I.E. 915 MHz must be used for North America. Check regulation for your area. |
| 298 | pub async fn set_frequency( | 266 | pub async fn set_frequency(&mut self, freq: u32) -> Result<(), Error<E, CS::Error, RESET::Error>> { |
| 299 | &mut self, | ||
| 300 | freq: u32, | ||
| 301 | ) -> Result<(), Error<E, CS::Error, RESET::Error>> { | ||
| 302 | const FREQ_STEP: f64 = 61.03515625; | 267 | const FREQ_STEP: f64 = 61.03515625; |
| 303 | // calculate register values | 268 | // calculate register values |
| 304 | let frf = (freq as f64 / FREQ_STEP) as u32; | 269 | let frf = (freq as f64 / FREQ_STEP) as u32; |
| 305 | // write registers | 270 | // write registers |
| 306 | self.write_register( | 271 | self.write_register(Register::RegFrfMsb.addr(), ((frf & 0x00FF_0000) >> 16) as u8) |
| 307 | Register::RegFrfMsb.addr(), | 272 | .await?; |
| 308 | ((frf & 0x00FF_0000) >> 16) as u8, | ||
| 309 | ) | ||
| 310 | .await?; | ||
| 311 | self.write_register(Register::RegFrfMid.addr(), ((frf & 0x0000_FF00) >> 8) as u8) | 273 | self.write_register(Register::RegFrfMid.addr(), ((frf & 0x0000_FF00) >> 8) as u8) |
| 312 | .await?; | 274 | .await?; |
| 313 | self.write_register(Register::RegFrfLsb.addr(), (frf & 0x0000_00FF) as u8) | 275 | self.write_register(Register::RegFrfLsb.addr(), (frf & 0x0000_00FF) as u8) |
| @@ -335,10 +297,7 @@ where | |||
| 335 | /// Sets the spreading factor of the radio. Supported values are between 6 and 12. | 297 | /// Sets the spreading factor of the radio. Supported values are between 6 and 12. |
| 336 | /// If a spreading factor of 6 is set, implicit header mode must be used to transmit | 298 | /// If a spreading factor of 6 is set, implicit header mode must be used to transmit |
| 337 | /// and receive packets. Default value is `7`. | 299 | /// and receive packets. Default value is `7`. |
| 338 | pub async fn set_spreading_factor( | 300 | pub async fn set_spreading_factor(&mut self, mut sf: u8) -> Result<(), Error<E, CS::Error, RESET::Error>> { |
| 339 | &mut self, | ||
| 340 | mut sf: u8, | ||
| 341 | ) -> Result<(), Error<E, CS::Error, RESET::Error>> { | ||
| 342 | if sf < 6 { | 301 | if sf < 6 { |
| 343 | sf = 6; | 302 | sf = 6; |
| 344 | } else if sf > 12 { | 303 | } else if sf > 12 { |
| @@ -346,13 +305,11 @@ where | |||
| 346 | } | 305 | } |
| 347 | 306 | ||
| 348 | if sf == 6 { | 307 | if sf == 6 { |
| 349 | self.write_register(Register::RegDetectionOptimize.addr(), 0xc5) | 308 | self.write_register(Register::RegDetectionOptimize.addr(), 0xc5).await?; |
| 350 | .await?; | ||
| 351 | self.write_register(Register::RegDetectionThreshold.addr(), 0x0c) | 309 | self.write_register(Register::RegDetectionThreshold.addr(), 0x0c) |
| 352 | .await?; | 310 | .await?; |
| 353 | } else { | 311 | } else { |
| 354 | self.write_register(Register::RegDetectionOptimize.addr(), 0xc3) | 312 | self.write_register(Register::RegDetectionOptimize.addr(), 0xc3).await?; |
| 355 | .await?; | ||
| 356 | self.write_register(Register::RegDetectionThreshold.addr(), 0x0a) | 313 | self.write_register(Register::RegDetectionThreshold.addr(), 0x0a) |
| 357 | .await?; | 314 | .await?; |
| 358 | } | 315 | } |
| @@ -364,16 +321,12 @@ where | |||
| 364 | .await?; | 321 | .await?; |
| 365 | self.set_ldo_flag().await?; | 322 | self.set_ldo_flag().await?; |
| 366 | 323 | ||
| 367 | self.write_register(Register::RegSymbTimeoutLsb.addr(), 0x05) | 324 | self.write_register(Register::RegSymbTimeoutLsb.addr(), 0x05).await?; |
| 368 | .await?; | ||
| 369 | 325 | ||
| 370 | Ok(()) | 326 | Ok(()) |
| 371 | } | 327 | } |
| 372 | 328 | ||
| 373 | pub async fn set_tcxo( | 329 | pub async fn set_tcxo(&mut self, external: bool) -> Result<(), Error<E, CS::Error, RESET::Error>> { |
| 374 | &mut self, | ||
| 375 | external: bool, | ||
| 376 | ) -> Result<(), Error<E, CS::Error, RESET::Error>> { | ||
| 377 | if external { | 330 | if external { |
| 378 | self.write_register(Register::RegTcxo.addr(), 0x10).await | 331 | self.write_register(Register::RegTcxo.addr(), 0x10).await |
| 379 | } else { | 332 | } else { |
| @@ -384,10 +337,7 @@ where | |||
| 384 | /// Sets the signal bandwidth of the radio. Supported values are: `7800 Hz`, `10400 Hz`, | 337 | /// Sets the signal bandwidth of the radio. Supported values are: `7800 Hz`, `10400 Hz`, |
| 385 | /// `15600 Hz`, `20800 Hz`, `31250 Hz`,`41700 Hz` ,`62500 Hz`,`125000 Hz` and `250000 Hz` | 338 | /// `15600 Hz`, `20800 Hz`, `31250 Hz`,`41700 Hz` ,`62500 Hz`,`125000 Hz` and `250000 Hz` |
| 386 | /// Default value is `125000 Hz` | 339 | /// Default value is `125000 Hz` |
| 387 | pub async fn set_signal_bandwidth( | 340 | pub async fn set_signal_bandwidth(&mut self, sbw: i64) -> Result<(), Error<E, CS::Error, RESET::Error>> { |
| 388 | &mut self, | ||
| 389 | sbw: i64, | ||
| 390 | ) -> Result<(), Error<E, CS::Error, RESET::Error>> { | ||
| 391 | let bw: i64 = match sbw { | 341 | let bw: i64 = match sbw { |
| 392 | 7_800 => 0, | 342 | 7_800 => 0, |
| 393 | 10_400 => 1, | 343 | 10_400 => 1, |
| @@ -413,10 +363,7 @@ where | |||
| 413 | /// Sets the coding rate of the radio with the numerator fixed at 4. Supported values | 363 | /// Sets the coding rate of the radio with the numerator fixed at 4. Supported values |
| 414 | /// are between `5` and `8`, these correspond to coding rates of `4/5` and `4/8`. | 364 | /// are between `5` and `8`, these correspond to coding rates of `4/5` and `4/8`. |
| 415 | /// Default value is `5`. | 365 | /// Default value is `5`. |
| 416 | pub async fn set_coding_rate_4( | 366 | pub async fn set_coding_rate_4(&mut self, mut denominator: u8) -> Result<(), Error<E, CS::Error, RESET::Error>> { |
| 417 | &mut self, | ||
| 418 | mut denominator: u8, | ||
| 419 | ) -> Result<(), Error<E, CS::Error, RESET::Error>> { | ||
| 420 | if denominator < 5 { | 367 | if denominator < 5 { |
| 421 | denominator = 5; | 368 | denominator = 5; |
| 422 | } else if denominator > 8 { | 369 | } else if denominator > 8 { |
| @@ -424,23 +371,16 @@ where | |||
| 424 | } | 371 | } |
| 425 | let cr = denominator - 4; | 372 | let cr = denominator - 4; |
| 426 | let modem_config_1 = self.read_register(Register::RegModemConfig1.addr()).await?; | 373 | let modem_config_1 = self.read_register(Register::RegModemConfig1.addr()).await?; |
| 427 | self.write_register( | 374 | self.write_register(Register::RegModemConfig1.addr(), (modem_config_1 & 0xf1) | (cr << 1)) |
| 428 | Register::RegModemConfig1.addr(), | 375 | .await |
| 429 | (modem_config_1 & 0xf1) | (cr << 1), | ||
| 430 | ) | ||
| 431 | .await | ||
| 432 | } | 376 | } |
| 433 | 377 | ||
| 434 | /// Sets the preamble length of the radio. Values are between 6 and 65535. | 378 | /// Sets the preamble length of the radio. Values are between 6 and 65535. |
| 435 | /// Default value is `8`. | 379 | /// Default value is `8`. |
| 436 | pub async fn set_preamble_length( | 380 | pub async fn set_preamble_length(&mut self, length: i64) -> Result<(), Error<E, CS::Error, RESET::Error>> { |
| 437 | &mut self, | ||
| 438 | length: i64, | ||
| 439 | ) -> Result<(), Error<E, CS::Error, RESET::Error>> { | ||
| 440 | self.write_register(Register::RegPreambleMsb.addr(), (length >> 8) as u8) | 381 | self.write_register(Register::RegPreambleMsb.addr(), (length >> 8) as u8) |
| 441 | .await?; | 382 | .await?; |
| 442 | self.write_register(Register::RegPreambleLsb.addr(), length as u8) | 383 | self.write_register(Register::RegPreambleLsb.addr(), length as u8).await |
| 443 | .await | ||
| 444 | } | 384 | } |
| 445 | 385 | ||
| 446 | /// Enables are disables the radio's CRC check. Default value is `false`. | 386 | /// Enables are disables the radio's CRC check. Default value is `false`. |
| @@ -456,20 +396,13 @@ where | |||
| 456 | } | 396 | } |
| 457 | 397 | ||
| 458 | /// Inverts the radio's IQ signals. Default value is `false`. | 398 | /// Inverts the radio's IQ signals. Default value is `false`. |
| 459 | pub async fn set_invert_iq( | 399 | pub async fn set_invert_iq(&mut self, value: bool) -> Result<(), Error<E, CS::Error, RESET::Error>> { |
| 460 | &mut self, | ||
| 461 | value: bool, | ||
| 462 | ) -> Result<(), Error<E, CS::Error, RESET::Error>> { | ||
| 463 | if value { | 400 | if value { |
| 464 | self.write_register(Register::RegInvertiq.addr(), 0x66) | 401 | self.write_register(Register::RegInvertiq.addr(), 0x66).await?; |
| 465 | .await?; | 402 | self.write_register(Register::RegInvertiq2.addr(), 0x19).await |
| 466 | self.write_register(Register::RegInvertiq2.addr(), 0x19) | ||
| 467 | .await | ||
| 468 | } else { | 403 | } else { |
| 469 | self.write_register(Register::RegInvertiq.addr(), 0x27) | 404 | self.write_register(Register::RegInvertiq.addr(), 0x27).await?; |
| 470 | .await?; | 405 | self.write_register(Register::RegInvertiq2.addr(), 0x1d).await |
| 471 | self.write_register(Register::RegInvertiq2.addr(), 0x1d) | ||
| 472 | .await | ||
| 473 | } | 406 | } |
| 474 | } | 407 | } |
| 475 | 408 | ||
| @@ -504,15 +437,11 @@ where | |||
| 504 | 437 | ||
| 505 | /// Returns the signal to noise radio of the the last received packet. | 438 | /// Returns the signal to noise radio of the the last received packet. |
| 506 | pub async fn get_packet_snr(&mut self) -> Result<f64, Error<E, CS::Error, RESET::Error>> { | 439 | pub async fn get_packet_snr(&mut self) -> Result<f64, Error<E, CS::Error, RESET::Error>> { |
| 507 | Ok(f64::from( | 440 | Ok(f64::from(self.read_register(Register::RegPktSnrValue.addr()).await?)) |
| 508 | self.read_register(Register::RegPktSnrValue.addr()).await?, | ||
| 509 | )) | ||
| 510 | } | 441 | } |
| 511 | 442 | ||
| 512 | /// Returns the frequency error of the last received packet in Hz. | 443 | /// Returns the frequency error of the last received packet in Hz. |
| 513 | pub async fn get_packet_frequency_error( | 444 | pub async fn get_packet_frequency_error(&mut self) -> Result<i64, Error<E, CS::Error, RESET::Error>> { |
| 514 | &mut self, | ||
| 515 | ) -> Result<i64, Error<E, CS::Error, RESET::Error>> { | ||
| 516 | let mut freq_error: i32; | 445 | let mut freq_error: i32; |
| 517 | freq_error = i32::from(self.read_register(Register::RegFreqErrorMsb.addr()).await? & 0x7); | 446 | freq_error = i32::from(self.read_register(Register::RegFreqErrorMsb.addr()).await? & 0x7); |
| 518 | freq_error <<= 8i64; | 447 | freq_error <<= 8i64; |
| @@ -537,29 +466,20 @@ where | |||
| 537 | let mut config_3 = self.read_register(Register::RegModemConfig3.addr()).await?; | 466 | let mut config_3 = self.read_register(Register::RegModemConfig3.addr()).await?; |
| 538 | config_3.set_bit(3, ldo_on); | 467 | config_3.set_bit(3, ldo_on); |
| 539 | //config_3.set_bit(2, true); | 468 | //config_3.set_bit(2, true); |
| 540 | self.write_register(Register::RegModemConfig3.addr(), config_3) | 469 | self.write_register(Register::RegModemConfig3.addr(), config_3).await |
| 541 | .await | ||
| 542 | } | 470 | } |
| 543 | 471 | ||
| 544 | async fn read_register(&mut self, reg: u8) -> Result<u8, Error<E, CS::Error, RESET::Error>> { | 472 | async fn read_register(&mut self, reg: u8) -> Result<u8, Error<E, CS::Error, RESET::Error>> { |
| 545 | let mut buffer = [reg & 0x7f, 0]; | 473 | let mut buffer = [reg & 0x7f, 0]; |
| 546 | self.cs.set_low().map_err(CS)?; | 474 | self.cs.set_low().map_err(CS)?; |
| 547 | 475 | ||
| 548 | let _ = self | 476 | let _ = self.spi.transfer(&mut buffer, &[reg & 0x7f, 0]).await.map_err(SPI)?; |
| 549 | .spi | ||
| 550 | .transfer(&mut buffer, &[reg & 0x7f, 0]) | ||
| 551 | .await | ||
| 552 | .map_err(SPI)?; | ||
| 553 | 477 | ||
| 554 | self.cs.set_high().map_err(CS)?; | 478 | self.cs.set_high().map_err(CS)?; |
| 555 | Ok(buffer[1]) | 479 | Ok(buffer[1]) |
| 556 | } | 480 | } |
| 557 | 481 | ||
| 558 | async fn write_register( | 482 | async fn write_register(&mut self, reg: u8, byte: u8) -> Result<(), Error<E, CS::Error, RESET::Error>> { |
| 559 | &mut self, | ||
| 560 | reg: u8, | ||
| 561 | byte: u8, | ||
| 562 | ) -> Result<(), Error<E, CS::Error, RESET::Error>> { | ||
| 563 | self.cs.set_low().map_err(CS)?; | 483 | self.cs.set_low().map_err(CS)?; |
| 564 | let buffer = [reg | 0x80, byte]; | 484 | let buffer = [reg | 0x80, byte]; |
| 565 | self.spi.write(&buffer).await.map_err(SPI)?; | 485 | self.spi.write(&buffer).await.map_err(SPI)?; |
| @@ -576,8 +496,7 @@ where | |||
| 576 | .set_bit(3, false) //Low freq registers | 496 | .set_bit(3, false) //Low freq registers |
| 577 | .set_bits(0..2, 0b011); // Mode | 497 | .set_bits(0..2, 0b011); // Mode |
| 578 | 498 | ||
| 579 | self.write_register(Register::RegOpMode as u8, op_mode) | 499 | self.write_register(Register::RegOpMode as u8, op_mode).await |
| 580 | .await | ||
| 581 | } | 500 | } |
| 582 | 501 | ||
| 583 | pub async fn set_fsk_pa_ramp( | 502 | pub async fn set_fsk_pa_ramp( |
| @@ -590,8 +509,7 @@ where | |||
| 590 | .set_bits(5..6, modulation_shaping as u8) | 509 | .set_bits(5..6, modulation_shaping as u8) |
| 591 | .set_bits(0..3, ramp as u8); | 510 | .set_bits(0..3, ramp as u8); |
| 592 | 511 | ||
| 593 | self.write_register(Register::RegPaRamp as u8, pa_ramp) | 512 | self.write_register(Register::RegPaRamp as u8, pa_ramp).await |
| 594 | .await | ||
| 595 | } | 513 | } |
| 596 | 514 | ||
| 597 | pub async fn set_lora_pa_ramp(&mut self) -> Result<(), Error<E, CS::Error, RESET::Error>> { | 515 | pub async fn set_lora_pa_ramp(&mut self) -> Result<(), Error<E, CS::Error, RESET::Error>> { |
diff --git a/embassy-macros/src/lib.rs b/embassy-macros/src/lib.rs index 50f442438..ec8498f9f 100644 --- a/embassy-macros/src/lib.rs +++ b/embassy-macros/src/lib.rs | |||
| @@ -25,17 +25,13 @@ pub fn main(args: TokenStream, item: TokenStream) -> TokenStream { | |||
| 25 | pub fn cortex_m_interrupt(args: TokenStream, item: TokenStream) -> TokenStream { | 25 | pub fn cortex_m_interrupt(args: TokenStream, item: TokenStream) -> TokenStream { |
| 26 | let args = syn::parse_macro_input!(args as syn::AttributeArgs); | 26 | let args = syn::parse_macro_input!(args as syn::AttributeArgs); |
| 27 | let f = syn::parse_macro_input!(item as syn::ItemFn); | 27 | let f = syn::parse_macro_input!(item as syn::ItemFn); |
| 28 | cortex_m_interrupt::run(args, f) | 28 | cortex_m_interrupt::run(args, f).unwrap_or_else(|x| x).into() |
| 29 | .unwrap_or_else(|x| x) | ||
| 30 | .into() | ||
| 31 | } | 29 | } |
| 32 | 30 | ||
| 33 | #[proc_macro] | 31 | #[proc_macro] |
| 34 | pub fn cortex_m_interrupt_declare(item: TokenStream) -> TokenStream { | 32 | pub fn cortex_m_interrupt_declare(item: TokenStream) -> TokenStream { |
| 35 | let name = syn::parse_macro_input!(item as syn::Ident); | 33 | let name = syn::parse_macro_input!(item as syn::Ident); |
| 36 | cortex_m_interrupt_declare::run(name) | 34 | cortex_m_interrupt_declare::run(name).unwrap_or_else(|x| x).into() |
| 37 | .unwrap_or_else(|x| x) | ||
| 38 | .into() | ||
| 39 | } | 35 | } |
| 40 | 36 | ||
| 41 | /// # interrupt_take procedural macro | 37 | /// # interrupt_take procedural macro |
| @@ -46,7 +42,5 @@ pub fn cortex_m_interrupt_declare(item: TokenStream) -> TokenStream { | |||
| 46 | #[proc_macro] | 42 | #[proc_macro] |
| 47 | pub fn cortex_m_interrupt_take(item: TokenStream) -> TokenStream { | 43 | pub fn cortex_m_interrupt_take(item: TokenStream) -> TokenStream { |
| 48 | let name = syn::parse_macro_input!(item as syn::Ident); | 44 | let name = syn::parse_macro_input!(item as syn::Ident); |
| 49 | cortex_m_interrupt_take::run(name) | 45 | cortex_m_interrupt_take::run(name).unwrap_or_else(|x| x).into() |
| 50 | .unwrap_or_else(|x| x) | ||
| 51 | .into() | ||
| 52 | } | 46 | } |
diff --git a/embassy-macros/src/macros/cortex_m_interrupt.rs b/embassy-macros/src/macros/cortex_m_interrupt.rs index 32cc0e010..13af8ca07 100644 --- a/embassy-macros/src/macros/cortex_m_interrupt.rs +++ b/embassy-macros/src/macros/cortex_m_interrupt.rs | |||
| @@ -1,9 +1,9 @@ | |||
| 1 | use std::iter; | ||
| 2 | |||
| 1 | use darling::FromMeta; | 3 | use darling::FromMeta; |
| 2 | use proc_macro2::TokenStream; | 4 | use proc_macro2::TokenStream; |
| 3 | use quote::quote; | 5 | use quote::quote; |
| 4 | use std::iter; | 6 | use syn::{ReturnType, Type, Visibility}; |
| 5 | use syn::ReturnType; | ||
| 6 | use syn::{Type, Visibility}; | ||
| 7 | 7 | ||
| 8 | use crate::util::ctxt::Ctxt; | 8 | use crate::util::ctxt::Ctxt; |
| 9 | 9 | ||
diff --git a/embassy-macros/src/macros/main.rs b/embassy-macros/src/macros/main.rs index b7ce9dda4..5638276b2 100644 --- a/embassy-macros/src/macros/main.rs +++ b/embassy-macros/src/macros/main.rs | |||
| @@ -81,14 +81,11 @@ pub fn run(args: syn::AttributeArgs, f: syn::ItemFn) -> Result<TokenStream, Toke | |||
| 81 | 81 | ||
| 82 | #[cfg(all(not(feature = "std"), not(feature = "wasm")))] | 82 | #[cfg(all(not(feature = "std"), not(feature = "wasm")))] |
| 83 | let main = { | 83 | let main = { |
| 84 | let config = args | 84 | let config = args.config.map(|s| s.parse::<syn::Expr>().unwrap()).unwrap_or_else(|| { |
| 85 | .config | 85 | syn::Expr::Verbatim(quote! { |
| 86 | .map(|s| s.parse::<syn::Expr>().unwrap()) | 86 | Default::default() |
| 87 | .unwrap_or_else(|| { | 87 | }) |
| 88 | syn::Expr::Verbatim(quote! { | 88 | }); |
| 89 | Default::default() | ||
| 90 | }) | ||
| 91 | }); | ||
| 92 | 89 | ||
| 93 | let (hal_setup, peris_arg) = match HAL { | 90 | let (hal_setup, peris_arg) = match HAL { |
| 94 | Some(hal) => { | 91 | Some(hal) => { |
diff --git a/embassy-macros/src/macros/task.rs b/embassy-macros/src/macros/task.rs index e48de3d63..53c9af546 100644 --- a/embassy-macros/src/macros/task.rs +++ b/embassy-macros/src/macros/task.rs | |||
| @@ -47,10 +47,7 @@ pub fn run(args: syn::AttributeArgs, f: syn::ItemFn) -> Result<TokenStream, Toke | |||
| 47 | id.mutability = None; | 47 | id.mutability = None; |
| 48 | } | 48 | } |
| 49 | _ => { | 49 | _ => { |
| 50 | ctxt.error_spanned_by( | 50 | ctxt.error_spanned_by(arg, "pattern matching in task arguments is not yet supported"); |
| 51 | arg, | ||
| 52 | "pattern matching in task arguments is not yet supported", | ||
| 53 | ); | ||
| 54 | } | 51 | } |
| 55 | }, | 52 | }, |
| 56 | } | 53 | } |
diff --git a/embassy-macros/src/util/ctxt.rs b/embassy-macros/src/util/ctxt.rs index d668ae780..74c872c3c 100644 --- a/embassy-macros/src/util/ctxt.rs +++ b/embassy-macros/src/util/ctxt.rs | |||
| @@ -1,11 +1,12 @@ | |||
| 1 | // nifty utility borrowed from serde :) | 1 | // nifty utility borrowed from serde :) |
| 2 | // https://github.com/serde-rs/serde/blob/master/serde_derive/src/internals/ctxt.rs | 2 | // https://github.com/serde-rs/serde/blob/master/serde_derive/src/internals/ctxt.rs |
| 3 | 3 | ||
| 4 | use proc_macro2::TokenStream; | ||
| 5 | use quote::{quote, ToTokens}; | ||
| 6 | use std::cell::RefCell; | 4 | use std::cell::RefCell; |
| 7 | use std::fmt::Display; | 5 | use std::fmt::Display; |
| 8 | use std::thread; | 6 | use std::thread; |
| 7 | |||
| 8 | use proc_macro2::TokenStream; | ||
| 9 | use quote::{quote, ToTokens}; | ||
| 9 | use syn; | 10 | use syn; |
| 10 | 11 | ||
| 11 | /// A type to collect errors together and format them. | 12 | /// A type to collect errors together and format them. |
diff --git a/embassy-net/src/device.rs b/embassy-net/src/device.rs index 99c6a2212..c183bd58a 100644 --- a/embassy-net/src/device.rs +++ b/embassy-net/src/device.rs | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | use core::task::Waker; | 1 | use core::task::Waker; |
| 2 | use smoltcp::phy::Device as SmolDevice; | 2 | |
| 3 | use smoltcp::phy::DeviceCapabilities; | 3 | use smoltcp::phy::{Device as SmolDevice, DeviceCapabilities}; |
| 4 | use smoltcp::time::Instant as SmolInstant; | 4 | use smoltcp::time::Instant as SmolInstant; |
| 5 | 5 | ||
| 6 | use crate::packet_pool::PacketBoxExt; | 6 | use crate::packet_pool::PacketBoxExt; |
diff --git a/embassy-net/src/lib.rs b/embassy-net/src/lib.rs index 243dfda88..1c5ba103a 100644 --- a/embassy-net/src/lib.rs +++ b/embassy-net/src/lib.rs | |||
| @@ -18,11 +18,9 @@ pub mod tcp; | |||
| 18 | 18 | ||
| 19 | // smoltcp reexports | 19 | // smoltcp reexports |
| 20 | pub use smoltcp::phy::{DeviceCapabilities, Medium}; | 20 | pub use smoltcp::phy::{DeviceCapabilities, Medium}; |
| 21 | pub use smoltcp::time::Duration as SmolDuration; | 21 | pub use smoltcp::time::{Duration as SmolDuration, Instant as SmolInstant}; |
| 22 | pub use smoltcp::time::Instant as SmolInstant; | ||
| 23 | #[cfg(feature = "medium-ethernet")] | 22 | #[cfg(feature = "medium-ethernet")] |
| 24 | pub use smoltcp::wire::{EthernetAddress, HardwareAddress}; | 23 | pub use smoltcp::wire::{EthernetAddress, HardwareAddress}; |
| 25 | pub use smoltcp::wire::{IpAddress, IpCidr, Ipv4Address, Ipv4Cidr}; | 24 | pub use smoltcp::wire::{IpAddress, IpCidr, Ipv4Address, Ipv4Cidr}; |
| 26 | |||
| 27 | #[cfg(feature = "proto-ipv6")] | 25 | #[cfg(feature = "proto-ipv6")] |
| 28 | pub use smoltcp::wire::{Ipv6Address, Ipv6Cidr}; | 26 | pub use smoltcp::wire::{Ipv6Address, Ipv6Cidr}; |
diff --git a/embassy-net/src/packet_pool.rs b/embassy-net/src/packet_pool.rs index 99311ae74..cb8a1316c 100644 --- a/embassy-net/src/packet_pool.rs +++ b/embassy-net/src/packet_pool.rs | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | use as_slice::{AsMutSlice, AsSlice}; | ||
| 2 | use core::ops::{Deref, DerefMut, Range}; | 1 | use core::ops::{Deref, DerefMut, Range}; |
| 3 | 2 | ||
| 3 | use as_slice::{AsMutSlice, AsSlice}; | ||
| 4 | use atomic_pool::{pool, Box}; | 4 | use atomic_pool::{pool, Box}; |
| 5 | 5 | ||
| 6 | pub const MTU: usize = 1516; | 6 | pub const MTU: usize = 1516; |
| @@ -41,10 +41,7 @@ pub trait PacketBoxExt { | |||
| 41 | 41 | ||
| 42 | impl PacketBoxExt for PacketBox { | 42 | impl PacketBoxExt for PacketBox { |
| 43 | fn slice(self, range: Range<usize>) -> PacketBuf { | 43 | fn slice(self, range: Range<usize>) -> PacketBuf { |
| 44 | PacketBuf { | 44 | PacketBuf { packet: self, range } |
| 45 | packet: self, | ||
| 46 | range, | ||
| 47 | } | ||
| 48 | } | 45 | } |
| 49 | } | 46 | } |
| 50 | 47 | ||
diff --git a/embassy-net/src/stack.rs b/embassy-net/src/stack.rs index e28370df8..f3b1ff9d4 100644 --- a/embassy-net/src/stack.rs +++ b/embassy-net/src/stack.rs | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | use core::cell::UnsafeCell; | 1 | use core::cell::UnsafeCell; |
| 2 | use core::future::Future; | 2 | use core::future::Future; |
| 3 | use core::task::Context; | 3 | use core::task::{Context, Poll}; |
| 4 | use core::task::Poll; | 4 | |
| 5 | use embassy::time::{Instant, Timer}; | 5 | use embassy::time::{Instant, Timer}; |
| 6 | use embassy::waitqueue::WakerRegistration; | 6 | use embassy::waitqueue::WakerRegistration; |
| 7 | use futures::future::poll_fn; | 7 | use futures::future::poll_fn; |
| @@ -9,19 +9,17 @@ use futures::pin_mut; | |||
| 9 | use heapless::Vec; | 9 | use heapless::Vec; |
| 10 | #[cfg(feature = "dhcpv4")] | 10 | #[cfg(feature = "dhcpv4")] |
| 11 | use smoltcp::iface::SocketHandle; | 11 | use smoltcp::iface::SocketHandle; |
| 12 | use smoltcp::iface::{Interface, InterfaceBuilder}; | 12 | use smoltcp::iface::{Interface, InterfaceBuilder, SocketSet, SocketStorage}; |
| 13 | use smoltcp::iface::{SocketSet, SocketStorage}; | ||
| 14 | #[cfg(feature = "dhcpv4")] | ||
| 15 | use smoltcp::socket::dhcpv4; | ||
| 16 | use smoltcp::time::Instant as SmolInstant; | ||
| 17 | use smoltcp::wire::{IpCidr, Ipv4Address, Ipv4Cidr}; | ||
| 18 | |||
| 19 | #[cfg(feature = "medium-ethernet")] | 13 | #[cfg(feature = "medium-ethernet")] |
| 20 | use smoltcp::iface::{Neighbor, NeighborCache, Route, Routes}; | 14 | use smoltcp::iface::{Neighbor, NeighborCache, Route, Routes}; |
| 21 | #[cfg(feature = "medium-ethernet")] | 15 | #[cfg(feature = "medium-ethernet")] |
| 22 | use smoltcp::phy::{Device as _, Medium}; | 16 | use smoltcp::phy::{Device as _, Medium}; |
| 17 | #[cfg(feature = "dhcpv4")] | ||
| 18 | use smoltcp::socket::dhcpv4; | ||
| 19 | use smoltcp::time::Instant as SmolInstant; | ||
| 23 | #[cfg(feature = "medium-ethernet")] | 20 | #[cfg(feature = "medium-ethernet")] |
| 24 | use smoltcp::wire::{EthernetAddress, HardwareAddress, IpAddress}; | 21 | use smoltcp::wire::{EthernetAddress, HardwareAddress, IpAddress}; |
| 22 | use smoltcp::wire::{IpCidr, Ipv4Address, Ipv4Cidr}; | ||
| 25 | 23 | ||
| 26 | use crate::device::{Device, DeviceAdapter, LinkState}; | 24 | use crate::device::{Device, DeviceAdapter, LinkState}; |
| 27 | 25 | ||
| @@ -38,9 +36,7 @@ pub struct StackResources<const ADDR: usize, const SOCK: usize, const NEIGHBOR: | |||
| 38 | neighbor_cache: [Option<(IpAddress, Neighbor)>; NEIGHBOR], | 36 | neighbor_cache: [Option<(IpAddress, Neighbor)>; NEIGHBOR], |
| 39 | } | 37 | } |
| 40 | 38 | ||
| 41 | impl<const ADDR: usize, const SOCK: usize, const NEIGHBOR: usize> | 39 | impl<const ADDR: usize, const SOCK: usize, const NEIGHBOR: usize> StackResources<ADDR, SOCK, NEIGHBOR> { |
| 42 | StackResources<ADDR, SOCK, NEIGHBOR> | ||
| 43 | { | ||
| 44 | pub fn new() -> Self { | 40 | pub fn new() -> Self { |
| 45 | Self { | 41 | Self { |
| 46 | addresses: [IpCidr::new(Ipv4Address::UNSPECIFIED.into(), 32); ADDR], | 42 | addresses: [IpCidr::new(Ipv4Address::UNSPECIFIED.into(), 32); ADDR], |
| @@ -122,8 +118,7 @@ impl<D: Device + 'static> Stack<D> { | |||
| 122 | 118 | ||
| 123 | let sockets = SocketSet::new(&mut resources.sockets[..]); | 119 | let sockets = SocketSet::new(&mut resources.sockets[..]); |
| 124 | 120 | ||
| 125 | let next_local_port = | 121 | let next_local_port = (random_seed % (LOCAL_PORT_MAX - LOCAL_PORT_MIN) as u64) as u16 + LOCAL_PORT_MIN; |
| 126 | (random_seed % (LOCAL_PORT_MAX - LOCAL_PORT_MIN) as u64) as u16 + LOCAL_PORT_MIN; | ||
| 127 | 122 | ||
| 128 | let mut inner = Inner { | 123 | let mut inner = Inner { |
| 129 | device, | 124 | device, |
| @@ -194,11 +189,7 @@ impl SocketStack { | |||
| 194 | #[allow(clippy::absurd_extreme_comparisons)] | 189 | #[allow(clippy::absurd_extreme_comparisons)] |
| 195 | pub fn get_local_port(&mut self) -> u16 { | 190 | pub fn get_local_port(&mut self) -> u16 { |
| 196 | let res = self.next_local_port; | 191 | let res = self.next_local_port; |
| 197 | self.next_local_port = if res >= LOCAL_PORT_MAX { | 192 | self.next_local_port = if res >= LOCAL_PORT_MAX { LOCAL_PORT_MIN } else { res + 1 }; |
| 198 | LOCAL_PORT_MIN | ||
| 199 | } else { | ||
| 200 | res + 1 | ||
| 201 | }; | ||
| 202 | res | 193 | res |
| 203 | } | 194 | } |
| 204 | } | 195 | } |
| @@ -217,10 +208,7 @@ impl<D: Device + 'static> Inner<D> { | |||
| 217 | if medium == Medium::Ethernet { | 208 | if medium == Medium::Ethernet { |
| 218 | if let Some(gateway) = config.gateway { | 209 | if let Some(gateway) = config.gateway { |
| 219 | debug!(" Default gateway: {}", gateway); | 210 | debug!(" Default gateway: {}", gateway); |
| 220 | s.iface | 211 | s.iface.routes_mut().add_default_ipv4_route(gateway).unwrap(); |
| 221 | .routes_mut() | ||
| 222 | .add_default_ipv4_route(gateway) | ||
| 223 | .unwrap(); | ||
| 224 | } else { | 212 | } else { |
| 225 | debug!(" Default gateway: None"); | 213 | debug!(" Default gateway: None"); |
| 226 | s.iface.routes_mut().remove_default_ipv4_route(); | 214 | s.iface.routes_mut().remove_default_ipv4_route(); |
| @@ -259,10 +247,7 @@ impl<D: Device + 'static> Inner<D> { | |||
| 259 | s.waker.register(cx.waker()); | 247 | s.waker.register(cx.waker()); |
| 260 | 248 | ||
| 261 | let timestamp = instant_to_smoltcp(Instant::now()); | 249 | let timestamp = instant_to_smoltcp(Instant::now()); |
| 262 | if s.iface | 250 | if s.iface.poll(timestamp, &mut self.device, &mut s.sockets).is_err() { |
| 263 | .poll(timestamp, &mut self.device, &mut s.sockets) | ||
| 264 | .is_err() | ||
| 265 | { | ||
| 266 | // If poll() returns error, it may not be done yet, so poll again later. | 251 | // If poll() returns error, it may not be done yet, so poll again later. |
| 267 | cx.waker().wake_by_ref(); | 252 | cx.waker().wake_by_ref(); |
| 268 | return; | 253 | return; |
diff --git a/embassy-net/src/tcp.rs b/embassy-net/src/tcp.rs index 35ecf1b0c..c18391ace 100644 --- a/embassy-net/src/tcp.rs +++ b/embassy-net/src/tcp.rs | |||
| @@ -2,18 +2,17 @@ use core::cell::UnsafeCell; | |||
| 2 | use core::future::Future; | 2 | use core::future::Future; |
| 3 | use core::mem; | 3 | use core::mem; |
| 4 | use core::task::Poll; | 4 | use core::task::Poll; |
| 5 | |||
| 5 | use futures::future::poll_fn; | 6 | use futures::future::poll_fn; |
| 6 | use smoltcp::iface::{Interface, SocketHandle}; | 7 | use smoltcp::iface::{Interface, SocketHandle}; |
| 7 | use smoltcp::socket::tcp; | 8 | use smoltcp::socket::tcp; |
| 8 | use smoltcp::time::Duration; | 9 | use smoltcp::time::Duration; |
| 9 | use smoltcp::wire::IpEndpoint; | 10 | use smoltcp::wire::{IpEndpoint, IpListenEndpoint}; |
| 10 | use smoltcp::wire::IpListenEndpoint; | ||
| 11 | 11 | ||
| 12 | use super::stack::Stack; | ||
| 12 | use crate::stack::SocketStack; | 13 | use crate::stack::SocketStack; |
| 13 | use crate::Device; | 14 | use crate::Device; |
| 14 | 15 | ||
| 15 | use super::stack::Stack; | ||
| 16 | |||
| 17 | #[derive(PartialEq, Eq, Clone, Copy, Debug)] | 16 | #[derive(PartialEq, Eq, Clone, Copy, Debug)] |
| 18 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | 17 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] |
| 19 | pub enum Error { | 18 | pub enum Error { |
| @@ -57,11 +56,7 @@ pub struct TcpWriter<'a> { | |||
| 57 | } | 56 | } |
| 58 | 57 | ||
| 59 | impl<'a> TcpSocket<'a> { | 58 | impl<'a> TcpSocket<'a> { |
| 60 | pub fn new<D: Device>( | 59 | pub fn new<D: Device>(stack: &'a Stack<D>, rx_buffer: &'a mut [u8], tx_buffer: &'a mut [u8]) -> Self { |
| 61 | stack: &'a Stack<D>, | ||
| 62 | rx_buffer: &'a mut [u8], | ||
| 63 | tx_buffer: &'a mut [u8], | ||
| 64 | ) -> Self { | ||
| 65 | // safety: not accessed reentrantly. | 60 | // safety: not accessed reentrantly. |
| 66 | let s = unsafe { &mut *stack.socket.get() }; | 61 | let s = unsafe { &mut *stack.socket.get() }; |
| 67 | let rx_buffer: &'static mut [u8] = unsafe { mem::transmute(rx_buffer) }; | 62 | let rx_buffer: &'static mut [u8] = unsafe { mem::transmute(rx_buffer) }; |
| @@ -91,10 +86,7 @@ impl<'a> TcpSocket<'a> { | |||
| 91 | let local_port = unsafe { &mut *self.io.stack.get() }.get_local_port(); | 86 | let local_port = unsafe { &mut *self.io.stack.get() }.get_local_port(); |
| 92 | 87 | ||
| 93 | // safety: not accessed reentrantly. | 88 | // safety: not accessed reentrantly. |
| 94 | match unsafe { | 89 | match unsafe { self.io.with_mut(|s, i| s.connect(i, remote_endpoint, local_port)) } { |
| 95 | self.io | ||
| 96 | .with_mut(|s, i| s.connect(i, remote_endpoint, local_port)) | ||
| 97 | } { | ||
| 98 | Ok(()) => {} | 90 | Ok(()) => {} |
| 99 | Err(tcp::ConnectError::InvalidState) => return Err(ConnectError::InvalidState), | 91 | Err(tcp::ConnectError::InvalidState) => return Err(ConnectError::InvalidState), |
| 100 | Err(tcp::ConnectError::Unaddressable) => return Err(ConnectError::NoRoute), | 92 | Err(tcp::ConnectError::Unaddressable) => return Err(ConnectError::NoRoute), |
| @@ -102,9 +94,7 @@ impl<'a> TcpSocket<'a> { | |||
| 102 | 94 | ||
| 103 | futures::future::poll_fn(|cx| unsafe { | 95 | futures::future::poll_fn(|cx| unsafe { |
| 104 | self.io.with_mut(|s, _| match s.state() { | 96 | self.io.with_mut(|s, _| match s.state() { |
| 105 | tcp::State::Closed | tcp::State::TimeWait => { | 97 | tcp::State::Closed | tcp::State::TimeWait => Poll::Ready(Err(ConnectError::ConnectionReset)), |
| 106 | Poll::Ready(Err(ConnectError::ConnectionReset)) | ||
| 107 | } | ||
| 108 | tcp::State::Listen => unreachable!(), | 98 | tcp::State::Listen => unreachable!(), |
| 109 | tcp::State::SynSent | tcp::State::SynReceived => { | 99 | tcp::State::SynSent | tcp::State::SynReceived => { |
| 110 | s.register_send_waker(cx.waker()); | 100 | s.register_send_waker(cx.waker()); |
diff --git a/embassy-nrf/src/buffered_uarte.rs b/embassy-nrf/src/buffered_uarte.rs index ef3ccdc93..34f20efe7 100644 --- a/embassy-nrf/src/buffered_uarte.rs +++ b/embassy-nrf/src/buffered_uarte.rs | |||
| @@ -13,28 +13,26 @@ | |||
| 13 | //! | 13 | //! |
| 14 | //! Please also see [crate::uarte] to understand when [BufferedUarte] should be used. | 14 | //! Please also see [crate::uarte] to understand when [BufferedUarte] should be used. |
| 15 | 15 | ||
| 16 | use crate::interrupt::InterruptExt; | ||
| 17 | use crate::Unborrow; | ||
| 18 | use core::cmp::min; | 16 | use core::cmp::min; |
| 19 | use core::future::Future; | 17 | use core::future::Future; |
| 20 | use core::marker::PhantomData; | 18 | use core::marker::PhantomData; |
| 21 | use core::sync::atomic::{compiler_fence, Ordering}; | 19 | use core::sync::atomic::{compiler_fence, Ordering}; |
| 22 | use core::task::Poll; | 20 | use core::task::Poll; |
| 21 | |||
| 23 | use embassy::waitqueue::WakerRegistration; | 22 | use embassy::waitqueue::WakerRegistration; |
| 24 | use embassy_cortex_m::peripheral::{PeripheralMutex, PeripheralState, StateStorage}; | 23 | use embassy_cortex_m::peripheral::{PeripheralMutex, PeripheralState, StateStorage}; |
| 25 | use embassy_hal_common::ring_buffer::RingBuffer; | 24 | use embassy_hal_common::ring_buffer::RingBuffer; |
| 26 | use embassy_hal_common::{low_power_wait_until, unborrow}; | 25 | use embassy_hal_common::{low_power_wait_until, unborrow}; |
| 27 | use futures::future::poll_fn; | 26 | use futures::future::poll_fn; |
| 27 | // Re-export SVD variants to allow user to directly set values | ||
| 28 | pub use pac::uarte0::{baudrate::BAUDRATE_A as Baudrate, config::PARITY_A as Parity}; | ||
| 28 | 29 | ||
| 29 | use crate::gpio::Pin as GpioPin; | 30 | use crate::gpio::Pin as GpioPin; |
| 30 | use crate::pac; | 31 | use crate::interrupt::InterruptExt; |
| 31 | use crate::ppi::{AnyConfigurableChannel, ConfigurableChannel, Event, Ppi, Task}; | 32 | use crate::ppi::{AnyConfigurableChannel, ConfigurableChannel, Event, Ppi, Task}; |
| 32 | use crate::timer::Instance as TimerInstance; | 33 | use crate::timer::{Frequency, Instance as TimerInstance, Timer}; |
| 33 | use crate::timer::{Frequency, Timer}; | ||
| 34 | use crate::uarte::{apply_workaround_for_enable_anomaly, Config, Instance as UarteInstance}; | 34 | use crate::uarte::{apply_workaround_for_enable_anomaly, Config, Instance as UarteInstance}; |
| 35 | 35 | use crate::{pac, Unborrow}; | |
| 36 | // Re-export SVD variants to allow user to directly set values | ||
| 37 | pub use pac::uarte0::{baudrate::BAUDRATE_A as Baudrate, config::PARITY_A as Parity}; | ||
| 38 | 36 | ||
| 39 | #[derive(Copy, Clone, Debug, PartialEq)] | 37 | #[derive(Copy, Clone, Debug, PartialEq)] |
| 40 | enum RxState { | 38 | enum RxState { |
| @@ -234,9 +232,7 @@ impl<'d, U: UarteInstance, T: TimerInstance> embedded_io::asynch::Read for Buffe | |||
| 234 | } | 232 | } |
| 235 | } | 233 | } |
| 236 | 234 | ||
| 237 | impl<'d, U: UarteInstance, T: TimerInstance> embedded_io::asynch::BufRead | 235 | impl<'d, U: UarteInstance, T: TimerInstance> embedded_io::asynch::BufRead for BufferedUarte<'d, U, T> { |
| 238 | for BufferedUarte<'d, U, T> | ||
| 239 | { | ||
| 240 | type FillBufFuture<'a> = impl Future<Output = Result<&'a [u8], Self::Error>> | 236 | type FillBufFuture<'a> = impl Future<Output = Result<&'a [u8], Self::Error>> |
| 241 | where | 237 | where |
| 242 | Self: 'a; | 238 | Self: 'a; |
| @@ -276,9 +272,7 @@ impl<'d, U: UarteInstance, T: TimerInstance> embedded_io::asynch::BufRead | |||
| 276 | } | 272 | } |
| 277 | } | 273 | } |
| 278 | 274 | ||
| 279 | impl<'d, U: UarteInstance, T: TimerInstance> embedded_io::asynch::Write | 275 | impl<'d, U: UarteInstance, T: TimerInstance> embedded_io::asynch::Write for BufferedUarte<'d, U, T> { |
| 280 | for BufferedUarte<'d, U, T> | ||
| 281 | { | ||
| 282 | type WriteFuture<'a> = impl Future<Output = Result<usize, Self::Error>> | 276 | type WriteFuture<'a> = impl Future<Output = Result<usize, Self::Error>> |
| 283 | where | 277 | where |
| 284 | Self: 'a; | 278 | Self: 'a; |
diff --git a/embassy-nrf/src/chips/nrf52805.rs b/embassy-nrf/src/chips/nrf52805.rs index 31659859b..8fca4da1a 100644 --- a/embassy-nrf/src/chips/nrf52805.rs +++ b/embassy-nrf/src/chips/nrf52805.rs | |||
| @@ -197,9 +197,10 @@ impl_saadc_input!(P0_04, ANALOGINPUT2); | |||
| 197 | impl_saadc_input!(P0_05, ANALOGINPUT3); | 197 | impl_saadc_input!(P0_05, ANALOGINPUT3); |
| 198 | 198 | ||
| 199 | pub mod irqs { | 199 | pub mod irqs { |
| 200 | use crate::pac::Interrupt as InterruptEnum; | ||
| 201 | use embassy_macros::cortex_m_interrupt_declare as declare; | 200 | use embassy_macros::cortex_m_interrupt_declare as declare; |
| 202 | 201 | ||
| 202 | use crate::pac::Interrupt as InterruptEnum; | ||
| 203 | |||
| 203 | declare!(POWER_CLOCK); | 204 | declare!(POWER_CLOCK); |
| 204 | declare!(RADIO); | 205 | declare!(RADIO); |
| 205 | declare!(UARTE0_UART0); | 206 | declare!(UARTE0_UART0); |
diff --git a/embassy-nrf/src/chips/nrf52810.rs b/embassy-nrf/src/chips/nrf52810.rs index 195be51c8..538a617d2 100644 --- a/embassy-nrf/src/chips/nrf52810.rs +++ b/embassy-nrf/src/chips/nrf52810.rs | |||
| @@ -218,9 +218,10 @@ impl_saadc_input!(P0_30, ANALOGINPUT6); | |||
| 218 | impl_saadc_input!(P0_31, ANALOGINPUT7); | 218 | impl_saadc_input!(P0_31, ANALOGINPUT7); |
| 219 | 219 | ||
| 220 | pub mod irqs { | 220 | pub mod irqs { |
| 221 | use crate::pac::Interrupt as InterruptEnum; | ||
| 222 | use embassy_macros::cortex_m_interrupt_declare as declare; | 221 | use embassy_macros::cortex_m_interrupt_declare as declare; |
| 223 | 222 | ||
| 223 | use crate::pac::Interrupt as InterruptEnum; | ||
| 224 | |||
| 224 | declare!(POWER_CLOCK); | 225 | declare!(POWER_CLOCK); |
| 225 | declare!(RADIO); | 226 | declare!(RADIO); |
| 226 | declare!(UARTE0_UART0); | 227 | declare!(UARTE0_UART0); |
diff --git a/embassy-nrf/src/chips/nrf52811.rs b/embassy-nrf/src/chips/nrf52811.rs index 18f054059..808adf517 100644 --- a/embassy-nrf/src/chips/nrf52811.rs +++ b/embassy-nrf/src/chips/nrf52811.rs | |||
| @@ -219,9 +219,10 @@ impl_saadc_input!(P0_30, ANALOGINPUT6); | |||
| 219 | impl_saadc_input!(P0_31, ANALOGINPUT7); | 219 | impl_saadc_input!(P0_31, ANALOGINPUT7); |
| 220 | 220 | ||
| 221 | pub mod irqs { | 221 | pub mod irqs { |
| 222 | use crate::pac::Interrupt as InterruptEnum; | ||
| 223 | use embassy_macros::cortex_m_interrupt_declare as declare; | 222 | use embassy_macros::cortex_m_interrupt_declare as declare; |
| 224 | 223 | ||
| 224 | use crate::pac::Interrupt as InterruptEnum; | ||
| 225 | |||
| 225 | declare!(POWER_CLOCK); | 226 | declare!(POWER_CLOCK); |
| 226 | declare!(RADIO); | 227 | declare!(RADIO); |
| 227 | declare!(UARTE0_UART0); | 228 | declare!(UARTE0_UART0); |
diff --git a/embassy-nrf/src/chips/nrf52820.rs b/embassy-nrf/src/chips/nrf52820.rs index b4ad4c729..6be5bd361 100644 --- a/embassy-nrf/src/chips/nrf52820.rs +++ b/embassy-nrf/src/chips/nrf52820.rs | |||
| @@ -211,9 +211,10 @@ impl_ppi_channel!(PPI_CH30, 30 => static); | |||
| 211 | impl_ppi_channel!(PPI_CH31, 31 => static); | 211 | impl_ppi_channel!(PPI_CH31, 31 => static); |
| 212 | 212 | ||
| 213 | pub mod irqs { | 213 | pub mod irqs { |
| 214 | use crate::pac::Interrupt as InterruptEnum; | ||
| 215 | use embassy_macros::cortex_m_interrupt_declare as declare; | 214 | use embassy_macros::cortex_m_interrupt_declare as declare; |
| 216 | 215 | ||
| 216 | use crate::pac::Interrupt as InterruptEnum; | ||
| 217 | |||
| 217 | declare!(POWER_CLOCK); | 218 | declare!(POWER_CLOCK); |
| 218 | declare!(RADIO); | 219 | declare!(RADIO); |
| 219 | declare!(UARTE0_UART0); | 220 | declare!(UARTE0_UART0); |
diff --git a/embassy-nrf/src/chips/nrf52832.rs b/embassy-nrf/src/chips/nrf52832.rs index d578519ff..cdc644d6e 100644 --- a/embassy-nrf/src/chips/nrf52832.rs +++ b/embassy-nrf/src/chips/nrf52832.rs | |||
| @@ -235,9 +235,10 @@ impl_saadc_input!(P0_30, ANALOGINPUT6); | |||
| 235 | impl_saadc_input!(P0_31, ANALOGINPUT7); | 235 | impl_saadc_input!(P0_31, ANALOGINPUT7); |
| 236 | 236 | ||
| 237 | pub mod irqs { | 237 | pub mod irqs { |
| 238 | use crate::pac::Interrupt as InterruptEnum; | ||
| 239 | use embassy_macros::cortex_m_interrupt_declare as declare; | 238 | use embassy_macros::cortex_m_interrupt_declare as declare; |
| 240 | 239 | ||
| 240 | use crate::pac::Interrupt as InterruptEnum; | ||
| 241 | |||
| 241 | declare!(POWER_CLOCK); | 242 | declare!(POWER_CLOCK); |
| 242 | declare!(RADIO); | 243 | declare!(RADIO); |
| 243 | declare!(UARTE0_UART0); | 244 | declare!(UARTE0_UART0); |
diff --git a/embassy-nrf/src/chips/nrf52833.rs b/embassy-nrf/src/chips/nrf52833.rs index 92f415a51..4c3c5574d 100644 --- a/embassy-nrf/src/chips/nrf52833.rs +++ b/embassy-nrf/src/chips/nrf52833.rs | |||
| @@ -278,9 +278,10 @@ impl_saadc_input!(P0_30, ANALOGINPUT6); | |||
| 278 | impl_saadc_input!(P0_31, ANALOGINPUT7); | 278 | impl_saadc_input!(P0_31, ANALOGINPUT7); |
| 279 | 279 | ||
| 280 | pub mod irqs { | 280 | pub mod irqs { |
| 281 | use crate::pac::Interrupt as InterruptEnum; | ||
| 282 | use embassy_macros::cortex_m_interrupt_declare as declare; | 281 | use embassy_macros::cortex_m_interrupt_declare as declare; |
| 283 | 282 | ||
| 283 | use crate::pac::Interrupt as InterruptEnum; | ||
| 284 | |||
| 284 | declare!(POWER_CLOCK); | 285 | declare!(POWER_CLOCK); |
| 285 | declare!(RADIO); | 286 | declare!(RADIO); |
| 286 | declare!(UARTE0_UART0); | 287 | declare!(UARTE0_UART0); |
diff --git a/embassy-nrf/src/chips/nrf52840.rs b/embassy-nrf/src/chips/nrf52840.rs index e7a94b18f..bdaeadb9b 100644 --- a/embassy-nrf/src/chips/nrf52840.rs +++ b/embassy-nrf/src/chips/nrf52840.rs | |||
| @@ -283,9 +283,10 @@ impl_saadc_input!(P0_30, ANALOGINPUT6); | |||
| 283 | impl_saadc_input!(P0_31, ANALOGINPUT7); | 283 | impl_saadc_input!(P0_31, ANALOGINPUT7); |
| 284 | 284 | ||
| 285 | pub mod irqs { | 285 | pub mod irqs { |
| 286 | use crate::pac::Interrupt as InterruptEnum; | ||
| 287 | use embassy_macros::cortex_m_interrupt_declare as declare; | 286 | use embassy_macros::cortex_m_interrupt_declare as declare; |
| 288 | 287 | ||
| 288 | use crate::pac::Interrupt as InterruptEnum; | ||
| 289 | |||
| 289 | declare!(POWER_CLOCK); | 290 | declare!(POWER_CLOCK); |
| 290 | declare!(RADIO); | 291 | declare!(RADIO); |
| 291 | declare!(UARTE0_UART0); | 292 | declare!(UARTE0_UART0); |
diff --git a/embassy-nrf/src/chips/nrf5340_app.rs b/embassy-nrf/src/chips/nrf5340_app.rs index 13ed23cd7..26dc56bdb 100644 --- a/embassy-nrf/src/chips/nrf5340_app.rs +++ b/embassy-nrf/src/chips/nrf5340_app.rs | |||
| @@ -468,9 +468,10 @@ impl_saadc_input!(P0_19, ANALOGINPUT6); | |||
| 468 | impl_saadc_input!(P0_20, ANALOGINPUT7); | 468 | impl_saadc_input!(P0_20, ANALOGINPUT7); |
| 469 | 469 | ||
| 470 | pub mod irqs { | 470 | pub mod irqs { |
| 471 | use crate::pac::Interrupt as InterruptEnum; | ||
| 472 | use embassy_macros::cortex_m_interrupt_declare as declare; | 471 | use embassy_macros::cortex_m_interrupt_declare as declare; |
| 473 | 472 | ||
| 473 | use crate::pac::Interrupt as InterruptEnum; | ||
| 474 | |||
| 474 | declare!(FPU); | 475 | declare!(FPU); |
| 475 | declare!(CACHE); | 476 | declare!(CACHE); |
| 476 | declare!(SPU); | 477 | declare!(SPU); |
diff --git a/embassy-nrf/src/chips/nrf5340_net.rs b/embassy-nrf/src/chips/nrf5340_net.rs index a7e70cdc3..e28cfe013 100644 --- a/embassy-nrf/src/chips/nrf5340_net.rs +++ b/embassy-nrf/src/chips/nrf5340_net.rs | |||
| @@ -328,9 +328,10 @@ impl_ppi_channel!(PPI_CH30, 30 => configurable); | |||
| 328 | impl_ppi_channel!(PPI_CH31, 31 => configurable); | 328 | impl_ppi_channel!(PPI_CH31, 31 => configurable); |
| 329 | 329 | ||
| 330 | pub mod irqs { | 330 | pub mod irqs { |
| 331 | use crate::pac::Interrupt as InterruptEnum; | ||
| 332 | use embassy_macros::cortex_m_interrupt_declare as declare; | 331 | use embassy_macros::cortex_m_interrupt_declare as declare; |
| 333 | 332 | ||
| 333 | use crate::pac::Interrupt as InterruptEnum; | ||
| 334 | |||
| 334 | declare!(CLOCK_POWER); | 335 | declare!(CLOCK_POWER); |
| 335 | declare!(RADIO); | 336 | declare!(RADIO); |
| 336 | declare!(RNG); | 337 | declare!(RNG); |
diff --git a/embassy-nrf/src/chips/nrf9160.rs b/embassy-nrf/src/chips/nrf9160.rs index 57ff39b7b..1a0bd10fe 100644 --- a/embassy-nrf/src/chips/nrf9160.rs +++ b/embassy-nrf/src/chips/nrf9160.rs | |||
| @@ -346,9 +346,10 @@ impl_saadc_input!(P0_19, ANALOGINPUT6); | |||
| 346 | impl_saadc_input!(P0_20, ANALOGINPUT7); | 346 | impl_saadc_input!(P0_20, ANALOGINPUT7); |
| 347 | 347 | ||
| 348 | pub mod irqs { | 348 | pub mod irqs { |
| 349 | use crate::pac::Interrupt as InterruptEnum; | ||
| 350 | use embassy_macros::cortex_m_interrupt_declare as declare; | 349 | use embassy_macros::cortex_m_interrupt_declare as declare; |
| 351 | 350 | ||
| 351 | use crate::pac::Interrupt as InterruptEnum; | ||
| 352 | |||
| 352 | declare!(SPU); | 353 | declare!(SPU); |
| 353 | declare!(CLOCK_POWER); | 354 | declare!(CLOCK_POWER); |
| 354 | declare!(UARTE0_SPIM0_SPIS0_TWIM0_TWIS0); | 355 | declare!(UARTE0_SPIM0_SPIS0_TWIM0_TWIS0); |
diff --git a/embassy-nrf/src/gpio.rs b/embassy-nrf/src/gpio.rs index a6c846213..e68b8874a 100644 --- a/embassy-nrf/src/gpio.rs +++ b/embassy-nrf/src/gpio.rs | |||
| @@ -4,15 +4,13 @@ use core::convert::Infallible; | |||
| 4 | use core::hint::unreachable_unchecked; | 4 | use core::hint::unreachable_unchecked; |
| 5 | use core::marker::PhantomData; | 5 | use core::marker::PhantomData; |
| 6 | 6 | ||
| 7 | use crate::Unborrow; | ||
| 8 | use cfg_if::cfg_if; | 7 | use cfg_if::cfg_if; |
| 9 | use embassy_hal_common::{unborrow, unsafe_impl_unborrow}; | 8 | use embassy_hal_common::{unborrow, unsafe_impl_unborrow}; |
| 10 | 9 | ||
| 11 | use crate::pac; | 10 | use self::sealed::Pin as _; |
| 12 | use crate::pac::p0 as gpio; | 11 | use crate::pac::p0 as gpio; |
| 13 | use crate::pac::p0::pin_cnf::{DRIVE_A, PULL_A}; | 12 | use crate::pac::p0::pin_cnf::{DRIVE_A, PULL_A}; |
| 14 | 13 | use crate::{pac, Unborrow}; | |
| 15 | use self::sealed::Pin as _; | ||
| 16 | 14 | ||
| 17 | /// A GPIO port with up to 32 pins. | 15 | /// A GPIO port with up to 32 pins. |
| 18 | #[derive(Debug, Eq, PartialEq)] | 16 | #[derive(Debug, Eq, PartialEq)] |
| @@ -93,11 +91,7 @@ pub struct Output<'d, T: Pin> { | |||
| 93 | } | 91 | } |
| 94 | 92 | ||
| 95 | impl<'d, T: Pin> Output<'d, T> { | 93 | impl<'d, T: Pin> Output<'d, T> { |
| 96 | pub fn new( | 94 | pub fn new(pin: impl Unborrow<Target = T> + 'd, initial_output: Level, drive: OutputDrive) -> Self { |
| 97 | pin: impl Unborrow<Target = T> + 'd, | ||
| 98 | initial_output: Level, | ||
| 99 | drive: OutputDrive, | ||
| 100 | ) -> Self { | ||
| 101 | let mut pin = Flex::new(pin); | 95 | let mut pin = Flex::new(pin); |
| 102 | match initial_output { | 96 | match initial_output { |
| 103 | Level::High => pin.set_high(), | 97 | Level::High => pin.set_high(), |
diff --git a/embassy-nrf/src/gpiote.rs b/embassy-nrf/src/gpiote.rs index 051546236..d4e1cb35c 100644 --- a/embassy-nrf/src/gpiote.rs +++ b/embassy-nrf/src/gpiote.rs | |||
| @@ -1,17 +1,17 @@ | |||
| 1 | use crate::interrupt::{Interrupt, InterruptExt}; | ||
| 2 | use core::convert::Infallible; | 1 | use core::convert::Infallible; |
| 3 | use core::future::Future; | 2 | use core::future::Future; |
| 4 | use core::marker::PhantomData; | 3 | use core::marker::PhantomData; |
| 5 | use core::task::{Context, Poll}; | 4 | use core::task::{Context, Poll}; |
| 5 | |||
| 6 | use embassy::waitqueue::AtomicWaker; | 6 | use embassy::waitqueue::AtomicWaker; |
| 7 | use embassy_hal_common::unsafe_impl_unborrow; | 7 | use embassy_hal_common::unsafe_impl_unborrow; |
| 8 | use futures::future::poll_fn; | 8 | use futures::future::poll_fn; |
| 9 | 9 | ||
| 10 | use crate::gpio::sealed::Pin as _; | 10 | use crate::gpio::sealed::Pin as _; |
| 11 | use crate::gpio::{AnyPin, Flex, Input, Output, Pin as GpioPin}; | 11 | use crate::gpio::{AnyPin, Flex, Input, Output, Pin as GpioPin}; |
| 12 | use crate::pac; | 12 | use crate::interrupt::{Interrupt, InterruptExt}; |
| 13 | use crate::ppi::{Event, Task}; | 13 | use crate::ppi::{Event, Task}; |
| 14 | use crate::{interrupt, peripherals}; | 14 | use crate::{interrupt, pac, peripherals}; |
| 15 | 15 | ||
| 16 | pub const CHANNEL_COUNT: usize = 8; | 16 | pub const CHANNEL_COUNT: usize = 8; |
| 17 | 17 | ||
| @@ -468,9 +468,7 @@ mod eh1 { | |||
| 468 | type Error = Infallible; | 468 | type Error = Infallible; |
| 469 | } | 469 | } |
| 470 | 470 | ||
| 471 | impl<'d, C: Channel, T: GpioPin> embedded_hal_1::digital::blocking::InputPin | 471 | impl<'d, C: Channel, T: GpioPin> embedded_hal_1::digital::blocking::InputPin for InputChannel<'d, C, T> { |
| 472 | for InputChannel<'d, C, T> | ||
| 473 | { | ||
| 474 | fn is_high(&self) -> Result<bool, Self::Error> { | 472 | fn is_high(&self) -> Result<bool, Self::Error> { |
| 475 | Ok(self.pin.is_high()) | 473 | Ok(self.pin.is_high()) |
| 476 | } | 474 | } |
diff --git a/embassy-nrf/src/lib.rs b/embassy-nrf/src/lib.rs index 6eaadfc63..1f1ffc99d 100644 --- a/embassy-nrf/src/lib.rs +++ b/embassy-nrf/src/lib.rs | |||
| @@ -35,10 +35,7 @@ | |||
| 35 | //! mutable slices always reside in RAM. | 35 | //! mutable slices always reside in RAM. |
| 36 | 36 | ||
| 37 | #![no_std] | 37 | #![no_std] |
| 38 | #![cfg_attr( | 38 | #![cfg_attr(feature = "nightly", feature(generic_associated_types, type_alias_impl_trait))] |
| 39 | feature = "nightly", | ||
| 40 | feature(generic_associated_types, type_alias_impl_trait) | ||
| 41 | )] | ||
| 42 | 39 | ||
| 43 | #[cfg(not(any( | 40 | #[cfg(not(any( |
| 44 | feature = "nrf51", | 41 | feature = "nrf51", |
| @@ -115,9 +112,10 @@ mod chip; | |||
| 115 | pub use chip::EASY_DMA_SIZE; | 112 | pub use chip::EASY_DMA_SIZE; |
| 116 | 113 | ||
| 117 | pub mod interrupt { | 114 | pub mod interrupt { |
| 118 | pub use crate::chip::irqs::*; | ||
| 119 | pub use cortex_m::interrupt::{CriticalSection, Mutex}; | 115 | pub use cortex_m::interrupt::{CriticalSection, Mutex}; |
| 120 | pub use embassy_cortex_m::interrupt::*; | 116 | pub use embassy_cortex_m::interrupt::*; |
| 117 | |||
| 118 | pub use crate::chip::irqs::*; | ||
| 121 | } | 119 | } |
| 122 | 120 | ||
| 123 | // Reexports | 121 | // Reexports |
| @@ -126,7 +124,6 @@ pub mod interrupt { | |||
| 126 | pub use chip::pac; | 124 | pub use chip::pac; |
| 127 | #[cfg(not(feature = "unstable-pac"))] | 125 | #[cfg(not(feature = "unstable-pac"))] |
| 128 | pub(crate) use chip::pac; | 126 | pub(crate) use chip::pac; |
| 129 | |||
| 130 | pub use chip::{peripherals, Peripherals}; | 127 | pub use chip::{peripherals, Peripherals}; |
| 131 | pub use embassy_cortex_m::executor; | 128 | pub use embassy_cortex_m::executor; |
| 132 | pub use embassy_hal_common::{unborrow, Unborrow}; | 129 | pub use embassy_hal_common::{unborrow, Unborrow}; |
diff --git a/embassy-nrf/src/nvmc.rs b/embassy-nrf/src/nvmc.rs index 108a71d5e..e350f8c99 100644 --- a/embassy-nrf/src/nvmc.rs +++ b/embassy-nrf/src/nvmc.rs | |||
| @@ -1,17 +1,16 @@ | |||
| 1 | //! Nvmcerature sensor interface. | 1 | //! Nvmcerature sensor interface. |
| 2 | 2 | ||
| 3 | use crate::pac; | ||
| 4 | use crate::peripherals::NVMC; | ||
| 5 | |||
| 6 | use crate::Unborrow; | ||
| 7 | use core::marker::PhantomData; | 3 | use core::marker::PhantomData; |
| 8 | use core::ptr; | 4 | use core::{ptr, slice}; |
| 9 | use core::slice; | 5 | |
| 10 | use embassy_hal_common::unborrow; | 6 | use embassy_hal_common::unborrow; |
| 11 | use embedded_storage::nor_flash::{ | 7 | use embedded_storage::nor_flash::{ |
| 12 | ErrorType, MultiwriteNorFlash, NorFlash, NorFlashError, NorFlashErrorKind, ReadNorFlash, | 8 | ErrorType, MultiwriteNorFlash, NorFlash, NorFlashError, NorFlashErrorKind, ReadNorFlash, |
| 13 | }; | 9 | }; |
| 14 | 10 | ||
| 11 | use crate::peripherals::NVMC; | ||
| 12 | use crate::{pac, Unborrow}; | ||
| 13 | |||
| 15 | pub const PAGE_SIZE: usize = 4096; | 14 | pub const PAGE_SIZE: usize = 4096; |
| 16 | pub const FLASH_SIZE: usize = crate::chip::FLASH_SIZE; | 15 | pub const FLASH_SIZE: usize = crate::chip::FLASH_SIZE; |
| 17 | 16 | ||
diff --git a/embassy-nrf/src/ppi/dppi.rs b/embassy-nrf/src/ppi/dppi.rs index 8609ef8d4..d0bffb1e0 100644 --- a/embassy-nrf/src/ppi/dppi.rs +++ b/embassy-nrf/src/ppi/dppi.rs | |||
| @@ -1,11 +1,9 @@ | |||
| 1 | use core::marker::PhantomData; | 1 | use core::marker::PhantomData; |
| 2 | 2 | ||
| 3 | use crate::Unborrow; | ||
| 4 | use embassy_hal_common::unborrow; | 3 | use embassy_hal_common::unborrow; |
| 5 | 4 | ||
| 6 | use crate::pac; | ||
| 7 | |||
| 8 | use super::{Channel, ConfigurableChannel, Event, Ppi, Task}; | 5 | use super::{Channel, ConfigurableChannel, Event, Ppi, Task}; |
| 6 | use crate::{pac, Unborrow}; | ||
| 9 | 7 | ||
| 10 | const DPPI_ENABLE_BIT: u32 = 0x8000_0000; | 8 | const DPPI_ENABLE_BIT: u32 = 0x8000_0000; |
| 11 | const DPPI_CHANNEL_MASK: u32 = 0x0000_00FF; | 9 | const DPPI_CHANNEL_MASK: u32 = 0x0000_00FF; |
| @@ -21,12 +19,7 @@ impl<'d, C: ConfigurableChannel> Ppi<'d, C, 1, 1> { | |||
| 21 | } | 19 | } |
| 22 | 20 | ||
| 23 | impl<'d, C: ConfigurableChannel> Ppi<'d, C, 1, 2> { | 21 | impl<'d, C: ConfigurableChannel> Ppi<'d, C, 1, 2> { |
| 24 | pub fn new_one_to_two( | 22 | pub fn new_one_to_two(ch: impl Unborrow<Target = C> + 'd, event: Event, task1: Task, task2: Task) -> Self { |
| 25 | ch: impl Unborrow<Target = C> + 'd, | ||
| 26 | event: Event, | ||
| 27 | task1: Task, | ||
| 28 | task2: Task, | ||
| 29 | ) -> Self { | ||
| 30 | Ppi::new_many_to_many(ch, [event], [task1, task2]) | 23 | Ppi::new_many_to_many(ch, [event], [task1, task2]) |
| 31 | } | 24 | } |
| 32 | } | 25 | } |
| @@ -64,9 +57,7 @@ impl<'d, C: ConfigurableChannel, const EVENT_COUNT: usize, const TASK_COUNT: usi | |||
| 64 | } | 57 | } |
| 65 | } | 58 | } |
| 66 | 59 | ||
| 67 | impl<'d, C: Channel, const EVENT_COUNT: usize, const TASK_COUNT: usize> | 60 | impl<'d, C: Channel, const EVENT_COUNT: usize, const TASK_COUNT: usize> Ppi<'d, C, EVENT_COUNT, TASK_COUNT> { |
| 68 | Ppi<'d, C, EVENT_COUNT, TASK_COUNT> | ||
| 69 | { | ||
| 70 | /// Enables the channel. | 61 | /// Enables the channel. |
| 71 | pub fn enable(&mut self) { | 62 | pub fn enable(&mut self) { |
| 72 | let n = self.ch.number(); | 63 | let n = self.ch.number(); |
| @@ -80,9 +71,7 @@ impl<'d, C: Channel, const EVENT_COUNT: usize, const TASK_COUNT: usize> | |||
| 80 | } | 71 | } |
| 81 | } | 72 | } |
| 82 | 73 | ||
| 83 | impl<'d, C: Channel, const EVENT_COUNT: usize, const TASK_COUNT: usize> Drop | 74 | impl<'d, C: Channel, const EVENT_COUNT: usize, const TASK_COUNT: usize> Drop for Ppi<'d, C, EVENT_COUNT, TASK_COUNT> { |
| 84 | for Ppi<'d, C, EVENT_COUNT, TASK_COUNT> | ||
| 85 | { | ||
| 86 | fn drop(&mut self) { | 75 | fn drop(&mut self) { |
| 87 | self.disable(); | 76 | self.disable(); |
| 88 | 77 | ||
diff --git a/embassy-nrf/src/ppi/mod.rs b/embassy-nrf/src/ppi/mod.rs index faabbf7ca..660db6410 100644 --- a/embassy-nrf/src/ppi/mod.rs +++ b/embassy-nrf/src/ppi/mod.rs | |||
| @@ -15,12 +15,13 @@ | |||
| 15 | //! many tasks and events, but any single task or event can only be coupled with one channel. | 15 | //! many tasks and events, but any single task or event can only be coupled with one channel. |
| 16 | //! | 16 | //! |
| 17 | 17 | ||
| 18 | use crate::peripherals; | ||
| 19 | use crate::Unborrow; | ||
| 20 | use core::marker::PhantomData; | 18 | use core::marker::PhantomData; |
| 21 | use core::ptr::NonNull; | 19 | use core::ptr::NonNull; |
| 20 | |||
| 22 | use embassy_hal_common::unsafe_impl_unborrow; | 21 | use embassy_hal_common::unsafe_impl_unborrow; |
| 23 | 22 | ||
| 23 | use crate::{peripherals, Unborrow}; | ||
| 24 | |||
| 24 | #[cfg(feature = "_dppi")] | 25 | #[cfg(feature = "_dppi")] |
| 25 | mod dppi; | 26 | mod dppi; |
| 26 | #[cfg(feature = "_ppi")] | 27 | #[cfg(feature = "_ppi")] |
diff --git a/embassy-nrf/src/ppi/ppi.rs b/embassy-nrf/src/ppi/ppi.rs index d832d69e7..e5c86d444 100644 --- a/embassy-nrf/src/ppi/ppi.rs +++ b/embassy-nrf/src/ppi/ppi.rs | |||
| @@ -1,10 +1,9 @@ | |||
| 1 | use core::marker::PhantomData; | 1 | use core::marker::PhantomData; |
| 2 | 2 | ||
| 3 | use crate::Unborrow; | ||
| 4 | use embassy_hal_common::unborrow; | 3 | use embassy_hal_common::unborrow; |
| 5 | 4 | ||
| 6 | use super::{Channel, ConfigurableChannel, Event, Ppi, StaticChannel, Task}; | 5 | use super::{Channel, ConfigurableChannel, Event, Ppi, StaticChannel, Task}; |
| 7 | use crate::pac; | 6 | use crate::{pac, Unborrow}; |
| 8 | 7 | ||
| 9 | impl Task { | 8 | impl Task { |
| 10 | fn reg_val(&self) -> u32 { | 9 | fn reg_val(&self) -> u32 { |
| @@ -55,12 +54,7 @@ impl<'d, C: ConfigurableChannel> Ppi<'d, C, 1, 1> { | |||
| 55 | 54 | ||
| 56 | #[cfg(not(feature = "nrf51"))] // Not for nrf51 because of the fork task | 55 | #[cfg(not(feature = "nrf51"))] // Not for nrf51 because of the fork task |
| 57 | impl<'d, C: ConfigurableChannel> Ppi<'d, C, 1, 2> { | 56 | impl<'d, C: ConfigurableChannel> Ppi<'d, C, 1, 2> { |
| 58 | pub fn new_one_to_two( | 57 | pub fn new_one_to_two(ch: impl Unborrow<Target = C> + 'd, event: Event, task1: Task, task2: Task) -> Self { |
| 59 | ch: impl Unborrow<Target = C> + 'd, | ||
| 60 | event: Event, | ||
| 61 | task1: Task, | ||
| 62 | task2: Task, | ||
| 63 | ) -> Self { | ||
| 64 | unborrow!(ch); | 58 | unborrow!(ch); |
| 65 | 59 | ||
| 66 | let r = regs(); | 60 | let r = regs(); |
| @@ -76,9 +70,7 @@ impl<'d, C: ConfigurableChannel> Ppi<'d, C, 1, 2> { | |||
| 76 | } | 70 | } |
| 77 | } | 71 | } |
| 78 | 72 | ||
| 79 | impl<'d, C: Channel, const EVENT_COUNT: usize, const TASK_COUNT: usize> | 73 | impl<'d, C: Channel, const EVENT_COUNT: usize, const TASK_COUNT: usize> Ppi<'d, C, EVENT_COUNT, TASK_COUNT> { |
| 80 | Ppi<'d, C, EVENT_COUNT, TASK_COUNT> | ||
| 81 | { | ||
| 82 | /// Enables the channel. | 74 | /// Enables the channel. |
| 83 | pub fn enable(&mut self) { | 75 | pub fn enable(&mut self) { |
| 84 | let n = self.ch.number(); | 76 | let n = self.ch.number(); |
| @@ -92,9 +84,7 @@ impl<'d, C: Channel, const EVENT_COUNT: usize, const TASK_COUNT: usize> | |||
| 92 | } | 84 | } |
| 93 | } | 85 | } |
| 94 | 86 | ||
| 95 | impl<'d, C: Channel, const EVENT_COUNT: usize, const TASK_COUNT: usize> Drop | 87 | impl<'d, C: Channel, const EVENT_COUNT: usize, const TASK_COUNT: usize> Drop for Ppi<'d, C, EVENT_COUNT, TASK_COUNT> { |
| 96 | for Ppi<'d, C, EVENT_COUNT, TASK_COUNT> | ||
| 97 | { | ||
| 98 | fn drop(&mut self) { | 88 | fn drop(&mut self) { |
| 99 | self.disable(); | 89 | self.disable(); |
| 100 | 90 | ||
diff --git a/embassy-nrf/src/pwm.rs b/embassy-nrf/src/pwm.rs index 3ed60ca05..9a78ff1f1 100644 --- a/embassy-nrf/src/pwm.rs +++ b/embassy-nrf/src/pwm.rs | |||
| @@ -1,16 +1,16 @@ | |||
| 1 | #![macro_use] | 1 | #![macro_use] |
| 2 | 2 | ||
| 3 | use crate::Unborrow; | ||
| 4 | use core::marker::PhantomData; | 3 | use core::marker::PhantomData; |
| 5 | use core::sync::atomic::{compiler_fence, Ordering}; | 4 | use core::sync::atomic::{compiler_fence, Ordering}; |
| 5 | |||
| 6 | use embassy_hal_common::unborrow; | 6 | use embassy_hal_common::unborrow; |
| 7 | 7 | ||
| 8 | use crate::gpio::sealed::Pin as _; | 8 | use crate::gpio::sealed::Pin as _; |
| 9 | use crate::gpio::{AnyPin, Pin as GpioPin, PselBits}; | 9 | use crate::gpio::{AnyPin, Pin as GpioPin, PselBits}; |
| 10 | use crate::interrupt::Interrupt; | 10 | use crate::interrupt::Interrupt; |
| 11 | use crate::pac; | ||
| 12 | use crate::ppi::{Event, Task}; | 11 | use crate::ppi::{Event, Task}; |
| 13 | use crate::util::slice_in_ram_or; | 12 | use crate::util::slice_in_ram_or; |
| 13 | use crate::{pac, Unborrow}; | ||
| 14 | 14 | ||
| 15 | /// SimplePwm is the traditional pwm interface you're probably used to, allowing | 15 | /// SimplePwm is the traditional pwm interface you're probably used to, allowing |
| 16 | /// to simply set a duty cycle across up to four channels. | 16 | /// to simply set a duty cycle across up to four channels. |
| @@ -68,14 +68,7 @@ impl<'d, T: Instance> SequencePwm<'d, T> { | |||
| 68 | config: Config, | 68 | config: Config, |
| 69 | ) -> Result<Self, Error> { | 69 | ) -> Result<Self, Error> { |
| 70 | unborrow!(ch0, ch1); | 70 | unborrow!(ch0, ch1); |
| 71 | Self::new_inner( | 71 | Self::new_inner(pwm, Some(ch0.degrade()), Some(ch1.degrade()), None, None, config) |
| 72 | pwm, | ||
| 73 | Some(ch0.degrade()), | ||
| 74 | Some(ch1.degrade()), | ||
| 75 | None, | ||
| 76 | None, | ||
| 77 | config, | ||
| 78 | ) | ||
| 79 | } | 72 | } |
| 80 | 73 | ||
| 81 | /// Create a new 3-channel PWM | 74 | /// Create a new 3-channel PWM |
| @@ -171,10 +164,8 @@ impl<'d, T: Instance> SequencePwm<'d, T> { | |||
| 171 | CounterMode::UpAndDown => w.updown().up_and_down(), | 164 | CounterMode::UpAndDown => w.updown().up_and_down(), |
| 172 | CounterMode::Up => w.updown().up(), | 165 | CounterMode::Up => w.updown().up(), |
| 173 | }); | 166 | }); |
| 174 | r.prescaler | 167 | r.prescaler.write(|w| w.prescaler().bits(config.prescaler as u8)); |
| 175 | .write(|w| w.prescaler().bits(config.prescaler as u8)); | 168 | r.countertop.write(|w| unsafe { w.countertop().bits(config.max_duty) }); |
| 176 | r.countertop | ||
| 177 | .write(|w| unsafe { w.countertop().bits(config.max_duty) }); | ||
| 178 | 169 | ||
| 179 | Ok(Self { | 170 | Ok(Self { |
| 180 | phantom: PhantomData, | 171 | phantom: PhantomData, |
| @@ -391,9 +382,7 @@ impl<'d, 's, T: Instance> SingleSequencer<'d, 's, T> { | |||
| 391 | pub fn start(&self, times: SingleSequenceMode) -> Result<(), Error> { | 382 | pub fn start(&self, times: SingleSequenceMode) -> Result<(), Error> { |
| 392 | let (start_seq, times) = match times { | 383 | let (start_seq, times) = match times { |
| 393 | SingleSequenceMode::Times(n) if n == 1 => (StartSequence::One, SequenceMode::Loop(1)), | 384 | SingleSequenceMode::Times(n) if n == 1 => (StartSequence::One, SequenceMode::Loop(1)), |
| 394 | SingleSequenceMode::Times(n) if n & 1 == 1 => { | 385 | SingleSequenceMode::Times(n) if n & 1 == 1 => (StartSequence::One, SequenceMode::Loop((n / 2) + 1)), |
| 395 | (StartSequence::One, SequenceMode::Loop((n / 2) + 1)) | ||
| 396 | } | ||
| 397 | SingleSequenceMode::Times(n) => (StartSequence::Zero, SequenceMode::Loop(n / 2)), | 386 | SingleSequenceMode::Times(n) => (StartSequence::Zero, SequenceMode::Loop(n / 2)), |
| 398 | SingleSequenceMode::Infinite => (StartSequence::Zero, SequenceMode::Infinite), | 387 | SingleSequenceMode::Infinite => (StartSequence::Zero, SequenceMode::Infinite), |
| 399 | }; | 388 | }; |
| @@ -424,11 +413,7 @@ pub struct Sequencer<'d, 's, T: Instance> { | |||
| 424 | impl<'d, 's, T: Instance> Sequencer<'d, 's, T> { | 413 | impl<'d, 's, T: Instance> Sequencer<'d, 's, T> { |
| 425 | /// Create a new double sequence. In the absence of sequence 1, sequence 0 | 414 | /// Create a new double sequence. In the absence of sequence 1, sequence 0 |
| 426 | /// will be used twice in the one loop. | 415 | /// will be used twice in the one loop. |
| 427 | pub fn new( | 416 | pub fn new(pwm: &'s mut SequencePwm<'d, T>, sequence0: Sequence<'s>, sequence1: Option<Sequence<'s>>) -> Self { |
| 428 | pwm: &'s mut SequencePwm<'d, T>, | ||
| 429 | sequence0: Sequence<'s>, | ||
| 430 | sequence1: Option<Sequence<'s>>, | ||
| 431 | ) -> Self { | ||
| 432 | Sequencer { | 417 | Sequencer { |
| 433 | _pwm: pwm, | 418 | _pwm: pwm, |
| 434 | sequence0, | 419 | sequence0, |
| @@ -457,42 +442,26 @@ impl<'d, 's, T: Instance> Sequencer<'d, 's, T> { | |||
| 457 | 442 | ||
| 458 | let r = T::regs(); | 443 | let r = T::regs(); |
| 459 | 444 | ||
| 460 | r.seq0 | 445 | r.seq0.refresh.write(|w| unsafe { w.bits(sequence0.config.refresh) }); |
| 461 | .refresh | 446 | r.seq0.enddelay.write(|w| unsafe { w.bits(sequence0.config.end_delay) }); |
| 462 | .write(|w| unsafe { w.bits(sequence0.config.refresh) }); | 447 | r.seq0.ptr.write(|w| unsafe { w.bits(sequence0.words.as_ptr() as u32) }); |
| 463 | r.seq0 | 448 | r.seq0.cnt.write(|w| unsafe { w.bits(sequence0.words.len() as u32) }); |
| 464 | .enddelay | ||
| 465 | .write(|w| unsafe { w.bits(sequence0.config.end_delay) }); | ||
| 466 | r.seq0 | ||
| 467 | .ptr | ||
| 468 | .write(|w| unsafe { w.bits(sequence0.words.as_ptr() as u32) }); | ||
| 469 | r.seq0 | ||
| 470 | .cnt | ||
| 471 | .write(|w| unsafe { w.bits(sequence0.words.len() as u32) }); | ||
| 472 | 449 | ||
| 473 | r.seq1 | 450 | r.seq1.refresh.write(|w| unsafe { w.bits(alt_sequence.config.refresh) }); |
| 474 | .refresh | ||
| 475 | .write(|w| unsafe { w.bits(alt_sequence.config.refresh) }); | ||
| 476 | r.seq1 | 451 | r.seq1 |
| 477 | .enddelay | 452 | .enddelay |
| 478 | .write(|w| unsafe { w.bits(alt_sequence.config.end_delay) }); | 453 | .write(|w| unsafe { w.bits(alt_sequence.config.end_delay) }); |
| 479 | r.seq1 | 454 | r.seq1 |
| 480 | .ptr | 455 | .ptr |
| 481 | .write(|w| unsafe { w.bits(alt_sequence.words.as_ptr() as u32) }); | 456 | .write(|w| unsafe { w.bits(alt_sequence.words.as_ptr() as u32) }); |
| 482 | r.seq1 | 457 | r.seq1.cnt.write(|w| unsafe { w.bits(alt_sequence.words.len() as u32) }); |
| 483 | .cnt | ||
| 484 | .write(|w| unsafe { w.bits(alt_sequence.words.len() as u32) }); | ||
| 485 | 458 | ||
| 486 | r.enable.write(|w| w.enable().enabled()); | 459 | r.enable.write(|w| w.enable().enabled()); |
| 487 | 460 | ||
| 488 | // defensive before seqstart | 461 | // defensive before seqstart |
| 489 | compiler_fence(Ordering::SeqCst); | 462 | compiler_fence(Ordering::SeqCst); |
| 490 | 463 | ||
| 491 | let seqstart_index = if start_seq == StartSequence::One { | 464 | let seqstart_index = if start_seq == StartSequence::One { 1 } else { 0 }; |
| 492 | 1 | ||
| 493 | } else { | ||
| 494 | 0 | ||
| 495 | }; | ||
| 496 | 465 | ||
| 497 | match times { | 466 | match times { |
| 498 | // just the one time, no loop count | 467 | // just the one time, no loop count |
| @@ -604,10 +573,7 @@ pub enum CounterMode { | |||
| 604 | impl<'d, T: Instance> SimplePwm<'d, T> { | 573 | impl<'d, T: Instance> SimplePwm<'d, T> { |
| 605 | /// Create a new 1-channel PWM | 574 | /// Create a new 1-channel PWM |
| 606 | #[allow(unused_unsafe)] | 575 | #[allow(unused_unsafe)] |
| 607 | pub fn new_1ch( | 576 | pub fn new_1ch(pwm: impl Unborrow<Target = T> + 'd, ch0: impl Unborrow<Target = impl GpioPin> + 'd) -> Self { |
| 608 | pwm: impl Unborrow<Target = T> + 'd, | ||
| 609 | ch0: impl Unborrow<Target = impl GpioPin> + 'd, | ||
| 610 | ) -> Self { | ||
| 611 | unborrow!(ch0); | 577 | unborrow!(ch0); |
| 612 | Self::new_inner(pwm, Some(ch0.degrade()), None, None, None) | 578 | Self::new_inner(pwm, Some(ch0.degrade()), None, None, None) |
| 613 | } | 579 | } |
| @@ -632,13 +598,7 @@ impl<'d, T: Instance> SimplePwm<'d, T> { | |||
| 632 | ch2: impl Unborrow<Target = impl GpioPin> + 'd, | 598 | ch2: impl Unborrow<Target = impl GpioPin> + 'd, |
| 633 | ) -> Self { | 599 | ) -> Self { |
| 634 | unborrow!(ch0, ch1, ch2); | 600 | unborrow!(ch0, ch1, ch2); |
| 635 | Self::new_inner( | 601 | Self::new_inner(pwm, Some(ch0.degrade()), Some(ch1.degrade()), Some(ch2.degrade()), None) |
| 636 | pwm, | ||
| 637 | Some(ch0.degrade()), | ||
| 638 | Some(ch1.degrade()), | ||
| 639 | Some(ch2.degrade()), | ||
| 640 | None, | ||
| 641 | ) | ||
| 642 | } | 602 | } |
| 643 | 603 | ||
| 644 | /// Create a new 4-channel PWM | 604 | /// Create a new 4-channel PWM |
| @@ -709,9 +669,7 @@ impl<'d, T: Instance> SimplePwm<'d, T> { | |||
| 709 | // Enable | 669 | // Enable |
| 710 | r.enable.write(|w| w.enable().enabled()); | 670 | r.enable.write(|w| w.enable().enabled()); |
| 711 | 671 | ||
| 712 | r.seq0 | 672 | r.seq0.ptr.write(|w| unsafe { w.bits((&pwm.duty).as_ptr() as u32) }); |
| 713 | .ptr | ||
| 714 | .write(|w| unsafe { w.bits((&pwm.duty).as_ptr() as u32) }); | ||
| 715 | 673 | ||
| 716 | r.seq0.cnt.write(|w| unsafe { w.bits(4) }); | 674 | r.seq0.cnt.write(|w| unsafe { w.bits(4) }); |
| 717 | r.seq0.refresh.write(|w| unsafe { w.bits(0) }); | 675 | r.seq0.refresh.write(|w| unsafe { w.bits(0) }); |
| @@ -750,9 +708,7 @@ impl<'d, T: Instance> SimplePwm<'d, T> { | |||
| 750 | self.duty[channel] = duty & 0x7FFF; | 708 | self.duty[channel] = duty & 0x7FFF; |
| 751 | 709 | ||
| 752 | // reload ptr in case self was moved | 710 | // reload ptr in case self was moved |
| 753 | r.seq0 | 711 | r.seq0.ptr.write(|w| unsafe { w.bits((&self.duty).as_ptr() as u32) }); |
| 754 | .ptr | ||
| 755 | .write(|w| unsafe { w.bits((&self.duty).as_ptr() as u32) }); | ||
| 756 | 712 | ||
| 757 | // defensive before seqstart | 713 | // defensive before seqstart |
| 758 | compiler_fence(Ordering::SeqCst); | 714 | compiler_fence(Ordering::SeqCst); |
diff --git a/embassy-nrf/src/qdec.rs b/embassy-nrf/src/qdec.rs index b230043b4..e254328a6 100644 --- a/embassy-nrf/src/qdec.rs +++ b/embassy-nrf/src/qdec.rs | |||
| @@ -1,19 +1,18 @@ | |||
| 1 | //! Quadrature decoder interface | 1 | //! Quadrature decoder interface |
| 2 | 2 | ||
| 3 | use crate::gpio::sealed::Pin as _; | ||
| 4 | use crate::gpio::{AnyPin, Pin as GpioPin}; | ||
| 5 | use crate::interrupt; | ||
| 6 | use crate::pac; | ||
| 7 | use crate::peripherals::QDEC; | ||
| 8 | |||
| 9 | use crate::interrupt::InterruptExt; | ||
| 10 | use crate::Unborrow; | ||
| 11 | use core::marker::PhantomData; | 3 | use core::marker::PhantomData; |
| 12 | use core::task::Poll; | 4 | use core::task::Poll; |
| 5 | |||
| 13 | use embassy::waitqueue::AtomicWaker; | 6 | use embassy::waitqueue::AtomicWaker; |
| 14 | use embassy_hal_common::unborrow; | 7 | use embassy_hal_common::unborrow; |
| 15 | use futures::future::poll_fn; | 8 | use futures::future::poll_fn; |
| 16 | 9 | ||
| 10 | use crate::gpio::sealed::Pin as _; | ||
| 11 | use crate::gpio::{AnyPin, Pin as GpioPin}; | ||
| 12 | use crate::interrupt::InterruptExt; | ||
| 13 | use crate::peripherals::QDEC; | ||
| 14 | use crate::{interrupt, pac, Unborrow}; | ||
| 15 | |||
| 17 | /// Quadrature decoder | 16 | /// Quadrature decoder |
| 18 | pub struct Qdec<'d> { | 17 | pub struct Qdec<'d> { |
| 19 | phantom: PhantomData<&'d QDEC>, | 18 | phantom: PhantomData<&'d QDEC>, |
| @@ -63,14 +62,7 @@ impl<'d> Qdec<'d> { | |||
| 63 | config: Config, | 62 | config: Config, |
| 64 | ) -> Self { | 63 | ) -> Self { |
| 65 | unborrow!(a, b, led); | 64 | unborrow!(a, b, led); |
| 66 | Self::new_inner( | 65 | Self::new_inner(qdec, irq, a.degrade(), b.degrade(), Some(led.degrade()), config) |
| 67 | qdec, | ||
| 68 | irq, | ||
| 69 | a.degrade(), | ||
| 70 | b.degrade(), | ||
| 71 | Some(led.degrade()), | ||
| 72 | config, | ||
| 73 | ) | ||
| 74 | } | 66 | } |
| 75 | 67 | ||
| 76 | fn new_inner( | 68 | fn new_inner( |
| @@ -139,9 +131,7 @@ impl<'d> Qdec<'d> { | |||
| 139 | }); | 131 | }); |
| 140 | irq.enable(); | 132 | irq.enable(); |
| 141 | 133 | ||
| 142 | Self { | 134 | Self { phantom: PhantomData } |
| 143 | phantom: PhantomData, | ||
| 144 | } | ||
| 145 | } | 135 | } |
| 146 | 136 | ||
| 147 | /// Perform an asynchronous read of the decoder. | 137 | /// Perform an asynchronous read of the decoder. |
diff --git a/embassy-nrf/src/qspi.rs b/embassy-nrf/src/qspi.rs index adb0d8386..92fa79b8a 100644 --- a/embassy-nrf/src/qspi.rs +++ b/embassy-nrf/src/qspi.rs | |||
| @@ -1,22 +1,20 @@ | |||
| 1 | #![macro_use] | 1 | #![macro_use] |
| 2 | 2 | ||
| 3 | use crate::interrupt::{Interrupt, InterruptExt}; | ||
| 4 | use crate::Unborrow; | ||
| 5 | use core::marker::PhantomData; | 3 | use core::marker::PhantomData; |
| 6 | use core::ptr; | 4 | use core::ptr; |
| 7 | use core::task::Poll; | 5 | use core::task::Poll; |
| 6 | |||
| 8 | use embassy_hal_common::drop::DropBomb; | 7 | use embassy_hal_common::drop::DropBomb; |
| 9 | use embassy_hal_common::unborrow; | 8 | use embassy_hal_common::unborrow; |
| 10 | use futures::future::poll_fn; | 9 | use futures::future::poll_fn; |
| 11 | 10 | ||
| 12 | use crate::gpio::sealed::Pin as _; | 11 | use crate::gpio::sealed::Pin as _; |
| 13 | use crate::gpio::{self, Pin as GpioPin}; | 12 | use crate::gpio::{self, Pin as GpioPin}; |
| 14 | use crate::pac; | 13 | use crate::interrupt::{Interrupt, InterruptExt}; |
| 15 | 14 | pub use crate::pac::qspi::ifconfig0::{ | |
| 16 | pub use crate::pac::qspi::ifconfig0::ADDRMODE_A as AddressMode; | 15 | ADDRMODE_A as AddressMode, PPSIZE_A as WritePageSize, READOC_A as ReadOpcode, WRITEOC_A as WriteOpcode, |
| 17 | pub use crate::pac::qspi::ifconfig0::PPSIZE_A as WritePageSize; | 16 | }; |
| 18 | pub use crate::pac::qspi::ifconfig0::READOC_A as ReadOpcode; | 17 | use crate::{pac, Unborrow}; |
| 19 | pub use crate::pac::qspi::ifconfig0::WRITEOC_A as WriteOpcode; | ||
| 20 | 18 | ||
| 21 | // TODO | 19 | // TODO |
| 22 | // - config: | 20 | // - config: |
| @@ -168,12 +166,7 @@ impl<'d, T: Instance, const FLASH_SIZE: usize> Qspi<'d, T, FLASH_SIZE> { | |||
| 168 | } | 166 | } |
| 169 | } | 167 | } |
| 170 | 168 | ||
| 171 | pub async fn custom_instruction( | 169 | pub async fn custom_instruction(&mut self, opcode: u8, req: &[u8], resp: &mut [u8]) -> Result<(), Error> { |
| 172 | &mut self, | ||
| 173 | opcode: u8, | ||
| 174 | req: &[u8], | ||
| 175 | resp: &mut [u8], | ||
| 176 | ) -> Result<(), Error> { | ||
| 177 | let bomb = DropBomb::new(); | 170 | let bomb = DropBomb::new(); |
| 178 | 171 | ||
| 179 | let len = core::cmp::max(req.len(), resp.len()) as u8; | 172 | let len = core::cmp::max(req.len(), resp.len()) as u8; |
| @@ -188,12 +181,7 @@ impl<'d, T: Instance, const FLASH_SIZE: usize> Qspi<'d, T, FLASH_SIZE> { | |||
| 188 | Ok(()) | 181 | Ok(()) |
| 189 | } | 182 | } |
| 190 | 183 | ||
| 191 | pub fn blocking_custom_instruction( | 184 | pub fn blocking_custom_instruction(&mut self, opcode: u8, req: &[u8], resp: &mut [u8]) -> Result<(), Error> { |
| 192 | &mut self, | ||
| 193 | opcode: u8, | ||
| 194 | req: &[u8], | ||
| 195 | resp: &mut [u8], | ||
| 196 | ) -> Result<(), Error> { | ||
| 197 | let len = core::cmp::max(req.len(), resp.len()) as u8; | 185 | let len = core::cmp::max(req.len(), resp.len()) as u8; |
| 198 | self.custom_instruction_start(opcode, req, len)?; | 186 | self.custom_instruction_start(opcode, req, len)?; |
| 199 | 187 | ||
| @@ -292,15 +280,9 @@ impl<'d, T: Instance, const FLASH_SIZE: usize> Qspi<'d, T, FLASH_SIZE> { | |||
| 292 | 280 | ||
| 293 | let r = T::regs(); | 281 | let r = T::regs(); |
| 294 | 282 | ||
| 295 | r.read | 283 | r.read.src.write(|w| unsafe { w.src().bits(address as u32) }); |
| 296 | .src | 284 | r.read.dst.write(|w| unsafe { w.dst().bits(data.as_ptr() as u32) }); |
| 297 | .write(|w| unsafe { w.src().bits(address as u32) }); | 285 | r.read.cnt.write(|w| unsafe { w.cnt().bits(data.len() as u32) }); |
| 298 | r.read | ||
| 299 | .dst | ||
| 300 | .write(|w| unsafe { w.dst().bits(data.as_ptr() as u32) }); | ||
| 301 | r.read | ||
| 302 | .cnt | ||
| 303 | .write(|w| unsafe { w.cnt().bits(data.len() as u32) }); | ||
| 304 | 286 | ||
| 305 | r.events_ready.reset(); | 287 | r.events_ready.reset(); |
| 306 | r.intenset.write(|w| w.ready().set()); | 288 | r.intenset.write(|w| w.ready().set()); |
| @@ -322,15 +304,9 @@ impl<'d, T: Instance, const FLASH_SIZE: usize> Qspi<'d, T, FLASH_SIZE> { | |||
| 322 | } | 304 | } |
| 323 | 305 | ||
| 324 | let r = T::regs(); | 306 | let r = T::regs(); |
| 325 | r.write | 307 | r.write.src.write(|w| unsafe { w.src().bits(data.as_ptr() as u32) }); |
| 326 | .src | 308 | r.write.dst.write(|w| unsafe { w.dst().bits(address as u32) }); |
| 327 | .write(|w| unsafe { w.src().bits(data.as_ptr() as u32) }); | 309 | r.write.cnt.write(|w| unsafe { w.cnt().bits(data.len() as u32) }); |
| 328 | r.write | ||
| 329 | .dst | ||
| 330 | .write(|w| unsafe { w.dst().bits(address as u32) }); | ||
| 331 | r.write | ||
| 332 | .cnt | ||
| 333 | .write(|w| unsafe { w.cnt().bits(data.len() as u32) }); | ||
| 334 | 310 | ||
| 335 | r.events_ready.reset(); | 311 | r.events_ready.reset(); |
| 336 | r.intenset.write(|w| w.ready().set()); | 312 | r.intenset.write(|w| w.ready().set()); |
| @@ -346,9 +322,7 @@ impl<'d, T: Instance, const FLASH_SIZE: usize> Qspi<'d, T, FLASH_SIZE> { | |||
| 346 | } | 322 | } |
| 347 | 323 | ||
| 348 | let r = T::regs(); | 324 | let r = T::regs(); |
| 349 | r.erase | 325 | r.erase.ptr.write(|w| unsafe { w.ptr().bits(address as u32) }); |
| 350 | .ptr | ||
| 351 | .write(|w| unsafe { w.ptr().bits(address as u32) }); | ||
| 352 | r.erase.len.write(|w| w.len()._4kb()); | 326 | r.erase.len.write(|w| w.len()._4kb()); |
| 353 | 327 | ||
| 354 | r.events_ready.reset(); | 328 | r.events_ready.reset(); |
| @@ -458,9 +432,7 @@ impl<'d, T: Instance, const FLASH_SIZE: usize> Drop for Qspi<'d, T, FLASH_SIZE> | |||
| 458 | } | 432 | } |
| 459 | } | 433 | } |
| 460 | 434 | ||
| 461 | use embedded_storage::nor_flash::{ | 435 | use embedded_storage::nor_flash::{ErrorType, NorFlash, NorFlashError, NorFlashErrorKind, ReadNorFlash}; |
| 462 | ErrorType, NorFlash, NorFlashError, NorFlashErrorKind, ReadNorFlash, | ||
| 463 | }; | ||
| 464 | 436 | ||
| 465 | impl<'d, T: Instance, const FLASH_SIZE: usize> ErrorType for Qspi<'d, T, FLASH_SIZE> { | 437 | impl<'d, T: Instance, const FLASH_SIZE: usize> ErrorType for Qspi<'d, T, FLASH_SIZE> { |
| 466 | type Error = Error; | 438 | type Error = Error; |
diff --git a/embassy-nrf/src/rng.rs b/embassy-nrf/src/rng.rs index 43cf805fd..e68ed912e 100644 --- a/embassy-nrf/src/rng.rs +++ b/embassy-nrf/src/rng.rs | |||
| @@ -1,19 +1,16 @@ | |||
| 1 | use core::marker::PhantomData; | 1 | use core::marker::PhantomData; |
| 2 | use core::ptr; | 2 | use core::ptr; |
| 3 | use core::sync::atomic::AtomicPtr; | 3 | use core::sync::atomic::{AtomicPtr, Ordering}; |
| 4 | use core::sync::atomic::Ordering; | ||
| 5 | use core::task::Poll; | 4 | use core::task::Poll; |
| 6 | 5 | ||
| 7 | use crate::interrupt::InterruptExt; | ||
| 8 | use crate::Unborrow; | ||
| 9 | use embassy::waitqueue::AtomicWaker; | 6 | use embassy::waitqueue::AtomicWaker; |
| 10 | use embassy_hal_common::drop::OnDrop; | 7 | use embassy_hal_common::drop::OnDrop; |
| 11 | use embassy_hal_common::unborrow; | 8 | use embassy_hal_common::unborrow; |
| 12 | use futures::future::poll_fn; | 9 | use futures::future::poll_fn; |
| 13 | 10 | ||
| 14 | use crate::interrupt; | 11 | use crate::interrupt::InterruptExt; |
| 15 | use crate::pac; | ||
| 16 | use crate::peripherals::RNG; | 12 | use crate::peripherals::RNG; |
| 13 | use crate::{interrupt, pac, Unborrow}; | ||
| 17 | 14 | ||
| 18 | impl RNG { | 15 | impl RNG { |
| 19 | fn regs() -> &'static pac::rng::RegisterBlock { | 16 | fn regs() -> &'static pac::rng::RegisterBlock { |
| @@ -48,10 +45,7 @@ impl<'d> Rng<'d> { | |||
| 48 | /// e.g. using `mem::forget`. | 45 | /// e.g. using `mem::forget`. |
| 49 | /// | 46 | /// |
| 50 | /// The synchronous API is safe. | 47 | /// The synchronous API is safe. |
| 51 | pub fn new( | 48 | pub fn new(_rng: impl Unborrow<Target = RNG> + 'd, irq: impl Unborrow<Target = interrupt::RNG> + 'd) -> Self { |
| 52 | _rng: impl Unborrow<Target = RNG> + 'd, | ||
| 53 | irq: impl Unborrow<Target = interrupt::RNG> + 'd, | ||
| 54 | ) -> Self { | ||
| 55 | unborrow!(irq); | 49 | unborrow!(irq); |
| 56 | 50 | ||
| 57 | let this = Self { | 51 | let this = Self { |
diff --git a/embassy-nrf/src/saadc.rs b/embassy-nrf/src/saadc.rs index 915115a12..7d39e33f8 100644 --- a/embassy-nrf/src/saadc.rs +++ b/embassy-nrf/src/saadc.rs | |||
| @@ -1,29 +1,23 @@ | |||
| 1 | #![macro_use] | 1 | #![macro_use] |
| 2 | 2 | ||
| 3 | use crate::interrupt::InterruptExt; | ||
| 4 | use crate::Unborrow; | ||
| 5 | use core::marker::PhantomData; | 3 | use core::marker::PhantomData; |
| 6 | use core::sync::atomic::{compiler_fence, Ordering}; | 4 | use core::sync::atomic::{compiler_fence, Ordering}; |
| 7 | use core::task::Poll; | 5 | use core::task::Poll; |
| 6 | |||
| 8 | use embassy::waitqueue::AtomicWaker; | 7 | use embassy::waitqueue::AtomicWaker; |
| 9 | use embassy_hal_common::unborrow; | 8 | use embassy_hal_common::unborrow; |
| 10 | use futures::future::poll_fn; | 9 | use futures::future::poll_fn; |
| 11 | |||
| 12 | use crate::interrupt; | ||
| 13 | use crate::ppi::{ConfigurableChannel, Event, Ppi, Task}; | ||
| 14 | use crate::timer::{Frequency, Instance as TimerInstance, Timer}; | ||
| 15 | use crate::{pac, peripherals}; | ||
| 16 | |||
| 17 | use pac::{saadc, SAADC}; | 10 | use pac::{saadc, SAADC}; |
| 18 | 11 | use saadc::ch::config::{GAIN_A, REFSEL_A, RESP_A, TACQ_A}; | |
| 19 | // We treat the positive and negative channels with the same enum values to keep our type tidy and given they are the same | 12 | // We treat the positive and negative channels with the same enum values to keep our type tidy and given they are the same |
| 20 | pub(crate) use saadc::ch::pselp::PSELP_A as InputChannel; | 13 | pub(crate) use saadc::ch::pselp::PSELP_A as InputChannel; |
| 14 | use saadc::oversample::OVERSAMPLE_A; | ||
| 15 | use saadc::resolution::VAL_A; | ||
| 21 | 16 | ||
| 22 | use saadc::{ | 17 | use crate::interrupt::InterruptExt; |
| 23 | ch::config::{GAIN_A, REFSEL_A, RESP_A, TACQ_A}, | 18 | use crate::ppi::{ConfigurableChannel, Event, Ppi, Task}; |
| 24 | oversample::OVERSAMPLE_A, | 19 | use crate::timer::{Frequency, Instance as TimerInstance, Timer}; |
| 25 | resolution::VAL_A, | 20 | use crate::{interrupt, pac, peripherals, Unborrow}; |
| 26 | }; | ||
| 27 | 21 | ||
| 28 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] | 22 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| 29 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | 23 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] |
| @@ -178,23 +172,17 @@ impl<'d, const N: usize> Saadc<'d, N> { | |||
| 178 | 172 | ||
| 179 | let r = unsafe { &*SAADC::ptr() }; | 173 | let r = unsafe { &*SAADC::ptr() }; |
| 180 | 174 | ||
| 181 | let Config { | 175 | let Config { resolution, oversample } = config; |
| 182 | resolution, | ||
| 183 | oversample, | ||
| 184 | } = config; | ||
| 185 | 176 | ||
| 186 | // Configure channels | 177 | // Configure channels |
| 187 | r.enable.write(|w| w.enable().enabled()); | 178 | r.enable.write(|w| w.enable().enabled()); |
| 188 | r.resolution.write(|w| w.val().variant(resolution.into())); | 179 | r.resolution.write(|w| w.val().variant(resolution.into())); |
| 189 | r.oversample | 180 | r.oversample.write(|w| w.oversample().variant(oversample.into())); |
| 190 | .write(|w| w.oversample().variant(oversample.into())); | ||
| 191 | 181 | ||
| 192 | for (i, cc) in channel_configs.iter().enumerate() { | 182 | for (i, cc) in channel_configs.iter().enumerate() { |
| 193 | r.ch[i].pselp.write(|w| w.pselp().variant(cc.p_channel)); | 183 | r.ch[i].pselp.write(|w| w.pselp().variant(cc.p_channel)); |
| 194 | if let Some(n_channel) = cc.n_channel { | 184 | if let Some(n_channel) = cc.n_channel { |
| 195 | r.ch[i] | 185 | r.ch[i].pseln.write(|w| unsafe { w.pseln().bits(n_channel as u8) }); |
| 196 | .pseln | ||
| 197 | .write(|w| unsafe { w.pseln().bits(n_channel as u8) }); | ||
| 198 | } | 186 | } |
| 199 | r.ch[i].config.write(|w| { | 187 | r.ch[i].config.write(|w| { |
| 200 | w.refsel().variant(cc.reference.into()); | 188 | w.refsel().variant(cc.reference.into()); |
| @@ -223,9 +211,7 @@ impl<'d, const N: usize> Saadc<'d, N> { | |||
| 223 | irq.unpend(); | 211 | irq.unpend(); |
| 224 | irq.enable(); | 212 | irq.enable(); |
| 225 | 213 | ||
| 226 | Self { | 214 | Self { phantom: PhantomData } |
| 227 | phantom: PhantomData, | ||
| 228 | } | ||
| 229 | } | 215 | } |
| 230 | 216 | ||
| 231 | fn on_interrupt(_ctx: *mut ()) { | 217 | fn on_interrupt(_ctx: *mut ()) { |
| @@ -285,12 +271,8 @@ impl<'d, const N: usize> Saadc<'d, N> { | |||
| 285 | let r = Self::regs(); | 271 | let r = Self::regs(); |
| 286 | 272 | ||
| 287 | // Set up the DMA | 273 | // Set up the DMA |
| 288 | r.result | 274 | r.result.ptr.write(|w| unsafe { w.ptr().bits(buf.as_mut_ptr() as u32) }); |
| 289 | .ptr | 275 | r.result.maxcnt.write(|w| unsafe { w.maxcnt().bits(N as _) }); |
| 290 | .write(|w| unsafe { w.ptr().bits(buf.as_mut_ptr() as u32) }); | ||
| 291 | r.result | ||
| 292 | .maxcnt | ||
| 293 | .write(|w| unsafe { w.maxcnt().bits(N as _) }); | ||
| 294 | 276 | ||
| 295 | // Reset and enable the end event | 277 | // Reset and enable the end event |
| 296 | r.events_end.reset(); | 278 | r.events_end.reset(); |
| @@ -353,11 +335,8 @@ impl<'d, const N: usize> Saadc<'d, N> { | |||
| 353 | // We want the task start to effectively short with the last one ending so | 335 | // We want the task start to effectively short with the last one ending so |
| 354 | // we don't miss any samples. It'd be great for the SAADC to offer a SHORTS | 336 | // we don't miss any samples. It'd be great for the SAADC to offer a SHORTS |
| 355 | // register instead, but it doesn't, so we must use PPI. | 337 | // register instead, but it doesn't, so we must use PPI. |
| 356 | let mut start_ppi = Ppi::new_one_to_one( | 338 | let mut start_ppi = |
| 357 | ppi_ch1, | 339 | Ppi::new_one_to_one(ppi_ch1, Event::from_reg(&r.events_end), Task::from_reg(&r.tasks_start)); |
| 358 | Event::from_reg(&r.events_end), | ||
| 359 | Task::from_reg(&r.tasks_start), | ||
| 360 | ); | ||
| 361 | start_ppi.enable(); | 340 | start_ppi.enable(); |
| 362 | 341 | ||
| 363 | let mut timer = Timer::new(timer); | 342 | let mut timer = Timer::new(timer); |
| @@ -365,11 +344,7 @@ impl<'d, const N: usize> Saadc<'d, N> { | |||
| 365 | timer.cc(0).write(sample_counter); | 344 | timer.cc(0).write(sample_counter); |
| 366 | timer.cc(0).short_compare_clear(); | 345 | timer.cc(0).short_compare_clear(); |
| 367 | 346 | ||
| 368 | let mut sample_ppi = Ppi::new_one_to_one( | 347 | let mut sample_ppi = Ppi::new_one_to_one(ppi_ch2, timer.cc(0).event_compare(), Task::from_reg(&r.tasks_sample)); |
| 369 | ppi_ch2, | ||
| 370 | timer.cc(0).event_compare(), | ||
| 371 | Task::from_reg(&r.tasks_sample), | ||
| 372 | ); | ||
| 373 | 348 | ||
| 374 | timer.start(); | 349 | timer.start(); |
| 375 | 350 | ||
| @@ -417,9 +392,7 @@ impl<'d, const N: usize> Saadc<'d, N> { | |||
| 417 | r.result | 392 | r.result |
| 418 | .ptr | 393 | .ptr |
| 419 | .write(|w| unsafe { w.ptr().bits(bufs[0].as_mut_ptr() as u32) }); | 394 | .write(|w| unsafe { w.ptr().bits(bufs[0].as_mut_ptr() as u32) }); |
| 420 | r.result | 395 | r.result.maxcnt.write(|w| unsafe { w.maxcnt().bits((N0 * N) as _) }); |
| 421 | .maxcnt | ||
| 422 | .write(|w| unsafe { w.maxcnt().bits((N0 * N) as _) }); | ||
| 423 | 396 | ||
| 424 | // Reset and enable the events | 397 | // Reset and enable the events |
| 425 | r.events_end.reset(); | 398 | r.events_end.reset(); |
| @@ -500,8 +473,7 @@ impl<'d> Saadc<'d, 1> { | |||
| 500 | ) where | 473 | ) where |
| 501 | S: FnMut(&[[i16; 1]]) -> SamplerState, | 474 | S: FnMut(&[[i16; 1]]) -> SamplerState, |
| 502 | { | 475 | { |
| 503 | self.run_sampler(bufs, Some(sample_rate_divisor), || {}, sampler) | 476 | self.run_sampler(bufs, Some(sample_rate_divisor), || {}, sampler).await; |
| 504 | .await; | ||
| 505 | } | 477 | } |
| 506 | } | 478 | } |
| 507 | 479 | ||
diff --git a/embassy-nrf/src/spim.rs b/embassy-nrf/src/spim.rs index 7b28373df..efccfeca3 100644 --- a/embassy-nrf/src/spim.rs +++ b/embassy-nrf/src/spim.rs | |||
| @@ -1,23 +1,20 @@ | |||
| 1 | #![macro_use] | 1 | #![macro_use] |
| 2 | 2 | ||
| 3 | use crate::interrupt::InterruptExt; | ||
| 4 | use crate::Unborrow; | ||
| 5 | use core::marker::PhantomData; | 3 | use core::marker::PhantomData; |
| 6 | use core::sync::atomic::{compiler_fence, Ordering}; | 4 | use core::sync::atomic::{compiler_fence, Ordering}; |
| 7 | use core::task::Poll; | 5 | use core::task::Poll; |
| 6 | |||
| 8 | use embassy_hal_common::unborrow; | 7 | use embassy_hal_common::unborrow; |
| 8 | pub use embedded_hal_02::spi::{Mode, Phase, Polarity, MODE_0, MODE_1, MODE_2, MODE_3}; | ||
| 9 | use futures::future::poll_fn; | 9 | use futures::future::poll_fn; |
| 10 | pub use pac::spim0::frequency::FREQUENCY_A as Frequency; | ||
| 10 | 11 | ||
| 11 | use crate::chip::FORCE_COPY_BUFFER_SIZE; | 12 | use crate::chip::FORCE_COPY_BUFFER_SIZE; |
| 12 | use crate::gpio::sealed::Pin as _; | 13 | use crate::gpio::sealed::Pin as _; |
| 13 | use crate::gpio::{self, AnyPin}; | 14 | use crate::gpio::{self, AnyPin, Pin as GpioPin, PselBits}; |
| 14 | use crate::gpio::{Pin as GpioPin, PselBits}; | 15 | use crate::interrupt::{Interrupt, InterruptExt}; |
| 15 | use crate::interrupt::Interrupt; | 16 | use crate::util::{slice_in_ram_or, slice_ptr_parts, slice_ptr_parts_mut}; |
| 16 | use crate::util::{slice_ptr_parts, slice_ptr_parts_mut}; | 17 | use crate::{pac, Unborrow}; |
| 17 | use crate::{pac, util::slice_in_ram_or}; | ||
| 18 | |||
| 19 | pub use embedded_hal_02::spi::{Mode, Phase, Polarity, MODE_0, MODE_1, MODE_2, MODE_3}; | ||
| 20 | pub use pac::spim0::frequency::FREQUENCY_A as Frequency; | ||
| 21 | 18 | ||
| 22 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] | 19 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| 23 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | 20 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] |
| @@ -183,9 +180,7 @@ impl<'d, T: Instance> Spim<'d, T> { | |||
| 183 | irq.unpend(); | 180 | irq.unpend(); |
| 184 | irq.enable(); | 181 | irq.enable(); |
| 185 | 182 | ||
| 186 | Self { | 183 | Self { phantom: PhantomData } |
| 187 | phantom: PhantomData, | ||
| 188 | } | ||
| 189 | } | 184 | } |
| 190 | 185 | ||
| 191 | fn on_interrupt(_: *mut ()) { | 186 | fn on_interrupt(_: *mut ()) { |
| @@ -295,11 +290,7 @@ impl<'d, T: Instance> Spim<'d, T> { | |||
| 295 | } | 290 | } |
| 296 | 291 | ||
| 297 | /// Same as [`blocking_transfer`](Spim::blocking_transfer) but will fail instead of copying data into RAM. Consult the module level documentation to learn more. | 292 | /// Same as [`blocking_transfer`](Spim::blocking_transfer) but will fail instead of copying data into RAM. Consult the module level documentation to learn more. |
| 298 | pub fn blocking_transfer_from_ram( | 293 | pub fn blocking_transfer_from_ram(&mut self, read: &mut [u8], write: &[u8]) -> Result<(), Error> { |
| 299 | &mut self, | ||
| 300 | read: &mut [u8], | ||
| 301 | write: &[u8], | ||
| 302 | ) -> Result<(), Error> { | ||
| 303 | self.blocking_inner(read, write) | 294 | self.blocking_inner(read, write) |
| 304 | } | 295 | } |
| 305 | 296 | ||
diff --git a/embassy-nrf/src/temp.rs b/embassy-nrf/src/temp.rs index e5e5f29ab..43ba3e042 100644 --- a/embassy-nrf/src/temp.rs +++ b/embassy-nrf/src/temp.rs | |||
| @@ -1,18 +1,18 @@ | |||
| 1 | //! Temperature sensor interface. | 1 | //! Temperature sensor interface. |
| 2 | 2 | ||
| 3 | use crate::interrupt; | ||
| 4 | use crate::pac; | ||
| 5 | use crate::peripherals::TEMP; | ||
| 6 | |||
| 7 | use crate::interrupt::InterruptExt; | ||
| 8 | use crate::Unborrow; | ||
| 9 | use core::marker::PhantomData; | 3 | use core::marker::PhantomData; |
| 10 | use core::task::Poll; | 4 | use core::task::Poll; |
| 5 | |||
| 11 | use embassy::waitqueue::AtomicWaker; | 6 | use embassy::waitqueue::AtomicWaker; |
| 12 | use embassy_hal_common::{drop::OnDrop, unborrow}; | 7 | use embassy_hal_common::drop::OnDrop; |
| 8 | use embassy_hal_common::unborrow; | ||
| 13 | use fixed::types::I30F2; | 9 | use fixed::types::I30F2; |
| 14 | use futures::future::poll_fn; | 10 | use futures::future::poll_fn; |
| 15 | 11 | ||
| 12 | use crate::interrupt::InterruptExt; | ||
| 13 | use crate::peripherals::TEMP; | ||
| 14 | use crate::{interrupt, pac, Unborrow}; | ||
| 15 | |||
| 16 | /// Integrated temperature sensor. | 16 | /// Integrated temperature sensor. |
| 17 | pub struct Temp<'d> { | 17 | pub struct Temp<'d> { |
| 18 | _temp: PhantomData<&'d TEMP>, | 18 | _temp: PhantomData<&'d TEMP>, |
| @@ -22,10 +22,7 @@ pub struct Temp<'d> { | |||
| 22 | static WAKER: AtomicWaker = AtomicWaker::new(); | 22 | static WAKER: AtomicWaker = AtomicWaker::new(); |
| 23 | 23 | ||
| 24 | impl<'d> Temp<'d> { | 24 | impl<'d> Temp<'d> { |
| 25 | pub fn new( | 25 | pub fn new(_t: impl Unborrow<Target = TEMP> + 'd, irq: impl Unborrow<Target = interrupt::TEMP> + 'd) -> Self { |
| 26 | _t: impl Unborrow<Target = TEMP> + 'd, | ||
| 27 | irq: impl Unborrow<Target = interrupt::TEMP> + 'd, | ||
| 28 | ) -> Self { | ||
| 29 | unborrow!(_t, irq); | 26 | unborrow!(_t, irq); |
| 30 | 27 | ||
| 31 | // Enable interrupt that signals temperature values | 28 | // Enable interrupt that signals temperature values |
diff --git a/embassy-nrf/src/time_driver.rs b/embassy-nrf/src/time_driver.rs index 8f1758146..f7b3345b2 100644 --- a/embassy-nrf/src/time_driver.rs +++ b/embassy-nrf/src/time_driver.rs | |||
| @@ -1,14 +1,14 @@ | |||
| 1 | use crate::interrupt::{Interrupt, InterruptExt}; | ||
| 2 | use core::cell::Cell; | 1 | use core::cell::Cell; |
| 3 | use core::sync::atomic::{compiler_fence, AtomicU32, AtomicU8, Ordering}; | 2 | use core::sync::atomic::{compiler_fence, AtomicU32, AtomicU8, Ordering}; |
| 4 | use core::{mem, ptr}; | 3 | use core::{mem, ptr}; |
| 4 | |||
| 5 | use critical_section::CriticalSection; | 5 | use critical_section::CriticalSection; |
| 6 | use embassy::blocking_mutex::raw::CriticalSectionRawMutex; | 6 | use embassy::blocking_mutex::raw::CriticalSectionRawMutex; |
| 7 | use embassy::blocking_mutex::CriticalSectionMutex as Mutex; | 7 | use embassy::blocking_mutex::CriticalSectionMutex as Mutex; |
| 8 | use embassy::time::driver::{AlarmHandle, Driver}; | 8 | use embassy::time::driver::{AlarmHandle, Driver}; |
| 9 | 9 | ||
| 10 | use crate::interrupt; | 10 | use crate::interrupt::{Interrupt, InterruptExt}; |
| 11 | use crate::pac; | 11 | use crate::{interrupt, pac}; |
| 12 | 12 | ||
| 13 | fn rtc() -> &'static pac::rtc0::RegisterBlock { | 13 | fn rtc() -> &'static pac::rtc0::RegisterBlock { |
| 14 | unsafe { &*pac::RTC1::ptr() } | 14 | unsafe { &*pac::RTC1::ptr() } |
| @@ -220,15 +220,13 @@ impl Driver for RtcDriver { | |||
| 220 | } | 220 | } |
| 221 | 221 | ||
| 222 | unsafe fn allocate_alarm(&self) -> Option<AlarmHandle> { | 222 | unsafe fn allocate_alarm(&self) -> Option<AlarmHandle> { |
| 223 | let id = self | 223 | let id = self.alarm_count.fetch_update(Ordering::AcqRel, Ordering::Acquire, |x| { |
| 224 | .alarm_count | 224 | if x < ALARM_COUNT as u8 { |
| 225 | .fetch_update(Ordering::AcqRel, Ordering::Acquire, |x| { | 225 | Some(x + 1) |
| 226 | if x < ALARM_COUNT as u8 { | 226 | } else { |
| 227 | Some(x + 1) | 227 | None |
| 228 | } else { | 228 | } |
| 229 | None | 229 | }); |
| 230 | } | ||
| 231 | }); | ||
| 232 | 230 | ||
| 233 | match id { | 231 | match id { |
| 234 | Ok(id) => Some(AlarmHandle::new(id)), | 232 | Ok(id) => Some(AlarmHandle::new(id)), |
diff --git a/embassy-nrf/src/timer.rs b/embassy-nrf/src/timer.rs index 588654f96..c8c36dfae 100644 --- a/embassy-nrf/src/timer.rs +++ b/embassy-nrf/src/timer.rs | |||
| @@ -3,16 +3,14 @@ | |||
| 3 | use core::marker::PhantomData; | 3 | use core::marker::PhantomData; |
| 4 | use core::task::Poll; | 4 | use core::task::Poll; |
| 5 | 5 | ||
| 6 | use crate::interrupt::Interrupt; | ||
| 7 | use crate::interrupt::InterruptExt; | ||
| 8 | use crate::Unborrow; | ||
| 9 | use embassy::waitqueue::AtomicWaker; | 6 | use embassy::waitqueue::AtomicWaker; |
| 10 | use embassy_hal_common::drop::OnDrop; | 7 | use embassy_hal_common::drop::OnDrop; |
| 11 | use embassy_hal_common::unborrow; | 8 | use embassy_hal_common::unborrow; |
| 12 | use futures::future::poll_fn; | 9 | use futures::future::poll_fn; |
| 13 | 10 | ||
| 14 | use crate::pac; | 11 | use crate::interrupt::{Interrupt, InterruptExt}; |
| 15 | use crate::ppi::{Event, Task}; | 12 | use crate::ppi::{Event, Task}; |
| 13 | use crate::{pac, Unborrow}; | ||
| 16 | 14 | ||
| 17 | pub(crate) mod sealed { | 15 | pub(crate) mod sealed { |
| 18 | 16 | ||
| @@ -131,9 +129,7 @@ impl<'d, T: Instance, I: TimerType> Timer<'d, T, I> { | |||
| 131 | fn new_irqless(_timer: impl Unborrow<Target = T> + 'd) -> Self { | 129 | fn new_irqless(_timer: impl Unborrow<Target = T> + 'd) -> Self { |
| 132 | let regs = T::regs(); | 130 | let regs = T::regs(); |
| 133 | 131 | ||
| 134 | let mut this = Self { | 132 | let mut this = Self { phantom: PhantomData }; |
| 135 | phantom: PhantomData, | ||
| 136 | }; | ||
| 137 | 133 | ||
| 138 | // Stop the timer before doing anything else, | 134 | // Stop the timer before doing anything else, |
| 139 | // since changing BITMODE while running can cause 'unpredictable behaviour' according to the specification. | 135 | // since changing BITMODE while running can cause 'unpredictable behaviour' according to the specification. |
| @@ -233,11 +229,7 @@ impl<'d, T: Instance, I: TimerType> Timer<'d, T, I> { | |||
| 233 | /// Panics if `n` >= the number of CC registers this timer has (4 for a normal timer, 6 for an extended timer). | 229 | /// Panics if `n` >= the number of CC registers this timer has (4 for a normal timer, 6 for an extended timer). |
| 234 | pub fn cc(&mut self, n: usize) -> Cc<T, I> { | 230 | pub fn cc(&mut self, n: usize) -> Cc<T, I> { |
| 235 | if n >= T::CCS { | 231 | if n >= T::CCS { |
| 236 | panic!( | 232 | panic!("Cannot get CC register {} of timer with {} CC registers.", n, T::CCS); |
| 237 | "Cannot get CC register {} of timer with {} CC registers.", | ||
| 238 | n, | ||
| 239 | T::CCS | ||
| 240 | ); | ||
| 241 | } | 233 | } |
| 242 | Cc { | 234 | Cc { |
| 243 | n, | 235 | n, |
diff --git a/embassy-nrf/src/twim.rs b/embassy-nrf/src/twim.rs index 2337ae219..c3921104e 100644 --- a/embassy-nrf/src/twim.rs +++ b/embassy-nrf/src/twim.rs | |||
| @@ -6,12 +6,12 @@ | |||
| 6 | //! | 6 | //! |
| 7 | //! - nRF52832: Section 33 | 7 | //! - nRF52832: Section 33 |
| 8 | //! - nRF52840: Section 6.31 | 8 | //! - nRF52840: Section 6.31 |
| 9 | use crate::interrupt::{Interrupt, InterruptExt}; | ||
| 10 | use crate::Unborrow; | ||
| 11 | use core::future::Future; | 9 | use core::future::Future; |
| 12 | use core::marker::PhantomData; | 10 | use core::marker::PhantomData; |
| 13 | use core::sync::atomic::{compiler_fence, Ordering::SeqCst}; | 11 | use core::sync::atomic::compiler_fence; |
| 12 | use core::sync::atomic::Ordering::SeqCst; | ||
| 14 | use core::task::Poll; | 13 | use core::task::Poll; |
| 14 | |||
| 15 | #[cfg(feature = "time")] | 15 | #[cfg(feature = "time")] |
| 16 | use embassy::time::{Duration, Instant}; | 16 | use embassy::time::{Duration, Instant}; |
| 17 | use embassy::waitqueue::AtomicWaker; | 17 | use embassy::waitqueue::AtomicWaker; |
| @@ -19,10 +19,10 @@ use embassy_hal_common::unborrow; | |||
| 19 | use futures::future::poll_fn; | 19 | use futures::future::poll_fn; |
| 20 | 20 | ||
| 21 | use crate::chip::{EASY_DMA_SIZE, FORCE_COPY_BUFFER_SIZE}; | 21 | use crate::chip::{EASY_DMA_SIZE, FORCE_COPY_BUFFER_SIZE}; |
| 22 | use crate::gpio; | ||
| 23 | use crate::gpio::Pin as GpioPin; | 22 | use crate::gpio::Pin as GpioPin; |
| 24 | use crate::pac; | 23 | use crate::interrupt::{Interrupt, InterruptExt}; |
| 25 | use crate::util::{slice_in_ram, slice_in_ram_or}; | 24 | use crate::util::{slice_in_ram, slice_in_ram_or}; |
| 25 | use crate::{gpio, pac, Unborrow}; | ||
| 26 | 26 | ||
| 27 | pub enum Frequency { | 27 | pub enum Frequency { |
| 28 | #[doc = "26738688: 100 kbps"] | 28 | #[doc = "26738688: 100 kbps"] |
| @@ -134,9 +134,7 @@ impl<'d, T: Instance> Twim<'d, T> { | |||
| 134 | irq.unpend(); | 134 | irq.unpend(); |
| 135 | irq.enable(); | 135 | irq.enable(); |
| 136 | 136 | ||
| 137 | Self { | 137 | Self { phantom: PhantomData } |
| 138 | phantom: PhantomData, | ||
| 139 | } | ||
| 140 | } | 138 | } |
| 141 | 139 | ||
| 142 | fn on_interrupt(_: *mut ()) { | 140 | fn on_interrupt(_: *mut ()) { |
| @@ -319,12 +317,7 @@ impl<'d, T: Instance> Twim<'d, T> { | |||
| 319 | }) | 317 | }) |
| 320 | } | 318 | } |
| 321 | 319 | ||
| 322 | fn setup_write_from_ram( | 320 | fn setup_write_from_ram(&mut self, address: u8, buffer: &[u8], inten: bool) -> Result<(), Error> { |
| 323 | &mut self, | ||
| 324 | address: u8, | ||
| 325 | buffer: &[u8], | ||
| 326 | inten: bool, | ||
| 327 | ) -> Result<(), Error> { | ||
| 328 | let r = T::regs(); | 321 | let r = T::regs(); |
| 329 | 322 | ||
| 330 | compiler_fence(SeqCst); | 323 | compiler_fence(SeqCst); |
| @@ -506,12 +499,7 @@ impl<'d, T: Instance> Twim<'d, T> { | |||
| 506 | /// | 499 | /// |
| 507 | /// The buffers must have a length of at most 255 bytes on the nRF52832 | 500 | /// The buffers must have a length of at most 255 bytes on the nRF52832 |
| 508 | /// and at most 65535 bytes on the nRF52840. | 501 | /// and at most 65535 bytes on the nRF52840. |
| 509 | pub fn blocking_write_read( | 502 | pub fn blocking_write_read(&mut self, address: u8, wr_buffer: &[u8], rd_buffer: &mut [u8]) -> Result<(), Error> { |
| 510 | &mut self, | ||
| 511 | address: u8, | ||
| 512 | wr_buffer: &[u8], | ||
| 513 | rd_buffer: &mut [u8], | ||
| 514 | ) -> Result<(), Error> { | ||
| 515 | self.setup_write_read(address, wr_buffer, rd_buffer, false)?; | 503 | self.setup_write_read(address, wr_buffer, rd_buffer, false)?; |
| 516 | self.blocking_wait(); | 504 | self.blocking_wait(); |
| 517 | compiler_fence(SeqCst); | 505 | compiler_fence(SeqCst); |
| @@ -543,12 +531,7 @@ impl<'d, T: Instance> Twim<'d, T> { | |||
| 543 | /// | 531 | /// |
| 544 | /// See [`blocking_write`]. | 532 | /// See [`blocking_write`]. |
| 545 | #[cfg(feature = "time")] | 533 | #[cfg(feature = "time")] |
| 546 | pub fn blocking_write_timeout( | 534 | pub fn blocking_write_timeout(&mut self, address: u8, buffer: &[u8], timeout: Duration) -> Result<(), Error> { |
| 547 | &mut self, | ||
| 548 | address: u8, | ||
| 549 | buffer: &[u8], | ||
| 550 | timeout: Duration, | ||
| 551 | ) -> Result<(), Error> { | ||
| 552 | self.setup_write(address, buffer, false)?; | 535 | self.setup_write(address, buffer, false)?; |
| 553 | self.blocking_wait_timeout(timeout)?; | 536 | self.blocking_wait_timeout(timeout)?; |
| 554 | compiler_fence(SeqCst); | 537 | compiler_fence(SeqCst); |
| @@ -578,12 +561,7 @@ impl<'d, T: Instance> Twim<'d, T> { | |||
| 578 | /// The buffer must have a length of at most 255 bytes on the nRF52832 | 561 | /// The buffer must have a length of at most 255 bytes on the nRF52832 |
| 579 | /// and at most 65535 bytes on the nRF52840. | 562 | /// and at most 65535 bytes on the nRF52840. |
| 580 | #[cfg(feature = "time")] | 563 | #[cfg(feature = "time")] |
| 581 | pub fn blocking_read_timeout( | 564 | pub fn blocking_read_timeout(&mut self, address: u8, buffer: &mut [u8], timeout: Duration) -> Result<(), Error> { |
| 582 | &mut self, | ||
| 583 | address: u8, | ||
| 584 | buffer: &mut [u8], | ||
| 585 | timeout: Duration, | ||
| 586 | ) -> Result<(), Error> { | ||
| 587 | self.setup_read(address, buffer, false)?; | 565 | self.setup_read(address, buffer, false)?; |
| 588 | self.blocking_wait_timeout(timeout)?; | 566 | self.blocking_wait_timeout(timeout)?; |
| 589 | compiler_fence(SeqCst); | 567 | compiler_fence(SeqCst); |
| @@ -662,12 +640,7 @@ impl<'d, T: Instance> Twim<'d, T> { | |||
| 662 | Ok(()) | 640 | Ok(()) |
| 663 | } | 641 | } |
| 664 | 642 | ||
| 665 | pub async fn write_read( | 643 | pub async fn write_read(&mut self, address: u8, wr_buffer: &[u8], rd_buffer: &mut [u8]) -> Result<(), Error> { |
| 666 | &mut self, | ||
| 667 | address: u8, | ||
| 668 | wr_buffer: &[u8], | ||
| 669 | rd_buffer: &mut [u8], | ||
| 670 | ) -> Result<(), Error> { | ||
| 671 | self.setup_write_read(address, wr_buffer, rd_buffer, true)?; | 644 | self.setup_write_read(address, wr_buffer, rd_buffer, true)?; |
| 672 | self.async_wait().await; | 645 | self.async_wait().await; |
| 673 | compiler_fence(SeqCst); | 646 | compiler_fence(SeqCst); |
| @@ -786,12 +759,7 @@ mod eh02 { | |||
| 786 | impl<'a, T: Instance> embedded_hal_02::blocking::i2c::WriteRead for Twim<'a, T> { | 759 | impl<'a, T: Instance> embedded_hal_02::blocking::i2c::WriteRead for Twim<'a, T> { |
| 787 | type Error = Error; | 760 | type Error = Error; |
| 788 | 761 | ||
| 789 | fn write_read<'w>( | 762 | fn write_read<'w>(&mut self, addr: u8, bytes: &'w [u8], buffer: &'w mut [u8]) -> Result<(), Error> { |
| 790 | &mut self, | ||
| 791 | addr: u8, | ||
| 792 | bytes: &'w [u8], | ||
| 793 | buffer: &'w mut [u8], | ||
| 794 | ) -> Result<(), Error> { | ||
| 795 | self.blocking_write_read(addr, bytes, buffer) | 763 | self.blocking_write_read(addr, bytes, buffer) |
| 796 | } | 764 | } |
| 797 | } | 765 | } |
| @@ -809,12 +777,12 @@ mod eh1 { | |||
| 809 | Self::Transmit => embedded_hal_1::i2c::ErrorKind::Other, | 777 | Self::Transmit => embedded_hal_1::i2c::ErrorKind::Other, |
| 810 | Self::Receive => embedded_hal_1::i2c::ErrorKind::Other, | 778 | Self::Receive => embedded_hal_1::i2c::ErrorKind::Other, |
| 811 | Self::DMABufferNotInDataMemory => embedded_hal_1::i2c::ErrorKind::Other, | 779 | Self::DMABufferNotInDataMemory => embedded_hal_1::i2c::ErrorKind::Other, |
| 812 | Self::AddressNack => embedded_hal_1::i2c::ErrorKind::NoAcknowledge( | 780 | Self::AddressNack => { |
| 813 | embedded_hal_1::i2c::NoAcknowledgeSource::Address, | 781 | embedded_hal_1::i2c::ErrorKind::NoAcknowledge(embedded_hal_1::i2c::NoAcknowledgeSource::Address) |
| 814 | ), | 782 | } |
| 815 | Self::DataNack => embedded_hal_1::i2c::ErrorKind::NoAcknowledge( | 783 | Self::DataNack => { |
| 816 | embedded_hal_1::i2c::NoAcknowledgeSource::Data, | 784 | embedded_hal_1::i2c::ErrorKind::NoAcknowledge(embedded_hal_1::i2c::NoAcknowledgeSource::Data) |
| 817 | ), | 785 | } |
| 818 | Self::Overrun => embedded_hal_1::i2c::ErrorKind::Overrun, | 786 | Self::Overrun => embedded_hal_1::i2c::ErrorKind::Overrun, |
| 819 | Self::Timeout => embedded_hal_1::i2c::ErrorKind::Other, | 787 | Self::Timeout => embedded_hal_1::i2c::ErrorKind::Other, |
| 820 | } | 788 | } |
| @@ -841,24 +809,14 @@ mod eh1 { | |||
| 841 | todo!(); | 809 | todo!(); |
| 842 | } | 810 | } |
| 843 | 811 | ||
| 844 | fn write_iter_read<B>( | 812 | fn write_iter_read<B>(&mut self, _address: u8, _bytes: B, _buffer: &mut [u8]) -> Result<(), Self::Error> |
| 845 | &mut self, | ||
| 846 | _address: u8, | ||
| 847 | _bytes: B, | ||
| 848 | _buffer: &mut [u8], | ||
| 849 | ) -> Result<(), Self::Error> | ||
| 850 | where | 813 | where |
| 851 | B: IntoIterator<Item = u8>, | 814 | B: IntoIterator<Item = u8>, |
| 852 | { | 815 | { |
| 853 | todo!(); | 816 | todo!(); |
| 854 | } | 817 | } |
| 855 | 818 | ||
| 856 | fn write_read( | 819 | fn write_read(&mut self, address: u8, wr_buffer: &[u8], rd_buffer: &mut [u8]) -> Result<(), Self::Error> { |
| 857 | &mut self, | ||
| 858 | address: u8, | ||
| 859 | wr_buffer: &[u8], | ||
| 860 | rd_buffer: &mut [u8], | ||
| 861 | ) -> Result<(), Self::Error> { | ||
| 862 | self.blocking_write_read(address, wr_buffer, rd_buffer) | 820 | self.blocking_write_read(address, wr_buffer, rd_buffer) |
| 863 | } | 821 | } |
| 864 | 822 | ||
| @@ -870,11 +828,7 @@ mod eh1 { | |||
| 870 | todo!(); | 828 | todo!(); |
| 871 | } | 829 | } |
| 872 | 830 | ||
| 873 | fn transaction_iter<'a, O>( | 831 | fn transaction_iter<'a, O>(&mut self, _address: u8, _operations: O) -> Result<(), Self::Error> |
| 874 | &mut self, | ||
| 875 | _address: u8, | ||
| 876 | _operations: O, | ||
| 877 | ) -> Result<(), Self::Error> | ||
| 878 | where | 832 | where |
| 879 | O: IntoIterator<Item = embedded_hal_1::i2c::blocking::Operation<'a>>, | 833 | O: IntoIterator<Item = embedded_hal_1::i2c::blocking::Operation<'a>>, |
| 880 | { | 834 | { |
diff --git a/embassy-nrf/src/uarte.rs b/embassy-nrf/src/uarte.rs index 70dbfb080..50b341447 100644 --- a/embassy-nrf/src/uarte.rs +++ b/embassy-nrf/src/uarte.rs | |||
| @@ -13,27 +13,24 @@ | |||
| 13 | //! memory may be used given that buffers are passed in directly to its read and write | 13 | //! memory may be used given that buffers are passed in directly to its read and write |
| 14 | //! methods. | 14 | //! methods. |
| 15 | 15 | ||
| 16 | use crate::interrupt::InterruptExt; | ||
| 17 | use crate::Unborrow; | ||
| 18 | use core::marker::PhantomData; | 16 | use core::marker::PhantomData; |
| 19 | use core::sync::atomic::{compiler_fence, Ordering}; | 17 | use core::sync::atomic::{compiler_fence, Ordering}; |
| 20 | use core::task::Poll; | 18 | use core::task::Poll; |
| 19 | |||
| 21 | use embassy_hal_common::drop::OnDrop; | 20 | use embassy_hal_common::drop::OnDrop; |
| 22 | use embassy_hal_common::unborrow; | 21 | use embassy_hal_common::unborrow; |
| 23 | use futures::future::poll_fn; | 22 | use futures::future::poll_fn; |
| 23 | // Re-export SVD variants to allow user to directly set values. | ||
| 24 | pub use pac::uarte0::{baudrate::BAUDRATE_A as Baudrate, config::PARITY_A as Parity}; | ||
| 24 | 25 | ||
| 25 | use crate::chip::{EASY_DMA_SIZE, FORCE_COPY_BUFFER_SIZE}; | 26 | use crate::chip::{EASY_DMA_SIZE, FORCE_COPY_BUFFER_SIZE}; |
| 26 | use crate::gpio::sealed::Pin as _; | 27 | use crate::gpio::sealed::Pin as _; |
| 27 | use crate::gpio::{self, AnyPin, Pin as GpioPin, PselBits}; | 28 | use crate::gpio::{self, AnyPin, Pin as GpioPin, PselBits}; |
| 28 | use crate::interrupt::Interrupt; | 29 | use crate::interrupt::{Interrupt, InterruptExt}; |
| 29 | use crate::pac; | ||
| 30 | use crate::ppi::{AnyConfigurableChannel, ConfigurableChannel, Event, Ppi, Task}; | 30 | use crate::ppi::{AnyConfigurableChannel, ConfigurableChannel, Event, Ppi, Task}; |
| 31 | use crate::timer::Instance as TimerInstance; | 31 | use crate::timer::{Frequency, Instance as TimerInstance, Timer}; |
| 32 | use crate::timer::{Frequency, Timer}; | ||
| 33 | use crate::util::slice_in_ram_or; | 32 | use crate::util::slice_in_ram_or; |
| 34 | 33 | use crate::{pac, Unborrow}; | |
| 35 | // Re-export SVD variants to allow user to directly set values. | ||
| 36 | pub use pac::uarte0::{baudrate::BAUDRATE_A as Baudrate, config::PARITY_A as Parity}; | ||
| 37 | 34 | ||
| 38 | #[non_exhaustive] | 35 | #[non_exhaustive] |
| 39 | pub struct Config { | 36 | pub struct Config { |
| @@ -182,12 +179,8 @@ impl<'d, T: Instance> Uarte<'d, T> { | |||
| 182 | 179 | ||
| 183 | Self { | 180 | Self { |
| 184 | phantom: PhantomData, | 181 | phantom: PhantomData, |
| 185 | tx: UarteTx { | 182 | tx: UarteTx { phantom: PhantomData }, |
| 186 | phantom: PhantomData, | 183 | rx: UarteRx { phantom: PhantomData }, |
| 187 | }, | ||
| 188 | rx: UarteRx { | ||
| 189 | phantom: PhantomData, | ||
| 190 | }, | ||
| 191 | } | 184 | } |
| 192 | } | 185 | } |
| 193 | 186 | ||
| @@ -893,9 +886,7 @@ mod eh02 { | |||
| 893 | } | 886 | } |
| 894 | } | 887 | } |
| 895 | 888 | ||
| 896 | impl<'d, U: Instance, T: TimerInstance> embedded_hal_02::blocking::serial::Write<u8> | 889 | impl<'d, U: Instance, T: TimerInstance> embedded_hal_02::blocking::serial::Write<u8> for UarteWithIdle<'d, U, T> { |
| 897 | for UarteWithIdle<'d, U, T> | ||
| 898 | { | ||
| 899 | type Error = Error; | 890 | type Error = Error; |
| 900 | 891 | ||
| 901 | fn bwrite_all(&mut self, buffer: &[u8]) -> Result<(), Self::Error> { | 892 | fn bwrite_all(&mut self, buffer: &[u8]) -> Result<(), Self::Error> { |
| @@ -956,9 +947,7 @@ mod eh1 { | |||
| 956 | type Error = Error; | 947 | type Error = Error; |
| 957 | } | 948 | } |
| 958 | 949 | ||
| 959 | impl<'d, U: Instance, T: TimerInstance> embedded_hal_1::serial::ErrorType | 950 | impl<'d, U: Instance, T: TimerInstance> embedded_hal_1::serial::ErrorType for UarteWithIdle<'d, U, T> { |
| 960 | for UarteWithIdle<'d, U, T> | ||
| 961 | { | ||
| 962 | type Error = Error; | 951 | type Error = Error; |
| 963 | } | 952 | } |
| 964 | } | 953 | } |
diff --git a/embassy-nrf/src/usb.rs b/embassy-nrf/src/usb.rs index d0223c4c9..6c872581d 100644 --- a/embassy-nrf/src/usb.rs +++ b/embassy-nrf/src/usb.rs | |||
| @@ -1,25 +1,23 @@ | |||
| 1 | #![macro_use] | 1 | #![macro_use] |
| 2 | 2 | ||
| 3 | use crate::interrupt::InterruptExt; | ||
| 4 | use crate::Unborrow; | ||
| 5 | use core::marker::PhantomData; | 3 | use core::marker::PhantomData; |
| 6 | use core::mem::MaybeUninit; | 4 | use core::mem::MaybeUninit; |
| 7 | use core::sync::atomic::{compiler_fence, AtomicU32, Ordering}; | 5 | use core::sync::atomic::{compiler_fence, AtomicU32, Ordering}; |
| 8 | use core::task::Poll; | 6 | use core::task::Poll; |
| 7 | |||
| 9 | use cortex_m::peripheral::NVIC; | 8 | use cortex_m::peripheral::NVIC; |
| 10 | use embassy::waitqueue::AtomicWaker; | 9 | use embassy::waitqueue::AtomicWaker; |
| 11 | use embassy_hal_common::unborrow; | 10 | use embassy_hal_common::unborrow; |
| 11 | pub use embassy_usb; | ||
| 12 | use embassy_usb::driver::{self, EndpointError, Event, Unsupported}; | 12 | use embassy_usb::driver::{self, EndpointError, Event, Unsupported}; |
| 13 | use embassy_usb::types::{EndpointAddress, EndpointInfo, EndpointType, UsbDirection}; | 13 | use embassy_usb::types::{EndpointAddress, EndpointInfo, EndpointType, UsbDirection}; |
| 14 | use futures::future::poll_fn; | 14 | use futures::future::poll_fn; |
| 15 | use futures::Future; | 15 | use futures::Future; |
| 16 | |||
| 17 | pub use embassy_usb; | ||
| 18 | use pac::usbd::RegisterBlock; | 16 | use pac::usbd::RegisterBlock; |
| 19 | 17 | ||
| 20 | use crate::interrupt::Interrupt; | 18 | use crate::interrupt::{Interrupt, InterruptExt}; |
| 21 | use crate::pac; | ||
| 22 | use crate::util::slice_in_ram; | 19 | use crate::util::slice_in_ram; |
| 20 | use crate::{pac, Unborrow}; | ||
| 23 | 21 | ||
| 24 | const NEW_AW: AtomicWaker = AtomicWaker::new(); | 22 | const NEW_AW: AtomicWaker = AtomicWaker::new(); |
| 25 | static BUS_WAKER: AtomicWaker = NEW_AW; | 23 | static BUS_WAKER: AtomicWaker = NEW_AW; |
| @@ -35,10 +33,7 @@ pub struct Driver<'d, T: Instance> { | |||
| 35 | } | 33 | } |
| 36 | 34 | ||
| 37 | impl<'d, T: Instance> Driver<'d, T> { | 35 | impl<'d, T: Instance> Driver<'d, T> { |
| 38 | pub fn new( | 36 | pub fn new(_usb: impl Unborrow<Target = T> + 'd, irq: impl Unborrow<Target = T::Interrupt> + 'd) -> Self { |
| 39 | _usb: impl Unborrow<Target = T> + 'd, | ||
| 40 | irq: impl Unborrow<Target = T::Interrupt> + 'd, | ||
| 41 | ) -> Self { | ||
| 42 | unborrow!(irq); | 37 | unborrow!(irq); |
| 43 | irq.set_handler(Self::on_interrupt); | 38 | irq.set_handler(Self::on_interrupt); |
| 44 | irq.unpend(); | 39 | irq.unpend(); |
| @@ -143,9 +138,7 @@ impl<'d, T: Instance> driver::Driver<'d> for Driver<'d, T> { | |||
| 143 | 138 | ||
| 144 | fn start(self, control_max_packet_size: u16) -> (Self::Bus, Self::ControlPipe) { | 139 | fn start(self, control_max_packet_size: u16) -> (Self::Bus, Self::ControlPipe) { |
| 145 | ( | 140 | ( |
| 146 | Bus { | 141 | Bus { phantom: PhantomData }, |
| 147 | phantom: PhantomData, | ||
| 148 | }, | ||
| 149 | ControlPipe { | 142 | ControlPipe { |
| 150 | _phantom: PhantomData, | 143 | _phantom: PhantomData, |
| 151 | max_packet_size: control_max_packet_size, | 144 | max_packet_size: control_max_packet_size, |
| @@ -266,8 +259,7 @@ impl<'d, T: Instance> driver::Bus for Bus<'d, T> { | |||
| 266 | let regs = T::regs(); | 259 | let regs = T::regs(); |
| 267 | unsafe { | 260 | unsafe { |
| 268 | if ep_addr.index() == 0 { | 261 | if ep_addr.index() == 0 { |
| 269 | regs.tasks_ep0stall | 262 | regs.tasks_ep0stall.write(|w| w.tasks_ep0stall().bit(stalled)); |
| 270 | .write(|w| w.tasks_ep0stall().bit(stalled)); | ||
| 271 | } else { | 263 | } else { |
| 272 | regs.epstall.write(|w| { | 264 | regs.epstall.write(|w| { |
| 273 | w.ep().bits(ep_addr.index() as u8 & 0b111); | 265 | w.ep().bits(ep_addr.index() as u8 & 0b111); |
| @@ -370,8 +362,7 @@ impl<'d, T: Instance> driver::Bus for Bus<'d, T> { | |||
| 370 | regs.eventcause.write(|w| w.usbwuallowed().set_bit()); | 362 | regs.eventcause.write(|w| w.usbwuallowed().set_bit()); |
| 371 | 363 | ||
| 372 | regs.dpdmvalue.write(|w| w.state().resume()); | 364 | regs.dpdmvalue.write(|w| w.state().resume()); |
| 373 | regs.tasks_dpdmdrive | 365 | regs.tasks_dpdmdrive.write(|w| w.tasks_dpdmdrive().set_bit()); |
| 374 | .write(|w| w.tasks_dpdmdrive().set_bit()); | ||
| 375 | 366 | ||
| 376 | Poll::Ready(()) | 367 | Poll::Ready(()) |
| 377 | } else { | 368 | } else { |
| @@ -520,11 +511,7 @@ unsafe fn read_dma<T: Instance>(i: usize, buf: &mut [u8]) -> Result<usize, Endpo | |||
| 520 | dma_start(); | 511 | dma_start(); |
| 521 | regs.events_endepout[i].reset(); | 512 | regs.events_endepout[i].reset(); |
| 522 | regs.tasks_startepout[i].write(|w| w.tasks_startepout().set_bit()); | 513 | regs.tasks_startepout[i].write(|w| w.tasks_startepout().set_bit()); |
| 523 | while regs.events_endepout[i] | 514 | while regs.events_endepout[i].read().events_endepout().bit_is_clear() {} |
| 524 | .read() | ||
| 525 | .events_endepout() | ||
| 526 | .bit_is_clear() | ||
| 527 | {} | ||
| 528 | regs.events_endepout[i].reset(); | 515 | regs.events_endepout[i].reset(); |
| 529 | dma_end(); | 516 | dma_end(); |
| 530 | 517 | ||
| @@ -579,9 +566,7 @@ impl<'d, T: Instance> driver::EndpointOut for Endpoint<'d, T, Out> { | |||
| 579 | let i = self.info.addr.index(); | 566 | let i = self.info.addr.index(); |
| 580 | assert!(i != 0); | 567 | assert!(i != 0); |
| 581 | 568 | ||
| 582 | self.wait_data_ready() | 569 | self.wait_data_ready().await.map_err(|_| EndpointError::Disabled)?; |
| 583 | .await | ||
| 584 | .map_err(|_| EndpointError::Disabled)?; | ||
| 585 | 570 | ||
| 586 | unsafe { read_dma::<T>(i, buf) } | 571 | unsafe { read_dma::<T>(i, buf) } |
| 587 | } | 572 | } |
| @@ -596,9 +581,7 @@ impl<'d, T: Instance> driver::EndpointIn for Endpoint<'d, T, In> { | |||
| 596 | let i = self.info.addr.index(); | 581 | let i = self.info.addr.index(); |
| 597 | assert!(i != 0); | 582 | assert!(i != 0); |
| 598 | 583 | ||
| 599 | self.wait_data_ready() | 584 | self.wait_data_ready().await.map_err(|_| EndpointError::Disabled)?; |
| 600 | .await | ||
| 601 | .map_err(|_| EndpointError::Disabled)?; | ||
| 602 | 585 | ||
| 603 | unsafe { write_dma::<T>(i, buf) } | 586 | unsafe { write_dma::<T>(i, buf) } |
| 604 | 587 | ||
| @@ -659,20 +642,14 @@ impl<'d, T: Instance> driver::ControlPipe for ControlPipe<'d, T> { | |||
| 659 | } | 642 | } |
| 660 | } | 643 | } |
| 661 | 644 | ||
| 662 | fn data_out<'a>( | 645 | fn data_out<'a>(&'a mut self, buf: &'a mut [u8], _first: bool, _last: bool) -> Self::DataOutFuture<'a> { |
| 663 | &'a mut self, | ||
| 664 | buf: &'a mut [u8], | ||
| 665 | _first: bool, | ||
| 666 | _last: bool, | ||
| 667 | ) -> Self::DataOutFuture<'a> { | ||
| 668 | async move { | 646 | async move { |
| 669 | let regs = T::regs(); | 647 | let regs = T::regs(); |
| 670 | 648 | ||
| 671 | regs.events_ep0datadone.reset(); | 649 | regs.events_ep0datadone.reset(); |
| 672 | 650 | ||
| 673 | // This starts a RX on EP0. events_ep0datadone notifies when done. | 651 | // This starts a RX on EP0. events_ep0datadone notifies when done. |
| 674 | regs.tasks_ep0rcvout | 652 | regs.tasks_ep0rcvout.write(|w| w.tasks_ep0rcvout().set_bit()); |
| 675 | .write(|w| w.tasks_ep0rcvout().set_bit()); | ||
| 676 | 653 | ||
| 677 | // Wait until ready | 654 | // Wait until ready |
| 678 | regs.intenset.write(|w| { | 655 | regs.intenset.write(|w| { |
| @@ -701,12 +678,7 @@ impl<'d, T: Instance> driver::ControlPipe for ControlPipe<'d, T> { | |||
| 701 | } | 678 | } |
| 702 | } | 679 | } |
| 703 | 680 | ||
| 704 | fn data_in<'a>( | 681 | fn data_in<'a>(&'a mut self, buf: &'a [u8], _first: bool, last: bool) -> Self::DataInFuture<'a> { |
| 705 | &'a mut self, | ||
| 706 | buf: &'a [u8], | ||
| 707 | _first: bool, | ||
| 708 | last: bool, | ||
| 709 | ) -> Self::DataInFuture<'a> { | ||
| 710 | async move { | 682 | async move { |
| 711 | let regs = T::regs(); | 683 | let regs = T::regs(); |
| 712 | regs.events_ep0datadone.reset(); | 684 | regs.events_ep0datadone.reset(); |
| @@ -745,8 +717,7 @@ impl<'d, T: Instance> driver::ControlPipe for ControlPipe<'d, T> { | |||
| 745 | fn accept<'a>(&'a mut self) -> Self::AcceptFuture<'a> { | 717 | fn accept<'a>(&'a mut self) -> Self::AcceptFuture<'a> { |
| 746 | async move { | 718 | async move { |
| 747 | let regs = T::regs(); | 719 | let regs = T::regs(); |
| 748 | regs.tasks_ep0status | 720 | regs.tasks_ep0status.write(|w| w.tasks_ep0status().bit(true)); |
| 749 | .write(|w| w.tasks_ep0status().bit(true)); | ||
| 750 | } | 721 | } |
| 751 | } | 722 | } |
| 752 | 723 | ||
diff --git a/embassy-rp/src/clocks.rs b/embassy-rp/src/clocks.rs index 3082cd0d7..3ad1e5d82 100644 --- a/embassy-rp/src/clocks.rs +++ b/embassy-rp/src/clocks.rs | |||
| @@ -47,11 +47,9 @@ pub unsafe fn init() { | |||
| 47 | start_xosc(); | 47 | start_xosc(); |
| 48 | 48 | ||
| 49 | // Before we touch PLLs, switch sys and ref cleanly away from their aux sources. | 49 | // Before we touch PLLs, switch sys and ref cleanly away from their aux sources. |
| 50 | c.clk_sys_ctrl() | 50 | c.clk_sys_ctrl().modify(|w| w.set_src(ClkSysCtrlSrc::CLK_REF)); |
| 51 | .modify(|w| w.set_src(ClkSysCtrlSrc::CLK_REF)); | ||
| 52 | while c.clk_sys_selected().read() != 1 {} | 51 | while c.clk_sys_selected().read() != 1 {} |
| 53 | c.clk_ref_ctrl() | 52 | c.clk_ref_ctrl().modify(|w| w.set_src(ClkRefCtrlSrc::ROSC_CLKSRC_PH)); |
| 54 | .modify(|w| w.set_src(ClkRefCtrlSrc::ROSC_CLKSRC_PH)); | ||
| 55 | while c.clk_ref_selected().read() != 1 {} | 53 | while c.clk_ref_selected().read() != 1 {} |
| 56 | 54 | ||
| 57 | // Configure PLLs | 55 | // Configure PLLs |
| @@ -135,9 +133,7 @@ unsafe fn start_xosc() { | |||
| 135 | .write(|w| w.set_freq_range(pac::xosc::vals::CtrlFreqRange::_1_15MHZ)); | 133 | .write(|w| w.set_freq_range(pac::xosc::vals::CtrlFreqRange::_1_15MHZ)); |
| 136 | 134 | ||
| 137 | let startup_delay = (((XOSC_MHZ * 1_000_000) / 1000) + 128) / 256; | 135 | let startup_delay = (((XOSC_MHZ * 1_000_000) / 1000) + 128) / 256; |
| 138 | pac::XOSC | 136 | pac::XOSC.startup().write(|w| w.set_delay(startup_delay as u16)); |
| 139 | .startup() | ||
| 140 | .write(|w| w.set_delay(startup_delay as u16)); | ||
| 141 | pac::XOSC.ctrl().write(|w| { | 137 | pac::XOSC.ctrl().write(|w| { |
| 142 | w.set_freq_range(pac::xosc::vals::CtrlFreqRange::_1_15MHZ); | 138 | w.set_freq_range(pac::xosc::vals::CtrlFreqRange::_1_15MHZ); |
| 143 | w.set_enable(pac::xosc::vals::Enable::ENABLE); | 139 | w.set_enable(pac::xosc::vals::Enable::ENABLE); |
| @@ -145,13 +141,7 @@ unsafe fn start_xosc() { | |||
| 145 | while !pac::XOSC.status().read().stable() {} | 141 | while !pac::XOSC.status().read().stable() {} |
| 146 | } | 142 | } |
| 147 | 143 | ||
| 148 | unsafe fn configure_pll( | 144 | unsafe fn configure_pll(p: pac::pll::Pll, refdiv: u32, vco_freq: u32, post_div1: u8, post_div2: u8) { |
| 149 | p: pac::pll::Pll, | ||
| 150 | refdiv: u32, | ||
| 151 | vco_freq: u32, | ||
| 152 | post_div1: u8, | ||
| 153 | post_div2: u8, | ||
| 154 | ) { | ||
| 155 | let ref_freq = XOSC_MHZ * 1_000_000 / refdiv; | 145 | let ref_freq = XOSC_MHZ * 1_000_000 / refdiv; |
| 156 | 146 | ||
| 157 | let fbdiv = vco_freq / ref_freq; | 147 | let fbdiv = vco_freq / ref_freq; |
diff --git a/embassy-rp/src/gpio.rs b/embassy-rp/src/gpio.rs index a2e1b3d7b..ae771e849 100644 --- a/embassy-rp/src/gpio.rs +++ b/embassy-rp/src/gpio.rs | |||
| @@ -1,13 +1,11 @@ | |||
| 1 | use core::convert::Infallible; | 1 | use core::convert::Infallible; |
| 2 | use core::marker::PhantomData; | 2 | use core::marker::PhantomData; |
| 3 | 3 | ||
| 4 | use crate::pac; | 4 | use embassy_hal_common::{unborrow, unsafe_impl_unborrow}; |
| 5 | |||
| 5 | use crate::pac::common::{Reg, RW}; | 6 | use crate::pac::common::{Reg, RW}; |
| 6 | use crate::pac::SIO; | 7 | use crate::pac::SIO; |
| 7 | use crate::peripherals; | 8 | use crate::{pac, peripherals, Unborrow}; |
| 8 | |||
| 9 | use crate::Unborrow; | ||
| 10 | use embassy_hal_common::{unborrow, unsafe_impl_unborrow}; | ||
| 11 | 9 | ||
| 12 | /// Represents a digital input or output level. | 10 | /// Represents a digital input or output level. |
| 13 | #[derive(Debug, Eq, PartialEq)] | 11 | #[derive(Debug, Eq, PartialEq)] |
| @@ -195,10 +193,7 @@ impl<'d, T: Pin> OutputOpenDrain<'d, T> { | |||
| 195 | pub fn set_high(&mut self) { | 193 | pub fn set_high(&mut self) { |
| 196 | // For Open Drain High, disable the output pin. | 194 | // For Open Drain High, disable the output pin. |
| 197 | unsafe { | 195 | unsafe { |
| 198 | self.pin | 196 | self.pin.sio_oe().value_clr().write_value(1 << self.pin.pin()); |
| 199 | .sio_oe() | ||
| 200 | .value_clr() | ||
| 201 | .write_value(1 << self.pin.pin()); | ||
| 202 | } | 197 | } |
| 203 | } | 198 | } |
| 204 | 199 | ||
| @@ -207,10 +202,7 @@ impl<'d, T: Pin> OutputOpenDrain<'d, T> { | |||
| 207 | pub fn set_low(&mut self) { | 202 | pub fn set_low(&mut self) { |
| 208 | // For Open Drain Low, enable the output pin. | 203 | // For Open Drain Low, enable the output pin. |
| 209 | unsafe { | 204 | unsafe { |
| 210 | self.pin | 205 | self.pin.sio_oe().value_set().write_value(1 << self.pin.pin()); |
| 211 | .sio_oe() | ||
| 212 | .value_set() | ||
| 213 | .write_value(1 << self.pin.pin()); | ||
| 214 | } | 206 | } |
| 215 | } | 207 | } |
| 216 | 208 | ||
diff --git a/embassy-rp/src/interrupt.rs b/embassy-rp/src/interrupt.rs index 042882691..d652a8c71 100644 --- a/embassy-rp/src/interrupt.rs +++ b/embassy-rp/src/interrupt.rs | |||
| @@ -5,9 +5,9 @@ | |||
| 5 | 5 | ||
| 6 | // Re-exports | 6 | // Re-exports |
| 7 | pub use embassy_cortex_m::interrupt::*; | 7 | pub use embassy_cortex_m::interrupt::*; |
| 8 | use embassy_macros::cortex_m_interrupt_declare as declare; | ||
| 8 | 9 | ||
| 9 | use crate::pac::Interrupt as InterruptEnum; | 10 | use crate::pac::Interrupt as InterruptEnum; |
| 10 | use embassy_macros::cortex_m_interrupt_declare as declare; | ||
| 11 | declare!(TIMER_IRQ_0); | 11 | declare!(TIMER_IRQ_0); |
| 12 | declare!(TIMER_IRQ_1); | 12 | declare!(TIMER_IRQ_1); |
| 13 | declare!(TIMER_IRQ_2); | 13 | declare!(TIMER_IRQ_2); |
diff --git a/embassy-rp/src/lib.rs b/embassy-rp/src/lib.rs index 72fe864b5..90ef1b170 100644 --- a/embassy-rp/src/lib.rs +++ b/embassy-rp/src/lib.rs | |||
| @@ -17,15 +17,14 @@ mod reset; | |||
| 17 | 17 | ||
| 18 | // Reexports | 18 | // Reexports |
| 19 | 19 | ||
| 20 | pub use embassy_cortex_m::executor; | ||
| 21 | pub use embassy_hal_common::{unborrow, Unborrow}; | ||
| 22 | pub use embassy_macros::cortex_m_interrupt as interrupt; | ||
| 20 | #[cfg(feature = "unstable-pac")] | 23 | #[cfg(feature = "unstable-pac")] |
| 21 | pub use rp2040_pac2 as pac; | 24 | pub use rp2040_pac2 as pac; |
| 22 | #[cfg(not(feature = "unstable-pac"))] | 25 | #[cfg(not(feature = "unstable-pac"))] |
| 23 | pub(crate) use rp2040_pac2 as pac; | 26 | pub(crate) use rp2040_pac2 as pac; |
| 24 | 27 | ||
| 25 | pub use embassy_cortex_m::executor; | ||
| 26 | pub use embassy_hal_common::{unborrow, Unborrow}; | ||
| 27 | pub use embassy_macros::cortex_m_interrupt as interrupt; | ||
| 28 | |||
| 29 | embassy_hal_common::peripherals! { | 28 | embassy_hal_common::peripherals! { |
| 30 | PIN_0, | 29 | PIN_0, |
| 31 | PIN_1, | 30 | PIN_1, |
diff --git a/embassy-rp/src/reset.rs b/embassy-rp/src/reset.rs index 914e6a698..edd47c223 100644 --- a/embassy-rp/src/reset.rs +++ b/embassy-rp/src/reset.rs | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | use crate::pac; | ||
| 2 | |||
| 3 | pub use pac::resets::regs::Peripherals; | 1 | pub use pac::resets::regs::Peripherals; |
| 4 | 2 | ||
| 3 | use crate::pac; | ||
| 4 | |||
| 5 | pub const ALL_PERIPHERALS: Peripherals = Peripherals(0x01ffffff); | 5 | pub const ALL_PERIPHERALS: Peripherals = Peripherals(0x01ffffff); |
| 6 | 6 | ||
| 7 | pub unsafe fn reset(peris: Peripherals) { | 7 | pub unsafe fn reset(peris: Peripherals) { |
| @@ -10,8 +10,6 @@ pub unsafe fn reset(peris: Peripherals) { | |||
| 10 | 10 | ||
| 11 | pub unsafe fn unreset_wait(peris: Peripherals) { | 11 | pub unsafe fn unreset_wait(peris: Peripherals) { |
| 12 | // TODO use the "atomic clear" register version | 12 | // TODO use the "atomic clear" register version |
| 13 | pac::RESETS | 13 | pac::RESETS.reset().modify(|v| *v = Peripherals(v.0 & !peris.0)); |
| 14 | .reset() | ||
| 15 | .modify(|v| *v = Peripherals(v.0 & !peris.0)); | ||
| 16 | while ((!pac::RESETS.reset_done().read().0) & peris.0) != 0 {} | 14 | while ((!pac::RESETS.reset_done().read().0) & peris.0) != 0 {} |
| 17 | } | 15 | } |
diff --git a/embassy-rp/src/spi.rs b/embassy-rp/src/spi.rs index 726c20a83..e988e41d2 100644 --- a/embassy-rp/src/spi.rs +++ b/embassy-rp/src/spi.rs | |||
| @@ -1,13 +1,11 @@ | |||
| 1 | use core::marker::PhantomData; | 1 | use core::marker::PhantomData; |
| 2 | 2 | ||
| 3 | use crate::Unborrow; | ||
| 4 | use embassy_hal_common::unborrow; | 3 | use embassy_hal_common::unborrow; |
| 4 | pub use embedded_hal_02::spi::{Phase, Polarity}; | ||
| 5 | 5 | ||
| 6 | use crate::gpio::sealed::Pin as _; | 6 | use crate::gpio::sealed::Pin as _; |
| 7 | use crate::gpio::{AnyPin, Pin as GpioPin}; | 7 | use crate::gpio::{AnyPin, Pin as GpioPin}; |
| 8 | use crate::{pac, peripherals}; | 8 | use crate::{pac, peripherals, Unborrow}; |
| 9 | |||
| 10 | pub use embedded_hal_02::spi::{Phase, Polarity}; | ||
| 11 | 9 | ||
| 12 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] | 10 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| 13 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | 11 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] |
| @@ -56,11 +54,7 @@ fn calc_prescs(freq: u32) -> (u8, u8) { | |||
| 56 | } | 54 | } |
| 57 | 55 | ||
| 58 | let presc = div_roundup(ratio, 256); | 56 | let presc = div_roundup(ratio, 256); |
| 59 | let postdiv = if presc == 1 { | 57 | let postdiv = if presc == 1 { ratio } else { div_roundup(ratio, presc) }; |
| 60 | ratio | ||
| 61 | } else { | ||
| 62 | div_roundup(ratio, presc) | ||
| 63 | }; | ||
| 64 | 58 | ||
| 65 | ((presc * 2) as u8, (postdiv - 1) as u8) | 59 | ((presc * 2) as u8, (postdiv - 1) as u8) |
| 66 | } | 60 | } |
| @@ -91,14 +85,7 @@ impl<'d, T: Instance> Spi<'d, T> { | |||
| 91 | config: Config, | 85 | config: Config, |
| 92 | ) -> Self { | 86 | ) -> Self { |
| 93 | unborrow!(clk, mosi); | 87 | unborrow!(clk, mosi); |
| 94 | Self::new_inner( | 88 | Self::new_inner(inner, Some(clk.degrade()), Some(mosi.degrade()), None, None, config) |
| 95 | inner, | ||
| 96 | Some(clk.degrade()), | ||
| 97 | Some(mosi.degrade()), | ||
| 98 | None, | ||
| 99 | None, | ||
| 100 | config, | ||
| 101 | ) | ||
| 102 | } | 89 | } |
| 103 | 90 | ||
| 104 | pub fn new_rxonly( | 91 | pub fn new_rxonly( |
| @@ -108,14 +95,7 @@ impl<'d, T: Instance> Spi<'d, T> { | |||
| 108 | config: Config, | 95 | config: Config, |
| 109 | ) -> Self { | 96 | ) -> Self { |
| 110 | unborrow!(clk, miso); | 97 | unborrow!(clk, miso); |
| 111 | Self::new_inner( | 98 | Self::new_inner(inner, Some(clk.degrade()), None, Some(miso.degrade()), None, config) |
| 112 | inner, | ||
| 113 | Some(clk.degrade()), | ||
| 114 | None, | ||
| 115 | Some(miso.degrade()), | ||
| 116 | None, | ||
| 117 | config, | ||
| 118 | ) | ||
| 119 | } | 99 | } |
| 120 | 100 | ||
| 121 | fn new_inner( | 101 | fn new_inner( |
diff --git a/embassy-rp/src/timer.rs b/embassy-rp/src/timer.rs index c43e044f3..6c4c258b1 100644 --- a/embassy-rp/src/timer.rs +++ b/embassy-rp/src/timer.rs | |||
| @@ -1,11 +1,12 @@ | |||
| 1 | use crate::interrupt::{Interrupt, InterruptExt}; | ||
| 2 | use atomic_polyfill::{AtomicU8, Ordering}; | ||
| 3 | use core::cell::Cell; | 1 | use core::cell::Cell; |
| 2 | |||
| 3 | use atomic_polyfill::{AtomicU8, Ordering}; | ||
| 4 | use critical_section::CriticalSection; | 4 | use critical_section::CriticalSection; |
| 5 | use embassy::blocking_mutex::raw::CriticalSectionRawMutex; | 5 | use embassy::blocking_mutex::raw::CriticalSectionRawMutex; |
| 6 | use embassy::blocking_mutex::Mutex; | 6 | use embassy::blocking_mutex::Mutex; |
| 7 | use embassy::time::driver::{AlarmHandle, Driver}; | 7 | use embassy::time::driver::{AlarmHandle, Driver}; |
| 8 | 8 | ||
| 9 | use crate::interrupt::{Interrupt, InterruptExt}; | ||
| 9 | use crate::{interrupt, pac}; | 10 | use crate::{interrupt, pac}; |
| 10 | 11 | ||
| 11 | struct AlarmState { | 12 | struct AlarmState { |
| @@ -45,15 +46,13 @@ impl Driver for TimerDriver { | |||
| 45 | } | 46 | } |
| 46 | 47 | ||
| 47 | unsafe fn allocate_alarm(&self) -> Option<AlarmHandle> { | 48 | unsafe fn allocate_alarm(&self) -> Option<AlarmHandle> { |
| 48 | let id = self | 49 | let id = self.next_alarm.fetch_update(Ordering::AcqRel, Ordering::Acquire, |x| { |
| 49 | .next_alarm | 50 | if x < ALARM_COUNT as u8 { |
| 50 | .fetch_update(Ordering::AcqRel, Ordering::Acquire, |x| { | 51 | Some(x + 1) |
| 51 | if x < ALARM_COUNT as u8 { | 52 | } else { |
| 52 | Some(x + 1) | 53 | None |
| 53 | } else { | 54 | } |
| 54 | None | 55 | }); |
| 55 | } | ||
| 56 | }); | ||
| 57 | 56 | ||
| 58 | match id { | 57 | match id { |
| 59 | Ok(id) => Some(AlarmHandle::new(id)), | 58 | Ok(id) => Some(AlarmHandle::new(id)), |
diff --git a/embassy-rp/src/uart.rs b/embassy-rp/src/uart.rs index 1aa3c5a84..c95407b6f 100644 --- a/embassy-rp/src/uart.rs +++ b/embassy-rp/src/uart.rs | |||
| @@ -1,10 +1,9 @@ | |||
| 1 | use core::marker::PhantomData; | 1 | use core::marker::PhantomData; |
| 2 | 2 | ||
| 3 | use crate::Unborrow; | ||
| 4 | use embassy_hal_common::unborrow; | 3 | use embassy_hal_common::unborrow; |
| 5 | use gpio::Pin; | 4 | use gpio::Pin; |
| 6 | 5 | ||
| 7 | use crate::{gpio, pac, peripherals}; | 6 | use crate::{gpio, pac, peripherals, Unborrow}; |
| 8 | 7 | ||
| 9 | #[non_exhaustive] | 8 | #[non_exhaustive] |
| 10 | pub struct Config { | 9 | pub struct Config { |
| @@ -57,10 +56,8 @@ impl<'d, T: Instance> Uart<'d, T> { | |||
| 57 | } | 56 | } |
| 58 | 57 | ||
| 59 | // Load PL011's baud divisor registers | 58 | // Load PL011's baud divisor registers |
| 60 | p.uartibrd() | 59 | p.uartibrd().write_value(pac::uart::regs::Uartibrd(baud_ibrd)); |
| 61 | .write_value(pac::uart::regs::Uartibrd(baud_ibrd)); | 60 | p.uartfbrd().write_value(pac::uart::regs::Uartfbrd(baud_fbrd)); |
| 62 | p.uartfbrd() | ||
| 63 | .write_value(pac::uart::regs::Uartfbrd(baud_fbrd)); | ||
| 64 | 61 | ||
| 65 | p.uartlcr_h().write(|w| { | 62 | p.uartlcr_h().write(|w| { |
| 66 | w.set_wlen(config.data_bits - 5); | 63 | w.set_wlen(config.data_bits - 5); |
diff --git a/embassy-stm32/build.rs b/embassy-stm32/build.rs index 42c88a269..3b4aa5dfd 100644 --- a/embassy-stm32/build.rs +++ b/embassy-stm32/build.rs | |||
| @@ -1,10 +1,10 @@ | |||
| 1 | use proc_macro2::TokenStream; | ||
| 2 | use quote::{format_ident, quote}; | ||
| 3 | use std::collections::{HashMap, HashSet}; | 1 | use std::collections::{HashMap, HashSet}; |
| 4 | use std::env; | ||
| 5 | use std::fmt::Write as _; | 2 | use std::fmt::Write as _; |
| 6 | use std::fs; | ||
| 7 | use std::path::PathBuf; | 3 | use std::path::PathBuf; |
| 4 | use std::{env, fs}; | ||
| 5 | |||
| 6 | use proc_macro2::TokenStream; | ||
| 7 | use quote::{format_ident, quote}; | ||
| 8 | use stm32_metapac::metadata::METADATA; | 8 | use stm32_metapac::metadata::METADATA; |
| 9 | 9 | ||
| 10 | fn main() { | 10 | fn main() { |
| @@ -116,10 +116,7 @@ fn main() { | |||
| 116 | continue; | 116 | continue; |
| 117 | } | 117 | } |
| 118 | for irq in p.interrupts { | 118 | for irq in p.interrupts { |
| 119 | dma_irqs | 119 | dma_irqs.entry(irq.interrupt).or_default().push((p.name, irq.signal)); |
| 120 | .entry(irq.interrupt) | ||
| 121 | .or_default() | ||
| 122 | .push((p.name, irq.signal)); | ||
| 123 | } | 120 | } |
| 124 | } | 121 | } |
| 125 | } | 122 | } |
| @@ -128,9 +125,7 @@ fn main() { | |||
| 128 | for (irq, channels) in dma_irqs { | 125 | for (irq, channels) in dma_irqs { |
| 129 | let irq = format_ident!("{}", irq); | 126 | let irq = format_ident!("{}", irq); |
| 130 | 127 | ||
| 131 | let channels = channels | 128 | let channels = channels.iter().map(|(dma, ch)| format_ident!("{}_{}", dma, ch)); |
| 132 | .iter() | ||
| 133 | .map(|(dma, ch)| format_ident!("{}_{}", dma, ch)); | ||
| 134 | 129 | ||
| 135 | g.extend(quote! { | 130 | g.extend(quote! { |
| 136 | #[crate::interrupt] | 131 | #[crate::interrupt] |
| @@ -147,9 +142,7 @@ fn main() { | |||
| 147 | 142 | ||
| 148 | for p in METADATA.peripherals { | 143 | for p in METADATA.peripherals { |
| 149 | // generating RccPeripheral impl for H7 ADC3 would result in bad frequency | 144 | // generating RccPeripheral impl for H7 ADC3 would result in bad frequency |
| 150 | if !singletons.contains(&p.name.to_string()) | 145 | if !singletons.contains(&p.name.to_string()) || (p.name == "ADC3" && METADATA.line.starts_with("STM32H7")) { |
| 151 | || (p.name == "ADC3" && METADATA.line.starts_with("STM32H7")) | ||
| 152 | { | ||
| 153 | continue; | 146 | continue; |
| 154 | } | 147 | } |
| 155 | 148 | ||
| @@ -568,12 +561,7 @@ fn main() { | |||
| 568 | let mut pins_table: Vec<Vec<String>> = Vec::new(); | 561 | let mut pins_table: Vec<Vec<String>> = Vec::new(); |
| 569 | let mut dma_channels_table: Vec<Vec<String>> = Vec::new(); | 562 | let mut dma_channels_table: Vec<Vec<String>> = Vec::new(); |
| 570 | 563 | ||
| 571 | let gpio_base = METADATA | 564 | let gpio_base = METADATA.peripherals.iter().find(|p| p.name == "GPIOA").unwrap().address as u32; |
| 572 | .peripherals | ||
| 573 | .iter() | ||
| 574 | .find(|p| p.name == "GPIOA") | ||
| 575 | .unwrap() | ||
| 576 | .address as u32; | ||
| 577 | let gpio_stride = 0x400; | 565 | let gpio_stride = 0x400; |
| 578 | 566 | ||
| 579 | for p in METADATA.peripherals { | 567 | for p in METADATA.peripherals { |
| @@ -618,11 +606,7 @@ fn main() { | |||
| 618 | 606 | ||
| 619 | for ch in METADATA.dma_channels { | 607 | for ch in METADATA.dma_channels { |
| 620 | let mut row = Vec::new(); | 608 | let mut row = Vec::new(); |
| 621 | let dma_peri = METADATA | 609 | let dma_peri = METADATA.peripherals.iter().find(|p| p.name == ch.dma).unwrap(); |
| 622 | .peripherals | ||
| 623 | .iter() | ||
| 624 | .find(|p| p.name == ch.dma) | ||
| 625 | .unwrap(); | ||
| 626 | let bi = dma_peri.registers.as_ref().unwrap(); | 610 | let bi = dma_peri.registers.as_ref().unwrap(); |
| 627 | 611 | ||
| 628 | let num; | 612 | let num; |
| @@ -649,10 +633,7 @@ fn main() { | |||
| 649 | row.push(num.to_string()); | 633 | row.push(num.to_string()); |
| 650 | if let Some(dmamux) = &ch.dmamux { | 634 | if let Some(dmamux) = &ch.dmamux { |
| 651 | let dmamux_channel = ch.dmamux_channel.unwrap(); | 635 | let dmamux_channel = ch.dmamux_channel.unwrap(); |
| 652 | row.push(format!( | 636 | row.push(format!("{{dmamux: {}, dmamux_channel: {}}}", dmamux, dmamux_channel)); |
| 653 | "{{dmamux: {}, dmamux_channel: {}}}", | ||
| 654 | dmamux, dmamux_channel | ||
| 655 | )); | ||
| 656 | } else { | 637 | } else { |
| 657 | row.push("{}".to_string()); | 638 | row.push("{}".to_string()); |
| 658 | } | 639 | } |
| @@ -709,11 +690,7 @@ fn main() { | |||
| 709 | }; | 690 | }; |
| 710 | 691 | ||
| 711 | if let Some(core) = core_name { | 692 | if let Some(core) = core_name { |
| 712 | println!( | 693 | println!("cargo:rustc-cfg={}_{}", &chip_name[..chip_name.len() - 2], core); |
| 713 | "cargo:rustc-cfg={}_{}", | ||
| 714 | &chip_name[..chip_name.len() - 2], | ||
| 715 | core | ||
| 716 | ); | ||
| 717 | } else { | 694 | } else { |
| 718 | println!("cargo:rustc-cfg={}", &chip_name[..chip_name.len() - 2]); | 695 | println!("cargo:rustc-cfg={}", &chip_name[..chip_name.len() - 2]); |
| 719 | } | 696 | } |
diff --git a/embassy-stm32/src/adc/f1.rs b/embassy-stm32/src/adc/f1.rs index ecb68b1a9..74cfac136 100644 --- a/embassy-stm32/src/adc/f1.rs +++ b/embassy-stm32/src/adc/f1.rs | |||
| @@ -1,10 +1,12 @@ | |||
| 1 | use core::marker::PhantomData; | ||
| 2 | |||
| 3 | use embassy_hal_common::unborrow; | ||
| 4 | use embedded_hal_02::blocking::delay::DelayUs; | ||
| 5 | |||
| 1 | use crate::adc::{AdcPin, Instance}; | 6 | use crate::adc::{AdcPin, Instance}; |
| 2 | use crate::rcc::get_freqs; | 7 | use crate::rcc::get_freqs; |
| 3 | use crate::time::Hertz; | 8 | use crate::time::Hertz; |
| 4 | use crate::Unborrow; | 9 | use crate::Unborrow; |
| 5 | use core::marker::PhantomData; | ||
| 6 | use embassy_hal_common::unborrow; | ||
| 7 | use embedded_hal_02::blocking::delay::DelayUs; | ||
| 8 | 10 | ||
| 9 | pub const VDDA_CALIB_MV: u32 = 3300; | 11 | pub const VDDA_CALIB_MV: u32 = 3300; |
| 10 | pub const ADC_MAX: u32 = (1 << 12) - 1; | 12 | pub const ADC_MAX: u32 = (1 << 12) - 1; |
diff --git a/embassy-stm32/src/adc/v2.rs b/embassy-stm32/src/adc/v2.rs index cdb8dfe9e..936a35562 100644 --- a/embassy-stm32/src/adc/v2.rs +++ b/embassy-stm32/src/adc/v2.rs | |||
| @@ -1,10 +1,12 @@ | |||
| 1 | use crate::adc::{AdcPin, Instance}; | ||
| 2 | use crate::time::Hertz; | ||
| 3 | use crate::Unborrow; | ||
| 4 | use core::marker::PhantomData; | 1 | use core::marker::PhantomData; |
| 2 | |||
| 5 | use embassy_hal_common::unborrow; | 3 | use embassy_hal_common::unborrow; |
| 6 | use embedded_hal_02::blocking::delay::DelayUs; | 4 | use embedded_hal_02::blocking::delay::DelayUs; |
| 7 | 5 | ||
| 6 | use crate::adc::{AdcPin, Instance}; | ||
| 7 | use crate::time::Hertz; | ||
| 8 | use crate::Unborrow; | ||
| 9 | |||
| 8 | pub const VDDA_CALIB_MV: u32 = 3000; | 10 | pub const VDDA_CALIB_MV: u32 = 3000; |
| 9 | 11 | ||
| 10 | #[cfg(not(any(rcc_f4, rcc_f7)))] | 12 | #[cfg(not(any(rcc_f4, rcc_f7)))] |
| @@ -132,9 +134,7 @@ impl Prescaler { | |||
| 132 | 2..=3 => Self::Div4, | 134 | 2..=3 => Self::Div4, |
| 133 | 4..=5 => Self::Div6, | 135 | 4..=5 => Self::Div6, |
| 134 | 6..=7 => Self::Div8, | 136 | 6..=7 => Self::Div8, |
| 135 | _ => panic!( | 137 | _ => panic!("Selected PCLK2 frequency is too high for ADC with largest possible prescaler."), |
| 136 | "Selected PCLK2 frequency is too high for ADC with largest possible prescaler." | ||
| 137 | ), | ||
| 138 | } | 138 | } |
| 139 | } | 139 | } |
| 140 | 140 | ||
| @@ -165,9 +165,7 @@ where | |||
| 165 | 165 | ||
| 166 | let presc = unsafe { Prescaler::from_pclk2(crate::rcc::get_freqs().apb2) }; | 166 | let presc = unsafe { Prescaler::from_pclk2(crate::rcc::get_freqs().apb2) }; |
| 167 | unsafe { | 167 | unsafe { |
| 168 | T::common_regs() | 168 | T::common_regs().ccr().modify(|w| w.set_adcpre(presc.adcpre())); |
| 169 | .ccr() | ||
| 170 | .modify(|w| w.set_adcpre(presc.adcpre())); | ||
| 171 | } | 169 | } |
| 172 | 170 | ||
| 173 | unsafe { | 171 | unsafe { |
| @@ -241,9 +239,7 @@ where | |||
| 241 | pin.set_as_analog(); | 239 | pin.set_as_analog(); |
| 242 | 240 | ||
| 243 | // Configure ADC | 241 | // Configure ADC |
| 244 | T::regs() | 242 | T::regs().cr1().modify(|reg| reg.set_res(self.resolution.res())); |
| 245 | .cr1() | ||
| 246 | .modify(|reg| reg.set_res(self.resolution.res())); | ||
| 247 | 243 | ||
| 248 | // Select channel | 244 | // Select channel |
| 249 | T::regs().sqr3().write(|reg| reg.set_sq(0, pin.channel())); | 245 | T::regs().sqr3().write(|reg| reg.set_sq(0, pin.channel())); |
diff --git a/embassy-stm32/src/adc/v3.rs b/embassy-stm32/src/adc/v3.rs index 875510b7b..49d149b18 100644 --- a/embassy-stm32/src/adc/v3.rs +++ b/embassy-stm32/src/adc/v3.rs | |||
| @@ -1,9 +1,11 @@ | |||
| 1 | use crate::adc::{AdcPin, Instance}; | ||
| 2 | use crate::Unborrow; | ||
| 3 | use core::marker::PhantomData; | 1 | use core::marker::PhantomData; |
| 2 | |||
| 4 | use embassy_hal_common::unborrow; | 3 | use embassy_hal_common::unborrow; |
| 5 | use embedded_hal_02::blocking::delay::DelayUs; | 4 | use embedded_hal_02::blocking::delay::DelayUs; |
| 6 | 5 | ||
| 6 | use crate::adc::{AdcPin, Instance}; | ||
| 7 | use crate::Unborrow; | ||
| 8 | |||
| 7 | pub const VDDA_CALIB_MV: u32 = 3000; | 9 | pub const VDDA_CALIB_MV: u32 = 3000; |
| 8 | 10 | ||
| 9 | /// Sadly we cannot use `RccPeripheral::enable` since devices are quite inconsistent ADC clock | 11 | /// Sadly we cannot use `RccPeripheral::enable` since devices are quite inconsistent ADC clock |
| @@ -369,13 +371,9 @@ impl<'d, T: Instance> Adc<'d, T> { | |||
| 369 | 371 | ||
| 370 | // Configure ADC | 372 | // Configure ADC |
| 371 | #[cfg(not(stm32g0))] | 373 | #[cfg(not(stm32g0))] |
| 372 | T::regs() | 374 | T::regs().cfgr().modify(|reg| reg.set_res(self.resolution.res())); |
| 373 | .cfgr() | ||
| 374 | .modify(|reg| reg.set_res(self.resolution.res())); | ||
| 375 | #[cfg(stm32g0)] | 375 | #[cfg(stm32g0)] |
| 376 | T::regs() | 376 | T::regs().cfgr1().modify(|reg| reg.set_res(self.resolution.res())); |
| 377 | .cfgr1() | ||
| 378 | .modify(|reg| reg.set_res(self.resolution.res())); | ||
| 379 | 377 | ||
| 380 | // Configure channel | 378 | // Configure channel |
| 381 | Self::set_channel_sample_time(pin.channel(), self.sample_time); | 379 | Self::set_channel_sample_time(pin.channel(), self.sample_time); |
| @@ -384,9 +382,7 @@ impl<'d, T: Instance> Adc<'d, T> { | |||
| 384 | #[cfg(not(stm32g0))] | 382 | #[cfg(not(stm32g0))] |
| 385 | T::regs().sqr1().write(|reg| reg.set_sq(0, pin.channel())); | 383 | T::regs().sqr1().write(|reg| reg.set_sq(0, pin.channel())); |
| 386 | #[cfg(stm32g0)] | 384 | #[cfg(stm32g0)] |
| 387 | T::regs() | 385 | T::regs().chselr().write(|reg| reg.set_chsel(pin.channel() as u32)); |
| 388 | .chselr() | ||
| 389 | .write(|reg| reg.set_chsel(pin.channel() as u32)); | ||
| 390 | 386 | ||
| 391 | // Some models are affected by an erratum: | 387 | // Some models are affected by an erratum: |
| 392 | // If we perform conversions slower than 1 kHz, the first read ADC value can be | 388 | // If we perform conversions slower than 1 kHz, the first read ADC value can be |
| @@ -407,9 +403,7 @@ impl<'d, T: Instance> Adc<'d, T> { | |||
| 407 | 403 | ||
| 408 | #[cfg(stm32g0)] | 404 | #[cfg(stm32g0)] |
| 409 | unsafe fn set_channel_sample_time(_ch: u8, sample_time: SampleTime) { | 405 | unsafe fn set_channel_sample_time(_ch: u8, sample_time: SampleTime) { |
| 410 | T::regs() | 406 | T::regs().smpr().modify(|reg| reg.set_smp1(sample_time.sample_time())); |
| 411 | .smpr() | ||
| 412 | .modify(|reg| reg.set_smp1(sample_time.sample_time())); | ||
| 413 | } | 407 | } |
| 414 | 408 | ||
| 415 | #[cfg(not(stm32g0))] | 409 | #[cfg(not(stm32g0))] |
diff --git a/embassy-stm32/src/adc/v4.rs b/embassy-stm32/src/adc/v4.rs index 316e04e0c..cdb79f517 100644 --- a/embassy-stm32/src/adc/v4.rs +++ b/embassy-stm32/src/adc/v4.rs | |||
| @@ -1,16 +1,13 @@ | |||
| 1 | use core::marker::PhantomData; | 1 | use core::marker::PhantomData; |
| 2 | 2 | ||
| 3 | use crate::time::{Hertz, U32Ext}; | 3 | use atomic_polyfill::{AtomicU8, Ordering}; |
| 4 | use crate::Unborrow; | ||
| 5 | use atomic_polyfill::AtomicU8; | ||
| 6 | use atomic_polyfill::Ordering; | ||
| 7 | use embedded_hal_02::blocking::delay::DelayUs; | 4 | use embedded_hal_02::blocking::delay::DelayUs; |
| 8 | use pac::adc::vals::{Adcaldif, Boost, Difsel, Exten, Pcsel}; | 5 | use pac::adc::vals::{Adcaldif, Boost, Difsel, Exten, Pcsel}; |
| 9 | use pac::adccommon::vals::Presc; | 6 | use pac::adccommon::vals::Presc; |
| 10 | 7 | ||
| 11 | use crate::pac; | ||
| 12 | |||
| 13 | use super::{AdcPin, Instance}; | 8 | use super::{AdcPin, Instance}; |
| 9 | use crate::time::{Hertz, U32Ext}; | ||
| 10 | use crate::{pac, Unborrow}; | ||
| 14 | 11 | ||
| 15 | pub enum Resolution { | 12 | pub enum Resolution { |
| 16 | SixteenBit, | 13 | SixteenBit, |
| @@ -333,9 +330,7 @@ impl<'d, T: Instance + crate::rcc::RccPeripheral> Adc<'d, T> { | |||
| 333 | let prescaler = Prescaler::from_ker_ck(T::frequency()); | 330 | let prescaler = Prescaler::from_ker_ck(T::frequency()); |
| 334 | 331 | ||
| 335 | unsafe { | 332 | unsafe { |
| 336 | T::common_regs() | 333 | T::common_regs().ccr().modify(|w| w.set_presc(prescaler.presc())); |
| 337 | .ccr() | ||
| 338 | .modify(|w| w.set_presc(prescaler.presc())); | ||
| 339 | } | 334 | } |
| 340 | 335 | ||
| 341 | let frequency = Hertz(T::frequency().0 / prescaler.divisor()); | 336 | let frequency = Hertz(T::frequency().0 / prescaler.divisor()); |
| @@ -509,9 +504,7 @@ impl<'d, T: Instance + crate::rcc::RccPeripheral> Adc<'d, T> { | |||
| 509 | 504 | ||
| 510 | unsafe fn read_channel(&mut self, channel: u8) -> u16 { | 505 | unsafe fn read_channel(&mut self, channel: u8) -> u16 { |
| 511 | // Configure ADC | 506 | // Configure ADC |
| 512 | T::regs() | 507 | T::regs().cfgr().modify(|reg| reg.set_res(self.resolution.res())); |
| 513 | .cfgr() | ||
| 514 | .modify(|reg| reg.set_res(self.resolution.res())); | ||
| 515 | 508 | ||
| 516 | // Configure channel | 509 | // Configure channel |
| 517 | Self::set_channel_sample_time(channel, self.sample_time); | 510 | Self::set_channel_sample_time(channel, self.sample_time); |
diff --git a/embassy-stm32/src/can/bxcan.rs b/embassy-stm32/src/can/bxcan.rs index 0922d4d65..b54fd3ff3 100644 --- a/embassy-stm32/src/can/bxcan.rs +++ b/embassy-stm32/src/can/bxcan.rs | |||
| @@ -1,13 +1,12 @@ | |||
| 1 | use core::marker::PhantomData; | 1 | use core::marker::PhantomData; |
| 2 | use core::ops::{Deref, DerefMut}; | 2 | use core::ops::{Deref, DerefMut}; |
| 3 | 3 | ||
| 4 | use crate::Unborrow; | 4 | pub use bxcan; |
| 5 | use embassy_hal_common::unborrow; | 5 | use embassy_hal_common::unborrow; |
| 6 | 6 | ||
| 7 | use crate::gpio::sealed::AFType; | 7 | use crate::gpio::sealed::AFType; |
| 8 | use crate::{peripherals, rcc::RccPeripheral}; | 8 | use crate::rcc::RccPeripheral; |
| 9 | 9 | use crate::{peripherals, Unborrow}; | |
| 10 | pub use bxcan; | ||
| 11 | 10 | ||
| 12 | pub struct Can<'d, T: Instance + bxcan::Instance> { | 11 | pub struct Can<'d, T: Instance + bxcan::Instance> { |
| 13 | phantom: PhantomData<&'d mut T>, | 12 | phantom: PhantomData<&'d mut T>, |
diff --git a/embassy-stm32/src/crc/v1.rs b/embassy-stm32/src/crc/v1.rs index 1ab4530b9..87133714c 100644 --- a/embassy-stm32/src/crc/v1.rs +++ b/embassy-stm32/src/crc/v1.rs | |||
| @@ -1,10 +1,11 @@ | |||
| 1 | use core::marker::PhantomData; | 1 | use core::marker::PhantomData; |
| 2 | 2 | ||
| 3 | use embassy_hal_common::unborrow; | ||
| 4 | |||
| 3 | use crate::pac::CRC as PAC_CRC; | 5 | use crate::pac::CRC as PAC_CRC; |
| 4 | use crate::peripherals::CRC; | 6 | use crate::peripherals::CRC; |
| 5 | use crate::rcc::sealed::RccPeripheral; | 7 | use crate::rcc::sealed::RccPeripheral; |
| 6 | use crate::Unborrow; | 8 | use crate::Unborrow; |
| 7 | use embassy_hal_common::unborrow; | ||
| 8 | 9 | ||
| 9 | pub struct Crc<'d> { | 10 | pub struct Crc<'d> { |
| 10 | _peripheral: CRC, | 11 | _peripheral: CRC, |
diff --git a/embassy-stm32/src/crc/v2v3.rs b/embassy-stm32/src/crc/v2v3.rs index b6645c67f..63f24e4e1 100644 --- a/embassy-stm32/src/crc/v2v3.rs +++ b/embassy-stm32/src/crc/v2v3.rs | |||
| @@ -1,11 +1,12 @@ | |||
| 1 | use core::marker::PhantomData; | 1 | use core::marker::PhantomData; |
| 2 | 2 | ||
| 3 | use embassy_hal_common::unborrow; | ||
| 4 | |||
| 3 | use crate::pac::crc::vals; | 5 | use crate::pac::crc::vals; |
| 4 | use crate::pac::CRC as PAC_CRC; | 6 | use crate::pac::CRC as PAC_CRC; |
| 5 | use crate::peripherals::CRC; | 7 | use crate::peripherals::CRC; |
| 6 | use crate::rcc::sealed::RccPeripheral; | 8 | use crate::rcc::sealed::RccPeripheral; |
| 7 | use crate::Unborrow; | 9 | use crate::Unborrow; |
| 8 | use embassy_hal_common::unborrow; | ||
| 9 | 10 | ||
| 10 | pub struct Crc<'d> { | 11 | pub struct Crc<'d> { |
| 11 | _peripheral: CRC, | 12 | _peripheral: CRC, |
diff --git a/embassy-stm32/src/dac/mod.rs b/embassy-stm32/src/dac/mod.rs index 1f6ba63df..f1cb452c7 100644 --- a/embassy-stm32/src/dac/mod.rs +++ b/embassy-stm32/src/dac/mod.rs | |||
| @@ -3,9 +3,10 @@ | |||
| 3 | #[cfg_attr(dac_v1, path = "v1.rs")] | 3 | #[cfg_attr(dac_v1, path = "v1.rs")] |
| 4 | #[cfg_attr(dac_v2, path = "v2.rs")] | 4 | #[cfg_attr(dac_v2, path = "v2.rs")] |
| 5 | mod _version; | 5 | mod _version; |
| 6 | use crate::peripherals; | ||
| 7 | pub use _version::*; | 6 | pub use _version::*; |
| 8 | 7 | ||
| 8 | use crate::peripherals; | ||
| 9 | |||
| 9 | pub(crate) mod sealed { | 10 | pub(crate) mod sealed { |
| 10 | pub trait Instance { | 11 | pub trait Instance { |
| 11 | fn regs() -> &'static crate::pac::dac::Dac; | 12 | fn regs() -> &'static crate::pac::dac::Dac; |
diff --git a/embassy-stm32/src/dac/v2.rs b/embassy-stm32/src/dac/v2.rs index 0b421cc88..ba7856a5a 100644 --- a/embassy-stm32/src/dac/v2.rs +++ b/embassy-stm32/src/dac/v2.rs | |||
| @@ -1,8 +1,10 @@ | |||
| 1 | use core::marker::PhantomData; | ||
| 2 | |||
| 3 | use embassy_hal_common::unborrow; | ||
| 4 | |||
| 1 | use crate::dac::{DacPin, Instance}; | 5 | use crate::dac::{DacPin, Instance}; |
| 2 | use crate::pac::dac; | 6 | use crate::pac::dac; |
| 3 | use crate::Unborrow; | 7 | use crate::Unborrow; |
| 4 | use core::marker::PhantomData; | ||
| 5 | use embassy_hal_common::unborrow; | ||
| 6 | 8 | ||
| 7 | #[derive(Debug, Copy, Clone, Eq, PartialEq)] | 9 | #[derive(Debug, Copy, Clone, Eq, PartialEq)] |
| 8 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | 10 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] |
| @@ -93,23 +95,14 @@ pub struct Dac<'d, T: Instance> { | |||
| 93 | 95 | ||
| 94 | macro_rules! enable { | 96 | macro_rules! enable { |
| 95 | ($enable_reg:ident, $enable_field:ident, $reset_reg:ident, $reset_field:ident) => { | 97 | ($enable_reg:ident, $enable_field:ident, $reset_reg:ident, $reset_field:ident) => { |
| 96 | crate::pac::RCC | 98 | crate::pac::RCC.$enable_reg().modify(|w| w.$enable_field(true)); |
| 97 | .$enable_reg() | 99 | crate::pac::RCC.$reset_reg().modify(|w| w.$reset_field(true)); |
| 98 | .modify(|w| w.$enable_field(true)); | 100 | crate::pac::RCC.$reset_reg().modify(|w| w.$reset_field(false)); |
| 99 | crate::pac::RCC | ||
| 100 | .$reset_reg() | ||
| 101 | .modify(|w| w.$reset_field(true)); | ||
| 102 | crate::pac::RCC | ||
| 103 | .$reset_reg() | ||
| 104 | .modify(|w| w.$reset_field(false)); | ||
| 105 | }; | 101 | }; |
| 106 | } | 102 | } |
| 107 | 103 | ||
| 108 | impl<'d, T: Instance> Dac<'d, T> { | 104 | impl<'d, T: Instance> Dac<'d, T> { |
| 109 | pub fn new_1ch( | 105 | pub fn new_1ch(peri: impl Unborrow<Target = T> + 'd, _ch1: impl Unborrow<Target = impl DacPin<T, 1>> + 'd) -> Self { |
| 110 | peri: impl Unborrow<Target = T> + 'd, | ||
| 111 | _ch1: impl Unborrow<Target = impl DacPin<T, 1>> + 'd, | ||
| 112 | ) -> Self { | ||
| 113 | unborrow!(peri); | 106 | unborrow!(peri); |
| 114 | Self::new_inner(peri, 1) | 107 | Self::new_inner(peri, 1) |
| 115 | } | 108 | } |
diff --git a/embassy-stm32/src/dcmi.rs b/embassy-stm32/src/dcmi.rs index 8a28ca4b2..f4ca93a71 100644 --- a/embassy-stm32/src/dcmi.rs +++ b/embassy-stm32/src/dcmi.rs | |||
| @@ -1,13 +1,14 @@ | |||
| 1 | use core::marker::PhantomData; | 1 | use core::marker::PhantomData; |
| 2 | use core::task::Poll; | 2 | use core::task::Poll; |
| 3 | 3 | ||
| 4 | use crate::interrupt::{Interrupt, InterruptExt}; | ||
| 5 | use crate::Unborrow; | ||
| 6 | use embassy::waitqueue::AtomicWaker; | 4 | use embassy::waitqueue::AtomicWaker; |
| 7 | use embassy_hal_common::unborrow; | 5 | use embassy_hal_common::unborrow; |
| 8 | use futures::future::poll_fn; | 6 | use futures::future::poll_fn; |
| 9 | 7 | ||
| 10 | use crate::gpio::{sealed::AFType, Speed}; | 8 | use crate::gpio::sealed::AFType; |
| 9 | use crate::gpio::Speed; | ||
| 10 | use crate::interrupt::{Interrupt, InterruptExt}; | ||
| 11 | use crate::Unborrow; | ||
| 11 | 12 | ||
| 12 | /// The level on the VSync pin when the data is not valid on the parallel interface. | 13 | /// The level on the VSync pin when the data is not valid on the parallel interface. |
| 13 | #[derive(Clone, Copy, PartialEq)] | 14 | #[derive(Clone, Copy, PartialEq)] |
| @@ -466,14 +467,7 @@ where | |||
| 466 | let src = r.dr().ptr() as *mut u32; | 467 | let src = r.dr().ptr() as *mut u32; |
| 467 | 468 | ||
| 468 | unsafe { | 469 | unsafe { |
| 469 | channel.start_double_buffered_read( | 470 | channel.start_double_buffered_read(request, src, m0ar, m1ar, chunk_size, TransferOptions::default()); |
| 470 | request, | ||
| 471 | src, | ||
| 472 | m0ar, | ||
| 473 | m1ar, | ||
| 474 | chunk_size, | ||
| 475 | TransferOptions::default(), | ||
| 476 | ); | ||
| 477 | } | 471 | } |
| 478 | 472 | ||
| 479 | let mut last_chunk_set_for_transfer = false; | 473 | let mut last_chunk_set_for_transfer = false; |
diff --git a/embassy-stm32/src/dma/bdma.rs b/embassy-stm32/src/dma/bdma.rs index b17d22953..c87f3ac49 100644 --- a/embassy-stm32/src/dma/bdma.rs +++ b/embassy-stm32/src/dma/bdma.rs | |||
| @@ -3,16 +3,15 @@ | |||
| 3 | use core::sync::atomic::{fence, Ordering}; | 3 | use core::sync::atomic::{fence, Ordering}; |
| 4 | use core::task::Waker; | 4 | use core::task::Waker; |
| 5 | 5 | ||
| 6 | use crate::interrupt::{Interrupt, InterruptExt}; | ||
| 7 | use embassy::waitqueue::AtomicWaker; | 6 | use embassy::waitqueue::AtomicWaker; |
| 8 | 7 | ||
| 8 | use super::{TransferOptions, Word, WordSize}; | ||
| 9 | use crate::_generated::BDMA_CHANNEL_COUNT; | 9 | use crate::_generated::BDMA_CHANNEL_COUNT; |
| 10 | use crate::dma::Request; | 10 | use crate::dma::Request; |
| 11 | use crate::interrupt::{Interrupt, InterruptExt}; | ||
| 11 | use crate::pac; | 12 | use crate::pac; |
| 12 | use crate::pac::bdma::vals; | 13 | use crate::pac::bdma::vals; |
| 13 | 14 | ||
| 14 | use super::{TransferOptions, Word, WordSize}; | ||
| 15 | |||
| 16 | impl From<WordSize> for vals::Size { | 15 | impl From<WordSize> for vals::Size { |
| 17 | fn from(raw: WordSize) -> Self { | 16 | fn from(raw: WordSize) -> Self { |
| 18 | match raw { | 17 | match raw { |
| @@ -185,14 +184,8 @@ mod low_level_api { | |||
| 185 | #[cfg(dmamux)] dmamux_regs: pac::dmamux::Dmamux, | 184 | #[cfg(dmamux)] dmamux_regs: pac::dmamux::Dmamux, |
| 186 | #[cfg(dmamux)] dmamux_ch_num: u8, | 185 | #[cfg(dmamux)] dmamux_ch_num: u8, |
| 187 | ) { | 186 | ) { |
| 188 | assert!( | 187 | assert!(options.mburst == crate::dma::Burst::Single, "Burst mode not supported"); |
| 189 | options.mburst == crate::dma::Burst::Single, | 188 | assert!(options.pburst == crate::dma::Burst::Single, "Burst mode not supported"); |
| 190 | "Burst mode not supported" | ||
| 191 | ); | ||
| 192 | assert!( | ||
| 193 | options.pburst == crate::dma::Burst::Single, | ||
| 194 | "Burst mode not supported" | ||
| 195 | ); | ||
| 196 | assert!( | 189 | assert!( |
| 197 | options.flow_ctrl == crate::dma::FlowControl::Dma, | 190 | options.flow_ctrl == crate::dma::FlowControl::Dma, |
| 198 | "Peripheral flow control not supported" | 191 | "Peripheral flow control not supported" |
| @@ -206,10 +199,7 @@ mod low_level_api { | |||
| 206 | super::super::dmamux::configure_dmamux(dmamux_regs, dmamux_ch_num, request); | 199 | super::super::dmamux::configure_dmamux(dmamux_regs, dmamux_ch_num, request); |
| 207 | 200 | ||
| 208 | #[cfg(bdma_v2)] | 201 | #[cfg(bdma_v2)] |
| 209 | critical_section::with(|_| { | 202 | critical_section::with(|_| dma.cselr().modify(|w| w.set_cs(channel_number as _, request))); |
| 210 | dma.cselr() | ||
| 211 | .modify(|w| w.set_cs(channel_number as _, request)) | ||
| 212 | }); | ||
| 213 | 203 | ||
| 214 | // "Preceding reads and writes cannot be moved past subsequent writes." | 204 | // "Preceding reads and writes cannot be moved past subsequent writes." |
| 215 | fence(Ordering::SeqCst); | 205 | fence(Ordering::SeqCst); |
| @@ -279,10 +269,7 @@ mod low_level_api { | |||
| 279 | let cr = dma.ch(channel_num).cr(); | 269 | let cr = dma.ch(channel_num).cr(); |
| 280 | 270 | ||
| 281 | if isr.teif(channel_num) { | 271 | if isr.teif(channel_num) { |
| 282 | panic!( | 272 | panic!("DMA: error on BDMA@{:08x} channel {}", dma.0 as u32, channel_num); |
| 283 | "DMA: error on BDMA@{:08x} channel {}", | ||
| 284 | dma.0 as u32, channel_num | ||
| 285 | ); | ||
| 286 | } | 273 | } |
| 287 | if isr.tcif(channel_num) && cr.read().tcie() { | 274 | if isr.tcif(channel_num) && cr.read().tcie() { |
| 288 | cr.write(|_| ()); // Disable channel interrupts with the default value. | 275 | cr.write(|_| ()); // Disable channel interrupts with the default value. |
diff --git a/embassy-stm32/src/dma/dma.rs b/embassy-stm32/src/dma/dma.rs index 04cde7b4b..e8e589de8 100644 --- a/embassy-stm32/src/dma/dma.rs +++ b/embassy-stm32/src/dma/dma.rs | |||
| @@ -1,15 +1,13 @@ | |||
| 1 | use core::sync::atomic::{fence, Ordering}; | 1 | use core::sync::atomic::{fence, Ordering}; |
| 2 | use core::task::Waker; | 2 | use core::task::Waker; |
| 3 | 3 | ||
| 4 | use crate::interrupt::{Interrupt, InterruptExt}; | ||
| 5 | use embassy::waitqueue::AtomicWaker; | 4 | use embassy::waitqueue::AtomicWaker; |
| 6 | 5 | ||
| 6 | use super::{Burst, FlowControl, Request, TransferOptions, Word, WordSize}; | ||
| 7 | use crate::_generated::DMA_CHANNEL_COUNT; | 7 | use crate::_generated::DMA_CHANNEL_COUNT; |
| 8 | use crate::interrupt; | 8 | use crate::interrupt::{Interrupt, InterruptExt}; |
| 9 | use crate::pac; | ||
| 10 | use crate::pac::dma::{regs, vals}; | 9 | use crate::pac::dma::{regs, vals}; |
| 11 | 10 | use crate::{interrupt, pac}; | |
| 12 | use super::{Burst, FlowControl, Request, TransferOptions, Word, WordSize}; | ||
| 13 | 11 | ||
| 14 | impl From<WordSize> for vals::Size { | 12 | impl From<WordSize> for vals::Size { |
| 15 | fn from(raw: WordSize) -> Self { | 13 | fn from(raw: WordSize) -> Self { |
| @@ -407,10 +405,7 @@ mod low_level_api { | |||
| 407 | let isr = dma.isr(channel_num / 4).read(); | 405 | let isr = dma.isr(channel_num / 4).read(); |
| 408 | 406 | ||
| 409 | if isr.teif(channel_num % 4) { | 407 | if isr.teif(channel_num % 4) { |
| 410 | panic!( | 408 | panic!("DMA: error on DMA@{:08x} channel {}", dma.0 as u32, channel_num); |
| 411 | "DMA: error on DMA@{:08x} channel {}", | ||
| 412 | dma.0 as u32, channel_num | ||
| 413 | ); | ||
| 414 | } | 409 | } |
| 415 | 410 | ||
| 416 | if isr.tcif(channel_num % 4) && cr.read().tcie() { | 411 | if isr.tcif(channel_num % 4) && cr.read().tcie() { |
| @@ -418,8 +413,7 @@ mod low_level_api { | |||
| 418 | cr.write(|_| ()); // Disable channel with the default value. | 413 | cr.write(|_| ()); // Disable channel with the default value. |
| 419 | } else { | 414 | } else { |
| 420 | // for double buffered mode, clear TCIF flag but do not stop the transfer | 415 | // for double buffered mode, clear TCIF flag but do not stop the transfer |
| 421 | dma.ifcr(channel_num / 4) | 416 | dma.ifcr(channel_num / 4).write(|w| w.set_tcif(channel_num % 4, true)); |
| 422 | .write(|w| w.set_tcif(channel_num % 4, true)); | ||
| 423 | } | 417 | } |
| 424 | STATE.channels[state_index].waker.wake(); | 418 | STATE.channels[state_index].waker.wake(); |
| 425 | } | 419 | } |
diff --git a/embassy-stm32/src/dma/dmamux.rs b/embassy-stm32/src/dma/dmamux.rs index c45bebe26..e9967e349 100644 --- a/embassy-stm32/src/dma/dmamux.rs +++ b/embassy-stm32/src/dma/dmamux.rs | |||
| @@ -1,13 +1,8 @@ | |||
| 1 | #![macro_use] | 1 | #![macro_use] |
| 2 | 2 | ||
| 3 | use crate::pac; | 3 | use crate::{pac, peripherals}; |
| 4 | use crate::peripherals; | 4 | |
| 5 | 5 | pub(crate) unsafe fn configure_dmamux(dmamux_regs: pac::dmamux::Dmamux, dmamux_ch_num: u8, request: u8) { | |
| 6 | pub(crate) unsafe fn configure_dmamux( | ||
| 7 | dmamux_regs: pac::dmamux::Dmamux, | ||
| 8 | dmamux_ch_num: u8, | ||
| 9 | request: u8, | ||
| 10 | ) { | ||
| 11 | let ch_mux_regs = dmamux_regs.ccr(dmamux_ch_num as _); | 6 | let ch_mux_regs = dmamux_regs.ccr(dmamux_ch_num as _); |
| 12 | ch_mux_regs.write(|reg| { | 7 | ch_mux_regs.write(|reg| { |
| 13 | reg.set_nbreq(0); | 8 | reg.set_nbreq(0); |
diff --git a/embassy-stm32/src/dma/gpdma.rs b/embassy-stm32/src/dma/gpdma.rs index b054f95cc..8e901d725 100644 --- a/embassy-stm32/src/dma/gpdma.rs +++ b/embassy-stm32/src/dma/gpdma.rs | |||
| @@ -1,15 +1,13 @@ | |||
| 1 | use core::sync::atomic::{fence, Ordering}; | 1 | use core::sync::atomic::{fence, Ordering}; |
| 2 | use core::task::Waker; | 2 | use core::task::Waker; |
| 3 | 3 | ||
| 4 | use crate::interrupt::{Interrupt, InterruptExt}; | ||
| 5 | use embassy::waitqueue::AtomicWaker; | 4 | use embassy::waitqueue::AtomicWaker; |
| 6 | 5 | ||
| 6 | use super::{Request, TransferOptions, Word, WordSize}; | ||
| 7 | use crate::_generated::GPDMA_CHANNEL_COUNT; | 7 | use crate::_generated::GPDMA_CHANNEL_COUNT; |
| 8 | use crate::interrupt; | 8 | use crate::interrupt::{Interrupt, InterruptExt}; |
| 9 | use crate::pac; | ||
| 10 | use crate::pac::gpdma::{vals, Gpdma}; | 9 | use crate::pac::gpdma::{vals, Gpdma}; |
| 11 | 10 | use crate::{interrupt, pac}; | |
| 12 | use super::{Request, TransferOptions, Word, WordSize}; | ||
| 13 | 11 | ||
| 14 | impl From<WordSize> for vals::ChTr1Dw { | 12 | impl From<WordSize> for vals::ChTr1Dw { |
| 15 | fn from(raw: WordSize) -> Self { | 13 | fn from(raw: WordSize) -> Self { |
diff --git a/embassy-stm32/src/dma/mod.rs b/embassy-stm32/src/dma/mod.rs index 3a9097784..87ac38ba8 100644 --- a/embassy-stm32/src/dma/mod.rs +++ b/embassy-stm32/src/dma/mod.rs | |||
| @@ -7,18 +7,18 @@ mod dmamux; | |||
| 7 | #[cfg(gpdma)] | 7 | #[cfg(gpdma)] |
| 8 | mod gpdma; | 8 | mod gpdma; |
| 9 | 9 | ||
| 10 | #[cfg(dmamux)] | ||
| 11 | pub use dmamux::*; | ||
| 12 | |||
| 13 | use crate::Unborrow; | ||
| 14 | use core::future::Future; | 10 | use core::future::Future; |
| 15 | use core::marker::PhantomData; | 11 | use core::marker::PhantomData; |
| 16 | use core::mem; | 12 | use core::mem; |
| 17 | use core::pin::Pin; | 13 | use core::pin::Pin; |
| 18 | use core::task::Waker; | 14 | use core::task::{Context, Poll, Waker}; |
| 19 | use core::task::{Context, Poll}; | 15 | |
| 16 | #[cfg(dmamux)] | ||
| 17 | pub use dmamux::*; | ||
| 20 | use embassy_hal_common::unborrow; | 18 | use embassy_hal_common::unborrow; |
| 21 | 19 | ||
| 20 | use crate::Unborrow; | ||
| 21 | |||
| 22 | #[cfg(feature = "unstable-pac")] | 22 | #[cfg(feature = "unstable-pac")] |
| 23 | pub mod low_level { | 23 | pub mod low_level { |
| 24 | pub use super::transfers::*; | 24 | pub use super::transfers::*; |
| @@ -249,15 +249,7 @@ mod transfers { | |||
| 249 | ) -> impl Future<Output = ()> + 'a { | 249 | ) -> impl Future<Output = ()> + 'a { |
| 250 | unborrow!(channel); | 250 | unborrow!(channel); |
| 251 | 251 | ||
| 252 | unsafe { | 252 | unsafe { channel.start_write_repeated::<W>(request, repeated, count, reg_addr, Default::default()) }; |
| 253 | channel.start_write_repeated::<W>( | ||
| 254 | request, | ||
| 255 | repeated, | ||
| 256 | count, | ||
| 257 | reg_addr, | ||
| 258 | Default::default(), | ||
| 259 | ) | ||
| 260 | }; | ||
| 261 | 253 | ||
| 262 | Transfer::new(channel) | 254 | Transfer::new(channel) |
| 263 | } | 255 | } |
diff --git a/embassy-stm32/src/eth/generic_smi.rs b/embassy-stm32/src/eth/generic_smi.rs index 5a323bf5a..968256046 100644 --- a/embassy-stm32/src/eth/generic_smi.rs +++ b/embassy-stm32/src/eth/generic_smi.rs | |||
| @@ -51,10 +51,7 @@ unsafe impl PHY for GenericSMI { | |||
| 51 | Self::smi_write_ext(sm, PHY_REG_WUCSR, 0); | 51 | Self::smi_write_ext(sm, PHY_REG_WUCSR, 0); |
| 52 | 52 | ||
| 53 | // Enable auto-negotiation | 53 | // Enable auto-negotiation |
| 54 | sm.smi_write( | 54 | sm.smi_write(PHY_REG_BCR, PHY_REG_BCR_AN | PHY_REG_BCR_ANRST | PHY_REG_BCR_100M); |
| 55 | PHY_REG_BCR, | ||
| 56 | PHY_REG_BCR_AN | PHY_REG_BCR_ANRST | PHY_REG_BCR_100M, | ||
| 57 | ); | ||
| 58 | } | 55 | } |
| 59 | 56 | ||
| 60 | fn poll_link<S: StationManagement>(sm: &mut S) -> bool { | 57 | fn poll_link<S: StationManagement>(sm: &mut S) -> bool { |
diff --git a/embassy-stm32/src/eth/v1/mod.rs b/embassy-stm32/src/eth/v1/mod.rs index d2cfb17c0..7985acc5a 100644 --- a/embassy-stm32/src/eth/v1/mod.rs +++ b/embassy-stm32/src/eth/v1/mod.rs | |||
| @@ -4,33 +4,30 @@ use core::marker::PhantomData; | |||
| 4 | use core::sync::atomic::{fence, Ordering}; | 4 | use core::sync::atomic::{fence, Ordering}; |
| 5 | use core::task::Waker; | 5 | use core::task::Waker; |
| 6 | 6 | ||
| 7 | use crate::Unborrow; | ||
| 8 | use embassy::waitqueue::AtomicWaker; | 7 | use embassy::waitqueue::AtomicWaker; |
| 9 | use embassy_cortex_m::peripheral::{PeripheralMutex, PeripheralState, StateStorage}; | 8 | use embassy_cortex_m::peripheral::{PeripheralMutex, PeripheralState, StateStorage}; |
| 10 | use embassy_hal_common::unborrow; | 9 | use embassy_hal_common::unborrow; |
| 11 | use embassy_net::{Device, DeviceCapabilities, LinkState, PacketBuf, MTU}; | 10 | use embassy_net::{Device, DeviceCapabilities, LinkState, PacketBuf, MTU}; |
| 12 | 11 | ||
| 13 | use crate::gpio::sealed::Pin as __GpioPin; | 12 | use crate::gpio::sealed::{AFType, Pin as __GpioPin}; |
| 14 | use crate::gpio::{sealed::AFType, AnyPin, Speed}; | 13 | use crate::gpio::{AnyPin, Speed}; |
| 15 | #[cfg(eth_v1a)] | 14 | #[cfg(eth_v1a)] |
| 16 | use crate::pac::AFIO; | 15 | use crate::pac::AFIO; |
| 17 | #[cfg(any(eth_v1b, eth_v1c))] | 16 | #[cfg(any(eth_v1b, eth_v1c))] |
| 18 | use crate::pac::SYSCFG; | 17 | use crate::pac::SYSCFG; |
| 19 | use crate::pac::{ETH, RCC}; | 18 | use crate::pac::{ETH, RCC}; |
| 19 | use crate::Unborrow; | ||
| 20 | 20 | ||
| 21 | mod descriptors; | 21 | mod descriptors; |
| 22 | mod rx_desc; | 22 | mod rx_desc; |
| 23 | mod tx_desc; | 23 | mod tx_desc; |
| 24 | 24 | ||
| 25 | use super::*; | ||
| 26 | use descriptors::DescriptorRing; | 25 | use descriptors::DescriptorRing; |
| 27 | use stm32_metapac::eth::vals::{ | 26 | use stm32_metapac::eth::vals::{Apcs, Cr, Dm, DmaomrSr, Fes, Ftf, Ifg, MbProgress, Mw, Pbl, Rsf, St, Tsf}; |
| 28 | Apcs, Cr, Dm, DmaomrSr, Fes, Ftf, Ifg, MbProgress, Mw, Pbl, Rsf, St, Tsf, | 27 | |
| 29 | }; | 28 | use super::*; |
| 30 | 29 | ||
| 31 | pub struct State<'d, T: Instance, const TX: usize, const RX: usize>( | 30 | pub struct State<'d, T: Instance, const TX: usize, const RX: usize>(StateStorage<Inner<'d, T, TX, RX>>); |
| 32 | StateStorage<Inner<'d, T, TX, RX>>, | ||
| 33 | ); | ||
| 34 | impl<'d, T: Instance, const TX: usize, const RX: usize> State<'d, T, TX, RX> { | 31 | impl<'d, T: Instance, const TX: usize, const RX: usize> State<'d, T, TX, RX> { |
| 35 | pub fn new() -> Self { | 32 | pub fn new() -> Self { |
| 36 | Self(StateStorage::new()) | 33 | Self(StateStorage::new()) |
| @@ -300,9 +297,7 @@ unsafe impl<'d, T: Instance, P: PHY, const TX: usize, const RX: usize> StationMa | |||
| 300 | } | 297 | } |
| 301 | } | 298 | } |
| 302 | 299 | ||
| 303 | impl<'d, T: Instance, P: PHY, const TX: usize, const RX: usize> Device | 300 | impl<'d, T: Instance, P: PHY, const TX: usize, const RX: usize> Device for Ethernet<'d, T, P, TX, RX> { |
| 304 | for Ethernet<'d, T, P, TX, RX> | ||
| 305 | { | ||
| 306 | fn is_transmit_ready(&mut self) -> bool { | 301 | fn is_transmit_ready(&mut self) -> bool { |
| 307 | self.state.with(|s| s.desc_ring.tx.available()) | 302 | self.state.with(|s| s.desc_ring.tx.available()) |
| 308 | } | 303 | } |
| @@ -339,9 +334,7 @@ impl<'d, T: Instance, P: PHY, const TX: usize, const RX: usize> Device | |||
| 339 | } | 334 | } |
| 340 | } | 335 | } |
| 341 | 336 | ||
| 342 | impl<'d, T: Instance, P: PHY, const TX: usize, const RX: usize> Drop | 337 | impl<'d, T: Instance, P: PHY, const TX: usize, const RX: usize> Drop for Ethernet<'d, T, P, TX, RX> { |
| 343 | for Ethernet<'d, T, P, TX, RX> | ||
| 344 | { | ||
| 345 | fn drop(&mut self) { | 338 | fn drop(&mut self) { |
| 346 | // NOTE(unsafe) We have `&mut self` and the interrupt doesn't use this registers | 339 | // NOTE(unsafe) We have `&mut self` and the interrupt doesn't use this registers |
| 347 | unsafe { | 340 | unsafe { |
diff --git a/embassy-stm32/src/eth/v1/rx_desc.rs b/embassy-stm32/src/eth/v1/rx_desc.rs index 6164f2975..d482590a1 100644 --- a/embassy-stm32/src/eth/v1/rx_desc.rs +++ b/embassy-stm32/src/eth/v1/rx_desc.rs | |||
| @@ -59,8 +59,7 @@ impl RDes { | |||
| 59 | // | 59 | // |
| 60 | // Contains first buffer of packet AND contains last buf of | 60 | // Contains first buffer of packet AND contains last buf of |
| 61 | // packet AND no errors | 61 | // packet AND no errors |
| 62 | (self.rdes0.get() & (RXDESC_0_ES | RXDESC_0_FS | RXDESC_0_LS)) | 62 | (self.rdes0.get() & (RXDESC_0_ES | RXDESC_0_FS | RXDESC_0_LS)) == (RXDESC_0_FS | RXDESC_0_LS) |
| 63 | == (RXDESC_0_FS | RXDESC_0_LS) | ||
| 64 | } | 63 | } |
| 65 | 64 | ||
| 66 | /// Return true if this RDes is not currently owned by the DMA | 65 | /// Return true if this RDes is not currently owned by the DMA |
| @@ -72,8 +71,7 @@ impl RDes { | |||
| 72 | /// Configures the reception buffer address and length and passed descriptor ownership to the DMA | 71 | /// Configures the reception buffer address and length and passed descriptor ownership to the DMA |
| 73 | #[inline(always)] | 72 | #[inline(always)] |
| 74 | pub fn set_ready(&mut self, buf_addr: u32, buf_len: usize) { | 73 | pub fn set_ready(&mut self, buf_addr: u32, buf_len: usize) { |
| 75 | self.rdes1 | 74 | self.rdes1.set(self.rdes1.get() | (buf_len as u32) & RXDESC_1_RBS_MASK); |
| 76 | .set(self.rdes1.get() | (buf_len as u32) & RXDESC_1_RBS_MASK); | ||
| 77 | self.rdes2.set(buf_addr); | 75 | self.rdes2.set(buf_addr); |
| 78 | 76 | ||
| 79 | // "Preceding reads and writes cannot be moved past subsequent writes." | 77 | // "Preceding reads and writes cannot be moved past subsequent writes." |
| @@ -220,11 +218,7 @@ impl<const N: usize> RDesRing<N> { | |||
| 220 | // We already have fences in `set_owned`, which is called in `setup` | 218 | // We already have fences in `set_owned`, which is called in `setup` |
| 221 | 219 | ||
| 222 | // Start receive | 220 | // Start receive |
| 223 | unsafe { | 221 | unsafe { ETH.ethernet_dma().dmaomr().modify(|w| w.set_sr(DmaomrSr::STARTED)) }; |
| 224 | ETH.ethernet_dma() | ||
| 225 | .dmaomr() | ||
| 226 | .modify(|w| w.set_sr(DmaomrSr::STARTED)) | ||
| 227 | }; | ||
| 228 | 222 | ||
| 229 | self.demand_poll(); | 223 | self.demand_poll(); |
| 230 | } | 224 | } |
diff --git a/embassy-stm32/src/eth/v1/tx_desc.rs b/embassy-stm32/src/eth/v1/tx_desc.rs index f253ab19a..f2889b550 100644 --- a/embassy-stm32/src/eth/v1/tx_desc.rs +++ b/embassy-stm32/src/eth/v1/tx_desc.rs | |||
| @@ -100,8 +100,7 @@ impl TDes { | |||
| 100 | // set up as a part fo the ring buffer - configures the tdes | 100 | // set up as a part fo the ring buffer - configures the tdes |
| 101 | pub fn setup(&mut self, next: Option<&Self>) { | 101 | pub fn setup(&mut self, next: Option<&Self>) { |
| 102 | // Defer this initialization to this function, so we can have `RingEntry` on bss. | 102 | // Defer this initialization to this function, so we can have `RingEntry` on bss. |
| 103 | self.tdes0 | 103 | self.tdes0.set(TXDESC_0_TCH | TXDESC_0_IOC | TXDESC_0_FS | TXDESC_0_LS); |
| 104 | .set(TXDESC_0_TCH | TXDESC_0_IOC | TXDESC_0_FS | TXDESC_0_LS); | ||
| 105 | match next { | 104 | match next { |
| 106 | Some(next) => self.set_buffer2(next as *const TDes as *const u8), | 105 | Some(next) => self.set_buffer2(next as *const TDes as *const u8), |
| 107 | None => { | 106 | None => { |
| @@ -169,11 +168,7 @@ impl<const N: usize> TDesRing<N> { | |||
| 169 | // volatiles | 168 | // volatiles |
| 170 | 169 | ||
| 171 | // Start transmission | 170 | // Start transmission |
| 172 | unsafe { | 171 | unsafe { ETH.ethernet_dma().dmaomr().modify(|w| w.set_st(St::STARTED)) }; |
| 173 | ETH.ethernet_dma() | ||
| 174 | .dmaomr() | ||
| 175 | .modify(|w| w.set_st(St::STARTED)) | ||
| 176 | }; | ||
| 177 | } | 172 | } |
| 178 | 173 | ||
| 179 | /// Return true if a TDes is available for use | 174 | /// Return true if a TDes is available for use |
diff --git a/embassy-stm32/src/eth/v2/descriptors.rs b/embassy-stm32/src/eth/v2/descriptors.rs index 23b11857c..c6c06a9ce 100644 --- a/embassy-stm32/src/eth/v2/descriptors.rs +++ b/embassy-stm32/src/eth/v2/descriptors.rs | |||
| @@ -101,11 +101,9 @@ impl<const N: usize> TDesRing<N> { | |||
| 101 | unsafe { | 101 | unsafe { |
| 102 | let dma = ETH.ethernet_dma(); | 102 | let dma = ETH.ethernet_dma(); |
| 103 | 103 | ||
| 104 | dma.dmactx_dlar() | 104 | dma.dmactx_dlar().write(|w| w.0 = &self.td as *const _ as u32); |
| 105 | .write(|w| w.0 = &self.td as *const _ as u32); | ||
| 106 | dma.dmactx_rlr().write(|w| w.set_tdrl((N as u16) - 1)); | 105 | dma.dmactx_rlr().write(|w| w.set_tdrl((N as u16) - 1)); |
| 107 | dma.dmactx_dtpr() | 106 | dma.dmactx_dtpr().write(|w| w.0 = &self.td[0] as *const _ as u32); |
| 108 | .write(|w| w.0 = &self.td[0] as *const _ as u32); | ||
| 109 | } | 107 | } |
| 110 | } | 108 | } |
| 111 | 109 | ||
| @@ -127,8 +125,7 @@ impl<const N: usize> TDesRing<N> { | |||
| 127 | 125 | ||
| 128 | // Read format | 126 | // Read format |
| 129 | td.tdes0.set(address); | 127 | td.tdes0.set(address); |
| 130 | td.tdes2 | 128 | td.tdes2.set(pkt_len as u32 & EMAC_TDES2_B1L | EMAC_TDES2_IOC); |
| 131 | .set(pkt_len as u32 & EMAC_TDES2_B1L | EMAC_TDES2_IOC); | ||
| 132 | 129 | ||
| 133 | // FD: Contains first buffer of packet | 130 | // FD: Contains first buffer of packet |
| 134 | // LD: Contains last buffer of packet | 131 | // LD: Contains last buffer of packet |
| @@ -225,8 +222,7 @@ impl RDes { | |||
| 225 | #[inline(always)] | 222 | #[inline(always)] |
| 226 | pub fn set_ready(&mut self, buf_addr: u32) { | 223 | pub fn set_ready(&mut self, buf_addr: u32) { |
| 227 | self.rdes0.set(buf_addr); | 224 | self.rdes0.set(buf_addr); |
| 228 | self.rdes3 | 225 | self.rdes3.set(EMAC_RDES3_BUF1V | EMAC_RDES3_IOC | EMAC_DES3_OWN); |
| 229 | .set(EMAC_RDES3_BUF1V | EMAC_RDES3_IOC | EMAC_DES3_OWN); | ||
| 230 | } | 226 | } |
| 231 | } | 227 | } |
| 232 | 228 | ||
diff --git a/embassy-stm32/src/eth/v2/mod.rs b/embassy-stm32/src/eth/v2/mod.rs index e438a7b5e..2b1caf992 100644 --- a/embassy-stm32/src/eth/v2/mod.rs +++ b/embassy-stm32/src/eth/v2/mod.rs | |||
| @@ -2,23 +2,22 @@ use core::marker::PhantomData; | |||
| 2 | use core::sync::atomic::{fence, Ordering}; | 2 | use core::sync::atomic::{fence, Ordering}; |
| 3 | use core::task::Waker; | 3 | use core::task::Waker; |
| 4 | 4 | ||
| 5 | use crate::Unborrow; | ||
| 6 | use embassy::waitqueue::AtomicWaker; | 5 | use embassy::waitqueue::AtomicWaker; |
| 7 | use embassy_cortex_m::peripheral::{PeripheralMutex, PeripheralState, StateStorage}; | 6 | use embassy_cortex_m::peripheral::{PeripheralMutex, PeripheralState, StateStorage}; |
| 8 | use embassy_hal_common::unborrow; | 7 | use embassy_hal_common::unborrow; |
| 9 | use embassy_net::{Device, DeviceCapabilities, LinkState, PacketBuf, MTU}; | 8 | use embassy_net::{Device, DeviceCapabilities, LinkState, PacketBuf, MTU}; |
| 10 | 9 | ||
| 11 | use crate::gpio::sealed::Pin as _; | 10 | use crate::gpio::sealed::{AFType, Pin as _}; |
| 12 | use crate::gpio::{sealed::AFType, AnyPin, Speed}; | 11 | use crate::gpio::{AnyPin, Speed}; |
| 13 | use crate::pac::{ETH, RCC, SYSCFG}; | 12 | use crate::pac::{ETH, RCC, SYSCFG}; |
| 13 | use crate::Unborrow; | ||
| 14 | 14 | ||
| 15 | mod descriptors; | 15 | mod descriptors; |
| 16 | use super::*; | ||
| 17 | use descriptors::DescriptorRing; | 16 | use descriptors::DescriptorRing; |
| 18 | 17 | ||
| 19 | pub struct State<'d, T: Instance, const TX: usize, const RX: usize>( | 18 | use super::*; |
| 20 | StateStorage<Inner<'d, T, TX, RX>>, | 19 | |
| 21 | ); | 20 | pub struct State<'d, T: Instance, const TX: usize, const RX: usize>(StateStorage<Inner<'d, T, TX, RX>>); |
| 22 | impl<'d, T: Instance, const TX: usize, const RX: usize> State<'d, T, TX, RX> { | 21 | impl<'d, T: Instance, const TX: usize, const RX: usize> State<'d, T, TX, RX> { |
| 23 | pub fn new() -> Self { | 22 | pub fn new() -> Self { |
| 24 | Self(StateStorage::new()) | 23 | Self(StateStorage::new()) |
| @@ -234,9 +233,7 @@ unsafe impl<'d, T: Instance, P: PHY, const TX: usize, const RX: usize> StationMa | |||
| 234 | } | 233 | } |
| 235 | } | 234 | } |
| 236 | 235 | ||
| 237 | impl<'d, T: Instance, P: PHY, const TX: usize, const RX: usize> Device | 236 | impl<'d, T: Instance, P: PHY, const TX: usize, const RX: usize> Device for Ethernet<'d, T, P, TX, RX> { |
| 238 | for Ethernet<'d, T, P, TX, RX> | ||
| 239 | { | ||
| 240 | fn is_transmit_ready(&mut self) -> bool { | 237 | fn is_transmit_ready(&mut self) -> bool { |
| 241 | self.state.with(|s| s.desc_ring.tx.available()) | 238 | self.state.with(|s| s.desc_ring.tx.available()) |
| 242 | } | 239 | } |
| @@ -273,9 +270,7 @@ impl<'d, T: Instance, P: PHY, const TX: usize, const RX: usize> Device | |||
| 273 | } | 270 | } |
| 274 | } | 271 | } |
| 275 | 272 | ||
| 276 | impl<'d, T: Instance, P: PHY, const TX: usize, const RX: usize> Drop | 273 | impl<'d, T: Instance, P: PHY, const TX: usize, const RX: usize> Drop for Ethernet<'d, T, P, TX, RX> { |
| 277 | for Ethernet<'d, T, P, TX, RX> | ||
| 278 | { | ||
| 279 | fn drop(&mut self) { | 274 | fn drop(&mut self) { |
| 280 | // NOTE(unsafe) We have `&mut self` and the interrupt doesn't use this registers | 275 | // NOTE(unsafe) We have `&mut self` and the interrupt doesn't use this registers |
| 281 | unsafe { | 276 | unsafe { |
diff --git a/embassy-stm32/src/exti.rs b/embassy-stm32/src/exti.rs index efe54e59a..378665b77 100644 --- a/embassy-stm32/src/exti.rs +++ b/embassy-stm32/src/exti.rs | |||
| @@ -1,17 +1,15 @@ | |||
| 1 | use crate::Unborrow; | ||
| 2 | use core::future::Future; | 1 | use core::future::Future; |
| 3 | use core::marker::PhantomData; | 2 | use core::marker::PhantomData; |
| 4 | use core::pin::Pin; | 3 | use core::pin::Pin; |
| 5 | use core::task::{Context, Poll}; | 4 | use core::task::{Context, Poll}; |
| 5 | |||
| 6 | use embassy::waitqueue::AtomicWaker; | 6 | use embassy::waitqueue::AtomicWaker; |
| 7 | use embassy_hal_common::unsafe_impl_unborrow; | 7 | use embassy_hal_common::unsafe_impl_unborrow; |
| 8 | 8 | ||
| 9 | use crate::gpio::{AnyPin, Input, Pin as GpioPin}; | 9 | use crate::gpio::{AnyPin, Input, Pin as GpioPin}; |
| 10 | use crate::interrupt; | ||
| 11 | use crate::pac; | ||
| 12 | use crate::pac::exti::regs::Lines; | 10 | use crate::pac::exti::regs::Lines; |
| 13 | use crate::pac::EXTI; | 11 | use crate::pac::EXTI; |
| 14 | use crate::peripherals; | 12 | use crate::{interrupt, pac, peripherals, Unborrow}; |
| 15 | 13 | ||
| 16 | const EXTI_COUNT: usize = 16; | 14 | const EXTI_COUNT: usize = 16; |
| 17 | const NEW_AW: AtomicWaker = AtomicWaker::new(); | 15 | const NEW_AW: AtomicWaker = AtomicWaker::new(); |
| @@ -130,9 +128,10 @@ impl<'d, T: GpioPin> ExtiInput<'d, T> { | |||
| 130 | } | 128 | } |
| 131 | 129 | ||
| 132 | mod eh02 { | 130 | mod eh02 { |
| 133 | use super::*; | ||
| 134 | use core::convert::Infallible; | 131 | use core::convert::Infallible; |
| 135 | 132 | ||
| 133 | use super::*; | ||
| 134 | |||
| 136 | impl<'d, T: GpioPin> embedded_hal_02::digital::v2::InputPin for ExtiInput<'d, T> { | 135 | impl<'d, T: GpioPin> embedded_hal_02::digital::v2::InputPin for ExtiInput<'d, T> { |
| 137 | type Error = Infallible; | 136 | type Error = Infallible; |
| 138 | 137 | ||
| @@ -148,9 +147,10 @@ mod eh02 { | |||
| 148 | 147 | ||
| 149 | #[cfg(feature = "unstable-traits")] | 148 | #[cfg(feature = "unstable-traits")] |
| 150 | mod eh1 { | 149 | mod eh1 { |
| 151 | use super::*; | ||
| 152 | use core::convert::Infallible; | 150 | use core::convert::Infallible; |
| 153 | 151 | ||
| 152 | use super::*; | ||
| 153 | |||
| 154 | impl<'d, T: GpioPin> embedded_hal_1::digital::ErrorType for ExtiInput<'d, T> { | 154 | impl<'d, T: GpioPin> embedded_hal_1::digital::ErrorType for ExtiInput<'d, T> { |
| 155 | type Error = Infallible; | 155 | type Error = Infallible; |
| 156 | } | 156 | } |
| @@ -212,9 +212,7 @@ impl<'a> ExtiInputFuture<'a> { | |||
| 212 | fn new(pin: u8, port: u8, rising: bool, falling: bool) -> Self { | 212 | fn new(pin: u8, port: u8, rising: bool, falling: bool) -> Self { |
| 213 | critical_section::with(|_| unsafe { | 213 | critical_section::with(|_| unsafe { |
| 214 | let pin = pin as usize; | 214 | let pin = pin as usize; |
| 215 | exticr_regs() | 215 | exticr_regs().exticr(pin / 4).modify(|w| w.set_exti(pin % 4, port)); |
| 216 | .exticr(pin / 4) | ||
| 217 | .modify(|w| w.set_exti(pin % 4, port)); | ||
| 218 | EXTI.rtsr(0).modify(|w| w.set_line(pin, rising)); | 216 | EXTI.rtsr(0).modify(|w| w.set_line(pin, rising)); |
| 219 | EXTI.ftsr(0).modify(|w| w.set_line(pin, falling)); | 217 | EXTI.ftsr(0).modify(|w| w.set_line(pin, falling)); |
| 220 | 218 | ||
| @@ -366,8 +364,7 @@ macro_rules! enable_irq { | |||
| 366 | 364 | ||
| 367 | /// safety: must be called only once | 365 | /// safety: must be called only once |
| 368 | pub(crate) unsafe fn init() { | 366 | pub(crate) unsafe fn init() { |
| 369 | use crate::interrupt::Interrupt; | 367 | use crate::interrupt::{Interrupt, InterruptExt}; |
| 370 | use crate::interrupt::InterruptExt; | ||
| 371 | 368 | ||
| 372 | foreach_exti_irq!(enable_irq); | 369 | foreach_exti_irq!(enable_irq); |
| 373 | 370 | ||
diff --git a/embassy-stm32/src/flash/f3.rs b/embassy-stm32/src/flash/f3.rs index a5dc8dd0a..1cb08ee1a 100644 --- a/embassy-stm32/src/flash/f3.rs +++ b/embassy-stm32/src/flash/f3.rs | |||
| @@ -20,10 +20,7 @@ pub(crate) unsafe fn blocking_write(offset: u32, buf: &[u8]) -> Result<(), Error | |||
| 20 | let mut ret: Result<(), Error> = Ok(()); | 20 | let mut ret: Result<(), Error> = Ok(()); |
| 21 | let mut offset = offset; | 21 | let mut offset = offset; |
| 22 | for chunk in buf.chunks(2) { | 22 | for chunk in buf.chunks(2) { |
| 23 | write_volatile( | 23 | write_volatile(offset as *mut u16, u16::from_le_bytes(chunk[0..2].try_into().unwrap())); |
| 24 | offset as *mut u16, | ||
| 25 | u16::from_le_bytes(chunk[0..2].try_into().unwrap()), | ||
| 26 | ); | ||
| 27 | offset += chunk.len() as u32; | 24 | offset += chunk.len() as u32; |
| 28 | 25 | ||
| 29 | ret = blocking_wait_ready(); | 26 | ret = blocking_wait_ready(); |
diff --git a/embassy-stm32/src/flash/f7.rs b/embassy-stm32/src/flash/f7.rs index 16316fd93..6d47b78a0 100644 --- a/embassy-stm32/src/flash/f7.rs +++ b/embassy-stm32/src/flash/f7.rs | |||
| @@ -26,10 +26,7 @@ pub(crate) unsafe fn blocking_write(offset: u32, buf: &[u8]) -> Result<(), Error | |||
| 26 | let mut offset = offset; | 26 | let mut offset = offset; |
| 27 | for chunk in buf.chunks(super::WRITE_SIZE) { | 27 | for chunk in buf.chunks(super::WRITE_SIZE) { |
| 28 | for val in chunk.chunks(4) { | 28 | for val in chunk.chunks(4) { |
| 29 | write_volatile( | 29 | write_volatile(offset as *mut u32, u32::from_le_bytes(val[0..4].try_into().unwrap())); |
| 30 | offset as *mut u32, | ||
| 31 | u32::from_le_bytes(val[0..4].try_into().unwrap()), | ||
| 32 | ); | ||
| 33 | offset += val.len() as u32; | 30 | offset += val.len() as u32; |
| 34 | 31 | ||
| 35 | // prevents parallelism errors | 32 | // prevents parallelism errors |
diff --git a/embassy-stm32/src/flash/h7.rs b/embassy-stm32/src/flash/h7.rs index afccffc4a..7ce0ac776 100644 --- a/embassy-stm32/src/flash/h7.rs +++ b/embassy-stm32/src/flash/h7.rs | |||
| @@ -28,8 +28,7 @@ pub(crate) unsafe fn unlock() { | |||
| 28 | } | 28 | } |
| 29 | 29 | ||
| 30 | pub(crate) unsafe fn blocking_write(offset: u32, buf: &[u8]) -> Result<(), Error> { | 30 | pub(crate) unsafe fn blocking_write(offset: u32, buf: &[u8]) -> Result<(), Error> { |
| 31 | let bank = if !is_dual_bank() || (offset - super::FLASH_BASE as u32) < SECOND_BANK_OFFSET as u32 | 31 | let bank = if !is_dual_bank() || (offset - super::FLASH_BASE as u32) < SECOND_BANK_OFFSET as u32 { |
| 32 | { | ||
| 33 | pac::FLASH.bank(0) | 32 | pac::FLASH.bank(0) |
| 34 | } else { | 33 | } else { |
| 35 | pac::FLASH.bank(1) | 34 | pac::FLASH.bank(1) |
| @@ -46,10 +45,7 @@ pub(crate) unsafe fn blocking_write(offset: u32, buf: &[u8]) -> Result<(), Error | |||
| 46 | 'outer: for chunk in buf.chunks(super::WRITE_SIZE) { | 45 | 'outer: for chunk in buf.chunks(super::WRITE_SIZE) { |
| 47 | for val in chunk.chunks(4) { | 46 | for val in chunk.chunks(4) { |
| 48 | trace!("Writing at {:x}", offset); | 47 | trace!("Writing at {:x}", offset); |
| 49 | write_volatile( | 48 | write_volatile(offset as *mut u32, u32::from_le_bytes(val[0..4].try_into().unwrap())); |
| 50 | offset as *mut u32, | ||
| 51 | u32::from_le_bytes(val[0..4].try_into().unwrap()), | ||
| 52 | ); | ||
| 53 | offset += val.len() as u32; | 49 | offset += val.len() as u32; |
| 54 | 50 | ||
| 55 | ret = blocking_wait_ready(bank); | 51 | ret = blocking_wait_ready(bank); |
diff --git a/embassy-stm32/src/flash/l.rs b/embassy-stm32/src/flash/l.rs index cad950e6f..5048a3314 100644 --- a/embassy-stm32/src/flash/l.rs +++ b/embassy-stm32/src/flash/l.rs | |||
| @@ -42,10 +42,7 @@ pub(crate) unsafe fn blocking_write(offset: u32, buf: &[u8]) -> Result<(), Error | |||
| 42 | let mut offset = offset; | 42 | let mut offset = offset; |
| 43 | for chunk in buf.chunks(super::WRITE_SIZE) { | 43 | for chunk in buf.chunks(super::WRITE_SIZE) { |
| 44 | for val in chunk.chunks(4) { | 44 | for val in chunk.chunks(4) { |
| 45 | write_volatile( | 45 | write_volatile(offset as *mut u32, u32::from_le_bytes(val[0..4].try_into().unwrap())); |
| 46 | offset as *mut u32, | ||
| 47 | u32::from_le_bytes(val[0..4].try_into().unwrap()), | ||
| 48 | ); | ||
| 49 | offset += val.len() as u32; | 46 | offset += val.len() as u32; |
| 50 | } | 47 | } |
| 51 | 48 | ||
| @@ -80,11 +77,7 @@ pub(crate) unsafe fn blocking_erase(from: u32, to: u32) -> Result<(), Error> { | |||
| 80 | let idx = (page - super::FLASH_BASE as u32) / super::ERASE_SIZE as u32; | 77 | let idx = (page - super::FLASH_BASE as u32) / super::ERASE_SIZE as u32; |
| 81 | 78 | ||
| 82 | #[cfg(flash_l4)] | 79 | #[cfg(flash_l4)] |
| 83 | let (idx, bank) = if idx > 255 { | 80 | let (idx, bank) = if idx > 255 { (idx - 256, true) } else { (idx, false) }; |
| 84 | (idx - 256, true) | ||
| 85 | } else { | ||
| 86 | (idx, false) | ||
| 87 | }; | ||
| 88 | 81 | ||
| 89 | pac::FLASH.cr().modify(|w| { | 82 | pac::FLASH.cr().modify(|w| { |
| 90 | w.set_per(true); | 83 | w.set_per(true); |
diff --git a/embassy-stm32/src/flash/mod.rs b/embassy-stm32/src/flash/mod.rs index 330e51421..31ca243a6 100644 --- a/embassy-stm32/src/flash/mod.rs +++ b/embassy-stm32/src/flash/mod.rs | |||
| @@ -1,17 +1,11 @@ | |||
| 1 | use crate::peripherals::FLASH; | ||
| 2 | use crate::Unborrow; | ||
| 3 | use core::marker::PhantomData; | 1 | use core::marker::PhantomData; |
| 4 | use embassy_hal_common::unborrow; | ||
| 5 | 2 | ||
| 6 | use embedded_storage::nor_flash::{ | 3 | use embassy_hal_common::unborrow; |
| 7 | ErrorType, NorFlash, NorFlashError, NorFlashErrorKind, ReadNorFlash, | 4 | use embedded_storage::nor_flash::{ErrorType, NorFlash, NorFlashError, NorFlashErrorKind, ReadNorFlash}; |
| 8 | }; | ||
| 9 | 5 | ||
| 10 | pub use crate::pac::ERASE_SIZE; | 6 | pub use crate::pac::{ERASE_SIZE, ERASE_VALUE, FLASH_BASE, FLASH_SIZE, WRITE_SIZE}; |
| 11 | pub use crate::pac::ERASE_VALUE; | 7 | use crate::peripherals::FLASH; |
| 12 | pub use crate::pac::FLASH_BASE; | 8 | use crate::Unborrow; |
| 13 | pub use crate::pac::FLASH_SIZE; | ||
| 14 | pub use crate::pac::WRITE_SIZE; | ||
| 15 | const FLASH_END: usize = FLASH_BASE + FLASH_SIZE; | 9 | const FLASH_END: usize = FLASH_BASE + FLASH_SIZE; |
| 16 | 10 | ||
| 17 | #[cfg_attr(any(flash_wl, flash_wb, flash_l0, flash_l1, flash_l4), path = "l.rs")] | 11 | #[cfg_attr(any(flash_wl, flash_wb, flash_l0, flash_l1, flash_l4), path = "l.rs")] |
diff --git a/embassy-stm32/src/fmc/mod.rs b/embassy-stm32/src/fmc/mod.rs index c227cfa17..4f8e467d0 100644 --- a/embassy-stm32/src/fmc/mod.rs +++ b/embassy-stm32/src/fmc/mod.rs | |||
| @@ -1,9 +1,10 @@ | |||
| 1 | use crate::Unborrow; | ||
| 2 | use core::marker::PhantomData; | 1 | use core::marker::PhantomData; |
| 2 | |||
| 3 | use embassy_hal_common::unborrow; | 3 | use embassy_hal_common::unborrow; |
| 4 | 4 | ||
| 5 | use crate::gpio::sealed::AFType; | 5 | use crate::gpio::sealed::AFType; |
| 6 | use crate::gpio::{Pull, Speed}; | 6 | use crate::gpio::{Pull, Speed}; |
| 7 | use crate::Unborrow; | ||
| 7 | 8 | ||
| 8 | mod pins; | 9 | mod pins; |
| 9 | pub use pins::*; | 10 | pub use pins::*; |
diff --git a/embassy-stm32/src/gpio.rs b/embassy-stm32/src/gpio.rs index 31f22e21b..6e445f8cd 100644 --- a/embassy-stm32/src/gpio.rs +++ b/embassy-stm32/src/gpio.rs | |||
| @@ -1,12 +1,11 @@ | |||
| 1 | #![macro_use] | 1 | #![macro_use] |
| 2 | use crate::Unborrow; | ||
| 3 | use core::convert::Infallible; | 2 | use core::convert::Infallible; |
| 4 | use core::marker::PhantomData; | 3 | use core::marker::PhantomData; |
| 4 | |||
| 5 | use embassy_hal_common::{unborrow, unsafe_impl_unborrow}; | 5 | use embassy_hal_common::{unborrow, unsafe_impl_unborrow}; |
| 6 | 6 | ||
| 7 | use crate::pac; | ||
| 8 | use crate::pac::gpio::{self, vals}; | 7 | use crate::pac::gpio::{self, vals}; |
| 9 | use crate::peripherals; | 8 | use crate::{pac, peripherals, Unborrow}; |
| 10 | 9 | ||
| 11 | /// Pull setting for an input. | 10 | /// Pull setting for an input. |
| 12 | #[derive(Debug, Eq, PartialEq)] | 11 | #[derive(Debug, Eq, PartialEq)] |
| @@ -138,8 +137,7 @@ impl<'d, T: Pin> Drop for Input<'d, T> { | |||
| 138 | #[cfg(gpio_v1)] | 137 | #[cfg(gpio_v1)] |
| 139 | { | 138 | { |
| 140 | let crlh = if n < 8 { 0 } else { 1 }; | 139 | let crlh = if n < 8 { 0 } else { 1 }; |
| 141 | r.cr(crlh) | 140 | r.cr(crlh).modify(|w| w.set_cnf_in(n % 8, vals::CnfIn::FLOATING)); |
| 142 | .modify(|w| w.set_cnf_in(n % 8, vals::CnfIn::FLOATING)); | ||
| 143 | } | 141 | } |
| 144 | #[cfg(gpio_v2)] | 142 | #[cfg(gpio_v2)] |
| 145 | r.pupdr().modify(|w| w.set_pupdr(n, vals::Pupdr::FLOATING)); | 143 | r.pupdr().modify(|w| w.set_pupdr(n, vals::Pupdr::FLOATING)); |
| @@ -264,12 +262,7 @@ pub struct OutputOpenDrain<'d, T: Pin> { | |||
| 264 | 262 | ||
| 265 | impl<'d, T: Pin> OutputOpenDrain<'d, T> { | 263 | impl<'d, T: Pin> OutputOpenDrain<'d, T> { |
| 266 | #[inline] | 264 | #[inline] |
| 267 | pub fn new( | 265 | pub fn new(pin: impl Unborrow<Target = T> + 'd, initial_output: Level, speed: Speed, pull: Pull) -> Self { |
| 268 | pin: impl Unborrow<Target = T> + 'd, | ||
| 269 | initial_output: Level, | ||
| 270 | speed: Speed, | ||
| 271 | pull: Pull, | ||
| 272 | ) -> Self { | ||
| 273 | unborrow!(pin); | 266 | unborrow!(pin); |
| 274 | 267 | ||
| 275 | match initial_output { | 268 | match initial_output { |
| @@ -289,8 +282,7 @@ impl<'d, T: Pin> OutputOpenDrain<'d, T> { | |||
| 289 | Pull::None => {} | 282 | Pull::None => {} |
| 290 | } | 283 | } |
| 291 | r.cr(crlh).modify(|w| w.set_mode(n % 8, speed.into())); | 284 | r.cr(crlh).modify(|w| w.set_mode(n % 8, speed.into())); |
| 292 | r.cr(crlh) | 285 | r.cr(crlh).modify(|w| w.set_cnf_out(n % 8, vals::CnfOut::OPENDRAIN)); |
| 293 | .modify(|w| w.set_cnf_out(n % 8, vals::CnfOut::OPENDRAIN)); | ||
| 294 | } | 286 | } |
| 295 | #[cfg(gpio_v2)] | 287 | #[cfg(gpio_v2)] |
| 296 | { | 288 | { |
| @@ -480,18 +472,12 @@ pub(crate) mod sealed { | |||
| 480 | block.afr(pin / 8).modify(|w| w.set_afr(pin % 8, af_num)); | 472 | block.afr(pin / 8).modify(|w| w.set_afr(pin % 8, af_num)); |
| 481 | match af_type { | 473 | match af_type { |
| 482 | AFType::Input => {} | 474 | AFType::Input => {} |
| 483 | AFType::OutputPushPull => { | 475 | AFType::OutputPushPull => block.otyper().modify(|w| w.set_ot(pin, vals::Ot::PUSHPULL)), |
| 484 | block.otyper().modify(|w| w.set_ot(pin, vals::Ot::PUSHPULL)) | 476 | AFType::OutputOpenDrain => block.otyper().modify(|w| w.set_ot(pin, vals::Ot::OPENDRAIN)), |
| 485 | } | ||
| 486 | AFType::OutputOpenDrain => block | ||
| 487 | .otyper() | ||
| 488 | .modify(|w| w.set_ot(pin, vals::Ot::OPENDRAIN)), | ||
| 489 | } | 477 | } |
| 490 | block.pupdr().modify(|w| w.set_pupdr(pin, pull.into())); | 478 | block.pupdr().modify(|w| w.set_pupdr(pin, pull.into())); |
| 491 | 479 | ||
| 492 | block | 480 | block.moder().modify(|w| w.set_moder(pin, vals::Moder::ALTERNATE)); |
| 493 | .moder() | ||
| 494 | .modify(|w| w.set_moder(pin, vals::Moder::ALTERNATE)); | ||
| 495 | } | 481 | } |
| 496 | 482 | ||
| 497 | #[inline] | 483 | #[inline] |
| @@ -507,9 +493,7 @@ pub(crate) mod sealed { | |||
| 507 | }); | 493 | }); |
| 508 | } | 494 | } |
| 509 | #[cfg(gpio_v2)] | 495 | #[cfg(gpio_v2)] |
| 510 | block | 496 | block.moder().modify(|w| w.set_moder(pin, vals::Moder::ANALOG)); |
| 511 | .moder() | ||
| 512 | .modify(|w| w.set_moder(pin, vals::Moder::ANALOG)); | ||
| 513 | } | 497 | } |
| 514 | 498 | ||
| 515 | /// Set the pin as "disconnected", ie doing nothing and consuming the lowest | 499 | /// Set the pin as "disconnected", ie doing nothing and consuming the lowest |
| @@ -535,9 +519,7 @@ pub(crate) mod sealed { | |||
| 535 | } | 519 | } |
| 536 | 520 | ||
| 537 | #[cfg(gpio_v2)] | 521 | #[cfg(gpio_v2)] |
| 538 | self.block() | 522 | self.block().ospeedr().modify(|w| w.set_ospeedr(pin, speed.into())); |
| 539 | .ospeedr() | ||
| 540 | .modify(|w| w.set_ospeedr(pin, speed.into())); | ||
| 541 | } | 523 | } |
| 542 | } | 524 | } |
| 543 | } | 525 | } |
| @@ -623,10 +605,9 @@ pub(crate) unsafe fn init() { | |||
| 623 | } | 605 | } |
| 624 | 606 | ||
| 625 | mod eh02 { | 607 | mod eh02 { |
| 608 | use embedded_hal_02::digital::v2::{InputPin, OutputPin, StatefulOutputPin, ToggleableOutputPin}; | ||
| 609 | |||
| 626 | use super::*; | 610 | use super::*; |
| 627 | use embedded_hal_02::digital::v2::{ | ||
| 628 | InputPin, OutputPin, StatefulOutputPin, ToggleableOutputPin, | ||
| 629 | }; | ||
| 630 | 611 | ||
| 631 | impl<'d, T: Pin> InputPin for Input<'d, T> { | 612 | impl<'d, T: Pin> InputPin for Input<'d, T> { |
| 632 | type Error = Infallible; | 613 | type Error = Infallible; |
| @@ -715,12 +696,11 @@ mod eh02 { | |||
| 715 | 696 | ||
| 716 | #[cfg(feature = "unstable-traits")] | 697 | #[cfg(feature = "unstable-traits")] |
| 717 | mod eh1 { | 698 | mod eh1 { |
| 718 | use super::*; | 699 | use embedded_hal_1::digital::blocking::{InputPin, OutputPin, StatefulOutputPin, ToggleableOutputPin}; |
| 719 | use embedded_hal_1::digital::blocking::{ | ||
| 720 | InputPin, OutputPin, StatefulOutputPin, ToggleableOutputPin, | ||
| 721 | }; | ||
| 722 | use embedded_hal_1::digital::ErrorType; | 700 | use embedded_hal_1::digital::ErrorType; |
| 723 | 701 | ||
| 702 | use super::*; | ||
| 703 | |||
| 724 | impl<'d, T: Pin> ErrorType for Input<'d, T> { | 704 | impl<'d, T: Pin> ErrorType for Input<'d, T> { |
| 725 | type Error = Infallible; | 705 | type Error = Infallible; |
| 726 | } | 706 | } |
diff --git a/embassy-stm32/src/i2c/mod.rs b/embassy-stm32/src/i2c/mod.rs index 54f8d1935..9d314f411 100644 --- a/embassy-stm32/src/i2c/mod.rs +++ b/embassy-stm32/src/i2c/mod.rs | |||
| @@ -5,9 +5,10 @@ use crate::interrupt::Interrupt; | |||
| 5 | #[cfg_attr(i2c_v1, path = "v1.rs")] | 5 | #[cfg_attr(i2c_v1, path = "v1.rs")] |
| 6 | #[cfg_attr(i2c_v2, path = "v2.rs")] | 6 | #[cfg_attr(i2c_v2, path = "v2.rs")] |
| 7 | mod _version; | 7 | mod _version; |
| 8 | use crate::peripherals; | ||
| 9 | pub use _version::*; | 8 | pub use _version::*; |
| 10 | 9 | ||
| 10 | use crate::peripherals; | ||
| 11 | |||
| 11 | #[derive(Debug)] | 12 | #[derive(Debug)] |
| 12 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | 13 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] |
| 13 | pub enum Error { | 14 | pub enum Error { |
diff --git a/embassy-stm32/src/i2c/v1.rs b/embassy-stm32/src/i2c/v1.rs index 77acc3870..87a4f9699 100644 --- a/embassy-stm32/src/i2c/v1.rs +++ b/embassy-stm32/src/i2c/v1.rs | |||
| @@ -1,11 +1,12 @@ | |||
| 1 | use crate::Unborrow; | ||
| 2 | use core::marker::PhantomData; | 1 | use core::marker::PhantomData; |
| 2 | |||
| 3 | use embassy_hal_common::unborrow; | 3 | use embassy_hal_common::unborrow; |
| 4 | 4 | ||
| 5 | use crate::gpio::sealed::AFType; | 5 | use crate::gpio::sealed::AFType; |
| 6 | use crate::i2c::{Error, Instance, SclPin, SdaPin}; | 6 | use crate::i2c::{Error, Instance, SclPin, SdaPin}; |
| 7 | use crate::pac::i2c; | 7 | use crate::pac::i2c; |
| 8 | use crate::time::Hertz; | 8 | use crate::time::Hertz; |
| 9 | use crate::Unborrow; | ||
| 9 | 10 | ||
| 10 | pub struct State {} | 11 | pub struct State {} |
| 11 | 12 | ||
| @@ -68,9 +69,7 @@ impl<'d, T: Instance> I2c<'d, T> { | |||
| 68 | }); | 69 | }); |
| 69 | } | 70 | } |
| 70 | 71 | ||
| 71 | Self { | 72 | Self { phantom: PhantomData } |
| 72 | phantom: PhantomData, | ||
| 73 | } | ||
| 74 | } | 73 | } |
| 75 | 74 | ||
| 76 | unsafe fn check_and_clear_error_flags(&self) -> Result<i2c::regs::Sr1, Error> { | 75 | unsafe fn check_and_clear_error_flags(&self) -> Result<i2c::regs::Sr1, Error> { |
| @@ -249,12 +248,7 @@ impl<'d, T: Instance> I2c<'d, T> { | |||
| 249 | Ok(()) | 248 | Ok(()) |
| 250 | } | 249 | } |
| 251 | 250 | ||
| 252 | pub fn blocking_write_read( | 251 | pub fn blocking_write_read(&mut self, addr: u8, bytes: &[u8], buffer: &mut [u8]) -> Result<(), Error> { |
| 253 | &mut self, | ||
| 254 | addr: u8, | ||
| 255 | bytes: &[u8], | ||
| 256 | buffer: &mut [u8], | ||
| 257 | ) -> Result<(), Error> { | ||
| 258 | unsafe { self.write_bytes(addr, bytes)? }; | 252 | unsafe { self.write_bytes(addr, bytes)? }; |
| 259 | self.blocking_read(addr, buffer)?; | 253 | self.blocking_read(addr, buffer)?; |
| 260 | 254 | ||
diff --git a/embassy-stm32/src/i2c/v2.rs b/embassy-stm32/src/i2c/v2.rs index 4d4840a0d..1a085e782 100644 --- a/embassy-stm32/src/i2c/v2.rs +++ b/embassy-stm32/src/i2c/v2.rs | |||
| @@ -2,8 +2,6 @@ use core::cmp; | |||
| 2 | use core::marker::PhantomData; | 2 | use core::marker::PhantomData; |
| 3 | use core::task::Poll; | 3 | use core::task::Poll; |
| 4 | 4 | ||
| 5 | use crate::interrupt::InterruptExt; | ||
| 6 | use crate::Unborrow; | ||
| 7 | use atomic_polyfill::{AtomicUsize, Ordering}; | 5 | use atomic_polyfill::{AtomicUsize, Ordering}; |
| 8 | use embassy::waitqueue::AtomicWaker; | 6 | use embassy::waitqueue::AtomicWaker; |
| 9 | use embassy_hal_common::drop::OnDrop; | 7 | use embassy_hal_common::drop::OnDrop; |
| @@ -13,8 +11,10 @@ use futures::future::poll_fn; | |||
| 13 | use crate::dma::NoDma; | 11 | use crate::dma::NoDma; |
| 14 | use crate::gpio::sealed::AFType; | 12 | use crate::gpio::sealed::AFType; |
| 15 | use crate::i2c::{Error, Instance, SclPin, SdaPin}; | 13 | use crate::i2c::{Error, Instance, SclPin, SdaPin}; |
| 14 | use crate::interrupt::InterruptExt; | ||
| 16 | use crate::pac::i2c; | 15 | use crate::pac::i2c; |
| 17 | use crate::time::Hertz; | 16 | use crate::time::Hertz; |
| 17 | use crate::Unborrow; | ||
| 18 | 18 | ||
| 19 | pub struct State { | 19 | pub struct State { |
| 20 | waker: AtomicWaker, | 20 | waker: AtomicWaker, |
| @@ -277,12 +277,7 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { | |||
| 277 | } | 277 | } |
| 278 | } | 278 | } |
| 279 | 279 | ||
| 280 | fn read_internal( | 280 | fn read_internal(&mut self, address: u8, buffer: &mut [u8], restart: bool) -> Result<(), Error> { |
| 281 | &mut self, | ||
| 282 | address: u8, | ||
| 283 | buffer: &mut [u8], | ||
| 284 | restart: bool, | ||
| 285 | ) -> Result<(), Error> { | ||
| 286 | let completed_chunks = buffer.len() / 255; | 281 | let completed_chunks = buffer.len() / 255; |
| 287 | let total_chunks = if completed_chunks * 255 == buffer.len() { | 282 | let total_chunks = if completed_chunks * 255 == buffer.len() { |
| 288 | completed_chunks | 283 | completed_chunks |
| @@ -335,12 +330,7 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { | |||
| 335 | // ST SAD+W | 330 | // ST SAD+W |
| 336 | // NOTE(unsafe) We have &mut self | 331 | // NOTE(unsafe) We have &mut self |
| 337 | unsafe { | 332 | unsafe { |
| 338 | Self::master_write( | 333 | Self::master_write(address, bytes.len().min(255), Stop::Software, last_chunk_idx != 0); |
| 339 | address, | ||
| 340 | bytes.len().min(255), | ||
| 341 | Stop::Software, | ||
| 342 | last_chunk_idx != 0, | ||
| 343 | ); | ||
| 344 | } | 334 | } |
| 345 | 335 | ||
| 346 | for (number, chunk) in bytes.chunks(255).enumerate() { | 336 | for (number, chunk) in bytes.chunks(255).enumerate() { |
| @@ -467,12 +457,7 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { | |||
| 467 | Ok(()) | 457 | Ok(()) |
| 468 | } | 458 | } |
| 469 | 459 | ||
| 470 | async fn read_dma_internal( | 460 | async fn read_dma_internal(&mut self, address: u8, buffer: &mut [u8], restart: bool) -> Result<(), Error> |
| 471 | &mut self, | ||
| 472 | address: u8, | ||
| 473 | buffer: &mut [u8], | ||
| 474 | restart: bool, | ||
| 475 | ) -> Result<(), Error> | ||
| 476 | where | 461 | where |
| 477 | RXDMA: crate::i2c::RxDma<T>, | 462 | RXDMA: crate::i2c::RxDma<T>, |
| 478 | { | 463 | { |
| @@ -513,13 +498,7 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { | |||
| 513 | 498 | ||
| 514 | // NOTE(unsafe) self.rx_dma does not fiddle with the i2c registers | 499 | // NOTE(unsafe) self.rx_dma does not fiddle with the i2c registers |
| 515 | unsafe { | 500 | unsafe { |
| 516 | Self::master_read( | 501 | Self::master_read(address, total_len.min(255), Stop::Software, total_chunks != 1, restart); |
| 517 | address, | ||
| 518 | total_len.min(255), | ||
| 519 | Stop::Software, | ||
| 520 | total_chunks != 1, | ||
| 521 | restart, | ||
| 522 | ); | ||
| 523 | } | 502 | } |
| 524 | 503 | ||
| 525 | poll_fn(|cx| { | 504 | poll_fn(|cx| { |
| @@ -597,12 +576,7 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { | |||
| 597 | } | 576 | } |
| 598 | } | 577 | } |
| 599 | 578 | ||
| 600 | pub async fn write_read( | 579 | pub async fn write_read(&mut self, address: u8, bytes: &[u8], buffer: &mut [u8]) -> Result<(), Error> |
| 601 | &mut self, | ||
| 602 | address: u8, | ||
| 603 | bytes: &[u8], | ||
| 604 | buffer: &mut [u8], | ||
| 605 | ) -> Result<(), Error> | ||
| 606 | where | 580 | where |
| 607 | TXDMA: super::TxDma<T>, | 581 | TXDMA: super::TxDma<T>, |
| 608 | RXDMA: super::RxDma<T>, | 582 | RXDMA: super::RxDma<T>, |
| @@ -634,12 +608,7 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { | |||
| 634 | self.write_internal(address, bytes, true) | 608 | self.write_internal(address, bytes, true) |
| 635 | } | 609 | } |
| 636 | 610 | ||
| 637 | pub fn blocking_write_read( | 611 | pub fn blocking_write_read(&mut self, address: u8, bytes: &[u8], buffer: &mut [u8]) -> Result<(), Error> { |
| 638 | &mut self, | ||
| 639 | address: u8, | ||
| 640 | bytes: &[u8], | ||
| 641 | buffer: &mut [u8], | ||
| 642 | ) -> Result<(), Error> { | ||
| 643 | self.write_internal(address, bytes, false)?; | 612 | self.write_internal(address, bytes, false)?; |
| 644 | self.read_internal(address, buffer, true) | 613 | self.read_internal(address, buffer, true) |
| 645 | // Automatic Stop | 614 | // Automatic Stop |
| @@ -675,10 +644,7 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { | |||
| 675 | if idx != 0 { | 644 | if idx != 0 { |
| 676 | // NOTE(unsafe) We have &mut self | 645 | // NOTE(unsafe) We have &mut self |
| 677 | unsafe { | 646 | unsafe { |
| 678 | Self::master_continue( | 647 | Self::master_continue(slice_len.min(255), (idx != last_slice_index) || (slice_len > 255)); |
| 679 | slice_len.min(255), | ||
| 680 | (idx != last_slice_index) || (slice_len > 255), | ||
| 681 | ); | ||
| 682 | } | 648 | } |
| 683 | } | 649 | } |
| 684 | 650 | ||
| @@ -686,10 +652,7 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { | |||
| 686 | if number != 0 { | 652 | if number != 0 { |
| 687 | // NOTE(unsafe) We have &mut self | 653 | // NOTE(unsafe) We have &mut self |
| 688 | unsafe { | 654 | unsafe { |
| 689 | Self::master_continue( | 655 | Self::master_continue(chunk.len(), (number != last_chunk_idx) || (idx != last_slice_index)); |
| 690 | chunk.len(), | ||
| 691 | (number != last_chunk_idx) || (idx != last_slice_index), | ||
| 692 | ); | ||
| 693 | } | 656 | } |
| 694 | } | 657 | } |
| 695 | 658 | ||
| @@ -737,12 +700,7 @@ mod eh02 { | |||
| 737 | impl<'d, T: Instance> embedded_hal_02::blocking::i2c::WriteRead for I2c<'d, T> { | 700 | impl<'d, T: Instance> embedded_hal_02::blocking::i2c::WriteRead for I2c<'d, T> { |
| 738 | type Error = Error; | 701 | type Error = Error; |
| 739 | 702 | ||
| 740 | fn write_read( | 703 | fn write_read(&mut self, address: u8, bytes: &[u8], buffer: &mut [u8]) -> Result<(), Self::Error> { |
| 741 | &mut self, | ||
| 742 | address: u8, | ||
| 743 | bytes: &[u8], | ||
| 744 | buffer: &mut [u8], | ||
| 745 | ) -> Result<(), Self::Error> { | ||
| 746 | self.blocking_write_read(address, bytes, buffer) | 704 | self.blocking_write_read(address, bytes, buffer) |
| 747 | } | 705 | } |
| 748 | } | 706 | } |
| @@ -794,10 +752,7 @@ impl Timings { | |||
| 794 | 752 | ||
| 795 | // For the standard-mode configuration method, we must have a ratio of 4 | 753 | // For the standard-mode configuration method, we must have a ratio of 4 |
| 796 | // or higher | 754 | // or higher |
| 797 | assert!( | 755 | assert!(ratio >= 4, "The I2C PCLK must be at least 4 times the bus frequency!"); |
| 798 | ratio >= 4, | ||
| 799 | "The I2C PCLK must be at least 4 times the bus frequency!" | ||
| 800 | ); | ||
| 801 | 756 | ||
| 802 | let (presc_reg, scll, sclh, sdadel, scldel) = if freq > 100_000 { | 757 | let (presc_reg, scll, sclh, sdadel, scldel) = if freq > 100_000 { |
| 803 | // Fast-mode (Fm) or Fast-mode Plus (Fm+) | 758 | // Fast-mode (Fm) or Fast-mode Plus (Fm+) |
| @@ -831,13 +786,7 @@ impl Timings { | |||
| 831 | (sdadel, scldel) | 786 | (sdadel, scldel) |
| 832 | }; | 787 | }; |
| 833 | 788 | ||
| 834 | ( | 789 | (presc_reg, scll as u8, sclh as u8, sdadel as u8, scldel as u8) |
| 835 | presc_reg, | ||
| 836 | scll as u8, | ||
| 837 | sclh as u8, | ||
| 838 | sdadel as u8, | ||
| 839 | scldel as u8, | ||
| 840 | ) | ||
| 841 | } else { | 790 | } else { |
| 842 | // Standard-mode (Sm) | 791 | // Standard-mode (Sm) |
| 843 | // here we pick SCLL = SCLH | 792 | // here we pick SCLL = SCLH |
| @@ -855,21 +804,12 @@ impl Timings { | |||
| 855 | let scll = sclh; | 804 | let scll = sclh; |
| 856 | 805 | ||
| 857 | // Speed check | 806 | // Speed check |
| 858 | assert!( | 807 | assert!(sclh < 256, "The I2C PCLK is too fast for this bus frequency!"); |
| 859 | sclh < 256, | ||
| 860 | "The I2C PCLK is too fast for this bus frequency!" | ||
| 861 | ); | ||
| 862 | 808 | ||
| 863 | let sdadel = i2cclk / 2_000_000 / presc; | 809 | let sdadel = i2cclk / 2_000_000 / presc; |
| 864 | let scldel = i2cclk / 500_000 / presc - 1; | 810 | let scldel = i2cclk / 500_000 / presc - 1; |
| 865 | 811 | ||
| 866 | ( | 812 | (presc_reg, scll as u8, sclh as u8, sdadel as u8, scldel as u8) |
| 867 | presc_reg, | ||
| 868 | scll as u8, | ||
| 869 | sclh as u8, | ||
| 870 | sdadel as u8, | ||
| 871 | scldel as u8, | ||
| 872 | ) | ||
| 873 | }; | 813 | }; |
| 874 | 814 | ||
| 875 | // Sanity check | 815 | // Sanity check |
| @@ -900,9 +840,9 @@ mod eh1 { | |||
| 900 | match *self { | 840 | match *self { |
| 901 | Self::Bus => embedded_hal_1::i2c::ErrorKind::Bus, | 841 | Self::Bus => embedded_hal_1::i2c::ErrorKind::Bus, |
| 902 | Self::Arbitration => embedded_hal_1::i2c::ErrorKind::ArbitrationLoss, | 842 | Self::Arbitration => embedded_hal_1::i2c::ErrorKind::ArbitrationLoss, |
| 903 | Self::Nack => embedded_hal_1::i2c::ErrorKind::NoAcknowledge( | 843 | Self::Nack => { |
| 904 | embedded_hal_1::i2c::NoAcknowledgeSource::Unknown, | 844 | embedded_hal_1::i2c::ErrorKind::NoAcknowledge(embedded_hal_1::i2c::NoAcknowledgeSource::Unknown) |
| 905 | ), | 845 | } |
| 906 | Self::Timeout => embedded_hal_1::i2c::ErrorKind::Other, | 846 | Self::Timeout => embedded_hal_1::i2c::ErrorKind::Other, |
| 907 | Self::Crc => embedded_hal_1::i2c::ErrorKind::Other, | 847 | Self::Crc => embedded_hal_1::i2c::ErrorKind::Other, |
| 908 | Self::Overrun => embedded_hal_1::i2c::ErrorKind::Overrun, | 848 | Self::Overrun => embedded_hal_1::i2c::ErrorKind::Overrun, |
| @@ -911,9 +851,7 @@ mod eh1 { | |||
| 911 | } | 851 | } |
| 912 | } | 852 | } |
| 913 | 853 | ||
| 914 | impl<'d, T: Instance, TXDMA: TxDma<T>, RXDMA: RxDma<T>> embedded_hal_1::i2c::ErrorType | 854 | impl<'d, T: Instance, TXDMA: TxDma<T>, RXDMA: RxDma<T>> embedded_hal_1::i2c::ErrorType for I2c<'d, T, TXDMA, RXDMA> { |
| 915 | for I2c<'d, T, TXDMA, RXDMA> | ||
| 916 | { | ||
| 917 | type Error = Error; | 855 | type Error = Error; |
| 918 | } | 856 | } |
| 919 | } | 857 | } |
diff --git a/embassy-stm32/src/lib.rs b/embassy-stm32/src/lib.rs index b795352c1..717ebb95e 100644 --- a/embassy-stm32/src/lib.rs +++ b/embassy-stm32/src/lib.rs | |||
| @@ -1,8 +1,5 @@ | |||
| 1 | #![no_std] | 1 | #![no_std] |
| 2 | #![cfg_attr( | 2 | #![cfg_attr(feature = "nightly", feature(generic_associated_types, type_alias_impl_trait))] |
| 3 | feature = "nightly", | ||
| 4 | feature(generic_associated_types, type_alias_impl_trait) | ||
| 5 | )] | ||
| 6 | 3 | ||
| 7 | // This must go FIRST so that all the other modules see its macros. | 4 | // This must go FIRST so that all the other modules see its macros. |
| 8 | pub mod fmt; | 5 | pub mod fmt; |
| @@ -42,9 +39,7 @@ pub mod i2c; | |||
| 42 | 39 | ||
| 43 | #[cfg(crc)] | 40 | #[cfg(crc)] |
| 44 | pub mod crc; | 41 | pub mod crc; |
| 45 | #[cfg(any( | 42 | #[cfg(any(flash_l0, flash_l1, flash_wl, flash_wb, flash_l4, flash_f3, flash_f7, flash_h7))] |
| 46 | flash_l0, flash_l1, flash_wl, flash_wb, flash_l4, flash_f3, flash_f7, flash_h7 | ||
| 47 | ))] | ||
| 48 | pub mod flash; | 43 | pub mod flash; |
| 49 | pub mod pwm; | 44 | pub mod pwm; |
| 50 | #[cfg(rng)] | 45 | #[cfg(rng)] |
| @@ -77,7 +72,6 @@ pub use _generated::{peripherals, Peripherals}; | |||
| 77 | pub use embassy_cortex_m::executor; | 72 | pub use embassy_cortex_m::executor; |
| 78 | pub use embassy_hal_common::{unborrow, Unborrow}; | 73 | pub use embassy_hal_common::{unborrow, Unborrow}; |
| 79 | pub use embassy_macros::cortex_m_interrupt as interrupt; | 74 | pub use embassy_macros::cortex_m_interrupt as interrupt; |
| 80 | |||
| 81 | #[cfg(feature = "unstable-pac")] | 75 | #[cfg(feature = "unstable-pac")] |
| 82 | pub use stm32_metapac as pac; | 76 | pub use stm32_metapac as pac; |
| 83 | #[cfg(not(feature = "unstable-pac"))] | 77 | #[cfg(not(feature = "unstable-pac"))] |
| @@ -114,8 +108,8 @@ pub fn init(config: Config) -> Peripherals { | |||
| 114 | cr.set_dbg_standby(true); | 108 | cr.set_dbg_standby(true); |
| 115 | } | 109 | } |
| 116 | #[cfg(any( | 110 | #[cfg(any( |
| 117 | dbgmcu_f1, dbgmcu_f2, dbgmcu_f3, dbgmcu_f4, dbgmcu_f7, dbgmcu_g4, dbgmcu_f7, | 111 | dbgmcu_f1, dbgmcu_f2, dbgmcu_f3, dbgmcu_f4, dbgmcu_f7, dbgmcu_g4, dbgmcu_f7, dbgmcu_l0, dbgmcu_l1, |
| 118 | dbgmcu_l0, dbgmcu_l1, dbgmcu_l4, dbgmcu_wb, dbgmcu_wl | 112 | dbgmcu_l4, dbgmcu_wb, dbgmcu_wl |
| 119 | ))] | 113 | ))] |
| 120 | { | 114 | { |
| 121 | cr.set_dbg_sleep(true); | 115 | cr.set_dbg_sleep(true); |
diff --git a/embassy-stm32/src/pwm/mod.rs b/embassy-stm32/src/pwm/mod.rs index c6edbc6c3..bd8358563 100644 --- a/embassy-stm32/src/pwm/mod.rs +++ b/embassy-stm32/src/pwm/mod.rs | |||
| @@ -64,9 +64,7 @@ pub(crate) mod sealed { | |||
| 64 | unsafe fn get_max_compare_value(&self) -> u16; | 64 | unsafe fn get_max_compare_value(&self) -> u16; |
| 65 | } | 65 | } |
| 66 | 66 | ||
| 67 | pub trait CaptureCompare32bitInstance: | 67 | pub trait CaptureCompare32bitInstance: crate::timer::sealed::GeneralPurpose32bitInstance { |
| 68 | crate::timer::sealed::GeneralPurpose32bitInstance | ||
| 69 | { | ||
| 70 | unsafe fn set_output_compare_mode(&mut self, channel: Channel, mode: OutputCompareMode); | 68 | unsafe fn set_output_compare_mode(&mut self, channel: Channel, mode: OutputCompareMode); |
| 71 | 69 | ||
| 72 | unsafe fn enable_channel(&mut self, channel: Channel, enable: bool); | 70 | unsafe fn enable_channel(&mut self, channel: Channel, enable: bool); |
| @@ -82,10 +80,7 @@ pub trait CaptureCompare16bitInstance: | |||
| 82 | { | 80 | { |
| 83 | } | 81 | } |
| 84 | pub trait CaptureCompare32bitInstance: | 82 | pub trait CaptureCompare32bitInstance: |
| 85 | sealed::CaptureCompare32bitInstance | 83 | sealed::CaptureCompare32bitInstance + CaptureCompare16bitInstance + crate::timer::GeneralPurpose32bitInstance + 'static |
| 86 | + CaptureCompare16bitInstance | ||
| 87 | + crate::timer::GeneralPurpose32bitInstance | ||
| 88 | + 'static | ||
| 89 | { | 84 | { |
| 90 | } | 85 | } |
| 91 | 86 | ||
| @@ -93,11 +88,7 @@ pub trait CaptureCompare32bitInstance: | |||
| 93 | macro_rules! impl_compare_capable_16bit { | 88 | macro_rules! impl_compare_capable_16bit { |
| 94 | ($inst:ident) => { | 89 | ($inst:ident) => { |
| 95 | impl crate::pwm::sealed::CaptureCompare16bitInstance for crate::peripherals::$inst { | 90 | impl crate::pwm::sealed::CaptureCompare16bitInstance for crate::peripherals::$inst { |
| 96 | unsafe fn set_output_compare_mode( | 91 | unsafe fn set_output_compare_mode(&mut self, channel: crate::pwm::Channel, mode: OutputCompareMode) { |
| 97 | &mut self, | ||
| 98 | channel: crate::pwm::Channel, | ||
| 99 | mode: OutputCompareMode, | ||
| 100 | ) { | ||
| 101 | use crate::timer::sealed::GeneralPurpose16bitInstance; | 92 | use crate::timer::sealed::GeneralPurpose16bitInstance; |
| 102 | let r = Self::regs_gp16(); | 93 | let r = Self::regs_gp16(); |
| 103 | let raw_channel: usize = channel.raw(); | 94 | let raw_channel: usize = channel.raw(); |
| @@ -114,9 +105,7 @@ macro_rules! impl_compare_capable_16bit { | |||
| 114 | 105 | ||
| 115 | unsafe fn set_compare_value(&mut self, channel: Channel, value: u16) { | 106 | unsafe fn set_compare_value(&mut self, channel: Channel, value: u16) { |
| 116 | use crate::timer::sealed::GeneralPurpose16bitInstance; | 107 | use crate::timer::sealed::GeneralPurpose16bitInstance; |
| 117 | Self::regs_gp16() | 108 | Self::regs_gp16().ccr(channel.raw()).modify(|w| w.set_ccr(value)); |
| 118 | .ccr(channel.raw()) | ||
| 119 | .modify(|w| w.set_ccr(value)); | ||
| 120 | } | 109 | } |
| 121 | 110 | ||
| 122 | unsafe fn get_max_compare_value(&self) -> u16 { | 111 | unsafe fn get_max_compare_value(&self) -> u16 { |
diff --git a/embassy-stm32/src/pwm/simple_pwm.rs b/embassy-stm32/src/pwm/simple_pwm.rs index 990f5bda7..a475f3f70 100644 --- a/embassy-stm32/src/pwm/simple_pwm.rs +++ b/embassy-stm32/src/pwm/simple_pwm.rs | |||
| @@ -1,11 +1,12 @@ | |||
| 1 | use crate::Unborrow; | ||
| 2 | use core::marker::PhantomData; | 1 | use core::marker::PhantomData; |
| 2 | |||
| 3 | use embassy_hal_common::unborrow; | 3 | use embassy_hal_common::unborrow; |
| 4 | 4 | ||
| 5 | use super::*; | 5 | use super::*; |
| 6 | #[allow(unused_imports)] | 6 | #[allow(unused_imports)] |
| 7 | use crate::gpio::sealed::{AFType, Pin}; | 7 | use crate::gpio::sealed::{AFType, Pin}; |
| 8 | use crate::time::Hertz; | 8 | use crate::time::Hertz; |
| 9 | use crate::Unborrow; | ||
| 9 | 10 | ||
| 10 | pub struct SimplePwm<'d, T> { | 11 | pub struct SimplePwm<'d, T> { |
| 11 | phantom: PhantomData<&'d mut T>, | 12 | phantom: PhantomData<&'d mut T>, |
| @@ -74,11 +75,7 @@ impl<'d, T: CaptureCompare16bitInstance> SimplePwm<'d, T> { | |||
| 74 | }) | 75 | }) |
| 75 | } | 76 | } |
| 76 | 77 | ||
| 77 | fn new_inner<F: Into<Hertz>>( | 78 | fn new_inner<F: Into<Hertz>>(tim: impl Unborrow<Target = T> + 'd, freq: F, configure_pins: impl FnOnce()) -> Self { |
| 78 | tim: impl Unborrow<Target = T> + 'd, | ||
| 79 | freq: F, | ||
| 80 | configure_pins: impl FnOnce(), | ||
| 81 | ) -> Self { | ||
| 82 | unborrow!(tim); | 79 | unborrow!(tim); |
| 83 | 80 | ||
| 84 | T::enable(); | 81 | T::enable(); |
diff --git a/embassy-stm32/src/rcc/f0.rs b/embassy-stm32/src/rcc/f0.rs index 427c958f0..10b075da4 100644 --- a/embassy-stm32/src/rcc/f0.rs +++ b/embassy-stm32/src/rcc/f0.rs | |||
| @@ -1,9 +1,8 @@ | |||
| 1 | use super::{set_freqs, Clocks}; | ||
| 1 | use crate::pac::rcc::vals::{Hpre, Pllmul, Pllsrc, Ppre, Sw, Usbsw}; | 2 | use crate::pac::rcc::vals::{Hpre, Pllmul, Pllsrc, Ppre, Sw, Usbsw}; |
| 2 | use crate::pac::{FLASH, RCC}; | 3 | use crate::pac::{FLASH, RCC}; |
| 3 | use crate::time::Hertz; | 4 | use crate::time::Hertz; |
| 4 | 5 | ||
| 5 | use super::{set_freqs, Clocks}; | ||
| 6 | |||
| 7 | const HSI: u32 = 8_000_000; | 6 | const HSI: u32 = 8_000_000; |
| 8 | 7 | ||
| 9 | /// Configuration of the clocks | 8 | /// Configuration of the clocks |
| @@ -112,8 +111,7 @@ pub(crate) unsafe fn init(config: Config) { | |||
| 112 | while !RCC.cr2().read().hsi48rdy() {} | 111 | while !RCC.cr2().read().hsi48rdy() {} |
| 113 | 112 | ||
| 114 | if pllmul_bits.is_some() { | 113 | if pllmul_bits.is_some() { |
| 115 | RCC.cfgr() | 114 | RCC.cfgr().modify(|w| w.set_pllsrc(Pllsrc::HSI48_DIV_PREDIV)) |
| 116 | .modify(|w| w.set_pllsrc(Pllsrc::HSI48_DIV_PREDIV)) | ||
| 117 | } | 115 | } |
| 118 | } | 116 | } |
| 119 | _ => { | 117 | _ => { |
diff --git a/embassy-stm32/src/rcc/f2.rs b/embassy-stm32/src/rcc/f2.rs index 7e5992bba..65fa78f82 100644 --- a/embassy-stm32/src/rcc/f2.rs +++ b/embassy-stm32/src/rcc/f2.rs | |||
| @@ -436,9 +436,7 @@ pub(crate) unsafe fn init(config: Config) { | |||
| 436 | let pll_clocks = config.pll.clocks(pll_src_freq); | 436 | let pll_clocks = config.pll.clocks(pll_src_freq); |
| 437 | assert!(Hertz(950_000) <= pll_clocks.in_freq && pll_clocks.in_freq <= Hertz(2_100_000)); | 437 | assert!(Hertz(950_000) <= pll_clocks.in_freq && pll_clocks.in_freq <= Hertz(2_100_000)); |
| 438 | assert!(Hertz(192_000_000) <= pll_clocks.vco_freq && pll_clocks.vco_freq <= Hertz(432_000_000)); | 438 | assert!(Hertz(192_000_000) <= pll_clocks.vco_freq && pll_clocks.vco_freq <= Hertz(432_000_000)); |
| 439 | assert!( | 439 | assert!(Hertz(24_000_000) <= pll_clocks.main_freq && pll_clocks.main_freq <= Hertz(120_000_000)); |
| 440 | Hertz(24_000_000) <= pll_clocks.main_freq && pll_clocks.main_freq <= Hertz(120_000_000) | ||
| 441 | ); | ||
| 442 | // USB actually requires == 48 MHz, but other PLL48 peripherals are fine with <= 48MHz | 440 | // USB actually requires == 48 MHz, but other PLL48 peripherals are fine with <= 48MHz |
| 443 | assert!(pll_clocks.pll48_freq <= Hertz(48_000_000)); | 441 | assert!(pll_clocks.pll48_freq <= Hertz(48_000_000)); |
| 444 | 442 | ||
diff --git a/embassy-stm32/src/rcc/f4.rs b/embassy-stm32/src/rcc/f4.rs index 22a2e9ad0..21f3ad15d 100644 --- a/embassy-stm32/src/rcc/f4.rs +++ b/embassy-stm32/src/rcc/f4.rs | |||
| @@ -20,18 +20,12 @@ pub struct Config { | |||
| 20 | pub pll48: bool, | 20 | pub pll48: bool, |
| 21 | } | 21 | } |
| 22 | 22 | ||
| 23 | unsafe fn setup_pll( | 23 | unsafe fn setup_pll(pllsrcclk: u32, use_hse: bool, pllsysclk: Option<u32>, pll48clk: bool) -> PllResults { |
| 24 | pllsrcclk: u32, | ||
| 25 | use_hse: bool, | ||
| 26 | pllsysclk: Option<u32>, | ||
| 27 | pll48clk: bool, | ||
| 28 | ) -> PllResults { | ||
| 29 | use crate::pac::rcc::vals::{Pllp, Pllsrc}; | 24 | use crate::pac::rcc::vals::{Pllp, Pllsrc}; |
| 30 | 25 | ||
| 31 | let sysclk = pllsysclk.unwrap_or(pllsrcclk); | 26 | let sysclk = pllsysclk.unwrap_or(pllsrcclk); |
| 32 | if pllsysclk.is_none() && !pll48clk { | 27 | if pllsysclk.is_none() && !pll48clk { |
| 33 | RCC.pllcfgr() | 28 | RCC.pllcfgr().modify(|w| w.set_pllsrc(Pllsrc(use_hse as u8))); |
| 34 | .modify(|w| w.set_pllsrc(Pllsrc(use_hse as u8))); | ||
| 35 | 29 | ||
| 36 | return PllResults { | 30 | return PllResults { |
| 37 | use_pll: false, | 31 | use_pll: false, |
| @@ -47,11 +41,7 @@ unsafe fn setup_pll( | |||
| 47 | // Sysclk output divisor must be one of 2, 4, 6 or 8 | 41 | // Sysclk output divisor must be one of 2, 4, 6 or 8 |
| 48 | let sysclk_div = core::cmp::min(8, (432_000_000 / sysclk) & !1); | 42 | let sysclk_div = core::cmp::min(8, (432_000_000 / sysclk) & !1); |
| 49 | 43 | ||
| 50 | let target_freq = if pll48clk { | 44 | let target_freq = if pll48clk { 48_000_000 } else { sysclk * sysclk_div }; |
| 51 | 48_000_000 | ||
| 52 | } else { | ||
| 53 | sysclk * sysclk_div | ||
| 54 | }; | ||
| 55 | 45 | ||
| 56 | // Find the lowest pllm value that minimize the difference between | 46 | // Find the lowest pllm value that minimize the difference between |
| 57 | // target frequency and the real vco_out frequency. | 47 | // target frequency and the real vco_out frequency. |
| @@ -135,11 +125,7 @@ pub(crate) unsafe fn init(config: Config) { | |||
| 135 | assert!((max::PLL_48_CLK as i32 - freq as i32).abs() <= max::PLL_48_TOLERANCE as i32); | 125 | assert!((max::PLL_48_CLK as i32 - freq as i32).abs() <= max::PLL_48_TOLERANCE as i32); |
| 136 | } | 126 | } |
| 137 | 127 | ||
| 138 | let sysclk = if sysclk_on_pll { | 128 | let sysclk = if sysclk_on_pll { unwrap!(plls.pllsysclk) } else { sysclk }; |
| 139 | unwrap!(plls.pllsysclk) | ||
| 140 | } else { | ||
| 141 | sysclk | ||
| 142 | }; | ||
| 143 | 129 | ||
| 144 | // AHB prescaler | 130 | // AHB prescaler |
| 145 | let hclk = config.hclk.map(|h| h.0).unwrap_or(sysclk); | 131 | let hclk = config.hclk.map(|h| h.0).unwrap_or(sysclk); |
| @@ -269,9 +255,7 @@ mod max { | |||
| 269 | pub(crate) const SYSCLK_MAX: u32 = 168_000_000; | 255 | pub(crate) const SYSCLK_MAX: u32 = 168_000_000; |
| 270 | #[cfg(any(stm32f410, stm32f411, stm32f412, stm32f413, stm32f423,))] | 256 | #[cfg(any(stm32f410, stm32f411, stm32f412, stm32f413, stm32f423,))] |
| 271 | pub(crate) const SYSCLK_MAX: u32 = 100_000_000; | 257 | pub(crate) const SYSCLK_MAX: u32 = 100_000_000; |
| 272 | #[cfg(any( | 258 | #[cfg(any(stm32f427, stm32f429, stm32f437, stm32f439, stm32f446, stm32f469, stm32f479,))] |
| 273 | stm32f427, stm32f429, stm32f437, stm32f439, stm32f446, stm32f469, stm32f479, | ||
| 274 | ))] | ||
| 275 | pub(crate) const SYSCLK_MAX: u32 = 180_000_000; | 259 | pub(crate) const SYSCLK_MAX: u32 = 180_000_000; |
| 276 | 260 | ||
| 277 | pub(crate) const HCLK_OVERDRIVE_FREQUENCY: u32 = 168_000_000; | 261 | pub(crate) const HCLK_OVERDRIVE_FREQUENCY: u32 = 168_000_000; |
diff --git a/embassy-stm32/src/rcc/f7.rs b/embassy-stm32/src/rcc/f7.rs index f45a725ce..d98aa4018 100644 --- a/embassy-stm32/src/rcc/f7.rs +++ b/embassy-stm32/src/rcc/f7.rs | |||
| @@ -21,18 +21,12 @@ pub struct Config { | |||
| 21 | pub pll48: bool, | 21 | pub pll48: bool, |
| 22 | } | 22 | } |
| 23 | 23 | ||
| 24 | unsafe fn setup_pll( | 24 | unsafe fn setup_pll(pllsrcclk: u32, use_hse: bool, pllsysclk: Option<u32>, pll48clk: bool) -> PllResults { |
| 25 | pllsrcclk: u32, | ||
| 26 | use_hse: bool, | ||
| 27 | pllsysclk: Option<u32>, | ||
| 28 | pll48clk: bool, | ||
| 29 | ) -> PllResults { | ||
| 30 | use crate::pac::rcc::vals::{Pllp, Pllsrc}; | 25 | use crate::pac::rcc::vals::{Pllp, Pllsrc}; |
| 31 | 26 | ||
| 32 | let sysclk = pllsysclk.unwrap_or(pllsrcclk); | 27 | let sysclk = pllsysclk.unwrap_or(pllsrcclk); |
| 33 | if pllsysclk.is_none() && !pll48clk { | 28 | if pllsysclk.is_none() && !pll48clk { |
| 34 | RCC.pllcfgr() | 29 | RCC.pllcfgr().modify(|w| w.set_pllsrc(Pllsrc(use_hse as u8))); |
| 35 | .modify(|w| w.set_pllsrc(Pllsrc(use_hse as u8))); | ||
| 36 | 30 | ||
| 37 | return PllResults { | 31 | return PllResults { |
| 38 | use_pll: false, | 32 | use_pll: false, |
| @@ -48,11 +42,7 @@ unsafe fn setup_pll( | |||
| 48 | // Sysclk output divisor must be one of 2, 4, 6 or 8 | 42 | // Sysclk output divisor must be one of 2, 4, 6 or 8 |
| 49 | let sysclk_div = core::cmp::min(8, (432_000_000 / sysclk) & !1); | 43 | let sysclk_div = core::cmp::min(8, (432_000_000 / sysclk) & !1); |
| 50 | 44 | ||
| 51 | let target_freq = if pll48clk { | 45 | let target_freq = if pll48clk { 48_000_000 } else { sysclk * sysclk_div }; |
| 52 | 48_000_000 | ||
| 53 | } else { | ||
| 54 | sysclk * sysclk_div | ||
| 55 | }; | ||
| 56 | 46 | ||
| 57 | // Find the lowest pllm value that minimize the difference between | 47 | // Find the lowest pllm value that minimize the difference between |
| 58 | // target frequency and the real vco_out frequency. | 48 | // target frequency and the real vco_out frequency. |
| @@ -146,11 +136,7 @@ pub(crate) unsafe fn init(config: Config) { | |||
| 146 | assert!((max::PLL_48_CLK as i32 - freq as i32).abs() <= max::PLL_48_TOLERANCE as i32); | 136 | assert!((max::PLL_48_CLK as i32 - freq as i32).abs() <= max::PLL_48_TOLERANCE as i32); |
| 147 | } | 137 | } |
| 148 | 138 | ||
| 149 | let sysclk = if sysclk_on_pll { | 139 | let sysclk = if sysclk_on_pll { unwrap!(plls.pllsysclk) } else { sysclk }; |
| 150 | unwrap!(plls.pllsysclk) | ||
| 151 | } else { | ||
| 152 | sysclk | ||
| 153 | }; | ||
| 154 | 140 | ||
| 155 | // AHB prescaler | 141 | // AHB prescaler |
| 156 | let hclk = config.hclk.map(|h| h.0).unwrap_or(sysclk); | 142 | let hclk = config.hclk.map(|h| h.0).unwrap_or(sysclk); |
diff --git a/embassy-stm32/src/rcc/g0.rs b/embassy-stm32/src/rcc/g0.rs index be0497290..36b49c711 100644 --- a/embassy-stm32/src/rcc/g0.rs +++ b/embassy-stm32/src/rcc/g0.rs | |||
| @@ -2,8 +2,7 @@ use crate::pac::flash::vals::Latency; | |||
| 2 | use crate::pac::rcc::vals::{self, Hpre, Hsidiv, Ppre, Sw}; | 2 | use crate::pac::rcc::vals::{self, Hpre, Hsidiv, Ppre, Sw}; |
| 3 | use crate::pac::{FLASH, PWR, RCC}; | 3 | use crate::pac::{FLASH, PWR, RCC}; |
| 4 | use crate::rcc::{set_freqs, Clocks}; | 4 | use crate::rcc::{set_freqs, Clocks}; |
| 5 | use crate::time::Hertz; | 5 | use crate::time::{Hertz, U32Ext}; |
| 6 | use crate::time::U32Ext; | ||
| 7 | 6 | ||
| 8 | /// HSI speed | 7 | /// HSI speed |
| 9 | pub const HSI_FREQ: u32 = 16_000_000; | 8 | pub const HSI_FREQ: u32 = 16_000_000; |
diff --git a/embassy-stm32/src/rcc/g4.rs b/embassy-stm32/src/rcc/g4.rs index ce8cca45d..2b8c2b576 100644 --- a/embassy-stm32/src/rcc/g4.rs +++ b/embassy-stm32/src/rcc/g4.rs | |||
| @@ -1,7 +1,6 @@ | |||
| 1 | use crate::pac::{PWR, RCC}; | 1 | use crate::pac::{PWR, RCC}; |
| 2 | use crate::rcc::{set_freqs, Clocks}; | 2 | use crate::rcc::{set_freqs, Clocks}; |
| 3 | use crate::time::Hertz; | 3 | use crate::time::{Hertz, U32Ext}; |
| 4 | use crate::time::U32Ext; | ||
| 5 | 4 | ||
| 6 | /// HSI speed | 5 | /// HSI speed |
| 7 | pub const HSI_FREQ: u32 = 16_000_000; | 6 | pub const HSI_FREQ: u32 = 16_000_000; |
diff --git a/embassy-stm32/src/rcc/h7.rs b/embassy-stm32/src/rcc/h7.rs index 0cd89645f..4fa01ade4 100644 --- a/embassy-stm32/src/rcc/h7.rs +++ b/embassy-stm32/src/rcc/h7.rs | |||
| @@ -1,19 +1,16 @@ | |||
| 1 | use core::marker::PhantomData; | 1 | use core::marker::PhantomData; |
| 2 | 2 | ||
| 3 | use crate::Unborrow; | ||
| 4 | use embassy_hal_common::unborrow; | 3 | use embassy_hal_common::unborrow; |
| 4 | pub use pll::PllConfig; | ||
| 5 | use stm32_metapac::rcc::vals::{Mco1, Mco2}; | 5 | use stm32_metapac::rcc::vals::{Mco1, Mco2}; |
| 6 | 6 | ||
| 7 | use crate::gpio::sealed::AFType; | 7 | use crate::gpio::sealed::AFType; |
| 8 | use crate::gpio::Speed; | 8 | use crate::gpio::Speed; |
| 9 | use crate::pac::rcc::vals::Timpre; | 9 | use crate::pac::rcc::vals::{Adcsel, Ckpersel, Dppre, Hpre, Hsidiv, Pllsrc, Sw, Timpre}; |
| 10 | use crate::pac::rcc::vals::{Adcsel, Ckpersel, Dppre, Hpre, Hsidiv, Pllsrc, Sw}; | ||
| 11 | use crate::pac::{PWR, RCC, SYSCFG}; | 10 | use crate::pac::{PWR, RCC, SYSCFG}; |
| 12 | use crate::peripherals; | ||
| 13 | use crate::rcc::{set_freqs, Clocks}; | 11 | use crate::rcc::{set_freqs, Clocks}; |
| 14 | use crate::time::Hertz; | 12 | use crate::time::Hertz; |
| 15 | 13 | use crate::{peripherals, Unborrow}; | |
| 16 | pub use pll::PllConfig; | ||
| 17 | 14 | ||
| 18 | const HSI: Hertz = Hertz(64_000_000); | 15 | const HSI: Hertz = Hertz(64_000_000); |
| 19 | const CSI: Hertz = Hertz(4_000_000); | 16 | const CSI: Hertz = Hertz(4_000_000); |
| @@ -181,8 +178,10 @@ fn sys_ck_setup(config: &mut Config, srcclk: Hertz) -> (Hertz, bool) { | |||
| 181 | // Therefore we must use pll1_p_ck | 178 | // Therefore we must use pll1_p_ck |
| 182 | let pll1_p_ck = match config.pll1.p_ck { | 179 | let pll1_p_ck = match config.pll1.p_ck { |
| 183 | Some(p_ck) => { | 180 | Some(p_ck) => { |
| 184 | assert!(p_ck == sys_ck, | 181 | assert!( |
| 185 | "Error: Cannot set pll1_p_ck independently as it must be used to generate sys_ck"); | 182 | p_ck == sys_ck, |
| 183 | "Error: Cannot set pll1_p_ck independently as it must be used to generate sys_ck" | ||
| 184 | ); | ||
| 186 | Some(p_ck) | 185 | Some(p_ck) |
| 187 | } | 186 | } |
| 188 | None => Some(sys_ck), | 187 | None => Some(sys_ck), |
| @@ -392,9 +391,7 @@ impl<'d, T: McoInstance> Mco<'d, T> { | |||
| 392 | pin.set_speed(Speed::VeryHigh); | 391 | pin.set_speed(Speed::VeryHigh); |
| 393 | }); | 392 | }); |
| 394 | 393 | ||
| 395 | Self { | 394 | Self { phantom: PhantomData } |
| 396 | phantom: PhantomData, | ||
| 397 | } | ||
| 398 | } | 395 | } |
| 399 | } | 396 | } |
| 400 | 397 | ||
| @@ -538,33 +535,19 @@ pub(crate) unsafe fn init(mut config: Config) { | |||
| 538 | // Timer prescaler selection | 535 | // Timer prescaler selection |
| 539 | let timpre = Timpre::DEFAULTX2; | 536 | let timpre = Timpre::DEFAULTX2; |
| 540 | 537 | ||
| 541 | let requested_pclk1 = config | 538 | let requested_pclk1 = config.pclk1.map(|v| v.0).unwrap_or_else(|| pclk_max.min(rcc_hclk / 2)); |
| 542 | .pclk1 | ||
| 543 | .map(|v| v.0) | ||
| 544 | .unwrap_or_else(|| pclk_max.min(rcc_hclk / 2)); | ||
| 545 | let (rcc_pclk1, ppre1_bits, ppre1, rcc_timerx_ker_ck) = | 539 | let (rcc_pclk1, ppre1_bits, ppre1, rcc_timerx_ker_ck) = |
| 546 | ppre_calculate(requested_pclk1, rcc_hclk, pclk_max, Some(timpre)); | 540 | ppre_calculate(requested_pclk1, rcc_hclk, pclk_max, Some(timpre)); |
| 547 | 541 | ||
| 548 | let requested_pclk2 = config | 542 | let requested_pclk2 = config.pclk2.map(|v| v.0).unwrap_or_else(|| pclk_max.min(rcc_hclk / 2)); |
| 549 | .pclk2 | ||
| 550 | .map(|v| v.0) | ||
| 551 | .unwrap_or_else(|| pclk_max.min(rcc_hclk / 2)); | ||
| 552 | let (rcc_pclk2, ppre2_bits, ppre2, rcc_timery_ker_ck) = | 543 | let (rcc_pclk2, ppre2_bits, ppre2, rcc_timery_ker_ck) = |
| 553 | ppre_calculate(requested_pclk2, rcc_hclk, pclk_max, Some(timpre)); | 544 | ppre_calculate(requested_pclk2, rcc_hclk, pclk_max, Some(timpre)); |
| 554 | 545 | ||
| 555 | let requested_pclk3 = config | 546 | let requested_pclk3 = config.pclk3.map(|v| v.0).unwrap_or_else(|| pclk_max.min(rcc_hclk / 2)); |
| 556 | .pclk3 | 547 | let (rcc_pclk3, ppre3_bits, ppre3, _) = ppre_calculate(requested_pclk3, rcc_hclk, pclk_max, None); |
| 557 | .map(|v| v.0) | ||
| 558 | .unwrap_or_else(|| pclk_max.min(rcc_hclk / 2)); | ||
| 559 | let (rcc_pclk3, ppre3_bits, ppre3, _) = | ||
| 560 | ppre_calculate(requested_pclk3, rcc_hclk, pclk_max, None); | ||
| 561 | 548 | ||
| 562 | let requested_pclk4 = config | 549 | let requested_pclk4 = config.pclk4.map(|v| v.0).unwrap_or_else(|| pclk_max.min(rcc_hclk / 2)); |
| 563 | .pclk4 | 550 | let (rcc_pclk4, ppre4_bits, ppre4, _) = ppre_calculate(requested_pclk4, rcc_hclk, pclk_max, None); |
| 564 | .map(|v| v.0) | ||
| 565 | .unwrap_or_else(|| pclk_max.min(rcc_hclk / 2)); | ||
| 566 | let (rcc_pclk4, ppre4_bits, ppre4, _) = | ||
| 567 | ppre_calculate(requested_pclk4, rcc_hclk, pclk_max, None); | ||
| 568 | 551 | ||
| 569 | flash_setup(rcc_aclk, pwr_vos); | 552 | flash_setup(rcc_aclk, pwr_vos); |
| 570 | 553 | ||
| @@ -593,11 +576,7 @@ pub(crate) unsafe fn init(mut config: Config) { | |||
| 593 | None => None, | 576 | None => None, |
| 594 | }; | 577 | }; |
| 595 | 578 | ||
| 596 | let pllsrc = if config.hse.is_some() { | 579 | let pllsrc = if config.hse.is_some() { Pllsrc::HSE } else { Pllsrc::HSI }; |
| 597 | Pllsrc::HSE | ||
| 598 | } else { | ||
| 599 | Pllsrc::HSI | ||
| 600 | }; | ||
| 601 | RCC.pllckselr().modify(|w| w.set_pllsrc(pllsrc)); | 580 | RCC.pllckselr().modify(|w| w.set_pllsrc(pllsrc)); |
| 602 | 581 | ||
| 603 | let enable_pll = |pll| { | 582 | let enable_pll = |pll| { |
| @@ -640,8 +619,7 @@ pub(crate) unsafe fn init(mut config: Config) { | |||
| 640 | RCC.d1ccipr().modify(|w| w.set_ckpersel(ckpersel)); | 619 | RCC.d1ccipr().modify(|w| w.set_ckpersel(ckpersel)); |
| 641 | 620 | ||
| 642 | // ADC clock MUX | 621 | // ADC clock MUX |
| 643 | RCC.d3ccipr() | 622 | RCC.d3ccipr().modify(|w| w.set_adcsel(config.adc_clock_source.adcsel())); |
| 644 | .modify(|w| w.set_adcsel(config.adc_clock_source.adcsel())); | ||
| 645 | 623 | ||
| 646 | let adc_ker_ck = match config.adc_clock_source { | 624 | let adc_ker_ck = match config.adc_clock_source { |
| 647 | AdcClockSource::Pll2PCk => pll2_p_ck.map(Hertz), | 625 | AdcClockSource::Pll2PCk => pll2_p_ck.map(Hertz), |
| @@ -823,15 +801,13 @@ mod pll { | |||
| 823 | let pll_x_n = vco_ck_target / ref_x_ck; | 801 | let pll_x_n = vco_ck_target / ref_x_ck; |
| 824 | assert!(pll_x_n >= 4); | 802 | assert!(pll_x_n >= 4); |
| 825 | assert!(pll_x_n <= 512); | 803 | assert!(pll_x_n <= 512); |
| 826 | RCC.plldivr(plln) | 804 | RCC.plldivr(plln).modify(|w| w.set_divn1((pll_x_n - 1) as u16)); |
| 827 | .modify(|w| w.set_divn1((pll_x_n - 1) as u16)); | ||
| 828 | 805 | ||
| 829 | // No FRACN | 806 | // No FRACN |
| 830 | RCC.pllcfgr().modify(|w| w.set_pllfracen(plln, false)); | 807 | RCC.pllcfgr().modify(|w| w.set_pllfracen(plln, false)); |
| 831 | let vco_ck = ref_x_ck * pll_x_n; | 808 | let vco_ck = ref_x_ck * pll_x_n; |
| 832 | 809 | ||
| 833 | RCC.plldivr(plln) | 810 | RCC.plldivr(plln).modify(|w| w.set_divp1(Divp((pll_x_p - 1) as u8))); |
| 834 | .modify(|w| w.set_divp1(Divp((pll_x_p - 1) as u8))); | ||
| 835 | RCC.pllcfgr().modify(|w| w.set_divpen(plln, true)); | 811 | RCC.pllcfgr().modify(|w| w.set_divpen(plln, true)); |
| 836 | 812 | ||
| 837 | // Calulate additional output dividers | 813 | // Calulate additional output dividers |
diff --git a/embassy-stm32/src/rcc/l0.rs b/embassy-stm32/src/rcc/l0.rs index 692791174..2e23833ca 100644 --- a/embassy-stm32/src/rcc/l0.rs +++ b/embassy-stm32/src/rcc/l0.rs | |||
| @@ -3,8 +3,7 @@ use crate::pac::RCC; | |||
| 3 | #[cfg(crs)] | 3 | #[cfg(crs)] |
| 4 | use crate::pac::{CRS, SYSCFG}; | 4 | use crate::pac::{CRS, SYSCFG}; |
| 5 | use crate::rcc::{set_freqs, Clocks}; | 5 | use crate::rcc::{set_freqs, Clocks}; |
| 6 | use crate::time::Hertz; | 6 | use crate::time::{Hertz, U32Ext}; |
| 7 | use crate::time::U32Ext; | ||
| 8 | 7 | ||
| 9 | /// HSI16 speed | 8 | /// HSI16 speed |
| 10 | pub const HSI16_FREQ: u32 = 16_000_000; | 9 | pub const HSI16_FREQ: u32 = 16_000_000; |
diff --git a/embassy-stm32/src/rcc/l1.rs b/embassy-stm32/src/rcc/l1.rs index dfcbd4f21..80290632e 100644 --- a/embassy-stm32/src/rcc/l1.rs +++ b/embassy-stm32/src/rcc/l1.rs | |||
| @@ -1,8 +1,7 @@ | |||
| 1 | use crate::pac::rcc::vals::{Hpre, Msirange, Plldiv, Pllmul, Pllsrc, Ppre, Sw}; | 1 | use crate::pac::rcc::vals::{Hpre, Msirange, Plldiv, Pllmul, Pllsrc, Ppre, Sw}; |
| 2 | use crate::pac::{FLASH, RCC}; | 2 | use crate::pac::{FLASH, RCC}; |
| 3 | use crate::rcc::{set_freqs, Clocks}; | 3 | use crate::rcc::{set_freqs, Clocks}; |
| 4 | use crate::time::Hertz; | 4 | use crate::time::{Hertz, U32Ext}; |
| 5 | use crate::time::U32Ext; | ||
| 6 | 5 | ||
| 7 | /// HSI speed | 6 | /// HSI speed |
| 8 | pub const HSI_FREQ: u32 = 16_000_000; | 7 | pub const HSI_FREQ: u32 = 16_000_000; |
diff --git a/embassy-stm32/src/rcc/l4.rs b/embassy-stm32/src/rcc/l4.rs index 3b84fb9b8..1905039b9 100644 --- a/embassy-stm32/src/rcc/l4.rs +++ b/embassy-stm32/src/rcc/l4.rs | |||
| @@ -1,8 +1,7 @@ | |||
| 1 | use crate::pac::rcc::vals::{Hpre, Msirange, Pllsrc, Ppre, Sw}; | 1 | use crate::pac::rcc::vals::{Hpre, Msirange, Pllsrc, Ppre, Sw}; |
| 2 | use crate::pac::{FLASH, RCC}; | 2 | use crate::pac::{FLASH, RCC}; |
| 3 | use crate::rcc::{set_freqs, Clocks}; | 3 | use crate::rcc::{set_freqs, Clocks}; |
| 4 | use crate::time::Hertz; | 4 | use crate::time::{Hertz, U32Ext}; |
| 5 | use crate::time::U32Ext; | ||
| 6 | 5 | ||
| 7 | /// HSI16 speed | 6 | /// HSI16 speed |
| 8 | pub const HSI16_FREQ: u32 = 16_000_000; | 7 | pub const HSI16_FREQ: u32 = 16_000_000; |
diff --git a/embassy-stm32/src/rcc/l5.rs b/embassy-stm32/src/rcc/l5.rs index 4419f3d31..48d12a890 100644 --- a/embassy-stm32/src/rcc/l5.rs +++ b/embassy-stm32/src/rcc/l5.rs | |||
| @@ -3,8 +3,7 @@ use stm32_metapac::PWR; | |||
| 3 | use crate::pac::rcc::vals::{Hpre, Msirange, Pllsrc, Ppre, Sw}; | 3 | use crate::pac::rcc::vals::{Hpre, Msirange, Pllsrc, Ppre, Sw}; |
| 4 | use crate::pac::{FLASH, RCC}; | 4 | use crate::pac::{FLASH, RCC}; |
| 5 | use crate::rcc::{set_freqs, Clocks}; | 5 | use crate::rcc::{set_freqs, Clocks}; |
| 6 | use crate::time::Hertz; | 6 | use crate::time::{Hertz, U32Ext}; |
| 7 | use crate::time::U32Ext; | ||
| 8 | 7 | ||
| 9 | /// HSI16 speed | 8 | /// HSI16 speed |
| 10 | pub const HSI16_FREQ: u32 = 16_000_000; | 9 | pub const HSI16_FREQ: u32 = 16_000_000; |
| @@ -297,8 +296,7 @@ impl Default for Config { | |||
| 297 | } | 296 | } |
| 298 | 297 | ||
| 299 | pub(crate) unsafe fn init(config: Config) { | 298 | pub(crate) unsafe fn init(config: Config) { |
| 300 | PWR.cr1() | 299 | PWR.cr1().modify(|w| w.set_vos(stm32_metapac::pwr::vals::Vos::RANGE0)); |
| 301 | .modify(|w| w.set_vos(stm32_metapac::pwr::vals::Vos::RANGE0)); | ||
| 302 | let (sys_clk, sw) = match config.mux { | 300 | let (sys_clk, sw) = match config.mux { |
| 303 | ClockSrc::MSI(range) => { | 301 | ClockSrc::MSI(range) => { |
| 304 | // Enable MSI | 302 | // Enable MSI |
diff --git a/embassy-stm32/src/rcc/mod.rs b/embassy-stm32/src/rcc/mod.rs index 959e59265..866b1ffc4 100644 --- a/embassy-stm32/src/rcc/mod.rs +++ b/embassy-stm32/src/rcc/mod.rs | |||
| @@ -1,8 +1,9 @@ | |||
| 1 | #![macro_use] | 1 | #![macro_use] |
| 2 | 2 | ||
| 3 | use crate::time::Hertz; | ||
| 4 | use core::mem::MaybeUninit; | 3 | use core::mem::MaybeUninit; |
| 5 | 4 | ||
| 5 | use crate::time::Hertz; | ||
| 6 | |||
| 6 | #[cfg_attr(rcc_f0, path = "f0.rs")] | 7 | #[cfg_attr(rcc_f0, path = "f0.rs")] |
| 7 | #[cfg_attr(any(rcc_f1, rcc_f1cl), path = "f1.rs")] | 8 | #[cfg_attr(any(rcc_f1, rcc_f1cl), path = "f1.rs")] |
| 8 | #[cfg_attr(rcc_f2, path = "f2.rs")] | 9 | #[cfg_attr(rcc_f2, path = "f2.rs")] |
| @@ -41,13 +42,11 @@ pub struct Clocks { | |||
| 41 | // AHB | 42 | // AHB |
| 42 | pub ahb1: Hertz, | 43 | pub ahb1: Hertz, |
| 43 | #[cfg(any( | 44 | #[cfg(any( |
| 44 | rcc_l4, rcc_l5, rcc_f2, rcc_f4, rcc_f410, rcc_f7, rcc_h7, rcc_h7ab, rcc_g4, rcc_u5, rcc_wb, | 45 | rcc_l4, rcc_l5, rcc_f2, rcc_f4, rcc_f410, rcc_f7, rcc_h7, rcc_h7ab, rcc_g4, rcc_u5, rcc_wb, rcc_wl5, rcc_wle |
| 45 | rcc_wl5, rcc_wle | ||
| 46 | ))] | 46 | ))] |
| 47 | pub ahb2: Hertz, | 47 | pub ahb2: Hertz, |
| 48 | #[cfg(any( | 48 | #[cfg(any( |
| 49 | rcc_l4, rcc_l5, rcc_f2, rcc_f4, rcc_f410, rcc_f7, rcc_h7, rcc_h7ab, rcc_u5, rcc_wb, | 49 | rcc_l4, rcc_l5, rcc_f2, rcc_f4, rcc_f410, rcc_f7, rcc_h7, rcc_h7ab, rcc_u5, rcc_wb, rcc_wl5, rcc_wle |
| 50 | rcc_wl5, rcc_wle | ||
| 51 | ))] | 50 | ))] |
| 52 | pub ahb3: Hertz, | 51 | pub ahb3: Hertz, |
| 53 | #[cfg(any(rcc_h7, rcc_h7ab))] | 52 | #[cfg(any(rcc_h7, rcc_h7ab))] |
diff --git a/embassy-stm32/src/rcc/u5.rs b/embassy-stm32/src/rcc/u5.rs index ac1cd06c8..74d3a11eb 100644 --- a/embassy-stm32/src/rcc/u5.rs +++ b/embassy-stm32/src/rcc/u5.rs | |||
| @@ -1,7 +1,8 @@ | |||
| 1 | use stm32_metapac::rcc::vals::{Hpre, Msirange, Msirgsel, Pllm, Pllsrc, Ppre, Sw}; | ||
| 2 | |||
| 1 | use crate::pac::{FLASH, RCC}; | 3 | use crate::pac::{FLASH, RCC}; |
| 2 | use crate::rcc::{set_freqs, Clocks}; | 4 | use crate::rcc::{set_freqs, Clocks}; |
| 3 | use crate::time::{Hertz, U32Ext}; | 5 | use crate::time::{Hertz, U32Ext}; |
| 4 | use stm32_metapac::rcc::vals::{Hpre, Msirange, Msirgsel, Pllm, Pllsrc, Ppre, Sw}; | ||
| 5 | 6 | ||
| 6 | /// HSI16 speed | 7 | /// HSI16 speed |
| 7 | pub const HSI16_FREQ: u32 = 16_000_000; | 8 | pub const HSI16_FREQ: u32 = 16_000_000; |
diff --git a/embassy-stm32/src/rcc/wb.rs b/embassy-stm32/src/rcc/wb.rs index eae7c9464..d950e28f8 100644 --- a/embassy-stm32/src/rcc/wb.rs +++ b/embassy-stm32/src/rcc/wb.rs | |||
| @@ -1,7 +1,6 @@ | |||
| 1 | use crate::pac::RCC; | 1 | use crate::pac::RCC; |
| 2 | use crate::rcc::{set_freqs, Clocks}; | 2 | use crate::rcc::{set_freqs, Clocks}; |
| 3 | use crate::time::Hertz; | 3 | use crate::time::{Hertz, U32Ext}; |
| 4 | use crate::time::U32Ext; | ||
| 5 | 4 | ||
| 6 | /// Most of clock setup is copied from stm32l0xx-hal, and adopted to the generated PAC, | 5 | /// Most of clock setup is copied from stm32l0xx-hal, and adopted to the generated PAC, |
| 7 | /// and with the addition of the init function to configure a system clock. | 6 | /// and with the addition of the init function to configure a system clock. |
diff --git a/embassy-stm32/src/rng.rs b/embassy-stm32/src/rng.rs index e74b66237..5b3558c92 100644 --- a/embassy-stm32/src/rng.rs +++ b/embassy-stm32/src/rng.rs | |||
| @@ -1,15 +1,14 @@ | |||
| 1 | #![macro_use] | 1 | #![macro_use] |
| 2 | 2 | ||
| 3 | use crate::Unborrow; | ||
| 4 | use core::marker::PhantomData; | 3 | use core::marker::PhantomData; |
| 5 | use core::task::Poll; | 4 | use core::task::Poll; |
| 5 | |||
| 6 | use embassy::waitqueue::AtomicWaker; | 6 | use embassy::waitqueue::AtomicWaker; |
| 7 | use embassy_hal_common::unborrow; | 7 | use embassy_hal_common::unborrow; |
| 8 | use futures::future::poll_fn; | 8 | use futures::future::poll_fn; |
| 9 | use rand_core::{CryptoRng, RngCore}; | 9 | use rand_core::{CryptoRng, RngCore}; |
| 10 | 10 | ||
| 11 | use crate::pac; | 11 | use crate::{pac, peripherals, Unborrow}; |
| 12 | use crate::peripherals; | ||
| 13 | 12 | ||
| 14 | pub(crate) static RNG_WAKER: AtomicWaker = AtomicWaker::new(); | 13 | pub(crate) static RNG_WAKER: AtomicWaker = AtomicWaker::new(); |
| 15 | 14 | ||
diff --git a/embassy-stm32/src/sdmmc/mod.rs b/embassy-stm32/src/sdmmc/mod.rs index a7290e74c..1ebf91b3f 100644 --- a/embassy-stm32/src/sdmmc/mod.rs +++ b/embassy-stm32/src/sdmmc/mod.rs | |||
| @@ -4,8 +4,6 @@ use core::default::Default; | |||
| 4 | use core::marker::PhantomData; | 4 | use core::marker::PhantomData; |
| 5 | use core::task::Poll; | 5 | use core::task::Poll; |
| 6 | 6 | ||
| 7 | use crate::interrupt::InterruptExt; | ||
| 8 | use crate::Unborrow; | ||
| 9 | use embassy::waitqueue::AtomicWaker; | 7 | use embassy::waitqueue::AtomicWaker; |
| 10 | use embassy_hal_common::drop::OnDrop; | 8 | use embassy_hal_common::drop::OnDrop; |
| 11 | use embassy_hal_common::unborrow; | 9 | use embassy_hal_common::unborrow; |
| @@ -15,11 +13,11 @@ use sdio_host::{BusWidth, CardCapacity, CardStatus, CurrentState, SDStatus, CID, | |||
| 15 | use crate::dma::NoDma; | 13 | use crate::dma::NoDma; |
| 16 | use crate::gpio::sealed::AFType; | 14 | use crate::gpio::sealed::AFType; |
| 17 | use crate::gpio::{Pull, Speed}; | 15 | use crate::gpio::{Pull, Speed}; |
| 18 | use crate::interrupt::Interrupt; | 16 | use crate::interrupt::{Interrupt, InterruptExt}; |
| 19 | use crate::pac::sdmmc::Sdmmc as RegBlock; | 17 | use crate::pac::sdmmc::Sdmmc as RegBlock; |
| 20 | use crate::peripherals; | ||
| 21 | use crate::rcc::RccPeripheral; | 18 | use crate::rcc::RccPeripheral; |
| 22 | use crate::time::Hertz; | 19 | use crate::time::Hertz; |
| 20 | use crate::{peripherals, Unborrow}; | ||
| 23 | 21 | ||
| 24 | /// The signalling scheme used on the SDMMC bus | 22 | /// The signalling scheme used on the SDMMC bus |
| 25 | #[non_exhaustive] | 23 | #[non_exhaustive] |
| @@ -283,11 +281,7 @@ impl<'d, T: Instance, P: Pins<T>, Dma: SdmmcDma<T>> Sdmmc<'d, T, P, Dma> { | |||
| 283 | } | 281 | } |
| 284 | 282 | ||
| 285 | #[inline(always)] | 283 | #[inline(always)] |
| 286 | pub async fn read_block( | 284 | pub async fn read_block(&mut self, block_idx: u32, buffer: &mut DataBlock) -> Result<(), Error> { |
| 287 | &mut self, | ||
| 288 | block_idx: u32, | ||
| 289 | buffer: &mut DataBlock, | ||
| 290 | ) -> Result<(), Error> { | ||
| 291 | let card_capacity = self.card()?.card_type; | 285 | let card_capacity = self.card()?.card_type; |
| 292 | let inner = T::inner(); | 286 | let inner = T::inner(); |
| 293 | let state = T::state(); | 287 | let state = T::state(); |
| @@ -475,8 +469,7 @@ impl SdmmcInner { | |||
| 475 | 469 | ||
| 476 | self.select_card(Some(&card))?; | 470 | self.select_card(Some(&card))?; |
| 477 | 471 | ||
| 478 | self.get_scr(&mut card, waker_reg, data_transfer_timeout, dma) | 472 | self.get_scr(&mut card, waker_reg, data_transfer_timeout, dma).await?; |
| 479 | .await?; | ||
| 480 | 473 | ||
| 481 | // Set bus width | 474 | // Set bus width |
| 482 | let (width, acmd_arg) = match bus_width { | 475 | let (width, acmd_arg) = match bus_width { |
| @@ -515,12 +508,7 @@ impl SdmmcInner { | |||
| 515 | if freq.0 > 25_000_000 { | 508 | if freq.0 > 25_000_000 { |
| 516 | // Switch to SDR25 | 509 | // Switch to SDR25 |
| 517 | *signalling = self | 510 | *signalling = self |
| 518 | .switch_signalling_mode( | 511 | .switch_signalling_mode(Signalling::SDR25, waker_reg, data_transfer_timeout, dma) |
| 519 | Signalling::SDR25, | ||
| 520 | waker_reg, | ||
| 521 | data_transfer_timeout, | ||
| 522 | dma, | ||
| 523 | ) | ||
| 524 | .await?; | 512 | .await?; |
| 525 | 513 | ||
| 526 | if *signalling == Signalling::SDR25 { | 514 | if *signalling == Signalling::SDR25 { |
| @@ -562,13 +550,7 @@ impl SdmmcInner { | |||
| 562 | let on_drop = OnDrop::new(|| unsafe { self.on_drop() }); | 550 | let on_drop = OnDrop::new(|| unsafe { self.on_drop() }); |
| 563 | 551 | ||
| 564 | unsafe { | 552 | unsafe { |
| 565 | self.prepare_datapath_read( | 553 | self.prepare_datapath_read(buffer as *mut [u32; 128], 512, 9, data_transfer_timeout, dma); |
| 566 | buffer as *mut [u32; 128], | ||
| 567 | 512, | ||
| 568 | 9, | ||
| 569 | data_transfer_timeout, | ||
| 570 | dma, | ||
| 571 | ); | ||
| 572 | self.data_interrupts(true); | 554 | self.data_interrupts(true); |
| 573 | } | 555 | } |
| 574 | self.cmd(Cmd::read_single_block(address), true)?; | 556 | self.cmd(Cmd::read_single_block(address), true)?; |
| @@ -617,13 +599,7 @@ impl SdmmcInner { | |||
| 617 | let on_drop = OnDrop::new(|| unsafe { self.on_drop() }); | 599 | let on_drop = OnDrop::new(|| unsafe { self.on_drop() }); |
| 618 | 600 | ||
| 619 | unsafe { | 601 | unsafe { |
| 620 | self.prepare_datapath_write( | 602 | self.prepare_datapath_write(buffer as *const [u32; 128], 512, 9, data_transfer_timeout, dma); |
| 621 | buffer as *const [u32; 128], | ||
| 622 | 512, | ||
| 623 | 9, | ||
| 624 | data_transfer_timeout, | ||
| 625 | dma, | ||
| 626 | ); | ||
| 627 | self.data_interrupts(true); | 603 | self.data_interrupts(true); |
| 628 | } | 604 | } |
| 629 | self.cmd(Cmd::write_single_block(address), true)?; | 605 | self.cmd(Cmd::write_single_block(address), true)?; |
| @@ -654,10 +630,7 @@ impl SdmmcInner { | |||
| 654 | 630 | ||
| 655 | // Try to read card status (ACMD13) | 631 | // Try to read card status (ACMD13) |
| 656 | while timeout > 0 { | 632 | while timeout > 0 { |
| 657 | match self | 633 | match self.read_sd_status(card, waker_reg, data_transfer_timeout, dma).await { |
| 658 | .read_sd_status(card, waker_reg, data_transfer_timeout, dma) | ||
| 659 | .await | ||
| 660 | { | ||
| 661 | Ok(_) => return Ok(()), | 634 | Ok(_) => return Ok(()), |
| 662 | Err(Error::Timeout) => (), // Try again | 635 | Err(Error::Timeout) => (), // Try again |
| 663 | Err(e) => return Err(e), | 636 | Err(e) => return Err(e), |
| @@ -732,8 +705,7 @@ impl SdmmcInner { | |||
| 732 | 705 | ||
| 733 | // NOTE(unsafe) We have exclusive access to the regisers | 706 | // NOTE(unsafe) We have exclusive access to the regisers |
| 734 | 707 | ||
| 735 | regs.dtimer() | 708 | regs.dtimer().write(|w| w.set_datatime(data_transfer_timeout)); |
| 736 | .write(|w| w.set_datatime(data_transfer_timeout)); | ||
| 737 | regs.dlenr().write(|w| w.set_datalength(length_bytes)); | 709 | regs.dlenr().write(|w| w.set_datalength(length_bytes)); |
| 738 | 710 | ||
| 739 | cfg_if::cfg_if! { | 711 | cfg_if::cfg_if! { |
| @@ -781,8 +753,7 @@ impl SdmmcInner { | |||
| 781 | 753 | ||
| 782 | // NOTE(unsafe) We have exclusive access to the regisers | 754 | // NOTE(unsafe) We have exclusive access to the regisers |
| 783 | 755 | ||
| 784 | regs.dtimer() | 756 | regs.dtimer().write(|w| w.set_datatime(data_transfer_timeout)); |
| 785 | .write(|w| w.set_datatime(data_transfer_timeout)); | ||
| 786 | regs.dlenr().write(|w| w.set_datalength(length_bytes)); | 757 | regs.dlenr().write(|w| w.set_datalength(length_bytes)); |
| 787 | 758 | ||
| 788 | cfg_if::cfg_if! { | 759 | cfg_if::cfg_if! { |
| @@ -824,13 +795,7 @@ impl SdmmcInner { | |||
| 824 | } | 795 | } |
| 825 | 796 | ||
| 826 | /// Sets the CLKDIV field in CLKCR. Updates clock field in self | 797 | /// Sets the CLKDIV field in CLKCR. Updates clock field in self |
| 827 | fn clkcr_set_clkdiv( | 798 | fn clkcr_set_clkdiv(&self, freq: u32, width: BusWidth, ker_ck: Hertz, clock: &mut Hertz) -> Result<(), Error> { |
| 828 | &self, | ||
| 829 | freq: u32, | ||
| 830 | width: BusWidth, | ||
| 831 | ker_ck: Hertz, | ||
| 832 | clock: &mut Hertz, | ||
| 833 | ) -> Result<(), Error> { | ||
| 834 | let regs = self.0; | 799 | let regs = self.0; |
| 835 | 800 | ||
| 836 | let (clkdiv, new_clock) = clk_div(ker_ck, freq)?; | 801 | let (clkdiv, new_clock) = clk_div(ker_ck, freq)?; |
| @@ -882,13 +847,7 @@ impl SdmmcInner { | |||
| 882 | let on_drop = OnDrop::new(|| unsafe { self.on_drop() }); | 847 | let on_drop = OnDrop::new(|| unsafe { self.on_drop() }); |
| 883 | 848 | ||
| 884 | unsafe { | 849 | unsafe { |
| 885 | self.prepare_datapath_read( | 850 | self.prepare_datapath_read(&mut status as *mut [u32; 16], 64, 6, data_transfer_timeout, dma); |
| 886 | &mut status as *mut [u32; 16], | ||
| 887 | 64, | ||
| 888 | 6, | ||
| 889 | data_transfer_timeout, | ||
| 890 | dma, | ||
| 891 | ); | ||
| 892 | self.data_interrupts(true); | 851 | self.data_interrupts(true); |
| 893 | } | 852 | } |
| 894 | self.cmd(Cmd::cmd6(set_function), true)?; // CMD6 | 853 | self.cmd(Cmd::cmd6(set_function), true)?; // CMD6 |
| @@ -970,13 +929,7 @@ impl SdmmcInner { | |||
| 970 | let on_drop = OnDrop::new(|| unsafe { self.on_drop() }); | 929 | let on_drop = OnDrop::new(|| unsafe { self.on_drop() }); |
| 971 | 930 | ||
| 972 | unsafe { | 931 | unsafe { |
| 973 | self.prepare_datapath_read( | 932 | self.prepare_datapath_read(&mut status as *mut [u32; 16], 64, 6, data_transfer_timeout, dma); |
| 974 | &mut status as *mut [u32; 16], | ||
| 975 | 64, | ||
| 976 | 6, | ||
| 977 | data_transfer_timeout, | ||
| 978 | dma, | ||
| 979 | ); | ||
| 980 | self.data_interrupts(true); | 933 | self.data_interrupts(true); |
| 981 | } | 934 | } |
| 982 | self.cmd(Cmd::card_status(0), true)?; | 935 | self.cmd(Cmd::card_status(0), true)?; |
| @@ -1473,10 +1426,12 @@ foreach_peripheral!( | |||
| 1473 | 1426 | ||
| 1474 | #[cfg(feature = "sdmmc-rs")] | 1427 | #[cfg(feature = "sdmmc-rs")] |
| 1475 | mod sdmmc_rs { | 1428 | mod sdmmc_rs { |
| 1476 | use super::*; | ||
| 1477 | use core::future::Future; | 1429 | use core::future::Future; |
| 1430 | |||
| 1478 | use embedded_sdmmc::{Block, BlockCount, BlockDevice, BlockIdx}; | 1431 | use embedded_sdmmc::{Block, BlockCount, BlockDevice, BlockIdx}; |
| 1479 | 1432 | ||
| 1433 | use super::*; | ||
| 1434 | |||
| 1480 | impl<'d, T: Instance, P: Pins<T>> BlockDevice for Sdmmc<'d, T, P> { | 1435 | impl<'d, T: Instance, P: Pins<T>> BlockDevice for Sdmmc<'d, T, P> { |
| 1481 | type Error = Error; | 1436 | type Error = Error; |
| 1482 | type ReadFuture<'a> | 1437 | type ReadFuture<'a> |
| @@ -1506,13 +1461,7 @@ mod sdmmc_rs { | |||
| 1506 | // NOTE(unsafe) Block uses align(4) | 1461 | // NOTE(unsafe) Block uses align(4) |
| 1507 | let buf = unsafe { &mut *(block as *mut [u8; 512] as *mut [u32; 128]) }; | 1462 | let buf = unsafe { &mut *(block as *mut [u8; 512] as *mut [u32; 128]) }; |
| 1508 | inner | 1463 | inner |
| 1509 | .read_block( | 1464 | .read_block(address, buf, card_capacity, state, self.config.data_transfer_timeout) |
| 1510 | address, | ||
| 1511 | buf, | ||
| 1512 | card_capacity, | ||
| 1513 | state, | ||
| 1514 | self.config.data_transfer_timeout, | ||
| 1515 | ) | ||
| 1516 | .await?; | 1465 | .await?; |
| 1517 | address += 1; | 1466 | address += 1; |
| 1518 | } | 1467 | } |
| @@ -1520,11 +1469,7 @@ mod sdmmc_rs { | |||
| 1520 | } | 1469 | } |
| 1521 | } | 1470 | } |
| 1522 | 1471 | ||
| 1523 | fn write<'a>( | 1472 | fn write<'a>(&'a mut self, blocks: &'a [Block], start_block_idx: BlockIdx) -> Self::WriteFuture<'a> { |
| 1524 | &'a mut self, | ||
| 1525 | blocks: &'a [Block], | ||
| 1526 | start_block_idx: BlockIdx, | ||
| 1527 | ) -> Self::WriteFuture<'a> { | ||
| 1528 | async move { | 1473 | async move { |
| 1529 | let card = self.card.as_mut().ok_or(Error::NoCard)?; | 1474 | let card = self.card.as_mut().ok_or(Error::NoCard)?; |
| 1530 | let inner = T::inner(); | 1475 | let inner = T::inner(); |
diff --git a/embassy-stm32/src/spi/mod.rs b/embassy-stm32/src/spi/mod.rs index 3cdc87c70..7c142e507 100644 --- a/embassy-stm32/src/spi/mod.rs +++ b/embassy-stm32/src/spi/mod.rs | |||
| @@ -1,22 +1,20 @@ | |||
| 1 | #![macro_use] | 1 | #![macro_use] |
| 2 | 2 | ||
| 3 | use crate::Unborrow; | ||
| 4 | use core::marker::PhantomData; | 3 | use core::marker::PhantomData; |
| 5 | use core::ptr; | 4 | use core::ptr; |
| 5 | |||
| 6 | use embassy_hal_common::unborrow; | 6 | use embassy_hal_common::unborrow; |
| 7 | pub use embedded_hal_02::spi::{Mode, Phase, Polarity, MODE_0, MODE_1, MODE_2, MODE_3}; | ||
| 7 | use futures::future::join; | 8 | use futures::future::join; |
| 8 | 9 | ||
| 9 | use self::sealed::WordSize; | 10 | use self::sealed::WordSize; |
| 10 | use crate::dma::{slice_ptr_parts, NoDma, Transfer}; | 11 | use crate::dma::{slice_ptr_parts, NoDma, Transfer}; |
| 11 | use crate::gpio::sealed::{AFType, Pin as _}; | 12 | use crate::gpio::sealed::{AFType, Pin as _}; |
| 12 | use crate::gpio::AnyPin; | 13 | use crate::gpio::AnyPin; |
| 13 | use crate::pac::spi::Spi as Regs; | 14 | use crate::pac::spi::{regs, vals, Spi as Regs}; |
| 14 | use crate::pac::spi::{regs, vals}; | ||
| 15 | use crate::peripherals; | ||
| 16 | use crate::rcc::RccPeripheral; | 15 | use crate::rcc::RccPeripheral; |
| 17 | use crate::time::Hertz; | 16 | use crate::time::Hertz; |
| 18 | 17 | use crate::{peripherals, Unborrow}; | |
| 19 | pub use embedded_hal_02::spi::{Mode, Phase, Polarity, MODE_0, MODE_1, MODE_2, MODE_3}; | ||
| 20 | 18 | ||
| 21 | #[derive(Debug)] | 19 | #[derive(Debug)] |
| 22 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | 20 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] |
| @@ -423,10 +421,7 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> { | |||
| 423 | 421 | ||
| 424 | let tx_request = self.txdma.request(); | 422 | let tx_request = self.txdma.request(); |
| 425 | let tx_dst = T::REGS.tx_ptr(); | 423 | let tx_dst = T::REGS.tx_ptr(); |
| 426 | unsafe { | 424 | unsafe { self.txdma.start_write(tx_request, data, tx_dst, Default::default()) } |
| 427 | self.txdma | ||
| 428 | .start_write(tx_request, data, tx_dst, Default::default()) | ||
| 429 | } | ||
| 430 | let tx_f = Transfer::new(&mut self.txdma); | 425 | let tx_f = Transfer::new(&mut self.txdma); |
| 431 | 426 | ||
| 432 | unsafe { | 427 | unsafe { |
| @@ -472,22 +467,13 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> { | |||
| 472 | 467 | ||
| 473 | let rx_request = self.rxdma.request(); | 468 | let rx_request = self.rxdma.request(); |
| 474 | let rx_src = T::REGS.rx_ptr(); | 469 | let rx_src = T::REGS.rx_ptr(); |
| 475 | unsafe { | 470 | unsafe { self.rxdma.start_read(rx_request, rx_src, data, Default::default()) }; |
| 476 | self.rxdma | ||
| 477 | .start_read(rx_request, rx_src, data, Default::default()) | ||
| 478 | }; | ||
| 479 | let rx_f = Transfer::new(&mut self.rxdma); | 471 | let rx_f = Transfer::new(&mut self.rxdma); |
| 480 | 472 | ||
| 481 | let tx_request = self.txdma.request(); | 473 | let tx_request = self.txdma.request(); |
| 482 | let tx_dst = T::REGS.tx_ptr(); | 474 | let tx_dst = T::REGS.tx_ptr(); |
| 483 | let clock_byte = 0x00u8; | 475 | let clock_byte = 0x00u8; |
| 484 | let tx_f = crate::dma::write_repeated( | 476 | let tx_f = crate::dma::write_repeated(&mut self.txdma, tx_request, clock_byte, clock_byte_count, tx_dst); |
| 485 | &mut self.txdma, | ||
| 486 | tx_request, | ||
| 487 | clock_byte, | ||
| 488 | clock_byte_count, | ||
| 489 | tx_dst, | ||
| 490 | ); | ||
| 491 | 477 | ||
| 492 | unsafe { | 478 | unsafe { |
| 493 | set_txdmaen(T::REGS, true); | 479 | set_txdmaen(T::REGS, true); |
| @@ -507,11 +493,7 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> { | |||
| 507 | Ok(()) | 493 | Ok(()) |
| 508 | } | 494 | } |
| 509 | 495 | ||
| 510 | async fn transfer_inner<W: Word>( | 496 | async fn transfer_inner<W: Word>(&mut self, read: *mut [W], write: *const [W]) -> Result<(), Error> |
| 511 | &mut self, | ||
| 512 | read: *mut [W], | ||
| 513 | write: *const [W], | ||
| 514 | ) -> Result<(), Error> | ||
| 515 | where | 497 | where |
| 516 | Tx: TxDma<T>, | 498 | Tx: TxDma<T>, |
| 517 | Rx: RxDma<T>, | 499 | Rx: RxDma<T>, |
| @@ -537,18 +519,12 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> { | |||
| 537 | 519 | ||
| 538 | let rx_request = self.rxdma.request(); | 520 | let rx_request = self.rxdma.request(); |
| 539 | let rx_src = T::REGS.rx_ptr(); | 521 | let rx_src = T::REGS.rx_ptr(); |
| 540 | unsafe { | 522 | unsafe { self.rxdma.start_read(rx_request, rx_src, read, Default::default()) }; |
| 541 | self.rxdma | ||
| 542 | .start_read(rx_request, rx_src, read, Default::default()) | ||
| 543 | }; | ||
| 544 | let rx_f = Transfer::new(&mut self.rxdma); | 523 | let rx_f = Transfer::new(&mut self.rxdma); |
| 545 | 524 | ||
| 546 | let tx_request = self.txdma.request(); | 525 | let tx_request = self.txdma.request(); |
| 547 | let tx_dst = T::REGS.tx_ptr(); | 526 | let tx_dst = T::REGS.tx_ptr(); |
| 548 | unsafe { | 527 | unsafe { self.txdma.start_write(tx_request, write, tx_dst, Default::default()) } |
| 549 | self.txdma | ||
| 550 | .start_write(tx_request, write, tx_dst, Default::default()) | ||
| 551 | } | ||
| 552 | let tx_f = Transfer::new(&mut self.txdma); | 528 | let tx_f = Transfer::new(&mut self.txdma); |
| 553 | 529 | ||
| 554 | unsafe { | 530 | unsafe { |
| @@ -835,9 +811,7 @@ mod eh02 { | |||
| 835 | // some marker traits. For details, see https://github.com/rust-embedded/embedded-hal/pull/289 | 811 | // some marker traits. For details, see https://github.com/rust-embedded/embedded-hal/pull/289 |
| 836 | macro_rules! impl_blocking { | 812 | macro_rules! impl_blocking { |
| 837 | ($w:ident) => { | 813 | ($w:ident) => { |
| 838 | impl<'d, T: Instance> embedded_hal_02::blocking::spi::Write<$w> | 814 | impl<'d, T: Instance> embedded_hal_02::blocking::spi::Write<$w> for Spi<'d, T, NoDma, NoDma> { |
| 839 | for Spi<'d, T, NoDma, NoDma> | ||
| 840 | { | ||
| 841 | type Error = Error; | 815 | type Error = Error; |
| 842 | 816 | ||
| 843 | fn write(&mut self, words: &[$w]) -> Result<(), Self::Error> { | 817 | fn write(&mut self, words: &[$w]) -> Result<(), Self::Error> { |
| @@ -845,9 +819,7 @@ mod eh02 { | |||
| 845 | } | 819 | } |
| 846 | } | 820 | } |
| 847 | 821 | ||
| 848 | impl<'d, T: Instance> embedded_hal_02::blocking::spi::Transfer<$w> | 822 | impl<'d, T: Instance> embedded_hal_02::blocking::spi::Transfer<$w> for Spi<'d, T, NoDma, NoDma> { |
| 849 | for Spi<'d, T, NoDma, NoDma> | ||
| 850 | { | ||
| 851 | type Error = Error; | 823 | type Error = Error; |
| 852 | 824 | ||
| 853 | fn transfer<'w>(&mut self, words: &'w mut [$w]) -> Result<&'w [$w], Self::Error> { | 825 | fn transfer<'w>(&mut self, words: &'w mut [$w]) -> Result<&'w [$w], Self::Error> { |
| @@ -876,25 +848,19 @@ mod eh1 { | |||
| 876 | } | 848 | } |
| 877 | } | 849 | } |
| 878 | 850 | ||
| 879 | impl<'d, T: Instance, W: Word> embedded_hal_1::spi::blocking::SpiBusRead<W> | 851 | impl<'d, T: Instance, W: Word> embedded_hal_1::spi::blocking::SpiBusRead<W> for Spi<'d, T, NoDma, NoDma> { |
| 880 | for Spi<'d, T, NoDma, NoDma> | ||
| 881 | { | ||
| 882 | fn read(&mut self, words: &mut [W]) -> Result<(), Self::Error> { | 852 | fn read(&mut self, words: &mut [W]) -> Result<(), Self::Error> { |
| 883 | self.blocking_read(words) | 853 | self.blocking_read(words) |
| 884 | } | 854 | } |
| 885 | } | 855 | } |
| 886 | 856 | ||
| 887 | impl<'d, T: Instance, W: Word> embedded_hal_1::spi::blocking::SpiBusWrite<W> | 857 | impl<'d, T: Instance, W: Word> embedded_hal_1::spi::blocking::SpiBusWrite<W> for Spi<'d, T, NoDma, NoDma> { |
| 888 | for Spi<'d, T, NoDma, NoDma> | ||
| 889 | { | ||
| 890 | fn write(&mut self, words: &[W]) -> Result<(), Self::Error> { | 858 | fn write(&mut self, words: &[W]) -> Result<(), Self::Error> { |
| 891 | self.blocking_write(words) | 859 | self.blocking_write(words) |
| 892 | } | 860 | } |
| 893 | } | 861 | } |
| 894 | 862 | ||
| 895 | impl<'d, T: Instance, W: Word> embedded_hal_1::spi::blocking::SpiBus<W> | 863 | impl<'d, T: Instance, W: Word> embedded_hal_1::spi::blocking::SpiBus<W> for Spi<'d, T, NoDma, NoDma> { |
| 896 | for Spi<'d, T, NoDma, NoDma> | ||
| 897 | { | ||
| 898 | fn transfer(&mut self, read: &mut [W], write: &[W]) -> Result<(), Self::Error> { | 864 | fn transfer(&mut self, read: &mut [W], write: &[W]) -> Result<(), Self::Error> { |
| 899 | self.blocking_transfer(read, write) | 865 | self.blocking_transfer(read, write) |
| 900 | } | 866 | } |
diff --git a/embassy-stm32/src/subghz/mod.rs b/embassy-stm32/src/subghz/mod.rs index 6736324ce..3b64932fa 100644 --- a/embassy-stm32/src/subghz/mod.rs +++ b/embassy-stm32/src/subghz/mod.rs | |||
| @@ -43,19 +43,20 @@ mod value_error; | |||
| 43 | pub use bit_sync::BitSync; | 43 | pub use bit_sync::BitSync; |
| 44 | pub use cad_params::{CadParams, ExitMode, NbCadSymbol}; | 44 | pub use cad_params::{CadParams, ExitMode, NbCadSymbol}; |
| 45 | pub use calibrate::{Calibrate, CalibrateImage}; | 45 | pub use calibrate::{Calibrate, CalibrateImage}; |
| 46 | use embassy_hal_common::ratio::Ratio; | ||
| 46 | pub use fallback_mode::FallbackMode; | 47 | pub use fallback_mode::FallbackMode; |
| 47 | pub use hse_trim::HseTrim; | 48 | pub use hse_trim::HseTrim; |
| 48 | pub use irq::{CfgIrq, Irq, IrqLine}; | 49 | pub use irq::{CfgIrq, Irq, IrqLine}; |
| 49 | pub use lora_sync_word::LoRaSyncWord; | 50 | pub use lora_sync_word::LoRaSyncWord; |
| 50 | pub use mod_params::BpskModParams; | 51 | pub use mod_params::{ |
| 51 | pub use mod_params::{CodingRate, LoRaBandwidth, LoRaModParams, SpreadingFactor}; | 52 | BpskModParams, CodingRate, FskBandwidth, FskBitrate, FskFdev, FskModParams, FskPulseShape, LoRaBandwidth, |
| 52 | pub use mod_params::{FskBandwidth, FskBitrate, FskFdev, FskModParams, FskPulseShape}; | 53 | LoRaModParams, SpreadingFactor, |
| 54 | }; | ||
| 53 | pub use ocp::Ocp; | 55 | pub use ocp::Ocp; |
| 54 | pub use op_error::OpError; | 56 | pub use op_error::OpError; |
| 55 | pub use pa_config::{PaConfig, PaSel}; | 57 | pub use pa_config::{PaConfig, PaSel}; |
| 56 | pub use packet_params::{ | 58 | pub use packet_params::{ |
| 57 | AddrComp, BpskPacketParams, CrcType, GenericPacketParams, HeaderType, LoRaPacketParams, | 59 | AddrComp, BpskPacketParams, CrcType, GenericPacketParams, HeaderType, LoRaPacketParams, PreambleDetection, |
| 58 | PreambleDetection, | ||
| 59 | }; | 60 | }; |
| 60 | pub use packet_status::{FskPacketStatus, LoRaPacketStatus}; | 61 | pub use packet_status::{FskPacketStatus, LoRaPacketStatus}; |
| 61 | pub use packet_type::PacketType; | 62 | pub use packet_type::PacketType; |
| @@ -75,17 +76,12 @@ pub use timeout::Timeout; | |||
| 75 | pub use tx_params::{RampTime, TxParams}; | 76 | pub use tx_params::{RampTime, TxParams}; |
| 76 | pub use value_error::ValueError; | 77 | pub use value_error::ValueError; |
| 77 | 78 | ||
| 78 | use embassy_hal_common::ratio::Ratio; | 79 | use crate::dma::NoDma; |
| 79 | 80 | use crate::peripherals::SUBGHZSPI; | |
| 80 | use crate::Unborrow; | 81 | use crate::rcc::sealed::RccPeripheral; |
| 81 | use crate::{ | 82 | use crate::spi::{BitOrder, Config as SpiConfig, MisoPin, MosiPin, SckPin, Spi, MODE_0}; |
| 82 | dma::NoDma, | 83 | use crate::time::Hertz; |
| 83 | pac, | 84 | use crate::{pac, Unborrow}; |
| 84 | peripherals::SUBGHZSPI, | ||
| 85 | rcc::sealed::RccPeripheral, | ||
| 86 | spi::{BitOrder, Config as SpiConfig, MisoPin, MosiPin, SckPin, Spi, MODE_0}, | ||
| 87 | time::Hertz, | ||
| 88 | }; | ||
| 89 | 85 | ||
| 90 | /// Passthrough for SPI errors (for now) | 86 | /// Passthrough for SPI errors (for now) |
| 91 | pub type Error = crate::spi::Error; | 87 | pub type Error = crate::spi::Error; |
| @@ -105,8 +101,7 @@ impl Nss { | |||
| 105 | fn clear() { | 101 | fn clear() { |
| 106 | let pwr = pac::PWR; | 102 | let pwr = pac::PWR; |
| 107 | unsafe { | 103 | unsafe { |
| 108 | pwr.subghzspicr() | 104 | pwr.subghzspicr().modify(|w| w.set_nss(pac::pwr::vals::Nss::LOW)); |
| 109 | .modify(|w| w.set_nss(pac::pwr::vals::Nss::LOW)); | ||
| 110 | } | 105 | } |
| 111 | } | 106 | } |
| 112 | 107 | ||
| @@ -115,8 +110,7 @@ impl Nss { | |||
| 115 | fn set() { | 110 | fn set() { |
| 116 | let pwr = pac::PWR; | 111 | let pwr = pac::PWR; |
| 117 | unsafe { | 112 | unsafe { |
| 118 | pwr.subghzspicr() | 113 | pwr.subghzspicr().modify(|w| w.set_nss(pac::pwr::vals::Nss::HIGH)); |
| 119 | .modify(|w| w.set_nss(pac::pwr::vals::Nss::HIGH)); | ||
| 120 | } | 114 | } |
| 121 | } | 115 | } |
| 122 | } | 116 | } |
| @@ -286,8 +280,7 @@ impl<'d> SubGhz<'d, NoDma, NoDma> { | |||
| 286 | self.poll_not_busy(); | 280 | self.poll_not_busy(); |
| 287 | { | 281 | { |
| 288 | let _nss: Nss = Nss::new(); | 282 | let _nss: Nss = Nss::new(); |
| 289 | self.spi | 283 | self.spi.blocking_write(&[OpCode::WriteBuffer as u8, offset])?; |
| 290 | .blocking_write(&[OpCode::WriteBuffer as u8, offset])?; | ||
| 291 | self.spi.blocking_write(data)?; | 284 | self.spi.blocking_write(data)?; |
| 292 | } | 285 | } |
| 293 | self.poll_not_busy(); | 286 | self.poll_not_busy(); |
| @@ -305,8 +298,7 @@ impl<'d> SubGhz<'d, NoDma, NoDma> { | |||
| 305 | self.poll_not_busy(); | 298 | self.poll_not_busy(); |
| 306 | { | 299 | { |
| 307 | let _nss: Nss = Nss::new(); | 300 | let _nss: Nss = Nss::new(); |
| 308 | self.spi | 301 | self.spi.blocking_write(&[OpCode::ReadBuffer as u8, offset])?; |
| 309 | .blocking_write(&[OpCode::ReadBuffer as u8, offset])?; | ||
| 310 | self.spi.blocking_transfer_in_place(&mut status_buf)?; | 302 | self.spi.blocking_transfer_in_place(&mut status_buf)?; |
| 311 | self.spi.blocking_transfer_in_place(buf)?; | 303 | self.spi.blocking_transfer_in_place(buf)?; |
| 312 | } | 304 | } |
| @@ -678,10 +670,7 @@ impl<'d> SubGhz<'d, NoDma, NoDma> { | |||
| 678 | /// # Ok::<(), embassy_stm32::subghz::Error>(()) | 670 | /// # Ok::<(), embassy_stm32::subghz::Error>(()) |
| 679 | /// ``` | 671 | /// ``` |
| 680 | pub fn set_rx_timeout_stop(&mut self, rx_timeout_stop: RxTimeoutStop) -> Result<(), Error> { | 672 | pub fn set_rx_timeout_stop(&mut self, rx_timeout_stop: RxTimeoutStop) -> Result<(), Error> { |
| 681 | self.write(&[ | 673 | self.write(&[OpCode::SetStopRxTimerOnPreamble.into(), rx_timeout_stop.into()]) |
| 682 | OpCode::SetStopRxTimerOnPreamble.into(), | ||
| 683 | rx_timeout_stop.into(), | ||
| 684 | ]) | ||
| 685 | } | 674 | } |
| 686 | 675 | ||
| 687 | /// Put the radio in non-continuous RX mode. | 676 | /// Put the radio in non-continuous RX mode. |
| @@ -730,11 +719,7 @@ impl<'d> SubGhz<'d, NoDma, NoDma> { | |||
| 730 | /// [`RxDone`]: crate::subghz::Irq::RxDone | 719 | /// [`RxDone`]: crate::subghz::Irq::RxDone |
| 731 | /// [`set_rf_frequency`]: crate::subghz::SubGhz::set_rf_frequency | 720 | /// [`set_rf_frequency`]: crate::subghz::SubGhz::set_rf_frequency |
| 732 | /// [`set_standby`]: crate::subghz::SubGhz::set_standby | 721 | /// [`set_standby`]: crate::subghz::SubGhz::set_standby |
| 733 | pub fn set_rx_duty_cycle( | 722 | pub fn set_rx_duty_cycle(&mut self, rx_period: Timeout, sleep_period: Timeout) -> Result<(), Error> { |
| 734 | &mut self, | ||
| 735 | rx_period: Timeout, | ||
| 736 | sleep_period: Timeout, | ||
| 737 | ) -> Result<(), Error> { | ||
| 738 | let rx_period_bits: u32 = rx_period.into_bits(); | 723 | let rx_period_bits: u32 = rx_period.into_bits(); |
| 739 | let sleep_period_bits: u32 = sleep_period.into_bits(); | 724 | let sleep_period_bits: u32 = sleep_period.into_bits(); |
| 740 | self.write(&[ | 725 | self.write(&[ |
| @@ -1288,9 +1273,7 @@ impl<'d> SubGhz<'d, NoDma, NoDma> { | |||
| 1288 | /// # Ok::<(), embassy_stm32::subghz::Error>(()) | 1273 | /// # Ok::<(), embassy_stm32::subghz::Error>(()) |
| 1289 | /// ``` | 1274 | /// ``` |
| 1290 | pub fn lora_packet_status(&mut self) -> Result<LoRaPacketStatus, Error> { | 1275 | pub fn lora_packet_status(&mut self) -> Result<LoRaPacketStatus, Error> { |
| 1291 | Ok(LoRaPacketStatus::from( | 1276 | Ok(LoRaPacketStatus::from(self.read_n(OpCode::GetPacketStatus)?)) |
| 1292 | self.read_n(OpCode::GetPacketStatus)?, | ||
| 1293 | )) | ||
| 1294 | } | 1277 | } |
| 1295 | 1278 | ||
| 1296 | /// Get the instantaneous signal strength during packet reception. | 1279 | /// Get the instantaneous signal strength during packet reception. |
diff --git a/embassy-stm32/src/subghz/pa_config.rs b/embassy-stm32/src/subghz/pa_config.rs index 8da4ba400..9833368c4 100644 --- a/embassy-stm32/src/subghz/pa_config.rs +++ b/embassy-stm32/src/subghz/pa_config.rs | |||
| @@ -13,58 +13,37 @@ impl PaConfig { | |||
| 13 | /// Optimal settings for +15dBm output power with the low-power PA. | 13 | /// Optimal settings for +15dBm output power with the low-power PA. |
| 14 | /// | 14 | /// |
| 15 | /// This must be used with [`TxParams::LP_15`](super::TxParams::LP_15). | 15 | /// This must be used with [`TxParams::LP_15`](super::TxParams::LP_15). |
| 16 | pub const LP_15: PaConfig = PaConfig::new() | 16 | pub const LP_15: PaConfig = PaConfig::new().set_pa_duty_cycle(0x6).set_hp_max(0x0).set_pa(PaSel::Lp); |
| 17 | .set_pa_duty_cycle(0x6) | ||
| 18 | .set_hp_max(0x0) | ||
| 19 | .set_pa(PaSel::Lp); | ||
| 20 | 17 | ||
| 21 | /// Optimal settings for +14dBm output power with the low-power PA. | 18 | /// Optimal settings for +14dBm output power with the low-power PA. |
| 22 | /// | 19 | /// |
| 23 | /// This must be used with [`TxParams::LP_14`](super::TxParams::LP_14). | 20 | /// This must be used with [`TxParams::LP_14`](super::TxParams::LP_14). |
| 24 | pub const LP_14: PaConfig = PaConfig::new() | 21 | pub const LP_14: PaConfig = PaConfig::new().set_pa_duty_cycle(0x4).set_hp_max(0x0).set_pa(PaSel::Lp); |
| 25 | .set_pa_duty_cycle(0x4) | ||
| 26 | .set_hp_max(0x0) | ||
| 27 | .set_pa(PaSel::Lp); | ||
| 28 | 22 | ||
| 29 | /// Optimal settings for +10dBm output power with the low-power PA. | 23 | /// Optimal settings for +10dBm output power with the low-power PA. |
| 30 | /// | 24 | /// |
| 31 | /// This must be used with [`TxParams::LP_10`](super::TxParams::LP_10). | 25 | /// This must be used with [`TxParams::LP_10`](super::TxParams::LP_10). |
| 32 | pub const LP_10: PaConfig = PaConfig::new() | 26 | pub const LP_10: PaConfig = PaConfig::new().set_pa_duty_cycle(0x1).set_hp_max(0x0).set_pa(PaSel::Lp); |
| 33 | .set_pa_duty_cycle(0x1) | ||
| 34 | .set_hp_max(0x0) | ||
| 35 | .set_pa(PaSel::Lp); | ||
| 36 | 27 | ||
| 37 | /// Optimal settings for +22dBm output power with the high-power PA. | 28 | /// Optimal settings for +22dBm output power with the high-power PA. |
| 38 | /// | 29 | /// |
| 39 | /// This must be used with [`TxParams::HP`](super::TxParams::HP). | 30 | /// This must be used with [`TxParams::HP`](super::TxParams::HP). |
| 40 | pub const HP_22: PaConfig = PaConfig::new() | 31 | pub const HP_22: PaConfig = PaConfig::new().set_pa_duty_cycle(0x4).set_hp_max(0x7).set_pa(PaSel::Hp); |
| 41 | .set_pa_duty_cycle(0x4) | ||
| 42 | .set_hp_max(0x7) | ||
| 43 | .set_pa(PaSel::Hp); | ||
| 44 | 32 | ||
| 45 | /// Optimal settings for +20dBm output power with the high-power PA. | 33 | /// Optimal settings for +20dBm output power with the high-power PA. |
| 46 | /// | 34 | /// |
| 47 | /// This must be used with [`TxParams::HP`](super::TxParams::HP). | 35 | /// This must be used with [`TxParams::HP`](super::TxParams::HP). |
| 48 | pub const HP_20: PaConfig = PaConfig::new() | 36 | pub const HP_20: PaConfig = PaConfig::new().set_pa_duty_cycle(0x3).set_hp_max(0x5).set_pa(PaSel::Hp); |
| 49 | .set_pa_duty_cycle(0x3) | ||
| 50 | .set_hp_max(0x5) | ||
| 51 | .set_pa(PaSel::Hp); | ||
| 52 | 37 | ||
| 53 | /// Optimal settings for +17dBm output power with the high-power PA. | 38 | /// Optimal settings for +17dBm output power with the high-power PA. |
| 54 | /// | 39 | /// |
| 55 | /// This must be used with [`TxParams::HP`](super::TxParams::HP). | 40 | /// This must be used with [`TxParams::HP`](super::TxParams::HP). |
| 56 | pub const HP_17: PaConfig = PaConfig::new() | 41 | pub const HP_17: PaConfig = PaConfig::new().set_pa_duty_cycle(0x2).set_hp_max(0x3).set_pa(PaSel::Hp); |
| 57 | .set_pa_duty_cycle(0x2) | ||
| 58 | .set_hp_max(0x3) | ||
| 59 | .set_pa(PaSel::Hp); | ||
| 60 | 42 | ||
| 61 | /// Optimal settings for +14dBm output power with the high-power PA. | 43 | /// Optimal settings for +14dBm output power with the high-power PA. |
| 62 | /// | 44 | /// |
| 63 | /// This must be used with [`TxParams::HP`](super::TxParams::HP). | 45 | /// This must be used with [`TxParams::HP`](super::TxParams::HP). |
| 64 | pub const HP_14: PaConfig = PaConfig::new() | 46 | pub const HP_14: PaConfig = PaConfig::new().set_pa_duty_cycle(0x2).set_hp_max(0x2).set_pa(PaSel::Hp); |
| 65 | .set_pa_duty_cycle(0x2) | ||
| 66 | .set_hp_max(0x2) | ||
| 67 | .set_pa(PaSel::Hp); | ||
| 68 | 47 | ||
| 69 | /// Create a new `PaConfig` struct. | 48 | /// Create a new `PaConfig` struct. |
| 70 | /// | 49 | /// |
diff --git a/embassy-stm32/src/subghz/packet_params.rs b/embassy-stm32/src/subghz/packet_params.rs index ae84ea26a..60b13ba4e 100644 --- a/embassy-stm32/src/subghz/packet_params.rs +++ b/embassy-stm32/src/subghz/packet_params.rs | |||
| @@ -147,10 +147,7 @@ impl GenericPacketParams { | |||
| 147 | /// # assert_eq!(PKT_PARAMS.as_slice()[3], 0x4); | 147 | /// # assert_eq!(PKT_PARAMS.as_slice()[3], 0x4); |
| 148 | /// ``` | 148 | /// ``` |
| 149 | #[must_use = "set_preamble_detection returns a modified GenericPacketParams"] | 149 | #[must_use = "set_preamble_detection returns a modified GenericPacketParams"] |
| 150 | pub const fn set_preamble_detection( | 150 | pub const fn set_preamble_detection(mut self, pb_det: PreambleDetection) -> GenericPacketParams { |
| 151 | mut self, | ||
| 152 | pb_det: PreambleDetection, | ||
| 153 | ) -> GenericPacketParams { | ||
| 154 | self.buf[3] = pb_det as u8; | 151 | self.buf[3] = pb_det as u8; |
| 155 | self | 152 | self |
| 156 | } | 153 | } |
diff --git a/embassy-stm32/src/subghz/packet_status.rs b/embassy-stm32/src/subghz/packet_status.rs index 46eded6f1..a4e348d94 100644 --- a/embassy-stm32/src/subghz/packet_status.rs +++ b/embassy-stm32/src/subghz/packet_status.rs | |||
| @@ -1,6 +1,4 @@ | |||
| 1 | use super::Ratio; | 1 | use super::{Ratio, Status}; |
| 2 | |||
| 3 | use super::Status; | ||
| 4 | 2 | ||
| 5 | /// (G)FSK packet status. | 3 | /// (G)FSK packet status. |
| 6 | /// | 4 | /// |
diff --git a/embassy-stm32/src/subghz/rf_frequency.rs b/embassy-stm32/src/subghz/rf_frequency.rs index 54c03dcd8..520dc89d7 100644 --- a/embassy-stm32/src/subghz/rf_frequency.rs +++ b/embassy-stm32/src/subghz/rf_frequency.rs | |||
| @@ -89,10 +89,7 @@ impl RfFreq { | |||
| 89 | 89 | ||
| 90 | // Get the frequency bit value. | 90 | // Get the frequency bit value. |
| 91 | const fn as_bits(&self) -> u32 { | 91 | const fn as_bits(&self) -> u32 { |
| 92 | ((self.buf[1] as u32) << 24) | 92 | ((self.buf[1] as u32) << 24) | ((self.buf[2] as u32) << 16) | ((self.buf[3] as u32) << 8) | (self.buf[4] as u32) |
| 93 | | ((self.buf[2] as u32) << 16) | ||
| 94 | | ((self.buf[3] as u32) << 8) | ||
| 95 | | (self.buf[4] as u32) | ||
| 96 | } | 93 | } |
| 97 | 94 | ||
| 98 | /// Get the actual frequency. | 95 | /// Get the actual frequency. |
diff --git a/embassy-stm32/src/subghz/sleep_cfg.rs b/embassy-stm32/src/subghz/sleep_cfg.rs index 3fdcc7133..2d2fe0c9c 100644 --- a/embassy-stm32/src/subghz/sleep_cfg.rs +++ b/embassy-stm32/src/subghz/sleep_cfg.rs | |||
| @@ -49,9 +49,7 @@ impl SleepCfg { | |||
| 49 | /// # assert_eq!(u8::from(SLEEP_CFG), 0b101); | 49 | /// # assert_eq!(u8::from(SLEEP_CFG), 0b101); |
| 50 | /// ``` | 50 | /// ``` |
| 51 | pub const fn new() -> SleepCfg { | 51 | pub const fn new() -> SleepCfg { |
| 52 | SleepCfg(0) | 52 | SleepCfg(0).set_startup(Startup::Warm).set_rtc_wakeup_en(true) |
| 53 | .set_startup(Startup::Warm) | ||
| 54 | .set_rtc_wakeup_en(true) | ||
| 55 | } | 53 | } |
| 56 | 54 | ||
| 57 | /// Set the startup mode. | 55 | /// Set the startup mode. |
diff --git a/embassy-stm32/src/subghz/status.rs b/embassy-stm32/src/subghz/status.rs index ae50c5193..10a212b99 100644 --- a/embassy-stm32/src/subghz/status.rs +++ b/embassy-stm32/src/subghz/status.rs | |||
| @@ -192,11 +192,6 @@ impl core::fmt::Display for Status { | |||
| 192 | #[cfg(feature = "defmt")] | 192 | #[cfg(feature = "defmt")] |
| 193 | impl defmt::Format for Status { | 193 | impl defmt::Format for Status { |
| 194 | fn format(&self, fmt: defmt::Formatter) { | 194 | fn format(&self, fmt: defmt::Formatter) { |
| 195 | defmt::write!( | 195 | defmt::write!(fmt, "Status {{ mode: {}, cmd: {} }}", self.mode(), self.cmd()) |
| 196 | fmt, | ||
| 197 | "Status {{ mode: {}, cmd: {} }}", | ||
| 198 | self.mode(), | ||
| 199 | self.cmd() | ||
| 200 | ) | ||
| 201 | } | 196 | } |
| 202 | } | 197 | } |
diff --git a/embassy-stm32/src/subghz/timeout.rs b/embassy-stm32/src/subghz/timeout.rs index 580d0a640..2a0f5b85e 100644 --- a/embassy-stm32/src/subghz/timeout.rs +++ b/embassy-stm32/src/subghz/timeout.rs | |||
| @@ -145,8 +145,7 @@ impl Timeout { | |||
| 145 | // `core::Duration` were not `const fn`, which leads to the hacks | 145 | // `core::Duration` were not `const fn`, which leads to the hacks |
| 146 | // you see here. | 146 | // you see here. |
| 147 | let nanos: u128 = duration.as_nanos(); | 147 | let nanos: u128 = duration.as_nanos(); |
| 148 | const UPPER_LIMIT: u128 = | 148 | const UPPER_LIMIT: u128 = Timeout::MAX.as_nanos() as u128 + (Timeout::RESOLUTION_NANOS as u128) / 2; |
| 149 | Timeout::MAX.as_nanos() as u128 + (Timeout::RESOLUTION_NANOS as u128) / 2; | ||
| 150 | const LOWER_LIMIT: u128 = (((Timeout::RESOLUTION_NANOS as u128) + 1) / 2) as u128; | 149 | const LOWER_LIMIT: u128 = (((Timeout::RESOLUTION_NANOS as u128) + 1) / 2) as u128; |
| 151 | 150 | ||
| 152 | if nanos > UPPER_LIMIT { | 151 | if nanos > UPPER_LIMIT { |
| @@ -420,15 +419,13 @@ impl From<Timeout> for embassy::time::Duration { | |||
| 420 | 419 | ||
| 421 | #[cfg(test)] | 420 | #[cfg(test)] |
| 422 | mod tests { | 421 | mod tests { |
| 423 | use super::{Timeout, ValueError}; | ||
| 424 | use core::time::Duration; | 422 | use core::time::Duration; |
| 425 | 423 | ||
| 424 | use super::{Timeout, ValueError}; | ||
| 425 | |||
| 426 | #[test] | 426 | #[test] |
| 427 | fn saturate() { | 427 | fn saturate() { |
| 428 | assert_eq!( | 428 | assert_eq!(Timeout::from_duration_sat(Duration::from_secs(u64::MAX)), Timeout::MAX); |
| 429 | Timeout::from_duration_sat(Duration::from_secs(u64::MAX)), | ||
| 430 | Timeout::MAX | ||
| 431 | ); | ||
| 432 | } | 429 | } |
| 433 | 430 | ||
| 434 | #[test] | 431 | #[test] |
| @@ -455,10 +452,7 @@ mod tests { | |||
| 455 | #[test] | 452 | #[test] |
| 456 | fn upper_limit() { | 453 | fn upper_limit() { |
| 457 | let high: Duration = Timeout::MAX.as_duration() + Timeout::RESOLUTION / 2; | 454 | let high: Duration = Timeout::MAX.as_duration() + Timeout::RESOLUTION / 2; |
| 458 | assert_eq!( | 455 | assert_eq!(Timeout::from_duration(high), Ok(Timeout::from_raw(0xFFFFFF))); |
| 459 | Timeout::from_duration(high), | ||
| 460 | Ok(Timeout::from_raw(0xFFFFFF)) | ||
| 461 | ); | ||
| 462 | 456 | ||
| 463 | let too_high: Duration = high + Duration::from_nanos(1); | 457 | let too_high: Duration = high + Duration::from_nanos(1); |
| 464 | assert_eq!( | 458 | assert_eq!( |
diff --git a/embassy-stm32/src/time_driver.rs b/embassy-stm32/src/time_driver.rs index b63ed5bd4..38a4adc1d 100644 --- a/embassy-stm32/src/time_driver.rs +++ b/embassy-stm32/src/time_driver.rs | |||
| @@ -1,22 +1,20 @@ | |||
| 1 | use crate::interrupt::InterruptExt; | ||
| 2 | use atomic_polyfill::{AtomicU32, AtomicU8}; | ||
| 3 | use core::cell::Cell; | 1 | use core::cell::Cell; |
| 4 | use core::convert::TryInto; | 2 | use core::convert::TryInto; |
| 5 | use core::sync::atomic::{compiler_fence, Ordering}; | 3 | use core::sync::atomic::{compiler_fence, Ordering}; |
| 6 | use core::{mem, ptr}; | 4 | use core::{mem, ptr}; |
| 5 | |||
| 6 | use atomic_polyfill::{AtomicU32, AtomicU8}; | ||
| 7 | use embassy::blocking_mutex::raw::CriticalSectionRawMutex; | 7 | use embassy::blocking_mutex::raw::CriticalSectionRawMutex; |
| 8 | use embassy::blocking_mutex::Mutex; | 8 | use embassy::blocking_mutex::Mutex; |
| 9 | use embassy::time::driver::{AlarmHandle, Driver}; | 9 | use embassy::time::driver::{AlarmHandle, Driver}; |
| 10 | use embassy::time::TICKS_PER_SECOND; | 10 | use embassy::time::TICKS_PER_SECOND; |
| 11 | use stm32_metapac::timer::regs; | 11 | use stm32_metapac::timer::regs; |
| 12 | 12 | ||
| 13 | use crate::interrupt; | 13 | use crate::interrupt::{CriticalSection, InterruptExt}; |
| 14 | use crate::interrupt::CriticalSection; | ||
| 15 | use crate::pac::timer::vals; | 14 | use crate::pac::timer::vals; |
| 16 | use crate::peripherals; | ||
| 17 | use crate::rcc::sealed::RccPeripheral; | 15 | use crate::rcc::sealed::RccPeripheral; |
| 18 | use crate::timer::sealed::Basic16bitInstance as BasicInstance; | 16 | use crate::timer::sealed::{Basic16bitInstance as BasicInstance, GeneralPurpose16bitInstance as Instance}; |
| 19 | use crate::timer::sealed::GeneralPurpose16bitInstance as Instance; | 17 | use crate::{interrupt, peripherals}; |
| 20 | 18 | ||
| 21 | #[cfg(not(any(time_driver_tim12, time_driver_tim15)))] | 19 | #[cfg(not(any(time_driver_tim12, time_driver_tim15)))] |
| 22 | const ALARM_COUNT: usize = 3; | 20 | const ALARM_COUNT: usize = 3; |
| @@ -271,15 +269,13 @@ impl Driver for RtcDriver { | |||
| 271 | } | 269 | } |
| 272 | 270 | ||
| 273 | unsafe fn allocate_alarm(&self) -> Option<AlarmHandle> { | 271 | unsafe fn allocate_alarm(&self) -> Option<AlarmHandle> { |
| 274 | let id = self | 272 | let id = self.alarm_count.fetch_update(Ordering::AcqRel, Ordering::Acquire, |x| { |
| 275 | .alarm_count | 273 | if x < ALARM_COUNT as u8 { |
| 276 | .fetch_update(Ordering::AcqRel, Ordering::Acquire, |x| { | 274 | Some(x + 1) |
| 277 | if x < ALARM_COUNT as u8 { | 275 | } else { |
| 278 | Some(x + 1) | 276 | None |
| 279 | } else { | 277 | } |
| 280 | None | 278 | }); |
| 281 | } | ||
| 282 | }); | ||
| 283 | 279 | ||
| 284 | match id { | 280 | match id { |
| 285 | Ok(id) => Some(AlarmHandle::new(id)), | 281 | Ok(id) => Some(AlarmHandle::new(id)), |
diff --git a/embassy-stm32/src/timer/mod.rs b/embassy-stm32/src/timer/mod.rs index 3cc6298be..9067fa462 100644 --- a/embassy-stm32/src/timer/mod.rs +++ b/embassy-stm32/src/timer/mod.rs | |||
| @@ -1,8 +1,9 @@ | |||
| 1 | use crate::interrupt::Interrupt; | 1 | use stm32_metapac::timer::vals; |
| 2 | 2 | ||
| 3 | use crate::rcc::{sealed::RccPeripheral as __RccPeri, RccPeripheral}; | 3 | use crate::interrupt::Interrupt; |
| 4 | use crate::rcc::sealed::RccPeripheral as __RccPeri; | ||
| 5 | use crate::rcc::RccPeripheral; | ||
| 4 | use crate::time::Hertz; | 6 | use crate::time::Hertz; |
| 5 | use stm32_metapac::timer::vals; | ||
| 6 | 7 | ||
| 7 | #[cfg(feature = "unstable-pac")] | 8 | #[cfg(feature = "unstable-pac")] |
| 8 | pub mod low_level { | 9 | pub mod low_level { |
| @@ -86,8 +87,7 @@ macro_rules! impl_basic_16bit_timer { | |||
| 86 | let timer_f = Self::frequency().0; | 87 | let timer_f = Self::frequency().0; |
| 87 | let pclk_ticks_per_timer_period = timer_f / f; | 88 | let pclk_ticks_per_timer_period = timer_f / f; |
| 88 | let psc: u16 = unwrap!(((pclk_ticks_per_timer_period - 1) / (1 << 16)).try_into()); | 89 | let psc: u16 = unwrap!(((pclk_ticks_per_timer_period - 1) / (1 << 16)).try_into()); |
| 89 | let arr: u16 = | 90 | let arr: u16 = unwrap!((pclk_ticks_per_timer_period / (u32::from(psc) + 1)).try_into()); |
| 90 | unwrap!((pclk_ticks_per_timer_period / (u32::from(psc) + 1)).try_into()); | ||
| 91 | 91 | ||
| 92 | let regs = Self::regs(); | 92 | let regs = Self::regs(); |
| 93 | unsafe { | 93 | unsafe { |
| @@ -138,8 +138,7 @@ macro_rules! impl_32bit_timer { | |||
| 138 | let timer_f = Self::frequency().0; | 138 | let timer_f = Self::frequency().0; |
| 139 | let pclk_ticks_per_timer_period = (timer_f / f) as u64; | 139 | let pclk_ticks_per_timer_period = (timer_f / f) as u64; |
| 140 | let psc: u16 = unwrap!(((pclk_ticks_per_timer_period - 1) / (1 << 32)).try_into()); | 140 | let psc: u16 = unwrap!(((pclk_ticks_per_timer_period - 1) / (1 << 32)).try_into()); |
| 141 | let arr: u32 = | 141 | let arr: u32 = unwrap!(((pclk_ticks_per_timer_period / (psc as u64 + 1)).try_into())); |
| 142 | unwrap!(((pclk_ticks_per_timer_period / (psc as u64 + 1)).try_into())); | ||
| 143 | 142 | ||
| 144 | let regs = Self::regs_gp32(); | 143 | let regs = Self::regs_gp32(); |
| 145 | unsafe { | 144 | unsafe { |
diff --git a/embassy-stm32/src/usart/buffered.rs b/embassy-stm32/src/usart/buffered.rs index e2c9f7802..c4703cff2 100644 --- a/embassy-stm32/src/usart/buffered.rs +++ b/embassy-stm32/src/usart/buffered.rs | |||
| @@ -1,6 +1,7 @@ | |||
| 1 | use atomic_polyfill::{compiler_fence, Ordering}; | ||
| 2 | use core::future::Future; | 1 | use core::future::Future; |
| 3 | use core::task::Poll; | 2 | use core::task::Poll; |
| 3 | |||
| 4 | use atomic_polyfill::{compiler_fence, Ordering}; | ||
| 4 | use embassy::waitqueue::WakerRegistration; | 5 | use embassy::waitqueue::WakerRegistration; |
| 5 | use embassy_cortex_m::peripheral::{PeripheralMutex, PeripheralState, StateStorage}; | 6 | use embassy_cortex_m::peripheral::{PeripheralMutex, PeripheralState, StateStorage}; |
| 6 | use embassy_hal_common::ring_buffer::RingBuffer; | 7 | use embassy_hal_common::ring_buffer::RingBuffer; |
diff --git a/embassy-stm32/src/usart/mod.rs b/embassy-stm32/src/usart/mod.rs index 2acec874f..a893e4b80 100644 --- a/embassy-stm32/src/usart/mod.rs +++ b/embassy-stm32/src/usart/mod.rs | |||
| @@ -1,15 +1,15 @@ | |||
| 1 | #![macro_use] | 1 | #![macro_use] |
| 2 | 2 | ||
| 3 | use crate::interrupt::Interrupt; | ||
| 4 | use crate::Unborrow; | ||
| 5 | use core::marker::PhantomData; | 3 | use core::marker::PhantomData; |
| 4 | |||
| 6 | use embassy_hal_common::unborrow; | 5 | use embassy_hal_common::unborrow; |
| 7 | 6 | ||
| 8 | use crate::dma::NoDma; | 7 | use crate::dma::NoDma; |
| 9 | use crate::gpio::sealed::AFType; | 8 | use crate::gpio::sealed::AFType; |
| 9 | use crate::interrupt::Interrupt; | ||
| 10 | use crate::pac::usart::{regs, vals}; | 10 | use crate::pac::usart::{regs, vals}; |
| 11 | use crate::peripherals; | ||
| 12 | use crate::rcc::RccPeripheral; | 11 | use crate::rcc::RccPeripheral; |
| 12 | use crate::{peripherals, Unborrow}; | ||
| 13 | 13 | ||
| 14 | #[derive(Clone, Copy, PartialEq, Eq, Debug)] | 14 | #[derive(Clone, Copy, PartialEq, Eq, Debug)] |
| 15 | pub enum DataBits { | 15 | pub enum DataBits { |
| @@ -314,18 +314,14 @@ mod eh02 { | |||
| 314 | } | 314 | } |
| 315 | } | 315 | } |
| 316 | 316 | ||
| 317 | impl<'d, T: Instance, TxDma, RxDma> embedded_hal_02::serial::Read<u8> | 317 | impl<'d, T: Instance, TxDma, RxDma> embedded_hal_02::serial::Read<u8> for Uart<'d, T, TxDma, RxDma> { |
| 318 | for Uart<'d, T, TxDma, RxDma> | ||
| 319 | { | ||
| 320 | type Error = Error; | 318 | type Error = Error; |
| 321 | fn read(&mut self) -> Result<u8, nb::Error<Self::Error>> { | 319 | fn read(&mut self) -> Result<u8, nb::Error<Self::Error>> { |
| 322 | embedded_hal_02::serial::Read::read(&mut self.rx) | 320 | embedded_hal_02::serial::Read::read(&mut self.rx) |
| 323 | } | 321 | } |
| 324 | } | 322 | } |
| 325 | 323 | ||
| 326 | impl<'d, T: Instance, TxDma, RxDma> embedded_hal_02::blocking::serial::Write<u8> | 324 | impl<'d, T: Instance, TxDma, RxDma> embedded_hal_02::blocking::serial::Write<u8> for Uart<'d, T, TxDma, RxDma> { |
| 327 | for Uart<'d, T, TxDma, RxDma> | ||
| 328 | { | ||
| 329 | type Error = Error; | 325 | type Error = Error; |
| 330 | fn bwrite_all(&mut self, buffer: &[u8]) -> Result<(), Self::Error> { | 326 | fn bwrite_all(&mut self, buffer: &[u8]) -> Result<(), Self::Error> { |
| 331 | self.blocking_write(buffer) | 327 | self.blocking_write(buffer) |
| @@ -351,9 +347,7 @@ mod eh1 { | |||
| 351 | } | 347 | } |
| 352 | } | 348 | } |
| 353 | 349 | ||
| 354 | impl<'d, T: Instance, TxDma, RxDma> embedded_hal_1::serial::ErrorType | 350 | impl<'d, T: Instance, TxDma, RxDma> embedded_hal_1::serial::ErrorType for Uart<'d, T, TxDma, RxDma> { |
| 355 | for Uart<'d, T, TxDma, RxDma> | ||
| 356 | { | ||
| 357 | type Error = Error; | 351 | type Error = Error; |
| 358 | } | 352 | } |
| 359 | 353 | ||
diff --git a/embassy-stm32/src/usb/mod.rs b/embassy-stm32/src/usb/mod.rs index 65451917e..fbd1fa823 100644 --- a/embassy-stm32/src/usb/mod.rs +++ b/embassy-stm32/src/usb/mod.rs | |||
| @@ -1,5 +1,4 @@ | |||
| 1 | use crate::interrupt::Interrupt; | 1 | use crate::interrupt::Interrupt; |
| 2 | |||
| 3 | use crate::rcc::RccPeripheral; | 2 | use crate::rcc::RccPeripheral; |
| 4 | 3 | ||
| 5 | #[cfg(feature = "nightly")] | 4 | #[cfg(feature = "nightly")] |
diff --git a/embassy-stm32/src/usb/usb.rs b/embassy-stm32/src/usb/usb.rs index eaf24f8ae..10eb94e6c 100644 --- a/embassy-stm32/src/usb/usb.rs +++ b/embassy-stm32/src/usb/usb.rs | |||
| @@ -1,11 +1,10 @@ | |||
| 1 | #![macro_use] | 1 | #![macro_use] |
| 2 | 2 | ||
| 3 | use crate::interrupt::InterruptExt; | ||
| 4 | use crate::Unborrow; | ||
| 5 | use atomic_polyfill::{AtomicBool, AtomicU8}; | ||
| 6 | use core::marker::PhantomData; | 3 | use core::marker::PhantomData; |
| 7 | use core::sync::atomic::Ordering; | 4 | use core::sync::atomic::Ordering; |
| 8 | use core::task::Poll; | 5 | use core::task::Poll; |
| 6 | |||
| 7 | use atomic_polyfill::{AtomicBool, AtomicU8}; | ||
| 9 | use embassy::time::{block_for, Duration}; | 8 | use embassy::time::{block_for, Duration}; |
| 10 | use embassy::waitqueue::AtomicWaker; | 9 | use embassy::waitqueue::AtomicWaker; |
| 11 | use embassy_hal_common::unborrow; | 10 | use embassy_hal_common::unborrow; |
| @@ -16,12 +15,12 @@ use futures::Future; | |||
| 16 | use pac::common::{Reg, RW}; | 15 | use pac::common::{Reg, RW}; |
| 17 | use pac::usb::vals::{EpType, Stat}; | 16 | use pac::usb::vals::{EpType, Stat}; |
| 18 | 17 | ||
| 18 | use super::{DmPin, DpPin, Instance}; | ||
| 19 | use crate::gpio::sealed::AFType; | 19 | use crate::gpio::sealed::AFType; |
| 20 | use crate::pac; | 20 | use crate::interrupt::InterruptExt; |
| 21 | use crate::pac::usb::regs; | 21 | use crate::pac::usb::regs; |
| 22 | use crate::rcc::sealed::RccPeripheral; | 22 | use crate::rcc::sealed::RccPeripheral; |
| 23 | 23 | use crate::{pac, Unborrow}; | |
| 24 | use super::{DmPin, DpPin, Instance}; | ||
| 25 | 24 | ||
| 26 | const EP_COUNT: usize = 8; | 25 | const EP_COUNT: usize = 8; |
| 27 | 26 | ||
| @@ -105,11 +104,7 @@ impl<T: Instance> EndpointBuffer<T> { | |||
| 105 | if i * 2 + 1 < buf.len() { | 104 | if i * 2 + 1 < buf.len() { |
| 106 | val |= (buf[i * 2 + 1] as u16) << 8; | 105 | val |= (buf[i * 2 + 1] as u16) << 8; |
| 107 | } | 106 | } |
| 108 | unsafe { | 107 | unsafe { T::regs().ep_mem(self.addr as usize / 2 + i).write_value(val) }; |
| 109 | T::regs() | ||
| 110 | .ep_mem(self.addr as usize / 2 + i) | ||
| 111 | .write_value(val) | ||
| 112 | }; | ||
| 113 | } | 108 | } |
| 114 | } | 109 | } |
| 115 | } | 110 | } |
| @@ -146,9 +141,7 @@ impl<'d, T: Instance> Driver<'d, T> { | |||
| 146 | unsafe { | 141 | unsafe { |
| 147 | crate::peripherals::PWR::enable(); | 142 | crate::peripherals::PWR::enable(); |
| 148 | 143 | ||
| 149 | pac::PWR | 144 | pac::PWR.cr2().modify(|w| w.set_usv(pac::pwr::vals::Usv::VALID)); |
| 150 | .cr2() | ||
| 151 | .modify(|w| w.set_usv(pac::pwr::vals::Usv::VALID)); | ||
| 152 | } | 145 | } |
| 153 | 146 | ||
| 154 | unsafe { | 147 | unsafe { |
| @@ -857,12 +850,7 @@ impl<'d, T: Instance> driver::ControlPipe for ControlPipe<'d, T> { | |||
| 857 | } | 850 | } |
| 858 | } | 851 | } |
| 859 | 852 | ||
| 860 | fn data_out<'a>( | 853 | fn data_out<'a>(&'a mut self, buf: &'a mut [u8], first: bool, last: bool) -> Self::DataOutFuture<'a> { |
| 861 | &'a mut self, | ||
| 862 | buf: &'a mut [u8], | ||
| 863 | first: bool, | ||
| 864 | last: bool, | ||
| 865 | ) -> Self::DataOutFuture<'a> { | ||
| 866 | async move { | 854 | async move { |
| 867 | let regs = T::regs(); | 855 | let regs = T::regs(); |
| 868 | 856 | ||
diff --git a/embassy-stm32/src/usb_otg.rs b/embassy-stm32/src/usb_otg.rs index 0f732965c..581754135 100644 --- a/embassy-stm32/src/usb_otg.rs +++ b/embassy-stm32/src/usb_otg.rs | |||
| @@ -1,9 +1,10 @@ | |||
| 1 | use crate::Unborrow; | ||
| 2 | use core::marker::PhantomData; | 1 | use core::marker::PhantomData; |
| 2 | |||
| 3 | use embassy_hal_common::unborrow; | 3 | use embassy_hal_common::unborrow; |
| 4 | 4 | ||
| 5 | use crate::gpio::sealed::AFType; | 5 | use crate::gpio::sealed::AFType; |
| 6 | use crate::{peripherals, rcc::RccPeripheral}; | 6 | use crate::rcc::RccPeripheral; |
| 7 | use crate::{peripherals, Unborrow}; | ||
| 7 | 8 | ||
| 8 | macro_rules! config_ulpi_pins { | 9 | macro_rules! config_ulpi_pins { |
| 9 | ($($pin:ident),*) => { | 10 | ($($pin:ident),*) => { |
| @@ -76,8 +77,8 @@ impl<'d, T: Instance> UsbOtg<'d, T> { | |||
| 76 | ulpi_d7: impl Unborrow<Target = impl UlpiD7Pin<T>> + 'd, | 77 | ulpi_d7: impl Unborrow<Target = impl UlpiD7Pin<T>> + 'd, |
| 77 | ) -> Self { | 78 | ) -> Self { |
| 78 | config_ulpi_pins!( | 79 | config_ulpi_pins!( |
| 79 | ulpi_clk, ulpi_dir, ulpi_nxt, ulpi_stp, ulpi_d0, ulpi_d1, ulpi_d2, ulpi_d3, ulpi_d4, | 80 | ulpi_clk, ulpi_dir, ulpi_nxt, ulpi_stp, ulpi_d0, ulpi_d1, ulpi_d2, ulpi_d3, ulpi_d4, ulpi_d5, ulpi_d6, |
| 80 | ulpi_d5, ulpi_d6, ulpi_d7 | 81 | ulpi_d7 |
| 81 | ); | 82 | ); |
| 82 | 83 | ||
| 83 | Self { | 84 | Self { |
diff --git a/embassy-usb-hid/src/lib.rs b/embassy-usb-hid/src/lib.rs index a75cb8c38..b87f57481 100644 --- a/embassy-usb-hid/src/lib.rs +++ b/embassy-usb-hid/src/lib.rs | |||
| @@ -12,13 +12,9 @@ use core::ops::Range; | |||
| 12 | use core::sync::atomic::{AtomicUsize, Ordering}; | 12 | use core::sync::atomic::{AtomicUsize, Ordering}; |
| 13 | 13 | ||
| 14 | use embassy::time::Duration; | 14 | use embassy::time::Duration; |
| 15 | use embassy_usb::driver::EndpointOut; | 15 | use embassy_usb::control::{ControlHandler, InResponse, OutResponse, Request, RequestType}; |
| 16 | use embassy_usb::{ | 16 | use embassy_usb::driver::{Driver, Endpoint, EndpointError, EndpointIn, EndpointOut}; |
| 17 | control::{ControlHandler, InResponse, OutResponse, Request, RequestType}, | 17 | use embassy_usb::Builder; |
| 18 | driver::{Driver, Endpoint, EndpointError, EndpointIn}, | ||
| 19 | Builder, | ||
| 20 | }; | ||
| 21 | |||
| 22 | #[cfg(feature = "usbd-hid")] | 18 | #[cfg(feature = "usbd-hid")] |
| 23 | use ssmarshal::serialize; | 19 | use ssmarshal::serialize; |
| 24 | #[cfg(feature = "usbd-hid")] | 20 | #[cfg(feature = "usbd-hid")] |
| @@ -145,9 +141,7 @@ fn build<'d, D: Driver<'d>>( | |||
| 145 | (ep_out, ep_in, &state.out_report_offset) | 141 | (ep_out, ep_in, &state.out_report_offset) |
| 146 | } | 142 | } |
| 147 | 143 | ||
| 148 | impl<'d, D: Driver<'d>, const READ_N: usize, const WRITE_N: usize> | 144 | impl<'d, D: Driver<'d>, const READ_N: usize, const WRITE_N: usize> HidReaderWriter<'d, D, READ_N, WRITE_N> { |
| 149 | HidReaderWriter<'d, D, READ_N, WRITE_N> | ||
| 150 | { | ||
| 151 | /// Creates a new HidReaderWriter. | 145 | /// Creates a new HidReaderWriter. |
| 152 | /// | 146 | /// |
| 153 | /// This will allocate one IN and one OUT endpoints. If you only need writing (sending) | 147 | /// This will allocate one IN and one OUT endpoints. If you only need writing (sending) |
| @@ -178,10 +172,7 @@ impl<'d, D: Driver<'d>, const READ_N: usize, const WRITE_N: usize> | |||
| 178 | 172 | ||
| 179 | /// Writes an input report by serializing the given report structure. | 173 | /// Writes an input report by serializing the given report structure. |
| 180 | #[cfg(feature = "usbd-hid")] | 174 | #[cfg(feature = "usbd-hid")] |
| 181 | pub async fn write_serialize<IR: AsInputReport>( | 175 | pub async fn write_serialize<IR: AsInputReport>(&mut self, r: &IR) -> Result<(), EndpointError> { |
| 182 | &mut self, | ||
| 183 | r: &IR, | ||
| 184 | ) -> Result<(), EndpointError> { | ||
| 185 | self.writer.write_serialize(r).await | 176 | self.writer.write_serialize(r).await |
| 186 | } | 177 | } |
| 187 | 178 | ||
| @@ -250,10 +241,7 @@ impl<'d, D: Driver<'d>, const N: usize> HidWriter<'d, D, N> { | |||
| 250 | 241 | ||
| 251 | /// Writes an input report by serializing the given report structure. | 242 | /// Writes an input report by serializing the given report structure. |
| 252 | #[cfg(feature = "usbd-hid")] | 243 | #[cfg(feature = "usbd-hid")] |
| 253 | pub async fn write_serialize<IR: AsInputReport>( | 244 | pub async fn write_serialize<IR: AsInputReport>(&mut self, r: &IR) -> Result<(), EndpointError> { |
| 254 | &mut self, | ||
| 255 | r: &IR, | ||
| 256 | ) -> Result<(), EndpointError> { | ||
| 257 | let mut buf: [u8; N] = [0; N]; | 245 | let mut buf: [u8; N] = [0; N]; |
| 258 | let size = match serialize(&mut buf, r) { | 246 | let size = match serialize(&mut buf, r) { |
| 259 | Ok(size) => size, | 247 | Ok(size) => size, |
| @@ -298,8 +286,12 @@ impl<'d, D: Driver<'d>, const N: usize> HidReader<'d, D, N> { | |||
| 298 | match self.read(&mut buf).await { | 286 | match self.read(&mut buf).await { |
| 299 | Ok(len) => { | 287 | Ok(len) => { |
| 300 | let id = if use_report_ids { buf[0] } else { 0 }; | 288 | let id = if use_report_ids { buf[0] } else { 0 }; |
| 301 | handler.set_report(ReportId::Out(id), &buf[..len]); } | 289 | handler.set_report(ReportId::Out(id), &buf[..len]); |
| 302 | Err(ReadError::BufferOverflow) => warn!("Host sent output report larger than the configured maximum output report length ({})", N), | 290 | } |
| 291 | Err(ReadError::BufferOverflow) => warn!( | ||
| 292 | "Host sent output report larger than the configured maximum output report length ({})", | ||
| 293 | N | ||
| 294 | ), | ||
| 303 | Err(ReadError::Disabled) => self.ep_out.wait_enabled().await, | 295 | Err(ReadError::Disabled) => self.ep_out.wait_enabled().await, |
| 304 | Err(ReadError::Sync(_)) => unreachable!(), | 296 | Err(ReadError::Sync(_)) => unreachable!(), |
| 305 | } | 297 | } |
diff --git a/embassy-usb-ncm/src/lib.rs b/embassy-usb-ncm/src/lib.rs index 70870d51a..e796af28f 100644 --- a/embassy-usb-ncm/src/lib.rs +++ b/embassy-usb-ncm/src/lib.rs | |||
| @@ -5,9 +5,11 @@ pub(crate) mod fmt; | |||
| 5 | 5 | ||
| 6 | use core::intrinsics::copy_nonoverlapping; | 6 | use core::intrinsics::copy_nonoverlapping; |
| 7 | use core::mem::{size_of, MaybeUninit}; | 7 | use core::mem::{size_of, MaybeUninit}; |
| 8 | |||
| 8 | use embassy_usb::control::{self, ControlHandler, InResponse, OutResponse, Request}; | 9 | use embassy_usb::control::{self, ControlHandler, InResponse, OutResponse, Request}; |
| 9 | use embassy_usb::driver::{Endpoint, EndpointError, EndpointIn, EndpointOut}; | 10 | use embassy_usb::driver::{Driver, Endpoint, EndpointError, EndpointIn, EndpointOut}; |
| 10 | use embassy_usb::{driver::Driver, types::*, Builder}; | 11 | use embassy_usb::types::*; |
| 12 | use embassy_usb::Builder; | ||
| 11 | 13 | ||
| 12 | /// This should be used as `device_class` when building the `UsbDevice`. | 14 | /// This should be used as `device_class` when building the `UsbDevice`. |
| 13 | pub const USB_CLASS_CDC: u8 = 0x02; | 15 | pub const USB_CLASS_CDC: u8 = 0x02; |
| @@ -358,9 +360,7 @@ impl<'d, D: Driver<'d>> Sender<'d, D> { | |||
| 358 | // First packet is not full, just send it. | 360 | // First packet is not full, just send it. |
| 359 | // No need to send ZLP because it's short for sure. | 361 | // No need to send ZLP because it's short for sure. |
| 360 | buf[OUT_HEADER_LEN..][..data.len()].copy_from_slice(data); | 362 | buf[OUT_HEADER_LEN..][..data.len()].copy_from_slice(data); |
| 361 | self.write_ep | 363 | self.write_ep.write(&buf[..OUT_HEADER_LEN + data.len()]).await?; |
| 362 | .write(&buf[..OUT_HEADER_LEN + data.len()]) | ||
| 363 | .await?; | ||
| 364 | } else { | 364 | } else { |
| 365 | let (d1, d2) = data.split_at(MAX_PACKET_SIZE - OUT_HEADER_LEN); | 365 | let (d1, d2) = data.split_at(MAX_PACKET_SIZE - OUT_HEADER_LEN); |
| 366 | 366 | ||
diff --git a/embassy-usb-serial/src/lib.rs b/embassy-usb-serial/src/lib.rs index 4587bf713..4d981e3fd 100644 --- a/embassy-usb-serial/src/lib.rs +++ b/embassy-usb-serial/src/lib.rs | |||
| @@ -8,10 +8,12 @@ pub(crate) mod fmt; | |||
| 8 | use core::cell::Cell; | 8 | use core::cell::Cell; |
| 9 | use core::mem::{self, MaybeUninit}; | 9 | use core::mem::{self, MaybeUninit}; |
| 10 | use core::sync::atomic::{AtomicBool, Ordering}; | 10 | use core::sync::atomic::{AtomicBool, Ordering}; |
| 11 | |||
| 11 | use embassy::blocking_mutex::CriticalSectionMutex; | 12 | use embassy::blocking_mutex::CriticalSectionMutex; |
| 12 | use embassy_usb::control::{self, ControlHandler, InResponse, OutResponse, Request}; | 13 | use embassy_usb::control::{self, ControlHandler, InResponse, OutResponse, Request}; |
| 13 | use embassy_usb::driver::{Endpoint, EndpointError, EndpointIn, EndpointOut}; | 14 | use embassy_usb::driver::{Driver, Endpoint, EndpointError, EndpointIn, EndpointOut}; |
| 14 | use embassy_usb::{driver::Driver, types::*, Builder}; | 15 | use embassy_usb::types::*; |
| 16 | use embassy_usb::Builder; | ||
| 15 | 17 | ||
| 16 | /// This should be used as `device_class` when building the `UsbDevice`. | 18 | /// This should be used as `device_class` when building the `UsbDevice`. |
| 17 | pub const USB_CLASS_CDC: u8 = 0x02; | 19 | pub const USB_CLASS_CDC: u8 = 0x02; |
| @@ -162,14 +164,8 @@ impl<'d> ControlHandler for Control<'d> { | |||
| 162 | impl<'d, D: Driver<'d>> CdcAcmClass<'d, D> { | 164 | impl<'d, D: Driver<'d>> CdcAcmClass<'d, D> { |
| 163 | /// Creates a new CdcAcmClass with the provided UsbBus and max_packet_size in bytes. For | 165 | /// Creates a new CdcAcmClass with the provided UsbBus and max_packet_size in bytes. For |
| 164 | /// full-speed devices, max_packet_size has to be one of 8, 16, 32 or 64. | 166 | /// full-speed devices, max_packet_size has to be one of 8, 16, 32 or 64. |
| 165 | pub fn new( | 167 | pub fn new(builder: &mut Builder<'d, D>, state: &'d mut State<'d>, max_packet_size: u16) -> Self { |
| 166 | builder: &mut Builder<'d, D>, | 168 | let control = state.control.write(Control { shared: &state.shared }); |
| 167 | state: &'d mut State<'d>, | ||
| 168 | max_packet_size: u16, | ||
| 169 | ) -> Self { | ||
| 170 | let control = state.control.write(Control { | ||
| 171 | shared: &state.shared, | ||
| 172 | }); | ||
| 173 | 169 | ||
| 174 | let control_shared = &state.shared; | 170 | let control_shared = &state.shared; |
| 175 | 171 | ||
diff --git a/embassy-usb/src/builder.rs b/embassy-usb/src/builder.rs index 09904949f..1ca24cc08 100644 --- a/embassy-usb/src/builder.rs +++ b/embassy-usb/src/builder.rs | |||
| @@ -1,14 +1,11 @@ | |||
| 1 | use heapless::Vec; | 1 | use heapless::Vec; |
| 2 | 2 | ||
| 3 | use crate::{Interface, STRING_INDEX_CUSTOM_START}; | ||
| 4 | |||
| 5 | use super::control::ControlHandler; | 3 | use super::control::ControlHandler; |
| 6 | use super::descriptor::{BosWriter, DescriptorWriter}; | 4 | use super::descriptor::{BosWriter, DescriptorWriter}; |
| 7 | use super::driver::{Driver, Endpoint}; | 5 | use super::driver::{Driver, Endpoint}; |
| 8 | use super::types::*; | 6 | use super::types::*; |
| 9 | use super::DeviceStateHandler; | 7 | use super::{DeviceStateHandler, UsbDevice, MAX_INTERFACE_COUNT}; |
| 10 | use super::UsbDevice; | 8 | use crate::{Interface, STRING_INDEX_CUSTOM_START}; |
| 11 | use super::MAX_INTERFACE_COUNT; | ||
| 12 | 9 | ||
| 13 | #[derive(Debug, Copy, Clone)] | 10 | #[derive(Debug, Copy, Clone)] |
| 14 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | 11 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] |
| @@ -151,9 +148,7 @@ impl<'d, D: Driver<'d>> Builder<'d, D> { | |||
| 151 | ) -> Self { | 148 | ) -> Self { |
| 152 | // Magic values specified in USB-IF ECN on IADs. | 149 | // Magic values specified in USB-IF ECN on IADs. |
| 153 | if config.composite_with_iads | 150 | if config.composite_with_iads |
| 154 | && (config.device_class != 0xEF | 151 | && (config.device_class != 0xEF || config.device_sub_class != 0x02 || config.device_protocol != 0x01) |
| 155 | || config.device_sub_class != 0x02 | ||
| 156 | || config.device_protocol != 0x01) | ||
| 157 | { | 152 | { |
| 158 | panic!("if composite_with_iads is set, you must set device_class = 0xEF, device_sub_class = 0x02, device_protocol = 0x01"); | 153 | panic!("if composite_with_iads is set, you must set device_class = 0xEF, device_sub_class = 0x02, device_protocol = 0x01"); |
| 159 | } | 154 | } |
| @@ -218,12 +213,7 @@ impl<'d, D: Driver<'d>> Builder<'d, D> { | |||
| 218 | /// with the given class/subclass/protocol, associating all the child interfaces. | 213 | /// with the given class/subclass/protocol, associating all the child interfaces. |
| 219 | /// | 214 | /// |
| 220 | /// If it's not set, no IAD descriptor is added. | 215 | /// If it's not set, no IAD descriptor is added. |
| 221 | pub fn function( | 216 | pub fn function(&mut self, class: u8, subclass: u8, protocol: u8) -> FunctionBuilder<'_, 'd, D> { |
| 222 | &mut self, | ||
| 223 | class: u8, | ||
| 224 | subclass: u8, | ||
| 225 | protocol: u8, | ||
| 226 | ) -> FunctionBuilder<'_, 'd, D> { | ||
| 227 | let iface_count_index = if self.config.composite_with_iads { | 217 | let iface_count_index = if self.config.composite_with_iads { |
| 228 | self.config_descriptor.iad( | 218 | self.config_descriptor.iad( |
| 229 | InterfaceNumber::new(self.interfaces.len() as _), | 219 | InterfaceNumber::new(self.interfaces.len() as _), |
| @@ -315,24 +305,14 @@ impl<'a, 'd, D: Driver<'d>> InterfaceBuilder<'a, 'd, D> { | |||
| 315 | /// Alternate setting numbers are guaranteed to be allocated consecutively, starting from 0. | 305 | /// Alternate setting numbers are guaranteed to be allocated consecutively, starting from 0. |
| 316 | /// | 306 | /// |
| 317 | /// The first alternate setting, with number 0, is the default one. | 307 | /// The first alternate setting, with number 0, is the default one. |
| 318 | pub fn alt_setting( | 308 | pub fn alt_setting(&mut self, class: u8, subclass: u8, protocol: u8) -> InterfaceAltBuilder<'_, 'd, D> { |
| 319 | &mut self, | ||
| 320 | class: u8, | ||
| 321 | subclass: u8, | ||
| 322 | protocol: u8, | ||
| 323 | ) -> InterfaceAltBuilder<'_, 'd, D> { | ||
| 324 | let number = self.next_alt_setting_number; | 309 | let number = self.next_alt_setting_number; |
| 325 | self.next_alt_setting_number += 1; | 310 | self.next_alt_setting_number += 1; |
| 326 | self.builder.interfaces[self.interface_number.0 as usize].num_alt_settings += 1; | 311 | self.builder.interfaces[self.interface_number.0 as usize].num_alt_settings += 1; |
| 327 | 312 | ||
| 328 | self.builder.config_descriptor.interface_alt( | 313 | self.builder |
| 329 | self.interface_number, | 314 | .config_descriptor |
| 330 | number, | 315 | .interface_alt(self.interface_number, number, class, subclass, protocol, None); |
| 331 | class, | ||
| 332 | subclass, | ||
| 333 | protocol, | ||
| 334 | None, | ||
| 335 | ); | ||
| 336 | 316 | ||
| 337 | InterfaceAltBuilder { | 317 | InterfaceAltBuilder { |
| 338 | builder: self.builder, | 318 | builder: self.builder, |
| @@ -365,17 +345,10 @@ impl<'a, 'd, D: Driver<'d>> InterfaceAltBuilder<'a, 'd, D> { | |||
| 365 | /// Descriptors are written in the order builder functions are called. Note that some | 345 | /// Descriptors are written in the order builder functions are called. Note that some |
| 366 | /// classes care about the order. | 346 | /// classes care about the order. |
| 367 | pub fn descriptor(&mut self, descriptor_type: u8, descriptor: &[u8]) { | 347 | pub fn descriptor(&mut self, descriptor_type: u8, descriptor: &[u8]) { |
| 368 | self.builder | 348 | self.builder.config_descriptor.write(descriptor_type, descriptor) |
| 369 | .config_descriptor | ||
| 370 | .write(descriptor_type, descriptor) | ||
| 371 | } | 349 | } |
| 372 | 350 | ||
| 373 | fn endpoint_in( | 351 | fn endpoint_in(&mut self, ep_type: EndpointType, max_packet_size: u16, interval: u8) -> D::EndpointIn { |
| 374 | &mut self, | ||
| 375 | ep_type: EndpointType, | ||
| 376 | max_packet_size: u16, | ||
| 377 | interval: u8, | ||
| 378 | ) -> D::EndpointIn { | ||
| 379 | let ep = self | 352 | let ep = self |
| 380 | .builder | 353 | .builder |
| 381 | .driver | 354 | .driver |
| @@ -387,12 +360,7 @@ impl<'a, 'd, D: Driver<'d>> InterfaceAltBuilder<'a, 'd, D> { | |||
| 387 | ep | 360 | ep |
| 388 | } | 361 | } |
| 389 | 362 | ||
| 390 | fn endpoint_out( | 363 | fn endpoint_out(&mut self, ep_type: EndpointType, max_packet_size: u16, interval: u8) -> D::EndpointOut { |
| 391 | &mut self, | ||
| 392 | ep_type: EndpointType, | ||
| 393 | max_packet_size: u16, | ||
| 394 | interval: u8, | ||
| 395 | ) -> D::EndpointOut { | ||
| 396 | let ep = self | 364 | let ep = self |
| 397 | .builder | 365 | .builder |
| 398 | .driver | 366 | .driver |
diff --git a/embassy-usb/src/descriptor.rs b/embassy-usb/src/descriptor.rs index 7f23fd921..b94a4b161 100644 --- a/embassy-usb/src/descriptor.rs +++ b/embassy-usb/src/descriptor.rs | |||
| @@ -1,5 +1,6 @@ | |||
| 1 | use super::builder::Config; | 1 | use super::builder::Config; |
| 2 | use super::{types::*, CONFIGURATION_VALUE}; | 2 | use super::types::*; |
| 3 | use super::CONFIGURATION_VALUE; | ||
| 3 | 4 | ||
| 4 | /// Standard descriptor types | 5 | /// Standard descriptor types |
| 5 | #[allow(missing_docs)] | 6 | #[allow(missing_docs)] |
| @@ -113,11 +114,7 @@ impl<'a> DescriptorWriter<'a> { | |||
| 113 | CONFIGURATION_VALUE, // bConfigurationValue | 114 | CONFIGURATION_VALUE, // bConfigurationValue |
| 114 | 0, // iConfiguration | 115 | 0, // iConfiguration |
| 115 | 0x80 | if config.self_powered { 0x40 } else { 0x00 } | 116 | 0x80 | if config.self_powered { 0x40 } else { 0x00 } |
| 116 | | if config.supports_remote_wakeup { | 117 | | if config.supports_remote_wakeup { 0x20 } else { 0x00 }, // bmAttributes |
| 117 | 0x20 | ||
| 118 | } else { | ||
| 119 | 0x00 | ||
| 120 | }, // bmAttributes | ||
| 121 | (config.max_power / 2) as u8, // bMaxPower | 118 | (config.max_power / 2) as u8, // bMaxPower |
| 122 | ], | 119 | ], |
| 123 | ) | 120 | ) |
diff --git a/embassy-usb/src/driver.rs b/embassy-usb/src/driver.rs index 0680df7a5..bfe44d627 100644 --- a/embassy-usb/src/driver.rs +++ b/embassy-usb/src/driver.rs | |||
| @@ -161,18 +161,12 @@ pub trait ControlPipe { | |||
| 161 | /// | 161 | /// |
| 162 | /// Must be called after `setup()` for requests with `direction` of `Out` | 162 | /// Must be called after `setup()` for requests with `direction` of `Out` |
| 163 | /// and `length` greater than zero. | 163 | /// and `length` greater than zero. |
| 164 | fn data_out<'a>( | 164 | fn data_out<'a>(&'a mut self, buf: &'a mut [u8], first: bool, last: bool) -> Self::DataOutFuture<'a>; |
| 165 | &'a mut self, | ||
| 166 | buf: &'a mut [u8], | ||
| 167 | first: bool, | ||
| 168 | last: bool, | ||
| 169 | ) -> Self::DataOutFuture<'a>; | ||
| 170 | 165 | ||
| 171 | /// Sends a DATA IN packet with `data` in response to a control read request. | 166 | /// Sends a DATA IN packet with `data` in response to a control read request. |
| 172 | /// | 167 | /// |
| 173 | /// If `last_packet` is true, the STATUS packet will be ACKed following the transfer of `data`. | 168 | /// If `last_packet` is true, the STATUS packet will be ACKed following the transfer of `data`. |
| 174 | fn data_in<'a>(&'a mut self, data: &'a [u8], first: bool, last: bool) | 169 | fn data_in<'a>(&'a mut self, data: &'a [u8], first: bool, last: bool) -> Self::DataInFuture<'a>; |
| 175 | -> Self::DataInFuture<'a>; | ||
| 176 | 170 | ||
| 177 | /// Accepts a control request. | 171 | /// Accepts a control request. |
| 178 | /// | 172 | /// |
diff --git a/embassy-usb/src/lib.rs b/embassy-usb/src/lib.rs index b691bf11e..f2577d4fc 100644 --- a/embassy-usb/src/lib.rs +++ b/embassy-usb/src/lib.rs | |||
| @@ -15,16 +15,13 @@ pub mod types; | |||
| 15 | use embassy::util::{select, Either}; | 15 | use embassy::util::{select, Either}; |
| 16 | use heapless::Vec; | 16 | use heapless::Vec; |
| 17 | 17 | ||
| 18 | use crate::descriptor_reader::foreach_endpoint; | 18 | pub use self::builder::{Builder, Config}; |
| 19 | use crate::driver::ControlPipe; | ||
| 20 | |||
| 21 | use self::control::*; | 19 | use self::control::*; |
| 22 | use self::descriptor::*; | 20 | use self::descriptor::*; |
| 23 | use self::driver::{Bus, Driver, Event}; | 21 | use self::driver::{Bus, Driver, Event}; |
| 24 | use self::types::*; | 22 | use self::types::*; |
| 25 | 23 | use crate::descriptor_reader::foreach_endpoint; | |
| 26 | pub use self::builder::Builder; | 24 | use crate::driver::ControlPipe; |
| 27 | pub use self::builder::Config; | ||
| 28 | 25 | ||
| 29 | /// The global state of the USB device. | 26 | /// The global state of the USB device. |
| 30 | /// | 27 | /// |
| @@ -418,10 +415,8 @@ impl<'d, D: Driver<'d>> Inner<'d, D> { | |||
| 418 | // Enable all endpoints of selected alt settings. | 415 | // Enable all endpoints of selected alt settings. |
| 419 | foreach_endpoint(self.config_descriptor, |ep| { | 416 | foreach_endpoint(self.config_descriptor, |ep| { |
| 420 | let iface = &self.interfaces[ep.interface as usize]; | 417 | let iface = &self.interfaces[ep.interface as usize]; |
| 421 | self.bus.endpoint_set_enabled( | 418 | self.bus |
| 422 | ep.ep_address, | 419 | .endpoint_set_enabled(ep.ep_address, iface.current_alt_setting == ep.interface_alt); |
| 423 | iface.current_alt_setting == ep.interface_alt, | ||
| 424 | ); | ||
| 425 | }) | 420 | }) |
| 426 | .unwrap(); | 421 | .unwrap(); |
| 427 | 422 | ||
| @@ -474,10 +469,8 @@ impl<'d, D: Driver<'d>> Inner<'d, D> { | |||
| 474 | // Enable/disable EPs of this interface as needed. | 469 | // Enable/disable EPs of this interface as needed. |
| 475 | foreach_endpoint(self.config_descriptor, |ep| { | 470 | foreach_endpoint(self.config_descriptor, |ep| { |
| 476 | if ep.interface == req.index as u8 { | 471 | if ep.interface == req.index as u8 { |
| 477 | self.bus.endpoint_set_enabled( | 472 | self.bus |
| 478 | ep.ep_address, | 473 | .endpoint_set_enabled(ep.ep_address, iface.current_alt_setting == ep.interface_alt); |
| 479 | iface.current_alt_setting == ep.interface_alt, | ||
| 480 | ); | ||
| 481 | } | 474 | } |
| 482 | }) | 475 | }) |
| 483 | .unwrap(); | 476 | .unwrap(); |
diff --git a/embassy/src/blocking_mutex/mod.rs b/embassy/src/blocking_mutex/mod.rs index 859eca075..eb3cd9392 100644 --- a/embassy/src/blocking_mutex/mod.rs +++ b/embassy/src/blocking_mutex/mod.rs | |||
| @@ -2,9 +2,10 @@ | |||
| 2 | 2 | ||
| 3 | pub mod raw; | 3 | pub mod raw; |
| 4 | 4 | ||
| 5 | use self::raw::RawMutex; | ||
| 6 | use core::cell::UnsafeCell; | 5 | use core::cell::UnsafeCell; |
| 7 | 6 | ||
| 7 | use self::raw::RawMutex; | ||
| 8 | |||
| 8 | /// Any object implementing this trait guarantees exclusive access to the data contained | 9 | /// Any object implementing this trait guarantees exclusive access to the data contained |
| 9 | /// within the mutex for the duration of the lock. | 10 | /// within the mutex for the duration of the lock. |
| 10 | /// Adapted from <https://github.com/rust-embedded/mutex-trait>. | 11 | /// Adapted from <https://github.com/rust-embedded/mutex-trait>. |
diff --git a/embassy/src/blocking_mutex/raw.rs b/embassy/src/blocking_mutex/raw.rs index ebeb6dccf..f9d249b08 100644 --- a/embassy/src/blocking_mutex/raw.rs +++ b/embassy/src/blocking_mutex/raw.rs | |||
| @@ -14,9 +14,7 @@ unsafe impl Sync for CriticalSectionRawMutex {} | |||
| 14 | 14 | ||
| 15 | impl CriticalSectionRawMutex { | 15 | impl CriticalSectionRawMutex { |
| 16 | pub const fn new() -> Self { | 16 | pub const fn new() -> Self { |
| 17 | Self { | 17 | Self { _phantom: PhantomData } |
| 18 | _phantom: PhantomData, | ||
| 19 | } | ||
| 20 | } | 18 | } |
| 21 | } | 19 | } |
| 22 | 20 | ||
| @@ -38,9 +36,7 @@ unsafe impl Send for NoopRawMutex {} | |||
| 38 | 36 | ||
| 39 | impl NoopRawMutex { | 37 | impl NoopRawMutex { |
| 40 | pub const fn new() -> Self { | 38 | pub const fn new() -> Self { |
| 41 | Self { | 39 | Self { _phantom: PhantomData } |
| 42 | _phantom: PhantomData, | ||
| 43 | } | ||
| 44 | } | 40 | } |
| 45 | } | 41 | } |
| 46 | 42 | ||
| @@ -66,19 +62,14 @@ mod thread_mode { | |||
| 66 | 62 | ||
| 67 | impl ThreadModeRawMutex { | 63 | impl ThreadModeRawMutex { |
| 68 | pub const fn new() -> Self { | 64 | pub const fn new() -> Self { |
| 69 | Self { | 65 | Self { _phantom: PhantomData } |
| 70 | _phantom: PhantomData, | ||
| 71 | } | ||
| 72 | } | 66 | } |
| 73 | } | 67 | } |
| 74 | 68 | ||
| 75 | impl RawMutex for ThreadModeRawMutex { | 69 | impl RawMutex for ThreadModeRawMutex { |
| 76 | const INIT: Self = Self::new(); | 70 | const INIT: Self = Self::new(); |
| 77 | fn lock<R>(&self, f: impl FnOnce() -> R) -> R { | 71 | fn lock<R>(&self, f: impl FnOnce() -> R) -> R { |
| 78 | assert!( | 72 | assert!(in_thread_mode(), "ThreadModeMutex can only be locked from thread mode."); |
| 79 | in_thread_mode(), | ||
| 80 | "ThreadModeMutex can only be locked from thread mode." | ||
| 81 | ); | ||
| 82 | 73 | ||
| 83 | f() | 74 | f() |
| 84 | } | 75 | } |
| @@ -104,8 +95,7 @@ mod thread_mode { | |||
| 104 | return Some("main") == std::thread::current().name(); | 95 | return Some("main") == std::thread::current().name(); |
| 105 | 96 | ||
| 106 | #[cfg(not(feature = "std"))] | 97 | #[cfg(not(feature = "std"))] |
| 107 | return cortex_m::peripheral::SCB::vect_active() | 98 | return cortex_m::peripheral::SCB::vect_active() == cortex_m::peripheral::scb::VectActive::ThreadMode; |
| 108 | == cortex_m::peripheral::scb::VectActive::ThreadMode; | ||
| 109 | } | 99 | } |
| 110 | } | 100 | } |
| 111 | #[cfg(any(cortex_m, feature = "std"))] | 101 | #[cfg(any(cortex_m, feature = "std"))] |
diff --git a/embassy/src/channel/mpmc.rs b/embassy/src/channel/mpmc.rs index 2377a9665..48056cd8f 100644 --- a/embassy/src/channel/mpmc.rs +++ b/embassy/src/channel/mpmc.rs | |||
| @@ -20,8 +20,7 @@ | |||
| 20 | 20 | ||
| 21 | use core::cell::RefCell; | 21 | use core::cell::RefCell; |
| 22 | use core::pin::Pin; | 22 | use core::pin::Pin; |
| 23 | use core::task::Context; | 23 | use core::task::{Context, Poll}; |
| 24 | use core::task::Poll; | ||
| 25 | 24 | ||
| 26 | use futures::Future; | 25 | use futures::Future; |
| 27 | use heapless::Deque; | 26 | use heapless::Deque; |
| @@ -44,9 +43,7 @@ where | |||
| 44 | M: RawMutex, | 43 | M: RawMutex, |
| 45 | { | 44 | { |
| 46 | fn clone(&self) -> Self { | 45 | fn clone(&self) -> Self { |
| 47 | Sender { | 46 | Sender { channel: self.channel } |
| 48 | channel: self.channel, | ||
| 49 | } | ||
| 50 | } | 47 | } |
| 51 | } | 48 | } |
| 52 | 49 | ||
| @@ -77,9 +74,7 @@ pub struct DynamicSender<'ch, T> { | |||
| 77 | 74 | ||
| 78 | impl<'ch, T> Clone for DynamicSender<'ch, T> { | 75 | impl<'ch, T> Clone for DynamicSender<'ch, T> { |
| 79 | fn clone(&self) -> Self { | 76 | fn clone(&self) -> Self { |
| 80 | DynamicSender { | 77 | DynamicSender { channel: self.channel } |
| 81 | channel: self.channel, | ||
| 82 | } | ||
| 83 | } | 78 | } |
| 84 | } | 79 | } |
| 85 | 80 | ||
| @@ -125,9 +120,7 @@ where | |||
| 125 | M: RawMutex, | 120 | M: RawMutex, |
| 126 | { | 121 | { |
| 127 | fn clone(&self) -> Self { | 122 | fn clone(&self) -> Self { |
| 128 | Receiver { | 123 | Receiver { channel: self.channel } |
| 129 | channel: self.channel, | ||
| 130 | } | ||
| 131 | } | 124 | } |
| 132 | } | 125 | } |
| 133 | 126 | ||
| @@ -158,9 +151,7 @@ pub struct DynamicReceiver<'ch, T> { | |||
| 158 | 151 | ||
| 159 | impl<'ch, T> Clone for DynamicReceiver<'ch, T> { | 152 | impl<'ch, T> Clone for DynamicReceiver<'ch, T> { |
| 160 | fn clone(&self) -> Self { | 153 | fn clone(&self) -> Self { |
| 161 | DynamicReceiver { | 154 | DynamicReceiver { channel: self.channel } |
| 162 | channel: self.channel, | ||
| 163 | } | ||
| 164 | } | 155 | } |
| 165 | } | 156 | } |
| 166 | 157 | ||
| @@ -169,9 +160,7 @@ impl<'ch, T> DynamicReceiver<'ch, T> { | |||
| 169 | /// | 160 | /// |
| 170 | /// See [`Channel::recv()`]. | 161 | /// See [`Channel::recv()`]. |
| 171 | pub fn recv(&self) -> DynamicRecvFuture<'_, T> { | 162 | pub fn recv(&self) -> DynamicRecvFuture<'_, T> { |
| 172 | DynamicRecvFuture { | 163 | DynamicRecvFuture { channel: self.channel } |
| 173 | channel: self.channel, | ||
| 174 | } | ||
| 175 | } | 164 | } |
| 176 | 165 | ||
| 177 | /// Attempt to immediately receive the next value. | 166 | /// Attempt to immediately receive the next value. |
| @@ -282,11 +271,7 @@ impl<'ch, T> Future for DynamicSendFuture<'ch, T> { | |||
| 282 | impl<'ch, T> Unpin for DynamicSendFuture<'ch, T> {} | 271 | impl<'ch, T> Unpin for DynamicSendFuture<'ch, T> {} |
| 283 | 272 | ||
| 284 | trait DynamicChannel<T> { | 273 | trait DynamicChannel<T> { |
| 285 | fn try_send_with_context( | 274 | fn try_send_with_context(&self, message: T, cx: Option<&mut Context<'_>>) -> Result<(), TrySendError<T>>; |
| 286 | &self, | ||
| 287 | message: T, | ||
| 288 | cx: Option<&mut Context<'_>>, | ||
| 289 | ) -> Result<(), TrySendError<T>>; | ||
| 290 | 275 | ||
| 291 | fn try_recv_with_context(&self, cx: Option<&mut Context<'_>>) -> Result<T, TryRecvError>; | 276 | fn try_recv_with_context(&self, cx: Option<&mut Context<'_>>) -> Result<T, TryRecvError>; |
| 292 | } | 277 | } |
| @@ -346,11 +331,7 @@ impl<T, const N: usize> ChannelState<T, N> { | |||
| 346 | self.try_send_with_context(message, None) | 331 | self.try_send_with_context(message, None) |
| 347 | } | 332 | } |
| 348 | 333 | ||
| 349 | fn try_send_with_context( | 334 | fn try_send_with_context(&mut self, message: T, cx: Option<&mut Context<'_>>) -> Result<(), TrySendError<T>> { |
| 350 | &mut self, | ||
| 351 | message: T, | ||
| 352 | cx: Option<&mut Context<'_>>, | ||
| 353 | ) -> Result<(), TrySendError<T>> { | ||
| 354 | match self.queue.push_back(message) { | 335 | match self.queue.push_back(message) { |
| 355 | Ok(()) => { | 336 | Ok(()) => { |
| 356 | self.receiver_waker.wake(); | 337 | self.receiver_waker.wake(); |
| @@ -425,11 +406,7 @@ where | |||
| 425 | self.lock(|c| c.try_recv_with_context(cx)) | 406 | self.lock(|c| c.try_recv_with_context(cx)) |
| 426 | } | 407 | } |
| 427 | 408 | ||
| 428 | fn try_send_with_context( | 409 | fn try_send_with_context(&self, m: T, cx: Option<&mut Context<'_>>) -> Result<(), TrySendError<T>> { |
| 429 | &self, | ||
| 430 | m: T, | ||
| 431 | cx: Option<&mut Context<'_>>, | ||
| 432 | ) -> Result<(), TrySendError<T>> { | ||
| 433 | self.lock(|c| c.try_send_with_context(m, cx)) | 410 | self.lock(|c| c.try_send_with_context(m, cx)) |
| 434 | } | 411 | } |
| 435 | 412 | ||
| @@ -491,11 +468,7 @@ impl<M, T, const N: usize> DynamicChannel<T> for Channel<M, T, N> | |||
| 491 | where | 468 | where |
| 492 | M: RawMutex, | 469 | M: RawMutex, |
| 493 | { | 470 | { |
| 494 | fn try_send_with_context( | 471 | fn try_send_with_context(&self, m: T, cx: Option<&mut Context<'_>>) -> Result<(), TrySendError<T>> { |
| 495 | &self, | ||
| 496 | m: T, | ||
| 497 | cx: Option<&mut Context<'_>>, | ||
| 498 | ) -> Result<(), TrySendError<T>> { | ||
| 499 | Channel::try_send_with_context(self, m, cx) | 472 | Channel::try_send_with_context(self, m, cx) |
| 500 | } | 473 | } |
| 501 | 474 | ||
| @@ -512,11 +485,10 @@ mod tests { | |||
| 512 | use futures_executor::ThreadPool; | 485 | use futures_executor::ThreadPool; |
| 513 | use futures_timer::Delay; | 486 | use futures_timer::Delay; |
| 514 | 487 | ||
| 488 | use super::*; | ||
| 515 | use crate::blocking_mutex::raw::{CriticalSectionRawMutex, NoopRawMutex}; | 489 | use crate::blocking_mutex::raw::{CriticalSectionRawMutex, NoopRawMutex}; |
| 516 | use crate::util::Forever; | 490 | use crate::util::Forever; |
| 517 | 491 | ||
| 518 | use super::*; | ||
| 519 | |||
| 520 | fn capacity<T, const N: usize>(c: &ChannelState<T, N>) -> usize { | 492 | fn capacity<T, const N: usize>(c: &ChannelState<T, N>) -> usize { |
| 521 | c.queue.capacity() - c.queue.len() | 493 | c.queue.capacity() - c.queue.len() |
| 522 | } | 494 | } |
diff --git a/embassy/src/executor/arch/wasm.rs b/embassy/src/executor/arch/wasm.rs index f069ebc3d..9d5aa31ed 100644 --- a/embassy/src/executor/arch/wasm.rs +++ b/embassy/src/executor/arch/wasm.rs | |||
| @@ -1,11 +1,11 @@ | |||
| 1 | use core::marker::PhantomData; | 1 | use core::marker::PhantomData; |
| 2 | |||
| 2 | use js_sys::Promise; | 3 | use js_sys::Promise; |
| 3 | use wasm_bindgen::prelude::*; | 4 | use wasm_bindgen::prelude::*; |
| 4 | 5 | ||
| 5 | use super::{ | 6 | use super::raw::util::UninitCell; |
| 6 | raw::{self, util::UninitCell}, | 7 | use super::raw::{self}; |
| 7 | Spawner, | 8 | use super::Spawner; |
| 8 | }; | ||
| 9 | 9 | ||
| 10 | /// WASM executor, wasm_bindgen to schedule tasks on the JS event loop. | 10 | /// WASM executor, wasm_bindgen to schedule tasks on the JS event loop. |
| 11 | pub struct Executor { | 11 | pub struct Executor { |
diff --git a/embassy/src/executor/raw/mod.rs b/embassy/src/executor/raw/mod.rs index 5034c0d66..09429c19a 100644 --- a/embassy/src/executor/raw/mod.rs +++ b/embassy/src/executor/raw/mod.rs | |||
| @@ -13,25 +13,25 @@ mod timer_queue; | |||
| 13 | pub(crate) mod util; | 13 | pub(crate) mod util; |
| 14 | mod waker; | 14 | mod waker; |
| 15 | 15 | ||
| 16 | use atomic_polyfill::{AtomicU32, Ordering}; | ||
| 17 | use core::cell::Cell; | 16 | use core::cell::Cell; |
| 18 | use core::future::Future; | 17 | use core::future::Future; |
| 19 | use core::pin::Pin; | 18 | use core::pin::Pin; |
| 20 | use core::ptr::NonNull; | 19 | use core::ptr::NonNull; |
| 21 | use core::task::{Context, Poll}; | 20 | use core::task::{Context, Poll}; |
| 22 | use core::{mem, ptr}; | 21 | use core::{mem, ptr}; |
| 22 | |||
| 23 | use atomic_polyfill::{AtomicU32, Ordering}; | ||
| 23 | use critical_section::CriticalSection; | 24 | use critical_section::CriticalSection; |
| 24 | 25 | ||
| 25 | use self::run_queue::{RunQueue, RunQueueItem}; | 26 | use self::run_queue::{RunQueue, RunQueueItem}; |
| 26 | use self::util::UninitCell; | 27 | use self::util::UninitCell; |
| 28 | pub use self::waker::task_from_waker; | ||
| 27 | use super::SpawnToken; | 29 | use super::SpawnToken; |
| 28 | #[cfg(feature = "time")] | 30 | #[cfg(feature = "time")] |
| 29 | use crate::time::driver::{self, AlarmHandle}; | 31 | use crate::time::driver::{self, AlarmHandle}; |
| 30 | #[cfg(feature = "time")] | 32 | #[cfg(feature = "time")] |
| 31 | use crate::time::Instant; | 33 | use crate::time::Instant; |
| 32 | 34 | ||
| 33 | pub use self::waker::task_from_waker; | ||
| 34 | |||
| 35 | /// Task is spawned (has a future) | 35 | /// Task is spawned (has a future) |
| 36 | pub(crate) const STATE_SPAWNED: u32 = 1 << 0; | 36 | pub(crate) const STATE_SPAWNED: u32 = 1 << 0; |
| 37 | /// Task is in the executor run queue | 37 | /// Task is in the executor run queue |
| @@ -97,8 +97,7 @@ impl TaskHeader { | |||
| 97 | } | 97 | } |
| 98 | 98 | ||
| 99 | // Mark it as scheduled | 99 | // Mark it as scheduled |
| 100 | self.state | 100 | self.state.store(state | STATE_RUN_QUEUED, Ordering::Relaxed); |
| 101 | .store(state | STATE_RUN_QUEUED, Ordering::Relaxed); | ||
| 102 | 101 | ||
| 103 | // We have just marked the task as scheduled, so enqueue it. | 102 | // We have just marked the task as scheduled, so enqueue it. |
| 104 | let executor = &*self.executor.get(); | 103 | let executor = &*self.executor.get(); |
diff --git a/embassy/src/executor/raw/run_queue.rs b/embassy/src/executor/raw/run_queue.rs index 7aa2079fa..31615da7e 100644 --- a/embassy/src/executor/raw/run_queue.rs +++ b/embassy/src/executor/raw/run_queue.rs | |||
| @@ -1,6 +1,7 @@ | |||
| 1 | use atomic_polyfill::{AtomicPtr, Ordering}; | ||
| 2 | use core::ptr; | 1 | use core::ptr; |
| 3 | use core::ptr::NonNull; | 2 | use core::ptr::NonNull; |
| 3 | |||
| 4 | use atomic_polyfill::{AtomicPtr, Ordering}; | ||
| 4 | use critical_section::CriticalSection; | 5 | use critical_section::CriticalSection; |
| 5 | 6 | ||
| 6 | use super::TaskHeader; | 7 | use super::TaskHeader; |
| @@ -63,10 +64,7 @@ impl RunQueue { | |||
| 63 | while let Some(task) = NonNull::new(ptr) { | 64 | while let Some(task) = NonNull::new(ptr) { |
| 64 | // If the task re-enqueues itself, the `next` pointer will get overwritten. | 65 | // If the task re-enqueues itself, the `next` pointer will get overwritten. |
| 65 | // Therefore, first read the next pointer, and only then process the task. | 66 | // Therefore, first read the next pointer, and only then process the task. |
| 66 | let next = unsafe { task.as_ref() } | 67 | let next = unsafe { task.as_ref() }.run_queue_item.next.load(Ordering::Relaxed); |
| 67 | .run_queue_item | ||
| 68 | .next | ||
| 69 | .load(Ordering::Relaxed); | ||
| 70 | 68 | ||
| 71 | on_task(task); | 69 | on_task(task); |
| 72 | 70 | ||
diff --git a/embassy/src/executor/raw/timer_queue.rs b/embassy/src/executor/raw/timer_queue.rs index e96910bb0..62fcfc531 100644 --- a/embassy/src/executor/raw/timer_queue.rs +++ b/embassy/src/executor/raw/timer_queue.rs | |||
| @@ -1,9 +1,10 @@ | |||
| 1 | use atomic_polyfill::Ordering; | ||
| 2 | use core::cell::Cell; | 1 | use core::cell::Cell; |
| 3 | use core::cmp::min; | 2 | use core::cmp::min; |
| 4 | use core::ptr; | 3 | use core::ptr; |
| 5 | use core::ptr::NonNull; | 4 | use core::ptr::NonNull; |
| 6 | 5 | ||
| 6 | use atomic_polyfill::Ordering; | ||
| 7 | |||
| 7 | use super::{TaskHeader, STATE_TIMER_QUEUED}; | 8 | use super::{TaskHeader, STATE_TIMER_QUEUED}; |
| 8 | use crate::time::Instant; | 9 | use crate::time::Instant; |
| 9 | 10 | ||
| @@ -54,11 +55,7 @@ impl TimerQueue { | |||
| 54 | res | 55 | res |
| 55 | } | 56 | } |
| 56 | 57 | ||
| 57 | pub(crate) unsafe fn dequeue_expired( | 58 | pub(crate) unsafe fn dequeue_expired(&self, now: Instant, on_task: impl Fn(NonNull<TaskHeader>)) { |
| 58 | &self, | ||
| 59 | now: Instant, | ||
| 60 | on_task: impl Fn(NonNull<TaskHeader>), | ||
| 61 | ) { | ||
| 62 | self.retain(|p| { | 59 | self.retain(|p| { |
| 63 | let task = p.as_ref(); | 60 | let task = p.as_ref(); |
| 64 | if task.expires_at.get() <= now { | 61 | if task.expires_at.get() <= now { |
diff --git a/embassy/src/executor/spawner.rs b/embassy/src/executor/spawner.rs index 73c1f786f..884db6b55 100644 --- a/embassy/src/executor/spawner.rs +++ b/embassy/src/executor/spawner.rs | |||
| @@ -2,6 +2,7 @@ use core::marker::PhantomData; | |||
| 2 | use core::mem; | 2 | use core::mem; |
| 3 | use core::ptr::NonNull; | 3 | use core::ptr::NonNull; |
| 4 | use core::task::Poll; | 4 | use core::task::Poll; |
| 5 | |||
| 5 | use futures::future::poll_fn; | 6 | use futures::future::poll_fn; |
| 6 | 7 | ||
| 7 | use super::raw; | 8 | use super::raw; |
diff --git a/embassy/src/lib.rs b/embassy/src/lib.rs index 5cfd18db7..1b6ff2d4b 100644 --- a/embassy/src/lib.rs +++ b/embassy/src/lib.rs | |||
| @@ -1,8 +1,5 @@ | |||
| 1 | #![cfg_attr(not(any(feature = "std", feature = "wasm")), no_std)] | 1 | #![cfg_attr(not(any(feature = "std", feature = "wasm")), no_std)] |
| 2 | #![cfg_attr( | 2 | #![cfg_attr(feature = "nightly", feature(generic_associated_types, type_alias_impl_trait))] |
| 3 | feature = "nightly", | ||
| 4 | feature(generic_associated_types, type_alias_impl_trait) | ||
| 5 | )] | ||
| 6 | #![allow(clippy::new_without_default)] | 3 | #![allow(clippy::new_without_default)] |
| 7 | 4 | ||
| 8 | // This mod MUST go first, so that the others see its macros. | 5 | // This mod MUST go first, so that the others see its macros. |
diff --git a/embassy/src/mutex.rs b/embassy/src/mutex.rs index 27353bd4d..7b6bcb147 100644 --- a/embassy/src/mutex.rs +++ b/embassy/src/mutex.rs | |||
| @@ -7,6 +7,7 @@ | |||
| 7 | use core::cell::{RefCell, UnsafeCell}; | 7 | use core::cell::{RefCell, UnsafeCell}; |
| 8 | use core::ops::{Deref, DerefMut}; | 8 | use core::ops::{Deref, DerefMut}; |
| 9 | use core::task::Poll; | 9 | use core::task::Poll; |
| 10 | |||
| 10 | use futures::future::poll_fn; | 11 | use futures::future::poll_fn; |
| 11 | 12 | ||
| 12 | use crate::blocking_mutex::raw::RawMutex; | 13 | use crate::blocking_mutex::raw::RawMutex; |
diff --git a/embassy/src/time/delay.rs b/embassy/src/time/delay.rs index 06ed8ec4e..83a895e93 100644 --- a/embassy/src/time/delay.rs +++ b/embassy/src/time/delay.rs | |||
| @@ -56,9 +56,10 @@ cfg_if::cfg_if! { | |||
| 56 | } | 56 | } |
| 57 | 57 | ||
| 58 | mod eh02 { | 58 | mod eh02 { |
| 59 | use super::*; | ||
| 60 | use embedded_hal_02::blocking::delay::{DelayMs, DelayUs}; | 59 | use embedded_hal_02::blocking::delay::{DelayMs, DelayUs}; |
| 61 | 60 | ||
| 61 | use super::*; | ||
| 62 | |||
| 62 | impl DelayMs<u8> for Delay { | 63 | impl DelayMs<u8> for Delay { |
| 63 | fn delay_ms(&mut self, ms: u8) { | 64 | fn delay_ms(&mut self, ms: u8) { |
| 64 | block_for(Duration::from_millis(ms as u64)) | 65 | block_for(Duration::from_millis(ms as u64)) |
diff --git a/embassy/src/time/driver_std.rs b/embassy/src/time/driver_std.rs index 0b5c6f85c..cb66f7c19 100644 --- a/embassy/src/time/driver_std.rs +++ b/embassy/src/time/driver_std.rs | |||
| @@ -1,11 +1,10 @@ | |||
| 1 | use atomic_polyfill::{AtomicU8, Ordering}; | ||
| 2 | use std::cell::UnsafeCell; | 1 | use std::cell::UnsafeCell; |
| 3 | use std::mem; | ||
| 4 | use std::mem::MaybeUninit; | 2 | use std::mem::MaybeUninit; |
| 5 | use std::sync::{Condvar, Mutex, Once}; | 3 | use std::sync::{Condvar, Mutex, Once}; |
| 6 | use std::time::Duration as StdDuration; | 4 | use std::time::{Duration as StdDuration, Instant as StdInstant}; |
| 7 | use std::time::Instant as StdInstant; | 5 | use std::{mem, ptr, thread}; |
| 8 | use std::{ptr, thread}; | 6 | |
| 7 | use atomic_polyfill::{AtomicU8, Ordering}; | ||
| 9 | 8 | ||
| 10 | use crate::time::driver::{AlarmHandle, Driver}; | 9 | use crate::time::driver::{AlarmHandle, Driver}; |
| 11 | 10 | ||
| @@ -106,15 +105,13 @@ impl Driver for TimeDriver { | |||
| 106 | } | 105 | } |
| 107 | 106 | ||
| 108 | unsafe fn allocate_alarm(&self) -> Option<AlarmHandle> { | 107 | unsafe fn allocate_alarm(&self) -> Option<AlarmHandle> { |
| 109 | let id = self | 108 | let id = self.alarm_count.fetch_update(Ordering::AcqRel, Ordering::Acquire, |x| { |
| 110 | .alarm_count | 109 | if x < ALARM_COUNT as u8 { |
| 111 | .fetch_update(Ordering::AcqRel, Ordering::Acquire, |x| { | 110 | Some(x + 1) |
| 112 | if x < ALARM_COUNT as u8 { | 111 | } else { |
| 113 | Some(x + 1) | 112 | None |
| 114 | } else { | 113 | } |
| 115 | None | 114 | }); |
| 116 | } | ||
| 117 | }); | ||
| 118 | 115 | ||
| 119 | match id { | 116 | match id { |
| 120 | Ok(id) => Some(AlarmHandle::new(id)), | 117 | Ok(id) => Some(AlarmHandle::new(id)), |
diff --git a/embassy/src/time/driver_wasm.rs b/embassy/src/time/driver_wasm.rs index 0a9270823..5f585a19a 100644 --- a/embassy/src/time/driver_wasm.rs +++ b/embassy/src/time/driver_wasm.rs | |||
| @@ -1,8 +1,9 @@ | |||
| 1 | use atomic_polyfill::{AtomicU8, Ordering}; | ||
| 2 | use std::cell::UnsafeCell; | 1 | use std::cell::UnsafeCell; |
| 3 | use std::mem::MaybeUninit; | 2 | use std::mem::MaybeUninit; |
| 4 | use std::ptr; | 3 | use std::ptr; |
| 5 | use std::sync::{Mutex, Once}; | 4 | use std::sync::{Mutex, Once}; |
| 5 | |||
| 6 | use atomic_polyfill::{AtomicU8, Ordering}; | ||
| 6 | use wasm_bindgen::prelude::*; | 7 | use wasm_bindgen::prelude::*; |
| 7 | use wasm_timer::Instant as StdInstant; | 8 | use wasm_timer::Instant as StdInstant; |
| 8 | 9 | ||
| @@ -66,15 +67,13 @@ impl Driver for TimeDriver { | |||
| 66 | } | 67 | } |
| 67 | 68 | ||
| 68 | unsafe fn allocate_alarm(&self) -> Option<AlarmHandle> { | 69 | unsafe fn allocate_alarm(&self) -> Option<AlarmHandle> { |
| 69 | let id = self | 70 | let id = self.alarm_count.fetch_update(Ordering::AcqRel, Ordering::Acquire, |x| { |
| 70 | .alarm_count | 71 | if x < ALARM_COUNT as u8 { |
| 71 | .fetch_update(Ordering::AcqRel, Ordering::Acquire, |x| { | 72 | Some(x + 1) |
| 72 | if x < ALARM_COUNT as u8 { | 73 | } else { |
| 73 | Some(x + 1) | 74 | None |
| 74 | } else { | 75 | } |
| 75 | None | 76 | }); |
| 76 | } | ||
| 77 | }); | ||
| 78 | 77 | ||
| 79 | match id { | 78 | match id { |
| 80 | Ok(id) => Some(AlarmHandle::new(id)), | 79 | Ok(id) => Some(AlarmHandle::new(id)), |
diff --git a/embassy/src/time/duration.rs b/embassy/src/time/duration.rs index 47b413f48..d35c2b65f 100644 --- a/embassy/src/time/duration.rs +++ b/embassy/src/time/duration.rs | |||
| @@ -65,30 +65,22 @@ impl Duration { | |||
| 65 | 65 | ||
| 66 | /// Adds one Duration to another, returning a new Duration or None in the event of an overflow. | 66 | /// Adds one Duration to another, returning a new Duration or None in the event of an overflow. |
| 67 | pub fn checked_add(self, rhs: Duration) -> Option<Duration> { | 67 | pub fn checked_add(self, rhs: Duration) -> Option<Duration> { |
| 68 | self.ticks | 68 | self.ticks.checked_add(rhs.ticks).map(|ticks| Duration { ticks }) |
| 69 | .checked_add(rhs.ticks) | ||
| 70 | .map(|ticks| Duration { ticks }) | ||
| 71 | } | 69 | } |
| 72 | 70 | ||
| 73 | /// Subtracts one Duration to another, returning a new Duration or None in the event of an overflow. | 71 | /// Subtracts one Duration to another, returning a new Duration or None in the event of an overflow. |
| 74 | pub fn checked_sub(self, rhs: Duration) -> Option<Duration> { | 72 | pub fn checked_sub(self, rhs: Duration) -> Option<Duration> { |
| 75 | self.ticks | 73 | self.ticks.checked_sub(rhs.ticks).map(|ticks| Duration { ticks }) |
| 76 | .checked_sub(rhs.ticks) | ||
| 77 | .map(|ticks| Duration { ticks }) | ||
| 78 | } | 74 | } |
| 79 | 75 | ||
| 80 | /// Multiplies one Duration by a scalar u32, returning a new Duration or None in the event of an overflow. | 76 | /// Multiplies one Duration by a scalar u32, returning a new Duration or None in the event of an overflow. |
| 81 | pub fn checked_mul(self, rhs: u32) -> Option<Duration> { | 77 | pub fn checked_mul(self, rhs: u32) -> Option<Duration> { |
| 82 | self.ticks | 78 | self.ticks.checked_mul(rhs as _).map(|ticks| Duration { ticks }) |
| 83 | .checked_mul(rhs as _) | ||
| 84 | .map(|ticks| Duration { ticks }) | ||
| 85 | } | 79 | } |
| 86 | 80 | ||
| 87 | /// Divides one Duration a scalar u32, returning a new Duration or None in the event of an overflow. | 81 | /// Divides one Duration a scalar u32, returning a new Duration or None in the event of an overflow. |
| 88 | pub fn checked_div(self, rhs: u32) -> Option<Duration> { | 82 | pub fn checked_div(self, rhs: u32) -> Option<Duration> { |
| 89 | self.ticks | 83 | self.ticks.checked_div(rhs as _).map(|ticks| Duration { ticks }) |
| 90 | .checked_div(rhs as _) | ||
| 91 | .map(|ticks| Duration { ticks }) | ||
| 92 | } | 84 | } |
| 93 | } | 85 | } |
| 94 | 86 | ||
| @@ -96,8 +88,7 @@ impl Add for Duration { | |||
| 96 | type Output = Duration; | 88 | type Output = Duration; |
| 97 | 89 | ||
| 98 | fn add(self, rhs: Duration) -> Duration { | 90 | fn add(self, rhs: Duration) -> Duration { |
| 99 | self.checked_add(rhs) | 91 | self.checked_add(rhs).expect("overflow when adding durations") |
| 100 | .expect("overflow when adding durations") | ||
| 101 | } | 92 | } |
| 102 | } | 93 | } |
| 103 | 94 | ||
| @@ -111,8 +102,7 @@ impl Sub for Duration { | |||
| 111 | type Output = Duration; | 102 | type Output = Duration; |
| 112 | 103 | ||
| 113 | fn sub(self, rhs: Duration) -> Duration { | 104 | fn sub(self, rhs: Duration) -> Duration { |
| 114 | self.checked_sub(rhs) | 105 | self.checked_sub(rhs).expect("overflow when subtracting durations") |
| 115 | .expect("overflow when subtracting durations") | ||
| 116 | } | 106 | } |
| 117 | } | 107 | } |
| 118 | 108 | ||
diff --git a/embassy/src/time/instant.rs b/embassy/src/time/instant.rs index 71adbeb3f..6a4925f47 100644 --- a/embassy/src/time/instant.rs +++ b/embassy/src/time/instant.rs | |||
| @@ -18,9 +18,7 @@ impl Instant { | |||
| 18 | 18 | ||
| 19 | /// Returns an Instant representing the current time. | 19 | /// Returns an Instant representing the current time. |
| 20 | pub fn now() -> Instant { | 20 | pub fn now() -> Instant { |
| 21 | Instant { | 21 | Instant { ticks: driver::now() } |
| 22 | ticks: driver::now(), | ||
| 23 | } | ||
| 24 | } | 22 | } |
| 25 | 23 | ||
| 26 | /// Create an Instant from a tick count since system boot. | 24 | /// Create an Instant from a tick count since system boot. |
| @@ -107,16 +105,12 @@ impl Instant { | |||
| 107 | 105 | ||
| 108 | /// Adds one Duration to self, returning a new `Instant` or None in the event of an overflow. | 106 | /// Adds one Duration to self, returning a new `Instant` or None in the event of an overflow. |
| 109 | pub fn checked_add(&self, duration: Duration) -> Option<Instant> { | 107 | pub fn checked_add(&self, duration: Duration) -> Option<Instant> { |
| 110 | self.ticks | 108 | self.ticks.checked_add(duration.ticks).map(|ticks| Instant { ticks }) |
| 111 | .checked_add(duration.ticks) | ||
| 112 | .map(|ticks| Instant { ticks }) | ||
| 113 | } | 109 | } |
| 114 | 110 | ||
| 115 | /// Subtracts one Duration to self, returning a new `Instant` or None in the event of an overflow. | 111 | /// Subtracts one Duration to self, returning a new `Instant` or None in the event of an overflow. |
| 116 | pub fn checked_sub(&self, duration: Duration) -> Option<Instant> { | 112 | pub fn checked_sub(&self, duration: Duration) -> Option<Instant> { |
| 117 | self.ticks | 113 | self.ticks.checked_sub(duration.ticks).map(|ticks| Instant { ticks }) |
| 118 | .checked_sub(duration.ticks) | ||
| 119 | .map(|ticks| Instant { ticks }) | ||
| 120 | } | 114 | } |
| 121 | } | 115 | } |
| 122 | 116 | ||
diff --git a/embassy/src/time/timer.rs b/embassy/src/time/timer.rs index 1b3832f37..2194a4b14 100644 --- a/embassy/src/time/timer.rs +++ b/embassy/src/time/timer.rs | |||
| @@ -1,7 +1,9 @@ | |||
| 1 | use core::future::Future; | 1 | use core::future::Future; |
| 2 | use core::pin::Pin; | 2 | use core::pin::Pin; |
| 3 | use core::task::{Context, Poll}; | 3 | use core::task::{Context, Poll}; |
| 4 | use futures::{future::select, future::Either, pin_mut, Stream}; | 4 | |
| 5 | use futures::future::{select, Either}; | ||
| 6 | use futures::{pin_mut, Stream}; | ||
| 5 | 7 | ||
| 6 | use crate::executor::raw; | 8 | use crate::executor::raw; |
| 7 | use crate::time::{Duration, Instant}; | 9 | use crate::time::{Duration, Instant}; |
| @@ -128,10 +130,7 @@ impl Ticker { | |||
| 128 | /// Creates a new ticker that ticks at the specified duration interval. | 130 | /// Creates a new ticker that ticks at the specified duration interval. |
| 129 | pub fn every(duration: Duration) -> Self { | 131 | pub fn every(duration: Duration) -> Self { |
| 130 | let expires_at = Instant::now() + duration; | 132 | let expires_at = Instant::now() + duration; |
| 131 | Self { | 133 | Self { expires_at, duration } |
| 132 | expires_at, | ||
| 133 | duration, | ||
| 134 | } | ||
| 135 | } | 134 | } |
| 136 | } | 135 | } |
| 137 | 136 | ||
diff --git a/embassy/src/waitqueue/waker.rs b/embassy/src/waitqueue/waker.rs index 9eddbdaa1..1ac6054f9 100644 --- a/embassy/src/waitqueue/waker.rs +++ b/embassy/src/waitqueue/waker.rs | |||
| @@ -1,7 +1,8 @@ | |||
| 1 | use atomic_polyfill::{compiler_fence, AtomicPtr, Ordering}; | ||
| 2 | use core::ptr::{self, NonNull}; | 1 | use core::ptr::{self, NonNull}; |
| 3 | use core::task::Waker; | 2 | use core::task::Waker; |
| 4 | 3 | ||
| 4 | use atomic_polyfill::{compiler_fence, AtomicPtr, Ordering}; | ||
| 5 | |||
| 5 | use crate::executor::raw::{task_from_waker, wake_task, TaskHeader}; | 6 | use crate::executor::raw::{task_from_waker, wake_task, TaskHeader}; |
| 6 | 7 | ||
| 7 | /// Utility struct to register and wake a waker. | 8 | /// Utility struct to register and wake a waker. |
diff --git a/examples/boot/nrf/src/bin/a.rs b/examples/boot/nrf/src/bin/a.rs index d45d0ff34..0b9715e49 100644 --- a/examples/boot/nrf/src/bin/a.rs +++ b/examples/boot/nrf/src/bin/a.rs | |||
| @@ -6,12 +6,9 @@ | |||
| 6 | 6 | ||
| 7 | use embassy_boot_nrf::FirmwareUpdater; | 7 | use embassy_boot_nrf::FirmwareUpdater; |
| 8 | use embassy_embedded_hal::adapter::BlockingAsync; | 8 | use embassy_embedded_hal::adapter::BlockingAsync; |
| 9 | use embassy_nrf::{ | 9 | use embassy_nrf::gpio::{Input, Level, Output, OutputDrive, Pull}; |
| 10 | gpio::{Input, Pull}, | 10 | use embassy_nrf::nvmc::Nvmc; |
| 11 | gpio::{Level, Output, OutputDrive}, | 11 | use embassy_nrf::Peripherals; |
| 12 | nvmc::Nvmc, | ||
| 13 | Peripherals, | ||
| 14 | }; | ||
| 15 | use panic_reset as _; | 12 | use panic_reset as _; |
| 16 | 13 | ||
| 17 | static APP_B: &[u8] = include_bytes!("../../b.bin"); | 14 | static APP_B: &[u8] = include_bytes!("../../b.bin"); |
| @@ -35,10 +32,7 @@ async fn main(_s: embassy::executor::Spawner, p: Peripherals) { | |||
| 35 | for chunk in APP_B.chunks(4096) { | 32 | for chunk in APP_B.chunks(4096) { |
| 36 | let mut buf: [u8; 4096] = [0; 4096]; | 33 | let mut buf: [u8; 4096] = [0; 4096]; |
| 37 | buf[..chunk.len()].copy_from_slice(chunk); | 34 | buf[..chunk.len()].copy_from_slice(chunk); |
| 38 | updater | 35 | updater.write_firmware(offset, &buf, &mut nvmc, 4096).await.unwrap(); |
| 39 | .write_firmware(offset, &buf, &mut nvmc, 4096) | ||
| 40 | .await | ||
| 41 | .unwrap(); | ||
| 42 | offset += chunk.len(); | 36 | offset += chunk.len(); |
| 43 | } | 37 | } |
| 44 | updater.update(&mut nvmc).await.unwrap(); | 38 | updater.update(&mut nvmc).await.unwrap(); |
diff --git a/examples/boot/nrf/src/bin/b.rs b/examples/boot/nrf/src/bin/b.rs index 18bb6330c..a06c20f8b 100644 --- a/examples/boot/nrf/src/bin/b.rs +++ b/examples/boot/nrf/src/bin/b.rs | |||
| @@ -5,11 +5,8 @@ | |||
| 5 | #![feature(type_alias_impl_trait)] | 5 | #![feature(type_alias_impl_trait)] |
| 6 | 6 | ||
| 7 | use embassy::time::{Duration, Timer}; | 7 | use embassy::time::{Duration, Timer}; |
| 8 | use embassy_nrf::{ | 8 | use embassy_nrf::gpio::{Level, Output, OutputDrive}; |
| 9 | gpio::{Level, Output, OutputDrive}, | 9 | use embassy_nrf::Peripherals; |
| 10 | Peripherals, | ||
| 11 | }; | ||
| 12 | |||
| 13 | use panic_reset as _; | 10 | use panic_reset as _; |
| 14 | 11 | ||
| 15 | #[embassy::main] | 12 | #[embassy::main] |
diff --git a/examples/boot/stm32f3/src/bin/a.rs b/examples/boot/stm32f3/src/bin/a.rs index 9ad798389..4ff18d7c7 100644 --- a/examples/boot/stm32f3/src/bin/a.rs +++ b/examples/boot/stm32f3/src/bin/a.rs | |||
| @@ -2,6 +2,8 @@ | |||
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | #[cfg(feature = "defmt-rtt")] | ||
| 6 | use defmt_rtt::*; | ||
| 5 | use embassy_boot_stm32::FirmwareUpdater; | 7 | use embassy_boot_stm32::FirmwareUpdater; |
| 6 | use embassy_embedded_hal::adapter::BlockingAsync; | 8 | use embassy_embedded_hal::adapter::BlockingAsync; |
| 7 | use embassy_stm32::exti::ExtiInput; | 9 | use embassy_stm32::exti::ExtiInput; |
| @@ -10,9 +12,6 @@ use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; | |||
| 10 | use embassy_stm32::Peripherals; | 12 | use embassy_stm32::Peripherals; |
| 11 | use panic_reset as _; | 13 | use panic_reset as _; |
| 12 | 14 | ||
| 13 | #[cfg(feature = "defmt-rtt")] | ||
| 14 | use defmt_rtt::*; | ||
| 15 | |||
| 16 | static APP_B: &[u8] = include_bytes!("../../b.bin"); | 15 | static APP_B: &[u8] = include_bytes!("../../b.bin"); |
| 17 | 16 | ||
| 18 | #[embassy::main] | 17 | #[embassy::main] |
| @@ -32,10 +31,7 @@ async fn main(_s: embassy::executor::Spawner, p: Peripherals) { | |||
| 32 | for chunk in APP_B.chunks(2048) { | 31 | for chunk in APP_B.chunks(2048) { |
| 33 | let mut buf: [u8; 2048] = [0; 2048]; | 32 | let mut buf: [u8; 2048] = [0; 2048]; |
| 34 | buf[..chunk.len()].copy_from_slice(chunk); | 33 | buf[..chunk.len()].copy_from_slice(chunk); |
| 35 | updater | 34 | updater.write_firmware(offset, &buf, &mut flash, 2048).await.unwrap(); |
| 36 | .write_firmware(offset, &buf, &mut flash, 2048) | ||
| 37 | .await | ||
| 38 | .unwrap(); | ||
| 39 | offset += chunk.len(); | 35 | offset += chunk.len(); |
| 40 | } | 36 | } |
| 41 | updater.update(&mut flash).await.unwrap(); | 37 | updater.update(&mut flash).await.unwrap(); |
diff --git a/examples/boot/stm32f3/src/bin/b.rs b/examples/boot/stm32f3/src/bin/b.rs index 814275988..4487e586e 100644 --- a/examples/boot/stm32f3/src/bin/b.rs +++ b/examples/boot/stm32f3/src/bin/b.rs | |||
| @@ -2,15 +2,14 @@ | |||
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | #[cfg(feature = "defmt-rtt")] | ||
| 6 | use defmt_rtt::*; | ||
| 5 | use embassy::executor::Spawner; | 7 | use embassy::executor::Spawner; |
| 6 | use embassy::time::{Duration, Timer}; | 8 | use embassy::time::{Duration, Timer}; |
| 7 | use embassy_stm32::gpio::{Level, Output, Speed}; | 9 | use embassy_stm32::gpio::{Level, Output, Speed}; |
| 8 | use embassy_stm32::Peripherals; | 10 | use embassy_stm32::Peripherals; |
| 9 | use panic_reset as _; | 11 | use panic_reset as _; |
| 10 | 12 | ||
| 11 | #[cfg(feature = "defmt-rtt")] | ||
| 12 | use defmt_rtt::*; | ||
| 13 | |||
| 14 | #[embassy::main] | 13 | #[embassy::main] |
| 15 | async fn main(_spawner: Spawner, p: Peripherals) { | 14 | async fn main(_spawner: Spawner, p: Peripherals) { |
| 16 | let mut led = Output::new(p.PA5, Level::High, Speed::Low); | 15 | let mut led = Output::new(p.PA5, Level::High, Speed::Low); |
diff --git a/examples/boot/stm32f7/src/bin/a.rs b/examples/boot/stm32f7/src/bin/a.rs index b4f49d579..9c7921a1a 100644 --- a/examples/boot/stm32f7/src/bin/a.rs +++ b/examples/boot/stm32f7/src/bin/a.rs | |||
| @@ -2,6 +2,8 @@ | |||
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | #[cfg(feature = "defmt-rtt")] | ||
| 6 | use defmt_rtt::*; | ||
| 5 | use embassy_boot_stm32::FirmwareUpdater; | 7 | use embassy_boot_stm32::FirmwareUpdater; |
| 6 | use embassy_embedded_hal::adapter::BlockingAsync; | 8 | use embassy_embedded_hal::adapter::BlockingAsync; |
| 7 | use embassy_stm32::exti::ExtiInput; | 9 | use embassy_stm32::exti::ExtiInput; |
| @@ -10,9 +12,6 @@ use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; | |||
| 10 | use embassy_stm32::Peripherals; | 12 | use embassy_stm32::Peripherals; |
| 11 | use panic_reset as _; | 13 | use panic_reset as _; |
| 12 | 14 | ||
| 13 | #[cfg(feature = "defmt-rtt")] | ||
| 14 | use defmt_rtt::*; | ||
| 15 | |||
| 16 | static APP_B: &[u8] = include_bytes!("../../b.bin"); | 15 | static APP_B: &[u8] = include_bytes!("../../b.bin"); |
| 17 | 16 | ||
| 18 | #[embassy::main] | 17 | #[embassy::main] |
| @@ -32,10 +31,7 @@ async fn main(_s: embassy::executor::Spawner, p: Peripherals) { | |||
| 32 | let mut buf: [u8; 256 * 1024] = [0; 256 * 1024]; | 31 | let mut buf: [u8; 256 * 1024] = [0; 256 * 1024]; |
| 33 | for chunk in APP_B.chunks(256 * 1024) { | 32 | for chunk in APP_B.chunks(256 * 1024) { |
| 34 | buf[..chunk.len()].copy_from_slice(chunk); | 33 | buf[..chunk.len()].copy_from_slice(chunk); |
| 35 | updater | 34 | updater.write_firmware(offset, &buf, &mut flash, 2048).await.unwrap(); |
| 36 | .write_firmware(offset, &buf, &mut flash, 2048) | ||
| 37 | .await | ||
| 38 | .unwrap(); | ||
| 39 | offset += chunk.len(); | 35 | offset += chunk.len(); |
| 40 | } | 36 | } |
| 41 | updater.update(&mut flash).await.unwrap(); | 37 | updater.update(&mut flash).await.unwrap(); |
diff --git a/examples/boot/stm32f7/src/bin/b.rs b/examples/boot/stm32f7/src/bin/b.rs index ed37137f5..aa05bbcdd 100644 --- a/examples/boot/stm32f7/src/bin/b.rs +++ b/examples/boot/stm32f7/src/bin/b.rs | |||
| @@ -2,15 +2,14 @@ | |||
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | #[cfg(feature = "defmt-rtt")] | ||
| 6 | use defmt_rtt::*; | ||
| 5 | use embassy::executor::Spawner; | 7 | use embassy::executor::Spawner; |
| 6 | use embassy::time::{Duration, Timer}; | 8 | use embassy::time::{Duration, Timer}; |
| 7 | use embassy_stm32::gpio::{Level, Output, Speed}; | 9 | use embassy_stm32::gpio::{Level, Output, Speed}; |
| 8 | use embassy_stm32::Peripherals; | 10 | use embassy_stm32::Peripherals; |
| 9 | use panic_reset as _; | 11 | use panic_reset as _; |
| 10 | 12 | ||
| 11 | #[cfg(feature = "defmt-rtt")] | ||
| 12 | use defmt_rtt::*; | ||
| 13 | |||
| 14 | #[embassy::main] | 13 | #[embassy::main] |
| 15 | async fn main(_spawner: Spawner, p: Peripherals) { | 14 | async fn main(_spawner: Spawner, p: Peripherals) { |
| 16 | Timer::after(Duration::from_millis(300)).await; | 15 | Timer::after(Duration::from_millis(300)).await; |
diff --git a/examples/boot/stm32h7/src/bin/a.rs b/examples/boot/stm32h7/src/bin/a.rs index 1d196e8a5..704979dba 100644 --- a/examples/boot/stm32h7/src/bin/a.rs +++ b/examples/boot/stm32h7/src/bin/a.rs | |||
| @@ -2,6 +2,8 @@ | |||
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | #[cfg(feature = "defmt-rtt")] | ||
| 6 | use defmt_rtt::*; | ||
| 5 | use embassy_boot_stm32::FirmwareUpdater; | 7 | use embassy_boot_stm32::FirmwareUpdater; |
| 6 | use embassy_embedded_hal::adapter::BlockingAsync; | 8 | use embassy_embedded_hal::adapter::BlockingAsync; |
| 7 | use embassy_stm32::exti::ExtiInput; | 9 | use embassy_stm32::exti::ExtiInput; |
| @@ -10,9 +12,6 @@ use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; | |||
| 10 | use embassy_stm32::Peripherals; | 12 | use embassy_stm32::Peripherals; |
| 11 | use panic_reset as _; | 13 | use panic_reset as _; |
| 12 | 14 | ||
| 13 | #[cfg(feature = "defmt-rtt")] | ||
| 14 | use defmt_rtt::*; | ||
| 15 | |||
| 16 | static APP_B: &[u8] = include_bytes!("../../b.bin"); | 15 | static APP_B: &[u8] = include_bytes!("../../b.bin"); |
| 17 | 16 | ||
| 18 | #[embassy::main] | 17 | #[embassy::main] |
| @@ -32,10 +31,7 @@ async fn main(_s: embassy::executor::Spawner, p: Peripherals) { | |||
| 32 | let mut buf: [u8; 128 * 1024] = [0; 128 * 1024]; | 31 | let mut buf: [u8; 128 * 1024] = [0; 128 * 1024]; |
| 33 | for chunk in APP_B.chunks(128 * 1024) { | 32 | for chunk in APP_B.chunks(128 * 1024) { |
| 34 | buf[..chunk.len()].copy_from_slice(chunk); | 33 | buf[..chunk.len()].copy_from_slice(chunk); |
| 35 | updater | 34 | updater.write_firmware(offset, &buf, &mut flash, 2048).await.unwrap(); |
| 36 | .write_firmware(offset, &buf, &mut flash, 2048) | ||
| 37 | .await | ||
| 38 | .unwrap(); | ||
| 39 | offset += chunk.len(); | 35 | offset += chunk.len(); |
| 40 | } | 36 | } |
| 41 | updater.update(&mut flash).await.unwrap(); | 37 | updater.update(&mut flash).await.unwrap(); |
diff --git a/examples/boot/stm32h7/src/bin/b.rs b/examples/boot/stm32h7/src/bin/b.rs index 233b93e1a..ea0140253 100644 --- a/examples/boot/stm32h7/src/bin/b.rs +++ b/examples/boot/stm32h7/src/bin/b.rs | |||
| @@ -2,15 +2,14 @@ | |||
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | #[cfg(feature = "defmt-rtt")] | ||
| 6 | use defmt_rtt::*; | ||
| 5 | use embassy::executor::Spawner; | 7 | use embassy::executor::Spawner; |
| 6 | use embassy::time::{Duration, Timer}; | 8 | use embassy::time::{Duration, Timer}; |
| 7 | use embassy_stm32::gpio::{Level, Output, Speed}; | 9 | use embassy_stm32::gpio::{Level, Output, Speed}; |
| 8 | use embassy_stm32::Peripherals; | 10 | use embassy_stm32::Peripherals; |
| 9 | use panic_reset as _; | 11 | use panic_reset as _; |
| 10 | 12 | ||
| 11 | #[cfg(feature = "defmt-rtt")] | ||
| 12 | use defmt_rtt::*; | ||
| 13 | |||
| 14 | #[embassy::main] | 13 | #[embassy::main] |
| 15 | async fn main(_spawner: Spawner, p: Peripherals) { | 14 | async fn main(_spawner: Spawner, p: Peripherals) { |
| 16 | Timer::after(Duration::from_millis(300)).await; | 15 | Timer::after(Duration::from_millis(300)).await; |
diff --git a/examples/boot/stm32l0/src/bin/a.rs b/examples/boot/stm32l0/src/bin/a.rs index d4b252bf0..ce620347b 100644 --- a/examples/boot/stm32l0/src/bin/a.rs +++ b/examples/boot/stm32l0/src/bin/a.rs | |||
| @@ -2,6 +2,8 @@ | |||
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | #[cfg(feature = "defmt-rtt")] | ||
| 6 | use defmt_rtt::*; | ||
| 5 | use embassy::time::{Duration, Timer}; | 7 | use embassy::time::{Duration, Timer}; |
| 6 | use embassy_boot_stm32::FirmwareUpdater; | 8 | use embassy_boot_stm32::FirmwareUpdater; |
| 7 | use embassy_embedded_hal::adapter::BlockingAsync; | 9 | use embassy_embedded_hal::adapter::BlockingAsync; |
| @@ -11,9 +13,6 @@ use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; | |||
| 11 | use embassy_stm32::Peripherals; | 13 | use embassy_stm32::Peripherals; |
| 12 | use panic_reset as _; | 14 | use panic_reset as _; |
| 13 | 15 | ||
| 14 | #[cfg(feature = "defmt-rtt")] | ||
| 15 | use defmt_rtt::*; | ||
| 16 | |||
| 17 | static APP_B: &[u8] = include_bytes!("../../b.bin"); | 16 | static APP_B: &[u8] = include_bytes!("../../b.bin"); |
| 18 | 17 | ||
| 19 | #[embassy::main] | 18 | #[embassy::main] |
| @@ -34,10 +33,7 @@ async fn main(_s: embassy::executor::Spawner, p: Peripherals) { | |||
| 34 | for chunk in APP_B.chunks(128) { | 33 | for chunk in APP_B.chunks(128) { |
| 35 | let mut buf: [u8; 128] = [0; 128]; | 34 | let mut buf: [u8; 128] = [0; 128]; |
| 36 | buf[..chunk.len()].copy_from_slice(chunk); | 35 | buf[..chunk.len()].copy_from_slice(chunk); |
| 37 | updater | 36 | updater.write_firmware(offset, &buf, &mut flash, 128).await.unwrap(); |
| 38 | .write_firmware(offset, &buf, &mut flash, 128) | ||
| 39 | .await | ||
| 40 | .unwrap(); | ||
| 41 | offset += chunk.len(); | 37 | offset += chunk.len(); |
| 42 | } | 38 | } |
| 43 | 39 | ||
diff --git a/examples/boot/stm32l0/src/bin/b.rs b/examples/boot/stm32l0/src/bin/b.rs index ed774fd70..0b585a14c 100644 --- a/examples/boot/stm32l0/src/bin/b.rs +++ b/examples/boot/stm32l0/src/bin/b.rs | |||
| @@ -2,15 +2,14 @@ | |||
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | #[cfg(feature = "defmt-rtt")] | ||
| 6 | use defmt_rtt::*; | ||
| 5 | use embassy::executor::Spawner; | 7 | use embassy::executor::Spawner; |
| 6 | use embassy::time::{Duration, Timer}; | 8 | use embassy::time::{Duration, Timer}; |
| 7 | use embassy_stm32::gpio::{Level, Output, Speed}; | 9 | use embassy_stm32::gpio::{Level, Output, Speed}; |
| 8 | use embassy_stm32::Peripherals; | 10 | use embassy_stm32::Peripherals; |
| 9 | use panic_reset as _; | 11 | use panic_reset as _; |
| 10 | 12 | ||
| 11 | #[cfg(feature = "defmt-rtt")] | ||
| 12 | use defmt_rtt::*; | ||
| 13 | |||
| 14 | #[embassy::main] | 13 | #[embassy::main] |
| 15 | async fn main(_spawner: Spawner, p: Peripherals) { | 14 | async fn main(_spawner: Spawner, p: Peripherals) { |
| 16 | let mut led = Output::new(p.PB6, Level::High, Speed::Low); | 15 | let mut led = Output::new(p.PB6, Level::High, Speed::Low); |
diff --git a/examples/boot/stm32l1/src/bin/a.rs b/examples/boot/stm32l1/src/bin/a.rs index d4b252bf0..ce620347b 100644 --- a/examples/boot/stm32l1/src/bin/a.rs +++ b/examples/boot/stm32l1/src/bin/a.rs | |||
| @@ -2,6 +2,8 @@ | |||
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | #[cfg(feature = "defmt-rtt")] | ||
| 6 | use defmt_rtt::*; | ||
| 5 | use embassy::time::{Duration, Timer}; | 7 | use embassy::time::{Duration, Timer}; |
| 6 | use embassy_boot_stm32::FirmwareUpdater; | 8 | use embassy_boot_stm32::FirmwareUpdater; |
| 7 | use embassy_embedded_hal::adapter::BlockingAsync; | 9 | use embassy_embedded_hal::adapter::BlockingAsync; |
| @@ -11,9 +13,6 @@ use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; | |||
| 11 | use embassy_stm32::Peripherals; | 13 | use embassy_stm32::Peripherals; |
| 12 | use panic_reset as _; | 14 | use panic_reset as _; |
| 13 | 15 | ||
| 14 | #[cfg(feature = "defmt-rtt")] | ||
| 15 | use defmt_rtt::*; | ||
| 16 | |||
| 17 | static APP_B: &[u8] = include_bytes!("../../b.bin"); | 16 | static APP_B: &[u8] = include_bytes!("../../b.bin"); |
| 18 | 17 | ||
| 19 | #[embassy::main] | 18 | #[embassy::main] |
| @@ -34,10 +33,7 @@ async fn main(_s: embassy::executor::Spawner, p: Peripherals) { | |||
| 34 | for chunk in APP_B.chunks(128) { | 33 | for chunk in APP_B.chunks(128) { |
| 35 | let mut buf: [u8; 128] = [0; 128]; | 34 | let mut buf: [u8; 128] = [0; 128]; |
| 36 | buf[..chunk.len()].copy_from_slice(chunk); | 35 | buf[..chunk.len()].copy_from_slice(chunk); |
| 37 | updater | 36 | updater.write_firmware(offset, &buf, &mut flash, 128).await.unwrap(); |
| 38 | .write_firmware(offset, &buf, &mut flash, 128) | ||
| 39 | .await | ||
| 40 | .unwrap(); | ||
| 41 | offset += chunk.len(); | 37 | offset += chunk.len(); |
| 42 | } | 38 | } |
| 43 | 39 | ||
diff --git a/examples/boot/stm32l1/src/bin/b.rs b/examples/boot/stm32l1/src/bin/b.rs index ed774fd70..0b585a14c 100644 --- a/examples/boot/stm32l1/src/bin/b.rs +++ b/examples/boot/stm32l1/src/bin/b.rs | |||
| @@ -2,15 +2,14 @@ | |||
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | #[cfg(feature = "defmt-rtt")] | ||
| 6 | use defmt_rtt::*; | ||
| 5 | use embassy::executor::Spawner; | 7 | use embassy::executor::Spawner; |
| 6 | use embassy::time::{Duration, Timer}; | 8 | use embassy::time::{Duration, Timer}; |
| 7 | use embassy_stm32::gpio::{Level, Output, Speed}; | 9 | use embassy_stm32::gpio::{Level, Output, Speed}; |
| 8 | use embassy_stm32::Peripherals; | 10 | use embassy_stm32::Peripherals; |
| 9 | use panic_reset as _; | 11 | use panic_reset as _; |
| 10 | 12 | ||
| 11 | #[cfg(feature = "defmt-rtt")] | ||
| 12 | use defmt_rtt::*; | ||
| 13 | |||
| 14 | #[embassy::main] | 13 | #[embassy::main] |
| 15 | async fn main(_spawner: Spawner, p: Peripherals) { | 14 | async fn main(_spawner: Spawner, p: Peripherals) { |
| 16 | let mut led = Output::new(p.PB6, Level::High, Speed::Low); | 15 | let mut led = Output::new(p.PB6, Level::High, Speed::Low); |
diff --git a/examples/boot/stm32l4/src/bin/a.rs b/examples/boot/stm32l4/src/bin/a.rs index 23b1d98bb..bf6099355 100644 --- a/examples/boot/stm32l4/src/bin/a.rs +++ b/examples/boot/stm32l4/src/bin/a.rs | |||
| @@ -2,6 +2,8 @@ | |||
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | #[cfg(feature = "defmt-rtt")] | ||
| 6 | use defmt_rtt::*; | ||
| 5 | use embassy_boot_stm32::FirmwareUpdater; | 7 | use embassy_boot_stm32::FirmwareUpdater; |
| 6 | use embassy_embedded_hal::adapter::BlockingAsync; | 8 | use embassy_embedded_hal::adapter::BlockingAsync; |
| 7 | use embassy_stm32::exti::ExtiInput; | 9 | use embassy_stm32::exti::ExtiInput; |
| @@ -10,9 +12,6 @@ use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; | |||
| 10 | use embassy_stm32::Peripherals; | 12 | use embassy_stm32::Peripherals; |
| 11 | use panic_reset as _; | 13 | use panic_reset as _; |
| 12 | 14 | ||
| 13 | #[cfg(feature = "defmt-rtt")] | ||
| 14 | use defmt_rtt::*; | ||
| 15 | |||
| 16 | static APP_B: &[u8] = include_bytes!("../../b.bin"); | 15 | static APP_B: &[u8] = include_bytes!("../../b.bin"); |
| 17 | 16 | ||
| 18 | #[embassy::main] | 17 | #[embassy::main] |
| @@ -32,10 +31,7 @@ async fn main(_s: embassy::executor::Spawner, p: Peripherals) { | |||
| 32 | for chunk in APP_B.chunks(2048) { | 31 | for chunk in APP_B.chunks(2048) { |
| 33 | let mut buf: [u8; 2048] = [0; 2048]; | 32 | let mut buf: [u8; 2048] = [0; 2048]; |
| 34 | buf[..chunk.len()].copy_from_slice(chunk); | 33 | buf[..chunk.len()].copy_from_slice(chunk); |
| 35 | updater | 34 | updater.write_firmware(offset, &buf, &mut flash, 2048).await.unwrap(); |
| 36 | .write_firmware(offset, &buf, &mut flash, 2048) | ||
| 37 | .await | ||
| 38 | .unwrap(); | ||
| 39 | offset += chunk.len(); | 35 | offset += chunk.len(); |
| 40 | } | 36 | } |
| 41 | updater.update(&mut flash).await.unwrap(); | 37 | updater.update(&mut flash).await.unwrap(); |
diff --git a/examples/boot/stm32l4/src/bin/b.rs b/examples/boot/stm32l4/src/bin/b.rs index 814275988..4487e586e 100644 --- a/examples/boot/stm32l4/src/bin/b.rs +++ b/examples/boot/stm32l4/src/bin/b.rs | |||
| @@ -2,15 +2,14 @@ | |||
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | #[cfg(feature = "defmt-rtt")] | ||
| 6 | use defmt_rtt::*; | ||
| 5 | use embassy::executor::Spawner; | 7 | use embassy::executor::Spawner; |
| 6 | use embassy::time::{Duration, Timer}; | 8 | use embassy::time::{Duration, Timer}; |
| 7 | use embassy_stm32::gpio::{Level, Output, Speed}; | 9 | use embassy_stm32::gpio::{Level, Output, Speed}; |
| 8 | use embassy_stm32::Peripherals; | 10 | use embassy_stm32::Peripherals; |
| 9 | use panic_reset as _; | 11 | use panic_reset as _; |
| 10 | 12 | ||
| 11 | #[cfg(feature = "defmt-rtt")] | ||
| 12 | use defmt_rtt::*; | ||
| 13 | |||
| 14 | #[embassy::main] | 13 | #[embassy::main] |
| 15 | async fn main(_spawner: Spawner, p: Peripherals) { | 14 | async fn main(_spawner: Spawner, p: Peripherals) { |
| 16 | let mut led = Output::new(p.PA5, Level::High, Speed::Low); | 15 | let mut led = Output::new(p.PA5, Level::High, Speed::Low); |
diff --git a/examples/boot/stm32wl/src/bin/a.rs b/examples/boot/stm32wl/src/bin/a.rs index 1089eff1e..dc1eb9bed 100644 --- a/examples/boot/stm32wl/src/bin/a.rs +++ b/examples/boot/stm32wl/src/bin/a.rs | |||
| @@ -2,6 +2,8 @@ | |||
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | #[cfg(feature = "defmt-rtt")] | ||
| 6 | use defmt_rtt::*; | ||
| 5 | use embassy_boot_stm32::FirmwareUpdater; | 7 | use embassy_boot_stm32::FirmwareUpdater; |
| 6 | use embassy_embedded_hal::adapter::BlockingAsync; | 8 | use embassy_embedded_hal::adapter::BlockingAsync; |
| 7 | use embassy_stm32::exti::ExtiInput; | 9 | use embassy_stm32::exti::ExtiInput; |
| @@ -10,9 +12,6 @@ use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; | |||
| 10 | use embassy_stm32::Peripherals; | 12 | use embassy_stm32::Peripherals; |
| 11 | use panic_reset as _; | 13 | use panic_reset as _; |
| 12 | 14 | ||
| 13 | #[cfg(feature = "defmt-rtt")] | ||
| 14 | use defmt_rtt::*; | ||
| 15 | |||
| 16 | static APP_B: &[u8] = include_bytes!("../../b.bin"); | 15 | static APP_B: &[u8] = include_bytes!("../../b.bin"); |
| 17 | 16 | ||
| 18 | #[embassy::main] | 17 | #[embassy::main] |
| @@ -34,10 +33,7 @@ async fn main(_s: embassy::executor::Spawner, p: Peripherals) { | |||
| 34 | let mut buf: [u8; 2048] = [0; 2048]; | 33 | let mut buf: [u8; 2048] = [0; 2048]; |
| 35 | buf[..chunk.len()].copy_from_slice(chunk); | 34 | buf[..chunk.len()].copy_from_slice(chunk); |
| 36 | // defmt::info!("Writing chunk at 0x{:x}", offset); | 35 | // defmt::info!("Writing chunk at 0x{:x}", offset); |
| 37 | updater | 36 | updater.write_firmware(offset, &buf, &mut flash, 2048).await.unwrap(); |
| 38 | .write_firmware(offset, &buf, &mut flash, 2048) | ||
| 39 | .await | ||
| 40 | .unwrap(); | ||
| 41 | offset += chunk.len(); | 37 | offset += chunk.len(); |
| 42 | } | 38 | } |
| 43 | updater.update(&mut flash).await.unwrap(); | 39 | updater.update(&mut flash).await.unwrap(); |
diff --git a/examples/boot/stm32wl/src/bin/b.rs b/examples/boot/stm32wl/src/bin/b.rs index ffe15b661..f2344bd53 100644 --- a/examples/boot/stm32wl/src/bin/b.rs +++ b/examples/boot/stm32wl/src/bin/b.rs | |||
| @@ -2,15 +2,14 @@ | |||
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | #[cfg(feature = "defmt-rtt")] | ||
| 6 | use defmt_rtt::*; | ||
| 5 | use embassy::executor::Spawner; | 7 | use embassy::executor::Spawner; |
| 6 | use embassy::time::{Duration, Timer}; | 8 | use embassy::time::{Duration, Timer}; |
| 7 | use embassy_stm32::gpio::{Level, Output, Speed}; | 9 | use embassy_stm32::gpio::{Level, Output, Speed}; |
| 8 | use embassy_stm32::Peripherals; | 10 | use embassy_stm32::Peripherals; |
| 9 | use panic_reset as _; | 11 | use panic_reset as _; |
| 10 | 12 | ||
| 11 | #[cfg(feature = "defmt-rtt")] | ||
| 12 | use defmt_rtt::*; | ||
| 13 | |||
| 14 | #[embassy::main] | 13 | #[embassy::main] |
| 15 | async fn main(_spawner: Spawner, p: Peripherals) { | 14 | async fn main(_spawner: Spawner, p: Peripherals) { |
| 16 | let mut led = Output::new(p.PB15, Level::High, Speed::Low); | 15 | let mut led = Output::new(p.PB15, Level::High, Speed::Low); |
diff --git a/examples/nrf/src/bin/awaitable_timer.rs b/examples/nrf/src/bin/awaitable_timer.rs index 810b4bd6a..34a657cb9 100644 --- a/examples/nrf/src/bin/awaitable_timer.rs +++ b/examples/nrf/src/bin/awaitable_timer.rs | |||
| @@ -4,12 +4,9 @@ | |||
| 4 | 4 | ||
| 5 | use defmt::info; | 5 | use defmt::info; |
| 6 | use embassy::executor::Spawner; | 6 | use embassy::executor::Spawner; |
| 7 | use embassy_nrf::interrupt; | ||
| 8 | use embassy_nrf::timer::Timer; | 7 | use embassy_nrf::timer::Timer; |
| 9 | use embassy_nrf::Peripherals; | 8 | use embassy_nrf::{interrupt, Peripherals}; |
| 10 | 9 | use {defmt_rtt as _, panic_probe as _}; | |
| 11 | use defmt_rtt as _; // global logger | ||
| 12 | use panic_probe as _; | ||
| 13 | 10 | ||
| 14 | #[embassy::main] | 11 | #[embassy::main] |
| 15 | async fn main(_spawner: Spawner, p: Peripherals) { | 12 | async fn main(_spawner: Spawner, p: Peripherals) { |
diff --git a/examples/nrf/src/bin/blinky.rs b/examples/nrf/src/bin/blinky.rs index 4828b08fb..23d16f796 100644 --- a/examples/nrf/src/bin/blinky.rs +++ b/examples/nrf/src/bin/blinky.rs | |||
| @@ -6,9 +6,7 @@ use embassy::executor::Spawner; | |||
| 6 | use embassy::time::{Duration, Timer}; | 6 | use embassy::time::{Duration, Timer}; |
| 7 | use embassy_nrf::gpio::{Level, Output, OutputDrive}; | 7 | use embassy_nrf::gpio::{Level, Output, OutputDrive}; |
| 8 | use embassy_nrf::Peripherals; | 8 | use embassy_nrf::Peripherals; |
| 9 | 9 | use {defmt_rtt as _, panic_probe as _}; | |
| 10 | use defmt_rtt as _; // global logger | ||
| 11 | use panic_probe as _; | ||
| 12 | 10 | ||
| 13 | #[embassy::main] | 11 | #[embassy::main] |
| 14 | async fn main(_spawner: Spawner, p: Peripherals) { | 12 | async fn main(_spawner: Spawner, p: Peripherals) { |
diff --git a/examples/nrf/src/bin/buffered_uart.rs b/examples/nrf/src/bin/buffered_uart.rs index 782c39499..18dd698bf 100644 --- a/examples/nrf/src/bin/buffered_uart.rs +++ b/examples/nrf/src/bin/buffered_uart.rs | |||
| @@ -4,13 +4,11 @@ | |||
| 4 | 4 | ||
| 5 | use defmt::*; | 5 | use defmt::*; |
| 6 | use embassy::executor::Spawner; | 6 | use embassy::executor::Spawner; |
| 7 | use embassy_nrf::buffered_uarte::State; | 7 | use embassy_nrf::buffered_uarte::{BufferedUarte, State}; |
| 8 | use embassy_nrf::{buffered_uarte::BufferedUarte, interrupt, uarte, Peripherals}; | 8 | use embassy_nrf::{interrupt, uarte, Peripherals}; |
| 9 | use embedded_io::asynch::{BufRead, Write}; | 9 | use embedded_io::asynch::{BufRead, Write}; |
| 10 | use futures::pin_mut; | 10 | use futures::pin_mut; |
| 11 | 11 | use {defmt_rtt as _, panic_probe as _}; | |
| 12 | use defmt_rtt as _; // global logger | ||
| 13 | use panic_probe as _; | ||
| 14 | 12 | ||
| 15 | #[embassy::main] | 13 | #[embassy::main] |
| 16 | async fn main(_spawner: Spawner, p: Peripherals) { | 14 | async fn main(_spawner: Spawner, p: Peripherals) { |
diff --git a/examples/nrf/src/bin/channel.rs b/examples/nrf/src/bin/channel.rs index 12b463581..c57b91a42 100644 --- a/examples/nrf/src/bin/channel.rs +++ b/examples/nrf/src/bin/channel.rs | |||
| @@ -9,9 +9,7 @@ use embassy::executor::Spawner; | |||
| 9 | use embassy::time::{Duration, Timer}; | 9 | use embassy::time::{Duration, Timer}; |
| 10 | use embassy_nrf::gpio::{Level, Output, OutputDrive}; | 10 | use embassy_nrf::gpio::{Level, Output, OutputDrive}; |
| 11 | use embassy_nrf::Peripherals; | 11 | use embassy_nrf::Peripherals; |
| 12 | 12 | use {defmt_rtt as _, panic_probe as _}; | |
| 13 | use defmt_rtt as _; // global logger | ||
| 14 | use panic_probe as _; | ||
| 15 | 13 | ||
| 16 | enum LedState { | 14 | enum LedState { |
| 17 | On, | 15 | On, |
diff --git a/examples/nrf/src/bin/channel_sender_receiver.rs b/examples/nrf/src/bin/channel_sender_receiver.rs index 1742dcc9e..847ce2382 100644 --- a/examples/nrf/src/bin/channel_sender_receiver.rs +++ b/examples/nrf/src/bin/channel_sender_receiver.rs | |||
| @@ -10,9 +10,7 @@ use embassy::time::{Duration, Timer}; | |||
| 10 | use embassy::util::Forever; | 10 | use embassy::util::Forever; |
| 11 | use embassy_nrf::gpio::{AnyPin, Level, Output, OutputDrive, Pin}; | 11 | use embassy_nrf::gpio::{AnyPin, Level, Output, OutputDrive, Pin}; |
| 12 | use embassy_nrf::Peripherals; | 12 | use embassy_nrf::Peripherals; |
| 13 | 13 | use {defmt_rtt as _, panic_probe as _}; | |
| 14 | use defmt_rtt as _; // global logger | ||
| 15 | use panic_probe as _; | ||
| 16 | 14 | ||
| 17 | enum LedState { | 15 | enum LedState { |
| 18 | On, | 16 | On, |
diff --git a/examples/nrf/src/bin/executor_fairness_test.rs b/examples/nrf/src/bin/executor_fairness_test.rs index 7a356d14b..5a4221519 100644 --- a/examples/nrf/src/bin/executor_fairness_test.rs +++ b/examples/nrf/src/bin/executor_fairness_test.rs | |||
| @@ -3,13 +3,12 @@ | |||
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | use core::task::Poll; | 5 | use core::task::Poll; |
| 6 | |||
| 6 | use defmt::{info, unwrap}; | 7 | use defmt::{info, unwrap}; |
| 7 | use embassy::executor::Spawner; | 8 | use embassy::executor::Spawner; |
| 8 | use embassy::time::{Duration, Instant, Timer}; | 9 | use embassy::time::{Duration, Instant, Timer}; |
| 9 | use embassy_nrf::Peripherals; | 10 | use embassy_nrf::Peripherals; |
| 10 | 11 | use {defmt_rtt as _, panic_probe as _}; | |
| 11 | use defmt_rtt as _; // global logger | ||
| 12 | use panic_probe as _; | ||
| 13 | 12 | ||
| 14 | #[embassy::task] | 13 | #[embassy::task] |
| 15 | async fn run1() { | 14 | async fn run1() { |
diff --git a/examples/nrf/src/bin/gpiote_channel.rs b/examples/nrf/src/bin/gpiote_channel.rs index 339f779f8..ad8f37c6e 100644 --- a/examples/nrf/src/bin/gpiote_channel.rs +++ b/examples/nrf/src/bin/gpiote_channel.rs | |||
| @@ -7,9 +7,7 @@ use embassy::executor::Spawner; | |||
| 7 | use embassy_nrf::gpio::{Input, Pull}; | 7 | use embassy_nrf::gpio::{Input, Pull}; |
| 8 | use embassy_nrf::gpiote::{InputChannel, InputChannelPolarity}; | 8 | use embassy_nrf::gpiote::{InputChannel, InputChannelPolarity}; |
| 9 | use embassy_nrf::Peripherals; | 9 | use embassy_nrf::Peripherals; |
| 10 | 10 | use {defmt_rtt as _, panic_probe as _}; | |
| 11 | use defmt_rtt as _; // global logger | ||
| 12 | use panic_probe as _; | ||
| 13 | 11 | ||
| 14 | #[embassy::main] | 12 | #[embassy::main] |
| 15 | async fn main(_spawner: Spawner, p: Peripherals) { | 13 | async fn main(_spawner: Spawner, p: Peripherals) { |
diff --git a/examples/nrf/src/bin/gpiote_port.rs b/examples/nrf/src/bin/gpiote_port.rs index dc6bd301f..30b87b3a7 100644 --- a/examples/nrf/src/bin/gpiote_port.rs +++ b/examples/nrf/src/bin/gpiote_port.rs | |||
| @@ -6,9 +6,7 @@ use defmt::{info, unwrap}; | |||
| 6 | use embassy::executor::Spawner; | 6 | use embassy::executor::Spawner; |
| 7 | use embassy_nrf::gpio::{AnyPin, Input, Pin as _, Pull}; | 7 | use embassy_nrf::gpio::{AnyPin, Input, Pin as _, Pull}; |
| 8 | use embassy_nrf::Peripherals; | 8 | use embassy_nrf::Peripherals; |
| 9 | 9 | use {defmt_rtt as _, panic_probe as _}; | |
| 10 | use defmt_rtt as _; // global logger | ||
| 11 | use panic_probe as _; | ||
| 12 | 10 | ||
| 13 | #[embassy::task(pool_size = 4)] | 11 | #[embassy::task(pool_size = 4)] |
| 14 | async fn button_task(n: usize, mut pin: Input<'static, AnyPin>) { | 12 | async fn button_task(n: usize, mut pin: Input<'static, AnyPin>) { |
diff --git a/examples/nrf/src/bin/multiprio.rs b/examples/nrf/src/bin/multiprio.rs index abda18aa5..1a4598e21 100644 --- a/examples/nrf/src/bin/multiprio.rs +++ b/examples/nrf/src/bin/multiprio.rs | |||
| @@ -64,9 +64,7 @@ use embassy::util::Forever; | |||
| 64 | use embassy_nrf::executor::{Executor, InterruptExecutor}; | 64 | use embassy_nrf::executor::{Executor, InterruptExecutor}; |
| 65 | use embassy_nrf::interrupt; | 65 | use embassy_nrf::interrupt; |
| 66 | use embassy_nrf::interrupt::InterruptExt; | 66 | use embassy_nrf::interrupt::InterruptExt; |
| 67 | 67 | use {defmt_rtt as _, panic_probe as _}; | |
| 68 | use defmt_rtt as _; // global logger | ||
| 69 | use panic_probe as _; | ||
| 70 | 68 | ||
| 71 | #[embassy::task] | 69 | #[embassy::task] |
| 72 | async fn run_high() { | 70 | async fn run_high() { |
diff --git a/examples/nrf/src/bin/mutex.rs b/examples/nrf/src/bin/mutex.rs index db1b72f6d..92e01976c 100644 --- a/examples/nrf/src/bin/mutex.rs +++ b/examples/nrf/src/bin/mutex.rs | |||
| @@ -8,9 +8,7 @@ use embassy::executor::Spawner; | |||
| 8 | use embassy::mutex::Mutex; | 8 | use embassy::mutex::Mutex; |
| 9 | use embassy::time::{Duration, Timer}; | 9 | use embassy::time::{Duration, Timer}; |
| 10 | use embassy_nrf::Peripherals; | 10 | use embassy_nrf::Peripherals; |
| 11 | 11 | use {defmt_rtt as _, panic_probe as _}; | |
| 12 | use defmt_rtt as _; // global logger | ||
| 13 | use panic_probe as _; | ||
| 14 | 12 | ||
| 15 | static MUTEX: Mutex<ThreadModeRawMutex, u32> = Mutex::new(0); | 13 | static MUTEX: Mutex<ThreadModeRawMutex, u32> = Mutex::new(0); |
| 16 | 14 | ||
diff --git a/examples/nrf/src/bin/nvmc.rs b/examples/nrf/src/bin/nvmc.rs index 7a57399f8..b55ef1f6c 100644 --- a/examples/nrf/src/bin/nvmc.rs +++ b/examples/nrf/src/bin/nvmc.rs | |||
| @@ -8,9 +8,7 @@ use embassy::time::{Duration, Timer}; | |||
| 8 | use embassy_nrf::nvmc::Nvmc; | 8 | use embassy_nrf::nvmc::Nvmc; |
| 9 | use embassy_nrf::Peripherals; | 9 | use embassy_nrf::Peripherals; |
| 10 | use embedded_storage::nor_flash::{NorFlash, ReadNorFlash}; | 10 | use embedded_storage::nor_flash::{NorFlash, ReadNorFlash}; |
| 11 | 11 | use {defmt_rtt as _, panic_probe as _}; | |
| 12 | use defmt_rtt as _; // global logger | ||
| 13 | use panic_probe as _; | ||
| 14 | 12 | ||
| 15 | #[embassy::main] | 13 | #[embassy::main] |
| 16 | async fn main(_spawner: Spawner, p: Peripherals) { | 14 | async fn main(_spawner: Spawner, p: Peripherals) { |
diff --git a/examples/nrf/src/bin/ppi.rs b/examples/nrf/src/bin/ppi.rs index 3c9a8148a..004a1bfa4 100644 --- a/examples/nrf/src/bin/ppi.rs +++ b/examples/nrf/src/bin/ppi.rs | |||
| @@ -3,6 +3,7 @@ | |||
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | use core::future::pending; | 5 | use core::future::pending; |
| 6 | |||
| 6 | use defmt::info; | 7 | use defmt::info; |
| 7 | use embassy::executor::Spawner; | 8 | use embassy::executor::Spawner; |
| 8 | use embassy_nrf::gpio::{Input, Level, Output, OutputDrive, Pull}; | 9 | use embassy_nrf::gpio::{Input, Level, Output, OutputDrive, Pull}; |
| @@ -10,9 +11,7 @@ use embassy_nrf::gpiote::{self, InputChannel, InputChannelPolarity}; | |||
| 10 | use embassy_nrf::ppi::Ppi; | 11 | use embassy_nrf::ppi::Ppi; |
| 11 | use embassy_nrf::Peripherals; | 12 | use embassy_nrf::Peripherals; |
| 12 | use gpiote::{OutputChannel, OutputChannelPolarity}; | 13 | use gpiote::{OutputChannel, OutputChannelPolarity}; |
| 13 | 14 | use {defmt_rtt as _, panic_probe as _}; | |
| 14 | use defmt_rtt as _; // global logger | ||
| 15 | use panic_probe as _; | ||
| 16 | 15 | ||
| 17 | #[embassy::main] | 16 | #[embassy::main] |
| 18 | async fn main(_spawner: Spawner, p: Peripherals) { | 17 | async fn main(_spawner: Spawner, p: Peripherals) { |
| @@ -60,12 +59,7 @@ async fn main(_spawner: Spawner, p: Peripherals) { | |||
| 60 | let mut ppi = Ppi::new_one_to_one(p.PPI_CH2, button3.event_in(), led1.task_set()); | 59 | let mut ppi = Ppi::new_one_to_one(p.PPI_CH2, button3.event_in(), led1.task_set()); |
| 61 | ppi.enable(); | 60 | ppi.enable(); |
| 62 | 61 | ||
| 63 | let mut ppi = Ppi::new_one_to_two( | 62 | let mut ppi = Ppi::new_one_to_two(p.PPI_CH3, button4.event_in(), led1.task_out(), led2.task_out()); |
| 64 | p.PPI_CH3, | ||
| 65 | button4.event_in(), | ||
| 66 | led1.task_out(), | ||
| 67 | led2.task_out(), | ||
| 68 | ); | ||
| 69 | ppi.enable(); | 63 | ppi.enable(); |
| 70 | 64 | ||
| 71 | info!("PPI setup!"); | 65 | info!("PPI setup!"); |
diff --git a/examples/nrf/src/bin/pwm.rs b/examples/nrf/src/bin/pwm.rs index 7939e79e4..aec5dd73a 100644 --- a/examples/nrf/src/bin/pwm.rs +++ b/examples/nrf/src/bin/pwm.rs | |||
| @@ -7,81 +7,67 @@ use embassy::executor::Spawner; | |||
| 7 | use embassy::time::{Duration, Timer}; | 7 | use embassy::time::{Duration, Timer}; |
| 8 | use embassy_nrf::pwm::{Prescaler, SimplePwm}; | 8 | use embassy_nrf::pwm::{Prescaler, SimplePwm}; |
| 9 | use embassy_nrf::Peripherals; | 9 | use embassy_nrf::Peripherals; |
| 10 | 10 | use {defmt_rtt as _, panic_probe as _}; | |
| 11 | use defmt_rtt as _; // global logger | ||
| 12 | use panic_probe as _; | ||
| 13 | 11 | ||
| 14 | // for i in range(1024): print(int((math.sin(i/512*math.pi)*0.4+0.5)**2*32767), ', ', end='') | 12 | // for i in range(1024): print(int((math.sin(i/512*math.pi)*0.4+0.5)**2*32767), ', ', end='') |
| 15 | static DUTY: [u16; 1024] = [ | 13 | static DUTY: [u16; 1024] = [ |
| 16 | 8191, 8272, 8353, 8434, 8516, 8598, 8681, 8764, 8847, 8931, 9015, 9099, 9184, 9269, 9354, 9440, | 14 | 8191, 8272, 8353, 8434, 8516, 8598, 8681, 8764, 8847, 8931, 9015, 9099, 9184, 9269, 9354, 9440, 9526, 9613, 9700, |
| 17 | 9526, 9613, 9700, 9787, 9874, 9962, 10050, 10139, 10227, 10316, 10406, 10495, 10585, 10675, | 15 | 9787, 9874, 9962, 10050, 10139, 10227, 10316, 10406, 10495, 10585, 10675, 10766, 10857, 10948, 11039, 11131, 11223, |
| 18 | 10766, 10857, 10948, 11039, 11131, 11223, 11315, 11407, 11500, 11592, 11685, 11779, 11872, | 16 | 11315, 11407, 11500, 11592, 11685, 11779, 11872, 11966, 12060, 12154, 12248, 12343, 12438, 12533, 12628, 12723, |
| 19 | 11966, 12060, 12154, 12248, 12343, 12438, 12533, 12628, 12723, 12818, 12914, 13010, 13106, | 17 | 12818, 12914, 13010, 13106, 13202, 13298, 13394, 13491, 13587, 13684, 13781, 13878, 13975, 14072, 14169, 14266, |
| 20 | 13202, 13298, 13394, 13491, 13587, 13684, 13781, 13878, 13975, 14072, 14169, 14266, 14364, | 18 | 14364, 14461, 14558, 14656, 14754, 14851, 14949, 15046, 15144, 15242, 15339, 15437, 15535, 15632, 15730, 15828, |
| 21 | 14461, 14558, 14656, 14754, 14851, 14949, 15046, 15144, 15242, 15339, 15437, 15535, 15632, | 19 | 15925, 16023, 16120, 16218, 16315, 16412, 16510, 16607, 16704, 16801, 16898, 16995, 17091, 17188, 17284, 17380, |
| 22 | 15730, 15828, 15925, 16023, 16120, 16218, 16315, 16412, 16510, 16607, 16704, 16801, 16898, | 20 | 17477, 17572, 17668, 17764, 17859, 17955, 18050, 18145, 18239, 18334, 18428, 18522, 18616, 18710, 18803, 18896, |
| 23 | 16995, 17091, 17188, 17284, 17380, 17477, 17572, 17668, 17764, 17859, 17955, 18050, 18145, | 21 | 18989, 19082, 19174, 19266, 19358, 19449, 19540, 19631, 19722, 19812, 19902, 19991, 20081, 20169, 20258, 20346, |
| 24 | 18239, 18334, 18428, 18522, 18616, 18710, 18803, 18896, 18989, 19082, 19174, 19266, 19358, | 22 | 20434, 20521, 20608, 20695, 20781, 20867, 20952, 21037, 21122, 21206, 21290, 21373, 21456, 21538, 21620, 21701, |
| 25 | 19449, 19540, 19631, 19722, 19812, 19902, 19991, 20081, 20169, 20258, 20346, 20434, 20521, | 23 | 21782, 21863, 21943, 22022, 22101, 22179, 22257, 22335, 22412, 22488, 22564, 22639, 22714, 22788, 22861, 22934, |
| 26 | 20608, 20695, 20781, 20867, 20952, 21037, 21122, 21206, 21290, 21373, 21456, 21538, 21620, | 24 | 23007, 23079, 23150, 23220, 23290, 23360, 23429, 23497, 23564, 23631, 23698, 23763, 23828, 23892, 23956, 24019, |
| 27 | 21701, 21782, 21863, 21943, 22022, 22101, 22179, 22257, 22335, 22412, 22488, 22564, 22639, | 25 | 24081, 24143, 24204, 24264, 24324, 24383, 24441, 24499, 24555, 24611, 24667, 24721, 24775, 24828, 24881, 24933, |
| 28 | 22714, 22788, 22861, 22934, 23007, 23079, 23150, 23220, 23290, 23360, 23429, 23497, 23564, | 26 | 24983, 25034, 25083, 25132, 25180, 25227, 25273, 25319, 25363, 25407, 25451, 25493, 25535, 25575, 25615, 25655, |
| 29 | 23631, 23698, 23763, 23828, 23892, 23956, 24019, 24081, 24143, 24204, 24264, 24324, 24383, | 27 | 25693, 25731, 25767, 25803, 25838, 25873, 25906, 25939, 25971, 26002, 26032, 26061, 26089, 26117, 26144, 26170, |
| 30 | 24441, 24499, 24555, 24611, 24667, 24721, 24775, 24828, 24881, 24933, 24983, 25034, 25083, | 28 | 26195, 26219, 26242, 26264, 26286, 26307, 26327, 26346, 26364, 26381, 26397, 26413, 26427, 26441, 26454, 26466, |
| 31 | 25132, 25180, 25227, 25273, 25319, 25363, 25407, 25451, 25493, 25535, 25575, 25615, 25655, | 29 | 26477, 26487, 26496, 26505, 26512, 26519, 26525, 26530, 26534, 26537, 26539, 26540, 26541, 26540, 26539, 26537, |
| 32 | 25693, 25731, 25767, 25803, 25838, 25873, 25906, 25939, 25971, 26002, 26032, 26061, 26089, | 30 | 26534, 26530, 26525, 26519, 26512, 26505, 26496, 26487, 26477, 26466, 26454, 26441, 26427, 26413, 26397, 26381, |
| 33 | 26117, 26144, 26170, 26195, 26219, 26242, 26264, 26286, 26307, 26327, 26346, 26364, 26381, | 31 | 26364, 26346, 26327, 26307, 26286, 26264, 26242, 26219, 26195, 26170, 26144, 26117, 26089, 26061, 26032, 26002, |
| 34 | 26397, 26413, 26427, 26441, 26454, 26466, 26477, 26487, 26496, 26505, 26512, 26519, 26525, | 32 | 25971, 25939, 25906, 25873, 25838, 25803, 25767, 25731, 25693, 25655, 25615, 25575, 25535, 25493, 25451, 25407, |
| 35 | 26530, 26534, 26537, 26539, 26540, 26541, 26540, 26539, 26537, 26534, 26530, 26525, 26519, | 33 | 25363, 25319, 25273, 25227, 25180, 25132, 25083, 25034, 24983, 24933, 24881, 24828, 24775, 24721, 24667, 24611, |
| 36 | 26512, 26505, 26496, 26487, 26477, 26466, 26454, 26441, 26427, 26413, 26397, 26381, 26364, | 34 | 24555, 24499, 24441, 24383, 24324, 24264, 24204, 24143, 24081, 24019, 23956, 23892, 23828, 23763, 23698, 23631, |
| 37 | 26346, 26327, 26307, 26286, 26264, 26242, 26219, 26195, 26170, 26144, 26117, 26089, 26061, | 35 | 23564, 23497, 23429, 23360, 23290, 23220, 23150, 23079, 23007, 22934, 22861, 22788, 22714, 22639, 22564, 22488, |
| 38 | 26032, 26002, 25971, 25939, 25906, 25873, 25838, 25803, 25767, 25731, 25693, 25655, 25615, | 36 | 22412, 22335, 22257, 22179, 22101, 22022, 21943, 21863, 21782, 21701, 21620, 21538, 21456, 21373, 21290, 21206, |
| 39 | 25575, 25535, 25493, 25451, 25407, 25363, 25319, 25273, 25227, 25180, 25132, 25083, 25034, | 37 | 21122, 21037, 20952, 20867, 20781, 20695, 20608, 20521, 20434, 20346, 20258, 20169, 20081, 19991, 19902, 19812, |
| 40 | 24983, 24933, 24881, 24828, 24775, 24721, 24667, 24611, 24555, 24499, 24441, 24383, 24324, | 38 | 19722, 19631, 19540, 19449, 19358, 19266, 19174, 19082, 18989, 18896, 18803, 18710, 18616, 18522, 18428, 18334, |
| 41 | 24264, 24204, 24143, 24081, 24019, 23956, 23892, 23828, 23763, 23698, 23631, 23564, 23497, | 39 | 18239, 18145, 18050, 17955, 17859, 17764, 17668, 17572, 17477, 17380, 17284, 17188, 17091, 16995, 16898, 16801, |
| 42 | 23429, 23360, 23290, 23220, 23150, 23079, 23007, 22934, 22861, 22788, 22714, 22639, 22564, | 40 | 16704, 16607, 16510, 16412, 16315, 16218, 16120, 16023, 15925, 15828, 15730, 15632, 15535, 15437, 15339, 15242, |
| 43 | 22488, 22412, 22335, 22257, 22179, 22101, 22022, 21943, 21863, 21782, 21701, 21620, 21538, | 41 | 15144, 15046, 14949, 14851, 14754, 14656, 14558, 14461, 14364, 14266, 14169, 14072, 13975, 13878, 13781, 13684, |
| 44 | 21456, 21373, 21290, 21206, 21122, 21037, 20952, 20867, 20781, 20695, 20608, 20521, 20434, | 42 | 13587, 13491, 13394, 13298, 13202, 13106, 13010, 12914, 12818, 12723, 12628, 12533, 12438, 12343, 12248, 12154, |
| 45 | 20346, 20258, 20169, 20081, 19991, 19902, 19812, 19722, 19631, 19540, 19449, 19358, 19266, | 43 | 12060, 11966, 11872, 11779, 11685, 11592, 11500, 11407, 11315, 11223, 11131, 11039, 10948, 10857, 10766, 10675, |
| 46 | 19174, 19082, 18989, 18896, 18803, 18710, 18616, 18522, 18428, 18334, 18239, 18145, 18050, | 44 | 10585, 10495, 10406, 10316, 10227, 10139, 10050, 9962, 9874, 9787, 9700, 9613, 9526, 9440, 9354, 9269, 9184, 9099, |
| 47 | 17955, 17859, 17764, 17668, 17572, 17477, 17380, 17284, 17188, 17091, 16995, 16898, 16801, | 45 | 9015, 8931, 8847, 8764, 8681, 8598, 8516, 8434, 8353, 8272, 8191, 8111, 8031, 7952, 7873, 7794, 7716, 7638, 7561, |
| 48 | 16704, 16607, 16510, 16412, 16315, 16218, 16120, 16023, 15925, 15828, 15730, 15632, 15535, | 46 | 7484, 7407, 7331, 7255, 7180, 7105, 7031, 6957, 6883, 6810, 6738, 6665, 6594, 6522, 6451, 6381, 6311, 6241, 6172, |
| 49 | 15437, 15339, 15242, 15144, 15046, 14949, 14851, 14754, 14656, 14558, 14461, 14364, 14266, | 47 | 6104, 6036, 5968, 5901, 5834, 5767, 5702, 5636, 5571, 5507, 5443, 5379, 5316, 5253, 5191, 5130, 5068, 5008, 4947, |
| 50 | 14169, 14072, 13975, 13878, 13781, 13684, 13587, 13491, 13394, 13298, 13202, 13106, 13010, | 48 | 4888, 4828, 4769, 4711, 4653, 4596, 4539, 4482, 4426, 4371, 4316, 4261, 4207, 4153, 4100, 4047, 3995, 3943, 3892, |
| 51 | 12914, 12818, 12723, 12628, 12533, 12438, 12343, 12248, 12154, 12060, 11966, 11872, 11779, | 49 | 3841, 3791, 3741, 3691, 3642, 3594, 3546, 3498, 3451, 3404, 3358, 3312, 3267, 3222, 3178, 3134, 3090, 3047, 3005, |
| 52 | 11685, 11592, 11500, 11407, 11315, 11223, 11131, 11039, 10948, 10857, 10766, 10675, 10585, | 50 | 2962, 2921, 2879, 2839, 2798, 2758, 2719, 2680, 2641, 2603, 2565, 2528, 2491, 2454, 2418, 2382, 2347, 2312, 2278, |
| 53 | 10495, 10406, 10316, 10227, 10139, 10050, 9962, 9874, 9787, 9700, 9613, 9526, 9440, 9354, 9269, | 51 | 2244, 2210, 2177, 2144, 2112, 2080, 2048, 2017, 1986, 1956, 1926, 1896, 1867, 1838, 1810, 1781, 1754, 1726, 1699, |
| 54 | 9184, 9099, 9015, 8931, 8847, 8764, 8681, 8598, 8516, 8434, 8353, 8272, 8191, 8111, 8031, 7952, | 52 | 1673, 1646, 1620, 1595, 1570, 1545, 1520, 1496, 1472, 1449, 1426, 1403, 1380, 1358, 1336, 1315, 1294, 1273, 1252, |
| 55 | 7873, 7794, 7716, 7638, 7561, 7484, 7407, 7331, 7255, 7180, 7105, 7031, 6957, 6883, 6810, 6738, | 53 | 1232, 1212, 1192, 1173, 1154, 1135, 1117, 1099, 1081, 1063, 1046, 1029, 1012, 996, 980, 964, 948, 933, 918, 903, |
| 56 | 6665, 6594, 6522, 6451, 6381, 6311, 6241, 6172, 6104, 6036, 5968, 5901, 5834, 5767, 5702, 5636, | 54 | 888, 874, 860, 846, 833, 819, 806, 793, 781, 768, 756, 744, 733, 721, 710, 699, 688, 677, 667, 657, 647, 637, 627, |
| 57 | 5571, 5507, 5443, 5379, 5316, 5253, 5191, 5130, 5068, 5008, 4947, 4888, 4828, 4769, 4711, 4653, | 55 | 618, 609, 599, 591, 582, 574, 565, 557, 549, 541, 534, 526, 519, 512, 505, 498, 492, 485, 479, 473, 467, 461, 455, |
| 58 | 4596, 4539, 4482, 4426, 4371, 4316, 4261, 4207, 4153, 4100, 4047, 3995, 3943, 3892, 3841, 3791, | 56 | 450, 444, 439, 434, 429, 424, 419, 415, 410, 406, 402, 398, 394, 390, 386, 383, 379, 376, 373, 370, 367, 364, 361, |
| 59 | 3741, 3691, 3642, 3594, 3546, 3498, 3451, 3404, 3358, 3312, 3267, 3222, 3178, 3134, 3090, 3047, | 57 | 359, 356, 354, 351, 349, 347, 345, 343, 342, 340, 338, 337, 336, 334, 333, 332, 331, 330, 330, 329, 328, 328, 328, |
| 60 | 3005, 2962, 2921, 2879, 2839, 2798, 2758, 2719, 2680, 2641, 2603, 2565, 2528, 2491, 2454, 2418, | 58 | 327, 327, 327, 327, 327, 328, 328, 328, 329, 330, 330, 331, 332, 333, 334, 336, 337, 338, 340, 342, 343, 345, 347, |
| 61 | 2382, 2347, 2312, 2278, 2244, 2210, 2177, 2144, 2112, 2080, 2048, 2017, 1986, 1956, 1926, 1896, | 59 | 349, 351, 354, 356, 359, 361, 364, 367, 370, 373, 376, 379, 383, 386, 390, 394, 398, 402, 406, 410, 415, 419, 424, |
| 62 | 1867, 1838, 1810, 1781, 1754, 1726, 1699, 1673, 1646, 1620, 1595, 1570, 1545, 1520, 1496, 1472, | 60 | 429, 434, 439, 444, 450, 455, 461, 467, 473, 479, 485, 492, 498, 505, 512, 519, 526, 534, 541, 549, 557, 565, 574, |
| 63 | 1449, 1426, 1403, 1380, 1358, 1336, 1315, 1294, 1273, 1252, 1232, 1212, 1192, 1173, 1154, 1135, | 61 | 582, 591, 599, 609, 618, 627, 637, 647, 657, 667, 677, 688, 699, 710, 721, 733, 744, 756, 768, 781, 793, 806, 819, |
| 64 | 1117, 1099, 1081, 1063, 1046, 1029, 1012, 996, 980, 964, 948, 933, 918, 903, 888, 874, 860, | 62 | 833, 846, 860, 874, 888, 903, 918, 933, 948, 964, 980, 996, 1012, 1029, 1046, 1063, 1081, 1099, 1117, 1135, 1154, |
| 65 | 846, 833, 819, 806, 793, 781, 768, 756, 744, 733, 721, 710, 699, 688, 677, 667, 657, 647, 637, | 63 | 1173, 1192, 1212, 1232, 1252, 1273, 1294, 1315, 1336, 1358, 1380, 1403, 1426, 1449, 1472, 1496, 1520, 1545, 1570, |
| 66 | 627, 618, 609, 599, 591, 582, 574, 565, 557, 549, 541, 534, 526, 519, 512, 505, 498, 492, 485, | 64 | 1595, 1620, 1646, 1673, 1699, 1726, 1754, 1781, 1810, 1838, 1867, 1896, 1926, 1956, 1986, 2017, 2048, 2080, 2112, |
| 67 | 479, 473, 467, 461, 455, 450, 444, 439, 434, 429, 424, 419, 415, 410, 406, 402, 398, 394, 390, | 65 | 2144, 2177, 2210, 2244, 2278, 2312, 2347, 2382, 2418, 2454, 2491, 2528, 2565, 2603, 2641, 2680, 2719, 2758, 2798, |
| 68 | 386, 383, 379, 376, 373, 370, 367, 364, 361, 359, 356, 354, 351, 349, 347, 345, 343, 342, 340, | 66 | 2839, 2879, 2921, 2962, 3005, 3047, 3090, 3134, 3178, 3222, 3267, 3312, 3358, 3404, 3451, 3498, 3546, 3594, 3642, |
| 69 | 338, 337, 336, 334, 333, 332, 331, 330, 330, 329, 328, 328, 328, 327, 327, 327, 327, 327, 328, | 67 | 3691, 3741, 3791, 3841, 3892, 3943, 3995, 4047, 4100, 4153, 4207, 4261, 4316, 4371, 4426, 4482, 4539, 4596, 4653, |
| 70 | 328, 328, 329, 330, 330, 331, 332, 333, 334, 336, 337, 338, 340, 342, 343, 345, 347, 349, 351, | 68 | 4711, 4769, 4828, 4888, 4947, 5008, 5068, 5130, 5191, 5253, 5316, 5379, 5443, 5507, 5571, 5636, 5702, 5767, 5834, |
| 71 | 354, 356, 359, 361, 364, 367, 370, 373, 376, 379, 383, 386, 390, 394, 398, 402, 406, 410, 415, | 69 | 5901, 5968, 6036, 6104, 6172, 6241, 6311, 6381, 6451, 6522, 6594, 6665, 6738, 6810, 6883, 6957, 7031, 7105, 7180, |
| 72 | 419, 424, 429, 434, 439, 444, 450, 455, 461, 467, 473, 479, 485, 492, 498, 505, 512, 519, 526, | 70 | 7255, 7331, 7407, 7484, 7561, 7638, 7716, 7794, 7873, 7952, 8031, 8111, |
| 73 | 534, 541, 549, 557, 565, 574, 582, 591, 599, 609, 618, 627, 637, 647, 657, 667, 677, 688, 699, | ||
| 74 | 710, 721, 733, 744, 756, 768, 781, 793, 806, 819, 833, 846, 860, 874, 888, 903, 918, 933, 948, | ||
| 75 | 964, 980, 996, 1012, 1029, 1046, 1063, 1081, 1099, 1117, 1135, 1154, 1173, 1192, 1212, 1232, | ||
| 76 | 1252, 1273, 1294, 1315, 1336, 1358, 1380, 1403, 1426, 1449, 1472, 1496, 1520, 1545, 1570, 1595, | ||
| 77 | 1620, 1646, 1673, 1699, 1726, 1754, 1781, 1810, 1838, 1867, 1896, 1926, 1956, 1986, 2017, 2048, | ||
| 78 | 2080, 2112, 2144, 2177, 2210, 2244, 2278, 2312, 2347, 2382, 2418, 2454, 2491, 2528, 2565, 2603, | ||
| 79 | 2641, 2680, 2719, 2758, 2798, 2839, 2879, 2921, 2962, 3005, 3047, 3090, 3134, 3178, 3222, 3267, | ||
| 80 | 3312, 3358, 3404, 3451, 3498, 3546, 3594, 3642, 3691, 3741, 3791, 3841, 3892, 3943, 3995, 4047, | ||
| 81 | 4100, 4153, 4207, 4261, 4316, 4371, 4426, 4482, 4539, 4596, 4653, 4711, 4769, 4828, 4888, 4947, | ||
| 82 | 5008, 5068, 5130, 5191, 5253, 5316, 5379, 5443, 5507, 5571, 5636, 5702, 5767, 5834, 5901, 5968, | ||
| 83 | 6036, 6104, 6172, 6241, 6311, 6381, 6451, 6522, 6594, 6665, 6738, 6810, 6883, 6957, 7031, 7105, | ||
| 84 | 7180, 7255, 7331, 7407, 7484, 7561, 7638, 7716, 7794, 7873, 7952, 8031, 8111, | ||
| 85 | ]; | 71 | ]; |
| 86 | 72 | ||
| 87 | #[embassy::main] | 73 | #[embassy::main] |
diff --git a/examples/nrf/src/bin/pwm_double_sequence.rs b/examples/nrf/src/bin/pwm_double_sequence.rs index 6fc429214..facafa775 100644 --- a/examples/nrf/src/bin/pwm_double_sequence.rs +++ b/examples/nrf/src/bin/pwm_double_sequence.rs | |||
| @@ -6,13 +6,10 @@ use defmt::*; | |||
| 6 | use embassy::executor::Spawner; | 6 | use embassy::executor::Spawner; |
| 7 | use embassy::time::{Duration, Timer}; | 7 | use embassy::time::{Duration, Timer}; |
| 8 | use embassy_nrf::pwm::{ | 8 | use embassy_nrf::pwm::{ |
| 9 | Config, Prescaler, Sequence, SequenceConfig, SequenceMode, SequencePwm, Sequencer, | 9 | Config, Prescaler, Sequence, SequenceConfig, SequenceMode, SequencePwm, Sequencer, StartSequence, |
| 10 | StartSequence, | ||
| 11 | }; | 10 | }; |
| 12 | use embassy_nrf::Peripherals; | 11 | use embassy_nrf::Peripherals; |
| 13 | 12 | use {defmt_rtt as _, panic_probe as _}; | |
| 14 | use defmt_rtt as _; // global logger | ||
| 15 | use panic_probe as _; | ||
| 16 | 13 | ||
| 17 | #[embassy::main] | 14 | #[embassy::main] |
| 18 | async fn main(_spawner: Spawner, p: Peripherals) { | 15 | async fn main(_spawner: Spawner, p: Peripherals) { |
diff --git a/examples/nrf/src/bin/pwm_sequence.rs b/examples/nrf/src/bin/pwm_sequence.rs index 3b2919ba5..b7cb385c7 100644 --- a/examples/nrf/src/bin/pwm_sequence.rs +++ b/examples/nrf/src/bin/pwm_sequence.rs | |||
| @@ -5,13 +5,9 @@ | |||
| 5 | use defmt::*; | 5 | use defmt::*; |
| 6 | use embassy::executor::Spawner; | 6 | use embassy::executor::Spawner; |
| 7 | use embassy::time::{Duration, Timer}; | 7 | use embassy::time::{Duration, Timer}; |
| 8 | use embassy_nrf::pwm::{ | 8 | use embassy_nrf::pwm::{Config, Prescaler, SequenceConfig, SequencePwm, SingleSequenceMode, SingleSequencer}; |
| 9 | Config, Prescaler, SequenceConfig, SequencePwm, SingleSequenceMode, SingleSequencer, | ||
| 10 | }; | ||
| 11 | use embassy_nrf::Peripherals; | 9 | use embassy_nrf::Peripherals; |
| 12 | 10 | use {defmt_rtt as _, panic_probe as _}; | |
| 13 | use defmt_rtt as _; // global logger | ||
| 14 | use panic_probe as _; | ||
| 15 | 11 | ||
| 16 | #[embassy::main] | 12 | #[embassy::main] |
| 17 | async fn main(_spawner: Spawner, p: Peripherals) { | 13 | async fn main(_spawner: Spawner, p: Peripherals) { |
diff --git a/examples/nrf/src/bin/pwm_sequence_ppi.rs b/examples/nrf/src/bin/pwm_sequence_ppi.rs index 1f3662c60..7d020e48d 100644 --- a/examples/nrf/src/bin/pwm_sequence_ppi.rs +++ b/examples/nrf/src/bin/pwm_sequence_ppi.rs | |||
| @@ -4,18 +4,15 @@ | |||
| 4 | #![feature(array_from_fn)] | 4 | #![feature(array_from_fn)] |
| 5 | 5 | ||
| 6 | use core::future::pending; | 6 | use core::future::pending; |
| 7 | |||
| 7 | use defmt::*; | 8 | use defmt::*; |
| 8 | use embassy::executor::Spawner; | 9 | use embassy::executor::Spawner; |
| 9 | use embassy_nrf::gpio::{Input, Pull}; | 10 | use embassy_nrf::gpio::{Input, Pull}; |
| 10 | use embassy_nrf::gpiote::{InputChannel, InputChannelPolarity}; | 11 | use embassy_nrf::gpiote::{InputChannel, InputChannelPolarity}; |
| 11 | use embassy_nrf::ppi::Ppi; | 12 | use embassy_nrf::ppi::Ppi; |
| 12 | use embassy_nrf::pwm::{ | 13 | use embassy_nrf::pwm::{Config, Prescaler, SequenceConfig, SequencePwm, SingleSequenceMode, SingleSequencer}; |
| 13 | Config, Prescaler, SequenceConfig, SequencePwm, SingleSequenceMode, SingleSequencer, | ||
| 14 | }; | ||
| 15 | use embassy_nrf::Peripherals; | 14 | use embassy_nrf::Peripherals; |
| 16 | 15 | use {defmt_rtt as _, panic_probe as _}; | |
| 17 | use defmt_rtt as _; // global logger | ||
| 18 | use panic_probe as _; | ||
| 19 | 16 | ||
| 20 | #[embassy::main] | 17 | #[embassy::main] |
| 21 | async fn main(_spawner: Spawner, p: Peripherals) { | 18 | async fn main(_spawner: Spawner, p: Peripherals) { |
diff --git a/examples/nrf/src/bin/pwm_sequence_ws2812b.rs b/examples/nrf/src/bin/pwm_sequence_ws2812b.rs index 8bfe1d50f..0dee8c949 100644 --- a/examples/nrf/src/bin/pwm_sequence_ws2812b.rs +++ b/examples/nrf/src/bin/pwm_sequence_ws2812b.rs | |||
| @@ -6,13 +6,10 @@ use defmt::*; | |||
| 6 | use embassy::executor::Spawner; | 6 | use embassy::executor::Spawner; |
| 7 | use embassy::time::{Duration, Timer}; | 7 | use embassy::time::{Duration, Timer}; |
| 8 | use embassy_nrf::pwm::{ | 8 | use embassy_nrf::pwm::{ |
| 9 | Config, Prescaler, SequenceConfig, SequenceLoad, SequencePwm, SingleSequenceMode, | 9 | Config, Prescaler, SequenceConfig, SequenceLoad, SequencePwm, SingleSequenceMode, SingleSequencer, |
| 10 | SingleSequencer, | ||
| 11 | }; | 10 | }; |
| 12 | use embassy_nrf::Peripherals; | 11 | use embassy_nrf::Peripherals; |
| 13 | 12 | use {defmt_rtt as _, panic_probe as _}; | |
| 14 | use defmt_rtt as _; // global logger | ||
| 15 | use panic_probe as _; | ||
| 16 | 13 | ||
| 17 | // WS2812B LED light demonstration. Drives just one light. | 14 | // WS2812B LED light demonstration. Drives just one light. |
| 18 | // The following reference on WS2812B may be of use: | 15 | // The following reference on WS2812B may be of use: |
diff --git a/examples/nrf/src/bin/pwm_servo.rs b/examples/nrf/src/bin/pwm_servo.rs index 40863bf3c..71a90a948 100644 --- a/examples/nrf/src/bin/pwm_servo.rs +++ b/examples/nrf/src/bin/pwm_servo.rs | |||
| @@ -7,9 +7,7 @@ use embassy::executor::Spawner; | |||
| 7 | use embassy::time::{Duration, Timer}; | 7 | use embassy::time::{Duration, Timer}; |
| 8 | use embassy_nrf::pwm::{Prescaler, SimplePwm}; | 8 | use embassy_nrf::pwm::{Prescaler, SimplePwm}; |
| 9 | use embassy_nrf::Peripherals; | 9 | use embassy_nrf::Peripherals; |
| 10 | 10 | use {defmt_rtt as _, panic_probe as _}; | |
| 11 | use defmt_rtt as _; // global logger | ||
| 12 | use panic_probe as _; | ||
| 13 | 11 | ||
| 14 | #[embassy::main] | 12 | #[embassy::main] |
| 15 | async fn main(_spawner: Spawner, p: Peripherals) { | 13 | async fn main(_spawner: Spawner, p: Peripherals) { |
diff --git a/examples/nrf/src/bin/qdec.rs b/examples/nrf/src/bin/qdec.rs index bf5b11468..9529c7bb6 100644 --- a/examples/nrf/src/bin/qdec.rs +++ b/examples/nrf/src/bin/qdec.rs | |||
| @@ -4,14 +4,9 @@ | |||
| 4 | 4 | ||
| 5 | use defmt::info; | 5 | use defmt::info; |
| 6 | use embassy::executor::Spawner; | 6 | use embassy::executor::Spawner; |
| 7 | use embassy_nrf::{ | 7 | use embassy_nrf::qdec::{self, Qdec}; |
| 8 | interrupt, | 8 | use embassy_nrf::{interrupt, Peripherals}; |
| 9 | qdec::{self, Qdec}, | 9 | use {defmt_rtt as _, panic_probe as _}; |
| 10 | Peripherals, | ||
| 11 | }; | ||
| 12 | |||
| 13 | use defmt_rtt as _; // global logger | ||
| 14 | use panic_probe as _; | ||
| 15 | 10 | ||
| 16 | #[embassy::main] | 11 | #[embassy::main] |
| 17 | async fn main(_spawner: Spawner, p: Peripherals) { | 12 | async fn main(_spawner: Spawner, p: Peripherals) { |
diff --git a/examples/nrf/src/bin/qspi.rs b/examples/nrf/src/bin/qspi.rs index 8673b7961..96c90f9c8 100644 --- a/examples/nrf/src/bin/qspi.rs +++ b/examples/nrf/src/bin/qspi.rs | |||
| @@ -4,11 +4,8 @@ | |||
| 4 | 4 | ||
| 5 | use defmt::{assert_eq, info, unwrap}; | 5 | use defmt::{assert_eq, info, unwrap}; |
| 6 | use embassy::executor::Spawner; | 6 | use embassy::executor::Spawner; |
| 7 | use embassy_nrf::Peripherals; | 7 | use embassy_nrf::{interrupt, qspi, Peripherals}; |
| 8 | use embassy_nrf::{interrupt, qspi}; | 8 | use {defmt_rtt as _, panic_probe as _}; |
| 9 | |||
| 10 | use defmt_rtt as _; // global logger | ||
| 11 | use panic_probe as _; | ||
| 12 | 9 | ||
| 13 | const PAGE_SIZE: usize = 4096; | 10 | const PAGE_SIZE: usize = 4096; |
| 14 | 11 | ||
diff --git a/examples/nrf/src/bin/qspi_lowpower.rs b/examples/nrf/src/bin/qspi_lowpower.rs index 255ce5d5e..ce2e40b23 100644 --- a/examples/nrf/src/bin/qspi_lowpower.rs +++ b/examples/nrf/src/bin/qspi_lowpower.rs | |||
| @@ -3,14 +3,12 @@ | |||
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | use core::mem; | 5 | use core::mem; |
| 6 | |||
| 6 | use defmt::{info, unwrap}; | 7 | use defmt::{info, unwrap}; |
| 7 | use embassy::executor::Spawner; | 8 | use embassy::executor::Spawner; |
| 8 | use embassy::time::{Duration, Timer}; | 9 | use embassy::time::{Duration, Timer}; |
| 9 | use embassy_nrf::Peripherals; | 10 | use embassy_nrf::{interrupt, qspi, Peripherals}; |
| 10 | use embassy_nrf::{interrupt, qspi}; | 11 | use {defmt_rtt as _, panic_probe as _}; |
| 11 | |||
| 12 | use defmt_rtt as _; // global logger | ||
| 13 | use panic_probe as _; | ||
| 14 | 12 | ||
| 15 | // Workaround for alignment requirements. | 13 | // Workaround for alignment requirements. |
| 16 | // Nicer API will probably come in the future. | 14 | // Nicer API will probably come in the future. |
diff --git a/examples/nrf/src/bin/raw_spawn.rs b/examples/nrf/src/bin/raw_spawn.rs index 1d9d3ed51..d564b6b26 100644 --- a/examples/nrf/src/bin/raw_spawn.rs +++ b/examples/nrf/src/bin/raw_spawn.rs | |||
| @@ -2,15 +2,14 @@ | |||
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | 3 | ||
| 4 | use core::mem; | 4 | use core::mem; |
| 5 | |||
| 5 | use cortex_m_rt::entry; | 6 | use cortex_m_rt::entry; |
| 6 | use defmt::{info, unwrap}; | 7 | use defmt::{info, unwrap}; |
| 7 | use embassy::executor::raw::TaskStorage; | 8 | use embassy::executor::raw::TaskStorage; |
| 8 | use embassy::executor::Executor; | 9 | use embassy::executor::Executor; |
| 9 | use embassy::time::{Duration, Timer}; | 10 | use embassy::time::{Duration, Timer}; |
| 10 | use embassy::util::Forever; | 11 | use embassy::util::Forever; |
| 11 | 12 | use {defmt_rtt as _, panic_probe as _}; | |
| 12 | use defmt_rtt as _; // global logger | ||
| 13 | use panic_probe as _; | ||
| 14 | 13 | ||
| 15 | async fn run1() { | 14 | async fn run1() { |
| 16 | loop { | 15 | loop { |
diff --git a/examples/nrf/src/bin/rng.rs b/examples/nrf/src/bin/rng.rs index 4b4b3a19b..08d3abe10 100644 --- a/examples/nrf/src/bin/rng.rs +++ b/examples/nrf/src/bin/rng.rs | |||
| @@ -3,13 +3,10 @@ | |||
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | use embassy::executor::Spawner; | 5 | use embassy::executor::Spawner; |
| 6 | use embassy_nrf::interrupt; | ||
| 7 | use embassy_nrf::rng::Rng; | 6 | use embassy_nrf::rng::Rng; |
| 8 | use embassy_nrf::Peripherals; | 7 | use embassy_nrf::{interrupt, Peripherals}; |
| 9 | use rand::Rng as _; | 8 | use rand::Rng as _; |
| 10 | 9 | use {defmt_rtt as _, panic_probe as _}; | |
| 11 | use defmt_rtt as _; // global logger | ||
| 12 | use panic_probe as _; | ||
| 13 | 10 | ||
| 14 | #[embassy::main] | 11 | #[embassy::main] |
| 15 | async fn main(_spawner: Spawner, p: Peripherals) { | 12 | async fn main(_spawner: Spawner, p: Peripherals) { |
| @@ -27,12 +24,6 @@ async fn main(_spawner: Spawner, p: Peripherals) { | |||
| 27 | rng.fill_bytes(&mut bytes).await; | 24 | rng.fill_bytes(&mut bytes).await; |
| 28 | let zero_count: u32 = bytes.iter().fold(0, |acc, val| acc + val.count_zeros()); | 25 | let zero_count: u32 = bytes.iter().fold(0, |acc, val| acc + val.count_zeros()); |
| 29 | let one_count: u32 = bytes.iter().fold(0, |acc, val| acc + val.count_ones()); | 26 | let one_count: u32 = bytes.iter().fold(0, |acc, val| acc + val.count_ones()); |
| 30 | defmt::info!( | 27 | defmt::info!("Chance of zero: {}%", zero_count * 100 / (bytes.len() as u32 * 8)); |
| 31 | "Chance of zero: {}%", | 28 | defmt::info!("Chance of one: {}%", one_count * 100 / (bytes.len() as u32 * 8)); |
| 32 | zero_count * 100 / (bytes.len() as u32 * 8) | ||
| 33 | ); | ||
| 34 | defmt::info!( | ||
| 35 | "Chance of one: {}%", | ||
| 36 | one_count * 100 / (bytes.len() as u32 * 8) | ||
| 37 | ); | ||
| 38 | } | 29 | } |
diff --git a/examples/nrf/src/bin/saadc.rs b/examples/nrf/src/bin/saadc.rs index 5835be31f..cb9289784 100644 --- a/examples/nrf/src/bin/saadc.rs +++ b/examples/nrf/src/bin/saadc.rs | |||
| @@ -7,9 +7,7 @@ use embassy::executor::Spawner; | |||
| 7 | use embassy::time::{Duration, Timer}; | 7 | use embassy::time::{Duration, Timer}; |
| 8 | use embassy_nrf::saadc::{ChannelConfig, Config, Saadc}; | 8 | use embassy_nrf::saadc::{ChannelConfig, Config, Saadc}; |
| 9 | use embassy_nrf::{interrupt, Peripherals}; | 9 | use embassy_nrf::{interrupt, Peripherals}; |
| 10 | 10 | use {defmt_rtt as _, panic_probe as _}; | |
| 11 | use defmt_rtt as _; // global logger | ||
| 12 | use panic_probe as _; | ||
| 13 | 11 | ||
| 14 | #[embassy::main] | 12 | #[embassy::main] |
| 15 | async fn main(_spawner: Spawner, mut p: Peripherals) { | 13 | async fn main(_spawner: Spawner, mut p: Peripherals) { |
diff --git a/examples/nrf/src/bin/saadc_continuous.rs b/examples/nrf/src/bin/saadc_continuous.rs index 5e357f79b..234294eae 100644 --- a/examples/nrf/src/bin/saadc_continuous.rs +++ b/examples/nrf/src/bin/saadc_continuous.rs | |||
| @@ -8,9 +8,7 @@ use embassy::time::Duration; | |||
| 8 | use embassy_nrf::saadc::{ChannelConfig, Config, Saadc, SamplerState}; | 8 | use embassy_nrf::saadc::{ChannelConfig, Config, Saadc, SamplerState}; |
| 9 | use embassy_nrf::timer::Frequency; | 9 | use embassy_nrf::timer::Frequency; |
| 10 | use embassy_nrf::{interrupt, Peripherals}; | 10 | use embassy_nrf::{interrupt, Peripherals}; |
| 11 | 11 | use {defmt_rtt as _, panic_probe as _}; | |
| 12 | use defmt_rtt as _; // global logger | ||
| 13 | use panic_probe as _; | ||
| 14 | 12 | ||
| 15 | // Demonstrates both continuous sampling and scanning multiple channels driven by a PPI linked timer | 13 | // Demonstrates both continuous sampling and scanning multiple channels driven by a PPI linked timer |
| 16 | 14 | ||
diff --git a/examples/nrf/src/bin/self_spawn.rs b/examples/nrf/src/bin/self_spawn.rs index 35e73a8dd..4b8ac04bc 100644 --- a/examples/nrf/src/bin/self_spawn.rs +++ b/examples/nrf/src/bin/self_spawn.rs | |||
| @@ -6,9 +6,7 @@ use defmt::{info, unwrap}; | |||
| 6 | use embassy::executor::Spawner; | 6 | use embassy::executor::Spawner; |
| 7 | use embassy::time::{Duration, Timer}; | 7 | use embassy::time::{Duration, Timer}; |
| 8 | use embassy_nrf::Peripherals; | 8 | use embassy_nrf::Peripherals; |
| 9 | 9 | use {defmt_rtt as _, panic_probe as _}; | |
| 10 | use defmt_rtt as _; // global logger | ||
| 11 | use panic_probe as _; | ||
| 12 | 10 | ||
| 13 | #[embassy::task(pool_size = 2)] | 11 | #[embassy::task(pool_size = 2)] |
| 14 | async fn my_task(spawner: Spawner, n: u32) { | 12 | async fn my_task(spawner: Spawner, n: u32) { |
diff --git a/examples/nrf/src/bin/self_spawn_current_executor.rs b/examples/nrf/src/bin/self_spawn_current_executor.rs index 4850d295d..3c3379ce6 100644 --- a/examples/nrf/src/bin/self_spawn_current_executor.rs +++ b/examples/nrf/src/bin/self_spawn_current_executor.rs | |||
| @@ -6,9 +6,7 @@ use defmt::{info, unwrap}; | |||
| 6 | use embassy::executor::Spawner; | 6 | use embassy::executor::Spawner; |
| 7 | use embassy::time::{Duration, Timer}; | 7 | use embassy::time::{Duration, Timer}; |
| 8 | use embassy_nrf::Peripherals; | 8 | use embassy_nrf::Peripherals; |
| 9 | 9 | use {defmt_rtt as _, panic_probe as _}; | |
| 10 | use defmt_rtt as _; // global logger | ||
| 11 | use panic_probe as _; | ||
| 12 | 10 | ||
| 13 | #[embassy::task(pool_size = 2)] | 11 | #[embassy::task(pool_size = 2)] |
| 14 | async fn my_task(n: u32) { | 12 | async fn my_task(n: u32) { |
diff --git a/examples/nrf/src/bin/spim.rs b/examples/nrf/src/bin/spim.rs index f2a4ab388..62040168a 100644 --- a/examples/nrf/src/bin/spim.rs +++ b/examples/nrf/src/bin/spim.rs | |||
| @@ -5,11 +5,8 @@ | |||
| 5 | use defmt::{info, unwrap}; | 5 | use defmt::{info, unwrap}; |
| 6 | use embassy::executor::Spawner; | 6 | use embassy::executor::Spawner; |
| 7 | use embassy_nrf::gpio::{Level, Output, OutputDrive}; | 7 | use embassy_nrf::gpio::{Level, Output, OutputDrive}; |
| 8 | use embassy_nrf::Peripherals; | 8 | use embassy_nrf::{interrupt, spim, Peripherals}; |
| 9 | use embassy_nrf::{interrupt, spim}; | 9 | use {defmt_rtt as _, panic_probe as _}; |
| 10 | |||
| 11 | use defmt_rtt as _; // global logger | ||
| 12 | use panic_probe as _; | ||
| 13 | 10 | ||
| 14 | #[embassy::main] | 11 | #[embassy::main] |
| 15 | async fn main(_spawner: Spawner, p: Peripherals) { | 12 | async fn main(_spawner: Spawner, p: Peripherals) { |
diff --git a/examples/nrf/src/bin/temp.rs b/examples/nrf/src/bin/temp.rs index aa807910f..939cb39e7 100644 --- a/examples/nrf/src/bin/temp.rs +++ b/examples/nrf/src/bin/temp.rs | |||
| @@ -5,10 +5,9 @@ | |||
| 5 | use defmt::info; | 5 | use defmt::info; |
| 6 | use embassy::executor::Spawner; | 6 | use embassy::executor::Spawner; |
| 7 | use embassy::time::{Duration, Timer}; | 7 | use embassy::time::{Duration, Timer}; |
| 8 | use embassy_nrf::{interrupt, temp::Temp, Peripherals}; | 8 | use embassy_nrf::temp::Temp; |
| 9 | 9 | use embassy_nrf::{interrupt, Peripherals}; | |
| 10 | use defmt_rtt as _; // global logger | 10 | use {defmt_rtt as _, panic_probe as _}; |
| 11 | use panic_probe as _; | ||
| 12 | 11 | ||
| 13 | #[embassy::main] | 12 | #[embassy::main] |
| 14 | async fn main(_spawner: Spawner, p: Peripherals) { | 13 | async fn main(_spawner: Spawner, p: Peripherals) { |
diff --git a/examples/nrf/src/bin/timer.rs b/examples/nrf/src/bin/timer.rs index ff8ee9a86..64376dd78 100644 --- a/examples/nrf/src/bin/timer.rs +++ b/examples/nrf/src/bin/timer.rs | |||
| @@ -6,9 +6,7 @@ use defmt::{info, unwrap}; | |||
| 6 | use embassy::executor::Spawner; | 6 | use embassy::executor::Spawner; |
| 7 | use embassy::time::{Duration, Timer}; | 7 | use embassy::time::{Duration, Timer}; |
| 8 | use embassy_nrf::Peripherals; | 8 | use embassy_nrf::Peripherals; |
| 9 | 9 | use {defmt_rtt as _, panic_probe as _}; | |
| 10 | use defmt_rtt as _; // global logger | ||
| 11 | use panic_probe as _; | ||
| 12 | 10 | ||
| 13 | #[embassy::task] | 11 | #[embassy::task] |
| 14 | async fn run1() { | 12 | async fn run1() { |
diff --git a/examples/nrf/src/bin/twim.rs b/examples/nrf/src/bin/twim.rs index 08c614157..fb8372a12 100644 --- a/examples/nrf/src/bin/twim.rs +++ b/examples/nrf/src/bin/twim.rs | |||
| @@ -10,9 +10,7 @@ use defmt::*; | |||
| 10 | use embassy::executor::Spawner; | 10 | use embassy::executor::Spawner; |
| 11 | use embassy_nrf::twim::{self, Twim}; | 11 | use embassy_nrf::twim::{self, Twim}; |
| 12 | use embassy_nrf::{interrupt, Peripherals}; | 12 | use embassy_nrf::{interrupt, Peripherals}; |
| 13 | 13 | use {defmt_rtt as _, panic_probe as _}; | |
| 14 | use defmt_rtt as _; // global logger | ||
| 15 | use panic_probe as _; | ||
| 16 | 14 | ||
| 17 | const ADDRESS: u8 = 0x50; | 15 | const ADDRESS: u8 = 0x50; |
| 18 | 16 | ||
diff --git a/examples/nrf/src/bin/twim_lowpower.rs b/examples/nrf/src/bin/twim_lowpower.rs index 45b347ea0..c9c2d503e 100644 --- a/examples/nrf/src/bin/twim_lowpower.rs +++ b/examples/nrf/src/bin/twim_lowpower.rs | |||
| @@ -9,14 +9,13 @@ | |||
| 9 | #![feature(type_alias_impl_trait)] | 9 | #![feature(type_alias_impl_trait)] |
| 10 | 10 | ||
| 11 | use core::mem; | 11 | use core::mem; |
| 12 | |||
| 12 | use defmt::*; | 13 | use defmt::*; |
| 13 | use embassy::executor::Spawner; | 14 | use embassy::executor::Spawner; |
| 14 | use embassy::time::{Duration, Timer}; | 15 | use embassy::time::{Duration, Timer}; |
| 15 | use embassy_nrf::twim::{self, Twim}; | 16 | use embassy_nrf::twim::{self, Twim}; |
| 16 | use embassy_nrf::{interrupt, Peripherals}; | 17 | use embassy_nrf::{interrupt, Peripherals}; |
| 17 | 18 | use {defmt_rtt as _, panic_probe as _}; | |
| 18 | use defmt_rtt as _; // global logger | ||
| 19 | use panic_probe as _; | ||
| 20 | 19 | ||
| 21 | const ADDRESS: u8 = 0x50; | 20 | const ADDRESS: u8 = 0x50; |
| 22 | 21 | ||
diff --git a/examples/nrf/src/bin/uart.rs b/examples/nrf/src/bin/uart.rs index 91f7f4fdd..c8c4a67a5 100644 --- a/examples/nrf/src/bin/uart.rs +++ b/examples/nrf/src/bin/uart.rs | |||
| @@ -5,9 +5,7 @@ | |||
| 5 | use defmt::*; | 5 | use defmt::*; |
| 6 | use embassy::executor::Spawner; | 6 | use embassy::executor::Spawner; |
| 7 | use embassy_nrf::{interrupt, uarte, Peripherals}; | 7 | use embassy_nrf::{interrupt, uarte, Peripherals}; |
| 8 | 8 | use {defmt_rtt as _, panic_probe as _}; | |
| 9 | use defmt_rtt as _; // global logger | ||
| 10 | use panic_probe as _; | ||
| 11 | 9 | ||
| 12 | #[embassy::main] | 10 | #[embassy::main] |
| 13 | async fn main(_spawner: Spawner, p: Peripherals) { | 11 | async fn main(_spawner: Spawner, p: Peripherals) { |
diff --git a/examples/nrf/src/bin/uart_idle.rs b/examples/nrf/src/bin/uart_idle.rs index 89336faaf..6679b28da 100644 --- a/examples/nrf/src/bin/uart_idle.rs +++ b/examples/nrf/src/bin/uart_idle.rs | |||
| @@ -5,9 +5,7 @@ | |||
| 5 | use defmt::*; | 5 | use defmt::*; |
| 6 | use embassy::executor::Spawner; | 6 | use embassy::executor::Spawner; |
| 7 | use embassy_nrf::{interrupt, uarte, Peripherals}; | 7 | use embassy_nrf::{interrupt, uarte, Peripherals}; |
| 8 | 8 | use {defmt_rtt as _, panic_probe as _}; | |
| 9 | use defmt_rtt as _; // global logger | ||
| 10 | use panic_probe as _; | ||
| 11 | 9 | ||
| 12 | #[embassy::main] | 10 | #[embassy::main] |
| 13 | async fn main(_spawner: Spawner, p: Peripherals) { | 11 | async fn main(_spawner: Spawner, p: Peripherals) { |
| @@ -16,9 +14,7 @@ async fn main(_spawner: Spawner, p: Peripherals) { | |||
| 16 | config.baudrate = uarte::Baudrate::BAUD115200; | 14 | config.baudrate = uarte::Baudrate::BAUD115200; |
| 17 | 15 | ||
| 18 | let irq = interrupt::take!(UARTE0_UART0); | 16 | let irq = interrupt::take!(UARTE0_UART0); |
| 19 | let mut uart = uarte::UarteWithIdle::new( | 17 | let mut uart = uarte::UarteWithIdle::new(p.UARTE0, p.TIMER0, p.PPI_CH0, p.PPI_CH1, irq, p.P0_08, p.P0_06, config); |
| 20 | p.UARTE0, p.TIMER0, p.PPI_CH0, p.PPI_CH1, irq, p.P0_08, p.P0_06, config, | ||
| 21 | ); | ||
| 22 | 18 | ||
| 23 | info!("uarte initialized!"); | 19 | info!("uarte initialized!"); |
| 24 | 20 | ||
diff --git a/examples/nrf/src/bin/uart_split.rs b/examples/nrf/src/bin/uart_split.rs index 958cfeba0..1ffb63706 100644 --- a/examples/nrf/src/bin/uart_split.rs +++ b/examples/nrf/src/bin/uart_split.rs | |||
| @@ -9,9 +9,7 @@ use embassy::executor::Spawner; | |||
| 9 | use embassy_nrf::peripherals::UARTE0; | 9 | use embassy_nrf::peripherals::UARTE0; |
| 10 | use embassy_nrf::uarte::UarteRx; | 10 | use embassy_nrf::uarte::UarteRx; |
| 11 | use embassy_nrf::{interrupt, uarte, Peripherals}; | 11 | use embassy_nrf::{interrupt, uarte, Peripherals}; |
| 12 | 12 | use {defmt_rtt as _, panic_probe as _}; | |
| 13 | use defmt_rtt as _; // global logger | ||
| 14 | use panic_probe as _; | ||
| 15 | 13 | ||
| 16 | static CHANNEL: Channel<ThreadModeRawMutex, [u8; 8], 1> = Channel::new(); | 14 | static CHANNEL: Channel<ThreadModeRawMutex, [u8; 8], 1> = Channel::new(); |
| 17 | 15 | ||
diff --git a/examples/nrf/src/bin/usb_ethernet.rs b/examples/nrf/src/bin/usb_ethernet.rs index 3d85d22bb..a20321fe8 100644 --- a/examples/nrf/src/bin/usb_ethernet.rs +++ b/examples/nrf/src/bin/usb_ethernet.rs | |||
| @@ -6,6 +6,7 @@ | |||
| 6 | use core::mem; | 6 | use core::mem; |
| 7 | use core::sync::atomic::{AtomicBool, Ordering}; | 7 | use core::sync::atomic::{AtomicBool, Ordering}; |
| 8 | use core::task::Waker; | 8 | use core::task::Waker; |
| 9 | |||
| 9 | use defmt::*; | 10 | use defmt::*; |
| 10 | use embassy::blocking_mutex::raw::ThreadModeRawMutex; | 11 | use embassy::blocking_mutex::raw::ThreadModeRawMutex; |
| 11 | use embassy::channel::mpmc::Channel; | 12 | use embassy::channel::mpmc::Channel; |
| @@ -13,18 +14,13 @@ use embassy::executor::Spawner; | |||
| 13 | use embassy::util::Forever; | 14 | use embassy::util::Forever; |
| 14 | use embassy_net::tcp::TcpSocket; | 15 | use embassy_net::tcp::TcpSocket; |
| 15 | use embassy_net::{PacketBox, PacketBoxExt, PacketBuf, Stack, StackResources}; | 16 | use embassy_net::{PacketBox, PacketBoxExt, PacketBuf, Stack, StackResources}; |
| 16 | use embassy_nrf::pac; | ||
| 17 | use embassy_nrf::rng::Rng; | 17 | use embassy_nrf::rng::Rng; |
| 18 | use embassy_nrf::usb::Driver; | 18 | use embassy_nrf::usb::Driver; |
| 19 | use embassy_nrf::Peripherals; | 19 | use embassy_nrf::{interrupt, pac, peripherals, Peripherals}; |
| 20 | use embassy_nrf::{interrupt, peripherals}; | ||
| 21 | use embassy_usb::{Builder, Config, UsbDevice}; | 20 | use embassy_usb::{Builder, Config, UsbDevice}; |
| 22 | use embassy_usb_ncm::{CdcNcmClass, Receiver, Sender, State}; | 21 | use embassy_usb_ncm::{CdcNcmClass, Receiver, Sender, State}; |
| 23 | |||
| 24 | use defmt_rtt as _; | ||
| 25 | use embedded_io::asynch::{Read, Write}; | 22 | use embedded_io::asynch::{Read, Write}; |
| 26 | // global logger | 23 | use {defmt_rtt as _, panic_probe as _}; |
| 27 | use panic_probe as _; | ||
| 28 | 24 | ||
| 29 | type MyDriver = Driver<'static, peripherals::USBD>; | 25 | type MyDriver = Driver<'static, peripherals::USBD>; |
| 30 | 26 | ||
| @@ -180,9 +176,7 @@ async fn main(spawner: Spawner, p: Peripherals) { | |||
| 180 | let seed = u64::from_le_bytes(seed); | 176 | let seed = u64::from_le_bytes(seed); |
| 181 | 177 | ||
| 182 | // Init network stack | 178 | // Init network stack |
| 183 | let device = Device { | 179 | let device = Device { mac_addr: our_mac_addr }; |
| 184 | mac_addr: our_mac_addr, | ||
| 185 | }; | ||
| 186 | let stack = &*forever!(Stack::new( | 180 | let stack = &*forever!(Stack::new( |
| 187 | device, | 181 | device, |
| 188 | config, | 182 | config, |
diff --git a/examples/nrf/src/bin/usb_hid_keyboard.rs b/examples/nrf/src/bin/usb_hid_keyboard.rs index 98e7dd696..97ec861d8 100644 --- a/examples/nrf/src/bin/usb_hid_keyboard.rs +++ b/examples/nrf/src/bin/usb_hid_keyboard.rs | |||
| @@ -5,25 +5,22 @@ | |||
| 5 | 5 | ||
| 6 | use core::mem; | 6 | use core::mem; |
| 7 | use core::sync::atomic::{AtomicBool, Ordering}; | 7 | use core::sync::atomic::{AtomicBool, Ordering}; |
| 8 | |||
| 8 | use defmt::*; | 9 | use defmt::*; |
| 9 | use embassy::channel::signal::Signal; | 10 | use embassy::channel::signal::Signal; |
| 10 | use embassy::executor::Spawner; | 11 | use embassy::executor::Spawner; |
| 11 | use embassy::time::Duration; | 12 | use embassy::time::Duration; |
| 12 | use embassy::util::{select, select3, Either, Either3}; | 13 | use embassy::util::{select, select3, Either, Either3}; |
| 13 | use embassy_nrf::gpio::{Input, Pin, Pull}; | 14 | use embassy_nrf::gpio::{Input, Pin, Pull}; |
| 14 | use embassy_nrf::interrupt; | ||
| 15 | use embassy_nrf::interrupt::InterruptExt; | 15 | use embassy_nrf::interrupt::InterruptExt; |
| 16 | use embassy_nrf::pac; | ||
| 17 | use embassy_nrf::usb::Driver; | 16 | use embassy_nrf::usb::Driver; |
| 18 | use embassy_nrf::Peripherals; | 17 | use embassy_nrf::{interrupt, pac, Peripherals}; |
| 19 | use embassy_usb::control::OutResponse; | 18 | use embassy_usb::control::OutResponse; |
| 20 | use embassy_usb::{Builder, Config, DeviceStateHandler}; | 19 | use embassy_usb::{Builder, Config, DeviceStateHandler}; |
| 21 | use embassy_usb_hid::{HidReaderWriter, ReportId, RequestHandler, State}; | 20 | use embassy_usb_hid::{HidReaderWriter, ReportId, RequestHandler, State}; |
| 22 | use futures::future::join; | 21 | use futures::future::join; |
| 23 | use usbd_hid::descriptor::{KeyboardReport, SerializedDescriptor}; | 22 | use usbd_hid::descriptor::{KeyboardReport, SerializedDescriptor}; |
| 24 | 23 | use {defmt_rtt as _, panic_probe as _}; | |
| 25 | use defmt_rtt as _; // global logger | ||
| 26 | use panic_probe as _; | ||
| 27 | 24 | ||
| 28 | static ENABLE_USB: Signal<bool> = Signal::new(); | 25 | static ENABLE_USB: Signal<bool> = Signal::new(); |
| 29 | static SUSPENDED: AtomicBool = AtomicBool::new(false); | 26 | static SUSPENDED: AtomicBool = AtomicBool::new(false); |
| @@ -182,9 +179,7 @@ async fn main(_spawner: Spawner, p: Peripherals) { | |||
| 182 | power_irq.unpend(); | 179 | power_irq.unpend(); |
| 183 | power_irq.enable(); | 180 | power_irq.enable(); |
| 184 | 181 | ||
| 185 | power | 182 | power.intenset.write(|w| w.usbdetected().set().usbremoved().set()); |
| 186 | .intenset | ||
| 187 | .write(|w| w.usbdetected().set().usbremoved().set()); | ||
| 188 | 183 | ||
| 189 | // Run everything concurrently. | 184 | // Run everything concurrently. |
| 190 | // If we had made everything `'static` above instead, we could do this using separate tasks instead. | 185 | // If we had made everything `'static` above instead, we could do this using separate tasks instead. |
| @@ -260,9 +255,7 @@ impl DeviceStateHandler for MyDeviceStateHandler { | |||
| 260 | fn configured(&self, configured: bool) { | 255 | fn configured(&self, configured: bool) { |
| 261 | self.configured.store(configured, Ordering::Relaxed); | 256 | self.configured.store(configured, Ordering::Relaxed); |
| 262 | if configured { | 257 | if configured { |
| 263 | info!( | 258 | info!("Device configured, it may now draw up to the configured current limit from Vbus.") |
| 264 | "Device configured, it may now draw up to the configured current limit from Vbus." | ||
| 265 | ) | ||
| 266 | } else { | 259 | } else { |
| 267 | info!("Device is no longer configured, the Vbus current limit is 100mA."); | 260 | info!("Device is no longer configured, the Vbus current limit is 100mA."); |
| 268 | } | 261 | } |
| @@ -275,9 +268,7 @@ impl DeviceStateHandler for MyDeviceStateHandler { | |||
| 275 | } else { | 268 | } else { |
| 276 | SUSPENDED.store(false, Ordering::Release); | 269 | SUSPENDED.store(false, Ordering::Release); |
| 277 | if self.configured.load(Ordering::Relaxed) { | 270 | if self.configured.load(Ordering::Relaxed) { |
| 278 | info!( | 271 | info!("Device resumed, it may now draw up to the configured current limit from Vbus"); |
| 279 | "Device resumed, it may now draw up to the configured current limit from Vbus" | ||
| 280 | ); | ||
| 281 | } else { | 272 | } else { |
| 282 | info!("Device resumed, the Vbus current limit is 100mA"); | 273 | info!("Device resumed, the Vbus current limit is 100mA"); |
| 283 | } | 274 | } |
diff --git a/examples/nrf/src/bin/usb_hid_mouse.rs b/examples/nrf/src/bin/usb_hid_mouse.rs index c526c1c6f..9c44e5cc8 100644 --- a/examples/nrf/src/bin/usb_hid_mouse.rs +++ b/examples/nrf/src/bin/usb_hid_mouse.rs | |||
| @@ -4,21 +4,18 @@ | |||
| 4 | #![feature(type_alias_impl_trait)] | 4 | #![feature(type_alias_impl_trait)] |
| 5 | 5 | ||
| 6 | use core::mem; | 6 | use core::mem; |
| 7 | |||
| 7 | use defmt::*; | 8 | use defmt::*; |
| 8 | use embassy::executor::Spawner; | 9 | use embassy::executor::Spawner; |
| 9 | use embassy::time::{Duration, Timer}; | 10 | use embassy::time::{Duration, Timer}; |
| 10 | use embassy_nrf::interrupt; | ||
| 11 | use embassy_nrf::pac; | ||
| 12 | use embassy_nrf::usb::Driver; | 11 | use embassy_nrf::usb::Driver; |
| 13 | use embassy_nrf::Peripherals; | 12 | use embassy_nrf::{interrupt, pac, Peripherals}; |
| 14 | use embassy_usb::control::OutResponse; | 13 | use embassy_usb::control::OutResponse; |
| 15 | use embassy_usb::{Builder, Config}; | 14 | use embassy_usb::{Builder, Config}; |
| 16 | use embassy_usb_hid::{HidWriter, ReportId, RequestHandler, State}; | 15 | use embassy_usb_hid::{HidWriter, ReportId, RequestHandler, State}; |
| 17 | use futures::future::join; | 16 | use futures::future::join; |
| 18 | use usbd_hid::descriptor::{MouseReport, SerializedDescriptor}; | 17 | use usbd_hid::descriptor::{MouseReport, SerializedDescriptor}; |
| 19 | 18 | use {defmt_rtt as _, panic_probe as _}; | |
| 20 | use defmt_rtt as _; // global logger | ||
| 21 | use panic_probe as _; | ||
| 22 | 19 | ||
| 23 | #[embassy::main] | 20 | #[embassy::main] |
| 24 | async fn main(_spawner: Spawner, p: Peripherals) { | 21 | async fn main(_spawner: Spawner, p: Peripherals) { |
diff --git a/examples/nrf/src/bin/usb_serial.rs b/examples/nrf/src/bin/usb_serial.rs index 2551c4ba1..f108db46d 100644 --- a/examples/nrf/src/bin/usb_serial.rs +++ b/examples/nrf/src/bin/usb_serial.rs | |||
| @@ -4,19 +4,16 @@ | |||
| 4 | #![feature(type_alias_impl_trait)] | 4 | #![feature(type_alias_impl_trait)] |
| 5 | 5 | ||
| 6 | use core::mem; | 6 | use core::mem; |
| 7 | |||
| 7 | use defmt::{info, panic}; | 8 | use defmt::{info, panic}; |
| 8 | use embassy::executor::Spawner; | 9 | use embassy::executor::Spawner; |
| 9 | use embassy_nrf::interrupt; | ||
| 10 | use embassy_nrf::pac; | ||
| 11 | use embassy_nrf::usb::{Driver, Instance}; | 10 | use embassy_nrf::usb::{Driver, Instance}; |
| 12 | use embassy_nrf::Peripherals; | 11 | use embassy_nrf::{interrupt, pac, Peripherals}; |
| 13 | use embassy_usb::driver::EndpointError; | 12 | use embassy_usb::driver::EndpointError; |
| 14 | use embassy_usb::{Builder, Config}; | 13 | use embassy_usb::{Builder, Config}; |
| 15 | use embassy_usb_serial::{CdcAcmClass, State}; | 14 | use embassy_usb_serial::{CdcAcmClass, State}; |
| 16 | use futures::future::join; | 15 | use futures::future::join; |
| 17 | 16 | use {defmt_rtt as _, panic_probe as _}; | |
| 18 | use defmt_rtt as _; // global logger | ||
| 19 | use panic_probe as _; | ||
| 20 | 17 | ||
| 21 | #[embassy::main] | 18 | #[embassy::main] |
| 22 | async fn main(_spawner: Spawner, p: Peripherals) { | 19 | async fn main(_spawner: Spawner, p: Peripherals) { |
| @@ -104,9 +101,7 @@ impl From<EndpointError> for Disconnected { | |||
| 104 | } | 101 | } |
| 105 | } | 102 | } |
| 106 | 103 | ||
| 107 | async fn echo<'d, T: Instance + 'd>( | 104 | async fn echo<'d, T: Instance + 'd>(class: &mut CdcAcmClass<'d, Driver<'d, T>>) -> Result<(), Disconnected> { |
| 108 | class: &mut CdcAcmClass<'d, Driver<'d, T>>, | ||
| 109 | ) -> Result<(), Disconnected> { | ||
| 110 | let mut buf = [0; 64]; | 105 | let mut buf = [0; 64]; |
| 111 | loop { | 106 | loop { |
| 112 | let n = class.read_packet(&mut buf).await?; | 107 | let n = class.read_packet(&mut buf).await?; |
diff --git a/examples/nrf/src/bin/usb_serial_multitask.rs b/examples/nrf/src/bin/usb_serial_multitask.rs index 0e82ba313..dc503e67c 100644 --- a/examples/nrf/src/bin/usb_serial_multitask.rs +++ b/examples/nrf/src/bin/usb_serial_multitask.rs | |||
| @@ -4,19 +4,16 @@ | |||
| 4 | #![feature(type_alias_impl_trait)] | 4 | #![feature(type_alias_impl_trait)] |
| 5 | 5 | ||
| 6 | use core::mem; | 6 | use core::mem; |
| 7 | |||
| 7 | use defmt::{info, panic, unwrap}; | 8 | use defmt::{info, panic, unwrap}; |
| 8 | use embassy::executor::Spawner; | 9 | use embassy::executor::Spawner; |
| 9 | use embassy::util::Forever; | 10 | use embassy::util::Forever; |
| 10 | use embassy_nrf::pac; | ||
| 11 | use embassy_nrf::usb::Driver; | 11 | use embassy_nrf::usb::Driver; |
| 12 | use embassy_nrf::Peripherals; | 12 | use embassy_nrf::{interrupt, pac, peripherals, Peripherals}; |
| 13 | use embassy_nrf::{interrupt, peripherals}; | ||
| 14 | use embassy_usb::driver::EndpointError; | 13 | use embassy_usb::driver::EndpointError; |
| 15 | use embassy_usb::{Builder, Config, UsbDevice}; | 14 | use embassy_usb::{Builder, Config, UsbDevice}; |
| 16 | use embassy_usb_serial::{CdcAcmClass, State}; | 15 | use embassy_usb_serial::{CdcAcmClass, State}; |
| 17 | 16 | use {defmt_rtt as _, panic_probe as _}; | |
| 18 | use defmt_rtt as _; // global logger | ||
| 19 | use panic_probe as _; | ||
| 20 | 17 | ||
| 21 | type MyDriver = Driver<'static, peripherals::USBD>; | 18 | type MyDriver = Driver<'static, peripherals::USBD>; |
| 22 | 19 | ||
diff --git a/examples/nrf/src/bin/wdt.rs b/examples/nrf/src/bin/wdt.rs index 431ccca8b..280e23bcf 100644 --- a/examples/nrf/src/bin/wdt.rs +++ b/examples/nrf/src/bin/wdt.rs | |||
| @@ -7,9 +7,7 @@ use embassy::executor::Spawner; | |||
| 7 | use embassy_nrf::gpio::{Input, Pull}; | 7 | use embassy_nrf::gpio::{Input, Pull}; |
| 8 | use embassy_nrf::wdt::{Config, Watchdog}; | 8 | use embassy_nrf::wdt::{Config, Watchdog}; |
| 9 | use embassy_nrf::Peripherals; | 9 | use embassy_nrf::Peripherals; |
| 10 | 10 | use {defmt_rtt as _, panic_probe as _}; | |
| 11 | use defmt_rtt as _; // global logger | ||
| 12 | use panic_probe as _; | ||
| 13 | 11 | ||
| 14 | #[embassy::main] | 12 | #[embassy::main] |
| 15 | async fn main(_spawner: Spawner, p: Peripherals) { | 13 | async fn main(_spawner: Spawner, p: Peripherals) { |
diff --git a/examples/rp/src/bin/blinky.rs b/examples/rp/src/bin/blinky.rs index 6f199d07e..35612a4cf 100644 --- a/examples/rp/src/bin/blinky.rs +++ b/examples/rp/src/bin/blinky.rs | |||
| @@ -7,9 +7,7 @@ use embassy::executor::Spawner; | |||
| 7 | use embassy::time::{Duration, Timer}; | 7 | use embassy::time::{Duration, Timer}; |
| 8 | use embassy_rp::{gpio, Peripherals}; | 8 | use embassy_rp::{gpio, Peripherals}; |
| 9 | use gpio::{Level, Output}; | 9 | use gpio::{Level, Output}; |
| 10 | 10 | use {defmt_rtt as _, panic_probe as _}; | |
| 11 | use defmt_rtt as _; // global logger | ||
| 12 | use panic_probe as _; | ||
| 13 | 11 | ||
| 14 | #[embassy::main] | 12 | #[embassy::main] |
| 15 | async fn main(_spawner: Spawner, p: Peripherals) { | 13 | async fn main(_spawner: Spawner, p: Peripherals) { |
diff --git a/examples/rp/src/bin/button.rs b/examples/rp/src/bin/button.rs index 2418ad012..980e54ea1 100644 --- a/examples/rp/src/bin/button.rs +++ b/examples/rp/src/bin/button.rs | |||
| @@ -5,9 +5,7 @@ | |||
| 5 | use embassy::executor::Spawner; | 5 | use embassy::executor::Spawner; |
| 6 | use embassy_rp::gpio::{Input, Level, Output, Pull}; | 6 | use embassy_rp::gpio::{Input, Level, Output, Pull}; |
| 7 | use embassy_rp::Peripherals; | 7 | use embassy_rp::Peripherals; |
| 8 | 8 | use {defmt_rtt as _, panic_probe as _}; | |
| 9 | use defmt_rtt as _; // global logger | ||
| 10 | use panic_probe as _; | ||
| 11 | 9 | ||
| 12 | #[embassy::main] | 10 | #[embassy::main] |
| 13 | async fn main(_spawner: Spawner, p: Peripherals) { | 11 | async fn main(_spawner: Spawner, p: Peripherals) { |
diff --git a/examples/rp/src/bin/spi.rs b/examples/rp/src/bin/spi.rs index b38424363..d97aa94b3 100644 --- a/examples/rp/src/bin/spi.rs +++ b/examples/rp/src/bin/spi.rs | |||
| @@ -4,13 +4,10 @@ | |||
| 4 | 4 | ||
| 5 | use defmt::*; | 5 | use defmt::*; |
| 6 | use embassy::executor::Spawner; | 6 | use embassy::executor::Spawner; |
| 7 | use embassy_rp::spi; | ||
| 8 | use embassy_rp::spi::Spi; | 7 | use embassy_rp::spi::Spi; |
| 9 | use embassy_rp::{gpio, Peripherals}; | 8 | use embassy_rp::{gpio, spi, Peripherals}; |
| 10 | use gpio::{Level, Output}; | 9 | use gpio::{Level, Output}; |
| 11 | 10 | use {defmt_rtt as _, panic_probe as _}; | |
| 12 | use defmt_rtt as _; // global logger | ||
| 13 | use panic_probe as _; | ||
| 14 | 11 | ||
| 15 | #[embassy::main] | 12 | #[embassy::main] |
| 16 | async fn main(_spawner: Spawner, p: Peripherals) { | 13 | async fn main(_spawner: Spawner, p: Peripherals) { |
diff --git a/examples/rp/src/bin/spi_display.rs b/examples/rp/src/bin/spi_display.rs index 5c3c4c4c5..f4a411ba6 100644 --- a/examples/rp/src/bin/spi_display.rs +++ b/examples/rp/src/bin/spi_display.rs | |||
| @@ -3,13 +3,13 @@ | |||
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | use core::cell::RefCell; | 5 | use core::cell::RefCell; |
| 6 | |||
| 6 | use defmt::*; | 7 | use defmt::*; |
| 7 | use embassy::executor::Spawner; | 8 | use embassy::executor::Spawner; |
| 8 | use embassy::time::Delay; | 9 | use embassy::time::Delay; |
| 9 | use embassy_rp::gpio::{Level, Output}; | 10 | use embassy_rp::gpio::{Level, Output}; |
| 10 | use embassy_rp::spi; | ||
| 11 | use embassy_rp::spi::Spi; | 11 | use embassy_rp::spi::Spi; |
| 12 | use embassy_rp::Peripherals; | 12 | use embassy_rp::{spi, Peripherals}; |
| 13 | use embedded_graphics::image::{Image, ImageRawLE}; | 13 | use embedded_graphics::image::{Image, ImageRawLE}; |
| 14 | use embedded_graphics::mono_font::ascii::FONT_10X20; | 14 | use embedded_graphics::mono_font::ascii::FONT_10X20; |
| 15 | use embedded_graphics::mono_font::MonoTextStyle; | 15 | use embedded_graphics::mono_font::MonoTextStyle; |
| @@ -18,14 +18,12 @@ use embedded_graphics::prelude::*; | |||
| 18 | use embedded_graphics::primitives::{PrimitiveStyleBuilder, Rectangle}; | 18 | use embedded_graphics::primitives::{PrimitiveStyleBuilder, Rectangle}; |
| 19 | use embedded_graphics::text::Text; | 19 | use embedded_graphics::text::Text; |
| 20 | use st7789::{Orientation, ST7789}; | 20 | use st7789::{Orientation, ST7789}; |
| 21 | use {defmt_rtt as _, panic_probe as _}; | ||
| 21 | 22 | ||
| 22 | use crate::my_display_interface::SPIDeviceInterface; | 23 | use crate::my_display_interface::SPIDeviceInterface; |
| 23 | use crate::shared_spi::SpiDeviceWithCs; | 24 | use crate::shared_spi::SpiDeviceWithCs; |
| 24 | use crate::touch::Touch; | 25 | use crate::touch::Touch; |
| 25 | 26 | ||
| 26 | use defmt_rtt as _; // global logger | ||
| 27 | use panic_probe as _; | ||
| 28 | |||
| 29 | //const DISPLAY_FREQ: u32 = 64_000_000; | 27 | //const DISPLAY_FREQ: u32 = 64_000_000; |
| 30 | const TOUCH_FREQ: u32 = 200_000; | 28 | const TOUCH_FREQ: u32 = 200_000; |
| 31 | 29 | ||
| @@ -94,9 +92,7 @@ async fn main(_spawner: Spawner, p: Peripherals) { | |||
| 94 | 92 | ||
| 95 | loop { | 93 | loop { |
| 96 | if let Some((x, y)) = touch.read() { | 94 | if let Some((x, y)) = touch.read() { |
| 97 | let style = PrimitiveStyleBuilder::new() | 95 | let style = PrimitiveStyleBuilder::new().fill_color(Rgb565::BLUE).build(); |
| 98 | .fill_color(Rgb565::BLUE) | ||
| 99 | .build(); | ||
| 100 | 96 | ||
| 101 | Rectangle::new(Point::new(x - 1, y - 1), Size::new(3, 3)) | 97 | Rectangle::new(Point::new(x - 1, y - 1), Size::new(3, 3)) |
| 102 | .into_styled(style) | 98 | .into_styled(style) |
diff --git a/examples/rp/src/bin/uart.rs b/examples/rp/src/bin/uart.rs index bc941dd8b..99072253a 100644 --- a/examples/rp/src/bin/uart.rs +++ b/examples/rp/src/bin/uart.rs | |||
| @@ -4,9 +4,7 @@ | |||
| 4 | 4 | ||
| 5 | use embassy::executor::Spawner; | 5 | use embassy::executor::Spawner; |
| 6 | use embassy_rp::{uart, Peripherals}; | 6 | use embassy_rp::{uart, Peripherals}; |
| 7 | 7 | use {defmt_rtt as _, panic_probe as _}; | |
| 8 | use defmt_rtt as _; // global logger | ||
| 9 | use panic_probe as _; | ||
| 10 | 8 | ||
| 11 | #[embassy::main] | 9 | #[embassy::main] |
| 12 | async fn main(_spawner: Spawner, p: Peripherals) { | 10 | async fn main(_spawner: Spawner, p: Peripherals) { |
diff --git a/examples/std/src/serial_port.rs b/examples/std/src/serial_port.rs index 6825cbebc..c41abd4d0 100644 --- a/examples/std/src/serial_port.rs +++ b/examples/std/src/serial_port.rs | |||
| @@ -1,18 +1,16 @@ | |||
| 1 | use std::io; | ||
| 2 | use std::os::unix::io::{AsRawFd, RawFd}; | ||
| 3 | |||
| 1 | use nix::errno::Errno; | 4 | use nix::errno::Errno; |
| 2 | use nix::fcntl::OFlag; | 5 | use nix::fcntl::OFlag; |
| 3 | use nix::sys::termios; | 6 | use nix::sys::termios; |
| 4 | use std::io; | ||
| 5 | use std::os::unix::io::{AsRawFd, RawFd}; | ||
| 6 | 7 | ||
| 7 | pub struct SerialPort { | 8 | pub struct SerialPort { |
| 8 | fd: RawFd, | 9 | fd: RawFd, |
| 9 | } | 10 | } |
| 10 | 11 | ||
| 11 | impl SerialPort { | 12 | impl SerialPort { |
| 12 | pub fn new<P: ?Sized + nix::NixPath>( | 13 | pub fn new<P: ?Sized + nix::NixPath>(path: &P, baudrate: termios::BaudRate) -> io::Result<Self> { |
| 13 | path: &P, | ||
| 14 | baudrate: termios::BaudRate, | ||
| 15 | ) -> io::Result<Self> { | ||
| 16 | let fd = nix::fcntl::open( | 14 | let fd = nix::fcntl::open( |
| 17 | path, | 15 | path, |
| 18 | OFlag::O_RDWR | OFlag::O_NOCTTY | OFlag::O_NONBLOCK, | 16 | OFlag::O_RDWR | OFlag::O_NOCTTY | OFlag::O_NONBLOCK, |
diff --git a/examples/std/src/tuntap.rs b/examples/std/src/tuntap.rs index b70767a3a..a0cace7f7 100644 --- a/examples/std/src/tuntap.rs +++ b/examples/std/src/tuntap.rs | |||
| @@ -1,9 +1,10 @@ | |||
| 1 | use async_io::Async; | ||
| 2 | use log::*; | ||
| 3 | use std::io; | 1 | use std::io; |
| 4 | use std::io::{Read, Write}; | 2 | use std::io::{Read, Write}; |
| 5 | use std::os::unix::io::{AsRawFd, RawFd}; | 3 | use std::os::unix::io::{AsRawFd, RawFd}; |
| 6 | 4 | ||
| 5 | use async_io::Async; | ||
| 6 | use log::*; | ||
| 7 | |||
| 7 | pub const SIOCGIFMTU: libc::c_ulong = 0x8921; | 8 | pub const SIOCGIFMTU: libc::c_ulong = 0x8921; |
| 8 | pub const _SIOCGIFINDEX: libc::c_ulong = 0x8933; | 9 | pub const _SIOCGIFINDEX: libc::c_ulong = 0x8933; |
| 9 | pub const _ETH_P_ALL: libc::c_short = 0x0003; | 10 | pub const _ETH_P_ALL: libc::c_short = 0x0003; |
| @@ -32,11 +33,7 @@ fn ifreq_for(name: &str) -> ifreq { | |||
| 32 | ifreq | 33 | ifreq |
| 33 | } | 34 | } |
| 34 | 35 | ||
| 35 | fn ifreq_ioctl( | 36 | fn ifreq_ioctl(lower: libc::c_int, ifreq: &mut ifreq, cmd: libc::c_ulong) -> io::Result<libc::c_int> { |
| 36 | lower: libc::c_int, | ||
| 37 | ifreq: &mut ifreq, | ||
| 38 | cmd: libc::c_ulong, | ||
| 39 | ) -> io::Result<libc::c_int> { | ||
| 40 | unsafe { | 37 | unsafe { |
| 41 | let res = libc::ioctl(lower, cmd as _, ifreq as *mut ifreq); | 38 | let res = libc::ioctl(lower, cmd as _, ifreq as *mut ifreq); |
| 42 | if res == -1 { | 39 | if res == -1 { |
| @@ -141,11 +138,10 @@ impl TunTapDevice { | |||
| 141 | } | 138 | } |
| 142 | 139 | ||
| 143 | use core::task::Waker; | 140 | use core::task::Waker; |
| 144 | use embassy_net::{ | ||
| 145 | Device, DeviceCapabilities, LinkState, Packet, PacketBox, PacketBoxExt, PacketBuf, | ||
| 146 | }; | ||
| 147 | use std::task::Context; | 141 | use std::task::Context; |
| 148 | 142 | ||
| 143 | use embassy_net::{Device, DeviceCapabilities, LinkState, Packet, PacketBox, PacketBoxExt, PacketBuf}; | ||
| 144 | |||
| 149 | impl Device for TunTapDevice { | 145 | impl Device for TunTapDevice { |
| 150 | fn is_transmit_ready(&mut self) -> bool { | 146 | fn is_transmit_ready(&mut self) -> bool { |
| 151 | true | 147 | true |
diff --git a/examples/stm32f0/src/bin/hello.rs b/examples/stm32f0/src/bin/hello.rs index 975e94f34..225f1c3ae 100644 --- a/examples/stm32f0/src/bin/hello.rs +++ b/examples/stm32f0/src/bin/hello.rs | |||
| @@ -6,9 +6,7 @@ use defmt::info; | |||
| 6 | use embassy::executor::Spawner; | 6 | use embassy::executor::Spawner; |
| 7 | use embassy::time::{Duration, Timer}; | 7 | use embassy::time::{Duration, Timer}; |
| 8 | use embassy_stm32::Peripherals; | 8 | use embassy_stm32::Peripherals; |
| 9 | 9 | use {defmt_rtt as _, panic_probe as _}; | |
| 10 | use defmt_rtt as _; // global logger | ||
| 11 | use panic_probe as _; | ||
| 12 | 10 | ||
| 13 | #[embassy::main] | 11 | #[embassy::main] |
| 14 | async fn main(_spawner: Spawner, _p: Peripherals) -> ! { | 12 | async fn main(_spawner: Spawner, _p: Peripherals) -> ! { |
diff --git a/examples/stm32f1/src/bin/adc.rs b/examples/stm32f1/src/bin/adc.rs index af403423d..09904d4cc 100644 --- a/examples/stm32f1/src/bin/adc.rs +++ b/examples/stm32f1/src/bin/adc.rs | |||
| @@ -7,9 +7,7 @@ use embassy::executor::Spawner; | |||
| 7 | use embassy::time::{Delay, Duration, Timer}; | 7 | use embassy::time::{Delay, Duration, Timer}; |
| 8 | use embassy_stm32::adc::Adc; | 8 | use embassy_stm32::adc::Adc; |
| 9 | use embassy_stm32::Peripherals; | 9 | use embassy_stm32::Peripherals; |
| 10 | 10 | use {defmt_rtt as _, panic_probe as _}; | |
| 11 | use defmt_rtt as _; // global logger | ||
| 12 | use panic_probe as _; | ||
| 13 | 11 | ||
| 14 | #[embassy::main] | 12 | #[embassy::main] |
| 15 | async fn main(_spawner: Spawner, p: Peripherals) { | 13 | async fn main(_spawner: Spawner, p: Peripherals) { |
diff --git a/examples/stm32f1/src/bin/blinky.rs b/examples/stm32f1/src/bin/blinky.rs index 657bcdd1d..c98d0cdad 100644 --- a/examples/stm32f1/src/bin/blinky.rs +++ b/examples/stm32f1/src/bin/blinky.rs | |||
| @@ -7,9 +7,7 @@ use embassy::executor::Spawner; | |||
| 7 | use embassy::time::{Duration, Timer}; | 7 | use embassy::time::{Duration, Timer}; |
| 8 | use embassy_stm32::gpio::{Level, Output, Speed}; | 8 | use embassy_stm32::gpio::{Level, Output, Speed}; |
| 9 | use embassy_stm32::Peripherals; | 9 | use embassy_stm32::Peripherals; |
| 10 | 10 | use {defmt_rtt as _, panic_probe as _}; | |
| 11 | use defmt_rtt as _; // global logger | ||
| 12 | use panic_probe as _; | ||
| 13 | 11 | ||
| 14 | #[embassy::main] | 12 | #[embassy::main] |
| 15 | async fn main(_spawner: Spawner, p: Peripherals) { | 13 | async fn main(_spawner: Spawner, p: Peripherals) { |
diff --git a/examples/stm32f1/src/bin/hello.rs b/examples/stm32f1/src/bin/hello.rs index 8054a8993..82f11bc28 100644 --- a/examples/stm32f1/src/bin/hello.rs +++ b/examples/stm32f1/src/bin/hello.rs | |||
| @@ -6,11 +6,8 @@ use defmt::info; | |||
| 6 | use embassy::executor::Spawner; | 6 | use embassy::executor::Spawner; |
| 7 | use embassy::time::{Duration, Timer}; | 7 | use embassy::time::{Duration, Timer}; |
| 8 | use embassy_stm32::time::Hertz; | 8 | use embassy_stm32::time::Hertz; |
| 9 | use embassy_stm32::Config; | 9 | use embassy_stm32::{Config, Peripherals}; |
| 10 | use embassy_stm32::Peripherals; | 10 | use {defmt_rtt as _, panic_probe as _}; |
| 11 | |||
| 12 | use defmt_rtt as _; // global logger | ||
| 13 | use panic_probe as _; | ||
| 14 | 11 | ||
| 15 | fn config() -> Config { | 12 | fn config() -> Config { |
| 16 | let mut config = Config::default(); | 13 | let mut config = Config::default(); |
diff --git a/examples/stm32f1/src/bin/usb_serial.rs b/examples/stm32f1/src/bin/usb_serial.rs index fe4aa4cc9..d06315d76 100644 --- a/examples/stm32f1/src/bin/usb_serial.rs +++ b/examples/stm32f1/src/bin/usb_serial.rs | |||
| @@ -2,24 +2,18 @@ | |||
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | use defmt::panic; | 5 | use defmt::{panic, *}; |
| 6 | use defmt::*; | ||
| 7 | use defmt_rtt as _; // global logger | ||
| 8 | use embassy::executor::Spawner; | 6 | use embassy::executor::Spawner; |
| 9 | use embassy::time::Duration; | 7 | use embassy::time::{Duration, Timer}; |
| 10 | use embassy::time::Timer; | 8 | use embassy_stm32::gpio::{Level, Output, Speed}; |
| 11 | use embassy_stm32::gpio::Level; | ||
| 12 | use embassy_stm32::gpio::Output; | ||
| 13 | use embassy_stm32::gpio::Speed; | ||
| 14 | use embassy_stm32::interrupt; | ||
| 15 | use embassy_stm32::time::Hertz; | 9 | use embassy_stm32::time::Hertz; |
| 16 | use embassy_stm32::usb::{Driver, Instance}; | 10 | use embassy_stm32::usb::{Driver, Instance}; |
| 17 | use embassy_stm32::{Config, Peripherals}; | 11 | use embassy_stm32::{interrupt, Config, Peripherals}; |
| 18 | use embassy_usb::driver::EndpointError; | 12 | use embassy_usb::driver::EndpointError; |
| 19 | use embassy_usb::Builder; | 13 | use embassy_usb::Builder; |
| 20 | use embassy_usb_serial::{CdcAcmClass, State}; | 14 | use embassy_usb_serial::{CdcAcmClass, State}; |
| 21 | use futures::future::join; | 15 | use futures::future::join; |
| 22 | use panic_probe as _; | 16 | use {defmt_rtt as _, panic_probe as _}; |
| 23 | 17 | ||
| 24 | fn config() -> Config { | 18 | fn config() -> Config { |
| 25 | let mut config = Config::default(); | 19 | let mut config = Config::default(); |
| @@ -104,9 +98,7 @@ impl From<EndpointError> for Disconnected { | |||
| 104 | } | 98 | } |
| 105 | } | 99 | } |
| 106 | 100 | ||
| 107 | async fn echo<'d, T: Instance + 'd>( | 101 | async fn echo<'d, T: Instance + 'd>(class: &mut CdcAcmClass<'d, Driver<'d, T>>) -> Result<(), Disconnected> { |
| 108 | class: &mut CdcAcmClass<'d, Driver<'d, T>>, | ||
| 109 | ) -> Result<(), Disconnected> { | ||
| 110 | let mut buf = [0; 64]; | 102 | let mut buf = [0; 64]; |
| 111 | loop { | 103 | loop { |
| 112 | let n = class.read_packet(&mut buf).await?; | 104 | let n = class.read_packet(&mut buf).await?; |
diff --git a/examples/stm32f2/src/bin/blinky.rs b/examples/stm32f2/src/bin/blinky.rs index 395f4df51..dd20ba85a 100644 --- a/examples/stm32f2/src/bin/blinky.rs +++ b/examples/stm32f2/src/bin/blinky.rs | |||
| @@ -7,9 +7,7 @@ use embassy::executor::Spawner; | |||
| 7 | use embassy::time::{Duration, Timer}; | 7 | use embassy::time::{Duration, Timer}; |
| 8 | use embassy_stm32::gpio::{Level, Output, Speed}; | 8 | use embassy_stm32::gpio::{Level, Output, Speed}; |
| 9 | use embassy_stm32::Peripherals; | 9 | use embassy_stm32::Peripherals; |
| 10 | 10 | use {defmt_rtt as _, panic_probe as _}; | |
| 11 | use defmt_rtt as _; // global logger | ||
| 12 | use panic_probe as _; | ||
| 13 | 11 | ||
| 14 | #[embassy::main] | 12 | #[embassy::main] |
| 15 | async fn main(_spawner: Spawner, p: Peripherals) { | 13 | async fn main(_spawner: Spawner, p: Peripherals) { |
diff --git a/examples/stm32f2/src/bin/pll.rs b/examples/stm32f2/src/bin/pll.rs index 4bd74f0bd..b09d64b0b 100644 --- a/examples/stm32f2/src/bin/pll.rs +++ b/examples/stm32f2/src/bin/pll.rs | |||
| @@ -3,20 +3,16 @@ | |||
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | use core::convert::TryFrom; | 5 | use core::convert::TryFrom; |
| 6 | |||
| 6 | use defmt::*; | 7 | use defmt::*; |
| 7 | use embassy::executor::Spawner; | 8 | use embassy::executor::Spawner; |
| 8 | use embassy::time::{Duration, Timer}; | 9 | use embassy::time::{Duration, Timer}; |
| 9 | use embassy_stm32::{ | 10 | use embassy_stm32::rcc::{ |
| 10 | rcc::{ | 11 | APBPrescaler, ClockSrc, HSEConfig, HSESrc, PLL48Div, PLLConfig, PLLMainDiv, PLLMul, PLLPreDiv, PLLSrc, |
| 11 | APBPrescaler, ClockSrc, HSEConfig, HSESrc, PLL48Div, PLLConfig, PLLMainDiv, PLLMul, | ||
| 12 | PLLPreDiv, PLLSrc, | ||
| 13 | }, | ||
| 14 | time::Hertz, | ||
| 15 | Config, Peripherals, | ||
| 16 | }; | 12 | }; |
| 17 | 13 | use embassy_stm32::time::Hertz; | |
| 18 | use defmt_rtt as _; // global logger | 14 | use embassy_stm32::{Config, Peripherals}; |
| 19 | use panic_probe as _; | 15 | use {defmt_rtt as _, panic_probe as _}; |
| 20 | 16 | ||
| 21 | // Example config for maximum performance on a NUCLEO-F207ZG board | 17 | // Example config for maximum performance on a NUCLEO-F207ZG board |
| 22 | fn config() -> Config { | 18 | fn config() -> Config { |
diff --git a/examples/stm32f3/src/bin/blinky.rs b/examples/stm32f3/src/bin/blinky.rs index 4b181a784..4d0b33f61 100644 --- a/examples/stm32f3/src/bin/blinky.rs +++ b/examples/stm32f3/src/bin/blinky.rs | |||
| @@ -7,9 +7,7 @@ use embassy::executor::Spawner; | |||
| 7 | use embassy::time::{Duration, Timer}; | 7 | use embassy::time::{Duration, Timer}; |
| 8 | use embassy_stm32::gpio::{Level, Output, Speed}; | 8 | use embassy_stm32::gpio::{Level, Output, Speed}; |
| 9 | use embassy_stm32::Peripherals; | 9 | use embassy_stm32::Peripherals; |
| 10 | 10 | use {defmt_rtt as _, panic_probe as _}; | |
| 11 | use defmt_rtt as _; // global logger | ||
| 12 | use panic_probe as _; | ||
| 13 | 11 | ||
| 14 | #[embassy::main] | 12 | #[embassy::main] |
| 15 | async fn main(_spawner: Spawner, p: Peripherals) { | 13 | async fn main(_spawner: Spawner, p: Peripherals) { |
diff --git a/examples/stm32f3/src/bin/button.rs b/examples/stm32f3/src/bin/button.rs index 207381bdd..b55bf3901 100644 --- a/examples/stm32f3/src/bin/button.rs +++ b/examples/stm32f3/src/bin/button.rs | |||
| @@ -4,9 +4,8 @@ | |||
| 4 | 4 | ||
| 5 | use cortex_m_rt::entry; | 5 | use cortex_m_rt::entry; |
| 6 | use defmt::*; | 6 | use defmt::*; |
| 7 | use defmt_rtt as _; // global logger | ||
| 8 | use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; | 7 | use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; |
| 9 | use panic_probe as _; | 8 | use {defmt_rtt as _, panic_probe as _}; |
| 10 | 9 | ||
| 11 | #[entry] | 10 | #[entry] |
| 12 | fn main() -> ! { | 11 | fn main() -> ! { |
diff --git a/examples/stm32f3/src/bin/button_events.rs b/examples/stm32f3/src/bin/button_events.rs index 593701799..45862ddc6 100644 --- a/examples/stm32f3/src/bin/button_events.rs +++ b/examples/stm32f3/src/bin/button_events.rs | |||
| @@ -19,9 +19,7 @@ use embassy_stm32::exti::ExtiInput; | |||
| 19 | use embassy_stm32::gpio::{AnyPin, Input, Level, Output, Pin, Pull, Speed}; | 19 | use embassy_stm32::gpio::{AnyPin, Input, Level, Output, Pin, Pull, Speed}; |
| 20 | use embassy_stm32::peripherals::PA0; | 20 | use embassy_stm32::peripherals::PA0; |
| 21 | use embassy_stm32::Peripherals; | 21 | use embassy_stm32::Peripherals; |
| 22 | 22 | use {defmt_rtt as _, panic_probe as _}; | |
| 23 | use defmt_rtt as _; // global logger | ||
| 24 | use panic_probe as _; | ||
| 25 | 23 | ||
| 26 | struct Leds<'a> { | 24 | struct Leds<'a> { |
| 27 | leds: [Output<'a, AnyPin>; 8], | 25 | leds: [Output<'a, AnyPin>; 8], |
| @@ -57,8 +55,7 @@ impl<'a> Leds<'a> { | |||
| 57 | self.process_event(new_message).await; | 55 | self.process_event(new_message).await; |
| 58 | } else { | 56 | } else { |
| 59 | self.leds[self.current_led].set_low(); | 57 | self.leds[self.current_led].set_low(); |
| 60 | if let Ok(new_message) = with_timeout(Duration::from_millis(200), CHANNEL.recv()).await | 58 | if let Ok(new_message) = with_timeout(Duration::from_millis(200), CHANNEL.recv()).await { |
| 61 | { | ||
| 62 | self.process_event(new_message).await; | 59 | self.process_event(new_message).await; |
| 63 | } | 60 | } |
| 64 | } | 61 | } |
| @@ -137,22 +134,16 @@ async fn button_waiter(mut button: ExtiInput<'static, PA0>) { | |||
| 137 | 134 | ||
| 138 | button.wait_for_rising_edge().await; | 135 | button.wait_for_rising_edge().await; |
| 139 | loop { | 136 | loop { |
| 140 | if with_timeout( | 137 | if with_timeout(Duration::from_millis(HOLD_DELAY), button.wait_for_falling_edge()) |
| 141 | Duration::from_millis(HOLD_DELAY), | 138 | .await |
| 142 | button.wait_for_falling_edge(), | 139 | .is_err() |
| 143 | ) | ||
| 144 | .await | ||
| 145 | .is_err() | ||
| 146 | { | 140 | { |
| 147 | info!("Hold"); | 141 | info!("Hold"); |
| 148 | CHANNEL.send(ButtonEvent::Hold).await; | 142 | CHANNEL.send(ButtonEvent::Hold).await; |
| 149 | button.wait_for_falling_edge().await; | 143 | button.wait_for_falling_edge().await; |
| 150 | } else if with_timeout( | 144 | } else if with_timeout(Duration::from_millis(DOUBLE_CLICK_DELAY), button.wait_for_rising_edge()) |
| 151 | Duration::from_millis(DOUBLE_CLICK_DELAY), | 145 | .await |
| 152 | button.wait_for_rising_edge(), | 146 | .is_err() |
| 153 | ) | ||
| 154 | .await | ||
| 155 | .is_err() | ||
| 156 | { | 147 | { |
| 157 | info!("Single click"); | 148 | info!("Single click"); |
| 158 | CHANNEL.send(ButtonEvent::SingleClick).await; | 149 | CHANNEL.send(ButtonEvent::SingleClick).await; |
diff --git a/examples/stm32f3/src/bin/button_exti.rs b/examples/stm32f3/src/bin/button_exti.rs index 68d166367..add6712b4 100644 --- a/examples/stm32f3/src/bin/button_exti.rs +++ b/examples/stm32f3/src/bin/button_exti.rs | |||
| @@ -3,12 +3,11 @@ | |||
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | use defmt::*; | 5 | use defmt::*; |
| 6 | use defmt_rtt as _; // global logger | ||
| 7 | use embassy::executor::Spawner; | 6 | use embassy::executor::Spawner; |
| 8 | use embassy_stm32::exti::ExtiInput; | 7 | use embassy_stm32::exti::ExtiInput; |
| 9 | use embassy_stm32::gpio::{Input, Pull}; | 8 | use embassy_stm32::gpio::{Input, Pull}; |
| 10 | use embassy_stm32::Peripherals; | 9 | use embassy_stm32::Peripherals; |
| 11 | use panic_probe as _; | 10 | use {defmt_rtt as _, panic_probe as _}; |
| 12 | 11 | ||
| 13 | #[embassy::main] | 12 | #[embassy::main] |
| 14 | async fn main(_spawner: Spawner, p: Peripherals) { | 13 | async fn main(_spawner: Spawner, p: Peripherals) { |
diff --git a/examples/stm32f3/src/bin/flash.rs b/examples/stm32f3/src/bin/flash.rs index 3890f0514..ce16f6de7 100644 --- a/examples/stm32f3/src/bin/flash.rs +++ b/examples/stm32f3/src/bin/flash.rs | |||
| @@ -7,9 +7,7 @@ use embassy::executor::Spawner; | |||
| 7 | use embassy_stm32::flash::Flash; | 7 | use embassy_stm32::flash::Flash; |
| 8 | use embassy_stm32::Peripherals; | 8 | use embassy_stm32::Peripherals; |
| 9 | use embedded_storage::nor_flash::{NorFlash, ReadNorFlash}; | 9 | use embedded_storage::nor_flash::{NorFlash, ReadNorFlash}; |
| 10 | 10 | use {defmt_rtt as _, panic_probe as _}; | |
| 11 | use defmt_rtt as _; // global logger | ||
| 12 | use panic_probe as _; | ||
| 13 | 11 | ||
| 14 | #[embassy::main] | 12 | #[embassy::main] |
| 15 | async fn main(_spawner: Spawner, p: Peripherals) { | 13 | async fn main(_spawner: Spawner, p: Peripherals) { |
diff --git a/examples/stm32f3/src/bin/hello.rs b/examples/stm32f3/src/bin/hello.rs index a79d6838c..3b89f1c72 100644 --- a/examples/stm32f3/src/bin/hello.rs +++ b/examples/stm32f3/src/bin/hello.rs | |||
| @@ -6,11 +6,8 @@ use defmt::info; | |||
| 6 | use embassy::executor::Spawner; | 6 | use embassy::executor::Spawner; |
| 7 | use embassy::time::{Duration, Timer}; | 7 | use embassy::time::{Duration, Timer}; |
| 8 | use embassy_stm32::time::Hertz; | 8 | use embassy_stm32::time::Hertz; |
| 9 | use embassy_stm32::Config; | 9 | use embassy_stm32::{Config, Peripherals}; |
| 10 | use embassy_stm32::Peripherals; | 10 | use {defmt_rtt as _, panic_probe as _}; |
| 11 | |||
| 12 | use defmt_rtt as _; // global logger | ||
| 13 | use panic_probe as _; | ||
| 14 | 11 | ||
| 15 | fn config() -> Config { | 12 | fn config() -> Config { |
| 16 | let mut config = Config::default(); | 13 | let mut config = Config::default(); |
diff --git a/examples/stm32f3/src/bin/multiprio.rs b/examples/stm32f3/src/bin/multiprio.rs index 684295609..4f2cf9a6f 100644 --- a/examples/stm32f3/src/bin/multiprio.rs +++ b/examples/stm32f3/src/bin/multiprio.rs | |||
| @@ -57,16 +57,14 @@ | |||
| 57 | #![no_main] | 57 | #![no_main] |
| 58 | #![feature(type_alias_impl_trait)] | 58 | #![feature(type_alias_impl_trait)] |
| 59 | 59 | ||
| 60 | use defmt::*; | ||
| 61 | use defmt_rtt as _; // global logger | ||
| 62 | use panic_probe as _; | ||
| 63 | |||
| 64 | use cortex_m_rt::entry; | 60 | use cortex_m_rt::entry; |
| 61 | use defmt::*; | ||
| 65 | use embassy::time::{Duration, Instant, Timer}; | 62 | use embassy::time::{Duration, Instant, Timer}; |
| 66 | use embassy::util::Forever; | 63 | use embassy::util::Forever; |
| 67 | use embassy_stm32::executor::{Executor, InterruptExecutor}; | 64 | use embassy_stm32::executor::{Executor, InterruptExecutor}; |
| 68 | use embassy_stm32::interrupt; | 65 | use embassy_stm32::interrupt; |
| 69 | use embassy_stm32::interrupt::InterruptExt; | 66 | use embassy_stm32::interrupt::InterruptExt; |
| 67 | use {defmt_rtt as _, panic_probe as _}; | ||
| 70 | 68 | ||
| 71 | #[embassy::task] | 69 | #[embassy::task] |
| 72 | async fn run_high() { | 70 | async fn run_high() { |
diff --git a/examples/stm32f3/src/bin/spi_dma.rs b/examples/stm32f3/src/bin/spi_dma.rs index 6d80c4087..ece1ae6fe 100644 --- a/examples/stm32f3/src/bin/spi_dma.rs +++ b/examples/stm32f3/src/bin/spi_dma.rs | |||
| @@ -4,14 +4,14 @@ | |||
| 4 | 4 | ||
| 5 | use core::fmt::Write; | 5 | use core::fmt::Write; |
| 6 | use core::str::from_utf8; | 6 | use core::str::from_utf8; |
| 7 | |||
| 7 | use defmt::*; | 8 | use defmt::*; |
| 8 | use defmt_rtt as _; // global logger | ||
| 9 | use embassy::executor::Spawner; | 9 | use embassy::executor::Spawner; |
| 10 | use embassy_stm32::spi::{Config, Spi}; | 10 | use embassy_stm32::spi::{Config, Spi}; |
| 11 | use embassy_stm32::time::Hertz; | 11 | use embassy_stm32::time::Hertz; |
| 12 | use embassy_stm32::Peripherals; | 12 | use embassy_stm32::Peripherals; |
| 13 | use heapless::String; | 13 | use heapless::String; |
| 14 | use panic_probe as _; | 14 | use {defmt_rtt as _, panic_probe as _}; |
| 15 | 15 | ||
| 16 | #[embassy::main] | 16 | #[embassy::main] |
| 17 | async fn main(_spawner: Spawner, p: Peripherals) { | 17 | async fn main(_spawner: Spawner, p: Peripherals) { |
| @@ -32,9 +32,7 @@ async fn main(_spawner: Spawner, p: Peripherals) { | |||
| 32 | let mut write: String<128> = String::new(); | 32 | let mut write: String<128> = String::new(); |
| 33 | let mut read = [0; 128]; | 33 | let mut read = [0; 128]; |
| 34 | core::write!(&mut write, "Hello DMA World {}!\r\n", n).unwrap(); | 34 | core::write!(&mut write, "Hello DMA World {}!\r\n", n).unwrap(); |
| 35 | spi.transfer(&mut read[0..write.len()], write.as_bytes()) | 35 | spi.transfer(&mut read[0..write.len()], write.as_bytes()).await.ok(); |
| 36 | .await | ||
| 37 | .ok(); | ||
| 38 | info!("read via spi+dma: {}", from_utf8(&read).unwrap()); | 36 | info!("read via spi+dma: {}", from_utf8(&read).unwrap()); |
| 39 | } | 37 | } |
| 40 | } | 38 | } |
diff --git a/examples/stm32f3/src/bin/usart_dma.rs b/examples/stm32f3/src/bin/usart_dma.rs index 859749eb7..4660f812e 100644 --- a/examples/stm32f3/src/bin/usart_dma.rs +++ b/examples/stm32f3/src/bin/usart_dma.rs | |||
| @@ -3,14 +3,14 @@ | |||
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | use core::fmt::Write; | 5 | use core::fmt::Write; |
| 6 | |||
| 6 | use defmt::*; | 7 | use defmt::*; |
| 7 | use defmt_rtt as _; // global logger | ||
| 8 | use embassy::executor::Spawner; | 8 | use embassy::executor::Spawner; |
| 9 | use embassy_stm32::dma::NoDma; | 9 | use embassy_stm32::dma::NoDma; |
| 10 | use embassy_stm32::usart::{Config, Uart}; | 10 | use embassy_stm32::usart::{Config, Uart}; |
| 11 | use embassy_stm32::Peripherals; | 11 | use embassy_stm32::Peripherals; |
| 12 | use heapless::String; | 12 | use heapless::String; |
| 13 | use panic_probe as _; | 13 | use {defmt_rtt as _, panic_probe as _}; |
| 14 | 14 | ||
| 15 | #[embassy::main] | 15 | #[embassy::main] |
| 16 | async fn main(_spawner: Spawner, p: Peripherals) { | 16 | async fn main(_spawner: Spawner, p: Peripherals) { |
diff --git a/examples/stm32f3/src/bin/usb_serial.rs b/examples/stm32f3/src/bin/usb_serial.rs index fc33d0bc7..8a76d4546 100644 --- a/examples/stm32f3/src/bin/usb_serial.rs +++ b/examples/stm32f3/src/bin/usb_serial.rs | |||
| @@ -2,24 +2,18 @@ | |||
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | use defmt::panic; | 5 | use defmt::{panic, *}; |
| 6 | use defmt::*; | ||
| 7 | use defmt_rtt as _; // global logger | ||
| 8 | use embassy::executor::Spawner; | 6 | use embassy::executor::Spawner; |
| 9 | use embassy::time::Duration; | 7 | use embassy::time::{Duration, Timer}; |
| 10 | use embassy::time::Timer; | 8 | use embassy_stm32::gpio::{Level, Output, Speed}; |
| 11 | use embassy_stm32::gpio::Level; | ||
| 12 | use embassy_stm32::gpio::Output; | ||
| 13 | use embassy_stm32::gpio::Speed; | ||
| 14 | use embassy_stm32::interrupt; | ||
| 15 | use embassy_stm32::time::U32Ext; | 9 | use embassy_stm32::time::U32Ext; |
| 16 | use embassy_stm32::usb::{Driver, Instance}; | 10 | use embassy_stm32::usb::{Driver, Instance}; |
| 17 | use embassy_stm32::{Config, Peripherals}; | 11 | use embassy_stm32::{interrupt, Config, Peripherals}; |
| 18 | use embassy_usb::driver::EndpointError; | 12 | use embassy_usb::driver::EndpointError; |
| 19 | use embassy_usb::Builder; | 13 | use embassy_usb::Builder; |
| 20 | use embassy_usb_serial::{CdcAcmClass, State}; | 14 | use embassy_usb_serial::{CdcAcmClass, State}; |
| 21 | use futures::future::join; | 15 | use futures::future::join; |
| 22 | use panic_probe as _; | 16 | use {defmt_rtt as _, panic_probe as _}; |
| 23 | 17 | ||
| 24 | fn config() -> Config { | 18 | fn config() -> Config { |
| 25 | let mut config = Config::default(); | 19 | let mut config = Config::default(); |
| @@ -103,9 +97,7 @@ impl From<EndpointError> for Disconnected { | |||
| 103 | } | 97 | } |
| 104 | } | 98 | } |
| 105 | 99 | ||
| 106 | async fn echo<'d, T: Instance + 'd>( | 100 | async fn echo<'d, T: Instance + 'd>(class: &mut CdcAcmClass<'d, Driver<'d, T>>) -> Result<(), Disconnected> { |
| 107 | class: &mut CdcAcmClass<'d, Driver<'d, T>>, | ||
| 108 | ) -> Result<(), Disconnected> { | ||
| 109 | let mut buf = [0; 64]; | 101 | let mut buf = [0; 64]; |
| 110 | loop { | 102 | loop { |
| 111 | let n = class.read_packet(&mut buf).await?; | 103 | let n = class.read_packet(&mut buf).await?; |
diff --git a/examples/stm32f4/src/bin/adc.rs b/examples/stm32f4/src/bin/adc.rs index f0b1ad232..84ddbfd3c 100644 --- a/examples/stm32f4/src/bin/adc.rs +++ b/examples/stm32f4/src/bin/adc.rs | |||
| @@ -2,14 +2,12 @@ | |||
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | use defmt_rtt as _; // global logger | ||
| 6 | use panic_probe as _; | ||
| 7 | |||
| 8 | use defmt::*; | 5 | use defmt::*; |
| 9 | use embassy::executor::Spawner; | 6 | use embassy::executor::Spawner; |
| 10 | use embassy::time::{Delay, Duration, Timer}; | 7 | use embassy::time::{Delay, Duration, Timer}; |
| 11 | use embassy_stm32::adc::Adc; | 8 | use embassy_stm32::adc::Adc; |
| 12 | use embassy_stm32::Peripherals; | 9 | use embassy_stm32::Peripherals; |
| 10 | use {defmt_rtt as _, panic_probe as _}; | ||
| 13 | 11 | ||
| 14 | #[embassy::main] | 12 | #[embassy::main] |
| 15 | async fn main(_spawner: Spawner, p: Peripherals) { | 13 | async fn main(_spawner: Spawner, p: Peripherals) { |
diff --git a/examples/stm32f4/src/bin/blinky.rs b/examples/stm32f4/src/bin/blinky.rs index 8b85ca96d..907492b3d 100644 --- a/examples/stm32f4/src/bin/blinky.rs +++ b/examples/stm32f4/src/bin/blinky.rs | |||
| @@ -3,12 +3,11 @@ | |||
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | use defmt::*; | 5 | use defmt::*; |
| 6 | use defmt_rtt as _; // global logger | ||
| 7 | use embassy::executor::Spawner; | 6 | use embassy::executor::Spawner; |
| 8 | use embassy::time::{Duration, Timer}; | 7 | use embassy::time::{Duration, Timer}; |
| 9 | use embassy_stm32::gpio::{Level, Output, Speed}; | 8 | use embassy_stm32::gpio::{Level, Output, Speed}; |
| 10 | use embassy_stm32::Peripherals; | 9 | use embassy_stm32::Peripherals; |
| 11 | use panic_probe as _; | 10 | use {defmt_rtt as _, panic_probe as _}; |
| 12 | 11 | ||
| 13 | #[embassy::main] | 12 | #[embassy::main] |
| 14 | async fn main(_spawner: Spawner, p: Peripherals) { | 13 | async fn main(_spawner: Spawner, p: Peripherals) { |
diff --git a/examples/stm32f4/src/bin/button.rs b/examples/stm32f4/src/bin/button.rs index 4f9af7fbd..b13e64531 100644 --- a/examples/stm32f4/src/bin/button.rs +++ b/examples/stm32f4/src/bin/button.rs | |||
| @@ -4,9 +4,8 @@ | |||
| 4 | 4 | ||
| 5 | use cortex_m_rt::entry; | 5 | use cortex_m_rt::entry; |
| 6 | use defmt::*; | 6 | use defmt::*; |
| 7 | use defmt_rtt as _; // global logger | ||
| 8 | use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; | 7 | use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; |
| 9 | use panic_probe as _; | 8 | use {defmt_rtt as _, panic_probe as _}; |
| 10 | 9 | ||
| 11 | #[entry] | 10 | #[entry] |
| 12 | fn main() -> ! { | 11 | fn main() -> ! { |
diff --git a/examples/stm32f4/src/bin/button_exti.rs b/examples/stm32f4/src/bin/button_exti.rs index 78f2e6ee2..24ece9927 100644 --- a/examples/stm32f4/src/bin/button_exti.rs +++ b/examples/stm32f4/src/bin/button_exti.rs | |||
| @@ -3,12 +3,11 @@ | |||
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | use defmt::*; | 5 | use defmt::*; |
| 6 | use defmt_rtt as _; // global logger | ||
| 7 | use embassy::executor::Spawner; | 6 | use embassy::executor::Spawner; |
| 8 | use embassy_stm32::exti::ExtiInput; | 7 | use embassy_stm32::exti::ExtiInput; |
| 9 | use embassy_stm32::gpio::{Input, Pull}; | 8 | use embassy_stm32::gpio::{Input, Pull}; |
| 10 | use embassy_stm32::Peripherals; | 9 | use embassy_stm32::Peripherals; |
| 11 | use panic_probe as _; | 10 | use {defmt_rtt as _, panic_probe as _}; |
| 12 | 11 | ||
| 13 | #[embassy::main] | 12 | #[embassy::main] |
| 14 | async fn main(_spawner: Spawner, p: Peripherals) { | 13 | async fn main(_spawner: Spawner, p: Peripherals) { |
diff --git a/examples/stm32f4/src/bin/can.rs b/examples/stm32f4/src/bin/can.rs index 0f41d6860..8abce87a2 100644 --- a/examples/stm32f4/src/bin/can.rs +++ b/examples/stm32f4/src/bin/can.rs | |||
| @@ -2,15 +2,13 @@ | |||
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | use defmt_rtt as _; // global logger | ||
| 6 | use panic_probe as _; | ||
| 7 | |||
| 8 | use cortex_m_rt::entry; | 5 | use cortex_m_rt::entry; |
| 9 | use defmt::*; | 6 | use defmt::*; |
| 10 | use embassy_stm32::can::bxcan::filter::Mask32; | 7 | use embassy_stm32::can::bxcan::filter::Mask32; |
| 11 | use embassy_stm32::can::bxcan::{Frame, StandardId}; | 8 | use embassy_stm32::can::bxcan::{Frame, StandardId}; |
| 12 | use embassy_stm32::can::Can; | 9 | use embassy_stm32::can::Can; |
| 13 | use embassy_stm32::gpio::{Input, Pull}; | 10 | use embassy_stm32::gpio::{Input, Pull}; |
| 11 | use {defmt_rtt as _, panic_probe as _}; | ||
| 14 | 12 | ||
| 15 | #[entry] | 13 | #[entry] |
| 16 | fn main() -> ! { | 14 | fn main() -> ! { |
diff --git a/examples/stm32f4/src/bin/hello.rs b/examples/stm32f4/src/bin/hello.rs index 92d87cedf..8e69e89d1 100644 --- a/examples/stm32f4/src/bin/hello.rs +++ b/examples/stm32f4/src/bin/hello.rs | |||
| @@ -6,11 +6,8 @@ use defmt::info; | |||
| 6 | use embassy::executor::Spawner; | 6 | use embassy::executor::Spawner; |
| 7 | use embassy::time::{Duration, Timer}; | 7 | use embassy::time::{Duration, Timer}; |
| 8 | use embassy_stm32::time::Hertz; | 8 | use embassy_stm32::time::Hertz; |
| 9 | use embassy_stm32::Config; | 9 | use embassy_stm32::{Config, Peripherals}; |
| 10 | use embassy_stm32::Peripherals; | 10 | use {defmt_rtt as _, panic_probe as _}; |
| 11 | |||
| 12 | use defmt_rtt as _; // global logger | ||
| 13 | use panic_probe as _; | ||
| 14 | 11 | ||
| 15 | fn config() -> Config { | 12 | fn config() -> Config { |
| 16 | let mut config = Config::default(); | 13 | let mut config = Config::default(); |
diff --git a/examples/stm32f4/src/bin/multiprio.rs b/examples/stm32f4/src/bin/multiprio.rs index 684295609..4f2cf9a6f 100644 --- a/examples/stm32f4/src/bin/multiprio.rs +++ b/examples/stm32f4/src/bin/multiprio.rs | |||
| @@ -57,16 +57,14 @@ | |||
| 57 | #![no_main] | 57 | #![no_main] |
| 58 | #![feature(type_alias_impl_trait)] | 58 | #![feature(type_alias_impl_trait)] |
| 59 | 59 | ||
| 60 | use defmt::*; | ||
| 61 | use defmt_rtt as _; // global logger | ||
| 62 | use panic_probe as _; | ||
| 63 | |||
| 64 | use cortex_m_rt::entry; | 60 | use cortex_m_rt::entry; |
| 61 | use defmt::*; | ||
| 65 | use embassy::time::{Duration, Instant, Timer}; | 62 | use embassy::time::{Duration, Instant, Timer}; |
| 66 | use embassy::util::Forever; | 63 | use embassy::util::Forever; |
| 67 | use embassy_stm32::executor::{Executor, InterruptExecutor}; | 64 | use embassy_stm32::executor::{Executor, InterruptExecutor}; |
| 68 | use embassy_stm32::interrupt; | 65 | use embassy_stm32::interrupt; |
| 69 | use embassy_stm32::interrupt::InterruptExt; | 66 | use embassy_stm32::interrupt::InterruptExt; |
| 67 | use {defmt_rtt as _, panic_probe as _}; | ||
| 70 | 68 | ||
| 71 | #[embassy::task] | 69 | #[embassy::task] |
| 72 | async fn run_high() { | 70 | async fn run_high() { |
diff --git a/examples/stm32f4/src/bin/sdmmc.rs b/examples/stm32f4/src/bin/sdmmc.rs index eab0fad4a..b08d26f49 100644 --- a/examples/stm32f4/src/bin/sdmmc.rs +++ b/examples/stm32f4/src/bin/sdmmc.rs | |||
| @@ -2,14 +2,12 @@ | |||
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | use defmt_rtt as _; // global logger | ||
| 6 | use panic_probe as _; | ||
| 7 | |||
| 8 | use defmt::*; | 5 | use defmt::*; |
| 9 | use embassy::executor::Spawner; | 6 | use embassy::executor::Spawner; |
| 10 | use embassy_stm32::sdmmc::Sdmmc; | 7 | use embassy_stm32::sdmmc::Sdmmc; |
| 11 | use embassy_stm32::time::U32Ext; | 8 | use embassy_stm32::time::U32Ext; |
| 12 | use embassy_stm32::{interrupt, Config, Peripherals}; | 9 | use embassy_stm32::{interrupt, Config, Peripherals}; |
| 10 | use {defmt_rtt as _, panic_probe as _}; | ||
| 13 | 11 | ||
| 14 | fn config() -> Config { | 12 | fn config() -> Config { |
| 15 | let mut config = Config::default(); | 13 | let mut config = Config::default(); |
diff --git a/examples/stm32f4/src/bin/spi.rs b/examples/stm32f4/src/bin/spi.rs index 69be81432..05b48f478 100644 --- a/examples/stm32f4/src/bin/spi.rs +++ b/examples/stm32f4/src/bin/spi.rs | |||
| @@ -2,15 +2,13 @@ | |||
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | use defmt_rtt as _; // global logger | ||
| 6 | use panic_probe as _; | ||
| 7 | |||
| 8 | use cortex_m_rt::entry; | 5 | use cortex_m_rt::entry; |
| 9 | use defmt::*; | 6 | use defmt::*; |
| 10 | use embassy_stm32::dma::NoDma; | 7 | use embassy_stm32::dma::NoDma; |
| 11 | use embassy_stm32::gpio::{Level, Output, Speed}; | 8 | use embassy_stm32::gpio::{Level, Output, Speed}; |
| 12 | use embassy_stm32::spi::{Config, Spi}; | 9 | use embassy_stm32::spi::{Config, Spi}; |
| 13 | use embassy_stm32::time::Hertz; | 10 | use embassy_stm32::time::Hertz; |
| 11 | use {defmt_rtt as _, panic_probe as _}; | ||
| 14 | 12 | ||
| 15 | #[entry] | 13 | #[entry] |
| 16 | fn main() -> ! { | 14 | fn main() -> ! { |
diff --git a/examples/stm32f4/src/bin/spi_dma.rs b/examples/stm32f4/src/bin/spi_dma.rs index 1bf9b856d..f3c0f2cd5 100644 --- a/examples/stm32f4/src/bin/spi_dma.rs +++ b/examples/stm32f4/src/bin/spi_dma.rs | |||
| @@ -4,14 +4,14 @@ | |||
| 4 | 4 | ||
| 5 | use core::fmt::Write; | 5 | use core::fmt::Write; |
| 6 | use core::str::from_utf8; | 6 | use core::str::from_utf8; |
| 7 | |||
| 7 | use defmt::*; | 8 | use defmt::*; |
| 8 | use defmt_rtt as _; // global logger | ||
| 9 | use embassy::executor::Spawner; | 9 | use embassy::executor::Spawner; |
| 10 | use embassy_stm32::spi::{Config, Spi}; | 10 | use embassy_stm32::spi::{Config, Spi}; |
| 11 | use embassy_stm32::time::Hertz; | 11 | use embassy_stm32::time::Hertz; |
| 12 | use embassy_stm32::Peripherals; | 12 | use embassy_stm32::Peripherals; |
| 13 | use heapless::String; | 13 | use heapless::String; |
| 14 | use panic_probe as _; | 14 | use {defmt_rtt as _, panic_probe as _}; |
| 15 | 15 | ||
| 16 | #[embassy::main] | 16 | #[embassy::main] |
| 17 | async fn main(_spawner: Spawner, p: Peripherals) { | 17 | async fn main(_spawner: Spawner, p: Peripherals) { |
| @@ -32,9 +32,7 @@ async fn main(_spawner: Spawner, p: Peripherals) { | |||
| 32 | let mut write: String<128> = String::new(); | 32 | let mut write: String<128> = String::new(); |
| 33 | let mut read = [0; 128]; | 33 | let mut read = [0; 128]; |
| 34 | core::write!(&mut write, "Hello DMA World {}!\r\n", n).unwrap(); | 34 | core::write!(&mut write, "Hello DMA World {}!\r\n", n).unwrap(); |
| 35 | spi.transfer(&mut read[0..write.len()], write.as_bytes()) | 35 | spi.transfer(&mut read[0..write.len()], write.as_bytes()).await.ok(); |
| 36 | .await | ||
| 37 | .ok(); | ||
| 38 | info!("read via spi+dma: {}", from_utf8(&read).unwrap()); | 36 | info!("read via spi+dma: {}", from_utf8(&read).unwrap()); |
| 39 | } | 37 | } |
| 40 | } | 38 | } |
diff --git a/examples/stm32f4/src/bin/usart.rs b/examples/stm32f4/src/bin/usart.rs index a302667e2..90ad882b8 100644 --- a/examples/stm32f4/src/bin/usart.rs +++ b/examples/stm32f4/src/bin/usart.rs | |||
| @@ -4,10 +4,9 @@ | |||
| 4 | 4 | ||
| 5 | use cortex_m_rt::entry; | 5 | use cortex_m_rt::entry; |
| 6 | use defmt::*; | 6 | use defmt::*; |
| 7 | use defmt_rtt as _; // global logger | ||
| 8 | use embassy_stm32::dma::NoDma; | 7 | use embassy_stm32::dma::NoDma; |
| 9 | use embassy_stm32::usart::{Config, Uart}; | 8 | use embassy_stm32::usart::{Config, Uart}; |
| 10 | use panic_probe as _; | 9 | use {defmt_rtt as _, panic_probe as _}; |
| 11 | 10 | ||
| 12 | #[entry] | 11 | #[entry] |
| 13 | fn main() -> ! { | 12 | fn main() -> ! { |
diff --git a/examples/stm32f4/src/bin/usart_buffered.rs b/examples/stm32f4/src/bin/usart_buffered.rs index 2a613ee4f..039e43bd2 100644 --- a/examples/stm32f4/src/bin/usart_buffered.rs +++ b/examples/stm32f4/src/bin/usart_buffered.rs | |||
| @@ -3,13 +3,12 @@ | |||
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | use defmt::*; | 5 | use defmt::*; |
| 6 | use defmt_rtt as _; // global logger | ||
| 7 | use embassy::executor::Spawner; | 6 | use embassy::executor::Spawner; |
| 8 | use embassy_stm32::dma::NoDma; | 7 | use embassy_stm32::dma::NoDma; |
| 9 | use embassy_stm32::usart::{BufferedUart, Config, State, Uart}; | 8 | use embassy_stm32::usart::{BufferedUart, Config, State, Uart}; |
| 10 | use embassy_stm32::{interrupt, Peripherals}; | 9 | use embassy_stm32::{interrupt, Peripherals}; |
| 11 | use embedded_io::asynch::BufRead; | 10 | use embedded_io::asynch::BufRead; |
| 12 | use panic_probe as _; | 11 | use {defmt_rtt as _, panic_probe as _}; |
| 13 | 12 | ||
| 14 | #[embassy::main] | 13 | #[embassy::main] |
| 15 | async fn main(_spawner: Spawner, p: Peripherals) { | 14 | async fn main(_spawner: Spawner, p: Peripherals) { |
diff --git a/examples/stm32f4/src/bin/usart_dma.rs b/examples/stm32f4/src/bin/usart_dma.rs index cf45b71c5..8d06f8439 100644 --- a/examples/stm32f4/src/bin/usart_dma.rs +++ b/examples/stm32f4/src/bin/usart_dma.rs | |||
| @@ -3,14 +3,14 @@ | |||
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | use core::fmt::Write; | 5 | use core::fmt::Write; |
| 6 | |||
| 6 | use defmt::*; | 7 | use defmt::*; |
| 7 | use defmt_rtt as _; // global logger | ||
| 8 | use embassy::executor::Spawner; | 8 | use embassy::executor::Spawner; |
| 9 | use embassy_stm32::dma::NoDma; | 9 | use embassy_stm32::dma::NoDma; |
| 10 | use embassy_stm32::usart::{Config, Uart}; | 10 | use embassy_stm32::usart::{Config, Uart}; |
| 11 | use embassy_stm32::Peripherals; | 11 | use embassy_stm32::Peripherals; |
| 12 | use heapless::String; | 12 | use heapless::String; |
| 13 | use panic_probe as _; | 13 | use {defmt_rtt as _, panic_probe as _}; |
| 14 | 14 | ||
| 15 | #[embassy::main] | 15 | #[embassy::main] |
| 16 | async fn main(_spawner: Spawner, p: Peripherals) { | 16 | async fn main(_spawner: Spawner, p: Peripherals) { |
diff --git a/examples/stm32f7/build.rs b/examples/stm32f7/build.rs index b72dd55ec..c4e15f19c 100644 --- a/examples/stm32f7/build.rs +++ b/examples/stm32f7/build.rs | |||
| @@ -1,7 +1,8 @@ | |||
| 1 | //! adapted from https://github.com/stm32-rs/stm32f7xx-hal/blob/master/build.rs | 1 | //! adapted from https://github.com/stm32-rs/stm32f7xx-hal/blob/master/build.rs |
| 2 | use std::env; | 2 | use std::env; |
| 3 | use std::fs::File; | 3 | use std::fs::File; |
| 4 | use std::io::{self, prelude::*}; | 4 | use std::io::prelude::*; |
| 5 | use std::io::{self}; | ||
| 5 | use std::path::PathBuf; | 6 | use std::path::PathBuf; |
| 6 | 7 | ||
| 7 | #[derive(Debug)] | 8 | #[derive(Debug)] |
diff --git a/examples/stm32f7/src/bin/adc.rs b/examples/stm32f7/src/bin/adc.rs index 87f5d30dd..fc8359622 100644 --- a/examples/stm32f7/src/bin/adc.rs +++ b/examples/stm32f7/src/bin/adc.rs | |||
| @@ -2,14 +2,12 @@ | |||
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | use defmt_rtt as _; // global logger | ||
| 6 | use panic_probe as _; | ||
| 7 | |||
| 8 | use defmt::*; | 5 | use defmt::*; |
| 9 | use embassy::executor::Spawner; | 6 | use embassy::executor::Spawner; |
| 10 | use embassy::time::{Delay, Duration, Timer}; | 7 | use embassy::time::{Delay, Duration, Timer}; |
| 11 | use embassy_stm32::adc::Adc; | 8 | use embassy_stm32::adc::Adc; |
| 12 | use embassy_stm32::Peripherals; | 9 | use embassy_stm32::Peripherals; |
| 10 | use {defmt_rtt as _, panic_probe as _}; | ||
| 13 | 11 | ||
| 14 | #[embassy::main] | 12 | #[embassy::main] |
| 15 | async fn main(_spawner: Spawner, p: Peripherals) { | 13 | async fn main(_spawner: Spawner, p: Peripherals) { |
diff --git a/examples/stm32f7/src/bin/blinky.rs b/examples/stm32f7/src/bin/blinky.rs index 8b85ca96d..907492b3d 100644 --- a/examples/stm32f7/src/bin/blinky.rs +++ b/examples/stm32f7/src/bin/blinky.rs | |||
| @@ -3,12 +3,11 @@ | |||
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | use defmt::*; | 5 | use defmt::*; |
| 6 | use defmt_rtt as _; // global logger | ||
| 7 | use embassy::executor::Spawner; | 6 | use embassy::executor::Spawner; |
| 8 | use embassy::time::{Duration, Timer}; | 7 | use embassy::time::{Duration, Timer}; |
| 9 | use embassy_stm32::gpio::{Level, Output, Speed}; | 8 | use embassy_stm32::gpio::{Level, Output, Speed}; |
| 10 | use embassy_stm32::Peripherals; | 9 | use embassy_stm32::Peripherals; |
| 11 | use panic_probe as _; | 10 | use {defmt_rtt as _, panic_probe as _}; |
| 12 | 11 | ||
| 13 | #[embassy::main] | 12 | #[embassy::main] |
| 14 | async fn main(_spawner: Spawner, p: Peripherals) { | 13 | async fn main(_spawner: Spawner, p: Peripherals) { |
diff --git a/examples/stm32f7/src/bin/button.rs b/examples/stm32f7/src/bin/button.rs index 4f9af7fbd..b13e64531 100644 --- a/examples/stm32f7/src/bin/button.rs +++ b/examples/stm32f7/src/bin/button.rs | |||
| @@ -4,9 +4,8 @@ | |||
| 4 | 4 | ||
| 5 | use cortex_m_rt::entry; | 5 | use cortex_m_rt::entry; |
| 6 | use defmt::*; | 6 | use defmt::*; |
| 7 | use defmt_rtt as _; // global logger | ||
| 8 | use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; | 7 | use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; |
| 9 | use panic_probe as _; | 8 | use {defmt_rtt as _, panic_probe as _}; |
| 10 | 9 | ||
| 11 | #[entry] | 10 | #[entry] |
| 12 | fn main() -> ! { | 11 | fn main() -> ! { |
diff --git a/examples/stm32f7/src/bin/button_exti.rs b/examples/stm32f7/src/bin/button_exti.rs index 78f2e6ee2..24ece9927 100644 --- a/examples/stm32f7/src/bin/button_exti.rs +++ b/examples/stm32f7/src/bin/button_exti.rs | |||
| @@ -3,12 +3,11 @@ | |||
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | use defmt::*; | 5 | use defmt::*; |
| 6 | use defmt_rtt as _; // global logger | ||
| 7 | use embassy::executor::Spawner; | 6 | use embassy::executor::Spawner; |
| 8 | use embassy_stm32::exti::ExtiInput; | 7 | use embassy_stm32::exti::ExtiInput; |
| 9 | use embassy_stm32::gpio::{Input, Pull}; | 8 | use embassy_stm32::gpio::{Input, Pull}; |
| 10 | use embassy_stm32::Peripherals; | 9 | use embassy_stm32::Peripherals; |
| 11 | use panic_probe as _; | 10 | use {defmt_rtt as _, panic_probe as _}; |
| 12 | 11 | ||
| 13 | #[embassy::main] | 12 | #[embassy::main] |
| 14 | async fn main(_spawner: Spawner, p: Peripherals) { | 13 | async fn main(_spawner: Spawner, p: Peripherals) { |
diff --git a/examples/stm32f7/src/bin/eth.rs b/examples/stm32f7/src/bin/eth.rs index af012f826..dc0b3c605 100644 --- a/examples/stm32f7/src/bin/eth.rs +++ b/examples/stm32f7/src/bin/eth.rs | |||
| @@ -13,13 +13,10 @@ use embassy_stm32::eth::{Ethernet, State}; | |||
| 13 | use embassy_stm32::peripherals::ETH; | 13 | use embassy_stm32::peripherals::ETH; |
| 14 | use embassy_stm32::rng::Rng; | 14 | use embassy_stm32::rng::Rng; |
| 15 | use embassy_stm32::time::U32Ext; | 15 | use embassy_stm32::time::U32Ext; |
| 16 | use embassy_stm32::Config; | 16 | use embassy_stm32::{interrupt, Config, Peripherals}; |
| 17 | use embassy_stm32::{interrupt, Peripherals}; | ||
| 18 | use embedded_io::asynch::Write; | 17 | use embedded_io::asynch::Write; |
| 19 | |||
| 20 | use defmt_rtt as _; // global logger | ||
| 21 | use panic_probe as _; | ||
| 22 | use rand_core::RngCore; | 18 | use rand_core::RngCore; |
| 19 | use {defmt_rtt as _, panic_probe as _}; | ||
| 23 | 20 | ||
| 24 | macro_rules! forever { | 21 | macro_rules! forever { |
| 25 | ($val:expr) => {{ | 22 | ($val:expr) => {{ |
diff --git a/examples/stm32f7/src/bin/flash.rs b/examples/stm32f7/src/bin/flash.rs index 9eb8e4b94..af66275d4 100644 --- a/examples/stm32f7/src/bin/flash.rs +++ b/examples/stm32f7/src/bin/flash.rs | |||
| @@ -8,9 +8,7 @@ use embassy::time::{Duration, Timer}; | |||
| 8 | use embassy_stm32::flash::Flash; | 8 | use embassy_stm32::flash::Flash; |
| 9 | use embassy_stm32::Peripherals; | 9 | use embassy_stm32::Peripherals; |
| 10 | use embedded_storage::nor_flash::{NorFlash, ReadNorFlash}; | 10 | use embedded_storage::nor_flash::{NorFlash, ReadNorFlash}; |
| 11 | 11 | use {defmt_rtt as _, panic_probe as _}; | |
| 12 | use defmt_rtt as _; // global logger | ||
| 13 | use panic_probe as _; | ||
| 14 | 12 | ||
| 15 | #[embassy::main] | 13 | #[embassy::main] |
| 16 | async fn main(_spawner: Spawner, p: Peripherals) { | 14 | async fn main(_spawner: Spawner, p: Peripherals) { |
| @@ -40,8 +38,8 @@ async fn main(_spawner: Spawner, p: Peripherals) { | |||
| 40 | unwrap!(f.write( | 38 | unwrap!(f.write( |
| 41 | ADDR, | 39 | ADDR, |
| 42 | &[ | 40 | &[ |
| 43 | 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, | 41 | 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, |
| 44 | 25, 26, 27, 28, 29, 30, 31, 32 | 42 | 30, 31, 32 |
| 45 | ] | 43 | ] |
| 46 | )); | 44 | )); |
| 47 | 45 | ||
| @@ -52,8 +50,8 @@ async fn main(_spawner: Spawner, p: Peripherals) { | |||
| 52 | assert_eq!( | 50 | assert_eq!( |
| 53 | &buf[..], | 51 | &buf[..], |
| 54 | &[ | 52 | &[ |
| 55 | 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, | 53 | 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, |
| 56 | 25, 26, 27, 28, 29, 30, 31, 32 | 54 | 30, 31, 32 |
| 57 | ] | 55 | ] |
| 58 | ); | 56 | ); |
| 59 | } | 57 | } |
diff --git a/examples/stm32f7/src/bin/hello.rs b/examples/stm32f7/src/bin/hello.rs index 92d87cedf..8e69e89d1 100644 --- a/examples/stm32f7/src/bin/hello.rs +++ b/examples/stm32f7/src/bin/hello.rs | |||
| @@ -6,11 +6,8 @@ use defmt::info; | |||
| 6 | use embassy::executor::Spawner; | 6 | use embassy::executor::Spawner; |
| 7 | use embassy::time::{Duration, Timer}; | 7 | use embassy::time::{Duration, Timer}; |
| 8 | use embassy_stm32::time::Hertz; | 8 | use embassy_stm32::time::Hertz; |
| 9 | use embassy_stm32::Config; | 9 | use embassy_stm32::{Config, Peripherals}; |
| 10 | use embassy_stm32::Peripherals; | 10 | use {defmt_rtt as _, panic_probe as _}; |
| 11 | |||
| 12 | use defmt_rtt as _; // global logger | ||
| 13 | use panic_probe as _; | ||
| 14 | 11 | ||
| 15 | fn config() -> Config { | 12 | fn config() -> Config { |
| 16 | let mut config = Config::default(); | 13 | let mut config = Config::default(); |
diff --git a/examples/stm32f7/src/bin/sdmmc.rs b/examples/stm32f7/src/bin/sdmmc.rs index dae07c303..1af1061ba 100644 --- a/examples/stm32f7/src/bin/sdmmc.rs +++ b/examples/stm32f7/src/bin/sdmmc.rs | |||
| @@ -2,14 +2,12 @@ | |||
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | use defmt_rtt as _; // global logger | ||
| 6 | use panic_probe as _; | ||
| 7 | |||
| 8 | use defmt::*; | 5 | use defmt::*; |
| 9 | use embassy::executor::Spawner; | 6 | use embassy::executor::Spawner; |
| 10 | use embassy_stm32::sdmmc::Sdmmc; | 7 | use embassy_stm32::sdmmc::Sdmmc; |
| 11 | use embassy_stm32::time::U32Ext; | 8 | use embassy_stm32::time::U32Ext; |
| 12 | use embassy_stm32::{interrupt, Config, Peripherals}; | 9 | use embassy_stm32::{interrupt, Config, Peripherals}; |
| 10 | use {defmt_rtt as _, panic_probe as _}; | ||
| 13 | 11 | ||
| 14 | fn config() -> Config { | 12 | fn config() -> Config { |
| 15 | let mut config = Config::default(); | 13 | let mut config = Config::default(); |
diff --git a/examples/stm32f7/src/bin/usart_dma.rs b/examples/stm32f7/src/bin/usart_dma.rs index 69fa21a0d..d8551620c 100644 --- a/examples/stm32f7/src/bin/usart_dma.rs +++ b/examples/stm32f7/src/bin/usart_dma.rs | |||
| @@ -3,15 +3,14 @@ | |||
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | use core::fmt::Write; | 5 | use core::fmt::Write; |
| 6 | |||
| 6 | use defmt::*; | 7 | use defmt::*; |
| 7 | use defmt_rtt as _; // global logger | ||
| 8 | use embassy::executor::Spawner; | 8 | use embassy::executor::Spawner; |
| 9 | use embassy_stm32::dma::NoDma; | 9 | use embassy_stm32::dma::NoDma; |
| 10 | use embassy_stm32::usart::{Config, Uart}; | 10 | use embassy_stm32::usart::{Config, Uart}; |
| 11 | use embassy_stm32::Peripherals; | 11 | use embassy_stm32::Peripherals; |
| 12 | use panic_probe as _; | ||
| 13 | |||
| 14 | use heapless::String; | 12 | use heapless::String; |
| 13 | use {defmt_rtt as _, panic_probe as _}; | ||
| 15 | 14 | ||
| 16 | #[embassy::main] | 15 | #[embassy::main] |
| 17 | async fn main(_spawner: Spawner, p: Peripherals) { | 16 | async fn main(_spawner: Spawner, p: Peripherals) { |
diff --git a/examples/stm32g0/src/bin/blinky.rs b/examples/stm32g0/src/bin/blinky.rs index 8b85ca96d..907492b3d 100644 --- a/examples/stm32g0/src/bin/blinky.rs +++ b/examples/stm32g0/src/bin/blinky.rs | |||
| @@ -3,12 +3,11 @@ | |||
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | use defmt::*; | 5 | use defmt::*; |
| 6 | use defmt_rtt as _; // global logger | ||
| 7 | use embassy::executor::Spawner; | 6 | use embassy::executor::Spawner; |
| 8 | use embassy::time::{Duration, Timer}; | 7 | use embassy::time::{Duration, Timer}; |
| 9 | use embassy_stm32::gpio::{Level, Output, Speed}; | 8 | use embassy_stm32::gpio::{Level, Output, Speed}; |
| 10 | use embassy_stm32::Peripherals; | 9 | use embassy_stm32::Peripherals; |
| 11 | use panic_probe as _; | 10 | use {defmt_rtt as _, panic_probe as _}; |
| 12 | 11 | ||
| 13 | #[embassy::main] | 12 | #[embassy::main] |
| 14 | async fn main(_spawner: Spawner, p: Peripherals) { | 13 | async fn main(_spawner: Spawner, p: Peripherals) { |
diff --git a/examples/stm32g0/src/bin/button.rs b/examples/stm32g0/src/bin/button.rs index 78d7ba1f2..72a3f5cbf 100644 --- a/examples/stm32g0/src/bin/button.rs +++ b/examples/stm32g0/src/bin/button.rs | |||
| @@ -4,9 +4,8 @@ | |||
| 4 | 4 | ||
| 5 | use cortex_m_rt::entry; | 5 | use cortex_m_rt::entry; |
| 6 | use defmt::*; | 6 | use defmt::*; |
| 7 | use defmt_rtt as _; // global logger | ||
| 8 | use embassy_stm32::gpio::{Input, Pull}; | 7 | use embassy_stm32::gpio::{Input, Pull}; |
| 9 | use panic_probe as _; | 8 | use {defmt_rtt as _, panic_probe as _}; |
| 10 | 9 | ||
| 11 | #[entry] | 10 | #[entry] |
| 12 | fn main() -> ! { | 11 | fn main() -> ! { |
diff --git a/examples/stm32g0/src/bin/button_exti.rs b/examples/stm32g0/src/bin/button_exti.rs index 4b1cadcb5..924feeb33 100644 --- a/examples/stm32g0/src/bin/button_exti.rs +++ b/examples/stm32g0/src/bin/button_exti.rs | |||
| @@ -3,12 +3,11 @@ | |||
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | use defmt::*; | 5 | use defmt::*; |
| 6 | use defmt_rtt as _; // global logger | ||
| 7 | use embassy::executor::Spawner; | 6 | use embassy::executor::Spawner; |
| 8 | use embassy_stm32::exti::ExtiInput; | 7 | use embassy_stm32::exti::ExtiInput; |
| 9 | use embassy_stm32::gpio::{Input, Pull}; | 8 | use embassy_stm32::gpio::{Input, Pull}; |
| 10 | use embassy_stm32::Peripherals; | 9 | use embassy_stm32::Peripherals; |
| 11 | use panic_probe as _; | 10 | use {defmt_rtt as _, panic_probe as _}; |
| 12 | 11 | ||
| 13 | #[embassy::main] | 12 | #[embassy::main] |
| 14 | async fn main(_spawner: Spawner, p: Peripherals) { | 13 | async fn main(_spawner: Spawner, p: Peripherals) { |
diff --git a/examples/stm32g4/src/bin/blinky.rs b/examples/stm32g4/src/bin/blinky.rs index 92ec2b579..cd4883276 100644 --- a/examples/stm32g4/src/bin/blinky.rs +++ b/examples/stm32g4/src/bin/blinky.rs | |||
| @@ -3,12 +3,11 @@ | |||
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | use defmt::*; | 5 | use defmt::*; |
| 6 | use defmt_rtt as _; // global logger | ||
| 7 | use embassy::executor::Spawner; | 6 | use embassy::executor::Spawner; |
| 8 | use embassy::time::{Duration, Timer}; | 7 | use embassy::time::{Duration, Timer}; |
| 9 | use embassy_stm32::gpio::{Level, Output, Speed}; | 8 | use embassy_stm32::gpio::{Level, Output, Speed}; |
| 10 | use embassy_stm32::Peripherals; | 9 | use embassy_stm32::Peripherals; |
| 11 | use panic_probe as _; | 10 | use {defmt_rtt as _, panic_probe as _}; |
| 12 | 11 | ||
| 13 | #[embassy::main] | 12 | #[embassy::main] |
| 14 | async fn main(_spawner: Spawner, p: Peripherals) { | 13 | async fn main(_spawner: Spawner, p: Peripherals) { |
diff --git a/examples/stm32g4/src/bin/button.rs b/examples/stm32g4/src/bin/button.rs index f6c981309..15abd86d9 100644 --- a/examples/stm32g4/src/bin/button.rs +++ b/examples/stm32g4/src/bin/button.rs | |||
| @@ -4,9 +4,8 @@ | |||
| 4 | 4 | ||
| 5 | use cortex_m_rt::entry; | 5 | use cortex_m_rt::entry; |
| 6 | use defmt::*; | 6 | use defmt::*; |
| 7 | use defmt_rtt as _; // global logger | ||
| 8 | use embassy_stm32::gpio::{Input, Pull}; | 7 | use embassy_stm32::gpio::{Input, Pull}; |
| 9 | use panic_probe as _; | 8 | use {defmt_rtt as _, panic_probe as _}; |
| 10 | 9 | ||
| 11 | #[entry] | 10 | #[entry] |
| 12 | fn main() -> ! { | 11 | fn main() -> ! { |
diff --git a/examples/stm32g4/src/bin/button_exti.rs b/examples/stm32g4/src/bin/button_exti.rs index 78f2e6ee2..24ece9927 100644 --- a/examples/stm32g4/src/bin/button_exti.rs +++ b/examples/stm32g4/src/bin/button_exti.rs | |||
| @@ -3,12 +3,11 @@ | |||
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | use defmt::*; | 5 | use defmt::*; |
| 6 | use defmt_rtt as _; // global logger | ||
| 7 | use embassy::executor::Spawner; | 6 | use embassy::executor::Spawner; |
| 8 | use embassy_stm32::exti::ExtiInput; | 7 | use embassy_stm32::exti::ExtiInput; |
| 9 | use embassy_stm32::gpio::{Input, Pull}; | 8 | use embassy_stm32::gpio::{Input, Pull}; |
| 10 | use embassy_stm32::Peripherals; | 9 | use embassy_stm32::Peripherals; |
| 11 | use panic_probe as _; | 10 | use {defmt_rtt as _, panic_probe as _}; |
| 12 | 11 | ||
| 13 | #[embassy::main] | 12 | #[embassy::main] |
| 14 | async fn main(_spawner: Spawner, p: Peripherals) { | 13 | async fn main(_spawner: Spawner, p: Peripherals) { |
diff --git a/examples/stm32g4/src/bin/pwm.rs b/examples/stm32g4/src/bin/pwm.rs index 3770f6f36..525b6001f 100644 --- a/examples/stm32g4/src/bin/pwm.rs +++ b/examples/stm32g4/src/bin/pwm.rs | |||
| @@ -3,13 +3,13 @@ | |||
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | use defmt::*; | 5 | use defmt::*; |
| 6 | use defmt_rtt as _; // global logger | ||
| 7 | use embassy::executor::Spawner; | 6 | use embassy::executor::Spawner; |
| 8 | use embassy::time::{Duration, Timer}; | 7 | use embassy::time::{Duration, Timer}; |
| 9 | use embassy_stm32::pwm::{simple_pwm::SimplePwm, Channel}; | 8 | use embassy_stm32::pwm::simple_pwm::SimplePwm; |
| 9 | use embassy_stm32::pwm::Channel; | ||
| 10 | use embassy_stm32::time::U32Ext; | 10 | use embassy_stm32::time::U32Ext; |
| 11 | use embassy_stm32::Peripherals; | 11 | use embassy_stm32::Peripherals; |
| 12 | use panic_probe as _; | 12 | use {defmt_rtt as _, panic_probe as _}; |
| 13 | 13 | ||
| 14 | #[embassy::main] | 14 | #[embassy::main] |
| 15 | async fn main(_spawner: Spawner, p: Peripherals) { | 15 | async fn main(_spawner: Spawner, p: Peripherals) { |
diff --git a/examples/stm32h7/src/bin/adc.rs b/examples/stm32h7/src/bin/adc.rs index b12bca307..e24390741 100644 --- a/examples/stm32h7/src/bin/adc.rs +++ b/examples/stm32h7/src/bin/adc.rs | |||
| @@ -2,16 +2,14 @@ | |||
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | use defmt::*; | ||
| 5 | use embassy::executor::Spawner; | 6 | use embassy::executor::Spawner; |
| 6 | use embassy::time::{Delay, Duration, Timer}; | 7 | use embassy::time::{Delay, Duration, Timer}; |
| 7 | use embassy_stm32::adc::{Adc, SampleTime}; | 8 | use embassy_stm32::adc::{Adc, SampleTime}; |
| 8 | use embassy_stm32::rcc::AdcClockSource; | 9 | use embassy_stm32::rcc::AdcClockSource; |
| 9 | use embassy_stm32::time::U32Ext; | 10 | use embassy_stm32::time::U32Ext; |
| 10 | use embassy_stm32::{Config, Peripherals}; | 11 | use embassy_stm32::{Config, Peripherals}; |
| 11 | 12 | use {defmt_rtt as _, panic_probe as _}; | |
| 12 | use defmt::*; | ||
| 13 | use defmt_rtt as _; // global logger | ||
| 14 | use panic_probe as _; | ||
| 15 | 13 | ||
| 16 | pub fn config() -> Config { | 14 | pub fn config() -> Config { |
| 17 | let mut config = Config::default(); | 15 | let mut config = Config::default(); |
diff --git a/examples/stm32h7/src/bin/blinky.rs b/examples/stm32h7/src/bin/blinky.rs index 2329125a6..7982f4a0b 100644 --- a/examples/stm32h7/src/bin/blinky.rs +++ b/examples/stm32h7/src/bin/blinky.rs | |||
| @@ -3,12 +3,11 @@ | |||
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | use defmt::*; | 5 | use defmt::*; |
| 6 | use defmt_rtt as _; // global logger | ||
| 7 | use embassy::executor::Spawner; | 6 | use embassy::executor::Spawner; |
| 8 | use embassy::time::{Duration, Timer}; | 7 | use embassy::time::{Duration, Timer}; |
| 9 | use embassy_stm32::gpio::{Level, Output, Speed}; | 8 | use embassy_stm32::gpio::{Level, Output, Speed}; |
| 10 | use embassy_stm32::Peripherals; | 9 | use embassy_stm32::Peripherals; |
| 11 | use panic_probe as _; | 10 | use {defmt_rtt as _, panic_probe as _}; |
| 12 | 11 | ||
| 13 | #[embassy::main] | 12 | #[embassy::main] |
| 14 | async fn main(_spawner: Spawner, p: Peripherals) { | 13 | async fn main(_spawner: Spawner, p: Peripherals) { |
diff --git a/examples/stm32h7/src/bin/button_exti.rs b/examples/stm32h7/src/bin/button_exti.rs index 78f2e6ee2..24ece9927 100644 --- a/examples/stm32h7/src/bin/button_exti.rs +++ b/examples/stm32h7/src/bin/button_exti.rs | |||
| @@ -3,12 +3,11 @@ | |||
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | use defmt::*; | 5 | use defmt::*; |
| 6 | use defmt_rtt as _; // global logger | ||
| 7 | use embassy::executor::Spawner; | 6 | use embassy::executor::Spawner; |
| 8 | use embassy_stm32::exti::ExtiInput; | 7 | use embassy_stm32::exti::ExtiInput; |
| 9 | use embassy_stm32::gpio::{Input, Pull}; | 8 | use embassy_stm32::gpio::{Input, Pull}; |
| 10 | use embassy_stm32::Peripherals; | 9 | use embassy_stm32::Peripherals; |
| 11 | use panic_probe as _; | 10 | use {defmt_rtt as _, panic_probe as _}; |
| 12 | 11 | ||
| 13 | #[embassy::main] | 12 | #[embassy::main] |
| 14 | async fn main(_spawner: Spawner, p: Peripherals) { | 13 | async fn main(_spawner: Spawner, p: Peripherals) { |
diff --git a/examples/stm32h7/src/bin/camera.rs b/examples/stm32h7/src/bin/camera.rs index 3311ba858..918eab659 100644 --- a/examples/stm32h7/src/bin/camera.rs +++ b/examples/stm32h7/src/bin/camera.rs | |||
| @@ -7,14 +7,10 @@ use embassy::time::{Duration, Timer}; | |||
| 7 | use embassy_stm32::dcmi::{self, *}; | 7 | use embassy_stm32::dcmi::{self, *}; |
| 8 | use embassy_stm32::gpio::{Level, Output, Speed}; | 8 | use embassy_stm32::gpio::{Level, Output, Speed}; |
| 9 | use embassy_stm32::i2c::I2c; | 9 | use embassy_stm32::i2c::I2c; |
| 10 | use embassy_stm32::interrupt; | ||
| 11 | use embassy_stm32::rcc::{Mco, Mco1Source, McoClock}; | 10 | use embassy_stm32::rcc::{Mco, Mco1Source, McoClock}; |
| 12 | use embassy_stm32::time::U32Ext; | 11 | use embassy_stm32::time::U32Ext; |
| 13 | use embassy_stm32::Config; | 12 | use embassy_stm32::{interrupt, Config, Peripherals}; |
| 14 | use embassy_stm32::Peripherals; | 13 | use {defmt_rtt as _, panic_probe as _}; |
| 15 | |||
| 16 | use defmt_rtt as _; // global logger | ||
| 17 | use panic_probe as _; | ||
| 18 | 14 | ||
| 19 | #[allow(unused)] | 15 | #[allow(unused)] |
| 20 | pub fn config() -> Config { | 16 | pub fn config() -> Config { |
| @@ -43,15 +39,7 @@ async fn main(_spawner: Spawner, p: Peripherals) { | |||
| 43 | 39 | ||
| 44 | let mut led = Output::new(p.PE3, Level::High, Speed::Low); | 40 | let mut led = Output::new(p.PE3, Level::High, Speed::Low); |
| 45 | let i2c_irq = interrupt::take!(I2C1_EV); | 41 | let i2c_irq = interrupt::take!(I2C1_EV); |
| 46 | let cam_i2c = I2c::new( | 42 | let cam_i2c = I2c::new(p.I2C1, p.PB8, p.PB9, i2c_irq, p.DMA1_CH1, p.DMA1_CH2, 100u32.khz()); |
| 47 | p.I2C1, | ||
| 48 | p.PB8, | ||
| 49 | p.PB9, | ||
| 50 | i2c_irq, | ||
| 51 | p.DMA1_CH1, | ||
| 52 | p.DMA1_CH2, | ||
| 53 | 100u32.khz(), | ||
| 54 | ); | ||
| 55 | 43 | ||
| 56 | let mut camera = Ov7725::new(cam_i2c, mco); | 44 | let mut camera = Ov7725::new(cam_i2c, mco); |
| 57 | 45 | ||
| @@ -60,17 +48,13 @@ async fn main(_spawner: Spawner, p: Peripherals) { | |||
| 60 | let manufacturer_id = defmt::unwrap!(camera.read_manufacturer_id().await); | 48 | let manufacturer_id = defmt::unwrap!(camera.read_manufacturer_id().await); |
| 61 | let camera_id = defmt::unwrap!(camera.read_product_id().await); | 49 | let camera_id = defmt::unwrap!(camera.read_product_id().await); |
| 62 | 50 | ||
| 63 | defmt::info!( | 51 | defmt::info!("manufacturer: 0x{:x}, pid: 0x{:x}", manufacturer_id, camera_id); |
| 64 | "manufacturer: 0x{:x}, pid: 0x{:x}", | ||
| 65 | manufacturer_id, | ||
| 66 | camera_id | ||
| 67 | ); | ||
| 68 | 52 | ||
| 69 | let dcmi_irq = interrupt::take!(DCMI); | 53 | let dcmi_irq = interrupt::take!(DCMI); |
| 70 | let config = dcmi::Config::default(); | 54 | let config = dcmi::Config::default(); |
| 71 | let mut dcmi = Dcmi::new_8bit( | 55 | let mut dcmi = Dcmi::new_8bit( |
| 72 | p.DCMI, p.DMA1_CH0, dcmi_irq, p.PC6, p.PC7, p.PE0, p.PE1, p.PE4, p.PD3, p.PE5, p.PE6, | 56 | p.DCMI, p.DMA1_CH0, dcmi_irq, p.PC6, p.PC7, p.PE0, p.PE1, p.PE4, p.PD3, p.PE5, p.PE6, p.PB7, p.PA4, p.PA6, |
| 73 | p.PB7, p.PA4, p.PA6, config, | 57 | config, |
| 74 | ); | 58 | ); |
| 75 | 59 | ||
| 76 | defmt::info!("attempting capture"); | 60 | defmt::info!("attempting capture"); |
| @@ -258,10 +242,8 @@ mod ov7725 { | |||
| 258 | let com3 = self.read(Register::Com3).await?; | 242 | let com3 = self.read(Register::Com3).await?; |
| 259 | let vflip = com3 & 0x80 > 0; | 243 | let vflip = com3 & 0x80 > 0; |
| 260 | 244 | ||
| 261 | self.modify(Register::HRef, |reg| { | 245 | self.modify(Register::HRef, |reg| reg & 0xbf | if vflip { 0x40 } else { 0x40 }) |
| 262 | reg & 0xbf | if vflip { 0x40 } else { 0x40 } | 246 | .await?; |
| 263 | }) | ||
| 264 | .await?; | ||
| 265 | 247 | ||
| 266 | if horizontal <= 320 || vertical <= 240 { | 248 | if horizontal <= 320 || vertical <= 240 { |
| 267 | self.write(Register::HStart, 0x3f).await?; | 249 | self.write(Register::HStart, 0x3f).await?; |
| @@ -291,11 +273,7 @@ mod ov7725 { | |||
| 291 | .map_err(Error::I2c) | 273 | .map_err(Error::I2c) |
| 292 | } | 274 | } |
| 293 | 275 | ||
| 294 | async fn modify<F: FnOnce(u8) -> u8>( | 276 | async fn modify<F: FnOnce(u8) -> u8>(&mut self, register: Register, f: F) -> Result<(), Error<Bus::Error>> { |
| 295 | &mut self, | ||
| 296 | register: Register, | ||
| 297 | f: F, | ||
| 298 | ) -> Result<(), Error<Bus::Error>> { | ||
| 299 | let value = self.read(register).await?; | 277 | let value = self.read(register).await?; |
| 300 | let value = f(value); | 278 | let value = f(value); |
| 301 | self.write(register, value).await | 279 | self.write(register, value).await |
diff --git a/examples/stm32h7/src/bin/dac.rs b/examples/stm32h7/src/bin/dac.rs index 86c874a6a..8ed33350c 100644 --- a/examples/stm32h7/src/bin/dac.rs +++ b/examples/stm32h7/src/bin/dac.rs | |||
| @@ -2,14 +2,12 @@ | |||
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | use defmt_rtt as _; // global logger | ||
| 6 | use panic_probe as _; | ||
| 7 | |||
| 8 | use cortex_m_rt::entry; | 5 | use cortex_m_rt::entry; |
| 9 | use defmt::*; | 6 | use defmt::*; |
| 10 | use embassy_stm32::dac::{Channel, Dac, Value}; | 7 | use embassy_stm32::dac::{Channel, Dac, Value}; |
| 11 | use embassy_stm32::time::U32Ext; | 8 | use embassy_stm32::time::U32Ext; |
| 12 | use embassy_stm32::Config; | 9 | use embassy_stm32::Config; |
| 10 | use {defmt_rtt as _, panic_probe as _}; | ||
| 13 | 11 | ||
| 14 | pub fn config() -> Config { | 12 | pub fn config() -> Config { |
| 15 | let mut config = Config::default(); | 13 | let mut config = Config::default(); |
diff --git a/examples/stm32h7/src/bin/eth.rs b/examples/stm32h7/src/bin/eth.rs index 649ff2605..6dabadc4b 100644 --- a/examples/stm32h7/src/bin/eth.rs +++ b/examples/stm32h7/src/bin/eth.rs | |||
| @@ -13,13 +13,10 @@ use embassy_stm32::eth::{Ethernet, State}; | |||
| 13 | use embassy_stm32::peripherals::ETH; | 13 | use embassy_stm32::peripherals::ETH; |
| 14 | use embassy_stm32::rng::Rng; | 14 | use embassy_stm32::rng::Rng; |
| 15 | use embassy_stm32::time::U32Ext; | 15 | use embassy_stm32::time::U32Ext; |
| 16 | use embassy_stm32::Config; | 16 | use embassy_stm32::{interrupt, Config, Peripherals}; |
| 17 | use embassy_stm32::{interrupt, Peripherals}; | ||
| 18 | use embedded_io::asynch::Write; | 17 | use embedded_io::asynch::Write; |
| 19 | |||
| 20 | use defmt_rtt as _; // global logger | ||
| 21 | use panic_probe as _; | ||
| 22 | use rand_core::RngCore; | 18 | use rand_core::RngCore; |
| 19 | use {defmt_rtt as _, panic_probe as _}; | ||
| 23 | 20 | ||
| 24 | macro_rules! forever { | 21 | macro_rules! forever { |
| 25 | ($val:expr) => {{ | 22 | ($val:expr) => {{ |
diff --git a/examples/stm32h7/src/bin/flash.rs b/examples/stm32h7/src/bin/flash.rs index b008c0884..5f97d2b31 100644 --- a/examples/stm32h7/src/bin/flash.rs +++ b/examples/stm32h7/src/bin/flash.rs | |||
| @@ -3,13 +3,12 @@ | |||
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | use defmt::{info, unwrap}; | 5 | use defmt::{info, unwrap}; |
| 6 | use defmt_rtt as _; // global logger | ||
| 7 | use embassy::executor::Spawner; | 6 | use embassy::executor::Spawner; |
| 8 | use embassy::time::{Duration, Timer}; | 7 | use embassy::time::{Duration, Timer}; |
| 9 | use embassy_stm32::flash::Flash; | 8 | use embassy_stm32::flash::Flash; |
| 10 | use embassy_stm32::Peripherals; | 9 | use embassy_stm32::Peripherals; |
| 11 | use embedded_storage::nor_flash::{NorFlash, ReadNorFlash}; | 10 | use embedded_storage::nor_flash::{NorFlash, ReadNorFlash}; |
| 12 | use panic_probe as _; | 11 | use {defmt_rtt as _, panic_probe as _}; |
| 13 | 12 | ||
| 14 | #[embassy::main] | 13 | #[embassy::main] |
| 15 | async fn main(_spawner: Spawner, p: Peripherals) { | 14 | async fn main(_spawner: Spawner, p: Peripherals) { |
| @@ -39,8 +38,8 @@ async fn main(_spawner: Spawner, p: Peripherals) { | |||
| 39 | unwrap!(f.write( | 38 | unwrap!(f.write( |
| 40 | ADDR, | 39 | ADDR, |
| 41 | &[ | 40 | &[ |
| 42 | 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, | 41 | 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, |
| 43 | 25, 26, 27, 28, 29, 30, 31, 32 | 42 | 30, 31, 32 |
| 44 | ] | 43 | ] |
| 45 | )); | 44 | )); |
| 46 | 45 | ||
| @@ -51,8 +50,8 @@ async fn main(_spawner: Spawner, p: Peripherals) { | |||
| 51 | assert_eq!( | 50 | assert_eq!( |
| 52 | &buf[..], | 51 | &buf[..], |
| 53 | &[ | 52 | &[ |
| 54 | 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, | 53 | 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, |
| 55 | 25, 26, 27, 28, 29, 30, 31, 32 | 54 | 30, 31, 32 |
| 56 | ] | 55 | ] |
| 57 | ); | 56 | ); |
| 58 | } | 57 | } |
diff --git a/examples/stm32h7/src/bin/fmc.rs b/examples/stm32h7/src/bin/fmc.rs index ba8215d6a..2f55479c1 100644 --- a/examples/stm32h7/src/bin/fmc.rs +++ b/examples/stm32h7/src/bin/fmc.rs | |||
| @@ -3,14 +3,12 @@ | |||
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | use defmt::*; | 5 | use defmt::*; |
| 6 | use defmt_rtt as _; // global logger | ||
| 7 | use embassy::executor::Spawner; | 6 | use embassy::executor::Spawner; |
| 8 | use embassy::time::{Delay, Duration, Timer}; | 7 | use embassy::time::{Delay, Duration, Timer}; |
| 9 | use embassy_stm32::fmc::Fmc; | 8 | use embassy_stm32::fmc::Fmc; |
| 10 | use embassy_stm32::time::U32Ext; | 9 | use embassy_stm32::time::U32Ext; |
| 11 | use embassy_stm32::Config; | 10 | use embassy_stm32::{Config, Peripherals}; |
| 12 | use embassy_stm32::Peripherals; | 11 | use {defmt_rtt as _, panic_probe as _}; |
| 13 | use panic_probe as _; | ||
| 14 | 12 | ||
| 15 | pub fn config() -> Config { | 13 | pub fn config() -> Config { |
| 16 | let mut config = Config::default(); | 14 | let mut config = Config::default(); |
| @@ -62,16 +60,8 @@ async fn main(_spawner: Spawner, p: Peripherals) { | |||
| 62 | const REGION_WRITE_BACK: u32 = 0x01; | 60 | const REGION_WRITE_BACK: u32 = 0x01; |
| 63 | const REGION_ENABLE: u32 = 0x01; | 61 | const REGION_ENABLE: u32 = 0x01; |
| 64 | 62 | ||
| 65 | crate::assert_eq!( | 63 | crate::assert_eq!(size & (size - 1), 0, "SDRAM memory region size must be a power of 2"); |
| 66 | size & (size - 1), | 64 | crate::assert_eq!(size & 0x1F, 0, "SDRAM memory region size must be 32 bytes or more"); |
| 67 | 0, | ||
| 68 | "SDRAM memory region size must be a power of 2" | ||
| 69 | ); | ||
| 70 | crate::assert_eq!( | ||
| 71 | size & 0x1F, | ||
| 72 | 0, | ||
| 73 | "SDRAM memory region size must be 32 bytes or more" | ||
| 74 | ); | ||
| 75 | fn log2minus1(sz: u32) -> u32 { | 65 | fn log2minus1(sz: u32) -> u32 { |
| 76 | for i in 5..=31 { | 66 | for i in 5..=31 { |
| 77 | if sz == (1 << i) { | 67 | if sz == (1 << i) { |
| @@ -104,8 +94,7 @@ async fn main(_spawner: Spawner, p: Peripherals) { | |||
| 104 | 94 | ||
| 105 | // Enable | 95 | // Enable |
| 106 | unsafe { | 96 | unsafe { |
| 107 | mpu.ctrl | 97 | mpu.ctrl.modify(|r| r | MPU_DEFAULT_MMAP_FOR_PRIVILEGED | MPU_ENABLE); |
| 108 | .modify(|r| r | MPU_DEFAULT_MMAP_FOR_PRIVILEGED | MPU_ENABLE); | ||
| 109 | 98 | ||
| 110 | scb.shcsr.modify(|r| r | MEMFAULTENA); | 99 | scb.shcsr.modify(|r| r | MEMFAULTENA); |
| 111 | 100 | ||
diff --git a/examples/stm32h7/src/bin/low_level_timer_api.rs b/examples/stm32h7/src/bin/low_level_timer_api.rs index 647c5a8fa..3a728a0dd 100644 --- a/examples/stm32h7/src/bin/low_level_timer_api.rs +++ b/examples/stm32h7/src/bin/low_level_timer_api.rs | |||
| @@ -3,8 +3,6 @@ | |||
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | use core::marker::PhantomData; | 5 | use core::marker::PhantomData; |
| 6 | use defmt_rtt as _; // global logger | ||
| 7 | use panic_probe as _; | ||
| 8 | 6 | ||
| 9 | use defmt::*; | 7 | use defmt::*; |
| 10 | use embassy::executor::Spawner; | 8 | use embassy::executor::Spawner; |
| @@ -13,9 +11,8 @@ use embassy_stm32::gpio::low_level::AFType; | |||
| 13 | use embassy_stm32::gpio::Speed; | 11 | use embassy_stm32::gpio::Speed; |
| 14 | use embassy_stm32::pwm::*; | 12 | use embassy_stm32::pwm::*; |
| 15 | use embassy_stm32::time::{Hertz, U32Ext}; | 13 | use embassy_stm32::time::{Hertz, U32Ext}; |
| 16 | use embassy_stm32::unborrow; | 14 | use embassy_stm32::{unborrow, Config, Peripherals, Unborrow}; |
| 17 | use embassy_stm32::Unborrow; | 15 | use {defmt_rtt as _, panic_probe as _}; |
| 18 | use embassy_stm32::{Config, Peripherals}; | ||
| 19 | 16 | ||
| 20 | pub fn config() -> Config { | 17 | pub fn config() -> Config { |
| 21 | let mut config = Config::default(); | 18 | let mut config = Config::default(); |
| @@ -108,25 +105,18 @@ impl<'d, T: CaptureCompare32bitInstance> SimplePwm32<'d, T> { | |||
| 108 | 105 | ||
| 109 | pub fn enable(&mut self, channel: Channel) { | 106 | pub fn enable(&mut self, channel: Channel) { |
| 110 | unsafe { | 107 | unsafe { |
| 111 | T::regs_gp32() | 108 | T::regs_gp32().ccer().modify(|w| w.set_cce(channel.raw(), true)); |
| 112 | .ccer() | ||
| 113 | .modify(|w| w.set_cce(channel.raw(), true)); | ||
| 114 | } | 109 | } |
| 115 | } | 110 | } |
| 116 | 111 | ||
| 117 | pub fn disable(&mut self, channel: Channel) { | 112 | pub fn disable(&mut self, channel: Channel) { |
| 118 | unsafe { | 113 | unsafe { |
| 119 | T::regs_gp32() | 114 | T::regs_gp32().ccer().modify(|w| w.set_cce(channel.raw(), false)); |
| 120 | .ccer() | ||
| 121 | .modify(|w| w.set_cce(channel.raw(), false)); | ||
| 122 | } | 115 | } |
| 123 | } | 116 | } |
| 124 | 117 | ||
| 125 | pub fn set_freq<F: Into<Hertz>>(&mut self, freq: F) { | 118 | pub fn set_freq<F: Into<Hertz>>(&mut self, freq: F) { |
| 126 | <T as embassy_stm32::timer::low_level::GeneralPurpose32bitInstance>::set_frequency( | 119 | <T as embassy_stm32::timer::low_level::GeneralPurpose32bitInstance>::set_frequency(&mut self.inner, freq); |
| 127 | &mut self.inner, | ||
| 128 | freq, | ||
| 129 | ); | ||
| 130 | } | 120 | } |
| 131 | 121 | ||
| 132 | pub fn get_max_duty(&self) -> u32 { | 122 | pub fn get_max_duty(&self) -> u32 { |
| @@ -135,10 +125,6 @@ impl<'d, T: CaptureCompare32bitInstance> SimplePwm32<'d, T> { | |||
| 135 | 125 | ||
| 136 | pub fn set_duty(&mut self, channel: Channel, duty: u32) { | 126 | pub fn set_duty(&mut self, channel: Channel, duty: u32) { |
| 137 | defmt::assert!(duty < self.get_max_duty()); | 127 | defmt::assert!(duty < self.get_max_duty()); |
| 138 | unsafe { | 128 | unsafe { T::regs_gp32().ccr(channel.raw()).modify(|w| w.set_ccr(duty)) } |
| 139 | T::regs_gp32() | ||
| 140 | .ccr(channel.raw()) | ||
| 141 | .modify(|w| w.set_ccr(duty)) | ||
| 142 | } | ||
| 143 | } | 129 | } |
| 144 | } | 130 | } |
diff --git a/examples/stm32h7/src/bin/mco.rs b/examples/stm32h7/src/bin/mco.rs index a6735036f..6f03b5479 100644 --- a/examples/stm32h7/src/bin/mco.rs +++ b/examples/stm32h7/src/bin/mco.rs | |||
| @@ -3,13 +3,12 @@ | |||
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | use defmt::*; | 5 | use defmt::*; |
| 6 | use defmt_rtt as _; // global logger | ||
| 7 | use embassy::executor::Spawner; | 6 | use embassy::executor::Spawner; |
| 8 | use embassy::time::{Duration, Timer}; | 7 | use embassy::time::{Duration, Timer}; |
| 9 | use embassy_stm32::gpio::{Level, Output, Speed}; | 8 | use embassy_stm32::gpio::{Level, Output, Speed}; |
| 10 | use embassy_stm32::rcc::{Mco, Mco1Source, McoClock}; | 9 | use embassy_stm32::rcc::{Mco, Mco1Source, McoClock}; |
| 11 | use embassy_stm32::Peripherals; | 10 | use embassy_stm32::Peripherals; |
| 12 | use panic_probe as _; | 11 | use {defmt_rtt as _, panic_probe as _}; |
| 13 | 12 | ||
| 14 | #[embassy::main] | 13 | #[embassy::main] |
| 15 | async fn main(_spawner: Spawner, p: Peripherals) { | 14 | async fn main(_spawner: Spawner, p: Peripherals) { |
diff --git a/examples/stm32h7/src/bin/pwm.rs b/examples/stm32h7/src/bin/pwm.rs index c33ba066e..0e85b8d80 100644 --- a/examples/stm32h7/src/bin/pwm.rs +++ b/examples/stm32h7/src/bin/pwm.rs | |||
| @@ -3,13 +3,13 @@ | |||
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | use defmt::*; | 5 | use defmt::*; |
| 6 | use defmt_rtt as _; // global logger | ||
| 7 | use embassy::executor::Spawner; | 6 | use embassy::executor::Spawner; |
| 8 | use embassy::time::{Duration, Timer}; | 7 | use embassy::time::{Duration, Timer}; |
| 9 | use embassy_stm32::pwm::{simple_pwm::SimplePwm, Channel}; | 8 | use embassy_stm32::pwm::simple_pwm::SimplePwm; |
| 9 | use embassy_stm32::pwm::Channel; | ||
| 10 | use embassy_stm32::time::U32Ext; | 10 | use embassy_stm32::time::U32Ext; |
| 11 | use embassy_stm32::{Config, Peripherals}; | 11 | use embassy_stm32::{Config, Peripherals}; |
| 12 | use panic_probe as _; | 12 | use {defmt_rtt as _, panic_probe as _}; |
| 13 | 13 | ||
| 14 | pub fn config() -> Config { | 14 | pub fn config() -> Config { |
| 15 | let mut config = Config::default(); | 15 | let mut config = Config::default(); |
diff --git a/examples/stm32h7/src/bin/rng.rs b/examples/stm32h7/src/bin/rng.rs index b914fa709..2b42a6afd 100644 --- a/examples/stm32h7/src/bin/rng.rs +++ b/examples/stm32h7/src/bin/rng.rs | |||
| @@ -3,11 +3,10 @@ | |||
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | use defmt::*; | 5 | use defmt::*; |
| 6 | use defmt_rtt as _; // global logger | ||
| 7 | use embassy::executor::Spawner; | 6 | use embassy::executor::Spawner; |
| 8 | use embassy_stm32::rng::Rng; | 7 | use embassy_stm32::rng::Rng; |
| 9 | use embassy_stm32::Peripherals; | 8 | use embassy_stm32::Peripherals; |
| 10 | use panic_probe as _; | 9 | use {defmt_rtt as _, panic_probe as _}; |
| 11 | 10 | ||
| 12 | #[embassy::main] | 11 | #[embassy::main] |
| 13 | async fn main(_spawner: Spawner, p: Peripherals) { | 12 | async fn main(_spawner: Spawner, p: Peripherals) { |
diff --git a/examples/stm32h7/src/bin/sdmmc.rs b/examples/stm32h7/src/bin/sdmmc.rs index c3b2ebcda..4a74780f4 100644 --- a/examples/stm32h7/src/bin/sdmmc.rs +++ b/examples/stm32h7/src/bin/sdmmc.rs | |||
| @@ -2,14 +2,12 @@ | |||
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | use defmt_rtt as _; // global logger | ||
| 6 | use panic_probe as _; | ||
| 7 | |||
| 8 | use defmt::*; | 5 | use defmt::*; |
| 9 | use embassy::executor::Spawner; | 6 | use embassy::executor::Spawner; |
| 10 | use embassy_stm32::sdmmc::Sdmmc; | 7 | use embassy_stm32::sdmmc::Sdmmc; |
| 11 | use embassy_stm32::time::U32Ext; | 8 | use embassy_stm32::time::U32Ext; |
| 12 | use embassy_stm32::{interrupt, Config, Peripherals}; | 9 | use embassy_stm32::{interrupt, Config, Peripherals}; |
| 10 | use {defmt_rtt as _, panic_probe as _}; | ||
| 13 | 11 | ||
| 14 | fn config() -> Config { | 12 | fn config() -> Config { |
| 15 | let mut config = Config::default(); | 13 | let mut config = Config::default(); |
diff --git a/examples/stm32h7/src/bin/signal.rs b/examples/stm32h7/src/bin/signal.rs index c63b2836c..f798b1c92 100644 --- a/examples/stm32h7/src/bin/signal.rs +++ b/examples/stm32h7/src/bin/signal.rs | |||
| @@ -2,17 +2,12 @@ | |||
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | // global logger | ||
| 6 | use defmt::{info, unwrap}; | 5 | use defmt::{info, unwrap}; |
| 7 | use defmt_rtt as _; | ||
| 8 | |||
| 9 | use panic_probe as _; | ||
| 10 | |||
| 11 | use embassy::channel::signal::Signal; | 6 | use embassy::channel::signal::Signal; |
| 12 | use embassy::executor::Spawner; | 7 | use embassy::executor::Spawner; |
| 13 | use embassy::time::{Duration, Timer}; | 8 | use embassy::time::{Duration, Timer}; |
| 14 | |||
| 15 | use embassy_stm32::Peripherals; | 9 | use embassy_stm32::Peripherals; |
| 10 | use {defmt_rtt as _, panic_probe as _}; | ||
| 16 | 11 | ||
| 17 | static SIGNAL: Signal<u32> = Signal::new(); | 12 | static SIGNAL: Signal<u32> = Signal::new(); |
| 18 | 13 | ||
diff --git a/examples/stm32h7/src/bin/spi.rs b/examples/stm32h7/src/bin/spi.rs index a0acb03db..d4ee44292 100644 --- a/examples/stm32h7/src/bin/spi.rs +++ b/examples/stm32h7/src/bin/spi.rs | |||
| @@ -2,21 +2,19 @@ | |||
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | use defmt_rtt as _; // global logger | ||
| 6 | use panic_probe as _; | ||
| 7 | |||
| 8 | use core::fmt::Write; | 5 | use core::fmt::Write; |
| 9 | use core::str::from_utf8; | 6 | use core::str::from_utf8; |
| 7 | |||
| 10 | use cortex_m_rt::entry; | 8 | use cortex_m_rt::entry; |
| 11 | use defmt::*; | 9 | use defmt::*; |
| 12 | use embassy::executor::Executor; | 10 | use embassy::executor::Executor; |
| 13 | use embassy::util::Forever; | 11 | use embassy::util::Forever; |
| 14 | use embassy_stm32::dma::NoDma; | 12 | use embassy_stm32::dma::NoDma; |
| 15 | use embassy_stm32::peripherals::SPI3; | 13 | use embassy_stm32::peripherals::SPI3; |
| 16 | use embassy_stm32::spi; | ||
| 17 | use embassy_stm32::time::U32Ext; | 14 | use embassy_stm32::time::U32Ext; |
| 18 | use embassy_stm32::Config; | 15 | use embassy_stm32::{spi, Config}; |
| 19 | use heapless::String; | 16 | use heapless::String; |
| 17 | use {defmt_rtt as _, panic_probe as _}; | ||
| 20 | 18 | ||
| 21 | pub fn config() -> Config { | 19 | pub fn config() -> Config { |
| 22 | let mut config = Config::default(); | 20 | let mut config = Config::default(); |
diff --git a/examples/stm32h7/src/bin/spi_dma.rs b/examples/stm32h7/src/bin/spi_dma.rs index 8f77b1d09..003bc7add 100644 --- a/examples/stm32h7/src/bin/spi_dma.rs +++ b/examples/stm32h7/src/bin/spi_dma.rs | |||
| @@ -2,20 +2,18 @@ | |||
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | use defmt_rtt as _; // global logger | ||
| 6 | use panic_probe as _; | ||
| 7 | |||
| 8 | use core::fmt::Write; | 5 | use core::fmt::Write; |
| 9 | use core::str::from_utf8; | 6 | use core::str::from_utf8; |
| 7 | |||
| 10 | use cortex_m_rt::entry; | 8 | use cortex_m_rt::entry; |
| 11 | use defmt::*; | 9 | use defmt::*; |
| 12 | use embassy::executor::Executor; | 10 | use embassy::executor::Executor; |
| 13 | use embassy::util::Forever; | 11 | use embassy::util::Forever; |
| 14 | use embassy_stm32::peripherals::{DMA1_CH3, DMA1_CH4, SPI3}; | 12 | use embassy_stm32::peripherals::{DMA1_CH3, DMA1_CH4, SPI3}; |
| 15 | use embassy_stm32::spi; | ||
| 16 | use embassy_stm32::time::U32Ext; | 13 | use embassy_stm32::time::U32Ext; |
| 17 | use embassy_stm32::Config; | 14 | use embassy_stm32::{spi, Config}; |
| 18 | use heapless::String; | 15 | use heapless::String; |
| 16 | use {defmt_rtt as _, panic_probe as _}; | ||
| 19 | 17 | ||
| 20 | pub fn config() -> Config { | 18 | pub fn config() -> Config { |
| 21 | let mut config = Config::default(); | 19 | let mut config = Config::default(); |
diff --git a/examples/stm32h7/src/bin/usart.rs b/examples/stm32h7/src/bin/usart.rs index 0982a6ac6..fc3db5a33 100644 --- a/examples/stm32h7/src/bin/usart.rs +++ b/examples/stm32h7/src/bin/usart.rs | |||
| @@ -2,15 +2,13 @@ | |||
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | use cortex_m_rt::entry; | ||
| 5 | use defmt::*; | 6 | use defmt::*; |
| 6 | use defmt_rtt as _; // global logger | ||
| 7 | use embassy::executor::Executor; | 7 | use embassy::executor::Executor; |
| 8 | use embassy::util::Forever; | 8 | use embassy::util::Forever; |
| 9 | use embassy_stm32::dma::NoDma; | 9 | use embassy_stm32::dma::NoDma; |
| 10 | use embassy_stm32::usart::{Config, Uart}; | 10 | use embassy_stm32::usart::{Config, Uart}; |
| 11 | use panic_probe as _; | 11 | use {defmt_rtt as _, panic_probe as _}; |
| 12 | |||
| 13 | use cortex_m_rt::entry; | ||
| 14 | 12 | ||
| 15 | #[embassy::task] | 13 | #[embassy::task] |
| 16 | async fn main_task() { | 14 | async fn main_task() { |
diff --git a/examples/stm32h7/src/bin/usart_dma.rs b/examples/stm32h7/src/bin/usart_dma.rs index 74de8b2a3..d3325b0c1 100644 --- a/examples/stm32h7/src/bin/usart_dma.rs +++ b/examples/stm32h7/src/bin/usart_dma.rs | |||
| @@ -3,16 +3,15 @@ | |||
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | use core::fmt::Write; | 5 | use core::fmt::Write; |
| 6 | |||
| 7 | use cortex_m_rt::entry; | ||
| 6 | use defmt::*; | 8 | use defmt::*; |
| 7 | use defmt_rtt as _; // global logger | ||
| 8 | use embassy::executor::Executor; | 9 | use embassy::executor::Executor; |
| 9 | use embassy::util::Forever; | 10 | use embassy::util::Forever; |
| 10 | use embassy_stm32::dma::NoDma; | 11 | use embassy_stm32::dma::NoDma; |
| 11 | use embassy_stm32::usart::{Config, Uart}; | 12 | use embassy_stm32::usart::{Config, Uart}; |
| 12 | use panic_probe as _; | ||
| 13 | |||
| 14 | use cortex_m_rt::entry; | ||
| 15 | use heapless::String; | 13 | use heapless::String; |
| 14 | use {defmt_rtt as _, panic_probe as _}; | ||
| 16 | 15 | ||
| 17 | #[embassy::task] | 16 | #[embassy::task] |
| 18 | async fn main_task() { | 17 | async fn main_task() { |
diff --git a/examples/stm32h7/src/bin/usart_split.rs b/examples/stm32h7/src/bin/usart_split.rs index eb3f9578c..678d8c911 100644 --- a/examples/stm32h7/src/bin/usart_split.rs +++ b/examples/stm32h7/src/bin/usart_split.rs | |||
| @@ -3,17 +3,14 @@ | |||
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | use defmt::*; | 5 | use defmt::*; |
| 6 | use defmt_rtt as _; // global logger | ||
| 7 | use embassy::blocking_mutex::raw::ThreadModeRawMutex; | 6 | use embassy::blocking_mutex::raw::ThreadModeRawMutex; |
| 8 | use embassy::channel::mpmc::Channel; | 7 | use embassy::channel::mpmc::Channel; |
| 9 | use embassy::executor::Spawner; | 8 | use embassy::executor::Spawner; |
| 10 | use embassy_stm32::dma::NoDma; | 9 | use embassy_stm32::dma::NoDma; |
| 11 | use embassy_stm32::{ | 10 | use embassy_stm32::peripherals::{DMA1_CH1, UART7}; |
| 12 | peripherals::{DMA1_CH1, UART7}, | 11 | use embassy_stm32::usart::{Config, Uart, UartRx}; |
| 13 | usart::{Config, Uart, UartRx}, | 12 | use embassy_stm32::Peripherals; |
| 14 | Peripherals, | 13 | use {defmt_rtt as _, panic_probe as _}; |
| 15 | }; | ||
| 16 | use panic_probe as _; | ||
| 17 | 14 | ||
| 18 | #[embassy::task] | 15 | #[embassy::task] |
| 19 | async fn writer(mut usart: Uart<'static, UART7, NoDma, NoDma>) { | 16 | async fn writer(mut usart: Uart<'static, UART7, NoDma, NoDma>) { |
diff --git a/examples/stm32l0/src/bin/blinky.rs b/examples/stm32l0/src/bin/blinky.rs index 72f13f06d..e027192bc 100644 --- a/examples/stm32l0/src/bin/blinky.rs +++ b/examples/stm32l0/src/bin/blinky.rs | |||
| @@ -2,14 +2,12 @@ | |||
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | use defmt_rtt as _; // global logger | ||
| 6 | use panic_probe as _; | ||
| 7 | |||
| 8 | use defmt::*; | 5 | use defmt::*; |
| 9 | use embassy::executor::Spawner; | 6 | use embassy::executor::Spawner; |
| 10 | use embassy::time::{Duration, Timer}; | 7 | use embassy::time::{Duration, Timer}; |
| 11 | use embassy_stm32::gpio::{Level, Output, Speed}; | 8 | use embassy_stm32::gpio::{Level, Output, Speed}; |
| 12 | use embassy_stm32::Peripherals; | 9 | use embassy_stm32::Peripherals; |
| 10 | use {defmt_rtt as _, panic_probe as _}; | ||
| 13 | 11 | ||
| 14 | #[embassy::main] | 12 | #[embassy::main] |
| 15 | async fn main(_spawner: Spawner, p: Peripherals) { | 13 | async fn main(_spawner: Spawner, p: Peripherals) { |
diff --git a/examples/stm32l0/src/bin/button.rs b/examples/stm32l0/src/bin/button.rs index dfa91259a..43ea8c2a5 100644 --- a/examples/stm32l0/src/bin/button.rs +++ b/examples/stm32l0/src/bin/button.rs | |||
| @@ -3,11 +3,10 @@ | |||
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | use defmt::*; | 5 | use defmt::*; |
| 6 | use defmt_rtt as _; // global logger | ||
| 7 | use embassy::executor::Spawner; | 6 | use embassy::executor::Spawner; |
| 8 | use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; | 7 | use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; |
| 9 | use embassy_stm32::Peripherals; | 8 | use embassy_stm32::Peripherals; |
| 10 | use panic_probe as _; | 9 | use {defmt_rtt as _, panic_probe as _}; |
| 11 | 10 | ||
| 12 | #[embassy::main] | 11 | #[embassy::main] |
| 13 | async fn main(_spawner: Spawner, p: Peripherals) { | 12 | async fn main(_spawner: Spawner, p: Peripherals) { |
diff --git a/examples/stm32l0/src/bin/button_exti.rs b/examples/stm32l0/src/bin/button_exti.rs index b1892e2c6..d87870a01 100644 --- a/examples/stm32l0/src/bin/button_exti.rs +++ b/examples/stm32l0/src/bin/button_exti.rs | |||
| @@ -2,14 +2,12 @@ | |||
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | use defmt_rtt as _; // global logger | ||
| 6 | use panic_probe as _; | ||
| 7 | |||
| 8 | use defmt::*; | 5 | use defmt::*; |
| 9 | use embassy::executor::Spawner; | 6 | use embassy::executor::Spawner; |
| 10 | use embassy_stm32::exti::ExtiInput; | 7 | use embassy_stm32::exti::ExtiInput; |
| 11 | use embassy_stm32::gpio::{Input, Pull}; | 8 | use embassy_stm32::gpio::{Input, Pull}; |
| 12 | use embassy_stm32::Peripherals; | 9 | use embassy_stm32::Peripherals; |
| 10 | use {defmt_rtt as _, panic_probe as _}; | ||
| 13 | 11 | ||
| 14 | fn config() -> embassy_stm32::Config { | 12 | fn config() -> embassy_stm32::Config { |
| 15 | let mut config = embassy_stm32::Config::default(); | 13 | let mut config = embassy_stm32::Config::default(); |
diff --git a/examples/stm32l0/src/bin/flash.rs b/examples/stm32l0/src/bin/flash.rs index c2ccb5b69..a2fec9291 100644 --- a/examples/stm32l0/src/bin/flash.rs +++ b/examples/stm32l0/src/bin/flash.rs | |||
| @@ -7,9 +7,7 @@ use embassy::executor::Spawner; | |||
| 7 | use embassy_stm32::flash::Flash; | 7 | use embassy_stm32::flash::Flash; |
| 8 | use embassy_stm32::Peripherals; | 8 | use embassy_stm32::Peripherals; |
| 9 | use embedded_storage::nor_flash::{NorFlash, ReadNorFlash}; | 9 | use embedded_storage::nor_flash::{NorFlash, ReadNorFlash}; |
| 10 | 10 | use {defmt_rtt as _, panic_probe as _}; | |
| 11 | use defmt_rtt as _; // global logger | ||
| 12 | use panic_probe as _; | ||
| 13 | 11 | ||
| 14 | #[embassy::main] | 12 | #[embassy::main] |
| 15 | async fn main(_spawner: Spawner, p: Peripherals) { | 13 | async fn main(_spawner: Spawner, p: Peripherals) { |
diff --git a/examples/stm32l0/src/bin/lorawan.rs b/examples/stm32l0/src/bin/lorawan.rs index c3b97de53..8b7e8f824 100644 --- a/examples/stm32l0/src/bin/lorawan.rs +++ b/examples/stm32l0/src/bin/lorawan.rs | |||
| @@ -6,20 +6,16 @@ | |||
| 6 | #![feature(generic_associated_types)] | 6 | #![feature(generic_associated_types)] |
| 7 | #![feature(type_alias_impl_trait)] | 7 | #![feature(type_alias_impl_trait)] |
| 8 | 8 | ||
| 9 | use defmt_rtt as _; // global logger | 9 | use embassy_lora::sx127x::*; |
| 10 | use panic_probe as _; | 10 | use embassy_lora::LoraTimer; |
| 11 | 11 | use embassy_stm32::exti::ExtiInput; | |
| 12 | use embassy_lora::{sx127x::*, LoraTimer}; | 12 | use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; |
| 13 | use embassy_stm32::{ | 13 | use embassy_stm32::rng::Rng; |
| 14 | exti::ExtiInput, | 14 | use embassy_stm32::time::U32Ext; |
| 15 | gpio::{Input, Level, Output, Pull, Speed}, | 15 | use embassy_stm32::{spi, Peripherals}; |
| 16 | rng::Rng, | ||
| 17 | spi, | ||
| 18 | time::U32Ext, | ||
| 19 | Peripherals, | ||
| 20 | }; | ||
| 21 | use lorawan::default_crypto::DefaultFactory as Crypto; | 16 | use lorawan::default_crypto::DefaultFactory as Crypto; |
| 22 | use lorawan_device::async_device::{region, Device, JoinMode}; | 17 | use lorawan_device::async_device::{region, Device, JoinMode}; |
| 18 | use {defmt_rtt as _, panic_probe as _}; | ||
| 23 | 19 | ||
| 24 | fn config() -> embassy_stm32::Config { | 20 | fn config() -> embassy_stm32::Config { |
| 25 | let mut config = embassy_stm32::Config::default(); | 21 | let mut config = embassy_stm32::Config::default(); |
| @@ -49,13 +45,10 @@ async fn main(_spawner: embassy::executor::Spawner, p: Peripherals) { | |||
| 49 | let ready = Input::new(p.PB4, Pull::Up); | 45 | let ready = Input::new(p.PB4, Pull::Up); |
| 50 | let ready_pin = ExtiInput::new(ready, p.EXTI4); | 46 | let ready_pin = ExtiInput::new(ready, p.EXTI4); |
| 51 | 47 | ||
| 52 | let radio = Sx127xRadio::new(spi, cs, reset, ready_pin, DummySwitch) | 48 | let radio = Sx127xRadio::new(spi, cs, reset, ready_pin, DummySwitch).await.unwrap(); |
| 53 | .await | ||
| 54 | .unwrap(); | ||
| 55 | 49 | ||
| 56 | let region = region::EU868::default().into(); | 50 | let region = region::EU868::default().into(); |
| 57 | let mut device: Device<_, Crypto, _, _> = | 51 | let mut device: Device<_, Crypto, _, _> = Device::new(region, radio, LoraTimer, Rng::new(p.RNG)); |
| 58 | Device::new(region, radio, LoraTimer, Rng::new(p.RNG)); | ||
| 59 | 52 | ||
| 60 | defmt::info!("Joining LoRaWAN network"); | 53 | defmt::info!("Joining LoRaWAN network"); |
| 61 | 54 | ||
diff --git a/examples/stm32l0/src/bin/raw_spawn.rs b/examples/stm32l0/src/bin/raw_spawn.rs index 4601d85df..dfe2cddb6 100644 --- a/examples/stm32l0/src/bin/raw_spawn.rs +++ b/examples/stm32l0/src/bin/raw_spawn.rs | |||
| @@ -1,17 +1,15 @@ | |||
| 1 | #![no_std] | 1 | #![no_std] |
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | 3 | ||
| 4 | use defmt::*; | ||
| 5 | use defmt_rtt as _; // global logger | ||
| 6 | use panic_probe as _; | ||
| 7 | |||
| 8 | use core::mem; | 4 | use core::mem; |
| 9 | use cortex_m_rt::entry; | ||
| 10 | 5 | ||
| 6 | use cortex_m_rt::entry; | ||
| 7 | use defmt::*; | ||
| 11 | use embassy::executor::raw::TaskStorage; | 8 | use embassy::executor::raw::TaskStorage; |
| 12 | use embassy::executor::Executor; | 9 | use embassy::executor::Executor; |
| 13 | use embassy::time::{Duration, Timer}; | 10 | use embassy::time::{Duration, Timer}; |
| 14 | use embassy::util::Forever; | 11 | use embassy::util::Forever; |
| 12 | use {defmt_rtt as _, panic_probe as _}; | ||
| 15 | 13 | ||
| 16 | async fn run1() { | 14 | async fn run1() { |
| 17 | loop { | 15 | loop { |
diff --git a/examples/stm32l0/src/bin/spi.rs b/examples/stm32l0/src/bin/spi.rs index 5ed783b10..dba0b281d 100644 --- a/examples/stm32l0/src/bin/spi.rs +++ b/examples/stm32l0/src/bin/spi.rs | |||
| @@ -2,17 +2,14 @@ | |||
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | use defmt_rtt as _; // global logger | ||
| 6 | use panic_probe as _; | ||
| 7 | |||
| 8 | use defmt::*; | 5 | use defmt::*; |
| 9 | use embassy::executor::Spawner; | 6 | use embassy::executor::Spawner; |
| 10 | use embassy_stm32::gpio::{Level, Output, Speed}; | ||
| 11 | |||
| 12 | use embassy_stm32::dma::NoDma; | 7 | use embassy_stm32::dma::NoDma; |
| 8 | use embassy_stm32::gpio::{Level, Output, Speed}; | ||
| 13 | use embassy_stm32::spi::{Config, Spi}; | 9 | use embassy_stm32::spi::{Config, Spi}; |
| 14 | use embassy_stm32::time::Hertz; | 10 | use embassy_stm32::time::Hertz; |
| 15 | use embassy_stm32::Peripherals; | 11 | use embassy_stm32::Peripherals; |
| 12 | use {defmt_rtt as _, panic_probe as _}; | ||
| 16 | 13 | ||
| 17 | #[embassy::main] | 14 | #[embassy::main] |
| 18 | async fn main(_spawner: Spawner, p: Peripherals) { | 15 | async fn main(_spawner: Spawner, p: Peripherals) { |
diff --git a/examples/stm32l0/src/bin/usart_dma.rs b/examples/stm32l0/src/bin/usart_dma.rs index b3fdcacbe..861241639 100644 --- a/examples/stm32l0/src/bin/usart_dma.rs +++ b/examples/stm32l0/src/bin/usart_dma.rs | |||
| @@ -2,25 +2,15 @@ | |||
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | use defmt_rtt as _; // global logger | ||
| 6 | use panic_probe as _; | ||
| 7 | |||
| 8 | use defmt::*; | 5 | use defmt::*; |
| 9 | |||
| 10 | use embassy::executor::Spawner; | 6 | use embassy::executor::Spawner; |
| 11 | use embassy_stm32::usart::{Config, Uart}; | 7 | use embassy_stm32::usart::{Config, Uart}; |
| 12 | use embassy_stm32::Peripherals; | 8 | use embassy_stm32::Peripherals; |
| 9 | use {defmt_rtt as _, panic_probe as _}; | ||
| 13 | 10 | ||
| 14 | #[embassy::main] | 11 | #[embassy::main] |
| 15 | async fn main(_spawner: Spawner, p: Peripherals) { | 12 | async fn main(_spawner: Spawner, p: Peripherals) { |
| 16 | let mut usart = Uart::new( | 13 | let mut usart = Uart::new(p.USART1, p.PB7, p.PB6, p.DMA1_CH2, p.DMA1_CH3, Config::default()); |
| 17 | p.USART1, | ||
| 18 | p.PB7, | ||
| 19 | p.PB6, | ||
| 20 | p.DMA1_CH2, | ||
| 21 | p.DMA1_CH3, | ||
| 22 | Config::default(), | ||
| 23 | ); | ||
| 24 | 14 | ||
| 25 | usart.write(b"Hello Embassy World!\r\n").await.unwrap(); | 15 | usart.write(b"Hello Embassy World!\r\n").await.unwrap(); |
| 26 | info!("wrote Hello, starting echo"); | 16 | info!("wrote Hello, starting echo"); |
diff --git a/examples/stm32l0/src/bin/usart_irq.rs b/examples/stm32l0/src/bin/usart_irq.rs index 4413a2945..09b1b0b03 100644 --- a/examples/stm32l0/src/bin/usart_irq.rs +++ b/examples/stm32l0/src/bin/usart_irq.rs | |||
| @@ -2,18 +2,13 @@ | |||
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | use defmt_rtt as _; | ||
| 6 | use embedded_io::asynch::{Read, Write}; | ||
| 7 | // global logger | ||
| 8 | use panic_probe as _; | ||
| 9 | |||
| 10 | use defmt::*; | 5 | use defmt::*; |
| 11 | |||
| 12 | use embassy::executor::Spawner; | 6 | use embassy::executor::Spawner; |
| 13 | use embassy_stm32::dma::NoDma; | 7 | use embassy_stm32::dma::NoDma; |
| 14 | use embassy_stm32::interrupt; | ||
| 15 | use embassy_stm32::usart::{BufferedUart, Config, State, Uart}; | 8 | use embassy_stm32::usart::{BufferedUart, Config, State, Uart}; |
| 16 | use embassy_stm32::Peripherals; | 9 | use embassy_stm32::{interrupt, Peripherals}; |
| 10 | use embedded_io::asynch::{Read, Write}; | ||
| 11 | use {defmt_rtt as _, panic_probe as _}; | ||
| 17 | 12 | ||
| 18 | #[embassy::main] | 13 | #[embassy::main] |
| 19 | async fn main(_spawner: Spawner, p: Peripherals) { | 14 | async fn main(_spawner: Spawner, p: Peripherals) { |
diff --git a/examples/stm32l1/src/bin/blinky.rs b/examples/stm32l1/src/bin/blinky.rs index e81455524..bace53d91 100644 --- a/examples/stm32l1/src/bin/blinky.rs +++ b/examples/stm32l1/src/bin/blinky.rs | |||
| @@ -2,14 +2,12 @@ | |||
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | use defmt_rtt as _; // global logger | ||
| 6 | use panic_probe as _; | ||
| 7 | |||
| 8 | use defmt::*; | 5 | use defmt::*; |
| 9 | use embassy::executor::Spawner; | 6 | use embassy::executor::Spawner; |
| 10 | use embassy::time::{Duration, Timer}; | 7 | use embassy::time::{Duration, Timer}; |
| 11 | use embassy_stm32::gpio::{Level, Output, Speed}; | 8 | use embassy_stm32::gpio::{Level, Output, Speed}; |
| 12 | use embassy_stm32::Peripherals; | 9 | use embassy_stm32::Peripherals; |
| 10 | use {defmt_rtt as _, panic_probe as _}; | ||
| 13 | 11 | ||
| 14 | #[embassy::main] | 12 | #[embassy::main] |
| 15 | async fn main(_spawner: Spawner, p: Peripherals) { | 13 | async fn main(_spawner: Spawner, p: Peripherals) { |
diff --git a/examples/stm32l1/src/bin/flash.rs b/examples/stm32l1/src/bin/flash.rs index eea838cba..fc519b079 100644 --- a/examples/stm32l1/src/bin/flash.rs +++ b/examples/stm32l1/src/bin/flash.rs | |||
| @@ -7,9 +7,7 @@ use embassy::executor::Spawner; | |||
| 7 | use embassy_stm32::flash::Flash; | 7 | use embassy_stm32::flash::Flash; |
| 8 | use embassy_stm32::Peripherals; | 8 | use embassy_stm32::Peripherals; |
| 9 | use embedded_storage::nor_flash::{NorFlash, ReadNorFlash}; | 9 | use embedded_storage::nor_flash::{NorFlash, ReadNorFlash}; |
| 10 | 10 | use {defmt_rtt as _, panic_probe as _}; | |
| 11 | use defmt_rtt as _; // global logger | ||
| 12 | use panic_probe as _; | ||
| 13 | 11 | ||
| 14 | #[embassy::main] | 12 | #[embassy::main] |
| 15 | async fn main(_spawner: Spawner, p: Peripherals) { | 13 | async fn main(_spawner: Spawner, p: Peripherals) { |
diff --git a/examples/stm32l1/src/bin/spi.rs b/examples/stm32l1/src/bin/spi.rs index bced0c54e..81ccba4e1 100644 --- a/examples/stm32l1/src/bin/spi.rs +++ b/examples/stm32l1/src/bin/spi.rs | |||
| @@ -2,17 +2,14 @@ | |||
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | use defmt_rtt as _; // global logger | ||
| 6 | use panic_probe as _; | ||
| 7 | |||
| 8 | use defmt::*; | 5 | use defmt::*; |
| 9 | use embassy::executor::Spawner; | 6 | use embassy::executor::Spawner; |
| 10 | use embassy_stm32::gpio::{Level, Output, Speed}; | ||
| 11 | |||
| 12 | use embassy_stm32::dma::NoDma; | 7 | use embassy_stm32::dma::NoDma; |
| 8 | use embassy_stm32::gpio::{Level, Output, Speed}; | ||
| 13 | use embassy_stm32::spi::{Config, Spi}; | 9 | use embassy_stm32::spi::{Config, Spi}; |
| 14 | use embassy_stm32::time::Hertz; | 10 | use embassy_stm32::time::Hertz; |
| 15 | use embassy_stm32::Peripherals; | 11 | use embassy_stm32::Peripherals; |
| 12 | use {defmt_rtt as _, panic_probe as _}; | ||
| 16 | 13 | ||
| 17 | #[embassy::main] | 14 | #[embassy::main] |
| 18 | async fn main(_spawner: Spawner, p: Peripherals) { | 15 | async fn main(_spawner: Spawner, p: Peripherals) { |
diff --git a/examples/stm32l4/src/bin/adc.rs b/examples/stm32l4/src/bin/adc.rs index 58ef6ebaa..499ea47dc 100644 --- a/examples/stm32l4/src/bin/adc.rs +++ b/examples/stm32l4/src/bin/adc.rs | |||
| @@ -2,13 +2,11 @@ | |||
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | use defmt_rtt as _; // global logger | ||
| 6 | use panic_probe as _; | ||
| 7 | |||
| 8 | use defmt::*; | 5 | use defmt::*; |
| 9 | use embassy::time::Delay; | 6 | use embassy::time::Delay; |
| 10 | use embassy_stm32::adc::{Adc, Resolution}; | 7 | use embassy_stm32::adc::{Adc, Resolution}; |
| 11 | use embassy_stm32::pac; | 8 | use embassy_stm32::pac; |
| 9 | use {defmt_rtt as _, panic_probe as _}; | ||
| 12 | 10 | ||
| 13 | #[cortex_m_rt::entry] | 11 | #[cortex_m_rt::entry] |
| 14 | fn main() -> ! { | 12 | fn main() -> ! { |
diff --git a/examples/stm32l4/src/bin/blinky.rs b/examples/stm32l4/src/bin/blinky.rs index e24a5bd37..54f8e03b2 100644 --- a/examples/stm32l4/src/bin/blinky.rs +++ b/examples/stm32l4/src/bin/blinky.rs | |||
| @@ -3,12 +3,11 @@ | |||
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | use defmt::*; | 5 | use defmt::*; |
| 6 | use defmt_rtt as _; // global logger | ||
| 7 | use embassy::executor::Spawner; | 6 | use embassy::executor::Spawner; |
| 8 | use embassy::time::{Duration, Timer}; | 7 | use embassy::time::{Duration, Timer}; |
| 9 | use embassy_stm32::gpio::{Level, Output, Speed}; | 8 | use embassy_stm32::gpio::{Level, Output, Speed}; |
| 10 | use embassy_stm32::Peripherals; | 9 | use embassy_stm32::Peripherals; |
| 11 | use panic_probe as _; | 10 | use {defmt_rtt as _, panic_probe as _}; |
| 12 | 11 | ||
| 13 | #[embassy::main] | 12 | #[embassy::main] |
| 14 | async fn main(_spawner: Spawner, p: Peripherals) { | 13 | async fn main(_spawner: Spawner, p: Peripherals) { |
diff --git a/examples/stm32l4/src/bin/button.rs b/examples/stm32l4/src/bin/button.rs index ff270b519..73b1962e8 100644 --- a/examples/stm32l4/src/bin/button.rs +++ b/examples/stm32l4/src/bin/button.rs | |||
| @@ -3,9 +3,8 @@ | |||
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | use defmt::*; | 5 | use defmt::*; |
| 6 | use defmt_rtt as _; // global logger | ||
| 7 | use embassy_stm32::gpio::{Input, Pull}; | 6 | use embassy_stm32::gpio::{Input, Pull}; |
| 8 | use panic_probe as _; | 7 | use {defmt_rtt as _, panic_probe as _}; |
| 9 | 8 | ||
| 10 | #[cortex_m_rt::entry] | 9 | #[cortex_m_rt::entry] |
| 11 | fn main() -> ! { | 10 | fn main() -> ! { |
diff --git a/examples/stm32l4/src/bin/button_exti.rs b/examples/stm32l4/src/bin/button_exti.rs index 4b1cadcb5..924feeb33 100644 --- a/examples/stm32l4/src/bin/button_exti.rs +++ b/examples/stm32l4/src/bin/button_exti.rs | |||
| @@ -3,12 +3,11 @@ | |||
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | use defmt::*; | 5 | use defmt::*; |
| 6 | use defmt_rtt as _; // global logger | ||
| 7 | use embassy::executor::Spawner; | 6 | use embassy::executor::Spawner; |
| 8 | use embassy_stm32::exti::ExtiInput; | 7 | use embassy_stm32::exti::ExtiInput; |
| 9 | use embassy_stm32::gpio::{Input, Pull}; | 8 | use embassy_stm32::gpio::{Input, Pull}; |
| 10 | use embassy_stm32::Peripherals; | 9 | use embassy_stm32::Peripherals; |
| 11 | use panic_probe as _; | 10 | use {defmt_rtt as _, panic_probe as _}; |
| 12 | 11 | ||
| 13 | #[embassy::main] | 12 | #[embassy::main] |
| 14 | async fn main(_spawner: Spawner, p: Peripherals) { | 13 | async fn main(_spawner: Spawner, p: Peripherals) { |
diff --git a/examples/stm32l4/src/bin/dac.rs b/examples/stm32l4/src/bin/dac.rs index c26e7e709..d6e744aa6 100644 --- a/examples/stm32l4/src/bin/dac.rs +++ b/examples/stm32l4/src/bin/dac.rs | |||
| @@ -2,12 +2,10 @@ | |||
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | use defmt_rtt as _; // global logger | ||
| 6 | use panic_probe as _; | ||
| 7 | |||
| 8 | use defmt::*; | 5 | use defmt::*; |
| 9 | use embassy_stm32::dac::{Channel, Dac, Value}; | 6 | use embassy_stm32::dac::{Channel, Dac, Value}; |
| 10 | use embassy_stm32::pac; | 7 | use embassy_stm32::pac; |
| 8 | use {defmt_rtt as _, panic_probe as _}; | ||
| 11 | 9 | ||
| 12 | #[cortex_m_rt::entry] | 10 | #[cortex_m_rt::entry] |
| 13 | fn main() -> ! { | 11 | fn main() -> ! { |
diff --git a/examples/stm32l4/src/bin/i2c.rs b/examples/stm32l4/src/bin/i2c.rs index 467765642..a22b52184 100644 --- a/examples/stm32l4/src/bin/i2c.rs +++ b/examples/stm32l4/src/bin/i2c.rs | |||
| @@ -2,16 +2,13 @@ | |||
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | use defmt_rtt as _; // global logger | ||
| 6 | use panic_probe as _; | ||
| 7 | |||
| 8 | use defmt::*; | 5 | use defmt::*; |
| 9 | use embassy::executor::Spawner; | 6 | use embassy::executor::Spawner; |
| 10 | use embassy_stm32::dma::NoDma; | 7 | use embassy_stm32::dma::NoDma; |
| 11 | use embassy_stm32::i2c::I2c; | 8 | use embassy_stm32::i2c::I2c; |
| 12 | use embassy_stm32::interrupt; | ||
| 13 | use embassy_stm32::time::Hertz; | 9 | use embassy_stm32::time::Hertz; |
| 14 | use embassy_stm32::Peripherals; | 10 | use embassy_stm32::{interrupt, Peripherals}; |
| 11 | use {defmt_rtt as _, panic_probe as _}; | ||
| 15 | 12 | ||
| 16 | const ADDRESS: u8 = 0x5F; | 13 | const ADDRESS: u8 = 0x5F; |
| 17 | const WHOAMI: u8 = 0x0F; | 14 | const WHOAMI: u8 = 0x0F; |
diff --git a/examples/stm32l4/src/bin/i2c_blocking_async.rs b/examples/stm32l4/src/bin/i2c_blocking_async.rs index eb74223b0..6c4a86703 100644 --- a/examples/stm32l4/src/bin/i2c_blocking_async.rs +++ b/examples/stm32l4/src/bin/i2c_blocking_async.rs | |||
| @@ -2,18 +2,15 @@ | |||
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | use defmt_rtt as _; // global logger | ||
| 6 | use panic_probe as _; | ||
| 7 | |||
| 8 | use defmt::*; | 5 | use defmt::*; |
| 9 | use embassy::executor::Spawner; | 6 | use embassy::executor::Spawner; |
| 10 | use embassy_embedded_hal::adapter::BlockingAsync; | 7 | use embassy_embedded_hal::adapter::BlockingAsync; |
| 11 | use embassy_stm32::dma::NoDma; | 8 | use embassy_stm32::dma::NoDma; |
| 12 | use embassy_stm32::i2c::I2c; | 9 | use embassy_stm32::i2c::I2c; |
| 13 | use embassy_stm32::interrupt; | ||
| 14 | use embassy_stm32::time::Hertz; | 10 | use embassy_stm32::time::Hertz; |
| 15 | use embassy_stm32::Peripherals; | 11 | use embassy_stm32::{interrupt, Peripherals}; |
| 16 | use embedded_hal_async::i2c::I2c as I2cTrait; | 12 | use embedded_hal_async::i2c::I2c as I2cTrait; |
| 13 | use {defmt_rtt as _, panic_probe as _}; | ||
| 17 | 14 | ||
| 18 | const ADDRESS: u8 = 0x5F; | 15 | const ADDRESS: u8 = 0x5F; |
| 19 | const WHOAMI: u8 = 0x0F; | 16 | const WHOAMI: u8 = 0x0F; |
diff --git a/examples/stm32l4/src/bin/i2c_dma.rs b/examples/stm32l4/src/bin/i2c_dma.rs index 886a0e09f..48d2e92cf 100644 --- a/examples/stm32l4/src/bin/i2c_dma.rs +++ b/examples/stm32l4/src/bin/i2c_dma.rs | |||
| @@ -2,15 +2,12 @@ | |||
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | use defmt_rtt as _; // global logger | ||
| 6 | use panic_probe as _; | ||
| 7 | |||
| 8 | use defmt::*; | 5 | use defmt::*; |
| 9 | use embassy::executor::Spawner; | 6 | use embassy::executor::Spawner; |
| 10 | use embassy_stm32::i2c::I2c; | 7 | use embassy_stm32::i2c::I2c; |
| 11 | use embassy_stm32::interrupt; | ||
| 12 | use embassy_stm32::time::Hertz; | 8 | use embassy_stm32::time::Hertz; |
| 13 | use embassy_stm32::Peripherals; | 9 | use embassy_stm32::{interrupt, Peripherals}; |
| 10 | use {defmt_rtt as _, panic_probe as _}; | ||
| 14 | 11 | ||
| 15 | const ADDRESS: u8 = 0x5F; | 12 | const ADDRESS: u8 = 0x5F; |
| 16 | const WHOAMI: u8 = 0x0F; | 13 | const WHOAMI: u8 = 0x0F; |
| @@ -18,15 +15,7 @@ const WHOAMI: u8 = 0x0F; | |||
| 18 | #[embassy::main] | 15 | #[embassy::main] |
| 19 | async fn main(_spawner: Spawner, p: Peripherals) -> ! { | 16 | async fn main(_spawner: Spawner, p: Peripherals) -> ! { |
| 20 | let irq = interrupt::take!(I2C2_EV); | 17 | let irq = interrupt::take!(I2C2_EV); |
| 21 | let mut i2c = I2c::new( | 18 | let mut i2c = I2c::new(p.I2C2, p.PB10, p.PB11, irq, p.DMA1_CH4, p.DMA1_CH5, Hertz(100_000)); |
| 22 | p.I2C2, | ||
| 23 | p.PB10, | ||
| 24 | p.PB11, | ||
| 25 | irq, | ||
| 26 | p.DMA1_CH4, | ||
| 27 | p.DMA1_CH5, | ||
| 28 | Hertz(100_000), | ||
| 29 | ); | ||
| 30 | 19 | ||
| 31 | let mut data = [0u8; 1]; | 20 | let mut data = [0u8; 1]; |
| 32 | unwrap!(i2c.write_read(ADDRESS, &[WHOAMI], &mut data).await); | 21 | unwrap!(i2c.write_read(ADDRESS, &[WHOAMI], &mut data).await); |
diff --git a/examples/stm32l4/src/bin/rng.rs b/examples/stm32l4/src/bin/rng.rs index 03773e61b..7aaa122ed 100644 --- a/examples/stm32l4/src/bin/rng.rs +++ b/examples/stm32l4/src/bin/rng.rs | |||
| @@ -3,12 +3,11 @@ | |||
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | use defmt::*; | 5 | use defmt::*; |
| 6 | use defmt_rtt as _; // global logger | ||
| 7 | use embassy::executor::Spawner; | 6 | use embassy::executor::Spawner; |
| 8 | use embassy_stm32::rcc::{ClockSrc, PLLClkDiv, PLLMul, PLLSource, PLLSrcDiv}; | 7 | use embassy_stm32::rcc::{ClockSrc, PLLClkDiv, PLLMul, PLLSource, PLLSrcDiv}; |
| 9 | use embassy_stm32::rng::Rng; | 8 | use embassy_stm32::rng::Rng; |
| 10 | use embassy_stm32::{Config, Peripherals}; | 9 | use embassy_stm32::{Config, Peripherals}; |
| 11 | use panic_probe as _; | 10 | use {defmt_rtt as _, panic_probe as _}; |
| 12 | 11 | ||
| 13 | fn config() -> Config { | 12 | fn config() -> Config { |
| 14 | let mut config = Config::default(); | 13 | let mut config = Config::default(); |
diff --git a/examples/stm32l4/src/bin/spi.rs b/examples/stm32l4/src/bin/spi.rs index 44fdf81a8..76e316a25 100644 --- a/examples/stm32l4/src/bin/spi.rs +++ b/examples/stm32l4/src/bin/spi.rs | |||
| @@ -2,14 +2,12 @@ | |||
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | use defmt_rtt as _; // global logger | ||
| 6 | use panic_probe as _; | ||
| 7 | |||
| 8 | use defmt::*; | 5 | use defmt::*; |
| 9 | use embassy_stm32::dma::NoDma; | 6 | use embassy_stm32::dma::NoDma; |
| 10 | use embassy_stm32::gpio::{Level, Output, Speed}; | 7 | use embassy_stm32::gpio::{Level, Output, Speed}; |
| 11 | use embassy_stm32::spi::{Config, Spi}; | 8 | use embassy_stm32::spi::{Config, Spi}; |
| 12 | use embassy_stm32::time::Hertz; | 9 | use embassy_stm32::time::Hertz; |
| 10 | use {defmt_rtt as _, panic_probe as _}; | ||
| 13 | 11 | ||
| 14 | #[cortex_m_rt::entry] | 12 | #[cortex_m_rt::entry] |
| 15 | fn main() -> ! { | 13 | fn main() -> ! { |
diff --git a/examples/stm32l4/src/bin/spi_blocking_async.rs b/examples/stm32l4/src/bin/spi_blocking_async.rs index e1a400107..20a2ff802 100644 --- a/examples/stm32l4/src/bin/spi_blocking_async.rs +++ b/examples/stm32l4/src/bin/spi_blocking_async.rs | |||
| @@ -2,9 +2,6 @@ | |||
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | use defmt_rtt as _; // global logger | ||
| 6 | use panic_probe as _; | ||
| 7 | |||
| 8 | use defmt::*; | 5 | use defmt::*; |
| 9 | use embassy::executor::Spawner; | 6 | use embassy::executor::Spawner; |
| 10 | use embassy_embedded_hal::adapter::BlockingAsync; | 7 | use embassy_embedded_hal::adapter::BlockingAsync; |
| @@ -14,6 +11,7 @@ use embassy_stm32::spi::{Config, Spi}; | |||
| 14 | use embassy_stm32::time::Hertz; | 11 | use embassy_stm32::time::Hertz; |
| 15 | use embassy_stm32::Peripherals; | 12 | use embassy_stm32::Peripherals; |
| 16 | use embedded_hal_async::spi::SpiBus; | 13 | use embedded_hal_async::spi::SpiBus; |
| 14 | use {defmt_rtt as _, panic_probe as _}; | ||
| 17 | 15 | ||
| 18 | #[embassy::main] | 16 | #[embassy::main] |
| 19 | async fn main(_spawner: Spawner, p: Peripherals) { | 17 | async fn main(_spawner: Spawner, p: Peripherals) { |
diff --git a/examples/stm32l4/src/bin/spi_dma.rs b/examples/stm32l4/src/bin/spi_dma.rs index 88d02c7e1..d0c3609af 100644 --- a/examples/stm32l4/src/bin/spi_dma.rs +++ b/examples/stm32l4/src/bin/spi_dma.rs | |||
| @@ -2,15 +2,13 @@ | |||
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | use defmt_rtt as _; // global logger | ||
| 6 | use panic_probe as _; | ||
| 7 | |||
| 8 | use defmt::*; | 5 | use defmt::*; |
| 9 | use embassy::executor::Spawner; | 6 | use embassy::executor::Spawner; |
| 10 | use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; | 7 | use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; |
| 11 | use embassy_stm32::spi::{Config, Spi}; | 8 | use embassy_stm32::spi::{Config, Spi}; |
| 12 | use embassy_stm32::time::Hertz; | 9 | use embassy_stm32::time::Hertz; |
| 13 | use embassy_stm32::Peripherals; | 10 | use embassy_stm32::Peripherals; |
| 11 | use {defmt_rtt as _, panic_probe as _}; | ||
| 14 | 12 | ||
| 15 | #[embassy::main] | 13 | #[embassy::main] |
| 16 | async fn main(_spawner: Spawner, p: Peripherals) { | 14 | async fn main(_spawner: Spawner, p: Peripherals) { |
diff --git a/examples/stm32l4/src/bin/usart.rs b/examples/stm32l4/src/bin/usart.rs index b38f55456..4a4b46c53 100644 --- a/examples/stm32l4/src/bin/usart.rs +++ b/examples/stm32l4/src/bin/usart.rs | |||
| @@ -2,12 +2,10 @@ | |||
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | use defmt_rtt as _; // global logger | ||
| 6 | use panic_probe as _; | ||
| 7 | |||
| 8 | use defmt::*; | 5 | use defmt::*; |
| 9 | use embassy_stm32::dma::NoDma; | 6 | use embassy_stm32::dma::NoDma; |
| 10 | use embassy_stm32::usart::{Config, Uart}; | 7 | use embassy_stm32::usart::{Config, Uart}; |
| 8 | use {defmt_rtt as _, panic_probe as _}; | ||
| 11 | 9 | ||
| 12 | #[cortex_m_rt::entry] | 10 | #[cortex_m_rt::entry] |
| 13 | fn main() -> ! { | 11 | fn main() -> ! { |
diff --git a/examples/stm32l4/src/bin/usart_dma.rs b/examples/stm32l4/src/bin/usart_dma.rs index 40e2c3671..7ae7e9e15 100644 --- a/examples/stm32l4/src/bin/usart_dma.rs +++ b/examples/stm32l4/src/bin/usart_dma.rs | |||
| @@ -3,14 +3,14 @@ | |||
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | use core::fmt::Write; | 5 | use core::fmt::Write; |
| 6 | |||
| 6 | use defmt::*; | 7 | use defmt::*; |
| 7 | use defmt_rtt as _; // global logger | ||
| 8 | use embassy::executor::Spawner; | 8 | use embassy::executor::Spawner; |
| 9 | use embassy_stm32::dma::NoDma; | 9 | use embassy_stm32::dma::NoDma; |
| 10 | use embassy_stm32::usart::{Config, Uart}; | 10 | use embassy_stm32::usart::{Config, Uart}; |
| 11 | use embassy_stm32::Peripherals; | 11 | use embassy_stm32::Peripherals; |
| 12 | use heapless::String; | 12 | use heapless::String; |
| 13 | use panic_probe as _; | 13 | use {defmt_rtt as _, panic_probe as _}; |
| 14 | 14 | ||
| 15 | #[embassy::main] | 15 | #[embassy::main] |
| 16 | async fn main(_spawner: Spawner, p: Peripherals) { | 16 | async fn main(_spawner: Spawner, p: Peripherals) { |
diff --git a/examples/stm32l5/src/bin/button_exti.rs b/examples/stm32l5/src/bin/button_exti.rs index 304ce0a8a..c7a6cfa28 100644 --- a/examples/stm32l5/src/bin/button_exti.rs +++ b/examples/stm32l5/src/bin/button_exti.rs | |||
| @@ -3,12 +3,11 @@ | |||
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | use defmt::*; | 5 | use defmt::*; |
| 6 | use defmt_rtt as _; // global logger | ||
| 7 | use embassy::executor::Spawner; | 6 | use embassy::executor::Spawner; |
| 8 | use embassy_stm32::exti::ExtiInput; | 7 | use embassy_stm32::exti::ExtiInput; |
| 9 | use embassy_stm32::gpio::{Input, Pull}; | 8 | use embassy_stm32::gpio::{Input, Pull}; |
| 10 | use embassy_stm32::Peripherals; | 9 | use embassy_stm32::Peripherals; |
| 11 | use panic_probe as _; | 10 | use {defmt_rtt as _, panic_probe as _}; |
| 12 | 11 | ||
| 13 | #[embassy::main] | 12 | #[embassy::main] |
| 14 | async fn main(_spawner: Spawner, p: Peripherals) { | 13 | async fn main(_spawner: Spawner, p: Peripherals) { |
diff --git a/examples/stm32l5/src/bin/rng.rs b/examples/stm32l5/src/bin/rng.rs index 5f75c1ff1..d3627d2c2 100644 --- a/examples/stm32l5/src/bin/rng.rs +++ b/examples/stm32l5/src/bin/rng.rs | |||
| @@ -3,12 +3,11 @@ | |||
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | use defmt::*; | 5 | use defmt::*; |
| 6 | use defmt_rtt as _; // global logger | ||
| 7 | use embassy::executor::Spawner; | 6 | use embassy::executor::Spawner; |
| 8 | use embassy_stm32::rcc::{ClockSrc, PLLClkDiv, PLLMul, PLLSource, PLLSrcDiv}; | 7 | use embassy_stm32::rcc::{ClockSrc, PLLClkDiv, PLLMul, PLLSource, PLLSrcDiv}; |
| 9 | use embassy_stm32::rng::Rng; | 8 | use embassy_stm32::rng::Rng; |
| 10 | use embassy_stm32::{Config, Peripherals}; | 9 | use embassy_stm32::{Config, Peripherals}; |
| 11 | use panic_probe as _; | 10 | use {defmt_rtt as _, panic_probe as _}; |
| 12 | 11 | ||
| 13 | fn config() -> Config { | 12 | fn config() -> Config { |
| 14 | let mut config = Config::default(); | 13 | let mut config = Config::default(); |
diff --git a/examples/stm32l5/src/bin/usb_ethernet.rs b/examples/stm32l5/src/bin/usb_ethernet.rs index 526b27530..d711616ef 100644 --- a/examples/stm32l5/src/bin/usb_ethernet.rs +++ b/examples/stm32l5/src/bin/usb_ethernet.rs | |||
| @@ -5,29 +5,24 @@ | |||
| 5 | 5 | ||
| 6 | use core::sync::atomic::{AtomicBool, Ordering}; | 6 | use core::sync::atomic::{AtomicBool, Ordering}; |
| 7 | use core::task::Waker; | 7 | use core::task::Waker; |
| 8 | |||
| 8 | use defmt::*; | 9 | use defmt::*; |
| 9 | use defmt_rtt as _; // global logger | ||
| 10 | use embassy::blocking_mutex::raw::ThreadModeRawMutex; | 10 | use embassy::blocking_mutex::raw::ThreadModeRawMutex; |
| 11 | use embassy::channel::mpmc::Channel; | 11 | use embassy::channel::mpmc::Channel; |
| 12 | use embassy::executor::Spawner; | 12 | use embassy::executor::Spawner; |
| 13 | use embassy::util::Forever; | 13 | use embassy::util::Forever; |
| 14 | use embassy_net::tcp::TcpSocket; | 14 | use embassy_net::tcp::TcpSocket; |
| 15 | use embassy_net::{PacketBox, PacketBoxExt, PacketBuf, Stack, StackResources}; | 15 | use embassy_net::{PacketBox, PacketBoxExt, PacketBuf, Stack, StackResources}; |
| 16 | use embassy_stm32::interrupt; | ||
| 17 | use embassy_stm32::rcc::*; | 16 | use embassy_stm32::rcc::*; |
| 18 | use embassy_stm32::rng::Rng; | 17 | use embassy_stm32::rng::Rng; |
| 19 | use embassy_stm32::time::Hertz; | 18 | use embassy_stm32::time::Hertz; |
| 20 | use embassy_stm32::usb::Driver; | 19 | use embassy_stm32::usb::Driver; |
| 21 | use embassy_stm32::{Config, Peripherals}; | 20 | use embassy_stm32::{interrupt, Config, Peripherals}; |
| 22 | use embassy_usb::{Builder, UsbDevice}; | 21 | use embassy_usb::{Builder, UsbDevice}; |
| 23 | use embassy_usb_ncm::{CdcNcmClass, Receiver, Sender, State}; | 22 | use embassy_usb_ncm::{CdcNcmClass, Receiver, Sender, State}; |
| 24 | use panic_probe as _; | ||
| 25 | |||
| 26 | use defmt_rtt as _; | ||
| 27 | use embedded_io::asynch::{Read, Write}; | 23 | use embedded_io::asynch::{Read, Write}; |
| 28 | // global logger | ||
| 29 | use panic_probe as _; | ||
| 30 | use rand_core::RngCore; | 24 | use rand_core::RngCore; |
| 25 | use {defmt_rtt as _, panic_probe as _}; | ||
| 31 | 26 | ||
| 32 | type MyDriver = Driver<'static, embassy_stm32::peripherals::USB>; | 27 | type MyDriver = Driver<'static, embassy_stm32::peripherals::USB>; |
| 33 | 28 | ||
| @@ -92,13 +87,7 @@ fn config() -> Config { | |||
| 92 | let mut config = Config::default(); | 87 | let mut config = Config::default(); |
| 93 | config.rcc.mux = ClockSrc::HSE(Hertz(16_000_000)); | 88 | config.rcc.mux = ClockSrc::HSE(Hertz(16_000_000)); |
| 94 | 89 | ||
| 95 | config.rcc.mux = ClockSrc::PLL( | 90 | config.rcc.mux = ClockSrc::PLL(PLLSource::HSI16, PLLClkDiv::Div2, PLLSrcDiv::Div1, PLLMul::Mul10, None); |
| 96 | PLLSource::HSI16, | ||
| 97 | PLLClkDiv::Div2, | ||
| 98 | PLLSrcDiv::Div1, | ||
| 99 | PLLMul::Mul10, | ||
| 100 | None, | ||
| 101 | ); | ||
| 102 | config.rcc.hsi48 = true; | 91 | config.rcc.hsi48 = true; |
| 103 | 92 | ||
| 104 | config | 93 | config |
| @@ -186,9 +175,7 @@ async fn main(spawner: Spawner, p: Peripherals) { | |||
| 186 | let seed = rng.next_u64(); | 175 | let seed = rng.next_u64(); |
| 187 | 176 | ||
| 188 | // Init network stack | 177 | // Init network stack |
| 189 | let device = Device { | 178 | let device = Device { mac_addr: our_mac_addr }; |
| 190 | mac_addr: our_mac_addr, | ||
| 191 | }; | ||
| 192 | let stack = &*forever!(Stack::new( | 179 | let stack = &*forever!(Stack::new( |
| 193 | device, | 180 | device, |
| 194 | config, | 181 | config, |
diff --git a/examples/stm32l5/src/bin/usb_hid_mouse.rs b/examples/stm32l5/src/bin/usb_hid_mouse.rs index d275aba36..d139e6bb1 100644 --- a/examples/stm32l5/src/bin/usb_hid_mouse.rs +++ b/examples/stm32l5/src/bin/usb_hid_mouse.rs | |||
| @@ -6,31 +6,22 @@ | |||
| 6 | use defmt::*; | 6 | use defmt::*; |
| 7 | use embassy::executor::Spawner; | 7 | use embassy::executor::Spawner; |
| 8 | use embassy::time::{Duration, Timer}; | 8 | use embassy::time::{Duration, Timer}; |
| 9 | use embassy_stm32::interrupt; | ||
| 10 | use embassy_stm32::rcc::*; | 9 | use embassy_stm32::rcc::*; |
| 11 | use embassy_stm32::time::Hertz; | 10 | use embassy_stm32::time::Hertz; |
| 12 | use embassy_stm32::usb::Driver; | 11 | use embassy_stm32::usb::Driver; |
| 13 | use embassy_stm32::{Config, Peripherals}; | 12 | use embassy_stm32::{interrupt, Config, Peripherals}; |
| 14 | use embassy_usb::control::OutResponse; | 13 | use embassy_usb::control::OutResponse; |
| 15 | use embassy_usb::Builder; | 14 | use embassy_usb::Builder; |
| 16 | use embassy_usb_hid::{HidWriter, ReportId, RequestHandler, State}; | 15 | use embassy_usb_hid::{HidWriter, ReportId, RequestHandler, State}; |
| 17 | use futures::future::join; | 16 | use futures::future::join; |
| 18 | use usbd_hid::descriptor::{MouseReport, SerializedDescriptor}; | 17 | use usbd_hid::descriptor::{MouseReport, SerializedDescriptor}; |
| 19 | 18 | use {defmt_rtt as _, panic_probe as _}; | |
| 20 | use defmt_rtt as _; // global logger | ||
| 21 | use panic_probe as _; | ||
| 22 | 19 | ||
| 23 | fn config() -> Config { | 20 | fn config() -> Config { |
| 24 | let mut config = Config::default(); | 21 | let mut config = Config::default(); |
| 25 | config.rcc.mux = ClockSrc::HSE(Hertz(16_000_000)); | 22 | config.rcc.mux = ClockSrc::HSE(Hertz(16_000_000)); |
| 26 | 23 | ||
| 27 | config.rcc.mux = ClockSrc::PLL( | 24 | config.rcc.mux = ClockSrc::PLL(PLLSource::HSI16, PLLClkDiv::Div2, PLLSrcDiv::Div1, PLLMul::Mul10, None); |
| 28 | PLLSource::HSI16, | ||
| 29 | PLLClkDiv::Div2, | ||
| 30 | PLLSrcDiv::Div1, | ||
| 31 | PLLMul::Mul10, | ||
| 32 | None, | ||
| 33 | ); | ||
| 34 | config.rcc.hsi48 = true; | 25 | config.rcc.hsi48 = true; |
| 35 | 26 | ||
| 36 | config | 27 | config |
diff --git a/examples/stm32l5/src/bin/usb_serial.rs b/examples/stm32l5/src/bin/usb_serial.rs index 987f1b692..8dab001c6 100644 --- a/examples/stm32l5/src/bin/usb_serial.rs +++ b/examples/stm32l5/src/bin/usb_serial.rs | |||
| @@ -2,32 +2,23 @@ | |||
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | use defmt::panic; | 5 | use defmt::{panic, *}; |
| 6 | use defmt::*; | ||
| 7 | use defmt_rtt as _; // global logger | ||
| 8 | use embassy::executor::Spawner; | 6 | use embassy::executor::Spawner; |
| 9 | use embassy_stm32::interrupt; | ||
| 10 | use embassy_stm32::rcc::*; | 7 | use embassy_stm32::rcc::*; |
| 11 | use embassy_stm32::time::Hertz; | 8 | use embassy_stm32::time::Hertz; |
| 12 | use embassy_stm32::usb::{Driver, Instance}; | 9 | use embassy_stm32::usb::{Driver, Instance}; |
| 13 | use embassy_stm32::{Config, Peripherals}; | 10 | use embassy_stm32::{interrupt, Config, Peripherals}; |
| 14 | use embassy_usb::driver::EndpointError; | 11 | use embassy_usb::driver::EndpointError; |
| 15 | use embassy_usb::Builder; | 12 | use embassy_usb::Builder; |
| 16 | use embassy_usb_serial::{CdcAcmClass, State}; | 13 | use embassy_usb_serial::{CdcAcmClass, State}; |
| 17 | use futures::future::join; | 14 | use futures::future::join; |
| 18 | use panic_probe as _; | 15 | use {defmt_rtt as _, panic_probe as _}; |
| 19 | 16 | ||
| 20 | fn config() -> Config { | 17 | fn config() -> Config { |
| 21 | let mut config = Config::default(); | 18 | let mut config = Config::default(); |
| 22 | config.rcc.mux = ClockSrc::HSE(Hertz(16_000_000)); | 19 | config.rcc.mux = ClockSrc::HSE(Hertz(16_000_000)); |
| 23 | 20 | ||
| 24 | config.rcc.mux = ClockSrc::PLL( | 21 | config.rcc.mux = ClockSrc::PLL(PLLSource::HSI16, PLLClkDiv::Div2, PLLSrcDiv::Div1, PLLMul::Mul10, None); |
| 25 | PLLSource::HSI16, | ||
| 26 | PLLClkDiv::Div2, | ||
| 27 | PLLSrcDiv::Div1, | ||
| 28 | PLLMul::Mul10, | ||
| 29 | None, | ||
| 30 | ); | ||
| 31 | config.rcc.hsi48 = true; | 22 | config.rcc.hsi48 = true; |
| 32 | 23 | ||
| 33 | config | 24 | config |
| @@ -99,9 +90,7 @@ impl From<EndpointError> for Disconnected { | |||
| 99 | } | 90 | } |
| 100 | } | 91 | } |
| 101 | 92 | ||
| 102 | async fn echo<'d, T: Instance + 'd>( | 93 | async fn echo<'d, T: Instance + 'd>(class: &mut CdcAcmClass<'d, Driver<'d, T>>) -> Result<(), Disconnected> { |
| 103 | class: &mut CdcAcmClass<'d, Driver<'d, T>>, | ||
| 104 | ) -> Result<(), Disconnected> { | ||
| 105 | let mut buf = [0; 64]; | 94 | let mut buf = [0; 64]; |
| 106 | loop { | 95 | loop { |
| 107 | let n = class.read_packet(&mut buf).await?; | 96 | let n = class.read_packet(&mut buf).await?; |
diff --git a/examples/stm32u5/src/bin/blinky.rs b/examples/stm32u5/src/bin/blinky.rs index e1bcccf58..4910e0b98 100644 --- a/examples/stm32u5/src/bin/blinky.rs +++ b/examples/stm32u5/src/bin/blinky.rs | |||
| @@ -3,13 +3,11 @@ | |||
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | use defmt::*; | 5 | use defmt::*; |
| 6 | use defmt_rtt as _; | ||
| 7 | use embassy::executor::Spawner; | 6 | use embassy::executor::Spawner; |
| 8 | use embassy::time::{Duration, Timer}; | 7 | use embassy::time::{Duration, Timer}; |
| 9 | use embassy_stm32::gpio::{Level, Output, Speed}; | 8 | use embassy_stm32::gpio::{Level, Output, Speed}; |
| 10 | use embassy_stm32::Peripherals; | 9 | use embassy_stm32::Peripherals; |
| 11 | // global logger | 10 | use {defmt_rtt as _, panic_probe as _}; |
| 12 | use panic_probe as _; | ||
| 13 | 11 | ||
| 14 | #[embassy::main] | 12 | #[embassy::main] |
| 15 | async fn main(_spawner: Spawner, p: Peripherals) -> ! { | 13 | async fn main(_spawner: Spawner, p: Peripherals) -> ! { |
diff --git a/examples/stm32u5/src/bin/boot.rs b/examples/stm32u5/src/bin/boot.rs index e04021349..e2112ce5c 100644 --- a/examples/stm32u5/src/bin/boot.rs +++ b/examples/stm32u5/src/bin/boot.rs | |||
| @@ -3,10 +3,7 @@ | |||
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | use defmt::*; | 5 | use defmt::*; |
| 6 | use defmt_rtt as _; // global logger | 6 | use {defmt_rtt as _, embassy_stm32 as _, panic_probe as _}; |
| 7 | use panic_probe as _; | ||
| 8 | |||
| 9 | use embassy_stm32 as _; | ||
| 10 | 7 | ||
| 11 | #[cortex_m_rt::entry] | 8 | #[cortex_m_rt::entry] |
| 12 | fn main() -> ! { | 9 | fn main() -> ! { |
diff --git a/examples/stm32wb/src/bin/blinky.rs b/examples/stm32wb/src/bin/blinky.rs index 59324161a..8ab9b749d 100644 --- a/examples/stm32wb/src/bin/blinky.rs +++ b/examples/stm32wb/src/bin/blinky.rs | |||
| @@ -3,12 +3,11 @@ | |||
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | use defmt::*; | 5 | use defmt::*; |
| 6 | use defmt_rtt as _; // global logger | ||
| 7 | use embassy::executor::Spawner; | 6 | use embassy::executor::Spawner; |
| 8 | use embassy::time::{Duration, Timer}; | 7 | use embassy::time::{Duration, Timer}; |
| 9 | use embassy_stm32::gpio::{Level, Output, Speed}; | 8 | use embassy_stm32::gpio::{Level, Output, Speed}; |
| 10 | use embassy_stm32::Peripherals; | 9 | use embassy_stm32::Peripherals; |
| 11 | use panic_probe as _; | 10 | use {defmt_rtt as _, panic_probe as _}; |
| 12 | 11 | ||
| 13 | #[embassy::main] | 12 | #[embassy::main] |
| 14 | async fn main(_spawner: Spawner, p: Peripherals) { | 13 | async fn main(_spawner: Spawner, p: Peripherals) { |
diff --git a/examples/stm32wb/src/bin/button_exti.rs b/examples/stm32wb/src/bin/button_exti.rs index a30a4a216..2ddeb887c 100644 --- a/examples/stm32wb/src/bin/button_exti.rs +++ b/examples/stm32wb/src/bin/button_exti.rs | |||
| @@ -3,12 +3,11 @@ | |||
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | use defmt::*; | 5 | use defmt::*; |
| 6 | use defmt_rtt as _; // global logger | ||
| 7 | use embassy::executor::Spawner; | 6 | use embassy::executor::Spawner; |
| 8 | use embassy_stm32::exti::ExtiInput; | 7 | use embassy_stm32::exti::ExtiInput; |
| 9 | use embassy_stm32::gpio::{Input, Pull}; | 8 | use embassy_stm32::gpio::{Input, Pull}; |
| 10 | use embassy_stm32::Peripherals; | 9 | use embassy_stm32::Peripherals; |
| 11 | use panic_probe as _; | 10 | use {defmt_rtt as _, panic_probe as _}; |
| 12 | 11 | ||
| 13 | #[embassy::main] | 12 | #[embassy::main] |
| 14 | async fn main(_spawner: Spawner, p: Peripherals) { | 13 | async fn main(_spawner: Spawner, p: Peripherals) { |
diff --git a/examples/stm32wl/src/bin/blinky.rs b/examples/stm32wl/src/bin/blinky.rs index 78079bfd3..9393af1c6 100644 --- a/examples/stm32wl/src/bin/blinky.rs +++ b/examples/stm32wl/src/bin/blinky.rs | |||
| @@ -3,12 +3,11 @@ | |||
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | use defmt::*; | 5 | use defmt::*; |
| 6 | use defmt_rtt as _; // global logger | ||
| 7 | use embassy::executor::Spawner; | 6 | use embassy::executor::Spawner; |
| 8 | use embassy::time::{Duration, Timer}; | 7 | use embassy::time::{Duration, Timer}; |
| 9 | use embassy_stm32::gpio::{Level, Output, Speed}; | 8 | use embassy_stm32::gpio::{Level, Output, Speed}; |
| 10 | use embassy_stm32::Peripherals; | 9 | use embassy_stm32::Peripherals; |
| 11 | use panic_probe as _; | 10 | use {defmt_rtt as _, panic_probe as _}; |
| 12 | 11 | ||
| 13 | #[embassy::main] | 12 | #[embassy::main] |
| 14 | async fn main(_spawner: Spawner, p: Peripherals) { | 13 | async fn main(_spawner: Spawner, p: Peripherals) { |
diff --git a/examples/stm32wl/src/bin/button.rs b/examples/stm32wl/src/bin/button.rs index f80b9ab4f..982a7a112 100644 --- a/examples/stm32wl/src/bin/button.rs +++ b/examples/stm32wl/src/bin/button.rs | |||
| @@ -2,12 +2,10 @@ | |||
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | use cortex_m_rt::entry; | ||
| 5 | use defmt::*; | 6 | use defmt::*; |
| 6 | use defmt_rtt as _; // global logger | ||
| 7 | use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; | 7 | use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; |
| 8 | use panic_probe as _; | 8 | use {defmt_rtt as _, panic_probe as _}; |
| 9 | |||
| 10 | use cortex_m_rt::entry; | ||
| 11 | 9 | ||
| 12 | #[entry] | 10 | #[entry] |
| 13 | fn main() -> ! { | 11 | fn main() -> ! { |
diff --git a/examples/stm32wl/src/bin/button_exti.rs b/examples/stm32wl/src/bin/button_exti.rs index 9a427c2d3..7d5c1b3cb 100644 --- a/examples/stm32wl/src/bin/button_exti.rs +++ b/examples/stm32wl/src/bin/button_exti.rs | |||
| @@ -3,12 +3,11 @@ | |||
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | use defmt::*; | 5 | use defmt::*; |
| 6 | use defmt_rtt as _; // global logger | ||
| 7 | use embassy::executor::Spawner; | 6 | use embassy::executor::Spawner; |
| 8 | use embassy_stm32::exti::ExtiInput; | 7 | use embassy_stm32::exti::ExtiInput; |
| 9 | use embassy_stm32::gpio::{Input, Pull}; | 8 | use embassy_stm32::gpio::{Input, Pull}; |
| 10 | use embassy_stm32::Peripherals; | 9 | use embassy_stm32::Peripherals; |
| 11 | use panic_probe as _; | 10 | use {defmt_rtt as _, panic_probe as _}; |
| 12 | 11 | ||
| 13 | #[embassy::main] | 12 | #[embassy::main] |
| 14 | async fn main(_spawner: Spawner, p: Peripherals) { | 13 | async fn main(_spawner: Spawner, p: Peripherals) { |
diff --git a/examples/stm32wl/src/bin/flash.rs b/examples/stm32wl/src/bin/flash.rs index f84818224..6531feae9 100644 --- a/examples/stm32wl/src/bin/flash.rs +++ b/examples/stm32wl/src/bin/flash.rs | |||
| @@ -7,9 +7,7 @@ use embassy::executor::Spawner; | |||
| 7 | use embassy_stm32::flash::Flash; | 7 | use embassy_stm32::flash::Flash; |
| 8 | use embassy_stm32::Peripherals; | 8 | use embassy_stm32::Peripherals; |
| 9 | use embedded_storage::nor_flash::{NorFlash, ReadNorFlash}; | 9 | use embedded_storage::nor_flash::{NorFlash, ReadNorFlash}; |
| 10 | 10 | use {defmt_rtt as _, panic_probe as _}; | |
| 11 | use defmt_rtt as _; // global logger | ||
| 12 | use panic_probe as _; | ||
| 13 | 11 | ||
| 14 | #[embassy::main] | 12 | #[embassy::main] |
| 15 | async fn main(_spawner: Spawner, p: Peripherals) { | 13 | async fn main(_spawner: Spawner, p: Peripherals) { |
diff --git a/examples/stm32wl/src/bin/lorawan.rs b/examples/stm32wl/src/bin/lorawan.rs index 393828c85..4f0dc7dfc 100644 --- a/examples/stm32wl/src/bin/lorawan.rs +++ b/examples/stm32wl/src/bin/lorawan.rs | |||
| @@ -5,20 +5,16 @@ | |||
| 5 | #![feature(generic_associated_types)] | 5 | #![feature(generic_associated_types)] |
| 6 | #![feature(type_alias_impl_trait)] | 6 | #![feature(type_alias_impl_trait)] |
| 7 | 7 | ||
| 8 | use defmt_rtt as _; // global logger | 8 | use embassy_lora::stm32wl::*; |
| 9 | use panic_probe as _; | 9 | use embassy_lora::LoraTimer; |
| 10 | 10 | use embassy_stm32::dma::NoDma; | |
| 11 | use embassy_lora::{stm32wl::*, LoraTimer}; | 11 | use embassy_stm32::gpio::{Level, Output, Pin, Speed}; |
| 12 | use embassy_stm32::{ | 12 | use embassy_stm32::rng::Rng; |
| 13 | dma::NoDma, | 13 | use embassy_stm32::subghz::*; |
| 14 | gpio::{Level, Output, Pin, Speed}, | 14 | use embassy_stm32::{interrupt, pac, Peripherals}; |
| 15 | interrupt, pac, | ||
| 16 | rng::Rng, | ||
| 17 | subghz::*, | ||
| 18 | Peripherals, | ||
| 19 | }; | ||
| 20 | use lorawan::default_crypto::DefaultFactory as Crypto; | 15 | use lorawan::default_crypto::DefaultFactory as Crypto; |
| 21 | use lorawan_device::async_device::{region, Device, JoinMode}; | 16 | use lorawan_device::async_device::{region, Device, JoinMode}; |
| 17 | use {defmt_rtt as _, panic_probe as _}; | ||
| 22 | 18 | ||
| 23 | fn config() -> embassy_stm32::Config { | 19 | fn config() -> embassy_stm32::Config { |
| 24 | let mut config = embassy_stm32::Config::default(); | 20 | let mut config = embassy_stm32::Config::default(); |
| @@ -43,8 +39,7 @@ async fn main(_spawner: embassy::executor::Spawner, p: Peripherals) { | |||
| 43 | let radio = unsafe { SubGhzRadio::new(&mut RADIO_STATE, radio, rfs, irq) }; | 39 | let radio = unsafe { SubGhzRadio::new(&mut RADIO_STATE, radio, rfs, irq) }; |
| 44 | 40 | ||
| 45 | let region = region::EU868::default().into(); | 41 | let region = region::EU868::default().into(); |
| 46 | let mut device: Device<_, Crypto, _, _> = | 42 | let mut device: Device<_, Crypto, _, _> = Device::new(region, radio, LoraTimer, Rng::new(p.RNG)); |
| 47 | Device::new(region, radio, LoraTimer, Rng::new(p.RNG)); | ||
| 48 | 43 | ||
| 49 | defmt::info!("Joining LoRaWAN network"); | 44 | defmt::info!("Joining LoRaWAN network"); |
| 50 | 45 | ||
diff --git a/examples/stm32wl/src/bin/subghz.rs b/examples/stm32wl/src/bin/subghz.rs index f5f9b6a32..c5f6e502a 100644 --- a/examples/stm32wl/src/bin/subghz.rs +++ b/examples/stm32wl/src/bin/subghz.rs | |||
| @@ -5,18 +5,15 @@ | |||
| 5 | #![feature(generic_associated_types)] | 5 | #![feature(generic_associated_types)] |
| 6 | #![feature(type_alias_impl_trait)] | 6 | #![feature(type_alias_impl_trait)] |
| 7 | 7 | ||
| 8 | use defmt_rtt as _; // global logger | ||
| 9 | use panic_probe as _; | ||
| 10 | |||
| 11 | use defmt::*; | 8 | use defmt::*; |
| 12 | use embassy::channel::signal::Signal; | 9 | use embassy::channel::signal::Signal; |
| 13 | use embassy_stm32::dma::NoDma; | 10 | use embassy_stm32::dma::NoDma; |
| 14 | use embassy_stm32::exti::ExtiInput; | 11 | use embassy_stm32::exti::ExtiInput; |
| 15 | use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; | 12 | use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; |
| 16 | use embassy_stm32::interrupt; | ||
| 17 | use embassy_stm32::interrupt::{Interrupt, InterruptExt}; | 13 | use embassy_stm32::interrupt::{Interrupt, InterruptExt}; |
| 18 | use embassy_stm32::subghz::*; | 14 | use embassy_stm32::subghz::*; |
| 19 | use embassy_stm32::Peripherals; | 15 | use embassy_stm32::{interrupt, Peripherals}; |
| 16 | use {defmt_rtt as _, panic_probe as _}; | ||
| 20 | 17 | ||
| 21 | const PING_DATA: &str = "PING"; | 18 | const PING_DATA: &str = "PING"; |
| 22 | const DATA_LEN: u8 = PING_DATA.len() as u8; | 19 | const DATA_LEN: u8 = PING_DATA.len() as u8; |
| @@ -46,20 +43,13 @@ const LORA_MOD_PARAMS: LoRaModParams = LoRaModParams::new() | |||
| 46 | 43 | ||
| 47 | // configuration for +10 dBm output power | 44 | // configuration for +10 dBm output power |
| 48 | // see table 35 "PA optimal setting and operating modes" | 45 | // see table 35 "PA optimal setting and operating modes" |
| 49 | const PA_CONFIG: PaConfig = PaConfig::new() | 46 | const PA_CONFIG: PaConfig = PaConfig::new().set_pa_duty_cycle(0x1).set_hp_max(0x0).set_pa(PaSel::Lp); |
| 50 | .set_pa_duty_cycle(0x1) | ||
| 51 | .set_hp_max(0x0) | ||
| 52 | .set_pa(PaSel::Lp); | ||
| 53 | 47 | ||
| 54 | const TCXO_MODE: TcxoMode = TcxoMode::new() | 48 | const TCXO_MODE: TcxoMode = TcxoMode::new() |
| 55 | .set_txco_trim(TcxoTrim::Volts1pt7) | 49 | .set_txco_trim(TcxoTrim::Volts1pt7) |
| 56 | .set_timeout(Timeout::from_duration_sat( | 50 | .set_timeout(Timeout::from_duration_sat(core::time::Duration::from_millis(10))); |
| 57 | core::time::Duration::from_millis(10), | ||
| 58 | )); | ||
| 59 | 51 | ||
| 60 | const TX_PARAMS: TxParams = TxParams::new() | 52 | const TX_PARAMS: TxParams = TxParams::new().set_power(0x0D).set_ramp_time(RampTime::Micros40); |
| 61 | .set_power(0x0D) | ||
| 62 | .set_ramp_time(RampTime::Micros40); | ||
| 63 | 53 | ||
| 64 | fn config() -> embassy_stm32::Config { | 54 | fn config() -> embassy_stm32::Config { |
| 65 | let mut config = embassy_stm32::Config::default(); | 55 | let mut config = embassy_stm32::Config::default(); |
diff --git a/examples/wasm/src/lib.rs b/examples/wasm/src/lib.rs index 0aa32a70b..61757ebd7 100644 --- a/examples/wasm/src/lib.rs +++ b/examples/wasm/src/lib.rs | |||
| @@ -1,10 +1,8 @@ | |||
| 1 | #![feature(type_alias_impl_trait)] | 1 | #![feature(type_alias_impl_trait)] |
| 2 | #![allow(incomplete_features)] | 2 | #![allow(incomplete_features)] |
| 3 | 3 | ||
| 4 | use embassy::{ | 4 | use embassy::executor::Spawner; |
| 5 | executor::Spawner, | 5 | use embassy::time::{Duration, Timer}; |
| 6 | time::{Duration, Timer}, | ||
| 7 | }; | ||
| 8 | 6 | ||
| 9 | #[embassy::task] | 7 | #[embassy::task] |
| 10 | async fn ticker() { | 8 | async fn ticker() { |
| @@ -13,13 +11,9 @@ async fn ticker() { | |||
| 13 | let mut counter = 0; | 11 | let mut counter = 0; |
| 14 | loop { | 12 | loop { |
| 15 | let document = window.document().expect("should have a document on window"); | 13 | let document = window.document().expect("should have a document on window"); |
| 16 | let list = document | 14 | let list = document.get_element_by_id("log").expect("should have a log element"); |
| 17 | .get_element_by_id("log") | ||
| 18 | .expect("should have a log element"); | ||
| 19 | 15 | ||
| 20 | let li = document | 16 | let li = document.create_element("li").expect("error creating list item element"); |
| 21 | .create_element("li") | ||
| 22 | .expect("error creating list item element"); | ||
| 23 | li.set_text_content(Some(&format!("tick {}", counter))); | 17 | li.set_text_content(Some(&format!("tick {}", counter))); |
| 24 | 18 | ||
| 25 | list.append_child(&li).expect("error appending list item"); | 19 | list.append_child(&li).expect("error appending list item"); |
diff --git a/stm32-gen-features/src/main.rs b/stm32-gen-features/src/main.rs index 72a907522..f40925169 100644 --- a/stm32-gen-features/src/main.rs +++ b/stm32-gen-features/src/main.rs | |||
| @@ -1,6 +1,5 @@ | |||
| 1 | use gen_features::{ | 1 | use gen_features::{ |
| 2 | chip_names_and_cores, embassy_stm32_needed_data, generate_cargo_toml_file, | 2 | chip_names_and_cores, embassy_stm32_needed_data, generate_cargo_toml_file, stm32_metapac_needed_data, |
| 3 | stm32_metapac_needed_data, | ||
| 4 | }; | 3 | }; |
| 5 | 4 | ||
| 6 | fn main() { | 5 | fn main() { |
diff --git a/stm32-metapac-gen/src/lib.rs b/stm32-metapac-gen/src/lib.rs index f5d61ca31..0d761508f 100644 --- a/stm32-metapac-gen/src/lib.rs +++ b/stm32-metapac-gen/src/lib.rs | |||
| @@ -1,16 +1,16 @@ | |||
| 1 | use chiptool::generate::CommonModule; | ||
| 2 | use chiptool::{generate, ir, transform}; | ||
| 3 | use proc_macro2::TokenStream; | ||
| 4 | use regex::Regex; | ||
| 5 | use std::collections::{BTreeMap, HashMap, HashSet}; | 1 | use std::collections::{BTreeMap, HashMap, HashSet}; |
| 6 | use std::fmt::{Debug, Write as _}; | 2 | use std::fmt::{Debug, Write as _}; |
| 7 | use std::fs; | 3 | use std::fs; |
| 8 | use std::fs::File; | 4 | use std::fs::File; |
| 9 | use std::io::Write; | 5 | use std::io::Write; |
| 10 | use std::path::Path; | 6 | use std::path::{Path, PathBuf}; |
| 11 | use std::path::PathBuf; | ||
| 12 | use std::str::FromStr; | 7 | use std::str::FromStr; |
| 13 | 8 | ||
| 9 | use chiptool::generate::CommonModule; | ||
| 10 | use chiptool::{generate, ir, transform}; | ||
| 11 | use proc_macro2::TokenStream; | ||
| 12 | use regex::Regex; | ||
| 13 | |||
| 14 | mod data; | 14 | mod data; |
| 15 | use data::*; | 15 | use data::*; |
| 16 | 16 | ||
| @@ -56,12 +56,7 @@ impl Gen { | |||
| 56 | 56 | ||
| 57 | let mut peripheral_versions: BTreeMap<String, String> = BTreeMap::new(); | 57 | let mut peripheral_versions: BTreeMap<String, String> = BTreeMap::new(); |
| 58 | 58 | ||
| 59 | let gpio_base = core | 59 | let gpio_base = core.peripherals.iter().find(|p| p.name == "GPIOA").unwrap().address as u32; |
| 60 | .peripherals | ||
| 61 | .iter() | ||
| 62 | .find(|p| p.name == "GPIOA") | ||
| 63 | .unwrap() | ||
| 64 | .address as u32; | ||
| 65 | let gpio_stride = 0x400; | 60 | let gpio_stride = 0x400; |
| 66 | 61 | ||
| 67 | for p in &core.peripherals { | 62 | for p in &core.peripherals { |
| @@ -75,9 +70,7 @@ impl Gen { | |||
| 75 | }; | 70 | }; |
| 76 | 71 | ||
| 77 | if let Some(bi) = &p.registers { | 72 | if let Some(bi) = &p.registers { |
| 78 | if let Some(old_version) = | 73 | if let Some(old_version) = peripheral_versions.insert(bi.kind.clone(), bi.version.clone()) { |
| 79 | peripheral_versions.insert(bi.kind.clone(), bi.version.clone()) | ||
| 80 | { | ||
| 81 | if old_version != bi.version { | 74 | if old_version != bi.version { |
| 82 | panic!( | 75 | panic!( |
| 83 | "Peripheral {} has multiple versions: {} and {}", | 76 | "Peripheral {} has multiple versions: {} and {}", |
| @@ -113,8 +106,7 @@ impl Gen { | |||
| 113 | ); | 106 | ); |
| 114 | 107 | ||
| 115 | for (module, version) in &peripheral_versions { | 108 | for (module, version) in &peripheral_versions { |
| 116 | self.all_peripheral_versions | 109 | self.all_peripheral_versions.insert((module.clone(), version.clone())); |
| 117 | .insert((module.clone(), version.clone())); | ||
| 118 | write!( | 110 | write!( |
| 119 | &mut extra, | 111 | &mut extra, |
| 120 | "#[path=\"../../peripherals/{}_{}.rs\"] pub mod {};\n", | 112 | "#[path=\"../../peripherals/{}_{}.rs\"] pub mod {};\n", |
| @@ -122,45 +114,15 @@ impl Gen { | |||
| 122 | ) | 114 | ) |
| 123 | .unwrap(); | 115 | .unwrap(); |
| 124 | } | 116 | } |
| 125 | write!( | 117 | write!(&mut extra, "pub const CORE_INDEX: usize = {};\n", core_index).unwrap(); |
| 126 | &mut extra, | ||
| 127 | "pub const CORE_INDEX: usize = {};\n", | ||
| 128 | core_index | ||
| 129 | ) | ||
| 130 | .unwrap(); | ||
| 131 | 118 | ||
| 132 | let flash = chip.memory.iter().find(|r| r.name == "BANK_1").unwrap(); | 119 | let flash = chip.memory.iter().find(|r| r.name == "BANK_1").unwrap(); |
| 133 | write!( | 120 | write!(&mut extra, "pub const FLASH_BASE: usize = {};\n", flash.address,).unwrap(); |
| 134 | &mut extra, | 121 | write!(&mut extra, "pub const FLASH_SIZE: usize = {};\n", flash.size,).unwrap(); |
| 135 | "pub const FLASH_BASE: usize = {};\n", | ||
| 136 | flash.address, | ||
| 137 | ) | ||
| 138 | .unwrap(); | ||
| 139 | write!( | ||
| 140 | &mut extra, | ||
| 141 | "pub const FLASH_SIZE: usize = {};\n", | ||
| 142 | flash.size, | ||
| 143 | ) | ||
| 144 | .unwrap(); | ||
| 145 | if let Some(settings) = &flash.settings { | 122 | if let Some(settings) = &flash.settings { |
| 146 | write!( | 123 | write!(&mut extra, "pub const ERASE_SIZE: usize = {};\n", settings.erase_size,).unwrap(); |
| 147 | &mut extra, | 124 | write!(&mut extra, "pub const WRITE_SIZE: usize = {};\n", settings.write_size,).unwrap(); |
| 148 | "pub const ERASE_SIZE: usize = {};\n", | 125 | write!(&mut extra, "pub const ERASE_VALUE: u8 = {};\n", settings.erase_value,).unwrap(); |
| 149 | settings.erase_size, | ||
| 150 | ) | ||
| 151 | .unwrap(); | ||
| 152 | write!( | ||
| 153 | &mut extra, | ||
| 154 | "pub const WRITE_SIZE: usize = {};\n", | ||
| 155 | settings.write_size, | ||
| 156 | ) | ||
| 157 | .unwrap(); | ||
| 158 | write!( | ||
| 159 | &mut extra, | ||
| 160 | "pub const ERASE_VALUE: u8 = {};\n", | ||
| 161 | settings.erase_value, | ||
| 162 | ) | ||
| 163 | .unwrap(); | ||
| 164 | } | 126 | } |
| 165 | 127 | ||
| 166 | // Cleanups! | 128 | // Cleanups! |
| @@ -260,11 +222,7 @@ impl Gen { | |||
| 260 | } | 222 | } |
| 261 | 223 | ||
| 262 | fn load_chip(&mut self, name: &str) -> Chip { | 224 | fn load_chip(&mut self, name: &str) -> Chip { |
| 263 | let chip_path = self | 225 | let chip_path = self.opts.data_dir.join("chips").join(&format!("{}.json", name)); |
| 264 | .opts | ||
| 265 | .data_dir | ||
| 266 | .join("chips") | ||
| 267 | .join(&format!("{}.json", name)); | ||
| 268 | let chip = fs::read(chip_path).expect(&format!("Could not load chip {}", name)); | 226 | let chip = fs::read(chip_path).expect(&format!("Could not load chip {}", name)); |
| 269 | serde_yaml::from_slice(&chip).unwrap() | 227 | serde_yaml::from_slice(&chip).unwrap() |
| 270 | } | 228 | } |
| @@ -313,9 +271,7 @@ impl Gen { | |||
| 313 | 271 | ||
| 314 | let mut ir: ir::IR = serde_yaml::from_reader(File::open(regs_path).unwrap()).unwrap(); | 272 | let mut ir: ir::IR = serde_yaml::from_reader(File::open(regs_path).unwrap()).unwrap(); |
| 315 | 273 | ||
| 316 | transform::expand_extends::ExpandExtends {} | 274 | transform::expand_extends::ExpandExtends {}.run(&mut ir).unwrap(); |
| 317 | .run(&mut ir) | ||
| 318 | .unwrap(); | ||
| 319 | 275 | ||
| 320 | transform::map_names(&mut ir, |k, s| match k { | 276 | transform::map_names(&mut ir, |k, s| match k { |
| 321 | transform::NameKind::Block => *s = format!("{}", s), | 277 | transform::NameKind::Block => *s = format!("{}", s), |
| @@ -378,9 +334,7 @@ impl Gen { | |||
| 378 | } | 334 | } |
| 379 | 335 | ||
| 380 | fn bytes_find(haystack: &[u8], needle: &[u8]) -> Option<usize> { | 336 | fn bytes_find(haystack: &[u8], needle: &[u8]) -> Option<usize> { |
| 381 | haystack | 337 | haystack.windows(needle.len()).position(|window| window == needle) |
| 382 | .windows(needle.len()) | ||
| 383 | .position(|window| window == needle) | ||
| 384 | } | 338 | } |
| 385 | 339 | ||
| 386 | fn stringify<T: Debug>(metadata: T) -> String { | 340 | fn stringify<T: Debug>(metadata: T) -> String { |
diff --git a/stm32-metapac-gen/src/main.rs b/stm32-metapac-gen/src/main.rs index 391441302..40a73adf8 100644 --- a/stm32-metapac-gen/src/main.rs +++ b/stm32-metapac-gen/src/main.rs | |||
| @@ -1,5 +1,6 @@ | |||
| 1 | use std::env::args; | 1 | use std::env::args; |
| 2 | use std::path::PathBuf; | 2 | use std::path::PathBuf; |
| 3 | |||
| 3 | use stm32_metapac_gen::*; | 4 | use stm32_metapac_gen::*; |
| 4 | 5 | ||
| 5 | fn main() { | 6 | fn main() { |
diff --git a/stm32-metapac/build.rs b/stm32-metapac/build.rs index 2b3fca809..0c183fa21 100644 --- a/stm32-metapac/build.rs +++ b/stm32-metapac/build.rs | |||
| @@ -1,5 +1,6 @@ | |||
| 1 | use std::env; | 1 | use std::env; |
| 2 | use std::path::PathBuf; | 2 | use std::path::PathBuf; |
| 3 | |||
| 3 | use stm32_metapac_gen::*; | 4 | use stm32_metapac_gen::*; |
| 4 | 5 | ||
| 5 | fn parse_chip_core(chip_and_core: &str) -> (String, Option<String>) { | 6 | fn parse_chip_core(chip_and_core: &str) -> (String, Option<String>) { |
diff --git a/stm32-metapac/build_pregenerated.rs b/stm32-metapac/build_pregenerated.rs index 660a95533..0f0358071 100644 --- a/stm32-metapac/build_pregenerated.rs +++ b/stm32-metapac/build_pregenerated.rs | |||
| @@ -25,10 +25,7 @@ fn main() { | |||
| 25 | crate_dir.display(), | 25 | crate_dir.display(), |
| 26 | chip_core_name | 26 | chip_core_name |
| 27 | ); | 27 | ); |
| 28 | println!( | 28 | println!("cargo:rustc-env=STM32_METAPAC_PAC_PATH=chips/{}/pac.rs", chip_core_name); |
| 29 | "cargo:rustc-env=STM32_METAPAC_PAC_PATH=chips/{}/pac.rs", | ||
| 30 | chip_core_name | ||
| 31 | ); | ||
| 32 | println!( | 29 | println!( |
| 33 | "cargo:rustc-env=STM32_METAPAC_METADATA_PATH=chips/{}/metadata.rs", | 30 | "cargo:rustc-env=STM32_METAPAC_METADATA_PATH=chips/{}/metadata.rs", |
| 34 | chip_core_name | 31 | chip_core_name |
diff --git a/tests/stm32/src/example_common.rs b/tests/stm32/src/example_common.rs index 11b11d685..c47ed75c4 100644 --- a/tests/stm32/src/example_common.rs +++ b/tests/stm32/src/example_common.rs | |||
| @@ -1,14 +1,12 @@ | |||
| 1 | #![macro_use] | 1 | #![macro_use] |
| 2 | 2 | ||
| 3 | use defmt_rtt as _; | 3 | use core::sync::atomic::{AtomicUsize, Ordering}; |
| 4 | |||
| 5 | pub use defmt::*; | ||
| 4 | #[allow(unused)] | 6 | #[allow(unused)] |
| 5 | use embassy_stm32::time::Hertz; | 7 | use embassy_stm32::time::Hertz; |
| 6 | use embassy_stm32::Config; | 8 | use embassy_stm32::Config; |
| 7 | use panic_probe as _; | 9 | use {defmt_rtt as _, panic_probe as _}; |
| 8 | |||
| 9 | pub use defmt::*; | ||
| 10 | |||
| 11 | use core::sync::atomic::{AtomicUsize, Ordering}; | ||
| 12 | 10 | ||
| 13 | defmt::timestamp! {"{=u64}", { | 11 | defmt::timestamp! {"{=u64}", { |
| 14 | static COUNT: AtomicUsize = AtomicUsize::new(0); | 12 | static COUNT: AtomicUsize = AtomicUsize::new(0); |
diff --git a/xtask/src/main.rs b/xtask/src/main.rs index d8d5e07da..b8b453fd0 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs | |||
| @@ -1,10 +1,9 @@ | |||
| 1 | #![allow(dead_code)] | 1 | #![allow(dead_code)] |
| 2 | #![deny(unused_must_use)] | 2 | #![deny(unused_must_use)] |
| 3 | 3 | ||
| 4 | use std::format; | 4 | use std::path::{Path, PathBuf}; |
| 5 | use std::{env, fs, path::PathBuf}; | 5 | use std::{env, format, fs}; |
| 6 | 6 | ||
| 7 | use std::path::Path; | ||
| 8 | use walkdir::WalkDir; | 7 | use walkdir::WalkDir; |
| 9 | use xshell::{cmd, Cmd}; | 8 | use xshell::{cmd, Cmd}; |
| 10 | use yaml_rust::YamlLoader; | 9 | use yaml_rust::YamlLoader; |
| @@ -67,10 +66,7 @@ impl Realm { | |||
| 67 | fn task_check(realm: Realm) -> Result<(), anyhow::Error> { | 66 | fn task_check(realm: Realm) -> Result<(), anyhow::Error> { |
| 68 | let _e = xshell::pushenv("CI", "true"); | 67 | let _e = xshell::pushenv("CI", "true"); |
| 69 | 68 | ||
| 70 | let matrix_yaml = root_dir() | 69 | let matrix_yaml = root_dir().join(".github").join("workflows").join("rust.yml"); |
| 71 | .join(".github") | ||
| 72 | .join("workflows") | ||
| 73 | .join("rust.yml"); | ||
| 74 | 70 | ||
| 75 | let matrix = YamlLoader::load_from_str(&*fs::read_to_string(matrix_yaml).unwrap()).unwrap(); | 71 | let matrix = YamlLoader::load_from_str(&*fs::read_to_string(matrix_yaml).unwrap()).unwrap(); |
| 76 | 72 | ||
