Merge pull request #12477 from fkjagodzinski/hal-gpio-get_capabilities

HAL: Add a get_capabilities() function to GPIO API
pull/12496/head
Martin Kojtal 2020-02-24 07:47:39 +00:00 committed by GitHub
commit dc733d8883
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 233 additions and 220 deletions

View File

@ -1,5 +1,5 @@
/* mbed Microcontroller Library /* mbed Microcontroller Library
* Copyright (c) 2019 ARM Limited * Copyright (c) 2019-2020 ARM Limited
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
@ -33,6 +33,14 @@ extern "C" {
*/ */
void fpga_test_basic_input_output(PinName pin); 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. /* Test explicit input initialization.
* *
* Given a GPIO instance, * Given a GPIO instance,

View File

@ -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 * SPDX-License-Identifier: Apache-2.0
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
@ -56,23 +56,64 @@ void fpga_test_basic_input_output(PinName pin)
// Select GPIO0. // Select GPIO0.
tester.select_peripheral(MbedTester::PeripheralGPIO); tester.select_peripheral(MbedTester::PeripheralGPIO);
// Initialize GPIO pin with a generic init fun.
gpio_t gpio; gpio_t gpio;
// Test gpio_is_connected() returned value. // Initialize GPIO pin with a generic init fun.
gpio_init(&gpio, NC); gpio_init(&gpio, NC);
// Test gpio_is_connected() returned value.
TEST_ASSERT_EQUAL_INT(0, gpio_is_connected(&gpio)); TEST_ASSERT_EQUAL_INT(0, gpio_is_connected(&gpio));
gpio_free(&gpio); gpio_free(&gpio);
gpio_init(&gpio, pin); gpio_init(&gpio, pin);
TEST_ASSERT_NOT_EQUAL(0, gpio_is_connected(&gpio)); 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. // Test GPIO used as an input.
gpio_dir(&gpio, PIN_INPUT); gpio_dir(&gpio, PIN_INPUT);
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));
// Test GPIO used as an output.
tester.gpio_write(MbedTester::LogicalPinGPIO0, 0, false);
gpio_dir(&gpio, PIN_OUTPUT);
gpio_write(&gpio, 0);
TEST_ASSERT_EQUAL_INT(0, tester.gpio_read(MbedTester::LogicalPinGPIO0));
gpio_write(&gpio, 1);
TEST_ASSERT_EQUAL_INT(1, tester.gpio_read(MbedTester::LogicalPinGPIO0));
gpio_write(&gpio, 0);
TEST_ASSERT_EQUAL_INT(0, tester.gpio_read(MbedTester::LogicalPinGPIO0));
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. // Test input, pull-up mode.
if (gcap.pull_up) {
gpio_mode(&gpio, PullUp); gpio_mode(&gpio, PullUp);
tester.gpio_write(MbedTester::LogicalPinGPIO0, 0, false); tester.gpio_write(MbedTester::LogicalPinGPIO0, 0, false);
wait_us(HI_Z_READ_DELAY_US); wait_us(HI_Z_READ_DELAY_US);
@ -86,8 +127,12 @@ void fpga_test_basic_input_output(PinName pin)
tester.gpio_write(MbedTester::LogicalPinGPIO0, 0, false); tester.gpio_write(MbedTester::LogicalPinGPIO0, 0, false);
wait_us(HI_Z_READ_DELAY_US); wait_us(HI_Z_READ_DELAY_US);
TEST_ASSERT_EQUAL_INT(1, gpio_read(&gpio)); // hi-Z, pulled up TEST_ASSERT_EQUAL_INT(1, gpio_read(&gpio)); // hi-Z, pulled up
} else {
utest_printf("skipped PullUp,");
}
// Test input, pull-down mode. // Test input, pull-down mode.
if (gcap.pull_down) {
gpio_mode(&gpio, PullDown); gpio_mode(&gpio, PullDown);
tester.gpio_write(MbedTester::LogicalPinGPIO0, 0, false); tester.gpio_write(MbedTester::LogicalPinGPIO0, 0, false);
wait_us(HI_Z_READ_DELAY_US); wait_us(HI_Z_READ_DELAY_US);
@ -101,8 +146,12 @@ void fpga_test_basic_input_output(PinName pin)
tester.gpio_write(MbedTester::LogicalPinGPIO0, 0, false); tester.gpio_write(MbedTester::LogicalPinGPIO0, 0, false);
wait_us(HI_Z_READ_DELAY_US); wait_us(HI_Z_READ_DELAY_US);
TEST_ASSERT_EQUAL_INT(0, gpio_read(&gpio)); // hi-Z, pulled down TEST_ASSERT_EQUAL_INT(0, gpio_read(&gpio)); // hi-Z, pulled down
} else {
utest_printf("skipped PullDown,");
}
// Test input, pull-none mode. // Test input, pull-none mode.
if (gcap.pull_none) {
gpio_mode(&gpio, PullNone); gpio_mode(&gpio, PullNone);
tester.gpio_write(MbedTester::LogicalPinGPIO0, 1, true); tester.gpio_write(MbedTester::LogicalPinGPIO0, 1, true);
TEST_ASSERT_EQUAL_INT(1, gpio_read(&gpio)); TEST_ASSERT_EQUAL_INT(1, gpio_read(&gpio));
@ -110,17 +159,9 @@ void fpga_test_basic_input_output(PinName pin)
TEST_ASSERT_EQUAL_INT(0, gpio_read(&gpio)); TEST_ASSERT_EQUAL_INT(0, gpio_read(&gpio));
tester.gpio_write(MbedTester::LogicalPinGPIO0, 1, true); tester.gpio_write(MbedTester::LogicalPinGPIO0, 1, true);
TEST_ASSERT_EQUAL_INT(1, gpio_read(&gpio)); TEST_ASSERT_EQUAL_INT(1, gpio_read(&gpio));
#endif } else {
utest_printf("skipped PullNone,");
// Test GPIO used as an output. }
tester.gpio_write(MbedTester::LogicalPinGPIO0, 0, false);
gpio_dir(&gpio, PIN_OUTPUT);
gpio_write(&gpio, 0);
TEST_ASSERT_EQUAL_INT(0, tester.gpio_read(MbedTester::LogicalPinGPIO0));
gpio_write(&gpio, 1);
TEST_ASSERT_EQUAL_INT(1, tester.gpio_read(MbedTester::LogicalPinGPIO0));
gpio_write(&gpio, 0);
TEST_ASSERT_EQUAL_INT(0, tester.gpio_read(MbedTester::LogicalPinGPIO0));
gpio_free(&gpio); gpio_free(&gpio);
} }
@ -143,8 +184,13 @@ void fpga_test_explicit_input(PinName pin)
tester.select_peripheral(MbedTester::PeripheralGPIO); tester.select_peripheral(MbedTester::PeripheralGPIO);
gpio_t gpio; 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. // Initialize GPIO pin as an input, pull-up mode.
if (gcap.pull_up) {
memset(&gpio, 0, sizeof gpio); memset(&gpio, 0, sizeof gpio);
gpio_init_in_ex(&gpio, pin, PullUp); gpio_init_in_ex(&gpio, pin, PullUp);
TEST_ASSERT_NOT_EQUAL(0, gpio_is_connected(&gpio)); TEST_ASSERT_NOT_EQUAL(0, gpio_is_connected(&gpio));
@ -152,8 +198,12 @@ void fpga_test_explicit_input(PinName pin)
wait_us(HI_Z_READ_DELAY_US); wait_us(HI_Z_READ_DELAY_US);
TEST_ASSERT_EQUAL_INT(1, gpio_read(&gpio)); // hi-Z, pulled up TEST_ASSERT_EQUAL_INT(1, gpio_read(&gpio)); // hi-Z, pulled up
gpio_free(&gpio); gpio_free(&gpio);
} else {
utest_printf("skipped PullUp,");
}
// Initialize GPIO pin as an input, pull-down mode. // Initialize GPIO pin as an input, pull-down mode.
if (gcap.pull_down) {
memset(&gpio, 0, sizeof gpio); memset(&gpio, 0, sizeof gpio);
gpio_init_in_ex(&gpio, pin, PullDown); gpio_init_in_ex(&gpio, pin, PullDown);
TEST_ASSERT_NOT_EQUAL(0, gpio_is_connected(&gpio)); TEST_ASSERT_NOT_EQUAL(0, gpio_is_connected(&gpio));
@ -161,8 +211,12 @@ void fpga_test_explicit_input(PinName pin)
wait_us(HI_Z_READ_DELAY_US); wait_us(HI_Z_READ_DELAY_US);
TEST_ASSERT_EQUAL_INT(0, gpio_read(&gpio)); // hi-Z, pulled down TEST_ASSERT_EQUAL_INT(0, gpio_read(&gpio)); // hi-Z, pulled down
gpio_free(&gpio); gpio_free(&gpio);
} else {
utest_printf("skipped PullDown,");
}
// Initialize GPIO pin as an input, pull-up mode. // Initialize GPIO pin as an input, pull-up mode.
if (gcap.pull_up) {
memset(&gpio, 0, sizeof gpio); memset(&gpio, 0, sizeof gpio);
gpio_init_inout(&gpio, pin, PIN_INPUT, PullUp, 0); gpio_init_inout(&gpio, pin, PIN_INPUT, PullUp, 0);
TEST_ASSERT_NOT_EQUAL(0, gpio_is_connected(&gpio)); TEST_ASSERT_NOT_EQUAL(0, gpio_is_connected(&gpio));
@ -170,8 +224,12 @@ void fpga_test_explicit_input(PinName pin)
wait_us(HI_Z_READ_DELAY_US); wait_us(HI_Z_READ_DELAY_US);
TEST_ASSERT_EQUAL_INT(1, gpio_read(&gpio)); // hi-Z, pulled up TEST_ASSERT_EQUAL_INT(1, gpio_read(&gpio)); // hi-Z, pulled up
gpio_free(&gpio); gpio_free(&gpio);
} else {
utest_printf("skipped PullUp,");
}
// Initialize GPIO pin as an input, pull-down mode. // Initialize GPIO pin as an input, pull-down mode.
if (gcap.pull_down) {
memset(&gpio, 0, sizeof gpio); memset(&gpio, 0, sizeof gpio);
gpio_init_inout(&gpio, pin, PIN_INPUT, PullDown, 0); gpio_init_inout(&gpio, pin, PIN_INPUT, PullDown, 0);
TEST_ASSERT_NOT_EQUAL(0, gpio_is_connected(&gpio)); TEST_ASSERT_NOT_EQUAL(0, gpio_is_connected(&gpio));
@ -179,6 +237,9 @@ void fpga_test_explicit_input(PinName pin)
wait_us(HI_Z_READ_DELAY_US); wait_us(HI_Z_READ_DELAY_US);
TEST_ASSERT_EQUAL_INT(0, gpio_read(&gpio)); // hi-Z, pulled down TEST_ASSERT_EQUAL_INT(0, gpio_read(&gpio)); // hi-Z, pulled down
gpio_free(&gpio); gpio_free(&gpio);
} else {
utest_printf("skipped PullDown,");
}
} }
/* Test explicit output initialization. /* Test explicit output initialization.
@ -199,6 +260,10 @@ void fpga_test_explicit_output(PinName pin)
tester.select_peripheral(MbedTester::PeripheralGPIO); tester.select_peripheral(MbedTester::PeripheralGPIO);
gpio_t gpio; 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. // Initialize GPIO pin as an output, output value = 0.
memset(&gpio, 0, sizeof gpio); memset(&gpio, 0, sizeof gpio);
@ -222,6 +287,7 @@ void fpga_test_explicit_output(PinName pin)
gpio_free(&gpio); gpio_free(&gpio);
// Initialize GPIO pin as an output, output value = 1. // Initialize GPIO pin as an output, output value = 1.
if (gcap.pull_none) {
memset(&gpio, 0, sizeof gpio); memset(&gpio, 0, sizeof gpio);
gpio_init_inout(&gpio, pin, PIN_OUTPUT, PullNone, 1); gpio_init_inout(&gpio, pin, PIN_OUTPUT, PullNone, 1);
TEST_ASSERT_NOT_EQUAL(0, gpio_is_connected(&gpio)); TEST_ASSERT_NOT_EQUAL(0, gpio_is_connected(&gpio));
@ -234,16 +300,15 @@ void fpga_test_explicit_output(PinName pin)
TEST_ASSERT_NOT_EQUAL(0, gpio_is_connected(&gpio)); TEST_ASSERT_NOT_EQUAL(0, gpio_is_connected(&gpio));
TEST_ASSERT_EQUAL_INT(0, tester.gpio_read(MbedTester::LogicalPinGPIO0)); TEST_ASSERT_EQUAL_INT(0, tester.gpio_read(MbedTester::LogicalPinGPIO0));
gpio_free(&gpio); gpio_free(&gpio);
} else {
utest_printf("skipped gpio_init_inout,");
}
} }
Case cases[] = { Case cases[] = {
Case("generic init, input & output", all_ports<GPIOPort, DefaultFormFactor, fpga_test_basic_input_output>), Case("basic input & output", all_ports<GPIOPort, DefaultFormFactor, fpga_test_basic_input_output>),
// Some targets don't support input pull mode. Case("input pull modes", all_ports<GPIOPort, DefaultFormFactor, fpga_test_input_pull_modes>),
#if !defined(TARGET_NANO100) && \
!defined(TARGET_NUC472) && \
!defined(TARGET_M451)
Case("explicit init, input", all_ports<GPIOPort, DefaultFormFactor, fpga_test_explicit_input>), Case("explicit init, input", all_ports<GPIOPort, DefaultFormFactor, fpga_test_explicit_input>),
#endif
Case("explicit init, output", all_ports<GPIOPort, DefaultFormFactor, fpga_test_explicit_output>), Case("explicit init, output", all_ports<GPIOPort, DefaultFormFactor, fpga_test_explicit_output>),
}; };

View File

@ -2,7 +2,7 @@
/** \addtogroup hal */ /** \addtogroup hal */
/** @{*/ /** @{*/
/* mbed Microcontroller Library /* mbed Microcontroller Library
* Copyright (c) 2006-2013 ARM Limited * Copyright (c) 2006-2020 ARM Limited
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * 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_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 * * ::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 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 * # Undefined behavior
* * Calling any ::gpio_mode, ::gpio_dir, ::gpio_write or ::gpio_read on a gpio_t object that was initialized * * 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 /** Set the given pin as GPIO
* *
* @param pin The pin to be set 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); 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 /** Get the pins that support all GPIO tests
* *
* Return a PinMap array of pins that support GPIO. The * Return a PinMap array of pins that support GPIO. The

View File

@ -1,5 +1,5 @@
/* mbed Microcontroller Library /* mbed Microcontroller Library
* Copyright (c) 2006-2013 ARM Limited * Copyright (c) 2006-2020 ARM Limited
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * 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 #ifdef TARGET_FF_ARDUINO
typedef enum { typedef enum {

View File

@ -1,5 +1,5 @@
/* mbed Microcontroller Library /* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -22,10 +22,6 @@
extern "C" { extern "C" {
#endif #endif
typedef enum {
GPIO_X = 0, // dummy peripheral used instead of GPIO_A..GPIO_E
} GPIOName;
typedef enum { typedef enum {
OSC32KCLK = 0, OSC32KCLK = 0,
} RTCName; } RTCName;

View File

@ -1,5 +1,5 @@
/* mbed Microcontroller Library /* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -19,118 +19,6 @@
#include <mstd_cstddef> #include <mstd_cstddef>
/************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***************/ /************RTC***************/
MSTD_CONSTEXPR_OBJ_11 PinMap PinMap_RTC[] = { MSTD_CONSTEXPR_OBJ_11 PinMap PinMap_RTC[] = {
{NC, OSC32KCLK, 0}, {NC, OSC32KCLK, 0},

View File

@ -1,5 +1,5 @@
/* mbed Microcontroller Library /* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -16,8 +16,20 @@
#include "PeripheralPins.h" #include "PeripheralPins.h"
#include "PeripheralPinMaps.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;
}
} }

View File

@ -1,5 +1,5 @@
/* mbed Microcontroller Library /* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -20,9 +20,6 @@
#include "pinmap.h" #include "pinmap.h"
#include "PeripheralNames.h" #include "PeripheralNames.h"
/************GPIO***************/
extern const PinMap PinMap_GPIO[];
/************RTC***************/ /************RTC***************/
extern const PinMap PinMap_RTC[]; extern const PinMap PinMap_RTC[];

View File

@ -1,5 +1,5 @@
/* mbed Microcontroller Library /* mbed Microcontroller Library
* Copyright (c) 2015-2016 Nuvoton * Copyright (c) 2015-2020 Nuvoton
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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); 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;
}

View File

@ -1,5 +1,5 @@
/* mbed Microcontroller Library /* mbed Microcontroller Library
* Copyright (c) 2015-2017 Nuvoton * Copyright (c) 2015-2020 Nuvoton
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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); 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;
}

View File

@ -1,5 +1,5 @@
/* mbed Microcontroller Library /* mbed Microcontroller Library
* Copyright (c) 2015-2016 Nuvoton * Copyright (c) 2015-2020 Nuvoton
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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); 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;
}