Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 7cf1623

Browse files
authoredDec 21, 2021
RMT refactoring based on IDF (espressif#6024)
Summary RMT HAL refactoring based on IDF. Impact Improves RMT by adding IDF v4.4 support. Receiving RMT can handle any size of data. rmtInit() has a new parameter - RxBufferSize - to hold any number of data when receiving RMT. rmtWrite() has a new parameter - wait_tx_done - to block writing until sending all data. Related links fix espressif#5905
1 parent c66c7fe commit 7cf1623

File tree

6 files changed

+343
-762
lines changed

6 files changed

+343
-762
lines changed
 

‎cores/esp32/esp32-hal-rmt.c

Lines changed: 306 additions & 754 deletions
Large diffs are not rendered by default.

‎cores/esp32/esp32-hal-rmt.h

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ extern "C" {
2525
#define RMT_FLAG_ERROR (4)
2626
#define RMT_FLAGS_ALL (RMT_FLAG_TX_DONE | RMT_FLAG_RX_DONE | RMT_FLAG_ERROR)
2727

28+
#define RMT_TX_MODE true
29+
#define RMT_RX_MODE false
30+
2831
struct rmt_obj_s;
2932

3033
typedef enum {
@@ -54,6 +57,13 @@ typedef struct {
5457
};
5558
} rmt_data_t;
5659

60+
61+
/**
62+
* Prints object information
63+
*
64+
*/
65+
void _rmtDumpStatus(rmt_obj_t* rmt);
66+
5767
/**
5868
* Initialize the object
5969
*
@@ -69,10 +79,17 @@ float rmtSetTick(rmt_obj_t* rmt, float tick);
6979
/**
7080
* Sending data in one-go mode or continual mode
7181
* (more data being send while updating buffers in interrupts)
72-
*
82+
* Non-Blocking mode - returns right after executing
7383
*/
7484
bool rmtWrite(rmt_obj_t* rmt, rmt_data_t* data, size_t size);
7585

86+
/**
87+
* Sending data in one-go mode or continual mode
88+
* (more data being send while updating buffers in interrupts)
89+
* Blocking mode - only returns when data has been sent
90+
*/
91+
bool rmtWriteBlocking(rmt_obj_t* rmt, rmt_data_t* data, size_t size);
92+
7693
/**
7794
* Loop data up to the reserved memsize continuously
7895
*

‎libraries/ESP32/examples/RMT/RMTCallback/RMTCallback.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class MyProcessor {
1212

1313
public:
1414
MyProcessor(uint8_t pin, float nanoTicks) {
15-
assert((rmt_recv = rmtInit(21, false, RMT_MEM_192)));
15+
assert((rmt_recv = rmtInit(21, RMT_RX_MODE, RMT_MEM_192)));
1616

1717
realNanoTick = rmtSetTick(rmt_recv, nanoTicks);
1818
};
@@ -61,4 +61,4 @@ void loop()
6161
{
6262
Serial.printf("GPIO 4: %08x 5: %08x 6: %08x\n", mp1.val(), mp2.val(), mp3.val());
6363
delay(500);
64-
}
64+
}

‎libraries/ESP32/examples/RMT/RMTLoopback/RMTLoopback.ino

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,17 @@
55

66
#include "esp32-hal.h"
77

8+
#if CONFIG_IDF_TARGET_ESP32C3
9+
// ESP32 C3 has only 2 channels for RX and 2 for TX, thus MAX RMT_MEM is 128
10+
#define RMT_TX_PIN 4
11+
#define RMT_RX_PIN 5
12+
#define RMT_MEM_RX RMT_MEM_128
13+
#else
14+
#define RMT_TX_PIN 18
15+
#define RMT_RX_PIN 21
16+
#define RMT_MEM_RX RMT_MEM_192
17+
#endif
18+
819
rmt_data_t my_data[256];
920
rmt_data_t data[256];
1021

@@ -18,18 +29,19 @@ void setup()
1829
Serial.begin(115200);
1930
events = xEventGroupCreate();
2031

21-
if ((rmt_send = rmtInit(18, true, RMT_MEM_64)) == NULL)
32+
if ((rmt_send = rmtInit(RMT_TX_PIN, RMT_TX_MODE, RMT_MEM_64)) == NULL)
2233
{
2334
Serial.println("init sender failed\n");
2435
}
25-
if ((rmt_recv = rmtInit(21, false, RMT_MEM_192)) == NULL)
36+
if ((rmt_recv = rmtInit(RMT_RX_PIN, RMT_RX_MODE, RMT_MEM_RX)) == NULL)
2637
{
2738
Serial.println("init receiver failed\n");
2839
}
2940

3041
float realTick = rmtSetTick(rmt_send, 100);
3142
printf("real tick set to: %fns\n", realTick);
32-
43+
// both will keep same tick
44+
realTick = rmtSetTick(rmt_recv, 100);
3345
}
3446

3547
void loop()

‎libraries/ESP32/examples/RMT/RMTReadXJT/RMTReadXJT.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ void setup()
182182
Serial.begin(115200);
183183

184184
// Initialize the channel to capture up to 192 items
185-
if ((rmt_recv = rmtInit(21, false, RMT_MEM_192)) == NULL)
185+
if ((rmt_recv = rmtInit(21, RMT_RX_MODE, RMT_MEM_192)) == NULL)
186186
{
187187
Serial.println("init receiver failed\n");
188188
}

‎libraries/ESP32/examples/RMT/RMTWriteNeoPixel/RMTWriteNeoPixel.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ void setup()
4141
{
4242
Serial.begin(115200);
4343

44-
if ((rmt_send = rmtInit(18, true, RMT_MEM_64)) == NULL)
44+
if ((rmt_send = rmtInit(18, RMT_TX_MODE, RMT_MEM_64)) == NULL)
4545
{
4646
Serial.println("init sender failed\n");
4747
}

0 commit comments

Comments
 (0)
Please sign in to comment.