Paparazzi UAS  v5.18.0_stable
Paparazzi is a free software Unmanned Aircraft System.
lis3mdl.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2019 Gautier Hattenberger <gautier.hattenberger@enac.fr>
3  *
4  * This file is part of paparazzi.
5  *
6  * paparazzi is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2, or (at your option)
9  * any later version.
10  *
11  * paparazzi is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with paparazzi; see the file COPYING. If not, see
18  * <http://www.gnu.org/licenses/>.
19  */
20 
27 #ifndef LIS3MDL_H
28 #define LIS3MDL_H
29 
30 #include "std.h"
31 #include "mcu_periph/i2c.h"
32 #include "math/pprz_algebra_int.h"
33 
34 #define LIS3MDL_ADDR1 (0b0011110 << 1)
35 #define LIS3MDL_ADDR2 (0b0011100 << 1)
36 
37 #define LIS3MDL_PERFORMANCE_LOW_POWER 0b00
38 #define LIS3MDL_PERFORMANCE_MEDIUM 0b01
39 #define LIS3MDL_PERFORMANCE_HIGH 0b10
40 #define LIS3MDL_PERFORMANCE_ULTRA_HIGH 0b11
41 
42 #define LIS3MDL_DATA_RATE_0_625_HZ 0b000
43 #define LIS3MDL_DATA_RATE_1_25_HZ 0b001
44 #define LIS3MDL_DATA_RATE_2_5_HZ 0b010
45 #define LIS3MDL_DATA_RATE_5_HZ 0b011
46 #define LIS3MDL_DATA_RATE_10_HZ 0b100
47 #define LIS3MDL_DATA_RATE_20_HZ 0b101
48 #define LIS3MDL_DATA_RATE_40_HZ 0b110
49 #define LIS3MDL_DATA_RATE_80_HZ 0b111
50 
51 #define LIS3MDL_MODE_CONTINUOUS 0b00
52 #define LIS3MDL_MODE_SINGLE 0b01
53 #define LIS3MDL_MODE_POWER_DOWN 0b11
54 
55 #define LIS3MDL_SCALE_4_GAUSS 0b00
56 #define LIS3MDL_SCALE_8_GAUSS 0b01
57 #define LIS3MDL_SCALE_12_GAUSS 0b10
58 #define LIS3MDL_SCALE_16_GAUSS 0b11
59 
66 };
67 
68 // main structure
69 struct Lis3mdl {
70  struct i2c_periph *i2c_p;
72  bool initialized;
74  volatile bool data_available;
75  union {
76  struct Int16Vect3 vect;
77  int16_t value[3];
78  } data;
79 };
80 
81 // Functions
82 extern void lis3mdl_init(struct Lis3mdl *mag, struct i2c_periph *i2c_p, uint8_t addr, uint8_t data_rate, uint8_t scale, uint8_t mode, uint8_t perf);
83 extern void lis3mdl_configure(struct Lis3mdl *mag);
84 extern void lis3mdl_event(struct Lis3mdl *mag);
85 extern void lis3mdl_read(struct Lis3mdl *mag);
86 
88 static inline void lis3mdl_periodic(struct Lis3mdl *mag)
89 {
90  if (mag->initialized) {
91  lis3mdl_read(mag);
92  } else {
93  lis3mdl_configure(mag);
94  }
95 }
96 
97 #endif /* LIS3MDL_H */
Int16Vect3
Definition: pprz_algebra_int.h:62
LIS3MDL_CONF_REG
@ LIS3MDL_CONF_REG
Definition: lis3mdl.h:63
Lis3mdl::initialized
bool initialized
config done flag
Definition: lis3mdl.h:72
LIS3MDL_CONF_UNINIT
@ LIS3MDL_CONF_UNINIT
Definition: lis3mdl.h:62
scale
static const float scale[]
Definition: dw1000_arduino.c:200
Lis3mdlStatus
Lis3mdlStatus
config status states
Definition: lis3mdl.h:61
Lis3mdl::i2c_p
struct i2c_periph * i2c_p
peripheral used for communcation
Definition: lis3mdl.h:70
lis3mdl_read
void lis3mdl_read(struct Lis3mdl *mag)
Definition: lis3mdl.c:113
pprz_algebra_int.h
Paparazzi fixed point algebra.
lis3mdl_configure
void lis3mdl_configure(struct Lis3mdl *mag)
Definition: lis3mdl.c:82
std.h
int16_t
signed short int16_t
Definition: types.h:17
lis3mdl_init
void lis3mdl_init(struct Lis3mdl *mag, struct i2c_periph *i2c_p, uint8_t addr, uint8_t data_rate, uint8_t scale, uint8_t mode, uint8_t perf)
Definition: lis3mdl.c:60
Lis3mdl::data
union Lis3mdl::@323 data
uint8_t
unsigned char uint8_t
Definition: types.h:14
i2c_transaction
I2C transaction structure.
Definition: i2c.h:93
Lis3mdl
Definition: lis3mdl.h:69
LIS3MDL_STATUS_IDLE
@ LIS3MDL_STATUS_IDLE
Definition: lis3mdl.h:64
Lis3mdl::data_available
volatile bool data_available
data ready flag
Definition: lis3mdl.h:74
LIS3MDL_STATUS_MEAS
@ LIS3MDL_STATUS_MEAS
Definition: lis3mdl.h:65
Lis3mdl::status
enum Lis3mdlStatus status
init status
Definition: lis3mdl.h:73
mode
static uint8_t mode
mode holds the current sonar mode mode = 0 used at high altitude, uses 16 wave patterns mode = 1 used...
Definition: sonar_bebop.c:69
Lis3mdl::i2c_trans
struct i2c_transaction i2c_trans
i2c transaction
Definition: lis3mdl.h:71
lis3mdl_event
void lis3mdl_event(struct Lis3mdl *mag)
Definition: lis3mdl.c:127
i2c_periph
Definition: i2c.h:144
i2c.h
lis3mdl_periodic
static void lis3mdl_periodic(struct Lis3mdl *mag)
convenience function: read or start configuration if not already initialized
Definition: lis3mdl.h:88