From 8de9fd8cd7d29123d2ff0c895b25ad8f6451e89d Mon Sep 17 00:00:00 2001 From: morris Date: Thu, 28 Jul 2022 19:05:58 +0800 Subject: [PATCH] rmt: only use register to control IDLE state hardware issue: we can't control the IDLE level by the stop item when loop transmission is enabled. But we can always control the IDLE state by register. --- components/driver/rmt/rmt_tx.c | 13 +++---------- .../components/test_utils/ref_clock_impl_rmt_pcnt.c | 1 + 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/components/driver/rmt/rmt_tx.c b/components/driver/rmt/rmt_tx.c index 3bd09da52b..b2c6bff66e 100644 --- a/components/driver/rmt/rmt_tx.c +++ b/components/driver/rmt/rmt_tx.c @@ -268,8 +268,8 @@ esp_err_t rmt_new_tx_channel(const rmt_tx_channel_config_t *config, rmt_channel_ rmt_ll_tx_set_limit(hal->regs, channel_id, tx_channel->ping_pong_symbols); // disable carrier modulation by default, can reenable by `rmt_apply_carrier()` rmt_ll_tx_enable_carrier_modulation(hal->regs, channel_id, false); - // idle level is determind by eof encoder, not set to a fixed value - rmt_ll_tx_fix_idle_level(hal->regs, channel_id, 0, false); + // idle level is determined by register value + rmt_ll_tx_fix_idle_level(hal->regs, channel_id, 0, true); // always enable tx wrap, both DMA mode and ping-pong mode rely this feature rmt_ll_tx_enable_wrap(hal->regs, channel_id, true); @@ -662,6 +662,7 @@ static void IRAM_ATTR rmt_tx_do_transaction(rmt_tx_channel_t *tx_chan, rmt_tx_tr #endif // turn on the TX machine portENTER_CRITICAL_ISR(&channel->spinlock); + rmt_ll_tx_fix_idle_level(hal->regs, channel_id, t->flags.eot_level, true); rmt_ll_tx_start(hal->regs, channel_id); portEXIT_CRITICAL_ISR(&channel->spinlock); } @@ -720,9 +721,6 @@ static esp_err_t rmt_tx_disable(rmt_channel_handle_t channel) int channel_id = channel->channel_id; portENTER_CRITICAL(&channel->spinlock); - // when this function called, the transaction might be middle-way, the output level when we stop the transmitter is nondeterministic, - // so we fix the idle level temporarily - rmt_ll_tx_fix_idle_level(hal->regs, channel->channel_id, tx_chan->cur_trans ? tx_chan->cur_trans->flags.eot_level : 0, true); rmt_ll_tx_enable_loop(hal->regs, channel->channel_id, false); #if SOC_RMT_SUPPORT_TX_ASYNC_STOP rmt_ll_tx_stop(hal->regs, channel->channel_id); @@ -740,11 +738,6 @@ static esp_err_t rmt_tx_disable(rmt_channel_handle_t channel) rmt_ll_clear_interrupt_status(hal->regs, RMT_LL_EVENT_TX_MASK(channel_id)); portEXIT_CRITICAL(&group->spinlock); - portENTER_CRITICAL(&channel->spinlock); - // restore the idle level selection, to be determind by eof symbol - rmt_ll_tx_fix_idle_level(hal->regs, channel_id, 0, false); - portEXIT_CRITICAL(&channel->spinlock); - #if SOC_RMT_SUPPORT_DMA if (channel->dma_chan) { gdma_stop(channel->dma_chan); diff --git a/tools/unit-test-app/components/test_utils/ref_clock_impl_rmt_pcnt.c b/tools/unit-test-app/components/test_utils/ref_clock_impl_rmt_pcnt.c index 41709016bc..398bedcac6 100644 --- a/tools/unit-test-app/components/test_utils/ref_clock_impl_rmt_pcnt.c +++ b/tools/unit-test-app/components/test_utils/ref_clock_impl_rmt_pcnt.c @@ -107,6 +107,7 @@ void ref_clock_init(void) }; rmt_transmit_config_t trans_config = { .loop_count = 0, // no loop + .flags.eot_level = 1, }; TEST_ESP_OK(rmt_transmit(s_rmt_chan, s_rmt_encoder, &data, sizeof(data), &trans_config));