dbgpin.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2020 Freie Universität Berlin
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
23 #ifndef DBGPIN_H
24 #define DBGPIN_H
25 
26 #include "container.h"
27 #include "periph/gpio.h"
28 
29 #ifdef __cplusplus
30 extern "C"
31 {
32 #endif
33 
34 #ifndef DBGPIN_PINS
35 #error Please specify the pins to use with the dbgpin module (DBGPIN_PINS)
36 #endif
37 
44 static inline void dbgpin_set(unsigned pin)
45 {
46  static const gpio_t dbgpin_pins[] = { DBGPIN_PINS };
47  gpio_set(dbgpin_pins[pin]);
48 }
49 
56 static inline void dbgpin_clear(unsigned pin)
57 {
58  static const gpio_t dbgpin_pins[] = { DBGPIN_PINS };
59  gpio_clear(dbgpin_pins[pin]);
60 }
61 
68 static inline void dbgpin_toggle(unsigned pin)
69 {
70  static const gpio_t dbgpin_pins[] = { DBGPIN_PINS };
71  gpio_toggle(dbgpin_pins[pin]);
72 }
73 
80 static inline void dbgpin_pulse(unsigned pin)
81 {
82  dbgpin_toggle(pin);
83  dbgpin_toggle(pin);
84 }
85 
93 static inline void dbgpin_signal(unsigned pin, unsigned num)
94 {
95  for (unsigned i = 0; i < num; i++) {
96  dbgpin_pulse(pin);
97  }
98 }
99 
105 static inline size_t dbgpin_count(void)
106 {
107  static const gpio_t dbgpin_pins[] = { DBGPIN_PINS };
108  return ARRAY_SIZE(dbgpin_pins);
109 }
110 
114 static inline void dbgpin_init(void)
115 {
116  static const gpio_t dbgpin_pins[] = { DBGPIN_PINS };
117  for (unsigned i = 0; i < ARRAY_SIZE(dbgpin_pins); i++) {
118  gpio_init(dbgpin_pins[i], GPIO_OUT);
119  gpio_clear(dbgpin_pins[i]);
120  }
121 }
122 
123 #ifdef __cplusplus
124 }
125 #endif
126 
127 #endif /* DBGPIN_H */
@ GPIO_OUT
select GPIO MASK as output
Definition: periph_cpu.h:165
Common macros and compiler attributes/pragmas configuration.
#define ARRAY_SIZE(a)
Calculate the number of elements in a static array.
Definition: container.h:83
Low-level GPIO peripheral driver interface definitions.
void gpio_toggle(gpio_t pin)
Toggle the value of the given pin.
void gpio_clear(gpio_t pin)
Set the given pin to LOW.
void gpio_set(gpio_t pin)
Set the given pin to HIGH.
int gpio_init(gpio_t pin, gpio_mode_t mode)
Initialize the given pin as general purpose input or output.
static void dbgpin_init(void)
Initialize the configured input pins.
Definition: dbgpin.h:114
static void dbgpin_signal(unsigned pin, unsigned num)
Output a specified number of pulses on the given debug pin.
Definition: dbgpin.h:93
static size_t dbgpin_count(void)
Get the number of configured debug pins.
Definition: dbgpin.h:105
static void dbgpin_set(unsigned pin)
Set the given debug pin to HIGH.
Definition: dbgpin.h:44
static void dbgpin_toggle(unsigned pin)
Toggle the given debug pin.
Definition: dbgpin.h:68
static void dbgpin_clear(unsigned pin)
Set the given debug pin to LOW.
Definition: dbgpin.h:56
static void dbgpin_pulse(unsigned pin)
Output a pulse on the given debug pin (toggles the pin twice)
Definition: dbgpin.h:80