The friendly Operating System for the Internet of Things
mag3110.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014 PHYTEC Messtechnik GmbH
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 
30 #ifndef MAG3110_H
31 #define MAG3110_H
32 
33 #include <stdint.h>
34 #include <stdbool.h>
35 #include "periph/i2c.h"
36 
37 #ifdef __cplusplus
38 extern "C"
39 {
40 #endif
41 
42 #ifndef MAG3110_I2C_ADDRESS
43 #define MAG3110_I2C_ADDRESS 0x0E
44 #endif
45 
46 #define MAG3110_DROS_8000_16 0
47 #define MAG3110_DROS_4000_32 1
48 #define MAG3110_DROS_2000_64 2
49 #define MAG3110_DROS_1000_128 3
50 #define MAG3110_DROS_4000_16 4
51 #define MAG3110_DROS_2000_32 5
52 #define MAG3110_DROS_1000_64 6
53 #define MAG3110_DROS_0500_128 7
54 #define MAG3110_DROS_2000_16 8
55 #define MAG3110_DROS_1000_32 9
56 #define MAG3110_DROS_0500_64 10
57 #define MAG3110_DROS_0250_128 11
58 #define MAG3110_DROS_1000_16 12
59 #define MAG3110_DROS_0500_32 13
60 #define MAG3110_DROS_0250_64 14
61 #define MAG3110_DROS_0125_128 15
62 #define MAG3110_DROS_0500_16 16
63 #define MAG3110_DROS_0250_32 17
64 #define MAG3110_DROS_0125_64 18
65 #define MAG3110_DROS_0063_128 19
66 #define MAG3110_DROS_0250_16 20
67 #define MAG3110_DROS_0125_32 21
68 #define MAG3110_DROS_0063_64 22
69 #define MAG3110_DROS_0031_128 23
70 #define MAG3110_DROS_0125_16 24
71 #define MAG3110_DROS_0063_32 25
72 #define MAG3110_DROS_0031_64 26
73 #define MAG3110_DROS_0016_128 27
74 #define MAG3110_DROS_0063_16 28
75 #define MAG3110_DROS_0031_32 29
76 #define MAG3110_DROS_0016_64 30
77 #define MAG3110_DROS_0008_128 31
78 #define MAG3110_DROS_DEFAULT MAG3110_DROS_0125_128
83 typedef struct {
85  uint8_t addr;
86  bool initialized;
87 } mag3110_t;
88 
98 int mag3110_test(mag3110_t *dev);
99 
114 int mag3110_init(mag3110_t *dev, i2c_t i2c, uint8_t address, uint8_t dros);
115 
128 int mag3110_set_user_offset(mag3110_t *dev, int16_t x, int16_t y, int16_t z);
129 
138 int mag3110_set_active(mag3110_t *dev);
139 
149 
159 int mag3110_is_ready(mag3110_t *dev);
160 
175 int mag3110_read(mag3110_t *dev, int16_t *x, int16_t *y, int16_t *z, uint8_t *status);
176 
186 int mag3110_read_dtemp(mag3110_t *dev, int8_t *dtemp);
187 
188 #ifdef __cplusplus
189 }
190 #endif
191 
192 #endif
193 
uint8_t addr
the magnetometer's slave address on the I2C bus
Definition: mag3110.h:85
int mag3110_set_active(mag3110_t *dev)
Set active mode, this enables periodic measurements.
unsigned int i2c_t
Default i2c_t type definition.
Definition: i2c.h:104
int mag3110_set_user_offset(mag3110_t *dev, int16_t x, int16_t y, int16_t z)
Set user offset correction.
int mag3110_read(mag3110_t *dev, int16_t *x, int16_t *y, int16_t *z, uint8_t *status)
Read magnetometer's data.
int mag3110_init(mag3110_t *dev, i2c_t i2c, uint8_t address, uint8_t dros)
Initialise the MAG3110 magnetometer driver.
int mag3110_is_ready(mag3110_t *dev)
Check for new set of measurement data.
int mag3110_set_standby(mag3110_t *dev)
Set standby mode.
i2c_t i2c
I2C device, the magnetometer is connected to.
Definition: mag3110.h:84
bool initialized
magnetometer status, true if magnetometer is initialized
Definition: mag3110.h:86
int mag3110_read_dtemp(mag3110_t *dev, int8_t *dtemp)
Read die temperature.
int mag3110_test(mag3110_t *dev)
MAG3110 magnetometer test.
Device descriptor for MAG3110 magnetometer.
Definition: mag3110.h:83
Low-level I2C peripheral driver interface definition.