Lines Matching +full:data +full:- +full:shift
3 * SPDX-License-Identifier: Apache-2.0
31 struct icm42688_emul_data *data = target->data; in icm42688_emul_set_reg() local
34 memcpy(data->reg + reg_addr, val, count); in icm42688_emul_set_reg()
39 struct icm42688_emul_data *data = target->data; in icm42688_emul_get_reg() local
42 memcpy(val, data->reg + reg_addr, count); in icm42688_emul_get_reg()
47 struct icm42688_emul_data *data = target->data; in icm42688_emul_handle_write() local
53 memset(data->reg, 0, NUM_REGS); in icm42688_emul_handle_write()
54 /* Initialized the who-am-i register */ in icm42688_emul_handle_write()
55 data->reg[REG_WHO_AM_I] = WHO_AM_I_ICM42688; in icm42688_emul_handle_write()
57 data->reg[REG_INT_STATUS] |= BIT_INT_STATUS_RESET_DONE; in icm42688_emul_handle_write()
67 struct icm42688_emul_data *data = target->data; in icm42688_emul_io_spi() local
75 tx = tx_bufs->buffers; in icm42688_emul_io_spi()
77 __ASSERT_NO_MSG(tx->len > 0); in icm42688_emul_io_spi()
79 regn = *(uint8_t *)tx->buf; in icm42688_emul_io_spi()
84 __ASSERT_NO_MSG(rx_bufs->count > 1); in icm42688_emul_io_spi()
86 rx = &rx_bufs->buffers[1]; in icm42688_emul_io_spi()
87 __ASSERT_NO_MSG(rx->buf != NULL); in icm42688_emul_io_spi()
88 __ASSERT_NO_MSG(rx->len > 0); in icm42688_emul_io_spi()
89 for (uint16_t i = 0; i < rx->len; ++i) { in icm42688_emul_io_spi()
90 ((uint8_t *)rx->buf)[i] = data->reg[regn + i]; in icm42688_emul_io_spi()
96 __ASSERT_NO_MSG(tx_bufs->count > 1); in icm42688_emul_io_spi()
97 tx = &tx_bufs->buffers[1]; in icm42688_emul_io_spi()
99 __ASSERT_NO_MSG(tx->len > 0); in icm42688_emul_io_spi()
100 value = ((uint8_t *)tx->buf)[0]; in icm42688_emul_io_spi()
109 struct icm42688_emul_data *data = target->data; in icm42688_emul_init() local
111 /* Initialized the who-am-i register */ in icm42688_emul_init()
112 data->reg[REG_WHO_AM_I] = WHO_AM_I_ICM42688; in icm42688_emul_init()
124 * @brief Get current full-scale range in g's based on register config, along with corresponding
125 * sensitivity and shift. See datasheet section 3.2, table 2.
128 int8_t *shift) in icm42688_emul_get_accel_settings() argument
141 /* shift is based on `fs_g * 9.8` since the final numbers will be in SI units of in icm42688_emul_get_accel_settings()
171 if (shift) { in icm42688_emul_get_accel_settings()
172 *shift = shift_out; in icm42688_emul_get_accel_settings()
177 * @brief Helper function for calculating accelerometer ranges. Considers the current full-scale
178 * register config (i.e. +/-2g, +/-4g, etc...)
181 q31_t *epsilon, int8_t *shift) in icm42688_emul_get_accel_ranges() argument
186 icm42688_emul_get_accel_settings(target, &fs_g, &sensitivity, shift); in icm42688_emul_get_accel_ranges()
188 /* Epsilon is equal to 1.5 bit-counts worth of error. */ in icm42688_emul_get_accel_ranges()
189 *epsilon = (3 * SENSOR_G * Q31_SCALE / sensitivity / 1000000LL / 2) >> *shift; in icm42688_emul_get_accel_ranges()
190 *upper = (fs_g * SENSOR_G * Q31_SCALE / 1000000LL) >> *shift; in icm42688_emul_get_accel_ranges()
191 *lower = -*upper; in icm42688_emul_get_accel_ranges()
195 * @brief Get current full-scale gyro range in milli-degrees per second based on register config,
196 * along with corresponding sensitivity and shift. See datasheet section 3.1, table 1.
199 int *sensitivity, int8_t *shift) in icm42688_emul_get_gyro_settings() argument
210 /* Milli-degrees per second */ in icm42688_emul_get_gyro_settings()
215 shift_out = 6; /* +/- 34.90659 */ in icm42688_emul_get_gyro_settings()
220 shift_out = 5; /* +/- 17.44444 */ in icm42688_emul_get_gyro_settings()
225 shift_out = 4; /* +/- 8.72222 */ in icm42688_emul_get_gyro_settings()
230 shift_out = 3; /* +/- 4.36111 */ in icm42688_emul_get_gyro_settings()
235 shift_out = 2; /* +/- 2.18055 */ in icm42688_emul_get_gyro_settings()
240 shift_out = 1; /* +/- 1.09027 */ in icm42688_emul_get_gyro_settings()
245 shift_out = 0; /* +/- 0.54513 */ in icm42688_emul_get_gyro_settings()
250 shift_out = -1; /* +/- 0.27256 */ in icm42688_emul_get_gyro_settings()
262 if (shift) { in icm42688_emul_get_gyro_settings()
263 *shift = shift_out; in icm42688_emul_get_gyro_settings()
268 * @brief Helper function for calculating gyroscope ranges. Considers the current full-scale
272 q31_t *epsilon, int8_t *shift) in icm42688_emul_get_gyro_ranges() argument
279 icm42688_emul_get_gyro_settings(target, &fs_mdps, &sensitivity, shift); in icm42688_emul_get_gyro_ranges()
281 /* Reduce the actual range of gyroscope values. Some full-scale ranges actually exceed the in icm42688_emul_get_gyro_ranges()
282 * size of an int16 by a small margin. For example, FS_SEL=0 has a +/-2000 deg/s range with in icm42688_emul_get_gyro_ranges()
284 * +/-2000 * 16.4 = +/-32800. This will cause the expected value to get clipped when in icm42688_emul_get_gyro_ranges()
291 /* Epsilon is equal to 1.5 bit-counts worth of error. */ in icm42688_emul_get_gyro_ranges()
293 *shift; in icm42688_emul_get_gyro_ranges()
294 *upper = (((fs_mdps * SENSOR_PI / 1000000LL) * Q31_SCALE) / 1000LL / 180LL) >> *shift; in icm42688_emul_get_gyro_ranges()
295 *lower = -*upper; in icm42688_emul_get_gyro_ranges()
300 q31_t *upper, q31_t *epsilon, int8_t *shift) in icm42688_emul_backend_get_sample_range() argument
302 if (!lower || !upper || !epsilon || !shift) { in icm42688_emul_backend_get_sample_range()
303 return -EINVAL; in icm42688_emul_backend_get_sample_range()
308 /* degrees C = ([16-bit signed temp_data register] / 132.48) + 25 */ in icm42688_emul_backend_get_sample_range()
309 *shift = 9; in icm42688_emul_backend_get_sample_range()
310 *lower = (int64_t)(-222.342995169 * Q31_SCALE) >> *shift; in icm42688_emul_backend_get_sample_range()
311 *upper = (int64_t)(272.33544686 * Q31_SCALE) >> *shift; in icm42688_emul_backend_get_sample_range()
312 *epsilon = (int64_t)(0.0076 * Q31_SCALE) >> *shift; in icm42688_emul_backend_get_sample_range()
317 icm42688_emul_get_accel_ranges(target, lower, upper, epsilon, shift); in icm42688_emul_backend_get_sample_range()
322 icm42688_emul_get_gyro_ranges(target, lower, upper, epsilon, shift); in icm42688_emul_backend_get_sample_range()
325 return -ENOTSUP; in icm42688_emul_backend_get_sample_range()
332 const q31_t *value, int8_t shift) in icm42688_emul_backend_set_channel() argument
334 if (!target || !target->data) { in icm42688_emul_backend_set_channel()
335 return -EINVAL; in icm42688_emul_backend_set_channel()
338 struct icm42688_emul_data *data = target->data; in icm42688_emul_backend_set_channel() local
344 shift < 0 ? ((int64_t)*value >> -shift) : ((int64_t)*value << shift); in icm42688_emul_backend_set_channel()
349 reg_val = ((value_unshifted - (25 * Q31_SCALE)) * 13248) / (100 * Q31_SCALE); in icm42688_emul_backend_set_channel()
393 return -ENOTSUP; in icm42688_emul_backend_set_channel()
396 data->reg[reg_addr] = (reg_val >> 8) & 0xFF; in icm42688_emul_backend_set_channel()
397 data->reg[reg_addr + 1] = reg_val & 0xFF; in icm42688_emul_backend_set_channel()
399 /* Set data ready flag */ in icm42688_emul_backend_set_channel()
400 data->reg[REG_INT_STATUS] |= BIT_INT_STATUS_DATA_RDY; in icm42688_emul_backend_set_channel()