Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
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;
61  struct i2c_transaction i2c_trans;
62  bool initialized;
63 
64  enum Ak8975Status status;
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 */
enum Ak8975Status status
main status
Definition: ak8975.h:64
void ak8975_read(struct Ak8975 *ak)
Definition: ak8975.c:113
Ak8975ConfStatus
config status states
Definition: ak8975.h:44
@ AK_DISABLE_ACCESS_CALIBRATION
Definition: ak8975.h:47
@ AK_CONF_REQUESTED
Definition: ak8975.h:48
@ AK_CONF_UNINIT
Definition: ak8975.h:45
@ AK_REQ_CALIBRATION
Definition: ak8975.h:46
struct i2c_transaction i2c_trans
i2c transaction used for communication with the ak8936
Definition: ak8975.h:61
void ak8975_configure(struct Ak8975 *ak)
Definition: ak8975.c:63
void ak8975_init(struct Ak8975 *ak, struct i2c_periph *i2c_p, uint8_t addr)
Definition: ak8975.c:47
enum Ak8975ConfStatus init_status
init status
Definition: ak8975.h:65
uint32_t last_meas_time
last measurement time in ms
Definition: ak8975.h:66
Ak8975Status
Normal status states.
Definition: ak8975.h:52
@ AK_STATUS_MEAS
Definition: ak8975.h:54
@ AK_STATUS_IDLE
Definition: ak8975.h:53
@ AK_STATUS_DONE
Definition: ak8975.h:56
@ AK_STATUS_READ
Definition: ak8975.h:55
union Ak8975::@301 data
static void ak8975_periodic(struct Ak8975 *ak)
convenience function: read or start configuration if not already initialized
Definition: ak8975.h:83
volatile bool data_available
data ready flag
Definition: ak8975.h:68
bool initialized
config done flag
Definition: ak8975.h:62
struct i2c_periph * i2c_p
peripheral used for communcation
Definition: ak8975.h:60
void ak8975_event(struct Ak8975 *ak)
Definition: ak8975.c:131
Definition: ak8975.h:59
I2C transaction structure.
Definition: i2c.h:93
Architecture independent I2C (Inter-Integrated Circuit Bus) API.
Paparazzi fixed point algebra.
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
Definition: vl53l1_types.h:78
short int16_t
Typedef defining 16 bit short type.
Definition: vl53l1_types.h:93
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
Definition: vl53l1_types.h:98