LSM303C_ACC_driver.c 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186
  1. /******************** (C) COPYRIGHT 2016 STMicroelectronics ********************
  2. * File Name : LSM303C_ACC_driver.c
  3. * Author : MEMS Application Team
  4. * Version : v1.1
  5. * Date : 22 Nov 2016
  6. * Description : LSM303C Platform Independent Driver
  7. *
  8. ********************************************************************************
  9. * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  10. * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
  11. * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
  12. * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
  13. * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
  14. * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  15. *
  16. * THIS SOFTWARE IS SPECIFICALLY DESIGNED FOR EXCLUSIVE USE WITH ST PARTS.
  17. *******************************************************************************/
  18. /* Includes ------------------------------------------------------------------*/
  19. #include "includes.h"
  20. //EXAMPLE to fill LSM303C_ACC_ReadReg and LSM303C_ACC_WriteReg
  21. /* Private typedef -----------------------------------------------------------*/
  22. /* Private define ------------------------------------------------------------*/
  23. /* Private macro -------------------------------------------------------------*/
  24. /* Private variables ---------------------------------------------------------*/
  25. /* Private function prototypes -----------------------------------------------*/
  26. /* Private functions ---------------------------------------------------------*/
  27. /************** Generic Function *******************/
  28. /*******************************************************************************
  29. * Function Name : LSM303C_ACC_WriteReg
  30. * Description : Generic Writing function. It must be fullfilled with either
  31. * : I2C or SPI writing function
  32. * Input : Register Address, ptr to buffer to be written,
  33. * length of buffer
  34. * Output : None
  35. * Return : None
  36. *******************************************************************************/
  37. status_t LSM303C_ACC_WriteReg(void *handle, u8_t Reg, u8_t *Bufp, u16_t len)
  38. {
  39. // HAL_I2C_Mem_Write(&hi2c1, LSM303C_ACC_MEMS_I2C_ADDRESS, Reg, I2C_MEMADD_SIZE_8BIT,
  40. // Bufp, len, 1000);
  41. // return MEMS_SUCCESS;
  42. //OperationI2C(LSM303C_ACC_MEMS_I2C_ADDRESS,&Reg,1);
  43. #if 0
  44. IIC_Start();
  45. IIC_Send_Byte(LSM303C_ACC_MEMS_I2C_ADDRESS);
  46. if(IIC_Wait_Ack())
  47. {
  48. IIC_Stop();//释放总线
  49. return 1;//没应答则退出
  50. }
  51. IIC_Send_Byte(Reg);
  52. IIC_Wait_Ack();
  53. IIC_Send_Byte(Bufp[0]);
  54. IIC_Wait_Ack();
  55. IIC_Stop();
  56. #else
  57. unsigned short addr;
  58. unsigned short i;
  59. MOTION_CS_XL_LOW;
  60. DelayNs(5);
  61. //写0x23
  62. addr=Reg;
  63. addr<<=8;
  64. addr|=*Bufp;
  65. for(i=0;i<16;i++)
  66. {
  67. MOTION_CLK_LOW;
  68. DelayNs(2);
  69. if((addr<<i)&0x8000) MOTION_SDA_HIGH;
  70. else MOTION_SDA_LOW;
  71. DelayNs(2);
  72. MOTION_CLK_HIGH;
  73. DelayNs(5);
  74. }
  75. MOTION_CS_XL_HIGH;
  76. DelayNs(5);
  77. return MEMS_SUCCESS;
  78. #endif
  79. }
  80. /*******************************************************************************
  81. * Function Name : LSM303C_ACC_ReadReg
  82. * Description : Generic Reading function. It must be fullfilled with either
  83. * : I2C or SPI writing function
  84. * Input : Register Address, ptr to buffer to be read,
  85. * length of buffer
  86. * Output : None
  87. * Return : None
  88. *******************************************************************************/
  89. status_t LSM303C_ACC_ReadReg(void *handle, u8_t Reg, u8_t *Bufp, u16_t len)
  90. {
  91. //HAL_I2C_Mem_Read(&hi2c1, LSM303C_ACC_MEMS_I2C_ADDRESS, Reg, I2C_MEMADD_SIZE_8BIT, Bufp, len, 1000);
  92. // OperationI2C(LSM303C_ACC_MEMS_I2C_ADDRESS,&Reg,1);
  93. // return OperationI2C(LSM303C_ACC_MEMS_I2C_ADDRESS|0x01,Bufp,1);
  94. #if 0
  95. unsigned char REG_data;
  96. IIC_Start();
  97. IIC_Send_Byte(LSM303C_ACC_MEMS_I2C_ADDRESS);//发写命令
  98. if(IIC_Wait_Ack())
  99. {
  100. IIC_Stop();//释放总线
  101. return 0;//没应答则退出
  102. }
  103. IIC_Send_Byte(Reg);
  104. IIC_Wait_Ack();
  105. IIC_Start();
  106. IIC_Send_Byte(LSM303C_ACC_MEMS_I2C_ADDRESS|0x01);//发读命令
  107. IIC_Wait_Ack();
  108. Bufp[0] = IIC_Read_Byte(0);
  109. IIC_Stop();
  110. return MEMS_SUCCESS;
  111. #else
  112. unsigned short addr;
  113. unsigned short dat=0,i;
  114. if(Reg>0x7F)return 0;
  115. addr=0x80|Reg;
  116. MOTION_CS_XL_LOW;
  117. DelayNs(5);
  118. //写
  119. for(i=0;i<8;i++)
  120. {
  121. DelayNs(2);
  122. MOTION_CLK_LOW;
  123. DelayNs(2);
  124. if((addr<<i)&0x80) MOTION_SDA_HIGH;
  125. else MOTION_SDA_LOW;
  126. DelayNs(2);
  127. MOTION_CLK_HIGH;
  128. DelayNs(2);
  129. }
  130. //读
  131. for(i=0;i<8;i++)
  132. {
  133. dat<<=1;
  134. DelayNs(2);
  135. MOTION_CLK_LOW;
  136. DelayNs(5);
  137. MOTION_CLK_HIGH;
  138. DelayNs(2);
  139. if(MOTION_SDA_READ) dat|=0x01;
  140. }
  141. *Bufp = dat;
  142. MOTION_CS_XL_HIGH;
  143. DelayNs(5);
  144. return MEMS_SUCCESS;
  145. #endif
  146. }
  147. /**************** Base Function *******************/
  148. /*******************************************************************************
  149. * Function Name : LSM303C_ACC_SetODR
  150. * Description : Sets LIS2HH Output Data Rate
  151. * Input : Set Output data rate [LSM303C_ACC_ODR_t]
  152. * Output : None
  153. * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
  154. *******************************************************************************/
  155. status_t LSM303C_ACC_SetODR(void *handle, LSM303C_ACC_ODR_t ov){
  156. u8_t value;
  157. if( !LSM303C_ACC_ReadReg(handle, LSM303C_ACC_CTRL1, &value, 1) )
  158. return MEMS_ERROR;
  159. value &= ~LSM303C_ACC_ODR_MASK; //mask
  160. value |= ov;
  161. if( !LSM303C_ACC_WriteReg(handle, LSM303C_ACC_CTRL1, &value, 1) )
  162. return MEMS_ERROR;
  163. return MEMS_SUCCESS;
  164. }
  165. /*******************************************************************************
  166. * Function Name : LSM303C_ACC_SetFullScale
  167. * Description : set LIS2HH Full scale
  168. * Input : set LIS2HH Full scale [LSM303C_ACC_FS_t]
  169. * Output : None
  170. * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
  171. *******************************************************************************/
  172. status_t LSM303C_ACC_SetFullScale(void *handle, LSM303C_ACC_FS_t ov){
  173. u8_t value;
  174. if( !LSM303C_ACC_ReadReg(handle, LSM303C_ACC_CTRL4, &value, 1) )
  175. return MEMS_ERROR;
  176. value &= ~LSM303C_ACC_FS_8g; //mask
  177. value |= ov;
  178. if( !LSM303C_ACC_WriteReg(handle, LSM303C_ACC_CTRL4, &value, 1) )
  179. return MEMS_ERROR;
  180. return MEMS_SUCCESS;
  181. }
  182. /*******************************************************************************
  183. * Function Name : LSM303C_ACC_BlockDataUpdate
  184. * Description : Enable/Disable LIS2HH BlockDataUpdate
  185. * Input : Enable/Disable LIS2HH BlockDataUpdate[LSM303C_ACC_BDU_t]
  186. * Output : None
  187. * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
  188. *******************************************************************************/
  189. status_t LSM303C_ACC_BlockDataUpdate(void *handle, LSM303C_ACC_BDU_t ov){
  190. u8_t value;
  191. if( !LSM303C_ACC_ReadReg(handle, LSM303C_ACC_CTRL1, &value, 1) )
  192. return MEMS_ERROR;
  193. value &= ~LSM303C_ACC_BDU_ENABLE; //mask
  194. value |= ov;
  195. if( !LSM303C_ACC_WriteReg(handle, LSM303C_ACC_CTRL1, &value, 1) )
  196. return MEMS_ERROR;
  197. return MEMS_SUCCESS;
  198. }
  199. /*******************************************************************************
  200. * Function Name : LSM303C_ACC_GetAccRaw
  201. * Description : Read accelerometer output register
  202. * Input : pointer to AxesRaw_t
  203. * Output : Acceleration Output Registers buffer AxesRaw_t
  204. * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
  205. *******************************************************************************/
  206. status_t LSM303C_ACC_GetAccRaw(void *handle, u8_t* buff)
  207. {
  208. u8_t i, j, k;
  209. u8_t numberOfByteForDimension;
  210. numberOfByteForDimension=6/3;
  211. k=0;
  212. for (i=0; i<3;i++ )
  213. {
  214. for (j=0; j<numberOfByteForDimension;j++ )
  215. {
  216. if( !LSM303C_ACC_ReadReg(handle, LSM303C_ACC_OUT_X_L+k, &buff[k], 1))
  217. return MEMS_ERROR;
  218. k++;
  219. }
  220. }
  221. return MEMS_SUCCESS;
  222. }
  223. /*******************************************************************************
  224. * Function Name : LSM303C_ACC_SelfTest
  225. * Description : Enable/Disable LIS2HH Self Test
  226. * Input : Self test [LSM303C_ACC_ST_t]
  227. * Output : None
  228. * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
  229. *******************************************************************************/
  230. status_t LSM303C_ACC_SelfTest(void *handle, LSM303C_ACC_ST_t ov){
  231. u8_t value;
  232. if( !LSM303C_ACC_ReadReg(handle, LSM303C_ACC_CTRL5, &value, 1) )
  233. return MEMS_ERROR;
  234. value &= ~LSM303C_ACC_ST_NA; //mask
  235. value |= ov;
  236. if( !LSM303C_ACC_WriteReg(handle, LSM303C_ACC_CTRL5, &value, 1) )
  237. return MEMS_ERROR;
  238. return MEMS_SUCCESS;
  239. }
  240. /*******************************************************************************
  241. * Function Name : LSM303C_ACC_AxOperativeMode
  242. * Description : Sets LIS2HH Output Data Rate
  243. * Input : Set Output data rate [LSM303C_ACC_HR_t]
  244. * Output : None
  245. * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
  246. *******************************************************************************/
  247. //#WARNING: If you enable the HR bit Low pass cut off frequency will change
  248. status_t LSM303C_ACC_AxOperativeMode(void *handle, LSM303C_ACC_HR_t ov){
  249. u8_t value;
  250. if( !LSM303C_ACC_ReadReg(handle, LSM303C_ACC_CTRL1, &value, 1) )
  251. return MEMS_ERROR;
  252. value &= ~LSM303C_ACC_HIGH_RES_ON; //mask
  253. value |= ov;
  254. if( !LSM303C_ACC_WriteReg(handle, LSM303C_ACC_CTRL1, &value, 1) )
  255. return MEMS_ERROR;
  256. return MEMS_SUCCESS;
  257. }
  258. /*******************************************************************************
  259. * Function Name : LSM303C_ACC_SoftReset
  260. * Description : Enable/Disable LIS2HH SoftReset
  261. * Input : SoftReset Enable/Disable [LSM303C_ACC_SOFT_RESET_t]
  262. * Output : None
  263. * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
  264. *******************************************************************************/
  265. status_t LSM303C_ACC_SoftReset(void *handle, LSM303C_ACC_SOFT_RESET_t ov){
  266. u8_t value;
  267. if( !LSM303C_ACC_ReadReg(handle, LSM303C_ACC_CTRL5, &value, 1) )
  268. return MEMS_ERROR;
  269. value &= ~LSM303C_ACC_SOFT_RESET_ENABLE; //mask
  270. value |= ov;
  271. if( !LSM303C_ACC_WriteReg(handle, LSM303C_ACC_CTRL5, &value, 1) )
  272. return MEMS_ERROR;
  273. return MEMS_SUCCESS;
  274. }
  275. /*******************************************************************************
  276. * Function Name : LSM303C_ACC_SerialInterfaceMode
  277. * Description : set LIS2HH SerialInterfaceMode
  278. * Input : set LIS2HH SerialInterfaceMode [LSM303C_ACC_SIM_t]
  279. * Output : None
  280. * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
  281. *******************************************************************************/
  282. status_t LSM303C_ACC_SerialInterfaceMode(void *handle, LSM303C_ACC_SIM_t ov){
  283. u8_t value;
  284. if( !LSM303C_ACC_ReadReg(handle, LSM303C_ACC_CTRL4, &value, 1) )
  285. return MEMS_ERROR;
  286. value &= ~LSM303C_ACC_SIM_3WIRE_INTERFACE; //mask
  287. value |= ov;
  288. if( !LSM303C_ACC_WriteReg(handle, LSM303C_ACC_CTRL4, &value, 1) )
  289. return MEMS_ERROR;
  290. return MEMS_SUCCESS;
  291. }
  292. /*******************************************************************************
  293. * Function Name : LSM303C_ACC_EnableInterruptGeneratorOne
  294. * Description : Enable/Disable LIS2HH interrupt generator one
  295. * Input : Enable/Disable LIS2HH interrupt generator one[LSM303C_ACC_IG_CONFIG_t]
  296. * Output : None
  297. * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
  298. *******************************************************************************/
  299. //You can use LSM303C_ACC_IG_CONFIG_t with or condition see DS 4D and 6D interrupt
  300. status_t LSM303C_ACC_EnableInterruptGeneratorOne(void *handle, LSM303C_ACC_IG_CONFIG_t ov){
  301. u8_t valueCTRL7, valueCFG1;
  302. if( !LSM303C_ACC_ReadReg(handle, LSM303C_ACC_CTRL7, &valueCTRL7, 1) )
  303. return MEMS_ERROR;
  304. if( !LSM303C_ACC_ReadReg(handle, LSM303C_ACC_IG_CFG1, &valueCFG1, 1) )
  305. return MEMS_ERROR;
  306. if (ov&LSM303C_ACC_IG_4D)
  307. {
  308. valueCFG1 &= 0x80; //disable all interrupt generation
  309. if( !LSM303C_ACC_WriteReg(handle, LSM303C_ACC_IG_CFG1, &valueCFG1, 1) )
  310. return MEMS_ERROR;
  311. valueCTRL7 |= LSM303C_ACC_4D_INTGEN1_EN; //enable 4D recognition
  312. if( !LSM303C_ACC_WriteReg(handle, LSM303C_ACC_CTRL7, &valueCTRL7, 1) )
  313. return MEMS_ERROR;
  314. }
  315. else
  316. {
  317. valueCFG1 &= ~0x7F; //enable selected interrupt
  318. valueCFG1 |= ov;
  319. if( !LSM303C_ACC_WriteReg(handle, LSM303C_ACC_IG_CFG1, &valueCFG1, 1) )
  320. return MEMS_ERROR;
  321. valueCTRL7 &= ~LSM303C_ACC_4D_INTGEN1_EN; //disable 4d recognition
  322. if( !LSM303C_ACC_WriteReg(handle, LSM303C_ACC_CTRL7, &valueCTRL7, 1) )
  323. return MEMS_ERROR;
  324. }
  325. return MEMS_SUCCESS;
  326. }
  327. /*******************************************************************************
  328. * Function Name : LSM303C_ACC_EnableInterruptGeneratorTwo
  329. * Description : Enable/Disable LIS2HH interrupt generator two
  330. * Input : Enable/Disable LIS2HH interrupt generator two[LSM303C_ACC_IG_CONFIG_t]
  331. * Output : None
  332. * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
  333. *******************************************************************************/
  334. //You can use LSM303C_ACC_IG_CONFIG_t with or condition see DS 4D and 6D interrupt
  335. status_t LSM303C_ACC_EnableInterruptGeneratorTwo(void *handle, LSM303C_ACC_IG_CONFIG_t ov){
  336. u8_t valueCTRL7, valueCFG2;
  337. if( !LSM303C_ACC_ReadReg(handle, LSM303C_ACC_CTRL7, &valueCTRL7, 1) )
  338. return MEMS_ERROR;
  339. if( !LSM303C_ACC_ReadReg(handle, LSM303C_ACC_IG_CFG2, &valueCFG2, 1) )
  340. return MEMS_ERROR;
  341. if (ov&LSM303C_ACC_IG_4D)
  342. {
  343. valueCFG2 &= 0x80; //disable all interrupt generation
  344. if( !LSM303C_ACC_WriteReg(handle, LSM303C_ACC_IG_CFG2, &valueCFG2, 1) )
  345. return MEMS_ERROR;
  346. valueCTRL7 |= LSM303C_ACC_4D_INTGEN2_EN; //enable 4D recognition
  347. if( !LSM303C_ACC_WriteReg(handle, LSM303C_ACC_CTRL7, &valueCTRL7, 1) )
  348. return MEMS_ERROR;
  349. }
  350. else
  351. {
  352. valueCFG2 &= ~0x7F; //enable selected interrupt
  353. valueCFG2 |= ov;
  354. if( !LSM303C_ACC_WriteReg(handle, LSM303C_ACC_IG_CFG2, &valueCFG2, 1) )
  355. return MEMS_ERROR;
  356. valueCTRL7 &= ~LSM303C_ACC_4D_INTGEN2_EN; //disable 4d recognition
  357. if( !LSM303C_ACC_WriteReg(handle, LSM303C_ACC_CTRL7, &valueCTRL7, 1) )
  358. return MEMS_ERROR;
  359. }
  360. return MEMS_SUCCESS;
  361. }
  362. /*******************************************************************************
  363. * Function Name : LSM303C_ACC_InterruptGeneratorOne_LogicCondition
  364. * Description : LIS2HH interrupt generator one LogicCondition
  365. * Input : LIS2HH interrupt generator one LogicCondition[LSM303C_ACC_AOI_IG_t]
  366. * Output : None
  367. * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
  368. *******************************************************************************/
  369. status_t LSM303C_ACC_InterruptGeneratorOne_LogicCondition(void *handle, LSM303C_ACC_AOI_IG_t ov){
  370. u8_t value;
  371. if( !LSM303C_ACC_ReadReg(handle, LSM303C_ACC_IG_CFG1, &value, 1) )
  372. return MEMS_ERROR;
  373. value &= ~LSM303C_ACC_AOI_IG_AND; //mask
  374. value |= ov;
  375. if( !LSM303C_ACC_WriteReg(handle, LSM303C_ACC_IG_CFG1, &value, 1) )
  376. return MEMS_ERROR;
  377. return MEMS_SUCCESS;
  378. }
  379. /*******************************************************************************
  380. * Function Name : LSM303C_ACC_InterruptGeneratorTwo_LogicCondition
  381. * Description : LIS2HH interrupt generator two LogicCondition
  382. * Input : LIS2HH interrupt generator two LogicCondition[LSM303C_ACC_AOI_IG_t]
  383. * Output : None
  384. * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
  385. *******************************************************************************/
  386. status_t LSM303C_ACC_InterruptGeneratorTwo_LogicCondition(void *handle, LSM303C_ACC_AOI_IG_t ov){
  387. u8_t value;
  388. if( !LSM303C_ACC_ReadReg(handle, LSM303C_ACC_IG_CFG2, &value, 1) )
  389. return MEMS_ERROR;
  390. value &= ~LSM303C_ACC_AOI_IG_AND; //mask
  391. value |= ov;
  392. if( !LSM303C_ACC_WriteReg(handle, LSM303C_ACC_IG_CFG2, &value, 1) )
  393. return MEMS_ERROR;
  394. return MEMS_SUCCESS;
  395. }
  396. /*******************************************************************************
  397. * Function Name : LSM303C_ACC_InterruptGeneratorOne_Flag
  398. * Description : read interrupt one generator flags
  399. * Input : pointer to LSM303C_ACC_IG_FLAGS_t
  400. * Output : LIS2HH XYZ Axis data overrun [LSM303C_ACC_IG_FLAGS_t]
  401. * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
  402. *******************************************************************************/
  403. //You can use LSM303C_ACC_IG_FLAGS_t with or condition to interpret value
  404. status_t LSM303C_ACC_InterruptGeneratorOne_Flag(void *handle, LSM303C_ACC_IG_FLAGS_t *value){
  405. if( !LSM303C_ACC_ReadReg(handle, LSM303C_ACC_IG_SRC1, (u8_t *)value, 1) )
  406. return MEMS_ERROR;
  407. *value &= 0x7F; //mask
  408. return MEMS_SUCCESS;
  409. }
  410. /*******************************************************************************
  411. * Function Name : LSM303C_ACC_InterruptGeneratorTwo_Flag
  412. * Description : read interrupt two generator flags
  413. * Input : pointer to LSM303C_ACC_IG_FLAGS_t
  414. * Output : LIS2HH XYZ Axis data overrun [LSM303C_ACC_IG_FLAGS_t]
  415. * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
  416. *******************************************************************************/
  417. //You can use LSM303C_ACC_IG_FLAGS_t with or condition to interpret value
  418. status_t LSM303C_ACC_InterruptGeneratorTwo_Flag(void *handle, LSM303C_ACC_IG_FLAGS_t *value){
  419. if( !LSM303C_ACC_ReadReg(handle, LSM303C_ACC_IG_SRC2, (u8_t *)value, 1) )
  420. return MEMS_ERROR;
  421. *value &= 0x7F; //mask
  422. return MEMS_SUCCESS;
  423. }
  424. /*******************************************************************************
  425. * Function Name : LSM303C_ACC_InterruptGeneratorOne_Wait
  426. * Description : Enable/Disable LIS2HH interrupt generator one Wait
  427. * Input : Enable/Disable LIS2HH interrupt generator one Wait[LSM303C_ACC_WAIT_IG_t]
  428. * Output : None
  429. * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
  430. *******************************************************************************/
  431. status_t LSM303C_ACC_InterruptGeneratorOne_Wait(void *handle, LSM303C_ACC_WAIT_IG_t ov){
  432. u8_t value;
  433. if( !LSM303C_ACC_ReadReg(handle, LSM303C_ACC_IG_DUR1, &value, 1) )
  434. return MEMS_ERROR;
  435. value &= ~LSM303C_ACC_WAIT_IG_ON; //mask
  436. value |= ov;
  437. if( !LSM303C_ACC_WriteReg(handle, LSM303C_ACC_IG_DUR1, &value, 1) )
  438. return MEMS_ERROR;
  439. return MEMS_SUCCESS;
  440. }
  441. /*******************************************************************************
  442. * Function Name : LSM303C_ACC_InterruptGeneratorTwo_Wait
  443. * Description : Enable/Disable LIS2HH interrupt generator two Wait
  444. * Input : Enable/Disable LIS2HH interrupt generator two Wait[LSM303C_ACC_WAIT_IG_t]
  445. * Output : None
  446. * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
  447. *******************************************************************************/
  448. status_t LSM303C_ACC_InterruptGeneratorTwo_Wait(void *handle, LSM303C_ACC_WAIT_IG_t ov){
  449. u8_t value;
  450. if( !LSM303C_ACC_ReadReg(handle, LSM303C_ACC_IG_DUR2, &value, 1) )
  451. return MEMS_ERROR;
  452. value &= ~LSM303C_ACC_WAIT_IG_ON; //mask
  453. value |= ov;
  454. if( !LSM303C_ACC_WriteReg(handle, LSM303C_ACC_IG_DUR2, &value, 1) )
  455. return MEMS_ERROR;
  456. return MEMS_SUCCESS;
  457. }
  458. /*******************************************************************************
  459. * Function Name : LSM303C_ACC_EnableInterruptPinOne
  460. * Description : Enable/Disable LIS2HH interrupt pin one
  461. * Input : Enable/Disable LIS2HH interrupt pin one[LSM303C_ACC_INT1_DRDY_t]
  462. * Output : None
  463. * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
  464. *******************************************************************************/
  465. status_t LSM303C_ACC_EnableInterruptPinOne(void *handle, LSM303C_ACC_INT1_DRDY_t ov){
  466. u8_t value;
  467. if( !LSM303C_ACC_ReadReg(handle, LSM303C_ACC_CTRL3, &value, 1) )
  468. return MEMS_ERROR;
  469. value &= ~0x7F; //mask
  470. value |= ov;
  471. if( !LSM303C_ACC_WriteReg(handle, LSM303C_ACC_CTRL3, &value, 1) )
  472. return MEMS_ERROR;
  473. return MEMS_SUCCESS;
  474. }
  475. /*******************************************************************************
  476. * Function Name : LSM303C_ACC_EnableInterruptPinTwo
  477. * Description : Enable/Disable LIS2HH interrupt pin two
  478. * Input : Enable/Disable LIS2HH interrupt pin two[LSM303C_ACC_INT2_DRDY_t]
  479. * Output : None
  480. * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
  481. *******************************************************************************/
  482. status_t LSM303C_ACC_EnableInterruptPinTwo(void *handle, LSM303C_ACC_INT2_DRDY_t ov){
  483. u8_t value;
  484. if( !LSM303C_ACC_ReadReg(handle, LSM303C_ACC_CTRL6, &value, 1) )
  485. return MEMS_ERROR;
  486. value &= ~0x3F; //mask
  487. value |= ov;
  488. if( !LSM303C_ACC_WriteReg(handle, LSM303C_ACC_CTRL6, &value, 1) )
  489. return MEMS_ERROR;
  490. return MEMS_SUCCESS;
  491. }
  492. /*******************************************************************************
  493. * Function Name : LSM303C_ACC_Reboot
  494. * Description : LSM303C_ACC_Reboot
  495. * Input : None
  496. * Output : None
  497. * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
  498. *******************************************************************************/
  499. status_t LSM303C_ACC_Reboot(void *handle){
  500. u8_t value;
  501. if( !LSM303C_ACC_ReadReg(handle, LSM303C_ACC_CTRL6, &value, 1) )
  502. return MEMS_ERROR;
  503. value |= LSM303C_ACC_REBOOT;
  504. if( !LSM303C_ACC_WriteReg(handle, LSM303C_ACC_CTRL6, &value, 1) )
  505. return MEMS_ERROR;
  506. return MEMS_SUCCESS;
  507. }
  508. /*******************************************************************************
  509. * Function Name : LSM303C_ACC_EnableAxis
  510. * Description : LSM303C_ACC_EnableAxis
  511. * Input : Enable/Disable LIS2HH axis [LSM303C_ACC_AXIS_EN_t]
  512. * Output : None
  513. * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
  514. *******************************************************************************/
  515. //You can use LSM303C_ACC_AXIS_EN_t with or condition
  516. status_t LSM303C_ACC_EnableAxis(void *handle, u8_t ov){
  517. u8_t value;
  518. if( !LSM303C_ACC_ReadReg(handle, LSM303C_ACC_CTRL1, &value, 1) )
  519. return MEMS_ERROR;
  520. value &= ~0x07; //mask
  521. value |= ov;
  522. if( !LSM303C_ACC_WriteReg(handle, LSM303C_ACC_CTRL1, &value, 1) )
  523. return MEMS_ERROR;
  524. return MEMS_SUCCESS;
  525. }
  526. /*******************************************************************************
  527. * Function Name : LSM303C_ACC_HighPassFilterMode
  528. * Description : LSM303C_ACC_HighPassFilterMode
  529. * Input : Select LIS2HH high pass filter mode [LSM303C_ACC_HPM_t]
  530. * Output : None
  531. * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
  532. *******************************************************************************/
  533. //Referring DS to HP filter Usage
  534. status_t LSM303C_ACC_HighPassFilterMode(void *handle, LSM303C_ACC_HPM_t ov){
  535. u8_t value;
  536. if( !LSM303C_ACC_ReadReg(handle, LSM303C_ACC_CTRL2, &value, 1) )
  537. return MEMS_ERROR;
  538. value &= ~0x18; //mask
  539. value |= ov;
  540. if( !LSM303C_ACC_WriteReg(handle, LSM303C_ACC_CTRL2, &value, 1) )
  541. return MEMS_ERROR;
  542. return MEMS_SUCCESS;
  543. }
  544. /*******************************************************************************
  545. * Function Name : LSM303C_ACC_I2C_Mode
  546. * Description : Enable/Disable LIS2HH I2C
  547. * Input : Enable/Disable LIS2HH I2C[LSM303C_ACC_I2C_t]
  548. * Output : None
  549. * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
  550. *******************************************************************************/
  551. status_t LSM303C_ACC_I2C_Mode(void *handle, LSM303C_ACC_I2C_t ov){
  552. u8_t value;
  553. if( !LSM303C_ACC_ReadReg(handle, LSM303C_ACC_CTRL4, &value, 1) )
  554. return MEMS_ERROR;
  555. value &= ~LSM303C_ACC_I2C_DISABLE; //mask
  556. value |= ov;
  557. if( !LSM303C_ACC_WriteReg(handle, LSM303C_ACC_CTRL4, &value, 1) )
  558. return MEMS_ERROR;
  559. return MEMS_SUCCESS;
  560. }
  561. /*******************************************************************************
  562. * Function Name : LSM303C_ACC_AuotoInc
  563. * Description : Enable/Disable LIS2HH AuotoInc
  564. * Input : Enable/Disable LIS2HH AuotoInc[LSM303C_ACC_IF_ADD_INC_t]
  565. * Output : None
  566. * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
  567. *******************************************************************************/
  568. status_t LSM303C_ACC_AuotoInc(void *handle, LSM303C_ACC_IF_ADD_INC_t ov){
  569. u8_t value;
  570. if( !LSM303C_ACC_ReadReg(handle, LSM303C_ACC_CTRL4, &value, 1) )
  571. return MEMS_ERROR;
  572. value &= ~LSM303C_ACC_IF_ADD_INC_ENABLE; //mask
  573. value |= ov;
  574. if( !LSM303C_ACC_WriteReg(handle, LSM303C_ACC_CTRL4, &value, 1) )
  575. return MEMS_ERROR;
  576. return MEMS_SUCCESS;
  577. }
  578. /*******************************************************************************
  579. * Function Name : LSM303C_ACC_Select_Bandwidth
  580. * Description : LIS2HH LSM303C_ACC_Select_Bandwidth
  581. * Input : LIS2HH LSM303C_ACC_Select_Bandwidth[LSM303C_ACC_BW_t]
  582. * Output : None
  583. * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
  584. *******************************************************************************/
  585. status_t LSM303C_ACC_Select_Bandwidth(void *handle, LSM303C_ACC_BW_t ov){
  586. u8_t value;
  587. if( !LSM303C_ACC_ReadReg(handle, LSM303C_ACC_CTRL4, &value, 1) )
  588. return MEMS_ERROR;
  589. value &= ~LSM303C_ACC_BW_50_Hz; //mask
  590. value |= ov;
  591. if( !LSM303C_ACC_WriteReg(handle, LSM303C_ACC_CTRL4, &value, 1) )
  592. return MEMS_ERROR;
  593. return MEMS_SUCCESS;
  594. }
  595. /*******************************************************************************
  596. * Function Name : LSM303C_ACC_IntPin_Mode
  597. * Description : LIS2HH Interrupt pin mode
  598. * Input : LIS2HH Interrupt pin mode[LSM303C_ACC_INT_PIN_CFG_t]
  599. * Output : None
  600. * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
  601. *******************************************************************************/
  602. status_t LSM303C_ACC_IntPin_Mode(void *handle, LSM303C_ACC_INT_PIN_CFG_t ov){
  603. u8_t value;
  604. if( !LSM303C_ACC_ReadReg(handle, LSM303C_ACC_CTRL5, &value, 1) )
  605. return MEMS_ERROR;
  606. value &= ~LSM303C_ACC_OPEN_DRAIN_ACTIVE_LOW; //mask
  607. value |= ov;
  608. if( !LSM303C_ACC_WriteReg(handle, LSM303C_ACC_CTRL5, &value, 1) )
  609. return MEMS_ERROR;
  610. return MEMS_SUCCESS;
  611. }
  612. /*******************************************************************************
  613. * Function Name : LSM303C_ACC_DebugMode
  614. * Description : Enable/Disable LIS2HH Debug Mode
  615. * Input : Enable/Disable LIS2HH Debug Mode[LSM303C_ACC_DEBUG_t]
  616. * Output : None
  617. * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
  618. *******************************************************************************/
  619. status_t LSM303C_ACC_DebugMode(void *handle, LSM303C_ACC_DEBUG_t ov){
  620. u8_t value;
  621. if( !LSM303C_ACC_ReadReg(handle, LSM303C_ACC_CTRL5, &value, 1) )
  622. return MEMS_ERROR;
  623. value &= ~LSM303C_ACC_DEBUG_ENABLE; //mask
  624. value |= ov;
  625. if( !LSM303C_ACC_WriteReg(handle, LSM303C_ACC_CTRL5, &value, 1) )
  626. return MEMS_ERROR;
  627. return MEMS_SUCCESS;
  628. }
  629. /*******************************************************************************
  630. * Function Name : LSM303C_ACC_InterruptSignalsMode
  631. * Description : LIS2HH Interrupt Signals Mode
  632. * Input : LIS2HH Interrupt Signals Mode[LSM303C_ACC_LAT_SIG_t]
  633. * Output : None
  634. * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
  635. *******************************************************************************/
  636. status_t LSM303C_ACC_InterruptSignalsMode(void *handle, LSM303C_ACC_LAT_SIG_t ov){
  637. u8_t value;
  638. if( !LSM303C_ACC_ReadReg(handle, LSM303C_ACC_CTRL7, &value, 1) )
  639. return MEMS_ERROR;
  640. value &= ~LSM303C_ACC_INT1_LAT_INT2_LAT; //mask
  641. value |= ov;
  642. if( !LSM303C_ACC_WriteReg(handle, LSM303C_ACC_CTRL7, &value, 1) )
  643. return MEMS_ERROR;
  644. return MEMS_SUCCESS;
  645. }
  646. /*******************************************************************************
  647. * Function Name : LSM303C_ACC_ResetInterruptDuration
  648. * Description : LIS2HH Reset Interrupt Duration
  649. * Input : LIS2HH Reset Interrupt Duration[LSM303C_ACC_RESET_DUR_t]
  650. * Output : None
  651. * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
  652. *******************************************************************************/
  653. status_t LSM303C_ACC_ResetInterruptDuration(void *handle, LSM303C_ACC_RESET_DUR_t ov){
  654. u8_t value;
  655. if( !LSM303C_ACC_ReadReg(handle, LSM303C_ACC_CTRL7, &value, 1) )
  656. return MEMS_ERROR;
  657. value &= ~LSM303C_ACC_DUR1_RST_DUR2_RST; //mask
  658. value |= ov;
  659. if( !LSM303C_ACC_WriteReg(handle, LSM303C_ACC_CTRL7, &value, 1) )
  660. return MEMS_ERROR;
  661. return MEMS_SUCCESS;
  662. }
  663. /*******************************************************************************
  664. * Function Name : LSM303C_ACC_Status_Flags
  665. * Description : read LIS2HH Status Flags
  666. * Input : pointer to LSM303C_ACC_STATUS_FLAGS_t
  667. * Output : read LIS2HH Status Flags [LSM303C_ACC_STATUS_FLAGS_t]
  668. * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
  669. *******************************************************************************/
  670. //You can use LSM303C_ACC_STATUS_FLAGS_t with or condition to interpret value
  671. status_t LSM303C_ACC_Status_Flags(void *handle, u8_t *value){
  672. if( !LSM303C_ACC_ReadReg(handle, LSM303C_ACC_STATUS, (u8_t *)value, 1) )
  673. return MEMS_ERROR;
  674. return MEMS_SUCCESS;
  675. }
  676. /*******************************************************************************
  677. * Function Name : LSM303C_ACC_FIFO_Mode
  678. * Description : LIS2HH FIFO Mode
  679. * Input : LIS2HH FIFO Mode[LSM303C_ACC_FMODE_t]
  680. * Output : None
  681. * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
  682. *******************************************************************************/
  683. //this function enable FIFO to disable use LSM303C_ACC_FIFO
  684. status_t LSM303C_ACC_FIFO_Mode(void *handle, LSM303C_ACC_FMODE_t ov){
  685. u8_t value;
  686. if( !LSM303C_ACC_ReadReg(handle, LSM303C_ACC_CTRL3, &value, 1) )
  687. return MEMS_ERROR;
  688. value |= LSM303C_ACC_FIFO_ENABLE; //Enable FIFO
  689. if( !LSM303C_ACC_WriteReg(handle, LSM303C_ACC_CTRL3, &value, 1) )
  690. return MEMS_ERROR;
  691. if( !LSM303C_ACC_ReadReg(handle, LSM303C_ACC_FIFO_CTRL, &value, 1) )
  692. return MEMS_ERROR;
  693. value &= ~LSM303C_ACC_FMODE_BYPASS_TO_FIFO; //mask
  694. value |= ov;
  695. if( !LSM303C_ACC_WriteReg(handle, LSM303C_ACC_FIFO_CTRL, &value, 1) )
  696. return MEMS_ERROR;
  697. return MEMS_SUCCESS;
  698. }
  699. /*******************************************************************************
  700. * Function Name : LSM303C_ACC_FIFO_Flags
  701. * Description : read LIS2HH FIFO Flags
  702. * Input : pointer to LSM303C_ACC_FIFO_FLAGS_t
  703. * Output : read LIS2HH FIFO Flags [LSM303C_ACC_FIFO_FLAGS_t]
  704. * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
  705. *******************************************************************************/
  706. //You can use LSM303C_ACC_FIFO_FLAGS_t with or condition to interpret value
  707. status_t LSM303C_ACC_FIFO_Flags(void *handle, LSM303C_ACC_FIFO_FLAGS_t *value){
  708. if( !LSM303C_ACC_ReadReg(handle, LSM303C_ACC_FIFO_SRC, (u8_t *)value, 1) )
  709. return MEMS_ERROR;
  710. *value &= 0xE0; //mask
  711. return MEMS_SUCCESS;
  712. }
  713. /*******************************************************************************
  714. * Function Name : LSM303C_ACC_FIFO_StopAtTh
  715. * Description : LIS2HH FIFO Stop at threshold
  716. * Input : LIS2HH FIFO Stop at threshold[LSM303C_ACC_STOP_FTH_t]
  717. * Output : None
  718. * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
  719. *******************************************************************************/
  720. status_t LSM303C_ACC_FIFO_StopAtTh(void *handle, LSM303C_ACC_STOP_FTH_t ov){
  721. u8_t value;
  722. if( !LSM303C_ACC_ReadReg(handle, LSM303C_ACC_CTRL3, &value, 1) )
  723. return MEMS_ERROR;
  724. value &= ~LSM303C_ACC_STOP_FTH_EN_FIFO_TH; //mask
  725. value |= ov;
  726. if( !LSM303C_ACC_WriteReg(handle, LSM303C_ACC_CTRL3, &value, 1) )
  727. return MEMS_ERROR;
  728. return MEMS_SUCCESS;
  729. }
  730. /*******************************************************************************
  731. * Function Name : LSM303C_ACC_FIFO
  732. * Description : Enable/Disable LIS2HH FIFO
  733. * Input : Enable/Disable LIS2HH FIFO[LSM303C_ACC_FIFO_EN_t]
  734. * Output : None
  735. * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
  736. *******************************************************************************/
  737. status_t LSM303C_ACC_FIFO(void *handle, LSM303C_ACC_FIFO_EN_t ov){
  738. u8_t value;
  739. if( !LSM303C_ACC_ReadReg(handle, LSM303C_ACC_CTRL3, &value, 1) )
  740. return MEMS_ERROR;
  741. value &= ~LSM303C_ACC_FIFO_ENABLE; //mask
  742. value |= ov;
  743. if( !LSM303C_ACC_WriteReg(handle, LSM303C_ACC_CTRL3, &value, 1) )
  744. return MEMS_ERROR;
  745. return MEMS_SUCCESS;
  746. }
  747. /*******************************************************************************
  748. * Function Name : LSM303C_ACC_GetTemperatureRaw
  749. * Description : Read Temperature output register
  750. * Input : pointer to u16_t
  751. * Output : Temperature data row to u16_t
  752. * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
  753. *******************************************************************************/
  754. status_t LSM303C_ACC_GetTemperatureRaw(void *handle, u16_t* buff) {
  755. u8_t valueL;
  756. u8_t valueH;
  757. if( !LSM303C_ACC_ReadReg(handle, LSM303C_ACC_TEMP_H, &valueL, 1) )
  758. return MEMS_ERROR;
  759. if( !LSM303C_ACC_ReadReg(handle, LSM303C_ACC_TEMP_L, &valueH, 1) )
  760. return MEMS_ERROR;
  761. *buff = (i16_t)( (valueH << 8) | valueL );
  762. return MEMS_SUCCESS;
  763. }
  764. /*******************************************************************************
  765. * Function Name : LSM303C_ACC_SetInterrupt1_Threshold_X
  766. * Description : Set Interrupt Threshold data row
  767. * Input : threshold row value [u8_t]
  768. * Output : None
  769. * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
  770. *******************************************************************************/
  771. status_t LSM303C_ACC_SetInterrupt1_Threshold_X(void *handle, u8_t buff) {
  772. if( !LSM303C_ACC_WriteReg(handle, LSM303C_ACC_IG_THS_X1, &buff, 1) )
  773. return MEMS_ERROR;
  774. return MEMS_SUCCESS;
  775. }
  776. /*******************************************************************************
  777. * Function Name : LSM303C_ACC_SetInterrupt1_Threshold_Y
  778. * Description : Set Interrupt Threshold data row
  779. * Input : threshold row value [u8_t]
  780. * Output : None
  781. * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
  782. *******************************************************************************/
  783. status_t LSM303C_ACC_SetInterrupt1_Threshold_Y(void *handle, u8_t buff) {
  784. if( !LSM303C_ACC_WriteReg(handle, LSM303C_ACC_IG_THS_Y1, &buff, 1) )
  785. return MEMS_ERROR;
  786. return MEMS_SUCCESS;
  787. }
  788. /*******************************************************************************
  789. * Function Name : LSM303C_ACC_SetInterrupt1_Threshold_Z
  790. * Description : Set Interrupt Threshold data row
  791. * Input : threshold row value [u8_t]
  792. * Output : None
  793. * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
  794. *******************************************************************************/
  795. status_t LSM303C_ACC_SetInterrupt1_Threshold_Z(void *handle, u8_t buff) {
  796. if( !LSM303C_ACC_WriteReg(handle, LSM303C_ACC_IG_THS_Z1, &buff, 1) )
  797. return MEMS_ERROR;
  798. return MEMS_SUCCESS;
  799. }
  800. /*******************************************************************************
  801. * Function Name : LSM303C_ACC_SetInterrupt2_Threshold_ZYX
  802. * Description : Set Interrupt Threshold data row
  803. * Input : threshold row value [u8_t]
  804. * Output : None
  805. * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
  806. *******************************************************************************/
  807. status_t LSM303C_ACC_SetInterrupt2_Threshold_ZYX(void *handle, u8_t buff) {
  808. if( !LSM303C_ACC_WriteReg(handle, LSM303C_ACC_IG_THS2, &buff, 1) )
  809. return MEMS_ERROR;
  810. return MEMS_SUCCESS;
  811. }
  812. /*******************************************************************************
  813. * Function Name : LSM303C_ACC_SetInterrupt1_Duration
  814. * Description : Set Interrupt Duration data row
  815. * Input : Duration row value [u8_t]
  816. * Output : None
  817. * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
  818. *******************************************************************************/
  819. //WARNING: value from 0x00->0x7F
  820. status_t LSM303C_ACC_SetInterrupt1_Duration(void *handle, u8_t buff) {
  821. u8_t value;
  822. buff |= 0x7F; //coerce
  823. if( !LSM303C_ACC_ReadReg(handle, LSM303C_ACC_IG_DUR1, &value, 1) )
  824. return MEMS_ERROR;
  825. value &= ~0x7F; //mask
  826. value |= buff;
  827. if( !LSM303C_ACC_WriteReg(handle, LSM303C_ACC_IG_DUR1, &value, 1) )
  828. return MEMS_ERROR;
  829. return MEMS_SUCCESS;
  830. }
  831. /*******************************************************************************
  832. * Function Name : LSM303C_ACC_SetInterrupt2_Duration
  833. * Description : Set Interrupt Duration data row
  834. * Input : Duration row value [u8_t]
  835. * Output : None
  836. * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
  837. *******************************************************************************/
  838. //WARNING: value from 0x00->0x7F
  839. status_t LSM303C_ACC_SetInterrupt2_Duration(void *handle, u8_t buff) {
  840. u8_t value;
  841. buff |= 0x7F; //coerce
  842. if( !LSM303C_ACC_ReadReg(handle, LSM303C_ACC_IG_DUR2, &value, 1) )
  843. return MEMS_ERROR;
  844. value &= ~0x7F; //mask
  845. value |= buff;
  846. if( !LSM303C_ACC_WriteReg(handle, LSM303C_ACC_IG_DUR2, &value, 1) )
  847. return MEMS_ERROR;
  848. return MEMS_SUCCESS;
  849. }
  850. /*******************************************************************************
  851. * Function Name : LSM303C_ACC_SetReferenceValue
  852. * Description : Set Reference data row
  853. * Input : Reference row value [AxesRaw_t]
  854. * Output : None
  855. * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
  856. *******************************************************************************/
  857. status_t LSM303C_ACC_SetReferenceValue(void *handle, u8_t *buff)
  858. {
  859. u8_t i;
  860. for (i=0; i<6;i++ )
  861. {
  862. if( !LSM303C_ACC_WriteReg(handle, LSM303C_ACC_XL_REFERENCE+i, &buff[i], 1) )
  863. return MEMS_ERROR;
  864. }
  865. return MEMS_SUCCESS;
  866. }
  867. /*******************************************************************************
  868. * Function Name : LSM303C_ACC_GetReferenceValue
  869. * Description : Get Reference data row
  870. * Input : Reference row value [AxesRaw_t]
  871. * Output : None
  872. * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
  873. *******************************************************************************/
  874. status_t LSM303C_ACC_GetReferenceValue(void *handle, u8_t *buff)
  875. {
  876. u8_t i, j, k;
  877. u8_t numberOfByteForDimension;
  878. numberOfByteForDimension=6/3;
  879. k=0;
  880. for (i=0; i<3;i++ )
  881. {
  882. for (j=0; j<numberOfByteForDimension;j++ )
  883. {
  884. if( !LSM303C_ACC_ReadReg(handle, LSM303C_ACC_XL_REFERENCE+k, &buff[k], 1))
  885. return MEMS_ERROR;
  886. k++;
  887. }
  888. }
  889. return MEMS_SUCCESS;
  890. }
  891. /*******************************************************************************
  892. * Function Name : LSM303C_ACC_SetActivity_Threshold
  893. * Description : Set Interrupt Threshold data row
  894. * Input : threshold row value [u8_t]
  895. * Output : None
  896. * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
  897. *******************************************************************************/
  898. status_t LSM303C_ACC_SetActivity_Threshold(void *handle, u8_t buff) {
  899. if( !LSM303C_ACC_WriteReg(handle, LSM303C_ACC_ACT_TSH, &buff, 1) )
  900. return MEMS_ERROR;
  901. return MEMS_SUCCESS;
  902. }
  903. /*******************************************************************************
  904. * Function Name : LSM303C_ACC_SetActivity_Duration
  905. * Description : Set Interrupt Threshold data row
  906. * Input : threshold row value [u8_t]
  907. * Output : None
  908. * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
  909. *******************************************************************************/
  910. status_t LSM303C_ACC_SetActivity_Duration(void *handle, u8_t buff) {
  911. if( !LSM303C_ACC_WriteReg(handle, LSM303C_ACC_ACT_DUR, &buff, 1) )
  912. return MEMS_ERROR;
  913. return MEMS_SUCCESS;
  914. }
  915. /*******************************************************************************
  916. * Function Name : LSM303C_ACC_SetFIFO_threshold
  917. * Description : FIFO Threshold data row
  918. * Input : threshold row value [u8_t]
  919. * Output : None
  920. * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
  921. *******************************************************************************/
  922. //WARNING: value from 0x00->0x1F
  923. status_t LSM303C_ACC_SetFIFO_threshold(void *handle, u8_t buff) {
  924. u8_t value;
  925. buff &= 0x1F; //coerce
  926. if (!LSM303C_ACC_ReadReg(handle, LSM303C_ACC_ACT_DUR, &value, 1) )
  927. return MEMS_ERROR;
  928. value &= ~0x1F; //mask
  929. value |= buff;
  930. if( !LSM303C_ACC_WriteReg(handle, LSM303C_ACC_ACT_DUR, &value, 1) )
  931. return MEMS_ERROR;
  932. return MEMS_SUCCESS;
  933. }
  934. /*******************************************************************************
  935. * Function Name : LSM303C_ACC_GetFIFO_StoredData
  936. * Description : FIFO Stored data row
  937. * Input : Stored data row value [u8_t]
  938. * Output : None
  939. * Return : Status [MEMS_ERROR, MEMS_SUCCESS]
  940. *******************************************************************************/
  941. //WARNING: value from 0x00->0x1F
  942. status_t LSM303C_ACC_GetFIFO_StoredData(void *handle, u8_t buff) {
  943. if (!LSM303C_ACC_ReadReg(handle, LSM303C_ACC_FIFO_SRC, &buff, 1) )
  944. return MEMS_ERROR;
  945. buff &= 0x1F; //coerce
  946. return MEMS_SUCCESS;
  947. }
  948. /******************* (C) COPYRIGHT 2016 STMicroelectronics *****END OF FILE****/