Loading...
Searching...
No Matches
vbus_gpio
// vi:set ft=cpp: -*- Mode: C++ -*-
/*
* (c) 2011 Adam Lackorzynski <adam@os.inf.tu-dresden.de>
* economic rights: Technische Universität Dresden (Germany)
*
* License: see LICENSE.spdx (in this directory or the directories above)
*/
#pragma once
#include <l4/vbus/vbus>
#include <l4/vbus/vbus_gpio.h>
namespace L4vbus {
class Gpio_pin : public Device
{
public:
Gpio_pin(Device const &dev, unsigned pin)
: Device(dev), _pin(pin)
{}
int get() const
{
return l4vbus_gpio_get(_bus.cap(), _dev, _pin);
}
int set(int value) const
{
return l4vbus_gpio_set(_bus.cap(), _dev, _pin, value);
}
int setup(unsigned mode, unsigned value) const
{
return l4vbus_gpio_setup(_bus.cap(), _dev, _pin, mode, value);
}
int config_pull(unsigned mode) const
{
return l4vbus_gpio_config_pull(_bus.cap(), _dev, _pin, mode);
}
int config_pad(unsigned func, unsigned value) const
{
return l4vbus_gpio_config_pad(_bus.cap(), _dev, _pin, func, value);
}
int config_get(unsigned func, unsigned *value) const
{
return l4vbus_gpio_config_get(_bus.cap(), _dev, _pin, func, value);
}
int to_irq() const
{
return l4vbus_gpio_to_irq(_bus.cap(), _dev, _pin);
}
unsigned pin() const { return _pin; }
protected:
Gpio_pin() {}
unsigned _pin;
};
class Gpio_module : public Device
{
public:
Gpio_module(Device dev)
: Device(dev)
{}
struct Pin_slice
{
Pin_slice(unsigned offset, unsigned mask) : offset(offset), mask(mask) {}
unsigned offset, mask;
};
int setup(Pin_slice const &mask, unsigned mode, unsigned value) const
{
return l4vbus_gpio_multi_setup(_bus.cap(), _dev, mask.offset, mask.mask,
mode, value);
}
int config_pad(Pin_slice const &mask, unsigned func, unsigned value) const
{
return l4vbus_gpio_multi_config_pad(_bus.cap(), _dev, mask.offset,
mask.mask, func, value);
}
int get(unsigned offset, unsigned *data) const
{
return l4vbus_gpio_multi_get(_bus.cap(), _dev, offset, data);
}
int set(Pin_slice const &mask, unsigned data)
{
return l4vbus_gpio_multi_set(_bus.cap(), _dev, mask.offset,
mask.mask, data);
}
Gpio_pin pin(unsigned pin) const
{
return Gpio_pin(*this, pin);
}
protected:
Gpio_module() {}
};
}
L4vbus::Device::Device
Device()
Construct a new vbus device using the NULL device L4VBUS_NULL.
Definition vbus:89
L4vbus::Device::_dev
l4vbus_device_handle_t _dev
The device handle for this device.
Definition vbus:247
L4vbus::Device::_bus
L4::Cap< Vbus > _bus
The Vbus capability where this device is located on.
Definition vbus:245
L4vbus::Gpio_module
A Gpio_module groups multiple GPIO pins together.
Definition vbus_gpio:134
L4vbus::Gpio_module::setup
int setup(Pin_slice const &mask, unsigned mode, unsigned value) const
Configure function of multiple GPIO pins at once.
Definition vbus_gpio:166
L4vbus::Gpio_module::config_pad
int config_pad(Pin_slice const &mask, unsigned func, unsigned value) const
Hardware specific configuration function for multiple GPIO pins.
Definition vbus_gpio:185
L4vbus::Gpio_module::get
int get(unsigned offset, unsigned *data) const
Read values of multiple GPIO pins at once.
Definition vbus_gpio:201
L4vbus::Gpio_module::set
int set(Pin_slice const &mask, unsigned data)
Set multiple GPIO output pins at once.
Definition vbus_gpio:217
L4vbus::Gpio_module::pin
Gpio_pin pin(unsigned pin) const
Get Gpio_pin for a specific pin of this Gpio_module.
Definition vbus_gpio:229
L4vbus::Gpio_pin
A GPIO pin.
Definition vbus_gpio:27
L4vbus::Gpio_pin::set
int set(int value) const
Set GPIO output pin.
Definition vbus_gpio:49
L4vbus::Gpio_pin::config_get
int config_get(unsigned func, unsigned *value) const
Read hardware specific configuration.
Definition vbus_gpio:102
L4vbus::Gpio_pin::get
int get() const
Read value of GPIO input pin.
Definition vbus_gpio:38
L4vbus::Gpio_pin::to_irq
int to_irq() const
Create IRQ for GPIO pin.
Definition vbus_gpio:112
L4vbus::Gpio_pin::config_pull
int config_pull(unsigned mode) const
Generic function to set pull up/down mode.
Definition vbus_gpio:75
L4vbus::Gpio_pin::pin
unsigned pin() const
Get pin number.
Definition vbus_gpio:122
L4vbus::Gpio_pin::config_pad
int config_pad(unsigned func, unsigned value) const
Hardware specific configuration function.
Definition vbus_gpio:89
L4vbus::Gpio_pin::setup
int setup(unsigned mode, unsigned value) const
Configure the function of a GPIO pin.
Definition vbus_gpio:64
l4vbus_gpio_to_irq
int l4vbus_gpio_to_irq(l4_cap_idx_t vbus, l4vbus_device_handle_t handle, unsigned pin)
Create IRQ for GPIO pin.
l4vbus_gpio_set
int l4vbus_gpio_set(l4_cap_idx_t vbus, l4vbus_device_handle_t handle, unsigned pin, int value)
Set GPIO output pin.
l4vbus_gpio_multi_set
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.
l4vbus_gpio_setup
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.
l4vbus_gpio_config_pull
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_gpio_multi_config_pad
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.
l4vbus_gpio_config_get
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.
l4vbus_gpio_multi_setup
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.
l4vbus_gpio_config_pad
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.
l4vbus_gpio_multi_get
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.
l4vbus_gpio_get
int l4vbus_gpio_get(l4_cap_idx_t vbus, l4vbus_device_handle_t handle, unsigned pin)
Read value of GPIO input pin.
L4vbus
C++ interface of the Vbus API.
Definition vbus:40
L4vbus::Gpio_module::Pin_slice
A slice of the pins provided by this module.
Definition vbus_gpio:147