aboutsummaryrefslogtreecommitdiffstats
path: root/os/ex/ST/lsm303dlhc.h
diff options
context:
space:
mode:
Diffstat (limited to 'os/ex/ST/lsm303dlhc.h')
-rw-r--r--os/ex/ST/lsm303dlhc.h405
1 files changed, 327 insertions, 78 deletions
diff --git a/os/ex/ST/lsm303dlhc.h b/os/ex/ST/lsm303dlhc.h
index 36f0a74c4..e58fd7a39 100644
--- a/os/ex/ST/lsm303dlhc.h
+++ b/os/ex/ST/lsm303dlhc.h
@@ -429,47 +429,6 @@ typedef enum {
} lsm303dlhc_acc_end_t;
/**
- * @brief LSM303DLHC accelerometer subsystem configuration structure.
- */
-typedef struct {
- /**
- * @brief LSM303DLHC initial sensitivity.
- */
- float *sensitivity;
- /**
- * @brief LSM303DLHC initial bias.
- */
- float *bias;
- /**
- * @brief LSM303DLHC accelerometer subsystem initial full scale.
- */
- lsm303dlhc_acc_fs_t fullscale;
- /**
- * @brief LSM303DLHC accelerometer subsystem output data rate.
- */
- lsm303dlhc_acc_odr_t outdatarate;
-#if LSM303DLHC_ACC_USE_ADVANCED || defined(__DOXYGEN__)
- /**
- * @brief LSM303DLHC accelerometer subsystem low power mode.
- */
- lsm303dlhc_acc_lp_t lowpower;
- /**
- * @brief LSM303DLHC accelerometer subsystem high resolution mode.
- */
- lsm303dlhc_acc_hr_t highresmode;
- /**
- * @brief LSM303DLHC accelerometer subsystem block data update.
- */
- lsm303dlhc_acc_bdu_t blockdataupdate;
- /**
- * @brief LSM303DLHC accelerometer endianness.
- */
- lsm303dlhc_acc_end_t endianess;
-#endif
-} LSM303DLHCAccConfig;
-/** @} */
-
-/**
* @name LSM303DLHC compass subsystem data structures and types.
* @{
*/
@@ -510,39 +469,9 @@ typedef enum {
} lsm303dlhc_comp_md_t;
/**
- * @brief LSM303DLHC compass subsystem configuration structure.
- */
-typedef struct {
- /**
- * @brief LSM303DLHC compass initial sensitivity.
- */
- float *sensitivity;
- /**
- * @brief LSM303DLHC compass initial bias.
- */
- float *bias;
- /**
- * @brief LSM303DLHC compass subsystem initial full scale.
- */
- lsm303dlhc_comp_fs_t fullscale;
- /**
- * @brief LSM303DLHC compass subsystem output data rate.
- */
- lsm303dlhc_comp_odr_t outputdatarate;
-#if LSM303DLHC_COMP_USE_ADVANCED || defined(__DOXYGEN__)
- /**
- * @brief LSM303DLHC compass subsystem working mode.
- */
- lsm303dlhc_comp_md_t mode;
-#endif
-} LSM303DLHCCompConfig;
-/** @} */
-
-/**
* @name LSM303DLHC main system data structures and types.
* @{
*/
-
/**
* @brief Driver state machine possible states.
*/
@@ -566,13 +495,61 @@ typedef struct {
*/
const I2CConfig *i2ccfg;
/**
- * @brief LSM303DLHC accelerometer subsystem configuration structure
+ * @brief LSM303DLHC initial sensitivity.
+ */
+ float *accsensitivity;
+ /**
+ * @brief LSM303DLHC initial bias.
+ */
+ float *accbias;
+ /**
+ * @brief LSM303DLHC accelerometer subsystem initial full scale.
+ */
+ lsm303dlhc_acc_fs_t accfullscale;
+ /**
+ * @brief LSM303DLHC accelerometer subsystem output data rate.
+ */
+ lsm303dlhc_acc_odr_t accoutdatarate;
+#if LSM303DLHC_ACC_USE_ADVANCED || defined(__DOXYGEN__)
+ /**
+ * @brief LSM303DLHC accelerometer subsystem low power mode.
*/
- const LSM303DLHCAccConfig *acccfg;
+ lsm303dlhc_acc_lp_t acclowpower;
/**
- * @brief LSM303DLHC compass subsystem configuration structure
+ * @brief LSM303DLHC accelerometer subsystem high resolution mode.
*/
- const LSM303DLHCCompConfig *compcfg;
+ lsm303dlhc_acc_hr_t acchighresmode;
+ /**
+ * @brief LSM303DLHC accelerometer subsystem block data update.
+ */
+ lsm303dlhc_acc_bdu_t accblockdataupdate;
+ /**
+ * @brief LSM303DLHC accelerometer endianness.
+ */
+ lsm303dlhc_acc_end_t accendianess;
+#endif
+ /**
+ * @brief LSM303DLHC compass initial sensitivity.
+ */
+ float *compsensitivity;
+ /**
+ * @brief LSM303DLHC compass initial bias.
+ */
+ float *compbias;
+ /**
+ * @brief LSM303DLHC compass subsystem initial full scale.
+ */
+ lsm303dlhc_comp_fs_t compfullscale;
+ /**
+ * @brief LSM303DLHC compass subsystem output data rate.
+ */
+ lsm303dlhc_comp_odr_t compoutputdatarate;
+#if LSM303DLHC_COMP_USE_ADVANCED || defined(__DOXYGEN__)
+ /**
+ * @brief LSM303DLHC compass subsystem working mode.
+ */
+ lsm303dlhc_comp_md_t compmode;
+#endif
} LSM303DLHCConfig;
/**
@@ -635,9 +612,9 @@ struct LSM303DLHCDriver {
/** @brief Virtual Methods Table.*/
const struct LSM303DLHCVMT *vmt;
/** @brief Accelerometer interface.*/
- BaseAccelerometer accelerometer_if;
+ BaseAccelerometer acc_if;
/** @brief Compass interface.*/
- BaseCompass compass_if;
+ BaseCompass comp_if;
_lsm303dlhc_data
};
/** @} */
@@ -645,7 +622,279 @@ struct LSM303DLHCDriver {
/*===========================================================================*/
/* Driver macros. */
/*===========================================================================*/
-
+/**
+ * @brief Return the number of axes of the BaseAccelerometer.
+ *
+ * @param[in] ip pointer to @p BaseAccelerometer interface
+ *
+ * @return the number of axes.
+ *
+ * @api
+ */
+#define lsm303dlhcAccelerometerGetAxesNumber(devp) \
+ accelerometerGetAxesNumber(&((devp)->acc_if))
+
+/**
+ * @brief Retrieves raw data from the BaseAccelerometer.
+ * @note This data is retrieved from MEMS register without any algebrical
+ * manipulation.
+ * @note The axes array must be at least the same size of the
+ * BaseAccelerometer axes number.
+ *
+ * @param[in] ip pointer to @p BaseAccelerometer interface.
+ * @param[out] axes a buffer which would be filled with raw data.
+ *
+ * @return The operation status.
+ * @retval MSG_OK if the function succeeded.
+ * @retval MSG_RESET if one or more I2C errors occurred, the errors can
+ * be retrieved using @p i2cGetErrors().
+ * @retval MSG_TIMEOUT if a timeout occurred before operation end.
+ *
+ * @api
+ */
+#define lsm303dlhcAccelerometerReadRaw(devp, axes) \
+ accelerometerReadRaw(&((devp)->acc_if), axes)
+
+/**
+ * @brief Retrieves cooked data from the BaseAccelerometer.
+ * @note This data is manipulated according to the formula
+ * cooked = (raw * sensitivity) - bias.
+ * @note Final data is expressed as milli-G.
+ * @note The axes array must be at least the same size of the
+ * BaseAccelerometer axes number.
+ *
+ * @param[in] ip pointer to @p BaseAccelerometer interface.
+ * @param[out] axes a buffer which would be filled with cooked data.
+ *
+ * @return The operation status.
+ * @retval MSG_OK if the function succeeded.
+ * @retval MSG_RESET if one or more I2C errors occurred, the errors can
+ * be retrieved using @p i2cGetErrors().
+ * @retval MSG_TIMEOUT if a timeout occurred before operation end.
+ *
+ * @api
+ */
+#define lsm303dlhcAccelerometerReadCooked(devp, axes) \
+ accelerometerReadCooked(&((devp)->acc_if), axes)
+
+/**
+ * @brief Set bias values for the BaseAccelerometer.
+ * @note Bias must be expressed as milli-G.
+ * @note The bias buffer must be at least the same size of the
+ * BaseAccelerometer axes number.
+ *
+ * @param[in] ip pointer to @p BaseAccelerometer interface.
+ * @param[in] bp a buffer which contains biases.
+ *
+ * @return The operation status.
+ * @retval MSG_OK if the function succeeded.
+ *
+ * @api
+ */
+#define lsm303dlhcAccelerometerSetBias(devp, bp) \
+ accelerometerSetBias(&((devp)->acc_if), bp)
+
+/**
+ * @brief Reset bias values for the BaseAccelerometer.
+ * @note Default biases value are obtained from device datasheet when
+ * available otherwise they are considered zero.
+ *
+ * @param[in] ip pointer to @p BaseAccelerometer interface.
+ *
+ * @return The operation status.
+ * @retval MSG_OK if the function succeeded.
+ *
+ * @api
+ */
+#define lsm303dlhcAccelerometerResetBias(devp) \
+ accelerometerResetBias(&((devp)->acc_if))
+
+/**
+ * @brief Set sensitivity values for the BaseAccelerometer.
+ * @note Sensitivity must be expressed as milli-G/LSB.
+ * @note The sensitivity buffer must be at least the same size of the
+ * BaseAccelerometer axes number.
+ *
+ * @param[in] ip pointer to @p BaseAccelerometer interface.
+ * @param[in] sp a buffer which contains sensitivities.
+ *
+ * @return The operation status.
+ * @retval MSG_OK if the function succeeded.
+ *
+ * @api
+ */
+#define lsm303dlhcAccelerometerSetSensitivity(devp, sp) \
+ accelerometerSetSensitivity(&((devp)->acc_if), sp)
+
+/**
+ * @brief Reset sensitivity values for the BaseAccelerometer.
+ * @note Default sensitivities value are obtained from device datasheet.
+ *
+ * @param[in] ip pointer to @p BaseAccelerometer interface.
+ *
+ * @return The operation status.
+ * @retval MSG_OK if the function succeeded.
+ * @retval MSG_RESET otherwise.
+ *
+ * @api
+ */
+#define lsm303dlhcAccelerometerResetSensitivity(devp) \
+ accelerometerResetSensitivity(&((devp)->acc_if))
+
+/**
+ * @brief Changes the LSM303DLHCDriver accelerometer fullscale value.
+ * @note This function also rescale sensitivities and biases based on
+ * previous and next fullscale value.
+ * @note A recalibration is highly suggested after calling this function.
+ *
+ * @param[in] ip pointer to @p LSM303DLHCDriver interface.
+ * @param[in] fs new fullscale value.
+ *
+ * @return The operation status.
+ * @retval MSG_OK if the function succeeded.
+ * @retval MSG_RESET otherwise.
+ *
+ * @api
+ */
+#define lsm303dlhcAccelerometerSetFullScale(devp, fs) \
+ (devp)->vmt->acc_set_full_scale(devp, fs)
+
+/**
+ * @brief Return the number of axes of the BaseCompass.
+ *
+ * @param[in] ip pointer to @p BaseCompass interface
+ *
+ * @return the number of axes.
+ *
+ * @api
+ */
+#define lsm303dlhcCompassGetAxesNumber(devp) \
+ compassGetAxesNumber(&((devp)->comp_if))
+
+/**
+ * @brief Retrieves raw data from the BaseCompass.
+ * @note This data is retrieved from MEMS register without any algebrical
+ * manipulation.
+ * @note The axes array must be at least the same size of the
+ * BaseCompass axes number.
+ *
+ * @param[in] ip pointer to @p BaseCompass interface.
+ * @param[out] axes a buffer which would be filled with raw data.
+ *
+ * @return The operation status.
+ * @retval MSG_OK if the function succeeded.
+ * @retval MSG_RESET if one or more I2C errors occurred, the errors can
+ * be retrieved using @p i2cGetErrors().
+ * @retval MSG_TIMEOUT if a timeout occurred before operation end.
+ *
+ * @api
+ */
+#define lsm303dlhcCompassReadRaw(devp, axes) \
+ compassReadRaw(&((devp)->comp_if), axes)
+
+/**
+ * @brief Retrieves cooked data from the BaseCompass.
+ * @note This data is manipulated according to the formula
+ * cooked = (raw * sensitivity) - bias.
+ * @note Final data is expressed as Ga.
+ * @note The axes array must be at least the same size of the
+ * BaseCompass axes number.
+ *
+ * @param[in] ip pointer to @p BaseCompass interface.
+ * @param[out] axes a buffer which would be filled with cooked data.
+ *
+ * @return The operation status.
+ * @retval MSG_OK if the function succeeded.
+ * @retval MSG_RESET if one or more I2C errors occurred, the errors can
+ * be retrieved using @p i2cGetErrors().
+ * @retval MSG_TIMEOUT if a timeout occurred before operation end.
+ *
+ * @api
+ */
+#define lsm303dlhcCompassReadCooked(devp, axes) \
+ compassReadCooked(&((devp)->comp_if), axes)
+
+/**
+ * @brief Set bias values for the BaseCompass.
+ * @note Bias must be expressed as Ga.
+ * @note The bias buffer must be at least the same size of the
+ * BaseCompass axes number.
+ *
+ * @param[in] ip pointer to @p BaseCompass interface.
+ * @param[in] bp a buffer which contains biases.
+ *
+ * @return The operation status.
+ * @retval MSG_OK if the function succeeded.
+ *
+ * @api
+ */
+#define lsm303dlhcCompassSetBias(devp, bp) \
+ compassSetBias(&((devp)->comp_if), bp)
+
+/**
+ * @brief Reset bias values for the BaseCompass.
+ * @note Default biases value are obtained from device datasheet when
+ * available otherwise they are considered zero.
+ *
+ * @param[in] ip pointer to @p BaseCompass interface.
+ *
+ * @return The operation status.
+ * @retval MSG_OK if the function succeeded.
+ *
+ * @api
+ */
+#define lsm303dlhcCompassResetBias(devp) \
+ compassResetBias(&((devp)->comp_if))
+
+/**
+ * @brief Set sensitivity values for the BaseCompass.
+ * @note Sensitivity must be expressed as Ga/LSB.
+ * @note The sensitivity buffer must be at least the same size of the
+ * BaseCompass axes number.
+ *
+ * @param[in] ip pointer to @p BaseCompass interface.
+ * @param[in] sp a buffer which contains sensitivities.
+ *
+ * @return The operation status.
+ * @retval MSG_OK if the function succeeded.
+ *
+ * @api
+ */
+#define lsm303dlhcCompassSetSensitivity(devp, sp) \
+ compassSetSensitivity(&((devp)->comp_if), sp)
+
+/**
+ * @brief Reset sensitivity values for the BaseCompass.
+ * @note Default sensitivities value are obtained from device datasheet.
+ *
+ * @param[in] ip pointer to @p BaseCompass interface.
+ *
+ * @return The operation status.
+ * @retval MSG_OK if the function succeeded.
+ * @retval MSG_RESET otherwise.
+ *
+ * @api
+ */
+#define lsm303dlhcCompassResetSensitivity(devp) \
+ compassResetSensitivity(&((devp)->comp_if))
+
+/**
+ * @brief Changes the LSM303DLHCDriver compass fullscale value.
+ * @note This function also rescale sensitivities and biases based on
+ * previous and next fullscale value.
+ * @note A recalibration is highly suggested after calling this function.
+ *
+ * @param[in] ip pointer to @p LSM303DLHCDriver interface.
+ * @param[in] fs new fullscale value.
+ *
+ * @return The operation status.
+ * @retval MSG_OK if the function succeeded.
+ * @retval MSG_RESET otherwise.
+ *
+ * @api
+ */
+#define lsm303dlhcCompassSetFullScale(devp, fs) \
+ (devp)->vmt->comp_set_full_scale(devp, fs)
/*===========================================================================*/
/* External declarations. */
/*===========================================================================*/