Revert "Update logic so Pixel uses only ONE channel and shares across all instances"
This reverts commit 4af3a22764.
This commit is contained in:
parent
4af3a22764
commit
95b41fd929
|
|
@ -4,14 +4,10 @@
|
||||||
///////////////////
|
///////////////////
|
||||||
|
|
||||||
Pixel::Pixel(int pin){
|
Pixel::Pixel(int pin){
|
||||||
|
|
||||||
if(!rf) // RMT Channel not yet assigned
|
|
||||||
rf=new RFControl(pin,false,false); // set clock to 1/80 usec, no default driver
|
|
||||||
|
|
||||||
if(!*rf) // if RMT Channel could NOT be assigned (no more channels)
|
rf=new RFControl(pin,false,false); // set clock to 1/80 usec, no default driver
|
||||||
|
if(!rf)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
this->pin=pin;
|
|
||||||
|
|
||||||
setTiming(0.32, 0.88, 0.64, 0.56, 80.0); // set default timing parameters (suitable for most SK68 and WS28 RGB pixels)
|
setTiming(0.32, 0.88, 0.64, 0.56, 80.0); // set default timing parameters (suitable for most SK68 and WS28 RGB pixels)
|
||||||
|
|
||||||
|
|
@ -71,8 +67,6 @@ void Pixel::setColors(const uint32_t *data, uint32_t nPixels, boolean multiColor
|
||||||
status.px=this;
|
status.px=this;
|
||||||
status.multiColor=multiColor;
|
status.multiColor=multiColor;
|
||||||
|
|
||||||
rmt_set_gpio(rf->getChannel(),RMT_MODE_TX,(gpio_num_t)(pin),false);
|
|
||||||
|
|
||||||
loadData(this); // load first two bytes of data to get started
|
loadData(this); // load first two bytes of data to get started
|
||||||
loadData(this);
|
loadData(this);
|
||||||
|
|
||||||
|
|
@ -128,4 +122,3 @@ void IRAM_ATTR Pixel::loadData(void *arg){
|
||||||
///////////////////
|
///////////////////
|
||||||
|
|
||||||
volatile Pixel::pixel_status_t Pixel::status;
|
volatile Pixel::pixel_status_t Pixel::status;
|
||||||
RFControl *Pixel::rf=NULL;
|
|
||||||
|
|
|
||||||
|
|
@ -21,12 +21,11 @@ class Pixel {
|
||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static RFControl *rf; // Pixel utilizes RFControl (shared across all Pixel instances)
|
RFControl *rf; // Pixel utilizes RFControl
|
||||||
uint32_t pattern[2]; // storage for zero-bit and one-bit pulses
|
uint32_t pattern[2]; // storage for zero-bit and one-bit pulses
|
||||||
uint32_t resetTime; // minimum time (in usec) between pulse trains
|
uint32_t resetTime; // minimum time (in usec) between pulse trains
|
||||||
uint32_t txEndMask; // mask for end-of-transmission interrupt
|
uint32_t txEndMask; // mask for end-of-transmission interrupt
|
||||||
uint32_t txThrMask; // mask for threshold interrupt
|
uint32_t txThrMask; // mask for threshold interrupt
|
||||||
int pin=-1; // pin number to which pixel is connected
|
|
||||||
|
|
||||||
const int memSize=sizeof(RMTMEM.chan[0].data32)/4; // determine size (in pulses) of one channel
|
const int memSize=sizeof(RMTMEM.chan[0].data32)/4; // determine size (in pulses) of one channel
|
||||||
|
|
||||||
|
|
@ -42,7 +41,7 @@ class Pixel {
|
||||||
void setHSV(float h, float s, float v, uint32_t nPixels=1); // sets color of nPixels to HSV values where h=[0,360], s=[0,100], v=[0,100]
|
void setHSV(float h, float s, float v, uint32_t nPixels=1); // sets color of nPixels to HSV values where h=[0,360], s=[0,100], v=[0,100]
|
||||||
void setColors(const uint32_t *data, uint32_t nPixels, bool multiColor=true); // sets colors of nPixels from array of colors stored in data
|
void setColors(const uint32_t *data, uint32_t nPixels, bool multiColor=true); // sets colors of nPixels from array of colors stored in data
|
||||||
|
|
||||||
int getPin(){return(pin);} // returns pixel pin (or -1 if initialization failed)
|
int getPin(){return(rf->getPin());} // returns pixel pin if valid, else returns -1
|
||||||
|
|
||||||
static uint32_t getColorRGB(uint8_t r, uint8_t g, uint8_t b); // return pixel Color from RGB values
|
static uint32_t getColorRGB(uint8_t r, uint8_t g, uint8_t b); // return pixel Color from RGB values
|
||||||
static uint32_t getColorHSV(float h, float s, float v); // return pixel Color from HSV values
|
static uint32_t getColorHSV(float h, float s, float v); // return pixel Color from HSV values
|
||||||
|
|
|
||||||
|
|
@ -33,18 +33,21 @@ RFControl::RFControl(uint8_t pin, boolean refClock, boolean installDriver){
|
||||||
if(installDriver)
|
if(installDriver)
|
||||||
rmt_driver_install(config->channel,0,0);
|
rmt_driver_install(config->channel,0,0);
|
||||||
|
|
||||||
this->refClock=refClock;
|
// 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
|
||||||
nChannels++;
|
|
||||||
|
|
||||||
|
this->refClock=refClock;
|
||||||
|
|
||||||
if(refClock)
|
if(refClock)
|
||||||
#if SOC_RMT_SUPPORT_REF_TICK
|
#ifdef CONFIG_IDF_TARGET_ESP32C3
|
||||||
rmt_set_source_clk(config->channel,RMT_BASECLK_REF); // use 1 MHz REF Tick Clock for ESP32 and ESP32-S2 instead of 80 MHz APB clock
|
REG_SET_FIELD(RMT_SYS_CONF_REG,RMT_SCLK_DIV_NUM,79); // ESP32-C3 does not have a 1 MHz REF Tick Clock, but allows the 80 MHz APB clock to be scaled by an additional RMT-specific divider
|
||||||
#elif SOC_RMT_SUPPORT_XTAL
|
#else
|
||||||
REG_SET_FIELD(RMT_SYS_CONF_REG,RMT_SCLK_DIV_NUM,79); // ESP32-C3 does not have a 1 MHz REF Tick Clock, but allows the 80 MHz APB clock to be scaled by an additional RMT-specific divider
|
rmt_set_source_clk(config->channel,RMT_BASECLK_REF); // use 1 MHz REF Tick Clock for ESP32 and ESP32-S2
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
nChannels++;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
///////////////////
|
///////////////////
|
||||||
|
|
||||||
void RFControl::start(uint8_t nCycles, uint8_t tickTime){ // starts transmission of pulses from internal data structure, repeated for nCycles, where each tick in pulse is tickTime microseconds long
|
void RFControl::start(uint8_t nCycles, uint8_t tickTime){ // starts transmission of pulses from internal data structure, repeated for nCycles, where each tick in pulse is tickTime microseconds long
|
||||||
|
|
@ -57,8 +60,8 @@ void RFControl::start(uint32_t *data, int nData, uint8_t nCycles, uint8_t tickTi
|
||||||
|
|
||||||
if(!config || nData==0)
|
if(!config || nData==0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
rmt_set_clk_div(config->channel,tickTime); // set clock divider
|
rmt_set_clk_div(config->channel,tickTime); // set clock divider
|
||||||
|
|
||||||
for(int i=0;i<nCycles;i++) // loop over nCycles
|
for(int i=0;i<nCycles;i++) // loop over nCycles
|
||||||
rmt_write_items(config->channel, (rmt_item32_t *) data, nData, true); // start transmission and wait until completed before returning
|
rmt_write_items(config->channel, (rmt_item32_t *) data, nData, true); // start transmission and wait until completed before returning
|
||||||
|
|
|
||||||
|
|
@ -81,12 +81,13 @@ struct Effect2 {
|
||||||
#define PIN 21
|
#define PIN 21
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Pixel px(PIN);
|
|
||||||
Pixel px2(2);
|
Pixel px2(2);
|
||||||
Pixel px5(5);
|
Pixel px(PIN);
|
||||||
Pixel px3(3);
|
Pixel px3(3);
|
||||||
Pixel px4(4);
|
Pixel px4(4);
|
||||||
|
Pixel px5(5);
|
||||||
Pixel px6(6);
|
Pixel px6(6);
|
||||||
|
Pixel px7(7);
|
||||||
|
|
||||||
Effect1 effect1(&px,5);
|
Effect1 effect1(&px,5);
|
||||||
Effect2 effect2(&px,100);
|
Effect2 effect2(&px,100);
|
||||||
|
|
@ -98,13 +99,6 @@ void setup() {
|
||||||
delay(1000); // wait for interface to flush
|
delay(1000); // wait for interface to flush
|
||||||
|
|
||||||
Serial.println("\n\nHomeSpan Pixel Example\n");
|
Serial.println("\n\nHomeSpan Pixel Example\n");
|
||||||
|
|
||||||
Serial.println(px.getPin());
|
|
||||||
Serial.println(px2.getPin());
|
|
||||||
Serial.println(px3.getPin());
|
|
||||||
Serial.println(px4.getPin());
|
|
||||||
Serial.println(px5.getPin());
|
|
||||||
Serial.println(px6.getPin());
|
|
||||||
|
|
||||||
} // end of setup()
|
} // end of setup()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue