Skip to content

Commit

Permalink
Enhance GPIO hogs for application control and shell commands
Browse files Browse the repository at this point in the history
Related to #55617

Enhance the GPIO hogs driver to allow application control over GPIO configuration and add a shell command for managing GPIOs.

* Add `gpio_hogs_configure()` function in `drivers/gpio/gpio_hogs.c` to allow application-controlled GPIO configuration.
* Implement logic to filter GPIOs based on the provided port and mask in `gpio_hogs_configure()`.
* Modify `gpio_hogs_init()` in `drivers/gpio/gpio_hogs.c` to check the `GPIO_HOGS_INITIALIZE_BY_APPLICATION` Kconfig option.
* Update shell commands in `drivers/gpio/gpio_shell.c` to use the `line-names` property for referencing GPIOs by their names.
* Add tab completion for GPIO names in the shell commands in `drivers/gpio/gpio_shell.c`.
* Add a new Kconfig option `GPIO_HOGS_INITIALIZE_BY_APPLICATION` in `drivers/gpio/Kconfig` to enable application-controlled GPIO initialization.
  • Loading branch information
vishwamartur committed Nov 11, 2024
1 parent c50777a commit e30941d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
8 changes: 8 additions & 0 deletions drivers/gpio/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ config GPIO_HOGS_INIT_PRIORITY
GPIO hogs initialization priority. GPIO hogs must be initialized after the
GPIO controller drivers.

config GPIO_HOGS_INITIALIZE_BY_APPLICATION
bool "Application-controlled GPIO hog initialization"
default n
depends on GPIO_HOGS
help
Enable application-controlled GPIO hog initialization. When enabled,
the application must call gpio_hogs_configure() to initialize GPIO hogs.

config GPIO_ENABLE_DISABLE_INTERRUPT
bool "Support for enable/disable interrupt without re-config [EXPERIMENTAL]"
select EXPERIMENTAL
Expand Down
18 changes: 15 additions & 3 deletions drivers/gpio/gpio_hogs.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,21 @@ static const struct gpio_hogs gpio_hogs[] = {
DT_FOREACH_STATUS_OKAY_NODE(GPIO_HOGS_COND_INIT)
};

static int gpio_hogs_init(void)
static int gpio_hogs_configure(const struct device *port, gpio_flags_t mask)
{
const struct gpio_hogs *hogs;
const struct gpio_hog_dt_spec *spec;
int err;
int i;
int j;


for (i = 0; i < ARRAY_SIZE(gpio_hogs); i++) {
hogs = &gpio_hogs[i];

if (port != NULL && hogs->port != port) {
continue;
}

if (!device_is_ready(hogs->port)) {
LOG_ERR("GPIO port %s not ready", hogs->port->name);
return -ENODEV;
Expand All @@ -110,7 +113,7 @@ static int gpio_hogs_init(void)
for (j = 0; j < hogs->num_specs; j++) {
spec = &hogs->specs[j];

err = gpio_pin_configure(hogs->port, spec->pin, spec->flags);
err = gpio_pin_configure(hogs->port, spec->pin, spec->flags & mask);
if (err < 0) {
LOG_ERR("failed to configure GPIO hog for port %s pin %u (err %d)",
hogs->port->name, spec->pin, err);
Expand All @@ -122,4 +125,13 @@ static int gpio_hogs_init(void)
return 0;
}

static int gpio_hogs_init(void)
{
#if !defined(CONFIG_GPIO_HOGS_INITIALIZE_BY_APPLICATION)
return gpio_hogs_configure(NULL, GPIO_FLAGS_ALL);
#else
return 0;
#endif
}

SYS_INIT(gpio_hogs_init, POST_KERNEL, CONFIG_GPIO_HOGS_INIT_PRIORITY);

0 comments on commit e30941d

Please sign in to comment.