diff options
| author | Dario Nieuwenhuis <[email protected]> | 2024-04-05 00:35:25 +0200 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2024-04-05 00:48:46 +0200 |
| commit | a84b33995eacc32e0e13d70293fa9bd7b2bd75f8 (patch) | |
| tree | cfd48dbdad8885495cf20c4832f373444b867397 /embassy-rp | |
| parent | ab85eb4b60cd49ebcd43d2305f42327685f5e5a6 (diff) | |
rp: remove mod sealed.
Diffstat (limited to 'embassy-rp')
| -rw-r--r-- | embassy-rp/src/adc.rs | 24 | ||||
| -rw-r--r-- | embassy-rp/src/clocks.rs | 11 | ||||
| -rw-r--r-- | embassy-rp/src/dma.rs | 23 | ||||
| -rw-r--r-- | embassy-rp/src/flash.rs | 16 | ||||
| -rw-r--r-- | embassy-rp/src/gpio.rs | 96 | ||||
| -rw-r--r-- | embassy-rp/src/i2c.rs | 51 | ||||
| -rw-r--r-- | embassy-rp/src/pio/mod.rs | 64 | ||||
| -rw-r--r-- | embassy-rp/src/pwm.rs | 12 | ||||
| -rw-r--r-- | embassy-rp/src/rtc/mod.rs | 11 | ||||
| -rw-r--r-- | embassy-rp/src/spi.rs | 27 | ||||
| -rw-r--r-- | embassy-rp/src/uart/mod.rs | 55 | ||||
| -rw-r--r-- | embassy-rp/src/usb.rs | 13 |
12 files changed, 188 insertions, 215 deletions
diff --git a/embassy-rp/src/adc.rs b/embassy-rp/src/adc.rs index 4c01fe195..101c5b71f 100644 --- a/embassy-rp/src/adc.rs +++ b/embassy-rp/src/adc.rs | |||
| @@ -8,8 +8,7 @@ use core::task::Poll; | |||
| 8 | use embassy_hal_internal::{into_ref, PeripheralRef}; | 8 | use embassy_hal_internal::{into_ref, PeripheralRef}; |
| 9 | use embassy_sync::waitqueue::AtomicWaker; | 9 | use embassy_sync::waitqueue::AtomicWaker; |
| 10 | 10 | ||
| 11 | use crate::gpio::sealed::Pin as GpioPin; | 11 | use crate::gpio::{self, AnyPin, Pull, SealedPin as GpioPin}; |
| 12 | use crate::gpio::{self, AnyPin, Pull}; | ||
| 13 | use crate::interrupt::typelevel::Binding; | 12 | use crate::interrupt::typelevel::Binding; |
| 14 | use crate::interrupt::InterruptExt; | 13 | use crate::interrupt::InterruptExt; |
| 15 | use crate::peripherals::{ADC, ADC_TEMP_SENSOR}; | 14 | use crate::peripherals::{ADC, ADC_TEMP_SENSOR}; |
| @@ -334,29 +333,28 @@ impl interrupt::typelevel::Handler<interrupt::typelevel::ADC_IRQ_FIFO> for Inter | |||
| 334 | } | 333 | } |
| 335 | } | 334 | } |
| 336 | 335 | ||
| 337 | mod sealed { | 336 | trait SealedAdcSample: crate::dma::Word {} |
| 338 | pub trait AdcSample: crate::dma::Word {} | 337 | trait SealedAdcChannel {} |
| 339 | |||
| 340 | pub trait AdcChannel {} | ||
| 341 | } | ||
| 342 | 338 | ||
| 343 | /// ADC sample. | 339 | /// ADC sample. |
| 344 | pub trait AdcSample: sealed::AdcSample {} | 340 | #[allow(private_bounds)] |
| 341 | pub trait AdcSample: SealedAdcSample {} | ||
| 345 | 342 | ||
| 346 | impl sealed::AdcSample for u16 {} | 343 | impl SealedAdcSample for u16 {} |
| 347 | impl AdcSample for u16 {} | 344 | impl AdcSample for u16 {} |
| 348 | 345 | ||
| 349 | impl sealed::AdcSample for u8 {} | 346 | impl SealedAdcSample for u8 {} |
| 350 | impl AdcSample for u8 {} | 347 | impl AdcSample for u8 {} |
| 351 | 348 | ||
| 352 | /// ADC channel. | 349 | /// ADC channel. |
| 353 | pub trait AdcChannel: sealed::AdcChannel {} | 350 | #[allow(private_bounds)] |
| 351 | pub trait AdcChannel: SealedAdcChannel {} | ||
| 354 | /// ADC pin. | 352 | /// ADC pin. |
| 355 | pub trait AdcPin: AdcChannel + gpio::Pin {} | 353 | pub trait AdcPin: AdcChannel + gpio::Pin {} |
| 356 | 354 | ||
| 357 | macro_rules! impl_pin { | 355 | macro_rules! impl_pin { |
| 358 | ($pin:ident, $channel:expr) => { | 356 | ($pin:ident, $channel:expr) => { |
| 359 | impl sealed::AdcChannel for peripherals::$pin {} | 357 | impl SealedAdcChannel for peripherals::$pin {} |
| 360 | impl AdcChannel for peripherals::$pin {} | 358 | impl AdcChannel for peripherals::$pin {} |
| 361 | impl AdcPin for peripherals::$pin {} | 359 | impl AdcPin for peripherals::$pin {} |
| 362 | }; | 360 | }; |
| @@ -367,5 +365,5 @@ impl_pin!(PIN_27, 1); | |||
| 367 | impl_pin!(PIN_28, 2); | 365 | impl_pin!(PIN_28, 2); |
| 368 | impl_pin!(PIN_29, 3); | 366 | impl_pin!(PIN_29, 3); |
| 369 | 367 | ||
| 370 | impl sealed::AdcChannel for peripherals::ADC_TEMP_SENSOR {} | 368 | impl SealedAdcChannel for peripherals::ADC_TEMP_SENSOR {} |
| 371 | impl AdcChannel for peripherals::ADC_TEMP_SENSOR {} | 369 | impl AdcChannel for peripherals::ADC_TEMP_SENSOR {} |
diff --git a/embassy-rp/src/clocks.rs b/embassy-rp/src/clocks.rs index b7f6aeac9..bedb79464 100644 --- a/embassy-rp/src/clocks.rs +++ b/embassy-rp/src/clocks.rs | |||
| @@ -6,8 +6,7 @@ use core::sync::atomic::{AtomicU16, AtomicU32, Ordering}; | |||
| 6 | use embassy_hal_internal::{into_ref, PeripheralRef}; | 6 | use embassy_hal_internal::{into_ref, PeripheralRef}; |
| 7 | use pac::clocks::vals::*; | 7 | use pac::clocks::vals::*; |
| 8 | 8 | ||
| 9 | use crate::gpio::sealed::Pin; | 9 | use crate::gpio::{AnyPin, SealedPin}; |
| 10 | use crate::gpio::AnyPin; | ||
| 11 | use crate::pac::common::{Reg, RW}; | 10 | use crate::pac::common::{Reg, RW}; |
| 12 | use crate::{pac, reset, Peripheral}; | 11 | use crate::{pac, reset, Peripheral}; |
| 13 | 12 | ||
| @@ -788,14 +787,14 @@ impl_gpinpin!(PIN_20, 20, 0); | |||
| 788 | impl_gpinpin!(PIN_22, 22, 1); | 787 | impl_gpinpin!(PIN_22, 22, 1); |
| 789 | 788 | ||
| 790 | /// General purpose clock input driver. | 789 | /// General purpose clock input driver. |
| 791 | pub struct Gpin<'d, T: Pin> { | 790 | pub struct Gpin<'d, T: GpinPin> { |
| 792 | gpin: PeripheralRef<'d, AnyPin>, | 791 | gpin: PeripheralRef<'d, AnyPin>, |
| 793 | _phantom: PhantomData<T>, | 792 | _phantom: PhantomData<T>, |
| 794 | } | 793 | } |
| 795 | 794 | ||
| 796 | impl<'d, T: Pin> Gpin<'d, T> { | 795 | impl<'d, T: GpinPin> Gpin<'d, T> { |
| 797 | /// Create new gpin driver. | 796 | /// Create new gpin driver. |
| 798 | pub fn new<P: GpinPin>(gpin: impl Peripheral<P = P> + 'd) -> Gpin<'d, P> { | 797 | pub fn new(gpin: impl Peripheral<P = T> + 'd) -> Self { |
| 799 | into_ref!(gpin); | 798 | into_ref!(gpin); |
| 800 | 799 | ||
| 801 | gpin.gpio().ctrl().write(|w| w.set_funcsel(0x08)); | 800 | gpin.gpio().ctrl().write(|w| w.set_funcsel(0x08)); |
| @@ -811,7 +810,7 @@ impl<'d, T: Pin> Gpin<'d, T> { | |||
| 811 | // } | 810 | // } |
| 812 | } | 811 | } |
| 813 | 812 | ||
| 814 | impl<'d, T: Pin> Drop for Gpin<'d, T> { | 813 | impl<'d, T: GpinPin> Drop for Gpin<'d, T> { |
| 815 | fn drop(&mut self) { | 814 | fn drop(&mut self) { |
| 816 | self.gpin | 815 | self.gpin |
| 817 | .gpio() | 816 | .gpio() |
diff --git a/embassy-rp/src/dma.rs b/embassy-rp/src/dma.rs index 44aabce6b..e6374a86c 100644 --- a/embassy-rp/src/dma.rs +++ b/embassy-rp/src/dma.rs | |||
| @@ -208,14 +208,12 @@ pub(crate) const CHANNEL_COUNT: usize = 12; | |||
| 208 | const NEW_AW: AtomicWaker = AtomicWaker::new(); | 208 | const NEW_AW: AtomicWaker = AtomicWaker::new(); |
| 209 | static CHANNEL_WAKERS: [AtomicWaker; CHANNEL_COUNT] = [NEW_AW; CHANNEL_COUNT]; | 209 | static CHANNEL_WAKERS: [AtomicWaker; CHANNEL_COUNT] = [NEW_AW; CHANNEL_COUNT]; |
| 210 | 210 | ||
| 211 | mod sealed { | 211 | trait SealedChannel {} |
| 212 | pub trait Channel {} | 212 | trait SealedWord {} |
| 213 | |||
| 214 | pub trait Word {} | ||
| 215 | } | ||
| 216 | 213 | ||
| 217 | /// DMA channel interface. | 214 | /// DMA channel interface. |
| 218 | pub trait Channel: Peripheral<P = Self> + sealed::Channel + Into<AnyChannel> + Sized + 'static { | 215 | #[allow(private_bounds)] |
| 216 | pub trait Channel: Peripheral<P = Self> + SealedChannel + Into<AnyChannel> + Sized + 'static { | ||
| 219 | /// Channel number. | 217 | /// Channel number. |
| 220 | fn number(&self) -> u8; | 218 | fn number(&self) -> u8; |
| 221 | 219 | ||
| @@ -231,26 +229,27 @@ pub trait Channel: Peripheral<P = Self> + sealed::Channel + Into<AnyChannel> + S | |||
| 231 | } | 229 | } |
| 232 | 230 | ||
| 233 | /// DMA word. | 231 | /// DMA word. |
| 234 | pub trait Word: sealed::Word { | 232 | #[allow(private_bounds)] |
| 233 | pub trait Word: SealedWord { | ||
| 235 | /// Word size. | 234 | /// Word size. |
| 236 | fn size() -> vals::DataSize; | 235 | fn size() -> vals::DataSize; |
| 237 | } | 236 | } |
| 238 | 237 | ||
| 239 | impl sealed::Word for u8 {} | 238 | impl SealedWord for u8 {} |
| 240 | impl Word for u8 { | 239 | impl Word for u8 { |
| 241 | fn size() -> vals::DataSize { | 240 | fn size() -> vals::DataSize { |
| 242 | vals::DataSize::SIZE_BYTE | 241 | vals::DataSize::SIZE_BYTE |
| 243 | } | 242 | } |
| 244 | } | 243 | } |
| 245 | 244 | ||
| 246 | impl sealed::Word for u16 {} | 245 | impl SealedWord for u16 {} |
| 247 | impl Word for u16 { | 246 | impl Word for u16 { |
| 248 | fn size() -> vals::DataSize { | 247 | fn size() -> vals::DataSize { |
| 249 | vals::DataSize::SIZE_HALFWORD | 248 | vals::DataSize::SIZE_HALFWORD |
| 250 | } | 249 | } |
| 251 | } | 250 | } |
| 252 | 251 | ||
| 253 | impl sealed::Word for u32 {} | 252 | impl SealedWord for u32 {} |
| 254 | impl Word for u32 { | 253 | impl Word for u32 { |
| 255 | fn size() -> vals::DataSize { | 254 | fn size() -> vals::DataSize { |
| 256 | vals::DataSize::SIZE_WORD | 255 | vals::DataSize::SIZE_WORD |
| @@ -264,7 +263,7 @@ pub struct AnyChannel { | |||
| 264 | 263 | ||
| 265 | impl_peripheral!(AnyChannel); | 264 | impl_peripheral!(AnyChannel); |
| 266 | 265 | ||
| 267 | impl sealed::Channel for AnyChannel {} | 266 | impl SealedChannel for AnyChannel {} |
| 268 | impl Channel for AnyChannel { | 267 | impl Channel for AnyChannel { |
| 269 | fn number(&self) -> u8 { | 268 | fn number(&self) -> u8 { |
| 270 | self.number | 269 | self.number |
| @@ -273,7 +272,7 @@ impl Channel for AnyChannel { | |||
| 273 | 272 | ||
| 274 | macro_rules! channel { | 273 | macro_rules! channel { |
| 275 | ($name:ident, $num:expr) => { | 274 | ($name:ident, $num:expr) => { |
| 276 | impl sealed::Channel for peripherals::$name {} | 275 | impl SealedChannel for peripherals::$name {} |
| 277 | impl Channel for peripherals::$name { | 276 | impl Channel for peripherals::$name { |
| 278 | fn number(&self) -> u8 { | 277 | fn number(&self) -> u8 { |
| 279 | $num | 278 | $num |
diff --git a/embassy-rp/src/flash.rs b/embassy-rp/src/flash.rs index 422b77400..45b385cb4 100644 --- a/embassy-rp/src/flash.rs +++ b/embassy-rp/src/flash.rs | |||
| @@ -903,22 +903,22 @@ pub(crate) unsafe fn in_ram(operation: impl FnOnce()) -> Result<(), Error> { | |||
| 903 | Ok(()) | 903 | Ok(()) |
| 904 | } | 904 | } |
| 905 | 905 | ||
| 906 | mod sealed { | 906 | trait SealedInstance {} |
| 907 | pub trait Instance {} | 907 | trait SealedMode {} |
| 908 | pub trait Mode {} | ||
| 909 | } | ||
| 910 | 908 | ||
| 911 | /// Flash instance. | 909 | /// Flash instance. |
| 912 | pub trait Instance: sealed::Instance {} | 910 | #[allow(private_bounds)] |
| 911 | pub trait Instance: SealedInstance {} | ||
| 913 | /// Flash mode. | 912 | /// Flash mode. |
| 914 | pub trait Mode: sealed::Mode {} | 913 | #[allow(private_bounds)] |
| 914 | pub trait Mode: SealedMode {} | ||
| 915 | 915 | ||
| 916 | impl sealed::Instance for FLASH {} | 916 | impl SealedInstance for FLASH {} |
| 917 | impl Instance for FLASH {} | 917 | impl Instance for FLASH {} |
| 918 | 918 | ||
| 919 | macro_rules! impl_mode { | 919 | macro_rules! impl_mode { |
| 920 | ($name:ident) => { | 920 | ($name:ident) => { |
| 921 | impl sealed::Mode for $name {} | 921 | impl SealedMode for $name {} |
| 922 | impl Mode for $name {} | 922 | impl Mode for $name {} |
| 923 | }; | 923 | }; |
| 924 | } | 924 | } |
diff --git a/embassy-rp/src/gpio.rs b/embassy-rp/src/gpio.rs index a84c00a2c..ea87fd9da 100644 --- a/embassy-rp/src/gpio.rs +++ b/embassy-rp/src/gpio.rs | |||
| @@ -8,7 +8,6 @@ use core::task::{Context, Poll}; | |||
| 8 | use embassy_hal_internal::{impl_peripheral, into_ref, PeripheralRef}; | 8 | use embassy_hal_internal::{impl_peripheral, into_ref, PeripheralRef}; |
| 9 | use embassy_sync::waitqueue::AtomicWaker; | 9 | use embassy_sync::waitqueue::AtomicWaker; |
| 10 | 10 | ||
| 11 | use self::sealed::Pin as _; | ||
| 12 | use crate::interrupt::InterruptExt; | 11 | use crate::interrupt::InterruptExt; |
| 13 | use crate::pac::common::{Reg, RW}; | 12 | use crate::pac::common::{Reg, RW}; |
| 14 | use crate::pac::SIO; | 13 | use crate::pac::SIO; |
| @@ -802,68 +801,65 @@ impl<'w> Drop for DormantWake<'w> { | |||
| 802 | } | 801 | } |
| 803 | } | 802 | } |
| 804 | 803 | ||
| 805 | pub(crate) mod sealed { | 804 | pub(crate) trait SealedPin: Sized { |
| 806 | use super::*; | 805 | fn pin_bank(&self) -> u8; |
| 807 | |||
| 808 | pub trait Pin: Sized { | ||
| 809 | fn pin_bank(&self) -> u8; | ||
| 810 | 806 | ||
| 811 | #[inline] | 807 | #[inline] |
| 812 | fn _pin(&self) -> u8 { | 808 | fn _pin(&self) -> u8 { |
| 813 | self.pin_bank() & 0x1f | 809 | self.pin_bank() & 0x1f |
| 814 | } | 810 | } |
| 815 | 811 | ||
| 816 | #[inline] | 812 | #[inline] |
| 817 | fn _bank(&self) -> Bank { | 813 | fn _bank(&self) -> Bank { |
| 818 | match self.pin_bank() >> 5 { | 814 | match self.pin_bank() >> 5 { |
| 819 | #[cfg(feature = "qspi-as-gpio")] | 815 | #[cfg(feature = "qspi-as-gpio")] |
| 820 | 1 => Bank::Qspi, | 816 | 1 => Bank::Qspi, |
| 821 | _ => Bank::Bank0, | 817 | _ => Bank::Bank0, |
| 822 | } | ||
| 823 | } | 818 | } |
| 819 | } | ||
| 824 | 820 | ||
| 825 | fn io(&self) -> pac::io::Io { | 821 | fn io(&self) -> pac::io::Io { |
| 826 | match self._bank() { | 822 | match self._bank() { |
| 827 | Bank::Bank0 => crate::pac::IO_BANK0, | 823 | Bank::Bank0 => crate::pac::IO_BANK0, |
| 828 | #[cfg(feature = "qspi-as-gpio")] | 824 | #[cfg(feature = "qspi-as-gpio")] |
| 829 | Bank::Qspi => crate::pac::IO_QSPI, | 825 | Bank::Qspi => crate::pac::IO_QSPI, |
| 830 | } | ||
| 831 | } | 826 | } |
| 827 | } | ||
| 832 | 828 | ||
| 833 | fn gpio(&self) -> pac::io::Gpio { | 829 | fn gpio(&self) -> pac::io::Gpio { |
| 834 | self.io().gpio(self._pin() as _) | 830 | self.io().gpio(self._pin() as _) |
| 835 | } | 831 | } |
| 836 | 832 | ||
| 837 | fn pad_ctrl(&self) -> Reg<pac::pads::regs::GpioCtrl, RW> { | 833 | fn pad_ctrl(&self) -> Reg<pac::pads::regs::GpioCtrl, RW> { |
| 838 | let block = match self._bank() { | 834 | let block = match self._bank() { |
| 839 | Bank::Bank0 => crate::pac::PADS_BANK0, | 835 | Bank::Bank0 => crate::pac::PADS_BANK0, |
| 840 | #[cfg(feature = "qspi-as-gpio")] | 836 | #[cfg(feature = "qspi-as-gpio")] |
| 841 | Bank::Qspi => crate::pac::PADS_QSPI, | 837 | Bank::Qspi => crate::pac::PADS_QSPI, |
| 842 | }; | 838 | }; |
| 843 | block.gpio(self._pin() as _) | 839 | block.gpio(self._pin() as _) |
| 844 | } | 840 | } |
| 845 | 841 | ||
| 846 | fn sio_out(&self) -> pac::sio::Gpio { | 842 | fn sio_out(&self) -> pac::sio::Gpio { |
| 847 | SIO.gpio_out(self._bank() as _) | 843 | SIO.gpio_out(self._bank() as _) |
| 848 | } | 844 | } |
| 849 | 845 | ||
| 850 | fn sio_oe(&self) -> pac::sio::Gpio { | 846 | fn sio_oe(&self) -> pac::sio::Gpio { |
| 851 | SIO.gpio_oe(self._bank() as _) | 847 | SIO.gpio_oe(self._bank() as _) |
| 852 | } | 848 | } |
| 853 | 849 | ||
| 854 | fn sio_in(&self) -> Reg<u32, RW> { | 850 | fn sio_in(&self) -> Reg<u32, RW> { |
| 855 | SIO.gpio_in(self._bank() as _) | 851 | SIO.gpio_in(self._bank() as _) |
| 856 | } | 852 | } |
| 857 | 853 | ||
| 858 | fn int_proc(&self) -> pac::io::Int { | 854 | fn int_proc(&self) -> pac::io::Int { |
| 859 | let proc = SIO.cpuid().read(); | 855 | let proc = SIO.cpuid().read(); |
| 860 | self.io().int_proc(proc as _) | 856 | self.io().int_proc(proc as _) |
| 861 | } | ||
| 862 | } | 857 | } |
| 863 | } | 858 | } |
| 864 | 859 | ||
| 865 | /// Interface for a Pin that can be configured by an [Input] or [Output] driver, or converted to an [AnyPin]. | 860 | /// Interface for a Pin that can be configured by an [Input] or [Output] driver, or converted to an [AnyPin]. |
| 866 | pub trait Pin: Peripheral<P = Self> + Into<AnyPin> + sealed::Pin + Sized + 'static { | 861 | #[allow(private_bounds)] |
| 862 | pub trait Pin: Peripheral<P = Self> + Into<AnyPin> + SealedPin + Sized + 'static { | ||
| 867 | /// Degrade to a generic pin struct | 863 | /// Degrade to a generic pin struct |
| 868 | fn degrade(self) -> AnyPin { | 864 | fn degrade(self) -> AnyPin { |
| 869 | AnyPin { | 865 | AnyPin { |
| @@ -903,7 +899,7 @@ impl AnyPin { | |||
| 903 | impl_peripheral!(AnyPin); | 899 | impl_peripheral!(AnyPin); |
| 904 | 900 | ||
| 905 | impl Pin for AnyPin {} | 901 | impl Pin for AnyPin {} |
| 906 | impl sealed::Pin for AnyPin { | 902 | impl SealedPin for AnyPin { |
| 907 | fn pin_bank(&self) -> u8 { | 903 | fn pin_bank(&self) -> u8 { |
| 908 | self.pin_bank | 904 | self.pin_bank |
| 909 | } | 905 | } |
| @@ -914,7 +910,7 @@ impl sealed::Pin for AnyPin { | |||
| 914 | macro_rules! impl_pin { | 910 | macro_rules! impl_pin { |
| 915 | ($name:ident, $bank:expr, $pin_num:expr) => { | 911 | ($name:ident, $bank:expr, $pin_num:expr) => { |
| 916 | impl Pin for peripherals::$name {} | 912 | impl Pin for peripherals::$name {} |
| 917 | impl sealed::Pin for peripherals::$name { | 913 | impl SealedPin for peripherals::$name { |
| 918 | #[inline] | 914 | #[inline] |
| 919 | fn pin_bank(&self) -> u8 { | 915 | fn pin_bank(&self) -> u8 { |
| 920 | ($bank as u8) * 32 + $pin_num | 916 | ($bank as u8) * 32 + $pin_num |
diff --git a/embassy-rp/src/i2c.rs b/embassy-rp/src/i2c.rs index 26a819b25..256875b4a 100644 --- a/embassy-rp/src/i2c.rs +++ b/embassy-rp/src/i2c.rs | |||
| @@ -784,34 +784,24 @@ pub fn i2c_reserved_addr(addr: u16) -> bool { | |||
| 784 | ((addr & 0x78) == 0 || (addr & 0x78) == 0x78) && addr != 0 | 784 | ((addr & 0x78) == 0 || (addr & 0x78) == 0x78) && addr != 0 |
| 785 | } | 785 | } |
| 786 | 786 | ||
| 787 | mod sealed { | 787 | pub(crate) trait SealedInstance { |
| 788 | use embassy_sync::waitqueue::AtomicWaker; | 788 | const TX_DREQ: u8; |
| 789 | const RX_DREQ: u8; | ||
| 789 | 790 | ||
| 790 | use crate::interrupt; | 791 | fn regs() -> crate::pac::i2c::I2c; |
| 791 | 792 | fn reset() -> crate::pac::resets::regs::Peripherals; | |
| 792 | pub trait Instance { | 793 | fn waker() -> &'static AtomicWaker; |
| 793 | const TX_DREQ: u8; | ||
| 794 | const RX_DREQ: u8; | ||
| 795 | |||
| 796 | type Interrupt: interrupt::typelevel::Interrupt; | ||
| 797 | |||
| 798 | fn regs() -> crate::pac::i2c::I2c; | ||
| 799 | fn reset() -> crate::pac::resets::regs::Peripherals; | ||
| 800 | fn waker() -> &'static AtomicWaker; | ||
| 801 | } | ||
| 802 | |||
| 803 | pub trait Mode {} | ||
| 804 | |||
| 805 | pub trait SdaPin<T: Instance> {} | ||
| 806 | pub trait SclPin<T: Instance> {} | ||
| 807 | } | 794 | } |
| 808 | 795 | ||
| 796 | trait SealedMode {} | ||
| 797 | |||
| 809 | /// Driver mode. | 798 | /// Driver mode. |
| 810 | pub trait Mode: sealed::Mode {} | 799 | #[allow(private_bounds)] |
| 800 | pub trait Mode: SealedMode {} | ||
| 811 | 801 | ||
| 812 | macro_rules! impl_mode { | 802 | macro_rules! impl_mode { |
| 813 | ($name:ident) => { | 803 | ($name:ident) => { |
| 814 | impl sealed::Mode for $name {} | 804 | impl SealedMode for $name {} |
| 815 | impl Mode for $name {} | 805 | impl Mode for $name {} |
| 816 | }; | 806 | }; |
| 817 | } | 807 | } |
| @@ -825,16 +815,18 @@ impl_mode!(Blocking); | |||
| 825 | impl_mode!(Async); | 815 | impl_mode!(Async); |
| 826 | 816 | ||
| 827 | /// I2C instance. | 817 | /// I2C instance. |
| 828 | pub trait Instance: sealed::Instance {} | 818 | #[allow(private_bounds)] |
| 819 | pub trait Instance: SealedInstance { | ||
| 820 | /// Interrupt for this peripheral. | ||
| 821 | type Interrupt: interrupt::typelevel::Interrupt; | ||
| 822 | } | ||
| 829 | 823 | ||
| 830 | macro_rules! impl_instance { | 824 | macro_rules! impl_instance { |
| 831 | ($type:ident, $irq:ident, $reset:ident, $tx_dreq:expr, $rx_dreq:expr) => { | 825 | ($type:ident, $irq:ident, $reset:ident, $tx_dreq:expr, $rx_dreq:expr) => { |
| 832 | impl sealed::Instance for peripherals::$type { | 826 | impl SealedInstance for peripherals::$type { |
| 833 | const TX_DREQ: u8 = $tx_dreq; | 827 | const TX_DREQ: u8 = $tx_dreq; |
| 834 | const RX_DREQ: u8 = $rx_dreq; | 828 | const RX_DREQ: u8 = $rx_dreq; |
| 835 | 829 | ||
| 836 | type Interrupt = crate::interrupt::typelevel::$irq; | ||
| 837 | |||
| 838 | #[inline] | 830 | #[inline] |
| 839 | fn regs() -> pac::i2c::I2c { | 831 | fn regs() -> pac::i2c::I2c { |
| 840 | pac::$type | 832 | pac::$type |
| @@ -854,7 +846,9 @@ macro_rules! impl_instance { | |||
| 854 | &WAKER | 846 | &WAKER |
| 855 | } | 847 | } |
| 856 | } | 848 | } |
| 857 | impl Instance for peripherals::$type {} | 849 | impl Instance for peripherals::$type { |
| 850 | type Interrupt = crate::interrupt::typelevel::$irq; | ||
| 851 | } | ||
| 858 | }; | 852 | }; |
| 859 | } | 853 | } |
| 860 | 854 | ||
| @@ -862,13 +856,12 @@ impl_instance!(I2C0, I2C0_IRQ, set_i2c0, 32, 33); | |||
| 862 | impl_instance!(I2C1, I2C1_IRQ, set_i2c1, 34, 35); | 856 | impl_instance!(I2C1, I2C1_IRQ, set_i2c1, 34, 35); |
| 863 | 857 | ||
| 864 | /// SDA pin. | 858 | /// SDA pin. |
| 865 | pub trait SdaPin<T: Instance>: sealed::SdaPin<T> + crate::gpio::Pin {} | 859 | pub trait SdaPin<T: Instance>: crate::gpio::Pin {} |
| 866 | /// SCL pin. | 860 | /// SCL pin. |
| 867 | pub trait SclPin<T: Instance>: sealed::SclPin<T> + crate::gpio::Pin {} | 861 | pub trait SclPin<T: Instance>: crate::gpio::Pin {} |
| 868 | 862 | ||
| 869 | macro_rules! impl_pin { | 863 | macro_rules! impl_pin { |
| 870 | ($pin:ident, $instance:ident, $function:ident) => { | 864 | ($pin:ident, $instance:ident, $function:ident) => { |
| 871 | impl sealed::$function<peripherals::$instance> for peripherals::$pin {} | ||
| 872 | impl $function<peripherals::$instance> for peripherals::$pin {} | 865 | impl $function<peripherals::$instance> for peripherals::$pin {} |
| 873 | }; | 866 | }; |
| 874 | } | 867 | } |
diff --git a/embassy-rp/src/pio/mod.rs b/embassy-rp/src/pio/mod.rs index 7eca700ba..2e5c57a26 100644 --- a/embassy-rp/src/pio/mod.rs +++ b/embassy-rp/src/pio/mod.rs | |||
| @@ -15,8 +15,7 @@ use pac::pio::vals::SmExecctrlStatusSel; | |||
| 15 | use pio::{Program, SideSet, Wrap}; | 15 | use pio::{Program, SideSet, Wrap}; |
| 16 | 16 | ||
| 17 | use crate::dma::{Channel, Transfer, Word}; | 17 | use crate::dma::{Channel, Transfer, Word}; |
| 18 | use crate::gpio::sealed::Pin as SealedPin; | 18 | use crate::gpio::{self, AnyPin, Drive, Level, Pull, SealedPin, SlewRate}; |
| 19 | use crate::gpio::{self, AnyPin, Drive, Level, Pull, SlewRate}; | ||
| 20 | use crate::interrupt::typelevel::{Binding, Handler, Interrupt}; | 19 | use crate::interrupt::typelevel::{Binding, Handler, Interrupt}; |
| 21 | use crate::pac::dma::vals::TreqSel; | 20 | use crate::pac::dma::vals::TreqSel; |
| 22 | use crate::relocate::RelocatedProgram; | 21 | use crate::relocate::RelocatedProgram; |
| @@ -695,6 +694,12 @@ impl<'d, PIO: Instance + 'd, const SM: usize> StateMachine<'d, PIO, SM> { | |||
| 695 | } | 694 | } |
| 696 | } | 695 | } |
| 697 | 696 | ||
| 697 | /// Set the clock divider for this state machine. | ||
| 698 | pub fn set_clock_divider(&mut self, clock_divider: FixedU32<U8>) { | ||
| 699 | let sm = Self::this_sm(); | ||
| 700 | sm.clkdiv().write(|w| w.0 = clock_divider.to_bits() << 8); | ||
| 701 | } | ||
| 702 | |||
| 698 | #[inline(always)] | 703 | #[inline(always)] |
| 699 | fn this_sm() -> crate::pac::pio::StateMachine { | 704 | fn this_sm() -> crate::pac::pio::StateMachine { |
| 700 | PIO::PIO.sm(SM) | 705 | PIO::PIO.sm(SM) |
| @@ -1148,49 +1153,47 @@ fn on_pio_drop<PIO: Instance>() { | |||
| 1148 | } | 1153 | } |
| 1149 | } | 1154 | } |
| 1150 | 1155 | ||
| 1151 | mod sealed { | 1156 | trait SealedInstance { |
| 1152 | use super::*; | 1157 | const PIO_NO: u8; |
| 1153 | 1158 | const PIO: &'static crate::pac::pio::Pio; | |
| 1154 | pub trait PioPin {} | 1159 | const FUNCSEL: crate::pac::io::vals::Gpio0ctrlFuncsel; |
| 1155 | 1160 | ||
| 1156 | pub trait Instance { | 1161 | #[inline] |
| 1157 | const PIO_NO: u8; | 1162 | fn wakers() -> &'static Wakers { |
| 1158 | const PIO: &'static crate::pac::pio::Pio; | 1163 | const NEW_AW: AtomicWaker = AtomicWaker::new(); |
| 1159 | const FUNCSEL: crate::pac::io::vals::Gpio0ctrlFuncsel; | 1164 | static WAKERS: Wakers = Wakers([NEW_AW; 12]); |
| 1160 | type Interrupt: crate::interrupt::typelevel::Interrupt; | ||
| 1161 | |||
| 1162 | #[inline] | ||
| 1163 | fn wakers() -> &'static Wakers { | ||
| 1164 | const NEW_AW: AtomicWaker = AtomicWaker::new(); | ||
| 1165 | static WAKERS: Wakers = Wakers([NEW_AW; 12]); | ||
| 1166 | 1165 | ||
| 1167 | &WAKERS | 1166 | &WAKERS |
| 1168 | } | 1167 | } |
| 1169 | 1168 | ||
| 1170 | #[inline] | 1169 | #[inline] |
| 1171 | fn state() -> &'static State { | 1170 | fn state() -> &'static State { |
| 1172 | static STATE: State = State { | 1171 | static STATE: State = State { |
| 1173 | users: AtomicU8::new(0), | 1172 | users: AtomicU8::new(0), |
| 1174 | used_pins: AtomicU32::new(0), | 1173 | used_pins: AtomicU32::new(0), |
| 1175 | }; | 1174 | }; |
| 1176 | 1175 | ||
| 1177 | &STATE | 1176 | &STATE |
| 1178 | } | ||
| 1179 | } | 1177 | } |
| 1180 | } | 1178 | } |
| 1181 | 1179 | ||
| 1182 | /// PIO instance. | 1180 | /// PIO instance. |
| 1183 | pub trait Instance: sealed::Instance + Sized + Unpin {} | 1181 | #[allow(private_bounds)] |
| 1182 | pub trait Instance: SealedInstance + Sized + Unpin { | ||
| 1183 | /// Interrupt for this peripheral. | ||
| 1184 | type Interrupt: crate::interrupt::typelevel::Interrupt; | ||
| 1185 | } | ||
| 1184 | 1186 | ||
| 1185 | macro_rules! impl_pio { | 1187 | macro_rules! impl_pio { |
| 1186 | ($name:ident, $pio:expr, $pac:ident, $funcsel:ident, $irq:ident) => { | 1188 | ($name:ident, $pio:expr, $pac:ident, $funcsel:ident, $irq:ident) => { |
| 1187 | impl sealed::Instance for peripherals::$name { | 1189 | impl SealedInstance for peripherals::$name { |
| 1188 | const PIO_NO: u8 = $pio; | 1190 | const PIO_NO: u8 = $pio; |
| 1189 | const PIO: &'static pac::pio::Pio = &pac::$pac; | 1191 | const PIO: &'static pac::pio::Pio = &pac::$pac; |
| 1190 | const FUNCSEL: pac::io::vals::Gpio0ctrlFuncsel = pac::io::vals::Gpio0ctrlFuncsel::$funcsel; | 1192 | const FUNCSEL: pac::io::vals::Gpio0ctrlFuncsel = pac::io::vals::Gpio0ctrlFuncsel::$funcsel; |
| 1193 | } | ||
| 1194 | impl Instance for peripherals::$name { | ||
| 1191 | type Interrupt = crate::interrupt::typelevel::$irq; | 1195 | type Interrupt = crate::interrupt::typelevel::$irq; |
| 1192 | } | 1196 | } |
| 1193 | impl Instance for peripherals::$name {} | ||
| 1194 | }; | 1197 | }; |
| 1195 | } | 1198 | } |
| 1196 | 1199 | ||
| @@ -1198,12 +1201,11 @@ impl_pio!(PIO0, 0, PIO0, PIO0_0, PIO0_IRQ_0); | |||
| 1198 | impl_pio!(PIO1, 1, PIO1, PIO1_0, PIO1_IRQ_0); | 1201 | impl_pio!(PIO1, 1, PIO1, PIO1_0, PIO1_IRQ_0); |
| 1199 | 1202 | ||
| 1200 | /// PIO pin. | 1203 | /// PIO pin. |
| 1201 | pub trait PioPin: sealed::PioPin + gpio::Pin {} | 1204 | pub trait PioPin: gpio::Pin {} |
| 1202 | 1205 | ||
| 1203 | macro_rules! impl_pio_pin { | 1206 | macro_rules! impl_pio_pin { |
| 1204 | ($( $pin:ident, )*) => { | 1207 | ($( $pin:ident, )*) => { |
| 1205 | $( | 1208 | $( |
| 1206 | impl sealed::PioPin for peripherals::$pin {} | ||
| 1207 | impl PioPin for peripherals::$pin {} | 1209 | impl PioPin for peripherals::$pin {} |
| 1208 | )* | 1210 | )* |
| 1209 | }; | 1211 | }; |
diff --git a/embassy-rp/src/pwm.rs b/embassy-rp/src/pwm.rs index 5aab3ff4f..7613e4e58 100644 --- a/embassy-rp/src/pwm.rs +++ b/embassy-rp/src/pwm.rs | |||
| @@ -6,8 +6,7 @@ use fixed::FixedU16; | |||
| 6 | use pac::pwm::regs::{ChDiv, Intr}; | 6 | use pac::pwm::regs::{ChDiv, Intr}; |
| 7 | use pac::pwm::vals::Divmode; | 7 | use pac::pwm::vals::Divmode; |
| 8 | 8 | ||
| 9 | use crate::gpio::sealed::Pin as _; | 9 | use crate::gpio::{AnyPin, Pin as GpioPin, SealedPin as _}; |
| 10 | use crate::gpio::{AnyPin, Pin as GpioPin}; | ||
| 11 | use crate::{pac, peripherals, RegExt}; | 10 | use crate::{pac, peripherals, RegExt}; |
| 12 | 11 | ||
| 13 | /// The configuration of a PWM slice. | 12 | /// The configuration of a PWM slice. |
| @@ -300,12 +299,11 @@ impl<'d, T: Slice> Drop for Pwm<'d, T> { | |||
| 300 | } | 299 | } |
| 301 | } | 300 | } |
| 302 | 301 | ||
| 303 | mod sealed { | 302 | trait SealedSlice {} |
| 304 | pub trait Slice {} | ||
| 305 | } | ||
| 306 | 303 | ||
| 307 | /// PWM Slice. | 304 | /// PWM Slice. |
| 308 | pub trait Slice: Peripheral<P = Self> + sealed::Slice + Sized + 'static { | 305 | #[allow(private_bounds)] |
| 306 | pub trait Slice: Peripheral<P = Self> + SealedSlice + Sized + 'static { | ||
| 309 | /// Slice number. | 307 | /// Slice number. |
| 310 | fn number(&self) -> u8; | 308 | fn number(&self) -> u8; |
| 311 | 309 | ||
| @@ -317,7 +315,7 @@ pub trait Slice: Peripheral<P = Self> + sealed::Slice + Sized + 'static { | |||
| 317 | 315 | ||
| 318 | macro_rules! slice { | 316 | macro_rules! slice { |
| 319 | ($name:ident, $num:expr) => { | 317 | ($name:ident, $num:expr) => { |
| 320 | impl sealed::Slice for peripherals::$name {} | 318 | impl SealedSlice for peripherals::$name {} |
| 321 | impl Slice for peripherals::$name { | 319 | impl Slice for peripherals::$name { |
| 322 | fn number(&self) -> u8 { | 320 | fn number(&self) -> u8 { |
| 323 | $num | 321 | $num |
diff --git a/embassy-rp/src/rtc/mod.rs b/embassy-rp/src/rtc/mod.rs index c8691bdc2..2ce7ac645 100644 --- a/embassy-rp/src/rtc/mod.rs +++ b/embassy-rp/src/rtc/mod.rs | |||
| @@ -188,16 +188,15 @@ pub enum RtcError { | |||
| 188 | NotRunning, | 188 | NotRunning, |
| 189 | } | 189 | } |
| 190 | 190 | ||
| 191 | mod sealed { | 191 | trait SealedInstance { |
| 192 | pub trait Instance { | 192 | fn regs(&self) -> crate::pac::rtc::Rtc; |
| 193 | fn regs(&self) -> crate::pac::rtc::Rtc; | ||
| 194 | } | ||
| 195 | } | 193 | } |
| 196 | 194 | ||
| 197 | /// RTC peripheral instance. | 195 | /// RTC peripheral instance. |
| 198 | pub trait Instance: sealed::Instance {} | 196 | #[allow(private_bounds)] |
| 197 | pub trait Instance: SealedInstance {} | ||
| 199 | 198 | ||
| 200 | impl sealed::Instance for crate::peripherals::RTC { | 199 | impl SealedInstance for crate::peripherals::RTC { |
| 201 | fn regs(&self) -> crate::pac::rtc::Rtc { | 200 | fn regs(&self) -> crate::pac::rtc::Rtc { |
| 202 | crate::pac::RTC | 201 | crate::pac::RTC |
| 203 | } | 202 | } |
diff --git a/embassy-rp/src/spi.rs b/embassy-rp/src/spi.rs index a2a22ffe5..ef4c644ae 100644 --- a/embassy-rp/src/spi.rs +++ b/embassy-rp/src/spi.rs | |||
| @@ -7,8 +7,7 @@ use embassy_hal_internal::{into_ref, PeripheralRef}; | |||
| 7 | pub use embedded_hal_02::spi::{Phase, Polarity}; | 7 | pub use embedded_hal_02::spi::{Phase, Polarity}; |
| 8 | 8 | ||
| 9 | use crate::dma::{AnyChannel, Channel}; | 9 | use crate::dma::{AnyChannel, Channel}; |
| 10 | use crate::gpio::sealed::Pin as _; | 10 | use crate::gpio::{AnyPin, Pin as GpioPin, SealedPin as _}; |
| 11 | use crate::gpio::{AnyPin, Pin as GpioPin}; | ||
| 12 | use crate::{pac, peripherals, Peripheral}; | 11 | use crate::{pac, peripherals, Peripheral}; |
| 13 | 12 | ||
| 14 | /// SPI errors. | 13 | /// SPI errors. |
| @@ -443,28 +442,26 @@ impl<'d, T: Instance> Spi<'d, T, Async> { | |||
| 443 | } | 442 | } |
| 444 | } | 443 | } |
| 445 | 444 | ||
| 446 | mod sealed { | 445 | trait SealedMode {} |
| 447 | use super::*; | ||
| 448 | 446 | ||
| 449 | pub trait Mode {} | 447 | trait SealedInstance { |
| 448 | const TX_DREQ: u8; | ||
| 449 | const RX_DREQ: u8; | ||
| 450 | 450 | ||
| 451 | pub trait Instance { | 451 | fn regs(&self) -> pac::spi::Spi; |
| 452 | const TX_DREQ: u8; | ||
| 453 | const RX_DREQ: u8; | ||
| 454 | |||
| 455 | fn regs(&self) -> pac::spi::Spi; | ||
| 456 | } | ||
| 457 | } | 452 | } |
| 458 | 453 | ||
| 459 | /// Mode. | 454 | /// Mode. |
| 460 | pub trait Mode: sealed::Mode {} | 455 | #[allow(private_bounds)] |
| 456 | pub trait Mode: SealedMode {} | ||
| 461 | 457 | ||
| 462 | /// SPI instance trait. | 458 | /// SPI instance trait. |
| 463 | pub trait Instance: sealed::Instance {} | 459 | #[allow(private_bounds)] |
| 460 | pub trait Instance: SealedInstance {} | ||
| 464 | 461 | ||
| 465 | macro_rules! impl_instance { | 462 | macro_rules! impl_instance { |
| 466 | ($type:ident, $irq:ident, $tx_dreq:expr, $rx_dreq:expr) => { | 463 | ($type:ident, $irq:ident, $tx_dreq:expr, $rx_dreq:expr) => { |
| 467 | impl sealed::Instance for peripherals::$type { | 464 | impl SealedInstance for peripherals::$type { |
| 468 | const TX_DREQ: u8 = $tx_dreq; | 465 | const TX_DREQ: u8 = $tx_dreq; |
| 469 | const RX_DREQ: u8 = $rx_dreq; | 466 | const RX_DREQ: u8 = $rx_dreq; |
| 470 | 467 | ||
| @@ -527,7 +524,7 @@ impl_pin!(PIN_29, SPI1, CsPin); | |||
| 527 | 524 | ||
| 528 | macro_rules! impl_mode { | 525 | macro_rules! impl_mode { |
| 529 | ($name:ident) => { | 526 | ($name:ident) => { |
| 530 | impl sealed::Mode for $name {} | 527 | impl SealedMode for $name {} |
| 531 | impl Mode for $name {} | 528 | impl Mode for $name {} |
| 532 | }; | 529 | }; |
| 533 | } | 530 | } |
diff --git a/embassy-rp/src/uart/mod.rs b/embassy-rp/src/uart/mod.rs index 65dcf4eb4..ee2dcb27d 100644 --- a/embassy-rp/src/uart/mod.rs +++ b/embassy-rp/src/uart/mod.rs | |||
| @@ -12,8 +12,7 @@ use pac::uart::regs::Uartris; | |||
| 12 | 12 | ||
| 13 | use crate::clocks::clk_peri_freq; | 13 | use crate::clocks::clk_peri_freq; |
| 14 | use crate::dma::{AnyChannel, Channel}; | 14 | use crate::dma::{AnyChannel, Channel}; |
| 15 | use crate::gpio::sealed::Pin; | 15 | use crate::gpio::{AnyPin, SealedPin}; |
| 16 | use crate::gpio::AnyPin; | ||
| 17 | use crate::interrupt::typelevel::{Binding, Interrupt}; | 16 | use crate::interrupt::typelevel::{Binding, Interrupt}; |
| 18 | use crate::pac::io::vals::{Inover, Outover}; | 17 | use crate::pac::io::vals::{Inover, Outover}; |
| 19 | use crate::{interrupt, pac, peripherals, Peripheral, RegExt}; | 18 | use crate::{interrupt, pac, peripherals, Peripheral, RegExt}; |
| @@ -1107,35 +1106,26 @@ impl<'d, T: Instance, M: Mode> embedded_hal_nb::serial::Write for Uart<'d, T, M> | |||
| 1107 | } | 1106 | } |
| 1108 | } | 1107 | } |
| 1109 | 1108 | ||
| 1110 | mod sealed { | 1109 | trait SealedMode {} |
| 1111 | use super::*; | ||
| 1112 | 1110 | ||
| 1113 | pub trait Mode {} | 1111 | trait SealedInstance { |
| 1112 | const TX_DREQ: u8; | ||
| 1113 | const RX_DREQ: u8; | ||
| 1114 | 1114 | ||
| 1115 | pub trait Instance { | 1115 | fn regs() -> pac::uart::Uart; |
| 1116 | const TX_DREQ: u8; | ||
| 1117 | const RX_DREQ: u8; | ||
| 1118 | 1116 | ||
| 1119 | type Interrupt: interrupt::typelevel::Interrupt; | 1117 | fn buffered_state() -> &'static buffered::State; |
| 1120 | 1118 | ||
| 1121 | fn regs() -> pac::uart::Uart; | 1119 | fn dma_state() -> &'static DmaState; |
| 1122 | |||
| 1123 | fn buffered_state() -> &'static buffered::State; | ||
| 1124 | |||
| 1125 | fn dma_state() -> &'static DmaState; | ||
| 1126 | } | ||
| 1127 | pub trait TxPin<T: Instance> {} | ||
| 1128 | pub trait RxPin<T: Instance> {} | ||
| 1129 | pub trait CtsPin<T: Instance> {} | ||
| 1130 | pub trait RtsPin<T: Instance> {} | ||
| 1131 | } | 1120 | } |
| 1132 | 1121 | ||
| 1133 | /// UART mode. | 1122 | /// UART mode. |
| 1134 | pub trait Mode: sealed::Mode {} | 1123 | #[allow(private_bounds)] |
| 1124 | pub trait Mode: SealedMode {} | ||
| 1135 | 1125 | ||
| 1136 | macro_rules! impl_mode { | 1126 | macro_rules! impl_mode { |
| 1137 | ($name:ident) => { | 1127 | ($name:ident) => { |
| 1138 | impl sealed::Mode for $name {} | 1128 | impl SealedMode for $name {} |
| 1139 | impl Mode for $name {} | 1129 | impl Mode for $name {} |
| 1140 | }; | 1130 | }; |
| 1141 | } | 1131 | } |
| @@ -1149,16 +1139,18 @@ impl_mode!(Blocking); | |||
| 1149 | impl_mode!(Async); | 1139 | impl_mode!(Async); |
| 1150 | 1140 | ||
| 1151 | /// UART instance. | 1141 | /// UART instance. |
| 1152 | pub trait Instance: sealed::Instance {} | 1142 | #[allow(private_bounds)] |
| 1143 | pub trait Instance: SealedInstance { | ||
| 1144 | /// Interrupt for this instance. | ||
| 1145 | type Interrupt: interrupt::typelevel::Interrupt; | ||
| 1146 | } | ||
| 1153 | 1147 | ||
| 1154 | macro_rules! impl_instance { | 1148 | macro_rules! impl_instance { |
| 1155 | ($inst:ident, $irq:ident, $tx_dreq:expr, $rx_dreq:expr) => { | 1149 | ($inst:ident, $irq:ident, $tx_dreq:expr, $rx_dreq:expr) => { |
| 1156 | impl sealed::Instance for peripherals::$inst { | 1150 | impl SealedInstance for peripherals::$inst { |
| 1157 | const TX_DREQ: u8 = $tx_dreq; | 1151 | const TX_DREQ: u8 = $tx_dreq; |
| 1158 | const RX_DREQ: u8 = $rx_dreq; | 1152 | const RX_DREQ: u8 = $rx_dreq; |
| 1159 | 1153 | ||
| 1160 | type Interrupt = crate::interrupt::typelevel::$irq; | ||
| 1161 | |||
| 1162 | fn regs() -> pac::uart::Uart { | 1154 | fn regs() -> pac::uart::Uart { |
| 1163 | pac::$inst | 1155 | pac::$inst |
| 1164 | } | 1156 | } |
| @@ -1176,7 +1168,9 @@ macro_rules! impl_instance { | |||
| 1176 | &STATE | 1168 | &STATE |
| 1177 | } | 1169 | } |
| 1178 | } | 1170 | } |
| 1179 | impl Instance for peripherals::$inst {} | 1171 | impl Instance for peripherals::$inst { |
| 1172 | type Interrupt = crate::interrupt::typelevel::$irq; | ||
| 1173 | } | ||
| 1180 | }; | 1174 | }; |
| 1181 | } | 1175 | } |
| 1182 | 1176 | ||
| @@ -1184,17 +1178,16 @@ impl_instance!(UART0, UART0_IRQ, 20, 21); | |||
| 1184 | impl_instance!(UART1, UART1_IRQ, 22, 23); | 1178 | impl_instance!(UART1, UART1_IRQ, 22, 23); |
| 1185 | 1179 | ||
| 1186 | /// Trait for TX pins. | 1180 | /// Trait for TX pins. |
| 1187 | pub trait TxPin<T: Instance>: sealed::TxPin<T> + crate::gpio::Pin {} | 1181 | pub trait TxPin<T: Instance>: crate::gpio::Pin {} |
| 1188 | /// Trait for RX pins. | 1182 | /// Trait for RX pins. |
| 1189 | pub trait RxPin<T: Instance>: sealed::RxPin<T> + crate::gpio::Pin {} | 1183 | pub trait RxPin<T: Instance>: crate::gpio::Pin {} |
| 1190 | /// Trait for Clear To Send (CTS) pins. | 1184 | /// Trait for Clear To Send (CTS) pins. |
| 1191 | pub trait CtsPin<T: Instance>: sealed::CtsPin<T> + crate::gpio::Pin {} | 1185 | pub trait CtsPin<T: Instance>: crate::gpio::Pin {} |
| 1192 | /// Trait for Request To Send (RTS) pins. | 1186 | /// Trait for Request To Send (RTS) pins. |
| 1193 | pub trait RtsPin<T: Instance>: sealed::RtsPin<T> + crate::gpio::Pin {} | 1187 | pub trait RtsPin<T: Instance>: crate::gpio::Pin {} |
| 1194 | 1188 | ||
| 1195 | macro_rules! impl_pin { | 1189 | macro_rules! impl_pin { |
| 1196 | ($pin:ident, $instance:ident, $function:ident) => { | 1190 | ($pin:ident, $instance:ident, $function:ident) => { |
| 1197 | impl sealed::$function<peripherals::$instance> for peripherals::$pin {} | ||
| 1198 | impl $function<peripherals::$instance> for peripherals::$pin {} | 1191 | impl $function<peripherals::$instance> for peripherals::$pin {} |
| 1199 | }; | 1192 | }; |
| 1200 | } | 1193 | } |
diff --git a/embassy-rp/src/usb.rs b/embassy-rp/src/usb.rs index d68dee4a3..37d37d6d9 100644 --- a/embassy-rp/src/usb.rs +++ b/embassy-rp/src/usb.rs | |||
| @@ -14,20 +14,19 @@ use embassy_usb_driver::{ | |||
| 14 | use crate::interrupt::typelevel::{Binding, Interrupt}; | 14 | use crate::interrupt::typelevel::{Binding, Interrupt}; |
| 15 | use crate::{interrupt, pac, peripherals, Peripheral, RegExt}; | 15 | use crate::{interrupt, pac, peripherals, Peripheral, RegExt}; |
| 16 | 16 | ||
| 17 | pub(crate) mod sealed { | 17 | trait SealedInstance { |
| 18 | pub trait Instance { | 18 | fn regs() -> crate::pac::usb::Usb; |
| 19 | fn regs() -> crate::pac::usb::Usb; | 19 | fn dpram() -> crate::pac::usb_dpram::UsbDpram; |
| 20 | fn dpram() -> crate::pac::usb_dpram::UsbDpram; | ||
| 21 | } | ||
| 22 | } | 20 | } |
| 23 | 21 | ||
| 24 | /// USB peripheral instance. | 22 | /// USB peripheral instance. |
| 25 | pub trait Instance: sealed::Instance + 'static { | 23 | #[allow(private_bounds)] |
| 24 | pub trait Instance: SealedInstance + 'static { | ||
| 26 | /// Interrupt for this peripheral. | 25 | /// Interrupt for this peripheral. |
| 27 | type Interrupt: interrupt::typelevel::Interrupt; | 26 | type Interrupt: interrupt::typelevel::Interrupt; |
| 28 | } | 27 | } |
| 29 | 28 | ||
| 30 | impl crate::usb::sealed::Instance for peripherals::USB { | 29 | impl crate::usb::SealedInstance for peripherals::USB { |
| 31 | fn regs() -> pac::usb::Usb { | 30 | fn regs() -> pac::usb::Usb { |
| 32 | pac::USBCTRL_REGS | 31 | pac::USBCTRL_REGS |
| 33 | } | 32 | } |
