mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
Merge pull request #17711 from benpicco/periph_init_buttons
drivers/periph_common: add periph_init_buttons to init on-board buttons
This commit is contained in:
commit
52f12e0734
@ -1,29 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2016 Freie Universität Berlin
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ingroup boards_calliope-mini
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief Board initialization code for the Calliope mini
|
||||
*
|
||||
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
|
||||
*
|
||||
* @}
|
||||
*/
|
||||
|
||||
#include "board.h"
|
||||
#include "periph/gpio.h"
|
||||
|
||||
void board_init(void)
|
||||
{
|
||||
/* initialize the mini's buttons */
|
||||
gpio_init(BTN0_PIN, BTN0_MODE);
|
||||
gpio_init(BTN1_PIN, BTN1_MODE);
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2021 Inria
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ingroup boards_microbit_v2
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief Board initialization code for the BBC micro:bit v2
|
||||
*
|
||||
* @author Alexandre Abadie <alexandre.abadie@inria.fr>
|
||||
*
|
||||
* @}
|
||||
*/
|
||||
|
||||
#include "board.h"
|
||||
#include "periph/gpio.h"
|
||||
|
||||
void board_init(void)
|
||||
{
|
||||
/* initialize the on board buttons */
|
||||
gpio_init(BTN0_PIN, BTN0_MODE);
|
||||
gpio_init(BTN1_PIN, BTN1_MODE);
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2016 Freie Universität Berlin
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ingroup boards_microbit
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief Board initialization code for the BBC micro:bit
|
||||
*
|
||||
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
|
||||
*
|
||||
* @}
|
||||
*/
|
||||
|
||||
#include "board.h"
|
||||
#include "periph/gpio.h"
|
||||
|
||||
void board_init(void)
|
||||
{
|
||||
/* initialize the micro:bit's buttons */
|
||||
gpio_init(BTN0_PIN, BTN0_MODE);
|
||||
gpio_init(BTN1_PIN, BTN1_MODE);
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2018 Inria
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ingroup boards_nrf51dk
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief Board initialization code for the nRF51DK
|
||||
*
|
||||
* @author Alexandre Abadie <alexandre.abadie@inria.fr>
|
||||
*
|
||||
* @}
|
||||
*/
|
||||
|
||||
#include "board.h"
|
||||
#include "periph/gpio.h"
|
||||
|
||||
void board_init(void)
|
||||
{
|
||||
/* initialize the board buttons */
|
||||
gpio_init(BTN0_PIN, BTN0_MODE);
|
||||
gpio_init(BTN1_PIN, BTN1_MODE);
|
||||
gpio_init(BTN2_PIN, BTN2_MODE);
|
||||
gpio_init(BTN3_PIN, BTN3_MODE);
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2021 Mesotic SAS
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ingroup boards_nrf9160dk
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief Board initialization for the nRF9160DK
|
||||
*
|
||||
* @author Dylan Laduranty <dylan.laduranty@mesotic.com>
|
||||
*
|
||||
* @}
|
||||
*/
|
||||
|
||||
#include "cpu.h"
|
||||
#include "board.h"
|
||||
#include "periph/gpio.h"
|
||||
|
||||
void board_init(void)
|
||||
{
|
||||
|
||||
gpio_init(BTN0_PIN, BTN0_MODE);
|
||||
gpio_init(BTN1_PIN, BTN1_MODE);
|
||||
gpio_init(BTN2_PIN, BTN2_MODE);
|
||||
gpio_init(BTN3_PIN, BTN3_MODE);
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2020 Scallog
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ingroup boards_olimexino-stm32
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief Board specific implementations for the OLIMEXINO STM32 board
|
||||
*
|
||||
* @author Corentin Vigourt <cvigourt@scallog.com>
|
||||
*/
|
||||
|
||||
#include "board.h"
|
||||
#include "periph/gpio.h"
|
||||
|
||||
void board_init(void)
|
||||
{
|
||||
|
||||
/* initialize the button */
|
||||
gpio_init(BTN0_PIN, BTN0_MODE);
|
||||
}
|
||||
/** @} */
|
@ -22,6 +22,4 @@ void board_init(void)
|
||||
{
|
||||
/* The boot pin must be set to input otherwise it may lock the bootloader */
|
||||
gpio_init(BOOT_PIN, GPIO_IN);
|
||||
|
||||
gpio_init(BTN0_PIN, BTN0_MODE);
|
||||
}
|
||||
|
@ -27,7 +27,6 @@ void board_init(void)
|
||||
/* The boot pin must be set to input otherwise it may lock the bootloader */
|
||||
gpio_init(BOOT_PIN, GPIO_IN);
|
||||
|
||||
gpio_init(BTN0_PIN, BTN0_MODE);
|
||||
gpio_init(RF24_SWITCH_CC2538_PIN, GPIO_OUT);
|
||||
gpio_init(RF24_SWITCH_AT86RF215_PIN, GPIO_OUT);
|
||||
|
||||
|
@ -57,11 +57,3 @@ static mtd_spi_nor_t mtd_nor_dev = {
|
||||
|
||||
mtd_dev_t *mtd0 = (mtd_dev_t *)&mtd_nor_dev;
|
||||
#endif /* MODULE_MTD */
|
||||
|
||||
void board_init(void)
|
||||
{
|
||||
/* Initialize LEDs and Buttons. */
|
||||
gpio_init(BTN1_PIN, BTN1_MODE);
|
||||
gpio_init(BTN2_PIN, BTN2_MODE);
|
||||
|
||||
}
|
||||
|
@ -23,15 +23,10 @@
|
||||
|
||||
void board_init(void)
|
||||
{
|
||||
|
||||
/* initialize the on-board button */
|
||||
gpio_init(BTN0_PIN, BTN0_MODE);
|
||||
|
||||
/* If the PA24 and PA25 pins are not connected, it is recommended
|
||||
* to enable a pull-up on PA24 and PA25 through input GPIO mode.
|
||||
* (those have external pull-ups on the board that would leak current)
|
||||
*/
|
||||
gpio_init(GPIO_PIN(PA, 24), GPIO_IN_PU);
|
||||
gpio_init(GPIO_PIN(PA, 25), GPIO_IN_PU);
|
||||
|
||||
}
|
||||
|
@ -1,30 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2020 ML!PA Consulting GmbH
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ingroup boards_samd20-xpro
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief Board specific implementations for the Atmel SAM D20 Xplained
|
||||
* Pro board
|
||||
*
|
||||
* @author Benjamin Valentin <benjamin.valentin@ml-pa.com>
|
||||
* @}
|
||||
*/
|
||||
|
||||
#include "board.h"
|
||||
#include "periph/gpio.h"
|
||||
|
||||
void board_init(void)
|
||||
{
|
||||
|
||||
/* initialize the on-board button */
|
||||
gpio_init(BTN0_PIN, BTN0_MODE);
|
||||
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Travis Griggs <travisgriggs@gmail.com>
|
||||
* Copyright (C) 2017 Dan Evans <photonthunder@gmail.com>
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ingroup boards_samd21-xpro
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief Board specific implementations for the Atmel SAM D21 Xplained
|
||||
* Pro board
|
||||
*
|
||||
* @author Travis Griggs <travisgriggs@gmail.com>
|
||||
* @author Dan Evans <photonthunder@gmail.com>
|
||||
* @author Sebastian Meiling <s@mlng.net>
|
||||
* @}
|
||||
*/
|
||||
|
||||
#include "board.h"
|
||||
#include "periph/gpio.h"
|
||||
|
||||
void board_init(void)
|
||||
{
|
||||
|
||||
/* initialize the on-board button */
|
||||
gpio_init(BTN0_PIN, BTN0_MODE);
|
||||
|
||||
}
|
@ -67,9 +67,3 @@ mtd_dev_t *mtd1 = (mtd_dev_t *)&at24mac_dev;
|
||||
VFS_AUTO_MOUNT(littlefs2, VFS_MTD(same54_nor_dev), "/nvm", 0);
|
||||
#endif
|
||||
#endif /* MODULE_MTD */
|
||||
|
||||
void board_init(void)
|
||||
{
|
||||
/* initialize the on-board button */
|
||||
gpio_init(BTN0_PIN, BTN0_MODE);
|
||||
}
|
||||
|
@ -44,11 +44,6 @@ mtd_dev_t *mtd0 = (mtd_dev_t *)&sensebox_sd_dev;
|
||||
|
||||
void board_init(void)
|
||||
{
|
||||
|
||||
|
||||
/* initialize the on-board button on pin PA20 */
|
||||
gpio_init(BTN0_PIN, BTN0_MODE);
|
||||
|
||||
/* initialize XBEE1 bus enable pin */
|
||||
gpio_init(XBEE1_EN_PIN, XBEE1_EN_MODE);
|
||||
|
||||
|
@ -1,29 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2021 BISSELL Homecare, Inc.
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ingroup boards_stm32g0316-disco
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief Board specific implementations for the STM32G0316-DISCO board
|
||||
*
|
||||
* @author Dave VanKampen <david.vankampen@bissell.com>
|
||||
*
|
||||
* @}
|
||||
*/
|
||||
|
||||
#include "cpu.h"
|
||||
#include "board.h"
|
||||
#include "periph/gpio.h"
|
||||
|
||||
void board_init(void)
|
||||
{
|
||||
|
||||
gpio_init(BTN0_PIN, BTN0_MODE);
|
||||
}
|
@ -28,6 +28,12 @@ config MODULE_PERIPH_INIT_ADC
|
||||
default y if MODULE_PERIPH_INIT
|
||||
depends on MODULE_PERIPH_ADC
|
||||
|
||||
config MODULE_PERIPH_INIT_BUTTONS
|
||||
bool
|
||||
depends on TEST_KCONFIG
|
||||
help
|
||||
Enable auto initialization of on-board buttons
|
||||
|
||||
config MODULE_PERIPH_CPUID
|
||||
bool "CPU unique ID"
|
||||
depends on HAS_PERIPH_CPUID
|
||||
|
@ -63,6 +63,11 @@ void periph_init(void)
|
||||
extern void led_init(void);
|
||||
led_init();
|
||||
}
|
||||
/* initialize buttonss */
|
||||
if (IS_USED(MODULE_PERIPH_INIT_BUTTONS)) {
|
||||
extern void button_init(void);
|
||||
button_init();
|
||||
}
|
||||
/* initialize configured I2C devices */
|
||||
#ifdef MODULE_PERIPH_INIT_I2C
|
||||
for (unsigned i = 0; i < I2C_NUMOF; i++) {
|
||||
|
55
drivers/periph_common/init_buttons.c
Normal file
55
drivers/periph_common/init_buttons.c
Normal file
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (C) 2022 ML!PA Consulting GmbH
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ingroup drivers_periph_init
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief Init on board Buttons as input
|
||||
*
|
||||
* @author Benjamin Valentin <benjamin.valentin@ml-pa.com>
|
||||
* @}
|
||||
*/
|
||||
|
||||
#include "board.h"
|
||||
#include "periph/gpio.h"
|
||||
#include "kernel_defines.h"
|
||||
|
||||
__attribute__ ((weak))
|
||||
void button_init(void)
|
||||
{
|
||||
if (!IS_USED(MODULE_PERIPH_GPIO)) {
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef BTN0_PIN
|
||||
gpio_init(BTN0_PIN, BTN0_MODE);
|
||||
#endif
|
||||
#ifdef BTN1_PIN
|
||||
gpio_init(BTN1_PIN, BTN1_MODE);
|
||||
#endif
|
||||
#ifdef BTN2_PIN
|
||||
gpio_init(BTN2_PIN, BTN2_MODE);
|
||||
#endif
|
||||
#ifdef BTN3_PIN
|
||||
gpio_init(BTN3_PIN, BTN3_MODE);
|
||||
#endif
|
||||
#ifdef BTN4_PIN
|
||||
gpio_init(BTN4_PIN, BTN4_MODE);
|
||||
#endif
|
||||
#ifdef BTN5_PIN
|
||||
gpio_init(BTN5_PIN, BTN5_MODE);
|
||||
#endif
|
||||
#ifdef BTN6_PIN
|
||||
gpio_init(BTN6_PIN, BTN6_MODE);
|
||||
#endif
|
||||
#ifdef BTN7_PIN
|
||||
gpio_init(BTN7_PIN, BTN7_MODE);
|
||||
#endif
|
||||
}
|
@ -3,4 +3,7 @@ include ../Makefile.tests_common
|
||||
# Some boards do not initialize LED0 by default
|
||||
CFLAGS=-DPERIPH_INIT_LED0
|
||||
|
||||
# auto-init on board buttons as well
|
||||
USEMODULE += periph_init_buttons
|
||||
|
||||
include $(RIOTBASE)/Makefile.include
|
||||
|
@ -5,6 +5,9 @@ endless loop. Each LED will light up once long, and twice short, where the long
|
||||
interval is roughly 4 times as long as the short interval. The length of the
|
||||
interval is not specified and differs for each platform.
|
||||
|
||||
Afterwards the test will connect each on-board button to an LED (if available),
|
||||
so that that LED state mirrors the button state.
|
||||
|
||||
Background
|
||||
==========
|
||||
Running this test shows if all the direct access macros for all on-board LEDs
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include "clk.h"
|
||||
#include "board.h"
|
||||
#include "periph_conf.h"
|
||||
#include "periph/gpio.h"
|
||||
|
||||
#define DELAY_SHORT (coreclk() / 50)
|
||||
#define DELAY_LONG (DELAY_SHORT * 4)
|
||||
@ -81,10 +82,10 @@ int main(void)
|
||||
}
|
||||
else {
|
||||
printf("Available LEDs: %i\n\n", numof);
|
||||
puts("Will now light up each LED once short and twice long in a loop");
|
||||
puts("Will now light up each LED once short and twice long");
|
||||
}
|
||||
|
||||
while (1) {
|
||||
for (unsigned i = 0; i < 4; ++i) {
|
||||
#ifdef LED0_ON
|
||||
LED0_ON;
|
||||
dumb_delay(DELAY_LONG);
|
||||
@ -199,5 +200,34 @@ int main(void)
|
||||
#endif
|
||||
}
|
||||
|
||||
puts("Mapping each LED to a button (if available)");
|
||||
|
||||
while (1) {
|
||||
#if defined(LED0_PIN) && defined(BTN0_PIN)
|
||||
gpio_write(LED0_PIN, gpio_read(BTN0_PIN));
|
||||
#endif
|
||||
#if defined(LED1_PIN) && defined(BTN1_PIN)
|
||||
gpio_write(LED1_PIN, gpio_read(BTN1_PIN));
|
||||
#endif
|
||||
#if defined(LED2_PIN) && defined(BTN2_PIN)
|
||||
gpio_write(LED2_PIN, gpio_read(BTN2_PIN));
|
||||
#endif
|
||||
#if defined(LED3_PIN) && defined(BTN3_PIN)
|
||||
gpio_write(LED3_PIN, gpio_read(BTN3_PIN));
|
||||
#endif
|
||||
#if defined(LED4_PIN) && defined(BTN4_PIN)
|
||||
gpio_write(LED4_PIN, gpio_read(BTN4_PIN));
|
||||
#endif
|
||||
#if defined(LED5_PIN) && defined(BTN5_PIN)
|
||||
gpio_write(LED5_PIN, gpio_read(BTN5_PIN));
|
||||
#endif
|
||||
#if defined(LED6_PIN) && defined(BTN6_PIN)
|
||||
gpio_write(LED6_PIN, gpio_read(BTN6_PIN));
|
||||
#endif
|
||||
#if defined(LED7_PIN) && defined(BTN7_PIN)
|
||||
gpio_write(LED7_PIN, gpio_read(BTN7_PIN));
|
||||
#endif
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user