upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
Data Structures | Functions | Macros | Typedefs | Enumerations
kx122.h File Reference
Include dependency graph for kx122.h:

API Description

/*
* The MIT License (MIT)
*
* Author: Samuli Rissanen <samuli.rissanen@hotmail.com>
* Copyright (c) 2018 Rohm Semiconductor.
*
* 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 <stdio.h>
#include <unistd.h>
#include <signal.h>
#include "kx122.h"
#include "upm_utilities.h"
bool shouldRun = true;
void sig_handler(int signo)
{
if(signo == SIGINT){
shouldRun = false;
}
}
int main(int argc, char **argv)
{
signal(SIGINT,sig_handler);
kx122_context sensor = kx122_init(0, -1, 24, 10000);
if (!sensor)
{
printf("kx122_init() failed.\n");
return 1;
}
kx122_device_init(sensor,KX122_ODR_50,HIGH_RES,KX122_RANGE_2G);
float x,y,z;
int wait_time = (kx122_get_sample_period(sensor) * MICRO_S);
if (wait_time < 0) wait_time = 1000;
while(shouldRun){
kx122_get_acceleration_data(sensor,&x,&y,&z);
printf("%.02f | %.02f | %.02f\n",x,y,z);
upm_delay_us(wait_time);
}
kx122_close(sensor);
return 0;
}

Go to the source code of this file.

Data Structures

struct  _kx122_context
 
struct  _odr_item
 

Functions

kx122_context kx122_init (int bus, int addr, int chip_select_pin, int spi_bus_frequency)
 
void kx122_close (kx122_context dev)
 
upm_result_t kx122_device_init (const kx122_context dev, KX122_ODR_T odr, KX122_RES_T res, KX122_RANGE_T grange)
 
float kx122_get_sample_period (const kx122_context dev)
 
upm_result_t kx122_get_who_am_i (const kx122_context dev, uint8_t *data)
 
upm_result_t kx122_get_acceleration_data_raw (const kx122_context dev, float *x, float *y, float *z)
 
upm_result_t kx122_get_acceleration_data (const kx122_context dev, float *x, float *y, float *z)
 
upm_result_t kx122_sensor_software_reset (const kx122_context dev)
 
upm_result_t kx122_enable_iir (const kx122_context dev)
 
upm_result_t kx122_disable_iir (const kx122_context dev)
 
upm_result_t kx122_self_test (const kx122_context dev)
 
upm_result_t kx122_set_sensor_standby (const kx122_context dev)
 
upm_result_t kx122_set_sensor_active (const kx122_context dev)
 
upm_result_t kx122_set_odr (const kx122_context dev, KX122_ODR_T odr)
 
upm_result_t kx122_set_grange (const kx122_context dev, KX122_RANGE_T grange)
 
upm_result_t kx122_set_resolution (const kx122_context dev, KX122_RES_T res)
 
upm_result_t kx122_set_bw (const kx122_context dev, LPRO_STATE_T lpro)
 
upm_result_t kx122_set_average (const kx122_context dev, KX122_AVG_T avg)
 
upm_result_t kx122_install_isr (const kx122_context dev, mraa_gpio_edge_t edge, KX122_INTERRUPT_PIN_T intp, int pin, void(*isr)(void *), void *arg)
 
void kx122_uninstall_isr (const kx122_context dev, KX122_INTERRUPT_PIN_T intp)
 
upm_result_t kx122_enable_interrupt1 (const kx122_context dev, KX122_INTERRUPT_POLARITY_T polarity)
 
upm_result_t kx122_enable_interrupt2 (const kx122_context dev, KX122_INTERRUPT_POLARITY_T polarity)
 
upm_result_t kx122_disable_interrupt1 (const kx122_context dev)
 
upm_result_t kx122_disable_interrupt2 (const kx122_context dev)
 
upm_result_t kx122_route_interrupt1 (const kx122_context dev, uint8_t bits)
 
upm_result_t kx122_route_interrupt2 (const kx122_context dev, uint8_t bits)
 
bool kx122_get_interrupt_status (const kx122_context dev)
 
upm_result_t kx122_get_interrupt_source (const kx122_context dev, uint8_t *data)
 
upm_result_t kx122_clear_interrupt (const kx122_context dev)
 
upm_result_t kx122_enable_data_ready_interrupt (const kx122_context dev)
 
upm_result_t kx122_disable_data_ready_interrupt (const kx122_context dev)
 
upm_result_t kx122_enable_buffer_full_interrupt (const kx122_context dev)
 
upm_result_t kx122_disable_buffer_full_interrupt (const kx122_context dev)
 
upm_result_t kx122_enable_buffer (const kx122_context dev)
 
upm_result_t kx122_disable_buffer (const kx122_context dev)
 
upm_result_t kx122_buffer_init (const kx122_context dev, uint samples, KX122_RES_T res, KX122_BUFFER_MODE_T mode)
 
upm_result_t kx122_set_buffer_resolution (const kx122_context dev, KX122_RES_T res)
 
upm_result_t kx122_set_buffer_threshold (const kx122_context dev, uint samples)
 
upm_result_t kx122_set_buffer_mode (const kx122_context dev, KX122_BUFFER_MODE_T mode)
 
upm_result_t kx122_get_buffer_status (const kx122_context dev, uint *samples)
 
upm_result_t kx122_read_buffer_samples_raw (const kx122_context dev, uint len, float *x_array, float *y_array, float *z_array)
 
upm_result_t kx122_read_buffer_samples (const kx122_context dev, uint len, float *x_array, float *y_array, float *z_array)
 
upm_result_t kx122_clear_buffer (const kx122_context dev)
 

Macros

#define DEFAULT_SPI_FREQUENCY   10000
 
#define KX122_DEFAULT_SLAVE_ADDR_1   0x1F
 
#define KX122_DEFAULT_SLAVE_ADDR_2   0x1E
 
#define MICRO_S   1000000
 

Typedefs

typedef struct _kx122_contextkx122_context
 
typedef struct _odr_item odr_item
 

Enumerations

enum  KX122_ODR_T {
  KX122_ODR_12P5 = KX122_ODCNTL_OSA_12P5, KX122_ODR_25 = KX122_ODCNTL_OSA_25, KX122_ODR_50 = KX122_ODCNTL_OSA_50, KX122_ODR_100 = KX122_ODCNTL_OSA_100,
  KX122_ODR_200 = KX122_ODCNTL_OSA_200, KX122_ODR_400 = KX122_ODCNTL_OSA_400, KX122_ODR_800 = KX122_ODCNTL_OSA_800, KX122_ODR_1600 = KX122_ODCNTL_OSA_1600,
  KX122_ODR_0P781 = KX122_ODCNTL_OSA_0P781, KX122_ODR_1P563 = KX122_ODCNTL_OSA_1P563, KX122_ODR_3P125 = KX122_ODCNTL_OSA_3P125, KX122_ODR_6P25 = KX122_ODCNTL_OSA_6P25,
  KX122_ODR_3200 = KX122_ODCNTL_OSA_3200, KX122_ODR_6400 = KX122_ODCNTL_OSA_6400, KX122_ODR_12800 = KX122_ODCNTL_OSA_12800, KX122_ODR_25600 = KX122_ODCNTL_OSA_25600
}
 
enum  KX122_AVG_T {
  KX122_NO_AVG = KX122_LP_CNTL_AVC_NO_AVG, KX122_2_SAMPLE_AVG = KX122_LP_CNTL_AVC_2_SAMPLE_AVG, KX122_4_SAMPLE_AVG = KX122_LP_CNTL_AVC_4_SAMPLE_AVG, KX122_8_SAMPLE_AVG = KX122_LP_CNTL_AVC_8_SAMPLE_AVG,
  KX122_16_SAMPLE_AVG = KX122_LP_CNTL_AVC_16_SAMPLE_AVG, KX122_32_SAMPLE_AVG = KX122_LP_CNTL_AVC_32_SAMPLE_AVG, KX122_64_SAMPLE_AVG = KX122_LP_CNTL_AVC_64_SAMPLE_AVG, KX122_128_SAMPLE_AVG = KX122_LP_CNTL_AVC_128_SAMPLE_AVG
}
 
enum  KX122_RANGE_T { KX122_RANGE_2G = KX122_CNTL1_GSEL_2G, KX122_RANGE_4G = KX122_CNTL1_GSEL_4G, KX122_RANGE_8G = KX122_CNTL1_GSEL_8G }
 
enum  KX122_BUFFER_MODE_T { KX122_FIFO_MODE = KX122_BUF_CNTL2_BUF_M_FIFO, KX122_FILO_MODE = KX122_BUF_CNTL2_BUF_M_FILO, KX122_STREAM_MODE = KX122_BUF_CNTL2_BUF_M_STREAM }
 
enum  KX122_INTERRUPT_T { KX122_BUF_FULL_INT = KX122_INC4_BFI1, KX122_WATERMARK_INT = KX122_INC4_WMI1, KX122_DATA_READY_INT = KX122_INC4_DRDYI1 }
 
enum  KX122_RES_T { HIGH_RES, LOW_RES }
 
enum  LPRO_STATE_T { ODR_9, ODR_2 }
 
enum  KX122_INTERRUPT_PIN_T { INT1, INT2 }
 
enum  KX122_INTERRUPT_POLARITY_T { ACTIVE_LOW, ACTIVE_HIGH }
 

Function Documentation

kx122_context kx122_init ( int  bus,
int  addr,
int  chip_select_pin,
int  spi_bus_frequency 
)

KX122 initialization

Set addr to -1 if using SPI. When using I2C, set chip_select_pin to -1;

If no errors occur, the device gets initialized with default values and gets set to active state.

Parameters
busI2C or SPI bus to use.
addrI2C address of the sensor.
chip_selectChip select pin for SPI.
spi_bus_frequencySpeed of the SPI communication bus in Hz (ignored when using I2C).
Returns
The device context, or NULL if an error occurs.

Here is the call graph for this function:

void kx122_close ( kx122_context  dev)

KX122 destructor Closes the I2C or SPI context, and removes interrupts. Frees memory of the kx122_context.

Parameters
devThe device context.

Here is the call graph for this function:

Here is the caller graph for this function:

upm_result_t kx122_device_init ( const kx122_context  dev,
KX122_ODR_T  odr,
KX122_RES_T  res,
KX122_RANGE_T  grange 
)

Intilializes the sensor with the given sampling rate, resolution and acceleration range.

This gets called during the kx122_init(), so it will not need to be called unless the device is reset.

Sensor is automatically set into standby mode during the initialization. Sensor is set to active mode after initialization.

Parameters
devThe device context.
odrOne of the KX122_ODR_T values.
resOne of the KX122_RES_T values.
grangeOne of the KX122_RANGE_T values.
Returns
UPM result.

Here is the call graph for this function:

Here is the caller graph for this function:

float kx122_get_sample_period ( const kx122_context  dev)

Gets the length of one sample period depending on the sampling rate of the sensor.

Parameters
devThe device context.
Returns
Floating point value of the sampling period, or if an error occurs returns -1.

Here is the caller graph for this function:

upm_result_t kx122_get_who_am_i ( const kx122_context  dev,
uint8_t *  data 
)

Gets who am i value of the sensor.

Parameters
devThe device context.
dataPointer to a uint8_t variable to store the value.
Returns
UPM result.

Here is the caller graph for this function:

upm_result_t kx122_get_acceleration_data_raw ( const kx122_context  dev,
float *  x,
float *  y,
float *  z 
)

Gets raw accelerometer data from the sensor.

Parameters
devThe device context.
xPointer to a floating point variable to store the x-axis value. Can be set to NULL if not wanted.
yPointer to a floating point variable to store the y-axis value. Can be set to NULL if not wanted.
zPointer to a floating point variable to store the z-axis value. Can be set to NULL if not wanted.
Returns
UPM result.

Here is the caller graph for this function:

upm_result_t kx122_get_acceleration_data ( const kx122_context  dev,
float *  x,
float *  y,
float *  z 
)

Gets converted (m/s^2) accelerometer data from the sensor.

Parameters
devThe device context.
xPointer to a floating point variable to store the x-axis value. Can be set to NULL if not wanted.
yPointer to a floating point variable to store the y-axis value. Can be set to NULL if not wanted.
zPointer to a floating point variable to store the z-axis value. Can be set to NULL if not wanted.

Here is the call graph for this function:

Here is the caller graph for this function:

upm_result_t kx122_sensor_software_reset ( const kx122_context  dev)

Performs a sensor software reset. The software reset clears the RAM of the sensor and resets all registers to pre-defined values.

You should call kx122_device_init() after the software reset.

See the datasheet for more details.

Parameters
devThe device context.
Returns
UPM result.

Here is the caller graph for this function:

upm_result_t kx122_enable_iir ( const kx122_context  dev)

Enables sensor filter bypass.

Sensor needs to be in standby mode when enabling the filter bypass.

Parameters
devThe device context.
Returns
UPM result.

Here is the caller graph for this function:

upm_result_t kx122_disable_iir ( const kx122_context  dev)

Disables sensor filter bypass.

Sensor needs to be in standby mode when disabling the filter bypass.

Parameters
devThe device context.
Returns
UPM result.

Here is the caller graph for this function:

upm_result_t kx122_self_test ( const kx122_context  dev)

Performs a self-test of the sensor. The test applies an electrostatic force to the sensor, simulating input acceleration. The test compares samples from all axis before and after applying the electrostatic force to the sensor. If the amount of acceleration increases according to the values defined in TABLE 1 of the datasheet, the test passes.

The function prints out the minimum, maximum and values calculated during the test for each axis, and the result of the test for each axis.

See the datasheet for more information.

Parameters
devThe device context.
Returns
UPM result.

Here is the call graph for this function:

Here is the caller graph for this function:

upm_result_t kx122_set_sensor_standby ( const kx122_context  dev)

Sets the sensor to the standby mode.

Parameters
devThe device context.
Returns
UPM result.

Here is the caller graph for this function:

upm_result_t kx122_set_sensor_active ( const kx122_context  dev)

Sets the sensor to active mode.

Parameters
devThe device context.
Returns
UPM result.

Here is the call graph for this function:

Here is the caller graph for this function:

upm_result_t kx122_set_odr ( const kx122_context  dev,
KX122_ODR_T  odr 
)

Sets the ODR of the sensor.

Sensor needs to be in standby mode when setting the ODR.

Parameters
devThe device context.
odrOne of the KX122_ODR_T values.
Returns
UPM result.

Here is the caller graph for this function:

upm_result_t kx122_set_grange ( const kx122_context  dev,
KX122_RANGE_T  grange 
)

Sets the acceleration range of the sensor.

Sensor needs to be in standby mode when setting the acceleration range value.

Parameters
devThe device context.
grangeOne of the KX122_RANGE_T values.
Returns
UPM result.

Here is the caller graph for this function:

upm_result_t kx122_set_resolution ( const kx122_context  dev,
KX122_RES_T  res 
)

Sets the resolution of the sensor. High resolution (16 bits) or low resolution (8 bits).

Sensor needs to be in standby mode when setting the sensor resolution.

When sensor is set to low resolution mode, the sensor runs in low power mode, which in turn enables features such as averaging.(kx122_set_average()).

Parameters
devThe device context.
resOne of the KX122_RES_T values.
Returns
UPM result.

Here is the caller graph for this function:

upm_result_t kx122_set_bw ( const kx122_context  dev,
LPRO_STATE_T  lpro 
)

Sets the low pass filter roll off

Sensor needs to be in standby mode when setting the filter roll off value.

Parameters
devThe device context.
lproOne of the LPRO_STATE_T values.
Returns
UPM result.

Here is the caller graph for this function:

upm_result_t kx122_set_average ( const kx122_context  dev,
KX122_AVG_T  avg 
)

Set the amount of samples to be averaged in low power mode.

Sensor needs to be in standby mode when setting the average value.

Parameters
devThe device context.
avgOne of the KX122_AVG_T values.
Returns
UPM result.

Here is the caller graph for this function:

upm_result_t kx122_install_isr ( const kx122_context  dev,
mraa_gpio_edge_t  edge,
KX122_INTERRUPT_PIN_T  intp,
int  pin,
void(*)(void *)  isr,
void *  arg 
)

Installs an interrupt handler to be executed when an interrupt is detected on the interrupt pin.

Parameters
devThe device context.
edgeOne of the mraa_gpio_edge_t values. Interrupt trigger edge.
intpOne of the KX122_INTERRUPT_PIN_T values. Specifies which interrupt pin you are setting.
pinThe GPIO pin to use as the interrupt pin.
isrPointer to the function to be called, when the interrupt occurs.
argThe arguments to be passed to the function.
Returns
UPM result.

Here is the caller graph for this function:

void kx122_uninstall_isr ( const kx122_context  dev,
KX122_INTERRUPT_PIN_T  intp 
)

Uninstalls a previously installed interrupt handler.

Parameters
devThe device context.
intpOne of the KX122_INTERRUPT_PIN_T values. Specifies which interrupt pin handler is uninstalled.

Here is the caller graph for this function:

upm_result_t kx122_enable_interrupt1 ( const kx122_context  dev,
KX122_INTERRUPT_POLARITY_T  polarity 
)

Enables interrupts on the interrupt pin 1 of the sensor.

Pulse width = 50us (10us if data sampling rate > 1600Hz). Using pulse mode.

Sensor needs to be in standby mode when enabling the interrupt.

See datasheet for more details.

Parameters
devThe device context.
polarityOne of the KX122_INTERRUPT_POLARITY_T values. Select the polarity of the interrupt.
Returns
UPM result.

Here is the caller graph for this function:

upm_result_t kx122_enable_interrupt2 ( const kx122_context  dev,
KX122_INTERRUPT_POLARITY_T  polarity 
)

Enables interrupts on the interrupt pin 2 of the sensor.

Pulse width = 50us (10us if data sampling rate > 1600Hz). Using pulse mode.

Sensor needs to be in standby mode when enabling the interrupt.

See datasheet for more details.

Parameters
devThe device context.
polarityOne of the KX122_INTERRUPT_POLARITY_T values. Select the polarity of the interrupt.
Returns
UPM result.

Here is the caller graph for this function:

upm_result_t kx122_disable_interrupt1 ( const kx122_context  dev)

Disables interrupts on the interrupt pin 1 of the sensor.

Sensor needs to be in standby mode when disabling the interrupt pin 1.

Parameters
devThe device context.
Returns
UPM result.

Here is the caller graph for this function:

upm_result_t kx122_disable_interrupt2 ( const kx122_context  dev)

Disables interrupts on the interrupt pin 2 of the sensor.

Sensor needs to be in standby mode when disabling the interrupt pin 2.

Parameters
devThe device context.
Returns
UPM result.

Here is the caller graph for this function:

upm_result_t kx122_route_interrupt1 ( const kx122_context  dev,
uint8_t  bits 
)

Routes the interrupts to the interrupt pin 1 of the sensor.

Sensor needs to be in standby mode when routing the interrupts.

See datasheet for more details.

Parameters
devThe device context.
bitsOne or more of the KX122_INTERRUPT_T values. Combine with bitwise OR (|)
Returns
UPM result.

Here is the caller graph for this function:

upm_result_t kx122_route_interrupt2 ( const kx122_context  dev,
uint8_t  bits 
)

Routes the interrupts to the interrupt pin 2 of the sensor.

Sensor needs to be in standby mode when routing the interrupts.

See datasheet for more details.

Parameters
devThe device context.
bitsOne or more of the KX122_INTERRUPT_T values. Combine with bitwise OR (|)
Returns
UPM result.

Here is the caller graph for this function:

bool kx122_get_interrupt_status ( const kx122_context  dev)

Gets the status of the interrupts. (Has an interrupt occured)

See datasheet for more details.

Parameters
devThe device context.
Returns
Return true if an interrupt event has occured, returns false if no interrupts have occured.

Here is the caller graph for this function:

upm_result_t kx122_get_interrupt_source ( const kx122_context  dev,
uint8_t *  data 
)

Gets the source of the interrupt. The value stored is one or more of the KX122_INTERRUPT_T values, depending on the interrupts that have occured.

If multiple interrupts have occured, and you need to determine a specific interrupt, you can use masking to get the state of the specific interrupt: (int_source & KX122_DATA_READY_INT) == KX122_DATA_READY_INT)

See datasheet for more details.

Parameters
devThe device context.
dataPointer to a uint8_t variable to store the value.
Returns
UPM result.

Here is the caller graph for this function:

upm_result_t kx122_clear_interrupt ( const kx122_context  dev)

Clears latching interrupts (Wakeup, Data Ready).

See datasheet for more details.

Parameters
devThe device context.
Returns
UPM result.

Here is the caller graph for this function:

upm_result_t kx122_enable_data_ready_interrupt ( const kx122_context  dev)

Enables the data ready interrupt. Availability of new acceleration data is reflected as an interrupt.

Sensor needs to be in standby mode when enabling the interrupt.

Parameters
devThe device context.
Returns
UPM result.

Here is the caller graph for this function:

upm_result_t kx122_disable_data_ready_interrupt ( const kx122_context  dev)

Disables the data ready interrupt.

Sensor needs to be in standby mode when disabling the interrupt.

Parameters
devThe device context.
Returns
UPM result.

Here is the caller graph for this function:

upm_result_t kx122_enable_buffer_full_interrupt ( const kx122_context  dev)

Enables the buffer full interrupt. Buffer can hold 681 sets of values (8 bit, low resolution mode) or 340 sets of values (16 bit, high resolution mode).

Sensor needs to be in standby mode when enabling the interrupt.

Parameters
devThe device context.
Returns
UPM result.

Here is the caller graph for this function:

upm_result_t kx122_disable_buffer_full_interrupt ( const kx122_context  dev)

Disables the buffer full interrupt.

Sensor needs to be in standby mode when disabling the interrupt.

Parameters
devThe device context.
Returns
UPM result.

Here is the caller graph for this function:

upm_result_t kx122_enable_buffer ( const kx122_context  dev)

Enables the buffer.

Sensor needs to be in standby mode when enabling the buffer.

Parameters
devThe device context.
Returns
UPM result.

Here is the caller graph for this function:

upm_result_t kx122_disable_buffer ( const kx122_context  dev)

Disables the buffer.

Sensor needs to be in standby mode when disabling the buffer.

Parameters
devThe device context.
Returns
UPM result.

Here is the caller graph for this function:

upm_result_t kx122_buffer_init ( const kx122_context  dev,
uint  samples,
KX122_RES_T  res,
KX122_BUFFER_MODE_T  mode 
)

Initializes the buffer with the given sample watermark level, buffer resolution and buffer operating mode. Buffer is enabled after the initialization.

Sensor is automatically set into standby mode during the buffer initialization. Sensor is set to active mode after initialization.

See the other buffer functions for details about the different parameter values.

Parameters
devThe device context.
samplesAmount of samples to trigger the watermark interrupt.
resOne of the KX122_RES_T values.
modeOne of the KX122_BUFFER_MODE_T values.
Returns
UPM result.

Here is the call graph for this function:

Here is the caller graph for this function:

upm_result_t kx122_set_buffer_resolution ( const kx122_context  dev,
KX122_RES_T  res 
)

Sets the buffer resolution. Buffer resolution is indepedent of the sensor resolution.

Sensor needs to be in standby mode when setting the buffer resolution.

Parameters
devThe device context.
Returns
UPM result.

Here is the caller graph for this function:

upm_result_t kx122_set_buffer_threshold ( const kx122_context  dev,
uint  samples 
)

Sets the buffer watermark interrupt threshold. When the buffer sample count reaches the watermark, watermark interrupt will be given.

In low resolution mode, maxiumum number of samples is 681. In high resolution, the maximum number is 340.

See datasheet for more details.

Sensor needs to be in standby mode when setting the buffer threshold.

Parameters
devThe device context.
samplesAmount of samples to trigger the watermark interrupt.
Returns
UPM result.

Here is the caller graph for this function:

upm_result_t kx122_set_buffer_mode ( const kx122_context  dev,
KX122_BUFFER_MODE_T  mode 
)

Sets the buffer operating mode. The buffer can operate in FIFO,FILO or Stream mode. The buffer gathers data, reports data and interracts with the status indicators in a slightly different way depending on the operating mode.

See datasheet for more details.

Sensor needs to be in standby mode when setting the buffer mode.

Parameters
devThe device context.
modeOne of the KX122_BUFFER_MODE_T values.
Returns
UPM result.

Here is the caller graph for this function:

upm_result_t kx122_get_buffer_status ( const kx122_context  dev,
uint *  samples 
)

Gets the current amount of samples in the buffer.

Parameters
devThe device context.
samplesPointer to an uint variable to store the data.
Returns
UPM result.

Here is the caller graph for this function:

upm_result_t kx122_read_buffer_samples_raw ( const kx122_context  dev,
uint  len,
float *  x_array,
float *  y_array,
float *  z_array 
)

Gets the specified amount of raw acceleration samples from the buffer.

Make sure the array size is atleast the amount of samples to be read.

Parameters
devThe device context.
lenThe amount of samples to read from the buffer.
x_arrayPointer to an floating point array to store the x-axis data. Can be set to NULL if not wanted.
y_arrayPointer to an floating point array to store the y-axis data. Can be set to NULL if not wanted.
z_arrayPointer to an floating point array to store the z-axis data. Can be set to NULL if not wanted.
Returns
UPM result.

Here is the caller graph for this function:

upm_result_t kx122_read_buffer_samples ( const kx122_context  dev,
uint  len,
float *  x_array,
float *  y_array,
float *  z_array 
)

Gets the specified amount of converted (m/s^2) acceleration samples from the buffer.

Make sure the array size is atleast the amount of samples to be read.

Parameters
devThe device context.
lenThe amount of samples to read from the buffer.
x_arrayPointer to an floating point array to store the x-axis data. Can be set to NULL if not wanted.
y_arrayPointer to an floating point array to store the y-axis data. Can be set to NULL if not wanted.
z_arrayPointer to an floating point array to store the z-axis data. Can be set to NULL if not wanted.
Returns
UPM result.

Here is the call graph for this function:

Here is the caller graph for this function:

upm_result_t kx122_clear_buffer ( const kx122_context  dev)

Clears the buffer, removing all existing samples from the buffer.

Parameters
devThe device context.
Returns
UPM result.

Here is the caller graph for this function: