AceWire  0.4.1
Unified interface for selecting different I2C implementations on Arduino platforms
SeeedWireInterface.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_SEEED_WIRE_INTERFACE_H
26 #define ACE_WIRE_SEEED_WIRE_INTERFACE_H
27 
28 #include <stdint.h>
29 
30 namespace ace_wire {
31 
40 template <typename T_WIRE>
42  public:
47  explicit SeeedWireInterface(T_WIRE& wire) : mWire(wire) {}
48 
50  void begin() const {}
51 
53  void end() const {}
54 
68  uint8_t beginTransmission(uint8_t addr) const {
69  return mWire.beginTransmission(addr) ^ 0x1;
70  }
71 
79  uint8_t write(uint8_t data) const {
80  return (uint8_t) mWire.write(data);
81  }
82 
92  uint8_t endTransmission(bool sendStop = true) const {
93  (void) sendStop;
94  return mWire.endTransmission();
95  }
96 
111  uint8_t requestFrom(uint8_t addr, uint8_t quantity, bool sendStop = true)
112  const {
113  (void) sendStop;
114  return mWire.requestFrom(addr, quantity);
115  }
116 
122  uint8_t read() const {
123  return mWire.read();
124  }
125 
126  // Use default copy constructor and assignment operator.
127  SeeedWireInterface(const SeeedWireInterface&) = default;
128  SeeedWireInterface& operator=(const SeeedWireInterface&) = default;
129 
130  private:
131  T_WIRE& mWire;
132 };
133 
134 }
135 
136 #endif
ace_wire::SeeedWireInterface::end
void end() const
End the interface.
Definition: SeeedWireInterface.h:53
ace_wire::SeeedWireInterface::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: SeeedWireInterface.h:111
ace_wire::SeeedWireInterface::write
uint8_t write(uint8_t data) const
Write data immediately into the I2C bus with the Write bit set, since the SoftwareI2C library does no...
Definition: SeeedWireInterface.h:79
ace_wire::SeeedWireInterface::begin
void begin() const
Initial the interface.
Definition: SeeedWireInterface.h:50
ace_wire::SeeedWireInterface::beginTransmission
uint8_t beginTransmission(uint8_t addr) const
Send the I2C address on the bus immediately since the underlying SoftwareI2C class does not use a TX ...
Definition: SeeedWireInterface.h:68
ace_wire::SeeedWireInterface
A thin wrapper for the SoftwareI2C class from the https://github.com/Seeed-Studio/Arduino_Software_I2...
Definition: SeeedWireInterface.h:41
ace_wire::SeeedWireInterface::endTransmission
uint8_t endTransmission(bool sendStop=true) const
Send the data in the buffer.
Definition: SeeedWireInterface.h:92
ace_wire::SeeedWireInterface::SeeedWireInterface
SeeedWireInterface(T_WIRE &wire)
Constructor.
Definition: SeeedWireInterface.h:47
ace_wire::SeeedWireInterface::read
uint8_t read() const
Read byte from the I2C bus.
Definition: SeeedWireInterface.h:122