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 81 float bias_x, bias_y, bias_z;
83 float min_x, min_y, min_z;
84 float max_x, max_y, max_z;
91 unsigned int sample_size;
110 REG_CTRL_REG1 = 0x20,
111 REG_CTRL_REG2 = 0x21,
112 REG_CTRL_REG3 = 0x22,
113 REG_CTRL_REG4 = 0x23,
114 REG_CTRL_REG5 = 0x24,
116 REG_REFERENCE = 0x25,
118 REG_OUT_TEMPERATURE = 0x26,
120 REG_STATUS_REG = 0x27,
132 REG_FIFO_CTRL_REG = 0x2e,
133 REG_FIFO_SRC_REG = 0x2f,
138 REG_INT1_TSH_XH = 0x32,
139 REG_INT1_TSH_XL = 0x33,
141 REG_INT1_TSH_YH = 0x34,
142 REG_INT1_TSH_YL = 0x35,
144 REG_INT1_TSH_ZH = 0x36,
145 REG_INT1_TSH_ZL = 0x37,
146 REG_INT1_DURATION = 0x38
153 CTRL_REG1_YEN = 0x01,
154 CTRL_REG1_XEN = 0x02,
155 CTRL_REG1_ZEN = 0x04,
158 CTRL_REG1_BW0 = 0x10,
159 CTRL_REG1_BW1 = 0x20,
160 _CTRL_REG1_BW_MASK = 3,
161 _CTRL_REG1_BW_SHIFT = 4,
163 CTRL_REG1_DR0 = 0x40,
164 CTRL_REG1_DR1 = 0x80,
165 _CTRL_REG1_DR_MASK = 3,
166 _CTRL_REG1_DR_SHIFT = 6,
171 _CTRL_REG1_ODR_CUTOFF0 = 0x10,
172 _CTRL_REG1_ODR_CUTOFF1 = 0x20,
173 _CTRL_REG1_ODR_CUTOFF2 = 0x40,
174 _CTRL_REG1_ODR_CUTOFF3 = 0x80,
175 _CTRL_REG1_ODR_CUTOFF_MASK = 15,
176 _CTRL_REG1_ODR_CUTOFF_SHIFT = 4
184 ODR_CUTOFF_95_12_5 = 0,
185 ODR_CUTOFF_95_25 = 1,
188 ODR_CUTOFF_190_12_5 = 4,
189 ODR_CUTOFF_190_25 = 5,
190 ODR_CUTOFF_190_50 = 6,
191 ODR_CUTOFF_190_70 = 7,
193 ODR_CUTOFF_380_20 = 8,
194 ODR_CUTOFF_380_25 = 9,
195 ODR_CUTOFF_380_50 = 10,
196 ODR_CUTOFF_380_100 = 11,
198 ODR_CUTOFF_760_30 = 12,
199 ODR_CUTOFF_760_35 = 13,
200 ODR_CUTOFF_760_50 = 14,
201 ODR_CUTOFF_760_100 = 15
218 _CTRL_REG2_RESERVED_BITS = 0x40 | 0x80,
220 CTRL_REG2_HPCF0 = 0x01,
221 CTRL_REG2_HPCF1 = 0x02,
222 CTRL_REG2_HPCF2 = 0x04,
223 CTRL_REG2_HPCF3 = 0x08,
224 _CTRL_REG2_HPCF_MASK = 15,
225 _CTRL_REG2_HPCF_SHIFT = 0,
227 CTRL_REG2_HPM0 = 0x10,
228 CTRL_REG2_HPM1 = 0x20,
229 _CTRL_REG2_HPM_MASK = 3,
230 _CTRL_REG2_HPM_SHIFT = 4
256 HPM_NORMAL_RESET_FILTER = 0,
257 HPM_REFERENCE_SIGNAL = 1,
259 HPM_AUTORESET_ON_INT = 3
266 CTRL_REG3_I2_EMPTY = 0x01,
267 CTRL_REG3_I2_ORUN = 0x02,
268 CTRL_REG3_I2_WTM = 0x04,
269 CTRL_REG3_I2_DRDY = 0x08,
270 CTRL_REG3_PP_OD = 0x10,
271 CTRL_REG3_H_LACTIVE = 0x20,
272 CTRL_REG3_I1_BOOT = 0x40,
273 CTRL_REG3_I1_INT1 = 0x80
280 _CTRL_REG4_RESERVED_BITS = 0x02 | 0x04 | 0x08,
282 CTRL_REG4_SIM = 0x01,
285 CTRL_REG4_FS0 = 0x10,
286 CTRL_REG4_FS1 = 0x20,
287 _CTRL_REG4_FS_MASK = 3,
288 _CTRL_REG4_FS_SHIFT = 4,
290 CTRL_REG4_BLE = 0x40,
307 _CTRL_REG5_RESERVED_BITS = 0x20,
309 CTRL_REG5_OUT_SEL0 = 0x01,
310 CTRL_REG5_OUT_SEL1 = 0x02,
311 _CTRL_REG5_OUT_SEL_MASK = 3,
312 _CTRL_REG5_OUT_SEL_SHIFT = 0,
314 CTRL_REG5_INT1_SEL0 = 0x04,
315 CTRL_REG5_INT1_SEL1 = 0x08,
316 _CTRL_REG5_INT1_SEL_MASK = 3,
317 _CTRL_REG5_INT1_SEL_SHIFT = 2,
319 CTRL_REG5_HPEN = 0x10,
322 CTRL_REG5_FIFO_EN = 0x40,
323 CTRL_REG5_BOOT = 0x80
330 STATUS_REG_XDA = 0x01,
331 STATUS_REG_YDA = 0x02,
332 STATUS_REG_ZDA = 0x04,
333 STATUS_REG_ZYXDA = 0x08,
335 STATUS_REG_XOR = 0x10,
336 STATUS_REG_YOR = 0x20,
337 STATUS_REG_ZOR = 0x40,
338 STATUS_REG_ZYXOR = 0x80
345 FIFO_CTRL_REG_WTM0 = 0x01,
346 FIFO_CTRL_REG_WTM1 = 0x02,
347 FIFO_CTRL_REG_WTM2 = 0x04,
348 FIFO_CTRL_REG_WTM3 = 0x08,
349 FIFO_CTRL_REG_WTM4 = 0x10,
350 _FIFO_CTRL_REG_WTM_MASK = 31,
351 _FIFO_CTRL_REG_WTM_SHIFT = 0,
353 FIFO_CTRL_REG_FM0 = 0x20,
354 FIFO_CTRL_REG_FM1 = 0x40,
355 FIFO_CTRL_REG_FM2 = 0x80,
356 _FIFO_CTRL_REG_FM_MASK = 7,
357 _FIFO_CTRL_REG_FM_SHIFT = 5
364 FIFO_MODE_BYPASS = 0,
366 FIFO_MODE_STREAM = 2,
367 FIFO_MODE_STREAM_TO_FIFO = 3,
368 FIFO_MODE_BYPASS_TO_STREAM = 4
376 FIFO_SRC_REG_FSS0 = 0x01,
377 FIFO_SRC_REG_FSS1 = 0x02,
378 FIFO_SRC_REG_FSS2 = 0x04,
379 FIFO_SRC_REG_FSS3 = 0x08,
380 FIFO_SRC_REG_FSS4 = 0x10,
381 _FIFO_SRC_REG_FSS_MASK = 31,
382 _FIFO_SRC_REG_FSS_SHIFT = 0,
384 FIFO_SRC_REG_EMPTY = 0x20,
385 FIFO_SRC_REG_OVRN = 0x40,
386 FIFO_SRC_REG_WTM = 0x80
393 INT1_CFG_XLIE = 0x01,
394 INT1_CFG_XHIE = 0x02,
396 INT1_CFG_YLIE = 0x04,
397 INT1_CFG_YHIE = 0x08,
399 INT1_CFG_ZLIE = 0x10,
400 INT1_CFG_ZHIE = 0x20,
403 INT1_CFG_AND_OR = 0x80
410 _INT1_SRC_RESERVED_BITS = 0x80,
430 INT1_DURATION_D0 = 0x01,
431 INT1_DURATION_D1 = 0x02,
432 INT1_DURATION_D2 = 0x04,
433 INT1_DURATION_D3 = 0x08,
434 INT1_DURATION_D4 = 0x10,
435 INT1_DURATION_D5 = 0x20,
436 INT1_DURATION_D6 = 0x40,
438 INT1_DURATION_WAIT = 0x80
455 L3GD20(
int bus,
int addr);
550 void installISR(
void (*isr)(
char*,
void*),
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];
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:183
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:103
STATUS_REG_BITS_T
Definition: l3gd20.hpp:329
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
C++ API wrapper for the bh1749 driver.
Definition: a110x.hpp:29
bool getCalibratedStatus()
Definition: l3gd20.cxx:514
CTRL_REG3_BITS_T
Definition: l3gd20.hpp:265
float getTemperature(bool fahrenheit=false)
Definition: l3gd20.cxx:322
void enableBDU(bool enable)
Definition: l3gd20.cxx:252
INT1_CFG_BITS_T
Definition: l3gd20.hpp:392
FS_T
Definition: l3gd20.hpp:297
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:255
Definition: l3gd20.hpp:80
FIFO_MODE_T
Definition: l3gd20.hpp:363
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:208
FIFO_SRC_BITS_T
Definition: l3gd20.hpp:375
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:344
void clampGyroReadingsToZero(float *x, float *y, float *z)
Definition: l3gd20.cxx:687
CTRL_REG2_BITS_T
Definition: l3gd20.hpp:217
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:279
void installISR(void(*isr)(char *, void *), void *arg)
Definition: l3gd20.cxx:347
L3GD20 Tri-axis Digital Gyroscope API.
Definition: l3gd20.hpp:77
HPCF_T
Definition: l3gd20.hpp:239
INT1_DURATION_BITS_T
Definition: l3gd20.hpp:429
CTRL_REG5_BITS_T
Definition: l3gd20.hpp:306
void getGyroscope(float *x, float *y, float *z)
Definition: l3gd20.cxx:264
INT1_SRC_BITS_T
Definition: l3gd20.hpp:409
CTRL_REG1_BITS_T
Definition: l3gd20.hpp:152