Kionix KX123 accelerometer C++ driver. Can be used for some extend also with kx022, kx023, kx122, etc. when used features are present in sensor.
Fork of kionix-kx123-driver by
kx123.h@3:4fd5361ed180, 2016-10-06 (annotated)
- Committer:
- MikkoZ
- Date:
- Thu Oct 06 13:02:55 2016 +0000
- Revision:
- 3:4fd5361ed180
- Parent:
- 2:62891556d47b
Bugfix: get_results_highpass; ; Changed parameter from uint16_t to int16_t as it should be.
Who changed what in which revision?
User | Revision | Line number | New 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 "RegisterWriter/RegisterWriter/rohm_hal2.h" |
MikkoZ | 0:a3f43eb92f86 | 19 | #include "RegisterWriter/RegisterWriter/RegisterWriter.h" |
MikkoZ | 0:a3f43eb92f86 | 20 | |
MikkoZ | 1:f328083fb80b | 21 | #include "kx123_registers.h" |
MikkoZ | 0:a3f43eb92f86 | 22 | |
MikkoZ | 0:a3f43eb92f86 | 23 | /** |
MikkoZ | 1:f328083fb80b | 24 | * Kionix KX123 accelerometer i2c driver. For some extend can be used also with |
MikkoZ | 1:f328083fb80b | 25 | * kx012, kx022, kx023, kx23h, kx112, kx122, kx124, kx222 and kx224. Driver uses |
MikkoZ | 1:f328083fb80b | 26 | * RegisterWriter -class as (i2c) hardware abstraction layer. |
MikkoZ | 2:62891556d47b | 27 | * Note that when doing setup, sensor has to be in setup mode, not in operating mode. |
MikkoZ | 0:a3f43eb92f86 | 28 | */ |
MikkoZ | 0:a3f43eb92f86 | 29 | class KX123 |
MikkoZ | 0:a3f43eb92f86 | 30 | { |
MikkoZ | 0:a3f43eb92f86 | 31 | public: |
MikkoZ | 1:f328083fb80b | 32 | |
MikkoZ | 0:a3f43eb92f86 | 33 | KX123(RegisterWriter &i2c_obj, uint8_t sad = KX123_DEFAULT_SLAVE_ADDRESS, uint8_t wai = KX123_WHO_AM_I_WAI_ID); |
MikkoZ | 0:a3f43eb92f86 | 34 | ~KX123(); |
MikkoZ | 0:a3f43eb92f86 | 35 | |
MikkoZ | 2:62891556d47b | 36 | bool start_setup_mode(void); |
MikkoZ | 2:62891556d47b | 37 | bool start_measurement_mode(void); |
MikkoZ | 0:a3f43eb92f86 | 38 | bool set_defaults(void); |
MikkoZ | 3:4fd5361ed180 | 39 | bool getresults_highpass(int16_t* buf); |
MikkoZ | 0:a3f43eb92f86 | 40 | bool getresults_raw(int16_t* buf); |
MikkoZ | 3:4fd5361ed180 | 41 | bool getresults_highpass_g(float* buf); |
MikkoZ | 0:a3f43eb92f86 | 42 | bool getresults_g(float* buf); |
MikkoZ | 0:a3f43eb92f86 | 43 | |
MikkoZ | 2:62891556d47b | 44 | |
MikkoZ | 2:62891556d47b | 45 | bool get_tilt(enum e_axis* current_previous); |
MikkoZ | 2:62891556d47b | 46 | bool get_tap_interrupt_axis(enum e_axis* axis); |
MikkoZ | 2:62891556d47b | 47 | bool get_detected_motion_axis(enum e_axis* axis); |
MikkoZ | 2:62891556d47b | 48 | bool set_tilt_axis_mask(uint8_t cnltl2_tilt_mask); |
MikkoZ | 2:62891556d47b | 49 | |
MikkoZ | 2:62891556d47b | 50 | bool get_interrupt_reason(enum e_interrupt_reason* int_reason); |
MikkoZ | 2:62891556d47b | 51 | |
MikkoZ | 2:62891556d47b | 52 | bool has_interrupt_occured(); |
MikkoZ | 2:62891556d47b | 53 | void clear_interrupt(); |
MikkoZ | 2:62891556d47b | 54 | void soft_reset(); |
MikkoZ | 2:62891556d47b | 55 | bool self_test(); |
MikkoZ | 2:62891556d47b | 56 | |
MikkoZ | 2:62891556d47b | 57 | bool set_cntl3_odrs(uint8_t tilt_position_odr, uint8_t directional_tap_odr, uint8_t motion_wuf_odr); //0xff for DONT_SET |
MikkoZ | 2:62891556d47b | 58 | bool set_odcntl(bool iir_filter_off, uint8_t lowpass_filter_freq_half, uint8_t odr); |
MikkoZ | 2:62891556d47b | 59 | bool int1_setup(uint8_t pwsel, |
MikkoZ | 2:62891556d47b | 60 | bool physical_int_pin_enabled, |
MikkoZ | 2:62891556d47b | 61 | bool physical_int_pin_active_high, |
MikkoZ | 2:62891556d47b | 62 | bool physical_int_pin_latch_disabled, |
MikkoZ | 2:62891556d47b | 63 | bool self_test_polarity_positive, |
MikkoZ | 2:62891556d47b | 64 | bool spi3wire_enabled); |
MikkoZ | 2:62891556d47b | 65 | bool int2_setup(uint8_t pwsel, |
MikkoZ | 2:62891556d47b | 66 | bool physical_int_pin_enabled, |
MikkoZ | 2:62891556d47b | 67 | bool physical_int_pin_active_high, |
MikkoZ | 2:62891556d47b | 68 | bool physical_int_pin_latch_disabled, |
MikkoZ | 2:62891556d47b | 69 | bool aclr2_enabled, |
MikkoZ | 2:62891556d47b | 70 | bool aclr1_enabled); |
MikkoZ | 2:62891556d47b | 71 | bool set_int1_interrupt_reason(uint8_t interrupt_reason); |
MikkoZ | 2:62891556d47b | 72 | bool set_int2_interrupt_reason(uint8_t interrupt_reason); |
MikkoZ | 2:62891556d47b | 73 | |
MikkoZ | 2:62891556d47b | 74 | bool set_motion_detect_axis(uint8_t xxyyzz, bool axis_and_combination_enabled = false); |
MikkoZ | 2:62891556d47b | 75 | bool set_tap_axis(uint8_t xxyyzz); |
MikkoZ | 2:62891556d47b | 76 | /** |
MikkoZ | 2:62891556d47b | 77 | * Note that not all sensor setup registers are exposed with this driver yet. |
MikkoZ | 2:62891556d47b | 78 | * There are also setup registers for motion detect, tap/double tap detect, free |
MikkoZ | 2:62891556d47b | 79 | * fall detect, tilt hysteresis, low power and FIFO. |
MikkoZ | 2:62891556d47b | 80 | */ |
MikkoZ | 2:62891556d47b | 81 | |
MikkoZ | 0:a3f43eb92f86 | 82 | private: |
MikkoZ | 2:62891556d47b | 83 | bool setup_mode_on; |
MikkoZ | 0:a3f43eb92f86 | 84 | void set_tilt_position_defaults(); |
MikkoZ | 0:a3f43eb92f86 | 85 | |
MikkoZ | 0:a3f43eb92f86 | 86 | RegisterWriter i2c_rw; |
MikkoZ | 0:a3f43eb92f86 | 87 | uint16_t resolution_divider; |
MikkoZ | 1:f328083fb80b | 88 | uint8_t _sad; |
MikkoZ | 1:f328083fb80b | 89 | uint8_t _wai; |
MikkoZ | 0:a3f43eb92f86 | 90 | }; |
MikkoZ | 0:a3f43eb92f86 | 91 | |
MikkoZ | 0:a3f43eb92f86 | 92 | #endif |