dRonin  adbada4
dRonin firmware
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
pios_hmc5983.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_HMC5983_H
32 #define PIOS_HMC5983_H
33 
34 #include <pios.h>
35 
36 /* HMC5983 Addresses */
37 #define PIOS_HMC5983_I2C_ADDR 0x1E
38 #define PIOS_HMC5983_I2C_READ_ADDR 0x3D
39 #define PIOS_HMC5983_I2C_WRITE_ADDR 0x3C
40 #define PIOS_HMC5983_CONFIG_REG_A (uint8_t)0x00
41 #define PIOS_HMC5983_CONFIG_REG_B (uint8_t)0x01
42 #define PIOS_HMC5983_MODE_REG (uint8_t)0x02
43 #define PIOS_HMC5983_DATAOUT_XMSB_REG 0x03
44 #define PIOS_HMC5983_DATAOUT_XLSB_REG 0x04
45 #define PIOS_HMC5983_DATAOUT_ZMSB_REG 0x05
46 #define PIOS_HMC5983_DATAOUT_ZLSB_REG 0x06
47 #define PIOS_HMC5983_DATAOUT_YMSB_REG 0x07
48 #define PIOS_HMC5983_DATAOUT_YLSB_REG 0x08
49 #define PIOS_HMC5983_DATAOUT_STATUS_REG 0x09
50 #define PIOS_HMC5983_DATAOUT_IDA_REG 0x0A
51 #define PIOS_HMC5983_DATAOUT_IDB_REG 0x0B
52 #define PIOS_HMC5983_DATAOUT_IDC_REG 0x0C
53 #define PIOS_HMC5983_DATAOUT_TEMPMSB_REG 0x31
54 #define PIOS_HMC5983_DATAOUT_TEMPLSB_REG 0x32
55 
56 /* Output Data Rate */
57 #define PIOS_HMC5983_ODR_0_75 0x00
58 #define PIOS_HMC5983_ODR_1_5 0x04
59 #define PIOS_HMC5983_ODR_3 0x08
60 #define PIOS_HMC5983_ODR_7_5 0x0C
61 #define PIOS_HMC5983_ODR_15 0x10
62 #define PIOS_HMC5983_ODR_30 0x14
63 #define PIOS_HMC5983_ODR_75 0x18
64 #define PIOS_HMC5983_ODR_220 0x1c
65 
66 /* Measure configuration */
67 #define PIOS_HMC5983_MEASCONF_NORMAL 0x00
68 #define PIOS_HMC5983_MEASCONF_BIAS_POS 0x01
69 #define PIOS_HMC5983_MEASCONF_BIAS_NEG 0x02
70 
71 /* Gain settings */
72 #define PIOS_HMC5983_GAIN_0_88 0x00
73 #define PIOS_HMC5983_GAIN_1_3 0x20
74 #define PIOS_HMC5983_GAIN_1_9 0x40
75 #define PIOS_HMC5983_GAIN_2_5 0x60
76 #define PIOS_HMC5983_GAIN_4_0 0x80
77 #define PIOS_HMC5983_GAIN_4_7 0xA0
78 #define PIOS_HMC5983_GAIN_5_6 0xC0
79 #define PIOS_HMC5983_GAIN_8_1 0xE0
80 
81 /* Modes */
82 #define PIOS_HMC5983_MODE_CONTINUOUS 0x00
83 #define PIOS_HMC5983_MODE_SINGLE 0x01
84 #define PIOS_HMC5983_MODE_IDLE 0x02
85 #define PIOS_HMC5983_MODE_SLEEP 0x03
86 
87 /* Sensitivity Conversion Values */
88 #define PIOS_HMC5983_Sensitivity_0_88Ga 1370 // LSB/Ga
89 #define PIOS_HMC5983_Sensitivity_1_3Ga 1090 // LSB/Ga
90 #define PIOS_HMC5983_Sensitivity_1_9Ga 820 // LSB/Ga
91 #define PIOS_HMC5983_Sensitivity_2_5Ga 660 // LSB/Ga
92 #define PIOS_HMC5983_Sensitivity_4_0Ga 440 // LSB/Ga
93 #define PIOS_HMC5983_Sensitivity_4_7Ga 390 // LSB/Ga
94 #define PIOS_HMC5983_Sensitivity_5_6Ga 330 // LSB/Ga
95 #define PIOS_HMC5983_Sensitivity_8_1Ga 230 // LSB/Ga --> NOT RECOMMENDED
96 
97 #define PIOS_HMC5983_AVERAGING_1 0x00
98 #define PIOS_HMC5983_AVERAGING_2 0x20
99 #define PIOS_HMC5983_AVERAGING_4 0x40
100 #define PIOS_HMC5983_AVERAGING_8 0x60
101 
102 #define PIOS_HMC5983_READ_MODE 0xC0
103 #define PIOS_HMC5983_ENABLE_TEMP_SENSOR 0x80
104 
106  // clockwise rotation from board forward while looking at top side
107  // 0 degree is chip mark on upper left corner
112  // clockwise rotation from board forward while looking at bottom side
113  // 0 degree is chip mark on upper left corner
118 };
119 
121  const struct pios_exti_cfg * exti_cfg; /* Pointer to the EXTI configuration */
122  uint8_t M_ODR; /* OUTPUT DATA RATE --> here below the relative define (See datasheet page 11 for more details) */
123  uint8_t Meas_Conf; /* Measurement Configuration,: Normal, positive bias, or negative bias --> here below the relative define */
124  uint8_t Gain; /* Gain Configuration, select the full scale --> here below the relative define (See datasheet page 11 for more details) */
125  uint8_t Averaging; /* Averaging configuration */
126  uint8_t Mode;
128 };
129 
130 /* Public Functions */
131 extern int32_t PIOS_HMC5983_Init(pios_spi_t spi_id, uint32_t slave_num, const struct pios_hmc5983_cfg *cfg);
132 extern bool PIOS_HMC5983_IRQHandler(void);
133 
134 #if defined(PIOS_INCLUDE_HMC5983_I2C)
135 int32_t PIOS_HMC5983_I2C_Init(pios_i2c_t i2c_id,
136  const struct pios_hmc5983_cfg *cfg);
137 extern int32_t PIOS_HMC5983_Test(void);
138 extern int32_t PIOS_HMC5983_SetOrientation(enum pios_hmc5983_orientation orientation);
139 #endif /* PIOS_INCLUDE_HMC5983_I2C */
140 
141 
142 #endif /* PIOS_HMC5983_H */
143 
pios_hmc5983_orientation
Definition: pios_hmc5983.h:105
Main PiOS header to include all the compiled in PiOS options.
static struct flyingpicmd_cfg_fa cfg
Definition: main.c:49
enum pios_hmc5983_orientation Orientation
Definition: pios_hmc5983.h:127
const struct pios_exti_cfg * exti_cfg
Definition: pios_hmc5983.h:121
struct pios_i2c_adapter * pios_i2c_t
Definition: pios_i2c.h:48
bool PIOS_HMC5983_IRQHandler(void)
int32_t PIOS_HMC5983_Init(pios_spi_t spi_id, uint32_t slave_num, const struct pios_hmc5983_cfg *cfg)