Loading...
Searching...
No Matches
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
9#pragma once
10
24
25#include "container.h"
26#include "periph/gpio.h"
27
28#ifdef __cplusplus
29extern "C"
30{
31#endif
32
33#ifndef DBGPIN_PINS
34#error Please specify the pins to use with the dbgpin module (DBGPIN_PINS)
35#endif
36
43static inline void dbgpin_set(unsigned pin)
44{
45 static const gpio_t dbgpin_pins[] = { DBGPIN_PINS };
46 gpio_set(dbgpin_pins[pin]);
47}
48
55static inline void dbgpin_clear(unsigned pin)
56{
57 static const gpio_t dbgpin_pins[] = { DBGPIN_PINS };
58 gpio_clear(dbgpin_pins[pin]);
59}
60
67static inline void dbgpin_toggle(unsigned pin)
68{
69 static const gpio_t dbgpin_pins[] = { DBGPIN_PINS };
70 gpio_toggle(dbgpin_pins[pin]);
71}
72
79static inline void dbgpin_pulse(unsigned pin)
80{
81 dbgpin_toggle(pin);
82 dbgpin_toggle(pin);
83}
84
92static inline void dbgpin_signal(unsigned pin, unsigned num)
93{
94 for (unsigned i = 0; i < num; i++) {
95 dbgpin_pulse(pin);
96 }
97}
98
104static inline size_t dbgpin_count(void)
105{
106 static const gpio_t dbgpin_pins[] = { DBGPIN_PINS };
107 return ARRAY_SIZE(dbgpin_pins);
108}
109
113static inline void dbgpin_init(void)
114{
115 static const gpio_t dbgpin_pins[] = { DBGPIN_PINS };
116 for (unsigned i = 0; i < ARRAY_SIZE(dbgpin_pins); i++) {
117 gpio_init(dbgpin_pins[i], GPIO_OUT);
118 gpio_clear(dbgpin_pins[i]);
119 }
120}
121
122#ifdef __cplusplus
123}
124#endif
125
@ GPIO_OUT
select GPIO MASK as output
Definition periph_cpu.h:164
Common macros and compiler attributes/pragmas configuration.
#define ARRAY_SIZE(a)
Calculate the number of elements in a static array.
Definition container.h:82
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:113
static void dbgpin_signal(unsigned pin, unsigned num)
Output a specified number of pulses on the given debug pin.
Definition dbgpin.h:92
static size_t dbgpin_count(void)
Get the number of configured debug pins.
Definition dbgpin.h:104
static void dbgpin_set(unsigned pin)
Set the given debug pin to HIGH.
Definition dbgpin.h:43
static void dbgpin_toggle(unsigned pin)
Toggle the given debug pin.
Definition dbgpin.h:67
static void dbgpin_clear(unsigned pin)
Set the given debug pin to LOW.
Definition dbgpin.h:55
static void dbgpin_pulse(unsigned pin)
Output a pulse on the given debug pin (toggles the pin twice)
Definition dbgpin.h:79