Lumitronix_Iflex_Pro_Workshop
Library to interact with the iFlexPro
TwoWireBitBangImple.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2 LumitronixIFlex library helper functions for DotStars using general Pins (APA102/LPD8806).
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 
31 {
32 public:
34 
35  TwoWireBitBangImple(uint8_t pinClock, uint8_t pinData) :
36  _pinClock(pinClock),
37  _pinData(pinData)
38  {
39  pinMode(pinClock, OUTPUT);
40  pinMode(pinData, OUTPUT);
41  }
42 
44  {
45  pinMode(_pinClock, INPUT);
46  pinMode(_pinData, INPUT);
47  }
48 
49  void begin()
50  {
51  digitalWrite(_pinClock, LOW);
52  digitalWrite(_pinData, LOW);
53  }
54 
56  {
57 
58  }
59 
61  {
62  digitalWrite(_pinData, LOW);
63  }
64 
65  void transmitBit(uint8_t bit)
66  {
67  // set data bit on pin
68  digitalWrite(_pinData, bit);
69 
70  // set clock high as data is ready
71  digitalWrite(_pinClock, HIGH);
72 
73  // set clock low as data pin is changed
74  digitalWrite(_pinClock, LOW);
75  }
76 
77  void transmitByte(uint8_t data)
78  {
79  for (int bit = 7; bit >= 0; bit--)
80  {
81  // set data bit on pin
82  digitalWrite(_pinData, (data & 0x80) == 0x80 ? HIGH : LOW);
83 
84  // set clock high as data is ready
85  digitalWrite(_pinClock, HIGH);
86 
87  data <<= 1;
88 
89  // set clock low as data pin is changed
90  digitalWrite(_pinClock, LOW);
91  }
92  }
93 
94  void transmitBytes(const uint8_t* data, size_t dataSize)
95  {
96  const uint8_t* endData = data + dataSize;
97  while (data < endData)
98  {
99  transmitByte(*data++);
100  }
101  }
102 
103  void applySettings([[maybe_unused]] const SettingsObject& settings)
104  {
105  }
106 
107 private:
108  const uint8_t _pinClock; // output pin number for clock line
109  const uint8_t _pinData; // output pin number for data line
110 };
Definition: NeoSettings.h:29
Definition: TwoWireBitBangImple.h:31
void endTransaction()
Definition: TwoWireBitBangImple.h:60
~TwoWireBitBangImple()
Definition: TwoWireBitBangImple.h:43
NeoNoSettings SettingsObject
Definition: TwoWireBitBangImple.h:33
void transmitByte(uint8_t data)
Definition: TwoWireBitBangImple.h:77
TwoWireBitBangImple(uint8_t pinClock, uint8_t pinData)
Definition: TwoWireBitBangImple.h:35
void beginTransaction()
Definition: TwoWireBitBangImple.h:55
void transmitBytes(const uint8_t *data, size_t dataSize)
Definition: TwoWireBitBangImple.h:94
void transmitBit(uint8_t bit)
Definition: TwoWireBitBangImple.h:65
void begin()
Definition: TwoWireBitBangImple.h:49
void applySettings([[maybe_unused]] const SettingsObject &settings)
Definition: TwoWireBitBangImple.h:103