qmc5883l.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2019 Freie Universit├Ąt Berlin
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
55 #ifndef QMC5883L_H
56 #define QMC5883L_H
57 
58 #ifdef __cplusplus
59 extern "C"
60 {
61 #endif
62 
63 #include <stdint.h>
64 
65 #include "periph/gpio.h"
66 #include "periph/i2c.h"
67 
71 #define QMC5883L_ADDR (0x0d)
72 
76 enum {
82 };
83 
93 typedef enum {
94  QMC5883L_ODR_10HZ = (0u << 2),
95  QMC5883L_ODR_50HZ = (1u << 2),
96  QMC5883L_ODR_100HZ = (2u << 2),
97  QMC5883L_ODR_200HZ = (3u << 2),
99 
110 typedef enum {
111  QMC5883L_RNG_2G = (0u << 4),
112  QMC5883L_RNG_8G = (1u << 4),
114 
124 typedef enum {
125  QMC5883L_OSR_512 = (0u << 6),
126  QMC5883L_OSR_256 = (1u << 6),
127  QMC5883L_OSR_128 = (2u << 6),
128  QMC5883L_OSR_64 = (3u << 6),
130 
134 typedef struct {
136  gpio_t pin_drdy;
141 
145 typedef struct {
147  gpio_t pin_drdy;
148  uint8_t cfg;
149 } qmc5883l_t;
150 
164 int qmc5883l_init(qmc5883l_t *dev, const qmc5883l_params_t *params);
165 
177 int qmc5883l_data_ready(const qmc5883l_t *dev);
178 
196 int qmc5883l_read(const qmc5883l_t *dev, int16_t *data_out);
197 
218 int qmc5883l_read_raw(const qmc5883l_t *dev, int16_t *data_out);
219 
230 int qmc5883l_poweron(const qmc5883l_t *dev);
231 
242 int qmc5883l_poweroff(const qmc5883l_t *dev);
243 
244 #if defined(MODULE_QMC5883L_INT) || defined(DOXYGEN)
245 
273 int qmc5883l_init_int(const qmc5883l_t *dev, gpio_cb_t cb, void *arg);
274 
287 int qmc5883l_irq_enable(const qmc5883l_t *dev);
288 
299 int qmc5883l_irq_disable(const qmc5883l_t *dev);
300 #endif /* defined(MODULE_QMC5883L_INT) || defined(DOXYGEN) */
301 
302 #ifdef __cplusplus
303 }
304 #endif
305 
306 #endif /* QMC5883L_H */
307 
int qmc5883l_init(qmc5883l_t *dev, const qmc5883l_params_t *params)
Initialize the given QMC5883L magnetic sensor.
int qmc5883l_poweron(const qmc5883l_t *dev)
Power on the sensor (put it into continuous sampling mode)
128 samples per reading
Definition: qmc5883l.h:127
int qmc5883l_irq_enable(const qmc5883l_t *dev)
Enable the data ready (DRDY) interrupt.
gpio_t pin_drdy
DRDY interrupt pin.
Definition: qmc5883l.h:147
i2c_t i2c
I2C bus the sensor is connected to.
Definition: qmc5883l.h:146
Low-level GPIO peripheral driver interface definitions.
qmc5883l_rng_t
Output value range.
Definition: qmc5883l.h:110
int qmc5883l_read(const qmc5883l_t *dev, int16_t *data_out)
Read sampled data from the device [converted to milli-Gauss].
64 samples per reading
Definition: qmc5883l.h:128
unsigned int i2c_t
Default i2c_t type definition.
Definition: i2c.h:157
50Hz data output rate
Definition: qmc5883l.h:95
10Hz data output rate
Definition: qmc5883l.h:94
int qmc5883l_poweroff(const qmc5883l_t *dev)
Power off the sensor (put it into standby mode)
uint8_t cfg
actual applied device configuration
Definition: qmc5883l.h:148
i2c bus error
Definition: qmc5883l.h:80
256 samples per reading
Definition: qmc5883l.h:126
qmc5883l_rng_t rng
output data range
Definition: qmc5883l.h:138
int qmc5883l_data_ready(const qmc5883l_t *dev)
Check if new data is available.
qmc5883l_odr_t
Output data rate.
Definition: qmc5883l.h:93
i2c_t i2c
I2C bus the sensor is connected to.
Definition: qmc5883l.h:135
qmc5883l_osr_t osr
oversampling rate
Definition: qmc5883l.h:139
success
Definition: qmc5883l.h:77
2 Gauss data output range
Definition: qmc5883l.h:111
qmc5883l_odr_t odr
output data rate
Definition: qmc5883l.h:137
QMC5883L device descriptor.
Definition: qmc5883l.h:145
QMC5883L initialization parameters.
Definition: qmc5883l.h:134
qmc5883l_osr_t
Over sample rate (bandwidth of internal digital filter)
Definition: qmc5883l.h:124
int qmc5883l_irq_disable(const qmc5883l_t *dev)
Disable the data ready (DRDY) interrupt.
at least one axis overflowed its range
Definition: qmc5883l.h:79
512 samples per reading
Definition: qmc5883l.h:125
200Hz data output rate
Definition: qmc5883l.h:97
100Hz data output rate
Definition: qmc5883l.h:96
8 Gauss data output range
Definition: qmc5883l.h:112
no data are available
Definition: qmc5883l.h:78
gpio_t pin_drdy
DRDY ISR pin, set to GPIO_UNDEF if unused.
Definition: qmc5883l.h:136
int qmc5883l_init_int(const qmc5883l_t *dev, gpio_cb_t cb, void *arg)
Initialize data ready (DRDY) interrupt notifications.
int qmc5883l_read_raw(const qmc5883l_t *dev, int16_t *data_out)
Read RAW data from the device.
void(* gpio_cb_t)(void *arg)
Signature of event callback functions triggered from interrupts.
Definition: gpio.h:141
Low-level I2C peripheral driver interface definition.
configuration error
Definition: qmc5883l.h:81