AceWire  0.4.0
Unified interface for selecting different I2C implementations on Arduino platforms
TestatoWireInterface.h
1 /*
2 MIT License
3 
4 Copyright (c) 2022 Brian T. Park
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 all
14 copies or substantial portions of the Software.
15 
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 SOFTWARE.
23 */
24 
25 #ifndef ACE_WIRE_TESTATO_WIRE_INTERFACE_H
26 #define ACE_WIRE_TESTATO_WIRE_INTERFACE_H
27 
28 #include <stdint.h>
29 
30 namespace ace_wire {
31 
40 template <typename T_WIRE>
42  public:
47  explicit TestatoWireInterface(T_WIRE& wire) : mWire(wire) {}
48 
50  void begin() const {}
51 
53  void end() const {}
54 
65  uint8_t beginTransmission(uint8_t addr) const {
66  mWire.beginTransmission(addr);
67  return 0;
68  }
69 
78  uint8_t write(uint8_t data) const {
79  return (uint8_t) mWire.write(data);
80  }
81 
95  uint8_t endTransmission(bool sendStop = true) const {
96  return mWire.endTransmission(sendStop);
97  }
98 
108  uint8_t requestFrom(uint8_t addr, uint8_t quantity, bool sendStop = true)
109  const {
110  return mWire.requestFrom(addr, quantity, sendStop);
111  }
112 
114  uint8_t read() const {
115  return mWire.read();
116  }
117 
118  // Use default copy constructor and assignment operator.
119  TestatoWireInterface(const TestatoWireInterface&) = default;
120  TestatoWireInterface& operator=(const TestatoWireInterface&) = default;
121 
122  private:
123  T_WIRE& mWire;
124 };
125 
126 }
127 
128 #endif
ace_wire::TestatoWireInterface::read
uint8_t read() const
Read byte from buffer.
Definition: TestatoWireInterface.h:114
ace_wire::TestatoWireInterface::begin
void begin() const
Initial the interface.
Definition: TestatoWireInterface.h:50
ace_wire::TestatoWireInterface::TestatoWireInterface
TestatoWireInterface(T_WIRE &wire)
Constructor.
Definition: TestatoWireInterface.h:47
ace_wire::TestatoWireInterface::end
void end() const
End the interface.
Definition: TestatoWireInterface.h:53
ace_wire::TestatoWireInterface::requestFrom
uint8_t requestFrom(uint8_t addr, uint8_t quantity, bool sendStop=true) const
Prepare to read bytes from the device at the given address, and send a STOP condition if sendStop is ...
Definition: TestatoWireInterface.h:108
ace_wire::TestatoWireInterface::endTransmission
uint8_t endTransmission(bool sendStop=true) const
Send a STOP condition if sendStop is true, or a REPEATED_START condition if sendStop is false.
Definition: TestatoWireInterface.h:95
ace_wire::TestatoWireInterface::beginTransmission
uint8_t beginTransmission(uint8_t addr) const
Prepare the write buffer to accept a sequence of data, and save the addr for transmission when endTra...
Definition: TestatoWireInterface.h:65
ace_wire::TestatoWireInterface
A thin wrapper around the SoftwareWire class provided by the https://github.com/Testato/SoftwareWire ...
Definition: TestatoWireInterface.h:41
ace_wire::TestatoWireInterface::write
uint8_t write(uint8_t data) const
Write data to the I2C bus.
Definition: TestatoWireInterface.h:78