@@ -15,7 +15,7 @@ use crate::{
15
15
time:: * ,
16
16
} ;
17
17
use core:: {
18
- cell:: RefCell ,
18
+ cell:: Cell ,
19
19
ops:: Deref ,
20
20
sync:: atomic:: { compiler_fence, Ordering } ,
21
21
} ;
@@ -263,7 +263,7 @@ where
263
263
// Internal helper function that returns 15 bit duty cycle value.
264
264
#[ inline( always) ]
265
265
fn duty_on_value ( & self , index : usize ) -> u16 {
266
- let val = T :: buffer ( ) . borrow ( ) [ index] ;
266
+ let val = T :: buffer ( ) . get ( ) [ index] ;
267
267
let is_inverted = ( val >> 15 ) & 1 == 0 ;
268
268
match is_inverted {
269
269
false => val,
@@ -274,7 +274,7 @@ where
274
274
// Internal helper function that returns 15 bit inverted duty cycle value.
275
275
#[ inline( always) ]
276
276
fn duty_off_value ( & self , index : usize ) -> u16 {
277
- let val = T :: buffer ( ) . borrow ( ) [ index] ;
277
+ let val = T :: buffer ( ) . get ( ) [ index] ;
278
278
let is_inverted = ( val >> 15 ) & 1 == 0 ;
279
279
match is_inverted {
280
280
false => self . max_duty ( ) - val,
@@ -287,7 +287,7 @@ where
287
287
pub fn set_duty_on_common ( & self , duty : u16 ) {
288
288
compiler_fence ( Ordering :: SeqCst ) ;
289
289
T :: buffer ( )
290
- . borrow_mut ( )
290
+ . get_mut ( )
291
291
. copy_from_slice ( & [ duty. min ( self . max_duty ( ) ) & 0x7FFF ; 4 ] [ ..] ) ;
292
292
self . one_shot ( ) ;
293
293
self . set_load_mode ( LoadMode :: Common ) ;
@@ -304,7 +304,7 @@ where
304
304
pub fn set_duty_off_common ( & self , duty : u16 ) {
305
305
compiler_fence ( Ordering :: SeqCst ) ;
306
306
T :: buffer ( )
307
- . borrow_mut ( )
307
+ . get_mut ( )
308
308
. copy_from_slice ( & [ duty. min ( self . max_duty ( ) ) | 0x8000 ; 4 ] [ ..] ) ;
309
309
self . one_shot ( ) ;
310
310
self . set_load_mode ( LoadMode :: Common ) ;
@@ -332,7 +332,7 @@ where
332
332
/// Will replace any ongoing sequence playback.
333
333
pub fn set_duty_on_group ( & self , group : Group , duty : u16 ) {
334
334
compiler_fence ( Ordering :: SeqCst ) ;
335
- T :: buffer ( ) . borrow_mut ( ) [ usize:: from ( group) ] = duty. min ( self . max_duty ( ) ) & 0x7FFF ;
335
+ T :: buffer ( ) . get_mut ( ) [ usize:: from ( group) ] = duty. min ( self . max_duty ( ) ) & 0x7FFF ;
336
336
self . one_shot ( ) ;
337
337
self . set_load_mode ( LoadMode :: Grouped ) ;
338
338
self . pwm
@@ -347,7 +347,7 @@ where
347
347
/// Will replace any ongoing sequence playback.
348
348
pub fn set_duty_off_group ( & self , group : Group , duty : u16 ) {
349
349
compiler_fence ( Ordering :: SeqCst ) ;
350
- T :: buffer ( ) . borrow_mut ( ) [ usize:: from ( group) ] = duty. min ( self . max_duty ( ) ) | 0x8000 ;
350
+ T :: buffer ( ) . get_mut ( ) [ usize:: from ( group) ] = duty. min ( self . max_duty ( ) ) | 0x8000 ;
351
351
self . one_shot ( ) ;
352
352
self . set_load_mode ( LoadMode :: Grouped ) ;
353
353
self . pwm
@@ -374,10 +374,10 @@ where
374
374
/// Will replace any ongoing sequence playback and the other channels will return to their previously set value.
375
375
pub fn set_duty_on ( & self , channel : Channel , duty : u16 ) {
376
376
compiler_fence ( Ordering :: SeqCst ) ;
377
- T :: buffer ( ) . borrow_mut ( ) [ usize:: from ( channel) ] = duty. min ( self . max_duty ( ) ) & 0x7FFF ;
377
+ T :: buffer ( ) . get_mut ( ) [ usize:: from ( channel) ] = duty. min ( self . max_duty ( ) ) & 0x7FFF ;
378
378
self . one_shot ( ) ;
379
379
self . set_load_mode ( LoadMode :: Individual ) ;
380
- if self . load_seq ( Seq :: Seq0 , T :: buffer ( ) . borrow ( ) ) . is_ok ( ) {
380
+ if self . load_seq ( Seq :: Seq0 , & T :: buffer ( ) . get ( ) ) . is_ok ( ) {
381
381
self . start_seq ( Seq :: Seq0 ) ;
382
382
}
383
383
}
@@ -386,10 +386,10 @@ where
386
386
/// Will replace any ongoing sequence playback and the other channels will return to their previously set value.
387
387
pub fn set_duty_off ( & self , channel : Channel , duty : u16 ) {
388
388
compiler_fence ( Ordering :: SeqCst ) ;
389
- T :: buffer ( ) . borrow_mut ( ) [ usize:: from ( channel) ] = duty. min ( self . max_duty ( ) ) | 0x8000 ;
389
+ T :: buffer ( ) . get_mut ( ) [ usize:: from ( channel) ] = duty. min ( self . max_duty ( ) ) | 0x8000 ;
390
390
self . one_shot ( ) ;
391
391
self . set_load_mode ( LoadMode :: Individual ) ;
392
- if self . load_seq ( Seq :: Seq0 , T :: buffer ( ) . borrow ( ) ) . is_ok ( ) {
392
+ if self . load_seq ( Seq :: Seq0 , & T :: buffer ( ) . get ( ) ) . is_ok ( ) {
393
393
self . start_seq ( Seq :: Seq0 ) ;
394
394
}
395
395
}
@@ -956,44 +956,44 @@ pub enum Error {
956
956
957
957
pub trait Instance : private:: Sealed + Deref < Target = crate :: pac:: pwm0:: RegisterBlock > {
958
958
const INTERRUPT : Interrupt ;
959
- fn buffer ( ) -> & ' static RefCell < [ u16 ; 4 ] > ;
959
+ fn buffer ( ) -> & ' static mut Cell < [ u16 ; 4 ] > ;
960
960
}
961
961
962
- static mut BUF0 : RefCell < [ u16 ; 4 ] > = RefCell :: new ( [ 0 ; 4 ] ) ;
962
+ static mut BUF0 : Cell < [ u16 ; 4 ] > = Cell :: new ( [ 0 ; 4 ] ) ;
963
963
impl Instance for PWM0 {
964
964
const INTERRUPT : Interrupt = Interrupt :: PWM0 ;
965
- fn buffer ( ) -> & ' static RefCell < [ u16 ; 4 ] > {
966
- unsafe { & BUF0 }
965
+ fn buffer ( ) -> & ' static mut Cell < [ u16 ; 4 ] > {
966
+ unsafe { & mut BUF0 }
967
967
}
968
968
}
969
969
970
970
#[ cfg( not( any( feature = "52810" , feature = "52811" ) ) ) ]
971
- static mut BUF1 : RefCell < [ u16 ; 4 ] > = RefCell :: new ( [ 0 ; 4 ] ) ;
971
+ static mut BUF1 : Cell < [ u16 ; 4 ] > = Cell :: new ( [ 0 ; 4 ] ) ;
972
972
#[ cfg( not( any( feature = "52810" , feature = "52811" ) ) ) ]
973
973
impl Instance for PWM1 {
974
974
const INTERRUPT : Interrupt = Interrupt :: PWM1 ;
975
- fn buffer ( ) -> & ' static RefCell < [ u16 ; 4 ] > {
976
- unsafe { & BUF1 }
975
+ fn buffer ( ) -> & ' static mut Cell < [ u16 ; 4 ] > {
976
+ unsafe { & mut BUF1 }
977
977
}
978
978
}
979
979
980
980
#[ cfg( not( any( feature = "52810" , feature = "52811" ) ) ) ]
981
- static mut BUF2 : RefCell < [ u16 ; 4 ] > = RefCell :: new ( [ 0 ; 4 ] ) ;
981
+ static mut BUF2 : Cell < [ u16 ; 4 ] > = Cell :: new ( [ 0 ; 4 ] ) ;
982
982
#[ cfg( not( any( feature = "52810" , feature = "52811" ) ) ) ]
983
983
impl Instance for PWM2 {
984
984
const INTERRUPT : Interrupt = Interrupt :: PWM2 ;
985
- fn buffer ( ) -> & ' static RefCell < [ u16 ; 4 ] > {
986
- unsafe { & BUF2 }
985
+ fn buffer ( ) -> & ' static mut Cell < [ u16 ; 4 ] > {
986
+ unsafe { & mut BUF2 }
987
987
}
988
988
}
989
989
990
990
#[ cfg( not( any( feature = "52810" , feature = "52811" , feature = "52832" ) ) ) ]
991
- static mut BUF3 : RefCell < [ u16 ; 4 ] > = RefCell :: new ( [ 0 ; 4 ] ) ;
991
+ static mut BUF3 : Cell < [ u16 ; 4 ] > = Cell :: new ( [ 0 ; 4 ] ) ;
992
992
#[ cfg( not( any( feature = "52810" , feature = "52811" , feature = "52832" ) ) ) ]
993
993
impl Instance for PWM3 {
994
994
const INTERRUPT : Interrupt = Interrupt :: PWM3 ;
995
- fn buffer ( ) -> & ' static RefCell < [ u16 ; 4 ] > {
996
- unsafe { & BUF3 }
995
+ fn buffer ( ) -> & ' static mut Cell < [ u16 ; 4 ] > {
996
+ unsafe { & mut BUF3 }
997
997
}
998
998
}
999
999
0 commit comments