34 #include <sys/types.h> 38 #include <mraa/gpio.h> 42 #include "kx122_registers.h" 53 #define DEFAULT_SPI_FREQUENCY 10000 56 #define KX122_DEFAULT_SLAVE_ADDR_1 0x1F 57 #define KX122_DEFAULT_SLAVE_ADDR_2 0x1E 60 #define MICRO_S 1000000 64 KX122_ODR_12P5 = KX122_ODCNTL_OSA_12P5,
65 KX122_ODR_25 = KX122_ODCNTL_OSA_25,
66 KX122_ODR_50 = KX122_ODCNTL_OSA_50,
67 KX122_ODR_100 = KX122_ODCNTL_OSA_100,
68 KX122_ODR_200 = KX122_ODCNTL_OSA_200,
69 KX122_ODR_400 = KX122_ODCNTL_OSA_400,
70 KX122_ODR_800 = KX122_ODCNTL_OSA_800,
71 KX122_ODR_1600 = KX122_ODCNTL_OSA_1600,
72 KX122_ODR_0P781 = KX122_ODCNTL_OSA_0P781,
73 KX122_ODR_1P563 = KX122_ODCNTL_OSA_1P563,
74 KX122_ODR_3P125 = KX122_ODCNTL_OSA_3P125,
75 KX122_ODR_6P25 = KX122_ODCNTL_OSA_6P25,
76 KX122_ODR_3200 = KX122_ODCNTL_OSA_3200,
77 KX122_ODR_6400 = KX122_ODCNTL_OSA_6400,
78 KX122_ODR_12800 = KX122_ODCNTL_OSA_12800,
79 KX122_ODR_25600 = KX122_ODCNTL_OSA_25600
84 KX122_NO_AVG = KX122_LP_CNTL_AVC_NO_AVG,
85 KX122_2_SAMPLE_AVG = KX122_LP_CNTL_AVC_2_SAMPLE_AVG,
86 KX122_4_SAMPLE_AVG = KX122_LP_CNTL_AVC_4_SAMPLE_AVG,
87 KX122_8_SAMPLE_AVG = KX122_LP_CNTL_AVC_8_SAMPLE_AVG,
88 KX122_16_SAMPLE_AVG = KX122_LP_CNTL_AVC_16_SAMPLE_AVG,
89 KX122_32_SAMPLE_AVG = KX122_LP_CNTL_AVC_32_SAMPLE_AVG,
90 KX122_64_SAMPLE_AVG = KX122_LP_CNTL_AVC_64_SAMPLE_AVG,
91 KX122_128_SAMPLE_AVG = KX122_LP_CNTL_AVC_128_SAMPLE_AVG
96 KX122_RANGE_2G = KX122_CNTL1_GSEL_2G,
97 KX122_RANGE_4G = KX122_CNTL1_GSEL_4G,
98 KX122_RANGE_8G = KX122_CNTL1_GSEL_8G
103 KX122_FIFO_MODE = KX122_BUF_CNTL2_BUF_M_FIFO,
104 KX122_FILO_MODE = KX122_BUF_CNTL2_BUF_M_FILO,
105 KX122_STREAM_MODE = KX122_BUF_CNTL2_BUF_M_STREAM,
106 } KX122_BUFFER_MODE_T;
110 KX122_BUF_FULL_INT = KX122_INC4_BFI1,
111 KX122_WATERMARK_INT = KX122_INC4_WMI1,
112 KX122_DATA_READY_INT = KX122_INC4_DRDYI1
131 }KX122_INTERRUPT_PIN_T;
137 } KX122_INTERRUPT_POLARITY_T;
141 mraa_i2c_context i2c;
142 mraa_spi_context spi;
143 mraa_gpio_context gpio1;
144 mraa_gpio_context gpio2;
145 mraa_gpio_context chip_select;
148 KX122_RES_T res_mode;
149 KX122_RANGE_T grange_mode;
151 float buffer_accel_scale;
152 KX122_BUFFER_MODE_T buffer_mode;
153 KX122_RES_T buffer_res;
379 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);
upm_result_t kx122_get_acceleration_data(const kx122_context dev, float *x, float *y, float *z)
Definition: kx122.c:557
upm_result_t kx122_read_buffer_samples_raw(const kx122_context dev, uint len, float *x_array, float *y_array, float *z_array)
Definition: kx122.c:1001
upm_result_t kx122_set_buffer_mode(const kx122_context dev, KX122_BUFFER_MODE_T mode)
Definition: kx122.c:957
upm_result_t kx122_disable_interrupt1(const kx122_context dev)
Definition: kx122.c:811
upm_result_t kx122_clear_buffer(const kx122_context dev)
Definition: kx122.c:965
upm_result_t kx122_disable_data_ready_interrupt(const kx122_context dev)
Definition: kx122.c:841
bool kx122_get_interrupt_status(const kx122_context dev)
Definition: kx122.c:873
upm_result_t kx122_disable_interrupt2(const kx122_context dev)
Definition: kx122.c:817
upm_result_t kx122_disable_iir(const kx122_context dev)
Definition: kx122.c:613
upm_result_t kx122_set_odr(const kx122_context dev, KX122_ODR_T odr)
Definition: kx122.c:698
upm_result_t kx122_enable_interrupt1(const kx122_context dev, KX122_INTERRUPT_POLARITY_T polarity)
Definition: kx122.c:787
upm_result_t kx122_enable_data_ready_interrupt(const kx122_context dev)
Definition: kx122.c:835
upm_result_t kx122_get_acceleration_data_raw(const kx122_context dev, float *x, float *y, float *z)
Definition: kx122.c:520
void kx122_uninstall_isr(const kx122_context dev, KX122_INTERRUPT_PIN_T intp)
Definition: kx122.c:772
upm_result_t kx122_set_buffer_threshold(const kx122_context dev, uint samples)
Definition: kx122.c:934
upm_result_t kx122_set_sensor_standby(const kx122_context dev)
Definition: kx122.c:504
upm_result_t kx122_buffer_init(const kx122_context dev, uint samples, KX122_RES_T res, KX122_BUFFER_MODE_T mode)
Definition: kx122.c:901
upm_result_t kx122_route_interrupt2(const kx122_context dev, uint8_t bits)
Definition: kx122.c:829
upm_result_t kx122_sensor_software_reset(const kx122_context dev)
Definition: kx122.c:578
upm_result_t kx122_clear_interrupt(const kx122_context dev)
Definition: kx122.c:865
kx122_context kx122_init(int bus, int addr, int chip_select_pin, int spi_bus_frequency)
Definition: kx122.c:164
upm_result_t kx122_set_sensor_active(const kx122_context dev)
Definition: kx122.c:510
upm_result_t kx122_get_who_am_i(const kx122_context dev, uint8_t *data)
Definition: kx122.c:498
upm_result_t kx122_enable_buffer_full_interrupt(const kx122_context dev)
Definition: kx122.c:847
upm_result_t kx122_get_buffer_status(const kx122_context dev, uint *samples)
Definition: kx122.c:971
upm_result_t kx122_enable_interrupt2(const kx122_context dev, KX122_INTERRUPT_POLARITY_T polarity)
Definition: kx122.c:799
upm_result_t kx122_enable_buffer(const kx122_context dev)
Definition: kx122.c:889
upm_result_t kx122_disable_buffer_full_interrupt(const kx122_context dev)
Definition: kx122.c:853
upm_result_t kx122_route_interrupt1(const kx122_context dev, uint8_t bits)
Definition: kx122.c:823
upm_result_t kx122_self_test(const kx122_context dev)
Definition: kx122.c:619
upm_result_t kx122_device_init(const kx122_context dev, KX122_ODR_T odr, KX122_RES_T res, KX122_RANGE_T grange)
Definition: kx122.c:479
upm_result_t kx122_set_buffer_resolution(const kx122_context dev, KX122_RES_T res)
Definition: kx122.c:922
upm_result_t kx122_set_grange(const kx122_context dev, KX122_RANGE_T grange)
Definition: kx122.c:704
void kx122_close(kx122_context dev)
Definition: kx122.c:249
upm_result_t kx122_get_interrupt_source(const kx122_context dev, uint8_t *data)
Definition: kx122.c:859
upm_result_t kx122_read_buffer_samples(const kx122_context dev, uint len, float *x_array, float *y_array, float *z_array)
Definition: kx122.c:1073
upm_result_t kx122_set_bw(const kx122_context dev, LPRO_STATE_T lpro)
Definition: kx122.c:727
upm_result_t kx122_disable_buffer(const kx122_context dev)
Definition: kx122.c:895
upm_result_t kx122_set_resolution(const kx122_context dev, KX122_RES_T res)
Definition: kx122.c:712
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)
Definition: kx122.c:744
float kx122_get_sample_period(const kx122_context dev)
Definition: kx122.c:455
upm_result_t kx122_enable_iir(const kx122_context dev)
Definition: kx122.c:607
upm_result_t kx122_set_average(const kx122_context dev, KX122_AVG_T avg)
Definition: kx122.c:738