File tree Expand file tree Collapse file tree 9 files changed +84
-18
lines changed
Expand file tree Collapse file tree 9 files changed +84
-18
lines changed Original file line number Diff line number Diff line change 22//!
33//! The pulse with modulation (PWM) module enables the generation of pulse width modulated signals on GPIO.
44
5- use core:: cell:: RefCell ;
65use core:: sync:: atomic:: { compiler_fence, Ordering } ;
6+ use core:: { cell:: RefCell , ops:: Deref } ;
77
88#[ cfg( any( feature = "52833" , feature = "52840" ) ) ]
99use crate :: {
@@ -973,7 +973,7 @@ pub enum Error {
973973 BufferTooLong ,
974974}
975975
976- pub trait Instance : private :: Sealed { }
976+ pub trait Instance : Deref < Target = crate :: pac :: pwm0 :: RegisterBlock > + sealed :: Sealed { }
977977
978978impl Instance for PWM0 { }
979979
@@ -986,8 +986,8 @@ impl Instance for PWM2 {}
986986#[ cfg( not( any( feature = "52810" , feature = "52811" , feature = "52832" ) ) ) ]
987987impl Instance for PWM3 { }
988988
989- mod private {
990- pub trait Sealed : core :: ops :: Deref < Target = crate :: pac :: pwm0 :: RegisterBlock > { }
989+ mod sealed {
990+ pub trait Sealed { }
991991
992992 impl Sealed for crate :: pwm:: PWM0 { }
993993
Original file line number Diff line number Diff line change @@ -219,17 +219,22 @@ pub enum Error {
219219}
220220
221221/// Implemented by all RTC instances.
222- pub trait Instance : Deref < Target = rtc0:: RegisterBlock > {
222+ pub trait Instance : Deref < Target = rtc0:: RegisterBlock > + sealed :: Sealed {
223223 /// The interrupt associated with this RTC instance.
224224 const INTERRUPT : Interrupt ;
225225}
226226
227+ mod sealed {
228+ pub trait Sealed { }
229+ }
230+
227231macro_rules! impl_instance {
228232 ( $( $name: ident, ) * ) => {
229233 $(
230234 impl Instance for $name {
231235 const INTERRUPT : Interrupt = Interrupt :: $name;
232236 }
237+ impl sealed:: Sealed for $name { }
233238 ) *
234239 }
235240}
Original file line number Diff line number Diff line change @@ -128,8 +128,14 @@ pub enum Error {
128128}
129129
130130/// Trait implemented by all SPI peripheral instances.
131- pub trait Instance : Deref < Target = spi0:: RegisterBlock > { }
131+ pub trait Instance : Deref < Target = spi0:: RegisterBlock > + sealed :: Sealed { }
132132
133+ mod sealed {
134+ pub trait Sealed { }
135+ }
136+
137+ impl sealed:: Sealed for SPI0 { }
133138impl Instance for SPI0 { }
134139
140+ impl sealed:: Sealed for SPI1 { }
135141impl Instance for SPI1 { }
Original file line number Diff line number Diff line change @@ -394,8 +394,13 @@ pub enum Error {
394394}
395395
396396/// Implemented by all SPIM instances.
397- pub trait Instance : Deref < Target = spim0:: RegisterBlock > { }
397+ pub trait Instance : Deref < Target = spim0:: RegisterBlock > + sealed :: Sealed { }
398398
399+ mod sealed {
400+ pub trait Sealed { }
401+ }
402+
403+ impl sealed:: Sealed for SPIM0 { }
399404impl Instance for SPIM0 { }
400405
401406#[ cfg( any(
@@ -404,10 +409,22 @@ impl Instance for SPIM0 {}
404409 feature = "52840" ,
405410 feature = "52811"
406411) ) ]
407- impl Instance for SPIM1 { }
412+ mod _spim1 {
413+ use super :: * ;
414+ impl Instance for SPIM1 { }
415+ impl sealed:: Sealed for SPIM1 { }
416+ }
408417
409418#[ cfg( any( feature = "52832" , feature = "52833" , feature = "52840" ) ) ]
410- impl Instance for SPIM2 { }
419+ mod _spim2 {
420+ use super :: * ;
421+ impl Instance for SPIM2 { }
422+ impl sealed:: Sealed for SPIM2 { }
423+ }
411424
412425#[ cfg( any( feature = "52833" , feature = "52840" ) ) ]
413- impl Instance for SPIM3 { }
426+ mod _spim3 {
427+ use super :: * ;
428+ impl Instance for SPIM3 { }
429+ impl sealed:: Sealed for SPIM3 { }
430+ }
Original file line number Diff line number Diff line change @@ -296,8 +296,14 @@ pub enum Error {
296296}
297297
298298/// Implemented by all TWIM instances.
299- pub trait Instance : Deref < Target = twi0:: RegisterBlock > { }
299+ pub trait Instance : Deref < Target = twi0:: RegisterBlock > + sealed :: Sealed { }
300300
301+ mod sealed {
302+ pub trait Sealed { }
303+ }
304+
305+ impl sealed:: Sealed for TWI0 { }
301306impl Instance for TWI0 { }
302307
308+ impl sealed:: Sealed for TWI1 { }
303309impl Instance for TWI1 { }
Original file line number Diff line number Diff line change @@ -447,9 +447,18 @@ pub enum Error {
447447}
448448
449449/// Implemented by all TWIM instances
450- pub trait Instance : Deref < Target = twim0:: RegisterBlock > { }
450+ pub trait Instance : Deref < Target = twim0:: RegisterBlock > + sealed :: Sealed { }
451451
452+ mod sealed {
453+ pub trait Sealed { }
454+ }
455+
456+ impl sealed:: Sealed for TWIM0 { }
452457impl Instance for TWIM0 { }
453458
454459#[ cfg( any( feature = "52832" , feature = "52833" , feature = "52840" ) ) ]
455- impl Instance for TWIM1 { }
460+ mod _twim1 {
461+ use super :: * ;
462+ impl sealed:: Sealed for TWIM1 { }
463+ impl Instance for TWIM1 { }
464+ }
Original file line number Diff line number Diff line change @@ -314,9 +314,18 @@ pub enum TwiEvent {
314314}
315315
316316/// Implemented by all TWIS instances
317- pub trait Instance : Deref < Target = twis0:: RegisterBlock > { }
317+ pub trait Instance : Deref < Target = twis0:: RegisterBlock > + sealed :: Sealed { }
318318
319+ mod sealed {
320+ pub trait Sealed { }
321+ }
322+
323+ impl sealed:: Sealed for TWIS0 { }
319324impl Instance for TWIS0 { }
320325
321326#[ cfg( any( feature = "52832" , feature = "52833" , feature = "52840" ) ) ]
322- impl Instance for TWIS1 { }
327+ mod _twis1 {
328+ use super :: * ;
329+ impl sealed:: Sealed for TWIS1 { }
330+ impl Instance for TWIS1 { }
331+ }
Original file line number Diff line number Diff line change @@ -142,6 +142,11 @@ pub struct Pins {
142142 pub rts : Option < Pin < Output < PushPull > > > ,
143143}
144144
145- pub trait Instance : Deref < Target = uart0:: RegisterBlock > { }
145+ pub trait Instance : Deref < Target = uart0:: RegisterBlock > + sealed :: Sealed { }
146146
147+ mod sealed {
148+ pub trait Sealed { }
149+ }
150+
151+ impl sealed:: Sealed for UART0 { }
147152impl Instance for UART0 { }
Original file line number Diff line number Diff line change @@ -368,9 +368,18 @@ pub enum Error {
368368 BufferNotInRAM ,
369369}
370370
371- pub trait Instance : Deref < Target = uarte0:: RegisterBlock > { }
371+ pub trait Instance : Deref < Target = uarte0:: RegisterBlock > + sealed :: Sealed { }
372372
373+ mod sealed {
374+ pub trait Sealed { }
375+ }
376+
377+ impl sealed:: Sealed for UARTE0 { }
373378impl Instance for UARTE0 { }
374379
375380#[ cfg( any( feature = "52833" , feature = "52840" , feature = "9160" ) ) ]
376- impl Instance for UARTE1 { }
381+ mod _uarte1 {
382+ use super :: * ;
383+ impl sealed:: Sealed for UARTE1 { }
384+ impl Instance for UARTE1 { }
385+ }
You can’t perform that action at this time.
0 commit comments