xous-core/services/com/src/api.rs

106 lines
2.7 KiB
Rust
Raw Normal View History

2020-11-24 14:45:44 +00:00
// NOTE: the use of ComState "verbs" as commands is not meant as a 1:1 mapping of commands
// It's just a convenient abuse of already-defined constants. However, it's intended that
// the COM server on the SoC side abstracts much of the EC bus complexity away.
pub(crate) const SERVER_NAME_COM: &str = "_COM manager_";
#[derive(Debug, Default, Copy, Clone, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)]
2020-11-24 21:11:32 +00:00
pub struct BattStats {
/// instantaneous voltage in mV
pub voltage: u16,
/// state of charge in %, as inferred by impedance tracking
pub soc: u8,
/// instantaneous current draw in mA
pub current: i16,
/// remaining capacity in mA, as measured by coulomb counting
pub remaining_capacity: u16,
}
impl From<[usize; 2]> for BattStats {
fn from(a: [usize; 2]) -> BattStats {
BattStats {
voltage: (a[0] & 0xFFFF) as u16,
soc: ((a[0] >> 16) & 0xFF) as u8,
current: ((a[1] >> 16) & 0xFFFF) as i16,
remaining_capacity: (a[1] & 0xFFFF) as u16,
}
}
}
impl Into<[usize; 2]> for BattStats {
fn into(self) -> [usize; 2] {
[
(self.voltage as usize & 0xffff) | ((self.soc as usize) << 16) & 0xFF_0000,
(self.remaining_capacity as usize & 0xffff)
| ((self.current as usize) << 16) & 0xffff_0000,
]
2020-11-24 21:11:32 +00:00
}
}
#[derive(Debug, num_derive::FromPrimitive, num_derive::ToPrimitive)]
pub(crate) enum Opcode {
2020-11-24 14:45:44 +00:00
/// Battery stats
BattStats,
/// Battery stats, non-blocking
BattStatsNb,
2020-11-24 21:11:32 +00:00
/// Query Full charge capacity of the battery
//BattFullCapacity,
2020-11-24 21:11:32 +00:00
2020-11-24 14:45:44 +00:00
/// Turn Boost Mode On
//BoostOn,
2020-11-24 14:45:44 +00:00
/// Turn Boost Mode Off
//BoostOff,
2020-11-24 14:45:44 +00:00
/// Read the current accelerations off the IMU
//ImuAccelRead,
2020-11-24 14:45:44 +00:00
/// Power off the SoC
PowerOffSoc,
/// Ship mode (battery disconnect)
//ShipMode,
2020-11-24 14:45:44 +00:00
/// Is the battery charging?
//IsCharging,
2020-11-24 14:45:44 +00:00
/// Set the backlight brightness
//SetBackLight,
2020-11-24 14:45:44 +00:00
/// Request charging
//RequestCharging,
2020-11-24 14:45:44 +00:00
/// Erase a region of EC FLASH
//FlashErase,
2020-11-24 14:45:44 +00:00
/// Program a page of FLASH
2021-02-12 17:42:31 +00:00
//FlashProgram(&'a [u8]),
2020-11-24 14:45:44 +00:00
/// Update the SSID list
//SsidScan,
2020-11-24 14:45:44 +00:00
/// Return the latest SSID list
//SsidFetch,
2020-12-31 11:31:12 +00:00
/// Fetch the git ID of the EC
EcGitRev,
/// Fetch the firmware rev of the WF200
Wf200Rev,
/// Send a line of PDS data
Wf200PdsLine, //String<512>
/// request for a listener to BattStats events
RegisterBattStatsListener, //String<64>
2020-11-24 14:45:44 +00:00
}
/// These enums indicate what kind of callback type we're sending.
#[derive(Debug, num_derive::FromPrimitive, num_derive::ToPrimitive)]
2021-04-02 08:40:17 +00:00
pub(crate) enum Callback {
/// Battery status
BattStats,
2021-04-02 08:40:17 +00:00
/// Server is quitting, drop connections
Drop,
}