summaryrefslogtreecommitdiff
path: root/peripheral/libupm/src/bmx055/bmc150.hpp
blob: c570af011b99f3e501d55245ac3df982743c8f4e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
/*
 * Author: Jon Trulson <jtrulson@ics.com>
 * Copyright (c) 2016 Intel Corporation.
 *
 * 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.
 */
#pragma once

#include <string>

#include "bma250e.hpp"
#include "bmm150.hpp"

#define BMC150_DEFAULT_BUS 0
#define BMC150_DEFAULT_ACC_ADDR 0x10
#define BMC150_DEFAULT_MAG_ADDR 0x12

namespace upm {

  /**
   * @library bmx055
   * @sensor bmc150
   * @comname BMC150 6-axis eCompass
   * @type accelerometer compass
   * @man mouser
   * @con i2c gpio spi
   * @web http://www.mouser.com/ProductDetail/Bosch-Sensortec/0330SB0156/?qs=sGAEpiMZZMsrChSOYEGTCd8nwjostN1SWavW0HYOOXw%3d
   *
   * @brief API for the BMC150 6-axis eCompass
   *
   *
   * The BMC150 is an integrated electronic compass solution for
   * consumer market applications. It comprises a 12bit leading edge
   * triaxial, low-g acceleration sensor and an ultra-low power, high
   * precision triaxial magnetic field sensor. It allows measurements
   * of acceleration and magnetic field in three perpendicular
   * axes. Performance and features of both sensing technologies are
   * carefully tuned and perfectly match the demanding requirements of
   * all 6-axis mobile applications such as electronic compass,
   * navigation or augmented reality.

   * The BMC150 is essentially 2 separate devices in one: the BMA250E
   * Accelerometer and the BMM150 Magnetometer.  They are completely
   * independant of each other.
   *
   * This driver provides a very simple interface to these 2 devices.
   * If finer control is desired, you should just use the separate
   * BMA25E and BMM150 device classes directly.  This driver simply
   * initializes both devices, and provides a mechanism to read
   * accelerometer and magnetometer data from them.
   *
   * @snippet bmc150.cxx Interesting
   */

  class BMC150 {
  public:
    /**
     * BMC150 constructor.
     *
     * This device can support both I2C and SPI. For SPI, set the addr
     * to -1, and specify a positive integer representing the Chip
     * Select (CS) pin for the cs argument.  If you are using a
     * hardware CS pin (like edison with arduino breakout), then you
     * can connect the proper pin to the hardware CS pin on your MCU
     * and supply -1 for cs.  The default operating mode is I2C.
     *
     * @param accelBus I2C or SPI bus to use. -1 to skip initializing
     * this device.
     * @param accelAddr The address for this device.  -1 for SPI.
     * @param accelCS The gpio pin to use for the SPI Chip Select.  -1 for
     * I2C or for SPI with a hardware controlled pin.
     * @param magBus I2C or SPI bus to use. -1 to skip initializing
     * this device.
     * @param magAddr The address for this device.  -1 for SPI.
     * @param magCS The gpio pin to use for the SPI Chip Select.  -1 for
     * I2C or for SPI with a hardware controlled pin.
     */
    BMC150(int accelBus=BMC150_DEFAULT_BUS,
           uint8_t accelAddr=BMC150_DEFAULT_ACC_ADDR,
           int accelCS=-1,
           int magBus=BMC150_DEFAULT_BUS,
           uint8_t magAddr=BMC150_DEFAULT_MAG_ADDR,
           int magCS=-1);

    /**
     * BMC150 Destructor.
     */
    ~BMC150();

    /**
     * Update the internal stored values from sensor data.
     */
    void update();

    /**
     * Initialize the accelerometer and start operation.  This
     * function is called from the constructor so will not typically
     * need to be called by a user unless the device is reset or you
     * want to change these values.
     *
     * @param pwr One of the BMA250E::POWER_MODE_T values.  The default is
     * BMA250E::POWER_MODE_NORMAL.
     * @param range One of the BMA250E::RANGE_T values.  The default is
     * BMA250E::RANGE_2G.
     * @param bw One of the filtering BMA250E::BW_T values.  The default is
     * BMA250E::BW_250.
     */
    void initAccelerometer(BMA250E::POWER_MODE_T pwr=BMA250E::POWER_MODE_NORMAL,
                           BMA250E::RANGE_T range=BMA250E::RANGE_2G,
                           BMA250E::BW_T bw=BMA250E::BW_250);

    /**
     * Initialize the magnetometer and start operation.  This function
     * is called from the constructor so will not typically need to be
     * called by a user unless the device is reset or you want to
     * change these values.  This method will call
     * BMM150::setPresetMode() with the passed parameter.
     *
     * @param usage One of the BMM150::USAGE_PRESETS_T values.  The default is
     * BMM150::USAGE_HIGH_ACCURACY.
     */
    void initMagnetometer(BMM150::USAGE_PRESETS_T usage=BMM150::USAGE_HIGH_ACCURACY);

    /**
     * Return accelerometer data in gravities.  update() must have
     * been called prior to calling this method.
     *
     * @param x Pointer to a floating point value that will have the
     * current x component placed into it.
     * @param y Pointer to a floating point value that will have the
     * current y component placed into it.
     * @param z Pointer to a floating point value that will have the
     * current z component placed into it.
     */
    void getAccelerometer(float *x, float *y, float *z);

    /**
     * Return accelerometer data in gravities in the form of a
     * floating point array.  The pointer returned by this function is
     * statically allocated and will be rewritten on each call.
     * update() must have been called prior to calling this method.
     *
     * @return A floating point array containing x, y, and z in
     * that order.
     */
    float *getAccelerometer();

    /**
     * Return magnetometer data in micro-Teslas (uT).  update() must
     * have been called prior to calling this method.
     *
     * @param x Pointer to a floating point value that will have the
     * current x component placed into it.
     * @param y Pointer to a floating point value that will have the
     * current y component placed into it.
     * @param z Pointer to a floating point value that will have the
     * current z component placed into it.
     */
    void getMagnetometer(float *x, float *y, float *z);

    /**
     * Return magnetometer data in micro-Teslas (uT) in the form of a
     * floating point array.  The pointer returned by this function is
     * statically allocated and will be rewritten on each call.
     * update() must have been called prior to calling this method.
     *
     * @return A floating point array containing x, y, and z in
     * that order.
     */
    float *getMagnetometer();


  protected:
    BMA250E *m_accel;
    BMM150 *m_mag;

  private:
  };
}