mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-09 20:41:14 +00:00
rmt: add workaround to get user context in a graceful way
This commit is contained in:
@@ -171,22 +171,6 @@ typedef struct {
|
||||
*/
|
||||
typedef void (*sample_to_rmt_t)(const void *src, rmt_item32_t *dest, size_t src_size, size_t wanted_num, size_t *translated_size, size_t *item_num);
|
||||
|
||||
/**
|
||||
* @brief IDF 4.x Workaround callback function for sample_to_rmt_t that lets user pass in context for rmt_write_sample
|
||||
*
|
||||
* @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.
|
||||
* @param context User context pointer
|
||||
*/
|
||||
typedef void (*sample_with_context_to_rmt_t)(const void *src, rmt_item32_t *dest, size_t src_size, size_t wanted_num, size_t *translated_size, size_t *item_num, void *context);
|
||||
|
||||
/**
|
||||
* @brief Set RMT clock divider, channel clock is divided from source clock.
|
||||
*
|
||||
@@ -779,27 +763,31 @@ esp_err_t rmt_get_ringbuf_handle(rmt_channel_t channel, RingbufHandle_t *buf_han
|
||||
esp_err_t rmt_translator_init(rmt_channel_t channel, sample_to_rmt_t fn);
|
||||
|
||||
/**
|
||||
* @brief Workaround for IDF 4.x
|
||||
* TODO: Add context to sample_to_rmt_t callback signature and allow user to pass in context
|
||||
* on rmt_translator_init
|
||||
* @brief Set user context for the translator of specific channel
|
||||
*
|
||||
* @param channel RMT channel .
|
||||
* @param fn Point to the data conversion function.
|
||||
* @param channel RMT channel number
|
||||
* @param context User context
|
||||
*
|
||||
* @return
|
||||
* - ESP_FAIL Init fail.
|
||||
* - ESP_OK Init success.
|
||||
*/
|
||||
esp_err_t rmt_translator_init_with_context(rmt_channel_t channel, sample_with_context_to_rmt_t fn, void* context);
|
||||
|
||||
/**
|
||||
* @brief Sets the user context for the translator
|
||||
* Requires rmt_translator_init_with_context to init the translator first
|
||||
* @return
|
||||
* - ESP_FAIL Set context fail
|
||||
* - ESP_OK Set context success
|
||||
*/
|
||||
esp_err_t rmt_set_translator_context(rmt_channel_t channel, void* context);
|
||||
esp_err_t rmt_translator_set_context(rmt_channel_t channel, void *context);
|
||||
|
||||
/**
|
||||
* @brief Get the user context set by 'rmt_translator_set_context'
|
||||
*
|
||||
* @note This API must be invoked in the RMT translator callback function,
|
||||
* and the first argument must be the actual parameter 'item_num' you got in that callback function.
|
||||
*
|
||||
* @param item_num Address of the memory which contains the number of translated items (It's from driver's internal memroy)
|
||||
* @param context Returned User context
|
||||
*
|
||||
* @return
|
||||
* - ESP_FAIL Get context fail
|
||||
* - ESP_OK Get context success
|
||||
*/
|
||||
esp_err_t rmt_translator_get_context(const size_t *item_num, void **context);
|
||||
|
||||
/**
|
||||
* @brief Translate uint8_t type of data into rmt format and send it out.
|
||||
|
Reference in New Issue
Block a user