lis3mdl.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670
  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 lis3mdl.h
  17. * @brief LIS3MDL MEMS interface module header.
  18. *
  19. * @addtogroup LIS3MDL
  20. * @ingroup EX_ST
  21. * @{
  22. */
  23. #ifndef _LIS3MDL_H_
  24. #define _LIS3MDL_H_
  25. #include "hal_compass.h"
  26. /*===========================================================================*/
  27. /* Driver constants. */
  28. /*===========================================================================*/
  29. /**
  30. * @name Version identification
  31. * @{
  32. */
  33. /**
  34. * @brief LIS3MDL driver version string.
  35. */
  36. #define EX_LIS3MDL_VERSION "1.1.2"
  37. /**
  38. * @brief LIS3MDL driver version major number.
  39. */
  40. #define EX_LIS3MDL_MAJOR 1
  41. /**
  42. * @brief LIS3MDL driver version minor number.
  43. */
  44. #define EX_LIS3MDL_MINOR 1
  45. /**
  46. * @brief LIS3MDL driver version patch number.
  47. */
  48. #define EX_LIS3MDL_PATCH 2
  49. /** @} */
  50. /**
  51. * @brief LIS3MDL compass subsystem characteristics.
  52. * @note Sensitivity is expressed as G/LSB whereas G stands for Gauss.
  53. * @note Bias is expressed as G.
  54. *
  55. * @{
  56. */
  57. #define LIS3MDL_COMP_NUMBER_OF_AXES 3U
  58. #define LIS3MDL_COMP_4GA 4.0f
  59. #define LIS3MDL_COMP_8GA 8.0f
  60. #define LIS3MDL_COMP_12GA 12.0f
  61. #define LIS3MDL_COMP_16GA 16.0f
  62. #define LIS3MDL_COMP_SENS_4GA 0.00014615f
  63. #define LIS3MDL_COMP_SENS_8GA 0.00029231f
  64. #define LIS3MDL_COMP_SENS_12GA 0.0004384f
  65. #define LIS3MDL_COMP_SENS_16GA 0.00058445f
  66. #define LIS3MDL_COMP_BIAS 0.0f
  67. /** @} */
  68. /**
  69. * @name LIS3MDL communication interfaces related bit masks
  70. * @{
  71. */
  72. #define LIS3MDL_DI_MASK 0xFF
  73. #define LIS3MDL_DI(n) (1 << n)
  74. #define LIS3MDL_AD_MASK 0x3F
  75. #define LIS3MDL_AD(n) (1 << n)
  76. #define LIS3MDL_MS (1 << 6)
  77. #define LIS3MDL_RW (1 << 7)
  78. #define LIS3MDL_SUB_MS (1 << 7)
  79. /** @} */
  80. /**
  81. * @name LIS3MDL register addresses
  82. * @{
  83. */
  84. #define LIS3MDL_AD_WHO_AM_I 0x0F
  85. #define LIS3MDL_AD_CTRL_REG1 0x20
  86. #define LIS3MDL_AD_CTRL_REG2 0x21
  87. #define LIS3MDL_AD_CTRL_REG3 0x22
  88. #define LIS3MDL_AD_CTRL_REG4 0x23
  89. #define LIS3MDL_AD_CTRL_REG5 0x24
  90. #define LIS3MDL_AD_STATUS_REG 0x27
  91. #define LIS3MDL_AD_OUT_X_L 0x28
  92. #define LIS3MDL_AD_OUT_X_H 0x29
  93. #define LIS3MDL_AD_OUT_Y_L 0x2A
  94. #define LIS3MDL_AD_OUT_Y_H 0x2B
  95. #define LIS3MDL_AD_OUT_Z_L 0x2C
  96. #define LIS3MDL_AD_OUT_Z_H 0x2D
  97. #define LIS3MDL_AD_TEMP_OUT_L 0x2E
  98. #define LIS3MDL_AD_TEMP_OUT_H 0x2F
  99. #define LIS3MDL_AD_INT_CFG 0x30
  100. #define LIS3MDL_AD_INT_SOURCE 0x31
  101. #define LIS3MDL_AD_INT_THS_L 0x32
  102. #define LIS3MDL_AD_INT_THS_H 0x33
  103. /** @} */
  104. /**
  105. * @name LIS3MDL_CTRL_REG1 register bits definitions
  106. * @{
  107. */
  108. #define LIS3MDL_CTRL_REG1_MASK 0xFF
  109. #define LIS3MDL_CTRL_REG1_ST (1 << 0)
  110. #define LIS3MDL_CTRL_REG1_FAST_ODR (1 << 1)
  111. #define LIS3MDL_CTRL_REG1_DO0 (1 << 2)
  112. #define LIS3MDL_CTRL_REG1_DO1 (1 << 3)
  113. #define LIS3MDL_CTRL_REG1_DO2 (1 << 4)
  114. #define LIS3MDL_CTRL_REG1_OM0 (1 << 5)
  115. #define LIS3MDL_CTRL_REG1_OM1 (1 << 6)
  116. #define LIS3MDL_CTRL_REG1_TEMP_EN (1 << 7)
  117. /** @} */
  118. /**
  119. * @name LIS3MDL_CTRL_REG2 register bits definitions
  120. * @{
  121. */
  122. #define LIS3MDL_CTRL_REG2_MASK 0x6C
  123. #define LIS3MDL_CTRL_REG2_SOFT_RST (1 << 2)
  124. #define LIS3MDL_CTRL_REG2_REBOOT (1 << 3)
  125. #define LIS3MDL_CTRL_REG2_FS_MASK 0x60
  126. #define LIS3MDL_CTRL_REG2_FS0 (1 << 5)
  127. #define LIS3MDL_CTRL_REG2_FS1 (1 << 6)
  128. /** @} */
  129. /**
  130. * @name LIS3MDL_CTRL_REG3 register bits definitions
  131. * @{
  132. */
  133. #define LIS3MDL_CTRL_REG3_MASK 0x27
  134. #define LIS3MDL_CTRL_REG3_MD0 (1 << 0)
  135. #define LIS3MDL_CTRL_REG3_MD1 (1 << 1)
  136. #define LIS3MDL_CTRL_REG3_SIM (1 << 2)
  137. #define LIS3MDL_CTRL_REG3_LP (1 << 5)
  138. /** @} */
  139. /**
  140. * @name LIS3MDL_CTRL_REG4 register bits definitions
  141. * @{
  142. */
  143. #define LIS3MDL_CTRL_REG4_MASK 0x0E
  144. #define LIS3MDL_CTRL_REG4_BLE (1 << 1)
  145. #define LIS3MDL_CTRL_REG4_OMZ0 (1 << 2)
  146. #define LIS3MDL_CTRL_REG4_OMZ1 (1 << 3)
  147. /** @} */
  148. /**
  149. * @name LIS3MDL_CTRL_REG5 register bits definitions
  150. * @{
  151. */
  152. #define LIS3MDL_CTRL_REG5_MASK 0xC0
  153. #define LIS3MDL_CTRL_REG5_BDU (1 << 6)
  154. #define LIS3MDL_CTRL_REG5_FAST_READ (1 << 7)
  155. /** @} */
  156. /*===========================================================================*/
  157. /* Driver pre-compile time settings. */
  158. /*===========================================================================*/
  159. /**
  160. * @name Configuration options
  161. * @{
  162. */
  163. /**
  164. * @brief LIS3MDL SPI interface switch.
  165. * @details If set to @p TRUE the support for SPI is included.
  166. * @note The default is @p FALSE.
  167. */
  168. #if !defined(LIS3MDL_USE_SPI) || defined(__DOXYGEN__)
  169. #define LIS3MDL_USE_SPI FALSE
  170. #endif
  171. /**
  172. * @brief LIS3MDL shared SPI switch.
  173. * @details If set to @p TRUE the device acquires SPI bus ownership
  174. * on each transaction.
  175. * @note The default is @p FALSE. Requires SPI_USE_MUTUAL_EXCLUSION.
  176. */
  177. #if !defined(LIS3MDL_SHARED_SPI) || defined(__DOXYGEN__)
  178. #define LIS3MDL_SHARED_SPI FALSE
  179. #endif
  180. /**
  181. * @brief LIS3MDL I2C interface switch.
  182. * @details If set to @p TRUE the support for I2C is included.
  183. * @note The default is @p TRUE.
  184. */
  185. #if !defined(LIS3MDL_USE_I2C) || defined(__DOXYGEN__)
  186. #define LIS3MDL_USE_I2C TRUE
  187. #endif
  188. /**
  189. * @brief LIS3MDL shared I2C switch.
  190. * @details If set to @p TRUE the device acquires I2C bus ownership
  191. * on each transaction.
  192. * @note The default is @p FALSE. Requires I2C_USE_MUTUAL_EXCLUSION
  193. */
  194. #if !defined(LIS3MDL_SHARED_I2C) || defined(__DOXYGEN__)
  195. #define LIS3MDL_SHARED_I2C FALSE
  196. #endif
  197. /**
  198. * @brief LIS3MDL advanced configurations switch.
  199. * @details If set to @p TRUE more configurations are available.
  200. * @note The default is @p FALSE.
  201. */
  202. #if !defined(LIS3MDL_USE_ADVANCED) || defined(__DOXYGEN__)
  203. #define LIS3MDL_USE_ADVANCED FALSE
  204. #endif
  205. /** @} */
  206. /*===========================================================================*/
  207. /* Derived constants and error checks. */
  208. /*===========================================================================*/
  209. #if !(LIS3MDL_USE_SPI ^ LIS3MDL_USE_I2C)
  210. #error "LIS3MDL_USE_SPI and LIS3MDL_USE_I2C cannot be both true or both false"
  211. #endif
  212. #if LIS3MDL_USE_SPI && !HAL_USE_SPI
  213. #error "LIS3MDL_USE_SPI requires HAL_USE_SPI"
  214. #endif
  215. #if LIS3MDL_SHARED_SPI && !SPI_USE_MUTUAL_EXCLUSION
  216. #error "LIS3MDL_SHARED_SPI requires SPI_USE_MUTUAL_EXCLUSION"
  217. #endif
  218. #if LIS3MDL_USE_I2C && !HAL_USE_I2C
  219. #error "LIS3MDL_USE_I2C requires HAL_USE_I2C"
  220. #endif
  221. #if LIS3MDL_SHARED_I2C && !I2C_USE_MUTUAL_EXCLUSION
  222. #error "LIS3MDL_SHARED_I2C requires I2C_USE_MUTUAL_EXCLUSION"
  223. #endif
  224. /**
  225. * @todo Add support for LIS3MDL over SPI.
  226. */
  227. #if LIS3MDL_USE_SPI
  228. #error "LIS3MDL over SPI still not supported"
  229. #endif
  230. /*===========================================================================*/
  231. /* Driver data structures and types. */
  232. /*===========================================================================*/
  233. /**
  234. * @name LIS3MDL data structures and types
  235. * @{
  236. */
  237. /**
  238. * @brief LIS3MDL slave address
  239. */
  240. /**
  241. * @brief Structure representing a LIS3MDL driver.
  242. */
  243. typedef struct LIS3MDLDriver LIS3MDLDriver;
  244. /**
  245. * @brief LIS3MDL slave address
  246. */
  247. typedef enum {
  248. LIS3MDL_SAD_GND = 0x1C, /**< Slave Address when SA1 is to GND */
  249. LIS3MDL_SAD_VCC = 0x1E /**< Slave Address when SA1 is to VCC */
  250. }lis3mdl_sad_t;
  251. /**
  252. * @brief LIS3MDL full scale
  253. */
  254. typedef enum {
  255. LIS3MDL_COMP_FS_4GA = 0x00, /**< ±4 Gauss */
  256. LIS3MDL_COMP_FS_8GA = 0x20, /**< ±8 Gauss */
  257. LIS3MDL_COMP_FS_12GA = 0x40, /**< ±12 Gauss */
  258. LIS3MDL_COMP_FS_16GA = 0x60 /**< ±16 Gauss */
  259. }lis3mdl_comp_fs_t;
  260. /**
  261. * @brief LIS3MDL output data rate
  262. */
  263. typedef enum {
  264. LIS3MDL_COMP_ODR_0_625HZ = 0x00, /**< Output Data Rate = 0.625 Hz */
  265. LIS3MDL_COMP_ODR_1_25HZ = 0x04, /**< Output Data Rate = 1.25 Hz */
  266. LIS3MDL_COMP_ODR_2_5HZ = 0x08, /**< Output Data Rate = 2.5 Hz */
  267. LIS3MDL_COMP_ODR_5HZ = 0x0C, /**< Output Data Rate = 5 Hz */
  268. LIS3MDL_COMP_ODR_10HZ = 0x10, /**< Output Data Rate = 10 Hz */
  269. LIS3MDL_COMP_ODR_20HZ = 0x14, /**< Output Data Rate = 20 Hz */
  270. LIS3MDL_COMP_ODR_40HZ = 0x18, /**< Output Data Rate = 40 Hz */
  271. LIS3MDL_COMP_ODR_80HZ = 0x1C /**< Output Data Rate = 80 Hz */
  272. }lis3mdl_comp_odr_t;
  273. /**
  274. * @brief LIS3MDL low power mode configuration
  275. */
  276. typedef enum {
  277. LIS3MDL_COMP_LP_DISABLED = 0x00, /**< Low Power mode disabled */
  278. LIS3MDL_COMP_LP_ENABLED = 0x20 /**< Low Power mode enabled */
  279. }lis3mdl_comp_lp_t;
  280. /**
  281. * @brief LIS3MDL conversion mode
  282. */
  283. typedef enum {
  284. LIS3MDL_COMP_MD_CONTINUOUS = 0x00,/**< Continuous conversion mode */
  285. LIS3MDL_COMP_MD_SINGLE = 0x01, /**< Single conversion mode */
  286. LIS3MDL_COMP_MD_POWER_DOWN = 0x02 /**< Power down mode */
  287. }lis3mdl_comp_md_t;
  288. /**
  289. * @brief LIS3MDL operation mode for X and Y axes
  290. */
  291. typedef enum {
  292. LIS3MDL_COMP_OMXY_LP = 0x00, /**< X-Y axes low power mode */
  293. LIS3MDL_COMP_OMXY_MEDIUM = 0x20, /**< X-Y axes medium performance mode */
  294. LIS3MDL_COMP_OMXY_HIGH = 0x40, /**< X-Y axes high performance mode */
  295. LIS3MDL_COMP_OMXY_ULTRA = 0x60 /**< X-Y axes ultra performance mode */
  296. }lis3mdl_comp_omxy_t;
  297. /**
  298. * @brief LIS3MDL operation mode for Z axis
  299. */
  300. typedef enum {
  301. LIS3MDL_COMP_OMZ_LP = 0x00, /**< Z axis low power mode */
  302. LIS3MDL_COMP_OMZ_MEDIUM = 0x04, /**< Z axis medium performance mode */
  303. LIS3MDL_COMP_OMZ_HIGH = 0x08, /**< Z axis high performance mode */
  304. LIS3MDL_COMP_OMZ_ULTRA = 0x0C /**< Z axis ultra performance mode */
  305. }lis3mdl_comp_omz_t;
  306. /**
  307. * @brief LIS3MDL temperature sensor enabling
  308. */
  309. typedef enum {
  310. LIS3MDL_TEMP_DISABLED = 0x00, /**< Temperature sensor disabled. */
  311. LIS3MDL_TEMP_ENABLED = 0x80 /**< Temperature sensor enabled. */
  312. }lis3mdl_temp_t;
  313. /**
  314. * @brief LIS3MDL block data update
  315. */
  316. typedef enum {
  317. LIS3MDL_BDU_CONTINUOUS = 0x00, /**< Continuous Update */
  318. LIS3MDL_BDU_BLOCKED = 0x40 /**< Block data updated after reading. */
  319. }lis3mdl_bdu_t;
  320. /**
  321. * @brief LIS3MDL endianness
  322. */
  323. typedef enum {
  324. LIS3MDL_END_LITTLE = 0x00, /**< Little endian. */
  325. LIS3MDL_END_BIG = 0x02 /**< Big endian. */
  326. }lis3mdl_end_t;
  327. /**
  328. * @brief Driver state machine possible states.
  329. */
  330. typedef enum {
  331. LIS3MDL_UNINIT = 0, /**< Not initialized. */
  332. LIS3MDL_STOP = 1, /**< Stopped. */
  333. LIS3MDL_READY = 2, /**< Ready. */
  334. } lis3mdl_state_t;
  335. /**
  336. * @brief LIS3MDL configuration structure.
  337. */
  338. typedef struct {
  339. #if (LIS3MDL_USE_SPI) || defined(__DOXYGEN__)
  340. /**
  341. * @brief SPI driver associated to this LIS3MDL.
  342. */
  343. SPIDriver *spip;
  344. /**
  345. * @brief SPI configuration associated to this LIS3MDL.
  346. */
  347. const SPIConfig *spicfg;
  348. #endif /* LIS3MDL_USE_SPI */
  349. #if (LIS3MDL_USE_I2C) || defined(__DOXYGEN__)
  350. /**
  351. * @brief I2C driver associated to this LIS3MDL.
  352. */
  353. I2CDriver *i2cp;
  354. /**
  355. * @brief I2C configuration associated to this LIS3MDL.
  356. */
  357. const I2CConfig *i2ccfg;
  358. /**
  359. * @brief LIS3MDL slave address
  360. */
  361. lis3mdl_sad_t slaveaddress;
  362. #endif /* LIS3MDL_USE_I2C */
  363. /**
  364. * @brief LIS3MDL compass subsystem initial sensitivity.
  365. */
  366. float *compsensitivity;
  367. /**
  368. * @brief LIS3MDL compass subsystem initial bias.
  369. */
  370. float *compbias;
  371. /**
  372. * @brief LIS3MDL compass subsystem full scale.
  373. */
  374. lis3mdl_comp_fs_t compfullscale;
  375. /**
  376. * @brief LIS3MDL compass subsystem output data rate.
  377. */
  378. lis3mdl_comp_odr_t compoutputdatarate;
  379. #if LIS3MDL_USE_ADVANCED || defined(__DOXYGEN__)
  380. /**
  381. * @brief LIS3MDL compass subsystem low power mode configuration.
  382. */
  383. lis3mdl_comp_lp_t complowpowermode;
  384. /**
  385. * @brief LIS3MDL compass subsystem conversion mode.
  386. */
  387. lis3mdl_comp_md_t compconversionmode;
  388. /**
  389. * @brief LIS3MDL compass subsystem operation mode for X and Y axes.
  390. */
  391. lis3mdl_comp_omxy_t compoperationmodexy;
  392. /**
  393. * @brief LIS3MDL compass subsystem operation mode for Z axis.
  394. */
  395. lis3mdl_comp_omz_t compoperationmodez;
  396. /**
  397. * @brief LIS3MDL block data update.
  398. */
  399. lis3mdl_bdu_t blockdataupdate;
  400. /**
  401. * @brief LIS3MDL endianness.
  402. */
  403. lis3mdl_end_t endianness;
  404. #endif
  405. } LIS3MDLConfig;
  406. /**
  407. * @brief @p LIS3MDL specific methods.
  408. */
  409. #define _lis3msl_methods_alone \
  410. /* Change full scale value of LIS3MDL compass subsystem.*/ \
  411. msg_t (*comp_set_full_scale)(LIS3MDLDriver *devp, lis3mdl_comp_fs_t fs);
  412. /**
  413. * @brief @p LIS3MDL specific methods with inherited ones.
  414. */
  415. #define _lis3mdl_methods \
  416. _base_object_methods \
  417. _lis3msl_methods_alone
  418. /**
  419. * @extends BaseCompassVMT
  420. *
  421. * @brief @p LIS3MDL virtual methods table.
  422. */
  423. struct LIS3MDLVMT {
  424. _lis3mdl_methods
  425. };
  426. /**
  427. * @brief @p LIS3MDLDriver specific data.
  428. */
  429. #define _lis3mdl_data \
  430. _base_compass_data \
  431. /* Driver state.*/ \
  432. lis3mdl_state_t state; \
  433. /* Current configuration data.*/ \
  434. const LIS3MDLConfig *config; \
  435. /* Compass subsystem axes number.*/ \
  436. size_t compaxes; \
  437. /* Compass subsystem current sensitivity.*/ \
  438. float compsensitivity[LIS3MDL_COMP_NUMBER_OF_AXES]; \
  439. /* Compass subsystem current bias.*/ \
  440. float compbias[LIS3MDL_COMP_NUMBER_OF_AXES]; \
  441. /* Compass subsystem current full scale value.*/ \
  442. float compfullscale;
  443. /**
  444. * @brief LIS3MDL 3-axis compass class.
  445. */
  446. struct LIS3MDLDriver {
  447. /** @brief Virtual Methods Table.*/
  448. const struct LIS3MDLVMT *vmt;
  449. /** @brief Base compass interface.*/
  450. BaseCompass comp_if;
  451. _lis3mdl_data
  452. };
  453. /** @} */
  454. /*===========================================================================*/
  455. /* Driver macros. */
  456. /*===========================================================================*/
  457. /**
  458. * @brief Return the number of axes of the BaseCompass.
  459. *
  460. * @param[in] devp pointer to @p LIS3MDLDriver.
  461. *
  462. * @return the number of axes.
  463. *
  464. * @api
  465. */
  466. #define lis3mdlCompassGetAxesNumber(devp) \
  467. compassGetAxesNumber(&((devp)->comp_if))
  468. /**
  469. * @brief Retrieves raw data from the BaseCompass.
  470. * @note This data is retrieved from MEMS register without any algebraical
  471. * manipulation.
  472. * @note The axes array must be at least the same size of the
  473. * BaseCompass axes number.
  474. *
  475. * @param[in] devp pointer to @p BaseCompass interface.
  476. * @param[out] axes a buffer which would be filled with raw data.
  477. *
  478. * @return The operation status.
  479. * @retval MSG_OK if the function succeeded.
  480. * @retval MSG_RESET if one or more I2C errors occurred, the errors can
  481. * be retrieved using @p i2cGetErrors().
  482. * @retval MSG_TIMEOUT if a timeout occurred before operation end.
  483. *
  484. * @api
  485. */
  486. #define lis3mdlCompassReadRaw(devp, axes) \
  487. compassReadRaw(&((devp)->comp_if), axes)
  488. /**
  489. * @brief Retrieves cooked data from the BaseCompass.
  490. * @note This data is manipulated according to the formula
  491. * cooked = (raw * sensitivity) - bias.
  492. * @note Final data is expressed as G.
  493. * @note The axes array must be at least the same size of the
  494. * BaseCompass axes number.
  495. *
  496. * @param[in] devp pointer to @p BaseCompass interface.
  497. * @param[out] axes a buffer which would be filled with cooked data.
  498. *
  499. * @return The operation status.
  500. * @retval MSG_OK if the function succeeded.
  501. * @retval MSG_RESET if one or more I2C errors occurred, the errors can
  502. * be retrieved using @p i2cGetErrors().
  503. * @retval MSG_TIMEOUT if a timeout occurred before operation end.
  504. *
  505. * @api
  506. */
  507. #define lis3mdlCompassReadCooked(devp, axes) \
  508. compassReadCooked(&((devp)->comp_if), axes)
  509. /**
  510. * @brief Set bias values for the BaseCompass.
  511. * @note Bias must be expressed as G.
  512. * @note The bias buffer must be at least the same size of the
  513. * BaseCompass axes number.
  514. *
  515. * @param[in] devp pointer to @p BaseCompass interface.
  516. * @param[in] bp a buffer which contains biases.
  517. *
  518. * @return The operation status.
  519. * @retval MSG_OK if the function succeeded.
  520. *
  521. * @api
  522. */
  523. #define lis3mdlCompassSetBias(devp, bp) \
  524. compassSetBias(&((devp)->comp_if), bp)
  525. /**
  526. * @brief Reset bias values for the BaseCompass.
  527. * @note Default biases value are obtained from device datasheet when
  528. * available otherwise they are considered zero.
  529. *
  530. * @param[in] devp pointer to @p LIS3MDLDriver.
  531. *
  532. * @return The operation status.
  533. * @retval MSG_OK if the function succeeded.
  534. *
  535. * @api
  536. */
  537. #define lis3mdlCompassResetBias(devp) \
  538. compassResetBias(&((devp)->comp_if))
  539. /**
  540. * @brief Set sensitivity values for the BaseCompass.
  541. * @note Sensitivity must be expressed as G/LSB.
  542. * @note The sensitivity buffer must be at least the same size of the
  543. * BaseCompass axes number.
  544. *
  545. * @param[in] devp pointer to @p LIS3MDLDriver.
  546. * @param[in] sp a buffer which contains sensitivities.
  547. *
  548. * @return The operation status.
  549. * @retval MSG_OK if the function succeeded.
  550. *
  551. * @api
  552. */
  553. #define lis3mdlCompassSetSensitivity(devp, sp) \
  554. compassSetSensitivity(&((devp)->comp_if), sp)
  555. /**
  556. * @brief Reset sensitivity values for the BaseCompass.
  557. * @note Default sensitivities value are obtained from device datasheet.
  558. *
  559. * @param[in] devp pointer to @p LIS3MDLDriver.
  560. *
  561. * @return The operation status.
  562. * @retval MSG_OK if the function succeeded.
  563. * @retval MSG_RESET otherwise.
  564. *
  565. * @api
  566. */
  567. #define lis3mdlCompassResetSensitivity(devp) \
  568. compassResetSensitivity(&((devp)->comp_if))
  569. /**
  570. * @brief Changes the LIS3MDLDriver compass fullscale value.
  571. * @note This function also rescale sensitivities and biases based on
  572. * previous and next fullscale value.
  573. * @note A recalibration is highly suggested after calling this function.
  574. *
  575. * @param[in] devp pointer to @p LIS3MDLDriver.
  576. * @param[in] fs new fullscale value.
  577. *
  578. * @return The operation status.
  579. * @retval MSG_OK if the function succeeded.
  580. * @retval MSG_RESET otherwise.
  581. *
  582. * @api
  583. */
  584. #define lis3mdlCompassSetFullScale(devp, fs) \
  585. (devp)->vmt->comp_set_full_scale(devp, fs)
  586. /*===========================================================================*/
  587. /* External declarations. */
  588. /*===========================================================================*/
  589. #ifdef __cplusplus
  590. extern "C" {
  591. #endif
  592. void lis3mdlObjectInit(LIS3MDLDriver *devp);
  593. void lis3mdlStart(LIS3MDLDriver *devp, const LIS3MDLConfig *config);
  594. void lis3mdlStop(LIS3MDLDriver *devp);
  595. #ifdef __cplusplus
  596. }
  597. #endif
  598. #endif /* _LIS3MDL_H_ */
  599. /** @} */