LPS22HB_lib.zip
(17.32 KB, 售价: 1 E币)
部分代码
- /* 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 Sensor_IO_Write( void *handle, uint8_t WriteAddr, uint8_t *pBuffer, uint16_t nBytesToWrite );
- extern uint8_t Sensor_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_ReadReg
- * 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_ReadReg( void *handle, uint8_t RegAddr, uint16_t NumByteToRead, uint8_t *Data )
- {
- if ( Sensor_IO_Read( handle, RegAddr, Data, NumByteToRead ) )
- return LPS22HB_ERROR;
- else
- return LPS22HB_OK;
- }
- /*******************************************************************************
- * Function Name : LPS22HB_WriteReg
- * 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_WriteReg( void *handle, uint8_t RegAddr, uint16_t NumByteToWrite, uint8_t *Data )
- {
- if ( Sensor_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_ReadReg(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_ReadReg(handle, LPS22HB_RES_CONF_REG, 1, &tmp))
- return LPS22HB_ERROR;
- tmp &= ~LPS22HB_LCEN_MASK;
- tmp |= (uint8_t)mode;
- if(LPS22HB_WriteReg(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_ReadReg(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_ReadReg(handle, LPS22HB_CTRL_REG1, 1, &tmp))
- return LPS22HB_ERROR;
- tmp &= ~LPS22HB_ODR_MASK;
- tmp |= (uint8_t)odr;
- if(LPS22HB_WriteReg(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_ReadReg(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_ReadReg(handle, LPS22HB_CTRL_REG1, 1, &tmp))
- return LPS22HB_ERROR;
- tmp &= ~LPS22HB_LPFP_MASK;
- tmp |= ((uint8_t)state)<<LPS22HB_LPFP_BIT;
- if(LPS22HB_WriteReg(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_ReadReg(handle, LPS22HB_CTRL_REG1, 1, &tmp))
- return LPS22HB_ERROR;
- tmp &= ~LPS22HB_LPFP_CUTOFF_MASK;
- tmp |= (uint8_t)cutoff;
- if(LPS22HB_WriteReg(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 ??
- * @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_ReadReg(handle, LPS22HB_CTRL_REG1, 1, &tmp))
- return LPS22HB_ERROR;
- tmp &= ~LPS22HB_BDU_MASK;
- tmp |= ((uint8_t)bdu);
- if(LPS22HB_WriteReg(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_ReadReg(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));
- ……………………
- …………限于本文篇幅 余下代码请下载附件…………
复制代码
【必读】版权免责声明
1、本主题所有言论和内容纯属会员个人意见,与本论坛立场无关。2、本站对所发内容真实性、客观性、可用性不做任何保证也不负任何责任,网友之间仅出于学习目的进行交流。3、对提供的数字内容不拥有任何权利,其版权归原著者拥有。请勿将该数字内容进行商业交易、转载等行为,该内容只为学习所提供,使用后发生的一切问题与本站无关。 4、本网站不保证本站提供的下载资源的准确性、安全性和完整性;同时本网站也不承担用户因使用这些下载资源对自己和他人造成任何形式的损失或伤害。 5、本网站所有软件和资料均为网友推荐收集整理而来,仅供学习用途使用,请务必下载后两小时内删除,禁止商用。6、如有侵犯你版权的,请及时联系我们(电子邮箱1370723259@qq.com)指出,本站将立即改正。
|
|