1 /* 2 $License: 3 Copyright 2011 InvenSense, Inc. 4 5 Licensed under the Apache License, Version 2.0 (the "License"); 6 you may not use this file except in compliance with the License. 7 You may obtain a copy of the License at 8 9 http://www.apache.org/licenses/LICENSE-2.0 10 11 Unless required by applicable law or agreed to in writing, software 12 distributed under the License is distributed on an "AS IS" BASIS, 13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 See the License for the specific language governing permissions and 15 limitations under the License. 16 $ 17 */ 18 /******************************************************************************* 19 * 20 * $Id: pressure.c 4120 2010-11-21 19:56:16Z mcaramello $ 21 * 22 *******************************************************************************/ 23 24 /** 25 * @defgroup PRESSUREDL 26 * @brief Motion Library - Pressure Driver Layer. 27 * Provides the interface to setup and handle a pressure sensor 28 * connected to either the primary or the seconday I2C interface 29 * of the gyroscope. 30 * 31 * @{ 32 * @file pressure.c 33 * @brief Pressure setup and handling methods. 34 **/ 35 36 /* ------------------ */ 37 /* - Include Files. - */ 38 /* ------------------ */ 39 40 #include <string.h> 41 42 #include "pressure.h" 43 44 #include "ml.h" 45 #include "mlinclude.h" 46 #include "dmpKey.h" 47 #include "mlFIFO.h" 48 #include "mldl.h" 49 #include "mldl_cfg.h" 50 #include "mlMathFunc.h" 51 #include "mlsl.h" 52 #include "mlos.h" 53 54 #include "log.h" 55 #undef MPL_LOG_TAG 56 #define MPL_LOG_TAG "MPL-pressure" 57 58 #define _pressureDebug(x) //{x} 59 60 /* --------------------- */ 61 /* - Global Variables. - */ 62 /* --------------------- */ 63 64 /* --------------------- */ 65 /* - Static Variables. - */ 66 /* --------------------- */ 67 68 /* --------------- */ 69 /* - Prototypes. - */ 70 /* --------------- */ 71 72 /* -------------- */ 73 /* - Externs. - */ 74 /* -------------- */ 75 76 /* -------------- */ 77 /* - Functions. - */ 78 /* -------------- */ 79 80 /** 81 * @brief Is a pressure configured and used by MPL? 82 * @return INV_SUCCESS if the pressure is present. 83 */ 84 unsigned char inv_pressure_present(void) 85 { 86 INVENSENSE_FUNC_START; 87 struct mldl_cfg *mldl_cfg = inv_get_dl_config(); 88 if (NULL != mldl_cfg->pressure && 89 NULL != mldl_cfg->pressure->resume && 90 mldl_cfg->requested_sensors & INV_THREE_AXIS_PRESSURE) 91 return TRUE; 92 else 93 return FALSE; 94 } 95 96 /** 97 * @brief Query the pressure slave address. 98 * @return The 7-bit pressure slave address. 99 */ 100 unsigned char inv_get_pressure_slave_addr(void) 101 { 102 INVENSENSE_FUNC_START; 103 struct mldl_cfg *mldl_cfg = inv_get_dl_config(); 104 if (NULL != mldl_cfg->pdata) 105 return mldl_cfg->pdata->pressure.address; 106 else 107 return 0; 108 } 109 110 /** 111 * @brief Get the ID of the pressure in use. 112 * @return ID of the pressure in use. 113 */ 114 unsigned short inv_get_pressure_id(void) 115 { 116 INVENSENSE_FUNC_START; 117 struct mldl_cfg *mldl_cfg = inv_get_dl_config(); 118 if (NULL != mldl_cfg->pressure) { 119 return mldl_cfg->pressure->id; 120 } 121 return ID_INVALID; 122 } 123 124 /** 125 * @brief Get a sample of pressure data from the device. 126 * @param data 127 * the buffer to store the pressure raw data for 128 * X, Y, and Z axes. 129 * @return INV_SUCCESS or a non-zero error code. 130 */ 131 inv_error_t inv_get_pressure_data(long *data) 132 { 133 inv_error_t result = INV_SUCCESS; 134 unsigned char tmp[3]; 135 struct mldl_cfg *mldl_cfg = inv_get_dl_config(); 136 137 /*--- read the pressure sensor data. 138 The pressure read function may return an INV_ERROR_PRESSURE_* errors 139 when the data is not ready (read/refresh frequency mismatch) or 140 the internal data sampling timing of the device was not respected. 141 Returning the error code will make the sensor fusion supervisor 142 ignore this pressure data sample. ---*/ 143 result = (inv_error_t) inv_mpu_read_pressure(mldl_cfg, 144 inv_get_serial_handle(), 145 inv_get_serial_handle(), tmp); 146 if (result) { 147 _pressureDebug(MPL_LOGV 148 ("inv_mpu_read_pressure returned %d (%s)\n", result, 149 MLErrorCode(result))); 150 return result; 151 } 152 if (EXT_SLAVE_BIG_ENDIAN == mldl_cfg->pressure->endian) 153 data[0] = 154 (((long)((signed char)tmp[0])) << 16) + (((long)tmp[1]) << 8) + 155 ((long)tmp[2]); 156 else 157 data[0] = 158 (((long)((signed char)tmp[2])) << 16) + (((long)tmp[1]) << 8) + 159 ((long)tmp[0]); 160 161 return INV_SUCCESS; 162 } 163 164 /** 165 * @} 166 */ 167