3
3
//! The pulse with modulation (PWM) module enables the generation of pulse width modulated signals on GPIO.
4
4
5
5
#[ cfg( not( any( feature = "9160" ) ) ) ]
6
- use crate :: pac:: {
7
- pwm0:: * , PWM0 ,
8
- } ;
6
+ use crate :: pac:: pwm0:: * ;
9
7
#[ cfg( any( feature = "9160" ) ) ]
10
- use crate :: pac:: {
11
- pwm0_ns:: * , PWM0_NS , PWM1_NS , PWM2_NS , PWM3_NS ,
12
- } ;
13
- #[ cfg( not( any( feature = "52810" , feature = "52811" , feature = "9160" ) ) ) ]
14
- use crate :: pac:: {
15
- PWM1 , PWM2 , PWM3 ,
16
- } ;
8
+ use crate :: pac:: pwm0_ns:: * ;
17
9
use crate :: {
18
10
gpio:: { Output , Pin , PushPull } ,
19
11
pac:: { generic:: Reg , Interrupt } ,
@@ -379,9 +371,12 @@ where
379
371
T :: buffer ( ) . set ( buffer) ;
380
372
self . one_shot ( ) ;
381
373
self . set_load_mode ( LoadMode :: Individual ) ;
382
- self . pwm . seq0 . ptr . write ( |w| unsafe { w. bits ( T :: buffer ( ) . as_ptr ( ) as u32 ) } ) ;
374
+ self . pwm
375
+ . seq0
376
+ . ptr
377
+ . write ( |w| unsafe { w. bits ( T :: buffer ( ) . as_ptr ( ) as u32 ) } ) ;
383
378
self . pwm . seq0 . cnt . write ( |w| unsafe { w. bits ( 4 ) } ) ;
384
- self . start_seq ( Seq :: Seq0 ) ;
379
+ self . start_seq ( Seq :: Seq0 ) ;
385
380
}
386
381
387
382
/// Sets inverted duty cycle (15 bit) for a PWM channel.
@@ -392,9 +387,12 @@ where
392
387
T :: buffer ( ) . set ( buffer) ;
393
388
self . one_shot ( ) ;
394
389
self . set_load_mode ( LoadMode :: Individual ) ;
395
- self . pwm . seq0 . ptr . write ( |w| unsafe { w. bits ( T :: buffer ( ) . as_ptr ( ) as u32 ) } ) ;
390
+ self . pwm
391
+ . seq0
392
+ . ptr
393
+ . write ( |w| unsafe { w. bits ( T :: buffer ( ) . as_ptr ( ) as u32 ) } ) ;
396
394
self . pwm . seq0 . cnt . write ( |w| unsafe { w. bits ( 4 ) } ) ;
397
- self . start_seq ( Seq :: Seq0 ) ;
395
+ self . start_seq ( Seq :: Seq0 ) ;
398
396
}
399
397
400
398
/// Returns the duty cycle value for a PWM channel.
@@ -470,7 +468,7 @@ where
470
468
pub fn start_seq ( & self , seq : Seq ) {
471
469
compiler_fence ( Ordering :: SeqCst ) ;
472
470
self . pwm . enable . write ( |w| w. enable ( ) . enabled ( ) ) ;
473
- self . pwm . tasks_seqstart [ usize:: from ( seq) ] . write ( |w| w . tasks_seqstart ( ) . set_bit ( ) ) ;
471
+ self . pwm . tasks_seqstart [ usize:: from ( seq) ] . write ( |w| unsafe { w . bits ( 1 ) } ) ;
474
472
while self . pwm . events_seqstarted [ usize:: from ( seq) ] . read ( ) . bits ( ) == 0 { }
475
473
self . pwm . events_seqend [ 0 ] . write ( |w| w) ;
476
474
self . pwm . events_seqend [ 1 ] . write ( |w| w) ;
@@ -480,16 +478,14 @@ where
480
478
/// Does not cause PWM generation to start if not running.
481
479
#[ inline( always) ]
482
480
pub fn next_step ( & self ) {
483
- self . pwm
484
- . tasks_nextstep
485
- . write ( |w| w. tasks_nextstep ( ) . set_bit ( ) ) ;
481
+ self . pwm . tasks_nextstep . write ( |w| unsafe { w. bits ( 1 ) } ) ;
486
482
}
487
483
488
484
/// Stops PWM pulse generation on all channels at the end of current PWM period, and stops sequence playback.
489
485
#[ inline( always) ]
490
486
pub fn stop ( & self ) {
491
487
compiler_fence ( Ordering :: SeqCst ) ;
492
- self . pwm . tasks_stop . write ( |w| w . tasks_stop ( ) . set_bit ( ) ) ;
488
+ self . pwm . tasks_stop . write ( |w| unsafe { w . bits ( 1 ) } ) ;
493
489
while self . pwm . events_stopped . read ( ) . bits ( ) == 0 { }
494
490
}
495
491
@@ -1082,94 +1078,104 @@ static mut BUF2: Cell<[u16; 4]> = Cell::new([0; 4]);
1082
1078
static mut BUF3 : Cell < [ u16 ; 4 ] > = Cell :: new ( [ 0 ; 4 ] ) ;
1083
1079
1084
1080
#[ cfg( not( any( feature = "9160" ) ) ) ]
1085
- impl Instance for PWM0 {
1081
+ impl Instance for crate :: pac :: PWM0 {
1086
1082
const INTERRUPT : Interrupt = Interrupt :: PWM0 ;
1087
1083
#[ inline( always) ]
1088
1084
fn buffer ( ) -> & ' static Cell < [ u16 ; 4 ] > {
1089
- unsafe { & BUF0 }
1085
+ unsafe { & BUF0 }
1090
1086
}
1091
1087
}
1092
1088
1093
1089
#[ cfg( not( any( feature = "52810" , feature = "52811" , feature = "9160" ) ) ) ]
1094
- impl Instance for PWM1 {
1090
+ impl Instance for crate :: pac :: PWM1 {
1095
1091
const INTERRUPT : Interrupt = Interrupt :: PWM1 ;
1096
1092
fn buffer ( ) -> & ' static Cell < [ u16 ; 4 ] > {
1097
- unsafe { & BUF1 }
1093
+ unsafe { & BUF1 }
1098
1094
}
1099
1095
}
1100
1096
1101
1097
#[ cfg( not( any( feature = "52810" , feature = "52811" , feature = "9160" ) ) ) ]
1102
- impl Instance for PWM2 {
1098
+ impl Instance for crate :: pac :: PWM2 {
1103
1099
const INTERRUPT : Interrupt = Interrupt :: PWM2 ;
1104
1100
fn buffer ( ) -> & ' static Cell < [ u16 ; 4 ] > {
1105
- unsafe { & BUF2 }
1101
+ unsafe { & BUF2 }
1106
1102
}
1107
1103
}
1108
1104
1109
- #[ cfg( not( any( feature = "52810" , feature = "52811" , feature = "52832" , feature = "9160" ) ) ) ]
1110
- impl Instance for PWM3 {
1105
+ #[ cfg( not( any(
1106
+ feature = "52810" ,
1107
+ feature = "52811" ,
1108
+ feature = "52832" ,
1109
+ feature = "9160"
1110
+ ) ) ) ]
1111
+ impl Instance for crate :: pac:: PWM3 {
1111
1112
const INTERRUPT : Interrupt = Interrupt :: PWM3 ;
1112
1113
fn buffer ( ) -> & ' static Cell < [ u16 ; 4 ] > {
1113
- unsafe { & BUF3 }
1114
+ unsafe { & BUF3 }
1114
1115
}
1115
1116
}
1116
1117
1117
1118
#[ cfg( any( feature = "9160" ) ) ]
1118
- impl Instance for PWM0_NS {
1119
+ impl Instance for crate :: pac :: PWM0_NS {
1119
1120
const INTERRUPT : Interrupt = Interrupt :: PWM0 ;
1120
1121
#[ inline( always) ]
1121
1122
fn buffer ( ) -> & ' static Cell < [ u16 ; 4 ] > {
1122
- unsafe { & BUF0 }
1123
+ unsafe { & BUF0 }
1123
1124
}
1124
1125
}
1125
1126
1126
1127
#[ cfg( any( feature = "9160" ) ) ]
1127
- impl Instance for PWM1_NS {
1128
+ impl Instance for crate :: pac :: PWM1_NS {
1128
1129
const INTERRUPT : Interrupt = Interrupt :: PWM1 ;
1129
1130
fn buffer ( ) -> & ' static Cell < [ u16 ; 4 ] > {
1130
- unsafe { & BUF1 }
1131
+ unsafe { & BUF1 }
1131
1132
}
1132
1133
}
1133
1134
1134
1135
#[ cfg( any( feature = "9160" ) ) ]
1135
- impl Instance for PWM2_NS {
1136
+ impl Instance for crate :: pac :: PWM2_NS {
1136
1137
const INTERRUPT : Interrupt = Interrupt :: PWM2 ;
1137
1138
fn buffer ( ) -> & ' static Cell < [ u16 ; 4 ] > {
1138
- unsafe { & BUF2 }
1139
+ unsafe { & BUF2 }
1139
1140
}
1140
1141
}
1141
1142
1142
1143
#[ cfg( any( feature = "9160" ) ) ]
1143
- impl Instance for PWM3_NS {
1144
+ impl Instance for crate :: pac :: PWM3_NS {
1144
1145
const INTERRUPT : Interrupt = Interrupt :: PWM3 ;
1145
1146
fn buffer ( ) -> & ' static Cell < [ u16 ; 4 ] > {
1146
- unsafe { & BUF3 }
1147
+ unsafe { & BUF3 }
1147
1148
}
1148
1149
}
1149
1150
mod sealed {
1150
1151
pub trait Sealed { }
1151
1152
1152
1153
#[ cfg( not( any( feature = "9160" ) ) ) ]
1153
- impl Sealed for crate :: pwm :: PWM0 { }
1154
+ impl Sealed for crate :: pac :: PWM0 { }
1154
1155
1155
1156
#[ cfg( not( any( feature = "52810" , feature = "52811" , feature = "9160" ) ) ) ]
1156
- impl Sealed for crate :: pwm :: PWM1 { }
1157
+ impl Sealed for crate :: pac :: PWM1 { }
1157
1158
1158
1159
#[ cfg( not( any( feature = "52810" , feature = "52811" , feature = "9160" ) ) ) ]
1159
- impl Sealed for crate :: pwm :: PWM2 { }
1160
+ impl Sealed for crate :: pac :: PWM2 { }
1160
1161
1161
- #[ cfg( not( any( feature = "52810" , feature = "52811" , feature = "52832" , feature = "9160" ) ) ) ]
1162
- impl Sealed for crate :: pwm:: PWM3 { }
1162
+ #[ cfg( not( any(
1163
+ feature = "52810" ,
1164
+ feature = "52811" ,
1165
+ feature = "52832" ,
1166
+ feature = "9160"
1167
+ ) ) ) ]
1168
+ impl Sealed for crate :: pac:: PWM3 { }
1163
1169
1164
1170
#[ cfg( any( feature = "9160" ) ) ]
1165
- impl Sealed for crate :: pwm :: PWM0_NS { }
1171
+ impl Sealed for crate :: pac :: PWM0_NS { }
1166
1172
1167
1173
#[ cfg( any( feature = "9160" ) ) ]
1168
- impl Sealed for crate :: pwm :: PWM1_NS { }
1174
+ impl Sealed for crate :: pac :: PWM1_NS { }
1169
1175
1170
1176
#[ cfg( any( feature = "9160" ) ) ]
1171
- impl Sealed for crate :: pwm :: PWM2_NS { }
1177
+ impl Sealed for crate :: pac :: PWM2_NS { }
1172
1178
1173
1179
#[ cfg( any( feature = "9160" ) ) ]
1174
- impl Sealed for crate :: pwm :: PWM3_NS { }
1180
+ impl Sealed for crate :: pac :: PWM3_NS { }
1175
1181
}
0 commit comments