rcbench
Servo and ESC test bench: panel, IOmcu and shared C
Loading...
Searching...
No Matches
dshot.h
Go to the documentation of this file.
1
37
38#ifndef RCBENCH_DSHOT_H
39#define RCBENCH_DSHOT_H
40
41#include <stdbool.h>
42#include <stddef.h>
43#include <stdint.h>
44
45#ifdef __cplusplus
46extern "C" {
47#endif
48
49/* ------------------------------------------------------------- the frame */
50
51#define DSHOT_FRAME_BITS 16u
52#define DSHOT_VALUE_MAX 2047u
53#define DSHOT_CMD_MAX 47u
54#define DSHOT_THROTTLE_MIN 48u
55#define DSHOT_THROTTLE_MAX 2047u
56
64#define DSHOT_CMD_REPEATS 10u
65
73typedef enum {
74 DSHOT_CMD_MOTOR_STOP = 0,
75 DSHOT_CMD_BEEP1 = 1,
76 DSHOT_CMD_BEEP2 = 2,
77 DSHOT_CMD_BEEP3 = 3,
78 DSHOT_CMD_BEEP4 = 4,
79 DSHOT_CMD_BEEP5 = 5,
80 DSHOT_CMD_ESC_INFO = 6,
81 DSHOT_CMD_SPIN_DIRECTION_1 = 7,
82 DSHOT_CMD_SPIN_DIRECTION_2 = 8,
83 DSHOT_CMD_3D_MODE_OFF = 9,
84 DSHOT_CMD_3D_MODE_ON = 10,
85 DSHOT_CMD_SETTINGS_REQUEST = 11,
86 DSHOT_CMD_SAVE_SETTINGS = 12,
87 DSHOT_CMD_EDT_ENABLE = 13,
88 DSHOT_CMD_EDT_DISABLE = 14,
89 DSHOT_CMD_SPIN_NORMAL = 20,
90 DSHOT_CMD_SPIN_REVERSED = 21,
92
113uint16_t dshot_frame(uint16_t value, bool telemetry, bool inverted);
114
132uint16_t dshot_throttle(uint16_t command, uint16_t span);
133
134/* ------------------------------------------------- the burst coming back */
135
140#define DSHOT_TELEM_BITS 21u
141
143#define DSHOT_TELEM_RATE_NUM 5u
144#define DSHOT_TELEM_RATE_DEN 4u
145
153#define DSHOT_EDT_MV_PER_COUNT 250u
154#define DSHOT_EDT_A_PER_COUNT 1u
155#define DSHOT_EDT_DEGC_PER_COUNT 1u
156
164uint32_t dshot_edt_millivolts(uint16_t count);
171uint32_t dshot_edt_amps(uint16_t count);
178uint32_t dshot_edt_celsius(uint16_t count);
179
201
205typedef struct {
207 uint16_t payload;
208 uint32_t period_us;
209 uint32_t erpm;
210 uint8_t value;
212
230bool dshot_gcr_decode(uint32_t line, uint16_t *out);
231
238uint32_t dshot_gcr_encode(uint16_t value);
239
258bool dshot_telem_from_value(uint16_t value, bool edt, dshot_telem_t *out);
259
268bool dshot_telem_decode(uint32_t line, bool edt, dshot_telem_t *out);
269
278uint16_t dshot_telem_value(dshot_telem_kind_t kind, uint16_t payload);
279
291uint32_t dshot_rpm(uint32_t erpm, uint8_t pole_pairs);
292
293/* ---------------------------------------- asking for extended telemetry */
294
299#define DSHOT_EDT_RETRY_MS 500u
300
302#define DSHOT_EDT_ASKS 10u
303
326typedef struct {
327 uint8_t left;
328 uint8_t asks;
329 uint32_t due_ms;
330 bool answered;
331 bool asked;
333
340void dshot_edt_bind(dshot_edt_t *e, uint32_t now_ms);
341
352void dshot_edt_idle(dshot_edt_t *e, uint32_t now_ms);
353
365bool dshot_edt_frame(dshot_edt_t *e, bool stopped, uint32_t now_ms);
366
374
375/* --------------------------------------------------- the captured samples */
376
403bool dshot_rx_bits(const uint32_t *samples, size_t words, uint8_t oversample,
404 uint32_t *line);
405
406#ifdef __cplusplus
407}
408#endif
409
410#endif /* RCBENCH_DSHOT_H */
dshot_telem_kind_t
What one response carried.
Definition dshot.h:187
@ DSHOT_TELEM_STATUS
Definition dshot.h:195
@ DSHOT_TELEM_VOLTAGE
Definition dshot.h:190
@ DSHOT_TELEM_CURRENT
Definition dshot.h:191
@ DSHOT_TELEM_STRESS
Definition dshot.h:194
@ DSHOT_TELEM_KINDS
How many kinds there are, for anything holding one slot per kind.
Definition dshot.h:199
@ DSHOT_TELEM_DEBUG1
Definition dshot.h:192
@ DSHOT_TELEM_DEBUG2
Definition dshot.h:193
@ DSHOT_TELEM_TEMPERATURE
Definition dshot.h:189
@ DSHOT_TELEM_ERPM
Definition dshot.h:188
dshot_cmd_t
The command range, 0 to 47.
Definition dshot.h:73
void dshot_edt_bind(dshot_edt_t *e, uint32_t now_ms)
A new binding: nothing asked, nothing heard, an ask due at once.
Definition dshot_edt.c:13
void dshot_edt_heard(dshot_edt_t *e, dshot_telem_kind_t kind)
A reply arrived; an extended kind after an ask ends the asking.
Definition dshot_edt.c:72
void dshot_edt_idle(dshot_edt_t *e, uint32_t now_ms)
Not driving: the next run owes the ask again, due from its first frame.
Definition dshot_edt.c:22
bool dshot_edt_frame(dshot_edt_t *e, bool stopped, uint32_t now_ms)
Whether the frame about to go out is a repeat of DSHOT_CMD_EDT_ENABLE.
Definition dshot_edt.c:36
uint16_t dshot_throttle(uint16_t command, uint16_t span)
Map a command of 0..span onto the throttle range.
Definition dshot_frame.c:47
uint16_t dshot_frame(uint16_t value, bool telemetry, bool inverted)
Build a frame.
Definition dshot_frame.c:33
bool dshot_gcr_decode(uint32_t line, uint16_t *out)
Undo the line code and the group code: 21 line bits to a 16-bit value.
Definition dshot_telem.c:95
uint16_t dshot_telem_value(dshot_telem_kind_t kind, uint16_t payload)
Build a response, for the suite and for anything that fakes an ESC.
Definition dshot_telem.c:205
uint32_t dshot_gcr_encode(uint16_t value)
The other direction, for the suite and for anything that fakes an ESC.
Definition dshot_telem.c:75
uint32_t dshot_rpm(uint32_t erpm, uint8_t pole_pairs)
Electrical rpm to mechanical rpm.
Definition dshot_telem.c:230
uint32_t dshot_edt_millivolts(uint16_t count)
Millivolts for a DSHOT_TELEM_VOLTAGE payload (at most 255 * 250 = 63,750).
Definition dshot_telem.c:310
uint32_t dshot_edt_amps(uint16_t count)
Amperes for a DSHOT_TELEM_CURRENT payload.
Definition dshot_telem.c:315
bool dshot_telem_decode(uint32_t line, bool edt, dshot_telem_t *out)
The two steps above, together: 21 line bits to a reading.
Definition dshot_telem.c:196
bool dshot_telem_from_value(uint16_t value, bool edt, dshot_telem_t *out)
A 16-bit value to what it meant, checksum first.
Definition dshot_telem.c:159
uint32_t dshot_edt_celsius(uint16_t count)
Degrees Celsius for a DSHOT_TELEM_TEMPERATURE payload.
Definition dshot_telem.c:320
bool dshot_rx_bits(const uint32_t *samples, size_t words, uint8_t oversample, uint32_t *line)
Turn an oversampled capture of the line into the 21 bits of the response.
Definition dshot_telem.c:252
When to send DSHOT_CMD_EDT_ENABLE, and whether the ESC has answered.
Definition dshot.h:326
uint32_t due_ms
Definition dshot.h:329
bool answered
Definition dshot.h:330
uint8_t left
Definition dshot.h:327
bool asked
Definition dshot.h:331
uint8_t asks
Definition dshot.h:328
One decoded response.
Definition dshot.h:205
uint32_t erpm
Definition dshot.h:209
uint32_t period_us
Definition dshot.h:208
uint8_t value
Definition dshot.h:210
uint16_t payload
Definition dshot.h:207