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
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
use crate::*;
register_map!(
    InputSourceControl: 0x00, RW,
    PowerOnConfiguration: 0x01, RW,
    ChargeCurrentControl: 0x02, RW,
    DischargeAndTerminationCurrent: 0x03, RW,
    ChargeVoltageControl: 0x04, RW,
    ChargeTerminationAndTimerControl: 0x05, RW,
    MiscellaneousOperationControl: 0x06, RW,
    SystemStatus: 0x07, RO,
    FaultFlags: 0x08, RO,
);
#[derive(BitfieldSpecifier, Debug, Eq, PartialEq)]
pub enum ChargeStatus {
    NotCharging,
    PreCharge,
    Charge,
    ChargeDone,
}
#[bitfield]
#[derive(Debug)]
pub struct SystemStatus {
    #[skip(setters)]
    pub thermal_regulation: bool,
    #[skip(setters)]
    pub power_good: bool,
    #[skip(setters)]
    pub power_path_enabled: bool,
    #[skip(setters)]
    pub charge_status: ChargeStatus,
    #[skip(setters)]
    pub revision: B2,
    #[skip]
    __: bool,
}
#[bitfield]
#[derive(Debug)]
pub struct FaultFlags {
    #[skip]
    __: B2,
    #[skip(setters)]
    pub safety_timer_expired: bool,
    #[skip(setters)]
    pub battery_fault: bool,
    #[skip(setters)]
    pub thermal_shutdown: bool,
    #[skip(setters)]
    pub input_fault: bool,
    #[skip(setters)]
    pub watchdog_timer_expired: bool,
    #[skip]
    __: bool,
}
#[derive(BitfieldSpecifier, Debug, Eq, PartialEq)]
pub enum ThermalThreshold {
    T60C,
    T80C,
    T100C,
    T120C,
}
#[bitfield]
#[derive(Debug)]
pub struct MiscellaneousOperationControl {
    pub thermal_regulation_threshold: ThermalThreshold,
    #[skip]
    __: bool,
    pub ntc_enabled: bool,
    #[skip]
    __: bool,
    pub battery_fet_disabled: bool,
    pub extended_safety_timer: bool,
    #[skip]
    __: bool,
}
impl Default for MiscellaneousOperationControl {
    fn default() -> Self {
        Self {
            bytes: [0b0000_1011],
        }
    }
}
#[derive(BitfieldSpecifier, Debug, Eq, PartialEq)]
pub enum SafetyTimerPeriod {
    P20h,
    P5h,
    P8h,
    P12h,
}
#[derive(BitfieldSpecifier, Debug, Eq, PartialEq)]
pub enum WatchdogTimerLimit {
    Disabled,
    L40s,
    L80s,
    L160s,
}
#[bitfield]
#[derive(Debug)]
pub struct ChargeTerminationAndTimerControl {
    pub termination_control_enabled: bool,
    pub timer_period: SafetyTimerPeriod,
    pub timer_enabled: bool,
    pub timer_limit: WatchdogTimerLimit,
    pub termination_enabled: bool,
    #[skip]
    __: bool,
}
impl Default for ChargeTerminationAndTimerControl {
    fn default() -> Self {
        Self {
            bytes: [0b0100_1010],
        }
    }
}
#[derive(BitfieldSpecifier, Debug, Eq, PartialEq)]
pub enum RechargeThreshold {
    U150mV,
    U300mV,
}
#[derive(BitfieldSpecifier, Debug, Eq, PartialEq)]
pub enum PrechargeThreshold {
    U2800mV,
    U3000mV,
}
#[bitfield]
#[derive(Debug)]
pub struct ChargeVoltageControl {
    pub recharge_threshold: RechargeThreshold,
    pub precharge_threshold: PrechargeThreshold,
    pub regulation_voltage: B6,
}
impl Default for ChargeVoltageControl {
    fn default() -> Self {
        Self {
            bytes: [0b1010_0011],
        }
    }
}
#[derive(BitfieldSpecifier, Debug, Eq, PartialEq)]
pub enum TerminalCurrent {
    I24mA,
    I52mA,
    I80mA,
    I108mA,
}
#[bitfield]
#[derive(Debug)]
pub struct DischargeAndTerminationCurrent {
    pub terminal_current: TerminalCurrent,
    #[skip]
    __: bool,
    pub discharge_current_limit: B4,
    #[skip]
    __: bool,
}
impl Default for DischargeAndTerminationCurrent {
    fn default() -> Self {
        Self {
            bytes: [0b0100_1001],
        }
    }
}
#[bitfield]
#[derive(Debug)]
pub struct ChargeCurrentControl {
    pub charge_current: B5,
    #[skip]
    __: B3,
}
impl Default for ChargeCurrentControl {
    fn default() -> Self {
        Self {
            bytes: [0b0000_0111],
        }
    }
}
#[derive(BitfieldSpecifier, Debug, Eq, PartialEq)]
pub enum UVLOThreshold {
    U2400mV,
    U2500mV,
    U2600mV,
    U2700mV,
    U2800mV,
    U2900mV,
    U3000mV,
    U3100mV,
}
#[bitfield]
#[derive(Debug)]
pub struct PowerOnConfiguration {
    pub uvlo_threshold: UVLOThreshold,
    pub charge_disabled: bool,
    #[skip]
    __: B2,
    pub watchdog_timer_reset: bool,
    pub settings_reset: bool,
}
impl Default for PowerOnConfiguration {
    fn default() -> Self {
        Self {
            bytes: [0b0000_0100],
        }
    }
}
#[derive(BitfieldSpecifier, Debug, Eq, PartialEq)]
pub enum InputCurrentLimit {
    I77mA,
    I118mA,
    I345mA,
    I470mA,
    I540mA,
    I635mA,
    I734mA,
    I993mA,
}
#[bitfield]
#[derive(Debug)]
pub struct InputSourceControl {
    pub input_current_limit: InputCurrentLimit,
    pub input_minimum_voltage: B4,
    pub ldo_fet_disabled: bool,
}
impl Default for InputSourceControl {
    fn default() -> Self {
        Self {
            bytes: [0b0100_1011],
        }
    }
}