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 a50bd78
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions app/module/drivers/gpio/gpio_595.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@ static int setup_pin_dir(const struct device *dev, uint32_t pin, int flags) {
return 0;
}

static int reg_595_port_set_bits_raw(const struct device *dev, uint32_t mask) {
return reg_595_port_set_masked_raw(dev, mask, mask);
}

static int reg_595_port_clear_bits_raw(const struct device *dev, uint32_t mask) {
return reg_595_port_set_masked_raw(dev, mask, 0);
}

static int reg_595_pin_config(const struct device *dev, gpio_pin_t pin, gpio_flags_t flags) {
int ret;

Expand All @@ -106,6 +114,12 @@ static int reg_595_pin_config(const struct device *dev, gpio_pin_t pin, gpio_fla
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;
}

Expand All @@ -132,14 +146,6 @@ static int reg_595_port_set_masked_raw(const struct device *dev, uint32_t mask,
return ret;
}

static int reg_595_port_set_bits_raw(const struct device *dev, uint32_t mask) {
return reg_595_port_set_masked_raw(dev, mask, mask);
}

static int reg_595_port_clear_bits_raw(const struct device *dev, uint32_t mask) {
return reg_595_port_set_masked_raw(dev, mask, 0);
}

static int reg_595_port_toggle_bits(const struct device *dev, uint32_t mask) {
struct reg_595_drv_data *const drv_data = (struct reg_595_drv_data *const)dev->data;
uint32_t buf;
Expand Down

0 comments on commit a50bd78

Please sign in to comment.