Statistics
| Branch: | Tag: | Revision:

amiro-lld / drivers / HMC5883L / v1 / alld_HMC5883L.h @ 22401187

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