AceWire  0.4.1
Unified interface for selecting different I2C implementations on Arduino platforms
FeliasFoggWireInterface.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_FELIAS_FOGG_WIRE_INTERFACE_H
26 #define ACE_WIRE_FELIAS_FOGG_WIRE_INTERFACE_H
27 
28 #include <stdint.h>
29 
30 namespace ace_wire {
31 
40 template <typename T_WIRE>
42  public:
47  explicit FeliasFoggWireInterface(T_WIRE& wire) : mWire(wire) {}
48 
50  void begin() const {}
51 
53  void end() const {}
54 
62  uint8_t beginTransmission(uint8_t addr) const {
63  mWire.beginTransmission(addr);
64  return 0;
65  }
66 
72  uint8_t write(uint8_t data) const {
73  return (uint8_t) mWire.write(data);
74  }
75 
89  uint8_t endTransmission(bool sendStop = true) const {
90  return mWire.endTransmission(sendStop);
91  }
92 
103  uint8_t requestFrom(uint8_t addr, uint8_t quantity, bool sendStop = true)
104  const {
105  return mWire.requestFrom(addr, quantity, sendStop);
106  }
107 
109  uint8_t read() const {
110  return mWire.read();
111  }
112 
113  // Use default copy constructor and assignment operator.
115  FeliasFoggWireInterface& operator=(
116  const FeliasFoggWireInterface&) = default;
117 
118  private:
119  T_WIRE& mWire;
120 };
121 
122 }
123 
124 #endif
ace_wire::FeliasFoggWireInterface::endTransmission
uint8_t endTransmission(bool sendStop=true) const
Send the data in the buffer, and return the following status code:
Definition: FeliasFoggWireInterface.h:89
ace_wire::FeliasFoggWireInterface::begin
void begin() const
Initial the interface.
Definition: FeliasFoggWireInterface.h:50
ace_wire::FeliasFoggWireInterface::requestFrom
uint8_t requestFrom(uint8_t addr, uint8_t quantity, bool sendStop=true) const
Read bytes from the slave and store in buffer owned by SoftWire.
Definition: FeliasFoggWireInterface.h:103
ace_wire::FeliasFoggWireInterface
A thin wrapper around the SlowSoftWire class provided by the https://github.com/felias-fogg/SlowSoftW...
Definition: FeliasFoggWireInterface.h:41
ace_wire::FeliasFoggWireInterface::FeliasFoggWireInterface
FeliasFoggWireInterface(T_WIRE &wire)
Constructor.
Definition: FeliasFoggWireInterface.h:47
ace_wire::FeliasFoggWireInterface::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: FeliasFoggWireInterface.h:62
ace_wire::FeliasFoggWireInterface::end
void end() const
End the interface.
Definition: FeliasFoggWireInterface.h:53
ace_wire::FeliasFoggWireInterface::read
uint8_t read() const
Read byte from buffer.
Definition: FeliasFoggWireInterface.h:109
ace_wire::FeliasFoggWireInterface::write
uint8_t write(uint8_t data) const
Write data into the write buffer.
Definition: FeliasFoggWireInterface.h:72