L4Re Operating System Framework – Interface and Usage Documentation
Loading...
Searching...
No Matches
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 * This file is part of TUD:OS and distributed under the terms of the
7 * GNU General Public License 2.
8 * Please see the COPYING-GPL-2 file for details.
9 */
10#pragma once
11
12#include <l4/vbus/vbus>
13#include <l4/vbus/vbus_gpio.h>
14
21namespace L4vbus {
22
28class Gpio_pin : public Device
29{
30public:
31 Gpio_pin(Device const &dev, unsigned pin)
32 : Device(dev), _pin(pin)
33 {}
34
40 int get() const
41 {
42 return l4vbus_gpio_get(_bus.cap(), _dev, _pin);
43 }
44
51 int set(int value) const
52 {
53 return l4vbus_gpio_set(_bus.cap(), _dev, _pin, value);
54 }
55
66 int setup(unsigned mode, unsigned value) const
67 {
68 return l4vbus_gpio_setup(_bus.cap(), _dev, _pin, mode, value);
69 }
70
77 int config_pull(unsigned mode) const
78 {
79 return l4vbus_gpio_config_pull(_bus.cap(), _dev, _pin, mode);
80 }
81
91 int config_pad(unsigned func, unsigned value) const
92 {
93 return l4vbus_gpio_config_pad(_bus.cap(), _dev, _pin, func, value);
94 }
95
104 int config_get(unsigned func, unsigned *value) const
105 {
106 return l4vbus_gpio_config_get(_bus.cap(), _dev, _pin, func, value);
107 }
108
114 int to_irq() const
115 {
116 return l4vbus_gpio_to_irq(_bus.cap(), _dev, _pin);
117 }
118
124 unsigned pin() const { return _pin; }
125
126protected:
127 Gpio_pin() {}
128 unsigned _pin;
129};
130
135class Gpio_module : public Device
136{
137public:
139 : Device(dev)
140 {}
141
149 {
150 Pin_slice(unsigned offset, unsigned mask) : offset(offset), mask(mask) {}
151 unsigned offset, mask;
152 };
153
168 int setup(Pin_slice const &mask, unsigned mode, unsigned value) const
169 {
170 return l4vbus_gpio_multi_setup(_bus.cap(), _dev, mask.offset, mask.mask,
171 mode, value);
172 }
173
187 int config_pad(Pin_slice const &mask, unsigned func, unsigned value) const
188 {
189 return l4vbus_gpio_multi_config_pad(_bus.cap(), _dev, mask.offset,
190 mask.mask, func, value);
191 }
192
203 int get(unsigned offset, unsigned *data) const
204 {
205 return l4vbus_gpio_multi_get(_bus.cap(), _dev, offset, data);
206 }
207
219 int set(Pin_slice const &mask, unsigned data)
220 {
221 return l4vbus_gpio_multi_set(_bus.cap(), _dev, mask.offset,
222 mask.mask, data);
223 }
224
231 Gpio_pin pin(unsigned pin) const
232 {
233 return Gpio_pin(*this, pin);
234 }
235
236protected:
237 Gpio_module() {}
238};
239
240}
Device on a L4vbus::Vbus.
Definition vbus:86
Device()
Construct a new vbus device using the NULL device L4VBUS_NULL.
Definition vbus:91
l4vbus_device_handle_t _dev
The device handle for this device.
Definition vbus:249
L4::Cap< Vbus > _bus
The Vbus capability where this device is located on.
Definition vbus:247
A Gpio_module groups multiple GPIO pins together.
Definition vbus_gpio:136
int setup(Pin_slice const &mask, unsigned mode, unsigned value) const
Configure function of multiple GPIO pins at once.
Definition vbus_gpio:168
int config_pad(Pin_slice const &mask, unsigned func, unsigned value) const
Hardware specific configuration function for multiple GPIO pins.
Definition vbus_gpio:187
int get(unsigned offset, unsigned *data) const
Read values of multiple GPIO pins at once.
Definition vbus_gpio:203
int set(Pin_slice const &mask, unsigned data)
Set multiple GPIO output pins at once.
Definition vbus_gpio:219
Gpio_pin pin(unsigned pin) const
Get Gpio_pin for a specific pin of this Gpio_module.
Definition vbus_gpio:231
A GPIO pin.
Definition vbus_gpio:29
int set(int value) const
Set GPIO output pin.
Definition vbus_gpio:51
int config_get(unsigned func, unsigned *value) const
Read hardware specific configuration.
Definition vbus_gpio:104
int get() const
Read value of GPIO input pin.
Definition vbus_gpio:40
int to_irq() const
Create IRQ for GPIO pin.
Definition vbus_gpio:114
int config_pull(unsigned mode) const
Generic function to set pull up/down mode.
Definition vbus_gpio:77
unsigned pin() const
Get pin number.
Definition vbus_gpio:124
int config_pad(unsigned func, unsigned value) const
Hardware specific configuration function.
Definition vbus_gpio:91
int setup(unsigned mode, unsigned value) const
Configure the function of a GPIO pin.
Definition vbus_gpio:66
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:42
A slice of the pins provided by this module.
Definition vbus_gpio:149