Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
qmc5883l.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2022 Paparazzi Team
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 QMC5883L_H
28 #define QMC5883L_H
29 
30 #include "std.h"
31 #include "mcu_periph/i2c.h"
32 #include "math/pprz_algebra_int.h"
33 
39 #define QMC5883L_ADDR0 (0b00001101 << 1) //from 0x0D to 0x1A since 7bits and 1 for R/W setting
40 
41 /* Continuous mode Output Data Rate (ODR) options in Hz */
42 #define QMC5883L_ODR_10 0x00
43 #define QMC5883L_ODR_50 0x04
44 #define QMC5883L_ODR_100 0x08
45 #define QMC5883L_ODR_200 0x0C
46 
47 /* Default data rate */
48 #define QMC5883L_ODR_DEFAULT QMC5883L_ODR_200 //We are never interested in powersavings 200 is best
49 
50 /* Status states */
52  QMC5883L_CONF_UNINIT, // Perform Initialization
53  QMC5883L_CONF_CCR_DONE, // Is done set CCR = Configure Continuous Rate done
54  QMC5883L_CONF_TMRC_DONE, // Is done set Datarate
55  QMC5883L_CONF_CCM_DONE, // Is done set Mode continuous or single CCM = Configure Continuous Measurement
56  QMC5883L_STATUS_IDLE, // Ready for data requests
57  QMC5883L_STATUS_MEAS // Get data
58 };
59 
60 struct Qmc5883l {
61  struct i2c_periph *i2c_p;
62  struct i2c_transaction i2c_trans;
64  bool initialized;
65  enum Qmc5883lStatus status;
66  volatile bool data_available;
67  union {
68  struct Int32Vect3 vect;
69  int32_t value[3];
70  } data;
71 };
72 
73 extern void qmc5883l_init(struct Qmc5883l *mag, struct i2c_periph *i2c_p, uint8_t addr, uint8_t data_rate);
74 extern void qmc5883l_configure(struct Qmc5883l *mag);
75 extern void qmc5883l_event(struct Qmc5883l *mag);
76 extern void qmc5883l_read(struct Qmc5883l *mag);
77 
79 static inline void qmc5883l_periodic(struct Qmc5883l *mag)
80 {
81  if (mag->initialized) {
82  qmc5883l_read(mag);
83  } else {
84  qmc5883l_configure(mag);
85  }
86 }
87 
88 #endif /* QMC5883L_H */
89 
90 
91 
92 
I2C transaction structure.
Definition: i2c.h:93
Architecture independent I2C (Inter-Integrated Circuit Bus) API.
Paparazzi fixed point algebra.
void qmc5883l_event(struct Qmc5883l *mag)
Definition: qmc5883l.c:154
volatile bool data_available
data ready flag
Definition: qmc5883l.h:66
Qmc5883lStatus
Definition: qmc5883l.h:51
@ QMC5883L_CONF_CCR_DONE
Definition: qmc5883l.h:53
@ QMC5883L_CONF_TMRC_DONE
Definition: qmc5883l.h:54
@ QMC5883L_STATUS_MEAS
Definition: qmc5883l.h:57
@ QMC5883L_STATUS_IDLE
Definition: qmc5883l.h:56
@ QMC5883L_CONF_UNINIT
Definition: qmc5883l.h:52
@ QMC5883L_CONF_CCM_DONE
Definition: qmc5883l.h:55
struct i2c_periph * i2c_p
peripheral used for communcation
Definition: qmc5883l.h:61
void qmc5883l_read(struct Qmc5883l *mag)
Definition: qmc5883l.c:126
enum Qmc5883lStatus status
init status
Definition: qmc5883l.h:65
bool initialized
config done flag
Definition: qmc5883l.h:64
void qmc5883l_configure(struct Qmc5883l *mag)
Definition: qmc5883l.c:80
struct i2c_transaction i2c_trans
i2c transaction
Definition: qmc5883l.h:62
void qmc5883l_init(struct Qmc5883l *mag, struct i2c_periph *i2c_p, uint8_t addr, uint8_t data_rate)
Definition: qmc5883l.c:66
union Qmc5883l::@348 data
uint8_t data_rate
sensor data rate
Definition: qmc5883l.h:63
static void qmc5883l_periodic(struct Qmc5883l *mag)
convenience function: read or start configuration if not already initialized
Definition: qmc5883l.h:79
int int32_t
Typedef defining 32 bit int type.
Definition: vl53l1_types.h:83
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
Definition: vl53l1_types.h:98