Skip to content

Commit

Permalink
WIP tests/drivers/gpio: generalize gpio specification solution
Browse files Browse the repository at this point in the history
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 <peter.bigot@nordicsemi.no>
  • Loading branch information
pabigot committed Sep 18, 2019
1 parent e487fa7 commit 2db9c66
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 2 deletions.
29 changes: 29 additions & 0 deletions dts/bindings/misc/test,scope-pins.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#
# Copyright (c) 2019 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: Apache-2.0
#

title: GPIO pin definitions for tests

description: >
Identify accessible board pins that can be used for GPIO signals.
Most development boards expose several GPIO pins on a header. These
may be used as signals to a logic analyzer, or to simulate an
external device. This binding provides a board-independent
description of pins that can be made available for this purpose.
compatible: "test,scope-pins"

properties:
gpios:
type: compound
required: true
description: >
Accessible pins used for GPIO-based instrumentation and
testing.
Any number of pins may be provided, on multiple GPIO devices.
However at least two entries must be present, and the first
two must be on the same GPIO device.
12 changes: 12 additions & 0 deletions tests/drivers/gpio/gpio_basic_api/efr32mg_sltb004a.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* Copyright (c) 2019 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/

/ {
scope-pins {
compatible = "test,scope-pins";
gpios = <&gpiof 6 0>, <&gpiof 5 0>;
};
};
18 changes: 18 additions & 0 deletions tests/drivers/gpio/gpio_basic_api/frdm_k64f.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright (c) 2019 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/

/ {
scope-pins {
compatible = "test,scope-pins";
gpios =
<&gpioc 16 0>, <&gpioc 17 0>,
<&gpioc 2 0>, <&gpioc 3 0>,
<&gpioc 1 0>, <&gpioc 8 0>,
<&gpioc 9 0>, <&gpioc 0 0>,
<&gpioc 7 0>, <&gpioc 5 0>;

};
};
17 changes: 17 additions & 0 deletions tests/drivers/gpio/gpio_basic_api/nrf52840_pca10056.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright (c) 2019 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/

/ {
scope-pins {
compatible = "test,scope-pins";
/* Use pins on P3 (Arduino D0) header. */
gpios =
<&gpio1 1 0>, <&gpio1 2 0>,
<&gpio1 3 0>, <&gpio1 4 0>,
<&gpio1 5 0>, <&gpio1 6 0>,
<&gpio1 7 0>, <&gpio1 8 0>;
};
};
1 change: 1 addition & 0 deletions tests/drivers/gpio/gpio_basic_api/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ CONFIG_GPIO=y
CONFIG_ZTEST=y
CONFIG_ENTROPY_GENERATOR=y
CONFIG_TEST_RANDOM_GENERATOR=y
#CONFIG_TEST_USERSPACE=y
21 changes: 21 additions & 0 deletions tests/drivers/gpio/gpio_basic_api/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,29 @@

#include "test_gpio.h"

/* Grotesque hack for pinmux boards */
#ifdef CONFIG_BOARD_FRDM_K64F
#include <drivers/pinmux.h>
#include <fsl_port.h>
#endif

static void board_setup(void)
{
#ifdef CONFIG_BOARD_FRDM_K64F
printk("Setting up pinmux for K64F\n");
const char *pmx_name = "portc";
struct device *pmx = device_get_binding(pmx_name);
printk("pmx %s for %s: %p\n", pmx_name, DEV_NAME, pmx);
int rc = pinmux_pin_set(pmx, PIN_OUT, PORT_PCR_MUX(kPORT_MuxAsGpio));
printk("pmx pin %u: %d\n", PIN_OUT, rc);
rc = pinmux_pin_set(pmx, PIN_IN, PORT_PCR_MUX(kPORT_MuxAsGpio));
printk("pmx pin %u: %d\n", PIN_IN, rc);
#endif
}

void test_main(void)
{
board_setup();
ztest_test_suite(gpio_basic_test,
ztest_unit_test(test_gpio_port),
ztest_unit_test(test_gpio_pin_read_write),
Expand Down
9 changes: 7 additions & 2 deletions tests/drivers/gpio/gpio_basic_api/src/test_gpio.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@
#include <sys/util.h>
#include <ztest.h>

#if defined(DT_ALIAS_GPIO_0_LABEL)
#ifdef DT_INST_0_TEST_SCOPE_PINS
#define DEV_NAME DT_INST_0_TEST_SCOPE_PINS_GPIOS_CONTROLLER_0
#define PIN_OUT DT_TEST_SCOPE_PINS_SCOPE_PINS_GPIOS_PIN_0
#define PIN_IN DT_TEST_SCOPE_PINS_SCOPE_PINS_GPIOS_PIN_1
#elif defined(DT_ALIAS_GPIO_0_LABEL)
#define DEV_NAME DT_ALIAS_GPIO_0_LABEL
#elif defined(DT_ALIAS_GPIO_1_LABEL)
#define DEV_NAME DT_ALIAS_GPIO_1_LABEL
Expand All @@ -22,9 +26,10 @@
#error Unsupported board
#endif

#ifndef PIN_OUT
#define PIN_OUT 2
#define PIN_IN 3

#endif /* PIN_OUT */

#define MAX_INT_CNT 3
struct drv_data {
Expand Down

0 comments on commit 2db9c66

Please sign in to comment.