hmc5883l.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2018 Gunar Schorcht
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 
32 #ifndef HMC5883L_H
33 #define HMC5883L_H
34 
35 #ifdef __cplusplus
36 extern "C"
37 {
38 #endif
39 
40 #include <stdbool.h>
41 #include <stdint.h>
42 
43 #include "periph/gpio.h"
44 #include "periph/i2c.h"
45 
47 typedef enum {
55 
61 typedef enum {
64  HMC5883L_DOR_3 = 0x08,
66  HMC5883L_DOR_15 = 0x10,
67  HMC5883L_DOR_30 = 0x14,
68  HMC5883L_DOR_75 = 0x18,
70 
76 typedef enum {
81 
87 typedef enum {
93 
99 typedef enum {
104 
110 typedef enum {
120 
124 typedef struct {
125  int16_t x;
126  int16_t y;
127  int16_t z;
129 
133 typedef struct {
134  int16_t x;
135  int16_t y;
136  int16_t z;
138 
139 #if MODULE_HMC5883L_INT || DOXYGEN
140 
151 typedef void (*hmc5883l_drdy_int_cb_t)(void *);
152 
153 #endif /* MODULE_HMC5883L_INT || DOXYGEN */
154 
158 typedef struct {
159  unsigned dev;
160 #if MODULE_HMC5883L_INT
161  gpio_t int_pin;
162 #endif
169 
173 typedef struct {
174  unsigned dev;
175 #if MODULE_HMC5883L_INT
176  gpio_t int_pin;
177 #endif
180 } hmc5883l_t;
181 
195 int hmc5883l_init(hmc5883l_t *dev, const hmc5883l_params_t *params);
196 
197 #if MODULE_HMC5883L_INT || DOXYGEN
198 
219 int hmc5883l_init_int(hmc5883l_t *dev, hmc5883l_drdy_int_cb_t cb, void *arg);
220 
221 #endif /* MODULE_HMC5883L_INT || DOXYGEN */
222 
235 int hmc5883l_data_ready(const hmc5883l_t *dev);
236 
251 int hmc5883l_read(const hmc5883l_t *dev, hmc5883l_data_t *data);
252 
263 int hmc5883l_read_raw(const hmc5883l_t *dev, hmc5883l_raw_data_t *raw);
264 
278 
289 int hmc5883l_power_up(hmc5883l_t *dev);
290 
291 #ifdef __cplusplus
292 }
293 #endif
294 
295 #endif /* HMC5883L_H */
296 
HMC5883L_MEAS_MODE_BIAS_POS
@ HMC5883L_MEAS_MODE_BIAS_POS
Positive bias config for all axes.
Definition: hmc5883l.h:78
hmc5883l_params_t::op_mode
hmc5883l_op_mode_t op_mode
Operation mode (HMC5883L_OP_MODE_CONTINUOUS)
Definition: hmc5883l.h:166
HMC5883L_GAIN_330
@ HMC5883L_GAIN_330
Range +-5.6 Gs, Resolution 3.03 mGs/LSB.
Definition: hmc5883l.h:117
HMC5883L_OP_MODE_CONTINUOUS
@ HMC5883L_OP_MODE_CONTINUOUS
Continuous measurement.
Definition: hmc5883l.h:100
hmc5883l_params_t
HMC5883L device initialization parameters.
Definition: hmc5883l.h:158
HMC5883L_DOR_7_5
@ HMC5883L_DOR_7_5
7.5 Hz
Definition: hmc5883l.h:65
HMC5883L_OP_MODE_SINGLE
@ HMC5883L_OP_MODE_SINGLE
Single measurement.
Definition: hmc5883l.h:101
hmc5883l_t::gain
hmc5883l_gain_t gain
Gain (default HMC5883L_GAIN_1090)
Definition: hmc5883l.h:179
hmc5883l_init_int
int hmc5883l_init_int(hmc5883l_t *dev, hmc5883l_drdy_int_cb_t cb, void *arg)
Initialize and activate the DRDY interrupt of HMC5883L sensor device.
hmc5883l_raw_data_t::y
int16_t y
magnetic field y-axis as 16 bit two's complements
Definition: hmc5883l.h:135
HMC5883L_OP_MODE_IDLE
@ HMC5883L_OP_MODE_IDLE
Idle mode.
Definition: hmc5883l.h:102
HMC5883L_ERROR_I2C
@ HMC5883L_ERROR_I2C
any I2C communication error
Definition: hmc5883l.h:49
hmc5883l_params_t::dor
hmc5883l_dor_t dor
Data output rate (default HMC5883L_DOR_15)
Definition: hmc5883l.h:165
hmc5883l_raw_data_t::z
int16_t z
magnetic field z-axis as 16 bit two's complements
Definition: hmc5883l.h:136
hmc5883l_params_t::meas_avg
hmc5883l_meas_avg_t meas_avg
Measurement avaraging (default HMC5883L_MEAS_AVG_NONE)
Definition: hmc5883l.h:164
hmc5883l_error_codes_t
hmc5883l_error_codes_t
Definition of error codes.
Definition: hmc5883l.h:47
hmc5883l_params_t::meas_mode
hmc5883l_meas_mode_t meas_mode
Measurement mode (default HMC5883L_MEAS_MODE_NORMAL)
Definition: hmc5883l.h:163
hmc5883l_gain_t
hmc5883l_gain_t
Gain (determines the sensitivity and the range)
Definition: hmc5883l.h:110
hmc5883l_t::dev
unsigned dev
I2C device.
Definition: hmc5883l.h:174
hmc5883l_power_down
int hmc5883l_power_down(hmc5883l_t *dev)
Power down the sensor.
HMC5883L_MEAS_AVG_4
@ HMC5883L_MEAS_AVG_4
4 samples are averaged
Definition: hmc5883l.h:90
hmc5883l_raw_data_t::x
int16_t x
magnetic field x-axis as 16 bit two's complements
Definition: hmc5883l.h:134
HMC5883L_ERROR_RAW_DATA
@ HMC5883L_ERROR_RAW_DATA
reading raw data failed
Definition: hmc5883l.h:52
hmc5883l_data_t::z
int16_t z
magnetic field y-axis
Definition: hmc5883l.h:127
HMC5883L_GAIN_820
@ HMC5883L_GAIN_820
Range +-1.9 Gs, Resolution 1.22 mGs/LSB.
Definition: hmc5883l.h:113
HMC5883L_DOR_1_5
@ HMC5883L_DOR_1_5
1.5 Hz
Definition: hmc5883l.h:63
HMC5883L_GAIN_660
@ HMC5883L_GAIN_660
Range +-2.5 Gs, Resolution 1.52 mGs/LSB.
Definition: hmc5883l.h:114
HMC5883L_MEAS_MODE_NORMAL
@ HMC5883L_MEAS_MODE_NORMAL
Normal measurement config.
Definition: hmc5883l.h:77
hmc5883l_power_up
int hmc5883l_power_up(hmc5883l_t *dev)
Power up the sensor.
HMC5883L_ERROR_COMMON
@ HMC5883L_ERROR_COMMON
common error
Definition: hmc5883l.h:53
hmc5883l_init
int hmc5883l_init(hmc5883l_t *dev, const hmc5883l_params_t *params)
Initialize the HMC5883L sensor device.
HMC5883L_DOR_3
@ HMC5883L_DOR_3
3 Hz
Definition: hmc5883l.h:64
HMC5883L_MEAS_AVG_8
@ HMC5883L_MEAS_AVG_8
8 samples are averaged
Definition: hmc5883l.h:91
HMC5883L_GAIN_440
@ HMC5883L_GAIN_440
Range +-4.0 Gs, Resolution 2.27 mGs/LSB.
Definition: hmc5883l.h:115
HMC5883L_DOR_75
@ HMC5883L_DOR_75
75 Hz
Definition: hmc5883l.h:68
HMC5883L_ERROR_NO_DATA
@ HMC5883L_ERROR_NO_DATA
no data are available
Definition: hmc5883l.h:51
hmc5883l_read_raw
int hmc5883l_read_raw(const hmc5883l_t *dev, hmc5883l_raw_data_t *raw)
Read one sample of raw sensor data as 16 bit two's complements.
HMC5883L_DOR_0_75
@ HMC5883L_DOR_0_75
0.75 Hz
Definition: hmc5883l.h:62
HMC5883L_GAIN_1370
@ HMC5883L_GAIN_1370
Range +-0.88 Gs, Resolution 0.73 mGs/LSB.
Definition: hmc5883l.h:111
HMC5883L_GAIN_390
@ HMC5883L_GAIN_390
Range +-4.7 Gs, Resolution 2.56 mGs/LSB.
Definition: hmc5883l.h:116
hmc5883l_params_t::gain
hmc5883l_gain_t gain
Gain (default HMC5883L_GAIN_1090)
Definition: hmc5883l.h:167
hmc5883l_drdy_int_cb_t
void(* hmc5883l_drdy_int_cb_t)(void *)
HMC5883L DRDY interrupt callback function type.
Definition: hmc5883l.h:151
HMC5883L_DOR_30
@ HMC5883L_DOR_30
30 Hz
Definition: hmc5883l.h:67
HMC5883L_MEAS_AVG_NONE
@ HMC5883L_MEAS_AVG_NONE
No averaging.
Definition: hmc5883l.h:88
HMC5883L_GAIN_230
@ HMC5883L_GAIN_230
Range +-8.1 Gs, Resolution 4.35 mGs/LSB.
Definition: hmc5883l.h:118
hmc5883l_meas_mode_t
hmc5883l_meas_mode_t
Measurement modes.
Definition: hmc5883l.h:76
hmc5883l_op_mode_t
hmc5883l_op_mode_t
Operation modes.
Definition: hmc5883l.h:99
hmc5883l_params_t::dev
unsigned dev
I2C device.
Definition: hmc5883l.h:159
HMC5883L_OK
@ HMC5883L_OK
success
Definition: hmc5883l.h:48
HMC5883L_MEAS_MODE_BIAS_NEG
@ HMC5883L_MEAS_MODE_BIAS_NEG
Negative bias config for all axes.
Definition: hmc5883l.h:79
hmc5883l_read
int hmc5883l_read(const hmc5883l_t *dev, hmc5883l_data_t *data)
Read one sample of magnetic field values in milli-Gauss (mGs)
hmc5883l_data_t
Magnetic field values in milli-Gauss (mGs)
Definition: hmc5883l.h:124
hmc5883l_dor_t
hmc5883l_dor_t
Data output rates (DOR)
Definition: hmc5883l.h:61
HMC5883L_GAIN_1090
@ HMC5883L_GAIN_1090
Range +-1.3 Gs, Resolution 0.92 mGs/LSB.
Definition: hmc5883l.h:112
HMC5883L_DOR_15
@ HMC5883L_DOR_15
15 Hz (default)
Definition: hmc5883l.h:66
hmc5883l_data_t::y
int16_t y
magnetic field y-axis
Definition: hmc5883l.h:126
gpio.h
Low-level GPIO peripheral driver interface definitions.
HMC5883L_ERROR_WRONG_ID
@ HMC5883L_ERROR_WRONG_ID
wrong id read
Definition: hmc5883l.h:50
hmc5883l_data_t::x
int16_t x
magnetic field x-axis
Definition: hmc5883l.h:125
hmc5883l_data_ready
int hmc5883l_data_ready(const hmc5883l_t *dev)
Data-ready status function.
hmc5883l_t::op_mode
hmc5883l_op_mode_t op_mode
Operation mode (HMC5883L_OP_MODE_CONTINUOUS)
Definition: hmc5883l.h:178
HMC5883L_MEAS_AVG_2
@ HMC5883L_MEAS_AVG_2
2 samples are averaged
Definition: hmc5883l.h:89
hmc5883l_raw_data_t
Raw data set as two complements.
Definition: hmc5883l.h:133
i2c.h
Low-level I2C peripheral driver interface definition.
hmc5883l_meas_avg_t
hmc5883l_meas_avg_t
Measurement avaraging (number of samples are averaged for output)
Definition: hmc5883l.h:87
hmc5883l_t
HMC5883L sensor device data structure type.
Definition: hmc5883l.h:173