@@ -15,7 +15,7 @@ use crate::{
1515 time:: * ,
1616} ;
1717use core:: {
18- cell:: RefCell ,
18+ cell:: Cell ,
1919 ops:: Deref ,
2020 sync:: atomic:: { compiler_fence, Ordering } ,
2121} ;
@@ -263,7 +263,7 @@ where
263263 // Internal helper function that returns 15 bit duty cycle value.
264264 #[ inline( always) ]
265265 fn duty_on_value ( & self , index : usize ) -> u16 {
266- let val = T :: buffer ( ) . borrow ( ) [ index] ;
266+ let val = T :: buffer ( ) . get ( ) [ index] ;
267267 let is_inverted = ( val >> 15 ) & 1 == 0 ;
268268 match is_inverted {
269269 false => val,
@@ -274,7 +274,7 @@ where
274274 // Internal helper function that returns 15 bit inverted duty cycle value.
275275 #[ inline( always) ]
276276 fn duty_off_value ( & self , index : usize ) -> u16 {
277- let val = T :: buffer ( ) . borrow ( ) [ index] ;
277+ let val = T :: buffer ( ) . get ( ) [ index] ;
278278 let is_inverted = ( val >> 15 ) & 1 == 0 ;
279279 match is_inverted {
280280 false => self . max_duty ( ) - val,
@@ -287,7 +287,7 @@ where
287287 pub fn set_duty_on_common ( & self , duty : u16 ) {
288288 compiler_fence ( Ordering :: SeqCst ) ;
289289 T :: buffer ( )
290- . borrow_mut ( )
290+ . get_mut ( )
291291 . copy_from_slice ( & [ duty. min ( self . max_duty ( ) ) & 0x7FFF ; 4 ] [ ..] ) ;
292292 self . one_shot ( ) ;
293293 self . set_load_mode ( LoadMode :: Common ) ;
@@ -304,7 +304,7 @@ where
304304 pub fn set_duty_off_common ( & self , duty : u16 ) {
305305 compiler_fence ( Ordering :: SeqCst ) ;
306306 T :: buffer ( )
307- . borrow_mut ( )
307+ . get_mut ( )
308308 . copy_from_slice ( & [ duty. min ( self . max_duty ( ) ) | 0x8000 ; 4 ] [ ..] ) ;
309309 self . one_shot ( ) ;
310310 self . set_load_mode ( LoadMode :: Common ) ;
@@ -332,7 +332,7 @@ where
332332 /// Will replace any ongoing sequence playback.
333333 pub fn set_duty_on_group ( & self , group : Group , duty : u16 ) {
334334 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 ;
336336 self . one_shot ( ) ;
337337 self . set_load_mode ( LoadMode :: Grouped ) ;
338338 self . pwm
@@ -347,7 +347,7 @@ where
347347 /// Will replace any ongoing sequence playback.
348348 pub fn set_duty_off_group ( & self , group : Group , duty : u16 ) {
349349 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 ;
351351 self . one_shot ( ) ;
352352 self . set_load_mode ( LoadMode :: Grouped ) ;
353353 self . pwm
@@ -374,10 +374,10 @@ where
374374 /// Will replace any ongoing sequence playback and the other channels will return to their previously set value.
375375 pub fn set_duty_on ( & self , channel : Channel , duty : u16 ) {
376376 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 ;
378378 self . one_shot ( ) ;
379379 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 ( ) {
381381 self . start_seq ( Seq :: Seq0 ) ;
382382 }
383383 }
@@ -386,10 +386,10 @@ where
386386 /// Will replace any ongoing sequence playback and the other channels will return to their previously set value.
387387 pub fn set_duty_off ( & self , channel : Channel , duty : u16 ) {
388388 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 ;
390390 self . one_shot ( ) ;
391391 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 ( ) {
393393 self . start_seq ( Seq :: Seq0 ) ;
394394 }
395395 }
@@ -956,44 +956,44 @@ pub enum Error {
956956
957957pub trait Instance : private:: Sealed + Deref < Target = crate :: pac:: pwm0:: RegisterBlock > {
958958 const INTERRUPT : Interrupt ;
959- fn buffer ( ) -> & ' static RefCell < [ u16 ; 4 ] > ;
959+ fn buffer ( ) -> & ' static mut Cell < [ u16 ; 4 ] > ;
960960}
961961
962- static mut BUF0 : RefCell < [ u16 ; 4 ] > = RefCell :: new ( [ 0 ; 4 ] ) ;
962+ static mut BUF0 : Cell < [ u16 ; 4 ] > = Cell :: new ( [ 0 ; 4 ] ) ;
963963impl Instance for PWM0 {
964964 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 }
967967 }
968968}
969969
970970#[ 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 ] ) ;
972972#[ cfg( not( any( feature = "52810" , feature = "52811" ) ) ) ]
973973impl Instance for PWM1 {
974974 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 }
977977 }
978978}
979979
980980#[ 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 ] ) ;
982982#[ cfg( not( any( feature = "52810" , feature = "52811" ) ) ) ]
983983impl Instance for PWM2 {
984984 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 }
987987 }
988988}
989989
990990#[ 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 ] ) ;
992992#[ cfg( not( any( feature = "52810" , feature = "52811" , feature = "52832" ) ) ) ]
993993impl Instance for PWM3 {
994994 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 }
997997 }
998998}
999999
0 commit comments