99//! On nRF52 devices, there is also a fork task endpoint, where the user can configure one more task
1010//! to be triggered by the same event, even fixed PPI channels have a configurable fork task.
1111
12+ use crate :: pac:: generic:: Reg ;
13+ use crate :: pac:: ppi:: tasks_chg:: { _DIS, _EN} ;
1214use crate :: pac:: PPI ;
1315use cfg_if:: cfg_if;
1416
@@ -52,8 +54,12 @@ mod sealed {
5254 }
5355
5456 pub trait NotFixed { }
57+
58+ pub trait ChannelGroup {
59+ const CHG : usize ;
60+ }
5561}
56- use sealed:: { Channel , Event , NotFixed , Task } ;
62+ use sealed:: { Channel , ChannelGroup , Event , NotFixed , Task } ;
5763
5864pub struct TaskAddr ( pub ( crate ) u32 ) ;
5965pub struct EventAddr ( pub ( crate ) u32 ) ;
@@ -83,6 +89,20 @@ pub trait ConfigurablePpi {
8389 fn set_event_endpoint < E : Event > ( & mut self , event : & E ) ;
8490}
8591
92+ /// Trait for a PPI channel group.
93+ pub trait PpiChannelGroup {
94+ /// Returns reference to `tasks_chg[x].en` endpoint for enabling channel group.
95+ fn task_enable ( & self ) -> & Reg < u32 , _EN > ;
96+ /// Returns reference to `tasks_chg[x].dis` endpoint for disabling channel group.
97+ fn task_disable ( & self ) -> & Reg < u32 , _DIS > ;
98+ /// Sets bitmask for PPI channels which shall be included in this channel group.
99+ fn set_channels ( & self , mask : u32 ) ;
100+ /// Enables this channel group.
101+ fn enable ( & self ) ;
102+ /// Disables this channel group.
103+ fn disable ( & self ) ;
104+ }
105+
86106// All unsafe `ptr` calls only uses registers atomically, and only changes the resources owned by
87107// the type (guaranteed by the abstraction).
88108impl < P : Channel > Ppi for P {
@@ -128,13 +148,42 @@ impl<P: Channel + NotFixed> ConfigurablePpi for P {
128148 }
129149}
130150
151+ impl < G : ChannelGroup > PpiChannelGroup for G {
152+ #[ inline( always) ]
153+ fn task_enable ( & self ) -> & Reg < u32 , _EN > {
154+ let regs = unsafe { & * PPI :: ptr ( ) } ;
155+ & regs. tasks_chg [ Self :: CHG ] . en
156+ }
157+ #[ inline( always) ]
158+ fn task_disable ( & self ) -> & Reg < u32 , _DIS > {
159+ let regs = unsafe { & * PPI :: ptr ( ) } ;
160+ & regs. tasks_chg [ Self :: CHG ] . dis
161+ }
162+ #[ inline( always) ]
163+ fn set_channels ( & self , mask : u32 ) {
164+ let regs = unsafe { & * PPI :: ptr ( ) } ;
165+ regs. chg [ Self :: CHG ] . write ( |w| unsafe { w. bits ( mask) } ) ;
166+ }
167+ #[ inline( always) ]
168+ fn enable ( & self ) {
169+ self . task_enable ( ) . write ( |w| unsafe { w. bits ( 1 ) } ) ;
170+ }
171+ #[ inline( always) ]
172+ fn disable ( & self ) {
173+ self . task_disable ( ) . write ( |w| unsafe { w. bits ( 1 ) } ) ;
174+ }
175+ }
176+
131177macro_rules! ppi {
132178 (
133179 not_fixed: [ $(
134180 $( #[ $attr: meta] ) *
135181 ( $ppix: ident, $PpixType: ident, $ch: expr) , ) +
136182 ] ,
137183 fixed: [ $( ( $ppix_fixed: ident, $PpixTypeFixed: ident, $ch_fixed: expr) , ) +] ,
184+ groups: [ $(
185+ $( #[ $chgattr: meta] ) *
186+ ( $chgx: ident, $ChgxType: ident, $chg: expr) , ) +] ,
138187 ) => {
139188
140189 $(
@@ -164,6 +213,19 @@ macro_rules! ppi {
164213 }
165214 ) +
166215
216+ $(
217+ /// Channel groups.
218+ $( #[ $chgattr] ) *
219+ pub struct $ChgxType {
220+ _private: ( ) ,
221+ }
222+
223+ $( #[ $chgattr] ) *
224+ impl ChannelGroup for $ChgxType {
225+ const CHG : usize = $chg;
226+ }
227+ ) *
228+
167229 /// Type that abstracts all the PPI channels.
168230 pub struct Parts {
169231 $(
@@ -173,6 +235,10 @@ macro_rules! ppi {
173235 $(
174236 pub $ppix_fixed: $PpixTypeFixed,
175237 ) +
238+ $(
239+ $( #[ $chgattr] ) *
240+ pub $chgx: $ChgxType,
241+ ) *
176242 }
177243
178244 impl Parts {
@@ -191,6 +257,12 @@ macro_rules! ppi {
191257 _private: ( ) ,
192258 } ,
193259 ) +
260+ $(
261+ $( #[ $chgattr] ) *
262+ $chgx: $ChgxType {
263+ _private: ( ) ,
264+ } ,
265+ ) *
194266 }
195267 }
196268 }
@@ -238,4 +310,14 @@ ppi!(
238310 ( ppi30, Ppi30 , 30 ) ,
239311 ( ppi31, Ppi31 , 31 ) ,
240312 ] ,
313+ groups: [
314+ ( chg0, Chg0 , 0 ) ,
315+ ( chg1, Chg1 , 1 ) ,
316+ ( chg2, Chg2 , 2 ) ,
317+ ( chg3, Chg3 , 3 ) ,
318+ #[ cfg( not( feature = "51" ) ) ]
319+ ( chg4, Chg4 , 4 ) ,
320+ #[ cfg( not( feature = "51" ) ) ]
321+ ( chg5, Chg5 , 5 ) ,
322+ ] ,
241323) ;
0 commit comments