2025-06-11 08:29:59 +01:00
|
|
|
/**
|
|
|
|
|
* @file DShotRMT.h
|
|
|
|
|
* @brief DShot signal generation using ESP32 RMT with continuous repeat and pause between frames
|
|
|
|
|
* @author Wastl Kraus
|
|
|
|
|
* @date 2025-06-11
|
|
|
|
|
* @license MIT
|
|
|
|
|
*/
|
2021-06-29 19:05:20 +01:00
|
|
|
|
2025-06-11 08:29:59 +01:00
|
|
|
#pragma once
|
2021-06-29 19:05:20 +01:00
|
|
|
|
2023-03-10 16:45:18 +00:00
|
|
|
#include <Arduino.h>
|
2025-06-11 08:29:59 +01:00
|
|
|
#include <driver/rmt_tx.h>
|
2022-11-26 12:52:46 +00:00
|
|
|
|
2025-06-11 08:29:59 +01:00
|
|
|
static constexpr auto DSHOT_THROTTLE_FAILSAVE = 0;
|
|
|
|
|
static constexpr auto DSHOT_THROTTLE_MIN = 48;
|
|
|
|
|
static constexpr auto DSHOT_THROTTLE_MAX = 2047;
|
|
|
|
|
static constexpr auto DEFAULT_RES_HZ = 10 * 1000 * 1000; // 10 MHz resolution
|
|
|
|
|
static constexpr auto PAUSE_BITS = 21;
|
|
|
|
|
static constexpr auto DSHOT_NULL_PACKET = 0b0000000000000000;
|
2021-06-29 19:05:20 +01:00
|
|
|
|
2025-06-11 08:29:59 +01:00
|
|
|
/// DShot Mode
|
2022-11-25 15:08:58 +00:00
|
|
|
typedef enum dshot_mode_e
|
|
|
|
|
{
|
2023-03-24 12:44:49 +00:00
|
|
|
DSHOT150,
|
|
|
|
|
DSHOT300,
|
2025-06-11 08:29:59 +01:00
|
|
|
DSHOT600
|
2021-06-29 19:05:20 +01:00
|
|
|
} dshot_mode_t;
|
|
|
|
|
|
2022-11-25 15:08:58 +00:00
|
|
|
class DShotRMT
|
|
|
|
|
{
|
2023-03-24 12:44:49 +00:00
|
|
|
public:
|
2025-06-11 08:29:59 +01:00
|
|
|
DShotRMT(gpio_num_t gpio, dshot_mode_t mode = DSHOT300, bool isBidirectional = false);
|
2023-03-27 18:47:23 +01:00
|
|
|
|
2025-06-11 08:29:59 +01:00
|
|
|
void begin();
|
|
|
|
|
void setThrottle(uint16_t throttle, bool telemetry = false);
|
2021-06-29 19:05:20 +01:00
|
|
|
|
2025-06-11 08:29:59 +01:00
|
|
|
gpio_num_t getGPIO() const { return _gpio; }
|
|
|
|
|
dshot_mode_t getDShotMode() const { return _mode; }
|
2021-06-29 19:05:20 +01:00
|
|
|
|
2023-03-24 12:44:49 +00:00
|
|
|
private:
|
2025-06-11 08:29:59 +01:00
|
|
|
gpio_num_t _gpio;
|
|
|
|
|
dshot_mode_t _mode;
|
|
|
|
|
bool _isBidirectional;
|
2021-06-29 19:05:20 +01:00
|
|
|
|
2025-06-12 11:24:27 +01:00
|
|
|
rmt_channel_handle_t _rmt_channel = nullptr;
|
2025-06-11 08:29:59 +01:00
|
|
|
rmt_encoder_handle_t _encoder = nullptr;
|
2025-06-12 11:24:27 +01:00
|
|
|
rmt_transmit_config_t _transmit_config = {};
|
2023-03-27 18:47:23 +01:00
|
|
|
|
2025-06-11 08:29:59 +01:00
|
|
|
void buildFrameSymbols(uint16_t frame, rmt_symbol_word_t *symbols, size_t &count);
|
|
|
|
|
};
|