1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00
RIOT/drivers/periph_common/gpio_ll.c
Marian Buschsieweke bd3f54ac8f
drivers/periph_gpio_ll: Add features for compile-time-checks
This adds the features

 - periph_gpio_ll_input_pull_down:
        To indicate support for input mode with internal pull down
 - periph_gpio_ll_input_pull_keep:
        To indicate support for input mode with internal resistor
        pulling towards current level
 - periph_gpio_ll_input_pull_up:
        To indicate support for input mode with internal pull up
 - periph_gpio_ll_disconnect:
        To indicate a GPIO can be disconnected
 - periph_gpio_ll_open_drain:
        To indicate support for open drain mode
 - periph_gpio_ll_open_drain_pull_up:
        To indicate support for open drain mode with internal pull up
 - periph_gpio_ll_open_source:
        To indicate support for open source mode
 - periph_gpio_ll_open_source_pull_down:
        To indicate support for open source mode with internal pull down
2024-01-23 15:03:34 +01:00

94 lines
2.4 KiB
C

/*
* Copyright (C) 2022 Otto-von-Guericke-Universität Magdeburg
*
* 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.
*/
#include <stdio.h>
#include "periph/gpio_ll.h"
/* Optimizing for low stack usage by not using printf(), which on newlib is
* prohibitively costly. This will allow developers to use this for debugging
* even in ISR - hopefully without increasing the ISR stack size.
*
* If module fmt is used, there is a stack friendly print_str() provided.
* Otherwise, fall back to fputs(), which is still way more stack friendly than
* printf().
*/
#ifdef MODULE_FMT
#include "fmt.h"
#else
static inline void print_str(const char *str)
{
fputs(str, stdout);
}
#endif
void gpio_ll_print_conf_common(const gpio_conf_t conf)
{
const char *off_on[] = { "off", "on" };
print_str("state: ");
switch (conf.state) {
case GPIO_INPUT:
print_str("in");
break;
case GPIO_OUTPUT_PUSH_PULL:
print_str("out-pp");
break;
#if MODULE_PERIPH_GPIO_LL_OPEN_DRAIN
case GPIO_OUTPUT_OPEN_DRAIN:
print_str("out-od");
break;
#endif
#if MODULE_PERIPH_GPIO_LL_OPEN_SOURCE
case GPIO_OUTPUT_OPEN_SOURCE:
print_str("out-os");
break;
#endif
case GPIO_USED_BY_PERIPHERAL:
print_str("periph");
break;
#if MODULE_PERIPH_GPIO_LL_DISCONNECT
case GPIO_DISCONNECT:
print_str("off");
break;
#endif
default:
print_str("?");
break;
}
if (conf.state != GPIO_OUTPUT_PUSH_PULL) {
print_str(", pull: ");
switch (conf.pull) {
default:
case GPIO_FLOATING:
print_str("none");
break;
case GPIO_PULL_UP:
print_str("up");
break;
case GPIO_PULL_DOWN:
print_str("down");
break;
case GPIO_PULL_KEEP:
print_str("keep");
break;
}
}
print_str(", value: ");
print_str(off_on[conf.initial_value]);
}
/* implement gpio_ll_print_conf as weak alias symbol for
* gpio_ll_print_conf_common - so that platform specific implementations can
* override gpio_ll_print_conf while reusing gpio_ll_print_conf_common()
*/
__attribute__((weak, alias("gpio_ll_print_conf_common")))
void gpio_ll_print_conf(gpio_conf_t conf);