From 46d7ade046bcfb6c5d8717307f64530a03f01d44 Mon Sep 17 00:00:00 2001 From: Gregg Date: Sun, 16 Jan 2022 14:16:52 -0600 Subject: [PATCH] Re-doing Pixel class once again This time using customized interrupts to fill RMT memory on-the-fly. * Added getChannel() to RFControl * Add 3rd, optional, boolean argument to RFControl(int pin, bool refTick, bool defaultDrive) to that RMT can be initialized but without the default driver (allows for use of custom interrupt code instead) --- src/extras/RFControl.cpp | 6 ++- src/extras/RFControl.h | 5 ++- src/extras/extras.ino | 79 +++++++++++++++++++++++++++++++--------- 3 files changed, 69 insertions(+), 21 deletions(-) diff --git a/src/extras/RFControl.cpp b/src/extras/RFControl.cpp index b87bb0b..7d1a78f 100644 --- a/src/extras/RFControl.cpp +++ b/src/extras/RFControl.cpp @@ -3,7 +3,7 @@ /////////////////// -RFControl::RFControl(uint8_t pin, boolean refClock){ +RFControl::RFControl(uint8_t pin, boolean refClock, boolean installDriver){ #ifdef CONFIG_IDF_TARGET_ESP32C3 if(nChannels==RMT_CHANNEL_MAX/2){ @@ -29,7 +29,9 @@ RFControl::RFControl(uint8_t pin, boolean refClock){ config->tx_config.loop_en=false; rmt_config(config); - rmt_driver_install(config->channel,0,0); + + if(installDriver) + rmt_driver_install(config->channel,0,0); // If specified, set the base clock to 1 MHz so tick-units are in microseconds (before any CLK_DIV is applied), otherwise default will be 80 MHz APB clock diff --git a/src/extras/RFControl.h b/src/extras/RFControl.h index e07851d..91c86d4 100644 --- a/src/extras/RFControl.h +++ b/src/extras/RFControl.h @@ -21,7 +21,7 @@ class RFControl { static uint8_t nChannels; public: - RFControl(uint8_t pin, boolean refClock=true); // creates transmitter on pin, using 1-MHz Ref Tick clock + RFControl(uint8_t pin, boolean refClock=true, boolean installDriver=true); // creates transmitter on pin, using 1-MHz Ref Tick clock void start(uint32_t *data, int nData, uint8_t nCycles=1, uint8_t tickTime=1); // starts transmission of pulses from specified data pointer, repeated for numCycles, where each tick in pulse is tickTime microseconds long void start(uint8_t nCycles=1, uint8_t tickTime=1); // starts transmission of pulses from internal data structure, repeated for numCycles, where each tick in pulse is tickTime microseconds long @@ -32,7 +32,8 @@ class RFControl { void enableCarrier(uint32_t freq, float duty=0.5); // enables carrier wave if freq>0, else disables carrier wave; duty is a fraction from 0-1 void disableCarrier(){enableCarrier(0);} // disables carrier wave - int getPin(){return(config?config->gpio_num:-1);} // returns the pin number + int getPin(){return(config?config->gpio_num:-1);} // returns the pin number + rmt_channel_t getChannel(){return(config?config->channel:RMT_CHANNEL_0);} // returns channel, or channel_0 is no channel defined operator bool(){ // override boolean operator to return true/false if creation succeeded/failed return(config); diff --git a/src/extras/extras.ino b/src/extras/extras.ino index 5343ba5..226fad2 100644 --- a/src/extras/extras.ino +++ b/src/extras/extras.ino @@ -73,9 +73,19 @@ struct Effect2 { } }; -Pixel px(21,8); -Effect1 effect1(&px,5); -Effect2 effect2(&px,100); +//Pixel px(21,8); +//Effect1 effect1(&px,5); +//Effect2 effect2(&px,100); + +#ifdef CONFIG_IDF_TARGET_ESP32C3 + #define PIN 7 + #define RMT_MEM_SIZE 48 +#else + #define PIN 13 + #define RMT_MEM_SIZE 64 +#endif + +volatile uint32_t data[10]; void setup() { @@ -84,25 +94,60 @@ void setup() { delay(1000); // wait for interface to flush Serial.println("\n\nHomeSpan Pixel Example\n"); - Serial.printf("PX on Pin=%d check: %s\n",px.getPin(),px?"OKAY":"BAD"); - px.setRGB(0,0,0,8); - for(int i=1;i<5;i++){ - px.setHSV(0,100,20,i); - delay(500); - } + RFControl rf(PIN,true,false); + rmt_set_clk_div(rf.getChannel(),100); // set clock divider + + rmt_isr_register(eot,(void *)data,0,NULL); + rmt_set_tx_intr_en(rf.getChannel(),true); + rmt_set_tx_thr_intr_en(rf.getChannel(),true,32); + + RMTMEM.chan[0].data32[0].val=5000<<16 | 5000 | 1<<15; + RMTMEM.chan[0].data32[1].val=5000<<16 | 5000 | 1<<15; + + for(int i=2;i