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)
This commit is contained in:
Gregg 2022-01-16 14:16:52 -06:00
parent 1f9c8bfd48
commit 46d7ade046
3 changed files with 69 additions and 21 deletions

View File

@ -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

View File

@ -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);

View File

@ -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<RMT_MEM_SIZE;i++)
RMTMEM.chan[0].data32[i].val=200<<16 | 200 | 1<<15;
data[0]=5;
rmt_tx_start(rf.getChannel(),true);
while(1);
for(int i=5;i<8;i++){
px.setHSV(60,100,30,i);
delay(500);
}
px.setHSV(120,100,100,8);
delay(500);
// 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);
// }
//
// for(int i=5;i<8;i++){
// px.setHSV(60,100,30,i);
// delay(500);
// }
//
// px.setHSV(120,100,100,8);
// delay(500);
} // end of setup()
void loop(){
effect2.update();
// effect2.update();
}
void eot(void *arg){
Serial.printf("%08X\n",RMT.int_st.val);
RMT.int_clr.ch0_tx_end=1; // must clear interrupt immediately, else havoc will break out
RMT.int_clr.ch0_tx_thr_event=1; // must clear interrupt immediately, else havoc will break out
Serial.printf("%08X\n",RMT.int_st.val);
volatile uint32_t *x=(uint32_t *)arg;
Serial.printf("%d\n",x[0]);
if(--x[0]==0)
RMTMEM.chan[0].data32[0].val=0;
// x[1]--;
// if(x[1])
// REG_WRITE(RMT_CH0CONF1_REG,0x0000000D); // use REF_TICK clock; reset xmit and receive memory address to start of channel; START TRANSMITTING!
}