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