Lines Matching +full:i2c +full:- +full:mode

4  * SPDX-License-Identifier: Apache-2.0
14 #include <zephyr/drivers/i2c.h>
135 struct i2c_dt_spec i2c; member
151 enum drv2605_mode mode; member
156 const struct drv2605_config *config = dev->config; in drv2605_haptic_config_audio()
157 struct drv2605_data *data = dev->data; in drv2605_haptic_config_audio()
160 ret = i2c_reg_update_byte_dt(&config->i2c, DRV2605_REG_CONTROL3, DRV2605_N_PWM_ANALOG, in drv2605_haptic_config_audio()
166 ret = i2c_reg_update_byte_dt(&config->i2c, DRV2605_REG_CONTROL1, DRV2605_AC_COUPLE, in drv2605_haptic_config_audio()
172 data->mode = DRV2605_MODE_AUDIO_TO_VIBE; in drv2605_haptic_config_audio()
179 const struct drv2605_config *config = dev->config; in drv2605_haptic_config_pwm_analog()
180 struct drv2605_data *data = dev->data; in drv2605_haptic_config_pwm_analog()
188 ret = i2c_reg_update_byte_dt(&config->i2c, DRV2605_REG_CONTROL3, DRV2605_N_PWM_ANALOG, in drv2605_haptic_config_pwm_analog()
194 data->mode = DRV2605_MODE_PWM_ANALOG_INPUT; in drv2605_haptic_config_pwm_analog()
202 const struct drv2605_rtp_data *rtp_data = data->rtp_data; in drv2605_rtp_work_handler()
203 const struct drv2605_config *config = data->dev->config; in drv2605_rtp_work_handler()
206 for (i = 0; i < rtp_data->size; i++) { in drv2605_rtp_work_handler()
207 i2c_reg_write_byte_dt(&config->i2c, DRV2605_REG_RT_PLAYBACK_INPUT, in drv2605_rtp_work_handler()
208 rtp_data->rtp_input[i]); in drv2605_rtp_work_handler()
209 k_usleep(rtp_data->rtp_hold_us[i]); in drv2605_rtp_work_handler()
216 const struct drv2605_config *config = dev->config; in drv2605_haptic_config_rtp()
217 struct drv2605_data *data = dev->data; in drv2605_haptic_config_rtp()
220 data->rtp_data = rtp_data; in drv2605_haptic_config_rtp()
222 ret = i2c_reg_write_byte_dt(&config->i2c, DRV2605_REG_RT_PLAYBACK_INPUT, 0); in drv2605_haptic_config_rtp()
227 ret = i2c_reg_update_byte_dt(&config->i2c, DRV2605_REG_MODE, DRV2605_MODE, in drv2605_haptic_config_rtp()
233 data->mode = DRV2605_MODE_RTP; in drv2605_haptic_config_rtp()
241 const struct drv2605_config *config = dev->config; in drv2605_haptic_config_rom()
243 struct drv2605_data *data = dev->data; in drv2605_haptic_config_rom()
246 switch (rom_data->trigger) { in drv2605_haptic_config_rom()
250 ret = i2c_reg_update_byte_dt(&config->i2c, DRV2605_REG_MODE, DRV2605_MODE, in drv2605_haptic_config_rom()
251 (uint8_t)rom_data->trigger); in drv2605_haptic_config_rom()
256 data->mode = rom_data->trigger; in drv2605_haptic_config_rom()
259 return -EINVAL; in drv2605_haptic_config_rom()
262 ret = i2c_reg_update_byte_dt(&config->i2c, DRV2605_REG_UNNAMED, DRV2605_LIBRARY_SEL, in drv2605_haptic_config_rom()
263 (uint8_t)rom_data->library); in drv2605_haptic_config_rom()
269 ret = i2c_reg_write_byte_dt(&config->i2c, reg_addr, rom_data->seq_regs[i]); in drv2605_haptic_config_rom()
276 if (rom_data->seq_regs[i] == 0U) { in drv2605_haptic_config_rom()
281 ret = i2c_reg_write_byte_dt(&config->i2c, DRV2605_REG_OVERDRIVE_TIME_OFFSET, in drv2605_haptic_config_rom()
282 rom_data->overdrive_time); in drv2605_haptic_config_rom()
287 ret = i2c_reg_write_byte_dt(&config->i2c, DRV2605_REG_SUSTAIN_TIME_OFFSET_POS, in drv2605_haptic_config_rom()
288 rom_data->sustain_pos_time); in drv2605_haptic_config_rom()
293 ret = i2c_reg_write_byte_dt(&config->i2c, DRV2605_REG_SUSTAIN_TIME_OFFSET_NEG, in drv2605_haptic_config_rom()
294 rom_data->sustain_neg_time); in drv2605_haptic_config_rom()
299 ret = i2c_reg_write_byte_dt(&config->i2c, DRV2605_REG_BRAKE_TIME_OFFSET, in drv2605_haptic_config_rom()
300 rom_data->brake_time); in drv2605_haptic_config_rom()
313 return drv2605_haptic_config_rom(dev, config_data->rom_data); in drv2605_haptic_config()
315 return drv2605_haptic_config_rtp(dev, config_data->rtp_data); in drv2605_haptic_config()
323 return -ENOTSUP; in drv2605_haptic_config()
331 const struct drv2605_config *config = dev->config; in drv2605_edge_mode_event()
334 ret = gpio_pin_set_dt(&config->in_trig_gpio, 1); in drv2605_edge_mode_event()
339 return gpio_pin_set_dt(&config->in_trig_gpio, 0); in drv2605_edge_mode_event()
344 const struct drv2605_config *config = dev->config; in drv2605_stop_output()
345 struct drv2605_data *data = dev->data; in drv2605_stop_output()
349 switch (data->mode) { in drv2605_stop_output()
352 ret = i2c_reg_read_byte_dt(&config->i2c, DRV2605_REG_GO, &value); in drv2605_stop_output()
358 LOG_DBG("Playback mode: %d is uninterruptible", data->mode); in drv2605_stop_output()
359 return -EBUSY; in drv2605_stop_output()
364 return i2c_reg_update_byte_dt(&config->i2c, DRV2605_REG_GO, DRV2605_GO, 0); in drv2605_stop_output()
368 return gpio_pin_set_dt(&config->in_trig_gpio, 0); in drv2605_stop_output()
371 ret = i2c_reg_update_byte_dt(&config->i2c, DRV2605_REG_MODE, DRV2605_MODE, in drv2605_stop_output()
377 return i2c_reg_update_byte_dt(&config->i2c, DRV2605_REG_GO, DRV2605_GO, 0); in drv2605_stop_output()
379 return k_work_cancel(&data->rtp_work); in drv2605_stop_output()
381 return -ENOTSUP; in drv2605_stop_output()
389 const struct drv2605_config *config = dev->config; in drv2605_start_output()
390 struct drv2605_data *data = dev->data; in drv2605_start_output()
392 switch (data->mode) { in drv2605_start_output()
396 return i2c_reg_update_byte_dt(&config->i2c, DRV2605_REG_GO, DRV2605_GO, DRV2605_GO); in drv2605_start_output()
400 return gpio_pin_set_dt(&config->in_trig_gpio, 1); in drv2605_start_output()
403 return i2c_reg_update_byte_dt(&config->i2c, DRV2605_REG_MODE, DRV2605_MODE, in drv2605_start_output()
404 (uint8_t)data->mode); in drv2605_start_output()
406 return k_work_submit(&data->rtp_work); in drv2605_start_output()
408 return -ENOTSUP; in drv2605_start_output()
417 const struct drv2605_config *config = dev->config; in drv2605_pm_action()
421 return i2c_reg_update_byte_dt(&config->i2c, DRV2605_REG_MODE, DRV2605_STANDBY, 0); in drv2605_pm_action()
423 return i2c_reg_update_byte_dt(&config->i2c, DRV2605_REG_MODE, DRV2605_STANDBY, in drv2605_pm_action()
426 if (config->en_gpio.port != NULL) { in drv2605_pm_action()
427 gpio_pin_set_dt(&config->en_gpio, 0); in drv2605_pm_action()
432 if (config->en_gpio.port != NULL) { in drv2605_pm_action()
433 gpio_pin_set_dt(&config->en_gpio, 1); in drv2605_pm_action()
438 return -ENOTSUP; in drv2605_pm_action()
447 const struct drv2605_config *config = dev->config; in drv2605_hw_config()
451 value = FIELD_PREP(DRV2605_N_ERM_LRA, config->actuator_mode) | in drv2605_hw_config()
452 FIELD_PREP(DRV2605_FB_BRAKE_FACTOR, config->feedback_brake_factor) | in drv2605_hw_config()
453 FIELD_PREP(DRV2605_LOOP_GAIN, config->loop_gain); in drv2605_hw_config()
457 ret = i2c_reg_update_byte_dt(&config->i2c, DRV2605_REG_FEEDBACK_CONTROL, mask, value); in drv2605_hw_config()
462 ret = i2c_reg_write_byte_dt(&config->i2c, DRV2605_REG_RATED_VOLTAGE, config->rated_voltage); in drv2605_hw_config()
467 ret = i2c_reg_write_byte_dt(&config->i2c, DRV2605_REG_OVERDRIVE_CLAMP_VOLTAGE, in drv2605_hw_config()
468 config->overdrive_clamp_voltage); in drv2605_hw_config()
473 if (config->actuator_mode == DRV2605_ACTUATOR_MODE_LRA) { in drv2605_hw_config()
474 ret = i2c_reg_update_byte_dt(&config->i2c, DRV2605_REG_CONTROL3, in drv2605_hw_config()
486 const struct drv2605_config *config = dev->config; in drv2605_reset()
490 i2c_reg_update_byte_dt(&config->i2c, DRV2605_REG_MODE, DRV2605_STANDBY, 0); in drv2605_reset()
492 ret = i2c_reg_update_byte_dt(&config->i2c, DRV2605_REG_MODE, DRV2605_DEV_RESET, in drv2605_reset()
501 retries--; in drv2605_reset()
503 ret = i2c_reg_read_byte_dt(&config->i2c, DRV2605_REG_MODE, &value); in drv2605_reset()
510 i2c_reg_update_byte_dt(&config->i2c, DRV2605_REG_MODE, DRV2605_STANDBY, 0); in drv2605_reset()
515 return -ETIMEDOUT; in drv2605_reset()
520 const struct drv2605_config *config = dev->config; in drv2605_check_devid()
524 ret = i2c_reg_read_byte_dt(&config->i2c, DRV2605_REG_STATUS, &value); in drv2605_check_devid()
537 return -ENOTSUP; in drv2605_check_devid()
547 const struct drv2605_config *config = dev->config; in drv2605_gpio_config()
550 if (config->en_gpio.port != NULL) { in drv2605_gpio_config()
551 if (!gpio_is_ready_dt(&config->en_gpio)) { in drv2605_gpio_config()
552 return -ENODEV; in drv2605_gpio_config()
555 ret = gpio_pin_configure_dt(&config->en_gpio, GPIO_OUTPUT_ACTIVE); in drv2605_gpio_config()
561 if (config->in_trig_gpio.port != NULL) { in drv2605_gpio_config()
562 if (!gpio_is_ready_dt(&config->in_trig_gpio)) { in drv2605_gpio_config()
563 return -ENODEV; in drv2605_gpio_config()
566 ret = gpio_pin_configure_dt(&config->in_trig_gpio, GPIO_OUTPUT_INACTIVE); in drv2605_gpio_config()
577 const struct drv2605_config *config = dev->config; in drv2605_init()
578 struct drv2605_data *data = dev->data; in drv2605_init()
581 data->dev = dev; in drv2605_init()
585 if (!i2c_is_ready_dt(&config->i2c)) { in drv2605_init()
586 return -ENODEV; in drv2605_init()
589 k_work_init(&data->rtp_work, drv2605_rtp_work_handler); in drv2605_init()
625 .i2c = I2C_DT_SPEC_INST_GET(inst), \
637 .mode = DRV2605_MODE_INTERNAL_TRIGGER, \