Paparazzi UAS  v5.18.0_stable
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;
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 */
Hmc58xx::type
enum Hmc58xxType type
Definition: hmc58xx.h:71
Int16Vect3
Definition: pprz_algebra_int.h:62
HMC_TYPE_5883
@ HMC_TYPE_5883
Definition: hmc58xx.h:57
uint16_t
unsigned short uint16_t
Definition: types.h:16
Hmc58xxConfig::mode
uint8_t mode
Measurement mode.
Definition: hmc58xx.h:43
Hmc58xx::data
union Hmc58xx::@317 data
HMC_CONF_MODE
@ HMC_CONF_MODE
Definition: hmc58xx.h:51
Hmc58xx::i2c_trans
struct i2c_transaction i2c_trans
Definition: hmc58xx.h:62
HMC_CONF_DONE
@ HMC_CONF_DONE
Definition: hmc58xx.h:52
Hmc58xxConfig::meas
uint8_t meas
Measurement configuration.
Definition: hmc58xx.h:41
Hmc58xx::init_status
enum Hmc58xxConfStatus init_status
init status
Definition: hmc58xx.h:64
Hmc58xxConfig::gain
uint8_t gain
Gain configuration (1 -> +- 1 Gauss)
Definition: hmc58xx.h:42
HMC_CONF_UNINIT
@ HMC_CONF_UNINIT
Definition: hmc58xx.h:48
pprz_algebra_int.h
Paparazzi fixed point algebra.
hmc58xx_read
void hmc58xx_read(struct Hmc58xx *hmc)
Definition: hmc58xx.c:139
hmc58xx_regs.h
std.h
hmc58xx_start_configure
void hmc58xx_start_configure(struct Hmc58xx *hmc)
Definition: hmc58xx.c:126
Hmc58xxConfig
Definition: hmc58xx.h:39
int16_t
signed short int16_t
Definition: types.h:17
uint8_t
unsigned char uint8_t
Definition: types.h:14
hmc58xx_periodic
static void hmc58xx_periodic(struct Hmc58xx *hmc)
convenience function: read or start configuration if not already initialized
Definition: hmc58xx.h:85
Hmc58xxConfStatus
Hmc58xxConfStatus
config status states
Definition: hmc58xx.h:47
HMC_CONF_CRB
@ HMC_CONF_CRB
Definition: hmc58xx.h:50
i2c_transaction
I2C transaction structure.
Definition: i2c.h:93
Hmc58xx::adc_overflow_cnt
uint16_t adc_overflow_cnt
counts number of ADC measurement under/overflows
Definition: hmc58xx.h:72
HMC_TYPE_5843
@ HMC_TYPE_5843
Definition: hmc58xx.h:56
Hmc58xxConfig::rate
uint8_t rate
Data Output Rate Bits(6 -> 50Hz with HMC5843, 75Hz with HMC5883)
Definition: hmc58xx.h:40
Hmc58xx
Definition: hmc58xx.h:60
hmc58xx_event
void hmc58xx_event(struct Hmc58xx *hmc)
Definition: hmc58xx.c:152
HMC_CONF_CRA
@ HMC_CONF_CRA
Definition: hmc58xx.h:49
hmc58xx_init
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
Hmc58xx::config
struct Hmc58xxConfig config
Definition: hmc58xx.h:70
Hmc58xx::data_available
volatile bool data_available
data ready flag
Definition: hmc58xx.h:65
Hmc58xx::i2c_p
struct i2c_periph * i2c_p
Definition: hmc58xx.h:61
i2c_periph
Definition: i2c.h:144
i2c.h
Hmc58xxType
Hmc58xxType
Definition: hmc58xx.h:55
Hmc58xx::initialized
bool initialized
config done flag
Definition: hmc58xx.h:63