Mario
Dependents: LoRaWANdemoUnina LoRaWANdemo72 LoRaWANRadiation Sensor_shield ... more
Revision 0:98c301bb7d1b, committed 2017-10-03
- Comitter:
- salvatoregulfo
- Date:
- Tue Oct 03 12:21:11 2017 +0000
- Commit message:
- Mario Conti
Changed in this revision
diff -r 000000000000 -r 98c301bb7d1b Components/HTS221Sensor/HTS221Sensor.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Components/HTS221Sensor/HTS221Sensor.cpp Tue Oct 03 12:21:11 2017 +0000 @@ -0,0 +1,315 @@ +/** + ****************************************************************************** + * @file HTS221Sensor.cpp + * @author CLab + * @version V1.0.0 + * @date 5 August 2016 + * @brief Implementation of an HTS221 Humidity and Temperature sensor. + ****************************************************************************** + * @attention + * + * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of STMicroelectronics nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************** + */ + + +/* Includes ------------------------------------------------------------------*/ + +#include "mbed.h" +#include "DevI2C.h" +#include "HTS221Sensor.h" +#include "HTS221_driver.h" + + +/* Class Implementation ------------------------------------------------------*/ + +/** Constructor + * @param i2c object of an helper class which handles the I2C peripheral + * @param address the address of the component's instance + */ +HTS221Sensor::HTS221Sensor(DevI2C &i2c) : _dev_i2c(i2c) +{ + _address = HTS221_I2C_ADDRESS; +}; + + +/** Constructor + * @param i2c object of an helper class which handles the I2C peripheral + * @param address the address of the component's instance + */ +HTS221Sensor::HTS221Sensor(DevI2C &i2c, uint8_t address) : _dev_i2c(i2c), _address(address) +{ + +}; + +/** + * @brief Initializing the component. + * @param[in] init pointer to device specific initalization structure. + * @retval "0" in case of success, an error code otherwise. + */ +int HTS221Sensor::init(void *init) +{ + /* Power down the device */ + if ( HTS221_DeActivate( (void *)this ) == HTS221_ERROR ) + { + return 1; + } + + /* Enable BDU */ + if ( HTS221_Set_BduMode( (void *)this, HTS221_ENABLE ) == HTS221_ERROR ) + { + return 1; + } + + if(set_odr(1.0f) == 1) + { + return 1; + } + + return 0; +} + +/** + * @brief Enable HTS221 + * @retval 0 in case of success, an error code otherwise + */ +int HTS221Sensor::enable(void) +{ + /* Power up the device */ + if ( HTS221_Activate( (void *)this ) == HTS221_ERROR ) + { + return 1; + } + + return 0; +} + +/** + * @brief Disable HTS221 + * @retval 0 in case of success, an error code otherwise + */ +int HTS221Sensor::disable(void) +{ + /* Power up the device */ + if ( HTS221_DeActivate( (void *)this ) == HTS221_ERROR ) + { + return 1; + } + + return 0; +} + +/** + * @brief Read ID address of HTS221 + * @param id the pointer where the ID of the device is stored + * @retval 0 in case of success, an error code otherwise + */ +int HTS221Sensor::read_id(uint8_t *id) +{ + if(!id) + { + return 1; + } + + /* Read WHO AM I register */ + if ( HTS221_Get_DeviceID( (void *)this, id ) == HTS221_ERROR ) + { + return 1; + } + + return 0; +} + +/** + * @brief Reboot memory content of HTS221 + * @param None + * @retval 0 in case of success, an error code otherwise + */ +int HTS221Sensor::reset(void) +{ + uint8_t tmpreg; + + /* Read CTRL_REG2 register */ + if (read_reg(HTS221_CTRL_REG2, &tmpreg) != 0) + { + return 1; + } + + /* Enable or Disable the reboot memory */ + tmpreg |= (0x01 << HTS221_BOOT_BIT); + + /* Write value to MEMS CTRL_REG2 regsister */ + if (write_reg(HTS221_CTRL_REG2, tmpreg) != 0) + { + return 1; + } + + return 0; +} + +/** + * @brief Read HTS221 output register, and calculate the humidity + * @param pfData the pointer to data output + * @retval 0 in case of success, an error code otherwise + */ +int HTS221Sensor::get_humidity(float* pfData) +{ + uint16_t uint16data = 0; + + /* Read data from HTS221. */ + if ( HTS221_Get_Humidity( (void *)this, &uint16data ) == HTS221_ERROR ) + { + return 1; + } + + *pfData = ( float )uint16data / 10.0f; + + return 0; +} + +/** + * @brief Read HTS221 output register, and calculate the temperature + * @param pfData the pointer to data output + * @retval 0 in case of success, an error code otherwise + */ +int HTS221Sensor::get_temperature(float* pfData) +{ + int16_t int16data = 0; + + /* Read data from HTS221. */ + if ( HTS221_Get_Temperature( (void *)this, &int16data ) == HTS221_ERROR ) + { + return 1; + } + + *pfData = ( float )int16data / 10.0f; + + return 0; +} + +/** + * @brief Read HTS221 output register, and calculate the humidity + * @param odr the pointer to the output data rate + * @retval 0 in case of success, an error code otherwise + */ +int HTS221Sensor::get_odr(float* odr) +{ + HTS221_Odr_et odr_low_level; + + if ( HTS221_Get_Odr( (void *)this, &odr_low_level ) == HTS221_ERROR ) + { + return 1; + } + + switch( odr_low_level ) + { + case HTS221_ODR_ONE_SHOT: + *odr = 0.0f; + break; + case HTS221_ODR_1HZ : + *odr = 1.0f; + break; + case HTS221_ODR_7HZ : + *odr = 7.0f; + break; + case HTS221_ODR_12_5HZ : + *odr = 12.5f; + break; + default : + *odr = -1.0f; + return 1; + } + + return 0; +} + +/** + * @brief Set ODR + * @param odr the output data rate to be set + * @retval 0 in case of success, an error code otherwise + */ +int HTS221Sensor::set_odr(float odr) +{ + HTS221_Odr_et new_odr; + + new_odr = ( odr <= 1.0f ) ? HTS221_ODR_1HZ + : ( odr <= 7.0f ) ? HTS221_ODR_7HZ + : HTS221_ODR_12_5HZ; + + if ( HTS221_Set_Odr( (void *)this, new_odr ) == HTS221_ERROR ) + { + return 1; + } + + return 0; +} + + +/** + * @brief Read the data from register + * @param reg register address + * @param data register data + * @retval 0 in case of success + * @retval 1 in case of failure + */ +int HTS221Sensor::read_reg( uint8_t reg, uint8_t *data ) +{ + + if ( HTS221_read_reg( (void *)this, reg, 1, data ) == HTS221_ERROR ) + { + return 1; + } + + return 0; +} + +/** + * @brief Write the data to register + * @param reg register address + * @param data register data + * @retval 0 in case of success + * @retval 1 in case of failure + */ +int HTS221Sensor::write_reg( uint8_t reg, uint8_t data ) +{ + + if ( HTS221_write_reg( (void *)this, reg, 1, &data ) == HTS221_ERROR ) + { + return 1; + } + + return 0; +} + +uint8_t HTS221_io_write( void *handle, uint8_t WriteAddr, uint8_t *pBuffer, uint16_t nBytesToWrite ) +{ + return ((HTS221Sensor *)handle)->io_write(pBuffer, WriteAddr, nBytesToWrite); +} + +uint8_t HTS221_io_read( void *handle, uint8_t ReadAddr, uint8_t *pBuffer, uint16_t nBytesToRead ) +{ + return ((HTS221Sensor *)handle)->io_read(pBuffer, ReadAddr, nBytesToRead); +}
diff -r 000000000000 -r 98c301bb7d1b Components/HTS221Sensor/HTS221Sensor.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Components/HTS221Sensor/HTS221Sensor.h Tue Oct 03 12:21:11 2017 +0000 @@ -0,0 +1,118 @@ +/** + ****************************************************************************** + * @file HTS221Sensor.h + * @author CLab + * @version V1.0.0 + * @date 5 August 2016 + * @brief Abstract class of an HTS221 Humidity and Temperature sensor. + ****************************************************************************** + * @attention + * + * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of STMicroelectronics nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************** + */ + + +/* Prevent recursive inclusion -----------------------------------------------*/ + +#ifndef __HTS221Sensor_H__ +#define __HTS221Sensor_H__ + + +/* Includes ------------------------------------------------------------------*/ + +#include "DevI2C.h" +#include "HTS221_driver.h" +#include "HumiditySensor.h" +#include "TempSensor.h" + + +/* Class Declaration ---------------------------------------------------------*/ + +/** + * Abstract class of an HTS221 Humidity and Temperature sensor. + */ +class HTS221Sensor : public HumiditySensor, public TempSensor +{ + public: + + HTS221Sensor(DevI2C &i2c); + HTS221Sensor(DevI2C &i2c, uint8_t address); + virtual int init(void *init); + virtual int read_id(uint8_t *id); + virtual int get_humidity(float *pfData); + virtual int get_temperature(float *pfData); + int enable(void); + int disable(void); + int reset(void); + int get_odr(float *odr); + int set_odr(float odr); + int read_reg(uint8_t reg, uint8_t *data); + int write_reg(uint8_t reg, uint8_t data); + /** + * @brief Utility function to read data. + * @param pBuffer: pointer to data to be read. + * @param RegisterAddr: specifies internal address register to be read. + * @param NumByteToRead: number of bytes to be read. + * @retval 0 if ok, an error code otherwise. + */ + uint8_t io_read(uint8_t* pBuffer, uint8_t RegisterAddr, uint16_t NumByteToRead) + { + return (uint8_t) _dev_i2c.i2c_read(pBuffer, _address, RegisterAddr, NumByteToRead); + } + + /** + * @brief Utility function to write data. + * @param pBuffer: pointer to data to be written. + * @param RegisterAddr: specifies internal address register to be written. + * @param NumByteToWrite: number of bytes to write. + * @retval 0 if ok, an error code otherwise. + */ + uint8_t io_write(uint8_t* pBuffer, uint8_t RegisterAddr, uint16_t NumByteToWrite) + { + return (uint8_t) _dev_i2c.i2c_write(pBuffer, _address, RegisterAddr, NumByteToWrite); + } + + private: + + /* Helper classes. */ + DevI2C &_dev_i2c; + + /* Configuration */ + uint8_t _address; + +}; + +#ifdef __cplusplus + extern "C" { +#endif +uint8_t HTS221_io_write( void *handle, uint8_t WriteAddr, uint8_t *pBuffer, uint16_t nBytesToWrite ); +uint8_t HTS221_io_read( void *handle, uint8_t ReadAddr, uint8_t *pBuffer, uint16_t nBytesToRead ); +#ifdef __cplusplus + } +#endif + +#endif
diff -r 000000000000 -r 98c301bb7d1b Components/HTS221Sensor/HTS221_driver.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Components/HTS221Sensor/HTS221_driver.c Tue Oct 03 12:21:11 2017 +0000 @@ -0,0 +1,987 @@ +/** + ****************************************************************************** + * @file HTS221_driver.c + * @author HESA Application Team + * @version V1.1 + * @date 10-August-2016 + * @brief HTS221 driver file + ****************************************************************************** + * @attention + * + * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of STMicroelectronics nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************** + */ + +/* Includes ------------------------------------------------------------------*/ +#include "HTS221_driver.h" + +#ifdef __cplusplus + extern "C" { +#endif + +#ifdef USE_FULL_ASSERT_HTS221 +#include <stdio.h> +#endif + + +/** @addtogroup Environmental_Sensor +* @{ +*/ + +/** @defgroup HTS221_DRIVER +* @brief HTS221 DRIVER +* @{ +*/ + +/** @defgroup HTS221_Imported_Function_Prototypes +* @{ +*/ + +extern uint8_t HTS221_io_write( void *handle, uint8_t WriteAddr, uint8_t *pBuffer, uint16_t nBytesToWrite ); +extern uint8_t HTS221_io_read( void *handle, uint8_t ReadAddr, uint8_t *pBuffer, uint16_t nBytesToRead ); + +/** +* @} +*/ + +/** @defgroup HTS221_Private_Function_Prototypes +* @{ +*/ + +/** +* @} +*/ + +/** @defgroup HTS221_Private_Functions +* @{ +*/ + +/** +* @} +*/ + +/** @defgroup HTS221_Public_Functions +* @{ +*/ + +/******************************************************************************* +* Function Name : HTS221_read_reg +* Description : Generic Reading function. It must be fullfilled with either +* : I2C or SPI reading functions +* Input : Register Address +* Output : Data Read +* Return : None +*******************************************************************************/ +HTS221_Error_et HTS221_read_reg( void *handle, uint8_t RegAddr, uint16_t NumByteToRead, uint8_t *Data ) +{ + + if ( NumByteToRead > 1 ) RegAddr |= 0x80; + + if ( HTS221_io_read( handle, RegAddr, Data, NumByteToRead ) ) + return HTS221_ERROR; + else + return HTS221_OK; +} + +/******************************************************************************* +* Function Name : HTS221_write_reg +* Description : Generic Writing function. It must be fullfilled with either +* : I2C or SPI writing function +* Input : Register Address, Data to be written +* Output : None +* Return : None +*******************************************************************************/ +HTS221_Error_et HTS221_write_reg( void *handle, uint8_t RegAddr, uint16_t NumByteToWrite, uint8_t *Data ) +{ + + if ( NumByteToWrite > 1 ) RegAddr |= 0x80; + + if ( HTS221_io_write( handle, RegAddr, Data, NumByteToWrite ) ) + return HTS221_ERROR; + else + return HTS221_OK; +} + +/** +* @brief Get the version of this driver. +* @param pxVersion pointer to a HTS221_DriverVersion_st structure that contains the version information. +* This parameter is a pointer to @ref HTS221_DriverVersion_st. +* @retval Error code [HTS221_OK, HTS221_ERROR]. +*/ +HTS221_Error_et HTS221_Get_DriverVersion(HTS221_DriverVersion_st* version) +{ + version->Major = HTS221_DRIVER_VERSION_MAJOR; + version->Minor = HTS221_DRIVER_VERSION_MINOR; + version->Point = HTS221_DRIVER_VERSION_POINT; + + return HTS221_OK; +} + +/** +* @brief Get device type ID. +* @param *handle Device handle. +* @param deviceid pointer to the returned device type ID. +* @retval Error code [HTS221_OK, HTS221_ERROR]. +*/ +HTS221_Error_et HTS221_Get_DeviceID(void *handle, uint8_t* deviceid) +{ + if(HTS221_read_reg(handle, HTS221_WHO_AM_I_REG, 1, deviceid)) + return HTS221_ERROR; + + return HTS221_OK; +} + +/** +* @brief Initializes the HTS221 with the specified parameters in HTS221_Init_st struct. +* @param *handle Device handle. +* @param pxInit pointer to a HTS221_Init_st structure that contains the configuration. +* This parameter is a pointer to @ref HTS221_Init_st. +* @retval Error code [HTS221_OK, HTS221_ERROR]. +*/ +HTS221_Error_et HTS221_Set_InitConfig(void *handle, HTS221_Init_st* pxInit) +{ + uint8_t buffer[3]; + + HTS221_assert_param(IS_HTS221_AVGH(pxInit->avg_h)); + HTS221_assert_param(IS_HTS221_AVGT(pxInit->avg_t)); + HTS221_assert_param(IS_HTS221_ODR(pxInit->odr)); + HTS221_assert_param(IS_HTS221_State(pxInit->bdu_status)); + HTS221_assert_param(IS_HTS221_State(pxInit->heater_status)); + + HTS221_assert_param(IS_HTS221_DrdyLevelType(pxInit->irq_level)); + HTS221_assert_param(IS_HTS221_OutputType(pxInit->irq_output_type)); + HTS221_assert_param(IS_HTS221_State(pxInit->irq_enable)); + + if(HTS221_read_reg(handle, HTS221_AV_CONF_REG, 1, buffer)) + return HTS221_ERROR; + + buffer[0] &= ~(HTS221_AVGH_MASK | HTS221_AVGT_MASK); + buffer[0] |= (uint8_t)pxInit->avg_h; + buffer[0] |= (uint8_t)pxInit->avg_t; + + if(HTS221_write_reg(handle, HTS221_AV_CONF_REG, 1, buffer)) + return HTS221_ERROR; + + if(HTS221_read_reg(handle, HTS221_CTRL_REG1, 3, buffer)) + return HTS221_ERROR; + + buffer[0] &= ~(HTS221_BDU_MASK | HTS221_ODR_MASK); + buffer[0] |= (uint8_t)pxInit->odr; + buffer[0] |= ((uint8_t)pxInit->bdu_status) << HTS221_BDU_BIT; + + buffer[1] &= ~HTS221_HEATHER_BIT; + buffer[1] |= ((uint8_t)pxInit->heater_status) << HTS221_HEATHER_BIT; + + buffer[2] &= ~(HTS221_DRDY_H_L_MASK | HTS221_PP_OD_MASK | HTS221_DRDY_MASK); + buffer[2] |= ((uint8_t)pxInit->irq_level) << HTS221_DRDY_H_L_BIT; + buffer[2] |= (uint8_t)pxInit->irq_output_type; + buffer[2] |= ((uint8_t)pxInit->irq_enable) << HTS221_DRDY_BIT; + + if(HTS221_write_reg(handle, HTS221_CTRL_REG1, 3, buffer)) + return HTS221_ERROR; + + return HTS221_OK; +} + +/** +* @brief Returns a HTS221_Init_st struct with the actual configuration. +* @param *handle Device handle. +* @param pxInit pointer to a HTS221_Init_st structure. +* This parameter is a pointer to @ref HTS221_Init_st. +* @retval Error code [HTS221_OK, HTS221_ERROR]. +*/ +HTS221_Error_et HTS221_Get_InitConfig(void *handle, HTS221_Init_st* pxInit) +{ + uint8_t buffer[3]; + + if(HTS221_read_reg(handle, HTS221_AV_CONF_REG, 1, buffer)) + return HTS221_ERROR; + + pxInit->avg_h = (HTS221_Avgh_et)(buffer[0] & HTS221_AVGH_MASK); + pxInit->avg_t = (HTS221_Avgt_et)(buffer[0] & HTS221_AVGT_MASK); + + if(HTS221_read_reg(handle, HTS221_CTRL_REG1, 3, buffer)) + return HTS221_ERROR; + + pxInit->odr = (HTS221_Odr_et)(buffer[0] & HTS221_ODR_MASK); + pxInit->bdu_status = (HTS221_State_et)((buffer[0] & HTS221_BDU_MASK) >> HTS221_BDU_BIT); + pxInit->heater_status = (HTS221_State_et)((buffer[1] & HTS221_HEATHER_MASK) >> HTS221_HEATHER_BIT); + + pxInit->irq_level = (HTS221_DrdyLevel_et)(buffer[2] & HTS221_DRDY_H_L_MASK); + pxInit->irq_output_type = (HTS221_OutputType_et)(buffer[2] & HTS221_PP_OD_MASK); + pxInit->irq_enable = (HTS221_State_et)((buffer[2] & HTS221_DRDY_MASK) >> HTS221_DRDY_BIT); + + return HTS221_OK; +} + +/** +* @brief De initialization function for HTS221. +* This function put the HTS221 in power down, make a memory boot and clear the data output flags. +* @param *handle Device handle. +* @retval Error code [HTS221_OK, HTS221_ERROR]. +*/ +HTS221_Error_et HTS221_DeInit(void *handle) +{ + uint8_t buffer[4]; + + if(HTS221_read_reg(handle, HTS221_CTRL_REG1, 2, buffer)) + return HTS221_ERROR; + + /* HTS221 in power down */ + buffer[0] |= 0x01 << HTS221_PD_BIT; + + /* Make HTS221 boot */ + buffer[1] |= 0x01 << HTS221_BOOT_BIT; + + if(HTS221_write_reg(handle, HTS221_CTRL_REG1, 2, buffer)) + return HTS221_ERROR; + + /* Dump of data output */ + if(HTS221_read_reg(handle, HTS221_HR_OUT_L_REG, 4, buffer)) + return HTS221_ERROR; + + return HTS221_OK; +} + +/** +* @brief Read HTS221 output registers, and calculate humidity and temperature. +* @param *handle Device handle. +* @param humidity pointer to the returned humidity value that must be divided by 10 to get the value in [%]. +* @param temperature pointer to the returned temperature value that must be divided by 10 to get the value in ['C]. +* @retval Error code [HTS221_OK, HTS221_ERROR]. +*/ +HTS221_Error_et HTS221_Get_Measurement(void *handle, uint16_t* humidity, int16_t* temperature) +{ + if ( HTS221_Get_Temperature( handle, temperature ) == HTS221_ERROR ) return HTS221_ERROR; + if ( HTS221_Get_Humidity( handle, humidity ) == HTS221_ERROR ) return HTS221_ERROR; + + return HTS221_OK; +} + +/** +* @brief Read HTS221 output registers. Humidity and temperature. +* @param *handle Device handle. +* @param humidity pointer to the returned humidity raw value. +* @param temperature pointer to the returned temperature raw value. +* @retval Error code [HTS221_OK, HTS221_ERROR]. +*/ +HTS221_Error_et HTS221_Get_RawMeasurement(void *handle, int16_t* humidity, int16_t* temperature) +{ + uint8_t buffer[4]; + + if(HTS221_read_reg(handle, HTS221_HR_OUT_L_REG, 4, buffer)) + return HTS221_ERROR; + + *humidity = (int16_t)((((uint16_t)buffer[1]) << 8) | (uint16_t)buffer[0]); + *temperature = (int16_t)((((uint16_t)buffer[3]) << 8) | (uint16_t)buffer[2]); + + return HTS221_OK; +} + +/** +* @brief Read HTS221 Humidity output registers, and calculate humidity. +* @param *handle Device handle. +* @param Pointer to the returned humidity value that must be divided by 10 to get the value in [%]. +* @retval Error code [HTS221_OK, HTS221_ERROR]. +*/ +HTS221_Error_et HTS221_Get_Humidity(void *handle, uint16_t* value) +{ + int16_t H0_T0_out, H1_T0_out, H_T_out; + int16_t H0_rh, H1_rh; + uint8_t buffer[2]; + float tmp_f; + + if(HTS221_read_reg(handle, HTS221_H0_RH_X2, 2, buffer)) + return HTS221_ERROR; + H0_rh = buffer[0] >> 1; + H1_rh = buffer[1] >> 1; + + if(HTS221_read_reg(handle, HTS221_H0_T0_OUT_L, 2, buffer)) + return HTS221_ERROR; + H0_T0_out = (((uint16_t)buffer[1]) << 8) | (uint16_t)buffer[0]; + + if(HTS221_read_reg(handle, HTS221_H1_T0_OUT_L, 2, buffer)) + return HTS221_ERROR; + H1_T0_out = (((uint16_t)buffer[1]) << 8) | (uint16_t)buffer[0]; + + if(HTS221_read_reg(handle, HTS221_HR_OUT_L_REG, 2, buffer)) + return HTS221_ERROR; + H_T_out = (((uint16_t)buffer[1]) << 8) | (uint16_t)buffer[0]; + + tmp_f = (float)(H_T_out - H0_T0_out) * (float)(H1_rh - H0_rh) / (float)(H1_T0_out - H0_T0_out) + H0_rh; + tmp_f *= 10.0f; + + *value = ( tmp_f > 1000.0f ) ? 1000 + : ( tmp_f < 0.0f ) ? 0 + : ( uint16_t )tmp_f; + + return HTS221_OK; +} + +/** +* @brief Read HTS221 humidity output registers. +* @param *handle Device handle. +* @param Pointer to the returned humidity raw value. +* @retval Error code [HTS221_OK, HTS221_ERROR]. +*/ +HTS221_Error_et HTS221_Get_HumidityRaw(void *handle, int16_t* value) +{ + uint8_t buffer[2]; + + if(HTS221_read_reg(handle, HTS221_HR_OUT_L_REG, 2, buffer)) + return HTS221_ERROR; + + *value = (int16_t)((((uint16_t)buffer[1]) << 8) | (uint16_t)buffer[0]); + + return HTS221_OK; +} + +/** +* @brief Read HTS221 temperature output registers, and calculate temperature. +* @param *handle Device handle. +* @param Pointer to the returned temperature value that must be divided by 10 to get the value in ['C]. +* @retval Error code [HTS221_OK, HTS221_ERROR]. +*/ +HTS221_Error_et HTS221_Get_Temperature(void *handle, int16_t *value) +{ + int16_t T0_out, T1_out, T_out, T0_degC_x8_u16, T1_degC_x8_u16; + int16_t T0_degC, T1_degC; + uint8_t buffer[4], tmp; + float tmp_f; + + if(HTS221_read_reg(handle, HTS221_T0_DEGC_X8, 2, buffer)) + return HTS221_ERROR; + if(HTS221_read_reg(handle, HTS221_T0_T1_DEGC_H2, 1, &tmp)) + return HTS221_ERROR; + + T0_degC_x8_u16 = (((uint16_t)(tmp & 0x03)) << 8) | ((uint16_t)buffer[0]); + T1_degC_x8_u16 = (((uint16_t)(tmp & 0x0C)) << 6) | ((uint16_t)buffer[1]); + T0_degC = T0_degC_x8_u16 >> 3; + T1_degC = T1_degC_x8_u16 >> 3; + + if(HTS221_read_reg(handle, HTS221_T0_OUT_L, 4, buffer)) + return HTS221_ERROR; + + T0_out = (((uint16_t)buffer[1]) << 8) | (uint16_t)buffer[0]; + T1_out = (((uint16_t)buffer[3]) << 8) | (uint16_t)buffer[2]; + + if(HTS221_read_reg(handle, HTS221_TEMP_OUT_L_REG, 2, buffer)) + return HTS221_ERROR; + + T_out = (((uint16_t)buffer[1]) << 8) | (uint16_t)buffer[0]; + + tmp_f = (float)(T_out - T0_out) * (float)(T1_degC - T0_degC) / (float)(T1_out - T0_out) + T0_degC; + tmp_f *= 10.0f; + + *value = ( int16_t )tmp_f; + + return HTS221_OK; +} + +/** +* @brief Read HTS221 temperature output registers. +* @param *handle Device handle. +* @param Pointer to the returned temperature raw value. +* @retval Error code [HTS221_OK, HTS221_ERROR]. +*/ +HTS221_Error_et HTS221_Get_TemperatureRaw(void *handle, int16_t* value) +{ + uint8_t buffer[2]; + + if(HTS221_read_reg(handle, HTS221_TEMP_OUT_L_REG, 2, buffer)) + return HTS221_ERROR; + + *value = (int16_t)((((uint16_t)buffer[1]) << 8) | (uint16_t)buffer[0]); + + return HTS221_OK; +} + +/** +* @brief Get the availability of new data for humidity and temperature. +* @param *handle Device handle. +* @param humidity pointer to the returned humidity data status [HTS221_SET/HTS221_RESET]. +* @param temperature pointer to the returned temperature data status [HTS221_SET/HTS221_RESET]. +* This parameter is a pointer to @ref HTS221_BitStatus_et. +* @retval Error code [HTS221_OK, HTS221_ERROR]. +*/ +HTS221_Error_et HTS221_Get_DataStatus(void *handle, HTS221_BitStatus_et* humidity, HTS221_BitStatus_et* temperature) +{ + uint8_t tmp; + + if(HTS221_read_reg(handle, HTS221_STATUS_REG, 1, &tmp)) + return HTS221_ERROR; + + *humidity = (HTS221_BitStatus_et)((tmp & HTS221_HDA_MASK) >> HTS221_H_DA_BIT); + *temperature = (HTS221_BitStatus_et)(tmp & HTS221_TDA_MASK); + + return HTS221_OK; +} + +/** +* @brief Exit from power down mode. +* @param *handle Device handle. +* @param void. +* @retval Error code [HTS221_OK, HTS221_ERROR]. +*/ +HTS221_Error_et HTS221_Activate(void *handle) +{ + uint8_t tmp; + + if(HTS221_read_reg(handle, HTS221_CTRL_REG1, 1, &tmp)) + return HTS221_ERROR; + + tmp |= HTS221_PD_MASK; + + if(HTS221_write_reg(handle, HTS221_CTRL_REG1, 1, &tmp)) + return HTS221_ERROR; + + return HTS221_OK; +} + +/** +* @brief Put the sensor in power down mode. +* @param *handle Device handle. +* @retval Error code [HTS221_OK, HTS221_ERROR]. +*/ +HTS221_Error_et HTS221_DeActivate(void *handle) +{ + uint8_t tmp; + + if(HTS221_read_reg(handle, HTS221_CTRL_REG1, 1, &tmp)) + return HTS221_ERROR; + + tmp &= ~HTS221_PD_MASK; + + if(HTS221_write_reg(handle, HTS221_CTRL_REG1, 1, &tmp)) + return HTS221_ERROR; + + return HTS221_OK; +} + + + +/** +* @brief Check if the single measurement has completed. +* @param *handle Device handle. +* @param tmp is set to 1, when the measure is completed +* @retval Status [HTS221_ERROR, HTS221_OK] +*/ +HTS221_Error_et HTS221_IsMeasurementCompleted(void *handle, HTS221_BitStatus_et* Is_Measurement_Completed) +{ + uint8_t tmp; + + if(HTS221_read_reg(handle, HTS221_STATUS_REG, 1, &tmp)) + return HTS221_ERROR; + + if((tmp & (uint8_t)(HTS221_HDA_MASK | HTS221_TDA_MASK)) == (uint8_t)(HTS221_HDA_MASK | HTS221_TDA_MASK)) + *Is_Measurement_Completed = HTS221_SET; + else + *Is_Measurement_Completed = HTS221_RESET; + + return HTS221_OK; +} + + +/** +* @brief Set_ humidity and temperature average mode. +* @param *handle Device handle. +* @param avgh is the average mode for humidity, this parameter is @ref HTS221_Avgh_et. +* @param avgt is the average mode for temperature, this parameter is @ref HTS221_Avgt_et. +* @retval Error code [HTS221_OK, HTS221_ERROR]. +*/ +HTS221_Error_et HTS221_Set_AvgHT(void *handle, HTS221_Avgh_et avgh, HTS221_Avgt_et avgt) +{ + uint8_t tmp; + + HTS221_assert_param(IS_HTS221_AVGH(avgh)); + HTS221_assert_param(IS_HTS221_AVGT(avgt)); + + if(HTS221_read_reg(handle, HTS221_AV_CONF_REG, 1, &tmp)) + return HTS221_ERROR; + + tmp &= ~(HTS221_AVGH_MASK | HTS221_AVGT_MASK); + tmp |= (uint8_t)avgh; + tmp |= (uint8_t)avgt; + + if(HTS221_write_reg(handle, HTS221_AV_CONF_REG, 1, &tmp)) + return HTS221_ERROR; + + return HTS221_OK; +} + +/** +* @brief Set humidity average mode. +* @param *handle Device handle. +* @param avgh is the average mode for humidity, this parameter is @ref HTS221_Avgh_et. +* @retval Error code [HTS221_OK, HTS221_ERROR]. +*/ +HTS221_Error_et HTS221_Set_AvgH(void *handle, HTS221_Avgh_et avgh) +{ + uint8_t tmp; + + HTS221_assert_param(IS_HTS221_AVGH(avgh)); + + if(HTS221_read_reg(handle, HTS221_AV_CONF_REG, 1, &tmp)) + return HTS221_ERROR; + + tmp &= ~HTS221_AVGH_MASK; + tmp |= (uint8_t)avgh; + + if(HTS221_write_reg(handle, HTS221_AV_CONF_REG, 1, &tmp)) + return HTS221_ERROR; + + return HTS221_OK; +} + +/** +* @brief Set temperature average mode. +* @param *handle Device handle. +* @param avgt is the average mode for temperature, this parameter is @ref HTS221_Avgt_et. +* @retval Error code [HTS221_OK, HTS221_ERROR]. +*/ +HTS221_Error_et HTS221_Set_AvgT(void *handle, HTS221_Avgt_et avgt) +{ + uint8_t tmp; + + HTS221_assert_param(IS_HTS221_AVGT(avgt)); + + if(HTS221_read_reg(handle, HTS221_AV_CONF_REG, 1, &tmp)) + return HTS221_ERROR; + + tmp &= ~HTS221_AVGT_MASK; + tmp |= (uint8_t)avgt; + + if(HTS221_write_reg(handle, HTS221_AV_CONF_REG, 1, &tmp)) + return HTS221_ERROR; + + return HTS221_OK; +} + +/** +* @brief Get humidity and temperature average mode. +* @param *handle Device handle. +* @param avgh pointer to the returned value with the humidity average mode. +* @param avgt pointer to the returned value with the temperature average mode. +* @retval Error code [HTS221_OK, HTS221_ERROR]. +*/ +HTS221_Error_et HTS221_Get_AvgHT(void *handle, HTS221_Avgh_et* avgh, HTS221_Avgt_et* avgt) +{ + uint8_t tmp; + + if(HTS221_read_reg(handle, HTS221_AV_CONF_REG, 1, &tmp)) + return HTS221_ERROR; + + *avgh = (HTS221_Avgh_et)(tmp & HTS221_AVGH_MASK); + *avgt = (HTS221_Avgt_et)(tmp & HTS221_AVGT_MASK); + + return HTS221_OK; +} + +/** +* @brief Set block data update mode. +* @param *handle Device handle. +* @param status can be HTS221_ENABLE: enable the block data update, output data registers are updated once both MSB and LSB are read. +* @param status can be HTS221_DISABLE: output data registers are continuously updated. +* This parameter is a @ref HTS221_BitStatus_et. +* @retval Error code [HTS221_OK, HTS221_ERROR]. +*/ +HTS221_Error_et HTS221_Set_BduMode(void *handle, HTS221_State_et status) +{ + uint8_t tmp; + + HTS221_assert_param(IS_HTS221_State(status)); + + if(HTS221_read_reg(handle, HTS221_CTRL_REG1, 1, &tmp)) + return HTS221_ERROR; + + tmp &= ~HTS221_BDU_MASK; + tmp |= ((uint8_t)status) << HTS221_BDU_BIT; + + if(HTS221_write_reg(handle, HTS221_CTRL_REG1, 1, &tmp)) + return HTS221_ERROR; + + return HTS221_OK; +} + +/** +* @brief Get block data update mode. +* @param *handle Device handle. +* @param Pointer to the returned value with block data update mode status. +* @retval Error code [HTS221_OK, HTS221_ERROR]. +*/ +HTS221_Error_et HTS221_Get_BduMode(void *handle, HTS221_State_et* status) +{ + uint8_t tmp; + + if(HTS221_read_reg(handle, HTS221_CTRL_REG1, 1, &tmp)) + return HTS221_ERROR; + + *status = (HTS221_State_et)((tmp & HTS221_BDU_MASK) >> HTS221_BDU_BIT); + + return HTS221_OK; +} + +/** +* @brief Enter or exit from power down mode. +* @param *handle Device handle. +* @param status can be HTS221_SET: HTS221 in power down mode. +* @param status can be HTS221_REET: HTS221 in active mode. +* This parameter is a @ref HTS221_BitStatus_et. +* @retval Error code [HTS221_OK, HTS221_ERROR]. +*/ +HTS221_Error_et HTS221_Set_PowerDownMode(void *handle, HTS221_BitStatus_et status) +{ + uint8_t tmp; + + HTS221_assert_param(IS_HTS221_BitStatus(status)); + + if(HTS221_read_reg(handle, HTS221_CTRL_REG1, 1, &tmp)) + return HTS221_ERROR; + + tmp &= ~HTS221_PD_MASK; + tmp |= ((uint8_t)status) << HTS221_PD_BIT; + + if(HTS221_write_reg(handle, HTS221_CTRL_REG1, 1, &tmp)) + return HTS221_ERROR; + + return HTS221_OK; +} + +/** +* @brief Get if HTS221 is in active mode or in power down mode. +* @param *handle Device handle. +* @param Pointer to the returned value with HTS221 status. +* @retval Error code [HTS221_OK, HTS221_ERROR]. +*/ +HTS221_Error_et HTS221_Get_PowerDownMode(void *handle, HTS221_BitStatus_et* status) +{ + uint8_t tmp; + + if(HTS221_read_reg(handle, HTS221_CTRL_REG1, 1, &tmp)) + return HTS221_ERROR; + + *status = (HTS221_BitStatus_et)((tmp & HTS221_PD_MASK) >> HTS221_PD_BIT); + + return HTS221_OK; +} + +/** +* @brief Set the output data rate mode. +* @param *handle Device handle. +* @param odr is the output data rate mode. +* This parameter is a @ref HTS221_Odr_et. +* @retval Error code [HTS221_OK, HTS221_ERROR]. +*/ +HTS221_Error_et HTS221_Set_Odr(void *handle, HTS221_Odr_et odr) +{ + uint8_t tmp; + + HTS221_assert_param(IS_HTS221_ODR(odr)); + + if(HTS221_read_reg(handle, HTS221_CTRL_REG1, 1, &tmp)) + return HTS221_ERROR; + + tmp &= ~HTS221_ODR_MASK; + tmp |= (uint8_t)odr; + + if(HTS221_write_reg(handle, HTS221_CTRL_REG1, 1, &tmp)) + return HTS221_ERROR; + + return HTS221_OK; +} + +/** +* @brief Get the output data rate mode. +* @param *handle Device handle. +* @param Pointer to the returned value with output data rate mode. +* @retval Error code [HTS221_OK, HTS221_ERROR]. +*/ +HTS221_Error_et HTS221_Get_Odr(void *handle, HTS221_Odr_et* odr) +{ + uint8_t tmp; + + if(HTS221_read_reg(handle, HTS221_CTRL_REG1, 1, &tmp)) + return HTS221_ERROR; + + tmp &= HTS221_ODR_MASK; + *odr = (HTS221_Odr_et)tmp; + + return HTS221_OK; +} + +/** +* @brief Reboot Memory Content. +* @param *handle Device handle. +* @retval Error code [HTS221_OK, HTS221_ERROR]. +*/ +HTS221_Error_et HTS221_MemoryBoot(void *handle) +{ + uint8_t tmp; + + if(HTS221_read_reg(handle, HTS221_CTRL_REG2, 1, &tmp)) + return HTS221_ERROR; + + tmp |= HTS221_BOOT_MASK; + + if(HTS221_write_reg(handle, HTS221_CTRL_REG2, 1, &tmp)) + return HTS221_ERROR; + + return HTS221_OK; +} + +/** +* @brief Configure the internal heater. +* @param *handle Device handle. +* @param The status of the internal heater [HTS221_ENABLE/HTS221_DISABLE]. +* This parameter is a @ref HTS221_State_et. +* @retval Error code [HTS221_OK, HTS221_ERROR] +*/ +HTS221_Error_et HTS221_Set_HeaterState(void *handle, HTS221_State_et status) +{ + uint8_t tmp; + + HTS221_assert_param(IS_HTS221_State(status)); + + if(HTS221_read_reg(handle, HTS221_CTRL_REG2, 1, &tmp)) + return HTS221_ERROR; + + tmp &= ~HTS221_HEATHER_MASK; + tmp |= ((uint8_t)status) << HTS221_HEATHER_BIT; + + if(HTS221_write_reg(handle, HTS221_CTRL_REG2, 1, &tmp)) + return HTS221_ERROR; + + return HTS221_OK; +} + +/** +* @brief Get the internal heater. +* @param *handle Device handle. +* @param Pointer to the returned status of the internal heater [HTS221_ENABLE/HTS221_DISABLE]. +* @retval Error code [HTS221_OK, HTS221_ERROR]. +*/ +HTS221_Error_et HTS221_Get_HeaterState(void *handle, HTS221_State_et* status) +{ + uint8_t tmp; + + if(HTS221_read_reg(handle, HTS221_CTRL_REG2, 1, &tmp)) + return HTS221_ERROR; + + *status = (HTS221_State_et)((tmp & HTS221_HEATHER_MASK) >> HTS221_HEATHER_BIT); + + return HTS221_OK; +} + +/** +* @brief Set ONE_SHOT bit to start a new conversion (ODR mode has to be 00). +* Once the measurement is done, ONE_SHOT bit is self-cleared. +* @param *handle Device handle. +* @retval Error code [HTS221_OK, HTS221_ERROR]. +*/ +HTS221_Error_et HTS221_StartOneShotMeasurement(void *handle) +{ + uint8_t tmp; + + if(HTS221_read_reg(handle, HTS221_CTRL_REG2, 1, &tmp)) + return HTS221_ERROR; + + tmp |= HTS221_ONE_SHOT_MASK; + + if(HTS221_write_reg(handle, HTS221_CTRL_REG2, 1, &tmp)) + return HTS221_ERROR; + + return HTS221_OK; + +} + +/** +* @brief Set level configuration of the interrupt pin DRDY. +* @param *handle Device handle. +* @param status can be HTS221_LOW_LVL: active level is LOW. +* @param status can be HTS221_HIGH_LVL: active level is HIGH. +* This parameter is a @ref HTS221_State_et. +* @retval Error code [HTS221_OK, HTS221_ERROR]. +*/ +HTS221_Error_et HTS221_Set_IrqActiveLevel(void *handle, HTS221_DrdyLevel_et value) +{ + uint8_t tmp; + + HTS221_assert_param(IS_HTS221_DrdyLevelType(value)); + + if(HTS221_read_reg(handle, HTS221_CTRL_REG3, 1, &tmp)) + return HTS221_ERROR; + + tmp &= ~HTS221_DRDY_H_L_MASK; + tmp |= (uint8_t)value; + + if(HTS221_write_reg(handle, HTS221_CTRL_REG3, 1, &tmp)) + return HTS221_ERROR; + + return HTS221_OK; +} + +/** +* @brief Get level configuration of the interrupt pin DRDY. +* @param *handle Device handle. +* @param Pointer to the returned status of the level configuration [HTS221_ENABLE/HTS221_DISABLE]. +* @retval Error code [HTS221_OK, HTS221_ERROR]. +*/ +HTS221_Error_et HTS221_Get_IrqActiveLevel(void *handle, HTS221_DrdyLevel_et* value) +{ + uint8_t tmp; + + if(HTS221_read_reg(handle, HTS221_CTRL_REG3, 1, &tmp)) + return HTS221_ERROR; + + *value = (HTS221_DrdyLevel_et)(tmp & HTS221_DRDY_H_L_MASK); + + return HTS221_OK; +} + +/** +* @brief Set Push-pull/open drain configuration for the interrupt pin DRDY. +* @param *handle Device handle. +* @param value is the output type configuration. +* This parameter is a @ref HTS221_OutputType_et. +* @retval Error code [HTS221_OK, HTS221_ERROR]. +*/ +HTS221_Error_et HTS221_Set_IrqOutputType(void *handle, HTS221_OutputType_et value) +{ + uint8_t tmp; + + HTS221_assert_param(IS_HTS221_OutputType(value)); + + if(HTS221_read_reg(handle, HTS221_CTRL_REG3, 1, &tmp)) + return HTS221_ERROR; + + tmp &= ~HTS221_PP_OD_MASK; + tmp |= (uint8_t)value; + + if(HTS221_write_reg(handle, HTS221_CTRL_REG3, 1, &tmp)) + return HTS221_ERROR; + + return HTS221_OK; +} + +/** +* @brief Get the configuration for the interrupt pin DRDY. +* @param *handle Device handle. +* @param Pointer to the returned value with output type configuration. +* @retval Error code [HTS221_OK, HTS221_ERROR]. +*/ +HTS221_Error_et HTS221_Get_IrqOutputType(void *handle, HTS221_OutputType_et* value) +{ + uint8_t tmp; + + if(HTS221_read_reg(handle, HTS221_CTRL_REG3, 1, &tmp)) + return HTS221_ERROR; + + *value = (HTS221_OutputType_et)(tmp & HTS221_PP_OD_MASK); + + return HTS221_OK; +} + +/** +* @brief Enable/disable the interrupt mode. +* @param *handle Device handle. +* @param status is the enable/disable for the interrupt mode. +* This parameter is a @ref HTS221_State_et. +* @retval Error code [HTS221_OK, HTS221_ERROR]. +*/ +HTS221_Error_et HTS221_Set_IrqEnable(void *handle, HTS221_State_et status) +{ + uint8_t tmp; + + HTS221_assert_param(IS_HTS221_State(status)); + + if(HTS221_read_reg(handle, HTS221_CTRL_REG3, 1, &tmp)) + return HTS221_ERROR; + + tmp &= ~HTS221_DRDY_MASK; + tmp |= ((uint8_t)status) << HTS221_DRDY_BIT; + + if(HTS221_write_reg(handle, HTS221_CTRL_REG3, 1, &tmp)) + return HTS221_ERROR; + + return HTS221_OK; +} + +/** +* @brief Get the interrupt mode. +* @param *handle Device handle. +* @param Pointer to the returned status of the interrupt mode configuration [HTS221_ENABLE/HTS221_DISABLE]. +* @retval Error code [HTS221_OK, HTS221_ERROR]. +*/ +HTS221_Error_et HTS221_Get_IrqEnable(void *handle, HTS221_State_et* status) +{ + uint8_t tmp; + + if(HTS221_read_reg(handle, HTS221_CTRL_REG3, 1, &tmp)) + return HTS221_ERROR; + + *status = (HTS221_State_et)((tmp & HTS221_DRDY_MASK) >> HTS221_DRDY_BIT); + + return HTS221_OK; +} + + +#ifdef USE_FULL_ASSERT_HTS221 +/** +* @brief Reports the name of the source file and the source line number +* where the assert_param error has occurred. +* @param file: pointer to the source file name +* @param line: assert_param error line source number +* @retval : None +*/ +void HTS221_assert_failed(uint8_t* file, uint32_t line) +{ + /* User can add his own implementation to report the file name and line number */ + printf("Wrong parameters value: file %s on line %d\r\n", file, (int)line); + + /* Infinite loop */ + while (1) + { + } +} +#endif + +#ifdef __cplusplus + } +#endif + +/** +* @} +*/ + +/** +* @} +*/ + +/** +* @} +*/ + +/******************* (C) COPYRIGHT 2013 STMicroelectronics *****END OF FILE****/
diff -r 000000000000 -r 98c301bb7d1b Components/HTS221Sensor/HTS221_driver.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Components/HTS221Sensor/HTS221_driver.h Tue Oct 03 12:21:11 2017 +0000 @@ -0,0 +1,514 @@ +/** + ****************************************************************************** + * @file HTS221_driver.h + * @author HESA Application Team + * @version V1.1 + * @date 10-August-2016 + * @brief HTS221 driver header file + ****************************************************************************** + * @attention + * + * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of STMicroelectronics nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************** + */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __HTS221_DRIVER__H +#define __HTS221_DRIVER__H + +#include <stdint.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/* Uncomment the line below to expanse the "assert_param" macro in the drivers code */ +#define USE_FULL_ASSERT_HTS221 + +/* Exported macro ------------------------------------------------------------*/ +#ifdef USE_FULL_ASSERT_HTS221 + +/** +* @brief The assert_param macro is used for function's parameters check. +* @param expr: If expr is false, it calls assert_failed function which reports +* the name of the source file and the source line number of the call +* that failed. If expr is true, it returns no value. +* @retval None +*/ +#define HTS221_assert_param(expr) ((expr) ? (void)0 : HTS221_assert_failed((uint8_t *)__FILE__, __LINE__)) +/* Exported functions ------------------------------------------------------- */ +void HTS221_assert_failed(uint8_t* file, uint32_t line); +#else +#define HTS221_assert_param(expr) ((void)0) +#endif /* USE_FULL_ASSERT_HTS221 */ + +/** @addtogroup Environmental_Sensor +* @{ +*/ + +/** @addtogroup HTS221_DRIVER +* @{ +*/ + +/* Exported Types -------------------------------------------------------------*/ +/** @defgroup HTS221_Exported_Types +* @{ +*/ + + +/** +* @brief Error code type. +*/ +typedef enum {HTS221_OK = (uint8_t)0, HTS221_ERROR = !HTS221_OK} HTS221_Error_et; + +/** +* @brief State type. +*/ +typedef enum {HTS221_DISABLE = (uint8_t)0, HTS221_ENABLE = !HTS221_DISABLE} HTS221_State_et; +#define IS_HTS221_State(MODE) ((MODE == HTS221_ENABLE) || (MODE == HTS221_DISABLE)) + +/** +* @brief Bit status type. +*/ +typedef enum {HTS221_RESET = (uint8_t)0, HTS221_SET = !HTS221_RESET} HTS221_BitStatus_et; +#define IS_HTS221_BitStatus(MODE) ((MODE == HTS221_RESET) || (MODE == HTS221_SET)) + +/** +* @brief Humidity average. +*/ +typedef enum +{ + HTS221_AVGH_4 = (uint8_t)0x00, /*!< Internal average on 4 samples */ + HTS221_AVGH_8 = (uint8_t)0x01, /*!< Internal average on 8 samples */ + HTS221_AVGH_16 = (uint8_t)0x02, /*!< Internal average on 16 samples */ + HTS221_AVGH_32 = (uint8_t)0x03, /*!< Internal average on 32 samples */ + HTS221_AVGH_64 = (uint8_t)0x04, /*!< Internal average on 64 samples */ + HTS221_AVGH_128 = (uint8_t)0x05, /*!< Internal average on 128 samples */ + HTS221_AVGH_256 = (uint8_t)0x06, /*!< Internal average on 256 samples */ + HTS221_AVGH_512 = (uint8_t)0x07 /*!< Internal average on 512 samples */ +} HTS221_Avgh_et; +#define IS_HTS221_AVGH(AVGH) ((AVGH == HTS221_AVGH_4) || (AVGH == HTS221_AVGH_8) || \ + (AVGH == HTS221_AVGH_16) || (AVGH == HTS221_AVGH_32) || \ + (AVGH == HTS221_AVGH_64) || (AVGH == HTS221_AVGH_128) || \ + (AVGH == HTS221_AVGH_256) || (AVGH == HTS221_AVGH_512)) + +/** +* @brief Temperature average. +*/ +typedef enum +{ + HTS221_AVGT_2 = (uint8_t)0x00, /*!< Internal average on 2 samples */ + HTS221_AVGT_4 = (uint8_t)0x08, /*!< Internal average on 4 samples */ + HTS221_AVGT_8 = (uint8_t)0x10, /*!< Internal average on 8 samples */ + HTS221_AVGT_16 = (uint8_t)0x18, /*!< Internal average on 16 samples */ + HTS221_AVGT_32 = (uint8_t)0x20, /*!< Internal average on 32 samples */ + HTS221_AVGT_64 = (uint8_t)0x28, /*!< Internal average on 64 samples */ + HTS221_AVGT_128 = (uint8_t)0x30, /*!< Internal average on 128 samples */ + HTS221_AVGT_256 = (uint8_t)0x38 /*!< Internal average on 256 samples */ +} HTS221_Avgt_et; +#define IS_HTS221_AVGT(AVGT) ((AVGT == HTS221_AVGT_2) || (AVGT == HTS221_AVGT_4) || \ + (AVGT == HTS221_AVGT_8) || (AVGT == HTS221_AVGT_16) || \ + (AVGT == HTS221_AVGT_32) || (AVGT == HTS221_AVGT_64) || \ + (AVGT == HTS221_AVGT_128) || (AVGT == HTS221_AVGT_256)) + +/** +* @brief Output data rate configuration. +*/ +typedef enum +{ + HTS221_ODR_ONE_SHOT = (uint8_t)0x00, /*!< Output Data Rate: one shot */ + HTS221_ODR_1HZ = (uint8_t)0x01, /*!< Output Data Rate: 1Hz */ + HTS221_ODR_7HZ = (uint8_t)0x02, /*!< Output Data Rate: 7Hz */ + HTS221_ODR_12_5HZ = (uint8_t)0x03, /*!< Output Data Rate: 12.5Hz */ +} HTS221_Odr_et; +#define IS_HTS221_ODR(ODR) ((ODR == HTS221_ODR_ONE_SHOT) || (ODR == HTS221_ODR_1HZ) || \ + (ODR == HTS221_ODR_7HZ) || (ODR == HTS221_ODR_12_5HZ)) + + +/** +* @brief Push-pull/Open Drain selection on DRDY pin. +*/ +typedef enum +{ + HTS221_PUSHPULL = (uint8_t)0x00, /*!< DRDY pin in push pull */ + HTS221_OPENDRAIN = (uint8_t)0x40 /*!< DRDY pin in open drain */ +} HTS221_OutputType_et; +#define IS_HTS221_OutputType(MODE) ((MODE == HTS221_PUSHPULL) || (MODE == HTS221_OPENDRAIN)) + +/** +* @brief Active level of DRDY pin. +*/ +typedef enum +{ + HTS221_HIGH_LVL = (uint8_t)0x00, /*!< HIGH state level for DRDY pin */ + HTS221_LOW_LVL = (uint8_t)0x80 /*!< LOW state level for DRDY pin */ +} HTS221_DrdyLevel_et; +#define IS_HTS221_DrdyLevelType(MODE) ((MODE == HTS221_HIGH_LVL) || (MODE == HTS221_LOW_LVL)) + +/** +* @brief Driver Version Info structure definition. +*/ +typedef struct +{ + uint8_t Major; + uint8_t Minor; + uint8_t Point; +} HTS221_DriverVersion_st; + + +/** +* @brief HTS221 Init structure definition. +*/ +typedef struct +{ + HTS221_Avgh_et avg_h; /*!< Humidity average */ + HTS221_Avgt_et avg_t; /*!< Temperature average */ + HTS221_Odr_et odr; /*!< Output data rate */ + HTS221_State_et bdu_status; /*!< HTS221_ENABLE/HTS221_DISABLE the block data update */ + HTS221_State_et heater_status; /*!< HTS221_ENABLE/HTS221_DISABLE the internal heater */ + + HTS221_DrdyLevel_et irq_level; /*!< HTS221_HIGH_LVL/HTS221_LOW_LVL the level for DRDY pin */ + HTS221_OutputType_et irq_output_type; /*!< Output configuration for DRDY pin */ + HTS221_State_et irq_enable; /*!< HTS221_ENABLE/HTS221_DISABLE interrupt on DRDY pin */ +} HTS221_Init_st; + +/** +* @} +*/ + + +/* Exported Constants ---------------------------------------------------------*/ +/** @defgroup HTS221_Exported_Constants +* @{ +*/ + +/** +* @brief Bitfield positioning. +*/ +#define HTS221_BIT(x) ((uint8_t)x) + +/** +* @brief I2C address. +*/ +#define HTS221_I2C_ADDRESS (uint8_t)0xBE + +/** +* @brief Driver version. +*/ +#define HTS221_DRIVER_VERSION_MAJOR (uint8_t)1 +#define HTS221_DRIVER_VERSION_MINOR (uint8_t)1 +#define HTS221_DRIVER_VERSION_POINT (uint8_t)0 + +/** +* @addtogroup HTS221_Registers +* @{ +*/ + + +/** +* @brief Device Identification register. +* \code +* Read +* Default value: 0xBC +* 7:0 This read-only register contains the device identifier for HTS221. +* \endcode +*/ +#define HTS221_WHO_AM_I_REG (uint8_t)0x0F + +/** +* @brief Device Identification value. +*/ +#define HTS221_WHO_AM_I_VAL (uint8_t)0xBC + + +/** +* @brief Humidity and temperature average mode register. +* \code +* Read/write +* Default value: 0x1B +* 7:6 Reserved. +* 5:3 AVGT2-AVGT1-AVGT0: Select the temperature internal average. +* +* AVGT2 | AVGT1 | AVGT0 | Nr. Internal Average +* ---------------------------------------------------- +* 0 | 0 | 0 | 2 +* 0 | 0 | 1 | 4 +* 0 | 1 | 0 | 8 +* 0 | 1 | 1 | 16 +* 1 | 0 | 0 | 32 +* 1 | 0 | 1 | 64 +* 1 | 1 | 0 | 128 +* 1 | 1 | 1 | 256 +* +* 2:0 AVGH2-AVGH1-AVGH0: Select humidity internal average. +* AVGH2 | AVGH1 | AVGH0 | Nr. Internal Average +* ------------------------------------------------------ +* 0 | 0 | 0 | 4 +* 0 | 0 | 1 | 8 +* 0 | 1 | 0 | 16 +* 0 | 1 | 1 | 32 +* 1 | 0 | 0 | 64 +* 1 | 0 | 1 | 128 +* 1 | 1 | 0 | 256 +* 1 | 1 | 1 | 512 +* +* \endcode +*/ +#define HTS221_AV_CONF_REG (uint8_t)0x10 + +#define HTS221_AVGT_BIT HTS221_BIT(3) +#define HTS221_AVGH_BIT HTS221_BIT(0) + +#define HTS221_AVGH_MASK (uint8_t)0x07 +#define HTS221_AVGT_MASK (uint8_t)0x38 + +/** +* @brief Control register 1. +* \code +* Read/write +* Default value: 0x00 +* 7 PD: power down control. 0 - power down mode; 1 - active mode. +* 6:3 Reserved. +* 2 BDU: block data update. 0 - continuous update; 1 - output registers not updated until MSB and LSB reading. +* 1:0 ODR1, ODR0: output data rate selection. +* +* ODR1 | ODR0 | Humidity output data-rate(Hz) | Pressure output data-rate(Hz) +* ---------------------------------------------------------------------------------- +* 0 | 0 | one shot | one shot +* 0 | 1 | 1 | 1 +* 1 | 0 | 7 | 7 +* 1 | 1 | 12.5 | 12.5 +* +* \endcode +*/ +#define HTS221_CTRL_REG1 (uint8_t)0x20 + +#define HTS221_PD_BIT HTS221_BIT(7) +#define HTS221_BDU_BIT HTS221_BIT(2) +#define HTS221_ODR_BIT HTS221_BIT(0) + +#define HTS221_PD_MASK (uint8_t)0x80 +#define HTS221_BDU_MASK (uint8_t)0x04 +#define HTS221_ODR_MASK (uint8_t)0x03 + +/** +* @brief Control register 2. +* \code +* Read/write +* Default value: 0x00 +* 7 BOOT: Reboot memory content. 0: normal mode; 1: reboot memory content. Self-cleared upon completation. +* 6:2 Reserved. +* 1 HEATHER: 0: heater enable; 1: heater disable. +* 0 ONE_SHOT: 0: waiting for start of conversion; 1: start for a new dataset. Self-cleared upon completation. +* \endcode +*/ +#define HTS221_CTRL_REG2 (uint8_t)0x21 + +#define HTS221_BOOT_BIT HTS221_BIT(7) +#define HTS221_HEATHER_BIT HTS221_BIT(1) +#define HTS221_ONESHOT_BIT HTS221_BIT(0) + +#define HTS221_BOOT_MASK (uint8_t)0x80 +#define HTS221_HEATHER_MASK (uint8_t)0x02 +#define HTS221_ONE_SHOT_MASK (uint8_t)0x01 + +/** +* @brief Control register 3. +* \code +* Read/write +* Default value: 0x00 +* 7 DRDY_H_L: Interrupt edge. 0: active high, 1: active low. +* 6 PP_OD: Push-Pull/OpenDrain selection on interrupt pads. 0: push-pull; 1: open drain. +* 5:3 Reserved. +* 2 DRDY: interrupt config. 0: disable, 1: enable. +* \endcode +*/ +#define HTS221_CTRL_REG3 (uint8_t)0x22 + +#define HTS221_DRDY_H_L_BIT HTS221_BIT(7) +#define HTS221_PP_OD_BIT HTS221_BIT(6) +#define HTS221_DRDY_BIT HTS221_BIT(2) + +#define HTS221_DRDY_H_L_MASK (uint8_t)0x80 +#define HTS221_PP_OD_MASK (uint8_t)0x40 +#define HTS221_DRDY_MASK (uint8_t)0x04 + +/** +* @brief Status register. +* \code +* Read +* Default value: 0x00 +* 7:2 Reserved. +* 1 H_DA: Humidity data available. 0: new data for humidity is not yet available; 1: new data for humidity is available. +* 0 T_DA: Temperature data available. 0: new data for temperature is not yet available; 1: new data for temperature is available. +* \endcode +*/ +#define HTS221_STATUS_REG (uint8_t)0x27 + +#define HTS221_H_DA_BIT HTS221_BIT(1) +#define HTS221_T_DA_BIT HTS221_BIT(0) + +#define HTS221_HDA_MASK (uint8_t)0x02 +#define HTS221_TDA_MASK (uint8_t)0x01 + +/** +* @brief Humidity data (LSB). +* \code +* Read +* Default value: 0x00. +* HOUT7 - HOUT0: Humidity data LSB (2's complement). +* \endcode +*/ +#define HTS221_HR_OUT_L_REG (uint8_t)0x28 + +/** +* @brief Humidity data (MSB). +* \code +* Read +* Default value: 0x00. +* HOUT15 - HOUT8: Humidity data MSB (2's complement). +* \endcode +*/ +#define HTS221_HR_OUT_H_REG (uint8_t)0x29 + + +/** +* @brief Temperature data (LSB). +* \code +* Read +* Default value: 0x00. +* TOUT7 - TOUT0: temperature data LSB. +* \endcode +*/ +#define HTS221_TEMP_OUT_L_REG (uint8_t)0x2A + +/** +* @brief Temperature data (MSB). +* \code +* Read +* Default value: 0x00. +* TOUT15 - TOUT8: temperature data MSB. +* \endcode +*/ +#define HTS221_TEMP_OUT_H_REG (uint8_t)0x2B + +/** +* @brief Calibration registers. +* \code +* Read +* \endcode +*/ +#define HTS221_H0_RH_X2 (uint8_t)0x30 +#define HTS221_H1_RH_X2 (uint8_t)0x31 +#define HTS221_T0_DEGC_X8 (uint8_t)0x32 +#define HTS221_T1_DEGC_X8 (uint8_t)0x33 +#define HTS221_T0_T1_DEGC_H2 (uint8_t)0x35 +#define HTS221_H0_T0_OUT_L (uint8_t)0x36 +#define HTS221_H0_T0_OUT_H (uint8_t)0x37 +#define HTS221_H1_T0_OUT_L (uint8_t)0x3A +#define HTS221_H1_T0_OUT_H (uint8_t)0x3B +#define HTS221_T0_OUT_L (uint8_t)0x3C +#define HTS221_T0_OUT_H (uint8_t)0x3D +#define HTS221_T1_OUT_L (uint8_t)0x3E +#define HTS221_T1_OUT_H (uint8_t)0x3F + + +/** +* @} +*/ + + +/** +* @} +*/ + + +/* Exported Functions -------------------------------------------------------------*/ +/** @defgroup HTS221_Exported_Functions +* @{ +*/ + +HTS221_Error_et HTS221_read_reg( void *handle, uint8_t RegAddr, uint16_t NumByteToRead, uint8_t *Data ); +HTS221_Error_et HTS221_write_reg( void *handle, uint8_t RegAddr, uint16_t NumByteToWrite, uint8_t *Data ); + +HTS221_Error_et HTS221_Get_DriverVersion(HTS221_DriverVersion_st* version); +HTS221_Error_et HTS221_Get_DeviceID(void *handle, uint8_t* deviceid); + +HTS221_Error_et HTS221_Set_InitConfig(void *handle, HTS221_Init_st* pxInit); +HTS221_Error_et HTS221_Get_InitConfig(void *handle, HTS221_Init_st* pxInit); +HTS221_Error_et HTS221_DeInit(void *handle); +HTS221_Error_et HTS221_IsMeasurementCompleted(void *handle, HTS221_BitStatus_et* Is_Measurement_Completed); + +HTS221_Error_et HTS221_Get_Measurement(void *handle, uint16_t* humidity, int16_t* temperature); +HTS221_Error_et HTS221_Get_RawMeasurement(void *handle, int16_t* humidity, int16_t* temperature); +HTS221_Error_et HTS221_Get_Humidity(void *handle, uint16_t* value); +HTS221_Error_et HTS221_Get_HumidityRaw(void *handle, int16_t* value); +HTS221_Error_et HTS221_Get_TemperatureRaw(void *handle, int16_t* value); +HTS221_Error_et HTS221_Get_Temperature(void *handle, int16_t* value); +HTS221_Error_et HTS221_Get_DataStatus(void *handle, HTS221_BitStatus_et* humidity, HTS221_BitStatus_et* temperature); +HTS221_Error_et HTS221_Activate(void *handle); +HTS221_Error_et HTS221_DeActivate(void *handle); + +HTS221_Error_et HTS221_Set_AvgHT(void *handle, HTS221_Avgh_et avgh, HTS221_Avgt_et avgt); +HTS221_Error_et HTS221_Set_AvgH(void *handle, HTS221_Avgh_et avgh); +HTS221_Error_et HTS221_Set_AvgT(void *handle, HTS221_Avgt_et avgt); +HTS221_Error_et HTS221_Get_AvgHT(void *handle, HTS221_Avgh_et* avgh, HTS221_Avgt_et* avgt); +HTS221_Error_et HTS221_Set_BduMode(void *handle, HTS221_State_et status); +HTS221_Error_et HTS221_Get_BduMode(void *handle, HTS221_State_et* status); +HTS221_Error_et HTS221_Set_PowerDownMode(void *handle, HTS221_BitStatus_et status); +HTS221_Error_et HTS221_Get_PowerDownMode(void *handle, HTS221_BitStatus_et* status); +HTS221_Error_et HTS221_Set_Odr(void *handle, HTS221_Odr_et odr); +HTS221_Error_et HTS221_Get_Odr(void *handle, HTS221_Odr_et* odr); +HTS221_Error_et HTS221_MemoryBoot(void *handle); +HTS221_Error_et HTS221_Set_HeaterState(void *handle, HTS221_State_et status); +HTS221_Error_et HTS221_Get_HeaterState(void *handle, HTS221_State_et* status); +HTS221_Error_et HTS221_StartOneShotMeasurement(void *handle); +HTS221_Error_et HTS221_Set_IrqActiveLevel(void *handle, HTS221_DrdyLevel_et status); +HTS221_Error_et HTS221_Get_IrqActiveLevel(void *handle, HTS221_DrdyLevel_et* status); +HTS221_Error_et HTS221_Set_IrqOutputType(void *handle, HTS221_OutputType_et value); +HTS221_Error_et HTS221_Get_IrqOutputType(void *handle, HTS221_OutputType_et* value); +HTS221_Error_et HTS221_Set_IrqEnable(void *handle, HTS221_State_et status); +HTS221_Error_et HTS221_Get_IrqEnable(void *handle, HTS221_State_et* status); + +/** +* @} +*/ + +/** +* @} +*/ + +/** +* @} +*/ + +#ifdef __cplusplus +} +#endif + +#endif /* __HTS221_DRIVER__H */ + +/******************* (C) COPYRIGHT 2013 STMicroelectronics *****END OF FILE****/
diff -r 000000000000 -r 98c301bb7d1b Components/LPS22HBSensor/LPS22HBSensor.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Components/LPS22HBSensor/LPS22HBSensor.cpp Tue Oct 03 12:21:11 2017 +0000 @@ -0,0 +1,399 @@ +/** + ****************************************************************************** + * @file LPS22HBSensor.cpp + * @author CLab + * @version V1.0.0 + * @date 5 August 2016 + * @brief Implementation of an LPS22HB Pressure sensor. + ****************************************************************************** + * @attention + * + * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of STMicroelectronics nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************** + */ + + +/* Includes ------------------------------------------------------------------*/ + +#include "mbed.h" +#include "DevI2C.h" +#include "LPS22HBSensor.h" +#include "LPS22HB_driver.h" + + +/* Class Implementation ------------------------------------------------------*/ + +/** Constructor + * @param i2c object of an helper class which handles the I2C peripheral + * @param address the address of the component's instance + */ +LPS22HBSensor::LPS22HBSensor(DevI2C &i2c) : _dev_i2c(i2c) +{ + _address = LPS22HB_ADDRESS_HIGH; +}; + + +/** Constructor + * @param i2c object of an helper class which handles the I2C peripheral + * @param address the address of the component's instance + */ +LPS22HBSensor::LPS22HBSensor(DevI2C &i2c, uint8_t address) : _dev_i2c(i2c), _address(address) +{ + +}; + +/** + * @brief Initializing the component. + * @param[in] init pointer to device specific initalization structure. + * @retval "0" in case of success, an error code otherwise. + */ +int LPS22HBSensor::init(void *init) +{ + if ( LPS22HB_Set_PowerMode( (void *)this, LPS22HB_LowPower) == LPS22HB_ERROR ) + { + return 1; + } + + /* Power down the device */ + if ( LPS22HB_Set_Odr( (void *)this, LPS22HB_ODR_ONE_SHOT ) == LPS22HB_ERROR ) + { + return 1; + } + + /* Disable low-pass filter on LPS22HB pressure data */ + if( LPS22HB_Set_LowPassFilter( (void *)this, LPS22HB_DISABLE) == LPS22HB_ERROR ) + { + return 1; + } + + /* Set low-pass filter cutoff configuration*/ + if( LPS22HB_Set_LowPassFilterCutoff( (void *)this, LPS22HB_ODR_9) == LPS22HB_ERROR ) + { + return 1; + } + + /* Set block data update mode */ + if ( LPS22HB_Set_Bdu( (void *)this, LPS22HB_BDU_NO_UPDATE ) == LPS22HB_ERROR ) + { + return 1; + } + + /* Set automatic increment for multi-byte read/write */ + if( LPS22HB_Set_AutomaticIncrementRegAddress( (void *)this, LPS22HB_ENABLE) == LPS22HB_ERROR ) + { + return 1; + } + + _is_enabled = 0; + _last_odr = 25.0f; + + return 0; +} + + +/** + * @brief Enable LPS22HB + * @retval 0 in case of success, an error code otherwise + */ +int LPS22HBSensor::enable(void) +{ + /* Check if the component is already enabled */ + if ( _is_enabled == 1 ) + { + return 0; + } + + if(Set_ODR_When_Enabled(_last_odr) == 1) + { + return 1; + } + + _is_enabled = 1; + + return 0; +} + +/** + * @brief Disable LPS22HB + * @retval 0 in case of success, an error code otherwise + */ +int LPS22HBSensor::disable(void) +{ + /* Check if the component is already disabled */ + if ( _is_enabled == 0 ) + { + return 0; + } + + /* Power down the device */ + if ( LPS22HB_Set_Odr( (void *)this, LPS22HB_ODR_ONE_SHOT ) == LPS22HB_ERROR ) + { + return 1; + } + + _is_enabled = 0; + + return 0; +} + +/** + * @brief Read ID address of LPS22HB + * @param id the pointer where the ID of the device is stored + * @retval 0 in case of success, an error code otherwise + */ +int LPS22HBSensor::read_id(uint8_t *id) +{ + if(!id) + { + return 1; + } + + /* Read WHO AM I register */ + if ( LPS22HB_Get_DeviceID( (void *)this, id ) == LPS22HB_ERROR ) + { + return 1; + } + + return 0; +} + +/** + * @brief Reboot memory content of LPS22HB + * @param None + * @retval 0 in case of success, an error code otherwise + */ +int LPS22HBSensor::reset(void) +{ + /* Read WHO AM I register */ + if ( LPS22HB_MemoryBoot((void *)this) == LPS22HB_ERROR ) + { + return 1; + } + + return 0; +} + +/** + * @brief Read LPS22HB output register, and calculate the pressure in mbar + * @param pfData the pressure value in mbar + * @retval 0 in case of success, an error code otherwise + */ +int LPS22HBSensor::get_pressure(float* pfData) +{ + int32_t int32data = 0; + + /* Read data from LPS22HB. */ + if ( LPS22HB_Get_Pressure( (void *)this, &int32data ) == LPS22HB_ERROR ) + { + return 1; + } + + *pfData = ( float )int32data / 100.0f; + + return 0; +} + +/** + * @brief Read LPS22HB output register, and calculate the temperature + * @param pfData the temperature value + * @retval 0 in case of success, an error code otherwise + */ +int LPS22HBSensor::get_temperature(float *pfData) +{ + int16_t int16data = 0; + + /* Read data from LPS22HB. */ + if ( LPS22HB_Get_Temperature( (void *)this, &int16data ) == LPS22HB_ERROR ) + { + return 1; + } + + *pfData = ( float )int16data / 10.0f; + + return 0; +} + +/** + * @brief Read LPS22HB output data rate + * @param odr the pointer to the output data rate + * @retval 0 in case of success, an error code otherwise + */ +int LPS22HBSensor::get_odr(float* odr) +{ + LPS22HB_Odr_et odr_low_level; + + if ( LPS22HB_Get_Odr( (void *)this, &odr_low_level ) == LPS22HB_ERROR ) + { + return 1; + } + + switch( odr_low_level ) + { + case LPS22HB_ODR_ONE_SHOT: + *odr = 0.0f; + break; + case LPS22HB_ODR_1HZ: + *odr = 1.0f; + break; + case LPS22HB_ODR_10HZ: + *odr = 10.0f; + break; + case LPS22HB_ODR_25HZ: + *odr = 25.0f; + break; + case LPS22HB_ODR_50HZ: + *odr = 50.0f; + break; + case LPS22HB_ODR_75HZ: + *odr = 75.0f; + break; + default: + *odr = -1.0f; + return 1; + } + + return 0; +} + +/** + * @brief Set ODR + * @param odr the output data rate to be set + * @retval 0 in case of success, an error code otherwise + */ +int LPS22HBSensor::set_odr(float odr) +{ + if(_is_enabled == 1) + { + if(Set_ODR_When_Enabled(odr) == 1) + { + return 1; + } + } + else + { + if(Set_ODR_When_Disabled(odr) == 1) + { + return 1; + } + } + + return 0; +} + + +/** + * @brief Set the LPS22HB sensor output data rate when enabled + * @param odr the functional output data rate to be set + * @retval 0 in case of success + * @retval 1 in case of failure + */ +int LPS22HBSensor::Set_ODR_When_Enabled( float odr ) +{ + LPS22HB_Odr_et new_odr; + + new_odr = ( odr <= 1.0f ) ? LPS22HB_ODR_1HZ + : ( odr <= 10.0f ) ? LPS22HB_ODR_10HZ + : ( odr <= 25.0f ) ? LPS22HB_ODR_25HZ + : ( odr <= 50.0f ) ? LPS22HB_ODR_50HZ + : LPS22HB_ODR_75HZ; + + if ( LPS22HB_Set_Odr( (void *)this, new_odr ) == LPS22HB_ERROR ) + { + return 1; + } + + if ( get_odr( &_last_odr ) == 1 ) + { + return 1; + } + + return 0; +} + +/** + * @brief Set the LPS22HB sensor output data rate when disabled + * @param odr the functional output data rate to be set + * @retval 0 in case of success + * @retval 1 in case of failure + */ +int LPS22HBSensor::Set_ODR_When_Disabled( float odr ) +{ + _last_odr = ( odr <= 1.0f ) ? 1.0f + : ( odr <= 10.0f ) ? 10.0f + : ( odr <= 25.0f ) ? 25.0f + : ( odr <= 50.0f ) ? 50.0f + : 75.0f; + + return 0; +} + + +/** + * @brief Read the data from register + * @param reg register address + * @param data register data + * @retval 0 in case of success + * @retval 1 in case of failure + */ +int LPS22HBSensor::read_reg( uint8_t reg, uint8_t *data ) +{ + + if ( LPS22HB_read_reg( (void *)this, reg, 1, data ) == LPS22HB_ERROR ) + { + return 1; + } + + return 0; +} + +/** + * @brief Write the data to register + * @param reg register address + * @param data register data + * @retval 0 in case of success + * @retval 1 in case of failure + */ +int LPS22HBSensor::write_reg( uint8_t reg, uint8_t data ) +{ + + if ( LPS22HB_write_reg( (void *)this, reg, 1, &data ) == LPS22HB_ERROR ) + { + return 1; + } + + return 0; +} + + +uint8_t LPS22HB_io_write( void *handle, uint8_t WriteAddr, uint8_t *pBuffer, uint16_t nBytesToWrite ) +{ + return ((LPS22HBSensor *)handle)->io_write(pBuffer, WriteAddr, nBytesToWrite); +} + +uint8_t LPS22HB_io_read( void *handle, uint8_t ReadAddr, uint8_t *pBuffer, uint16_t nBytesToRead ) +{ + return ((LPS22HBSensor *)handle)->io_read(pBuffer, ReadAddr, nBytesToRead); +}
diff -r 000000000000 -r 98c301bb7d1b Components/LPS22HBSensor/LPS22HBSensor.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Components/LPS22HBSensor/LPS22HBSensor.h Tue Oct 03 12:21:11 2017 +0000 @@ -0,0 +1,121 @@ +/** + ****************************************************************************** + * @file LPS22HBSensor.h + * @author CLab + * @version V1.0.0 + * @date 5 August 2016 + * @brief Abstract Class of an LPS22HB Pressure sensor. + ****************************************************************************** + * @attention + * + * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of STMicroelectronics nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************** + */ + + +/* Prevent recursive inclusion -----------------------------------------------*/ + +#ifndef __LPS22HBSensor_H__ +#define __LPS22HBSensor_H__ + + +/* Includes ------------------------------------------------------------------*/ + +#include "DevI2C.h" +#include "LPS22HB_driver.h" +#include "PressureSensor.h" +#include "TempSensor.h" + +/* Class Declaration ---------------------------------------------------------*/ + +/** + * Abstract class of an LPS22HB Pressure sensor. + */ +class LPS22HBSensor : public PressureSensor, public TempSensor +{ + public: + LPS22HBSensor(DevI2C &i2c); + LPS22HBSensor(DevI2C &i2c, uint8_t address); + virtual int init(void *init); + virtual int read_id(uint8_t *id); + virtual int get_pressure(float *pfData); + virtual int get_temperature(float *pfData); + int enable(void); + int disable(void); + int reset(void); + int get_odr(float *odr); + int set_odr(float odr); + int read_reg(uint8_t reg, uint8_t *data); + int write_reg(uint8_t reg, uint8_t data); + + /** + * @brief Utility function to read data. + * @param pBuffer: pointer to data to be read. + * @param RegisterAddr: specifies internal address register to be read. + * @param NumByteToRead: number of bytes to be read. + * @retval 0 if ok, an error code otherwise. + */ + uint8_t io_read(uint8_t* pBuffer, uint8_t RegisterAddr, uint16_t NumByteToRead) + { + return (uint8_t) _dev_i2c.i2c_read(pBuffer, _address, RegisterAddr, NumByteToRead); + } + + /** + * @brief Utility function to write data. + * @param pBuffer: pointer to data to be written. + * @param RegisterAddr: specifies internal address register to be written. + * @param NumByteToWrite: number of bytes to write. + * @retval 0 if ok, an error code otherwise. + */ + uint8_t io_write(uint8_t* pBuffer, uint8_t RegisterAddr, uint16_t NumByteToWrite) + { + return (uint8_t) _dev_i2c.i2c_write(pBuffer, _address, RegisterAddr, NumByteToWrite); + } + + private: + int Set_ODR_When_Enabled(float odr); + int Set_ODR_When_Disabled(float odr); + + /* Helper classes. */ + DevI2C &_dev_i2c; + + /* Configuration */ + uint8_t _address; + + uint8_t _is_enabled; + float _last_odr; +}; + +#ifdef __cplusplus + extern "C" { +#endif +uint8_t LPS22HB_io_write( void *handle, uint8_t WriteAddr, uint8_t *pBuffer, uint16_t nBytesToWrite ); +uint8_t LPS22HB_io_read( void *handle, uint8_t ReadAddr, uint8_t *pBuffer, uint16_t nBytesToRead ); +#ifdef __cplusplus + } +#endif + +#endif
diff -r 000000000000 -r 98c301bb7d1b Components/LPS22HBSensor/LPS22HB_driver.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Components/LPS22HBSensor/LPS22HB_driver.c Tue Oct 03 12:21:11 2017 +0000 @@ -0,0 +1,1761 @@ +/** + ******************************************************************************* + * @file LPS22HB_driver.c + * @author HESA Application Team + * @version V1.1 + * @date 10-August-2016 + * @brief LPS22HB driver file + ******************************************************************************* + * @attention + * + * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of STMicroelectronics nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************** + */ + +/* Includes ------------------------------------------------------------------*/ +#include "LPS22HB_driver.h" +#ifdef USE_FULL_ASSERT_LPS22HB +#include <stdio.h> +#endif + +/** @addtogroup Environmental_Sensor +* @{ +*/ + +/** @defgroup LPS22HB_DRIVER +* @brief LPS22HB DRIVER +* @{ +*/ + +/** @defgroup LPS22HB_Imported_Function_Prototypes +* @{ +*/ + +extern uint8_t LPS22HB_io_write( void *handle, uint8_t WriteAddr, uint8_t *pBuffer, uint16_t nBytesToWrite ); +extern uint8_t LPS22HB_io_read( void *handle, uint8_t ReadAddr, uint8_t *pBuffer, uint16_t nBytesToRead ); + +/** +* @} +*/ + +/** @defgroup LPS22HB_Private_Function_Prototypes +* @{ +*/ + +/** +* @} +*/ + +/** @defgroup LPS22HB_Private_Functions +* @{ +*/ + +/** +* @} +*/ + +/** @defgroup LPS22HB_Public_Functions +* @{ +*/ + +/******************************************************************************* +* Function Name : LPS22HB_read_reg +* Description : Generic Reading function. It must be fullfilled with either +* : I2C or SPI reading functions +* Input : Register Address +* Output : Data Read +* Return : None +*******************************************************************************/ +LPS22HB_Error_et LPS22HB_read_reg( void *handle, uint8_t RegAddr, uint16_t NumByteToRead, uint8_t *Data ) +{ + + if ( LPS22HB_io_read( handle, RegAddr, Data, NumByteToRead ) ) + return LPS22HB_ERROR; + else + return LPS22HB_OK; +} + +/******************************************************************************* +* Function Name : LPS22HB_write_reg +* Description : Generic Writing function. It must be fullfilled with either +* : I2C or SPI writing function +* Input : Register Address, Data to be written +* Output : None +* Return : None +*******************************************************************************/ +LPS22HB_Error_et LPS22HB_write_reg( void *handle, uint8_t RegAddr, uint16_t NumByteToWrite, uint8_t *Data ) +{ + + if ( LPS22HB_io_write( handle, RegAddr, Data, NumByteToWrite ) ) + return LPS22HB_ERROR; + else + return LPS22HB_OK; +} + +/** +* @brief Read identification code by WHO_AM_I register +* @param *handle Device handle. +* @param Buffer to empty by Device identification Value. +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Get_DeviceID(void *handle, uint8_t* deviceid) +{ + if(LPS22HB_read_reg(handle, LPS22HB_WHO_AM_I_REG, 1, deviceid)) + return LPS22HB_ERROR; + + return LPS22HB_OK; +} + + +/** +* @brief Get the LPS22HB driver version. +* @param None +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Get_DriverVersion(LPS22HB_driverVersion_st *Version) +{ + Version->Major = LPS22HB_driverVersion_Major; + Version->Minor = LPS22HB_driverVersion_Minor; + Version->Point = LPS22HB_driverVersion_Point; + + return LPS22HB_OK; +} + + +/** +* @brief Set LPS22HB Low Power or Low Noise Mode Configuration +* @param *handle Device handle. +* @param LPS22HB_LowNoise or LPS22HB_LowPower mode +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Set_PowerMode(void *handle, LPS22HB_PowerMode_et mode) +{ + uint8_t tmp; + + LPS22HB_assert_param(IS_LPS22HB_PowerMode(mode)); + + if(LPS22HB_read_reg(handle, LPS22HB_RES_CONF_REG, 1, &tmp)) + return LPS22HB_ERROR; + + tmp &= ~LPS22HB_LCEN_MASK; + tmp |= (uint8_t)mode; + + if(LPS22HB_write_reg(handle, LPS22HB_RES_CONF_REG, 1, &tmp)) + return LPS22HB_ERROR; + + return LPS22HB_OK; +} + +/** +* @brief Get LPS22HB Power Mode +* @param *handle Device handle. +* @param Buffer to empty with Mode: Low Noise or Low Current +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Get_PowerMode(void *handle, LPS22HB_PowerMode_et* mode) +{ + uint8_t tmp; + + if(LPS22HB_read_reg(handle, LPS22HB_RES_CONF_REG, 1, &tmp)) + return LPS22HB_ERROR; + + *mode = (LPS22HB_PowerMode_et)(tmp & LPS22HB_LCEN_MASK); + + return LPS22HB_OK; +} + + +/** +* @brief Set LPS22HB Output Data Rate +* @param *handle Device handle. +* @param Output Data Rate +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Set_Odr(void *handle, LPS22HB_Odr_et odr) +{ + uint8_t tmp; + + + LPS22HB_assert_param(IS_LPS22HB_ODR(odr)); + + if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG1, 1, &tmp)) + return LPS22HB_ERROR; + + tmp &= ~LPS22HB_ODR_MASK; + tmp |= (uint8_t)odr; + + if(LPS22HB_write_reg(handle, LPS22HB_CTRL_REG1, 1, &tmp)) + return LPS22HB_ERROR; + + return LPS22HB_OK; +} + +/** +* @brief Get LPS22HB Output Data Rate +* @param *handle Device handle. +* @param Buffer to empty with Output Data Rate +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Get_Odr(void *handle, LPS22HB_Odr_et* odr) +{ + uint8_t tmp; + + if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG1, 1, &tmp)) + return LPS22HB_ERROR; + + *odr = (LPS22HB_Odr_et)(tmp & LPS22HB_ODR_MASK); + + return LPS22HB_OK; +} + +/** +* @brief Enable/Disale low-pass filter on LPS22HB pressure data +* @param *handle Device handle. +* @param state: enable or disable +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Set_LowPassFilter(void *handle, LPS22HB_State_et state) +{ + uint8_t tmp; + + LPS22HB_assert_param(IS_LPS22HB_State(state)); + + if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG1, 1, &tmp)) + return LPS22HB_ERROR; + + tmp &= ~LPS22HB_LPFP_MASK; + tmp |= ((uint8_t)state)<<LPS22HB_LPFP_BIT; + + + if(LPS22HB_write_reg(handle, LPS22HB_CTRL_REG1, 1, &tmp)) + return LPS22HB_ERROR; + + + return LPS22HB_OK; +} + + +/** +* @brief Set low-pass filter cutoff configuration on LPS22HB pressure data +* @param *handle Device handle. +* @param Filter Cutoff ODR/9 or ODR/20 +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Set_LowPassFilterCutoff(void *handle, LPS22HB_LPF_Cutoff_et cutoff){ + + uint8_t tmp; + + LPS22HB_assert_param(IS_LPS22HB_LPF_Cutoff(cutoff)); + + if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG1, 1, &tmp)) + return LPS22HB_ERROR; + + tmp &= ~LPS22HB_LPFP_CUTOFF_MASK; + tmp |= (uint8_t)cutoff; + + + + if(LPS22HB_write_reg(handle, LPS22HB_CTRL_REG1, 1, &tmp)) + return LPS22HB_ERROR; + + + return LPS22HB_OK; + +} + +/** +* @brief Set Block Data Mode +* @detail It is recommended to set BDU bit to ‘1’. +* @detail This feature avoids reading LSB and MSB related to different samples. +* @param *handle Device handle. +* @param LPS22HB_BDU_CONTINUOUS_UPDATE, LPS22HB_BDU_NO_UPDATE +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ + +LPS22HB_Error_et LPS22HB_Set_Bdu(void *handle, LPS22HB_Bdu_et bdu) +{ + uint8_t tmp; + + + LPS22HB_assert_param(IS_LPS22HB_BDUMode(bdu)); + + if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG1, 1, &tmp)) + return LPS22HB_ERROR; + + tmp &= ~LPS22HB_BDU_MASK; + tmp |= ((uint8_t)bdu); + + + if(LPS22HB_write_reg(handle, LPS22HB_CTRL_REG1, 1, &tmp)) + return LPS22HB_OK; + + return LPS22HB_OK; +} + +/** +* @brief Get Block Data Mode +* @param *handle Device handle. +* @param Buffer to empty whit the bdu mode read from sensor +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Get_Bdu(void *handle, LPS22HB_Bdu_et* bdu) +{ + uint8_t tmp; + + if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG1, 1, &tmp)) + return LPS22HB_ERROR; + + *bdu = (LPS22HB_Bdu_et)(tmp & LPS22HB_BDU_MASK); + + return LPS22HB_OK; +} + +/** +* @brief Set SPI mode: 3 Wire Interface or 4 Wire Interface +* @param *handle Device handle. +* @param LPS22HB_SPI_3_WIRE, LPS22HB_SPI_4_WIRE +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Set_SpiInterface(void *handle, LPS22HB_SPIMode_et spimode) +{ + uint8_t tmp; + + + LPS22HB_assert_param(IS_LPS22HB_SPIMode(spimode)); + + if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG1, 1, &tmp)) + return LPS22HB_ERROR; + + tmp &= ~LPS22HB_SIM_MASK; + tmp |= (uint8_t)spimode; + + if(LPS22HB_write_reg(handle, LPS22HB_CTRL_REG1, 1, &tmp)) + return LPS22HB_ERROR; + + return LPS22HB_OK; +} + +/** +* @brief Clock Tree Configuration +* @param *handle Device handle. +* @param LPS22HB_CTE_NotBalanced, LPS22HB_CTE_ABalanced +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Set_ClockTreeConfifuration(void *handle, LPS22HB_CTE_et mode) +{ + uint8_t tmp; + + + LPS22HB_assert_param(IS_LPS22HB_CTE(mode)); + + if(LPS22HB_read_reg(handle, LPS22HB_CLOCK_TREE_CONFIGURATION, 1, &tmp)) + return LPS22HB_ERROR; + + tmp &= ~LPS22HB_CTE_MASK; + tmp |= (uint8_t)mode; + + + if(LPS22HB_write_reg(handle, LPS22HB_CLOCK_TREE_CONFIGURATION, 1, &tmp)) + return LPS22HB_ERROR; + + return LPS22HB_OK; +} + + +/** +* @brief Get SPI mode: 3 Wire Interface or 4 Wire Interface +* @param *handle Device handle. +* @param Buffet to empty with spi mode read from Sensor +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Get_SpiInterface(void *handle, LPS22HB_SPIMode_et* spimode) +{ + uint8_t tmp; + + if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG1, 1, &tmp)) + return LPS22HB_ERROR; + + *spimode = (LPS22HB_SPIMode_et)(tmp & LPS22HB_SIM_MASK); + + return LPS22HB_OK; +} + + /** +* @brief Software Reset. Self-clearing upon completion +* @param *handle Device handle. +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_SwReset(void *handle) +{ + uint8_t tmp; + + if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG2, 1, &tmp)) + return LPS22HB_ERROR; + + tmp |= (0x01<<LPS22HB_SW_RESET_BIT); + + if(LPS22HB_write_reg(handle, LPS22HB_CTRL_REG2, 1, &tmp)) + return LPS22HB_ERROR; + + return LPS22HB_OK; +} + +/** +* @brief Reboot Memory Content +* @param *handle Device handle. +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ + +LPS22HB_Error_et LPS22HB_MemoryBoot(void *handle) +{ + uint8_t tmp; + + if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG2, 1, &tmp)) + return LPS22HB_ERROR; + + tmp |= (0x01<<LPS22HB_BOOT_BIT); + + if(LPS22HB_write_reg(handle, LPS22HB_CTRL_REG2, 1, &tmp)) + return LPS22HB_ERROR; + + return LPS22HB_OK; +} + +/** +* @brief Software Reset ann Reboot Memory Content. +* @detail The device is reset to the power on configuration if the SWRESET bit is set to ‘1’ + + and BOOT is set to ‘1’; Self-clearing upon completion. +* @param *handle Device handle. +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_SwResetAndMemoryBoot(void *handle) +{ + uint8_t tmp; + + if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG2, 1, &tmp)) + return LPS22HB_ERROR; + + tmp |= ((0x01<<LPS22HB_SW_RESET_BIT) | (0x01<<LPS22HB_BOOT_BIT)); + + if(LPS22HB_write_reg(handle, LPS22HB_CTRL_REG2, 1, &tmp)) + return LPS22HB_ERROR; + + return LPS22HB_OK; +} + + +/** +* @brief Enable/Disable FIFO Mode +* @param *handle Device handle. +* @param LPS22HB_ENABLE/LPS22HB_DISABLE +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Set_FifoModeUse(void *handle, LPS22HB_State_et status) +{ + uint8_t tmp; + + LPS22HB_assert_param(IS_LPS22HB_State(status)); + + if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG2, 1, &tmp)) + return LPS22HB_ERROR; + + tmp &= ~LPS22HB_FIFO_EN_MASK; + tmp |= ((uint8_t)status)<<LPS22HB_FIFO_EN_BIT; + + if(LPS22HB_write_reg(handle, LPS22HB_CTRL_REG2, 1, &tmp)) + return LPS22HB_ERROR; + + return LPS22HB_OK; +} +/** +* @brief Enable/Disable FIFO Watermark Level Use +* @param *handle Device handle. +* @param LPS22HB_ENABLE/LPS22HB_DISABLE +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Set_FifoWatermarkLevelUse(void *handle, LPS22HB_State_et status) +{ + uint8_t tmp; + + LPS22HB_assert_param(IS_LPS22HB_State(status)); + + if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG2, 1, &tmp)) + return LPS22HB_ERROR; + + tmp &= ~LPS22HB_WTM_EN_MASK; + tmp |= ((uint8_t)status)<<LPS22HB_WTM_EN_BIT; + + if(LPS22HB_write_reg(handle, LPS22HB_CTRL_REG2, 1, &tmp)) + return LPS22HB_ERROR; + + return LPS22HB_OK; +} + + /** +* @brief Enable or Disable the Automatic increment register address during a multiple byte access with a serial interface (I2C or SPI) +* @param *handle Device handle. +* @param LPS22HB_ENABLE/LPS22HB_DISABLE. Default is LPS22HB_ENABLE +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Set_AutomaticIncrementRegAddress(void *handle, LPS22HB_State_et status){ + + uint8_t tmp; + + LPS22HB_assert_param(IS_LPS22HB_State(status)); + + if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG2, 1, &tmp)) + return LPS22HB_ERROR; + + tmp &= ~LPS22HB_ADD_INC_MASK; + tmp |= (((uint8_t)status)<<LPS22HB_ADD_INC_BIT); + + if(LPS22HB_write_reg(handle, LPS22HB_CTRL_REG2, 1, &tmp)) + return LPS22HB_ERROR; + + return LPS22HB_OK; + +} + +/** +* @brief Enable/Disable I2C Interface +* @param *handle Device handle. +* @param State: LPS22HB_ENABLE (reset bit)/ LPS22HB_DISABLE (set bit) +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Set_I2C(void *handle, LPS22HB_State_et statei2c) +{ + uint8_t tmp; + + LPS22HB_assert_param(IS_LPS22HB_State(statei2c)); + + if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG2, 1, &tmp)) + return LPS22HB_ERROR; + + /*Reset Bit->I2C Enabled*/ + tmp &= ~LPS22HB_I2C_MASK; + tmp|=((uint8_t)~statei2c)<<LPS22HB_I2C_BIT; + + if(LPS22HB_write_reg(handle, LPS22HB_CTRL_REG2, 1, &tmp)) + return LPS22HB_ERROR; + + return LPS22HB_OK; +} + + +/** +* @brief Set the one-shot bit in order to start acquisition when the ONE SHOT mode +* has been selected by the ODR configuration. +* @detail Once the measurement is done, ONE_SHOT bit will self-clear. +* @param *handle Device handle. +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_StartOneShotMeasurement(void *handle) +{ + uint8_t tmp; + + if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG2, 1, &tmp)) + return LPS22HB_ERROR; + + /* Set the one shot bit */ + /* Once the measurement is done, one shot bit will self-clear*/ + tmp |= LPS22HB_ONE_SHOT_MASK; + + if(LPS22HB_write_reg(handle, LPS22HB_CTRL_REG2, 1, &tmp)) + return LPS22HB_ERROR; + + return LPS22HB_OK; + +} + +/** +* @brief Set Interrupt Active on High or Low Level +* @param *handle Device handle. +* @param LPS22HB_ActiveHigh/LPS22HB_ActiveLow +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Set_InterruptActiveLevel(void *handle, LPS22HB_InterruptActiveLevel_et mode) +{ + uint8_t tmp; + + LPS22HB_assert_param(IS_LPS22HB_InterruptActiveLevel(mode)); + + if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG3, 1, &tmp)) + return LPS22HB_ERROR; + + tmp &= ~LPS22HB_INT_H_L_MASK; + tmp |= ((uint8_t)mode); + + if(LPS22HB_write_reg(handle, LPS22HB_CTRL_REG3, 1, &tmp)) + return LPS22HB_ERROR; + + return LPS22HB_OK; +} + + +/** +* @brief Push-pull/open drain selection on interrupt pads. Default tmp: 0 +* @param *handle Device handle. +* @param LPS22HB_PushPull/LPS22HB_OpenDrain +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Set_InterruptOutputType(void *handle, LPS22HB_OutputType_et output) +{ + uint8_t tmp; + + LPS22HB_assert_param(IS_LPS22HB_OutputType(output)); + + if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG3, 1, &tmp)) + return LPS22HB_ERROR; + + tmp &= ~LPS22HB_PP_OD_MASK; + tmp |= (uint8_t)output; + + if(LPS22HB_write_reg(handle, LPS22HB_CTRL_REG3, 1, &tmp)) + return LPS22HB_ERROR; + + return LPS22HB_OK; +} + +/** +* @brief Set Data signal on INT pad control bits. +* @param *handle Device handle. +* @param LPS22HB_DATA,LPS22HB_P_HIGH_LPS22HB_P_LOW,LPS22HB_P_LOW_HIGH +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Set_InterruptControlConfig(void *handle, LPS22HB_OutputSignalConfig_et config) +{ + uint8_t tmp; + + LPS22HB_assert_param(IS_LPS22HB_OutputSignal(config)); + + if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG3, 1, &tmp)) + return LPS22HB_ERROR; + + tmp &= ~(LPS22HB_INT_S12_MASK); + tmp |= (uint8_t)config; + + if(LPS22HB_write_reg(handle, LPS22HB_CTRL_REG3, 1, &tmp)) + return LPS22HB_ERROR; + + return LPS22HB_OK; +} + + +/** +* @brief Enable/Disable Data-ready signal on INT_DRDY pin. +* @param *handle Device handle. +* @param LPS22HB_ENABLE/LPS22HB_DISABLE +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Set_DRDYInterrupt(void *handle, LPS22HB_State_et status) +{ + uint8_t tmp; + + + LPS22HB_assert_param(IS_LPS22HB_State(status)); + + if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG3, 1, &tmp)) + return LPS22HB_ERROR; + + tmp &= ~LPS22HB_DRDY_MASK; + tmp |= ((uint8_t)status)<<LPS22HB_DRDY_BIT; + + if(LPS22HB_write_reg(handle, LPS22HB_CTRL_REG3, 1, &tmp)) + return LPS22HB_ERROR; + + return LPS22HB_OK; +} + + /** +* @brief Enable/Disable FIFO overrun interrupt on INT_DRDY pin. +* @param *handle Device handle. +* @param LPS22HB_ENABLE/LPS22HB_DISABLE +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Set_FIFO_OVR_Interrupt(void *handle, LPS22HB_State_et status) +{ + uint8_t tmp; + + + LPS22HB_assert_param(IS_LPS22HB_State(status)); + + if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG3, 1, &tmp)) + return LPS22HB_ERROR; + + tmp &= ~LPS22HB_FIFO_OVR_MASK; + tmp |= ((uint8_t)status)<<LPS22HB_FIFO_OVR_BIT; + + if(LPS22HB_write_reg(handle, LPS22HB_CTRL_REG3, 1, &tmp)) + return LPS22HB_ERROR; + + return LPS22HB_OK; +} + + /** +* @brief Enable/Disable FIFO threshold (Watermark) interrupt on INT_DRDY pin. +* @param *handle Device handle. +* @param LPS22HB_ENABLE/LPS22HB_DISABLE +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Set_FIFO_FTH_Interrupt(void *handle, LPS22HB_State_et status) +{ + uint8_t tmp; + + LPS22HB_assert_param(IS_LPS22HB_State(status)); + + if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG3, 1, &tmp)) + return LPS22HB_ERROR; + + tmp &= ~LPS22HB_FIFO_FTH_MASK; + tmp |= ((uint8_t)status)<<LPS22HB_FIFO_FTH_BIT; + + if(LPS22HB_write_reg(handle, LPS22HB_CTRL_REG3, 1, &tmp)) + return LPS22HB_ERROR; + + return LPS22HB_OK; +} + +/** +* @brief Enable/Disable FIFO FULL interrupt on INT_DRDY pin. +* @param *handle Device handle. +* @param LPS22HB_ENABLE/LPS22HB_DISABLE +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Set_FIFO_FULL_Interrupt(void *handle, LPS22HB_State_et status) +{ + uint8_t tmp; + + LPS22HB_assert_param(IS_LPS22HB_State(status)); + + if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG3, 1, &tmp)) + return LPS22HB_ERROR; + + tmp &= ~LPS22HB_FIFO_FULL_MASK; + tmp |= ((uint8_t)status)<<LPS22HB_FIFO_FULL_BIT; + + if(LPS22HB_write_reg(handle, LPS22HB_CTRL_REG3, 1, &tmp)) + return LPS22HB_ERROR; + + return LPS22HB_OK; +} + + + +/** +* @brief Enable AutoRifP function +* @detail When this function is enabled, an internal register is set with the current pressure values +* and the content is subtracted from the pressure output value and result is used for the interrupt generation. +* the AutoRifP is slf creared. +* @param *handle Device handle. +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Set_AutoRifP(void *handle) +{ + uint8_t tmp; + + if(LPS22HB_read_reg(handle, LPS22HB_INTERRUPT_CFG_REG, 1, &tmp)) + return LPS22HB_ERROR; + + tmp |= ((uint8_t)LPS22HB_AUTORIFP_MASK); + + if(LPS22HB_write_reg(handle, LPS22HB_INTERRUPT_CFG_REG, 1, &tmp)) + return LPS22HB_ERROR; + + return LPS22HB_OK; +} + +/** +* @brief Disable AutoRifP function +* @detail the RESET_ARP bit is used to disable the AUTORIFP function. This bis i is selfdleared +* @param *handle Device handle. +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_ResetAutoRifP(void *handle) +{ + uint8_t tmp; + + if(LPS22HB_read_reg(handle, LPS22HB_INTERRUPT_CFG_REG, 1, &tmp)) + return LPS22HB_ERROR; + + + tmp |= ((uint8_t)LPS22HB_RESET_ARP_MASK); + + if(LPS22HB_write_reg(handle, LPS22HB_INTERRUPT_CFG_REG, 1, &tmp)) + return LPS22HB_ERROR; + + return LPS22HB_OK; +} + + +/* +* @brief Set AutoZero Function bit +* @detail When set to ‘1’, the actual pressure output is copied in the REF_P reg (@0x15..0x17) +* @param *handle Device handle. +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Set_AutoZeroFunction(void *handle) +{ + uint8_t tmp; + + if(LPS22HB_read_reg(handle, LPS22HB_INTERRUPT_CFG_REG, 1, &tmp)) + return LPS22HB_ERROR; + + tmp |= LPS22HB_AUTOZERO_MASK; + + if(LPS22HB_write_reg(handle, LPS22HB_INTERRUPT_CFG_REG, 1, &tmp)) + return LPS22HB_ERROR; + + return LPS22HB_OK; +} + + +/* +* @brief Set ResetAutoZero Function bit +* @details REF_P reg (@0x015..17) set pressure reference to default value RPDS reg (0x18/19). +* @param *handle Device handle. +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_ResetAutoZeroFunction(void *handle) +{ + uint8_t tmp; + + if(LPS22HB_read_reg(handle, LPS22HB_INTERRUPT_CFG_REG, 1, &tmp)) + return LPS22HB_ERROR; + + /* Set the RESET_AZ bit*/ + /* RESET_AZ is self cleared*/ + tmp |= LPS22HB_RESET_AZ_MASK; + + if(LPS22HB_write_reg(handle, LPS22HB_INTERRUPT_CFG_REG, 1, &tmp)) + return LPS22HB_ERROR; + + + return LPS22HB_OK; +} + + +/** +* @brief Enable/ Disable the computing of differential pressure output (Interrupt Generation) +* @param *handle Device handle. +* @param LPS22HB_ENABLE,LPS22HB_DISABLE +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Set_InterruptDifferentialGeneration(void *handle, LPS22HB_State_et diff_en) +{ + uint8_t tmp; + + LPS22HB_assert_param(IS_LPS22HB_State(diff_en)); + + if(LPS22HB_read_reg(handle, LPS22HB_INTERRUPT_CFG_REG, 1, &tmp)) + return LPS22HB_ERROR; + + tmp &= ~LPS22HB_DIFF_EN_MASK; + tmp |= ((uint8_t)diff_en)<<LPS22HB_DIFF_EN_BIT; + + if(LPS22HB_write_reg(handle, LPS22HB_INTERRUPT_CFG_REG, 1, &tmp)) + return LPS22HB_ERROR; + + return LPS22HB_OK; +} + + +/** +* @brief Get the DIFF_EN bit value +* @param *handle Device handle. +* @param buffer to empty with the read value of DIFF_EN bit +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Get_InterruptDifferentialGeneration(void *handle, LPS22HB_State_et* diff_en) +{ + uint8_t tmp; + + if(LPS22HB_read_reg(handle, LPS22HB_INTERRUPT_CFG_REG, 1, &tmp)) + return LPS22HB_ERROR; + + *diff_en= (LPS22HB_State_et)((tmp & LPS22HB_DIFF_EN_MASK)>>LPS22HB_DIFF_EN_BIT); + + return LPS22HB_OK; +} + +/** +* @brief Latch Interrupt request to the INT_SOURCE register. +* @param *handle Device handle. +* @param LPS22HB_ENABLE/LPS22HB_DISABLE +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_LatchInterruptRequest(void *handle, LPS22HB_State_et status) +{ + uint8_t tmp; + + LPS22HB_assert_param(IS_LPS22HB_State(status)); + + if(LPS22HB_read_reg(handle, LPS22HB_INTERRUPT_CFG_REG, 1, &tmp)) + return LPS22HB_ERROR; + + tmp &= ~LPS22HB_LIR_MASK; + tmp |= (((uint8_t)status)<<LPS22HB_LIR_BIT); + + if(LPS22HB_write_reg(handle, LPS22HB_INTERRUPT_CFG_REG, 1, &tmp)) + return LPS22HB_ERROR; + + return LPS22HB_OK; +} + + + + /** +* @brief Enable\Disable Interrupt Generation on differential pressure Low event +* @param *handle Device handle. +* @param LPS22HB_ENABLE/LPS22HB_DISABLE +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Set_PLE(void *handle, LPS22HB_State_et status) +{ + uint8_t tmp; + + LPS22HB_assert_param(IS_LPS22HB_State(status)); + + if(LPS22HB_read_reg(handle, LPS22HB_INTERRUPT_CFG_REG, 1, &tmp)) + return LPS22HB_ERROR; + + tmp &= ~LPS22HB_PLE_MASK; + tmp |= (((uint8_t)status)<<LPS22HB_PLE_BIT); + + if(LPS22HB_write_reg(handle, LPS22HB_INTERRUPT_CFG_REG, 1, &tmp)) + return LPS22HB_ERROR; + + return LPS22HB_OK; +} + +/** +* @brief Enable\Disable Interrupt Generation on differential pressure High event +* @param *handle Device handle. +* @param LPS22HB_ENABLE/LPS22HB_DISABLE +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Set_PHE(void *handle, LPS22HB_State_et status) +{ + uint8_t tmp; + + LPS22HB_assert_param(IS_LPS22HB_State(status)); + + if(LPS22HB_read_reg(handle, LPS22HB_INTERRUPT_CFG_REG, 1, &tmp)) + return LPS22HB_ERROR; + + tmp &= ~LPS22HB_PHE_MASK; + tmp |= (((uint8_t)status)<<LPS22HB_PHE_BIT); + + if(LPS22HB_write_reg(handle, LPS22HB_INTERRUPT_CFG_REG, 1, &tmp)) + return LPS22HB_ERROR; + + return LPS22HB_OK; +} + +/** +* @brief Get the Interrupt Generation on differential pressure status event and the Boot Status. +* @detail The INT_SOURCE register is cleared by reading it. +* @param *handle Device handle. +* @param Status Event Flag: BOOT, PH,PL,IA +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Get_InterruptDifferentialEventStatus(void *handle, LPS22HB_InterruptDiffStatus_st* interruptsource) +{ + uint8_t tmp; + + if(LPS22HB_read_reg(handle, LPS22HB_INTERRUPT_SOURCE_REG, 1, &tmp)) + return LPS22HB_ERROR; + + interruptsource->PH = (uint8_t)(tmp & LPS22HB_PH_MASK); + interruptsource->PL = (uint8_t)((tmp & LPS22HB_PL_MASK)>>LPS22HB_PL_BIT); + interruptsource->IA = (uint8_t)((tmp & LPS22HB_IA_MASK)>>LPS22HB_IA_BIT); + interruptsource->BOOT= (uint8_t)((tmp & LPS22HB_BOOT_STATUS_MASK)>>LPS22HB_BOOT_STATUS_BIT); + + return LPS22HB_OK; +} + +/** +* @brief Get the status of Pressure and Temperature data +* @param *handle Device handle. +* @param Data Status Flag: TempDataAvailable, TempDataOverrun, PressDataAvailable, PressDataOverrun +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Get_DataStatus(void *handle, LPS22HB_DataStatus_st* datastatus) +{ + uint8_t tmp; + + if(LPS22HB_read_reg(handle, LPS22HB_STATUS_REG, 1, &tmp)) + return LPS22HB_ERROR; + + datastatus->PressDataAvailable = (uint8_t)(tmp & LPS22HB_PDA_MASK); + datastatus->TempDataAvailable = (uint8_t)((tmp & LPS22HB_TDA_MASK)>>LPS22HB_PDA_BIT); + datastatus->TempDataOverrun = (uint8_t)((tmp & LPS22HB_TOR_MASK)>>LPS22HB_TOR_BIT); + datastatus->PressDataOverrun = (uint8_t)((tmp & LPS22HB_POR_MASK)>>LPS22HB_POR_BIT); + + return LPS22HB_OK; +} + + + +/** +* @brief Get the LPS22HB raw presure value +* @detail The data are expressed as PRESS_OUT_H/_L/_XL in 2’s complement. + Pout(hPA)=PRESS_OUT / 4096 +* @param *handle Device handle. +* @param The buffer to empty with the pressure raw value +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Get_RawPressure(void *handle, int32_t *raw_press) +{ + uint8_t buffer[3]; + uint32_t tmp = 0; + uint8_t i; + + if(LPS22HB_read_reg(handle, LPS22HB_PRESS_OUT_XL_REG, 3, buffer)) + return LPS22HB_ERROR; + + /* Build the raw data */ + for(i=0; i<3; i++) + tmp |= (((uint32_t)buffer[i]) << (8*i)); + + /* convert the 2's complement 24 bit to 2's complement 32 bit */ + if(tmp & 0x00800000) + tmp |= 0xFF000000; + + *raw_press = ((int32_t)tmp); + + return LPS22HB_OK; +} + +/** +* @brief Get the LPS22HB Pressure value in hPA. +* @detail The data are expressed as PRESS_OUT_H/_L/_XL in 2’s complement. + Pout(hPA)=PRESS_OUT / 4096 +* @param *handle Device handle. +* @param The buffer to empty with the pressure value that must be divided by 100 to get the value in hPA +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Get_Pressure(void *handle, int32_t* Pout) +{ + int32_t raw_press; + + if(LPS22HB_Get_RawPressure(handle, &raw_press)) + return LPS22HB_ERROR; + + *Pout = (raw_press*100)/4096; + + return LPS22HB_OK; +} + +/** +* @brief Get the Raw Temperature value. +* @detail Temperature data are expressed as TEMP_OUT_H&TEMP_OUT_L as 2’s complement number. +* Tout(degC)=TEMP_OUT/100 +* @param *handle Device handle. +* @param Buffer to empty with the temperature raw tmp. +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Get_RawTemperature(void *handle, int16_t* raw_data) +{ + uint8_t buffer[2]; + uint16_t tmp; + + if(LPS22HB_read_reg(handle, LPS22HB_TEMP_OUT_L_REG, 2, buffer)) + return LPS22HB_ERROR; + + /* Build the raw tmp */ + tmp = (((uint16_t)buffer[1]) << 8) + (uint16_t)buffer[0]; + + *raw_data = ((int16_t)tmp); + + return LPS22HB_OK; +} + + +/** +* @brief Get the Temperature value in °C. +* @detail Temperature data are expressed as TEMP_OUT_H&TEMP_OUT_L as 2’s complement number. +* Tout(degC)=TEMP_OUT/100 +* @param *handle Device handle. +* @param Buffer to empty with the temperature value that must be divided by 10 to get the value in °C +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Get_Temperature(void *handle, int16_t* Tout) +{ + int16_t raw_data; + + if(LPS22HB_Get_RawTemperature(handle, &raw_data)) + return LPS22HB_ERROR; + + *Tout = (raw_data*10)/100; + + return LPS22HB_OK; +} + +/** +* @brief Get the threshold value used for pressure interrupt generation (hPA). +* @detail THS_P=THS_P_H&THS_P_L and is expressed as unsigned number. P_ths(hPA)=(THS_P)/16. +* @param *handle Device handle. +* @param Buffer to empty with the pressure threshold in hPA +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Get_PressureThreshold(void *handle, int16_t* P_ths) +{ + uint8_t tempReg[2]; + + if(LPS22HB_read_reg(handle, LPS22HB_THS_P_LOW_REG, 2, tempReg)) + return LPS22HB_ERROR; + + *P_ths= (((((uint16_t)tempReg[1])<<8) + tempReg[0])/16); + + return LPS22HB_OK; +} + +/** +* @brief Set the threshold value used for pressure interrupt generation (hPA). +* @detail THS_P=THS_P_H&THS_P_L and is expressed as unsigned number. P_ths(hPA)=(THS_P)/16. +* @param *handle Device handle. +* @param Pressure threshold in hPA +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Set_PressureThreshold(void *handle, int16_t P_ths) +{ + uint8_t buffer[2]; + + buffer[0] = (uint8_t)(16 * P_ths); + buffer[1] = (uint8_t)(((uint16_t)(16 * P_ths))>>8); + + if(LPS22HB_write_reg(handle, LPS22HB_THS_P_LOW_REG, 2, buffer)) + return LPS22HB_ERROR; + + return LPS22HB_OK; +} + +/** +* @brief Set Fifo Mode. +* @param *handle Device handle. +* @param Fifo Mode struct +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Set_FifoMode(void *handle, LPS22HB_FifoMode_et fifomode) +{ + uint8_t tmp; + + LPS22HB_assert_param(IS_LPS22HB_FifoMode(fifomode)); + + if(LPS22HB_read_reg(handle, LPS22HB_CTRL_FIFO_REG, 1, &tmp)) + return LPS22HB_ERROR; + + tmp &= ~LPS22HB_FIFO_MODE_MASK; + tmp |= (uint8_t)fifomode; + + if(LPS22HB_write_reg(handle, LPS22HB_CTRL_FIFO_REG, 1, &tmp)) + return LPS22HB_ERROR; + + return LPS22HB_OK; +} + +/** +* @brief Get Fifo Mode +* @param *handle Device handle. +* @param buffer to empty with fifo mode tmp +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Get_FifoMode(void *handle, LPS22HB_FifoMode_et* fifomode) +{ + uint8_t tmp; + + if(LPS22HB_read_reg(handle, LPS22HB_CTRL_FIFO_REG, 1, &tmp)) + return LPS22HB_ERROR; + + tmp &= LPS22HB_FIFO_MODE_MASK; + *fifomode = (LPS22HB_FifoMode_et)tmp; + + return LPS22HB_OK; +} + +/** +* @brief Set Fifo Watermark Level. +* @param *handle Device handle. +* @param Watermark level value [0 31] +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Set_FifoWatermarkLevel(void *handle, uint8_t wtmlevel) +{ + uint8_t tmp; + + LPS22HB_assert_param(IS_LPS22HB_WtmLevel(wtmlevel)); + + if(LPS22HB_read_reg(handle, LPS22HB_CTRL_FIFO_REG, 1, &tmp)) + return LPS22HB_ERROR; + + tmp &= ~LPS22HB_WTM_POINT_MASK; + tmp |= wtmlevel; + + if(LPS22HB_write_reg(handle, LPS22HB_CTRL_FIFO_REG, 1, &tmp)) + return LPS22HB_ERROR; + + return LPS22HB_OK; +} + +/** +* @brief Get FIFO Watermark Level +* @param *handle Device handle. +* @param buffer to empty with watermak level[0,31] value read from sensor +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Get_FifoWatermarkLevel(void *handle, uint8_t *wtmlevel) +{ + if(LPS22HB_read_reg(handle, LPS22HB_CTRL_FIFO_REG, 1, wtmlevel)) + return LPS22HB_ERROR; + + *wtmlevel &= LPS22HB_WTM_POINT_MASK; + + return LPS22HB_OK; +} + +/** +* @brief Get the Fifo Status +* @param *handle Device handle. +* @param Status Flag: FIFO_FTH,FIFO_EMPTY,FIFO_FULL,FIFO_OVR and level of the FIFO->FIFO_LEVEL +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Get_FifoStatus(void *handle, LPS22HB_FifoStatus_st* status) +{ + uint8_t tmp; + + if(LPS22HB_read_reg(handle, LPS22HB_STATUS_FIFO_REG, 1, &tmp)) + return LPS22HB_ERROR; + + status->FIFO_FTH = (uint8_t)((tmp & LPS22HB_FTH_FIFO_MASK)>>LPS22HB_FTH_FIFO_BIT); + status->FIFO_OVR=(uint8_t)((tmp & LPS22HB_OVR_FIFO_MASK)>>LPS22HB_OVR_FIFO_BIT); + status->FIFO_LEVEL = (uint8_t)(tmp & LPS22HB_LEVEL_FIFO_MASK); + + if(status->FIFO_LEVEL ==LPS22HB_FIFO_EMPTY) + status->FIFO_EMPTY=0x01; + else + status->FIFO_EMPTY=0x00; + + if (status->FIFO_LEVEL ==LPS22HB_FIFO_FULL) + status->FIFO_FULL=0x01; + else + status->FIFO_FULL=0x00; + + + return LPS22HB_OK; +} + +/** +* @brief Get the reference pressure after soldering for computing differential pressure (hPA) +* @param *handle Device handle. +* @param buffer to empty with the he pressure value (hPA) +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Get_PressureOffsetValue(void *handle, int16_t *pressoffset) +{ + uint8_t buffer[2]; + int16_t raw_press; + + if(LPS22HB_read_reg(handle, LPS22HB_RPDS_L_REG, 2, buffer)) + return LPS22HB_ERROR; + + raw_press = (int16_t)((((uint16_t)buffer[1]) << 8) + (uint16_t)buffer[0]); + + *pressoffset = (raw_press*100)/4096; + + return LPS22HB_OK; +} + + +/** +* @brief Get the Reference Pressure value +* @detail It is a 24-bit data added to the sensor output measurement to detect a measured pressure beyond programmed limits. +* @param *handle Device handle. +* @param Buffer to empty with reference pressure value +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Get_ReferencePressure(void *handle, int32_t* RefP) +{ + uint8_t buffer[3]; + uint32_t tempVal=0; + int32_t raw_press; + uint8_t i; + + if(LPS22HB_read_reg(handle, LPS22HB_REF_P_XL_REG, 3, buffer)) + return LPS22HB_ERROR; + + /* Build the raw data */ + for(i=0; i<3; i++) + tempVal |= (((uint32_t)buffer[i]) << (8*i)); + + /* convert the 2's complement 24 bit to 2's complement 32 bit */ + if(tempVal & 0x00800000) + tempVal |= 0xFF000000; + + raw_press =((int32_t)tempVal); + *RefP = (raw_press*100)/4096; + + + return LPS22HB_OK; +} + + +/** +* @brief Check if the single measurement has completed. +* @param *handle Device handle. +* @param the returned value is set to 1, when the measurement is completed +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_IsMeasurementCompleted(void *handle, uint8_t* Is_Measurement_Completed) +{ + uint8_t tmp; + LPS22HB_DataStatus_st datastatus; + + if(LPS22HB_read_reg(handle, LPS22HB_STATUS_REG, 1, &tmp)) + return LPS22HB_ERROR; + + datastatus.TempDataAvailable=(uint8_t)((tmp&LPS22HB_TDA_MASK)>>LPS22HB_TDA_BIT); + datastatus.PressDataAvailable= (uint8_t)(tmp&LPS22HB_PDA_MASK); + + *Is_Measurement_Completed=(uint8_t)((datastatus.PressDataAvailable) & (datastatus.TempDataAvailable)); + + return LPS22HB_OK; +} + +/** +* @brief Get the values of the last single measurement. +* @param *handle Device handle. +* @param Pressure and temperature tmp +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Get_Measurement(void *handle, LPS22HB_MeasureTypeDef_st *Measurement_Value) +{ + int16_t Tout; + int32_t Pout; + + if(LPS22HB_Get_Temperature(handle, &Tout)) + return LPS22HB_ERROR; + + Measurement_Value->Tout=Tout; + + if(LPS22HB_Get_Pressure(handle, &Pout)) + return LPS22HB_ERROR; + + Measurement_Value->Pout=Pout; + + return LPS22HB_OK; + +} + +/** +* @brief Initialization function for LPS22HB. +* This function make a memory boot. +* Init the sensor with a standard basic confifuration. +* Low Power, ODR 25 Hz, Low Pass Filter disabled; BDU enabled; I2C enabled; +* NO FIFO; NO Interrupt Enabled. +* @param *handle Device handle. +* @retval Error code[LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Init(void *handle) +{ + LPS22HB_ConfigTypeDef_st pLPS22HBInit; + + /* Make LPS22HB Reset and Reboot */ + if(LPS22HB_SwResetAndMemoryBoot(handle)) + return LPS22HB_ERROR; + + pLPS22HBInit.PowerMode=LPS22HB_LowPower; + pLPS22HBInit.OutputDataRate=LPS22HB_ODR_25HZ; + pLPS22HBInit.LowPassFilter=LPS22HB_DISABLE; + pLPS22HBInit.LPF_Cutoff=LPS22HB_ODR_9; + pLPS22HBInit.BDU=LPS22HB_BDU_NO_UPDATE; + pLPS22HBInit.IfAddInc=LPS22HB_ENABLE; //default + pLPS22HBInit.Sim= LPS22HB_SPI_4_WIRE; + + /* Set Generic Configuration*/ + if(LPS22HB_Set_GenericConfig(handle, &pLPS22HBInit)) + return LPS22HB_ERROR; + + return LPS22HB_OK; +} + +/** +* @brief De initialization function for LPS22HB. +* This function make a memory boot and clear the data output flags. +* @param *handle Device handle. +* @retval Error code[LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_DeInit(void *handle) +{ + LPS22HB_MeasureTypeDef_st Measurement_Value; + + /* Make LPS22HB Reset and Reboot */ + if(LPS22HB_SwResetAndMemoryBoot(handle)) + return LPS22HB_ERROR; + + /* Dump of data output */ + if(LPS22HB_Get_Measurement(handle, &Measurement_Value)) + return LPS22HB_ERROR; + + return LPS22HB_OK; +} + + +/** +* @brief Set Generic Configuration +* @param *handle Device handle. +* @param Struct to empty with the chosen values +* @retval Error code[LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Set_GenericConfig(void *handle, LPS22HB_ConfigTypeDef_st* pxLPS22HBInit) +{ + + /* Enable Low Current Mode (low Power) or Low Noise Mode*/ + if(LPS22HB_Set_PowerMode(handle, pxLPS22HBInit->PowerMode)) + return LPS22HB_ERROR; + + /* Init the Output Data Rate*/ + if(LPS22HB_Set_Odr(handle, pxLPS22HBInit->OutputDataRate)) + return LPS22HB_ERROR; + + /* BDU bit is used to inhibit the output registers update between the reading of upper and + lower register parts. In default mode (BDU = ‘0’), the lower and upper register parts are + updated continuously. If it is not sure to read faster than output data rate, it is recommended + to set BDU bit to ‘1’. In this way, after the reading of the lower (upper) register part, the + content of that output registers is not updated until the upper (lower) part is read too. + This feature avoids reading LSB and MSB related to different samples.*/ + + if(LPS22HB_Set_Bdu(handle, pxLPS22HBInit->BDU)) + return LPS22HB_ERROR; + + /*Enable/Disale low-pass filter on LPS22HB pressure data*/ + if(LPS22HB_Set_LowPassFilter(handle, pxLPS22HBInit->LowPassFilter)) + return LPS22HB_ERROR; + + /* Set low-pass filter cutoff configuration*/ + if(LPS22HB_Set_LowPassFilterCutoff(handle, pxLPS22HBInit->LPF_Cutoff)) + return LPS22HB_ERROR; + + /* SIM bit selects the SPI serial interface mode.*/ + /* This feature has effect only if SPI interface is used*/ + + if(LPS22HB_Set_SpiInterface(handle, pxLPS22HBInit->Sim)) + return LPS22HB_ERROR; + + /*Enable or Disable the Automatic increment register address during a multiple byte access with a serial interface (I2C or SPI)*/ + if(LPS22HB_Set_AutomaticIncrementRegAddress(handle, pxLPS22HBInit->IfAddInc)) + return LPS22HB_ERROR; + + + return LPS22HB_OK; +} + +/** +* @brief Get Generic configuration +* @param *handle Device handle. +* @param Struct to empty with configuration values +* @retval Error code[LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Get_GenericConfig(void *handle, LPS22HB_ConfigTypeDef_st* pxLPS22HBInit) +{ + + uint8_t tmp; + + /*Read LPS22HB_RES_CONF_REG*/ + if(LPS22HB_Get_PowerMode(handle, &pxLPS22HBInit->PowerMode)) + return LPS22HB_ERROR; + + /*Read LPS22HB_CTRL_REG1*/ + if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG1, 1, &tmp)) + return LPS22HB_ERROR; + + pxLPS22HBInit->OutputDataRate= (LPS22HB_Odr_et)(tmp & LPS22HB_ODR_MASK); + pxLPS22HBInit->BDU=(LPS22HB_Bdu_et)(tmp & LPS22HB_BDU_MASK); + pxLPS22HBInit->Sim=(LPS22HB_SPIMode_et)(tmp& LPS22HB_SIM_MASK); + pxLPS22HBInit->LowPassFilter=(LPS22HB_State_et)((tmp& LPS22HB_LPFP_MASK)>>LPS22HB_LPFP_BIT); + pxLPS22HBInit->LPF_Cutoff=(LPS22HB_LPF_Cutoff_et)(tmp& LPS22HB_LPFP_CUTOFF_MASK); + + /*Read LPS22HB_CTRL_REG2*/ + if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG2, 1, &tmp)) + return LPS22HB_ERROR; + + pxLPS22HBInit->IfAddInc=(LPS22HB_State_et)((tmp& LPS22HB_ADD_INC_MASK)>>LPS22HB_ADD_INC_BIT); + + return LPS22HB_OK; +} + + +/** +* @brief Set Interrupt configuration +* @param *handle Device handle. +* @param Struct holding the configuration values +* @retval Error code[LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Set_InterruptConfig(void *handle, LPS22HB_InterruptTypeDef_st* pLPS22HBInt) +{ + /* Enable Low Current Mode (low Power) or Low Noise Mode*/ + if(LPS22HB_Set_InterruptActiveLevel(handle, pLPS22HBInt->INT_H_L)) + return LPS22HB_ERROR; + + /* Push-pull/open drain selection on interrupt pads.*/ + if(LPS22HB_Set_InterruptOutputType(handle, pLPS22HBInt->PP_OD)) + return LPS22HB_ERROR; + + /* Set Data signal on INT pad control bits.*/ + if(LPS22HB_Set_InterruptControlConfig(handle, pLPS22HBInt->OutputSignal_INT)) + return LPS22HB_ERROR; + + /* Enable/Disable Data-ready signal on INT_DRDY pin. */ + if(LPS22HB_Set_DRDYInterrupt(handle, pLPS22HBInt->DRDY)) + return LPS22HB_ERROR; + + /* Enable/Disable FIFO overrun interrupt on INT_DRDY pin. */ + if(LPS22HB_Set_FIFO_OVR_Interrupt(handle, pLPS22HBInt->FIFO_OVR)) + return LPS22HB_ERROR; + + /* Enable/Disable FIFO Treshold interrupt on INT_DRDY pin. */ + if(LPS22HB_Set_FIFO_FTH_Interrupt(handle, pLPS22HBInt->FIFO_FTH)) + return LPS22HB_ERROR; + + /* Enable/Disable FIFO FULL interrupt on INT_DRDY pin. */ + if(LPS22HB_Set_FIFO_FULL_Interrupt(handle, pLPS22HBInt->FIFO_FULL)) + return LPS22HB_ERROR; + + /* Latch Interrupt request to the INT_SOURCE register. */ + if(LPS22HB_LatchInterruptRequest(handle, pLPS22HBInt->LatchIRQ)) + return LPS22HB_ERROR; + + /* Set the threshold value used for pressure interrupt generation (hPA). */ + if(LPS22HB_Set_PressureThreshold(handle, pLPS22HBInt->THS_threshold)) + return LPS22HB_ERROR; + + /*Enable/Disable AutoRifP function */ + if(pLPS22HBInt->AutoRifP==LPS22HB_ENABLE){ + if(LPS22HB_Set_AutoRifP(handle)) + return LPS22HB_ERROR; + } + else{ + if(LPS22HB_ResetAutoRifP(handle)) + return LPS22HB_ERROR; + } + + /*Enable/Disable AutoZero function*/ + if(pLPS22HBInt->AutoZero==LPS22HB_ENABLE){ + if(LPS22HB_Set_AutoZeroFunction(handle)) + return LPS22HB_ERROR; + } + else{ + if(LPS22HB_ResetAutoZeroFunction(handle)) + return LPS22HB_ERROR; + } + + + if(pLPS22HBInt->OutputSignal_INT==LPS22HB_P_HIGH) + { + /* Enable\Disable Interrupt Generation on differential pressure high event*/ + if(LPS22HB_Set_PHE(handle, LPS22HB_ENABLE)) + return LPS22HB_ERROR; + if(LPS22HB_Set_InterruptDifferentialGeneration(handle, LPS22HB_ENABLE)) + return LPS22HB_ERROR; + } + else if(pLPS22HBInt->OutputSignal_INT==LPS22HB_P_LOW) + { + /* Enable Interrupt Generation on differential pressure Loe event*/ + if(LPS22HB_Set_PLE(handle, LPS22HB_ENABLE)) + return LPS22HB_ERROR; + if(LPS22HB_Set_InterruptDifferentialGeneration(handle, LPS22HB_ENABLE)) + return LPS22HB_ERROR; + } + else if(pLPS22HBInt->OutputSignal_INT==LPS22HB_P_LOW_HIGH) + { + /* Enable Interrupt Generation on differential pressure high event*/ + if(LPS22HB_Set_PHE(handle, LPS22HB_ENABLE)) + return LPS22HB_ERROR; + /* Enable\Disable Interrupt Generation on differential pressure Loe event*/ + if(LPS22HB_Set_PLE(handle, LPS22HB_ENABLE)) + return LPS22HB_ERROR; + if(LPS22HB_Set_InterruptDifferentialGeneration(handle, LPS22HB_ENABLE)) + return LPS22HB_ERROR; + } + else + { + if(LPS22HB_Set_InterruptDifferentialGeneration(handle, LPS22HB_DISABLE)) + return LPS22HB_ERROR; + /* Disable Interrupt Generation on differential pressure High event*/ + if(LPS22HB_Set_PHE(handle, LPS22HB_DISABLE)) + return LPS22HB_ERROR; + /* Disable Interrupt Generation on differential pressure Low event*/ + if(LPS22HB_Set_PLE(handle, LPS22HB_DISABLE)) + return LPS22HB_ERROR; + } + + return LPS22HB_OK; +} + +/** +* @brief LPS22HBGet_InterruptConfig +* @param *handle Device handle. +* @param Struct to empty with configuration values +* @retval S Error code[LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Get_InterruptConfig(void *handle, LPS22HB_InterruptTypeDef_st* pLPS22HBInt) +{ + uint8_t tmp; + + /*Read LPS22HB_CTRL_REG3*/ + if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG3, 1, &tmp)) + return LPS22HB_ERROR; + + pLPS22HBInt->INT_H_L= (LPS22HB_InterruptActiveLevel_et)(tmp & LPS22HB_INT_H_L_MASK); + pLPS22HBInt->PP_OD=(LPS22HB_OutputType_et)(tmp & LPS22HB_PP_OD_MASK); + pLPS22HBInt->OutputSignal_INT=(LPS22HB_OutputSignalConfig_et)(tmp& LPS22HB_INT_S12_MASK); + pLPS22HBInt->DRDY=(LPS22HB_State_et)((tmp& LPS22HB_DRDY_MASK)>>LPS22HB_DRDY_BIT); + pLPS22HBInt->FIFO_OVR=(LPS22HB_State_et)((tmp& LPS22HB_FIFO_OVR_MASK)>>LPS22HB_FIFO_OVR_BIT); + pLPS22HBInt->FIFO_FTH=(LPS22HB_State_et)((tmp& LPS22HB_FIFO_FTH_MASK)>>LPS22HB_FIFO_FTH_BIT); + pLPS22HBInt->FIFO_FULL=(LPS22HB_State_et)((tmp& LPS22HB_FIFO_FULL_MASK)>>LPS22HB_FIFO_FULL_BIT); + + /*Read LPS22HB_INTERRUPT_CFG_REG*/ + if(LPS22HB_read_reg(handle, LPS22HB_INTERRUPT_CFG_REG, 1, &tmp)) + return LPS22HB_ERROR; + + pLPS22HBInt->LatchIRQ= (LPS22HB_State_et)((tmp& LPS22HB_LIR_MASK)>>LPS22HB_LIR_BIT); + + if(LPS22HB_Get_PressureThreshold(handle, &pLPS22HBInt->THS_threshold)) + return LPS22HB_ERROR; + + //AutoRifP and Autozero are self clear // + pLPS22HBInt->AutoRifP=LPS22HB_DISABLE; + pLPS22HBInt->AutoZero=LPS22HB_DISABLE; + + return LPS22HB_OK; +} + +/** +* @brief Set Fifo configuration +* @param *handle Device handle. +* @param Struct holding the configuration values +* @retval Error code[LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Set_FifoConfig(void *handle, LPS22HB_FIFOTypeDef_st* pLPS22HBFIFO) +{ + + if(pLPS22HBFIFO->FIFO_MODE == LPS22HB_FIFO_BYPASS_MODE) { + /* FIFO Disable-> FIFO_EN bit=0 in CTRL_REG2*/ + if(LPS22HB_Set_FifoModeUse(handle, LPS22HB_DISABLE)) + return LPS22HB_ERROR; + /* Force->Disable FIFO Watermark Level Use*/ + if(LPS22HB_Set_FifoWatermarkLevelUse(handle, LPS22HB_DISABLE)) + return LPS22HB_ERROR; + + /* Force->Disable FIFO Treshold interrupt on INT_DRDY pin. */ + if(LPS22HB_Set_FIFO_FTH_Interrupt(handle, LPS22HB_DISABLE)) + return LPS22HB_ERROR; + } + else { + /* FIFO Enable-> FIFO_EN bit=1 in CTRL_REG2*/ + if(LPS22HB_Set_FifoModeUse(handle, LPS22HB_ENABLE)) + return LPS22HB_ERROR; + + if (pLPS22HBFIFO->WTM_INT){ + /* Enable FIFO Watermark Level Use*/ + if(LPS22HB_Set_FifoWatermarkLevelUse(handle, LPS22HB_ENABLE)) + return LPS22HB_ERROR; + /*Set Fifo Watermark Level*/ + if(LPS22HB_Set_FifoWatermarkLevel(handle, pLPS22HBFIFO->WTM_LEVEL)) + return LPS22HB_ERROR; + /* Force->enable FIFO Treshold interrupt on INT_DRDY pin. */ + if(LPS22HB_Set_FIFO_FTH_Interrupt(handle, LPS22HB_ENABLE)) + return LPS22HB_ERROR; + } + } + + if(LPS22HB_Set_FifoMode(handle, pLPS22HBFIFO->FIFO_MODE)) + return LPS22HB_ERROR; + + return LPS22HB_OK; +} + +/** +* @brief Get Fifo configuration +* @param *handle Device handle. +* @param Struct to empty with the configuration values +* @retval Error code[LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Get_FifoConfig(void *handle, LPS22HB_FIFOTypeDef_st* pLPS22HBFIFO) +{ + uint8_t tmp; + + if(LPS22HB_read_reg(handle, LPS22HB_CTRL_FIFO_REG, 1, &tmp)) + return LPS22HB_ERROR; + + /*!< Fifo Mode Selection */ + pLPS22HBFIFO->FIFO_MODE= (LPS22HB_FifoMode_et)(tmp& LPS22HB_FIFO_MODE_MASK); + + /*!< FIFO threshold/Watermark level selection*/ + pLPS22HBFIFO->WTM_LEVEL= (uint8_t)(tmp& LPS22HB_WTM_POINT_MASK); + + if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG2, 1, &tmp)) + return LPS22HB_ERROR; + + /*!< Enable/Disable the watermark interrupt*/ + pLPS22HBFIFO->WTM_INT= (LPS22HB_State_et)((tmp& LPS22HB_WTM_EN_MASK)>>LPS22HB_WTM_EN_BIT); + + + return LPS22HB_OK; +} + +#ifdef USE_FULL_ASSERT_LPS22HB +/** +* @brief Reports the name of the source file and the source line number +* where the assert_param error has occurred. +* @param file: pointer to the source file name +* @param line: assert_param error line source number +* @retval : None +*/ +void LPS22HB_assert_failed(uint8_t* file, uint32_t line) +{ + /* User can add his own implementation to report the file name and line number */ + printf("Wrong parameters tmp: file %s on line %d\r\n", file, (int)line); + + /* Infinite loop */ + while (1) + { + } +} +#endif + +/** +* @} +*/ + +/** +* @} +*/ + +/** +* @} +*/ + +/******************* (C) COPYRIGHT 2013 STMicroelectronics *****END OF FILE****/
diff -r 000000000000 -r 98c301bb7d1b Components/LPS22HBSensor/LPS22HB_driver.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Components/LPS22HBSensor/LPS22HB_driver.h Tue Oct 03 12:21:11 2017 +0000 @@ -0,0 +1,1305 @@ +/** + ****************************************************************************** + * @file LPS22HB_driver.h + * @author HESA Application Team + * @version V1.1 + * @date 10-August-2016 + * @brief LPS22HB driver header file + ****************************************************************************** + * @attention + * + * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of STMicroelectronics nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************** + */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __LPS22HB_DRIVER__H +#define __LPS22HB_DRIVER__H + +#include <stdint.h> + +#ifdef __cplusplus +extern "C" { +#endif + +// the user must include the proper file where HAL_read_reg and HAL_write_reg are implemented +//#include "HAL_EnvSensors.h" + +/* Uncomment the line below to expanse the "assert_param" macro in the drivers code */ +//#define USE_FULL_ASSERT_LPS22HB + +/* Exported macro ------------------------------------------------------------*/ +#ifdef USE_FULL_ASSERT_LPS22HB + +/** +* @brief The assert_param macro is used for function's parameters check. +* @param expr: If expr is false, it calls assert_failed function which reports +* the name of the source file and the source line number of the call +* that failed. If expr is true, it returns no value. +* @retval None +*/ +#define LPS22HB_assert_param(expr) ((expr) ? (void)0 : LPS22HB_assert_failed((uint8_t *)__FILE__, __LINE__)) +/* Exported functions ------------------------------------------------------- */ +void LPS22HB_assert_failed(uint8_t* file, uint32_t line); +#else +#define LPS22HB_assert_param(expr) ((void)0) +#endif /* USE_FULL_ASSERT_LPS22HB */ + + /** @addtogroup Environmental_Sensor + * @{ + */ + + /** @addtogroup LPS22HB_DRIVER + * @{ + */ + + /* Exported Types -------------------------------------------------------------*/ + /** @defgroup LPS22HB_Exported_Types + * @{ + */ + + /** + * @brief Error type. + */ + typedef enum {LPS22HB_OK = (uint8_t)0, LPS22HB_ERROR = !LPS22HB_OK} LPS22HB_Error_et; + + /** + * @brief Enable/Disable type. + */ + typedef enum {LPS22HB_DISABLE = (uint8_t)0, LPS22HB_ENABLE = !LPS22HB_DISABLE} LPS22HB_State_et; +#define IS_LPS22HB_State(MODE) ((MODE == LPS22HB_ENABLE) || (MODE == LPS22HB_DISABLE) ) + + /** + * @brief Bit status type. + */ + typedef enum {LPS22HB_RESET = (uint8_t)0, LPS22HB_SET = !LPS22HB_RESET} LPS22HB_BitStatus_et; +#define IS_LPS22HB_BitStatus(MODE) ((MODE == LPS22HB_RESET) || (MODE == LPS22HB_SET)) + + /*RES_CONF see LC_EN bit*/ + /** +* @brief LPS22HB Power/Noise Mode configuration. +*/ +typedef enum { + LPS22HB_LowNoise = (uint8_t)0x00, /*!< Low Noise mode */ + LPS22HB_LowPower = (uint8_t)0x01 /*!< Low Current mode */ +} LPS22HB_PowerMode_et; + +#define IS_LPS22HB_PowerMode(MODE) ((MODE == LPS22HB_LowNoise) || (MODE == LPS22HB_LowPower)) + +/** +* @brief Output data rate configuration. +*/ +typedef enum { + + LPS22HB_ODR_ONE_SHOT = (uint8_t)0x00, /*!< Output Data Rate: one shot */ + LPS22HB_ODR_1HZ = (uint8_t)0x10, /*!< Output Data Rate: 1Hz */ + LPS22HB_ODR_10HZ = (uint8_t)0x20, /*!< Output Data Rate: 10Hz */ + LPS22HB_ODR_25HZ = (uint8_t)0x30, /*!< Output Data Rate: 25Hz */ + LPS22HB_ODR_50HZ = (uint8_t)0x40, /*!< Output Data Rate: 50Hz */ + LPS22HB_ODR_75HZ = (uint8_t)0x50 /*!< Output Data Rate: 75Hz */ +} LPS22HB_Odr_et; + +#define IS_LPS22HB_ODR(ODR) ((ODR == LPS22HB_ODR_ONE_SHOT) || (ODR == LPS22HB_ODR_1HZ) || \ +(ODR == LPS22HB_ODR_10HZ) || (ODR == LPS22HB_ODR_25HZ)|| (ODR == LPS22HB_ODR_50HZ) || (ODR == LPS22HB_ODR_75HZ)) + +/** +* @brief Low Pass Filter Cutoff Configuration. +*/ +typedef enum { + + LPS22HB_ODR_9 = (uint8_t)0x00, /*!< Filter Cutoff ODR/9 */ + LPS22HB_ODR_20 = (uint8_t)0x04 /*!< Filter Cutoff ODR/20 */ +} LPS22HB_LPF_Cutoff_et; + +#define IS_LPS22HB_LPF_Cutoff(CUTOFF) ((CUTOFF == LPS22HB_ODR_9) || (CUTOFF == LPS22HB_ODR_20) ) + +/** +* @brief Block data update. +*/ + +typedef enum { + LPS22HB_BDU_CONTINUOUS_UPDATE = (uint8_t)0x00, /*!< Data updated continuously */ + LPS22HB_BDU_NO_UPDATE = (uint8_t)0x02 /*!< Data updated after a read operation */ +} LPS22HB_Bdu_et; +#define IS_LPS22HB_BDUMode(MODE) ((MODE == LPS22HB_BDU_CONTINUOUS_UPDATE) || (MODE == LPS22HB_BDU_NO_UPDATE)) + +/** +* @brief LPS22HB Spi Mode configuration. +*/ +typedef enum { + LPS22HB_SPI_4_WIRE = (uint8_t)0x00, + LPS22HB_SPI_3_WIRE = (uint8_t)0x01 +} LPS22HB_SPIMode_et; + +#define IS_LPS22HB_SPIMode(MODE) ((MODE == LPS22HB_SPI_4_WIRE) || (MODE == LPS22HB_SPI_3_WIRE)) + + +/** +* @brief LPS22HB Interrupt Active Level Configuration (on High or Low) +*/ +typedef enum +{ + LPS22HB_ActiveHigh = (uint8_t)0x00, + LPS22HB_ActiveLow = (uint8_t)0x80 +}LPS22HB_InterruptActiveLevel_et; +#define IS_LPS22HB_InterruptActiveLevel(MODE) ((MODE == LPS22HB_ActiveHigh) || (MODE == LPS22HB_ActiveLow)) + +/** +* @brief LPS22HB Push-pull/Open Drain selection on Interrupt pads. +*/ +typedef enum +{ + LPS22HB_PushPull = (uint8_t)0x00, + LPS22HB_OpenDrain = (uint8_t)0x40 +}LPS22HB_OutputType_et; +#define IS_LPS22HB_OutputType(MODE) ((MODE == LPS22HB_PushPull) || (MODE == LPS22HB_OpenDrain)) + + +/** +* @brief Data Signal on INT pad control bits. +*/ +typedef enum +{ + LPS22HB_DATA = (uint8_t)0x00, + LPS22HB_P_HIGH = (uint8_t)0x01, + LPS22HB_P_LOW = (uint8_t)0x02, + LPS22HB_P_LOW_HIGH = (uint8_t)0x03 +}LPS22HB_OutputSignalConfig_et; +#define IS_LPS22HB_OutputSignal(MODE) ((MODE == LPS22HB_DATA) || (MODE == LPS22HB_P_HIGH)||\ +(MODE == LPS22HB_P_LOW) || (MODE == LPS22HB_P_LOW_HIGH)) + + + +/** +* @brief LPS22HB Interrupt Differential Status. +*/ + +typedef struct +{ + uint8_t PH; /*!< High Differential Pressure event occured */ + uint8_t PL; /*!< Low Differential Pressure event occured */ + uint8_t IA; /*!< One or more interrupt events have been generated.Interrupt Active */ + uint8_t BOOT; /*!< i '1' indicates that the Boot (Reboot) phase is running */ +}LPS22HB_InterruptDiffStatus_st; + + +/** +* @brief LPS22HB Pressure and Temperature data status. +*/ +typedef struct +{ + uint8_t TempDataAvailable; /*!< Temperature data available bit */ + uint8_t PressDataAvailable; /*!< Pressure data available bit */ + uint8_t TempDataOverrun; /*!< Temperature data over-run bit */ + uint8_t PressDataOverrun; /*!< Pressure data over-run bit */ +}LPS22HB_DataStatus_st; + + +/** +* @brief LPS22HB Clock Tree configuration. +*/ +typedef enum { + LPS22HB_CTE_NotBalanced = (uint8_t)0x00, + LPS22HB_CTE_Balanced = (uint8_t)0x20 +} LPS22HB_CTE_et; + +#define IS_LPS22HB_CTE(MODE) ((MODE == LPS22HB_CTE_NotBalanced) || (MODE == LPS22HB_CTE_Balanced)) + +/** +* @brief LPS22HB Fifo Mode. +*/ + +typedef enum { + LPS22HB_FIFO_BYPASS_MODE = (uint8_t)0x00, /*!< The FIFO is disabled and empty. The pressure is read directly*/ + LPS22HB_FIFO_MODE = (uint8_t)0x20, /*!< Stops collecting data when full */ + LPS22HB_FIFO_STREAM_MODE = (uint8_t)0x40, /*!< Keep the newest measurements in the FIFO*/ + LPS22HB_FIFO_TRIGGER_STREAMTOFIFO_MODE = (uint8_t)0x60, /*!< STREAM MODE until trigger deasserted, then change to FIFO MODE*/ + LPS22HB_FIFO_TRIGGER_BYPASSTOSTREAM_MODE = (uint8_t)0x80, /*!< BYPASS MODE until trigger deasserted, then STREAM MODE*/ + LPS22HB_FIFO_TRIGGER_BYPASSTOFIFO_MODE = (uint8_t)0xE0 /*!< BYPASS mode until trigger deasserted, then FIFO MODE*/ +} LPS22HB_FifoMode_et; + +#define IS_LPS22HB_FifoMode(MODE) ((MODE == LPS22HB_FIFO_BYPASS_MODE) || (MODE ==LPS22HB_FIFO_MODE)||\ +(MODE == LPS22HB_FIFO_STREAM_MODE) || (MODE == LPS22HB_FIFO_TRIGGER_STREAMTOFIFO_MODE)||\ + (MODE == LPS22HB_FIFO_TRIGGER_BYPASSTOSTREAM_MODE) || (MODE == LPS22HB_FIFO_TRIGGER_BYPASSTOFIFO_MODE)) + + +/** +* @brief LPS22HB Fifo Satus. +*/ +typedef struct { + uint8_t FIFO_LEVEL; /*!< FIFO Stored data level: 00000: FIFO empty; 10000: FIFO is FULL and ha 32 unread samples */ + uint8_t FIFO_EMPTY; /*!< Empty FIFO Flag .1 FIFO is empty (see FIFO_level) */ + uint8_t FIFO_FULL; /*!< Full FIFO flag.1 FIFO is Full (see FIFO_level) */ + uint8_t FIFO_OVR; /*!< Overrun bit status. 1 FIFO is full and at least one sample in the FIFO has been overwritten */ + uint8_t FIFO_FTH; /*!< FIFO Threshold (Watermark) Status. 1 FIFO filling is equal or higher then FTH (wtm) level.*/ +}LPS22HB_FifoStatus_st; + + + +/** +* @brief LPS22HB Configuration structure definition. +*/ +typedef struct +{ + LPS22HB_PowerMode_et PowerMode; /*!< Enable Low Current Mode (low Power) or Low Noise Mode*/ + LPS22HB_Odr_et OutputDataRate; /*!< Output Data Rate */ + LPS22HB_Bdu_et BDU; /*!< Enable to inhibit the output registers update between the reading of upper and lower register parts.*/ + LPS22HB_State_et LowPassFilter; /*!< Enable/ Disable Low Pass Filter */ + LPS22HB_LPF_Cutoff_et LPF_Cutoff; /*!< Low Pass Filter Configuration */ + LPS22HB_SPIMode_et Sim; /*!< SPI Serial Interface Mode selection */ + LPS22HB_State_et IfAddInc; /*!< Enable/Disable Register address automatically inceremented during a multiple byte access */ +}LPS22HB_ConfigTypeDef_st; + + + /** +* @brief LPS22HB Interrupt structure definition . +*/ +typedef struct { + LPS22HB_InterruptActiveLevel_et INT_H_L; /*!< Interrupt active high, low. Default value: 0 */ + LPS22HB_OutputType_et PP_OD; /*!< Push-pull/open drain selection on interrupt pads. Default value: 0 */ + LPS22HB_OutputSignalConfig_et OutputSignal_INT; /*!< Data signal on INT Pad: Data,Pressure High, Preessure Low,P High or Low*/ + LPS22HB_State_et DRDY; /*!< Enable/Disable Data Ready Interrupt on INT_DRDY Pin*/ + LPS22HB_State_et FIFO_OVR; /*!< Enable/Disable FIFO Overrun Interrupt on INT_DRDY Pin*/ + LPS22HB_State_et FIFO_FTH; /*!< Enable/Disable FIFO threshold (Watermark) interrupt on INT_DRDY pin.*/ + LPS22HB_State_et FIFO_FULL; /*!< Enable/Disable FIFO FULL interrupt on INT_DRDY pin.*/ + LPS22HB_State_et LatchIRQ; /*!< Latch Interrupt request in to INT_SOURCE reg*/ + int16_t THS_threshold; /*!< Threshold value for pressure interrupt generation*/ + LPS22HB_State_et AutoRifP; /*!< Enable/Disable AutoRifP function */ + LPS22HB_State_et AutoZero; /*!< Enable/Disable AutoZero function */ +}LPS22HB_InterruptTypeDef_st; + +/** +* @brief LPS22HB FIFO structure definition. +*/ +typedef struct { + LPS22HB_FifoMode_et FIFO_MODE; /*!< Fifo Mode Selection */ + LPS22HB_State_et WTM_INT; /*!< Enable/Disable the watermark interrupt*/ + uint8_t WTM_LEVEL; /*!< FIFO threshold/Watermark level selection*/ +}LPS22HB_FIFOTypeDef_st; + +#define IS_LPS22HB_WtmLevel(LEVEL) ((LEVEL > 0) && (LEVEL <=31)) +/** +* @brief LPS22HB Measure Type definition. +*/ +typedef struct { + int16_t Tout; + int32_t Pout; +}LPS22HB_MeasureTypeDef_st; + + +/** +* @brief LPS22HB Driver Version Info structure definition. +*/ +typedef struct { + uint8_t Major; + uint8_t Minor; + uint8_t Point; +}LPS22HB_driverVersion_st; + + +/** +* @brief Bitfield positioning. +*/ +#define LPS22HB_BIT(x) ((uint8_t)x) + +/** +* @brief I2C address. +*/ +/* SD0/SA0(pin 5) is connected to the voltage supply */ +#define LPS22HB_ADDRESS_HIGH 0xBA /**< LPS22HB I2C Address High */ +/* SDO/SA0 (pin5) is connected to the GND */ +#define LPS22HB_ADDRESS_LOW 0xB8 /**< LPS22HB I2C Address Low */ + +/** +* @brief Set the LPS22HB driver version. +*/ + +#define LPS22HB_driverVersion_Major (uint8_t)1 +#define LPS22HB_driverVersion_Minor (uint8_t)0 +#define LPS22HB_driverVersion_Point (uint8_t)0 + +/** +* @} +*/ + + +/* Exported Constants ---------------------------------------------------------*/ +/** @defgroup LPS22HB_Exported_Constants +* @{ +*/ + + +/** +* @addtogroup LPS22HB_Register +* @{ +*/ + + + +/** +* @brief Device Identification register. +* \code +* Read +* Default value: 0xB1 +* 7:0 This read-only register contains the device identifier that, for LPS22HB, is set to B1h. +* \endcode +*/ + +#define LPS22HB_WHO_AM_I_REG (uint8_t)0x0F + +/** +* @brief Device Identification value. +*/ +#define LPS22HB_WHO_AM_I_VAL (uint8_t)0xB1 + + +/** +* @brief Reference Pressure Register(LSB data) +* \code +* Read/write +* Default value: 0x00 +* 7:0 REFL7-0: Lower part of the reference pressure value that +* is sum to the sensor output pressure. +* \endcode +*/ +#define LPS22HB_REF_P_XL_REG (uint8_t)0x15 + + +/** +* @brief Reference Pressure Register (Middle data) +* \code +* Read/write +* Default value: 0x00 +* 7:0 REFL15-8: Middle part of the reference pressure value that +* is sum to the sensor output pressure. +* \endcode +*/ +#define LPS22HB_REF_P_L_REG (uint8_t)0x16 + +/** +* @brief Reference Pressure Register (MSB data) +* \code +* Read/write +* Default value: 0x00 +* 7:0 REFL23-16 Higest part of the reference pressure value that +* is sum to the sensor output pressure. +* \endcode +*/ +#define LPS22HB_REF_P_H_REG (uint8_t)0x17 + + +/** +* @brief Pressure and temperature resolution mode Register +* \code +* Read/write +* Default value: 0x05 +* 7:2 These bits must be set to 0 for proper operation of the device +* 1: Reserved +* 0 LC_EN: Low Current Mode Enable. Default 0 +* \endcode +*/ +#define LPS22HB_RES_CONF_REG (uint8_t)0x1A + +#define LPS22HB_LCEN_MASK (uint8_t)0x01 + +/** +* @brief Control Register 1 +* \code +* Read/write +* Default value: 0x00 +* 7: This bit must be set to 0 for proper operation of the device +* 6:4 ODR2, ODR1, ODR0: output data rate selection.Default 000 +* ODR2 | ODR1 | ODR0 | Pressure output data-rate(Hz) | Pressure output data-rate(Hz) +* ---------------------------------------------------------------------------------- +* 0 | 0 | 0 | one shot | one shot +* 0 | 0 | 1 | 1 | 1 +* 0 | 1 | 0 | 10 | 10 +* 0 | 1 | 1 | 25 | 25 +* 1 | 0 | 0 | 50 | 50 +* 1 | 0 | 1 | 75 | 75 +* 1 | 1 | 0 | Reserved | Reserved +* 1 | 1 | 1 | Reserved | Reserved +* +* 3 EN_LPFP: Enable Low Pass filter on Pressure data. Default value:0 +* 2:LPF_CFG Low-pass configuration register. (0: Filter cutoff is ODR/9; 1: filter cutoff is ODR/20) +* 1 BDU: block data update. 0 - continuous update; 1 - output registers not updated until MSB and LSB reading. +* 0 SIM: SPI Serial Interface Mode selection. 0 - SPI 4-wire; 1 - SPI 3-wire +* \endcode +*/ +#define LPS22HB_CTRL_REG1 (uint8_t)0x10 + +#define LPS22HB_ODR_MASK (uint8_t)0x70 +#define LPS22HB_LPFP_MASK (uint8_t)0x08 +#define LPS22HB_LPFP_CUTOFF_MASK (uint8_t)0x04 +#define LPS22HB_BDU_MASK (uint8_t)0x02 +#define LPS22HB_SIM_MASK (uint8_t)0x01 + +#define LPS22HB_LPFP_BIT LPS22HB_BIT(3) + + +/** +* @brief Control Register 2 +* \code +* Read/write +* Default value: 0x10 +* 7 BOOT: Reboot memory content. 0: normal mode; 1: reboot memory content. Self-clearing upon completation +* 6 FIFO_EN: FIFO Enable. 0: disable; 1: enable +* 5 STOP_ON_FTH: Stop on FIFO Threshold FIFO Watermark level use. 0: disable; 1: enable +* 4 IF_ADD_INC: Register address automatically incrementeed during a multiple byte access with a serial interface (I2C or SPI). Default value 1.( 0: disable; 1: enable) +* 3 I2C DIS: Disable I2C interface 0: I2C Enabled; 1: I2C disabled +* 2 SWRESET: Software reset. 0: normal mode; 1: SW reset. Self-clearing upon completation +* 1 AUTO_ZERO: Autozero enable. 0: normal mode; 1: autozero enable. +* 0 ONE_SHOT: One shot enable. 0: waiting for start of conversion; 1: start for a new dataset +* \endcode +*/ +#define LPS22HB_CTRL_REG2 (uint8_t)0x11 + +#define LPS22HB_BOOT_BIT LPS22HB_BIT(7) +#define LPS22HB_FIFO_EN_BIT LPS22HB_BIT(6) +#define LPS22HB_WTM_EN_BIT LPS22HB_BIT(5) +#define LPS22HB_ADD_INC_BIT LPS22HB_BIT(4) +#define LPS22HB_I2C_BIT LPS22HB_BIT(3) +#define LPS22HB_SW_RESET_BIT LPS22HB_BIT(2) + +#define LPS22HB_FIFO_EN_MASK (uint8_t)0x40 +#define LPS22HB_WTM_EN_MASK (uint8_t)0x20 +#define LPS22HB_ADD_INC_MASK (uint8_t)0x10 +#define LPS22HB_I2C_MASK (uint8_t)0x08 +#define LPS22HB_ONE_SHOT_MASK (uint8_t)0x01 + + +/** +* @brief CTRL Reg3 Interrupt Control Register +* \code +* Read/write +* Default value: 0x00 +* 7 INT_H_L: Interrupt active high, low. 0:active high; 1: active low. +* 6 PP_OD: Push-Pull/OpenDrain selection on interrupt pads. 0: Push-pull; 1: open drain. +* 5 F_FSS5: FIFO full flag on INT_DRDY pin. Defaul value: 0. (0: Diasable; 1 : Enable). +* 4 F_FTH: FIFO threshold (watermark) status on INT_DRDY pin. Defaul value: 0. (0: Diasable; 1 : Enable). +* 3 F_OVR: FIFO overrun interrupt on INT_DRDY pin. Defaul value: 0. (0: Diasable; 1 : Enable). +* 2 DRDY: Data-ready signal on INT_DRDY pin. Defaul value: 0. (0: Diasable; 1 : Enable). +* 1:0 INT_S2, INT_S1: data signal on INT pad control bits. +* INT_S2 | INT_S1 | INT pin +* ------------------------------------------------------ +* 0 | 0 | Data signal( in order of priority:PTH_DRDY or F_FTH or F_OVR_or F_FSS5 +* 0 | 1 | Pressure high (P_high) +* 1 | 0 | Pressure low (P_low) +* 1 | 1 | P_low OR P_high +* \endcode +*/ +#define LPS22HB_CTRL_REG3 (uint8_t)0x12 + +#define LPS22HB_PP_OD_BIT LPS22HB_BIT(6) +#define LPS22HB_FIFO_FULL_BIT LPS22HB_BIT(5) +#define LPS22HB_FIFO_FTH_BIT LPS22HB_BIT(4) +#define LPS22HB_FIFO_OVR_BIT LPS22HB_BIT(3) +#define LPS22HB_DRDY_BIT LPS22HB_BIT(2) + + +#define LPS22HB_INT_H_L_MASK (uint8_t)0x80 +#define LPS22HB_PP_OD_MASK (uint8_t)0x40 +#define LPS22HB_FIFO_FULL_MASK (uint8_t)0x20 +#define LPS22HB_FIFO_FTH_MASK (uint8_t)0x10 +#define LPS22HB_FIFO_OVR_MASK (uint8_t)0x08 +#define LPS22HB_DRDY_MASK (uint8_t)0x04 +#define LPS22HB_INT_S12_MASK (uint8_t)0x03 + + +/** +* @brief Interrupt Differential configuration Register +* \code +* Read/write +* Default value: 0x00. +* 7 AUTORIFP: AutoRifP Enable ?? +* 6 RESET_ARP: Reset AutoRifP function +* 4 AUTOZERO: Autozero enabled +* 5 RESET_AZ: Reset Autozero Function +* 3 DIFF_EN: Interrupt generation enable +* 2 LIR: Latch Interrupt request into INT_SOURCE register. 0 - interrupt request not latched; 1 - interrupt request latched +* 1 PL_E: Enable interrupt generation on differential pressure low event. 0 - disable; 1 - enable +* 0 PH_E: Enable interrupt generation on differential pressure high event. 0 - disable; 1 - enable +* \endcode +*/ +#define LPS22HB_INTERRUPT_CFG_REG (uint8_t)0x0B + +#define LPS22HB_DIFF_EN_BIT LPS22HB_BIT(3) +#define LPS22HB_LIR_BIT LPS22HB_BIT(2) +#define LPS22HB_PLE_BIT LPS22HB_BIT(1) +#define LPS22HB_PHE_BIT LPS22HB_BIT(0) + +#define LPS22HB_AUTORIFP_MASK (uint8_t)0x80 +#define LPS22HB_RESET_ARP_MASK (uint8_t)0x40 +#define LPS22HB_AUTOZERO_MASK (uint8_t)0x20 +#define LPS22HB_RESET_AZ_MASK (uint8_t)0x10 +#define LPS22HB_DIFF_EN_MASK (uint8_t)0x08 +#define LPS22HB_LIR_MASK (uint8_t)0x04 +#define LPS22HB_PLE_MASK (uint8_t)0x02 +#define LPS22HB_PHE_MASK (uint8_t)0x01 + + + +/** +* @brief Interrupt source Register (It is cleared by reading it) +* \code +* Read +* Default value: ----. +* 7 BOOT_STATUS: If 1 indicates that the Boot (Reboot) phase is running. +* 6:3 Reserved: Keep these bits at 0 +* 2 IA: Interrupt Active.0: no interrupt has been generated; 1: one or more interrupt events have been generated. +* 1 PL: Differential pressure Low. 0: no interrupt has been generated; 1: Low differential pressure event has occurred. +* 0 PH: Differential pressure High. 0: no interrupt has been generated; 1: High differential pressure event has occurred. +* \endcode +*/ +#define LPS22HB_INTERRUPT_SOURCE_REG (uint8_t)0x25 + +#define LPS22HB_BOOT_STATUS_BIT LPS22HB_BIT(7) +#define LPS22HB_IA_BIT LPS22HB_BIT(2) +#define LPS22HB_PL_BIT LPS22HB_BIT(1) +#define LPS22HB_PH_BIT LPS22HB_BIT(0) + +#define LPS22HB_BOOT_STATUS_MASK (uint8_t)0x80 +#define LPS22HB_IA_MASK (uint8_t)0x04 +#define LPS22HB_PL_MASK (uint8_t)0x02 +#define LPS22HB_PH_MASK (uint8_t)0x01 + + +/** +* @brief Status Register +* \code +* Read +* Default value: --- +* 7:6 Reserved: 0 +* 5 T_OR: Temperature data overrun. 0: no overrun has occurred; 1: a new data for temperature has overwritten the previous one. +* 4 P_OR: Pressure data overrun. 0: no overrun has occurred; 1: new data for pressure has overwritten the previous one. +* 3:2 Reserved: 0 +* 1 T_DA: Temperature data available. 0: new data for temperature is not yet available; 1: new data for temperature is available. +* 0 P_DA: Pressure data available. 0: new data for pressure is not yet available; 1: new data for pressure is available. +* \endcode +*/ +#define LPS22HB_STATUS_REG (uint8_t)0x27 + +#define LPS22HB_TOR_BIT LPS22HB_BIT(5) +#define LPS22HB_POR_BIT LPS22HB_BIT(4) +#define LPS22HB_TDA_BIT LPS22HB_BIT(1) +#define LPS22HB_PDA_BIT LPS22HB_BIT(0) + +#define LPS22HB_TOR_MASK (uint8_t)0x20 +#define LPS22HB_POR_MASK (uint8_t)0x10 +#define LPS22HB_TDA_MASK (uint8_t)0x02 +#define LPS22HB_PDA_MASK (uint8_t)0x01 + + + +/** +* @brief Pressure data (LSB) register. +* \code +* Read +* Default value: 0x00.(To be verified) +* POUT7 - POUT0: Pressure data LSB (2's complement). +* Pressure output data: Pout(hPA)=(PRESS_OUT_H & PRESS_OUT_L & +* PRESS_OUT_XL)[dec]/4096. +* \endcode +*/ + +#define LPS22HB_PRESS_OUT_XL_REG (uint8_t)0x28 +/** +* @brief Pressure data (Middle part) register. +* \code +* Read +* Default value: 0x80. +* POUT15 - POUT8: Pressure data middle part (2's complement). +* Pressure output data: Pout(hPA)=(PRESS_OUT_H & PRESS_OUT_L & +* PRESS_OUT_XL)[dec]/4096. +* \endcode +*/ +#define LPS22HB_PRESS_OUT_L_REG (uint8_t)0x29 + +/** +* @brief Pressure data (MSB) register. +* \code +* Read +* Default value: 0x2F. +* POUT23 - POUT16: Pressure data MSB (2's complement). +* Pressure output data: Pout(hPA)=(PRESS_OUT_H & PRESS_OUT_L & +* PRESS_OUT_XL)[dec]/4096. +* \endcode +*/ +#define LPS22HB_PRESS_OUT_H_REG (uint8_t)0x2A + +/** +* @brief Temperature data (LSB) register. +* \code +* Read +* Default value: 0x00. +* TOUT7 - TOUT0: temperature data LSB. +* Tout(degC)=TEMP_OUT/100 +* \endcode +*/ +#define LPS22HB_TEMP_OUT_L_REG (uint8_t)0x2B + +/** +* @brief Temperature data (MSB) register. +* \code +* Read +* Default value: 0x00. +* TOUT15 - TOUT8: temperature data MSB. +* Tout(degC)=TEMP_OUT/100 +* \endcode +*/ +#define LPS22HBH_TEMP_OUT_H_REG (uint8_t)0x2C + +/** +* @brief Threshold pressure (LSB) register. +* \code +* Read/write +* Default value: 0x00. +* 7:0 THS7-THS0: LSB Threshold pressure Low part of threshold value for pressure interrupt +* generation. The complete threshold value is given by THS_P_H & THS_P_L and is +* expressed as unsigned number. P_ths(hPA)=(THS_P_H & THS_P_L)[dec]/16. +* \endcode +*/ +#define LPS22HB_THS_P_LOW_REG (uint8_t)0x0C + +/** +* @brief Threshold pressure (MSB) +* \code +* Read/write +* Default value: 0x00. +* 7:0 THS15-THS8: MSB Threshold pressure. High part of threshold value for pressure interrupt +* generation. The complete threshold value is given by THS_P_H & THS_P_L and is +* expressed as unsigned number. P_ths(mbar)=(THS_P_H & THS_P_L)[dec]/16. +* \endcode +*/ +#define LPS22HB_THS_P_HIGH_REG (uint8_t)0x0D + +/** +* @brief FIFO control register +* \code +* Read/write +* Default value: 0x00 +* 7:5 F_MODE2, F_MODE1, F_MODE0: FIFO mode selection. +* FM2 | FM1 | FM0 | FIFO MODE +* --------------------------------------------------- +* 0 | 0 | 0 | BYPASS MODE +* 0 | 0 | 1 | FIFO MODE. Stops collecting data when full +* 0 | 1 | 0 | STREAM MODE: Keep the newest measurements in the FIFO +* 0 | 1 | 1 | STREAM MODE until trigger deasserted, then change to FIFO MODE +* 1 | 0 | 0 | BYPASS MODE until trigger deasserted, then STREAM MODE +* 1 | 0 | 1 | Reserved for future use +* 1 | 1 | 0 | Reserved +* 1 | 1 | 1 | BYPASS mode until trigger deasserted, then FIFO MODE +* +* 4:0 WTM_POINT4-0 : FIFO Watermark level selection (0-31) +*/ +#define LPS22HB_CTRL_FIFO_REG (uint8_t)0x14 + +#define LPS22HB_FIFO_MODE_MASK (uint8_t)0xE0 +#define LPS22HB_WTM_POINT_MASK (uint8_t)0x1F + + +/** +* @brief FIFO Status register +* \code +* Read +* Default value: ---- +* 7 FTH_FIFO: FIFO threshold status. 0:FIFO filling is lower than FTH level; 1: FIFO is equal or higher than FTH level. +* 6 OVR: Overrun bit status. 0 - FIFO not full; 1 -FIFO is full and at least one sample in the FIFO has been overwritten. +* 5:0 FSS: FIFO Stored data level. 000000: FIFO empty, 100000: FIFO is full and has 32 unread samples. +* \endcode +*/ +#define LPS22HB_STATUS_FIFO_REG (uint8_t)0x26 + +#define LPS22HB_FTH_FIFO_BIT LPS22HB_BIT(7) +#define LPS22HB_OVR_FIFO_BIT LPS22HB_BIT(6) + +#define LPS22HB_FTH_FIFO_MASK (uint8_t)0x80 +#define LPS22HB_OVR_FIFO_MASK (uint8_t)0x40 +#define LPS22HB_LEVEL_FIFO_MASK (uint8_t)0x3F +#define LPS22HB_FIFO_EMPTY (uint8_t)0x00 +#define LPS22HB_FIFO_FULL (uint8_t)0x20 + + + +/** +* @brief Pressure offset register (LSB) +* \code +* Read/write +* Default value: 0x00 +* 7:0 RPDS7-0:Pressure Offset for 1 point calibration (OPC) after soldering. +* This register contains the low part of the pressure offset value after soldering,for +* differential pressure computing. The complete value is given by RPDS_L & RPDS_H +* and is expressed as signed 2 complement value. +* \endcode +*/ +#define LPS22HB_RPDS_L_REG (uint8_t)0x18 + +/** +* @brief Pressure offset register (MSB) +* \code +* Read/write +* Default value: 0x00 +* 7:0 RPDS15-8:Pressure Offset for 1 point calibration (OPC) after soldering. +* This register contains the high part of the pressure offset value after soldering (see description RPDS_L) +* \endcode +*/ +#define LPS22HB_RPDS_H_REG (uint8_t)0x19 + + +/** +* @brief Clock Tree Configuration register +* \code +* Read/write +* Default value: 0x00 +* 7:6 Reserved. +* 5: CTE: Clock Tree Enhancement +* \endcode +*/ + +#define LPS22HB_CLOCK_TREE_CONFIGURATION (uint8_t)0x43 + +#define LPS22HB_CTE_MASK (uint8_t)0x20 + +/** +* @} +*/ + + +/** +* @} +*/ + + +/* Exported Functions -------------------------------------------------------------*/ +/** @defgroup LPS22HB_Exported_Functions +* @{ +*/ + +LPS22HB_Error_et LPS22HB_read_reg( void *handle, uint8_t RegAddr, uint16_t NumByteToRead, uint8_t *Data ); +LPS22HB_Error_et LPS22HB_write_reg( void *handle, uint8_t RegAddr, uint16_t NumByteToWrite, uint8_t *Data ); + +/** +* @brief Init the HAL layer. +* @param None +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +#define LPS22HB_HalInit (LPS22HB_Error_et)HAL_Init_I2C + +/** +* @brief DeInit the HAL layer. +* @param None +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +#define LPS22HB_HalDeInit (LPS22HB_Error_et)HAL_DeInit_I2C + + +/** +* @brief Get the LPS22HB driver version. +* @param None +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Get_DriverVersion(LPS22HB_driverVersion_st *Version); + +/** +* @brief Initialization function for LPS22HB. +* This function make a memory boot. +* Init the sensor with a standard basic confifuration. +* Low Power, ODR 25 Hz, Low Pass Filter disabled; BDU enabled; I2C enabled; +* NO FIFO; NO Interrupt Enabled. +* @param None. +* @retval Error code[LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Init(void *handle); + +/** +* @brief DeInit the LPS2Hb driver. +* @param None +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ + +LPS22HB_Error_et LPS22HB_DeInit(void *handle); + + +/** +* @brief Read identification code by WHO_AM_I register +* @param Buffer to empty by Device identification Value. +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Get_DeviceID(void *handle, uint8_t* deviceid); + + +/** +* @brief Set LPS22HB Low Power or Low Noise Mode Configuration +* @param LPS22HB_LowNoise or LPS22HB_LowPower mode +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Set_PowerMode(void *handle, LPS22HB_PowerMode_et mode); + +/** +* @brief Get LPS22HB Power Mode +* @param Buffer to empty with Mode: Low Noise or Low Current +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Get_PowerMode(void *handle, LPS22HB_PowerMode_et* mode); + + +/** +* @brief Set LPS22HB Output Data Rate +* @param Output Data Rate +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Set_Odr(void *handle, LPS22HB_Odr_et odr); + + +/** +* @brief Get LPS22HB Output Data Rate +* @param Buffer to empty with Output Data Rate +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Get_Odr(void *handle, LPS22HB_Odr_et* odr); + +/** +* @brief Enable/Disale low-pass filter on LPS22HB pressure data +* @param state: enable or disable +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Set_LowPassFilter(void *handle, LPS22HB_State_et state); + + +/** +* @brief Set low-pass filter cutoff configuration on LPS22HB pressure data +* @param Filter Cutoff ODR/9 or ODR/20 +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Set_LowPassFilterCutoff(void *handle, LPS22HB_LPF_Cutoff_et cutoff); + +/** +* @brief Set Block Data Update mode +* @param LPS22HB_BDU_CONTINUOS_UPDATE/ LPS22HB_BDU_NO_UPDATE +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Set_Bdu(void *handle, LPS22HB_Bdu_et bdu); + + +/** +* @brief Get Block Data Update mode +* @param Buffer to empty whit the bdu mode read from sensor +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Get_Bdu(void *handle, LPS22HB_Bdu_et* bdu); + +/** +* @brief Set SPI mode: 3 Wire Interface OR 4 Wire Interface +* @param LPS22HB_SPI_4_WIRE/LPS22HB_SPI_3_WIRE +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Set_SpiInterface(void *handle, LPS22HB_SPIMode_et spimode); + +/** +* @brief Get SPI mode: 3 Wire Interface OR 4 Wire Interface +* @param buffer to empty with SPI mode +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Get_SpiInterface(void *handle, LPS22HB_SPIMode_et* spimode); + +/** +* @brief Software Reset +* @param void +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_SwReset(void *handle); + +/** +* @brief Reboot Memory Content. +* @param void +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_MemoryBoot(void *handle); + +/** +* @brief Software Reset ann BOOT +* @param void +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_SwResetAndMemoryBoot(void *handle); + + +/** +* @brief Enable or Disable FIFO +* @param LPS22HB_ENABLE/LPS22HB_DISABLE +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Set_FifoModeUse(void *handle, LPS22HB_State_et status); + +/** +* @brief Enable or Disable FIFO Watermark level use. Stop on FIFO Threshold +* @param LPS22HB_ENABLE/LPS22HB_DISABLE +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Set_FifoWatermarkLevelUse(void *handle, LPS22HB_State_et status); + +/** +* @brief Enable or Disable the Automatic increment register address during a multiple byte access with a serial interface (I2C or SPI) +* @param LPS22HB_ENABLE/LPS22HB_DISABLE. Default is LPS22HB_ENABLE +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Set_AutomaticIncrementRegAddress(void *handle, LPS22HB_State_et status); + + +/** +* @brief Set One Shot bit to start a new conversion (ODR mode has to be 000) +* @param void +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_StartOneShotMeasurement(void *handle); + +/** +* @brief Enable/Disable I2C +* @param State. Enable (reset bit)/ Disable (set bit) +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Set_I2C(void *handle, LPS22HB_State_et i2cstate); + + +/*CTRL_REG3 Interrupt Control*/ +/** +* @brief Set Interrupt Active on High or Low Level +* @param LPS22HB_ActiveHigh/LPS22HB_ActiveLow +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Set_InterruptActiveLevel(void *handle, LPS22HB_InterruptActiveLevel_et mode); + +/** +* @brief Set Push-pull/open drain selection on interrupt pads. +* @param LPS22HB_PushPull/LPS22HB_OpenDrain +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Set_InterruptOutputType(void *handle, LPS22HB_OutputType_et output); + +/** +* @brief Set Data signal on INT1 pad control bits. +* @param LPS22HB_DATA,LPS22HB_P_HIGH_LPS22HB_P_LOW,LPS22HB_P_LOW_HIGH +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Set_InterruptControlConfig(void *handle, LPS22HB_OutputSignalConfig_et config); + + +/** +* @brief Enable/Disable Data-ready signal on INT_DRDY pin. +* @param LPS22HB_ENABLE/LPS22HB_DISABLE +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Set_DRDYInterrupt(void *handle, LPS22HB_State_et status); + + /** +* @brief Enable/Disable FIFO overrun interrupt on INT_DRDY pin. +* @param LPS22HB_ENABLE/LPS22HB_DISABLE +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Set_FIFO_OVR_Interrupt(void *handle, LPS22HB_State_et status); + + /** +* @brief Enable/Disable FIFO threshold (Watermark) interrupt on INT_DRDY pin. +* @param LPS22HB_ENABLE/LPS22HB_DISABLE +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Set_FIFO_FTH_Interrupt(void *handle, LPS22HB_State_et status); + +/** +* @brief Enable/Disable FIFO FULL interrupt on INT_DRDY pin. +* @param LPS22HB_ENABLE/LPS22HB_DISABLE +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Set_FIFO_FULL_Interrupt(void *handle, LPS22HB_State_et status); + +/** +* @brief Enable AutoRifP function +* @param none +* @detail When this function is enabled, an internal register is set with the current pressure values +* and the content is subtracted from the pressure output value and result is used for the interrupt generation. +* the AutoRifP is slf creared. +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Set_AutoRifP(void *handle); + +/** +* @brief Disable AutoRifP +* @param none +* @detail the RESET_ARP bit is used to disable the AUTORIFP function. This bis i is selfdleared +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_ResetAutoRifP(void *handle); + +/**????? +* @brief Set AutoZero Function bit +* @detail When set to ‘1’, the actual pressure output is copied in the REF_P reg (@0x15..0x17) +* @param None +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Set_AutoZeroFunction(void *handle); + +/**??? +* @brief Set ResetAutoZero Function bit +* @details REF_P reg (@0x015..17) set pressure reference to default value RPDS reg (0x18/19). +* @param None +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_ResetAutoZeroFunction(void *handle); + + +/** +* @brief Enable/ Disable the computing of differential pressure output (Interrupt Generation) +* @param LPS22HB_ENABLE,LPS22HB_DISABLE +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Set_InterruptDifferentialGeneration(void *handle, LPS22HB_State_et diff_en) ; + + + +/** +* @brief Get the DIFF_EN bit value +* @param buffer to empty with the read value of DIFF_EN bit +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Get_InterruptDifferentialGeneration(void *handle, LPS22HB_State_et* diff_en); + + +/** +* @brief Latch Interrupt request to the INT_SOURCE register. +* @param LPS22HB_ENABLE/LPS22HB_DISABLE +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_LatchInterruptRequest(void *handle, LPS22HB_State_et status); + +/** +* @brief Enable\Disable Interrupt Generation on differential pressure Low event +* @param LPS22HB_ENABLE/LPS22HB_DISABLE +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Set_PLE(void *handle, LPS22HB_State_et status); + +/** +* @brief Enable\Disable Interrupt Generation on differential pressure High event +* @param LPS22HB_ENABLE/LPS22HB_DISABLE +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Set_PHE(void *handle, LPS22HB_State_et status); + +/** +* @brief Get the Interrupt Generation on differential pressure status event and the Boot Status. +* @detail The INT_SOURCE register is cleared by reading it. +* @param Status Event Flag: BOOT, PH,PL,IA +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Get_InterruptDifferentialEventStatus(void *handle, LPS22HB_InterruptDiffStatus_st* interruptsource); + + +/** +* @brief Get the status of Pressure and Temperature data +* @param Data Status Flag: TempDataAvailable, TempDataOverrun, PressDataAvailable, PressDataOverrun +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Get_DataStatus(void *handle, LPS22HB_DataStatus_st* datastatus); + + +/** +* @brief Get the LPS22HB raw presure value +* @param The buffer to empty with the pressure raw value +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Get_RawPressure(void *handle, int32_t *raw_press); + +/** +* @brief Get the LPS22HB Pressure value in hPA. +* @param The buffer to empty with the pressure value that must be divided by 100 to get the value in hPA +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Get_Pressure(void *handle, int32_t* Pout); + +/** +* @brief Read LPS22HB output register, and calculate the raw temperature. +* @param The buffer to empty with the temperature raw value +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Get_RawTemperature(void *handle, int16_t *raw_data); + +/** +* @brief Read the Temperature value in °C. +* @param The buffer to empty with the temperature value that must be divided by 10 to get the value in ['C] +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Get_Temperature(void *handle, int16_t* Tout); + +/** +* @brief Get the threshold value used for pressure interrupt generation. +* @param The buffer to empty with the temperature value +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Get_PressureThreshold(void *handle, int16_t *P_ths); + +/** +* @brief Set the threshold value used for pressure interrupt generation. +* @param The buffer to empty with the temperature value +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Set_PressureThreshold(void *handle, int16_t P_ths); + +/** +* @brief Set Fifo Mode. +* @param Fifo Mode struct +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Set_FifoMode(void *handle, LPS22HB_FifoMode_et fifomode); +/** +* @brief Get Fifo Mode. +* @param Buffer to empty with fifo mode value +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Get_FifoMode(void *handle, LPS22HB_FifoMode_et* fifomode); + +/** +* @brief Set Fifo Watermark Level. +* @param Watermark level value [0 31] +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Set_FifoWatermarkLevel(void *handle, uint8_t wtmlevel); + +/** +* @brief Get FIFO Watermark Level +* @param buffer to empty with watermak level[0,31] value read from sensor +* @retval Status [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Get_FifoWatermarkLevel(void *handle, uint8_t *wtmlevel); + + +/** +* @brief Get Fifo Status. +* @param Buffer to empty with fifo status +* @retval Status [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Get_FifoStatus(void *handle, LPS22HB_FifoStatus_st* status); + + +/** +* @brief Get the reference pressure after soldering for computing differential pressure (hPA) +* @param buffer to empty with the he pressure value (hPA) +* @retval Status [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Get_PressureOffsetValue(void *handle, int16_t *pressoffset); + +/** +* @brief Get the Reference Pressure value +* @detail It is a 24-bit data added to the sensor output measurement to detect a measured pressure beyond programmed limits. +* @param Buffer to empty with reference pressure value +* @retval Status [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Get_ReferencePressure(void *handle, int32_t* RefP); + + +/** +* @brief Check if the single measurement has completed. +* @param the returned value is set to 1, when the measurement is completed +* @retval Status [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_IsMeasurementCompleted(void *handle, uint8_t* Is_Measurement_Completed); + + +/** +* @brief Get the values of the last single measurement. +* @param Pressure and temperature value +* @retvalStatus [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Get_Measurement(void *handle, LPS22HB_MeasureTypeDef_st *Measurement_Value); + + +/** +* @brief Set Generic Configuration +* @param Struct to empty with the chosen values +* @retval Error code[LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Set_GenericConfig(void *handle, LPS22HB_ConfigTypeDef_st* pxLPS22HBInit); + +/** +* @brief Get Generic configuration +* @param Struct to empty with configuration values +* @retval Error code[LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Get_GenericConfig(void *handle, LPS22HB_ConfigTypeDef_st* pxLPS22HBInit); + +/** +* @brief Set Interrupt configuration +* @param Struct holding the configuration values +* @retval Error code[LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Set_InterruptConfig(void *handle, LPS22HB_InterruptTypeDef_st* pLPS22HBInt); + +/** +* @brief LPS22HBGet_InterruptConfig +* @param Struct to empty with configuration values +* @retval S Error code[LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Get_InterruptConfig(void *handle, LPS22HB_InterruptTypeDef_st* pLPS22HBInt); + +/** +* @brief Set Fifo configuration +* @param Struct holding the configuration values +* @retval Error code[LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Set_FifoConfig(void *handle, LPS22HB_FIFOTypeDef_st* pLPS22HBFIFO); + +/** +* @brief Get Fifo configuration +* @param Struct to empty with the configuration values +* @retval Error code[LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Get_FifoConfig(void *handle, LPS22HB_FIFOTypeDef_st* pLPS22HBFIFO); + +/** +* @brief Clock Tree Confoguration +* @param LPS22HB_CTE_NotBalanced, LPS22HB_CTE_ABalanced +* @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] +*/ +LPS22HB_Error_et LPS22HB_Set_ClockTreeConfifuration(void *handle, LPS22HB_CTE_et mode); + +/** +* @} +*/ + +/** +* @} +*/ + +/** +* @} +*/ + +#ifdef __cplusplus +} +#endif + +#endif /* __LPS22HB_DRIVER__H */ + +/******************* (C) COPYRIGHT 2013 STMicroelectronics *****END OF FILE****/
diff -r 000000000000 -r 98c301bb7d1b Components/LSM303AGRSensor/LSM303AGRAccSensor.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Components/LSM303AGRSensor/LSM303AGRAccSensor.cpp Tue Oct 03 12:21:11 2017 +0000 @@ -0,0 +1,639 @@ +/** + ****************************************************************************** + * @file LSM303AGRAccSensor.cpp + * @author CLab + * @version V1.0.0 + * @date 5 August 2016 + * @brief Implementation an LSM303AGR accelerometer sensor. + ****************************************************************************** + * @attention + * + * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of STMicroelectronics nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************** + */ + + +/* Includes ------------------------------------------------------------------*/ + +#include "DevI2C.h" +#include "LSM303AGRAccSensor.h" +#include "LSM303AGR_acc_driver.h" + + +/* Class Implementation ------------------------------------------------------*/ + +/** Constructor + * @param i2c object of an helper class which handles the I2C peripheral + * @param address the address of the component's instance + */ +LSM303AGRAccSensor::LSM303AGRAccSensor(DevI2C &i2c) : _dev_i2c(i2c) +{ + _address = LSM303AGR_ACC_I2C_ADDRESS; +}; + +/** Constructor + * @param i2c object of an helper class which handles the I2C peripheral + * @param address the address of the component's instance + */ +LSM303AGRAccSensor::LSM303AGRAccSensor(DevI2C &i2c, uint8_t address) : _dev_i2c(i2c), _address(address) +{ + +}; + +/** + * @brief Initializing the component. + * @param[in] init pointer to device specific initalization structure. + * @retval "0" in case of success, an error code otherwise. + */ +int LSM303AGRAccSensor::init(void *init) +{ + /* Enable BDU */ + if ( LSM303AGR_ACC_W_BlockDataUpdate( (void *)this, LSM303AGR_ACC_BDU_ENABLED ) == MEMS_ERROR ) + { + return 1; + } + + /* FIFO mode selection */ + if ( LSM303AGR_ACC_W_FifoMode( (void *)this, LSM303AGR_ACC_FM_BYPASS ) == MEMS_ERROR ) + { + return 1; + } + + /* Output data rate selection - power down. */ + if ( LSM303AGR_ACC_W_ODR( (void *)this, LSM303AGR_ACC_ODR_DO_PWR_DOWN ) == MEMS_ERROR ) + { + return 1; + } + + /* Full scale selection. */ + if ( set_x_fs( 2.0f ) == 1 ) + { + return 1; + } + + /* Enable axes. */ + if ( LSM303AGR_ACC_W_XEN( (void *)this, LSM303AGR_ACC_XEN_ENABLED ) == MEMS_ERROR ) + { + return 1; + } + + if ( LSM303AGR_ACC_W_YEN ( (void *)this, LSM303AGR_ACC_YEN_ENABLED ) == MEMS_ERROR ) + { + return 1; + } + + if ( LSM303AGR_ACC_W_ZEN ( (void *)this, LSM303AGR_ACC_ZEN_ENABLED ) == MEMS_ERROR ) + { + return 1; + } + + /* Select default output data rate. */ + _last_odr = 100.0f; + + _is_enabled = 0; + + return 0; +} + +/** + * @brief Enable LSM303AGR Accelerator + * @retval 0 in case of success, an error code otherwise + */ +int LSM303AGRAccSensor::enable(void) +{ + /* Check if the component is already enabled */ + if ( _is_enabled == 1 ) + { + return 0; + } + + /* Output data rate selection. */ + if ( set_x_odr_when_enabled( _last_odr ) == 1 ) + { + return 1; + } + + _is_enabled = 1; + + return 0; +} + +/** + * @brief Disable LSM303AGR Accelerator + * @retval 0 in case of success, an error code otherwise + */ +int LSM303AGRAccSensor::disable(void) +{ + /* Check if the component is already disabled */ + if ( _is_enabled == 0 ) + { + return 0; + } + + /* Store actual output data rate. */ + if ( get_x_odr( &_last_odr ) == 1 ) + { + return 1; + } + + /* Output data rate selection - power down. */ + if ( LSM303AGR_ACC_W_ODR( (void *)this, LSM303AGR_ACC_ODR_DO_PWR_DOWN ) == MEMS_ERROR ) + { + return 1; + } + + _is_enabled = 0; + + return 0; +} + +/** + * @brief Read ID of LSM303AGR Accelerometer + * @param p_id the pointer where the ID of the device is stored + * @retval 0 in case of success, an error code otherwise + */ +int LSM303AGRAccSensor::read_id(uint8_t *id) +{ + if(!id) + { + return 1; + } + + /* Read WHO AM I register */ + if ( LSM303AGR_ACC_R_WHO_AM_I( (void *)this, id ) == MEMS_ERROR ) + { + return 1; + } + + return 0; +} + +/** + * @brief Read data from LSM303AGR Accelerometer + * @param pData the pointer where the accelerometer data are stored + * @retval 0 in case of success, an error code otherwise + */ +int LSM303AGRAccSensor::get_x_axes(int32_t *pData) +{ + int data[3]; + + /* Read data from LSM303AGR. */ + if ( !LSM303AGR_ACC_Get_Acceleration((void *)this, data) ) + { + return 1; + } + + /* Calculate the data. */ + pData[0] = (int32_t)data[0]; + pData[1] = (int32_t)data[1]; + pData[2] = (int32_t)data[2]; + + return 0; +} + +/** + * @brief Read Accelerometer Sensitivity + * @param pfData the pointer where the accelerometer sensitivity is stored + * @retval 0 in case of success, an error code otherwise + */ +int LSM303AGRAccSensor::get_x_sensitivity(float *pfData) +{ + LSM303AGR_ACC_LPEN_t lp_value; + LSM303AGR_ACC_HR_t hr_value; + + /* Read low power flag */ + if( LSM303AGR_ACC_R_LOWPWR_EN( (void *)this, &lp_value ) == MEMS_ERROR ) + { + return 1; + } + + /* Read high performance flag */ + if( LSM303AGR_ACC_R_HiRes( (void *)this, &hr_value ) == MEMS_ERROR ) + { + return 1; + } + + if( lp_value == LSM303AGR_ACC_LPEN_DISABLED && hr_value == LSM303AGR_ACC_HR_DISABLED ) + { + /* Normal Mode */ + return get_x_sensitivity_normal_mode( pfData ); + } else if ( lp_value == LSM303AGR_ACC_LPEN_ENABLED && hr_value == LSM303AGR_ACC_HR_DISABLED ) + { + /* Low Power Mode */ + return get_x_sensitivity_lp_mode( pfData ); + } else if ( lp_value == LSM303AGR_ACC_LPEN_DISABLED && hr_value == LSM303AGR_ACC_HR_ENABLED ) + { + /* High Resolution Mode */ + return get_x_sensitivity_hr_mode( pfData ); + } else + { + /* Not allowed */ + return 1; + } +} + +/** + * @brief Read Accelerometer Sensitivity in Normal Mode + * @param sensitivity the pointer where the accelerometer sensitivity is stored + * @retval 0 in case of success, an error code otherwise + */ +int LSM303AGRAccSensor::get_x_sensitivity_normal_mode( float *sensitivity ) +{ + LSM303AGR_ACC_FS_t fullScale; + + /* Read actual full scale selection from sensor. */ + if ( LSM303AGR_ACC_R_FullScale( (void *)this, &fullScale ) == MEMS_ERROR ) + { + return 1; + } + + /* Store the sensitivity based on actual full scale. */ + switch( fullScale ) + { + case LSM303AGR_ACC_FS_2G: + *sensitivity = ( float )LSM303AGR_ACC_SENSITIVITY_FOR_FS_2G_NORMAL_MODE; + break; + case LSM303AGR_ACC_FS_4G: + *sensitivity = ( float )LSM303AGR_ACC_SENSITIVITY_FOR_FS_4G_NORMAL_MODE; + break; + case LSM303AGR_ACC_FS_8G: + *sensitivity = ( float )LSM303AGR_ACC_SENSITIVITY_FOR_FS_8G_NORMAL_MODE; + break; + case LSM303AGR_ACC_FS_16G: + *sensitivity = ( float )LSM303AGR_ACC_SENSITIVITY_FOR_FS_16G_NORMAL_MODE; + break; + default: + *sensitivity = -1.0f; + return 1; + } + + return 0; +} + +/** + * @brief Read Accelerometer Sensitivity in LP Mode + * @param sensitivity the pointer where the accelerometer sensitivity is stored + * @retval 0 in case of success, an error code otherwise + */ +int LSM303AGRAccSensor::get_x_sensitivity_lp_mode( float *sensitivity ) +{ + LSM303AGR_ACC_FS_t fullScale; + + /* Read actual full scale selection from sensor. */ + if ( LSM303AGR_ACC_R_FullScale( (void *)this, &fullScale ) == MEMS_ERROR ) + { + return 1; + } + + /* Store the sensitivity based on actual full scale. */ + switch( fullScale ) + { + case LSM303AGR_ACC_FS_2G: + *sensitivity = ( float )LSM303AGR_ACC_SENSITIVITY_FOR_FS_2G_LOW_POWER_MODE; + break; + case LSM303AGR_ACC_FS_4G: + *sensitivity = ( float )LSM303AGR_ACC_SENSITIVITY_FOR_FS_4G_LOW_POWER_MODE; + break; + case LSM303AGR_ACC_FS_8G: + *sensitivity = ( float )LSM303AGR_ACC_SENSITIVITY_FOR_FS_8G_LOW_POWER_MODE; + break; + case LSM303AGR_ACC_FS_16G: + *sensitivity = ( float )LSM303AGR_ACC_SENSITIVITY_FOR_FS_16G_LOW_POWER_MODE; + break; + default: + *sensitivity = -1.0f; + return 1; + } + + return 0; +} + +/** + * @brief Read Accelerometer Sensitivity in HR Mode + * @param sensitivity the pointer where the accelerometer sensitivity is stored + * @retval 0 in case of success, an error code otherwise + */ +int LSM303AGRAccSensor::get_x_sensitivity_hr_mode( float *sensitivity ) +{ + LSM303AGR_ACC_FS_t fullScale; + + /* Read actual full scale selection from sensor. */ + if ( LSM303AGR_ACC_R_FullScale( (void *)this, &fullScale ) == MEMS_ERROR ) + { + return 1; + } + + /* Store the sensitivity based on actual full scale. */ + switch( fullScale ) + { + case LSM303AGR_ACC_FS_2G: + *sensitivity = ( float )LSM303AGR_ACC_SENSITIVITY_FOR_FS_2G_HIGH_RESOLUTION_MODE; + break; + case LSM303AGR_ACC_FS_4G: + *sensitivity = ( float )LSM303AGR_ACC_SENSITIVITY_FOR_FS_4G_HIGH_RESOLUTION_MODE; + break; + case LSM303AGR_ACC_FS_8G: + *sensitivity = ( float )LSM303AGR_ACC_SENSITIVITY_FOR_FS_8G_HIGH_RESOLUTION_MODE; + break; + case LSM303AGR_ACC_FS_16G: + *sensitivity = ( float )LSM303AGR_ACC_SENSITIVITY_FOR_FS_16G_HIGH_RESOLUTION_MODE; + break; + default: + *sensitivity = -1.0f; + return 1; + } + + return 0; +} + +/** + * @brief Read raw data from LSM303AGR Accelerometer + * @param pData the pointer where the accelerometer raw data are stored + * @retval 0 in case of success, an error code otherwise + */ +int LSM303AGRAccSensor::get_x_axes_raw(int16_t *pData) +{ + uint8_t regValue[6] = {0, 0, 0, 0, 0, 0}; + u8_t shift = 0; + LSM303AGR_ACC_LPEN_t lp; + LSM303AGR_ACC_HR_t hr; + + /* Determine which operational mode the acc is set */ + if(!LSM303AGR_ACC_R_HiRes( (void *)this, &hr )) { + return 1; + } + + if(!LSM303AGR_ACC_R_LOWPWR_EN( (void *)this, &lp )) { + return 1; + } + + if (lp == LSM303AGR_ACC_LPEN_ENABLED && hr == LSM303AGR_ACC_HR_DISABLED) { + /* op mode is LP 8-bit */ + shift = 8; + } else if (lp == LSM303AGR_ACC_LPEN_DISABLED && hr == LSM303AGR_ACC_HR_DISABLED) { + /* op mode is Normal 10-bit */ + shift = 6; + } else if (lp == LSM303AGR_ACC_LPEN_DISABLED && hr == LSM303AGR_ACC_HR_ENABLED) { + /* op mode is HR 12-bit */ + shift = 4; + } else { + return 1; + } + + /* Read output registers from LSM303AGR_ACC_GYRO_OUTX_L_XL to LSM303AGR_ACC_GYRO_OUTZ_H_XL. */ + if (!LSM303AGR_ACC_Get_Raw_Acceleration( (void *)this, ( uint8_t* )regValue )) + { + return 1; + } + + /* Format the data. */ + pData[0] = ( ( ( ( ( int16_t )regValue[1] ) << 8 ) + ( int16_t )regValue[0] ) >> shift ); + pData[1] = ( ( ( ( ( int16_t )regValue[3] ) << 8 ) + ( int16_t )regValue[2] ) >> shift ); + pData[2] = ( ( ( ( ( int16_t )regValue[5] ) << 8 ) + ( int16_t )regValue[4] ) >> shift ); + + return 0; +} + +/** + * @brief Read LSM303AGR Accelerometer output data rate + * @param odr the pointer to the output data rate + * @retval 0 in case of success, an error code otherwise + */ +int LSM303AGRAccSensor::get_x_odr(float* odr) +{ + LSM303AGR_ACC_ODR_t odr_low_level; + + if ( LSM303AGR_ACC_R_ODR( (void *)this, &odr_low_level ) == MEMS_ERROR ) + { + return 1; + } + + switch( odr_low_level ) + { + case LSM303AGR_ACC_ODR_DO_PWR_DOWN: + *odr = 0.0f; + break; + case LSM303AGR_ACC_ODR_DO_1Hz: + *odr = 1.0f; + break; + case LSM303AGR_ACC_ODR_DO_10Hz: + *odr = 10.0f; + break; + case LSM303AGR_ACC_ODR_DO_25Hz: + *odr = 25.0f; + break; + case LSM303AGR_ACC_ODR_DO_50Hz: + *odr = 50.0f; + break; + case LSM303AGR_ACC_ODR_DO_100Hz: + *odr = 100.0f; + break; + case LSM303AGR_ACC_ODR_DO_200Hz: + *odr = 200.0f; + break; + case LSM303AGR_ACC_ODR_DO_400Hz: + *odr = 400.0f; + break; + default: + *odr = -1.0f; + return 1; + } + + return 0; +} + +/** + * @brief Set ODR + * @param odr the output data rate to be set + * @retval 0 in case of success, an error code otherwise + */ +int LSM303AGRAccSensor::set_x_odr(float odr) +{ + if(_is_enabled == 1) + { + if(set_x_odr_when_enabled(odr) == 1) + { + return 1; + } + } + else + { + if(set_x_odr_when_disabled(odr) == 1) + { + return 1; + } + } + + return 0; +} + +/** + * @brief Set ODR when enabled + * @param odr the output data rate to be set + * @retval 0 in case of success, an error code otherwise + */ +int LSM303AGRAccSensor::set_x_odr_when_enabled(float odr) +{ + LSM303AGR_ACC_ODR_t new_odr; + + new_odr = ( odr <= 1.0f ) ? LSM303AGR_ACC_ODR_DO_1Hz + : ( odr <= 10.0f ) ? LSM303AGR_ACC_ODR_DO_10Hz + : ( odr <= 25.0f ) ? LSM303AGR_ACC_ODR_DO_25Hz + : ( odr <= 50.0f ) ? LSM303AGR_ACC_ODR_DO_50Hz + : ( odr <= 100.0f ) ? LSM303AGR_ACC_ODR_DO_100Hz + : ( odr <= 200.0f ) ? LSM303AGR_ACC_ODR_DO_200Hz + : LSM303AGR_ACC_ODR_DO_400Hz; + + if ( LSM303AGR_ACC_W_ODR( (void *)this, new_odr ) == MEMS_ERROR ) + { + return 1; + } + + return 0; +} + +/** + * @brief Set ODR when disabled + * @param odr the output data rate to be set + * @retval 0 in case of success, an error code otherwise + */ +int LSM303AGRAccSensor::set_x_odr_when_disabled(float odr) +{ + _last_odr = ( odr <= 1.0f ) ? 1.0f + : ( odr <= 10.0f ) ? 10.0f + : ( odr <= 25.0f ) ? 25.0f + : ( odr <= 50.0f ) ? 50.0f + : ( odr <= 100.0f ) ? 100.0f + : ( odr <= 200.0f ) ? 200.0f + : 400.0f; + + return 0; +} + + +/** + * @brief Read LSM303AGR Accelerometer full scale + * @param fullScale the pointer to the full scale + * @retval 0 in case of success, an error code otherwise + */ +int LSM303AGRAccSensor::get_x_fs(float* fullScale) +{ + LSM303AGR_ACC_FS_t fs_low_level; + + if ( LSM303AGR_ACC_R_FullScale( (void *)this, &fs_low_level ) == MEMS_ERROR ) + { + return 1; + } + + switch( fs_low_level ) + { + case LSM303AGR_ACC_FS_2G: + *fullScale = 2.0f; + break; + case LSM303AGR_ACC_FS_4G: + *fullScale = 4.0f; + break; + case LSM303AGR_ACC_FS_8G: + *fullScale = 8.0f; + break; + case LSM303AGR_ACC_FS_16G: + *fullScale = 16.0f; + break; + default: + *fullScale = -1.0f; + return 1; + } + + return 0; +} + +/** + * @brief Set full scale + * @param fullScale the full scale to be set + * @retval 0 in case of success, an error code otherwise + */ +int LSM303AGRAccSensor::set_x_fs(float fullScale) +{ + LSM303AGR_ACC_FS_t new_fs; + + new_fs = ( fullScale <= 2.0f ) ? LSM303AGR_ACC_FS_2G + : ( fullScale <= 4.0f ) ? LSM303AGR_ACC_FS_4G + : ( fullScale <= 8.0f ) ? LSM303AGR_ACC_FS_8G + : LSM303AGR_ACC_FS_16G; + + if ( LSM303AGR_ACC_W_FullScale( (void *)this, new_fs ) == MEMS_ERROR ) + { + return 1; + } + + return 0; +} + +/** + * @brief Read accelerometer data from register + * @param reg register address + * @param data register data + * @retval 0 in case of success + * @retval 1 in case of failure + */ +int LSM303AGRAccSensor::read_reg( uint8_t reg, uint8_t *data ) +{ + + if ( LSM303AGR_ACC_read_reg( (void *)this, reg, data ) == MEMS_ERROR ) + { + return 1; + } + + return 0; +} + +/** + * @brief Write accelerometer data to register + * @param reg register address + * @param data register data + * @retval 0 in case of success + * @retval 1 in case of failure + */ +int LSM303AGRAccSensor::write_reg( uint8_t reg, uint8_t data ) +{ + + if ( LSM303AGR_ACC_write_reg( (void *)this, reg, data ) == MEMS_ERROR ) + { + return 1; + } + + return 0; +} + +uint8_t LSM303AGR_ACC_io_write( void *handle, uint8_t WriteAddr, uint8_t *pBuffer, uint16_t nBytesToWrite ) +{ + return ((LSM303AGRAccSensor *)handle)->io_write(pBuffer, WriteAddr, nBytesToWrite); +} + +uint8_t LSM303AGR_ACC_io_read( void *handle, uint8_t ReadAddr, uint8_t *pBuffer, uint16_t nBytesToRead ) +{ + return ((LSM303AGRAccSensor *)handle)->io_read(pBuffer, ReadAddr, nBytesToRead); +}
diff -r 000000000000 -r 98c301bb7d1b Components/LSM303AGRSensor/LSM303AGRAccSensor.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Components/LSM303AGRSensor/LSM303AGRAccSensor.h Tue Oct 03 12:21:11 2017 +0000 @@ -0,0 +1,140 @@ +/** + ****************************************************************************** + * @file LSM303AGRAccSensor.h + * @author CLab + * @version V1.0.0 + * @date 5 August 2016 + * @brief Abstract Class of an LSM303AGR accelerometer sensor. + ****************************************************************************** + * @attention + * + * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of STMicroelectronics nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************** + */ + + +/* Prevent recursive inclusion -----------------------------------------------*/ + +#ifndef __LSM303AGRAccSensor_H__ +#define __LSM303AGRAccSensor_H__ + + +/* Includes ------------------------------------------------------------------*/ + +#include "DevI2C.h" +#include "LSM303AGR_acc_driver.h" +#include "MotionSensor.h" + +/* Defines -------------------------------------------------------------------*/ +#define LSM303AGR_ACC_SENSITIVITY_FOR_FS_2G_NORMAL_MODE 3.900f /**< Sensitivity value for 2 g full scale and normal mode [mg/LSB] */ +#define LSM303AGR_ACC_SENSITIVITY_FOR_FS_2G_HIGH_RESOLUTION_MODE 0.980f /**< Sensitivity value for 2 g full scale and high resolution mode [mg/LSB] */ +#define LSM303AGR_ACC_SENSITIVITY_FOR_FS_2G_LOW_POWER_MODE 15.630f /**< Sensitivity value for 2 g full scale and low power mode [mg/LSB] */ +#define LSM303AGR_ACC_SENSITIVITY_FOR_FS_4G_NORMAL_MODE 7.820f /**< Sensitivity value for 4 g full scale and normal mode [mg/LSB] */ +#define LSM303AGR_ACC_SENSITIVITY_FOR_FS_4G_HIGH_RESOLUTION_MODE 1.950f /**< Sensitivity value for 4 g full scale and high resolution mode [mg/LSB] */ +#define LSM303AGR_ACC_SENSITIVITY_FOR_FS_4G_LOW_POWER_MODE 31.260f /**< Sensitivity value for 4 g full scale and low power mode [mg/LSB] */ +#define LSM303AGR_ACC_SENSITIVITY_FOR_FS_8G_NORMAL_MODE 15.630f /**< Sensitivity value for 8 g full scale and normal mode [mg/LSB] */ +#define LSM303AGR_ACC_SENSITIVITY_FOR_FS_8G_HIGH_RESOLUTION_MODE 3.900f /**< Sensitivity value for 8 g full scale and high resolution mode [mg/LSB] */ +#define LSM303AGR_ACC_SENSITIVITY_FOR_FS_8G_LOW_POWER_MODE 62.520f /**< Sensitivity value for 8 g full scale and low power mode [mg/LSB] */ +#define LSM303AGR_ACC_SENSITIVITY_FOR_FS_16G_NORMAL_MODE 46.900f /**< Sensitivity value for 16 g full scale and normal mode [mg/LSB] */ +#define LSM303AGR_ACC_SENSITIVITY_FOR_FS_16G_HIGH_RESOLUTION_MODE 11.720f /**< Sensitivity value for 16 g full scale and high resolution mode [mg/LSB] */ +#define LSM303AGR_ACC_SENSITIVITY_FOR_FS_16G_LOW_POWER_MODE 187.580f /**< Sensitivity value for 16 g full scale and low power mode [mg/LSB] */ + +/* Class Declaration ---------------------------------------------------------*/ + +/** + * Abstract class of an LSM303AGR Inertial Measurement Unit (IMU) 6 axes + * sensor. + */ +class LSM303AGRAccSensor : public MotionSensor +{ + public: + LSM303AGRAccSensor(DevI2C &i2c); + LSM303AGRAccSensor(DevI2C &i2c, uint8_t address); + virtual int init(void *init); + virtual int read_id(uint8_t *id); + virtual int get_x_axes(int32_t *pData); + virtual int get_x_axes_raw(int16_t *pData); + virtual int get_x_sensitivity(float *pfData); + virtual int get_x_odr(float *odr); + virtual int set_x_odr(float odr); + virtual int get_x_fs(float *fullScale); + virtual int set_x_fs(float fullScale); + int enable(void); + int disable(void); + int read_reg(uint8_t reg, uint8_t *data); + int write_reg(uint8_t reg, uint8_t data); + + /** + * @brief Utility function to read data. + * @param pBuffer: pointer to data to be read. + * @param RegisterAddr: specifies internal address register to be read. + * @param NumByteToRead: number of bytes to be read. + * @retval 0 if ok, an error code otherwise. + */ + uint8_t io_read(uint8_t* pBuffer, uint8_t RegisterAddr, uint16_t NumByteToRead) + { + return (uint8_t) _dev_i2c.i2c_read(pBuffer, _address, RegisterAddr, NumByteToRead); + } + + /** + * @brief Utility function to write data. + * @param pBuffer: pointer to data to be written. + * @param RegisterAddr: specifies internal address register to be written. + * @param NumByteToWrite: number of bytes to write. + * @retval 0 if ok, an error code otherwise. + */ + uint8_t io_write(uint8_t* pBuffer, uint8_t RegisterAddr, uint16_t NumByteToWrite) + { + return (uint8_t) _dev_i2c.i2c_write(pBuffer, _address, RegisterAddr, NumByteToWrite); + } + + private: + int set_x_odr_when_enabled(float odr); + int set_x_odr_when_disabled(float odr); + int get_x_sensitivity_normal_mode(float *sensitivity ); + int get_x_sensitivity_lp_mode(float *sensitivity ); + int get_x_sensitivity_hr_mode(float *sensitivity ); + + /* Helper classes. */ + DevI2C &_dev_i2c; + + /* Configuration */ + uint8_t _address; + + uint8_t _is_enabled; + float _last_odr; +}; + +#ifdef __cplusplus + extern "C" { +#endif +uint8_t LSM303AGR_ACC_io_write( void *handle, uint8_t WriteAddr, uint8_t *pBuffer, uint16_t nBytesToWrite ); +uint8_t LSM303AGR_ACC_io_read( void *handle, uint8_t ReadAddr, uint8_t *pBuffer, uint16_t nBytesToRead ); +#ifdef __cplusplus + } +#endif + +#endif
diff -r 000000000000 -r 98c301bb7d1b Components/LSM303AGRSensor/LSM303AGRMagSensor.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Components/LSM303AGRSensor/LSM303AGRMagSensor.cpp Tue Oct 03 12:21:11 2017 +0000 @@ -0,0 +1,347 @@ +/** + ****************************************************************************** + * @file LSM303AGRMagSensor.cpp + * @author CLab + * @version V1.0.0 + * @date 5 August 2016 + * @brief Implementation an LSM303AGR magnetometer sensor. + ****************************************************************************** + * @attention + * + * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of STMicroelectronics nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************** + */ + + +/* Includes ------------------------------------------------------------------*/ + +#include "mbed.h" +#include "DevI2C.h" +#include "LSM303AGRMagSensor.h" +#include "LSM303AGR_mag_driver.h" + + +/* Class Implementation ------------------------------------------------------*/ + +/** Constructor + * @param i2c object of an helper class which handles the I2C peripheral + * @param address the address of the component's instance + */ +LSM303AGRMagSensor::LSM303AGRMagSensor(DevI2C &i2c) : _dev_i2c(i2c) +{ + _address = LSM303AGR_MAG_I2C_ADDRESS; +}; + +/** Constructor + * @param i2c object of an helper class which handles the I2C peripheral + * @param address the address of the component's instance + */ +LSM303AGRMagSensor::LSM303AGRMagSensor(DevI2C &i2c, uint8_t address) : _dev_i2c(i2c), _address(address) +{ + +}; + +/** + * @brief Initializing the component. + * @param[in] init pointer to device specific initalization structure. + * @retval "0" in case of success, an error code otherwise. + */ +int LSM303AGRMagSensor::init(void *init) +{ + /* Operating mode selection - power down */ + if ( LSM303AGR_MAG_W_MD( (void *)this, LSM303AGR_MAG_MD_IDLE1_MODE ) == MEMS_ERROR ) + { + return 1; + } + + /* Enable BDU */ + if ( LSM303AGR_MAG_W_BDU( (void *)this, LSM303AGR_MAG_BDU_ENABLED ) == MEMS_ERROR ) + { + return 1; + } + + if ( set_m_odr( 100.0f ) == 1 ) + { + return 1; + } + + if ( set_m_fs( 50.0f ) == 1 ) + { + return 1; + } + + if ( LSM303AGR_MAG_W_ST( (void *)this, LSM303AGR_MAG_ST_DISABLED ) == MEMS_ERROR ) + { + return 1; + } + + return 0; +} + +/** + * @brief Enable LSM303AGR magnetometer + * @retval 0 in case of success, an error code otherwise + */ +int LSM303AGRMagSensor::enable(void) +{ + /* Operating mode selection */ + if ( LSM303AGR_MAG_W_MD( (void *)this, LSM303AGR_MAG_MD_CONTINUOS_MODE ) == MEMS_ERROR ) + { + return 1; + } + + return 0; +} + +/** + * @brief Disable LSM303AGR magnetometer + * @retval 0 in case of success, an error code otherwise + */ +int LSM303AGRMagSensor::disable(void) +{ + /* Operating mode selection - power down */ + if ( LSM303AGR_MAG_W_MD( (void *)this, LSM303AGR_MAG_MD_IDLE1_MODE ) == MEMS_ERROR ) + { + return 1; + } + + return 0; +} + +/** + * @brief Read ID of LSM303AGR Magnetometer + * @param p_id the pointer where the ID of the device is stored + * @retval 0 in case of success, an error code otherwise + */ +int LSM303AGRMagSensor::read_id(uint8_t *id) +{ + if(!id) + { + return 1; + } + + /* Read WHO AM I register */ + if ( LSM303AGR_MAG_R_WHO_AM_I( (void *)this, id ) == MEMS_ERROR ) + { + return 1; + } + + return 0; +} + +/** + * @brief Read data from LSM303AGR Magnetometer + * @param pData the pointer where the magnetometer data are stored + * @retval 0 in case of success, an error code otherwise + */ +int LSM303AGRMagSensor::get_m_axes(int32_t *pData) +{ + int16_t pDataRaw[3]; + float sensitivity = 0; + + /* Read raw data from LSM303AGR output register. */ + if ( get_m_axes_raw( pDataRaw ) == 1 ) + { + return 1; + } + + /* Get LSM303AGR actual sensitivity. */ + if ( get_m_sensitivity( &sensitivity ) == 1 ) + { + return 1; + } + + /* Calculate the data. */ + pData[0] = ( int32_t )( pDataRaw[0] * sensitivity ); + pData[1] = ( int32_t )( pDataRaw[1] * sensitivity ); + pData[2] = ( int32_t )( pDataRaw[2] * sensitivity ); + + return 0; +} + +/** + * @brief Read Magnetometer Sensitivity + * @param pfData the pointer where the magnetometer sensitivity is stored + * @retval 0 in case of success, an error code otherwise + */ +int LSM303AGRMagSensor::get_m_sensitivity(float *pfData) +{ + *pfData = 1.5f; + + return 0; +} + +/** + * @brief Read raw data from LSM303AGR Magnetometer + * @param pData the pointer where the magnetomer raw data are stored + * @retval 0 in case of success, an error code otherwise + */ +int LSM303AGRMagSensor::get_m_axes_raw(int16_t *pData) +{ + uint8_t regValue[6] = {0, 0, 0, 0, 0, 0}; + int16_t *regValueInt16; + + /* Read output registers from LSM303AGR_MAG_OUTX_L to LSM303AGR_MAG_OUTZ_H. */ + if ( LSM303AGR_MAG_Get_Raw_Magnetic( (void *)this, regValue ) == MEMS_ERROR ) + { + return 1; + } + + regValueInt16 = (int16_t *)regValue; + + /* Format the data. */ + pData[0] = regValueInt16[0]; + pData[1] = regValueInt16[1]; + pData[2] = regValueInt16[2]; + + return 0; +} + +/** + * @brief Read LSM303AGR Magnetometer output data rate + * @param odr the pointer to the output data rate + * @retval 0 in case of success, an error code otherwise + */ +int LSM303AGRMagSensor::get_m_odr(float* odr) +{ + LSM303AGR_MAG_ODR_t odr_low_level; + + if ( LSM303AGR_MAG_R_ODR( (void *)this, &odr_low_level ) == MEMS_ERROR ) + { + return 1; + } + + switch( odr_low_level ) + { + case LSM303AGR_MAG_ODR_10Hz: + *odr = 10.000f; + break; + case LSM303AGR_MAG_ODR_20Hz: + *odr = 20.000f; + break; + case LSM303AGR_MAG_ODR_50Hz: + *odr = 50.000f; + break; + case LSM303AGR_MAG_ODR_100Hz: + *odr = 100.000f; + break; + default: + *odr = -1.000f; + return 1; + } + return 0; +} + +/** + * @brief Set ODR + * @param odr the output data rate to be set + * @retval 0 in case of success, an error code otherwise + */ +int LSM303AGRMagSensor::set_m_odr(float odr) +{ + LSM303AGR_MAG_ODR_t new_odr; + + new_odr = ( odr <= 10.000f ) ? LSM303AGR_MAG_ODR_10Hz + : ( odr <= 20.000f ) ? LSM303AGR_MAG_ODR_20Hz + : ( odr <= 50.000f ) ? LSM303AGR_MAG_ODR_50Hz + : LSM303AGR_MAG_ODR_100Hz; + + if ( LSM303AGR_MAG_W_ODR( (void *)this, new_odr ) == MEMS_ERROR ) + { + return 1; + } + + return 0; +} + + +/** + * @brief Read LSM303AGR Magnetometer full scale + * @param fullScale the pointer to the output data rate + * @retval 0 in case of success, an error code otherwise + */ +int LSM303AGRMagSensor::get_m_fs(float* fullScale) +{ + *fullScale = 50.0f; + + return 0; +} + +/** + * @brief Set full scale + * @param fullScale the full scale to be set + * @retval 0 in case of success, an error code otherwise + */ +int LSM303AGRMagSensor::set_m_fs(float fullScale) +{ + return 0; +} + + +/** + * @brief Read magnetometer data from register + * @param reg register address + * @param data register data + * @retval 0 in case of success + * @retval 1 in case of failure + */ +int LSM303AGRMagSensor::read_reg( uint8_t reg, uint8_t *data ) +{ + if ( LSM303AGR_MAG_read_reg( (void *)this, reg, data ) == MEMS_ERROR ) + { + return 1; + } + + return 0; +} + + +/** + * @brief Write magnetometer data to register + * @param reg register address + * @param data register data + * @retval 0 in case of success + * @retval 1 in case of failure + */ +int LSM303AGRMagSensor::write_reg( uint8_t reg, uint8_t data ) +{ + if ( LSM303AGR_MAG_write_reg( (void *)this, reg, data ) == MEMS_ERROR ) + { + return 1; + } + + return 0; +} + +uint8_t LSM303AGR_MAG_io_write( void *handle, uint8_t WriteAddr, uint8_t *pBuffer, uint16_t nBytesToWrite ) +{ + return ((LSM303AGRMagSensor *)handle)->io_write(pBuffer, WriteAddr, nBytesToWrite); +} + +uint8_t LSM303AGR_MAG_io_read( void *handle, uint8_t ReadAddr, uint8_t *pBuffer, uint16_t nBytesToRead ) +{ + return ((LSM303AGRMagSensor *)handle)->io_read(pBuffer, ReadAddr, nBytesToRead); +}
diff -r 000000000000 -r 98c301bb7d1b Components/LSM303AGRSensor/LSM303AGRMagSensor.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Components/LSM303AGRSensor/LSM303AGRMagSensor.h Tue Oct 03 12:21:11 2017 +0000 @@ -0,0 +1,119 @@ +/** + ****************************************************************************** + * @file LSM303AGRMagSensor.h + * @author CLab + * @version V1.0.0 + * @date 5 August 2016 + * @brief Abstract Class of an LSM303AGR magnetometer sensor. + ****************************************************************************** + * @attention + * + * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of STMicroelectronics nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************** + */ + + +/* Prevent recursive inclusion -----------------------------------------------*/ + +#ifndef __LSM303AGRMagSensor_H__ +#define __LSM303AGRMagSensor_H__ + + +/* Includes ------------------------------------------------------------------*/ + +#include "DevI2C.h" +#include "LSM303AGR_mag_driver.h" +#include "MagneticSensor.h" + + +/* Class Declaration ---------------------------------------------------------*/ + +/** + * Abstract class of an LSM303AGR Inertial Measurement Unit (IMU) 6 axes + * sensor. + */ +class LSM303AGRMagSensor : public MagneticSensor +{ + public: + LSM303AGRMagSensor(DevI2C &i2c); + LSM303AGRMagSensor(DevI2C &i2c, uint8_t address); + virtual int init(void *init); + virtual int read_id(uint8_t *id); + virtual int get_m_axes(int32_t *pData); + virtual int get_m_axes_raw(int16_t *pData); + int enable(void); + int disable(void); + int get_m_sensitivity(float *pfData); + int get_m_odr(float *odr); + int set_m_odr(float odr); + int get_m_fs(float *fullScale); + int set_m_fs(float fullScale); + int read_reg(uint8_t reg, uint8_t *data); + int write_reg(uint8_t reg, uint8_t data); + + /** + * @brief Utility function to read data. + * @param pBuffer: pointer to data to be read. + * @param RegisterAddr: specifies internal address register to be read. + * @param NumByteToRead: number of bytes to be read. + * @retval 0 if ok, an error code otherwise. + */ + uint8_t io_read(uint8_t* pBuffer, uint8_t RegisterAddr, uint16_t NumByteToRead) + { + return (uint8_t) _dev_i2c.i2c_read(pBuffer, _address, RegisterAddr, NumByteToRead); + } + + /** + * @brief Utility function to write data. + * @param pBuffer: pointer to data to be written. + * @param RegisterAddr: specifies internal address register to be written. + * @param NumByteToWrite: number of bytes to write. + * @retval 0 if ok, an error code otherwise. + */ + uint8_t io_write(uint8_t* pBuffer, uint8_t RegisterAddr, uint16_t NumByteToWrite) + { + return (uint8_t) _dev_i2c.i2c_write(pBuffer, _address, RegisterAddr, NumByteToWrite); + } + + private: + + /* Helper classes. */ + DevI2C &_dev_i2c; + + /* Configuration */ + uint8_t _address; +}; + +#ifdef __cplusplus + extern "C" { +#endif +uint8_t LSM303AGR_MAG_io_write( void *handle, uint8_t WriteAddr, uint8_t *pBuffer, uint16_t nBytesToWrite ); +uint8_t LSM303AGR_MAG_io_read( void *handle, uint8_t ReadAddr, uint8_t *pBuffer, uint16_t nBytesToRead ); +#ifdef __cplusplus + } +#endif + +#endif
diff -r 000000000000 -r 98c301bb7d1b Components/LSM303AGRSensor/LSM303AGR_acc_driver.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Components/LSM303AGRSensor/LSM303AGR_acc_driver.c Tue Oct 03 12:21:11 2017 +0000 @@ -0,0 +1,3950 @@ +/** + ****************************************************************************** + * @file LSM303AGR_acc_driver.c + * @author MEMS Application Team + * @version V1.1 + * @date 24-February-2016 + * @brief LSM303AGR Accelerometer driver file + ****************************************************************************** + * @attention + * + * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of STMicroelectronics nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************** + */ + +/* Includes ------------------------------------------------------------------*/ +#include "LSM303AGR_acc_driver.h" + +/* Imported function prototypes ----------------------------------------------*/ +extern uint8_t LSM303AGR_ACC_io_write(void *handle, uint8_t WriteAddr, uint8_t *pBuffer, uint16_t nBytesToWrite); +extern uint8_t LSM303AGR_ACC_io_read(void *handle, uint8_t ReadAddr, uint8_t *pBuffer, uint16_t nBytesToRead); + +/* Private typedef -----------------------------------------------------------*/ + +/* Private define ------------------------------------------------------------*/ + +/* Private macro -------------------------------------------------------------*/ + +/* Private variables ---------------------------------------------------------*/ + +/* Private functions ---------------------------------------------------------*/ + +/******************************************************************************* +* Function Name : LSM303AGR_ACC_read_reg +* Description : Generic Reading function. It must be fullfilled with either +* : I2C or SPI reading functions +* Input : Register Address +* Output : Data REad +* Return : None +*******************************************************************************/ +mems_status_t LSM303AGR_ACC_read_reg(void *handle, u8_t Reg, u8_t* Data) +{ + + if (LSM303AGR_ACC_io_read(handle, Reg, Data, 1)) + { + return MEMS_ERROR; + } + else + { + return MEMS_SUCCESS; + } +} + +/******************************************************************************* +* Function Name : LSM303AGR_ACC_write_reg +* Description : Generic Writing function. It must be fullfilled with either +* : I2C or SPI writing function +* Input : Register Address, Data to be written +* Output : None +* Return : None +*******************************************************************************/ +mems_status_t LSM303AGR_ACC_write_reg(void *handle, u8_t Reg, u8_t Data) +{ + + if (LSM303AGR_ACC_io_write(handle, Reg, &Data, 1)) + { + return MEMS_ERROR; + } + else + { + return MEMS_SUCCESS; + } +} + +/******************************************************************************* +* Function Name : SwapHighLowByte +* Description : Swap High/low byte in multiple byte values +* It works with minimum 2 byte for every dimension. +* Example x,y,z with 2 byte for every dimension +* +* Input : bufferToSwap -> buffer to swap +* numberOfByte -> the buffer length in byte +* dimension -> number of dimension +* +* Output : bufferToSwap -> buffer swapped +* Return : None +*******************************************************************************/ +void LSM303AGR_ACC_SwapHighLowByte(u8_t *bufferToSwap, u8_t numberOfByte, u8_t dimension) +{ + + u8_t numberOfByteForDimension, i, j; + u8_t tempValue[10]; + + numberOfByteForDimension=numberOfByte/dimension; + + for (i=0; i<dimension;i++ ) + { + for (j=0; j<numberOfByteForDimension;j++ ) + tempValue[j]=bufferToSwap[j+i*numberOfByteForDimension]; + for (j=0; j<numberOfByteForDimension;j++ ) + *(bufferToSwap+i*(numberOfByteForDimension)+j)=*(tempValue+(numberOfByteForDimension-1)-j); + } +} + +/* Exported functions ---------------------------------------------------------*/ + +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_x_data_avail +* Description : Read 1DA +* Input : Pointer to LSM303AGR_ACC_1DA_t +* Output : Status of 1DA see LSM303AGR_ACC_1DA_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_x_data_avail(void *handle, LSM303AGR_ACC_1DA_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_STATUS_REG_AUX, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_1DA_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_y_data_avail +* Description : Read 2DA_ +* Input : Pointer to LSM303AGR_ACC_2DA__t +* Output : Status of 2DA_ see LSM303AGR_ACC_2DA__t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_y_data_avail(void *handle, LSM303AGR_ACC_2DA__t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_STATUS_REG_AUX, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_2DA__MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_z_data_avail +* Description : Read 3DA_ +* Input : Pointer to LSM303AGR_ACC_3DA__t +* Output : Status of 3DA_ see LSM303AGR_ACC_3DA__t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_z_data_avail(void *handle, LSM303AGR_ACC_3DA__t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_STATUS_REG_AUX, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_3DA__MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_xyz_data_avail +* Description : Read 321DA_ +* Input : Pointer to LSM303AGR_ACC_321DA__t +* Output : Status of 321DA_ see LSM303AGR_ACC_321DA__t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_xyz_data_avail(void *handle, LSM303AGR_ACC_321DA__t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_STATUS_REG_AUX, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_321DA__MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_DataXOverrun +* Description : Read 1OR_ +* Input : Pointer to LSM303AGR_ACC_1OR__t +* Output : Status of 1OR_ see LSM303AGR_ACC_1OR__t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_DataXOverrun(void *handle, LSM303AGR_ACC_1OR__t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_STATUS_REG_AUX, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_1OR__MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_DataYOverrun +* Description : Read 2OR_ +* Input : Pointer to LSM303AGR_ACC_2OR__t +* Output : Status of 2OR_ see LSM303AGR_ACC_2OR__t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_DataYOverrun(void *handle, LSM303AGR_ACC_2OR__t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_STATUS_REG_AUX, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_2OR__MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_DataZOverrun +* Description : Read 3OR_ +* Input : Pointer to LSM303AGR_ACC_3OR__t +* Output : Status of 3OR_ see LSM303AGR_ACC_3OR__t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_DataZOverrun(void *handle, LSM303AGR_ACC_3OR__t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_STATUS_REG_AUX, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_3OR__MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_DataXYZOverrun +* Description : Read 321OR_ +* Input : Pointer to LSM303AGR_ACC_321OR__t +* Output : Status of 321OR_ see LSM303AGR_ACC_321OR__t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_DataXYZOverrun(void *handle, LSM303AGR_ACC_321OR__t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_STATUS_REG_AUX, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_321OR__MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_int_counter +* Description : Read IC +* Input : Pointer to u8_t +* Output : Status of IC +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_int_counter(void *handle, u8_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_INT_COUNTER_REG, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_IC_MASK; //coerce + *value = *value >> LSM303AGR_ACC_IC_POSITION; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_WHO_AM_I +* Description : Read WHO_AM_I +* Input : Pointer to u8_t +* Output : Status of WHO_AM_I +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_WHO_AM_I(void *handle, u8_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_WHO_AM_I_REG, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_WHO_AM_I_MASK; //coerce + *value = *value >> LSM303AGR_ACC_WHO_AM_I_POSITION; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_W_TEMP_EN_bits +* Description : Write TEMP_EN +* Input : LSM303AGR_ACC_TEMP_EN_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_ACC_W_TEMP_EN_bits(void *handle, LSM303AGR_ACC_TEMP_EN_t newValue) +{ + u8_t value; + + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_TEMP_CFG_REG, &value) ) + return MEMS_ERROR; + + value &= ~LSM303AGR_ACC_TEMP_EN_MASK; + value |= newValue; + + if( !LSM303AGR_ACC_write_reg(handle, LSM303AGR_ACC_TEMP_CFG_REG, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_TEMP_EN_bits +* Description : Read TEMP_EN +* Input : Pointer to LSM303AGR_ACC_TEMP_EN_t +* Output : Status of TEMP_EN see LSM303AGR_ACC_TEMP_EN_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_TEMP_EN_bits(void *handle, LSM303AGR_ACC_TEMP_EN_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_TEMP_CFG_REG, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_TEMP_EN_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_W_ADC_PD +* Description : Write ADC_PD +* Input : LSM303AGR_ACC_ADC_PD_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_ACC_W_ADC_PD(void *handle, LSM303AGR_ACC_ADC_PD_t newValue) +{ + u8_t value; + + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_TEMP_CFG_REG, &value) ) + return MEMS_ERROR; + + value &= ~LSM303AGR_ACC_ADC_PD_MASK; + value |= newValue; + + if( !LSM303AGR_ACC_write_reg(handle, LSM303AGR_ACC_TEMP_CFG_REG, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_ADC_PD +* Description : Read ADC_PD +* Input : Pointer to LSM303AGR_ACC_ADC_PD_t +* Output : Status of ADC_PD see LSM303AGR_ACC_ADC_PD_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_ADC_PD(void *handle, LSM303AGR_ACC_ADC_PD_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_TEMP_CFG_REG, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_ADC_PD_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_W_XEN +* Description : Write XEN +* Input : LSM303AGR_ACC_XEN_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_ACC_W_XEN(void *handle, LSM303AGR_ACC_XEN_t newValue) +{ + u8_t value; + + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_CTRL_REG1, &value) ) + return MEMS_ERROR; + + value &= ~LSM303AGR_ACC_XEN_MASK; + value |= newValue; + + if( !LSM303AGR_ACC_write_reg(handle, LSM303AGR_ACC_CTRL_REG1, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_XEN +* Description : Read XEN +* Input : Pointer to LSM303AGR_ACC_XEN_t +* Output : Status of XEN see LSM303AGR_ACC_XEN_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_XEN(void *handle, LSM303AGR_ACC_XEN_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_CTRL_REG1, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_XEN_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_W_YEN +* Description : Write YEN +* Input : LSM303AGR_ACC_YEN_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_ACC_W_YEN(void *handle, LSM303AGR_ACC_YEN_t newValue) +{ + u8_t value; + + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_CTRL_REG1, &value) ) + return MEMS_ERROR; + + value &= ~LSM303AGR_ACC_YEN_MASK; + value |= newValue; + + if( !LSM303AGR_ACC_write_reg(handle, LSM303AGR_ACC_CTRL_REG1, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_YEN +* Description : Read YEN +* Input : Pointer to LSM303AGR_ACC_YEN_t +* Output : Status of YEN see LSM303AGR_ACC_YEN_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_YEN(void *handle, LSM303AGR_ACC_YEN_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_CTRL_REG1, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_YEN_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_W_ZEN +* Description : Write ZEN +* Input : LSM303AGR_ACC_ZEN_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_ACC_W_ZEN(void *handle, LSM303AGR_ACC_ZEN_t newValue) +{ + u8_t value; + + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_CTRL_REG1, &value) ) + return MEMS_ERROR; + + value &= ~LSM303AGR_ACC_ZEN_MASK; + value |= newValue; + + if( !LSM303AGR_ACC_write_reg(handle, LSM303AGR_ACC_CTRL_REG1, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_ZEN +* Description : Read ZEN +* Input : Pointer to LSM303AGR_ACC_ZEN_t +* Output : Status of ZEN see LSM303AGR_ACC_ZEN_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_ZEN(void *handle, LSM303AGR_ACC_ZEN_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_CTRL_REG1, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_ZEN_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_W_LOWPWR_EN +* Description : Write LPEN +* Input : LSM303AGR_ACC_LPEN_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_ACC_W_LOWPWR_EN(void *handle, LSM303AGR_ACC_LPEN_t newValue) +{ + u8_t value; + + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_CTRL_REG1, &value) ) + return MEMS_ERROR; + + value &= ~LSM303AGR_ACC_LPEN_MASK; + value |= newValue; + + if( !LSM303AGR_ACC_write_reg(handle, LSM303AGR_ACC_CTRL_REG1, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_LOWPWR_EN +* Description : Read LPEN +* Input : Pointer to LSM303AGR_ACC_LPEN_t +* Output : Status of LPEN see LSM303AGR_ACC_LPEN_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_LOWPWR_EN(void *handle, LSM303AGR_ACC_LPEN_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_CTRL_REG1, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_LPEN_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_W_ODR +* Description : Write ODR +* Input : LSM303AGR_ACC_ODR_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_ACC_W_ODR(void *handle, LSM303AGR_ACC_ODR_t newValue) +{ + u8_t value; + + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_CTRL_REG1, &value) ) + return MEMS_ERROR; + + value &= ~LSM303AGR_ACC_ODR_MASK; + value |= newValue; + + if( !LSM303AGR_ACC_write_reg(handle, LSM303AGR_ACC_CTRL_REG1, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_ODR +* Description : Read ODR +* Input : Pointer to LSM303AGR_ACC_ODR_t +* Output : Status of ODR see LSM303AGR_ACC_ODR_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_ODR(void *handle, LSM303AGR_ACC_ODR_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_CTRL_REG1, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_ODR_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_W_hpf_aoi_en_int1 +* Description : Write HPIS1 +* Input : LSM303AGR_ACC_HPIS1_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_ACC_W_hpf_aoi_en_int1(void *handle, LSM303AGR_ACC_HPIS1_t newValue) +{ + u8_t value; + + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_CTRL_REG2, &value) ) + return MEMS_ERROR; + + value &= ~LSM303AGR_ACC_HPIS1_MASK; + value |= newValue; + + if( !LSM303AGR_ACC_write_reg(handle, LSM303AGR_ACC_CTRL_REG2, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_hpf_aoi_en_int1 +* Description : Read HPIS1 +* Input : Pointer to LSM303AGR_ACC_HPIS1_t +* Output : Status of HPIS1 see LSM303AGR_ACC_HPIS1_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_hpf_aoi_en_int1(void *handle, LSM303AGR_ACC_HPIS1_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_CTRL_REG2, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_HPIS1_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_W_hpf_aoi_en_int2 +* Description : Write HPIS2 +* Input : LSM303AGR_ACC_HPIS2_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_ACC_W_hpf_aoi_en_int2(void *handle, LSM303AGR_ACC_HPIS2_t newValue) +{ + u8_t value; + + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_CTRL_REG2, &value) ) + return MEMS_ERROR; + + value &= ~LSM303AGR_ACC_HPIS2_MASK; + value |= newValue; + + if( !LSM303AGR_ACC_write_reg(handle, LSM303AGR_ACC_CTRL_REG2, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_hpf_aoi_en_int2 +* Description : Read HPIS2 +* Input : Pointer to LSM303AGR_ACC_HPIS2_t +* Output : Status of HPIS2 see LSM303AGR_ACC_HPIS2_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_hpf_aoi_en_int2(void *handle, LSM303AGR_ACC_HPIS2_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_CTRL_REG2, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_HPIS2_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_W_hpf_click_en +* Description : Write HPCLICK +* Input : LSM303AGR_ACC_HPCLICK_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_ACC_W_hpf_click_en(void *handle, LSM303AGR_ACC_HPCLICK_t newValue) +{ + u8_t value; + + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_CTRL_REG2, &value) ) + return MEMS_ERROR; + + value &= ~LSM303AGR_ACC_HPCLICK_MASK; + value |= newValue; + + if( !LSM303AGR_ACC_write_reg(handle, LSM303AGR_ACC_CTRL_REG2, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_hpf_click_en +* Description : Read HPCLICK +* Input : Pointer to LSM303AGR_ACC_HPCLICK_t +* Output : Status of HPCLICK see LSM303AGR_ACC_HPCLICK_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_hpf_click_en(void *handle, LSM303AGR_ACC_HPCLICK_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_CTRL_REG2, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_HPCLICK_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_W_Data_Filter +* Description : Write FDS +* Input : LSM303AGR_ACC_FDS_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_ACC_W_Data_Filter(void *handle, LSM303AGR_ACC_FDS_t newValue) +{ + u8_t value; + + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_CTRL_REG2, &value) ) + return MEMS_ERROR; + + value &= ~LSM303AGR_ACC_FDS_MASK; + value |= newValue; + + if( !LSM303AGR_ACC_write_reg(handle, LSM303AGR_ACC_CTRL_REG2, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_Data_Filter +* Description : Read FDS +* Input : Pointer to LSM303AGR_ACC_FDS_t +* Output : Status of FDS see LSM303AGR_ACC_FDS_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_Data_Filter(void *handle, LSM303AGR_ACC_FDS_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_CTRL_REG2, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_FDS_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_W_hpf_cutoff_freq +* Description : Write HPCF +* Input : LSM303AGR_ACC_HPCF_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_ACC_W_hpf_cutoff_freq(void *handle, LSM303AGR_ACC_HPCF_t newValue) +{ + u8_t value; + + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_CTRL_REG2, &value) ) + return MEMS_ERROR; + + value &= ~LSM303AGR_ACC_HPCF_MASK; + value |= newValue; + + if( !LSM303AGR_ACC_write_reg(handle, LSM303AGR_ACC_CTRL_REG2, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_hpf_cutoff_freq +* Description : Read HPCF +* Input : Pointer to LSM303AGR_ACC_HPCF_t +* Output : Status of HPCF see LSM303AGR_ACC_HPCF_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_hpf_cutoff_freq(void *handle, LSM303AGR_ACC_HPCF_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_CTRL_REG2, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_HPCF_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_W_hpf_mode +* Description : Write HPM +* Input : LSM303AGR_ACC_HPM_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_ACC_W_hpf_mode(void *handle, LSM303AGR_ACC_HPM_t newValue) +{ + u8_t value; + + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_CTRL_REG2, &value) ) + return MEMS_ERROR; + + value &= ~LSM303AGR_ACC_HPM_MASK; + value |= newValue; + + if( !LSM303AGR_ACC_write_reg(handle, LSM303AGR_ACC_CTRL_REG2, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_hpf_mode +* Description : Read HPM +* Input : Pointer to LSM303AGR_ACC_HPM_t +* Output : Status of HPM see LSM303AGR_ACC_HPM_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_hpf_mode(void *handle, LSM303AGR_ACC_HPM_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_CTRL_REG2, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_HPM_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_W_FIFO_Overrun_on_INT1 +* Description : Write I1_OVERRUN +* Input : LSM303AGR_ACC_I1_OVERRUN_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_ACC_W_FIFO_Overrun_on_INT1(void *handle, LSM303AGR_ACC_I1_OVERRUN_t newValue) +{ + u8_t value; + + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_CTRL_REG3, &value) ) + return MEMS_ERROR; + + value &= ~LSM303AGR_ACC_I1_OVERRUN_MASK; + value |= newValue; + + if( !LSM303AGR_ACC_write_reg(handle, LSM303AGR_ACC_CTRL_REG3, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_FIFO_Overrun_on_INT1 +* Description : Read I1_OVERRUN +* Input : Pointer to LSM303AGR_ACC_I1_OVERRUN_t +* Output : Status of I1_OVERRUN see LSM303AGR_ACC_I1_OVERRUN_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_FIFO_Overrun_on_INT1(void *handle, LSM303AGR_ACC_I1_OVERRUN_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_CTRL_REG3, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_I1_OVERRUN_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_W_FIFO_Watermark_on_INT1 +* Description : Write I1_WTM +* Input : LSM303AGR_ACC_I1_WTM_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_ACC_W_FIFO_Watermark_on_INT1(void *handle, LSM303AGR_ACC_I1_WTM_t newValue) +{ + u8_t value; + + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_CTRL_REG3, &value) ) + return MEMS_ERROR; + + value &= ~LSM303AGR_ACC_I1_WTM_MASK; + value |= newValue; + + if( !LSM303AGR_ACC_write_reg(handle, LSM303AGR_ACC_CTRL_REG3, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_FIFO_Watermark_on_INT1 +* Description : Read I1_WTM +* Input : Pointer to LSM303AGR_ACC_I1_WTM_t +* Output : Status of I1_WTM see LSM303AGR_ACC_I1_WTM_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_FIFO_Watermark_on_INT1(void *handle, LSM303AGR_ACC_I1_WTM_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_CTRL_REG3, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_I1_WTM_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_W_FIFO_DRDY2_on_INT1 +* Description : Write I1_DRDY2 +* Input : LSM303AGR_ACC_I1_DRDY2_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_ACC_W_FIFO_DRDY2_on_INT1(void *handle, LSM303AGR_ACC_I1_DRDY2_t newValue) +{ + u8_t value; + + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_CTRL_REG3, &value) ) + return MEMS_ERROR; + + value &= ~LSM303AGR_ACC_I1_DRDY2_MASK; + value |= newValue; + + if( !LSM303AGR_ACC_write_reg(handle, LSM303AGR_ACC_CTRL_REG3, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_FIFO_DRDY2_on_INT1 +* Description : Read I1_DRDY2 +* Input : Pointer to LSM303AGR_ACC_I1_DRDY2_t +* Output : Status of I1_DRDY2 see LSM303AGR_ACC_I1_DRDY2_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_FIFO_DRDY2_on_INT1(void *handle, LSM303AGR_ACC_I1_DRDY2_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_CTRL_REG3, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_I1_DRDY2_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_W_FIFO_DRDY1_on_INT1 +* Description : Write I1_DRDY1 +* Input : LSM303AGR_ACC_I1_DRDY1_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_ACC_W_FIFO_DRDY1_on_INT1(void *handle, LSM303AGR_ACC_I1_DRDY1_t newValue) +{ + u8_t value; + + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_CTRL_REG3, &value) ) + return MEMS_ERROR; + + value &= ~LSM303AGR_ACC_I1_DRDY1_MASK; + value |= newValue; + + if( !LSM303AGR_ACC_write_reg(handle, LSM303AGR_ACC_CTRL_REG3, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_FIFO_DRDY1_on_INT1 +* Description : Read I1_DRDY1 +* Input : Pointer to LSM303AGR_ACC_I1_DRDY1_t +* Output : Status of I1_DRDY1 see LSM303AGR_ACC_I1_DRDY1_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_FIFO_DRDY1_on_INT1(void *handle, LSM303AGR_ACC_I1_DRDY1_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_CTRL_REG3, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_I1_DRDY1_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_W_FIFO_AOL2_on_INT1 +* Description : Write I1_AOI2 +* Input : LSM303AGR_ACC_I1_AOI2_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_ACC_W_FIFO_AOL2_on_INT1(void *handle, LSM303AGR_ACC_I1_AOI2_t newValue) +{ + u8_t value; + + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_CTRL_REG3, &value) ) + return MEMS_ERROR; + + value &= ~LSM303AGR_ACC_I1_AOI2_MASK; + value |= newValue; + + if( !LSM303AGR_ACC_write_reg(handle, LSM303AGR_ACC_CTRL_REG3, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_FIFO_AOL2_on_INT1 +* Description : Read I1_AOI2 +* Input : Pointer to LSM303AGR_ACC_I1_AOI2_t +* Output : Status of I1_AOI2 see LSM303AGR_ACC_I1_AOI2_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_FIFO_AOL2_on_INT1(void *handle, LSM303AGR_ACC_I1_AOI2_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_CTRL_REG3, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_I1_AOI2_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_W_FIFO_AOL1_on_INT1 +* Description : Write I1_AOI1 +* Input : LSM303AGR_ACC_I1_AOI1_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_ACC_W_FIFO_AOL1_on_INT1(void *handle, LSM303AGR_ACC_I1_AOI1_t newValue) +{ + u8_t value; + + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_CTRL_REG3, &value) ) + return MEMS_ERROR; + + value &= ~LSM303AGR_ACC_I1_AOI1_MASK; + value |= newValue; + + if( !LSM303AGR_ACC_write_reg(handle, LSM303AGR_ACC_CTRL_REG3, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_FIFO_AOL1_on_INT1 +* Description : Read I1_AOI1 +* Input : Pointer to LSM303AGR_ACC_I1_AOI1_t +* Output : Status of I1_AOI1 see LSM303AGR_ACC_I1_AOI1_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_FIFO_AOL1_on_INT1(void *handle, LSM303AGR_ACC_I1_AOI1_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_CTRL_REG3, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_I1_AOI1_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_W_FIFO_Click_on_INT1 +* Description : Write I1_CLICK +* Input : LSM303AGR_ACC_I1_CLICK_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_ACC_W_FIFO_Click_on_INT1(void *handle, LSM303AGR_ACC_I1_CLICK_t newValue) +{ + u8_t value; + + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_CTRL_REG3, &value) ) + return MEMS_ERROR; + + value &= ~LSM303AGR_ACC_I1_CLICK_MASK; + value |= newValue; + + if( !LSM303AGR_ACC_write_reg(handle, LSM303AGR_ACC_CTRL_REG3, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_FIFO_Click_on_INT1 +* Description : Read I1_CLICK +* Input : Pointer to LSM303AGR_ACC_I1_CLICK_t +* Output : Status of I1_CLICK see LSM303AGR_ACC_I1_CLICK_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_FIFO_Click_on_INT1(void *handle, LSM303AGR_ACC_I1_CLICK_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_CTRL_REG3, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_I1_CLICK_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_W_SPI_mode +* Description : Write SIM +* Input : LSM303AGR_ACC_SIM_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_ACC_W_SPI_mode(void *handle, LSM303AGR_ACC_SIM_t newValue) +{ + u8_t value; + + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_CTRL_REG4, &value) ) + return MEMS_ERROR; + + value &= ~LSM303AGR_ACC_SIM_MASK; + value |= newValue; + + if( !LSM303AGR_ACC_write_reg(handle, LSM303AGR_ACC_CTRL_REG4, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_SPI_mode +* Description : Read SIM +* Input : Pointer to LSM303AGR_ACC_SIM_t +* Output : Status of SIM see LSM303AGR_ACC_SIM_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_SPI_mode(void *handle, LSM303AGR_ACC_SIM_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_CTRL_REG4, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_SIM_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_W_SelfTest +* Description : Write ST +* Input : LSM303AGR_ACC_ST_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_ACC_W_SelfTest(void *handle, LSM303AGR_ACC_ST_t newValue) +{ + u8_t value; + + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_CTRL_REG4, &value) ) + return MEMS_ERROR; + + value &= ~LSM303AGR_ACC_ST_MASK; + value |= newValue; + + if( !LSM303AGR_ACC_write_reg(handle, LSM303AGR_ACC_CTRL_REG4, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_SelfTest +* Description : Read ST +* Input : Pointer to LSM303AGR_ACC_ST_t +* Output : Status of ST see LSM303AGR_ACC_ST_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_SelfTest(void *handle, LSM303AGR_ACC_ST_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_CTRL_REG4, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_ST_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_W_HiRes +* Description : Write HR +* Input : LSM303AGR_ACC_HR_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_ACC_W_HiRes(void *handle, LSM303AGR_ACC_HR_t newValue) +{ + u8_t value; + + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_CTRL_REG4, &value) ) + return MEMS_ERROR; + + value &= ~LSM303AGR_ACC_HR_MASK; + value |= newValue; + + if( !LSM303AGR_ACC_write_reg(handle, LSM303AGR_ACC_CTRL_REG4, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_HiRes +* Description : Read HR +* Input : Pointer to LSM303AGR_ACC_HR_t +* Output : Status of HR see LSM303AGR_ACC_HR_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_HiRes(void *handle, LSM303AGR_ACC_HR_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_CTRL_REG4, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_HR_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_W_FullScale +* Description : Write FS +* Input : LSM303AGR_ACC_FS_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_ACC_W_FullScale(void *handle, LSM303AGR_ACC_FS_t newValue) +{ + u8_t value; + + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_CTRL_REG4, &value) ) + return MEMS_ERROR; + + value &= ~LSM303AGR_ACC_FS_MASK; + value |= newValue; + + if( !LSM303AGR_ACC_write_reg(handle, LSM303AGR_ACC_CTRL_REG4, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_FullScale +* Description : Read FS +* Input : Pointer to LSM303AGR_ACC_FS_t +* Output : Status of FS see LSM303AGR_ACC_FS_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_FullScale(void *handle, LSM303AGR_ACC_FS_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_CTRL_REG4, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_FS_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_W_LittleBigEndian +* Description : Write BLE +* Input : LSM303AGR_ACC_BLE_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_ACC_W_LittleBigEndian(void *handle, LSM303AGR_ACC_BLE_t newValue) +{ + u8_t value; + + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_CTRL_REG4, &value) ) + return MEMS_ERROR; + + value &= ~LSM303AGR_ACC_BLE_MASK; + value |= newValue; + + if( !LSM303AGR_ACC_write_reg(handle, LSM303AGR_ACC_CTRL_REG4, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_LittleBigEndian +* Description : Read BLE +* Input : Pointer to LSM303AGR_ACC_BLE_t +* Output : Status of BLE see LSM303AGR_ACC_BLE_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_LittleBigEndian(void *handle, LSM303AGR_ACC_BLE_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_CTRL_REG4, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_BLE_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_W_BlockDataUpdate +* Description : Write BDU +* Input : LSM303AGR_ACC_BDU_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_ACC_W_BlockDataUpdate(void *handle, LSM303AGR_ACC_BDU_t newValue) +{ + u8_t value; + + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_CTRL_REG4, &value) ) + return MEMS_ERROR; + + value &= ~LSM303AGR_ACC_BDU_MASK; + value |= newValue; + + if( !LSM303AGR_ACC_write_reg(handle, LSM303AGR_ACC_CTRL_REG4, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_BlockDataUpdate +* Description : Read BDU +* Input : Pointer to LSM303AGR_ACC_BDU_t +* Output : Status of BDU see LSM303AGR_ACC_BDU_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_BlockDataUpdate(void *handle, LSM303AGR_ACC_BDU_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_CTRL_REG4, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_BDU_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_W_4D_on_INT2 +* Description : Write D4D_INT2 +* Input : LSM303AGR_ACC_D4D_INT2_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_ACC_W_4D_on_INT2(void *handle, LSM303AGR_ACC_D4D_INT2_t newValue) +{ + u8_t value; + + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_CTRL_REG5, &value) ) + return MEMS_ERROR; + + value &= ~LSM303AGR_ACC_D4D_INT2_MASK; + value |= newValue; + + if( !LSM303AGR_ACC_write_reg(handle, LSM303AGR_ACC_CTRL_REG5, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_4D_on_INT2 +* Description : Read D4D_INT2 +* Input : Pointer to LSM303AGR_ACC_D4D_INT2_t +* Output : Status of D4D_INT2 see LSM303AGR_ACC_D4D_INT2_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_4D_on_INT2(void *handle, LSM303AGR_ACC_D4D_INT2_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_CTRL_REG5, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_D4D_INT2_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_W_LatchInterrupt_on_INT2 +* Description : Write LIR_INT2 +* Input : LSM303AGR_ACC_LIR_INT2_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_ACC_W_LatchInterrupt_on_INT2(void *handle, LSM303AGR_ACC_LIR_INT2_t newValue) +{ + u8_t value; + + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_CTRL_REG5, &value) ) + return MEMS_ERROR; + + value &= ~LSM303AGR_ACC_LIR_INT2_MASK; + value |= newValue; + + if( !LSM303AGR_ACC_write_reg(handle, LSM303AGR_ACC_CTRL_REG5, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_LatchInterrupt_on_INT2 +* Description : Read LIR_INT2 +* Input : Pointer to LSM303AGR_ACC_LIR_INT2_t +* Output : Status of LIR_INT2 see LSM303AGR_ACC_LIR_INT2_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_LatchInterrupt_on_INT2(void *handle, LSM303AGR_ACC_LIR_INT2_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_CTRL_REG5, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_LIR_INT2_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_ACC_W_4D_on_INT1 +* Description : Write D4D_INT1 +* Input : LSM303AGR_ACC_D4D_INT1_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_ACC_W_4D_on_INT1(void *handle, LSM303AGR_ACC_D4D_INT1_t newValue) +{ + u8_t value; + + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_CTRL_REG5, &value) ) + return MEMS_ERROR; + + value &= ~LSM303AGR_ACC_D4D_INT1_MASK; + value |= newValue; + + if( !LSM303AGR_ACC_write_reg(handle, LSM303AGR_ACC_CTRL_REG5, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_4D_on_INT1 +* Description : Read D4D_INT1 +* Input : Pointer to LSM303AGR_ACC_D4D_INT1_t +* Output : Status of D4D_INT1 see LSM303AGR_ACC_D4D_INT1_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_4D_on_INT1(void *handle, LSM303AGR_ACC_D4D_INT1_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_CTRL_REG5, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_D4D_INT1_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_W_LatchInterrupt_on_INT1 +* Description : Write LIR_INT1 +* Input : LSM303AGR_ACC_LIR_INT1_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_ACC_W_LatchInterrupt_on_INT1(void *handle, LSM303AGR_ACC_LIR_INT1_t newValue) +{ + u8_t value; + + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_CTRL_REG5, &value) ) + return MEMS_ERROR; + + value &= ~LSM303AGR_ACC_LIR_INT1_MASK; + value |= newValue; + + if( !LSM303AGR_ACC_write_reg(handle, LSM303AGR_ACC_CTRL_REG5, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_LatchInterrupt_on_INT1 +* Description : Read LIR_INT1 +* Input : Pointer to LSM303AGR_ACC_LIR_INT1_t +* Output : Status of LIR_INT1 see LSM303AGR_ACC_LIR_INT1_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_LatchInterrupt_on_INT1(void *handle, LSM303AGR_ACC_LIR_INT1_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_CTRL_REG5, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_LIR_INT1_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_ACC_W_FIFO_EN +* Description : Write FIFO_EN +* Input : LSM303AGR_ACC_FIFO_EN_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_ACC_W_FIFO_EN(void *handle, LSM303AGR_ACC_FIFO_EN_t newValue) +{ + u8_t value; + + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_CTRL_REG5, &value) ) + return MEMS_ERROR; + + value &= ~LSM303AGR_ACC_FIFO_EN_MASK; + value |= newValue; + + if( !LSM303AGR_ACC_write_reg(handle, LSM303AGR_ACC_CTRL_REG5, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_FIFO_EN +* Description : Read FIFO_EN +* Input : Pointer to LSM303AGR_ACC_FIFO_EN_t +* Output : Status of FIFO_EN see LSM303AGR_ACC_FIFO_EN_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_FIFO_EN(void *handle, LSM303AGR_ACC_FIFO_EN_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_CTRL_REG5, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_FIFO_EN_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_W_RebootMemory +* Description : Write BOOT +* Input : LSM303AGR_ACC_BOOT_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_ACC_W_RebootMemory(void *handle, LSM303AGR_ACC_BOOT_t newValue) +{ + u8_t value; + + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_CTRL_REG5, &value) ) + return MEMS_ERROR; + + value &= ~LSM303AGR_ACC_BOOT_MASK; + value |= newValue; + + if( !LSM303AGR_ACC_write_reg(handle, LSM303AGR_ACC_CTRL_REG5, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_RebootMemory +* Description : Read BOOT +* Input : Pointer to LSM303AGR_ACC_BOOT_t +* Output : Status of BOOT see LSM303AGR_ACC_BOOT_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_RebootMemory(void *handle, LSM303AGR_ACC_BOOT_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_CTRL_REG5, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_BOOT_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_W_IntActive +* Description : Write H_LACTIVE +* Input : LSM303AGR_ACC_H_LACTIVE_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_ACC_W_IntActive(void *handle, LSM303AGR_ACC_H_LACTIVE_t newValue) +{ + u8_t value; + + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_CTRL_REG6, &value) ) + return MEMS_ERROR; + + value &= ~LSM303AGR_ACC_H_LACTIVE_MASK; + value |= newValue; + + if( !LSM303AGR_ACC_write_reg(handle, LSM303AGR_ACC_CTRL_REG6, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_IntActive +* Description : Read H_LACTIVE +* Input : Pointer to LSM303AGR_ACC_H_LACTIVE_t +* Output : Status of H_LACTIVE see LSM303AGR_ACC_H_LACTIVE_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_IntActive(void *handle, LSM303AGR_ACC_H_LACTIVE_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_CTRL_REG6, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_H_LACTIVE_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_ACC_W_P2_ACT +* Description : Write P2_ACT +* Input : LSM303AGR_ACC_P2_ACT_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_ACC_W_P2_ACT(void *handle, LSM303AGR_ACC_P2_ACT_t newValue) +{ + u8_t value; + + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_CTRL_REG6, &value) ) + return MEMS_ERROR; + + value &= ~LSM303AGR_ACC_P2_ACT_MASK; + value |= newValue; + + if( !LSM303AGR_ACC_write_reg(handle, LSM303AGR_ACC_CTRL_REG6, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_P2_ACT +* Description : Read P2_ACT +* Input : Pointer to LSM303AGR_ACC_P2_ACT_t +* Output : Status of P2_ACT see LSM303AGR_ACC_P2_ACT_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_P2_ACT(void *handle, LSM303AGR_ACC_P2_ACT_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_CTRL_REG6, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_P2_ACT_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_ACC_W_Boot_on_INT2 +* Description : Write BOOT_I1 +* Input : LSM303AGR_ACC_BOOT_I1_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_ACC_W_Boot_on_INT2(void *handle, LSM303AGR_ACC_BOOT_I1_t newValue) +{ + u8_t value; + + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_CTRL_REG6, &value) ) + return MEMS_ERROR; + + value &= ~LSM303AGR_ACC_BOOT_I1_MASK; + value |= newValue; + + if( !LSM303AGR_ACC_write_reg(handle, LSM303AGR_ACC_CTRL_REG6, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_Boot_on_INT2 +* Description : Read BOOT_I1 +* Input : Pointer to LSM303AGR_ACC_BOOT_I1_t +* Output : Status of BOOT_I1 see LSM303AGR_ACC_BOOT_I1_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_Boot_on_INT2(void *handle, LSM303AGR_ACC_BOOT_I1_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_CTRL_REG6, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_BOOT_I1_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_W_I2_on_INT2 +* Description : Write I2_INT2 +* Input : LSM303AGR_ACC_I2_INT2_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_ACC_W_I2_on_INT2(void *handle, LSM303AGR_ACC_I2_INT2_t newValue) +{ + u8_t value; + + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_CTRL_REG6, &value) ) + return MEMS_ERROR; + + value &= ~LSM303AGR_ACC_I2_INT2_MASK; + value |= newValue; + + if( !LSM303AGR_ACC_write_reg(handle, LSM303AGR_ACC_CTRL_REG6, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_I2_on_INT2 +* Description : Read I2_INT2 +* Input : Pointer to LSM303AGR_ACC_I2_INT2_t +* Output : Status of I2_INT2 see LSM303AGR_ACC_I2_INT2_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_I2_on_INT2(void *handle, LSM303AGR_ACC_I2_INT2_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_CTRL_REG6, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_I2_INT2_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_W_I2_on_INT1 +* Description : Write I2_INT1 +* Input : LSM303AGR_ACC_I2_INT1_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_ACC_W_I2_on_INT1(void *handle, LSM303AGR_ACC_I2_INT1_t newValue) +{ + u8_t value; + + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_CTRL_REG6, &value) ) + return MEMS_ERROR; + + value &= ~LSM303AGR_ACC_I2_INT1_MASK; + value |= newValue; + + if( !LSM303AGR_ACC_write_reg(handle, LSM303AGR_ACC_CTRL_REG6, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_I2_on_INT1 +* Description : Read I2_INT1 +* Input : Pointer to LSM303AGR_ACC_I2_INT1_t +* Output : Status of I2_INT1 see LSM303AGR_ACC_I2_INT1_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_I2_on_INT1(void *handle, LSM303AGR_ACC_I2_INT1_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_CTRL_REG6, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_I2_INT1_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_W_Click_on_INT2 +* Description : Write I2_CLICKEN +* Input : LSM303AGR_ACC_I2_CLICKEN_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_ACC_W_Click_on_INT2(void *handle, LSM303AGR_ACC_I2_CLICKEN_t newValue) +{ + u8_t value; + + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_CTRL_REG6, &value) ) + return MEMS_ERROR; + + value &= ~LSM303AGR_ACC_I2_CLICKEN_MASK; + value |= newValue; + + if( !LSM303AGR_ACC_write_reg(handle, LSM303AGR_ACC_CTRL_REG6, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_Click_on_INT2 +* Description : Read I2_CLICKEN +* Input : Pointer to LSM303AGR_ACC_I2_CLICKEN_t +* Output : Status of I2_CLICKEN see LSM303AGR_ACC_I2_CLICKEN_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_Click_on_INT2(void *handle, LSM303AGR_ACC_I2_CLICKEN_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_CTRL_REG6, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_I2_CLICKEN_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_W_ReferenceVal +* Description : Write REF +* Input : u8_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_ACC_W_ReferenceVal(void *handle, u8_t newValue) +{ + u8_t value; + + newValue = newValue << LSM303AGR_ACC_REF_POSITION; //mask + newValue &= LSM303AGR_ACC_REF_MASK; //coerce + + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_REFERENCE, &value) ) + return MEMS_ERROR; + + value &= (u8_t)~LSM303AGR_ACC_REF_MASK; + value |= newValue; + + if( !LSM303AGR_ACC_write_reg(handle, LSM303AGR_ACC_REFERENCE, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_ReferenceVal +* Description : Read REF +* Input : Pointer to u8_t +* Output : Status of REF +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_ReferenceVal(void *handle, u8_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_REFERENCE, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_REF_MASK; //coerce + *value = *value >> LSM303AGR_ACC_REF_POSITION; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_XDataAvail +* Description : Read XDA +* Input : Pointer to LSM303AGR_ACC_XDA_t +* Output : Status of XDA see LSM303AGR_ACC_XDA_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_XDataAvail(void *handle, LSM303AGR_ACC_XDA_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_STATUS_REG2, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_XDA_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_YDataAvail +* Description : Read YDA +* Input : Pointer to LSM303AGR_ACC_YDA_t +* Output : Status of YDA see LSM303AGR_ACC_YDA_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_YDataAvail(void *handle, LSM303AGR_ACC_YDA_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_STATUS_REG2, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_YDA_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_ZDataAvail +* Description : Read ZDA +* Input : Pointer to LSM303AGR_ACC_ZDA_t +* Output : Status of ZDA see LSM303AGR_ACC_ZDA_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_ZDataAvail(void *handle, LSM303AGR_ACC_ZDA_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_STATUS_REG2, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_ZDA_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_XYZDataAvail +* Description : Read ZYXDA +* Input : Pointer to LSM303AGR_ACC_ZYXDA_t +* Output : Status of ZYXDA see LSM303AGR_ACC_ZYXDA_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_XYZDataAvail(void *handle, LSM303AGR_ACC_ZYXDA_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_STATUS_REG2, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_ZYXDA_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_XDataOverrun +* Description : Read XOR +* Input : Pointer to LSM303AGR_ACC_XOR_t +* Output : Status of XOR see LSM303AGR_ACC_XOR_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_XDataOverrun(void *handle, LSM303AGR_ACC_XOR_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_STATUS_REG2, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_XOR_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_YDataOverrun +* Description : Read YOR +* Input : Pointer to LSM303AGR_ACC_YOR_t +* Output : Status of YOR see LSM303AGR_ACC_YOR_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_YDataOverrun(void *handle, LSM303AGR_ACC_YOR_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_STATUS_REG2, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_YOR_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_ZDataOverrun +* Description : Read ZOR +* Input : Pointer to LSM303AGR_ACC_ZOR_t +* Output : Status of ZOR see LSM303AGR_ACC_ZOR_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_ZDataOverrun(void *handle, LSM303AGR_ACC_ZOR_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_STATUS_REG2, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_ZOR_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_XYZDataOverrun +* Description : Read ZYXOR +* Input : Pointer to LSM303AGR_ACC_ZYXOR_t +* Output : Status of ZYXOR see LSM303AGR_ACC_ZYXOR_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_XYZDataOverrun(void *handle, LSM303AGR_ACC_ZYXOR_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_STATUS_REG2, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_ZYXOR_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_W_FifoThreshold +* Description : Write FTH +* Input : u8_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_ACC_W_FifoThreshold(void *handle, u8_t newValue) +{ + u8_t value; + + newValue = newValue << LSM303AGR_ACC_FTH_POSITION; //mask + newValue &= LSM303AGR_ACC_FTH_MASK; //coerce + + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_FIFO_CTRL_REG, &value) ) + return MEMS_ERROR; + + value &= ~LSM303AGR_ACC_FTH_MASK; + value |= newValue; + + if( !LSM303AGR_ACC_write_reg(handle, LSM303AGR_ACC_FIFO_CTRL_REG, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_FifoThreshold +* Description : Read FTH +* Input : Pointer to u8_t +* Output : Status of FTH +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_FifoThreshold(void *handle, u8_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_FIFO_CTRL_REG, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_FTH_MASK; //coerce + *value = *value >> LSM303AGR_ACC_FTH_POSITION; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_W_TriggerSel +* Description : Write TR +* Input : LSM303AGR_ACC_TR_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_ACC_W_TriggerSel(void *handle, LSM303AGR_ACC_TR_t newValue) +{ + u8_t value; + + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_FIFO_CTRL_REG, &value) ) + return MEMS_ERROR; + + value &= ~LSM303AGR_ACC_TR_MASK; + value |= newValue; + + if( !LSM303AGR_ACC_write_reg(handle, LSM303AGR_ACC_FIFO_CTRL_REG, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_TriggerSel +* Description : Read TR +* Input : Pointer to LSM303AGR_ACC_TR_t +* Output : Status of TR see LSM303AGR_ACC_TR_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_TriggerSel(void *handle, LSM303AGR_ACC_TR_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_FIFO_CTRL_REG, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_TR_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_W_FifoMode +* Description : Write FM +* Input : LSM303AGR_ACC_FM_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_ACC_W_FifoMode(void *handle, LSM303AGR_ACC_FM_t newValue) +{ + u8_t value; + + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_FIFO_CTRL_REG, &value) ) + return MEMS_ERROR; + + value &= ~LSM303AGR_ACC_FM_MASK; + value |= newValue; + + if( !LSM303AGR_ACC_write_reg(handle, LSM303AGR_ACC_FIFO_CTRL_REG, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_FifoMode +* Description : Read FM +* Input : Pointer to LSM303AGR_ACC_FM_t +* Output : Status of FM see LSM303AGR_ACC_FM_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_FifoMode(void *handle, LSM303AGR_ACC_FM_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_FIFO_CTRL_REG, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_FM_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_FifoSamplesAvail +* Description : Read FSS +* Input : Pointer to u8_t +* Output : Status of FSS +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_FifoSamplesAvail(void *handle, u8_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_FIFO_SRC_REG, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_FSS_MASK; //coerce + *value = *value >> LSM303AGR_ACC_FSS_POSITION; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_FifoEmpty +* Description : Read EMPTY +* Input : Pointer to LSM303AGR_ACC_EMPTY_t +* Output : Status of EMPTY see LSM303AGR_ACC_EMPTY_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_FifoEmpty(void *handle, LSM303AGR_ACC_EMPTY_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_FIFO_SRC_REG, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_EMPTY_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_FifoOverrun +* Description : Read OVRN_FIFO +* Input : Pointer to LSM303AGR_ACC_OVRN_FIFO_t +* Output : Status of OVRN_FIFO see LSM303AGR_ACC_OVRN_FIFO_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_FifoOverrun(void *handle, LSM303AGR_ACC_OVRN_FIFO_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_FIFO_SRC_REG, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_OVRN_FIFO_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_WatermarkLevel +* Description : Read WTM +* Input : Pointer to LSM303AGR_ACC_WTM_t +* Output : Status of WTM see LSM303AGR_ACC_WTM_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_WatermarkLevel(void *handle, LSM303AGR_ACC_WTM_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_FIFO_SRC_REG, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_WTM_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_W_Int1EnXLo +* Description : Write XLIE +* Input : LSM303AGR_ACC_XLIE_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_ACC_W_Int1EnXLo(void *handle, LSM303AGR_ACC_XLIE_t newValue) +{ + u8_t value; + + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_INT1_CFG, &value) ) + return MEMS_ERROR; + + value &= ~LSM303AGR_ACC_XLIE_MASK; + value |= newValue; + + if( !LSM303AGR_ACC_write_reg(handle, LSM303AGR_ACC_INT1_CFG, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_Int1EnXLo +* Description : Read XLIE +* Input : Pointer to LSM303AGR_ACC_XLIE_t +* Output : Status of XLIE see LSM303AGR_ACC_XLIE_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_Int1EnXLo(void *handle, LSM303AGR_ACC_XLIE_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_INT1_CFG, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_XLIE_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_W_Int1EnXHi +* Description : Write XHIE +* Input : LSM303AGR_ACC_XHIE_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_ACC_W_Int1EnXHi(void *handle, LSM303AGR_ACC_XHIE_t newValue) +{ + u8_t value; + + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_INT1_CFG, &value) ) + return MEMS_ERROR; + + value &= ~LSM303AGR_ACC_XHIE_MASK; + value |= newValue; + + if( !LSM303AGR_ACC_write_reg(handle, LSM303AGR_ACC_INT1_CFG, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_Int1EnXHi +* Description : Read XHIE +* Input : Pointer to LSM303AGR_ACC_XHIE_t +* Output : Status of XHIE see LSM303AGR_ACC_XHIE_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_Int1EnXHi(void *handle, LSM303AGR_ACC_XHIE_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_INT1_CFG, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_XHIE_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_W_Int1EnYLo +* Description : Write YLIE +* Input : LSM303AGR_ACC_YLIE_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_ACC_W_Int1EnYLo(void *handle, LSM303AGR_ACC_YLIE_t newValue) +{ + u8_t value; + + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_INT1_CFG, &value) ) + return MEMS_ERROR; + + value &= ~LSM303AGR_ACC_YLIE_MASK; + value |= newValue; + + if( !LSM303AGR_ACC_write_reg(handle, LSM303AGR_ACC_INT1_CFG, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_Int1EnYLo +* Description : Read YLIE +* Input : Pointer to LSM303AGR_ACC_YLIE_t +* Output : Status of YLIE see LSM303AGR_ACC_YLIE_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_Int1EnYLo(void *handle, LSM303AGR_ACC_YLIE_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_INT1_CFG, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_YLIE_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_W_Int1EnYHi +* Description : Write YHIE +* Input : LSM303AGR_ACC_YHIE_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_ACC_W_Int1EnYHi(void *handle, LSM303AGR_ACC_YHIE_t newValue) +{ + u8_t value; + + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_INT1_CFG, &value) ) + return MEMS_ERROR; + + value &= ~LSM303AGR_ACC_YHIE_MASK; + value |= newValue; + + if( !LSM303AGR_ACC_write_reg(handle, LSM303AGR_ACC_INT1_CFG, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_Int1EnYHi +* Description : Read YHIE +* Input : Pointer to LSM303AGR_ACC_YHIE_t +* Output : Status of YHIE see LSM303AGR_ACC_YHIE_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_Int1EnYHi(void *handle, LSM303AGR_ACC_YHIE_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_INT1_CFG, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_YHIE_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_W_Int1EnZLo +* Description : Write ZLIE +* Input : LSM303AGR_ACC_ZLIE_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_ACC_W_Int1EnZLo(void *handle, LSM303AGR_ACC_ZLIE_t newValue) +{ + u8_t value; + + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_INT1_CFG, &value) ) + return MEMS_ERROR; + + value &= ~LSM303AGR_ACC_ZLIE_MASK; + value |= newValue; + + if( !LSM303AGR_ACC_write_reg(handle, LSM303AGR_ACC_INT1_CFG, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_Int1EnZLo +* Description : Read ZLIE +* Input : Pointer to LSM303AGR_ACC_ZLIE_t +* Output : Status of ZLIE see LSM303AGR_ACC_ZLIE_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_Int1EnZLo(void *handle, LSM303AGR_ACC_ZLIE_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_INT1_CFG, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_ZLIE_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_W_Int1EnZHi +* Description : Write ZHIE +* Input : LSM303AGR_ACC_ZHIE_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_ACC_W_Int1EnZHi(void *handle, LSM303AGR_ACC_ZHIE_t newValue) +{ + u8_t value; + + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_INT1_CFG, &value) ) + return MEMS_ERROR; + + value &= ~LSM303AGR_ACC_ZHIE_MASK; + value |= newValue; + + if( !LSM303AGR_ACC_write_reg(handle, LSM303AGR_ACC_INT1_CFG, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_Int1EnZHi +* Description : Read ZHIE +* Input : Pointer to LSM303AGR_ACC_ZHIE_t +* Output : Status of ZHIE see LSM303AGR_ACC_ZHIE_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_Int1EnZHi(void *handle, LSM303AGR_ACC_ZHIE_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_INT1_CFG, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_ZHIE_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_W_Int1_6D +* Description : Write 6D +* Input : LSM303AGR_ACC_6D_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_ACC_W_Int1_6D(void *handle, LSM303AGR_ACC_6D_t newValue) +{ + u8_t value; + + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_INT1_CFG, &value) ) + return MEMS_ERROR; + + value &= ~LSM303AGR_ACC_6D_MASK; + value |= newValue; + + if( !LSM303AGR_ACC_write_reg(handle, LSM303AGR_ACC_INT1_CFG, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_Int1_6D +* Description : Read 6D +* Input : Pointer to LSM303AGR_ACC_6D_t +* Output : Status of 6D see LSM303AGR_ACC_6D_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_Int1_6D(void *handle, LSM303AGR_ACC_6D_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_INT1_CFG, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_6D_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_W_Int1_AOI +* Description : Write AOI +* Input : LSM303AGR_ACC_AOI_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_ACC_W_Int1_AOI(void *handle, LSM303AGR_ACC_AOI_t newValue) +{ + u8_t value; + + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_INT1_CFG, &value) ) + return MEMS_ERROR; + + value &= ~LSM303AGR_ACC_AOI_MASK; + value |= newValue; + + if( !LSM303AGR_ACC_write_reg(handle, LSM303AGR_ACC_INT1_CFG, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_Int1_AOI +* Description : Read AOI +* Input : Pointer to LSM303AGR_ACC_AOI_t +* Output : Status of AOI see LSM303AGR_ACC_AOI_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_Int1_AOI(void *handle, LSM303AGR_ACC_AOI_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_INT1_CFG, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_AOI_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_W_Int2EnXLo +* Description : Write XLIE +* Input : LSM303AGR_ACC_XLIE_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_ACC_W_Int2EnXLo(void *handle, LSM303AGR_ACC_XLIE_t newValue) +{ + u8_t value; + + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_INT2_CFG, &value) ) + return MEMS_ERROR; + + value &= ~LSM303AGR_ACC_XLIE_MASK; + value |= newValue; + + if( !LSM303AGR_ACC_write_reg(handle, LSM303AGR_ACC_INT2_CFG, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_Int2EnXLo +* Description : Read XLIE +* Input : Pointer to LSM303AGR_ACC_XLIE_t +* Output : Status of XLIE see LSM303AGR_ACC_XLIE_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_Int2EnXLo(void *handle, LSM303AGR_ACC_XLIE_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_INT2_CFG, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_XLIE_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_W_Int2EnXHi +* Description : Write XHIE +* Input : LSM303AGR_ACC_XHIE_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_ACC_W_Int2EnXHi(void *handle, LSM303AGR_ACC_XHIE_t newValue) +{ + u8_t value; + + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_INT2_CFG, &value) ) + return MEMS_ERROR; + + value &= ~LSM303AGR_ACC_XHIE_MASK; + value |= newValue; + + if( !LSM303AGR_ACC_write_reg(handle, LSM303AGR_ACC_INT2_CFG, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_Int2EnXHi +* Description : Read XHIE +* Input : Pointer to LSM303AGR_ACC_XHIE_t +* Output : Status of XHIE see LSM303AGR_ACC_XHIE_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_Int2EnXHi(void *handle, LSM303AGR_ACC_XHIE_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_INT2_CFG, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_XHIE_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_W_Int2EnYLo +* Description : Write YLIE +* Input : LSM303AGR_ACC_YLIE_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_ACC_W_Int2EnYLo(void *handle, LSM303AGR_ACC_YLIE_t newValue) +{ + u8_t value; + + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_INT2_CFG, &value) ) + return MEMS_ERROR; + + value &= ~LSM303AGR_ACC_YLIE_MASK; + value |= newValue; + + if( !LSM303AGR_ACC_write_reg(handle, LSM303AGR_ACC_INT2_CFG, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_Int2EnYLo +* Description : Read YLIE +* Input : Pointer to LSM303AGR_ACC_YLIE_t +* Output : Status of YLIE see LSM303AGR_ACC_YLIE_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_Int2EnYLo(void *handle, LSM303AGR_ACC_YLIE_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_INT2_CFG, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_YLIE_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_W_Int2EnYHi +* Description : Write YHIE +* Input : LSM303AGR_ACC_YHIE_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_ACC_W_Int2EnYHi(void *handle, LSM303AGR_ACC_YHIE_t newValue) +{ + u8_t value; + + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_INT2_CFG, &value) ) + return MEMS_ERROR; + + value &= ~LSM303AGR_ACC_YHIE_MASK; + value |= newValue; + + if( !LSM303AGR_ACC_write_reg(handle, LSM303AGR_ACC_INT2_CFG, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_Int2EnYHi +* Description : Read YHIE +* Input : Pointer to LSM303AGR_ACC_YHIE_t +* Output : Status of YHIE see LSM303AGR_ACC_YHIE_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_Int2EnYHi(void *handle, LSM303AGR_ACC_YHIE_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_INT2_CFG, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_YHIE_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_W_Int2EnZLo +* Description : Write ZLIE +* Input : LSM303AGR_ACC_ZLIE_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_ACC_W_Int2EnZLo(void *handle, LSM303AGR_ACC_ZLIE_t newValue) +{ + u8_t value; + + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_INT2_CFG, &value) ) + return MEMS_ERROR; + + value &= ~LSM303AGR_ACC_ZLIE_MASK; + value |= newValue; + + if( !LSM303AGR_ACC_write_reg(handle, LSM303AGR_ACC_INT2_CFG, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_Int2EnZLo +* Description : Read ZLIE +* Input : Pointer to LSM303AGR_ACC_ZLIE_t +* Output : Status of ZLIE see LSM303AGR_ACC_ZLIE_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_Int2EnZLo(void *handle, LSM303AGR_ACC_ZLIE_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_INT2_CFG, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_ZLIE_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_W_Int2EnZHi +* Description : Write ZHIE +* Input : LSM303AGR_ACC_ZHIE_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_ACC_W_Int2EnZHi(void *handle, LSM303AGR_ACC_ZHIE_t newValue) +{ + u8_t value; + + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_INT2_CFG, &value) ) + return MEMS_ERROR; + + value &= ~LSM303AGR_ACC_ZHIE_MASK; + value |= newValue; + + if( !LSM303AGR_ACC_write_reg(handle, LSM303AGR_ACC_INT2_CFG, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_Int2EnZHi +* Description : Read ZHIE +* Input : Pointer to LSM303AGR_ACC_ZHIE_t +* Output : Status of ZHIE see LSM303AGR_ACC_ZHIE_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_Int2EnZHi(void *handle, LSM303AGR_ACC_ZHIE_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_INT2_CFG, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_ZHIE_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_W_Int2_6D +* Description : Write 6D +* Input : LSM303AGR_ACC_6D_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_ACC_W_Int2_6D(void *handle, LSM303AGR_ACC_6D_t newValue) +{ + u8_t value; + + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_INT2_CFG, &value) ) + return MEMS_ERROR; + + value &= ~LSM303AGR_ACC_6D_MASK; + value |= newValue; + + if( !LSM303AGR_ACC_write_reg(handle, LSM303AGR_ACC_INT2_CFG, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_Int2_6D +* Description : Read 6D +* Input : Pointer to LSM303AGR_ACC_6D_t +* Output : Status of 6D see LSM303AGR_ACC_6D_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_Int2_6D(void *handle, LSM303AGR_ACC_6D_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_INT2_CFG, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_6D_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_W_Int2_AOI +* Description : Write AOI +* Input : LSM303AGR_ACC_AOI_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_ACC_W_Int2_AOI(void *handle, LSM303AGR_ACC_AOI_t newValue) +{ + u8_t value; + + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_INT2_CFG, &value) ) + return MEMS_ERROR; + + value &= ~LSM303AGR_ACC_AOI_MASK; + value |= newValue; + + if( !LSM303AGR_ACC_write_reg(handle, LSM303AGR_ACC_INT2_CFG, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_Int2_AOI +* Description : Read AOI +* Input : Pointer to LSM303AGR_ACC_AOI_t +* Output : Status of AOI see LSM303AGR_ACC_AOI_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_Int2_AOI(void *handle, LSM303AGR_ACC_AOI_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_INT2_CFG, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_AOI_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_Int1_Xlo +* Description : Read XL +* Input : Pointer to LSM303AGR_ACC_XL_t +* Output : Status of XL see LSM303AGR_ACC_XL_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_Int1_Xlo(void *handle, LSM303AGR_ACC_XL_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_INT1_SOURCE, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_XL_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_Int1_XHi +* Description : Read XH +* Input : Pointer to LSM303AGR_ACC_XH_t +* Output : Status of XH see LSM303AGR_ACC_XH_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_Int1_XHi(void *handle, LSM303AGR_ACC_XH_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_INT1_SOURCE, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_XH_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_Int1_YLo +* Description : Read YL +* Input : Pointer to LSM303AGR_ACC_YL_t +* Output : Status of YL see LSM303AGR_ACC_YL_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_Int1_YLo(void *handle, LSM303AGR_ACC_YL_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_INT1_SOURCE, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_YL_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_Int1_YHi +* Description : Read YH +* Input : Pointer to LSM303AGR_ACC_YH_t +* Output : Status of YH see LSM303AGR_ACC_YH_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_Int1_YHi(void *handle, LSM303AGR_ACC_YH_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_INT1_SOURCE, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_YH_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_Int1_Zlo +* Description : Read ZL +* Input : Pointer to LSM303AGR_ACC_ZL_t +* Output : Status of ZL see LSM303AGR_ACC_ZL_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_Int1_Zlo(void *handle, LSM303AGR_ACC_ZL_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_INT1_SOURCE, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_ZL_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_Int1_ZHi +* Description : Read ZH +* Input : Pointer to LSM303AGR_ACC_ZH_t +* Output : Status of ZH see LSM303AGR_ACC_ZH_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_Int1_ZHi(void *handle, LSM303AGR_ACC_ZH_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_INT1_SOURCE, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_ZH_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_Int1_IA +* Description : Read IA +* Input : Pointer to LSM303AGR_ACC_IA_t +* Output : Status of IA see LSM303AGR_ACC_IA_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_Int1_IA(void *handle, LSM303AGR_ACC_IA_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_INT1_SOURCE, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_IA_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_Int2_Xlo +* Description : Read XL +* Input : Pointer to LSM303AGR_ACC_XL_t +* Output : Status of XL see LSM303AGR_ACC_XL_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_Int2_Xlo(void *handle, LSM303AGR_ACC_XL_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_INT2_SOURCE, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_XL_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_Int2_XHi +* Description : Read XH +* Input : Pointer to LSM303AGR_ACC_XH_t +* Output : Status of XH see LSM303AGR_ACC_XH_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_Int2_XHi(void *handle, LSM303AGR_ACC_XH_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_INT2_SOURCE, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_XH_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_Int2_YLo +* Description : Read YL +* Input : Pointer to LSM303AGR_ACC_YL_t +* Output : Status of YL see LSM303AGR_ACC_YL_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_Int2_YLo(void *handle, LSM303AGR_ACC_YL_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_INT2_SOURCE, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_YL_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_Int2_YHi +* Description : Read YH +* Input : Pointer to LSM303AGR_ACC_YH_t +* Output : Status of YH see LSM303AGR_ACC_YH_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_Int2_YHi(void *handle, LSM303AGR_ACC_YH_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_INT2_SOURCE, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_YH_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_Int2_Zlo +* Description : Read ZL +* Input : Pointer to LSM303AGR_ACC_ZL_t +* Output : Status of ZL see LSM303AGR_ACC_ZL_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_Int2_Zlo(void *handle, LSM303AGR_ACC_ZL_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_INT2_SOURCE, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_ZL_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_Int2_ZHi +* Description : Read ZH +* Input : Pointer to LSM303AGR_ACC_ZH_t +* Output : Status of ZH see LSM303AGR_ACC_ZH_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_Int2_ZHi(void *handle, LSM303AGR_ACC_ZH_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_INT2_SOURCE, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_ZH_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_Int2_IA +* Description : Read IA +* Input : Pointer to LSM303AGR_ACC_IA_t +* Output : Status of IA see LSM303AGR_ACC_IA_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_Int2_IA(void *handle, LSM303AGR_ACC_IA_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_INT2_SOURCE, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_IA_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_ACC_W_Int1_Threshold +* Description : Write THS +* Input : u8_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_ACC_W_Int1_Threshold(void *handle, u8_t newValue) +{ + u8_t value; + + newValue = newValue << LSM303AGR_ACC_THS_POSITION; //mask + newValue &= LSM303AGR_ACC_THS_MASK; //coerce + + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_INT1_THS, &value) ) + return MEMS_ERROR; + + value &= ~LSM303AGR_ACC_THS_MASK; + value |= newValue; + + if( !LSM303AGR_ACC_write_reg(handle, LSM303AGR_ACC_INT1_THS, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_Int1_Threshold +* Description : Read THS +* Input : Pointer to u8_t +* Output : Status of THS +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_Int1_Threshold(void *handle, u8_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_INT1_THS, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_THS_MASK; //coerce + *value = *value >> LSM303AGR_ACC_THS_POSITION; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_ACC_W_Int2_Threshold +* Description : Write THS +* Input : u8_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_ACC_W_Int2_Threshold(void *handle, u8_t newValue) +{ + u8_t value; + + newValue = newValue << LSM303AGR_ACC_THS_POSITION; //mask + newValue &= LSM303AGR_ACC_THS_MASK; //coerce + + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_INT2_THS, &value) ) + return MEMS_ERROR; + + value &= ~LSM303AGR_ACC_THS_MASK; + value |= newValue; + + if( !LSM303AGR_ACC_write_reg(handle, LSM303AGR_ACC_INT2_THS, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_Int2_Threshold +* Description : Read THS +* Input : Pointer to u8_t +* Output : Status of THS +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_Int2_Threshold(void *handle, u8_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_INT2_THS, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_THS_MASK; //coerce + *value = *value >> LSM303AGR_ACC_THS_POSITION; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_ACC_W_Int1_Duration +* Description : Write D +* Input : u8_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_ACC_W_Int1_Duration(void *handle, u8_t newValue) +{ + u8_t value; + + newValue = newValue << LSM303AGR_ACC_D_POSITION; //mask + newValue &= LSM303AGR_ACC_D_MASK; //coerce + + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_INT1_DURATION, &value) ) + return MEMS_ERROR; + + value &= ~LSM303AGR_ACC_D_MASK; + value |= newValue; + + if( !LSM303AGR_ACC_write_reg(handle, LSM303AGR_ACC_INT1_DURATION, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_Int1_Duration +* Description : Read D +* Input : Pointer to u8_t +* Output : Status of D +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_Int1_Duration(void *handle, u8_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_INT1_DURATION, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_D_MASK; //coerce + *value = *value >> LSM303AGR_ACC_D_POSITION; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_ACC_W_Int2_Duration +* Description : Write D +* Input : u8_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_ACC_W_Int2_Duration(void *handle, u8_t newValue) +{ + u8_t value; + + newValue = newValue << LSM303AGR_ACC_D_POSITION; //mask + newValue &= LSM303AGR_ACC_D_MASK; //coerce + + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_INT2_DURATION, &value) ) + return MEMS_ERROR; + + value &= ~LSM303AGR_ACC_D_MASK; + value |= newValue; + + if( !LSM303AGR_ACC_write_reg(handle, LSM303AGR_ACC_INT2_DURATION, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_Int2_Duration +* Description : Read D +* Input : Pointer to u8_t +* Output : Status of D +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_Int2_Duration(void *handle, u8_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_INT2_DURATION, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_D_MASK; //coerce + *value = *value >> LSM303AGR_ACC_D_POSITION; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_ACC_W_XSingle +* Description : Write XS +* Input : LSM303AGR_ACC_XS_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_ACC_W_XSingle(void *handle, LSM303AGR_ACC_XS_t newValue) +{ + u8_t value; + + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_CLICK_CFG, &value) ) + return MEMS_ERROR; + + value &= ~LSM303AGR_ACC_XS_MASK; + value |= newValue; + + if( !LSM303AGR_ACC_write_reg(handle, LSM303AGR_ACC_CLICK_CFG, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_XSingle +* Description : Read XS +* Input : Pointer to LSM303AGR_ACC_XS_t +* Output : Status of XS see LSM303AGR_ACC_XS_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_XSingle(void *handle, LSM303AGR_ACC_XS_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_CLICK_CFG, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_XS_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_W_XDouble +* Description : Write XD +* Input : LSM303AGR_ACC_XD_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_ACC_W_XDouble(void *handle, LSM303AGR_ACC_XD_t newValue) +{ + u8_t value; + + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_CLICK_CFG, &value) ) + return MEMS_ERROR; + + value &= ~LSM303AGR_ACC_XD_MASK; + value |= newValue; + + if( !LSM303AGR_ACC_write_reg(handle, LSM303AGR_ACC_CLICK_CFG, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_XDouble +* Description : Read XD +* Input : Pointer to LSM303AGR_ACC_XD_t +* Output : Status of XD see LSM303AGR_ACC_XD_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_XDouble(void *handle, LSM303AGR_ACC_XD_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_CLICK_CFG, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_XD_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_W_YSingle +* Description : Write YS +* Input : LSM303AGR_ACC_YS_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_ACC_W_YSingle(void *handle, LSM303AGR_ACC_YS_t newValue) +{ + u8_t value; + + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_CLICK_CFG, &value) ) + return MEMS_ERROR; + + value &= ~LSM303AGR_ACC_YS_MASK; + value |= newValue; + + if( !LSM303AGR_ACC_write_reg(handle, LSM303AGR_ACC_CLICK_CFG, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_YSingle +* Description : Read YS +* Input : Pointer to LSM303AGR_ACC_YS_t +* Output : Status of YS see LSM303AGR_ACC_YS_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_YSingle(void *handle, LSM303AGR_ACC_YS_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_CLICK_CFG, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_YS_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_W_YDouble +* Description : Write YD +* Input : LSM303AGR_ACC_YD_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_ACC_W_YDouble(void *handle, LSM303AGR_ACC_YD_t newValue) +{ + u8_t value; + + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_CLICK_CFG, &value) ) + return MEMS_ERROR; + + value &= ~LSM303AGR_ACC_YD_MASK; + value |= newValue; + + if( !LSM303AGR_ACC_write_reg(handle, LSM303AGR_ACC_CLICK_CFG, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_YDouble +* Description : Read YD +* Input : Pointer to LSM303AGR_ACC_YD_t +* Output : Status of YD see LSM303AGR_ACC_YD_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_YDouble(void *handle, LSM303AGR_ACC_YD_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_CLICK_CFG, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_YD_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_W_ZSingle +* Description : Write ZS +* Input : LSM303AGR_ACC_ZS_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_ACC_W_ZSingle(void *handle, LSM303AGR_ACC_ZS_t newValue) +{ + u8_t value; + + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_CLICK_CFG, &value) ) + return MEMS_ERROR; + + value &= ~LSM303AGR_ACC_ZS_MASK; + value |= newValue; + + if( !LSM303AGR_ACC_write_reg(handle, LSM303AGR_ACC_CLICK_CFG, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_ZSingle +* Description : Read ZS +* Input : Pointer to LSM303AGR_ACC_ZS_t +* Output : Status of ZS see LSM303AGR_ACC_ZS_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_ZSingle(void *handle, LSM303AGR_ACC_ZS_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_CLICK_CFG, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_ZS_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_W_ZDouble +* Description : Write ZD +* Input : LSM303AGR_ACC_ZD_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_ACC_W_ZDouble(void *handle, LSM303AGR_ACC_ZD_t newValue) +{ + u8_t value; + + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_CLICK_CFG, &value) ) + return MEMS_ERROR; + + value &= ~LSM303AGR_ACC_ZD_MASK; + value |= newValue; + + if( !LSM303AGR_ACC_write_reg(handle, LSM303AGR_ACC_CLICK_CFG, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_ZDouble +* Description : Read ZD +* Input : Pointer to LSM303AGR_ACC_ZD_t +* Output : Status of ZD see LSM303AGR_ACC_ZD_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_ZDouble(void *handle, LSM303AGR_ACC_ZD_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_CLICK_CFG, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_ZD_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_ClickX +* Description : Read X +* Input : Pointer to LSM303AGR_ACC_X_t +* Output : Status of X see LSM303AGR_ACC_X_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_ClickX(void *handle, LSM303AGR_ACC_X_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_CLICK_SRC, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_X_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_ClickY +* Description : Read Y +* Input : Pointer to LSM303AGR_ACC_Y_t +* Output : Status of Y see LSM303AGR_ACC_Y_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_ClickY(void *handle, LSM303AGR_ACC_Y_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_CLICK_SRC, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_Y_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_ClickZ +* Description : Read Z +* Input : Pointer to LSM303AGR_ACC_Z_t +* Output : Status of Z see LSM303AGR_ACC_Z_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_ClickZ(void *handle, LSM303AGR_ACC_Z_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_CLICK_SRC, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_Z_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_ClickSign +* Description : Read SIGN +* Input : Pointer to LSM303AGR_ACC_SIGN_t +* Output : Status of SIGN see LSM303AGR_ACC_SIGN_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_ClickSign(void *handle, LSM303AGR_ACC_SIGN_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_CLICK_SRC, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_SIGN_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_SingleCLICK +* Description : Read SCLICK +* Input : Pointer to LSM303AGR_ACC_SCLICK_t +* Output : Status of SCLICK see LSM303AGR_ACC_SCLICK_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_SingleCLICK(void *handle, LSM303AGR_ACC_SCLICK_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_CLICK_SRC, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_SCLICK_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_DoubleCLICK +* Description : Read DCLICK +* Input : Pointer to LSM303AGR_ACC_DCLICK_t +* Output : Status of DCLICK see LSM303AGR_ACC_DCLICK_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_DoubleCLICK(void *handle, LSM303AGR_ACC_DCLICK_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_CLICK_SRC, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_DCLICK_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_IA +* Description : Read IA +* Input : Pointer to LSM303AGR_ACC_IA_t +* Output : Status of IA see LSM303AGR_ACC_IA_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_CLICK_IA(void *handle, LSM303AGR_ACC_CLICK_IA_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_CLICK_SRC, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_IA_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_W_ClickThreshold +* Description : Write THS +* Input : u8_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_ACC_W_ClickThreshold(void *handle, u8_t newValue) +{ + u8_t value; + + newValue = newValue << LSM303AGR_ACC_THS_POSITION; //mask + newValue &= LSM303AGR_ACC_THS_MASK; //coerce + + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_CLICK_THS, &value) ) + return MEMS_ERROR; + + value &= ~LSM303AGR_ACC_THS_MASK; + value |= newValue; + + if( !LSM303AGR_ACC_write_reg(handle, LSM303AGR_ACC_CLICK_THS, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_ClickThreshold +* Description : Read THS +* Input : Pointer to u8_t +* Output : Status of THS +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_ClickThreshold(void *handle, u8_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_CLICK_THS, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_THS_MASK; //coerce + *value = *value >> LSM303AGR_ACC_THS_POSITION; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_W_ClickTimeLimit +* Description : Write TLI +* Input : u8_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_ACC_W_ClickTimeLimit(void *handle, u8_t newValue) +{ + u8_t value; + + newValue = newValue << LSM303AGR_ACC_TLI_POSITION; //mask + newValue &= LSM303AGR_ACC_TLI_MASK; //coerce + + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_TIME_LIMIT, &value) ) + return MEMS_ERROR; + + value &= ~LSM303AGR_ACC_TLI_MASK; + value |= newValue; + + if( !LSM303AGR_ACC_write_reg(handle, LSM303AGR_ACC_TIME_LIMIT, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_ClickTimeLimit +* Description : Read TLI +* Input : Pointer to u8_t +* Output : Status of TLI +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_ClickTimeLimit(void *handle, u8_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_TIME_LIMIT, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_TLI_MASK; //coerce + *value = *value >> LSM303AGR_ACC_TLI_POSITION; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_W_ClickTimeLatency +* Description : Write TLA +* Input : u8_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_ACC_W_ClickTimeLatency(void *handle, u8_t newValue) +{ + u8_t value; + + newValue = newValue << LSM303AGR_ACC_TLA_POSITION; //mask + newValue &= LSM303AGR_ACC_TLA_MASK; //coerce + + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_TIME_LATENCY, &value) ) + return MEMS_ERROR; + + value &= (u8_t)~LSM303AGR_ACC_TLA_MASK; + value |= newValue; + + if( !LSM303AGR_ACC_write_reg(handle, LSM303AGR_ACC_TIME_LATENCY, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_ClickTimeLatency +* Description : Read TLA +* Input : Pointer to u8_t +* Output : Status of TLA +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_ClickTimeLatency(void *handle, u8_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_TIME_LATENCY, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_TLA_MASK; //coerce + *value = *value >> LSM303AGR_ACC_TLA_POSITION; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_ACC_W_ClickTimeWindow +* Description : Write TW +* Input : u8_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_ACC_W_ClickTimeWindow(void *handle, u8_t newValue) +{ + u8_t value; + + newValue = newValue << LSM303AGR_ACC_TW_POSITION; //mask + newValue &= LSM303AGR_ACC_TW_MASK; //coerce + + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_TIME_WINDOW, &value) ) + return MEMS_ERROR; + + value &= (u8_t)~LSM303AGR_ACC_TW_MASK; + value |= newValue; + + if( !LSM303AGR_ACC_write_reg(handle, LSM303AGR_ACC_TIME_WINDOW, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_ACC_R_ClickTimeWindow +* Description : Read TW +* Input : Pointer to u8_t +* Output : Status of TW +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_ACC_R_ClickTimeWindow(void *handle, u8_t *value) +{ + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_TIME_WINDOW, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_ACC_TW_MASK; //coerce + *value = *value >> LSM303AGR_ACC_TW_POSITION; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : mems_status_t LSM303AGR_ACC_Get_Voltage_ADC(u8_t *buff) +* Description : Read Voltage_ADC output register +* Input : pointer to [u8_t] +* Output : Voltage_ADC buffer u8_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_ACC_Get_Voltage_ADC(void *handle, u8_t *buff) +{ + u8_t i, j, k; + u8_t numberOfByteForDimension; + + numberOfByteForDimension=6/3; + + k=0; + for (i=0; i<3;i++ ) + { + for (j=0; j<numberOfByteForDimension;j++ ) + { + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_OUT_ADC1_L+k, &buff[k])) + return MEMS_ERROR; + k++; + } + } + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : mems_status_t LSM303AGR_ACC_Get_Raw_Acceleration(u8_t *buff) +* Description : Read Acceleration output register +* Input : pointer to [u8_t] +* Output : Acceleration buffer u8_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_ACC_Get_Raw_Acceleration(void *handle, u8_t *buff) +{ + u8_t i, j, k; + u8_t numberOfByteForDimension; + + numberOfByteForDimension=6/3; + + k=0; + for (i=0; i<3;i++ ) + { + for (j=0; j<numberOfByteForDimension;j++ ) + { + if( !LSM303AGR_ACC_read_reg(handle, LSM303AGR_ACC_OUT_X_L+k, &buff[k])) + return MEMS_ERROR; + k++; + } + } + + return MEMS_SUCCESS; +} + +/* + * Following is the table of sensitivity values for each case. + * Values are espressed in ug/digit. + */ +const long long LSM303AGR_ACC_Sensitivity_List[3][4] = { + /* HR 12-bit */ + { + 980, /* FS @2g */ + 1950, /* FS @4g */ + 3900, /* FS @8g */ + 11720, /* FS @16g */ + }, + + /* Normal 10-bit */ + { + 3900, /* FS @2g */ + 7820, /* FS @4g */ + 15630, /* FS @8g */ + 46900, /* FS @16g */ + }, + + /* LP 8-bit */ + { + 15630, /* FS @2g */ + 31260, /* FS @4g */ + 62520, /* FS @8g */ + 187580, /* FS @16g */ + }, +}; + +/* + * Values returned are espressed in mg. + */ +mems_status_t LSM303AGR_ACC_Get_Acceleration(void *handle, int *buff) +{ + Type3Axis16bit_U raw_data_tmp; + u8_t op_mode = 0, fs_mode = 0, shift = 0; + LSM303AGR_ACC_LPEN_t lp; + LSM303AGR_ACC_HR_t hr; + LSM303AGR_ACC_FS_t fs; + + /* Determine which operational mode the acc is set */ + if(!LSM303AGR_ACC_R_HiRes(handle, &hr)) { + return MEMS_ERROR; + } + + if(!LSM303AGR_ACC_R_LOWPWR_EN(handle, &lp)) { + return MEMS_ERROR; + } + + if (lp == LSM303AGR_ACC_LPEN_ENABLED && hr == LSM303AGR_ACC_HR_DISABLED) { + /* op mode is LP 8-bit */ + op_mode = 2; + shift = 8; + } else if (lp == LSM303AGR_ACC_LPEN_DISABLED && hr == LSM303AGR_ACC_HR_DISABLED) { + /* op mode is Normal 10-bit */ + op_mode = 1; + shift = 6; + } else if (lp == LSM303AGR_ACC_LPEN_DISABLED && hr == LSM303AGR_ACC_HR_ENABLED) { + /* op mode is HR 12-bit */ + op_mode = 0; + shift = 4; + } else { + return MEMS_ERROR; + } + + /* Determine the Full Scale the acc is set */ + if(!LSM303AGR_ACC_R_FullScale(handle, &fs)) { + return MEMS_ERROR; + } + + switch (fs) { + case LSM303AGR_ACC_FS_2G: + fs_mode = 0; + break; + + case LSM303AGR_ACC_FS_4G: + fs_mode = 1; + break; + + case LSM303AGR_ACC_FS_8G: + fs_mode = 2; + break; + + case LSM303AGR_ACC_FS_16G: + fs_mode = 3; + break; + } + + /* Read out raw accelerometer samples */ + if(!LSM303AGR_ACC_Get_Raw_Acceleration(handle, raw_data_tmp.u8bit)) { + return MEMS_ERROR; + } + + /* Apply proper shift and sensitivity */ + buff[0] = ((raw_data_tmp.i16bit[0] >> shift) * LSM303AGR_ACC_Sensitivity_List[op_mode][fs_mode] + 500) / 1000; + buff[1] = ((raw_data_tmp.i16bit[1] >> shift) * LSM303AGR_ACC_Sensitivity_List[op_mode][fs_mode] + 500) / 1000; + buff[2] = ((raw_data_tmp.i16bit[2] >> shift) * LSM303AGR_ACC_Sensitivity_List[op_mode][fs_mode] + 500) / 1000; + + return MEMS_SUCCESS; +}
diff -r 000000000000 -r 98c301bb7d1b Components/LSM303AGRSensor/LSM303AGR_acc_driver.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Components/LSM303AGRSensor/LSM303AGR_acc_driver.h Tue Oct 03 12:21:11 2017 +0000 @@ -0,0 +1,1608 @@ +/** + ****************************************************************************** + * @file LSM303AGR_acc_driver.h + * @author MEMS Application Team + * @version V1.1 + * @date 24-February-2016 + * @brief LSM303AGR Accelerometer header driver file + ****************************************************************************** + * @attention + * + * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of STMicroelectronics nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************** + */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __LSM303AGR_ACC_DRIVER__H +#define __LSM303AGR_ACC_DRIVER__H + +/* Includes ------------------------------------------------------------------*/ +#include <stdint.h> + +/* Exported types ------------------------------------------------------------*/ + +#ifdef __cplusplus +extern "C" { +#endif + +//these could change accordingly with the architecture + +#ifndef __ARCHDEP__TYPES +#define __ARCHDEP__TYPES + +typedef unsigned char u8_t; +typedef unsigned short int u16_t; +typedef unsigned int u32_t; +typedef int i32_t; +typedef short int i16_t; +typedef signed char i8_t; + +#endif /*__ARCHDEP__TYPES*/ + +/* Exported common structure --------------------------------------------------------*/ + +#ifndef __SHARED__TYPES +#define __SHARED__TYPES + +typedef union{ + i16_t i16bit[3]; + u8_t u8bit[6]; +} Type3Axis16bit_U; + +typedef union{ + i16_t i16bit; + u8_t u8bit[2]; +} Type1Axis16bit_U; + +typedef union{ + i32_t i32bit; + u8_t u8bit[4]; +} Type1Axis32bit_U; + +typedef enum { + MEMS_SUCCESS = 0x01, + MEMS_ERROR = 0x00 +} mems_status_t; + +#endif /*__SHARED__TYPES*/ + +/* Exported macro ------------------------------------------------------------*/ + +/* Exported constants --------------------------------------------------------*/ + +/************** I2C Address *****************/ + +#define LSM303AGR_ACC_I2C_ADDRESS 0x32 + +/************** Who am I *******************/ + +#define LSM303AGR_ACC_WHO_AM_I 0x33 + +/* Private Function Prototype -------------------------------------------------------*/ + +void LSM303AGR_ACC_SwapHighLowByte(u8_t *bufferToSwap, u8_t numberOfByte, u8_t dimension); + +/* Public Function Prototypes ------------------------------------------------*/ + +mems_status_t LSM303AGR_ACC_read_reg( void *handle, u8_t Reg, u8_t* Data ); +mems_status_t LSM303AGR_ACC_write_reg( void *handle, u8_t Reg, u8_t Data ); + + +/************** Device Register *******************/ +#define LSM303AGR_ACC_STATUS_REG_AUX 0X07 +#define LSM303AGR_ACC_OUT_ADC1_L 0X08 +#define LSM303AGR_ACC_OUT_ADC1_H 0X09 +#define LSM303AGR_ACC_OUT_ADC2_L 0X0A +#define LSM303AGR_ACC_OUT_ADC2_H 0X0B +#define LSM303AGR_ACC_OUT_ADC3_L 0X0C +#define LSM303AGR_ACC_OUT_ADC3_H 0X0D +#define LSM303AGR_ACC_INT_COUNTER_REG 0X0E +#define LSM303AGR_ACC_WHO_AM_I_REG 0X0F +#define LSM303AGR_ACC_TEMP_CFG_REG 0X1F +#define LSM303AGR_ACC_CTRL_REG1 0X20 +#define LSM303AGR_ACC_CTRL_REG2 0X21 +#define LSM303AGR_ACC_CTRL_REG3 0X22 +#define LSM303AGR_ACC_CTRL_REG4 0X23 +#define LSM303AGR_ACC_CTRL_REG5 0X24 +#define LSM303AGR_ACC_CTRL_REG6 0X25 +#define LSM303AGR_ACC_REFERENCE 0X26 +#define LSM303AGR_ACC_STATUS_REG2 0X27 +#define LSM303AGR_ACC_OUT_X_L 0X28 +#define LSM303AGR_ACC_OUT_X_H 0X29 +#define LSM303AGR_ACC_OUT_Y_L 0X2A +#define LSM303AGR_ACC_OUT_Y_H 0X2B +#define LSM303AGR_ACC_OUT_Z_L 0X2C +#define LSM303AGR_ACC_OUT_Z_H 0X2D +#define LSM303AGR_ACC_FIFO_CTRL_REG 0X2E +#define LSM303AGR_ACC_FIFO_SRC_REG 0X2F +#define LSM303AGR_ACC_INT1_CFG 0X30 +#define LSM303AGR_ACC_INT1_SOURCE 0X31 +#define LSM303AGR_ACC_INT1_THS 0X32 +#define LSM303AGR_ACC_INT1_DURATION 0X33 +#define LSM303AGR_ACC_INT2_CFG 0X34 +#define LSM303AGR_ACC_INT2_SOURCE 0X35 +#define LSM303AGR_ACC_INT2_THS 0X36 +#define LSM303AGR_ACC_INT2_DURATION 0X37 +#define LSM303AGR_ACC_CLICK_CFG 0X38 +#define LSM303AGR_ACC_CLICK_SRC 0X39 +#define LSM303AGR_ACC_CLICK_THS 0X3A +#define LSM303AGR_ACC_TIME_LIMIT 0X3B +#define LSM303AGR_ACC_TIME_LATENCY 0X3C +#define LSM303AGR_ACC_TIME_WINDOW 0X3D + +/******************************************************************************* +* Register : STATUS_REG_AUX +* Address : 0X07 +* Bit Group Name: 1DA +* Permission : RO +*******************************************************************************/ +typedef enum { + LSM303AGR_ACC_1DA_NOT_AVAILABLE =0x00, + LSM303AGR_ACC_1DA_AVAILABLE =0x01, +} LSM303AGR_ACC_1DA_t; + +#define LSM303AGR_ACC_1DA_MASK 0x01 +mems_status_t LSM303AGR_ACC_R_x_data_avail(void *handle, LSM303AGR_ACC_1DA_t *value); + +/******************************************************************************* +* Register : STATUS_REG_AUX +* Address : 0X07 +* Bit Group Name: 2DA_ +* Permission : RO +*******************************************************************************/ +typedef enum { + LSM303AGR_ACC_2DA__NOT_AVAILABLE =0x00, + LSM303AGR_ACC_2DA__AVAILABLE =0x02, +} LSM303AGR_ACC_2DA__t; + +#define LSM303AGR_ACC_2DA__MASK 0x02 +mems_status_t LSM303AGR_ACC_R_y_data_avail(void *handle, LSM303AGR_ACC_2DA__t *value); + +/******************************************************************************* +* Register : STATUS_REG_AUX +* Address : 0X07 +* Bit Group Name: 3DA_ +* Permission : RO +*******************************************************************************/ +typedef enum { + LSM303AGR_ACC_3DA__NOT_AVAILABLE =0x00, + LSM303AGR_ACC_3DA__AVAILABLE =0x04, +} LSM303AGR_ACC_3DA__t; + +#define LSM303AGR_ACC_3DA__MASK 0x04 +mems_status_t LSM303AGR_ACC_R_z_data_avail(void *handle, LSM303AGR_ACC_3DA__t *value); + +/******************************************************************************* +* Register : STATUS_REG_AUX +* Address : 0X07 +* Bit Group Name: 321DA_ +* Permission : RO +*******************************************************************************/ +typedef enum { + LSM303AGR_ACC_321DA__NOT_AVAILABLE =0x00, + LSM303AGR_ACC_321DA__AVAILABLE =0x08, +} LSM303AGR_ACC_321DA__t; + +#define LSM303AGR_ACC_321DA__MASK 0x08 +mems_status_t LSM303AGR_ACC_R_xyz_data_avail(void *handle, LSM303AGR_ACC_321DA__t *value); + +/******************************************************************************* +* Register : STATUS_REG_AUX +* Address : 0X07 +* Bit Group Name: 1OR_ +* Permission : RO +*******************************************************************************/ +typedef enum { + LSM303AGR_ACC_1OR__NO_OVERRUN =0x00, + LSM303AGR_ACC_1OR__OVERRUN =0x10, +} LSM303AGR_ACC_1OR__t; + +#define LSM303AGR_ACC_1OR__MASK 0x10 +mems_status_t LSM303AGR_ACC_R_DataXOverrun(void *handle, LSM303AGR_ACC_1OR__t *value); + +/******************************************************************************* +* Register : STATUS_REG_AUX +* Address : 0X07 +* Bit Group Name: 2OR_ +* Permission : RO +*******************************************************************************/ +typedef enum { + LSM303AGR_ACC_2OR__NO_OVERRUN =0x00, + LSM303AGR_ACC_2OR__OVERRUN =0x20, +} LSM303AGR_ACC_2OR__t; + +#define LSM303AGR_ACC_2OR__MASK 0x20 +mems_status_t LSM303AGR_ACC_R_DataYOverrun(void *handle, LSM303AGR_ACC_2OR__t *value); + +/******************************************************************************* +* Register : STATUS_REG_AUX +* Address : 0X07 +* Bit Group Name: 3OR_ +* Permission : RO +*******************************************************************************/ +typedef enum { + LSM303AGR_ACC_3OR__NO_OVERRUN =0x00, + LSM303AGR_ACC_3OR__OVERRUN =0x40, +} LSM303AGR_ACC_3OR__t; + +#define LSM303AGR_ACC_3OR__MASK 0x40 +mems_status_t LSM303AGR_ACC_R_DataZOverrun(void *handle, LSM303AGR_ACC_3OR__t *value); + +/******************************************************************************* +* Register : STATUS_REG_AUX +* Address : 0X07 +* Bit Group Name: 321OR_ +* Permission : RO +*******************************************************************************/ +typedef enum { + LSM303AGR_ACC_321OR__NO_OVERRUN =0x00, + LSM303AGR_ACC_321OR__OVERRUN =0x80, +} LSM303AGR_ACC_321OR__t; + +#define LSM303AGR_ACC_321OR__MASK 0x80 +mems_status_t LSM303AGR_ACC_R_DataXYZOverrun(void *handle, LSM303AGR_ACC_321OR__t *value); + +/******************************************************************************* +* Register : INT_COUNTER_REG +* Address : 0X0E +* Bit Group Name: IC +* Permission : RO +*******************************************************************************/ +#define LSM303AGR_ACC_IC_MASK 0xFF +#define LSM303AGR_ACC_IC_POSITION 0 +mems_status_t LSM303AGR_ACC_R_int_counter(void *handle, u8_t *value); + +/******************************************************************************* +* Register : WHO_AM_I +* Address : 0X0F +* Bit Group Name: WHO_AM_I +* Permission : RO +*******************************************************************************/ +#define LSM303AGR_ACC_WHO_AM_I_MASK 0xFF +#define LSM303AGR_ACC_WHO_AM_I_POSITION 0 +mems_status_t LSM303AGR_ACC_R_WHO_AM_I(void *handle, u8_t *value); + +/******************************************************************************* +* Register : TEMP_CFG_REG +* Address : 0X1F +* Bit Group Name: TEMP_EN +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM303AGR_ACC_TEMP_EN_DISABLED =0x00, + LSM303AGR_ACC_TEMP_EN_ENABLED =0x40, +} LSM303AGR_ACC_TEMP_EN_t; + +#define LSM303AGR_ACC_TEMP_EN_MASK 0x40 +mems_status_t LSM303AGR_ACC_W_TEMP_EN_bits(void *handle, LSM303AGR_ACC_TEMP_EN_t newValue); +mems_status_t LSM303AGR_ACC_R_TEMP_EN_bits(void *handle, LSM303AGR_ACC_TEMP_EN_t *value); + +/******************************************************************************* +* Register : TEMP_CFG_REG +* Address : 0X1F +* Bit Group Name: ADC_PD +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM303AGR_ACC_ADC_PD_DISABLED =0x00, + LSM303AGR_ACC_ADC_PD_ENABLED =0x80, +} LSM303AGR_ACC_ADC_PD_t; + +#define LSM303AGR_ACC_ADC_PD_MASK 0x80 +mems_status_t LSM303AGR_ACC_W_ADC_PD(void *handle, LSM303AGR_ACC_ADC_PD_t newValue); +mems_status_t LSM303AGR_ACC_R_ADC_PD(void *handle, LSM303AGR_ACC_ADC_PD_t *value); + +/******************************************************************************* +* Register : CTRL_REG1 +* Address : 0X20 +* Bit Group Name: XEN +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM303AGR_ACC_XEN_DISABLED =0x00, + LSM303AGR_ACC_XEN_ENABLED =0x01, +} LSM303AGR_ACC_XEN_t; + +#define LSM303AGR_ACC_XEN_MASK 0x01 +mems_status_t LSM303AGR_ACC_W_XEN(void *handle, LSM303AGR_ACC_XEN_t newValue); +mems_status_t LSM303AGR_ACC_R_XEN(void *handle, LSM303AGR_ACC_XEN_t *value); + +/******************************************************************************* +* Register : CTRL_REG1 +* Address : 0X20 +* Bit Group Name: YEN +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM303AGR_ACC_YEN_DISABLED =0x00, + LSM303AGR_ACC_YEN_ENABLED =0x02, +} LSM303AGR_ACC_YEN_t; + +#define LSM303AGR_ACC_YEN_MASK 0x02 +mems_status_t LSM303AGR_ACC_W_YEN(void *handle, LSM303AGR_ACC_YEN_t newValue); +mems_status_t LSM303AGR_ACC_R_YEN(void *handle, LSM303AGR_ACC_YEN_t *value); + +/******************************************************************************* +* Register : CTRL_REG1 +* Address : 0X20 +* Bit Group Name: ZEN +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM303AGR_ACC_ZEN_DISABLED =0x00, + LSM303AGR_ACC_ZEN_ENABLED =0x04, +} LSM303AGR_ACC_ZEN_t; + +#define LSM303AGR_ACC_ZEN_MASK 0x04 +mems_status_t LSM303AGR_ACC_W_ZEN(void *handle, LSM303AGR_ACC_ZEN_t newValue); +mems_status_t LSM303AGR_ACC_R_ZEN(void *handle, LSM303AGR_ACC_ZEN_t *value); + +/******************************************************************************* +* Register : CTRL_REG1 +* Address : 0X20 +* Bit Group Name: LPEN +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM303AGR_ACC_LPEN_DISABLED =0x00, + LSM303AGR_ACC_LPEN_ENABLED =0x08, +} LSM303AGR_ACC_LPEN_t; + +#define LSM303AGR_ACC_LPEN_MASK 0x08 +mems_status_t LSM303AGR_ACC_W_LOWPWR_EN(void *handle, LSM303AGR_ACC_LPEN_t newValue); +mems_status_t LSM303AGR_ACC_R_LOWPWR_EN(void *handle, LSM303AGR_ACC_LPEN_t *value); + +/******************************************************************************* +* Register : CTRL_REG1 +* Address : 0X20 +* Bit Group Name: ODR +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM303AGR_ACC_ODR_DO_PWR_DOWN =0x00, + LSM303AGR_ACC_ODR_DO_1Hz =0x10, + LSM303AGR_ACC_ODR_DO_10Hz =0x20, + LSM303AGR_ACC_ODR_DO_25Hz =0x30, + LSM303AGR_ACC_ODR_DO_50Hz =0x40, + LSM303AGR_ACC_ODR_DO_100Hz =0x50, + LSM303AGR_ACC_ODR_DO_200Hz =0x60, + LSM303AGR_ACC_ODR_DO_400Hz =0x70, + LSM303AGR_ACC_ODR_DO_1_6KHz =0x80, + LSM303AGR_ACC_ODR_DO_1_25KHz =0x90, +} LSM303AGR_ACC_ODR_t; + +#define LSM303AGR_ACC_ODR_MASK 0xF0 +mems_status_t LSM303AGR_ACC_W_ODR(void *handle, LSM303AGR_ACC_ODR_t newValue); +mems_status_t LSM303AGR_ACC_R_ODR(void *handle, LSM303AGR_ACC_ODR_t *value); + +/******************************************************************************* +* Register : CTRL_REG2 +* Address : 0X21 +* Bit Group Name: HPIS1 +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM303AGR_ACC_HPIS1_DISABLED =0x00, + LSM303AGR_ACC_HPIS1_ENABLED =0x01, +} LSM303AGR_ACC_HPIS1_t; + +#define LSM303AGR_ACC_HPIS1_MASK 0x01 +mems_status_t LSM303AGR_ACC_W_hpf_aoi_en_int1(void *handle, LSM303AGR_ACC_HPIS1_t newValue); +mems_status_t LSM303AGR_ACC_R_hpf_aoi_en_int1(void *handle, LSM303AGR_ACC_HPIS1_t *value); + +/******************************************************************************* +* Register : CTRL_REG2 +* Address : 0X21 +* Bit Group Name: HPIS2 +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM303AGR_ACC_HPIS2_DISABLED =0x00, + LSM303AGR_ACC_HPIS2_ENABLED =0x02, +} LSM303AGR_ACC_HPIS2_t; + +#define LSM303AGR_ACC_HPIS2_MASK 0x02 +mems_status_t LSM303AGR_ACC_W_hpf_aoi_en_int2(void *handle, LSM303AGR_ACC_HPIS2_t newValue); +mems_status_t LSM303AGR_ACC_R_hpf_aoi_en_int2(void *handle, LSM303AGR_ACC_HPIS2_t *value); + +/******************************************************************************* +* Register : CTRL_REG2 +* Address : 0X21 +* Bit Group Name: HPCLICK +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM303AGR_ACC_HPCLICK_DISABLED =0x00, + LSM303AGR_ACC_HPCLICK_ENABLED =0x04, +} LSM303AGR_ACC_HPCLICK_t; + +#define LSM303AGR_ACC_HPCLICK_MASK 0x04 +mems_status_t LSM303AGR_ACC_W_hpf_click_en(void *handle, LSM303AGR_ACC_HPCLICK_t newValue); +mems_status_t LSM303AGR_ACC_R_hpf_click_en(void *handle, LSM303AGR_ACC_HPCLICK_t *value); + +/******************************************************************************* +* Register : CTRL_REG2 +* Address : 0X21 +* Bit Group Name: FDS +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM303AGR_ACC_FDS_BYPASSED =0x00, + LSM303AGR_ACC_FDS_ENABLED =0x08, +} LSM303AGR_ACC_FDS_t; + +#define LSM303AGR_ACC_FDS_MASK 0x08 +mems_status_t LSM303AGR_ACC_W_Data_Filter(void *handle, LSM303AGR_ACC_FDS_t newValue); +mems_status_t LSM303AGR_ACC_R_Data_Filter(void *handle, LSM303AGR_ACC_FDS_t *value); + +/******************************************************************************* +* Register : CTRL_REG2 +* Address : 0X21 +* Bit Group Name: HPCF +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM303AGR_ACC_HPCF_00 =0x00, + LSM303AGR_ACC_HPCF_01 =0x10, + LSM303AGR_ACC_HPCF_10 =0x20, + LSM303AGR_ACC_HPCF_11 =0x30, +} LSM303AGR_ACC_HPCF_t; + +#define LSM303AGR_ACC_HPCF_MASK 0x30 +mems_status_t LSM303AGR_ACC_W_hpf_cutoff_freq(void *handle, LSM303AGR_ACC_HPCF_t newValue); +mems_status_t LSM303AGR_ACC_R_hpf_cutoff_freq(void *handle, LSM303AGR_ACC_HPCF_t *value); + +/******************************************************************************* +* Register : CTRL_REG2 +* Address : 0X21 +* Bit Group Name: HPM +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM303AGR_ACC_HPM_NORMAL =0x00, + LSM303AGR_ACC_HPM_REFERENCE_SIGNAL =0x40, + LSM303AGR_ACC_HPM_NORMAL_2 =0x80, + LSM303AGR_ACC_HPM_AUTORST_ON_INT =0xC0, +} LSM303AGR_ACC_HPM_t; + +#define LSM303AGR_ACC_HPM_MASK 0xC0 +mems_status_t LSM303AGR_ACC_W_hpf_mode(void *handle, LSM303AGR_ACC_HPM_t newValue); +mems_status_t LSM303AGR_ACC_R_hpf_mode(void *handle, LSM303AGR_ACC_HPM_t *value); + +/******************************************************************************* +* Register : CTRL_REG3 +* Address : 0X22 +* Bit Group Name: I1_OVERRUN +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM303AGR_ACC_I1_OVERRUN_DISABLED =0x00, + LSM303AGR_ACC_I1_OVERRUN_ENABLED =0x02, +} LSM303AGR_ACC_I1_OVERRUN_t; + +#define LSM303AGR_ACC_I1_OVERRUN_MASK 0x02 +mems_status_t LSM303AGR_ACC_W_FIFO_Overrun_on_INT1(void *handle, LSM303AGR_ACC_I1_OVERRUN_t newValue); +mems_status_t LSM303AGR_ACC_R_FIFO_Overrun_on_INT1(void *handle, LSM303AGR_ACC_I1_OVERRUN_t *value); + +/******************************************************************************* +* Register : CTRL_REG3 +* Address : 0X22 +* Bit Group Name: I1_WTM +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM303AGR_ACC_I1_WTM_DISABLED =0x00, + LSM303AGR_ACC_I1_WTM_ENABLED =0x04, +} LSM303AGR_ACC_I1_WTM_t; + +#define LSM303AGR_ACC_I1_WTM_MASK 0x04 +mems_status_t LSM303AGR_ACC_W_FIFO_Watermark_on_INT1(void *handle, LSM303AGR_ACC_I1_WTM_t newValue); +mems_status_t LSM303AGR_ACC_R_FIFO_Watermark_on_INT1(void *handle, LSM303AGR_ACC_I1_WTM_t *value); + +/******************************************************************************* +* Register : CTRL_REG3 +* Address : 0X22 +* Bit Group Name: I1_DRDY2 +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM303AGR_ACC_I1_DRDY2_DISABLED =0x00, + LSM303AGR_ACC_I1_DRDY2_ENABLED =0x08, +} LSM303AGR_ACC_I1_DRDY2_t; + +#define LSM303AGR_ACC_I1_DRDY2_MASK 0x08 +mems_status_t LSM303AGR_ACC_W_FIFO_DRDY2_on_INT1(void *handle, LSM303AGR_ACC_I1_DRDY2_t newValue); +mems_status_t LSM303AGR_ACC_R_FIFO_DRDY2_on_INT1(void *handle, LSM303AGR_ACC_I1_DRDY2_t *value); + +/******************************************************************************* +* Register : CTRL_REG3 +* Address : 0X22 +* Bit Group Name: I1_DRDY1 +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM303AGR_ACC_I1_DRDY1_DISABLED =0x00, + LSM303AGR_ACC_I1_DRDY1_ENABLED =0x10, +} LSM303AGR_ACC_I1_DRDY1_t; + +#define LSM303AGR_ACC_I1_DRDY1_MASK 0x10 +mems_status_t LSM303AGR_ACC_W_FIFO_DRDY1_on_INT1(void *handle, LSM303AGR_ACC_I1_DRDY1_t newValue); +mems_status_t LSM303AGR_ACC_R_FIFO_DRDY1_on_INT1(void *handle, LSM303AGR_ACC_I1_DRDY1_t *value); + +/******************************************************************************* +* Register : CTRL_REG3 +* Address : 0X22 +* Bit Group Name: I1_AOI2 +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM303AGR_ACC_I1_AOI2_DISABLED =0x00, + LSM303AGR_ACC_I1_AOI2_ENABLED =0x20, +} LSM303AGR_ACC_I1_AOI2_t; + +#define LSM303AGR_ACC_I1_AOI2_MASK 0x20 +mems_status_t LSM303AGR_ACC_W_FIFO_AOL2_on_INT1(void *handle, LSM303AGR_ACC_I1_AOI2_t newValue); +mems_status_t LSM303AGR_ACC_R_FIFO_AOL2_on_INT1(void *handle, LSM303AGR_ACC_I1_AOI2_t *value); + +/******************************************************************************* +* Register : CTRL_REG3 +* Address : 0X22 +* Bit Group Name: I1_AOI1 +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM303AGR_ACC_I1_AOI1_DISABLED =0x00, + LSM303AGR_ACC_I1_AOI1_ENABLED =0x40, +} LSM303AGR_ACC_I1_AOI1_t; + +#define LSM303AGR_ACC_I1_AOI1_MASK 0x40 +mems_status_t LSM303AGR_ACC_W_FIFO_AOL1_on_INT1(void *handle, LSM303AGR_ACC_I1_AOI1_t newValue); +mems_status_t LSM303AGR_ACC_R_FIFO_AOL1_on_INT1(void *handle, LSM303AGR_ACC_I1_AOI1_t *value); + +/******************************************************************************* +* Register : CTRL_REG3 +* Address : 0X22 +* Bit Group Name: I1_CLICK +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM303AGR_ACC_I1_CLICK_DISABLED =0x00, + LSM303AGR_ACC_I1_CLICK_ENABLED =0x80, +} LSM303AGR_ACC_I1_CLICK_t; + +#define LSM303AGR_ACC_I1_CLICK_MASK 0x80 +mems_status_t LSM303AGR_ACC_W_FIFO_Click_on_INT1(void *handle, LSM303AGR_ACC_I1_CLICK_t newValue); +mems_status_t LSM303AGR_ACC_R_FIFO_Click_on_INT1(void *handle, LSM303AGR_ACC_I1_CLICK_t *value); + +/******************************************************************************* +* Register : CTRL_REG4 +* Address : 0X23 +* Bit Group Name: SIM +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM303AGR_ACC_SIM_4_WIRES =0x00, + LSM303AGR_ACC_SIM_3_WIRES =0x01, +} LSM303AGR_ACC_SIM_t; + +#define LSM303AGR_ACC_SIM_MASK 0x01 +mems_status_t LSM303AGR_ACC_W_SPI_mode(void *handle, LSM303AGR_ACC_SIM_t newValue); +mems_status_t LSM303AGR_ACC_R_SPI_mode(void *handle, LSM303AGR_ACC_SIM_t *value); + +/******************************************************************************* +* Register : CTRL_REG4 +* Address : 0X23 +* Bit Group Name: ST +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM303AGR_ACC_ST_DISABLED =0x00, + LSM303AGR_ACC_ST_SELF_TEST_0 =0x02, + LSM303AGR_ACC_ST_SELF_TEST_1 =0x04, + LSM303AGR_ACC_ST_NOT_APPLICABLE =0x06, +} LSM303AGR_ACC_ST_t; + +#define LSM303AGR_ACC_ST_MASK 0x06 +mems_status_t LSM303AGR_ACC_W_SelfTest(void *handle, LSM303AGR_ACC_ST_t newValue); +mems_status_t LSM303AGR_ACC_R_SelfTest(void *handle, LSM303AGR_ACC_ST_t *value); + +/******************************************************************************* +* Register : CTRL_REG4 +* Address : 0X23 +* Bit Group Name: HR +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM303AGR_ACC_HR_DISABLED =0x00, + LSM303AGR_ACC_HR_ENABLED =0x08, +} LSM303AGR_ACC_HR_t; + +#define LSM303AGR_ACC_HR_MASK 0x08 +mems_status_t LSM303AGR_ACC_W_HiRes(void *handle, LSM303AGR_ACC_HR_t newValue); +mems_status_t LSM303AGR_ACC_R_HiRes(void *handle, LSM303AGR_ACC_HR_t *value); + +/******************************************************************************* +* Register : CTRL_REG4 +* Address : 0X23 +* Bit Group Name: FS +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM303AGR_ACC_FS_2G =0x00, + LSM303AGR_ACC_FS_4G =0x10, + LSM303AGR_ACC_FS_8G =0x20, + LSM303AGR_ACC_FS_16G =0x30, +} LSM303AGR_ACC_FS_t; + +#define LSM303AGR_ACC_FS_MASK 0x30 +mems_status_t LSM303AGR_ACC_W_FullScale(void *handle, LSM303AGR_ACC_FS_t newValue); +mems_status_t LSM303AGR_ACC_R_FullScale(void *handle, LSM303AGR_ACC_FS_t *value); + +/******************************************************************************* +* Register : CTRL_REG4 +* Address : 0X23 +* Bit Group Name: BLE +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM303AGR_ACC_BLE_LITTLE_ENDIAN =0x00, + LSM303AGR_ACC_BLE_BIG_ENDIAN =0x40, +} LSM303AGR_ACC_BLE_t; + +#define LSM303AGR_ACC_BLE_MASK 0x40 +mems_status_t LSM303AGR_ACC_W_LittleBigEndian(void *handle, LSM303AGR_ACC_BLE_t newValue); +mems_status_t LSM303AGR_ACC_R_LittleBigEndian(void *handle, LSM303AGR_ACC_BLE_t *value); + +/******************************************************************************* +* Register : CTRL_REG4 +* Address : 0X23 +* Bit Group Name: BDU +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM303AGR_ACC_BDU_DISABLED =0x00, + LSM303AGR_ACC_BDU_ENABLED =0x80, +} LSM303AGR_ACC_BDU_t; + +#define LSM303AGR_ACC_BDU_MASK 0x80 +mems_status_t LSM303AGR_ACC_W_BlockDataUpdate(void *handle, LSM303AGR_ACC_BDU_t newValue); +mems_status_t LSM303AGR_ACC_R_BlockDataUpdate(void *handle, LSM303AGR_ACC_BDU_t *value); + +/******************************************************************************* +* Register : CTRL_REG5 +* Address : 0X24 +* Bit Group Name: D4D_INT2 +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM303AGR_ACC_D4D_INT2_DISABLED =0x00, + LSM303AGR_ACC_D4D_INT2_ENABLED =0x01, +} LSM303AGR_ACC_D4D_INT2_t; + +#define LSM303AGR_ACC_D4D_INT2_MASK 0x01 +mems_status_t LSM303AGR_ACC_W_4D_on_INT2(void *handle, LSM303AGR_ACC_D4D_INT2_t newValue); +mems_status_t LSM303AGR_ACC_R_4D_on_INT2(void *handle, LSM303AGR_ACC_D4D_INT2_t *value); + +/******************************************************************************* +* Register : CTRL_REG5 +* Address : 0X24 +* Bit Group Name: LIR_INT2 +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM303AGR_ACC_LIR_INT2_DISABLED =0x00, + LSM303AGR_ACC_LIR_INT2_ENABLED =0x02, +} LSM303AGR_ACC_LIR_INT2_t; + +#define LSM303AGR_ACC_LIR_INT2_MASK 0x02 +mems_status_t LSM303AGR_ACC_W_LatchInterrupt_on_INT2(void *handle, LSM303AGR_ACC_LIR_INT2_t newValue); +mems_status_t LSM303AGR_ACC_R_LatchInterrupt_on_INT2(void *handle, LSM303AGR_ACC_LIR_INT2_t *value); + +/******************************************************************************* +* Register : CTRL_REG5 +* Address : 0X24 +* Bit Group Name: D4D_INT1 +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM303AGR_ACC_D4D_INT1_DISABLED =0x00, + LSM303AGR_ACC_D4D_INT1_ENABLED =0x04, +} LSM303AGR_ACC_D4D_INT1_t; + +#define LSM303AGR_ACC_D4D_INT1_MASK 0x04 +mems_status_t LSM303AGR_ACC_W_4D_on_INT1(void *handle, LSM303AGR_ACC_D4D_INT1_t newValue); +mems_status_t LSM303AGR_ACC_R_4D_on_INT1(void *handle, LSM303AGR_ACC_D4D_INT1_t *value); + +/******************************************************************************* +* Register : CTRL_REG5 +* Address : 0X24 +* Bit Group Name: LIR_INT1 +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM303AGR_ACC_LIR_INT1_DISABLED =0x00, + LSM303AGR_ACC_LIR_INT1_ENABLED =0x08, +} LSM303AGR_ACC_LIR_INT1_t; + +#define LSM303AGR_ACC_LIR_INT1_MASK 0x08 +mems_status_t LSM303AGR_ACC_W_LatchInterrupt_on_INT1(void *handle, LSM303AGR_ACC_LIR_INT1_t newValue); +mems_status_t LSM303AGR_ACC_R_LatchInterrupt_on_INT1(void *handle, LSM303AGR_ACC_LIR_INT1_t *value); + +/******************************************************************************* +* Register : CTRL_REG5 +* Address : 0X24 +* Bit Group Name: FIFO_EN +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM303AGR_ACC_FIFO_EN_DISABLED =0x00, + LSM303AGR_ACC_FIFO_EN_ENABLED =0x40, +} LSM303AGR_ACC_FIFO_EN_t; + +#define LSM303AGR_ACC_FIFO_EN_MASK 0x40 +mems_status_t LSM303AGR_ACC_W_FIFO_EN(void *handle, LSM303AGR_ACC_FIFO_EN_t newValue); +mems_status_t LSM303AGR_ACC_R_FIFO_EN(void *handle, LSM303AGR_ACC_FIFO_EN_t *value); + +/******************************************************************************* +* Register : CTRL_REG5 +* Address : 0X24 +* Bit Group Name: BOOT +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM303AGR_ACC_BOOT_NORMAL_MODE =0x00, + LSM303AGR_ACC_BOOT_REBOOT =0x80, +} LSM303AGR_ACC_BOOT_t; + +#define LSM303AGR_ACC_BOOT_MASK 0x80 +mems_status_t LSM303AGR_ACC_W_RebootMemory(void *handle, LSM303AGR_ACC_BOOT_t newValue); +mems_status_t LSM303AGR_ACC_R_RebootMemory(void *handle, LSM303AGR_ACC_BOOT_t *value); + +/******************************************************************************* +* Register : CTRL_REG6 +* Address : 0X25 +* Bit Group Name: H_LACTIVE +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM303AGR_ACC_H_LACTIVE_ACTIVE_HI =0x00, + LSM303AGR_ACC_H_LACTIVE_ACTIVE_LO =0x02, +} LSM303AGR_ACC_H_LACTIVE_t; + +#define LSM303AGR_ACC_H_LACTIVE_MASK 0x02 +mems_status_t LSM303AGR_ACC_W_IntActive(void *handle, LSM303AGR_ACC_H_LACTIVE_t newValue); +mems_status_t LSM303AGR_ACC_R_IntActive(void *handle, LSM303AGR_ACC_H_LACTIVE_t *value); + +/******************************************************************************* +* Register : CTRL_REG6 +* Address : 0X25 +* Bit Group Name: P2_ACT +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM303AGR_ACC_P2_ACT_DISABLED =0x00, + LSM303AGR_ACC_P2_ACT_ENABLED =0x08, +} LSM303AGR_ACC_P2_ACT_t; + +#define LSM303AGR_ACC_P2_ACT_MASK 0x08 +mems_status_t LSM303AGR_ACC_W_P2_ACT(void *handle, LSM303AGR_ACC_P2_ACT_t newValue); +mems_status_t LSM303AGR_ACC_R_P2_ACT(void *handle, LSM303AGR_ACC_P2_ACT_t *value); + +/******************************************************************************* +* Register : CTRL_REG6 +* Address : 0X25 +* Bit Group Name: BOOT_I1 +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM303AGR_ACC_BOOT_I1_DISABLED =0x00, + LSM303AGR_ACC_BOOT_I1_ENABLED =0x10, +} LSM303AGR_ACC_BOOT_I1_t; + +#define LSM303AGR_ACC_BOOT_I1_MASK 0x10 +mems_status_t LSM303AGR_ACC_W_Boot_on_INT2(void *handle, LSM303AGR_ACC_BOOT_I1_t newValue); +mems_status_t LSM303AGR_ACC_R_Boot_on_INT2(void *handle, LSM303AGR_ACC_BOOT_I1_t *value); + +/******************************************************************************* +* Register : CTRL_REG6 +* Address : 0X25 +* Bit Group Name: I2_INT2 +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM303AGR_ACC_I2_INT2_DISABLED =0x00, + LSM303AGR_ACC_I2_INT2_ENABLED =0x20, +} LSM303AGR_ACC_I2_INT2_t; + +#define LSM303AGR_ACC_I2_INT2_MASK 0x20 +mems_status_t LSM303AGR_ACC_W_I2_on_INT2(void *handle, LSM303AGR_ACC_I2_INT2_t newValue); +mems_status_t LSM303AGR_ACC_R_I2_on_INT2(void *handle, LSM303AGR_ACC_I2_INT2_t *value); + +/******************************************************************************* +* Register : CTRL_REG6 +* Address : 0X25 +* Bit Group Name: I2_INT1 +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM303AGR_ACC_I2_INT1_DISABLED =0x00, + LSM303AGR_ACC_I2_INT1_ENABLED =0x40, +} LSM303AGR_ACC_I2_INT1_t; + +#define LSM303AGR_ACC_I2_INT1_MASK 0x40 +mems_status_t LSM303AGR_ACC_W_I2_on_INT1(void *handle, LSM303AGR_ACC_I2_INT1_t newValue); +mems_status_t LSM303AGR_ACC_R_I2_on_INT1(void *handle, LSM303AGR_ACC_I2_INT1_t *value); + +/******************************************************************************* +* Register : CTRL_REG6 +* Address : 0X25 +* Bit Group Name: I2_CLICKEN +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM303AGR_ACC_I2_CLICKEN_DISABLED =0x00, + LSM303AGR_ACC_I2_CLICKEN_ENABLED =0x80, +} LSM303AGR_ACC_I2_CLICKEN_t; + +#define LSM303AGR_ACC_I2_CLICKEN_MASK 0x80 +mems_status_t LSM303AGR_ACC_W_Click_on_INT2(void *handle, LSM303AGR_ACC_I2_CLICKEN_t newValue); +mems_status_t LSM303AGR_ACC_R_Click_on_INT2(void *handle, LSM303AGR_ACC_I2_CLICKEN_t *value); + +/******************************************************************************* +* Register : REFERENCE +* Address : 0X26 +* Bit Group Name: REF +* Permission : RW +*******************************************************************************/ +#define LSM303AGR_ACC_REF_MASK 0xFF +#define LSM303AGR_ACC_REF_POSITION 0 +mems_status_t LSM303AGR_ACC_W_ReferenceVal(void *handle, u8_t newValue); +mems_status_t LSM303AGR_ACC_R_ReferenceVal(void *handle, u8_t *value); + +/******************************************************************************* +* Register : STATUS_REG2 +* Address : 0X27 +* Bit Group Name: XDA +* Permission : RO +*******************************************************************************/ +typedef enum { + LSM303AGR_ACC_XDA_NOT_AVAILABLE =0x00, + LSM303AGR_ACC_XDA_AVAILABLE =0x01, +} LSM303AGR_ACC_XDA_t; + +#define LSM303AGR_ACC_XDA_MASK 0x01 +mems_status_t LSM303AGR_ACC_R_XDataAvail(void *handle, LSM303AGR_ACC_XDA_t *value); + +/******************************************************************************* +* Register : STATUS_REG2 +* Address : 0X27 +* Bit Group Name: YDA +* Permission : RO +*******************************************************************************/ +typedef enum { + LSM303AGR_ACC_YDA_NOT_AVAILABLE =0x00, + LSM303AGR_ACC_YDA_AVAILABLE =0x02, +} LSM303AGR_ACC_YDA_t; + +#define LSM303AGR_ACC_YDA_MASK 0x02 +mems_status_t LSM303AGR_ACC_R_YDataAvail(void *handle, LSM303AGR_ACC_YDA_t *value); + +/******************************************************************************* +* Register : STATUS_REG2 +* Address : 0X27 +* Bit Group Name: ZDA +* Permission : RO +*******************************************************************************/ +typedef enum { + LSM303AGR_ACC_ZDA_NOT_AVAILABLE =0x00, + LSM303AGR_ACC_ZDA_AVAILABLE =0x04, +} LSM303AGR_ACC_ZDA_t; + +#define LSM303AGR_ACC_ZDA_MASK 0x04 +mems_status_t LSM303AGR_ACC_R_ZDataAvail(void *handle, LSM303AGR_ACC_ZDA_t *value); + +/******************************************************************************* +* Register : STATUS_REG2 +* Address : 0X27 +* Bit Group Name: ZYXDA +* Permission : RO +*******************************************************************************/ +typedef enum { + LSM303AGR_ACC_ZYXDA_NOT_AVAILABLE =0x00, + LSM303AGR_ACC_ZYXDA_AVAILABLE =0x08, +} LSM303AGR_ACC_ZYXDA_t; + +#define LSM303AGR_ACC_ZYXDA_MASK 0x08 +mems_status_t LSM303AGR_ACC_R_XYZDataAvail(void *handle, LSM303AGR_ACC_ZYXDA_t *value); + +/******************************************************************************* +* Register : STATUS_REG2 +* Address : 0X27 +* Bit Group Name: XOR +* Permission : RO +*******************************************************************************/ +typedef enum { + LSM303AGR_ACC_XOR_NO_OVERRUN =0x00, + LSM303AGR_ACC_XOR_OVERRUN =0x10, +} LSM303AGR_ACC_XOR_t; + +#define LSM303AGR_ACC_XOR_MASK 0x10 +mems_status_t LSM303AGR_ACC_R_XDataOverrun(void *handle, LSM303AGR_ACC_XOR_t *value); + +/******************************************************************************* +* Register : STATUS_REG2 +* Address : 0X27 +* Bit Group Name: YOR +* Permission : RO +*******************************************************************************/ +typedef enum { + LSM303AGR_ACC_YOR_NO_OVERRUN =0x00, + LSM303AGR_ACC_YOR_OVERRUN =0x20, +} LSM303AGR_ACC_YOR_t; + +#define LSM303AGR_ACC_YOR_MASK 0x20 +mems_status_t LSM303AGR_ACC_R_YDataOverrun(void *handle, LSM303AGR_ACC_YOR_t *value); + +/******************************************************************************* +* Register : STATUS_REG2 +* Address : 0X27 +* Bit Group Name: ZOR +* Permission : RO +*******************************************************************************/ +typedef enum { + LSM303AGR_ACC_ZOR_NO_OVERRUN =0x00, + LSM303AGR_ACC_ZOR_OVERRUN =0x40, +} LSM303AGR_ACC_ZOR_t; + +#define LSM303AGR_ACC_ZOR_MASK 0x40 +mems_status_t LSM303AGR_ACC_R_ZDataOverrun(void *handle, LSM303AGR_ACC_ZOR_t *value); + +/******************************************************************************* +* Register : STATUS_REG2 +* Address : 0X27 +* Bit Group Name: ZYXOR +* Permission : RO +*******************************************************************************/ +typedef enum { + LSM303AGR_ACC_ZYXOR_NO_OVERRUN =0x00, + LSM303AGR_ACC_ZYXOR_OVERRUN =0x80, +} LSM303AGR_ACC_ZYXOR_t; + +#define LSM303AGR_ACC_ZYXOR_MASK 0x80 +mems_status_t LSM303AGR_ACC_R_XYZDataOverrun(void *handle, LSM303AGR_ACC_ZYXOR_t *value); + +/******************************************************************************* +* Register : FIFO_CTRL_REG +* Address : 0X2E +* Bit Group Name: FTH +* Permission : RW +*******************************************************************************/ +#define LSM303AGR_ACC_FTH_MASK 0x1F +#define LSM303AGR_ACC_FTH_POSITION 0 +mems_status_t LSM303AGR_ACC_W_FifoThreshold(void *handle, u8_t newValue); +mems_status_t LSM303AGR_ACC_R_FifoThreshold(void *handle, u8_t *value); + +/******************************************************************************* +* Register : FIFO_CTRL_REG +* Address : 0X2E +* Bit Group Name: TR +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM303AGR_ACC_TR_TRIGGER_ON_INT1 =0x00, + LSM303AGR_ACC_TR_TRIGGER_ON_INT2 =0x20, +} LSM303AGR_ACC_TR_t; + +#define LSM303AGR_ACC_TR_MASK 0x20 +mems_status_t LSM303AGR_ACC_W_TriggerSel(void *handle, LSM303AGR_ACC_TR_t newValue); +mems_status_t LSM303AGR_ACC_R_TriggerSel(void *handle, LSM303AGR_ACC_TR_t *value); + +/******************************************************************************* +* Register : FIFO_CTRL_REG +* Address : 0X2E +* Bit Group Name: FM +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM303AGR_ACC_FM_BYPASS =0x00, + LSM303AGR_ACC_FM_FIFO =0x40, + LSM303AGR_ACC_FM_STREAM =0x80, + LSM303AGR_ACC_FM_TRIGGER =0xC0, +} LSM303AGR_ACC_FM_t; + +#define LSM303AGR_ACC_FM_MASK 0xC0 +mems_status_t LSM303AGR_ACC_W_FifoMode(void *handle, LSM303AGR_ACC_FM_t newValue); +mems_status_t LSM303AGR_ACC_R_FifoMode(void *handle, LSM303AGR_ACC_FM_t *value); + +/******************************************************************************* +* Register : FIFO_SRC_REG +* Address : 0X2F +* Bit Group Name: FSS +* Permission : RO +*******************************************************************************/ +#define LSM303AGR_ACC_FSS_MASK 0x1F +#define LSM303AGR_ACC_FSS_POSITION 0 +mems_status_t LSM303AGR_ACC_R_FifoSamplesAvail(void *handle, u8_t *value); + +/******************************************************************************* +* Register : FIFO_SRC_REG +* Address : 0X2F +* Bit Group Name: EMPTY +* Permission : RO +*******************************************************************************/ +typedef enum { + LSM303AGR_ACC_EMPTY_NOT_EMPTY =0x00, + LSM303AGR_ACC_EMPTY_EMPTY =0x20, +} LSM303AGR_ACC_EMPTY_t; + +#define LSM303AGR_ACC_EMPTY_MASK 0x20 +mems_status_t LSM303AGR_ACC_R_FifoEmpty(void *handle, LSM303AGR_ACC_EMPTY_t *value); + +/******************************************************************************* +* Register : FIFO_SRC_REG +* Address : 0X2F +* Bit Group Name: OVRN_FIFO +* Permission : RO +*******************************************************************************/ +typedef enum { + LSM303AGR_ACC_OVRN_FIFO_NO_OVERRUN =0x00, + LSM303AGR_ACC_OVRN_FIFO_OVERRUN =0x40, +} LSM303AGR_ACC_OVRN_FIFO_t; + +#define LSM303AGR_ACC_OVRN_FIFO_MASK 0x40 +mems_status_t LSM303AGR_ACC_R_FifoOverrun(void *handle, LSM303AGR_ACC_OVRN_FIFO_t *value); + +/******************************************************************************* +* Register : FIFO_SRC_REG +* Address : 0X2F +* Bit Group Name: WTM +* Permission : RO +*******************************************************************************/ +typedef enum { + LSM303AGR_ACC_WTM_NORMAL =0x00, + LSM303AGR_ACC_WTM_OVERFLOW =0x80, +} LSM303AGR_ACC_WTM_t; + +#define LSM303AGR_ACC_WTM_MASK 0x80 +mems_status_t LSM303AGR_ACC_R_WatermarkLevel(void *handle, LSM303AGR_ACC_WTM_t *value); + +/******************************************************************************* +* Register : INT1_CFG/INT2_CFG +* Address : 0X30/0x34 +* Bit Group Name: XLIE +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM303AGR_ACC_XLIE_DISABLED =0x00, + LSM303AGR_ACC_XLIE_ENABLED =0x01, +} LSM303AGR_ACC_XLIE_t; + +#define LSM303AGR_ACC_XLIE_MASK 0x01 +mems_status_t LSM303AGR_ACC_W_Int1EnXLo(void *handle, LSM303AGR_ACC_XLIE_t newValue); +mems_status_t LSM303AGR_ACC_R_Int1EnXLo(void *handle, LSM303AGR_ACC_XLIE_t *value); +mems_status_t LSM303AGR_ACC_W_Int2EnXLo(void *handle, LSM303AGR_ACC_XLIE_t newValue); +mems_status_t LSM303AGR_ACC_R_Int2EnXLo(void *handle, LSM303AGR_ACC_XLIE_t *value); + +/******************************************************************************* +* Register : INT1_CFG/INT2_CFG +* Address : 0X30/0x34 +* Bit Group Name: XHIE +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM303AGR_ACC_XHIE_DISABLED =0x00, + LSM303AGR_ACC_XHIE_ENABLED =0x02, +} LSM303AGR_ACC_XHIE_t; + +#define LSM303AGR_ACC_XHIE_MASK 0x02 +mems_status_t LSM303AGR_ACC_W_Int1EnXHi(void *handle, LSM303AGR_ACC_XHIE_t newValue); +mems_status_t LSM303AGR_ACC_R_Int1EnXHi(void *handle, LSM303AGR_ACC_XHIE_t *value); +mems_status_t LSM303AGR_ACC_W_Int2EnXHi(void *handle, LSM303AGR_ACC_XHIE_t newValue); +mems_status_t LSM303AGR_ACC_R_Int2EnXHi(void *handle, LSM303AGR_ACC_XHIE_t *value); + +/******************************************************************************* +* Register : INT1_CFG/INT2_CFG +* Address : 0X30/0x34 +* Bit Group Name: YLIE +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM303AGR_ACC_YLIE_DISABLED =0x00, + LSM303AGR_ACC_YLIE_ENABLED =0x04, +} LSM303AGR_ACC_YLIE_t; + +#define LSM303AGR_ACC_YLIE_MASK 0x04 +mems_status_t LSM303AGR_ACC_W_Int1EnYLo(void *handle, LSM303AGR_ACC_YLIE_t newValue); +mems_status_t LSM303AGR_ACC_R_Int1EnYLo(void *handle, LSM303AGR_ACC_YLIE_t *value); +mems_status_t LSM303AGR_ACC_W_Int2EnYLo(void *handle, LSM303AGR_ACC_YLIE_t newValue); +mems_status_t LSM303AGR_ACC_R_Int2EnYLo(void *handle, LSM303AGR_ACC_YLIE_t *value); + +/******************************************************************************* +* Register : INT1_CFG/INT2_CFG +* Address : 0X30/0x34 +* Bit Group Name: YHIE +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM303AGR_ACC_YHIE_DISABLED =0x00, + LSM303AGR_ACC_YHIE_ENABLED =0x08, +} LSM303AGR_ACC_YHIE_t; + +#define LSM303AGR_ACC_YHIE_MASK 0x08 +mems_status_t LSM303AGR_ACC_W_Int1EnYHi(void *handle, LSM303AGR_ACC_YHIE_t newValue); +mems_status_t LSM303AGR_ACC_R_Int1EnYHi(void *handle, LSM303AGR_ACC_YHIE_t *value); +mems_status_t LSM303AGR_ACC_W_Int2EnYHi(void *handle, LSM303AGR_ACC_YHIE_t newValue); +mems_status_t LSM303AGR_ACC_R_Int2EnYHi(void *handle, LSM303AGR_ACC_YHIE_t *value); + +/******************************************************************************* +* Register : INT1_CFG/INT2_CFG +* Address : 0X30/0x34 +* Bit Group Name: ZLIE +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM303AGR_ACC_ZLIE_DISABLED =0x00, + LSM303AGR_ACC_ZLIE_ENABLED =0x10, +} LSM303AGR_ACC_ZLIE_t; + +#define LSM303AGR_ACC_ZLIE_MASK 0x10 +mems_status_t LSM303AGR_ACC_W_Int1EnZLo(void *handle, LSM303AGR_ACC_ZLIE_t newValue); +mems_status_t LSM303AGR_ACC_R_Int1EnZLo(void *handle, LSM303AGR_ACC_ZLIE_t *value); +mems_status_t LSM303AGR_ACC_W_Int2EnZLo(void *handle, LSM303AGR_ACC_ZLIE_t newValue); +mems_status_t LSM303AGR_ACC_R_Int2EnZLo(void *handle, LSM303AGR_ACC_ZLIE_t *value); + +/******************************************************************************* +* Register : INT1_CFG/INT2_CFG +* Address : 0X30/0x34 +* Bit Group Name: ZHIE +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM303AGR_ACC_ZHIE_DISABLED =0x00, + LSM303AGR_ACC_ZHIE_ENABLED =0x20, +} LSM303AGR_ACC_ZHIE_t; + +#define LSM303AGR_ACC_ZHIE_MASK 0x20 +mems_status_t LSM303AGR_ACC_W_Int1EnZHi(void *handle, LSM303AGR_ACC_ZHIE_t newValue); +mems_status_t LSM303AGR_ACC_R_Int1EnZHi(void *handle, LSM303AGR_ACC_ZHIE_t *value); +mems_status_t LSM303AGR_ACC_W_Int2EnZHi(void *handle, LSM303AGR_ACC_ZHIE_t newValue); +mems_status_t LSM303AGR_ACC_R_Int2EnZHi(void *handle, LSM303AGR_ACC_ZHIE_t *value); + +/******************************************************************************* +* Register : INT1_CFG/INT2_CFG +* Address : 0X30/0x34 +* Bit Group Name: 6D +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM303AGR_ACC_6D_DISABLED =0x00, + LSM303AGR_ACC_6D_ENABLED =0x40, +} LSM303AGR_ACC_6D_t; + +#define LSM303AGR_ACC_6D_MASK 0x40 +mems_status_t LSM303AGR_ACC_W_Int1_6D(void *handle, LSM303AGR_ACC_6D_t newValue); +mems_status_t LSM303AGR_ACC_R_Int1_6D(void *handle, LSM303AGR_ACC_6D_t *value); +mems_status_t LSM303AGR_ACC_W_Int2_6D(void *handle, LSM303AGR_ACC_6D_t newValue); +mems_status_t LSM303AGR_ACC_R_Int2_6D(void *handle, LSM303AGR_ACC_6D_t *value); + +/******************************************************************************* +* Register : INT1_CFG/INT2_CFG +* Address : 0X30/0x34 +* Bit Group Name: AOI +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM303AGR_ACC_AOI_OR =0x00, + LSM303AGR_ACC_AOI_AND =0x80, +} LSM303AGR_ACC_AOI_t; + +#define LSM303AGR_ACC_AOI_MASK 0x80 +mems_status_t LSM303AGR_ACC_W_Int1_AOI(void *handle, LSM303AGR_ACC_AOI_t newValue); +mems_status_t LSM303AGR_ACC_R_Int1_AOI(void *handle, LSM303AGR_ACC_AOI_t *value); +mems_status_t LSM303AGR_ACC_W_Int2_AOI(void *handle, LSM303AGR_ACC_AOI_t newValue); +mems_status_t LSM303AGR_ACC_R_Int2_AOI(void *handle, LSM303AGR_ACC_AOI_t *value); + +/******************************************************************************* +* Register : INT1_SOURCE/INT2_SOURCE +* Address : 0X31/0x35 +* Bit Group Name: XL +* Permission : RO +*******************************************************************************/ +typedef enum { + LSM303AGR_ACC_XL_DOWN =0x00, + LSM303AGR_ACC_XL_UP =0x01, +} LSM303AGR_ACC_XL_t; + +#define LSM303AGR_ACC_XL_MASK 0x01 +mems_status_t LSM303AGR_ACC_R_Int1_Xlo(void *handle, LSM303AGR_ACC_XL_t *value); +mems_status_t LSM303AGR_ACC_R_Int2_Xlo(void *handle, LSM303AGR_ACC_XL_t *value); + +/******************************************************************************* +* Register : INT1_SOURCE/INT2_SOURCE +* Address : 0X31/0x35 +* Bit Group Name: XH +* Permission : RO +*******************************************************************************/ +typedef enum { + LSM303AGR_ACC_XH_DOWN =0x00, + LSM303AGR_ACC_XH_UP =0x02, +} LSM303AGR_ACC_XH_t; + +#define LSM303AGR_ACC_XH_MASK 0x02 +mems_status_t LSM303AGR_ACC_R_Int1_XHi(void *handle, LSM303AGR_ACC_XH_t *value); +mems_status_t LSM303AGR_ACC_R_Int2_XHi(void *handle, LSM303AGR_ACC_XH_t *value); + +/******************************************************************************* +* Register : INT1_SOURCE/INT2_SOURCE +* Address : 0X31/0x35 +* Bit Group Name: YL +* Permission : RO +*******************************************************************************/ +typedef enum { + LSM303AGR_ACC_YL_DOWN =0x00, + LSM303AGR_ACC_YL_UP =0x04, +} LSM303AGR_ACC_YL_t; + +#define LSM303AGR_ACC_YL_MASK 0x04 +mems_status_t LSM303AGR_ACC_R_Int1_YLo(void *handle, LSM303AGR_ACC_YL_t *value); +mems_status_t LSM303AGR_ACC_R_Int2_YLo(void *handle, LSM303AGR_ACC_YL_t *value); + +/******************************************************************************* +* Register : INT1_SOURCE/INT2_SOURCE +* Address : 0X31/0x35 +* Bit Group Name: YH +* Permission : RO +*******************************************************************************/ +typedef enum { + LSM303AGR_ACC_YH_DOWN =0x00, + LSM303AGR_ACC_YH_UP =0x08, +} LSM303AGR_ACC_YH_t; + +#define LSM303AGR_ACC_YH_MASK 0x08 +mems_status_t LSM303AGR_ACC_R_Int1_YHi(void *handle, LSM303AGR_ACC_YH_t *value); +mems_status_t LSM303AGR_ACC_R_Int2_YHi(void *handle, LSM303AGR_ACC_YH_t *value); + +/******************************************************************************* +* Register : INT1_SOURCE/INT2_SOURCE +* Address : 0X31/0x35 +* Bit Group Name: ZL +* Permission : RO +*******************************************************************************/ +typedef enum { + LSM303AGR_ACC_ZL_DOWN =0x00, + LSM303AGR_ACC_ZL_UP =0x10, +} LSM303AGR_ACC_ZL_t; + +#define LSM303AGR_ACC_ZL_MASK 0x10 +mems_status_t LSM303AGR_ACC_R_Int1_Zlo(void *handle, LSM303AGR_ACC_ZL_t *value); +mems_status_t LSM303AGR_ACC_R_Int2_Zlo(void *handle, LSM303AGR_ACC_ZL_t *value); + +/******************************************************************************* +* Register : INT1_SOURCE/INT2_SOURCE +* Address : 0X31/0x35 +* Bit Group Name: ZH +* Permission : RO +*******************************************************************************/ +typedef enum { + LSM303AGR_ACC_ZH_DOWN =0x00, + LSM303AGR_ACC_ZH_UP =0x20, +} LSM303AGR_ACC_ZH_t; + +#define LSM303AGR_ACC_ZH_MASK 0x20 +mems_status_t LSM303AGR_ACC_R_Int1_ZHi(void *handle, LSM303AGR_ACC_ZH_t *value); +mems_status_t LSM303AGR_ACC_R_Int2_ZHi(void *handle, LSM303AGR_ACC_ZH_t *value); + +/******************************************************************************* +* Register : INT1_SOURCE/INT2_SOURCE +* Address : 0X31/0x35 +* Bit Group Name: IA +* Permission : RO +*******************************************************************************/ +typedef enum { + LSM303AGR_ACC_IA_DOWN =0x00, + LSM303AGR_ACC_IA_UP =0x40, +} LSM303AGR_ACC_IA_t; + +#define LSM303AGR_ACC_IA_MASK 0x40 +mems_status_t LSM303AGR_ACC_R_Int1_IA(void *handle, LSM303AGR_ACC_IA_t *value); +mems_status_t LSM303AGR_ACC_R_Int2_IA(void *handle, LSM303AGR_ACC_IA_t *value); + +/******************************************************************************* +* Register : INT1_THS/INT2_THS +* Address : 0X32/0x36 +* Bit Group Name: THS +* Permission : RW +*******************************************************************************/ +#define LSM303AGR_ACC_THS_MASK 0x7F +#define LSM303AGR_ACC_THS_POSITION 0 +mems_status_t LSM303AGR_ACC_W_Int1_Threshold(void *handle, u8_t newValue); +mems_status_t LSM303AGR_ACC_R_Int1_Threshold(void *handle, u8_t *value); +mems_status_t LSM303AGR_ACC_W_Int2_Threshold(void *handle, u8_t newValue); +mems_status_t LSM303AGR_ACC_R_Int2_Threshold(void *handle, u8_t *value); + +/******************************************************************************* +* Register : INT1_DURATION/INT2_DURATION +* Address : 0X33/0x37 +* Bit Group Name: D +* Permission : RW +*******************************************************************************/ +#define LSM303AGR_ACC_D_MASK 0x7F +#define LSM303AGR_ACC_D_POSITION 0 +mems_status_t LSM303AGR_ACC_W_Int1_Duration(void *handle, u8_t newValue); +mems_status_t LSM303AGR_ACC_R_Int1_Duration(void *handle, u8_t *value); +mems_status_t LSM303AGR_ACC_W_Int2_Duration(void *handle, u8_t newValue); +mems_status_t LSM303AGR_ACC_R_Int2_Duration(void *handle, u8_t *value); + +/******************************************************************************* +* Register : CLICK_CFG +* Address : 0X38 +* Bit Group Name: XS +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM303AGR_ACC_XS_DISABLED =0x00, + LSM303AGR_ACC_XS_ENABLED =0x01, +} LSM303AGR_ACC_XS_t; + +#define LSM303AGR_ACC_XS_MASK 0x01 +mems_status_t LSM303AGR_ACC_W_XSingle(void *handle, LSM303AGR_ACC_XS_t newValue); +mems_status_t LSM303AGR_ACC_R_XSingle(void *handle, LSM303AGR_ACC_XS_t *value); + +/******************************************************************************* +* Register : CLICK_CFG +* Address : 0X38 +* Bit Group Name: XD +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM303AGR_ACC_XD_DISABLED =0x00, + LSM303AGR_ACC_XD_ENABLED =0x02, +} LSM303AGR_ACC_XD_t; + +#define LSM303AGR_ACC_XD_MASK 0x02 +mems_status_t LSM303AGR_ACC_W_XDouble(void *handle, LSM303AGR_ACC_XD_t newValue); +mems_status_t LSM303AGR_ACC_R_XDouble(void *handle, LSM303AGR_ACC_XD_t *value); + +/******************************************************************************* +* Register : CLICK_CFG +* Address : 0X38 +* Bit Group Name: YS +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM303AGR_ACC_YS_DISABLED =0x00, + LSM303AGR_ACC_YS_ENABLED =0x04, +} LSM303AGR_ACC_YS_t; + +#define LSM303AGR_ACC_YS_MASK 0x04 +mems_status_t LSM303AGR_ACC_W_YSingle(void *handle, LSM303AGR_ACC_YS_t newValue); +mems_status_t LSM303AGR_ACC_R_YSingle(void *handle, LSM303AGR_ACC_YS_t *value); + +/******************************************************************************* +* Register : CLICK_CFG +* Address : 0X38 +* Bit Group Name: YD +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM303AGR_ACC_YD_DISABLED =0x00, + LSM303AGR_ACC_YD_ENABLED =0x08, +} LSM303AGR_ACC_YD_t; + +#define LSM303AGR_ACC_YD_MASK 0x08 +mems_status_t LSM303AGR_ACC_W_YDouble(void *handle, LSM303AGR_ACC_YD_t newValue); +mems_status_t LSM303AGR_ACC_R_YDouble(void *handle, LSM303AGR_ACC_YD_t *value); + +/******************************************************************************* +* Register : CLICK_CFG +* Address : 0X38 +* Bit Group Name: ZS +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM303AGR_ACC_ZS_DISABLED =0x00, + LSM303AGR_ACC_ZS_ENABLED =0x10, +} LSM303AGR_ACC_ZS_t; + +#define LSM303AGR_ACC_ZS_MASK 0x10 +mems_status_t LSM303AGR_ACC_W_ZSingle(void *handle, LSM303AGR_ACC_ZS_t newValue); +mems_status_t LSM303AGR_ACC_R_ZSingle(void *handle, LSM303AGR_ACC_ZS_t *value); + +/******************************************************************************* +* Register : CLICK_CFG +* Address : 0X38 +* Bit Group Name: ZD +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM303AGR_ACC_ZD_DISABLED =0x00, + LSM303AGR_ACC_ZD_ENABLED =0x20, +} LSM303AGR_ACC_ZD_t; + +#define LSM303AGR_ACC_ZD_MASK 0x20 +mems_status_t LSM303AGR_ACC_W_ZDouble(void *handle, LSM303AGR_ACC_ZD_t newValue); +mems_status_t LSM303AGR_ACC_R_ZDouble(void *handle, LSM303AGR_ACC_ZD_t *value); + +/******************************************************************************* +* Register : CLICK_SRC +* Address : 0X39 +* Bit Group Name: X +* Permission : RO +*******************************************************************************/ +typedef enum { + LSM303AGR_ACC_X_DOWN =0x00, + LSM303AGR_ACC_X_UP =0x01, +} LSM303AGR_ACC_X_t; + +#define LSM303AGR_ACC_X_MASK 0x01 +mems_status_t LSM303AGR_ACC_R_ClickX(void *handle, LSM303AGR_ACC_X_t *value); + +/******************************************************************************* +* Register : CLICK_SRC +* Address : 0X39 +* Bit Group Name: Y +* Permission : RO +*******************************************************************************/ +typedef enum { + LSM303AGR_ACC_Y_DOWN =0x00, + LSM303AGR_ACC_Y_UP =0x02, +} LSM303AGR_ACC_Y_t; + +#define LSM303AGR_ACC_Y_MASK 0x02 +mems_status_t LSM303AGR_ACC_R_ClickY(void *handle, LSM303AGR_ACC_Y_t *value); + +/******************************************************************************* +* Register : CLICK_SRC +* Address : 0X39 +* Bit Group Name: Z +* Permission : RO +*******************************************************************************/ +typedef enum { + LSM303AGR_ACC_Z_DOWN =0x00, + LSM303AGR_ACC_Z_UP =0x04, +} LSM303AGR_ACC_Z_t; + +#define LSM303AGR_ACC_Z_MASK 0x04 +mems_status_t LSM303AGR_ACC_R_ClickZ(void *handle, LSM303AGR_ACC_Z_t *value); + +/******************************************************************************* +* Register : CLICK_SRC +* Address : 0X39 +* Bit Group Name: SIGN +* Permission : RO +*******************************************************************************/ +typedef enum { + LSM303AGR_ACC_SIGN_POSITIVE =0x00, + LSM303AGR_ACC_SIGN_NEGATIVE =0x08, +} LSM303AGR_ACC_SIGN_t; + +#define LSM303AGR_ACC_SIGN_MASK 0x08 +mems_status_t LSM303AGR_ACC_R_ClickSign(void *handle, LSM303AGR_ACC_SIGN_t *value); + +/******************************************************************************* +* Register : CLICK_SRC +* Address : 0X39 +* Bit Group Name: SCLICK +* Permission : RO +*******************************************************************************/ +typedef enum { + LSM303AGR_ACC_SCLICK_DISABLED =0x00, + LSM303AGR_ACC_SCLICK_ENABLED =0x10, +} LSM303AGR_ACC_SCLICK_t; + +#define LSM303AGR_ACC_SCLICK_MASK 0x10 +mems_status_t LSM303AGR_ACC_R_SingleCLICK(void *handle, LSM303AGR_ACC_SCLICK_t *value); + +/******************************************************************************* +* Register : CLICK_SRC +* Address : 0X39 +* Bit Group Name: DCLICK +* Permission : RO +*******************************************************************************/ +typedef enum { + LSM303AGR_ACC_DCLICK_DISABLED =0x00, + LSM303AGR_ACC_DCLICK_ENABLED =0x20, +} LSM303AGR_ACC_DCLICK_t; + +#define LSM303AGR_ACC_DCLICK_MASK 0x20 +mems_status_t LSM303AGR_ACC_R_DoubleCLICK(void *handle, LSM303AGR_ACC_DCLICK_t *value); + +/******************************************************************************* +* Register : CLICK_SRC +* Address : 0X39 +* Bit Group Name: IA +* Permission : RO +*******************************************************************************/ +typedef enum { + LSM303AGR_ACC_CLICK_IA_DOWN =0x00, + LSM303AGR_ACC_CLICK_IA_UP =0x40, +} LSM303AGR_ACC_CLICK_IA_t; + +#define LSM303AGR_ACC_IA_MASK 0x40 +mems_status_t LSM303AGR_ACC_R_CLICK_IA(void *handle, LSM303AGR_ACC_CLICK_IA_t *value); + +/******************************************************************************* +* Register : CLICK_THS +* Address : 0X3A +* Bit Group Name: THS +* Permission : RW +*******************************************************************************/ +#define LSM303AGR_ACC_THS_MASK 0x7F +#define LSM303AGR_ACC_THS_POSITION 0 +mems_status_t LSM303AGR_ACC_W_ClickThreshold(void *handle, u8_t newValue); +mems_status_t LSM303AGR_ACC_R_ClickThreshold(void *handle, u8_t *value); + +/******************************************************************************* +* Register : TIME_LIMIT +* Address : 0X3B +* Bit Group Name: TLI +* Permission : RW +*******************************************************************************/ +#define LSM303AGR_ACC_TLI_MASK 0x7F +#define LSM303AGR_ACC_TLI_POSITION 0 +mems_status_t LSM303AGR_ACC_W_ClickTimeLimit(void *handle, u8_t newValue); +mems_status_t LSM303AGR_ACC_R_ClickTimeLimit(void *handle, u8_t *value); + +/******************************************************************************* +* Register : TIME_LATENCY +* Address : 0X3C +* Bit Group Name: TLA +* Permission : RW +*******************************************************************************/ +#define LSM303AGR_ACC_TLA_MASK 0xFF +#define LSM303AGR_ACC_TLA_POSITION 0 +mems_status_t LSM303AGR_ACC_W_ClickTimeLatency(void *handle, u8_t newValue); +mems_status_t LSM303AGR_ACC_R_ClickTimeLatency(void *handle, u8_t *value); + +/******************************************************************************* +* Register : TIME_WINDOW +* Address : 0X3D +* Bit Group Name: TW +* Permission : RW +*******************************************************************************/ +#define LSM303AGR_ACC_TW_MASK 0xFF +#define LSM303AGR_ACC_TW_POSITION 0 +mems_status_t LSM303AGR_ACC_W_ClickTimeWindow(void *handle, u8_t newValue); +mems_status_t LSM303AGR_ACC_R_ClickTimeWindow(void *handle, u8_t *value); +/******************************************************************************* +* Register : <REGISTER_L> - <REGISTER_H> +* Output Type : Voltage_ADC +* Permission : RO +*******************************************************************************/ +mems_status_t LSM303AGR_ACC_Get_Voltage_ADC(void *handle, u8_t *buff); +/******************************************************************************* +* Register : <REGISTER_L> - <REGISTER_H> +* Output Type : Acceleration +* Permission : RO +*******************************************************************************/ +mems_status_t LSM303AGR_ACC_Get_Raw_Acceleration(void *handle, u8_t *buff); +mems_status_t LSM303AGR_ACC_Get_Acceleration(void *handle, int *buff); + +#ifdef __cplusplus +} +#endif + +#endif
diff -r 000000000000 -r 98c301bb7d1b Components/LSM303AGRSensor/LSM303AGR_mag_driver.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Components/LSM303AGRSensor/LSM303AGR_mag_driver.c Tue Oct 03 12:21:11 2017 +0000 @@ -0,0 +1,1639 @@ +/** + ******************************************************************************* + * @file LSM303AGR_mag_driver.c + * @author MEMS Application Team + * @version V1.1 + * @date 25-February-2016 + * @brief LSM303AGR Magnetometer driver file + ******************************************************************************* + * @attention + * + * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of STMicroelectronics nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************** + */ + +/* Includes ------------------------------------------------------------------*/ +#include "LSM303AGR_mag_driver.h" + +/* Imported function prototypes ----------------------------------------------*/ +extern uint8_t LSM303AGR_MAG_io_write(void *handle, uint8_t WriteAddr, uint8_t *pBuffer, uint16_t nBytesToWrite); +extern uint8_t LSM303AGR_MAG_io_read(void *handle, uint8_t ReadAddr, uint8_t *pBuffer, uint16_t nBytesToRead); + +/* Private typedef -----------------------------------------------------------*/ + +/* Private define ------------------------------------------------------------*/ + +/* Private macro -------------------------------------------------------------*/ + +/* Private variables ---------------------------------------------------------*/ + +/* Private functions ---------------------------------------------------------*/ + +/******************************************************************************* +* Function Name : LSM303AGR_MAG_read_reg +* Description : Generic Reading function. It must be fullfilled with either +* : I2C or SPI reading functions +* Input : Register Address +* Output : Data REad +* Return : None +*******************************************************************************/ +mems_status_t LSM303AGR_MAG_read_reg( void *handle, u8_t Reg, u8_t* Data ) +{ + + if (LSM303AGR_MAG_io_read(handle, Reg, Data, 1)) + { + return MEMS_ERROR; + } + else + { + return MEMS_SUCCESS; + } +} + +/******************************************************************************* +* Function Name : LSM303AGR_MAG_write_reg +* Description : Generic Writing function. It must be fullfilled with either +* : I2C or SPI writing function +* Input : Register Address, Data to be written +* Output : None +* Return : None +*******************************************************************************/ +mems_status_t LSM303AGR_MAG_write_reg( void *handle, u8_t Reg, u8_t Data ) +{ + + if (LSM303AGR_MAG_io_write(handle, Reg, &Data, 1)) + { + return MEMS_ERROR; + } + else + { + return MEMS_SUCCESS; + } +} + +/******************************************************************************* +* Function Name : SwapHighLowByte +* Description : Swap High/low byte in multiple byte values +* It works with minimum 2 byte for every dimension. +* Example x,y,z with 2 byte for every dimension +* +* Input : bufferToSwap -> buffer to swap +* numberOfByte -> the buffer length in byte +* dimension -> number of dimension +* +* Output : bufferToSwap -> buffer swapped +* Return : None +*******************************************************************************/ +void LSM303AGR_MAG_SwapHighLowByte(u8_t *bufferToSwap, u8_t numberOfByte, u8_t dimension) +{ + + u8_t numberOfByteForDimension, i, j; + u8_t tempValue[10]; + + numberOfByteForDimension=numberOfByte/dimension; + + for (i=0; i<dimension;i++ ) + { + for (j=0; j<numberOfByteForDimension;j++ ) + tempValue[j]=bufferToSwap[j+i*numberOfByteForDimension]; + for (j=0; j<numberOfByteForDimension;j++ ) + *(bufferToSwap+i*(numberOfByteForDimension)+j)=*(tempValue+(numberOfByteForDimension-1)-j); + } +} + +/* Exported functions ---------------------------------------------------------*/ + +/******************************************************************************* +* Function Name : LSM303AGR_MAG_W_OFF_X_L +* Description : Write OFF_X_L +* Input : u8_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_MAG_W_OFF_X_L(void *handle, u8_t newValue) +{ + u8_t value; + + newValue = newValue << LSM303AGR_MAG_OFF_X_L_POSITION; //mask + newValue &= LSM303AGR_MAG_OFF_X_L_MASK; //coerce + + if( !LSM303AGR_MAG_read_reg(handle, LSM303AGR_MAG_OFFSET_X_REG_L, &value) ) + return MEMS_ERROR; + + value &= (u8_t)~LSM303AGR_MAG_OFF_X_L_MASK; + value |= newValue; + + if( !LSM303AGR_MAG_write_reg(handle, LSM303AGR_MAG_OFFSET_X_REG_L, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_MAG_R_OFF_X_L +* Description : Read OFF_X_L +* Input : Pointer to u8_t +* Output : Status of OFF_X_L +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_MAG_R_OFF_X_L(void *handle, u8_t *value) +{ + if( !LSM303AGR_MAG_read_reg(handle, LSM303AGR_MAG_OFFSET_X_REG_L, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_MAG_OFF_X_L_MASK; //coerce + *value = *value >> LSM303AGR_MAG_OFF_X_L_POSITION; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_MAG_W_OFF_X_H +* Description : Write OFF_X_H +* Input : u8_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_MAG_W_OFF_X_H(void *handle, u8_t newValue) +{ + u8_t value; + + newValue = newValue << LSM303AGR_MAG_OFF_X_H_POSITION; //mask + newValue &= LSM303AGR_MAG_OFF_X_H_MASK; //coerce + + if( !LSM303AGR_MAG_read_reg(handle, LSM303AGR_MAG_OFFSET_X_REG_H, &value) ) + return MEMS_ERROR; + + value &= (u8_t)~LSM303AGR_MAG_OFF_X_H_MASK; + value |= newValue; + + if( !LSM303AGR_MAG_write_reg(handle, LSM303AGR_MAG_OFFSET_X_REG_H, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_MAG_R_OFF_X_H +* Description : Read OFF_X_H +* Input : Pointer to u8_t +* Output : Status of OFF_X_H +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_MAG_R_OFF_X_H(void *handle, u8_t *value) +{ + if( !LSM303AGR_MAG_read_reg(handle, LSM303AGR_MAG_OFFSET_X_REG_H, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_MAG_OFF_X_H_MASK; //coerce + *value = *value >> LSM303AGR_MAG_OFF_X_H_POSITION; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_MAG_W_OFF_Y_L +* Description : Write OFF_Y_L +* Input : u8_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_MAG_W_OFF_Y_L(void *handle, u8_t newValue) +{ + u8_t value; + + newValue = newValue << LSM303AGR_MAG_OFF_Y_L_POSITION; //mask + newValue &= LSM303AGR_MAG_OFF_Y_L_MASK; //coerce + + if( !LSM303AGR_MAG_read_reg(handle, LSM303AGR_MAG_OFFSET_Y_REG_L, &value) ) + return MEMS_ERROR; + + value &= (u8_t)~LSM303AGR_MAG_OFF_Y_L_MASK; + value |= newValue; + + if( !LSM303AGR_MAG_write_reg(handle, LSM303AGR_MAG_OFFSET_Y_REG_L, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_MAG_R_OFF_Y_L +* Description : Read OFF_Y_L +* Input : Pointer to u8_t +* Output : Status of OFF_Y_L +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_MAG_R_OFF_Y_L(void *handle, u8_t *value) +{ + if( !LSM303AGR_MAG_read_reg(handle, LSM303AGR_MAG_OFFSET_Y_REG_L, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_MAG_OFF_Y_L_MASK; //coerce + *value = *value >> LSM303AGR_MAG_OFF_Y_L_POSITION; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_MAG_W_OFF_Y_H +* Description : Write OFF_Y_H +* Input : u8_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_MAG_W_OFF_Y_H(void *handle, u8_t newValue) +{ + u8_t value; + + newValue = newValue << LSM303AGR_MAG_OFF_Y_H_POSITION; //mask + newValue &= LSM303AGR_MAG_OFF_Y_H_MASK; //coerce + + if( !LSM303AGR_MAG_read_reg(handle, LSM303AGR_MAG_OFFSET_Y_REG_H, &value) ) + return MEMS_ERROR; + + value &= (u8_t)~LSM303AGR_MAG_OFF_Y_H_MASK; + value |= newValue; + + if( !LSM303AGR_MAG_write_reg(handle, LSM303AGR_MAG_OFFSET_Y_REG_H, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_MAG_R_OFF_Y_H +* Description : Read OFF_Y_H +* Input : Pointer to u8_t +* Output : Status of OFF_Y_H +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_MAG_R_OFF_Y_H(void *handle, u8_t *value) +{ + if( !LSM303AGR_MAG_read_reg(handle, LSM303AGR_MAG_OFFSET_Y_REG_H, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_MAG_OFF_Y_H_MASK; //coerce + *value = *value >> LSM303AGR_MAG_OFF_Y_H_POSITION; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_MAG_W_OFF_Z_L +* Description : Write OFF_Z_L +* Input : u8_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_MAG_W_OFF_Z_L(void *handle, u8_t newValue) +{ + u8_t value; + + newValue = newValue << LSM303AGR_MAG_OFF_Z_L_POSITION; //mask + newValue &= LSM303AGR_MAG_OFF_Z_L_MASK; //coerce + + if( !LSM303AGR_MAG_read_reg(handle, LSM303AGR_MAG_OFFSET_Z_REG_L, &value) ) + return MEMS_ERROR; + + value &= (u8_t)~LSM303AGR_MAG_OFF_Z_L_MASK; + value |= newValue; + + if( !LSM303AGR_MAG_write_reg(handle, LSM303AGR_MAG_OFFSET_Z_REG_L, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_MAG_R_OFF_Z_L +* Description : Read OFF_Z_L +* Input : Pointer to u8_t +* Output : Status of OFF_Z_L +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_MAG_R_OFF_Z_L(void *handle, u8_t *value) +{ + if( !LSM303AGR_MAG_read_reg(handle, LSM303AGR_MAG_OFFSET_Z_REG_L, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_MAG_OFF_Z_L_MASK; //coerce + *value = *value >> LSM303AGR_MAG_OFF_Z_L_POSITION; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_MAG_W_OFF_Z_H +* Description : Write OFF_Z_H +* Input : u8_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_MAG_W_OFF_Z_H(void *handle, u8_t newValue) +{ + u8_t value; + + newValue = newValue << LSM303AGR_MAG_OFF_Z_H_POSITION; //mask + newValue &= LSM303AGR_MAG_OFF_Z_H_MASK; //coerce + + if( !LSM303AGR_MAG_read_reg(handle, LSM303AGR_MAG_OFFSET_Z_REG_H, &value) ) + return MEMS_ERROR; + + value &= (u8_t)~LSM303AGR_MAG_OFF_Z_H_MASK; + value |= newValue; + + if( !LSM303AGR_MAG_write_reg(handle, LSM303AGR_MAG_OFFSET_Z_REG_H, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* + * Set/Get the Magnetic offsets +*******************************************************************************/ +mems_status_t LSM303AGR_MAG_Get_MagOff(void *handle, u16_t *magx_off, u16_t *magy_off, u16_t *magz_off) +{ + u8_t reg_l, reg_h; + + /* read mag_x_off */ + //LSM303AGR_MAG_R_OFF_X_L(®_l); + //LSM303AGR_MAG_R_OFF_X_H(®_h); + LSM303AGR_MAG_R_OFF_X_L(handle, ®_l); + LSM303AGR_MAG_R_OFF_X_H(handle, ®_h); + *magx_off = ((reg_h << 8) & 0xff00) | reg_l; + + /* read mag_y_off */ + //LSM303AGR_MAG_R_OFF_Y_L(®_l); + //LSM303AGR_MAG_R_OFF_Y_H(®_h); + LSM303AGR_MAG_R_OFF_Y_L(handle, ®_l); + LSM303AGR_MAG_R_OFF_Y_H(handle, ®_h); + *magy_off = ((reg_h << 8) & 0xff00) | reg_l; + + /* read mag_z_off */ + //LSM303AGR_MAG_R_OFF_Z_L(®_l); + //LSM303AGR_MAG_R_OFF_Z_H(®_h); + LSM303AGR_MAG_R_OFF_Z_L(handle, ®_l); + LSM303AGR_MAG_R_OFF_Z_H(handle, ®_h); + *magz_off = ((reg_h << 8) & 0xff00) | reg_l; + + return MEMS_SUCCESS; +} + +mems_status_t LSM303AGR_MAG_Set_MagOff(void *handle, u16_t magx_off, u16_t magy_off, u16_t magz_off) +{ + /* write mag_x_off */ + //LSM303AGR_MAG_W_OFF_X_L(magx_off & 0xff); + //LSM303AGR_MAG_W_OFF_X_H((magx_off >> 8) & 0xff); + LSM303AGR_MAG_W_OFF_X_L(handle, magx_off & 0xff); + LSM303AGR_MAG_W_OFF_X_H(handle, (magx_off >> 8) & 0xff); + + /* write mag_y_off */ + //LSM303AGR_MAG_W_OFF_Y_L(magy_off & 0xff); + //LSM303AGR_MAG_W_OFF_Y_H((magy_off >> 8) & 0xff); + LSM303AGR_MAG_W_OFF_Y_L(handle, magy_off & 0xff); + LSM303AGR_MAG_W_OFF_Y_H(handle, (magy_off >> 8) & 0xff); + + /* write mag_z_off */ + //LSM303AGR_MAG_W_OFF_Z_L(magz_off & 0xff); + //LSM303AGR_MAG_W_OFF_Z_H((magz_off >> 8) & 0xff); + LSM303AGR_MAG_W_OFF_Z_L(handle, magz_off & 0xff); + LSM303AGR_MAG_W_OFF_Z_H(handle, (magz_off >> 8) & 0xff); + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_MAG_R_OFF_Z_H +* Description : Read OFF_Z_H +* Input : Pointer to u8_t +* Output : Status of OFF_Z_H +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_MAG_R_OFF_Z_H(void *handle, u8_t *value) +{ + if( !LSM303AGR_MAG_read_reg(handle, LSM303AGR_MAG_OFFSET_Z_REG_H, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_MAG_OFF_Z_H_MASK; //coerce + *value = *value >> LSM303AGR_MAG_OFF_Z_H_POSITION; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_MAG_R_WHO_AM_I +* Description : Read WHO_AM_I +* Input : Pointer to u8_t +* Output : Status of WHO_AM_I +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_MAG_R_WHO_AM_I(void *handle, u8_t *value) +{ + if( !LSM303AGR_MAG_read_reg(handle, LSM303AGR_MAG_WHO_AM_I_REG, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_MAG_WHO_AM_I_MASK; //coerce + *value = *value >> LSM303AGR_MAG_WHO_AM_I_POSITION; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_MAG_W_MD +* Description : Write MD +* Input : LSM303AGR_MAG_MD_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_MAG_W_MD(void *handle, LSM303AGR_MAG_MD_t newValue) +{ + u8_t value; + + if( !LSM303AGR_MAG_read_reg(handle, LSM303AGR_MAG_CFG_REG_A, &value) ) + return MEMS_ERROR; + + value &= ~LSM303AGR_MAG_MD_MASK; + value |= newValue; + + if( !LSM303AGR_MAG_write_reg(handle, LSM303AGR_MAG_CFG_REG_A, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_MAG_R_MD +* Description : Read MD +* Input : Pointer to LSM303AGR_MAG_MD_t +* Output : Status of MD see LSM303AGR_MAG_MD_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_MAG_R_MD(void *handle, LSM303AGR_MAG_MD_t *value) +{ + if( !LSM303AGR_MAG_read_reg(handle, LSM303AGR_MAG_CFG_REG_A, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_MAG_MD_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_MAG_W_ODR +* Description : Write ODR +* Input : LSM303AGR_MAG_ODR_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_MAG_W_ODR(void *handle, LSM303AGR_MAG_ODR_t newValue) +{ + u8_t value; + + if( !LSM303AGR_MAG_read_reg(handle, LSM303AGR_MAG_CFG_REG_A, &value) ) + return MEMS_ERROR; + + value &= ~LSM303AGR_MAG_ODR_MASK; + value |= newValue; + + if( !LSM303AGR_MAG_write_reg(handle, LSM303AGR_MAG_CFG_REG_A, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_MAG_R_ODR +* Description : Read ODR +* Input : Pointer to LSM303AGR_MAG_ODR_t +* Output : Status of ODR see LSM303AGR_MAG_ODR_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_MAG_R_ODR(void *handle, LSM303AGR_MAG_ODR_t *value) +{ + if( !LSM303AGR_MAG_read_reg(handle, LSM303AGR_MAG_CFG_REG_A, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_MAG_ODR_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_MAG_W_LP +* Description : Write LP +* Input : LSM303AGR_MAG_LP_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_MAG_W_LP(void *handle, LSM303AGR_MAG_LP_t newValue) +{ + u8_t value; + + if( !LSM303AGR_MAG_read_reg(handle, LSM303AGR_MAG_CFG_REG_A, &value) ) + return MEMS_ERROR; + + value &= ~LSM303AGR_MAG_LP_MASK; + value |= newValue; + + if( !LSM303AGR_MAG_write_reg(handle, LSM303AGR_MAG_CFG_REG_A, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_MAG_R_LP +* Description : Read LP +* Input : Pointer to LSM303AGR_MAG_LP_t +* Output : Status of LP see LSM303AGR_MAG_LP_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_MAG_R_LP(void *handle, LSM303AGR_MAG_LP_t *value) +{ + if( !LSM303AGR_MAG_read_reg(handle, LSM303AGR_MAG_CFG_REG_A, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_MAG_LP_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_MAG_W_SOFT_RST +* Description : Write SOFT_RST +* Input : LSM303AGR_MAG_SOFT_RST_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_MAG_W_SOFT_RST(void *handle, LSM303AGR_MAG_SOFT_RST_t newValue) +{ + u8_t value; + + if( !LSM303AGR_MAG_read_reg(handle, LSM303AGR_MAG_CFG_REG_A, &value) ) + return MEMS_ERROR; + + value &= ~LSM303AGR_MAG_SOFT_RST_MASK; + value |= newValue; + + if( !LSM303AGR_MAG_write_reg(handle, LSM303AGR_MAG_CFG_REG_A, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_MAG_R_SOFT_RST +* Description : Read SOFT_RST +* Input : Pointer to LSM303AGR_MAG_SOFT_RST_t +* Output : Status of SOFT_RST see LSM303AGR_MAG_SOFT_RST_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_MAG_R_SOFT_RST(void *handle, LSM303AGR_MAG_SOFT_RST_t *value) +{ + if( !LSM303AGR_MAG_read_reg(handle, LSM303AGR_MAG_CFG_REG_A, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_MAG_SOFT_RST_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_MAG_W_LPF +* Description : Write LPF +* Input : LSM303AGR_MAG_LPF_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_MAG_W_LPF(void *handle, LSM303AGR_MAG_LPF_t newValue) +{ + u8_t value; + + if( !LSM303AGR_MAG_read_reg(handle, LSM303AGR_MAG_CFG_REG_B, &value) ) + return MEMS_ERROR; + + value &= ~LSM303AGR_MAG_LPF_MASK; + value |= newValue; + + if( !LSM303AGR_MAG_write_reg(handle, LSM303AGR_MAG_CFG_REG_B, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_MAG_R_LPF +* Description : Read LPF +* Input : Pointer to LSM303AGR_MAG_LPF_t +* Output : Status of LPF see LSM303AGR_MAG_LPF_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_MAG_R_LPF(void *handle, LSM303AGR_MAG_LPF_t *value) +{ + if( !LSM303AGR_MAG_read_reg(handle, LSM303AGR_MAG_CFG_REG_B, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_MAG_LPF_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_MAG_W_OFF_CANC +* Description : Write OFF_CANC +* Input : LSM303AGR_MAG_OFF_CANC_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_MAG_W_OFF_CANC(void *handle, LSM303AGR_MAG_OFF_CANC_t newValue) +{ + u8_t value; + + if( !LSM303AGR_MAG_read_reg(handle, LSM303AGR_MAG_CFG_REG_B, &value) ) + return MEMS_ERROR; + + value &= ~LSM303AGR_MAG_OFF_CANC_MASK; + value |= newValue; + + if( !LSM303AGR_MAG_write_reg(handle, LSM303AGR_MAG_CFG_REG_B, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_MAG_R_OFF_CANC +* Description : Read OFF_CANC +* Input : Pointer to LSM303AGR_MAG_OFF_CANC_t +* Output : Status of OFF_CANC see LSM303AGR_MAG_OFF_CANC_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_MAG_R_OFF_CANC(void *handle, LSM303AGR_MAG_OFF_CANC_t *value) +{ + if( !LSM303AGR_MAG_read_reg(handle, LSM303AGR_MAG_CFG_REG_B, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_MAG_OFF_CANC_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_MAG_W_SET_FREQ +* Description : Write SET_FREQ +* Input : LSM303AGR_MAG_SET_FREQ_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_MAG_W_SET_FREQ(void *handle, LSM303AGR_MAG_SET_FREQ_t newValue) +{ + u8_t value; + + if( !LSM303AGR_MAG_read_reg(handle, LSM303AGR_MAG_CFG_REG_B, &value) ) + return MEMS_ERROR; + + value &= ~LSM303AGR_MAG_SET_FREQ_MASK; + value |= newValue; + + if( !LSM303AGR_MAG_write_reg(handle, LSM303AGR_MAG_CFG_REG_B, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_MAG_R_SET_FREQ +* Description : Read SET_FREQ +* Input : Pointer to LSM303AGR_MAG_SET_FREQ_t +* Output : Status of SET_FREQ see LSM303AGR_MAG_SET_FREQ_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_MAG_R_SET_FREQ(void *handle, LSM303AGR_MAG_SET_FREQ_t *value) +{ + if( !LSM303AGR_MAG_read_reg(handle, LSM303AGR_MAG_CFG_REG_B, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_MAG_SET_FREQ_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_MAG_W_INT_ON_DATAOFF +* Description : Write INT_ON_DATAOFF +* Input : LSM303AGR_MAG_INT_ON_DATAOFF_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_MAG_W_INT_ON_DATAOFF(void *handle, LSM303AGR_MAG_INT_ON_DATAOFF_t newValue) +{ + u8_t value; + + if( !LSM303AGR_MAG_read_reg(handle, LSM303AGR_MAG_CFG_REG_B, &value) ) + return MEMS_ERROR; + + value &= ~LSM303AGR_MAG_INT_ON_DATAOFF_MASK; + value |= newValue; + + if( !LSM303AGR_MAG_write_reg(handle, LSM303AGR_MAG_CFG_REG_B, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_MAG_R_INT_ON_DATAOFF +* Description : Read INT_ON_DATAOFF +* Input : Pointer to LSM303AGR_MAG_INT_ON_DATAOFF_t +* Output : Status of INT_ON_DATAOFF see LSM303AGR_MAG_INT_ON_DATAOFF_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_MAG_R_INT_ON_DATAOFF(void *handle, LSM303AGR_MAG_INT_ON_DATAOFF_t *value) +{ + if( !LSM303AGR_MAG_read_reg(handle, LSM303AGR_MAG_CFG_REG_B, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_MAG_INT_ON_DATAOFF_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_MAG_W_INT_MAG +* Description : Write INT_MAG +* Input : LSM303AGR_MAG_INT_MAG_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_MAG_W_INT_MAG(void *handle, LSM303AGR_MAG_INT_MAG_t newValue) +{ + u8_t value; + + if( !LSM303AGR_MAG_read_reg(handle, LSM303AGR_MAG_CFG_REG_C, &value) ) + return MEMS_ERROR; + + value &= ~LSM303AGR_MAG_INT_MAG_MASK; + value |= newValue; + + if( !LSM303AGR_MAG_write_reg(handle, LSM303AGR_MAG_CFG_REG_C, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_MAG_R_INT_MAG +* Description : Read INT_MAG +* Input : Pointer to LSM303AGR_MAG_INT_MAG_t +* Output : Status of INT_MAG see LSM303AGR_MAG_INT_MAG_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_MAG_R_INT_MAG(void *handle, LSM303AGR_MAG_INT_MAG_t *value) +{ + if( !LSM303AGR_MAG_read_reg(handle, LSM303AGR_MAG_CFG_REG_C, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_MAG_INT_MAG_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_MAG_W_ST +* Description : Write ST +* Input : LSM303AGR_MAG_ST_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_MAG_W_ST(void *handle, LSM303AGR_MAG_ST_t newValue) +{ + u8_t value; + + if( !LSM303AGR_MAG_read_reg(handle, LSM303AGR_MAG_CFG_REG_C, &value) ) + return MEMS_ERROR; + + value &= ~LSM303AGR_MAG_ST_MASK; + value |= newValue; + + if( !LSM303AGR_MAG_write_reg(handle, LSM303AGR_MAG_CFG_REG_C, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_MAG_R_ST +* Description : Read ST +* Input : Pointer to LSM303AGR_MAG_ST_t +* Output : Status of ST see LSM303AGR_MAG_ST_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_MAG_R_ST(void *handle, LSM303AGR_MAG_ST_t *value) +{ + if( !LSM303AGR_MAG_read_reg(handle, LSM303AGR_MAG_CFG_REG_C, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_MAG_ST_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_MAG_W_BLE +* Description : Write BLE +* Input : LSM303AGR_MAG_BLE_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_MAG_W_BLE(void *handle, LSM303AGR_MAG_BLE_t newValue) +{ + u8_t value; + + if( !LSM303AGR_MAG_read_reg(handle, LSM303AGR_MAG_CFG_REG_C, &value) ) + return MEMS_ERROR; + + value &= ~LSM303AGR_MAG_BLE_MASK; + value |= newValue; + + if( !LSM303AGR_MAG_write_reg(handle, LSM303AGR_MAG_CFG_REG_C, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_MAG_R_BLE +* Description : Read BLE +* Input : Pointer to LSM303AGR_MAG_BLE_t +* Output : Status of BLE see LSM303AGR_MAG_BLE_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_MAG_R_BLE(void *handle, LSM303AGR_MAG_BLE_t *value) +{ + if( !LSM303AGR_MAG_read_reg(handle, LSM303AGR_MAG_CFG_REG_C, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_MAG_BLE_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_MAG_W_BDU +* Description : Write BDU +* Input : LSM303AGR_MAG_BDU_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_MAG_W_BDU(void *handle, LSM303AGR_MAG_BDU_t newValue) +{ + u8_t value; + + if( !LSM303AGR_MAG_read_reg(handle, LSM303AGR_MAG_CFG_REG_C, &value) ) + return MEMS_ERROR; + + value &= ~LSM303AGR_MAG_BDU_MASK; + value |= newValue; + + if( !LSM303AGR_MAG_write_reg(handle, LSM303AGR_MAG_CFG_REG_C, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_MAG_R_BDU +* Description : Read BDU +* Input : Pointer to LSM303AGR_MAG_BDU_t +* Output : Status of BDU see LSM303AGR_MAG_BDU_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_MAG_R_BDU(void *handle, LSM303AGR_MAG_BDU_t *value) +{ + if( !LSM303AGR_MAG_read_reg(handle, LSM303AGR_MAG_CFG_REG_C, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_MAG_BDU_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_MAG_W_I2C_DIS +* Description : Write I2C_DIS +* Input : LSM303AGR_MAG_I2C_DIS_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_MAG_W_I2C_DIS(void *handle, LSM303AGR_MAG_I2C_DIS_t newValue) +{ + u8_t value; + + if( !LSM303AGR_MAG_read_reg(handle, LSM303AGR_MAG_CFG_REG_C, &value) ) + return MEMS_ERROR; + + value &= ~LSM303AGR_MAG_I2C_DIS_MASK; + value |= newValue; + + if( !LSM303AGR_MAG_write_reg(handle, LSM303AGR_MAG_CFG_REG_C, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_MAG_R_I2C_DIS +* Description : Read I2C_DIS +* Input : Pointer to LSM303AGR_MAG_I2C_DIS_t +* Output : Status of I2C_DIS see LSM303AGR_MAG_I2C_DIS_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_MAG_R_I2C_DIS(void *handle, LSM303AGR_MAG_I2C_DIS_t *value) +{ + if( !LSM303AGR_MAG_read_reg(handle, LSM303AGR_MAG_CFG_REG_C, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_MAG_I2C_DIS_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_MAG_W_INT_MAG_PIN +* Description : Write INT_MAG_PIN +* Input : LSM303AGR_MAG_INT_MAG_PIN_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_MAG_W_INT_MAG_PIN(void *handle, LSM303AGR_MAG_INT_MAG_PIN_t newValue) +{ + u8_t value; + + if( !LSM303AGR_MAG_read_reg(handle, LSM303AGR_MAG_CFG_REG_C, &value) ) + return MEMS_ERROR; + + value &= ~LSM303AGR_MAG_INT_MAG_PIN_MASK; + value |= newValue; + + if( !LSM303AGR_MAG_write_reg(handle, LSM303AGR_MAG_CFG_REG_C, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_MAG_R_INT_MAG_PIN +* Description : Read INT_MAG_PIN +* Input : Pointer to LSM303AGR_MAG_INT_MAG_PIN_t +* Output : Status of INT_MAG_PIN see LSM303AGR_MAG_INT_MAG_PIN_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_MAG_R_INT_MAG_PIN(void *handle, LSM303AGR_MAG_INT_MAG_PIN_t *value) +{ + if( !LSM303AGR_MAG_read_reg(handle, LSM303AGR_MAG_CFG_REG_C, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_MAG_INT_MAG_PIN_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_MAG_W_IEN +* Description : Write IEN +* Input : LSM303AGR_MAG_IEN_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_MAG_W_IEN(void *handle, LSM303AGR_MAG_IEN_t newValue) +{ + u8_t value; + + if( !LSM303AGR_MAG_read_reg(handle, LSM303AGR_MAG_INT_CTRL_REG, &value) ) + return MEMS_ERROR; + + value &= ~LSM303AGR_MAG_IEN_MASK; + value |= newValue; + + if( !LSM303AGR_MAG_write_reg(handle, LSM303AGR_MAG_INT_CTRL_REG, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_MAG_R_IEN +* Description : Read IEN +* Input : Pointer to LSM303AGR_MAG_IEN_t +* Output : Status of IEN see LSM303AGR_MAG_IEN_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_MAG_R_IEN(void *handle, LSM303AGR_MAG_IEN_t *value) +{ + if( !LSM303AGR_MAG_read_reg(handle, LSM303AGR_MAG_INT_CTRL_REG, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_MAG_IEN_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_MAG_W_IEL +* Description : Write IEL +* Input : LSM303AGR_MAG_IEL_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_MAG_W_IEL(void *handle, LSM303AGR_MAG_IEL_t newValue) +{ + u8_t value; + + if( !LSM303AGR_MAG_read_reg(handle, LSM303AGR_MAG_INT_CTRL_REG, &value) ) + return MEMS_ERROR; + + value &= ~LSM303AGR_MAG_IEL_MASK; + value |= newValue; + + if( !LSM303AGR_MAG_write_reg(handle, LSM303AGR_MAG_INT_CTRL_REG, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_MAG_R_IEL +* Description : Read IEL +* Input : Pointer to LSM303AGR_MAG_IEL_t +* Output : Status of IEL see LSM303AGR_MAG_IEL_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_MAG_R_IEL(void *handle, LSM303AGR_MAG_IEL_t *value) +{ + if( !LSM303AGR_MAG_read_reg(handle, LSM303AGR_MAG_INT_CTRL_REG, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_MAG_IEL_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_MAG_W_IEA +* Description : Write IEA +* Input : LSM303AGR_MAG_IEA_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_MAG_W_IEA(void *handle, LSM303AGR_MAG_IEA_t newValue) +{ + u8_t value; + + if( !LSM303AGR_MAG_read_reg(handle, LSM303AGR_MAG_INT_CTRL_REG, &value) ) + return MEMS_ERROR; + + value &= ~LSM303AGR_MAG_IEA_MASK; + value |= newValue; + + if( !LSM303AGR_MAG_write_reg(handle, LSM303AGR_MAG_INT_CTRL_REG, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_MAG_R_IEA +* Description : Read IEA +* Input : Pointer to LSM303AGR_MAG_IEA_t +* Output : Status of IEA see LSM303AGR_MAG_IEA_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_MAG_R_IEA(void *handle, LSM303AGR_MAG_IEA_t *value) +{ + if( !LSM303AGR_MAG_read_reg(handle, LSM303AGR_MAG_INT_CTRL_REG, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_MAG_IEA_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_MAG_W_ZIEN +* Description : Write ZIEN +* Input : LSM303AGR_MAG_ZIEN_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_MAG_W_ZIEN(void *handle, LSM303AGR_MAG_ZIEN_t newValue) +{ + u8_t value; + + if( !LSM303AGR_MAG_read_reg(handle, LSM303AGR_MAG_INT_CTRL_REG, &value) ) + return MEMS_ERROR; + + value &= ~LSM303AGR_MAG_ZIEN_MASK; + value |= newValue; + + if( !LSM303AGR_MAG_write_reg(handle, LSM303AGR_MAG_INT_CTRL_REG, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_MAG_R_ZIEN +* Description : Read ZIEN +* Input : Pointer to LSM303AGR_MAG_ZIEN_t +* Output : Status of ZIEN see LSM303AGR_MAG_ZIEN_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_MAG_R_ZIEN(void *handle, LSM303AGR_MAG_ZIEN_t *value) +{ + if( !LSM303AGR_MAG_read_reg(handle, LSM303AGR_MAG_INT_CTRL_REG, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_MAG_ZIEN_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_MAG_W_YIEN +* Description : Write YIEN +* Input : LSM303AGR_MAG_YIEN_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_MAG_W_YIEN(void *handle, LSM303AGR_MAG_YIEN_t newValue) +{ + u8_t value; + + if( !LSM303AGR_MAG_read_reg(handle, LSM303AGR_MAG_INT_CTRL_REG, &value) ) + return MEMS_ERROR; + + value &= ~LSM303AGR_MAG_YIEN_MASK; + value |= newValue; + + if( !LSM303AGR_MAG_write_reg(handle, LSM303AGR_MAG_INT_CTRL_REG, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_MAG_R_YIEN +* Description : Read YIEN +* Input : Pointer to LSM303AGR_MAG_YIEN_t +* Output : Status of YIEN see LSM303AGR_MAG_YIEN_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_MAG_R_YIEN(void *handle, LSM303AGR_MAG_YIEN_t *value) +{ + if( !LSM303AGR_MAG_read_reg(handle, LSM303AGR_MAG_INT_CTRL_REG, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_MAG_YIEN_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_MAG_W_XIEN +* Description : Write XIEN +* Input : LSM303AGR_MAG_XIEN_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_MAG_W_XIEN(void *handle, LSM303AGR_MAG_XIEN_t newValue) +{ + u8_t value; + + if( !LSM303AGR_MAG_read_reg(handle, LSM303AGR_MAG_INT_CTRL_REG, &value) ) + return MEMS_ERROR; + + value &= ~LSM303AGR_MAG_XIEN_MASK; + value |= newValue; + + if( !LSM303AGR_MAG_write_reg(handle, LSM303AGR_MAG_INT_CTRL_REG, value) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_MAG_R_XIEN +* Description : Read XIEN +* Input : Pointer to LSM303AGR_MAG_XIEN_t +* Output : Status of XIEN see LSM303AGR_MAG_XIEN_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_MAG_R_XIEN(void *handle, LSM303AGR_MAG_XIEN_t *value) +{ + if( !LSM303AGR_MAG_read_reg(handle, LSM303AGR_MAG_INT_CTRL_REG, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_MAG_XIEN_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_MAG_R_INT +* Description : Read INT +* Input : Pointer to LSM303AGR_MAG_INT_t +* Output : Status of INT see LSM303AGR_MAG_INT_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_MAG_R_INT(void *handle, LSM303AGR_MAG_INT_t *value) +{ + if( !LSM303AGR_MAG_read_reg(handle, LSM303AGR_MAG_INT_SOURCE_REG, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_MAG_INT_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_MAG_R_MROI +* Description : Read MROI +* Input : Pointer to LSM303AGR_MAG_MROI_t +* Output : Status of MROI see LSM303AGR_MAG_MROI_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_MAG_R_MROI(void *handle, LSM303AGR_MAG_MROI_t *value) +{ + if( !LSM303AGR_MAG_read_reg(handle, LSM303AGR_MAG_INT_SOURCE_REG, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_MAG_MROI_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_MAG_R_N_TH_S_Z +* Description : Read N_TH_S_Z +* Input : Pointer to LSM303AGR_MAG_N_TH_S_Z_t +* Output : Status of N_TH_S_Z see LSM303AGR_MAG_N_TH_S_Z_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_MAG_R_N_TH_S_Z(void *handle, LSM303AGR_MAG_N_TH_S_Z_t *value) +{ + if( !LSM303AGR_MAG_read_reg(handle, LSM303AGR_MAG_INT_SOURCE_REG, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_MAG_N_TH_S_Z_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_MAG_R_N_TH_S_Y +* Description : Read N_TH_S_Y +* Input : Pointer to LSM303AGR_MAG_N_TH_S_Y_t +* Output : Status of N_TH_S_Y see LSM303AGR_MAG_N_TH_S_Y_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_MAG_R_N_TH_S_Y(void *handle, LSM303AGR_MAG_N_TH_S_Y_t *value) +{ + if( !LSM303AGR_MAG_read_reg(handle, LSM303AGR_MAG_INT_SOURCE_REG, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_MAG_N_TH_S_Y_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_MAG_R_N_TH_S_X +* Description : Read N_TH_S_X +* Input : Pointer to LSM303AGR_MAG_N_TH_S_X_t +* Output : Status of N_TH_S_X see LSM303AGR_MAG_N_TH_S_X_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_MAG_R_N_TH_S_X(void *handle, LSM303AGR_MAG_N_TH_S_X_t *value) +{ + if( !LSM303AGR_MAG_read_reg(handle, LSM303AGR_MAG_INT_SOURCE_REG, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_MAG_N_TH_S_X_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_MAG_R_P_TH_S_Z +* Description : Read P_TH_S_Z +* Input : Pointer to LSM303AGR_MAG_P_TH_S_Z_t +* Output : Status of P_TH_S_Z see LSM303AGR_MAG_P_TH_S_Z_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_MAG_R_P_TH_S_Z(void *handle, LSM303AGR_MAG_P_TH_S_Z_t *value) +{ + if( !LSM303AGR_MAG_read_reg(handle, LSM303AGR_MAG_INT_SOURCE_REG, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_MAG_P_TH_S_Z_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_MAG_R_P_TH_S_Y +* Description : Read P_TH_S_Y +* Input : Pointer to LSM303AGR_MAG_P_TH_S_Y_t +* Output : Status of P_TH_S_Y see LSM303AGR_MAG_P_TH_S_Y_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_MAG_R_P_TH_S_Y(void *handle, LSM303AGR_MAG_P_TH_S_Y_t *value) +{ + if( !LSM303AGR_MAG_read_reg(handle, LSM303AGR_MAG_INT_SOURCE_REG, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_MAG_P_TH_S_Y_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_MAG_R_P_TH_S_X +* Description : Read P_TH_S_X +* Input : Pointer to LSM303AGR_MAG_P_TH_S_X_t +* Output : Status of P_TH_S_X see LSM303AGR_MAG_P_TH_S_X_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_MAG_R_P_TH_S_X(void *handle, LSM303AGR_MAG_P_TH_S_X_t *value) +{ + if( !LSM303AGR_MAG_read_reg(handle, LSM303AGR_MAG_INT_SOURCE_REG, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_MAG_P_TH_S_X_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM303AGR_MAG_R_XDA +* Description : Read XDA +* Input : Pointer to LSM303AGR_MAG_XDA_t +* Output : Status of XDA see LSM303AGR_MAG_XDA_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_MAG_R_XDA(void *handle, LSM303AGR_MAG_XDA_t *value) +{ + if( !LSM303AGR_MAG_read_reg(handle, LSM303AGR_MAG_STATUS_REG, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_MAG_XDA_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_MAG_R_YDA +* Description : Read YDA +* Input : Pointer to LSM303AGR_MAG_YDA_t +* Output : Status of YDA see LSM303AGR_MAG_YDA_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_MAG_R_YDA(void *handle, LSM303AGR_MAG_YDA_t *value) +{ + if( !LSM303AGR_MAG_read_reg(handle, LSM303AGR_MAG_STATUS_REG, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_MAG_YDA_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_MAG_R_ZDA +* Description : Read ZDA +* Input : Pointer to LSM303AGR_MAG_ZDA_t +* Output : Status of ZDA see LSM303AGR_MAG_ZDA_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_MAG_R_ZDA(void *handle, LSM303AGR_MAG_ZDA_t *value) +{ + if( !LSM303AGR_MAG_read_reg(handle, LSM303AGR_MAG_STATUS_REG, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_MAG_ZDA_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_MAG_R_ZYXDA +* Description : Read ZYXDA +* Input : Pointer to LSM303AGR_MAG_ZYXDA_t +* Output : Status of ZYXDA see LSM303AGR_MAG_ZYXDA_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_MAG_R_ZYXDA(void *handle, LSM303AGR_MAG_ZYXDA_t *value) +{ + if( !LSM303AGR_MAG_read_reg(handle, LSM303AGR_MAG_STATUS_REG, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_MAG_ZYXDA_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_MAG_R_XOR +* Description : Read XOR +* Input : Pointer to LSM303AGR_MAG_XOR_t +* Output : Status of XOR see LSM303AGR_MAG_XOR_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_MAG_R_XOR(void *handle, LSM303AGR_MAG_XOR_t *value) +{ + if( !LSM303AGR_MAG_read_reg(handle, LSM303AGR_MAG_STATUS_REG, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_MAG_XOR_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_MAG_R_YOR +* Description : Read YOR +* Input : Pointer to LSM303AGR_MAG_YOR_t +* Output : Status of YOR see LSM303AGR_MAG_YOR_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_MAG_R_YOR(void *handle, LSM303AGR_MAG_YOR_t *value) +{ + if( !LSM303AGR_MAG_read_reg(handle, LSM303AGR_MAG_STATUS_REG, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_MAG_YOR_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_MAG_R_ZOR +* Description : Read ZOR +* Input : Pointer to LSM303AGR_MAG_ZOR_t +* Output : Status of ZOR see LSM303AGR_MAG_ZOR_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_MAG_R_ZOR(void *handle, LSM303AGR_MAG_ZOR_t *value) +{ + if( !LSM303AGR_MAG_read_reg(handle, LSM303AGR_MAG_STATUS_REG, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_MAG_ZOR_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM303AGR_MAG_R_ZYXOR +* Description : Read ZYXOR +* Input : Pointer to LSM303AGR_MAG_ZYXOR_t +* Output : Status of ZYXOR see LSM303AGR_MAG_ZYXOR_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ + +mems_status_t LSM303AGR_MAG_R_ZYXOR(void *handle, LSM303AGR_MAG_ZYXOR_t *value) +{ + if( !LSM303AGR_MAG_read_reg(handle, LSM303AGR_MAG_STATUS_REG, (u8_t *)value) ) + return MEMS_ERROR; + + *value &= LSM303AGR_MAG_ZYXOR_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : mems_status_t LSM303AGR_MAG_Get_Raw_Magnetic(u8_t *buff) +* Description : Read Magnetic output register +* Input : pointer to [u8_t] +* Output : Magnetic buffer u8_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_MAG_Get_Raw_Magnetic(void *handle, u8_t *buff) +{ + u8_t i, j, k; + u8_t numberOfByteForDimension; + + numberOfByteForDimension=6/3; + + k=0; + for (i=0; i<3;i++ ) + { + for (j=0; j<numberOfByteForDimension;j++ ) + { + if( !LSM303AGR_MAG_read_reg(handle, LSM303AGR_MAG_OUTX_L_REG+k, &buff[k])) + return MEMS_ERROR; + k++; + } + } + + return MEMS_SUCCESS; +} + +#define LSM303AGR_MAG_SENSITIVITY 15/10 + +mems_status_t LSM303AGR_MAG_Get_Magnetic(void *handle, int *buff) +{ + Type3Axis16bit_U raw_data_tmp; + + /* Read out raw magnetometer samples */ + if(!LSM303AGR_MAG_Get_Raw_Magnetic(handle, raw_data_tmp.u8bit)) { + return MEMS_ERROR; + } + + /* Applysensitivity */ + buff[0] = raw_data_tmp.i16bit[0] * LSM303AGR_MAG_SENSITIVITY; + buff[1] = raw_data_tmp.i16bit[1] * LSM303AGR_MAG_SENSITIVITY; + buff[2] = raw_data_tmp.i16bit[2] * LSM303AGR_MAG_SENSITIVITY; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : mems_status_t LSM303AGR_MAG_Get_IntThreshld(u8_t *buff) +* Description : Read IntThreshld output register +* Input : pointer to [u8_t] +* Output : IntThreshld buffer u8_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_MAG_Get_IntThreshld(void *handle, u8_t *buff) +{ + u8_t i, j, k; + u8_t numberOfByteForDimension; + + numberOfByteForDimension=2/1; + + k=0; + for (i=0; i<1;i++ ) + { + for (j=0; j<numberOfByteForDimension;j++ ) + { + if( !LSM303AGR_MAG_read_reg(handle, LSM303AGR_MAG_INT_THS_L_REG+k, &buff[k])) + return MEMS_ERROR; + k++; + } + } + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : mems_status_t LSM303AGR_MAG_Set_IntThreshld(u8_t *buff) +* Description : Write IntThreshld output register +* Input : pointer to [u8_t] +* Output : IntThreshld buffer u8_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM303AGR_MAG_Set_IntThreshld(void *handle, u8_t *buff) +{ + u8_t i, j, k; + u8_t numberOfByteForDimension; + + numberOfByteForDimension=2/1; + + k=0; + for (i=0; i<1;i++ ) + { + for (j=0; j<numberOfByteForDimension;j++ ) + { + if( !LSM303AGR_MAG_write_reg(handle, LSM303AGR_MAG_INT_THS_L_REG+k, buff[k])) + return MEMS_ERROR; + k++; + } + } + + return MEMS_SUCCESS; +}
diff -r 000000000000 -r 98c301bb7d1b Components/LSM303AGRSensor/LSM303AGR_mag_driver.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Components/LSM303AGRSensor/LSM303AGR_mag_driver.h Tue Oct 03 12:21:11 2017 +0000 @@ -0,0 +1,766 @@ +/** + ****************************************************************************** + * @file LSM303AGR_mag_driver.h + * @author MEMS Application Team + * @version V1.1 + * @date 25-February-2016 + * @brief LSM303AGR Magnetometer header driver file + ****************************************************************************** + * @attention + * + * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of STMicroelectronics nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************** + */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __LSM303AGR_MAG_DRIVER__H +#define __LSM303AGR_MAG_DRIVER__H + +/* Includes ------------------------------------------------------------------*/ +#include <stdint.h> + +/* Exported types ------------------------------------------------------------*/ + +#ifdef __cplusplus +extern "C" { +#endif + +//these could change accordingly with the architecture + +#ifndef __ARCHDEP__TYPES +#define __ARCHDEP__TYPES + +typedef unsigned char u8_t; +typedef unsigned short int u16_t; +typedef unsigned int u32_t; +typedef int i32_t; +typedef short int i16_t; +typedef signed char i8_t; + +#endif /*__ARCHDEP__TYPES*/ + +/* Exported common structure --------------------------------------------------------*/ + +#ifndef __SHARED__TYPES +#define __SHARED__TYPES + +typedef union{ + i16_t i16bit[3]; + u8_t u8bit[6]; +} Type3Axis16bit_U; + +typedef union{ + i16_t i16bit; + u8_t u8bit[2]; +} Type1Axis16bit_U; + +typedef union{ + i32_t i32bit; + u8_t u8bit[4]; +} Type1Axis32bit_U; + +typedef enum { + MEMS_SUCCESS = 0x01, + MEMS_ERROR = 0x00 +} mems_status_t; + +#endif /*__SHARED__TYPES*/ + +/* Exported macro ------------------------------------------------------------*/ + +/* Exported constants --------------------------------------------------------*/ + +/************** I2C Address *****************/ + +#define LSM303AGR_MAG_I2C_ADDRESS 0x3C + +/************** Who am I *******************/ + +#define LSM303AGR_MAG_WHO_AM_I 0x40 + +/* Private Function Prototype -------------------------------------------------------*/ + +void LSM303AGR_MAG_SwapHighLowByte(u8_t *bufferToSwap, u8_t numberOfByte, u8_t dimension); + +/* Public Function Prototypes -------------------------------------------------------*/ + +mems_status_t LSM303AGR_MAG_read_reg( void *handle, u8_t Reg, u8_t* Data ); +mems_status_t LSM303AGR_MAG_write_reg( void *handle, u8_t Reg, u8_t Data ); + + +/************** Device Register *******************/ +#define LSM303AGR_MAG_OFFSET_X_REG_L 0X45 +#define LSM303AGR_MAG_OFFSET_X_REG_H 0X46 +#define LSM303AGR_MAG_OFFSET_Y_REG_L 0X47 +#define LSM303AGR_MAG_OFFSET_Y_REG_H 0X48 +#define LSM303AGR_MAG_OFFSET_Z_REG_L 0X49 +#define LSM303AGR_MAG_OFFSET_Z_REG_H 0X4A +#define LSM303AGR_MAG_WHO_AM_I_REG 0X4F +#define LSM303AGR_MAG_CFG_REG_A 0X60 +#define LSM303AGR_MAG_CFG_REG_B 0X61 +#define LSM303AGR_MAG_CFG_REG_C 0X62 +#define LSM303AGR_MAG_INT_CTRL_REG 0X63 +#define LSM303AGR_MAG_INT_SOURCE_REG 0X64 +#define LSM303AGR_MAG_INT_THS_L_REG 0X65 +#define LSM303AGR_MAG_INT_THS_H_REG 0X66 +#define LSM303AGR_MAG_STATUS_REG 0X67 +#define LSM303AGR_MAG_OUTX_L_REG 0X68 +#define LSM303AGR_MAG_OUTX_H_REG 0X69 +#define LSM303AGR_MAG_OUTY_L_REG 0X6A +#define LSM303AGR_MAG_OUTY_H_REG 0X6B +#define LSM303AGR_MAG_OUTZ_L_REG 0X6C +#define LSM303AGR_MAG_OUTZ_H_REG 0X6D + +/******************************************************************************* +* Register : OFFSET_X_REG_L +* Address : 0X45 +* Bit Group Name: OFF_X_L +* Permission : RW +*******************************************************************************/ +#define LSM303AGR_MAG_OFF_X_L_MASK 0xFF +#define LSM303AGR_MAG_OFF_X_L_POSITION 0 +mems_status_t LSM303AGR_MAG_W_OFF_X_L(void *handle, u8_t newValue); +mems_status_t LSM303AGR_MAG_R_OFF_X_L(void *handle, u8_t *value); + +/******************************************************************************* +* Register : OFFSET_X_REG_H +* Address : 0X46 +* Bit Group Name: OFF_X_H +* Permission : RW +*******************************************************************************/ +#define LSM303AGR_MAG_OFF_X_H_MASK 0xFF +#define LSM303AGR_MAG_OFF_X_H_POSITION 0 +mems_status_t LSM303AGR_MAG_W_OFF_X_H(void *handle, u8_t newValue); +mems_status_t LSM303AGR_MAG_R_OFF_X_H(void *handle, u8_t *value); + +/******************************************************************************* +* Register : OFFSET_Y_REG_L +* Address : 0X47 +* Bit Group Name: OFF_Y_L +* Permission : RW +*******************************************************************************/ +#define LSM303AGR_MAG_OFF_Y_L_MASK 0xFF +#define LSM303AGR_MAG_OFF_Y_L_POSITION 0 +mems_status_t LSM303AGR_MAG_W_OFF_Y_L(void *handle, u8_t newValue); +mems_status_t LSM303AGR_MAG_R_OFF_Y_L(void *handle, u8_t *value); + +/******************************************************************************* +* Register : OFFSET_Y_REG_H +* Address : 0X48 +* Bit Group Name: OFF_Y_H +* Permission : RW +*******************************************************************************/ +#define LSM303AGR_MAG_OFF_Y_H_MASK 0xFF +#define LSM303AGR_MAG_OFF_Y_H_POSITION 0 +mems_status_t LSM303AGR_MAG_W_OFF_Y_H(void *handle, u8_t newValue); +mems_status_t LSM303AGR_MAG_R_OFF_Y_H(void *handle, u8_t *value); + +/******************************************************************************* +* Register : OFFSET_Z_REG_L +* Address : 0X49 +* Bit Group Name: OFF_Z_L +* Permission : RW +*******************************************************************************/ +#define LSM303AGR_MAG_OFF_Z_L_MASK 0xFF +#define LSM303AGR_MAG_OFF_Z_L_POSITION 0 +mems_status_t LSM303AGR_MAG_W_OFF_Z_L(void *handle, u8_t newValue); +mems_status_t LSM303AGR_MAG_R_OFF_Z_L(void *handle, u8_t *value); + +/******************************************************************************* +* Register : OFFSET_Z_REG_H +* Address : 0X4A +* Bit Group Name: OFF_Z_H +* Permission : RW +*******************************************************************************/ +#define LSM303AGR_MAG_OFF_Z_H_MASK 0xFF +#define LSM303AGR_MAG_OFF_Z_H_POSITION 0 +mems_status_t LSM303AGR_MAG_W_OFF_Z_H(void *handle, u8_t newValue); +mems_status_t LSM303AGR_MAG_R_OFF_Z_H(void *handle, u8_t *value); + +/******************************************************************************* + * Set/Get the Magnetic offsets +*******************************************************************************/ +mems_status_t LSM303AGR_MAG_Get_MagOff(void *handle, u16_t *magx_off, u16_t *magy_off, u16_t *magz_off); +mems_status_t LSM303AGR_MAG_Set_MagOff(void *handle, u16_t magx_off, u16_t magy_off, u16_t magz_off); + +/******************************************************************************* +* Register : WHO_AM_I_REG +* Address : 0X4F +* Bit Group Name: WHO_AM_I +* Permission : RO +*******************************************************************************/ +#define LSM303AGR_MAG_WHO_AM_I_MASK 0xFF +#define LSM303AGR_MAG_WHO_AM_I_POSITION 0 +mems_status_t LSM303AGR_MAG_R_WHO_AM_I(void *handle, u8_t *value); + +/******************************************************************************* +* Register : CFG_REG_A +* Address : 0X60 +* Bit Group Name: MD +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM303AGR_MAG_MD_CONTINUOS_MODE =0x00, + LSM303AGR_MAG_MD_SINGLE_MODE =0x01, + LSM303AGR_MAG_MD_IDLE1_MODE =0x02, + LSM303AGR_MAG_MD_IDLE2_MODE =0x03, +} LSM303AGR_MAG_MD_t; + +#define LSM303AGR_MAG_MD_MASK 0x03 +mems_status_t LSM303AGR_MAG_W_MD(void *handle, LSM303AGR_MAG_MD_t newValue); +mems_status_t LSM303AGR_MAG_R_MD(void *handle, LSM303AGR_MAG_MD_t *value); + +/******************************************************************************* +* Register : CFG_REG_A +* Address : 0X60 +* Bit Group Name: ODR +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM303AGR_MAG_ODR_10Hz =0x00, + LSM303AGR_MAG_ODR_20Hz =0x04, + LSM303AGR_MAG_ODR_50Hz =0x08, + LSM303AGR_MAG_ODR_100Hz =0x0C, +} LSM303AGR_MAG_ODR_t; + +#define LSM303AGR_MAG_ODR_MASK 0x0C +mems_status_t LSM303AGR_MAG_W_ODR(void *handle, LSM303AGR_MAG_ODR_t newValue); +mems_status_t LSM303AGR_MAG_R_ODR(void *handle, LSM303AGR_MAG_ODR_t *value); + +/******************************************************************************* +* Register : CFG_REG_A +* Address : 0X60 +* Bit Group Name: LP +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM303AGR_MAG_HR_MODE =0x00, + LSM303AGR_MAG_LP_MODE =0x10, +} LSM303AGR_MAG_LP_t; + +#define LSM303AGR_MAG_LP_MASK 0x10 +mems_status_t LSM303AGR_MAG_W_LP(void *handle, LSM303AGR_MAG_LP_t newValue); +mems_status_t LSM303AGR_MAG_R_LP(void *handle, LSM303AGR_MAG_LP_t *value); + +/******************************************************************************* +* Register : CFG_REG_A +* Address : 0X60 +* Bit Group Name: SOFT_RST +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM303AGR_MAG_SOFT_RST_DISABLED =0x00, + LSM303AGR_MAG_SOFT_RST_ENABLED =0x20, +} LSM303AGR_MAG_SOFT_RST_t; + +#define LSM303AGR_MAG_SOFT_RST_MASK 0x20 +mems_status_t LSM303AGR_MAG_W_SOFT_RST(void *handle, LSM303AGR_MAG_SOFT_RST_t newValue); +mems_status_t LSM303AGR_MAG_R_SOFT_RST(void *handle, LSM303AGR_MAG_SOFT_RST_t *value); + +/******************************************************************************* +* Register : CFG_REG_B +* Address : 0X61 +* Bit Group Name: LPF +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM303AGR_MAG_LPF_DISABLED =0x00, + LSM303AGR_MAG_LPF_ENABLED =0x01, +} LSM303AGR_MAG_LPF_t; + +#define LSM303AGR_MAG_LPF_MASK 0x01 +mems_status_t LSM303AGR_MAG_W_LPF(void *handle, LSM303AGR_MAG_LPF_t newValue); +mems_status_t LSM303AGR_MAG_R_LPF(void *handle, LSM303AGR_MAG_LPF_t *value); + +/******************************************************************************* +* Register : CFG_REG_B +* Address : 0X61 +* Bit Group Name: OFF_CANC +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM303AGR_MAG_OFF_CANC_DISABLED =0x00, + LSM303AGR_MAG_OFF_CANC_ENABLED =0x02, +} LSM303AGR_MAG_OFF_CANC_t; + +#define LSM303AGR_MAG_OFF_CANC_MASK 0x02 +mems_status_t LSM303AGR_MAG_W_OFF_CANC(void *handle, LSM303AGR_MAG_OFF_CANC_t newValue); +mems_status_t LSM303AGR_MAG_R_OFF_CANC(void *handle, LSM303AGR_MAG_OFF_CANC_t *value); + +/******************************************************************************* +* Register : CFG_REG_B +* Address : 0X61 +* Bit Group Name: SET_FREQ +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM303AGR_MAG_SET_FREQ_CONTINUOS =0x00, + LSM303AGR_MAG_SET_FREQ_SINGLE =0x04, +} LSM303AGR_MAG_SET_FREQ_t; + +#define LSM303AGR_MAG_SET_FREQ_MASK 0x04 +mems_status_t LSM303AGR_MAG_W_SET_FREQ(void *handle, LSM303AGR_MAG_SET_FREQ_t newValue); +mems_status_t LSM303AGR_MAG_R_SET_FREQ(void *handle, LSM303AGR_MAG_SET_FREQ_t *value); + +/******************************************************************************* +* Register : CFG_REG_B +* Address : 0X61 +* Bit Group Name: INT_ON_DATAOFF +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM303AGR_MAG_INT_ON_DATAOFF_DISABLED =0x00, + LSM303AGR_MAG_INT_ON_DATAOFF_ENABLED =0x08, +} LSM303AGR_MAG_INT_ON_DATAOFF_t; + +#define LSM303AGR_MAG_INT_ON_DATAOFF_MASK 0x08 +mems_status_t LSM303AGR_MAG_W_INT_ON_DATAOFF(void *handle, LSM303AGR_MAG_INT_ON_DATAOFF_t newValue); +mems_status_t LSM303AGR_MAG_R_INT_ON_DATAOFF(void *handle, LSM303AGR_MAG_INT_ON_DATAOFF_t *value); + +/******************************************************************************* +* Register : CFG_REG_C +* Address : 0X62 +* Bit Group Name: INT_MAG +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM303AGR_MAG_INT_MAG_DISABLED =0x00, + LSM303AGR_MAG_INT_MAG_ENABLED =0x01, +} LSM303AGR_MAG_INT_MAG_t; + +#define LSM303AGR_MAG_INT_MAG_MASK 0x01 +mems_status_t LSM303AGR_MAG_W_INT_MAG(void *handle, LSM303AGR_MAG_INT_MAG_t newValue); +mems_status_t LSM303AGR_MAG_R_INT_MAG(void *handle, LSM303AGR_MAG_INT_MAG_t *value); + +/******************************************************************************* +* Register : CFG_REG_C +* Address : 0X62 +* Bit Group Name: ST +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM303AGR_MAG_ST_DISABLED =0x00, + LSM303AGR_MAG_ST_ENABLED =0x02, +} LSM303AGR_MAG_ST_t; + +#define LSM303AGR_MAG_ST_MASK 0x02 +mems_status_t LSM303AGR_MAG_W_ST(void *handle, LSM303AGR_MAG_ST_t newValue); +mems_status_t LSM303AGR_MAG_R_ST(void *handle, LSM303AGR_MAG_ST_t *value); + +/******************************************************************************* +* Register : CFG_REG_C +* Address : 0X62 +* Bit Group Name: BLE +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM303AGR_MAG_BLE_DISABLED =0x00, + LSM303AGR_MAG_BLE_ENABLED =0x08, +} LSM303AGR_MAG_BLE_t; + +#define LSM303AGR_MAG_BLE_MASK 0x08 +mems_status_t LSM303AGR_MAG_W_BLE(void *handle, LSM303AGR_MAG_BLE_t newValue); +mems_status_t LSM303AGR_MAG_R_BLE(void *handle, LSM303AGR_MAG_BLE_t *value); + +/******************************************************************************* +* Register : CFG_REG_C +* Address : 0X62 +* Bit Group Name: BDU +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM303AGR_MAG_BDU_DISABLED =0x00, + LSM303AGR_MAG_BDU_ENABLED =0x10, +} LSM303AGR_MAG_BDU_t; + +#define LSM303AGR_MAG_BDU_MASK 0x10 +mems_status_t LSM303AGR_MAG_W_BDU(void *handle, LSM303AGR_MAG_BDU_t newValue); +mems_status_t LSM303AGR_MAG_R_BDU(void *handle, LSM303AGR_MAG_BDU_t *value); + +/******************************************************************************* +* Register : CFG_REG_C +* Address : 0X62 +* Bit Group Name: I2C_DIS +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM303AGR_MAG_I2C_ENABLED =0x00, + LSM303AGR_MAG_I2C_DISABLED =0x20, +} LSM303AGR_MAG_I2C_DIS_t; + +#define LSM303AGR_MAG_I2C_DIS_MASK 0x20 +mems_status_t LSM303AGR_MAG_W_I2C_DIS(void *handle, LSM303AGR_MAG_I2C_DIS_t newValue); +mems_status_t LSM303AGR_MAG_R_I2C_DIS(void *handle, LSM303AGR_MAG_I2C_DIS_t *value); + +/******************************************************************************* +* Register : CFG_REG_C +* Address : 0X62 +* Bit Group Name: INT_MAG_PIN +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM303AGR_MAG_INT_MAG_PIN_DISABLED =0x00, + LSM303AGR_MAG_INT_MAG_PIN_ENABLED =0x40, +} LSM303AGR_MAG_INT_MAG_PIN_t; + +#define LSM303AGR_MAG_INT_MAG_PIN_MASK 0x40 +mems_status_t LSM303AGR_MAG_W_INT_MAG_PIN(void *handle, LSM303AGR_MAG_INT_MAG_PIN_t newValue); +mems_status_t LSM303AGR_MAG_R_INT_MAG_PIN(void *handle, LSM303AGR_MAG_INT_MAG_PIN_t *value); + +/******************************************************************************* +* Register : INT_CTRL_REG +* Address : 0X63 +* Bit Group Name: IEN +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM303AGR_MAG_IEN_DISABLED =0x00, + LSM303AGR_MAG_IEN_ENABLED =0x01, +} LSM303AGR_MAG_IEN_t; + +#define LSM303AGR_MAG_IEN_MASK 0x01 +mems_status_t LSM303AGR_MAG_W_IEN(void *handle, LSM303AGR_MAG_IEN_t newValue); +mems_status_t LSM303AGR_MAG_R_IEN(void *handle, LSM303AGR_MAG_IEN_t *value); + +/******************************************************************************* +* Register : INT_CTRL_REG +* Address : 0X63 +* Bit Group Name: IEL +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM303AGR_MAG_IEL_PULSED =0x00, + LSM303AGR_MAG_IEL_LATCHED =0x02, +} LSM303AGR_MAG_IEL_t; + +#define LSM303AGR_MAG_IEL_MASK 0x02 +mems_status_t LSM303AGR_MAG_W_IEL(void *handle, LSM303AGR_MAG_IEL_t newValue); +mems_status_t LSM303AGR_MAG_R_IEL(void *handle, LSM303AGR_MAG_IEL_t *value); + +/******************************************************************************* +* Register : INT_CTRL_REG +* Address : 0X63 +* Bit Group Name: IEA +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM303AGR_MAG_IEA_ACTIVE_LO =0x00, + LSM303AGR_MAG_IEA_ACTIVE_HI =0x04, +} LSM303AGR_MAG_IEA_t; + +#define LSM303AGR_MAG_IEA_MASK 0x04 +mems_status_t LSM303AGR_MAG_W_IEA(void *handle, LSM303AGR_MAG_IEA_t newValue); +mems_status_t LSM303AGR_MAG_R_IEA(void *handle, LSM303AGR_MAG_IEA_t *value); + +/******************************************************************************* +* Register : INT_CTRL_REG +* Address : 0X63 +* Bit Group Name: ZIEN +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM303AGR_MAG_ZIEN_DISABLED =0x00, + LSM303AGR_MAG_ZIEN_ENABLED =0x20, +} LSM303AGR_MAG_ZIEN_t; + +#define LSM303AGR_MAG_ZIEN_MASK 0x20 +mems_status_t LSM303AGR_MAG_W_ZIEN(void *handle, LSM303AGR_MAG_ZIEN_t newValue); +mems_status_t LSM303AGR_MAG_R_ZIEN(void *handle, LSM303AGR_MAG_ZIEN_t *value); + +/******************************************************************************* +* Register : INT_CTRL_REG +* Address : 0X63 +* Bit Group Name: YIEN +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM303AGR_MAG_YIEN_DISABLED =0x00, + LSM303AGR_MAG_YIEN_ENABLED =0x40, +} LSM303AGR_MAG_YIEN_t; + +#define LSM303AGR_MAG_YIEN_MASK 0x40 +mems_status_t LSM303AGR_MAG_W_YIEN(void *handle, LSM303AGR_MAG_YIEN_t newValue); +mems_status_t LSM303AGR_MAG_R_YIEN(void *handle, LSM303AGR_MAG_YIEN_t *value); + +/******************************************************************************* +* Register : INT_CTRL_REG +* Address : 0X63 +* Bit Group Name: XIEN +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM303AGR_MAG_XIEN_DISABLED =0x00, + LSM303AGR_MAG_XIEN_ENABLED =0x80, +} LSM303AGR_MAG_XIEN_t; + +#define LSM303AGR_MAG_XIEN_MASK 0x80 +mems_status_t LSM303AGR_MAG_W_XIEN(void *handle, LSM303AGR_MAG_XIEN_t newValue); +mems_status_t LSM303AGR_MAG_R_XIEN(void *handle, LSM303AGR_MAG_XIEN_t *value); + +/******************************************************************************* +* Register : INT_SOURCE_REG +* Address : 0X64 +* Bit Group Name: INT +* Permission : RO +*******************************************************************************/ +typedef enum { + LSM303AGR_MAG_INT_EV_OFF =0x00, + LSM303AGR_MAG_INT_EV_ON =0x01, +} LSM303AGR_MAG_INT_t; + +#define LSM303AGR_MAG_INT_MASK 0x01 +mems_status_t LSM303AGR_MAG_R_INT(void *handle, LSM303AGR_MAG_INT_t *value); + +/******************************************************************************* +* Register : INT_SOURCE_REG +* Address : 0X64 +* Bit Group Name: MROI +* Permission : RO +*******************************************************************************/ +typedef enum { + LSM303AGR_MAG_MROI_EV_OFF =0x00, + LSM303AGR_MAG_MROI_EV_ON =0x02, +} LSM303AGR_MAG_MROI_t; + +#define LSM303AGR_MAG_MROI_MASK 0x02 +mems_status_t LSM303AGR_MAG_R_MROI(void *handle, LSM303AGR_MAG_MROI_t *value); + +/******************************************************************************* +* Register : INT_SOURCE_REG +* Address : 0X64 +* Bit Group Name: N_TH_S_Z +* Permission : RO +*******************************************************************************/ +typedef enum { + LSM303AGR_MAG_N_TH_S_Z_EV_OFF =0x00, + LSM303AGR_MAG_N_TH_S_Z_EV_ON =0x04, +} LSM303AGR_MAG_N_TH_S_Z_t; + +#define LSM303AGR_MAG_N_TH_S_Z_MASK 0x04 +mems_status_t LSM303AGR_MAG_R_N_TH_S_Z(void *handle, LSM303AGR_MAG_N_TH_S_Z_t *value); + +/******************************************************************************* +* Register : INT_SOURCE_REG +* Address : 0X64 +* Bit Group Name: N_TH_S_Y +* Permission : RO +*******************************************************************************/ +typedef enum { + LSM303AGR_MAG_N_TH_S_Y_EV_OFF =0x00, + LSM303AGR_MAG_N_TH_S_Y_EV_ON =0x08, +} LSM303AGR_MAG_N_TH_S_Y_t; + +#define LSM303AGR_MAG_N_TH_S_Y_MASK 0x08 +mems_status_t LSM303AGR_MAG_R_N_TH_S_Y(void *handle, LSM303AGR_MAG_N_TH_S_Y_t *value); + +/******************************************************************************* +* Register : INT_SOURCE_REG +* Address : 0X64 +* Bit Group Name: N_TH_S_X +* Permission : RO +*******************************************************************************/ +typedef enum { + LSM303AGR_MAG_N_TH_S_X_EV_OFF =0x00, + LSM303AGR_MAG_N_TH_S_X_EV_ON =0x10, +} LSM303AGR_MAG_N_TH_S_X_t; + +#define LSM303AGR_MAG_N_TH_S_X_MASK 0x10 +mems_status_t LSM303AGR_MAG_R_N_TH_S_X(void *handle, LSM303AGR_MAG_N_TH_S_X_t *value); + +/******************************************************************************* +* Register : INT_SOURCE_REG +* Address : 0X64 +* Bit Group Name: P_TH_S_Z +* Permission : RO +*******************************************************************************/ +typedef enum { + LSM303AGR_MAG_P_TH_S_Z_EV_OFF =0x00, + LSM303AGR_MAG_P_TH_S_Z_EV_ON =0x20, +} LSM303AGR_MAG_P_TH_S_Z_t; + +#define LSM303AGR_MAG_P_TH_S_Z_MASK 0x20 +mems_status_t LSM303AGR_MAG_R_P_TH_S_Z(void *handle, LSM303AGR_MAG_P_TH_S_Z_t *value); + +/******************************************************************************* +* Register : INT_SOURCE_REG +* Address : 0X64 +* Bit Group Name: P_TH_S_Y +* Permission : RO +*******************************************************************************/ +typedef enum { + LSM303AGR_MAG_P_TH_S_Y_EV_OFF =0x00, + LSM303AGR_MAG_P_TH_S_Y_EV_ON =0x40, +} LSM303AGR_MAG_P_TH_S_Y_t; + +#define LSM303AGR_MAG_P_TH_S_Y_MASK 0x40 +mems_status_t LSM303AGR_MAG_R_P_TH_S_Y(void *handle, LSM303AGR_MAG_P_TH_S_Y_t *value); + +/******************************************************************************* +* Register : INT_SOURCE_REG +* Address : 0X64 +* Bit Group Name: P_TH_S_X +* Permission : RO +*******************************************************************************/ +typedef enum { + LSM303AGR_MAG_P_TH_S_X_EV_OFF =0x00, + LSM303AGR_MAG_P_TH_S_X_EV_ON =0x80, +} LSM303AGR_MAG_P_TH_S_X_t; + +#define LSM303AGR_MAG_P_TH_S_X_MASK 0x80 +mems_status_t LSM303AGR_MAG_R_P_TH_S_X(void *handle, LSM303AGR_MAG_P_TH_S_X_t *value); + +/******************************************************************************* +* Register : STATUS_REG +* Address : 0X67 +* Bit Group Name: XDA +* Permission : RO +*******************************************************************************/ +typedef enum { + LSM303AGR_MAG_XDA_EV_OFF =0x00, + LSM303AGR_MAG_XDA_EV_ON =0x01, +} LSM303AGR_MAG_XDA_t; + +#define LSM303AGR_MAG_XDA_MASK 0x01 +mems_status_t LSM303AGR_MAG_R_XDA(void *handle, LSM303AGR_MAG_XDA_t *value); + +/******************************************************************************* +* Register : STATUS_REG +* Address : 0X67 +* Bit Group Name: YDA +* Permission : RO +*******************************************************************************/ +typedef enum { + LSM303AGR_MAG_YDA_EV_OFF =0x00, + LSM303AGR_MAG_YDA_EV_ON =0x02, +} LSM303AGR_MAG_YDA_t; + +#define LSM303AGR_MAG_YDA_MASK 0x02 +mems_status_t LSM303AGR_MAG_R_YDA(void *handle, LSM303AGR_MAG_YDA_t *value); + +/******************************************************************************* +* Register : STATUS_REG +* Address : 0X67 +* Bit Group Name: ZDA +* Permission : RO +*******************************************************************************/ +typedef enum { + LSM303AGR_MAG_ZDA_EV_OFF =0x00, + LSM303AGR_MAG_ZDA_EV_ON =0x04, +} LSM303AGR_MAG_ZDA_t; + +#define LSM303AGR_MAG_ZDA_MASK 0x04 +mems_status_t LSM303AGR_MAG_R_ZDA(void *handle, LSM303AGR_MAG_ZDA_t *value); + +/******************************************************************************* +* Register : STATUS_REG +* Address : 0X67 +* Bit Group Name: ZYXDA +* Permission : RO +*******************************************************************************/ +typedef enum { + LSM303AGR_MAG_ZYXDA_EV_OFF =0x00, + LSM303AGR_MAG_ZYXDA_EV_ON =0x08, +} LSM303AGR_MAG_ZYXDA_t; + +#define LSM303AGR_MAG_ZYXDA_MASK 0x08 +mems_status_t LSM303AGR_MAG_R_ZYXDA(void *handle, LSM303AGR_MAG_ZYXDA_t *value); + +/******************************************************************************* +* Register : STATUS_REG +* Address : 0X67 +* Bit Group Name: XOR +* Permission : RO +*******************************************************************************/ +typedef enum { + LSM303AGR_MAG_XOR_EV_OFF =0x00, + LSM303AGR_MAG_XOR_EV_ON =0x10, +} LSM303AGR_MAG_XOR_t; + +#define LSM303AGR_MAG_XOR_MASK 0x10 +mems_status_t LSM303AGR_MAG_R_XOR(void *handle, LSM303AGR_MAG_XOR_t *value); + +/******************************************************************************* +* Register : STATUS_REG +* Address : 0X67 +* Bit Group Name: YOR +* Permission : RO +*******************************************************************************/ +typedef enum { + LSM303AGR_MAG_YOR_EV_OFF =0x00, + LSM303AGR_MAG_YOR_EV_ON =0x20, +} LSM303AGR_MAG_YOR_t; + +#define LSM303AGR_MAG_YOR_MASK 0x20 +mems_status_t LSM303AGR_MAG_R_YOR(void *handle, LSM303AGR_MAG_YOR_t *value); + +/******************************************************************************* +* Register : STATUS_REG +* Address : 0X67 +* Bit Group Name: ZOR +* Permission : RO +*******************************************************************************/ +typedef enum { + LSM303AGR_MAG_ZOR_EV_OFF =0x00, + LSM303AGR_MAG_ZOR_EV_ON =0x40, +} LSM303AGR_MAG_ZOR_t; + +#define LSM303AGR_MAG_ZOR_MASK 0x40 +mems_status_t LSM303AGR_MAG_R_ZOR(void *handle, LSM303AGR_MAG_ZOR_t *value); + +/******************************************************************************* +* Register : STATUS_REG +* Address : 0X67 +* Bit Group Name: ZYXOR +* Permission : RO +*******************************************************************************/ +typedef enum { + LSM303AGR_MAG_ZYXOR_EV_OFF =0x00, + LSM303AGR_MAG_ZYXOR_EV_ON =0x80, +} LSM303AGR_MAG_ZYXOR_t; + +#define LSM303AGR_MAG_ZYXOR_MASK 0x80 +mems_status_t LSM303AGR_MAG_R_ZYXOR(void *handle, LSM303AGR_MAG_ZYXOR_t *value); +/******************************************************************************* +* Register : <REGISTER_L> - <REGISTER_H> +* Output Type : Magnetic +* Permission : ro +*******************************************************************************/ +mems_status_t LSM303AGR_MAG_Get_Raw_Magnetic(void *handle, u8_t *buff); +mems_status_t LSM303AGR_MAG_Get_Magnetic(void *handle, int *buff); + +/******************************************************************************* +* Register : <REGISTER_L> - <REGISTER_H> +* Output Type : IntThreshld +* Permission : rw +*******************************************************************************/ +mems_status_t LSM303AGR_MAG_Get_IntThreshld(void *handle, u8_t *buff); +mems_status_t LSM303AGR_MAG_Set_IntThreshld(void *handle, u8_t *buff); + +#ifdef __cplusplus +} +#endif + +#endif
diff -r 000000000000 -r 98c301bb7d1b Components/LSM6DSLSensor/LSM6DSLSensor.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Components/LSM6DSLSensor/LSM6DSLSensor.cpp Tue Oct 03 12:21:11 2017 +0000 @@ -0,0 +1,2129 @@ +/** + ****************************************************************************** + * @file LSM6DSLSensor.cpp + * @author CLab + * @version V1.0.0 + * @date 5 August 2016 + * @brief Implementation of an LSM6DSL Inertial Measurement Unit (IMU) 6 axes + * sensor. + ****************************************************************************** + * @attention + * + * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of STMicroelectronics nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************** + */ + + +/* Includes ------------------------------------------------------------------*/ + +#include "mbed.h" +#include "DevI2C.h" +#include "LSM6DSLSensor.h" +#include "LSM6DSL_acc_gyro_driver.h" + + +/* Class Implementation ------------------------------------------------------*/ + +/** Constructor + * @param i2c object of an helper class which handles the I2C peripheral + * @param address the address of the component's instance + */ +LSM6DSLSensor::LSM6DSLSensor(DevI2C &i2c, PinName int1_pin, PinName int2_pin) : _dev_i2c(i2c), _int1_irq(int1_pin), _int2_irq(int2_pin) +{ + _address = LSM6DSL_ACC_GYRO_I2C_ADDRESS_HIGH; +}; + +/** Constructor + * @param i2c object of an helper class which handles the I2C peripheral + * @param address the address of the component's instance + */ +LSM6DSLSensor::LSM6DSLSensor(DevI2C &i2c, PinName int1_pin, PinName int2_pin, uint8_t address) : _dev_i2c(i2c), _int1_irq(int1_pin), _int2_irq(int2_pin), _address(address) +{ + +}; + +/** + * @brief Initializing the component. + * @param[in] init pointer to device specific initalization structure. + * @retval "0" in case of success, an error code otherwise. + */ +int LSM6DSLSensor::init(void *init) +{ + /* Enable register address automatically incremented during a multiple byte + access with a serial interface. */ + if ( LSM6DSL_ACC_GYRO_W_IF_Addr_Incr( (void *)this, LSM6DSL_ACC_GYRO_IF_INC_ENABLED ) == MEMS_ERROR ) + { + return 1; + } + + /* Enable BDU */ + if ( LSM6DSL_ACC_GYRO_W_BDU( (void *)this, LSM6DSL_ACC_GYRO_BDU_BLOCK_UPDATE ) == MEMS_ERROR ) + { + return 1; + } + + /* FIFO mode selection */ + if ( LSM6DSL_ACC_GYRO_W_FIFO_MODE( (void *)this, LSM6DSL_ACC_GYRO_FIFO_MODE_BYPASS ) == MEMS_ERROR ) + { + return 1; + } + + /* Output data rate selection - power down. */ + if ( LSM6DSL_ACC_GYRO_W_ODR_XL( (void *)this, LSM6DSL_ACC_GYRO_ODR_XL_POWER_DOWN ) == MEMS_ERROR ) + { + return 1; + } + + /* Full scale selection. */ + if ( set_x_fs( 2.0f ) == 1 ) + { + return 1; + } + + /* Output data rate selection - power down */ + if ( LSM6DSL_ACC_GYRO_W_ODR_G( (void *)this, LSM6DSL_ACC_GYRO_ODR_G_POWER_DOWN ) == MEMS_ERROR ) + { + return 1; + } + + /* Full scale selection. */ + if ( set_g_fs( 2000.0f ) == 1 ) + { + return 1; + } + + _x_last_odr = 104.0f; + + _x_is_enabled = 0; + + _g_last_odr = 104.0f; + + _g_is_enabled = 0; + + return 0; +} + +/** + * @brief Enable LSM6DSL Accelerator + * @retval 0 in case of success, an error code otherwise + */ +int LSM6DSLSensor::enable_x(void) +{ + /* Check if the component is already enabled */ + if ( _x_is_enabled == 1 ) + { + return 0; + } + + /* Output data rate selection. */ + if ( set_x_odr_when_enabled( _x_last_odr ) == 1 ) + { + return 1; + } + + _x_is_enabled = 1; + + return 0; +} + +/** + * @brief Enable LSM6DSL Gyroscope + * @retval 0 in case of success, an error code otherwise + */ +int LSM6DSLSensor::enable_g(void) +{ + /* Check if the component is already enabled */ + if ( _g_is_enabled == 1 ) + { + return 0; + } + + /* Output data rate selection. */ + if ( set_g_odr_when_enabled( _g_last_odr ) == 1 ) + { + return 1; + } + + _g_is_enabled = 1; + + return 0; +} + +/** + * @brief Disable LSM6DSL Accelerator + * @retval 0 in case of success, an error code otherwise + */ +int LSM6DSLSensor::disable_x(void) +{ + /* Check if the component is already disabled */ + if ( _x_is_enabled == 0 ) + { + return 0; + } + + /* Store actual output data rate. */ + if ( get_x_odr( &_x_last_odr ) == 1 ) + { + return 1; + } + + /* Output data rate selection - power down. */ + if ( LSM6DSL_ACC_GYRO_W_ODR_XL( (void *)this, LSM6DSL_ACC_GYRO_ODR_XL_POWER_DOWN ) == MEMS_ERROR ) + { + return 1; + } + + _x_is_enabled = 0; + + return 0; +} + +/** + * @brief Disable LSM6DSL Gyroscope + * @retval 0 in case of success, an error code otherwise + */ +int LSM6DSLSensor::disable_g(void) +{ + /* Check if the component is already disabled */ + if ( _g_is_enabled == 0 ) + { + return 0; + } + + /* Store actual output data rate. */ + if ( get_g_odr( &_g_last_odr ) == 1 ) + { + return 1; + } + + /* Output data rate selection - power down */ + if ( LSM6DSL_ACC_GYRO_W_ODR_G( (void *)this, LSM6DSL_ACC_GYRO_ODR_G_POWER_DOWN ) == MEMS_ERROR ) + { + return 1; + } + + _g_is_enabled = 0; + + return 0; +} + +/** + * @brief Read ID of LSM6DSL Accelerometer and Gyroscope + * @param p_id the pointer where the ID of the device is stored + * @retval 0 in case of success, an error code otherwise + */ +int LSM6DSLSensor::read_id(uint8_t *id) +{ + if(!id) + { + return 1; + } + + /* Read WHO AM I register */ + if ( LSM6DSL_ACC_GYRO_R_WHO_AM_I( (void *)this, id ) == MEMS_ERROR ) + { + return 1; + } + + return 0; +} + +/** + * @brief Read data from LSM6DSL Accelerometer + * @param pData the pointer where the accelerometer data are stored + * @retval 0 in case of success, an error code otherwise + */ +int LSM6DSLSensor::get_x_axes(int32_t *pData) +{ + int16_t dataRaw[3]; + float sensitivity = 0; + + /* Read raw data from LSM6DSL output register. */ + if ( get_x_axes_raw( dataRaw ) == 1 ) + { + return 1; + } + + /* Get LSM6DSL actual sensitivity. */ + if ( get_x_sensitivity( &sensitivity ) == 1 ) + { + return 1; + } + + /* Calculate the data. */ + pData[0] = ( int32_t )( dataRaw[0] * sensitivity ); + pData[1] = ( int32_t )( dataRaw[1] * sensitivity ); + pData[2] = ( int32_t )( dataRaw[2] * sensitivity ); + + return 0; +} + +/** + * @brief Read data from LSM6DSL Gyroscope + * @param pData the pointer where the gyroscope data are stored + * @retval 0 in case of success, an error code otherwise + */ +int LSM6DSLSensor::get_g_axes(int32_t *pData) +{ + int16_t dataRaw[3]; + float sensitivity = 0; + + /* Read raw data from LSM6DSL output register. */ + if ( get_g_axes_raw( dataRaw ) == 1 ) + { + return 1; + } + + /* Get LSM6DSL actual sensitivity. */ + if ( get_g_sensitivity( &sensitivity ) == 1 ) + { + return 1; + } + + /* Calculate the data. */ + pData[0] = ( int32_t )( dataRaw[0] * sensitivity ); + pData[1] = ( int32_t )( dataRaw[1] * sensitivity ); + pData[2] = ( int32_t )( dataRaw[2] * sensitivity ); + + return 0; +} + +/** + * @brief Read Accelerometer Sensitivity + * @param pfData the pointer where the accelerometer sensitivity is stored + * @retval 0 in case of success, an error code otherwise + */ +int LSM6DSLSensor::get_x_sensitivity(float *pfData) +{ + LSM6DSL_ACC_GYRO_FS_XL_t fullScale; + + /* Read actual full scale selection from sensor. */ + if ( LSM6DSL_ACC_GYRO_R_FS_XL( (void *)this, &fullScale ) == MEMS_ERROR ) + { + return 1; + } + + /* Store the sensitivity based on actual full scale. */ + switch( fullScale ) + { + case LSM6DSL_ACC_GYRO_FS_XL_2g: + *pfData = ( float )LSM6DSL_ACC_SENSITIVITY_FOR_FS_2G; + break; + case LSM6DSL_ACC_GYRO_FS_XL_4g: + *pfData = ( float )LSM6DSL_ACC_SENSITIVITY_FOR_FS_4G; + break; + case LSM6DSL_ACC_GYRO_FS_XL_8g: + *pfData = ( float )LSM6DSL_ACC_SENSITIVITY_FOR_FS_8G; + break; + case LSM6DSL_ACC_GYRO_FS_XL_16g: + *pfData = ( float )LSM6DSL_ACC_SENSITIVITY_FOR_FS_16G; + break; + default: + *pfData = -1.0f; + return 1; + } + + return 0; +} + +/** + * @brief Read Gyroscope Sensitivity + * @param pfData the pointer where the gyroscope sensitivity is stored + * @retval 0 in case of success, an error code otherwise + */ +int LSM6DSLSensor::get_g_sensitivity(float *pfData) +{ + LSM6DSL_ACC_GYRO_FS_125_t fullScale125; + LSM6DSL_ACC_GYRO_FS_G_t fullScale; + + /* Read full scale 125 selection from sensor. */ + if ( LSM6DSL_ACC_GYRO_R_FS_125( (void *)this, &fullScale125 ) == MEMS_ERROR ) + { + return 1; + } + + if ( fullScale125 == LSM6DSL_ACC_GYRO_FS_125_ENABLED ) + { + *pfData = ( float )LSM6DSL_GYRO_SENSITIVITY_FOR_FS_125DPS; + } + + else + { + + /* Read actual full scale selection from sensor. */ + if ( LSM6DSL_ACC_GYRO_R_FS_G( (void *)this, &fullScale ) == MEMS_ERROR ) + { + return 1; + } + + /* Store the sensitivity based on actual full scale. */ + switch( fullScale ) + { + case LSM6DSL_ACC_GYRO_FS_G_245dps: + *pfData = ( float )LSM6DSL_GYRO_SENSITIVITY_FOR_FS_245DPS; + break; + case LSM6DSL_ACC_GYRO_FS_G_500dps: + *pfData = ( float )LSM6DSL_GYRO_SENSITIVITY_FOR_FS_500DPS; + break; + case LSM6DSL_ACC_GYRO_FS_G_1000dps: + *pfData = ( float )LSM6DSL_GYRO_SENSITIVITY_FOR_FS_1000DPS; + break; + case LSM6DSL_ACC_GYRO_FS_G_2000dps: + *pfData = ( float )LSM6DSL_GYRO_SENSITIVITY_FOR_FS_2000DPS; + break; + default: + *pfData = -1.0f; + return 1; + } + } + + return 0; +} + +/** + * @brief Read raw data from LSM6DSL Accelerometer + * @param pData the pointer where the accelerometer raw data are stored + * @retval 0 in case of success, an error code otherwise + */ +int LSM6DSLSensor::get_x_axes_raw(int16_t *pData) +{ + uint8_t regValue[6] = {0, 0, 0, 0, 0, 0}; + + /* Read output registers from LSM6DSL_ACC_GYRO_OUTX_L_XL to LSM6DSL_ACC_GYRO_OUTZ_H_XL. */ + if ( LSM6DSL_ACC_GYRO_GetRawAccData( (void *)this, regValue ) == MEMS_ERROR ) + { + return 1; + } + + /* Format the data. */ + pData[0] = ( ( ( ( int16_t )regValue[1] ) << 8 ) + ( int16_t )regValue[0] ); + pData[1] = ( ( ( ( int16_t )regValue[3] ) << 8 ) + ( int16_t )regValue[2] ); + pData[2] = ( ( ( ( int16_t )regValue[5] ) << 8 ) + ( int16_t )regValue[4] ); + + return 0; +} + +/** + * @brief Read raw data from LSM6DSL Gyroscope + * @param pData the pointer where the gyroscope raw data are stored + * @retval 0 in case of success, an error code otherwise + */ +int LSM6DSLSensor::get_g_axes_raw(int16_t *pData) +{ + uint8_t regValue[6] = {0, 0, 0, 0, 0, 0}; + + /* Read output registers from LSM6DSL_ACC_GYRO_OUTX_L_G to LSM6DSL_ACC_GYRO_OUTZ_H_G. */ + if ( LSM6DSL_ACC_GYRO_GetRawGyroData( (void *)this, regValue ) == MEMS_ERROR ) + { + return 1; + } + + /* Format the data. */ + pData[0] = ( ( ( ( int16_t )regValue[1] ) << 8 ) + ( int16_t )regValue[0] ); + pData[1] = ( ( ( ( int16_t )regValue[3] ) << 8 ) + ( int16_t )regValue[2] ); + pData[2] = ( ( ( ( int16_t )regValue[5] ) << 8 ) + ( int16_t )regValue[4] ); + + return 0; +} + +/** + * @brief Read LSM6DSL Accelerometer output data rate + * @param odr the pointer to the output data rate + * @retval 0 in case of success, an error code otherwise + */ +int LSM6DSLSensor::get_x_odr(float* odr) +{ + LSM6DSL_ACC_GYRO_ODR_XL_t odr_low_level; + + if ( LSM6DSL_ACC_GYRO_R_ODR_XL( (void *)this, &odr_low_level ) == MEMS_ERROR ) + { + return 1; + } + + switch( odr_low_level ) + { + case LSM6DSL_ACC_GYRO_ODR_XL_POWER_DOWN: + *odr = 0.0f; + break; + case LSM6DSL_ACC_GYRO_ODR_XL_13Hz: + *odr = 13.0f; + break; + case LSM6DSL_ACC_GYRO_ODR_XL_26Hz: + *odr = 26.0f; + break; + case LSM6DSL_ACC_GYRO_ODR_XL_52Hz: + *odr = 52.0f; + break; + case LSM6DSL_ACC_GYRO_ODR_XL_104Hz: + *odr = 104.0f; + break; + case LSM6DSL_ACC_GYRO_ODR_XL_208Hz: + *odr = 208.0f; + break; + case LSM6DSL_ACC_GYRO_ODR_XL_416Hz: + *odr = 416.0f; + break; + case LSM6DSL_ACC_GYRO_ODR_XL_833Hz: + *odr = 833.0f; + break; + case LSM6DSL_ACC_GYRO_ODR_XL_1660Hz: + *odr = 1660.0f; + break; + case LSM6DSL_ACC_GYRO_ODR_XL_3330Hz: + *odr = 3330.0f; + break; + case LSM6DSL_ACC_GYRO_ODR_XL_6660Hz: + *odr = 6660.0f; + break; + default: + *odr = -1.0f; + return 1; + } + + return 0; +} + +/** + * @brief Read LSM6DSL Gyroscope output data rate + * @param odr the pointer to the output data rate + * @retval 0 in case of success, an error code otherwise + */ +int LSM6DSLSensor::get_g_odr(float* odr) +{ + LSM6DSL_ACC_GYRO_ODR_G_t odr_low_level; + + if ( LSM6DSL_ACC_GYRO_R_ODR_G( (void *)this, &odr_low_level ) == MEMS_ERROR ) + { + return 1; + } + + switch( odr_low_level ) + { + case LSM6DSL_ACC_GYRO_ODR_G_POWER_DOWN: + *odr = 0.0f; + break; + case LSM6DSL_ACC_GYRO_ODR_G_13Hz: + *odr = 13.0f; + break; + case LSM6DSL_ACC_GYRO_ODR_G_26Hz: + *odr = 26.0f; + break; + case LSM6DSL_ACC_GYRO_ODR_G_52Hz: + *odr = 52.0f; + break; + case LSM6DSL_ACC_GYRO_ODR_G_104Hz: + *odr = 104.0f; + break; + case LSM6DSL_ACC_GYRO_ODR_G_208Hz: + *odr = 208.0f; + break; + case LSM6DSL_ACC_GYRO_ODR_G_416Hz: + *odr = 416.0f; + break; + case LSM6DSL_ACC_GYRO_ODR_G_833Hz: + *odr = 833.0f; + break; + case LSM6DSL_ACC_GYRO_ODR_G_1660Hz: + *odr = 1660.0f; + break; + case LSM6DSL_ACC_GYRO_ODR_G_3330Hz: + *odr = 3330.0f; + break; + case LSM6DSL_ACC_GYRO_ODR_G_6660Hz: + *odr = 6660.0f; + break; + default: + *odr = -1.0f; + return 1; + } + + return 0; +} + +/** + * @brief Set LSM6DSL Accelerometer output data rate + * @param odr the output data rate to be set + * @retval 0 in case of success, an error code otherwise + */ +int LSM6DSLSensor::set_x_odr(float odr) +{ + if(_x_is_enabled == 1) + { + if(set_x_odr_when_enabled(odr) == 1) + { + return 1; + } + } + else + { + if(set_x_odr_when_disabled(odr) == 1) + { + return 1; + } + } + + return 0; +} + +/** + * @brief Set LSM6DSL Accelerometer output data rate when enabled + * @param odr the output data rate to be set + * @retval 0 in case of success, an error code otherwise + */ +int LSM6DSLSensor::set_x_odr_when_enabled(float odr) +{ + LSM6DSL_ACC_GYRO_ODR_XL_t new_odr; + + new_odr = ( odr <= 13.0f ) ? LSM6DSL_ACC_GYRO_ODR_XL_13Hz + : ( odr <= 26.0f ) ? LSM6DSL_ACC_GYRO_ODR_XL_26Hz + : ( odr <= 52.0f ) ? LSM6DSL_ACC_GYRO_ODR_XL_52Hz + : ( odr <= 104.0f ) ? LSM6DSL_ACC_GYRO_ODR_XL_104Hz + : ( odr <= 208.0f ) ? LSM6DSL_ACC_GYRO_ODR_XL_208Hz + : ( odr <= 416.0f ) ? LSM6DSL_ACC_GYRO_ODR_XL_416Hz + : ( odr <= 833.0f ) ? LSM6DSL_ACC_GYRO_ODR_XL_833Hz + : ( odr <= 1660.0f ) ? LSM6DSL_ACC_GYRO_ODR_XL_1660Hz + : ( odr <= 3330.0f ) ? LSM6DSL_ACC_GYRO_ODR_XL_3330Hz + : LSM6DSL_ACC_GYRO_ODR_XL_6660Hz; + + if ( LSM6DSL_ACC_GYRO_W_ODR_XL( (void *)this, new_odr ) == MEMS_ERROR ) + { + return 1; + } + + return 0; +} + +/** + * @brief Set LSM6DSL Accelerometer output data rate when disabled + * @param odr the output data rate to be set + * @retval 0 in case of success, an error code otherwise + */ +int LSM6DSLSensor::set_x_odr_when_disabled(float odr) +{ + _x_last_odr = ( odr <= 13.0f ) ? 13.0f + : ( odr <= 26.0f ) ? 26.0f + : ( odr <= 52.0f ) ? 52.0f + : ( odr <= 104.0f ) ? 104.0f + : ( odr <= 208.0f ) ? 208.0f + : ( odr <= 416.0f ) ? 416.0f + : ( odr <= 833.0f ) ? 833.0f + : ( odr <= 1660.0f ) ? 1660.0f + : ( odr <= 3330.0f ) ? 3330.0f + : 6660.0f; + + return 0; +} + +/** + * @brief Set LSM6DSL Gyroscope output data rate + * @param odr the output data rate to be set + * @retval 0 in case of success, an error code otherwise + */ +int LSM6DSLSensor::set_g_odr(float odr) +{ + if(_g_is_enabled == 1) + { + if(set_g_odr_when_enabled(odr) == 1) + { + return 1; + } + } + else + { + if(set_g_odr_when_disabled(odr) == 1) + { + return 1; + } + } + + return 0; +} + +/** + * @brief Set LSM6DSL Gyroscope output data rate when enabled + * @param odr the output data rate to be set + * @retval 0 in case of success, an error code otherwise + */ +int LSM6DSLSensor::set_g_odr_when_enabled(float odr) +{ + LSM6DSL_ACC_GYRO_ODR_G_t new_odr; + + new_odr = ( odr <= 13.0f ) ? LSM6DSL_ACC_GYRO_ODR_G_13Hz + : ( odr <= 26.0f ) ? LSM6DSL_ACC_GYRO_ODR_G_26Hz + : ( odr <= 52.0f ) ? LSM6DSL_ACC_GYRO_ODR_G_52Hz + : ( odr <= 104.0f ) ? LSM6DSL_ACC_GYRO_ODR_G_104Hz + : ( odr <= 208.0f ) ? LSM6DSL_ACC_GYRO_ODR_G_208Hz + : ( odr <= 416.0f ) ? LSM6DSL_ACC_GYRO_ODR_G_416Hz + : ( odr <= 833.0f ) ? LSM6DSL_ACC_GYRO_ODR_G_833Hz + : ( odr <= 1660.0f ) ? LSM6DSL_ACC_GYRO_ODR_G_1660Hz + : ( odr <= 3330.0f ) ? LSM6DSL_ACC_GYRO_ODR_G_3330Hz + : LSM6DSL_ACC_GYRO_ODR_G_6660Hz; + + if ( LSM6DSL_ACC_GYRO_W_ODR_G( (void *)this, new_odr ) == MEMS_ERROR ) + { + return 1; + } + + return 0; +} + +/** + * @brief Set LSM6DSL Gyroscope output data rate when disabled + * @param odr the output data rate to be set + * @retval 0 in case of success, an error code otherwise + */ +int LSM6DSLSensor::set_g_odr_when_disabled(float odr) +{ + _g_last_odr = ( odr <= 13.0f ) ? 13.0f + : ( odr <= 26.0f ) ? 26.0f + : ( odr <= 52.0f ) ? 52.0f + : ( odr <= 104.0f ) ? 104.0f + : ( odr <= 208.0f ) ? 208.0f + : ( odr <= 416.0f ) ? 416.0f + : ( odr <= 833.0f ) ? 833.0f + : ( odr <= 1660.0f ) ? 1660.0f + : ( odr <= 3330.0f ) ? 3330.0f + : 6660.0f; + + return 0; +} + +/** + * @brief Read LSM6DSL Accelerometer full scale + * @param fullScale the pointer to the full scale + * @retval 0 in case of success, an error code otherwise + */ +int LSM6DSLSensor::get_x_fs(float* fullScale) +{ + LSM6DSL_ACC_GYRO_FS_XL_t fs_low_level; + + if ( LSM6DSL_ACC_GYRO_R_FS_XL( (void *)this, &fs_low_level ) == MEMS_ERROR ) + { + return 1; + } + + switch( fs_low_level ) + { + case LSM6DSL_ACC_GYRO_FS_XL_2g: + *fullScale = 2.0f; + break; + case LSM6DSL_ACC_GYRO_FS_XL_4g: + *fullScale = 4.0f; + break; + case LSM6DSL_ACC_GYRO_FS_XL_8g: + *fullScale = 8.0f; + break; + case LSM6DSL_ACC_GYRO_FS_XL_16g: + *fullScale = 16.0f; + break; + default: + *fullScale = -1.0f; + return 1; + } + + return 0; +} + +/** + * @brief Read LSM6DSL Gyroscope full scale + * @param fullScale the pointer to the full scale + * @retval 0 in case of success, an error code otherwise + */ +int LSM6DSLSensor::get_g_fs(float* fullScale) +{ + LSM6DSL_ACC_GYRO_FS_G_t fs_low_level; + LSM6DSL_ACC_GYRO_FS_125_t fs_125; + + if ( LSM6DSL_ACC_GYRO_R_FS_125( (void *)this, &fs_125 ) == MEMS_ERROR ) + { + return 1; + } + if ( LSM6DSL_ACC_GYRO_R_FS_G( (void *)this, &fs_low_level ) == MEMS_ERROR ) + { + return 1; + } + + if ( fs_125 == LSM6DSL_ACC_GYRO_FS_125_ENABLED ) + { + *fullScale = 125.0f; + } + + else + { + switch( fs_low_level ) + { + case LSM6DSL_ACC_GYRO_FS_G_245dps: + *fullScale = 245.0f; + break; + case LSM6DSL_ACC_GYRO_FS_G_500dps: + *fullScale = 500.0f; + break; + case LSM6DSL_ACC_GYRO_FS_G_1000dps: + *fullScale = 1000.0f; + break; + case LSM6DSL_ACC_GYRO_FS_G_2000dps: + *fullScale = 2000.0f; + break; + default: + *fullScale = -1.0f; + return 1; + } + } + + return 0; +} + +/** + * @brief Set LSM6DSL Accelerometer full scale + * @param fullScale the full scale to be set + * @retval 0 in case of success, an error code otherwise + */ +int LSM6DSLSensor::set_x_fs(float fullScale) +{ + LSM6DSL_ACC_GYRO_FS_XL_t new_fs; + + new_fs = ( fullScale <= 2.0f ) ? LSM6DSL_ACC_GYRO_FS_XL_2g + : ( fullScale <= 4.0f ) ? LSM6DSL_ACC_GYRO_FS_XL_4g + : ( fullScale <= 8.0f ) ? LSM6DSL_ACC_GYRO_FS_XL_8g + : LSM6DSL_ACC_GYRO_FS_XL_16g; + + if ( LSM6DSL_ACC_GYRO_W_FS_XL( (void *)this, new_fs ) == MEMS_ERROR ) + { + return 1; + } + + return 0; +} + +/** + * @brief Set LSM6DSL Gyroscope full scale + * @param fullScale the full scale to be set + * @retval 0 in case of success, an error code otherwise + */ +int LSM6DSLSensor::set_g_fs(float fullScale) +{ + LSM6DSL_ACC_GYRO_FS_G_t new_fs; + + if ( fullScale <= 125.0f ) + { + if ( LSM6DSL_ACC_GYRO_W_FS_125( (void *)this, LSM6DSL_ACC_GYRO_FS_125_ENABLED ) == MEMS_ERROR ) + { + return 1; + } + } + else + { + new_fs = ( fullScale <= 245.0f ) ? LSM6DSL_ACC_GYRO_FS_G_245dps + : ( fullScale <= 500.0f ) ? LSM6DSL_ACC_GYRO_FS_G_500dps + : ( fullScale <= 1000.0f ) ? LSM6DSL_ACC_GYRO_FS_G_1000dps + : LSM6DSL_ACC_GYRO_FS_G_2000dps; + + if ( LSM6DSL_ACC_GYRO_W_FS_125( (void *)this, LSM6DSL_ACC_GYRO_FS_125_DISABLED ) == MEMS_ERROR ) + { + return 1; + } + if ( LSM6DSL_ACC_GYRO_W_FS_G( (void *)this, new_fs ) == MEMS_ERROR ) + { + return 1; + } + } + + return 0; +} + +/** + * @brief Enable free fall detection + * @param pin the interrupt pin to be used + * @note This function sets the LSM6DSL accelerometer ODR to 416Hz and the LSM6DSL accelerometer full scale to 2g + * @retval 0 in case of success, an error code otherwise +*/ +int LSM6DSLSensor::enable_free_fall_detection(LSM6DSL_Interrupt_Pin_t pin) +{ + /* Output Data Rate selection */ + if(set_x_odr(416.0f) == 1) + { + return 1; + } + + /* Full scale selection */ + if ( LSM6DSL_ACC_GYRO_W_FS_XL( (void *)this, LSM6DSL_ACC_GYRO_FS_XL_2g ) == MEMS_ERROR ) + { + return 1; + } + + /* FF_DUR setting */ + if ( LSM6DSL_ACC_GYRO_W_FF_Duration( (void *)this, 0x06 ) == MEMS_ERROR ) + { + return 1; + } + + /* WAKE_DUR setting */ + if ( LSM6DSL_ACC_GYRO_W_WAKE_DUR( (void *)this, 0x00 ) == MEMS_ERROR ) + { + return 1; + } + + /* TIMER_HR setting */ + if ( LSM6DSL_ACC_GYRO_W_TIMER_HR( (void *)this, LSM6DSL_ACC_GYRO_TIMER_HR_6_4ms ) == MEMS_ERROR ) + { + return 1; + } + + /* SLEEP_DUR setting */ + if ( LSM6DSL_ACC_GYRO_W_SLEEP_DUR( (void *)this, 0x00 ) == MEMS_ERROR ) + { + return 1; + } + + /* FF_THS setting */ + if ( LSM6DSL_ACC_GYRO_W_FF_THS( (void *)this, LSM6DSL_ACC_GYRO_FF_THS_312mg ) == MEMS_ERROR ) + { + return 1; + } + + /* Enable basic Interrupts */ + if ( LSM6DSL_ACC_GYRO_W_BASIC_INT( (void *)this, LSM6DSL_ACC_GYRO_BASIC_INT_ENABLED ) == MEMS_ERROR ) + { + return 1; + } + + /* Enable free fall event on either INT1 or INT2 pin */ + switch (pin) + { + case LSM6DSL_INT1_PIN: + if ( LSM6DSL_ACC_GYRO_W_FFEvOnInt1( (void *)this, LSM6DSL_ACC_GYRO_INT1_FF_ENABLED ) == MEMS_ERROR ) + { + return 1; + } + break; + + case LSM6DSL_INT2_PIN: + if ( LSM6DSL_ACC_GYRO_W_FFEvOnInt2( (void *)this, LSM6DSL_ACC_GYRO_INT2_FF_ENABLED ) == MEMS_ERROR ) + { + return 1; + } + break; + + default: + return 1; + } + + return 0; +} + +/** + * @brief Disable free fall detection + * @param None + * @retval 0 in case of success, an error code otherwise +*/ +int LSM6DSLSensor::disable_free_fall_detection(void) +{ + /* Disable free fall event on INT1 pin */ + if ( LSM6DSL_ACC_GYRO_W_FFEvOnInt1( (void *)this, LSM6DSL_ACC_GYRO_INT1_FF_DISABLED ) == MEMS_ERROR ) + { + return 1; + } + + /* Disable free fall event on INT2 pin */ + if ( LSM6DSL_ACC_GYRO_W_FFEvOnInt2( (void *)this, LSM6DSL_ACC_GYRO_INT2_FF_DISABLED ) == MEMS_ERROR ) + { + return 1; + } + + /* Disable basic Interrupts */ + if ( LSM6DSL_ACC_GYRO_W_BASIC_INT( (void *)this, LSM6DSL_ACC_GYRO_BASIC_INT_DISABLED ) == MEMS_ERROR ) + { + return 1; + } + + /* FF_DUR setting */ + if ( LSM6DSL_ACC_GYRO_W_FF_Duration( (void *)this, 0x00 ) == MEMS_ERROR ) + { + return 1; + } + + /* FF_THS setting */ + if ( LSM6DSL_ACC_GYRO_W_FF_THS( (void *)this, LSM6DSL_ACC_GYRO_FF_THS_156mg ) == MEMS_ERROR ) + { + return 1; + } + + return 0; +} + +/** + * @brief Set the free fall detection threshold for LSM6DSL accelerometer sensor + * @param thr the threshold to be set + * @retval 0 in case of success, an error code otherwise + */ +int LSM6DSLSensor::set_free_fall_threshold(uint8_t thr) +{ + + if ( LSM6DSL_ACC_GYRO_W_FF_THS( (void *)this, (LSM6DSL_ACC_GYRO_FF_THS_t)thr ) == MEMS_ERROR ) + { + return 1; + } + + return 0; +} + +/** + * @brief Enable the pedometer feature for LSM6DSL accelerometer sensor + * @note This function sets the LSM6DSL accelerometer ODR to 26Hz and the LSM6DSL accelerometer full scale to 2g + * @retval 0 in case of success, an error code otherwise + */ +int LSM6DSLSensor::enable_pedometer(void) +{ + /* Output Data Rate selection */ + if( set_x_odr(26.0f) == 1 ) + { + return 1; + } + + /* Full scale selection. */ + if( set_x_fs(2.0f) == 1 ) + { + return 1; + } + + /* Set pedometer threshold. */ + if ( set_pedometer_threshold(LSM6DSL_PEDOMETER_THRESHOLD_MID_HIGH) == 1 ) + { + return 1; + } + + /* Enable embedded functionalities. */ + if ( LSM6DSL_ACC_GYRO_W_FUNC_EN( (void *)this, LSM6DSL_ACC_GYRO_FUNC_EN_ENABLED ) == MEMS_ERROR ) + { + return 1; + } + + /* Enable pedometer algorithm. */ + if ( LSM6DSL_ACC_GYRO_W_PEDO( (void *)this, LSM6DSL_ACC_GYRO_PEDO_ENABLED ) == MEMS_ERROR ) + { + return 1; + } + + /* Enable pedometer on INT1. */ + if ( LSM6DSL_ACC_GYRO_W_STEP_DET_on_INT1( (void *)this, LSM6DSL_ACC_GYRO_INT1_PEDO_ENABLED ) == MEMS_ERROR ) + { + return 1; + } + + return 0; +} + +/** + * @brief Disable the pedometer feature for LSM6DSL accelerometer sensor + * @retval 0 in case of success, an error code otherwise + */ +int LSM6DSLSensor::disable_pedometer(void) +{ + /* Disable pedometer on INT1. */ + if ( LSM6DSL_ACC_GYRO_W_STEP_DET_on_INT1( (void *)this, LSM6DSL_ACC_GYRO_INT1_PEDO_DISABLED ) == MEMS_ERROR ) + { + return 1; + } + + /* Disable pedometer algorithm. */ + if ( LSM6DSL_ACC_GYRO_W_PEDO( (void *)this, LSM6DSL_ACC_GYRO_PEDO_DISABLED ) == MEMS_ERROR ) + { + return 1; + } + + /* Disable embedded functionalities. */ + if ( LSM6DSL_ACC_GYRO_W_FUNC_EN( (void *)this, LSM6DSL_ACC_GYRO_FUNC_EN_DISABLED ) == MEMS_ERROR ) + { + return 1; + } + + /* Reset pedometer threshold. */ + if ( set_pedometer_threshold(0x0) == 1 ) + { + return 1; + } + + return 0; +} + +/** + * @brief Get the step counter for LSM6DSL accelerometer sensor + * @param step_count the pointer to the step counter + * @retval 0 in case of success, an error code otherwise + */ +int LSM6DSLSensor::get_step_counter(uint16_t *step_count) +{ + if ( LSM6DSL_ACC_GYRO_Get_GetStepCounter( (void *)this, ( uint8_t* )step_count ) == MEMS_ERROR ) + { + return 1; + } + + return 0; +} + +/** + * @brief Reset of the step counter for LSM6DSL accelerometer sensor + * @retval 0 in case of success, an error code otherwise + */ +int LSM6DSLSensor::reset_step_counter(void) +{ + if ( LSM6DSL_ACC_GYRO_W_PedoStepReset( (void *)this, LSM6DSL_ACC_GYRO_PEDO_RST_STEP_ENABLED ) == MEMS_ERROR ) + { + return 1; + } + + wait_ms(10); + + if ( LSM6DSL_ACC_GYRO_W_PedoStepReset( (void *)this, LSM6DSL_ACC_GYRO_PEDO_RST_STEP_DISABLED ) == MEMS_ERROR ) + { + return 1; + } + + return 0; +} + +/** + * @brief Set the pedometer threshold for LSM6DSL accelerometer sensor + * @param thr the threshold to be set + * @retval 0 in case of success, an error code otherwise + */ +int LSM6DSLSensor::set_pedometer_threshold(uint8_t thr) +{ + if ( LSM6DSL_ACC_GYRO_W_PedoThreshold( (void *)this, thr ) == MEMS_ERROR ) + { + return 1; + } + + return 0; +} + +/** + * @brief Enable the tilt detection for LSM6DSL accelerometer sensor + * @param pin the interrupt pin to be used + * @note This function sets the LSM6DSL accelerometer ODR to 26Hz and the LSM6DSL accelerometer full scale to 2g + * @retval 0 in case of success, an error code otherwise + */ +int LSM6DSLSensor::enable_tilt_detection(LSM6DSL_Interrupt_Pin_t pin) +{ + /* Output Data Rate selection */ + if( set_x_odr(26.0f) == 1 ) + { + return 1; + } + + /* Full scale selection. */ + if( set_x_fs(2.0f) == 1 ) + { + return 1; + } + + /* Enable embedded functionalities */ + if ( LSM6DSL_ACC_GYRO_W_FUNC_EN( (void *)this, LSM6DSL_ACC_GYRO_FUNC_EN_ENABLED ) == MEMS_ERROR ) + { + return 1; + } + + /* Enable tilt calculation. */ + if ( LSM6DSL_ACC_GYRO_W_TILT( (void *)this, LSM6DSL_ACC_GYRO_TILT_ENABLED ) == MEMS_ERROR ) + { + return 1; + } + + /* Enable tilt detection on either INT1 or INT2 pin */ + switch (pin) + { + case LSM6DSL_INT1_PIN: + if ( LSM6DSL_ACC_GYRO_W_TiltEvOnInt1( (void *)this, LSM6DSL_ACC_GYRO_INT1_TILT_ENABLED ) == MEMS_ERROR ) + { + return 1; + } + break; + + case LSM6DSL_INT2_PIN: + if ( LSM6DSL_ACC_GYRO_W_TiltEvOnInt2( (void *)this, LSM6DSL_ACC_GYRO_INT2_TILT_ENABLED ) == MEMS_ERROR ) + { + return 1; + } + break; + + default: + return 1; + } + + return 0; +} + +/** + * @brief Disable the tilt detection for LSM6DSL accelerometer sensor + * @retval 0 in case of success, an error code otherwise + */ +int LSM6DSLSensor::disable_tilt_detection(void) +{ + /* Disable tilt event on INT1. */ + if ( LSM6DSL_ACC_GYRO_W_TiltEvOnInt1( (void *)this, LSM6DSL_ACC_GYRO_INT1_TILT_DISABLED ) == MEMS_ERROR ) + { + return 1; + } + + /* Disable tilt event on INT2. */ + if ( LSM6DSL_ACC_GYRO_W_TiltEvOnInt2( (void *)this, LSM6DSL_ACC_GYRO_INT2_TILT_DISABLED ) == MEMS_ERROR ) + { + return 1; + } + + /* Disable tilt calculation. */ + if ( LSM6DSL_ACC_GYRO_W_TILT( (void *)this, LSM6DSL_ACC_GYRO_TILT_DISABLED ) == MEMS_ERROR ) + { + return 1; + } + + /* Disable embedded functionalities */ + if ( LSM6DSL_ACC_GYRO_W_FUNC_EN( (void *)this, LSM6DSL_ACC_GYRO_FUNC_EN_DISABLED ) == MEMS_ERROR ) + { + return 1; + } + + return 0; +} + +/** + * @brief Enable the wake up detection for LSM6DSL accelerometer sensor + * @param pin the interrupt pin to be used + * @note This function sets the LSM6DSL accelerometer ODR to 416Hz and the LSM6DSL accelerometer full scale to 2g + * @retval 0 in case of success, an error code otherwise + */ +int LSM6DSLSensor::enable_wake_up_detection(LSM6DSL_Interrupt_Pin_t pin) +{ + /* Output Data Rate selection */ + if( set_x_odr(416.0f) == 1 ) + { + return 1; + } + + /* Full scale selection. */ + if( set_x_fs(2.0f) == 1 ) + { + return 1; + } + + /* WAKE_DUR setting */ + if ( LSM6DSL_ACC_GYRO_W_WAKE_DUR( (void *)this, 0x00 ) == MEMS_ERROR ) + { + return 1; + } + + /* Set wake up threshold. */ + if ( LSM6DSL_ACC_GYRO_W_WK_THS( (void *)this, 0x02 ) == MEMS_ERROR ) + { + return 1; + } + + /* Enable basic Interrupts */ + if ( LSM6DSL_ACC_GYRO_W_BASIC_INT( (void *)this, LSM6DSL_ACC_GYRO_BASIC_INT_ENABLED ) == MEMS_ERROR ) + { + return 1; + } + + /* Enable wake up detection on either INT1 or INT2 pin */ + switch (pin) + { + case LSM6DSL_INT1_PIN: + if ( LSM6DSL_ACC_GYRO_W_WUEvOnInt1( (void *)this, LSM6DSL_ACC_GYRO_INT1_WU_ENABLED ) == MEMS_ERROR ) + { + return 1; + } + break; + + case LSM6DSL_INT2_PIN: + if ( LSM6DSL_ACC_GYRO_W_WUEvOnInt2( (void *)this, LSM6DSL_ACC_GYRO_INT2_WU_ENABLED ) == MEMS_ERROR ) + { + return 1; + } + break; + + default: + return 1; + } + + return 0; +} + +/** + * @brief Disable the wake up detection for LSM6DSL accelerometer sensor + * @retval 0 in case of success, an error code otherwise + */ +int LSM6DSLSensor::disable_wake_up_detection(void) +{ + /* Disable wake up event on INT1 */ + if ( LSM6DSL_ACC_GYRO_W_WUEvOnInt1( (void *)this, LSM6DSL_ACC_GYRO_INT1_WU_DISABLED ) == MEMS_ERROR ) + { + return 1; + } + + /* Disable wake up event on INT2 */ + if ( LSM6DSL_ACC_GYRO_W_WUEvOnInt2( (void *)this, LSM6DSL_ACC_GYRO_INT2_WU_DISABLED ) == MEMS_ERROR ) + { + return 1; + } + + /* Disable basic Interrupts */ + if ( LSM6DSL_ACC_GYRO_W_BASIC_INT( (void *)this, LSM6DSL_ACC_GYRO_BASIC_INT_DISABLED ) == MEMS_ERROR ) + { + return 1; + } + + /* WU_DUR setting */ + if ( LSM6DSL_ACC_GYRO_W_WAKE_DUR( (void *)this, 0x00 ) == MEMS_ERROR ) + { + return 1; + } + + /* WU_THS setting */ + if ( LSM6DSL_ACC_GYRO_W_WK_THS( (void *)this, 0x00 ) == MEMS_ERROR ) + { + return 1; + } + + return 0; +} + +/** + * @brief Set the wake up threshold for LSM6DSL accelerometer sensor + * @param thr the threshold to be set + * @retval 0 in case of success, an error code otherwise + */ +int LSM6DSLSensor::set_wake_up_threshold(uint8_t thr) +{ + if ( LSM6DSL_ACC_GYRO_W_WK_THS( (void *)this, thr ) == MEMS_ERROR ) + { + return 1; + } + + return 0; +} + +/** + * @brief Enable the single tap detection for LSM6DSL accelerometer sensor + * @param pin the interrupt pin to be used + * @note This function sets the LSM6DSL accelerometer ODR to 416Hz and the LSM6DSL accelerometer full scale to 2g + * @retval 0 in case of success, an error code otherwise + */ +int LSM6DSLSensor::enable_single_tap_detection(LSM6DSL_Interrupt_Pin_t pin) +{ + /* Output Data Rate selection */ + if( set_x_odr(416.0f) == 1 ) + { + return 1; + } + + /* Full scale selection. */ + if( set_x_fs(2.0f) == 1 ) + { + return 1; + } + + /* Enable X direction in tap recognition. */ + if ( LSM6DSL_ACC_GYRO_W_TAP_X_EN( (void *)this, LSM6DSL_ACC_GYRO_TAP_X_EN_ENABLED ) == MEMS_ERROR ) + { + return 1; + } + + /* Enable Y direction in tap recognition. */ + if ( LSM6DSL_ACC_GYRO_W_TAP_Y_EN( (void *)this, LSM6DSL_ACC_GYRO_TAP_Y_EN_ENABLED ) == MEMS_ERROR ) + { + return 1; + } + + /* Enable Z direction in tap recognition. */ + if ( LSM6DSL_ACC_GYRO_W_TAP_Z_EN( (void *)this, LSM6DSL_ACC_GYRO_TAP_Z_EN_ENABLED ) == MEMS_ERROR ) + { + return 1; + } + + /* Set tap threshold. */ + if ( set_tap_threshold( LSM6DSL_TAP_THRESHOLD_MID_LOW ) == 1 ) + { + return 1; + } + + /* Set tap shock time window. */ + if ( set_tap_shock_time( LSM6DSL_TAP_SHOCK_TIME_MID_HIGH ) == 1 ) + { + return 1; + } + + /* Set tap quiet time window. */ + if ( set_tap_quiet_time( LSM6DSL_TAP_QUIET_TIME_MID_LOW ) == 1 ) + { + return 1; + } + + /* _NOTE_: Tap duration time window - don't care for single tap. */ + + /* _NOTE_: Single/Double Tap event - don't care of this flag for single tap. */ + + /* Enable basic Interrupts */ + if ( LSM6DSL_ACC_GYRO_W_BASIC_INT( (void *)this, LSM6DSL_ACC_GYRO_BASIC_INT_ENABLED ) == MEMS_ERROR ) + { + return 1; + } + + /* Enable single tap on either INT1 or INT2 pin */ + switch (pin) + { + case LSM6DSL_INT1_PIN: + if ( LSM6DSL_ACC_GYRO_W_SingleTapOnInt1( (void *)this, LSM6DSL_ACC_GYRO_INT1_SINGLE_TAP_ENABLED ) == MEMS_ERROR ) + { + return 1; + } + break; + + case LSM6DSL_INT2_PIN: + if ( LSM6DSL_ACC_GYRO_W_SingleTapOnInt2( (void *)this, LSM6DSL_ACC_GYRO_INT2_SINGLE_TAP_ENABLED ) == MEMS_ERROR ) + { + return 1; + } + break; + + default: + return 1; + } + + return 0; +} + +/** + * @brief Disable the single tap detection for LSM6DSL accelerometer sensor + * @retval 0 in case of success, an error code otherwise + */ +int LSM6DSLSensor::disable_single_tap_detection(void) +{ + /* Disable single tap interrupt on INT1 pin. */ + if ( LSM6DSL_ACC_GYRO_W_SingleTapOnInt1( (void *)this, LSM6DSL_ACC_GYRO_INT1_SINGLE_TAP_DISABLED ) == MEMS_ERROR ) + { + return 1; + } + + /* Disable single tap interrupt on INT2 pin. */ + if ( LSM6DSL_ACC_GYRO_W_SingleTapOnInt2( (void *)this, LSM6DSL_ACC_GYRO_INT2_SINGLE_TAP_DISABLED ) == MEMS_ERROR ) + { + return 1; + } + + /* Disable basic Interrupts */ + if ( LSM6DSL_ACC_GYRO_W_BASIC_INT( (void *)this, LSM6DSL_ACC_GYRO_BASIC_INT_DISABLED ) == MEMS_ERROR ) + { + return 1; + } + + /* Reset tap threshold. */ + if ( set_tap_threshold( 0x0 ) == 1 ) + { + return 1; + } + + /* Reset tap shock time window. */ + if ( set_tap_shock_time( 0x0 ) == 1 ) + { + return 1; + } + + /* Reset tap quiet time window. */ + if ( set_tap_quiet_time( 0x0 ) == 1 ) + { + return 1; + } + + /* _NOTE_: Tap duration time window - don't care for single tap. */ + + /* _NOTE_: Single/Double Tap event - don't care of this flag for single tap. */ + + /* Disable Z direction in tap recognition. */ + if ( LSM6DSL_ACC_GYRO_W_TAP_Z_EN( (void *)this, LSM6DSL_ACC_GYRO_TAP_Z_EN_DISABLED ) == MEMS_ERROR ) + { + return 1; + } + + /* Disable Y direction in tap recognition. */ + if ( LSM6DSL_ACC_GYRO_W_TAP_Y_EN( (void *)this, LSM6DSL_ACC_GYRO_TAP_Y_EN_DISABLED ) == MEMS_ERROR ) + { + return 1; + } + + /* Disable X direction in tap recognition. */ + if ( LSM6DSL_ACC_GYRO_W_TAP_X_EN( (void *)this, LSM6DSL_ACC_GYRO_TAP_X_EN_DISABLED ) == MEMS_ERROR ) + { + return 1; + } + + return 0; +} + +/** + * @brief Enable the double tap detection for LSM6DSL accelerometer sensor + * @param pin the interrupt pin to be used + * @note This function sets the LSM6DSL accelerometer ODR to 416Hz and the LSM6DSL accelerometer full scale to 2g + * @retval 0 in case of success, an error code otherwise + */ +int LSM6DSLSensor::enable_double_tap_detection(LSM6DSL_Interrupt_Pin_t pin) +{ + /* Output Data Rate selection */ + if( set_x_odr(416.0f) == 1 ) + { + return 1; + } + + /* Full scale selection. */ + if( set_x_fs(2.0f) == 1 ) + { + return 1; + } + + /* Enable X direction in tap recognition. */ + if ( LSM6DSL_ACC_GYRO_W_TAP_X_EN( (void *)this, LSM6DSL_ACC_GYRO_TAP_X_EN_ENABLED ) == MEMS_ERROR ) + { + return 1; + } + + /* Enable Y direction in tap recognition. */ + if ( LSM6DSL_ACC_GYRO_W_TAP_Y_EN( (void *)this, LSM6DSL_ACC_GYRO_TAP_Y_EN_ENABLED ) == MEMS_ERROR ) + { + return 1; + } + + /* Enable Z direction in tap recognition. */ + if ( LSM6DSL_ACC_GYRO_W_TAP_Z_EN( (void *)this, LSM6DSL_ACC_GYRO_TAP_Z_EN_ENABLED ) == MEMS_ERROR ) + { + return 1; + } + + /* Set tap threshold. */ + if ( set_tap_threshold( LSM6DSL_TAP_THRESHOLD_MID_LOW ) == 1 ) + { + return 1; + } + + /* Set tap shock time window. */ + if ( set_tap_shock_time( LSM6DSL_TAP_SHOCK_TIME_HIGH ) == 1 ) + { + return 1; + } + + /* Set tap quiet time window. */ + if ( set_tap_quiet_time( LSM6DSL_TAP_QUIET_TIME_HIGH ) == 1 ) + { + return 1; + } + + /* Set tap duration time window. */ + if ( set_tap_duration_time( LSM6DSL_TAP_DURATION_TIME_MID ) == 1 ) + { + return 1; + } + + /* Single and double tap enabled. */ + if ( LSM6DSL_ACC_GYRO_W_SINGLE_DOUBLE_TAP_EV( (void *)this, LSM6DSL_ACC_GYRO_SINGLE_DOUBLE_TAP_DOUBLE_TAP ) == MEMS_ERROR ) + { + return 1; + } + + /* Enable basic Interrupts */ + if ( LSM6DSL_ACC_GYRO_W_BASIC_INT( (void *)this, LSM6DSL_ACC_GYRO_BASIC_INT_ENABLED ) == MEMS_ERROR ) + { + return 1; + } + + /* Enable double tap on either INT1 or INT2 pin */ + switch (pin) + { + case LSM6DSL_INT1_PIN: + if ( LSM6DSL_ACC_GYRO_W_TapEvOnInt1( (void *)this, LSM6DSL_ACC_GYRO_INT1_TAP_ENABLED ) == MEMS_ERROR ) + { + return 1; + } + break; + + case LSM6DSL_INT2_PIN: + if ( LSM6DSL_ACC_GYRO_W_TapEvOnInt2( (void *)this, LSM6DSL_ACC_GYRO_INT2_TAP_ENABLED ) == MEMS_ERROR ) + { + return 1; + } + break; + + default: + return 1; + } + + return 0; +} + +/** + * @brief Disable the double tap detection for LSM6DSL accelerometer sensor + * @retval 0 in case of success, an error code otherwise + */ +int LSM6DSLSensor::disable_double_tap_detection(void) +{ + /* Disable double tap interrupt on INT1 pin. */ + if ( LSM6DSL_ACC_GYRO_W_TapEvOnInt1( (void *)this, LSM6DSL_ACC_GYRO_INT1_TAP_DISABLED ) == MEMS_ERROR ) + { + return 1; + } + + /* Disable double tap interrupt on INT2 pin. */ + if ( LSM6DSL_ACC_GYRO_W_TapEvOnInt2( (void *)this, LSM6DSL_ACC_GYRO_INT2_TAP_DISABLED ) == MEMS_ERROR ) + { + return 1; + } + + /* Disable basic Interrupts */ + if ( LSM6DSL_ACC_GYRO_W_BASIC_INT( (void *)this, LSM6DSL_ACC_GYRO_BASIC_INT_DISABLED ) == MEMS_ERROR ) + { + return 1; + } + + /* Reset tap threshold. */ + if ( set_tap_threshold( 0x0 ) == 1 ) + { + return 1; + } + + /* Reset tap shock time window. */ + if ( set_tap_shock_time( 0x0 ) == 1 ) + { + return 1; + } + + /* Reset tap quiet time window. */ + if ( set_tap_quiet_time( 0x0 ) == 1 ) + { + return 1; + } + + /* Reset tap duration time window. */ + if ( set_tap_duration_time( 0x0 ) == 1 ) + { + return 1; + } + + /* Only single tap enabled. */ + if ( LSM6DSL_ACC_GYRO_W_SINGLE_DOUBLE_TAP_EV( (void *)this, LSM6DSL_ACC_GYRO_SINGLE_DOUBLE_TAP_SINGLE_TAP ) == MEMS_ERROR ) + { + return 1; + } + + /* Disable Z direction in tap recognition. */ + if ( LSM6DSL_ACC_GYRO_W_TAP_Z_EN( (void *)this, LSM6DSL_ACC_GYRO_TAP_Z_EN_DISABLED ) == MEMS_ERROR ) + { + return 1; + } + + /* Disable Y direction in tap recognition. */ + if ( LSM6DSL_ACC_GYRO_W_TAP_Y_EN( (void *)this, LSM6DSL_ACC_GYRO_TAP_Y_EN_DISABLED ) == MEMS_ERROR ) + { + return 1; + } + + /* Disable X direction in tap recognition. */ + if ( LSM6DSL_ACC_GYRO_W_TAP_X_EN( (void *)this, LSM6DSL_ACC_GYRO_TAP_X_EN_DISABLED ) == MEMS_ERROR ) + { + return 1; + } + + return 0; +} + +/** + * @brief Set the tap threshold for LSM6DSL accelerometer sensor + * @param thr the threshold to be set + * @retval 0 in case of success, an error code otherwise + */ +int LSM6DSLSensor::set_tap_threshold(uint8_t thr) +{ + if ( LSM6DSL_ACC_GYRO_W_TAP_THS( (void *)this, thr ) == MEMS_ERROR ) + { + return 1; + } + + return 0; +} + +/** + * @brief Set the tap shock time window for LSM6DSL accelerometer sensor + * @param time the shock time window to be set + * @retval 0 in case of success, an error code otherwise + */ +int LSM6DSLSensor::set_tap_shock_time(uint8_t time) +{ + if ( LSM6DSL_ACC_GYRO_W_SHOCK_Duration( (void *)this, time ) == MEMS_ERROR ) + { + return 1; + } + + return 0; +} + +/** + * @brief Set the tap quiet time window for LSM6DSL accelerometer sensor + * @param time the quiet time window to be set + * @retval 0 in case of success, an error code otherwise + */ +int LSM6DSLSensor::set_tap_quiet_time(uint8_t time) +{ + if ( LSM6DSL_ACC_GYRO_W_QUIET_Duration( (void *)this, time ) == MEMS_ERROR ) + { + return 1; + } + + return 0; +} + +/** + * @brief Set the tap duration of the time window for LSM6DSL accelerometer sensor + * @param time the duration of the time window to be set + * @retval 0 in case of success, an error code otherwise + */ +int LSM6DSLSensor::set_tap_duration_time(uint8_t time) +{ + if ( LSM6DSL_ACC_GYRO_W_DUR( (void *)this, time ) == MEMS_ERROR ) + { + return 1; + } + + return 0; +} + +/** + * @brief Enable the 6D orientation detection for LSM6DSL accelerometer sensor + * @param pin the interrupt pin to be used + * @note This function sets the LSM6DSL accelerometer ODR to 416Hz and the LSM6DSL accelerometer full scale to 2g + * @retval 0 in case of success, an error code otherwise + */ +int LSM6DSLSensor::enable_6d_orientation(LSM6DSL_Interrupt_Pin_t pin) +{ + /* Output Data Rate selection */ + if( set_x_odr(416.0f) == 1 ) + { + return 1; + } + + /* Full scale selection. */ + if( set_x_fs(2.0f) == 1 ) + { + return 1; + } + + /* Set 6D threshold. */ + if ( LSM6DSL_ACC_GYRO_W_SIXD_THS( (void *)this, LSM6DSL_ACC_GYRO_SIXD_THS_60_degree ) == MEMS_ERROR ) + { + return 1; + } + + /* Enable basic Interrupts */ + if ( LSM6DSL_ACC_GYRO_W_BASIC_INT( (void *)this, LSM6DSL_ACC_GYRO_BASIC_INT_ENABLED ) == MEMS_ERROR ) + { + return 1; + } + + /* Enable 6D orientation on either INT1 or INT2 pin */ + switch (pin) + { + case LSM6DSL_INT1_PIN: + if ( LSM6DSL_ACC_GYRO_W_6DEvOnInt1( (void *)this, LSM6DSL_ACC_GYRO_INT1_6D_ENABLED ) == MEMS_ERROR ) + { + return 1; + } + break; + + case LSM6DSL_INT2_PIN: + if ( LSM6DSL_ACC_GYRO_W_6DEvOnInt2( (void *)this, LSM6DSL_ACC_GYRO_INT2_6D_ENABLED ) == MEMS_ERROR ) + { + return 1; + } + break; + + default: + return 1; + } + + return 0; +} + +/** + * @brief Disable the 6D orientation detection for LSM6DSL accelerometer sensor + * @retval 0 in case of success, an error code otherwise + */ +int LSM6DSLSensor::disable_6d_orientation(void) +{ + /* Disable 6D orientation interrupt on INT1 pin. */ + if ( LSM6DSL_ACC_GYRO_W_6DEvOnInt1( (void *)this, LSM6DSL_ACC_GYRO_INT1_6D_DISABLED ) == MEMS_ERROR ) + { + return 1; + } + + /* Disable 6D orientation interrupt on INT2 pin. */ + if ( LSM6DSL_ACC_GYRO_W_6DEvOnInt2( (void *)this, LSM6DSL_ACC_GYRO_INT2_6D_DISABLED ) == MEMS_ERROR ) + { + return 1; + } + + /* Disable basic Interrupts */ + if ( LSM6DSL_ACC_GYRO_W_BASIC_INT( (void *)this, LSM6DSL_ACC_GYRO_BASIC_INT_DISABLED ) == MEMS_ERROR ) + { + return 1; + } + + /* Reset 6D threshold. */ + if ( LSM6DSL_ACC_GYRO_W_SIXD_THS( (void *)this, LSM6DSL_ACC_GYRO_SIXD_THS_80_degree ) == MEMS_ERROR ) + { + return 1; + } + + return 0; +} + +/** + * @brief Get the 6D orientation XL axis for LSM6DSL accelerometer sensor + * @param xl the pointer to the 6D orientation XL axis + * @retval 0 in case of success, an error code otherwise + */ +int LSM6DSLSensor::get_6d_orientation_xl(uint8_t *xl) +{ + LSM6DSL_ACC_GYRO_DSD_XL_t xl_raw; + + if ( LSM6DSL_ACC_GYRO_R_DSD_XL( (void *)this, &xl_raw ) == MEMS_ERROR ) + { + return 1; + } + + switch( xl_raw ) + { + case LSM6DSL_ACC_GYRO_DSD_XL_DETECTED: + *xl = 1; + break; + case LSM6DSL_ACC_GYRO_DSD_XL_NOT_DETECTED: + *xl = 0; + break; + default: + return 1; + } + + return 0; +} + +/** + * @brief Get the 6D orientation XH axis for LSM6DSL accelerometer sensor + * @param xh the pointer to the 6D orientation XH axis + * @retval 0 in case of success, an error code otherwise + */ +int LSM6DSLSensor::get_6d_orientation_xh(uint8_t *xh) +{ + LSM6DSL_ACC_GYRO_DSD_XH_t xh_raw; + + if ( LSM6DSL_ACC_GYRO_R_DSD_XH( (void *)this, &xh_raw ) == MEMS_ERROR ) + { + return 1; + } + + switch( xh_raw ) + { + case LSM6DSL_ACC_GYRO_DSD_XH_DETECTED: + *xh = 1; + break; + case LSM6DSL_ACC_GYRO_DSD_XH_NOT_DETECTED: + *xh = 0; + break; + default: + return 1; + } + + return 0; +} + +/** + * @brief Get the 6D orientation YL axis for LSM6DSL accelerometer sensor + * @param yl the pointer to the 6D orientation YL axis + * @retval 0 in case of success, an error code otherwise + */ +int LSM6DSLSensor::get_6d_orientation_yl(uint8_t *yl) +{ + LSM6DSL_ACC_GYRO_DSD_YL_t yl_raw; + + if ( LSM6DSL_ACC_GYRO_R_DSD_YL( (void *)this, &yl_raw ) == MEMS_ERROR ) + { + return 1; + } + + switch( yl_raw ) + { + case LSM6DSL_ACC_GYRO_DSD_YL_DETECTED: + *yl = 1; + break; + case LSM6DSL_ACC_GYRO_DSD_YL_NOT_DETECTED: + *yl = 0; + break; + default: + return 1; + } + + return 0; +} + +/** + * @brief Get the 6D orientation YH axis for LSM6DSL accelerometer sensor + * @param yh the pointer to the 6D orientation YH axis + * @retval 0 in case of success, an error code otherwise + */ +int LSM6DSLSensor::get_6d_orientation_yh(uint8_t *yh) +{ + LSM6DSL_ACC_GYRO_DSD_YH_t yh_raw; + + if ( LSM6DSL_ACC_GYRO_R_DSD_YH( (void *)this, &yh_raw ) == MEMS_ERROR ) + { + return 1; + } + + switch( yh_raw ) + { + case LSM6DSL_ACC_GYRO_DSD_YH_DETECTED: + *yh = 1; + break; + case LSM6DSL_ACC_GYRO_DSD_YH_NOT_DETECTED: + *yh = 0; + break; + default: + return 1; + } + + return 0; +} + +/** + * @brief Get the 6D orientation ZL axis for LSM6DSL accelerometer sensor + * @param zl the pointer to the 6D orientation ZL axis + * @retval 0 in case of success, an error code otherwise + */ +int LSM6DSLSensor::get_6d_orientation_zl(uint8_t *zl) +{ + LSM6DSL_ACC_GYRO_DSD_ZL_t zl_raw; + + if ( LSM6DSL_ACC_GYRO_R_DSD_ZL( (void *)this, &zl_raw ) == MEMS_ERROR ) + { + return 1; + } + + switch( zl_raw ) + { + case LSM6DSL_ACC_GYRO_DSD_ZL_DETECTED: + *zl = 1; + break; + case LSM6DSL_ACC_GYRO_DSD_ZL_NOT_DETECTED: + *zl = 0; + break; + default: + return 1; + } + + return 0; +} + +/** + * @brief Get the 6D orientation ZH axis for LSM6DSL accelerometer sensor + * @param zh the pointer to the 6D orientation ZH axis + * @retval 0 in case of success, an error code otherwise + */ +int LSM6DSLSensor::get_6d_orientation_zh(uint8_t *zh) +{ + LSM6DSL_ACC_GYRO_DSD_ZH_t zh_raw; + + if ( LSM6DSL_ACC_GYRO_R_DSD_ZH( (void *)this, &zh_raw ) == MEMS_ERROR ) + { + return 1; + } + + switch( zh_raw ) + { + case LSM6DSL_ACC_GYRO_DSD_ZH_DETECTED: + *zh = 1; + break; + case LSM6DSL_ACC_GYRO_DSD_ZH_NOT_DETECTED: + *zh = 0; + break; + default: + return 1; + } + + return 0; +} + +/** + * @brief Get the status of all hardware events for LSM6DSL accelerometer sensor + * @param status the pointer to the status of all hardware events + * @retval 0 in case of success, an error code otherwise + */ +int LSM6DSLSensor::get_event_status(LSM6DSL_Event_Status_t *status) +{ + uint8_t Wake_Up_Src = 0, Tap_Src = 0, D6D_Src = 0, Func_Src = 0, Md1_Cfg = 0, Md2_Cfg = 0, Int1_Ctrl = 0; + + memset((void *)status, 0x0, sizeof(LSM6DSL_Event_Status_t)); + + if(read_reg(LSM6DSL_ACC_GYRO_WAKE_UP_SRC, &Wake_Up_Src) != 0) + { + return 1; + } + + if(read_reg(LSM6DSL_ACC_GYRO_TAP_SRC, &Tap_Src) != 0) + { + return 1; + } + + if(read_reg(LSM6DSL_ACC_GYRO_D6D_SRC, &D6D_Src) != 0) + { + return 1; + } + + if(read_reg(LSM6DSL_ACC_GYRO_FUNC_SRC, &Func_Src) != 0) + { + return 1; + } + + if(read_reg(LSM6DSL_ACC_GYRO_MD1_CFG, &Md1_Cfg ) != 0 ) + { + return 1; + } + + if(read_reg(LSM6DSL_ACC_GYRO_MD2_CFG, &Md2_Cfg ) != 0) + { + return 1; + } + + if(read_reg(LSM6DSL_ACC_GYRO_INT1_CTRL, &Int1_Ctrl ) != 0) + { + return 1; + } + + if((Md1_Cfg & LSM6DSL_ACC_GYRO_INT1_FF_MASK) || (Md2_Cfg & LSM6DSL_ACC_GYRO_INT2_FF_MASK)) + { + if((Wake_Up_Src & LSM6DSL_ACC_GYRO_FF_EV_STATUS_MASK)) + { + status->FreeFallStatus = 1; + } + } + + if((Md1_Cfg & LSM6DSL_ACC_GYRO_INT1_WU_MASK) || (Md2_Cfg & LSM6DSL_ACC_GYRO_INT2_WU_MASK)) + { + if((Wake_Up_Src & LSM6DSL_ACC_GYRO_WU_EV_STATUS_MASK)) + { + status->WakeUpStatus = 1; + } + } + + if((Md1_Cfg & LSM6DSL_ACC_GYRO_INT1_SINGLE_TAP_MASK) || (Md2_Cfg & LSM6DSL_ACC_GYRO_INT2_SINGLE_TAP_MASK)) + { + if((Tap_Src & LSM6DSL_ACC_GYRO_SINGLE_TAP_EV_STATUS_MASK)) + { + status->TapStatus = 1; + } + } + + if((Md1_Cfg & LSM6DSL_ACC_GYRO_INT1_TAP_MASK) || (Md2_Cfg & LSM6DSL_ACC_GYRO_INT2_TAP_MASK)) + { + if((Tap_Src & LSM6DSL_ACC_GYRO_DOUBLE_TAP_EV_STATUS_MASK)) + { + status->DoubleTapStatus = 1; + } + } + + if((Md1_Cfg & LSM6DSL_ACC_GYRO_INT1_6D_MASK) || (Md2_Cfg & LSM6DSL_ACC_GYRO_INT2_6D_MASK)) + { + if((D6D_Src & LSM6DSL_ACC_GYRO_D6D_EV_STATUS_MASK)) + { + status->D6DOrientationStatus = 1; + } + } + + if((Int1_Ctrl & LSM6DSL_ACC_GYRO_INT1_PEDO_MASK)) + { + if((Func_Src & LSM6DSL_ACC_GYRO_PEDO_EV_STATUS_MASK)) + { + status->StepStatus = 1; + } + } + + if((Md1_Cfg & LSM6DSL_ACC_GYRO_INT1_TILT_MASK) || (Md2_Cfg & LSM6DSL_ACC_GYRO_INT2_TILT_MASK)) + { + if((Func_Src & LSM6DSL_ACC_GYRO_TILT_EV_STATUS_MASK)) + { + status->TiltStatus = 1; + } + } + + return 0; +} + +/** + * @brief Read the data from register + * @param reg register address + * @param data register data + * @retval 0 in case of success, an error code otherwise + */ +int LSM6DSLSensor::read_reg( uint8_t reg, uint8_t *data ) +{ + + if ( LSM6DSL_ACC_GYRO_read_reg( (void *)this, reg, data, 1 ) == MEMS_ERROR ) + { + return 1; + } + + return 0; +} + +/** + * @brief Write the data to register + * @param reg register address + * @param data register data + * @retval 0 in case of success, an error code otherwise + */ +int LSM6DSLSensor::write_reg( uint8_t reg, uint8_t data ) +{ + + if ( LSM6DSL_ACC_GYRO_write_reg( (void *)this, reg, &data, 1 ) == MEMS_ERROR ) + { + return 1; + } + + return 0; +} + + +uint8_t LSM6DSL_io_write( void *handle, uint8_t WriteAddr, uint8_t *pBuffer, uint16_t nBytesToWrite ) +{ + return ((LSM6DSLSensor *)handle)->io_write(pBuffer, WriteAddr, nBytesToWrite); +} + +uint8_t LSM6DSL_io_read( void *handle, uint8_t ReadAddr, uint8_t *pBuffer, uint16_t nBytesToRead ) +{ + return ((LSM6DSLSensor *)handle)->io_read(pBuffer, ReadAddr, nBytesToRead); +}
diff -r 000000000000 -r 98c301bb7d1b Components/LSM6DSLSensor/LSM6DSLSensor.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Components/LSM6DSLSensor/LSM6DSLSensor.h Tue Oct 03 12:21:11 2017 +0000 @@ -0,0 +1,297 @@ +/** + ****************************************************************************** + * @file LSM6DSLSensor.h + * @author CLab + * @version V1.0.0 + * @date 5 August 2016 + * @brief Abstract Class of an LSM6DSL Inertial Measurement Unit (IMU) 6 axes + * sensor. + ****************************************************************************** + * @attention + * + * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of STMicroelectronics nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************** + */ + + +/* Prevent recursive inclusion -----------------------------------------------*/ + +#ifndef __LSM6DSLSensor_H__ +#define __LSM6DSLSensor_H__ + + +/* Includes ------------------------------------------------------------------*/ + +#include "DevI2C.h" +#include "LSM6DSL_acc_gyro_driver.h" +#include "MotionSensor.h" +#include "GyroSensor.h" + +/* Defines -------------------------------------------------------------------*/ + +#define LSM6DSL_ACC_SENSITIVITY_FOR_FS_2G 0.061 /**< Sensitivity value for 2 g full scale [mg/LSB] */ +#define LSM6DSL_ACC_SENSITIVITY_FOR_FS_4G 0.122 /**< Sensitivity value for 4 g full scale [mg/LSB] */ +#define LSM6DSL_ACC_SENSITIVITY_FOR_FS_8G 0.244 /**< Sensitivity value for 8 g full scale [mg/LSB] */ +#define LSM6DSL_ACC_SENSITIVITY_FOR_FS_16G 0.488 /**< Sensitivity value for 16 g full scale [mg/LSB] */ + +#define LSM6DSL_GYRO_SENSITIVITY_FOR_FS_125DPS 04.375 /**< Sensitivity value for 125 dps full scale [mdps/LSB] */ +#define LSM6DSL_GYRO_SENSITIVITY_FOR_FS_245DPS 08.750 /**< Sensitivity value for 245 dps full scale [mdps/LSB] */ +#define LSM6DSL_GYRO_SENSITIVITY_FOR_FS_500DPS 17.500 /**< Sensitivity value for 500 dps full scale [mdps/LSB] */ +#define LSM6DSL_GYRO_SENSITIVITY_FOR_FS_1000DPS 35.000 /**< Sensitivity value for 1000 dps full scale [mdps/LSB] */ +#define LSM6DSL_GYRO_SENSITIVITY_FOR_FS_2000DPS 70.000 /**< Sensitivity value for 2000 dps full scale [mdps/LSB] */ + +#define LSM6DSL_PEDOMETER_THRESHOLD_LOW 0x00 /**< Lowest value of pedometer threshold */ +#define LSM6DSL_PEDOMETER_THRESHOLD_MID_LOW 0x07 +#define LSM6DSL_PEDOMETER_THRESHOLD_MID 0x0F +#define LSM6DSL_PEDOMETER_THRESHOLD_MID_HIGH 0x17 +#define LSM6DSL_PEDOMETER_THRESHOLD_HIGH 0x1F /**< Highest value of pedometer threshold */ + +#define LSM6DSL_WAKE_UP_THRESHOLD_LOW 0x01 /**< Lowest value of wake up threshold */ +#define LSM6DSL_WAKE_UP_THRESHOLD_MID_LOW 0x0F +#define LSM6DSL_WAKE_UP_THRESHOLD_MID 0x1F +#define LSM6DSL_WAKE_UP_THRESHOLD_MID_HIGH 0x2F +#define LSM6DSL_WAKE_UP_THRESHOLD_HIGH 0x3F /**< Highest value of wake up threshold */ + +#define LSM6DSL_TAP_THRESHOLD_LOW 0x01 /**< Lowest value of wake up threshold */ +#define LSM6DSL_TAP_THRESHOLD_MID_LOW 0x08 +#define LSM6DSL_TAP_THRESHOLD_MID 0x10 +#define LSM6DSL_TAP_THRESHOLD_MID_HIGH 0x18 +#define LSM6DSL_TAP_THRESHOLD_HIGH 0x1F /**< Highest value of wake up threshold */ + +#define LSM6DSL_TAP_SHOCK_TIME_LOW 0x00 /**< Lowest value of wake up threshold */ +#define LSM6DSL_TAP_SHOCK_TIME_MID_LOW 0x01 +#define LSM6DSL_TAP_SHOCK_TIME_MID_HIGH 0x02 +#define LSM6DSL_TAP_SHOCK_TIME_HIGH 0x03 /**< Highest value of wake up threshold */ + +#define LSM6DSL_TAP_QUIET_TIME_LOW 0x00 /**< Lowest value of wake up threshold */ +#define LSM6DSL_TAP_QUIET_TIME_MID_LOW 0x01 +#define LSM6DSL_TAP_QUIET_TIME_MID_HIGH 0x02 +#define LSM6DSL_TAP_QUIET_TIME_HIGH 0x03 /**< Highest value of wake up threshold */ + +#define LSM6DSL_TAP_DURATION_TIME_LOW 0x00 /**< Lowest value of wake up threshold */ +#define LSM6DSL_TAP_DURATION_TIME_MID_LOW 0x04 +#define LSM6DSL_TAP_DURATION_TIME_MID 0x08 +#define LSM6DSL_TAP_DURATION_TIME_MID_HIGH 0x0C +#define LSM6DSL_TAP_DURATION_TIME_HIGH 0x0F /**< Highest value of wake up threshold */ + +/* Typedefs ------------------------------------------------------------------*/ + +typedef enum +{ + LSM6DSL_INT1_PIN, + LSM6DSL_INT2_PIN +} LSM6DSL_Interrupt_Pin_t; + +typedef struct +{ + unsigned int FreeFallStatus : 1; + unsigned int TapStatus : 1; + unsigned int DoubleTapStatus : 1; + unsigned int WakeUpStatus : 1; + unsigned int StepStatus : 1; + unsigned int TiltStatus : 1; + unsigned int D6DOrientationStatus : 1; +} LSM6DSL_Event_Status_t; + +/* Class Declaration ---------------------------------------------------------*/ + +/** + * Abstract class of an LSM6DSL Inertial Measurement Unit (IMU) 6 axes + * sensor. + */ +class LSM6DSLSensor : public MotionSensor, public GyroSensor +{ + public: + LSM6DSLSensor(DevI2C &i2c, PinName INT1_pin, PinName INT2_pin); + LSM6DSLSensor(DevI2C &i2c, PinName INT1_pin, PinName INT2_pin, uint8_t address); + virtual int init(void *init); + virtual int read_id(uint8_t *id); + virtual int get_x_axes(int32_t *pData); + virtual int get_g_axes(int32_t *pData); + virtual int get_x_sensitivity(float *pfData); + virtual int get_g_sensitivity(float *pfData); + virtual int get_x_axes_raw(int16_t *pData); + virtual int get_g_axes_raw(int16_t *pData); + virtual int get_x_odr(float *odr); + virtual int get_g_odr(float *odr); + virtual int set_x_odr(float odr); + virtual int set_g_odr(float odr); + virtual int get_x_fs(float *fullScale); + virtual int get_g_fs(float *fullScale); + virtual int set_x_fs(float fullScale); + virtual int set_g_fs(float fullScale); + int enable_x(void); + int enable_g(void); + int disable_x(void); + int disable_g(void); + int enable_free_fall_detection(LSM6DSL_Interrupt_Pin_t pin = LSM6DSL_INT1_PIN); + int disable_free_fall_detection(void); + int set_free_fall_threshold(uint8_t thr); + int enable_pedometer(void); + int disable_pedometer(void); + int get_step_counter(uint16_t *step_count); + int reset_step_counter(void); + int set_pedometer_threshold(uint8_t thr); + int enable_tilt_detection(LSM6DSL_Interrupt_Pin_t pin = LSM6DSL_INT1_PIN); + int disable_tilt_detection(void); + int enable_wake_up_detection(LSM6DSL_Interrupt_Pin_t pin = LSM6DSL_INT2_PIN); + int disable_wake_up_detection(void); + int set_wake_up_threshold(uint8_t thr); + int enable_single_tap_detection(LSM6DSL_Interrupt_Pin_t pin = LSM6DSL_INT1_PIN); + int disable_single_tap_detection(void); + int enable_double_tap_detection(LSM6DSL_Interrupt_Pin_t pin = LSM6DSL_INT1_PIN); + int disable_double_tap_detection(void); + int set_tap_threshold(uint8_t thr); + int set_tap_shock_time(uint8_t time); + int set_tap_quiet_time(uint8_t time); + int set_tap_duration_time(uint8_t time); + int enable_6d_orientation(LSM6DSL_Interrupt_Pin_t pin = LSM6DSL_INT1_PIN); + int disable_6d_orientation(void); + int get_6d_orientation_xl(uint8_t *xl); + int get_6d_orientation_xh(uint8_t *xh); + int get_6d_orientation_yl(uint8_t *yl); + int get_6d_orientation_yh(uint8_t *yh); + int get_6d_orientation_zl(uint8_t *zl); + int get_6d_orientation_zh(uint8_t *zh); + int get_event_status(LSM6DSL_Event_Status_t *status); + int read_reg(uint8_t reg, uint8_t *data); + int write_reg(uint8_t reg, uint8_t data); + + /** + * @brief Attaching an interrupt handler to the INT1 interrupt. + * @param fptr An interrupt handler. + * @retval None. + */ + void attach_int1_irq(void (*fptr)(void)) + { + _int1_irq.rise(fptr); + } + + /** + * @brief Enabling the INT1 interrupt handling. + * @param None. + * @retval None. + */ + void enable_int1_irq(void) + { + _int1_irq.enable_irq(); + } + + /** + * @brief Disabling the INT1 interrupt handling. + * @param None. + * @retval None. + */ + void disable_int1_irq(void) + { + _int1_irq.disable_irq(); + } + + /** + * @brief Attaching an interrupt handler to the INT2 interrupt. + * @param fptr An interrupt handler. + * @retval None. + */ + void attach_int2_irq(void (*fptr)(void)) + { + _int2_irq.rise(fptr); + } + + /** + * @brief Enabling the INT2 interrupt handling. + * @param None. + * @retval None. + */ + void enable_int2_irq(void) + { + _int2_irq.enable_irq(); + } + + /** + * @brief Disabling the INT2 interrupt handling. + * @param None. + * @retval None. + */ + void disable_int2_irq(void) + { + _int2_irq.disable_irq(); + } + + /** + * @brief Utility function to read data. + * @param pBuffer: pointer to data to be read. + * @param RegisterAddr: specifies internal address register to be read. + * @param NumByteToRead: number of bytes to be read. + * @retval 0 if ok, an error code otherwise. + */ + uint8_t io_read(uint8_t* pBuffer, uint8_t RegisterAddr, uint16_t NumByteToRead) + { + return (uint8_t) _dev_i2c.i2c_read(pBuffer, _address, RegisterAddr, NumByteToRead); + } + + /** + * @brief Utility function to write data. + * @param pBuffer: pointer to data to be written. + * @param RegisterAddr: specifies internal address register to be written. + * @param NumByteToWrite: number of bytes to write. + * @retval 0 if ok, an error code otherwise. + */ + uint8_t io_write(uint8_t* pBuffer, uint8_t RegisterAddr, uint16_t NumByteToWrite) + { + return (uint8_t) _dev_i2c.i2c_write(pBuffer, _address, RegisterAddr, NumByteToWrite); + } + + private: + int set_x_odr_when_enabled(float odr); + int set_g_odr_when_enabled(float odr); + int set_x_odr_when_disabled(float odr); + int set_g_odr_when_disabled(float odr); + + /* Helper classes. */ + DevI2C &_dev_i2c; + + InterruptIn _int1_irq; + InterruptIn _int2_irq; + + /* Configuration */ + uint8_t _address; + + uint8_t _x_is_enabled; + float _x_last_odr; + uint8_t _g_is_enabled; + float _g_last_odr; +}; + +#ifdef __cplusplus + extern "C" { +#endif +uint8_t LSM6DSL_io_write( void *handle, uint8_t WriteAddr, uint8_t *pBuffer, uint16_t nBytesToWrite ); +uint8_t LSM6DSL_io_read( void *handle, uint8_t ReadAddr, uint8_t *pBuffer, uint16_t nBytesToRead ); +#ifdef __cplusplus + } +#endif + +#endif
diff -r 000000000000 -r 98c301bb7d1b Components/LSM6DSLSensor/LSM6DSL_acc_gyro_driver.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Components/LSM6DSLSensor/LSM6DSL_acc_gyro_driver.c Tue Oct 03 12:21:11 2017 +0000 @@ -0,0 +1,6393 @@ +/** + ****************************************************************************** + * @file LSM6DSL_acc_gyro_driver.c + * @author MEMS Application Team + * @version V1.5 + * @date 17-May-2016 + * @brief LSM6DSL driver file + ****************************************************************************** + * @attention + * + * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of STMicroelectronics nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************** + */ + +/* Includes ------------------------------------------------------------------*/ +#include "LSM6DSL_acc_gyro_driver.h" + +/* Imported function prototypes ----------------------------------------------*/ +extern uint8_t LSM6DSL_io_write(void *handle, uint8_t WriteAddr, uint8_t *pBuffer, uint16_t nBytesToWrite); +extern uint8_t LSM6DSL_io_read(void *handle, uint8_t ReadAddr, uint8_t *pBuffer, uint16_t nBytesToRead); + +/* Private typedef -----------------------------------------------------------*/ + +/* Private define ------------------------------------------------------------*/ + +/* Private macro -------------------------------------------------------------*/ + +/* Private variables ---------------------------------------------------------*/ + +/* Private functions ---------------------------------------------------------*/ + +/* Exported functions ---------------------------------------------------------*/ + +/************** Generic Function *******************/ + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_read_reg +* Description : Generic Reading function. It must be fullfilled with either +* : I2C or SPI reading functions +* Input : Register Address, length of buffer +* Output : Data REad +* Return : None +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_read_reg(void *handle, u8_t Reg, u8_t* Data, u16_t len) +{ + if (LSM6DSL_io_read(handle, Reg, Data, len)) + { + return MEMS_ERROR; + } + else + { + return MEMS_SUCCESS; + } +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_write_reg +* Description : Generic Writing function. It must be fullfilled with either +* : I2C or SPI writing function +* Input : Register Address, Data to be written, length of buffer +* Output : None +* Return : None +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_write_reg(void *handle, u8_t Reg, u8_t *Data, u16_t len) +{ + if (LSM6DSL_io_write(handle, Reg, Data, len)) + { + return MEMS_ERROR; + } + else + { + return MEMS_SUCCESS; + } +} + +/**************** Base Function *******************/ + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_WHO_AM_I +* Description : Read WHO_AM_I_BIT +* Input : Pointer to u8_t +* Output : Status of WHO_AM_I_BIT +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_WHO_AM_I(void *handle, u8_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_WHO_AM_I_REG, (u8_t *)value, 1)) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_WHO_AM_I_BIT_MASK; //coerce + *value = *value >> LSM6DSL_ACC_GYRO_WHO_AM_I_BIT_POSITION; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_BDU +* Description : Write BDU +* Input : LSM6DSL_ACC_GYRO_BDU_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_BDU(void *handle, LSM6DSL_ACC_GYRO_BDU_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL3_C, &value, 1)) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_BDU_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_CTRL3_C, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_BDU +* Description : Read BDU +* Input : Pointer to LSM6DSL_ACC_GYRO_BDU_t +* Output : Status of BDU see LSM6DSL_ACC_GYRO_BDU_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_BDU(void *handle, LSM6DSL_ACC_GYRO_BDU_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL3_C, (u8_t *)value, 1)) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_BDU_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_FS_XL +* Description : Write FS_XL +* Input : LSM6DSL_ACC_GYRO_FS_XL_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_FS_XL(void *handle, LSM6DSL_ACC_GYRO_FS_XL_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL1_XL, &value, 1)) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_FS_XL_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_CTRL1_XL, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_FS_XL +* Description : Read FS_XL +* Input : Pointer to LSM6DSL_ACC_GYRO_FS_XL_t +* Output : Status of FS_XL see LSM6DSL_ACC_GYRO_FS_XL_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_FS_XL(void *handle, LSM6DSL_ACC_GYRO_FS_XL_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL1_XL, (u8_t *)value, 1)) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_FS_XL_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : mems_status_t LSM6DSL_ACC_GYRO_GetRawAccData(u8_t *buff) +* Description : Read GetAccData output register +* Input : pointer to [u8_t] +* Output : GetAccData buffer u8_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_GetRawAccData(void *handle, u8_t *buff) +{ + u8_t i, j, k; + u8_t numberOfByteForDimension; + + numberOfByteForDimension=6/3; + + k=0; + for (i=0; i<3;i++ ) + { + for (j=0; j<numberOfByteForDimension;j++ ) + { + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_OUTX_L_XL+k, &buff[k], 1)) + return MEMS_ERROR; + k++; + } + } + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : mems_status_t LSM6DSL_ACC_Get_Acceleration(void *handle, int *buff, u8_t from_fifo) +* Description : Read GetAccData output register +* Input : pointer to [u8_t] +* Output : values are expressed in mg +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +/* + * Following is the table of sensitivity values for each case. + * Values are expressed in ug/digit. + */ +static const long long LSM6DSL_ACC_Sensitivity_List[4] = { + 61, /* FS @2g */ + 122, /* FS @4g */ + 244, /* FS @8g */ + 488, /* FS @16g */ +}; +mems_status_t LSM6DSL_ACC_Get_Acceleration(void *handle, int *buff, u8_t from_fifo) +{ + LSM6DSL_ACC_GYRO_FS_XL_t fs; + long long sensitivity = 0; + Type3Axis16bit_U raw_data_tmp; + + /* Read out current odr, fs, hf setting */ + LSM6DSL_ACC_GYRO_R_FS_XL(handle, &fs); + + /* Determine the sensitivity according to fs */ + switch(fs) { + case LSM6DSL_ACC_GYRO_FS_XL_2g: + sensitivity = LSM6DSL_ACC_Sensitivity_List[0]; + break; + + case LSM6DSL_ACC_GYRO_FS_XL_4g: + sensitivity = LSM6DSL_ACC_Sensitivity_List[1]; + break; + + case LSM6DSL_ACC_GYRO_FS_XL_8g: + sensitivity = LSM6DSL_ACC_Sensitivity_List[2]; + break; + + case LSM6DSL_ACC_GYRO_FS_XL_16g: + sensitivity = LSM6DSL_ACC_Sensitivity_List[3]; + break; + } + + /* Read out raw accelerometer samples */ + if (from_fifo) { + u8_t i; + + /* read all 3 axis from FIFO */ + for(i = 0; i < 3; i++) + LSM6DSL_ACC_GYRO_Get_GetFIFOData(handle, raw_data_tmp.u8bit + 2*i); + } else + LSM6DSL_ACC_GYRO_GetRawAccData(handle, raw_data_tmp.u8bit); + + /* Apply proper shift and sensitivity */ + buff[0] = (raw_data_tmp.i16bit[0] * sensitivity + 500)/1000; + buff[1] = (raw_data_tmp.i16bit[1] * sensitivity + 500)/1000; + buff[2] = (raw_data_tmp.i16bit[2] * sensitivity + 500)/1000; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_ODR_XL +* Description : Write ODR_XL +* Input : LSM6DSL_ACC_GYRO_ODR_XL_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_ODR_XL(void *handle, LSM6DSL_ACC_GYRO_ODR_XL_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL1_XL, &value, 1)) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_ODR_XL_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_CTRL1_XL, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_ODR_XL +* Description : Read ODR_XL +* Input : Pointer to LSM6DSL_ACC_GYRO_ODR_XL_t +* Output : Status of ODR_XL see LSM6DSL_ACC_GYRO_ODR_XL_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_ODR_XL(void *handle, LSM6DSL_ACC_GYRO_ODR_XL_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL1_XL, (u8_t *)value, 1)) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_ODR_XL_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_translate_ODR_XL +* Description : Read ODR_XL +* Input : LSM6DSL_ACC_GYRO_ODR_XL_t +* Output : The ODR value in Hz +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_translate_ODR_XL(LSM6DSL_ACC_GYRO_ODR_XL_t value, u16_t *odr_hz_val) +{ + switch(value) { + case LSM6DSL_ACC_GYRO_ODR_XL_POWER_DOWN: + *odr_hz_val = 0; + break; + + case LSM6DSL_ACC_GYRO_ODR_XL_13Hz: + *odr_hz_val = 13; + break; + + case LSM6DSL_ACC_GYRO_ODR_XL_26Hz: + *odr_hz_val = 26; + break; + + case LSM6DSL_ACC_GYRO_ODR_XL_52Hz: + *odr_hz_val = 52; + break; + + case LSM6DSL_ACC_GYRO_ODR_XL_104Hz: + *odr_hz_val = 104; + break; + + case LSM6DSL_ACC_GYRO_ODR_XL_208Hz: + *odr_hz_val = 208; + break; + + case LSM6DSL_ACC_GYRO_ODR_XL_416Hz: + *odr_hz_val = 416; + break; + + case LSM6DSL_ACC_GYRO_ODR_XL_833Hz: + *odr_hz_val = 833; + break; + + case LSM6DSL_ACC_GYRO_ODR_XL_1660Hz: + *odr_hz_val = 1660; + break; + + default: + return MEMS_ERROR; + } + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_FS_G +* Description : Write FS_G +* Input : LSM6DSL_ACC_GYRO_FS_G_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_FS_G(void *handle, LSM6DSL_ACC_GYRO_FS_G_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL2_G, &value, 1)) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_FS_G_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_CTRL2_G, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_FS_G +* Description : Read FS_G +* Input : Pointer to LSM6DSL_ACC_GYRO_FS_G_t +* Output : Status of FS_G see LSM6DSL_ACC_GYRO_FS_G_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_FS_G(void *handle, LSM6DSL_ACC_GYRO_FS_G_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL2_G, (u8_t *)value, 1)) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_FS_G_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : mems_status_t LSM6DSL_ACC_GYRO_GetRawGyroData(u8_t *buff) +* Description : Read GetGyroData output register +* Input : pointer to [u8_t] +* Output : GetGyroData buffer u8_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_GetRawGyroData(void *handle, u8_t *buff) +{ + u8_t i, j, k; + u8_t numberOfByteForDimension; + + numberOfByteForDimension=6/3; + + k=0; + for (i=0; i<3;i++ ) + { + for (j=0; j<numberOfByteForDimension;j++ ) + { + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_OUTX_L_G+k, &buff[k], 1)) + return MEMS_ERROR; + k++; + } + } + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : mems_status_t LSM6DSL_ACC_Get_AngularRate(u8_t *buff) +* Description : Read GetGyroData output register +* Input : pointer to [u8_t] +* Output : Returned values are espressed in mdps +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +/* + * Following is the table of sensitivity values for each case. + * Values are espressed in udps/digit. + */ +static const long long LSM6DSL_GYRO_Sensitivity_List[5] = { + 4375, /* FS @125 */ + 8750, /* FS @245 */ + 17500, /* FS @500 */ + 35000, /* FS @1000 */ + 70000, /* FS @2000 */ +}; +mems_status_t LSM6DSL_ACC_Get_AngularRate(void *handle, int *buff, u8_t from_fifo) +{ + LSM6DSL_ACC_GYRO_FS_125_t fs_125; + LSM6DSL_ACC_GYRO_FS_G_t fs; + long long sensitivity = 0; + Type3Axis16bit_U raw_data_tmp; + + /* Read out current odr, fs, hf setting */ + LSM6DSL_ACC_GYRO_R_FS_125(handle, &fs_125); + if (fs_125 == LSM6DSL_ACC_GYRO_FS_125_ENABLED) { + sensitivity = LSM6DSL_GYRO_Sensitivity_List[0]; + } else { + LSM6DSL_ACC_GYRO_R_FS_G(handle, &fs); + + /* Determine the sensitivity according to fs */ + switch(fs) { + case LSM6DSL_ACC_GYRO_FS_G_245dps: + sensitivity = LSM6DSL_GYRO_Sensitivity_List[1]; + break; + + case LSM6DSL_ACC_GYRO_FS_G_500dps: + sensitivity = LSM6DSL_GYRO_Sensitivity_List[2]; + break; + + case LSM6DSL_ACC_GYRO_FS_G_1000dps: + sensitivity = LSM6DSL_GYRO_Sensitivity_List[3]; + break; + + case LSM6DSL_ACC_GYRO_FS_G_2000dps: + sensitivity = LSM6DSL_GYRO_Sensitivity_List[4]; + break; + } + } + + /* Read out raw accelerometer samples */ + if (from_fifo) { + u8_t i; + + /* read all 3 axis from FIFO */ + for(i = 0; i < 3; i++) + LSM6DSL_ACC_GYRO_Get_GetFIFOData(handle, raw_data_tmp.u8bit + 2*i); + } else + LSM6DSL_ACC_GYRO_GetRawGyroData(handle, raw_data_tmp.u8bit); + + /* Apply proper shift and sensitivity */ + buff[0] = (raw_data_tmp.i16bit[0] * sensitivity + 500)/1000; + buff[1] = (raw_data_tmp.i16bit[1] * sensitivity + 500)/1000; + buff[2] = (raw_data_tmp.i16bit[2] * sensitivity + 500)/1000; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_ODR_G +* Description : Write ODR_G +* Input : LSM6DSL_ACC_GYRO_ODR_G_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_ODR_G(void *handle, LSM6DSL_ACC_GYRO_ODR_G_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL2_G, &value, 1)) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_ODR_G_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_CTRL2_G, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_ODR_G +* Description : Read ODR_G +* Input : Pointer to LSM6DSL_ACC_GYRO_ODR_G_t +* Output : Status of ODR_G see LSM6DSL_ACC_GYRO_ODR_G_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_ODR_G(void *handle, LSM6DSL_ACC_GYRO_ODR_G_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL2_G, (u8_t *)value, 1)) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_ODR_G_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_translate_ODR_G +* Description : Read ODR_G +* Input : LSM6DSL_ACC_GYRO_ODR_G_t +* Output : The ODR value in Hz +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_translate_ODR_G(LSM6DSL_ACC_GYRO_ODR_G_t value, u16_t *odr_hz_val) +{ + switch(value) { + case LSM6DSL_ACC_GYRO_ODR_G_POWER_DOWN: + *odr_hz_val = 0; + break; + + case LSM6DSL_ACC_GYRO_ODR_G_13Hz: + *odr_hz_val = 13; + break; + + case LSM6DSL_ACC_GYRO_ODR_G_26Hz: + *odr_hz_val = 26; + break; + + case LSM6DSL_ACC_GYRO_ODR_G_52Hz: + *odr_hz_val = 52; + break; + + case LSM6DSL_ACC_GYRO_ODR_G_104Hz: + *odr_hz_val = 104; + break; + + case LSM6DSL_ACC_GYRO_ODR_G_208Hz: + *odr_hz_val = 208; + break; + + case LSM6DSL_ACC_GYRO_ODR_G_416Hz: + *odr_hz_val = 416; + break; + + case LSM6DSL_ACC_GYRO_ODR_G_833Hz: + *odr_hz_val = 833; + break; + + case LSM6DSL_ACC_GYRO_ODR_G_1660Hz: + *odr_hz_val = 1660; + break; + + default: + return MEMS_ERROR; + } + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_FS_125 +* Description : Write FS_125 +* Input : LSM6DSL_ACC_GYRO_FS_125_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_FS_125(void *handle, LSM6DSL_ACC_GYRO_FS_125_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL2_G, &value, 1)) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_FS_125_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_CTRL2_G, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_FS_125 +* Description : Read FS_125 +* Input : Pointer to LSM6DSL_ACC_GYRO_FS_125_t +* Output : Status of FS_125 see LSM6DSL_ACC_GYRO_FS_125_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_FS_125(void *handle, LSM6DSL_ACC_GYRO_FS_125_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL2_G, (u8_t *)value, 1)) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_FS_125_MASK; //mask + + return MEMS_SUCCESS; +} + +/**************** Advanced Function *******************/ + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_BW_SEL +* Description : Write BW_SEL +* Input : LSM6DSL_ACC_GYRO_BW_SEL_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_BW_SEL(void *handle, LSM6DSL_ACC_GYRO_BW_SEL_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL1_XL, &value, 1)) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_BW_SEL_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_CTRL1_XL, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_BW_SEL +* Description : Read BW_SEL +* Input : Pointer to LSM6DSL_ACC_GYRO_BW_SEL_t +* Output : Status of BW_SEL see LSM6DSL_ACC_GYRO_BW_SEL_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_BW_SEL(void *handle, LSM6DSL_ACC_GYRO_BW_SEL_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL1_XL, (u8_t *)value, 1)) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_BW_SEL_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_BLE +* Description : Write BLE +* Input : LSM6DSL_ACC_GYRO_BLE_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_BLE(void *handle, LSM6DSL_ACC_GYRO_BLE_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL3_C, &value, 1)) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_BLE_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_CTRL3_C, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_BLE +* Description : Read BLE +* Input : Pointer to LSM6DSL_ACC_GYRO_BLE_t +* Output : Status of BLE see LSM6DSL_ACC_GYRO_BLE_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_BLE(void *handle, LSM6DSL_ACC_GYRO_BLE_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL3_C, (u8_t *)value, 1)) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_BLE_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_EmbeddedAccess +* Description : Write EMB_ACC +* Input : LSM6DSL_ACC_GYRO_EMB_ACC_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_EmbeddedAccess(void *handle, LSM6DSL_ACC_GYRO_EMB_ACC_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_FUNC_CFG_ACCESS, &value, 1) ) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_EMB_ACC_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_FUNC_CFG_ACCESS, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_EmbeddedAccess +* Description : Read EMB_ACC +* Input : Pointer to LSM6DSL_ACC_GYRO_EMB_ACC_t +* Output : Status of EMB_ACC see LSM6DSL_ACC_GYRO_EMB_ACC_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_EmbeddedAccess(void *handle, LSM6DSL_ACC_GYRO_EMB_ACC_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_FUNC_CFG_ACCESS, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_EMB_ACC_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_SYNC_RES_RATIO +* Description : Write RR +* Input : LSM6DSL_ACC_GYRO_SYNC_RES_RATIO_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_SYNC_RES_RATIO(void *handle, LSM6DSL_ACC_GYRO_SYNC_RES_RATIO_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_SENSOR_RES_RATIO, &value, 1) ) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_SYNC_RES_RATIO_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_SENSOR_RES_RATIO, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_SYNC_RES_RATIO +* Description : Read RR +* Input : Pointer to LSM6DSL_ACC_GYRO_SYNC_RES_RATIO_t +* Output : Status of RR see LSM6DSL_ACC_GYRO_SYNC_RES_RATIO_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_SYNC_RES_RATIO(void *handle, LSM6DSL_ACC_GYRO_SYNC_RES_RATIO_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_SENSOR_RES_RATIO, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_SYNC_RES_RATIO_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_Stamping_Time_Frame +* Description : Write TPH +* Input : u8_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_Stamping_Time_Frame(void *handle, u8_t newValue) +{ + u8_t value; + + newValue = newValue << LSM6DSL_ACC_GYRO_TPH_POSITION; //mask + newValue &= LSM6DSL_ACC_GYRO_TPH_MASK; //coerce + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_SENSOR_SYNC_TIME, &value, 1) ) + return MEMS_ERROR; + + value &= (u8_t)~LSM6DSL_ACC_GYRO_TPH_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_SENSOR_SYNC_TIME, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_Stamping_Time_Frame +* Description : Read TPH +* Input : Pointer to u8_t +* Output : Status of TPH +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_Stamping_Time_Frame(void *handle, u8_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_SENSOR_SYNC_TIME, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_TPH_MASK; //coerce + *value = *value >> LSM6DSL_ACC_GYRO_TPH_POSITION; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_FIFO_Watermark +* Description : Write WTM_FIFO +* Input : u16_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_FIFO_Watermark(void *handle, u16_t newValue) +{ + u8_t valueH, valueL; + u8_t value; + + valueL = newValue & 0xFF; + valueH = (newValue >> 8) & 0xFF; + + /* Low part goes in FIFO_CTRL1 */ + valueL = valueL << LSM6DSL_ACC_GYRO_WTM_FIFO_CTRL1_POSITION; //mask + valueL &= LSM6DSL_ACC_GYRO_WTM_FIFO_CTRL1_MASK; //coerce + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_FIFO_CTRL1, &value, 1) ) + return MEMS_ERROR; + + value &= (u8_t)~LSM6DSL_ACC_GYRO_WTM_FIFO_CTRL1_MASK; + value |= valueL; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_FIFO_CTRL1, &value, 1) ) + return MEMS_ERROR; + + /* High part goes in FIFO_CTRL2 */ + valueH = valueH << LSM6DSL_ACC_GYRO_WTM_FIFO_CTRL2_POSITION; //mask + valueH &= LSM6DSL_ACC_GYRO_WTM_FIFO_CTRL2_MASK; //coerce + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_FIFO_CTRL2, &value, 1) ) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_WTM_FIFO_CTRL2_MASK; + value |= valueH; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_FIFO_CTRL2, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_FIFO_Watermark +* Description : Read WTM_FIFO +* Input : Pointer to u16_t +* Output : Status of WTM_FIFO +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_FIFO_Watermark(void *handle, u16_t *value) +{ + u8_t valueH, valueL; + + /* Low part from FIFO_CTRL1 */ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_FIFO_CTRL1, (u8_t *)&valueL, 1) ) + return MEMS_ERROR; + + valueL &= LSM6DSL_ACC_GYRO_WTM_FIFO_CTRL1_MASK; //coerce + valueL = valueL >> LSM6DSL_ACC_GYRO_WTM_FIFO_CTRL1_POSITION; //mask + + /* High part from FIFO_CTRL2 */ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_FIFO_CTRL2, (u8_t *)&valueH, 1) ) + return MEMS_ERROR; + + valueH &= LSM6DSL_ACC_GYRO_WTM_FIFO_CTRL2_MASK; //coerce + valueH = valueH >> LSM6DSL_ACC_GYRO_WTM_FIFO_CTRL2_POSITION; //mask + + *value = ((valueH << 8) & 0xFF00) | valueL; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_FIFO_TEMP +* Description : Write FIFO_TEMP_EN +* Input : LSM6DSL_ACC_GYRO_FIFO_TEMP_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_FIFO_TEMP(void *handle, LSM6DSL_ACC_GYRO_FIFO_TEMP_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_FIFO_CTRL2, &value, 1) ) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_FIFO_TEMP_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_FIFO_CTRL2, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_FIFO_TEMP +* Description : Read FIFO_TEMP_EN +* Input : Pointer to LSM6DSL_ACC_GYRO_FIFO_TEMP_t +* Output : Status of FIFO_TEMP_EN see LSM6DSL_ACC_GYRO_FIFO_TEMP_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_FIFO_TEMP(void *handle, LSM6DSL_ACC_GYRO_FIFO_TEMP_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_FIFO_CTRL2, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_FIFO_TEMP_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_TIM_PEDO_FIFO_Write_En +* Description : Write TIM_PEDO_FIFO_DRDY +* Input : LSM6DSL_ACC_GYRO_TIM_PEDO_FIFO_DRDY_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_TIM_PEDO_FIFO_Write_En(void *handle, LSM6DSL_ACC_GYRO_TIM_PEDO_FIFO_DRDY_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_FIFO_CTRL2, &value, 1) ) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_TIM_PEDO_FIFO_DRDY_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_FIFO_CTRL2, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_TIM_PEDO_FIFO_Write_En +* Description : Read TIM_PEDO_FIFO_DRDY +* Input : Pointer to LSM6DSL_ACC_GYRO_TIM_PEDO_FIFO_DRDY_t +* Output : Status of TIM_PEDO_FIFO_DRDY see LSM6DSL_ACC_GYRO_TIM_PEDO_FIFO_DRDY_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_TIM_PEDO_FIFO_Write_En(void *handle, LSM6DSL_ACC_GYRO_TIM_PEDO_FIFO_DRDY_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_FIFO_CTRL2, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_TIM_PEDO_FIFO_DRDY_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_TIM_PEDO_FIFO_En +* Description : Write TIM_PEDO_FIFO_EN +* Input : LSM6DSL_ACC_GYRO_TIM_PEDO_FIFO_EN_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_TIM_PEDO_FIFO_En(void *handle, LSM6DSL_ACC_GYRO_TIM_PEDO_FIFO_EN_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_FIFO_CTRL2, &value, 1) ) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_TIM_PEDO_FIFO_EN_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_FIFO_CTRL2, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_TIM_PEDO_FIFO_En +* Description : Read TIM_PEDO_FIFO_EN +* Input : Pointer to LSM6DSL_ACC_GYRO_TIM_PEDO_FIFO_EN_t +* Output : Status of TIM_PEDO_FIFO_EN see LSM6DSL_ACC_GYRO_TIM_PEDO_FIFO_EN_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_TIM_PEDO_FIFO_En(void *handle, LSM6DSL_ACC_GYRO_TIM_PEDO_FIFO_EN_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_FIFO_CTRL2, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_TIM_PEDO_FIFO_EN_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_DEC_FIFO_XL +* Description : Write DEC_FIFO_XL +* Input : LSM6DSL_ACC_GYRO_DEC_FIFO_XL_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_DEC_FIFO_XL(void *handle, LSM6DSL_ACC_GYRO_DEC_FIFO_XL_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_FIFO_CTRL3, &value, 1) ) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_DEC_FIFO_XL_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_FIFO_CTRL3, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_DEC_FIFO_XL_val +* Description : Write DEC_FIFO_XL +* Input : u16_t +* Output : Program XL decimation value from unsigned short +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_DEC_FIFO_XL_val(void *handle, u16_t newValue) +{ + switch(newValue) { + case 0: + LSM6DSL_ACC_GYRO_W_DEC_FIFO_XL(handle, LSM6DSL_ACC_GYRO_DEC_FIFO_XL_DATA_NOT_IN_FIFO); + break; + + case 1: + LSM6DSL_ACC_GYRO_W_DEC_FIFO_XL(handle, LSM6DSL_ACC_GYRO_DEC_FIFO_XL_NO_DECIMATION); + break; + + case 2: + LSM6DSL_ACC_GYRO_W_DEC_FIFO_XL(handle, LSM6DSL_ACC_GYRO_DEC_FIFO_XL_DECIMATION_BY_2); + break; + + case 3: + LSM6DSL_ACC_GYRO_W_DEC_FIFO_XL(handle, LSM6DSL_ACC_GYRO_DEC_FIFO_XL_DECIMATION_BY_3); + break; + + case 4: + LSM6DSL_ACC_GYRO_W_DEC_FIFO_XL(handle, LSM6DSL_ACC_GYRO_DEC_FIFO_XL_DECIMATION_BY_4); + break; + + case 8: + LSM6DSL_ACC_GYRO_W_DEC_FIFO_XL(handle, LSM6DSL_ACC_GYRO_DEC_FIFO_XL_DECIMATION_BY_8); + break; + + case 16: + LSM6DSL_ACC_GYRO_W_DEC_FIFO_XL(handle, LSM6DSL_ACC_GYRO_DEC_FIFO_XL_DECIMATION_BY_16); + break; + + case 32: + LSM6DSL_ACC_GYRO_W_DEC_FIFO_XL(handle, LSM6DSL_ACC_GYRO_DEC_FIFO_XL_DECIMATION_BY_32); + break; + + default: + return MEMS_ERROR; + } + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_DEC_FIFO_XL +* Description : Read DEC_FIFO_XL +* Input : Pointer to LSM6DSL_ACC_GYRO_DEC_FIFO_XL_t +* Output : Status of DEC_FIFO_XL see LSM6DSL_ACC_GYRO_DEC_FIFO_XL_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_DEC_FIFO_XL(void *handle, LSM6DSL_ACC_GYRO_DEC_FIFO_XL_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_FIFO_CTRL3, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_DEC_FIFO_XL_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_DEC_FIFO_G +* Description : Write DEC_FIFO_G +* Input : LSM6DSL_ACC_GYRO_DEC_FIFO_G_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_DEC_FIFO_G(void *handle, LSM6DSL_ACC_GYRO_DEC_FIFO_G_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_FIFO_CTRL3, &value, 1)) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_DEC_FIFO_G_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_FIFO_CTRL3, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_DEC_FIFO_G_val +* Description : Write DEC_FIFO_G +* Input : u16_t +* Output : Program G decimation value from unsigned short +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_DEC_FIFO_G_val(void *handle, u16_t newValue) +{ + switch(newValue) { + case 0: + LSM6DSL_ACC_GYRO_W_DEC_FIFO_G(handle, LSM6DSL_ACC_GYRO_DEC_FIFO_G_DATA_NOT_IN_FIFO); + break; + + case 1: + LSM6DSL_ACC_GYRO_W_DEC_FIFO_G(handle, LSM6DSL_ACC_GYRO_DEC_FIFO_G_NO_DECIMATION); + break; + + case 2: + LSM6DSL_ACC_GYRO_W_DEC_FIFO_G(handle, LSM6DSL_ACC_GYRO_DEC_FIFO_G_DECIMATION_BY_2); + break; + + case 3: + LSM6DSL_ACC_GYRO_W_DEC_FIFO_G(handle, LSM6DSL_ACC_GYRO_DEC_FIFO_G_DECIMATION_BY_3); + break; + + case 4: + LSM6DSL_ACC_GYRO_W_DEC_FIFO_G(handle, LSM6DSL_ACC_GYRO_DEC_FIFO_G_DECIMATION_BY_4); + break; + + case 8: + LSM6DSL_ACC_GYRO_W_DEC_FIFO_G(handle, LSM6DSL_ACC_GYRO_DEC_FIFO_G_DECIMATION_BY_8); + break; + + case 16: + LSM6DSL_ACC_GYRO_W_DEC_FIFO_G(handle, LSM6DSL_ACC_GYRO_DEC_FIFO_G_DECIMATION_BY_16); + break; + + case 32: + LSM6DSL_ACC_GYRO_W_DEC_FIFO_G(handle, LSM6DSL_ACC_GYRO_DEC_FIFO_G_DECIMATION_BY_32); + break; + + default: + return MEMS_ERROR; + } + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_DEC_FIFO_G +* Description : Read DEC_FIFO_G +* Input : Pointer to LSM6DSL_ACC_GYRO_DEC_FIFO_G_t +* Output : Status of DEC_FIFO_G see LSM6DSL_ACC_GYRO_DEC_FIFO_G_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_DEC_FIFO_G(void *handle, LSM6DSL_ACC_GYRO_DEC_FIFO_G_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_FIFO_CTRL3, (u8_t *)value, 1)) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_DEC_FIFO_G_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_DEC_FIFO_DS3 +* Description : Write DEC_DS3_FIFO +* Input : LSM6DSL_ACC_GYRO_DEC_FIFO_DS3_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_DEC_FIFO_DS3(void *handle, LSM6DSL_ACC_GYRO_DEC_FIFO_DS3_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_FIFO_CTRL4, &value, 1)) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_DEC_FIFO_DS3_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_FIFO_CTRL4, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_DEC_FIFO_DS3 +* Description : Read DEC_DS3_FIFO +* Input : Pointer to LSM6DSL_ACC_GYRO_DEC_FIFO_DS3_t +* Output : Status of DEC_DS3_FIFO see LSM6DSL_ACC_GYRO_DEC_FIFO_DS3_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_DEC_FIFO_DS3(void *handle, LSM6DSL_ACC_GYRO_DEC_FIFO_DS3_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_FIFO_CTRL4, (u8_t *)value, 1)) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_DEC_FIFO_DS3_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_DEC_FIFO_DS4 +* Description : Write DEC_DS4_FIFO +* Input : LSM6DSL_ACC_GYRO_DEC_FIFO_DS4_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_DEC_FIFO_DS4(void *handle, LSM6DSL_ACC_GYRO_DEC_FIFO_DS4_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_FIFO_CTRL4, &value, 1)) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_DEC_FIFO_DS4_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_FIFO_CTRL4, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_DEC_FIFO_DS4 +* Description : Read DEC_DS4_FIFO +* Input : Pointer to LSM6DSL_ACC_GYRO_DEC_FIFO_DS4_t +* Output : Status of DEC_DS4_FIFO see LSM6DSL_ACC_GYRO_DEC_FIFO_DS4_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_DEC_FIFO_DS4(void *handle, LSM6DSL_ACC_GYRO_DEC_FIFO_DS4_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_FIFO_CTRL4, (u8_t *)value, 1)) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_DEC_FIFO_DS4_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_HI_DATA_ONLY +* Description : Write HI_DATA_ONLY +* Input : LSM6DSL_ACC_GYRO_HI_DATA_ONLY_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_HI_DATA_ONLY(void *handle, LSM6DSL_ACC_GYRO_HI_DATA_ONLY_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_FIFO_CTRL4, &value, 1)) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_HI_DATA_ONLY_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_FIFO_CTRL4, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_HI_DATA_ONLY +* Description : Read HI_DATA_ONLY +* Input : Pointer to LSM6DSL_ACC_GYRO_HI_DATA_ONLY_t +* Output : Status of HI_DATA_ONLY see LSM6DSL_ACC_GYRO_HI_DATA_ONLY_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_HI_DATA_ONLY(void *handle, LSM6DSL_ACC_GYRO_HI_DATA_ONLY_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_FIFO_CTRL4, (u8_t *)value, 1)) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_HI_DATA_ONLY_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_STOP_ON_FTH +* Description : Write STOP_ON_FTH +* Input : LSM6DSL_ACC_GYRO_STOP_ON_FTH_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_STOP_ON_FTH(void *handle, LSM6DSL_ACC_GYRO_STOP_ON_FTH_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_FIFO_CTRL4, &value, 1)) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_STOP_ON_FTH_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_FIFO_CTRL4, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_STOP_ON_FTH +* Description : Read STOP_ON_FTH +* Input : Pointer to LSM6DSL_ACC_GYRO_STOP_ON_FTH_t +* Output : Status of STOP_ON_FTH see LSM6DSL_ACC_GYRO_STOP_ON_FTH_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_STOP_ON_FTH(void *handle, LSM6DSL_ACC_GYRO_STOP_ON_FTH_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_FIFO_CTRL4, (u8_t *)value, 1)) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_STOP_ON_FTH_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_FIFO_MODE +* Description : Write FIFO_MODE +* Input : LSM6DSL_ACC_GYRO_FIFO_MODE_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_FIFO_MODE(void *handle, LSM6DSL_ACC_GYRO_FIFO_MODE_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_FIFO_CTRL5, &value, 1)) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_FIFO_MODE_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_FIFO_CTRL5, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_FIFO_MODE +* Description : Read FIFO_MODE +* Input : Pointer to LSM6DSL_ACC_GYRO_FIFO_MODE_t +* Output : Status of FIFO_MODE see LSM6DSL_ACC_GYRO_FIFO_MODE_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_FIFO_MODE(void *handle, LSM6DSL_ACC_GYRO_FIFO_MODE_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_FIFO_CTRL5, (u8_t *)value, 1)) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_FIFO_MODE_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_ODR_FIFO +* Description : Write ODR_FIFO +* Input : LSM6DSL_ACC_GYRO_ODR_FIFO_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_ODR_FIFO(void *handle, LSM6DSL_ACC_GYRO_ODR_FIFO_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_FIFO_CTRL5, &value, 1)) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_ODR_FIFO_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_FIFO_CTRL5, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_ODR_FIFO +* Description : Read ODR_FIFO +* Input : Pointer to LSM6DSL_ACC_GYRO_ODR_FIFO_t +* Output : Status of ODR_FIFO see LSM6DSL_ACC_GYRO_ODR_FIFO_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_ODR_FIFO(void *handle, LSM6DSL_ACC_GYRO_ODR_FIFO_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_FIFO_CTRL5, (u8_t *)value, 1)) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_ODR_FIFO_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_DRDY_PULSE +* Description : Write DRDY_PULSE +* Input : LSM6DSL_ACC_GYRO_DRDY_PULSE_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_DRDY_PULSE(void *handle, LSM6DSL_ACC_GYRO_DRDY_PULSE_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_DRDY_PULSE_CFG_G, &value, 1)) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_DRDY_PULSE_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_DRDY_PULSE_CFG_G, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_DRDY_PULSE +* Description : Read DRDY_PULSE +* Input : Pointer to LSM6DSL_ACC_GYRO_DRDY_PULSE_t +* Output : Status of DRDY_PULSE see LSM6DSL_ACC_GYRO_DRDY_PULSE_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_DRDY_PULSE(void *handle, LSM6DSL_ACC_GYRO_DRDY_PULSE_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_DRDY_PULSE_CFG_G, (u8_t *)value, 1)) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_DRDY_PULSE_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_DRDY_XL_on_INT1 +* Description : Write INT1_DRDY_XL +* Input : LSM6DSL_ACC_GYRO_INT1_DRDY_XL_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_DRDY_XL_on_INT1(void *handle, LSM6DSL_ACC_GYRO_INT1_DRDY_XL_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_INT1_CTRL, &value, 1)) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_INT1_DRDY_XL_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_INT1_CTRL, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_DRDY_XL_on_INT1 +* Description : Read INT1_DRDY_XL +* Input : Pointer to LSM6DSL_ACC_GYRO_INT1_DRDY_XL_t +* Output : Status of INT1_DRDY_XL see LSM6DSL_ACC_GYRO_INT1_DRDY_XL_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_DRDY_XL_on_INT1(void *handle, LSM6DSL_ACC_GYRO_INT1_DRDY_XL_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_INT1_CTRL, (u8_t *)value, 1)) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_INT1_DRDY_XL_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_DRDY_G_on_INT1 +* Description : Write INT1_DRDY_G +* Input : LSM6DSL_ACC_GYRO_INT1_DRDY_G_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_DRDY_G_on_INT1(void *handle, LSM6DSL_ACC_GYRO_INT1_DRDY_G_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_INT1_CTRL, &value, 1)) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_INT1_DRDY_G_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_INT1_CTRL, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_DRDY_G_on_INT1 +* Description : Read INT1_DRDY_G +* Input : Pointer to LSM6DSL_ACC_GYRO_INT1_DRDY_G_t +* Output : Status of INT1_DRDY_G see LSM6DSL_ACC_GYRO_INT1_DRDY_G_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_DRDY_G_on_INT1(void *handle, LSM6DSL_ACC_GYRO_INT1_DRDY_G_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_INT1_CTRL, (u8_t *)value, 1)) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_INT1_DRDY_G_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_BOOT_on_INT1 +* Description : Write INT1_BOOT +* Input : LSM6DSL_ACC_GYRO_INT1_BOOT_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_BOOT_on_INT1(void *handle, LSM6DSL_ACC_GYRO_INT1_BOOT_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_INT1_CTRL, &value, 1)) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_INT1_BOOT_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_INT1_CTRL, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_BOOT_on_INT1 +* Description : Read INT1_BOOT +* Input : Pointer to LSM6DSL_ACC_GYRO_INT1_BOOT_t +* Output : Status of INT1_BOOT see LSM6DSL_ACC_GYRO_INT1_BOOT_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_BOOT_on_INT1(void *handle, LSM6DSL_ACC_GYRO_INT1_BOOT_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_INT1_CTRL, (u8_t *)value, 1)) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_INT1_BOOT_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_FIFO_TSHLD_on_INT1 +* Description : Write INT1_FTH +* Input : LSM6DSL_ACC_GYRO_INT1_FTH_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_FIFO_TSHLD_on_INT1(void *handle, LSM6DSL_ACC_GYRO_INT1_FTH_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_INT1_CTRL, &value, 1) ) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_INT1_FTH_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_INT1_CTRL, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_FIFO_TSHLD_on_INT1 +* Description : Read INT1_FTH +* Input : Pointer to LSM6DSL_ACC_GYRO_INT1_FTH_t +* Output : Status of INT1_FTH see LSM6DSL_ACC_GYRO_INT1_FTH_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_FIFO_TSHLD_on_INT1(void *handle, LSM6DSL_ACC_GYRO_INT1_FTH_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_INT1_CTRL, (u8_t *)value, 1)) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_INT1_FTH_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_OVERRUN_on_INT1 +* Description : Write INT1_OVR +* Input : LSM6DSL_ACC_GYRO_INT1_OVR_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_OVERRUN_on_INT1(void *handle, LSM6DSL_ACC_GYRO_INT1_OVR_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_INT1_CTRL, &value, 1)) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_INT1_OVR_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_INT1_CTRL, &value, 1)) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_OVERRUN_on_INT1 +* Description : Read INT1_OVR +* Input : Pointer to LSM6DSL_ACC_GYRO_INT1_OVR_t +* Output : Status of INT1_OVR see LSM6DSL_ACC_GYRO_INT1_OVR_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_OVERRUN_on_INT1(void *handle, LSM6DSL_ACC_GYRO_INT1_OVR_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_INT1_CTRL, (u8_t *)value, 1)) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_INT1_OVR_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_FULL_FLAG_on_INT1 +* Description : Write INT1_FULL_FLAG +* Input : LSM6DSL_ACC_GYRO_INT1_FULL_FLAG_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_FULL_FLAG_on_INT1(void *handle, LSM6DSL_ACC_GYRO_INT1_FULL_FLAG_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_INT1_CTRL, &value, 1)) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_INT1_FULL_FLAG_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_INT1_CTRL, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_FULL_FLAG_on_INT1 +* Description : Read INT1_FULL_FLAG +* Input : Pointer to LSM6DSL_ACC_GYRO_INT1_FULL_FLAG_t +* Output : Status of INT1_FULL_FLAG see LSM6DSL_ACC_GYRO_INT1_FULL_FLAG_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_FULL_FLAG_on_INT1(void *handle, LSM6DSL_ACC_GYRO_INT1_FULL_FLAG_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_INT1_CTRL, (u8_t *)value, 1)) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_INT1_FULL_FLAG_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_SIGN_MOT_on_INT1 +* Description : Write INT1_SIGN_MOT +* Input : LSM6DSL_ACC_GYRO_INT1_SIGN_MOT_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_SIGN_MOT_on_INT1(void *handle, LSM6DSL_ACC_GYRO_INT1_SIGN_MOT_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_INT1_CTRL, &value, 1)) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_INT1_SIGN_MOT_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_INT1_CTRL, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_SIGN_MOT_on_INT1 +* Description : Read INT1_SIGN_MOT +* Input : Pointer to LSM6DSL_ACC_GYRO_INT1_SIGN_MOT_t +* Output : Status of INT1_SIGN_MOT see LSM6DSL_ACC_GYRO_INT1_SIGN_MOT_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_SIGN_MOT_on_INT1(void *handle, LSM6DSL_ACC_GYRO_INT1_SIGN_MOT_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_INT1_CTRL, (u8_t *)value, 1)) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_INT1_SIGN_MOT_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_STEP_DET_on_INT1 +* Description : Write INT1_PEDO +* Input : LSM6DSL_ACC_GYRO_INT1_PEDO_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_STEP_DET_on_INT1(void *handle, LSM6DSL_ACC_GYRO_INT1_PEDO_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_INT1_CTRL, &value, 1)) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_INT1_PEDO_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_INT1_CTRL, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_STEP_DET_on_INT1 +* Description : Read INT1_PEDO +* Input : Pointer to LSM6DSL_ACC_GYRO_INT1_PEDO_t +* Output : Status of INT1_PEDO see LSM6DSL_ACC_GYRO_INT1_PEDO_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_STEP_DET_on_INT1(void *handle, LSM6DSL_ACC_GYRO_INT1_PEDO_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_INT1_CTRL, (u8_t *)value, 1)) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_INT1_PEDO_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_DRDY_XL_on_INT2 +* Description : Write INT2_DRDY_XL +* Input : LSM6DSL_ACC_GYRO_INT2_DRDY_XL_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_DRDY_XL_on_INT2(void *handle, LSM6DSL_ACC_GYRO_INT2_DRDY_XL_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_INT2_CTRL, &value, 1)) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_INT2_DRDY_XL_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_INT2_CTRL, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_DRDY_XL_on_INT2 +* Description : Read INT2_DRDY_XL +* Input : Pointer to LSM6DSL_ACC_GYRO_INT2_DRDY_XL_t +* Output : Status of INT2_DRDY_XL see LSM6DSL_ACC_GYRO_INT2_DRDY_XL_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_DRDY_XL_on_INT2(void *handle, LSM6DSL_ACC_GYRO_INT2_DRDY_XL_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_INT2_CTRL, (u8_t *)value, 1)) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_INT2_DRDY_XL_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_DRDY_G_on_INT2 +* Description : Write INT2_DRDY_G +* Input : LSM6DSL_ACC_GYRO_INT2_DRDY_G_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_DRDY_G_on_INT2(void *handle, LSM6DSL_ACC_GYRO_INT2_DRDY_G_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_INT2_CTRL, &value, 1)) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_INT2_DRDY_G_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_INT2_CTRL, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_DRDY_G_on_INT2 +* Description : Read INT2_DRDY_G +* Input : Pointer to LSM6DSL_ACC_GYRO_INT2_DRDY_G_t +* Output : Status of INT2_DRDY_G see LSM6DSL_ACC_GYRO_INT2_DRDY_G_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_DRDY_G_on_INT2(void *handle, LSM6DSL_ACC_GYRO_INT2_DRDY_G_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_INT2_CTRL, (u8_t *)value, 1)) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_INT2_DRDY_G_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_DRDY_TEMP_on_INT2 +* Description : Write INT2_DRDY_TEMP +* Input : LSM6DSL_ACC_GYRO_INT2_DRDY_TEMP_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_DRDY_TEMP_on_INT2(void *handle, LSM6DSL_ACC_GYRO_INT2_DRDY_TEMP_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_INT2_CTRL, &value, 1)) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_INT2_DRDY_TEMP_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_INT2_CTRL, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_DRDY_TEMP_on_INT2 +* Description : Read INT2_DRDY_TEMP +* Input : Pointer to LSM6DSL_ACC_GYRO_INT2_DRDY_TEMP_t +* Output : Status of INT2_DRDY_TEMP see LSM6DSL_ACC_GYRO_INT2_DRDY_TEMP_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_DRDY_TEMP_on_INT2(void *handle, LSM6DSL_ACC_GYRO_INT2_DRDY_TEMP_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_INT2_CTRL, (u8_t *)value, 1)) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_INT2_DRDY_TEMP_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_FIFO_TSHLD_on_INT2 +* Description : Write INT2_FTH +* Input : LSM6DSL_ACC_GYRO_INT2_FTH_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_FIFO_TSHLD_on_INT2(void *handle, LSM6DSL_ACC_GYRO_INT2_FTH_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_INT2_CTRL, &value, 1)) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_INT2_FTH_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_INT2_CTRL, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_FIFO_TSHLD_on_INT2 +* Description : Read INT2_FTH +* Input : Pointer to LSM6DSL_ACC_GYRO_INT2_FTH_t +* Output : Status of INT2_FTH see LSM6DSL_ACC_GYRO_INT2_FTH_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_FIFO_TSHLD_on_INT2(void *handle, LSM6DSL_ACC_GYRO_INT2_FTH_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_INT2_CTRL, (u8_t *)value, 1)) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_INT2_FTH_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_OVERRUN_on_INT2 +* Description : Write INT2_OVR +* Input : LSM6DSL_ACC_GYRO_INT2_OVR_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_OVERRUN_on_INT2(void *handle, LSM6DSL_ACC_GYRO_INT2_OVR_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_INT2_CTRL, &value, 1)) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_INT2_OVR_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_INT2_CTRL, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_OVERRUN_on_INT2 +* Description : Read INT2_OVR +* Input : Pointer to LSM6DSL_ACC_GYRO_INT2_OVR_t +* Output : Status of INT2_OVR see LSM6DSL_ACC_GYRO_INT2_OVR_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_OVERRUN_on_INT2(void *handle, LSM6DSL_ACC_GYRO_INT2_OVR_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_INT2_CTRL, (u8_t *)value, 1)) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_INT2_OVR_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_FULL_FLAG_on_INT2 +* Description : Write INT2_FULL_FLAG +* Input : LSM6DSL_ACC_GYRO_INT2_FULL_FLAG_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_FULL_FLAG_on_INT2(void *handle, LSM6DSL_ACC_GYRO_INT2_FULL_FLAG_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_INT2_CTRL, &value, 1)) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_INT2_FULL_FLAG_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_INT2_CTRL, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_FULL_FLAG_on_INT2 +* Description : Read INT2_FULL_FLAG +* Input : Pointer to LSM6DSL_ACC_GYRO_INT2_FULL_FLAG_t +* Output : Status of INT2_FULL_FLAG see LSM6DSL_ACC_GYRO_INT2_FULL_FLAG_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_FULL_FLAG_on_INT2(void *handle, LSM6DSL_ACC_GYRO_INT2_FULL_FLAG_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_INT2_CTRL, (u8_t *)value, 1)) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_INT2_FULL_FLAG_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_STEP_COUNT_OV_on_INT2 +* Description : Write INT2_STEP_COUNT_OV +* Input : LSM6DSL_ACC_GYRO_INT2_STEP_COUNT_OV_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_STEP_COUNT_OV_on_INT2(void *handle, LSM6DSL_ACC_GYRO_INT2_STEP_COUNT_OV_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_INT2_CTRL, &value, 1)) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_INT2_STEP_COUNT_OV_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_INT2_CTRL, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_STEP_COUNT_OV_on_INT2 +* Description : Read INT2_STEP_COUNT_OV +* Input : Pointer to LSM6DSL_ACC_GYRO_INT2_STEP_COUNT_OV_t +* Output : Status of INT2_STEP_COUNT_OV see LSM6DSL_ACC_GYRO_INT2_STEP_COUNT_OV_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_STEP_COUNT_OV_on_INT2(void *handle, LSM6DSL_ACC_GYRO_INT2_STEP_COUNT_OV_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_INT2_CTRL, (u8_t *)value, 1)) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_INT2_STEP_COUNT_OV_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_STEP_DELTA_on_INT2 +* Description : Write INT2_STEP_DELTA +* Input : LSM6DSL_ACC_GYRO_INT2_STEP_DELTA_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_STEP_DELTA_on_INT2(void *handle, LSM6DSL_ACC_GYRO_INT2_STEP_DELTA_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_INT2_CTRL, &value, 1)) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_INT2_STEP_DELTA_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_INT2_CTRL, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_STEP_DELTA_on_INT2 +* Description : Read INT2_STEP_DELTA +* Input : Pointer to LSM6DSL_ACC_GYRO_INT2_STEP_DELTA_t +* Output : Status of INT2_STEP_DELTA see LSM6DSL_ACC_GYRO_INT2_STEP_DELTA_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_STEP_DELTA_on_INT2(void *handle, LSM6DSL_ACC_GYRO_INT2_STEP_DELTA_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_INT2_CTRL, (u8_t *)value, 1)) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_INT2_STEP_DELTA_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_SW_RESET +* Description : Write SW_RESET +* Input : LSM6DSL_ACC_GYRO_SW_RESET_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_SW_RESET(void *handle, LSM6DSL_ACC_GYRO_SW_RESET_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL3_C, &value, 1)) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_SW_RESET_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_CTRL3_C, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_SW_RESET +* Description : Read SW_RESET +* Input : Pointer to LSM6DSL_ACC_GYRO_SW_RESET_t +* Output : Status of SW_RESET see LSM6DSL_ACC_GYRO_SW_RESET_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_SW_RESET(void *handle, LSM6DSL_ACC_GYRO_SW_RESET_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL3_C, (u8_t *)value, 1)) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_SW_RESET_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_IF_Addr_Incr +* Description : Write IF_INC +* Input : LSM6DSL_ACC_GYRO_IF_INC_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_IF_Addr_Incr(void *handle, LSM6DSL_ACC_GYRO_IF_INC_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL3_C, &value, 1)) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_IF_INC_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_CTRL3_C, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_IF_Addr_Incr +* Description : Read IF_INC +* Input : Pointer to LSM6DSL_ACC_GYRO_IF_INC_t +* Output : Status of IF_INC see LSM6DSL_ACC_GYRO_IF_INC_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_IF_Addr_Incr(void *handle, LSM6DSL_ACC_GYRO_IF_INC_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL3_C, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_IF_INC_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_SPI_Mode +* Description : Write SIM +* Input : LSM6DSL_ACC_GYRO_SIM_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_SPI_Mode(void *handle, LSM6DSL_ACC_GYRO_SIM_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL3_C, &value, 1)) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_SIM_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_CTRL3_C, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_SPI_Mode +* Description : Read SIM +* Input : Pointer to LSM6DSL_ACC_GYRO_SIM_t +* Output : Status of SIM see LSM6DSL_ACC_GYRO_SIM_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_SPI_Mode(void *handle, LSM6DSL_ACC_GYRO_SIM_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL3_C, (u8_t *)value, 1)) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_SIM_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_PadSel +* Description : Write PP_OD +* Input : LSM6DSL_ACC_GYRO_PP_OD_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_PadSel(void *handle, LSM6DSL_ACC_GYRO_PP_OD_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL3_C, &value, 1)) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_PP_OD_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_CTRL3_C, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_PadSel +* Description : Read PP_OD +* Input : Pointer to LSM6DSL_ACC_GYRO_PP_OD_t +* Output : Status of PP_OD see LSM6DSL_ACC_GYRO_PP_OD_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_PadSel(void *handle, LSM6DSL_ACC_GYRO_PP_OD_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL3_C, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_PP_OD_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_INT_ACT_LEVEL +* Description : Write INT_ACT_LEVEL +* Input : LSM6DSL_ACC_GYRO_INT_ACT_LEVEL_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_INT_ACT_LEVEL(void *handle, LSM6DSL_ACC_GYRO_INT_ACT_LEVEL_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL3_C, &value, 1)) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_INT_ACT_LEVEL_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_CTRL3_C, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_INT_ACT_LEVEL +* Description : Read INT_ACT_LEVEL +* Input : Pointer to LSM6DSL_ACC_GYRO_INT_ACT_LEVEL_t +* Output : Status of INT_ACT_LEVEL see LSM6DSL_ACC_GYRO_INT_ACT_LEVEL_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_INT_ACT_LEVEL(void *handle, LSM6DSL_ACC_GYRO_INT_ACT_LEVEL_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL3_C, (u8_t *)value, 1)) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_INT_ACT_LEVEL_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_BOOT +* Description : Write BOOT +* Input : LSM6DSL_ACC_GYRO_BOOT_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_BOOT(void *handle, LSM6DSL_ACC_GYRO_BOOT_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL3_C, &value, 1)) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_BOOT_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_CTRL3_C, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_BOOT +* Description : Read BOOT +* Input : Pointer to LSM6DSL_ACC_GYRO_BOOT_t +* Output : Status of BOOT see LSM6DSL_ACC_GYRO_BOOT_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_BOOT(void *handle, LSM6DSL_ACC_GYRO_BOOT_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL3_C, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_BOOT_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_LPF1_SEL_G +* Description : Write LPF1_SEL_G +* Input : LSM6DSL_ACC_GYRO_LPF1_SEL_G_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_LPF1_SEL_G(void *handle, LSM6DSL_ACC_GYRO_LPF1_SEL_G_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL4_C, &value, 1)) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_LPF1_SEL_G_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_CTRL4_C, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_LPF1_SEL_G +* Description : Read LPF1_SEL_G +* Input : Pointer to LSM6DSL_ACC_GYRO_LPF1_SEL_G_t +* Output : Status of LPF1_SEL_G see LSM6DSL_ACC_GYRO_LPF1_SEL_G_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_LPF1_SEL_G(void *handle, LSM6DSL_ACC_GYRO_LPF1_SEL_G_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL4_C, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_LPF1_SEL_G_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_I2C_DISABLE +* Description : Write I2C_DISABLE +* Input : LSM6DSL_ACC_GYRO_I2C_DISABLE_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_I2C_DISABLE(void *handle, LSM6DSL_ACC_GYRO_I2C_DISABLE_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL4_C, &value, 1)) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_I2C_DISABLE_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_CTRL4_C, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_I2C_DISABLE +* Description : Read I2C_DISABLE +* Input : Pointer to LSM6DSL_ACC_GYRO_I2C_DISABLE_t +* Output : Status of I2C_DISABLE see LSM6DSL_ACC_GYRO_I2C_DISABLE_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_I2C_DISABLE(void *handle, LSM6DSL_ACC_GYRO_I2C_DISABLE_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL4_C, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_I2C_DISABLE_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_DRDY_MSK +* Description : Write DRDY_MSK +* Input : LSM6DSL_ACC_GYRO_DRDY_MSK_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_DRDY_MSK(void *handle, LSM6DSL_ACC_GYRO_DRDY_MSK_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL4_C, &value, 1)) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_DRDY_MSK_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_CTRL4_C, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_DRDY_MSK +* Description : Read DRDY_MSK +* Input : Pointer to LSM6DSL_ACC_GYRO_DRDY_MSK_t +* Output : Status of DRDY_MSK see LSM6DSL_ACC_GYRO_DRDY_MSK_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_DRDY_MSK(void *handle, LSM6DSL_ACC_GYRO_DRDY_MSK_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL4_C, (u8_t *)value, 1)) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_DRDY_MSK_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_INT2_ON_INT1 +* Description : Write INT2_ON_INT1 +* Input : LSM6DSL_ACC_GYRO_INT2_ON_INT1_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_INT2_ON_INT1(void *handle, LSM6DSL_ACC_GYRO_INT2_ON_INT1_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL4_C, &value, 1)) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_INT2_ON_INT1_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_CTRL4_C, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_INT2_ON_INT1 +* Description : Read INT2_ON_INT1 +* Input : Pointer to LSM6DSL_ACC_GYRO_INT2_ON_INT1_t +* Output : Status of INT2_ON_INT1 see LSM6DSL_ACC_GYRO_INT2_ON_INT1_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_INT2_ON_INT1(void *handle, LSM6DSL_ACC_GYRO_INT2_ON_INT1_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL4_C, (u8_t *)value, 1)) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_INT2_ON_INT1_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_SleepMode_G +* Description : Write SLEEP_G +* Input : LSM6DSL_ACC_GYRO_SLEEP_G_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_SleepMode_G(void *handle, LSM6DSL_ACC_GYRO_SLEEP_G_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL4_C, &value, 1)) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_SLEEP_G_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_CTRL4_C, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_SleepMode_G +* Description : Read SLEEP_G +* Input : Pointer to LSM6DSL_ACC_GYRO_SLEEP_G_t +* Output : Status of SLEEP_G see LSM6DSL_ACC_GYRO_SLEEP_G_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_SleepMode_G(void *handle, LSM6DSL_ACC_GYRO_SLEEP_G_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL4_C, (u8_t *)value, 1)) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_SLEEP_G_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_SelfTest_XL +* Description : Write ST_XL +* Input : LSM6DSL_ACC_GYRO_ST_XL_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_SelfTest_XL(void *handle, LSM6DSL_ACC_GYRO_ST_XL_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL5_C, &value, 1)) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_ST_XL_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_CTRL5_C, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_SelfTest_XL +* Description : Read ST_XL +* Input : Pointer to LSM6DSL_ACC_GYRO_ST_XL_t +* Output : Status of ST_XL see LSM6DSL_ACC_GYRO_ST_XL_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_SelfTest_XL(void *handle, LSM6DSL_ACC_GYRO_ST_XL_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL5_C, (u8_t *)value, 1)) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_ST_XL_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_SelfTest_G +* Description : Write ST_G +* Input : LSM6DSL_ACC_GYRO_ST_G_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_SelfTest_G(void *handle, LSM6DSL_ACC_GYRO_ST_G_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL5_C, &value, 1)) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_ST_G_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_CTRL5_C, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_SelfTest_G +* Description : Read ST_G +* Input : Pointer to LSM6DSL_ACC_GYRO_ST_G_t +* Output : Status of ST_G see LSM6DSL_ACC_GYRO_ST_G_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_SelfTest_G(void *handle, LSM6DSL_ACC_GYRO_ST_G_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL5_C, (u8_t *)value, 1)) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_ST_G_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_DEN_Polarity +* Description : Write DEN_LH +* Input : LSM6DSL_ACC_GYRO_DEN_LH_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_DEN_Polarity(void *handle, LSM6DSL_ACC_GYRO_DEN_LH_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL5_C, &value, 1)) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_DEN_LH_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_CTRL5_C, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_DEN_Polarity +* Description : Read DEN_LH +* Input : Pointer to LSM6DSL_ACC_GYRO_DEN_LH_t +* Output : Status of DEN_LH see LSM6DSL_ACC_GYRO_DEN_LH_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_DEN_Polarity(void *handle, LSM6DSL_ACC_GYRO_DEN_LH_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL5_C, (u8_t *)value, 1)) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_DEN_LH_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_CircularBurstMode +* Description : Write ST_ROUNDING +* Input : LSM6DSL_ACC_GYRO_ROUNDING_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_CircularBurstMode(void *handle, LSM6DSL_ACC_GYRO_ROUNDING_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL5_C, &value, 1)) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_LSM6DSL_ACC_GYRO_ROUNDING_t_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_CTRL5_C, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_CircularBurstMode +* Description : Read ST_ROUNDING +* Input : Pointer to LSM6DSL_ACC_GYRO_ROUNDING_t +* Output : Status of ST_ROUNDING see LSM6DSL_ACC_GYRO_ROUNDING_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_CircularBurstMode(void *handle, LSM6DSL_ACC_GYRO_ROUNDING_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL5_C, (u8_t *)value, 1)) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_LSM6DSL_ACC_GYRO_ROUNDING_t_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_LP_BW_G +* Description : Write FTYPE +* Input : LSM6DSL_ACC_GYRO_FTYPE_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_LP_BW_G(void *handle, LSM6DSL_ACC_GYRO_FTYPE_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL6_G, &value, 1)) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_FTYPE_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_CTRL6_G, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_LP_BW_G +* Description : Read FTYPE +* Input : Pointer to LSM6DSL_ACC_GYRO_FTYPE_t +* Output : Status of FTYPE see LSM6DSL_ACC_GYRO_FTYPE_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_LP_BW_G(void *handle, LSM6DSL_ACC_GYRO_FTYPE_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL6_G, (u8_t *)value, 1)) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_FTYPE_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_UserOffsetWeight +* Description : Write USR_OFF_W +* Input : LSM6DSL_ACC_GYRO_USR_OFF_W_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_UserOffsetWeight(void *handle, LSM6DSL_ACC_GYRO_USR_OFF_W_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL6_G, &value, 1)) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_USR_OFF_W_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_CTRL6_G, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_UserOffsetWeight +* Description : Read USR_OFF_W +* Input : Pointer to LSM6DSL_ACC_GYRO_USR_OFF_W_t +* Output : Status of USR_OFF_W see LSM6DSL_ACC_GYRO_USR_OFF_W_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_UserOffsetWeight(void *handle, LSM6DSL_ACC_GYRO_USR_OFF_W_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL6_G, (u8_t *)value, 1)) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_USR_OFF_W_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_LowPower_XL +* Description : Write LP_XL +* Input : LSM6DSL_ACC_GYRO_LP_XL_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_LowPower_XL(void *handle, LSM6DSL_ACC_GYRO_LP_XL_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL6_G, &value, 1)) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_LP_XL_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_CTRL6_G, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_LowPower_XL +* Description : Read LP_XL +* Input : Pointer to LSM6DSL_ACC_GYRO_LP_XL_t +* Output : Status of LP_XL see LSM6DSL_ACC_GYRO_LP_XL_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_LowPower_XL(void *handle, LSM6DSL_ACC_GYRO_LP_XL_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL6_G, (u8_t *)value, 1)) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_LP_XL_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_DEN_LVL2_EN +* Description : Write DEN_LVL2_EN +* Input : LSM6DSL_ACC_GYRO_DEN_LVL2_EN_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_DEN_LVL2_EN(void *handle, LSM6DSL_ACC_GYRO_DEN_LVL2_EN_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL6_G, &value, 1)) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_DEN_LVL2_EN_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_CTRL6_G, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_DEN_LVL2_EN +* Description : Read DEN_LVL2_EN +* Input : Pointer to LSM6DSL_ACC_GYRO_DEN_LVL2_EN_t +* Output : Status of DEN_LVL2_EN see LSM6DSL_ACC_GYRO_DEN_LVL2_EN_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_DEN_LVL2_EN(void *handle, LSM6DSL_ACC_GYRO_DEN_LVL2_EN_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL6_G, (u8_t *)value, 1)) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_DEN_LVL2_EN_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_DEN_LVL_EN +* Description : Write DEN_LVL_EN +* Input : LSM6DSL_ACC_GYRO_DEN_LVL_EN_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_DEN_LVL_EN(void *handle, LSM6DSL_ACC_GYRO_DEN_LVL_EN_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL6_G, &value, 1)) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_DEN_LVL_EN_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_CTRL6_G, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_DEN_LVL_EN +* Description : Read DEN_LVL_EN +* Input : Pointer to LSM6DSL_ACC_GYRO_DEN_LVL_EN_t +* Output : Status of DEN_LVL_EN see LSM6DSL_ACC_GYRO_DEN_LVL_EN_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_DEN_LVL_EN(void *handle, LSM6DSL_ACC_GYRO_DEN_LVL_EN_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL6_G, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_DEN_LVL_EN_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_ExternalTrigger +* Description : Write DEN_EDGE_EN +* Input : LSM6DSL_ACC_GYRO_DEN_EDGE_EN_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_ExternalTrigger(void *handle, LSM6DSL_ACC_GYRO_DEN_EDGE_EN_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL6_G, &value, 1) ) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_DEN_EDGE_EN_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_CTRL6_G, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_ExternalTrigger +* Description : Read DEN_EDGE_EN +* Input : Pointer to LSM6DSL_ACC_GYRO_DEN_EDGE_EN_t +* Output : Status of DEN_EDGE_EN see LSM6DSL_ACC_GYRO_DEN_EDGE_EN_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_ExternalTrigger(void *handle, LSM6DSL_ACC_GYRO_DEN_EDGE_EN_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL6_G, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_DEN_EDGE_EN_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_HPM_G +* Description : Write HPM_G +* Input : LSM6DSL_ACC_GYRO_HPM_G_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_HPM_G(void *handle, LSM6DSL_ACC_GYRO_HPM_G_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL7_G, &value, 1) ) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_HPM_G_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_CTRL7_G, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_HPM_G +* Description : Read HPM_G +* Input : Pointer to LSM6DSL_ACC_GYRO_HPM_G_t +* Output : Status of HPM_G see LSM6DSL_ACC_GYRO_HPM_G_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_HPM_G(void *handle, LSM6DSL_ACC_GYRO_HPM_G_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL7_G, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_HPM_G_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_RoundingOnStatusRegisters +* Description : Write HPM_G +* Input : LSM6DSL_ACC_GYRO_RND_STATUS_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_RoundingOnStatusRegisters(void *handle, LSM6DSL_ACC_GYRO_RND_STATUS_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL7_G, &value, 1) ) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_RND_STATUS_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_CTRL7_G, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_RoundingOnStatusRegisters +* Description : Read HPM_G +* Input : Pointer to LSM6DSL_ACC_GYRO_RND_STATUS_t +* Output : Status of HPM_G see LSM6DSL_ACC_GYRO_RND_STATUS_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_RoundingOnStatusRegisters(void *handle, LSM6DSL_ACC_GYRO_RND_STATUS_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL7_G, (u8_t *)value, 1)) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_RND_STATUS_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_HPFilter_En +* Description : Write HP_EN +* Input : LSM6DSL_ACC_GYRO_HP_EN_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_HPFilter_En(void *handle, LSM6DSL_ACC_GYRO_HP_EN_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL7_G, &value, 1) ) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_HP_EN_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_CTRL7_G, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_HPFilter_En +* Description : Read HP_EN +* Input : Pointer to LSM6DSL_ACC_GYRO_HP_EN_t +* Output : Status of HP_EN see LSM6DSL_ACC_GYRO_HP_EN_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_HPFilter_En(void *handle, LSM6DSL_ACC_GYRO_HP_EN_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL7_G, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_HP_EN_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_LP_Mode +* Description : Write LP_EN +* Input : LSM6DSL_ACC_GYRO_LP_EN_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_LP_Mode(void *handle, LSM6DSL_ACC_GYRO_LP_EN_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL7_G, &value, 1) ) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_LP_EN_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_CTRL7_G, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_LP_Mode +* Description : Read LP_EN +* Input : Pointer to LSM6DSL_ACC_GYRO_LP_EN_t +* Output : Status of LP_EN see LSM6DSL_ACC_GYRO_LP_EN_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_LP_Mode(void *handle, LSM6DSL_ACC_GYRO_LP_EN_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL7_G, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_LP_EN_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_ROUNDING_STATUS +* Description : Write ROUNDING_STATUS +* Input : LSM6DSL_ACC_GYRO_ROUNDING_STATUS_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_ROUNDING_STATUS(void *handle, LSM6DSL_ACC_GYRO_ROUNDING_STATUS_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL7_G, &value, 1) ) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_ROUNDING_STATUS_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_CTRL7_G, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_ROUNDING_STATUS +* Description : Read ROUNDING_STATUS +* Input : Pointer to LSM6DSL_ACC_GYRO_ROUNDING_STATUS_t +* Output : Status of ROUNDING_STATUS see LSM6DSL_ACC_GYRO_ROUNDING_STATUS_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_ROUNDING_STATUS(void *handle, LSM6DSL_ACC_GYRO_ROUNDING_STATUS_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL7_G, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_ROUNDING_STATUS_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_HP_G_RST +* Description : Write HP_G_RST +* Input : LSM6DSL_ACC_GYRO_HP_G_RST_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_HP_G_RST(void *handle, LSM6DSL_ACC_GYRO_HP_G_RST_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL7_G, &value, 1) ) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_HP_G_RST_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_CTRL7_G, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_HP_G_RST +* Description : Read HP_G_RST +* Input : Pointer to LSM6DSL_ACC_GYRO_HP_G_RST_t +* Output : Status of HP_G_RST see LSM6DSL_ACC_GYRO_HP_G_RST_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_HP_G_RST(void *handle, LSM6DSL_ACC_GYRO_HP_G_RST_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL7_G, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_HP_G_RST_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_InComposit +* Description : Write INPUT_COMPOSITE +* Input : LSM6DSL_ACC_GYRO_IN_COMP_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_InComposit(void *handle, LSM6DSL_ACC_GYRO_IN_COMP_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL8_XL, &value, 1) ) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_IN_COMP_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_CTRL8_XL, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_InComposit +* Description : Read INPUT_COMPOSITE +* Input : Pointer to LSM6DSL_ACC_GYRO_IN_COMP_t +* Output : Status of INPUT_COMPOSITE see LSM6DSL_ACC_GYRO_IN_COMP_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_InComposit(void *handle, LSM6DSL_ACC_GYRO_IN_COMP_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL8_XL, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_IN_COMP_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_HPfilterReference +* Description : Write HP_REF_MODE +* Input : LSM6DSL_ACC_GYRO_HP_REF_MODE_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_HPfilterReference(void *handle, LSM6DSL_ACC_GYRO_HP_REF_MODE_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL8_XL, &value, 1) ) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_HP_REF_MODE_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_CTRL8_XL, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_HPfilterReference +* Description : Read HP_REF_MODE +* Input : Pointer to LSM6DSL_ACC_GYRO_HP_REF_MODE_t +* Output : Status of HP_REF_MODE see LSM6DSL_ACC_GYRO_HP_REF_MODE_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_HPfilterReference(void *handle, LSM6DSL_ACC_GYRO_HP_REF_MODE_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL8_XL, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_HP_REF_MODE_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_HPCF_XL +* Description : Write HPCF_XL +* Input : LSM6DSL_ACC_GYRO_HPCF_XL_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_HPCF_XL(void *handle, LSM6DSL_ACC_GYRO_HPCF_XL_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL8_XL, &value, 1) ) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_HPCF_XL_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_CTRL8_XL, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_HPCF_XL +* Description : Read HPCF_XL +* Input : Pointer to LSM6DSL_ACC_GYRO_HPCF_XL_t +* Output : Status of HPCF_XL see LSM6DSL_ACC_GYRO_HPCF_XL_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_HPCF_XL(void *handle, LSM6DSL_ACC_GYRO_HPCF_XL_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL8_XL, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_HPCF_XL_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_LowPassFiltSel_XL +* Description : Write LPF2_XL_EN +* Input : LSM6DSL_ACC_GYRO_LPF2_XL_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_LowPassFiltSel_XL(void *handle, LSM6DSL_ACC_GYRO_LPF2_XL_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL8_XL, &value, 1) ) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_LPF2_XL_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_CTRL8_XL, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_LowPassFiltSel_XL +* Description : Read LPF2_XL_EN +* Input : Pointer to LSM6DSL_ACC_GYRO_LPF2_XL_t +* Output : Status of LPF2_XL_EN see LSM6DSL_ACC_GYRO_LPF2_XL_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_LowPassFiltSel_XL(void *handle, LSM6DSL_ACC_GYRO_LPF2_XL_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL8_XL, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_LPF2_XL_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_LOW_PASS_ON_6D +* Description : Write LOW_PASS_ON_6D +* Input : LSM6DSL_ACC_GYRO_LOW_PASS_ON_6D_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_LOW_PASS_ON_6D(void *handle, LSM6DSL_ACC_GYRO_LOW_PASS_ON_6D_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL8_XL, &value, 1) ) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_LOW_PASS_ON_6D_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_CTRL8_XL, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_LOW_PASS_ON_6D +* Description : Read LOW_PASS_ON_6D +* Input : Pointer to LSM6DSL_ACC_GYRO_LOW_PASS_ON_6D_t +* Output : Status of LOW_PASS_ON_6D see LSM6DSL_ACC_GYRO_LOW_PASS_ON_6D_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_LOW_PASS_ON_6D(void *handle, LSM6DSL_ACC_GYRO_LOW_PASS_ON_6D_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL8_XL, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_LOW_PASS_ON_6D_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_HP_SLOPE_XL +* Description : Write HP_SLOPE_XL_EN +* Input : LSM6DSL_ACC_GYRO_HP_SLOPE_XL_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_HP_SLOPE_XL(void *handle, LSM6DSL_ACC_GYRO_HP_SLOPE_XL_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL8_XL, &value, 1) ) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_HP_SLOPE_XL_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_CTRL8_XL, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_HP_SLOPE_XL +* Description : Read HP_SLOPE_XL_EN +* Input : Pointer to LSM6DSL_ACC_GYRO_HP_SLOPE_XL_t +* Output : Status of HP_SLOPE_XL_EN see LSM6DSL_ACC_GYRO_HP_SLOPE_XL_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_HP_SLOPE_XL(void *handle, LSM6DSL_ACC_GYRO_HP_SLOPE_XL_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL8_XL, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_HP_SLOPE_XL_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_SOFT +* Description : Write SOFT_EN +* Input : LSM6DSL_ACC_GYRO_SOFT_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_SOFT(void *handle, LSM6DSL_ACC_GYRO_SOFT_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL9_XL, &value, 1) ) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_SOFT_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_CTRL9_XL, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_SOFT +* Description : Read SOFT_EN +* Input : Pointer to LSM6DSL_ACC_GYRO_SOFT_t +* Output : Status of SOFT_EN see LSM6DSL_ACC_GYRO_SOFT_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_SOFT(void *handle, LSM6DSL_ACC_GYRO_SOFT_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL9_XL, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_SOFT_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_SignifcantMotion +* Description : Write SIGN_MOTION_EN +* Input : LSM6DSL_ACC_GYRO_SIGN_MOTION_EN_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_SignifcantMotion(void *handle, LSM6DSL_ACC_GYRO_SIGN_MOTION_EN_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL10_C, &value, 1) ) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_SIGN_MOTION_EN_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_CTRL10_C, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_SignifcantMotion +* Description : Read SIGN_MOTION_EN +* Input : Pointer to LSM6DSL_ACC_GYRO_SIGN_MOTION_EN_t +* Output : Status of SIGN_MOTION_EN see LSM6DSL_ACC_GYRO_SIGN_MOTION_EN_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_SignifcantMotion(void *handle, LSM6DSL_ACC_GYRO_SIGN_MOTION_EN_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL10_C, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_SIGN_MOTION_EN_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_PedoStepReset +* Description : Write PEDO_RST_STEP +* Input : LSM6DSL_ACC_GYRO_PEDO_RST_STEP_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_PedoStepReset(void *handle, LSM6DSL_ACC_GYRO_PEDO_RST_STEP_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL10_C, &value, 1) ) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_PEDO_RST_STEP_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_CTRL10_C, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_PedoStepReset +* Description : Read PEDO_RST_STEP +* Input : Pointer to LSM6DSL_ACC_GYRO_PEDO_RST_STEP_t +* Output : Status of PEDO_RST_STEP see LSM6DSL_ACC_GYRO_PEDO_RST_STEP_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_PedoStepReset(void *handle, LSM6DSL_ACC_GYRO_PEDO_RST_STEP_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL10_C, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_PEDO_RST_STEP_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_TILT +* Description : Write XEN_G +* Input : LSM6DSL_ACC_GYRO_TILT_G_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_TILT(void *handle, LSM6DSL_ACC_GYRO_TILT_G_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL10_C, &value, 1) ) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_TILT_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_CTRL10_C, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_TILT +* Description : Read XEN_G +* Input : Pointer to LSM6DSL_ACC_GYRO_TILT_G_t +* Output : Status of XEN_G see LSM6DSL_ACC_GYRO_TILT_G_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_TILT(void *handle, LSM6DSL_ACC_GYRO_TILT_G_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL10_C, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_TILT_MASK; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_PEDO +* Description : Write PEDO_EN +* Input : LSM6DSL_ACC_GYRO_PEDO_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_PEDO(void *handle, LSM6DSL_ACC_GYRO_PEDO_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL10_C, &value, 1) ) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_PEDO_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_CTRL10_C, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_PEDO +* Description : Read PEDO_EN +* Input : Pointer to LSM6DSL_ACC_GYRO_PEDO_t +* Output : Status of PEDO_EN see LSM6DSL_ACC_GYRO_PEDO_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_PEDO(void *handle, LSM6DSL_ACC_GYRO_PEDO_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL10_C, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_PEDO_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_TIMER +* Description : Write TIMER_EN +* Input : LSM6DSL_ACC_GYRO_TIMER_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_TIMER(void *handle, LSM6DSL_ACC_GYRO_TIMER_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL10_C, &value, 1) ) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_TIMER_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_CTRL10_C, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_TIMER +* Description : Read TIMER_EN +* Input : Pointer to LSM6DSL_ACC_GYRO_TIMER_t +* Output : Status of TIMER_EN see LSM6DSL_ACC_GYRO_TIMER_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_TIMER(void *handle, LSM6DSL_ACC_GYRO_TIMER_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL10_C, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_TIMER_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_FUNC_EN +* Description : Write FUNC_EN +* Input : LSM6DSL_ACC_GYRO_FUNC_EN_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_FUNC_EN(void *handle, LSM6DSL_ACC_GYRO_FUNC_EN_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL10_C, &value, 1) ) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_FUNC_EN_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_CTRL10_C, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_FUNC_EN +* Description : Read FUNC_EN +* Input : Pointer to LSM6DSL_ACC_GYRO_FUNC_EN_t +* Output : Status of FUNC_EN see LSM6DSL_ACC_GYRO_FUNC_EN_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_FUNC_EN(void *handle, LSM6DSL_ACC_GYRO_FUNC_EN_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CTRL10_C, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_FUNC_EN_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_I2C_MASTER_Enable +* Description : Write MASTER_ON +* Input : LSM6DSL_ACC_GYRO_MASTER_ON_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_I2C_MASTER_Enable(void *handle, LSM6DSL_ACC_GYRO_MASTER_ON_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_MASTER_CONFIG, &value, 1) ) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_MASTER_ON_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_MASTER_CONFIG, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_I2C_MASTER_Enable +* Description : Read MASTER_ON +* Input : Pointer to LSM6DSL_ACC_GYRO_MASTER_ON_t +* Output : Status of MASTER_ON see LSM6DSL_ACC_GYRO_MASTER_ON_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_I2C_MASTER_Enable(void *handle, LSM6DSL_ACC_GYRO_MASTER_ON_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_MASTER_CONFIG, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_MASTER_ON_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_IronCorrection_EN +* Description : Write IRON_EN +* Input : LSM6DSL_ACC_GYRO_IRON_EN_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_IronCorrection_EN(void *handle, LSM6DSL_ACC_GYRO_IRON_EN_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_MASTER_CONFIG, &value, 1) ) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_IRON_EN_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_MASTER_CONFIG, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_IronCorrection_EN +* Description : Read IRON_EN +* Input : Pointer to LSM6DSL_ACC_GYRO_IRON_EN_t +* Output : Status of IRON_EN see LSM6DSL_ACC_GYRO_IRON_EN_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_IronCorrection_EN(void *handle, LSM6DSL_ACC_GYRO_IRON_EN_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_MASTER_CONFIG, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_IRON_EN_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_PASS_THRU_MODE +* Description : Write PASS_THRU_MODE +* Input : LSM6DSL_ACC_GYRO_PASS_THRU_MODE_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_PASS_THRU_MODE(void *handle, LSM6DSL_ACC_GYRO_PASS_THRU_MODE_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_MASTER_CONFIG, &value, 1) ) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_PASS_THRU_MODE_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_MASTER_CONFIG, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_PASS_THRU_MODE +* Description : Read PASS_THRU_MODE +* Input : Pointer to LSM6DSL_ACC_GYRO_PASS_THRU_MODE_t +* Output : Status of PASS_THRU_MODE see LSM6DSL_ACC_GYRO_PASS_THRU_MODE_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_PASS_THRU_MODE(void *handle, LSM6DSL_ACC_GYRO_PASS_THRU_MODE_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_MASTER_CONFIG, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_PASS_THRU_MODE_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_PULL_UP_EN +* Description : Write PULL_UP_EN +* Input : LSM6DSL_ACC_GYRO_PULL_UP_EN_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_PULL_UP_EN(void *handle, LSM6DSL_ACC_GYRO_PULL_UP_EN_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_MASTER_CONFIG, &value, 1) ) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_PULL_UP_EN_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_MASTER_CONFIG, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_PULL_UP_EN +* Description : Read PULL_UP_EN +* Input : Pointer to LSM6DSL_ACC_GYRO_PULL_UP_EN_t +* Output : Status of PULL_UP_EN see LSM6DSL_ACC_GYRO_PULL_UP_EN_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_PULL_UP_EN(void *handle, LSM6DSL_ACC_GYRO_PULL_UP_EN_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_MASTER_CONFIG, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_PULL_UP_EN_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_SensorHUB_Trigger_Sel +* Description : Write START_CONFIG +* Input : LSM6DSL_ACC_GYRO_START_CONFIG_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_SensorHUB_Trigger_Sel(void *handle, LSM6DSL_ACC_GYRO_START_CONFIG_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_MASTER_CONFIG, &value, 1) ) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_START_CONFIG_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_MASTER_CONFIG, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_SensorHUB_Trigger_Sel +* Description : Read START_CONFIG +* Input : Pointer to LSM6DSL_ACC_GYRO_START_CONFIG_t +* Output : Status of START_CONFIG see LSM6DSL_ACC_GYRO_START_CONFIG_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_SensorHUB_Trigger_Sel(void *handle, LSM6DSL_ACC_GYRO_START_CONFIG_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_MASTER_CONFIG, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_START_CONFIG_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_DATA_VAL_SEL_FIFO +* Description : Write DATA_VAL_SEL_FIFO +* Input : LSM6DSL_ACC_GYRO_DATA_VAL_SEL_FIFO_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_DATA_VAL_SEL_FIFO(void *handle, LSM6DSL_ACC_GYRO_DATA_VAL_SEL_FIFO_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_MASTER_CONFIG, &value, 1) ) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_DATA_VAL_SEL_FIFO_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_MASTER_CONFIG, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_DATA_VAL_SEL_FIFO +* Description : Read DATA_VAL_SEL_FIFO +* Input : Pointer to LSM6DSL_ACC_GYRO_DATA_VAL_SEL_FIFO_t +* Output : Status of DATA_VAL_SEL_FIFO see LSM6DSL_ACC_GYRO_DATA_VAL_SEL_FIFO_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_DATA_VAL_SEL_FIFO(void *handle, LSM6DSL_ACC_GYRO_DATA_VAL_SEL_FIFO_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_MASTER_CONFIG, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_DATA_VAL_SEL_FIFO_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_DRDY_ON_INT1 +* Description : Write DRDY_ON_INT1 +* Input : LSM6DSL_ACC_GYRO_DRDY_ON_INT1_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_DRDY_ON_INT1(void *handle, LSM6DSL_ACC_GYRO_DRDY_ON_INT1_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_MASTER_CONFIG, &value, 1) ) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_DRDY_ON_INT1_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_MASTER_CONFIG, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_DRDY_ON_INT1 +* Description : Read DRDY_ON_INT1 +* Input : Pointer to LSM6DSL_ACC_GYRO_DRDY_ON_INT1_t +* Output : Status of DRDY_ON_INT1 see LSM6DSL_ACC_GYRO_DRDY_ON_INT1_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_DRDY_ON_INT1(void *handle, LSM6DSL_ACC_GYRO_DRDY_ON_INT1_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_MASTER_CONFIG, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_DRDY_ON_INT1_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_Z_WU +* Description : Read Z_WU +* Input : Pointer to LSM6DSL_ACC_GYRO_Z_WU_t +* Output : Status of Z_WU see LSM6DSL_ACC_GYRO_Z_WU_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_Z_WU(void *handle, LSM6DSL_ACC_GYRO_Z_WU_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_WAKE_UP_SRC, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_Z_WU_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_Y_WU +* Description : Read Y_WU +* Input : Pointer to LSM6DSL_ACC_GYRO_Y_WU_t +* Output : Status of Y_WU see LSM6DSL_ACC_GYRO_Y_WU_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_Y_WU(void *handle, LSM6DSL_ACC_GYRO_Y_WU_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_WAKE_UP_SRC, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_Y_WU_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_X_WU +* Description : Read X_WU +* Input : Pointer to LSM6DSL_ACC_GYRO_X_WU_t +* Output : Status of X_WU see LSM6DSL_ACC_GYRO_X_WU_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_X_WU(void *handle, LSM6DSL_ACC_GYRO_X_WU_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_WAKE_UP_SRC, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_X_WU_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_WU_EV_STATUS +* Description : Read WU_EV_STATUS +* Input : Pointer to LSM6DSL_ACC_GYRO_WU_EV_STATUS_t +* Output : Status of WU_EV_STATUS see LSM6DSL_ACC_GYRO_WU_EV_STATUS_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_WU_EV_STATUS(void *handle, LSM6DSL_ACC_GYRO_WU_EV_STATUS_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_WAKE_UP_SRC, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_WU_EV_STATUS_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_SLEEP_EV_STATUS +* Description : Read SLEEP_EV_STATUS +* Input : Pointer to LSM6DSL_ACC_GYRO_SLEEP_EV_STATUS_t +* Output : Status of SLEEP_EV_STATUS see LSM6DSL_ACC_GYRO_SLEEP_EV_STATUS_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_SLEEP_EV_STATUS(void *handle, LSM6DSL_ACC_GYRO_SLEEP_EV_STATUS_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_WAKE_UP_SRC, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_SLEEP_EV_STATUS_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_FF_EV_STATUS +* Description : Read FF_EV_STATUS +* Input : Pointer to LSM6DSL_ACC_GYRO_FF_EV_STATUS_t +* Output : Status of FF_EV_STATUS see LSM6DSL_ACC_GYRO_FF_EV_STATUS_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_FF_EV_STATUS(void *handle, LSM6DSL_ACC_GYRO_FF_EV_STATUS_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_WAKE_UP_SRC, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_FF_EV_STATUS_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_Z_TAP +* Description : Read Z_TAP +* Input : Pointer to LSM6DSL_ACC_GYRO_Z_TAP_t +* Output : Status of Z_TAP see LSM6DSL_ACC_GYRO_Z_TAP_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_Z_TAP(void *handle, LSM6DSL_ACC_GYRO_Z_TAP_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_TAP_SRC, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_Z_TAP_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_Y_TAP +* Description : Read Y_TAP +* Input : Pointer to LSM6DSL_ACC_GYRO_Y_TAP_t +* Output : Status of Y_TAP see LSM6DSL_ACC_GYRO_Y_TAP_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_Y_TAP(void *handle, LSM6DSL_ACC_GYRO_Y_TAP_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_TAP_SRC, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_Y_TAP_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_X_TAP +* Description : Read X_TAP +* Input : Pointer to LSM6DSL_ACC_GYRO_X_TAP_t +* Output : Status of X_TAP see LSM6DSL_ACC_GYRO_X_TAP_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_X_TAP(void *handle, LSM6DSL_ACC_GYRO_X_TAP_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_TAP_SRC, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_X_TAP_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_TAP_SIGN +* Description : Read TAP_SIGN +* Input : Pointer to LSM6DSL_ACC_GYRO_TAP_SIGN_t +* Output : Status of TAP_SIGN see LSM6DSL_ACC_GYRO_TAP_SIGN_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_TAP_SIGN(void *handle, LSM6DSL_ACC_GYRO_TAP_SIGN_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_TAP_SRC, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_TAP_SIGN_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_DOUBLE_TAP_EV_STATUS +* Description : Read DOUBLE_TAP_EV_STATUS +* Input : Pointer to LSM6DSL_ACC_GYRO_DOUBLE_TAP_EV_STATUS_t +* Output : Status of DOUBLE_TAP_EV_STATUS see LSM6DSL_ACC_GYRO_DOUBLE_TAP_EV_STATUS_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_DOUBLE_TAP_EV_STATUS(void *handle, LSM6DSL_ACC_GYRO_DOUBLE_TAP_EV_STATUS_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_TAP_SRC, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_DOUBLE_TAP_EV_STATUS_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_SINGLE_TAP_EV_STATUS +* Description : Read SINGLE_TAP_EV_STATUS +* Input : Pointer to LSM6DSL_ACC_GYRO_SINGLE_TAP_EV_STATUS_t +* Output : Status of SINGLE_TAP_EV_STATUS see LSM6DSL_ACC_GYRO_SINGLE_TAP_EV_STATUS_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_SINGLE_TAP_EV_STATUS(void *handle, LSM6DSL_ACC_GYRO_SINGLE_TAP_EV_STATUS_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_TAP_SRC, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_SINGLE_TAP_EV_STATUS_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_TAP_EV_STATUS +* Description : Read TAP_EV_STATUS +* Input : Pointer to LSM6DSL_ACC_GYRO_TAP_EV_STATUS_t +* Output : Status of TAP_EV_STATUS see LSM6DSL_ACC_GYRO_TAP_EV_STATUS_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_TAP_EV_STATUS(void *handle, LSM6DSL_ACC_GYRO_TAP_EV_STATUS_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_TAP_SRC, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_TAP_EV_STATUS_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_DSD_XL +* Description : Read DSD_XL +* Input : Pointer to LSM6DSL_ACC_GYRO_DSD_XL_t +* Output : Status of DSD_XL see LSM6DSL_ACC_GYRO_DSD_XL_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_DSD_XL(void *handle, LSM6DSL_ACC_GYRO_DSD_XL_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_D6D_SRC, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_DSD_XL_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_DSD_XH +* Description : Read DSD_XH +* Input : Pointer to LSM6DSL_ACC_GYRO_DSD_XH_t +* Output : Status of DSD_XH see LSM6DSL_ACC_GYRO_DSD_XH_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_DSD_XH(void *handle, LSM6DSL_ACC_GYRO_DSD_XH_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_D6D_SRC, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_DSD_XH_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_DSD_YL +* Description : Read DSD_YL +* Input : Pointer to LSM6DSL_ACC_GYRO_DSD_YL_t +* Output : Status of DSD_YL see LSM6DSL_ACC_GYRO_DSD_YL_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_DSD_YL(void *handle, LSM6DSL_ACC_GYRO_DSD_YL_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_D6D_SRC, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_DSD_YL_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_DSD_YH +* Description : Read DSD_YH +* Input : Pointer to LSM6DSL_ACC_GYRO_DSD_YH_t +* Output : Status of DSD_YH see LSM6DSL_ACC_GYRO_DSD_YH_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_DSD_YH(void *handle, LSM6DSL_ACC_GYRO_DSD_YH_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_D6D_SRC, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_DSD_YH_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_DSD_ZL +* Description : Read DSD_ZL +* Input : Pointer to LSM6DSL_ACC_GYRO_DSD_ZL_t +* Output : Status of DSD_ZL see LSM6DSL_ACC_GYRO_DSD_ZL_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_DSD_ZL(void *handle, LSM6DSL_ACC_GYRO_DSD_ZL_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_D6D_SRC, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_DSD_ZL_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_DSD_ZH +* Description : Read DSD_ZH +* Input : Pointer to LSM6DSL_ACC_GYRO_DSD_ZH_t +* Output : Status of DSD_ZH see LSM6DSL_ACC_GYRO_DSD_ZH_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_DSD_ZH(void *handle, LSM6DSL_ACC_GYRO_DSD_ZH_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_D6D_SRC, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_DSD_ZH_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_D6D_EV_STATUS +* Description : Read D6D_EV_STATUS +* Input : Pointer to LSM6DSL_ACC_GYRO_D6D_EV_STATUS_t +* Output : Status of D6D_EV_STATUS see LSM6DSL_ACC_GYRO_D6D_EV_STATUS_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_D6D_EV_STATUS(void *handle, LSM6DSL_ACC_GYRO_D6D_EV_STATUS_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_D6D_SRC, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_D6D_EV_STATUS_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_XLDA +* Description : Read XLDA +* Input : Pointer to LSM6DSL_ACC_GYRO_XLDA_t +* Output : Status of XLDA see LSM6DSL_ACC_GYRO_XLDA_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_XLDA(void *handle, LSM6DSL_ACC_GYRO_XLDA_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_STATUS_REG, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_XLDA_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_GDA +* Description : Read GDA +* Input : Pointer to LSM6DSL_ACC_GYRO_GDA_t +* Output : Status of GDA see LSM6DSL_ACC_GYRO_GDA_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_GDA(void *handle, LSM6DSL_ACC_GYRO_GDA_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_STATUS_REG, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_GDA_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_TDA +* Description : Read GDA +* Input : Pointer to LSM6DSL_ACC_GYRO_TDA_t +* Output : Status of GDA see LSM6DSL_ACC_GYRO_TDA_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_TDA(void *handle, LSM6DSL_ACC_GYRO_TDA_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_STATUS_REG, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_TDA_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_FIFONumOfEntries +* Description : Read DIFF_FIFO +* Input : Pointer to u16_t +* Output : Status of DIFF_FIFO +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_FIFONumOfEntries(void *handle, u16_t *value) +{ + u8_t valueH, valueL; + + /* Low part from FIFO_STATUS1 */ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_FIFO_STATUS1, (u8_t *)&valueL, 1) ) + return MEMS_ERROR; + + valueL &= LSM6DSL_ACC_GYRO_DIFF_FIFO_STATUS1_MASK; //coerce + valueL = valueL >> LSM6DSL_ACC_GYRO_DIFF_FIFO_STATUS1_POSITION; //mask + + /* High part from FIFO_STATUS2 */ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_FIFO_STATUS2, (u8_t *)&valueH, 1) ) + return MEMS_ERROR; + + valueH &= LSM6DSL_ACC_GYRO_DIFF_FIFO_STATUS2_MASK; //coerce + valueH = valueH >> LSM6DSL_ACC_GYRO_DIFF_FIFO_STATUS2_POSITION; //mask + + *value = ((valueH << 8) & 0xFF00) | valueL; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_FIFOEmpty +* Description : Read FIFO_EMPTY +* Input : Pointer to LSM6DSL_ACC_GYRO_FIFO_EMPTY_t +* Output : Status of FIFO_EMPTY see LSM6DSL_ACC_GYRO_FIFO_EMPTY_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_FIFOEmpty(void *handle, LSM6DSL_ACC_GYRO_FIFO_EMPTY_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_FIFO_STATUS2, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_FIFO_EMPTY_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_FIFOFull +* Description : Read FIFO_FULL +* Input : Pointer to LSM6DSL_ACC_GYRO_FIFO_FULL_t +* Output : Status of FIFO_FULL see LSM6DSL_ACC_GYRO_FIFO_FULL_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_FIFOFull(void *handle, LSM6DSL_ACC_GYRO_FIFO_FULL_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_FIFO_STATUS2, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_FIFO_FULL_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_OVERRUN +* Description : Read OVERRUN +* Input : Pointer to LSM6DSL_ACC_GYRO_OVERRUN_t +* Output : Status of OVERRUN see LSM6DSL_ACC_GYRO_OVERRUN_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_OVERRUN(void *handle, LSM6DSL_ACC_GYRO_OVERRUN_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_FIFO_STATUS2, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_OVERRUN_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_WaterMark +* Description : Read WTM +* Input : Pointer to LSM6DSL_ACC_GYRO_WTM_t +* Output : Status of WTM see LSM6DSL_ACC_GYRO_WTM_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_WaterMark(void *handle, LSM6DSL_ACC_GYRO_WTM_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_FIFO_STATUS2, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_WTM_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_FIFOPattern +* Description : Read FIFO_PATTERN +* Input : Pointer to u16_t +* Output : Status of FIFO_PATTERN +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_FIFOPattern(void *handle, u16_t *value) +{ + u8_t valueH, valueL; + + /* Low part from FIFO_STATUS3 */ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_FIFO_STATUS3, (u8_t *)&valueL, 1) ) + return MEMS_ERROR; + + valueL &= LSM6DSL_ACC_GYRO_FIFO_STATUS3_PATTERN_MASK; //coerce + valueL = valueL >> LSM6DSL_ACC_GYRO_FIFO_STATUS3_PATTERN_POSITION; //mask + + /* High part from FIFO_STATUS4 */ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_FIFO_STATUS4, (u8_t *)&valueH, 1) ) + return MEMS_ERROR; + + valueH &= LSM6DSL_ACC_GYRO_FIFO_STATUS4_PATTERN_MASK; //coerce + valueH = valueH >> LSM6DSL_ACC_GYRO_FIFO_STATUS4_PATTERN_POSITION; //mask + + *value = ((valueH << 8) & 0xFF00) | valueL; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_SENS_HUB_END +* Description : Read SENS_HUB_END +* Input : Pointer to LSM6DSL_ACC_GYRO_SENS_HUB_END_t +* Output : Status of SENS_HUB_END see LSM6DSL_ACC_GYRO_SENS_HUB_END_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_SENS_HUB_END(void *handle, LSM6DSL_ACC_GYRO_SENS_HUB_END_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_FUNC_SRC, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_SENS_HUB_END_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_SOFT_IRON_END +* Description : Read SOFT_IRON_END +* Input : Pointer to LSM6DSL_ACC_GYRO_SOFT_IRON_END_t +* Output : Status of SOFT_IRON_END see LSM6DSL_ACC_GYRO_SOFT_IRON_END_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_SOFT_IRON_END(void *handle, LSM6DSL_ACC_GYRO_SOFT_IRON_END_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_FUNC_SRC, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_SOFT_IRON_END_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_HardIron +* Description : Read HI_FAIL +* Input : Pointer to LSM6DSL_ACC_GYRO_SOFT_HARD_IRON_STAT_t +* Output : Status of HI_FAIL see LSM6DSL_ACC_GYRO_SOFT_HARD_IRON_STAT_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_HardIron(void *handle, LSM6DSL_ACC_GYRO_SOFT_HARD_IRON_STAT_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_FUNC_SRC, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_HARD_IRON_STAT_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_STEP_OVERFLOW +* Description : Read STEP_OVERFLOW +* Input : Pointer to LSM6DSL_ACC_GYRO_STEP_OVERFLOW_t +* Output : Status of STEP_OVERFLOW see LSM6DSL_ACC_GYRO_STEP_OVERFLOW_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_STEP_OVERFLOW(void *handle, LSM6DSL_ACC_GYRO_STEP_OVERFLOW_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_FUNC_SRC, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_STEP_OVERFLOW_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_STEP_COUNT_DELTA +* Description : Read STEP_COUNT_DELTA_IA +* Input : Pointer to LSM6DSL_ACC_GYRO_STEP_COUNT_DELTA_t +* Output : Status of STEP_COUNT_DELTA_IA see LSM6DSL_ACC_GYRO_STEP_COUNT_DELTA_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_STEP_COUNT_DELTA(void *handle, LSM6DSL_ACC_GYRO_STEP_COUNT_DELTA_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_FUNC_SRC, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_STEP_COUNT_DELTA_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_PEDO_EV_STATUS +* Description : Read PEDO_EV_STATUS +* Input : Pointer to LSM6DSL_ACC_GYRO_PEDO_EV_STATUS_t +* Output : Status of PEDO_EV_STATUS see LSM6DSL_ACC_GYRO_PEDO_EV_STATUS_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_PEDO_EV_STATUS(void *handle, LSM6DSL_ACC_GYRO_PEDO_EV_STATUS_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_FUNC_SRC, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_PEDO_EV_STATUS_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_TILT_EV_STATUS +* Description : Read TILT_EV_STATUS +* Input : Pointer to LSM6DSL_ACC_GYRO_TILT_EV_STATUS_t +* Output : Status of TILT_EV_STATUS see LSM6DSL_ACC_GYRO_TILT_EV_STATUS_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_TILT_EV_STATUS(void *handle, LSM6DSL_ACC_GYRO_TILT_EV_STATUS_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_FUNC_SRC, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_TILT_EV_STATUS_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_SIGN_MOT_EV_STATUS +* Description : Read SIGN_MOT_EV_STATUS +* Input : Pointer to LSM6DSL_ACC_GYRO_SIGN_MOT_EV_STATUS_t +* Output : Status of SIGN_MOT_EV_STATUS see LSM6DSL_ACC_GYRO_SIGN_MOT_EV_STATUS_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_SIGN_MOT_EV_STATUS(void *handle, LSM6DSL_ACC_GYRO_SIGN_MOT_EV_STATUS_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_FUNC_SRC, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_SIGN_MOT_EV_STATUS_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_LIR +* Description : Write LIR +* Input : LSM6DSL_ACC_GYRO_LIR_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_LIR(void *handle, LSM6DSL_ACC_GYRO_LIR_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_TAP_CFG1, &value, 1) ) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_LIR_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_TAP_CFG1, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_LIR +* Description : Read LIR +* Input : Pointer to LSM6DSL_ACC_GYRO_LIR_t +* Output : Status of LIR see LSM6DSL_ACC_GYRO_LIR_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_LIR(void *handle, LSM6DSL_ACC_GYRO_LIR_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_TAP_CFG1, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_LIR_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_TAP_Z_EN +* Description : Write TAP_Z_EN +* Input : LSM6DSL_ACC_GYRO_TAP_Z_EN_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_TAP_Z_EN(void *handle, LSM6DSL_ACC_GYRO_TAP_Z_EN_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_TAP_CFG1, &value, 1) ) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_TAP_Z_EN_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_TAP_CFG1, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_TAP_Z_EN +* Description : Read TAP_Z_EN +* Input : Pointer to LSM6DSL_ACC_GYRO_TAP_Z_EN_t +* Output : Status of TAP_Z_EN see LSM6DSL_ACC_GYRO_TAP_Z_EN_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_TAP_Z_EN(void *handle, LSM6DSL_ACC_GYRO_TAP_Z_EN_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_TAP_CFG1, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_TAP_Z_EN_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_TAP_Y_EN +* Description : Write TAP_Y_EN +* Input : LSM6DSL_ACC_GYRO_TAP_Y_EN_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_TAP_Y_EN(void *handle, LSM6DSL_ACC_GYRO_TAP_Y_EN_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_TAP_CFG1, &value, 1) ) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_TAP_Y_EN_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_TAP_CFG1, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_TAP_Y_EN +* Description : Read TAP_Y_EN +* Input : Pointer to LSM6DSL_ACC_GYRO_TAP_Y_EN_t +* Output : Status of TAP_Y_EN see LSM6DSL_ACC_GYRO_TAP_Y_EN_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_TAP_Y_EN(void *handle, LSM6DSL_ACC_GYRO_TAP_Y_EN_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_TAP_CFG1, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_TAP_Y_EN_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_TAP_X_EN +* Description : Write TAP_X_EN +* Input : LSM6DSL_ACC_GYRO_TAP_X_EN_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_TAP_X_EN(void *handle, LSM6DSL_ACC_GYRO_TAP_X_EN_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_TAP_CFG1, &value, 1) ) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_TAP_X_EN_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_TAP_CFG1, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_TAP_X_EN +* Description : Read TAP_X_EN +* Input : Pointer to LSM6DSL_ACC_GYRO_TAP_X_EN_t +* Output : Status of TAP_X_EN see LSM6DSL_ACC_GYRO_TAP_X_EN_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_TAP_X_EN(void *handle, LSM6DSL_ACC_GYRO_TAP_X_EN_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_TAP_CFG1, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_TAP_X_EN_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_SLOPE_FDS +* Description : Write SLOPE_FDS +* Input : LSM6DSL_ACC_GYRO_SLOPE_FDS_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_SLOPE_FDS(void *handle, LSM6DSL_ACC_GYRO_SLOPE_FDS_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_TAP_CFG1, &value, 1) ) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_SLOPE_FDS_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_TAP_CFG1, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_SLOPE_FDS +* Description : Read SLOPE_FDS +* Input : Pointer to LSM6DSL_ACC_GYRO_SLOPE_FDS_t +* Output : Status of SLOPE_FDS see LSM6DSL_ACC_GYRO_SLOPE_FDS_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_SLOPE_FDS(void *handle, LSM6DSL_ACC_GYRO_SLOPE_FDS_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_TAP_CFG1, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_SLOPE_FDS_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_BASIC_INT +* Description : Write INTERRUPTS_ENABLE +* Input : LSM6DSL_ACC_GYRO_INT_EN_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_BASIC_INT(void *handle, LSM6DSL_ACC_GYRO_INT_EN_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_TAP_CFG1, &value, 1) ) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_INT_EN_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_TAP_CFG1, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_BASIC_INT +* Description : Read INTERRUPTS_ENABLE +* Input : Pointer to LSM6DSL_ACC_GYRO_INT_EN_t +* Output : Status of INTERRUPTS_ENABLE see LSM6DSL_ACC_GYRO_INT_EN_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_BASIC_INT(void *handle, LSM6DSL_ACC_GYRO_INT_EN_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_TAP_CFG1, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_INT_EN_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_TAP_THS +* Description : Write TAP_THS +* Input : u8_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_TAP_THS(void *handle, u8_t newValue) +{ + u8_t value; + + newValue = newValue << LSM6DSL_ACC_GYRO_TAP_THS_POSITION; //mask + newValue &= LSM6DSL_ACC_GYRO_TAP_THS_MASK; //coerce + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_TAP_THS_6D, &value, 1) ) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_TAP_THS_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_TAP_THS_6D, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_TAP_THS +* Description : Read TAP_THS +* Input : Pointer to u8_t +* Output : Status of TAP_THS +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_TAP_THS(void *handle, u8_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_TAP_THS_6D, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_TAP_THS_MASK; //coerce + *value = *value >> LSM6DSL_ACC_GYRO_TAP_THS_POSITION; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_SIXD_THS +* Description : Write SIXD_THS +* Input : LSM6DSL_ACC_GYRO_SIXD_THS_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_SIXD_THS(void *handle, LSM6DSL_ACC_GYRO_SIXD_THS_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_TAP_THS_6D, &value, 1) ) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_SIXD_THS_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_TAP_THS_6D, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_SIXD_THS +* Description : Read SIXD_THS +* Input : Pointer to LSM6DSL_ACC_GYRO_SIXD_THS_t +* Output : Status of SIXD_THS see LSM6DSL_ACC_GYRO_SIXD_THS_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_SIXD_THS(void *handle, LSM6DSL_ACC_GYRO_SIXD_THS_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_TAP_THS_6D, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_SIXD_THS_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_D4D +* Description : Write D4D_EN +* Input : LSM6DSL_ACC_GYRO_D4D_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_D4D(void *handle, LSM6DSL_ACC_GYRO_D4D_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_TAP_THS_6D, &value, 1) ) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_D4D_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_TAP_THS_6D, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_D4D +* Description : Read D4D_EN +* Input : Pointer to LSM6DSL_ACC_GYRO_D4D_t +* Output : Status of D4D_EN see LSM6DSL_ACC_GYRO_D4D_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_D4D(void *handle, LSM6DSL_ACC_GYRO_D4D_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_TAP_THS_6D, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_D4D_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_SHOCK_Duration +* Description : Write SHOCK +* Input : u8_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_SHOCK_Duration(void *handle, u8_t newValue) +{ + u8_t value; + + newValue = newValue << LSM6DSL_ACC_GYRO_SHOCK_POSITION; //mask + newValue &= LSM6DSL_ACC_GYRO_SHOCK_MASK; //coerce + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_INT_DUR2, &value, 1) ) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_SHOCK_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_INT_DUR2, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_SHOCK_Duration +* Description : Read SHOCK +* Input : Pointer to u8_t +* Output : Status of SHOCK +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_SHOCK_Duration(void *handle, u8_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_INT_DUR2, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_SHOCK_MASK; //coerce + *value = *value >> LSM6DSL_ACC_GYRO_SHOCK_POSITION; //mask + + return MEMS_SUCCESS; +} +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_QUIET_Duration +* Description : Write QUIET +* Input : u8_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_QUIET_Duration(void *handle, u8_t newValue) +{ + u8_t value; + + newValue = newValue << LSM6DSL_ACC_GYRO_QUIET_POSITION; //mask + newValue &= LSM6DSL_ACC_GYRO_QUIET_MASK; //coerce + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_INT_DUR2, &value, 1) ) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_QUIET_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_INT_DUR2, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_QUIET_Duration +* Description : Read QUIET +* Input : Pointer to u8_t +* Output : Status of QUIET +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_QUIET_Duration(void *handle, u8_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_INT_DUR2, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_QUIET_MASK; //coerce + *value = *value >> LSM6DSL_ACC_GYRO_QUIET_POSITION; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_DUR +* Description : Write DUR +* Input : u8_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_DUR(void *handle, u8_t newValue) +{ + u8_t value; + + newValue = newValue << LSM6DSL_ACC_GYRO_DUR_POSITION; //mask + newValue &= LSM6DSL_ACC_GYRO_DUR_MASK; //coerce + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_INT_DUR2, &value, 1) ) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_DUR_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_INT_DUR2, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_DUR +* Description : Read DUR +* Input : Pointer to u8_t +* Output : Status of DUR +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_DUR(void *handle, u8_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_INT_DUR2, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_DUR_MASK; //coerce + *value = *value >> LSM6DSL_ACC_GYRO_DUR_POSITION; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_WK_THS +* Description : Write WK_THS +* Input : u8_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_WK_THS(void *handle, u8_t newValue) +{ + u8_t value; + + newValue = newValue << LSM6DSL_ACC_GYRO_WK_THS_POSITION; //mask + newValue &= LSM6DSL_ACC_GYRO_WK_THS_MASK; //coerce + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_WAKE_UP_THS, &value, 1) ) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_WK_THS_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_WAKE_UP_THS, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_WK_THS +* Description : Read WK_THS +* Input : Pointer to u8_t +* Output : Status of WK_THS +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_WK_THS(void *handle, u8_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_WAKE_UP_THS, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_WK_THS_MASK; //coerce + *value = *value >> LSM6DSL_ACC_GYRO_WK_THS_POSITION; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_SINGLE_DOUBLE_TAP_EV +* Description : Write SINGLE_DOUBLE_TAP +* Input : LSM6DSL_ACC_GYRO_SINGLE_DOUBLE_TAP_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_SINGLE_DOUBLE_TAP_EV(void *handle, LSM6DSL_ACC_GYRO_SINGLE_DOUBLE_TAP_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_WAKE_UP_THS, &value, 1) ) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_SINGLE_DOUBLE_TAP_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_WAKE_UP_THS, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_SINGLE_DOUBLE_TAP_EV +* Description : Read SINGLE_DOUBLE_TAP +* Input : Pointer to LSM6DSL_ACC_GYRO_SINGLE_DOUBLE_TAP_t +* Output : Status of SINGLE_DOUBLE_TAP see LSM6DSL_ACC_GYRO_SINGLE_DOUBLE_TAP_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_SINGLE_DOUBLE_TAP_EV(void *handle, LSM6DSL_ACC_GYRO_SINGLE_DOUBLE_TAP_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_WAKE_UP_THS, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_SINGLE_DOUBLE_TAP_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_SLEEP_DUR +* Description : Write SLEEP_DUR +* Input : u8_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_SLEEP_DUR(void *handle, u8_t newValue) +{ + u8_t value; + + newValue = newValue << LSM6DSL_ACC_GYRO_SLEEP_DUR_POSITION; //mask + newValue &= LSM6DSL_ACC_GYRO_SLEEP_DUR_MASK; //coerce + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_WAKE_UP_DUR, &value, 1) ) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_SLEEP_DUR_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_WAKE_UP_DUR, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_SLEEP_DUR +* Description : Read SLEEP_DUR +* Input : Pointer to u8_t +* Output : Status of SLEEP_DUR +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_SLEEP_DUR(void *handle, u8_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_WAKE_UP_DUR, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_SLEEP_DUR_MASK; //coerce + *value = *value >> LSM6DSL_ACC_GYRO_SLEEP_DUR_POSITION; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_TIMER_HR +* Description : Write TIMER_HR +* Input : LSM6DSL_ACC_GYRO_TIMER_HR_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_TIMER_HR(void *handle, LSM6DSL_ACC_GYRO_TIMER_HR_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_WAKE_UP_DUR, &value, 1) ) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_TIMER_HR_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_WAKE_UP_DUR, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_TIMER_HR +* Description : Read TIMER_HR +* Input : Pointer to LSM6DSL_ACC_GYRO_TIMER_HR_t +* Output : Status of TIMER_HR see LSM6DSL_ACC_GYRO_TIMER_HR_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_TIMER_HR(void *handle, LSM6DSL_ACC_GYRO_TIMER_HR_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_WAKE_UP_DUR, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_TIMER_HR_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_WAKE_DUR +* Description : Write WAKE_DUR +* Input : u8_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_WAKE_DUR(void *handle, u8_t newValue) +{ + u8_t value; + + newValue = newValue << LSM6DSL_ACC_GYRO_WAKE_DUR_POSITION; //mask + newValue &= LSM6DSL_ACC_GYRO_WAKE_DUR_MASK; //coerce + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_WAKE_UP_DUR, &value, 1) ) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_WAKE_DUR_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_WAKE_UP_DUR, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_WAKE_DUR +* Description : Read WAKE_DUR +* Input : Pointer to u8_t +* Output : Status of WAKE_DUR +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_WAKE_DUR(void *handle, u8_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_WAKE_UP_DUR, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_WAKE_DUR_MASK; //coerce + *value = *value >> LSM6DSL_ACC_GYRO_WAKE_DUR_POSITION; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_FF_THS +* Description : Write FF_THS +* Input : LSM6DSL_ACC_GYRO_FF_THS_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_FF_THS(void *handle, LSM6DSL_ACC_GYRO_FF_THS_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_FREE_FALL, &value, 1) ) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_FF_THS_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_FREE_FALL, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_FF_THS +* Description : Read FF_THS +* Input : Pointer to LSM6DSL_ACC_GYRO_FF_THS_t +* Output : Status of FF_THS see LSM6DSL_ACC_GYRO_FF_THS_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_FF_THS(void *handle, LSM6DSL_ACC_GYRO_FF_THS_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_FREE_FALL, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_FF_THS_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_FF_Duration +* Description : Write FF_DUR +* Input : u8_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_FF_Duration(void *handle, u8_t newValue) +{ + u8_t valueH, valueL; + u8_t value; + + valueL = newValue & 0x1F; + valueH = (newValue >> 5) & 0x1; + + /* Low part in FREE_FALL reg */ + valueL = valueL << LSM6DSL_ACC_GYRO_FF_FREE_FALL_DUR_POSITION; //mask + valueL &= LSM6DSL_ACC_GYRO_FF_FREE_FALL_DUR_MASK; //coerce + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_FREE_FALL, &value, 1) ) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_FF_FREE_FALL_DUR_MASK; + value |= valueL; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_FREE_FALL, &value, 1) ) + return MEMS_ERROR; + + /* High part in WAKE_UP_DUR reg */ + valueH = valueH << LSM6DSL_ACC_GYRO_FF_WAKE_UP_DUR_POSITION; //mask + valueH &= LSM6DSL_ACC_GYRO_FF_WAKE_UP_DUR_MASK; //coerce + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_WAKE_UP_DUR, &value, 1) ) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_FF_WAKE_UP_DUR_MASK; + value |= valueH; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_WAKE_UP_DUR, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_FF_Duration +* Description : Read FF_DUR +* Input : Pointer to u8_t +* Output : Status of FF_DUR +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_FF_Duration(void *handle, u8_t *value) +{ + u8_t valueH, valueL; + + /* Low part from FREE_FALL reg */ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_FREE_FALL, (u8_t *)&valueL, 1) ) + return MEMS_ERROR; + + valueL &= LSM6DSL_ACC_GYRO_FF_FREE_FALL_DUR_MASK; //coerce + valueL = valueL >> LSM6DSL_ACC_GYRO_FF_FREE_FALL_DUR_POSITION; //mask + + /* High part from WAKE_UP_DUR reg */ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_WAKE_UP_DUR, (u8_t *)&valueH, 1) ) + return MEMS_ERROR; + + valueH &= LSM6DSL_ACC_GYRO_FF_WAKE_UP_DUR_MASK; //coerce + valueH = valueH >> LSM6DSL_ACC_GYRO_FF_WAKE_UP_DUR_POSITION; //mask + + *value = ((valueH << 5) & 0x20) | valueL; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_TimerEvRouteInt1 +* Description : Write INT1_TIMER +* Input : LSM6DSL_ACC_GYRO_INT1_TIMER_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_TimerEvRouteInt1(void *handle, LSM6DSL_ACC_GYRO_INT1_TIMER_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_MD1_CFG, &value, 1) ) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_INT1_TIMER_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_MD1_CFG, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_TimerEvRouteInt1 +* Description : Read INT1_TIMER +* Input : Pointer to LSM6DSL_ACC_GYRO_INT1_TIMER_t +* Output : Status of INT1_TIMER see LSM6DSL_ACC_GYRO_INT1_TIMER_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_TimerEvRouteInt1(void *handle, LSM6DSL_ACC_GYRO_INT1_TIMER_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_MD1_CFG, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_INT1_TIMER_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_TiltEvOnInt1 +* Description : Write INT1_TILT +* Input : LSM6DSL_ACC_GYRO_INT1_TILT_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_TiltEvOnInt1(void *handle, LSM6DSL_ACC_GYRO_INT1_TILT_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_MD1_CFG, &value, 1) ) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_INT1_TILT_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_MD1_CFG, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_TiltEvOnInt1 +* Description : Read INT1_TILT +* Input : Pointer to LSM6DSL_ACC_GYRO_INT1_TILT_t +* Output : Status of INT1_TILT see LSM6DSL_ACC_GYRO_INT1_TILT_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_TiltEvOnInt1(void *handle, LSM6DSL_ACC_GYRO_INT1_TILT_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_MD1_CFG, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_INT1_TILT_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_6DEvOnInt1 +* Description : Write INT1_6D +* Input : LSM6DSL_ACC_GYRO_INT1_6D_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_6DEvOnInt1(void *handle, LSM6DSL_ACC_GYRO_INT1_6D_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_MD1_CFG, &value, 1) ) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_INT1_6D_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_MD1_CFG, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_6DEvOnInt1 +* Description : Read INT1_6D +* Input : Pointer to LSM6DSL_ACC_GYRO_INT1_6D_t +* Output : Status of INT1_6D see LSM6DSL_ACC_GYRO_INT1_6D_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_6DEvOnInt1(void *handle, LSM6DSL_ACC_GYRO_INT1_6D_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_MD1_CFG, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_INT1_6D_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_TapEvOnInt1 +* Description : Write INT1_TAP +* Input : LSM6DSL_ACC_GYRO_INT1_TAP_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_TapEvOnInt1(void *handle, LSM6DSL_ACC_GYRO_INT1_TAP_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_MD1_CFG, &value, 1) ) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_INT1_TAP_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_MD1_CFG, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_TapEvOnInt1 +* Description : Read INT1_TAP +* Input : Pointer to LSM6DSL_ACC_GYRO_INT1_TAP_t +* Output : Status of INT1_TAP see LSM6DSL_ACC_GYRO_INT1_TAP_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_TapEvOnInt1(void *handle, LSM6DSL_ACC_GYRO_INT1_TAP_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_MD1_CFG, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_INT1_TAP_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_FFEvOnInt1 +* Description : Write INT1_FF +* Input : LSM6DSL_ACC_GYRO_INT1_FF_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_FFEvOnInt1(void *handle, LSM6DSL_ACC_GYRO_INT1_FF_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_MD1_CFG, &value, 1) ) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_INT1_FF_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_MD1_CFG, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_FFEvOnInt1 +* Description : Read INT1_FF +* Input : Pointer to LSM6DSL_ACC_GYRO_INT1_FF_t +* Output : Status of INT1_FF see LSM6DSL_ACC_GYRO_INT1_FF_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_FFEvOnInt1(void *handle, LSM6DSL_ACC_GYRO_INT1_FF_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_MD1_CFG, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_INT1_FF_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_WUEvOnInt1 +* Description : Write INT1_WU +* Input : LSM6DSL_ACC_GYRO_INT1_WU_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_WUEvOnInt1(void *handle, LSM6DSL_ACC_GYRO_INT1_WU_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_MD1_CFG, &value, 1) ) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_INT1_WU_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_MD1_CFG, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_WUEvOnInt1 +* Description : Read INT1_WU +* Input : Pointer to LSM6DSL_ACC_GYRO_INT1_WU_t +* Output : Status of INT1_WU see LSM6DSL_ACC_GYRO_INT1_WU_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_WUEvOnInt1(void *handle, LSM6DSL_ACC_GYRO_INT1_WU_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_MD1_CFG, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_INT1_WU_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_SingleTapOnInt1 +* Description : Write INT1_SINGLE_TAP +* Input : LSM6DSL_ACC_GYRO_INT1_SINGLE_TAP_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_SingleTapOnInt1(void *handle, LSM6DSL_ACC_GYRO_INT1_SINGLE_TAP_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_MD1_CFG, &value, 1) ) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_INT1_SINGLE_TAP_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_MD1_CFG, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_SingleTapOnInt1 +* Description : Read INT1_SINGLE_TAP +* Input : Pointer to LSM6DSL_ACC_GYRO_INT1_SINGLE_TAP_t +* Output : Status of INT1_SINGLE_TAP see LSM6DSL_ACC_GYRO_INT1_SINGLE_TAP_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_SingleTapOnInt1(void *handle, LSM6DSL_ACC_GYRO_INT1_SINGLE_TAP_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_MD1_CFG, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_INT1_SINGLE_TAP_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_SleepEvOnInt1 +* Description : Write INT1_SLEEP +* Input : LSM6DSL_ACC_GYRO_INT1_SLEEP_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_SleepEvOnInt1(void *handle, LSM6DSL_ACC_GYRO_INT1_SLEEP_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_MD1_CFG, &value, 1) ) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_INT1_SLEEP_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_MD1_CFG, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_SleepEvOnInt1 +* Description : Read INT1_SLEEP +* Input : Pointer to LSM6DSL_ACC_GYRO_INT1_SLEEP_t +* Output : Status of INT1_SLEEP see LSM6DSL_ACC_GYRO_INT1_SLEEP_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_SleepEvOnInt1(void *handle, LSM6DSL_ACC_GYRO_INT1_SLEEP_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_MD1_CFG, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_INT1_SLEEP_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_MagCorrection_Int2 +* Description : Write INT2_IRON +* Input : LSM6DSL_ACC_GYRO_INT2_IRON_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_MagCorrection_Int2(void *handle, LSM6DSL_ACC_GYRO_INT2_IRON_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_MD2_CFG, &value, 1) ) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_INT2_IRON_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_MD2_CFG, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_MagCorrection_Int2 +* Description : Read INT2_IRON +* Input : Pointer to LSM6DSL_ACC_GYRO_INT2_IRON_t +* Output : Status of INT2_IRON see LSM6DSL_ACC_GYRO_INT2_IRON_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_MagCorrection_Int2(void *handle, LSM6DSL_ACC_GYRO_INT2_IRON_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_MD2_CFG, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_INT2_IRON_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_TiltEvOnInt2 +* Description : Write INT2_TILT +* Input : LSM6DSL_ACC_GYRO_INT2_TILT_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_TiltEvOnInt2(void *handle, LSM6DSL_ACC_GYRO_INT2_TILT_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_MD2_CFG, &value, 1) ) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_INT2_TILT_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_MD2_CFG, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_TiltEvOnInt2 +* Description : Read INT2_TILT +* Input : Pointer to LSM6DSL_ACC_GYRO_INT2_TILT_t +* Output : Status of INT2_TILT see LSM6DSL_ACC_GYRO_INT2_TILT_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_TiltEvOnInt2(void *handle, LSM6DSL_ACC_GYRO_INT2_TILT_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_MD2_CFG, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_INT2_TILT_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_6DEvOnInt2 +* Description : Write INT2_6D +* Input : LSM6DSL_ACC_GYRO_INT2_6D_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_6DEvOnInt2(void *handle, LSM6DSL_ACC_GYRO_INT2_6D_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_MD2_CFG, &value, 1) ) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_INT2_6D_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_MD2_CFG, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_6DEvOnInt2 +* Description : Read INT2_6D +* Input : Pointer to LSM6DSL_ACC_GYRO_INT2_6D_t +* Output : Status of INT2_6D see LSM6DSL_ACC_GYRO_INT2_6D_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_6DEvOnInt2(void *handle, LSM6DSL_ACC_GYRO_INT2_6D_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_MD2_CFG, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_INT2_6D_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_TapEvOnInt2 +* Description : Write INT2_TAP +* Input : LSM6DSL_ACC_GYRO_INT2_TAP_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_TapEvOnInt2(void *handle, LSM6DSL_ACC_GYRO_INT2_TAP_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_MD2_CFG, &value, 1) ) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_INT2_TAP_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_MD2_CFG, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_TapEvOnInt2 +* Description : Read INT2_TAP +* Input : Pointer to LSM6DSL_ACC_GYRO_INT2_TAP_t +* Output : Status of INT2_TAP see LSM6DSL_ACC_GYRO_INT2_TAP_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_TapEvOnInt2(void *handle, LSM6DSL_ACC_GYRO_INT2_TAP_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_MD2_CFG, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_INT2_TAP_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_FFEvOnInt2 +* Description : Write INT2_FF +* Input : LSM6DSL_ACC_GYRO_INT2_FF_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_FFEvOnInt2(void *handle, LSM6DSL_ACC_GYRO_INT2_FF_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_MD2_CFG, &value, 1) ) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_INT2_FF_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_MD2_CFG, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_FFEvOnInt2 +* Description : Read INT2_FF +* Input : Pointer to LSM6DSL_ACC_GYRO_INT2_FF_t +* Output : Status of INT2_FF see LSM6DSL_ACC_GYRO_INT2_FF_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_FFEvOnInt2(void *handle, LSM6DSL_ACC_GYRO_INT2_FF_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_MD2_CFG, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_INT2_FF_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_WUEvOnInt2 +* Description : Write INT2_WU +* Input : LSM6DSL_ACC_GYRO_INT2_WU_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_WUEvOnInt2(void *handle, LSM6DSL_ACC_GYRO_INT2_WU_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_MD2_CFG, &value, 1) ) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_INT2_WU_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_MD2_CFG, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_WUEvOnInt2 +* Description : Read INT2_WU +* Input : Pointer to LSM6DSL_ACC_GYRO_INT2_WU_t +* Output : Status of INT2_WU see LSM6DSL_ACC_GYRO_INT2_WU_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_WUEvOnInt2(void *handle, LSM6DSL_ACC_GYRO_INT2_WU_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_MD2_CFG, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_INT2_WU_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_SingleTapOnInt2 +* Description : Write INT2_SINGLE_TAP +* Input : LSM6DSL_ACC_GYRO_INT2_SINGLE_TAP_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_SingleTapOnInt2(void *handle, LSM6DSL_ACC_GYRO_INT2_SINGLE_TAP_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_MD2_CFG, &value, 1) ) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_INT2_SINGLE_TAP_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_MD2_CFG, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_SingleTapOnInt2 +* Description : Read INT2_SINGLE_TAP +* Input : Pointer to LSM6DSL_ACC_GYRO_INT2_SINGLE_TAP_t +* Output : Status of INT2_SINGLE_TAP see LSM6DSL_ACC_GYRO_INT2_SINGLE_TAP_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_SingleTapOnInt2(void *handle, LSM6DSL_ACC_GYRO_INT2_SINGLE_TAP_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_MD2_CFG, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_INT2_SINGLE_TAP_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_SleepEvOnInt2 +* Description : Write INT2_SLEEP +* Input : LSM6DSL_ACC_GYRO_INT2_SLEEP_t +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_SleepEvOnInt2(void *handle, LSM6DSL_ACC_GYRO_INT2_SLEEP_t newValue) +{ + u8_t value; + + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_MD2_CFG, &value, 1) ) + return MEMS_ERROR; + + value &= ~LSM6DSL_ACC_GYRO_INT2_SLEEP_MASK; + value |= newValue; + + if( !LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_MD2_CFG, &value, 1) ) + return MEMS_ERROR; + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_R_SleepEvOnInt2 +* Description : Read INT2_SLEEP +* Input : Pointer to LSM6DSL_ACC_GYRO_INT2_SLEEP_t +* Output : Status of INT2_SLEEP see LSM6DSL_ACC_GYRO_INT2_SLEEP_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_R_SleepEvOnInt2(void *handle, LSM6DSL_ACC_GYRO_INT2_SLEEP_t *value) +{ + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_MD2_CFG, (u8_t *)value, 1) ) + return MEMS_ERROR; + + *value &= LSM6DSL_ACC_GYRO_INT2_SLEEP_MASK; //mask + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : mems_status_t LSM6DSL_ACC_GYRO_Get_GetFIFOData(u8_t *buff) +* Description : Read GetFIFOData output register +* Input : pointer to [u8_t] +* Output : GetFIFOData buffer u8_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_Get_GetFIFOData(void *handle, u8_t *buff) +{ + u8_t i, j, k; + u8_t numberOfByteForDimension; + + numberOfByteForDimension=2/1; + + k=0; + for (i=0; i<1;i++ ) + { + for (j=0; j<numberOfByteForDimension;j++ ) + { + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_FIFO_DATA_OUT_L+k, &buff[k], 1)) + return MEMS_ERROR; + k++; + } + } + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : mems_status_t LSM6DSL_ACC_GYRO_Get_GetTimestamp(u8_t *buff) +* Description : Read GetTimestamp output register +* Input : pointer to [u8_t] +* Output : GetTimestamp buffer u8_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_Get_GetTimestamp(void *handle, u8_t *buff) +{ + u8_t i, j, k; + u8_t numberOfByteForDimension; + + numberOfByteForDimension=3/1; + + k=0; + for (i=0; i<1;i++ ) + { + for (j=0; j<numberOfByteForDimension;j++ ) + { + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_TIMESTAMP0_REG+k, &buff[k], 1)) + return MEMS_ERROR; + k++; + } + } + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : mems_status_t LSM6DSL_ACC_GYRO_Get_GetStepCounter(u8_t *buff) +* Description : Read GetStepCounter output register +* Input : pointer to [u8_t] +* Output : GetStepCounter buffer u8_t +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_Get_GetStepCounter(void *handle, u8_t *buff) +{ + u8_t i, j, k; + u8_t numberOfByteForDimension; + + numberOfByteForDimension=2/1; + + k=0; + for (i=0; i<1;i++ ) + { + for (j=0; j<numberOfByteForDimension;j++ ) + { + if( !LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_STEP_COUNTER_L+k, &buff[k], 1)) + return MEMS_ERROR; + k++; + } + } + + return MEMS_SUCCESS; +} + +/******************************************************************************* +* Function Name : LSM6DSL_ACC_GYRO_W_PedoThreshold(void *handle, u8_t newValue) +* Description : Set accelerometer threshold for pedometer +* Input : pointer to [u8_t] +* Output : None +* Return : Status [MEMS_ERROR, MEMS_SUCCESS] +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_PedoThreshold(void *handle, u8_t newValue) +{ + u8_t value; + + /* Open Embedded Function Register page*/ + LSM6DSL_ACC_GYRO_W_EmbeddedAccess(handle, LSM6DSL_ACC_GYRO_EMBEDDED_ACCESS_ENABLED); + + /* read current value */ + LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_CONFIG_PEDO_THS_MIN, &value, 1); + + value &= ~0x1F; + value |= (newValue & 0x1F); + + /* write new value */ + LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_CONFIG_PEDO_THS_MIN, &value, 1); + + /* Close Embedded Function Register page*/ + LSM6DSL_ACC_GYRO_W_EmbeddedAccess(handle, LSM6DSL_ACC_GYRO_EMBEDDED_ACCESS_DISABLED); + + return MEMS_SUCCESS; +} + +/************** Use Sensor Hub *******************/ +/* + * Program the nine Soft Iron Matrix coefficients. + * The SI_Matrix buffer must provide coefficients + * in xx, xy, xz, yx, yy, yz, zx, zy, zz order. + */ +mems_status_t LSM6DSL_ACC_GYRO_SH_init_SI_Matrix(void *handle, u8_t *SI_matrix) +{ + /* Open Embedded Function Register page*/ + LSM6DSL_ACC_GYRO_W_EmbeddedAccess(handle, LSM6DSL_ACC_GYRO_EMBEDDED_ACCESS_ENABLED); + + /* Write the Soft Iron Matrix coefficients */ + LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_MAG_SI_XX, SI_matrix, 9); + + /* Close Embedded Function Register page*/ + LSM6DSL_ACC_GYRO_W_EmbeddedAccess(handle, LSM6DSL_ACC_GYRO_EMBEDDED_ACCESS_DISABLED); + + return MEMS_SUCCESS; +} + +/* Read a remote device through I2C Sensor Hub Slave 0 */ +mems_status_t LSM6DSL_ACC_GYRO_SH0_Program(void *handle, u8_t SlvAddr, u8_t Reg, u8_t len) +{ + /* Open Embedded Function Register page*/ + LSM6DSL_ACC_GYRO_W_EmbeddedAccess(handle, LSM6DSL_ACC_GYRO_EMBEDDED_ACCESS_ENABLED); + + /* Write remote device I2C slave address */ + SlvAddr |= 0x1; /* Raise the read op bit */ + LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_SLV0_ADD, &SlvAddr, 1); + + /* Write remote device I2C subaddress */ + LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_SLV0_SUBADD, &Reg, 1); + + /* Write number of bytes to read [SLAVE0_CONFIG - 04h ]*/ + u8_t sl0_cfg = 0; + sl0_cfg |= 0x00; //00 bit [7-6] : no decimation + sl0_cfg |= 0x00; //00 bit [5-4] : one sensor + sl0_cfg |= 0x00; // 0 bit [3] : source mode read disabled + sl0_cfg |= len & 0x07; // bit [2-0] : number of bytes + + LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_SLAVE0_CONFIG, &sl0_cfg, 1); + + /* Close Embedded Function Register page*/ + LSM6DSL_ACC_GYRO_W_EmbeddedAccess(handle, LSM6DSL_ACC_GYRO_EMBEDDED_ACCESS_DISABLED); + + /* Enable FUNC */ + LSM6DSL_ACC_GYRO_W_FUNC_EN(handle, LSM6DSL_ACC_GYRO_FUNC_EN_ENABLED); + + /* MASTER_EN */ + LSM6DSL_ACC_GYRO_W_I2C_MASTER_Enable(handle, LSM6DSL_ACC_GYRO_MASTER_ON_ENABLED); + + return MEMS_SUCCESS; +} + +/* Read a remote device through I2C Sensor Hub Slave 0 */ +mems_status_t LSM6DSL_ACC_GYRO_SH0_ReadMem(void *handle, u8_t SlvAddr, u8_t Reg, u8_t *Bufp, u8_t len, u8_t stop) +{ + LSM6DSL_ACC_GYRO_SENS_HUB_END_t op_cmpl = LSM6DSL_ACC_GYRO_SENS_HUB_END_STILL_ONGOING; + LSM6DSL_ACC_GYRO_XLDA_t op_update = LSM6DSL_ACC_GYRO_XLDA_NO_DATA_AVAIL; + u8_t dummy[6]; + + LSM6DSL_ACC_GYRO_W_ODR_XL(handle, LSM6DSL_ACC_GYRO_ODR_XL_POWER_DOWN); + + LSM6DSL_ACC_GYRO_SH0_Program(handle, SlvAddr, Reg, len); + + /* Syncronize the SH with internal trigger (xl) */ + LSM6DSL_ACC_GYRO_W_ODR_XL(handle, LSM6DSL_ACC_GYRO_ODR_XL_104Hz); + + /* Wait until operation is not completed */ + LSM6DSL_ACC_GYRO_GetRawAccData(handle, dummy); + do { + LSM6DSL_ACC_GYRO_R_XLDA(handle, &op_update); + } while(op_update != LSM6DSL_ACC_GYRO_XLDA_DATA_AVAIL); + do { + LSM6DSL_ACC_GYRO_R_SENS_HUB_END(handle, &op_cmpl); + } while(op_cmpl != LSM6DSL_ACC_GYRO_SENS_HUB_END_OP_COMPLETED); + + + /* Read the result */ + LSM6DSL_ACC_GYRO_read_reg(handle, LSM6DSL_ACC_GYRO_SENSORHUB1_REG, Bufp, len); + + LSM6DSL_ACC_GYRO_W_ODR_XL(handle, LSM6DSL_ACC_GYRO_ODR_XL_POWER_DOWN); + + if (stop) { + /* Stop everything */ + LSM6DSL_ACC_GYRO_W_FUNC_EN(handle, LSM6DSL_ACC_GYRO_FUNC_EN_DISABLED); + LSM6DSL_ACC_GYRO_W_I2C_MASTER_Enable(handle, LSM6DSL_ACC_GYRO_MASTER_ON_DISABLED); + } + + return MEMS_SUCCESS; +} + +/* Write a remote device through I2C Sensor Hub Slave 0 */ +mems_status_t LSM6DSL_ACC_GYRO_SH0_WriteByte(void *handle, u8_t SlvAddr, u8_t Reg, u8_t Bufp) +{ + LSM6DSL_ACC_GYRO_SENS_HUB_END_t op_cmpl = LSM6DSL_ACC_GYRO_SENS_HUB_END_STILL_ONGOING; + LSM6DSL_ACC_GYRO_XLDA_t op_update = LSM6DSL_ACC_GYRO_XLDA_NO_DATA_AVAIL; + u8_t dummy[6]; + + /* Open Embedded Function Register page*/ + LSM6DSL_ACC_GYRO_W_EmbeddedAccess(handle, LSM6DSL_ACC_GYRO_EMBEDDED_ACCESS_ENABLED); + + /* Write remote device I2C slave address */ + LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_SLV0_ADD, &SlvAddr, 1); + + /* Write remote device I2C subaddress */ + LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_SLV0_SUBADD, &Reg, 1); + + /* Write the data */ + LSM6DSL_ACC_GYRO_write_reg(handle, LSM6DSL_ACC_GYRO_DATAWRITE_SRC_MODE_SUB_SLV0, &Bufp, 1); + + /* Close Embedded Function Register page*/ + LSM6DSL_ACC_GYRO_W_EmbeddedAccess(handle, LSM6DSL_ACC_GYRO_EMBEDDED_ACCESS_DISABLED); + + /* Enable FUNC */ + LSM6DSL_ACC_GYRO_W_FUNC_EN(handle, LSM6DSL_ACC_GYRO_FUNC_EN_ENABLED); + + /* Enable PULL_UP_EN and MASTER_EN */ + //LSM6DSL_ACC_GYRO_W_PULL_UP_EN(handle, LSM6DSL_ACC_GYRO_PULL_UP_EN_ENABLED); + LSM6DSL_ACC_GYRO_W_I2C_MASTER_Enable(handle, LSM6DSL_ACC_GYRO_MASTER_ON_ENABLED); + + /* Syncronize the SH with internal trigger (xl) */ + LSM6DSL_ACC_GYRO_W_ODR_XL(handle, LSM6DSL_ACC_GYRO_ODR_XL_104Hz); + + /* Wait until operation is not completed */ + LSM6DSL_ACC_GYRO_GetRawAccData(handle, dummy); + do { + LSM6DSL_ACC_GYRO_R_XLDA(handle, &op_update); + } while(op_update != LSM6DSL_ACC_GYRO_XLDA_DATA_AVAIL); + do { + LSM6DSL_ACC_GYRO_R_SENS_HUB_END(handle, &op_cmpl); + } while(op_cmpl != LSM6DSL_ACC_GYRO_SENS_HUB_END_OP_COMPLETED); + + LSM6DSL_ACC_GYRO_W_ODR_XL(handle, LSM6DSL_ACC_GYRO_ODR_XL_POWER_DOWN); + + /* Stop everything */ + LSM6DSL_ACC_GYRO_W_FUNC_EN(handle, LSM6DSL_ACC_GYRO_FUNC_EN_DISABLED); + LSM6DSL_ACC_GYRO_W_I2C_MASTER_Enable(handle, LSM6DSL_ACC_GYRO_MASTER_ON_DISABLED); + + + return MEMS_SUCCESS; +}
diff -r 000000000000 -r 98c301bb7d1b Components/LSM6DSLSensor/LSM6DSL_acc_gyro_driver.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Components/LSM6DSLSensor/LSM6DSL_acc_gyro_driver.h Tue Oct 03 12:21:11 2017 +0000 @@ -0,0 +1,2752 @@ +/** + ****************************************************************************** + * @file LSM6DSL_acc_gyro_driver.h + * @author MEMS Application Team + * @version V1.5 + * @date 17-May-2016 + * @brief LSM6DSL header driver file + ****************************************************************************** + * @attention + * + * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of STMicroelectronics nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************** + */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __LSM6DSL_ACC_GYRO_DRIVER__H +#define __LSM6DSL_ACC_GYRO_DRIVER__H + +/* Includes ------------------------------------------------------------------*/ +#include <stdint.h> +/* Exported types ------------------------------------------------------------*/ + +#ifdef __cplusplus +extern "C" { +#endif + +//these could change accordingly with the architecture + +#ifndef __ARCHDEP__TYPES +#define __ARCHDEP__TYPES + +typedef unsigned char u8_t; +typedef unsigned short int u16_t; +typedef unsigned int u32_t; +typedef int i32_t; +typedef short int i16_t; +typedef signed char i8_t; + +#endif /*__ARCHDEP__TYPES*/ + +/* Exported common structure --------------------------------------------------------*/ + +#ifndef __SHARED__TYPES +#define __SHARED__TYPES + +typedef union{ + i16_t i16bit[3]; + u8_t u8bit[6]; +} Type3Axis16bit_U; + +typedef union{ + i16_t i16bit; + u8_t u8bit[2]; +} Type1Axis16bit_U; + +typedef union{ + i32_t i32bit; + u8_t u8bit[4]; +} Type1Axis32bit_U; + +typedef enum { + MEMS_SUCCESS = 0x01, + MEMS_ERROR = 0x00 +} mems_status_t; + +#endif /*__SHARED__TYPES*/ + +/* Exported macro ------------------------------------------------------------*/ + +/* Exported constants --------------------------------------------------------*/ + +/************** I2C Address *****************/ + +#define LSM6DSL_ACC_GYRO_I2C_ADDRESS_LOW 0xD4 // SAD[0] = 0 +#define LSM6DSL_ACC_GYRO_I2C_ADDRESS_HIGH 0xD6 // SAD[0] = 1 + +/************** Who am I *******************/ + +#define LSM6DSL_ACC_GYRO_WHO_AM_I 0x6A + +/************** Device Register *******************/ + +#define LSM6DSL_ACC_GYRO_FUNC_CFG_ACCESS 0X01 + +#define LSM6DSL_ACC_GYRO_SENSOR_SYNC_TIME 0X04 +#define LSM6DSL_ACC_GYRO_SENSOR_RES_RATIO 0X05 + +#define LSM6DSL_ACC_GYRO_FIFO_CTRL1 0X06 +#define LSM6DSL_ACC_GYRO_FIFO_CTRL2 0X07 +#define LSM6DSL_ACC_GYRO_FIFO_CTRL3 0X08 +#define LSM6DSL_ACC_GYRO_FIFO_CTRL4 0X09 +#define LSM6DSL_ACC_GYRO_FIFO_CTRL5 0X0A + +#define LSM6DSL_ACC_GYRO_DRDY_PULSE_CFG_G 0X0B +#define LSM6DSL_ACC_GYRO_INT1_CTRL 0X0D +#define LSM6DSL_ACC_GYRO_INT2_CTRL 0X0E +#define LSM6DSL_ACC_GYRO_WHO_AM_I_REG 0X0F +#define LSM6DSL_ACC_GYRO_CTRL1_XL 0X10 +#define LSM6DSL_ACC_GYRO_CTRL2_G 0X11 +#define LSM6DSL_ACC_GYRO_CTRL3_C 0X12 +#define LSM6DSL_ACC_GYRO_CTRL4_C 0X13 +#define LSM6DSL_ACC_GYRO_CTRL5_C 0X14 +#define LSM6DSL_ACC_GYRO_CTRL6_G 0X15 +#define LSM6DSL_ACC_GYRO_CTRL7_G 0X16 +#define LSM6DSL_ACC_GYRO_CTRL8_XL 0X17 +#define LSM6DSL_ACC_GYRO_CTRL9_XL 0X18 +#define LSM6DSL_ACC_GYRO_CTRL10_C 0X19 + +#define LSM6DSL_ACC_GYRO_MASTER_CONFIG 0X1A +#define LSM6DSL_ACC_GYRO_WAKE_UP_SRC 0X1B +#define LSM6DSL_ACC_GYRO_TAP_SRC 0X1C +#define LSM6DSL_ACC_GYRO_D6D_SRC 0X1D +#define LSM6DSL_ACC_GYRO_STATUS_REG 0X1E + +#define LSM6DSL_ACC_GYRO_OUT_TEMP_L 0X20 +#define LSM6DSL_ACC_GYRO_OUT_TEMP_H 0X21 +#define LSM6DSL_ACC_GYRO_OUTX_L_G 0X22 +#define LSM6DSL_ACC_GYRO_OUTX_H_G 0X23 +#define LSM6DSL_ACC_GYRO_OUTY_L_G 0X24 +#define LSM6DSL_ACC_GYRO_OUTY_H_G 0X25 +#define LSM6DSL_ACC_GYRO_OUTZ_L_G 0X26 +#define LSM6DSL_ACC_GYRO_OUTZ_H_G 0X27 +#define LSM6DSL_ACC_GYRO_OUTX_L_XL 0X28 +#define LSM6DSL_ACC_GYRO_OUTX_H_XL 0X29 +#define LSM6DSL_ACC_GYRO_OUTY_L_XL 0X2A +#define LSM6DSL_ACC_GYRO_OUTY_H_XL 0X2B +#define LSM6DSL_ACC_GYRO_OUTZ_L_XL 0X2C +#define LSM6DSL_ACC_GYRO_OUTZ_H_XL 0X2D +#define LSM6DSL_ACC_GYRO_SENSORHUB1_REG 0X2E +#define LSM6DSL_ACC_GYRO_SENSORHUB2_REG 0X2F +#define LSM6DSL_ACC_GYRO_SENSORHUB3_REG 0X30 +#define LSM6DSL_ACC_GYRO_SENSORHUB4_REG 0X31 +#define LSM6DSL_ACC_GYRO_SENSORHUB5_REG 0X32 +#define LSM6DSL_ACC_GYRO_SENSORHUB6_REG 0X33 +#define LSM6DSL_ACC_GYRO_SENSORHUB7_REG 0X34 +#define LSM6DSL_ACC_GYRO_SENSORHUB8_REG 0X35 +#define LSM6DSL_ACC_GYRO_SENSORHUB9_REG 0X36 +#define LSM6DSL_ACC_GYRO_SENSORHUB10_REG 0X37 +#define LSM6DSL_ACC_GYRO_SENSORHUB11_REG 0X38 +#define LSM6DSL_ACC_GYRO_SENSORHUB12_REG 0X39 +#define LSM6DSL_ACC_GYRO_FIFO_STATUS1 0X3A +#define LSM6DSL_ACC_GYRO_FIFO_STATUS2 0X3B +#define LSM6DSL_ACC_GYRO_FIFO_STATUS3 0X3C +#define LSM6DSL_ACC_GYRO_FIFO_STATUS4 0X3D +#define LSM6DSL_ACC_GYRO_FIFO_DATA_OUT_L 0X3E +#define LSM6DSL_ACC_GYRO_FIFO_DATA_OUT_H 0X3F +#define LSM6DSL_ACC_GYRO_TIMESTAMP0_REG 0X40 +#define LSM6DSL_ACC_GYRO_TIMESTAMP1_REG 0X41 +#define LSM6DSL_ACC_GYRO_TIMESTAMP2_REG 0X42 + +#define LSM6DSL_ACC_GYRO_TIMESTAMP_L 0X49 +#define LSM6DSL_ACC_GYRO_TIMESTAMP_H 0X4A + +#define LSM6DSL_ACC_GYRO_STEP_COUNTER_L 0X4B +#define LSM6DSL_ACC_GYRO_STEP_COUNTER_H 0X4C + +#define LSM6DSL_ACC_GYRO_SENSORHUB13_REG 0X4D +#define LSM6DSL_ACC_GYRO_SENSORHUB14_REG 0X4E +#define LSM6DSL_ACC_GYRO_SENSORHUB15_REG 0X4F +#define LSM6DSL_ACC_GYRO_SENSORHUB16_REG 0X50 +#define LSM6DSL_ACC_GYRO_SENSORHUB17_REG 0X51 +#define LSM6DSL_ACC_GYRO_SENSORHUB18_REG 0X52 + +#define LSM6DSL_ACC_GYRO_FUNC_SRC 0X53 +#define LSM6DSL_ACC_GYRO_TAP_CFG1 0X58 +#define LSM6DSL_ACC_GYRO_TAP_THS_6D 0X59 +#define LSM6DSL_ACC_GYRO_INT_DUR2 0X5A +#define LSM6DSL_ACC_GYRO_WAKE_UP_THS 0X5B +#define LSM6DSL_ACC_GYRO_WAKE_UP_DUR 0X5C +#define LSM6DSL_ACC_GYRO_FREE_FALL 0X5D +#define LSM6DSL_ACC_GYRO_MD1_CFG 0X5E +#define LSM6DSL_ACC_GYRO_MD2_CFG 0X5F + +#define LSM6DSL_ACC_GYRO_OUT_MAG_RAW_X_L 0X66 +#define LSM6DSL_ACC_GYRO_OUT_MAG_RAW_X_H 0X67 +#define LSM6DSL_ACC_GYRO_OUT_MAG_RAW_Y_L 0X68 +#define LSM6DSL_ACC_GYRO_OUT_MAG_RAW_Y_H 0X69 +#define LSM6DSL_ACC_GYRO_OUT_MAG_RAW_Z_L 0X6A +#define LSM6DSL_ACC_GYRO_OUT_MAG_RAW_Z_H 0X6B + +#define LSM6DSL_ACC_GYRO_X_OFS_USR 0X73 +#define LSM6DSL_ACC_GYRO_Y_OFS_USR 0X74 +#define LSM6DSL_ACC_GYRO_Z_OFS_USR 0X75 + +/************** Embedded functions register mapping *******************/ +#define LSM6DSL_ACC_GYRO_SLV0_ADD 0x02 +#define LSM6DSL_ACC_GYRO_SLV0_SUBADD 0x03 +#define LSM6DSL_ACC_GYRO_SLAVE0_CONFIG 0x04 +#define LSM6DSL_ACC_GYRO_SLV1_ADD 0x05 +#define LSM6DSL_ACC_GYRO_SLV1_SUBADD 0x06 +#define LSM6DSL_ACC_GYRO_SLAVE1_CONFIG 0x07 +#define LSM6DSL_ACC_GYRO_SLV2_ADD 0x08 +#define LSM6DSL_ACC_GYRO_SLV2_SUBADD 0x09 +#define LSM6DSL_ACC_GYRO_SLAVE2_CONFIG 0x0A +#define LSM6DSL_ACC_GYRO_SLV3_ADD 0x0B +#define LSM6DSL_ACC_GYRO_SLV3_SUBADD 0x0C +#define LSM6DSL_ACC_GYRO_SLAVE3_CONFIG 0x0D +#define LSM6DSL_ACC_GYRO_DATAWRITE_SRC_MODE_SUB_SLV0 0x0E +#define LSM6DSL_ACC_GYRO_CONFIG_PEDO_THS_MIN 0x0F + +#define LSM6DSL_ACC_GYRO_SM_STEP_THS 0x13 +#define LSM6DSL_ACC_GYRO_PEDO_DEB_REG 0x14 +#define LSM6DSL_ACC_GYRO_STEP_COUNT_DELTA 0x15 + +#define LSM6DSL_ACC_GYRO_MAG_SI_XX 0x24 +#define LSM6DSL_ACC_GYRO_MAG_SI_XY 0x25 +#define LSM6DSL_ACC_GYRO_MAG_SI_XZ 0x26 +#define LSM6DSL_ACC_GYRO_MAG_SI_YX 0x27 +#define LSM6DSL_ACC_GYRO_MAG_SI_YY 0x28 +#define LSM6DSL_ACC_GYRO_MAG_SI_YZ 0x29 +#define LSM6DSL_ACC_GYRO_MAG_SI_ZX 0x2A +#define LSM6DSL_ACC_GYRO_MAG_SI_ZY 0x2B +#define LSM6DSL_ACC_GYRO_MAG_SI_ZZ 0x2C +#define LSM6DSL_ACC_GYRO_MAG_OFFX_L 0x2D +#define LSM6DSL_ACC_GYRO_MAG_OFFX_H 0x2E +#define LSM6DSL_ACC_GYRO_MAG_OFFY_L 0x2F +#define LSM6DSL_ACC_GYRO_MAG_OFFY_H 0x30 +#define LSM6DSL_ACC_GYRO_MAG_OFFZ_L 0x31 +#define LSM6DSL_ACC_GYRO_MAG_OFFZ_H 0x32 + +/************** Generic Function *******************/ + +/******************************************************************************* +* Register : Generic - All +* Address : Generic - All +* Bit Group Name: None +* Permission : W +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_write_reg( void *handle, u8_t Reg, u8_t *Bufp, u16_t len ); + +/******************************************************************************* +* Register : Generic - All +* Address : Generic - All +* Bit Group Name: None +* Permission : R +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_read_reg( void *handle, u8_t Reg, u8_t *Bufp, u16_t len ); + +/**************** Base Function *******************/ + +/******************************************************************************* +* Register : WHO_AM_I +* Address : 0X0F +* Bit Group Name: WHO_AM_I_BIT +* Permission : RO +*******************************************************************************/ +#define LSM6DSL_ACC_GYRO_WHO_AM_I_BIT_MASK 0xFF +#define LSM6DSL_ACC_GYRO_WHO_AM_I_BIT_POSITION 0 +mems_status_t LSM6DSL_ACC_GYRO_R_WHO_AM_I(void *handle, u8_t *value); + +/******************************************************************************* +* Register : CTRL3_C +* Address : 0X12 +* Bit Group Name: BDU +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_BDU_CONTINUOS =0x00, + LSM6DSL_ACC_GYRO_BDU_BLOCK_UPDATE =0x40, +} LSM6DSL_ACC_GYRO_BDU_t; + +#define LSM6DSL_ACC_GYRO_BDU_MASK 0x40 +mems_status_t LSM6DSL_ACC_GYRO_W_BDU(void *handle, LSM6DSL_ACC_GYRO_BDU_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_BDU(void *handle, LSM6DSL_ACC_GYRO_BDU_t *value); + +/******************************************************************************* +* Register : CTRL1_XL +* Address : 0X10 +* Bit Group Name: FS_XL +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_FS_XL_2g =0x00, + LSM6DSL_ACC_GYRO_FS_XL_16g =0x04, + LSM6DSL_ACC_GYRO_FS_XL_4g =0x08, + LSM6DSL_ACC_GYRO_FS_XL_8g =0x0C, +} LSM6DSL_ACC_GYRO_FS_XL_t; + +#define LSM6DSL_ACC_GYRO_FS_XL_MASK 0x0C +mems_status_t LSM6DSL_ACC_GYRO_W_FS_XL(void *handle, LSM6DSL_ACC_GYRO_FS_XL_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_FS_XL(void *handle, LSM6DSL_ACC_GYRO_FS_XL_t *value); + +/******************************************************************************* +* Register : <REGISTER_L> - <REGISTER_H> +* Output Type : GetAccData +* Permission : RO +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_GetRawAccData(void *handle, u8_t *buff); +mems_status_t LSM6DSL_ACC_Get_Acceleration(void *handle, int *buff, u8_t from_fifo); + +/******************************************************************************* +* Register : CTRL1_XL +* Address : 0X10 +* Bit Group Name: ODR_XL +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_ODR_XL_POWER_DOWN =0x00, + LSM6DSL_ACC_GYRO_ODR_XL_13Hz =0x10, + LSM6DSL_ACC_GYRO_ODR_XL_26Hz =0x20, + LSM6DSL_ACC_GYRO_ODR_XL_52Hz =0x30, + LSM6DSL_ACC_GYRO_ODR_XL_104Hz =0x40, + LSM6DSL_ACC_GYRO_ODR_XL_208Hz =0x50, + LSM6DSL_ACC_GYRO_ODR_XL_416Hz =0x60, + LSM6DSL_ACC_GYRO_ODR_XL_833Hz =0x70, + LSM6DSL_ACC_GYRO_ODR_XL_1660Hz =0x80, + LSM6DSL_ACC_GYRO_ODR_XL_3330Hz =0x90, + LSM6DSL_ACC_GYRO_ODR_XL_6660Hz =0xA0, +} LSM6DSL_ACC_GYRO_ODR_XL_t; + +#define LSM6DSL_ACC_GYRO_ODR_XL_MASK 0xF0 +mems_status_t LSM6DSL_ACC_GYRO_W_ODR_XL(void *handle, LSM6DSL_ACC_GYRO_ODR_XL_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_ODR_XL(void *handle, LSM6DSL_ACC_GYRO_ODR_XL_t *value); +mems_status_t LSM6DSL_ACC_GYRO_translate_ODR_XL(LSM6DSL_ACC_GYRO_ODR_XL_t value, u16_t *odr_hz_val); + +/******************************************************************************* +* Register : CTRL2_G +* Address : 0X11 +* Bit Group Name: FS_G +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_FS_G_245dps =0x00, + LSM6DSL_ACC_GYRO_FS_G_500dps =0x04, + LSM6DSL_ACC_GYRO_FS_G_1000dps =0x08, + LSM6DSL_ACC_GYRO_FS_G_2000dps =0x0C, +} LSM6DSL_ACC_GYRO_FS_G_t; + +#define LSM6DSL_ACC_GYRO_FS_G_MASK 0x0C +mems_status_t LSM6DSL_ACC_GYRO_W_FS_G(void *handle, LSM6DSL_ACC_GYRO_FS_G_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_FS_G(void *handle, LSM6DSL_ACC_GYRO_FS_G_t *value); + +/******************************************************************************* +* Register : CTRL2_G +* Address : 0X11 +* Bit Group Name: ODR_G +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_ODR_G_POWER_DOWN =0x00, + LSM6DSL_ACC_GYRO_ODR_G_13Hz =0x10, + LSM6DSL_ACC_GYRO_ODR_G_26Hz =0x20, + LSM6DSL_ACC_GYRO_ODR_G_52Hz =0x30, + LSM6DSL_ACC_GYRO_ODR_G_104Hz =0x40, + LSM6DSL_ACC_GYRO_ODR_G_208Hz =0x50, + LSM6DSL_ACC_GYRO_ODR_G_416Hz =0x60, + LSM6DSL_ACC_GYRO_ODR_G_833Hz =0x70, + LSM6DSL_ACC_GYRO_ODR_G_1660Hz =0x80, + LSM6DSL_ACC_GYRO_ODR_G_3330Hz =0x90, + LSM6DSL_ACC_GYRO_ODR_G_6660Hz =0xA0, +} LSM6DSL_ACC_GYRO_ODR_G_t; + +#define LSM6DSL_ACC_GYRO_ODR_G_MASK 0xF0 +mems_status_t LSM6DSL_ACC_GYRO_W_ODR_G(void *handle, LSM6DSL_ACC_GYRO_ODR_G_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_ODR_G(void *handle, LSM6DSL_ACC_GYRO_ODR_G_t *value); +mems_status_t LSM6DSL_ACC_GYRO_translate_ODR_G(LSM6DSL_ACC_GYRO_ODR_G_t value, u16_t *odr_hz_val); + +/******************************************************************************* +* Register : <REGISTER_L> - <REGISTER_H> +* Output Type : GetGyroData +* Permission : RO +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_GetRawGyroData(void *handle, u8_t *buff); +mems_status_t LSM6DSL_ACC_Get_AngularRate(void *handle, int *buff, u8_t from_fifo); + +/******************************************************************************* +* Register : CTRL1_XL +* Address : 0X10 +* Bit Group Name: BW_SEL +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_BW_SEL_ODR2 =0x00, + LSM6DSL_ACC_GYRO_BW_SEL_ODR4 =0x02, +} LSM6DSL_ACC_GYRO_BW_SEL_t; + +#define LSM6DSL_ACC_GYRO_BW_SEL_MASK 0x02 +mems_status_t LSM6DSL_ACC_GYRO_W_BW_SEL(void *handle, LSM6DSL_ACC_GYRO_BW_SEL_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_BW_SEL(void *handle, LSM6DSL_ACC_GYRO_BW_SEL_t *value); + +/******************************************************************************* +* Register : CTRL2_G +* Address : 0X11 +* Bit Group Name: FS_125 +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_FS_125_DISABLED =0x00, + LSM6DSL_ACC_GYRO_FS_125_ENABLED =0x02, +} LSM6DSL_ACC_GYRO_FS_125_t; + +#define LSM6DSL_ACC_GYRO_FS_125_MASK 0x02 +mems_status_t LSM6DSL_ACC_GYRO_W_FS_125(void *handle, LSM6DSL_ACC_GYRO_FS_125_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_FS_125(void *handle, LSM6DSL_ACC_GYRO_FS_125_t *value); + +/**************** Advanced Function *******************/ + +/******************************************************************************* +* Register : CTRL3_C +* Address : 0X12 +* Bit Group Name: BLE +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_BLE_LSB =0x00, + LSM6DSL_ACC_GYRO_BLE_MSB =0x02, +} LSM6DSL_ACC_GYRO_BLE_t; + +#define LSM6DSL_ACC_GYRO_BLE_MASK 0x02 +mems_status_t LSM6DSL_ACC_GYRO_W_BLE(void *handle, LSM6DSL_ACC_GYRO_BLE_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_BLE(void *handle, LSM6DSL_ACC_GYRO_BLE_t *value); + +/******************************************************************************* +* Register : FUNC_CFG_ACCESS +* Address : 0X01 +* Bit Group Name: EMB_ACC +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_EMBEDDED_ACCESS_DISABLED =0x00, + LSM6DSL_ACC_GYRO_EMBEDDED_ACCESS_ENABLED =0x80, +} LSM6DSL_ACC_GYRO_EMB_ACC_t; + +#define LSM6DSL_ACC_GYRO_EMB_ACC_MASK 0x80 +mems_status_t LSM6DSL_ACC_GYRO_W_EmbeddedAccess(void *handle, LSM6DSL_ACC_GYRO_EMB_ACC_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_EmbeddedAccess(void *handle, LSM6DSL_ACC_GYRO_EMB_ACC_t *value); + +/******************************************************************************* +* Register : SENSOR_SYNC_TIME +* Address : 0X04 +* Bit Group Name: TPH +* Permission : RW +*******************************************************************************/ +#define LSM6DSL_ACC_GYRO_TPH_MASK 0xFF +#define LSM6DSL_ACC_GYRO_TPH_POSITION 0 +mems_status_t LSM6DSL_ACC_GYRO_W_Stamping_Time_Frame(void *handle, u8_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_Stamping_Time_Frame(void *handle, u8_t *value); + +/******************************************************************************* +* Register : SENSOR_SYNC_RES_RATIO +* Address : 0X05 +* Bit Group Name: RR +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_TIM_RATIO_2_11 =0x00, + LSM6DSL_ACC_GYRO_TIM_RATIO_2_12 =0x01, + LSM6DSL_ACC_GYRO_TIM_RATIO_2_13 =0x02, + LSM6DSL_ACC_GYRO_TIM_RATIO_2_14 =0x03, +} LSM6DSL_ACC_GYRO_SYNC_RES_RATIO_t; + +#define LSM6DSL_ACC_GYRO_SYNC_RES_RATIO_MASK 0x03 +mems_status_t LSM6DSL_ACC_GYRO_W_SYNC_RES_RATIO(void *handle, LSM6DSL_ACC_GYRO_SYNC_RES_RATIO_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_SYNC_RES_RATIO(void *handle, LSM6DSL_ACC_GYRO_SYNC_RES_RATIO_t *value); + + +/******************************************************************************* +* Register : FIFO_CTRL1 +* Address : 0X06 +* Bit Group Name: WTM_FIFO +* Permission : RW +*******************************************************************************/ +#define LSM6DSL_ACC_GYRO_WTM_FIFO_CTRL1_MASK 0xFF +#define LSM6DSL_ACC_GYRO_WTM_FIFO_CTRL1_POSITION 0 +#define LSM6DSL_ACC_GYRO_WTM_FIFO_CTRL2_MASK 0x07 +#define LSM6DSL_ACC_GYRO_WTM_FIFO_CTRL2_POSITION 0 +mems_status_t LSM6DSL_ACC_GYRO_W_FIFO_Watermark(void *handle, u16_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_FIFO_Watermark(void *handle, u16_t *value); + +/******************************************************************************* +* Register : FIFO_CTRL2 +* Address : 0X07 +* Bit Group Name: FIFO_TEMP_EN +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_FIFO_TEMP_DISABLE =0x00, + LSM6DSL_ACC_GYRO_FIFO_TEMP_ENABLE =0x08, +} LSM6DSL_ACC_GYRO_FIFO_TEMP_t; + +#define LSM6DSL_ACC_GYRO_FIFO_TEMP_MASK 0x08 +mems_status_t LSM6DSL_ACC_GYRO_W_FIFO_TEMP(void *handle, LSM6DSL_ACC_GYRO_FIFO_TEMP_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_FIFO_TEMP(void *handle, LSM6DSL_ACC_GYRO_FIFO_TEMP_t *value); + + +/******************************************************************************* +* Register : FIFO_CTRL2 +* Address : 0X07 +* Bit Group Name: TIM_PEDO_FIFO_DRDY +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_TIM_PEDO_FIFO_DRDY_DISABLED =0x00, + LSM6DSL_ACC_GYRO_TIM_PEDO_FIFO_DRDY_ENABLED =0x40, +} LSM6DSL_ACC_GYRO_TIM_PEDO_FIFO_DRDY_t; + +#define LSM6DSL_ACC_GYRO_TIM_PEDO_FIFO_DRDY_MASK 0x40 +mems_status_t LSM6DSL_ACC_GYRO_W_TIM_PEDO_FIFO_Write_En(void *handle, LSM6DSL_ACC_GYRO_TIM_PEDO_FIFO_DRDY_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_TIM_PEDO_FIFO_Write_En(void *handle, LSM6DSL_ACC_GYRO_TIM_PEDO_FIFO_DRDY_t *value); + +/******************************************************************************* +* Register : FIFO_CTRL2 +* Address : 0X07 +* Bit Group Name: TIM_PEDO_FIFO_EN +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_TIM_PEDO_FIFO_EN_DISABLED =0x00, + LSM6DSL_ACC_GYRO_TIM_PEDO_FIFO_EN_ENABLED =0x80, +} LSM6DSL_ACC_GYRO_TIM_PEDO_FIFO_EN_t; + +#define LSM6DSL_ACC_GYRO_TIM_PEDO_FIFO_EN_MASK 0x80 +mems_status_t LSM6DSL_ACC_GYRO_W_TIM_PEDO_FIFO_En(void *handle, LSM6DSL_ACC_GYRO_TIM_PEDO_FIFO_EN_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_TIM_PEDO_FIFO_En(void *handle, LSM6DSL_ACC_GYRO_TIM_PEDO_FIFO_EN_t *value); + +/******************************************************************************* +* Register : FIFO_CTRL3 +* Address : 0X08 +* Bit Group Name: DEC_FIFO_XL +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_DEC_FIFO_XL_DATA_NOT_IN_FIFO =0x00, + LSM6DSL_ACC_GYRO_DEC_FIFO_XL_NO_DECIMATION =0x01, + LSM6DSL_ACC_GYRO_DEC_FIFO_XL_DECIMATION_BY_2 =0x02, + LSM6DSL_ACC_GYRO_DEC_FIFO_XL_DECIMATION_BY_3 =0x03, + LSM6DSL_ACC_GYRO_DEC_FIFO_XL_DECIMATION_BY_4 =0x04, + LSM6DSL_ACC_GYRO_DEC_FIFO_XL_DECIMATION_BY_8 =0x05, + LSM6DSL_ACC_GYRO_DEC_FIFO_XL_DECIMATION_BY_16 =0x06, + LSM6DSL_ACC_GYRO_DEC_FIFO_XL_DECIMATION_BY_32 =0x07, +} LSM6DSL_ACC_GYRO_DEC_FIFO_XL_t; + +#define LSM6DSL_ACC_GYRO_DEC_FIFO_XL_MASK 0x07 +mems_status_t LSM6DSL_ACC_GYRO_W_DEC_FIFO_XL(void *handle, LSM6DSL_ACC_GYRO_DEC_FIFO_XL_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_W_DEC_FIFO_XL_val(void *handle, u16_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_DEC_FIFO_XL(void *handle, LSM6DSL_ACC_GYRO_DEC_FIFO_XL_t *value); + +/******************************************************************************* +* Register : FIFO_CTRL3 +* Address : 0X08 +* Bit Group Name: DEC_FIFO_G +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_DEC_FIFO_G_DATA_NOT_IN_FIFO =0x00, + LSM6DSL_ACC_GYRO_DEC_FIFO_G_NO_DECIMATION =0x08, + LSM6DSL_ACC_GYRO_DEC_FIFO_G_DECIMATION_BY_2 =0x10, + LSM6DSL_ACC_GYRO_DEC_FIFO_G_DECIMATION_BY_3 =0x18, + LSM6DSL_ACC_GYRO_DEC_FIFO_G_DECIMATION_BY_4 =0x20, + LSM6DSL_ACC_GYRO_DEC_FIFO_G_DECIMATION_BY_8 =0x28, + LSM6DSL_ACC_GYRO_DEC_FIFO_G_DECIMATION_BY_16 =0x30, + LSM6DSL_ACC_GYRO_DEC_FIFO_G_DECIMATION_BY_32 =0x38, +} LSM6DSL_ACC_GYRO_DEC_FIFO_G_t; + +#define LSM6DSL_ACC_GYRO_DEC_FIFO_G_MASK 0x38 +mems_status_t LSM6DSL_ACC_GYRO_W_DEC_FIFO_G(void *handle, LSM6DSL_ACC_GYRO_DEC_FIFO_G_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_W_DEC_FIFO_G_val(void *handle, u16_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_DEC_FIFO_G(void *handle, LSM6DSL_ACC_GYRO_DEC_FIFO_G_t *value); + +/******************************************************************************* +* Register : FIFO_CTRL4 +* Address : 0X09 +* Bit Group Name: DEC_DS3_FIFO +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_DEC_FIFO_DS3_DATA_NOT_IN_FIFO =0x00, + LSM6DSL_ACC_GYRO_DEC_FIFO_DS3_NO_DECIMATION =0x01, + LSM6DSL_ACC_GYRO_DEC_FIFO_DS3_DECIMATION_BY_2 =0x02, + LSM6DSL_ACC_GYRO_DEC_FIFO_DS3_DECIMATION_BY_3 =0x03, + LSM6DSL_ACC_GYRO_DEC_FIFO_DS3_DECIMATION_BY_4 =0x04, + LSM6DSL_ACC_GYRO_DEC_FIFO_DS3_DECIMATION_BY_8 =0x05, + LSM6DSL_ACC_GYRO_DEC_FIFO_DS3_DECIMATION_BY_16 =0x06, + LSM6DSL_ACC_GYRO_DEC_FIFO_DS3_DECIMATION_BY_32 =0x07, +} LSM6DSL_ACC_GYRO_DEC_FIFO_DS3_t; + +#define LSM6DSL_ACC_GYRO_DEC_FIFO_DS3_MASK 0x07 +mems_status_t LSM6DSL_ACC_GYRO_W_DEC_FIFO_DS3(void *handle, LSM6DSL_ACC_GYRO_DEC_FIFO_DS3_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_DEC_FIFO_DS3(void *handle, LSM6DSL_ACC_GYRO_DEC_FIFO_DS3_t *value); + +/******************************************************************************* +* Register : FIFO_CTRL4 +* Address : 0X09 +* Bit Group Name: DEC_DS4_FIFO +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_DEC_FIFO_DS4_DATA_NOT_IN_FIFO =0x00, + LSM6DSL_ACC_GYRO_DEC_FIFO_DS4_NO_DECIMATION =0x08, + LSM6DSL_ACC_GYRO_DEC_FIFO_DS4_DECIMATION_BY_2 =0x10, + LSM6DSL_ACC_GYRO_DEC_FIFO_DS4_DECIMATION_BY_3 =0x18, + LSM6DSL_ACC_GYRO_DEC_FIFO_DS4_DECIMATION_BY_4 =0x20, + LSM6DSL_ACC_GYRO_DEC_FIFO_DS4_DECIMATION_BY_8 =0x28, + LSM6DSL_ACC_GYRO_DEC_FIFO_DS4_DECIMATION_BY_16 =0x30, + LSM6DSL_ACC_GYRO_DEC_FIFO_DS4_DECIMATION_BY_32 =0x38, +} LSM6DSL_ACC_GYRO_DEC_FIFO_DS4_t; + +#define LSM6DSL_ACC_GYRO_DEC_FIFO_DS4_MASK 0x38 +mems_status_t LSM6DSL_ACC_GYRO_W_DEC_FIFO_DS4(void *handle, LSM6DSL_ACC_GYRO_DEC_FIFO_DS4_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_DEC_FIFO_DS4(void *handle, LSM6DSL_ACC_GYRO_DEC_FIFO_DS4_t *value); + +/******************************************************************************* +* Register : FIFO_CTRL4 +* Address : 0X09 +* Bit Group Name: HI_DATA_ONLY +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_HI_DATA_ONLY_DISABLED =0x00, + LSM6DSL_ACC_GYRO_HI_DATA_ONLY_ENABLED =0x40, +} LSM6DSL_ACC_GYRO_HI_DATA_ONLY_t; + +#define LSM6DSL_ACC_GYRO_HI_DATA_ONLY_MASK 0x40 +mems_status_t LSM6DSL_ACC_GYRO_W_HI_DATA_ONLY(void *handle, LSM6DSL_ACC_GYRO_HI_DATA_ONLY_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_HI_DATA_ONLY(void *handle, LSM6DSL_ACC_GYRO_HI_DATA_ONLY_t *value); + +/******************************************************************************* +* Register : FIFO_CTRL4 +* Address : 0X09 +* Bit Group Name: STOP_ON_FTH +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_STOP_ON_FTH_DISABLED =0x00, + LSM6DSL_ACC_GYRO_STOP_ON_FTH_ENABLED =0x80, +} LSM6DSL_ACC_GYRO_STOP_ON_FTH_t; + +#define LSM6DSL_ACC_GYRO_STOP_ON_FTH_MASK 0x80 +mems_status_t LSM6DSL_ACC_GYRO_W_STOP_ON_FTH(void *handle, LSM6DSL_ACC_GYRO_STOP_ON_FTH_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_STOP_ON_FTH(void *handle, LSM6DSL_ACC_GYRO_STOP_ON_FTH_t *value); + +/******************************************************************************* +* Register : FIFO_CTRL5 +* Address : 0X0A +* Bit Group Name: FIFO_MODE +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_FIFO_MODE_BYPASS =0x00, + LSM6DSL_ACC_GYRO_FIFO_MODE_FIFO =0x01, + LSM6DSL_ACC_GYRO_FIFO_MODE_STREAM =0x02, + LSM6DSL_ACC_GYRO_FIFO_MODE_STF =0x03, + LSM6DSL_ACC_GYRO_FIFO_MODE_BTS =0x04, + LSM6DSL_ACC_GYRO_FIFO_MODE_DYN_STREAM =0x05, + LSM6DSL_ACC_GYRO_FIFO_MODE_DYN_STREAM_2 =0x06, + LSM6DSL_ACC_GYRO_FIFO_MODE_BTF =0x07, +} LSM6DSL_ACC_GYRO_FIFO_MODE_t; + +#define LSM6DSL_ACC_GYRO_FIFO_MODE_MASK 0x07 +mems_status_t LSM6DSL_ACC_GYRO_W_FIFO_MODE(void *handle, LSM6DSL_ACC_GYRO_FIFO_MODE_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_FIFO_MODE(void *handle, LSM6DSL_ACC_GYRO_FIFO_MODE_t *value); + +/******************************************************************************* +* Register : FIFO_CTRL5 +* Address : 0X0A +* Bit Group Name: ODR_FIFO +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_ODR_FIFO_10Hz =0x08, + LSM6DSL_ACC_GYRO_ODR_FIFO_25Hz =0x10, + LSM6DSL_ACC_GYRO_ODR_FIFO_50Hz =0x18, + LSM6DSL_ACC_GYRO_ODR_FIFO_100Hz =0x20, + LSM6DSL_ACC_GYRO_ODR_FIFO_200Hz =0x28, + LSM6DSL_ACC_GYRO_ODR_FIFO_400Hz =0x30, + LSM6DSL_ACC_GYRO_ODR_FIFO_800Hz =0x38, + LSM6DSL_ACC_GYRO_ODR_FIFO_1600Hz =0x40, + LSM6DSL_ACC_GYRO_ODR_FIFO_3300Hz =0x48, + LSM6DSL_ACC_GYRO_ODR_FIFO_6600Hz =0x50, + LSM6DSL_ACC_GYRO_ODR_FIFO_13300Hz =0x58, +} LSM6DSL_ACC_GYRO_ODR_FIFO_t; + +#define LSM6DSL_ACC_GYRO_ODR_FIFO_MASK 0x78 +mems_status_t LSM6DSL_ACC_GYRO_W_ODR_FIFO(void *handle, LSM6DSL_ACC_GYRO_ODR_FIFO_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_ODR_FIFO(void *handle, LSM6DSL_ACC_GYRO_ODR_FIFO_t *value); + +/******************************************************************************* +* Register : DRDY_PULSE_CFG_G +* Address : 0X0B +* Bit Group Name: DRDY_PULSE +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_DRDY_LATCH =0x00, + LSM6DSL_ACC_GYRO_DRDY_PULSE =0x80, +} LSM6DSL_ACC_GYRO_DRDY_PULSE_t; + +#define LSM6DSL_ACC_GYRO_DRDY_PULSE_MASK 0x80 +mems_status_t LSM6DSL_ACC_GYRO_W_DRDY_PULSE(void *handle, LSM6DSL_ACC_GYRO_DRDY_PULSE_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_DRDY_PULSE(void *handle, LSM6DSL_ACC_GYRO_DRDY_PULSE_t *value); + +/******************************************************************************* +* Register : INT1_CTRL +* Address : 0X0D +* Bit Group Name: INT1_DRDY_XL +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_INT1_DRDY_XL_DISABLED =0x00, + LSM6DSL_ACC_GYRO_INT1_DRDY_XL_ENABLED =0x01, +} LSM6DSL_ACC_GYRO_INT1_DRDY_XL_t; + +#define LSM6DSL_ACC_GYRO_INT1_DRDY_XL_MASK 0x01 +mems_status_t LSM6DSL_ACC_GYRO_W_DRDY_XL_on_INT1(void *handle, LSM6DSL_ACC_GYRO_INT1_DRDY_XL_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_DRDY_XL_on_INT1(void *handle, LSM6DSL_ACC_GYRO_INT1_DRDY_XL_t *value); + +/******************************************************************************* +* Register : INT1_CTRL +* Address : 0X0D +* Bit Group Name: INT1_DRDY_G +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_INT1_DRDY_G_DISABLED =0x00, + LSM6DSL_ACC_GYRO_INT1_DRDY_G_ENABLED =0x02, +} LSM6DSL_ACC_GYRO_INT1_DRDY_G_t; + +#define LSM6DSL_ACC_GYRO_INT1_DRDY_G_MASK 0x02 +mems_status_t LSM6DSL_ACC_GYRO_W_DRDY_G_on_INT1(void *handle, LSM6DSL_ACC_GYRO_INT1_DRDY_G_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_DRDY_G_on_INT1(void *handle, LSM6DSL_ACC_GYRO_INT1_DRDY_G_t *value); + +/******************************************************************************* +* Register : INT1_CTRL +* Address : 0X0D +* Bit Group Name: INT1_BOOT +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_INT1_BOOT_DISABLED =0x00, + LSM6DSL_ACC_GYRO_INT1_BOOT_ENABLED =0x04, +} LSM6DSL_ACC_GYRO_INT1_BOOT_t; + +#define LSM6DSL_ACC_GYRO_INT1_BOOT_MASK 0x04 +mems_status_t LSM6DSL_ACC_GYRO_W_BOOT_on_INT1(void *handle, LSM6DSL_ACC_GYRO_INT1_BOOT_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_BOOT_on_INT1(void *handle, LSM6DSL_ACC_GYRO_INT1_BOOT_t *value); + +/******************************************************************************* +* Register : INT1_CTRL +* Address : 0X0D +* Bit Group Name: INT1_FTH +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_INT1_FTH_DISABLED =0x00, + LSM6DSL_ACC_GYRO_INT1_FTH_ENABLED =0x08, +} LSM6DSL_ACC_GYRO_INT1_FTH_t; + +#define LSM6DSL_ACC_GYRO_INT1_FTH_MASK 0x08 +mems_status_t LSM6DSL_ACC_GYRO_W_FIFO_TSHLD_on_INT1(void *handle, LSM6DSL_ACC_GYRO_INT1_FTH_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_FIFO_TSHLD_on_INT1(void *handle, LSM6DSL_ACC_GYRO_INT1_FTH_t *value); + +/******************************************************************************* +* Register : INT1_CTRL +* Address : 0X0D +* Bit Group Name: INT1_OVR +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_INT1_OVR_DISABLED =0x00, + LSM6DSL_ACC_GYRO_INT1_OVR_ENABLED =0x10, +} LSM6DSL_ACC_GYRO_INT1_OVR_t; + +#define LSM6DSL_ACC_GYRO_INT1_OVR_MASK 0x10 +mems_status_t LSM6DSL_ACC_GYRO_W_OVERRUN_on_INT1(void *handle, LSM6DSL_ACC_GYRO_INT1_OVR_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_OVERRUN_on_INT1(void *handle, LSM6DSL_ACC_GYRO_INT1_OVR_t *value); + +/******************************************************************************* +* Register : INT1_CTRL +* Address : 0X0D +* Bit Group Name: INT1_FULL_FLAG +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_INT1_FULL_FLAG_DISABLED =0x00, + LSM6DSL_ACC_GYRO_INT1_FULL_FLAG_ENABLED =0x20, +} LSM6DSL_ACC_GYRO_INT1_FULL_FLAG_t; + +#define LSM6DSL_ACC_GYRO_INT1_FULL_FLAG_MASK 0x20 +mems_status_t LSM6DSL_ACC_GYRO_W_FULL_FLAG_on_INT1(void *handle, LSM6DSL_ACC_GYRO_INT1_FULL_FLAG_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_FULL_FLAG_on_INT1(void *handle, LSM6DSL_ACC_GYRO_INT1_FULL_FLAG_t *value); + +/******************************************************************************* +* Register : INT1_CTRL +* Address : 0X0D +* Bit Group Name: INT1_SIGN_MOT +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_INT1_SIGN_MOT_DISABLED =0x00, + LSM6DSL_ACC_GYRO_INT1_SIGN_MOT_ENABLED =0x40, +} LSM6DSL_ACC_GYRO_INT1_SIGN_MOT_t; + +#define LSM6DSL_ACC_GYRO_INT1_SIGN_MOT_MASK 0x40 +mems_status_t LSM6DSL_ACC_GYRO_W_SIGN_MOT_on_INT1(void *handle, LSM6DSL_ACC_GYRO_INT1_SIGN_MOT_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_SIGN_MOT_on_INT1(void *handle, LSM6DSL_ACC_GYRO_INT1_SIGN_MOT_t *value); + +/******************************************************************************* +* Register : INT1_CTRL +* Address : 0X0D +* Bit Group Name: INT1_STEP_DETECTOR +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_INT1_PEDO_DISABLED =0x00, + LSM6DSL_ACC_GYRO_INT1_PEDO_ENABLED =0x80, +} LSM6DSL_ACC_GYRO_INT1_PEDO_t; + +#define LSM6DSL_ACC_GYRO_INT1_PEDO_MASK 0x80 +mems_status_t LSM6DSL_ACC_GYRO_W_STEP_DET_on_INT1(void *handle, LSM6DSL_ACC_GYRO_INT1_PEDO_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_STEP_DET_on_INT1(void *handle, LSM6DSL_ACC_GYRO_INT1_PEDO_t *value); + +/******************************************************************************* +* Register : INT2_CTRL +* Address : 0X0E +* Bit Group Name: INT2_DRDY_XL +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_INT2_DRDY_XL_DISABLED =0x00, + LSM6DSL_ACC_GYRO_INT2_DRDY_XL_ENABLED =0x01, +} LSM6DSL_ACC_GYRO_INT2_DRDY_XL_t; + +#define LSM6DSL_ACC_GYRO_INT2_DRDY_XL_MASK 0x01 +mems_status_t LSM6DSL_ACC_GYRO_W_DRDY_XL_on_INT2(void *handle, LSM6DSL_ACC_GYRO_INT2_DRDY_XL_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_DRDY_XL_on_INT2(void *handle, LSM6DSL_ACC_GYRO_INT2_DRDY_XL_t *value); + +/******************************************************************************* +* Register : INT2_CTRL +* Address : 0X0E +* Bit Group Name: INT2_DRDY_G +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_INT2_DRDY_G_DISABLED =0x00, + LSM6DSL_ACC_GYRO_INT2_DRDY_G_ENABLED =0x02, +} LSM6DSL_ACC_GYRO_INT2_DRDY_G_t; + +#define LSM6DSL_ACC_GYRO_INT2_DRDY_G_MASK 0x02 +mems_status_t LSM6DSL_ACC_GYRO_W_DRDY_G_on_INT2(void *handle, LSM6DSL_ACC_GYRO_INT2_DRDY_G_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_DRDY_G_on_INT2(void *handle, LSM6DSL_ACC_GYRO_INT2_DRDY_G_t *value); + +/******************************************************************************* +* Register : INT2_CTRL +* Address : 0X0E +* Bit Group Name: INT2_DRDY_TEMP +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_INT2_DRDY_TEMP_DISABLED =0x00, + LSM6DSL_ACC_GYRO_INT2_DRDY_TEMP_ENABLED =0x04, +} LSM6DSL_ACC_GYRO_INT2_DRDY_TEMP_t; + +#define LSM6DSL_ACC_GYRO_INT2_DRDY_TEMP_MASK 0x04 +mems_status_t LSM6DSL_ACC_GYRO_W_DRDY_TEMP_on_INT2(void *handle, LSM6DSL_ACC_GYRO_INT2_DRDY_TEMP_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_DRDY_TEMP_on_INT2(void *handle, LSM6DSL_ACC_GYRO_INT2_DRDY_TEMP_t *value); + + +/******************************************************************************* +* Register : INT2_CTRL +* Address : 0X0E +* Bit Group Name: INT2_FTH +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_INT2_FTH_DISABLED =0x00, + LSM6DSL_ACC_GYRO_INT2_FTH_ENABLED =0x08, +} LSM6DSL_ACC_GYRO_INT2_FTH_t; + +#define LSM6DSL_ACC_GYRO_INT2_FTH_MASK 0x08 +mems_status_t LSM6DSL_ACC_GYRO_W_FIFO_TSHLD_on_INT2(void *handle, LSM6DSL_ACC_GYRO_INT2_FTH_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_FIFO_TSHLD_on_INT2(void *handle, LSM6DSL_ACC_GYRO_INT2_FTH_t *value); + +/******************************************************************************* +* Register : INT2_CTRL +* Address : 0X0E +* Bit Group Name: INT2_OVR +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_INT2_OVR_DISABLED =0x00, + LSM6DSL_ACC_GYRO_INT2_OVR_ENABLED =0x10, +} LSM6DSL_ACC_GYRO_INT2_OVR_t; + +#define LSM6DSL_ACC_GYRO_INT2_OVR_MASK 0x10 +mems_status_t LSM6DSL_ACC_GYRO_W_OVERRUN_on_INT2(void *handle, LSM6DSL_ACC_GYRO_INT2_OVR_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_OVERRUN_on_INT2(void *handle, LSM6DSL_ACC_GYRO_INT2_OVR_t *value); + +/******************************************************************************* +* Register : INT2_CTRL +* Address : 0X0E +* Bit Group Name: INT2_FULL_FLAG +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_INT2_FULL_FLAG_DISABLED =0x00, + LSM6DSL_ACC_GYRO_INT2_FULL_FLAG_ENABLED =0x20, +} LSM6DSL_ACC_GYRO_INT2_FULL_FLAG_t; + +#define LSM6DSL_ACC_GYRO_INT2_FULL_FLAG_MASK 0x20 +mems_status_t LSM6DSL_ACC_GYRO_W_FULL_FLAG_on_INT2(void *handle, LSM6DSL_ACC_GYRO_INT2_FULL_FLAG_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_FULL_FLAG_on_INT2(void *handle, LSM6DSL_ACC_GYRO_INT2_FULL_FLAG_t *value); + +/******************************************************************************* +* Register : INT2_CTRL +* Address : 0X0E +* Bit Group Name: INT2_STEP_COUNT_OV +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_INT2_STEP_COUNT_OV_DISABLED =0x00, + LSM6DSL_ACC_GYRO_INT2_STEP_COUNT_OV_ENABLED =0x40, +} LSM6DSL_ACC_GYRO_INT2_STEP_COUNT_OV_t; + +#define LSM6DSL_ACC_GYRO_INT2_STEP_COUNT_OV_MASK 0x40 +mems_status_t LSM6DSL_ACC_GYRO_W_STEP_COUNT_OV_on_INT2(void *handle, LSM6DSL_ACC_GYRO_INT2_STEP_COUNT_OV_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_STEP_COUNT_OV_on_INT2(void *handle, LSM6DSL_ACC_GYRO_INT2_STEP_COUNT_OV_t *value); + +/******************************************************************************* +* Register : INT2_CTRL +* Address : 0X0E +* Bit Group Name: INT2_STEP_DELTA +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_INT2_STEP_DELTA_DISABLED =0x00, + LSM6DSL_ACC_GYRO_INT2_STEP_DELTA_ENABLED =0x80, +} LSM6DSL_ACC_GYRO_INT2_STEP_DELTA_t; + +#define LSM6DSL_ACC_GYRO_INT2_STEP_DELTA_MASK 0x80 +mems_status_t LSM6DSL_ACC_GYRO_W_STEP_DELTA_on_INT2(void *handle, LSM6DSL_ACC_GYRO_INT2_STEP_DELTA_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_STEP_DELTA_on_INT2(void *handle, LSM6DSL_ACC_GYRO_INT2_STEP_DELTA_t *value); + +/******************************************************************************* +* Register : CTRL3_C +* Address : 0X12 +* Bit Group Name: SW_RESET +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_SW_RESET_NORMAL_MODE =0x00, + LSM6DSL_ACC_GYRO_SW_RESET_RESET_DEVICE =0x01, +} LSM6DSL_ACC_GYRO_SW_RESET_t; + +#define LSM6DSL_ACC_GYRO_SW_RESET_MASK 0x01 +mems_status_t LSM6DSL_ACC_GYRO_W_SW_RESET(void *handle, LSM6DSL_ACC_GYRO_SW_RESET_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_SW_RESET(void *handle, LSM6DSL_ACC_GYRO_SW_RESET_t *value); + + +/******************************************************************************* +* Register : CTRL3_C +* Address : 0X12 +* Bit Group Name: IF_INC +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_IF_INC_DISABLED =0x00, + LSM6DSL_ACC_GYRO_IF_INC_ENABLED =0x04, +} LSM6DSL_ACC_GYRO_IF_INC_t; + +#define LSM6DSL_ACC_GYRO_IF_INC_MASK 0x04 +mems_status_t LSM6DSL_ACC_GYRO_W_IF_Addr_Incr(void *handle, LSM6DSL_ACC_GYRO_IF_INC_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_IF_Addr_Incr(void *handle, LSM6DSL_ACC_GYRO_IF_INC_t *value); + +/******************************************************************************* +* Register : CTRL3_C +* Address : 0X12 +* Bit Group Name: SIM +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_SIM_4_WIRE =0x00, + LSM6DSL_ACC_GYRO_SIM_3_WIRE =0x08, +} LSM6DSL_ACC_GYRO_SIM_t; + +#define LSM6DSL_ACC_GYRO_SIM_MASK 0x08 +mems_status_t LSM6DSL_ACC_GYRO_W_SPI_Mode(void *handle, LSM6DSL_ACC_GYRO_SIM_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_SPI_Mode(void *handle, LSM6DSL_ACC_GYRO_SIM_t *value); + +/******************************************************************************* +* Register : CTRL3_C +* Address : 0X12 +* Bit Group Name: PP_OD +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_PP_OD_PUSH_PULL =0x00, + LSM6DSL_ACC_GYRO_PP_OD_OPEN_DRAIN =0x10, +} LSM6DSL_ACC_GYRO_PP_OD_t; + +#define LSM6DSL_ACC_GYRO_PP_OD_MASK 0x10 +mems_status_t LSM6DSL_ACC_GYRO_W_PadSel(void *handle, LSM6DSL_ACC_GYRO_PP_OD_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_PadSel(void *handle, LSM6DSL_ACC_GYRO_PP_OD_t *value); + +/******************************************************************************* +* Register : CTRL3_C +* Address : 0X12 +* Bit Group Name: H_LACTIVE +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_INT_ACT_LEVEL_ACTIVE_HI =0x00, + LSM6DSL_ACC_GYRO_INT_ACT_LEVEL_ACTIVE_LO =0x20, +} LSM6DSL_ACC_GYRO_INT_ACT_LEVEL_t; + +#define LSM6DSL_ACC_GYRO_INT_ACT_LEVEL_MASK 0x20 +mems_status_t LSM6DSL_ACC_GYRO_W_INT_ACT_LEVEL(void *handle, LSM6DSL_ACC_GYRO_INT_ACT_LEVEL_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_INT_ACT_LEVEL(void *handle, LSM6DSL_ACC_GYRO_INT_ACT_LEVEL_t *value); + + +/******************************************************************************* +* Register : CTRL3_C +* Address : 0X12 +* Bit Group Name: BOOT +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_BOOT_NORMAL_MODE =0x00, + LSM6DSL_ACC_GYRO_BOOT_REBOOT_MODE =0x80, +} LSM6DSL_ACC_GYRO_BOOT_t; + +#define LSM6DSL_ACC_GYRO_BOOT_MASK 0x80 +mems_status_t LSM6DSL_ACC_GYRO_W_BOOT(void *handle, LSM6DSL_ACC_GYRO_BOOT_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_BOOT(void *handle, LSM6DSL_ACC_GYRO_BOOT_t *value); + +/******************************************************************************* +* Register : CTRL4_C +* Address : 0X13 +* Bit Group Name: LPF1_SEL_G +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_MODE3_LPF1_G_DISABLED =0x00, + LSM6DSL_ACC_GYRO_MODE3_LPF1_G_ENABLED =0x02, +} LSM6DSL_ACC_GYRO_LPF1_SEL_G_t; + +#define LSM6DSL_ACC_GYRO_LPF1_SEL_G_MASK 0x02 +mems_status_t LSM6DSL_ACC_GYRO_W_LPF1_SEL_G(void *handle, LSM6DSL_ACC_GYRO_LPF1_SEL_G_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_LPF1_SEL_G(void *handle, LSM6DSL_ACC_GYRO_LPF1_SEL_G_t *value); + +/******************************************************************************* +* Register : CTRL4_C +* Address : 0X13 +* Bit Group Name: I2C_DISABLE +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_I2C_DISABLE_I2C_AND_SPI =0x00, + LSM6DSL_ACC_GYRO_I2C_DISABLE_SPI_ONLY =0x04, +} LSM6DSL_ACC_GYRO_I2C_DISABLE_t; + +#define LSM6DSL_ACC_GYRO_I2C_DISABLE_MASK 0x04 +mems_status_t LSM6DSL_ACC_GYRO_W_I2C_DISABLE(void *handle, LSM6DSL_ACC_GYRO_I2C_DISABLE_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_I2C_DISABLE(void *handle, LSM6DSL_ACC_GYRO_I2C_DISABLE_t *value); + +/******************************************************************************* +* Register : CTRL4_C +* Address : 0X13 +* Bit Group Name: DRDY_MSK +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_DRDY_MSK_DISABLED =0x00, + LSM6DSL_ACC_GYRO_DRDY_MSK_ENABLED =0x08, +} LSM6DSL_ACC_GYRO_DRDY_MSK_t; + +#define LSM6DSL_ACC_GYRO_DRDY_MSK_MASK 0x08 +mems_status_t LSM6DSL_ACC_GYRO_W_DRDY_MSK(void *handle, LSM6DSL_ACC_GYRO_DRDY_MSK_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_DRDY_MSK(void *handle, LSM6DSL_ACC_GYRO_DRDY_MSK_t *value); + +/******************************************************************************* +* Register : CTRL4_C +* Address : 0X13 +* Bit Group Name: INT2_ON_INT1 +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_INT2_ON_INT1_DISABLED =0x00, + LSM6DSL_ACC_GYRO_INT2_ON_INT1_ENABLED =0x20, +} LSM6DSL_ACC_GYRO_INT2_ON_INT1_t; + +#define LSM6DSL_ACC_GYRO_INT2_ON_INT1_MASK 0x20 +mems_status_t LSM6DSL_ACC_GYRO_W_INT2_ON_INT1(void *handle, LSM6DSL_ACC_GYRO_INT2_ON_INT1_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_INT2_ON_INT1(void *handle, LSM6DSL_ACC_GYRO_INT2_ON_INT1_t *value); + +/******************************************************************************* +* Register : CTRL4_C +* Address : 0X13 +* Bit Group Name: SLEEP_G +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_SLEEP_G_DISABLED =0x00, + LSM6DSL_ACC_GYRO_SLEEP_G_ENABLED =0x40, +} LSM6DSL_ACC_GYRO_SLEEP_G_t; + +#define LSM6DSL_ACC_GYRO_SLEEP_G_MASK 0x40 +mems_status_t LSM6DSL_ACC_GYRO_W_SleepMode_G(void *handle, LSM6DSL_ACC_GYRO_SLEEP_G_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_SleepMode_G(void *handle, LSM6DSL_ACC_GYRO_SLEEP_G_t *value); + +/******************************************************************************* +* Register : CTRL5_C +* Address : 0X14 +* Bit Group Name: ST_XL +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_ST_XL_NORMAL_MODE =0x00, + LSM6DSL_ACC_GYRO_ST_XL_POS_SIGN_TEST =0x01, + LSM6DSL_ACC_GYRO_ST_XL_NEG_SIGN_TEST =0x02, + LSM6DSL_ACC_GYRO_ST_XL_NA =0x03, +} LSM6DSL_ACC_GYRO_ST_XL_t; + +#define LSM6DSL_ACC_GYRO_ST_XL_MASK 0x03 +mems_status_t LSM6DSL_ACC_GYRO_W_SelfTest_XL(void *handle, LSM6DSL_ACC_GYRO_ST_XL_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_SelfTest_XL(void *handle, LSM6DSL_ACC_GYRO_ST_XL_t *value); + +/******************************************************************************* +* Register : CTRL5_C +* Address : 0X14 +* Bit Group Name: ST_G +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_ST_G_NORMAL_MODE =0x00, + LSM6DSL_ACC_GYRO_ST_G_POS_SIGN_TEST =0x04, + LSM6DSL_ACC_GYRO_ST_G_NA =0x08, + LSM6DSL_ACC_GYRO_ST_G_NEG_SIGN_TEST =0x0C, +} LSM6DSL_ACC_GYRO_ST_G_t; + +#define LSM6DSL_ACC_GYRO_ST_G_MASK 0x0C +mems_status_t LSM6DSL_ACC_GYRO_W_SelfTest_G(void *handle, LSM6DSL_ACC_GYRO_ST_G_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_SelfTest_G(void *handle, LSM6DSL_ACC_GYRO_ST_G_t *value); + +/******************************************************************************* +* Register : CTRL5_C +* Address : 0X14 +* Bit Group Name: DEN_LH +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_DEN_LOW =0x00, + LSM6DSL_ACC_GYRO_DEN_HIGH =0x10, +} LSM6DSL_ACC_GYRO_DEN_LH_t; + +#define LSM6DSL_ACC_GYRO_DEN_LH_MASK 0x10 +mems_status_t LSM6DSL_ACC_GYRO_W_DEN_Polarity(void *handle, LSM6DSL_ACC_GYRO_DEN_LH_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_DEN_Polarity(void *handle, LSM6DSL_ACC_GYRO_DEN_LH_t *value); + +/******************************************************************************* +* Register : CTRL5_C +* Address : 0X14 +* Bit Group Name: ST_ROUNDING +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_NO_ROUNDING =0x00, + LSM6DSL_ACC_GYRO_ACC_ONLY =0x20, + LSM6DSL_ACC_GYRO_GYRO_ONLY =0x40, + LSM6DSL_ACC_GYRO_ACC_GYRO =0x60, + LSM6DSL_ACC_GYRO_SH1_SH6 =0x80, + LSM6DSL_ACC_GYRO_ACC_SH1_SH6 =0xA0, + LSM6DSL_ACC_GYRO_ACC_GYRO_SH1_SH6_SH7_SH12 =0xC0, + LSM6DSL_ACC_GYRO_ACC_GYRO_SH1_SH6 =0xE0, +} LSM6DSL_ACC_GYRO_ROUNDING_t; + +#define LSM6DSL_ACC_GYRO_LSM6DSL_ACC_GYRO_ROUNDING_t_MASK 0xE0 +mems_status_t LSM6DSL_ACC_GYRO_W_CircularBurstMode(void *handle, LSM6DSL_ACC_GYRO_ROUNDING_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_CircularBurstMode(void *handle, LSM6DSL_ACC_GYRO_ROUNDING_t *value); + +/******************************************************************************* +* Register : CTRL6_G +* Address : 0X15 +* Bit Group Name: FTYPE +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_LP_G_NORMAL =0x00, + LSM6DSL_ACC_GYRO_LP_G_NARROW =0x01, + LSM6DSL_ACC_GYRO_LP_G_VERY_NARROW =0x02, + LSM6DSL_ACC_GYRO_LP_G_WIDE =0x03, +} LSM6DSL_ACC_GYRO_FTYPE_t; + +#define LSM6DSL_ACC_GYRO_FTYPE_MASK 0x03 +mems_status_t LSM6DSL_ACC_GYRO_W_LP_BW_G(void *handle, LSM6DSL_ACC_GYRO_FTYPE_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_LP_BW_G(void *handle, LSM6DSL_ACC_GYRO_FTYPE_t *value); + +/******************************************************************************* +* Register : CTRL6_G +* Address : 0X15 +* Bit Group Name: USR_OFF_W +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_2Emin10 =0x00, + LSM6DSL_ACC_GYRO_2Emin6 =0x08, +} LSM6DSL_ACC_GYRO_USR_OFF_W_t; + +#define LSM6DSL_ACC_GYRO_USR_OFF_W_MASK 0x08 +mems_status_t LSM6DSL_ACC_GYRO_W_UserOffsetWeight(void *handle, LSM6DSL_ACC_GYRO_USR_OFF_W_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_UserOffsetWeight(void *handle, LSM6DSL_ACC_GYRO_USR_OFF_W_t *value); + + +/******************************************************************************* +* Register : CTRL6_G +* Address : 0X15 +* Bit Group Name: LP_XL +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_LP_XL_DISABLED =0x00, + LSM6DSL_ACC_GYRO_LP_XL_ENABLED =0x10, +} LSM6DSL_ACC_GYRO_LP_XL_t; + +#define LSM6DSL_ACC_GYRO_LP_XL_MASK 0x10 +mems_status_t LSM6DSL_ACC_GYRO_W_LowPower_XL(void *handle, LSM6DSL_ACC_GYRO_LP_XL_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_LowPower_XL(void *handle, LSM6DSL_ACC_GYRO_LP_XL_t *value); + +/******************************************************************************* +* Register : CTRL6_G +* Address : 0X15 +* Bit Group Name: DEN_LVL2_EN +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_DEN_LVL2_EN_DISABLED =0x00, + LSM6DSL_ACC_GYRO_DEN_LVL2_EN_ENABLED =0x20, +} LSM6DSL_ACC_GYRO_DEN_LVL2_EN_t; + +#define LSM6DSL_ACC_GYRO_DEN_LVL2_EN_MASK 0x20 +mems_status_t LSM6DSL_ACC_GYRO_W_DEN_LVL2_EN(void *handle, LSM6DSL_ACC_GYRO_DEN_LVL2_EN_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_DEN_LVL2_EN(void *handle, LSM6DSL_ACC_GYRO_DEN_LVL2_EN_t *value); + +/******************************************************************************* +* Register : CTRL6_G +* Address : 0X15 +* Bit Group Name: DEN_LVL_EN +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_DEN_LVL_EN_DISABLED =0x00, + LSM6DSL_ACC_GYRO_DEN_LVL_EN_ENABLED =0x40, +} LSM6DSL_ACC_GYRO_DEN_LVL_EN_t; + +#define LSM6DSL_ACC_GYRO_DEN_LVL_EN_MASK 0x40 +mems_status_t LSM6DSL_ACC_GYRO_W_DEN_LVL_EN(void *handle, LSM6DSL_ACC_GYRO_DEN_LVL_EN_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_DEN_LVL_EN(void *handle, LSM6DSL_ACC_GYRO_DEN_LVL_EN_t *value); + +/******************************************************************************* +* Register : CTRL6_G +* Address : 0X15 +* Bit Group Name: TRIG_EN +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_DEN_EDGE_EN_DISABLED =0x00, + LSM6DSL_ACC_GYRO_DEN_EDGE_EN_ENABLED =0x80, +} LSM6DSL_ACC_GYRO_DEN_EDGE_EN_t; + +#define LSM6DSL_ACC_GYRO_DEN_EDGE_EN_MASK 0x80 +mems_status_t LSM6DSL_ACC_GYRO_W_ExternalTrigger(void *handle, LSM6DSL_ACC_GYRO_DEN_EDGE_EN_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_ExternalTrigger(void *handle, LSM6DSL_ACC_GYRO_DEN_EDGE_EN_t *value); + +/******************************************************************************* +* Register : CTRL7_G +* Address : 0X16 +* Bit Group Name: ROUNDING_STATUS +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_RND_DISABLE =0x00, + LSM6DSL_ACC_GYRO_RND_ENABLE =0x04, +} LSM6DSL_ACC_GYRO_RND_STATUS_t; + +#define LSM6DSL_ACC_GYRO_RND_STATUS_MASK 0x04 +mems_status_t LSM6DSL_ACC_GYRO_W_RoundingOnStatusRegisters(void *handle, LSM6DSL_ACC_GYRO_RND_STATUS_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_RoundingOnStatusRegisters(void *handle, LSM6DSL_ACC_GYRO_RND_STATUS_t *value); + + +/******************************************************************************* +* Register : CTRL7_G +* Address : 0X16 +* Bit Group Name: HPM_G +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_HPM_G_0Hz016 =0x00, + LSM6DSL_ACC_GYRO_HPM_G_0Hz065 =0x10, + LSM6DSL_ACC_GYRO_HPM_G_2Hz260 =0x20, + LSM6DSL_ACC_GYRO_HPM_G_1Hz04 =0x30, +} LSM6DSL_ACC_GYRO_HPM_G_t; + +#define LSM6DSL_ACC_GYRO_HPM_G_MASK 0x30 +mems_status_t LSM6DSL_ACC_GYRO_W_HPM_G(void *handle, LSM6DSL_ACC_GYRO_HPM_G_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_HPM_G(void *handle, LSM6DSL_ACC_GYRO_HPM_G_t *value); + +/******************************************************************************* +* Register : CTRL7_G +* Address : 0X16 +* Bit Group Name: HP_EN_G +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_HP_EN_DISABLED =0x00, + LSM6DSL_ACC_GYRO_HP_EN_ENABLED =0x40, +} LSM6DSL_ACC_GYRO_HP_EN_t; + +#define LSM6DSL_ACC_GYRO_HP_EN_MASK 0x40 +mems_status_t LSM6DSL_ACC_GYRO_W_HPFilter_En(void *handle, LSM6DSL_ACC_GYRO_HP_EN_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_HPFilter_En(void *handle, LSM6DSL_ACC_GYRO_HP_EN_t *value); + +/******************************************************************************* +* Register : CTRL7_G +* Address : 0X16 +* Bit Group Name: LP_EN +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_LP_EN_DISABLED =0x00, + LSM6DSL_ACC_GYRO_LP_EN_ENABLED =0x80, +} LSM6DSL_ACC_GYRO_LP_EN_t; + +#define LSM6DSL_ACC_GYRO_LP_EN_MASK 0x80 +mems_status_t LSM6DSL_ACC_GYRO_W_LP_Mode(void *handle, LSM6DSL_ACC_GYRO_LP_EN_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_LP_Mode(void *handle, LSM6DSL_ACC_GYRO_LP_EN_t *value); + +/******************************************************************************* +* Register : CTRL7_G +* Address : 0X16 +* Bit Group Name: ROUNDING_STATUS +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_ROUNDING_STATUS_DISABLED =0x00, + LSM6DSL_ACC_GYRO_ROUNDING_STATUS_ENABLED =0x04, +} LSM6DSL_ACC_GYRO_ROUNDING_STATUS_t; + +#define LSM6DSL_ACC_GYRO_ROUNDING_STATUS_MASK 0x04 +mems_status_t LSM6DSL_ACC_GYRO_W_ROUNDING_STATUS(void *handle, LSM6DSL_ACC_GYRO_ROUNDING_STATUS_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_ROUNDING_STATUS(void *handle, LSM6DSL_ACC_GYRO_ROUNDING_STATUS_t *value); + +/******************************************************************************* +* Register : CTRL7_G +* Address : 0X16 +* Bit Group Name: HP_G_RST +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_HP_G_RST_OFF =0x00, + LSM6DSL_ACC_GYRO_HP_G_RST_ON =0x08, +} LSM6DSL_ACC_GYRO_HP_G_RST_t; + +#define LSM6DSL_ACC_GYRO_HP_G_RST_MASK 0x08 +mems_status_t LSM6DSL_ACC_GYRO_W_HP_G_RST(void *handle, LSM6DSL_ACC_GYRO_HP_G_RST_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_HP_G_RST(void *handle, LSM6DSL_ACC_GYRO_HP_G_RST_t *value); + +/******************************************************************************* +* Register : CTRL8_XL +* Address : 0X17 +* Bit Group Name: LOW_PASS_ON_6D +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_LOW_PASS_ON_6D_OFF =0x00, + LSM6DSL_ACC_GYRO_LOW_PASS_ON_6D_ON =0x01, +} LSM6DSL_ACC_GYRO_LOW_PASS_ON_6D_t; + +#define LSM6DSL_ACC_GYRO_LOW_PASS_ON_6D_MASK 0x01 +mems_status_t LSM6DSL_ACC_GYRO_W_LOW_PASS_ON_6D(void *handle, LSM6DSL_ACC_GYRO_LOW_PASS_ON_6D_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_LOW_PASS_ON_6D(void *handle, LSM6DSL_ACC_GYRO_LOW_PASS_ON_6D_t *value); + +/******************************************************************************* +* Register : CTRL8_XL +* Address : 0X17 +* Bit Group Name: HP_SLOPE_XL_EN +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_HP_SLOPE_XL_EN =0x00, + LSM6DSL_ACC_GYRO_HP_SLOPE_XL_DIS =0x04, +} LSM6DSL_ACC_GYRO_HP_SLOPE_XL_t; + +#define LSM6DSL_ACC_GYRO_HP_SLOPE_XL_MASK 0x04 +mems_status_t LSM6DSL_ACC_GYRO_W_HP_SLOPE_XL(void *handle, LSM6DSL_ACC_GYRO_HP_SLOPE_XL_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_HP_SLOPE_XL(void *handle, LSM6DSL_ACC_GYRO_HP_SLOPE_XL_t *value); + +/******************************************************************************* +* Register : CTRL8_XL +* Address : 0X17 +* Bit Group Name: INPUT_COMPOSITE +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_IN_ODR_DIV_2 =0x00, + LSM6DSL_ACC_GYRO_IN_ODR_DIV_4 =0x80, +} LSM6DSL_ACC_GYRO_IN_COMP_t; + +#define LSM6DSL_ACC_GYRO_IN_COMP_MASK 0x80 +mems_status_t LSM6DSL_ACC_GYRO_W_InComposit(void *handle, LSM6DSL_ACC_GYRO_IN_COMP_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_InComposit(void *handle, LSM6DSL_ACC_GYRO_IN_COMP_t *value); + +/******************************************************************************* +* Register : CTRL8_XL +* Address : 0X17 +* Bit Group Name: HP_REF_MODE +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_HP_REF_DISABLE =0x00, + LSM6DSL_ACC_GYRO_HP_REF_ENABLE =0x10, +} LSM6DSL_ACC_GYRO_HP_REF_MODE_t; + +#define LSM6DSL_ACC_GYRO_HP_REF_MODE_MASK 0x10 +mems_status_t LSM6DSL_ACC_GYRO_W_HPfilterReference(void *handle, LSM6DSL_ACC_GYRO_HP_REF_MODE_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_HPfilterReference(void *handle, LSM6DSL_ACC_GYRO_HP_REF_MODE_t *value); + +/******************************************************************************* +* Register : CTRL8_XL +* Address : 0X17 +* Bit Group Name: HPCF_XL +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_HPCF_XL_DIV4 =0x00, + LSM6DSL_ACC_GYRO_HPCF_XL_DIV100 =0x20, + LSM6DSL_ACC_GYRO_HPCF_XL_DIV9 =0x40, + LSM6DSL_ACC_GYRO_HPCF_XL_DIV400 =0x60, +} LSM6DSL_ACC_GYRO_HPCF_XL_t; + +#define LSM6DSL_ACC_GYRO_HPCF_XL_MASK 0x60 +mems_status_t LSM6DSL_ACC_GYRO_W_HPCF_XL(void *handle, LSM6DSL_ACC_GYRO_HPCF_XL_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_HPCF_XL(void *handle, LSM6DSL_ACC_GYRO_HPCF_XL_t *value); + +/******************************************************************************* +* Register : CTRL8_XL +* Address : 0X17 +* Bit Group Name: LPF2_XL_EN +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_LPF2_XL_DISABLE =0x00, + LSM6DSL_ACC_GYRO_LPF2_XL_ENABLE =0x80, +} LSM6DSL_ACC_GYRO_LPF2_XL_t; + +#define LSM6DSL_ACC_GYRO_LPF2_XL_MASK 0x80 +mems_status_t LSM6DSL_ACC_GYRO_W_LowPassFiltSel_XL(void *handle, LSM6DSL_ACC_GYRO_LPF2_XL_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_LowPassFiltSel_XL(void *handle, LSM6DSL_ACC_GYRO_LPF2_XL_t *value); + + +/******************************************************************************* +* Register : CTRL9_XL +* Address : 0X18 +* Bit Group Name: SOFT_EN +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_SOFT_DISABLED =0x00, + LSM6DSL_ACC_GYRO_SOFT_ENABLE =0x04, +} LSM6DSL_ACC_GYRO_SOFT_t; + +#define LSM6DSL_ACC_GYRO_SOFT_MASK 0x04 +mems_status_t LSM6DSL_ACC_GYRO_W_SOFT(void *handle, LSM6DSL_ACC_GYRO_SOFT_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_SOFT(void *handle, LSM6DSL_ACC_GYRO_SOFT_t *value); + +/******************************************************************************* +* Register : CTRL10_C +* Address : 0X19 +* Bit Group Name: SIGN_MOTION_EN +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_SIGN_MOTION_EN_DISABLED =0x00, + LSM6DSL_ACC_GYRO_SIGN_MOTION_EN_ENABLED =0x01, +} LSM6DSL_ACC_GYRO_SIGN_MOTION_EN_t; + +#define LSM6DSL_ACC_GYRO_SIGN_MOTION_EN_MASK 0x01 +mems_status_t LSM6DSL_ACC_GYRO_W_SignifcantMotion(void *handle, LSM6DSL_ACC_GYRO_SIGN_MOTION_EN_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_SignifcantMotion(void *handle, LSM6DSL_ACC_GYRO_SIGN_MOTION_EN_t *value); + +/******************************************************************************* +* Register : CTRL10_C +* Address : 0X19 +* Bit Group Name: PEDO_RST_STEP +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_PEDO_RST_STEP_DISABLED =0x00, + LSM6DSL_ACC_GYRO_PEDO_RST_STEP_ENABLED =0x02, +} LSM6DSL_ACC_GYRO_PEDO_RST_STEP_t; + +#define LSM6DSL_ACC_GYRO_PEDO_RST_STEP_MASK 0x02 +mems_status_t LSM6DSL_ACC_GYRO_W_PedoStepReset(void *handle, LSM6DSL_ACC_GYRO_PEDO_RST_STEP_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_PedoStepReset(void *handle, LSM6DSL_ACC_GYRO_PEDO_RST_STEP_t *value); + +/******************************************************************************* +* Register : CTRL10_C +* Address : 0X19 +* Bit Group Name: FUNC_EN +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_FUNC_EN_DISABLED =0x00, + LSM6DSL_ACC_GYRO_FUNC_EN_ENABLED =0x04, +} LSM6DSL_ACC_GYRO_FUNC_EN_t; + +#define LSM6DSL_ACC_GYRO_FUNC_EN_MASK 0x04 +mems_status_t LSM6DSL_ACC_GYRO_W_FUNC_EN(void *handle, LSM6DSL_ACC_GYRO_FUNC_EN_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_FUNC_EN(void *handle, LSM6DSL_ACC_GYRO_FUNC_EN_t *value); + +/******************************************************************************* +* Register : CTRL10_C +* Address : 0X19 +* Bit Group Name: TILT_EN +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_TILT_DISABLED =0x00, + LSM6DSL_ACC_GYRO_TILT_ENABLED =0x08, +} LSM6DSL_ACC_GYRO_TILT_G_t; + +#define LSM6DSL_ACC_GYRO_TILT_MASK 0x08 +mems_status_t LSM6DSL_ACC_GYRO_W_TILT(void *handle, LSM6DSL_ACC_GYRO_TILT_G_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_TILT(void *handle, LSM6DSL_ACC_GYRO_TILT_G_t *value); + +/******************************************************************************* +* Register : CTRL10_C +* Address : 0X19 +* Bit Group Name: PEDO_EN +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_PEDO_DISABLED =0x00, + LSM6DSL_ACC_GYRO_PEDO_ENABLED =0x10, +} LSM6DSL_ACC_GYRO_PEDO_t; + +#define LSM6DSL_ACC_GYRO_PEDO_MASK 0x10 +mems_status_t LSM6DSL_ACC_GYRO_W_PEDO(void *handle, LSM6DSL_ACC_GYRO_PEDO_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_PEDO(void *handle, LSM6DSL_ACC_GYRO_PEDO_t *value); + +/******************************************************************************* +* Register : CTRL10_C +* Address : 0X19 +* Bit Group Name: TIMER_EN +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_TIMER_DISABLED =0x00, + LSM6DSL_ACC_GYRO_TIMER_ENABLED =0x20, +} LSM6DSL_ACC_GYRO_TIMER_t; + +#define LSM6DSL_ACC_GYRO_TIMER_MASK 0x20 +mems_status_t LSM6DSL_ACC_GYRO_W_TIMER(void *handle, LSM6DSL_ACC_GYRO_TIMER_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_TIMER(void *handle, LSM6DSL_ACC_GYRO_TIMER_t *value); + + +/******************************************************************************* +* Register : MASTER_CONFIG +* Address : 0X1A +* Bit Group Name: MASTER_ON +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_MASTER_ON_DISABLED =0x00, + LSM6DSL_ACC_GYRO_MASTER_ON_ENABLED =0x01, +} LSM6DSL_ACC_GYRO_MASTER_ON_t; + +#define LSM6DSL_ACC_GYRO_MASTER_ON_MASK 0x01 +mems_status_t LSM6DSL_ACC_GYRO_W_I2C_MASTER_Enable(void *handle, LSM6DSL_ACC_GYRO_MASTER_ON_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_I2C_MASTER_Enable(void *handle, LSM6DSL_ACC_GYRO_MASTER_ON_t *value); + +/******************************************************************************* +* Register : MASTER_CONFIG +* Address : 0X1A +* Bit Group Name: IRON_EN +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_IRON_EN_DISABLED =0x00, + LSM6DSL_ACC_GYRO_IRON_EN_ENABLED =0x02, +} LSM6DSL_ACC_GYRO_IRON_EN_t; + +#define LSM6DSL_ACC_GYRO_IRON_EN_MASK 0x02 +mems_status_t LSM6DSL_ACC_GYRO_W_IronCorrection_EN(void *handle, LSM6DSL_ACC_GYRO_IRON_EN_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_IronCorrection_EN(void *handle, LSM6DSL_ACC_GYRO_IRON_EN_t *value); + +/******************************************************************************* +* Register : MASTER_CONFIG +* Address : 0X1A +* Bit Group Name: PASS_THRU_MODE +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_PASS_THRU_MODE_DISABLED =0x00, + LSM6DSL_ACC_GYRO_PASS_THRU_MODE_ENABLED =0x04, +} LSM6DSL_ACC_GYRO_PASS_THRU_MODE_t; + +#define LSM6DSL_ACC_GYRO_PASS_THRU_MODE_MASK 0x04 +mems_status_t LSM6DSL_ACC_GYRO_W_PASS_THRU_MODE(void *handle, LSM6DSL_ACC_GYRO_PASS_THRU_MODE_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_PASS_THRU_MODE(void *handle, LSM6DSL_ACC_GYRO_PASS_THRU_MODE_t *value); + +/******************************************************************************* +* Register : MASTER_CONFIG +* Address : 0X1A +* Bit Group Name: PULL_UP_EN +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_PULL_UP_EN_DISABLED =0x00, + LSM6DSL_ACC_GYRO_PULL_UP_EN_ENABLED =0x08, +} LSM6DSL_ACC_GYRO_PULL_UP_EN_t; + +#define LSM6DSL_ACC_GYRO_PULL_UP_EN_MASK 0x08 +mems_status_t LSM6DSL_ACC_GYRO_W_PULL_UP_EN(void *handle, LSM6DSL_ACC_GYRO_PULL_UP_EN_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_PULL_UP_EN(void *handle, LSM6DSL_ACC_GYRO_PULL_UP_EN_t *value); + +/******************************************************************************* +* Register : MASTER_CONFIG +* Address : 0X1A +* Bit Group Name: START_CONFIG +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_START_CONFIG_XL_G_DRDY =0x00, + LSM6DSL_ACC_GYRO_START_CONFIG_EXT_INT2 =0x10, +} LSM6DSL_ACC_GYRO_START_CONFIG_t; + +#define LSM6DSL_ACC_GYRO_START_CONFIG_MASK 0x10 +mems_status_t LSM6DSL_ACC_GYRO_W_SensorHUB_Trigger_Sel(void *handle, LSM6DSL_ACC_GYRO_START_CONFIG_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_SensorHUB_Trigger_Sel(void *handle, LSM6DSL_ACC_GYRO_START_CONFIG_t *value); + +/******************************************************************************* +* Register : MASTER_CONFIG +* Address : 0X1A +* Bit Group Name: DATA_VAL_SEL_FIFO +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_DATA_VAL_SEL_FIFO_XL_G_DRDY =0x00, + LSM6DSL_ACC_GYRO_DATA_VAL_SEL_FIFO_SHUB_DRDY =0x40, +} LSM6DSL_ACC_GYRO_DATA_VAL_SEL_FIFO_t; + +#define LSM6DSL_ACC_GYRO_DATA_VAL_SEL_FIFO_MASK 0x40 +mems_status_t LSM6DSL_ACC_GYRO_W_DATA_VAL_SEL_FIFO(void *handle, LSM6DSL_ACC_GYRO_DATA_VAL_SEL_FIFO_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_DATA_VAL_SEL_FIFO(void *handle, LSM6DSL_ACC_GYRO_DATA_VAL_SEL_FIFO_t *value); + +/******************************************************************************* +* Register : MASTER_CONFIG +* Address : 0X1A +* Bit Group Name: DRDY_ON_INT1 +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_DRDY_ON_INT1_DISABLED =0x00, + LSM6DSL_ACC_GYRO_DRDY_ON_INT1_ENABLED =0x80, +} LSM6DSL_ACC_GYRO_DRDY_ON_INT1_t; + +#define LSM6DSL_ACC_GYRO_DRDY_ON_INT1_MASK 0x80 +mems_status_t LSM6DSL_ACC_GYRO_W_DRDY_ON_INT1(void *handle, LSM6DSL_ACC_GYRO_DRDY_ON_INT1_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_DRDY_ON_INT1(void *handle, LSM6DSL_ACC_GYRO_DRDY_ON_INT1_t *value); + +/******************************************************************************* +* Register : WAKE_UP_SRC +* Address : 0X1B +* Bit Group Name: Z_WU +* Permission : RO +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_Z_WU_NOT_DETECTED =0x00, + LSM6DSL_ACC_GYRO_Z_WU_DETECTED =0x01, +} LSM6DSL_ACC_GYRO_Z_WU_t; + +#define LSM6DSL_ACC_GYRO_Z_WU_MASK 0x01 +mems_status_t LSM6DSL_ACC_GYRO_R_Z_WU(void *handle, LSM6DSL_ACC_GYRO_Z_WU_t *value); + +/******************************************************************************* +* Register : WAKE_UP_SRC +* Address : 0X1B +* Bit Group Name: Y_WU +* Permission : RO +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_Y_WU_NOT_DETECTED =0x00, + LSM6DSL_ACC_GYRO_Y_WU_DETECTED =0x02, +} LSM6DSL_ACC_GYRO_Y_WU_t; + +#define LSM6DSL_ACC_GYRO_Y_WU_MASK 0x02 +mems_status_t LSM6DSL_ACC_GYRO_R_Y_WU(void *handle, LSM6DSL_ACC_GYRO_Y_WU_t *value); + +/******************************************************************************* +* Register : WAKE_UP_SRC +* Address : 0X1B +* Bit Group Name: X_WU +* Permission : RO +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_X_WU_NOT_DETECTED =0x00, + LSM6DSL_ACC_GYRO_X_WU_DETECTED =0x04, +} LSM6DSL_ACC_GYRO_X_WU_t; + +#define LSM6DSL_ACC_GYRO_X_WU_MASK 0x04 +mems_status_t LSM6DSL_ACC_GYRO_R_X_WU(void *handle, LSM6DSL_ACC_GYRO_X_WU_t *value); + +/******************************************************************************* +* Register : WAKE_UP_SRC +* Address : 0X1B +* Bit Group Name: WU_EV_STATUS +* Permission : RO +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_WU_EV_STATUS_NOT_DETECTED =0x00, + LSM6DSL_ACC_GYRO_WU_EV_STATUS_DETECTED =0x08, +} LSM6DSL_ACC_GYRO_WU_EV_STATUS_t; + +#define LSM6DSL_ACC_GYRO_WU_EV_STATUS_MASK 0x08 +mems_status_t LSM6DSL_ACC_GYRO_R_WU_EV_STATUS(void *handle, LSM6DSL_ACC_GYRO_WU_EV_STATUS_t *value); + +/******************************************************************************* +* Register : WAKE_UP_SRC +* Address : 0X1B +* Bit Group Name: SLEEP_EV_STATUS +* Permission : RO +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_SLEEP_EV_STATUS_NOT_DETECTED =0x00, + LSM6DSL_ACC_GYRO_SLEEP_EV_STATUS_DETECTED =0x10, +} LSM6DSL_ACC_GYRO_SLEEP_EV_STATUS_t; + +#define LSM6DSL_ACC_GYRO_SLEEP_EV_STATUS_MASK 0x10 +mems_status_t LSM6DSL_ACC_GYRO_R_SLEEP_EV_STATUS(void *handle, LSM6DSL_ACC_GYRO_SLEEP_EV_STATUS_t *value); + +/******************************************************************************* +* Register : WAKE_UP_SRC +* Address : 0X1B +* Bit Group Name: FF_EV_STATUS +* Permission : RO +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_FF_EV_STATUS_NOT_DETECTED =0x00, + LSM6DSL_ACC_GYRO_FF_EV_STATUS_DETECTED =0x20, +} LSM6DSL_ACC_GYRO_FF_EV_STATUS_t; + +#define LSM6DSL_ACC_GYRO_FF_EV_STATUS_MASK 0x20 +mems_status_t LSM6DSL_ACC_GYRO_R_FF_EV_STATUS(void *handle, LSM6DSL_ACC_GYRO_FF_EV_STATUS_t *value); + +/******************************************************************************* +* Register : TAP_SRC +* Address : 0X1C +* Bit Group Name: Z_TAP +* Permission : RO +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_Z_TAP_NOT_DETECTED =0x00, + LSM6DSL_ACC_GYRO_Z_TAP_DETECTED =0x01, +} LSM6DSL_ACC_GYRO_Z_TAP_t; + +#define LSM6DSL_ACC_GYRO_Z_TAP_MASK 0x01 +mems_status_t LSM6DSL_ACC_GYRO_R_Z_TAP(void *handle, LSM6DSL_ACC_GYRO_Z_TAP_t *value); + +/******************************************************************************* +* Register : TAP_SRC +* Address : 0X1C +* Bit Group Name: Y_TAP +* Permission : RO +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_Y_TAP_NOT_DETECTED =0x00, + LSM6DSL_ACC_GYRO_Y_TAP_DETECTED =0x02, +} LSM6DSL_ACC_GYRO_Y_TAP_t; + +#define LSM6DSL_ACC_GYRO_Y_TAP_MASK 0x02 +mems_status_t LSM6DSL_ACC_GYRO_R_Y_TAP(void *handle, LSM6DSL_ACC_GYRO_Y_TAP_t *value); + +/******************************************************************************* +* Register : TAP_SRC +* Address : 0X1C +* Bit Group Name: X_TAP +* Permission : RO +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_X_TAP_NOT_DETECTED =0x00, + LSM6DSL_ACC_GYRO_X_TAP_DETECTED =0x04, +} LSM6DSL_ACC_GYRO_X_TAP_t; + +#define LSM6DSL_ACC_GYRO_X_TAP_MASK 0x04 +mems_status_t LSM6DSL_ACC_GYRO_R_X_TAP(void *handle, LSM6DSL_ACC_GYRO_X_TAP_t *value); + +/******************************************************************************* +* Register : TAP_SRC +* Address : 0X1C +* Bit Group Name: TAP_SIGN +* Permission : RO +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_TAP_SIGN_POS_SIGN =0x00, + LSM6DSL_ACC_GYRO_TAP_SIGN_NEG_SIGN =0x08, +} LSM6DSL_ACC_GYRO_TAP_SIGN_t; + +#define LSM6DSL_ACC_GYRO_TAP_SIGN_MASK 0x08 +mems_status_t LSM6DSL_ACC_GYRO_R_TAP_SIGN(void *handle, LSM6DSL_ACC_GYRO_TAP_SIGN_t *value); + +/******************************************************************************* +* Register : TAP_SRC +* Address : 0X1C +* Bit Group Name: DOUBLE_TAP_EV_STATUS +* Permission : RO +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_DOUBLE_TAP_EV_STATUS_NOT_DETECTED =0x00, + LSM6DSL_ACC_GYRO_DOUBLE_TAP_EV_STATUS_DETECTED =0x10, +} LSM6DSL_ACC_GYRO_DOUBLE_TAP_EV_STATUS_t; + +#define LSM6DSL_ACC_GYRO_DOUBLE_TAP_EV_STATUS_MASK 0x10 +mems_status_t LSM6DSL_ACC_GYRO_R_DOUBLE_TAP_EV_STATUS(void *handle, LSM6DSL_ACC_GYRO_DOUBLE_TAP_EV_STATUS_t *value); + +/******************************************************************************* +* Register : TAP_SRC +* Address : 0X1C +* Bit Group Name: SINGLE_TAP_EV_STATUS +* Permission : RO +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_SINGLE_TAP_EV_STATUS_NOT_DETECTED =0x00, + LSM6DSL_ACC_GYRO_SINGLE_TAP_EV_STATUS_DETECTED =0x20, +} LSM6DSL_ACC_GYRO_SINGLE_TAP_EV_STATUS_t; + +#define LSM6DSL_ACC_GYRO_SINGLE_TAP_EV_STATUS_MASK 0x20 +mems_status_t LSM6DSL_ACC_GYRO_R_SINGLE_TAP_EV_STATUS(void *handle, LSM6DSL_ACC_GYRO_SINGLE_TAP_EV_STATUS_t *value); + +/******************************************************************************* +* Register : TAP_SRC +* Address : 0X1C +* Bit Group Name: TAP_EV_STATUS +* Permission : RO +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_TAP_EV_STATUS_NOT_DETECTED =0x00, + LSM6DSL_ACC_GYRO_TAP_EV_STATUS_DETECTED =0x40, +} LSM6DSL_ACC_GYRO_TAP_EV_STATUS_t; + +#define LSM6DSL_ACC_GYRO_TAP_EV_STATUS_MASK 0x40 +mems_status_t LSM6DSL_ACC_GYRO_R_TAP_EV_STATUS(void *handle, LSM6DSL_ACC_GYRO_TAP_EV_STATUS_t *value); + +/******************************************************************************* +* Register : D6D_SRC +* Address : 0X1D +* Bit Group Name: DSD_XL +* Permission : RO +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_DSD_XL_NOT_DETECTED =0x00, + LSM6DSL_ACC_GYRO_DSD_XL_DETECTED =0x01, +} LSM6DSL_ACC_GYRO_DSD_XL_t; + +#define LSM6DSL_ACC_GYRO_DSD_XL_MASK 0x01 +mems_status_t LSM6DSL_ACC_GYRO_R_DSD_XL(void *handle, LSM6DSL_ACC_GYRO_DSD_XL_t *value); + +/******************************************************************************* +* Register : D6D_SRC +* Address : 0X1D +* Bit Group Name: DSD_XH +* Permission : RO +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_DSD_XH_NOT_DETECTED =0x00, + LSM6DSL_ACC_GYRO_DSD_XH_DETECTED =0x02, +} LSM6DSL_ACC_GYRO_DSD_XH_t; + +#define LSM6DSL_ACC_GYRO_DSD_XH_MASK 0x02 +mems_status_t LSM6DSL_ACC_GYRO_R_DSD_XH(void *handle, LSM6DSL_ACC_GYRO_DSD_XH_t *value); + +/******************************************************************************* +* Register : D6D_SRC +* Address : 0X1D +* Bit Group Name: DSD_YL +* Permission : RO +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_DSD_YL_NOT_DETECTED =0x00, + LSM6DSL_ACC_GYRO_DSD_YL_DETECTED =0x04, +} LSM6DSL_ACC_GYRO_DSD_YL_t; + +#define LSM6DSL_ACC_GYRO_DSD_YL_MASK 0x04 +mems_status_t LSM6DSL_ACC_GYRO_R_DSD_YL(void *handle, LSM6DSL_ACC_GYRO_DSD_YL_t *value); + +/******************************************************************************* +* Register : D6D_SRC +* Address : 0X1D +* Bit Group Name: DSD_YH +* Permission : RO +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_DSD_YH_NOT_DETECTED =0x00, + LSM6DSL_ACC_GYRO_DSD_YH_DETECTED =0x08, +} LSM6DSL_ACC_GYRO_DSD_YH_t; + +#define LSM6DSL_ACC_GYRO_DSD_YH_MASK 0x08 +mems_status_t LSM6DSL_ACC_GYRO_R_DSD_YH(void *handle, LSM6DSL_ACC_GYRO_DSD_YH_t *value); + +/******************************************************************************* +* Register : D6D_SRC +* Address : 0X1D +* Bit Group Name: DSD_ZL +* Permission : RO +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_DSD_ZL_NOT_DETECTED =0x00, + LSM6DSL_ACC_GYRO_DSD_ZL_DETECTED =0x10, +} LSM6DSL_ACC_GYRO_DSD_ZL_t; + +#define LSM6DSL_ACC_GYRO_DSD_ZL_MASK 0x10 +mems_status_t LSM6DSL_ACC_GYRO_R_DSD_ZL(void *handle, LSM6DSL_ACC_GYRO_DSD_ZL_t *value); + +/******************************************************************************* +* Register : D6D_SRC +* Address : 0X1D +* Bit Group Name: DSD_ZH +* Permission : RO +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_DSD_ZH_NOT_DETECTED =0x00, + LSM6DSL_ACC_GYRO_DSD_ZH_DETECTED =0x20, +} LSM6DSL_ACC_GYRO_DSD_ZH_t; + +#define LSM6DSL_ACC_GYRO_DSD_ZH_MASK 0x20 +mems_status_t LSM6DSL_ACC_GYRO_R_DSD_ZH(void *handle, LSM6DSL_ACC_GYRO_DSD_ZH_t *value); + +/******************************************************************************* +* Register : D6D_SRC +* Address : 0X1D +* Bit Group Name: D6D_EV_STATUS +* Permission : RO +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_D6D_EV_STATUS_NOT_DETECTED =0x00, + LSM6DSL_ACC_GYRO_D6D_EV_STATUS_DETECTED =0x40, +} LSM6DSL_ACC_GYRO_D6D_EV_STATUS_t; + +#define LSM6DSL_ACC_GYRO_D6D_EV_STATUS_MASK 0x40 +mems_status_t LSM6DSL_ACC_GYRO_R_D6D_EV_STATUS(void *handle, LSM6DSL_ACC_GYRO_D6D_EV_STATUS_t *value); + +/******************************************************************************* +* Register : STATUS_REG +* Address : 0X1E +* Bit Group Name: XLDA +* Permission : RO +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_XLDA_NO_DATA_AVAIL =0x00, + LSM6DSL_ACC_GYRO_XLDA_DATA_AVAIL =0x01, +} LSM6DSL_ACC_GYRO_XLDA_t; + +#define LSM6DSL_ACC_GYRO_XLDA_MASK 0x01 +mems_status_t LSM6DSL_ACC_GYRO_R_XLDA(void *handle, LSM6DSL_ACC_GYRO_XLDA_t *value); + +/******************************************************************************* +* Register : STATUS_REG +* Address : 0X1E +* Bit Group Name: GDA +* Permission : RO +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_GDA_NO_DATA_AVAIL =0x00, + LSM6DSL_ACC_GYRO_GDA_DATA_AVAIL =0x02, +} LSM6DSL_ACC_GYRO_GDA_t; + +#define LSM6DSL_ACC_GYRO_GDA_MASK 0x02 +mems_status_t LSM6DSL_ACC_GYRO_R_GDA(void *handle, LSM6DSL_ACC_GYRO_GDA_t *value); + +/******************************************************************************* +* Register : STATUS_REG +* Address : 0X1E +* Bit Group Name: TDA +* Permission : RO +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_TDA_NO_DATA_AVAIL =0x00, + LSM6DSL_ACC_GYRO_TDA_DATA_AVAIL =0x04, +} LSM6DSL_ACC_GYRO_TDA_t; + +#define LSM6DSL_ACC_GYRO_TDA_MASK 0x04 +mems_status_t LSM6DSL_ACC_GYRO_R_TDA(void *handle, LSM6DSL_ACC_GYRO_TDA_t *value); + +/******************************************************************************* +* Register : FIFO_STATUS1 +* Address : 0X3A +* Bit Group Name: DIFF_FIFO +* Permission : RO +*******************************************************************************/ +#define LSM6DSL_ACC_GYRO_DIFF_FIFO_STATUS1_MASK 0xFF +#define LSM6DSL_ACC_GYRO_DIFF_FIFO_STATUS1_POSITION 0 +#define LSM6DSL_ACC_GYRO_DIFF_FIFO_STATUS2_MASK 0xF +#define LSM6DSL_ACC_GYRO_DIFF_FIFO_STATUS2_POSITION 0 +mems_status_t LSM6DSL_ACC_GYRO_R_FIFONumOfEntries(void *handle, u16_t *value); + +/******************************************************************************* +* Register : FIFO_STATUS2 +* Address : 0X3B +* Bit Group Name: FIFO_EMPTY +* Permission : RO +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_FIFO_EMPTY_FIFO_NOT_EMPTY =0x00, + LSM6DSL_ACC_GYRO_FIFO_EMPTY_FIFO_EMPTY =0x10, +} LSM6DSL_ACC_GYRO_FIFO_EMPTY_t; + +#define LSM6DSL_ACC_GYRO_FIFO_EMPTY_MASK 0x10 +mems_status_t LSM6DSL_ACC_GYRO_R_FIFOEmpty(void *handle, LSM6DSL_ACC_GYRO_FIFO_EMPTY_t *value); + +/******************************************************************************* +* Register : FIFO_STATUS2 +* Address : 0X3B +* Bit Group Name: FIFO_FULL +* Permission : RO +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_FIFO_FULL_FIFO_NOT_FULL =0x00, + LSM6DSL_ACC_GYRO_FIFO_FULL_FIFO_FULL =0x20, +} LSM6DSL_ACC_GYRO_FIFO_FULL_t; + +#define LSM6DSL_ACC_GYRO_FIFO_FULL_MASK 0x20 +mems_status_t LSM6DSL_ACC_GYRO_R_FIFOFull(void *handle, LSM6DSL_ACC_GYRO_FIFO_FULL_t *value); + +/******************************************************************************* +* Register : FIFO_STATUS2 +* Address : 0X3B +* Bit Group Name: OVERRUN +* Permission : RO +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_OVERRUN_NO_OVERRUN =0x00, + LSM6DSL_ACC_GYRO_OVERRUN_OVERRUN =0x40, +} LSM6DSL_ACC_GYRO_OVERRUN_t; + +#define LSM6DSL_ACC_GYRO_OVERRUN_MASK 0x40 +mems_status_t LSM6DSL_ACC_GYRO_R_OVERRUN(void *handle, LSM6DSL_ACC_GYRO_OVERRUN_t *value); + +/******************************************************************************* +* Register : FIFO_STATUS2 +* Address : 0X3B +* Bit Group Name: WTM +* Permission : RO +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_WTM_BELOW_WTM =0x00, + LSM6DSL_ACC_GYRO_WTM_ABOVE_OR_EQUAL_WTM =0x80, +} LSM6DSL_ACC_GYRO_WTM_t; + +#define LSM6DSL_ACC_GYRO_WTM_MASK 0x80 +mems_status_t LSM6DSL_ACC_GYRO_R_WaterMark(void *handle, LSM6DSL_ACC_GYRO_WTM_t *value); + +/******************************************************************************* +* Register : FIFO_STATUS3 +* Address : 0X3C +* Bit Group Name: FIFO_PATTERN +* Permission : RO +*******************************************************************************/ +#define LSM6DSL_ACC_GYRO_FIFO_STATUS3_PATTERN_MASK 0xFF +#define LSM6DSL_ACC_GYRO_FIFO_STATUS3_PATTERN_POSITION 0 +#define LSM6DSL_ACC_GYRO_FIFO_STATUS4_PATTERN_MASK 0x03 +#define LSM6DSL_ACC_GYRO_FIFO_STATUS4_PATTERN_POSITION 0 +mems_status_t LSM6DSL_ACC_GYRO_R_FIFOPattern(void *handle, u16_t *value); + +/******************************************************************************* +* Register : FUNC_SRC +* Address : 0X53 +* Bit Group Name: SENS_HUB_END +* Permission : RO +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_SENS_HUB_END_STILL_ONGOING =0x00, + LSM6DSL_ACC_GYRO_SENS_HUB_END_OP_COMPLETED =0x01, +} LSM6DSL_ACC_GYRO_SENS_HUB_END_t; + +#define LSM6DSL_ACC_GYRO_SENS_HUB_END_MASK 0x01 +mems_status_t LSM6DSL_ACC_GYRO_R_SENS_HUB_END(void *handle, LSM6DSL_ACC_GYRO_SENS_HUB_END_t *value); + +/******************************************************************************* +* Register : FUNC_SRC +* Address : 0X53 +* Bit Group Name: SOFT_IRON_END +* Permission : RO +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_SOFT_IRON_END_NOT_COMPLETED =0x00, + LSM6DSL_ACC_GYRO_SOFT_IRON_END_COMPLETED =0x02, +} LSM6DSL_ACC_GYRO_SOFT_IRON_END_t; + +#define LSM6DSL_ACC_GYRO_SOFT_IRON_END_MASK 0x02 +mems_status_t LSM6DSL_ACC_GYRO_R_SOFT_IRON_END(void *handle, LSM6DSL_ACC_GYRO_SOFT_IRON_END_t *value); + +/******************************************************************************* +* Register : FUNC_SRC +* Address : 0X53 +* Bit Group Name: HI_FAIL +* Permission : RO +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_HARD_IRON_NORMAL =0x00, + LSM6DSL_ACC_GYRO_HARD_IRON_FAIL =0x04, +} LSM6DSL_ACC_GYRO_SOFT_HARD_IRON_STAT_t; + +#define LSM6DSL_ACC_GYRO_HARD_IRON_STAT_MASK 0x04 +mems_status_t LSM6DSL_ACC_GYRO_R_HardIron(void *handle, LSM6DSL_ACC_GYRO_SOFT_HARD_IRON_STAT_t *value); + +/******************************************************************************* +* Register : FUNC_SRC +* Address : 0X53 +* Bit Group Name: STEP_OVERFLOW +* Permission : RO +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_PEDO_STEP_IN_RANGE =0x00, + LSM6DSL_ACC_GYRO_PEDO_ESTEP_OVERFLOW =0x08, +} LSM6DSL_ACC_GYRO_STEP_OVERFLOW_t; + +#define LSM6DSL_ACC_GYRO_STEP_OVERFLOW_MASK 0x08 +mems_status_t LSM6DSL_ACC_GYRO_R_STEP_OVERFLOW(void *handle, LSM6DSL_ACC_GYRO_STEP_OVERFLOW_t *value); + +/******************************************************************************* +* Register : FUNC_SRC +* Address : 0X53 +* Bit Group Name: PEDO_EV_STATUS +* Permission : RO +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_PEDO_EV_STATUS_NOT_DETECTED =0x00, + LSM6DSL_ACC_GYRO_PEDO_EV_STATUS_DETECTED =0x10, +} LSM6DSL_ACC_GYRO_PEDO_EV_STATUS_t; + +#define LSM6DSL_ACC_GYRO_PEDO_EV_STATUS_MASK 0x10 +mems_status_t LSM6DSL_ACC_GYRO_R_PEDO_EV_STATUS(void *handle, LSM6DSL_ACC_GYRO_PEDO_EV_STATUS_t *value); + +/******************************************************************************* +* Register : FUNC_SRC +* Address : 0X53 +* Bit Group Name: TILT_EV_STATUS +* Permission : RO +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_TILT_EV_STATUS_NOT_DETECTED =0x00, + LSM6DSL_ACC_GYRO_TILT_EV_STATUS_DETECTED =0x20, +} LSM6DSL_ACC_GYRO_TILT_EV_STATUS_t; + +#define LSM6DSL_ACC_GYRO_TILT_EV_STATUS_MASK 0x20 +mems_status_t LSM6DSL_ACC_GYRO_R_TILT_EV_STATUS(void *handle, LSM6DSL_ACC_GYRO_TILT_EV_STATUS_t *value); + +/******************************************************************************* +* Register : FUNC_SRC +* Address : 0X53 +* Bit Group Name: SIGN_MOT_EV_STATUS +* Permission : RO +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_SIGN_MOT_EV_STATUS_NOT_DETECTED =0x00, + LSM6DSL_ACC_GYRO_SIGN_MOT_EV_STATUS_DETECTED =0x40, +} LSM6DSL_ACC_GYRO_SIGN_MOT_EV_STATUS_t; + +#define LSM6DSL_ACC_GYRO_SIGN_MOT_EV_STATUS_MASK 0x40 +mems_status_t LSM6DSL_ACC_GYRO_R_SIGN_MOT_EV_STATUS(void *handle, LSM6DSL_ACC_GYRO_SIGN_MOT_EV_STATUS_t *value); + +/******************************************************************************* +* Register : FUNC_SRC +* Address : 0X53 +* Bit Group Name: STEP_COUNT_DELTA_IA +* Permission : RO +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_NO_STEP_COUNT_IN_DELTA =0x00, + LSM6DSL_ACC_GYRO_STEP_COUNT_IN_DELTA =0x80, +} LSM6DSL_ACC_GYRO_STEP_COUNT_DELTA_t; + +#define LSM6DSL_ACC_GYRO_STEP_COUNT_DELTA_MASK 0x80 +mems_status_t LSM6DSL_ACC_GYRO_R_STEP_COUNT_DELTA(void *handle, LSM6DSL_ACC_GYRO_STEP_COUNT_DELTA_t *value); + +/******************************************************************************* +* Register : TAP_CFG1 +* Address : 0X58 +* Bit Group Name: LIR +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_LIR_DISABLED =0x00, + LSM6DSL_ACC_GYRO_LIR_ENABLED =0x01, +} LSM6DSL_ACC_GYRO_LIR_t; + +#define LSM6DSL_ACC_GYRO_LIR_MASK 0x01 +mems_status_t LSM6DSL_ACC_GYRO_W_LIR(void *handle, LSM6DSL_ACC_GYRO_LIR_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_LIR(void *handle, LSM6DSL_ACC_GYRO_LIR_t *value); + +/******************************************************************************* +* Register : TAP_CFG1 +* Address : 0X58 +* Bit Group Name: TAP_Z_EN +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_TAP_Z_EN_DISABLED =0x00, + LSM6DSL_ACC_GYRO_TAP_Z_EN_ENABLED =0x02, +} LSM6DSL_ACC_GYRO_TAP_Z_EN_t; + +#define LSM6DSL_ACC_GYRO_TAP_Z_EN_MASK 0x02 +mems_status_t LSM6DSL_ACC_GYRO_W_TAP_Z_EN(void *handle, LSM6DSL_ACC_GYRO_TAP_Z_EN_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_TAP_Z_EN(void *handle, LSM6DSL_ACC_GYRO_TAP_Z_EN_t *value); + +/******************************************************************************* +* Register : TAP_CFG1 +* Address : 0X58 +* Bit Group Name: TAP_Y_EN +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_TAP_Y_EN_DISABLED =0x00, + LSM6DSL_ACC_GYRO_TAP_Y_EN_ENABLED =0x04, +} LSM6DSL_ACC_GYRO_TAP_Y_EN_t; + +#define LSM6DSL_ACC_GYRO_TAP_Y_EN_MASK 0x04 +mems_status_t LSM6DSL_ACC_GYRO_W_TAP_Y_EN(void *handle, LSM6DSL_ACC_GYRO_TAP_Y_EN_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_TAP_Y_EN(void *handle, LSM6DSL_ACC_GYRO_TAP_Y_EN_t *value); + +/******************************************************************************* +* Register : TAP_CFG1 +* Address : 0X58 +* Bit Group Name: TAP_X_EN +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_TAP_X_EN_DISABLED =0x00, + LSM6DSL_ACC_GYRO_TAP_X_EN_ENABLED =0x08, +} LSM6DSL_ACC_GYRO_TAP_X_EN_t; + +#define LSM6DSL_ACC_GYRO_TAP_X_EN_MASK 0x08 +mems_status_t LSM6DSL_ACC_GYRO_W_TAP_X_EN(void *handle, LSM6DSL_ACC_GYRO_TAP_X_EN_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_TAP_X_EN(void *handle, LSM6DSL_ACC_GYRO_TAP_X_EN_t *value); +/******************************************************************************* +* Register : TAP_CFG1 +* Address : 0X58 +* Bit Group Name: SLOPE_FDS +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_SLOPE_FDS_DISABLED =0x00, + LSM6DSL_ACC_GYRO_SLOPE_FDS_ENABLED =0x10, +} LSM6DSL_ACC_GYRO_SLOPE_FDS_t; + +#define LSM6DSL_ACC_GYRO_SLOPE_FDS_MASK 0x10 +mems_status_t LSM6DSL_ACC_GYRO_W_SLOPE_FDS(void *handle, LSM6DSL_ACC_GYRO_SLOPE_FDS_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_SLOPE_FDS(void *handle, LSM6DSL_ACC_GYRO_SLOPE_FDS_t *value); + +/******************************************************************************* +* Register : TAP_CFG1 +* Address : 0X58 +* Bit Group Name: INTERRUPTS_ENABLE +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_BASIC_INT_DISABLED =0x00, + LSM6DSL_ACC_GYRO_BASIC_INT_ENABLED =0x80, +} LSM6DSL_ACC_GYRO_INT_EN_t; + +#define LSM6DSL_ACC_GYRO_INT_EN_MASK 0x80 +mems_status_t LSM6DSL_ACC_GYRO_W_BASIC_INT(void *handle, LSM6DSL_ACC_GYRO_INT_EN_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_BASIC_INT(void *handle, LSM6DSL_ACC_GYRO_INT_EN_t *value); + +/******************************************************************************* +* Register : TAP_THS_6D +* Address : 0X59 +* Bit Group Name: TAP_THS +* Permission : RW +*******************************************************************************/ +#define LSM6DSL_ACC_GYRO_TAP_THS_MASK 0x1F +#define LSM6DSL_ACC_GYRO_TAP_THS_POSITION 0 +mems_status_t LSM6DSL_ACC_GYRO_W_TAP_THS(void *handle, u8_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_TAP_THS(void *handle, u8_t *value); + +/******************************************************************************* +* Register : TAP_THS_6D +* Address : 0X59 +* Bit Group Name: SIXD_THS +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_SIXD_THS_80_degree =0x00, + LSM6DSL_ACC_GYRO_SIXD_THS_70_degree =0x20, + LSM6DSL_ACC_GYRO_SIXD_THS_60_degree =0x40, + LSM6DSL_ACC_GYRO_SIXD_THS_50_degree =0x60, +} LSM6DSL_ACC_GYRO_SIXD_THS_t; + +#define LSM6DSL_ACC_GYRO_SIXD_THS_MASK 0x60 +mems_status_t LSM6DSL_ACC_GYRO_W_SIXD_THS(void *handle, LSM6DSL_ACC_GYRO_SIXD_THS_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_SIXD_THS(void *handle, LSM6DSL_ACC_GYRO_SIXD_THS_t *value); + +/******************************************************************************* +* Register : TAP_THS_6D +* Address : 0X59 +* Bit Group Name: D4D_EN +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_D4D_DIS =0x00, + LSM6DSL_ACC_GYRO_D4D_EN =0x80, +} LSM6DSL_ACC_GYRO_D4D_t; + +#define LSM6DSL_ACC_GYRO_D4D_MASK 0x80 +mems_status_t LSM6DSL_ACC_GYRO_W_D4D(void *handle, LSM6DSL_ACC_GYRO_D4D_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_D4D(void *handle, LSM6DSL_ACC_GYRO_D4D_t *value); + +/******************************************************************************* +* Register : INT_DUR2 +* Address : 0X5A +* Bit Group Name: SHOCK +* Permission : RW +*******************************************************************************/ +#define LSM6DSL_ACC_GYRO_SHOCK_MASK 0x03 +#define LSM6DSL_ACC_GYRO_SHOCK_POSITION 0 +mems_status_t LSM6DSL_ACC_GYRO_W_SHOCK_Duration(void *handle, u8_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_SHOCK_Duration(void *handle, u8_t *value); + +/******************************************************************************* +* Register : INT_DUR2 +* Address : 0X5A +* Bit Group Name: QUIET +* Permission : RW +*******************************************************************************/ +#define LSM6DSL_ACC_GYRO_QUIET_MASK 0x0C +#define LSM6DSL_ACC_GYRO_QUIET_POSITION 2 +mems_status_t LSM6DSL_ACC_GYRO_W_QUIET_Duration(void *handle, u8_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_QUIET_Duration(void *handle, u8_t *value); + +/******************************************************************************* +* Register : INT_DUR2 +* Address : 0X5A +* Bit Group Name: DUR +* Permission : RW +*******************************************************************************/ +#define LSM6DSL_ACC_GYRO_DUR_MASK 0xF0 +#define LSM6DSL_ACC_GYRO_DUR_POSITION 4 +mems_status_t LSM6DSL_ACC_GYRO_W_DUR(void *handle, u8_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_DUR(void *handle, u8_t *value); + +/******************************************************************************* +* Register : WAKE_UP_THS +* Address : 0X5B +* Bit Group Name: WK_THS +* Permission : RW +*******************************************************************************/ +#define LSM6DSL_ACC_GYRO_WK_THS_MASK 0x3F +#define LSM6DSL_ACC_GYRO_WK_THS_POSITION 0 +mems_status_t LSM6DSL_ACC_GYRO_W_WK_THS(void *handle, u8_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_WK_THS(void *handle, u8_t *value); + +/******************************************************************************* +* Register : WAKE_UP_THS +* Address : 0X5B +* Bit Group Name: SINGLE_DOUBLE_TAP +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_SINGLE_DOUBLE_TAP_SINGLE_TAP =0x00, + LSM6DSL_ACC_GYRO_SINGLE_DOUBLE_TAP_DOUBLE_TAP =0x80, +} LSM6DSL_ACC_GYRO_SINGLE_DOUBLE_TAP_t; + +#define LSM6DSL_ACC_GYRO_SINGLE_DOUBLE_TAP_MASK 0x80 +mems_status_t LSM6DSL_ACC_GYRO_W_SINGLE_DOUBLE_TAP_EV(void *handle, LSM6DSL_ACC_GYRO_SINGLE_DOUBLE_TAP_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_SINGLE_DOUBLE_TAP_EV(void *handle, LSM6DSL_ACC_GYRO_SINGLE_DOUBLE_TAP_t *value); + +/******************************************************************************* +* Register : WAKE_UP_DUR +* Address : 0X5C +* Bit Group Name: SLEEP_DUR +* Permission : RW +*******************************************************************************/ +#define LSM6DSL_ACC_GYRO_SLEEP_DUR_MASK 0x0F +#define LSM6DSL_ACC_GYRO_SLEEP_DUR_POSITION 0 +mems_status_t LSM6DSL_ACC_GYRO_W_SLEEP_DUR(void *handle, u8_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_SLEEP_DUR(void *handle, u8_t *value); + +/******************************************************************************* +* Register : WAKE_UP_DUR +* Address : 0X5C +* Bit Group Name: TIMER_HR +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_TIMER_HR_6_4ms =0x00, + LSM6DSL_ACC_GYRO_TIMER_HR_25us =0x10, +} LSM6DSL_ACC_GYRO_TIMER_HR_t; + +#define LSM6DSL_ACC_GYRO_TIMER_HR_MASK 0x10 +mems_status_t LSM6DSL_ACC_GYRO_W_TIMER_HR(void *handle, LSM6DSL_ACC_GYRO_TIMER_HR_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_TIMER_HR(void *handle, LSM6DSL_ACC_GYRO_TIMER_HR_t *value); + +/******************************************************************************* +* Register : WAKE_UP_DUR +* Address : 0X5C +* Bit Group Name: WAKE_DUR +* Permission : RW +*******************************************************************************/ +#define LSM6DSL_ACC_GYRO_WAKE_DUR_MASK 0x60 +#define LSM6DSL_ACC_GYRO_WAKE_DUR_POSITION 5 +mems_status_t LSM6DSL_ACC_GYRO_W_WAKE_DUR(void *handle, u8_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_WAKE_DUR(void *handle, u8_t *value); + +/******************************************************************************* +* Register : FREE_FALL +* Address : 0X5D +* Bit Group Name: FF_DUR +* Permission : RW +*******************************************************************************/ +#define LSM6DSL_ACC_GYRO_FF_FREE_FALL_DUR_MASK 0xF8 +#define LSM6DSL_ACC_GYRO_FF_FREE_FALL_DUR_POSITION 3 +#define LSM6DSL_ACC_GYRO_FF_WAKE_UP_DUR_MASK 0x80 +#define LSM6DSL_ACC_GYRO_FF_WAKE_UP_DUR_POSITION 7 +mems_status_t LSM6DSL_ACC_GYRO_W_FF_Duration(void *handle, u8_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_FF_Duration(void *handle, u8_t *value); + + +/******************************************************************************* +* Register : FREE_FALL +* Address : 0X5D +* Bit Group Name: FF_THS +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_FF_THS_156mg =0x00, + LSM6DSL_ACC_GYRO_FF_THS_219mg =0x01, + LSM6DSL_ACC_GYRO_FF_THS_250mg =0x02, + LSM6DSL_ACC_GYRO_FF_THS_312mg =0x03, + LSM6DSL_ACC_GYRO_FF_THS_344mg =0x04, + LSM6DSL_ACC_GYRO_FF_THS_406mg =0x05, + LSM6DSL_ACC_GYRO_FF_THS_469mg =0x06, + LSM6DSL_ACC_GYRO_FF_THS_500mg =0x07, +} LSM6DSL_ACC_GYRO_FF_THS_t; + +#define LSM6DSL_ACC_GYRO_FF_THS_MASK 0x07 +mems_status_t LSM6DSL_ACC_GYRO_W_FF_THS(void *handle, LSM6DSL_ACC_GYRO_FF_THS_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_FF_THS(void *handle, LSM6DSL_ACC_GYRO_FF_THS_t *value); + +/******************************************************************************* +* Register : MD1_CFG +* Address : 0X5E +* Bit Group Name: INT1_TIMER +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_INT1_TIMER_DISABLED =0x00, + LSM6DSL_ACC_GYRO_INT1_TIMER_ENABLED =0x01, +} LSM6DSL_ACC_GYRO_INT1_TIMER_t; + +#define LSM6DSL_ACC_GYRO_INT1_TIMER_MASK 0x01 +mems_status_t LSM6DSL_ACC_GYRO_W_TimerEvRouteInt1(void *handle, LSM6DSL_ACC_GYRO_INT1_TIMER_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_TimerEvRouteInt1(void *handle, LSM6DSL_ACC_GYRO_INT1_TIMER_t *value); + +/******************************************************************************* +* Register : MD1_CFG +* Address : 0X5E +* Bit Group Name: INT1_TILT +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_INT1_TILT_DISABLED =0x00, + LSM6DSL_ACC_GYRO_INT1_TILT_ENABLED =0x02, +} LSM6DSL_ACC_GYRO_INT1_TILT_t; + +#define LSM6DSL_ACC_GYRO_INT1_TILT_MASK 0x02 +mems_status_t LSM6DSL_ACC_GYRO_W_TiltEvOnInt1(void *handle, LSM6DSL_ACC_GYRO_INT1_TILT_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_TiltEvOnInt1(void *handle, LSM6DSL_ACC_GYRO_INT1_TILT_t *value); + +/******************************************************************************* +* Register : MD1_CFG +* Address : 0X5E +* Bit Group Name: INT1_6D +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_INT1_6D_DISABLED =0x00, + LSM6DSL_ACC_GYRO_INT1_6D_ENABLED =0x04, +} LSM6DSL_ACC_GYRO_INT1_6D_t; + +#define LSM6DSL_ACC_GYRO_INT1_6D_MASK 0x04 +mems_status_t LSM6DSL_ACC_GYRO_W_6DEvOnInt1(void *handle, LSM6DSL_ACC_GYRO_INT1_6D_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_6DEvOnInt1(void *handle, LSM6DSL_ACC_GYRO_INT1_6D_t *value); + +/******************************************************************************* +* Register : MD1_CFG +* Address : 0X5E +* Bit Group Name: INT1_TAP +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_INT1_TAP_DISABLED =0x00, + LSM6DSL_ACC_GYRO_INT1_TAP_ENABLED =0x08, +} LSM6DSL_ACC_GYRO_INT1_TAP_t; + +#define LSM6DSL_ACC_GYRO_INT1_TAP_MASK 0x08 +mems_status_t LSM6DSL_ACC_GYRO_W_TapEvOnInt1(void *handle, LSM6DSL_ACC_GYRO_INT1_TAP_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_TapEvOnInt1(void *handle, LSM6DSL_ACC_GYRO_INT1_TAP_t *value); + +/******************************************************************************* +* Register : MD1_CFG +* Address : 0X5E +* Bit Group Name: INT1_FF +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_INT1_FF_DISABLED =0x00, + LSM6DSL_ACC_GYRO_INT1_FF_ENABLED =0x10, +} LSM6DSL_ACC_GYRO_INT1_FF_t; + +#define LSM6DSL_ACC_GYRO_INT1_FF_MASK 0x10 +mems_status_t LSM6DSL_ACC_GYRO_W_FFEvOnInt1(void *handle, LSM6DSL_ACC_GYRO_INT1_FF_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_FFEvOnInt1(void *handle, LSM6DSL_ACC_GYRO_INT1_FF_t *value); + +/******************************************************************************* +* Register : MD1_CFG +* Address : 0X5E +* Bit Group Name: INT1_WU +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_INT1_WU_DISABLED =0x00, + LSM6DSL_ACC_GYRO_INT1_WU_ENABLED =0x20, +} LSM6DSL_ACC_GYRO_INT1_WU_t; + +#define LSM6DSL_ACC_GYRO_INT1_WU_MASK 0x20 +mems_status_t LSM6DSL_ACC_GYRO_W_WUEvOnInt1(void *handle, LSM6DSL_ACC_GYRO_INT1_WU_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_WUEvOnInt1(void *handle, LSM6DSL_ACC_GYRO_INT1_WU_t *value); + +/******************************************************************************* +* Register : MD1_CFG +* Address : 0X5E +* Bit Group Name: INT1_SINGLE_TAP +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_INT1_SINGLE_TAP_DISABLED =0x00, + LSM6DSL_ACC_GYRO_INT1_SINGLE_TAP_ENABLED =0x40, +} LSM6DSL_ACC_GYRO_INT1_SINGLE_TAP_t; + +#define LSM6DSL_ACC_GYRO_INT1_SINGLE_TAP_MASK 0x40 +mems_status_t LSM6DSL_ACC_GYRO_W_SingleTapOnInt1(void *handle, LSM6DSL_ACC_GYRO_INT1_SINGLE_TAP_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_SingleTapOnInt1(void *handle, LSM6DSL_ACC_GYRO_INT1_SINGLE_TAP_t *value); + +/******************************************************************************* +* Register : MD1_CFG +* Address : 0X5E +* Bit Group Name: INT1_INACT_STATE +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_INT1_SLEEP_DISABLED =0x00, + LSM6DSL_ACC_GYRO_INT1_SLEEP_ENABLED =0x80, +} LSM6DSL_ACC_GYRO_INT1_SLEEP_t; + +#define LSM6DSL_ACC_GYRO_INT1_SLEEP_MASK 0x80 +mems_status_t LSM6DSL_ACC_GYRO_W_SleepEvOnInt1(void *handle, LSM6DSL_ACC_GYRO_INT1_SLEEP_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_SleepEvOnInt1(void *handle, LSM6DSL_ACC_GYRO_INT1_SLEEP_t *value); + +/******************************************************************************* +* Register : MD2_CFG +* Address : 0X5F +* Bit Group Name: INT2_IRON +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_INT2_IRON_DISABLED =0x00, + LSM6DSL_ACC_GYRO_INT2_IRON_ENABLED =0x01, +} LSM6DSL_ACC_GYRO_INT2_IRON_t; + +#define LSM6DSL_ACC_GYRO_INT2_IRON_MASK 0x01 +mems_status_t LSM6DSL_ACC_GYRO_W_MagCorrection_Int2(void *handle, LSM6DSL_ACC_GYRO_INT2_IRON_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_MagCorrection_Int2(void *handle, LSM6DSL_ACC_GYRO_INT2_IRON_t *value); + +/******************************************************************************* +* Register : MD2_CFG +* Address : 0X5F +* Bit Group Name: INT2_TILT +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_INT2_TILT_DISABLED =0x00, + LSM6DSL_ACC_GYRO_INT2_TILT_ENABLED =0x02, +} LSM6DSL_ACC_GYRO_INT2_TILT_t; + +#define LSM6DSL_ACC_GYRO_INT2_TILT_MASK 0x02 +mems_status_t LSM6DSL_ACC_GYRO_W_TiltEvOnInt2(void *handle, LSM6DSL_ACC_GYRO_INT2_TILT_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_TiltEvOnInt2(void *handle, LSM6DSL_ACC_GYRO_INT2_TILT_t *value); + +/******************************************************************************* +* Register : MD2_CFG +* Address : 0X5F +* Bit Group Name: INT2_6D +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_INT2_6D_DISABLED =0x00, + LSM6DSL_ACC_GYRO_INT2_6D_ENABLED =0x04, +} LSM6DSL_ACC_GYRO_INT2_6D_t; + +#define LSM6DSL_ACC_GYRO_INT2_6D_MASK 0x04 +mems_status_t LSM6DSL_ACC_GYRO_W_6DEvOnInt2(void *handle, LSM6DSL_ACC_GYRO_INT2_6D_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_6DEvOnInt2(void *handle, LSM6DSL_ACC_GYRO_INT2_6D_t *value); + +/******************************************************************************* +* Register : MD2_CFG +* Address : 0X5F +* Bit Group Name: INT2_TAP +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_INT2_TAP_DISABLED =0x00, + LSM6DSL_ACC_GYRO_INT2_TAP_ENABLED =0x08, +} LSM6DSL_ACC_GYRO_INT2_TAP_t; + +#define LSM6DSL_ACC_GYRO_INT2_TAP_MASK 0x08 +mems_status_t LSM6DSL_ACC_GYRO_W_TapEvOnInt2(void *handle, LSM6DSL_ACC_GYRO_INT2_TAP_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_TapEvOnInt2(void *handle, LSM6DSL_ACC_GYRO_INT2_TAP_t *value); + +/******************************************************************************* +* Register : MD2_CFG +* Address : 0X5F +* Bit Group Name: INT2_FF +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_INT2_FF_DISABLED =0x00, + LSM6DSL_ACC_GYRO_INT2_FF_ENABLED =0x10, +} LSM6DSL_ACC_GYRO_INT2_FF_t; + +#define LSM6DSL_ACC_GYRO_INT2_FF_MASK 0x10 +mems_status_t LSM6DSL_ACC_GYRO_W_FFEvOnInt2(void *handle, LSM6DSL_ACC_GYRO_INT2_FF_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_FFEvOnInt2(void *handle, LSM6DSL_ACC_GYRO_INT2_FF_t *value); + +/******************************************************************************* +* Register : MD2_CFG +* Address : 0X5F +* Bit Group Name: INT2_WU +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_INT2_WU_DISABLED =0x00, + LSM6DSL_ACC_GYRO_INT2_WU_ENABLED =0x20, +} LSM6DSL_ACC_GYRO_INT2_WU_t; + +#define LSM6DSL_ACC_GYRO_INT2_WU_MASK 0x20 +mems_status_t LSM6DSL_ACC_GYRO_W_WUEvOnInt2(void *handle, LSM6DSL_ACC_GYRO_INT2_WU_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_WUEvOnInt2(void *handle, LSM6DSL_ACC_GYRO_INT2_WU_t *value); + +/******************************************************************************* +* Register : MD2_CFG +* Address : 0X5F +* Bit Group Name: INT2_SINGLE_TAP +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_INT2_SINGLE_TAP_DISABLED =0x00, + LSM6DSL_ACC_GYRO_INT2_SINGLE_TAP_ENABLED =0x40, +} LSM6DSL_ACC_GYRO_INT2_SINGLE_TAP_t; + +#define LSM6DSL_ACC_GYRO_INT2_SINGLE_TAP_MASK 0x40 +mems_status_t LSM6DSL_ACC_GYRO_W_SingleTapOnInt2(void *handle, LSM6DSL_ACC_GYRO_INT2_SINGLE_TAP_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_SingleTapOnInt2(void *handle, LSM6DSL_ACC_GYRO_INT2_SINGLE_TAP_t *value); + +/******************************************************************************* +* Register : MD2_CFG +* Address : 0X5F +* Bit Group Name: INT2_INACT_STATE +* Permission : RW +*******************************************************************************/ +typedef enum { + LSM6DSL_ACC_GYRO_INT2_SLEEP_DISABLED =0x00, + LSM6DSL_ACC_GYRO_INT2_SLEEP_ENABLED =0x80, +} LSM6DSL_ACC_GYRO_INT2_SLEEP_t; + +#define LSM6DSL_ACC_GYRO_INT2_SLEEP_MASK 0x80 +mems_status_t LSM6DSL_ACC_GYRO_W_SleepEvOnInt2(void *handle, LSM6DSL_ACC_GYRO_INT2_SLEEP_t newValue); +mems_status_t LSM6DSL_ACC_GYRO_R_SleepEvOnInt2(void *handle, LSM6DSL_ACC_GYRO_INT2_SLEEP_t *value); + +/******************************************************************************* +* Register : <REGISTER_L> - <REGISTER_H> +* Output Type : GetAccData +* Permission : RO +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_GetRawAccData(void *handle, u8_t *buff); +mems_status_t LSM6DSL_ACC_Get_Acceleration(void *handle, int *buff, u8_t from_fifo); + +/******************************************************************************* +* Register : <REGISTER_L> - <REGISTER_H> +* Output Type : GetFIFOData +* Permission : RO +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_Get_GetFIFOData(void *handle, u8_t *buff); +/******************************************************************************* +* Register : <REGISTER_L> - <REGISTER_H> +* Output Type : GetTimestamp +* Permission : RO +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_Get_GetTimestamp(void *handle, u8_t *buff); +/******************************************************************************* +* Register : <REGISTER_L> - <REGISTER_H> +* Output Type : GetStepCounter +* Permission : RO +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_Get_GetStepCounter(void *handle, u8_t *buff); + +/******************************************************************************* +* Register : <REGISTER_L> - <REGISTER_H> +* Output Type : Pedometer Threshold +* Permission : RO +*******************************************************************************/ +mems_status_t LSM6DSL_ACC_GYRO_W_PedoThreshold(void *handle, u8_t newValue); + +/************** Use Sensor Hub *******************/ + +/* program to .... */ +mems_status_t LSM6DSL_ACC_GYRO_SH0_Program(void *handle, u8_t SlvAddr, u8_t Reg, u8_t len); + +/* Program the six Soft Iron Matrix coefficients. */ +mems_status_t LSM6DSL_ACC_GYRO_SH_init_SI_Matrix(void *handle, u8_t *SI_matrix); + +/* Read a remote device through I2C Sensor Hub Slave 0 */ +mems_status_t LSM6DSL_ACC_GYRO_SH0_ReadMem(void *handle, u8_t SlvAddr, u8_t Reg, u8_t *Bufp, u8_t len, u8_t stop); + +/* Write a remote device through I2C Sensor Hub Slave 0 */ +mems_status_t LSM6DSL_ACC_GYRO_SH0_WriteByte(void *handle, u8_t SlvAddr, u8_t Reg, u8_t Bufp); + +#ifdef __cplusplus +} +#endif + +#endif
diff -r 000000000000 -r 98c301bb7d1b ST_INTERFACES/Actuators/BDCMotor.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ST_INTERFACES/Actuators/BDCMotor.h Tue Oct 03 12:21:11 2017 +0000 @@ -0,0 +1,162 @@ +/** + ****************************************************************************** + * @file BDCMotor.h + * @author IPC Rennes + * @version V1.0.0 + * @date April 6th, 2016 + * @brief This file contains the abstract class describing the interface of a + * Brush DC motor component. + ****************************************************************************** + * @attention + * + * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of STMicroelectronics nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************** + */ + + +/* Define to prevent from recursive inclusion --------------------------------*/ + +#ifndef __BDCMOTOR_CLASS_H +#define __BDCMOTOR_CLASS_H + + +/* Includes ------------------------------------------------------------------*/ + +#include <Component.h> + + +/* Classes ------------------------------------------------------------------*/ + +/** + * An abstract class for BDCMotor components. + */ +class BDCMotor : public Component { +public: + + /** + * @brief Rotation modes. + */ + typedef enum { + BWD = 0, /* Backward. */ + FWD = 1 /* Forward. */ + } direction_t; + + /** + * @brief Disabling the specified bridge. + * @param bridgeId from 0 for bridge A to 1 for bridge B. + * @retval None. + */ + virtual void disable_bridge(unsigned int) = 0; + + /** + * @brief Enabling the specified bridge. + * @param bridgeId from 0 for bridge A to 1 for bridge B + * @retval None. + */ + virtual void enable_bridge(unsigned int) = 0; + + /** + * @brief Getting the PWM frequency of the specified bridge; + * @param bridgeId from 0 for bridge A to 1 for bridge B. + * @retval The frequency in Hz of the specified bridge input PWM. + */ + virtual unsigned int get_bridge_input_pwm_freq(unsigned int) = 0; + + /** + * @brief Getting the bridge status. + * @param bridgeId from 0 for bridge A to 1 for bridge B. + * @retval The status. + */ + virtual unsigned int get_bridge_status(unsigned int) = 0; + + /** + * @brief Getting the device State. + * @param motorId from 0 to (MAX_NUMBER_OF_BRUSH_DC_MOTORS - 1). + * @retval The device state + */ + virtual motorState_t get_device_state(unsigned int) = 0; + + /** + * @brief Getting the current speed in % of the specified motor. + * @param motorId from 0 to (MAX_NUMBER_OF_BRUSH_DC_MOTORS - 1). + * @retval The current speed in %. + */ + virtual unsigned int get_speed(unsigned int) = 0; + + /** + * @brief Stopping the motor and disabling the power bridge immediately. + * @param motorId from 0 to (MAX_NUMBER_OF_BRUSH_DC_MOTORS - 1). + * @retval None. + */ + virtual void hard_hiz(unsigned int) = 0; + + /** + * @brief Stopping the motor immediately. + * @param motorId from 0 to (MAX_NUMBER_OF_BRUSH_DC_MOTORS - 1). + * @retval None. + */ + virtual void hard_stop(unsigned int) = 0; + + /** + * @brief Running the motor. + * @param motorId from 0 to (MAX_NUMBER_OF_BRUSH_DC_MOTORS - 1). + * @param direction The direction of rotation. + * @retval None. + */ + virtual void run(unsigned int, direction_t) = 0; + + /** + * @brief Setting the PWM frequency of the specified bridge. + * @param bridgeId from 0 for bridge A to 1 for bridge B. + * @param frequency of the PWM in Hz + * @retval None. + */ + virtual void set_bridge_input_pwm_freq(unsigned int, unsigned int) = 0; + + /** + * @brief Setting the dual bridge configuration mode. + * @param configuration. The bridge configuration. + * @retval None. + */ + virtual void set_dual_full_bridge_config(unsigned int) = 0; + + /** + * @brief Setting the speed in %. + * @param motorId from 0 to (MAX_NUMBER_OF_BRUSH_DC_MOTORS - 1). + * @param speed The new speed in %. + * @retval "true" in case of success, "false" otherwise. + */ + virtual bool set_speed(unsigned int, unsigned int) = 0; + + /** + * @brief Destructor. + */ + virtual ~BDCMotor() {}; +}; + +#endif /* __BDCMOTOR_CLASS_H */ + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff -r 000000000000 -r 98c301bb7d1b ST_INTERFACES/Actuators/StepperMotor.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ST_INTERFACES/Actuators/StepperMotor.h Tue Oct 03 12:21:11 2017 +0000 @@ -0,0 +1,275 @@ +/** + ****************************************************************************** + * @file StepperMotor.h + * @author Davide Aliprandi, STMicroelectronics + * @version V1.1.0 + * @date April 6th, 2016 + * @brief This file contains the abstract class describing the interface of a + * stepper-motor component. + ****************************************************************************** + * @attention + * + * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of STMicroelectronics nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************** + */ + + +/* Define to prevent from recursive inclusion --------------------------------*/ + +#ifndef __STEPPERMOTOR_CLASS_H +#define __STEPPERMOTOR_CLASS_H + + +/* Includes ------------------------------------------------------------------*/ + +#include <Component.h> + + +/* Classes ------------------------------------------------------------------*/ + +/** + * An abstract class for StepperMotor components. + */ +class StepperMotor : public Component { +public: + + /** + * @brief Rotation modes. + */ + typedef enum { + BWD = 0, /* Backward. */ + FWD = 1 /* Forward. */ + } direction_t; + + /** + * @brief Step modes. + */ + typedef enum { + STEP_MODE_FULL = 0, /* Full-step. */ + STEP_MODE_HALF, /* Half-step. */ + STEP_MODE_1_4, /* 1/4 microstep. */ + STEP_MODE_1_8, /* 1/8 microstep. */ + STEP_MODE_1_16, /* 1/16 microstep. */ + STEP_MODE_1_32, /* 1/32 microstep. */ + STEP_MODE_1_64, /* 1/64 microstep. */ + STEP_MODE_1_128, /* 1/128 microstep. */ + STEP_MODE_1_256, /* 1/256 microstep. */ + STEP_MODE_UNKNOWN, /* Unknown. */ + STEP_MODE_WAVE /* Full-step one-phase-on. */ + } step_mode_t; + + /** + * @brief Getting the status. + * @param None. + * @retval The status. + */ + virtual unsigned int get_status(void) = 0; + + /** + * @brief Getting the position. + * @param None. + * @retval The position. + */ + virtual signed int get_position(void) = 0; + + /** + * @brief Getting the marked position. + * @param None. + * @retval The marked position. + */ + virtual signed int get_mark(void) = 0; + + /** + * @brief Getting the current speed in pps. + * @param None. + * @retval The current speed in pps. + */ + virtual unsigned int get_speed(void) = 0; + + /** + * @brief Getting the maximum speed in pps. + * @param None. + * @retval The maximum speed in pps. + */ + virtual unsigned int get_max_speed(void) = 0; + + /** + * @brief Getting the minimum speed in pps. + * @param None. + * @retval The minimum speed in pps. + */ + virtual unsigned int get_min_speed(void) = 0; + + /** + * @brief Getting the acceleration in pps^2. + * @param None. + * @retval The acceleration in pps^2. + */ + virtual unsigned int get_acceleration(void) = 0; + + /** + * @brief Getting the deceleration in pps^2. + * @param None. + * @retval The deceleration in pps^2. + */ + virtual unsigned int get_deceleration(void) = 0; + + /** + * @brief Getting the direction of rotation. + * @param None. + * @retval The direction of rotation. + */ + virtual direction_t get_direction(void) = 0; + + /** + * @brief Setting the current position to be the home position. + * @param None. + * @retval None. + */ + virtual void set_home(void) = 0; + + /** + * @brief Setting the current position to be the marked position. + * @param None. + * @retval None. + */ + virtual void set_mark(void) = 0; + + /** + * @brief Setting the maximum speed in pps. + * @param speed The maximum speed in pps. + * @retval "true" in case of success, "false" otherwise. + */ + virtual bool set_max_speed(unsigned int speed) = 0; + + /** + * @brief Setting the minimum speed in pps. + * @param speed The minimum speed in pps. + * @retval "true" in case of success, "false" otherwise. + */ + virtual bool set_min_speed(unsigned int speed) = 0; + + /** + * @brief Setting the acceleration in pps^2. + * @param acceleration The acceleration in pps^2. + * @retval "true" in case of success, "false" otherwise. + */ + virtual bool set_acceleration(unsigned int acceleration) = 0; + + /** + * @brief Setting the deceleration in pps^2. + * @param deceleration The deceleration in pps^2. + * @retval "true" in case of success, "false" otherwise. + */ + virtual bool set_deceleration(unsigned int deceleration) = 0; + + /** + * @brief Setting the Step Mode. + * @param step_mode The Step Mode. + * @retval "true" in case of success, "false" otherwise. + */ + virtual bool set_step_mode(step_mode_t step_mode) = 0; + + /** + * @brief Going to a specified position. + * @param position The desired position. + * @retval None. + */ + virtual void go_to(signed int position) = 0; + + /** + * @brief Going to the home position. + * @param None. + * @retval None. + */ + virtual void go_home(void) = 0; + + /** + * @brief Going to the marked position. + * @param None. + * @retval None. + */ + virtual void go_mark(void) = 0; + + /** + * @brief Running the motor towards a specified direction. + * @param direction The direction of rotation. + * @retval None. + */ + virtual void run(direction_t direction) = 0; + + /** + * @brief Moving the motor towards a specified direction for a certain number of steps. + * @param direction The direction of rotation. + * @param steps The desired number of steps. + * @retval None. + */ + virtual void move(direction_t direction, unsigned int steps) = 0; + + /** + * @brief Stopping the motor through an immediate deceleration up to zero speed. + * @param None. + * @retval None. + */ + virtual void soft_stop(void) = 0; + + /** + * @brief Stopping the motor through an immediate infinite deceleration. + * @param None. + * @retval None. + */ + virtual void hard_stop(void) = 0; + + /** + * @brief Disabling the power bridge after performing a deceleration to zero. + * @param None. + * @retval None. + */ + virtual void soft_hiz(void) = 0; + + /** + * @brief Disabling the power bridge immediately. + * @param None. + * @retval None. + */ + virtual void hard_hiz(void) = 0; + + /** + * @brief Waiting while the motor is active. + * @param None. + * @retval None. + */ + virtual void wait_while_active(void) = 0; + + /** + * @brief Destructor. + */ + virtual ~StepperMotor() {}; +}; + +#endif /* __STEPPERMOTOR_CLASS_H */ + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff -r 000000000000 -r 98c301bb7d1b ST_INTERFACES/Common/Component.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ST_INTERFACES/Common/Component.h Tue Oct 03 12:21:11 2017 +0000 @@ -0,0 +1,81 @@ +/** + ****************************************************************************** + * @file Component.h + * @author AST + * @version V1.0.0 + * @date April 13th, 2015 + * @brief This file contains the abstract class describing the interface of a + * generic component. + ****************************************************************************** + * @attention + * + * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of STMicroelectronics nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************** + */ + + +/* Define to prevent recursive inclusion -------------------------------------*/ + +#ifndef __COMPONENT_CLASS_H +#define __COMPONENT_CLASS_H + + +/* Includes ------------------------------------------------------------------*/ + +#include <stdint.h> + + +/* Classes ------------------------------------------------------------------*/ + +/** + * An abstract class for Generic components. + */ +class Component { +public: + + /** + * @brief Initializing the component. + * @param[in] init pointer to device specific initalization structure. + * @retval "0" in case of success, an error code otherwise. + */ + virtual int init(void *init) = 0; + + /** + * @brief Getting the ID of the component. + * @param[out] id pointer to an allocated variable to store the ID into. + * @retval "0" in case of success, an error code otherwise. + */ + virtual int read_id(uint8_t *id) = 0; + + /** + * @brief Destructor. + */ + virtual ~Component() {}; +}; + +#endif /* __COMPONENT_CLASS_H */ + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff -r 000000000000 -r 98c301bb7d1b ST_INTERFACES/Communications/Nfc.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ST_INTERFACES/Communications/Nfc.h Tue Oct 03 12:21:11 2017 +0000 @@ -0,0 +1,92 @@ +/** + ****************************************************************************** + * @file Nfc.h + * @author ST Central Labs + * @version V1.0.0 + * @date 13-April-2015 + * @brief This file contains the abstract class describing the interface of a + * nfc component. + ****************************************************************************** + * @attention + * + * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of STMicroelectronics nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************** + */ + + +/* Generated with Stm32CubeTOO -----------------------------------------------*/ + +/* Define to prevent from recursive inclusion --------------------------------*/ + +#ifndef __NFC_CLASS_H +#define __NFC_CLASS_H + + +/* Includes ------------------------------------------------------------------*/ + +#include <Component.h> + +typedef enum { + NFC_SUCCESS = 0, +} NFC_t; +/* Error codes are in component driver */ + + +/* Classes ------------------------------------------------------------------*/ + +/** + * An abstract class for Nfc components. + */ +class Nfc : public Component { +public: + + /** + * Read data from the tag. + * @param offset Read offset. + * @param nb_bytes_to_read Number of bytes to read. + * @param[out] p_buffer_read Buffer to store the read data into. + * @return NFC_SUCCESS if no errors + */ + virtual int read_binary(uint16_t offset, uint8_t nb_bytes_to_read, uint8_t *p_buffer_read) = 0; + + /** + * Write data to the tag. + * @param offset Write offset. + * @param nb_bytes_to_write Number of bytes to write. + * @param p_buffer_write Buffer to write. + * @return NFC_SUCCESS if no errors + */ + virtual int update_binary(uint16_t offset, uint8_t nb_bytes_to_write, uint8_t *p_buffer_write) = 0; + + /** + * @brief Destructor. + */ + virtual ~Nfc() {}; +}; + +#endif /* __NFC_CLASS_H */ + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff -r 000000000000 -r 98c301bb7d1b ST_INTERFACES/Sensors/GyroSensor.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ST_INTERFACES/Sensors/GyroSensor.h Tue Oct 03 12:21:11 2017 +0000 @@ -0,0 +1,126 @@ +/** + ****************************************************************************** + * @file GyroSensor.h + * @author AST / EST + * @version V0.0.1 + * @date 13-April-2015 + * @brief This file contains the abstract class describing in general + * the interfaces of a gyroscope + ****************************************************************************** + * @attention + * + * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of STMicroelectronics nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************** + */ + + +/* Define to prevent from recursive inclusion --------------------------------*/ + +#ifndef __GYRO_SENSOR_CLASS_H +#define __GYRO_SENSOR_CLASS_H + + +/* Includes ------------------------------------------------------------------*/ + +#include <Component.h> + + +/* Classes ------------------------------------------------------------------*/ + +/** + * An abstract class for a Gyroscope + */ +class GyroSensor : public Component { +public: + + /** + * @brief Get current gyroscope angular rate X/Y/Z-axes values + * in standard data units [mdps] + * @param[out] p_data Pointer to where to store angular rates to. + * p_data must point to an array of (at least) three elements, where: + * p_data[0] corresponds to X-axis, + * p_data[1] corresponds to Y-axis, and + * p_data[2] corresponds to Z-axis. + * @return 0 in case of success, an error code otherwise + */ + virtual int get_g_axes(int32_t *p_data) = 0; + + /** + * @brief Get current gyroscope raw data X/Y/Z-axes values + * in device sepcific LSB units + * @param[out] p_data Pointer to where to store gyroscope raw data to. + * p_data must point to an array of (at least) three elements, where: + * p_data[0] corresponds to X-axis, + * p_data[1] corresponds to Y-axis, and + * p_data[2] corresponds to Z-axis. + * @return 0 in case of success, an error code otherwise + */ + virtual int get_g_axes_raw(int16_t *p_data) = 0; + + /** + * @brief Get gyroscope's current sensitivity [mdps/LSB] + * @param[out] pf_data Pointer to where the gyroscope's sensitivity is stored to + * @return 0 in case of success, an error code otherwise + */ + virtual int get_g_sensitivity(float *pf_data) = 0; + + /** + * @brief Get gyroscope's current output data rate [Hz] + * @param[out] pf_data Pointer to where the gyroscope output data rate is stored to + * @return 0 in case of success, an error code otherwise + */ + virtual int get_g_odr(float *pf_data) = 0; + + /** + * @brief Set gyroscope's output data rate + * @param[in] odr New value for gyroscope's output data rate in [Hz] + * @return 0 in case of success, an error code otherwise + */ + virtual int set_g_odr(float odr) = 0; + + /** + * @brief Get gyroscope's full scale value + * i.e.\ min/max measurable value [dps] + * @param[out] pf_data Pointer to where the gyroscope full scale value is stored to + * @return 0 in case of success, an error code otherwise + */ + virtual int get_g_fs(float *pf_data) = 0; + + /** + * @brief Set gyroscope's full scale value + * i.e.\ min/max measurable value + * @param[in] fs New full scale value for gyroscope in [dps] + * @return 0 in case of success, an error code otherwise + */ + virtual int set_g_fs(float fs) = 0; + + /** + * @brief Destructor. + */ + virtual ~GyroSensor() {}; +}; + +#endif /* __GYRO_SENSOR_CLASS_H */
diff -r 000000000000 -r 98c301bb7d1b ST_INTERFACES/Sensors/HumiditySensor.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ST_INTERFACES/Sensors/HumiditySensor.h Tue Oct 03 12:21:11 2017 +0000 @@ -0,0 +1,72 @@ +/** + ****************************************************************************** + * @file HumiditySensor.h + * @author AST / EST + * @version V0.0.1 + * @date 13-April-2015 + * @brief This file contains the abstract class describing in general + * the interfaces of a humidity sensor + ****************************************************************************** + * @attention + * + * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of STMicroelectronics nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************** + */ + + +/* Define to prevent from recursive inclusion --------------------------------*/ + +#ifndef __HUMIDITY_SENSOR_CLASS_H +#define __HUMIDITY_SENSOR_CLASS_H + + +/* Includes ------------------------------------------------------------------*/ + +#include <Component.h> + + +/* Classes ------------------------------------------------------------------*/ + +/** + * An abstract class for Humidity sensors + */ +class HumiditySensor : public Component { +public: + + /** + * @brief Get current humidity [%] + * @param[out] pf_data Pointer to where to store humidity to + * @return 0 in case of success, an error code otherwise + */ + virtual int get_humidity(float *pf_data) = 0; + + /** + * @brief Destructor. + */ + virtual ~HumiditySensor() {}; +}; + +#endif /* __HUMIDITY_SENSOR_CLASS_H */
diff -r 000000000000 -r 98c301bb7d1b ST_INTERFACES/Sensors/LightSensor.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ST_INTERFACES/Sensors/LightSensor.h Tue Oct 03 12:21:11 2017 +0000 @@ -0,0 +1,72 @@ +/** + ****************************************************************************** + * @file LightSensor.h + * @author AST / EST + * @version V0.0.1 + * @date 13-April-2015 + * @brief This file contains the abstract class describing in general + * the interfaces of an ambient light sensor (ALS) + ****************************************************************************** + * @attention + * + * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of STMicroelectronics nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************** + */ + + +/* Define to prevent from recursive inclusion --------------------------------*/ + +#ifndef __LIGHT_SENSOR_CLASS_H +#define __LIGHT_SENSOR_CLASS_H + + +/* Includes ------------------------------------------------------------------*/ + +#include <Component.h> + + +/* Classes ------------------------------------------------------------------*/ + +/** + * An abstract class for ambient light sensors + */ +class LightSensor : public Component { +public: + + /** + * @brief Get current light [lux] + * @param[out] pi_data Pointer to where to store light to + * @return 0 in case of success, an error code otherwise + */ + virtual int get_lux(uint32_t *pi_data) = 0; + + /** + * @brief Destructor. + */ + virtual ~LightSensor() {}; +}; + +#endif /* __LIGHT_SENSOR_CLASS_H */
diff -r 000000000000 -r 98c301bb7d1b ST_INTERFACES/Sensors/MagneticSensor.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ST_INTERFACES/Sensors/MagneticSensor.h Tue Oct 03 12:21:11 2017 +0000 @@ -0,0 +1,89 @@ +/** + ****************************************************************************** + * @file MagneticSensor.h + * @author AST / EST + * @version V0.0.1 + * @date 13-April-2015 + * @brief This file contains the abstract class describing in general + * the interfaces of a magnetometer + ****************************************************************************** + * @attention + * + * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of STMicroelectronics nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************** + */ + + +/* Define to prevent from recursive inclusion --------------------------------*/ + +#ifndef __MAGNETIC_SENSOR_CLASS_H +#define __MAGNETIC_SENSOR_CLASS_H + + +/* Includes ------------------------------------------------------------------*/ + +#include <Component.h> + + +/* Classes ------------------------------------------------------------------*/ + +/** + * An abstract class for a magnetometer + */ +class MagneticSensor : public Component { +public: + + /** + * @brief Get current magnetometer magnetic X/Y/Z-axes values + * in standard data units [mgauss] + * @param[out] p_data Pointer to where to store magnetic values to. + * p_data must point to an array of (at least) three elements, where: + * p_data[0] corresponds to X-axis, + * p_data[1] corresponds to Y-axis, and + * p_data[2] corresponds to Z-axis. + * @return 0 in case of success, an error code otherwise + */ + virtual int get_m_axes(int32_t *p_data) = 0; + + /** + * @brief Get current magnetometer raw data X/Y/Z-axes values + * in device sepcific LSB units + * @param[out] p_data Pointer to where to store magnetometer raw data to. + * p_data must point to an array of (at least) three elements, where: + * p_data[0] corresponds to X-axis, + * p_data[1] corresponds to Y-axis, and + * p_data[2] corresponds to Z-axis. + * @return 0 in case of success, an error code otherwise + */ + virtual int get_m_axes_raw(int16_t *p_data) = 0; + + /** + * @brief Destructor. + */ + virtual ~MagneticSensor() {}; +}; + +#endif /* __MAGNETIC_SENSOR_CLASS_H */
diff -r 000000000000 -r 98c301bb7d1b ST_INTERFACES/Sensors/MotionSensor.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ST_INTERFACES/Sensors/MotionSensor.h Tue Oct 03 12:21:11 2017 +0000 @@ -0,0 +1,126 @@ +/** + ****************************************************************************** + * @file MotionSensor.h + * @author AST / EST + * @version V0.0.1 + * @date 13-April-2015 + * @brief This file contains the abstract class describing in general + * the interfaces of an accelerometer + ****************************************************************************** + * @attention + * + * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of STMicroelectronics nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************** + */ + + +/* Define to prevent from recursive inclusion --------------------------------*/ + +#ifndef __MOTION_SENSOR_CLASS_H +#define __MOTION_SENSOR_CLASS_H + + +/* Includes ------------------------------------------------------------------*/ + +#include <Component.h> + + +/* Classes ------------------------------------------------------------------*/ + +/** + * An abstract class for an Accelerometer + */ +class MotionSensor : public Component { +public: + + /** + * @brief Get current accelerometer linear acceleration X/Y/Z-axes values + * in standard data units [mg] + * @param[out] p_data Pointer to where to store linear accelerations to. + * p_data must point to an array of (at least) three elements, where: + * p_data[0] corresponds to X-axis, + * p_data[1] corresponds to Y-axis, and + * p_data[2] corresponds to Z-axis. + * @return 0 in case of success, an error code otherwise + */ + virtual int get_x_axes(int32_t *p_data) = 0; + + /** + * @brief Get current accelerometer raw data X/Y/Z-axes values + * in device sepcific LSB units + * @param[out] p_data Pointer to where to store accelerometer raw data to. + * p_data must point to an array of (at least) three elements, where: + * p_data[0] corresponds to X-axis, + * p_data[1] corresponds to Y-axis, and + * p_data[2] corresponds to Z-axis. + * @return 0 in case of success, an error code otherwise + */ + virtual int get_x_axes_raw(int16_t *p_data) = 0; + + /** + * @brief Get accelerometer's current sensitivity [mg/LSB] + * @param[out] pf_data Pointer to where the accelerometer's sensitivity is stored to + * @return 0 in case of success, an error code otherwise + */ + virtual int get_x_sensitivity(float *pf_data) = 0; + + /** + * @brief Get accelerometer's current output data rate [Hz] + * @param[out] pf_data Pointer to where the accelerometer output data rate is stored to + * @return 0 in case of success, an error code otherwise + */ + virtual int get_x_odr(float *pf_data) = 0; + + /** + * @brief Set accelerometer's output data rate + * @param[in] odr New value for accelerometer's output data rate in [Hz] + * @return 0 in case of success, an error code otherwise + */ + virtual int set_x_odr(float odr) = 0; + + /** + * @brief Get accelerometer's full scale value + * i.e.\ min/max measurable value [g] + * @param[out] pf_data Pointer to where the accelerometer full scale value is stored to + * @return 0 in case of success, an error code otherwise + */ + virtual int get_x_fs(float *pf_data) = 0; + + /** + * @brief Set accelerometer's full scale value + * i.e.\ min/max measurable value + * @param[in] fs New full scale value for accelerometer in [g] + * @return 0 in case of success, an error code otherwise + */ + virtual int set_x_fs(float fs) = 0; + + /** + * @brief Destructor. + */ + virtual ~MotionSensor() {}; +}; + +#endif /* __MOTION_SENSOR_CLASS_H */
diff -r 000000000000 -r 98c301bb7d1b ST_INTERFACES/Sensors/PressureSensor.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ST_INTERFACES/Sensors/PressureSensor.h Tue Oct 03 12:21:11 2017 +0000 @@ -0,0 +1,72 @@ +/** + ****************************************************************************** + * @file PressureSensor.h + * @author AST / EST + * @version V0.0.1 + * @date 13-April-2015 + * @brief This file contains the abstract class describing in general + * the interfaces of a pressure sensor + ****************************************************************************** + * @attention + * + * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of STMicroelectronics nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************** + */ + + +/* Define to prevent from recursive inclusion --------------------------------*/ + +#ifndef __PRESSURE_SENSOR_CLASS_H +#define __PRESSURE_SENSOR_CLASS_H + + +/* Includes ------------------------------------------------------------------*/ + +#include <Component.h> + + +/* Classes ------------------------------------------------------------------*/ + +/** + * An abstract class for a Pressure Sensor + */ +class PressureSensor : public Component { +public: + + /** + * @brief Get current pressure [mbar] + * @param[out] pf_data Pointer to where to store pressure to + * @return 0 in case of success, an error code otherwise + */ + virtual int get_pressure(float *pf_data) = 0; + + /** + * @brief Destructor. + */ + virtual ~PressureSensor() {}; +}; + +#endif /* __PRESSURE_SENSOR_CLASS_H */
diff -r 000000000000 -r 98c301bb7d1b ST_INTERFACES/Sensors/RangeSensor.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ST_INTERFACES/Sensors/RangeSensor.h Tue Oct 03 12:21:11 2017 +0000 @@ -0,0 +1,72 @@ +/** + ****************************************************************************** + * @file RangeSensor.h + * @author AST / EST + * @version V0.0.1 + * @date 13-April-2015 + * @brief This file contains the abstract class describing in general + * the interfaces of a range sensor + ****************************************************************************** + * @attention + * + * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of STMicroelectronics nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************** + */ + + +/* Define to prevent from recursive inclusion --------------------------------*/ + +#ifndef __RANGE_SENSOR_CLASS_H +#define __RANGE_SENSOR_CLASS_H + + +/* Includes ------------------------------------------------------------------*/ + +#include <Component.h> + + +/* Classes ------------------------------------------------------------------*/ + +/** + * An abstract class for range sensors + */ +class RangeSensor : public Component { +public: + + /** + * @brief Get current range [mm] + * @param[out] pi_data Pointer to where to store range to + * @return 0 in case of success, an error code otherwise + */ + virtual int get_distance(uint32_t *pi_data) = 0; + + /** + * @brief Destructor. + */ + virtual ~RangeSensor() {}; +}; + +#endif /* __RANGE_SENSOR_CLASS_H */
diff -r 000000000000 -r 98c301bb7d1b ST_INTERFACES/Sensors/TempSensor.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ST_INTERFACES/Sensors/TempSensor.h Tue Oct 03 12:21:11 2017 +0000 @@ -0,0 +1,91 @@ +/** + ****************************************************************************** + * @file TempSensor.h + * @author AST / EST + * @version V0.0.1 + * @date 13-April-2015 + * @brief This file contains the abstract class describing in general + * the interfaces of a temperature sensor + ****************************************************************************** + * @attention + * + * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of STMicroelectronics nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************** + */ + + +/* Define to prevent from recursive inclusion --------------------------------*/ + +#ifndef __TEMP_SENSOR_CLASS_H +#define __TEMP_SENSOR_CLASS_H + + +/* Includes ------------------------------------------------------------------*/ + +#include <Component.h> + + +/* Classes ------------------------------------------------------------------*/ + +/** + * An abstract class for Temperature sensors + */ +class TempSensor : public Component { +public: + + /** + * @brief Get current temperature in degrees Celsius [°C] + * @param[out] pf_data Pointer to where to store temperature to + * @return 0 in case of success, an error code otherwise + */ + virtual int get_temperature(float *pf_data) = 0; + + /** + * @brief Get current temperature in degrees Fahrenheit [°F] + * @param[out] pf_data Pointer to where to store temperature to + * @return 0 in case of success, an error code otherwise + */ + virtual int get_fahrenheit(float *pf_data) { + float celsius; + int ret; + + ret = get_temperature(&celsius); + if (ret) { + return ret; + } + + *pf_data = ((celsius * 1.8f) + 32.0f); + + return 0; + } + + /** + * @brief Destructor. + */ + virtual ~TempSensor() {}; +}; + +#endif /* __TEMP_SENSOR_CLASS_H */
diff -r 000000000000 -r 98c301bb7d1b XNucleoIKS01A2.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/XNucleoIKS01A2.cpp Tue Oct 03 12:21:11 2017 +0000 @@ -0,0 +1,122 @@ +/** + ****************************************************************************** + * @file XNucleoIKS01A2.cpp + * @author CLab + * @version V1.0.0 + * @date 9-August-2016 + * @brief Implementation file for the X_NUCLEO_IKS01A2 singleton class + ****************************************************************************** + * @attention + * + * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of STMicroelectronics nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************** +*/ + +/* Includes ------------------------------------------------------------------*/ +#include "mbed.h" +#include "XNucleoIKS01A2.h" + +/* Static variables ----------------------------------------------------------*/ +XNucleoIKS01A2 *XNucleoIKS01A2::_instance = NULL; + + +/* Methods -------------------------------------------------------------------*/ +/** + * @brief Constructor + */ +XNucleoIKS01A2::XNucleoIKS01A2(DevI2C *ext_i2c, PinName int1, PinName int2) : dev_i2c(ext_i2c), + ht_sensor(new HTS221Sensor(*dev_i2c)), + magnetometer(new LSM303AGRMagSensor(*dev_i2c)), + accelerometer(new LSM303AGRAccSensor(*dev_i2c)), + pt_sensor(new LPS22HBSensor(*dev_i2c)), + acc_gyro(new LSM6DSLSensor(*dev_i2c, int1, int2)) +{ + ht_sensor->init(NULL); + magnetometer->init(NULL); + accelerometer->init(NULL); + pt_sensor->init(NULL); + acc_gyro->init(NULL); +} + +/** + * @brief Get singleton instance + * @return a pointer to the initialized singleton instance of class XNucleoIKS01A2. + * A return value of NULL indicates an out of memory situation. + * @param[in] ext_i2c (optional) pointer to an instance of DevI2C to be used + * for communication on the expansion board. + * Defaults to NULL. + * Taken into account only on the very first call of one of the 'Instance' functions. + * If not provided a new DevI2C will be created with standard + * configuration parameters. + * The used DevI2C object gets saved in instance variable dev_i2c. + * @param[in] int1 LSM6DSL INT1 pin. + * Taken into account only on the very first call of one of the 'Instance' functions. + * It maps the INT1 pin for LSM6DSL. Defaults to IKS01A2_PIN_LSM6DSL_INT1. + * @param[in] int2 LSM6DSL INT1 pin. + * Taken into account only on the very first call of one of the 'Instance' functions. + * It maps the INT2 pin for LSM6DSL. Defaults to IKS01A2_PIN_LSM6DSL_INT2. + */ +XNucleoIKS01A2 *XNucleoIKS01A2::instance(DevI2C *ext_i2c, PinName int1, PinName int2) { + if(_instance == NULL) { + if(ext_i2c == NULL) + ext_i2c = new DevI2C(IKS01A2_PIN_I2C_SDA, IKS01A2_PIN_I2C_SCL); + + if(ext_i2c != NULL) + _instance = new XNucleoIKS01A2(ext_i2c, int1, int2); + } + + return _instance; +} + +/** + * @brief Get singleton instance + * @return a pointer to the initialized singleton instance of class X_NUCLEO_IKS01A1. + * A return value of NULL indicates an out of memory situation. + * @param[in] sda I2C data line pin. + * Taken into account only on the very first call of one of the 'Instance' functions. + * A new DevI2C will be created based on parameters 'sda' and 'scl'. + * The used DevI2C object gets saved in instance variable dev_i2c. + * @param[in] scl I2C clock line pin. + * Taken into account only on the very first call of one of the 'Instance' functions. + * A new DevI2C will be created based on parameters 'sda' and 'scl'. + * The used DevI2C object gets saved in instance variable dev_i2c. + * @param[in] int1 LSM6DSL INT1 pin. + * Taken into account only on the very first call of one of the 'Instance' functions. + * It maps the INT1 pin for LSM6DSL. Defaults to IKS01A2_PIN_LSM6DSL_INT1. + * @param[in] int2 LSM6DSL INT1 pin. + * Taken into account only on the very first call of one of the 'Instance' functions. + * It maps the INT2 pin for LSM6DSL. Defaults to IKS01A2_PIN_LSM6DSL_INT2. + */ +XNucleoIKS01A2 *XNucleoIKS01A2::instance(PinName sda, PinName scl, PinName int1, PinName int2) { + if(_instance == NULL) { + DevI2C *ext_i2c = new DevI2C(sda, scl); + + if(ext_i2c != NULL) + _instance = new XNucleoIKS01A2(ext_i2c, int1, int2); + } + + return _instance; +}
diff -r 000000000000 -r 98c301bb7d1b XNucleoIKS01A2.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/XNucleoIKS01A2.h Tue Oct 03 12:21:11 2017 +0000 @@ -0,0 +1,107 @@ +/** + ****************************************************************************** + * @file XNucleoIKS01A2.h + * @author CLab + * @version V1.0.0 + * @date 9-August-2016 + * @brief Header file for class XNucleoIKS01A2 representing a X-NUCLEO-IKS01A2 + * expansion board + ****************************************************************************** + * @attention + * + * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of STMicroelectronics nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************** + */ + +/* Define to prevent from recursive inclusion --------------------------------*/ +#ifndef __X_NUCLEO_IKS01A2_H +#define __X_NUCLEO_IKS01A2_H + +/* Includes ------------------------------------------------------------------*/ +#include "mbed.h" +#include "x_nucleo_iks01a2_targets.h" +#include "HTS221Sensor/HTS221Sensor.h" +#include "LSM303AGRSensor/LSM303AGRAccSensor.h" +#include "LSM303AGRSensor/LSM303AGRMagSensor.h" +#include "LPS22HBSensor/LPS22HBSensor.h" +#include "LSM6DSLSensor/LSM6DSLSensor.h" +#include "DevI2C.h" + +/* Macros -------------------------------------------------------------------*/ +#define CALL_METH(obj, meth, param, ret) ((obj == NULL) ? \ + ((*(param) = (ret)), 0) : \ + ((obj)->meth(param)) \ + ) + +/* Classes -------------------------------------------------------------------*/ +/** Class XNucleoIKS01A2 is intended to represent the MEMS Inertial & Environmental + * Nucleo Expansion Board with the same name. + * + * The expansion board is featuring basically four IPs:\n + * -# a HTS221 Relative Humidity and Temperature Sensor\n + * -# a LSM303AGR 3-Axis Magnetometer and 3D Acceleromenter\n + * -# a LPS22HB MEMS Pressure Sensor (and Temperature Sensor)\n + * -# and a LSM6DSL 3D Acceleromenter and 3D Gyroscope\n + * + * The expansion board features also a DIL 24-pin socket which makes it possible + * to add further MEMS adapters and other sensors (e.g. UV index). + * + * It is intentionally implemented as a singleton because only one + * X_NUCLEO_IKS01A2 at a time might be deployed in a HW component stack.\n + * In order to get the singleton instance you have to call class method `Instance()`, + * e.g.: + * @code + * // Inertial & Environmental expansion board singleton instance + * static X_NUCLEO_IKS01A2 *<TODO>_expansion_board = X_NUCLEO_IKS01A2::Instance(); + * @endcode + */ +class XNucleoIKS01A2 +{ + protected: + XNucleoIKS01A2(DevI2C *ext_i2c, PinName int1, PinName int2); + + ~XNucleoIKS01A2(void) { + /* should never be called */ + error("Trial to delete XNucleoIKS01A2 singleton!\n"); + } + + public: + static XNucleoIKS01A2* instance(DevI2C *ext_i2c = NULL, PinName int1 = IKS01A2_PIN_LSM6DSL_INT1, PinName int2 = IKS01A2_PIN_LSM6DSL_INT2); + static XNucleoIKS01A2* instance(PinName sda, PinName scl, PinName int1 = IKS01A2_PIN_LSM6DSL_INT1, PinName int2 = IKS01A2_PIN_LSM6DSL_INT2); + + DevI2C *dev_i2c; + + HTS221Sensor *ht_sensor; + LSM303AGRMagSensor *magnetometer; + LSM303AGRAccSensor *accelerometer; + LPS22HBSensor *pt_sensor; + LSM6DSLSensor *acc_gyro; + + private: + static XNucleoIKS01A2 *_instance; +}; + +#endif /* __X_NUCLEO_IKS01A2_H */
diff -r 000000000000 -r 98c301bb7d1b X_NUCLEO_COMMON/DbgMCU/DbgMCU.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/X_NUCLEO_COMMON/DbgMCU/DbgMCU.h Tue Oct 03 12:21:11 2017 +0000 @@ -0,0 +1,64 @@ +/** + ****************************************************************************** + * @file DbgMCU.h + * @author AST / EST + * @version V0.0.1 + * @date 30-March-2015 + * @brief Header file for enabling debugging in sleep modes for STM32 MCUs + ****************************************************************************** + * @attention + * + * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2> + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of STMicroelectronics nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************** + */ + +/* Define to prevent from recursive inclusion --------------------------------*/ +#ifndef __DBG_MCU_H +#define __DBG_MCU_H + +/* Includes ------------------------------------------------------------------*/ + +/* Classes -------------------------------------------------------------------*/ +/** Helper class DbgMCU providing a default constructor which enables debugging + * on STM32 MCUs while using sleep modes. + */ +class DbgMCU +{ + public: + /** Create a DbgMCU dummy object */ + DbgMCU(void) { + /* the following code is NOT portable */ + volatile uint32_t *dbgmcu_creg = (uint32_t*)0xE0042004; + uint32_t tmp = *dbgmcu_creg; + + tmp &= ~(0xE7); + tmp |= 0x27; // Set asynchronous communication via DBGMCU_CR (for ITM/printf) + // tmp |= 0xE7; // Set 4-pin tracing via DBGMCU_CR (for ETM) + *dbgmcu_creg = tmp; + } +}; + +#endif /* __DBG_MCU_H */
diff -r 000000000000 -r 98c301bb7d1b X_NUCLEO_COMMON/DevI2C/DevI2C.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/X_NUCLEO_COMMON/DevI2C/DevI2C.h Tue Oct 03 12:21:11 2017 +0000 @@ -0,0 +1,142 @@ +/** + ****************************************************************************** + * @file DevI2C.h + * @author AST / EST + * @version V1.1.0 + * @date 21-January-2016 + * @brief Header file for a special I2C class DevI2C which provides some + * helper function for on-board communication + ****************************************************************************** + * @attention + * + * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of STMicroelectronics nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************** + */ + +/* Define to prevent from recursive inclusion --------------------------------*/ +#ifndef __DEV_I2C_H +#define __DEV_I2C_H + +/* Includes ------------------------------------------------------------------*/ +#include "mbed.h" +#include "pinmap.h" + +/* Classes -------------------------------------------------------------------*/ +/** Helper class DevI2C providing functions for multi-register I2C communication + * common for a series of I2C devices + */ +class DevI2C : public I2C +{ +public: + /** Create a DevI2C Master interface, connected to the specified pins + * + * @param sda I2C data line pin + * @param scl I2C clock line pin + */ + DevI2C(PinName sda, PinName scl) : I2C(sda, scl) {} + + /** Create a DevI2C Master interface, connected to the specified pins and set their pin modes + * + * @param sda I2C data line pin + * @param sda I2C data pin mode + * @param scl I2C clock line pin + * @param scl I2C clock pin mode + * + * @note this is a workaround to provide a constructor which currently + * is somehow missing in the I2C base class and it's underlying + * implementations. In some circumstances (e.g. while debugging) + * where long latencies between the initialization of the i2c + * interface in the I2C constructor and the setting of the pin + * modes in the beyond constructor might occur, the i2c + * communication might be compromised. + */ + DevI2C(PinName sda, int mode_sda, PinName scl, int mode_scl) : I2C(sda, scl) { + pin_mode(sda, (PinMode)mode_sda); + pin_mode(scl, (PinMode)mode_scl); + } + + /** + * @brief Writes a buffer towards the I2C peripheral device. + * @param pBuffer pointer to the byte-array data to send + * @param DeviceAddr specifies the peripheral device slave address. + * @param RegisterAddr specifies the internal address register + * where to start writing to (must be correctly masked). + * @param NumByteToWrite number of bytes to be written. + * @retval 0 if ok, + * @retval -1 if an I2C error has occured, or + * @retval -2 on temporary buffer overflow (i.e. NumByteToWrite was too high) + * @note On some devices if NumByteToWrite is greater + * than one, the RegisterAddr must be masked correctly! + */ + int i2c_write(uint8_t* pBuffer, uint8_t DeviceAddr, uint8_t RegisterAddr, + uint16_t NumByteToWrite) { + int ret; + uint8_t tmp[TEMP_BUF_SIZE]; + + if(NumByteToWrite >= TEMP_BUF_SIZE) return -2; + + /* First, send device address. Then, send data and STOP condition */ + tmp[0] = RegisterAddr; + memcpy(tmp+1, pBuffer, NumByteToWrite); + + ret = write(DeviceAddr, (const char*)tmp, NumByteToWrite+1, false); + + if(ret) return -1; + return 0; + } + + /** + * @brief Reads a buffer from the I2C peripheral device. + * @param pBuffer pointer to the byte-array to read data in to + * @param DaviceAddr specifies the peripheral device slave address. + * @param RegisterAddr specifies the internal address register + * where to start reading from (must be correctly masked). + * @param NumByteToRead number of bytes to be read. + * @retval 0 if ok, + * @retval -1 if an I2C error has occured + * @note On some devices if NumByteToWrite is greater + * than one, the RegisterAddr must be masked correctly! + */ + int i2c_read(uint8_t* pBuffer, uint8_t DeviceAddr, uint8_t RegisterAddr, + uint16_t NumByteToRead) { + int ret; + + /* Send device address, with no STOP condition */ + ret = write(DeviceAddr, (const char*)&RegisterAddr, 1, true); + if(!ret) { + /* Read data, with STOP condition */ + ret = read(DeviceAddr, (char*)pBuffer, NumByteToRead, false); + } + + if(ret) return -1; + return 0; + } + +private: + static const unsigned int TEMP_BUF_SIZE = 32; +}; + +#endif /* __DEV_I2C_H */
diff -r 000000000000 -r 98c301bb7d1b X_NUCLEO_COMMON/DevSPI/DevSPI.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/X_NUCLEO_COMMON/DevSPI/DevSPI.h Tue Oct 03 12:21:11 2017 +0000 @@ -0,0 +1,302 @@ +/** + ****************************************************************************** + * @file DevSPI.h + * @author AST / Software Platforms and Cloud / EST + * @version V1.2.1 + * @date 19-February-2016 + * @brief Header file for a special SPI class DevSPI which provides some + * helper functions for on-board communication. + ****************************************************************************** + * @attention + * + * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of STMicroelectronics nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************** + */ + +/* Define to prevent from recursive inclusion --------------------------------*/ +#ifndef __DEV_SPI_H +#define __DEV_SPI_H + +/* Includes ------------------------------------------------------------------*/ +#include "mbed.h" + +/* Macros --------------------------------------------------------------------*/ +#if (defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)) /* GCC */ || \ + (defined(G_BYTE_ORDER) && (G_BYTE_ORDER == G_BIG_ENDIAN)) /* IAR */ || \ + (defined(__BIG_ENDIAN)) /* ARM */ +#define __DEV_SPI_BIG_ENDIAN +#endif + +/* Classes -------------------------------------------------------------------*/ +/** Helper class DevSPI providing functions for synchronous SPI communication + * common for a series of SPI devices. + */ +class DevSPI : public SPI +{ + public: + /* + * Create a DevSPI interface. + * @param mosi pin name of the MOSI pin of the SPI device to be used for communication. + * @param miso pin name of the MISO pin of the SPI device to be used for communication. + * @param sclk pin name of the SCLK pin of the SPI device to be used for communication. + */ + DevSPI(PinName mosi, PinName miso, PinName sclk) : SPI(mosi, miso, sclk) + { + /* Set default configuration. */ + setup(8, 3, 1E6); + } + + /* + * Setup the spi. + * Typically: + * + 8 bit data; + * + high steady state clock; + * + second edge capture; + * + 1MHz clock rate. + * + * @param bits Number of bits per SPI frame (4 - 16) + * @param mode Clock polarity and phase mode (0 - 3) + * @param frequency_hz SCLK frequency in hz (default = 1MHz) + * + * @code + * mode | POL PHA + * -----+-------- + * 0 | 0 0 + * 1 | 0 1 + * 2 | 1 0 + * 3 | 1 1 + * @endcode + */ + void setup(int bits, int mode = 0, int frequency_hz = 1E6) + { + /* Set given configuration. */ + format(bits, mode); + frequency(frequency_hz); + } + + /** + * @brief Writes a buffer to the SPI peripheral device in 8-bit data mode + * using synchronous SPI communication. + * @param[in] pBuffer pointer to the buffer of data to send. + * @param[in] ssel GPIO of the SSEL pin of the SPI device to be used for communication. + * @param[in] NumBytesToWrite number of bytes to write. + * @retval 0 if ok. + * @retval -1 if data format error. + * @note When using the SPI in Interrupt-mode, remember to disable interrupts + * before calling this function and to enable them again after. + */ + int spi_write(uint8_t* pBuffer, DigitalOut &ssel, uint16_t NumBytesToWrite) + { + /* Check data format */ + if(_bits != 8) return -1; + + /* Select the chip. */ + ssel = 0; + + /* Write data. */ + for (int i = 0; i < NumBytesToWrite; i++) { + write(pBuffer[i]); + } + + /* Unselect the chip. */ + ssel = 1; + + return 0; + } + + /** + * @brief Reads a buffer from the SPI peripheral device in 8-bit data mode + * using synchronous SPI communication. + * @param[out] pBuffer pointer to the buffer to read data into. + * @param[in] ssel GPIO of the SSEL pin of the SPI device to be used for communication. + * @param[in] NumBytesToRead number of bytes to read. + * @retval 0 if ok. + * @retval -1 if data format error. + * @note When using the SPI in Interrupt-mode, remember to disable interrupts + * before calling this function and to enable them again after. + */ + int spi_read(uint8_t* pBuffer, DigitalOut &ssel, uint16_t NumBytesToRead) + { + /* Check data format */ + if(_bits != 8) return -1; + + /* Select the chip. */ + ssel = 0; + + /* Read data. */ + for (int i = 0; i < NumBytesToRead; i++) { + pBuffer[i] = write(0); + } + + /* Unselect the chip. */ + ssel = 1; + + return 0; + } + + /** + * @brief Reads and write a buffer from/to the SPI peripheral device at the same time + * in 8-bit data mode using synchronous SPI communication. + * @param[out] pBufferToRead pointer to the buffer to read data into. + * @param[in] pBufferToWrite pointer to the buffer of data to send. + * @param[in] ssel GPIO of the SSEL pin of the SPI device to be used for communication. + * @param[in] NumBytes number of bytes to read and write. + * @retval 0 if ok. + * @retval -1 if data format error. + * @note When using the SPI in Interrupt-mode, remember to disable interrupts + * before calling this function and to enable them again after. + */ + int spi_read_write(uint8_t* pBufferToRead, uint8_t* pBufferToWrite, DigitalOut &ssel, uint16_t NumBytes) + { + /* Check data format */ + if(_bits != 8) return -1; + + /* Select the chip. */ + ssel = 0; + + /* Read and write data at the same time. */ + for (int i = 0; i < NumBytes; i++) { + pBufferToRead[i] = write(pBufferToWrite[i]); + } + + /* Unselect the chip. */ + ssel = 1; + + return 0; + } + + /** + * @brief Writes a buffer to the SPI peripheral device in 16-bit data mode + * using synchronous SPI communication. + * @param[in] pBuffer pointer to the buffer of data to send. + * @param[in] ssel GPIO of the SSEL pin of the SPI device to be used for communication. + * @param[in] NumValuesToWrite number of 16-bit values to write. + * @retval 0 if ok. + * @retval -1 if data format error. + * @note When using the SPI in Interrupt-mode, remember to disable interrupts + * before calling this function and to enable them again after. + * @note In order to guarantee this method to work correctly you have to + * pass buffers which are correctly aligned. + */ + int spi_write(uint16_t* pBuffer, DigitalOut &ssel, uint16_t NumValuesToWrite) + { + /* Check data format */ + if(_bits != 16) return -1; + + /* Select the chip. */ + ssel = 0; + + /* Write data. */ + for (int i = 0; i < NumValuesToWrite; i++) { + write(htons(pBuffer[i])); + } + + /* Unselect the chip. */ + ssel = 1; + + return 0; + } + + /** + * @brief Reads a buffer from the SPI peripheral device in 16-bit data mode + * using synchronous SPI communication. + * @param[out] pBuffer pointer to the buffer to read data into. + * @param[in] ssel GPIO of the SSEL pin of the SPI device to be used for communication. + * @param[in] NumValuesToRead number of 16-bit values to read. + * @retval 0 if ok. + * @retval -1 if data format error. + * @note When using the SPI in Interrupt-mode, remember to disable interrupts + * before calling this function and to enable them again after. + * @note In order to guarantee this method to work correctly you have to + * pass buffers which are correctly aligned. + */ + int spi_read(uint16_t* pBuffer, DigitalOut &ssel, uint16_t NumValuesToRead) + { + /* Check data format */ + if(_bits != 16) return -1; + + /* Select the chip. */ + ssel = 0; + + /* Read data. */ + for (int i = 0; i < NumValuesToRead; i++) { + pBuffer[i] = ntohs((uint16_t)write(0)); + } + + /* Unselect the chip. */ + ssel = 1; + + return 0; + } + + /** + * @brief Reads and write a buffer from/to the SPI peripheral device at the same time + * in 16-bit data mode using synchronous SPI communication. + * @param[out] pBufferToRead pointer to the buffer to read data into. + * @param[in] pBufferToWrite pointer to the buffer of data to send. + * @param[in] ssel GPIO of the SSEL pin of the SPI device to be used for communication. + * @param[in] NumValues number of 16-bit values to read and write. + * @retval 0 if ok. + * @retval -1 if data format error. + * @note When using the SPI in Interrupt-mode, remember to disable interrupts + * before calling this function and to enable them again after. + * @note In order to guarantee this method to work correctly you have to + * pass buffers which are correctly aligned. + */ + int spi_read_write(uint16_t* pBufferToRead, uint16_t* pBufferToWrite, DigitalOut &ssel, uint16_t NumValues) + { + /* Check data format */ + if(_bits != 16) return -1; + + /* Select the chip. */ + ssel = 0; + + /* Read and write data at the same time. */ + for (int i = 0; i < NumValues; i++) { + pBufferToRead[i] = ntohs((uint16_t)write(htons(pBufferToWrite[i]))); + } + + /* Unselect the chip. */ + ssel = 1; + + return 0; + } + +protected: + inline uint16_t htons(uint16_t x) { +#ifndef __DEV_SPI_BIG_ENDIAN + return (((x)<<8)|((x)>>8)); +#else // __DEV_SPI_BIG_ENDIAN + return (x); +#endif // __DEV_SPI_BIG_ENDIAN + } + + inline uint16_t ntohs(uint16_t x) { + return htons(x); + } +}; + +#endif /* __DEV_SPI_H */
diff -r 000000000000 -r 98c301bb7d1b x_nucleo_iks01a2_targets.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/x_nucleo_iks01a2_targets.h Tue Oct 03 12:21:11 2017 +0000 @@ -0,0 +1,54 @@ +/** + ****************************************************************************** + * @file x_nucleo_iks01a2_targets.h + * @author CLab + * @version V1.0.0 + * @date 9-August-2016 + * @brief This header file is intended to manage the differences between + * the different supported base-boards which might mount the + * X_NUCLEO_IKS01A2 MEMS Inertial & Environmental Nucleo Expansion Board. + ****************************************************************************** + * @attention + * + * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of STMicroelectronics nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************** + */ + +/* Define to prevent from recursive inclusion --------------------------------*/ +#ifndef _X_NUCLEO_IKS01A2_TARGETS_H_ +#define _X_NUCLEO_IKS01A2_TARGETS_H_ + +/*** I2C ***/ +/* Use Arduino I2C Connectors */ +#define IKS01A2_PIN_I2C_SDA (D14) +#define IKS01A2_PIN_I2C_SCL (D15) + +/* LSM6DSL INT1 */ +#define IKS01A2_PIN_LSM6DSL_INT1 (D4) +/* LSM6DSL INT2 */ +#define IKS01A2_PIN_LSM6DSL_INT2 (D5) + +#endif // _X_NUCLEO_IKS01A2_TARGETS_H_