Suppressed conflicting destructor function.
Dependencies: X_NUCLEO_COMMON ST_INTERFACES
Dependents: D7A_1x_TRAINING D7_MLX_AND_BAT D7A_1x_demo_sensors_v3
Fork of X_NUCLEO_IKS01A1 by
LSM303C_MAG_driver.h
00001 /** 00002 ****************************************************************************** 00003 * @file LSM303C_MAG_driver.h 00004 * @author MEMS Application Team 00005 * @version V1.1 00006 * @date 25-February-2016 00007 * @brief LSM303C Magnetometer header driver file 00008 ****************************************************************************** 00009 * @attention 00010 * 00011 * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> 00012 * 00013 * Redistribution and use in source and binary forms, with or without modification, 00014 * are permitted provided that the following conditions are met: 00015 * 1. Redistributions of source code must retain the above copyright notice, 00016 * this list of conditions and the following disclaimer. 00017 * 2. Redistributions in binary form must reproduce the above copyright notice, 00018 * this list of conditions and the following disclaimer in the documentation 00019 * and/or other materials provided with the distribution. 00020 * 3. Neither the name of STMicroelectronics nor the names of its contributors 00021 * may be used to endorse or promote products derived from this software 00022 * without specific prior written permission. 00023 * 00024 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00025 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00026 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00027 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 00028 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00029 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00030 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00031 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00032 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00033 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00034 * 00035 ****************************************************************************** 00036 */ 00037 00038 /* Define to prevent recursive inclusion -------------------------------------*/ 00039 #ifndef __LSM303C_MAG_DRIVER__H 00040 #define __LSM303C_MAG_DRIVER__H 00041 00042 /* Includes ------------------------------------------------------------------*/ 00043 #include <stdint.h> 00044 00045 /* Exported types ------------------------------------------------------------*/ 00046 00047 #ifdef __cplusplus 00048 extern "C" { 00049 #endif 00050 00051 //these could change accordingly with the architecture 00052 00053 #ifndef __ARCHDEP__TYPES 00054 #define __ARCHDEP__TYPES 00055 00056 typedef unsigned char u8_t; 00057 typedef unsigned short int u16_t; 00058 typedef unsigned int u32_t; 00059 typedef int i32_t; 00060 typedef short int i16_t; 00061 typedef signed char i8_t; 00062 00063 #endif /*__ARCHDEP__TYPES*/ 00064 00065 /* Exported common structure --------------------------------------------------------*/ 00066 00067 #ifndef __SHARED__TYPES 00068 #define __SHARED__TYPES 00069 00070 typedef union{ 00071 i16_t i16bit[3]; 00072 u8_t u8bit[6]; 00073 } Type3Axis16bit_U; 00074 00075 typedef union{ 00076 i16_t i16bit; 00077 u8_t u8bit[2]; 00078 } Type1Axis16bit_U; 00079 00080 typedef union{ 00081 i32_t i32bit; 00082 u8_t u8bit[4]; 00083 } Type1Axis32bit_U; 00084 00085 typedef enum { 00086 MEMS_SUCCESS = 0x01, 00087 MEMS_ERROR = 0x00 00088 } status_t; 00089 00090 #endif /*__SHARED__TYPES*/ 00091 00092 /* Exported macro ------------------------------------------------------------*/ 00093 00094 /* Exported constants --------------------------------------------------------*/ 00095 00096 /************** I2C Address *****************/ 00097 00098 #define LSM303C_MAG_I2C_ADDRESS 0x3C 00099 #define I_AM_LSM303C_MAG 0x3D 00100 00101 /* Magnetic field Registers */ 00102 #define LSM303C_WHO_AM_I_REG_M 0x0F /* device identification register */ 00103 #define LSM303C_CTRL_REG1_M 0x20 /* Magnetic control register 1 */ 00104 #define LSM303C_CTRL_REG2_M 0x21 /* Magnetic control register 2 */ 00105 #define LSM303C_CTRL_REG3_M 0x22 /* Magnetic control register 3 */ 00106 #define LSM303C_CTRL_REG4_M 0x23 /* Magnetic control register 4 */ 00107 #define LSM303C_CTRL_REG5_M 0x24 /* Magnetic control register 5 */ 00108 00109 #define LSM303C_STATUS_REG_M 0x27 /* Magnetic status register M */ 00110 00111 #define LSM303C_OUT_X_L_M 0x28 /* Output Register X magnetic field */ 00112 #define LSM303C_OUT_X_H_M 0x29 /* Output Register X magnetic field */ 00113 #define LSM303C_OUT_Y_L_M 0x2A /* Output Register Y magnetic field */ 00114 #define LSM303C_OUT_Y_H_M 0x2B /* Output Register Y magnetic field */ 00115 #define LSM303C_OUT_Z_L_M 0x2C /* Output Register Z magnetic field */ 00116 #define LSM303C_OUT_Z_H_M 0x2D /* Output Register Z magnetic field */ 00117 00118 #define LSM303C_TEMP_OUT_L_M 0x2E /* Temperature Register magnetic field */ 00119 #define LSM303C_TEMP_OUT_H_M 0x2F /* Temperature Register magnetic field */ 00120 00121 #define LSM303C_INT_CFG_M 0x30 /* Axis interrupt configuration */ 00122 #define LSM303C_INT_SRC_M 0x31 /* Axis interrupt source */ 00123 #define LSM303C_INT_THS_L_M 0x32 /* Interrupt threshold L */ 00124 #define LSM303C_INT_THS_H_M 0x33 /* Interrupt threshold M */ 00125 00126 /* Private Function Prototype -------------------------------------------------------*/ 00127 00128 void LSM303C_MAG_SwapHighLowByte(u8_t *bufferToSwap, u8_t numberOfByte, u8_t dimension); 00129 00130 /* Public Function Prototypes -------------------------------------------------------*/ 00131 00132 status_t LSM303C_MAG_ReadReg( void *handle, u8_t Reg, u8_t* Data ); 00133 status_t LSM303C_MAG_WriteReg( void *handle, u8_t Reg, u8_t Data ); 00134 00135 /******************************************************************************* 00136 * Register : WHO_AM_I_REG 00137 * Address : 0X4F 00138 * Bit Group Name: WHO_AM_I 00139 * Permission : RO 00140 *******************************************************************************/ 00141 #define LSM303C_MAG_WHO_AM_I_MASK 0xFF 00142 #define LSM303C_MAG_WHO_AM_I_POSITION 0 00143 status_t LSM303C_MAG_R_WHO_AM_I(void *handle, u8_t *value); 00144 00145 /******************************************************************************* 00146 * Register : CFG_REG_A 00147 * Address : 0X60 00148 * Bit Group Name: MD 00149 * Permission : RW 00150 *******************************************************************************/ 00151 typedef enum { 00152 LSM303C_MAG_MD_CONTINUOS_MODE =0x00, 00153 LSM303C_MAG_MD_SINGLE_MODE =0x01, 00154 LSM303C_MAG_MD_IDLE1_MODE =0x02, 00155 LSM303C_MAG_MD_IDLE2_MODE =0x03, 00156 } LSM303C_MAG_MD_t; 00157 00158 #define LSM303C_MAG_MD_MASK 0x03 00159 status_t LSM303C_MAG_W_MD(void *handle, LSM303C_MAG_MD_t newValue); 00160 status_t LSM303C_MAG_R_MD(void *handle, LSM303C_MAG_MD_t *value); 00161 00162 /******************************************************************************* 00163 * Register : CFG_REG_A 00164 * Address : 0X60 00165 * Bit Group Name: ODR 00166 * Permission : RW 00167 *******************************************************************************/ 00168 typedef enum { 00169 LSM303C_MAG_ODR_0_625Hz =0x00, 00170 LSM303C_MAG_ODR_1_25Hz =0x04, 00171 LSM303C_MAG_ODR_2_5Hz =0x08, 00172 LSM303C_MAG_ODR_5Hz =0x0C, 00173 LSM303C_MAG_ODR_10Hz =0x10, 00174 LSM303C_MAG_ODR_20Hz =0x14, 00175 LSM303C_MAG_ODR_40Hz =0x18, 00176 LSM303C_MAG_ODR_80Hz =0x1C, 00177 } LSM303C_MAG_ODR_t; 00178 00179 #define LSM303C_MAG_ODR_MASK 0x1C 00180 status_t LSM303C_MAG_W_ODR(void *handle, LSM303C_MAG_ODR_t newValue); 00181 status_t LSM303C_MAG_R_ODR(void *handle, LSM303C_MAG_ODR_t *value); 00182 00183 /******************************************************************************* 00184 * Register : CFG_REG_A 00185 * Address : 0X60 00186 * Bit Group Name: LP 00187 * Permission : RW 00188 *******************************************************************************/ 00189 typedef enum { 00190 LSM303C_MAG_HR_MODE =0x00, 00191 LSM303C_MAG_LP_MODE =0x20, 00192 } LSM303C_MAG_LP_t; 00193 00194 #define LSM303C_MAG_LP_MASK 0x20 00195 status_t LSM303C_MAG_W_LP(void *handle, LSM303C_MAG_LP_t newValue); 00196 status_t LSM303C_MAG_R_LP(void *handle, LSM303C_MAG_LP_t *value); 00197 00198 /******************************************************************************* 00199 * Register : CFG_REG_A 00200 * Address : 0X60 00201 * Bit Group Name: SOFT_RST 00202 * Permission : RW 00203 *******************************************************************************/ 00204 typedef enum { 00205 LSM303C_MAG_SOFT_RST_DISABLED =0x00, 00206 LSM303C_MAG_SOFT_RST_ENABLED =0x04, 00207 } LSM303C_MAG_SOFT_RST_t; 00208 00209 #define LSM303C_MAG_SOFT_RST_MASK 0x04 00210 status_t LSM303C_MAG_W_SOFT_RST(void *handle, LSM303C_MAG_SOFT_RST_t newValue); 00211 status_t LSM303C_MAG_R_SOFT_RST(void *handle, LSM303C_MAG_SOFT_RST_t *value); 00212 00213 /******************************************************************************* 00214 * Register : CFG_REG_C 00215 * Address : 0X62 00216 * Bit Group Name: ST 00217 * Permission : RW 00218 *******************************************************************************/ 00219 typedef enum { 00220 LSM303C_MAG_ST_DISABLED =0x00, 00221 LSM303C_MAG_ST_ENABLED =0x01, 00222 } LSM303C_MAG_ST_t; 00223 00224 #define LSM303C_MAG_ST_MASK 0x01 00225 status_t LSM303C_MAG_W_ST(void *handle, LSM303C_MAG_ST_t newValue); 00226 status_t LSM303C_MAG_R_ST(void *handle, LSM303C_MAG_ST_t *value); 00227 00228 /******************************************************************************* 00229 * Register : CFG_REG_C 00230 * Address : 0X62 00231 * Bit Group Name: BLE 00232 * Permission : RW 00233 *******************************************************************************/ 00234 typedef enum { 00235 LSM303C_MAG_BLE_DISABLED =0x00, 00236 LSM303C_MAG_BLE_ENABLED =0x02, 00237 } LSM303C_MAG_BLE_t; 00238 00239 #define LSM303C_MAG_BLE_MASK 0x02 00240 status_t LSM303C_MAG_W_BLE(void *handle, LSM303C_MAG_BLE_t newValue); 00241 status_t LSM303C_MAG_R_BLE(void *handle, LSM303C_MAG_BLE_t *value); 00242 00243 /******************************************************************************* 00244 * Register : CFG_REG_C 00245 * Address : 0X62 00246 * Bit Group Name: BDU 00247 * Permission : RW 00248 *******************************************************************************/ 00249 typedef enum { 00250 LSM303C_MAG_BDU_DISABLED =0x00, 00251 LSM303C_MAG_BDU_ENABLED =0x40, 00252 } LSM303C_MAG_BDU_t; 00253 00254 #define LSM303C_MAG_BDU_MASK 0x40 00255 status_t LSM303C_MAG_W_BDU(void *handle, LSM303C_MAG_BDU_t newValue); 00256 status_t LSM303C_MAG_R_BDU(void *handle, LSM303C_MAG_BDU_t *value); 00257 00258 /******************************************************************************* 00259 * Register : CFG_REG_C 00260 * Address : 0X62 00261 * Bit Group Name: I2C_DIS 00262 * Permission : RW 00263 *******************************************************************************/ 00264 typedef enum { 00265 LSM303C_MAG_I2C_ENABLED =0x00, 00266 LSM303C_MAG_I2C_DISABLED =0x80, 00267 } LSM303C_MAG_I2C_DIS_t; 00268 00269 #define LSM303C_MAG_I2C_DIS_MASK 0x80 00270 status_t LSM303C_MAG_W_I2C_DIS(void *handle, LSM303C_MAG_I2C_DIS_t newValue); 00271 status_t LSM303C_MAG_R_I2C_DIS(void *handle, LSM303C_MAG_I2C_DIS_t *value); 00272 00273 /******************************************************************************* 00274 * Register : STATUS_REG 00275 * Address : 0X67 00276 * Bit Group Name: XDA 00277 * Permission : RO 00278 *******************************************************************************/ 00279 typedef enum { 00280 LSM303C_MAG_XDA_EV_OFF =0x00, 00281 LSM303C_MAG_XDA_EV_ON =0x01, 00282 } LSM303C_MAG_XDA_t; 00283 00284 #define LSM303C_MAG_XDA_MASK 0x01 00285 status_t LSM303C_MAG_R_XDA(void *handle, LSM303C_MAG_XDA_t *value); 00286 00287 /******************************************************************************* 00288 * Register : STATUS_REG 00289 * Address : 0X67 00290 * Bit Group Name: YDA 00291 * Permission : RO 00292 *******************************************************************************/ 00293 typedef enum { 00294 LSM303C_MAG_YDA_EV_OFF =0x00, 00295 LSM303C_MAG_YDA_EV_ON =0x02, 00296 } LSM303C_MAG_YDA_t; 00297 00298 #define LSM303C_MAG_YDA_MASK 0x02 00299 status_t LSM303C_MAG_R_YDA(void *handle, LSM303C_MAG_YDA_t *value); 00300 00301 /******************************************************************************* 00302 * Register : STATUS_REG 00303 * Address : 0X67 00304 * Bit Group Name: ZDA 00305 * Permission : RO 00306 *******************************************************************************/ 00307 typedef enum { 00308 LSM303C_MAG_ZDA_EV_OFF =0x00, 00309 LSM303C_MAG_ZDA_EV_ON =0x04, 00310 } LSM303C_MAG_ZDA_t; 00311 00312 #define LSM303C_MAG_ZDA_MASK 0x04 00313 status_t LSM303C_MAG_R_ZDA(void *handle, LSM303C_MAG_ZDA_t *value); 00314 00315 /******************************************************************************* 00316 * Register : STATUS_REG 00317 * Address : 0X67 00318 * Bit Group Name: ZYXDA 00319 * Permission : RO 00320 *******************************************************************************/ 00321 typedef enum { 00322 LSM303C_MAG_ZYXDA_EV_OFF =0x00, 00323 LSM303C_MAG_ZYXDA_EV_ON =0x08, 00324 } LSM303C_MAG_ZYXDA_t; 00325 00326 #define LSM303C_MAG_ZYXDA_MASK 0x08 00327 status_t LSM303C_MAG_R_ZYXDA(void *handle, LSM303C_MAG_ZYXDA_t *value); 00328 00329 /******************************************************************************* 00330 * Register : STATUS_REG 00331 * Address : 0X67 00332 * Bit Group Name: XOR 00333 * Permission : RO 00334 *******************************************************************************/ 00335 typedef enum { 00336 LSM303C_MAG_XOR_EV_OFF =0x00, 00337 LSM303C_MAG_XOR_EV_ON =0x10, 00338 } LSM303C_MAG_XOR_t; 00339 00340 #define LSM303C_MAG_XOR_MASK 0x10 00341 status_t LSM303C_MAG_R_XOR(void *handle, LSM303C_MAG_XOR_t *value); 00342 00343 /******************************************************************************* 00344 * Register : STATUS_REG 00345 * Address : 0X67 00346 * Bit Group Name: YOR 00347 * Permission : RO 00348 *******************************************************************************/ 00349 typedef enum { 00350 LSM303C_MAG_YOR_EV_OFF =0x00, 00351 LSM303C_MAG_YOR_EV_ON =0x20, 00352 } LSM303C_MAG_YOR_t; 00353 00354 #define LSM303C_MAG_YOR_MASK 0x20 00355 status_t LSM303C_MAG_R_YOR(void *handle, LSM303C_MAG_YOR_t *value); 00356 00357 /******************************************************************************* 00358 * Register : STATUS_REG 00359 * Address : 0X67 00360 * Bit Group Name: ZOR 00361 * Permission : RO 00362 *******************************************************************************/ 00363 typedef enum { 00364 LSM303C_MAG_ZOR_EV_OFF =0x00, 00365 LSM303C_MAG_ZOR_EV_ON =0x40, 00366 } LSM303C_MAG_ZOR_t; 00367 00368 #define LSM303C_MAG_ZOR_MASK 0x40 00369 status_t LSM303C_MAG_R_ZOR(void *handle, LSM303C_MAG_ZOR_t *value); 00370 00371 /******************************************************************************* 00372 * Register : STATUS_REG 00373 * Address : 0X67 00374 * Bit Group Name: ZYXOR 00375 * Permission : RO 00376 *******************************************************************************/ 00377 typedef enum { 00378 LSM303C_MAG_ZYXOR_EV_OFF =0x00, 00379 LSM303C_MAG_ZYXOR_EV_ON =0x80, 00380 } LSM303C_MAG_ZYXOR_t; 00381 00382 #define LSM303C_MAG_ZYXOR_MASK 0x80 00383 status_t LSM303C_MAG_R_ZYXOR(void *handle, LSM303C_MAG_ZYXOR_t *value); 00384 /******************************************************************************* 00385 * Register : <REGISTER_L> - <REGISTER_H> 00386 * Output Type : Magnetic 00387 * Permission : ro 00388 *******************************************************************************/ 00389 status_t LSM303C_MAG_Get_Raw_Magnetic(void *handle, u8_t *buff); 00390 status_t LSM303C_MAG_Get_Magnetic(void *handle, int *buff); 00391 00392 /******************************************************************************* 00393 * Register : <REGISTER_L> - <REGISTER_H> 00394 * Output Type : IntThreshld 00395 * Permission : rw 00396 *******************************************************************************/ 00397 status_t LSM303C_MAG_Get_IntThreshld(void *handle, u8_t *buff); 00398 status_t LSM303C_MAG_Set_IntThreshld(void *handle, u8_t *buff); 00399 00400 #ifdef __cplusplus 00401 } 00402 #endif 00403 00404 #endif
Generated on Tue Jul 12 2022 17:30:06 by
1.7.2
