mag3110.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014 PHYTEC Messtechnik GmbH
3  * 2017 HAW Hamburg
4  *
5  * This file is subject to the terms and conditions of the GNU Lesser
6  * General Public License v2.1. See the file LICENSE in the top level
7  * directory for more details.
8  */
9 
35 #ifndef MAG3110_H
36 #define MAG3110_H
37 
38 #include <stdint.h>
39 #include <stdbool.h>
40 #include "periph/i2c.h"
41 
42 #ifdef __cplusplus
43 extern "C"
44 {
45 #endif
46 
50 enum {
55 };
56 
68 #ifndef CONFIG_MAG3110_I2C_ADDRESS
69 #define CONFIG_MAG3110_I2C_ADDRESS 0x0E
70 #endif
71 
77 #define MAG3110_DROS_8000_16 0
78 #define MAG3110_DROS_4000_32 1
79 #define MAG3110_DROS_2000_64 2
80 #define MAG3110_DROS_1000_128 3
81 #define MAG3110_DROS_4000_16 4
82 #define MAG3110_DROS_2000_32 5
83 #define MAG3110_DROS_1000_64 6
84 #define MAG3110_DROS_0500_128 7
85 #define MAG3110_DROS_2000_16 8
86 #define MAG3110_DROS_1000_32 9
87 #define MAG3110_DROS_0500_64 10
88 #define MAG3110_DROS_0250_128 11
89 #define MAG3110_DROS_1000_16 12
90 #define MAG3110_DROS_0500_32 13
91 #define MAG3110_DROS_0250_64 14
92 #define MAG3110_DROS_0125_128 15
93 #define MAG3110_DROS_0500_16 16
94 #define MAG3110_DROS_0250_32 17
95 #define MAG3110_DROS_0125_64 18
96 #define MAG3110_DROS_0063_128 19
97 #define MAG3110_DROS_0250_16 20
98 #define MAG3110_DROS_0125_32 21
99 #define MAG3110_DROS_0063_64 22
100 #define MAG3110_DROS_0031_128 23
101 #define MAG3110_DROS_0125_16 24
102 #define MAG3110_DROS_0063_32 25
103 #define MAG3110_DROS_0031_64 26
104 #define MAG3110_DROS_0016_128 27
105 #define MAG3110_DROS_0063_16 28
106 #define MAG3110_DROS_0031_32 29
107 #define MAG3110_DROS_0016_64 30
108 #define MAG3110_DROS_0008_128 31
109 #define MAG3110_DROS_DEFAULT MAG3110_DROS_0125_128
115 typedef struct {
117  uint8_t addr;
118  uint8_t type;
119  uint8_t dros;
120  int16_t offset[3];
122 
126 typedef struct {
128 } mag3110_t;
129 
133 typedef struct {
134  int16_t x;
135  int16_t y;
136  int16_t z;
138 
150 int mag3110_init(mag3110_t *dev, const mag3110_params_t *params);
151 
165 int mag3110_set_user_offset(const mag3110_t *dev, int16_t x, int16_t y, int16_t z);
166 
175 int mag3110_set_active(const mag3110_t *dev);
176 
185 int mag3110_set_standby(const mag3110_t *dev);
186 
196 int mag3110_is_ready(const mag3110_t *dev);
197 
210 int mag3110_read(const mag3110_t *dev, mag3110_data_t *data);
211 
221 int mag3110_read_dtemp(const mag3110_t *dev, int8_t *dtemp);
222 
223 #ifdef __cplusplus
224 }
225 #endif
226 
227 #endif /* MAG3110_H */
228 
mag3110_read
int mag3110_read(const mag3110_t *dev, mag3110_data_t *data)
Read magnetometer's data.
mag3110_params_t::addr
uint8_t addr
I2C bus address of the device.
Definition: mag3110.h:117
mag3110_read_dtemp
int mag3110_read_dtemp(const mag3110_t *dev, int8_t *dtemp)
Read die temperature.
mag3110_is_ready
int mag3110_is_ready(const mag3110_t *dev)
Check for new set of measurement data.
i2c_t
unsigned int i2c_t
Default i2c_t type definition.
Definition: i2c.h:151
MAG3110_ERROR_CNF
@ MAG3110_ERROR_CNF
Device configuration failed.
Definition: mag3110.h:54
mag3110_t
Device descriptor for MAG3110 magnetometer.
Definition: mag3110.h:126
mag3110_params_t
Configuration parameters.
Definition: mag3110.h:115
MAG3110_ERROR_DEV
@ MAG3110_ERROR_DEV
Device MAG3110 not found.
Definition: mag3110.h:53
mag3110_t::params
mag3110_params_t params
device configuration parameters
Definition: mag3110.h:127
mag3110_data_t
Data type for the result data.
Definition: mag3110.h:133
mag3110_init
int mag3110_init(mag3110_t *dev, const mag3110_params_t *params)
Initialise the MAG3110 magnetometer driver.
mag3110_params_t::type
uint8_t type
device type
Definition: mag3110.h:118
mag3110_set_user_offset
int mag3110_set_user_offset(const mag3110_t *dev, int16_t x, int16_t y, int16_t z)
Set user offset correction.
MAG3110_OK
@ MAG3110_OK
all good
Definition: mag3110.h:51
mag3110_params_t::dros
uint8_t dros
sampling rate to use
Definition: mag3110.h:119
mag3110_set_standby
int mag3110_set_standby(const mag3110_t *dev)
Set standby mode.
mag3110_params_t::i2c
i2c_t i2c
I2C bus the device is connected to.
Definition: mag3110.h:116
mag3110_set_active
int mag3110_set_active(const mag3110_t *dev)
Set active mode, this enables periodic measurements.
MAG3110_ERROR_I2C
@ MAG3110_ERROR_I2C
I2C communication failed.
Definition: mag3110.h:52
mag3110_data_t::z
int16_t z
acceleration in Z direction
Definition: mag3110.h:136
i2c.h
Low-level I2C peripheral driver interface definition.
mag3110_data_t::x
int16_t x
acceleration in X direction
Definition: mag3110.h:134
mag3110_data_t::y
int16_t y
acceleration in Y direction
Definition: mag3110.h:135