Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: kionix-kx123-hello
kx123.h
00001 /* Copyright 2016 Rohm Semiconductor 00002 00003 Licensed under the Apache License, Version 2.0 (the "License"); 00004 you may not use this file except in compliance with the License. 00005 You may obtain a copy of the License at 00006 00007 http://www.apache.org/licenses/LICENSE-2.0 00008 00009 Unless required by applicable law or agreed to in writing, software 00010 distributed under the License is distributed on an "AS IS" BASIS, 00011 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00012 See the License for the specific language governing permissions and 00013 limitations under the License. 00014 */ 00015 #ifndef KX123_H 00016 #define KX123_H 00017 00018 #include "RegisterWriter/RegisterWriter/rohm_hal2.h" 00019 #include "RegisterWriter/RegisterWriter/RegisterWriter.h" 00020 00021 #include "kx123_registers.h" 00022 00023 /** 00024 * Kionix KX123 accelerometer i2c driver. For some extend can be used also with 00025 * kx012, kx022, kx023, kx23h, kx112, kx122, kx124, kx222 and kx224. Driver uses 00026 * RegisterWriter -class as (i2c) hardware abstraction layer. 00027 * Note that when doing setup, sensor has to be in setup mode, not in operating mode. 00028 */ 00029 class KX123 00030 { 00031 public: 00032 00033 KX123(RegisterWriter &i2c_obj, uint8_t sad = KX123_DEFAULT_SLAVE_ADDRESS, uint8_t wai = KX123_WHO_AM_I_WAI_ID); 00034 ~KX123(); 00035 00036 bool start_setup_mode(void); 00037 bool start_measurement_mode(void); 00038 bool set_defaults(void); 00039 bool getresults_highpass(int16_t* buf); 00040 bool getresults_raw(int16_t* buf); 00041 bool getresults_highpass_g(float* buf); 00042 bool getresults_g(float* buf); 00043 00044 00045 bool get_tilt(enum e_axis* current_previous); 00046 bool get_tap_interrupt_axis(enum e_axis* axis); 00047 bool get_detected_motion_axis(enum e_axis* axis); 00048 bool set_tilt_axis_mask(uint8_t cnltl2_tilt_mask); 00049 00050 bool get_interrupt_reason(enum e_interrupt_reason* int_reason); 00051 00052 bool has_interrupt_occured(); 00053 void clear_interrupt(); 00054 void soft_reset(); 00055 bool self_test(); 00056 00057 bool set_cntl3_odrs(uint8_t tilt_position_odr, uint8_t directional_tap_odr, uint8_t motion_wuf_odr); //0xff for DONT_SET 00058 bool set_odcntl(bool iir_filter_off, uint8_t lowpass_filter_freq_half, uint8_t odr); 00059 bool int1_setup(uint8_t pwsel, 00060 bool physical_int_pin_enabled, 00061 bool physical_int_pin_active_high, 00062 bool physical_int_pin_latch_disabled, 00063 bool self_test_polarity_positive, 00064 bool spi3wire_enabled); 00065 bool int2_setup(uint8_t pwsel, 00066 bool physical_int_pin_enabled, 00067 bool physical_int_pin_active_high, 00068 bool physical_int_pin_latch_disabled, 00069 bool aclr2_enabled, 00070 bool aclr1_enabled); 00071 bool set_int1_interrupt_reason(uint8_t interrupt_reason); 00072 bool set_int2_interrupt_reason(uint8_t interrupt_reason); 00073 00074 bool set_motion_detect_axis(uint8_t xxyyzz, bool axis_and_combination_enabled = false); 00075 bool set_tap_axis(uint8_t xxyyzz); 00076 /** 00077 * Note that not all sensor setup registers are exposed with this driver yet. 00078 * There are also setup registers for motion detect, tap/double tap detect, free 00079 * fall detect, tilt hysteresis, low power and FIFO. 00080 */ 00081 00082 private: 00083 bool setup_mode_on; 00084 void set_tilt_position_defaults(); 00085 00086 RegisterWriter i2c_rw; 00087 uint16_t resolution_divider; 00088 uint8_t _sad; 00089 uint8_t _wai; 00090 }; 00091 00092 #endif
Generated on Thu Jul 14 2022 07:48:42 by
1.7.2
Rohm/Kionix KX123-6000 | Accelerometer