Paparazzi UAS  v6.0_unstable-96-g165dd5c-dirty
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
rm3100.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2021 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 RM3100_H
28 #define RM3100_H
29 
30 #include "std.h"
31 #include "mcu_periph/i2c.h"
32 #include "math/pprz_algebra_int.h"
33 
37 #define RM3100_ADDR0 (0b0100000 << 1)
38 #define RM3100_ADDR1 (0b0100001 << 1)
39 #define RM3100_ADDR2 (0b0100010 << 1)
40 #define RM3100_ADDR3 (0b0100011 << 1)
41 
42 // Continuous mode data rate in Hz
43 #define RM3100_RATE_600 0x92
44 #define RM3100_RATE_300 0x93
45 #define RM3100_RATE_150 0x94
46 #define RM3100_RATE_75 0x95
47 #define RM3100_RATE_37 0x96
48 #define RM3100_RATE_18 0x97
49 #define RM3100_RATE_9 0x98
50 #define RM3100_RATE_4_5 0x99
51 #define RM3100_RATE_2_3 0x9A
52 #define RM3100_RATE_1_2 0x9B
53 #define RM3100_RATE_0_6 0x9C
54 #define RM3100_RATE_0_3 0x9D
55 #define RM3100_RATE_0_15 0x9E
56 #define RM3100_RATE_0_075 0x9F
57 
58 // Default data rate
59 #define RM3100_TMRC_DEFAULT RM3100_RATE_150
60 
69 };
70 
71 // main structure
72 struct Rm3100 {
73  struct i2c_periph *i2c_p;
76  bool initialized;
78  volatile bool data_available;
79  union {
80  struct Int32Vect3 vect;
81  int32_t value[3];
82  } data;
83 };
84 
85 // Functions
86 extern void rm3100_init(struct Rm3100 *mag, struct i2c_periph *i2c_p, uint8_t addr, uint8_t data_rate);
87 extern void rm3100_configure(struct Rm3100 *mag);
88 extern void rm3100_event(struct Rm3100 *mag);
89 extern void rm3100_read(struct Rm3100 *mag);
90 
92 static inline void rm3100_periodic(struct Rm3100 *mag)
93 {
94  if (mag->initialized) {
95  rm3100_read(mag);
96  } else {
97  rm3100_configure(mag);
98  }
99 }
100 
101 #endif /* RM31000_H */
struct i2c_periph * i2c_p
peripheral used for communcation
Definition: rm3100.h:73
static void rm3100_periodic(struct Rm3100 *mag)
convenience function: read or start configuration if not already initialized
Definition: rm3100.h:92
void rm3100_configure(struct Rm3100 *mag)
Definition: rm3100.c:75
enum Rm3100Status status
init status
Definition: rm3100.h:77
int int32_t
Typedef defining 32 bit int type.
Definition: vl53l1_types.h:83
uint8_t data_rate
sensor data rate
Definition: rm3100.h:75
I2C transaction structure.
Definition: i2c.h:93
void rm3100_init(struct Rm3100 *mag, struct i2c_periph *i2c_p, uint8_t addr, uint8_t data_rate)
Definition: rm3100.c:59
union Rm3100::@330 data
bool initialized
config done flag
Definition: rm3100.h:76
void rm3100_read(struct Rm3100 *mag)
Definition: rm3100.c:130
volatile bool data_available
data ready flag
Definition: rm3100.h:78
Definition: rm3100.h:72
Rm3100Status
config status states
Definition: rm3100.h:62
void rm3100_event(struct Rm3100 *mag)
Definition: rm3100.c:152
struct i2c_transaction i2c_trans
i2c transaction
Definition: rm3100.h:74
Paparazzi fixed point algebra.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
Definition: vl53l1_types.h:98
Architecture independent I2C (Inter-Integrated Circuit Bus) API.