Skip to main content

rp2040_dshot/
lib.rs

1//! A crate for using the rp2040's PIO machines to write DSHOT commands
2//! 
3//! Has support for both regular and BDDshot, as well as ESC telemetry, and extended BDDshot telemetry frames
4//! VERY ALPHA, BDDShot features have not been tested and likely do not work.
5#![no_std]
6
7#[cfg(feature = "driver")]
8pub mod program;
9#[cfg(feature = "driver")]
10pub use program::StandardDShotTimings as StandardDShotTimings;
11#[cfg(feature = "driver")]
12pub use program::BdDShotTimings as BdDShotTimings;
13#[cfg(feature = "driver")]
14pub mod driver;
15
16pub mod encoder;
17
18#[derive(Debug, Clone)]
19#[cfg_attr(feature = "thiserror", derive(thiserror_no_std::Error))]
20#[cfg_attr(feature = "defmt", derive(defmt::Format))]
21pub enum Error {
22    /// Throttle command must be in the range 0-1999
23    #[cfg(feature = "driver")]
24    #[cfg_attr(feature = "thiserror", error("Throttle command must be in the range 0-1999, was {throttle}"))]
25    ThrottleBoundsError { throttle: u16 },
26    /// Clock divider conversion from float to fixed failed in clock divisor calculation.
27    #[cfg(feature = "driver")]
28    #[cfg_attr(feature = "thiserror", error("Conversion from float to fixed failed in clock divider calculation. Float value: {}", clock_divider_float))]
29    ClockDividerConversionError { clock_divider_float: f32 },
30    /// Failed to spawn task.
31    #[cfg(feature = "driver")]
32    #[cfg_attr(feature = "thiserror", error("Failed to spawn task"))]
33    SpawnError(embassy_executor::SpawnError),
34    /// Failed to recieve value from channel.
35    #[cfg(feature = "driver")]
36    #[cfg_attr(feature = "thiserror", error("Failed to recieve value from channel"))]
37    TryReceiveError(embassy_sync::channel::TryReceiveError),
38    /// Driver future timed out
39    #[cfg(feature = "driver")]
40    #[cfg_attr(feature = "thiserror", error("Driver future timed out"))]
41    TimeoutError(embassy_time::TimeoutError),
42    /// Invalid ERPM telemerty checksum.
43    #[cfg(feature = "driver")]
44    #[cfg_attr(feature = "thiserror", error("Invalid ERPM telemetry checksum"))]
45    InvalidTelemetryChecksum,
46    /// TX Push Faliure
47    #[cfg(feature = "driver")]
48    #[cfg_attr(feature = "thiserror", error("TX Push Faliure"))]
49    TxTryPushFaliure,
50    #[cfg(feature = "driver")]
51    /// State machine split faliure, empty pointer!
52    #[cfg_attr(feature = "thiserror", error("SM Split Faliure, empty pointer!"))]
53    SmSplitFaliure,
54}
55
56#[cfg(feature = "driver")]
57impl From<embassy_executor::SpawnError> for Error {
58    fn from(e: embassy_executor::SpawnError) -> Self {
59        Error::SpawnError(e)
60    }
61}
62
63#[cfg(feature = "driver")]
64impl From<embassy_sync::channel::TryReceiveError> for Error {
65    fn from(e: embassy_sync::channel::TryReceiveError) -> Self {
66        Error::TryReceiveError(e)
67    }
68}
69
70#[cfg(feature = "driver")]
71impl From<embassy_time::TimeoutError> for Error {
72    fn from(e: embassy_time::TimeoutError) -> Self {
73        Error::TimeoutError(e)
74    }
75}