16uint8_t dshot_crc(uint16_t v12,
bool bidirectional)
18 uint8_t crc = (uint8_t)((v12 ^ (v12 >> 4) ^ (v12 >> 8)) & 0x0F);
20 crc = (uint8_t)((~crc) & 0x0F);
25uint16_t detws_dshot_encode(uint16_t value11,
bool telemetry,
bool bidirectional)
28 uint16_t v12 = (uint16_t)((value11 << 1) | (telemetry ? 1 : 0));
29 uint8_t crc = dshot_crc(v12, bidirectional);
30 return (uint16_t)((v12 << 4) | crc);
33bool detws_dshot_decode(uint16_t frame, uint16_t *value11,
bool *telemetry,
bool bidirectional)
35 uint16_t v12 = (uint16_t)(frame >> 4);
36 uint8_t got = (uint8_t)(frame & 0x0F);
37 if (got != dshot_crc(v12, bidirectional))
40 *value11 = (uint16_t)(v12 >> 1);
42 *telemetry = (v12 & 1) != 0;
46uint32_t detws_dshot_bit_ns(uint16_t rate_kbit,
bool bit)
67 return bit ? (period_ns * 3 / 4) : (period_ns * 3 / 8);
70uint32_t detws_esc_pwm_ns(uint16_t throttle_1000, DetwsEscPwm mode)
76 case DetwsEscPwm::DETWS_ESC_ONESHOT125:
80 case DetwsEscPwm::DETWS_ESC_ONESHOT42:
84 case DetwsEscPwm::DETWS_ESC_MULTISHOT:
88 case DetwsEscPwm::DETWS_ESC_PWM:
94 if (throttle_1000 > 1000)
97 return lo + (uint32_t)(((uint64_t)(hi - lo) * throttle_1000) / 1000);
DShot ESC digital throttle protocol codec (DETWS_ENABLE_DSHOT).