Skip to content

Commit b4d5cd3

Browse files
alayandercfriedt
authored andcommitted
tests: drivers: pwm: pwm_api: Add Kconfig options for test values
Add Kconfig options for default period/pulse values and port to remove platform/vendor specific preprocessor conditionals. Signed-off-by: Alexander Lay <[email protected]>
1 parent 3855d18 commit b4d5cd3

8 files changed

+68
-50
lines changed

tests/drivers/pwm/pwm_api/Kconfig

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Copyright (c) 2025 Tenstorrent AI ULC
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
mainmenu "PWM GPIO API test"
5+
6+
source "Kconfig.zephyr"
7+
8+
config DEFAULT_PWM_PORT
9+
int "Default PWM port/channel"
10+
default 1 if PWM_STM32
11+
default 0
12+
help
13+
PWM port matching the channel associated with PWM pin.
14+
15+
config INVALID_PWM_PORT
16+
int "Invalid PWM port/channel"
17+
default 9 if PWM_NRFX
18+
default -1
19+
help
20+
Invalid PWM port/channel for negative testing.
21+
22+
config DEFAULT_PERIOD_CYCLE
23+
int "Default PWM period in cycles"
24+
default 1024 if SOC_MK64F12 || SOC_MKW41Z4 || SOC_ESP32S2 || SOC_ESP32S3 || SOC_ESP32C3
25+
default 32768 if PWM_INTEL_BLINKY
26+
default 64000
27+
help
28+
Default PWM period in clock cycles.
29+
30+
config DEFAULT_PULSE_CYCLE
31+
int "Default PWM pulse in cycles"
32+
default 512 if SOC_MK64F12 || SOC_MKW41Z4 || SOC_ESP32S2 || SOC_ESP32S3 || SOC_ESP32C3
33+
default 16384 if PWM_INTEL_BLINKY
34+
default 32000
35+
help
36+
Default PWM pulse in clock cycles.
37+
38+
config DEFAULT_PERIOD_NSEC
39+
int "Default PWM period in nanoseconds"
40+
default 4000000 if SOC_FAMILY_MCXW
41+
default 2000000
42+
help
43+
Default PWM period in nanoseconds.
44+
45+
config DEFAULT_PULSE_NSEC
46+
int "Default PWM pulse in nanoseconds"
47+
default 500000 if SOC_MK64F12 || SOC_MKW41Z4 || SOC_ESP32S2 || SOC_ESP32S3 || SOC_ESP32C3
48+
default 500000 if PWM_INTEL_BLINKY
49+
default 2000000 if SOC_FAMILY_MCXW
50+
default 1000000
51+
help
52+
Default PWM pulse in nanoseconds.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CONFIG_DEFAULT_PWM_PORT=2 # TCC1/WO[2] on PA18 (D7)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
CONFIG_DEFAULT_PERIOD_CYCLE=1024
2+
CONFIG_DEFAULT_PULSE_CYCLE=512
3+
CONFIG_DEFAULT_PERIOD_NSEC=2000000
4+
CONFIG_DEFAULT_PULSE_NSEC=500000
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CONFIG_DEFAULT_PWM_PORT=2 # D2 on Arduino connector P18
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CONFIG_DEFAULT_PWM_PORT=2 # D2 on Arduino connector P18
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CONFIG_DEFAULT_PWM_PORT=7 # D3 on Arduino connector J27
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CONFIG_DEFAULT_PWM_PORT=2 # PWM on EXT2 connector, pin 8

tests/drivers/pwm/pwm_api/src/test_pwm.c

Lines changed: 7 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -35,61 +35,18 @@
3535
#error "Test requires a pwm-test alias in DTS"
3636
#endif
3737

