9
9
//! On nRF52 devices, there is also a fork task endpoint, where the user can configure one more task
10
10
//! to be triggered by the same event, even fixed PPI channels have a configurable fork task.
11
11
12
+ use crate :: pac:: generic:: Reg ;
13
+ use crate :: pac:: ppi:: tasks_chg:: { _DIS, _EN} ;
12
14
use crate :: pac:: PPI ;
13
15
use cfg_if:: cfg_if;
14
16
@@ -52,8 +54,12 @@ mod sealed {
52
54
}
53
55
54
56
pub trait NotFixed { }
57
+
58
+ pub trait ChannelGroup {
59
+ const CHG : usize ;
60
+ }
55
61
}
56
- use sealed:: { Channel , Event , NotFixed , Task } ;
62
+ use sealed:: { Channel , ChannelGroup , Event , NotFixed , Task } ;
57
63
58
64
pub struct TaskAddr ( pub ( crate ) u32 ) ;
59
65
pub struct EventAddr ( pub ( crate ) u32 ) ;
@@ -83,6 +89,20 @@ pub trait ConfigurablePpi {
83
89
fn set_event_endpoint < E : Event > ( & mut self , event : & E ) ;
84
90
}
85
91
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
+
86
106
// All unsafe `ptr` calls only uses registers atomically, and only changes the resources owned by
87
107
// the type (guaranteed by the abstraction).
88
108
impl < P : Channel > Ppi for P {
@@ -128,13 +148,42 @@ impl<P: Channel + NotFixed> ConfigurablePpi for P {
128
148
}
129
149
}
130
150
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
+
131
177
macro_rules! ppi {
132
178
(
133
179
not_fixed: [ $(
134
180
$( #[ $attr: meta] ) *
135
181
( $ppix: ident, $PpixType: ident, $ch: expr) , ) +
136
182
] ,
137
183
fixed: [ $( ( $ppix_fixed: ident, $PpixTypeFixed: ident, $ch_fixed: expr) , ) +] ,
184
+ groups: [ $(
185
+ $( #[ $chgattr: meta] ) *
186
+ ( $chgx: ident, $ChgxType: ident, $chg: expr) , ) +] ,
138
187
) => {
139
188
140
189
$(
@@ -164,6 +213,19 @@ macro_rules! ppi {
164
213
}
165
214
) +
166
215
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
+
167
229
/// Type that abstracts all the PPI channels.
168
230
pub struct Parts {
169
231
$(
@@ -173,6 +235,10 @@ macro_rules! ppi {
173
235
$(
174
236
pub $ppix_fixed: $PpixTypeFixed,
175
237
) +
238
+ $(
239
+ $( #[ $chgattr] ) *
240
+ pub $chgx: $ChgxType,
241
+ ) *
176
242
}
177
243
178
244
impl Parts {
@@ -191,6 +257,12 @@ macro_rules! ppi {
191
257
_private: ( ) ,
192
258
} ,
193
259
) +
260
+ $(
261
+ $( #[ $chgattr] ) *
262
+ $chgx: $ChgxType {
263
+ _private: ( ) ,
264
+ } ,
265
+ ) *
194
266
}
195
267
}
196
268
}
@@ -238,4 +310,14 @@ ppi!(
238
310
( ppi30, Ppi30 , 30 ) ,
239
311
( ppi31, Ppi31 , 31 ) ,
240
312
] ,
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
+ ] ,
241
323
) ;
0 commit comments