aboutsummaryrefslogtreecommitdiff
path: root/drivers/dcdc/src/lib.rs
blob: ab2b814b5464c1c4401e1427801f6a4c642de88f (plain)
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
#![no_std]

pub type Instance = ral_registers::Instance<RegisterBlock>;

#[repr(C)]
#[allow(non_snake_case)]
pub struct RegisterBlock {
    pub REG0: u32,
    pub REG1: u32,
    pub REG2: u32,
    pub REG3: u32,
}

pub type DCDC = ral_registers::Instance<RegisterBlock>;

/// Set the target value of `VDD_SOC`, in millivolts
///
/// Values are clamped between 800mV and 1575mV, with 25mV step
/// sizes.
pub fn set_target_vdd_soc(dcdc: DCDC, millivolts: u32) {
    let mv = millivolts.clamp(800, 1575);
    let trg = (mv - 800) / 25;
    ral_registers::modify_reg!(self, dcdc, REG3, TRG: trg);
    while ral_registers::read_reg!(self, dcdc, REG0, STS_DC_OK == 0) {}
}

/// Returns the target value of `VDD_SOC`, in millivolts.
pub fn target_vdd_soc(dcdc: DCDC) -> u32 {
    let trg = ral_registers::read_reg!(self, dcdc, REG3, TRG);
    trg * 25 + 800
}

ral_registers::register! {
    pub REG3<u32> RW [
        TRG start(0) width(5) RW {}
    ]
}

ral_registers::register! {
    pub REG0<u32> RW [
        STS_DC_OK start(31) width(1) RW {}
    ]
}