1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186 |
- /******************** (C) COPYRIGHT 2016 STMicroelectronics ********************
- * File Name : LSM303C_ACC_driver.c
- * Author : MEMS Application Team
- * Version : v1.1
- * Date : 22 Nov 2016
- * Description : LSM303C Platform Independent Driver
- *
- ********************************************************************************
- * 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 SOFTWARE IS SPECIFICALLY DESIGNED FOR EXCLUSIVE USE WITH ST PARTS.
- *******************************************************************************/
- /* Includes ------------------------------------------------------------------*/
- #include "includes.h"
- //EXAMPLE to fill LSM303C_ACC_ReadReg and LSM303C_ACC_WriteReg
- /* Private typedef -----------------------------------------------------------*/
- /* Private define ------------------------------------------------------------*/
- /* Private macro -------------------------------------------------------------*/
- /* Private variables ---------------------------------------------------------*/
- /* Private function prototypes -----------------------------------------------*/
- /* Private functions ---------------------------------------------------------*/
- /************** Generic Function *******************/
- /*******************************************************************************
- * Function Name : LSM303C_ACC_WriteReg
- * Description : Generic Writing function. It must be fullfilled with either
- * : I2C or SPI writing function
- * Input : Register Address, ptr to buffer to be written,
- * length of buffer
- * Output : None
- * Return : None
- *******************************************************************************/
- status_t LSM303C_ACC_WriteReg(void *handle, u8_t Reg, u8_t *Bufp, u16_t len)
- {
- // HAL_I2C_Mem_Write(&hi2c1, LSM303C_ACC_MEMS_I2C_ADDRESS, Reg, I2C_MEMADD_SIZE_8BIT,
- // Bufp, len, 1000);
- // return MEMS_SUCCESS;
- //OperationI2C(LSM303C_ACC_MEMS_I2C_ADDRESS,&Reg,1);
- #if 0
- IIC_Start();
- IIC_Send_Byte(LSM303C_ACC_MEMS_I2C_ADDRESS);
- if(IIC_Wait_Ack())
- {
- IIC_Stop();//释放总线
- return 1;//没应答则退出
- }
- IIC_Send_Byte(Reg);
- IIC_Wait_Ack();
- IIC_Send_Byte(Bufp[0]);
- IIC_Wait_Ack();
- IIC_Stop();
- #else
- unsigned short addr;
- unsigned short i;
- MOTION_CS_XL_LOW;
- DelayNs(5);
- //写0x23
- addr=Reg;
- addr<<=8;
- addr|=*Bufp;
- for(i=0;i<16;i++)
- {
- MOTION_CLK_LOW;
- DelayNs(2);
- if((addr<<i)&0x8000) MOTION_SDA_HIGH;
- else MOTION_SDA_LOW;
- DelayNs(2);
- MOTION_CLK_HIGH;
- DelayNs(5);
- }
- MOTION_CS_XL_HIGH;
- DelayNs(5);
- return MEMS_SUCCESS;
- #endif
- }
- /*******************************************************************************
- * Function Name : LSM303C_ACC_ReadReg
- * Description : Generic Reading function. It must be fullfilled with either
- * : I2C or SPI writing function
- * Input : Register Address, ptr to buffer to be read,
- * length of buffer
- * Output : None
- * Return : None
- *******************************************************************************/
- status_t LSM303C_ACC_ReadReg(void *handle, u8_t Reg, u8_t *Bufp, u16_t len)
- {
- //HAL_I2C_Mem_Read(&hi2c1, LSM303C_ACC_MEMS_I2C_ADDRESS, Reg, I2C_MEMADD_SIZE_8BIT, Bufp, len, 1000);
- // OperationI2C(LSM303C_ACC_MEMS_I2C_ADDRESS,&Reg,1);
- // return OperationI2C(LSM303C_ACC_MEMS_I2C_ADDRESS|0x01,Bufp,1);
- #if 0
- unsigned char REG_data;
- IIC_Start();
- IIC_Send_Byte(LSM303C_ACC_MEMS_I2C_ADDRESS);//发写命令
- if(IIC_Wait_Ack())
- {
- IIC_Stop();//释放总线
- return 0;//没应答则退出
- }
- IIC_Send_Byte(Reg);
- IIC_Wait_Ack();
- IIC_Start();
- IIC_Send_Byte(LSM303C_ACC_MEMS_I2C_ADDRESS|0x01);//发读命令
- IIC_Wait_Ack();
- Bufp[0] = IIC_Read_Byte(0);
- IIC_Stop();
-
- return MEMS_SUCCESS;
- #else
- unsigned short addr;
- unsigned short dat=0,i;
- if(Reg>0x7F)return 0;
- addr=0x80|Reg;
- MOTION_CS_XL_LOW;
- DelayNs(5);
- //写
- for(i=0;i<8;i++)
- {
- DelayNs(2);
- MOTION_CLK_LOW;
- DelayNs(2);
- if((addr<<i)&0x80) MOTION_SDA_HIGH;
- else MOTION_SDA_LOW;
- DelayNs(2);
- MOTION_CLK_HIGH;
- DelayNs(2);
- }
- //读
- for(i=0;i<8;i++)
- {
- dat<<=1;
- DelayNs(2);
- MOTION_CLK_LOW;
- DelayNs(5);
- MOTION_CLK_HIGH;
- DelayNs(2);
- if(MOTION_SDA_READ) dat|=0x01;
- }
- *Bufp = dat;
- MOTION_CS_XL_HIGH;
- DelayNs(5);
- return MEMS_SUCCESS;
-
- #endif
- }
- /**************** Base Function *******************/
- /*******************************************************************************
- * Function Name : LSM303C_ACC_SetODR
- * Description : Sets LIS2HH Output Data Rate
- * Input : Set Output data rate [LSM303C_ACC_ODR_t]
- * Output : None
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_ACC_SetODR(void *handle, LSM303C_ACC_ODR_t ov){
- u8_t value;
- if( !LSM303C_ACC_ReadReg(handle, LSM303C_ACC_CTRL1, &value, 1) )
- return MEMS_ERROR;
- value &= ~LSM303C_ACC_ODR_MASK; //mask
- value |= ov;
-
- if( !LSM303C_ACC_WriteReg(handle, LSM303C_ACC_CTRL1, &value, 1) )
- return MEMS_ERROR;
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_ACC_SetFullScale
- * Description : set LIS2HH Full scale
- * Input : set LIS2HH Full scale [LSM303C_ACC_FS_t]
- * Output : None
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_ACC_SetFullScale(void *handle, LSM303C_ACC_FS_t ov){
- u8_t value;
- if( !LSM303C_ACC_ReadReg(handle, LSM303C_ACC_CTRL4, &value, 1) )
- return MEMS_ERROR;
- value &= ~LSM303C_ACC_FS_8g; //mask
- value |= ov;
- if( !LSM303C_ACC_WriteReg(handle, LSM303C_ACC_CTRL4, &value, 1) )
- return MEMS_ERROR;
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_ACC_BlockDataUpdate
- * Description : Enable/Disable LIS2HH BlockDataUpdate
- * Input : Enable/Disable LIS2HH BlockDataUpdate[LSM303C_ACC_BDU_t]
- * Output : None
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_ACC_BlockDataUpdate(void *handle, LSM303C_ACC_BDU_t ov){
- u8_t value;
- if( !LSM303C_ACC_ReadReg(handle, LSM303C_ACC_CTRL1, &value, 1) )
- return MEMS_ERROR;
- value &= ~LSM303C_ACC_BDU_ENABLE; //mask
- value |= ov;
- if( !LSM303C_ACC_WriteReg(handle, LSM303C_ACC_CTRL1, &value, 1) )
- return MEMS_ERROR;
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_ACC_GetAccRaw
- * Description : Read accelerometer output register
- * Input : pointer to AxesRaw_t
- * Output : Acceleration Output Registers buffer AxesRaw_t
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_ACC_GetAccRaw(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( !LSM303C_ACC_ReadReg(handle, LSM303C_ACC_OUT_X_L+k, &buff[k], 1))
- return MEMS_ERROR;
- k++;
- }
- }
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_ACC_SelfTest
- * Description : Enable/Disable LIS2HH Self Test
- * Input : Self test [LSM303C_ACC_ST_t]
- * Output : None
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_ACC_SelfTest(void *handle, LSM303C_ACC_ST_t ov){
- u8_t value;
- if( !LSM303C_ACC_ReadReg(handle, LSM303C_ACC_CTRL5, &value, 1) )
- return MEMS_ERROR;
- value &= ~LSM303C_ACC_ST_NA; //mask
- value |= ov;
- if( !LSM303C_ACC_WriteReg(handle, LSM303C_ACC_CTRL5, &value, 1) )
- return MEMS_ERROR;
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_ACC_AxOperativeMode
- * Description : Sets LIS2HH Output Data Rate
- * Input : Set Output data rate [LSM303C_ACC_HR_t]
- * Output : None
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- //#WARNING: If you enable the HR bit Low pass cut off frequency will change
- status_t LSM303C_ACC_AxOperativeMode(void *handle, LSM303C_ACC_HR_t ov){
- u8_t value;
- if( !LSM303C_ACC_ReadReg(handle, LSM303C_ACC_CTRL1, &value, 1) )
- return MEMS_ERROR;
- value &= ~LSM303C_ACC_HIGH_RES_ON; //mask
- value |= ov;
- if( !LSM303C_ACC_WriteReg(handle, LSM303C_ACC_CTRL1, &value, 1) )
- return MEMS_ERROR;
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_ACC_SoftReset
- * Description : Enable/Disable LIS2HH SoftReset
- * Input : SoftReset Enable/Disable [LSM303C_ACC_SOFT_RESET_t]
- * Output : None
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_ACC_SoftReset(void *handle, LSM303C_ACC_SOFT_RESET_t ov){
- u8_t value;
- if( !LSM303C_ACC_ReadReg(handle, LSM303C_ACC_CTRL5, &value, 1) )
- return MEMS_ERROR;
- value &= ~LSM303C_ACC_SOFT_RESET_ENABLE; //mask
- value |= ov;
- if( !LSM303C_ACC_WriteReg(handle, LSM303C_ACC_CTRL5, &value, 1) )
- return MEMS_ERROR;
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_ACC_SerialInterfaceMode
- * Description : set LIS2HH SerialInterfaceMode
- * Input : set LIS2HH SerialInterfaceMode [LSM303C_ACC_SIM_t]
- * Output : None
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_ACC_SerialInterfaceMode(void *handle, LSM303C_ACC_SIM_t ov){
- u8_t value;
- if( !LSM303C_ACC_ReadReg(handle, LSM303C_ACC_CTRL4, &value, 1) )
- return MEMS_ERROR;
- value &= ~LSM303C_ACC_SIM_3WIRE_INTERFACE; //mask
- value |= ov;
- if( !LSM303C_ACC_WriteReg(handle, LSM303C_ACC_CTRL4, &value, 1) )
- return MEMS_ERROR;
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_ACC_EnableInterruptGeneratorOne
- * Description : Enable/Disable LIS2HH interrupt generator one
- * Input : Enable/Disable LIS2HH interrupt generator one[LSM303C_ACC_IG_CONFIG_t]
- * Output : None
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- //You can use LSM303C_ACC_IG_CONFIG_t with or condition see DS 4D and 6D interrupt
- status_t LSM303C_ACC_EnableInterruptGeneratorOne(void *handle, LSM303C_ACC_IG_CONFIG_t ov){
- u8_t valueCTRL7, valueCFG1;
-
- if( !LSM303C_ACC_ReadReg(handle, LSM303C_ACC_CTRL7, &valueCTRL7, 1) )
- return MEMS_ERROR;
- if( !LSM303C_ACC_ReadReg(handle, LSM303C_ACC_IG_CFG1, &valueCFG1, 1) )
- return MEMS_ERROR;
-
- if (ov&LSM303C_ACC_IG_4D)
- {
- valueCFG1 &= 0x80; //disable all interrupt generation
- if( !LSM303C_ACC_WriteReg(handle, LSM303C_ACC_IG_CFG1, &valueCFG1, 1) )
- return MEMS_ERROR;
- valueCTRL7 |= LSM303C_ACC_4D_INTGEN1_EN; //enable 4D recognition
- if( !LSM303C_ACC_WriteReg(handle, LSM303C_ACC_CTRL7, &valueCTRL7, 1) )
- return MEMS_ERROR;
- }
- else
- {
- valueCFG1 &= ~0x7F; //enable selected interrupt
- valueCFG1 |= ov;
- if( !LSM303C_ACC_WriteReg(handle, LSM303C_ACC_IG_CFG1, &valueCFG1, 1) )
- return MEMS_ERROR;
- valueCTRL7 &= ~LSM303C_ACC_4D_INTGEN1_EN; //disable 4d recognition
- if( !LSM303C_ACC_WriteReg(handle, LSM303C_ACC_CTRL7, &valueCTRL7, 1) )
- return MEMS_ERROR;
- }
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_ACC_EnableInterruptGeneratorTwo
- * Description : Enable/Disable LIS2HH interrupt generator two
- * Input : Enable/Disable LIS2HH interrupt generator two[LSM303C_ACC_IG_CONFIG_t]
- * Output : None
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- //You can use LSM303C_ACC_IG_CONFIG_t with or condition see DS 4D and 6D interrupt
- status_t LSM303C_ACC_EnableInterruptGeneratorTwo(void *handle, LSM303C_ACC_IG_CONFIG_t ov){
- u8_t valueCTRL7, valueCFG2;
-
- if( !LSM303C_ACC_ReadReg(handle, LSM303C_ACC_CTRL7, &valueCTRL7, 1) )
- return MEMS_ERROR;
- if( !LSM303C_ACC_ReadReg(handle, LSM303C_ACC_IG_CFG2, &valueCFG2, 1) )
- return MEMS_ERROR;
-
- if (ov&LSM303C_ACC_IG_4D)
- {
- valueCFG2 &= 0x80; //disable all interrupt generation
- if( !LSM303C_ACC_WriteReg(handle, LSM303C_ACC_IG_CFG2, &valueCFG2, 1) )
- return MEMS_ERROR;
- valueCTRL7 |= LSM303C_ACC_4D_INTGEN2_EN; //enable 4D recognition
- if( !LSM303C_ACC_WriteReg(handle, LSM303C_ACC_CTRL7, &valueCTRL7, 1) )
- return MEMS_ERROR;
- }
- else
- {
-
- valueCFG2 &= ~0x7F; //enable selected interrupt
- valueCFG2 |= ov;
- if( !LSM303C_ACC_WriteReg(handle, LSM303C_ACC_IG_CFG2, &valueCFG2, 1) )
- return MEMS_ERROR;
- valueCTRL7 &= ~LSM303C_ACC_4D_INTGEN2_EN; //disable 4d recognition
- if( !LSM303C_ACC_WriteReg(handle, LSM303C_ACC_CTRL7, &valueCTRL7, 1) )
- return MEMS_ERROR;
- }
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_ACC_InterruptGeneratorOne_LogicCondition
- * Description : LIS2HH interrupt generator one LogicCondition
- * Input : LIS2HH interrupt generator one LogicCondition[LSM303C_ACC_AOI_IG_t]
- * Output : None
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_ACC_InterruptGeneratorOne_LogicCondition(void *handle, LSM303C_ACC_AOI_IG_t ov){
- u8_t value;
- if( !LSM303C_ACC_ReadReg(handle, LSM303C_ACC_IG_CFG1, &value, 1) )
- return MEMS_ERROR;
- value &= ~LSM303C_ACC_AOI_IG_AND; //mask
- value |= ov;
- if( !LSM303C_ACC_WriteReg(handle, LSM303C_ACC_IG_CFG1, &value, 1) )
- return MEMS_ERROR;
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_ACC_InterruptGeneratorTwo_LogicCondition
- * Description : LIS2HH interrupt generator two LogicCondition
- * Input : LIS2HH interrupt generator two LogicCondition[LSM303C_ACC_AOI_IG_t]
- * Output : None
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_ACC_InterruptGeneratorTwo_LogicCondition(void *handle, LSM303C_ACC_AOI_IG_t ov){
- u8_t value;
- if( !LSM303C_ACC_ReadReg(handle, LSM303C_ACC_IG_CFG2, &value, 1) )
- return MEMS_ERROR;
- value &= ~LSM303C_ACC_AOI_IG_AND; //mask
- value |= ov;
-
- if( !LSM303C_ACC_WriteReg(handle, LSM303C_ACC_IG_CFG2, &value, 1) )
- return MEMS_ERROR;
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_ACC_InterruptGeneratorOne_Flag
- * Description : read interrupt one generator flags
- * Input : pointer to LSM303C_ACC_IG_FLAGS_t
- * Output : LIS2HH XYZ Axis data overrun [LSM303C_ACC_IG_FLAGS_t]
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- //You can use LSM303C_ACC_IG_FLAGS_t with or condition to interpret value
- status_t LSM303C_ACC_InterruptGeneratorOne_Flag(void *handle, LSM303C_ACC_IG_FLAGS_t *value){
- if( !LSM303C_ACC_ReadReg(handle, LSM303C_ACC_IG_SRC1, (u8_t *)value, 1) )
- return MEMS_ERROR;
- *value &= 0x7F; //mask
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_ACC_InterruptGeneratorTwo_Flag
- * Description : read interrupt two generator flags
- * Input : pointer to LSM303C_ACC_IG_FLAGS_t
- * Output : LIS2HH XYZ Axis data overrun [LSM303C_ACC_IG_FLAGS_t]
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- //You can use LSM303C_ACC_IG_FLAGS_t with or condition to interpret value
- status_t LSM303C_ACC_InterruptGeneratorTwo_Flag(void *handle, LSM303C_ACC_IG_FLAGS_t *value){
- if( !LSM303C_ACC_ReadReg(handle, LSM303C_ACC_IG_SRC2, (u8_t *)value, 1) )
- return MEMS_ERROR;
- *value &= 0x7F; //mask
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_ACC_InterruptGeneratorOne_Wait
- * Description : Enable/Disable LIS2HH interrupt generator one Wait
- * Input : Enable/Disable LIS2HH interrupt generator one Wait[LSM303C_ACC_WAIT_IG_t]
- * Output : None
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_ACC_InterruptGeneratorOne_Wait(void *handle, LSM303C_ACC_WAIT_IG_t ov){
- u8_t value;
- if( !LSM303C_ACC_ReadReg(handle, LSM303C_ACC_IG_DUR1, &value, 1) )
- return MEMS_ERROR;
- value &= ~LSM303C_ACC_WAIT_IG_ON; //mask
- value |= ov;
- if( !LSM303C_ACC_WriteReg(handle, LSM303C_ACC_IG_DUR1, &value, 1) )
- return MEMS_ERROR;
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_ACC_InterruptGeneratorTwo_Wait
- * Description : Enable/Disable LIS2HH interrupt generator two Wait
- * Input : Enable/Disable LIS2HH interrupt generator two Wait[LSM303C_ACC_WAIT_IG_t]
- * Output : None
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_ACC_InterruptGeneratorTwo_Wait(void *handle, LSM303C_ACC_WAIT_IG_t ov){
- u8_t value;
- if( !LSM303C_ACC_ReadReg(handle, LSM303C_ACC_IG_DUR2, &value, 1) )
- return MEMS_ERROR;
- value &= ~LSM303C_ACC_WAIT_IG_ON; //mask
- value |= ov;
-
- if( !LSM303C_ACC_WriteReg(handle, LSM303C_ACC_IG_DUR2, &value, 1) )
- return MEMS_ERROR;
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_ACC_EnableInterruptPinOne
- * Description : Enable/Disable LIS2HH interrupt pin one
- * Input : Enable/Disable LIS2HH interrupt pin one[LSM303C_ACC_INT1_DRDY_t]
- * Output : None
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_ACC_EnableInterruptPinOne(void *handle, LSM303C_ACC_INT1_DRDY_t ov){
- u8_t value;
- if( !LSM303C_ACC_ReadReg(handle, LSM303C_ACC_CTRL3, &value, 1) )
- return MEMS_ERROR;
- value &= ~0x7F; //mask
- value |= ov;
- if( !LSM303C_ACC_WriteReg(handle, LSM303C_ACC_CTRL3, &value, 1) )
- return MEMS_ERROR;
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_ACC_EnableInterruptPinTwo
- * Description : Enable/Disable LIS2HH interrupt pin two
- * Input : Enable/Disable LIS2HH interrupt pin two[LSM303C_ACC_INT2_DRDY_t]
- * Output : None
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_ACC_EnableInterruptPinTwo(void *handle, LSM303C_ACC_INT2_DRDY_t ov){
- u8_t value;
- if( !LSM303C_ACC_ReadReg(handle, LSM303C_ACC_CTRL6, &value, 1) )
- return MEMS_ERROR;
- value &= ~0x3F; //mask
- value |= ov;
- if( !LSM303C_ACC_WriteReg(handle, LSM303C_ACC_CTRL6, &value, 1) )
- return MEMS_ERROR;
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_ACC_Reboot
- * Description : LSM303C_ACC_Reboot
- * Input : None
- * Output : None
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_ACC_Reboot(void *handle){
- u8_t value;
- if( !LSM303C_ACC_ReadReg(handle, LSM303C_ACC_CTRL6, &value, 1) )
- return MEMS_ERROR;
- value |= LSM303C_ACC_REBOOT;
- if( !LSM303C_ACC_WriteReg(handle, LSM303C_ACC_CTRL6, &value, 1) )
- return MEMS_ERROR;
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_ACC_EnableAxis
- * Description : LSM303C_ACC_EnableAxis
- * Input : Enable/Disable LIS2HH axis [LSM303C_ACC_AXIS_EN_t]
- * Output : None
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- //You can use LSM303C_ACC_AXIS_EN_t with or condition
- status_t LSM303C_ACC_EnableAxis(void *handle, u8_t ov){
- u8_t value;
- if( !LSM303C_ACC_ReadReg(handle, LSM303C_ACC_CTRL1, &value, 1) )
- return MEMS_ERROR;
- value &= ~0x07; //mask
- value |= ov;
- if( !LSM303C_ACC_WriteReg(handle, LSM303C_ACC_CTRL1, &value, 1) )
- return MEMS_ERROR;
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_ACC_HighPassFilterMode
- * Description : LSM303C_ACC_HighPassFilterMode
- * Input : Select LIS2HH high pass filter mode [LSM303C_ACC_HPM_t]
- * Output : None
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- //Referring DS to HP filter Usage
- status_t LSM303C_ACC_HighPassFilterMode(void *handle, LSM303C_ACC_HPM_t ov){
- u8_t value;
- if( !LSM303C_ACC_ReadReg(handle, LSM303C_ACC_CTRL2, &value, 1) )
- return MEMS_ERROR;
- value &= ~0x18; //mask
- value |= ov;
- if( !LSM303C_ACC_WriteReg(handle, LSM303C_ACC_CTRL2, &value, 1) )
- return MEMS_ERROR;
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_ACC_I2C_Mode
- * Description : Enable/Disable LIS2HH I2C
- * Input : Enable/Disable LIS2HH I2C[LSM303C_ACC_I2C_t]
- * Output : None
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_ACC_I2C_Mode(void *handle, LSM303C_ACC_I2C_t ov){
- u8_t value;
- if( !LSM303C_ACC_ReadReg(handle, LSM303C_ACC_CTRL4, &value, 1) )
- return MEMS_ERROR;
- value &= ~LSM303C_ACC_I2C_DISABLE; //mask
- value |= ov;
- if( !LSM303C_ACC_WriteReg(handle, LSM303C_ACC_CTRL4, &value, 1) )
- return MEMS_ERROR;
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_ACC_AuotoInc
- * Description : Enable/Disable LIS2HH AuotoInc
- * Input : Enable/Disable LIS2HH AuotoInc[LSM303C_ACC_IF_ADD_INC_t]
- * Output : None
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_ACC_AuotoInc(void *handle, LSM303C_ACC_IF_ADD_INC_t ov){
- u8_t value;
- if( !LSM303C_ACC_ReadReg(handle, LSM303C_ACC_CTRL4, &value, 1) )
- return MEMS_ERROR;
- value &= ~LSM303C_ACC_IF_ADD_INC_ENABLE; //mask
- value |= ov;
- if( !LSM303C_ACC_WriteReg(handle, LSM303C_ACC_CTRL4, &value, 1) )
- return MEMS_ERROR;
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_ACC_Select_Bandwidth
- * Description : LIS2HH LSM303C_ACC_Select_Bandwidth
- * Input : LIS2HH LSM303C_ACC_Select_Bandwidth[LSM303C_ACC_BW_t]
- * Output : None
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_ACC_Select_Bandwidth(void *handle, LSM303C_ACC_BW_t ov){
- u8_t value;
- if( !LSM303C_ACC_ReadReg(handle, LSM303C_ACC_CTRL4, &value, 1) )
- return MEMS_ERROR;
- value &= ~LSM303C_ACC_BW_50_Hz; //mask
- value |= ov;
- if( !LSM303C_ACC_WriteReg(handle, LSM303C_ACC_CTRL4, &value, 1) )
- return MEMS_ERROR;
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_ACC_IntPin_Mode
- * Description : LIS2HH Interrupt pin mode
- * Input : LIS2HH Interrupt pin mode[LSM303C_ACC_INT_PIN_CFG_t]
- * Output : None
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_ACC_IntPin_Mode(void *handle, LSM303C_ACC_INT_PIN_CFG_t ov){
- u8_t value;
- if( !LSM303C_ACC_ReadReg(handle, LSM303C_ACC_CTRL5, &value, 1) )
- return MEMS_ERROR;
- value &= ~LSM303C_ACC_OPEN_DRAIN_ACTIVE_LOW; //mask
- value |= ov;
- if( !LSM303C_ACC_WriteReg(handle, LSM303C_ACC_CTRL5, &value, 1) )
- return MEMS_ERROR;
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_ACC_DebugMode
- * Description : Enable/Disable LIS2HH Debug Mode
- * Input : Enable/Disable LIS2HH Debug Mode[LSM303C_ACC_DEBUG_t]
- * Output : None
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_ACC_DebugMode(void *handle, LSM303C_ACC_DEBUG_t ov){
- u8_t value;
- if( !LSM303C_ACC_ReadReg(handle, LSM303C_ACC_CTRL5, &value, 1) )
- return MEMS_ERROR;
- value &= ~LSM303C_ACC_DEBUG_ENABLE; //mask
- value |= ov;
- if( !LSM303C_ACC_WriteReg(handle, LSM303C_ACC_CTRL5, &value, 1) )
- return MEMS_ERROR;
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_ACC_InterruptSignalsMode
- * Description : LIS2HH Interrupt Signals Mode
- * Input : LIS2HH Interrupt Signals Mode[LSM303C_ACC_LAT_SIG_t]
- * Output : None
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_ACC_InterruptSignalsMode(void *handle, LSM303C_ACC_LAT_SIG_t ov){
- u8_t value;
- if( !LSM303C_ACC_ReadReg(handle, LSM303C_ACC_CTRL7, &value, 1) )
- return MEMS_ERROR;
- value &= ~LSM303C_ACC_INT1_LAT_INT2_LAT; //mask
- value |= ov;
- if( !LSM303C_ACC_WriteReg(handle, LSM303C_ACC_CTRL7, &value, 1) )
- return MEMS_ERROR;
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_ACC_ResetInterruptDuration
- * Description : LIS2HH Reset Interrupt Duration
- * Input : LIS2HH Reset Interrupt Duration[LSM303C_ACC_RESET_DUR_t]
- * Output : None
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_ACC_ResetInterruptDuration(void *handle, LSM303C_ACC_RESET_DUR_t ov){
- u8_t value;
- if( !LSM303C_ACC_ReadReg(handle, LSM303C_ACC_CTRL7, &value, 1) )
- return MEMS_ERROR;
- value &= ~LSM303C_ACC_DUR1_RST_DUR2_RST; //mask
- value |= ov;
- if( !LSM303C_ACC_WriteReg(handle, LSM303C_ACC_CTRL7, &value, 1) )
- return MEMS_ERROR;
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_ACC_Status_Flags
- * Description : read LIS2HH Status Flags
- * Input : pointer to LSM303C_ACC_STATUS_FLAGS_t
- * Output : read LIS2HH Status Flags [LSM303C_ACC_STATUS_FLAGS_t]
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- //You can use LSM303C_ACC_STATUS_FLAGS_t with or condition to interpret value
- status_t LSM303C_ACC_Status_Flags(void *handle, u8_t *value){
- if( !LSM303C_ACC_ReadReg(handle, LSM303C_ACC_STATUS, (u8_t *)value, 1) )
- return MEMS_ERROR;
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_ACC_FIFO_Mode
- * Description : LIS2HH FIFO Mode
- * Input : LIS2HH FIFO Mode[LSM303C_ACC_FMODE_t]
- * Output : None
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- //this function enable FIFO to disable use LSM303C_ACC_FIFO
- status_t LSM303C_ACC_FIFO_Mode(void *handle, LSM303C_ACC_FMODE_t ov){
- u8_t value;
- if( !LSM303C_ACC_ReadReg(handle, LSM303C_ACC_CTRL3, &value, 1) )
- return MEMS_ERROR;
- value |= LSM303C_ACC_FIFO_ENABLE; //Enable FIFO
- if( !LSM303C_ACC_WriteReg(handle, LSM303C_ACC_CTRL3, &value, 1) )
- return MEMS_ERROR;
-
- if( !LSM303C_ACC_ReadReg(handle, LSM303C_ACC_FIFO_CTRL, &value, 1) )
- return MEMS_ERROR;
- value &= ~LSM303C_ACC_FMODE_BYPASS_TO_FIFO; //mask
- value |= ov;
- if( !LSM303C_ACC_WriteReg(handle, LSM303C_ACC_FIFO_CTRL, &value, 1) )
- return MEMS_ERROR;
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_ACC_FIFO_Flags
- * Description : read LIS2HH FIFO Flags
- * Input : pointer to LSM303C_ACC_FIFO_FLAGS_t
- * Output : read LIS2HH FIFO Flags [LSM303C_ACC_FIFO_FLAGS_t]
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- //You can use LSM303C_ACC_FIFO_FLAGS_t with or condition to interpret value
- status_t LSM303C_ACC_FIFO_Flags(void *handle, LSM303C_ACC_FIFO_FLAGS_t *value){
- if( !LSM303C_ACC_ReadReg(handle, LSM303C_ACC_FIFO_SRC, (u8_t *)value, 1) )
- return MEMS_ERROR;
- *value &= 0xE0; //mask
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_ACC_FIFO_StopAtTh
- * Description : LIS2HH FIFO Stop at threshold
- * Input : LIS2HH FIFO Stop at threshold[LSM303C_ACC_STOP_FTH_t]
- * Output : None
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_ACC_FIFO_StopAtTh(void *handle, LSM303C_ACC_STOP_FTH_t ov){
- u8_t value;
- if( !LSM303C_ACC_ReadReg(handle, LSM303C_ACC_CTRL3, &value, 1) )
- return MEMS_ERROR;
- value &= ~LSM303C_ACC_STOP_FTH_EN_FIFO_TH; //mask
- value |= ov;
- if( !LSM303C_ACC_WriteReg(handle, LSM303C_ACC_CTRL3, &value, 1) )
- return MEMS_ERROR;
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_ACC_FIFO
- * Description : Enable/Disable LIS2HH FIFO
- * Input : Enable/Disable LIS2HH FIFO[LSM303C_ACC_FIFO_EN_t]
- * Output : None
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_ACC_FIFO(void *handle, LSM303C_ACC_FIFO_EN_t ov){
- u8_t value;
- if( !LSM303C_ACC_ReadReg(handle, LSM303C_ACC_CTRL3, &value, 1) )
- return MEMS_ERROR;
- value &= ~LSM303C_ACC_FIFO_ENABLE; //mask
- value |= ov;
- if( !LSM303C_ACC_WriteReg(handle, LSM303C_ACC_CTRL3, &value, 1) )
- return MEMS_ERROR;
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_ACC_GetTemperatureRaw
- * Description : Read Temperature output register
- * Input : pointer to u16_t
- * Output : Temperature data row to u16_t
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_ACC_GetTemperatureRaw(void *handle, u16_t* buff) {
- u8_t valueL;
- u8_t valueH;
-
- if( !LSM303C_ACC_ReadReg(handle, LSM303C_ACC_TEMP_H, &valueL, 1) )
- return MEMS_ERROR;
-
- if( !LSM303C_ACC_ReadReg(handle, LSM303C_ACC_TEMP_L, &valueH, 1) )
- return MEMS_ERROR;
-
- *buff = (i16_t)( (valueH << 8) | valueL );
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_ACC_SetInterrupt1_Threshold_X
- * Description : Set Interrupt Threshold data row
- * Input : threshold row value [u8_t]
- * Output : None
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_ACC_SetInterrupt1_Threshold_X(void *handle, u8_t buff) {
-
- if( !LSM303C_ACC_WriteReg(handle, LSM303C_ACC_IG_THS_X1, &buff, 1) )
- return MEMS_ERROR;
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_ACC_SetInterrupt1_Threshold_Y
- * Description : Set Interrupt Threshold data row
- * Input : threshold row value [u8_t]
- * Output : None
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_ACC_SetInterrupt1_Threshold_Y(void *handle, u8_t buff) {
-
- if( !LSM303C_ACC_WriteReg(handle, LSM303C_ACC_IG_THS_Y1, &buff, 1) )
- return MEMS_ERROR;
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_ACC_SetInterrupt1_Threshold_Z
- * Description : Set Interrupt Threshold data row
- * Input : threshold row value [u8_t]
- * Output : None
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_ACC_SetInterrupt1_Threshold_Z(void *handle, u8_t buff) {
-
- if( !LSM303C_ACC_WriteReg(handle, LSM303C_ACC_IG_THS_Z1, &buff, 1) )
- return MEMS_ERROR;
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_ACC_SetInterrupt2_Threshold_ZYX
- * Description : Set Interrupt Threshold data row
- * Input : threshold row value [u8_t]
- * Output : None
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_ACC_SetInterrupt2_Threshold_ZYX(void *handle, u8_t buff) {
-
- if( !LSM303C_ACC_WriteReg(handle, LSM303C_ACC_IG_THS2, &buff, 1) )
- return MEMS_ERROR;
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_ACC_SetInterrupt1_Duration
- * Description : Set Interrupt Duration data row
- * Input : Duration row value [u8_t]
- * Output : None
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- //WARNING: value from 0x00->0x7F
- status_t LSM303C_ACC_SetInterrupt1_Duration(void *handle, u8_t buff) {
- u8_t value;
-
- buff |= 0x7F; //coerce
- if( !LSM303C_ACC_ReadReg(handle, LSM303C_ACC_IG_DUR1, &value, 1) )
- return MEMS_ERROR;
- value &= ~0x7F; //mask
- value |= buff;
- if( !LSM303C_ACC_WriteReg(handle, LSM303C_ACC_IG_DUR1, &value, 1) )
- return MEMS_ERROR;
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_ACC_SetInterrupt2_Duration
- * Description : Set Interrupt Duration data row
- * Input : Duration row value [u8_t]
- * Output : None
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- //WARNING: value from 0x00->0x7F
- status_t LSM303C_ACC_SetInterrupt2_Duration(void *handle, u8_t buff) {
-
- u8_t value;
-
- buff |= 0x7F; //coerce
- if( !LSM303C_ACC_ReadReg(handle, LSM303C_ACC_IG_DUR2, &value, 1) )
- return MEMS_ERROR;
- value &= ~0x7F; //mask
- value |= buff;
- if( !LSM303C_ACC_WriteReg(handle, LSM303C_ACC_IG_DUR2, &value, 1) )
- return MEMS_ERROR;
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_ACC_SetReferenceValue
- * Description : Set Reference data row
- * Input : Reference row value [AxesRaw_t]
- * Output : None
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_ACC_SetReferenceValue(void *handle, u8_t *buff)
- {
- u8_t i;
- for (i=0; i<6;i++ )
- {
- if( !LSM303C_ACC_WriteReg(handle, LSM303C_ACC_XL_REFERENCE+i, &buff[i], 1) )
- return MEMS_ERROR;
- }
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_ACC_GetReferenceValue
- * Description : Get Reference data row
- * Input : Reference row value [AxesRaw_t]
- * Output : None
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_ACC_GetReferenceValue(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( !LSM303C_ACC_ReadReg(handle, LSM303C_ACC_XL_REFERENCE+k, &buff[k], 1))
- return MEMS_ERROR;
- k++;
- }
- }
- return MEMS_SUCCESS;
-
- }
- /*******************************************************************************
- * Function Name : LSM303C_ACC_SetActivity_Threshold
- * Description : Set Interrupt Threshold data row
- * Input : threshold row value [u8_t]
- * Output : None
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_ACC_SetActivity_Threshold(void *handle, u8_t buff) {
-
- if( !LSM303C_ACC_WriteReg(handle, LSM303C_ACC_ACT_TSH, &buff, 1) )
- return MEMS_ERROR;
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_ACC_SetActivity_Duration
- * Description : Set Interrupt Threshold data row
- * Input : threshold row value [u8_t]
- * Output : None
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_ACC_SetActivity_Duration(void *handle, u8_t buff) {
-
- if( !LSM303C_ACC_WriteReg(handle, LSM303C_ACC_ACT_DUR, &buff, 1) )
- return MEMS_ERROR;
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_ACC_SetFIFO_threshold
- * Description : FIFO Threshold data row
- * Input : threshold row value [u8_t]
- * Output : None
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- //WARNING: value from 0x00->0x1F
- status_t LSM303C_ACC_SetFIFO_threshold(void *handle, u8_t buff) {
- u8_t value;
-
- buff &= 0x1F; //coerce
- if (!LSM303C_ACC_ReadReg(handle, LSM303C_ACC_ACT_DUR, &value, 1) )
- return MEMS_ERROR;
- value &= ~0x1F; //mask
- value |= buff;
- if( !LSM303C_ACC_WriteReg(handle, LSM303C_ACC_ACT_DUR, &value, 1) )
- return MEMS_ERROR;
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_ACC_GetFIFO_StoredData
- * Description : FIFO Stored data row
- * Input : Stored data row value [u8_t]
- * Output : None
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- //WARNING: value from 0x00->0x1F
- status_t LSM303C_ACC_GetFIFO_StoredData(void *handle, u8_t buff) {
- if (!LSM303C_ACC_ReadReg(handle, LSM303C_ACC_FIFO_SRC, &buff, 1) )
- return MEMS_ERROR;
-
- buff &= 0x1F; //coerce
- return MEMS_SUCCESS;
- }
- /******************* (C) COPYRIGHT 2016 STMicroelectronics *****END OF FILE****/
|