iNEMO inertial module: 3D accelerometer and 3D gyroscope.
Dependencies: X_NUCLEO_COMMON ST_INTERFACES
Dependents: X_NUCLEO_IKS01A3 X_NUCLEO_IKS01A3
Diff: LSM6DSOSensor.h
- Revision:
- 3:4274d9103f1d
- Parent:
- 1:888ac5f8d970
- Child:
- 4:77faf76e3cd8
diff -r 4d14e9edf37e -r 4274d9103f1d LSM6DSOSensor.h
--- a/LSM6DSOSensor.h Mon Jun 03 09:16:08 2019 +0000
+++ b/LSM6DSOSensor.h Wed Jul 24 14:19:35 2019 +0000
@@ -66,37 +66,34 @@
/* Typedefs ------------------------------------------------------------------*/
-typedef enum
-{
- LSM6DSO_INT1_PIN,
- LSM6DSO_INT2_PIN,
+typedef enum {
+ LSM6DSO_INT1_PIN,
+ LSM6DSO_INT2_PIN,
} LSM6DSO_Interrupt_Pin_t;
-typedef struct
-{
- unsigned int FreeFallStatus : 1;
- unsigned int TapStatus : 1;
- unsigned int DoubleTapStatus : 1;
- unsigned int WakeUpStatus : 1;
- unsigned int StepStatus : 1;
- unsigned int TiltStatus : 1;
- unsigned int D6DOrientationStatus : 1;
- unsigned int SleepStatus : 1;
+typedef struct {
+ unsigned int FreeFallStatus : 1;
+ unsigned int TapStatus : 1;
+ unsigned int DoubleTapStatus : 1;
+ unsigned int WakeUpStatus : 1;
+ unsigned int StepStatus : 1;
+ unsigned int TiltStatus : 1;
+ unsigned int D6DOrientationStatus : 1;
+ unsigned int SleepStatus : 1;
} LSM6DSO_Event_Status_t;
/* Class Declaration ---------------------------------------------------------*/
-
+
/**
* Abstract class of an LSM6DSO Inertial Measurement Unit (IMU) 6 axes
* sensor.
*/
-class LSM6DSOSensor : public MotionSensor, public GyroSensor
-{
- public:
+class LSM6DSOSensor : public MotionSensor, public GyroSensor {
+public:
enum SPI_type_t {SPI3W, SPI4W};
- LSM6DSOSensor(SPI *spi, PinName cs_pin, PinName int1_pin=NC, PinName int2_pin=NC, SPI_type_t spi_type=SPI4W);
- LSM6DSOSensor(DevI2C *i2c, uint8_t address=LSM6DSO_I2C_ADD_H, PinName int1_pin=NC, PinName int2_pin=NC);
+ LSM6DSOSensor(SPI *spi, PinName cs_pin, PinName int1_pin = NC, PinName int2_pin = NC, SPI_type_t spi_type = SPI4W);
+ LSM6DSOSensor(DevI2C *i2c, uint8_t address = LSM6DSO_I2C_ADD_H, PinName int1_pin = NC, PinName int2_pin = NC);
virtual int init(void *init);
virtual int read_id(uint8_t *id);
virtual int get_x_axes(int32_t *acceleration);
@@ -168,7 +165,7 @@
int set_fifo_x_bdr(float bdr);
int get_fifo_g_axes(int32_t *angular_velocity);
int set_fifo_g_bdr(float bdr);
-
+
/**
* @brief Attaching an interrupt handler to the INT1 interrupt.
* @param fptr An interrupt handler.
@@ -188,7 +185,7 @@
{
_int1_irq.enable_irq();
}
-
+
/**
* @brief Disabling the INT1 interrupt handling.
* @param None.
@@ -198,7 +195,7 @@
{
_int1_irq.disable_irq();
}
-
+
/**
* @brief Attaching an interrupt handler to the INT2 interrupt.
* @param fptr An interrupt handler.
@@ -218,7 +215,7 @@
{
_int2_irq.enable_irq();
}
-
+
/**
* @brief Disabling the INT2 interrupt handling.
* @param None.
@@ -228,7 +225,7 @@
{
_int2_irq.disable_irq();
}
-
+
/**
* @brief Utility function to read data.
* @param pBuffer: pointer to data to be read.
@@ -236,30 +233,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.
@@ -267,22 +266,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:
int set_x_odr_when_enabled(float odr);
int set_g_odr_when_enabled(float odr);
int set_x_odr_when_disabled(float odr);
@@ -294,11 +295,11 @@
/* Configuration */
uint8_t _address;
- DigitalOut _cs_pin;
+ DigitalOut _cs_pin;
InterruptIn _int1_irq;
InterruptIn _int2_irq;
SPI_type_t _spi_type;
-
+
uint8_t _x_is_enabled;
lsm6dso_odr_xl_t _x_last_odr;
uint8_t _g_is_enabled;
@@ -308,12 +309,12 @@
};
#ifdef __cplusplus
- extern "C" {
+extern "C" {
#endif
-int32_t LSM6DSO_io_write( void *handle, uint8_t WriteAddr, uint8_t *pBuffer, uint16_t nBytesToWrite );
-int32_t LSM6DSO_io_read( void *handle, uint8_t ReadAddr, uint8_t *pBuffer, uint16_t nBytesToRead );
+int32_t LSM6DSO_io_write(void *handle, uint8_t WriteAddr, uint8_t *pBuffer, uint16_t nBytesToWrite);
+int32_t LSM6DSO_io_read(void *handle, uint8_t ReadAddr, uint8_t *pBuffer, uint16_t nBytesToRead);
#ifdef __cplusplus
- }
+}
#endif
#endif