Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance GPIO hogs for application control and shell commands #81238

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Loading