From 888c0d966cd52f3ab5145992f61b14d6262c1951 Mon Sep 17 00:00:00 2001 From: Peter Johanson Date: Fri, 15 Nov 2024 10:36:19 -0700 Subject: [PATCH] feat(drivers): Support init high/low in 595 driver Add support for initializing a pin to a given high/low value during configuration. Needed for proper initialization by systems like GPIO hogs or gpio-leds Zephyr drivers. --- app/module/drivers/gpio/gpio_595.c | 46 +++++++++++++++++------------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/app/module/drivers/gpio/gpio_595.c b/app/module/drivers/gpio/gpio_595.c index 3d3858449c5..d9cc66448db 100644 --- a/app/module/drivers/gpio/gpio_595.c +++ b/app/module/drivers/gpio/gpio_595.c @@ -89,26 +89,6 @@ static int setup_pin_dir(const struct device *dev, uint32_t pin, int flags) { return 0; } -static int reg_595_pin_config(const struct device *dev, gpio_pin_t pin, gpio_flags_t flags) { - int ret; - - /* Can't do SPI bus operations from an ISR */ - if (k_is_in_isr()) { - return -EWOULDBLOCK; - } - - if ((flags & GPIO_OPEN_DRAIN) != 0U) { - return -ENOTSUP; - }; - - ret = setup_pin_dir(dev, pin, flags); - if (ret) { - LOG_ERR("595: error setting pin direction (%d)", ret); - } - - return ret; -} - static int reg_595_port_get_raw(const struct device *dev, uint32_t *value) { return -ENOTSUP; } static int reg_595_port_set_masked_raw(const struct device *dev, uint32_t mask, uint32_t value) { @@ -161,6 +141,32 @@ static int reg_595_port_toggle_bits(const struct device *dev, uint32_t mask) { return ret; } +static int reg_595_pin_config(const struct device *dev, gpio_pin_t pin, gpio_flags_t flags) { + int ret; + + /* Can't do SPI bus operations from an ISR */ + if (k_is_in_isr()) { + return -EWOULDBLOCK; + } + + if ((flags & GPIO_OPEN_DRAIN) != 0U) { + return -ENOTSUP; + }; + + ret = setup_pin_dir(dev, pin, flags); + if (ret) { + LOG_ERR("595: error setting pin direction (%d)", ret); + } + + if ((flags & GPIO_OUTPUT_INIT_LOW) != 0) { + return reg_595_port_clear_bits_raw(dev, BIT(pin)); + } else if ((flags & GPIO_OUTPUT_INIT_HIGH) != 0) { + return reg_595_port_set_bits_raw(dev, BIT(pin)); + } + + return ret; +} + static const struct gpio_driver_api api_table = { .pin_configure = reg_595_pin_config, .port_get_raw = reg_595_port_get_raw,