Kionix KX123 accelerometer C++ driver. Can be used for some extend also with kx022, kx023, kx122, etc. when used features are present in sensor.

Dependents:   kionix-kx123-hello

Committer:
MikkoZ
Date:
Thu Sep 29 15:05:08 2016 +0000
Revision:
0:a3f43eb92f86
Child:
1:f328083fb80b
Kionix KX123 minimal C++ driver. Initial version. Uses RegisterWriter library.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
MikkoZ 0:a3f43eb92f86 1 /* Copyright 2016 Rohm Semiconductor
MikkoZ 0:a3f43eb92f86 2
MikkoZ 0:a3f43eb92f86 3 Licensed under the Apache License, Version 2.0 (the "License");
MikkoZ 0:a3f43eb92f86 4 you may not use this file except in compliance with the License.
MikkoZ 0:a3f43eb92f86 5 You may obtain a copy of the License at
MikkoZ 0:a3f43eb92f86 6
MikkoZ 0:a3f43eb92f86 7 http://www.apache.org/licenses/LICENSE-2.0
MikkoZ 0:a3f43eb92f86 8
MikkoZ 0:a3f43eb92f86 9 Unless required by applicable law or agreed to in writing, software
MikkoZ 0:a3f43eb92f86 10 distributed under the License is distributed on an "AS IS" BASIS,
MikkoZ 0:a3f43eb92f86 11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
MikkoZ 0:a3f43eb92f86 12 See the License for the specific language governing permissions and
MikkoZ 0:a3f43eb92f86 13 limitations under the License.
MikkoZ 0:a3f43eb92f86 14 */
MikkoZ 0:a3f43eb92f86 15 #ifndef KX123_H
MikkoZ 0:a3f43eb92f86 16 #define KX123_H
MikkoZ 0:a3f43eb92f86 17
MikkoZ 0:a3f43eb92f86 18 //#include "mbed.h" //types
MikkoZ 0:a3f43eb92f86 19 #include "I2C.h" //I2C
MikkoZ 0:a3f43eb92f86 20
MikkoZ 0:a3f43eb92f86 21 #include "RegisterWriter/RegisterWriter/rohm_hal2.h"
MikkoZ 0:a3f43eb92f86 22 #include "RegisterWriter/RegisterWriter/RegisterWriter.h"
MikkoZ 0:a3f43eb92f86 23
MikkoZ 0:a3f43eb92f86 24
MikkoZ 0:a3f43eb92f86 25 /**
MikkoZ 0:a3f43eb92f86 26 * KX123 accelerometer driver
MikkoZ 0:a3f43eb92f86 27 */
MikkoZ 0:a3f43eb92f86 28 class KX123
MikkoZ 0:a3f43eb92f86 29 {
MikkoZ 0:a3f43eb92f86 30 public:
MikkoZ 0:a3f43eb92f86 31 /**
MikkoZ 0:a3f43eb92f86 32 * Create a KX123 instance which is connected to pre-instantiated I2C object.
MikkoZ 0:a3f43eb92f86 33 *
MikkoZ 0:a3f43eb92f86 34 * @param sad slave address of sensor.
MikkoZ 0:a3f43eb92f86 35 * @param wai who_am_i value (i.e. sensor type/model)
MikkoZ 0:a3f43eb92f86 36 */
MikkoZ 0:a3f43eb92f86 37 KX123(RegisterWriter &i2c_obj, uint8_t sad = KX123_DEFAULT_SLAVE_ADDRESS, uint8_t wai = KX123_WHO_AM_I_WAI_ID);
MikkoZ 0:a3f43eb92f86 38
MikkoZ 0:a3f43eb92f86 39 /**
MikkoZ 0:a3f43eb92f86 40 * KX123 destructor
MikkoZ 0:a3f43eb92f86 41 */
MikkoZ 0:a3f43eb92f86 42 ~KX123();
MikkoZ 0:a3f43eb92f86 43
MikkoZ 0:a3f43eb92f86 44 /**
MikkoZ 0:a3f43eb92f86 45 * Probe and setup kx123 (or other accelerometer from same family)
MikkoZ 0:a3f43eb92f86 46 */
MikkoZ 0:a3f43eb92f86 47 bool set_defaults(void);
MikkoZ 0:a3f43eb92f86 48 /**
MikkoZ 0:a3f43eb92f86 49 * Get results in raw value
MikkoZ 0:a3f43eb92f86 50 */
MikkoZ 0:a3f43eb92f86 51 bool getresults_raw(int16_t* buf);
MikkoZ 0:a3f43eb92f86 52 /**
MikkoZ 0:a3f43eb92f86 53 * Get results in 1G-values
MikkoZ 0:a3f43eb92f86 54 */
MikkoZ 0:a3f43eb92f86 55 bool getresults_g(float* buf);
MikkoZ 0:a3f43eb92f86 56
MikkoZ 0:a3f43eb92f86 57
MikkoZ 0:a3f43eb92f86 58 private:
MikkoZ 0:a3f43eb92f86 59 void set_tilt_position_defaults();
MikkoZ 0:a3f43eb92f86 60
MikkoZ 0:a3f43eb92f86 61 RegisterWriter i2c_rw;
MikkoZ 0:a3f43eb92f86 62 uint16_t resolution_divider;
MikkoZ 0:a3f43eb92f86 63 uint8_t sad;
MikkoZ 0:a3f43eb92f86 64 uint8_t wai;
MikkoZ 0:a3f43eb92f86 65 };
MikkoZ 0:a3f43eb92f86 66
MikkoZ 0:a3f43eb92f86 67 #endif