Paparazzi UAS  v5.10_stable-5-g83a0da5-dirty
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
ak8975.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 Xavier Paris, Gautier Hattenberger
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 AK8975_H
28 #define AK8975_H
29 
30 #include "std.h"
31 #include "mcu_periph/i2c.h"
32 #include "math/pprz_algebra_int.h"
33 
34 /* Address and register definitions */
35 #define AK8975_I2C_SLV_ADDR (0x0C<<1)
36 #define AK8975_REG_ST1_ADDR 0x02
37 #define AK8975_REG_CNTL_ADDR 0x0A
38 #define AK8975_REG_ASASX 0x10
39 #define AK8975_MODE_FUSE_ACCESS 0b00001111
40 #define AK8975_MODE_POWER_DOWN 0b00000000
41 #define AK8975_MODE_SINGLE_MEAS 0b00000001
42 
49 };
50 
57 };
58 
59 struct Ak8975 {
60  struct i2c_periph *i2c_p;
62  bool initialized;
63 
67 
68  volatile bool data_available;
69  union {
70  struct Int16Vect3 vect;
71  int16_t value[3];
72  } data;
73 };
74 
75 
76 // Functions
77 extern void ak8975_init(struct Ak8975 *ak, struct i2c_periph *i2c_p, uint8_t addr);
78 extern void ak8975_configure(struct Ak8975 *ak);
79 extern void ak8975_event(struct Ak8975 *ak);
80 extern void ak8975_read(struct Ak8975 *ak);
81 
83 static inline void ak8975_periodic(struct Ak8975 *ak)
84 {
85  if (ak->initialized) {
86  ak8975_read(ak);
87  } else {
88  ak8975_configure(ak);
89  }
90 }
91 
92 #endif /* AK8975_H */
Ak8975Status
Normal status states.
Definition: ak8975.h:52
Definition: ak8975.h:59
volatile bool data_available
data ready flag
Definition: ak8975.h:68
uint32_t last_meas_time
last measurement time in ms
Definition: ak8975.h:66
enum Ak8975ConfStatus init_status
init status
Definition: ak8975.h:65
Ak8975ConfStatus
config status states
Definition: ak8975.h:44
static void ak8975_periodic(struct Ak8975 *ak)
convenience function: read or start configuration if not already initialized
Definition: ak8975.h:83
void ak8975_event(struct Ak8975 *ak)
Definition: ak8975.c:131
enum Ak8975Status status
main status
Definition: ak8975.h:64
unsigned long uint32_t
Definition: types.h:18
void ak8975_configure(struct Ak8975 *ak)
Definition: ak8975.c:63
signed short int16_t
Definition: types.h:17
I2C transaction structure.
Definition: i2c.h:93
bool initialized
config done flag
Definition: ak8975.h:62
I2C peripheral structure.
Definition: i2c.h:138
void ak8975_init(struct Ak8975 *ak, struct i2c_periph *i2c_p, uint8_t addr)
Definition: ak8975.c:47
unsigned char uint8_t
Definition: types.h:14
union Ak8975::@294 data
struct i2c_transaction i2c_trans
i2c transaction used for communication with the ak8936
Definition: ak8975.h:61
void ak8975_read(struct Ak8975 *ak)
Definition: ak8975.c:113
struct i2c_periph * i2c_p
peripheral used for communcation
Definition: ak8975.h:60
Paparazzi fixed point algebra.
Architecture independent I2C (Inter-Integrated Circuit Bus) API.