Loading...
Searching...
No Matches
ina3221_internal.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2019 Otto-von-Guericke-Universität Magdeburg
3 *
4 * This file is subject to the terms and conditions of the GNU Lesser
5 * General Public License v2.1. See the file LICENSE in the top level
6 * directory for more details.
7 */
8
20#ifndef INA3221_INTERNAL_H
21#define INA3221_INTERNAL_H
22
23#include <assert.h>
24#include "ina3221_defines.h"
25#include "ina3221.h"
26
27#ifdef __cplusplus
28extern "C" {
29#endif
30
40static inline int32_t reg_val_to_shunt_voltage_uv(int16_t reg_val)
41{
43
44 return reg_val / 8 * INA3221_SHUNT_VOLTAGE_PRECISION_UV;
45}
46
56static inline int16_t shunt_voltage_uv_to_reg_val(int32_t s_uv)
57{
59
60 return s_uv / INA3221_SHUNT_VOLTAGE_PRECISION_UV * 8;
61}
62
72static inline int16_t reg_val_to_bus_voltage_mv(int16_t reg_val)
73{
75
76 return reg_val / 8 * INA3221_BUS_VOLTAGE_PRECISION_MV;
77}
78
88static inline int16_t bus_voltage_mv_to_reg_val(int16_t b_mv)
89{
92
93 return b_mv / INA3221_BUS_VOLTAGE_PRECISION_MV * 8;
94}
95
105static inline int32_t sum_reg_val_to_shunt_voltage_uv(int16_t sum_reg_val)
106{
108
109 return sum_reg_val / 2 * INA3221_SHUNT_VOLTAGE_PRECISION_UV;
110}
111
121static inline int16_t sum_shunt_voltage_uv_to_reg_val(int32_t sum_suv)
122{
124
125 return sum_suv / INA3221_SHUNT_VOLTAGE_PRECISION_UV * 2;
126}
127
128#ifdef __cplusplus
129}
130#endif
131
132#endif /* INA3221_INTERNAL_H */
POSIX.1-2008 compliant version of the assert macro.
#define assert(cond)
abort the program if assertion is false
Definition assert.h:136
Device driver interface for Texas Instruments INA3221 three-channel, high-side current and bus voltag...
Internal definitions for Texas Instruments INA3221 three-channel, high-side current and bus voltage m...
#define INA3221_MAX_SHUNT_SUM_UV
Max.
#define INA3221_MAX_BUS_MV
Max.
#define INA3221_MAX_SHUNT_REG_VAL
0111 1111 1111 1000
#define INA3221_MIN_BUS_MV
Min.
#define INA3221_MAX_SHUNT_UV
Max.
#define INA3221_BUS_VOLTAGE_PRECISION_MV
Bus voltage measurement precision.
#define INA3221_MAX_SHUNT_SUM_REG_VAL
0111 1111 1111 1110
#define INA3221_MAX_BUS_REG_VAL
0111 1111 1111 1000
#define INA3221_SHUNT_VOLTAGE_PRECISION_UV
Shunt voltage measurement precision.
static int32_t reg_val_to_shunt_voltage_uv(int16_t reg_val)
Convert register value to shunt voltage in uV.
static int32_t sum_reg_val_to_shunt_voltage_uv(int16_t sum_reg_val)
Convert register value to shunt voltage sum value in mV.
static int16_t bus_voltage_mv_to_reg_val(int16_t b_mv)
Convert bus voltage in mV to register value.
static int16_t reg_val_to_bus_voltage_mv(int16_t reg_val)
Convert register value to bus voltage in mV.
static int16_t shunt_voltage_uv_to_reg_val(int32_t s_uv)
Convert shunt voltage in uV to register value.
static int16_t sum_shunt_voltage_uv_to_reg_val(int32_t sum_suv)
Convert shunt voltage sum value in uV to register value.