@@ -18,10 +18,12 @@ LOG_MODULE_REGISTER(INA230, CONFIG_SENSOR_LOG_LEVEL);
1818
1919/** @brief The LSB value for the bus voltage register, in microvolts/LSB. */
2020#define INA230_BUS_VOLTAGE_UV_LSB 1250U
21+ #define INA232_BUS_VOLTAGE_UV_LSB 1600U
2122#define INA236_BUS_VOLTAGE_UV_LSB 1600U
2223
2324/** @brief The scaling for the power register. */
2425#define INA230_POWER_SCALING 25
26+ #define INA232_POWER_SCALING 32
2527#define INA236_POWER_SCALING 32
2628
2729INA2XX_REG_DEFINE (ina230_config , INA230_REG_CONFIG , 16 );
@@ -39,6 +41,18 @@ static struct ina2xx_channels ina230_channels = {
3941};
4042#endif /* ti_ina230 */
4143
44+ #if DT_HAS_COMPAT_STATUS_OKAY (ti_ina232 )
45+ INA2XX_CHANNEL_DEFINE (ina232_current , INA230_REG_CURRENT , 16 , 0 , 1 , 1 );
46+ INA2XX_CHANNEL_DEFINE (ina232_bus_voltage , INA230_REG_BUS_VOLT , 16 , 0 , INA232_BUS_VOLTAGE_UV_LSB , 1 );
47+ INA2XX_CHANNEL_DEFINE (ina232_power , INA230_REG_POWER , 16 , 0 , INA232_POWER_SCALING , 1 );
48+
49+ static struct ina2xx_channels ina232_channels = {
50+ .voltage = & ina232_bus_voltage ,
51+ .current = & ina232_current ,
52+ .power = & ina232_power ,
53+ };
54+ #endif /* ti_ina232 */
55+
4256#if DT_HAS_COMPAT_STATUS_OKAY (ti_ina236 )
4357INA2XX_CHANNEL_DEFINE (ina236_current , INA230_REG_CURRENT , 16 , 0 , 1 , 1 );
4458INA2XX_CHANNEL_DEFINE (ina236_bus_voltage , INA230_REG_BUS_VOLT , 16 , 0 , INA236_BUS_VOLTAGE_UV_LSB , 1 );
@@ -198,67 +212,96 @@ static DEVICE_API(sensor, ina230_driver_api) = {
198212#define INA230_CFG_IRQ (inst )
199213#endif /* CONFIG_INA230_TRIGGER */
200214
201- #define INA230_DT_CONFIG (inst ) \
202- (DT_INST_PROP_OR(inst, high_precision, 0) << 12) | \
203- (DT_INST_ENUM_IDX(inst, avg_count) << 9) | \
204- (DT_INST_ENUM_IDX(inst, vbus_conversion_time_us) << 6) | \
205- (DT_INST_ENUM_IDX(inst, vshunt_conversion_time_us) << 3) | \
206- (DT_INST_ENUM_IDX(inst, adc_mode))
207-
208- #define INA230_DT_CAL (inst ) \
209- (uint16_t)(((INA230_CAL_SCALING * 10000000ULL) / \
210- ((uint64_t)DT_INST_PROP(inst, current_lsb_microamps) * \
211- DT_INST_PROP(inst, rshunt_micro_ohms))) >> \
212- (DT_INST_PROP_OR(inst, high_precision, 0) << 1))
213-
214- #define INA230_DRIVER_INIT (inst ) \
215- static struct ina230_data ina230_data_##inst; \
216- static const struct ina230_config ina230_config_##inst = { \
217- .common = { \
218- .bus = I2C_DT_SPEC_INST_GET(inst), \
219- .current_lsb = DT_INST_PROP(inst, current_lsb_microamps), \
220- .config = INA230_DT_CONFIG(inst), \
221- .cal = INA230_DT_CAL(inst), \
222- .id_reg = NULL, \
223- .config_reg = &ina230_config, \
224- .adc_config_reg = NULL, \
225- .cal_reg = &ina230_cal, \
226- .channels = &ina230_channels, \
227- }, \
228- .uv_lsb = INA230_BUS_VOLTAGE_UV_LSB, \
229- .power_scale = INA230_POWER_SCALING, \
230- COND_CODE_1(DT_INST_NODE_HAS_PROP(inst, alert_gpios), \
231- (INA230_CFG_IRQ(inst)), ())}; \
232- SENSOR_DEVICE_DT_INST_DEFINE(inst, &ina230_init, NULL, \
233- &ina230_data_##inst, &ina230_config_##inst, \
234- POST_KERNEL, CONFIG_SENSOR_INIT_PRIORITY, &ina230_driver_api);
235-
236- #define INA236_DRIVER_INIT (inst ) \
237- static struct ina230_data ina236_data_##inst; \
238- static const struct ina230_config ina236_config_##inst = { \
239- .common = { \
240- .bus = I2C_DT_SPEC_INST_GET(inst), \
241- .current_lsb = DT_INST_PROP(inst, current_lsb_microamps), \
242- .config = INA230_DT_CONFIG(inst), \
243- .cal = INA230_DT_CAL(inst), \
244- .id_reg = NULL, \
245- .config_reg = &ina230_config, \
246- .adc_config_reg = NULL, \
247- .cal_reg = &ina230_cal, \
248- .channels = &ina236_channels, \
249- }, \
250- .uv_lsb = INA236_BUS_VOLTAGE_UV_LSB, \
251- .power_scale = INA236_POWER_SCALING, \
252- COND_CODE_1(DT_INST_NODE_HAS_PROP(inst, alert_gpios), \
253- (INA230_CFG_IRQ(inst)), ())}; \
254- SENSOR_DEVICE_DT_INST_DEFINE(inst, &ina230_init, NULL, \
255- &ina236_data_##inst, &ina236_config_##inst, \
256- POST_KERNEL, CONFIG_SENSOR_INIT_PRIORITY, &ina230_driver_api);
215+ #define INA230_DT_CONFIG (inst ) \
216+ (DT_INST_PROP_OR(inst, high_precision, 0) << 12) | \
217+ (DT_INST_ENUM_IDX(inst, avg_count) << 9) | \
218+ (DT_INST_ENUM_IDX(inst, vbus_conversion_time_us) << 6) | \
219+ (DT_INST_ENUM_IDX(inst, vshunt_conversion_time_us) << 3) | \
220+ (DT_INST_ENUM_IDX(inst, adc_mode))
221+
222+ #define INA230_DT_CAL (inst ) \
223+ (uint16_t)(((INA230_CAL_SCALING * 10000000ULL) / \
224+ ((uint64_t)DT_INST_PROP(inst, current_lsb_microamps) * \
225+ DT_INST_PROP(inst, rshunt_micro_ohms))) >> \
226+ (DT_INST_PROP_OR(inst, high_precision, 0) << 1))
227+
228+ #define INA230_DRIVER_INIT (inst ) \
229+ static struct ina230_data ina230_data_##inst; \
230+ static const struct ina230_config ina230_config_##inst = { \
231+ .common = \
232+ { \
233+ .bus = I2C_DT_SPEC_INST_GET(inst), \
234+ .current_lsb = DT_INST_PROP(inst, current_lsb_microamps), \
235+ .config = INA230_DT_CONFIG(inst), \
236+ .cal = INA230_DT_CAL(inst), \
237+ .id_reg = NULL, \
238+ .config_reg = &ina230_config, \
239+ .adc_config_reg = NULL, \
240+ .cal_reg = &ina230_cal, \
241+ .channels = &ina230_channels, \
242+ }, \
243+ .uv_lsb = INA230_BUS_VOLTAGE_UV_LSB, \
244+ .power_scale = INA230_POWER_SCALING, \
245+ COND_CODE_1(DT_INST_NODE_HAS_PROP(inst, alert_gpios), \
246+ (INA230_CFG_IRQ(inst)), ())}; \
247+ SENSOR_DEVICE_DT_INST_DEFINE(inst, &ina230_init, NULL, &ina230_data_##inst, \
248+ &ina230_config_##inst, POST_KERNEL, \
249+ CONFIG_SENSOR_INIT_PRIORITY, &ina230_driver_api);
250+
251+ #define INA232_DRIVER_INIT (inst ) \
252+ static struct ina230_data ina232_data_##inst; \
253+ static const struct ina230_config ina232_config_##inst = { \
254+ .common = \
255+ { \
256+ .bus = I2C_DT_SPEC_INST_GET(inst), \
257+ .current_lsb = DT_INST_PROP(inst, current_lsb_microamps), \
258+ .config = INA230_DT_CONFIG(inst), \
259+ .cal = INA230_DT_CAL(inst), \
260+ .id_reg = NULL, \
261+ .config_reg = &ina230_config, \
262+ .adc_config_reg = NULL, \
263+ .cal_reg = &ina230_cal, \
264+ .channels = &ina232_channels, \
265+ }, \
266+ .uv_lsb = INA232_BUS_VOLTAGE_UV_LSB, \
267+ .power_scale = INA232_POWER_SCALING, \
268+ COND_CODE_1(DT_INST_NODE_HAS_PROP(inst, alert_gpios), \
269+ (INA230_CFG_IRQ(inst)), ())}; \
270+ SENSOR_DEVICE_DT_INST_DEFINE(inst, &ina230_init, NULL, &ina232_data_##inst, \
271+ &ina232_config_##inst, POST_KERNEL, \
272+ CONFIG_SENSOR_INIT_PRIORITY, &ina230_driver_api);
273+
274+ #define INA236_DRIVER_INIT (inst ) \
275+ static struct ina230_data ina236_data_##inst; \
276+ static const struct ina230_config ina236_config_##inst = { \
277+ .common = \
278+ { \
279+ .bus = I2C_DT_SPEC_INST_GET(inst), \
280+ .current_lsb = DT_INST_PROP(inst, current_lsb_microamps), \
281+ .config = INA230_DT_CONFIG(inst), \
282+ .cal = INA230_DT_CAL(inst), \
283+ .id_reg = NULL, \
284+ .config_reg = &ina230_config, \
285+ .adc_config_reg = NULL, \
286+ .cal_reg = &ina230_cal, \
287+ .channels = &ina236_channels, \
288+ }, \
289+ .uv_lsb = INA236_BUS_VOLTAGE_UV_LSB, \
290+ .power_scale = INA236_POWER_SCALING, \
291+ COND_CODE_1(DT_INST_NODE_HAS_PROP(inst, alert_gpios), \
292+ (INA230_CFG_IRQ(inst)), ())}; \
293+ SENSOR_DEVICE_DT_INST_DEFINE(inst, &ina230_init, NULL, &ina236_data_##inst, \
294+ &ina236_config_##inst, POST_KERNEL, \
295+ CONFIG_SENSOR_INIT_PRIORITY, &ina230_driver_api);
257296
258297#define DT_DRV_COMPAT ti_ina230
259298DT_INST_FOREACH_STATUS_OKAY (INA230_DRIVER_INIT )
260299#undef DT_DRV_COMPAT
261300
301+ #define DT_DRV_COMPAT ti_ina232
302+ DT_INST_FOREACH_STATUS_OKAY (INA232_DRIVER_INIT )
303+ #undef DT_DRV_COMPAT
304+
262305#define DT_DRV_COMPAT ti_ina236
263306DT_INST_FOREACH_STATUS_OKAY (INA236_DRIVER_INIT )
264307#undef DT_DRV_COMPAT
0 commit comments