5
5
#include "board.h"
6
6
#include "periph/gpio.h"
7
7
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
-
31
8
/**
32
9
* @brief callback function for button interrupt
33
10
*
34
- * @param[in] arg contains gpio pin
11
+ * @param[in] arg NULL
35
12
*/
36
13
static void btn_callback (void * arg )
37
14
{
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 ;
47
16
}
48
17
49
18
/**
@@ -53,21 +22,21 @@ static void btn_callback(void* arg)
53
22
*/
54
23
int main (void )
55
24
{
56
- puts ("SmartUniversity - Button Example!" );
57
- puts ("================" );
25
+ puts (" SmartUniversity - Button Example! " );
26
+ puts ("=================================== " );
58
27
printf ("You are running RIOT on a(n) %s board.\n" , RIOT_BOARD );
59
28
printf ("This board features a(n) %s MCU.\n" , RIOT_MCU );
60
- puts ("================" );
29
+ puts ("=================================== " );
61
30
62
31
// 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!" );
67
37
return 1 ;
68
38
}
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." );
71
40
72
41
// infinity loop 1
73
42
while (1 ) {
0 commit comments