From 4816c168d8f39de01c3c24f81664af41c58c53a9 Mon Sep 17 00:00:00 2001 From: Philip Gladstone Date: Thu, 1 Feb 2024 20:31:56 -0500 Subject: [PATCH] Add support for using multiple memory slots in rmt setup (#3568) * Add support for using multiple memory slots in rmt setup * Fix a crash when stopping an RMT receiver * Add missing docs to the mkdocs --- components/modules/rmt.c | 19 +++++++++++++++++-- docs/modules/rmt.md | 2 ++ mkdocs.yml | 2 ++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/components/modules/rmt.c b/components/modules/rmt.c index 305777000..224fa2616 100644 --- a/components/modules/rmt.c +++ b/components/modules/rmt.c @@ -49,7 +49,7 @@ static int configure_channel(lua_State *L, rmt_config_t *config, rmt_mode_t mode lua_setmetatable(L, -2); // We have allocated the channel -- must free it if the rest of this method fails - int channel = platform_rmt_allocate(1, mode); + int channel = platform_rmt_allocate(config->mem_block_num, mode); if (channel < 0) { return luaL_error(L, "no spare RMT channel"); @@ -66,7 +66,7 @@ static int configure_channel(lua_State *L, rmt_config_t *config, rmt_mode_t mode return luaL_error(L, "Failed to configure RMT"); } - rc = rmt_driver_install(config->channel, 1000, 0); + rc = rmt_driver_install(config->channel, config->mem_block_num * 600, 0); if (rc) { platform_rmt_release(config->channel); return luaL_error(L, "Failed to install RMT driver"); @@ -112,6 +112,13 @@ static int lrmt_txsetup(lua_State *L) { config.flags |= RMT_CHANNEL_FLAGS_INVERT_SIG; } lua_pop(L, 1); + + lua_getfield(L, 3, "slots"); + int slots = lua_tointeger(L, -1); + if (slots > 0 && slots <= 8) { + config.mem_block_num = slots; + } + lua_pop(L, 1); } configure_channel(L, &config, RMT_MODE_TX); @@ -155,6 +162,13 @@ static int lrmt_rxsetup(lua_State *L) { config.rx_config.idle_threshold = threshold; } lua_pop(L, 1); + + lua_getfield(L, 3, "slots"); + int slots = lua_tointeger(L, -1); + if (slots > 0 && slots <= 8) { + config.mem_block_num = slots; + } + lua_pop(L, 1); } configure_channel(L, &config, RMT_MODE_RX); @@ -202,6 +216,7 @@ static void handle_receive(void *param) { vRingbufferReturnItem(rb, (void *) items); } } + rmt_rx_stop(p->channel); p->dont_call = true; task_post_high(cb_task_id, (task_param_t) p); diff --git a/docs/modules/rmt.md b/docs/modules/rmt.md index d3ab062df..0d9584404 100644 --- a/docs/modules/rmt.md +++ b/docs/modules/rmt.md @@ -40,6 +40,7 @@ This optional table consists of a number of keys that control various aspects of - `carrier_hz` specifies that the signal is to modulate the carrier at the specified frequency. This is useful for IR transmissions. - `carrier_duty` specifies the duty cycle of the carrier. Defaults to 50% - `idle_level` specifies what value to send when the transmission completes. +- `slots` If specified, then the number of memory slots used for transmission. 1 slot = 64 pulses (i.e. high and low widths). Total slots in the system are 8 (on the ESP32). Slots cannot be shared. ## rmt.rxsetup(gpio, bitrate, options) @@ -71,6 +72,7 @@ This optional table consists of a number of keys that control various aspects of - `invert` if true, then the input is inverted. - `filter_ticks` If specified, then any pulse shorter than this will be ignored. This is in units of the bit time. - `idle_threshold` If specified, then any level longer than this will set the receiver as idle. The default is 65535 bit times. +- `slots` If specified, then the number of memory slots used for reception. 1 slot = 64 pulses (i.e. high and low widths). Total slots in the system are 8 (on the ESP32). Slots cannot be shared. ## channel:on(event, callback) diff --git a/mkdocs.yml b/mkdocs.yml index eec8f0c0f..ce5dfd874 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -47,6 +47,7 @@ pages: - 'dac': 'modules/dac.md' - 'dht': 'modules/dht.md' - 'encoder': 'modules/encoder.md' + - 'eromfs': 'modules/eromfs.md' - 'eth': 'modules/eth.md' - 'file': 'modules/file.md' - 'gpio': 'modules/gpio.md' @@ -64,6 +65,7 @@ pages: - 'pipe': 'modules/pipe.md' - 'pulsecnt': 'modules/pulsecnt.md' - 'qrcodegen': 'modules/qrcodegen.md' + - 'rmt': 'modules/rmt.md' - 'sdmmc': 'modules/sdmmc.md' - 'sigma delta': 'modules/sigma-delta.md' - 'sjson': 'modules/sjson.md'