mirror of https://github.com/ARMmbed/mbed-os.git
[STD-PIN] BUTTON and LED define
hal/tests/TESTS/mbed_hal/gpio/main.cpp is replaced by hal/tests/TESTS/pin_names/generic/main.cpp nowpull/14381/head
parent
23e3bb301d
commit
a4350f72bd
|
@ -42,13 +42,13 @@ To achieve meaningful portability of application code across various Mbed Enable
|
|||
Only add LEDs that are available on the board. This is an example on how to define LEDs in PinNames.h:
|
||||
|
||||
// Px_xx relates to the processor pin connected to the LED
|
||||
#define LED1 = Px_xx // LED1
|
||||
#define LED2 = Px_xx // LED2
|
||||
#define LED3 = Px_xx // LED3
|
||||
#define LED4 = Px_xx // LED4
|
||||
#define LED1 Px_xx // LED1
|
||||
#define LED2 Px_xx // LED2
|
||||
#define LED3 Px_xx // LED3
|
||||
#define LED4 Px_xx // LED4
|
||||
.
|
||||
.
|
||||
#define LEDN = Px_xx // LEDN
|
||||
#define LEDN Px_xx // LEDN
|
||||
|
||||
Note this document is proposing changing LEDs from `enums` to `define`, which causes a minor change in the compile preprocessor. From application point of view, there are no implications.
|
||||
|
||||
|
@ -56,14 +56,14 @@ Note this document is proposing changing LEDs from `enums` to `define`, which ca
|
|||
|
||||
The detection of available LEDs at application level can be done as follow:
|
||||
|
||||
#ifdef(LED1)
|
||||
#ifdef LED1
|
||||
DigitalOut myLED(LED1);
|
||||
myLED = 1;
|
||||
#endif
|
||||
|
||||
Alternatively, if the usage of an LED is required, then the application can detect its availability and generate an error accordingly:
|
||||
|
||||
#ifndef(LED1)
|
||||
#ifndef LED1
|
||||
#error This application requires the availability of an LED
|
||||
#endif
|
||||
|
||||
|
@ -81,13 +81,13 @@ However, these names do not apply to all boards and hence should not be used in
|
|||
Only add buttons that are available on the board. This is an example on how to define buttons in PinNames.h:
|
||||
|
||||
// Px_xx relates to the processor pin connected to the button
|
||||
#define BUTTON1 = Px_xx // BUTTON1
|
||||
#define BUTTON2 = Px_xx // BUTTON2
|
||||
#define BUTTON3 = Px_xx // BUTTON3
|
||||
#define BUTTON4 = Px_xx // BUTTON4
|
||||
#define BUTTON1 Px_xx // BUTTON1
|
||||
#define BUTTON2 Px_xx // BUTTON2
|
||||
#define BUTTON3 Px_xx // BUTTON3
|
||||
#define BUTTON4 Px_xx // BUTTON4
|
||||
.
|
||||
.
|
||||
#define BUTTONN = Px_xx // BUTTONN
|
||||
#define BUTTONN Px_xx // BUTTONN
|
||||
|
||||
Note this document is proposing changing buttons from `enums` to `define`, which causes a minor change in the compile preprocessor. From application point of view, there are no implications.
|
||||
|
||||
|
@ -95,14 +95,14 @@ Note this document is proposing changing buttons from `enums` to `define`, which
|
|||
|
||||
The detection of available buttons at application level can be done as follow:
|
||||
|
||||
#ifdef(BUTTON1)
|
||||
#ifdef BUTTON1
|
||||
DigitalIn myBUTTON(BUTTON1);
|
||||
int input = myBUTTON.read();
|
||||
#endif
|
||||
|
||||
Alternatively, if the usage of a button is required, then the application can detect its availability and generate an error accordingly:
|
||||
|
||||
#ifndef(BUTTON1)
|
||||
#ifndef BUTTON1
|
||||
#error This application requires the availability of a button
|
||||
#endif
|
||||
|
||||
|
@ -135,15 +135,15 @@ Note this document is proposing unifying the pin names used for UART communicati
|
|||
If either LEDs or buttons are not available, they should not be defined.
|
||||
This allows for unavailable LEDs or BUTTONs to be caught in Mbed OS allowing the corresponding errors to be generated.
|
||||
|
||||
LED1 = PB_0, // LED1 is valid
|
||||
LED2 = LED1, // Not valid as it's duplicate and LED2 does not exist on the board
|
||||
LED3 = PB_0, // Not valid as it's duplicate and LED3 does not exist on the board
|
||||
LED4 = NC // Not valid definition as LED4 does not exist
|
||||
#define LED1 PB_0 // LED1 is valid
|
||||
#define LED2 LED1 // Not valid as it's duplicate and LED2 does not exist on the board
|
||||
#define LED3 PB_0 // Not valid as it's duplicate and LED3 does not exist on the board
|
||||
#define LED4 NC // Not valid definition as LED4 does not exist
|
||||
|
||||
BUTTON1 = PB_1, // BUTTON1 is valid
|
||||
BUTTON2 = BUTTON1, // Not valid as it's duplicate and BUTTON2 does not exist on the board
|
||||
BUTTON3 = PB_1, // Not valid as it's duplicate and BUTTON3 does not exist on the board
|
||||
BUTTON4 = NC, // Not valid as BUTTON4 does not exist
|
||||
#define BUTTON1 PB_1 // BUTTON1 is valid
|
||||
#define BUTTON2 BUTTON1 // Not valid as it's duplicate and BUTTON2 does not exist on the board
|
||||
#define BUTTON3 PB_1 // Not valid as it's duplicate and BUTTON3 does not exist on the board
|
||||
#define BUTTON4 NC // Not valid as BUTTON4 does not exist
|
||||
|
||||
|
||||
### Testing compliance
|
||||
|
|
|
@ -1,57 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2019 ARM Limited
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "utest/utest.h"
|
||||
#include "unity/unity.h"
|
||||
#include "greentea-client/test_env.h"
|
||||
|
||||
using namespace utest::v1;
|
||||
|
||||
#include "PinNames.h"
|
||||
#include "gpio_api.h"
|
||||
|
||||
static void gpio_nc_test()
|
||||
{
|
||||
gpio_t nc_obj;
|
||||
gpio_init(&nc_obj, NC);
|
||||
TEST_ASSERT_FALSE(gpio_is_connected(&nc_obj));
|
||||
|
||||
gpio_t led_obj;
|
||||
gpio_init(&led_obj, LED1);
|
||||
if (LED1 == NC) {
|
||||
TEST_ASSERT_FALSE(gpio_is_connected(&led_obj));
|
||||
} else {
|
||||
TEST_ASSERT_TRUE(gpio_is_connected(&led_obj));
|
||||
}
|
||||
}
|
||||
|
||||
Case cases[] = {
|
||||
Case("gpio NC test", gpio_nc_test)
|
||||
};
|
||||
|
||||
utest::v1::status_t greentea_test_setup(const size_t number_of_cases)
|
||||
{
|
||||
GREENTEA_SETUP(20, "default_auto");
|
||||
return greentea_test_setup_handler(number_of_cases);
|
||||
}
|
||||
|
||||
Specification specification(greentea_test_setup, cases, greentea_test_teardown_handler);
|
||||
|
||||
int main()
|
||||
{
|
||||
Harness::run(specification);
|
||||
}
|
|
@ -29,9 +29,12 @@ WEAK MBED_NORETURN void mbed_die(void)
|
|||
core_util_critical_section_enter();
|
||||
#endif
|
||||
gpio_t led_err;
|
||||
#ifdef LED1
|
||||
gpio_init_out(&led_err, LED1);
|
||||
#endif
|
||||
|
||||
while (1) {
|
||||
#ifdef LED1
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
gpio_write(&led_err, 1);
|
||||
wait_us(150000);
|
||||
|
@ -45,6 +48,7 @@ WEAK MBED_NORETURN void mbed_die(void)
|
|||
gpio_write(&led_err, 0);
|
||||
wait_us(400000);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -28,7 +28,9 @@
|
|||
|
||||
using namespace utest::v1;
|
||||
|
||||
#ifdef LED1
|
||||
DigitalOut led1(LED1);
|
||||
#endif
|
||||
|
||||
// Targets with these cores have their RAM enough size to create threads with bigger stacks
|
||||
#if defined(__CORTEX_A9) || defined(__CORTEX_M23) || defined(__CORTEX_M33) || defined(__CORTEX_M7)
|
||||
|
@ -47,7 +49,9 @@ static void busy_thread()
|
|||
volatile uint64_t i = ~0;
|
||||
|
||||
while (i--) {
|
||||
#ifdef LED1
|
||||
led1 = !led1;
|
||||
#endif
|
||||
wait_us(wait_time);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -203,14 +203,6 @@ typedef enum {
|
|||
SPI_MISO = D12,
|
||||
SPI_SCK = D13,
|
||||
|
||||
// Standardized LED and button names
|
||||
LED1 = PA_5, // ARD_D13 [SPI1_SCK/LED1]
|
||||
LED2 = PB_14, // LED2 [LED_GREEN]
|
||||
LED3 = PC_9, // LED3_WIFI_ LED4_BLE
|
||||
BUTTON1 = PC_13, // BUTTON_EXTI13 [B2]
|
||||
|
||||
// Backward legacy names
|
||||
USER_BUTTON = BUTTON1,
|
||||
PWM_OUT = D3,
|
||||
|
||||
/**** USB FS pins ****/
|
||||
|
@ -264,6 +256,12 @@ typedef enum {
|
|||
NC = (int)0xFFFFFFFF
|
||||
} PinName;
|
||||
|
||||
// Standardized LED and button names
|
||||
#define LED1 PA_5 // Green LED (LD1) // D13
|
||||
#define LED2 PB_14 // Green LED (LD2)
|
||||
#define LED3 PC_9 // Yellow LED (LD3 WIFI) / Blue LED (LD4 BLE)
|
||||
#define BUTTON1 PC_13 // BUTTON_EXTI13 [B2]
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue