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 
qmc5883l_params_t::osr
qmc5883l_osr_t osr
oversampling rate
Definition: qmc5883l.h:139
qmc5883l_poweron
int qmc5883l_poweron(const qmc5883l_t *dev)
Power on the sensor (put it into continuous sampling mode)
qmc5883l_irq_disable
int qmc5883l_irq_disable(const qmc5883l_t *dev)
Disable the data ready (DRDY) interrupt.
qmc5883l_t::i2c
i2c_t i2c
I2C bus the sensor is connected to.
Definition: qmc5883l.h:146
QMC5883L_OSR_64
@ QMC5883L_OSR_64
64 samples per reading
Definition: qmc5883l.h:128
qmc5883l_osr_t
qmc5883l_osr_t
Over sample rate (bandwidth of internal digital filter)
Definition: qmc5883l.h:124
QMC5883L_ODR_10HZ
@ QMC5883L_ODR_10HZ
10Hz data output rate
Definition: qmc5883l.h:94
qmc5883l_params_t
QMC5883L initialization parameters.
Definition: qmc5883l.h:134
qmc5883l_odr_t
qmc5883l_odr_t
Output data rate.
Definition: qmc5883l.h:93
i2c_t
unsigned int i2c_t
Default i2c_t type definition.
Definition: i2c.h:151
qmc5883l_read
int qmc5883l_read(const qmc5883l_t *dev, int16_t *data_out)
Read sampled data from the device [converted to milli-Gauss].
QMC5883L_OSR_256
@ QMC5883L_OSR_256
256 samples per reading
Definition: qmc5883l.h:126
qmc5883l_params_t::odr
qmc5883l_odr_t odr
output data rate
Definition: qmc5883l.h:137
qmc5883l_params_t::i2c
i2c_t i2c
I2C bus the sensor is connected to.
Definition: qmc5883l.h:135
QMC5883L_ODR_200HZ
@ QMC5883L_ODR_200HZ
200Hz data output rate
Definition: qmc5883l.h:97
qmc5883l_params_t::pin_drdy
gpio_t pin_drdy
DRDY ISR pin, set to GPIO_UNDEF if unused.
Definition: qmc5883l.h:136
qmc5883l_t
QMC5883L device descriptor.
Definition: qmc5883l.h:145
QMC5883L_NOCFG
@ QMC5883L_NOCFG
configuration error
Definition: qmc5883l.h:81
QMC5883L_RNG_2G
@ QMC5883L_RNG_2G
2 Gauss data output range
Definition: qmc5883l.h:111
QMC5883L_ODR_50HZ
@ QMC5883L_ODR_50HZ
50Hz data output rate
Definition: qmc5883l.h:95
gpio_cb_t
void(* gpio_cb_t)(void *arg)
Signature of event callback functions triggered from interrupts.
Definition: gpio.h:146
qmc5883l_init_int
int qmc5883l_init_int(const qmc5883l_t *dev, gpio_cb_t cb, void *arg)
Initialize data ready (DRDY) interrupt notifications.
QMC5883L_BUSERR
@ QMC5883L_BUSERR
i2c bus error
Definition: qmc5883l.h:80
QMC5883L_NODATA
@ QMC5883L_NODATA
no data are available
Definition: qmc5883l.h:78
gpio.h
Low-level GPIO peripheral driver interface definitions.
qmc5883l_init
int qmc5883l_init(qmc5883l_t *dev, const qmc5883l_params_t *params)
Initialize the given QMC5883L magnetic sensor.
qmc5883l_poweroff
int qmc5883l_poweroff(const qmc5883l_t *dev)
Power off the sensor (put it into standby mode)
qmc5883l_irq_enable
int qmc5883l_irq_enable(const qmc5883l_t *dev)
Enable the data ready (DRDY) interrupt.
QMC5883L_RNG_8G
@ QMC5883L_RNG_8G
8 Gauss data output range
Definition: qmc5883l.h:112
qmc5883l_t::cfg
uint8_t cfg
actual applied device configuration
Definition: qmc5883l.h:148
QMC5883L_OVERFLOW
@ QMC5883L_OVERFLOW
at least one axis overflowed its range
Definition: qmc5883l.h:79
QMC5883L_OSR_512
@ QMC5883L_OSR_512
512 samples per reading
Definition: qmc5883l.h:125
qmc5883l_params_t::rng
qmc5883l_rng_t rng
output data range
Definition: qmc5883l.h:138
qmc5883l_rng_t
qmc5883l_rng_t
Output value range.
Definition: qmc5883l.h:110
qmc5883l_t::pin_drdy
gpio_t pin_drdy
DRDY interrupt pin.
Definition: qmc5883l.h:147
qmc5883l_read_raw
int qmc5883l_read_raw(const qmc5883l_t *dev, int16_t *data_out)
Read RAW data from the device.
i2c.h
Low-level I2C peripheral driver interface definition.
QMC5883L_ODR_100HZ
@ QMC5883L_ODR_100HZ
100Hz data output rate
Definition: qmc5883l.h:96
QMC5883L_OSR_128
@ QMC5883L_OSR_128
128 samples per reading
Definition: qmc5883l.h:127
QMC5883L_OK
@ QMC5883L_OK
success
Definition: qmc5883l.h:77
qmc5883l_data_ready
int qmc5883l_data_ready(const qmc5883l_t *dev)
Check if new data is available.