Dependents:
kionix-kx123-hello
« Back to documentation index
KX123 Class Reference
Kionix KX123 accelerometer i2c driver.
More...
#include <kx123.h >
Public Member Functions
KX123 (RegisterWriter &i2c_obj, uint8_t sad=KX123_DEFAULT_SLAVE_ADDRESS, uint8_t wai=KX123_WHO_AM_I_WAI_ID)
Create a KX123 instance for communication through pre-instantiated RegisterWriter (I2C) -object.
bool start_setup_mode (void)
Start setup/stand-by mode and shut off measurements.
bool start_measurement_mode (void)
Start operating/measurement mode.
bool set_defaults (void)
Check if sensor is connected, setup defaults to sensor and start measuring.
bool getresults_highpass (int16_t *buf)
Get filtered uint16_t XYZ-values from sensor.
bool getresults_raw (int16_t *buf)
Get raw uint16_t XYZ-values from sensor.
bool getresults_highpass_g (float *buf)
Get gravity scaled float XYZ-values from highpass filtered sensor values.
bool getresults_g (float *buf)
Get gravity scaled float XYZ-values from sensor.
bool get_tilt (enum e_axis *current_previous)
Get axes of current tilt and previous tilt.
bool get_tap_interrupt_axis (enum e_axis *axis)
Get axis of triggered tap/double tap interrupt from INS1.
bool get_detected_motion_axis (enum e_axis *axis)
Get axis of triggered motion detect interrupt from INS3.
bool set_tilt_axis_mask (uint8_t cnltl2_tilt_mask)
Set axis of triggered motion detect interrupt from CNTL2.
bool get_interrupt_reason (enum e_interrupt_reason *int_reason)
get cause of interrupt trigger from INS2
bool has_interrupt_occured ()
Check from sensor register if interrupt has occured.
void clear_interrupt ()
Clear interrupt flag when latched.
void soft_reset ()
Initiate software reset and RAM reboot routine and wait untill finished.
bool self_test ()
Verify proper integrated circuit functionality.
bool set_cntl3_odrs (uint8_t tilt_position_odr, uint8_t directional_tap_odr, uint8_t motion_wuf_odr)
Setup ODR values for Tilt Position, Directional Tap and Motion Detect.
bool set_odcntl (bool iir_filter_off, uint8_t lowpass_filter_freq_half, uint8_t odr)
Setup ODR value, IIR-filter on/off and lowpass filter corner frequency.
bool int1_setup (uint8_t pwsel, bool physical_int_pin_enabled, bool physical_int_pin_active_high, bool physical_int_pin_latch_disabled, bool self_test_polarity_positive, bool spi3wire_enabled)
Setup physical int1 pin, selftest polarity and SPI 3-wire on/off.
bool int2_setup (uint8_t pwsel, bool physical_int_pin_enabled, bool physical_int_pin_active_high, bool physical_int_pin_latch_disabled, bool aclr2_enabled, bool aclr1_enabled)
Setup physical int2 pin and int1/2 autoclear.
bool set_int1_interrupt_reason (uint8_t interrupt_reason)
Select interrupt reasons that can trigger interrupt for int1.
bool set_int2_interrupt_reason (uint8_t interrupt_reason)
Select interrupt reasons that can trigger interrupt for int2.
bool set_motion_detect_axis (uint8_t xxyyzz, bool axis_and_combination_enabled=false)
Select axis that are monitored for motion detect interrupt.
bool set_tap_axis (uint8_t xxyyzz)
Select axis that are monitored for tap/doubletap interrupt.
Detailed Description
Kionix KX123 accelerometer i2c driver.
For some extend can be used also with kx012, kx022, kx023, kx23h, kx112, kx122, kx124, kx222 and kx224. Driver uses RegisterWriter -class as (i2c) hardware abstraction layer. Note that when doing setup, sensor has to be in setup mode, not in operating mode.
Definition at line 29 of file kx123.h .
Constructor & Destructor Documentation
KX123
(
RegisterWriter &
i2c_obj ,
uint8_t
sad = KX123_DEFAULT_SLAVE_ADDRESS,
uint8_t
wai = KX123_WHO_AM_I_WAI_ID
)
Create a KX123 instance for communication through pre-instantiated RegisterWriter (I2C) -object.
Parameters:
i2c_obj pre-instantiated RegisterWriter (I2C) -object reference
sad slave address of sensor.
wai who_am_i value (i.e. sensor type/model)
Definition at line 28 of file kx123.cpp .
Member Function Documentation
Clear interrupt flag when latched.
(==Interrupt release) Doesn't work for FIFO Buffer Full or FIFO Watermark -interrupts.
Definition at line 305 of file kx123.cpp .
bool get_detected_motion_axis
(
enum e_axis *
axis )
Get axis of triggered motion detect interrupt from INS3.
Parameters:
*axis space for storing 1 (uint8_t) value in e_axis format
Returns: true on error
Definition at line 254 of file kx123.cpp .
bool get_interrupt_reason
(
enum e_interrupt_reason *
int_reason )
get cause of interrupt trigger from INS2
Parameters:
*int_reason space for storing 1 (uint8_t) value in e_interrupt_reason format
Returns: true on error
Definition at line 279 of file kx123.cpp .
bool get_tap_interrupt_axis
(
enum e_axis *
axis )
Get axis of triggered tap/double tap interrupt from INS1.
Parameters:
*axis space for storing 1 (uint8_t) value in e_axis format
Returns: true on error
Definition at line 240 of file kx123.cpp .
bool get_tilt
(
enum e_axis *
current_previous )
Get axes of current tilt and previous tilt.
Parameters:
*current_previous space for storing 2 (uint8_t) values
Returns: true on error
Definition at line 226 of file kx123.cpp .
bool getresults_g
(
float *
buf )
Get gravity scaled float XYZ-values from sensor.
Parameters:
*buf to float[3] for results
Returns: true on error, false on read ok.
Definition at line 184 of file kx123.cpp .
bool getresults_highpass
(
int16_t *
buf )
Get filtered uint16_t XYZ-values from sensor.
Parameters:
*buf to uint16_t[3] for results
Returns: true on error, false on read ok.
Definition at line 143 of file kx123.cpp .
bool getresults_highpass_g
(
float *
buf )
Get gravity scaled float XYZ-values from highpass filtered sensor values.
Parameters:
*buf to float[3] for results
Returns: true on error, false on read ok.
Definition at line 205 of file kx123.cpp .
bool getresults_raw
(
int16_t *
buf )
Get raw uint16_t XYZ-values from sensor.
Parameters:
*buf to uint16_t[3] for results
Returns: true on error, false on read ok.
Definition at line 163 of file kx123.cpp .
bool has_interrupt_occured
(
)
Check from sensor register if interrupt has occured.
Usable feature when multiple sensor interrupts are connected to same interrupt pin.
Returns: true when interrupt has occured. False on read fail and no interrupt.
Definition at line 293 of file kx123.cpp .
bool int1_setup
(
uint8_t
pwsel ,
bool
physical_int_pin_enabled ,
bool
physical_int_pin_active_high ,
bool
physical_int_pin_latch_disabled ,
bool
self_test_polarity_positive ,
bool
spi3wire_enabled
)
Setup physical int1 pin, selftest polarity and SPI 3-wire on/off.
Parameters:
pwsel Pulse width configuration in KX122_INC1_PWSEL1_* values
physical_int_pin_enabled
physical_int_pin_active_high (default true)
physical_int_pin_latch_disabled
self_test_polarity_positive
spi3wire_enabled Use 3 wires instead of 4.
Returns: true on error or setup mode off, false on setup ok.
Definition at line 414 of file kx123.cpp .
bool int2_setup
(
uint8_t
pwsel ,
bool
physical_int_pin_enabled ,
bool
physical_int_pin_active_high ,
bool
physical_int_pin_latch_disabled ,
bool
aclr2_enabled ,
bool
aclr1_enabled
)
Setup physical int2 pin and int1/2 autoclear.
Parameters:
pwsel Pulse width configuration in KX122_INC1_PWSEL1_* values
physical_int_pin_enabled
physical_int_pin_active_high (default true)
physical_int_pin_latch_disabled
aclr2_enabled
aclr1_enabled
Returns: true on error or setup mode off, false on setup ok.
Definition at line 455 of file kx123.cpp .
Verify proper integrated circuit functionality.
Returns: true on test fail or setup mode off, false on test ok.
Definition at line 334 of file kx123.cpp .
bool set_cntl3_odrs
(
uint8_t
tilt_position_odr ,
uint8_t
directional_tap_odr ,
uint8_t
motion_wuf_odr
)
Setup ODR values for Tilt Position, Directional Tap and Motion Detect.
Parameters:
tilt_position_odr KX122_CNTL3_OTP_* -value or 0xff to skip.
directional_tap_odr KX122_CNTL3_OTDT_* -value or 0xff to skip.
motion_wuf_odr motion detect/high-pass odr (KX122_CNTL3_OWUF_* -value) or 0xff to skip.
Returns: true on error or setup mode off, false on setup ok.
Definition at line 360 of file kx123.cpp .
bool set_defaults
(
void
)
Check if sensor is connected, setup defaults to sensor and start measuring.
Returns: true on error, false on ok
Definition at line 59 of file kx123.cpp .
bool set_int1_interrupt_reason
(
uint8_t
interrupt_reason )
Select interrupt reasons that can trigger interrupt for int1.
Parameters:
interrupt_reason One or more e_interrupt_reason -values except doubletap.
Returns: true on error or setup mode off, false on setup ok.
Definition at line 490 of file kx123.cpp .
bool set_int2_interrupt_reason
(
uint8_t
interrupt_reason )
Select interrupt reasons that can trigger interrupt for int2.
Parameters:
interrupt_reason One or more e_interrupt_reason -values except doubletap.
Returns: true on error or setup mode off, false on setup ok.
Definition at line 500 of file kx123.cpp .
bool set_motion_detect_axis
(
uint8_t
xxyyzz ,
bool
axis_and_combination_enabled = false
)
Select axis that are monitored for motion detect interrupt.
Parameters:
xxyyzz combination of e_axis -values for enabling axis
axis_and_combination_enabled true for AND or false for OR
true for AND configuration = (XN || XP) && (YN || YP) && (ZN || ZP)
false for OR configuration = (XN || XP || YN || TP || ZN || ZP)
Returns: true on error or setup mode off, false on setup ok.
Definition at line 515 of file kx123.cpp .
bool set_odcntl
(
bool
iir_filter_off ,
uint8_t
lowpass_filter_freq_half ,
uint8_t
odr
)
Setup ODR value, IIR-filter on/off and lowpass filter corner frequency.
Parameters:
iir_filter_off False to filter ON or true to filter OFF.
lowpass_filter_freq_half Filter corner frequency setup. False to ODR/9. True to ODR/2.
odr Output Data Rate using KX122_ODCNTL_OSA_* -definitions.
Returns: true on error or setup mode off, false on setup ok.
Definition at line 388 of file kx123.cpp .
bool set_tap_axis
(
uint8_t
xxyyzz )
Select axis that are monitored for tap/doubletap interrupt.
Parameters:
xxyyzz combination of e_axis -values for enabling axis
Returns: true on error or setup mode off, false on setup ok.
Definition at line 532 of file kx123.cpp .
bool set_tilt_axis_mask
(
uint8_t
cnltl2_tilt_mask )
Set axis of triggered motion detect interrupt from CNTL2.
Parameters:
cnltl2_tilt_mask Orred e_axis values for axes directions to cause interrupt
Returns: true on error or setup mode off
Definition at line 268 of file kx123.cpp .
Initiate software reset and RAM reboot routine and wait untill finished.
Definition at line 316 of file kx123.cpp .
bool start_measurement_mode
(
void
)
Start operating/measurement mode.
Setup is not allowed while in this mode.
Returns: true on error, false on ok
Definition at line 50 of file kx123.cpp .
bool start_setup_mode
(
void
)
Start setup/stand-by mode and shut off measurements.
Returns: true on error, false on ok
Definition at line 41 of file kx123.cpp .