Paparazzi UAS  v5.15_devel-58-g208c37b
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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 */
struct i2c_transaction i2c_trans
i2c transaction
Definition: lis3mdl.h:71
Lis3mdlStatus
config status states
Definition: lis3mdl.h:61
void lis3mdl_configure(struct Lis3mdl *mag)
Definition: lis3mdl.c:82
void lis3mdl_read(struct Lis3mdl *mag)
Definition: lis3mdl.c:113
struct i2c_periph * i2c_p
peripheral used for communcation
Definition: lis3mdl.h:70
union Lis3mdl::@314 data
signed short int16_t
Definition: types.h:17
I2C transaction structure.
Definition: i2c.h:93
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
static const float scale[]
I2C peripheral structure.
Definition: i2c.h:138
unsigned char uint8_t
Definition: types.h:14
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
enum Lis3mdlStatus status
init status
Definition: lis3mdl.h:73
static void lis3mdl_periodic(struct Lis3mdl *mag)
convenience function: read or start configuration if not already initialized
Definition: lis3mdl.h:88
volatile bool data_available
data ready flag
Definition: lis3mdl.h:74
bool initialized
config done flag
Definition: lis3mdl.h:72
void lis3mdl_event(struct Lis3mdl *mag)
Definition: lis3mdl.c:127
Paparazzi fixed point algebra.
Architecture independent I2C (Inter-Integrated Circuit Bus) API.