...not really happy with callback

This commit is contained in:
Wastl Kraus 2025-08-31 20:23:04 +02:00
parent 5b02953516
commit a4ec6248ec
2 changed files with 32 additions and 17 deletions

View File

@ -108,7 +108,7 @@ bool DShotRMT::_initTXChannel()
// Initialize RMT RX channel // Initialize RMT RX channel
bool DShotRMT::_initRXChannel() bool DShotRMT::_initRXChannel()
{ {
// Create a queue to receive data from the RX callback // Create a queue to receive data from the RX callback
_rx_queue = xQueueCreate(1, sizeof(rmt_rx_done_event_data_t)); _rx_queue = xQueueCreate(1, sizeof(rmt_rx_done_event_data_t));
if (_rx_queue == nullptr) if (_rx_queue == nullptr)
{ {
@ -122,8 +122,8 @@ bool DShotRMT::_initRXChannel()
_rx_channel_config.mem_block_symbols = RX_BUFFER_SIZE; _rx_channel_config.mem_block_symbols = RX_BUFFER_SIZE;
// Configure reception parameters // Configure reception parameters
_receive_config.signal_range_min_ns = 2; _receive_config.signal_range_min_ns = DSHOT_PULSE_MIN;
_receive_config.signal_range_max_ns = 200; _receive_config.signal_range_max_ns = DSHOT_PULSE_MAX;
// Create RMT RX channel // Create RMT RX channel
if (rmt_new_rx_channel(&_rx_channel_config, &_rmt_rx_channel) != DSHOT_OK) if (rmt_new_rx_channel(&_rx_channel_config, &_rmt_rx_channel) != DSHOT_OK)
@ -288,7 +288,7 @@ uint16_t DShotRMT::_calculateCRC(const dshot_packet_t &packet)
// Transmit DShot packet via RMT // Transmit DShot packet via RMT
uint16_t DShotRMT::_sendDShotFrame(const dshot_packet_t &packet) uint16_t DShotRMT::_sendDShotFrame(const dshot_packet_t &packet)
{ {
// Check timing requirements // Check timing requirements
if (!_timer_signal()) if (!_timer_signal())
{ {
return DSHOT_ERROR; return DSHOT_ERROR;
@ -298,6 +298,9 @@ uint16_t DShotRMT::_sendDShotFrame(const dshot_packet_t &packet)
if (_is_bidirectional) if (_is_bidirectional)
{ {
rmt_receive(_rmt_rx_channel, _rx_symbols, sizeof(_rx_symbols), &_receive_config); rmt_receive(_rmt_rx_channel, _rx_symbols, sizeof(_rx_symbols), &_receive_config);
// Disable RMT RX for sending
rmt_disable(_rmt_rx_channel);
} }
// Encode DShot packet into RMT symbols // Encode DShot packet into RMT symbols
@ -314,9 +317,17 @@ uint16_t DShotRMT::_sendDShotFrame(const dshot_packet_t &packet)
return DSHOT_ERROR; return DSHOT_ERROR;
} }
// Update timestamp // Re-enable RMT RX
_timer_reset(); if (_is_bidirectional)
{
if (rmt_enable(_rmt_rx_channel) != DSHOT_OK)
{
_dshot_log(RX_RMT_RECEIVER_ERROR);
}
}
// Update timestamp and return success
_timer_reset();
return DSHOT_OK; return DSHOT_OK;
} }
@ -410,10 +421,10 @@ void DShotRMT::printDshotInfo(Stream &output) const
// Current DShot mode // Current DShot mode
output.printf("Current Mode: DSHOT%d\n", output.printf("Current Mode: DSHOT%d\n",
_mode == DSHOT150 ? 150 : _mode == DSHOT150 ? 150 : _mode == DSHOT300 ? 300
_mode == DSHOT300 ? 300 : : _mode == DSHOT600 ? 600
_mode == DSHOT600 ? 600 : : _mode == DSHOT1200 ? 1200
_mode == DSHOT1200 ? 1200 : 0); : 0);
output.printf("Bidirectional: %s\n", _is_bidirectional ? "YES" : "NO"); output.printf("Bidirectional: %s\n", _is_bidirectional ? "YES" : "NO");
@ -451,4 +462,3 @@ void DShotRMT::printCpuInfo(Stream &output) const
output.printf("XTAL Freq = %lu MHz\n", getXtalFrequencyMhz()); output.printf("XTAL Freq = %lu MHz\n", getXtalFrequencyMhz());
output.printf("APB Freq = %lu Hz\n", getApbFrequency()); output.printf("APB Freq = %lu Hz\n", getApbFrequency());
} }

View File

@ -30,6 +30,11 @@ constexpr auto RMT_BUFFER_SIZE = DSHOT_BITS_PER_FRAME;
constexpr auto RX_BUFFER_SIZE = 64; constexpr auto RX_BUFFER_SIZE = 64;
constexpr auto TX_BUFFER_SIZE = 64; constexpr auto TX_BUFFER_SIZE = 64;
// Smallest pulse for DShot1200 is 2us. Largest for DShot150 is 40us.
// The range is set from 3us (3000ns) to 60us (60000ns) to be safe across all modes.
constexpr uint32_t DSHOT_PULSE_MIN = 3000;
constexpr uint32_t DSHOT_PULSE_MAX = 60000;
// DShot Mode Enumeration // DShot Mode Enumeration
typedef enum dshot_mode_e typedef enum dshot_mode_e
{ {