drivers/sensors: add resistance, conductivity, energy and charge types

Cover the remaining electrical quantities so that they do not have to fork
into driver private namespaces later.  Add SENSOR_TYPE_RESISTANCE (Ohm),
SENSOR_TYPE_CONDUCTIVITY (S/m), SENSOR_TYPE_ENERGY (J) and
SENSOR_TYPE_CHARGE (C), the last two matching the native unit of the
accumulator registers in power and energy monitors.

Signed-off-by: likun17 <likun17@xiaomi.com>
This commit is contained in:
likun17 2026-09-09 20:15:48 +08:00 committed by Xiang Xiao
parent cd225a0e56
commit 29a536f53e
2 changed files with 66 additions and 4 deletions

View file

@ -227,6 +227,10 @@ static const struct sensor_meta_s g_sensor_meta[] =
{sizeof(struct sensor_voltage), "voltage"},
{sizeof(struct sensor_current), "current"},
{sizeof(struct sensor_power), "power"},
{sizeof(struct sensor_resistance), "resistance"},
{sizeof(struct sensor_conductivity), "conductivity"},
{sizeof(struct sensor_energy), "energy"},
{sizeof(struct sensor_charge), "charge"},
};
static const struct file_operations g_sensor_fops =

View file

@ -607,18 +607,52 @@
/* Power
* A sensor of this type returns the measured instantaneous active power.
* The value is in SI units watt(W). The accumulated energy and the AC
* power components (reactive, apparent and power factor) are not covered
* by this type.
* The value is in SI units watt(W). The accumulated energy is reported by
* SENSOR_TYPE_ENERGY. The AC power components (reactive, apparent and
* power factor) are not covered by this type.
*/
#define SENSOR_TYPE_POWER 61
/* Resistance
* A sensor of this type returns the measured DC resistance. The value is
* in SI units Ohm(Ω). Use SENSOR_TYPE_IMPEDANCE instead when the reactance
* is also needed.
*/
#define SENSOR_TYPE_RESISTANCE 62
/* Electrical conductivity
* A sensor of this type returns the measured electrical conductivity of a
* medium. The value is in SI units siemens per metre(S/m), where 1 S/m
* equals 1e4 uS/cm.
*/
#define SENSOR_TYPE_CONDUCTIVITY 63
/* Energy
* A sensor of this type returns the electrical energy accumulated since
* the accumulator was last reset. The value is in uJ, where 1 Wh equals
* 3.6e9 uJ. The value is signed: a negative value indicates that the
* energy flows in the direction opposite to the reference direction.
*/
#define SENSOR_TYPE_ENERGY 64
/* Charge
* A sensor of this type returns the electrical charge accumulated since
* the accumulator was last reset, that is the time integral of the
* current. The value is in uC, where 1 Ah equals 3.6e9 uC. The value is
* signed and uses the same direction convention as SENSOR_TYPE_CURRENT.
*/
#define SENSOR_TYPE_CHARGE 65
/* The total number of sensor
* please increase it if you added a new sensor type!
*/
#define SENSOR_TYPE_COUNT 62
#define SENSOR_TYPE_COUNT 66
/* The additional sensor open flags */
@ -1075,6 +1109,30 @@ struct sensor_power /* Type: Power */
float power; /* Instantaneous active power in SI units W */
};
struct sensor_resistance /* Type: Resistance */
{
uint64_t timestamp; /* Unit is microseconds */
float resistance; /* in SI units Ohm(Ω) */
};
struct sensor_conductivity /* Type: Electrical conductivity */
{
uint64_t timestamp; /* Unit is microseconds */
float conductivity; /* in SI units S/m, 1 S/m = 1e4 uS/cm */
};
struct sensor_energy /* Type: Energy */
{
uint64_t timestamp; /* Unit is microseconds */
int64_t energy; /* Accumulated energy. Unit is uJ. */
};
struct sensor_charge /* Type: Charge */
{
uint64_t timestamp; /* Unit is microseconds */
int64_t charge; /* Accumulated charge. Unit is uC. */
};
struct sensor_gnss /* Type: GNSS */
{
uint64_t timestamp; /* Time since system start, Units is microseconds */