1 /*
2  * Copyright (c) 2021  Grinn
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef ZEPHYR_DRIVERS_SENSOR_INA23X_INA237_H_
8 #define ZEPHYR_DRIVERS_SENSOR_INA23X_INA237_H_
9 
10 #include "ina23x_trigger.h"
11 
12 #include <stdint.h>
13 
14 #include <zephyr/device.h>
15 #include <zephyr/drivers/gpio.h>
16 #include <zephyr/drivers/i2c.h>
17 #include <zephyr/drivers/sensor.h>
18 
19 #define INA237_REG_CONFIG     0x00
20 #define INA237_CFG_HIGH_PRECISION	BIT(4)
21 
22 #define INA237_REG_ADC_CONFIG 0x01
23 #define INA237_REG_CALIB      0x02
24 #define INA237_REG_SHUNT_VOLT 0x04
25 #define INA237_REG_BUS_VOLT   0x05
26 #define INA237_REG_DIETEMP    0x06
27 #define INA237_REG_CURRENT    0x07
28 #define INA237_REG_POWER      0x08
29 #define INA237_REG_ALERT      0x0B
30 #define INA237_REG_SOVL       0x0C
31 #define INA237_REG_SUVL       0x0D
32 #define INA237_REG_BOVL       0x0E
33 #define INA237_REG_BUVL       0x0F
34 #define INA237_REG_TEMP_LIMIT 0x10
35 #define INA237_REG_PWR_LIMIT  0x11
36 #define INA237_REG_MANUFACTURER_ID 0x3E
37 
38 #define INA237_MANUFACTURER_ID 0x5449
39 
40 struct ina237_data {
41 	const struct device *dev;
42 	int16_t current;
43 	uint16_t bus_voltage;
44 	uint32_t power;
45 	int16_t die_temp;
46 #ifdef CONFIG_INA237_VSHUNT
47 	int16_t shunt_voltage;
48 #endif
49 	enum sensor_channel chan;
50 	struct ina23x_trigger trigger;
51 };
52 
53 struct ina237_config {
54 	struct i2c_dt_spec bus;
55 	uint16_t config;
56 	uint16_t adc_config;
57 	uint32_t current_lsb;
58 	uint16_t cal;
59 	const struct gpio_dt_spec alert_gpio;
60 	uint16_t alert_config;
61 };
62 
63 #endif /* ZEPHYR_DRIVERS_SENSOR_INA23X_INA237_H_ */
64