|
|
@@ -1,4 +1,4 @@
|
|
|
-// Copyright 2015-2019 Espressif Systems (Shanghai) PTE LTD
|
|
|
+// Copyright 2015-2020 Espressif Systems (Shanghai) PTE LTD
|
|
|
//
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
@@ -79,6 +79,12 @@ typedef struct {
|
|
|
#endif
|
|
|
rmt_item32_t *tx_buf;
|
|
|
RingbufHandle_t rx_buf;
|
|
|
+#if SOC_RMT_SUPPORT_RX_PINGPONG
|
|
|
+ rmt_item32_t *rx_item_buf;
|
|
|
+ uint32_t rx_item_buf_size;
|
|
|
+ uint32_t rx_item_len;
|
|
|
+ uint32_t rx_item_start_idx;
|
|
|
+#endif
|
|
|
sample_to_rmt_t sample_to_rmt;
|
|
|
size_t sample_size_remain;
|
|
|
const uint8_t *sample_cur;
|
|
|
@@ -154,8 +160,8 @@ esp_err_t rmt_set_tx_carrier(rmt_channel_t channel, bool carrier_en, uint16_t hi
|
|
|
RMT_CHECK(channel < RMT_CHANNEL_MAX, RMT_CHANNEL_ERROR_STR, ESP_ERR_INVALID_ARG);
|
|
|
RMT_CHECK(carrier_level < RMT_CARRIER_LEVEL_MAX, RMT_CARRIER_ERROR_STR, ESP_ERR_INVALID_ARG);
|
|
|
RMT_ENTER_CRITICAL();
|
|
|
- rmt_ll_set_carrier_high_low_ticks(p_rmt_obj[channel]->hal.regs, channel, high_level, low_level);
|
|
|
- rmt_ll_set_carrier_to_level(p_rmt_obj[channel]->hal.regs, channel, carrier_level);
|
|
|
+ rmt_ll_set_tx_carrier_high_low_ticks(p_rmt_obj[channel]->hal.regs, channel, high_level, low_level);
|
|
|
+ rmt_ll_set_carrier_on_level(p_rmt_obj[channel]->hal.regs, channel, carrier_level);
|
|
|
rmt_ll_enable_carrier(p_rmt_obj[channel]->hal.regs, channel, carrier_en);
|
|
|
RMT_EXIT_CRITICAL();
|
|
|
return ESP_OK;
|
|
|
@@ -165,7 +171,7 @@ esp_err_t rmt_set_mem_pd(rmt_channel_t channel, bool pd_en)
|
|
|
{
|
|
|
RMT_CHECK(channel < RMT_CHANNEL_MAX, RMT_CHANNEL_ERROR_STR, ESP_ERR_INVALID_ARG);
|
|
|
RMT_ENTER_CRITICAL();
|
|
|
- rmt_ll_power_down_mem(p_rmt_obj[channel]->hal.regs, channel, pd_en);
|
|
|
+ rmt_ll_power_down_mem(p_rmt_obj[channel]->hal.regs, pd_en);
|
|
|
RMT_EXIT_CRITICAL();
|
|
|
return ESP_OK;
|
|
|
}
|
|
|
@@ -174,7 +180,7 @@ esp_err_t rmt_get_mem_pd(rmt_channel_t channel, bool *pd_en)
|
|
|
{
|
|
|
RMT_CHECK(channel < RMT_CHANNEL_MAX, RMT_CHANNEL_ERROR_STR, ESP_ERR_INVALID_ARG);
|
|
|
RMT_ENTER_CRITICAL();
|
|
|
- *pd_en = rmt_ll_is_mem_power_down(p_rmt_obj[channel]->hal.regs, channel);
|
|
|
+ *pd_en = rmt_ll_is_mem_power_down(p_rmt_obj[channel]->hal.regs);
|
|
|
RMT_EXIT_CRITICAL();
|
|
|
return ESP_OK;
|
|
|
}
|
|
|
@@ -187,7 +193,17 @@ esp_err_t rmt_tx_start(rmt_channel_t channel, bool tx_idx_rst)
|
|
|
rmt_ll_reset_tx_pointer(p_rmt_obj[channel]->hal.regs, channel);
|
|
|
}
|
|
|
rmt_ll_clear_tx_end_interrupt(p_rmt_obj[channel]->hal.regs, channel);
|
|
|
- rmt_ll_enable_tx_end_interrupt(p_rmt_obj[channel]->hal.regs, channel, true);
|
|
|
+ // enable tx end interrupt in non-loop mode
|
|
|
+ if (!rmt_ll_is_tx_loop_enabled(p_rmt_obj[channel]->hal.regs, channel)) {
|
|
|
+ rmt_ll_enable_tx_end_interrupt(p_rmt_obj[channel]->hal.regs, channel, true);
|
|
|
+ } else {
|
|
|
+#if SOC_RMT_SUPPORT_TX_LOOP_COUNT
|
|
|
+ rmt_ll_reset_tx_loop(p_rmt_obj[channel]->hal.regs, channel);
|
|
|
+ rmt_ll_enable_tx_loop_count(p_rmt_obj[channel]->hal.regs, channel, true);
|
|
|
+ rmt_ll_clear_tx_loop_interrupt(p_rmt_obj[channel]->hal.regs, channel);
|
|
|
+ rmt_ll_enable_tx_loop_interrupt(p_rmt_obj[channel]->hal.regs, channel, true);
|
|
|
+#endif
|
|
|
+ }
|
|
|
rmt_ll_start_tx(p_rmt_obj[channel]->hal.regs, channel);
|
|
|
RMT_EXIT_CRITICAL();
|
|
|
return ESP_OK;
|
|
|
@@ -213,6 +229,14 @@ esp_err_t rmt_rx_start(rmt_channel_t channel, bool rx_idx_rst)
|
|
|
}
|
|
|
rmt_ll_clear_rx_end_interrupt(p_rmt_obj[channel]->hal.regs, channel);
|
|
|
rmt_ll_enable_rx_end_interrupt(p_rmt_obj[channel]->hal.regs, channel, true);
|
|
|
+
|
|
|
+#if SOC_RMT_SUPPORT_RX_PINGPONG
|
|
|
+ const uint32_t item_block_len = rmt_ll_get_mem_blocks(p_rmt_obj[channel]->hal.regs, channel) * RMT_MEM_ITEM_NUM;
|
|
|
+ p_rmt_obj[channel]->rx_item_start_idx = 0;
|
|
|
+ p_rmt_obj[channel]->rx_item_len = 0;
|
|
|
+ rmt_set_rx_thr_intr_en(channel, true, item_block_len / 2);
|
|
|
+#endif
|
|
|
+
|
|
|
rmt_ll_enable_rx(p_rmt_obj[channel]->hal.regs, channel, true);
|
|
|
RMT_EXIT_CRITICAL();
|
|
|
return ESP_OK;
|
|
|
@@ -222,8 +246,12 @@ esp_err_t rmt_rx_stop(rmt_channel_t channel)
|
|
|
{
|
|
|
RMT_CHECK(channel < RMT_CHANNEL_MAX, RMT_CHANNEL_ERROR_STR, ESP_ERR_INVALID_ARG);
|
|
|
RMT_ENTER_CRITICAL();
|
|
|
- rmt_ll_enable_rx(p_rmt_obj[channel]->hal.regs, channel, false);
|
|
|
rmt_ll_enable_rx_end_interrupt(p_rmt_obj[channel]->hal.regs, channel, false);
|
|
|
+ rmt_ll_enable_rx(p_rmt_obj[channel]->hal.regs, channel, false);
|
|
|
+ rmt_ll_reset_rx_pointer(p_rmt_obj[channel]->hal.regs, channel);
|
|
|
+#if SOC_RMT_SUPPORT_RX_PINGPONG
|
|
|
+ rmt_ll_enable_rx_thres_interrupt(p_rmt_obj[channel]->hal.regs, channel, false);
|
|
|
+#endif
|
|
|
RMT_EXIT_CRITICAL();
|
|
|
return ESP_OK;
|
|
|
}
|
|
|
@@ -262,7 +290,7 @@ esp_err_t rmt_set_tx_loop_mode(rmt_channel_t channel, bool loop_en)
|
|
|
{
|
|
|
RMT_CHECK(channel < RMT_CHANNEL_MAX, RMT_CHANNEL_ERROR_STR, ESP_ERR_INVALID_ARG);
|
|
|
RMT_ENTER_CRITICAL();
|
|
|
- rmt_ll_enable_tx_cyclic(p_rmt_obj[channel]->hal.regs, channel, loop_en);
|
|
|
+ rmt_ll_enable_tx_loop(p_rmt_obj[channel]->hal.regs, channel, loop_en);
|
|
|
RMT_EXIT_CRITICAL();
|
|
|
return ESP_OK;
|
|
|
}
|
|
|
@@ -271,7 +299,7 @@ esp_err_t rmt_get_tx_loop_mode(rmt_channel_t channel, bool *loop_en)
|
|
|
{
|
|
|
RMT_CHECK(channel < RMT_CHANNEL_MAX, RMT_CHANNEL_ERROR_STR, ESP_ERR_INVALID_ARG);
|
|
|
RMT_ENTER_CRITICAL();
|
|
|
- *loop_en = rmt_ll_is_tx_cyclic_enabled(p_rmt_obj[channel]->hal.regs, channel);
|
|
|
+ *loop_en = rmt_ll_is_tx_loop_enabled(p_rmt_obj[channel]->hal.regs, channel);
|
|
|
RMT_EXIT_CRITICAL();
|
|
|
return ESP_OK;
|
|
|
}
|
|
|
@@ -358,6 +386,26 @@ esp_err_t rmt_set_rx_intr_en(rmt_channel_t channel, bool en)
|
|
|
return ESP_OK;
|
|
|
}
|
|
|
|
|
|
+#if SOC_RMT_SUPPORT_RX_PINGPONG
|
|
|
+esp_err_t rmt_set_rx_thr_intr_en(rmt_channel_t channel, bool en, uint16_t evt_thresh)
|
|
|
+{
|
|
|
+ RMT_CHECK(channel < RMT_CHANNEL_MAX, RMT_CHANNEL_ERROR_STR, ESP_ERR_INVALID_ARG);
|
|
|
+ if (en) {
|
|
|
+ uint32_t item_block_len = rmt_ll_get_mem_blocks(p_rmt_obj[channel]->hal.regs, channel) * RMT_MEM_ITEM_NUM;
|
|
|
+ RMT_CHECK(evt_thresh <= item_block_len, "RMT EVT THRESH ERR", ESP_ERR_INVALID_ARG);
|
|
|
+ RMT_ENTER_CRITICAL();
|
|
|
+ rmt_ll_set_rx_limit(p_rmt_obj[channel]->hal.regs, channel, evt_thresh);
|
|
|
+ rmt_ll_enable_rx_thres_interrupt(p_rmt_obj[channel]->hal.regs, channel, true);
|
|
|
+ RMT_EXIT_CRITICAL();
|
|
|
+ } else {
|
|
|
+ RMT_ENTER_CRITICAL();
|
|
|
+ rmt_ll_enable_rx_thres_interrupt(p_rmt_obj[channel]->hal.regs, channel, false);
|
|
|
+ RMT_EXIT_CRITICAL();
|
|
|
+ }
|
|
|
+ return ESP_OK;
|
|
|
+}
|
|
|
+#endif
|
|
|
+
|
|
|
esp_err_t rmt_set_err_intr_en(rmt_channel_t channel, bool en)
|
|
|
{
|
|
|
RMT_CHECK(channel < RMT_CHANNEL_MAX, RMT_CHANNEL_ERROR_STR, ESP_ERR_INVALID_ARG);
|
|
|
@@ -380,7 +428,8 @@ esp_err_t rmt_set_tx_thr_intr_en(rmt_channel_t channel, bool en, uint16_t evt_th
|
|
|
{
|
|
|
RMT_CHECK(channel < RMT_CHANNEL_MAX, RMT_CHANNEL_ERROR_STR, ESP_ERR_INVALID_ARG);
|
|
|
if (en) {
|
|
|
- RMT_CHECK(evt_thresh <= 256, "RMT EVT THRESH ERR", ESP_ERR_INVALID_ARG);
|
|
|
+ uint32_t item_block_len = rmt_ll_get_mem_blocks(p_rmt_obj[channel]->hal.regs, channel) * RMT_MEM_ITEM_NUM;
|
|
|
+ RMT_CHECK(evt_thresh <= item_block_len, "RMT EVT THRESH ERR", ESP_ERR_INVALID_ARG);
|
|
|
RMT_ENTER_CRITICAL();
|
|
|
rmt_ll_set_tx_limit(p_rmt_obj[channel]->hal.regs, channel, evt_thresh);
|
|
|
rmt_ll_enable_tx_thres_interrupt(p_rmt_obj[channel]->hal.regs, channel, true);
|
|
|
@@ -447,7 +496,6 @@ static esp_err_t rmt_internal_config(rmt_dev_t *dev, const rmt_config_t *rmt_par
|
|
|
}
|
|
|
rmt_ll_set_mem_blocks(dev, channel, mem_cnt);
|
|
|
rmt_ll_set_mem_owner(dev, channel, RMT_MEM_OWNER_HW);
|
|
|
- rmt_ll_enable_carrier(dev, channel, false); // disable carrier feature by default
|
|
|
RMT_EXIT_CRITICAL();
|
|
|
|
|
|
s_rmt_src_clock_hz[channel] = rmt_source_clk_hz;
|
|
|
@@ -458,7 +506,13 @@ static esp_err_t rmt_internal_config(rmt_dev_t *dev, const rmt_config_t *rmt_par
|
|
|
uint8_t idle_level = rmt_param->tx_config.idle_level;
|
|
|
|
|
|
RMT_ENTER_CRITICAL();
|
|
|
- rmt_ll_enable_tx_cyclic(dev, channel, rmt_param->tx_config.loop_en);
|
|
|
+ rmt_ll_enable_tx_loop(dev, channel, rmt_param->tx_config.loop_en);
|
|
|
+#if SOC_RMT_SUPPORT_TX_LOOP_COUNT
|
|
|
+ if (rmt_param->tx_config.loop_en) {
|
|
|
+ rmt_ll_set_tx_loop_count(dev, channel, rmt_param->tx_config.loop_count);
|
|
|
+ }
|
|
|
+#endif
|
|
|
+ /* always enable tx ping-pong */
|
|
|
rmt_ll_enable_tx_pingpong(dev, true);
|
|
|
/*Set idle level */
|
|
|
rmt_ll_enable_tx_idle(dev, channel, rmt_param->tx_config.idle_output_en);
|
|
|
@@ -470,11 +524,11 @@ static esp_err_t rmt_internal_config(rmt_dev_t *dev, const rmt_config_t *rmt_par
|
|
|
duty_div = rmt_source_clk_hz / carrier_freq_hz;
|
|
|
duty_h = duty_div * carrier_duty_percent / 100;
|
|
|
duty_l = duty_div - duty_h;
|
|
|
- rmt_ll_set_carrier_to_level(dev, channel, carrier_level);
|
|
|
- rmt_ll_set_carrier_high_low_ticks(dev, channel, duty_h, duty_l);
|
|
|
+ rmt_ll_set_carrier_on_level(dev, channel, carrier_level);
|
|
|
+ rmt_ll_set_tx_carrier_high_low_ticks(dev, channel, duty_h, duty_l);
|
|
|
} else {
|
|
|
- rmt_ll_set_carrier_to_level(dev, channel, 0);
|
|
|
- rmt_ll_set_carrier_high_low_ticks(dev, channel, 0, 0);
|
|
|
+ rmt_ll_set_carrier_on_level(dev, channel, 0);
|
|
|
+ rmt_ll_set_tx_carrier_high_low_ticks(dev, channel, 0, 0);
|
|
|
}
|
|
|
RMT_EXIT_CRITICAL();
|
|
|
|
|
|
@@ -490,6 +544,22 @@ static esp_err_t rmt_internal_config(rmt_dev_t *dev, const rmt_config_t *rmt_par
|
|
|
/* Set RX filter */
|
|
|
rmt_ll_set_rx_filter_thres(dev, channel, filter_cnt);
|
|
|
rmt_ll_enable_rx_filter(dev, channel, rmt_param->rx_config.filter_en);
|
|
|
+
|
|
|
+#if SOC_RMT_SUPPORT_RX_PINGPONG
|
|
|
+ /* always enable rx ping-pong */
|
|
|
+ rmt_ll_enable_rx_pingpong(dev, channel, true);
|
|
|
+#endif
|
|
|
+
|
|
|
+#if SOC_RMT_SUPPORT_RX_DEMODULATION
|
|
|
+ rmt_ll_enable_carrier(dev, channel, rmt_param->rx_config.rm_carrier);
|
|
|
+ if (rmt_param->rx_config.rm_carrier) {
|
|
|
+ uint32_t duty_total = rmt_source_clk_hz / rmt_ll_get_counter_clock_div(dev, channel) / rmt_param->rx_config.carrier_freq_hz;
|
|
|
+ uint32_t duty_high = duty_total * rmt_param->rx_config.carrier_duty_percent / 100;
|
|
|
+ // there could be residual in timing the carrier pulse, so double enlarge the theoretical value
|
|
|
+ rmt_ll_set_rx_carrier_high_low_ticks(dev, channel, duty_high * 2, (duty_total - duty_high) * 2);
|
|
|
+ rmt_ll_set_carrier_on_level(dev, channel, rmt_param->rx_config.carrier_level);
|
|
|
+ }
|
|
|
+#endif
|
|
|
RMT_EXIT_CRITICAL();
|
|
|
|
|
|
ESP_LOGD(RMT_TAG, "Rmt Rx Channel %u|Gpio %u|Sclk_Hz %u|Div %u|Thresold %u|Filter %u",
|
|
|
@@ -660,13 +730,28 @@ static void IRAM_ATTR rmt_driver_isr_default(void *arg)
|
|
|
rmt_ll_set_mem_owner(p_rmt_obj[channel]->hal.regs, channel, RMT_MEM_OWNER_SW);
|
|
|
if (p_rmt->rx_buf) {
|
|
|
addr = RMTMEM.chan[channel].data32;
|
|
|
+#if SOC_RMT_SUPPORT_RX_PINGPONG
|
|
|
+ if (item_len > p_rmt->rx_item_start_idx) {
|
|
|
+ item_len = item_len - p_rmt->rx_item_start_idx;
|
|
|
+ }
|
|
|
+ memcpy((void *)(p_rmt->rx_item_buf + p_rmt->rx_item_len), (void *)(addr + p_rmt->rx_item_start_idx), item_len * 4);
|
|
|
+ p_rmt->rx_item_len += item_len;
|
|
|
+ BaseType_t res = xRingbufferSendFromISR(p_rmt->rx_buf, (void *)(p_rmt->rx_item_buf), p_rmt->rx_item_len * 4, &HPTaskAwoken);
|
|
|
+#else
|
|
|
BaseType_t res = xRingbufferSendFromISR(p_rmt->rx_buf, (void *)addr, item_len * 4, &HPTaskAwoken);
|
|
|
+#endif
|
|
|
if (res == pdFALSE) {
|
|
|
ESP_EARLY_LOGE(RMT_TAG, "RMT RX BUFFER FULL");
|
|
|
}
|
|
|
} else {
|
|
|
ESP_EARLY_LOGE(RMT_TAG, "RMT RX BUFFER ERROR");
|
|
|
}
|
|
|
+
|
|
|
+#if SOC_RMT_SUPPORT_RX_PINGPONG
|
|
|
+ p_rmt->rx_item_start_idx = 0;
|
|
|
+ p_rmt->rx_item_len = 0;
|
|
|
+ memset((void *)p_rmt->rx_item_buf, 0, p_rmt->rx_item_buf_size);
|
|
|
+#endif
|
|
|
rmt_ll_reset_rx_pointer(p_rmt_obj[channel]->hal.regs, channel);
|
|
|
rmt_ll_set_mem_owner(p_rmt_obj[channel]->hal.regs, channel, RMT_MEM_OWNER_HW);
|
|
|
rmt_ll_enable_rx(p_rmt_obj[channel]->hal.regs, channel, true);
|
|
|
@@ -674,6 +759,49 @@ static void IRAM_ATTR rmt_driver_isr_default(void *arg)
|
|
|
rmt_ll_clear_rx_end_interrupt(hal->regs, channel);
|
|
|
}
|
|
|
|
|
|
+#if SOC_RMT_SUPPORT_RX_PINGPONG
|
|
|
+ // Rx thres interrupt
|
|
|
+ status = rmt_ll_get_rx_thres_interrupt_status(hal->regs);
|
|
|
+ while (status) {
|
|
|
+ channel = __builtin_ffs(status) - 1;
|
|
|
+ status &= ~(1 << channel);
|
|
|
+ rmt_obj_t *p_rmt = p_rmt_obj[channel];
|
|
|
+ int mem_item_size = rmt_ll_get_mem_blocks(p_rmt_obj[channel]->hal.regs, channel) * RMT_MEM_ITEM_NUM;
|
|
|
+ int rx_thres_lim = rmt_ll_get_rx_limit(p_rmt_obj[channel]->hal.regs, channel);
|
|
|
+ int item_len = (p_rmt->rx_item_start_idx == 0) ? rx_thres_lim : (mem_item_size - rx_thres_lim);
|
|
|
+ if ((p_rmt->rx_item_len + item_len) < (p_rmt->rx_item_buf_size / 4)) {
|
|
|
+ rmt_ll_set_mem_owner(p_rmt_obj[channel]->hal.regs, channel, RMT_MEM_OWNER_SW);
|
|
|
+ memcpy((void *)(p_rmt->rx_item_buf + p_rmt->rx_item_len), (void *)(RMTMEM.chan[channel].data32 + p_rmt->rx_item_start_idx), item_len * 4);
|
|
|
+ rmt_ll_set_mem_owner(p_rmt_obj[channel]->hal.regs, channel, RMT_MEM_OWNER_HW);
|
|
|
+ p_rmt->rx_item_len += item_len;
|
|
|
+ p_rmt->rx_item_start_idx += item_len;
|
|
|
+ if (p_rmt->rx_item_start_idx >= mem_item_size) {
|
|
|
+ p_rmt->rx_item_start_idx = 0;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ ESP_EARLY_LOGE(RMT_TAG, "---RX buffer too small: %d", sizeof(p_rmt->rx_item_buf));
|
|
|
+ }
|
|
|
+ rmt_ll_clear_rx_thres_interrupt(hal->regs, channel);
|
|
|
+ }
|
|
|
+#endif
|
|
|
+
|
|
|
+#if SOC_RMT_SUPPORT_TX_LOOP_COUNT
|
|
|
+ // loop count interrupt
|
|
|
+ status = rmt_ll_get_tx_loop_interrupt_status(hal->regs);
|
|
|
+ while (status) {
|
|
|
+ channel = __builtin_ffs(status) - 1;
|
|
|
+ status &= ~(1 << channel);
|
|
|
+ rmt_obj_t *p_rmt = p_rmt_obj[channel];
|
|
|
+ if (p_rmt) {
|
|
|
+ xSemaphoreGiveFromISR(p_rmt->tx_sem, &HPTaskAwoken);
|
|
|
+ if (rmt_tx_end_callback.function != NULL) {
|
|
|
+ rmt_tx_end_callback.function(channel, rmt_tx_end_callback.arg);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ rmt_ll_clear_tx_loop_interrupt(hal->regs, channel);
|
|
|
+ }
|
|
|
+#endif
|
|
|
+
|
|
|
// Err interrupt
|
|
|
status = rmt_ll_get_err_interrupt_status(hal->regs);
|
|
|
while (status) {
|
|
|
@@ -710,7 +838,10 @@ esp_err_t rmt_driver_uninstall(rmt_channel_t channel)
|
|
|
rmt_set_rx_intr_en(channel, 0);
|
|
|
rmt_set_err_intr_en(channel, 0);
|
|
|
rmt_set_tx_intr_en(channel, 0);
|
|
|
- rmt_set_tx_thr_intr_en(channel, 0, 0xffff);
|
|
|
+ rmt_set_tx_thr_intr_en(channel, false, 0xffff);
|
|
|
+#if SOC_RMT_SUPPORT_RX_PINGPONG
|
|
|
+ rmt_set_rx_thr_intr_en(channel, false, 0xffff);
|
|
|
+#endif
|
|
|
|
|
|
_lock_acquire_recursive(&rmt_driver_isr_lock);
|
|
|
|
|
|
@@ -742,6 +873,13 @@ esp_err_t rmt_driver_uninstall(rmt_channel_t channel)
|
|
|
if (p_rmt_obj[channel]->sample_to_rmt) {
|
|
|
p_rmt_obj[channel]->sample_to_rmt = NULL;
|
|
|
}
|
|
|
+#if SOC_RMT_SUPPORT_RX_PINGPONG
|
|
|
+ if (p_rmt_obj[channel]->rx_item_buf) {
|
|
|
+ free(p_rmt_obj[channel]->rx_item_buf);
|
|
|
+ p_rmt_obj[channel]->rx_item_buf = NULL;
|
|
|
+ p_rmt_obj[channel]->rx_item_buf_size = 0;
|
|
|
+ }
|
|
|
+#endif
|
|
|
|
|
|
free(p_rmt_obj[channel]);
|
|
|
p_rmt_obj[channel] = NULL;
|
|
|
@@ -762,12 +900,12 @@ esp_err_t rmt_driver_install(rmt_channel_t channel, size_t rx_buf_size, int intr
|
|
|
}
|
|
|
|
|
|
#if !CONFIG_SPIRAM_USE_MALLOC
|
|
|
- p_rmt_obj[channel] = (rmt_obj_t *)malloc(sizeof(rmt_obj_t));
|
|
|
+ p_rmt_obj[channel] = calloc(1, sizeof(rmt_obj_t));
|
|
|
#else
|
|
|
if (!(intr_alloc_flags & ESP_INTR_FLAG_IRAM)) {
|
|
|
- p_rmt_obj[channel] = (rmt_obj_t *)malloc(sizeof(rmt_obj_t));
|
|
|
+ p_rmt_obj[channel] = calloc(1, sizeof(rmt_obj_t));
|
|
|
} else {
|
|
|
- p_rmt_obj[channel] = (rmt_obj_t *)heap_caps_calloc(1, sizeof(rmt_obj_t), MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
|
|
|
+ p_rmt_obj[channel] = heap_caps_calloc(1, sizeof(rmt_obj_t), MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
|
|
|
}
|
|
|
#endif
|
|
|
|
|
|
@@ -775,7 +913,6 @@ esp_err_t rmt_driver_install(rmt_channel_t channel, size_t rx_buf_size, int intr
|
|
|
ESP_LOGE(RMT_TAG, "RMT driver malloc error");
|
|
|
return ESP_ERR_NO_MEM;
|
|
|
}
|
|
|
- memset(p_rmt_obj[channel], 0, sizeof(rmt_obj_t));
|
|
|
|
|
|
rmt_hal_init(&p_rmt_obj[channel]->hal);
|
|
|
rmt_hal_channel_reset(&p_rmt_obj[channel]->hal, channel);
|
|
|
@@ -804,6 +941,26 @@ esp_err_t rmt_driver_install(rmt_channel_t channel, size_t rx_buf_size, int intr
|
|
|
if (p_rmt_obj[channel]->rx_buf == NULL && rx_buf_size > 0) {
|
|
|
p_rmt_obj[channel]->rx_buf = xRingbufferCreate(rx_buf_size, RINGBUF_TYPE_NOSPLIT);
|
|
|
}
|
|
|
+
|
|
|
+#if SOC_RMT_SUPPORT_RX_PINGPONG
|
|
|
+ if (p_rmt_obj[channel]->rx_item_buf == NULL && rx_buf_size > 0) {
|
|
|
+#if !CONFIG_SPIRAM_USE_MALLOC
|
|
|
+ p_rmt_obj[channel]->rx_item_buf = calloc(1, rx_buf_size);
|
|
|
+#else
|
|
|
+ if (!(p_rmt_obj[channel]->intr_alloc_flags & ESP_INTR_FLAG_IRAM)) {
|
|
|
+ p_rmt_obj[channel]->rx_item_buf = calloc(1, rx_buf_size);
|
|
|
+ } else {
|
|
|
+ p_rmt_obj[channel]->rx_item_buf = heap_caps_calloc(1, rx_buf_size, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
|
|
|
+ }
|
|
|
+#endif
|
|
|
+ if (p_rmt_obj[channel]->rx_item_buf == NULL) {
|
|
|
+ ESP_LOGE(RMT_TAG, "RMT malloc fail");
|
|
|
+ return ESP_FAIL;
|
|
|
+ }
|
|
|
+ p_rmt_obj[channel]->rx_item_buf_size = rx_buf_size;
|
|
|
+ }
|
|
|
+#endif
|
|
|
+
|
|
|
rmt_set_err_intr_en(channel, 1);
|
|
|
_lock_acquire_recursive(&rmt_driver_isr_lock);
|
|
|
|
|
|
@@ -858,8 +1015,17 @@ esp_err_t rmt_write_items(rmt_channel_t channel, const rmt_item32_t *rmt_item, i
|
|
|
rmt_tx_start(channel, true);
|
|
|
p_rmt->wait_done = wait_tx_done;
|
|
|
if (wait_tx_done) {
|
|
|
- xSemaphoreTake(p_rmt->tx_sem, portMAX_DELAY);
|
|
|
- xSemaphoreGive(p_rmt->tx_sem);
|
|
|
+ // wait loop done
|
|
|
+ if (rmt_ll_is_tx_loop_enabled(p_rmt_obj[channel]->hal.regs, channel)) {
|
|
|
+#if SOC_RMT_SUPPORT_TX_LOOP_COUNT
|
|
|
+ xSemaphoreTake(p_rmt->tx_sem, portMAX_DELAY);
|
|
|
+ xSemaphoreGive(p_rmt->tx_sem);
|
|
|
+#endif
|
|
|
+ } else {
|
|
|
+ // wait tx end
|
|
|
+ xSemaphoreTake(p_rmt->tx_sem, portMAX_DELAY);
|
|
|
+ xSemaphoreGive(p_rmt->tx_sem);
|
|
|
+ }
|
|
|
}
|
|
|
return ESP_OK;
|
|
|
}
|
|
|
@@ -1000,3 +1166,27 @@ esp_err_t rmt_get_counter_clock(rmt_channel_t channel, uint32_t *clock_hz)
|
|
|
RMT_EXIT_CRITICAL();
|
|
|
return ESP_OK;
|
|
|
}
|
|
|
+
|
|
|
+#if SOC_RMT_SUPPORT_TX_GROUP
|
|
|
+esp_err_t rmt_add_channel_to_group(rmt_channel_t channel)
|
|
|
+{
|
|
|
+ RMT_CHECK(channel < RMT_CHANNEL_MAX, RMT_CHANNEL_ERROR_STR, ESP_ERR_INVALID_ARG);
|
|
|
+ RMT_ENTER_CRITICAL();
|
|
|
+ rmt_ll_enable_tx_sync(p_rmt_obj[channel]->hal.regs, true);
|
|
|
+ rmt_ll_add_channel_to_group(p_rmt_obj[channel]->hal.regs, channel);
|
|
|
+ rmt_ll_reset_counter_clock_div(p_rmt_obj[channel]->hal.regs, channel);
|
|
|
+ RMT_EXIT_CRITICAL();
|
|
|
+ return ESP_OK;
|
|
|
+}
|
|
|
+
|
|
|
+esp_err_t rmt_remove_channel_from_group(rmt_channel_t channel)
|
|
|
+{
|
|
|
+ RMT_CHECK(channel < RMT_CHANNEL_MAX, RMT_CHANNEL_ERROR_STR, ESP_ERR_INVALID_ARG);
|
|
|
+ RMT_ENTER_CRITICAL();
|
|
|
+ if (rmt_ll_remove_channel_from_group(p_rmt_obj[channel]->hal.regs, channel) == 0) {
|
|
|
+ rmt_ll_enable_tx_sync(p_rmt_obj[channel]->hal.regs, false);
|
|
|
+ }
|
|
|
+ RMT_EXIT_CRITICAL();
|
|
|
+ return ESP_OK;
|
|
|
+}
|
|
|
+#endif
|