1 /* 2 * Copyright 2021 The Chromium OS Authors 3 * Copyright (c) 2021 Grinn 4 * 5 * SPDX-License-Identifier: Apache-2.0 6 */ 7 8 #ifndef ZEPHYR_DRIVERS_SENSOR_INA23X_INA230_H_ 9 #define ZEPHYR_DRIVERS_SENSOR_INA23X_INA230_H_ 10 11 #ifdef CONFIG_INA230_TRIGGER 12 #include <stdbool.h> 13 #endif 14 #include <stdint.h> 15 16 #include <zephyr/device.h> 17 #ifdef CONFIG_INA230_TRIGGER 18 #include <zephyr/drivers/gpio.h> 19 #endif 20 #include <zephyr/drivers/i2c.h> 21 #include <zephyr/drivers/sensor.h> 22 #ifdef CONFIG_INA230_TRIGGER 23 #include <zephyr/kernel.h> 24 #endif 25 26 #define INA230_REG_CONFIG 0x00 27 #define INA230_REG_SHUNT_VOLT 0x01 28 #define INA230_REG_BUS_VOLT 0x02 29 #define INA230_REG_POWER 0x03 30 #define INA230_REG_CURRENT 0x04 31 #define INA230_REG_CALIB 0x05 32 #define INA230_REG_MASK 0x06 33 #define INA230_REG_ALERT 0x07 34 #define INA236_REG_MANUFACTURER_ID 0x3E 35 #define INA236_REG_DEVICE_ID 0x3F 36 37 struct ina230_data { 38 const struct device *dev; 39 int16_t current; 40 uint16_t bus_voltage; 41 uint16_t power; 42 #ifdef CONFIG_INA230_TRIGGER 43 const struct device *gpio; 44 struct gpio_callback gpio_cb; 45 struct k_work work; 46 sensor_trigger_handler_t handler_alert; 47 const struct sensor_trigger *trig_alert; 48 #endif /* CONFIG_INA230_TRIGGER */ 49 }; 50 51 struct ina230_config { 52 struct i2c_dt_spec bus; 53 uint16_t config; 54 uint32_t current_lsb; 55 uint16_t cal; 56 uint8_t power_scale; 57 uint32_t uv_lsb; 58 #ifdef CONFIG_INA230_TRIGGER 59 bool trig_enabled; 60 uint16_t mask; 61 const struct gpio_dt_spec alert_gpio; 62 uint16_t alert_limit; 63 #endif /* CONFIG_INA230_TRIGGER */ 64 }; 65 66 int ina230_trigger_mode_init(const struct device *dev); 67 int ina230_trigger_set(const struct device *dev, const struct sensor_trigger *trig, 68 sensor_trigger_handler_t handler); 69 70 #endif /* ZEPHYR_DRIVERS_SENSOR_INA23X_INA230_H_ */ 71