1
+ #include "freertos/FreeRTOS.h"
2
+ #include "freertos/event_groups.h"
3
+
1
4
#include "esp32-hal.h"
2
5
#include "esp8266-compat.h"
3
6
#include "soc/gpio_reg.h"
@@ -44,7 +47,7 @@ typedef enum {
44
47
struct rmt_obj_s
45
48
{
46
49
bool allocated ;
47
- intr_handle_t intr_handle ;
50
+ EventGroupHandle_t events ;
48
51
int pin ;
49
52
int channel ;
50
53
bool tx_not_rx ;
@@ -61,8 +64,6 @@ static rmt_obj_t g_rmt_objects[MAX_CHANNELS] = {
61
64
};
62
65
63
66
static intr_handle_t intr_handle ;
64
- static int state = 0 ;
65
-
66
67
67
68
static bool periph_enabled = false;
68
69
@@ -181,6 +182,11 @@ bool rmtReceive(rmt_obj_t* rmt, size_t idle_thres)
181
182
}
182
183
int channel = rmt -> channel ;
183
184
185
+ RMT .int_clr .val |= _INT_ERROR (channel );
186
+
187
+ RMT .int_ena .val |= _INT_ERROR (channel );
188
+
189
+ RMT .conf_ch [channel ].conf1 .mem_owner = 1 ;
184
190
RMT .conf_ch [channel ].conf0 .idle_thres = idle_thres ;
185
191
186
192
RMT .conf_ch [channel ].conf1 .mem_wr_rst = 1 ;
@@ -190,6 +196,45 @@ bool rmtReceive(rmt_obj_t* rmt, size_t idle_thres)
190
196
return true;
191
197
}
192
198
199
+ bool rmtReceiveAsync (rmt_obj_t * rmt , size_t idle_thres , uint32_t * data , size_t size , void * eventFlag )
200
+ {
201
+ if (!rmt ) {
202
+ return false;
203
+ }
204
+ int channel = rmt -> channel ;
205
+
206
+ if (g_rmt_objects [channel ].buffers < size /MAX_DATA_PER_CHANNEL ) {
207
+ return false;
208
+ }
209
+
210
+ if (eventFlag ) {
211
+ xEventGroupClearBits (eventFlag , RMT_FLAGS_ALL );
212
+ rmt -> events = eventFlag ;
213
+ }
214
+
215
+ if (data && size > 0 ) {
216
+ rmt -> remaining_ptr = data ;
217
+ rmt -> remaining_to_send = size ;
218
+ }
219
+
220
+ rmt -> intr_mode = e_rx_intr ;
221
+
222
+ RMT .conf_ch [channel ].conf1 .mem_owner = 1 ;
223
+ RMT .conf_ch [channel ].conf0 .idle_thres = idle_thres ;
224
+
225
+ RMT .int_clr .val |= _INT_RX_END (channel );
226
+ RMT .int_clr .val |= _INT_ERROR (channel );
227
+
228
+ RMT .int_ena .val |= _INT_RX_END (channel );
229
+ RMT .int_ena .val |= _INT_ERROR (channel );
230
+
231
+ RMT .conf_ch [channel ].conf1 .mem_wr_rst = 1 ;
232
+
233
+ RMT .conf_ch [channel ].conf1 .rx_en = 1 ;
234
+
235
+ return true;
236
+ }
237
+
193
238
194
239
bool rmtSend (rmt_obj_t * rmt , uint32_t * data , size_t size )
195
240
{
@@ -354,10 +399,20 @@ static void IRAM_ATTR _rmt_isr(void* arg)
354
399
if (intr_val & _INT_RX_END (ch )) {
355
400
// clear the flag
356
401
RMT .int_clr .val |= _INT_RX_END (ch );
357
-
358
402
//
359
403
if ((g_rmt_objects [ch ].intr_mode )& e_rx_intr ) {
360
- // Not yet implemented
404
+
405
+ if (g_rmt_objects [ch ].events ) {
406
+ xEventGroupSetBits (g_rmt_objects [ch ].events , RMT_FLAG_RX_DONE );
407
+ }
408
+ if (g_rmt_objects [ch ].remaining_ptr && g_rmt_objects [ch ].remaining_to_send > 0 ) {
409
+ size_t i ;
410
+ for (i = 0 ; i < g_rmt_objects [ch ].remaining_to_send ; i ++ ) {
411
+ * (g_rmt_objects [ch ].remaining_ptr )++ = RMTMEM .chan [ch ].data32 [i ].val ;
412
+ }
413
+ }
414
+ g_rmt_objects [ch ].intr_mode &= ~e_rx_intr ;
415
+
361
416
} else {
362
417
// Report error and disable Rx interrupt
363
418
ets_printf ("Unexpected Rx interrupt!\n" );
@@ -368,11 +423,18 @@ static void IRAM_ATTR _rmt_isr(void* arg)
368
423
if (intr_val & _INT_ERROR (ch )) {
369
424
// clear the flag
370
425
RMT .int_clr .val |= _INT_ERROR (ch );
426
+ RMT .int_ena .val &= ~_INT_ERROR (ch );
371
427
// report error
372
- ets_printf ("RMT Error!\n" );
428
+ ets_printf ("RMT Error %d!\n" , ch );
429
+ if (g_rmt_objects [ch ].events ) {
430
+ xEventGroupSetBits (g_rmt_objects [ch ].events , RMT_FLAG_ERROR );
431
+ }
373
432
433
+ // reset memory
374
434
RMT .conf_ch [ch ].conf1 .mem_rd_rst = 1 ;
375
435
RMT .conf_ch [ch ].conf1 .mem_rd_rst = 0 ;
436
+ RMT .conf_ch [ch ].conf1 .mem_wr_rst = 1 ;
437
+ RMT .conf_ch [ch ].conf1 .mem_wr_rst = 0 ;
376
438
}
377
439
378
440
if (intr_val & _INT_TX_END (ch )) {
0 commit comments