FastLED 3.9.15
Loading...
Searching...
No Matches
ObjectFLED.h
Go to the documentation of this file.
1/* ObjectFLED - Teensy 4.x DMA to all pins for independent control of large and
2 multiple LED display objects
3
4 Copyright (c) 2024 Kurt Funderburg
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to deal
8 in the Software without restriction, including without limitation the rights
9 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 OctoWS2811 library code was well-studied and substantial portions of it used
17 to implement high-speed, non-blocking DMA for LED signal output in this library.
18 See ObjectFLED.cpp for a summary of changes made to the original OctoWS2811.
19
20 OctoWS2811 - High Performance WS2811 LED Display Library
21 Copyright (c) 2013 Paul Stoffregen, PJRC.COM, LLC
22 http://www.pjrc.com/teensy/td_libs_OctoWS2811.html
23
24 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
29 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
30 THE SOFTWARE.
31*/
32
33#include "platforms/arm/teensy/is_teensy.h"
34
35#ifndef FL_IS_TEENSY_4X
36#error "Sorry, ObjectFLED only works on Teensy 4.x boards."
37#endif
38#if TEENSYDUINO < 121
39#error "Teensyduino version 1.21 or later is required to compile this library."
40#endif
41#ifndef ObjectFLED_h
42#define ObjectFLED_h
43#include <WProgram.h>
44#include "DMAChannel.h"
46
47#include "fl/stl/stdint.h"
48
49//Experimentally found DSE=3, SPEED=0 gave best LED overclocking
50//boot defaults DSE=6, SPEED=2.
51#define OUTPUT_PAD_DSE 3 //Legal values 0-7
52#define OUTPUT_PAD_SPEED 0 //Legal values 0-3
53
54// Ordinary RGB data is converted to GPIO bitmasks on-the-fly using
55// a transmit buffer sized for 2 DMA transfers. The larger this setting,
56// the more interrupt latency OctoWS2811 can tolerate, but the transmit
57// buffer grows in size. For good performance, the buffer should be kept
58// smaller than the half the Cortex-M7 data cache.
59//bitdata[B_P_D * 64] buffer holds data (10KB) for 80 LED bytes: 4DW * 8b = 32DW/LEDB = 96DW/LED
60//framebuffer_index = B_P_D * 2 = pointer to next block for transfer (80 LEDB / bitdata buffer)
61#define BYTES_PER_DMA 20 //= number of pairs of LEDB (40=80B) bitmasks in bitdata.
62
63#define CORDER_RGB 0 //* WS2811, YF923
64#define CORDER_RBG 1
65#define CORDER_GRB 2 //* WS2811B, Most LED strips are wired this way
66#define CORDER_GBR 3 //*
67#define CORDER_BRG 4 //* Adafruit Product ID: 5984 As of November 5, 2024 - this strand has different 'internal' color ordering. It's now BRG not RGB,
68#define CORDER_BGR 5 //* Adafruit Dotstar LEDs SK9822 uses this CO but they use inverted start/stop bits
69#define CORDER_RGBW 6 //* Popular
70#define CORDER_RBGW 7
71#define CORDER_GRBW 8
72#define CORDER_GBRW 9
73#define CORDER_BRGW 10
74#define CORDER_BGRW 11 // Adafruit Dotstar LEDs SK9822 uses this CO but they use inverted start/stop bits
75#define CORDER_WRGB 12
76#define CORDER_WRBG 13
77#define CORDER_WGRB 14
78#define CORDER_WGBR 15
79#define CORDER_WBRG 16
80#define CORDER_WBGR 17
81#define CORDER_RWGB 18
82#define CORDER_RWBG 19
83#define CORDER_GWRB 20
84#define CORDER_GWBR 21
85#define CORDER_BWRG 22
86#define CORDER_BWGR 23
87#define CORDER_RGWB 24
88#define CORDER_RBWG 25
89#define CORDER_GRWB 26
90#define CORDER_GBWR 27
91#define CORDER_BRWG 28
92#define CORDER_BGWR 29
93
94namespace fl {
95
96
97//Usage: ObjectFLED myCube ( Num_LEDs, *drawBuffer, LED_type, numPins, *pinList, serpentineNumber )
99public:
100 // Usage: ObjectFLED myCube ( Num_LEDs, *drawBuffer, LED_type, numPins, *pinList, serpentineNumber )
101 // Example:
102 // byte pinList[NUM_CHANNELS] = {1, 8, 14, 17, 24, 29, 20, 0, 15, 16, 18, 19, 21, 22, 23, 25};
103 // byte pinListBlank[7] = {1, 8, 14, 17, 24, 29, 20};
104 // CRGB testCube[NUM_PLANES][NUM_ROWS][PIX_PER_ROW];
105 // CRGB blankLeds[7][8][8];
106 // ObjectFLED leds(PIX_PER_ROW * NUM_ROWS * NUM_PLANES, testCube, CORDER_RGB, NUM_CHANNELS, pinList);
107 // void setup() {
108 // leds.begin(1.6, 72); //1.6 ocervlock factor, 72uS LED latch delay
109 // leds.setBrightness(64);
110 // }
111 // void loop() {
112 // leds.show();
113 // delay(100);
114 // }
115 ObjectFLED(uint16_t numLEDs, void* drawBuf, uint8_t config, uint8_t numPins, const uint8_t* pinList, \
116 uint8_t serpentine = 0);
117
119
124 template <typename TIMING>
125 void begin(uint16_t latch_delay_us = TIMING::RESET) {
126 // Extract T1, T2, T3 directly from TIMING struct
127 // T1 = high time for '0' bit
128 // T2 = additional high time for '1' bit
129 // T3 = low tail duration
130 begin(TIMING::T1, TIMING::T2, TIMING::T3, latch_delay_us);
131 }
132
139 void begin(uint16_t t1, uint16_t t2, uint16_t t3, uint16_t latch_delay_us = 300);
140
141private:
142 //begin() - Use defalut LED timing: 1.0 OC Factor, 1250 nS CLK (=800 KHz), 300 nS T0H, 750 nS T1H, 300 uS LED Latch Delay.
143 void begin(void);
144
145 //begin(LED_Latch_Delay_uS) - sets the LED Latch Delay.
147
148 //beginInternal(LED_CLK_nS, LED_T0H_nS, LED_T1H_nS, LED_Latch_Delay_uS) - specifies full LED waveform timing.
150
151public:
152
153 void show(void);
155
156 int busy(void);
157
158 //Brightness values 0-255
160
161 //Color Balance is 3-byte number in RGB order. Each byte is a brightness value for that color.
163
165
167
168 // Frame buffer for direct pixel access (used by FastLED integration)
170
171private:
172 static void isr(void);
173
175
182public:
184private:
187 uint8_t pinlist[NUM_DIGITAL_PINS];
190 uint16_t TH_TL = 1250; //nS- period of LED output
191 uint16_t T0H = 300; //nS- duration of T0H
192 uint16_t T1H = 750; //nS- duration of T1H
193 uint16_t LATCH_DELAY = 300; //uS time to hold output low for LED latch.
194
195 //for show context switch
199 uint8_t pin_bitnumLocal[NUM_DIGITAL_PINS];
200 uint8_t pin_offsetLocal[NUM_DIGITAL_PINS];
201}; // class ObjectFLED
202
203
204//fadeToColorBy(RGB_array, LED_count, Color, FadeAmount)
205//Fades an RGB array towards the background color by amount.
207
208
209//drawSquare(RGB_Array, LED_Rows, LED_Cols, Y_Corner, X_Corner, square_Size)
210//Draws square in a 2D RGB array with lower left corner at (Y_Corner, X_Corner).
211//Safe to specify -Y, -X corner, safe to draw a box which partially fits on LED plane.
212void drawSquare(void*, uint16_t, uint16_t, int, int, uint32_t, uint32_t);
213
214} // namespace fl
215
216#endif
void * drawBuffer
Definition ObjectFLED.h:183
uint8_t * frameBufferLocal
Definition ObjectFLED.h:169
void begin(uint16_t t1, uint16_t t2, uint16_t t3, uint16_t latch_delay_us=300)
Three-phase timing begin method (T1, T2, T3 format) This method converts 3-phase timing to ObjectFLED...
uint8_t brightness
Definition ObjectFLED.h:177
uint8_t pin_bitnumLocal[NUM_DIGITAL_PINS]
Definition ObjectFLED.h:199
uint8_t pinlist[NUM_DIGITAL_PINS]
Definition ObjectFLED.h:187
uint32_t update_begin_micros
Definition ObjectFLED.h:176
uint32_t colorBalance
Definition ObjectFLED.h:178
int busy(void)
uint32_t getBalance()
void setBalance(uint32_t)
uint16_t LATCH_DELAY
Definition ObjectFLED.h:193
void genFrameBuffer(uint32_t)
ObjectFLED(uint16_t numLEDs, void *drawBuf, uint8_t config, uint8_t numPins, const uint8_t *pinList, uint8_t serpentine=0)
uint32_t gLevel
Definition ObjectFLED.h:180
uint8_t getBrightness()
void waitForDmaToFinish()
uint32_t bitmaskLocal[4]
Definition ObjectFLED.h:196
static void isr(void)
uint16_t stripLen
Definition ObjectFLED.h:185
uint8_t serpNumber
Definition ObjectFLED.h:189
void setBrightness(uint8_t)
uint16_t TH_TL
Definition ObjectFLED.h:190
uint32_t rLevel
Definition ObjectFLED.h:179
void begin(uint16_t latch_delay_us=TIMING::RESET)
Template-based begin method - extracts timing from TIMING struct at compile-time This is the preferre...
Definition ObjectFLED.h:125
void begin(void)
void begin(uint16_t)
void show(void)
uint32_t numbytesLocal
Definition ObjectFLED.h:198
uint16_t comp1load[3]
Definition ObjectFLED.h:188
uint8_t numpinsLocal
Definition ObjectFLED.h:197
void beginInternal(uint16_t, uint16_t, uint16_t, uint16_t=300)
uint8_t pin_offsetLocal[NUM_DIGITAL_PINS]
Definition ObjectFLED.h:200
uint32_t bLevel
Definition ObjectFLED.h:181
fl::u32 uint32_t
Definition s16x16x4.h:219
fl::u16 uint16_t
Definition s16x16x4.h:214
void drawSquare(void *, uint16_t, uint16_t, int, int, uint32_t, uint32_t)
void fadeToColorBy(void *, uint16_t, uint32_t, uint8_t)
unsigned char uint8_t
Definition s16x16x4.h:209
Base definition for an LED controller.
Definition crgb.hpp:179