forked from jrowberg/i2cdevlib
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathITG3200.cpp
More file actions
521 lines (496 loc) · 18.6 KB
/
Copy pathITG3200.cpp
File metadata and controls
521 lines (496 loc) · 18.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
// I2Cdev library collection - ITG3200 I2C device class
// Based on InvenSense ITG-3200 datasheet rev. 1.4, 3/30/2010 (PS-ITG-3200A-00-01.4)
// 7/31/2011 by Jeff Rowberg <jeff@rowberg.net>
// Updates should (hopefully) always be available at https://github.com/jrowberg/i2cdevlib
//
// Changelog:
// 2011-07-31 - initial release
/* ============================================
I2Cdev device library code is placed under the MIT license
Copyright (c) 2011 Jeff Rowberg
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
===============================================
*/
#include "ITG3200.h"
/** Default constructor, uses default I2C address.
* @see ITG3200_DEFAULT_ADDRESS
*/
ITG3200::ITG3200() {
devAddr = ITG3200_DEFAULT_ADDRESS;
}
/** Specific address constructor.
* @param address I2C address
* @see ITG3200_DEFAULT_ADDRESS
* @see ITG3200_ADDRESS_AD0_LOW
* @see ITG3200_ADDRESS_AD0_HIGH
*/
ITG3200::ITG3200(uint8_t address) {
devAddr = address;
}
/** Power on and prepare for general usage.
* This will activate the gyroscope, so be sure to adjust the power settings
* after you call this method if you want it to enter standby mode, or another
* less demanding mode of operation. This also sets the gyroscope to use the
* X-axis gyro for a clock source. Note that it doesn't have any delays in the
* routine, which means you might want to add ~50ms to be safe if you happen
* to need to read gyro data immediately after initialization. The data will
* flow in either case, but the first reports may have higher error offsets.
*/
void ITG3200::initialize() {
setFullScaleRange(ITG3200_FULLSCALE_2000);
setClockSource(ITG3200_CLOCK_PLL_XGYRO);
}
/** Verify the I2C connection.
* Make sure the device is connected and responds as expected.
* @return True if connection is valid, false otherwise
*/
bool ITG3200::testConnection() {
return getDeviceID() == 0b110100;
}
// WHO_AM_I register
/** Get Device ID.
* This register is used to verify the identity of the device (0b110100).
* @return Device ID (should be 0x34, 52 dec, 64 oct)
* @see ITG3200_RA_WHO_AM_I
* @see ITG3200_RA_DEVID_BIT
* @see ITG3200_RA_DEVID_LENGTH
*/
uint8_t ITG3200::getDeviceID() {
I2Cdev::readBits(devAddr, ITG3200_RA_WHO_AM_I, ITG3200_DEVID_BIT, ITG3200_DEVID_LENGTH, buffer);
return buffer[0];
}
/** Set Device ID.
* Write a new ID into the WHO_AM_I register (no idea why this should ever be
* necessary though).
* @param id New device ID to set.
* @see getDeviceID()
* @see ITG3200_RA_WHO_AM_I
* @see ITG3200_RA_DEVID_BIT
* @see ITG3200_RA_DEVID_LENGTH
*/
void ITG3200::setDeviceID(uint8_t id) {
I2Cdev::writeBits(devAddr, ITG3200_RA_WHO_AM_I, ITG3200_DEVID_BIT, ITG3200_DEVID_LENGTH, id);
}
// SMPLRT_DIV register
/** Get sample rate.
* This register determines the sample rate of the ITG-3200 gyros. The gyros'
* outputs are sampled internally at either 1kHz or 8kHz, determined by the
* DLPF_CFG setting (see register 22). This sampling is then filtered digitally
* and delivered into the sensor registers after the number of cycles determined
* by this register. The sample rate is given by the following formula:
*
* F_sample = F_internal / (divider+1), where F_internal is either 1kHz or 8kHz
*
* As an example, if the internal sampling is at 1kHz, then setting this
* register to 7 would give the following:
*
* F_sample = 1kHz / (7 + 1) = 125Hz, or 8ms per sample
*
* @return Current sample rate
* @see setDLPFBandwidth()
* @see ITG3200_RA_SMPLRT_DIV
*/
uint8_t ITG3200::getRate() {
I2Cdev::readByte(devAddr, ITG3200_RA_SMPLRT_DIV, buffer);
return buffer[0];
}
/** Set sample rate.
* @param rate New sample rate
* @see getRate()
* @see setDLPFBandwidth()
* @see ITG3200_RA_SMPLRT_DIV
*/
void ITG3200::setRate(uint8_t rate) {
I2Cdev::writeByte(devAddr, ITG3200_RA_SMPLRT_DIV, rate);
}
// DLPF_FS register
/** Set full-scale range.
* The FS_SEL parameter allows setting the full-scale range of the gyro sensors,
* as described in the table below. The power-on-reset value of FS_SEL is 00h.
* Set to 03h for proper operation.
*
* 0 = Reserved
* 1 = Reserved
* 2 = Reserved
* 3 = +/- 2000 degrees/sec
*
* @return Current full-scale range setting
* @see ITG3200_FULLSCALE_2000
* @see ITG3200_RA_DLPF_FS
* @see ITG3200_DF_FS_SEL_BIT
* @see ITG3200_DF_FS_SEL_LENGTH
*/
uint8_t ITG3200::getFullScaleRange() {
I2Cdev::readBits(devAddr, ITG3200_RA_DLPF_FS, ITG3200_DF_FS_SEL_BIT, ITG3200_DF_FS_SEL_LENGTH, buffer);
return buffer[0];
}
/** Set full-scale range setting.
* @param range New full-scale range value
* @see getFullScaleRange()
* @see ITG3200_FULLSCALE_2000
* @see ITG3200_RA_DLPF_FS
* @see ITG3200_DF_FS_SEL_BIT
* @see ITG3200_DF_FS_SEL_LENGTH
*/
void ITG3200::setFullScaleRange(uint8_t range) {
I2Cdev::writeBits(devAddr, ITG3200_RA_DLPF_FS, ITG3200_DF_FS_SEL_BIT, ITG3200_DF_FS_SEL_LENGTH, range);
}
/** Get digital low-pass filter bandwidth.
* The DLPF_CFG parameter sets the digital low pass filter configuration. It
* also determines the internal sampling rate used by the device as shown in
* the table below.
*
* DLPF_CFG | Low-Pass Filter Bandwidth | Internal Sample Rate
* ---------+---------------------------+---------------------
* 0 | 256Hz | 8kHz
* 1 | 188Hz | 1kHz
* 2 | 98Hz | 1kHz
* 3 | 42Hz | 1kHz
* 4 | 20Hz | 1kHz
* 5 | 10Hz | 1kHz
* 6 | 5Hz | 1kHz
* 7 | Reserved | Reserved
*
* @return DLFP bandwidth setting
* @see ITG3200_RA_DLPF_FS
* @see ITG3200_DF_DLPF_CFG_BIT
* @see ITG3200_DF_DLPF_CFG_LENGTH
*/
uint8_t ITG3200::getDLPFBandwidth() {
I2Cdev::readBits(devAddr, ITG3200_RA_DLPF_FS, ITG3200_DF_DLPF_CFG_BIT, ITG3200_DF_DLPF_CFG_LENGTH, buffer);
return buffer[0];
}
/** Set digital low-pass filter bandwidth.
* @param bandwidth New DLFP bandwidth setting
* @see getDLPFBandwidth()
* @see ITG3200_DLPF_BW_256
* @see ITG3200_RA_DLPF_FS
* @see ITG3200_DF_DLPF_CFG_BIT
* @see ITG3200_DF_DLPF_CFG_LENGTH
*/
void ITG3200::setDLPFBandwidth(uint8_t bandwidth) {
I2Cdev::writeBits(devAddr, ITG3200_RA_DLPF_FS, ITG3200_DF_DLPF_CFG_BIT, ITG3200_DF_DLPF_CFG_LENGTH, bandwidth);
}
// INT_CFG register
/** Get interrupt logic level mode.
* Will be set 0 for active-high, 1 for active-low.
* @return Current interrupt mode (0=active-high, 1=active-low)
* @see ITG3200_RA_INT_CFG
* @see ITG3200_INTCFG_ACTL_BIT
*/
bool ITG3200::getInterruptMode() {
I2Cdev::readBit(devAddr, ITG3200_RA_INT_CFG, ITG3200_INTCFG_ACTL_BIT, buffer);
return buffer[0];
}
/** Set interrupt logic level mode.
* @param mode New interrupt mode (0=active-high, 1=active-low)
* @see getInterruptMode()
* @see ITG3200_RA_INT_CFG
* @see ITG3200_INTCFG_ACTL_BIT
*/
void ITG3200::setInterruptMode(bool mode) {
I2Cdev::writeBit(devAddr, ITG3200_RA_INT_CFG, ITG3200_INTCFG_ACTL_BIT, mode);
}
/** Get interrupt drive mode.
* Will be set 0 for push-pull, 1 for open-drain.
* @return Current interrupt drive mode (0=push-pull, 1=open-drain)
* @see ITG3200_RA_INT_CFG
* @see ITG3200_INTCFG_OPEN_BIT
*/
bool ITG3200::getInterruptDrive() {
I2Cdev::readBit(devAddr, ITG3200_RA_INT_CFG, ITG3200_INTCFG_OPEN_BIT, buffer);
return buffer[0];
}
/** Set interrupt drive mode.
* @param drive New interrupt drive mode (0=push-pull, 1=open-drain)
* @see getInterruptDrive()
* @see ITG3200_RA_INT_CFG
* @see ITG3200_INTCFG_OPEN_BIT
*/
void ITG3200::setInterruptDrive(bool drive) {
I2Cdev::writeBit(devAddr, ITG3200_RA_INT_CFG, ITG3200_INTCFG_OPEN_BIT, drive);
}
/** Get interrupt latch mode.
* Will be set 0 for 50us-pulse, 1 for latch-until-int-cleared.
* @return Current latch mode (0=50us-pulse, 1=latch-until-int-cleared)
* @see ITG3200_RA_INT_CFG
* @see ITG3200_INTCFG_LATCH_INT_EN_BIT
*/
bool ITG3200::getInterruptLatch() {
I2Cdev::readBit(devAddr, ITG3200_RA_INT_CFG, ITG3200_INTCFG_LATCH_INT_EN_BIT, buffer);
return buffer[0];
}
/** Set interrupt latch mode.
* @param latch New latch mode (0=50us-pulse, 1=latch-until-int-cleared)
* @see getInterruptLatch()
* @see ITG3200_RA_INT_CFG
* @see ITG3200_INTCFG_LATCH_INT_EN_BIT
*/
void ITG3200::setInterruptLatch(bool latch) {
I2Cdev::writeBit(devAddr, ITG3200_RA_INT_CFG, ITG3200_INTCFG_LATCH_INT_EN_BIT, latch);
}
/** Get interrupt latch clear mode.
* Will be set 0 for status-read-only, 1 for any-register-read.
* @return Current latch clear mode (0=status-read-only, 1=any-register-read)
* @see ITG3200_RA_INT_CFG
* @see ITG3200_INTCFG_INT_ANYRD_2CLEAR_BIT
*/
bool ITG3200::getInterruptLatchClear() {
I2Cdev::readBit(devAddr, ITG3200_RA_INT_CFG, ITG3200_INTCFG_INT_ANYRD_2CLEAR_BIT, buffer);
return buffer[0];
}
/** Set interrupt latch clear mode.
* @param clear New latch clear mode (0=status-read-only, 1=any-register-read)
* @see getInterruptLatchClear()
* @see ITG3200_RA_INT_CFG
* @see ITG3200_INTCFG_INT_ANYRD_2CLEAR_BIT
*/
void ITG3200::setInterruptLatchClear(bool clear) {
I2Cdev::writeBit(devAddr, ITG3200_RA_INT_CFG, ITG3200_INTCFG_INT_ANYRD_2CLEAR_BIT, clear);
}
/** Get "device ready" interrupt enabled setting.
* Will be set 0 for disabled, 1 for enabled.
* @return Current interrupt enabled setting
* @see ITG3200_RA_INT_CFG
* @see ITG3200_INTCFG_ITG_RDY_EN_BIT
*/
bool ITG3200::getIntDeviceReadyEnabled() {
I2Cdev::readBit(devAddr, ITG3200_RA_INT_CFG, ITG3200_INTCFG_ITG_RDY_EN_BIT, buffer);
return buffer[0];
}
/** Set "device ready" interrupt enabled setting.
* @param enabled New interrupt enabled setting
* @see getIntDeviceReadyEnabled()
* @see ITG3200_RA_INT_CFG
* @see ITG3200_INTCFG_ITG_RDY_EN_BIT
*/
void ITG3200::setIntDeviceReadyEnabled(bool enabled) {
I2Cdev::writeBit(devAddr, ITG3200_RA_INT_CFG, ITG3200_INTCFG_ITG_RDY_EN_BIT, enabled);
}
/** Get "data ready" interrupt enabled setting.
* Will be set 0 for disabled, 1 for enabled.
* @return Current interrupt enabled setting
* @see ITG3200_RA_INT_CFG
* @see ITG3200_INTCFG_RAW_RDY_EN_BIT
*/
bool ITG3200::getIntDataReadyEnabled() {
I2Cdev::readBit(devAddr, ITG3200_RA_INT_CFG, ITG3200_INTCFG_RAW_RDY_EN_BIT, buffer);
return buffer[0];
}
/** Set "data ready" interrupt enabled setting.
* @param enabled New interrupt enabled setting
* @see getIntDataReadyEnabled()
* @see ITG3200_RA_INT_CFG
* @see ITG3200_INTCFG_RAW_RDY_EN_BIT
*/
void ITG3200::setIntDataReadyEnabled(bool enabled) {
I2Cdev::writeBit(devAddr, ITG3200_RA_INT_CFG, ITG3200_INTCFG_RAW_RDY_EN_BIT, enabled);
}
// INT_STATUS register
/** Get Device Ready interrupt status.
* The ITG_RDY interrupt indicates that the PLL is ready and gyroscopic data can
* be read.
* @return Device Ready interrupt status
* @see ITG3200_RA_INT_STATUS
* @see ITG3200_INTSTAT_RAW_DATA_READY_BIT
*/
bool ITG3200::getIntDeviceReadyStatus() {
I2Cdev::readBit(devAddr, ITG3200_RA_INT_STATUS, ITG3200_INTSTAT_ITG_RDY_BIT, buffer);
return buffer[0];
}
/** Get Data Ready interrupt status.
* In normal use, the RAW_DATA_RDY interrupt is used to determine when new
* sensor data is available in and of the sensor registers (27 to 32).
* @return Data Ready interrupt status
* @see ITG3200_RA_INT_STATUS
* @see ITG3200_INTSTAT_RAW_DATA_READY_BIT
*/
bool ITG3200::getIntDataReadyStatus() {
I2Cdev::readBit(devAddr, ITG3200_RA_INT_STATUS, ITG3200_INTSTAT_RAW_DATA_READY_BIT, buffer);
return buffer[0];
}
// TEMP_OUT_* registers
/** Get current internal temperature.
* @return Temperature reading in 16-bit 2's complement format
* @see ITG3200_RA_TEMP_OUT_H
*/
int16_t ITG3200::getTemperature() {
I2Cdev::readBytes(devAddr, ITG3200_RA_TEMP_OUT_H, 2, buffer);
return (((int16_t)buffer[0]) << 8) | buffer[1];
}
// GYRO_*OUT_* registers
/** Get 3-axis gyroscope readings.
* @param x 16-bit signed integer container for X-axis rotation
* @param y 16-bit signed integer container for Y-axis rotation
* @param z 16-bit signed integer container for Z-axis rotation
* @see ITG3200_RA_GYRO_XOUT_H
*/
void ITG3200::getRotation(int16_t* x, int16_t* y, int16_t* z) {
I2Cdev::readBytes(devAddr, ITG3200_RA_GYRO_XOUT_H, 6, buffer);
*x = (((int16_t)buffer[0]) << 8) | buffer[1];
*y = (((int16_t)buffer[2]) << 8) | buffer[3];
*z = (((int16_t)buffer[4]) << 8) | buffer[5];
}
/** Get X-axis gyroscope reading.
* @return X-axis rotation measurement in 16-bit 2's complement format
* @see ITG3200_RA_GYRO_XOUT_H
*/
int16_t ITG3200::getRotationX() {
I2Cdev::readBytes(devAddr, ITG3200_RA_GYRO_XOUT_H, 2, buffer);
return (((int16_t)buffer[0]) << 8) | buffer[1];
}
/** Get Y-axis gyroscope reading.
* @return Y-axis rotation measurement in 16-bit 2's complement format
* @see ITG3200_RA_GYRO_YOUT_H
*/
int16_t ITG3200::getRotationY() {
I2Cdev::readBytes(devAddr, ITG3200_RA_GYRO_YOUT_H, 2, buffer);
return (((int16_t)buffer[0]) << 8) | buffer[1];
}
/** Get Z-axis gyroscope reading.
* @return Z-axis rotation measurement in 16-bit 2's complement format
* @see ITG3200_RA_GYRO_ZOUT_H
*/
int16_t ITG3200::getRotationZ() {
I2Cdev::readBytes(devAddr, ITG3200_RA_GYRO_ZOUT_H, 2, buffer);
return (((int16_t)buffer[0]) << 8) | buffer[1];
}
// PWR_MGM register
/** Trigger a full device reset.
* A small delay of ~50ms may be desirable after triggering a reset.
* @see ITG3200_RA_PWR_MGM
* @see ITG3200_PWR_H_RESET_BIT
*/
void ITG3200::reset() {
I2Cdev::writeBit(devAddr, ITG3200_RA_PWR_MGM, ITG3200_PWR_H_RESET_BIT, true);
}
/** Get sleep mode status.
* Setting the SLEEP bit in the register puts the device into very low power
* sleep mode. In this mode, only the serial interface and internal registers
* remain active, allowing for a very low standby current. Clearing this bit
* puts the device back into normal mode. To save power, the individual standby
* selections for each of the gyros should be used if any gyro axis is not used
* by the application.
* @return Current sleep mode enabled status
* @see ITG3200_RA_PWR_MGM
* @see ITG3200_PWR_SLEEP_BIT
*/
bool ITG3200::getSleepEnabled() {
I2Cdev::readBit(devAddr, ITG3200_RA_PWR_MGM, ITG3200_PWR_SLEEP_BIT, buffer);
return buffer[0];
}
/** Set sleep mode status.
* @param enabled New sleep mode enabled status
* @see getSleepEnabled()
* @see ITG3200_RA_PWR_MGM
* @see ITG3200_PWR_SLEEP_BIT
*/
void ITG3200::setSleepEnabled(bool enabled) {
I2Cdev::writeBit(devAddr, ITG3200_RA_PWR_MGM, ITG3200_PWR_SLEEP_BIT, enabled);
}
/** Get X-axis standby enabled status.
* If enabled, the X-axis will not gather or report data (or use power).
* @return Current X-axis standby enabled status
* @see ITG3200_RA_PWR_MGM
* @see ITG3200_PWR_STBY_XG_BIT
*/
bool ITG3200::getStandbyXEnabled() {
I2Cdev::readBit(devAddr, ITG3200_RA_PWR_MGM, ITG3200_PWR_STBY_XG_BIT, buffer);
return buffer[0];
}
/** Set X-axis standby enabled status.
* @param New X-axis standby enabled status
* @see getStandbyXEnabled()
* @see ITG3200_RA_PWR_MGM
* @see ITG3200_PWR_STBY_XG_BIT
*/
void ITG3200::setStandbyXEnabled(bool enabled) {
I2Cdev::writeBit(devAddr, ITG3200_RA_PWR_MGM, ITG3200_PWR_STBY_XG_BIT, enabled);
}
/** Get Y-axis standby enabled status.
* If enabled, the Y-axis will not gather or report data (or use power).
* @return Current Y-axis standby enabled status
* @see ITG3200_RA_PWR_MGM
* @see ITG3200_PWR_STBY_YG_BIT
*/
bool ITG3200::getStandbyYEnabled() {
I2Cdev::readBit(devAddr, ITG3200_RA_PWR_MGM, ITG3200_PWR_STBY_YG_BIT, buffer);
return buffer[0];
}
/** Set Y-axis standby enabled status.
* @param New Y-axis standby enabled status
* @see getStandbyYEnabled()
* @see ITG3200_RA_PWR_MGM
* @see ITG3200_PWR_STBY_YG_BIT
*/
void ITG3200::setStandbyYEnabled(bool enabled) {
I2Cdev::writeBit(devAddr, ITG3200_RA_PWR_MGM, ITG3200_PWR_STBY_YG_BIT, enabled);
}
/** Get Z-axis standby enabled status.
* If enabled, the Z-axis will not gather or report data (or use power).
* @return Current Z-axis standby enabled status
* @see ITG3200_RA_PWR_MGM
* @see ITG3200_PWR_STBY_ZG_BIT
*/
bool ITG3200::getStandbyZEnabled() {
I2Cdev::readBit(devAddr, ITG3200_RA_PWR_MGM, ITG3200_PWR_STBY_ZG_BIT, buffer);
return buffer[0];
}
/** Set Z-axis standby enabled status.
* @param New Z-axis standby enabled status
* @see getStandbyZEnabled()
* @see ITG3200_RA_PWR_MGM
* @see ITG3200_PWR_STBY_ZG_BIT
*/
void ITG3200::setStandbyZEnabled(bool enabled) {
I2Cdev::writeBit(devAddr, ITG3200_RA_PWR_MGM, ITG3200_PWR_STBY_ZG_BIT, enabled);
}
/** Get clock source setting.
* @return Current clock source setting
* @see ITG3200_RA_PWR_MGM
* @see ITG3200_PWR_CLK_SEL_BIT
* @see ITG3200_PWR_CLK_SEL_LENGTH
*/
uint8_t ITG3200::getClockSource() {
I2Cdev::readBits(devAddr, ITG3200_RA_PWR_MGM, ITG3200_PWR_CLK_SEL_BIT, ITG3200_PWR_CLK_SEL_LENGTH, buffer);
return buffer[0];
}
/** Set clock source setting.
* On power up, the ITG-3200 defaults to the internal oscillator. It is highly recommended that the device is configured to use one of the gyros (or an external clock) as the clock reference, due to the improved stability.
*
* The CLK_SEL setting determines the device clock source as follows:
*
* CLK_SEL | Clock Source
* --------+--------------------------------------
* 0 | Internal oscillator
* 1 | PLL with X Gyro reference
* 2 | PLL with Y Gyro reference
* 3 | PLL with Z Gyro reference
* 4 | PLL with external 32.768kHz reference
* 5 | PLL with external 19.2MHz reference
* 6 | Reserved
* 7 | Reserved
*
* @param source New clock source setting
* @see getClockSource()
* @see ITG3200_RA_PWR_MGM
* @see ITG3200_PWR_CLK_SEL_BIT
* @see ITG3200_PWR_CLK_SEL_LENGTH
*/
void ITG3200::setClockSource(uint8_t source) {
I2Cdev::writeBits(devAddr, ITG3200_RA_PWR_MGM, ITG3200_PWR_CLK_SEL_BIT, ITG3200_PWR_CLK_SEL_LENGTH, source);
}