11/*
22sfeTkArdI2C.cpp
3+ The MIT License (MIT)
4+
5+ Copyright (c) 2023 SparkFun Electronics
6+
7+ Permission is hereby granted, free of charge, to any person obtaining a
8+ copy of this software and associated documentation files (the "Software"),
9+ to deal in the Software without restriction, including without limitation
10+ the rights to use, copy, modify, merge, publish, distribute, sublicense,
11+ and/or sell copies of the Software, and to permit persons to whom the
12+ Software is furnished to do so, subject to the following conditions: The
13+ above copyright notice and this permission notice shall be included in all
14+ copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED
15+ "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
16+ NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
17+ PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
18+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
19+ ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21+
322*/
423
524#include " sfeTkArdI2C.h"
25+ #include < cstdint>
626
727// ---------------------------------------------------------------------------------
828// init()
@@ -68,7 +88,7 @@ sfeTkError_t sfeTkArdI2C::ping()
6888// ---------------------------------------------------------------------------------
6989// writeByte()
7090//
71- // Writes a single byte to the device.
91+ // Sends a single byte to the device.
7292//
7393// Returns true on success, false on failure
7494//
@@ -83,6 +103,41 @@ sfeTkError_t sfeTkArdI2C::writeByte(uint8_t dataToWrite)
83103 return _i2cPort->endTransmission () == 0 ? kSTkErrOk : kSTkErrFail ;
84104}
85105
106+ // ---------------------------------------------------------------------------------
107+ // writeWord()
108+ //
109+ // Sends a word to the device.
110+ //
111+ // Returns true on success, false on failure
112+ //
113+ sfeTkError_t sfeTkArdI2C::writeWord (uint16_t dataToWrite)
114+ {
115+ if (!_i2cPort)
116+ return kSTkErrBusNotInit ;
117+
118+ return writeBlock ((uint8_t *)&dataToWrite, sizeof (uint16_t ));
119+ }
120+
121+ // ---------------------------------------------------------------------------------
122+ // writeBlock()
123+ //
124+ // Sends an array of data to the device.
125+ //
126+ // Returns true on success, false on failure
127+ //
128+ sfeTkError_t sfeTkArdI2C::writeBlock (const uint8_t *data, size_t length)
129+ {
130+ int nData = 0 ;
131+ if (!_i2cPort)
132+ return kSTkErrBusNotInit ;
133+
134+ // do the Arduino I2C work
135+ _i2cPort->beginTransmission (address ());
136+ _i2cPort->write (data, (int )length);
137+
138+ return _i2cPort->endTransmission () == 0 ? kSTkErrOk : kSTkErrFail ;
139+ }
140+
86141// ---------------------------------------------------------------------------------
87142// writeRegisterByte()
88143//
0 commit comments