Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: X_NUCLEO_COMMON ST_INTERFACES
Dependents: X_NUCLEO_IKS01A3 X_NUCLEO_IKS01A3
Revision 1:8562ae1a0534, committed 2019-07-24
- Comitter:
- cparata
- Date:
- Wed Jul 24 14:18:39 2019 +0000
- Parent:
- 0:671edf39d961
- Commit message:
- Format with Astyle
Changed in this revision
diff -r 671edf39d961 -r 8562ae1a0534 LIS2MDLSensor.cpp
--- a/LIS2MDLSensor.cpp Tue Mar 05 18:06:37 2019 +0000
+++ b/LIS2MDLSensor.cpp Wed Jul 24 14:18:39 2019 +0000
@@ -51,28 +51,26 @@
*/
LIS2MDLSensor::LIS2MDLSensor(SPI *spi, PinName cs_pin, PinName int_pin, SPI_type_t spi_type) : _dev_spi(spi), _cs_pin(cs_pin), _int_irq(int_pin), _spi_type(spi_type)
{
- assert (spi);
- if (cs_pin == NC)
- {
- printf ("ERROR LIS2MDL CS MUST NOT BE NC\n\r");
- _dev_spi = NULL;
- _dev_i2c = NULL;
- return;
- }
+ assert(spi);
+ if (cs_pin == NC) {
+ printf("ERROR LIS2MDL CS MUST NOT BE NC\n\r");
+ _dev_spi = NULL;
+ _dev_i2c = NULL;
+ return;
+ }
- _reg_ctx.write_reg = LIS2MDL_io_write;
- _reg_ctx.read_reg = LIS2MDL_io_read;
- _reg_ctx.handle = (void *)this;
- _cs_pin = 1;
- _dev_i2c = NULL;
- _address = 0;
-
- if (_spi_type == SPI4W)
- {
- /* Enable SPI 4-Wires on the component (in this way we lose the usage of INT pin) */
- uint8_t data = 0x34;
- lis2mdl_write_reg(&_reg_ctx, LIS2MDL_CFG_REG_C, &data, 1);
- }
+ _reg_ctx.write_reg = LIS2MDL_io_write;
+ _reg_ctx.read_reg = LIS2MDL_io_read;
+ _reg_ctx.handle = (void *)this;
+ _cs_pin = 1;
+ _dev_i2c = NULL;
+ _address = 0;
+
+ if (_spi_type == SPI4W) {
+ /* Enable SPI 4-Wires on the component (in this way we lose the usage of INT pin) */
+ uint8_t data = 0x34;
+ lis2mdl_write_reg(&_reg_ctx, LIS2MDL_CFG_REG_C, &data, 1);
+ }
}
/** Constructor
@@ -82,11 +80,11 @@
*/
LIS2MDLSensor::LIS2MDLSensor(DevI2C *i2c, uint8_t address, PinName int_pin) : _dev_i2c(i2c), _address(address), _cs_pin(NC), _int_irq(int_pin)
{
- assert (i2c);
- _dev_spi = NULL;
- _reg_ctx.write_reg = LIS2MDL_io_write;
- _reg_ctx.read_reg = LIS2MDL_io_read;
- _reg_ctx.handle = (void *)this;
+ assert(i2c);
+ _dev_spi = NULL;
+ _reg_ctx.write_reg = LIS2MDL_io_write;
+ _reg_ctx.read_reg = LIS2MDL_io_read;
+ _reg_ctx.handle = (void *)this;
}
/**
@@ -96,33 +94,29 @@
*/
int LIS2MDLSensor::init(void *init)
{
- /* Enable BDU */
- if (lis2mdl_block_data_update_set(&(_reg_ctx), PROPERTY_ENABLE) != 0)
- {
- return 1;
- }
+ /* Enable BDU */
+ if (lis2mdl_block_data_update_set(&(_reg_ctx), PROPERTY_ENABLE) != 0) {
+ return 1;
+ }
- /* Operating mode selection - power down */
- if (lis2mdl_operating_mode_set(&(_reg_ctx), LIS2MDL_POWER_DOWN) != 0)
- {
- return 1;
- }
+ /* Operating mode selection - power down */
+ if (lis2mdl_operating_mode_set(&(_reg_ctx), LIS2MDL_POWER_DOWN) != 0) {
+ return 1;
+ }
- /* Output data rate selection */
- if (lis2mdl_data_rate_set(&(_reg_ctx), LIS2MDL_ODR_100Hz) != 0)
- {
- return 1;
- }
+ /* Output data rate selection */
+ if (lis2mdl_data_rate_set(&(_reg_ctx), LIS2MDL_ODR_100Hz) != 0) {
+ return 1;
+ }
- /* Self Test disabled. */
- if (lis2mdl_self_test_set(&(_reg_ctx), PROPERTY_DISABLE) != 0)
- {
- return 1;
- }
+ /* Self Test disabled. */
+ if (lis2mdl_self_test_set(&(_reg_ctx), PROPERTY_DISABLE) != 0) {
+ return 1;
+ }
- _mag_is_enabled = 0;
+ _mag_is_enabled = 0;
- return 0;
+ return 0;
}
/**
@@ -132,12 +126,11 @@
*/
int LIS2MDLSensor::read_id(uint8_t *id)
{
- if (lis2mdl_device_id_get(&_reg_ctx, id) != 0)
- {
- return 1;
- }
+ if (lis2mdl_device_id_get(&_reg_ctx, id) != 0) {
+ return 1;
+ }
- return 0;
+ return 0;
}
@@ -147,21 +140,19 @@
*/
int LIS2MDLSensor::enable()
{
- /* Check if the component is already enabled */
- if (_mag_is_enabled == 1U)
- {
- return 0;
- }
+ /* Check if the component is already enabled */
+ if (_mag_is_enabled == 1U) {
+ return 0;
+ }
- /* Output data rate selection. */
- if (lis2mdl_operating_mode_set(&_reg_ctx, LIS2MDL_CONTINUOUS_MODE) != 0)
- {
- return 1;
- }
+ /* Output data rate selection. */
+ if (lis2mdl_operating_mode_set(&_reg_ctx, LIS2MDL_CONTINUOUS_MODE) != 0) {
+ return 1;
+ }
- _mag_is_enabled = 1;
+ _mag_is_enabled = 1;
- return 0;
+ return 0;
}
/**
@@ -170,21 +161,19 @@
*/
int LIS2MDLSensor::disable()
{
- /* Check if the component is already disabled */
- if (_mag_is_enabled == 0U)
- {
- return 0;
- }
+ /* Check if the component is already disabled */
+ if (_mag_is_enabled == 0U) {
+ return 0;
+ }
- /* Output data rate selection - power down. */
- if (lis2mdl_operating_mode_set(&_reg_ctx, LIS2MDL_POWER_DOWN) != 0)
- {
- return 1;
- }
+ /* Output data rate selection - power down. */
+ if (lis2mdl_operating_mode_set(&_reg_ctx, LIS2MDL_POWER_DOWN) != 0) {
+ return 1;
+ }
- _mag_is_enabled = 0;
+ _mag_is_enabled = 0;
- return 0;
+ return 0;
}
/**
@@ -194,9 +183,9 @@
*/
int LIS2MDLSensor::get_m_sensitivity(float *sensitivity)
{
- *sensitivity = LIS2MDL_MAG_SENSITIVITY_FS_50GAUSS;
+ *sensitivity = LIS2MDL_MAG_SENSITIVITY_FS_50GAUSS;
- return 0;
+ return 0;
}
/**
@@ -206,39 +195,37 @@
*/
int LIS2MDLSensor::get_m_odr(float *odr)
{
- int ret = 0;
- lis2mdl_odr_t odr_low_level;
+ int ret = 0;
+ lis2mdl_odr_t odr_low_level;
- /* Get current output data rate. */
- if (lis2mdl_data_rate_get(&_reg_ctx, &odr_low_level) != 0)
- {
- return 1;
- }
+ /* Get current output data rate. */
+ if (lis2mdl_data_rate_get(&_reg_ctx, &odr_low_level) != 0) {
+ return 1;
+ }
- switch (odr_low_level)
- {
- case LIS2MDL_ODR_10Hz:
- *odr = 10.0f;
- break;
+ switch (odr_low_level) {
+ case LIS2MDL_ODR_10Hz:
+ *odr = 10.0f;
+ break;
- case LIS2MDL_ODR_20Hz:
- *odr = 20.0f;
- break;
+ case LIS2MDL_ODR_20Hz:
+ *odr = 20.0f;
+ break;
- case LIS2MDL_ODR_50Hz:
- *odr = 50.0f;
- break;
+ case LIS2MDL_ODR_50Hz:
+ *odr = 50.0f;
+ break;
- case LIS2MDL_ODR_100Hz:
- *odr = 100.0f;
- break;
+ case LIS2MDL_ODR_100Hz:
+ *odr = 100.0f;
+ break;
- default:
- ret = 1;
- break;
- }
+ default:
+ ret = 1;
+ break;
+ }
- return ret;
+ return ret;
}
/**
@@ -248,19 +235,18 @@
*/
int LIS2MDLSensor::set_m_odr(float odr)
{
- lis2mdl_odr_t new_odr;
-
- new_odr = (odr <= 10.000f) ? LIS2MDL_ODR_10Hz
- : (odr <= 20.000f) ? LIS2MDL_ODR_20Hz
- : (odr <= 50.000f) ? LIS2MDL_ODR_50Hz
- : LIS2MDL_ODR_100Hz;
+ lis2mdl_odr_t new_odr;
- if (lis2mdl_data_rate_set(&_reg_ctx, new_odr) != 0)
- {
- return 1;
- }
+ new_odr = (odr <= 10.000f) ? LIS2MDL_ODR_10Hz
+ : (odr <= 20.000f) ? LIS2MDL_ODR_20Hz
+ : (odr <= 50.000f) ? LIS2MDL_ODR_50Hz
+ : LIS2MDL_ODR_100Hz;
- return 0;
+ if (lis2mdl_data_rate_set(&_reg_ctx, new_odr) != 0) {
+ return 1;
+ }
+
+ return 0;
}
/**
@@ -270,9 +256,9 @@
*/
int LIS2MDLSensor::get_m_fs(float *full_scale)
{
- *full_scale = 50.0f;
+ *full_scale = 50.0f;
- return 0;
+ return 0;
}
/**
@@ -282,8 +268,8 @@
*/
int LIS2MDLSensor::set_m_fs(float full_scale)
{
- (void)full_scale;
- return 0;
+ (void)full_scale;
+ return 0;
}
/**
@@ -293,27 +279,25 @@
*/
int LIS2MDLSensor::get_m_axes(int32_t *magnetic_field)
{
- axis3bit16_t data_raw;
- float sensitivity;
+ axis3bit16_t data_raw;
+ float sensitivity;
- /* Read raw data values. */
- if (lis2mdl_magnetic_raw_get(&_reg_ctx, data_raw.u8bit) != 0)
- {
- return 1;
- }
+ /* Read raw data values. */
+ if (lis2mdl_magnetic_raw_get(&_reg_ctx, data_raw.u8bit) != 0) {
+ return 1;
+ }
- /* Get LIS2MDL actual sensitivity. */
- if (get_m_sensitivity(&sensitivity) != 0)
- {
- return 1;
- }
+ /* Get LIS2MDL actual sensitivity. */
+ if (get_m_sensitivity(&sensitivity) != 0) {
+ return 1;
+ }
- /* Calculate the data. */
- magnetic_field[0] = (int32_t)((float)((float)data_raw.i16bit[0] * sensitivity));
- magnetic_field[1] = (int32_t)((float)((float)data_raw.i16bit[1] * sensitivity));
- magnetic_field[2] = (int32_t)((float)((float)data_raw.i16bit[2] * sensitivity));
+ /* Calculate the data. */
+ magnetic_field[0] = (int32_t)((float)((float)data_raw.i16bit[0] * sensitivity));
+ magnetic_field[1] = (int32_t)((float)((float)data_raw.i16bit[1] * sensitivity));
+ magnetic_field[2] = (int32_t)((float)((float)data_raw.i16bit[2] * sensitivity));
- return 0;
+ return 0;
}
/**
@@ -323,20 +307,19 @@
*/
int LIS2MDLSensor::get_m_axes_raw(int16_t *value)
{
- axis3bit16_t data_raw;
+ axis3bit16_t data_raw;
+
+ /* Read raw data values. */
+ if (lis2mdl_magnetic_raw_get(&_reg_ctx, data_raw.u8bit) != 0) {
+ return 1;
+ }
- /* Read raw data values. */
- if (lis2mdl_magnetic_raw_get(&_reg_ctx, data_raw.u8bit) != 0)
- {
- return 1;
- }
+ /* Format the data. */
+ value[0] = data_raw.i16bit[0];
+ value[1] = data_raw.i16bit[1];
+ value[2] = data_raw.i16bit[2];
- /* Format the data. */
- value[0] = data_raw.i16bit[0];
- value[1] = data_raw.i16bit[1];
- value[2] = data_raw.i16bit[2];
-
- return 0;
+ return 0;
}
/**
@@ -347,12 +330,11 @@
*/
int LIS2MDLSensor::read_reg(uint8_t reg, uint8_t *data)
{
- if (lis2mdl_read_reg(&_reg_ctx, reg, data, 1) != 0)
- {
- return 1;
- }
+ if (lis2mdl_read_reg(&_reg_ctx, reg, data, 1) != 0) {
+ return 1;
+ }
- return 0;
+ return 0;
}
/**
@@ -364,12 +346,11 @@
*/
int LIS2MDLSensor::write_reg(uint8_t reg, uint8_t data)
{
- if (lis2mdl_write_reg(&_reg_ctx, reg, &data, 1) != 0)
- {
- return 1;
- }
+ if (lis2mdl_write_reg(&_reg_ctx, reg, &data, 1) != 0) {
+ return 1;
+ }
- return 0;
+ return 0;
}
/**
@@ -379,12 +360,11 @@
*/
int LIS2MDLSensor::set_m_self_test(uint8_t status)
{
- if (lis2mdl_self_test_set(&_reg_ctx, status) != 0)
- {
- return 1;
- }
+ if (lis2mdl_self_test_set(&_reg_ctx, status) != 0) {
+ return 1;
+ }
- return 0;
+ return 0;
}
/**
@@ -394,22 +374,21 @@
*/
int LIS2MDLSensor::get_m_drdy_status(uint8_t *status)
{
- if (lis2mdl_mag_data_ready_get(&_reg_ctx, status) != 0)
- {
- return 1;
- }
+ if (lis2mdl_mag_data_ready_get(&_reg_ctx, status) != 0) {
+ return 1;
+ }
- return 0;
+ return 0;
}
int32_t LIS2MDL_io_write(void *handle, uint8_t WriteAddr, uint8_t *pBuffer, uint16_t nBytesToWrite)
{
- return ((LIS2MDLSensor *)handle)->io_write(pBuffer, WriteAddr, nBytesToWrite);
+ return ((LIS2MDLSensor *)handle)->io_write(pBuffer, WriteAddr, nBytesToWrite);
}
int32_t LIS2MDL_io_read(void *handle, uint8_t ReadAddr, uint8_t *pBuffer, uint16_t nBytesToRead)
{
- return ((LIS2MDLSensor *)handle)->io_read(pBuffer, ReadAddr, nBytesToRead);
+ return ((LIS2MDLSensor *)handle)->io_read(pBuffer, ReadAddr, nBytesToRead);
}
diff -r 671edf39d961 -r 8562ae1a0534 LIS2MDLSensor.h
--- a/LIS2MDLSensor.h Tue Mar 05 18:06:37 2019 +0000
+++ b/LIS2MDLSensor.h Wed Jul 24 14:18:39 2019 +0000
@@ -56,33 +56,30 @@
/* Typedefs ------------------------------------------------------------------*/
-typedef struct
-{
- int16_t x;
- int16_t y;
- int16_t z;
+typedef struct {
+ int16_t x;
+ int16_t y;
+ int16_t z;
} LIS2MDL_AxesRaw_t;
-typedef struct
-{
- int32_t x;
- int32_t y;
- int32_t z;
+typedef struct {
+ int32_t x;
+ int32_t y;
+ int32_t z;
} LIS2MDL_Axes_t;
/* Class Declaration ---------------------------------------------------------*/
-
+
/**
* Abstract class of an LIS2MDL Inertial Measurement Unit (IMU) 3 axes
* sensor.
*/
-class LIS2MDLSensor : public MagneticSensor
-{
- public:
+class LIS2MDLSensor : public MagneticSensor {
+public:
enum SPI_type_t {SPI3W, SPI4W};
- LIS2MDLSensor(SPI *spi, PinName cs_pin, PinName int_pin=NC, SPI_type_t spi_type=SPI4W);
- LIS2MDLSensor(DevI2C *i2c, uint8_t address=LIS2MDL_I2C_ADD, PinName int_pin=NC);
+ LIS2MDLSensor(SPI *spi, PinName cs_pin, PinName int_pin = NC, SPI_type_t spi_type = SPI4W);
+ LIS2MDLSensor(DevI2C *i2c, uint8_t address = LIS2MDL_I2C_ADD, PinName int_pin = NC);
virtual int init(void *init);
virtual int read_id(uint8_t *id);
virtual int get_m_axes(int32_t *magnetic_field);
@@ -118,7 +115,7 @@
{
_int_irq.enable_irq();
}
-
+
/**
* @brief Disabling the INT interrupt handling.
* @param None.
@@ -136,30 +133,32 @@
* @param NumByteToRead: number of bytes to be read.
* @retval 0 if ok, an error code otherwise.
*/
- uint8_t io_read(uint8_t* pBuffer, uint8_t RegisterAddr, uint16_t NumByteToRead)
+ uint8_t io_read(uint8_t *pBuffer, uint8_t RegisterAddr, uint16_t NumByteToRead)
{
if (_dev_spi) {
/* Write Reg Address */
_dev_spi->lock();
- _cs_pin = 0;
- if (_spi_type == SPI4W) {
+ _cs_pin = 0;
+ if (_spi_type == SPI4W) {
_dev_spi->write(RegisterAddr | 0x80);
- for (int i=0; i<NumByteToRead; i++) {
- *(pBuffer+i) = _dev_spi->write(0x00);
+ for (int i = 0; i < NumByteToRead; i++) {
+ *(pBuffer + i) = _dev_spi->write(0x00);
}
- } else if (_spi_type == SPI3W){
+ } else if (_spi_type == SPI3W) {
/* Write RD Reg Address with RD bit*/
- uint8_t TxByte = RegisterAddr | 0x80;
+ uint8_t TxByte = RegisterAddr | 0x80;
_dev_spi->write((char *)&TxByte, 1, (char *)pBuffer, (int) NumByteToRead);
- }
+ }
_cs_pin = 1;
- _dev_spi->unlock();
+ _dev_spi->unlock();
return 0;
- }
- if (_dev_i2c) return (uint8_t) _dev_i2c->i2c_read(pBuffer, _address, RegisterAddr, NumByteToRead);
+ }
+ if (_dev_i2c) {
+ return (uint8_t) _dev_i2c->i2c_read(pBuffer, _address, RegisterAddr, NumByteToRead);
+ }
return 1;
}
-
+
/**
* @brief Utility function to write data.
* @param pBuffer: pointer to data to be written.
@@ -167,22 +166,24 @@
* @param NumByteToWrite: number of bytes to write.
* @retval 0 if ok, an error code otherwise.
*/
- uint8_t io_write(uint8_t* pBuffer, uint8_t RegisterAddr, uint16_t NumByteToWrite)
+ uint8_t io_write(uint8_t *pBuffer, uint8_t RegisterAddr, uint16_t NumByteToWrite)
{
- if (_dev_spi) {
+ if (_dev_spi) {
_dev_spi->lock();
_cs_pin = 0;
- _dev_spi->write(RegisterAddr);
- _dev_spi->write((char *)pBuffer, (int) NumByteToWrite, NULL, 0);
- _cs_pin = 1;
+ _dev_spi->write(RegisterAddr);
+ _dev_spi->write((char *)pBuffer, (int) NumByteToWrite, NULL, 0);
+ _cs_pin = 1;
_dev_spi->unlock();
- return 0;
- }
- if (_dev_i2c) return (uint8_t) _dev_i2c->i2c_write(pBuffer, _address, RegisterAddr, NumByteToWrite);
+ return 0;
+ }
+ if (_dev_i2c) {
+ return (uint8_t) _dev_i2c->i2c_write(pBuffer, _address, RegisterAddr, NumByteToWrite);
+ }
return 1;
}
- private:
+private:
/* Helper classes. */
DevI2C *_dev_i2c;
@@ -190,23 +191,23 @@
/* Configuration */
uint8_t _address;
- DigitalOut _cs_pin;
+ DigitalOut _cs_pin;
InterruptIn _int_irq;
SPI_type_t _spi_type;
-
+
uint8_t _mag_is_enabled;
-
+
lis2mdl_ctx_t _reg_ctx;
-
+
};
#ifdef __cplusplus
- extern "C" {
+extern "C" {
#endif
-int32_t LIS2MDL_io_write( void *handle, uint8_t WriteAddr, uint8_t *pBuffer, uint16_t nBytesToWrite );
-int32_t LIS2MDL_io_read( void *handle, uint8_t ReadAddr, uint8_t *pBuffer, uint16_t nBytesToRead );
+int32_t LIS2MDL_io_write(void *handle, uint8_t WriteAddr, uint8_t *pBuffer, uint16_t nBytesToWrite);
+int32_t LIS2MDL_io_read(void *handle, uint8_t ReadAddr, uint8_t *pBuffer, uint16_t nBytesToRead);
#ifdef __cplusplus
- }
+}
#endif
#endif
diff -r 671edf39d961 -r 8562ae1a0534 lis2mdl_reg.c
--- a/lis2mdl_reg.c Tue Mar 05 18:06:37 2019 +0000
+++ b/lis2mdl_reg.c Wed Jul 24 14:18:39 2019 +0000
@@ -62,12 +62,12 @@
* @retval interface status (MANDATORY: return 0 -> no Error)
*
*/
-int32_t lis2mdl_read_reg(lis2mdl_ctx_t* ctx, uint8_t reg, uint8_t* data,
+int32_t lis2mdl_read_reg(lis2mdl_ctx_t *ctx, uint8_t reg, uint8_t *data,
uint16_t len)
{
- int32_t ret;
- ret = ctx->read_reg(ctx->handle, reg, data, len);
- return ret;
+ int32_t ret;
+ ret = ctx->read_reg(ctx->handle, reg, data, len);
+ return ret;
}
/**
@@ -80,12 +80,12 @@
* @retval interface status (MANDATORY: return 0 -> no Error)
*
*/
-int32_t lis2mdl_write_reg(lis2mdl_ctx_t* ctx, uint8_t reg, uint8_t* data,
+int32_t lis2mdl_write_reg(lis2mdl_ctx_t *ctx, uint8_t reg, uint8_t *data,
uint16_t len)
{
- int32_t ret;
- ret = ctx->write_reg(ctx->handle, reg, data, len);
- return ret;
+ int32_t ret;
+ ret = ctx->write_reg(ctx->handle, reg, data, len);
+ return ret;
}
/**
@@ -93,20 +93,20 @@
*
*/
- /**
- * @defgroup LIS2MDL_Sensitivity
- * @brief These functions convert raw-data into engineering units.
- * @{
- *
- */
+/**
+* @defgroup LIS2MDL_Sensitivity
+* @brief These functions convert raw-data into engineering units.
+* @{
+*
+*/
float_t lis2mdl_from_lsb_to_mgauss(int16_t lsb)
{
- return ((float_t)lsb * 1.5f);
+ return ((float_t)lsb * 1.5f);
}
float_t lis2mdl_from_lsb_to_celsius(int16_t lsb)
{
- return (((float_t)lsb / 8.0f) + 25.0f);
+ return (((float_t)lsb / 8.0f) + 25.0f);
}
/**
@@ -136,9 +136,9 @@
*/
int32_t lis2mdl_mag_user_offset_set(lis2mdl_ctx_t *ctx, uint8_t *buff)
{
- int32_t ret;
- ret = lis2mdl_write_reg(ctx, LIS2MDL_OFFSET_X_REG_L, buff, 6);
- return ret;
+ int32_t ret;
+ ret = lis2mdl_write_reg(ctx, LIS2MDL_OFFSET_X_REG_L, buff, 6);
+ return ret;
}
/**
@@ -155,9 +155,9 @@
*/
int32_t lis2mdl_mag_user_offset_get(lis2mdl_ctx_t *ctx, uint8_t *buff)
{
- int32_t ret;
- ret = lis2mdl_read_reg(ctx, LIS2MDL_OFFSET_X_REG_L, buff, 6);
- return ret;
+ int32_t ret;
+ ret = lis2mdl_read_reg(ctx, LIS2MDL_OFFSET_X_REG_L, buff, 6);
+ return ret;
}
/**
@@ -170,17 +170,17 @@
*/
int32_t lis2mdl_operating_mode_set(lis2mdl_ctx_t *ctx, lis2mdl_md_t val)
{
- lis2mdl_cfg_reg_a_t reg;
- int32_t ret;
+ lis2mdl_cfg_reg_a_t reg;
+ int32_t ret;
+
+ ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t *)®, 1);
- ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t*)®, 1);
-
- if(ret == 0){
- reg.md = (uint8_t)val;
- ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t*)®, 1);
- }
-
- return ret;
+ if (ret == 0) {
+ reg.md = (uint8_t)val;
+ ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t *)®, 1);
+ }
+
+ return ret;
}
/**
@@ -193,30 +193,30 @@
*/
int32_t lis2mdl_operating_mode_get(lis2mdl_ctx_t *ctx, lis2mdl_md_t *val)
{
- lis2mdl_cfg_reg_a_t reg;
- int32_t ret;
+ lis2mdl_cfg_reg_a_t reg;
+ int32_t ret;
- ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t*)®, 1);
- switch (reg.md){
- case LIS2MDL_POWER_DOWN:
- *val = LIS2MDL_POWER_DOWN;
- break;
- case LIS2MDL_CONTINUOUS_MODE:
- *val = LIS2MDL_CONTINUOUS_MODE;
- break;
- case LIS2MDL_SINGLE_TRIGGER:
- *val = LIS2MDL_SINGLE_TRIGGER;
- break;
- default:
- *val = LIS2MDL_POWER_DOWN;
- break;
- }
+ ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t *)®, 1);
+ switch (reg.md) {
+ case LIS2MDL_POWER_DOWN:
+ *val = LIS2MDL_POWER_DOWN;
+ break;
+ case LIS2MDL_CONTINUOUS_MODE:
+ *val = LIS2MDL_CONTINUOUS_MODE;
+ break;
+ case LIS2MDL_SINGLE_TRIGGER:
+ *val = LIS2MDL_SINGLE_TRIGGER;
+ break;
+ default:
+ *val = LIS2MDL_POWER_DOWN;
+ break;
+ }
- return ret;
+ return ret;
}
/**
- * @brief Output data rate selection.[set]
+ * @brief Output data rate selection.[set]
*
* @param ctx read / write interface definitions.(ptr)
* @param val change the values of odr in reg CFG_REG_A
@@ -225,21 +225,21 @@
*/
int32_t lis2mdl_data_rate_set(lis2mdl_ctx_t *ctx, lis2mdl_odr_t val)
{
- lis2mdl_cfg_reg_a_t reg;
- int32_t ret;
+ lis2mdl_cfg_reg_a_t reg;
+ int32_t ret;
+
+ ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t *)®, 1);
- ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t*)®, 1);
-
- if(ret == 0){
- reg.odr = (uint8_t)val;
- ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t*)®, 1);
- }
-
- return ret;
+ if (ret == 0) {
+ reg.odr = (uint8_t)val;
+ ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t *)®, 1);
+ }
+
+ return ret;
}
/**
- * @brief Output data rate selection.[get]
+ * @brief Output data rate selection.[get]
*
* @param ctx read / write interface definitions.(ptr)
* @param val Get the values of odr in reg CFG_REG_A.(ptr)
@@ -248,28 +248,28 @@
*/
int32_t lis2mdl_data_rate_get(lis2mdl_ctx_t *ctx, lis2mdl_odr_t *val)
{
- lis2mdl_cfg_reg_a_t reg;
- int32_t ret;
+ lis2mdl_cfg_reg_a_t reg;
+ int32_t ret;
- ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t*)®, 1);
- switch (reg.odr){
- case LIS2MDL_ODR_10Hz:
- *val = LIS2MDL_ODR_10Hz;
- break;
- case LIS2MDL_ODR_20Hz:
- *val = LIS2MDL_ODR_20Hz;
- break;
- case LIS2MDL_ODR_50Hz:
- *val = LIS2MDL_ODR_50Hz;
- break;
- case LIS2MDL_ODR_100Hz:
- *val = LIS2MDL_ODR_100Hz;
- break;
- default:
- *val = LIS2MDL_ODR_10Hz;
- break;
- }
- return ret;
+ ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t *)®, 1);
+ switch (reg.odr) {
+ case LIS2MDL_ODR_10Hz:
+ *val = LIS2MDL_ODR_10Hz;
+ break;
+ case LIS2MDL_ODR_20Hz:
+ *val = LIS2MDL_ODR_20Hz;
+ break;
+ case LIS2MDL_ODR_50Hz:
+ *val = LIS2MDL_ODR_50Hz;
+ break;
+ case LIS2MDL_ODR_100Hz:
+ *val = LIS2MDL_ODR_100Hz;
+ break;
+ default:
+ *val = LIS2MDL_ODR_10Hz;
+ break;
+ }
+ return ret;
}
/**
@@ -282,17 +282,17 @@
*/
int32_t lis2mdl_power_mode_set(lis2mdl_ctx_t *ctx, lis2mdl_lp_t val)
{
- lis2mdl_cfg_reg_a_t reg;
- int32_t ret;
+ lis2mdl_cfg_reg_a_t reg;
+ int32_t ret;
+
+ ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t *)®, 1);
- ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t*)®, 1);
-
- if(ret == 0){
- reg.lp = (uint8_t)val;
- ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t*)®, 1);
- }
-
- return ret;
+ if (ret == 0) {
+ reg.lp = (uint8_t)val;
+ ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t *)®, 1);
+ }
+
+ return ret;
}
/**
@@ -305,26 +305,26 @@
*/
int32_t lis2mdl_power_mode_get(lis2mdl_ctx_t *ctx, lis2mdl_lp_t *val)
{
- lis2mdl_cfg_reg_a_t reg;
- int32_t ret;
+ lis2mdl_cfg_reg_a_t reg;
+ int32_t ret;
- ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t*)®, 1);
- switch (reg.lp){
- case LIS2MDL_HIGH_RESOLUTION:
- *val = LIS2MDL_HIGH_RESOLUTION;
- break;
- case LIS2MDL_LOW_POWER:
- *val = LIS2MDL_LOW_POWER;
- break;
- default:
- *val = LIS2MDL_HIGH_RESOLUTION;
- break;
- }
- return ret;
+ ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t *)®, 1);
+ switch (reg.lp) {
+ case LIS2MDL_HIGH_RESOLUTION:
+ *val = LIS2MDL_HIGH_RESOLUTION;
+ break;
+ case LIS2MDL_LOW_POWER:
+ *val = LIS2MDL_LOW_POWER;
+ break;
+ default:
+ *val = LIS2MDL_HIGH_RESOLUTION;
+ break;
+ }
+ return ret;
}
/**
- * @brief Enables the magnetometer temperature compensation.[set]
+ * @brief Enables the magnetometer temperature compensation.[set]
*
* @param ctx read / write interface definitions.(ptr)
* @param val change the values of comp_temp_en in reg CFG_REG_A
@@ -333,17 +333,17 @@
*/
int32_t lis2mdl_offset_temp_comp_set(lis2mdl_ctx_t *ctx, uint8_t val)
{
- lis2mdl_cfg_reg_a_t reg;
- int32_t ret;
+ lis2mdl_cfg_reg_a_t reg;
+ int32_t ret;
+
+ ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t *)®, 1);
- ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t*)®, 1);
-
- if(ret == 0){
- reg.comp_temp_en = val;
- ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t*)®, 1);
- }
-
- return ret;
+ if (ret == 0) {
+ reg.comp_temp_en = val;
+ ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t *)®, 1);
+ }
+
+ return ret;
}
/**
@@ -356,13 +356,13 @@
*/
int32_t lis2mdl_offset_temp_comp_get(lis2mdl_ctx_t *ctx, uint8_t *val)
{
- lis2mdl_cfg_reg_a_t reg;
- int32_t ret;
+ lis2mdl_cfg_reg_a_t reg;
+ int32_t ret;
- ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t*)®, 1);
- *val = reg.comp_temp_en;
+ ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t *)®, 1);
+ *val = reg.comp_temp_en;
- return ret;
+ return ret;
}
/**
@@ -376,17 +376,17 @@
int32_t lis2mdl_low_pass_bandwidth_set(lis2mdl_ctx_t *ctx,
lis2mdl_lpf_t val)
{
- lis2mdl_cfg_reg_b_t reg;
- int32_t ret;
+ lis2mdl_cfg_reg_b_t reg;
+ int32_t ret;
+
+ ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_B, (uint8_t *)®, 1);
- ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_B, (uint8_t*)®, 1);
-
- if(ret == 0){
- reg.lpf = (uint8_t)val;
- ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_B, (uint8_t*)®, 1);
- }
-
- return ret;
+ if (ret == 0) {
+ reg.lpf = (uint8_t)val;
+ ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_B, (uint8_t *)®, 1);
+ }
+
+ return ret;
}
/**
@@ -400,22 +400,22 @@
int32_t lis2mdl_low_pass_bandwidth_get(lis2mdl_ctx_t *ctx,
lis2mdl_lpf_t *val)
{
- lis2mdl_cfg_reg_b_t reg;
- int32_t ret;
+ lis2mdl_cfg_reg_b_t reg;
+ int32_t ret;
- ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_B, (uint8_t*)®, 1);
- switch (reg.lpf){
- case LIS2MDL_ODR_DIV_2:
- *val = LIS2MDL_ODR_DIV_2;
- break;
- case LIS2MDL_ODR_DIV_4:
- *val = LIS2MDL_ODR_DIV_4;
- break;
- default:
- *val = LIS2MDL_ODR_DIV_2;
- break;
- }
- return ret;
+ ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_B, (uint8_t *)®, 1);
+ switch (reg.lpf) {
+ case LIS2MDL_ODR_DIV_2:
+ *val = LIS2MDL_ODR_DIV_2;
+ break;
+ case LIS2MDL_ODR_DIV_4:
+ *val = LIS2MDL_ODR_DIV_4;
+ break;
+ default:
+ *val = LIS2MDL_ODR_DIV_2;
+ break;
+ }
+ return ret;
}
/**
@@ -428,17 +428,17 @@
*/
int32_t lis2mdl_set_rst_mode_set(lis2mdl_ctx_t *ctx, lis2mdl_set_rst_t val)
{
- lis2mdl_cfg_reg_b_t reg;
- int32_t ret;
+ lis2mdl_cfg_reg_b_t reg;
+ int32_t ret;
+
+ ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_B, (uint8_t *)®, 1);
- ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_B, (uint8_t*)®, 1);
-
- if(ret == 0){
- reg.set_rst = (uint8_t)val;
- ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_B, (uint8_t*)®, 1);
- }
-
- return ret;
+ if (ret == 0) {
+ reg.set_rst = (uint8_t)val;
+ ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_B, (uint8_t *)®, 1);
+ }
+
+ return ret;
}
/**
@@ -451,29 +451,29 @@
*/
int32_t lis2mdl_set_rst_mode_get(lis2mdl_ctx_t *ctx, lis2mdl_set_rst_t *val)
{
- lis2mdl_cfg_reg_b_t reg;
- int32_t ret;
+ lis2mdl_cfg_reg_b_t reg;
+ int32_t ret;
- ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_B, (uint8_t*)®, 1);
- switch (reg.set_rst){
- case LIS2MDL_SET_SENS_ODR_DIV_63:
- *val = LIS2MDL_SET_SENS_ODR_DIV_63;
- break;
- case LIS2MDL_SENS_OFF_CANC_EVERY_ODR:
- *val = LIS2MDL_SENS_OFF_CANC_EVERY_ODR;
- break;
- case LIS2MDL_SET_SENS_ONLY_AT_POWER_ON:
- *val = LIS2MDL_SET_SENS_ONLY_AT_POWER_ON;
- break;
- default:
- *val = LIS2MDL_SET_SENS_ODR_DIV_63;
- break;
- }
- return ret;
+ ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_B, (uint8_t *)®, 1);
+ switch (reg.set_rst) {
+ case LIS2MDL_SET_SENS_ODR_DIV_63:
+ *val = LIS2MDL_SET_SENS_ODR_DIV_63;
+ break;
+ case LIS2MDL_SENS_OFF_CANC_EVERY_ODR:
+ *val = LIS2MDL_SENS_OFF_CANC_EVERY_ODR;
+ break;
+ case LIS2MDL_SET_SENS_ONLY_AT_POWER_ON:
+ *val = LIS2MDL_SET_SENS_ONLY_AT_POWER_ON;
+ break;
+ default:
+ *val = LIS2MDL_SET_SENS_ODR_DIV_63;
+ break;
+ }
+ return ret;
}
/**
- * @brief Enables offset cancellation in single measurement mode.
+ * @brief Enables offset cancellation in single measurement mode.
* The OFF_CANC bit must be set to 1 when enabling offset
* cancellation in single measurement mode this means a
* call function: set_rst_mode(SENS_OFF_CANC_EVERY_ODR)
@@ -486,21 +486,21 @@
*/
int32_t lis2mdl_set_rst_sensor_single_set(lis2mdl_ctx_t *ctx, uint8_t val)
{
- lis2mdl_cfg_reg_b_t reg;
- int32_t ret;
+ lis2mdl_cfg_reg_b_t reg;
+ int32_t ret;
+
+ ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_B, (uint8_t *)®, 1);
- ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_B, (uint8_t*)®, 1);
-
- if(ret == 0){
- reg.off_canc_one_shot = val;
- ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_B, (uint8_t*)®, 1);
- }
-
- return ret;
+ if (ret == 0) {
+ reg.off_canc_one_shot = val;
+ ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_B, (uint8_t *)®, 1);
+ }
+
+ return ret;
}
/**
- * @brief Enables offset cancellation in single measurement mode.
+ * @brief Enables offset cancellation in single measurement mode.
* The OFF_CANC bit must be set to 1 when enabling offset
* cancellation in single measurement mode this means a
* call function: set_rst_mode(SENS_OFF_CANC_EVERY_ODR)
@@ -513,13 +513,13 @@
*/
int32_t lis2mdl_set_rst_sensor_single_get(lis2mdl_ctx_t *ctx, uint8_t *val)
{
- lis2mdl_cfg_reg_b_t reg;
- int32_t ret;
+ lis2mdl_cfg_reg_b_t reg;
+ int32_t ret;
- ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_B, (uint8_t*)®, 1);
- *val = reg.off_canc_one_shot;
+ ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_B, (uint8_t *)®, 1);
+ *val = reg.off_canc_one_shot;
- return ret;
+ return ret;
}
/**
@@ -532,17 +532,17 @@
*/
int32_t lis2mdl_block_data_update_set(lis2mdl_ctx_t *ctx, uint8_t val)
{
- lis2mdl_cfg_reg_c_t reg;
- int32_t ret;
+ lis2mdl_cfg_reg_c_t reg;
+ int32_t ret;
+
+ ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t *)®, 1);
- ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t*)®, 1);
-
- if(ret == 0){
- reg.bdu = val;
- ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t*)®, 1);
- }
-
- return ret;
+ if (ret == 0) {
+ reg.bdu = val;
+ ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t *)®, 1);
+ }
+
+ return ret;
}
/**
@@ -555,13 +555,13 @@
*/
int32_t lis2mdl_block_data_update_get(lis2mdl_ctx_t *ctx, uint8_t *val)
{
- lis2mdl_cfg_reg_c_t reg;
- int32_t ret;
+ lis2mdl_cfg_reg_c_t reg;
+ int32_t ret;
- ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t*)®, 1);
- *val = reg.bdu;
+ ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t *)®, 1);
+ *val = reg.bdu;
- return ret;
+ return ret;
}
/**
@@ -574,13 +574,13 @@
*/
int32_t lis2mdl_mag_data_ready_get(lis2mdl_ctx_t *ctx, uint8_t *val)
{
- lis2mdl_status_reg_t reg;
- int32_t ret;
+ lis2mdl_status_reg_t reg;
+ int32_t ret;
- ret = lis2mdl_read_reg(ctx, LIS2MDL_STATUS_REG, (uint8_t*)®, 1);
- *val = reg.zyxda;
+ ret = lis2mdl_read_reg(ctx, LIS2MDL_STATUS_REG, (uint8_t *)®, 1);
+ *val = reg.zyxda;
- return ret;
+ return ret;
}
/**
@@ -593,13 +593,13 @@
*/
int32_t lis2mdl_mag_data_ovr_get(lis2mdl_ctx_t *ctx, uint8_t *val)
{
- lis2mdl_status_reg_t reg;
- int32_t ret;
+ lis2mdl_status_reg_t reg;
+ int32_t ret;
- ret = lis2mdl_read_reg(ctx, LIS2MDL_STATUS_REG, (uint8_t*)®, 1);
- *val = reg.zyxor;
+ ret = lis2mdl_read_reg(ctx, LIS2MDL_STATUS_REG, (uint8_t *)®, 1);
+ *val = reg.zyxor;
- return ret;
+ return ret;
}
/**
@@ -612,9 +612,9 @@
*/
int32_t lis2mdl_magnetic_raw_get(lis2mdl_ctx_t *ctx, uint8_t *buff)
{
- int32_t ret;
- ret = lis2mdl_read_reg(ctx, LIS2MDL_OUTX_L_REG, buff, 6);
- return ret;
+ int32_t ret;
+ ret = lis2mdl_read_reg(ctx, LIS2MDL_OUTX_L_REG, buff, 6);
+ return ret;
}
/**
@@ -627,9 +627,9 @@
*/
int32_t lis2mdl_temperature_raw_get(lis2mdl_ctx_t *ctx, uint8_t *buff)
{
- int32_t ret;
- ret = lis2mdl_read_reg(ctx, LIS2MDL_TEMP_OUT_L_REG, buff, 2);
- return ret;
+ int32_t ret;
+ ret = lis2mdl_read_reg(ctx, LIS2MDL_TEMP_OUT_L_REG, buff, 2);
+ return ret;
}
/**
@@ -654,9 +654,9 @@
*/
int32_t lis2mdl_device_id_get(lis2mdl_ctx_t *ctx, uint8_t *buff)
{
- int32_t ret;
- ret = lis2mdl_read_reg(ctx, LIS2MDL_WHO_AM_I, buff, 1);
- return ret;
+ int32_t ret;
+ ret = lis2mdl_read_reg(ctx, LIS2MDL_WHO_AM_I, buff, 1);
+ return ret;
}
/**
@@ -669,17 +669,17 @@
*/
int32_t lis2mdl_reset_set(lis2mdl_ctx_t *ctx, uint8_t val)
{
- lis2mdl_cfg_reg_a_t reg;
- int32_t ret;
+ lis2mdl_cfg_reg_a_t reg;
+ int32_t ret;
+
+ ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t *)®, 1);
- ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t*)®, 1);
-
- if(ret == 0){
- reg.soft_rst = val;
- ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t*)®, 1);
- }
-
- return ret;
+ if (ret == 0) {
+ reg.soft_rst = val;
+ ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t *)®, 1);
+ }
+
+ return ret;
}
/**
@@ -692,17 +692,17 @@
*/
int32_t lis2mdl_reset_get(lis2mdl_ctx_t *ctx, uint8_t *val)
{
- lis2mdl_cfg_reg_a_t reg;
- int32_t ret;
+ lis2mdl_cfg_reg_a_t reg;
+ int32_t ret;
- ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t*)®, 1);
- *val = reg.soft_rst;
+ ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t *)®, 1);
+ *val = reg.soft_rst;
- return ret;
+ return ret;
}
/**
- * @brief Reboot memory content. Reload the calibration parameters.[set]
+ * @brief Reboot memory content. Reload the calibration parameters.[set]
*
* @param ctx read / write interface definitions.(ptr)
* @param val change the values of reboot in reg CFG_REG_A
@@ -711,17 +711,17 @@
*/
int32_t lis2mdl_boot_set(lis2mdl_ctx_t *ctx, uint8_t val)
{
- lis2mdl_cfg_reg_a_t reg;
- int32_t ret;
+ lis2mdl_cfg_reg_a_t reg;
+ int32_t ret;
+
+ ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t *)®, 1);
- ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t*)®, 1);
-
- if(ret == 0){
- reg.reboot = val;
- ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t*)®, 1);
- }
-
- return ret;
+ if (ret == 0) {
+ reg.reboot = val;
+ ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t *)®, 1);
+ }
+
+ return ret;
}
/**
@@ -734,13 +734,13 @@
*/
int32_t lis2mdl_boot_get(lis2mdl_ctx_t *ctx, uint8_t *val)
{
- lis2mdl_cfg_reg_a_t reg;
- int32_t ret;
+ lis2mdl_cfg_reg_a_t reg;
+ int32_t ret;
- ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t*)®, 1);
- *val = reg.reboot;
+ ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t *)®, 1);
+ *val = reg.reboot;
- return ret;
+ return ret;
}
/**
@@ -753,17 +753,17 @@
*/
int32_t lis2mdl_self_test_set(lis2mdl_ctx_t *ctx, uint8_t val)
{
- lis2mdl_cfg_reg_c_t reg;
- int32_t ret;
+ lis2mdl_cfg_reg_c_t reg;
+ int32_t ret;
+
+ ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t *)®, 1);
- ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t*)®, 1);
-
- if(ret == 0){
- reg.self_test = val;
- ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t*)®, 1);
- }
-
- return ret;
+ if (ret == 0) {
+ reg.self_test = val;
+ ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t *)®, 1);
+ }
+
+ return ret;
}
/**
@@ -776,13 +776,13 @@
*/
int32_t lis2mdl_self_test_get(lis2mdl_ctx_t *ctx, uint8_t *val)
{
- lis2mdl_cfg_reg_c_t reg;
- int32_t ret;
+ lis2mdl_cfg_reg_c_t reg;
+ int32_t ret;
- ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t*)®, 1);
- *val = reg.self_test;
+ ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t *)®, 1);
+ *val = reg.self_test;
- return ret;
+ return ret;
}
/**
@@ -795,17 +795,17 @@
*/
int32_t lis2mdl_data_format_set(lis2mdl_ctx_t *ctx, lis2mdl_ble_t val)
{
- lis2mdl_cfg_reg_c_t reg;
- int32_t ret;
+ lis2mdl_cfg_reg_c_t reg;
+ int32_t ret;
+
+ ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t *)®, 1);
- ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t*)®, 1);
-
- if(ret == 0){
- reg.ble = (uint8_t)val;
- ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t*)®, 1);
- }
-
- return ret;
+ if (ret == 0) {
+ reg.ble = (uint8_t)val;
+ ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t *)®, 1);
+ }
+
+ return ret;
}
/**
@@ -818,22 +818,22 @@
*/
int32_t lis2mdl_data_format_get(lis2mdl_ctx_t *ctx, lis2mdl_ble_t *val)
{
- lis2mdl_cfg_reg_c_t reg;
- int32_t ret;
+ lis2mdl_cfg_reg_c_t reg;
+ int32_t ret;
- ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t*)®, 1);
- switch (reg.ble){
- case LIS2MDL_LSB_AT_LOW_ADD:
- *val = LIS2MDL_LSB_AT_LOW_ADD;
- break;
- case LIS2MDL_MSB_AT_LOW_ADD:
- *val = LIS2MDL_MSB_AT_LOW_ADD;
- break;
- default:
- *val = LIS2MDL_LSB_AT_LOW_ADD;
- break;
- }
- return ret;
+ ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t *)®, 1);
+ switch (reg.ble) {
+ case LIS2MDL_LSB_AT_LOW_ADD:
+ *val = LIS2MDL_LSB_AT_LOW_ADD;
+ break;
+ case LIS2MDL_MSB_AT_LOW_ADD:
+ *val = LIS2MDL_MSB_AT_LOW_ADD;
+ break;
+ default:
+ *val = LIS2MDL_LSB_AT_LOW_ADD;
+ break;
+ }
+ return ret;
}
/**
@@ -846,9 +846,9 @@
*/
int32_t lis2mdl_status_get(lis2mdl_ctx_t *ctx, lis2mdl_status_reg_t *val)
{
- int32_t ret;
- ret = lis2mdl_read_reg(ctx, LIS2MDL_STATUS_REG, (uint8_t*) val, 1);
- return ret;
+ int32_t ret;
+ ret = lis2mdl_read_reg(ctx, LIS2MDL_STATUS_REG, (uint8_t *) val, 1);
+ return ret;
}
/**
@@ -875,17 +875,17 @@
int32_t lis2mdl_offset_int_conf_set(lis2mdl_ctx_t *ctx,
lis2mdl_int_on_dataoff_t val)
{
- lis2mdl_cfg_reg_b_t reg;
- int32_t ret;
+ lis2mdl_cfg_reg_b_t reg;
+ int32_t ret;
+
+ ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_B, (uint8_t *)®, 1);
- ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_B, (uint8_t*)®, 1);
-
- if(ret == 0){
- reg.int_on_dataoff = (uint8_t)val;
- ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_B, (uint8_t*)®, 1);
- }
-
- return ret;
+ if (ret == 0) {
+ reg.int_on_dataoff = (uint8_t)val;
+ ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_B, (uint8_t *)®, 1);
+ }
+
+ return ret;
}
/**
@@ -900,22 +900,22 @@
int32_t lis2mdl_offset_int_conf_get(lis2mdl_ctx_t *ctx,
lis2mdl_int_on_dataoff_t *val)
{
- lis2mdl_cfg_reg_b_t reg;
- int32_t ret;
+ lis2mdl_cfg_reg_b_t reg;
+ int32_t ret;
- ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_B, (uint8_t*)®, 1);
- switch (reg.int_on_dataoff){
- case LIS2MDL_CHECK_BEFORE:
- *val = LIS2MDL_CHECK_BEFORE;
- break;
- case LIS2MDL_CHECK_AFTER:
- *val = LIS2MDL_CHECK_AFTER;
- break;
- default:
- *val = LIS2MDL_CHECK_BEFORE;
- break;
- }
- return ret;
+ ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_B, (uint8_t *)®, 1);
+ switch (reg.int_on_dataoff) {
+ case LIS2MDL_CHECK_BEFORE:
+ *val = LIS2MDL_CHECK_BEFORE;
+ break;
+ case LIS2MDL_CHECK_AFTER:
+ *val = LIS2MDL_CHECK_AFTER;
+ break;
+ default:
+ *val = LIS2MDL_CHECK_BEFORE;
+ break;
+ }
+ return ret;
}
/**
@@ -928,17 +928,17 @@
*/
int32_t lis2mdl_drdy_on_pin_set(lis2mdl_ctx_t *ctx, uint8_t val)
{
- lis2mdl_cfg_reg_c_t reg;
- int32_t ret;
+ lis2mdl_cfg_reg_c_t reg;
+ int32_t ret;
+
+ ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t *)®, 1);
- ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t*)®, 1);
-
- if(ret == 0){
- reg.drdy_on_pin = val;
- ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t*)®, 1);
- }
-
- return ret;
+ if (ret == 0) {
+ reg.drdy_on_pin = val;
+ ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t *)®, 1);
+ }
+
+ return ret;
}
/**
@@ -951,13 +951,13 @@
*/
int32_t lis2mdl_drdy_on_pin_get(lis2mdl_ctx_t *ctx, uint8_t *val)
{
- lis2mdl_cfg_reg_c_t reg;
- int32_t ret;
+ lis2mdl_cfg_reg_c_t reg;
+ int32_t ret;
- ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t*)®, 1);
- *val = reg.drdy_on_pin;
+ ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t *)®, 1);
+ *val = reg.drdy_on_pin;
- return ret;
+ return ret;
}
/**
@@ -970,17 +970,17 @@
*/
int32_t lis2mdl_int_on_pin_set(lis2mdl_ctx_t *ctx, uint8_t val)
{
- lis2mdl_cfg_reg_c_t reg;
- int32_t ret;
+ lis2mdl_cfg_reg_c_t reg;
+ int32_t ret;
+
+ ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t *)®, 1);
- ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t*)®, 1);
-
- if(ret == 0){
- reg.int_on_pin = val;
- ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t*)®, 1);
- }
-
- return ret;
+ if (ret == 0) {
+ reg.int_on_pin = val;
+ ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t *)®, 1);
+ }
+
+ return ret;
}
/**
@@ -993,13 +993,13 @@
*/
int32_t lis2mdl_int_on_pin_get(lis2mdl_ctx_t *ctx, uint8_t *val)
{
- lis2mdl_cfg_reg_c_t reg;
- int32_t ret;
+ lis2mdl_cfg_reg_c_t reg;
+ int32_t ret;
- ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t*)®, 1);
- *val = reg.int_on_pin;
+ ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t *)®, 1);
+ *val = reg.int_on_pin;
- return ret;
+ return ret;
}
/**
@@ -1013,9 +1013,9 @@
int32_t lis2mdl_int_gen_conf_set(lis2mdl_ctx_t *ctx,
lis2mdl_int_crtl_reg_t *val)
{
- int32_t ret;
- ret = lis2mdl_write_reg(ctx, LIS2MDL_INT_CRTL_REG, (uint8_t*) val, 1);
- return ret;
+ int32_t ret;
+ ret = lis2mdl_write_reg(ctx, LIS2MDL_INT_CRTL_REG, (uint8_t *) val, 1);
+ return ret;
}
/**
@@ -1029,9 +1029,9 @@
int32_t lis2mdl_int_gen_conf_get(lis2mdl_ctx_t *ctx,
lis2mdl_int_crtl_reg_t *val)
{
- int32_t ret;
- ret = lis2mdl_read_reg(ctx, LIS2MDL_INT_CRTL_REG, (uint8_t*) val, 1);
- return ret;
+ int32_t ret;
+ ret = lis2mdl_read_reg(ctx, LIS2MDL_INT_CRTL_REG, (uint8_t *) val, 1);
+ return ret;
}
/**
@@ -1045,9 +1045,9 @@
int32_t lis2mdl_int_gen_source_get(lis2mdl_ctx_t *ctx,
lis2mdl_int_source_reg_t *val)
{
- int32_t ret;
- ret = lis2mdl_read_reg(ctx, LIS2MDL_INT_SOURCE_REG, (uint8_t*) val, 1);
- return ret;
+ int32_t ret;
+ ret = lis2mdl_read_reg(ctx, LIS2MDL_INT_SOURCE_REG, (uint8_t *) val, 1);
+ return ret;
}
/**
@@ -1062,9 +1062,9 @@
*/
int32_t lis2mdl_int_gen_treshold_set(lis2mdl_ctx_t *ctx, uint8_t *buff)
{
- int32_t ret;
- ret = lis2mdl_write_reg(ctx, LIS2MDL_INT_THS_L_REG, buff, 2);
- return ret;
+ int32_t ret;
+ ret = lis2mdl_write_reg(ctx, LIS2MDL_INT_THS_L_REG, buff, 2);
+ return ret;
}
/**
@@ -1079,9 +1079,9 @@
*/
int32_t lis2mdl_int_gen_treshold_get(lis2mdl_ctx_t *ctx, uint8_t *buff)
{
- int32_t ret;
- ret = lis2mdl_read_reg(ctx, LIS2MDL_INT_THS_L_REG, buff, 2);
- return ret;
+ int32_t ret;
+ ret = lis2mdl_read_reg(ctx, LIS2MDL_INT_THS_L_REG, buff, 2);
+ return ret;
}
/**
@@ -1107,17 +1107,17 @@
*/
int32_t lis2mdl_i2c_interface_set(lis2mdl_ctx_t *ctx, lis2mdl_i2c_dis_t val)
{
- lis2mdl_cfg_reg_c_t reg;
- int32_t ret;
+ lis2mdl_cfg_reg_c_t reg;
+ int32_t ret;
+
+ ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t *)®, 1);
- ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t*)®, 1);
-
- if(ret == 0){
- reg.i2c_dis = (uint8_t)val;
- ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t*)®, 1);
- }
-
- return ret;
+ if (ret == 0) {
+ reg.i2c_dis = (uint8_t)val;
+ ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t *)®, 1);
+ }
+
+ return ret;
}
/**
@@ -1130,22 +1130,22 @@
*/
int32_t lis2mdl_i2c_interface_get(lis2mdl_ctx_t *ctx, lis2mdl_i2c_dis_t *val)
{
- lis2mdl_cfg_reg_c_t reg;
- int32_t ret;
+ lis2mdl_cfg_reg_c_t reg;
+ int32_t ret;
- ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t*)®, 1);
- switch (reg.i2c_dis){
- case LIS2MDL_I2C_ENABLE:
- *val = LIS2MDL_I2C_ENABLE;
- break;
- case LIS2MDL_I2C_DISABLE:
- *val = LIS2MDL_I2C_DISABLE;
- break;
- default:
- *val = LIS2MDL_I2C_ENABLE;
- break;
- }
- return ret;
+ ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t *)®, 1);
+ switch (reg.i2c_dis) {
+ case LIS2MDL_I2C_ENABLE:
+ *val = LIS2MDL_I2C_ENABLE;
+ break;
+ case LIS2MDL_I2C_DISABLE:
+ *val = LIS2MDL_I2C_DISABLE;
+ break;
+ default:
+ *val = LIS2MDL_I2C_ENABLE;
+ break;
+ }
+ return ret;
}
/**
diff -r 671edf39d961 -r 8562ae1a0534 lis2mdl_reg.h
--- a/lis2mdl_reg.h Tue Mar 05 18:06:37 2019 +0000
+++ b/lis2mdl_reg.h Wed Jul 24 14:18:39 2019 +0000
@@ -39,7 +39,7 @@
#define LIS2MDL_REGS_H
#ifdef __cplusplus
- extern "C" {
+extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
@@ -76,24 +76,24 @@
*
*/
-typedef union{
- int16_t i16bit[3];
- uint8_t u8bit[6];
+typedef union {
+ int16_t i16bit[3];
+ uint8_t u8bit[6];
} axis3bit16_t;
-typedef union{
- int16_t i16bit;
- uint8_t u8bit[2];
+typedef union {
+ int16_t i16bit;
+ uint8_t u8bit[2];
} axis1bit16_t;
-typedef union{
- int32_t i32bit[3];
- uint8_t u8bit[12];
+typedef union {
+ int32_t i32bit[3];
+ uint8_t u8bit[12];
} axis3bit32_t;
-typedef union{
- int32_t i32bit;
- uint8_t u8bit[4];
+typedef union {
+ int32_t i32bit;
+ uint8_t u8bit[4];
} axis1bit32_t;
/**
@@ -101,15 +101,15 @@
*
*/
-typedef struct{
- uint8_t bit0 : 1;
- uint8_t bit1 : 1;
- uint8_t bit2 : 1;
- uint8_t bit3 : 1;
- uint8_t bit4 : 1;
- uint8_t bit5 : 1;
- uint8_t bit6 : 1;
- uint8_t bit7 : 1;
+typedef struct {
+ uint8_t bit0 : 1;
+ uint8_t bit1 : 1;
+ uint8_t bit2 : 1;
+ uint8_t bit3 : 1;
+ uint8_t bit4 : 1;
+ uint8_t bit5 : 1;
+ uint8_t bit6 : 1;
+ uint8_t bit7 : 1;
} bitwise_t;
#define PROPERTY_DISABLE (0U)
@@ -122,23 +122,23 @@
*
*/
- /** @addtogroup LIS2MDL_Interfaces_Functions
- * @brief This section provide a set of functions used to read and
- * write a generic register of the device.
- * MANDATORY: return 0 -> no Error.
- * @{
- *
- */
+/** @addtogroup LIS2MDL_Interfaces_Functions
+ * @brief This section provide a set of functions used to read and
+ * write a generic register of the device.
+ * MANDATORY: return 0 -> no Error.
+ * @{
+ *
+ */
-typedef int32_t (*lis2mdl_write_ptr)(void *, uint8_t, uint8_t*, uint16_t);
-typedef int32_t (*lis2mdl_read_ptr) (void *, uint8_t, uint8_t*, uint16_t);
+typedef int32_t (*lis2mdl_write_ptr)(void *, uint8_t, uint8_t *, uint16_t);
+typedef int32_t (*lis2mdl_read_ptr)(void *, uint8_t, uint8_t *, uint16_t);
typedef struct {
- /** Component mandatory fields **/
- lis2mdl_write_ptr write_reg;
- lis2mdl_read_ptr read_reg;
- /** Customizable optional pointer **/
- void *handle;
+ /** Component mandatory fields **/
+ lis2mdl_write_ptr write_reg;
+ lis2mdl_read_ptr read_reg;
+ /** Customizable optional pointer **/
+ void *handle;
} lis2mdl_ctx_t;
/**
@@ -151,7 +151,7 @@
*
*/
- /** I2C Device Address 8 bit format **/
+/** I2C Device Address 8 bit format **/
#define LIS2MDL_I2C_ADD 0x3DU
/** Device Identification (Who am I) **/
@@ -171,70 +171,70 @@
#define LIS2MDL_WHO_AM_I 0x4FU
#define LIS2MDL_CFG_REG_A 0x60U
typedef struct {
- uint8_t md : 2;
- uint8_t odr : 2;
- uint8_t lp : 1;
- uint8_t soft_rst : 1;
- uint8_t reboot : 1;
- uint8_t comp_temp_en : 1;
+ uint8_t md : 2;
+ uint8_t odr : 2;
+ uint8_t lp : 1;
+ uint8_t soft_rst : 1;
+ uint8_t reboot : 1;
+ uint8_t comp_temp_en : 1;
} lis2mdl_cfg_reg_a_t;
#define LIS2MDL_CFG_REG_B 0x61U
typedef struct {
- uint8_t lpf : 1;
- uint8_t set_rst : 2; /* OFF_CANC + Set_FREQ */
- uint8_t int_on_dataoff : 1;
- uint8_t off_canc_one_shot : 1;
- uint8_t not_used_01 : 3;
+ uint8_t lpf : 1;
+ uint8_t set_rst : 2; /* OFF_CANC + Set_FREQ */
+ uint8_t int_on_dataoff : 1;
+ uint8_t off_canc_one_shot : 1;
+ uint8_t not_used_01 : 3;
} lis2mdl_cfg_reg_b_t;
#define LIS2MDL_CFG_REG_C 0x62U
typedef struct {
- uint8_t drdy_on_pin : 1;
- uint8_t self_test : 1;
- uint8_t not_used_01 : 1;
- uint8_t ble : 1;
- uint8_t bdu : 1;
- uint8_t i2c_dis : 1;
- uint8_t int_on_pin : 1;
- uint8_t not_used_02 : 1;
+ uint8_t drdy_on_pin : 1;
+ uint8_t self_test : 1;
+ uint8_t not_used_01 : 1;
+ uint8_t ble : 1;
+ uint8_t bdu : 1;
+ uint8_t i2c_dis : 1;
+ uint8_t int_on_pin : 1;
+ uint8_t not_used_02 : 1;
} lis2mdl_cfg_reg_c_t;
#define LIS2MDL_INT_CRTL_REG 0x63U
typedef struct {
- uint8_t ien : 1;
- uint8_t iel : 1;
- uint8_t iea : 1;
- uint8_t not_used_01 : 2;
- uint8_t zien : 1;
- uint8_t yien : 1;
- uint8_t xien : 1;
+ uint8_t ien : 1;
+ uint8_t iel : 1;
+ uint8_t iea : 1;
+ uint8_t not_used_01 : 2;
+ uint8_t zien : 1;
+ uint8_t yien : 1;
+ uint8_t xien : 1;
} lis2mdl_int_crtl_reg_t;
#define LIS2MDL_INT_SOURCE_REG 0x64U
typedef struct {
- uint8_t _int : 1;
- uint8_t mroi : 1;
- uint8_t n_th_s_z : 1;
- uint8_t n_th_s_y : 1;
- uint8_t n_th_s_x : 1;
- uint8_t p_th_s_z : 1;
- uint8_t p_th_s_y : 1;
- uint8_t p_th_s_x : 1;
+ uint8_t _int : 1;
+ uint8_t mroi : 1;
+ uint8_t n_th_s_z : 1;
+ uint8_t n_th_s_y : 1;
+ uint8_t n_th_s_x : 1;
+ uint8_t p_th_s_z : 1;
+ uint8_t p_th_s_y : 1;
+ uint8_t p_th_s_x : 1;
} lis2mdl_int_source_reg_t;
#define LIS2MDL_INT_THS_L_REG 0x65U
#define LIS2MDL_INT_THS_H_REG 0x66U
#define LIS2MDL_STATUS_REG 0x67U
typedef struct {
- uint8_t xda : 1;
- uint8_t yda : 1;
- uint8_t zda : 1;
- uint8_t zyxda : 1;
- uint8_t xior : 1; //changed as xor is a reserved word in c++
- uint8_t yor : 1;
- uint8_t zor : 1;
- uint8_t zyxor : 1;
+ uint8_t xda : 1;
+ uint8_t yda : 1;
+ uint8_t zda : 1;
+ uint8_t zyxda : 1;
+ uint8_t xior : 1; //changed as xor is a reserved word in c++
+ uint8_t yor : 1;
+ uint8_t zor : 1;
+ uint8_t zyxor : 1;
} lis2mdl_status_reg_t;
#define LIS2MDL_OUTX_L_REG 0x68U
@@ -258,15 +258,15 @@
* @{
*
*/
-typedef union{
- lis2mdl_cfg_reg_a_t cfg_reg_a;
- lis2mdl_cfg_reg_b_t cfg_reg_b;
- lis2mdl_cfg_reg_c_t cfg_reg_c;
- lis2mdl_int_crtl_reg_t int_crtl_reg;
- lis2mdl_int_source_reg_t int_source_reg;
- lis2mdl_status_reg_t status_reg;
- bitwise_t bitwise;
- uint8_t byte;
+typedef union {
+ lis2mdl_cfg_reg_a_t cfg_reg_a;
+ lis2mdl_cfg_reg_b_t cfg_reg_b;
+ lis2mdl_cfg_reg_c_t cfg_reg_c;
+ lis2mdl_int_crtl_reg_t int_crtl_reg;
+ lis2mdl_int_source_reg_t int_source_reg;
+ lis2mdl_status_reg_t status_reg;
+ bitwise_t bitwise;
+ uint8_t byte;
} lis2mdl_reg_t;
/**
@@ -274,11 +274,11 @@
*
*/
-int32_t lis2mdl_read_reg(lis2mdl_ctx_t *ctx, uint8_t reg, uint8_t* data,
+int32_t lis2mdl_read_reg(lis2mdl_ctx_t *ctx, uint8_t reg, uint8_t *data,
uint16_t len);
-int32_t lis2mdl_write_reg(lis2mdl_ctx_t *ctx, uint8_t reg, uint8_t* data,
+int32_t lis2mdl_write_reg(lis2mdl_ctx_t *ctx, uint8_t reg, uint8_t *data,
uint16_t len);
-
+
extern float_t lis2mdl_from_lsb_to_mgauss(int16_t lsb);
extern float_t lis2mdl_from_lsb_to_celsius(int16_t lsb);
@@ -286,25 +286,25 @@
int32_t lis2mdl_mag_user_offset_get(lis2mdl_ctx_t *ctx, uint8_t *buff);
typedef enum {
- LIS2MDL_CONTINUOUS_MODE = 0,
- LIS2MDL_SINGLE_TRIGGER = 1,
- LIS2MDL_POWER_DOWN = 2,
+ LIS2MDL_CONTINUOUS_MODE = 0,
+ LIS2MDL_SINGLE_TRIGGER = 1,
+ LIS2MDL_POWER_DOWN = 2,
} lis2mdl_md_t;
int32_t lis2mdl_operating_mode_set(lis2mdl_ctx_t *ctx, lis2mdl_md_t val);
int32_t lis2mdl_operating_mode_get(lis2mdl_ctx_t *ctx, lis2mdl_md_t *val);
typedef enum {
- LIS2MDL_ODR_10Hz = 0,
- LIS2MDL_ODR_20Hz = 1,
- LIS2MDL_ODR_50Hz = 2,
- LIS2MDL_ODR_100Hz = 3,
+ LIS2MDL_ODR_10Hz = 0,
+ LIS2MDL_ODR_20Hz = 1,
+ LIS2MDL_ODR_50Hz = 2,
+ LIS2MDL_ODR_100Hz = 3,
} lis2mdl_odr_t;
int32_t lis2mdl_data_rate_set(lis2mdl_ctx_t *ctx, lis2mdl_odr_t val);
int32_t lis2mdl_data_rate_get(lis2mdl_ctx_t *ctx, lis2mdl_odr_t *val);
typedef enum {
- LIS2MDL_HIGH_RESOLUTION = 0,
- LIS2MDL_LOW_POWER = 1,
+ LIS2MDL_HIGH_RESOLUTION = 0,
+ LIS2MDL_LOW_POWER = 1,
} lis2mdl_lp_t;
int32_t lis2mdl_power_mode_set(lis2mdl_ctx_t *ctx, lis2mdl_lp_t val);
int32_t lis2mdl_power_mode_get(lis2mdl_ctx_t *ctx, lis2mdl_lp_t *val);
@@ -313,8 +313,8 @@
int32_t lis2mdl_offset_temp_comp_get(lis2mdl_ctx_t *ctx, uint8_t *val);
typedef enum {
- LIS2MDL_ODR_DIV_2 = 0,
- LIS2MDL_ODR_DIV_4 = 1,
+ LIS2MDL_ODR_DIV_2 = 0,
+ LIS2MDL_ODR_DIV_4 = 1,
} lis2mdl_lpf_t;
int32_t lis2mdl_low_pass_bandwidth_set(lis2mdl_ctx_t *ctx,
lis2mdl_lpf_t val);
@@ -322,9 +322,9 @@
lis2mdl_lpf_t *val);
typedef enum {
- LIS2MDL_SET_SENS_ODR_DIV_63 = 0,
- LIS2MDL_SENS_OFF_CANC_EVERY_ODR = 1,
- LIS2MDL_SET_SENS_ONLY_AT_POWER_ON = 2,
+ LIS2MDL_SET_SENS_ODR_DIV_63 = 0,
+ LIS2MDL_SENS_OFF_CANC_EVERY_ODR = 1,
+ LIS2MDL_SET_SENS_ONLY_AT_POWER_ON = 2,
} lis2mdl_set_rst_t;
int32_t lis2mdl_set_rst_mode_set(lis2mdl_ctx_t *ctx,
lis2mdl_set_rst_t val);
@@ -359,8 +359,8 @@
int32_t lis2mdl_self_test_get(lis2mdl_ctx_t *ctx, uint8_t *val);
typedef enum {
- LIS2MDL_LSB_AT_LOW_ADD = 0,
- LIS2MDL_MSB_AT_LOW_ADD = 1,
+ LIS2MDL_LSB_AT_LOW_ADD = 0,
+ LIS2MDL_MSB_AT_LOW_ADD = 1,
} lis2mdl_ble_t;
int32_t lis2mdl_data_format_set(lis2mdl_ctx_t *ctx, lis2mdl_ble_t val);
int32_t lis2mdl_data_format_get(lis2mdl_ctx_t *ctx, lis2mdl_ble_t *val);
@@ -368,8 +368,8 @@
int32_t lis2mdl_status_get(lis2mdl_ctx_t *ctx, lis2mdl_status_reg_t *val);
typedef enum {
- LIS2MDL_CHECK_BEFORE = 0,
- LIS2MDL_CHECK_AFTER = 1,
+ LIS2MDL_CHECK_BEFORE = 0,
+ LIS2MDL_CHECK_AFTER = 1,
} lis2mdl_int_on_dataoff_t;
int32_t lis2mdl_offset_int_conf_set(lis2mdl_ctx_t *ctx,
lis2mdl_int_on_dataoff_t val);
@@ -394,8 +394,8 @@
int32_t lis2mdl_int_gen_treshold_get(lis2mdl_ctx_t *ctx, uint8_t *buff);
typedef enum {
- LIS2MDL_I2C_ENABLE = 0,
- LIS2MDL_I2C_DISABLE = 1,
+ LIS2MDL_I2C_ENABLE = 0,
+ LIS2MDL_I2C_DISABLE = 1,
} lis2mdl_i2c_dis_t;
int32_t lis2mdl_i2c_interface_set(lis2mdl_ctx_t *ctx,
lis2mdl_i2c_dis_t val);