Unverified Commit 7cf16234 authored by Rodrigo Garcia's avatar Rodrigo Garcia Committed by GitHub

RMT refactoring based on IDF (#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 #5905
parent c66c7fe2
This diff is collapsed.
...@@ -25,6 +25,9 @@ extern "C" { ...@@ -25,6 +25,9 @@ extern "C" {
#define RMT_FLAG_ERROR (4) #define RMT_FLAG_ERROR (4)
#define RMT_FLAGS_ALL (RMT_FLAG_TX_DONE | RMT_FLAG_RX_DONE | RMT_FLAG_ERROR) #define RMT_FLAGS_ALL (RMT_FLAG_TX_DONE | RMT_FLAG_RX_DONE | RMT_FLAG_ERROR)
#define RMT_TX_MODE true
#define RMT_RX_MODE false
struct rmt_obj_s; struct rmt_obj_s;
typedef enum { typedef enum {
...@@ -54,6 +57,13 @@ typedef struct { ...@@ -54,6 +57,13 @@ typedef struct {
}; };
} rmt_data_t; } rmt_data_t;
/**
* Prints object information
*
*/
void _rmtDumpStatus(rmt_obj_t* rmt);
/** /**
* Initialize the object * Initialize the object
* *
...@@ -69,10 +79,17 @@ float rmtSetTick(rmt_obj_t* rmt, float tick); ...@@ -69,10 +79,17 @@ float rmtSetTick(rmt_obj_t* rmt, float tick);
/** /**
* Sending data in one-go mode or continual mode * Sending data in one-go mode or continual mode
* (more data being send while updating buffers in interrupts) * (more data being send while updating buffers in interrupts)
* * Non-Blocking mode - returns right after executing
*/ */
bool rmtWrite(rmt_obj_t* rmt, rmt_data_t* data, size_t size); bool rmtWrite(rmt_obj_t* rmt, rmt_data_t* data, size_t size);
/**
* Sending data in one-go mode or continual mode
* (more data being send while updating buffers in interrupts)
* Blocking mode - only returns when data has been sent
*/
bool rmtWriteBlocking(rmt_obj_t* rmt, rmt_data_t* data, size_t size);
/** /**
* Loop data up to the reserved memsize continuously * Loop data up to the reserved memsize continuously
* *
......
...@@ -12,7 +12,7 @@ class MyProcessor { ...@@ -12,7 +12,7 @@ class MyProcessor {
public: public:
MyProcessor(uint8_t pin, float nanoTicks) { MyProcessor(uint8_t pin, float nanoTicks) {
assert((rmt_recv = rmtInit(21, false, RMT_MEM_192))); assert((rmt_recv = rmtInit(21, RMT_RX_MODE, RMT_MEM_192)));
realNanoTick = rmtSetTick(rmt_recv, nanoTicks); realNanoTick = rmtSetTick(rmt_recv, nanoTicks);
}; };
......
...@@ -5,6 +5,17 @@ ...@@ -5,6 +5,17 @@
#include "esp32-hal.h" #include "esp32-hal.h"
#if CONFIG_IDF_TARGET_ESP32C3
// ESP32 C3 has only 2 channels for RX and 2 for TX, thus MAX RMT_MEM is 128
#define RMT_TX_PIN 4
#define RMT_RX_PIN 5
#define RMT_MEM_RX RMT_MEM_128
#else
#define RMT_TX_PIN 18
#define RMT_RX_PIN 21
#define RMT_MEM_RX RMT_MEM_192
#endif
rmt_data_t my_data[256]; rmt_data_t my_data[256];
rmt_data_t data[256]; rmt_data_t data[256];
...@@ -18,18 +29,19 @@ void setup() ...@@ -18,18 +29,19 @@ void setup()
Serial.begin(115200); Serial.begin(115200);
events = xEventGroupCreate(); events = xEventGroupCreate();
if ((rmt_send = rmtInit(18, true, RMT_MEM_64)) == NULL) if ((rmt_send = rmtInit(RMT_TX_PIN, RMT_TX_MODE, RMT_MEM_64)) == NULL)
{ {
Serial.println("init sender failed\n"); Serial.println("init sender failed\n");
} }
if ((rmt_recv = rmtInit(21, false, RMT_MEM_192)) == NULL) if ((rmt_recv = rmtInit(RMT_RX_PIN, RMT_RX_MODE, RMT_MEM_RX)) == NULL)
{ {
Serial.println("init receiver failed\n"); Serial.println("init receiver failed\n");
} }
float realTick = rmtSetTick(rmt_send, 100); float realTick = rmtSetTick(rmt_send, 100);
printf("real tick set to: %fns\n", realTick); printf("real tick set to: %fns\n", realTick);
// both will keep same tick
realTick = rmtSetTick(rmt_recv, 100);
} }
void loop() void loop()
......
...@@ -182,7 +182,7 @@ void setup() ...@@ -182,7 +182,7 @@ void setup()
Serial.begin(115200); Serial.begin(115200);
// Initialize the channel to capture up to 192 items // Initialize the channel to capture up to 192 items
if ((rmt_recv = rmtInit(21, false, RMT_MEM_192)) == NULL) if ((rmt_recv = rmtInit(21, RMT_RX_MODE, RMT_MEM_192)) == NULL)
{ {
Serial.println("init receiver failed\n"); Serial.println("init receiver failed\n");
} }
......
...@@ -41,7 +41,7 @@ void setup() ...@@ -41,7 +41,7 @@ void setup()
{ {
Serial.begin(115200); Serial.begin(115200);
if ((rmt_send = rmtInit(18, true, RMT_MEM_64)) == NULL) if ((rmt_send = rmtInit(18, RMT_TX_MODE, RMT_MEM_64)) == NULL)
{ {
Serial.println("init sender failed\n"); Serial.println("init sender failed\n");
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment