Lines Matching +full:i2c +full:- +full:mode
4 * SPDX-License-Identifier: Apache-2.0
7 #include <zephyr/drivers/i2c.h>
72 /* The sensor device returns 10^-9 Teslas after scaling. in ak8963_convert_magn()
80 return -EOVERFLOW; in ak8963_convert_magn()
85 val->val1 = scaled_val / 1000000; in ak8963_convert_magn()
86 val->val2 = scaled_val % 1000000; in ak8963_convert_magn()
93 /* Instruct the MPU9250 to access over its external i2c bus in ak8963_execute_rw()
96 const struct mpu9250_config *cfg = dev->config; in ak8963_execute_rw()
105 /* Set target i2c address */ in ak8963_execute_rw()
106 ret = i2c_reg_write_byte_dt(&cfg->i2c, in ak8963_execute_rw()
110 LOG_ERR("Failed to write i2c target slave address."); in ak8963_execute_rw()
114 /* Set target i2c register */ in ak8963_execute_rw()
115 ret = i2c_reg_write_byte_dt(&cfg->i2c, in ak8963_execute_rw()
119 LOG_ERR("Failed to write i2c target slave register."); in ak8963_execute_rw()
124 ret = i2c_reg_write_byte_dt(&cfg->i2c, in ak8963_execute_rw()
128 LOG_ERR("Failed to initiate i2c slave transfer."); in ak8963_execute_rw()
134 ret = i2c_reg_read_byte_dt(&cfg->i2c, in ak8963_execute_rw()
147 const struct mpu9250_config *cfg = dev->config; in ak8963_read_reg()
158 ret = i2c_reg_read_byte_dt(&cfg->i2c, in ak8963_read_reg()
170 const struct mpu9250_config *cfg = dev->config; in ak8963_write_reg()
174 ret = i2c_reg_write_byte_dt(&cfg->i2c, in ak8963_write_reg()
192 static int ak8963_set_mode(const struct device *dev, uint8_t mode) in ak8963_set_mode() argument
196 ret = ak8963_write_reg(dev, AK8963_REG_CNTL1, mode); in ak8963_set_mode()
198 LOG_ERR("Failed to set AK8963 mode."); in ak8963_set_mode()
202 /* Wait for mode to change */ in ak8963_set_mode()
215 * -> 0.1499 * 10^4 = 1499 in ak8963_calc_adj()
218 * Calculation from MPU-9250 Register Map and Descriptions in ak8963_calc_adj()
219 * adj = (((val-128)*0.5)/128)+1 in ak8963_calc_adj()
221 return ((AK9863_SCALE_TO_UG * (val - 128)) / 256) + AK9863_SCALE_TO_UG; in ak8963_calc_adj()
227 struct mpu9250_data *drv_data = dev->data; in ak8963_fetch_adj()
231 /* Change to FUSE access mode to access adjustment registers */ in ak8963_fetch_adj()
234 LOG_ERR("Failed to set chip in fuse access mode."); in ak8963_fetch_adj()
243 drv_data->magn_scale_x = ak8963_calc_adj(buf); in ak8963_fetch_adj()
250 drv_data->magn_scale_y = ak8963_calc_adj(buf); in ak8963_fetch_adj()
257 drv_data->magn_scale_z = ak8963_calc_adj(buf); in ak8963_fetch_adj()
259 /* Change back to the powerdown mode */ in ak8963_fetch_adj()
262 LOG_ERR("Failed to set chip in power down mode."); in ak8963_fetch_adj()
266 LOG_DBG("Adjustment values %d %d %d", drv_data->magn_scale_x, in ak8963_fetch_adj()
267 drv_data->magn_scale_y, drv_data->magn_scale_z); in ak8963_fetch_adj()
276 /* Reset the chip -> reset all settings. */ in ak8963_reset()
292 const struct mpu9250_config *cfg = dev->config; in ak8963_init_master()
295 /* Instruct MPU9250 to use its external I2C bus as master */ in ak8963_init_master()
296 ret = i2c_reg_write_byte_dt(&cfg->i2c, in ak8963_init_master()
300 LOG_ERR("Failed to set MPU9250 master i2c mode."); in ak8963_init_master()
304 /* Set MPU9250 I2C bus as 400kHz and issue interrupt at data ready. */ in ak8963_init_master()
305 ret = i2c_reg_write_byte_dt(&cfg->i2c, in ak8963_init_master()
309 LOG_ERR("Failed to set MPU9250 master i2c speed."); in ak8963_init_master()
318 const struct mpu9250_config *cfg = dev->config; in ak8963_init_readout()
321 /* Set target i2c address */ in ak8963_init_readout()
322 ret = i2c_reg_write_byte_dt(&cfg->i2c, in ak8963_init_readout()
331 ret = i2c_reg_write_byte_dt(&cfg->i2c, in ak8963_init_readout()
339 ret = i2c_reg_write_byte_dt(&cfg->i2c, in ak8963_init_readout()
357 LOG_ERR("Initializing MPU9250 master mode failed."); in ak8963_init()
376 return -ENOTSUP; in ak8963_init()