1 /* ist8310.h - header file for IST8310 Geomagnetic sensor driver */ 2 3 /* 4 * Copyright (c) 2023 NXP Semiconductors 5 * Copyright (c) 2023 Cognipilot Foundation 6 * 7 * SPDX-License-Identifier: Apache-2.0 8 */ 9 10 #ifndef ZEPHYR_DRIVERS_SENSOR_IST8310_IST8310_H_ 11 #define ZEPHYR_DRIVERS_SENSOR_IST8310_IST8310_H_ 12 13 #include <zephyr/types.h> 14 #include <zephyr/device.h> 15 #include <zephyr/devicetree.h> 16 #include <zephyr/drivers/spi.h> 17 #include <zephyr/drivers/i2c.h> 18 #include <zephyr/sys/util.h> 19 #include <zephyr/kernel.h> 20 #include <zephyr/device.h> 21 #include <zephyr/drivers/sensor.h> 22 #include <zephyr/sys/__assert.h> 23 #include <zephyr/drivers/gpio.h> 24 #include <stdint.h> 25 26 #define DT_DRV_COMPAT isentek_ist8310 27 28 #define IST8310_BUS_I2C DT_ANY_INST_ON_BUS_STATUS_OKAY(i2c) 29 30 union ist8310_bus { 31 struct i2c_dt_spec i2c; 32 }; 33 34 typedef int (*ist8310_bus_check_fn)(const union ist8310_bus *bus); 35 typedef int (*ist8310_reg_read_fn)(const union ist8310_bus *bus, 36 uint8_t start, uint8_t *buf, int size); 37 typedef int (*ist8310_reg_write_fn)(const union ist8310_bus *bus, 38 uint8_t reg, uint8_t val); 39 40 struct ist8310_bus_io { 41 ist8310_bus_check_fn check; 42 ist8310_reg_read_fn read; 43 ist8310_reg_write_fn write; 44 }; 45 46 extern const struct ist8310_bus_io ist8310_bus_io_i2c; 47 48 #define IST8310_WHO_AM_I 0x00 49 #define IST8310_WHO_AM_I_VALUE 0x10 50 51 #define IST8310_STATUS_REGISTER1 0x02 52 #define STAT1_DRDY 0x01 53 #define STAT1_DRO 0x02 54 55 #define IST8310_OUTPUT_VALUE_X_L 0x03 56 #define IST8310_OUTPUT_VALUE_X_H 0x04 57 #define IST8310_OUTPUT_VALUE_Y_L 0x05 58 #define IST8310_OUTPUT_VALUE_Y_H 0x06 59 #define IST8310_OUTPUT_VALUE_Z_L 0x07 60 #define IST8310_OUTPUT_VALUE_Z_H 0x08 61 62 #define IST8310_CONTROL_REGISTER1 0x0A 63 #define CTRL1_MODE_SINGLE 0x1 64 65 #define IST8310_CONTROL_REGISTER2 0x0B 66 #define CTRL2_SRST 0x01 67 68 #define IST8310_OUTPUT_VALUE_T_L 0x1C 69 #define IST8310_OUTPUT_VALUE_T_H 0x1D 70 71 #define IST8310_CONTROL_REGISTER3 0x0d 72 #define Z_16BIT 0x40 73 #define Y_16BIT 0x20 74 #define X_16BIT 0x10 75 76 #define IST8310_AVG_REGISTER 0x41 77 #define Y_16TIMES_SET 0x20 78 #define Y_16TIMES_CLEAR 0x18 79 #define XZ_16TIMES_SET 0x04 80 #define XZ_16TIMES_CLEAR 0x03 81 82 #define IST8310_PDCNTL_REGISTER 0x42 83 #define PULSE_NORMAL 0xC0 84 85 86 struct ist8310_config { 87 union ist8310_bus bus; 88 const struct ist8310_bus_io *bus_io; 89 }; 90 91 struct ist8310_data { 92 struct k_sem sem; 93 int16_t sample_x, sample_y, sample_z; 94 }; 95 96 int ist8310_reg_update_byte(const struct device *dev, uint8_t reg, 97 uint8_t mask, uint8_t value); 98 99 #endif /* __SENSOR_IST8310_H__ */ 100