@@ -35,229 +35,228 @@ over Inter-Integrated Circuit (I2C) in Arduino
35
35
36
36
/* *
37
37
* @brief The sfeTkArdI2C implements an sfeTkII2C interface, defining the Arduino implementation for I2C in the Toolkit
38
- * /
38
+ */
39
39
40
40
class sfeTkArdI2C : public sfeTkII2C
41
41
{
42
42
public:
43
43
/* *--------------------------------------------------------------------------
44
44
@brief Constructor
45
45
*/
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
92
51
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
+ }
95
76
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.
99
80
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 ();
103
84
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);
107
89
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.
111
92
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.
113
95
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 );
117
99
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
121
103
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 ();
124
107
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
128
111
129
- /* *--------------------------------------------------------------------------
130
- @brief Write a single word to the given register
131
- @note sfeTkIBus interface method
112
+ @param data Data to write.
132
113
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);
135
117
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
139
121
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 .
142
124
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);
145
128
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
148
132
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.
152
135
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);
155
139
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.
159
142
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
161
145
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.
164
148
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);
167
152
168
- @note sfeTkIBus interface method
153
+ /* *--------------------------------------------------------------------------
154
+ @brief Writes a number of bytes starting at the given register's 16-bit address.
169
155
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.
172
159
173
- @retval kStkErrOk on success
174
- */
175
- sfeTkError_t readRegisterByte (uint8_t devReg, uint8_t &data);
160
+ @retval sfeTkError_t kSTkErrOk on successful execution
176
161
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);
179
164
180
- @note sfeTkIBus interface method
165
+ /* *--------------------------------------------------------------------------
166
+ @brief Reads a byte of data from the given register.
181
167
182
- @param devReg The device's register's address.
183
- @param data Data to read.
168
+ @note sfeTkIBus interface method
184
169
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.
188
172
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);
191
176
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.
194
179
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
199
181
182
+ @param devReg The device's register's address.
183
+ @param data Data to read.
200
184
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 );
204
188
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.
207
191
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
212
194
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
214
199
215
- */
216
- sfeTkError_t readRegister16Region (uint16_t reg, uint8_t *data, size_t numBytes, size_t &readBytes);
217
200
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);
221
204
222
- @note default size is 32
205
+ /* *--------------------------------------------------------------------------
206
+ @brief Reads a block of data from the given 16-bit register address.
223
207
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
225
212
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
232
214
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);
235
217
236
- @retval The current chunk size
218
+ // Buffer size chunk getter/setter
219
+ /* *--------------------------------------------------------------------------
220
+ @brief set the buffer chunk size
237
221
238
- */
239
- size_t bufferChunkSize (void )
240
- {
241
- return _bufferChunkSize;
242
- }
222
+ @note default size is 32
243
223
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
250
225
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
+ }
253
232
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
256
235
257
- /* * Default buffer chunk size*/
258
- static constexpr size_t kDefaultBufferChunk = 32 ;
236
+ @retval The current chunk size
259
237
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