L4Re - L4 Runtime Environment
vbus_gpio
1 // vi:ft=cpp
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 
15 namespace L4vbus {
16 
22 class Gpio_pin : public Device
23 {
24 public:
25  Gpio_pin(Device const &dev, unsigned pin)
26  : Device(dev), _pin(pin)
27  {}
28 
34  int get() const
35  {
36  return l4vbus_gpio_get(_bus.cap(), _dev, _pin);
37  }
38 
45  int set(int value) const
46  {
47  return l4vbus_gpio_set(_bus.cap(), _dev, _pin, value);
48  }
49 
60  int setup(unsigned mode, unsigned value) const
61  {
62  return l4vbus_gpio_setup(_bus.cap(), _dev, _pin, mode, value);
63  }
64 
71  int config_pull(unsigned mode) const
72  {
73  return l4vbus_gpio_config_pull(_bus.cap(), _dev, _pin, mode);
74  }
75 
85  int config_pad(unsigned func, unsigned value) const
86  {
87  return l4vbus_gpio_config_pad(_bus.cap(), _dev, _pin, func, value);
88  }
89 
98  int config_get(unsigned func, unsigned *value) const
99  {
100  return l4vbus_gpio_config_get(_bus.cap(), _dev, _pin, func, value);
101  }
102 
108  int to_irq() const
109  {
110  return l4vbus_gpio_to_irq(_bus.cap(), _dev, _pin);
111  }
112 
118  unsigned pin() const { return _pin; }
119 
120 protected:
121  Gpio_pin() {}
122  unsigned _pin;
123 };
124 
129 class Gpio_module : public Device
130 {
131 public:
132  Gpio_module(Device dev)
133  : Device(dev)
134  {}
135 
142  struct Pin_slice
143  {
144  Pin_slice(unsigned offset, unsigned mask) : offset(offset), mask(mask) {}
145  unsigned offset, mask;
146  };
147 
162  int setup(Pin_slice const &mask, unsigned mode, unsigned value) const
163  {
164  return l4vbus_gpio_multi_setup(_bus.cap(), _dev, mask.offset, mask.mask,
165  mode, value);
166  }
167 
181  int config_pad(Pin_slice const &mask, unsigned func, unsigned value) const
182  {
183  return l4vbus_gpio_multi_config_pad(_bus.cap(), _dev, mask.offset,
184  mask.mask, func, value);
185  }
186 
197  int get(unsigned offset, unsigned *data) const
198  {
199  return l4vbus_gpio_multi_get(_bus.cap(), _dev, offset, data);
200  }
201 
213  int set(Pin_slice const &mask, unsigned data)
214  {
215  return l4vbus_gpio_multi_set(_bus.cap(), _dev, mask.offset,
216  mask.mask, data);
217  }
218 
225  Gpio_pin pin(unsigned pin) const
226  {
227  return Gpio_pin(*this, pin);
228  }
229 
230 protected:
231  Gpio_module() {}
232 };
233 
234 }
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.
A GPIO pin.
Definition: vbus_gpio:22
int to_irq() const
Create IRQ for GPIO pin.
Definition: vbus_gpio:108
int config_get(unsigned func, unsigned *value) const
Read hardware specific configuration.
Definition: vbus_gpio:98
Device on a L4vbus::Vbus.
Definition: vbus:71
int config_pad(Pin_slice const &mask, unsigned func, unsigned value) const
Hardware specific configuration function for multiple GPIO pins.
Definition: vbus_gpio:181
int setup(Pin_slice const &mask, unsigned mode, unsigned value) const
Configure function of multiple GPIO pins at once.
Definition: vbus_gpio:162
unsigned pin() const
Get pin number.
Definition: vbus_gpio:118
int config_pad(unsigned func, unsigned value) const
Hardware specific configuration function.
Definition: vbus_gpio:85
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_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_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_config_pull(l4_cap_idx_t vbus, l4vbus_device_handle_t handle, unsigned pin, unsigned mode)
Generic function to set pull up/down mode.
l4vbus_device_handle_t _dev
The device handle for this device.
Definition: vbus:222
int setup(unsigned mode, unsigned value) const
Configure the function of a GPIO pin.
Definition: vbus_gpio:60
L4::Cap< Vbus > _bus
Definition: vbus:220
Definition: vbus:38
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.
Gpio_pin pin(unsigned pin) const
Get Gpio_pin for a specific pin of this Gpio_module.
Definition: vbus_gpio:225
int l4vbus_gpio_get(l4_cap_idx_t vbus, l4vbus_device_handle_t handle, unsigned pin)
Read value of GPIO input pin.
A Gpio_module groups multiple GPIO pins together.
Definition: vbus_gpio:129
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_pad(l4_cap_idx_t vbus, l4vbus_device_handle_t handle, unsigned pin, unsigned func, unsigned value)
Hardware specific configuration function.
int config_pull(unsigned mode) const
Generic function to set pull up/down mode.
Definition: vbus_gpio:71
int l4vbus_gpio_to_irq(l4_cap_idx_t vbus, l4vbus_device_handle_t handle, unsigned pin)
Create IRQ for GPIO pin.
A slice of the pins provided by this module.
Definition: vbus_gpio:142
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.