Example of free fall detection for LSM6DSL in X-NUCLEO-IKS01A2

Dependencies:   X_NUCLEO_IKS01A2 mbed

Fork of FreeFall_IKS01A2 by ST Expansion SW Team

Free Fall Detection Demo Application based on sensor expansion board X-NUCLEO-IKS01A2

Main function is to show how to detect the free fall event using the sensor expansion board and send a notification using UART to a connected PC or Desktop and display it on terminal applications like TeraTerm.
After connection has been established:
- the user can try to leave falling the board and then view the notification using an hyper terminal. When the free fall is detected, the LED is switched on for a while.
- the user button can be used to enable/disable the free fall detection feature.

Committer:
cparata
Date:
Fri Aug 12 13:39:06 2016 +0000
Revision:
0:6a670fda63c2
First release of Free Fall for LSM6DSL in IKS01A2

Who changed what in which revision?

UserRevisionLine numberNew contents of line
cparata 0:6a670fda63c2 1 /**
cparata 0:6a670fda63c2 2 *******************************************************************************
cparata 0:6a670fda63c2 3 * @file LSM303AGR_MAG_driver.c
cparata 0:6a670fda63c2 4 * @author MEMS Application Team
cparata 0:6a670fda63c2 5 * @version V1.1
cparata 0:6a670fda63c2 6 * @date 25-February-2016
cparata 0:6a670fda63c2 7 * @brief LSM303AGR Magnetometer driver file
cparata 0:6a670fda63c2 8 *******************************************************************************
cparata 0:6a670fda63c2 9 * @attention
cparata 0:6a670fda63c2 10 *
cparata 0:6a670fda63c2 11 * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
cparata 0:6a670fda63c2 12 *
cparata 0:6a670fda63c2 13 * Redistribution and use in source and binary forms, with or without modification,
cparata 0:6a670fda63c2 14 * are permitted provided that the following conditions are met:
cparata 0:6a670fda63c2 15 * 1. Redistributions of source code must retain the above copyright notice,
cparata 0:6a670fda63c2 16 * this list of conditions and the following disclaimer.
cparata 0:6a670fda63c2 17 * 2. Redistributions in binary form must reproduce the above copyright notice,
cparata 0:6a670fda63c2 18 * this list of conditions and the following disclaimer in the documentation
cparata 0:6a670fda63c2 19 * and/or other materials provided with the distribution.
cparata 0:6a670fda63c2 20 * 3. Neither the name of STMicroelectronics nor the names of its contributors
cparata 0:6a670fda63c2 21 * may be used to endorse or promote products derived from this software
cparata 0:6a670fda63c2 22 * without specific prior written permission.
cparata 0:6a670fda63c2 23 *
cparata 0:6a670fda63c2 24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
cparata 0:6a670fda63c2 25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
cparata 0:6a670fda63c2 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
cparata 0:6a670fda63c2 27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
cparata 0:6a670fda63c2 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
cparata 0:6a670fda63c2 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
cparata 0:6a670fda63c2 30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
cparata 0:6a670fda63c2 31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
cparata 0:6a670fda63c2 32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
cparata 0:6a670fda63c2 33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
cparata 0:6a670fda63c2 34 *
cparata 0:6a670fda63c2 35 ******************************************************************************
cparata 0:6a670fda63c2 36 */
cparata 0:6a670fda63c2 37
cparata 0:6a670fda63c2 38 /* Includes ------------------------------------------------------------------*/
cparata 0:6a670fda63c2 39 #include "LSM303AGR_MAG_driver.h"
cparata 0:6a670fda63c2 40
cparata 0:6a670fda63c2 41 /* Imported function prototypes ----------------------------------------------*/
cparata 0:6a670fda63c2 42 extern uint8_t LSM303AGR_MAG_IO_Write(void *handle, uint8_t WriteAddr, uint8_t *pBuffer, uint16_t nBytesToWrite);
cparata 0:6a670fda63c2 43 extern uint8_t LSM303AGR_MAG_IO_Read(void *handle, uint8_t ReadAddr, uint8_t *pBuffer, uint16_t nBytesToRead);
cparata 0:6a670fda63c2 44
cparata 0:6a670fda63c2 45 /* Private typedef -----------------------------------------------------------*/
cparata 0:6a670fda63c2 46
cparata 0:6a670fda63c2 47 /* Private define ------------------------------------------------------------*/
cparata 0:6a670fda63c2 48
cparata 0:6a670fda63c2 49 /* Private macro -------------------------------------------------------------*/
cparata 0:6a670fda63c2 50
cparata 0:6a670fda63c2 51 /* Private variables ---------------------------------------------------------*/
cparata 0:6a670fda63c2 52
cparata 0:6a670fda63c2 53 /* Private functions ---------------------------------------------------------*/
cparata 0:6a670fda63c2 54
cparata 0:6a670fda63c2 55 /*******************************************************************************
cparata 0:6a670fda63c2 56 * Function Name : LSM303AGR_MAG_ReadReg
cparata 0:6a670fda63c2 57 * Description : Generic Reading function. It must be fullfilled with either
cparata 0:6a670fda63c2 58 * : I2C or SPI reading functions
cparata 0:6a670fda63c2 59 * Input : Register Address
cparata 0:6a670fda63c2 60 * Output : Data REad
cparata 0:6a670fda63c2 61 * Return : None
cparata 0:6a670fda63c2 62 *******************************************************************************/
cparata 0:6a670fda63c2 63 status_t LSM303AGR_MAG_ReadReg( void *handle, u8_t Reg, u8_t* Data )
cparata 0:6a670fda63c2 64 {
cparata 0:6a670fda63c2 65
cparata 0:6a670fda63c2 66 if (LSM303AGR_MAG_IO_Read(handle, Reg, Data, 1))
cparata 0:6a670fda63c2 67 {
cparata 0:6a670fda63c2 68 return MEMS_ERROR;
cparata 0:6a670fda63c2 69 }
cparata 0:6a670fda63c2 70 else
cparata 0:6a670fda63c2 71 {
cparata 0:6a670fda63c2 72 return MEMS_SUCCESS;
cparata 0:6a670fda63c2 73 }
cparata 0:6a670fda63c2 74 }
cparata 0:6a670fda63c2 75
cparata 0:6a670fda63c2 76 /*******************************************************************************
cparata 0:6a670fda63c2 77 * Function Name : LSM303AGR_MAG_WriteReg
cparata 0:6a670fda63c2 78 * Description : Generic Writing function. It must be fullfilled with either
cparata 0:6a670fda63c2 79 * : I2C or SPI writing function
cparata 0:6a670fda63c2 80 * Input : Register Address, Data to be written
cparata 0:6a670fda63c2 81 * Output : None
cparata 0:6a670fda63c2 82 * Return : None
cparata 0:6a670fda63c2 83 *******************************************************************************/
cparata 0:6a670fda63c2 84 status_t LSM303AGR_MAG_WriteReg( void *handle, u8_t Reg, u8_t Data )
cparata 0:6a670fda63c2 85 {
cparata 0:6a670fda63c2 86
cparata 0:6a670fda63c2 87 if (LSM303AGR_MAG_IO_Write(handle, Reg, &Data, 1))
cparata 0:6a670fda63c2 88 {
cparata 0:6a670fda63c2 89 return MEMS_ERROR;
cparata 0:6a670fda63c2 90 }
cparata 0:6a670fda63c2 91 else
cparata 0:6a670fda63c2 92 {
cparata 0:6a670fda63c2 93 return MEMS_SUCCESS;
cparata 0:6a670fda63c2 94 }
cparata 0:6a670fda63c2 95 }
cparata 0:6a670fda63c2 96
cparata 0:6a670fda63c2 97 /*******************************************************************************
cparata 0:6a670fda63c2 98 * Function Name : SwapHighLowByte
cparata 0:6a670fda63c2 99 * Description : Swap High/low byte in multiple byte values
cparata 0:6a670fda63c2 100 * It works with minimum 2 byte for every dimension.
cparata 0:6a670fda63c2 101 * Example x,y,z with 2 byte for every dimension
cparata 0:6a670fda63c2 102 *
cparata 0:6a670fda63c2 103 * Input : bufferToSwap -> buffer to swap
cparata 0:6a670fda63c2 104 * numberOfByte -> the buffer length in byte
cparata 0:6a670fda63c2 105 * dimension -> number of dimension
cparata 0:6a670fda63c2 106 *
cparata 0:6a670fda63c2 107 * Output : bufferToSwap -> buffer swapped
cparata 0:6a670fda63c2 108 * Return : None
cparata 0:6a670fda63c2 109 *******************************************************************************/
cparata 0:6a670fda63c2 110 void LSM303AGR_MAG_SwapHighLowByte(u8_t *bufferToSwap, u8_t numberOfByte, u8_t dimension)
cparata 0:6a670fda63c2 111 {
cparata 0:6a670fda63c2 112
cparata 0:6a670fda63c2 113 u8_t numberOfByteForDimension, i, j;
cparata 0:6a670fda63c2 114 u8_t tempValue[10];
cparata 0:6a670fda63c2 115
cparata 0:6a670fda63c2 116 numberOfByteForDimension=numberOfByte/dimension;
cparata 0:6a670fda63c2 117
cparata 0:6a670fda63c2 118 for (i=0; i<dimension;i++ )
cparata 0:6a670fda63c2 119 {
cparata 0:6a670fda63c2 120 for (j=0; j<numberOfByteForDimension;j++ )
cparata 0:6a670fda63c2 121 tempValue[j]=bufferToSwap[j+i*numberOfByteForDimension];
cparata 0:6a670fda63c2 122 for (j=0; j<numberOfByteForDimension;j++ )
cparata 0:6a670fda63c2 123 *(bufferToSwap+i*(numberOfByteForDimension)+j)=*(tempValue+(numberOfByteForDimension-1)-j);
cparata 0:6a670fda63c2 124 }
cparata 0:6a670fda63c2 125 }
cparata 0:6a670fda63c2 126
cparata 0:6a670fda63c2 127 /* Exported functions ---------------------------------------------------------*/
cparata 0:6a670fda63c2 128
cparata 0:6a670fda63c2 129 /*******************************************************************************
cparata 0:6a670fda63c2 130 * Function Name : LSM303AGR_MAG_W_OFF_X_L
cparata 0:6a670fda63c2 131 * Description : Write OFF_X_L
cparata 0:6a670fda63c2 132 * Input : u8_t
cparata 0:6a670fda63c2 133 * Output : None
cparata 0:6a670fda63c2 134 * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
cparata 0:6a670fda63c2 135 *******************************************************************************/
cparata 0:6a670fda63c2 136 status_t LSM303AGR_MAG_W_OFF_X_L(void *handle, u8_t newValue)
cparata 0:6a670fda63c2 137 {
cparata 0:6a670fda63c2 138 u8_t value;
cparata 0:6a670fda63c2 139
cparata 0:6a670fda63c2 140 newValue = newValue << LSM303AGR_MAG_OFF_X_L_POSITION; //mask
cparata 0:6a670fda63c2 141 newValue &= LSM303AGR_MAG_OFF_X_L_MASK; //coerce
cparata 0:6a670fda63c2 142
cparata 0:6a670fda63c2 143 if( !LSM303AGR_MAG_ReadReg(handle, LSM303AGR_MAG_OFFSET_X_REG_L, &value) )
cparata 0:6a670fda63c2 144 return MEMS_ERROR;
cparata 0:6a670fda63c2 145
cparata 0:6a670fda63c2 146 value &= (u8_t)~LSM303AGR_MAG_OFF_X_L_MASK;
cparata 0:6a670fda63c2 147 value |= newValue;
cparata 0:6a670fda63c2 148
cparata 0:6a670fda63c2 149 if( !LSM303AGR_MAG_WriteReg(handle, LSM303AGR_MAG_OFFSET_X_REG_L, value) )
cparata 0:6a670fda63c2 150 return MEMS_ERROR;
cparata 0:6a670fda63c2 151
cparata 0:6a670fda63c2 152 return MEMS_SUCCESS;
cparata 0:6a670fda63c2 153 }
cparata 0:6a670fda63c2 154
cparata 0:6a670fda63c2 155 /*******************************************************************************
cparata 0:6a670fda63c2 156 * Function Name : LSM303AGR_MAG_R_OFF_X_L
cparata 0:6a670fda63c2 157 * Description : Read OFF_X_L
cparata 0:6a670fda63c2 158 * Input : Pointer to u8_t
cparata 0:6a670fda63c2 159 * Output : Status of OFF_X_L
cparata 0:6a670fda63c2 160 * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
cparata 0:6a670fda63c2 161 *******************************************************************************/
cparata 0:6a670fda63c2 162
cparata 0:6a670fda63c2 163 status_t LSM303AGR_MAG_R_OFF_X_L(void *handle, u8_t *value)
cparata 0:6a670fda63c2 164 {
cparata 0:6a670fda63c2 165 if( !LSM303AGR_MAG_ReadReg(handle, LSM303AGR_MAG_OFFSET_X_REG_L, (u8_t *)value) )
cparata 0:6a670fda63c2 166 return MEMS_ERROR;
cparata 0:6a670fda63c2 167
cparata 0:6a670fda63c2 168 *value &= LSM303AGR_MAG_OFF_X_L_MASK; //coerce
cparata 0:6a670fda63c2 169 *value = *value >> LSM303AGR_MAG_OFF_X_L_POSITION; //mask
cparata 0:6a670fda63c2 170
cparata 0:6a670fda63c2 171 return MEMS_SUCCESS;
cparata 0:6a670fda63c2 172 }
cparata 0:6a670fda63c2 173 /*******************************************************************************
cparata 0:6a670fda63c2 174 * Function Name : LSM303AGR_MAG_W_OFF_X_H
cparata 0:6a670fda63c2 175 * Description : Write OFF_X_H
cparata 0:6a670fda63c2 176 * Input : u8_t
cparata 0:6a670fda63c2 177 * Output : None
cparata 0:6a670fda63c2 178 * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
cparata 0:6a670fda63c2 179 *******************************************************************************/
cparata 0:6a670fda63c2 180 status_t LSM303AGR_MAG_W_OFF_X_H(void *handle, u8_t newValue)
cparata 0:6a670fda63c2 181 {
cparata 0:6a670fda63c2 182 u8_t value;
cparata 0:6a670fda63c2 183
cparata 0:6a670fda63c2 184 newValue = newValue << LSM303AGR_MAG_OFF_X_H_POSITION; //mask
cparata 0:6a670fda63c2 185 newValue &= LSM303AGR_MAG_OFF_X_H_MASK; //coerce
cparata 0:6a670fda63c2 186
cparata 0:6a670fda63c2 187 if( !LSM303AGR_MAG_ReadReg(handle, LSM303AGR_MAG_OFFSET_X_REG_H, &value) )
cparata 0:6a670fda63c2 188 return MEMS_ERROR;
cparata 0:6a670fda63c2 189
cparata 0:6a670fda63c2 190 value &= (u8_t)~LSM303AGR_MAG_OFF_X_H_MASK;
cparata 0:6a670fda63c2 191 value |= newValue;
cparata 0:6a670fda63c2 192
cparata 0:6a670fda63c2 193 if( !LSM303AGR_MAG_WriteReg(handle, LSM303AGR_MAG_OFFSET_X_REG_H, value) )
cparata 0:6a670fda63c2 194 return MEMS_ERROR;
cparata 0:6a670fda63c2 195
cparata 0:6a670fda63c2 196 return MEMS_SUCCESS;
cparata 0:6a670fda63c2 197 }
cparata 0:6a670fda63c2 198
cparata 0:6a670fda63c2 199 /*******************************************************************************
cparata 0:6a670fda63c2 200 * Function Name : LSM303AGR_MAG_R_OFF_X_H
cparata 0:6a670fda63c2 201 * Description : Read OFF_X_H
cparata 0:6a670fda63c2 202 * Input : Pointer to u8_t
cparata 0:6a670fda63c2 203 * Output : Status of OFF_X_H
cparata 0:6a670fda63c2 204 * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
cparata 0:6a670fda63c2 205 *******************************************************************************/
cparata 0:6a670fda63c2 206
cparata 0:6a670fda63c2 207 status_t LSM303AGR_MAG_R_OFF_X_H(void *handle, u8_t *value)
cparata 0:6a670fda63c2 208 {
cparata 0:6a670fda63c2 209 if( !LSM303AGR_MAG_ReadReg(handle, LSM303AGR_MAG_OFFSET_X_REG_H, (u8_t *)value) )
cparata 0:6a670fda63c2 210 return MEMS_ERROR;
cparata 0:6a670fda63c2 211
cparata 0:6a670fda63c2 212 *value &= LSM303AGR_MAG_OFF_X_H_MASK; //coerce
cparata 0:6a670fda63c2 213 *value = *value >> LSM303AGR_MAG_OFF_X_H_POSITION; //mask
cparata 0:6a670fda63c2 214
cparata 0:6a670fda63c2 215 return MEMS_SUCCESS;
cparata 0:6a670fda63c2 216 }
cparata 0:6a670fda63c2 217 /*******************************************************************************
cparata 0:6a670fda63c2 218 * Function Name : LSM303AGR_MAG_W_OFF_Y_L
cparata 0:6a670fda63c2 219 * Description : Write OFF_Y_L
cparata 0:6a670fda63c2 220 * Input : u8_t
cparata 0:6a670fda63c2 221 * Output : None
cparata 0:6a670fda63c2 222 * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
cparata 0:6a670fda63c2 223 *******************************************************************************/
cparata 0:6a670fda63c2 224 status_t LSM303AGR_MAG_W_OFF_Y_L(void *handle, u8_t newValue)
cparata 0:6a670fda63c2 225 {
cparata 0:6a670fda63c2 226 u8_t value;
cparata 0:6a670fda63c2 227
cparata 0:6a670fda63c2 228 newValue = newValue << LSM303AGR_MAG_OFF_Y_L_POSITION; //mask
cparata 0:6a670fda63c2 229 newValue &= LSM303AGR_MAG_OFF_Y_L_MASK; //coerce
cparata 0:6a670fda63c2 230
cparata 0:6a670fda63c2 231 if( !LSM303AGR_MAG_ReadReg(handle, LSM303AGR_MAG_OFFSET_Y_REG_L, &value) )
cparata 0:6a670fda63c2 232 return MEMS_ERROR;
cparata 0:6a670fda63c2 233
cparata 0:6a670fda63c2 234 value &= (u8_t)~LSM303AGR_MAG_OFF_Y_L_MASK;
cparata 0:6a670fda63c2 235 value |= newValue;
cparata 0:6a670fda63c2 236
cparata 0:6a670fda63c2 237 if( !LSM303AGR_MAG_WriteReg(handle, LSM303AGR_MAG_OFFSET_Y_REG_L, value) )
cparata 0:6a670fda63c2 238 return MEMS_ERROR;
cparata 0:6a670fda63c2 239
cparata 0:6a670fda63c2 240 return MEMS_SUCCESS;
cparata 0:6a670fda63c2 241 }
cparata 0:6a670fda63c2 242
cparata 0:6a670fda63c2 243 /*******************************************************************************
cparata 0:6a670fda63c2 244 * Function Name : LSM303AGR_MAG_R_OFF_Y_L
cparata 0:6a670fda63c2 245 * Description : Read OFF_Y_L
cparata 0:6a670fda63c2 246 * Input : Pointer to u8_t
cparata 0:6a670fda63c2 247 * Output : Status of OFF_Y_L
cparata 0:6a670fda63c2 248 * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
cparata 0:6a670fda63c2 249 *******************************************************************************/
cparata 0:6a670fda63c2 250
cparata 0:6a670fda63c2 251 status_t LSM303AGR_MAG_R_OFF_Y_L(void *handle, u8_t *value)
cparata 0:6a670fda63c2 252 {
cparata 0:6a670fda63c2 253 if( !LSM303AGR_MAG_ReadReg(handle, LSM303AGR_MAG_OFFSET_Y_REG_L, (u8_t *)value) )
cparata 0:6a670fda63c2 254 return MEMS_ERROR;
cparata 0:6a670fda63c2 255
cparata 0:6a670fda63c2 256 *value &= LSM303AGR_MAG_OFF_Y_L_MASK; //coerce
cparata 0:6a670fda63c2 257 *value = *value >> LSM303AGR_MAG_OFF_Y_L_POSITION; //mask
cparata 0:6a670fda63c2 258
cparata 0:6a670fda63c2 259 return MEMS_SUCCESS;
cparata 0:6a670fda63c2 260 }
cparata 0:6a670fda63c2 261 /*******************************************************************************
cparata 0:6a670fda63c2 262 * Function Name : LSM303AGR_MAG_W_OFF_Y_H
cparata 0:6a670fda63c2 263 * Description : Write OFF_Y_H
cparata 0:6a670fda63c2 264 * Input : u8_t
cparata 0:6a670fda63c2 265 * Output : None
cparata 0:6a670fda63c2 266 * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
cparata 0:6a670fda63c2 267 *******************************************************************************/
cparata 0:6a670fda63c2 268 status_t LSM303AGR_MAG_W_OFF_Y_H(void *handle, u8_t newValue)
cparata 0:6a670fda63c2 269 {
cparata 0:6a670fda63c2 270 u8_t value;
cparata 0:6a670fda63c2 271
cparata 0:6a670fda63c2 272 newValue = newValue << LSM303AGR_MAG_OFF_Y_H_POSITION; //mask
cparata 0:6a670fda63c2 273 newValue &= LSM303AGR_MAG_OFF_Y_H_MASK; //coerce
cparata 0:6a670fda63c2 274
cparata 0:6a670fda63c2 275 if( !LSM303AGR_MAG_ReadReg(handle, LSM303AGR_MAG_OFFSET_Y_REG_H, &value) )
cparata 0:6a670fda63c2 276 return MEMS_ERROR;
cparata 0:6a670fda63c2 277
cparata 0:6a670fda63c2 278 value &= (u8_t)~LSM303AGR_MAG_OFF_Y_H_MASK;
cparata 0:6a670fda63c2 279 value |= newValue;
cparata 0:6a670fda63c2 280
cparata 0:6a670fda63c2 281 if( !LSM303AGR_MAG_WriteReg(handle, LSM303AGR_MAG_OFFSET_Y_REG_H, value) )
cparata 0:6a670fda63c2 282 return MEMS_ERROR;
cparata 0:6a670fda63c2 283
cparata 0:6a670fda63c2 284 return MEMS_SUCCESS;
cparata 0:6a670fda63c2 285 }
cparata 0:6a670fda63c2 286
cparata 0:6a670fda63c2 287 /*******************************************************************************
cparata 0:6a670fda63c2 288 * Function Name : LSM303AGR_MAG_R_OFF_Y_H
cparata 0:6a670fda63c2 289 * Description : Read OFF_Y_H
cparata 0:6a670fda63c2 290 * Input : Pointer to u8_t
cparata 0:6a670fda63c2 291 * Output : Status of OFF_Y_H
cparata 0:6a670fda63c2 292 * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
cparata 0:6a670fda63c2 293 *******************************************************************************/
cparata 0:6a670fda63c2 294
cparata 0:6a670fda63c2 295 status_t LSM303AGR_MAG_R_OFF_Y_H(void *handle, u8_t *value)
cparata 0:6a670fda63c2 296 {
cparata 0:6a670fda63c2 297 if( !LSM303AGR_MAG_ReadReg(handle, LSM303AGR_MAG_OFFSET_Y_REG_H, (u8_t *)value) )
cparata 0:6a670fda63c2 298 return MEMS_ERROR;
cparata 0:6a670fda63c2 299
cparata 0:6a670fda63c2 300 *value &= LSM303AGR_MAG_OFF_Y_H_MASK; //coerce
cparata 0:6a670fda63c2 301 *value = *value >> LSM303AGR_MAG_OFF_Y_H_POSITION; //mask
cparata 0:6a670fda63c2 302
cparata 0:6a670fda63c2 303 return MEMS_SUCCESS;
cparata 0:6a670fda63c2 304 }
cparata 0:6a670fda63c2 305 /*******************************************************************************
cparata 0:6a670fda63c2 306 * Function Name : LSM303AGR_MAG_W_OFF_Z_L
cparata 0:6a670fda63c2 307 * Description : Write OFF_Z_L
cparata 0:6a670fda63c2 308 * Input : u8_t
cparata 0:6a670fda63c2 309 * Output : None
cparata 0:6a670fda63c2 310 * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
cparata 0:6a670fda63c2 311 *******************************************************************************/
cparata 0:6a670fda63c2 312 status_t LSM303AGR_MAG_W_OFF_Z_L(void *handle, u8_t newValue)
cparata 0:6a670fda63c2 313 {
cparata 0:6a670fda63c2 314 u8_t value;
cparata 0:6a670fda63c2 315
cparata 0:6a670fda63c2 316 newValue = newValue << LSM303AGR_MAG_OFF_Z_L_POSITION; //mask
cparata 0:6a670fda63c2 317 newValue &= LSM303AGR_MAG_OFF_Z_L_MASK; //coerce
cparata 0:6a670fda63c2 318
cparata 0:6a670fda63c2 319 if( !LSM303AGR_MAG_ReadReg(handle, LSM303AGR_MAG_OFFSET_Z_REG_L, &value) )
cparata 0:6a670fda63c2 320 return MEMS_ERROR;
cparata 0:6a670fda63c2 321
cparata 0:6a670fda63c2 322 value &= (u8_t)~LSM303AGR_MAG_OFF_Z_L_MASK;
cparata 0:6a670fda63c2 323 value |= newValue;
cparata 0:6a670fda63c2 324
cparata 0:6a670fda63c2 325 if( !LSM303AGR_MAG_WriteReg(handle, LSM303AGR_MAG_OFFSET_Z_REG_L, value) )
cparata 0:6a670fda63c2 326 return MEMS_ERROR;
cparata 0:6a670fda63c2 327
cparata 0:6a670fda63c2 328 return MEMS_SUCCESS;
cparata 0:6a670fda63c2 329 }
cparata 0:6a670fda63c2 330
cparata 0:6a670fda63c2 331 /*******************************************************************************
cparata 0:6a670fda63c2 332 * Function Name : LSM303AGR_MAG_R_OFF_Z_L
cparata 0:6a670fda63c2 333 * Description : Read OFF_Z_L
cparata 0:6a670fda63c2 334 * Input : Pointer to u8_t
cparata 0:6a670fda63c2 335 * Output : Status of OFF_Z_L
cparata 0:6a670fda63c2 336 * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
cparata 0:6a670fda63c2 337 *******************************************************************************/
cparata 0:6a670fda63c2 338
cparata 0:6a670fda63c2 339 status_t LSM303AGR_MAG_R_OFF_Z_L(void *handle, u8_t *value)
cparata 0:6a670fda63c2 340 {
cparata 0:6a670fda63c2 341 if( !LSM303AGR_MAG_ReadReg(handle, LSM303AGR_MAG_OFFSET_Z_REG_L, (u8_t *)value) )
cparata 0:6a670fda63c2 342 return MEMS_ERROR;
cparata 0:6a670fda63c2 343
cparata 0:6a670fda63c2 344 *value &= LSM303AGR_MAG_OFF_Z_L_MASK; //coerce
cparata 0:6a670fda63c2 345 *value = *value >> LSM303AGR_MAG_OFF_Z_L_POSITION; //mask
cparata 0:6a670fda63c2 346
cparata 0:6a670fda63c2 347 return MEMS_SUCCESS;
cparata 0:6a670fda63c2 348 }
cparata 0:6a670fda63c2 349 /*******************************************************************************
cparata 0:6a670fda63c2 350 * Function Name : LSM303AGR_MAG_W_OFF_Z_H
cparata 0:6a670fda63c2 351 * Description : Write OFF_Z_H
cparata 0:6a670fda63c2 352 * Input : u8_t
cparata 0:6a670fda63c2 353 * Output : None
cparata 0:6a670fda63c2 354 * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
cparata 0:6a670fda63c2 355 *******************************************************************************/
cparata 0:6a670fda63c2 356 status_t LSM303AGR_MAG_W_OFF_Z_H(void *handle, u8_t newValue)
cparata 0:6a670fda63c2 357 {
cparata 0:6a670fda63c2 358 u8_t value;
cparata 0:6a670fda63c2 359
cparata 0:6a670fda63c2 360 newValue = newValue << LSM303AGR_MAG_OFF_Z_H_POSITION; //mask
cparata 0:6a670fda63c2 361 newValue &= LSM303AGR_MAG_OFF_Z_H_MASK; //coerce
cparata 0:6a670fda63c2 362
cparata 0:6a670fda63c2 363 if( !LSM303AGR_MAG_ReadReg(handle, LSM303AGR_MAG_OFFSET_Z_REG_H, &value) )
cparata 0:6a670fda63c2 364 return MEMS_ERROR;
cparata 0:6a670fda63c2 365
cparata 0:6a670fda63c2 366 value &= (u8_t)~LSM303AGR_MAG_OFF_Z_H_MASK;
cparata 0:6a670fda63c2 367 value |= newValue;
cparata 0:6a670fda63c2 368
cparata 0:6a670fda63c2 369 if( !LSM303AGR_MAG_WriteReg(handle, LSM303AGR_MAG_OFFSET_Z_REG_H, value) )
cparata 0:6a670fda63c2 370 return MEMS_ERROR;
cparata 0:6a670fda63c2 371
cparata 0:6a670fda63c2 372 return MEMS_SUCCESS;
cparata 0:6a670fda63c2 373 }
cparata 0:6a670fda63c2 374
cparata 0:6a670fda63c2 375 /*******************************************************************************
cparata 0:6a670fda63c2 376 * Set/Get the Magnetic offsets
cparata 0:6a670fda63c2 377 *******************************************************************************/
cparata 0:6a670fda63c2 378 status_t LSM303AGR_MAG_Get_MagOff(void *handle, u16_t *magx_off, u16_t *magy_off, u16_t *magz_off)
cparata 0:6a670fda63c2 379 {
cparata 0:6a670fda63c2 380 u8_t reg_l, reg_h;
cparata 0:6a670fda63c2 381
cparata 0:6a670fda63c2 382 /* read mag_x_off */
cparata 0:6a670fda63c2 383 //LSM303AGR_MAG_R_OFF_X_L(&reg_l);
cparata 0:6a670fda63c2 384 //LSM303AGR_MAG_R_OFF_X_H(&reg_h);
cparata 0:6a670fda63c2 385 LSM303AGR_MAG_R_OFF_X_L(handle, &reg_l);
cparata 0:6a670fda63c2 386 LSM303AGR_MAG_R_OFF_X_H(handle, &reg_h);
cparata 0:6a670fda63c2 387 *magx_off = ((reg_h << 8) & 0xff00) | reg_l;
cparata 0:6a670fda63c2 388
cparata 0:6a670fda63c2 389 /* read mag_y_off */
cparata 0:6a670fda63c2 390 //LSM303AGR_MAG_R_OFF_Y_L(&reg_l);
cparata 0:6a670fda63c2 391 //LSM303AGR_MAG_R_OFF_Y_H(&reg_h);
cparata 0:6a670fda63c2 392 LSM303AGR_MAG_R_OFF_Y_L(handle, &reg_l);
cparata 0:6a670fda63c2 393 LSM303AGR_MAG_R_OFF_Y_H(handle, &reg_h);
cparata 0:6a670fda63c2 394 *magy_off = ((reg_h << 8) & 0xff00) | reg_l;
cparata 0:6a670fda63c2 395
cparata 0:6a670fda63c2 396 /* read mag_z_off */
cparata 0:6a670fda63c2 397 //LSM303AGR_MAG_R_OFF_Z_L(&reg_l);
cparata 0:6a670fda63c2 398 //LSM303AGR_MAG_R_OFF_Z_H(&reg_h);
cparata 0:6a670fda63c2 399 LSM303AGR_MAG_R_OFF_Z_L(handle, &reg_l);
cparata 0:6a670fda63c2 400 LSM303AGR_MAG_R_OFF_Z_H(handle, &reg_h);
cparata 0:6a670fda63c2 401 *magz_off = ((reg_h << 8) & 0xff00) | reg_l;
cparata 0:6a670fda63c2 402
cparata 0:6a670fda63c2 403 return MEMS_SUCCESS;
cparata 0:6a670fda63c2 404 }
cparata 0:6a670fda63c2 405
cparata 0:6a670fda63c2 406 status_t LSM303AGR_MAG_Set_MagOff(void *handle, u16_t magx_off, u16_t magy_off, u16_t magz_off)
cparata 0:6a670fda63c2 407 {
cparata 0:6a670fda63c2 408 /* write mag_x_off */
cparata 0:6a670fda63c2 409 //LSM303AGR_MAG_W_OFF_X_L(magx_off & 0xff);
cparata 0:6a670fda63c2 410 //LSM303AGR_MAG_W_OFF_X_H((magx_off >> 8) & 0xff);
cparata 0:6a670fda63c2 411 LSM303AGR_MAG_W_OFF_X_L(handle, magx_off & 0xff);
cparata 0:6a670fda63c2 412 LSM303AGR_MAG_W_OFF_X_H(handle, (magx_off >> 8) & 0xff);
cparata 0:6a670fda63c2 413
cparata 0:6a670fda63c2 414 /* write mag_y_off */
cparata 0:6a670fda63c2 415 //LSM303AGR_MAG_W_OFF_Y_L(magy_off & 0xff);
cparata 0:6a670fda63c2 416 //LSM303AGR_MAG_W_OFF_Y_H((magy_off >> 8) & 0xff);
cparata 0:6a670fda63c2 417 LSM303AGR_MAG_W_OFF_Y_L(handle, magy_off & 0xff);
cparata 0:6a670fda63c2 418 LSM303AGR_MAG_W_OFF_Y_H(handle, (magy_off >> 8) & 0xff);
cparata 0:6a670fda63c2 419
cparata 0:6a670fda63c2 420 /* write mag_z_off */
cparata 0:6a670fda63c2 421 //LSM303AGR_MAG_W_OFF_Z_L(magz_off & 0xff);
cparata 0:6a670fda63c2 422 //LSM303AGR_MAG_W_OFF_Z_H((magz_off >> 8) & 0xff);
cparata 0:6a670fda63c2 423 LSM303AGR_MAG_W_OFF_Z_L(handle, magz_off & 0xff);
cparata 0:6a670fda63c2 424 LSM303AGR_MAG_W_OFF_Z_H(handle, (magz_off >> 8) & 0xff);
cparata 0:6a670fda63c2 425
cparata 0:6a670fda63c2 426 return MEMS_SUCCESS;
cparata 0:6a670fda63c2 427 }
cparata 0:6a670fda63c2 428
cparata 0:6a670fda63c2 429 /*******************************************************************************
cparata 0:6a670fda63c2 430 * Function Name : LSM303AGR_MAG_R_OFF_Z_H
cparata 0:6a670fda63c2 431 * Description : Read OFF_Z_H
cparata 0:6a670fda63c2 432 * Input : Pointer to u8_t
cparata 0:6a670fda63c2 433 * Output : Status of OFF_Z_H
cparata 0:6a670fda63c2 434 * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
cparata 0:6a670fda63c2 435 *******************************************************************************/
cparata 0:6a670fda63c2 436
cparata 0:6a670fda63c2 437 status_t LSM303AGR_MAG_R_OFF_Z_H(void *handle, u8_t *value)
cparata 0:6a670fda63c2 438 {
cparata 0:6a670fda63c2 439 if( !LSM303AGR_MAG_ReadReg(handle, LSM303AGR_MAG_OFFSET_Z_REG_H, (u8_t *)value) )
cparata 0:6a670fda63c2 440 return MEMS_ERROR;
cparata 0:6a670fda63c2 441
cparata 0:6a670fda63c2 442 *value &= LSM303AGR_MAG_OFF_Z_H_MASK; //coerce
cparata 0:6a670fda63c2 443 *value = *value >> LSM303AGR_MAG_OFF_Z_H_POSITION; //mask
cparata 0:6a670fda63c2 444
cparata 0:6a670fda63c2 445 return MEMS_SUCCESS;
cparata 0:6a670fda63c2 446 }
cparata 0:6a670fda63c2 447 /*******************************************************************************
cparata 0:6a670fda63c2 448 * Function Name : LSM303AGR_MAG_R_WHO_AM_I
cparata 0:6a670fda63c2 449 * Description : Read WHO_AM_I
cparata 0:6a670fda63c2 450 * Input : Pointer to u8_t
cparata 0:6a670fda63c2 451 * Output : Status of WHO_AM_I
cparata 0:6a670fda63c2 452 * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
cparata 0:6a670fda63c2 453 *******************************************************************************/
cparata 0:6a670fda63c2 454
cparata 0:6a670fda63c2 455 status_t LSM303AGR_MAG_R_WHO_AM_I(void *handle, u8_t *value)
cparata 0:6a670fda63c2 456 {
cparata 0:6a670fda63c2 457 if( !LSM303AGR_MAG_ReadReg(handle, LSM303AGR_MAG_WHO_AM_I_REG, (u8_t *)value) )
cparata 0:6a670fda63c2 458 return MEMS_ERROR;
cparata 0:6a670fda63c2 459
cparata 0:6a670fda63c2 460 *value &= LSM303AGR_MAG_WHO_AM_I_MASK; //coerce
cparata 0:6a670fda63c2 461 *value = *value >> LSM303AGR_MAG_WHO_AM_I_POSITION; //mask
cparata 0:6a670fda63c2 462
cparata 0:6a670fda63c2 463 return MEMS_SUCCESS;
cparata 0:6a670fda63c2 464 }
cparata 0:6a670fda63c2 465 /*******************************************************************************
cparata 0:6a670fda63c2 466 * Function Name : LSM303AGR_MAG_W_MD
cparata 0:6a670fda63c2 467 * Description : Write MD
cparata 0:6a670fda63c2 468 * Input : LSM303AGR_MAG_MD_t
cparata 0:6a670fda63c2 469 * Output : None
cparata 0:6a670fda63c2 470 * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
cparata 0:6a670fda63c2 471 *******************************************************************************/
cparata 0:6a670fda63c2 472 status_t LSM303AGR_MAG_W_MD(void *handle, LSM303AGR_MAG_MD_t newValue)
cparata 0:6a670fda63c2 473 {
cparata 0:6a670fda63c2 474 u8_t value;
cparata 0:6a670fda63c2 475
cparata 0:6a670fda63c2 476 if( !LSM303AGR_MAG_ReadReg(handle, LSM303AGR_MAG_CFG_REG_A, &value) )
cparata 0:6a670fda63c2 477 return MEMS_ERROR;
cparata 0:6a670fda63c2 478
cparata 0:6a670fda63c2 479 value &= ~LSM303AGR_MAG_MD_MASK;
cparata 0:6a670fda63c2 480 value |= newValue;
cparata 0:6a670fda63c2 481
cparata 0:6a670fda63c2 482 if( !LSM303AGR_MAG_WriteReg(handle, LSM303AGR_MAG_CFG_REG_A, value) )
cparata 0:6a670fda63c2 483 return MEMS_ERROR;
cparata 0:6a670fda63c2 484
cparata 0:6a670fda63c2 485 return MEMS_SUCCESS;
cparata 0:6a670fda63c2 486 }
cparata 0:6a670fda63c2 487
cparata 0:6a670fda63c2 488 /*******************************************************************************
cparata 0:6a670fda63c2 489 * Function Name : LSM303AGR_MAG_R_MD
cparata 0:6a670fda63c2 490 * Description : Read MD
cparata 0:6a670fda63c2 491 * Input : Pointer to LSM303AGR_MAG_MD_t
cparata 0:6a670fda63c2 492 * Output : Status of MD see LSM303AGR_MAG_MD_t
cparata 0:6a670fda63c2 493 * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
cparata 0:6a670fda63c2 494 *******************************************************************************/
cparata 0:6a670fda63c2 495
cparata 0:6a670fda63c2 496 status_t LSM303AGR_MAG_R_MD(void *handle, LSM303AGR_MAG_MD_t *value)
cparata 0:6a670fda63c2 497 {
cparata 0:6a670fda63c2 498 if( !LSM303AGR_MAG_ReadReg(handle, LSM303AGR_MAG_CFG_REG_A, (u8_t *)value) )
cparata 0:6a670fda63c2 499 return MEMS_ERROR;
cparata 0:6a670fda63c2 500
cparata 0:6a670fda63c2 501 *value &= LSM303AGR_MAG_MD_MASK; //mask
cparata 0:6a670fda63c2 502
cparata 0:6a670fda63c2 503 return MEMS_SUCCESS;
cparata 0:6a670fda63c2 504 }
cparata 0:6a670fda63c2 505 /*******************************************************************************
cparata 0:6a670fda63c2 506 * Function Name : LSM303AGR_MAG_W_ODR
cparata 0:6a670fda63c2 507 * Description : Write ODR
cparata 0:6a670fda63c2 508 * Input : LSM303AGR_MAG_ODR_t
cparata 0:6a670fda63c2 509 * Output : None
cparata 0:6a670fda63c2 510 * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
cparata 0:6a670fda63c2 511 *******************************************************************************/
cparata 0:6a670fda63c2 512 status_t LSM303AGR_MAG_W_ODR(void *handle, LSM303AGR_MAG_ODR_t newValue)
cparata 0:6a670fda63c2 513 {
cparata 0:6a670fda63c2 514 u8_t value;
cparata 0:6a670fda63c2 515
cparata 0:6a670fda63c2 516 if( !LSM303AGR_MAG_ReadReg(handle, LSM303AGR_MAG_CFG_REG_A, &value) )
cparata 0:6a670fda63c2 517 return MEMS_ERROR;
cparata 0:6a670fda63c2 518
cparata 0:6a670fda63c2 519 value &= ~LSM303AGR_MAG_ODR_MASK;
cparata 0:6a670fda63c2 520 value |= newValue;
cparata 0:6a670fda63c2 521
cparata 0:6a670fda63c2 522 if( !LSM303AGR_MAG_WriteReg(handle, LSM303AGR_MAG_CFG_REG_A, value) )
cparata 0:6a670fda63c2 523 return MEMS_ERROR;
cparata 0:6a670fda63c2 524
cparata 0:6a670fda63c2 525 return MEMS_SUCCESS;
cparata 0:6a670fda63c2 526 }
cparata 0:6a670fda63c2 527
cparata 0:6a670fda63c2 528 /*******************************************************************************
cparata 0:6a670fda63c2 529 * Function Name : LSM303AGR_MAG_R_ODR
cparata 0:6a670fda63c2 530 * Description : Read ODR
cparata 0:6a670fda63c2 531 * Input : Pointer to LSM303AGR_MAG_ODR_t
cparata 0:6a670fda63c2 532 * Output : Status of ODR see LSM303AGR_MAG_ODR_t
cparata 0:6a670fda63c2 533 * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
cparata 0:6a670fda63c2 534 *******************************************************************************/
cparata 0:6a670fda63c2 535
cparata 0:6a670fda63c2 536 status_t LSM303AGR_MAG_R_ODR(void *handle, LSM303AGR_MAG_ODR_t *value)
cparata 0:6a670fda63c2 537 {
cparata 0:6a670fda63c2 538 if( !LSM303AGR_MAG_ReadReg(handle, LSM303AGR_MAG_CFG_REG_A, (u8_t *)value) )
cparata 0:6a670fda63c2 539 return MEMS_ERROR;
cparata 0:6a670fda63c2 540
cparata 0:6a670fda63c2 541 *value &= LSM303AGR_MAG_ODR_MASK; //mask
cparata 0:6a670fda63c2 542
cparata 0:6a670fda63c2 543 return MEMS_SUCCESS;
cparata 0:6a670fda63c2 544 }
cparata 0:6a670fda63c2 545 /*******************************************************************************
cparata 0:6a670fda63c2 546 * Function Name : LSM303AGR_MAG_W_LP
cparata 0:6a670fda63c2 547 * Description : Write LP
cparata 0:6a670fda63c2 548 * Input : LSM303AGR_MAG_LP_t
cparata 0:6a670fda63c2 549 * Output : None
cparata 0:6a670fda63c2 550 * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
cparata 0:6a670fda63c2 551 *******************************************************************************/
cparata 0:6a670fda63c2 552 status_t LSM303AGR_MAG_W_LP(void *handle, LSM303AGR_MAG_LP_t newValue)
cparata 0:6a670fda63c2 553 {
cparata 0:6a670fda63c2 554 u8_t value;
cparata 0:6a670fda63c2 555
cparata 0:6a670fda63c2 556 if( !LSM303AGR_MAG_ReadReg(handle, LSM303AGR_MAG_CFG_REG_A, &value) )
cparata 0:6a670fda63c2 557 return MEMS_ERROR;
cparata 0:6a670fda63c2 558
cparata 0:6a670fda63c2 559 value &= ~LSM303AGR_MAG_LP_MASK;
cparata 0:6a670fda63c2 560 value |= newValue;
cparata 0:6a670fda63c2 561
cparata 0:6a670fda63c2 562 if( !LSM303AGR_MAG_WriteReg(handle, LSM303AGR_MAG_CFG_REG_A, value) )
cparata 0:6a670fda63c2 563 return MEMS_ERROR;
cparata 0:6a670fda63c2 564
cparata 0:6a670fda63c2 565 return MEMS_SUCCESS;
cparata 0:6a670fda63c2 566 }
cparata 0:6a670fda63c2 567
cparata 0:6a670fda63c2 568 /*******************************************************************************
cparata 0:6a670fda63c2 569 * Function Name : LSM303AGR_MAG_R_LP
cparata 0:6a670fda63c2 570 * Description : Read LP
cparata 0:6a670fda63c2 571 * Input : Pointer to LSM303AGR_MAG_LP_t
cparata 0:6a670fda63c2 572 * Output : Status of LP see LSM303AGR_MAG_LP_t
cparata 0:6a670fda63c2 573 * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
cparata 0:6a670fda63c2 574 *******************************************************************************/
cparata 0:6a670fda63c2 575
cparata 0:6a670fda63c2 576 status_t LSM303AGR_MAG_R_LP(void *handle, LSM303AGR_MAG_LP_t *value)
cparata 0:6a670fda63c2 577 {
cparata 0:6a670fda63c2 578 if( !LSM303AGR_MAG_ReadReg(handle, LSM303AGR_MAG_CFG_REG_A, (u8_t *)value) )
cparata 0:6a670fda63c2 579 return MEMS_ERROR;
cparata 0:6a670fda63c2 580
cparata 0:6a670fda63c2 581 *value &= LSM303AGR_MAG_LP_MASK; //mask
cparata 0:6a670fda63c2 582
cparata 0:6a670fda63c2 583 return MEMS_SUCCESS;
cparata 0:6a670fda63c2 584 }
cparata 0:6a670fda63c2 585 /*******************************************************************************
cparata 0:6a670fda63c2 586 * Function Name : LSM303AGR_MAG_W_SOFT_RST
cparata 0:6a670fda63c2 587 * Description : Write SOFT_RST
cparata 0:6a670fda63c2 588 * Input : LSM303AGR_MAG_SOFT_RST_t
cparata 0:6a670fda63c2 589 * Output : None
cparata 0:6a670fda63c2 590 * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
cparata 0:6a670fda63c2 591 *******************************************************************************/
cparata 0:6a670fda63c2 592 status_t LSM303AGR_MAG_W_SOFT_RST(void *handle, LSM303AGR_MAG_SOFT_RST_t newValue)
cparata 0:6a670fda63c2 593 {
cparata 0:6a670fda63c2 594 u8_t value;
cparata 0:6a670fda63c2 595
cparata 0:6a670fda63c2 596 if( !LSM303AGR_MAG_ReadReg(handle, LSM303AGR_MAG_CFG_REG_A, &value) )
cparata 0:6a670fda63c2 597 return MEMS_ERROR;
cparata 0:6a670fda63c2 598
cparata 0:6a670fda63c2 599 value &= ~LSM303AGR_MAG_SOFT_RST_MASK;
cparata 0:6a670fda63c2 600 value |= newValue;
cparata 0:6a670fda63c2 601
cparata 0:6a670fda63c2 602 if( !LSM303AGR_MAG_WriteReg(handle, LSM303AGR_MAG_CFG_REG_A, value) )
cparata 0:6a670fda63c2 603 return MEMS_ERROR;
cparata 0:6a670fda63c2 604
cparata 0:6a670fda63c2 605 return MEMS_SUCCESS;
cparata 0:6a670fda63c2 606 }
cparata 0:6a670fda63c2 607
cparata 0:6a670fda63c2 608 /*******************************************************************************
cparata 0:6a670fda63c2 609 * Function Name : LSM303AGR_MAG_R_SOFT_RST
cparata 0:6a670fda63c2 610 * Description : Read SOFT_RST
cparata 0:6a670fda63c2 611 * Input : Pointer to LSM303AGR_MAG_SOFT_RST_t
cparata 0:6a670fda63c2 612 * Output : Status of SOFT_RST see LSM303AGR_MAG_SOFT_RST_t
cparata 0:6a670fda63c2 613 * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
cparata 0:6a670fda63c2 614 *******************************************************************************/
cparata 0:6a670fda63c2 615
cparata 0:6a670fda63c2 616 status_t LSM303AGR_MAG_R_SOFT_RST(void *handle, LSM303AGR_MAG_SOFT_RST_t *value)
cparata 0:6a670fda63c2 617 {
cparata 0:6a670fda63c2 618 if( !LSM303AGR_MAG_ReadReg(handle, LSM303AGR_MAG_CFG_REG_A, (u8_t *)value) )
cparata 0:6a670fda63c2 619 return MEMS_ERROR;
cparata 0:6a670fda63c2 620
cparata 0:6a670fda63c2 621 *value &= LSM303AGR_MAG_SOFT_RST_MASK; //mask
cparata 0:6a670fda63c2 622
cparata 0:6a670fda63c2 623 return MEMS_SUCCESS;
cparata 0:6a670fda63c2 624 }
cparata 0:6a670fda63c2 625 /*******************************************************************************
cparata 0:6a670fda63c2 626 * Function Name : LSM303AGR_MAG_W_LPF
cparata 0:6a670fda63c2 627 * Description : Write LPF
cparata 0:6a670fda63c2 628 * Input : LSM303AGR_MAG_LPF_t
cparata 0:6a670fda63c2 629 * Output : None
cparata 0:6a670fda63c2 630 * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
cparata 0:6a670fda63c2 631 *******************************************************************************/
cparata 0:6a670fda63c2 632 status_t LSM303AGR_MAG_W_LPF(void *handle, LSM303AGR_MAG_LPF_t newValue)
cparata 0:6a670fda63c2 633 {
cparata 0:6a670fda63c2 634 u8_t value;
cparata 0:6a670fda63c2 635
cparata 0:6a670fda63c2 636 if( !LSM303AGR_MAG_ReadReg(handle, LSM303AGR_MAG_CFG_REG_B, &value) )
cparata 0:6a670fda63c2 637 return MEMS_ERROR;
cparata 0:6a670fda63c2 638
cparata 0:6a670fda63c2 639 value &= ~LSM303AGR_MAG_LPF_MASK;
cparata 0:6a670fda63c2 640 value |= newValue;
cparata 0:6a670fda63c2 641
cparata 0:6a670fda63c2 642 if( !LSM303AGR_MAG_WriteReg(handle, LSM303AGR_MAG_CFG_REG_B, value) )
cparata 0:6a670fda63c2 643 return MEMS_ERROR;
cparata 0:6a670fda63c2 644
cparata 0:6a670fda63c2 645 return MEMS_SUCCESS;
cparata 0:6a670fda63c2 646 }
cparata 0:6a670fda63c2 647
cparata 0:6a670fda63c2 648 /*******************************************************************************
cparata 0:6a670fda63c2 649 * Function Name : LSM303AGR_MAG_R_LPF
cparata 0:6a670fda63c2 650 * Description : Read LPF
cparata 0:6a670fda63c2 651 * Input : Pointer to LSM303AGR_MAG_LPF_t
cparata 0:6a670fda63c2 652 * Output : Status of LPF see LSM303AGR_MAG_LPF_t
cparata 0:6a670fda63c2 653 * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
cparata 0:6a670fda63c2 654 *******************************************************************************/
cparata 0:6a670fda63c2 655
cparata 0:6a670fda63c2 656 status_t LSM303AGR_MAG_R_LPF(void *handle, LSM303AGR_MAG_LPF_t *value)
cparata 0:6a670fda63c2 657 {
cparata 0:6a670fda63c2 658 if( !LSM303AGR_MAG_ReadReg(handle, LSM303AGR_MAG_CFG_REG_B, (u8_t *)value) )
cparata 0:6a670fda63c2 659 return MEMS_ERROR;
cparata 0:6a670fda63c2 660
cparata 0:6a670fda63c2 661 *value &= LSM303AGR_MAG_LPF_MASK; //mask
cparata 0:6a670fda63c2 662
cparata 0:6a670fda63c2 663 return MEMS_SUCCESS;
cparata 0:6a670fda63c2 664 }
cparata 0:6a670fda63c2 665 /*******************************************************************************
cparata 0:6a670fda63c2 666 * Function Name : LSM303AGR_MAG_W_OFF_CANC
cparata 0:6a670fda63c2 667 * Description : Write OFF_CANC
cparata 0:6a670fda63c2 668 * Input : LSM303AGR_MAG_OFF_CANC_t
cparata 0:6a670fda63c2 669 * Output : None
cparata 0:6a670fda63c2 670 * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
cparata 0:6a670fda63c2 671 *******************************************************************************/
cparata 0:6a670fda63c2 672 status_t LSM303AGR_MAG_W_OFF_CANC(void *handle, LSM303AGR_MAG_OFF_CANC_t newValue)
cparata 0:6a670fda63c2 673 {
cparata 0:6a670fda63c2 674 u8_t value;
cparata 0:6a670fda63c2 675
cparata 0:6a670fda63c2 676 if( !LSM303AGR_MAG_ReadReg(handle, LSM303AGR_MAG_CFG_REG_B, &value) )
cparata 0:6a670fda63c2 677 return MEMS_ERROR;
cparata 0:6a670fda63c2 678
cparata 0:6a670fda63c2 679 value &= ~LSM303AGR_MAG_OFF_CANC_MASK;
cparata 0:6a670fda63c2 680 value |= newValue;
cparata 0:6a670fda63c2 681
cparata 0:6a670fda63c2 682 if( !LSM303AGR_MAG_WriteReg(handle, LSM303AGR_MAG_CFG_REG_B, value) )
cparata 0:6a670fda63c2 683 return MEMS_ERROR;
cparata 0:6a670fda63c2 684
cparata 0:6a670fda63c2 685 return MEMS_SUCCESS;
cparata 0:6a670fda63c2 686 }
cparata 0:6a670fda63c2 687
cparata 0:6a670fda63c2 688 /*******************************************************************************
cparata 0:6a670fda63c2 689 * Function Name : LSM303AGR_MAG_R_OFF_CANC
cparata 0:6a670fda63c2 690 * Description : Read OFF_CANC
cparata 0:6a670fda63c2 691 * Input : Pointer to LSM303AGR_MAG_OFF_CANC_t
cparata 0:6a670fda63c2 692 * Output : Status of OFF_CANC see LSM303AGR_MAG_OFF_CANC_t
cparata 0:6a670fda63c2 693 * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
cparata 0:6a670fda63c2 694 *******************************************************************************/
cparata 0:6a670fda63c2 695
cparata 0:6a670fda63c2 696 status_t LSM303AGR_MAG_R_OFF_CANC(void *handle, LSM303AGR_MAG_OFF_CANC_t *value)
cparata 0:6a670fda63c2 697 {
cparata 0:6a670fda63c2 698 if( !LSM303AGR_MAG_ReadReg(handle, LSM303AGR_MAG_CFG_REG_B, (u8_t *)value) )
cparata 0:6a670fda63c2 699 return MEMS_ERROR;
cparata 0:6a670fda63c2 700
cparata 0:6a670fda63c2 701 *value &= LSM303AGR_MAG_OFF_CANC_MASK; //mask
cparata 0:6a670fda63c2 702
cparata 0:6a670fda63c2 703 return MEMS_SUCCESS;
cparata 0:6a670fda63c2 704 }
cparata 0:6a670fda63c2 705 /*******************************************************************************
cparata 0:6a670fda63c2 706 * Function Name : LSM303AGR_MAG_W_SET_FREQ
cparata 0:6a670fda63c2 707 * Description : Write SET_FREQ
cparata 0:6a670fda63c2 708 * Input : LSM303AGR_MAG_SET_FREQ_t
cparata 0:6a670fda63c2 709 * Output : None
cparata 0:6a670fda63c2 710 * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
cparata 0:6a670fda63c2 711 *******************************************************************************/
cparata 0:6a670fda63c2 712 status_t LSM303AGR_MAG_W_SET_FREQ(void *handle, LSM303AGR_MAG_SET_FREQ_t newValue)
cparata 0:6a670fda63c2 713 {
cparata 0:6a670fda63c2 714 u8_t value;
cparata 0:6a670fda63c2 715
cparata 0:6a670fda63c2 716 if( !LSM303AGR_MAG_ReadReg(handle, LSM303AGR_MAG_CFG_REG_B, &value) )
cparata 0:6a670fda63c2 717 return MEMS_ERROR;
cparata 0:6a670fda63c2 718
cparata 0:6a670fda63c2 719 value &= ~LSM303AGR_MAG_SET_FREQ_MASK;
cparata 0:6a670fda63c2 720 value |= newValue;
cparata 0:6a670fda63c2 721
cparata 0:6a670fda63c2 722 if( !LSM303AGR_MAG_WriteReg(handle, LSM303AGR_MAG_CFG_REG_B, value) )
cparata 0:6a670fda63c2 723 return MEMS_ERROR;
cparata 0:6a670fda63c2 724
cparata 0:6a670fda63c2 725 return MEMS_SUCCESS;
cparata 0:6a670fda63c2 726 }
cparata 0:6a670fda63c2 727
cparata 0:6a670fda63c2 728 /*******************************************************************************
cparata 0:6a670fda63c2 729 * Function Name : LSM303AGR_MAG_R_SET_FREQ
cparata 0:6a670fda63c2 730 * Description : Read SET_FREQ
cparata 0:6a670fda63c2 731 * Input : Pointer to LSM303AGR_MAG_SET_FREQ_t
cparata 0:6a670fda63c2 732 * Output : Status of SET_FREQ see LSM303AGR_MAG_SET_FREQ_t
cparata 0:6a670fda63c2 733 * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
cparata 0:6a670fda63c2 734 *******************************************************************************/
cparata 0:6a670fda63c2 735
cparata 0:6a670fda63c2 736 status_t LSM303AGR_MAG_R_SET_FREQ(void *handle, LSM303AGR_MAG_SET_FREQ_t *value)
cparata 0:6a670fda63c2 737 {
cparata 0:6a670fda63c2 738 if( !LSM303AGR_MAG_ReadReg(handle, LSM303AGR_MAG_CFG_REG_B, (u8_t *)value) )
cparata 0:6a670fda63c2 739 return MEMS_ERROR;
cparata 0:6a670fda63c2 740
cparata 0:6a670fda63c2 741 *value &= LSM303AGR_MAG_SET_FREQ_MASK; //mask
cparata 0:6a670fda63c2 742
cparata 0:6a670fda63c2 743 return MEMS_SUCCESS;
cparata 0:6a670fda63c2 744 }
cparata 0:6a670fda63c2 745 /*******************************************************************************
cparata 0:6a670fda63c2 746 * Function Name : LSM303AGR_MAG_W_INT_ON_DATAOFF
cparata 0:6a670fda63c2 747 * Description : Write INT_ON_DATAOFF
cparata 0:6a670fda63c2 748 * Input : LSM303AGR_MAG_INT_ON_DATAOFF_t
cparata 0:6a670fda63c2 749 * Output : None
cparata 0:6a670fda63c2 750 * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
cparata 0:6a670fda63c2 751 *******************************************************************************/
cparata 0:6a670fda63c2 752 status_t LSM303AGR_MAG_W_INT_ON_DATAOFF(void *handle, LSM303AGR_MAG_INT_ON_DATAOFF_t newValue)
cparata 0:6a670fda63c2 753 {
cparata 0:6a670fda63c2 754 u8_t value;
cparata 0:6a670fda63c2 755
cparata 0:6a670fda63c2 756 if( !LSM303AGR_MAG_ReadReg(handle, LSM303AGR_MAG_CFG_REG_B, &value) )
cparata 0:6a670fda63c2 757 return MEMS_ERROR;
cparata 0:6a670fda63c2 758
cparata 0:6a670fda63c2 759 value &= ~LSM303AGR_MAG_INT_ON_DATAOFF_MASK;
cparata 0:6a670fda63c2 760 value |= newValue;
cparata 0:6a670fda63c2 761
cparata 0:6a670fda63c2 762 if( !LSM303AGR_MAG_WriteReg(handle, LSM303AGR_MAG_CFG_REG_B, value) )
cparata 0:6a670fda63c2 763 return MEMS_ERROR;
cparata 0:6a670fda63c2 764
cparata 0:6a670fda63c2 765 return MEMS_SUCCESS;
cparata 0:6a670fda63c2 766 }
cparata 0:6a670fda63c2 767
cparata 0:6a670fda63c2 768 /*******************************************************************************
cparata 0:6a670fda63c2 769 * Function Name : LSM303AGR_MAG_R_INT_ON_DATAOFF
cparata 0:6a670fda63c2 770 * Description : Read INT_ON_DATAOFF
cparata 0:6a670fda63c2 771 * Input : Pointer to LSM303AGR_MAG_INT_ON_DATAOFF_t
cparata 0:6a670fda63c2 772 * Output : Status of INT_ON_DATAOFF see LSM303AGR_MAG_INT_ON_DATAOFF_t
cparata 0:6a670fda63c2 773 * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
cparata 0:6a670fda63c2 774 *******************************************************************************/
cparata 0:6a670fda63c2 775
cparata 0:6a670fda63c2 776 status_t LSM303AGR_MAG_R_INT_ON_DATAOFF(void *handle, LSM303AGR_MAG_INT_ON_DATAOFF_t *value)
cparata 0:6a670fda63c2 777 {
cparata 0:6a670fda63c2 778 if( !LSM303AGR_MAG_ReadReg(handle, LSM303AGR_MAG_CFG_REG_B, (u8_t *)value) )
cparata 0:6a670fda63c2 779 return MEMS_ERROR;
cparata 0:6a670fda63c2 780
cparata 0:6a670fda63c2 781 *value &= LSM303AGR_MAG_INT_ON_DATAOFF_MASK; //mask
cparata 0:6a670fda63c2 782
cparata 0:6a670fda63c2 783 return MEMS_SUCCESS;
cparata 0:6a670fda63c2 784 }
cparata 0:6a670fda63c2 785 /*******************************************************************************
cparata 0:6a670fda63c2 786 * Function Name : LSM303AGR_MAG_W_INT_MAG
cparata 0:6a670fda63c2 787 * Description : Write INT_MAG
cparata 0:6a670fda63c2 788 * Input : LSM303AGR_MAG_INT_MAG_t
cparata 0:6a670fda63c2 789 * Output : None
cparata 0:6a670fda63c2 790 * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
cparata 0:6a670fda63c2 791 *******************************************************************************/
cparata 0:6a670fda63c2 792 status_t LSM303AGR_MAG_W_INT_MAG(void *handle, LSM303AGR_MAG_INT_MAG_t newValue)
cparata 0:6a670fda63c2 793 {
cparata 0:6a670fda63c2 794 u8_t value;
cparata 0:6a670fda63c2 795
cparata 0:6a670fda63c2 796 if( !LSM303AGR_MAG_ReadReg(handle, LSM303AGR_MAG_CFG_REG_C, &value) )
cparata 0:6a670fda63c2 797 return MEMS_ERROR;
cparata 0:6a670fda63c2 798
cparata 0:6a670fda63c2 799 value &= ~LSM303AGR_MAG_INT_MAG_MASK;
cparata 0:6a670fda63c2 800 value |= newValue;
cparata 0:6a670fda63c2 801
cparata 0:6a670fda63c2 802 if( !LSM303AGR_MAG_WriteReg(handle, LSM303AGR_MAG_CFG_REG_C, value) )
cparata 0:6a670fda63c2 803 return MEMS_ERROR;
cparata 0:6a670fda63c2 804
cparata 0:6a670fda63c2 805 return MEMS_SUCCESS;
cparata 0:6a670fda63c2 806 }
cparata 0:6a670fda63c2 807
cparata 0:6a670fda63c2 808 /*******************************************************************************
cparata 0:6a670fda63c2 809 * Function Name : LSM303AGR_MAG_R_INT_MAG
cparata 0:6a670fda63c2 810 * Description : Read INT_MAG
cparata 0:6a670fda63c2 811 * Input : Pointer to LSM303AGR_MAG_INT_MAG_t
cparata 0:6a670fda63c2 812 * Output : Status of INT_MAG see LSM303AGR_MAG_INT_MAG_t
cparata 0:6a670fda63c2 813 * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
cparata 0:6a670fda63c2 814 *******************************************************************************/
cparata 0:6a670fda63c2 815
cparata 0:6a670fda63c2 816 status_t LSM303AGR_MAG_R_INT_MAG(void *handle, LSM303AGR_MAG_INT_MAG_t *value)
cparata 0:6a670fda63c2 817 {
cparata 0:6a670fda63c2 818 if( !LSM303AGR_MAG_ReadReg(handle, LSM303AGR_MAG_CFG_REG_C, (u8_t *)value) )
cparata 0:6a670fda63c2 819 return MEMS_ERROR;
cparata 0:6a670fda63c2 820
cparata 0:6a670fda63c2 821 *value &= LSM303AGR_MAG_INT_MAG_MASK; //mask
cparata 0:6a670fda63c2 822
cparata 0:6a670fda63c2 823 return MEMS_SUCCESS;
cparata 0:6a670fda63c2 824 }
cparata 0:6a670fda63c2 825 /*******************************************************************************
cparata 0:6a670fda63c2 826 * Function Name : LSM303AGR_MAG_W_ST
cparata 0:6a670fda63c2 827 * Description : Write ST
cparata 0:6a670fda63c2 828 * Input : LSM303AGR_MAG_ST_t
cparata 0:6a670fda63c2 829 * Output : None
cparata 0:6a670fda63c2 830 * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
cparata 0:6a670fda63c2 831 *******************************************************************************/
cparata 0:6a670fda63c2 832 status_t LSM303AGR_MAG_W_ST(void *handle, LSM303AGR_MAG_ST_t newValue)
cparata 0:6a670fda63c2 833 {
cparata 0:6a670fda63c2 834 u8_t value;
cparata 0:6a670fda63c2 835
cparata 0:6a670fda63c2 836 if( !LSM303AGR_MAG_ReadReg(handle, LSM303AGR_MAG_CFG_REG_C, &value) )
cparata 0:6a670fda63c2 837 return MEMS_ERROR;
cparata 0:6a670fda63c2 838
cparata 0:6a670fda63c2 839 value &= ~LSM303AGR_MAG_ST_MASK;
cparata 0:6a670fda63c2 840 value |= newValue;
cparata 0:6a670fda63c2 841
cparata 0:6a670fda63c2 842 if( !LSM303AGR_MAG_WriteReg(handle, LSM303AGR_MAG_CFG_REG_C, value) )
cparata 0:6a670fda63c2 843 return MEMS_ERROR;
cparata 0:6a670fda63c2 844
cparata 0:6a670fda63c2 845 return MEMS_SUCCESS;
cparata 0:6a670fda63c2 846 }
cparata 0:6a670fda63c2 847
cparata 0:6a670fda63c2 848 /*******************************************************************************
cparata 0:6a670fda63c2 849 * Function Name : LSM303AGR_MAG_R_ST
cparata 0:6a670fda63c2 850 * Description : Read ST
cparata 0:6a670fda63c2 851 * Input : Pointer to LSM303AGR_MAG_ST_t
cparata 0:6a670fda63c2 852 * Output : Status of ST see LSM303AGR_MAG_ST_t
cparata 0:6a670fda63c2 853 * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
cparata 0:6a670fda63c2 854 *******************************************************************************/
cparata 0:6a670fda63c2 855
cparata 0:6a670fda63c2 856 status_t LSM303AGR_MAG_R_ST(void *handle, LSM303AGR_MAG_ST_t *value)
cparata 0:6a670fda63c2 857 {
cparata 0:6a670fda63c2 858 if( !LSM303AGR_MAG_ReadReg(handle, LSM303AGR_MAG_CFG_REG_C, (u8_t *)value) )
cparata 0:6a670fda63c2 859 return MEMS_ERROR;
cparata 0:6a670fda63c2 860
cparata 0:6a670fda63c2 861 *value &= LSM303AGR_MAG_ST_MASK; //mask
cparata 0:6a670fda63c2 862
cparata 0:6a670fda63c2 863 return MEMS_SUCCESS;
cparata 0:6a670fda63c2 864 }
cparata 0:6a670fda63c2 865 /*******************************************************************************
cparata 0:6a670fda63c2 866 * Function Name : LSM303AGR_MAG_W_BLE
cparata 0:6a670fda63c2 867 * Description : Write BLE
cparata 0:6a670fda63c2 868 * Input : LSM303AGR_MAG_BLE_t
cparata 0:6a670fda63c2 869 * Output : None
cparata 0:6a670fda63c2 870 * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
cparata 0:6a670fda63c2 871 *******************************************************************************/
cparata 0:6a670fda63c2 872 status_t LSM303AGR_MAG_W_BLE(void *handle, LSM303AGR_MAG_BLE_t newValue)
cparata 0:6a670fda63c2 873 {
cparata 0:6a670fda63c2 874 u8_t value;
cparata 0:6a670fda63c2 875
cparata 0:6a670fda63c2 876 if( !LSM303AGR_MAG_ReadReg(handle, LSM303AGR_MAG_CFG_REG_C, &value) )
cparata 0:6a670fda63c2 877 return MEMS_ERROR;
cparata 0:6a670fda63c2 878
cparata 0:6a670fda63c2 879 value &= ~LSM303AGR_MAG_BLE_MASK;
cparata 0:6a670fda63c2 880 value |= newValue;
cparata 0:6a670fda63c2 881
cparata 0:6a670fda63c2 882 if( !LSM303AGR_MAG_WriteReg(handle, LSM303AGR_MAG_CFG_REG_C, value) )
cparata 0:6a670fda63c2 883 return MEMS_ERROR;
cparata 0:6a670fda63c2 884
cparata 0:6a670fda63c2 885 return MEMS_SUCCESS;
cparata 0:6a670fda63c2 886 }
cparata 0:6a670fda63c2 887
cparata 0:6a670fda63c2 888 /*******************************************************************************
cparata 0:6a670fda63c2 889 * Function Name : LSM303AGR_MAG_R_BLE
cparata 0:6a670fda63c2 890 * Description : Read BLE
cparata 0:6a670fda63c2 891 * Input : Pointer to LSM303AGR_MAG_BLE_t
cparata 0:6a670fda63c2 892 * Output : Status of BLE see LSM303AGR_MAG_BLE_t
cparata 0:6a670fda63c2 893 * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
cparata 0:6a670fda63c2 894 *******************************************************************************/
cparata 0:6a670fda63c2 895
cparata 0:6a670fda63c2 896 status_t LSM303AGR_MAG_R_BLE(void *handle, LSM303AGR_MAG_BLE_t *value)
cparata 0:6a670fda63c2 897 {
cparata 0:6a670fda63c2 898 if( !LSM303AGR_MAG_ReadReg(handle, LSM303AGR_MAG_CFG_REG_C, (u8_t *)value) )
cparata 0:6a670fda63c2 899 return MEMS_ERROR;
cparata 0:6a670fda63c2 900
cparata 0:6a670fda63c2 901 *value &= LSM303AGR_MAG_BLE_MASK; //mask
cparata 0:6a670fda63c2 902
cparata 0:6a670fda63c2 903 return MEMS_SUCCESS;
cparata 0:6a670fda63c2 904 }
cparata 0:6a670fda63c2 905 /*******************************************************************************
cparata 0:6a670fda63c2 906 * Function Name : LSM303AGR_MAG_W_BDU
cparata 0:6a670fda63c2 907 * Description : Write BDU
cparata 0:6a670fda63c2 908 * Input : LSM303AGR_MAG_BDU_t
cparata 0:6a670fda63c2 909 * Output : None
cparata 0:6a670fda63c2 910 * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
cparata 0:6a670fda63c2 911 *******************************************************************************/
cparata 0:6a670fda63c2 912 status_t LSM303AGR_MAG_W_BDU(void *handle, LSM303AGR_MAG_BDU_t newValue)
cparata 0:6a670fda63c2 913 {
cparata 0:6a670fda63c2 914 u8_t value;
cparata 0:6a670fda63c2 915
cparata 0:6a670fda63c2 916 if( !LSM303AGR_MAG_ReadReg(handle, LSM303AGR_MAG_CFG_REG_C, &value) )
cparata 0:6a670fda63c2 917 return MEMS_ERROR;
cparata 0:6a670fda63c2 918
cparata 0:6a670fda63c2 919 value &= ~LSM303AGR_MAG_BDU_MASK;
cparata 0:6a670fda63c2 920 value |= newValue;
cparata 0:6a670fda63c2 921
cparata 0:6a670fda63c2 922 if( !LSM303AGR_MAG_WriteReg(handle, LSM303AGR_MAG_CFG_REG_C, value) )
cparata 0:6a670fda63c2 923 return MEMS_ERROR;
cparata 0:6a670fda63c2 924
cparata 0:6a670fda63c2 925 return MEMS_SUCCESS;
cparata 0:6a670fda63c2 926 }
cparata 0:6a670fda63c2 927
cparata 0:6a670fda63c2 928 /*******************************************************************************
cparata 0:6a670fda63c2 929 * Function Name : LSM303AGR_MAG_R_BDU
cparata 0:6a670fda63c2 930 * Description : Read BDU
cparata 0:6a670fda63c2 931 * Input : Pointer to LSM303AGR_MAG_BDU_t
cparata 0:6a670fda63c2 932 * Output : Status of BDU see LSM303AGR_MAG_BDU_t
cparata 0:6a670fda63c2 933 * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
cparata 0:6a670fda63c2 934 *******************************************************************************/
cparata 0:6a670fda63c2 935
cparata 0:6a670fda63c2 936 status_t LSM303AGR_MAG_R_BDU(void *handle, LSM303AGR_MAG_BDU_t *value)
cparata 0:6a670fda63c2 937 {
cparata 0:6a670fda63c2 938 if( !LSM303AGR_MAG_ReadReg(handle, LSM303AGR_MAG_CFG_REG_C, (u8_t *)value) )
cparata 0:6a670fda63c2 939 return MEMS_ERROR;
cparata 0:6a670fda63c2 940
cparata 0:6a670fda63c2 941 *value &= LSM303AGR_MAG_BDU_MASK; //mask
cparata 0:6a670fda63c2 942
cparata 0:6a670fda63c2 943 return MEMS_SUCCESS;
cparata 0:6a670fda63c2 944 }
cparata 0:6a670fda63c2 945 /*******************************************************************************
cparata 0:6a670fda63c2 946 * Function Name : LSM303AGR_MAG_W_I2C_DIS
cparata 0:6a670fda63c2 947 * Description : Write I2C_DIS
cparata 0:6a670fda63c2 948 * Input : LSM303AGR_MAG_I2C_DIS_t
cparata 0:6a670fda63c2 949 * Output : None
cparata 0:6a670fda63c2 950 * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
cparata 0:6a670fda63c2 951 *******************************************************************************/
cparata 0:6a670fda63c2 952 status_t LSM303AGR_MAG_W_I2C_DIS(void *handle, LSM303AGR_MAG_I2C_DIS_t newValue)
cparata 0:6a670fda63c2 953 {
cparata 0:6a670fda63c2 954 u8_t value;
cparata 0:6a670fda63c2 955
cparata 0:6a670fda63c2 956 if( !LSM303AGR_MAG_ReadReg(handle, LSM303AGR_MAG_CFG_REG_C, &value) )
cparata 0:6a670fda63c2 957 return MEMS_ERROR;
cparata 0:6a670fda63c2 958
cparata 0:6a670fda63c2 959 value &= ~LSM303AGR_MAG_I2C_DIS_MASK;
cparata 0:6a670fda63c2 960 value |= newValue;
cparata 0:6a670fda63c2 961
cparata 0:6a670fda63c2 962 if( !LSM303AGR_MAG_WriteReg(handle, LSM303AGR_MAG_CFG_REG_C, value) )
cparata 0:6a670fda63c2 963 return MEMS_ERROR;
cparata 0:6a670fda63c2 964
cparata 0:6a670fda63c2 965 return MEMS_SUCCESS;
cparata 0:6a670fda63c2 966 }
cparata 0:6a670fda63c2 967
cparata 0:6a670fda63c2 968 /*******************************************************************************
cparata 0:6a670fda63c2 969 * Function Name : LSM303AGR_MAG_R_I2C_DIS
cparata 0:6a670fda63c2 970 * Description : Read I2C_DIS
cparata 0:6a670fda63c2 971 * Input : Pointer to LSM303AGR_MAG_I2C_DIS_t
cparata 0:6a670fda63c2 972 * Output : Status of I2C_DIS see LSM303AGR_MAG_I2C_DIS_t
cparata 0:6a670fda63c2 973 * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
cparata 0:6a670fda63c2 974 *******************************************************************************/
cparata 0:6a670fda63c2 975
cparata 0:6a670fda63c2 976 status_t LSM303AGR_MAG_R_I2C_DIS(void *handle, LSM303AGR_MAG_I2C_DIS_t *value)
cparata 0:6a670fda63c2 977 {
cparata 0:6a670fda63c2 978 if( !LSM303AGR_MAG_ReadReg(handle, LSM303AGR_MAG_CFG_REG_C, (u8_t *)value) )
cparata 0:6a670fda63c2 979 return MEMS_ERROR;
cparata 0:6a670fda63c2 980
cparata 0:6a670fda63c2 981 *value &= LSM303AGR_MAG_I2C_DIS_MASK; //mask
cparata 0:6a670fda63c2 982
cparata 0:6a670fda63c2 983 return MEMS_SUCCESS;
cparata 0:6a670fda63c2 984 }
cparata 0:6a670fda63c2 985 /*******************************************************************************
cparata 0:6a670fda63c2 986 * Function Name : LSM303AGR_MAG_W_INT_MAG_PIN
cparata 0:6a670fda63c2 987 * Description : Write INT_MAG_PIN
cparata 0:6a670fda63c2 988 * Input : LSM303AGR_MAG_INT_MAG_PIN_t
cparata 0:6a670fda63c2 989 * Output : None
cparata 0:6a670fda63c2 990 * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
cparata 0:6a670fda63c2 991 *******************************************************************************/
cparata 0:6a670fda63c2 992 status_t LSM303AGR_MAG_W_INT_MAG_PIN(void *handle, LSM303AGR_MAG_INT_MAG_PIN_t newValue)
cparata 0:6a670fda63c2 993 {
cparata 0:6a670fda63c2 994 u8_t value;
cparata 0:6a670fda63c2 995
cparata 0:6a670fda63c2 996 if( !LSM303AGR_MAG_ReadReg(handle, LSM303AGR_MAG_CFG_REG_C, &value) )
cparata 0:6a670fda63c2 997 return MEMS_ERROR;
cparata 0:6a670fda63c2 998
cparata 0:6a670fda63c2 999 value &= ~LSM303AGR_MAG_INT_MAG_PIN_MASK;
cparata 0:6a670fda63c2 1000 value |= newValue;
cparata 0:6a670fda63c2 1001
cparata 0:6a670fda63c2 1002 if( !LSM303AGR_MAG_WriteReg(handle, LSM303AGR_MAG_CFG_REG_C, value) )
cparata 0:6a670fda63c2 1003 return MEMS_ERROR;
cparata 0:6a670fda63c2 1004
cparata 0:6a670fda63c2 1005 return MEMS_SUCCESS;
cparata 0:6a670fda63c2 1006 }
cparata 0:6a670fda63c2 1007
cparata 0:6a670fda63c2 1008 /*******************************************************************************
cparata 0:6a670fda63c2 1009 * Function Name : LSM303AGR_MAG_R_INT_MAG_PIN
cparata 0:6a670fda63c2 1010 * Description : Read INT_MAG_PIN
cparata 0:6a670fda63c2 1011 * Input : Pointer to LSM303AGR_MAG_INT_MAG_PIN_t
cparata 0:6a670fda63c2 1012 * Output : Status of INT_MAG_PIN see LSM303AGR_MAG_INT_MAG_PIN_t
cparata 0:6a670fda63c2 1013 * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
cparata 0:6a670fda63c2 1014 *******************************************************************************/
cparata 0:6a670fda63c2 1015
cparata 0:6a670fda63c2 1016 status_t LSM303AGR_MAG_R_INT_MAG_PIN(void *handle, LSM303AGR_MAG_INT_MAG_PIN_t *value)
cparata 0:6a670fda63c2 1017 {
cparata 0:6a670fda63c2 1018 if( !LSM303AGR_MAG_ReadReg(handle, LSM303AGR_MAG_CFG_REG_C, (u8_t *)value) )
cparata 0:6a670fda63c2 1019 return MEMS_ERROR;
cparata 0:6a670fda63c2 1020
cparata 0:6a670fda63c2 1021 *value &= LSM303AGR_MAG_INT_MAG_PIN_MASK; //mask
cparata 0:6a670fda63c2 1022
cparata 0:6a670fda63c2 1023 return MEMS_SUCCESS;
cparata 0:6a670fda63c2 1024 }
cparata 0:6a670fda63c2 1025 /*******************************************************************************
cparata 0:6a670fda63c2 1026 * Function Name : LSM303AGR_MAG_W_IEN
cparata 0:6a670fda63c2 1027 * Description : Write IEN
cparata 0:6a670fda63c2 1028 * Input : LSM303AGR_MAG_IEN_t
cparata 0:6a670fda63c2 1029 * Output : None
cparata 0:6a670fda63c2 1030 * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
cparata 0:6a670fda63c2 1031 *******************************************************************************/
cparata 0:6a670fda63c2 1032 status_t LSM303AGR_MAG_W_IEN(void *handle, LSM303AGR_MAG_IEN_t newValue)
cparata 0:6a670fda63c2 1033 {
cparata 0:6a670fda63c2 1034 u8_t value;
cparata 0:6a670fda63c2 1035
cparata 0:6a670fda63c2 1036 if( !LSM303AGR_MAG_ReadReg(handle, LSM303AGR_MAG_INT_CTRL_REG, &value) )
cparata 0:6a670fda63c2 1037 return MEMS_ERROR;
cparata 0:6a670fda63c2 1038
cparata 0:6a670fda63c2 1039 value &= ~LSM303AGR_MAG_IEN_MASK;
cparata 0:6a670fda63c2 1040 value |= newValue;
cparata 0:6a670fda63c2 1041
cparata 0:6a670fda63c2 1042 if( !LSM303AGR_MAG_WriteReg(handle, LSM303AGR_MAG_INT_CTRL_REG, value) )
cparata 0:6a670fda63c2 1043 return MEMS_ERROR;
cparata 0:6a670fda63c2 1044
cparata 0:6a670fda63c2 1045 return MEMS_SUCCESS;
cparata 0:6a670fda63c2 1046 }
cparata 0:6a670fda63c2 1047
cparata 0:6a670fda63c2 1048 /*******************************************************************************
cparata 0:6a670fda63c2 1049 * Function Name : LSM303AGR_MAG_R_IEN
cparata 0:6a670fda63c2 1050 * Description : Read IEN
cparata 0:6a670fda63c2 1051 * Input : Pointer to LSM303AGR_MAG_IEN_t
cparata 0:6a670fda63c2 1052 * Output : Status of IEN see LSM303AGR_MAG_IEN_t
cparata 0:6a670fda63c2 1053 * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
cparata 0:6a670fda63c2 1054 *******************************************************************************/
cparata 0:6a670fda63c2 1055
cparata 0:6a670fda63c2 1056 status_t LSM303AGR_MAG_R_IEN(void *handle, LSM303AGR_MAG_IEN_t *value)
cparata 0:6a670fda63c2 1057 {
cparata 0:6a670fda63c2 1058 if( !LSM303AGR_MAG_ReadReg(handle, LSM303AGR_MAG_INT_CTRL_REG, (u8_t *)value) )
cparata 0:6a670fda63c2 1059 return MEMS_ERROR;
cparata 0:6a670fda63c2 1060
cparata 0:6a670fda63c2 1061 *value &= LSM303AGR_MAG_IEN_MASK; //mask
cparata 0:6a670fda63c2 1062
cparata 0:6a670fda63c2 1063 return MEMS_SUCCESS;
cparata 0:6a670fda63c2 1064 }
cparata 0:6a670fda63c2 1065 /*******************************************************************************
cparata 0:6a670fda63c2 1066 * Function Name : LSM303AGR_MAG_W_IEL
cparata 0:6a670fda63c2 1067 * Description : Write IEL
cparata 0:6a670fda63c2 1068 * Input : LSM303AGR_MAG_IEL_t
cparata 0:6a670fda63c2 1069 * Output : None
cparata 0:6a670fda63c2 1070 * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
cparata 0:6a670fda63c2 1071 *******************************************************************************/
cparata 0:6a670fda63c2 1072 status_t LSM303AGR_MAG_W_IEL(void *handle, LSM303AGR_MAG_IEL_t newValue)
cparata 0:6a670fda63c2 1073 {
cparata 0:6a670fda63c2 1074 u8_t value;
cparata 0:6a670fda63c2 1075
cparata 0:6a670fda63c2 1076 if( !LSM303AGR_MAG_ReadReg(handle, LSM303AGR_MAG_INT_CTRL_REG, &value) )
cparata 0:6a670fda63c2 1077 return MEMS_ERROR;
cparata 0:6a670fda63c2 1078
cparata 0:6a670fda63c2 1079 value &= ~LSM303AGR_MAG_IEL_MASK;
cparata 0:6a670fda63c2 1080 value |= newValue;
cparata 0:6a670fda63c2 1081
cparata 0:6a670fda63c2 1082 if( !LSM303AGR_MAG_WriteReg(handle, LSM303AGR_MAG_INT_CTRL_REG, value) )
cparata 0:6a670fda63c2 1083 return MEMS_ERROR;
cparata 0:6a670fda63c2 1084
cparata 0:6a670fda63c2 1085 return MEMS_SUCCESS;
cparata 0:6a670fda63c2 1086 }
cparata 0:6a670fda63c2 1087
cparata 0:6a670fda63c2 1088 /*******************************************************************************
cparata 0:6a670fda63c2 1089 * Function Name : LSM303AGR_MAG_R_IEL
cparata 0:6a670fda63c2 1090 * Description : Read IEL
cparata 0:6a670fda63c2 1091 * Input : Pointer to LSM303AGR_MAG_IEL_t
cparata 0:6a670fda63c2 1092 * Output : Status of IEL see LSM303AGR_MAG_IEL_t
cparata 0:6a670fda63c2 1093 * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
cparata 0:6a670fda63c2 1094 *******************************************************************************/
cparata 0:6a670fda63c2 1095
cparata 0:6a670fda63c2 1096 status_t LSM303AGR_MAG_R_IEL(void *handle, LSM303AGR_MAG_IEL_t *value)
cparata 0:6a670fda63c2 1097 {
cparata 0:6a670fda63c2 1098 if( !LSM303AGR_MAG_ReadReg(handle, LSM303AGR_MAG_INT_CTRL_REG, (u8_t *)value) )
cparata 0:6a670fda63c2 1099 return MEMS_ERROR;
cparata 0:6a670fda63c2 1100
cparata 0:6a670fda63c2 1101 *value &= LSM303AGR_MAG_IEL_MASK; //mask
cparata 0:6a670fda63c2 1102
cparata 0:6a670fda63c2 1103 return MEMS_SUCCESS;
cparata 0:6a670fda63c2 1104 }
cparata 0:6a670fda63c2 1105 /*******************************************************************************
cparata 0:6a670fda63c2 1106 * Function Name : LSM303AGR_MAG_W_IEA
cparata 0:6a670fda63c2 1107 * Description : Write IEA
cparata 0:6a670fda63c2 1108 * Input : LSM303AGR_MAG_IEA_t
cparata 0:6a670fda63c2 1109 * Output : None
cparata 0:6a670fda63c2 1110 * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
cparata 0:6a670fda63c2 1111 *******************************************************************************/
cparata 0:6a670fda63c2 1112 status_t LSM303AGR_MAG_W_IEA(void *handle, LSM303AGR_MAG_IEA_t newValue)
cparata 0:6a670fda63c2 1113 {
cparata 0:6a670fda63c2 1114 u8_t value;
cparata 0:6a670fda63c2 1115
cparata 0:6a670fda63c2 1116 if( !LSM303AGR_MAG_ReadReg(handle, LSM303AGR_MAG_INT_CTRL_REG, &value) )
cparata 0:6a670fda63c2 1117 return MEMS_ERROR;
cparata 0:6a670fda63c2 1118
cparata 0:6a670fda63c2 1119 value &= ~LSM303AGR_MAG_IEA_MASK;
cparata 0:6a670fda63c2 1120 value |= newValue;
cparata 0:6a670fda63c2 1121
cparata 0:6a670fda63c2 1122 if( !LSM303AGR_MAG_WriteReg(handle, LSM303AGR_MAG_INT_CTRL_REG, value) )
cparata 0:6a670fda63c2 1123 return MEMS_ERROR;
cparata 0:6a670fda63c2 1124
cparata 0:6a670fda63c2 1125 return MEMS_SUCCESS;
cparata 0:6a670fda63c2 1126 }
cparata 0:6a670fda63c2 1127
cparata 0:6a670fda63c2 1128 /*******************************************************************************
cparata 0:6a670fda63c2 1129 * Function Name : LSM303AGR_MAG_R_IEA
cparata 0:6a670fda63c2 1130 * Description : Read IEA
cparata 0:6a670fda63c2 1131 * Input : Pointer to LSM303AGR_MAG_IEA_t
cparata 0:6a670fda63c2 1132 * Output : Status of IEA see LSM303AGR_MAG_IEA_t
cparata 0:6a670fda63c2 1133 * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
cparata 0:6a670fda63c2 1134 *******************************************************************************/
cparata 0:6a670fda63c2 1135
cparata 0:6a670fda63c2 1136 status_t LSM303AGR_MAG_R_IEA(void *handle, LSM303AGR_MAG_IEA_t *value)
cparata 0:6a670fda63c2 1137 {
cparata 0:6a670fda63c2 1138 if( !LSM303AGR_MAG_ReadReg(handle, LSM303AGR_MAG_INT_CTRL_REG, (u8_t *)value) )
cparata 0:6a670fda63c2 1139 return MEMS_ERROR;
cparata 0:6a670fda63c2 1140
cparata 0:6a670fda63c2 1141 *value &= LSM303AGR_MAG_IEA_MASK; //mask
cparata 0:6a670fda63c2 1142
cparata 0:6a670fda63c2 1143 return MEMS_SUCCESS;
cparata 0:6a670fda63c2 1144 }
cparata 0:6a670fda63c2 1145 /*******************************************************************************
cparata 0:6a670fda63c2 1146 * Function Name : LSM303AGR_MAG_W_ZIEN
cparata 0:6a670fda63c2 1147 * Description : Write ZIEN
cparata 0:6a670fda63c2 1148 * Input : LSM303AGR_MAG_ZIEN_t
cparata 0:6a670fda63c2 1149 * Output : None
cparata 0:6a670fda63c2 1150 * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
cparata 0:6a670fda63c2 1151 *******************************************************************************/
cparata 0:6a670fda63c2 1152 status_t LSM303AGR_MAG_W_ZIEN(void *handle, LSM303AGR_MAG_ZIEN_t newValue)
cparata 0:6a670fda63c2 1153 {
cparata 0:6a670fda63c2 1154 u8_t value;
cparata 0:6a670fda63c2 1155
cparata 0:6a670fda63c2 1156 if( !LSM303AGR_MAG_ReadReg(handle, LSM303AGR_MAG_INT_CTRL_REG, &value) )
cparata 0:6a670fda63c2 1157 return MEMS_ERROR;
cparata 0:6a670fda63c2 1158
cparata 0:6a670fda63c2 1159 value &= ~LSM303AGR_MAG_ZIEN_MASK;
cparata 0:6a670fda63c2 1160 value |= newValue;
cparata 0:6a670fda63c2 1161
cparata 0:6a670fda63c2 1162 if( !LSM303AGR_MAG_WriteReg(handle, LSM303AGR_MAG_INT_CTRL_REG, value) )
cparata 0:6a670fda63c2 1163 return MEMS_ERROR;
cparata 0:6a670fda63c2 1164
cparata 0:6a670fda63c2 1165 return MEMS_SUCCESS;
cparata 0:6a670fda63c2 1166 }
cparata 0:6a670fda63c2 1167
cparata 0:6a670fda63c2 1168 /*******************************************************************************
cparata 0:6a670fda63c2 1169 * Function Name : LSM303AGR_MAG_R_ZIEN
cparata 0:6a670fda63c2 1170 * Description : Read ZIEN
cparata 0:6a670fda63c2 1171 * Input : Pointer to LSM303AGR_MAG_ZIEN_t
cparata 0:6a670fda63c2 1172 * Output : Status of ZIEN see LSM303AGR_MAG_ZIEN_t
cparata 0:6a670fda63c2 1173 * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
cparata 0:6a670fda63c2 1174 *******************************************************************************/
cparata 0:6a670fda63c2 1175
cparata 0:6a670fda63c2 1176 status_t LSM303AGR_MAG_R_ZIEN(void *handle, LSM303AGR_MAG_ZIEN_t *value)
cparata 0:6a670fda63c2 1177 {
cparata 0:6a670fda63c2 1178 if( !LSM303AGR_MAG_ReadReg(handle, LSM303AGR_MAG_INT_CTRL_REG, (u8_t *)value) )
cparata 0:6a670fda63c2 1179 return MEMS_ERROR;
cparata 0:6a670fda63c2 1180
cparata 0:6a670fda63c2 1181 *value &= LSM303AGR_MAG_ZIEN_MASK; //mask
cparata 0:6a670fda63c2 1182
cparata 0:6a670fda63c2 1183 return MEMS_SUCCESS;
cparata 0:6a670fda63c2 1184 }
cparata 0:6a670fda63c2 1185 /*******************************************************************************
cparata 0:6a670fda63c2 1186 * Function Name : LSM303AGR_MAG_W_YIEN
cparata 0:6a670fda63c2 1187 * Description : Write YIEN
cparata 0:6a670fda63c2 1188 * Input : LSM303AGR_MAG_YIEN_t
cparata 0:6a670fda63c2 1189 * Output : None
cparata 0:6a670fda63c2 1190 * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
cparata 0:6a670fda63c2 1191 *******************************************************************************/
cparata 0:6a670fda63c2 1192 status_t LSM303AGR_MAG_W_YIEN(void *handle, LSM303AGR_MAG_YIEN_t newValue)
cparata 0:6a670fda63c2 1193 {
cparata 0:6a670fda63c2 1194 u8_t value;
cparata 0:6a670fda63c2 1195
cparata 0:6a670fda63c2 1196 if( !LSM303AGR_MAG_ReadReg(handle, LSM303AGR_MAG_INT_CTRL_REG, &value) )
cparata 0:6a670fda63c2 1197 return MEMS_ERROR;
cparata 0:6a670fda63c2 1198
cparata 0:6a670fda63c2 1199 value &= ~LSM303AGR_MAG_YIEN_MASK;
cparata 0:6a670fda63c2 1200 value |= newValue;
cparata 0:6a670fda63c2 1201
cparata 0:6a670fda63c2 1202 if( !LSM303AGR_MAG_WriteReg(handle, LSM303AGR_MAG_INT_CTRL_REG, value) )
cparata 0:6a670fda63c2 1203 return MEMS_ERROR;
cparata 0:6a670fda63c2 1204
cparata 0:6a670fda63c2 1205 return MEMS_SUCCESS;
cparata 0:6a670fda63c2 1206 }
cparata 0:6a670fda63c2 1207
cparata 0:6a670fda63c2 1208 /*******************************************************************************
cparata 0:6a670fda63c2 1209 * Function Name : LSM303AGR_MAG_R_YIEN
cparata 0:6a670fda63c2 1210 * Description : Read YIEN
cparata 0:6a670fda63c2 1211 * Input : Pointer to LSM303AGR_MAG_YIEN_t
cparata 0:6a670fda63c2 1212 * Output : Status of YIEN see LSM303AGR_MAG_YIEN_t
cparata 0:6a670fda63c2 1213 * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
cparata 0:6a670fda63c2 1214 *******************************************************************************/
cparata 0:6a670fda63c2 1215
cparata 0:6a670fda63c2 1216 status_t LSM303AGR_MAG_R_YIEN(void *handle, LSM303AGR_MAG_YIEN_t *value)
cparata 0:6a670fda63c2 1217 {
cparata 0:6a670fda63c2 1218 if( !LSM303AGR_MAG_ReadReg(handle, LSM303AGR_MAG_INT_CTRL_REG, (u8_t *)value) )
cparata 0:6a670fda63c2 1219 return MEMS_ERROR;
cparata 0:6a670fda63c2 1220
cparata 0:6a670fda63c2 1221 *value &= LSM303AGR_MAG_YIEN_MASK; //mask
cparata 0:6a670fda63c2 1222
cparata 0:6a670fda63c2 1223 return MEMS_SUCCESS;
cparata 0:6a670fda63c2 1224 }
cparata 0:6a670fda63c2 1225 /*******************************************************************************
cparata 0:6a670fda63c2 1226 * Function Name : LSM303AGR_MAG_W_XIEN
cparata 0:6a670fda63c2 1227 * Description : Write XIEN
cparata 0:6a670fda63c2 1228 * Input : LSM303AGR_MAG_XIEN_t
cparata 0:6a670fda63c2 1229 * Output : None
cparata 0:6a670fda63c2 1230 * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
cparata 0:6a670fda63c2 1231 *******************************************************************************/
cparata 0:6a670fda63c2 1232 status_t LSM303AGR_MAG_W_XIEN(void *handle, LSM303AGR_MAG_XIEN_t newValue)
cparata 0:6a670fda63c2 1233 {
cparata 0:6a670fda63c2 1234 u8_t value;
cparata 0:6a670fda63c2 1235
cparata 0:6a670fda63c2 1236 if( !LSM303AGR_MAG_ReadReg(handle, LSM303AGR_MAG_INT_CTRL_REG, &value) )
cparata 0:6a670fda63c2 1237 return MEMS_ERROR;
cparata 0:6a670fda63c2 1238
cparata 0:6a670fda63c2 1239 value &= ~LSM303AGR_MAG_XIEN_MASK;
cparata 0:6a670fda63c2 1240 value |= newValue;
cparata 0:6a670fda63c2 1241
cparata 0:6a670fda63c2 1242 if( !LSM303AGR_MAG_WriteReg(handle, LSM303AGR_MAG_INT_CTRL_REG, value) )
cparata 0:6a670fda63c2 1243 return MEMS_ERROR;
cparata 0:6a670fda63c2 1244
cparata 0:6a670fda63c2 1245 return MEMS_SUCCESS;
cparata 0:6a670fda63c2 1246 }
cparata 0:6a670fda63c2 1247
cparata 0:6a670fda63c2 1248 /*******************************************************************************
cparata 0:6a670fda63c2 1249 * Function Name : LSM303AGR_MAG_R_XIEN
cparata 0:6a670fda63c2 1250 * Description : Read XIEN
cparata 0:6a670fda63c2 1251 * Input : Pointer to LSM303AGR_MAG_XIEN_t
cparata 0:6a670fda63c2 1252 * Output : Status of XIEN see LSM303AGR_MAG_XIEN_t
cparata 0:6a670fda63c2 1253 * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
cparata 0:6a670fda63c2 1254 *******************************************************************************/
cparata 0:6a670fda63c2 1255
cparata 0:6a670fda63c2 1256 status_t LSM303AGR_MAG_R_XIEN(void *handle, LSM303AGR_MAG_XIEN_t *value)
cparata 0:6a670fda63c2 1257 {
cparata 0:6a670fda63c2 1258 if( !LSM303AGR_MAG_ReadReg(handle, LSM303AGR_MAG_INT_CTRL_REG, (u8_t *)value) )
cparata 0:6a670fda63c2 1259 return MEMS_ERROR;
cparata 0:6a670fda63c2 1260
cparata 0:6a670fda63c2 1261 *value &= LSM303AGR_MAG_XIEN_MASK; //mask
cparata 0:6a670fda63c2 1262
cparata 0:6a670fda63c2 1263 return MEMS_SUCCESS;
cparata 0:6a670fda63c2 1264 }
cparata 0:6a670fda63c2 1265 /*******************************************************************************
cparata 0:6a670fda63c2 1266 * Function Name : LSM303AGR_MAG_R_INT
cparata 0:6a670fda63c2 1267 * Description : Read INT
cparata 0:6a670fda63c2 1268 * Input : Pointer to LSM303AGR_MAG_INT_t
cparata 0:6a670fda63c2 1269 * Output : Status of INT see LSM303AGR_MAG_INT_t
cparata 0:6a670fda63c2 1270 * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
cparata 0:6a670fda63c2 1271 *******************************************************************************/
cparata 0:6a670fda63c2 1272
cparata 0:6a670fda63c2 1273 status_t LSM303AGR_MAG_R_INT(void *handle, LSM303AGR_MAG_INT_t *value)
cparata 0:6a670fda63c2 1274 {
cparata 0:6a670fda63c2 1275 if( !LSM303AGR_MAG_ReadReg(handle, LSM303AGR_MAG_INT_SOURCE_REG, (u8_t *)value) )
cparata 0:6a670fda63c2 1276 return MEMS_ERROR;
cparata 0:6a670fda63c2 1277
cparata 0:6a670fda63c2 1278 *value &= LSM303AGR_MAG_INT_MASK; //mask
cparata 0:6a670fda63c2 1279
cparata 0:6a670fda63c2 1280 return MEMS_SUCCESS;
cparata 0:6a670fda63c2 1281 }
cparata 0:6a670fda63c2 1282 /*******************************************************************************
cparata 0:6a670fda63c2 1283 * Function Name : LSM303AGR_MAG_R_MROI
cparata 0:6a670fda63c2 1284 * Description : Read MROI
cparata 0:6a670fda63c2 1285 * Input : Pointer to LSM303AGR_MAG_MROI_t
cparata 0:6a670fda63c2 1286 * Output : Status of MROI see LSM303AGR_MAG_MROI_t
cparata 0:6a670fda63c2 1287 * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
cparata 0:6a670fda63c2 1288 *******************************************************************************/
cparata 0:6a670fda63c2 1289
cparata 0:6a670fda63c2 1290 status_t LSM303AGR_MAG_R_MROI(void *handle, LSM303AGR_MAG_MROI_t *value)
cparata 0:6a670fda63c2 1291 {
cparata 0:6a670fda63c2 1292 if( !LSM303AGR_MAG_ReadReg(handle, LSM303AGR_MAG_INT_SOURCE_REG, (u8_t *)value) )
cparata 0:6a670fda63c2 1293 return MEMS_ERROR;
cparata 0:6a670fda63c2 1294
cparata 0:6a670fda63c2 1295 *value &= LSM303AGR_MAG_MROI_MASK; //mask
cparata 0:6a670fda63c2 1296
cparata 0:6a670fda63c2 1297 return MEMS_SUCCESS;
cparata 0:6a670fda63c2 1298 }
cparata 0:6a670fda63c2 1299 /*******************************************************************************
cparata 0:6a670fda63c2 1300 * Function Name : LSM303AGR_MAG_R_N_TH_S_Z
cparata 0:6a670fda63c2 1301 * Description : Read N_TH_S_Z
cparata 0:6a670fda63c2 1302 * Input : Pointer to LSM303AGR_MAG_N_TH_S_Z_t
cparata 0:6a670fda63c2 1303 * Output : Status of N_TH_S_Z see LSM303AGR_MAG_N_TH_S_Z_t
cparata 0:6a670fda63c2 1304 * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
cparata 0:6a670fda63c2 1305 *******************************************************************************/
cparata 0:6a670fda63c2 1306
cparata 0:6a670fda63c2 1307 status_t LSM303AGR_MAG_R_N_TH_S_Z(void *handle, LSM303AGR_MAG_N_TH_S_Z_t *value)
cparata 0:6a670fda63c2 1308 {
cparata 0:6a670fda63c2 1309 if( !LSM303AGR_MAG_ReadReg(handle, LSM303AGR_MAG_INT_SOURCE_REG, (u8_t *)value) )
cparata 0:6a670fda63c2 1310 return MEMS_ERROR;
cparata 0:6a670fda63c2 1311
cparata 0:6a670fda63c2 1312 *value &= LSM303AGR_MAG_N_TH_S_Z_MASK; //mask
cparata 0:6a670fda63c2 1313
cparata 0:6a670fda63c2 1314 return MEMS_SUCCESS;
cparata 0:6a670fda63c2 1315 }
cparata 0:6a670fda63c2 1316 /*******************************************************************************
cparata 0:6a670fda63c2 1317 * Function Name : LSM303AGR_MAG_R_N_TH_S_Y
cparata 0:6a670fda63c2 1318 * Description : Read N_TH_S_Y
cparata 0:6a670fda63c2 1319 * Input : Pointer to LSM303AGR_MAG_N_TH_S_Y_t
cparata 0:6a670fda63c2 1320 * Output : Status of N_TH_S_Y see LSM303AGR_MAG_N_TH_S_Y_t
cparata 0:6a670fda63c2 1321 * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
cparata 0:6a670fda63c2 1322 *******************************************************************************/
cparata 0:6a670fda63c2 1323
cparata 0:6a670fda63c2 1324 status_t LSM303AGR_MAG_R_N_TH_S_Y(void *handle, LSM303AGR_MAG_N_TH_S_Y_t *value)
cparata 0:6a670fda63c2 1325 {
cparata 0:6a670fda63c2 1326 if( !LSM303AGR_MAG_ReadReg(handle, LSM303AGR_MAG_INT_SOURCE_REG, (u8_t *)value) )
cparata 0:6a670fda63c2 1327 return MEMS_ERROR;
cparata 0:6a670fda63c2 1328
cparata 0:6a670fda63c2 1329 *value &= LSM303AGR_MAG_N_TH_S_Y_MASK; //mask
cparata 0:6a670fda63c2 1330
cparata 0:6a670fda63c2 1331 return MEMS_SUCCESS;
cparata 0:6a670fda63c2 1332 }
cparata 0:6a670fda63c2 1333 /*******************************************************************************
cparata 0:6a670fda63c2 1334 * Function Name : LSM303AGR_MAG_R_N_TH_S_X
cparata 0:6a670fda63c2 1335 * Description : Read N_TH_S_X
cparata 0:6a670fda63c2 1336 * Input : Pointer to LSM303AGR_MAG_N_TH_S_X_t
cparata 0:6a670fda63c2 1337 * Output : Status of N_TH_S_X see LSM303AGR_MAG_N_TH_S_X_t
cparata 0:6a670fda63c2 1338 * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
cparata 0:6a670fda63c2 1339 *******************************************************************************/
cparata 0:6a670fda63c2 1340
cparata 0:6a670fda63c2 1341 status_t LSM303AGR_MAG_R_N_TH_S_X(void *handle, LSM303AGR_MAG_N_TH_S_X_t *value)
cparata 0:6a670fda63c2 1342 {
cparata 0:6a670fda63c2 1343 if( !LSM303AGR_MAG_ReadReg(handle, LSM303AGR_MAG_INT_SOURCE_REG, (u8_t *)value) )
cparata 0:6a670fda63c2 1344 return MEMS_ERROR;
cparata 0:6a670fda63c2 1345
cparata 0:6a670fda63c2 1346 *value &= LSM303AGR_MAG_N_TH_S_X_MASK; //mask
cparata 0:6a670fda63c2 1347
cparata 0:6a670fda63c2 1348 return MEMS_SUCCESS;
cparata 0:6a670fda63c2 1349 }
cparata 0:6a670fda63c2 1350 /*******************************************************************************
cparata 0:6a670fda63c2 1351 * Function Name : LSM303AGR_MAG_R_P_TH_S_Z
cparata 0:6a670fda63c2 1352 * Description : Read P_TH_S_Z
cparata 0:6a670fda63c2 1353 * Input : Pointer to LSM303AGR_MAG_P_TH_S_Z_t
cparata 0:6a670fda63c2 1354 * Output : Status of P_TH_S_Z see LSM303AGR_MAG_P_TH_S_Z_t
cparata 0:6a670fda63c2 1355 * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
cparata 0:6a670fda63c2 1356 *******************************************************************************/
cparata 0:6a670fda63c2 1357
cparata 0:6a670fda63c2 1358 status_t LSM303AGR_MAG_R_P_TH_S_Z(void *handle, LSM303AGR_MAG_P_TH_S_Z_t *value)
cparata 0:6a670fda63c2 1359 {
cparata 0:6a670fda63c2 1360 if( !LSM303AGR_MAG_ReadReg(handle, LSM303AGR_MAG_INT_SOURCE_REG, (u8_t *)value) )
cparata 0:6a670fda63c2 1361 return MEMS_ERROR;
cparata 0:6a670fda63c2 1362
cparata 0:6a670fda63c2 1363 *value &= LSM303AGR_MAG_P_TH_S_Z_MASK; //mask
cparata 0:6a670fda63c2 1364
cparata 0:6a670fda63c2 1365 return MEMS_SUCCESS;
cparata 0:6a670fda63c2 1366 }
cparata 0:6a670fda63c2 1367 /*******************************************************************************
cparata 0:6a670fda63c2 1368 * Function Name : LSM303AGR_MAG_R_P_TH_S_Y
cparata 0:6a670fda63c2 1369 * Description : Read P_TH_S_Y
cparata 0:6a670fda63c2 1370 * Input : Pointer to LSM303AGR_MAG_P_TH_S_Y_t
cparata 0:6a670fda63c2 1371 * Output : Status of P_TH_S_Y see LSM303AGR_MAG_P_TH_S_Y_t
cparata 0:6a670fda63c2 1372 * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
cparata 0:6a670fda63c2 1373 *******************************************************************************/
cparata 0:6a670fda63c2 1374
cparata 0:6a670fda63c2 1375 status_t LSM303AGR_MAG_R_P_TH_S_Y(void *handle, LSM303AGR_MAG_P_TH_S_Y_t *value)
cparata 0:6a670fda63c2 1376 {
cparata 0:6a670fda63c2 1377 if( !LSM303AGR_MAG_ReadReg(handle, LSM303AGR_MAG_INT_SOURCE_REG, (u8_t *)value) )
cparata 0:6a670fda63c2 1378 return MEMS_ERROR;
cparata 0:6a670fda63c2 1379
cparata 0:6a670fda63c2 1380 *value &= LSM303AGR_MAG_P_TH_S_Y_MASK; //mask
cparata 0:6a670fda63c2 1381
cparata 0:6a670fda63c2 1382 return MEMS_SUCCESS;
cparata 0:6a670fda63c2 1383 }
cparata 0:6a670fda63c2 1384 /*******************************************************************************
cparata 0:6a670fda63c2 1385 * Function Name : LSM303AGR_MAG_R_P_TH_S_X
cparata 0:6a670fda63c2 1386 * Description : Read P_TH_S_X
cparata 0:6a670fda63c2 1387 * Input : Pointer to LSM303AGR_MAG_P_TH_S_X_t
cparata 0:6a670fda63c2 1388 * Output : Status of P_TH_S_X see LSM303AGR_MAG_P_TH_S_X_t
cparata 0:6a670fda63c2 1389 * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
cparata 0:6a670fda63c2 1390 *******************************************************************************/
cparata 0:6a670fda63c2 1391
cparata 0:6a670fda63c2 1392 status_t LSM303AGR_MAG_R_P_TH_S_X(void *handle, LSM303AGR_MAG_P_TH_S_X_t *value)
cparata 0:6a670fda63c2 1393 {
cparata 0:6a670fda63c2 1394 if( !LSM303AGR_MAG_ReadReg(handle, LSM303AGR_MAG_INT_SOURCE_REG, (u8_t *)value) )
cparata 0:6a670fda63c2 1395 return MEMS_ERROR;
cparata 0:6a670fda63c2 1396
cparata 0:6a670fda63c2 1397 *value &= LSM303AGR_MAG_P_TH_S_X_MASK; //mask
cparata 0:6a670fda63c2 1398
cparata 0:6a670fda63c2 1399 return MEMS_SUCCESS;
cparata 0:6a670fda63c2 1400 }
cparata 0:6a670fda63c2 1401
cparata 0:6a670fda63c2 1402 /*******************************************************************************
cparata 0:6a670fda63c2 1403 * Function Name : LSM303AGR_MAG_R_XDA
cparata 0:6a670fda63c2 1404 * Description : Read XDA
cparata 0:6a670fda63c2 1405 * Input : Pointer to LSM303AGR_MAG_XDA_t
cparata 0:6a670fda63c2 1406 * Output : Status of XDA see LSM303AGR_MAG_XDA_t
cparata 0:6a670fda63c2 1407 * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
cparata 0:6a670fda63c2 1408 *******************************************************************************/
cparata 0:6a670fda63c2 1409
cparata 0:6a670fda63c2 1410 status_t LSM303AGR_MAG_R_XDA(void *handle, LSM303AGR_MAG_XDA_t *value)
cparata 0:6a670fda63c2 1411 {
cparata 0:6a670fda63c2 1412 if( !LSM303AGR_MAG_ReadReg(handle, LSM303AGR_MAG_STATUS_REG, (u8_t *)value) )
cparata 0:6a670fda63c2 1413 return MEMS_ERROR;
cparata 0:6a670fda63c2 1414
cparata 0:6a670fda63c2 1415 *value &= LSM303AGR_MAG_XDA_MASK; //mask
cparata 0:6a670fda63c2 1416
cparata 0:6a670fda63c2 1417 return MEMS_SUCCESS;
cparata 0:6a670fda63c2 1418 }
cparata 0:6a670fda63c2 1419 /*******************************************************************************
cparata 0:6a670fda63c2 1420 * Function Name : LSM303AGR_MAG_R_YDA
cparata 0:6a670fda63c2 1421 * Description : Read YDA
cparata 0:6a670fda63c2 1422 * Input : Pointer to LSM303AGR_MAG_YDA_t
cparata 0:6a670fda63c2 1423 * Output : Status of YDA see LSM303AGR_MAG_YDA_t
cparata 0:6a670fda63c2 1424 * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
cparata 0:6a670fda63c2 1425 *******************************************************************************/
cparata 0:6a670fda63c2 1426
cparata 0:6a670fda63c2 1427 status_t LSM303AGR_MAG_R_YDA(void *handle, LSM303AGR_MAG_YDA_t *value)
cparata 0:6a670fda63c2 1428 {
cparata 0:6a670fda63c2 1429 if( !LSM303AGR_MAG_ReadReg(handle, LSM303AGR_MAG_STATUS_REG, (u8_t *)value) )
cparata 0:6a670fda63c2 1430 return MEMS_ERROR;
cparata 0:6a670fda63c2 1431
cparata 0:6a670fda63c2 1432 *value &= LSM303AGR_MAG_YDA_MASK; //mask
cparata 0:6a670fda63c2 1433
cparata 0:6a670fda63c2 1434 return MEMS_SUCCESS;
cparata 0:6a670fda63c2 1435 }
cparata 0:6a670fda63c2 1436 /*******************************************************************************
cparata 0:6a670fda63c2 1437 * Function Name : LSM303AGR_MAG_R_ZDA
cparata 0:6a670fda63c2 1438 * Description : Read ZDA
cparata 0:6a670fda63c2 1439 * Input : Pointer to LSM303AGR_MAG_ZDA_t
cparata 0:6a670fda63c2 1440 * Output : Status of ZDA see LSM303AGR_MAG_ZDA_t
cparata 0:6a670fda63c2 1441 * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
cparata 0:6a670fda63c2 1442 *******************************************************************************/
cparata 0:6a670fda63c2 1443
cparata 0:6a670fda63c2 1444 status_t LSM303AGR_MAG_R_ZDA(void *handle, LSM303AGR_MAG_ZDA_t *value)
cparata 0:6a670fda63c2 1445 {
cparata 0:6a670fda63c2 1446 if( !LSM303AGR_MAG_ReadReg(handle, LSM303AGR_MAG_STATUS_REG, (u8_t *)value) )
cparata 0:6a670fda63c2 1447 return MEMS_ERROR;
cparata 0:6a670fda63c2 1448
cparata 0:6a670fda63c2 1449 *value &= LSM303AGR_MAG_ZDA_MASK; //mask
cparata 0:6a670fda63c2 1450
cparata 0:6a670fda63c2 1451 return MEMS_SUCCESS;
cparata 0:6a670fda63c2 1452 }
cparata 0:6a670fda63c2 1453 /*******************************************************************************
cparata 0:6a670fda63c2 1454 * Function Name : LSM303AGR_MAG_R_ZYXDA
cparata 0:6a670fda63c2 1455 * Description : Read ZYXDA
cparata 0:6a670fda63c2 1456 * Input : Pointer to LSM303AGR_MAG_ZYXDA_t
cparata 0:6a670fda63c2 1457 * Output : Status of ZYXDA see LSM303AGR_MAG_ZYXDA_t
cparata 0:6a670fda63c2 1458 * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
cparata 0:6a670fda63c2 1459 *******************************************************************************/
cparata 0:6a670fda63c2 1460
cparata 0:6a670fda63c2 1461 status_t LSM303AGR_MAG_R_ZYXDA(void *handle, LSM303AGR_MAG_ZYXDA_t *value)
cparata 0:6a670fda63c2 1462 {
cparata 0:6a670fda63c2 1463 if( !LSM303AGR_MAG_ReadReg(handle, LSM303AGR_MAG_STATUS_REG, (u8_t *)value) )
cparata 0:6a670fda63c2 1464 return MEMS_ERROR;
cparata 0:6a670fda63c2 1465
cparata 0:6a670fda63c2 1466 *value &= LSM303AGR_MAG_ZYXDA_MASK; //mask
cparata 0:6a670fda63c2 1467
cparata 0:6a670fda63c2 1468 return MEMS_SUCCESS;
cparata 0:6a670fda63c2 1469 }
cparata 0:6a670fda63c2 1470 /*******************************************************************************
cparata 0:6a670fda63c2 1471 * Function Name : LSM303AGR_MAG_R_XOR
cparata 0:6a670fda63c2 1472 * Description : Read XOR
cparata 0:6a670fda63c2 1473 * Input : Pointer to LSM303AGR_MAG_XOR_t
cparata 0:6a670fda63c2 1474 * Output : Status of XOR see LSM303AGR_MAG_XOR_t
cparata 0:6a670fda63c2 1475 * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
cparata 0:6a670fda63c2 1476 *******************************************************************************/
cparata 0:6a670fda63c2 1477
cparata 0:6a670fda63c2 1478 status_t LSM303AGR_MAG_R_XOR(void *handle, LSM303AGR_MAG_XOR_t *value)
cparata 0:6a670fda63c2 1479 {
cparata 0:6a670fda63c2 1480 if( !LSM303AGR_MAG_ReadReg(handle, LSM303AGR_MAG_STATUS_REG, (u8_t *)value) )
cparata 0:6a670fda63c2 1481 return MEMS_ERROR;
cparata 0:6a670fda63c2 1482
cparata 0:6a670fda63c2 1483 *value &= LSM303AGR_MAG_XOR_MASK; //mask
cparata 0:6a670fda63c2 1484
cparata 0:6a670fda63c2 1485 return MEMS_SUCCESS;
cparata 0:6a670fda63c2 1486 }
cparata 0:6a670fda63c2 1487 /*******************************************************************************
cparata 0:6a670fda63c2 1488 * Function Name : LSM303AGR_MAG_R_YOR
cparata 0:6a670fda63c2 1489 * Description : Read YOR
cparata 0:6a670fda63c2 1490 * Input : Pointer to LSM303AGR_MAG_YOR_t
cparata 0:6a670fda63c2 1491 * Output : Status of YOR see LSM303AGR_MAG_YOR_t
cparata 0:6a670fda63c2 1492 * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
cparata 0:6a670fda63c2 1493 *******************************************************************************/
cparata 0:6a670fda63c2 1494
cparata 0:6a670fda63c2 1495 status_t LSM303AGR_MAG_R_YOR(void *handle, LSM303AGR_MAG_YOR_t *value)
cparata 0:6a670fda63c2 1496 {
cparata 0:6a670fda63c2 1497 if( !LSM303AGR_MAG_ReadReg(handle, LSM303AGR_MAG_STATUS_REG, (u8_t *)value) )
cparata 0:6a670fda63c2 1498 return MEMS_ERROR;
cparata 0:6a670fda63c2 1499
cparata 0:6a670fda63c2 1500 *value &= LSM303AGR_MAG_YOR_MASK; //mask
cparata 0:6a670fda63c2 1501
cparata 0:6a670fda63c2 1502 return MEMS_SUCCESS;
cparata 0:6a670fda63c2 1503 }
cparata 0:6a670fda63c2 1504 /*******************************************************************************
cparata 0:6a670fda63c2 1505 * Function Name : LSM303AGR_MAG_R_ZOR
cparata 0:6a670fda63c2 1506 * Description : Read ZOR
cparata 0:6a670fda63c2 1507 * Input : Pointer to LSM303AGR_MAG_ZOR_t
cparata 0:6a670fda63c2 1508 * Output : Status of ZOR see LSM303AGR_MAG_ZOR_t
cparata 0:6a670fda63c2 1509 * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
cparata 0:6a670fda63c2 1510 *******************************************************************************/
cparata 0:6a670fda63c2 1511
cparata 0:6a670fda63c2 1512 status_t LSM303AGR_MAG_R_ZOR(void *handle, LSM303AGR_MAG_ZOR_t *value)
cparata 0:6a670fda63c2 1513 {
cparata 0:6a670fda63c2 1514 if( !LSM303AGR_MAG_ReadReg(handle, LSM303AGR_MAG_STATUS_REG, (u8_t *)value) )
cparata 0:6a670fda63c2 1515 return MEMS_ERROR;
cparata 0:6a670fda63c2 1516
cparata 0:6a670fda63c2 1517 *value &= LSM303AGR_MAG_ZOR_MASK; //mask
cparata 0:6a670fda63c2 1518
cparata 0:6a670fda63c2 1519 return MEMS_SUCCESS;
cparata 0:6a670fda63c2 1520 }
cparata 0:6a670fda63c2 1521 /*******************************************************************************
cparata 0:6a670fda63c2 1522 * Function Name : LSM303AGR_MAG_R_ZYXOR
cparata 0:6a670fda63c2 1523 * Description : Read ZYXOR
cparata 0:6a670fda63c2 1524 * Input : Pointer to LSM303AGR_MAG_ZYXOR_t
cparata 0:6a670fda63c2 1525 * Output : Status of ZYXOR see LSM303AGR_MAG_ZYXOR_t
cparata 0:6a670fda63c2 1526 * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
cparata 0:6a670fda63c2 1527 *******************************************************************************/
cparata 0:6a670fda63c2 1528
cparata 0:6a670fda63c2 1529 status_t LSM303AGR_MAG_R_ZYXOR(void *handle, LSM303AGR_MAG_ZYXOR_t *value)
cparata 0:6a670fda63c2 1530 {
cparata 0:6a670fda63c2 1531 if( !LSM303AGR_MAG_ReadReg(handle, LSM303AGR_MAG_STATUS_REG, (u8_t *)value) )
cparata 0:6a670fda63c2 1532 return MEMS_ERROR;
cparata 0:6a670fda63c2 1533
cparata 0:6a670fda63c2 1534 *value &= LSM303AGR_MAG_ZYXOR_MASK; //mask
cparata 0:6a670fda63c2 1535
cparata 0:6a670fda63c2 1536 return MEMS_SUCCESS;
cparata 0:6a670fda63c2 1537 }
cparata 0:6a670fda63c2 1538 /*******************************************************************************
cparata 0:6a670fda63c2 1539 * Function Name : status_t LSM303AGR_MAG_Get_Raw_Magnetic(u8_t *buff)
cparata 0:6a670fda63c2 1540 * Description : Read Magnetic output register
cparata 0:6a670fda63c2 1541 * Input : pointer to [u8_t]
cparata 0:6a670fda63c2 1542 * Output : Magnetic buffer u8_t
cparata 0:6a670fda63c2 1543 * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
cparata 0:6a670fda63c2 1544 *******************************************************************************/
cparata 0:6a670fda63c2 1545 status_t LSM303AGR_MAG_Get_Raw_Magnetic(void *handle, u8_t *buff)
cparata 0:6a670fda63c2 1546 {
cparata 0:6a670fda63c2 1547 u8_t i, j, k;
cparata 0:6a670fda63c2 1548 u8_t numberOfByteForDimension;
cparata 0:6a670fda63c2 1549
cparata 0:6a670fda63c2 1550 numberOfByteForDimension=6/3;
cparata 0:6a670fda63c2 1551
cparata 0:6a670fda63c2 1552 k=0;
cparata 0:6a670fda63c2 1553 for (i=0; i<3;i++ )
cparata 0:6a670fda63c2 1554 {
cparata 0:6a670fda63c2 1555 for (j=0; j<numberOfByteForDimension;j++ )
cparata 0:6a670fda63c2 1556 {
cparata 0:6a670fda63c2 1557 if( !LSM303AGR_MAG_ReadReg(handle, LSM303AGR_MAG_OUTX_L_REG+k, &buff[k]))
cparata 0:6a670fda63c2 1558 return MEMS_ERROR;
cparata 0:6a670fda63c2 1559 k++;
cparata 0:6a670fda63c2 1560 }
cparata 0:6a670fda63c2 1561 }
cparata 0:6a670fda63c2 1562
cparata 0:6a670fda63c2 1563 return MEMS_SUCCESS;
cparata 0:6a670fda63c2 1564 }
cparata 0:6a670fda63c2 1565
cparata 0:6a670fda63c2 1566 #define LSM303AGR_MAG_SENSITIVITY 15/10
cparata 0:6a670fda63c2 1567
cparata 0:6a670fda63c2 1568 status_t LSM303AGR_MAG_Get_Magnetic(void *handle, int *buff)
cparata 0:6a670fda63c2 1569 {
cparata 0:6a670fda63c2 1570 Type3Axis16bit_U raw_data_tmp;
cparata 0:6a670fda63c2 1571
cparata 0:6a670fda63c2 1572 /* Read out raw magnetometer samples */
cparata 0:6a670fda63c2 1573 if(!LSM303AGR_MAG_Get_Raw_Magnetic(handle, raw_data_tmp.u8bit)) {
cparata 0:6a670fda63c2 1574 return MEMS_ERROR;
cparata 0:6a670fda63c2 1575 }
cparata 0:6a670fda63c2 1576
cparata 0:6a670fda63c2 1577 /* Applysensitivity */
cparata 0:6a670fda63c2 1578 buff[0] = raw_data_tmp.i16bit[0] * LSM303AGR_MAG_SENSITIVITY;
cparata 0:6a670fda63c2 1579 buff[1] = raw_data_tmp.i16bit[1] * LSM303AGR_MAG_SENSITIVITY;
cparata 0:6a670fda63c2 1580 buff[2] = raw_data_tmp.i16bit[2] * LSM303AGR_MAG_SENSITIVITY;
cparata 0:6a670fda63c2 1581
cparata 0:6a670fda63c2 1582 return MEMS_SUCCESS;
cparata 0:6a670fda63c2 1583 }
cparata 0:6a670fda63c2 1584
cparata 0:6a670fda63c2 1585 /*******************************************************************************
cparata 0:6a670fda63c2 1586 * Function Name : status_t LSM303AGR_MAG_Get_IntThreshld(u8_t *buff)
cparata 0:6a670fda63c2 1587 * Description : Read IntThreshld output register
cparata 0:6a670fda63c2 1588 * Input : pointer to [u8_t]
cparata 0:6a670fda63c2 1589 * Output : IntThreshld buffer u8_t
cparata 0:6a670fda63c2 1590 * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
cparata 0:6a670fda63c2 1591 *******************************************************************************/
cparata 0:6a670fda63c2 1592 status_t LSM303AGR_MAG_Get_IntThreshld(void *handle, u8_t *buff)
cparata 0:6a670fda63c2 1593 {
cparata 0:6a670fda63c2 1594 u8_t i, j, k;
cparata 0:6a670fda63c2 1595 u8_t numberOfByteForDimension;
cparata 0:6a670fda63c2 1596
cparata 0:6a670fda63c2 1597 numberOfByteForDimension=2/1;
cparata 0:6a670fda63c2 1598
cparata 0:6a670fda63c2 1599 k=0;
cparata 0:6a670fda63c2 1600 for (i=0; i<1;i++ )
cparata 0:6a670fda63c2 1601 {
cparata 0:6a670fda63c2 1602 for (j=0; j<numberOfByteForDimension;j++ )
cparata 0:6a670fda63c2 1603 {
cparata 0:6a670fda63c2 1604 if( !LSM303AGR_MAG_ReadReg(handle, LSM303AGR_MAG_INT_THS_L_REG+k, &buff[k]))
cparata 0:6a670fda63c2 1605 return MEMS_ERROR;
cparata 0:6a670fda63c2 1606 k++;
cparata 0:6a670fda63c2 1607 }
cparata 0:6a670fda63c2 1608 }
cparata 0:6a670fda63c2 1609
cparata 0:6a670fda63c2 1610 return MEMS_SUCCESS;
cparata 0:6a670fda63c2 1611 }
cparata 0:6a670fda63c2 1612
cparata 0:6a670fda63c2 1613 /*******************************************************************************
cparata 0:6a670fda63c2 1614 * Function Name : status_t LSM303AGR_MAG_Set_IntThreshld(u8_t *buff)
cparata 0:6a670fda63c2 1615 * Description : Write IntThreshld output register
cparata 0:6a670fda63c2 1616 * Input : pointer to [u8_t]
cparata 0:6a670fda63c2 1617 * Output : IntThreshld buffer u8_t
cparata 0:6a670fda63c2 1618 * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
cparata 0:6a670fda63c2 1619 *******************************************************************************/
cparata 0:6a670fda63c2 1620 status_t LSM303AGR_MAG_Set_IntThreshld(void *handle, u8_t *buff)
cparata 0:6a670fda63c2 1621 {
cparata 0:6a670fda63c2 1622 u8_t i, j, k;
cparata 0:6a670fda63c2 1623 u8_t numberOfByteForDimension;
cparata 0:6a670fda63c2 1624
cparata 0:6a670fda63c2 1625 numberOfByteForDimension=2/1;
cparata 0:6a670fda63c2 1626
cparata 0:6a670fda63c2 1627 k=0;
cparata 0:6a670fda63c2 1628 for (i=0; i<1;i++ )
cparata 0:6a670fda63c2 1629 {
cparata 0:6a670fda63c2 1630 for (j=0; j<numberOfByteForDimension;j++ )
cparata 0:6a670fda63c2 1631 {
cparata 0:6a670fda63c2 1632 if( !LSM303AGR_MAG_WriteReg(handle, LSM303AGR_MAG_INT_THS_L_REG+k, buff[k]))
cparata 0:6a670fda63c2 1633 return MEMS_ERROR;
cparata 0:6a670fda63c2 1634 k++;
cparata 0:6a670fda63c2 1635 }
cparata 0:6a670fda63c2 1636 }
cparata 0:6a670fda63c2 1637
cparata 0:6a670fda63c2 1638 return MEMS_SUCCESS;
cparata 0:6a670fda63c2 1639 }