38-
#if defined(CONFIG_BOARD_COLIBRI_IMX7D_MCIMX7D_M4) || defined(CONFIG_SOC_MK64F12) || \
39-
defined(CONFIG_SOC_MKW41Z4) || defined(CONFIG_SOC_SERIES_ESP32S2) || \
40-
defined(CONFIG_SOC_SERIES_ESP32S3) || defined(CONFIG_SOC_SERIES_ESP32C3)
41-
#define DEFAULT_PERIOD_CYCLE 1024
42-
#define DEFAULT_PULSE_CYCLE 512
43-
#define DEFAULT_PERIOD_NSEC 2000000
44-
#define DEFAULT_PULSE_NSEC 500000
45-
#elif DT_HAS_COMPAT_STATUS_OKAY(intel_blinky_pwm)
46-
#define DEFAULT_PERIOD_CYCLE 32768
47-
#define DEFAULT_PULSE_CYCLE 16384
48-
#define DEFAULT_PERIOD_NSEC 2000000
49-
#define DEFAULT_PULSE_NSEC 500000
50-
#elif defined(CONFIG_SOC_FAMILY_MCXW)
51-
#define DEFAULT_PERIOD_CYCLE 64000
52-
#define DEFAULT_PULSE_CYCLE 32000
53-
#define DEFAULT_PERIOD_NSEC 4000000
54-
#define DEFAULT_PULSE_NSEC 2000000
55-
#else
56-
#define DEFAULT_PERIOD_CYCLE 64000
57-
#define DEFAULT_PULSE_CYCLE 32000
58-
#define DEFAULT_PERIOD_NSEC 2000000
59-
#define DEFAULT_PULSE_NSEC 1000000
60-
#endif
38+
#define DEFAULT_PERIOD_CYCLE CONFIG_DEFAULT_PERIOD_CYCLE
39+
#define DEFAULT_PULSE_CYCLE CONFIG_DEFAULT_PULSE_CYCLE
40+
#define DEFAULT_PERIOD_NSEC CONFIG_DEFAULT_PERIOD_NSEC
41+
#define DEFAULT_PULSE_NSEC CONFIG_DEFAULT_PULSE_NSEC
6142

6243
#if DT_HAS_COMPAT_STATUS_OKAY(zephyr_fake_pwm)
6344
#include <zephyr/fff.h>
6445
DEFINE_FFF_GLOBALS;
6546
#endif
6647

67-
#if defined CONFIG_BOARD_SAM_E70_XPLAINED
68-
#define DEFAULT_PWM_PORT 2 /* PWM on EXT2 connector, pin 8 */
69-
#elif defined CONFIG_PWM_NRFX
70-
#define DEFAULT_PWM_PORT 0
71-
#define INVALID_PWM_PORT 9
72-
#elif defined CONFIG_BOARD_ADAFRUIT_ITSYBITSY_M4_EXPRESS
73-
#define DEFAULT_PWM_PORT 2 /* TCC1/WO[2] on PA18 (D7) */
74-
#elif defined CONFIG_BOARD_MIMXRT685_EVK
75-
#define DEFAULT_PWM_PORT 7 /* D3 on Arduino connector J27 */
76-
#elif defined(CONFIG_BOARD_LPCXPRESSO55S69_LPC55S69_CPU0_NS) || \
77-
defined(CONFIG_BOARD_LPCXPRESSO55S69_LPC55S69_CPU0)
78-
#define DEFAULT_PWM_PORT 2 /* D2 on Arduino connector P18 */
79-
#elif DT_HAS_COMPAT_STATUS_OKAY(st_stm32_pwm)
80-
/* Default port should be adapted per board to fit the channel
81-
* associated to the PWM pin. For intsance, for following device,
82-
* pwm1: pwm {
83-
* status = "okay";
84-
* pinctrl-0 = <&tim1_ch3_pe13>;
85-
* };
86-
* the following should be used:
87-
* #define DEFAULT_PWM_PORT 3
88-
*/
89-
#define DEFAULT_PWM_PORT 1
90-
#else
91-
#define DEFAULT_PWM_PORT 0
92-
#endif
48+
#define DEFAULT_PWM_PORT CONFIG_DEFAULT_PWM_PORT
49+
#define INVALID_PWM_PORT CONFIG_INVALID_PWM_PORT
9350

9451
#define UNIT_CYCLES 0
9552
#define UNIT_NSECS 1
@@ -164,7 +121,7 @@ ZTEST_USER(pwm_basic, test_pwm_cycle)
164121
k_sleep(K_MSEC(1000));
165122
}
166123

167-
#if defined INVALID_PWM_PORT
124+
#if (CONFIG_INVALID_PWM_PORT >= 0)
168125
ZTEST_USER(pwm_basic, test_pwm_invalid_port)
169126
{
170127
const struct device *pwm_dev = get_pwm_device();

0 commit comments

Comments
 (0)