diff --git a/TESTS/mbed_hal_fpga_ci_test_shield/gpio/gpio_fpga_test.h b/TESTS/mbed_hal_fpga_ci_test_shield/gpio/gpio_fpga_test.h index efca1fcf0e1..34f817b73c7 100644 --- a/TESTS/mbed_hal_fpga_ci_test_shield/gpio/gpio_fpga_test.h +++ b/TESTS/mbed_hal_fpga_ci_test_shield/gpio/gpio_fpga_test.h @@ -1,5 +1,5 @@ /* mbed Microcontroller Library - * Copyright (c) 2019 ARM Limited + * Copyright (c) 2019-2020 ARM Limited * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -33,6 +33,14 @@ extern "C" { */ void fpga_test_basic_input_output(PinName pin); +/* Test input pull modes. + * + * Given a GPIO instance configured with an input pull mode, + * when basic input operations are performed, + * then all operations succeed. + */ +void fpga_test_input_pull_modes(PinName pin); + /* Test explicit input initialization. * * Given a GPIO instance, diff --git a/TESTS/mbed_hal_fpga_ci_test_shield/gpio/main.cpp b/TESTS/mbed_hal_fpga_ci_test_shield/gpio/main.cpp index 76d24525964..aaec0836840 100644 --- a/TESTS/mbed_hal_fpga_ci_test_shield/gpio/main.cpp +++ b/TESTS/mbed_hal_fpga_ci_test_shield/gpio/main.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, Arm Limited and affiliates. + * Copyright (c) 2019-2020, Arm Limited and affiliates. * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -56,61 +56,23 @@ void fpga_test_basic_input_output(PinName pin) // Select GPIO0. tester.select_peripheral(MbedTester::PeripheralGPIO); - // Initialize GPIO pin with a generic init fun. gpio_t gpio; - // Test gpio_is_connected() returned value. + // Initialize GPIO pin with a generic init fun. gpio_init(&gpio, NC); + // Test gpio_is_connected() returned value. TEST_ASSERT_EQUAL_INT(0, gpio_is_connected(&gpio)); gpio_free(&gpio); gpio_init(&gpio, pin); TEST_ASSERT_NOT_EQUAL(0, gpio_is_connected(&gpio)); - // Some targets don't support input pull mode. -#if !defined(TARGET_NANO100) && \ - !defined(TARGET_NUC472) && \ - !defined(TARGET_M451) // Test GPIO used as an input. gpio_dir(&gpio, PIN_INPUT); - - // Test input, pull-up mode. - gpio_mode(&gpio, PullUp); - tester.gpio_write(MbedTester::LogicalPinGPIO0, 0, false); - wait_us(HI_Z_READ_DELAY_US); - TEST_ASSERT_EQUAL_INT(1, gpio_read(&gpio)); // hi-Z, pulled up - tester.gpio_write(MbedTester::LogicalPinGPIO0, 0, true); - TEST_ASSERT_EQUAL_INT(0, gpio_read(&gpio)); - tester.gpio_write(MbedTester::LogicalPinGPIO0, 1, true); - TEST_ASSERT_EQUAL_INT(1, gpio_read(&gpio)); - tester.gpio_write(MbedTester::LogicalPinGPIO0, 0, true); - TEST_ASSERT_EQUAL_INT(0, gpio_read(&gpio)); - tester.gpio_write(MbedTester::LogicalPinGPIO0, 0, false); - wait_us(HI_Z_READ_DELAY_US); - TEST_ASSERT_EQUAL_INT(1, gpio_read(&gpio)); // hi-Z, pulled up - - // Test input, pull-down mode. - gpio_mode(&gpio, PullDown); - tester.gpio_write(MbedTester::LogicalPinGPIO0, 0, false); - wait_us(HI_Z_READ_DELAY_US); - TEST_ASSERT_EQUAL_INT(0, gpio_read(&gpio)); // hi-Z, pulled down - tester.gpio_write(MbedTester::LogicalPinGPIO0, 1, true); - TEST_ASSERT_EQUAL_INT(1, gpio_read(&gpio)); - tester.gpio_write(MbedTester::LogicalPinGPIO0, 0, true); - TEST_ASSERT_EQUAL_INT(0, gpio_read(&gpio)); - tester.gpio_write(MbedTester::LogicalPinGPIO0, 1, true); - TEST_ASSERT_EQUAL_INT(1, gpio_read(&gpio)); - tester.gpio_write(MbedTester::LogicalPinGPIO0, 0, false); - wait_us(HI_Z_READ_DELAY_US); - TEST_ASSERT_EQUAL_INT(0, gpio_read(&gpio)); // hi-Z, pulled down - - // Test input, pull-none mode. - gpio_mode(&gpio, PullNone); tester.gpio_write(MbedTester::LogicalPinGPIO0, 1, true); TEST_ASSERT_EQUAL_INT(1, gpio_read(&gpio)); tester.gpio_write(MbedTester::LogicalPinGPIO0, 0, true); TEST_ASSERT_EQUAL_INT(0, gpio_read(&gpio)); tester.gpio_write(MbedTester::LogicalPinGPIO0, 1, true); TEST_ASSERT_EQUAL_INT(1, gpio_read(&gpio)); -#endif // Test GPIO used as an output. tester.gpio_write(MbedTester::LogicalPinGPIO0, 0, false); @@ -125,6 +87,85 @@ void fpga_test_basic_input_output(PinName pin) gpio_free(&gpio); } +/* Test input pull modes. + * + * Given a GPIO instance configured with an input pull mode, + * when basic input operations are performed, + * then all operations succeed. + */ +void fpga_test_input_pull_modes(PinName pin) +{ + // Reset everything and set all tester pins to hi-Z. + tester.reset(); + + // Map pins for test. + tester.pin_map_set(pin, MbedTester::LogicalPinGPIO0); + + // Select GPIO0. + tester.select_peripheral(MbedTester::PeripheralGPIO); + + gpio_t gpio; + // Initialize GPIO pin with a generic init fun. + gpio_init(&gpio, pin); + TEST_ASSERT_NOT_EQUAL(0, gpio_is_connected(&gpio)); + gpio_dir(&gpio, PIN_INPUT); + gpio_capabilities_t gcap = {}; + gpio_get_capabilities(&gpio, &gcap); + + // Test input, pull-up mode. + if (gcap.pull_up) { + gpio_mode(&gpio, PullUp); + tester.gpio_write(MbedTester::LogicalPinGPIO0, 0, false); + wait_us(HI_Z_READ_DELAY_US); + TEST_ASSERT_EQUAL_INT(1, gpio_read(&gpio)); // hi-Z, pulled up + tester.gpio_write(MbedTester::LogicalPinGPIO0, 0, true); + TEST_ASSERT_EQUAL_INT(0, gpio_read(&gpio)); + tester.gpio_write(MbedTester::LogicalPinGPIO0, 1, true); + TEST_ASSERT_EQUAL_INT(1, gpio_read(&gpio)); + tester.gpio_write(MbedTester::LogicalPinGPIO0, 0, true); + TEST_ASSERT_EQUAL_INT(0, gpio_read(&gpio)); + tester.gpio_write(MbedTester::LogicalPinGPIO0, 0, false); + wait_us(HI_Z_READ_DELAY_US); + TEST_ASSERT_EQUAL_INT(1, gpio_read(&gpio)); // hi-Z, pulled up + } else { + utest_printf("skipped PullUp,"); + } + + // Test input, pull-down mode. + if (gcap.pull_down) { + gpio_mode(&gpio, PullDown); + tester.gpio_write(MbedTester::LogicalPinGPIO0, 0, false); + wait_us(HI_Z_READ_DELAY_US); + TEST_ASSERT_EQUAL_INT(0, gpio_read(&gpio)); // hi-Z, pulled down + tester.gpio_write(MbedTester::LogicalPinGPIO0, 1, true); + TEST_ASSERT_EQUAL_INT(1, gpio_read(&gpio)); + tester.gpio_write(MbedTester::LogicalPinGPIO0, 0, true); + TEST_ASSERT_EQUAL_INT(0, gpio_read(&gpio)); + tester.gpio_write(MbedTester::LogicalPinGPIO0, 1, true); + TEST_ASSERT_EQUAL_INT(1, gpio_read(&gpio)); + tester.gpio_write(MbedTester::LogicalPinGPIO0, 0, false); + wait_us(HI_Z_READ_DELAY_US); + TEST_ASSERT_EQUAL_INT(0, gpio_read(&gpio)); // hi-Z, pulled down + } else { + utest_printf("skipped PullDown,"); + } + + // Test input, pull-none mode. + if (gcap.pull_none) { + gpio_mode(&gpio, PullNone); + tester.gpio_write(MbedTester::LogicalPinGPIO0, 1, true); + TEST_ASSERT_EQUAL_INT(1, gpio_read(&gpio)); + tester.gpio_write(MbedTester::LogicalPinGPIO0, 0, true); + TEST_ASSERT_EQUAL_INT(0, gpio_read(&gpio)); + tester.gpio_write(MbedTester::LogicalPinGPIO0, 1, true); + TEST_ASSERT_EQUAL_INT(1, gpio_read(&gpio)); + } else { + utest_printf("skipped PullNone,"); + } + + gpio_free(&gpio); +} + /* Test explicit input initialization. * * Given a GPIO instance, @@ -143,42 +184,62 @@ void fpga_test_explicit_input(PinName pin) tester.select_peripheral(MbedTester::PeripheralGPIO); gpio_t gpio; + gpio_init(&gpio, pin); + gpio_capabilities_t gcap = {}; + gpio_get_capabilities(&gpio, &gcap); + gpio_free(&gpio); // Initialize GPIO pin as an input, pull-up mode. - memset(&gpio, 0, sizeof gpio); - gpio_init_in_ex(&gpio, pin, PullUp); - TEST_ASSERT_NOT_EQUAL(0, gpio_is_connected(&gpio)); - tester.gpio_write(MbedTester::LogicalPinGPIO0, 0, false); - wait_us(HI_Z_READ_DELAY_US); - TEST_ASSERT_EQUAL_INT(1, gpio_read(&gpio)); // hi-Z, pulled up - gpio_free(&gpio); + if (gcap.pull_up) { + memset(&gpio, 0, sizeof gpio); + gpio_init_in_ex(&gpio, pin, PullUp); + TEST_ASSERT_NOT_EQUAL(0, gpio_is_connected(&gpio)); + tester.gpio_write(MbedTester::LogicalPinGPIO0, 0, false); + wait_us(HI_Z_READ_DELAY_US); + TEST_ASSERT_EQUAL_INT(1, gpio_read(&gpio)); // hi-Z, pulled up + gpio_free(&gpio); + } else { + utest_printf("skipped PullUp,"); + } // Initialize GPIO pin as an input, pull-down mode. - memset(&gpio, 0, sizeof gpio); - gpio_init_in_ex(&gpio, pin, PullDown); - TEST_ASSERT_NOT_EQUAL(0, gpio_is_connected(&gpio)); - tester.gpio_write(MbedTester::LogicalPinGPIO0, 0, false); - wait_us(HI_Z_READ_DELAY_US); - TEST_ASSERT_EQUAL_INT(0, gpio_read(&gpio)); // hi-Z, pulled down - gpio_free(&gpio); + if (gcap.pull_down) { + memset(&gpio, 0, sizeof gpio); + gpio_init_in_ex(&gpio, pin, PullDown); + TEST_ASSERT_NOT_EQUAL(0, gpio_is_connected(&gpio)); + tester.gpio_write(MbedTester::LogicalPinGPIO0, 0, false); + wait_us(HI_Z_READ_DELAY_US); + TEST_ASSERT_EQUAL_INT(0, gpio_read(&gpio)); // hi-Z, pulled down + gpio_free(&gpio); + } else { + utest_printf("skipped PullDown,"); + } // Initialize GPIO pin as an input, pull-up mode. - memset(&gpio, 0, sizeof gpio); - gpio_init_inout(&gpio, pin, PIN_INPUT, PullUp, 0); - TEST_ASSERT_NOT_EQUAL(0, gpio_is_connected(&gpio)); - tester.gpio_write(MbedTester::LogicalPinGPIO0, 0, false); - wait_us(HI_Z_READ_DELAY_US); - TEST_ASSERT_EQUAL_INT(1, gpio_read(&gpio)); // hi-Z, pulled up - gpio_free(&gpio); + if (gcap.pull_up) { + memset(&gpio, 0, sizeof gpio); + gpio_init_inout(&gpio, pin, PIN_INPUT, PullUp, 0); + TEST_ASSERT_NOT_EQUAL(0, gpio_is_connected(&gpio)); + tester.gpio_write(MbedTester::LogicalPinGPIO0, 0, false); + wait_us(HI_Z_READ_DELAY_US); + TEST_ASSERT_EQUAL_INT(1, gpio_read(&gpio)); // hi-Z, pulled up + gpio_free(&gpio); + } else { + utest_printf("skipped PullUp,"); + } // Initialize GPIO pin as an input, pull-down mode. - memset(&gpio, 0, sizeof gpio); - gpio_init_inout(&gpio, pin, PIN_INPUT, PullDown, 0); - TEST_ASSERT_NOT_EQUAL(0, gpio_is_connected(&gpio)); - tester.gpio_write(MbedTester::LogicalPinGPIO0, 0, false); - wait_us(HI_Z_READ_DELAY_US); - TEST_ASSERT_EQUAL_INT(0, gpio_read(&gpio)); // hi-Z, pulled down - gpio_free(&gpio); + if (gcap.pull_down) { + memset(&gpio, 0, sizeof gpio); + gpio_init_inout(&gpio, pin, PIN_INPUT, PullDown, 0); + TEST_ASSERT_NOT_EQUAL(0, gpio_is_connected(&gpio)); + tester.gpio_write(MbedTester::LogicalPinGPIO0, 0, false); + wait_us(HI_Z_READ_DELAY_US); + TEST_ASSERT_EQUAL_INT(0, gpio_read(&gpio)); // hi-Z, pulled down + gpio_free(&gpio); + } else { + utest_printf("skipped PullDown,"); + } } /* Test explicit output initialization. @@ -199,6 +260,10 @@ void fpga_test_explicit_output(PinName pin) tester.select_peripheral(MbedTester::PeripheralGPIO); gpio_t gpio; + gpio_init(&gpio, pin); + gpio_capabilities_t gcap = {}; + gpio_get_capabilities(&gpio, &gcap); + gpio_free(&gpio); // Initialize GPIO pin as an output, output value = 0. memset(&gpio, 0, sizeof gpio); @@ -222,28 +287,28 @@ void fpga_test_explicit_output(PinName pin) gpio_free(&gpio); // Initialize GPIO pin as an output, output value = 1. - memset(&gpio, 0, sizeof gpio); - gpio_init_inout(&gpio, pin, PIN_OUTPUT, PullNone, 1); - TEST_ASSERT_NOT_EQUAL(0, gpio_is_connected(&gpio)); - TEST_ASSERT_EQUAL_INT(1, tester.gpio_read(MbedTester::LogicalPinGPIO0)); - gpio_free(&gpio); - - // Initialize GPIO pin as an output, output value = 0. - memset(&gpio, 0, sizeof gpio); - gpio_init_inout(&gpio, pin, PIN_OUTPUT, PullNone, 0); - TEST_ASSERT_NOT_EQUAL(0, gpio_is_connected(&gpio)); - TEST_ASSERT_EQUAL_INT(0, tester.gpio_read(MbedTester::LogicalPinGPIO0)); - gpio_free(&gpio); + if (gcap.pull_none) { + memset(&gpio, 0, sizeof gpio); + gpio_init_inout(&gpio, pin, PIN_OUTPUT, PullNone, 1); + TEST_ASSERT_NOT_EQUAL(0, gpio_is_connected(&gpio)); + TEST_ASSERT_EQUAL_INT(1, tester.gpio_read(MbedTester::LogicalPinGPIO0)); + gpio_free(&gpio); + + // Initialize GPIO pin as an output, output value = 0. + memset(&gpio, 0, sizeof gpio); + gpio_init_inout(&gpio, pin, PIN_OUTPUT, PullNone, 0); + TEST_ASSERT_NOT_EQUAL(0, gpio_is_connected(&gpio)); + TEST_ASSERT_EQUAL_INT(0, tester.gpio_read(MbedTester::LogicalPinGPIO0)); + gpio_free(&gpio); + } else { + utest_printf("skipped gpio_init_inout,"); + } } Case cases[] = { - Case("generic init, input & output", all_ports), - // Some targets don't support input pull mode. -#if !defined(TARGET_NANO100) && \ - !defined(TARGET_NUC472) && \ - !defined(TARGET_M451) + Case("basic input & output", all_ports), + Case("input pull modes", all_ports), Case("explicit init, input", all_ports), -#endif Case("explicit init, output", all_ports), }; diff --git a/hal/gpio_api.h b/hal/gpio_api.h index cafba8d1e0b..c4f4d171cbf 100644 --- a/hal/gpio_api.h +++ b/hal/gpio_api.h @@ -2,7 +2,7 @@ /** \addtogroup hal */ /** @{*/ /* mbed Microcontroller Library - * Copyright (c) 2006-2013 ARM Limited + * Copyright (c) 2006-2020 ARM Limited * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -46,6 +46,8 @@ extern "C" { * * ::gpio_init_out_ex inits the pin as an output and sets the output value * * ::gpio_init_inout inits the pin to be input/output and set pin mode and value * * The GPIO operations ::gpio_write, ::gpio_read take less than 20us to complete + * * The function ::gpio_get_capabilities fills the given + * `gpio_capabilities_t` instance according to pin capabilities. * * # Undefined behavior * * Calling any ::gpio_mode, ::gpio_dir, ::gpio_write or ::gpio_read on a gpio_t object that was initialized @@ -65,6 +67,14 @@ extern "C" { * */ +/** GPIO capabilities for a given pin + */ +typedef struct { + uint8_t pull_none : 1; + uint8_t pull_down : 1; + uint8_t pull_up : 1; +} gpio_capabilities_t; + /** Set the given pin as GPIO * * @param pin The pin to be set as GPIO @@ -164,6 +174,10 @@ void gpio_init_out_ex(gpio_t *gpio, PinName pin, int value); */ void gpio_init_inout(gpio_t *gpio, PinName pin, PinDirection direction, PinMode mode, int value); +/** Fill the given gpio_capabilities_t instance according to pin capabilities. + */ +void gpio_get_capabilities(gpio_t *gpio, gpio_capabilities_t *cap); + /** Get the pins that support all GPIO tests * * Return a PinMap array of pins that support GPIO. The diff --git a/hal/mbed_gpio.c b/hal/mbed_gpio.c index 0579a02f2e0..7659cff9b9a 100644 --- a/hal/mbed_gpio.c +++ b/hal/mbed_gpio.c @@ -1,5 +1,5 @@ /* mbed Microcontroller Library - * Copyright (c) 2006-2013 ARM Limited + * Copyright (c) 2006-2020 ARM Limited * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -68,6 +68,15 @@ void gpio_init_inout(gpio_t *gpio, PinName pin, PinDirection direction, PinMode } } +// To be re-implemented in the target layer if required. +MBED_WEAK void gpio_get_capabilities(gpio_t *gpio, gpio_capabilities_t *cap) +{ + (void)gpio; // By default, every pin supports all basic input pull modes. + cap->pull_none = 1; + cap->pull_down = 1; + cap->pull_up = 1; +} + #ifdef TARGET_FF_ARDUINO typedef enum { diff --git a/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/TARGET_FRDM/PeripheralNames.h b/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/TARGET_FRDM/PeripheralNames.h index c5005d473ce..16134f00039 100644 --- a/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/TARGET_FRDM/PeripheralNames.h +++ b/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/TARGET_FRDM/PeripheralNames.h @@ -1,5 +1,5 @@ /* mbed Microcontroller Library - * Copyright (c) 2006-2013 ARM Limited + * Copyright (c) 2006-2020 ARM Limited * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,10 +22,6 @@ extern "C" { #endif -typedef enum { - GPIO_X = 0, // dummy peripheral used instead of GPIO_A..GPIO_E -} GPIOName; - typedef enum { OSC32KCLK = 0, } RTCName; diff --git a/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/TARGET_FRDM/PeripheralPinMaps.h b/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/TARGET_FRDM/PeripheralPinMaps.h index a3d15d56731..c94874830a0 100644 --- a/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/TARGET_FRDM/PeripheralPinMaps.h +++ b/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/TARGET_FRDM/PeripheralPinMaps.h @@ -1,5 +1,5 @@ /* mbed Microcontroller Library - * Copyright (c) 2006-2013 ARM Limited + * Copyright (c) 2006-2020 ARM Limited * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,118 +19,6 @@ #include -/************GPIO***************/ -MSTD_CONSTEXPR_OBJ_11 PinMap PinMap_GPIO[] = { - {PTA0, GPIO_X, 1}, - {PTA1, GPIO_X, 1}, - {PTA2, GPIO_X, 1}, - {PTA3, GPIO_X, 1}, - {PTA4, GPIO_X, 1}, - {PTA5, GPIO_X, 1}, - {PTA6, GPIO_X, 1}, - {PTA7, GPIO_X, 1}, - {PTA8, GPIO_X, 1}, - {PTA9, GPIO_X, 1}, - {PTA10, GPIO_X, 1}, - {PTA11, GPIO_X, 1}, - {PTA12, GPIO_X, 1}, - {PTA13, GPIO_X, 1}, - {PTA14, GPIO_X, 1}, - {PTA15, GPIO_X, 1}, - {PTA16, GPIO_X, 1}, - {PTA17, GPIO_X, 1}, - {PTA18, GPIO_X, 1}, - {PTA19, GPIO_X, 1}, - {PTA24, GPIO_X, 1}, - {PTA25, GPIO_X, 1}, - {PTA26, GPIO_X, 1}, - {PTA27, GPIO_X, 1}, - {PTA28, GPIO_X, 1}, - {PTA29, GPIO_X, 1}, - - {PTB0, GPIO_X, 1}, - {PTB1, GPIO_X, 1}, - {PTB2, GPIO_X, 1}, - {PTB3, GPIO_X, 1}, - {PTB4, GPIO_X, 1}, - {PTB5, GPIO_X, 1}, - {PTB6, GPIO_X, 1}, - {PTB7, GPIO_X, 1}, - {PTB8, GPIO_X, 1}, - {PTB9, GPIO_X, 1}, - {PTB10, GPIO_X, 1}, - {PTB11, GPIO_X, 1}, - {PTB12, GPIO_X, 1}, - {PTB13, GPIO_X, 1}, - {PTB16, GPIO_X, 1}, - {PTB17, GPIO_X, 1}, - {PTB18, GPIO_X, 1}, - {PTB19, GPIO_X, 1}, - {PTB20, GPIO_X, 1}, - {PTB21, GPIO_X, 1}, - {PTB22, GPIO_X, 1}, - {PTB23, GPIO_X, 1}, - - {PTC0, GPIO_X, 1}, - {PTC1, GPIO_X, 1}, - {PTC2, GPIO_X, 1}, - {PTC3, GPIO_X, 1}, - {PTC4, GPIO_X, 1}, - {PTC5, GPIO_X, 1}, - {PTC6, GPIO_X, 1}, - {PTC7, GPIO_X, 1}, - {PTC8, GPIO_X, 1}, - {PTC9, GPIO_X, 1}, - {PTC10, GPIO_X, 1}, - {PTC11, GPIO_X, 1}, - {PTC12, GPIO_X, 1}, - {PTC13, GPIO_X, 1}, - {PTC14, GPIO_X, 1}, - {PTC15, GPIO_X, 1}, - {PTC16, GPIO_X, 1}, - {PTC17, GPIO_X, 1}, - {PTC18, GPIO_X, 1}, - {PTC19, GPIO_X, 1}, - - {PTD0, GPIO_X, 1}, - {PTD1, GPIO_X, 1}, - {PTD2, GPIO_X, 1}, - {PTD3, GPIO_X, 1}, - {PTD4, GPIO_X, 1}, - {PTD5, GPIO_X, 1}, - {PTD6, GPIO_X, 1}, - {PTD7, GPIO_X, 1}, - {PTD8, GPIO_X, 1}, - {PTD9, GPIO_X, 1}, - {PTD10, GPIO_X, 1}, - {PTD11, GPIO_X, 1}, - {PTD12, GPIO_X, 1}, - {PTD13, GPIO_X, 1}, - {PTD14, GPIO_X, 1}, - {PTD15, GPIO_X, 1}, - - {PTE0, GPIO_X, 1}, - {PTE1, GPIO_X, 1}, - {PTE2, GPIO_X, 1}, - {PTE3, GPIO_X, 1}, - {PTE4, GPIO_X, 1}, - {PTE5, GPIO_X, 1}, - {PTE6, GPIO_X, 1}, - {PTE7, GPIO_X, 1}, - {PTE8, GPIO_X, 1}, - {PTE9, GPIO_X, 1}, - {PTE10, GPIO_X, 1}, - {PTE11, GPIO_X, 1}, - {PTE12, GPIO_X, 1}, - // {PTE24, GPIO_X, 1}, // fixed pull-up (for I2C) - // {PTE25, GPIO_X, 1}, // fixed pull-up (for I2C) - {PTE26, GPIO_X, 1}, - {PTE27, GPIO_X, 1}, - {PTE28, GPIO_X, 1}, - - {NC, NC, 0} -}; - /************RTC***************/ MSTD_CONSTEXPR_OBJ_11 PinMap PinMap_RTC[] = { {NC, OSC32KCLK, 0}, diff --git a/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/TARGET_FRDM/PeripheralPins.c b/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/TARGET_FRDM/PeripheralPins.c index a41c0708f46..a20aa080baa 100644 --- a/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/TARGET_FRDM/PeripheralPins.c +++ b/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/TARGET_FRDM/PeripheralPins.c @@ -1,5 +1,5 @@ /* mbed Microcontroller Library - * Copyright (c) 2006-2013 ARM Limited + * Copyright (c) 2006-2020 ARM Limited * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,8 +16,20 @@ #include "PeripheralPins.h" #include "PeripheralPinMaps.h" +#include "mbed_assert.h" +#include "hal/gpio_api.h" -const PinMap *gpio_pinmap() +void gpio_get_capabilities(gpio_t *obj, gpio_capabilities_t *cap) { - return PinMap_GPIO; + MBED_ASSERT(obj->pin != (PinName)NC); + // fixed pull-ups (for I2C) + if (obj->pin == PTE24 || obj->pin == PTE25) { + cap->pull_none = 0; + cap->pull_down = 0; + cap->pull_up = 0; + } else { + cap->pull_none = 1; + cap->pull_down = 1; + cap->pull_up = 1; + } } diff --git a/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/api/PeripheralPins.h b/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/api/PeripheralPins.h index 0720a43d126..0e8854ffa31 100644 --- a/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/api/PeripheralPins.h +++ b/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/api/PeripheralPins.h @@ -1,5 +1,5 @@ /* mbed Microcontroller Library - * Copyright (c) 2006-2013 ARM Limited + * Copyright (c) 2006-2020 ARM Limited * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,9 +20,6 @@ #include "pinmap.h" #include "PeripheralNames.h" -/************GPIO***************/ -extern const PinMap PinMap_GPIO[]; - /************RTC***************/ extern const PinMap PinMap_RTC[]; diff --git a/targets/TARGET_NUVOTON/TARGET_M451/gpio_api.c b/targets/TARGET_NUVOTON/TARGET_M451/gpio_api.c index f3ce3fe477a..e0c59e75b46 100644 --- a/targets/TARGET_NUVOTON/TARGET_M451/gpio_api.c +++ b/targets/TARGET_NUVOTON/TARGET_M451/gpio_api.c @@ -1,5 +1,5 @@ /* mbed Microcontroller Library - * Copyright (c) 2015-2016 Nuvoton + * Copyright (c) 2015-2020 Nuvoton * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -140,3 +140,11 @@ void gpio_dir(gpio_t *obj, PinDirection direction) pin_mode(obj->pin, obj->mode); } + +void gpio_get_capabilities(gpio_t *obj, gpio_capabilities_t *cap) +{ + // Pull modes not supported. + cap->pull_none = 0; + cap->pull_down = 0; + cap->pull_up = 0; +} diff --git a/targets/TARGET_NUVOTON/TARGET_NANO100/gpio_api.c b/targets/TARGET_NUVOTON/TARGET_NANO100/gpio_api.c index 1398e8198f2..b83a74da320 100644 --- a/targets/TARGET_NUVOTON/TARGET_NANO100/gpio_api.c +++ b/targets/TARGET_NUVOTON/TARGET_NANO100/gpio_api.c @@ -1,5 +1,5 @@ /* mbed Microcontroller Library - * Copyright (c) 2015-2017 Nuvoton + * Copyright (c) 2015-2020 Nuvoton * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -121,3 +121,11 @@ void gpio_dir(gpio_t *obj, PinDirection direction) pin_mode(obj->pin, obj->mode); } + +void gpio_get_capabilities(gpio_t *obj, gpio_capabilities_t *cap) +{ + // Pull modes not supported. + cap->pull_none = 0; + cap->pull_down = 0; + cap->pull_up = 0; +} diff --git a/targets/TARGET_NUVOTON/TARGET_NUC472/gpio_api.c b/targets/TARGET_NUVOTON/TARGET_NUC472/gpio_api.c index f3ce3fe477a..e0c59e75b46 100644 --- a/targets/TARGET_NUVOTON/TARGET_NUC472/gpio_api.c +++ b/targets/TARGET_NUVOTON/TARGET_NUC472/gpio_api.c @@ -1,5 +1,5 @@ /* mbed Microcontroller Library - * Copyright (c) 2015-2016 Nuvoton + * Copyright (c) 2015-2020 Nuvoton * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -140,3 +140,11 @@ void gpio_dir(gpio_t *obj, PinDirection direction) pin_mode(obj->pin, obj->mode); } + +void gpio_get_capabilities(gpio_t *obj, gpio_capabilities_t *cap) +{ + // Pull modes not supported. + cap->pull_none = 0; + cap->pull_down = 0; + cap->pull_up = 0; +}