L4Re Operating System Framework
Interface and Usage Documentation
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
vbus_gpio
1// vi:set ft=cpp: -*- Mode: C++ -*-
2/*
3 * (c) 2011 Adam Lackorzynski <adam@os.inf.tu-dresden.de>
4 * economic rights: Technische Universität Dresden (Germany)
5 *
6 * License: see LICENSE.spdx (in this directory or the directories above)
7 */
8#pragma once
9
10#include <l4/vbus/vbus>
11#include <l4/vbus/vbus_gpio.h>
12
19namespace L4vbus {
20
26class Gpio_pin : public Device
27{
28public:
29 Gpio_pin(Device const &dev, unsigned pin)
30 : Device(dev), _pin(pin)
31 {}
32
38 int get() const
39 {
40 return l4vbus_gpio_get(_bus.cap(), _dev, _pin);
41 }
42
49 int set(int value) const
50 {
51 return l4vbus_gpio_set(_bus.cap(), _dev, _pin, value);
52 }
53
64 int setup(unsigned mode, unsigned value) const
65 {
66 return l4vbus_gpio_setup(_bus.cap(), _dev, _pin, mode, value);
67 }
68
75 int config_pull(unsigned mode) const
76 {
77 return l4vbus_gpio_config_pull(_bus.cap(), _dev, _pin, mode);
78 }
79
89 int config_pad(unsigned func, unsigned value) const
90 {
91 return l4vbus_gpio_config_pad(_bus.cap(), _dev, _pin, func, value);
92 }
93
102 int config_get(unsigned func, unsigned *value) const
103 {
104 return l4vbus_gpio_config_get(_bus.cap(), _dev, _pin, func, value);
105 }
106
112 int to_irq() const
113 {
114 return l4vbus_gpio_to_irq(_bus.cap(), _dev, _pin);
115 }
116
122 unsigned pin() const { return _pin; }
123
124protected:
125 Gpio_pin() {}
126 unsigned _pin;
127};
128
133class Gpio_module : public Device
134{
135public:
137 : Device(dev)
138 {}
139
147 {
148 Pin_slice(unsigned offset, unsigned mask) : offset(offset), mask(mask) {}
149 unsigned offset, mask;
150 };
151
166 int setup(Pin_slice const &mask, unsigned mode, unsigned value) const
167 {
168 return l4vbus_gpio_multi_setup(_bus.cap(), _dev, mask.offset, mask.mask,
169 mode, value);
170 }
171
185 int config_pad(Pin_slice const &mask, unsigned func, unsigned value) const
186 {
187 return l4vbus_gpio_multi_config_pad(_bus.cap(), _dev, mask.offset,
188 mask.mask, func, value);
189 }
190
201 int get(unsigned offset, unsigned *data) const
202 {
203 return l4vbus_gpio_multi_get(_bus.cap(), _dev, offset, data);
204 }
205
217 int set(Pin_slice const &mask, unsigned data)
218 {
219 return l4vbus_gpio_multi_set(_bus.cap(), _dev, mask.offset,
220 mask.mask, data);
221 }
222
229 Gpio_pin pin(unsigned pin) const
230 {
231 return Gpio_pin(*this, pin);
232 }
233
234protected:
235 Gpio_module() {}
236};
237
238}
Device on a L4vbus::Vbus.
Definition vbus:84
Device()
Construct a new vbus device using the NULL device L4VBUS_NULL.
Definition vbus:89
l4vbus_device_handle_t _dev
The device handle for this device.
Definition vbus:247
L4::Cap< Vbus > _bus
The Vbus capability where this device is located on.
Definition vbus:245
A Gpio_module groups multiple GPIO pins together.
Definition vbus_gpio:134
int setup(Pin_slice const &mask, unsigned mode, unsigned value) const
Configure function of multiple GPIO pins at once.
Definition vbus_gpio:166
int config_pad(Pin_slice const &mask, unsigned func, unsigned value) const
Hardware specific configuration function for multiple GPIO pins.
Definition vbus_gpio:185
int get(unsigned offset, unsigned *data) const
Read values of multiple GPIO pins at once.
Definition vbus_gpio:201
int set(Pin_slice const &mask, unsigned data)
Set multiple GPIO output pins at once.
Definition vbus_gpio:217
Gpio_pin pin(unsigned pin) const
Get Gpio_pin for a specific pin of this Gpio_module.
Definition vbus_gpio:229
A GPIO pin.
Definition vbus_gpio:27
int set(int value) const
Set GPIO output pin.
Definition vbus_gpio:49
int config_get(unsigned func, unsigned *value) const
Read hardware specific configuration.
Definition vbus_gpio:102
int get() const
Read value of GPIO input pin.
Definition vbus_gpio:38
int to_irq() const
Create IRQ for GPIO pin.
Definition vbus_gpio:112
int config_pull(unsigned mode) const
Generic function to set pull up/down mode.
Definition vbus_gpio:75
unsigned pin() const
Get pin number.
Definition vbus_gpio:122
int config_pad(unsigned func, unsigned value) const
Hardware specific configuration function.
Definition vbus_gpio:89
int setup(unsigned mode, unsigned value) const
Configure the function of a GPIO pin.
Definition vbus_gpio:64
int l4vbus_gpio_to_irq(l4_cap_idx_t vbus, l4vbus_device_handle_t handle, unsigned pin)
Create IRQ for GPIO pin.
int l4vbus_gpio_set(l4_cap_idx_t vbus, l4vbus_device_handle_t handle, unsigned pin, int value)
Set GPIO output pin.
int l4vbus_gpio_multi_set(l4_cap_idx_t vbus, l4vbus_device_handle_t handle, unsigned offset, unsigned mask, unsigned data)
Set multiple GPIO output pins at once.
int l4vbus_gpio_setup(l4_cap_idx_t vbus, l4vbus_device_handle_t handle, unsigned pin, unsigned mode, int value)
Configure the function of a GPIO pin.
int l4vbus_gpio_config_pull(l4_cap_idx_t vbus, l4vbus_device_handle_t handle, unsigned pin, unsigned mode)
Generic function to set pull up/down mode.
int l4vbus_gpio_multi_config_pad(l4_cap_idx_t vbus, l4vbus_device_handle_t handle, unsigned offset, unsigned mask, unsigned func, unsigned value)
Hardware specific configuration function for multiple GPIO pins.
int l4vbus_gpio_config_get(l4_cap_idx_t vbus, l4vbus_device_handle_t handle, unsigned pin, unsigned func, unsigned *value)
Read hardware specific configuration.
int l4vbus_gpio_multi_setup(l4_cap_idx_t vbus, l4vbus_device_handle_t handle, unsigned offset, unsigned mask, unsigned mode, unsigned value)
Configure function of multiple GPIO pins at once.
int l4vbus_gpio_config_pad(l4_cap_idx_t vbus, l4vbus_device_handle_t handle, unsigned pin, unsigned func, unsigned value)
Hardware specific configuration function.
int l4vbus_gpio_multi_get(l4_cap_idx_t vbus, l4vbus_device_handle_t handle, unsigned offset, unsigned *data)
Read values of multiple GPIO pins at once.
int l4vbus_gpio_get(l4_cap_idx_t vbus, l4vbus_device_handle_t handle, unsigned pin)
Read value of GPIO input pin.
C++ interface of the Vbus API.
Definition vbus:40
A slice of the pins provided by this module.
Definition vbus_gpio:147