Skip to content

Commit 8c49962

Browse files
committed
button: adapted gpio handling to latest riot
1 parent fd16341 commit 8c49962

File tree

1 file changed

+11
-42
lines changed

1 file changed

+11
-42
lines changed

src/button/main.c

Lines changed: 11 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -5,45 +5,14 @@
55
#include "board.h"
66
#include "periph/gpio.h"
77

8-
// compatibility
9-
#ifndef LED_ON
10-
#define LED_ON LED_RED_ON
11-
#define LED_OFF LED_RED_OFF
12-
#define LED_TOGGLE LED_RED_TOGGLE
13-
#endif
14-
15-
// button parameters, matching Atmel SAM R21 board
16-
#ifdef BOARD_SAMR21_XPRO
17-
#define BTN_PORT 0 // Port+Pin A28
18-
#define BTN_PIN 28
19-
#define BTN_PULL GPIO_PULLUP
20-
#define BTN_FLANK GPIO_BOTH
21-
#else
22-
// or button parameters, matching Phytec phyWAVE
23-
// Note: port is ignored, only pin is used by GPIO
24-
//#ifdef BOARD_PBA_D_01_KW2X
25-
#define BTN_PORT 0 // Port+Pin D1
26-
#define BTN_PIN 3
27-
#define BTN_PULL GPIO_PULLUP
28-
#define BTN_FLANK GPIO_BOTH
29-
#endif
30-
318
/**
329
* @brief callback function for button interrupt
3310
*
34-
* @param[in] arg contains gpio pin
11+
* @param[in] arg NULL
3512
*/
3613
static void btn_callback(void* arg)
3714
{
38-
gpio_t pin = *((gpio_t*)arg);
39-
if (gpio_read(pin)) {
40-
puts("LED off");
41-
LED_OFF;
42-
}
43-
else {
44-
puts("LED on");
45-
LED_ON;
46-
}
15+
LED0_TOGGLE;
4716
}
4817

4918
/**
@@ -53,21 +22,21 @@ static void btn_callback(void* arg)
5322
*/
5423
int main(void)
5524
{
56-
puts("SmartUniversity - Button Example!");
57-
puts("================");
25+
puts(" SmartUniversity - Button Example! ");
26+
puts("===================================");
5827
printf("You are running RIOT on a(n) %s board.\n", RIOT_BOARD);
5928
printf("This board features a(n) %s MCU.\n", RIOT_MCU);
60-
puts("================");
29+
puts("===================================");
6130

6231
// init button as interrupt to trigger LED
63-
int gpio_pin = GPIO(BTN_PORT, BTN_PIN);
64-
if (gpio_init_int(gpio_pin, BTN_PULL, BTN_FLANK, btn_callback, (void *)&gpio_pin) < 0) {
65-
printf("Error while initializing PORT_%i.%02i as external interrupt\n",
66-
BTN_PORT, BTN_PIN);
32+
gpio_t pin = BUTTON_GPIO;
33+
gpio_mode_t mode = GPIO_IN_PU;
34+
gpio_flank_t flank = GPIO_FALLING;
35+
if (gpio_init_int(pin, mode, flank, btn_callback, NULL) < 0) {
36+
puts("Error while initializing BUTTON_GPIO as external interrupt!");
6737
return 1;
6838
}
69-
printf("PORT_%i.%02i initialized successful as external interrupt\n",
70-
BTN_PORT, BTN_PIN);
39+
printf("BUTTON_GPIO initialized successful as external interrupt.");
7140

7241
// infinity loop 1
7342
while(1) {

0 commit comments

Comments
 (0)