summaryrefslogtreecommitdiff
path: root/peripheral/libupm/src/adis16448/adis16448.h
blob: 0159e4882d268a0e4b10b96285e7585061902d1a (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
//////////////////////////////////////////////////////////////////////////////////////
// The MIT License (MIT)
//
// Submit Date: 03/09/2015
// Author: Juan Jose Chong <juanjchong@gmail.com>
// Copyright (c) 2015 Juan Jose Chong
//
//////////////////////////////////////////////////////////////////////////////////////
// adis16448.h
//////////////////////////////////////////////////////////////////////////////////////
//
// This library runs on an Intel Edison and uses mraa to acquire data
// from an ADIS16448. This data is then scaled and printed onto the terminal.
//
// This software has been tested to connect to an ADIS16448 through a level shifter
// such as the TI TXB0104. The SPI lines (DIN, DOUT, SCLK, /CS) are all wired through
// the level shifter and the ADIS16448 is also being powered by the Intel Edison.
//
// 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.
//
//////////////////////////////////////////////////////////////////////////////////////
#include <string>
#include <mraa/spi.h>
#include <mraa/gpio.h>

// User Register Memory Map from Table 6 of the Datasheet
#define FLASH_CNT 0x00 //Flash memory write count
#define XGYRO_OUT 0x04 //X-axis gyroscope output
#define YGYRO_OUT 0x06 //Y-axis gyroscope output
#define ZGYRO_OUT 0x08 //Z-axis gyroscope output
#define XACCL_OUT 0x0A //X-axis accelerometer output
#define YACCL_OUT 0x0C //Y-axis accelerometer output
#define ZACCL_OUT 0x0E //Z-axis accelerometer output
#define XMAGN_OUT 0X10 //X-axis magnetometer output
#define YMAGN_OUT 0x12 //Y-axis magnetometer output
#define ZMAGN_OUT 0x14 //Z-axis magnetometer output
#define BARO_OUT 0x16 //Barometer pressure measurement, high word
#define TEMP_OUT 0x18 //Temperature output
#define XGYRO_OFF 0x1A //X-axis gyroscope bias offset factor
#define YGYRO_OFF 0x1C //Y-axis gyroscope bias offset factor
#define ZGYRO_OFF 0x1E //Z-axis gyroscope bias offset factor
#define XACCL_OFF 0x20 //X-axis acceleration bias offset factor
#define YACCL_OFF 0x22 //Y-axis acceleration bias offset factor
#define ZACCL_OFF 0x24 //Z-axis acceleration bias offset factor
#define XMAGN_HIC 0x26 //X-axis magnetometer, hard iron factor
#define YMAGN_HIC 0x28 //Y-axis magnetometer, hard iron factor
#define ZMAGN_HIC 0x2A //Z-axis magnetometer, hard iron factor
#define XMAGN_SIC 0x2C //X-axis magnetometer, soft iron factor
#define YMAGN_SIC 0x2E //Y-axis magnetometer, soft iron factor
#define ZMAGN_SIC 0x30 //Z-axis magnetometer, soft iron factor
#define GPIO_CTRL 0x32 //GPIO control
#define MSC_CTRL 0x34 //Misc. control
#define SMPL_PRD 0x36 //Sample clock/Decimation filter control
#define SENS_AVG 0x38 //Digital filter control
#define SEQ_CNT 0x3A //xMAGN_OUT and BARO_OUT counter
#define DIAG_STAT 0x3C //System status
#define GLOB_CMD 0x3E //System command
#define ALM_MAG1 0x40 //Alarm 1 amplitude threshold
#define ALM_MAG2 0x42 //Alarm 2 amplitude threshold
#define ALM_SMPL1 0x44 //Alarm 1 sample size
#define ALM_SMPL2 0x46 //Alarm 2 sample size
#define ALM_CTRL 0x48 //Alarm control
#define LOT_ID1 0x52 //Lot identification number
#define LOT_ID2 0x54 //Lot identification number
#define PROD_ID 0x56 //Product identifier
#define SERIAL_NUM 0x58 //Lot-specific serial number

namespace upm {
 /**
  * @brief ADIS16448 Accelerometer library
  * @defgroup adis16448 libupm-adis16448
  * @ingroup generic spi accelerometer
  */

 /**
  * @library adis16448
  * @sensor adis16448
  * @comname ADIS16448 Accelerometer
  * @type accelerometer
  * @man generic
  * @web http://www.analog.com/en/products/sensors/isensor-mems-inertial-measurement-units/adis16448.html
  * @con spi
  *
  * @brief API for the Analog Devices ADIS16448 Accelerometer
  *
  * This is an industrial-grade accelerometer by Analog Devices.
  *
  * @snippet adis16448.cxx Interesting
  */
    class ADIS16448{

        public:

        /**
         * Constructor with configurable HW Reset
         */
        ADIS16448(int bus, int rst);

        /**
         * Destructor
         */
        ~ADIS16448();

        /**
         * Performs hardware reset by sending the specified pin low for 2 seconds
         */
        void resetDUT();

        /**
         * Sets SPI frequency, mode, and bits/word
         */
        void configSPI();

        /**
         * Reads a specified register and returns data
         */
        int16_t regRead(uint8_t regAddr);

        /**
         * Writes to a specified register
         */
        void regWrite(uint8_t regAddr, uint16_t regData);

        /**
         * Scales accelerometer data
         */
        float accelScale(int16_t sensorData);

        /**
         * Scales gyro data
         */
        float gyroScale(int16_t sensorData);

        /**
         * Scales temperature data
         */
        float tempScale(int16_t sensorData);

        /**
         * Scales pressure data
         */
        float pressureScale(int16_t sensorData);

        /**
         * Scales magnetometer data
         */
        float magnetometerScale(int16_t sensorData);

        private:

        mraa_spi_context _spi;
        mraa_gpio_context _rst;

    };
}