Skip to content

Commit 2db9c66

Browse files
committed
WIP tests/drivers/gpio: generalize gpio specification solution
Provide board-specific overlays that specify which pins to use for the test, rather than use aliases in the board device tree. This uses a binding that's specifically documented for use in GPIO applications. Signed-off-by: Peter Bigot <[email protected]>
1 parent e487fa7 commit 2db9c66

File tree

7 files changed

+105
-2
lines changed

7 files changed

+105
-2
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#
2+
# Copyright (c) 2019 Nordic Semiconductor ASA
3+
#
4+
# SPDX-License-Identifier: Apache-2.0
5+
#
6+
7+
title: GPIO pin definitions for tests
8+
9+
description: >
10+
Identify accessible board pins that can be used for GPIO signals.
11+
12+
Most development boards expose several GPIO pins on a header. These
13+
may be used as signals to a logic analyzer, or to simulate an
14+
external device. This binding provides a board-independent
15+
description of pins that can be made available for this purpose.
16+
17+
compatible: "test,scope-pins"
18+
19+
properties:
20+
gpios:
21+
type: compound
22+
required: true
23+
description: >
24+
Accessible pins used for GPIO-based instrumentation and
25+
testing.
26+
27+
Any number of pins may be provided, on multiple GPIO devices.
28+
However at least two entries must be present, and the first
29+
two must be on the same GPIO device.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*
2+
* Copyright (c) 2019 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/ {
8+
scope-pins {
9+
compatible = "test,scope-pins";
10+
gpios = <&gpiof 6 0>, <&gpiof 5 0>;
11+
};
12+
};
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* Copyright (c) 2019 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/ {
8+
scope-pins {
9+
compatible = "test,scope-pins";
10+
gpios =
11+
<&gpioc 16 0>, <&gpioc 17 0>,
12+
<&gpioc 2 0>, <&gpioc 3 0>,
13+
<&gpioc 1 0>, <&gpioc 8 0>,
14+
<&gpioc 9 0>, <&gpioc 0 0>,
15+
<&gpioc 7 0>, <&gpioc 5 0>;
16+
17+
};
18+
};
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
* Copyright (c) 2019 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/ {
8+
scope-pins {
9+
compatible = "test,scope-pins";
10+
/* Use pins on P3 (Arduino D0) header. */
11+
gpios =
12+
<&gpio1 1 0>, <&gpio1 2 0>,
13+
<&gpio1 3 0>, <&gpio1 4 0>,
14+
<&gpio1 5 0>, <&gpio1 6 0>,
15+
<&gpio1 7 0>, <&gpio1 8 0>;
16+
};
17+
};

tests/drivers/gpio/gpio_basic_api/prj.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ CONFIG_GPIO=y
22
CONFIG_ZTEST=y
33
CONFIG_ENTROPY_GENERATOR=y
44
CONFIG_TEST_RANDOM_GENERATOR=y
5+
#CONFIG_TEST_USERSPACE=y

tests/drivers/gpio/gpio_basic_api/src/main.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,29 @@
77

88
#include "test_gpio.h"
99

10+
/* Grotesque hack for pinmux boards */
11+
#ifdef CONFIG_BOARD_FRDM_K64F
12+
#include <drivers/pinmux.h>
13+
#include <fsl_port.h>
14+
#endif
15+
16+
static void board_setup(void)
17+
{
18+
#ifdef CONFIG_BOARD_FRDM_K64F
19+
printk("Setting up pinmux for K64F\n");
20+
const char *pmx_name = "portc";
21+
struct device *pmx = device_get_binding(pmx_name);
22+
printk("pmx %s for %s: %p\n", pmx_name, DEV_NAME, pmx);
23+
int rc = pinmux_pin_set(pmx, PIN_OUT, PORT_PCR_MUX(kPORT_MuxAsGpio));
24+
printk("pmx pin %u: %d\n", PIN_OUT, rc);
25+
rc = pinmux_pin_set(pmx, PIN_IN, PORT_PCR_MUX(kPORT_MuxAsGpio));
26+
printk("pmx pin %u: %d\n", PIN_IN, rc);
27+
#endif
28+
}
29+
1030
void test_main(void)
1131
{
32+
board_setup();
1233
ztest_test_suite(gpio_basic_test,
1334
ztest_unit_test(test_gpio_port),
1435
ztest_unit_test(test_gpio_pin_read_write),

tests/drivers/gpio/gpio_basic_api/src/test_gpio.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@
1212
#include <sys/util.h>
1313
#include <ztest.h>
1414

15-
#if defined(DT_ALIAS_GPIO_0_LABEL)
15+
#ifdef DT_INST_0_TEST_SCOPE_PINS
16+
#define DEV_NAME DT_INST_0_TEST_SCOPE_PINS_GPIOS_CONTROLLER_0
17+
#define PIN_OUT DT_TEST_SCOPE_PINS_SCOPE_PINS_GPIOS_PIN_0
18+
#define PIN_IN DT_TEST_SCOPE_PINS_SCOPE_PINS_GPIOS_PIN_1
19+
#elif defined(DT_ALIAS_GPIO_0_LABEL)
1620
#define DEV_NAME DT_ALIAS_GPIO_0_LABEL
1721
#elif defined(DT_ALIAS_GPIO_1_LABEL)
1822
#define DEV_NAME DT_ALIAS_GPIO_1_LABEL
@@ -22,9 +26,10 @@
2226
#error Unsupported board
2327
#endif
2428

29+
#ifndef PIN_OUT
2530
#define PIN_OUT 2
2631
#define PIN_IN 3
27-
32+
#endif /* PIN_OUT */
2833

2934
#define MAX_INT_CNT 3
3035
struct drv_data {

0 commit comments

Comments
 (0)