Skip to content

Commit

Permalink
feat(drivers): Support init high/low in 595 driver
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
petejohanson committed Nov 15, 2024
1 parent 58de2eb commit 19b408c
Showing 1 changed file with 26 additions and 20 deletions.
46 changes: 26 additions & 20 deletions app/module/drivers/gpio/gpio_595.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 19b408c

Please sign in to comment.