dbgpin.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2020 Freie Universität Berlin
3  * SPDX-License-Identifier: LGPL-2.1-only
4  */
5 
6 #pragma once
7 
22 #include "container.h"
23 #include "periph/gpio.h"
24 
25 #ifdef __cplusplus
26 extern "C"
27 {
28 #endif
29 
30 #ifndef DBGPIN_PINS
31 #error Please specify the pins to use with the dbgpin module (DBGPIN_PINS)
32 #endif
33 
40 static inline void dbgpin_set(unsigned pin)
41 {
42  static const gpio_t dbgpin_pins[] = { DBGPIN_PINS };
43  gpio_set(dbgpin_pins[pin]);
44 }
45 
52 static inline void dbgpin_clear(unsigned pin)
53 {
54  static const gpio_t dbgpin_pins[] = { DBGPIN_PINS };
55  gpio_clear(dbgpin_pins[pin]);
56 }
57 
64 static inline void dbgpin_toggle(unsigned pin)
65 {
66  static const gpio_t dbgpin_pins[] = { DBGPIN_PINS };
67  gpio_toggle(dbgpin_pins[pin]);
68 }
69 
76 static inline void dbgpin_pulse(unsigned pin)
77 {
78  dbgpin_toggle(pin);
79  dbgpin_toggle(pin);
80 }
81 
89 static inline void dbgpin_signal(unsigned pin, unsigned num)
90 {
91  for (unsigned i = 0; i < num; i++) {
92  dbgpin_pulse(pin);
93  }
94 }
95 
101 static inline size_t dbgpin_count(void)
102 {
103  static const gpio_t dbgpin_pins[] = { DBGPIN_PINS };
104  return ARRAY_SIZE(dbgpin_pins);
105 }
106 
110 static inline void dbgpin_init(void)
111 {
112  static const gpio_t dbgpin_pins[] = { DBGPIN_PINS };
113  for (unsigned i = 0; i < ARRAY_SIZE(dbgpin_pins); i++) {
114  gpio_init(dbgpin_pins[i], GPIO_OUT);
115  gpio_clear(dbgpin_pins[i]);
116  }
117 }
118 
119 #ifdef __cplusplus
120 }
121 #endif
122 
@ GPIO_OUT
select GPIO MASK as output
Definition: periph_cpu.h:161
Common macros and compiler attributes/pragmas configuration.
#define ARRAY_SIZE(a)
Calculate the number of elements in a static array.
Definition: container.h:79
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:110
static void dbgpin_signal(unsigned pin, unsigned num)
Output a specified number of pulses on the given debug pin.
Definition: dbgpin.h:89
static size_t dbgpin_count(void)
Get the number of configured debug pins.
Definition: dbgpin.h:101
static void dbgpin_set(unsigned pin)
Set the given debug pin to HIGH.
Definition: dbgpin.h:40
static void dbgpin_toggle(unsigned pin)
Toggle the given debug pin.
Definition: dbgpin.h:64
static void dbgpin_clear(unsigned pin)
Set the given debug pin to LOW.
Definition: dbgpin.h:52
static void dbgpin_pulse(unsigned pin)
Output a pulse on the given debug pin (toggles the pin twice)
Definition: dbgpin.h:76