amiro-lld / include / alld_hmc5883l.h @ e2db16a4
History | View | Annotate | Download (5.759 KB)
1 |
/*
|
---|---|
2 |
AMiRo-LLD is a compilation of low-level hardware drivers for the Autonomous Mini Robot (AMiRo) platform.
|
3 |
Copyright (C) 2016..2018 Thomas Schöpping et al.
|
4 |
|
5 |
This program is free software: you can redistribute it and/or modify
|
6 |
it under the terms of the GNU General Public License as published by
|
7 |
the Free Software Foundation, either version 3 of the License, or
|
8 |
(at your option) any later version.
|
9 |
|
10 |
This program is distributed in the hope that it will be useful,
|
11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
GNU General Public License for more details.
|
14 |
|
15 |
You should have received a copy of the GNU General Public License
|
16 |
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
17 |
*/
|
18 |
|
19 |
#ifndef _AMIROLLD_HMC5883L_H_
|
20 |
#define _AMIROLLD_HMC5883L_H_
|
21 |
|
22 |
#include <amiro-lld.h> |
23 |
|
24 |
#if defined(AMIROLLD_CFG_USE_HMC5883L) || defined(__DOXYGEN__)
|
25 |
|
26 |
/**
|
27 |
* @brief The HMC5883L driver struct
|
28 |
*/
|
29 |
typedef struct { |
30 |
apalI2CDriver_t* i2cd; /**< @brief The I2C Driver */
|
31 |
} HMC5883LDriver; |
32 |
|
33 |
/**
|
34 |
* @brief Constant I2C address.
|
35 |
*/
|
36 |
#define HMC5883L_LLD_I2C_ADDR 0x1Eu |
37 |
|
38 |
/**
|
39 |
* @brief Maximum I2C frequency.
|
40 |
*/
|
41 |
#define HMC5883L_LLD_I2C_MAXFREQUENCY 400000 |
42 |
|
43 |
/**
|
44 |
* @brief A falling edge indicates an interrupt.
|
45 |
*/
|
46 |
#define HMC5883L_LLD_INT_EDGE APAL_GPIO_EDGE_FALLING
|
47 |
|
48 |
/**
|
49 |
* @brief Register enum.
|
50 |
*/
|
51 |
typedef enum { |
52 |
HMC5883L_LLD_REGISTER_CONFIG_A = 0x00u,
|
53 |
HMC5883L_LLD_REGISTER_CONFIG_B = 0x01u,
|
54 |
HMC5883L_LLD_REGISTER_MODE = 0x02u,
|
55 |
HMC5883L_LLD_REGISTER_DATA_OUT_X_MSB = 0x03u,
|
56 |
HMC5883L_LLD_REGISTER_DATA_OUT_X_LSB = 0x04u,
|
57 |
HMC5883L_LLD_REGISTER_DATA_OUT_Z_MSB = 0x05u,
|
58 |
HMC5883L_LLD_REGISTER_DATA_OUT_Z_LSB = 0x06u,
|
59 |
HMC5883L_LLD_REGISTER_DATA_OUT_Y_MSB = 0x07u,
|
60 |
HMC5883L_LLD_REGISTER_DATA_OUT_Y_LSB = 0x08u,
|
61 |
HMC5883L_LLD_REGISTER_STATUS = 0x09u,
|
62 |
HMC5883L_LLD_REGISTER_IDENTIFICATION_A = 0x0Au,
|
63 |
HMC5883L_LLD_REGISTER_IDENTIFICATION_B = 0x0Bu,
|
64 |
HMC5883L_LLD_REGISTER_IDENTIFICATION_C = 0x0Cu,
|
65 |
} hmc5883l_lld_register_t; |
66 |
|
67 |
/**
|
68 |
* @brief Averaging options.
|
69 |
*/
|
70 |
typedef enum { |
71 |
HMC5883L_LLD_AVG1 = 0x00,
|
72 |
HMC5883L_LLD_AVG2 = 0x20,
|
73 |
HMC5883L_LLD_AVG4 = 0x40,
|
74 |
HMC5883L_LLD_AVG8 = 0x60,
|
75 |
} hmc5883l_lld_averaging_t; |
76 |
|
77 |
/**
|
78 |
* @brief Data output rate.
|
79 |
*/
|
80 |
typedef enum { |
81 |
HMC5883L_LLD_0_75_HZ = 0x00,
|
82 |
HMC5883L_LLD_1_5_HZ = 0x04,
|
83 |
HMC5883L_LLD_3_HZ = 0x08,
|
84 |
HMC5883L_LLD_7_5_HZ = 0x0C,
|
85 |
HMC5883L_LLD_15_HZ = 0x10,
|
86 |
HMC5883L_LLD_30_HZ = 0x14,
|
87 |
HMC5883L_LLD_75_HZ = 0x18,
|
88 |
} hmc5883l_lld_data_output_rate_t; |
89 |
|
90 |
/**
|
91 |
* @brief Measurement bias.
|
92 |
*/
|
93 |
typedef enum { |
94 |
HMC5883L_LLD_MB_NORMAL = 0x00,
|
95 |
HMC5883L_LLD_MB_POSITIVE_BIAS = 0x01,
|
96 |
HMC5883L_LLD_MB_NEGATIVE_BIAS = 0x02,
|
97 |
} hmc5883l_lld_measurement_bias_t; |
98 |
|
99 |
/**
|
100 |
* @brief Gain settings.
|
101 |
*/
|
102 |
typedef enum { |
103 |
HMC5883L_LLD_GN_0_GA = 0x00,
|
104 |
HMC5883L_LLD_GN_1_GA = 0x20,
|
105 |
HMC5883L_LLD_GN_2_GA = 0x40,
|
106 |
HMC5883L_LLD_GN_3_GA = 0x60,
|
107 |
HMC5883L_LLD_GN_4_GA = 0x80,
|
108 |
HMC5883L_LLD_GN_5_GA = 0xA0,
|
109 |
HMC5883L_LLD_GN_6_GA = 0xC0,
|
110 |
HMC5883L_LLD_GN_7_GA = 0xE0,
|
111 |
} hmc5883l_lld_gain_t; |
112 |
|
113 |
/**
|
114 |
* @brief Highspeed enable settings.
|
115 |
*/
|
116 |
typedef enum { |
117 |
HMC5883L_LLD_HS_DISABLE = 0x00,
|
118 |
HMC5883L_LLD_HS_ENABLE = 0x80,
|
119 |
} hmc5883l_lld_highspeed_t; |
120 |
|
121 |
/**
|
122 |
* @brief Measurement modes.
|
123 |
*/
|
124 |
typedef enum { |
125 |
HMC5883L_LLD_MM_CONTINUOUS = 0x00,
|
126 |
HMC5883L_LLD_MM_SINGLE = 0x01,
|
127 |
HMC5883L_LLD_MM_IDLE = 0x02,
|
128 |
} hmc5883l_lld_measurement_mode_t; |
129 |
|
130 |
/**
|
131 |
* @brief Read or write access.
|
132 |
*/
|
133 |
typedef enum { |
134 |
HMC5883L_LLD_READ = 0x3Du,
|
135 |
HMC5883L_LLD_WRITE = 0x3Cu,
|
136 |
} hmc5883l_lld_access_mode_t; |
137 |
|
138 |
/**
|
139 |
* @brief Status lock or ready.
|
140 |
*/
|
141 |
typedef enum { |
142 |
HMC5883L_LLD_LOCK = 0x0u,
|
143 |
HMC5883L_LLD_RDY = 0x1u,
|
144 |
} hmc5883l_lld_status_t; |
145 |
|
146 |
/**
|
147 |
* @brief Identification values.
|
148 |
*/
|
149 |
typedef enum { |
150 |
HMC5883L_LLD_IDENTIFICATION_A = 0x48,
|
151 |
HMC5883L_LLD_IDENTIFICATION_B = 0x34,
|
152 |
HMC5883L_LLD_IDENTIFICATION_C = 0x33,
|
153 |
} hmc5883l_lld_identification_t; |
154 |
|
155 |
/**
|
156 |
* @brief HMC5883L configuration struct.
|
157 |
*/
|
158 |
typedef struct { |
159 |
hmc5883l_lld_averaging_t avg; |
160 |
hmc5883l_lld_data_output_rate_t outrate; |
161 |
hmc5883l_lld_measurement_bias_t mbias; |
162 |
hmc5883l_lld_gain_t gain; |
163 |
hmc5883l_lld_highspeed_t highspeed; |
164 |
hmc5883l_lld_measurement_mode_t mode; |
165 |
} hmc5883l_lld_config_t; |
166 |
|
167 |
#ifdef __cplusplus
|
168 |
extern "C" { |
169 |
#endif
|
170 |
apalExitStatus_t hmc5883l_lld_check(const HMC5883LDriver* const hmcd, uint8_t* const rxbuffer, const uint8_t size, const apalTime_t timeout); |
171 |
apalExitStatus_t hmc5883l_lld_write_register(const HMC5883LDriver* const hmcd, const hmc5883l_lld_register_t regaddr, const uint8_t* const data, const uint8_t num, const apalTime_t timeout); |
172 |
apalExitStatus_t hmc5883l_lld_set_register(const HMC5883LDriver* const hmcd, const hmc5883l_lld_register_t regaddr, const uint8_t data, const apalTime_t timeout); |
173 |
apalExitStatus_t hmc5883l_lld_read_register(const HMC5883LDriver* const hmcd, const hmc5883l_lld_register_t regaddr, uint8_t* const data, const uint8_t num, const apalTime_t timeout); |
174 |
apalExitStatus_t hmc5883l_lld_read_data(const HMC5883LDriver* const hmcd, uint16_t* const data, const apalTime_t timeout); |
175 |
apalExitStatus_t hmc5883l_lld_write_config(const HMC5883LDriver* const hmcd, const hmc5883l_lld_config_t conf, const apalTime_t timeout); |
176 |
apalExitStatus_t hmc5883l_lld_read_config(const HMC5883LDriver* const hmcd, hmc5883l_lld_config_t* const conf, const apalTime_t timeout); |
177 |
apalExitStatus_t hmc5883l_lld_read_status(const HMC5883LDriver* const hmcd, uint8_t* const status, const apalTime_t timeout); |
178 |
apalExitStatus_t hmc5883l_lld_read_lock(const HMC5883LDriver* const hmcd, uint8_t* const lock, const apalTime_t timeout); |
179 |
apalExitStatus_t hmc5883l_lld_read_rdy(const HMC5883LDriver* const hmcd, uint8_t* const rdy, const apalTime_t timeout); |
180 |
#ifdef __cplusplus
|
181 |
} |
182 |
#endif
|
183 |
|
184 |
#endif /* defined(AMIROLLD_CFG_USE_HMC5883L) */ |
185 |
|
186 |
#endif /* _AMIROLLD_HMC5883L_H_ */ |