Paparazzi UAS  v4.0.4_stable-3-gf39211a
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
hmc58xx.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright (C) 2011 Gautier Hattenberger
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 
23 /* Driver for HMC5843 and HMC5883
24  */
25 
26 #ifndef HMC58XX_H
27 #define HMC58XX_H
28 
29 #include "std.h"
30 #include "mcu_periph/i2c.h"
31 #include "math/pprz_algebra_int.h"
32 
33 /* default I2C address */
34 #define HMC58XX_ADDR 0x3C
35 
36 /* Registers */
37 #define HMC58XX_REG_CFGA 0x00
38 #define HMC58XX_REG_CFGB 0x01
39 #define HMC58XX_REG_MODE 0x02
40 #define HMC58XX_REG_DATXM 0x03
41 #define HMC58XX_REG_DATXL 0x04
42 #define HMC58XX_REG_DATYM 0x05
43 #define HMC58XX_REG_DATYL 0x06
44 #define HMC58XX_REG_DATZM 0x07
45 #define HMC58XX_REG_DATZL 0x08
46 #define HMC58XX_REG_STATUS 0x09
47 #define HMC58XX_REG_IDA 0x0A
48 #define HMC58XX_REG_IDB 0x0B
49 #define HMC58XX_REG_IDC 0x0C
50 
51 /* HMC58XX default conf */
52 #ifndef HMC58XX_DO
53 #define HMC58XX_DO 0x6 // Data Output Rate (6 -> 50Hz with HMC5843, 75Hz with HMC5883)
54 #endif
55 #ifndef HMC58XX_MS
56 #define HMC58XX_MS 0x0 // Measurement configuration
57 #endif
58 #ifndef HMC58XX_GN
59 #define HMC58XX_GN 0x1 // Gain configuration (1 -> +- 1 Gauss)
60 #endif
61 #ifndef HMC58XX_MD
62 #define HMC58XX_MD 0x0 // Continious measurement mode
63 #endif
64 
65 #define HMC58XX_CRA ((HMC58XX_DO<<2)|(HMC58XX_MS))
66 #define HMC58XX_CRB (HMC58XX_GN<<5)
67 
68 /* Default I2C device is i2c2 (for lisa) */
69 #ifndef HMC58XX_I2C_DEVICE
70 #define HMC58XX_I2C_DEVICE i2c2
71 #endif
72 
73 // Config done flag
74 extern bool_t hmc58xx_initialized;
75 // Data ready flag
76 extern volatile bool_t hmc58xx_data_available;
77 // Data vector
78 extern struct Int16Vect3 hmc58xx_data;
79 // I2C transaction structure
81 
82 // TODO IRQ handling
83 
84 // Functions
85 extern void hmc58xx_init(void);
86 extern void hmc58xx_configure(void);
87 extern void hmc58xx_read(void);
88 extern void hmc58xx_event(void);
89 
90 // Macro for using HMC58XX in periodic function
91 #define Hmc58xxPeriodic() { \
92  if (hmc58xx_initialized) hmc58xx_read(); \
93  else hmc58xx_configure(); \
94 }
95 
96 #define MagEvent(_m_handler) { \
97  hmc58xx_event(); \
98  if (hmc58xx_data_available) { \
99  _m_handler(); \
100  } \
101  }
102 
103 #endif /* HMC58XX_H */
void hmc58xx_event(void)
Definition: hmc58xx.c:109
struct Int16Vect3 hmc58xx_data
Definition: hmc58xx.c:39
bool_t hmc58xx_initialized
Definition: hmc58xx.c:43
void hmc58xx_configure(void)
Definition: hmc58xx.c:88
struct i2c_transaction hmc58xx_i2c_trans
Definition: hmc58xx.c:41
void hmc58xx_init(void)
Definition: hmc58xx.c:48
volatile bool_t hmc58xx_data_available
Definition: hmc58xx.c:37
void hmc58xx_read(void)
Definition: hmc58xx.c:99
Paparazzi fixed point algebra.