Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
ak8963.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014 Freek van Tienen <freek.v.tienen@gmail.com>
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, write to
18  * the Free Software Foundation, 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21 
28 #ifndef AK8963_H
29 #define AK8963_H
30 
31 #include "std.h"
32 #include "mcu_periph/i2c.h"
33 #include "math/pprz_algebra_int.h"
34 
35 /* Address and register definitions */
37 
43 };
44 
50 };
51 
53 struct Ak8963 {
54  struct i2c_periph *i2c_p;
55  struct i2c_transaction i2c_trans;
56  bool initialized;
57 
58  enum Ak8963Status status;
60 
61  volatile bool data_available;
62  union {
63  struct Int16Vect3 vect;
64  int16_t value[3];
65  } data;
66 };
67 
68 // Functions
69 extern void ak8963_init(struct Ak8963 *ak, struct i2c_periph *i2c_p, uint8_t addr);
70 extern void ak8963_configure(struct Ak8963 *ak);
71 extern void ak8963_event(struct Ak8963 *ak);
72 extern void ak8963_read(struct Ak8963 *ak);
73 
75 static inline void ak8963_periodic(struct Ak8963 *ak)
76 {
77  if (ak->initialized) {
78  ak8963_read(ak);
79  } else {
80  ak8963_configure(ak);
81  }
82 }
83 
84 #endif /* AK8963_H */
void ak8963_event(struct Ak8963 *ak)
Definition: ak8963.c:95
enum Ak8963Status status
main status
Definition: ak8963.h:58
void ak8963_configure(struct Ak8963 *ak)
Definition: ak8963.c:46
Ak8963Status
Normal status states.
Definition: ak8963.h:46
@ AK_STATUS_IDLE
Definition: ak8963.h:47
@ AK_STATUS_DONE
Definition: ak8963.h:49
@ AK_STATUS_READ
Definition: ak8963.h:48
struct i2c_transaction i2c_trans
i2c transaction used for communication with the ak8936
Definition: ak8963.h:55
enum Ak8963ConfStatus init_status
init status
Definition: ak8963.h:59
bool initialized
config done flag
Definition: ak8963.h:56
volatile bool data_available
data ready flag
Definition: ak8963.h:61
union Ak8963::@310 data
struct i2c_periph * i2c_p
peripheral used for communcation
Definition: ak8963.h:54
void ak8963_init(struct Ak8963 *ak, struct i2c_periph *i2c_p, uint8_t addr)
Initialize AK8963 struct.
Definition: ak8963.c:34
static void ak8963_periodic(struct Ak8963 *ak)
convenience function: read or start configuration if not already initialized
Definition: ak8963.h:75
Ak8963ConfStatus
Config status states.
Definition: ak8963.h:39
@ AK_CONF_MODE
Definition: ak8963.h:41
@ AK_CONF_UNINIT
Definition: ak8963.h:40
@ AK_CONF_DONE
Definition: ak8963.h:42
void ak8963_read(struct Ak8963 *ak)
Definition: ak8963.c:83
Default Ak8963 structure.
Definition: ak8963.h:53
I2C transaction structure.
Definition: i2c.h:93
Architecture independent I2C (Inter-Integrated Circuit Bus) API.
Paparazzi fixed point algebra.
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