@@ -443,6 +443,66 @@ impl Pwm {
443443 pub fn set_turn_off ( & self , sm : SM , channel : Channel , compare : i16 ) {
444444 self . set_value ( sm, turn_off ( channel) , compare) ;
445445 }
446+
447+ /// Read the output masks for the PWM module.
448+ pub fn output_masks ( & self ) -> OutputMasks {
449+ // Masks are four bits wide. They fit within a u8.
450+ let ( pwm_a, pwm_b) = crate :: ral:: read_reg!( pwm, self . pwm, MASK , MASKA , MASKB ) ;
451+ OutputMasks {
452+ pwm_a : Mask :: from_bits_truncate ( pwm_a as u8 ) ,
453+ pwm_b : Mask :: from_bits_truncate ( pwm_b as u8 ) ,
454+ }
455+ }
456+
457+ /// Set the output masks for the PWM module.
458+ ///
459+ /// See [`OutputMasks`] to learn about output masking. The masking takes
460+ /// effect at the next reload opportunity. (Although some MCUs might support
461+ /// forced update, it's not standard across all MCUs, so it's not exported.)
462+ ///
463+ /// This call performs a single write. It does not read the existing mask
464+ /// bits to maintain them. If you need to perform these incremental updates,
465+ /// use [`output_masks`](Self::output_masks) to understand the prior state.
466+ pub fn set_output_masks ( & self , masks : OutputMasks ) {
467+ crate :: ral:: write_reg!( pwm, self . pwm, MASK ,
468+ MASKA : masks. pwm_a. bits( ) as u16 ,
469+ MASKB : masks. pwm_b. bits( ) as u16 ,
470+ ) ;
471+ }
472+ }
473+
474+ /// The mask state of PWM outputs.
475+ ///
476+ /// If a bit is high, the output is masked. Formally, it's diven to logic level 0
477+ /// in the IP block (before considering output polarity).
478+ #[ derive( Clone , Copy , PartialEq , Eq ) ]
479+ #[ non_exhaustive] // Leave option for pwm_x
480+ pub struct OutputMasks {
481+ /// The PWM A outputs of a given submodule.
482+ pub pwm_a : Mask ,
483+ /// The PWM B outputs of a given submodule.
484+ pub pwm_b : Mask ,
485+ }
486+
487+ impl OutputMasks {
488+ /// Returns a mask set with no outputs masked.
489+ ///
490+ /// After construction (in a constant context), you're free to manipulate
491+ /// the mask bits.
492+ pub const fn empty ( ) -> Self {
493+ Self {
494+ pwm_a : Mask :: empty ( ) ,
495+ pwm_b : Mask :: empty ( ) ,
496+ }
497+ }
498+
499+ /// Returns a mask set with all outputs masks.
500+ pub const fn all ( ) -> Self {
501+ Self {
502+ pwm_a : Mask :: all ( ) ,
503+ pwm_b : Mask :: all ( ) ,
504+ }
505+ }
446506}
447507
448508#[ inline( never) ]
0 commit comments