|
15 | 15 | #include <zephyr/drivers/gpio.h>
|
16 | 16 | #include <zephyr/device.h>
|
17 | 17 | #include <zephyr/kernel.h>
|
| 18 | +#include <zephyr/drivers/pinctrl.h> |
18 | 19 |
|
19 | 20 | #include <zephyr/logging/log.h>
|
20 | 21 | LOG_MODULE_REGISTER(led_gpio, CONFIG_LED_LOG_LEVEL);
|
21 | 22 |
|
22 | 23 | struct led_gpio_config {
|
23 | 24 | size_t num_leds;
|
24 | 25 | const struct gpio_dt_spec *led;
|
| 26 | + const struct pinctrl_dev_config *pcfg; |
25 | 27 | };
|
26 | 28 |
|
27 | 29 | static int led_gpio_set_brightness(const struct device *dev, uint32_t led, uint8_t value)
|
@@ -59,6 +61,12 @@ static int led_gpio_init(const struct device *dev)
|
59 | 61 | err = -ENODEV;
|
60 | 62 | }
|
61 | 63 |
|
| 64 | + err = pinctrl_apply_state(config->pcfg, PINCTRL_STATE_DEFAULT); |
| 65 | + if (err < 0 && err != -ENOENT) { |
| 66 | + LOG_ERR("failed to apply pinctrl"); |
| 67 | + return err; |
| 68 | + } |
| 69 | + |
62 | 70 | for (size_t i = 0; (i < config->num_leds) && !err; i++) {
|
63 | 71 | const struct gpio_dt_spec *led = &config->led[i];
|
64 | 72 |
|
@@ -92,6 +100,7 @@ static const struct gpio_dt_spec gpio_dt_spec_##i[] = { \
|
92 | 100 | static const struct led_gpio_config led_gpio_config_##i = { \
|
93 | 101 | .num_leds = ARRAY_SIZE(gpio_dt_spec_##i), \
|
94 | 102 | .led = gpio_dt_spec_##i, \
|
| 103 | + .pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(i), \ |
95 | 104 | }; \
|
96 | 105 | \
|
97 | 106 | DEVICE_DT_INST_DEFINE(i, &led_gpio_init, NULL, \
|
|
0 commit comments