16uint8_t dshot_crc(uint16_t v12,
bool bidirectional)
18 uint8_t crc = (uint8_t)((v12 ^ (v12 >> 4) ^ (v12 >> 8)) & 0x0F);
21 crc = (uint8_t)((~crc) & 0x0F);
27uint16_t pc_dshot_encode(uint16_t value11,
bool telemetry,
bool bidirectional)
30 uint16_t v12 = (uint16_t)((value11 << 1) | (telemetry ? 1 : 0));
31 uint8_t crc = dshot_crc(v12, bidirectional);
32 return (uint16_t)((v12 << 4) | crc);
35bool pc_dshot_decode(uint16_t frame, uint16_t *value11,
bool *telemetry,
bool bidirectional)
37 uint16_t v12 = (uint16_t)(frame >> 4);
38 uint8_t got = (uint8_t)(frame & 0x0F);
39 if (got != dshot_crc(v12, bidirectional))
45 *value11 = (uint16_t)(v12 >> 1);
49 *telemetry = (v12 & 1) != 0;
54uint32_t pc_dshot_bit_ns(uint16_t rate_kbit,
bool bit)
75 return bit ? (period_ns * 3 / 4) : (period_ns * 3 / 8);
78uint32_t pc_esc_pwm_ns(uint16_t throttle_1000, pc_esc_pwm mode)
84 case pc_esc_pwm::PC_ESC_ONESHOT125:
88 case pc_esc_pwm::PC_ESC_ONESHOT42:
92 case pc_esc_pwm::PC_ESC_MULTISHOT:
96 case pc_esc_pwm::PC_ESC_PWM:
102 if (throttle_1000 > 1000)
104 throttle_1000 = 1000;
107 return lo + (uint32_t)(((uint64_t)(hi - lo) * throttle_1000) / 1000);
DShot ESC digital throttle protocol codec (PC_ENABLE_DSHOT).