1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534 |
- /******************** (C) COPYRIGHT 2016 STMicroelectronics ********************
- * File Name : LSM303C_MAG_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"
- /* Private typedef -----------------------------------------------------------*/
- /* Private define ------------------------------------------------------------*/
- /* Private macro -------------------------------------------------------------*/
- /* Private variables ---------------------------------------------------------*/
- /* Private functions ---------------------------------------------------------*/
- /************** Generic Function *******************/
- /*******************************************************************************
- * Function Name : LSM303C_MAG_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
- *******************************************************************************/
- u8_t LSM303C_MAG_WriteReg(void *handle, u8_t Reg, u8_t *Bufp, u16_t len)
- {
- /*Example*/
- //HAL_I2C_Mem_Write(&hi2c1, LSM303C_MAG_I2C_ADDRESS, Reg, I2C_MEMADD_SIZE_8BIT,
- // Bufp, len, 1000);
-
- // OperationI2C(LSM303C_MAG_I2C_ADDRESS,&Reg,1);
- #if 0
- IIC_Start();
- IIC_Send_Byte(LSM303C_MAG_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();
- return MEMS_SUCCESS;
- #else
- unsigned short addr;
- unsigned short i;
- MOTION_CS_MAG_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);
- }
- DelayNs(5);
- MOTION_CS_MAG_HIGH;
- return MEMS_SUCCESS;
- #endif
- }
- /*******************************************************************************
- * Function Name : LSM303C_MAG_ReadReg
- * Description : Generic Reading function. It must be fullfilled with either
- * : I2C or SPI reading functions
- * Input : Register Address
- * Output : Data REad
- * Return : None
- *******************************************************************************/
- u8_t LSM303C_MAG_ReadReg(void *handle, u8_t Reg, u8_t *Bufp, u16_t len)
- {
- /*Example*/
- //HAL_I2C_Mem_Read(&hi2c1, LSM303C_MAG_I2C_ADDRESS, Reg, I2C_MEMADD_SIZE_8BIT,
- // Bufp, len, 1000);
- // OperationI2C(LSM303C_MAG_I2C_ADDRESS,&Reg,1);
- // return OperationI2C(LSM303C_MAG_I2C_ADDRESS|0x01,Bufp,1);
- #if 0
- IIC_Start();
- IIC_Send_Byte(LSM303C_MAG_I2C_ADDRESS);//发写命令
- if(IIC_Wait_Ack())
- {
- IIC_Stop();//释放总线
- return 0;//没应答则退出
- }
- IIC_Send_Byte(Reg);
- IIC_Wait_Ack();
- IIC_Start();
- IIC_Send_Byte(LSM303C_MAG_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_MAG_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;
- }
-
- DelayNs(5);
- *Bufp = dat;
- MOTION_CS_MAG_HIGH;
- return MEMS_SUCCESS;
-
- #endif
- }
- /**************** Base Function *******************/
- /*******************************************************************************
- * Function Name : LSM303C_MAG_R_WHO_AM_I_
- * Description : Read WHO_AM_I_BIT
- * Input : Pointer to u8_t
- * Output : Status of WHO_AM_I_BIT
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_MAG_R_WHO_AM_I_(void *handle, u8_t *value)
- {
- if( !LSM303C_MAG_ReadReg(handle, LSM303C_MAG_WHO_AM_I_REG, (u8_t *)value, 1) )
- return MEMS_ERROR;
- *value &= LSM303C_MAG_WHO_AM_I_BIT_MASK; //coerce
- *value = *value >> LSM303C_MAG_WHO_AM_I_BIT_POSITION; //mask
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_MAG_W_SystemOperatingMode
- * Description : Write MD
- * Input : LSM303C_MAG_MD_t
- * Output : None
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_MAG_W_SystemOperatingMode(void *handle, LSM303C_MAG_MD_t newValue)
- {
- u8_t value;
- if( !LSM303C_MAG_ReadReg(handle, LSM303C_MAG_CTRL_REG3, &value, 1) )
- return MEMS_ERROR;
- value &= ~LSM303C_MAG_MD_MASK;
- value |= newValue;
-
- if( !LSM303C_MAG_WriteReg(handle, LSM303C_MAG_CTRL_REG3, &value, 1) )
- return MEMS_ERROR;
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_MAG_R_SystemOperatingMode
- * Description : Read MD
- * Input : Pointer to LSM303C_MAG_MD_t
- * Output : Status of MD see LSM303C_MAG_MD_t
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_MAG_R_SystemOperatingMode(void *handle, LSM303C_MAG_MD_t *value)
- {
- if( !LSM303C_MAG_ReadReg(handle, LSM303C_MAG_CTRL_REG3, (u8_t *)value, 1) )
- return MEMS_ERROR;
- *value &= LSM303C_MAG_MD_MASK; //mask
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_MAG_W_BlockDataUpdate
- * Description : Write BDU
- * Input : LSM303C_MAG_BDU_t
- * Output : None
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_MAG_W_BlockDataUpdate(void *handle, LSM303C_MAG_BDU_t newValue)
- {
- u8_t value;
- if( !LSM303C_MAG_ReadReg(handle, LSM303C_MAG_CTRL_REG5, &value, 1) )
- return MEMS_ERROR;
- value &= ~LSM303C_MAG_BDU_MASK;
- value |= newValue;
-
- if( !LSM303C_MAG_WriteReg(handle, LSM303C_MAG_CTRL_REG5, &value, 1) )
- return MEMS_ERROR;
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_MAG_R_BlockDataUpdate
- * Description : Read BDU
- * Input : Pointer to LSM303C_MAG_BDU_t
- * Output : Status of BDU see LSM303C_MAG_BDU_t
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_MAG_R_BlockDataUpdate(void *handle, LSM303C_MAG_BDU_t *value)
- {
- if( !LSM303C_MAG_ReadReg(handle, LSM303C_MAG_CTRL_REG5, (u8_t *)value, 1) )
- return MEMS_ERROR;
- *value &= LSM303C_MAG_BDU_MASK; //mask
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_MAG_W_FullScale
- * Description : Write FS
- * Input : LSM303C_MAG_FS_t
- * Output : None
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_MAG_W_FullScale(void *handle, LSM303C_MAG_FS_t newValue)
- {
- u8_t value;
- if( !LSM303C_MAG_ReadReg(handle, LSM303C_MAG_CTRL_REG2, &value, 1) )
- return MEMS_ERROR;
- value &= ~LSM303C_MAG_FS_MASK;
- value |= newValue;
-
- if( !LSM303C_MAG_WriteReg(handle, LSM303C_MAG_CTRL_REG2, &value, 1) )
- return MEMS_ERROR;
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_MAG_R_FullScale
- * Description : Read FS
- * Input : Pointer to LSM303C_MAG_FS_t
- * Output : Status of FS see LSM303C_MAG_FS_t
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_MAG_R_FullScale(void *handle, LSM303C_MAG_FS_t *value)
- {
- if( !LSM303C_MAG_ReadReg(handle, LSM303C_MAG_CTRL_REG2, (u8_t *)value, 1) )
- return MEMS_ERROR;
- *value &= LSM303C_MAG_FS_MASK; //mask
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_MAG_W_OutputDataRate
- * Description : Write DO
- * Input : LSM303C_MAG_DO_t
- * Output : None
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_MAG_W_OutputDataRate(void *handle, LSM303C_MAG_DO_t newValue)
- {
- u8_t value;
- if( !LSM303C_MAG_ReadReg(handle, LSM303C_MAG_CTRL_REG1, &value, 1) )
- return MEMS_ERROR;
- value &= ~LSM303C_MAG_DO_MASK;
- value |= newValue;
-
- if( !LSM303C_MAG_WriteReg(handle, LSM303C_MAG_CTRL_REG1, &value, 1) )
- return MEMS_ERROR;
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_MAG_R_OutputDataRate
- * Description : Read DO
- * Input : Pointer to LSM303C_MAG_DO_t
- * Output : Status of DO see LSM303C_MAG_DO_t
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_MAG_R_OutputDataRate(void *handle, LSM303C_MAG_DO_t *value)
- {
- if( !LSM303C_MAG_ReadReg(handle, LSM303C_MAG_CTRL_REG1, (u8_t *)value, 1) )
- return MEMS_ERROR;
- *value &= LSM303C_MAG_DO_MASK; //mask
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : status_t LSM303C_MAG_Get_Magnetic(u8_t *buff)
- * Description : Read Magnetic output register
- * Input : pointer to [u8_t]
- * Output : Magnetic buffer u8_t
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_MAG_Get_Magnetic(void *handle, u8_t *buff)
- {
- u8_t i, j, k;
- u8_t numberOfByteForDimension;
-
- numberOfByteForDimension=6/3;
- k=0;
- for (i=0; i<3;i++ )
- {
- for (j=0; j<numberOfByteForDimension;j++ )
- {
- if( !LSM303C_MAG_ReadReg(handle, LSM303C_MAG_OUTX_L+k, &buff[k], 1))
- return MEMS_ERROR;
- k++;
- }
- }
- return MEMS_SUCCESS;
- }
- /**************** Advanced Function *******************/
- /*******************************************************************************
- * Function Name : LSM303C_MAG_W_SelfTest
- * Description : Write ST
- * Input : LSM303C_MAG_ST_t
- * Output : None
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_MAG_W_SelfTest(void *handle, LSM303C_MAG_ST_t newValue)
- {
- u8_t value;
- if( !LSM303C_MAG_ReadReg(handle, LSM303C_MAG_CTRL_REG1, &value, 1) )
- return MEMS_ERROR;
- value &= ~LSM303C_MAG_ST_MASK;
- value |= newValue;
-
- if( !LSM303C_MAG_WriteReg(handle, LSM303C_MAG_CTRL_REG1, &value, 1) )
- return MEMS_ERROR;
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_MAG_R_SelfTest
- * Description : Read ST
- * Input : Pointer to LSM303C_MAG_ST_t
- * Output : Status of ST see LSM303C_MAG_ST_t
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_MAG_R_SelfTest(void *handle, LSM303C_MAG_ST_t *value)
- {
- if( !LSM303C_MAG_ReadReg(handle, LSM303C_MAG_CTRL_REG1, (u8_t *)value, 1) )
- return MEMS_ERROR;
- *value &= LSM303C_MAG_ST_MASK; //mask
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_MAG_W_OperatingModeXY
- * Description : Write OM
- * Input : LSM303C_MAG_OM_t
- * Output : None
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_MAG_W_OperatingModeXY(void *handle, LSM303C_MAG_OM_t newValue)
- {
- u8_t value;
- if( !LSM303C_MAG_ReadReg(handle, LSM303C_MAG_CTRL_REG1, &value, 1) )
- return MEMS_ERROR;
- value &= ~LSM303C_MAG_OM_MASK;
- value |= newValue;
-
- if( !LSM303C_MAG_WriteReg(handle, LSM303C_MAG_CTRL_REG1, &value, 1) )
- return MEMS_ERROR;
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_MAG_R_OperatingModeXY
- * Description : Read OM
- * Input : Pointer to LSM303C_MAG_OM_t
- * Output : Status of OM see LSM303C_MAG_OM_t
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_MAG_R_OperatingModeXY(void *handle, LSM303C_MAG_OM_t *value)
- {
- if( !LSM303C_MAG_ReadReg(handle, LSM303C_MAG_CTRL_REG1, (u8_t *)value, 1) )
- return MEMS_ERROR;
- *value &= LSM303C_MAG_OM_MASK; //mask
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_MAG_W_TemperatureSensor
- * Description : Write TEMP_EN
- * Input : LSM303C_MAG_TEMP_EN_t
- * Output : None
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_MAG_W_TemperatureSensor(void *handle, LSM303C_MAG_TEMP_EN_t newValue)
- {
- u8_t value;
- if( !LSM303C_MAG_ReadReg(handle, LSM303C_MAG_CTRL_REG1, &value, 1) )
- return MEMS_ERROR;
- value &= ~LSM303C_MAG_TEMP_EN_MASK;
- value |= newValue;
-
- if( !LSM303C_MAG_WriteReg(handle, LSM303C_MAG_CTRL_REG1, &value, 1) )
- return MEMS_ERROR;
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_MAG_R_TemperatureSensor
- * Description : Read TEMP_EN
- * Input : Pointer to LSM303C_MAG_TEMP_EN_t
- * Output : Status of TEMP_EN see LSM303C_MAG_TEMP_EN_t
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_MAG_R_TemperatureSensor(void *handle, LSM303C_MAG_TEMP_EN_t *value)
- {
- if( !LSM303C_MAG_ReadReg(handle, LSM303C_MAG_CTRL_REG1, (u8_t *)value, 1) )
- return MEMS_ERROR;
- *value &= LSM303C_MAG_TEMP_EN_MASK; //mask
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_MAG_W_SoftRST
- * Description : Write SOFT_RST
- * Input : LSM303C_MAG_SOFT_RST_t
- * Output : None
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_MAG_W_SoftRST(void *handle, LSM303C_MAG_SOFT_RST_t newValue)
- {
- u8_t value;
- if( !LSM303C_MAG_ReadReg(handle, LSM303C_MAG_CTRL_REG2, &value, 1) )
- return MEMS_ERROR;
- value &= ~LSM303C_MAG_SOFT_RST_MASK;
- value |= newValue;
-
- if( !LSM303C_MAG_WriteReg(handle, LSM303C_MAG_CTRL_REG2, &value, 1) )
- return MEMS_ERROR;
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_MAG_R_SoftRST
- * Description : Read SOFT_RST
- * Input : Pointer to LSM303C_MAG_SOFT_RST_t
- * Output : Status of SOFT_RST see LSM303C_MAG_SOFT_RST_t
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_MAG_R_SoftRST(void *handle, LSM303C_MAG_SOFT_RST_t *value)
- {
- if( !LSM303C_MAG_ReadReg(handle, LSM303C_MAG_CTRL_REG2, (u8_t *)value, 1) )
- return MEMS_ERROR;
- *value &= LSM303C_MAG_SOFT_RST_MASK; //mask
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_MAG_W_Reboot
- * Description : Write REBOOT
- * Input : LSM303C_MAG_REBOOT_t
- * Output : None
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_MAG_W_Reboot(void *handle, LSM303C_MAG_REBOOT_t newValue)
- {
- u8_t value;
- if( !LSM303C_MAG_ReadReg(handle, LSM303C_MAG_CTRL_REG2, &value, 1) )
- return MEMS_ERROR;
- value &= ~LSM303C_MAG_REBOOT_MASK;
- value |= newValue;
-
- if( !LSM303C_MAG_WriteReg(handle, LSM303C_MAG_CTRL_REG2, &value, 1) )
- return MEMS_ERROR;
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_MAG_R_Reboot
- * Description : Read REBOOT
- * Input : Pointer to LSM303C_MAG_REBOOT_t
- * Output : Status of REBOOT see LSM303C_MAG_REBOOT_t
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_MAG_R_Reboot(void *handle, LSM303C_MAG_REBOOT_t *value)
- {
- if( !LSM303C_MAG_ReadReg(handle, LSM303C_MAG_CTRL_REG2, (u8_t *)value, 1) )
- return MEMS_ERROR;
- *value &= LSM303C_MAG_REBOOT_MASK; //mask
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_MAG_W_SerialInterfaceMode
- * Description : Write SIM
- * Input : LSM303C_MAG_SIM_t
- * Output : None
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_MAG_W_SerialInterfaceMode(void *handle, LSM303C_MAG_SIM_t newValue)
- {
- u8_t value;
- if( !LSM303C_MAG_ReadReg(handle, LSM303C_MAG_CTRL_REG3, &value, 1) )
- return MEMS_ERROR;
- value &= ~LSM303C_MAG_SIM_MASK;
- value |= newValue;
-
- if( !LSM303C_MAG_WriteReg(handle, LSM303C_MAG_CTRL_REG3, &value, 1) )
- return MEMS_ERROR;
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_MAG_R_SerialInterfaceMode
- * Description : Read SIM
- * Input : Pointer to LSM303C_MAG_SIM_t
- * Output : Status of SIM see LSM303C_MAG_SIM_t
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_MAG_R_SerialInterfaceMode(void *handle, LSM303C_MAG_SIM_t *value)
- {
- if( !LSM303C_MAG_ReadReg(handle, LSM303C_MAG_CTRL_REG3, (u8_t *)value, 1) )
- return MEMS_ERROR;
- *value &= LSM303C_MAG_SIM_MASK; //mask
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_MAG_W_FastLowPowerXYZ
- * Description : Write LP
- * Input : LSM303C_MAG_LP_t
- * Output : None
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_MAG_W_FastLowPowerXYZ(void *handle, LSM303C_MAG_LP_t newValue)
- {
- u8_t value;
- if( !LSM303C_MAG_ReadReg(handle, LSM303C_MAG_CTRL_REG3, &value, 1) )
- return MEMS_ERROR;
- value &= ~LSM303C_MAG_LP_MASK;
- value |= newValue;
-
- if( !LSM303C_MAG_WriteReg(handle, LSM303C_MAG_CTRL_REG3, &value, 1) )
- return MEMS_ERROR;
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_MAG_R_FastLowPowerXYZ
- * Description : Read LP
- * Input : Pointer to LSM303C_MAG_LP_t
- * Output : Status of LP see LSM303C_MAG_LP_t
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_MAG_R_FastLowPowerXYZ(void *handle, LSM303C_MAG_LP_t *value)
- {
- if( !LSM303C_MAG_ReadReg(handle, LSM303C_MAG_CTRL_REG3, (u8_t *)value, 1) )
- return MEMS_ERROR;
- *value &= LSM303C_MAG_LP_MASK; //mask
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_MAG_W_LittleBigEndianInversion
- * Description : Write BLE
- * Input : LSM303C_MAG_BLE_t
- * Output : None
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_MAG_W_LittleBigEndianInversion(void *handle, LSM303C_MAG_BLE_t newValue)
- {
- u8_t value;
- if( !LSM303C_MAG_ReadReg(handle, LSM303C_MAG_CTRL_REG4, &value, 1) )
- return MEMS_ERROR;
- value &= ~LSM303C_MAG_BLE_MASK;
- value |= newValue;
-
- if( !LSM303C_MAG_WriteReg(handle, LSM303C_MAG_CTRL_REG4, &value, 1) )
- return MEMS_ERROR;
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_MAG_R_LittleBigEndianInversion
- * Description : Read BLE
- * Input : Pointer to LSM303C_MAG_BLE_t
- * Output : Status of BLE see LSM303C_MAG_BLE_t
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_MAG_R_LittleBigEndianInversion(void *handle, LSM303C_MAG_BLE_t *value)
- {
- if( !LSM303C_MAG_ReadReg(handle, LSM303C_MAG_CTRL_REG4, (u8_t *)value, 1) )
- return MEMS_ERROR;
- *value &= LSM303C_MAG_BLE_MASK; //mask
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_MAG_W_OperatingModeZ
- * Description : Write OMZ
- * Input : LSM303C_MAG_OMZ_t
- * Output : None
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_MAG_W_OperatingModeZ(void *handle, LSM303C_MAG_OMZ_t newValue)
- {
- u8_t value;
- if( !LSM303C_MAG_ReadReg(handle, LSM303C_MAG_CTRL_REG4, &value, 1) )
- return MEMS_ERROR;
- value &= ~LSM303C_MAG_OMZ_MASK;
- value |= newValue;
-
- if( !LSM303C_MAG_WriteReg(handle, LSM303C_MAG_CTRL_REG4, &value, 1) )
- return MEMS_ERROR;
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_MAG_R_OperatingModeZ
- * Description : Read OMZ
- * Input : Pointer to LSM303C_MAG_OMZ_t
- * Output : Status of OMZ see LSM303C_MAG_OMZ_t
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_MAG_R_OperatingModeZ(void *handle, LSM303C_MAG_OMZ_t *value)
- {
- if( !LSM303C_MAG_ReadReg(handle, LSM303C_MAG_CTRL_REG4, (u8_t *)value, 1) )
- return MEMS_ERROR;
- *value &= LSM303C_MAG_OMZ_MASK; //mask
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_MAG_R_NewXData
- * Description : Read XDA
- * Input : Pointer to LSM303C_MAG_XDA_t
- * Output : Status of XDA see LSM303C_MAG_XDA_t
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_MAG_R_NewXData(void *handle, LSM303C_MAG_XDA_t *value)
- {
- if( !LSM303C_MAG_ReadReg(handle, LSM303C_MAG_STATUS_REG, (u8_t *)value, 1) )
- return MEMS_ERROR;
- *value &= LSM303C_MAG_XDA_MASK; //mask
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_MAG_R_NewYData
- * Description : Read YDA
- * Input : Pointer to LSM303C_MAG_YDA_t
- * Output : Status of YDA see LSM303C_MAG_YDA_t
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_MAG_R_NewYData(void *handle, LSM303C_MAG_YDA_t *value)
- {
- if( !LSM303C_MAG_ReadReg(handle, LSM303C_MAG_STATUS_REG, (u8_t *)value, 1) )
- return MEMS_ERROR;
- *value &= LSM303C_MAG_YDA_MASK; //mask
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_MAG_R_NewZData
- * Description : Read ZDA
- * Input : Pointer to LSM303C_MAG_ZDA_t
- * Output : Status of ZDA see LSM303C_MAG_ZDA_t
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_MAG_R_NewZData(void *handle, LSM303C_MAG_ZDA_t *value)
- {
- if( !LSM303C_MAG_ReadReg(handle, LSM303C_MAG_STATUS_REG, (u8_t *)value, 1) )
- return MEMS_ERROR;
- *value &= LSM303C_MAG_ZDA_MASK; //mask
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_MAG_R_NewXYZData
- * Description : Read ZYXDA
- * Input : Pointer to LSM303C_MAG_ZYXDA_t
- * Output : Status of ZYXDA see LSM303C_MAG_ZYXDA_t
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_MAG_R_NewXYZData(void *handle, LSM303C_MAG_ZYXDA_t *value)
- {
- if( !LSM303C_MAG_ReadReg(handle, LSM303C_MAG_STATUS_REG, (u8_t *)value, 1) )
- return MEMS_ERROR;
- *value &= LSM303C_MAG_ZYXDA_MASK; //mask
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_MAG_R_DataXOverrun
- * Description : Read XOR
- * Input : Pointer to LSM303C_MAG_XOR_t
- * Output : Status of XOR see LSM303C_MAG_XOR_t
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_MAG_R_DataXOverrun(void *handle, LSM303C_MAG_XOR_t *value)
- {
- if( !LSM303C_MAG_ReadReg(handle, LSM303C_MAG_STATUS_REG, (u8_t *)value, 1) )
- return MEMS_ERROR;
- *value &= LSM303C_MAG_XOR_MASK; //mask
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_MAG_R_DataYOverrun
- * Description : Read YOR
- * Input : Pointer to LSM303C_MAG_YOR_t
- * Output : Status of YOR see LSM303C_MAG_YOR_t
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_MAG_R_DataYOverrun(void *handle, LSM303C_MAG_YOR_t *value)
- {
- if( !LSM303C_MAG_ReadReg(handle, LSM303C_MAG_STATUS_REG, (u8_t *)value, 1) )
- return MEMS_ERROR;
- *value &= LSM303C_MAG_YOR_MASK; //mask
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_MAG_R_DataZOverrun
- * Description : Read ZOR
- * Input : Pointer to LSM303C_MAG_ZOR_t
- * Output : Status of ZOR see LSM303C_MAG_ZOR_t
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_MAG_R_DataZOverrun(void *handle, LSM303C_MAG_ZOR_t *value)
- {
- if( !LSM303C_MAG_ReadReg(handle, LSM303C_MAG_STATUS_REG, (u8_t *)value, 1) )
- return MEMS_ERROR;
- *value &= LSM303C_MAG_ZOR_MASK; //mask
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_MAG_R_DataXYZOverrun
- * Description : Read ZYXOR
- * Input : Pointer to LSM303C_MAG_ZYXOR_t
- * Output : Status of ZYXOR see LSM303C_MAG_ZYXOR_t
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_MAG_R_DataXYZOverrun(void *handle, LSM303C_MAG_ZYXOR_t *value)
- {
- if( !LSM303C_MAG_ReadReg(handle, LSM303C_MAG_STATUS_REG, (u8_t *)value, 1) )
- return MEMS_ERROR;
- *value &= LSM303C_MAG_ZYXOR_MASK; //mask
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_MAG_W_InterruptEnable
- * Description : Write IEN
- * Input : LSM303C_MAG_IEN_t
- * Output : None
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_MAG_W_InterruptEnable(void *handle, LSM303C_MAG_IEN_t newValue)
- {
- u8_t value;
- if( !LSM303C_MAG_ReadReg(handle, LSM303C_MAG_INT_CFG, &value, 1) )
- return MEMS_ERROR;
- value &= ~LSM303C_MAG_IEN_MASK;
- value |= newValue;
-
- if( !LSM303C_MAG_WriteReg(handle, LSM303C_MAG_INT_CFG, &value, 1) )
- return MEMS_ERROR;
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_MAG_R_InterruptEnable
- * Description : Read IEN
- * Input : Pointer to LSM303C_MAG_IEN_t
- * Output : Status of IEN see LSM303C_MAG_IEN_t
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_MAG_R_InterruptEnable(void *handle, LSM303C_MAG_IEN_t *value)
- {
- if( !LSM303C_MAG_ReadReg(handle, LSM303C_MAG_INT_CFG, (u8_t *)value, 1) )
- return MEMS_ERROR;
- *value &= LSM303C_MAG_IEN_MASK; //mask
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_MAG_W_LatchInterruptRq
- * Description : Write LIR
- * Input : LSM303C_MAG_LIR_t
- * Output : None
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_MAG_W_LatchInterruptRq(void *handle, LSM303C_MAG_LIR_t newValue)
- {
- u8_t value;
- if( !LSM303C_MAG_ReadReg(handle, LSM303C_MAG_INT_CFG, &value, 1) )
- return MEMS_ERROR;
- value &= ~LSM303C_MAG_LIR_MASK;
- value |= newValue;
-
- if( !LSM303C_MAG_WriteReg(handle, LSM303C_MAG_INT_CFG, &value, 1) )
- return MEMS_ERROR;
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_MAG_R_LatchInterruptRq
- * Description : Read LIR
- * Input : Pointer to LSM303C_MAG_LIR_t
- * Output : Status of LIR see LSM303C_MAG_LIR_t
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_MAG_R_LatchInterruptRq(void *handle, LSM303C_MAG_LIR_t *value)
- {
- if( !LSM303C_MAG_ReadReg(handle, LSM303C_MAG_INT_CFG, (u8_t *)value, 1) )
- return MEMS_ERROR;
- *value &= LSM303C_MAG_LIR_MASK; //mask
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_MAG_W_InterruptActive
- * Description : Write IEA
- * Input : LSM303C_MAG_IEA_t
- * Output : None
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_MAG_W_InterruptActive(void *handle, LSM303C_MAG_IEA_t newValue)
- {
- u8_t value;
- if( !LSM303C_MAG_ReadReg(handle, LSM303C_MAG_INT_CFG, &value, 1) )
- return MEMS_ERROR;
- value &= ~LSM303C_MAG_IEA_MASK;
- value |= newValue;
-
- if( !LSM303C_MAG_WriteReg(handle, LSM303C_MAG_INT_CFG, &value, 1) )
- return MEMS_ERROR;
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_MAG_R_InterruptActive
- * Description : Read IEA
- * Input : Pointer to LSM303C_MAG_IEA_t
- * Output : Status of IEA see LSM303C_MAG_IEA_t
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_MAG_R_InterruptActive(void *handle, LSM303C_MAG_IEA_t *value)
- {
- if( !LSM303C_MAG_ReadReg(handle, LSM303C_MAG_INT_CFG, (u8_t *)value, 1) )
- return MEMS_ERROR;
- *value &= LSM303C_MAG_IEA_MASK; //mask
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_MAG_W_InterruptOnZ
- * Description : Write ZIEN
- * Input : LSM303C_MAG_ZIEN_t
- * Output : None
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_MAG_W_InterruptOnZ(void *handle, LSM303C_MAG_ZIEN_t newValue)
- {
- u8_t value;
- if( !LSM303C_MAG_ReadReg(handle, LSM303C_MAG_INT_CFG, &value, 1) )
- return MEMS_ERROR;
- value &= ~LSM303C_MAG_ZIEN_MASK;
- value |= newValue;
-
- if( !LSM303C_MAG_WriteReg(handle, LSM303C_MAG_INT_CFG, &value, 1) )
- return MEMS_ERROR;
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_MAG_R_InterruptOnZ
- * Description : Read ZIEN
- * Input : Pointer to LSM303C_MAG_ZIEN_t
- * Output : Status of ZIEN see LSM303C_MAG_ZIEN_t
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_MAG_R_InterruptOnZ(void *handle, LSM303C_MAG_ZIEN_t *value)
- {
- if( !LSM303C_MAG_ReadReg(handle, LSM303C_MAG_INT_CFG, (u8_t *)value, 1) )
- return MEMS_ERROR;
- *value &= LSM303C_MAG_ZIEN_MASK; //mask
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_MAG_W_InterruptOnY
- * Description : Write YIEN
- * Input : LSM303C_MAG_YIEN_t
- * Output : None
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_MAG_W_InterruptOnY(void *handle, LSM303C_MAG_YIEN_t newValue)
- {
- u8_t value;
- if( !LSM303C_MAG_ReadReg(handle, LSM303C_MAG_INT_CFG, &value, 1) )
- return MEMS_ERROR;
- value &= ~LSM303C_MAG_YIEN_MASK;
- value |= newValue;
-
- if( !LSM303C_MAG_WriteReg(handle, LSM303C_MAG_INT_CFG, &value, 1) )
- return MEMS_ERROR;
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_MAG_R_InterruptOnY
- * Description : Read YIEN
- * Input : Pointer to LSM303C_MAG_YIEN_t
- * Output : Status of YIEN see LSM303C_MAG_YIEN_t
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_MAG_R_InterruptOnY(void *handle, LSM303C_MAG_YIEN_t *value)
- {
- if( !LSM303C_MAG_ReadReg(handle, LSM303C_MAG_INT_CFG, (u8_t *)value, 1) )
- return MEMS_ERROR;
- *value &= LSM303C_MAG_YIEN_MASK; //mask
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_MAG_W_InterruptOnX
- * Description : Write XIEN
- * Input : LSM303C_MAG_XIEN_t
- * Output : None
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_MAG_W_InterruptOnX(void *handle, LSM303C_MAG_XIEN_t newValue)
- {
- u8_t value;
- if( !LSM303C_MAG_ReadReg(handle, LSM303C_MAG_INT_CFG, &value, 1) )
- return MEMS_ERROR;
- value &= ~LSM303C_MAG_XIEN_MASK;
- value |= newValue;
-
- if( !LSM303C_MAG_WriteReg(handle, LSM303C_MAG_INT_CFG, &value, 1) )
- return MEMS_ERROR;
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_MAG_R_InterruptOnX
- * Description : Read XIEN
- * Input : Pointer to LSM303C_MAG_XIEN_t
- * Output : Status of XIEN see LSM303C_MAG_XIEN_t
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_MAG_R_InterruptOnX(void *handle, LSM303C_MAG_XIEN_t *value)
- {
- if( !LSM303C_MAG_ReadReg(handle, LSM303C_MAG_INT_CFG, (u8_t *)value, 1) )
- return MEMS_ERROR;
- *value &= LSM303C_MAG_XIEN_MASK; //mask
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_MAG_W_InterruptFlag
- * Description : Write INT
- * Input : LSM303C_MAG_INT_t
- * Output : None
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_MAG_W_InterruptFlag(void *handle, LSM303C_MAG_INT_t newValue)
- {
- u8_t value;
- if( !LSM303C_MAG_ReadReg(handle, LSM303C_MAG_INT_SRC, &value, 1) )
- return MEMS_ERROR;
- value &= ~LSM303C_MAG_INT_MASK;
- value |= newValue;
-
- if( !LSM303C_MAG_WriteReg(handle, LSM303C_MAG_INT_SRC, &value, 1) )
- return MEMS_ERROR;
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_MAG_R_InterruptFlag
- * Description : Read INT
- * Input : Pointer to LSM303C_MAG_INT_t
- * Output : Status of INT see LSM303C_MAG_INT_t
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_MAG_R_InterruptFlag(void *handle, LSM303C_MAG_INT_t *value)
- {
- if( !LSM303C_MAG_ReadReg(handle, LSM303C_MAG_INT_SRC, (u8_t *)value, 1) )
- return MEMS_ERROR;
- *value &= LSM303C_MAG_INT_MASK; //mask
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_MAG_W_MagneticFieldOverflow
- * Description : Write MROI
- * Input : LSM303C_MAG_MROI_t
- * Output : None
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_MAG_W_MagneticFieldOverflow(void *handle, LSM303C_MAG_MROI_t newValue)
- {
- u8_t value;
- if( !LSM303C_MAG_ReadReg(handle, LSM303C_MAG_INT_SRC, &value, 1) )
- return MEMS_ERROR;
- value &= ~LSM303C_MAG_MROI_MASK;
- value |= newValue;
-
- if( !LSM303C_MAG_WriteReg(handle, LSM303C_MAG_INT_SRC, &value, 1) )
- return MEMS_ERROR;
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_MAG_R_MagneticFieldOverflow
- * Description : Read MROI
- * Input : Pointer to LSM303C_MAG_MROI_t
- * Output : Status of MROI see LSM303C_MAG_MROI_t
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_MAG_R_MagneticFieldOverflow(void *handle, LSM303C_MAG_MROI_t *value)
- {
- if( !LSM303C_MAG_ReadReg(handle, LSM303C_MAG_INT_SRC, (u8_t *)value, 1) )
- return MEMS_ERROR;
- *value &= LSM303C_MAG_MROI_MASK; //mask
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_MAG_W_NegativeThresholdFlagZ
- * Description : Write NTH_Z
- * Input : LSM303C_MAG_NTH_Z_t
- * Output : None
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_MAG_W_NegativeThresholdFlagZ(void *handle, LSM303C_MAG_NTH_Z_t newValue)
- {
- u8_t value;
- if( !LSM303C_MAG_ReadReg(handle, LSM303C_MAG_INT_SRC, &value, 1) )
- return MEMS_ERROR;
- value &= ~LSM303C_MAG_NTH_Z_MASK;
- value |= newValue;
-
- if( !LSM303C_MAG_WriteReg(handle, LSM303C_MAG_INT_SRC, &value, 1) )
- return MEMS_ERROR;
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_MAG_R_NegativeThresholdFlagZ
- * Description : Read NTH_Z
- * Input : Pointer to LSM303C_MAG_NTH_Z_t
- * Output : Status of NTH_Z see LSM303C_MAG_NTH_Z_t
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_MAG_R_NegativeThresholdFlagZ(void *handle, LSM303C_MAG_NTH_Z_t *value)
- {
- if( !LSM303C_MAG_ReadReg(handle, LSM303C_MAG_INT_SRC, (u8_t *)value, 1) )
- return MEMS_ERROR;
- *value &= LSM303C_MAG_NTH_Z_MASK; //mask
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_MAG_W_NegativeThresholdFlagY
- * Description : Write NTH_Y
- * Input : LSM303C_MAG_NTH_Y_t
- * Output : None
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_MAG_W_NegativeThresholdFlagY(void *handle, LSM303C_MAG_NTH_Y_t newValue)
- {
- u8_t value;
- if( !LSM303C_MAG_ReadReg(handle, LSM303C_MAG_INT_SRC, &value, 1) )
- return MEMS_ERROR;
- value &= ~LSM303C_MAG_NTH_Y_MASK;
- value |= newValue;
-
- if( !LSM303C_MAG_WriteReg(handle, LSM303C_MAG_INT_SRC, &value, 1) )
- return MEMS_ERROR;
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_MAG_R_NegativeThresholdFlagY
- * Description : Read NTH_Y
- * Input : Pointer to LSM303C_MAG_NTH_Y_t
- * Output : Status of NTH_Y see LSM303C_MAG_NTH_Y_t
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_MAG_R_NegativeThresholdFlagY(void *handle, LSM303C_MAG_NTH_Y_t *value)
- {
- if( !LSM303C_MAG_ReadReg(handle, LSM303C_MAG_INT_SRC, (u8_t *)value, 1) )
- return MEMS_ERROR;
- *value &= LSM303C_MAG_NTH_Y_MASK; //mask
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_MAG_W_NegativeThresholdFlagX
- * Description : Write NTH_X
- * Input : LSM303C_MAG_NTH_X_t
- * Output : None
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_MAG_W_NegativeThresholdFlagX(void *handle, LSM303C_MAG_NTH_X_t newValue)
- {
- u8_t value;
- if( !LSM303C_MAG_ReadReg(handle, LSM303C_MAG_INT_SRC, &value, 1) )
- return MEMS_ERROR;
- value &= ~LSM303C_MAG_NTH_X_MASK;
- value |= newValue;
-
- if( !LSM303C_MAG_WriteReg(handle, LSM303C_MAG_INT_SRC, &value, 1) )
- return MEMS_ERROR;
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_MAG_R_NegativeThresholdFlagX
- * Description : Read NTH_X
- * Input : Pointer to LSM303C_MAG_NTH_X_t
- * Output : Status of NTH_X see LSM303C_MAG_NTH_X_t
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_MAG_R_NegativeThresholdFlagX(void *handle, LSM303C_MAG_NTH_X_t *value)
- {
- if( !LSM303C_MAG_ReadReg(handle, LSM303C_MAG_INT_SRC, (u8_t *)value, 1) )
- return MEMS_ERROR;
- *value &= LSM303C_MAG_NTH_X_MASK; //mask
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_MAG_W_PositiveThresholdFlagZ
- * Description : Write PTH_Z
- * Input : LSM303C_MAG_PTH_Z_t
- * Output : None
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_MAG_W_PositiveThresholdFlagZ(void *handle, LSM303C_MAG_PTH_Z_t newValue)
- {
- u8_t value;
- if( !LSM303C_MAG_ReadReg(handle, LSM303C_MAG_INT_SRC, &value, 1) )
- return MEMS_ERROR;
- value &= ~LSM303C_MAG_PTH_Z_MASK;
- value |= newValue;
-
- if( !LSM303C_MAG_WriteReg(handle, LSM303C_MAG_INT_SRC, &value, 1) )
- return MEMS_ERROR;
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_MAG_R_PositiveThresholdFlagZ
- * Description : Read PTH_Z
- * Input : Pointer to LSM303C_MAG_PTH_Z_t
- * Output : Status of PTH_Z see LSM303C_MAG_PTH_Z_t
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_MAG_R_PositiveThresholdFlagZ(void *handle, LSM303C_MAG_PTH_Z_t *value)
- {
- if( !LSM303C_MAG_ReadReg(handle, LSM303C_MAG_INT_SRC, (u8_t *)value, 1) )
- return MEMS_ERROR;
- *value &= LSM303C_MAG_PTH_Z_MASK; //mask
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_MAG_W_PositiveThresholdFlagY
- * Description : Write PTH_Y
- * Input : LSM303C_MAG_PTH_Y_t
- * Output : None
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_MAG_W_PositiveThresholdFlagY(void *handle, LSM303C_MAG_PTH_Y_t newValue)
- {
- u8_t value;
- if( !LSM303C_MAG_ReadReg(handle, LSM303C_MAG_INT_SRC, &value, 1) )
- return MEMS_ERROR;
- value &= ~LSM303C_MAG_PTH_Y_MASK;
- value |= newValue;
-
- if( !LSM303C_MAG_WriteReg(handle, LSM303C_MAG_INT_SRC, &value, 1) )
- return MEMS_ERROR;
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_MAG_R_PositiveThresholdFlagY
- * Description : Read PTH_Y
- * Input : Pointer to LSM303C_MAG_PTH_Y_t
- * Output : Status of PTH_Y see LSM303C_MAG_PTH_Y_t
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_MAG_R_PositiveThresholdFlagY(void *handle, LSM303C_MAG_PTH_Y_t *value)
- {
- if( !LSM303C_MAG_ReadReg(handle, LSM303C_MAG_INT_SRC, (u8_t *)value, 1) )
- return MEMS_ERROR;
- *value &= LSM303C_MAG_PTH_Y_MASK; //mask
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_MAG_W_PositiveThresholdFlagX
- * Description : Write PTH_X
- * Input : LSM303C_MAG_PTH_X_t
- * Output : None
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_MAG_W_PositiveThresholdFlagX(void *handle, LSM303C_MAG_PTH_X_t newValue)
- {
- u8_t value;
- if( !LSM303C_MAG_ReadReg(handle, LSM303C_MAG_INT_SRC, &value, 1) )
- return MEMS_ERROR;
- value &= ~LSM303C_MAG_PTH_X_MASK;
- value |= newValue;
-
- if( !LSM303C_MAG_WriteReg(handle, LSM303C_MAG_INT_SRC, &value, 1) )
- return MEMS_ERROR;
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : LSM303C_MAG_R_PositiveThresholdFlagX
- * Description : Read PTH_X
- * Input : Pointer to LSM303C_MAG_PTH_X_t
- * Output : Status of PTH_X see LSM303C_MAG_PTH_X_t
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_MAG_R_PositiveThresholdFlagX(void *handle, LSM303C_MAG_PTH_X_t *value)
- {
- if( !LSM303C_MAG_ReadReg(handle, LSM303C_MAG_INT_SRC, (u8_t *)value, 1) )
- return MEMS_ERROR;
- *value &= LSM303C_MAG_PTH_X_MASK; //mask
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : status_t LSM303C_MAG_Get_Temperature(u8_t *buff)
- * Description : Read Temperature output register
- * Input : pointer to [u8_t]
- * Output : Temperature buffer u8_t
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_MAG_Get_Temperature(void *handle, u8_t *buff)
- {
- u8_t i, j, k;
- u8_t numberOfByteForDimension;
-
- numberOfByteForDimension=2/1;
- k=0;
- for (i=0; i<1;i++ )
- {
- for (j=0; j<numberOfByteForDimension;j++ )
- {
- if( !LSM303C_MAG_ReadReg(handle, LSM303C_MAG_TEMP_OUT_L+k, &buff[k], 1))
- return MEMS_ERROR;
- k++;
- }
- }
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : status_t LSM303C_MAG_Set_MagneticThreshold(u8_t *buff)
- * Description : Set MagneticThreshold data row
- * Input : pointer to [u8_t]
- * Output : None
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_MAG_Set_MagneticThreshold(void *handle, u8_t *buff)
- {
- u8_t i;
- for (i=0; i<2;i++ )
- {
- if( !LSM303C_MAG_WriteReg(handle, LSM303C_MAG_INT_THS_L+i, &buff[i], 1) )
- return MEMS_ERROR;
- }
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : status_t LSM303C_MAG_Get_MagneticThreshold(u8_t *buff)
- * Description : Read MagneticThreshold output register
- * Input : pointer to [u8_t]
- * Output : MagneticThreshold buffer u8_t
- * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
- *******************************************************************************/
- status_t LSM303C_MAG_Get_MagneticThreshold(void *handle, u8_t *buff)
- {
- u8_t i, j, k;
- u8_t numberOfByteForDimension;
-
- numberOfByteForDimension=2/1;
- k=0;
- for (i=0; i<1;i++ )
- {
- for (j=0; j<numberOfByteForDimension;j++ )
- {
- if( !LSM303C_MAG_ReadReg(handle, LSM303C_MAG_INT_THS_L+k, &buff[k], 1))
- return MEMS_ERROR;
- k++;
- }
- }
- return MEMS_SUCCESS;
- }
- /*******************************************************************************
- * Function Name : SwapHighLowByte
- * Description : Swap High/low byte in multiple byte values
- * It works with minimum 2 byte for every dimension.
- * Example x,y,z with 2 byte for every dimension
- *
- * Input : bufferToSwap -> buffer to swap
- * numberOfByte -> the buffer length in byte
- * dimension -> number of dimension
- *
- * Output : bufferToSwap -> buffer swapped
- * Return : None
- *******************************************************************************/
- void LSM303C_MAG_SwapHighLowByte(u8_t *bufferToSwap, u8_t numberOfByte, u8_t dimension)
- {
- u8_t numberOfByteForDimension, i, j;
- u8_t tempValue[10];
-
- numberOfByteForDimension=numberOfByte/dimension;
-
- for (i=0; i<dimension;i++ )
- {
- for (j=0; j<numberOfByteForDimension;j++ )
- tempValue[j]=bufferToSwap[j+i*numberOfByteForDimension];
- for (j=0; j<numberOfByteForDimension;j++ )
- *(bufferToSwap+i*(numberOfByteForDimension)+j)=*(tempValue+(numberOfByteForDimension-1)-j);
- }
- }
|