12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565 |
- /**
- ******************************************************************************
- * @file lps25hb.c
- * @author HESA Application Team
- * @version 1.0.0
- * @date 07/04/2014
- * @brief LPS25HB driver file
- * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
- * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
- * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
- * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
- * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
- * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
- *
- * THIS SOURCE CODE IS PROTECTED BY A LICENSE.
- * FOR MORE INFORMATION PLEASE CAREFULLY READ THE LICENSE AGREEMENT FILE LOCATED
- * IN THE ROOT DIRECTORY OF THIS FIRMWARE PACKAGE.
- *
- * <h2><center>© COPYRIGHT 2013 STMicroelectronics</center></h2>
- ******************************************************************************
- */
- /* Includes ------------------------------------------------------------------*/
- #include "hal/lps25hb.h"
- #include "driver/i2c_master.h"
- #ifdef USE_FULL_ASSERT_LPS25HB
- #include <stdio.h>
- #endif
- /** @addtogroup Environmental_Sensor
- * @{
- */
- /** @defgroup LPS25HB_DRIVER
- * @brief LPS25HB DRIVER
- * @{
- */
- #define LPS25HB_WRITE_ADDRESS 0xB8
- #define LPS25HB_READ_ADDRESS 0xB9
- uint8_t ICACHE_FLASH_ATTR Sensor_IO_Write(uint8_t WriteAddr, uint16_t nBytesToWrite, uint8_t *pBuffer)
- {
- uint16_t i;
- i2c_master_init();
- // write device address
- i2c_master_start();
- i2c_master_writeByte(LPS25HB_WRITE_ADDRESS);
- if (!i2c_master_checkAck()) {
- i2c_master_stop();
- return 1;
- }
- // write initial address for reg to be written to
- i2c_master_writeByte(WriteAddr);
- if (!i2c_master_checkAck()) {
- i2c_master_stop();
- return 1;
- }
- // write bytes
- for (i=0; i<(nBytesToWrite); i++) {
- i2c_master_writeByte(pBuffer[i]);
- if (!i2c_master_checkAck()) {
- i2c_master_stop();
- return 1;
- }
- }
- i2c_master_stop();
- return 0;
- // enable LSM6DS3 for SPI communication
- //lsm6ds3_i2c_short(false);
- }
- uint8_t ICACHE_FLASH_ATTR Sensor_IO_Read(uint8_t ReadAddr, uint16_t nBytesToRead, uint8_t *pBuffer)
- {
- uint16_t i;
- i2c_master_init();
- // enable LSM6DS3 for I2C communication
- //lsm6ds3_i2c_short(true);
- // open connection to devive to write
- i2c_master_start();
- i2c_master_writeByte(LPS25HB_WRITE_ADDRESS);
- if (!i2c_master_checkAck()) {
- i2c_master_stop();
- return 1;
- }
- // write read address
- i2c_master_writeByte(ReadAddr);
- if (!i2c_master_checkAck()) {
- i2c_master_stop();
- return 1;
- }
- // open connection to device to read
- i2c_master_start();
- i2c_master_writeByte(LPS25HB_READ_ADDRESS);
- if (!i2c_master_checkAck()) {
- i2c_master_stop();
- return 1;
- }
- // read bytes
- for (i=0; i<nBytesToRead; i++)
- {
- pBuffer[i] = i2c_master_readByte();
- //os_printf("Byte %x\r\n", pBuffer[i]);
- if (i == (nBytesToRead - 1))
- i2c_master_send_nack();
- else
- i2c_master_send_ack();
- }
- i2c_master_stop();
- // enable LSM6DS3 for SPI communication
- // lsm6ds3_i2c_short(false);
- return 0;
- }
- /** @defgroup LPS25HB_Public_Functions
- * @{
- */
- /**
- * @brief Read identification code by WHO_AM_I register
- * @param Buffer to empty by Device identification Value.
- * @retval Status [LPS25HB_ERROR, LPS25HB_OK]
- */
- LPS25HB_Error_et ICACHE_FLASH_ATTR LPS25HB_Get_DeviceID(uint8_t* deviceid)
- {
- if(LPS25HB_ReadReg(LPS25HB_WHO_AM_I_REG, 1, deviceid))
- return LPS25HB_ERROR;
- return LPS25HB_OK;
- }
- /**
- * @brief Get the LPS25HB driver version.
- * @param None
- * @retval Status [LPS25HB_ERROR, LPS25HB_OK]
- */
- LPS25HB_Error_et ICACHE_FLASH_ATTR LPS25HB_Get_DriverVersion(LPS25HB_DriverVersion_st *Version)
- {
- Version->Major = LPS25HB_DriverVersion_Major;
- Version->Minor = LPS25HB_DriverVersion_Minor;
- Version->Point = LPS25HB_DriverVersion_Point;
- return LPS25HB_OK;
- }
- /**
- * @brief Set LPS25HB Pressure and Temperature Resolution Mode
- * @param Pressure Resolution
- * @param Temperature Resolution
- * @retval Status [LPS25HB_ERROR, LPS25HB_OK]
- */
- LPS25HB_Error_et ICACHE_FLASH_ATTR LPS25HB_Set_Avg(LPS25HB_Avgp_et avgp,LPS25HB_Avgt_et avgt )
- {
- uint8_t tmp;
- LPS25HB_assert_param(IS_LPS25HB_AVGT(avgt));
- LPS25HB_assert_param(IS_LPS25HB_AVGP(avgp));
- if(LPS25HB_ReadReg(LPS25HB_RES_CONF_REG, 1, &tmp))
- return LPS25HB_ERROR;
- tmp &= ~(LPS25HB_AVGT_MASK | LPS25HB_AVGP_MASK);
- tmp |= (uint8_t)avgp;
- tmp |= (uint8_t)avgt;
- if(LPS25HB_WriteReg(LPS25HB_RES_CONF_REG, 1, &tmp) )
- return LPS25HB_ERROR;
- return LPS25HB_OK;
- }
- /**
- * @brief Exit the shutdown mode for LPS25HB.
- * @param None
- * @retval None
- */
- LPS25HB_Error_et ICACHE_FLASH_ATTR LPS25HB_Activate(void)
- {
- if(LPS25HB_Set_PowerDownMode(LPS25HB_SET))
- return LPS25HB_ERROR;
- return LPS25HB_OK;
- }
- /**
- * @brief Enter the shutdown mode for LPS25HB.
- * @param None
- * @retval None
- */
- LPS25HB_Error_et ICACHE_FLASH_ATTR LPS25HB_DeActivate(void)
- {
- if(LPS25HB_Set_PowerDownMode(LPS25HB_RESET))
- return LPS25HB_ERROR;
- return LPS25HB_OK;
- }
- /**
- * @brief Set LPS25HB Pressure Resolution Mode
- * @param Pressure Resolution
- * @retval Status [LPS25HB_ERROR, LPS25HB_OK]
- */
- LPS25HB_Error_et ICACHE_FLASH_ATTR LPS25HB_Set_AvgP(LPS25HB_Avgp_et avgp)
- {
- uint8_t tmp;
- LPS25HB_assert_param(IS_LPS25HB_AVGP(avgp));
- if(LPS25HB_ReadReg(LPS25HB_RES_CONF_REG, 1, &tmp))
- return LPS25HB_ERROR;
- tmp &= ~LPS25HB_AVGP_MASK;
- tmp |= (uint8_t)avgp;
- if(LPS25HB_WriteReg(LPS25HB_RES_CONF_REG, 1, &tmp))
- return LPS25HB_ERROR;
- return LPS25HB_OK;
- }
- /**
- * @brief Set LPS25HB Temperature Resolution Mode
- * @param Temperature Resolution
- * @retval Status [LPS25HB_ERROR, LPS25HB_OK]
- */
- LPS25HB_Error_et ICACHE_FLASH_ATTR LPS25HB_Set_AvgT(LPS25HB_Avgt_et avgt)
- {
- uint8_t tmp;
- LPS25HB_assert_param(IS_LPS25HB_AVGT(avgt));
- if(LPS25HB_ReadReg(LPS25HB_RES_CONF_REG, 1, &tmp))
- return LPS25HB_ERROR;
- tmp &= ~LPS25HB_AVGT_MASK;
- tmp |= (uint8_t)avgt;
- if(LPS25HB_WriteReg(LPS25HB_RES_CONF_REG, 1, &tmp))
- return LPS25HB_ERROR;
- return LPS25HB_OK;
- }
- /**
- * @brief Get LPS25HB Pressure Resolution Mode
- * @param Pressure Resolution
- * @retval Status [LPS25HB_ERROR, LPS25HB_OK]
- */
- LPS25HB_Error_et ICACHE_FLASH_ATTR LPS25HB_Get_AvgP(LPS25HB_Avgp_et* avgp)
- {
- uint8_t tmp;
- if(LPS25HB_ReadReg(LPS25HB_RES_CONF_REG, 1, &tmp))
- return LPS25HB_ERROR;
- *avgp = (LPS25HB_Avgp_et)(tmp & LPS25HB_AVGP_MASK);
- return LPS25HB_OK;
- }
- /**
- * @brief Get LPS25HB Temperature Resolution Mode
- * @param Temperature Resolution
- * @retval Status [LPS25HB_ERROR, LPS25HB_OK]
- */
- LPS25HB_Error_et ICACHE_FLASH_ATTR LPS25HB_Get_AvgT(LPS25HB_Avgt_et* avgt)
- {
- uint8_t tmp;
- if(LPS25HB_ReadReg(LPS25HB_RES_CONF_REG, 1, &tmp) )
- return LPS25HB_ERROR;
- *avgt = (LPS25HB_Avgt_et)(tmp & LPS25HB_AVGT_MASK);
- return LPS25HB_OK;
- }
- /**
- * @brief Set LPS25HB Output Data Rate
- * @param Output Data Rate
- * @retval Status [LPS25HB_ERROR, LPS25HB_OK]
- */
- LPS25HB_Error_et ICACHE_FLASH_ATTR LPS25HB_Set_Odr(LPS25HB_Odr_et odr)
- {
- uint8_t tmp;
- LPS25HB_assert_param(IS_LPS25HB_ODR(odr));
- if(LPS25HB_ReadReg(LPS25HB_CTRL_REG1, 1, &tmp))
- return LPS25HB_ERROR;
- tmp &= ~LPS25HB_ODR_MASK;
- tmp |= (uint8_t)odr;
- if(LPS25HB_WriteReg(LPS25HB_CTRL_REG1, 1, &tmp))
- return LPS25HB_ERROR;
- return LPS25HB_OK;
- }
- /**
- * @brief Get LPS25HB Output Data Rate
- * @param Buffer to empty with Output Data Rate
- * @retval Status [LPS25HB_ERROR, LPS25HB_OK]
- */
- LPS25HB_Error_et ICACHE_FLASH_ATTR LPS25HB_Get_Odr(LPS25HB_Odr_et* odr)
- {
- uint8_t tmp;
- if(LPS25HB_ReadReg(LPS25HB_CTRL_REG1, 1, &tmp))
- return LPS25HB_ERROR;
- *odr = (LPS25HB_Odr_et)(tmp & LPS25HB_ODR_MASK);
- return LPS25HB_OK;
- }
- /**
- * @brief SET/RESET LPS25HB Power Down Mode bit
- * @param LPS25HB_SET (Active Mode)/LPS25HB_RESET (Power Down Mode)
- * @retval Status [LPS25HB_ERROR, LPS25HB_OK]
- */
- LPS25HB_Error_et ICACHE_FLASH_ATTR LPS25HB_Set_PowerDownMode(LPS25HB_BitStatus_et pd)
- {
- uint8_t tmp;
- LPS25HB_assert_param(IS_LPS25HB_BitStatus(pd));
- if(LPS25HB_ReadReg(LPS25HB_CTRL_REG1, 1, &tmp))
- return LPS25HB_ERROR;
- tmp &= ~LPS25HB_PD_MASK;
- tmp |= ((uint8_t)pd)<<LPS25HB_PD_BIT;
- if(LPS25HB_WriteReg(LPS25HB_CTRL_REG1, 1, &tmp))
- return LPS25HB_ERROR;
- return LPS25HB_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 LPS25HB_BDU_CONTINUOS_UPDATE, LPS25HB_BDU_NO_UPDATE
- * @retval Status [LPS25HB_ERROR, LPS25HB_OK]
- */
- LPS25HB_Error_et ICACHE_FLASH_ATTR LPS25HB_Set_Bdu(LPS25HB_Bdu_et bdu)
- {
- uint8_t tmp;
- LPS25HB_assert_param(IS_LPS25HB_BDUMode(bdu));
- if(LPS25HB_ReadReg(LPS25HB_CTRL_REG1, 1, &tmp))
- return LPS25HB_ERROR;
- tmp &= ~LPS25HB_BDU_MASK;
- tmp |= ((uint8_t)bdu);
- if(LPS25HB_WriteReg(LPS25HB_CTRL_REG1, 1, &tmp))
- return LPS25HB_ERROR;
- return LPS25HB_OK;
- }
- /**
- * @brief Get Block Data Mode
- * @param Buffer to empty whit thw bdu mode read from sensor
- * @retval Status [LPS25HB_ERROR, LPS25HB_OK]
- */
- LPS25HB_Error_et ICACHE_FLASH_ATTR LPS25HB_Get_Bdu(LPS25HB_Bdu_et* bdu)
- {
- uint8_t tmp;
- if(LPS25HB_ReadReg(LPS25HB_CTRL_REG1, 1, &tmp))
- return LPS25HB_ERROR;
- *bdu = (LPS25HB_Bdu_et)(tmp & LPS25HB_BDU_MASK);
- return LPS25HB_OK;
- }
- /**
- * @brief Enable/Disable Interrupt Circuit.
- * @param LPS25HB_ENABLE/LPS25HB_DISABLE
- * @retval Status [LPS25HB_ERROR, LPS25HB_OK]
- */
- LPS25HB_Error_et ICACHE_FLASH_ATTR LPS25HB_Set_InterruptCircuitEnable(LPS25HB_State_et diff_en)
- {
- uint8_t tmp;
- LPS25HB_assert_param(IS_LPS25HB_State(diff_en));
- if(LPS25HB_ReadReg(LPS25HB_CTRL_REG1, 1, &tmp))
- return LPS25HB_ERROR;
- tmp &= ~LPS25HB_DIFF_EN_MASK;
- tmp |= ((uint8_t)diff_en)<<LPS25HB_DIFF_EN_BIT;
- if(LPS25HB_WriteReg(LPS25HB_CTRL_REG1, 1, &tmp))
- return LPS25HB_ERROR;
- return LPS25HB_OK;
- }
- /**
- * @brief Get the Interrupt Circuit bit.
- * @param Buffer to empty whit thw diff_en mode read from sensor
- * @retval Status [LPS25HB_ERROR, LPS25HB_OK]
- */
- LPS25HB_Error_et ICACHE_FLASH_ATTR LPS25HB_Get_InterruptCircuitEnable(LPS25HB_State_et* diff_en)
- {
- uint8_t tmp;
- if(LPS25HB_ReadReg(LPS25HB_CTRL_REG1, 1, &tmp))
- return LPS25HB_ERROR;
- *diff_en= (LPS25HB_State_et)((tmp & LPS25HB_DIFF_EN_MASK)>>LPS25HB_DIFF_EN_BIT);
- return LPS25HB_OK;
- }
- /**
- * @brief Set ResetAutoZero Function bit
- * @details REF_P reg (@0x08..0A) set pressure reference to default tmp RPDS reg (0x39/3A).
- * @param None
- * @retval Status [LPS25HB_ERROR, LPS25HB_OK]
- */
- LPS25HB_Error_et ICACHE_FLASH_ATTR LPS25HB_ResetAZ(void)
- {
- uint8_t tmp;
- if(LPS25HB_ReadReg(LPS25HB_CTRL_REG1, 1, &tmp))
- return LPS25HB_ERROR;
- /* Set the RESET_AZ bit*/
- /* RESET_AZ is self cleared*/
- tmp |= LPS25HB_RESET_AZ_MASK;
- if(LPS25HB_WriteReg(LPS25HB_CTRL_REG1, 1, &tmp))
- return LPS25HB_ERROR;
- return LPS25HB_OK;
- }
- /**
- * @brief Set SPI mode: 3 Wire Interface or 4 Wire Interface
- * @param LPS25HB_SPI_3_WIRE, LPS25HB_SPI_4_WIRE
- * @retval Status [LPS25HB_ERROR, LPS25HB_OK]
- */
- LPS25HB_Error_et ICACHE_FLASH_ATTR LPS25HB_Set_SpiInterface(LPS25HB_SPIMode_et spimode)
- {
- uint8_t tmp;
- LPS25HB_assert_param(IS_LPS25HB_SPIMode(spimode));
- if(LPS25HB_ReadReg(LPS25HB_CTRL_REG1, 1, &tmp))
- return LPS25HB_ERROR;
- tmp &= ~LPS25HB_SIM_MASK;
- tmp |= (uint8_t)spimode;
- if(LPS25HB_WriteReg(LPS25HB_CTRL_REG1, 1, &tmp))
- return LPS25HB_ERROR;
- return LPS25HB_OK;
- }
- /**
- * @brief Get SPI mode: 3 Wire Interface or 4 Wire Interface
- * @param Buffer to empty with spi mode read from Sensor
- * @retval Status [LPS25HB_ERROR, LPS25HB_OK]
- */
- LPS25HB_Error_et ICACHE_FLASH_ATTR LPS25HB_Get_SpiInterface(LPS25HB_SPIMode_et* spimode)
- {
- uint8_t tmp;
- if(LPS25HB_ReadReg(LPS25HB_CTRL_REG1, 1, &tmp))
- return LPS25HB_ERROR;
- *spimode = (LPS25HB_SPIMode_et)(tmp & LPS25HB_SIM_MASK);
- return LPS25HB_OK;
- }
- /**
- * @brief Enable/Disable I2C Mode
- * @param State: Enable (reset bit)/ Disable (set bit)
- * @retval Status [LPS25HB_ERROR, LPS25HB_OK]
- */
- LPS25HB_Error_et ICACHE_FLASH_ATTR LPS25HB_Set_I2C(LPS25HB_State_et statei2c)
- {
- uint8_t tmp;
- LPS25HB_assert_param(IS_LPS25HB_State(statei2c));
- if(LPS25HB_ReadReg(LPS25HB_CTRL_REG2, 1, &tmp))
- return LPS25HB_ERROR;
- tmp &= ~LPS25HB_I2C_MASK;
- if(statei2c == LPS25HB_DISABLE) {
- tmp |= LPS25HB_I2C_MASK;
- }
- if(LPS25HB_WriteReg(LPS25HB_CTRL_REG2, 1, &tmp))
- return LPS25HB_ERROR;
- return LPS25HB_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 None
- * @retval Status [LPS25HB_ERROR, LPS25HB_OK]
- */
- LPS25HB_Error_et ICACHE_FLASH_ATTR LPS25HB_StartOneShotMeasurement(void)
- {
- uint8_t tmp;
- if(LPS25HB_ReadReg(LPS25HB_CTRL_REG2, 1, &tmp))
- return LPS25HB_ERROR;
- /* Set the one shot bit */
- /* Once the measurement is done, one shot bit will self-clear*/
- tmp |= LPS25HB_ONE_SHOT_MASK;
- if(LPS25HB_WriteReg(LPS25HB_CTRL_REG2, 1, &tmp))
- return LPS25HB_ERROR;
- return LPS25HB_OK;
- }
- /**
- * @brief Set AutoZero Function bit
- * @detail When set to �1�, the actual pressure output is copied in the REF_P reg (@0x08..0A)
- * @param LPS25HB_SET/LPS25HB_RESET
- * @retval Status [LPS25HB_ERROR, LPS25HB_OK]
- */
- LPS25HB_Error_et ICACHE_FLASH_ATTR LPS25HB_Set_AutoZeroFunction(LPS25HB_BitStatus_et autozero)
- {
- uint8_t tmp;
- LPS25HB_assert_param(IS_LPS25HB_BitStatus(autozero));
- if(LPS25HB_ReadReg(LPS25HB_CTRL_REG2, 1, &tmp))
- return LPS25HB_ERROR;
- tmp &= ~LPS25HB_AUTO_ZERO_MASK;
- tmp |= ((uint8_t)autozero)<<LPS25HB_AUTO_ZERO_BIT;
- if(LPS25HB_WriteReg(LPS25HB_CTRL_REG2, 1, &tmp))
- return LPS25HB_ERROR;
- return LPS25HB_OK;
- }
- /**
- * @brief Software Reset. Self-clearing upon completion
- * @param None
- * @retval Status [LPS25HB_ERROR, LPS25HB_OK]
- */
- LPS25HB_Error_et ICACHE_FLASH_ATTR LPS25HB_SwReset(void)
- {
- uint8_t tmp;
- if(LPS25HB_ReadReg(LPS25HB_CTRL_REG2, 1, &tmp))
- return LPS25HB_ERROR;
- tmp |= (0x01<<LPS25HB_SW_RESET_BIT);
- if(LPS25HB_WriteReg(LPS25HB_CTRL_REG2, 1, &tmp))
- return LPS25HB_ERROR;
- return LPS25HB_OK;
- }
- /**
- * @brief Reboot Memory Content
- * @param None
- * @retval Status [LPS25HB_ERROR, LPS25HB_OK]
- */
- LPS25HB_Error_et ICACHE_FLASH_ATTR LPS25HB_MemoryBoot(void)
- {
- uint8_t tmp;
- if(LPS25HB_ReadReg(LPS25HB_CTRL_REG2, 1, &tmp))
- return LPS25HB_ERROR;
- tmp |= (0x01<<LPS25HB_BOOT_BIT);
- if(LPS25HB_WriteReg(LPS25HB_CTRL_REG2, 1, &tmp))
- return LPS25HB_ERROR;
- return LPS25HB_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 None
- * @retval Status [LPS25HB_ERROR, LPS25HB_OK]
- */
- LPS25HB_Error_et ICACHE_FLASH_ATTR LPS25HB_SwResetAndMemoryBoot(void)
- {
- uint8_t tmp;
- if(LPS25HB_ReadReg(LPS25HB_CTRL_REG2, 1, &tmp))
- return LPS25HB_ERROR;
- tmp |= ((0x01<<LPS25HB_SW_RESET_BIT) | (0x01<<LPS25HB_BOOT_BIT));
- if(LPS25HB_WriteReg(LPS25HB_CTRL_REG2, 1, &tmp))
- return LPS25HB_ERROR;
- return LPS25HB_OK;
- }
- /**
- * @brief Enable/Disable FIFO Mode
- * @param LPS25HB_ENABLE/LPS25HB_DISABLE
- * @retval Status [LPS25HB_ERROR, LPS25HB_OK]
- */
- LPS25HB_Error_et ICACHE_FLASH_ATTR LPS25HB_Set_FifoModeUse(LPS25HB_State_et status)
- {
- uint8_t tmp;
- LPS25HB_assert_param(IS_LPS25HB_State(status));
- if(LPS25HB_ReadReg(LPS25HB_CTRL_REG2, 1, &tmp))
- return LPS25HB_ERROR;
- tmp &= ~LPS25HB_FIFO_EN_MASK;
- tmp |= ((uint8_t)status)<<LPS25HB_FIFO_EN_BIT;
- if(LPS25HB_WriteReg(LPS25HB_CTRL_REG2, 1, &tmp))
- return LPS25HB_ERROR;
- return LPS25HB_OK;
- }
- /**
- * @brief Enable/Disable FIFO Watermark Level Use
- * @param LPS25HB_ENABLE/LPS25HB_DISABLE
- * @retval Status [LPS25HB_ERROR, LPS25HB_OK]
- */
- LPS25HB_Error_et ICACHE_FLASH_ATTR LPS25HB_Set_FifoWatermarkLevelUse(LPS25HB_State_et status)
- {
- uint8_t tmp;
- LPS25HB_assert_param(IS_LPS25HB_State(status));
- if(LPS25HB_ReadReg(LPS25HB_CTRL_REG2, 1, &tmp))
- return LPS25HB_ERROR;
- tmp &= ~LPS25HB_WTM_EN_MASK;
- tmp |= ((uint8_t)status)<<LPS25HB_WTM_EN_BIT;
- if(LPS25HB_WriteReg(LPS25HB_CTRL_REG2, 1, &tmp))
- return LPS25HB_ERROR;
- return LPS25HB_OK;
- }
- /**
- * @brief Enable/Disable 1 HZ ODR Decimation
- * @param LPS25HB_ENABLE/LPS25HB_DISABLE
- * @retval Status [LPS25HB_ERROR, LPS25HB_OK]
- */
- LPS25HB_Error_et ICACHE_FLASH_ATTR LPS25HB_Set_FifoMeanDecUse(LPS25HB_State_et status)
- {
- uint8_t tmp;
- LPS25HB_assert_param(IS_LPS25HB_State(status));
- if(LPS25HB_ReadReg(LPS25HB_CTRL_REG2, 1, &tmp))
- return LPS25HB_ERROR;
- tmp &= ~LPS25HB_FIFO_MEAN_MASK;
- tmp |= ((uint8_t)status)<<LPS25HB_FIFO_MEAN_BIT;
- if(LPS25HB_WriteReg(LPS25HB_CTRL_REG2, 1, &tmp))
- return LPS25HB_ERROR;
- return LPS25HB_OK;
- }
- /**
- * @brief Enable/Disable Interrupt Active High (default tmp 0) or Low(tmp 1)
- * @param LPS25HB_ENABLE/LPS25HB_DISABLE
- * @retval Status [LPS25HB_ERROR, LPS25HB_OK]
- */
- LPS25HB_Error_et ICACHE_FLASH_ATTR LPS25HB_Set_InterruptActiveLevel(LPS25HB_State_et status)
- {
- uint8_t tmp;
- LPS25HB_assert_param(IS_LPS25HB_State(status));
- if(LPS25HB_ReadReg(LPS25HB_CTRL_REG3, 1, &tmp))
- return LPS25HB_ERROR;
- tmp &= ~LPS25HB_INT_H_L_MASK;
- tmp |= ((uint8_t)status)<<LPS25HB_INT_H_L_BIT;
- if(LPS25HB_WriteReg(LPS25HB_CTRL_REG3, 1, &tmp))
- return LPS25HB_ERROR;
- return LPS25HB_OK;
- }
- /**
- * @brief Push-pull/open drain selection on interrupt pads. Default tmp: 0
- * @param LPS25HB_PushPull/LPS25HB_OpenDrain
- * @retval Status [LPS25HB_ERROR, LPS25HB_OK]
- */
- LPS25HB_Error_et ICACHE_FLASH_ATTR LPS25HB_Set_InterruptOutputType(LPS25HB_OutputType_et output)
- {
- uint8_t tmp;
- LPS25HB_assert_param(IS_LPS25HB_OutputType(output));
- if(LPS25HB_ReadReg(LPS25HB_CTRL_REG3, 1, &tmp))
- return LPS25HB_ERROR;
- tmp &= ~LPS25HB_PP_OD_MASK;
- tmp |= (uint8_t)output;
- if(LPS25HB_WriteReg(LPS25HB_CTRL_REG3, 1, &tmp))
- return LPS25HB_ERROR;
- return LPS25HB_OK;
- }
- /**
- * @brief Set Data signal on INT1 pad control bits. Default tmp: 00
- * @param LPS25HB_DATA,LPS25HB_P_HIGH_LPS25HB_P_LOW,LPS25HB_P_LOW_HIGH
- * @retval Status [LPS25HB_ERROR, LPS25HB_OK]
- */
- LPS25HB_Error_et ICACHE_FLASH_ATTR LPS25HB_Set_InterruptControlConfig(LPS25HB_OutputSignalConfig_et config)
- {
- uint8_t tmp;
- LPS25HB_assert_param(IS_LPS25HB_OutputSignal(config));
- if(LPS25HB_ReadReg(LPS25HB_CTRL_REG3, 1, &tmp))
- return LPS25HB_ERROR;
- tmp &= ~(LPS25HB_INT1_S2_MASK | LPS25HB_INT1_S1_MASK);
- tmp |= (uint8_t)config;
- if(LPS25HB_WriteReg(LPS25HB_CTRL_REG3, 1, &tmp))
- return LPS25HB_ERROR;
- return LPS25HB_OK;
- }
- /**
- * @brief Set INT1 interrupt pins configuration
- * @param LPS25HB_EMPTY,LPS25HB_WTM,LPS25HB_OVR,LPS25HB_DATA_READY
- * @retval Status [LPS25HB_ERROR, LPS25HB_OK]
- */
- LPS25HB_Error_et ICACHE_FLASH_ATTR LPS25HB_Set_InterruptDataConfig(LPS25HB_DataSignalType_et signal)
- {
- uint8_t tmp;
- LPS25HB_assert_param(IS_LPS25HB_DataSignal(signal));
- if(LPS25HB_ReadReg(LPS25HB_CTRL_REG4, 1, &tmp))
- return LPS25HB_ERROR;
- tmp &= ~(LPS25HB_P1_EMPTY_MASK | LPS25HB_P1_WTM_MASK \
- | LPS25HB_P1_OVERRUN_MASK | LPS25HB_P1_DRDY_MASK );
- tmp |= (uint8_t)signal;
- if(LPS25HB_WriteReg(LPS25HB_CTRL_REG4, 1, &tmp))
- return LPS25HB_ERROR;
- return LPS25HB_OK;
- }
- /**
- * @brief Enable\Disable Interrupt Generation on differential pressure low and/or high event
- * @param LPS25HB_DISABLE_INT, LPS25HB_PHE,LPS25HB_PLE,LPS25HB_PLE_PHE
- * @retval Status [LPS25HB_ERROR, LPS25HB_OK]
- */
- LPS25HB_Error_et ICACHE_FLASH_ATTR LPS25HB_Set_InterruptDifferentialConfig(LPS25HB_InterruptDiffConfig_et config)
- {
- uint8_t tmp;
- LPS25HB_assert_param(IS_LPS25HB_InterruptDiff(config));
- if(LPS25HB_ReadReg(LPS25HB_INTERRUPT_CFG_REG, 1, &tmp))
- return LPS25HB_ERROR;
- tmp &= ~(LPS25HB_PL_E_MASK | LPS25HB_PH_E_MASK);
- tmp |= (uint8_t)config;
- if(config!=LPS25HB_DISABLE_INT){
- /* Enable DIFF_EN bit in CTRL_REG1 */
- if(LPS25HB_Set_InterruptCircuitEnable(LPS25HB_ENABLE))
- return LPS25HB_ERROR;
- }
- if(LPS25HB_WriteReg(LPS25HB_INTERRUPT_CFG_REG, 1, &tmp))
- return LPS25HB_ERROR;
- return LPS25HB_OK;
- }
- /**
- * @brief Enable/Disable Latch Interrupt request into INT_SOURCE register.
- * @param LPS25HB_ENABLE/LPS25HB_DISABLE
- * @retval Status [LPS25HB_ERROR, LPS25HB_OK]
- */
- LPS25HB_Error_et ICACHE_FLASH_ATTR LPS25HB_LatchInterruptRequest(LPS25HB_State_et status)
- {
- uint8_t tmp;
- LPS25HB_assert_param(IS_LPS25HB_State(status));
- if(LPS25HB_ReadReg(LPS25HB_INTERRUPT_CFG_REG, 1, &tmp))
- return LPS25HB_ERROR;
- tmp &= ~LPS25HB_LIR_MASK;
- tmp |= (((uint8_t)status)<<LPS25HB_LIR_BIT);
- if(LPS25HB_WriteReg(LPS25HB_INTERRUPT_CFG_REG, 1, &tmp))
- return LPS25HB_ERROR;
- return LPS25HB_OK;
- }
- /**
- * @brief Get the Interrupt Generation on differential pressure status event.
- * @detail The INT_SOURCE register is cleared by reading it.
- * @param Status Event Flag: PH,PL,IA
- * @retval Status [LPS25HB_ERROR, LPS25HB_OK]
- */
- LPS25HB_Error_et ICACHE_FLASH_ATTR LPS25HB_Get_InterruptDifferentialEventStatus(LPS25HB_InterruptDiffStatus_st* interruptsource)
- {
- uint8_t tmp;
- if(LPS25HB_ReadReg(LPS25HB_INTERRUPT_SOURCE_REG, 1, &tmp))
- return LPS25HB_ERROR;
- interruptsource->PH = (uint8_t)(tmp & LPS25HB_PH_MASK);
- interruptsource->PL = (uint8_t)((tmp & LPS25HB_PL_MASK)>>LPS25HB_PL_BIT);
- interruptsource->IA = (uint8_t)((tmp & LPS25HB_IA_MASK)>>LPS25HB_IA_BIT);
- return LPS25HB_OK;
- }
- /**
- * @brief Get the status of Pressure and Temperature data
- * @param Data Status Flag: TempDataAvailable, TempDataOverrun, PressDataAvailable, PressDataOverrun
- * @retval Status [LPS25HB_ERROR, LPS25HB_OK]
- */
- LPS25HB_Error_et ICACHE_FLASH_ATTR LPS25HB_Get_DataStatus(LPS25HB_DataStatus_st* datastatus)
- {
- uint8_t tmp;
- if(LPS25HB_ReadReg(LPS25HB_STATUS_REG, 1, &tmp))
- return LPS25HB_ERROR;
- datastatus->TempDataAvailable = (tmp & LPS25HB_TDA_MASK);
- datastatus->PressDataAvailable = (uint8_t)((tmp & LPS25HB_PDA_MASK)>>LPS25HB_PDA_BIT);
- datastatus->TempDataOverrun = (uint8_t)((tmp & LPS25HB_TOR_MASK)>>LPS25HB_TOR_BIT);
- datastatus->PressDataOverrun = (uint8_t)((tmp & LPS25HB_POR_MASK)>>LPS25HB_POR_BIT);
- return LPS25HB_OK;
- }
- /**
- * @brief Get the raw pressure tmp
- * @detail The data are expressed as PRESS_OUT_H/_L/_XL in 2�s complement.
- Pout(hPA)=PRESS_OUT / 4096
- * @param The buffer to empty with the pressure raw tmp
- * @retval Status [LPS25HB_ERROR, LPS25HB_OK]
- */
- LPS25HB_Error_et ICACHE_FLASH_ATTR LPS25HB_Get_RawPressure(int32_t *raw_press)
- {
- uint8_t buffer[3];
- uint32_t tmp = 0;
- uint8_t i;
- if(LPS25HB_ReadReg(LPS25HB_PRESS_OUT_XL_REG, 3, buffer))
- return LPS25HB_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 LPS25HB_OK;
- }
- /**
- * @brief Get the 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 The buffer to empty with the pressure value that must be divided by 100 to get the value in hPA
- * @retval Status [LPS25HB_ERROR, LPS25HB_OK]
- */
- LPS25HB_Error_et ICACHE_FLASH_ATTR LPS25HB_Get_Pressure(int32_t* Pout)
- {
- int32_t raw_press;
- if(LPS25HB_Get_RawPressure(&raw_press))
- return LPS25HB_ERROR;
- *Pout = (raw_press*100)/4096;
- return LPS25HB_OK;
- }
- /**
- * @brief Get the Raw Temperature tmp.
- * @detail Temperature data are expressed as TEMP_OUT_H&TEMP_OUT_L as 2�s complement number.
- Tout(degC)=42.5+ (TEMP_OUT/480)
- * @param Buffer to empty with the temperature raw tmp.
- * @retval Status [LPS25HB_ERROR, LPS25HB_OK]
- */
- LPS25HB_Error_et ICACHE_FLASH_ATTR LPS25HB_Get_RawTemperature(int16_t* raw_data)
- {
- uint8_t buffer[2];
- uint16_t tmp;
- if(LPS25HB_ReadReg(LPS25HB_TEMP_OUT_L_REG, 2, buffer))
- return LPS25HB_ERROR;
- /* Build the raw tmp */
- tmp = (((uint16_t)buffer[1]) << 8) + (uint16_t)buffer[0];
- *raw_data = ((int16_t)tmp);
- return LPS25HB_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)=42.5+ (TEMP_OUT/480)
- * @param Buffer to empty with the temperature value that must be divided by 10 to get the value in �C
- * @retval Status [LPS25HB_ERROR, LPS25HB_OK]
- */
- LPS25HB_Error_et ICACHE_FLASH_ATTR LPS25HB_Get_Temperature(int16_t* Tout)
- {
- int16_t raw_data;
- if(LPS25HB_Get_RawTemperature(&raw_data))
- return LPS25HB_ERROR;
- *Tout = raw_data/48 + 425;
- return LPS25HB_OK;
- }
- /**
- * @brief Get the threshold tmp 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 Buffer to empty with the pressure threshold in hPA
- * @retval Status [LPS25HB_ERROR, LPS25HB_OK]
- */
- LPS25HB_Error_et ICACHE_FLASH_ATTR LPS25HB_Get_PressureThreshold(int16_t* P_ths)
- {
- uint8_t tempReg[2];
- if(LPS25HB_ReadReg(LPS25HB_THS_P_LOW_REG, 2, tempReg))
- return LPS25HB_ERROR;
- *P_ths= (((((uint16_t)tempReg[1])<<8) + tempReg[0])/16);
- return LPS25HB_OK;
- }
- /**
- * @brief Set the threshold tmp 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 Pressure threshold in hPA
- * @retval Status [LPS25HB_ERROR, LPS25HB_OK]
- */
- LPS25HB_Error_et ICACHE_FLASH_ATTR LPS25HB_Set_PressureThreshold(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(LPS25HB_WriteReg(LPS25HB_THS_P_LOW_REG, 2, buffer))
- return LPS25HB_ERROR;
- return LPS25HB_OK;
- }
- /**
- * @brief Set Fifo Mode
- * @param LPS25HB_FIFO_BYPASS_MODE, LPS25HB_FIFO_MODE, LPS25HB_FIFO_STREAM_MODE, LPS25HB_FIFO_TRIGGER_STREAMTOFIFO_MODE,
- LPS25HB_FIFO_TRIGGER_BYPASSTOSTREAM_MODE,LPS25HB_FIFO_MEAN_MODE, LPS25HB_FIFO_TRIGGER_BYPASSTOFIFO_MODE
- * @retval Status [LPS25HB_ERROR, LPS25HB_OK]
- */
- LPS25HB_Error_et ICACHE_FLASH_ATTR LPS25HB_Set_FifoMode(LPS25HB_FifoMode_et fifomode)
- {
- uint8_t tmp;
- LPS25HB_assert_param(IS_LPS25HB_FifoMode(fifomode));
- if(LPS25HB_ReadReg(LPS25HB_CTRL_FIFO_REG, 1, &tmp))
- return LPS25HB_ERROR;
- tmp &= ~LPS25HB_FMODE_MASK;
- tmp |= (uint8_t)fifomode;
- if(LPS25HB_WriteReg(LPS25HB_CTRL_FIFO_REG, 1, &tmp))
- return LPS25HB_ERROR;
- return LPS25HB_OK;
- }
- /**
- * @brief Get Fifo Mode
- * @param buffer to empty with fifo mode tmp
- * @retval Status [LPS25HB_ERROR, LPS25HB_OK]
- */
- LPS25HB_Error_et ICACHE_FLASH_ATTR LPS25HB_Get_FifoMode(LPS25HB_FifoMode_et* fifomode)
- {
- uint8_t tmp;
- if(LPS25HB_ReadReg(LPS25HB_CTRL_FIFO_REG, 1, &tmp))
- return LPS25HB_ERROR;
- tmp &= ~LPS25HB_WTM_POINT_MASK;
- *fifomode = (LPS25HB_FifoMode_et)tmp;
- return LPS25HB_OK;
- }
- /**
- * @brief Get the Fifo Status
- * @param Status Flag: FIFO_WTM,FIFO_EMPTY,FIFO_FULL,FIFO_LEVEL
- * @retval Status [LPS25HB_ERROR, LPS25HB_OK]
- */
- LPS25HB_Error_et ICACHE_FLASH_ATTR LPS25HB_Get_FifoStatus(LPS25HB_FifoStatus_st* status)
- {
- uint8_t tmp;
- if(LPS25HB_ReadReg(LPS25HB_STATUS_FIFO_REG, 1, &tmp))
- return LPS25HB_ERROR;
- status->FIFO_WTM = (uint8_t)((tmp & LPS25HB_WTM_FIFO_MASK)>>LPS25HB_WTM_FIFO_BIT);
- status->FIFO_FULL = (uint8_t)((tmp & LPS25HB_FULL_FIFO_MASK)>>LPS25HB_FULL_FIFO_BIT);
- status->FIFO_EMPTY = (uint8_t)((tmp & LPS25HB_EMPTY_FIFO_MASK)>>LPS25HB_EMPTY_FIFO_BIT);
- status->FIFO_LEVEL = (uint8_t)(tmp & LPS25HB_DIFF_POINT_MASK);
- return LPS25HB_OK;
- }
- /**
- * @brief Set Watermark Value
- * @param wtmlevel = [0,31]
- * @retval Status [LPS25HB_ERROR, LPS25HB_OK]
- */
- LPS25HB_Error_et ICACHE_FLASH_ATTR LPS25HB_Set_FifoWatermarkLevel(uint8_t wtmlevel)
- {
- uint8_t tmp;
- LPS25HB_assert_param(IS_LPS25HB_WtmLevel(wtmlevel));
- if(LPS25HB_ReadReg(LPS25HB_CTRL_FIFO_REG, 1, &tmp))
- return LPS25HB_ERROR;
- tmp &= ~LPS25HB_WTM_POINT_MASK;
- tmp |= wtmlevel;
- if(LPS25HB_WriteReg(LPS25HB_CTRL_FIFO_REG, 1, &tmp))
- return LPS25HB_ERROR;
- return LPS25HB_OK;
- }
- /**
- * @brief Get Watermark Value
- * @param wtmlevel tmp read from sensor
- * @retval Status [LPS25HB_ERROR, LPS25HB_OK]
- */
- LPS25HB_Error_et ICACHE_FLASH_ATTR LPS25HB_Get_FifoWatermarkLevel(uint8_t *wtmlevel)
- {
- if(LPS25HB_ReadReg(LPS25HB_CTRL_FIFO_REG, 1, wtmlevel))
- return LPS25HB_ERROR;
- *wtmlevel &= LPS25HB_WTM_POINT_MASK;
- return LPS25HB_OK;
- }
- /**
- * @brief Set the number of sample to perform moving average when FIFO_MEAN_MODE is used
- * @param LPS25HB_FIFO_SAMPLE_2,LPS25HB_FIFO_SAMPLE_4,LPS25HB_FIFO_SAMPLE_8,LPS25HB_FIFO_SAMPLE_16,LPS25HB_FIFO_SAMPLE_32
- * @retval Status [LPS25HB_ERROR, LPS25HB_OK]
- */
- LPS25HB_Error_et ICACHE_FLASH_ATTR LPS25HB_Set_FifoSampleSize(LPS25HB_FifoMeanModeSample_et samplesize)
- {
- uint8_t tmp;
- LPS25HB_assert_param(IS_LPS25HB_FifoMeanModeSample(samplesize));
- if(LPS25HB_ReadReg(LPS25HB_CTRL_FIFO_REG, 1, &tmp))
- return LPS25HB_ERROR;
- tmp &= ~LPS25HB_WTM_POINT_MASK;
- tmp |= (uint8_t)samplesize;
- if(LPS25HB_WriteReg(LPS25HB_CTRL_FIFO_REG, 1, &tmp))
- return LPS25HB_ERROR;
- return LPS25HB_OK;
- }
- /**
- * @brief Get the number of sample to perform moving average when FIFO_MEAN_MODE is used
- * @param buffer to empty with sample size tmp
- * @retval Status [LPS25HB_ERROR, LPS25HB_OK]
- */
- LPS25HB_Error_et ICACHE_FLASH_ATTR LPS25HB_Get_FifoSampleSize(LPS25HB_FifoMeanModeSample_et* samplesize)
- {
- uint8_t tmp;
- if(LPS25HB_ReadReg(LPS25HB_CTRL_FIFO_REG, 1, &tmp))
- return LPS25HB_ERROR;
- tmp &= LPS25HB_WTM_POINT_MASK;
- *samplesize = (LPS25HB_FifoMeanModeSample_et)tmp;
- return LPS25HB_OK;
- }
- /**
- * @brief Get the reference pressure after soldering for computing differential pressure (hPA)
- * @param buffer to empty with the he pressure tmp (hPA)
- * @retval Status [LPS25HB_ERROR, LPS25HB_OK]
- */
- LPS25HB_Error_et ICACHE_FLASH_ATTR LPS25HB_Get_PressureOffsetValue(int16_t *pressoffset)
- {
- uint8_t buffer[2];
- int16_t raw_press;
- if(LPS25HB_ReadReg(LPS25HB_RPDS_L_REG, 2, buffer))
- return LPS25HB_ERROR;
- raw_press = (int16_t)((((uint16_t)buffer[1]) << 8) + (uint16_t)buffer[0]);
- *pressoffset = (raw_press*100)/4096;
- return LPS25HB_OK;
- }
- /**
- * @brief Set Generic Configuration
- * @param Struct to empty with the chosen tmp
- * @retval Status [LPS25HB_ERROR, LPS25HB_OK]
- */
- LPS25HB_Error_et ICACHE_FLASH_ATTR LPS25HB_Set_GenericConfig(LPS25HB_ConfigTypeDef_st* pxLPS25HBInit)
- {
- /* Step 1. Init REF_P register*/
- /* The REF_P is the Reference Pressure. Its reset tmp is 0x00*/
- /* The REF_P will be set to the defualt RPDS (0x39h) tmp if Reset_AZ is enabled.*/
- /* The REF_P will be set the actual pressure output if AutoZero is enabled*/
- if((pxLPS25HBInit->Reset_AZ)==LPS25HB_ENABLE){
- if(LPS25HB_ResetAZ())
- return LPS25HB_ERROR;
- }
- else if((pxLPS25HBInit->AutoZero)==LPS25HB_ENABLE){
- if(LPS25HB_Set_AutoZeroFunction(LPS25HB_SET))
- return LPS25HB_ERROR;
- }
- /* Step 2. Init the Pressure and Temperature Resolution*/
- if(LPS25HB_Set_Avg(pxLPS25HBInit->PressResolution,pxLPS25HBInit->TempResolution))
- return LPS25HB_ERROR;
- /* Step 3. Init the Output Data Rate*/
- if(LPS25HB_Set_Odr(pxLPS25HBInit->OutputDataRate))
- return LPS25HB_ERROR;
- /*Step 4. 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(LPS25HB_Set_Bdu(pxLPS25HBInit->BDU))
- return LPS25HB_ERROR;
- /*Step 5. SIM bit selects the SPI serial interface mode.*/
- /* This feature has effect only if SPI interface is used*/
- if(LPS25HB_Set_SpiInterface(pxLPS25HBInit->Sim))
- return LPS25HB_ERROR;
- return LPS25HB_OK;
- }
- /**
- * @brief Get Generic Configuration
- * @param Struct to empty with the tmp read from sensor
- * @retval Status [LPS25HB_ERROR, LPS25HB_OK]
- */
- LPS25HB_Error_et ICACHE_FLASH_ATTR LPS25HB_Get_GenericConfig(LPS25HB_ConfigTypeDef_st* pxLPS25HBInit)
- {
- uint8_t tmp;
- if(LPS25HB_ReadReg(LPS25HB_RES_CONF_REG, 1, &tmp))
- return LPS25HB_ERROR;
- pxLPS25HBInit->PressResolution=(LPS25HB_Avgp_et)(tmp&LPS25HB_AVGP_MASK);
- pxLPS25HBInit->TempResolution=(LPS25HB_Avgt_et)(tmp& LPS25HB_AVGT_MASK);
- if(LPS25HB_ReadReg(LPS25HB_CTRL_REG1, 1, &tmp))
- return LPS25HB_ERROR;
- pxLPS25HBInit->OutputDataRate= (LPS25HB_Odr_et)(tmp & LPS25HB_ODR_MASK);
- pxLPS25HBInit->BDU=(LPS25HB_Bdu_et)(tmp & LPS25HB_BDU_MASK);
- pxLPS25HBInit->Sim=(LPS25HB_SPIMode_et)(tmp& LPS25HB_SIM_MASK);
- if(LPS25HB_ReadReg(LPS25HB_CTRL_REG2, 1, &tmp))
- return LPS25HB_ERROR;
- pxLPS25HBInit->AutoZero=(LPS25HB_State_et)((tmp&LPS25HB_RESET_AZ_MASK)>>LPS25HB_AUTO_ZERO_BIT);
- return LPS25HB_OK;
- }
- /**
- * @brief Set Interrupt Configuration
- * @param Struct to empty with the chosen tmp
- * @retval Status [LPS25HB_ERROR, LPS25HB_OK]
- */
- LPS25HB_Error_et ICACHE_FLASH_ATTR LPS25HB_Set_InterruptConfig(LPS25HB_InterruptTypeDef_st* pLPS25HBInt)
- {
- if(LPS25HB_Set_InterruptActiveLevel(pLPS25HBInt->INT_H_L))
- return LPS25HB_ERROR;
- if(LPS25HB_Set_InterruptOutputType(pLPS25HBInt->PP_OD))
- return LPS25HB_ERROR;
- if(LPS25HB_Set_InterruptControlConfig(pLPS25HBInt->OutputSignal_INT1))
- return LPS25HB_ERROR;
- if(pLPS25HBInt->OutputSignal_INT1==LPS25HB_DATA){
- if(LPS25HB_Set_InterruptDataConfig(pLPS25HBInt->DataInterrupt_INT1))
- return LPS25HB_ERROR;
- }
- if(LPS25HB_LatchInterruptRequest(pLPS25HBInt->LatchIRQ))
- return LPS25HB_ERROR;
- if(LPS25HB_Set_PressureThreshold(pLPS25HBInt->fP_threshold))
- return LPS25HB_ERROR;
- /*DIFF_EN bit is used to enable the circuitry for the computing of differential pressure output.*/
- /*It is suggested to turn on the circuitry only after the configuration of REF_P_x and THS_P_x.*/
- if(LPS25HB_Set_InterruptDifferentialConfig(pLPS25HBInt->PressureInterrupt))
- return LPS25HB_ERROR;
- return LPS25HB_OK;
- }
- /**
- * @brief Get Interrupt Configuration
- * @param Struct to empty with the tmp read from sensor
- * @retval Status [LPS25HB_ERROR, LPS25HB_OK]
- */
- LPS25HB_Error_et ICACHE_FLASH_ATTR LPS25HB_Get_InterruptConfig(LPS25HB_InterruptTypeDef_st* pLPS25HBInt)
- {
- uint8_t tmp;
- if(LPS25HB_ReadReg(LPS25HB_CTRL_REG3, 1, &tmp))
- return LPS25HB_ERROR;
- pLPS25HBInt->INT_H_L=(LPS25HB_State_et)((tmp&LPS25HB_INT_H_L_MASK)>>LPS25HB_INT_H_L_BIT);
- pLPS25HBInt->PP_OD =(LPS25HB_OutputType_et)(tmp&LPS25HB_PP_OD_MASK);
- pLPS25HBInt->OutputSignal_INT1=(LPS25HB_OutputSignalConfig_et)((tmp&0x03));
- if(pLPS25HBInt->OutputSignal_INT1==LPS25HB_DATA){
- if(LPS25HB_ReadReg(LPS25HB_CTRL_REG4, 1, &tmp))
- return LPS25HB_ERROR;
- pLPS25HBInt->DataInterrupt_INT1=(LPS25HB_DataSignalType_et)(tmp &=0x0F);
- }
- if(LPS25HB_ReadReg(LPS25HB_INTERRUPT_CFG_REG, 1, &tmp))
- return LPS25HB_ERROR;
- pLPS25HBInt->LatchIRQ=(LPS25HB_State_et)((tmp &LPS25HB_LIR_MASK)>>LPS25HB_LIR_BIT);
- pLPS25HBInt->PressureInterrupt=(LPS25HB_InterruptDiffConfig_et)(tmp &LPS25HB_PE_MASK);
- if(LPS25HB_Get_PressureThreshold(&pLPS25HBInt->fP_threshold))
- return LPS25HB_ERROR;
- return LPS25HB_OK;
- }
- /**
- * @brief Set Fifo Configuration
- * @param Struct to empty with the chosen tmp
- * @retval Status [LPS25HB_ERROR, LPS25HB_OK]
- */
- LPS25HB_Error_et ICACHE_FLASH_ATTR LPS25HB_Set_FifoConfig(LPS25HB_FIFOTypeDef_st* pLPS25HBFIFO)
- {
- if(pLPS25HBFIFO->FIFO_MODE == LPS25HB_FIFO_BYPASS_MODE) {
- /* FIFO Disable-> FIFO_EN bit=0 in CTRL_REG2*/
- if(LPS25HB_Set_FifoModeUse(LPS25HB_DISABLE))
- return LPS25HB_ERROR;
- }
- else {
- /* FIFO Enable-> FIFO_EN bit=1 in CTRL_REG2*/
- if(LPS25HB_Set_FifoModeUse(LPS25HB_ENABLE))
- return LPS25HB_ERROR;
- if(pLPS25HBFIFO->FIFO_MODE==LPS25HB_FIFO_MEAN_MODE){
- if(LPS25HB_Set_FifoSampleSize(pLPS25HBFIFO->MEAN_MODE_SAMPLE))
- return LPS25HB_ERROR;
- if(pLPS25HBFIFO->FIFO_MEAN_DEC)
- if(LPS25HB_Set_FifoMeanDecUse(LPS25HB_ENABLE))
- return LPS25HB_ERROR;
- }
- else{
- if (pLPS25HBFIFO->WTM_INT){
- if(LPS25HB_Set_FifoWatermarkLevelUse(LPS25HB_ENABLE))
- return LPS25HB_ERROR;
- if(LPS25HB_Set_FifoWatermarkLevel(pLPS25HBFIFO->WTM_LEVEL))
- return LPS25HB_ERROR;
- }
- }
- }
- if(LPS25HB_Set_FifoMode(pLPS25HBFIFO->FIFO_MODE))
- return LPS25HB_ERROR;
- return LPS25HB_OK;
- }
- /**
- * @brief Get Fifo Configuration
- * @param Struct to empty with the tmp read from sensor
- * @retval Status [LPS25HB_ERROR, LPS25HB_OK]
- */
- LPS25HB_Error_et ICACHE_FLASH_ATTR LPS25HB_Get_FifoConfig(LPS25HB_FIFOTypeDef_st* pLPS25HBFIFO)
- {
- uint8_t tmp;
- if(LPS25HB_ReadReg(LPS25HB_CTRL_FIFO_REG, 1, &tmp))
- return LPS25HB_ERROR;
- pLPS25HBFIFO->FIFO_MODE=(LPS25HB_FifoMode_et)(tmp&LPS25HB_FMODE_MASK);
- if(pLPS25HBFIFO->FIFO_MODE==LPS25HB_FIFO_MEAN_MODE){
- pLPS25HBFIFO->MEAN_MODE_SAMPLE=(LPS25HB_FifoMeanModeSample_et)(tmp&LPS25HB_WTM_POINT_MASK);
- if(LPS25HB_ReadReg(LPS25HB_CTRL_REG2, 1, &tmp))
- return LPS25HB_ERROR;
- pLPS25HBFIFO->FIFO_MEAN_DEC=(LPS25HB_State_et)((tmp&LPS25HB_FIFO_MEAN_MASK)>>LPS25HB_FIFO_MEAN_BIT);
- }
- else{
- if(pLPS25HBFIFO->FIFO_MODE != LPS25HB_FIFO_BYPASS_MODE) {
- if(LPS25HB_ReadReg(LPS25HB_CTRL_REG2, 1, &tmp))
- return LPS25HB_ERROR;
- pLPS25HBFIFO->WTM_INT=(LPS25HB_State_et)((tmp&LPS25HB_WTM_EN_MASK)>>LPS25HB_WTM_EN_BIT);
- if (pLPS25HBFIFO->WTM_INT){
- if(LPS25HB_ReadReg(LPS25HB_CTRL_FIFO_REG, 1, &tmp))
- return LPS25HB_ERROR;
- pLPS25HBFIFO->WTM_LEVEL=(uint8_t)(tmp&LPS25HB_WTM_POINT_MASK);
- }
- }
- }
- return LPS25HB_OK;
- }
- /**
- * @brief Get the Reference Pressure tmp that is sum to the sensor output pressure
- * @param Buffer to empty with reference pressure tmp
- * @retval Status [LPS25HB_ERROR, LPS25HB_OK]
- */
- LPS25HB_Error_et ICACHE_FLASH_ATTR LPS25HB_Get_ReferencePressure(int32_t* RefP)
- {
- uint8_t buffer[3];
- uint32_t tempVal=0;
- int32_t raw_press;
- uint8_t i;
- if(LPS25HB_ReadReg(LPS25HB_REF_P_XL_REG, 3, buffer))
- return LPS25HB_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 LPS25HB_OK;
- }
- /**
- * @brief Check if the single measurement has completed.
- * @param tmp is set to 1, when the measure is completed
- * @retval Status [LPS25HB_ERROR, LPS25HB_OK]
- */
- LPS25HB_Error_et ICACHE_FLASH_ATTR LPS25HB_IsMeasurementCompleted(uint8_t* Is_Measurement_Completed)
- {
- uint8_t tmp;
- LPS25HB_DataStatus_st datastatus;
- if(LPS25HB_ReadReg(LPS25HB_STATUS_REG, 1, &tmp))
- return LPS25HB_ERROR;
- datastatus.TempDataAvailable=(uint8_t)(tmp&0x01);
- datastatus.PressDataAvailable= (uint8_t)((tmp&0x02)>>LPS25HB_PDA_BIT);
- *Is_Measurement_Completed=(uint8_t)((datastatus.PressDataAvailable) & (datastatus.TempDataAvailable));
- return LPS25HB_OK;
- }
- /**
- * @brief Get the values of the last single measurement.
- * @param Pressure and temperature tmp
- * @retval Status [LPS25HB_ERROR, LPS25HB_OK]
- */
- LPS25HB_Error_et ICACHE_FLASH_ATTR LPS25HB_Get_Measurement(LPS25HB_MeasureTypeDef_st *Measurement_Value)
- {
- int16_t Tout;
- int32_t Pout;
- if(LPS25HB_Get_Temperature(&Tout))
- return LPS25HB_ERROR;
- Measurement_Value->Tout=Tout;
- if(LPS25HB_Get_Pressure(&Pout))
- return LPS25HB_ERROR;
- Measurement_Value->Pout=Pout;
- return LPS25HB_OK;
- }
- /**
- * @brief De initialization function for LPS25HB.
- * This function put the LPS25HB in power down, make a memory boot and clear the data output flags.
- * @param None.
- * @retval Error code [LPS25HB_OK, LPS25HB_ERROR].
- */
- LPS25HB_Error_et ICACHE_FLASH_ATTR LPS25HB_DeInit(void)
- {
- LPS25HB_MeasureTypeDef_st Measurement_Value;
- /* LPS25HB in power down */
- if(LPS25HB_Set_PowerDownMode(LPS25HB_RESET))
- return LPS25HB_ERROR;
- /* Make LPS25HB Reset and Reboot */
- if(LPS25HB_SwResetAndMemoryBoot())
- return LPS25HB_ERROR;
- /* Dump of data output */
- if(LPS25HB_Get_Measurement(& Measurement_Value))
- return LPS25HB_ERROR;
- return LPS25HB_OK;
- }
- #ifdef USE_FULL_ASSERT_LPS25HB
- /**
- * @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 ICACHE_FLASH_ATTR LPS25HB_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, line);
- /* Infinite loop */
- while (1)
- {
- }
- }
- #endif
- /**
- * @}
- */
- /**
- * @}
- */
- /**
- * @}
- */
- /******************* (C) COPYRIGHT 2013 STMicroelectronics *****END OF FILE****/
|