@@ -35,229 +35,228 @@ over Inter-Integrated Circuit (I2C) in Arduino
3535
3636/* *
3737 * @brief The sfeTkArdI2C implements an sfeTkII2C interface, defining the Arduino implementation for I2C in the Toolkit
38- * /
38+ */
3939
4040class sfeTkArdI2C : public sfeTkII2C
4141{
4242 public:
4343 /* *--------------------------------------------------------------------------
4444 @brief Constructor
4545 */
46- sfeTkArdI2C (void ) : _i2cPort(nullptr ), _bufferChunkSize{kDefaultBufferChunk }
47- {
48- }
49- /* *--------------------------------------------------------------------------
50- @brief Constructor
51-
52- @param addr The address of the device
53- */
54- sfeTkArdI2C (uint8_t addr) : sfeTkII2C(addr)
55- {
56- }
57-
58- /* *
59- * @brief copy constructor
60- */
61- sfeTkArdI2C (sfeTkArdI2C const &rhs) : sfeTkII2C(), _i2cPort{rhs._i2cPort }
62- {
63- }
64-
65- /* *
66- * @brief Copy assignment
67- *
68- * @param rhs right hand side of the assignment
69- * @return value of the left hand side of the assignment
70- */
71- sfeTkArdI2C &operator =(const sfeTkArdI2C &rhs)
72- {
73- _i2cPort = rhs._i2cPort ;
74- return *this ;
75- }
76-
77- /* *--------------------------------------------------------------------------
78- @brief Method sets up the required I2C settings.
79- @note This function provides a default I2C Port.
80-
81- @retval kSTkErrOk on successful execution.
82- */
83- sfeTkError_t init ();
84-
85- /* *--------------------------------------------------------------------------
86- @brief - address version of the init method
87- */
88- sfeTkError_t init (uint8_t addr);
89-
90- /* *--------------------------------------------------------------------------
91- @brief Method sets up the required I2C settings.
46+ sfeTkArdI2C (void ) : _i2cPort(nullptr ), _bufferChunkSize{kDefaultBufferChunk }
47+ {
48+ }
49+ /* *--------------------------------------------------------------------------
50+ @brief Constructor
9251
93- @param wirePort Port for I2C communication.
94- @param bInit This flag tracks whether the bus has been initialized.
52+ @param addr The address of the device
53+ */
54+ sfeTkArdI2C (uint8_t addr) : sfeTkII2C(addr)
55+ {
56+ }
57+
58+ /* *
59+ * @brief copy constructor
60+ */
61+ sfeTkArdI2C (sfeTkArdI2C const &rhs) : sfeTkII2C(), _i2cPort{rhs._i2cPort }
62+ {
63+ }
64+
65+ /* *
66+ * @brief Copy assignment
67+ *
68+ * @param rhs right hand side of the assignment
69+ * @return value of the left hand side of the assignment
70+ */
71+ sfeTkArdI2C &operator =(const sfeTkArdI2C &rhs)
72+ {
73+ _i2cPort = rhs._i2cPort ;
74+ return *this ;
75+ }
9576
96- @retval kSTkErrOk on successful execution.
97- */
98- sfeTkError_t init (TwoWire &wirePort, uint8_t addr, bool bInit = false );
77+ /* *--------------------------------------------------------------------------
78+ @brief Method sets up the required I2C settings.
79+ @note This function provides a default I2C Port.
9980
100- /* *--------------------------------------------------------------------------
101- @brief A simple ping of the device at the given address.
102- @note sfeTkIBus interface method
81+ @retval kSTkErrOk on successful execution.
82+ */
83+ sfeTkError_t init ();
10384
104- @retval kSTkErrOk on success,
105- */
106- sfeTkError_t ping ();
85+ /* *--------------------------------------------------------------------------
86+ @brief - address version of the init method
87+ */
88+ sfeTkError_t init (uint8_t addr);
10789
108- /* *--------------------------------------------------------------------------
109- @brief Write a single byte to the device
110- @note sfeTkIBus interface method
90+ /* *--------------------------------------------------------------------------
91+ @brief Method sets up the required I2C settings.
11192
112- @param data Data to write.
93+ @param wirePort Port for I2C communication.
94+ @param bInit This flag tracks whether the bus has been initialized.
11395
114- @retval returns kStkErrOk on success
115- */
116- sfeTkError_t writeByte ( uint8_t data );
96+ @retval kSTkErrOk on successful execution.
97+ */
98+ sfeTkError_t init (TwoWire &wirePort, uint8_t addr, bool bInit = false );
11799
118- /* *--------------------------------------------------------------------------
119- @brief Write a single byte to the given register
120- @note sfeTkIBus interface method
100+ /* *--------------------------------------------------------------------------
101+ @brief A simple ping of the device at the given address.
102+ @note sfeTkIBus interface method
121103
122- @param devReg The device's register's address.
123- @param data Data to write.
104+ @retval kSTkErrOk on success,
105+ */
106+ sfeTkError_t ping ();
124107
125- @retval returns kStkErrOk on success
126- */
127- sfeTkError_t writeRegisterByte ( uint8_t devReg, uint8_t data);
108+ /* *--------------------------------------------------------------------------
109+ @brief Write a single byte to the device
110+ @note sfeTkIBus interface method
128111
129- /* *--------------------------------------------------------------------------
130- @brief Write a single word to the given register
131- @note sfeTkIBus interface method
112+ @param data Data to write.
132113
133- @param devReg The device's register's address.
134- @param data Data to write.
114+ @retval returns kStkErrOk on success
115+ */
116+ sfeTkError_t writeByte (uint8_t data);
135117
136- @retval returns kStkErrOk on success
137- */
138- sfeTkError_t writeRegisterWord ( uint8_t devReg, uint16_t data);
118+ /* *--------------------------------------------------------------------------
119+ @brief Write a single byte to the given register
120+ @note sfeTkIBus interface method
139121
140- /* *--------------------------------------------------------------------------
141- @brief Writes a number of bytes starting at the given register's address .
122+ @param devReg The device's register's address.
123+ @param data Data to write .
142124
143- @note sfeTkIBus interface method
144- @note This method is virtual to allow it to be overridden to support a device that requires a unique impl
125+ @retval returns kStkErrOk on success
126+ */
127+ sfeTkError_t writeRegisterByte (uint8_t devReg, uint8_t data);
145128
146- @param devReg The device's register's address.
147- @param data Data to write.
129+ /* *--------------------------------------------------------------------------
130+ @brief Write a single word to the given register
131+ @note sfeTkIBus interface method
148132
149- @retval kStkErrOk on success
150- */
151- sfeTkError_t writeRegisterRegion (uint8_t devReg, const uint8_t *data, size_t length);
133+ @param devReg The device's register's address.
134+ @param data Data to write.
152135
153- /* *--------------------------------------------------------------------------
154- @brief Writes a number of bytes starting at the given register's 16-bit address.
136+ @retval returns kStkErrOk on success
137+ */
138+ sfeTkError_t writeRegisterWord (uint8_t devReg, uint16_t data);
155139
156- @param devAddr The device's 16-bit address/pin
157- param devReg The device's register's address.
158- @param data Data to write.
140+ /* *--------------------------------------------------------------------------
141+ @brief Writes a number of bytes starting at the given register's address.
159142
160- @retval sfeTkError_t kSTkErrOk on successful execution
143+ @note sfeTkIBus interface method
144+ @note This method is virtual to allow it to be overridden to support a device that requires a unique impl
161145
162- */
163- sfeTkError_t writeRegister16Region ( uint16_t devReg, const uint8_t * data, size_t length);
146+ @param devReg The device's register's address.
147+ @param data Data to write.
164148
165- /* *--------------------------------------------------------------------------
166- @brief Reads a byte of data from the given register.
149+ @retval kStkErrOk on success
150+ */
151+ sfeTkError_t writeRegisterRegion (uint8_t devReg, const uint8_t *data, size_t length);
167152
168- @note sfeTkIBus interface method
153+ /* *--------------------------------------------------------------------------
154+ @brief Writes a number of bytes starting at the given register's 16-bit address.
169155
170- @param devReg The device's register's address.
171- @param data Data to read.
156+ @param devAddr The device's 16-bit address/pin
157+ param devReg The device's register's address.
158+ @param data Data to write.
172159
173- @retval kStkErrOk on success
174- */
175- sfeTkError_t readRegisterByte (uint8_t devReg, uint8_t &data);
160+ @retval sfeTkError_t kSTkErrOk on successful execution
176161
177- /* *--------------------------------------------------------------------------
178- @brief Reads a word of data from the given register.
162+ */
163+ sfeTkError_t writeRegister16Region ( uint16_t devReg, const uint8_t * data, size_t length);
179164
180- @note sfeTkIBus interface method
165+ /* *--------------------------------------------------------------------------
166+ @brief Reads a byte of data from the given register.
181167
182- @param devReg The device's register's address.
183- @param data Data to read.
168+ @note sfeTkIBus interface method
184169
185- @retval kSTkErrOk on success
186- */
187- sfeTkError_t readRegisterWord (uint8_t devReg, uint16_t &data);
170+ @param devReg The device's register's address.
171+ @param data Data to read.
188172
189- /* *--------------------------------------------------------------------------
190- @brief Reads a block of data from the given register.
173+ @retval kStkErrOk on success
174+ */
175+ sfeTkError_t readRegisterByte (uint8_t devReg, uint8_t &data);
191176
192- @note sfeTkIBus interface method
193- @note This method is virtual to allow it to be overridden to support a device that requires a unique impl
177+ /* *--------------------------------------------------------------------------
178+ @brief Reads a word of data from the given register.
194179
195- @param devReg The device's register's address.
196- @param data Data being read.
197- @param numBytes Number of bytes to read.
198- @param[out] readBytes - Number of bytes read
180+ @note sfeTkIBus interface method
199181
182+ @param devReg The device's register's address.
183+ @param data Data to read.
200184
201- @retval kSTkErrOk on success
202- */
203- sfeTkError_t readRegisterRegion (uint8_t devReg, uint8_t *data, size_t numBytes, size_t &readBytes );
185+ @retval kSTkErrOk on success
186+ */
187+ sfeTkError_t readRegisterWord (uint8_t devReg, uint16_t &data );
204188
205- /* *--------------------------------------------------------------------------
206- @brief Reads a block of data from the given 16-bit register address .
189+ /* *--------------------------------------------------------------------------
190+ @brief Reads a block of data from the given register.
207191
208- @param reg The device's 16 bit register's address.
209- @param data Data to write.
210- @param numBytes - length of data
211- @param[out] readBytes - number of bytes read
192+ @note sfeTkIBus interface method
193+ @note This method is virtual to allow it to be overridden to support a device that requires a unique impl
212194
213- @retval int returns kSTkErrOk on success, or kSTkErrFail code
195+ @param devReg The device's register's address.
196+ @param data Data being read.
197+ @param numBytes Number of bytes to read.
198+ @param[out] readBytes - Number of bytes read
214199
215- */
216- sfeTkError_t readRegister16Region (uint16_t reg, uint8_t *data, size_t numBytes, size_t &readBytes);
217200
218- // Buffer size chunk getter/setter
219- /* *--------------------------------------------------------------------------
220- @brief set the buffer chunk size
201+ @retval kSTkErrOk on success
202+ */
203+ sfeTkError_t readRegisterRegion ( uint8_t devReg, uint8_t *data, size_t numBytes, size_t &readBytes);
221204
222- @note default size is 32
205+ /* *--------------------------------------------------------------------------
206+ @brief Reads a block of data from the given 16-bit register address.
223207
224- @param theChunk the new size - must be > 0
208+ @param reg The device's 16 bit register's address.
209+ @param data Data to write.
210+ @param numBytes - length of data
211+ @param[out] readBytes - number of bytes read
225212
226- */
227- void setBufferChunkSize (size_t theChunk)
228- {
229- if (theChunk > 0 )
230- _bufferChunkSize = theChunk;
231- }
213+ @retval int returns kSTkErrOk on success, or kSTkErrFail code
232214
233- /* *--------------------------------------------------------------------------
234- @brief set the buffer chunk size
215+ */
216+ sfeTkError_t readRegister16Region ( uint16_t reg, uint8_t *data, size_t numBytes, size_t &readBytes);
235217
236- @retval The current chunk size
218+ // Buffer size chunk getter/setter
219+ /* *--------------------------------------------------------------------------
220+ @brief set the buffer chunk size
237221
238- */
239- size_t bufferChunkSize (void )
240- {
241- return _bufferChunkSize;
242- }
222+ @note default size is 32
243223
244- protected:
245- // note: The wire port is protected, allowing access if a sub-class is
246- // created to implement a special read/write routine
247- //
248- /* * The actual Arduino i2c port */
249- TwoWire *_i2cPort;
224+ @param theChunk the new size - must be > 0
250225
251- private:
252- sfeTkError_t writeRegisterRegionAddress (uint8_t *devReg, size_t regLength, const uint8_t *data, size_t length);
226+ */
227+ void setBufferChunkSize (size_t theChunk)
228+ {
229+ if (theChunk > 0 )
230+ _bufferChunkSize = theChunk;
231+ }
253232
254- sfeTkError_t readRegisterRegionAnyAddress ( uint8_t *devReg, size_t regLength, uint8_t *data, size_t numBytes,
255- size_t &readBytes);
233+ /* *--------------------------------------------------------------------------
234+ @brief set the buffer chunk size
256235
257- /* * Default buffer chunk size*/
258- static constexpr size_t kDefaultBufferChunk = 32 ;
236+ @retval The current chunk size
259237
260- /* * The I2C buffer chunker - chunk size*/
261- size_t _bufferChunkSize;
262- }
263- ;
238+ */
239+ size_t bufferChunkSize (void )
240+ {
241+ return _bufferChunkSize;
242+ }
243+
244+ protected:
245+ // note: The wire port is protected, allowing access if a sub-class is
246+ // created to implement a special read/write routine
247+ //
248+ /* * The actual Arduino i2c port */
249+ TwoWire *_i2cPort;
250+
251+ private:
252+ sfeTkError_t writeRegisterRegionAddress (uint8_t *devReg, size_t regLength, const uint8_t *data, size_t length);
253+
254+ sfeTkError_t readRegisterRegionAnyAddress (uint8_t *devReg, size_t regLength, uint8_t *data, size_t numBytes,
255+ size_t &readBytes);
256+
257+ /* * Default buffer chunk size*/
258+ static constexpr size_t kDefaultBufferChunk = 32 ;
259+
260+ /* * The I2C buffer chunker - chunk size*/
261+ size_t _bufferChunkSize;
262+ };
0 commit comments