As always the simplest thing in Zephyr is also the most complicated. I have a Laird module (the BL652) that originally used GPIO 0.19 as an LED driver in their device tree. I overlay that use in my device tree to produce an (active low) enable like so:
/delete-node/ &led2; // GPIO 19 repurposed to be vout enable
/{
lm5176_control {
compatible = "gpio-leds";
enable1: enable_1 {
gpios = <&gpio0 19 GPIO_ACTIVE_HIGH>;
label = "VOUT Enable Low";
};
};
aliases {
cmvoutenable = &enable1;
/delete-property/ led1; // This was GPIO 19
};
};
Then, in my C code, I set up a dt spec like this:
#define VOUT_ENABLE DT_ALIAS(cmvoutenable) static const struct gpio_dt_spec vout_enable = GPIO_DT_SPEC_GET(VOUT_ENABLE, gpios);
And I try to set the state of the GPIO like this:
message_error_t lm5176_vout_set_enable( bool on )
{
if (!device_is_ready(vout_enable.port)) {
printk("VOUT GPIO enable not ready\n");
return GPIO_ERROR;
} else {
if( gpio_pin_configure_dt(&vout_enable, GPIO_OUTPUT_ACTIVE) < 0 ) {
printk("VOUT GPIO enable cannot be activated\n");
return GPIO_ERROR;
}
}
if ( on ) {
printk("Enabling Vout\n");
}
else {
printk("Disabling Vout\n");
}
// GPIO logic is reversed from pin function
if( gpio_pin_set_dt(&vout_enable, on ? 0 : 1 ) < 0 ) {
printk("Unable to set Vout enable");
return GPIO_ERROR;
}
return MESSAGE_OK;
}
But the GPIO is forever high, regardless of what I try to set it to.
Am I misunderstanding the use of gpio_pin_set_dt?