...trying new tricks

This commit is contained in:
Wastl Kraus 2025-08-18 22:11:32 +02:00
parent ef0778b7ee
commit 9ee5aea348
2 changed files with 10 additions and 9 deletions

View File

@ -131,7 +131,6 @@ uint16_t DShotRMT::getERPM()
} }
// Try to receive telemetry data // Try to receive telemetry data
rmt_symbol_word_t _rx_symbols[RX_BUFFER_SIZE];
if (!rmt_receive(_rmt_rx_channel, _rx_symbols, DSHOT_SYMBOLS_SIZE, &_receive_config)) if (!rmt_receive(_rmt_rx_channel, _rx_symbols, DSHOT_SYMBOLS_SIZE, &_receive_config))
{ {
Serial.println(DSHOT_MSG_08); Serial.println(DSHOT_MSG_08);
@ -222,14 +221,13 @@ bool DShotRMT::_initDShotEncoder()
bool DShotRMT::_sendDShotFrame(const dshot_packet_t &packet) bool DShotRMT::_sendDShotFrame(const dshot_packet_t &packet)
{ {
// Excluding calculation from timing is more timing stable // Excluding calculation from timing is more timing stable
rmt_symbol_word_t tx_symbols[DSHOT_BITS_PER_FRAME]; _encodeDShotFrame(packet, _tx_symbols);
_encodeDShotFrame(packet, tx_symbols);
// Checking timer signal // Checking timer signal
if (_timer_signal()) if (_timer_signal())
{ {
// Triggers RMT Transmit // Triggers RMT Transmit
rmt_transmit(_rmt_tx_channel, _dshot_encoder, tx_symbols, DSHOT_SYMBOLS_SIZE, &_transmit_config); rmt_transmit(_rmt_tx_channel, _dshot_encoder, _tx_symbols, DSHOT_SYMBOLS_SIZE, &_transmit_config);
// Time Stamp // Time Stamp
return _timer_reset(); return _timer_reset();
@ -276,7 +274,7 @@ dshot_packet_t DShotRMT::_buildDShotPacket(const uint16_t value)
} }
// Encodes DShot packet into RMT buffer and places code into IRAM instead of flash // Encodes DShot packet into RMT buffer and places code into IRAM instead of flash
bool DShotRMT::_encodeDShotFrame(const dshot_packet_t &packet, rmt_symbol_word_t *symbols) bool IRAM_ATTR DShotRMT::_encodeDShotFrame(const dshot_packet_t &packet, rmt_symbol_word_t *symbols)
{ {
// Parse actual packet into buffer // Parse actual packet into buffer
_current_packet = _parseDShotPacket(packet); _current_packet = _parseDShotPacket(packet);
@ -339,9 +337,10 @@ uint16_t DShotRMT::_decodeDShotFrame(const rmt_symbol_word_t *symbols)
} }
// Timer triggered // Timer triggered
bool DShotRMT::_timer_signal() bool IRAM_ATTR DShotRMT::_timer_signal()
{ {
return (micros() - _last_transmission_time >= _frame_timer_us); // trying new tricks
return __builtin_expect((micros() - _last_transmission_time >= _frame_timer_us), 1);
} }
// Updates timestamp // Updates timestamp

View File

@ -112,6 +112,8 @@ private:
rmt_encoder_handle_t _dshot_encoder; rmt_encoder_handle_t _dshot_encoder;
// --- RMT Config --- // --- RMT Config ---
rmt_symbol_word_t _tx_symbols[DSHOT_BITS_PER_FRAME];
rmt_symbol_word_t _rx_symbols[RX_BUFFER_SIZE];
rmt_tx_channel_config_t _tx_channel_config; rmt_tx_channel_config_t _tx_channel_config;
rmt_rx_channel_config_t _rx_channel_config; rmt_rx_channel_config_t _rx_channel_config;
rmt_transmit_config_t _transmit_config; rmt_transmit_config_t _transmit_config;
@ -132,11 +134,11 @@ private:
uint16_t _calculateCRC(const dshot_packet_t &packet); uint16_t _calculateCRC(const dshot_packet_t &packet);
dshot_packet_t _buildDShotPacket(const uint16_t value); dshot_packet_t _buildDShotPacket(const uint16_t value);
uint16_t _parseDShotPacket(const dshot_packet_t &packet); uint16_t _parseDShotPacket(const dshot_packet_t &packet);
bool _encodeDShotFrame(const dshot_packet_t &packet, rmt_symbol_word_t *symbols); bool IRAM_ATTR _encodeDShotFrame(const dshot_packet_t &packet, rmt_symbol_word_t *symbols);
uint16_t _decodeDShotFrame(const rmt_symbol_word_t *symbols); uint16_t _decodeDShotFrame(const rmt_symbol_word_t *symbols);
// --- Simple Timer --- // --- Simple Timer ---
bool _timer_signal(); bool IRAM_ATTR _timer_signal();
bool _timer_reset(); bool _timer_reset();
// --- Error Handling --- // --- Error Handling ---