Crates.io | dshot-frame |
lib.rs | dshot-frame |
version | 0.1.3 |
source | src |
created_at | 2024-05-24 00:55:08.231323 |
updated_at | 2024-05-25 12:14:12.326846 |
description | Generates frames for the DShot ESC protocol |
homepage | |
repository | https://github.com/sulami/dshot-frame |
max_upload_size | |
id | 1250596 |
size | 13,989 |
This crate provides support for the DShot ESC protocol.
DShot has two-byte frames, where the first 11 bits are the throttle speed, bit 12 is a telemetry request flag, and the last four bits are a checksum.
Throttle values below 48 are reserved for special commands.
It is transmitted over the wire at a fixed speed, with ones and zeroes both being pulses, but ones being twice as long as zeroes.
This example is adapted from an embassy-stm32 codebase:
async fn dshot(/* ... */) {
let mut pwm = SimplePwm::new(
timer,
Some(PwmPin::new_ch1(pin, OutputType::PushPull)),
None,
None,
None,
Hertz(150_000),
CountingMode::EdgeAlignedUp,
);
let max_duty_cycle = pwm.get_max_duty() as u16;
let frame = Frame::new(1000, false).unwrap();
pwm.waveform_up(&mut dma, Ch1, &frame.duty_cycles()).await;
// Pull the line low after sending a frame.
pwm.set_duty(channel, 0);
pwm.enable(channel);
}