From f1cce0faa7b7481862648d024c6442cfb3ec39c0 Mon Sep 17 00:00:00 2001 From: Wastl Kraus Date: Thu, 19 Jun 2025 00:43:59 +0200 Subject: [PATCH] ...rmt class objects --- DShotRMT.cpp | 14 ++++++-------- DShotRMT.h | 6 ++++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/DShotRMT.cpp b/DShotRMT.cpp index b767120..85681a3 100644 --- a/DShotRMT.cpp +++ b/DShotRMT.cpp @@ -18,7 +18,7 @@ void DShotRMT::begin() // RX RMT Channel Configuration (for BiDirectional DShot) if (_isBidirectional) { - rmt_rx_channel_config_t rmt_rx_channel_config = { + _rmt_rx_channel_config = { .gpio_num = _gpio, .clk_src = DSHOT_CLOCK_SRC_DEFAULT, .resolution_hz = DSHOT_RMT_RESOLUTION, @@ -27,15 +27,15 @@ void DShotRMT::begin() .invert_in = false, .with_dma = false}}; - rmt_new_rx_channel(&rmt_rx_channel_config, &_rmt_rx_channel); + rmt_new_rx_channel(&_rmt_rx_channel_config, &_rmt_rx_channel); rmt_enable(_rmt_rx_channel); - _receive_config.signal_range_min_ns = 100; - _receive_config.signal_range_max_ns = 10000; + _receive_config.signal_range_min_ns = 1000; + _receive_config.signal_range_max_ns = 15000; } // TX RMT Channel Configuration - rmt_tx_channel_config_t rmt_tx_channel_config = { + _rmt_tx_channel_config = { .gpio_num = _gpio, .clk_src = DSHOT_CLOCK_SRC_DEFAULT, .resolution_hz = DSHOT_RMT_RESOLUTION, @@ -46,7 +46,7 @@ void DShotRMT::begin() .invert_out = _isBidirectional, .with_dma = false}}; - rmt_new_tx_channel(&rmt_tx_channel_config, &_rmt_tx_channel); + rmt_new_tx_channel(&_rmt_tx_channel_config, &_rmt_tx_channel); rmt_enable(_rmt_tx_channel); // Use a copy encoder to send raw symbols @@ -80,10 +80,8 @@ void DShotRMT::setThrottle(uint16_t throttle) size_t count = 0; encodeDShotTX(_tx_packet, _tx_symbols, count); - // Restart transmission with new data rmt_disable(_rmt_tx_channel); rmt_enable(_rmt_tx_channel); - rmt_transmit(_rmt_tx_channel, _dshot_encoder, _tx_symbols, count * sizeof(rmt_symbol_word_t), &_transmit_config); } diff --git a/DShotRMT.h b/DShotRMT.h index a278418..870cf33 100644 --- a/DShotRMT.h +++ b/DShotRMT.h @@ -29,10 +29,10 @@ static constexpr auto NO_ERPM_SIGNAL = 0; // RMT configuration parameters static constexpr auto DSHOT_CLOCK_SRC_DEFAULT = RMT_CLK_SRC_DEFAULT; -static constexpr auto DSHOT_RMT_RESOLUTION = 10 * 1000 * 1000; // 10 MHz +static constexpr auto DSHOT_RMT_RESOLUTION = 10 * 1000 * 1000; // 10 MHz - 0.1 µs Tick static constexpr auto TX_BUFFER_SIZE = DSHOT_BITS_PER_FRAME; -static constexpr auto RX_BUFFER_SIZE = DSHOT_BITS_PER_FRAME + 4; // Padding for RX decoding +static constexpr auto RX_BUFFER_SIZE = 32; // Padding for RX decoding // --- DShot Mode Selection --- // Select the appropriate bit timing for the protocol @@ -92,6 +92,8 @@ private: // --- RMT Channel --- rmt_channel_handle_t _rmt_rx_channel = nullptr; rmt_channel_handle_t _rmt_tx_channel = nullptr; + rmt_rx_channel_config_t _rmt_rx_channel_config = {}; + rmt_tx_channel_config_t _rmt_tx_channel_config = {}; // --- DShot RMT Encoder --- rmt_encoder_handle_t _dshot_encoder = nullptr;