|
rcbench
Servo and ESC test bench: panel, IOmcu and shared C
|
The outbound half of DShot: sixteen bits and the map from travel onto them. More...
#include "dshot.h"Functions | |
| static uint16_t | fold (uint16_t payload) |
| The checksum is three nibbles of the twelve-bit payload folded together. | |
| uint16_t | dshot_frame (uint16_t value, bool telemetry, bool inverted) |
| Build a frame. | |
| uint16_t | dshot_throttle (uint16_t command, uint16_t span) |
Map a command of 0..span onto the throttle range. | |
The outbound half of DShot: sixteen bits and the map from travel onto them.
See dshot.h for the model.
SPDX-License-Identifier: MIT
| uint16_t dshot_frame | ( | uint16_t | value, |
| bool | telemetry, | ||
| bool | inverted ) |
Build a frame.
value is 0..2047 and is used as given: mapping travel onto it is dshot_throttle()'s job, and a caller that wants to send command 12 must be able to say 12. telemetry asks the ESC to answer on its telemetry wire (the separate serial one, not the signal line). inverted selects bidirectional DShot, whose checksum is the complement of the ordinary one so that a receiver cannot mistake one protocol for the other.
Returns 0 for a value above 2047: zero is motor-stop, which is the safe reading of a number this end could not encode.
| value | Frame value, 0..2047, used as given. |
| telemetry | true asks the ESC to answer on its telemetry wire. |
| inverted | true selects bidirectional DShot (complemented checksum). |
| uint16_t dshot_throttle | ( | uint16_t | command, |
| uint16_t | span ) |
Map a command of 0..span onto the throttle range.
Zero is DSHOT_CMD_MOTOR_STOP and everything above it lands in 48..2047, so the command range is never entered by a throttle that is merely low. The discontinuity at the bottom is the protocol's, not this function's: an ESC has no idea of "barely turning".
A command above span returns DSHOT_CMD_MOTOR_STOP, the same reading of a fault that dshot_frame() applies to a value it cannot encode. A command equal to span is the top of the range and returns 2047.
| command | Command or travel step, 0 to span. |
| span | Largest command, the top of the travel. |
span; otherwise a value from 48 to 2047.
|
static |
The checksum is three nibbles of the twelve-bit payload folded together.
It catches every single-bit error and every burst inside one nibble, which is what a bit period misread as its neighbour looks like. It is not a CRC (cyclic redundancy check) in any useful sense and the protocol does not claim one.
| payload | The twelve-bit payload, value and telemetry bit. |