Skip to content

Commit 16dc0c6

Browse files
Raffael Rostagnorlubos
authored andcommitted
[nrf fromtree] tests: drivers: pwm: Update gpio config
Update gpio config for more correct handling. Signed-off-by: Raffael Rostagno <[email protected]> (cherry picked from commit 931c671)
1 parent 3ed21ed commit 16dc0c6

File tree

1 file changed

+26
-16
lines changed
  • tests/drivers/pwm/pwm_gpio_loopback/src

1 file changed

+26
-16
lines changed

tests/drivers/pwm/pwm_gpio_loopback/src/main.c

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2024 Espressif Systems (Shanghai) Co., Ltd.
2+
* Copyright (c) 2025 Espressif Systems (Shanghai) Co., Ltd.
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -97,22 +97,19 @@ static void setup_edge_detect(void)
9797

9898
static void config_gpio(const struct gpio_dt_spec *gpio_dt)
9999
{
100-
/* Configure GPIO pin for edge detection */
101100
gpio_pin_configure_dt(gpio_dt, GPIO_INPUT);
102-
103-
gpio_cb.pin_mask = BIT(gpio_dt->pin);
104-
105-
gpio_init_callback(&gpio_cb, gpio_edge_isr, gpio_cb.pin_mask);
101+
gpio_init_callback(&gpio_cb, gpio_edge_isr, BIT(gpio_dt->pin));
106102
gpio_add_callback(gpio_dt->port, &gpio_cb);
107-
gpio_pin_interrupt_configure(gpio_dt->port, gpio_dt->pin, GPIO_INT_EDGE_BOTH);
108103
}
109104

110-
static void unconfig_gpio(const struct gpio_dt_spec *gpio_dt)
105+
static void enable_int_gpio(const struct gpio_dt_spec *gpio_dt, bool enable)
111106
{
112-
/* Disable interrupt for already tested channel */
113-
gpio_pin_interrupt_configure(gpio_dt->port, gpio_dt->pin, GPIO_INT_DISABLE);
114-
115-
gpio_cb.pin_mask &= ~BIT(gpio_dt->pin);
107+
if (enable) {
108+
gpio_pin_interrupt_configure(gpio_dt->port, gpio_dt->pin, GPIO_INT_EDGE_BOTH);
109+
gpio_cb.pin_mask = BIT(gpio_dt->pin);
110+
} else {
111+
gpio_pin_interrupt_configure(gpio_dt->port, gpio_dt->pin, GPIO_INT_DISABLE);
112+
}
116113
}
117114

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

210-
config_gpio(gpio_dt);
207+
enable_int_gpio(gpio_dt, true);
211208

212209
result = check_timing(pwm_dt, gpio_dt, duty);
213210

214-
unconfig_gpio(gpio_dt);
211+
enable_int_gpio(gpio_dt, false);
215212

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

225221
/* Test case: [Duty: 25%] */
226222
test_run(&pwms_dt[i], &gpios_dt[i], 25, true);
@@ -251,4 +247,18 @@ ZTEST(pwm_gpio_loopback, test_pwm_cross)
251247
}
252248
}
253249

254-
ZTEST_SUITE(pwm_gpio_loopback, NULL, NULL, NULL, NULL, NULL);
250+
static void *pwm_gpio_loopback_setup(void)
251+
{
252+
for (int i = 0; i < TEST_GPIO_COUNT; i++) {
253+
if (device_is_ready(gpios_dt[i].port)) {
254+
/* Configure GPIO pin for edge detection */
255+
config_gpio(&gpios_dt[i]);
256+
} else {
257+
TC_PRINT("GPIO device %s is not ready", gpios_dt[i].port->name);
258+
}
259+
}
260+
261+
return NULL;
262+
}
263+
264+
ZTEST_SUITE(pwm_gpio_loopback, NULL, pwm_gpio_loopback_setup, NULL, NULL, NULL);

0 commit comments

Comments
 (0)