1 /* 2 * Copyright (c) 2016 Intel Corporation 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #ifndef ZEPHYR_DRIVERS_SENSOR_SX9500_SX9500_H_ 8 #define ZEPHYR_DRIVERS_SENSOR_SX9500_SX9500_H_ 9 10 #include <zephyr/types.h> 11 #include <zephyr/device.h> 12 #include <zephyr/drivers/i2c.h> 13 14 #define SX9500_REG_IRQ_SRC 0x00 15 #define SX9500_REG_STAT 0x01 16 #define SX9500_REG_IRQ_MSK 0x03 17 18 #define SX9500_REG_PROX_CTRL0 0x06 19 #define SX9500_REG_PROX_CTRL1 0x07 20 21 /* These are used both in the IRQ_SRC register, to identify which 22 * interrupt occur, and in the IRQ_MSK register, to enable specific 23 * interrupts. 24 */ 25 #define SX9500_CONV_DONE_IRQ (1 << 3) 26 #define SX9500_NEAR_FAR_IRQ ((1 << 5) | (1 << 6)) 27 28 struct sx9500_config { 29 struct i2c_dt_spec i2c; 30 #ifdef CONFIG_SX9500_TRIGGER 31 struct gpio_dt_spec int_gpio; 32 #endif 33 }; 34 35 struct sx9500_data { 36 uint8_t prox_stat; 37 38 struct gpio_callback gpio_cb; 39 40 #ifdef CONFIG_SX9500_TRIGGER_OWN_THREAD 41 struct k_sem sem; 42 #endif 43 44 #ifdef CONFIG_SX9500_TRIGGER_GLOBAL_THREAD 45 struct k_work work; 46 #endif 47 48 #ifdef CONFIG_SX9500_TRIGGER 49 const struct device *dev; 50 const struct sensor_trigger *trigger_drdy; 51 const struct sensor_trigger *trigger_near_far; 52 53 sensor_trigger_handler_t handler_drdy; 54 sensor_trigger_handler_t handler_near_far; 55 #endif 56 }; 57 58 #ifdef CONFIG_SX9500_TRIGGER 59 int sx9500_setup_interrupt(const struct device *dev); 60 int sx9500_trigger_set(const struct device *dev, 61 const struct sensor_trigger *trig, 62 sensor_trigger_handler_t handler); 63 #else sx9500_setup_interrupt(const struct device * dev)64static inline int sx9500_setup_interrupt(const struct device *dev) 65 { 66 return 0; 67 } 68 #endif 69 70 #endif /* ZEPHYR_DRIVERS_SENSOR_SX9500_SX9500_H_ */ 71