Skip to content

Commit

Permalink
tests: gpio_basic_api: Convert test to use DEVICE_DT_GET
Browse files Browse the repository at this point in the history
Move to use DEVICE_DT_GET instead of device_get_binding as
we work on phasing out use of DTS 'label' property.

Signed-off-by: Kumar Gala <[email protected]>
  • Loading branch information
galak committed Jul 8, 2022
1 parent 1f82e32 commit 2a8e3fe
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 28 deletions.
26 changes: 11 additions & 15 deletions tests/drivers/gpio/gpio_basic_api/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ static void board_setup(void)
{
#if DT_NODE_HAS_STATUS(DT_INST(0, test_gpio_basic_api), okay)
/* PIN_IN and PIN_OUT must be on same controller. */
if (strcmp(DT_GPIO_LABEL(DT_INST(0, test_gpio_basic_api), out_gpios),
DT_GPIO_LABEL(DT_INST(0, test_gpio_basic_api), in_gpios)) != 0) {
const struct device *in_dev = DEVICE_DT_GET(DEV_OUT);
const struct device *out_dev = DEVICE_DT_GET(DEV_IN);

if (in_dev != out_dev) {
printk("FATAL: output controller %s != input controller %s\n",
DT_GPIO_LABEL(DT_INST(0, test_gpio_basic_api), out_gpios),
DT_GPIO_LABEL(DT_INST(0, test_gpio_basic_api), in_gpios));
out_dev->name, in_dev->name);
k_panic();
}
#endif
Expand All @@ -37,12 +38,6 @@ static void board_setup(void)
* selected as test pins in device tree.
*/

if (strcmp(DEV_NAME, "GPIO_5") != 0) {
printk("FATAL: controller set in DTS %s != controller %s\n",
DEV_NAME, "GPIO_5");
k_panic();
}

if (PIN_IN != 15) {
printk("FATAL: input pin set in DTS %d != %d\n", PIN_IN, 15);
k_panic();
Expand Down Expand Up @@ -87,16 +82,17 @@ static void board_setup(void)
IOMUXC_SW_PAD_CTL_PAD_SPEED(2) |
IOMUXC_SW_PAD_CTL_PAD_DSE(6));
#elif defined(CONFIG_BOARD_RV32M1_VEGA)
const char *pmx_name = DT_LABEL(DT_NODELABEL(porta));
const struct device *pmx = device_get_binding(pmx_name);
const struct device *pmx = DEVICE_DT_GET(DT_NODELABEL(porta));

zassert_true(device_is_ready(pmx), "pinmux dev is not ready");

pinmux_pin_set(pmx, PIN_OUT, PORT_PCR_MUX(kPORT_MuxAsGpio));
pinmux_pin_set(pmx, PIN_IN, PORT_PCR_MUX(kPORT_MuxAsGpio));
#elif defined(CONFIG_GPIO_EMUL)
extern struct gpio_callback gpio_emul_callback;
const struct device *dev = device_get_binding(DEV_NAME);
zassert_not_equal(dev, NULL,
"Device not found");
const struct device *dev = DEVICE_DT_GET(DEV);

zassert_true(device_is_ready(dev), "GPIO dev is not ready");
int rc = gpio_add_callback(dev, &gpio_emul_callback);
__ASSERT(rc == 0, "gpio_add_callback() failed: %d", rc);
#endif
Expand Down
6 changes: 3 additions & 3 deletions tests/drivers/gpio/gpio_basic_api/src/test_callback_manage.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ static void trigger_callback(const struct device *dev, int enable_cb)

static int test_callback_add_remove(void)
{
const struct device *dev = device_get_binding(DEV_NAME);
const struct device *dev = DEVICE_DT_GET(DEV);

/* SetUp: initialize environment */
int rc = init_callback(dev, callback_1, callback_2);
Expand Down Expand Up @@ -132,7 +132,7 @@ static int test_callback_add_remove(void)
static int test_callback_self_remove(void)
{
int res = TC_FAIL;
const struct device *dev = device_get_binding(DEV_NAME);
const struct device *dev = DEVICE_DT_GET(DEV);

/* SetUp: initialize environment */
int rc = init_callback(dev, callback_1, callback_remove_self);
Expand Down Expand Up @@ -184,7 +184,7 @@ static int test_callback_self_remove(void)

static int test_callback_enable_disable(void)
{
const struct device *dev = device_get_binding(DEV_NAME);
const struct device *dev = DEVICE_DT_GET(DEV);

/* SetUp: initialize environment */
int rc = init_callback(dev, callback_1, callback_2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ static void callback(const struct device *dev,

static int test_callback(int mode)
{
const struct device *dev = device_get_binding(DEV_NAME);
const struct device *dev = DEVICE_DT_GET(DEV);
struct drv_data *drv_data = &data;

gpio_pin_interrupt_configure(dev, PIN_IN, GPIO_INT_DISABLE);
Expand Down
10 changes: 6 additions & 4 deletions tests/drivers/gpio/gpio_basic_api/src/test_gpio.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,18 @@
* If this is not present devices that have gpio-0, gpio-1, or gpio-2
* aliases are supported for build-only tests.
*/
#define DEV_NAME DT_GPIO_LABEL(DT_INST(0, test_gpio_basic_api), out_gpios)
#define DEV_OUT DT_GPIO_CTLR(DT_INST(0, test_gpio_basic_api), out_gpios)
#define DEV_IN DT_GPIO_CTLR(DT_INST(0, test_gpio_basic_api), in_gpios)
#define DEV DEV_OUT /* DEV_OUT should equal DEV_IN, we test for this */
#define PIN_OUT DT_GPIO_PIN(DT_INST(0, test_gpio_basic_api), out_gpios)
#define PIN_IN DT_GPIO_PIN(DT_INST(0, test_gpio_basic_api), in_gpios)

#elif DT_NODE_HAS_STATUS(DT_ALIAS(gpio_0), okay)
#define DEV_NAME DT_LABEL(DT_ALIAS(gpio_0))
#define DEV DT_GPIO_CTLR(DT_ALIAS(gpio_0))
#elif DT_NODE_HAS_STATUS(DT_ALIAS(gpio_1), okay)
#define DEV_NAME DT_LABEL(DT_ALIAS(gpio_1))
#define DEV DT_GPIO_CTLR(DT_ALIAS(gpio_1))
#elif DT_NODE_HAS_STATUS(DT_ALIAS(gpio_3), okay)
#define DEV_NAME DT_LABEL(DT_ALIAS(gpio_3))
#define DEV DT_GPIO_CTLR(DT_ALIAS(gpio_3))
#else
#error Unsupported board
#endif
Expand Down
10 changes: 5 additions & 5 deletions tests/drivers/gpio/gpio_basic_api/src/test_gpio_port.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ static int setup(void)
int rc;
gpio_port_value_t v1;

TC_PRINT("Validate device %s\n", DEV_NAME);
dev = device_get_binding(DEV_NAME);
zassert_not_equal(dev, NULL,
"Device not found");
const struct device *dev = DEVICE_DT_GET(DEV);

TC_PRINT("Check %s output %d connected to input %d\n", DEV_NAME,
TC_PRINT("Validate device %s\n", dev->name);
zassert_true(device_is_ready(dev), "GPIO dev is not ready");

TC_PRINT("Check %s output %d connected to input %d\n", dev->name,
PIN_OUT, PIN_IN);

rc = gpio_pin_configure(dev, PIN_IN, GPIO_INPUT);
Expand Down

0 comments on commit 2a8e3fe

Please sign in to comment.