網頁

2018年11月23日 星期五

DIY - ESP32:ESP32 RMT API 函數(三十六)

DIY - ESP32:ESP32 RMT API 函數(三十六):

ESP32 的 IDF 內 RMT (遠程控制 / Remote Control)API函數,RMT(遠程控制)函數模塊可用於發送和接收紅外遙控信號。 由於RMT模塊的靈活性,函數模塊還可用於生成或接收許多其他類型的信號。

功能 - rmt_set_clk_div
原型:esp_err_t rmt_set_clk_div(rmt_channel_t channel, uint8_t div_cnt)
參數:channel: RMT channel (0-7)
            div_cnt: RMT counter clock divider
返回:ESP_ERR_INVALID_ARG Parameter error
            ESP_OK Success
說明:Set RMT clock divider, channel clock is divided from source clock.
範例:

功能 - rmt_get_clk_div
原型:esp_err_t rmt_get_clk_div(rmt_channel_t channel, uint8_t *div_cnt)
參數:channel: RMT channel (0-7)
            div_cnt: pointer to accept RMT counter divider
返回:ESP_ERR_INVALID_ARG Parameter error
            ESP_OK Success
說明:Get RMT clock divider, channel clock is divided from source clock.
範例:

功能 - rmt_set_rx_idle_thresh(
原型:esp_err_t rmt_set_rx_idle_thresh(rmt_channel_t channel, uint16_t thresh)
參數:channel: RMT channel (0-7)
            thresh: RMT RX idle threshold
返回:ESP_ERR_INVALID_ARG Parameter error
            ESP_OK Success
說明:Set RMT RX idle threshold value. In receive mode, when no edge is detected on the input signal for longer than idle_thres channel clock cycles, the receive process is finished.
範例:

功能 - rmt_get_rx_idle_thresh
原型:esp_err_t rmt_get_rx_idle_thresh(rmt_channel_t channel, uint16_t *thresh)
參數:channel: RMT channel (0-7)
            thresh: pointer to accept RMT RX idle threshold value
返回:ESP_ERR_INVALID_ARG Parameter error
            ESP_OK Success
說明:Get RMT idle threshold value.
In receive mode, when no edge is detected on the input signal for longer than idle_thres channel clock cycles, the receive process is finished.
範例:

功能 - rmt_set_mem_block_num
原型:esp_err_t rmt_set_mem_block_num(rmt_channel_t channel, uint8_t rmt_mem_num)
參數:channel: RMT channel (0-7)
            rmt_mem_num: RMT RX memory block number, one block has 64 * 32 bits.
返回:ESP_ERR_INVALID_ARG Parameter error
            ESP_OK Success
說明:Set RMT memory block number for RMT channel.
This function is used to configure the amount of memory blocks allocated to channel n The 8 channels share a 512x32-bit RAM block which can be read and written by the processor cores over the APB bus, as well as read by the transmitters and written by the receivers.
The RAM address range for channel n is start_addr_CHn to end_addr_CHn, which are defined by: Memory block start address is RMT_CHANNEL_MEM(n) (in soc/rmt_reg.h), that is, start_addr_chn = RMT base address + 0x800 + 64 4 n, and end_addr_chn = RMT base address + 0x800 + 64 4 n + 64 4 RMT_MEM_SIZE_CHn mod 512 4
If memory block number of one channel is set to a value greater than 1, this channel will occupy the memory block of the next channel. Channel 0 can use at most 8 blocks of memory, accordingly channel 7 can only use one memory block.
範例:

功能 - rmt_get_mem_block_num
原型:esp_err_t rmt_get_mem_block_num(rmt_channel_t channel, uint8_t *rmt_mem_num)
參數:channel: RMT channel (0-7)
            rmt_mem_num: Pointer to accept RMT RX memory block number
返回:ESP_ERR_INVALID_ARG Parameter error
            ESP_OK Success
說明:Get RMT memory block number.
範例:

功能 - rmt_set_tx_carrier
原型:esp_err_t rmt_set_tx_carrier(rmt_channel_t channel, bool carrier_en, uint16_t high_level, uint16_t low_level, rmt_carrier_level_t carrier_level)
參數:channel: RMT channel (0-7)
            carrier_en: Whether to enable output carrier.
            high_level: High level duration of carrier
            low_level: Low level duration of carrier.
            carrier_level: Configure the way carrier wave is modulated for channel 0-7.
                 b1:transmit on low output level
                 b0:transmit on high output level
返回:ESP_ERR_INVALID_ARG Parameter error
            ESP_OK Success
說明:Configure RMT carrier for TX signal.

Set different values for carrier_high and carrier_low to set different frequency of carrier. The unit of carrier_high/low is the source clock tick, not the divided channel counter clock.
範例:

功能 - rmt_set_mem_pd
原型:esp_err_t rmt_set_mem_pd(rmt_channel_t channel, bool pd_en)
參數:channel: RMT channel (0-7)
            pd_en: RMT memory low power enable.
返回:ESP_ERR_INVALID_ARG Parameter error
            ESP_OK Success
說明:Set RMT memory in low power mode.
Reduce power consumed by memory. 1:memory is in low power state.
範例:

功能 - rmt_get_mem_pd
原型:esp_err_t rmt_get_mem_pd(rmt_channel_t channel, bool *pd_en)
參數:channel: RMT channel (0-7)
            pd_en: Pointer to accept RMT memory low power mode.
返回:ESP_ERR_INVALID_ARG Parameter error
            ESP_OK Success
說明:Get RMT memory low power mode.
範例:

功能 - rmt_tx_start
原型:esp_err_t rmt_tx_start(rmt_channel_t channel, bool tx_idx_rst)
參數:channel: RMT channel (0-7)
            tx_idx_rst: Set true to reset memory index for TX. Otherwise, transmitter will continue sending from the last index in memory.
返回:ESP_ERR_INVALID_ARG Parameter error
            ESP_OK Success
說明:Set RMT start sending data from memory.
範例:

功能 - rmt_tx_stop
原型:esp_err_t rmt_tx_stop(rmt_channel_t channel)
參數:channel: RMT channel (0-7)
返回:ESP_ERR_INVALID_ARG Parameter error
            ESP_OK Success
說明:Set RMT stop sending.
範例:

功能 - rmt_rx_start
原型:esp_err_t rmt_rx_start(rmt_channel_t channel, bool rx_idx_rst)
參數:channel: RMT channel (0-7)
            rx_idx_rst: Set true to reset memory index for receiver. Otherwise, receiver will continue receiving data to the last index in memory.
返回:ESP_ERR_INVALID_ARG Parameter error
            ESP_OK Success
說明:Set RMT start receiving data.
範例:

功能 - rmt_rx_stop
原型:esp_err_t rmt_rx_stop(rmt_channel_t channel)
參數:channel: RMT channel (0-7)
返回:ESP_ERR_INVALID_ARG Parameter error
            ESP_OK Success
說明:Set RMT stop receiving data.
範例:

功能 - rmt_memory_rw_rst
原型:esp_err_t rmt_memory_rw_rst(rmt_channel_t channel)
參數:channel: RMT channel (0-7)
返回:ESP_ERR_INVALID_ARG Parameter error
            ESP_OK Success
說明:Reset RMT TX/RX memory index.
範例:

功能 - rmt_set_memory_owner
原型:esp_err_t rmt_set_memory_owner(rmt_channel_t channel, rmt_mem_owner_t owner)
參數:channel: RMT channel (0-7)
            owner: To set when the transmitter or receiver can process the memory of channel.
返回:ESP_ERR_INVALID_ARG Parameter error
            ESP_OK Success
說明:Set RMT memory owner.
範例:

功能 - rmt_set_tx_loop_mode
原型:esp_err_t rmt_set_tx_loop_mode(rmt_channel_t channel, bool loop_en)
參數: channel: RMT channel (0-7)
             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.
返回:ESP_ERR_INVALID_ARG Parameter error
            ESP_OK Success
說明:Set RMT tx loop mode.
範例:

功能 - rmt_get_tx_loop_mode
原型:esp_err_t rmt_get_tx_loop_mode(rmt_channel_t channel, bool *loop_en)
參數:channel: RMT channel (0-7)
            loop_en: Pointer to accept RMT transmitter loop sending mode.
返回:ESP_ERR_INVALID_ARG Parameter error
            ESP_OK Success
說明:Get RMT tx loop mode.
範例:

功能 - rmt_set_rx_filter
原型:esp_err_t rmt_set_rx_filter(rmt_channel_t channel, bool rx_filter_en, uint8_t thresh)
參數:channel: RMT channel (0-7)
            rx_filter_en: To enable RMT receiver filter.
            thresh: Threshold of pulse width for receiver.
返回:ESP_ERR_INVALID_ARG Parameter error
            ESP_OK Success
說明:Set RMT RX filter.
In receive mode, channel 0-7 will ignore input pulse when the pulse width is smaller than threshold. Counted in source clock, not divided counter clock.
範例:

功能 - rmt_set_source_clk
原型:esp_err_t rmt_set_source_clk(rmt_channel_t channel, rmt_source_clk_t base_clk)
參數:channel: RMT channel (0-7)
            base_clk: To choose source clock for RMT module.
返回:ESP_ERR_INVALID_ARG Parameter error
            ESP_OK Success
說明:Set RMT source clock.
RMT module has two clock sources: APB clock which is 80Mhz, REF tick clock, which would be 1Mhz (not supported in this version).
範例:

功能 - rmt_get_source_clk
原型:esp_err_t rmt_get_source_clk(rmt_channel_t channel, rmt_source_clk_t *src_clk)
參數:channel: RMT channel (0-7)
            src_clk: Pointer to accept source clock for RMT module.
返回:ESP_ERR_INVALID_ARG Parameter error
            ESP_OK Success
說明:Get RMT source clock.
RMT module has two clock sources: APB clock which is 80Mhz, REF tick clock, which would be 1Mhz (not supported in this version).
範例:

功能 - rmt_set_idle_level
原型:esp_err_t rmt_set_idle_level(rmt_channel_t channel, bool idle_out_en, rmt_idle_level_t level)
參數:channel: RMT channel (0-7)
            idle_out_en: To enable idle level output.
            level: To set the output signal’s level for channel 0-7 in idle state.
返回:ESP_ERR_INVALID_ARG Parameter error
            ESP_OK Success
說明:Set RMT idle output level for transmitter.
範例:

功能 - rmt_get_status
原型:esp_err_t rmt_get_status(rmt_channel_t channel, uint32_t *status)
參數:channel: RMT channel (0-7)
            status: Pointer to accept channel status.
返回:ESP_ERR_INVALID_ARG Parameter error
            ESP_OK Success
說明:Get RMT status.
範例:

功能 - rmt_set_intr_enable_mask
原型:void rmt_set_intr_enable_mask(uint32_t mask)
參數:mask: Bit mask to set to the register
返回:
說明:Set mask value to RMT interrupt enable register.
範例:

功能 - rmt_clr_intr_enable_mask
原型:void rmt_clr_intr_enable_mask(uint32_t mask)
參數:mask: Bit mask to clear the register
返回:
說明:Clear mask value to RMT interrupt enable register.
範例:

功能 - rmt_set_rx_intr_en
原型:esp_err_t rmt_set_rx_intr_en(rmt_channel_t channel, bool en)
參數:channel: RMT channel (0 - 7)
            en: enable or disable RX interrupt.
返回:ESP_ERR_INVALID_ARG Parameter error
            ESP_OK Success
說明:Set RMT RX interrupt enable.
範例:

功能 - rmt_set_err_intr_en
原型:esp_err_t rmt_set_err_intr_en(rmt_channel_t channel, bool en)
參數:channel: RMT channel (0 - 7)
            en: enable or disable RX err interrupt.
返回:ESP_ERR_INVALID_ARG Parameter error
            ESP_OK Success
說明:Set RMT RX error interrupt enable.
範例:

功能 - rmt_set_tx_intr_en
原型:esp_err_t rmt_set_tx_intr_en(rmt_channel_t channel, bool en)
參數:channel: RMT channel (0 - 7)
            en: enable or disable TX interrupt.
返回:ESP_ERR_INVALID_ARG Parameter error
            ESP_OK Success
說明:Set RMT TX interrupt enable.
範例:

功能 - rmt_set_tx_thr_intr_en
原型:esp_err_t rmt_set_tx_thr_intr_en(rmt_channel_t channel, bool en, uint16_t evt_thresh)
參數:channel: RMT channel (0 - 7)
            en: enable or disable TX event interrupt.
            evt_thresh: RMT event interrupt threshold value
返回:ESP_ERR_INVALID_ARG Parameter error
            ESP_OK Success
說明:Set RMT TX threshold event interrupt enable.
An interrupt will be triggered when the number of transmitted items reaches the threshold value
範例:

功能 - rmt_set_pin
原型:esp_err_t rmt_set_pin(rmt_channel_t channel, rmt_mode_t mode, gpio_num_t gpio_num)
參數:channel: RMT channel (0 - 7)
            mode: TX or RX mode for RMT
            gpio_num: GPIO number to transmit or receive the signal.
返回:ESP_ERR_INVALID_ARG Parameter error
            ESP_OK Success
說明:Set RMT pin.
範例:

功能 - rmt_config
原型:esp_err_t rmt_config(const rmt_config_t *rmt_param)
參數:rmt_param: RMT parameter struct
返回:ESP_ERR_INVALID_ARG Parameter error
            ESP_OK Success
說明:Configure RMT parameters.
範例:

功能 - rmt_isr_register
原型:esp_err_t rmt_isr_register(void (*fn)(void *), void *arg, int intr_alloc_flags, rmt_isr_handle_t *handle, )
參數:fn: Interrupt handler function.
            arg: Parameter for the handler function
            intr_alloc_flags: Flags used to allocate the interrupt. One or multiple (ORred) ESP_INTR_FLAG_* values. See esp_intr_alloc.h for more info.
            handle: If non-zero, a handle to later clean up the ISR gets stored here.
返回:ESP_OK Success
            ESP_ERR_INVALID_ARG Function pointer error.
            ESP_FAIL System driver installed, can not register ISR handler for RMT
說明:Register RMT interrupt handler, the handler is an ISR.
The handler will be attached to the same CPU core that this function is running on.
If you already called rmt_driver_install to use system RMT driver, please do not register ISR handler again.
範例:

功能 - rmt_isr_deregister
原型:esp_err_t rmt_isr_deregister(rmt_isr_handle_t handle)
參數:handle: Handle obtained from rmt_isr_register
返回:ESP_OK Success
            ESP_ERR_INVALID_ARG Handle invalid
說明:Deregister previously registered RMT interrupt handler.
範例:

功能 - rmt_fill_tx_items
原型:esp_err_t rmt_fill_tx_items(rmt_channel_t channel, const rmt_item32_t *item, uint16_t item_num, uint16_t mem_offset)
參數:channel: RMT channel (0 - 7)
            item: Pointer of items.
            item_num: RMT sending items number.
            mem_offset: Index offset of memory.
返回:ESP_ERR_INVALID_ARG Parameter error
            ESP_OK Success
說明:Fill memory data of channel with given RMT items.
範例:

功能 - rmt_driver_install
原型:esp_err_t rmt_driver_install(rmt_channel_t channel, size_t rx_buf_size, int intr_alloc_flags)
參數:channel: RMT channel (0 - 7)
            rx_buf_size: Size of RMT RX ringbuffer. Can be 0 if the RX ringbuffer is not used.
            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.
返回:ESP_ERR_INVALID_STATE Driver is already installed, call rmt_driver_uninstall first.
            ESP_ERR_NO_MEM Memory allocation failure
            ESP_ERR_INVALID_ARG Parameter error
            ESP_OK Success
說明:Initialize RMT driver.
範例:

功能 - rmt_driver_uninstall
原型:esp_err_t rmt_driver_uninstall(rmt_channel_t channel)
參數:channel: RMT channel (0 - 7)
返回:ESP_ERR_INVALID_ARG Parameter error
            ESP_OK Success
說明:Uninstall RMT driver.
範例:

功能 - rmt_write_items
原型:esp_err_t rmt_write_items(rmt_channel_t channel, const rmt_item32_t *rmt_item, int item_num, bool wait_tx_done)
參數:channel: RMT channel (0 - 7)
            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.
            item_num: RMT data item number.
            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.
返回:ESP_ERR_INVALID_ARG Parameter error
            ESP_OK Success
說明:RMT send waveform from rmt_item array. This API allows user to send waveform with any length.
This function will not copy data, instead, it will point to the original items, and send the waveform items. If wait_tx_done is set to true, this function will block and will not return until all items have been sent out. If wait_tx_done is set to false, this function will return immediately, and the driver interrupt will continue sending the items. We must make sure the item data will not be damaged when the driver is still sending items in driver interrupt.
範例:

功能 - rmt_wait_tx_done
原型:esp_err_t rmt_wait_tx_done(rmt_channel_t channel, TickType_t wait_time)
參數:channel: RMT channel (0 - 7)
            wait_time: Maximum time in ticks to wait for transmission to be complete
返回:ESP_OK RMT Tx done successfully
        ESP_ERR_TIMEOUT Exceeded the ‘wait_time’ given
        ESP_ERR_INVALID_ARG Parameter error
        ESP_FAIL Driver not installed
說明:Wait RMT TX finished.
範例:

功能 - rmt_get_ringbuf_handle
原型:esp_err_t rmt_get_ringbuf_handle(rmt_channel_t channel, RingbufHandle_t *buf_handle)
參數:channel: RMT channel (0 - 7)
            buf_handle: Pointer to buffer handle to accept RX ringbuffer handle.
返回:ESP_ERR_INVALID_ARG Parameter error
            ESP_OK Success
說明:Get ringbuffer from RMT.
Users can get the RMT RX ringbuffer handle, and process the RX data.
範例:

功能 - rmt_translator_init
原型:esp_err_t rmt_translator_init(rmt_channel_t channel, sample_to_rmt_t fn)
參數:channel: RMT channel (0 - 7).
            fn: Point to the data conversion function.
返回:ESP_FAIL Init fail.
            ESP_OK Init success.
說明:Init rmt translator and register user callback. The callback will convert the raw data that needs to be sent to rmt format. If a channel is initialized more than once, tha user callback will be replaced by the later.
範例:

功能 - rmt_write_sample
原型:esp_err_t rmt_write_sample(rmt_channel_t channel, const uint8_t *src, size_t src_size, bool wait_tx_done)
參數:channel: RMT channel (0 - 7).
            src: Pointer to the raw data.
            src_size: The size of the raw data.
            wait_tx_done: Set true to wait all data send done.
返回:ESP_FAIL Send fail
            ESP_OK Send success
說明:Translate uint8_t type of data into rmt format and send it out. Requires rmt_translator_init to init the translator first.
範例:

功能 - rmt_register_tx_end_callback
原型:rmt_tx_end_callback_t rmt_register_tx_end_callback(rmt_tx_end_fn_t function, void *arg)
參數:function: Function to be called from the default interrupt handler or NULL.
            arg: Argument which will be provided to the callback when it is called.
返回:the previous callback settings (members will be set to NULL if there was none)
說明:Registers a callback that will be called when transmission ends.
Called by rmt_driver_isr_default in interrupt context.
NoteRequires rmt_driver_install to install the default ISR handler.
範例: 


相關網址:
※ DIY - ESP32:ESP32 紅外線接收器發射器電路(三十三)
※ DIY - ESP32:ESP32 紅外線接收器發射器程式(三十四)
※ DIY - ESP32:ESP32 RMT API 函數介紹(三十五)
※ DIY - ESP32:ESP32 RMT API 函數結構件及其它(三十七)

2018年 11月 23日 天氣報告
氣溫:20.9@ 20:10
相對濕度:百分之 74%
天氣:天色大致良好

沒有留言:

張貼留言