1 /* 2 * Copyright (c) 2017-2019 Phytec Messtechnik GmbH 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #ifndef ZEPHYR_DRIVERS_SENSOR_AMG88XX_AMG88XX_H_ 8 #define ZEPHYR_DRIVERS_SENSOR_AMG88XX_AMG88XX_H_ 9 10 #include <zephyr/device.h> 11 #include <zephyr/drivers/gpio.h> 12 #include <zephyr/sys/util.h> 13 14 #define AMG88XX_PCLT 0x00 /* Setting Power control register */ 15 #define AMG88XX_RST 0x01 /* Reset register */ 16 #define AMG88XX_FPSC 0x02 /* Setting frame rate register */ 17 #define AMG88XX_INTC 0x03 /* Setting interrupt control register */ 18 #define AMG88XX_STAT 0x04 /* Status register */ 19 #define AMG88XX_SCLR 0x05 /* Status clear register */ 20 #define AMG88XX_AVE 0x07 /* Setting average register */ 21 #define AMG88XX_INTHL 0x08 /* Interrupt level upper limit [7:0] */ 22 #define AMG88XX_INTHH 0x09 /* Interrupt level upper limit [11:8] */ 23 #define AMG88XX_INTLL 0x0a /* Interrupt level lower limit [7:0] */ 24 #define AMG88XX_INTLH 0x0b /* Interrupt level lower limit [11:8] */ 25 #define AMG88XX_INTSL 0x0c /* Interrupt hysteresis level [7:0] */ 26 #define AMG88XX_INTSH 0x0d /* Interrupt hysteresis level [11:8] */ 27 #define AMG88XX_TTHL 0x0e /* Thermistor temperature data [7:0] */ 28 #define AMG88XX_TTHH 0x0f /* Thermistor temperature data [10:8] */ 29 #define AMG88XX_INT0 0x10 /* Pixel 1..8 Interrupt Result */ 30 #define AMG88XX_INT1 0x11 /* Pixel 9..16 Interrupt Result */ 31 #define AMG88XX_INT2 0x12 /* Pixel 17..24 Interrupt Result */ 32 #define AMG88XX_INT3 0x13 /* Pixel 25..32 Interrupt Result */ 33 #define AMG88XX_INT4 0x14 /* Pixel 33..40 Interrupt Result */ 34 #define AMG88XX_INT5 0x15 /* Pixel 41..48 Interrupt Result */ 35 #define AMG88XX_INT6 0x16 /* Pixel 49..56 Interrupt Result */ 36 #define AMG88XX_INT7 0x17 /* Pixel 57..64 Interrupt Result */ 37 38 #define AMG88XX_OUTPUT_BASE 0x80 /* Base address for the output values */ 39 40 #define AMG88XX_PCLT_NORMAL_MODE 0x00 41 #define AMG88XX_PCLT_SLEEP_MODE 0x10 42 #define AMG88XX_PCLT_STAND_BY_60S_MODE 0x20 43 #define AMG88XX_PCLT_STAND_BY_10S_MODE 0x21 44 45 #define AMG88XX_RST_FLAG_RST 0x30 46 #define AMG88XX_RST_INITIAL_RST 0x3F 47 48 #define AMG88XX_FPSC_10FPS 0x00 49 #define AMG88XX_FPSC_1FPS 0x01 50 51 #define AMG88XX_INTC_DISABLED 0x00 52 #define AMG88XX_INTC_DIFF_MODE 0x01 53 #define AMG88XX_INTC_ABS_MODE 0x03 54 55 #define AMG88XX_STAT_INTF_MASK 0x02 56 #define AMG88XX_STAT_OVF_IRS_MASK 0x04 57 58 #define AMG88XX_SCLR_INTCLR_MASK 0x02 59 #define AMG88XX_SCLR_OVS_CLR_MASK 0x04 60 61 #define AMG88XX_AVE_MAMOD_MASK 0x20 62 63 /* 1 LSB is equivalent to 0.25 degree Celsius scaled to micro degrees */ 64 #define AMG88XX_TREG_LSB_SCALING 250000 65 66 #define AMG88XX_WAIT_MODE_CHANGE_US 50000 67 #define AMG88XX_WAIT_INITIAL_RESET_US 2000 68 69 struct amg88xx_config { 70 const struct i2c_dt_spec i2c; 71 #ifdef CONFIG_AMG88XX_TRIGGER 72 const struct gpio_dt_spec int_gpio; 73 #endif 74 }; 75 76 struct amg88xx_data { 77 int16_t sample[64]; 78 79 #ifdef CONFIG_AMG88XX_TRIGGER 80 const struct device *dev; 81 struct gpio_callback gpio_cb; 82 83 sensor_trigger_handler_t drdy_handler; 84 const struct sensor_trigger *drdy_trigger; 85 86 sensor_trigger_handler_t th_handler; 87 const struct sensor_trigger *th_trigger; 88 89 #if defined(CONFIG_AMG88XX_TRIGGER_OWN_THREAD) 90 K_KERNEL_STACK_MEMBER(thread_stack, CONFIG_AMG88XX_THREAD_STACK_SIZE); 91 struct k_sem gpio_sem; 92 struct k_thread thread; 93 #elif defined(CONFIG_AMG88XX_TRIGGER_GLOBAL_THREAD) 94 struct k_work work; 95 #endif 96 97 #endif /* CONFIG_AMG88XX_TRIGGER */ 98 }; 99 100 #ifdef CONFIG_AMG88XX_TRIGGER 101 int amg88xx_attr_set(const struct device *dev, 102 enum sensor_channel chan, 103 enum sensor_attribute attr, 104 const struct sensor_value *val); 105 106 int amg88xx_trigger_set(const struct device *dev, 107 const struct sensor_trigger *trig, 108 sensor_trigger_handler_t handler); 109 110 int amg88xx_init_interrupt(const struct device *dev); 111 #endif /* CONFIG_AMG88XX_TRIGGER */ 112 113 #endif 114