11//! HAL interface to the TWIS peripheral.
22//!
33
4- use core:: ops :: Deref ;
5- use core :: sync :: atomic :: { compiler_fence , Ordering :: SeqCst } ;
6-
7- use crate :: pac :: { twis0 , P0 , TWIS0 } ;
4+ use core:: {
5+ ops :: Deref ,
6+ sync :: atomic :: { compiler_fence , Ordering :: SeqCst } ,
7+ } ;
88
9- #[ cfg( any( feature = "52832" , feature = "52833" , feature = "52840" ) ) ]
10- use crate :: pac:: TWIS1 ;
9+ #[ cfg( feature = "9160" ) ]
10+ use crate :: pac:: {
11+ twis0_ns:: { self as twis0, _EVENTS_READ, _EVENTS_STOPPED, _EVENTS_WRITE, _TASKS_STOP} ,
12+ P0_NS as P0 , TWIS0_NS as TWIS0 ,
13+ } ;
1114
15+ #[ cfg( not( feature = "9160" ) ) ]
1216use crate :: pac:: {
13- generic :: Reg ,
14- twis0 :: { _EVENTS_READ , _EVENTS_STOPPED , _EVENTS_WRITE , _TASKS_STOP } ,
17+ twis0 :: { self , _EVENTS_READ , _EVENTS_STOPPED , _EVENTS_WRITE , _TASKS_STOP } ,
18+ P0 , TWIS0 ,
1519} ;
1620
21+ #[ cfg( any( feature = "52832" , feature = "52833" , feature = "52840" ) ) ]
22+ use crate :: pac:: TWIS1 ;
23+
1724use crate :: {
1825 gpio:: { Floating , Input , Pin } ,
26+ pac:: { generic:: Reg , Interrupt } ,
1927 slice_in_ram_or,
20- target_constants:: EASY_DMA_SIZE ,
28+ target_constants:: { EASY_DMA_SIZE , SRAM_LOWER , SRAM_UPPER } ,
2129} ;
30+ use embedded_dma:: * ;
2231
2332/// Interface to a TWIS instance.
24- pub struct Twis < T > ( T ) ;
33+ pub struct Twis < T : Instance > ( T ) ;
2534
2635impl < T > Twis < T >
2736where
@@ -295,7 +304,7 @@ pub struct Pins {
295304 pub sda : Pin < Input < Floating > > ,
296305}
297306
298- #[ derive( Debug ) ]
307+ #[ derive( Debug , Eq , PartialEq , Clone , Copy ) ]
299308pub enum Error {
300309 TxBufferTooLong ,
301310 RxBufferTooLong ,
@@ -314,9 +323,27 @@ pub enum TwiEvent {
314323}
315324
316325/// Implemented by all TWIS instances
317- pub trait Instance : Deref < Target = twis0:: RegisterBlock > { }
326+ pub trait Instance : sealed:: Sealed + Deref < Target = twis0:: RegisterBlock > {
327+ const INTERRUPT : Interrupt ;
328+ }
318329
319- impl Instance for TWIS0 { }
330+ impl Instance for TWIS0 {
331+ #[ cfg( not( any( feature = "9160" , feature = "52810" ) ) ) ]
332+ const INTERRUPT : Interrupt = Interrupt :: SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0 ;
333+ #[ cfg( feature = "9160" ) ]
334+ const INTERRUPT : Interrupt = Interrupt :: UARTE0_SPIM0_SPIS0_TWIM0_TWIS0 ;
335+ #[ cfg( feature = "52810" ) ]
336+ const INTERRUPT : Interrupt = Interrupt :: TWIM0_TWIS0_TWI0 ;
337+ }
320338
321339#[ cfg( any( feature = "52832" , feature = "52833" , feature = "52840" ) ) ]
322- impl Instance for TWIS1 { }
340+ impl Instance for TWIS1 {
341+ const INTERRUPT : Interrupt = Interrupt :: SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1 ;
342+ }
343+
344+ mod sealed {
345+ pub trait Sealed { }
346+ impl Sealed for super :: TWIS0 { }
347+ #[ cfg( any( feature = "52832" , feature = "52833" , feature = "52840" ) ) ]
348+ impl Sealed for super :: TWIS1 { }
349+ }
0 commit comments