Skip to content

Commit

Permalink
[nrf fromtree] tests: drivers: pwm: Update gpio config
Browse files Browse the repository at this point in the history
Update gpio config for more correct handling.

Signed-off-by: Raffael Rostagno <[email protected]>
(cherry picked from commit 931c671cc2e87670b4e49fa44807664721990426)
  • Loading branch information
Raffael Rostagno authored and nika-nordic committed Feb 21, 2025
1 parent bbcb577 commit 8057f8c
Showing 1 changed file with 26 additions and 16 deletions.
42 changes: 26 additions & 16 deletions tests/drivers/pwm/pwm_gpio_loopback/src/main.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024 Espressif Systems (Shanghai) Co., Ltd.
* Copyright (c) 2025 Espressif Systems (Shanghai) Co., Ltd.
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -97,22 +97,19 @@ static void setup_edge_detect(void)

static void config_gpio(const struct gpio_dt_spec *gpio_dt)
{
/* Configure GPIO pin for edge detection */
gpio_pin_configure_dt(gpio_dt, GPIO_INPUT);

gpio_cb.pin_mask = BIT(gpio_dt->pin);

gpio_init_callback(&gpio_cb, gpio_edge_isr, gpio_cb.pin_mask);
gpio_init_callback(&gpio_cb, gpio_edge_isr, BIT(gpio_dt->pin));
gpio_add_callback(gpio_dt->port, &gpio_cb);
gpio_pin_interrupt_configure(gpio_dt->port, gpio_dt->pin, GPIO_INT_EDGE_BOTH);
}

static void unconfig_gpio(const struct gpio_dt_spec *gpio_dt)
static void enable_int_gpio(const struct gpio_dt_spec *gpio_dt, bool enable)
{
/* Disable interrupt for already tested channel */
gpio_pin_interrupt_configure(gpio_dt->port, gpio_dt->pin, GPIO_INT_DISABLE);

gpio_cb.pin_mask &= ~BIT(gpio_dt->pin);
if (enable) {
gpio_pin_interrupt_configure(gpio_dt->port, gpio_dt->pin, GPIO_INT_EDGE_BOTH);
gpio_cb.pin_mask = BIT(gpio_dt->pin);
} else {
gpio_pin_interrupt_configure(gpio_dt->port, gpio_dt->pin, GPIO_INT_DISABLE);
}
}

static bool check_range(float refval, float measval)
Expand Down Expand Up @@ -207,11 +204,11 @@ static void test_run(const struct pwm_dt_spec *pwm_dt, const struct gpio_dt_spec
zassert_false(result, "Failed on pwm_set() call");
}

config_gpio(gpio_dt);
enable_int_gpio(gpio_dt, true);

result = check_timing(pwm_dt, gpio_dt, duty);

unconfig_gpio(gpio_dt);
enable_int_gpio(gpio_dt, false);

zassert_equal(result, TC_PASS, "Test case failed");
}
Expand All @@ -220,7 +217,6 @@ ZTEST(pwm_gpio_loopback, test_pwm)
{
for (int i = 0; i < TEST_PWM_COUNT; i++) {
zassert_true(device_is_ready(pwms_dt[i].dev), "PWM device is not ready");
zassert_true(device_is_ready(gpios_dt[i].port), "GPIO device is not ready");

/* Test case: [Duty: 25%] */
test_run(&pwms_dt[i], &gpios_dt[i], 25, true);
Expand Down Expand Up @@ -251,4 +247,18 @@ ZTEST(pwm_gpio_loopback, test_pwm_cross)
}
}

ZTEST_SUITE(pwm_gpio_loopback, NULL, NULL, NULL, NULL, NULL);
static void *pwm_gpio_loopback_setup(void)
{
for (int i = 0; i < TEST_GPIO_COUNT; i++) {
if (device_is_ready(gpios_dt[i].port)) {
/* Configure GPIO pin for edge detection */
config_gpio(&gpios_dt[i]);
} else {
TC_PRINT("GPIO device %s is not ready", gpios_dt[i].port->name);
}
}

return NULL;
}

ZTEST_SUITE(pwm_gpio_loopback, NULL, pwm_gpio_loopback_setup, NULL, NULL, NULL);

0 comments on commit 8057f8c

Please sign in to comment.