Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
hmc58xx.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2011 Gautier Hattenberger <gautier.hattenberger@enac.fr>
3  * 2013 Felix Ruess <felix.ruess@gmail.com>
4  *
5  * This file is part of paparazzi.
6  *
7  * paparazzi is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2, or (at your option)
10  * any later version.
11  *
12  * paparazzi is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with paparazzi; see the file COPYING. If not, write to
19  * the Free Software Foundation, 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */
22 
29 #ifndef HMC58XX_H
30 #define HMC58XX_H
31 
32 #include "std.h"
33 #include "mcu_periph/i2c.h"
34 #include "math/pprz_algebra_int.h"
35 
36 /* Address and register definitions */
38 
39 struct Hmc58xxConfig {
44 };
45 
53 };
54 
58 };
59 
60 struct Hmc58xx {
61  struct i2c_periph *i2c_p;
63  bool initialized;
65  volatile bool data_available;
66  union {
67  struct Int16Vect3 vect;
68  int16_t value[3];
69  } data;
70  struct Hmc58xxConfig config;
71  enum Hmc58xxType type;
73 };
74 
75 
76 // TODO IRQ handling
77 
78 // Functions
79 extern void hmc58xx_init(struct Hmc58xx *hmc, struct i2c_periph *i2c_p, uint8_t addr);
80 extern void hmc58xx_start_configure(struct Hmc58xx *hmc);
81 extern void hmc58xx_read(struct Hmc58xx *hmc);
82 extern void hmc58xx_event(struct Hmc58xx *hmc);
83 
85 static inline void hmc58xx_periodic(struct Hmc58xx *hmc)
86 {
87  if (hmc->initialized) {
88  hmc58xx_read(hmc);
89  } else {
91  }
92 }
93 
94 #endif /* HMC58XX_H */
I2C transaction structure.
Definition: i2c.h:93
uint8_t mode
Measurement mode.
Definition: hmc58xx.h:43
void hmc58xx_init(struct Hmc58xx *hmc, struct i2c_periph *i2c_p, uint8_t addr)
Initialize Hmc58xx struct and set default config options.
Definition: hmc58xx.c:75
bool initialized
config done flag
Definition: hmc58xx.h:63
static void hmc58xx_periodic(struct Hmc58xx *hmc)
convenience function: read or start configuration if not already initialized
Definition: hmc58xx.h:85
enum Hmc58xxType type
Definition: hmc58xx.h:71
struct i2c_periph * i2c_p
Definition: hmc58xx.h:61
struct i2c_transaction i2c_trans
Definition: hmc58xx.h:62
void hmc58xx_event(struct Hmc58xx *hmc)
Definition: hmc58xx.c:152
Hmc58xxType
Definition: hmc58xx.h:55
@ HMC_TYPE_5883
Definition: hmc58xx.h:57
@ HMC_TYPE_5843
Definition: hmc58xx.h:56
Hmc58xxConfStatus
config status states
Definition: hmc58xx.h:47
@ HMC_CONF_MODE
Definition: hmc58xx.h:51
@ HMC_CONF_UNINIT
Definition: hmc58xx.h:48
@ HMC_CONF_DONE
Definition: hmc58xx.h:52
@ HMC_CONF_CRB
Definition: hmc58xx.h:50
@ HMC_CONF_CRA
Definition: hmc58xx.h:49
uint8_t meas
Measurement configuration.
Definition: hmc58xx.h:41
union Hmc58xx::@321 data
uint8_t gain
Gain configuration (1 -> +- 1 Gauss)
Definition: hmc58xx.h:42
void hmc58xx_read(struct Hmc58xx *hmc)
Definition: hmc58xx.c:139
void hmc58xx_start_configure(struct Hmc58xx *hmc)
Definition: hmc58xx.c:126
struct Hmc58xxConfig config
Definition: hmc58xx.h:70
enum Hmc58xxConfStatus init_status
init status
Definition: hmc58xx.h:64
volatile bool data_available
data ready flag
Definition: hmc58xx.h:65
uint8_t rate
Data Output Rate Bits(6 -> 50Hz with HMC5843, 75Hz with HMC5883)
Definition: hmc58xx.h:40
uint16_t adc_overflow_cnt
counts number of ADC measurement under/overflows
Definition: hmc58xx.h:72
Register defs for Honeywell HMC5843 and HMC5883 magnetometers.
Architecture independent I2C (Inter-Integrated Circuit Bus) API.
Paparazzi fixed point algebra.
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
Definition: vl53l1_types.h:88
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