sensor.h for nPM1300, triggers

Hello. I want to use sensor.h library for setting interrupt trigger for PMIC. The interrupt should be triggered when event from charger and temperature occurs (e.g. ntc cold, charging completed etc.)  I have used this documentation as a reference : 
https://developer.nordicsemi.com/nRF_Connect_SDK/doc/1.9.99-dev1/zephyr/reference/peripherals/sensor.html#c.sensor_trigger_type

Here is my setting from .dts file :

&i2c0_default {
	group1 {
		bias-pull-up;
	};
};

&i2c0 {

    npm1300_ek_pmic: pmic@6b {
		compatible = "nordic,npm1300";
		reg = <0x6b>;
		host-int-gpios = <&gpio1 11 GPIO_ACTIVE_HIGH>;
		pmic-int-pin = <4>;

		npm1300_ek_gpio: gpio-controller {
			compatible = "nordic,npm1300-gpio";
			gpio-controller;
			#gpio-cells = <2>;
			ngpios = <5>;
		};

		npm1300_ek_regulators: regulators {
			compatible = "nordic,npm1300-regulator";

			npm1300_ek_buck1: BUCK1 {
			};

			npm1300_ek_buck2: BUCK2 {
			};

			npm1300_ek_ldo1: LDO1 {
			};

			npm1300_ek_ldo2: LDO2 {
			};
		};

		npm1300_ek_charger: charger {
			compatible = "nordic,npm1300-charger";
			term-microvolt = <4150000>;
			term-warm-microvolt = <4000000>;
			current-microamp = <800000>;
			dischg-limit-microamp = <1340000>;
			vbus-limit-microamp = <1500000>;
			thermistor-ohms = <10000>;
			thermistor-beta = <3380>;
			trickle-microvolt = <2900000>;
			thermistor-cold-millidegrees = <0>;
  			thermistor-cool-millidegrees = <10000>;
  			thermistor-warm-millidegrees = <45000>;
  			thermistor-hot-millidegrees = <60000>;
			charging-enable;
			term-current-percent = <10>;
			vbatlow-charge-enable;			
		};

		npm1300_ek_leds: leds {
			compatible = "nordic,npm1300-led";
			nordic,led0-mode = "error";
			nordic,led1-mode = "charging";
			nordic,led2-mode = "host";
		};
	};
};

As you can see, I have used GPIO4 pin from PMIC as an interrupt output. The input comes to pin 11, port 1 of nRF52.

My problem has started when I wanted to use 'int sensor_trigger_set(const struct device *dev, const struct sensor_trigger *trig, sensor_trigger_handler_t handler)'.

Before using this function I should fill the fields of structure 'sensor_trigger' - type and channel. I don't know which type should I use for this purpose. Also I don't know which channel should I use. In sensor.h file these channels and types are listed but no one fits for my purpose. So the question is, which channel and type should I use for setting the interrupt from charger and temperature events?

I found information that higher values are sensor specific and can write new types and channels like below :

but I don't know which value should I use. Can't find sensor specific values for npm1300.


Secondly, how does it work? How functions from sensor.h know e.g. which enumerated channel corresponds to the direct register of the sensor? I mean e.g. SENSOR_CHAN_GAUGE_VOLTAGE channel has the value of 40. The battery voltage is measured by TASKVBATMEASURE(0x0) register that trigger the task and the value is read from ADCVBATRESULTMSB(0x11) register and another one with LSB value. Everything have place for ADC instance which address is 0x00000500. How that value of 40 is correlated with these registers? Why for SENSOR_CHAN_NPM1300_CHARGER_STATUS value is 59 etc. etc.

Parents Reply Children
No Data
Related