1 /*
2  * Copyright (c) 2023 Michal Morsisko
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef ZEPHYR_DRIVERS_SENSOR_TMAG5170_TMAG5170_H_
8 #define ZEPHYR_DRIVERS_SENSOR_TMAG5170_TMAG5170_H_
9 
10 #include <zephyr/device.h>
11 #include <zephyr/drivers/gpio.h>
12 #include <zephyr/drivers/spi.h>
13 #include <zephyr/sys/util.h>
14 
15 struct tmag5170_dev_config {
16 	struct spi_dt_spec bus;
17 	uint8_t magnetic_channels;
18 	uint8_t x_range;
19 	uint8_t y_range;
20 	uint8_t z_range;
21 	uint8_t oversampling;
22 	bool tempeature_measurement;
23 	uint8_t magnet_type;
24 	uint8_t angle_measurement;
25 	bool disable_temperature_oversampling;
26 	uint8_t sleep_time;
27 	uint8_t operating_mode;
28 #if defined(CONFIG_TMAG5170_TRIGGER)
29 	struct gpio_dt_spec int_gpio;
30 #endif
31 };
32 
33 struct tmag5170_data {
34 	uint8_t chip_revision;
35 	uint16_t x;
36 	uint16_t y;
37 	uint16_t z;
38 	uint16_t temperature;
39 	uint16_t angle;
40 #if defined(CONFIG_TMAG5170_TRIGGER)
41 	struct gpio_callback gpio_cb;
42 	sensor_trigger_handler_t handler_drdy;
43 	const struct sensor_trigger *trigger_drdy;
44 	const struct device *dev;
45 #endif
46 
47 #if defined(CONFIG_TMAG5170_TRIGGER_OWN_THREAD)
48 	struct k_sem sem;
49 	struct k_thread thread;
50 
51 	K_KERNEL_STACK_MEMBER(thread_stack,
52 			      CONFIG_TMAG5170_THREAD_STACK_SIZE);
53 #elif defined(CONFIG_TMAG5170_TRIGGER_GLOBAL_THREAD)
54 	struct k_work work;
55 #endif
56 };
57 
58 #if defined(CONFIG_TMAG5170_TRIGGER)
59 int tmag5170_trigger_set(const struct device *dev,
60 			 const struct sensor_trigger *trig,
61 			 sensor_trigger_handler_t handler);
62 
63 int tmag5170_trigger_init(const struct device *dev);
64 #endif
65 
66 #endif /* ZEPHYR_DRIVERS_SENSOR_TMAG5170_TMAG5170_H_ */
67