1 /*
2  * Copyright (c) 2024 Arrow Electronics.
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include <zephyr/drivers/sensor.h>
8 #include <zephyr/logging/log.h>
9 #include <zephyr/kernel.h>
10 
11 #include "tmp1075.h"
12 
13 LOG_MODULE_DECLARE(TMP1075, CONFIG_SENSOR_LOG_LEVEL);
14 
15 /*
16  * @brief GPIO alert line interrupt callback
17  * @param gpio - not used
18  * @param cb - callback structure for interrupt handler
19  * @param pins - not used
20  */
tmp1075_trigger_handle_alert(const struct device * gpio,struct gpio_callback * cb,gpio_port_pins_t pins)21 void tmp1075_trigger_handle_alert(const struct device *gpio, struct gpio_callback *cb,
22 				  gpio_port_pins_t pins)
23 {
24 	struct tmp1075_data *drv_data = CONTAINER_OF(cb, struct tmp1075_data, temp_alert_gpio_cb);
25 	/* Successful read, call set callbacks */
26 	if (drv_data->temp_alert_handler) {
27 		drv_data->temp_alert_handler(drv_data->tmp1075_dev, drv_data->temp_alert_trigger);
28 	}
29 }
30 
31 /*
32  * @brief callback implementation for setting the custom trigger handler in the userspace
33  * @param dev - sensor device struct pointer
34  * @param trig - trigger struct pointer to be set up
35  * @param handler - pointer to custom callback handler which the user would like to use
36  * @return 0 if ok - -ENOTSUP in case of err
37  */
tmp1075_trigger_set(const struct device * dev,const struct sensor_trigger * trig,sensor_trigger_handler_t handler)38 int tmp1075_trigger_set(const struct device *dev, const struct sensor_trigger *trig,
39 			sensor_trigger_handler_t handler)
40 {
41 	if (!device_is_ready(dev)) {
42 		return -ENODEV;
43 	}
44 
45 	struct tmp1075_data *drv_data = dev->data;
46 
47 	if (trig->type == SENSOR_TRIG_THRESHOLD) {
48 		drv_data->temp_alert_handler = handler;
49 		drv_data->temp_alert_trigger = trig;
50 		return 0;
51 	}
52 
53 	return -ENOTSUP;
54 }
55