some more cleanup

Next up:  Move loadData into isrHandler, if possible.
To Do: redo single-color methods
This commit is contained in:
Gregg 2022-01-16 23:24:54 -06:00
parent 1a99df4214
commit 40c05bd53f
3 changed files with 13 additions and 14 deletions

View File

@ -10,7 +10,9 @@ Pixel::Pixel(int pin, uint32_t nPixels){
rmt_isr_register(isrHandler,(void *)this,0,NULL); // end-transmission interrupt automatically enabled by rmt_tx_start rmt_isr_register(isrHandler,(void *)this,0,NULL); // end-transmission interrupt automatically enabled by rmt_tx_start
rmt_set_tx_thr_intr_en(rf->getChannel(),true,8); // need to also enable threshold interrupt rmt_set_tx_thr_intr_en(rf->getChannel(),true,8); // need to also enable threshold interrupt
channelNum=rf->getChannel(); channelNum=rf->getChannel();
txEndMask=TxEndMask(channelNum);
} }
@ -51,7 +53,6 @@ void Pixel::setColors(const uint32_t *data, uint32_t nPixels){
status.iMem=0; status.iMem=0;
status.iBit=24; status.iBit=24;
status.started=true; status.started=true;
status.txEndMask=TxEndMask(channelNum);
loadData(); // load first 2 bytes loadData(); // load first 2 bytes
loadData(); loadData();
@ -92,7 +93,7 @@ void Pixel::setHSV(float h, float s, float v, int nPixels){
/////////////////// ///////////////////
void Pixel::loadColor(color_t c, uint32_t *p){ void Pixel::loadColor(uint32_t c, uint32_t *p){
uint32_t count=24; uint32_t count=24;
p+=23; p+=23;
@ -105,13 +106,13 @@ void Pixel::loadColor(color_t c, uint32_t *p){
/////////////////// ///////////////////
color_t Pixel::getColorRGB(uint8_t r, uint8_t g, uint8_t b){ uint32_t Pixel::getColorRGB(uint8_t r, uint8_t g, uint8_t b){
return(g<<16 | r<<8 | b); return(g<<16 | r<<8 | b);
} }
/////////////////// ///////////////////
color_t Pixel::getColorHSV(float h, float s, float v){ uint32_t Pixel::getColorHSV(float h, float s, float v){
float r,g,b; float r,g,b;
LedPin::HSVtoRGB(h,s/100.0,v/100.0,&r,&g,&b); LedPin::HSVtoRGB(h,s/100.0,v/100.0,&r,&g,&b);
return(getColorRGB(r*255,g*255,b*255)); return(getColorRGB(r*255,g*255,b*255));
@ -143,7 +144,7 @@ void Pixel::isrHandler(void *arg){
Pixel *pix=(Pixel *)arg; Pixel *pix=(Pixel *)arg;
if(RMT.int_st.val & status.txEndMask){ if(RMT.int_st.val & pix->txEndMask){
RMT.int_clr.val=~0; RMT.int_clr.val=~0;
status.started=false; status.started=false;
return; return;

View File

@ -8,15 +8,12 @@
#include "RFControl.h" #include "RFControl.h"
#include "PwmPin.h" #include "PwmPin.h"
typedef uint32_t color_t;
struct pixel_status_t { struct pixel_status_t {
int nPixels; int nPixels;
const uint32_t *data; const uint32_t *data;
int iBit; int iBit;
int iMem; int iMem;
boolean started; boolean started;
uint32_t txEndMask; // mask for end-of-transmission interrupt
}; };
class Pixel { class Pixel {
@ -24,6 +21,7 @@ class Pixel {
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
int channelNum; // channel number int channelNum; // channel number
uint32_t txEndMask; // mask for end-of-transmission interrupt
uint32_t nTrain; // number of Pixels to transmit per pulse train batch uint32_t nTrain; // number of Pixels to transmit per pulse train batch
@ -45,7 +43,7 @@ class Pixel {
volatile static pixel_status_t status; volatile static pixel_status_t status;
static void isrHandler(void *arg); // interrupt handler static void isrHandler(void *arg); // interrupt handler
void loadColor(color_t c, uint32_t *p); // creates pulse pattern for pixel color (encoded as RGB in low 24-bits of *p) void loadColor(uint32_t c, uint32_t *p); // creates pulse pattern for pixel color (encoded as RGB in low 24-bits of *p)
public: public:
Pixel(int pin, uint32_t nPixels=1); // creates addressable single-wire RGB LED on pin (such as the SK68 or WS28), with OPTIONAL reserve of memory for nPixels Pixel(int pin, uint32_t nPixels=1); // creates addressable single-wire RGB LED on pin (such as the SK68 or WS28), with OPTIONAL reserve of memory for nPixels
@ -57,8 +55,8 @@ class Pixel {
void setColors(const uint32_t *data, uint32_t nPixels); // sets colors of nPixels from array of Colors void setColors(const uint32_t *data, uint32_t nPixels); // sets colors of nPixels from array of Colors
int getPin(){return(rf->getPin());} // returns pixel pin if valid, else returns -1 int getPin(){return(rf->getPin());} // returns pixel pin if valid, else returns -1
static color_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 color_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
void loadData(); void loadData();

View File

@ -6,7 +6,7 @@ struct Effect1 {
Pixel *px; Pixel *px;
int H=0; int H=0;
color_t x[8]; uint32_t x[8];
uint32_t alarmTime=0; uint32_t alarmTime=0;
uint32_t speed; uint32_t speed;
@ -35,7 +35,7 @@ struct Effect2 {
int phase=0; int phase=0;
int dir=1; int dir=1;
int H=0; int H=0;
color_t x[8]; uint32_t x[8];
uint32_t alarmTime=0; uint32_t alarmTime=0;
uint32_t speed; uint32_t speed;
@ -106,7 +106,7 @@ void setup() {
colors[4]=px.getColorRGB(40,0,0); colors[4]=px.getColorRGB(40,0,0);
colors[5]=px.getColorRGB(40,0,0); colors[5]=px.getColorRGB(40,0,0);
colors[6]=px.getColorRGB(40,0,0); colors[6]=px.getColorRGB(40,0,0);
colors[7]=px.getColorRGB(0,0,40); colors[7]=px.getColorRGB(0,40,0);
px.setColors(colors,8); px.setColors(colors,8);
Serial.println("\n\nDone\n\n"); Serial.println("\n\nDone\n\n");