h3 imported to make Bob work
H3LIS331DL.cpp@0:a9de25fd7c41, 2015-10-23 (annotated)
- Committer:
- daveheitzman
- Date:
- Fri Oct 23 18:26:28 2015 +0000
- Revision:
- 0:a9de25fd7c41
publishing mDot_Bob
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
daveheitzman | 0:a9de25fd7c41 | 1 | /* |
daveheitzman | 0:a9de25fd7c41 | 2 | * H3LIS331DL.cpp |
daveheitzman | 0:a9de25fd7c41 | 3 | * A library for 3-Axis Digital Accelerometer(±400g) |
daveheitzman | 0:a9de25fd7c41 | 4 | * |
daveheitzman | 0:a9de25fd7c41 | 5 | * Copyright (c) 2014 seeed technology inc. |
daveheitzman | 0:a9de25fd7c41 | 6 | * Website : www.seeed.cc |
daveheitzman | 0:a9de25fd7c41 | 7 | * Author : lawliet zou |
daveheitzman | 0:a9de25fd7c41 | 8 | * Create Time: April 2014 |
daveheitzman | 0:a9de25fd7c41 | 9 | * Change Log : |
daveheitzman | 0:a9de25fd7c41 | 10 | * |
daveheitzman | 0:a9de25fd7c41 | 11 | * The MIT License (MIT) |
daveheitzman | 0:a9de25fd7c41 | 12 | * |
daveheitzman | 0:a9de25fd7c41 | 13 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
daveheitzman | 0:a9de25fd7c41 | 14 | * of this software and associated documentation files (the "Software"), to deal |
daveheitzman | 0:a9de25fd7c41 | 15 | * in the Software without restriction, including without limitation the rights |
daveheitzman | 0:a9de25fd7c41 | 16 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
daveheitzman | 0:a9de25fd7c41 | 17 | * copies of the Software, and to permit persons to whom the Software is |
daveheitzman | 0:a9de25fd7c41 | 18 | * furnished to do so, subject to the following conditions: |
daveheitzman | 0:a9de25fd7c41 | 19 | * |
daveheitzman | 0:a9de25fd7c41 | 20 | * The above copyright notice and this permission notice shall be included in |
daveheitzman | 0:a9de25fd7c41 | 21 | * all copies or substantial portions of the Software. |
daveheitzman | 0:a9de25fd7c41 | 22 | * |
daveheitzman | 0:a9de25fd7c41 | 23 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
daveheitzman | 0:a9de25fd7c41 | 24 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
daveheitzman | 0:a9de25fd7c41 | 25 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
daveheitzman | 0:a9de25fd7c41 | 26 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
daveheitzman | 0:a9de25fd7c41 | 27 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
daveheitzman | 0:a9de25fd7c41 | 28 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
daveheitzman | 0:a9de25fd7c41 | 29 | * THE SOFTWARE. |
daveheitzman | 0:a9de25fd7c41 | 30 | */ |
daveheitzman | 0:a9de25fd7c41 | 31 | |
daveheitzman | 0:a9de25fd7c41 | 32 | #include "H3LIS331DL.h" |
daveheitzman | 0:a9de25fd7c41 | 33 | |
daveheitzman | 0:a9de25fd7c41 | 34 | void H3LIS331DL::init(H3LIS331DL_ODR_t odr,H3LIS331DL_Mode_t mode,H3LIS331DL_Fullscale_t fullScale) |
daveheitzman | 0:a9de25fd7c41 | 35 | { |
daveheitzman | 0:a9de25fd7c41 | 36 | //set output data rate |
daveheitzman | 0:a9de25fd7c41 | 37 | setODR(odr); |
daveheitzman | 0:a9de25fd7c41 | 38 | //set PowerMode |
daveheitzman | 0:a9de25fd7c41 | 39 | setMode( mode); |
daveheitzman | 0:a9de25fd7c41 | 40 | //set Fullscale |
daveheitzman | 0:a9de25fd7c41 | 41 | setFullScale( fullScale); |
daveheitzman | 0:a9de25fd7c41 | 42 | //set axis Enable |
daveheitzman | 0:a9de25fd7c41 | 43 | setAxis( H3LIS331DL_X_ENABLE | H3LIS331DL_Y_ENABLE | H3LIS331DL_Z_ENABLE); |
daveheitzman | 0:a9de25fd7c41 | 44 | } |
daveheitzman | 0:a9de25fd7c41 | 45 | |
daveheitzman | 0:a9de25fd7c41 | 46 | void H3LIS331DL::importPara(int16_t val_x, int16_t val_y, int16_t val_z) |
daveheitzman | 0:a9de25fd7c41 | 47 | { |
daveheitzman | 0:a9de25fd7c41 | 48 | _adjVal[0] = val_x; |
daveheitzman | 0:a9de25fd7c41 | 49 | _adjVal[1] = val_y; |
daveheitzman | 0:a9de25fd7c41 | 50 | _adjVal[2] = val_z; |
daveheitzman | 0:a9de25fd7c41 | 51 | } |
daveheitzman | 0:a9de25fd7c41 | 52 | void H3LIS331DL::readXYZ(int16_t* x, int16_t* y, int16_t* z) |
daveheitzman | 0:a9de25fd7c41 | 53 | { |
daveheitzman | 0:a9de25fd7c41 | 54 | //get Acceleration Raw data |
daveheitzman | 0:a9de25fd7c41 | 55 | AxesRaw_t data; |
daveheitzman | 0:a9de25fd7c41 | 56 | status_t response = getAccAxesRaw(&data); |
daveheitzman | 0:a9de25fd7c41 | 57 | if(MEMS_SUCCESS == response){ |
daveheitzman | 0:a9de25fd7c41 | 58 | *x = (data.AXIS_X - _adjVal[0]); |
daveheitzman | 0:a9de25fd7c41 | 59 | *y = (data.AXIS_Y - _adjVal[1]); |
daveheitzman | 0:a9de25fd7c41 | 60 | *z = (data.AXIS_Z - _adjVal[2]); |
daveheitzman | 0:a9de25fd7c41 | 61 | } |
daveheitzman | 0:a9de25fd7c41 | 62 | } |
daveheitzman | 0:a9de25fd7c41 | 63 | |
daveheitzman | 0:a9de25fd7c41 | 64 | void H3LIS331DL::getAcceleration(float* xyz) |
daveheitzman | 0:a9de25fd7c41 | 65 | { |
daveheitzman | 0:a9de25fd7c41 | 66 | AxesRaw_t data; |
daveheitzman | 0:a9de25fd7c41 | 67 | double gains = 0.003; |
daveheitzman | 0:a9de25fd7c41 | 68 | getAccAxesRaw(&data); |
daveheitzman | 0:a9de25fd7c41 | 69 | |
daveheitzman | 0:a9de25fd7c41 | 70 | xyz[0] = (data.AXIS_X - _adjVal[0]) * gains; |
daveheitzman | 0:a9de25fd7c41 | 71 | xyz[1] = (data.AXIS_Y - _adjVal[1]) * gains; |
daveheitzman | 0:a9de25fd7c41 | 72 | xyz[2] = (data.AXIS_Z - _adjVal[2]) * gains; |
daveheitzman | 0:a9de25fd7c41 | 73 | } |
daveheitzman | 0:a9de25fd7c41 | 74 | |
daveheitzman | 0:a9de25fd7c41 | 75 | |
daveheitzman | 0:a9de25fd7c41 | 76 | /******************************************************************************* |
daveheitzman | 0:a9de25fd7c41 | 77 | * Function Name : getWHO_AM_I |
daveheitzman | 0:a9de25fd7c41 | 78 | * Description : Read identification code from H3LIS331DL::WHO_AM_I register |
daveheitzman | 0:a9de25fd7c41 | 79 | * Input : char to be filled with the Device identification Value |
daveheitzman | 0:a9de25fd7c41 | 80 | * Output : None |
daveheitzman | 0:a9de25fd7c41 | 81 | * Return : Status [value of FSS] |
daveheitzman | 0:a9de25fd7c41 | 82 | *******************************************************************************/ |
daveheitzman | 0:a9de25fd7c41 | 83 | status_t H3LIS331DL::getWHO_AM_I(uint8_t* val){ |
daveheitzman | 0:a9de25fd7c41 | 84 | |
daveheitzman | 0:a9de25fd7c41 | 85 | if( !readReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_WHO_AM_I, val) ) |
daveheitzman | 0:a9de25fd7c41 | 86 | return MEMS_ERROR; |
daveheitzman | 0:a9de25fd7c41 | 87 | |
daveheitzman | 0:a9de25fd7c41 | 88 | return MEMS_SUCCESS; |
daveheitzman | 0:a9de25fd7c41 | 89 | } |
daveheitzman | 0:a9de25fd7c41 | 90 | |
daveheitzman | 0:a9de25fd7c41 | 91 | |
daveheitzman | 0:a9de25fd7c41 | 92 | /******************************************************************************* |
daveheitzman | 0:a9de25fd7c41 | 93 | * Function Name : setODR |
daveheitzman | 0:a9de25fd7c41 | 94 | * Description : Sets H3LIS331DL Accelerometer Output Data Rate |
daveheitzman | 0:a9de25fd7c41 | 95 | * Input : Output Data Rate |
daveheitzman | 0:a9de25fd7c41 | 96 | * Output : None |
daveheitzman | 0:a9de25fd7c41 | 97 | * Return : Status [MEMS_ERROR, MEMS_SUCCESS] |
daveheitzman | 0:a9de25fd7c41 | 98 | *******************************************************************************/ |
daveheitzman | 0:a9de25fd7c41 | 99 | status_t H3LIS331DL::setODR(H3LIS331DL_ODR_t dr){ |
daveheitzman | 0:a9de25fd7c41 | 100 | uint8_t value; |
daveheitzman | 0:a9de25fd7c41 | 101 | |
daveheitzman | 0:a9de25fd7c41 | 102 | if( !readReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_CTRL_REG1, &value) ) |
daveheitzman | 0:a9de25fd7c41 | 103 | return MEMS_ERROR; |
daveheitzman | 0:a9de25fd7c41 | 104 | |
daveheitzman | 0:a9de25fd7c41 | 105 | value &= 0xE7; |
daveheitzman | 0:a9de25fd7c41 | 106 | value |= dr<<H3LIS331DL_DR; |
daveheitzman | 0:a9de25fd7c41 | 107 | |
daveheitzman | 0:a9de25fd7c41 | 108 | if( !writeReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_CTRL_REG1, value) ) |
daveheitzman | 0:a9de25fd7c41 | 109 | return MEMS_ERROR; |
daveheitzman | 0:a9de25fd7c41 | 110 | |
daveheitzman | 0:a9de25fd7c41 | 111 | return MEMS_SUCCESS; |
daveheitzman | 0:a9de25fd7c41 | 112 | } |
daveheitzman | 0:a9de25fd7c41 | 113 | |
daveheitzman | 0:a9de25fd7c41 | 114 | |
daveheitzman | 0:a9de25fd7c41 | 115 | /******************************************************************************* |
daveheitzman | 0:a9de25fd7c41 | 116 | * Function Name : setMode |
daveheitzman | 0:a9de25fd7c41 | 117 | * Description : Sets H3LIS331DLH Accelerometer Operating Mode |
daveheitzman | 0:a9de25fd7c41 | 118 | * Input : Modality (H3LIS331DL_LOW_POWER, H3LIS331DL_NORMAL, H3LIS331DL_POWER_DOWN...) |
daveheitzman | 0:a9de25fd7c41 | 119 | * Output : None |
daveheitzman | 0:a9de25fd7c41 | 120 | * Return : Status [MEMS_ERROR, MEMS_SUCCESS] |
daveheitzman | 0:a9de25fd7c41 | 121 | *******************************************************************************/ |
daveheitzman | 0:a9de25fd7c41 | 122 | status_t H3LIS331DL::setMode(H3LIS331DL_Mode_t pm) { |
daveheitzman | 0:a9de25fd7c41 | 123 | uint8_t value; |
daveheitzman | 0:a9de25fd7c41 | 124 | |
daveheitzman | 0:a9de25fd7c41 | 125 | if( !readReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_CTRL_REG1, &value) ) |
daveheitzman | 0:a9de25fd7c41 | 126 | return MEMS_ERROR; |
daveheitzman | 0:a9de25fd7c41 | 127 | |
daveheitzman | 0:a9de25fd7c41 | 128 | value &= 0x1F; |
daveheitzman | 0:a9de25fd7c41 | 129 | value |= (pm<<H3LIS331DL_PM); |
daveheitzman | 0:a9de25fd7c41 | 130 | |
daveheitzman | 0:a9de25fd7c41 | 131 | if( !writeReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_CTRL_REG1, value) ) |
daveheitzman | 0:a9de25fd7c41 | 132 | return MEMS_ERROR; |
daveheitzman | 0:a9de25fd7c41 | 133 | |
daveheitzman | 0:a9de25fd7c41 | 134 | return MEMS_SUCCESS; |
daveheitzman | 0:a9de25fd7c41 | 135 | } |
daveheitzman | 0:a9de25fd7c41 | 136 | |
daveheitzman | 0:a9de25fd7c41 | 137 | /******************************************************************************* |
daveheitzman | 0:a9de25fd7c41 | 138 | * Function Name : setAxis |
daveheitzman | 0:a9de25fd7c41 | 139 | * Description : Enable/Disable LIS331DLH Axis |
daveheitzman | 0:a9de25fd7c41 | 140 | * Input : H3LIS331DL_X_ENABLE/H3LIS331DL_X_DISABLE | H3LIS331DL_Y_ENABLE/H3LIS331DL_Y_DISABLE |
daveheitzman | 0:a9de25fd7c41 | 141 | | H3LIS331DL_Z_ENABLE/H3LIS331DL_Z_DISABLE |
daveheitzman | 0:a9de25fd7c41 | 142 | * Output : None |
daveheitzman | 0:a9de25fd7c41 | 143 | * Note : You MUST use all input variable in the argument, as example |
daveheitzman | 0:a9de25fd7c41 | 144 | * Return : Status [MEMS_ERROR, MEMS_SUCCESS] |
daveheitzman | 0:a9de25fd7c41 | 145 | *******************************************************************************/ |
daveheitzman | 0:a9de25fd7c41 | 146 | status_t H3LIS331DL::setAxis(H3LIS331DL_Axis_t axis) { |
daveheitzman | 0:a9de25fd7c41 | 147 | uint8_t value; |
daveheitzman | 0:a9de25fd7c41 | 148 | |
daveheitzman | 0:a9de25fd7c41 | 149 | if( !readReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_CTRL_REG1, &value) ) |
daveheitzman | 0:a9de25fd7c41 | 150 | return MEMS_ERROR; |
daveheitzman | 0:a9de25fd7c41 | 151 | |
daveheitzman | 0:a9de25fd7c41 | 152 | value &= 0xF8; |
daveheitzman | 0:a9de25fd7c41 | 153 | value |= (0x07 & axis); |
daveheitzman | 0:a9de25fd7c41 | 154 | |
daveheitzman | 0:a9de25fd7c41 | 155 | if( !writeReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_CTRL_REG1, value) ) |
daveheitzman | 0:a9de25fd7c41 | 156 | return MEMS_ERROR; |
daveheitzman | 0:a9de25fd7c41 | 157 | |
daveheitzman | 0:a9de25fd7c41 | 158 | return MEMS_SUCCESS; |
daveheitzman | 0:a9de25fd7c41 | 159 | } |
daveheitzman | 0:a9de25fd7c41 | 160 | |
daveheitzman | 0:a9de25fd7c41 | 161 | |
daveheitzman | 0:a9de25fd7c41 | 162 | /******************************************************************************* |
daveheitzman | 0:a9de25fd7c41 | 163 | * Function Name : setFullScale |
daveheitzman | 0:a9de25fd7c41 | 164 | * Description : Sets the LIS331DLH FullScale |
daveheitzman | 0:a9de25fd7c41 | 165 | * Input : H3LIS331DL_FULLSCALE_2/H3LIS331DL_FULLSCALE_4/H3LIS331DL_FULLSCALE_8 |
daveheitzman | 0:a9de25fd7c41 | 166 | * Output : None |
daveheitzman | 0:a9de25fd7c41 | 167 | * Return : Status [MEMS_ERROR, MEMS_SUCCESS] |
daveheitzman | 0:a9de25fd7c41 | 168 | *******************************************************************************/ |
daveheitzman | 0:a9de25fd7c41 | 169 | status_t H3LIS331DL::setFullScale(H3LIS331DL_Fullscale_t fs) { |
daveheitzman | 0:a9de25fd7c41 | 170 | uint8_t value; |
daveheitzman | 0:a9de25fd7c41 | 171 | |
daveheitzman | 0:a9de25fd7c41 | 172 | if( !readReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_CTRL_REG4, &value) ) |
daveheitzman | 0:a9de25fd7c41 | 173 | return MEMS_ERROR; |
daveheitzman | 0:a9de25fd7c41 | 174 | |
daveheitzman | 0:a9de25fd7c41 | 175 | value &= 0xCF; |
daveheitzman | 0:a9de25fd7c41 | 176 | value |= (fs<<H3LIS331DL_FS); |
daveheitzman | 0:a9de25fd7c41 | 177 | |
daveheitzman | 0:a9de25fd7c41 | 178 | if( !writeReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_CTRL_REG4, value) ) |
daveheitzman | 0:a9de25fd7c41 | 179 | return MEMS_ERROR; |
daveheitzman | 0:a9de25fd7c41 | 180 | |
daveheitzman | 0:a9de25fd7c41 | 181 | return MEMS_SUCCESS; |
daveheitzman | 0:a9de25fd7c41 | 182 | } |
daveheitzman | 0:a9de25fd7c41 | 183 | |
daveheitzman | 0:a9de25fd7c41 | 184 | |
daveheitzman | 0:a9de25fd7c41 | 185 | /******************************************************************************* |
daveheitzman | 0:a9de25fd7c41 | 186 | * Function Name : setBDU |
daveheitzman | 0:a9de25fd7c41 | 187 | * Description : Enable/Disable Block Data Update Functionality |
daveheitzman | 0:a9de25fd7c41 | 188 | * Input : MEMS_ENABLE/MEMS_DISABLE |
daveheitzman | 0:a9de25fd7c41 | 189 | * Output : None |
daveheitzman | 0:a9de25fd7c41 | 190 | * Return : Status [MEMS_ERROR, MEMS_SUCCESS] |
daveheitzman | 0:a9de25fd7c41 | 191 | *******************************************************************************/ |
daveheitzman | 0:a9de25fd7c41 | 192 | status_t H3LIS331DL::setBDU(State_t bdu) { |
daveheitzman | 0:a9de25fd7c41 | 193 | uint8_t value; |
daveheitzman | 0:a9de25fd7c41 | 194 | |
daveheitzman | 0:a9de25fd7c41 | 195 | if( !readReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_CTRL_REG4, &value) ) |
daveheitzman | 0:a9de25fd7c41 | 196 | return MEMS_ERROR; |
daveheitzman | 0:a9de25fd7c41 | 197 | |
daveheitzman | 0:a9de25fd7c41 | 198 | value &= 0x7F; |
daveheitzman | 0:a9de25fd7c41 | 199 | value |= (bdu<<H3LIS331DL_BDU); |
daveheitzman | 0:a9de25fd7c41 | 200 | |
daveheitzman | 0:a9de25fd7c41 | 201 | if( !writeReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_CTRL_REG4, value) ) |
daveheitzman | 0:a9de25fd7c41 | 202 | return MEMS_ERROR; |
daveheitzman | 0:a9de25fd7c41 | 203 | |
daveheitzman | 0:a9de25fd7c41 | 204 | return MEMS_SUCCESS; |
daveheitzman | 0:a9de25fd7c41 | 205 | } |
daveheitzman | 0:a9de25fd7c41 | 206 | |
daveheitzman | 0:a9de25fd7c41 | 207 | |
daveheitzman | 0:a9de25fd7c41 | 208 | /******************************************************************************* |
daveheitzman | 0:a9de25fd7c41 | 209 | * Function Name : setBLE |
daveheitzman | 0:a9de25fd7c41 | 210 | * Description : Set Endianess (MSB/LSB) |
daveheitzman | 0:a9de25fd7c41 | 211 | * Input : H3LIS331DL_BLE_LSB / H3LIS331DL_BLE_MSB |
daveheitzman | 0:a9de25fd7c41 | 212 | * Output : None |
daveheitzman | 0:a9de25fd7c41 | 213 | * Return : Status [MEMS_ERROR, MEMS_SUCCESS] |
daveheitzman | 0:a9de25fd7c41 | 214 | *******************************************************************************/ |
daveheitzman | 0:a9de25fd7c41 | 215 | status_t H3LIS331DL::setBLE(H3LIS331DL_Endianess_t ble) { |
daveheitzman | 0:a9de25fd7c41 | 216 | uint8_t value; |
daveheitzman | 0:a9de25fd7c41 | 217 | |
daveheitzman | 0:a9de25fd7c41 | 218 | if( !readReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_CTRL_REG4, &value) ) |
daveheitzman | 0:a9de25fd7c41 | 219 | return MEMS_ERROR; |
daveheitzman | 0:a9de25fd7c41 | 220 | |
daveheitzman | 0:a9de25fd7c41 | 221 | value &= 0xBF; |
daveheitzman | 0:a9de25fd7c41 | 222 | value |= (ble<<H3LIS331DL_BLE); |
daveheitzman | 0:a9de25fd7c41 | 223 | |
daveheitzman | 0:a9de25fd7c41 | 224 | if( !writeReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_CTRL_REG4, value) ) |
daveheitzman | 0:a9de25fd7c41 | 225 | return MEMS_ERROR; |
daveheitzman | 0:a9de25fd7c41 | 226 | |
daveheitzman | 0:a9de25fd7c41 | 227 | return MEMS_SUCCESS; |
daveheitzman | 0:a9de25fd7c41 | 228 | } |
daveheitzman | 0:a9de25fd7c41 | 229 | |
daveheitzman | 0:a9de25fd7c41 | 230 | |
daveheitzman | 0:a9de25fd7c41 | 231 | /******************************************************************************* |
daveheitzman | 0:a9de25fd7c41 | 232 | * Function Name : setFDS |
daveheitzman | 0:a9de25fd7c41 | 233 | * Description : Set Filter Data Selection |
daveheitzman | 0:a9de25fd7c41 | 234 | * Input : MEMS_ENABLE/MEMS_DISABLE |
daveheitzman | 0:a9de25fd7c41 | 235 | * Output : None |
daveheitzman | 0:a9de25fd7c41 | 236 | * Return : Status [MEMS_ERROR, MEMS_SUCCESS] |
daveheitzman | 0:a9de25fd7c41 | 237 | *******************************************************************************/ |
daveheitzman | 0:a9de25fd7c41 | 238 | status_t H3LIS331DL::setFDS(State_t fds) { |
daveheitzman | 0:a9de25fd7c41 | 239 | uint8_t value; |
daveheitzman | 0:a9de25fd7c41 | 240 | |
daveheitzman | 0:a9de25fd7c41 | 241 | if( !readReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_CTRL_REG2, &value) ) |
daveheitzman | 0:a9de25fd7c41 | 242 | return MEMS_ERROR; |
daveheitzman | 0:a9de25fd7c41 | 243 | |
daveheitzman | 0:a9de25fd7c41 | 244 | value &= 0xEF; |
daveheitzman | 0:a9de25fd7c41 | 245 | value |= (fds<<H3LIS331DL_FDS); |
daveheitzman | 0:a9de25fd7c41 | 246 | |
daveheitzman | 0:a9de25fd7c41 | 247 | if( !writeReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_CTRL_REG2, value) ) |
daveheitzman | 0:a9de25fd7c41 | 248 | return MEMS_ERROR; |
daveheitzman | 0:a9de25fd7c41 | 249 | |
daveheitzman | 0:a9de25fd7c41 | 250 | return MEMS_SUCCESS; |
daveheitzman | 0:a9de25fd7c41 | 251 | } |
daveheitzman | 0:a9de25fd7c41 | 252 | |
daveheitzman | 0:a9de25fd7c41 | 253 | |
daveheitzman | 0:a9de25fd7c41 | 254 | /******************************************************************************* |
daveheitzman | 0:a9de25fd7c41 | 255 | * Function Name : setBOOT |
daveheitzman | 0:a9de25fd7c41 | 256 | * Description : Rebot memory content |
daveheitzman | 0:a9de25fd7c41 | 257 | * Input : MEMS_ENABLE/MEMS_DISABLE |
daveheitzman | 0:a9de25fd7c41 | 258 | * Output : None |
daveheitzman | 0:a9de25fd7c41 | 259 | * Return : Status [MEMS_ERROR, MEMS_SUCCESS] |
daveheitzman | 0:a9de25fd7c41 | 260 | *******************************************************************************/ |
daveheitzman | 0:a9de25fd7c41 | 261 | status_t H3LIS331DL::setBOOT(State_t boot) { |
daveheitzman | 0:a9de25fd7c41 | 262 | uint8_t value; |
daveheitzman | 0:a9de25fd7c41 | 263 | |
daveheitzman | 0:a9de25fd7c41 | 264 | if( !readReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_CTRL_REG2, &value) ) |
daveheitzman | 0:a9de25fd7c41 | 265 | return MEMS_ERROR; |
daveheitzman | 0:a9de25fd7c41 | 266 | |
daveheitzman | 0:a9de25fd7c41 | 267 | value &= 0x7F; |
daveheitzman | 0:a9de25fd7c41 | 268 | value |= (boot<<H3LIS331DL_BOOT); |
daveheitzman | 0:a9de25fd7c41 | 269 | |
daveheitzman | 0:a9de25fd7c41 | 270 | if( !writeReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_CTRL_REG2, value) ) |
daveheitzman | 0:a9de25fd7c41 | 271 | return MEMS_ERROR; |
daveheitzman | 0:a9de25fd7c41 | 272 | |
daveheitzman | 0:a9de25fd7c41 | 273 | return MEMS_SUCCESS; |
daveheitzman | 0:a9de25fd7c41 | 274 | } |
daveheitzman | 0:a9de25fd7c41 | 275 | |
daveheitzman | 0:a9de25fd7c41 | 276 | |
daveheitzman | 0:a9de25fd7c41 | 277 | /******************************************************************************* |
daveheitzman | 0:a9de25fd7c41 | 278 | * Function Name : setSelfTest |
daveheitzman | 0:a9de25fd7c41 | 279 | * Description : Set Self Test Modality |
daveheitzman | 0:a9de25fd7c41 | 280 | * Input : MEMS_DISABLE/MEMS_ENABLE |
daveheitzman | 0:a9de25fd7c41 | 281 | * Output : None |
daveheitzman | 0:a9de25fd7c41 | 282 | * Return : Status [MEMS_ERROR, MEMS_SUCCESS] |
daveheitzman | 0:a9de25fd7c41 | 283 | *******************************************************************************/ |
daveheitzman | 0:a9de25fd7c41 | 284 | status_t H3LIS331DL::setSelfTest(State_t st) { |
daveheitzman | 0:a9de25fd7c41 | 285 | uint8_t value; |
daveheitzman | 0:a9de25fd7c41 | 286 | |
daveheitzman | 0:a9de25fd7c41 | 287 | if( !readReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_CTRL_REG4, &value) ) |
daveheitzman | 0:a9de25fd7c41 | 288 | return MEMS_ERROR; |
daveheitzman | 0:a9de25fd7c41 | 289 | |
daveheitzman | 0:a9de25fd7c41 | 290 | value &= 0xFD; |
daveheitzman | 0:a9de25fd7c41 | 291 | value |= (st<<H3LIS331DL_ST); |
daveheitzman | 0:a9de25fd7c41 | 292 | |
daveheitzman | 0:a9de25fd7c41 | 293 | if( !writeReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_CTRL_REG4, value) ) |
daveheitzman | 0:a9de25fd7c41 | 294 | return MEMS_ERROR; |
daveheitzman | 0:a9de25fd7c41 | 295 | |
daveheitzman | 0:a9de25fd7c41 | 296 | return MEMS_SUCCESS; |
daveheitzman | 0:a9de25fd7c41 | 297 | } |
daveheitzman | 0:a9de25fd7c41 | 298 | |
daveheitzman | 0:a9de25fd7c41 | 299 | |
daveheitzman | 0:a9de25fd7c41 | 300 | /******************************************************************************* |
daveheitzman | 0:a9de25fd7c41 | 301 | * Function Name : setSelfTestSign |
daveheitzman | 0:a9de25fd7c41 | 302 | * Description : Set Self Test Sign (Disable = st_plus, Enable = st_minus) |
daveheitzman | 0:a9de25fd7c41 | 303 | * Input : MEMS_DISABLE/MEMS_ENABLE |
daveheitzman | 0:a9de25fd7c41 | 304 | * Output : None |
daveheitzman | 0:a9de25fd7c41 | 305 | * Return : Status [MEMS_ERROR, MEMS_SUCCESS] |
daveheitzman | 0:a9de25fd7c41 | 306 | *******************************************************************************/ |
daveheitzman | 0:a9de25fd7c41 | 307 | status_t H3LIS331DL::setSelfTestSign(State_t st_sign) { |
daveheitzman | 0:a9de25fd7c41 | 308 | uint8_t value; |
daveheitzman | 0:a9de25fd7c41 | 309 | |
daveheitzman | 0:a9de25fd7c41 | 310 | if( !readReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_CTRL_REG4, &value) ) |
daveheitzman | 0:a9de25fd7c41 | 311 | return MEMS_ERROR; |
daveheitzman | 0:a9de25fd7c41 | 312 | |
daveheitzman | 0:a9de25fd7c41 | 313 | value &= 0xF7; |
daveheitzman | 0:a9de25fd7c41 | 314 | value |= (st_sign<<H3LIS331DL_ST_SIGN); |
daveheitzman | 0:a9de25fd7c41 | 315 | |
daveheitzman | 0:a9de25fd7c41 | 316 | if( !writeReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_CTRL_REG4, value) ) |
daveheitzman | 0:a9de25fd7c41 | 317 | return MEMS_ERROR; |
daveheitzman | 0:a9de25fd7c41 | 318 | |
daveheitzman | 0:a9de25fd7c41 | 319 | return MEMS_SUCCESS; |
daveheitzman | 0:a9de25fd7c41 | 320 | } |
daveheitzman | 0:a9de25fd7c41 | 321 | |
daveheitzman | 0:a9de25fd7c41 | 322 | |
daveheitzman | 0:a9de25fd7c41 | 323 | /******************************************************************************* |
daveheitzman | 0:a9de25fd7c41 | 324 | * Function Name : setIntHighLow |
daveheitzman | 0:a9de25fd7c41 | 325 | * Description : Set Interrupt active state (Disable = active high, Enable = active low) |
daveheitzman | 0:a9de25fd7c41 | 326 | * Input : MEMS_DISABLE/MEMS_ENABLE |
daveheitzman | 0:a9de25fd7c41 | 327 | * Output : None |
daveheitzman | 0:a9de25fd7c41 | 328 | * Return : Status [MEMS_ERROR, MEMS_SUCCESS] |
daveheitzman | 0:a9de25fd7c41 | 329 | *******************************************************************************/ |
daveheitzman | 0:a9de25fd7c41 | 330 | status_t H3LIS331DL::setIntHighLow(State_t ihl) { |
daveheitzman | 0:a9de25fd7c41 | 331 | uint8_t value; |
daveheitzman | 0:a9de25fd7c41 | 332 | |
daveheitzman | 0:a9de25fd7c41 | 333 | if( !readReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_CTRL_REG3, &value) ) |
daveheitzman | 0:a9de25fd7c41 | 334 | return MEMS_ERROR; |
daveheitzman | 0:a9de25fd7c41 | 335 | |
daveheitzman | 0:a9de25fd7c41 | 336 | value &= 0x7F; |
daveheitzman | 0:a9de25fd7c41 | 337 | value |= (ihl<<H3LIS331DL_IHL); |
daveheitzman | 0:a9de25fd7c41 | 338 | |
daveheitzman | 0:a9de25fd7c41 | 339 | if( !writeReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_CTRL_REG3, value) ) |
daveheitzman | 0:a9de25fd7c41 | 340 | return MEMS_ERROR; |
daveheitzman | 0:a9de25fd7c41 | 341 | |
daveheitzman | 0:a9de25fd7c41 | 342 | return MEMS_SUCCESS; |
daveheitzman | 0:a9de25fd7c41 | 343 | } |
daveheitzman | 0:a9de25fd7c41 | 344 | |
daveheitzman | 0:a9de25fd7c41 | 345 | |
daveheitzman | 0:a9de25fd7c41 | 346 | /******************************************************************************* |
daveheitzman | 0:a9de25fd7c41 | 347 | * Function Name : setIntPPOD |
daveheitzman | 0:a9de25fd7c41 | 348 | * Description : Set Interrupt Push-Pull/OpenDrain Pad (Disable = Push-Pull, Enable = OpenDrain) |
daveheitzman | 0:a9de25fd7c41 | 349 | * Input : MEMS_DISABLE/MEMS_ENABLE |
daveheitzman | 0:a9de25fd7c41 | 350 | * Output : None |
daveheitzman | 0:a9de25fd7c41 | 351 | * Return : Status [MEMS_ERROR, MEMS_SUCCESS] |
daveheitzman | 0:a9de25fd7c41 | 352 | *******************************************************************************/ |
daveheitzman | 0:a9de25fd7c41 | 353 | status_t H3LIS331DL::setIntPPOD(State_t pp_od) { |
daveheitzman | 0:a9de25fd7c41 | 354 | uint8_t value; |
daveheitzman | 0:a9de25fd7c41 | 355 | |
daveheitzman | 0:a9de25fd7c41 | 356 | if( !readReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_CTRL_REG3, &value) ) |
daveheitzman | 0:a9de25fd7c41 | 357 | return MEMS_ERROR; |
daveheitzman | 0:a9de25fd7c41 | 358 | |
daveheitzman | 0:a9de25fd7c41 | 359 | value &= 0xBF; |
daveheitzman | 0:a9de25fd7c41 | 360 | value |= (pp_od<<H3LIS331DL_PP_OD); |
daveheitzman | 0:a9de25fd7c41 | 361 | |
daveheitzman | 0:a9de25fd7c41 | 362 | if( !writeReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_CTRL_REG3, value) ) |
daveheitzman | 0:a9de25fd7c41 | 363 | return MEMS_ERROR; |
daveheitzman | 0:a9de25fd7c41 | 364 | |
daveheitzman | 0:a9de25fd7c41 | 365 | return MEMS_SUCCESS; |
daveheitzman | 0:a9de25fd7c41 | 366 | } |
daveheitzman | 0:a9de25fd7c41 | 367 | |
daveheitzman | 0:a9de25fd7c41 | 368 | |
daveheitzman | 0:a9de25fd7c41 | 369 | /******************************************************************************* |
daveheitzman | 0:a9de25fd7c41 | 370 | * Function Name : setInt1DataSign |
daveheitzman | 0:a9de25fd7c41 | 371 | * Description : Set Data signal Interrupt 1 pad |
daveheitzman | 0:a9de25fd7c41 | 372 | * Input : Modality by H3LIS331DL_INT_Conf_t Typedef |
daveheitzman | 0:a9de25fd7c41 | 373 | (H3LIS331DL_INT_SOURCE, H3LIS331DL_INT_1OR2_SOURCE, H3LIS331DL_DATA_READY, H3LIS331DL_BOOT_RUNNING) |
daveheitzman | 0:a9de25fd7c41 | 374 | * Output : None |
daveheitzman | 0:a9de25fd7c41 | 375 | * Return : Status [MEMS_ERROR, MEMS_SUCCESS] |
daveheitzman | 0:a9de25fd7c41 | 376 | *******************************************************************************/ |
daveheitzman | 0:a9de25fd7c41 | 377 | status_t H3LIS331DL::setInt1DataSign(H3LIS331DL_INT_Conf_t i_cfg) { |
daveheitzman | 0:a9de25fd7c41 | 378 | uint8_t value; |
daveheitzman | 0:a9de25fd7c41 | 379 | |
daveheitzman | 0:a9de25fd7c41 | 380 | if( !readReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_CTRL_REG3, &value) ) |
daveheitzman | 0:a9de25fd7c41 | 381 | return MEMS_ERROR; |
daveheitzman | 0:a9de25fd7c41 | 382 | |
daveheitzman | 0:a9de25fd7c41 | 383 | value &= 0xFC; |
daveheitzman | 0:a9de25fd7c41 | 384 | value |= (i_cfg<<H3LIS331DL_I1_CFG); |
daveheitzman | 0:a9de25fd7c41 | 385 | |
daveheitzman | 0:a9de25fd7c41 | 386 | if( !writeReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_CTRL_REG3, value) ) |
daveheitzman | 0:a9de25fd7c41 | 387 | return MEMS_ERROR; |
daveheitzman | 0:a9de25fd7c41 | 388 | |
daveheitzman | 0:a9de25fd7c41 | 389 | return MEMS_SUCCESS; |
daveheitzman | 0:a9de25fd7c41 | 390 | } |
daveheitzman | 0:a9de25fd7c41 | 391 | |
daveheitzman | 0:a9de25fd7c41 | 392 | |
daveheitzman | 0:a9de25fd7c41 | 393 | /******************************************************************************* |
daveheitzman | 0:a9de25fd7c41 | 394 | * Function Name : setInt2DataSign |
daveheitzman | 0:a9de25fd7c41 | 395 | * Description : Set Data signal Interrupt 2 pad |
daveheitzman | 0:a9de25fd7c41 | 396 | * Input : Modality by H3LIS331DL_INT_Conf_t Typedef |
daveheitzman | 0:a9de25fd7c41 | 397 | (H3LIS331DL_INT_SOURCE, H3LIS331DL_INT_1OR2_SOURCE, H3LIS331DL_DATA_READY, H3LIS331DL_BOOT_RUNNING) |
daveheitzman | 0:a9de25fd7c41 | 398 | * Output : None |
daveheitzman | 0:a9de25fd7c41 | 399 | * Return : Status [MEMS_ERROR, MEMS_SUCCESS] |
daveheitzman | 0:a9de25fd7c41 | 400 | *******************************************************************************/ |
daveheitzman | 0:a9de25fd7c41 | 401 | status_t H3LIS331DL::setInt2DataSign(H3LIS331DL_INT_Conf_t i_cfg) { |
daveheitzman | 0:a9de25fd7c41 | 402 | uint8_t value; |
daveheitzman | 0:a9de25fd7c41 | 403 | |
daveheitzman | 0:a9de25fd7c41 | 404 | if( !readReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_CTRL_REG3, &value) ) |
daveheitzman | 0:a9de25fd7c41 | 405 | return MEMS_ERROR; |
daveheitzman | 0:a9de25fd7c41 | 406 | |
daveheitzman | 0:a9de25fd7c41 | 407 | value &= 0xE7; |
daveheitzman | 0:a9de25fd7c41 | 408 | value |= (i_cfg<<H3LIS331DL_I2_CFG); |
daveheitzman | 0:a9de25fd7c41 | 409 | |
daveheitzman | 0:a9de25fd7c41 | 410 | if( !writeReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_CTRL_REG3, value) ) |
daveheitzman | 0:a9de25fd7c41 | 411 | return MEMS_ERROR; |
daveheitzman | 0:a9de25fd7c41 | 412 | |
daveheitzman | 0:a9de25fd7c41 | 413 | return MEMS_SUCCESS; |
daveheitzman | 0:a9de25fd7c41 | 414 | } |
daveheitzman | 0:a9de25fd7c41 | 415 | |
daveheitzman | 0:a9de25fd7c41 | 416 | |
daveheitzman | 0:a9de25fd7c41 | 417 | /******************************************************************************* |
daveheitzman | 0:a9de25fd7c41 | 418 | * Function Name : setSPI34Wire |
daveheitzman | 0:a9de25fd7c41 | 419 | * Description : Set SPI mode |
daveheitzman | 0:a9de25fd7c41 | 420 | * Input : Modality by H3LIS331DL_SPIMode_t Typedef (H3LIS331DL_SPI_4_WIRE, H3LIS331DL_SPI_3_WIRE) |
daveheitzman | 0:a9de25fd7c41 | 421 | * Output : None |
daveheitzman | 0:a9de25fd7c41 | 422 | * Return : Status [MEMS_ERROR, MEMS_SUCCESS] |
daveheitzman | 0:a9de25fd7c41 | 423 | *******************************************************************************/ |
daveheitzman | 0:a9de25fd7c41 | 424 | status_t H3LIS331DL::setSPI34Wire(H3LIS331DL_SPIMode_t sim) { |
daveheitzman | 0:a9de25fd7c41 | 425 | uint8_t value; |
daveheitzman | 0:a9de25fd7c41 | 426 | |
daveheitzman | 0:a9de25fd7c41 | 427 | if( !readReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_CTRL_REG4, &value) ) |
daveheitzman | 0:a9de25fd7c41 | 428 | return MEMS_ERROR; |
daveheitzman | 0:a9de25fd7c41 | 429 | |
daveheitzman | 0:a9de25fd7c41 | 430 | value &= 0xFE; |
daveheitzman | 0:a9de25fd7c41 | 431 | value |= (sim<<H3LIS331DL_SIM); |
daveheitzman | 0:a9de25fd7c41 | 432 | |
daveheitzman | 0:a9de25fd7c41 | 433 | if( !writeReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_CTRL_REG4, value) ) |
daveheitzman | 0:a9de25fd7c41 | 434 | return MEMS_ERROR; |
daveheitzman | 0:a9de25fd7c41 | 435 | |
daveheitzman | 0:a9de25fd7c41 | 436 | return MEMS_SUCCESS; |
daveheitzman | 0:a9de25fd7c41 | 437 | } |
daveheitzman | 0:a9de25fd7c41 | 438 | |
daveheitzman | 0:a9de25fd7c41 | 439 | |
daveheitzman | 0:a9de25fd7c41 | 440 | /******************************************************************************* |
daveheitzman | 0:a9de25fd7c41 | 441 | * Function Name : turnONEnable |
daveheitzman | 0:a9de25fd7c41 | 442 | * Description : TurnON Mode selection for sleep to wake function |
daveheitzman | 0:a9de25fd7c41 | 443 | * Input : H3LIS331DL_SLEEP_TO_WAKE_DIS/H3LIS331DL_SLEEP_TO_WAKE_ENA |
daveheitzman | 0:a9de25fd7c41 | 444 | * Output : None |
daveheitzman | 0:a9de25fd7c41 | 445 | * Return : Status [MEMS_ERROR, MEMS_SUCCESS] |
daveheitzman | 0:a9de25fd7c41 | 446 | *******************************************************************************/ |
daveheitzman | 0:a9de25fd7c41 | 447 | status_t H3LIS331DL::turnONEnable(H3LIS331DL_Sleep_To_Wake_Conf_t stw) { |
daveheitzman | 0:a9de25fd7c41 | 448 | uint8_t value; |
daveheitzman | 0:a9de25fd7c41 | 449 | |
daveheitzman | 0:a9de25fd7c41 | 450 | if( !readReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_CTRL_REG5, &value) ) |
daveheitzman | 0:a9de25fd7c41 | 451 | return MEMS_ERROR; |
daveheitzman | 0:a9de25fd7c41 | 452 | |
daveheitzman | 0:a9de25fd7c41 | 453 | value &= 0x00; |
daveheitzman | 0:a9de25fd7c41 | 454 | value |= (stw<<H3LIS331DL_TURN_ON); |
daveheitzman | 0:a9de25fd7c41 | 455 | |
daveheitzman | 0:a9de25fd7c41 | 456 | if( !writeReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_CTRL_REG5, value) ) |
daveheitzman | 0:a9de25fd7c41 | 457 | return MEMS_ERROR; |
daveheitzman | 0:a9de25fd7c41 | 458 | |
daveheitzman | 0:a9de25fd7c41 | 459 | return MEMS_SUCCESS; |
daveheitzman | 0:a9de25fd7c41 | 460 | } |
daveheitzman | 0:a9de25fd7c41 | 461 | |
daveheitzman | 0:a9de25fd7c41 | 462 | #if 0 |
daveheitzman | 0:a9de25fd7c41 | 463 | /******************************************************************************* |
daveheitzman | 0:a9de25fd7c41 | 464 | * Function Name : HPFilterReset |
daveheitzman | 0:a9de25fd7c41 | 465 | * Description : Reading register for reset the content of internal HP filter |
daveheitzman | 0:a9de25fd7c41 | 466 | * Input : None |
daveheitzman | 0:a9de25fd7c41 | 467 | * Output : None |
daveheitzman | 0:a9de25fd7c41 | 468 | * Return : Status [MEMS_ERROR, MEMS_SUCCESS] |
daveheitzman | 0:a9de25fd7c41 | 469 | *******************************************************************************/ |
daveheitzman | 0:a9de25fd7c41 | 470 | status_t H3LIS331DL::HPFilterReset(void) { |
daveheitzman | 0:a9de25fd7c41 | 471 | uint8_t value; |
daveheitzman | 0:a9de25fd7c41 | 472 | |
daveheitzman | 0:a9de25fd7c41 | 473 | if( !readReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_HP_FILTER_RESET, &value) ) |
daveheitzman | 0:a9de25fd7c41 | 474 | return MEMS_ERROR; |
daveheitzman | 0:a9de25fd7c41 | 475 | |
daveheitzman | 0:a9de25fd7c41 | 476 | return MEMS_SUCCESS; |
daveheitzman | 0:a9de25fd7c41 | 477 | } |
daveheitzman | 0:a9de25fd7c41 | 478 | #endif |
daveheitzman | 0:a9de25fd7c41 | 479 | |
daveheitzman | 0:a9de25fd7c41 | 480 | /******************************************************************************* |
daveheitzman | 0:a9de25fd7c41 | 481 | * Function Name : setReference |
daveheitzman | 0:a9de25fd7c41 | 482 | * Description : Sets Reference register acceleration value as a reference for HP filter |
daveheitzman | 0:a9de25fd7c41 | 483 | * Input : Value of reference acceleration value (0-255) |
daveheitzman | 0:a9de25fd7c41 | 484 | * Output : None |
daveheitzman | 0:a9de25fd7c41 | 485 | * Return : Status [MEMS_ERROR, MEMS_SUCCESS] |
daveheitzman | 0:a9de25fd7c41 | 486 | *******************************************************************************/ |
daveheitzman | 0:a9de25fd7c41 | 487 | status_t H3LIS331DL::setReference(int8_t ref) { |
daveheitzman | 0:a9de25fd7c41 | 488 | |
daveheitzman | 0:a9de25fd7c41 | 489 | if( !writeReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_REFERENCE_REG, ref) ) |
daveheitzman | 0:a9de25fd7c41 | 490 | return MEMS_ERROR; |
daveheitzman | 0:a9de25fd7c41 | 491 | |
daveheitzman | 0:a9de25fd7c41 | 492 | return MEMS_SUCCESS; |
daveheitzman | 0:a9de25fd7c41 | 493 | } |
daveheitzman | 0:a9de25fd7c41 | 494 | |
daveheitzman | 0:a9de25fd7c41 | 495 | |
daveheitzman | 0:a9de25fd7c41 | 496 | /******************************************************************************* |
daveheitzman | 0:a9de25fd7c41 | 497 | * Function Name : setHPFMode |
daveheitzman | 0:a9de25fd7c41 | 498 | * Description : Set High Pass Filter Modality |
daveheitzman | 0:a9de25fd7c41 | 499 | * Input : H3LIS331DL_HPM_NORMAL_MODE_RES/H3LIS331DL_HPM_REF_SIGNAL/H3LIS331DL_HPM_NORMAL_MODE |
daveheitzman | 0:a9de25fd7c41 | 500 | * Output : None |
daveheitzman | 0:a9de25fd7c41 | 501 | * Return : Status [MEMS_ERROR, MEMS_SUCCESS] |
daveheitzman | 0:a9de25fd7c41 | 502 | *******************************************************************************/ |
daveheitzman | 0:a9de25fd7c41 | 503 | status_t H3LIS331DL::setHPFMode(H3LIS331DL_HPFMode_t hpm) { |
daveheitzman | 0:a9de25fd7c41 | 504 | uint8_t value; |
daveheitzman | 0:a9de25fd7c41 | 505 | |
daveheitzman | 0:a9de25fd7c41 | 506 | if( !readReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_CTRL_REG2, &value) ) |
daveheitzman | 0:a9de25fd7c41 | 507 | return MEMS_ERROR; |
daveheitzman | 0:a9de25fd7c41 | 508 | |
daveheitzman | 0:a9de25fd7c41 | 509 | value &= 0x9F; |
daveheitzman | 0:a9de25fd7c41 | 510 | value |= (hpm<<H3LIS331DL_HPM); |
daveheitzman | 0:a9de25fd7c41 | 511 | |
daveheitzman | 0:a9de25fd7c41 | 512 | if( !writeReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_CTRL_REG2, value) ) |
daveheitzman | 0:a9de25fd7c41 | 513 | return MEMS_ERROR; |
daveheitzman | 0:a9de25fd7c41 | 514 | |
daveheitzman | 0:a9de25fd7c41 | 515 | return MEMS_SUCCESS; |
daveheitzman | 0:a9de25fd7c41 | 516 | } |
daveheitzman | 0:a9de25fd7c41 | 517 | |
daveheitzman | 0:a9de25fd7c41 | 518 | |
daveheitzman | 0:a9de25fd7c41 | 519 | /******************************************************************************* |
daveheitzman | 0:a9de25fd7c41 | 520 | * Function Name : setHPFCutOFF |
daveheitzman | 0:a9de25fd7c41 | 521 | * Description : Set High Pass CUT OFF Freq |
daveheitzman | 0:a9de25fd7c41 | 522 | * Input : H3LIS331DL_HPFCF [0,3] |
daveheitzman | 0:a9de25fd7c41 | 523 | * Output : None |
daveheitzman | 0:a9de25fd7c41 | 524 | * Return : Status [MEMS_ERROR, MEMS_SUCCESS] |
daveheitzman | 0:a9de25fd7c41 | 525 | *******************************************************************************/ |
daveheitzman | 0:a9de25fd7c41 | 526 | status_t H3LIS331DL::setHPFCutOFF(H3LIS331DL_HPFCutOffFreq_t hpf) { |
daveheitzman | 0:a9de25fd7c41 | 527 | uint8_t value; |
daveheitzman | 0:a9de25fd7c41 | 528 | |
daveheitzman | 0:a9de25fd7c41 | 529 | if( !readReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_CTRL_REG2, &value) ) |
daveheitzman | 0:a9de25fd7c41 | 530 | return MEMS_ERROR; |
daveheitzman | 0:a9de25fd7c41 | 531 | |
daveheitzman | 0:a9de25fd7c41 | 532 | value &= 0xFC; |
daveheitzman | 0:a9de25fd7c41 | 533 | value |= (hpf<<H3LIS331DL_HPCF); |
daveheitzman | 0:a9de25fd7c41 | 534 | |
daveheitzman | 0:a9de25fd7c41 | 535 | if( !writeReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_CTRL_REG2, value) ) |
daveheitzman | 0:a9de25fd7c41 | 536 | return MEMS_ERROR; |
daveheitzman | 0:a9de25fd7c41 | 537 | |
daveheitzman | 0:a9de25fd7c41 | 538 | return MEMS_SUCCESS; |
daveheitzman | 0:a9de25fd7c41 | 539 | |
daveheitzman | 0:a9de25fd7c41 | 540 | } |
daveheitzman | 0:a9de25fd7c41 | 541 | |
daveheitzman | 0:a9de25fd7c41 | 542 | |
daveheitzman | 0:a9de25fd7c41 | 543 | /******************************************************************************* |
daveheitzman | 0:a9de25fd7c41 | 544 | * Function Name : setInt2HPEnable |
daveheitzman | 0:a9de25fd7c41 | 545 | * Description : Set Interrupt2 hp filter enable/disable |
daveheitzman | 0:a9de25fd7c41 | 546 | * Input : MEMS_ENABLE/MEMS_DISABLE |
daveheitzman | 0:a9de25fd7c41 | 547 | * example : H3LIS331DL_SetInt2HPEnable(MEMS_ENABLE) |
daveheitzman | 0:a9de25fd7c41 | 548 | * Output : None |
daveheitzman | 0:a9de25fd7c41 | 549 | * Return : Status [MEMS_ERROR, MEMS_SUCCESS] |
daveheitzman | 0:a9de25fd7c41 | 550 | *******************************************************************************/ |
daveheitzman | 0:a9de25fd7c41 | 551 | status_t H3LIS331DL::setInt2HPEnable(State_t stat) { |
daveheitzman | 0:a9de25fd7c41 | 552 | uint8_t value; |
daveheitzman | 0:a9de25fd7c41 | 553 | |
daveheitzman | 0:a9de25fd7c41 | 554 | if( !readReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_CTRL_REG2, &value) ) |
daveheitzman | 0:a9de25fd7c41 | 555 | return MEMS_ERROR; |
daveheitzman | 0:a9de25fd7c41 | 556 | |
daveheitzman | 0:a9de25fd7c41 | 557 | value &= 0xF7; |
daveheitzman | 0:a9de25fd7c41 | 558 | value |= stat<<H3LIS331DL_HPEN2 ; |
daveheitzman | 0:a9de25fd7c41 | 559 | |
daveheitzman | 0:a9de25fd7c41 | 560 | if( !writeReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_CTRL_REG2, value) ) |
daveheitzman | 0:a9de25fd7c41 | 561 | return MEMS_ERROR; |
daveheitzman | 0:a9de25fd7c41 | 562 | |
daveheitzman | 0:a9de25fd7c41 | 563 | return MEMS_SUCCESS; |
daveheitzman | 0:a9de25fd7c41 | 564 | } |
daveheitzman | 0:a9de25fd7c41 | 565 | |
daveheitzman | 0:a9de25fd7c41 | 566 | |
daveheitzman | 0:a9de25fd7c41 | 567 | /******************************************************************************* |
daveheitzman | 0:a9de25fd7c41 | 568 | * Function Name : setInt1HPEnable |
daveheitzman | 0:a9de25fd7c41 | 569 | * Description : Set Interrupt1 hp filter enable/disable |
daveheitzman | 0:a9de25fd7c41 | 570 | * Input : MEMS_ENABLE/MEMS_DISABLE |
daveheitzman | 0:a9de25fd7c41 | 571 | * example : H3LIS331DL_SetInt1HPEnable(MEMS_ENABLE) |
daveheitzman | 0:a9de25fd7c41 | 572 | * Output : None |
daveheitzman | 0:a9de25fd7c41 | 573 | * Return : Status [MEMS_ERROR, MEMS_SUCCESS] |
daveheitzman | 0:a9de25fd7c41 | 574 | *******************************************************************************/ |
daveheitzman | 0:a9de25fd7c41 | 575 | status_t H3LIS331DL::setInt1HPEnable(State_t stat) { |
daveheitzman | 0:a9de25fd7c41 | 576 | uint8_t value; |
daveheitzman | 0:a9de25fd7c41 | 577 | |
daveheitzman | 0:a9de25fd7c41 | 578 | if( !readReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_CTRL_REG2, &value) ) |
daveheitzman | 0:a9de25fd7c41 | 579 | return MEMS_ERROR; |
daveheitzman | 0:a9de25fd7c41 | 580 | |
daveheitzman | 0:a9de25fd7c41 | 581 | value &= 0xFB; |
daveheitzman | 0:a9de25fd7c41 | 582 | value |= stat<<H3LIS331DL_HPEN1 ; |
daveheitzman | 0:a9de25fd7c41 | 583 | |
daveheitzman | 0:a9de25fd7c41 | 584 | if( !writeReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_CTRL_REG2, value) ) |
daveheitzman | 0:a9de25fd7c41 | 585 | return MEMS_ERROR; |
daveheitzman | 0:a9de25fd7c41 | 586 | |
daveheitzman | 0:a9de25fd7c41 | 587 | return MEMS_SUCCESS; |
daveheitzman | 0:a9de25fd7c41 | 588 | } |
daveheitzman | 0:a9de25fd7c41 | 589 | |
daveheitzman | 0:a9de25fd7c41 | 590 | |
daveheitzman | 0:a9de25fd7c41 | 591 | /******************************************************************************* |
daveheitzman | 0:a9de25fd7c41 | 592 | * Function Name : int1LatchEnable |
daveheitzman | 0:a9de25fd7c41 | 593 | * Description : Enable Interrupt 1 Latching function |
daveheitzman | 0:a9de25fd7c41 | 594 | * Input : ENABLE/DISABLE |
daveheitzman | 0:a9de25fd7c41 | 595 | * Output : None |
daveheitzman | 0:a9de25fd7c41 | 596 | * Return : Status [MEMS_ERROR, MEMS_SUCCESS] |
daveheitzman | 0:a9de25fd7c41 | 597 | *******************************************************************************/ |
daveheitzman | 0:a9de25fd7c41 | 598 | status_t H3LIS331DL::int1LatchEnable(State_t latch) { |
daveheitzman | 0:a9de25fd7c41 | 599 | uint8_t value; |
daveheitzman | 0:a9de25fd7c41 | 600 | |
daveheitzman | 0:a9de25fd7c41 | 601 | if( !readReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_CTRL_REG3, &value) ) |
daveheitzman | 0:a9de25fd7c41 | 602 | return MEMS_ERROR; |
daveheitzman | 0:a9de25fd7c41 | 603 | |
daveheitzman | 0:a9de25fd7c41 | 604 | value &= 0xFB; |
daveheitzman | 0:a9de25fd7c41 | 605 | value |= latch<<H3LIS331DL_LIR1; |
daveheitzman | 0:a9de25fd7c41 | 606 | |
daveheitzman | 0:a9de25fd7c41 | 607 | if( !writeReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_CTRL_REG3, value) ) |
daveheitzman | 0:a9de25fd7c41 | 608 | return MEMS_ERROR; |
daveheitzman | 0:a9de25fd7c41 | 609 | |
daveheitzman | 0:a9de25fd7c41 | 610 | return MEMS_SUCCESS; |
daveheitzman | 0:a9de25fd7c41 | 611 | } |
daveheitzman | 0:a9de25fd7c41 | 612 | |
daveheitzman | 0:a9de25fd7c41 | 613 | |
daveheitzman | 0:a9de25fd7c41 | 614 | /******************************************************************************* |
daveheitzman | 0:a9de25fd7c41 | 615 | * Function Name : int2LatchEnable |
daveheitzman | 0:a9de25fd7c41 | 616 | * Description : Enable Interrupt 2 Latching function |
daveheitzman | 0:a9de25fd7c41 | 617 | * Input : ENABLE/DISABLE |
daveheitzman | 0:a9de25fd7c41 | 618 | * Output : None |
daveheitzman | 0:a9de25fd7c41 | 619 | * Return : Status [MEMS_ERROR, MEMS_SUCCESS] |
daveheitzman | 0:a9de25fd7c41 | 620 | *******************************************************************************/ |
daveheitzman | 0:a9de25fd7c41 | 621 | status_t H3LIS331DL::int2LatchEnable(State_t latch) { |
daveheitzman | 0:a9de25fd7c41 | 622 | uint8_t value; |
daveheitzman | 0:a9de25fd7c41 | 623 | |
daveheitzman | 0:a9de25fd7c41 | 624 | if( !readReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_CTRL_REG3, &value) ) |
daveheitzman | 0:a9de25fd7c41 | 625 | return MEMS_ERROR; |
daveheitzman | 0:a9de25fd7c41 | 626 | |
daveheitzman | 0:a9de25fd7c41 | 627 | value &= 0xDF; |
daveheitzman | 0:a9de25fd7c41 | 628 | value |= latch<<H3LIS331DL_LIR2; |
daveheitzman | 0:a9de25fd7c41 | 629 | |
daveheitzman | 0:a9de25fd7c41 | 630 | if( !writeReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_CTRL_REG3, value) ) |
daveheitzman | 0:a9de25fd7c41 | 631 | return MEMS_ERROR; |
daveheitzman | 0:a9de25fd7c41 | 632 | |
daveheitzman | 0:a9de25fd7c41 | 633 | return MEMS_SUCCESS; |
daveheitzman | 0:a9de25fd7c41 | 634 | } |
daveheitzman | 0:a9de25fd7c41 | 635 | |
daveheitzman | 0:a9de25fd7c41 | 636 | |
daveheitzman | 0:a9de25fd7c41 | 637 | /******************************************************************************* |
daveheitzman | 0:a9de25fd7c41 | 638 | * Function Name : resetInt1Latch |
daveheitzman | 0:a9de25fd7c41 | 639 | * Description : Reset Interrupt 1 Latching function |
daveheitzman | 0:a9de25fd7c41 | 640 | * Input : None |
daveheitzman | 0:a9de25fd7c41 | 641 | * Output : None |
daveheitzman | 0:a9de25fd7c41 | 642 | * Return : Status [MEMS_ERROR, MEMS_SUCCESS] |
daveheitzman | 0:a9de25fd7c41 | 643 | *******************************************************************************/ |
daveheitzman | 0:a9de25fd7c41 | 644 | status_t H3LIS331DL::resetInt1Latch(void) { |
daveheitzman | 0:a9de25fd7c41 | 645 | uint8_t value; |
daveheitzman | 0:a9de25fd7c41 | 646 | |
daveheitzman | 0:a9de25fd7c41 | 647 | if( !readReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_INT1_SRC, &value) ) |
daveheitzman | 0:a9de25fd7c41 | 648 | return MEMS_ERROR; |
daveheitzman | 0:a9de25fd7c41 | 649 | |
daveheitzman | 0:a9de25fd7c41 | 650 | return MEMS_SUCCESS; |
daveheitzman | 0:a9de25fd7c41 | 651 | } |
daveheitzman | 0:a9de25fd7c41 | 652 | |
daveheitzman | 0:a9de25fd7c41 | 653 | |
daveheitzman | 0:a9de25fd7c41 | 654 | /******************************************************************************* |
daveheitzman | 0:a9de25fd7c41 | 655 | * Function Name : resetInt2Latch |
daveheitzman | 0:a9de25fd7c41 | 656 | * Description : Reset Interrupt 2 Latching function |
daveheitzman | 0:a9de25fd7c41 | 657 | * Input : None |
daveheitzman | 0:a9de25fd7c41 | 658 | * Output : None |
daveheitzman | 0:a9de25fd7c41 | 659 | * Return : Status [MEMS_ERROR, MEMS_SUCCESS] |
daveheitzman | 0:a9de25fd7c41 | 660 | *******************************************************************************/ |
daveheitzman | 0:a9de25fd7c41 | 661 | status_t H3LIS331DL::resetInt2Latch(void) { |
daveheitzman | 0:a9de25fd7c41 | 662 | uint8_t value; |
daveheitzman | 0:a9de25fd7c41 | 663 | |
daveheitzman | 0:a9de25fd7c41 | 664 | if( !readReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_INT2_SRC, &value) ) |
daveheitzman | 0:a9de25fd7c41 | 665 | return MEMS_ERROR; |
daveheitzman | 0:a9de25fd7c41 | 666 | |
daveheitzman | 0:a9de25fd7c41 | 667 | return MEMS_SUCCESS; |
daveheitzman | 0:a9de25fd7c41 | 668 | } |
daveheitzman | 0:a9de25fd7c41 | 669 | |
daveheitzman | 0:a9de25fd7c41 | 670 | |
daveheitzman | 0:a9de25fd7c41 | 671 | /******************************************************************************* |
daveheitzman | 0:a9de25fd7c41 | 672 | * Function Name : setInt1Configuration |
daveheitzman | 0:a9de25fd7c41 | 673 | * Description : Interrupt 1 Configuration (without 6D_INT) |
daveheitzman | 0:a9de25fd7c41 | 674 | * Input : H3LIS331DL_INT_AND/OR | H3LIS331DL_INT_ZHIE_ENABLE/DISABLE | H3LIS331DL_INT_ZLIE_ENABLE/DISABLE... |
daveheitzman | 0:a9de25fd7c41 | 675 | * Output : None |
daveheitzman | 0:a9de25fd7c41 | 676 | * Note : You MUST use ALL input variable in the argument, as in example above |
daveheitzman | 0:a9de25fd7c41 | 677 | * Return : Status [MEMS_ERROR, MEMS_SUCCESS] |
daveheitzman | 0:a9de25fd7c41 | 678 | *******************************************************************************/ |
daveheitzman | 0:a9de25fd7c41 | 679 | status_t H3LIS331DL::setInt1Configuration(H3LIS331DL_IntConf_t ic) { |
daveheitzman | 0:a9de25fd7c41 | 680 | uint8_t value; |
daveheitzman | 0:a9de25fd7c41 | 681 | |
daveheitzman | 0:a9de25fd7c41 | 682 | if( !readReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_INT1_CFG, &value) ) |
daveheitzman | 0:a9de25fd7c41 | 683 | return MEMS_ERROR; |
daveheitzman | 0:a9de25fd7c41 | 684 | |
daveheitzman | 0:a9de25fd7c41 | 685 | value &= 0x40; |
daveheitzman | 0:a9de25fd7c41 | 686 | value |= ic; |
daveheitzman | 0:a9de25fd7c41 | 687 | |
daveheitzman | 0:a9de25fd7c41 | 688 | if( !writeReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_INT1_CFG, value) ) |
daveheitzman | 0:a9de25fd7c41 | 689 | return MEMS_ERROR; |
daveheitzman | 0:a9de25fd7c41 | 690 | |
daveheitzman | 0:a9de25fd7c41 | 691 | return MEMS_SUCCESS; |
daveheitzman | 0:a9de25fd7c41 | 692 | } |
daveheitzman | 0:a9de25fd7c41 | 693 | |
daveheitzman | 0:a9de25fd7c41 | 694 | |
daveheitzman | 0:a9de25fd7c41 | 695 | /******************************************************************************* |
daveheitzman | 0:a9de25fd7c41 | 696 | * Function Name : setInt2Configuration |
daveheitzman | 0:a9de25fd7c41 | 697 | * Description : Interrupt 2 Configuration (without 6D_INT) |
daveheitzman | 0:a9de25fd7c41 | 698 | * Input : H3LIS331DL_INT_AND/OR | H3LIS331DL_INT_ZHIE_ENABLE/DISABLE | H3LIS331DL_INT_ZLIE_ENABLE/DISABLE... |
daveheitzman | 0:a9de25fd7c41 | 699 | * Output : None |
daveheitzman | 0:a9de25fd7c41 | 700 | * Note : You MUST use all input variable in the argument, as example |
daveheitzman | 0:a9de25fd7c41 | 701 | * Return : Status [MEMS_ERROR, MEMS_SUCCESS] |
daveheitzman | 0:a9de25fd7c41 | 702 | *******************************************************************************/ |
daveheitzman | 0:a9de25fd7c41 | 703 | status_t H3LIS331DL::setInt2Configuration(H3LIS331DL_IntConf_t ic) { |
daveheitzman | 0:a9de25fd7c41 | 704 | uint8_t value; |
daveheitzman | 0:a9de25fd7c41 | 705 | |
daveheitzman | 0:a9de25fd7c41 | 706 | if( !readReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_INT2_CFG, &value) ) |
daveheitzman | 0:a9de25fd7c41 | 707 | return MEMS_ERROR; |
daveheitzman | 0:a9de25fd7c41 | 708 | |
daveheitzman | 0:a9de25fd7c41 | 709 | value &= 0x40; |
daveheitzman | 0:a9de25fd7c41 | 710 | value |= ic; |
daveheitzman | 0:a9de25fd7c41 | 711 | |
daveheitzman | 0:a9de25fd7c41 | 712 | if( !writeReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_INT2_CFG, value) ) |
daveheitzman | 0:a9de25fd7c41 | 713 | return MEMS_ERROR; |
daveheitzman | 0:a9de25fd7c41 | 714 | |
daveheitzman | 0:a9de25fd7c41 | 715 | return MEMS_SUCCESS; |
daveheitzman | 0:a9de25fd7c41 | 716 | } |
daveheitzman | 0:a9de25fd7c41 | 717 | |
daveheitzman | 0:a9de25fd7c41 | 718 | |
daveheitzman | 0:a9de25fd7c41 | 719 | /******************************************************************************* |
daveheitzman | 0:a9de25fd7c41 | 720 | * Function Name : setInt1Mode |
daveheitzman | 0:a9de25fd7c41 | 721 | * Description : Interrupt 1 Configuration mode (OR, 6D Movement, AND, 6D Position) |
daveheitzman | 0:a9de25fd7c41 | 722 | * Input : H3LIS331DL_INT_MODE_OR, H3LIS331DL_INT_MODE_6D_MOVEMENT, H3LIS331DL_INT_MODE_AND, H3LIS331DL_INT_MODE_6D_POSITION |
daveheitzman | 0:a9de25fd7c41 | 723 | * Output : None |
daveheitzman | 0:a9de25fd7c41 | 724 | * Return : Status [MEMS_ERROR, MEMS_SUCCESS] |
daveheitzman | 0:a9de25fd7c41 | 725 | *******************************************************************************/ |
daveheitzman | 0:a9de25fd7c41 | 726 | status_t H3LIS331DL::setInt1Mode(H3LIS331DL_IntMode_t int_mode) { |
daveheitzman | 0:a9de25fd7c41 | 727 | uint8_t value; |
daveheitzman | 0:a9de25fd7c41 | 728 | |
daveheitzman | 0:a9de25fd7c41 | 729 | if( !readReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_INT1_CFG, &value) ) |
daveheitzman | 0:a9de25fd7c41 | 730 | return MEMS_ERROR; |
daveheitzman | 0:a9de25fd7c41 | 731 | |
daveheitzman | 0:a9de25fd7c41 | 732 | value &= 0x3F; |
daveheitzman | 0:a9de25fd7c41 | 733 | value |= (int_mode<<H3LIS331DL_INT_6D); |
daveheitzman | 0:a9de25fd7c41 | 734 | |
daveheitzman | 0:a9de25fd7c41 | 735 | if( !writeReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_INT1_CFG, value) ) |
daveheitzman | 0:a9de25fd7c41 | 736 | return MEMS_ERROR; |
daveheitzman | 0:a9de25fd7c41 | 737 | |
daveheitzman | 0:a9de25fd7c41 | 738 | return MEMS_SUCCESS; |
daveheitzman | 0:a9de25fd7c41 | 739 | } |
daveheitzman | 0:a9de25fd7c41 | 740 | |
daveheitzman | 0:a9de25fd7c41 | 741 | |
daveheitzman | 0:a9de25fd7c41 | 742 | /******************************************************************************* |
daveheitzman | 0:a9de25fd7c41 | 743 | * Function Name : setInt2Mode |
daveheitzman | 0:a9de25fd7c41 | 744 | * Description : Interrupt 2 Configuration mode (OR, 6D Movement, AND, 6D Position) |
daveheitzman | 0:a9de25fd7c41 | 745 | * Input : H3LIS331DL_INT_MODE_OR, H3LIS331DL_INT_MODE_6D_MOVEMENT, H3LIS331DL_INT_MODE_AND, H3LIS331DL_INT_MODE_6D_POSITION |
daveheitzman | 0:a9de25fd7c41 | 746 | * Output : None |
daveheitzman | 0:a9de25fd7c41 | 747 | * Return : Status [MEMS_ERROR, MEMS_SUCCESS] |
daveheitzman | 0:a9de25fd7c41 | 748 | *******************************************************************************/ |
daveheitzman | 0:a9de25fd7c41 | 749 | status_t H3LIS331DL::setInt2Mode(H3LIS331DL_IntMode_t int_mode) { |
daveheitzman | 0:a9de25fd7c41 | 750 | uint8_t value; |
daveheitzman | 0:a9de25fd7c41 | 751 | |
daveheitzman | 0:a9de25fd7c41 | 752 | if( !readReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_INT2_CFG, &value) ) |
daveheitzman | 0:a9de25fd7c41 | 753 | return MEMS_ERROR; |
daveheitzman | 0:a9de25fd7c41 | 754 | |
daveheitzman | 0:a9de25fd7c41 | 755 | value &= 0x3F; |
daveheitzman | 0:a9de25fd7c41 | 756 | value |= (int_mode<<H3LIS331DL_INT_6D); |
daveheitzman | 0:a9de25fd7c41 | 757 | |
daveheitzman | 0:a9de25fd7c41 | 758 | if( !writeReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_INT2_CFG, value) ) |
daveheitzman | 0:a9de25fd7c41 | 759 | return MEMS_ERROR; |
daveheitzman | 0:a9de25fd7c41 | 760 | |
daveheitzman | 0:a9de25fd7c41 | 761 | return MEMS_SUCCESS; |
daveheitzman | 0:a9de25fd7c41 | 762 | } |
daveheitzman | 0:a9de25fd7c41 | 763 | |
daveheitzman | 0:a9de25fd7c41 | 764 | |
daveheitzman | 0:a9de25fd7c41 | 765 | /******************************************************************************* |
daveheitzman | 0:a9de25fd7c41 | 766 | * Function Name : get6DPositionInt1 |
daveheitzman | 0:a9de25fd7c41 | 767 | * Description : 6D Interrupt 1 Position Detect |
daveheitzman | 0:a9de25fd7c41 | 768 | * Input : uint8_t to be filled with H3LIS331DL_POSITION_6D_t Typedef |
daveheitzman | 0:a9de25fd7c41 | 769 | * Output : None |
daveheitzman | 0:a9de25fd7c41 | 770 | * Return : Status [MEMS_ERROR, MEMS_SUCCESS] |
daveheitzman | 0:a9de25fd7c41 | 771 | *******************************************************************************/ |
daveheitzman | 0:a9de25fd7c41 | 772 | status_t H3LIS331DL::get6DPositionInt1(uint8_t* val){ |
daveheitzman | 0:a9de25fd7c41 | 773 | uint8_t value; |
daveheitzman | 0:a9de25fd7c41 | 774 | |
daveheitzman | 0:a9de25fd7c41 | 775 | if( !readReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_INT1_SRC, &value) ) |
daveheitzman | 0:a9de25fd7c41 | 776 | return MEMS_ERROR; |
daveheitzman | 0:a9de25fd7c41 | 777 | |
daveheitzman | 0:a9de25fd7c41 | 778 | value &= 0x7F; |
daveheitzman | 0:a9de25fd7c41 | 779 | |
daveheitzman | 0:a9de25fd7c41 | 780 | switch (value){ |
daveheitzman | 0:a9de25fd7c41 | 781 | case H3LIS331DL_UP_SX: |
daveheitzman | 0:a9de25fd7c41 | 782 | *val = H3LIS331DL_UP_SX; |
daveheitzman | 0:a9de25fd7c41 | 783 | break; |
daveheitzman | 0:a9de25fd7c41 | 784 | case H3LIS331DL_UP_DX: |
daveheitzman | 0:a9de25fd7c41 | 785 | *val = H3LIS331DL_UP_DX; |
daveheitzman | 0:a9de25fd7c41 | 786 | break; |
daveheitzman | 0:a9de25fd7c41 | 787 | case H3LIS331DL_DW_SX: |
daveheitzman | 0:a9de25fd7c41 | 788 | *val = H3LIS331DL_DW_SX; |
daveheitzman | 0:a9de25fd7c41 | 789 | break; |
daveheitzman | 0:a9de25fd7c41 | 790 | case H3LIS331DL_DW_DX: |
daveheitzman | 0:a9de25fd7c41 | 791 | *val = H3LIS331DL_DW_DX; |
daveheitzman | 0:a9de25fd7c41 | 792 | break; |
daveheitzman | 0:a9de25fd7c41 | 793 | case H3LIS331DL_TOP: |
daveheitzman | 0:a9de25fd7c41 | 794 | *val = H3LIS331DL_TOP; |
daveheitzman | 0:a9de25fd7c41 | 795 | break; |
daveheitzman | 0:a9de25fd7c41 | 796 | case H3LIS331DL_BOTTOM: |
daveheitzman | 0:a9de25fd7c41 | 797 | *val = H3LIS331DL_BOTTOM; |
daveheitzman | 0:a9de25fd7c41 | 798 | break; |
daveheitzman | 0:a9de25fd7c41 | 799 | } |
daveheitzman | 0:a9de25fd7c41 | 800 | |
daveheitzman | 0:a9de25fd7c41 | 801 | return MEMS_SUCCESS; |
daveheitzman | 0:a9de25fd7c41 | 802 | } |
daveheitzman | 0:a9de25fd7c41 | 803 | |
daveheitzman | 0:a9de25fd7c41 | 804 | |
daveheitzman | 0:a9de25fd7c41 | 805 | /******************************************************************************* |
daveheitzman | 0:a9de25fd7c41 | 806 | * Function Name : get6DPositionInt2 |
daveheitzman | 0:a9de25fd7c41 | 807 | * Description : 6D Interrupt 2 Position Detect |
daveheitzman | 0:a9de25fd7c41 | 808 | * Input : Byte to be filled with H3LIS331DL_POSITION_6D_t Typedef |
daveheitzman | 0:a9de25fd7c41 | 809 | * Output : None |
daveheitzman | 0:a9de25fd7c41 | 810 | * Return : Status [MEMS_ERROR, MEMS_SUCCESS] |
daveheitzman | 0:a9de25fd7c41 | 811 | *******************************************************************************/ |
daveheitzman | 0:a9de25fd7c41 | 812 | status_t H3LIS331DL::get6DPositionInt2(uint8_t* val){ |
daveheitzman | 0:a9de25fd7c41 | 813 | uint8_t value; |
daveheitzman | 0:a9de25fd7c41 | 814 | |
daveheitzman | 0:a9de25fd7c41 | 815 | if( !readReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_INT2_SRC, &value) ) |
daveheitzman | 0:a9de25fd7c41 | 816 | return MEMS_ERROR; |
daveheitzman | 0:a9de25fd7c41 | 817 | |
daveheitzman | 0:a9de25fd7c41 | 818 | value &= 0x7F; |
daveheitzman | 0:a9de25fd7c41 | 819 | |
daveheitzman | 0:a9de25fd7c41 | 820 | switch (value){ |
daveheitzman | 0:a9de25fd7c41 | 821 | case H3LIS331DL_UP_SX: |
daveheitzman | 0:a9de25fd7c41 | 822 | *val = H3LIS331DL_UP_SX; |
daveheitzman | 0:a9de25fd7c41 | 823 | break; |
daveheitzman | 0:a9de25fd7c41 | 824 | case H3LIS331DL_UP_DX: |
daveheitzman | 0:a9de25fd7c41 | 825 | *val = H3LIS331DL_UP_DX; |
daveheitzman | 0:a9de25fd7c41 | 826 | break; |
daveheitzman | 0:a9de25fd7c41 | 827 | case H3LIS331DL_DW_SX: |
daveheitzman | 0:a9de25fd7c41 | 828 | *val = H3LIS331DL_DW_SX; |
daveheitzman | 0:a9de25fd7c41 | 829 | break; |
daveheitzman | 0:a9de25fd7c41 | 830 | case H3LIS331DL_DW_DX: |
daveheitzman | 0:a9de25fd7c41 | 831 | *val = H3LIS331DL_DW_DX; |
daveheitzman | 0:a9de25fd7c41 | 832 | break; |
daveheitzman | 0:a9de25fd7c41 | 833 | case H3LIS331DL_TOP: |
daveheitzman | 0:a9de25fd7c41 | 834 | *val = H3LIS331DL_TOP; |
daveheitzman | 0:a9de25fd7c41 | 835 | break; |
daveheitzman | 0:a9de25fd7c41 | 836 | case H3LIS331DL_BOTTOM: |
daveheitzman | 0:a9de25fd7c41 | 837 | *val = H3LIS331DL_BOTTOM; |
daveheitzman | 0:a9de25fd7c41 | 838 | break; |
daveheitzman | 0:a9de25fd7c41 | 839 | } |
daveheitzman | 0:a9de25fd7c41 | 840 | |
daveheitzman | 0:a9de25fd7c41 | 841 | return MEMS_SUCCESS; |
daveheitzman | 0:a9de25fd7c41 | 842 | } |
daveheitzman | 0:a9de25fd7c41 | 843 | |
daveheitzman | 0:a9de25fd7c41 | 844 | |
daveheitzman | 0:a9de25fd7c41 | 845 | /******************************************************************************* |
daveheitzman | 0:a9de25fd7c41 | 846 | * Function Name : setInt1Threshold |
daveheitzman | 0:a9de25fd7c41 | 847 | * Description : Sets Interrupt 1 Threshold |
daveheitzman | 0:a9de25fd7c41 | 848 | * Input : Threshold = [0,127] |
daveheitzman | 0:a9de25fd7c41 | 849 | * Output : None |
daveheitzman | 0:a9de25fd7c41 | 850 | * Return : Status [MEMS_ERROR, MEMS_SUCCESS] |
daveheitzman | 0:a9de25fd7c41 | 851 | *******************************************************************************/ |
daveheitzman | 0:a9de25fd7c41 | 852 | status_t H3LIS331DL::setInt1Threshold(uint8_t ths) { |
daveheitzman | 0:a9de25fd7c41 | 853 | if (ths > 127) |
daveheitzman | 0:a9de25fd7c41 | 854 | return MEMS_ERROR; |
daveheitzman | 0:a9de25fd7c41 | 855 | |
daveheitzman | 0:a9de25fd7c41 | 856 | if( !writeReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_INT1_THS, ths) ) |
daveheitzman | 0:a9de25fd7c41 | 857 | return MEMS_ERROR; |
daveheitzman | 0:a9de25fd7c41 | 858 | |
daveheitzman | 0:a9de25fd7c41 | 859 | return MEMS_SUCCESS; |
daveheitzman | 0:a9de25fd7c41 | 860 | } |
daveheitzman | 0:a9de25fd7c41 | 861 | |
daveheitzman | 0:a9de25fd7c41 | 862 | |
daveheitzman | 0:a9de25fd7c41 | 863 | /******************************************************************************* |
daveheitzman | 0:a9de25fd7c41 | 864 | * Function Name : setInt1Duration |
daveheitzman | 0:a9de25fd7c41 | 865 | * Description : Sets Interrupt 1 Duration |
daveheitzman | 0:a9de25fd7c41 | 866 | * Input : Duration = [0,127] |
daveheitzman | 0:a9de25fd7c41 | 867 | * Output : None |
daveheitzman | 0:a9de25fd7c41 | 868 | * Return : Status [MEMS_ERROR, MEMS_SUCCESS] |
daveheitzman | 0:a9de25fd7c41 | 869 | *******************************************************************************/ |
daveheitzman | 0:a9de25fd7c41 | 870 | status_t H3LIS331DL::setInt1Duration(uint8_t id) { |
daveheitzman | 0:a9de25fd7c41 | 871 | if (id > 127) |
daveheitzman | 0:a9de25fd7c41 | 872 | return MEMS_ERROR; |
daveheitzman | 0:a9de25fd7c41 | 873 | |
daveheitzman | 0:a9de25fd7c41 | 874 | if( !writeReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_INT1_DURATION, id) ) |
daveheitzman | 0:a9de25fd7c41 | 875 | return MEMS_ERROR; |
daveheitzman | 0:a9de25fd7c41 | 876 | |
daveheitzman | 0:a9de25fd7c41 | 877 | return MEMS_SUCCESS; |
daveheitzman | 0:a9de25fd7c41 | 878 | } |
daveheitzman | 0:a9de25fd7c41 | 879 | |
daveheitzman | 0:a9de25fd7c41 | 880 | |
daveheitzman | 0:a9de25fd7c41 | 881 | /******************************************************************************* |
daveheitzman | 0:a9de25fd7c41 | 882 | * Function Name : setInt2Threshold |
daveheitzman | 0:a9de25fd7c41 | 883 | * Description : Sets Interrupt 2 Threshold |
daveheitzman | 0:a9de25fd7c41 | 884 | * Input : Threshold = [0,127] |
daveheitzman | 0:a9de25fd7c41 | 885 | * Output : None |
daveheitzman | 0:a9de25fd7c41 | 886 | * Return : Status [MEMS_ERROR, MEMS_SUCCESS] |
daveheitzman | 0:a9de25fd7c41 | 887 | *******************************************************************************/ |
daveheitzman | 0:a9de25fd7c41 | 888 | status_t H3LIS331DL::setInt2Threshold(uint8_t ths) { |
daveheitzman | 0:a9de25fd7c41 | 889 | if (ths > 127) |
daveheitzman | 0:a9de25fd7c41 | 890 | return MEMS_ERROR; |
daveheitzman | 0:a9de25fd7c41 | 891 | |
daveheitzman | 0:a9de25fd7c41 | 892 | if( !writeReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_INT2_THS, ths) ) |
daveheitzman | 0:a9de25fd7c41 | 893 | return MEMS_ERROR; |
daveheitzman | 0:a9de25fd7c41 | 894 | |
daveheitzman | 0:a9de25fd7c41 | 895 | return MEMS_SUCCESS; |
daveheitzman | 0:a9de25fd7c41 | 896 | } |
daveheitzman | 0:a9de25fd7c41 | 897 | |
daveheitzman | 0:a9de25fd7c41 | 898 | |
daveheitzman | 0:a9de25fd7c41 | 899 | /******************************************************************************* |
daveheitzman | 0:a9de25fd7c41 | 900 | * Function Name : setInt2Duration |
daveheitzman | 0:a9de25fd7c41 | 901 | * Description : Sets Interrupt 2 Duration |
daveheitzman | 0:a9de25fd7c41 | 902 | * Input : Duration = [0,127] |
daveheitzman | 0:a9de25fd7c41 | 903 | * Output : None |
daveheitzman | 0:a9de25fd7c41 | 904 | * Return : Status [MEMS_ERROR, MEMS_SUCCESS] |
daveheitzman | 0:a9de25fd7c41 | 905 | *******************************************************************************/ |
daveheitzman | 0:a9de25fd7c41 | 906 | status_t H3LIS331DL::setInt2Duration(uint8_t id) { |
daveheitzman | 0:a9de25fd7c41 | 907 | if (id > 127) |
daveheitzman | 0:a9de25fd7c41 | 908 | return MEMS_ERROR; |
daveheitzman | 0:a9de25fd7c41 | 909 | |
daveheitzman | 0:a9de25fd7c41 | 910 | if( !writeReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_INT2_DURATION, id) ) |
daveheitzman | 0:a9de25fd7c41 | 911 | return MEMS_ERROR; |
daveheitzman | 0:a9de25fd7c41 | 912 | |
daveheitzman | 0:a9de25fd7c41 | 913 | return MEMS_SUCCESS; |
daveheitzman | 0:a9de25fd7c41 | 914 | } |
daveheitzman | 0:a9de25fd7c41 | 915 | |
daveheitzman | 0:a9de25fd7c41 | 916 | |
daveheitzman | 0:a9de25fd7c41 | 917 | /******************************************************************************* |
daveheitzman | 0:a9de25fd7c41 | 918 | * Function Name : getStatusReg |
daveheitzman | 0:a9de25fd7c41 | 919 | * Description : Read the status register |
daveheitzman | 0:a9de25fd7c41 | 920 | * Input : char to empty by Status Reg Value |
daveheitzman | 0:a9de25fd7c41 | 921 | * Output : None |
daveheitzman | 0:a9de25fd7c41 | 922 | * Return : Status [MEMS_ERROR, MEMS_SUCCESS] |
daveheitzman | 0:a9de25fd7c41 | 923 | *******************************************************************************/ |
daveheitzman | 0:a9de25fd7c41 | 924 | status_t H3LIS331DL::getStatusReg(uint8_t* val) { |
daveheitzman | 0:a9de25fd7c41 | 925 | |
daveheitzman | 0:a9de25fd7c41 | 926 | if( !readReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_STATUS_REG, val) ) |
daveheitzman | 0:a9de25fd7c41 | 927 | return MEMS_ERROR; |
daveheitzman | 0:a9de25fd7c41 | 928 | |
daveheitzman | 0:a9de25fd7c41 | 929 | return MEMS_SUCCESS; |
daveheitzman | 0:a9de25fd7c41 | 930 | } |
daveheitzman | 0:a9de25fd7c41 | 931 | |
daveheitzman | 0:a9de25fd7c41 | 932 | /******************************************************************************* |
daveheitzman | 0:a9de25fd7c41 | 933 | * Function Name : getStatusBIT |
daveheitzman | 0:a9de25fd7c41 | 934 | * Description : Read the status register BIT |
daveheitzman | 0:a9de25fd7c41 | 935 | * Input : H3LIS331DL_STATUS_REG_ZYXOR, H3LIS331DL_STATUS_REG_ZOR, H3LIS331DL_STATUS_REG_YOR, H3LIS331DL_STATUS_REG_XOR, |
daveheitzman | 0:a9de25fd7c41 | 936 | H3LIS331DL_STATUS_REG_ZYXDA, H3LIS331DL_STATUS_REG_ZDA, H3LIS331DL_STATUS_REG_YDA, H3LIS331DL_STATUS_REG_XDA, |
daveheitzman | 0:a9de25fd7c41 | 937 | H3LIS331DL_DATAREADY_BIT |
daveheitzman | 0:a9de25fd7c41 | 938 | * Output : status register BIT |
daveheitzman | 0:a9de25fd7c41 | 939 | * Return : Status [MEMS_ERROR, MEMS_SUCCESS] |
daveheitzman | 0:a9de25fd7c41 | 940 | *******************************************************************************/ |
daveheitzman | 0:a9de25fd7c41 | 941 | status_t H3LIS331DL::getStatusBit(uint8_t statusBIT, uint8_t *val) { |
daveheitzman | 0:a9de25fd7c41 | 942 | uint8_t value; |
daveheitzman | 0:a9de25fd7c41 | 943 | |
daveheitzman | 0:a9de25fd7c41 | 944 | if( !readReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_STATUS_REG, &value) ) |
daveheitzman | 0:a9de25fd7c41 | 945 | return MEMS_ERROR; |
daveheitzman | 0:a9de25fd7c41 | 946 | |
daveheitzman | 0:a9de25fd7c41 | 947 | switch (statusBIT){ |
daveheitzman | 0:a9de25fd7c41 | 948 | case H3LIS331DL_STATUS_REG_ZYXOR: |
daveheitzman | 0:a9de25fd7c41 | 949 | if(value &= H3LIS331DL_STATUS_REG_ZYXOR){ |
daveheitzman | 0:a9de25fd7c41 | 950 | *val = MEMS_SET; |
daveheitzman | 0:a9de25fd7c41 | 951 | return MEMS_SUCCESS; |
daveheitzman | 0:a9de25fd7c41 | 952 | } |
daveheitzman | 0:a9de25fd7c41 | 953 | else{ |
daveheitzman | 0:a9de25fd7c41 | 954 | *val = MEMS_RESET; |
daveheitzman | 0:a9de25fd7c41 | 955 | return MEMS_SUCCESS; |
daveheitzman | 0:a9de25fd7c41 | 956 | } |
daveheitzman | 0:a9de25fd7c41 | 957 | case H3LIS331DL_STATUS_REG_ZOR: |
daveheitzman | 0:a9de25fd7c41 | 958 | if(value &= H3LIS331DL_STATUS_REG_ZOR){ |
daveheitzman | 0:a9de25fd7c41 | 959 | *val = MEMS_SET; |
daveheitzman | 0:a9de25fd7c41 | 960 | return MEMS_SUCCESS; |
daveheitzman | 0:a9de25fd7c41 | 961 | } |
daveheitzman | 0:a9de25fd7c41 | 962 | else{ |
daveheitzman | 0:a9de25fd7c41 | 963 | *val = MEMS_RESET; |
daveheitzman | 0:a9de25fd7c41 | 964 | return MEMS_SUCCESS; |
daveheitzman | 0:a9de25fd7c41 | 965 | } |
daveheitzman | 0:a9de25fd7c41 | 966 | case H3LIS331DL_STATUS_REG_YOR: |
daveheitzman | 0:a9de25fd7c41 | 967 | if(value &= H3LIS331DL_STATUS_REG_YOR){ |
daveheitzman | 0:a9de25fd7c41 | 968 | *val = MEMS_SET; |
daveheitzman | 0:a9de25fd7c41 | 969 | return MEMS_SUCCESS; |
daveheitzman | 0:a9de25fd7c41 | 970 | } |
daveheitzman | 0:a9de25fd7c41 | 971 | else{ |
daveheitzman | 0:a9de25fd7c41 | 972 | *val = MEMS_RESET; |
daveheitzman | 0:a9de25fd7c41 | 973 | return MEMS_SUCCESS; |
daveheitzman | 0:a9de25fd7c41 | 974 | } |
daveheitzman | 0:a9de25fd7c41 | 975 | case H3LIS331DL_STATUS_REG_XOR: |
daveheitzman | 0:a9de25fd7c41 | 976 | if(value &= H3LIS331DL_STATUS_REG_XOR){ |
daveheitzman | 0:a9de25fd7c41 | 977 | *val = MEMS_SET; |
daveheitzman | 0:a9de25fd7c41 | 978 | return MEMS_SUCCESS; |
daveheitzman | 0:a9de25fd7c41 | 979 | } |
daveheitzman | 0:a9de25fd7c41 | 980 | else{ |
daveheitzman | 0:a9de25fd7c41 | 981 | *val = MEMS_RESET; |
daveheitzman | 0:a9de25fd7c41 | 982 | return MEMS_SUCCESS; |
daveheitzman | 0:a9de25fd7c41 | 983 | } |
daveheitzman | 0:a9de25fd7c41 | 984 | case H3LIS331DL_STATUS_REG_ZYXDA: |
daveheitzman | 0:a9de25fd7c41 | 985 | if(value &= H3LIS331DL_STATUS_REG_ZYXDA){ |
daveheitzman | 0:a9de25fd7c41 | 986 | *val = MEMS_SET; |
daveheitzman | 0:a9de25fd7c41 | 987 | return MEMS_SUCCESS; |
daveheitzman | 0:a9de25fd7c41 | 988 | } |
daveheitzman | 0:a9de25fd7c41 | 989 | else{ |
daveheitzman | 0:a9de25fd7c41 | 990 | *val = MEMS_RESET; |
daveheitzman | 0:a9de25fd7c41 | 991 | return MEMS_SUCCESS; |
daveheitzman | 0:a9de25fd7c41 | 992 | } |
daveheitzman | 0:a9de25fd7c41 | 993 | case H3LIS331DL_STATUS_REG_ZDA: |
daveheitzman | 0:a9de25fd7c41 | 994 | if(value &= H3LIS331DL_STATUS_REG_ZDA){ |
daveheitzman | 0:a9de25fd7c41 | 995 | *val = MEMS_SET; |
daveheitzman | 0:a9de25fd7c41 | 996 | return MEMS_SUCCESS; |
daveheitzman | 0:a9de25fd7c41 | 997 | } |
daveheitzman | 0:a9de25fd7c41 | 998 | else{ |
daveheitzman | 0:a9de25fd7c41 | 999 | *val = MEMS_RESET; |
daveheitzman | 0:a9de25fd7c41 | 1000 | return MEMS_SUCCESS; |
daveheitzman | 0:a9de25fd7c41 | 1001 | } |
daveheitzman | 0:a9de25fd7c41 | 1002 | case H3LIS331DL_STATUS_REG_YDA: |
daveheitzman | 0:a9de25fd7c41 | 1003 | if(value &= H3LIS331DL_STATUS_REG_YDA){ |
daveheitzman | 0:a9de25fd7c41 | 1004 | *val = MEMS_SET; |
daveheitzman | 0:a9de25fd7c41 | 1005 | return MEMS_SUCCESS; |
daveheitzman | 0:a9de25fd7c41 | 1006 | } |
daveheitzman | 0:a9de25fd7c41 | 1007 | else{ |
daveheitzman | 0:a9de25fd7c41 | 1008 | *val = MEMS_RESET; |
daveheitzman | 0:a9de25fd7c41 | 1009 | return MEMS_SUCCESS; |
daveheitzman | 0:a9de25fd7c41 | 1010 | } |
daveheitzman | 0:a9de25fd7c41 | 1011 | case H3LIS331DL_STATUS_REG_XDA: |
daveheitzman | 0:a9de25fd7c41 | 1012 | if(value &= H3LIS331DL_STATUS_REG_XDA){ |
daveheitzman | 0:a9de25fd7c41 | 1013 | *val = MEMS_SET; |
daveheitzman | 0:a9de25fd7c41 | 1014 | return MEMS_SUCCESS; |
daveheitzman | 0:a9de25fd7c41 | 1015 | } |
daveheitzman | 0:a9de25fd7c41 | 1016 | else{ |
daveheitzman | 0:a9de25fd7c41 | 1017 | *val = MEMS_RESET; |
daveheitzman | 0:a9de25fd7c41 | 1018 | return MEMS_SUCCESS; |
daveheitzman | 0:a9de25fd7c41 | 1019 | } |
daveheitzman | 0:a9de25fd7c41 | 1020 | } |
daveheitzman | 0:a9de25fd7c41 | 1021 | |
daveheitzman | 0:a9de25fd7c41 | 1022 | return MEMS_ERROR; |
daveheitzman | 0:a9de25fd7c41 | 1023 | } |
daveheitzman | 0:a9de25fd7c41 | 1024 | |
daveheitzman | 0:a9de25fd7c41 | 1025 | |
daveheitzman | 0:a9de25fd7c41 | 1026 | /******************************************************************************* |
daveheitzman | 0:a9de25fd7c41 | 1027 | * Function Name : getAccAxesRaw |
daveheitzman | 0:a9de25fd7c41 | 1028 | * Description : Read the Acceleration Values Output Registers |
daveheitzman | 0:a9de25fd7c41 | 1029 | * Input : buffer to empty by AccAxesRaw_t Typedef |
daveheitzman | 0:a9de25fd7c41 | 1030 | * Output : None |
daveheitzman | 0:a9de25fd7c41 | 1031 | * Return : Status [MEMS_ERROR, MEMS_SUCCESS] |
daveheitzman | 0:a9de25fd7c41 | 1032 | *******************************************************************************/ |
daveheitzman | 0:a9de25fd7c41 | 1033 | status_t H3LIS331DL::getAccAxesRaw(AxesRaw_t* buff) { |
daveheitzman | 0:a9de25fd7c41 | 1034 | uint8_t valueL = 0,valueH = 0; |
daveheitzman | 0:a9de25fd7c41 | 1035 | readReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_OUT_X_L, &valueL); |
daveheitzman | 0:a9de25fd7c41 | 1036 | readReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_OUT_X_H, &valueH); |
daveheitzman | 0:a9de25fd7c41 | 1037 | buff->AXIS_X = (valueH<<8)|valueL; |
daveheitzman | 0:a9de25fd7c41 | 1038 | readReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_OUT_Y_L, &valueL); |
daveheitzman | 0:a9de25fd7c41 | 1039 | readReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_OUT_Y_H, &valueH); |
daveheitzman | 0:a9de25fd7c41 | 1040 | buff->AXIS_Y = (valueH<<8)|valueL; |
daveheitzman | 0:a9de25fd7c41 | 1041 | readReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_OUT_Z_L, &valueL); |
daveheitzman | 0:a9de25fd7c41 | 1042 | readReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_OUT_Z_H, &valueH); |
daveheitzman | 0:a9de25fd7c41 | 1043 | buff->AXIS_Z = (valueH<<8)|valueL; |
daveheitzman | 0:a9de25fd7c41 | 1044 | return MEMS_SUCCESS; |
daveheitzman | 0:a9de25fd7c41 | 1045 | } |
daveheitzman | 0:a9de25fd7c41 | 1046 | |
daveheitzman | 0:a9de25fd7c41 | 1047 | |
daveheitzman | 0:a9de25fd7c41 | 1048 | /******************************************************************************* |
daveheitzman | 0:a9de25fd7c41 | 1049 | * Function Name : getInt1Src |
daveheitzman | 0:a9de25fd7c41 | 1050 | * Description : Reset Interrupt 1 Latching function |
daveheitzman | 0:a9de25fd7c41 | 1051 | * Input : buffer to empty by Int1 Source Value |
daveheitzman | 0:a9de25fd7c41 | 1052 | * Output : None |
daveheitzman | 0:a9de25fd7c41 | 1053 | * Return : Status [MEMS_ERROR, MEMS_SUCCESS] |
daveheitzman | 0:a9de25fd7c41 | 1054 | *******************************************************************************/ |
daveheitzman | 0:a9de25fd7c41 | 1055 | status_t H3LIS331DL::getInt1Src(uint8_t* val) { |
daveheitzman | 0:a9de25fd7c41 | 1056 | if( !readReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_INT1_SRC, val) ) |
daveheitzman | 0:a9de25fd7c41 | 1057 | return MEMS_ERROR; |
daveheitzman | 0:a9de25fd7c41 | 1058 | |
daveheitzman | 0:a9de25fd7c41 | 1059 | return MEMS_SUCCESS; |
daveheitzman | 0:a9de25fd7c41 | 1060 | } |
daveheitzman | 0:a9de25fd7c41 | 1061 | |
daveheitzman | 0:a9de25fd7c41 | 1062 | |
daveheitzman | 0:a9de25fd7c41 | 1063 | /******************************************************************************* |
daveheitzman | 0:a9de25fd7c41 | 1064 | * Function Name : getInt2Src |
daveheitzman | 0:a9de25fd7c41 | 1065 | * Description : Reset Interrupt 2 Latching function |
daveheitzman | 0:a9de25fd7c41 | 1066 | * Input : buffer to empty by Int2 Source Value |
daveheitzman | 0:a9de25fd7c41 | 1067 | * Output : None |
daveheitzman | 0:a9de25fd7c41 | 1068 | * Return : Status [MEMS_ERROR, MEMS_SUCCESS] |
daveheitzman | 0:a9de25fd7c41 | 1069 | *******************************************************************************/ |
daveheitzman | 0:a9de25fd7c41 | 1070 | status_t H3LIS331DL::getInt2Src(uint8_t* val) { |
daveheitzman | 0:a9de25fd7c41 | 1071 | if( !readReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_INT2_SRC, val) ) |
daveheitzman | 0:a9de25fd7c41 | 1072 | return MEMS_ERROR; |
daveheitzman | 0:a9de25fd7c41 | 1073 | |
daveheitzman | 0:a9de25fd7c41 | 1074 | return MEMS_SUCCESS; |
daveheitzman | 0:a9de25fd7c41 | 1075 | } |
daveheitzman | 0:a9de25fd7c41 | 1076 | |
daveheitzman | 0:a9de25fd7c41 | 1077 | |
daveheitzman | 0:a9de25fd7c41 | 1078 | /******************************************************************************* |
daveheitzman | 0:a9de25fd7c41 | 1079 | * Function Name : getInt1SrcBit |
daveheitzman | 0:a9de25fd7c41 | 1080 | * Description : Reset Interrupt 1 Latching function |
daveheitzman | 0:a9de25fd7c41 | 1081 | * Input : H3LIS331DL_INT1_SRC_IA, H3LIS331DL_INT1_SRC_ZH, H3LIS331DL_INT1_SRC_ZL ..... |
daveheitzman | 0:a9de25fd7c41 | 1082 | * Output : None |
daveheitzman | 0:a9de25fd7c41 | 1083 | * Return : Status of BIT [MEMS_ERROR, MEMS_SUCCESS] |
daveheitzman | 0:a9de25fd7c41 | 1084 | *******************************************************************************/ |
daveheitzman | 0:a9de25fd7c41 | 1085 | status_t H3LIS331DL::getInt1SrcBit(uint8_t statusBIT, uint8_t *val) { |
daveheitzman | 0:a9de25fd7c41 | 1086 | uint8_t value; |
daveheitzman | 0:a9de25fd7c41 | 1087 | |
daveheitzman | 0:a9de25fd7c41 | 1088 | if( !readReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_INT1_SRC, &value) ) |
daveheitzman | 0:a9de25fd7c41 | 1089 | return MEMS_ERROR; |
daveheitzman | 0:a9de25fd7c41 | 1090 | |
daveheitzman | 0:a9de25fd7c41 | 1091 | if(statusBIT == H3LIS331DL_INT_SRC_IA){ |
daveheitzman | 0:a9de25fd7c41 | 1092 | if(value &= H3LIS331DL_INT_SRC_IA){ |
daveheitzman | 0:a9de25fd7c41 | 1093 | *val = MEMS_SET; |
daveheitzman | 0:a9de25fd7c41 | 1094 | return MEMS_SUCCESS; |
daveheitzman | 0:a9de25fd7c41 | 1095 | } |
daveheitzman | 0:a9de25fd7c41 | 1096 | else{ |
daveheitzman | 0:a9de25fd7c41 | 1097 | *val = MEMS_RESET; |
daveheitzman | 0:a9de25fd7c41 | 1098 | return MEMS_SUCCESS; |
daveheitzman | 0:a9de25fd7c41 | 1099 | } |
daveheitzman | 0:a9de25fd7c41 | 1100 | } |
daveheitzman | 0:a9de25fd7c41 | 1101 | |
daveheitzman | 0:a9de25fd7c41 | 1102 | if(statusBIT == H3LIS331DL_INT_SRC_ZH){ |
daveheitzman | 0:a9de25fd7c41 | 1103 | if(value &= H3LIS331DL_INT_SRC_ZH){ |
daveheitzman | 0:a9de25fd7c41 | 1104 | *val = MEMS_SET; |
daveheitzman | 0:a9de25fd7c41 | 1105 | return MEMS_SUCCESS; |
daveheitzman | 0:a9de25fd7c41 | 1106 | } |
daveheitzman | 0:a9de25fd7c41 | 1107 | else{ |
daveheitzman | 0:a9de25fd7c41 | 1108 | *val = MEMS_RESET; |
daveheitzman | 0:a9de25fd7c41 | 1109 | return MEMS_SUCCESS; |
daveheitzman | 0:a9de25fd7c41 | 1110 | } |
daveheitzman | 0:a9de25fd7c41 | 1111 | } |
daveheitzman | 0:a9de25fd7c41 | 1112 | |
daveheitzman | 0:a9de25fd7c41 | 1113 | if(statusBIT == H3LIS331DL_INT_SRC_ZL){ |
daveheitzman | 0:a9de25fd7c41 | 1114 | if(value &= H3LIS331DL_INT_SRC_ZL){ |
daveheitzman | 0:a9de25fd7c41 | 1115 | *val = MEMS_SET; |
daveheitzman | 0:a9de25fd7c41 | 1116 | return MEMS_SUCCESS; |
daveheitzman | 0:a9de25fd7c41 | 1117 | } |
daveheitzman | 0:a9de25fd7c41 | 1118 | else{ |
daveheitzman | 0:a9de25fd7c41 | 1119 | *val = MEMS_RESET; |
daveheitzman | 0:a9de25fd7c41 | 1120 | return MEMS_SUCCESS; |
daveheitzman | 0:a9de25fd7c41 | 1121 | } |
daveheitzman | 0:a9de25fd7c41 | 1122 | } |
daveheitzman | 0:a9de25fd7c41 | 1123 | |
daveheitzman | 0:a9de25fd7c41 | 1124 | if(statusBIT == H3LIS331DL_INT_SRC_YH){ |
daveheitzman | 0:a9de25fd7c41 | 1125 | if(value &= H3LIS331DL_INT_SRC_YH){ |
daveheitzman | 0:a9de25fd7c41 | 1126 | *val = MEMS_SET; |
daveheitzman | 0:a9de25fd7c41 | 1127 | return MEMS_SUCCESS; |
daveheitzman | 0:a9de25fd7c41 | 1128 | } |
daveheitzman | 0:a9de25fd7c41 | 1129 | else{ |
daveheitzman | 0:a9de25fd7c41 | 1130 | *val = MEMS_RESET; |
daveheitzman | 0:a9de25fd7c41 | 1131 | return MEMS_SUCCESS; |
daveheitzman | 0:a9de25fd7c41 | 1132 | } |
daveheitzman | 0:a9de25fd7c41 | 1133 | } |
daveheitzman | 0:a9de25fd7c41 | 1134 | |
daveheitzman | 0:a9de25fd7c41 | 1135 | if(statusBIT == H3LIS331DL_INT_SRC_YL){ |
daveheitzman | 0:a9de25fd7c41 | 1136 | if(value &= H3LIS331DL_INT_SRC_YL){ |
daveheitzman | 0:a9de25fd7c41 | 1137 | *val = MEMS_SET; |
daveheitzman | 0:a9de25fd7c41 | 1138 | return MEMS_SUCCESS; |
daveheitzman | 0:a9de25fd7c41 | 1139 | } |
daveheitzman | 0:a9de25fd7c41 | 1140 | else{ |
daveheitzman | 0:a9de25fd7c41 | 1141 | *val = MEMS_RESET; |
daveheitzman | 0:a9de25fd7c41 | 1142 | return MEMS_SUCCESS; |
daveheitzman | 0:a9de25fd7c41 | 1143 | } |
daveheitzman | 0:a9de25fd7c41 | 1144 | } |
daveheitzman | 0:a9de25fd7c41 | 1145 | |
daveheitzman | 0:a9de25fd7c41 | 1146 | if(statusBIT == H3LIS331DL_INT_SRC_XH){ |
daveheitzman | 0:a9de25fd7c41 | 1147 | if(value &= H3LIS331DL_INT_SRC_XH){ |
daveheitzman | 0:a9de25fd7c41 | 1148 | *val = MEMS_SET; |
daveheitzman | 0:a9de25fd7c41 | 1149 | return MEMS_SUCCESS; |
daveheitzman | 0:a9de25fd7c41 | 1150 | } |
daveheitzman | 0:a9de25fd7c41 | 1151 | else{ |
daveheitzman | 0:a9de25fd7c41 | 1152 | *val = MEMS_RESET; |
daveheitzman | 0:a9de25fd7c41 | 1153 | return MEMS_SUCCESS; |
daveheitzman | 0:a9de25fd7c41 | 1154 | } |
daveheitzman | 0:a9de25fd7c41 | 1155 | } |
daveheitzman | 0:a9de25fd7c41 | 1156 | |
daveheitzman | 0:a9de25fd7c41 | 1157 | if(statusBIT == H3LIS331DL_INT_SRC_XL){ |
daveheitzman | 0:a9de25fd7c41 | 1158 | if(value &= H3LIS331DL_INT_SRC_XL){ |
daveheitzman | 0:a9de25fd7c41 | 1159 | *val = MEMS_SET; |
daveheitzman | 0:a9de25fd7c41 | 1160 | return MEMS_SUCCESS; |
daveheitzman | 0:a9de25fd7c41 | 1161 | } |
daveheitzman | 0:a9de25fd7c41 | 1162 | else{ |
daveheitzman | 0:a9de25fd7c41 | 1163 | *val = MEMS_RESET; |
daveheitzman | 0:a9de25fd7c41 | 1164 | return MEMS_SUCCESS; |
daveheitzman | 0:a9de25fd7c41 | 1165 | } |
daveheitzman | 0:a9de25fd7c41 | 1166 | } |
daveheitzman | 0:a9de25fd7c41 | 1167 | return MEMS_ERROR; |
daveheitzman | 0:a9de25fd7c41 | 1168 | } |
daveheitzman | 0:a9de25fd7c41 | 1169 | |
daveheitzman | 0:a9de25fd7c41 | 1170 | |
daveheitzman | 0:a9de25fd7c41 | 1171 | /******************************************************************************* |
daveheitzman | 0:a9de25fd7c41 | 1172 | * Function Name : getInt2SrcBit |
daveheitzman | 0:a9de25fd7c41 | 1173 | * Description : Reset Interrupt 2 Latching function |
daveheitzman | 0:a9de25fd7c41 | 1174 | * Input : H3LIS331DL_INT_SRC_IA, H3LIS331DL_INT_SRC_ZH, H3LIS331DL_INT_SRC_ZL ..... |
daveheitzman | 0:a9de25fd7c41 | 1175 | * Output : None |
daveheitzman | 0:a9de25fd7c41 | 1176 | * Return : Status of BIT [MEMS_ERROR, MEMS_SUCCESS] |
daveheitzman | 0:a9de25fd7c41 | 1177 | *******************************************************************************/ |
daveheitzman | 0:a9de25fd7c41 | 1178 | status_t H3LIS331DL::getInt2SrcBit(uint8_t statusBIT, uint8_t *val) { |
daveheitzman | 0:a9de25fd7c41 | 1179 | uint8_t value; |
daveheitzman | 0:a9de25fd7c41 | 1180 | |
daveheitzman | 0:a9de25fd7c41 | 1181 | if( !readReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_INT2_SRC, &value) ) |
daveheitzman | 0:a9de25fd7c41 | 1182 | return MEMS_ERROR; |
daveheitzman | 0:a9de25fd7c41 | 1183 | |
daveheitzman | 0:a9de25fd7c41 | 1184 | if(statusBIT == H3LIS331DL_INT_SRC_IA){ |
daveheitzman | 0:a9de25fd7c41 | 1185 | if(value &= H3LIS331DL_INT_SRC_IA){ |
daveheitzman | 0:a9de25fd7c41 | 1186 | *val = MEMS_SET; |
daveheitzman | 0:a9de25fd7c41 | 1187 | return MEMS_SUCCESS; |
daveheitzman | 0:a9de25fd7c41 | 1188 | } |
daveheitzman | 0:a9de25fd7c41 | 1189 | else{ |
daveheitzman | 0:a9de25fd7c41 | 1190 | *val = MEMS_RESET; |
daveheitzman | 0:a9de25fd7c41 | 1191 | return MEMS_SUCCESS; |
daveheitzman | 0:a9de25fd7c41 | 1192 | } |
daveheitzman | 0:a9de25fd7c41 | 1193 | } |
daveheitzman | 0:a9de25fd7c41 | 1194 | |
daveheitzman | 0:a9de25fd7c41 | 1195 | if(statusBIT == H3LIS331DL_INT_SRC_ZH){ |
daveheitzman | 0:a9de25fd7c41 | 1196 | if(value &= H3LIS331DL_INT_SRC_ZH){ |
daveheitzman | 0:a9de25fd7c41 | 1197 | *val = MEMS_SET; |
daveheitzman | 0:a9de25fd7c41 | 1198 | return MEMS_SUCCESS; |
daveheitzman | 0:a9de25fd7c41 | 1199 | } |
daveheitzman | 0:a9de25fd7c41 | 1200 | else{ |
daveheitzman | 0:a9de25fd7c41 | 1201 | *val = MEMS_RESET; |
daveheitzman | 0:a9de25fd7c41 | 1202 | return MEMS_SUCCESS; |
daveheitzman | 0:a9de25fd7c41 | 1203 | } |
daveheitzman | 0:a9de25fd7c41 | 1204 | } |
daveheitzman | 0:a9de25fd7c41 | 1205 | |
daveheitzman | 0:a9de25fd7c41 | 1206 | if(statusBIT == H3LIS331DL_INT_SRC_ZL){ |
daveheitzman | 0:a9de25fd7c41 | 1207 | if(value &= H3LIS331DL_INT_SRC_ZL){ |
daveheitzman | 0:a9de25fd7c41 | 1208 | *val = MEMS_SET; |
daveheitzman | 0:a9de25fd7c41 | 1209 | return MEMS_SUCCESS; |
daveheitzman | 0:a9de25fd7c41 | 1210 | } |
daveheitzman | 0:a9de25fd7c41 | 1211 | else{ |
daveheitzman | 0:a9de25fd7c41 | 1212 | *val = MEMS_RESET; |
daveheitzman | 0:a9de25fd7c41 | 1213 | return MEMS_SUCCESS; |
daveheitzman | 0:a9de25fd7c41 | 1214 | } |
daveheitzman | 0:a9de25fd7c41 | 1215 | } |
daveheitzman | 0:a9de25fd7c41 | 1216 | |
daveheitzman | 0:a9de25fd7c41 | 1217 | if(statusBIT == H3LIS331DL_INT_SRC_YH){ |
daveheitzman | 0:a9de25fd7c41 | 1218 | if(value &= H3LIS331DL_INT_SRC_YH){ |
daveheitzman | 0:a9de25fd7c41 | 1219 | *val = MEMS_SET; |
daveheitzman | 0:a9de25fd7c41 | 1220 | return MEMS_SUCCESS; |
daveheitzman | 0:a9de25fd7c41 | 1221 | } |
daveheitzman | 0:a9de25fd7c41 | 1222 | else{ |
daveheitzman | 0:a9de25fd7c41 | 1223 | *val = MEMS_RESET; |
daveheitzman | 0:a9de25fd7c41 | 1224 | return MEMS_SUCCESS; |
daveheitzman | 0:a9de25fd7c41 | 1225 | } |
daveheitzman | 0:a9de25fd7c41 | 1226 | } |
daveheitzman | 0:a9de25fd7c41 | 1227 | |
daveheitzman | 0:a9de25fd7c41 | 1228 | if(statusBIT == H3LIS331DL_INT_SRC_YL){ |
daveheitzman | 0:a9de25fd7c41 | 1229 | if(value &= H3LIS331DL_INT_SRC_YL){ |
daveheitzman | 0:a9de25fd7c41 | 1230 | *val = MEMS_SET; |
daveheitzman | 0:a9de25fd7c41 | 1231 | return MEMS_SUCCESS; |
daveheitzman | 0:a9de25fd7c41 | 1232 | } |
daveheitzman | 0:a9de25fd7c41 | 1233 | else{ |
daveheitzman | 0:a9de25fd7c41 | 1234 | *val = MEMS_RESET; |
daveheitzman | 0:a9de25fd7c41 | 1235 | return MEMS_SUCCESS; |
daveheitzman | 0:a9de25fd7c41 | 1236 | } |
daveheitzman | 0:a9de25fd7c41 | 1237 | } |
daveheitzman | 0:a9de25fd7c41 | 1238 | |
daveheitzman | 0:a9de25fd7c41 | 1239 | if(statusBIT == H3LIS331DL_INT_SRC_XH){ |
daveheitzman | 0:a9de25fd7c41 | 1240 | if(value &= H3LIS331DL_INT_SRC_XH){ |
daveheitzman | 0:a9de25fd7c41 | 1241 | *val = MEMS_SET; |
daveheitzman | 0:a9de25fd7c41 | 1242 | return MEMS_SUCCESS; |
daveheitzman | 0:a9de25fd7c41 | 1243 | } |
daveheitzman | 0:a9de25fd7c41 | 1244 | else{ |
daveheitzman | 0:a9de25fd7c41 | 1245 | *val = MEMS_RESET; |
daveheitzman | 0:a9de25fd7c41 | 1246 | return MEMS_SUCCESS; |
daveheitzman | 0:a9de25fd7c41 | 1247 | } |
daveheitzman | 0:a9de25fd7c41 | 1248 | } |
daveheitzman | 0:a9de25fd7c41 | 1249 | |
daveheitzman | 0:a9de25fd7c41 | 1250 | if(statusBIT == H3LIS331DL_INT_SRC_XL){ |
daveheitzman | 0:a9de25fd7c41 | 1251 | if(value &= H3LIS331DL_INT_SRC_XL){ |
daveheitzman | 0:a9de25fd7c41 | 1252 | *val = MEMS_SET; |
daveheitzman | 0:a9de25fd7c41 | 1253 | return MEMS_SUCCESS; |
daveheitzman | 0:a9de25fd7c41 | 1254 | } |
daveheitzman | 0:a9de25fd7c41 | 1255 | else{ |
daveheitzman | 0:a9de25fd7c41 | 1256 | *val = MEMS_RESET; |
daveheitzman | 0:a9de25fd7c41 | 1257 | return MEMS_SUCCESS; |
daveheitzman | 0:a9de25fd7c41 | 1258 | } |
daveheitzman | 0:a9de25fd7c41 | 1259 | } |
daveheitzman | 0:a9de25fd7c41 | 1260 | return MEMS_ERROR; |
daveheitzman | 0:a9de25fd7c41 | 1261 | } |
daveheitzman | 0:a9de25fd7c41 | 1262 | |
daveheitzman | 0:a9de25fd7c41 | 1263 | /******************************************************************************* |
daveheitzman | 0:a9de25fd7c41 | 1264 | * Function Name : readReg |
daveheitzman | 0:a9de25fd7c41 | 1265 | * Description : Generic Reading function. It must be full filled with either |
daveheitzman | 0:a9de25fd7c41 | 1266 | * : I2C or SPI reading functions |
daveheitzman | 0:a9de25fd7c41 | 1267 | * Input : Register Address |
daveheitzman | 0:a9de25fd7c41 | 1268 | * Output : Data Read |
daveheitzman | 0:a9de25fd7c41 | 1269 | * Return : Status [MEMS_ERROR, MEMS_SUCCESS] |
daveheitzman | 0:a9de25fd7c41 | 1270 | *******************************************************************************/ |
daveheitzman | 0:a9de25fd7c41 | 1271 | uint8_t H3LIS331DL::readReg(uint8_t deviceAddr, uint8_t Reg, uint8_t* Data) { |
daveheitzman | 0:a9de25fd7c41 | 1272 | uint8_t result; |
daveheitzman | 0:a9de25fd7c41 | 1273 | |
daveheitzman | 0:a9de25fd7c41 | 1274 | result = i2c->write((deviceAddr << 1), (char *)&Reg, 1, true); |
daveheitzman | 0:a9de25fd7c41 | 1275 | result |= i2c->read((deviceAddr << 1), (char *)Data, 2); |
daveheitzman | 0:a9de25fd7c41 | 1276 | |
daveheitzman | 0:a9de25fd7c41 | 1277 | if (result) { |
daveheitzman | 0:a9de25fd7c41 | 1278 | return MEMS_ERROR; |
daveheitzman | 0:a9de25fd7c41 | 1279 | } |
daveheitzman | 0:a9de25fd7c41 | 1280 | else { |
daveheitzman | 0:a9de25fd7c41 | 1281 | return MEMS_SUCCESS; |
daveheitzman | 0:a9de25fd7c41 | 1282 | } |
daveheitzman | 0:a9de25fd7c41 | 1283 | } |
daveheitzman | 0:a9de25fd7c41 | 1284 | |
daveheitzman | 0:a9de25fd7c41 | 1285 | /******************************************************************************* |
daveheitzman | 0:a9de25fd7c41 | 1286 | * Function Name : writeReg |
daveheitzman | 0:a9de25fd7c41 | 1287 | * Description : Generic Writing function. It must be full filled with either |
daveheitzman | 0:a9de25fd7c41 | 1288 | * : I2C or SPI writing function |
daveheitzman | 0:a9de25fd7c41 | 1289 | * Input : Register Address, Data to be written |
daveheitzman | 0:a9de25fd7c41 | 1290 | * Output : None |
daveheitzman | 0:a9de25fd7c41 | 1291 | * Return : Status [MEMS_ERROR, MEMS_SUCCESS] |
daveheitzman | 0:a9de25fd7c41 | 1292 | *******************************************************************************/ |
daveheitzman | 0:a9de25fd7c41 | 1293 | uint8_t H3LIS331DL::writeReg(uint8_t deviceAddress, uint8_t WriteAddr, uint8_t Data) { |
daveheitzman | 0:a9de25fd7c41 | 1294 | uint8_t buf[2]; |
daveheitzman | 0:a9de25fd7c41 | 1295 | uint8_t result; |
daveheitzman | 0:a9de25fd7c41 | 1296 | |
daveheitzman | 0:a9de25fd7c41 | 1297 | buf[0] = WriteAddr; |
daveheitzman | 0:a9de25fd7c41 | 1298 | buf[1] = Data; |
daveheitzman | 0:a9de25fd7c41 | 1299 | result = i2c->write((deviceAddress << 1), (char *)buf, 2); |
daveheitzman | 0:a9de25fd7c41 | 1300 | |
daveheitzman | 0:a9de25fd7c41 | 1301 | if (result) { |
daveheitzman | 0:a9de25fd7c41 | 1302 | return MEMS_ERROR; |
daveheitzman | 0:a9de25fd7c41 | 1303 | } |
daveheitzman | 0:a9de25fd7c41 | 1304 | else { |
daveheitzman | 0:a9de25fd7c41 | 1305 | return MEMS_SUCCESS; |
daveheitzman | 0:a9de25fd7c41 | 1306 | } |
daveheitzman | 0:a9de25fd7c41 | 1307 | } |