ST / LSM6DSL

Dependencies:   X_NUCLEO_COMMON ST_INTERFACES

Dependents:   HelloWorld_ST_Sensors MOTENV_Mbed mbed-os-mqtt-client LSM6DSL_JS ... more

Files at this revision

API Documentation at this revision

Comitter:
mapellil
Date:
Wed Sep 27 16:50:11 2017 +0200
Parent:
0:704c89673b57
Child:
2:578a45c4dad5
Commit message:
Fixed NonCopyable

Changed in this revision

LSM6DSLSensor.cpp Show annotated file Show diff for this revision Revisions of this file
LSM6DSLSensor.h Show annotated file Show diff for this revision Revisions of this file
--- a/LSM6DSLSensor.cpp	Mon Sep 04 16:08:00 2017 +0000
+++ b/LSM6DSLSensor.cpp	Wed Sep 27 16:50:11 2017 +0200
@@ -48,18 +48,10 @@
  * @param i2c object of an helper class which handles the I2C peripheral
  * @param address the address of the component's instance
  */
-LSM6DSLSensor::LSM6DSLSensor(DevI2C &i2c, PinName int1_pin, PinName int2_pin) : _dev_i2c(i2c), _int1_irq(int1_pin), _int2_irq(int2_pin)
+LSM6DSLSensor::LSM6DSLSensor(DevI2C *i2c, uint8_t address, PinName int1_pin, PinName int2_pin) :
+                             _dev_i2c(i2c), _address(address), _cs_pin(NC), _int1_irq(int1_pin), _int2_irq(int2_pin)
 {
-  _address = LSM6DSL_ACC_GYRO_I2C_ADDRESS_HIGH; 
-};
-
-/** Constructor
- * @param i2c object of an helper class which handles the I2C peripheral
- * @param address the address of the component's instance
- */
-LSM6DSLSensor::LSM6DSLSensor(DevI2C &i2c, PinName int1_pin, PinName int2_pin, uint8_t address) : _dev_i2c(i2c), _int1_irq(int1_pin), _int2_irq(int2_pin), _address(address)
-{
-
+    assert (i2c);
 };
 
 /**
--- a/LSM6DSLSensor.h	Mon Sep 04 16:08:00 2017 +0000
+++ b/LSM6DSLSensor.h	Wed Sep 27 16:50:11 2017 +0200
@@ -49,6 +49,7 @@
 #include "LSM6DSL_acc_gyro_driver.h"
 #include "MotionSensor.h"
 #include "GyroSensor.h"
+#include <assert.h>
 
 /* Defines -------------------------------------------------------------------*/
 
@@ -125,8 +126,7 @@
 class LSM6DSLSensor : public MotionSensor, public GyroSensor
 {
   public:
-    LSM6DSLSensor(DevI2C &i2c, PinName INT1_pin, PinName INT2_pin);
-    LSM6DSLSensor(DevI2C &i2c, PinName INT1_pin, PinName INT2_pin, uint8_t address);
+    LSM6DSLSensor(DevI2C *i2c, uint8_t address=LSM6DSL_ACC_GYRO_I2C_ADDRESS_HIGH, 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 *pData);
@@ -249,7 +249,7 @@
      */
     uint8_t io_read(uint8_t* pBuffer, uint8_t RegisterAddr, uint16_t NumByteToRead)
     {
-        return (uint8_t) _dev_i2c.i2c_read(pBuffer, _address, RegisterAddr, NumByteToRead);
+        return (uint8_t) _dev_i2c->i2c_read(pBuffer, _address, RegisterAddr, NumByteToRead);
     }
     
     /**
@@ -261,7 +261,7 @@
      */
     uint8_t io_write(uint8_t* pBuffer, uint8_t RegisterAddr, uint16_t NumByteToWrite)
     {
-        return (uint8_t) _dev_i2c.i2c_write(pBuffer, _address, RegisterAddr, NumByteToWrite);
+        return (uint8_t) _dev_i2c->i2c_write(pBuffer, _address, RegisterAddr, NumByteToWrite);
     }
 
   private:
@@ -271,13 +271,13 @@
     int set_g_odr_when_disabled(float odr);
 
     /* Helper classes. */
-    DevI2C &_dev_i2c;
-
-    InterruptIn _int1_irq;
-    InterruptIn _int2_irq;
+    DevI2C *_dev_i2c;
 
     /* Configuration */
     uint8_t _address;
+    DigitalOut  _cs_pin;        
+    InterruptIn _int1_irq;
+    InterruptIn _int2_irq;
     
     uint8_t _x_is_enabled;
     float _x_last_odr;