Procházet zdrojové kódy

driver(rmt): Fixed some RMT related issues.

1. Add missing get function to RMT API: rmt_get_idle_level().
2. Suppress error message from rmt_wait_tx_done() if wait_time==0 (allows for polling).
3. Remove the blank lines between parameter lists.

Merges https://github.com/espressif/esp-idf/pull/2666
Paul Abbott před 7 roky
rodič
revize
be567d3eb5
2 změnil soubory, kde provedl 25 přidání a 53 odebrání
  1. 14 52
      components/driver/include/driver/rmt.h
  2. 11 1
      components/driver/rmt.c

+ 14 - 52
components/driver/include/driver/rmt.h

@@ -148,16 +148,11 @@ typedef struct {
  *        This function may be called from an ISR, so, the code should be short and efficient.
  *
  * @param  src Pointer to the buffer storing the raw data that needs to be converted to rmt format.
- *
  * @param[out] dest Pointer to the buffer storing the rmt format data.
- *
  * @param  src_size The raw data size.
- *
  * @param  wanted_num The number of rmt format data that wanted to get.
- *
  * @param[out] translated_size The size of the raw data that has been converted to rmt format,
  *             it should return 0 if no data is converted in user callback.
- *
  * @param[out] item_num The number of the rmt format data that actually converted to, it can be less than wanted_num if there is not enough raw data,
  *             but cannot exceed wanted_num. it should return 0 if no data was converted.
  *
@@ -172,7 +167,6 @@ typedef void (*sample_to_rmt_t)(const void* src, rmt_item32_t* dest, size_t src_
  * @brief Set RMT clock divider, channel clock is divided from source clock.
  *
  * @param channel RMT channel (0-7)
- *
  * @param div_cnt RMT counter clock divider
  *
  * @return
@@ -185,7 +179,6 @@ esp_err_t rmt_set_clk_div(rmt_channel_t channel, uint8_t div_cnt);
  * @brief Get RMT clock divider, channel clock is divided from source clock.
  *
  * @param channel RMT channel (0-7)
- *
  * @param div_cnt pointer to accept RMT counter divider
  *
  * @return
@@ -202,7 +195,6 @@ esp_err_t rmt_get_clk_div(rmt_channel_t channel, uint8_t* div_cnt);
  *        the receive process is finished.
  *
  * @param channel RMT channel (0-7)
- *
  * @param thresh RMT RX idle threshold
  *
  * @return
@@ -219,7 +211,6 @@ esp_err_t rmt_set_rx_idle_thresh(rmt_channel_t channel, uint16_t thresh);
  *        the receive process is finished.
  *
  * @param channel RMT channel (0-7)
- *
  * @param thresh pointer to accept RMT RX idle threshold value
  *
  * @return
@@ -247,7 +238,6 @@ esp_err_t rmt_get_rx_idle_thresh(rmt_channel_t channel, uint16_t *thresh);
  *        Channel 0 can use at most 8 blocks of memory, accordingly channel 7 can only use one memory block.
  *
  * @param channel RMT channel (0-7)
- *
  * @param rmt_mem_num RMT RX memory block number, one block has 64 * 32 bits.
  *
  * @return
@@ -260,7 +250,6 @@ esp_err_t rmt_set_mem_block_num(rmt_channel_t channel, uint8_t rmt_mem_num);
  * @brief Get RMT memory block number
  *
  * @param channel RMT channel (0-7)
- *
  * @param rmt_mem_num Pointer to accept RMT RX memory block number
  *
  * @return
@@ -276,13 +265,9 @@ esp_err_t rmt_get_mem_block_num(rmt_channel_t channel, uint8_t* rmt_mem_num);
  *        The unit of carrier_high/low is the source clock tick, not the divided channel counter clock.
  *
  * @param channel RMT channel (0-7)
- *
  * @param carrier_en Whether to enable output carrier.
- *
  * @param high_level High level duration of carrier
- *
  * @param low_level Low level duration of carrier.
- *
  * @param carrier_level Configure the way carrier wave is modulated for channel 0-7.
  *     - 1'b1:transmit on low output level
  *     - 1'b0:transmit on high output level
@@ -299,7 +284,6 @@ esp_err_t rmt_set_tx_carrier(rmt_channel_t channel, bool carrier_en, uint16_t hi
  *        Reduce power consumed by memory. 1:memory is in low power state.
  *
  * @param channel RMT channel (0-7)
- *
  * @param pd_en RMT memory low power enable.
  *
  * @return
@@ -312,7 +296,6 @@ esp_err_t rmt_set_mem_pd(rmt_channel_t channel, bool pd_en);
  * @brief Get RMT memory low power mode.
  *
  * @param channel RMT channel (0-7)
- *
  * @param pd_en Pointer to accept RMT memory low power mode.
  *
  * @return
@@ -325,7 +308,6 @@ esp_err_t rmt_get_mem_pd(rmt_channel_t channel, bool* pd_en);
  * @brief Set RMT start sending data from memory.
  *
  * @param channel RMT channel (0-7)
- *
  * @param tx_idx_rst Set true to reset memory index for TX.
  *                   Otherwise, transmitter will continue sending from the last index in memory.
  *
@@ -350,7 +332,6 @@ esp_err_t rmt_tx_stop(rmt_channel_t channel);
  * @brief Set RMT start receiving data.
  *
  * @param channel RMT channel (0-7)
- *
  * @param rx_idx_rst Set true to reset memory index for receiver.
  *                   Otherwise, receiver will continue receiving data to the last index in memory.
  *
@@ -386,7 +367,6 @@ esp_err_t rmt_memory_rw_rst(rmt_channel_t channel);
  * @brief Set RMT memory owner.
  *
  * @param channel RMT channel (0-7)
- *
  * @param owner To set when the transmitter or receiver can process the memory of channel.
  *
  * @return
@@ -399,7 +379,6 @@ esp_err_t rmt_set_memory_owner(rmt_channel_t channel, rmt_mem_owner_t owner);
  * @brief Get RMT memory owner.
  *
  * @param channel RMT channel (0-7)
- *
  * @param owner Pointer to get memory owner.
  *
  * @return
@@ -412,7 +391,6 @@ esp_err_t rmt_get_memory_owner(rmt_channel_t channel, rmt_mem_owner_t* owner);
  * @brief Set RMT tx loop mode.
  *
  * @param channel RMT channel (0-7)
- *
  * @param loop_en Enable RMT transmitter loop sending mode.
  *                If set true, transmitter will continue sending from the first data
  *                to the last data in channel 0-7 over and over again in a loop.
@@ -427,7 +405,6 @@ esp_err_t rmt_set_tx_loop_mode(rmt_channel_t channel, bool loop_en);
  * @brief Get RMT tx loop mode.
  *
  * @param channel RMT channel (0-7)
- *
  * @param loop_en Pointer to accept RMT transmitter loop sending mode.
  *
  * @return
@@ -443,9 +420,7 @@ esp_err_t rmt_get_tx_loop_mode(rmt_channel_t channel, bool* loop_en);
  *        Counted in source clock, not divided counter clock.
  *
  * @param channel RMT channel (0-7)
- *
  * @param rx_filter_en To enable RMT receiver filter.
- *
  * @param thresh Threshold of pulse width for receiver.
  *
  * @return
@@ -462,7 +437,6 @@ esp_err_t rmt_set_rx_filter(rmt_channel_t channel, bool rx_filter_en, uint8_t th
  *        2. REF tick clock, which would be 1Mhz (not supported in this version).
  *
  * @param channel RMT channel (0-7)
- *
  * @param base_clk To choose source clock for RMT module.
  *
  * @return
@@ -479,7 +453,6 @@ esp_err_t rmt_set_source_clk(rmt_channel_t channel, rmt_source_clk_t base_clk);
  *        2. REF tick clock, which would be 1Mhz (not supported in this version).
  *
  * @param channel RMT channel (0-7)
- *
  * @param src_clk Pointer to accept source clock for RMT module.
  *
  * @return
@@ -492,9 +465,7 @@ esp_err_t rmt_get_source_clk(rmt_channel_t channel, rmt_source_clk_t* src_clk);
  * @brief Set RMT idle output level for transmitter
  *
  * @param channel RMT channel (0-7)
- *
  * @param idle_out_en To enable idle level output.
- *
  * @param level To set the output signal's level for channel 0-7 in idle state.
  *
  * @return
@@ -504,10 +475,22 @@ esp_err_t rmt_get_source_clk(rmt_channel_t channel, rmt_source_clk_t* src_clk);
 esp_err_t rmt_set_idle_level(rmt_channel_t channel, bool idle_out_en, rmt_idle_level_t level);
 
 /**
- * @brief Get RMT status
+ * @brief Get RMT idle output level for transmitter
  *
  * @param channel RMT channel (0-7)
+ * @param idle_out_en Pointer to accept value of enable idle.
+ * @param level Pointer to accept value of output signal's level in idle state for specified channel.
  *
+ * @return
+ *     - ESP_ERR_INVALID_ARG Parameter error
+ *     - ESP_OK Success
+ */
+esp_err_t rmt_get_idle_level(rmt_channel_t channel, bool* idle_out_en, rmt_idle_level_t* level);
+
+/**
+ * @brief Get RMT status
+ *
+ * @param channel RMT channel (0-7)
  * @param status Pointer to accept channel status.
  *        Please refer to RMT_CHnSTATUS_REG(n=0~7) in `rmt_reg.h` for more details of each field.
  *
@@ -537,7 +520,6 @@ void rmt_clr_intr_enable_mask(uint32_t mask);
  * @brief Set RMT RX interrupt enable
  *
  * @param channel RMT channel (0 - 7)
- *
  * @param en enable or disable RX interrupt.
  *
  * @return
@@ -550,7 +532,6 @@ esp_err_t rmt_set_rx_intr_en(rmt_channel_t channel, bool en);
  * @brief Set RMT RX error interrupt enable
  *
  * @param channel RMT channel (0 - 7)
- *
  * @param en enable or disable RX err interrupt.
  *
  * @return
@@ -563,7 +544,6 @@ esp_err_t rmt_set_err_intr_en(rmt_channel_t channel, bool en);
  * @brief Set RMT TX interrupt enable
  *
  * @param channel RMT channel (0 - 7)
- *
  * @param en enable or disable TX interrupt.
  *
  * @return
@@ -578,9 +558,7 @@ esp_err_t rmt_set_tx_intr_en(rmt_channel_t channel, bool en);
  * An interrupt will be triggered when the number of transmitted items reaches the threshold value
  *
  * @param channel RMT channel (0 - 7)
- *
  * @param en enable or disable TX event interrupt.
- *
  * @param evt_thresh RMT event interrupt threshold value
  *
  * @return
@@ -593,9 +571,7 @@ esp_err_t rmt_set_tx_thr_intr_en(rmt_channel_t channel, bool en, uint16_t evt_th
  * @brief Set RMT pin
  *
  * @param channel RMT channel (0 - 7)
- *
  * @param mode TX or RX mode for RMT
- *
  * @param gpio_num GPIO number to transmit or receive the signal.
  *
  * @return
@@ -651,11 +627,8 @@ esp_err_t rmt_isr_deregister(rmt_isr_handle_t handle);
  * @brief Fill memory data of channel with given RMT items.
  *
  * @param channel RMT channel (0 - 7)
- *
  * @param item Pointer of items.
- *
  * @param item_num RMT sending items number.
- *
  * @param mem_offset Index offset of memory.
  *
  * @return
@@ -668,9 +641,7 @@ esp_err_t rmt_fill_tx_items(rmt_channel_t channel, const rmt_item32_t* item, uin
  * @brief Initialize RMT driver
  *
  * @param channel RMT channel (0 - 7)
- *
  * @param rx_buf_size Size of RMT RX ringbuffer. Can be 0 if the RX ringbuffer is not used.
- *
  * @param intr_alloc_flags Flags for the RMT driver interrupt handler. Pass 0 for default flags. See esp_intr_alloc.h for details.
  *        If ESP_INTR_FLAG_IRAM is used, please do not use the memory allocated from psram when calling rmt_write_items.
  *
@@ -712,12 +683,9 @@ esp_err_t rmt_get_channel_status(rmt_channel_status_result_t *channel_status);
  *        This API allows user to send waveform with any length.
  *
  * @param channel RMT channel (0 - 7)
- *
  * @param rmt_item head point of RMT items array.
  *        If ESP_INTR_FLAG_IRAM is used, please do not use the memory allocated from psram when calling rmt_write_items.
- *
  * @param item_num RMT data item number.
- *
  * @param wait_tx_done
  *        - If set 1, it will block the task and wait for sending done.
  *        - If set 0, it will not wait and return immediately.
@@ -741,8 +709,7 @@ esp_err_t rmt_write_items(rmt_channel_t channel, const rmt_item32_t* rmt_item, i
  * @brief Wait RMT TX finished.
  *
  * @param channel RMT channel (0 - 7)
- *
- * @param wait_time Maximum time in ticks to wait for transmission to be complete 
+ * @param wait_time Maximum time in ticks to wait for transmission to be complete.  If set 0, return immediately with ESP_ERR_TIMEOUT if TX is busy (polling).
  *
  * @return
  *     - ESP_OK RMT Tx done successfully
@@ -758,7 +725,6 @@ esp_err_t rmt_wait_tx_done(rmt_channel_t channel, TickType_t wait_time);
  *        Users can get the RMT RX ringbuffer handle, and process the RX data.
  *
  * @param channel RMT channel (0 - 7)
- *
  * @param buf_handle Pointer to buffer handle to accept RX ringbuffer handle.
  *
  * @return
@@ -773,7 +739,6 @@ esp_err_t rmt_get_ringbuf_handle(rmt_channel_t channel, RingbufHandle_t* buf_han
  *        If a channel is initialized more than once, tha user callback will be replaced by the later.
  *
  * @param channel RMT channel (0 - 7).
- *
  * @param fn Point to the data conversion function.
  *
  * @return
@@ -787,11 +752,8 @@ esp_err_t rmt_translator_init(rmt_channel_t channel, sample_to_rmt_t fn);
  *        Requires rmt_translator_init to init the translator first.
  *
  * @param channel RMT channel (0 - 7).
- *
  * @param src Pointer to the raw data.
- *
  * @param src_size The size of the raw data.
- *
  * @param wait_tx_done Set true to wait all data send done.
  *
  * @return

+ 11 - 1
components/driver/rmt.c

@@ -307,6 +307,14 @@ esp_err_t rmt_set_idle_level(rmt_channel_t channel, bool idle_out_en, rmt_idle_l
     return ESP_OK;
 }
 
+esp_err_t rmt_get_idle_level(rmt_channel_t channel, bool* idle_out_en, rmt_idle_level_t* level)
+{
+    RMT_CHECK(channel < RMT_CHANNEL_MAX, RMT_CHANNEL_ERROR_STR, ESP_ERR_INVALID_ARG);
+    *idle_out_en = (bool) (RMT.conf_ch[channel].conf1.idle_out_en);
+    *level = (rmt_idle_level_t) (RMT.conf_ch[channel].conf1.idle_out_lv);
+    return ESP_OK;
+}
+
 esp_err_t rmt_get_status(rmt_channel_t channel, uint32_t* status)
 {
     RMT_CHECK(channel < RMT_CHANNEL_MAX, RMT_CHANNEL_ERROR_STR, ESP_ERR_INVALID_ARG);
@@ -838,7 +846,9 @@ esp_err_t rmt_wait_tx_done(rmt_channel_t channel, TickType_t wait_time)
         return ESP_OK;
     }
     else {
-        ESP_LOGE(RMT_TAG, "Timeout on wait_tx_done");
+        if (wait_time != 0) {  // Don't emit error message if just polling.
+            ESP_LOGE(RMT_TAG, "Timeout on wait_tx_done");
+        }
         return ESP_ERR_TIMEOUT;
     }
 }