diff options
author | Peter Johanson <[email protected]> | 2024-11-15 10:36:19 -0700 |
---|---|---|
committer | Pete Johanson <[email protected]> | 2024-11-15 11:00:37 -0700 |
commit | 888c0d966cd52f3ab5145992f61b14d6262c1951 (patch) | |
tree | 592f1f645cf811549a6d59f0f59e9098e5965af8 | |
parent | 58de2eb5e96937ece2129d8b47997349aaf5e6c7 (diff) | |
download | zmk-888c0d966cd52f3ab5145992f61b14d6262c1951.tar.gz zmk-888c0d966cd52f3ab5145992f61b14d6262c1951.zip |
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.
-rw-r--r-- | app/module/drivers/gpio/gpio_595.c | 46 |
1 files changed, 26 insertions, 20 deletions
diff --git a/app/module/drivers/gpio/gpio_595.c b/app/module/drivers/gpio/gpio_595.c index 3d3858449c..d9cc66448d 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, |