Interrupt setup in devicetree overlay for I2C device - nrf5340

Hi,

I'm developing a library (in the "src" folder of the project) for a I2C sensor. The device is a temperature sensor that has a specific pin for alert (interrupt). I'm trying to understand how to write properly a DTS overlay file to implement such functionalities. I already read the last devicetree specifications (0.4rc) and looked in nrf connect sdk documentation, but specific info on syntax and requirements are missing (or i have not been able to find them!). 

I would like to connect the interrupt pin on P1.10, but i don't understand what are the required fields and their parameters. This is my overlay at the moment

&i2c1 {
    compatible = "nordic,nrf-twim";
    status="okay";
    pinctrl-0=<&i2c1_default>;
    pinctrl-1=<&i2c1_sleep>;
    
    temp-sensor-test: temp_sens@18{
        compatible = "i2c-device";
        reg = <0x18>;
        label = "temp_sens";
        interrupt-parent = < &nvic >;
        interrupts = <1 NRF_DEFAULT_IRQ_PRIORITY>;
    };
    
};

Even if i know that there are different ways i can make an interrupt work, i'm trying to understand better how to use devicetree more efficiently. Any guide or suggestion you can provide me is really appreciated!

Thanks,

Frax

Parents
  • Hi,

    Have a look at  Creating an out-of-tree zephyr driver with bindings... and see if you can learn what you need from this case.

    Regards,
    Sigurd Hellesvik

  • Hello,

    thank you for the link! I'm not sure this fits with my request. I already read some (unofficial) guide to OOT drivers and i don't plan to write one at the moment. By the way i'll read it a bit more. In the meantime i even looked for more material. If i understood correctly the material i have been able to find until now i have two options to implement interrupt configuration in bindings:

    1) use gpio bindings (like in the sample for button interrupt) and use them in code with gpio apis. In this case everything is already available out of the box, but i have to map separately the i2c device and its interrupt pin.

    2) write a custom yaml file for the i2c device i'm working on add a field for interrupt parameters on it, use the "compatible" property in the DTS overlay and use these in code with gpio apis. In this case i need to write an additional file (the custom yaml) but the result is more compact and maintanable.

    Am i correct?

    I'm sorry if my vocabulary can be still a bit naive, but this is the best way i can explain it at the moment.

    Thank you,

    Frax

  • From a scan of you answer, I see that I indeed misunderstood your question.

    I will look over your statement tomorrow and let you know if it is correct or not.

    Regards,
    Sigurd Hellesvik

  • I'm developing a library (in the "src" folder of the project) for a I2C sensor.

    So since your library just use the I2C driver, you do not need to do a fancy out of tree module thing, as you pointed out.

    frax84 said:
    1) use gpio bindings (like in the sample for button interrupt) and use them in code with gpio apis. In this case everything is already available out of the box, but i have to map separately the i2c device and its interrupt pin.

    This for sure sounds like the easiest solution to implement.

    frax84 said:
    2) write a custom yaml file for the i2c device i'm working on add a field for interrupt parameters on it, use the "compatible" property in the DTS overlay and use these in code with gpio apis. In this case i need to write an additional file (the custom yaml) but the result is more compact and maintanable.

    Yes, this would make sense to me. Requires more work, but is more elegant than 1).

    See this unofficial sample on how you can add a this yaml file.

    Regards,
    Sigurd Hellesvik

Reply
  • I'm developing a library (in the "src" folder of the project) for a I2C sensor.

    So since your library just use the I2C driver, you do not need to do a fancy out of tree module thing, as you pointed out.

    frax84 said:
    1) use gpio bindings (like in the sample for button interrupt) and use them in code with gpio apis. In this case everything is already available out of the box, but i have to map separately the i2c device and its interrupt pin.

    This for sure sounds like the easiest solution to implement.

    frax84 said:
    2) write a custom yaml file for the i2c device i'm working on add a field for interrupt parameters on it, use the "compatible" property in the DTS overlay and use these in code with gpio apis. In this case i need to write an additional file (the custom yaml) but the result is more compact and maintanable.

    Yes, this would make sense to me. Requires more work, but is more elegant than 1).

    See this unofficial sample on how you can add a this yaml file.

    Regards,
    Sigurd Hellesvik

Children
Related