remove dependency from arduino.h

This commit is contained in:
zackees
2024-11-27 03:56:00 -08:00
parent ec51b6b30c
commit df779b478a
2 changed files with 41 additions and 13 deletions
+18 -3
View File
@@ -38,8 +38,23 @@
#endif
#ifndef ObjectFLED_h
#define ObjectFLED_h
#include <Arduino.h>
// #include <Arduino.h>
#include "DMAChannel.h"
#include "core_pins.h"
// for DMAMEM
#include "pgmspace.h"
// for NUM_DIGITAL_PINS and NUM_DIGITAL_PINS
#include "pins_arduino.h"
#if !defined(NUM_DIGITAL_PINS) && !defined(USING_ARDUINO_FOR_TEENSY)
#define USING_ARDUINO_FOR_TEENSY 0
#else
#define USING_ARDUINO_FOR_TEENSY 1
#endif
// Ordinary RGB data is converted to GPIO bitmasks on-the-fly using
// a transmit buffer sized for 2 DMA transfers. The larger this setting,
@@ -122,7 +137,7 @@ public:
private:
static void isr(void);
void genFrameBuffer(uint);
void genFrameBuffer(uint32_t);
static uint8_t* frameBuffer; //isr()
static uint32_t numbytes; //isr()
@@ -170,6 +185,6 @@ void fadeToColorBy(void*, uint16_t, uint32_t, uint8_t);
//drawSquare(RGB_Array, LED_Rows, LED_Cols, Y_Corner, X_Corner, square_Size)
//Draws square in a 2D RGB array with lower left corner at (Y_Corner, X_Corner).
//Safe to specify -Y, -X corner, safe to draw a box which partially fits on LED plane.
void drawSquare(void*, uint16_t, uint16_t, int, int, uint, uint32_t);
void drawSquare(void*, uint16_t, uint16_t, int, int, uint32_t, uint32_t);
#endif
+23 -10
View File
@@ -53,11 +53,24 @@ GOIO9List = { 2, 3, 4, 5, 29, 33, 48, 49, 50, 51, 52, 53, 54 } //6 top, 7 botto
* FrameBuffer no longer passed in, constructor now creates buffer; destructor added
* Added support for per-object setting of OC factor, TH+TL, T0H, T1H, and LATCH_DELAY in begin function
*/
#ifndef __IMXRT1062__
#error Only Teensy 4.x supported.
#else
#include <string.h>
#include "ObjectFLED.h"
#ifndef MIN
#define MIN(a,b) ((a)<(b)?(a):(b))
#endif
#ifndef MAX
#define MAX(a,b) ((a)>(b)?(a):(b))
#endif
volatile uint32_t framebuffer_index = 0; //isr()
uint8_t* ObjectFLED::frameBuffer; //isr()
uint32_t ObjectFLED::numbytes; //isr()
@@ -273,16 +286,16 @@ void fillbits(uint32_t *dest, const uint8_t *pixels, int n, uint32_t mask) {
}
void ObjectFLED::genFrameBuffer(uint serp) {
uint j = 0;
void ObjectFLED::genFrameBuffer(uint32_t serp) {
uint32_t j = 0;
int jChange = -3;
if (serp == 0) { // use faster loops if no serp
switch (params & 0x3F) {
case CORDER_RGBW: // R,G,B = R,G,B - min(R,G,B); W = min(R,G,B)
case CORDER_RGBW: // R,G,B = R,G,B - MIN(R,G,B); W = MIN(R,G,B)
for (uint16_t i = 0; i < (numbytes * numpins); i += 4) {
uint8_t minRGB = min(*((uint8_t*)drawBuffer + j) * rLevel / 65025, \
uint8_t minRGB = MIN(*((uint8_t*)drawBuffer + j) * rLevel / 65025, \
*((uint8_t*)drawBuffer + j + 1) * rLevel / 65025);
minRGB = min(minRGB, *((uint8_t*)drawBuffer + j + 2) * rLevel / 65025);
minRGB = MIN(minRGB, *((uint8_t*)drawBuffer + j + 2) * rLevel / 65025);
*(frameBuffer + i) = *((uint8_t*)drawBuffer + j) * rLevel / 65025 - minRGB;
*(frameBuffer + i + 1) = *((uint8_t*)drawBuffer + j + 1) * gLevel / 65025 - minRGB;
*(frameBuffer + i + 2) = *((uint8_t*)drawBuffer + j + 2) * bLevel / 65025 - minRGB;
@@ -317,11 +330,11 @@ void ObjectFLED::genFrameBuffer(uint serp) {
} // switch()
} else { //serpentine
switch (params & 0x3F) {
case CORDER_RGBW: // R,G,B = R,G,B - min(R,G,B); W = min(R,G,B)
case CORDER_RGBW: // R,G,B = R,G,B - MIN(R,G,B); W = MIN(R,G,B)
for (uint16_t i = 0; i < (numbytes * numpins); i += 4) {
uint8_t minRGB = min(*((uint8_t*)drawBuffer + j) * rLevel / 65025, \
uint8_t minRGB = MIN(*((uint8_t*)drawBuffer + j) * rLevel / 65025, \
* ((uint8_t*)drawBuffer + j + 1) * rLevel / 65025);
minRGB = min(minRGB, *((uint8_t*)drawBuffer + j + 2) * rLevel / 65025);
minRGB = MIN(minRGB, *((uint8_t*)drawBuffer + j + 2) * rLevel / 65025);
if (i % (serp * 4) == 0) {
if (jChange < 0) { j = i / 4 * 3; jChange = 3; }
else { j = (i / 4 + serp - 1) * 3; jChange = -3; }
@@ -544,7 +557,7 @@ void ObjectFLED::setBalance(uint32_t balMask) {
//Fades CRGB array towards the background color by amount.
void fadeToColorBy(void* leds, uint16_t count, uint32_t color, uint8_t fadeAmt) {
for (uint x = 0; x < count * 3; x += 3) {
for (uint32_t x = 0; x < count * 3; x += 3) {
//fade red
*((uint8_t*)leds + x) = (( *((uint8_t*)leds + x) * (1 + (255 - fadeAmt))) >> 8) + \
(( ((color >> 16) & 0xFF) * (1 + fadeAmt)) >> 8);
@@ -559,7 +572,7 @@ void fadeToColorBy(void* leds, uint16_t count, uint32_t color, uint8_t fadeAmt)
// Safely draws box even if partially offscreen on 2D CRGB array
void drawSquare(void* leds, uint16_t planeY, uint16_t planeX, int yCorner, int xCorner, uint size, uint32_t color) {
void drawSquare(void* leds, uint16_t planeY, uint16_t planeX, int yCorner, int xCorner, uint32_t size, uint32_t color) {
if (size != 0) { size--; }
else { return; }
for (int x = xCorner; x <= xCorner + (int)size; x++) {