Statistics
| Branch: | Tag: | Revision:

amiro-lld / include / HMC5883L / v1 / alld_HMC5883L_v1.h @ 54dbb62d

History | View | Annotate | Download (7.634 KB)

1 d6728c5b Thomas Schöpping
/*
2
AMiRo-LLD is a compilation of low-level hardware drivers for the Autonomous Mini Robot (AMiRo) platform.
3 f125ae07 Thomas Schöpping
Copyright (C) 2016..2019  Thomas Schöpping et al.
4 d6728c5b Thomas Schöpping

5
This program is free software: you can redistribute it and/or modify
6 f0ca400f Thomas Schöpping
it under the terms of the GNU Lesser General Public License as published by
7 d6728c5b Thomas Schöpping
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 f0ca400f Thomas Schöpping
GNU Lesser General Public License for more details.
14 d6728c5b Thomas Schöpping

15 f0ca400f Thomas Schöpping
You should have received a copy of the GNU Lesser General Public License
16 d6728c5b Thomas Schöpping
along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
*/
18
19 5e2f673b Marc Rothmann
/**
20 1d5bcc82 Thomas Schöpping
 * @file    alld_HMC5883L_v1.h
21 5e2f673b Marc Rothmann
 * @brief   Compass macros and structures.
22
 *
23
 * @addtogroup lld_compass
24
 * @{
25
 */
26
27 1d5bcc82 Thomas Schöpping
#ifndef AMIROLLD_HMC5883L_V1_H
28
#define AMIROLLD_HMC5883L_V1_H
29 d6728c5b Thomas Schöpping
30
#include <amiro-lld.h>
31
32 1d5bcc82 Thomas Schöpping
#if (defined(AMIROLLD_CFG_HMC5883L) && (AMIROLLD_CFG_HMC5883L == 1)) || defined(__DOXYGEN__)
33 d6728c5b Thomas Schöpping
34 ef078306 Thomas Schöpping
/******************************************************************************/
35
/* CONSTANTS                                                                  */
36
/******************************************************************************/
37 d6728c5b Thomas Schöpping
38
/**
39
 * @brief Constant I2C address.
40
 */
41
#define HMC5883L_LLD_I2C_ADDR           0x1Eu
42
43
/**
44
 * @brief Maximum I2C frequency.
45
 */
46
#define HMC5883L_LLD_I2C_MAXFREQUENCY   400000
47
48
/**
49
 * @brief A falling edge indicates an interrupt.
50
 */
51
#define HMC5883L_LLD_INT_EDGE           APAL_GPIO_EDGE_FALLING
52
53 ef078306 Thomas Schöpping
/******************************************************************************/
54
/* SETTINGS                                                                   */
55
/******************************************************************************/
56
57
/******************************************************************************/
58
/* CHECKS                                                                     */
59
/******************************************************************************/
60
61
/******************************************************************************/
62
/* DATA STRUCTURES AND TYPES                                                  */
63
/******************************************************************************/
64
65
/**
66
 * @brief The HMC5883L driver struct
67
 */
68
typedef struct {
69
  apalI2CDriver_t* i2cd;        /**< @brief The I2C Driver */
70
} HMC5883LDriver;
71
72 d6728c5b Thomas Schöpping
/**
73
 * @brief Register enum.
74
 */
75
typedef enum {
76
  HMC5883L_LLD_REGISTER_CONFIG_A         = 0x00u,
77
  HMC5883L_LLD_REGISTER_CONFIG_B         = 0x01u,
78
  HMC5883L_LLD_REGISTER_MODE             = 0x02u,
79
  HMC5883L_LLD_REGISTER_DATA_OUT_X_MSB   = 0x03u,
80
  HMC5883L_LLD_REGISTER_DATA_OUT_X_LSB   = 0x04u,
81
  HMC5883L_LLD_REGISTER_DATA_OUT_Z_MSB   = 0x05u,
82
  HMC5883L_LLD_REGISTER_DATA_OUT_Z_LSB   = 0x06u,
83
  HMC5883L_LLD_REGISTER_DATA_OUT_Y_MSB   = 0x07u,
84
  HMC5883L_LLD_REGISTER_DATA_OUT_Y_LSB   = 0x08u,
85
  HMC5883L_LLD_REGISTER_STATUS           = 0x09u,
86
  HMC5883L_LLD_REGISTER_IDENTIFICATION_A = 0x0Au,
87
  HMC5883L_LLD_REGISTER_IDENTIFICATION_B = 0x0Bu,
88
  HMC5883L_LLD_REGISTER_IDENTIFICATION_C = 0x0Cu,
89
} hmc5883l_lld_register_t;
90
91
/**
92
 * @brief Averaging options.
93
 */
94
typedef enum {
95
  HMC5883L_LLD_AVG1 = 0x00,
96
  HMC5883L_LLD_AVG2 = 0x20,
97
  HMC5883L_LLD_AVG4 = 0x40,
98
  HMC5883L_LLD_AVG8 = 0x60,
99
} hmc5883l_lld_averaging_t;
100
101
/**
102
 * @brief Data output rate.
103
 */
104
typedef enum {
105
  HMC5883L_LLD_0_75_HZ = 0x00,
106
  HMC5883L_LLD_1_5_HZ  = 0x04,
107
  HMC5883L_LLD_3_HZ    = 0x08,
108
  HMC5883L_LLD_7_5_HZ  = 0x0C,
109
  HMC5883L_LLD_15_HZ   = 0x10,
110
  HMC5883L_LLD_30_HZ   = 0x14,
111
  HMC5883L_LLD_75_HZ   = 0x18,
112
} hmc5883l_lld_data_output_rate_t;
113
114
/**
115
 * @brief Measurement bias.
116
 */
