hts221_reg.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911
  1. /*
  2. ******************************************************************************
  3. * @file hts221_reg.c
  4. * @author MEMS Software Solution Team
  5. * @brief HTS221 driver file
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; COPYRIGHT(c) 2018 STMicroelectronics</center></h2>
  10. *
  11. * Redistribution and use in source and binary forms, with or without modification,
  12. * are permitted provided that the following conditions are met:
  13. * 1. Redistributions of source code must retain the above copyright notice,
  14. * this list of conditions and the following disclaimer.
  15. * 2. Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  19. * may be used to endorse or promote products derived from this software
  20. * without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  23. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  25. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  26. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  27. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  28. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  29. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  30. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  31. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. *
  33. */
  34. #include "hts221_reg.h"
  35. /**
  36. * @addtogroup hts221
  37. * @brief This file provides a set of functions needed to drive the
  38. * hts221 enanced inertial module.
  39. * @{
  40. */
  41. /**
  42. * @addtogroup interfaces_functions
  43. * @brief This section provide a set of functions used to read and write
  44. * a generic register of the device.
  45. * @{
  46. */
  47. /**
  48. * @brief Read generic device register
  49. *
  50. * @param hts221_ctx_t* ctx: read / write interface definitions
  51. * @param uint8_t reg: register to read
  52. * @param uint8_t* data: pointer to buffer that store the data read
  53. * @param uint16_t len: number of consecutive register to read
  54. *
  55. */
  56. int32_t hts221_read_reg(hts221_ctx_t *ctx, uint8_t reg, uint8_t *data,
  57. uint16_t len)
  58. {
  59. int32_t ret;
  60. ret = ctx->read_reg(ctx->handle, reg, data, len);
  61. return ret;
  62. }
  63. /**
  64. * @brief Write generic device register
  65. *
  66. * @param hts221_ctx_t *ctx: read / write interface definitions
  67. * @param uint8_t reg: register to write
  68. * @param uint8_t* data: pointer to data to write in register reg
  69. * @param uint16_t len: number of consecutive register to write
  70. *
  71. */
  72. int32_t hts221_write_reg(hts221_ctx_t *ctx, uint8_t reg, uint8_t *data,
  73. uint16_t len)
  74. {
  75. int32_t ret;
  76. ret = ctx->write_reg(ctx->handle, reg, data, len);
  77. return ret;
  78. }
  79. /**
  80. * @}
  81. */
  82. /**
  83. * @addtogroup data_generation_c
  84. * @brief This section group all the functions concerning data generation
  85. * @{
  86. */
  87. /**
  88. * @brief humidity_avg: [set] The numbers of averaged humidity samples.
  89. *
  90. * @param hts221_ctx_t *ctx: read / write interface definitions
  91. * @param hts221_avgh_t: change the values of avgh in reg AV_CONF
  92. *
  93. */
  94. int32_t hts221_humidity_avg_set(hts221_ctx_t *ctx, hts221_avgh_t val)
  95. {
  96. hts221_reg_t reg;
  97. int32_t ret;
  98. ret = hts221_read_reg(ctx, HTS221_AV_CONF, &reg.byte, 1);
  99. if (ret == 0)
  100. {
  101. reg.av_conf.avgh = (uint8_t)val;
  102. ret = hts221_write_reg(ctx, HTS221_AV_CONF, &reg.byte, 1);
  103. }
  104. return ret;
  105. }
  106. /**
  107. * @brief humidity_avg: [get] The numbers of averaged humidity samples.
  108. *
  109. * @param hts221_ctx_t *ctx: read / write interface definitions
  110. * @param hts221_avgh_t: Get the values of avgh in reg AV_CONF
  111. *
  112. */
  113. int32_t hts221_humidity_avg_get(hts221_ctx_t *ctx, hts221_avgh_t *val)
  114. {
  115. hts221_reg_t reg;
  116. int32_t ret;
  117. ret = hts221_read_reg(ctx, HTS221_AV_CONF, &reg.byte, 1);
  118. switch (reg.av_conf.avgh)
  119. {
  120. case HTS221_H_AVG_4:
  121. *val = HTS221_H_AVG_4;
  122. break;
  123. case HTS221_H_AVG_8:
  124. *val = HTS221_H_AVG_8;
  125. break;
  126. case HTS221_H_AVG_16:
  127. *val = HTS221_H_AVG_16;
  128. break;
  129. case HTS221_H_AVG_32:
  130. *val = HTS221_H_AVG_32;
  131. break;
  132. case HTS221_H_AVG_64:
  133. *val = HTS221_H_AVG_64;
  134. break;
  135. case HTS221_H_AVG_128:
  136. *val = HTS221_H_AVG_128;
  137. break;
  138. case HTS221_H_AVG_256:
  139. *val = HTS221_H_AVG_256;
  140. break;
  141. case HTS221_H_AVG_512:
  142. *val = HTS221_H_AVG_512;
  143. break;
  144. default:
  145. *val = HTS221_H_AVG_ND;
  146. break;
  147. }
  148. return ret;
  149. }
  150. /**
  151. * @brief temperature_avg: [set] The numbers of averaged temperature samples.
  152. *
  153. * @param hts221_ctx_t *ctx: read / write interface definitions
  154. * @param hts221_avgt_t: change the values of avgt in reg AV_CONF
  155. *
  156. */
  157. int32_t hts221_temperature_avg_set(hts221_ctx_t *ctx, hts221_avgt_t val)
  158. {
  159. hts221_reg_t reg;
  160. int32_t ret;
  161. ret = hts221_read_reg(ctx, HTS221_AV_CONF, &reg.byte, 1);
  162. if (ret == 0)
  163. {
  164. reg.av_conf.avgt = (uint8_t)val;
  165. ret = hts221_write_reg(ctx, HTS221_AV_CONF, &reg.byte, 1);
  166. }
  167. return ret;
  168. }
  169. /**
  170. * @brief temperature_avg: [get] The numbers of averaged temperature
  171. * samples.
  172. *
  173. * @param hts221_ctx_t *ctx: read / write interface definitions
  174. * @param hts221_avgt_t: Get the values of avgt in reg AV_CONF
  175. *
  176. */
  177. int32_t hts221_temperature_avg_get(hts221_ctx_t *ctx, hts221_avgt_t *val)
  178. {
  179. hts221_reg_t reg;
  180. int32_t ret;
  181. ret = hts221_read_reg(ctx, HTS221_AV_CONF, &reg.byte, 1);
  182. switch (reg.av_conf.avgh)
  183. {
  184. case HTS221_T_AVG_2:
  185. *val = HTS221_T_AVG_2;
  186. break;
  187. case HTS221_T_AVG_4:
  188. *val = HTS221_T_AVG_4;
  189. break;
  190. case HTS221_T_AVG_8:
  191. *val = HTS221_T_AVG_8;
  192. break;
  193. case HTS221_T_AVG_16:
  194. *val = HTS221_T_AVG_16;
  195. break;
  196. case HTS221_T_AVG_32:
  197. *val = HTS221_T_AVG_32;
  198. break;
  199. case HTS221_T_AVG_64:
  200. *val = HTS221_T_AVG_64;
  201. break;
  202. case HTS221_T_AVG_128:
  203. *val = HTS221_T_AVG_128;
  204. break;
  205. case HTS221_T_AVG_256:
  206. *val = HTS221_T_AVG_256;
  207. break;
  208. default:
  209. *val = HTS221_T_AVG_ND;
  210. break;
  211. }
  212. return ret;
  213. }
  214. /**
  215. * @brief data_rate: [set] Output data rate selection.
  216. *
  217. * @param hts221_ctx_t *ctx: read / write interface definitions
  218. * @param hts221_odr_t: change the values of odr in reg CTRL_REG1
  219. *
  220. */
  221. int32_t hts221_data_rate_set(hts221_ctx_t *ctx, hts221_odr_t val)
  222. {
  223. hts221_reg_t reg;
  224. int32_t ret;
  225. ret = hts221_read_reg(ctx, HTS221_CTRL_REG1, &reg.byte, 1);
  226. if (ret == 0)
  227. {
  228. reg.ctrl_reg1.odr = (uint8_t)val;
  229. ret = hts221_write_reg(ctx, HTS221_CTRL_REG1, &reg.byte, 1);
  230. }
  231. return ret;
  232. }
  233. /**
  234. * @brief data_rate: [get] Output data rate selection.
  235. *
  236. * @param hts221_ctx_t *ctx: read / write interface definitions
  237. * @param hts221_odr_t: Get the values of odr in reg CTRL_REG1
  238. *
  239. */
  240. int32_t hts221_data_rate_get(hts221_ctx_t *ctx, hts221_odr_t *val)
  241. {
  242. hts221_reg_t reg;
  243. int32_t ret;
  244. ret = hts221_read_reg(ctx, HTS221_CTRL_REG1, &reg.byte, 1);
  245. switch (reg.ctrl_reg1.odr)
  246. {
  247. case HTS221_ONE_SHOT:
  248. *val = HTS221_ONE_SHOT;
  249. break;
  250. case HTS221_ODR_1Hz:
  251. *val = HTS221_ODR_1Hz;
  252. break;
  253. case HTS221_ODR_7Hz:
  254. *val = HTS221_ODR_7Hz;
  255. break;
  256. case HTS221_ODR_12Hz5:
  257. *val = HTS221_ODR_12Hz5;
  258. break;
  259. default:
  260. *val = HTS221_ODR_ND;
  261. break;
  262. }
  263. return ret;
  264. }
  265. /**
  266. * @brief block_data_update: [set] Blockdataupdate.
  267. *
  268. * @param hts221_ctx_t *ctx: read / write interface definitions
  269. * @param uint8_t val: change the values of bdu in reg CTRL_REG1
  270. *
  271. */
  272. int32_t hts221_block_data_update_set(hts221_ctx_t *ctx, uint8_t val)
  273. {
  274. hts221_reg_t reg;
  275. int32_t ret;
  276. ret = hts221_read_reg(ctx, HTS221_CTRL_REG1, &reg.byte, 1);
  277. if (ret == 0)
  278. {
  279. reg.ctrl_reg1.bdu = val;
  280. ret = hts221_write_reg(ctx, HTS221_CTRL_REG1, &reg.byte, 1);
  281. }
  282. return ret;
  283. }
  284. /**
  285. * @brief block_data_update: [get] Blockdataupdate.
  286. *
  287. * @param hts221_ctx_t *ctx: read / write interface definitions
  288. * @param uint8_t: change the values of bdu in reg CTRL_REG1
  289. *
  290. */
  291. int32_t hts221_block_data_update_get(hts221_ctx_t *ctx, uint8_t *val)
  292. {
  293. hts221_reg_t reg;
  294. int32_t ret;
  295. ret = hts221_read_reg(ctx, HTS221_CTRL_REG1, &reg.byte, 1);
  296. *val = reg.ctrl_reg1.bdu;
  297. return ret;
  298. }
  299. /**
  300. * @brief one_shoot_trigger: [set] One-shot mode. Device perform a
  301. * single measure.
  302. *
  303. * @param hts221_ctx_t *ctx: read / write interface definitions
  304. * @param uint8_t val: change the values of one_shot in reg CTRL_REG2
  305. *
  306. */
  307. int32_t hts221_one_shoot_trigger_set(hts221_ctx_t *ctx, uint8_t val)
  308. {
  309. hts221_reg_t reg;
  310. int32_t ret;
  311. ret = hts221_read_reg(ctx, HTS221_CTRL_REG2, &reg.byte, 1);
  312. if (ret == 0)
  313. {
  314. reg.ctrl_reg2.one_shot = val;
  315. ret = hts221_write_reg(ctx, HTS221_CTRL_REG2, &reg.byte, 1);
  316. }
  317. return ret;
  318. }
  319. /**
  320. * @brief one_shoot_trigger: [get] One-shot mode. Device perform a
  321. * single measure.
  322. *
  323. * @param hts221_ctx_t *ctx: read / write interface definitions
  324. * @param uint8_t: change the values of one_shot in reg CTRL_REG2
  325. *
  326. */
  327. int32_t hts221_one_shoot_trigger_get(hts221_ctx_t *ctx, uint8_t *val)
  328. {
  329. hts221_reg_t reg;
  330. int32_t ret;
  331. ret = hts221_read_reg(ctx, HTS221_CTRL_REG2, &reg.byte, 1);
  332. *val = reg.ctrl_reg2.one_shot;
  333. return ret;
  334. }
  335. /**
  336. * @brief temp_data_ready: [get] Temperature data available.
  337. *
  338. * @param hts221_ctx_t *ctx: read / write interface definitions
  339. * @param uint8_t: change the values of t_da in reg STATUS_REG
  340. *
  341. */
  342. int32_t hts221_temp_data_ready_get(hts221_ctx_t *ctx, uint8_t *val)
  343. {
  344. hts221_reg_t reg;
  345. int32_t ret;
  346. ret = hts221_read_reg(ctx, HTS221_STATUS_REG, &reg.byte, 1);
  347. *val = reg.status_reg.t_da;
  348. return ret;
  349. }
  350. /**
  351. * @brief hum_data_ready: [get] Humidity data available.
  352. *
  353. * @param hts221_ctx_t *ctx: read / write interface definitions
  354. * @param uint8_t: change the values of h_da in reg STATUS_REG
  355. *
  356. */
  357. int32_t hts221_hum_data_ready_get(hts221_ctx_t *ctx, uint8_t *val)
  358. {
  359. hts221_reg_t reg;
  360. int32_t ret;
  361. ret = hts221_read_reg(ctx, HTS221_STATUS_REG, &reg.byte, 1);
  362. *val = reg.status_reg.h_da;
  363. return ret;
  364. }
  365. /**
  366. * @brief humidity_raw: [get] Humidity output value
  367. *
  368. * @param hts221_ctx_t *ctx: read / write interface definitions
  369. * @param uint8_t * : buffer that stores data read
  370. *
  371. */
  372. int32_t hts221_humidity_raw_get(hts221_ctx_t *ctx, uint8_t *buff)
  373. {
  374. return hts221_read_reg(ctx, HTS221_HUMIDITY_OUT_L, buff, 2);
  375. }
  376. /**
  377. * @brief temperature_raw: [get] Temperature output value
  378. *
  379. * @param hts221_ctx_t *ctx: read / write interface definitions
  380. * @param uint8_t * : buffer that stores data read
  381. *
  382. */
  383. int32_t hts221_temperature_raw_get(hts221_ctx_t *ctx, uint8_t *buff)
  384. {
  385. return hts221_read_reg(ctx, HTS221_TEMP_OUT_L, buff, 2);
  386. }
  387. /**
  388. * @}
  389. */
  390. /**
  391. * @addtogroup common
  392. * @brief This section group common usefull functions
  393. * @{
  394. */
  395. /**
  396. * @brief device_id: [get] DeviceWhoamI.
  397. *
  398. * @param hts221_ctx_t *ctx: read / write interface definitions
  399. * @param uint8_t * : buffer that stores data read
  400. *
  401. */
  402. int32_t hts221_device_id_get(hts221_ctx_t *ctx, uint8_t *buff)
  403. {
  404. return hts221_read_reg(ctx, HTS221_WHO_AM_I, buff, 1);
  405. }
  406. /**
  407. * @brief power_on: [set] Switch device on/off
  408. *
  409. * @param hts221_ctx_t *ctx: read / write interface definitions
  410. * @param uint8_t val: change the values of pd in reg CTRL_REG1
  411. *
  412. */
  413. int32_t hts221_power_on_set(hts221_ctx_t *ctx, uint8_t val)
  414. {
  415. hts221_reg_t reg;
  416. int32_t ret;
  417. ret = hts221_read_reg(ctx, HTS221_CTRL_REG1, &reg.byte, 1);
  418. if (ret == 0)
  419. {
  420. reg.ctrl_reg1.pd = val;
  421. ret = hts221_write_reg(ctx, HTS221_CTRL_REG1, &reg.byte, 1);
  422. }
  423. return ret;
  424. }
  425. /**
  426. * @brief power_on: [get] Switch device on/off
  427. *
  428. * @param hts221_ctx_t *ctx: read / write interface definitions
  429. * @param uint8_t: change the values of pd in reg CTRL_REG1
  430. *
  431. */
  432. int32_t hts221_power_on_get(hts221_ctx_t *ctx, uint8_t *val)
  433. {
  434. hts221_reg_t reg;
  435. int32_t mm_error;
  436. mm_error = hts221_read_reg(ctx, HTS221_CTRL_REG1, &reg.byte, 1);
  437. *val = reg.ctrl_reg1.pd;
  438. return mm_error;
  439. }
  440. /**
  441. * @brief heater: [set] Heater enable / disable.
  442. *
  443. * @param hts221_ctx_t *ctx: read / write interface definitions
  444. * @param uint8_t val: change the values of heater in reg CTRL_REG2
  445. *
  446. */
  447. int32_t hts221_heater_set(hts221_ctx_t *ctx, uint8_t val)
  448. {
  449. hts221_reg_t reg;
  450. int32_t ret;
  451. ret = hts221_read_reg(ctx, HTS221_CTRL_REG2, &reg.byte, 1);
  452. if (ret == 0)
  453. {
  454. reg.ctrl_reg2.heater = val;
  455. ret = hts221_write_reg(ctx, HTS221_CTRL_REG2, &reg.byte, 1);
  456. }
  457. return ret;
  458. }
  459. /**
  460. * @brief heater: [get] Heater enable / disable.
  461. *
  462. * @param hts221_ctx_t *ctx: read / write interface definitions
  463. * @param uint8_t: change the values of heater in reg CTRL_REG2
  464. *
  465. */
  466. int32_t hts221_heater_get(hts221_ctx_t *ctx, uint8_t *val)
  467. {
  468. hts221_reg_t reg;
  469. int32_t ret;
  470. ret = hts221_read_reg(ctx, HTS221_CTRL_REG2, &reg.byte, 1);
  471. *val = reg.ctrl_reg2.heater;
  472. return ret;
  473. }
  474. /**
  475. * @brief boot: [set] Reboot memory content. Reload the calibration
  476. * parameters.
  477. *
  478. * @param hts221_ctx_t *ctx: read / write interface definitions
  479. * @param uint8_t val: change the values of boot in reg CTRL_REG2
  480. *
  481. */
  482. int32_t hts221_boot_set(hts221_ctx_t *ctx, uint8_t val)
  483. {
  484. hts221_reg_t reg;
  485. int32_t ret;
  486. ret = hts221_read_reg(ctx, HTS221_CTRL_REG2, &reg.byte, 1);
  487. if (ret == 0)
  488. {
  489. reg.ctrl_reg2.boot = val;
  490. ret = hts221_write_reg(ctx, HTS221_CTRL_REG2, &reg.byte, 1);
  491. }
  492. return ret;
  493. }
  494. /**
  495. * @brief boot: [get] Reboot memory content. Reload the calibration
  496. * parameters.
  497. *
  498. * @param hts221_ctx_t *ctx: read / write interface definitions
  499. * @param uint8_t: change the values of boot in reg CTRL_REG2
  500. *
  501. */
  502. int32_t hts221_boot_get(hts221_ctx_t *ctx, uint8_t *val)
  503. {
  504. hts221_reg_t reg;
  505. int32_t ret;
  506. ret = hts221_read_reg(ctx, HTS221_CTRL_REG2, &reg.byte, 1);
  507. *val = reg.ctrl_reg2.boot;
  508. return ret;
  509. }
  510. /**
  511. * @brief status: [get] Info about device status
  512. *
  513. * @param hts221_ctx_t *ctx: read / write interface definitions
  514. * @param hts221_status_t: Registers STATUS_REG
  515. *
  516. */
  517. int32_t hts221_status_get(hts221_ctx_t *ctx, hts221_status_reg_t *val)
  518. {
  519. return hts221_read_reg(ctx, HTS221_STATUS_REG, (uint8_t *) val, 1);
  520. }
  521. /**
  522. * @}
  523. */
  524. /**
  525. * @addtogroup interrupts
  526. * @brief This section group all the functions that manage interrupts
  527. * @{
  528. */
  529. /**
  530. * @brief drdy_on_int: [set] Data-ready signal on INT_DRDY pin.
  531. *
  532. * @param hts221_ctx_t *ctx: read / write interface definitions
  533. * @param uint8_t val: change the values of drdy in reg CTRL_REG3
  534. *
  535. */
  536. int32_t hts221_drdy_on_int_set(hts221_ctx_t *ctx, uint8_t val)
  537. {
  538. hts221_reg_t reg;
  539. int32_t ret;
  540. ret = hts221_read_reg(ctx, HTS221_CTRL_REG3, &reg.byte, 1);
  541. if (ret == 0)
  542. {
  543. reg.ctrl_reg3.drdy = val;
  544. ret = hts221_write_reg(ctx, HTS221_CTRL_REG3, &reg.byte, 1);
  545. }
  546. return ret;
  547. }
  548. /**
  549. * @brief drdy_on_int: [get] Data-ready signal on INT_DRDY pin.
  550. *
  551. * @param hts221_ctx_t *ctx: read / write interface definitions
  552. * @param uint8_t: change the values of drdy in reg CTRL_REG3
  553. *
  554. */
  555. int32_t hts221_drdy_on_int_get(hts221_ctx_t *ctx, uint8_t *val)
  556. {
  557. hts221_reg_t reg;
  558. int32_t ret;
  559. ret = hts221_read_reg(ctx, HTS221_CTRL_REG3, &reg.byte, 1);
  560. *val = reg.ctrl_reg3.drdy;
  561. return ret;
  562. }
  563. /**
  564. * @brief pin_mode: [set] Push-pull/open drain selection on interrupt pads.
  565. *
  566. * @param hts221_ctx_t *ctx: read / write interface definitions
  567. * @param hts221_pp_od_t: change the values of pp_od in reg CTRL_REG3
  568. *
  569. */
  570. int32_t hts221_pin_mode_set(hts221_ctx_t *ctx, hts221_pp_od_t val)
  571. {
  572. hts221_reg_t reg;
  573. int32_t ret;
  574. ret = hts221_read_reg(ctx, HTS221_CTRL_REG3, &reg.byte, 1);
  575. if (ret == 0)
  576. {
  577. reg.ctrl_reg3.pp_od = (uint8_t)val;
  578. ret = hts221_write_reg(ctx, HTS221_CTRL_REG3, &reg.byte, 1);
  579. }
  580. return ret;
  581. }
  582. /**
  583. * @brief pin_mode: [get] Push-pull/open drain selection on interrupt pads.
  584. *
  585. * @param hts221_ctx_t *ctx: read / write interface definitions
  586. * @param hts221_pp_od_t: Get the values of pp_od in reg CTRL_REG3
  587. *
  588. */
  589. int32_t hts221_pin_mode_get(hts221_ctx_t *ctx, hts221_pp_od_t *val)
  590. {
  591. hts221_reg_t reg;
  592. int32_t ret;
  593. ret = hts221_read_reg(ctx, HTS221_CTRL_REG3, &reg.byte, 1);
  594. switch (reg.ctrl_reg3.pp_od)
  595. {
  596. case HTS221_PUSH_PULL:
  597. *val = HTS221_PUSH_PULL;
  598. break;
  599. case HTS221_OPEN_DRAIN:
  600. *val = HTS221_OPEN_DRAIN;
  601. break;
  602. default:
  603. *val = HTS221_PIN_MODE_ND;
  604. break;
  605. }
  606. return ret;
  607. }
  608. /**
  609. * @brief int_polarity: [set] Interrupt active-high/low.
  610. *
  611. * @param hts221_ctx_t *ctx: read / write interface definitions
  612. * @param hts221_drdy_h_l_t: change the values of drdy_h_l in reg CTRL_REG3
  613. *
  614. */
  615. int32_t hts221_int_polarity_set(hts221_ctx_t *ctx, hts221_drdy_h_l_t val)
  616. {
  617. hts221_reg_t reg;
  618. int32_t ret;
  619. ret = hts221_read_reg(ctx, HTS221_CTRL_REG3, &reg.byte, 1);
  620. if (ret == 0)
  621. {
  622. reg.ctrl_reg3.drdy_h_l = (uint8_t)val;
  623. ret = hts221_write_reg(ctx, HTS221_CTRL_REG3, &reg.byte, 1);
  624. }
  625. return ret;
  626. }
  627. /**
  628. * @brief int_polarity: [get] Interrupt active-high/low.
  629. *
  630. * @param hts221_ctx_t *ctx: read / write interface definitions
  631. * @param hts221_drdy_h_l_t: Get the values of drdy_h_l in reg CTRL_REG3
  632. *
  633. */
  634. int32_t hts221_int_polarity_get(hts221_ctx_t *ctx, hts221_drdy_h_l_t *val)
  635. {
  636. hts221_reg_t reg;
  637. int32_t ret;
  638. ret = hts221_read_reg(ctx, HTS221_CTRL_REG3, &reg.byte, 1);
  639. switch (reg.ctrl_reg3.drdy_h_l)
  640. {
  641. case HTS221_ACTIVE_HIGH:
  642. *val = HTS221_ACTIVE_HIGH;
  643. break;
  644. case HTS221_ACTIVE_LOW:
  645. *val = HTS221_ACTIVE_LOW;
  646. break;
  647. default:
  648. *val = HTS221_ACTIVE_ND;
  649. break;
  650. }
  651. return ret;
  652. }
  653. /**
  654. * @}
  655. */
  656. /**
  657. * @addtogroup calibration
  658. * @brief This section group all the calibration coefficients need
  659. * for reading data
  660. * @{
  661. */
  662. /**
  663. * @brief hum_rh_point_0: [get] First calibration point for Rh Humidity.
  664. *
  665. * @param hts221_ctx_t *ctx: read / write interface definitions
  666. * @param uint8_t * : buffer that stores data read
  667. *
  668. */
  669. int32_t hts221_hum_rh_point_0_get(hts221_ctx_t *ctx, uint8_t *buff)
  670. {
  671. int32_t ret;
  672. ret = hts221_read_reg(ctx, HTS221_H0_RH_X2, buff, 1);
  673. *buff = (uint8_t)(((uint16_t)(*buff) >> 1) & 0x7FFFu);
  674. return ret;
  675. }
  676. /**
  677. * @brief hum_rh_point_1: [get] Second calibration point for Rh Humidity.
  678. *
  679. * @param hts221_ctx_t *ctx: read / write interface definitions
  680. * @param uint8_t * : buffer that stores data read
  681. *
  682. */
  683. int32_t hts221_hum_rh_point_1_get(hts221_ctx_t *ctx, uint8_t *buff)
  684. {
  685. int32_t ret;
  686. ret = hts221_read_reg(ctx, HTS221_H1_RH_X2, buff, 1);
  687. *buff = (uint8_t)(((uint16_t)(*buff) >> 1) & 0x7FFFu);
  688. return ret;
  689. }
  690. /**
  691. * @brief temp_deg_point_0: [get] First calibration point for
  692. * degC temperature.
  693. *
  694. * @param hts221_ctx_t *ctx: read / write interface definitions
  695. * @param uint8_t * : buffer that stores data read
  696. *
  697. */
  698. int32_t hts221_temp_deg_point_0_get(hts221_ctx_t *ctx, uint8_t *buff)
  699. {
  700. hts221_reg_t reg;
  701. int32_t ret;
  702. axis1bit16_t coeff;
  703. ret = hts221_read_reg(ctx, HTS221_T0_DEGC_X8, coeff.u8bit, 1);
  704. if (ret == 0)
  705. {
  706. ret = hts221_read_reg(ctx, HTS221_T1_T0_MSB, &reg.byte, 1);
  707. coeff.u8bit[1] = reg.t1_t0_msb.t0_msb;
  708. coeff.i16bit = coeff.i16bit / 8;
  709. *(buff) = (uint8_t)coeff.i16bit;
  710. }
  711. return ret;
  712. }
  713. /**
  714. * @brief temp_deg_point_1: [get] Second calibration point for
  715. * degC temperature.
  716. *
  717. * @param hts221_ctx_t *ctx: read / write interface definitions
  718. * @param uint8_t * : buffer that stores data read
  719. *
  720. */
  721. int32_t hts221_temp_deg_point_1_get(hts221_ctx_t *ctx, uint8_t *buff)
  722. {
  723. hts221_reg_t reg;
  724. int32_t ret;
  725. axis1bit16_t coeff;
  726. ret = hts221_read_reg(ctx, HTS221_T1_DEGC_X8, coeff.u8bit, 1);
  727. if (ret == 0)
  728. {
  729. ret = hts221_read_reg(ctx, HTS221_T1_T0_MSB, &reg.byte, 1);
  730. coeff.u8bit[1] = reg.t1_t0_msb.t1_msb;
  731. coeff.i16bit = coeff.i16bit / 8;
  732. *(buff) = (uint8_t)coeff.i16bit;
  733. }
  734. return ret;
  735. }
  736. /**
  737. * @brief hum_adc_point_0: [get] First calibration point for
  738. * humidity in LSB.
  739. *
  740. * @param hts221_ctx_t *ctx: read / write interface definitions
  741. * @param uint8_t * : buffer that stores data read
  742. *
  743. */
  744. int32_t hts221_hum_adc_point_0_get(hts221_ctx_t *ctx, uint8_t *buff)
  745. {
  746. return hts221_read_reg(ctx, HTS221_H0_T0_OUT_L, buff, 2);
  747. }
  748. /**
  749. * @brief hum_adc_point_1: [get] Second calibration point for
  750. * humidity in LSB.
  751. *
  752. * @param hts221_ctx_t *ctx: read / write interface definitions
  753. * @param uint8_t * : buffer that stores data read
  754. *
  755. */
  756. int32_t hts221_hum_adc_point_1_get(hts221_ctx_t *ctx, uint8_t *buff)
  757. {
  758. return hts221_read_reg(ctx, HTS221_H1_T0_OUT_L, buff, 2);
  759. }
  760. /**
  761. * @brief temp_adc_point_0: [get] First calibration point for
  762. * temperature in LSB.
  763. *
  764. * @param hts221_ctx_t *ctx: read / write interface definitions
  765. * @param uint8_t * : buffer that stores data read
  766. *
  767. */
  768. int32_t hts221_temp_adc_point_0_get(hts221_ctx_t *ctx, uint8_t *buff)
  769. {
  770. return hts221_read_reg(ctx, HTS221_T0_OUT_L, buff, 2);
  771. }
  772. /**
  773. * @brief temp_adc_point_1: [get] Second calibration point for
  774. * temperature in LSB.
  775. *
  776. * @param hts221_ctx_t *ctx: read / write interface definitions
  777. * @param uint8_t * : buffer that stores data read
  778. *
  779. */
  780. int32_t hts221_temp_adc_point_1_get(hts221_ctx_t *ctx, uint8_t *buff)
  781. {
  782. return hts221_read_reg(ctx, HTS221_T1_OUT_L, buff, 2);
  783. }
  784. /**
  785. * @}
  786. */
  787. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/