AceWire  0.4.1
Unified interface for selecting different I2C implementations on Arduino platforms
TodbotWireInterface.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_TODBOT_WIRE_INTERFACE_H
26 #define ACE_WIRE_TODBOT_WIRE_INTERFACE_H
27 
28 #include <stdint.h>
29 
30 namespace ace_wire {
31 
43 template <typename T_WIRE>
45  public:
50  explicit TodbotWireInterface(T_WIRE& wire) : mWire(wire) {}
51 
53  void begin() const {}
54 
56  void end() const {}
57 
71  uint8_t beginTransmission(uint8_t addr) const {
72  return mWire.beginTransmission(addr) ^ 0x1;
73  }
74 
83  uint8_t write(uint8_t data) const {
84  return (uint8_t) mWire.write(data);
85  }
86 
94  uint8_t endTransmission(bool sendStop = true) const {
95  (void) sendStop;
96  return mWire.endTransmission();
97  }
98 
113  uint8_t requestFrom(uint8_t addr, uint8_t quantity, bool sendStop = true)
114  const {
115  (void) sendStop; // sendStop not implemented by SoftI2CMaster
116  return mWire.requestFrom(addr, quantity);
117  }
118 
133  uint8_t read() const {
134  return mWire.read();
135  }
136 
137  // Use default copy constructor and assignment operator.
138  TodbotWireInterface(const TodbotWireInterface&) = default;
139  TodbotWireInterface& operator=(const TodbotWireInterface&) = default;
140 
141  private:
142  T_WIRE& mWire;
143 };
144 
145 }
146 
147 #endif
ace_wire::TodbotWireInterface
A thin wrapper for the SoftI2CMaster class from the https://github.com/todbot/SoftI2CMaster project s...
Definition: TodbotWireInterface.h:44
ace_wire::TodbotWireInterface::write
uint8_t write(uint8_t data) const
Write data immediately into the I2C bus with the Write bit set, since SoftI2CMaster library does not ...
Definition: TodbotWireInterface.h:83
ace_wire::TodbotWireInterface::read
uint8_t read() const
Read byte from the I2C bus.
Definition: TodbotWireInterface.h:133
ace_wire::TodbotWireInterface::requestFrom
uint8_t requestFrom(uint8_t addr, uint8_t quantity, bool sendStop=true) const
Prepare to send quantity bytes to the device at addr.
Definition: TodbotWireInterface.h:113
ace_wire::TodbotWireInterface::beginTransmission
uint8_t beginTransmission(uint8_t addr) const
Send the I2C address on the bus immediately, since the underlying implementation does not use a TX bu...
Definition: TodbotWireInterface.h:71
ace_wire::TodbotWireInterface::end
void end() const
End the interface.
Definition: TodbotWireInterface.h:56
ace_wire::TodbotWireInterface::begin
void begin() const
Initial the interface.
Definition: TodbotWireInterface.h:53
ace_wire::TodbotWireInterface::endTransmission
uint8_t endTransmission(bool sendStop=true) const
Send the data in the buffer.
Definition: TodbotWireInterface.h:94
ace_wire::TodbotWireInterface::TodbotWireInterface
TodbotWireInterface(T_WIRE &wire)
Constructor.
Definition: TodbotWireInterface.h:50