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 {
46 };
47 
55 };
56 
60 };
61 
62 struct Hmc58xx {
63  struct i2c_periph *i2c_p;
65  bool initialized;
67  volatile bool data_available;
68  union {
69  struct Int16Vect3 vect;
70  int16_t value[3];
71  } data;
72  struct Hmc58xxConfig config;
73  enum Hmc58xxType type;
75 };
76 
77 
78 // TODO IRQ handling
79 
80 // Functions
81 extern void hmc58xx_init(struct Hmc58xx *hmc, struct i2c_periph *i2c_p, uint8_t addr);
82 extern void hmc58xx_start_configure(struct Hmc58xx *hmc);
83 extern void hmc58xx_read(struct Hmc58xx *hmc);
84 extern void hmc58xx_event(struct Hmc58xx *hmc);
85 
87 static inline void hmc58xx_periodic(struct Hmc58xx *hmc)
88 {
89  if (hmc->initialized) {
90  hmc58xx_read(hmc);
91  } else {
93  }
94 }
95 
96 #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:83
bool initialized
config done flag
Definition: hmc58xx.h:65
static void hmc58xx_periodic(struct Hmc58xx *hmc)
convenience function: read or start configuration if not already initialized
Definition: hmc58xx.h:87
union Hmc58xx::@323 data
enum Hmc58xxType type
Definition: hmc58xx.h:73
struct i2c_periph * i2c_p
Definition: hmc58xx.h:63
struct i2c_transaction i2c_trans
Definition: hmc58xx.h:64
void hmc58xx_event(struct Hmc58xx *hmc)
Definition: hmc58xx.c:160
Hmc58xxType
Definition: hmc58xx.h:57
@ HMC_TYPE_5883
Definition: hmc58xx.h:59
@ HMC_TYPE_5843
Definition: hmc58xx.h:58
uint8_t samples_averaged
Number of samples averaged per measurement output.
Definition: hmc58xx.h:44
uint8_t temp_comp
Enable temperature sensor (only on HMC5983)
Definition: hmc58xx.h:45
Hmc58xxConfStatus
config status states
Definition: hmc58xx.h:49
@ HMC_CONF_MODE
Definition: hmc58xx.h:53
@ HMC_CONF_UNINIT
Definition: hmc58xx.h:50
@ HMC_CONF_DONE
Definition: hmc58xx.h:54
@ HMC_CONF_CRB
Definition: hmc58xx.h:52
@ HMC_CONF_CRA
Definition: hmc58xx.h:51
uint8_t meas
Measurement configuration.
Definition: hmc58xx.h:41
uint8_t gain
Gain configuration (1 -> +- 1 Gauss)
Definition: hmc58xx.h:42
void hmc58xx_read(struct Hmc58xx *hmc)
Definition: hmc58xx.c:147
void hmc58xx_start_configure(struct Hmc58xx *hmc)
Definition: hmc58xx.c:134
struct Hmc58xxConfig config
Definition: hmc58xx.h:72
enum Hmc58xxConfStatus init_status
init status
Definition: hmc58xx.h:66
volatile bool data_available
data ready flag
Definition: hmc58xx.h:67
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:74
Register defs for Honeywell HMC5843, HMC5883 and HMC5983 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