My attempt to made a more useful lib. You can get the accelerator and magnetometer.

Fork of LSM303DLH by Michael Shimniok

Revision:
5:48722ae56546
Parent:
4:4f2ed3f8726c
Child:
6:86cf2afe3e52
--- a/LSM303DLH.h	Sun Aug 06 03:19:17 2017 +0000
+++ b/LSM303DLH.h	Sun Aug 06 19:11:23 2017 +0000
@@ -2,43 +2,15 @@
 #include "vector.h"
 #include "AnsiGraphicalConsole.h"
 
+#include "LSM303DLH_RegisterDef.h"
+
 #ifndef M_PI
 #define M_PI 3.14159265358979323846
 #endif
 
 /** Tilt-compensated compass interface Library for the STMicro LSM303DLH 3-axis magnetometer, 3-axis acceleromter
  *
- * Michael Shimniok http://bot-thoughts.com
- *
- * Based on test program by @tosihisa and 
- *
- * Pololu sample library for LSM303DLH breakout by ryantm:
- *
- * Copyright (c) 2011 Pololu Corporation. For more information, see
- *
- * http://www.pololu.com/
- * http://forum.pololu.com/
- *
- * Permission is hereby granted, free of charge, to any person
- * obtaining a copy of this software and associated documentation
- * files (the "Software"), to deal in the Software without
- * restriction, including without limitation the rights to use,
- * copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following
- * conditions:
- *
- * The above copyright notice and this permission notice shall be
- * included in all copies or substantial portions of the Software.
- * 
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
- * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
- * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
+ * @author Salco <JeSuisSalco@gmail.com>
  *
  * @code
  * #include "mbed.h"
@@ -71,6 +43,10 @@
          * @param scl is the pin for the I2C SCL line
          */
         LSM303DLH(PinName sda, PinName scl);
+        /** Create a new interface for an LSM303DLH
+         *
+         * @param ptrI2C is a pointer from existing I2C
+         */
         LSM303DLH(I2C* ptrI2C);
         /** sets the x, y, and z offset corrections for hard iron calibration
          * 
@@ -121,67 +97,26 @@
          * @param frequency is the I2C bus/clock frequency, either standard (100000) or fast (400000)
          */
         void frequency(int hz);
-    
-    
-        /** @defgroup regA Register 
-         *  Register for accelerometer
-         *  @{
-         */
-        
-        #if defined(DOXYGEN_ONLY)
-        /** CTRL_REG1_A structure definition
-         */ 
-        union LSM303DLH::Ctrl_Reg1_A_t  {      
-        
-        #else
-        union Ctrl_Reg1_A_t {
-        #endif
-        
-        
-            uint8_t byte; /**< Value in byte.*/
-            
-            struct{
-                uint8_t Xen:1; /**< X axis enable. Default value: 1. */
-                uint8_t Yen:1; /**< Y axis enable. Default value: 1. */
-                uint8_t Zen:1; /**< Z axis enable. Default value: 1. */
-                uint8_t LPen:1;/**< Low-power mode enable. Default value: 0. */
-                uint8_t ODR:4; /**< Data rate selection. Default value: 0. */
-            };    
+
+      private:
+        enum REG_ADDRS {
+            /* --- Mag --- */
+            CRA_REG_M   = 0x00,
+            CRB_REG_M   = 0x01,
+            MR_REG_M    = 0x02,
+            OUT_X_M     = 0x03,
+            OUT_Y_M     = 0x05,
+            OUT_Z_M     = 0x07,
+            SR_REG_M    = 0x09,
+            /* --- Acc --- */
+            CTRL_REG1_A = 0x20,
+            CTRL_REG4_A = 0x23,
+            STATUS_REG_A= 0x27,
+            OUT_X_A     = 0x28,
+            OUT_Y_A     = 0x2A,
+            OUT_Z_A     = 0x2C,
         };
         
-        #ifdef DOXYGEN_ONLY
-        /*! Another enum, with inline docs */
-        enum AnotherEnum 
-        { 
-          V1, /*!< value 1 */
-          V2  /*!< value 2 */
-        };
-        #endif
-        /**
-         * @brief Another enum, with inline docs 
-         * @var V1 value 1 
-         * @var V2 value 2 
-         */
-        struct Anotherstruct 
-        { 
-          V1; 
-          V2; 
-        };
-    
-        union Ctrl_Reg2_A_t
-        {
-            uint8_t byte;
-            struct{
-                uint8_t HPIS1:1;
-                uint8_t HPIS2:1;
-                uint8_t HPCLICK:1;
-                uint8_t FDS:1;
-                uint8_t HPCF:2;
-            };    
-        };
-       
-        /** @} */ // end of regA
-         private:
         I2C* m_ptr_I2C;//_compass;
         float _offset_x;
         float _offset_y;
@@ -194,7 +129,14 @@
         long _filt_az;
        
         void init(void) ;
+        
+        bool write_reg(int addr_i2c,int addr_reg, uint8_t v);
         bool write_reg(int addr_i2c,int addr_reg, char v);
+        
+        bool read_reg(int addr_i2c,int addr_reg, uint8_t *v);
         bool read_reg(int addr_i2c,int addr_reg, char *v);
+        
         bool read_reg_short(int addr_i2c,int addr_reg, short *v);
+        
+        int8_t get_FullScall_selection(void);
 };