Skip to content

Commit

Permalink
Add support for using multiple memory slots in rmt setup (#3568)
Browse files Browse the repository at this point in the history
* Add support for using multiple memory slots in rmt setup

* Fix a crash when stopping an RMT receiver

* Add missing docs to the mkdocs
  • Loading branch information
pjsg authored Feb 2, 2024
1 parent 3cc1d48 commit 4816c16
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
19 changes: 17 additions & 2 deletions components/modules/rmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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");
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions docs/modules/rmt.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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'
Expand Down

0 comments on commit 4816c16

Please sign in to comment.