Dynamically setting the LPCOMP REFSEL

Hello,

Is there a way to change the LPCOMP reference level in Zephyr other than what is set in the devicetree overlay?

I'm happy to disable it, change it and re-enable it if that's what's needed I just can't see how that can be done through Zephyr.

Example code I currently have is basic, in premise the change I'd like is to go from reference VDD_4_8 to VDD_3_8 when the first reference is passed/a callback is triggered.

Here's the basic code I already have, thank you -

#include <zephyr/drivers/comparator.h>

#include <zephyr/drivers/gpio.h>

#include <zephyr/kernel.h>

#include <zephyr/pm/device_runtime.h>

static const struct device *test_dev = DEVICE_DT_GET(DT_ALIAS(test_comp));

static const struct gpio_dt_spec test_pin = GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), test_gpios);

volatile int counter;

static void test_callback(const struct device *dev, void *user_data)

{

    counter++;

    printk("Comparator triggered, counter=%d\n", counter);

}

void main(void)

{

    int rc;



    pm_device_runtime_enable(test_dev);

    pm_device_runtime_get(test_dev);

    rc = comparator_set_trigger_callback(test_dev, test_callback, NULL);

    __ASSERT_NO_MSG(rc == 0);

    rc = comparator_set_trigger(test_dev, COMPARATOR_TRIGGER_FALLING_EDGE);

    __ASSERT_NO_MSG(rc == 0);

    counter = 0;

    while (1) {

        __WFE();  // Wait for event (comparator interrupt)

    }

}

Parents Reply Children
Related