117
typedef enum {
118
  HMC5883L_LLD_MB_NORMAL        = 0x00,
119
  HMC5883L_LLD_MB_POSITIVE_BIAS = 0x01,
120
  HMC5883L_LLD_MB_NEGATIVE_BIAS = 0x02,
121
} hmc5883l_lld_measurement_bias_t;
122
123
/**
124
 * @brief Gain settings.
125
 */
126
typedef enum {
127
  HMC5883L_LLD_GN_0_GA = 0x00,
128
  HMC5883L_LLD_GN_1_GA = 0x20,
129
  HMC5883L_LLD_GN_2_GA = 0x40,
130
  HMC5883L_LLD_GN_3_GA = 0x60,
131
  HMC5883L_LLD_GN_4_GA = 0x80,
132
  HMC5883L_LLD_GN_5_GA = 0xA0,
133
  HMC5883L_LLD_GN_6_GA = 0xC0,
134
  HMC5883L_LLD_GN_7_GA = 0xE0,
135
} hmc5883l_lld_gain_t;
136
137
/**
138
 * @brief Highspeed enable settings.
139
 */
140
typedef enum {
141
  HMC5883L_LLD_HS_DISABLE = 0x00,
142
  HMC5883L_LLD_HS_ENABLE  = 0x80,
143
} hmc5883l_lld_highspeed_t;
144
145
/**
146
 * @brief Measurement modes.
147
 */
148
typedef enum {
149
  HMC5883L_LLD_MM_CONTINUOUS = 0x00,
150
  HMC5883L_LLD_MM_SINGLE     = 0x01,
151
  HMC5883L_LLD_MM_IDLE       = 0x02,
152
} hmc5883l_lld_measurement_mode_t;
153
154
/**
155
 * @brief Read or write access.
156
 */
157
typedef enum {
158
  HMC5883L_LLD_READ  = 0x3Du,
159
  HMC5883L_LLD_WRITE = 0x3Cu,
160
} hmc5883l_lld_access_mode_t;
161
162
/**
163
 * @brief Status lock or ready.
164
 */
165
typedef enum {
166
  HMC5883L_LLD_LOCK = 0x0u,
167
  HMC5883L_LLD_RDY  = 0x1u,
168
} hmc5883l_lld_status_t;
169
170
/**
171
 * @brief Identification values.
172
 */
173
typedef enum {
174
  HMC5883L_LLD_IDENTIFICATION_A = 0x48,
175
  HMC5883L_LLD_IDENTIFICATION_B = 0x34,
176
  HMC5883L_LLD_IDENTIFICATION_C = 0x33,
177
} hmc5883l_lld_identification_t;
178
179
/**
180
 * @brief HMC5883L configuration struct.
181
 */
182
typedef struct {
183
  hmc5883l_lld_averaging_t avg;
184
  hmc5883l_lld_data_output_rate_t outrate;
185
  hmc5883l_lld_measurement_bias_t mbias;
186
  hmc5883l_lld_gain_t gain;
187
  hmc5883l_lld_highspeed_t highspeed;
188
  hmc5883l_lld_measurement_mode_t mode;
189
} hmc5883l_lld_config_t;
190
191 ef078306 Thomas Schöpping
/******************************************************************************/
192
/* MACROS                                                                     */
193
/******************************************************************************/
194
195
/******************************************************************************/
196
/* EXTERN DECLARATIONS                                                        */
197
/******************************************************************************/
198
199 d6728c5b Thomas Schöpping
#ifdef __cplusplus
200
extern "C" {
201
#endif
202
  apalExitStatus_t hmc5883l_lld_check(const HMC5883LDriver* const hmcd, uint8_t* const rxbuffer, const uint8_t size, const apalTime_t timeout);
203
  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);
204
  apalExitStatus_t hmc5883l_lld_set_register(const HMC5883LDriver* const hmcd, const hmc5883l_lld_register_t regaddr, const uint8_t data, const apalTime_t timeout);
205
  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);
206
  apalExitStatus_t hmc5883l_lld_read_data(const HMC5883LDriver* const hmcd, uint16_t* const data, const apalTime_t timeout);
207
  apalExitStatus_t hmc5883l_lld_write_config(const HMC5883LDriver* const hmcd, const hmc5883l_lld_config_t conf, const apalTime_t timeout);
208
  apalExitStatus_t hmc5883l_lld_read_config(const HMC5883LDriver* const hmcd, hmc5883l_lld_config_t* const conf, const apalTime_t timeout);
209
  apalExitStatus_t hmc5883l_lld_read_status(const HMC5883LDriver* const hmcd, uint8_t* const status, const apalTime_t timeout);
210
  apalExitStatus_t hmc5883l_lld_read_lock(const HMC5883LDriver* const hmcd, uint8_t* const lock, const apalTime_t timeout);
211
  apalExitStatus_t hmc5883l_lld_read_rdy(const HMC5883LDriver* const hmcd, uint8_t* const rdy, const apalTime_t timeout);
212
#ifdef __cplusplus
213
}
214
#endif
215
216 ef078306 Thomas Schöpping
/******************************************************************************/
217
/* INLINE FUNCTIONS                                                           */
218
/******************************************************************************/
219
220 1d5bcc82 Thomas Schöpping
#endif /* defined(AMIROLLD_CFG_HMC5883L) && (AMIROLLD_CFG_HMC5883L == 1) */
221 d6728c5b Thomas Schöpping
222 1d5bcc82 Thomas Schöpping
#endif /* AMIROLLD_HMC5883L_V1_H */
223 5e2f673b Marc Rothmann
224
/** @} */