diff --git a/components/platform/dht.c b/components/platform/dht.c index e41ca5e4..aaf47f1b 100644 --- a/components/platform/dht.c +++ b/components/platform/dht.c @@ -25,6 +25,7 @@ * ****************************************************************************/ #include "platform.h" +#include "platform_rmt.h" #include "driver/rmt.h" #include "driver/gpio.h" @@ -91,7 +92,7 @@ static int dht_init( uint8_t gpio_num ) rmt_rx.rx_config.filter_ticks_thresh = 30; rmt_rx.rx_config.idle_threshold = DHT_DURATION_RX_IDLE; if (rmt_config( &rmt_rx ) == ESP_OK) { - if (rmt_driver_install( rmt_rx.channel, 512, ESP_INTR_FLAG_LOWMED | ESP_INTR_FLAG_IRAM | ESP_INTR_FLAG_SHARED ) == ESP_OK) { + if (rmt_driver_install( rmt_rx.channel, 512, PLATFORM_RMT_INTR_FLAGS ) == ESP_OK) { rmt_get_ringbuf_handle( dht_rmt.channel, &dht_rmt.rb ); diff --git a/components/platform/include/platform.h b/components/platform/include/platform.h index 35b13a84..c540c8db 100644 --- a/components/platform/include/platform.h +++ b/components/platform/include/platform.h @@ -179,30 +179,6 @@ int platform_i2c_send_byte( unsigned id, uint8_t data, int ack_check_en ); int platform_i2c_recv_byte( unsigned id, int ack_val ); -// ***************************************************************************** -// RMT platform interface - -/** - * @brief Allocate an RMT channel. - * - * @param num_mem Number of memory blocks. - * - * @return - * - Channel number when successful - * - -1 if no channel available - * - */ -int platform_rmt_allocate( uint8_t num_mem ); - -/** - * @brief Release a previously allocated RMT channel. - * - * @param channel Channel number. - * - */ -void platform_rmt_release( uint8_t channel ); - - // ***************************************************************************** // Onewire platform interface diff --git a/components/platform/include/platform_rmt.h b/components/platform/include/platform_rmt.h new file mode 100644 index 00000000..fbdbbc3d --- /dev/null +++ b/components/platform/include/platform_rmt.h @@ -0,0 +1,33 @@ +#ifndef _PLATFORM_RMT_H_ +#define _PLATFORM_RMT_H_ + +#include "driver/rmt.h" + + +// define a common set of esp interrupt allocation flags for common use +#define PLATFORM_RMT_INTR_FLAGS (ESP_INTR_FLAG_LOWMED | ESP_INTR_FLAG_SHARED) + +// ***************************************************************************** +// RMT platform interface + +/** + * @brief Allocate an RMT channel. + * + * @param num_mem Number of memory blocks. + * + * @return + * - Channel number when successful + * - -1 if no channel available + * + */ +int platform_rmt_allocate( uint8_t num_mem ); + +/** + * @brief Release a previously allocated RMT channel. + * + * @param channel Channel number. + * + */ +void platform_rmt_release( uint8_t channel ); + +#endif diff --git a/components/platform/onewire.c b/components/platform/onewire.c index e47eb58d..b37b1487 100644 --- a/components/platform/onewire.c +++ b/components/platform/onewire.c @@ -59,6 +59,7 @@ sample code bearing this copyright. */ #include "platform.h" +#include "platform_rmt.h" #include "driver/rmt.h" #include "driver/gpio.h" @@ -127,7 +128,7 @@ static int onewire_rmt_init( uint8_t gpio_num ) rmt_tx.tx_config.idle_output_en = true; rmt_tx.rmt_mode = RMT_MODE_TX; if (rmt_config( &rmt_tx ) == ESP_OK) { - if (rmt_driver_install( rmt_tx.channel, 0, ESP_INTR_FLAG_LOWMED | ESP_INTR_FLAG_IRAM | ESP_INTR_FLAG_SHARED ) == ESP_OK) { + if (rmt_driver_install( rmt_tx.channel, 0, PLATFORM_RMT_INTR_FLAGS ) == ESP_OK) { rmt_config_t rmt_rx; rmt_rx.channel = ow_rmt.rx; @@ -139,7 +140,7 @@ static int onewire_rmt_init( uint8_t gpio_num ) rmt_rx.rx_config.filter_ticks_thresh = 30; rmt_rx.rx_config.idle_threshold = OW_DURATION_RX_IDLE; if (rmt_config( &rmt_rx ) == ESP_OK) { - if (rmt_driver_install( rmt_rx.channel, 512, ESP_INTR_FLAG_LOWMED | ESP_INTR_FLAG_IRAM | ESP_INTR_FLAG_SHARED ) == ESP_OK) { + if (rmt_driver_install( rmt_rx.channel, 512, PLATFORM_RMT_INTR_FLAGS ) == ESP_OK) { rmt_get_ringbuf_handle( ow_rmt.rx, &ow_rmt.rb ); diff --git a/components/platform/rmt.c b/components/platform/platform_rmt.c similarity index 97% rename from components/platform/rmt.c rename to components/platform/platform_rmt.c index 759d5b51..972fc0e5 100644 --- a/components/platform/rmt.c +++ b/components/platform/platform_rmt.c @@ -1,6 +1,6 @@ -#include "platform.h" #include +#include "platform_rmt.h" #include "driver/rmt.h" diff --git a/components/platform/ws2812.c b/components/platform/ws2812.c index e48c6426..358b0e54 100644 --- a/components/platform/ws2812.c +++ b/components/platform/ws2812.c @@ -24,6 +24,7 @@ * ****************************************************************************/ #include "platform.h" +#include "platform_rmt.h" #include "driver/rmt.h" #include "driver/gpio.h" @@ -79,7 +80,7 @@ static ws2812_chain_t ws2812_chains[RMT_CHANNEL_MAX]; static intr_handle_t ws2812_intr_handle; -static void IRAM_ATTR ws2812_fill_memory_encoded( rmt_channel_t channel, const uint8_t *data, size_t len, size_t tx_offset ) +static void ws2812_fill_memory_encoded( rmt_channel_t channel, const uint8_t *data, size_t len, size_t tx_offset ) { for (size_t idx = 0; idx < len; idx++) { uint8_t byte = data[idx]; @@ -93,7 +94,7 @@ static void IRAM_ATTR ws2812_fill_memory_encoded( rmt_channel_t channel, const u } -static void IRAM_ATTR ws2812_isr(void *arg) +static void ws2812_isr(void *arg) { uint32_t intr_st = RMT.int_st.val; @@ -195,7 +196,7 @@ int platform_ws2812_send( void ) res = PLATFORM_ERR; break; } - if (rmt_driver_install( channel, 0, ESP_INTR_FLAG_LOWMED | ESP_INTR_FLAG_IRAM | ESP_INTR_FLAG_SHARED ) != ESP_OK) { + if (rmt_driver_install( channel, 0, PLATFORM_RMT_INTR_FLAGS ) != ESP_OK) { res = PLATFORM_ERR; break; } @@ -204,7 +205,7 @@ int platform_ws2812_send( void ) // hook-in our shared ISR - esp_intr_alloc( ETS_RMT_INTR_SOURCE, ESP_INTR_FLAG_LOWMED | ESP_INTR_FLAG_IRAM | ESP_INTR_FLAG_SHARED, ws2812_isr, NULL, &ws2812_intr_handle ); + esp_intr_alloc( ETS_RMT_INTR_SOURCE, PLATFORM_RMT_INTR_FLAGS, ws2812_isr, NULL, &ws2812_intr_handle ); // start selected channels one by one