Hardware Abstraction Layer for FreeRTOS
gpio_prv.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: MIT */
2 /*
3  * Author: Andreas Werner <kernel@andy89.org>
4  * Date: 2016
5  */
6 #ifndef GPIO_PRV_H_
7 #define GPIO_PRV_H_
8 #ifndef GPIO_PRV
9 # error "Never include this file out of a GPIO driver"
10 #endif
11 #include <stdbool.h>
12 #include <stdint.h>
13 #include <hal.h>
14 #define GPIO_ALREDY_INITED 1
15 int32_t gpio_genericInit(struct gpio *gpio);
16 #define GPIO_ADDDEV(ns, p) HAL_ADDDEV(gpio, ns, p)
18 #define GPIO_GET_DEV(index) HAL_GET_DEV(gpio, index)
19 #ifndef CONFIG_GPIO_MULTI
20 # define GPIO_OPS(ns)
21 # define GPIO_INIT_DEV(ns)
22 # define GPIO_INIT(ns, index) struct gpio *gpio_init(uint32_t index)
23 # define GPIO_DEINIT(ns, g) int32_t gpio_deinit(struct gpio *g)
24 # define GPIO_PIN_INIT(ns, g, p, dir, setting) struct gpio_pin *gpioPin_init(struct gpio *g, uint32_t p, enum gpio_direction dir, enum gpio_setting setting)
25 # define GPIO_PIN_DEINIT(ns, p) int32_t gpioPin_deinit(struct gpio_pin *p)
26 # define GPIO_PIN_ENABLE_INTERRUPT(ns, p) int32_t gpioPin_enableInterrupt(struct gpio_pin *p)
27 # define GPIO_PIN_DISABLE_INTERRUPT(ns, p) int32_t gpioPin_disableInterrupt(struct gpio_pin *p)
28 # define GPIO_PIN_SET_CALLBACK(ns, p, callback, data, inter) int32_t gpioPin_setCallback(struct gpio_pin *p, bool (*callback)(struct gpio_pin *pin, uint32_t pinID, void *data), void *data, enum gpio_interrupt inter)
29 # define GPIO_PIN_SET_DIRECTION(ns, p, dir) int32_t gpioPin_setDirection(struct gpio_pin *p, enum gpio_direction dir)
30 # define GPIO_PIN_SET_SETTING(ns, p, setting) int32_t gpioPin_setSetting(struct gpio_pin *p, enum gpio_setting setting)
31 # define GPIO_PIN_SCHMITT_TRIGGER(ns, p, schmitt) int32_t gpioPin_SchmittTrigger(struct gpio_pin *p, bool schmitt)
32 # define GPIO_PIN_SET_VALUE(ns, p, value) int32_t gpioPin_setValue(struct gpio_pin *p, bool value)
33 # define GPIO_PIN_SET_PIN(ns, p) int32_t gpioPin_setPin(struct gpio_pin *p)
34 # define GPIO_PIN_CLEAR_PIN(ns, p) int32_t gpioPin_clearPin(struct gpio_pin *p)
35 # define GPIO_PIN_TOGGLE_PIN(ns, p) int32_t gpioPin_togglePin(struct gpio_pin *p)
36 # define GPIO_PIN_GET_VALUE(ns, p) bool gpioPin_getValue(struct gpio_pin *p)
37 #else
38 # define GPIO_OPS(ns) const struct gpio_ops ns##_gpio_ops = { \
39  .gpio_init = ns##_gpio_init, \
40  .gpio_deinit = ns##_gpio_deinit, \
41  .gpioPin_init = ns##_gpioPin_init, \
42  .gpioPin_deinit = ns##_gpioPin_deinit, \
43  .gpioPin_enableInterrupt = ns##_gpioPin_enableInterrupt, \
44  .gpioPin_disableInterrupt = ns##_gpioPin_disableInterrupt, \
45  .gpioPin_setCallback = ns##_gpioPin_setCallback, \
46  .gpioPin_setDirection = ns##_gpioPin_setDirection, \
47  .gpioPin_setSetting = ns##_gpioPin_setSetting, \
48  .gpioPin_SchmittTrigger = ns##_gpioPin_SchmittTrigger, \
49  .gpioPin_setValue = ns##_gpioPin_setValue, \
50  .gpioPin_setPin = ns##_gpioPin_setPin, \
51  .gpioPin_clearPin = ns##_gpioPin_clearPin, \
52  .gpioPin_togglePin = ns##_gpioPin_togglePin, \
53  .gpioPin_getValue = ns##_gpioPin_getValue \
54 }
55 # define GPIO_INIT_DEV(ns) .gen.ops = &ns##_gpio_ops,
56 # define GPIO_INIT(ns, index) static struct gpio *ns##_gpio_init(uint32_t index)
57 # define GPIO_DEINIT(ns, g) static int32_t ns##_gpio_deinit(struct gpio *g)
58 # define GPIO_PIN_INIT(ns, g, p, dir, setting) static struct gpio_pin *ns##_gpioPin_init(struct gpio *g, uint32_t p, enum gpio_direction dir, enum gpio_setting setting)
59 # define GPIO_PIN_DEINIT(ns, p) static int32_t ns##_gpioPin_deinit(struct gpio_pin *p)
60 # define GPIO_PIN_ENABLE_INTERRUPT(ns, p) static int32_t ns##_gpioPin_enableInterrupt(struct gpio_pin *p)
61 # define GPIO_PIN_DISABLE_INTERRUPT(ns, p) static int32_t ns##_gpioPin_disableInterrupt(struct gpio_pin *p)
62 # define GPIO_PIN_SET_CALLBACK(ns, p, callback, data, inter) static int32_t ns##_gpioPin_setCallback(struct gpio_pin *p, bool (*callback)(struct gpio_pin *pin, uint32_t pinID, void *data), void *data, enum gpio_interrupt inter)
63 # define GPIO_PIN_SET_DIRECTION(ns, p, dir) static int32_t ns##_gpioPin_setDirection(struct gpio_pin *p, enum gpio_direction dir)
64 # define GPIO_PIN_SET_SETTING(ns, p, setting) static int32_t ns##_gpioPin_setSetting(struct gpio_pin *p, enum gpio_setting setting)
65 # define GPIO_PIN_SCHMITT_TRIGGER(ns, p, schmitt) static int32_t ns##_gpioPin_SchmittTrigger(struct gpio_pin *p, bool schmitt)
66 # define GPIO_PIN_SET_VALUE(ns, p, value) static int32_t ns##_gpioPin_setValue(struct gpio_pin *p, bool value)
67 # define GPIO_PIN_SET_PIN(ns, p) static int32_t ns##_gpioPin_setPin(struct gpio_pin *p)
68 # define GPIO_PIN_CLEAR_PIN(ns, p) static int32_t ns##_gpioPin_clearPin(struct gpio_pin *p)
69 # define GPIO_PIN_TOGGLE_PIN(ns, p) int32_t ns##_gpioPin_togglePin(struct gpio_pin *p)
70 # define GPIO_PIN_GET_VALUE(ns, p) static bool ns##_gpioPin_getValue(struct gpio_pin *p)
71 #endif
72 #endif
gpio_genericInit
int32_t gpio_genericInit(struct gpio *gpio)
hal.h
HAL_DEFINE_GLOBAL_ARRAY
HAL_DEFINE_GLOBAL_ARRAY(gpio)