cu_bdshot/
messages.rs

1use bincode::{Decode, Encode};
2use serde::{Deserialize, Serialize};
3
4/// Telemetry payload decoded from a DSHOT ESC.
5#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, Encode, Decode)]
6pub enum DShotTelemetry {
7    EncodingError,
8    Erpm(u16),
9    Temp(u8),
10    Voltage(u8),
11    Amps(u8),
12    Debug1(u8),
13    Debug2(u8),
14    Debug3(u8),
15    Event(u8),
16}
17
18/// Command sent from Copper into the ESC bridge.
19#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, Encode, Decode)]
20pub struct EscCommand {
21    /// Raw throttle value (0 - 2047). Values >= 48 arm the ESC per DSHOT spec.
22    pub throttle: u16,
23    /// Whether the bridge should request telemetry for this frame.
24    pub request_telemetry: bool,
25}
26
27impl Default for EscCommand {
28    fn default() -> Self {
29        Self {
30            throttle: 0,
31            request_telemetry: true,
32        }
33    }
34}
35
36impl EscCommand {
37    pub fn disarm() -> Self {
38        Self::default()
39    }
40}
41
42/// Telemetry sample received from the ESC bridge.
43#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize, Encode, Decode)]
44pub struct EscTelemetry {
45    pub sample: Option<DShotTelemetry>,
46}