lps25h.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696
  1. /*
  2. ChibiOS - Copyright (C) 2016..2018 Rocco Marco Guglielmi
  3. This file is part of ChibiOS.
  4. ChibiOS is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3 of the License, or
  7. (at your option) any later version.
  8. ChibiOS is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. /**
  16. * @file lps25h.c
  17. * @brief LPS25H MEMS interface module code.
  18. *
  19. * @addtogroup LPS25H
  20. * @ingroup EX_ST
  21. * @{
  22. */
  23. #include "hal.h"
  24. #include "lps25h.h"
  25. /*===========================================================================*/
  26. /* Driver local definitions. */
  27. /*===========================================================================*/
  28. /*===========================================================================*/
  29. /* Driver exported variables. */
  30. /*===========================================================================*/
  31. /*===========================================================================*/
  32. /* Driver local variables and types. */
  33. /*===========================================================================*/
  34. /*===========================================================================*/
  35. /* Driver local functions. */
  36. /*===========================================================================*/
  37. #if (LPS25H_USE_I2C) || defined(__DOXYGEN__)
  38. /**
  39. * @brief Reads registers value using I2C.
  40. * @pre The I2C interface must be initialized and the driver started.
  41. *
  42. * @param[in] i2cp pointer to the I2C interface
  43. * @param[in] sad slave address without R bit
  44. * @param[in] reg first sub-register address
  45. * @param[out] rxbuf pointer to an output buffer
  46. * @param[in] n number of consecutive register to read
  47. * @return the operation status.
  48. *
  49. * @notapi
  50. */
  51. static msg_t lps25hI2CReadRegister(I2CDriver *i2cp, lps25h_sad_t sad,
  52. uint8_t reg, uint8_t* rxbuf, size_t n) {
  53. uint8_t txbuf = reg;
  54. if(n > 1)
  55. txbuf |= LPS25H_SUB_MS;
  56. return i2cMasterTransmitTimeout(i2cp, sad, &txbuf, 1, rxbuf, n,
  57. TIME_INFINITE);
  58. }
  59. /**
  60. * @brief Writes a value into a register using I2C.
  61. * @pre The I2C interface must be initialized and the driver started.
  62. *
  63. * @param[in] i2cp pointer to the I2C interface
  64. * @param[in] sad slave address without R bit
  65. * @param[in] txbuf buffer containing sub-address value in first position
  66. * and values to write
  67. * @param[in] n size of txbuf less one (not considering the first
  68. * element)
  69. * @return the operation status.
  70. *
  71. * @notapi
  72. */
  73. static msg_t lps25hI2CWriteRegister(I2CDriver *i2cp, lps25h_sad_t sad,
  74. uint8_t* txbuf, size_t n) {
  75. if (n > 1)
  76. (*txbuf) |= LPS25H_SUB_MS;
  77. return i2cMasterTransmitTimeout(i2cp, sad, txbuf, n + 1, NULL, 0,
  78. TIME_INFINITE);
  79. }
  80. #endif /* LPS25H_USE_I2C */
  81. /**
  82. * @brief Return the number of axes of the BaseBarometer.
  83. *
  84. * @param[in] ip pointer to @p BaseBarometer interface.
  85. *
  86. * @return the number of axes.
  87. */
  88. static size_t baro_get_axes_number(void *ip) {
  89. (void)ip;
  90. return LPS25H_BARO_NUMBER_OF_AXES;
  91. }
  92. /**
  93. * @brief Retrieves raw data from the BaseBarometer.
  94. * @note This data is retrieved from MEMS register without any algebraical
  95. * manipulation.
  96. * @note The axes array must be at least the same size of the
  97. * BaseBarometer axes number.
  98. *
  99. * @param[in] ip pointer to @p BaseBarometer interface.
  100. * @param[out] axes a buffer which would be filled with raw data.
  101. *
  102. * @return The operation status.
  103. * @retval MSG_OK if the function succeeded.
  104. * @retval MSG_RESET if one or more I2C errors occurred, the errors can
  105. * be retrieved using @p i2cGetErrors().
  106. * @retval MSG_TIMEOUT if a timeout occurred before operation end.
  107. */
  108. static msg_t baro_read_raw(void *ip, int32_t axes[]) {
  109. LPS25HDriver* devp;
  110. uint8_t buff[3];
  111. msg_t msg;
  112. osalDbgCheck((ip != NULL) && (axes != NULL));
  113. /* Getting parent instance pointer.*/
  114. devp = objGetInstance(LPS25HDriver*, (BaseBarometer*)ip);
  115. osalDbgAssert((devp->state == LPS25H_READY),
  116. "baro_read_raw(), invalid state");
  117. osalDbgAssert((devp->config->i2cp->state == I2C_READY),
  118. "baro_read_raw(), channel not ready");
  119. #if LPS25H_SHARED_I2C
  120. i2cAcquireBus(devp->config->i2cp);
  121. i2cStart(devp->config->i2cp,
  122. devp->config->i2ccfg);
  123. #endif /* LPS25H_SHARED_I2C */
  124. msg = lps25hI2CReadRegister(devp->config->i2cp, devp->config->slaveaddress,
  125. LPS25H_AD_PRESS_OUT_XL, buff, 3);
  126. #if LPS25H_SHARED_I2C
  127. i2cReleaseBus(devp->config->i2cp);
  128. #endif /* LPS25H_SHARED_I2C */
  129. if(msg == MSG_OK) {
  130. *axes = buff[0] + (buff[1] << 8) + (buff[2] << 16);
  131. }
  132. return msg;
  133. }
  134. /**
  135. * @brief Retrieves cooked data from the BaseBarometer.
  136. * @note This data is manipulated according to the formula
  137. * cooked = (raw * sensitivity) - bias.
  138. * @note Final data is expressed as hPa.
  139. * @note The axes array must be at least the same size of the
  140. * BaseBarometer axes number.
  141. *
  142. * @param[in] ip pointer to @p BaseBarometer interface.
  143. * @param[out] axes a buffer which would be filled with cooked data.
  144. *
  145. * @return The operation status.
  146. * @retval MSG_OK if the function succeeded.
  147. * @retval MSG_RESET if one or more I2C errors occurred, the errors can
  148. * be retrieved using @p i2cGetErrors().
  149. * @retval MSG_TIMEOUT if a timeout occurred before operation end.
  150. */
  151. static msg_t baro_read_cooked(void *ip, float axes[]) {
  152. LPS25HDriver* devp;
  153. int32_t raw;
  154. msg_t msg;
  155. osalDbgCheck((ip != NULL) && (axes != NULL));
  156. /* Getting parent instance pointer.*/
  157. devp = objGetInstance(LPS25HDriver*, (BaseBarometer*)ip);
  158. osalDbgAssert((devp->state == LPS25H_READY),
  159. "baro_read_cooked(), invalid state");
  160. msg = baro_read_raw(ip, &raw);
  161. *axes = (raw * devp->barosensitivity) - devp->barobias;
  162. return msg;
  163. }
  164. /**
  165. * @brief Set bias values for the BaseBarometer.
  166. * @note Bias must be expressed as hPa.
  167. * @note The bias buffer must be at least the same size of the
  168. * BaseBarometer axes number.
  169. *
  170. * @param[in] ip pointer to @p BaseBarometer interface.
  171. * @param[in] bp a buffer which contains biases.
  172. *
  173. * @return The operation status.
  174. * @retval MSG_OK if the function succeeded.
  175. * @retval MSG_RESET if one or more I2C errors occurred, the errors can
  176. * be retrieved using @p i2cGetErrors().
  177. * @retval MSG_TIMEOUT if a timeout occurred before operation end.
  178. */
  179. static msg_t baro_set_bias(void *ip, float *bp) {
  180. LPS25HDriver* devp;
  181. msg_t msg = MSG_OK;
  182. osalDbgCheck((ip != NULL) && (bp != NULL));
  183. /* Getting parent instance pointer.*/
  184. devp = objGetInstance(LPS25HDriver*, (BaseBarometer*)ip);
  185. osalDbgAssert((devp->state == LPS25H_READY),
  186. "baro_set_bias(), invalid state");
  187. devp->barobias = *bp;
  188. return msg;
  189. }
  190. /**
  191. * @brief Reset bias values for the BaseBarometer.
  192. * @note Default biases value are obtained from device datasheet when
  193. * available otherwise they are considered zero.
  194. *
  195. * @param[in] ip pointer to @p BaseBarometer interface.
  196. *
  197. * @return The operation status.
  198. * @retval MSG_OK if the function succeeded.
  199. */
  200. static msg_t baro_reset_bias(void *ip) {
  201. LPS25HDriver* devp;
  202. msg_t msg = MSG_OK;
  203. osalDbgCheck(ip != NULL);
  204. /* Getting parent instance pointer.*/
  205. devp = objGetInstance(LPS25HDriver*, (BaseBarometer*)ip);
  206. osalDbgAssert((devp->state == LPS25H_READY),
  207. "baro_reset_bias(), invalid state");
  208. devp->barobias = LPS25H_BARO_SENS;
  209. return msg;
  210. }
  211. /**
  212. * @brief Set sensitivity values for the BaseBarometer.
  213. * @note Sensitivity must be expressed as hPa/LSB.
  214. * @note The sensitivity buffer must be at least the same size of the
  215. * BaseBarometer axes number.
  216. *
  217. * @param[in] ip pointer to @p BaseBarometer interface.
  218. * @param[in] sp a buffer which contains sensitivities.
  219. *
  220. * @return The operation status.
  221. * @retval MSG_OK if the function succeeded.
  222. */
  223. static msg_t baro_set_sensitivity(void *ip, float *sp) {
  224. LPS25HDriver* devp;
  225. msg_t msg = MSG_OK;
  226. osalDbgCheck((ip != NULL) && (sp != NULL));
  227. /* Getting parent instance pointer.*/
  228. devp = objGetInstance(LPS25HDriver*, (BaseBarometer*)ip);
  229. osalDbgAssert((devp->state == LPS25H_READY),
  230. "baro_set_sensitivity(), invalid state");
  231. devp->barosensitivity = *sp;
  232. return msg;
  233. }
  234. /**
  235. * @brief Reset sensitivity values for the BaseBarometer.
  236. * @note Default sensitivities value are obtained from device datasheet.
  237. *
  238. * @param[in] ip pointer to @p BaseBarometer interface.
  239. *
  240. * @return The operation status.
  241. * @retval MSG_OK if the function succeeded.
  242. */
  243. static msg_t baro_reset_sensitivity(void *ip) {
  244. LPS25HDriver* devp;
  245. msg_t msg = MSG_OK;
  246. osalDbgCheck(ip != NULL);
  247. /* Getting parent instance pointer.*/
  248. devp = objGetInstance(LPS25HDriver*, (BaseBarometer*)ip);
  249. osalDbgAssert((devp->state == LPS25H_READY),
  250. "baro_reset_sensitivity(), invalid state");
  251. devp->barosensitivity = LPS25H_BARO_SENS;
  252. return msg;
  253. }
  254. /**
  255. * @brief Return the number of axes of the BaseThermometer.
  256. *
  257. * @param[in] ip pointer to @p BaseThermometer interface.
  258. *
  259. * @return the number of axes.
  260. */
  261. static size_t thermo_get_axes_number(void *ip) {
  262. (void)ip;
  263. return LPS25H_THERMO_NUMBER_OF_AXES;
  264. }
  265. /**
  266. * @brief Retrieves raw data from the BaseThermometer.
  267. * @note This data is retrieved from MEMS register without any algebraical
  268. * manipulation.
  269. * @note The axes array must be at least the same size of the
  270. * BaseThermometer axes number.
  271. *
  272. * @param[in] ip pointer to @p BaseThermometer interface.
  273. * @param[out] axes a buffer which would be filled with raw data.
  274. *
  275. * @return The operation status.
  276. * @retval MSG_OK if the function succeeded.
  277. * @retval MSG_RESET if one or more I2C errors occurred, the errors can
  278. * be retrieved using @p i2cGetErrors().
  279. * @retval MSG_TIMEOUT if a timeout occurred before operation end.
  280. */
  281. static msg_t thermo_read_raw(void *ip, int32_t axes[]) {
  282. LPS25HDriver* devp;
  283. int16_t tmp;
  284. uint8_t buff[2];
  285. msg_t msg;
  286. osalDbgCheck((ip != NULL) && (axes != NULL));
  287. /* Getting parent instance pointer.*/
  288. devp = objGetInstance(LPS25HDriver*, (BaseThermometer*)ip);
  289. osalDbgAssert((devp->state == LPS25H_READY),
  290. "thermo_read_raw(), invalid state");
  291. osalDbgAssert((devp->config->i2cp->state == I2C_READY),
  292. "thermo_read_raw(), channel not ready");
  293. #if LPS25H_SHARED_I2C
  294. i2cAcquireBus(devp->config->i2cp);
  295. i2cStart(devp->config->i2cp,
  296. devp->config->i2ccfg);
  297. #endif /* LPS25H_SHARED_I2C */
  298. msg = lps25hI2CReadRegister(devp->config->i2cp, devp->config->slaveaddress,
  299. LPS25H_AD_TEMP_OUT_L, buff, 2);
  300. #if LPS25H_SHARED_I2C
  301. i2cReleaseBus(devp->config->i2cp);
  302. #endif /* LPS25H_SHARED_I2C */
  303. if (msg == MSG_OK) {
  304. tmp = buff[0] + (buff[1] << 8);
  305. *axes = (int32_t)tmp;
  306. }
  307. return msg;
  308. }
  309. /**
  310. * @brief Retrieves cooked data from the BaseThermometer.
  311. * @note This data is manipulated according to the formula
  312. * cooked = (raw * sensitivity) - bias.
  313. * @note Final data is expressed as °C.
  314. * @note The axes array must be at least the same size of the
  315. * BaseThermometer axes number.
  316. *
  317. * @param[in] ip pointer to @p BaseThermometer interface.
  318. * @param[out] axis a buffer which would be filled with cooked data.
  319. *
  320. * @return The operation status.
  321. * @retval MSG_OK if the function succeeded.
  322. * @retval MSG_RESET if one or more I2C errors occurred, the errors can
  323. * be retrieved using @p i2cGetErrors().
  324. * @retval MSG_TIMEOUT if a timeout occurred before operation end.
  325. */
  326. static msg_t thermo_read_cooked(void *ip, float* axis) {
  327. LPS25HDriver* devp;
  328. int32_t raw;
  329. msg_t msg;
  330. osalDbgCheck((ip != NULL) && (axis != NULL));
  331. /* Getting parent instance pointer.*/
  332. devp = objGetInstance(LPS25HDriver*, (BaseThermometer*)ip);
  333. osalDbgAssert((devp->state == LPS25H_READY),
  334. "thermo_read_cooked(), invalid state");
  335. msg = thermo_read_raw(devp, &raw);
  336. *axis = (raw * devp->thermosensitivity) - devp->thermobias;
  337. return msg;
  338. }
  339. /**
  340. * @brief Set bias values for the BaseThermometer.
  341. * @note Bias must be expressed as °C.
  342. * @note The bias buffer must be at least the same size of the
  343. * BaseThermometer axes number.
  344. *
  345. * @param[in] ip pointer to @p BaseThermometer interface.
  346. * @param[in] bp a buffer which contains biases.
  347. *
  348. * @return The operation status.
  349. * @retval MSG_OK if the function succeeded.
  350. */
  351. static msg_t thermo_set_bias(void *ip, float *bp) {
  352. LPS25HDriver* devp;
  353. msg_t msg = MSG_OK;
  354. osalDbgCheck((ip != NULL) && (bp != NULL));
  355. /* Getting parent instance pointer.*/
  356. devp = objGetInstance(LPS25HDriver*, (BaseThermometer*)ip);
  357. osalDbgAssert((devp->state == LPS25H_READY),
  358. "thermo_set_bias(), invalid state");
  359. devp->thermobias = *bp;
  360. return msg;
  361. }
  362. /**
  363. * @brief Reset bias values for the BaseThermometer.
  364. * @note Default biases value are obtained from device datasheet when
  365. * available otherwise they are considered zero.
  366. *
  367. * @param[in] ip pointer to @p BaseThermometer interface.
  368. *
  369. * @return The operation status.
  370. * @retval MSG_OK if the function succeeded.
  371. */
  372. static msg_t thermo_reset_bias(void *ip) {
  373. LPS25HDriver* devp;
  374. msg_t msg = MSG_OK;
  375. osalDbgCheck(ip != NULL);
  376. /* Getting parent instance pointer.*/
  377. devp = objGetInstance(LPS25HDriver*, (BaseThermometer*)ip);
  378. osalDbgAssert((devp->state == LPS25H_READY),
  379. "thermo_reset_bias(), invalid state");
  380. devp->thermobias = LPS25H_THERMO_BIAS;
  381. return msg;
  382. }
  383. /**
  384. * @brief Set sensitivity values for the BaseThermometer.
  385. * @note Sensitivity must be expressed as °C/LSB.
  386. * @note The sensitivity buffer must be at least the same size of the
  387. * BaseThermometer axes number.
  388. *
  389. * @param[in] ip pointer to @p BaseThermometer interface.
  390. * @param[in] sp a buffer which contains sensitivities.
  391. *
  392. * @return The operation status.
  393. * @retval MSG_OK if the function succeeded.
  394. */
  395. static msg_t thermo_set_sensitivity(void *ip, float *sp) {
  396. LPS25HDriver* devp;
  397. msg_t msg = MSG_OK;
  398. osalDbgCheck((ip != NULL) && (sp != NULL));
  399. /* Getting parent instance pointer.*/
  400. devp = objGetInstance(LPS25HDriver*, (BaseThermometer*)ip);
  401. osalDbgAssert((devp->state == LPS25H_READY),
  402. "thermo_set_sensitivity(), invalid state");
  403. devp->thermosensitivity = *sp;
  404. return msg;
  405. }
  406. /**
  407. * @brief Reset sensitivity values for the BaseThermometer.
  408. * @note Default sensitivities value are obtained from device datasheet.
  409. *
  410. * @param[in] ip pointer to @p BaseThermometer interface.
  411. *
  412. * @return The operation status.
  413. * @retval MSG_OK if the function succeeded.
  414. */
  415. static msg_t thermo_reset_sensitivity(void *ip) {
  416. LPS25HDriver* devp;
  417. msg_t msg = MSG_OK;
  418. osalDbgCheck(ip != NULL);
  419. /* Getting parent instance pointer.*/
  420. devp = objGetInstance(LPS25HDriver*, (BaseThermometer*)ip);
  421. osalDbgAssert((devp->state == LPS25H_READY),
  422. "thermo_reset_sensitivity(), invalid state");
  423. devp->thermosensitivity = LPS25H_THERMO_SENS;
  424. return msg;
  425. }
  426. static const struct LPS25HVMT vmt_device = {
  427. (size_t)0
  428. };
  429. static const struct BaseBarometerVMT vmt_barometer = {
  430. sizeof(struct LPS25HVMT*),
  431. baro_get_axes_number, baro_read_raw, baro_read_cooked,
  432. baro_set_bias, baro_reset_bias, baro_set_sensitivity,
  433. baro_reset_sensitivity
  434. };
  435. static const struct BaseThermometerVMT vmt_thermometer = {
  436. sizeof(struct LPS25HVMT*) + sizeof(BaseBarometer),
  437. thermo_get_axes_number, thermo_read_raw, thermo_read_cooked,
  438. thermo_set_bias, thermo_reset_bias, thermo_set_sensitivity,
  439. thermo_reset_sensitivity
  440. };
  441. /*===========================================================================*/
  442. /* Driver exported functions. */
  443. /*===========================================================================*/
  444. /**
  445. * @brief Initializes an instance.
  446. *
  447. * @param[out] devp pointer to the @p LPS25HDriver object
  448. *
  449. * @init
  450. */
  451. void lps25hObjectInit(LPS25HDriver *devp) {
  452. devp->vmt = &vmt_device;
  453. devp->baro_if.vmt = &vmt_barometer;
  454. devp->thermo_if.vmt = &vmt_thermometer;
  455. devp->config = NULL;
  456. devp->baroaxes = LPS25H_BARO_NUMBER_OF_AXES;
  457. devp->thermoaxes = LPS25H_THERMO_NUMBER_OF_AXES;
  458. devp->state = LPS25H_STOP;
  459. }
  460. /**
  461. * @brief Configures and activates LPS25H Complex Driver peripheral.
  462. *
  463. * @param[in] devp pointer to the @p LPS25HDriver object
  464. * @param[in] config pointer to the @p LPS25HConfig object
  465. *
  466. * @api
  467. */
  468. void lps25hStart(LPS25HDriver *devp, const LPS25HConfig *config) {
  469. uint8_t cr[2];
  470. osalDbgCheck((devp != NULL) && (config != NULL));
  471. osalDbgAssert((devp->state == LPS25H_STOP) || (devp->state == LPS25H_READY),
  472. "lps25hStart(), invalid state");
  473. devp->config = config;
  474. /* Control register 1 configuration block.*/
  475. {
  476. cr[0] = LPS25H_AD_CTRL_REG1;
  477. cr[1] = devp->config->outputdatarate | LPS25H_CTRL_REG1_PD;
  478. #if LPS25H_USE_ADVANCED || defined(__DOXYGEN__)
  479. cr[1] |= devp->config->blockdataupdate;
  480. #endif
  481. }
  482. #if LPS25H_SHARED_I2C
  483. i2cAcquireBus((devp)->config->i2cp);
  484. #endif /* LPS25H_SHARED_I2C */
  485. i2cStart((devp)->config->i2cp,
  486. (devp)->config->i2ccfg);
  487. lps25hI2CWriteRegister(devp->config->i2cp, devp->config->slaveaddress, cr, 1);
  488. #if LPS25H_SHARED_I2C
  489. i2cReleaseBus((devp)->config->i2cp);
  490. #endif /* LPS25H_SHARED_I2C */
  491. /* Resolution configuration block.*/
  492. {
  493. cr[0] = LPS25H_AD_RES_CONF;
  494. cr[1] = 0x05;
  495. #if LPS25H_USE_ADVANCED || defined(__DOXYGEN__)
  496. cr[1] = devp->config->baroresolution | devp->config->thermoresolution;
  497. #endif
  498. }
  499. #if LPS25H_SHARED_I2C
  500. i2cAcquireBus((devp)->config->i2cp);
  501. i2cStart((devp)->config->i2cp,
  502. (devp)->config->i2ccfg);
  503. #endif /* LPS25H_SHARED_I2C */
  504. lps25hI2CWriteRegister(devp->config->i2cp, devp->config->slaveaddress,
  505. cr, 1);
  506. #if LPS25H_SHARED_I2C
  507. i2cReleaseBus((devp)->config->i2cp);
  508. #endif /* LPS25H_SHARED_I2C */
  509. if(devp->config->barosensitivity == NULL) {
  510. devp->barosensitivity = LPS25H_BARO_SENS;
  511. }
  512. else{
  513. /* Taking barometer sensitivity from user configurations */
  514. devp->barosensitivity = *(devp->config->barosensitivity);
  515. }
  516. if(devp->config->barobias == NULL) {
  517. devp->barobias = LPS25H_BARO_BIAS;
  518. }
  519. else{
  520. /* Taking barometer bias from user configurations */
  521. devp->barobias = *(devp->config->barobias);
  522. }
  523. if(devp->config->thermosensitivity == NULL) {
  524. devp->thermosensitivity = LPS25H_THERMO_SENS;
  525. }
  526. else{
  527. /* Taking thermometer sensitivity from user configurations */
  528. devp->thermosensitivity = *(devp->config->thermosensitivity);
  529. }
  530. if(devp->config->thermobias == NULL) {
  531. devp->thermobias = LPS25H_THERMO_BIAS;
  532. }
  533. else{
  534. /* Taking thermometer bias from user configurations */
  535. devp->thermobias = *(devp->config->thermobias);
  536. }
  537. /* This is the Barometer transient recovery time */
  538. osalThreadSleepMilliseconds(5);
  539. devp->state = LPS25H_READY;
  540. }
  541. /**
  542. * @brief Deactivates the LPS25H Complex Driver peripheral.
  543. *
  544. * @param[in] devp pointer to the @p LPS25HDriver object
  545. *
  546. * @api
  547. */
  548. void lps25hStop(LPS25HDriver *devp) {
  549. uint8_t cr[2];
  550. osalDbgCheck(devp != NULL);
  551. osalDbgAssert((devp->state == LPS25H_STOP) || (devp->state == LPS25H_READY),
  552. "lps25hStop(), invalid state");
  553. if (devp->state == LPS25H_READY) {
  554. #if LPS25H_SHARED_I2C
  555. i2cAcquireBus((devp)->config->i2cp);
  556. i2cStart((devp)->config->i2cp,
  557. (devp)->config->i2ccfg);
  558. #endif /* LPS25H_SHARED_I2C */
  559. cr[0] = LPS25H_AD_CTRL_REG1;
  560. cr[1] = 0;
  561. lps25hI2CWriteRegister(devp->config->i2cp, devp->config->slaveaddress,
  562. cr, 1);
  563. i2cStop((devp)->config->i2cp);
  564. #if LPS25H_SHARED_I2C
  565. i2cReleaseBus((devp)->config->i2cp);
  566. #endif /* LPS25H_SHARED_I2C */
  567. }
  568. devp->state = LPS25H_STOP;
  569. }
  570. /** @} */