Lumitronix_Iflex_Pro_Workshop
Library to interact with the iFlexPro
Lpd8806GenericMethod.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2 LumitronixIFlex library helper functions for LPD8806 using general Pins
3 
4 Written by Michael C. Miller.
5 
6 I invest time and resources providing this open source code,
7 please support me by dontating (see https://github.com/Makuna)
8 
9 -------------------------------------------------------------------------
10 This file is part of the LUMITRONIX_iFlex_Workshop library.
11 
12 LumitronixIFlexBus is free software: you can redistribute it and/or modify
13 it under the terms of the GNU Lesser General Public License as
14 published by the Free Software Foundation, either version 3 of
15 the License, or (at your option) any later version.
16 
17 LumitronixIFlexBus is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU Lesser General Public License for more details.
21 
22 You should have received a copy of the GNU Lesser General Public
23 License along with LumitronixIFlex. If not, see
24 <http://www.gnu.org/licenses/>.
25 -------------------------------------------------------------------------*/
26 
27 #pragma once
28 
29 // must also check for arm due to Teensy incorrectly having ARDUINO_ARCH_AVR set
30 #if defined(ARDUINO_ARCH_AVR) && !defined(__arm__)
31 #include "TwoWireBitBangImpleAvr.h"
32 #else
33 #include "TwoWireBitBangImple.h"
34 #endif
35 
36 
37 template<typename T_TWOWIRE> class Lpd8806MethodBase
38 {
39 public:
40  typedef typename T_TWOWIRE::SettingsObject SettingsObject;
41 
42  Lpd8806MethodBase(uint8_t pinClock, uint8_t pinData, uint16_t pixelCount, size_t elementSize, size_t settingsSize) :
43  _sizeData(pixelCount * elementSize + settingsSize),
44  _sizeFrame((pixelCount + 31) / 32),
45  _wire(pinClock, pinData)
46  {
47  _data = static_cast<uint8_t*>(malloc(_sizeData));
48  // data cleared later in Begin()
49  }
50 
51 #if !defined(__AVR_ATtiny85__) && !defined(ARDUINO_attiny)
52  Lpd8806MethodBase(uint16_t pixelCount, size_t elementSize, size_t settingsSize) :
53  Lpd8806MethodBase(SCK, MOSI, pixelCount, elementSize, settingsSize)
54  {
55  }
56 #endif
57 
58 
60  {
61  free(_data);
62  }
63 
64  bool IsReadyToUpdate() const
65  {
66  return true; // dot stars don't have a required delay
67  }
68 
69 #if defined(ARDUINO_ARCH_ESP32)
70  void Initialize(int8_t sck, int8_t miso, int8_t mosi, int8_t ss)
71  {
72  _wire.begin(sck, miso, mosi, ss);
73  }
74 #endif
75 
76  void Initialize()
77  {
78  _wire.begin();
79  }
80 
81  void Update(bool)
82  {
83  _wire.beginTransaction();
84 
85  // start frame
86  for (size_t frameByte = 0; frameByte < _sizeFrame; frameByte++)
87  {
88  _wire.transmitByte(0x00);
89  }
90 
91  // data
92  _wire.transmitBytes(_data, _sizeData);
93 
94  // end frame
95  for (size_t frameByte = 0; frameByte < _sizeFrame; frameByte++)
96  {
97  _wire.transmitByte(0xff);
98  }
99 
100  _wire.endTransaction();
101  }
102 
104  {
105  // this method requires update to be called only if changes to buffer
106  return false;
107  }
108 
109  uint8_t* getData() const
110  {
111  return _data;
112  };
113 
114  size_t getDataSize() const
115  {
116  return _sizeData;
117  };
118 
119  void applySettings([[maybe_unused]] const SettingsObject& settings)
120  {
121  _wire.applySettings(settings);
122  }
123 
124 private:
125  const size_t _sizeData; // Size of '_data' buffer below
126  const size_t _sizeFrame;
127 
128  T_TWOWIRE _wire;
129  uint8_t* _data; // Holds LED color values
130 };
131 
133 
134 #if !defined(__AVR_ATtiny85__) && !defined(ARDUINO_attiny)
135 #include "TwoWireSpiImple.h"
142 
144 
146 #endif
147 
148 
149 
Lpd8806MethodBase< TwoWireSpiImple< SpiSpeedHz > > Lpd8806SpiHzMethod
Definition: Lpd8806GenericMethod.h:143
Lpd8806MethodBase< TwoWireSpiImple< SpiSpeed1Mhz > > Lpd8806Spi1MhzMethod
Definition: Lpd8806GenericMethod.h:140
Lpd8806MethodBase< TwoWireSpiImple< SpiSpeed10Mhz > > Lpd8806Spi10MhzMethod
Definition: Lpd8806GenericMethod.h:137
Lpd8806MethodBase< TwoWireSpiImple< SpiSpeed2Mhz > > Lpd8806Spi2MhzMethod
Definition: Lpd8806GenericMethod.h:139
Lpd8806MethodBase< TwoWireBitBangImple > Lpd8806Method
Definition: Lpd8806GenericMethod.h:132
Lpd8806MethodBase< TwoWireSpiImple< SpiSpeed500Khz > > Lpd8806Spi500KhzMethod
Definition: Lpd8806GenericMethod.h:141
Lpd8806MethodBase< TwoWireSpiImple< SpiSpeed20Mhz > > Lpd8806Spi20MhzMethod
Definition: Lpd8806GenericMethod.h:136
Lpd8806MethodBase< TwoWireSpiImple< SpiSpeed5Mhz > > Lpd8806Spi5MhzMethod
Definition: Lpd8806GenericMethod.h:138
Lpd8806Spi10MhzMethod Lpd8806SpiMethod
Definition: Lpd8806GenericMethod.h:145
Definition: Lpd8806GenericMethod.h:38
Lpd8806MethodBase(uint8_t pinClock, uint8_t pinData, uint16_t pixelCount, size_t elementSize, size_t settingsSize)
Definition: Lpd8806GenericMethod.h:42
T_TWOWIRE::SettingsObject SettingsObject
Definition: Lpd8806GenericMethod.h:40
bool IsReadyToUpdate() const
Definition: Lpd8806GenericMethod.h:64
size_t getDataSize() const
Definition: Lpd8806GenericMethod.h:114
void Initialize()
Definition: Lpd8806GenericMethod.h:76
~Lpd8806MethodBase()
Definition: Lpd8806GenericMethod.h:59
void Update(bool)
Definition: Lpd8806GenericMethod.h:81
bool AlwaysUpdate()
Definition: Lpd8806GenericMethod.h:103
uint8_t * getData() const
Definition: Lpd8806GenericMethod.h:109
void applySettings([[maybe_unused]] const SettingsObject &settings)
Definition: Lpd8806GenericMethod.h:119
Lpd8806MethodBase(uint16_t pixelCount, size_t elementSize, size_t settingsSize)
Definition: Lpd8806GenericMethod.h:52