use bitflags::bitflags;
#[derive(Copy, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct BstReturn {
pub battery_state: BatteryState,
pub battery_present_rate: u32,
pub battery_remaining_capacity: u32,
pub battery_present_voltage: u32,
}
#[derive(Copy, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct BatteryState(u32);
bitflags! {
impl BatteryState: u32 {
const DISCHARGING = 1 << 0;
const CHARGING = 1 << 1;
const CRITICAL = 1 << 2;
const CHARGE_LIMITING = 1 << 3;
}
}
#[derive(PartialEq, Eq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct BixReturn<'a> {
pub revision: u32,
pub power_unit: PowerUnit,
pub design_capacity: u32,
pub last_full_charge_capacity: u32,
pub battery_technology: BatteryTechnology,
pub design_voltage: u32,
pub design_cap_of_warning: u32,
pub design_cap_of_low: u32,
pub cycle_count: u32,
pub measurement_accuracy: u32,
pub max_sampling_time: u32,
pub min_sampling_time: u32,
pub max_averaging_interval: u32,
pub min_averaging_interval: u32,
pub battery_capacity_granularity_1: u32,
pub battery_capacity_granularity_2: u32,
pub model_number: &'a mut [u8],
pub serial_number: &'a mut [u8],
pub battery_type: &'a mut [u8],
pub oem_info: &'a mut [u8],
pub battery_swapping_capability: BatterySwapCapability,
}
#[repr(u32)]
#[derive(Copy, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum PowerUnit {
MilliWatts = 0,
MilliAmps = 1,
}
impl From<PowerUnit> for u32 {
fn from(value: PowerUnit) -> Self {
match value {
PowerUnit::MilliWatts => 0,
PowerUnit::MilliAmps => 1,
}
}
}
#[repr(u32)]
#[derive(Copy, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum BatteryTechnology {
Primary = 0,
Secondary = 1,
}
impl From<BatteryTechnology> for u32 {
fn from(value: BatteryTechnology) -> Self {
match value {
BatteryTechnology::Primary => 0,
BatteryTechnology::Secondary => 1,
}
}
}
#[repr(u32)]
#[derive(Copy, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum BatterySwapCapability {
NonSwappable = 0,
ColdSwappable = 1,
HotSwappable = 2,
}
impl From<BatterySwapCapability> for u32 {
fn from(value: BatterySwapCapability) -> Self {
match value {
BatterySwapCapability::NonSwappable => 0,
BatterySwapCapability::ColdSwappable => 1,
BatterySwapCapability::HotSwappable => 2,
}
}
}
#[derive(Copy, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct PsrReturn {
pub power_source: PowerSource,
}
#[repr(u32)]
#[derive(Copy, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum PowerSource {
Offline = 0,
Online = 1,
}
impl From<PowerSource> for u32 {
fn from(value: PowerSource) -> Self {
match value {
PowerSource::Offline => 0,
PowerSource::Online => 1,
}
}
}
#[derive(PartialEq, Eq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Pif<'a> {
pub power_source_state: PowerSourceState,
pub max_output_power: u32,
pub max_input_power: u32,
pub model_number: &'a mut [u8],
pub serial_number: &'a mut [u8],
pub oem_info: &'a mut [u8],
}
#[derive(Copy, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct PowerSourceState(u32);
bitflags! {
impl PowerSourceState: u32 {
const REDUNDANT = 1 << 0;
const SHARED = 1 << 1;
}
}
#[derive(Copy, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Bps {
pub revision: u32,
pub instantaneous_peak_power_level: u32,
pub instantaneous_peak_power_period: u32,
pub sustainable_peak_power_level: u32,
pub sustainable_peak_power_period: u32,
}
#[derive(Copy, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Btp {
pub trip_point: u32,
}
#[derive(Copy, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Bpt {
pub revision: u32,
pub threshold_id: ThresholdId,
pub threshold_value: u32,
}
#[repr(u32)]
#[derive(Copy, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum ThresholdId {
ClearAll = 0,
InstantaneousPeakPower = 1,
SustainablePeakPower = 2,
}
#[repr(u32)]
#[derive(Copy, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum BptReturnStatus {
Success = 0x00000000,
InvalidThresholdValue = 0x00000001,
HardwareTimeout = 0x00000002,
UnknownHardwareError = 0x00000003,
UnsupportedThresholdType = 0x00000004,
UnsupportedRevision = 0x00000005,
}
#[derive(Copy, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Bpc {
pub revision: u32,
pub power_threshold_support: PowerThresholdSupport,
pub max_instantaneous_peak_power_threshold: u32,
pub max_sustainable_peak_power_threshold: u32,
}
#[derive(Copy, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct PowerThresholdSupport(u32);
bitflags! {
impl PowerThresholdSupport: u32 {
const INSTANTANEOUS = 1 << 0;
const SUSTAINABLE = 1 << 1;
}
}
#[derive(Copy, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Bmc {
pub maintenance_control_flags: BmcControlFlags,
}
#[derive(Copy, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct BmcControlFlags(u32);
bitflags! {
impl BmcControlFlags: u32 {
const CALIBRATION_CYCLE = 1 << 0;
const DISABLE_CHARGING = 1 << 1;
const ALLOW_DISCHARGE_ON_AC = 1 << 2;
const SUSPEND_CHARGE_LIMITING = 1 << 3;
}
}
#[derive(Copy, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Bmd {
pub status_flags: BmdStatusFlags,
pub capability_flags: BmdCapabilityFlags,
pub recalibrate_count: u32,
pub quick_recalibrate_time: u32,
pub slow_recalibrate_time: u32,
}
#[derive(Copy, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct BmdStatusFlags(u32);
bitflags! {
impl BmdStatusFlags: u32 {
const AML_CALIBRATION_ACTIVE = 1 << 0;
const CHARGING_DISABLED = 1 << 1;
const DISCHARGE_ON_AC = 1 << 2;
const RECALIBRATION_NEEDED = 1 << 3;
const STANDBY_RECOMMENDED = 1 << 4;
const CHARGE_LIMIT_THERMAL_LOCK = 1 << 5;
const CHARGE_LIMIT_PROTECTION_LOCK = 1 << 6;
}
}
#[derive(Copy, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct BmdCapabilityFlags(u32);
bitflags! {
impl BmdCapabilityFlags: u32 {
const AML_CALIBRATION_SUPPORTED = 1 << 0;
const CHARGER_DISABLE_SUPPORTED = 1 << 1;
const DISCHARGE_ON_AC_SUPPORTED = 1 << 2;
const GLOBAL_CONTROL = 1 << 3;
const FULL_CHARGE_BEFORE_CALIBRATION = 1 << 4;
const CHARGE_LIMIT_SUSPEND_SUPPORTED = 1 << 5;
}
}
#[derive(Copy, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Bct {
pub charge_level_percent: u32,
}
#[repr(u32)]
#[derive(Copy, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum BctReturnResult {
InvalidTarget = 0x00000000,
EstimatedTime(u32),
Unknown = 0xFFFFFFFF,
}
impl From<u32> for BctReturnResult {
fn from(value: u32) -> Self {
match value {
0x00000000 => BctReturnResult::InvalidTarget,
0xFFFFFFFF => BctReturnResult::Unknown,
seconds => BctReturnResult::EstimatedTime(seconds),
}
}
}
#[derive(Copy, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Btm {
pub discharge_rate: u32,
}
#[repr(u32)]
#[derive(Copy, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum BtmReturnResult {
RateTooHighOrBatteryCritical = 0x00000000,
EstimatedRuntime(u32),
Unknown = 0xFFFFFFFF,
}
impl From<u32> for BtmReturnResult {
fn from(value: u32) -> Self {
match value {
0x00000000 => BtmReturnResult::RateTooHighOrBatteryCritical,
0xFFFFFFFF => BtmReturnResult::Unknown,
seconds => BtmReturnResult::EstimatedRuntime(seconds),
}
}
}
#[derive(Copy, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Bms {
pub sampling_time_ms: u32,
}
#[repr(u32)]
#[derive(Copy, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum BmsReturnResult {
Success = 0,
OutOfRange = 1,
}
impl From<BmsReturnResult> for u32 {
fn from(value: BmsReturnResult) -> Self {
match value {
BmsReturnResult::Success => 0,
BmsReturnResult::OutOfRange => 1,
}
}
}
#[derive(Copy, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Bma {
pub averaging_interval_ms: u32,
}
#[repr(u32)]
#[derive(Copy, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum BmaReturnResult {
Success = 0,
OutOfRange = 1,
}
impl From<BmaReturnResult> for u32 {
fn from(value: BmaReturnResult) -> Self {
match value {
BmaReturnResult::Success => 0,
BmaReturnResult::OutOfRange => 1,
}
}
}