# sysctl.rs - source
Source of the Rust file `/home/runner/.cargo/git/checkouts/k210-hal-1069b16e3180bc3a/795ac3f/src/sysctl.rs`.
Keywords: rust, rustlang, rust-lang

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61

    //! (TODO) System Controller (SYSCTL)

    use crate::pac::{sysctl, SYSCTL};

    pub(crate) fn sysctl<'a>() -> &'a sysctl::RegisterBlock {
        unsafe { &*(SYSCTL::ptr()) }
    }

    pub(crate) fn clk_en_cent<'a>() -> &'a sysctl::CLK_EN_CENT {
        &sysctl().clk_en_cent
    }

    pub(crate) fn clk_en_peri<'a>() -> &'a sysctl::CLK_EN_PERI {
        &sysctl().clk_en_peri
    }

    pub(crate) fn peri_reset<'a>() -> &'a sysctl::PERI_RESET {
        &sysctl().peri_reset
    }

    pub trait SysctlExt {
        fn constrain(self) -> Parts;
    }

    impl SysctlExt for SYSCTL {
        fn constrain(self) -> Parts {
            Parts {
                apb0: APB0 { _ownership: () },
            }
        }
    }

    // ref: sysctl.c
    pub struct Parts {
        // todo: PLL0, PLL1, PLL2
        // todo: CPU, SRAM, APB-bus, ROM, DMA, AI
        pub apb0: APB0,
        // pub apb1: APB1,
        // pub apb2: APB2,
    }

    pub struct APB0 {
        _ownership: ()
    }

    impl APB0 {
        pub(crate) fn enable(&mut self) {
            clk_en_cent().modify(
                |_r, w|
                    w.apb0_clk_en().set_bit()
            );
        }
    }

    // pub struct APB1 {
    //     _ownership: ()
    // }

    // pub struct APB2 {
    //     _ownership: ()
    // }