dRonin  adbada4
dRonin firmware
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
pios_hmc5883_priv.h
Go to the documentation of this file.
1 
16 /*
17  * This program is free software; you can redistribute it and/or modify
18  * it under the terms of the GNU General Public License as published by
19  * the Free Software Foundation; either version 3 of the License, or
20  * (at your option) any later version.
21  *
22  * This program is distributed in the hope that it will be useful, but
23  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
24  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
25  * for more details.
26  *
27  * You should have received a copy of the GNU General Public License along
28  * with this program; if not, see <http://www.gnu.org/licenses/>
29  */
30 
31 #ifndef PIOS_HMC5883_H
32 #define PIOS_HMC5883_H
33 
34 #include <stdint.h>
35 #include <stdbool.h>
36 
37 /* HMC5883 Addresses */
38 #define PIOS_HMC5883_I2C_ADDR 0x1E
39 #define PIOS_HMC5883_I2C_READ_ADDR 0x3D
40 #define PIOS_HMC5883_I2C_WRITE_ADDR 0x3C
41 #define PIOS_HMC5883_CONFIG_REG_A (uint8_t)0x00
42 #define PIOS_HMC5883_CONFIG_REG_B (uint8_t)0x01
43 #define PIOS_HMC5883_MODE_REG (uint8_t)0x02
44 #define PIOS_HMC5883_DATAOUT_XMSB_REG 0x03
45 #define PIOS_HMC5883_DATAOUT_XLSB_REG 0x04
46 #define PIOS_HMC5883_DATAOUT_ZMSB_REG 0x05
47 #define PIOS_HMC5883_DATAOUT_ZLSB_REG 0x06
48 #define PIOS_HMC5883_DATAOUT_YMSB_REG 0x07
49 #define PIOS_HMC5883_DATAOUT_YLSB_REG 0x08
50 #define PIOS_HMC5883_DATAOUT_STATUS_REG 0x09
51 #define PIOS_HMC5883_DATAOUT_IDA_REG 0x0A
52 #define PIOS_HMC5883_DATAOUT_IDB_REG 0x0B
53 #define PIOS_HMC5883_DATAOUT_IDC_REG 0x0C
54 
55 /* Output Data Rate */
56 #define PIOS_HMC5883_ODR_0_75 0x00
57 #define PIOS_HMC5883_ODR_1_5 0x04
58 #define PIOS_HMC5883_ODR_3 0x08
59 #define PIOS_HMC5883_ODR_7_5 0x0C
60 #define PIOS_HMC5883_ODR_15 0x10
61 #define PIOS_HMC5883_ODR_30 0x14
62 #define PIOS_HMC5883_ODR_75 0x18
63 
64 /* Measure configuration */
65 #define PIOS_HMC5883_MEASCONF_NORMAL 0x00
66 #define PIOS_HMC5883_MEASCONF_BIAS_POS 0x01
67 #define PIOS_HMC5883_MEASCONF_BIAS_NEG 0x02
68 
69 /* Gain settings */
70 #define PIOS_HMC5883_GAIN_0_88 0x00
71 #define PIOS_HMC5883_GAIN_1_3 0x20
72 #define PIOS_HMC5883_GAIN_1_9 0x40
73 #define PIOS_HMC5883_GAIN_2_5 0x60
74 #define PIOS_HMC5883_GAIN_4_0 0x80
75 #define PIOS_HMC5883_GAIN_4_7 0xA0
76 #define PIOS_HMC5883_GAIN_5_6 0xC0
77 #define PIOS_HMC5883_GAIN_8_1 0xE0
78 
79 /* Modes */
80 #define PIOS_HMC5883_MODE_CONTINUOUS 0x00
81 #define PIOS_HMC5883_MODE_SINGLE 0x01
82 #define PIOS_HMC5883_MODE_IDLE 0x02
83 #define PIOS_HMC5883_MODE_SLEEP 0x03
84 
85 /* Sensitivity Conversion Values */
94  PIOS_HMC5883_Sensitivity_8_1Ga = 230, // LSB/Ga --> NOT RECOMMENDED
95 };
96 
98  // clockwise rotation from board forward while looking at top side
99  // 0 degree is chip mark on upper left corner
104  // clockwise rotation from board forward while looking at bottom side
105  // 0 degree is chip mark on upper left corner
110 };
111 
113  const struct pios_exti_cfg * exti_cfg; /* Pointer to the EXTI configuration */
114  uint8_t M_ODR; /* OUTPUT DATA RATE --> here below the relative define (See datasheet page 11 for more details) */
115  uint8_t Meas_Conf; /* Measurement Configuration,: Normal, positive bias, or negative bias --> here below the relative define */
116  uint8_t Gain; /* Gain Configuration, select the full scale --> here below the relative define (See datasheet page 11 for more details) */
117  uint8_t Mode;
119 };
120 
122  int16_t mag_x;
123  int16_t mag_y;
124  int16_t mag_z;
125 };
126 
127 /* Public Functions */
128 extern int32_t PIOS_HMC5883_Init(pios_i2c_t i2c_id,
129  const struct pios_hmc5883_cfg * cfg);
130 extern int32_t PIOS_HMC5883_Test(void);
131 extern int32_t PIOS_HMC5883_SetOrientation(enum pios_hmc5883_orientation orientation);
132 extern bool PIOS_HMC5883_IRQHandler();
133 #endif /* PIOS_HMC5883_H */
134 
const struct pios_exti_cfg * exti_cfg
int32_t PIOS_HMC5883_SetOrientation(enum pios_hmc5883_orientation orientation)
pios_hmc5883_orientation
int32_t PIOS_HMC5883_Test(void)
bool PIOS_HMC5883_IRQHandler()
static struct flyingpicmd_cfg_fa cfg
Definition: main.c:49
struct pios_i2c_adapter * pios_i2c_t
Definition: pios_i2c.h:48
pios_hmc5883_sensitivity
int32_t PIOS_HMC5883_Init(pios_i2c_t i2c_id, const struct pios_hmc5883_cfg *cfg)
enum pios_hmc5883_orientation Default_Orientation