Blame view

RIOT/tests/buttons/main.c 1.79 KB
a752c7ab   elopes   add first test an...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
  /*
   * Copyright (C) 2017 HAW Hamburg
   *
   * 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     tests
   * @{
   *
   * @file
   * @brief       Test for the on-board button macros
   *
   * @author      Sebastian Meiling <s@mlng.net>
   *
   * @}
   */
  
  #include <stdio.h>
  #include <stdint.h>
  
  #include "board.h"
  #include "periph/gpio.h"
  #include "periph_conf.h"
  
  #define TEST_FLANK      GPIO_FALLING
  
  #ifdef BTN0_PIN /* assuming that first button is always BTN0 */
  static void cb(void *arg)
  {
      printf("Pressed BTN%d\n", (int)arg);
  }
  #endif
  
  int main(void)
  {
      int cnt = 0;
      /* get the number of available buttons and init interrupt handler */
  #ifdef BTN0_PIN
      if (gpio_init_int(BTN0_PIN, BTN0_MODE, TEST_FLANK, cb, (void *)cnt) < 0) {
          puts("[FAILED] init BTN0!");
          return 1;
      }
      ++cnt;
  #endif
  #ifdef BTN1_PIN
      if (gpio_init_int(BTN1_PIN, BTN1_MODE, TEST_FLANK, cb, (void *)cnt) < 0) {
          puts("[FAILED] init BTN1!");
          return 1;
      }
      ++cnt;
  #endif
  #ifdef BTN2_PIN
      if (gpio_init_int(BTN2_PIN, BTN2_MODE, TEST_FLANK, cb, (void *)cnt) < 0) {
          puts("[FAILED] init BTN2!");
          return 1;
      }
      ++cnt;
  #endif
  #ifdef BTN3_PIN
      if (gpio_init_int(BTN3_PIN, BTN3_MODE, TEST_FLANK, cb, (void *)cnt) < 0) {
          puts("[FAILED] init BTN3!");
          return 1;
      }
      ++cnt;
  #endif
  
      puts("On-board button test\n");
      /* cppcheck-suppress knownConditionTrueFalse
       * rationale: board-dependent ifdefs */
      if (cnt == 0) {
          puts("[FAILED] no buttons available!");
          return 2;
      }
      printf(" -- Available buttons: %i\n\n", cnt);
      puts(" -- Try pressing buttons to test.\n");
      puts("[SUCCESS]");
      return 0;
  }