@@ -44,6 +44,12 @@ pub struct RegisterBlock {
4444 _reserved10 : [ u32 ; 9 ] ,
4545 /// 0x96c - SPI Bus Gating Reset register.
4646 pub spi_bgr : RW < SpiBusGating > ,
47+ _reserved11 : [ u32 ; 0xA0 ] ,
48+ /// 0xbf0 - LDEC Clock register.
49+ pub ledc_clk : RW < LedcClock > ,
50+ _reserved12 : [ u32 ; 2 ] ,
51+ /// 0xbfc - LDEC Bus Gating Reset register.
52+ pub ledc_bgr : RW < LedcBusGating > ,
4753}
4854
4955/// CPU AXI Configuration register.
@@ -493,6 +499,113 @@ impl SmhcBusGating {
493499 }
494500}
495501
502+ /// LEDC Clock register.
503+ #[ derive( Clone , Copy , Debug , PartialEq , Eq , Hash ) ]
504+ #[ repr( transparent) ]
505+ pub struct LedcClock ( u32 ) ;
506+
507+ impl LedcClock {
508+ const CLK_SRC_SEL : u32 = 1 << 24 ;
509+ const FACTOR_N : u32 = 0x3 << 8 ;
510+ const FACTOR_M : u32 = 0xf << 0 ;
511+ const CLK_GATING : u32 = 1 << 31 ;
512+
513+ /// Get LEDC clock source.
514+ #[ inline]
515+ pub const fn clock_source ( self ) -> SmhcClockSource {
516+ match ( self . 0 & Self :: CLK_SRC_SEL ) >> 24 {
517+ 0x0 => SmhcClockSource :: Hosc ,
518+ 0x1 => SmhcClockSource :: PllPeri1x ,
519+ _ => panic ! ( "impossible clock source" ) ,
520+ }
521+ }
522+ /// Set LEDC clock source.
523+ #[ inline]
524+ pub const fn set_clock_source ( self , val : SmhcClockSource ) -> Self {
525+ let val = match val {
526+ SmhcClockSource :: Hosc => 0x0 ,
527+ SmhcClockSource :: PllPeri1x => 0x1 ,
528+ _ => panic ! ( "impossible clock source" ) ,
529+ } ;
530+ Self ( ( self . 0 & !Self :: CLK_SRC_SEL ) | ( val << 24 ) )
531+ }
532+ /// Get LEDC clock divide factor N.
533+ #[ inline]
534+ pub const fn factor_n ( self ) -> PeriFactorN {
535+ match ( self . 0 & Self :: FACTOR_N ) >> 8 {
536+ 0 => PeriFactorN :: N1 ,
537+ 1 => PeriFactorN :: N2 ,
538+ 2 => PeriFactorN :: N4 ,
539+ 3 => PeriFactorN :: N8 ,
540+ _ => unreachable ! ( ) ,
541+ }
542+ }
543+ /// Set LEDC clock divide factor N.
544+ #[ inline]
545+ pub const fn set_factor_n ( self , val : PeriFactorN ) -> Self {
546+ let val = match val {
547+ PeriFactorN :: N1 => 0 ,
548+ PeriFactorN :: N2 => 1 ,
549+ PeriFactorN :: N4 => 2 ,
550+ PeriFactorN :: N8 => 3 ,
551+ } ;
552+ Self ( ( self . 0 & !Self :: FACTOR_N ) | ( val << 8 ) )
553+ }
554+ /// Get LEDC clock divide factor M.
555+ #[ inline]
556+ pub const fn factor_m ( self ) -> u8 {
557+ ( self . 0 & Self :: FACTOR_M ) as u8
558+ }
559+ /// Set LEDC clock divide factor M.
560+ #[ inline]
561+ pub const fn set_factor_m ( self , val : u8 ) -> Self {
562+ Self ( ( self . 0 & !Self :: FACTOR_M ) | val as u32 )
563+ }
564+ /// Enable clock gating.
565+ #[ inline]
566+ pub const fn enable_clock_gating ( self ) -> Self {
567+ Self ( self . 0 | Self :: CLK_GATING )
568+ }
569+ /// Disable clock gating.
570+ #[ inline]
571+ pub const fn disable_clock_gating ( self ) -> Self {
572+ Self ( self . 0 & !Self :: CLK_GATING )
573+ }
574+ /// Get if clock gating is enabled.
575+ #[ inline]
576+ pub const fn is_clock_gating_enabled ( self ) -> bool {
577+ self . 0 & Self :: CLK_GATING != 0
578+ }
579+ }
580+
581+ /// LEDC Clock Reset register.
582+ #[ derive( Clone , Copy , Debug , PartialEq , Eq , Hash ) ]
583+ #[ repr( transparent) ]
584+ pub struct LedcBusGating ( u32 ) ;
585+
586+ impl LedcBusGating {
587+ /// Disable clock gate for LEDC.
588+ #[ inline]
589+ pub const fn gate_mask ( self ) -> Self {
590+ Self ( self . 0 & !( 1 << 0 ) )
591+ }
592+ /// Enable clock gate for LEDC.
593+ #[ inline]
594+ pub const fn gate_pass ( self ) -> Self {
595+ Self ( self . 0 | ( 1 << 0 ) )
596+ }
597+ /// Assert reset signal for LEDC.
598+ #[ inline]
599+ pub const fn assert_reset ( self ) -> Self {
600+ Self ( self . 0 & !( 1 << ( 0 + 16 ) ) )
601+ }
602+ /// Deassert reset signal for LEDC.
603+ #[ inline]
604+ pub const fn deassert_reset ( self ) -> Self {
605+ Self ( self . 0 | ( 1 << ( 0 + 16 ) ) )
606+ }
607+ }
608+
496609#[ cfg( test) ]
497610mod tests {
498611 use super :: {
@@ -514,6 +627,8 @@ mod tests {
514627 assert_eq ! ( offset_of!( RegisterBlock , uart_bgr) , 0x90c ) ;
515628 assert_eq ! ( offset_of!( RegisterBlock , spi_clk) , 0x940 ) ;
516629 assert_eq ! ( offset_of!( RegisterBlock , spi_bgr) , 0x96c ) ;
630+ assert_eq ! ( offset_of!( RegisterBlock , ledc_clk) , 0xbf0 ) ;
631+ assert_eq ! ( offset_of!( RegisterBlock , ledc_bgr) , 0xbfc ) ;
517632 }
518633
519634 #[ test]
0 commit comments