Paparazzi UAS  v5.18.0_stable
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;
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 */
Int16Vect3
Definition: pprz_algebra_int.h:62
Ak8975::i2c_trans
struct i2c_transaction i2c_trans
i2c transaction used for communication with the ak8936
Definition: ak8975.h:61
AK_STATUS_IDLE
@ AK_STATUS_IDLE
Definition: ak8975.h:53
ak8975_read
void ak8975_read(struct Ak8975 *ak)
Definition: ak8975.c:113
Ak8975::data
union Ak8975::@307 data
Ak8975Status
Ak8975Status
Normal status states.
Definition: ak8975.h:52
uint32_t
unsigned long uint32_t
Definition: types.h:18
Ak8975
Definition: ak8975.h:59
Ak8975::last_meas_time
uint32_t last_meas_time
last measurement time in ms
Definition: ak8975.h:66
AK_STATUS_DONE
@ AK_STATUS_DONE
Definition: ak8975.h:56
Ak8975ConfStatus
Ak8975ConfStatus
config status states
Definition: ak8975.h:44
pprz_algebra_int.h
Paparazzi fixed point algebra.
AK_STATUS_MEAS
@ AK_STATUS_MEAS
Definition: ak8975.h:54
std.h
AK_DISABLE_ACCESS_CALIBRATION
@ AK_DISABLE_ACCESS_CALIBRATION
Definition: ak8975.h:47
ak8975_event
void ak8975_event(struct Ak8975 *ak)
Definition: ak8975.c:131
int16_t
signed short int16_t
Definition: types.h:17
uint8_t
unsigned char uint8_t
Definition: types.h:14
ak8975_configure
void ak8975_configure(struct Ak8975 *ak)
Definition: ak8975.c:63
ak8975_init
void ak8975_init(struct Ak8975 *ak, struct i2c_periph *i2c_p, uint8_t addr)
Definition: ak8975.c:47
ak8975_periodic
static void ak8975_periodic(struct Ak8975 *ak)
convenience function: read or start configuration if not already initialized
Definition: ak8975.h:83
AK_STATUS_READ
@ AK_STATUS_READ
Definition: ak8975.h:55
i2c_transaction
I2C transaction structure.
Definition: i2c.h:93
Ak8975::init_status
enum Ak8975ConfStatus init_status
init status
Definition: ak8975.h:65
Ak8975::initialized
bool initialized
config done flag
Definition: ak8975.h:62
AK_CONF_UNINIT
@ AK_CONF_UNINIT
Definition: ak8975.h:45
AK_REQ_CALIBRATION
@ AK_REQ_CALIBRATION
Definition: ak8975.h:46
Ak8975::status
enum Ak8975Status status
main status
Definition: ak8975.h:64
AK_CONF_REQUESTED
@ AK_CONF_REQUESTED
Definition: ak8975.h:48
Ak8975::data_available
volatile bool data_available
data ready flag
Definition: ak8975.h:68
i2c_periph
Definition: i2c.h:144
i2c.h
Ak8975::i2c_p
struct i2c_periph * i2c_p
peripheral used for communcation
Definition: ak8975.h:60