32 #include <mraa/i2c.hpp>
34 #define L3GD20_DEFAULT_I2C_BUS 0
36 #define L3GD20_DEFAULT_I2C_ADDR 0x6a
37 #define L3GD20_DEFAULT_CHIP_ID 0xd4
39 #define L3GD20H_DEFAULT_CHIP_ID 0xd7
80 float bias_x, bias_y, bias_z;
82 float min_x, min_y, min_z;
83 float max_x, max_y, max_z;
90 unsigned int sample_size;
109 REG_CTRL_REG1 = 0x20,
110 REG_CTRL_REG2 = 0x21,
111 REG_CTRL_REG3 = 0x22,
112 REG_CTRL_REG4 = 0x23,
113 REG_CTRL_REG5 = 0x24,
115 REG_REFERENCE = 0x25,
117 REG_OUT_TEMPERATURE = 0x26,
119 REG_STATUS_REG = 0x27,
131 REG_FIFO_CTRL_REG = 0x2e,
132 REG_FIFO_SRC_REG = 0x2f,
137 REG_INT1_TSH_XH = 0x32,
138 REG_INT1_TSH_XL = 0x33,
140 REG_INT1_TSH_YH = 0x34,
141 REG_INT1_TSH_YL = 0x35,
143 REG_INT1_TSH_ZH = 0x36,
144 REG_INT1_TSH_ZL = 0x37,
145 REG_INT1_DURATION = 0x38
152 CTRL_REG1_YEN = 0x01,
153 CTRL_REG1_XEN = 0x02,
154 CTRL_REG1_ZEN = 0x04,
157 CTRL_REG1_BW0 = 0x10,
158 CTRL_REG1_BW1 = 0x20,
159 _CTRL_REG1_BW_MASK = 3,
160 _CTRL_REG1_BW_SHIFT = 4,
162 CTRL_REG1_DR0 = 0x40,
163 CTRL_REG1_DR1 = 0x80,
164 _CTRL_REG1_DR_MASK = 3,
165 _CTRL_REG1_DR_SHIFT = 6,
170 _CTRL_REG1_ODR_CUTOFF0 = 0x10,
171 _CTRL_REG1_ODR_CUTOFF1 = 0x20,
172 _CTRL_REG1_ODR_CUTOFF2 = 0x40,
173 _CTRL_REG1_ODR_CUTOFF3 = 0x80,
174 _CTRL_REG1_ODR_CUTOFF_MASK = 15,
175 _CTRL_REG1_ODR_CUTOFF_SHIFT = 4
183 ODR_CUTOFF_95_12_5 = 0,
184 ODR_CUTOFF_95_25 = 1,
187 ODR_CUTOFF_190_12_5 = 4,
188 ODR_CUTOFF_190_25 = 5,
189 ODR_CUTOFF_190_50 = 6,
190 ODR_CUTOFF_190_70 = 7,
192 ODR_CUTOFF_380_20 = 8,
193 ODR_CUTOFF_380_25 = 9,
194 ODR_CUTOFF_380_50 = 10,
195 ODR_CUTOFF_380_100 = 11,
197 ODR_CUTOFF_760_30 = 12,
198 ODR_CUTOFF_760_35 = 13,
199 ODR_CUTOFF_760_50 = 14,
200 ODR_CUTOFF_760_100 = 15
217 _CTRL_REG2_RESERVED_BITS = 0x40 | 0x80,
219 CTRL_REG2_HPCF0 = 0x01,
220 CTRL_REG2_HPCF1 = 0x02,
221 CTRL_REG2_HPCF2 = 0x04,
222 CTRL_REG2_HPCF3 = 0x08,
223 _CTRL_REG2_HPCF_MASK = 15,
224 _CTRL_REG2_HPCF_SHIFT = 0,
226 CTRL_REG2_HPM0 = 0x10,
227 CTRL_REG2_HPM1 = 0x20,
228 _CTRL_REG2_HPM_MASK = 3,
229 _CTRL_REG2_HPM_SHIFT = 4
255 HPM_NORMAL_RESET_FILTER = 0,
256 HPM_REFERENCE_SIGNAL = 1,
258 HPM_AUTORESET_ON_INT = 3
265 CTRL_REG3_I2_EMPTY = 0x01,
266 CTRL_REG3_I2_ORUN = 0x02,
267 CTRL_REG3_I2_WTM = 0x04,
268 CTRL_REG3_I2_DRDY = 0x08,
269 CTRL_REG3_PP_OD = 0x10,
270 CTRL_REG3_H_LACTIVE = 0x20,
271 CTRL_REG3_I1_BOOT = 0x40,
272 CTRL_REG3_I1_INT1 = 0x80
279 _CTRL_REG4_RESERVED_BITS = 0x02 | 0x04 | 0x08,
281 CTRL_REG4_SIM = 0x01,
284 CTRL_REG4_FS0 = 0x10,
285 CTRL_REG4_FS1 = 0x20,
286 _CTRL_REG4_FS_MASK = 3,
287 _CTRL_REG4_FS_SHIFT = 4,
289 CTRL_REG4_BLE = 0x40,
306 _CTRL_REG5_RESERVED_BITS = 0x20,
308 CTRL_REG5_OUT_SEL0 = 0x01,
309 CTRL_REG5_OUT_SEL1 = 0x02,
310 _CTRL_REG5_OUT_SEL_MASK = 3,
311 _CTRL_REG5_OUT_SEL_SHIFT = 0,
313 CTRL_REG5_INT1_SEL0 = 0x04,
314 CTRL_REG5_INT1_SEL1 = 0x08,
315 _CTRL_REG5_INT1_SEL_MASK = 3,
316 _CTRL_REG5_INT1_SEL_SHIFT = 2,
318 CTRL_REG5_HPEN = 0x10,
321 CTRL_REG5_FIFO_EN = 0x40,
322 CTRL_REG5_BOOT = 0x80
329 STATUS_REG_XDA = 0x01,
330 STATUS_REG_YDA = 0x02,
331 STATUS_REG_ZDA = 0x04,
332 STATUS_REG_ZYXDA = 0x08,
334 STATUS_REG_XOR = 0x10,
335 STATUS_REG_YOR = 0x20,
336 STATUS_REG_ZOR = 0x40,
337 STATUS_REG_ZYXOR = 0x80
344 FIFO_CTRL_REG_WTM0 = 0x01,
345 FIFO_CTRL_REG_WTM1 = 0x02,
346 FIFO_CTRL_REG_WTM2 = 0x04,
347 FIFO_CTRL_REG_WTM3 = 0x08,
348 FIFO_CTRL_REG_WTM4 = 0x10,
349 _FIFO_CTRL_REG_WTM_MASK = 31,
350 _FIFO_CTRL_REG_WTM_SHIFT = 0,
352 FIFO_CTRL_REG_FM0 = 0x20,
353 FIFO_CTRL_REG_FM1 = 0x40,
354 FIFO_CTRL_REG_FM2 = 0x80,
355 _FIFO_CTRL_REG_FM_MASK = 7,
356 _FIFO_CTRL_REG_FM_SHIFT = 5
363 FIFO_MODE_BYPASS = 0,
365 FIFO_MODE_STREAM = 2,
366 FIFO_MODE_STREAM_TO_FIFO = 3,
367 FIFO_MODE_BYPASS_TO_STREAM = 4
375 FIFO_SRC_REG_FSS0 = 0x01,
376 FIFO_SRC_REG_FSS1 = 0x02,
377 FIFO_SRC_REG_FSS2 = 0x04,
378 FIFO_SRC_REG_FSS3 = 0x08,
379 FIFO_SRC_REG_FSS4 = 0x10,
380 _FIFO_SRC_REG_FSS_MASK = 31,
381 _FIFO_SRC_REG_FSS_SHIFT = 0,
383 FIFO_SRC_REG_EMPTY = 0x20,
384 FIFO_SRC_REG_OVRN = 0x40,
385 FIFO_SRC_REG_WTM = 0x80
392 INT1_CFG_XLIE = 0x01,
393 INT1_CFG_XHIE = 0x02,
395 INT1_CFG_YLIE = 0x04,
396 INT1_CFG_YHIE = 0x08,
398 INT1_CFG_ZLIE = 0x10,
399 INT1_CFG_ZHIE = 0x20,
402 INT1_CFG_AND_OR = 0x80
409 _INT1_SRC_RESERVED_BITS = 0x80,
429 INT1_DURATION_D0 = 0x01,
430 INT1_DURATION_D1 = 0x02,
431 INT1_DURATION_D2 = 0x04,
432 INT1_DURATION_D3 = 0x08,
433 INT1_DURATION_D4 = 0x10,
434 INT1_DURATION_D5 = 0x20,
435 INT1_DURATION_D6 = 0x40,
437 INT1_DURATION_WAIT = 0x80
454 L3GD20(
int bus,
int addr);
550 void installISR(
void (*isr)(
char*),
void* arg);
604 bool extract3Axis(
char* data,
float* x,
float* y,
float* z);
641 int readRegs(uint8_t reg, uint8_t *buffer,
int len);
649 void writeReg(uint8_t reg, uint8_t val);
672 float median(
float* queue,
unsigned int size);
682 partition(
float* list,
unsigned int left,
unsigned int right,
unsigned int pivot_index);
701 mraa_iio_context m_iio;
703 int m_iio_device_num;
704 bool m_mount_matrix_exist;
705 float m_mount_matrix[9];
709 gyro_cal_t m_cal_data;
710 filter_median_t m_filter;
uint8_t getStatusBits()
Definition: l3gd20.cxx:340
int64_t getChannelValue(unsigned char *input, mraa_iio_channel *chan)
Definition: l3gd20.cxx:353
ODR_CUTOFF_T
Definition: l3gd20.hpp:182
void writeReg(uint8_t reg, uint8_t val)
Definition: l3gd20.cxx:183
void update()
Definition: l3gd20.cxx:276
void initCalibrate()
Definition: l3gd20.cxx:504
~L3GD20()
Definition: l3gd20.cxx:162
bool setSamplingFrequency(const float sampling_frequency)
Definition: l3gd20.cxx:432
bool disableBuffer()
Definition: l3gd20.cxx:414
L3GD20(int device)
Definition: l3gd20.cxx:49
int readRegs(uint8_t reg, uint8_t *buffer, int len)
Definition: l3gd20.cxx:177
uint8_t readReg(uint8_t reg)
Definition: l3gd20.cxx:172
void setODR(ODR_CUTOFF_T odr)
Definition: l3gd20.cxx:330
bool enableBuffer(int length)
Definition: l3gd20.cxx:405
L3GD20_REGS_T
Definition: l3gd20.hpp:102
STATUS_REG_BITS_T
Definition: l3gd20.hpp:328
bool setScale(const float scale)
Definition: l3gd20.cxx:421
void gyroDenoiseMedian(float *x, float *y, float *z)
Definition: l3gd20.cxx:596
uint8_t getChipID()
Definition: l3gd20.cxx:192
bool getCalibratedStatus()
Definition: l3gd20.cxx:514
CTRL_REG3_BITS_T
Definition: l3gd20.hpp:264
float getTemperature(bool fahrenheit=false)
Definition: l3gd20.cxx:322
void enableBDU(bool enable)
Definition: l3gd20.cxx:252
INT1_CFG_BITS_T
Definition: l3gd20.hpp:391
FS_T
Definition: l3gd20.hpp:296
void getCalibratedData(float *bias_x, float *bias_y, float *bias_z)
Definition: l3gd20.cxx:520
void setRange(FS_T range)
Definition: l3gd20.cxx:226
HPM_T
Definition: l3gd20.hpp:254
Definition: l3gd20.hpp:79
FIFO_MODE_T
Definition: l3gd20.hpp:362
float median(float *queue, unsigned int size)
Definition: l3gd20.cxx:626
void setPowerMode(POWER_MODES_T mode)
Definition: l3gd20.cxx:197
void loadCalibratedData(float bias_x, float bias_y, float bias_z)
Definition: l3gd20.cxx:528
POWER_MODES_T
Definition: l3gd20.hpp:207
FIFO_SRC_BITS_T
Definition: l3gd20.hpp:374
bool gyroCollect(float x, float y, float z)
Definition: l3gd20.cxx:537
bool extract3Axis(char *data, float *x, float *y, float *z)
Definition: l3gd20.cxx:455
bool enable3AxisChannel()
Definition: l3gd20.cxx:439
FIFO_CTRL_REG_BITS_T
Definition: l3gd20.hpp:343
void clampGyroReadingsToZero(float *x, float *y, float *z)
Definition: l3gd20.cxx:687
CTRL_REG2_BITS_T
Definition: l3gd20.hpp:216
unsigned int partition(float *list, unsigned int left, unsigned int right, unsigned int pivot_index)
Definition: l3gd20.cxx:657
CTRL_REG4_BITS_T
Definition: l3gd20.hpp:278
L3GD20 Tri-axis Digital Gyroscope API.
Definition: l3gd20.hpp:76
HPCF_T
Definition: l3gd20.hpp:238
void installISR(void(*isr)(char *), void *arg)
Definition: l3gd20.cxx:347
INT1_DURATION_BITS_T
Definition: l3gd20.hpp:428
CTRL_REG5_BITS_T
Definition: l3gd20.hpp:305
void getGyroscope(float *x, float *y, float *z)
Definition: l3gd20.cxx:264
INT1_SRC_BITS_T
Definition: l3gd20.hpp:408
CTRL_REG1_BITS_T
Definition: l3gd20.hpp:151