Mikkel Jakobsen | 0b0c2e7 | 2022-03-29 13:12:03 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2022 Esco Medical ApS |
| 3 | * Copyright (c) 2020 TDK Invensense |
| 4 | * |
| 5 | * SPDX-License-Identifier: Apache-2.0 |
| 6 | */ |
| 7 | |
| 8 | #ifndef ZEPHYR_DRIVERS_SENSOR_ICM42670_SPI_H_ |
| 9 | #define ZEPHYR_DRIVERS_SENSOR_ICM42670_SPI_H_ |
| 10 | |
Gerard Marull-Paretas | fb60aab | 2022-05-06 10:25:46 +0200 | [diff] [blame^] | 11 | #include <zephyr/device.h> |
| 12 | #include <zephyr/drivers/spi.h> |
Mikkel Jakobsen | 0b0c2e7 | 2022-03-29 13:12:03 +0200 | [diff] [blame] | 13 | |
| 14 | /** |
| 15 | * @brief perform a single SPI write to a ICM42670 register |
| 16 | * |
| 17 | * this functions wraps all logic necessary to write to any of the ICM42670 registers, regardless |
| 18 | * of which memory bank the register belongs to. |
| 19 | * |
| 20 | * @param bus SPI bus pointer |
| 21 | * @param reg address of ICM42670 register to write to |
| 22 | * @param data data byte to write to register |
| 23 | * @return int 0 on success, negative error code otherwise |
| 24 | */ |
| 25 | int icm42670_spi_single_write(const struct spi_dt_spec *bus, uint16_t reg, uint8_t data); |
| 26 | |
| 27 | /** |
| 28 | * @brief update a single ICM42670 register value |
| 29 | * |
| 30 | * this functions wraps all logic necessary to update any of the ICM42670 registers, regardless |
| 31 | * of which memory bank the register belongs to. |
| 32 | * |
| 33 | * @param bus SPI bus pointer |
| 34 | * @param reg address of ICM42670 register to update |
| 35 | * @param mask bitmask defining which bits of the register to update |
| 36 | * @param data new value to update register with, respecting the bitmask |
| 37 | * @return int 0 on success, negative error code otherwise |
| 38 | */ |
| 39 | int icm42670_spi_update_register(const struct spi_dt_spec *bus, uint16_t reg, uint8_t mask, |
| 40 | uint8_t data); |
| 41 | |
| 42 | /** |
| 43 | * @brief read from one or more ICM42670 registers |
| 44 | * |
| 45 | * this functions wraps all logic necessary to read from any of the ICM42670 registers, regardless |
| 46 | * of which memory bank the register belongs to. |
| 47 | * |
| 48 | * @param bus SPI bus pointer |
| 49 | * @param reg start address of ICM42670 register(s) to read from |
| 50 | * @param data pointer to byte array to read register values to |
| 51 | * @param len number of bytes to read from the device |
| 52 | * @return int 0 on success, negative error code otherwise |
| 53 | */ |
| 54 | int icm42670_spi_read(const struct spi_dt_spec *bus, uint16_t reg, uint8_t *data, size_t len); |
| 55 | |
| 56 | #endif /* ZEPHYR_DRIVERS_SENSOR_ICM42670_SPI_H_ */ |