1 /* 2 * Copyright (c) 2015-2016 Intel Corporation. 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #ifndef __TEST_GPIO_H__ 8 #define __TEST_GPIO_H__ 9 10 #include <zephyr/kernel.h> 11 #include <zephyr/drivers/gpio.h> 12 #include <zephyr/sys/util.h> 13 #include <zephyr/ztest.h> 14 15 #if DT_NODE_HAS_STATUS(DT_INST(0, test_gpio_basic_api), okay) 16 17 /* Execution of the test requires hardware configuration described in 18 * devicetree. See the test,gpio_basic_api binding local to this test 19 * for details. 20 * 21 * If this is not present devices that have gpio-0, gpio-1, or gpio-2 22 * aliases are supported for build-only tests. 23 */ 24 #define DEV_OUT DT_GPIO_CTLR(DT_INST(0, test_gpio_basic_api), out_gpios) 25 #define DEV_IN DT_GPIO_CTLR(DT_INST(0, test_gpio_basic_api), in_gpios) 26 #define DEV DEV_OUT /* DEV_OUT should equal DEV_IN, we test for this */ 27 #define PIN_OUT DT_GPIO_PIN(DT_INST(0, test_gpio_basic_api), out_gpios) 28 #define PIN_OUT_FLAGS DT_GPIO_FLAGS(DT_INST(0, test_gpio_basic_api), out_gpios) 29 #define PIN_IN DT_GPIO_PIN(DT_INST(0, test_gpio_basic_api), in_gpios) 30 #define PIN_IN_FLAGS DT_GPIO_FLAGS(DT_INST(0, test_gpio_basic_api), in_gpios) 31 32 #elif DT_NODE_HAS_STATUS(DT_ALIAS(gpio_0), okay) 33 #define DEV DT_GPIO_CTLR(DT_ALIAS(gpio_0)) 34 #elif DT_NODE_HAS_STATUS(DT_ALIAS(gpio_1), okay) 35 #define DEV DT_GPIO_CTLR(DT_ALIAS(gpio_1)) 36 #elif DT_NODE_HAS_STATUS(DT_ALIAS(gpio_3), okay) 37 #define DEV DT_GPIO_CTLR(DT_ALIAS(gpio_3)) 38 #else 39 #error Unsupported board 40 #endif 41 42 #ifndef PIN_OUT 43 /* For build-only testing use fixed pins. */ 44 #define PIN_OUT 2 45 #define PIN_IN 3 46 #endif 47 48 #define MAX_INT_CNT 3 49 struct drv_data { 50 struct gpio_callback gpio_cb; 51 gpio_flags_t mode; 52 int index; 53 int aux; 54 }; 55 56 void test_gpio_pin_read_write(void); 57 void test_gpio_callback_add_remove(void); 58 void test_gpio_callback_self_remove(void); 59 void test_gpio_callback_enable_disable(void); 60 void test_gpio_callback_variants(void); 61 62 void test_gpio_port(void); 63 64 void test_gpio_deprecated(void); 65 66 #endif /* __TEST_GPIO_H__ */ 67