Paparazzi UAS v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
gpio_ext_common.c
Go to the documentation of this file.
1/*
2 * Copyright (C) Tom van Dijk <tomvand@users.noreply.github.com>
3 *
4 * This file is part of paparazzi
5 *
6 * paparazzi is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
9 * any later version.
10 *
11 * paparazzi is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with paparazzi; see the file COPYING. If not, see
18 * <http://www.gnu.org/licenses/>.
19 */
20
26#include "gpio_ext_common.h"
27
28#include "generated/airframe.h"
29#include "generated/modules.h"
30#include "mcu_periph/gpio.h"
31
32#include <stdint.h>
33
34
35/* External GPIO providers */
36#define GPIO_EXT_NOT_PROVIDED NULL
37
38#ifndef GPIO_EXT_PROVIDER1
39#define GPIO_EXT_PROVIDER1 GPIO_EXT_NOT_PROVIDED
40#endif
41#ifndef GPIO_EXT_PROVIDER2
42#define GPIO_EXT_PROVIDER2 GPIO_EXT_NOT_PROVIDED
43#endif
44#ifndef GPIO_EXT_PROVIDER3
45#define GPIO_EXT_PROVIDER3 GPIO_EXT_NOT_PROVIDED
46#endif
47#ifndef GPIO_EXT_PROVIDER4
48#define GPIO_EXT_PROVIDER4 GPIO_EXT_NOT_PROVIDED
49#endif
50
57
58
59/*
60 * External GPIO implementation
61 */
62#define SAFE_CALL(_port, _fn, _args...) if(gpio_ext_impl[_port - GPIOEXT1] && gpio_ext_impl[_port - GPIOEXT1]->_fn) gpio_ext_impl[_port - GPIOEXT1]->_fn(_args);
63
64// Wrapping functions
68 if (port >= GPIOEXT1 && port < GPIOEXT1 + GPIOEXT_NB) {
69 SAFE_CALL(port, setup_output, port, gpios);
70 } else {
72 }
73}
74
78 if (port >= GPIOEXT1 && port < GPIOEXT1 + GPIOEXT_NB) {
79 SAFE_CALL(port, setup_input, port, gpios);
80 } else {
82 }
83}
84
88 if (port >= GPIOEXT1 && port < GPIOEXT1 + GPIOEXT_NB) {
89 if (gpio_ext_impl[port - GPIOEXT1] && gpio_ext_impl[port - GPIOEXT1]->get) {
90 return gpio_ext_impl[port - GPIOEXT1]->get(port, gpios);
91 } else {
92 return 0;
93 }
94 } else {
95 return __real_gpio_get(port, gpios);
96 }
97}
98
102 if (port >= GPIOEXT1 && port < GPIOEXT1 + GPIOEXT_NB) {
103 SAFE_CALL(port, set, port, gpios);
104 } else {
105 __real_gpio_set(port, gpios);
106 }
107}
108
112 if (port >= GPIOEXT1 && port < GPIOEXT1 + GPIOEXT_NB) {
113 SAFE_CALL(port, clear, port, gpios);
114 } else {
116 }
117}
118
122 if (port >= GPIOEXT1 && port < GPIOEXT1 + GPIOEXT_NB) {
123 SAFE_CALL(port, toggle, port, gpios);
124 } else {
126 }
127}
128
129
Some architecture independent helper functions for GPIOs.
void __wrap_gpio_set(uint32_t port, uint32_t gpios)
uint32_t __wrap_gpio_get(uint32_t port, uint32_t gpios)
#define GPIO_EXT_PROVIDER2
void __wrap_gpio_toggle(uint32_t port, uint32_t gpios)
#define GPIO_EXT_PROVIDER1
void __real_gpio_set(uint32_t port, uint32_t gpios)
#define GPIO_EXT_PROVIDER3
void __wrap_gpio_setup_input(uint32_t port, uint32_t gpios)
#define GPIO_EXT_PROVIDER4
uint32_t __real_gpio_get(uint32_t port, uint32_t gpios)
#define SAFE_CALL(_port, _fn, _args...)
void __real_gpio_clear(uint32_t port, uint32_t gpios)
void __real_gpio_setup_output(uint32_t port, uint32_t gpios)
void __real_gpio_toggle(uint32_t port, uint32_t gpios)
void __real_gpio_setup_input(uint32_t port, uint32_t gpios)
static struct gpio_ext_functions * gpio_ext_impl[GPIOEXT_NB]
void __wrap_gpio_clear(uint32_t port, uint32_t gpios)
void __wrap_gpio_setup_output(uint32_t port, uint32_t gpios)
uint16_t foo
Definition main_demo5.c:58
void(* setup_output)(uint32_t port, uint32_t gpios)
void(* setup_input)(uint32_t port, uint32_t gpios)
uint32_t(* get)(uint32_t port, uint32_t gpios)
void(* clear)(uint32_t port, uint32_t gpios)
void(* toggle)(uint32_t port, uint32_t gpios)
void(* set)(uint32_t port, uint32_t gpios)
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.