36 #include <mraa/gpio.h> 39 #include "kxtj3_registers.h" 62 #define SECOND_IN_MICRO_S 1000000 81 } KXTJ3_INTERRUPT_POLARITY_T;
90 } KXTJ3_INTERRUPT_RESPONSE_T;
98 KXTJ3_DATA_READY_INTERRUPT = KXTJ3_INT_SOURCE1_DRDY,
99 KXTJ3_WAKEUP_INTERRUPT = KXTJ3_INT_SOURCE1_WUFS,
100 KXTJ3_DATA_READY_AND_WAKEUP_INT = KXTJ3_INT_SOURCE1_DRDY | KXTJ3_INT_SOURCE1_WUFS
101 } KXTJ3_INTERRUPT_SOURCE_T;
108 KXTJ3_RANGE_2G = KXTJ3_CTRL_REG1_GSEL_2G,
109 KXTJ3_RANGE_4G = KXTJ3_CTRL_REG1_GSEL_4G,
110 KXTJ3_RANGE_8G = KXTJ3_CTRL_REG1_GSEL_8G,
111 KXTJ3_RANGE_8G_14 = KXTJ3_CTRL_REG1_GSEL_8G_14,
112 KXTJ3_RANGE_16G = KXTJ3_CTRL_REG1_GSEL_16G,
113 KXTJ3_RANGE_16G_2 = KXTJ3_CTRL_REG1_GSEL_16G2,
114 KXTJ3_RANGE_16G_3 = KXTJ3_CTRL_REG1_GSEL_16G3,
115 KXTJ3_RANGE_16G_14 = KXTJ3_CTRL_REG1_GSEL_16G_14
123 KXTJ3_ODR_0P781 = KXTJ3_DATA_CTRL_REG_OSA_0P781,
124 KXTJ3_ODR_1P563 = KXTJ3_DATA_CTRL_REG_OSA_1P563,
125 KXTJ3_ODR_3P125 = KXTJ3_DATA_CTRL_REG_OSA_3P125,
126 KXTJ3_ODR_6P25 = KXTJ3_DATA_CTRL_REG_OSA_6P25,
127 KXTJ3_ODR_12P5 = KXTJ3_DATA_CTRL_REG_OSA_12P5,
128 KXTJ3_ODR_25 = KXTJ3_DATA_CTRL_REG_OSA_25,
129 KXTJ3_ODR_50 = KXTJ3_DATA_CTRL_REG_OSA_50,
130 KXTJ3_ODR_100 = KXTJ3_DATA_CTRL_REG_OSA_100,
131 KXTJ3_ODR_200 = KXTJ3_DATA_CTRL_REG_OSA_200,
132 KXTJ3_ODR_400 = KXTJ3_DATA_CTRL_REG_OSA_400,
133 KXTJ3_ODR_800 = KXTJ3_DATA_CTRL_REG_OSA_800,
134 KXTJ3_ODR_1600 = KXTJ3_DATA_CTRL_REG_OSA_1600
142 KXTJ3_ODR_WAKEUP_0P781 = KXTJ3_CTRL_REG2_OWUF_0P781,
143 KXTJ3_ODR_WAKEUP_1P563 = KXTJ3_CTRL_REG2_OWUF_1P563,
144 KXTJ3_ODR_WAKEUP_3P125 = KXTJ3_CTRL_REG2_OWUF_3P125,
145 KXTJ3_ODR_WAKEUP_6P25 = KXTJ3_CTRL_REG2_OWUF_6P25,
146 KXTJ3_ODR_WAKEUP_12P5 = KXTJ3_CTRL_REG2_OWUF_12P5,
147 KXTJ3_ODR_WAKEUP_25 = KXTJ3_CTRL_REG2_OWUF_25,
148 KXTJ3_ODR_WAKEUP_50 = KXTJ3_CTRL_REG2_OWUF_50,
149 KXTJ3_ODR_WAKEUP_100 = KXTJ3_CTRL_REG2_OWUF_100
150 } KXTJ3_ODR_WAKEUP_T;
157 X_NEGATIVE = KXTJ3_INT_CTRL_REG2_XNWU,
158 X_POSITIVE = KXTJ3_INT_CTRL_REG2_XPWU,
159 Y_NEGATIVE = KXTJ3_INT_CTRL_REG2_YNWU,
160 Y_POSITIVE = KXTJ3_INT_CTRL_REG2_YPWU,
161 Z_NEGATIVE = KXTJ3_INT_CTRL_REG2_ZNWU,
162 Z_POSITIVE = KXTJ3_INT_CTRL_REG2_ZPWU
163 } KXTJ3_WAKEUP_SOURCE_T;
183 mraa_i2c_context i2c;
184 KXTJ3_RESOLUTION_T res_mode;
185 KXTJ3_G_RANGE_T g_range_mode;
186 float acceleration_scale;
189 KXTJ3_ODR_WAKEUP_T odr_wakeup;
190 float odr_in_sec_wakeup;
191 mraa_gpio_context interrupt_pin;
219 upm_result_t kxtj3_sensor_init(
const kxtj3_context dev, KXTJ3_ODR_T odr, KXTJ3_RESOLUTION_T res, KXTJ3_G_RANGE_T g_range);
228 upm_result_t kxtj3_get_who_am_i(
const kxtj3_context dev, uint8_t *data);
245 upm_result_t kxtj3_set_sensor_active(
const kxtj3_context dev);
253 upm_result_t kxtj3_set_sensor_standby(
const kxtj3_context dev);
268 upm_result_t kxtj3_set_g_range(
const kxtj3_context dev, KXTJ3_G_RANGE_T g_range);
285 upm_result_t kxtj3_set_resolution(
const kxtj3_context dev, KXTJ3_RESOLUTION_T resolution);
296 upm_result_t kxtj3_set_odr(
const kxtj3_context dev, KXTJ3_ODR_T odr);
307 upm_result_t kxtj3_set_odr_wakeup_function(
const kxtj3_context dev, KXTJ3_ODR_WAKEUP_T odr);
321 upm_result_t kxtj3_self_test_digital_communication(
kxtj3_context dev);
336 upm_result_t kxtj3_sensor_self_test(
const kxtj3_context dev);
349 upm_result_t kxtj3_sensor_software_reset(
const kxtj3_context dev);
360 upm_result_t kxtj3_get_acceleration_data_raw(
const kxtj3_context dev,
float *x,
float *y,
float *z);
370 upm_result_t kxtj3_get_acceleration_data(
const kxtj3_context dev,
float *x,
float *y,
float *z);
379 float kxtj3_get_acceleration_sampling_period(
kxtj3_context dev);
399 upm_result_t kxtj3_enable_data_ready_interrupt(
const kxtj3_context dev);
409 upm_result_t kxtj3_disable_data_ready_interrupt(
const kxtj3_context dev);
419 upm_result_t kxtj3_enable_wakeup_interrupt(
const kxtj3_context dev);
429 upm_result_t kxtj3_disable_wakeup_interrupt(
const kxtj3_context dev);
450 upm_result_t kxtj3_enable_interrupt_pin(
const kxtj3_context dev, KXTJ3_INTERRUPT_POLARITY_T polarity, KXTJ3_INTERRUPT_RESPONSE_T response_type);
460 upm_result_t kxtj3_disable_interrupt_pin(
const kxtj3_context dev);
473 upm_result_t kxtj3_set_interrupt_polarity(
const kxtj3_context dev, KXTJ3_INTERRUPT_POLARITY_T polarity);
491 upm_result_t kxtj3_set_interrupt_response(
const kxtj3_context dev, KXTJ3_INTERRUPT_RESPONSE_T response_type);
513 upm_result_t kxtj3_read_interrupt_source1_reg(
const kxtj3_context dev, uint8_t *reg_value);
523 KXTJ3_INTERRUPT_SOURCE_T kxtj3_get_interrupt_source(
const kxtj3_context dev);
535 upm_result_t kxtj3_install_isr(
const kxtj3_context dev, mraa_gpio_edge_t edge,
int pin,
void (*isr)(
void *),
void *isr_args);
553 upm_result_t kxtj3_clear_interrupt_information(
kxtj3_context dev);
564 upm_result_t kxtj3_enable_wakeup_single_axis_direction(
kxtj3_context dev, KXTJ3_WAKEUP_SOURCE_T axis);
575 upm_result_t kxtj3_disable_wakeup_single_axis_direction(
kxtj3_context dev, KXTJ3_WAKEUP_SOURCE_T axis);
634 upm_result_t kxtj3_set_wakeup_motion_counter(
kxtj3_context dev, uint8_t count);
649 upm_result_t kxtj3_set_wakeup_motion_time(
kxtj3_context dev,
float desired_time);
658 upm_result_t kxtj3_get_wakeup_motion_time(
kxtj3_context dev,
float *out_time);
676 upm_result_t kxtj3_set_wakeup_non_activity_counter(
kxtj3_context dev, uint8_t count);
691 upm_result_t kxtj3_set_wakeup_non_activity_time(
kxtj3_context dev,
float desired_time);
700 upm_result_t kxtj3_get_wakeup_non_activity_time(
kxtj3_context dev,
float *out_time);
717 upm_result_t kxtj3_set_wakeup_threshold_counter(
kxtj3_context dev, uint16_t count);
733 upm_result_t kxtj3_set_wakeup_threshold_g_value(
kxtj3_context dev,
float g_threshold);
742 upm_result_t kxtj3_get_wakeup_threshold(
kxtj3_context dev,
float *out_threshold);
Use it to get axis and direction for wake-up function.
Definition: kxtj3.h:168
Sensor context.
Definition: kxtj3.h:181