Paparazzi UAS v7.0_unstable
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"
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
67
68// main structure
69struct Lis3mdl {
70 struct i2c_periph *i2c_p;
74 volatile bool data_available;
75 union {
76 struct Int16Vect3 vect;
77 int16_t value[3];
79};
80
81// Functions
82extern 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);
83extern void lis3mdl_configure(struct Lis3mdl *mag);
84extern void lis3mdl_event(struct Lis3mdl *mag);
85extern void lis3mdl_read(struct Lis3mdl *mag);
86
88static inline void lis3mdl_periodic(struct Lis3mdl *mag)
89{
90 if (mag->initialized) {
91 lis3mdl_read(mag);
92 } else {
94 }
95}
96
97#endif /* LIS3MDL_H */
static const float scale[]
I2C transaction structure.
Definition i2c.h:93
Architecture independent I2C (Inter-Integrated Circuit Bus) API.
struct i2c_transaction i2c_trans
i2c transaction
Definition lis3mdl.h:71
enum Lis3mdlStatus status
init status
Definition lis3mdl.h:73
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
void lis3mdl_read(struct Lis3mdl *mag)
Definition lis3mdl.c:113
bool initialized
config done flag
Definition lis3mdl.h:72
volatile bool data_available
data ready flag
Definition lis3mdl.h:74
struct i2c_periph * i2c_p
peripheral used for communcation
Definition lis3mdl.h:70
Lis3mdlStatus
config status states
Definition lis3mdl.h:61
@ LIS3MDL_CONF_UNINIT
Definition lis3mdl.h:62
@ LIS3MDL_STATUS_MEAS
Definition lis3mdl.h:65
@ LIS3MDL_STATUS_IDLE
Definition lis3mdl.h:64
@ LIS3MDL_CONF_REG
Definition lis3mdl.h:63
static void lis3mdl_periodic(struct Lis3mdl *mag)
convenience function: read or start configuration if not already initialized
Definition lis3mdl.h:88
union Lis3mdl::@333 data
void lis3mdl_event(struct Lis3mdl *mag)
Definition lis3mdl.c:127
void lis3mdl_configure(struct Lis3mdl *mag)
Definition lis3mdl.c:82
uint16_t foo
Definition main_demo5.c:58
Paparazzi fixed point algebra.
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:65
short int16_t
Typedef defining 16 bit short type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.