FastLED 3.9.15
Loading...
Searching...
No Matches
pins.h
Go to the documentation of this file.
1
7
8#pragma once
9
10#include "fl/system/pin.h" // IWYU pragma: keep
11#include "fl/stl/span.h"
12#include "fl/stl/noexcept.h"
13
14namespace fl {
15
18struct Pins8 {
19 int pins[8];
20};
21
29 public:
31
33 void init(const Pins8& pins);
34
39 void write(fl::span<const u8> pin_data) const;
40
46 void writeByte(u8 byte) const {
47 const u8 lo_nib = byte & 0x0F;
48 const u8 hi_nib = (byte >> 4) & 0x0F;
49 applyNibble(mSetLo[lo_nib], mClrLo[lo_nib]);
50 applyNibble(mSetHi[hi_nib], mClrHi[hi_nib]);
51 }
52
55 bool allSamePort() const;
56
57 private:
58 // Each LUT entry stores up to 4 pin indices to set or clear.
59 struct PinList {
60 int pins[4];
62 };
63
64 void buildNibbleLut(u8 bit_offset, PinList (&set_lut)[16],
65 PinList (&clr_lut)[16]);
66
67 static void applyNibble(const PinList &set, const PinList &clr);
68
69 int mPins[8] = {-1, -1, -1, -1, -1, -1, -1, -1};
70 PinList mSetLo[16] = {};
71 PinList mClrLo[16] = {};
72 PinList mSetHi[16] = {};
73 PinList mClrHi[16] = {};
74};
75
79void digitalMultiWrite8(const Pins8& pins, fl::span<const u8> pin_data);
80
83struct Pins16 {
84 int pins[16];
85};
86
94 public:
96
98 void init(const Pins16& pins);
99
104 void write(fl::span<const u16> pin_data) const;
105
108 bool allSamePort() const;
109
110 private:
111 // Each LUT entry stores up to 4 pin indices to set or clear.
112 struct PinList {
113 int pins[4];
115 };
116
117 void buildNibbleLut(u8 bit_offset, PinList (&set_lut)[16],
118 PinList (&clr_lut)[16]);
119
120 static void applyNibble(const PinList &set, const PinList &clr);
121
122 int mPins[16] = {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1};
123 PinList mSetNib[4][16] = {}; // nibbles 0-3 (bits 0-3, 4-7, 8-11, 12-15)
124 PinList mClrNib[4][16] = {};
125};
126
130void digitalMultiWrite16(const Pins16& pins, fl::span<const u16> pin_data);
131
133struct PinInfo {
134 int pin = -1;
135 int port = -1;
136};
137
142int pinToPort(int pin);
143
147
148} // namespace fl
int pins[]
Definition Spi.ino:11
bool allSamePort() const
Check whether all active pins (non -1) share the same GPIO port.
Definition pins.cpp.hpp:338
void write(fl::span< const u16 > pin_data) const
Write pre-transposed 16-bit data to the 16 pins.
Definition pins.cpp.hpp:328
void init(const Pins16 &pins)
Initialize from 16 pin numbers. -1 means "skip this bit position".
Definition pins.cpp.hpp:275
void buildNibbleLut(u8 bit_offset, PinList(&set_lut)[16], PinList(&clr_lut)[16])
Definition pins.cpp.hpp:354
PinList mSetNib[4][16]
Definition pins.h:123
static void applyNibble(const PinList &set, const PinList &clr)
Definition pins.cpp.hpp:376
PinList mClrNib[4][16]
Definition pins.h:124
DigitalMultiWrite16() FL_NOEXCEPT=default
PinList mClrLo[16]
Definition pins.h:71
void init(const Pins8 &pins)
Initialize from 8 pin numbers. -1 means "skip this bit position".
Definition pins.cpp.hpp:157
PinList mSetHi[16]
Definition pins.h:72
void buildNibbleLut(u8 bit_offset, PinList(&set_lut)[16], PinList(&clr_lut)[16])
Definition pins.cpp.hpp:235
static void applyNibble(const PinList &set, const PinList &clr)
Definition pins.cpp.hpp:256
void writeByte(u8 byte) const
Write a single bitmask byte to the 8 pins.
Definition pins.h:46
bool allSamePort() const
Check whether all active pins (non -1) share the same GPIO port.
Definition pins.cpp.hpp:219
void write(fl::span< const u8 > pin_data) const
Write pre-transposed byte data to the 8 pins.
Definition pins.cpp.hpp:209
DigitalMultiWrite8() FL_NOEXCEPT=default
PinList mSetLo[16]
Definition pins.h:70
PinList mClrHi[16]
Definition pins.h:73
Definition set.h:367
unsigned char u8
Definition stdint.h:131
void digitalMultiWrite8(const Pins8 &pins, fl::span< const u8 > pin_data)
Convenience free function — creates a temporary DigitalMultiWrite8, initializes it,...
Definition pins.cpp.hpp:265
int pinToPort(int pin)
Map a runtime pin number to an integer port ID using FastPin<N>::port().
Definition pins.cpp.hpp:150
void digitalMultiWrite16(const Pins16 &pins, fl::span< const u16 > pin_data)
Convenience free function — creates a temporary DigitalMultiWrite16, initializes it,...
Definition pins.cpp.hpp:385
void pinMap(fl::span< PinInfo > pins)
Resolve port IDs for an array of PinInfo in-place.
Definition pins.cpp.hpp:395
Base definition for an LED controller.
Definition crgb.hpp:179
int port
Definition pins.h:135
int pins[16]
Definition pins.h:84
int pins[8]
Definition pins.h:19
int pin
Definition pins.h:134
Pin number with its resolved port ID.
Definition pins.h:133
POD struct holding 16 pin numbers for bulk pin writes.
Definition pins.h:83
POD struct holding 8 pin numbers for bulk pin writes.
Definition pins.h:18
#define FL_NOEXCEPT