DUDS
Distributed Update of Data from Something
duds::hardware::interface::linux Namespace Reference

A Linux specific library for communicating with external hardware. More...

Classes

class  DevI2c
 Implementation of the I2c interface using the Linux kernel's user-space support. More...
 
class  DevSmbus
 Implementation of the Smbus interface using the Linux kernel's user-space support. More...
 
struct  GpioDevGetLinehandleError
 An error was reported from a GPIO_GET_LINEHANDLE_IOCTL operation. More...
 
struct  GpioDevGetLineValuesError
 An error was reported from a GPIOHANDLE_GET_LINE_VALUES_IOCTL operation. More...
 
class  GpioDevPort
 A GPIO implementation using the Linux kernel's GPIO character devices. More...
 
struct  GpioDevPortError
 Base class for all errors specific to using the Linux GPIO character device. More...
 
struct  GpioDevSetLineValuesError
 An error was reported from a GPIOHANDLE_SET_LINE_VALUES_IOCTL operation. More...
 
class  GpioRequest
 An abstraction for using gpiohandle_request object(s). More...
 
class  IoGpioRequest
 Implements using two gpiohandle_requests object for working with multiple pins. More...
 
struct  PwmError
 
class  SingleGpioRequest
 Implements using a single gpiohandle_request object for working with a single pin. More...
 
class  SpiMasterSyncSerial
 A synchronous serial implementation using the SPI userspace interface provided by the Linux kernel. More...
 
class  SysFsPort
 A GPIO implementation using the Linux kernel's userspace interface in syfs. More...
 
class  SysPwm
 This is a Linux-only PWM driver that I need for my eclipse project. More...
 

Typedefs

typedef boost::error_info< struct Info_SysPwmChannel, int > SysPwmChannel
 
typedef boost::error_info< struct Info_SysPwmChip, int > SysPwmChip
 
typedef boost::error_info< struct Info_SysPwmDutyNs, long > SysPwmDutyNs
 
typedef boost::error_info< struct Info_SysPwmPeriodNs, long > SysPwmPeriodNs
 

Functions

static void AddOffset (gpiohandle_request &req, std::uint32_t offset)
 Adds a GPIO line offset to a gpiohandle_request object. More...
 
static void CloseIfOpen (gpiohandle_request &req)
 Closes the file descriptor in the request object if it appears to have a file, and then sets the descriptor to zero. More...
 
static int FindOffset (gpiohandle_request &req, std::uint32_t offset)
 Finds the array index that corresponds to the given offset. More...
 
static void GetInput (int chipFd, gpiohandle_data &result, gpiohandle_request &req)
 Requests input states from the kernel. More...
 
static void InitGpioHandleReq (gpiohandle_request &req, const std::string &consumer)
 Initializes a gpiohandle_request structure. More...
 
static bool RemoveOffset (gpiohandle_request &req, std::uint32_t offset)
 Removes a GPIO line offset from a gpiohandle_request object. More...
 
static void SetOutput (int chipFd, gpiohandle_request &req)
 Sets the output states for all the pins in the request object. More...
 

Variables

static const char * prefix = "/sys/class/gpio/gpio"
 
static const char * prefix = "/sys/class/pwm/pwmchip"
 

Detailed Description

A Linux specific library for communicating with external hardware.

Any code that is specific to both Linux and some particular processor or other hardware not abstracted by the kernel should be placed in a namespace named for that hardware under this namespace. Code directly in this name space must not be specific to any particular hardware by using user-space kernel interfaces.

Many of Linux's user-space interfaces are file based, like the sysfs filesystem. Should an I/O error occur while using a file, and the error requires an exception to be thrown, boost::exception should be used (all duds exceptions do), and boost::errinfo_file_name should be added with the name of the file.

Typedef Documentation

◆ SysPwmChannel

typedef boost::error_info<struct Info_SysPwmChannel, int> duds::hardware::interface::linux::SysPwmChannel

Definition at line 23 of file SysPwm.hpp.

◆ SysPwmChip

typedef boost::error_info<struct Info_SysPwmChip, int> duds::hardware::interface::linux::SysPwmChip

Definition at line 22 of file SysPwm.hpp.

◆ SysPwmDutyNs

typedef boost::error_info<struct Info_SysPwmDutyNs, long> duds::hardware::interface::linux::SysPwmDutyNs

Definition at line 27 of file SysPwm.hpp.

◆ SysPwmPeriodNs

typedef boost::error_info<struct Info_SysPwmPeriodNs, long> duds::hardware::interface::linux::SysPwmPeriodNs

Definition at line 25 of file SysPwm.hpp.

Function Documentation

◆ AddOffset()

static void duds::hardware::interface::linux::AddOffset ( gpiohandle_request &  req,
std::uint32_t  offset 
)
static

Adds a GPIO line offset to a gpiohandle_request object.

Parameters
reqThe request object that will hold the offset.
offsetThe offset to add. It will be placed at the end.

Definition at line 38 of file GpioDevPort.cpp.

Referenced by duds::hardware::interface::linux::IoGpioRequest::addInputOffset(), duds::hardware::interface::linux::IoGpioRequest::addOutputOffset(), duds::hardware::interface::linux::IoGpioRequest::inputOffset(), duds::hardware::interface::linux::IoGpioRequest::outputOffset(), and duds::hardware::interface::linux::IoGpioRequest::outputState().

◆ CloseIfOpen()

◆ FindOffset()

static int duds::hardware::interface::linux::FindOffset ( gpiohandle_request &  req,
std::uint32_t  offset 
)
static

Finds the array index that corresponds to the given offset.

Useful in cases where the two do not match, such as with IoGpioRequest.

Parameters
reqThe request object to search.
offsetThe pin offset to find.
Returns
The index into the lineoffsets array in req for offset, or -1 if the offset was not found.

Definition at line 58 of file GpioDevPort.cpp.

Referenced by duds::hardware::interface::linux::IoGpioRequest::inputState(), duds::hardware::interface::linux::IoGpioRequest::outputState(), and duds::hardware::interface::linux::IoGpioRequest::write().

◆ GetInput()

static void duds::hardware::interface::linux::GetInput ( int  chipFd,
gpiohandle_data &  result,
gpiohandle_request &  req 
)
static

Requests input states from the kernel.

If the request for using input rather than output has not yet been made, it will be made here. This is because it is valid to have set an input state, lose the access object, then create a new access object for the same pins, and assume the pins are still inputs. The request to use them as inputs, however, must be made again to the kernel.

Parameters
chipFdThe file descriptor for the GPIO device. Needed for the GPIO_GET_LINEHANDLE_IOCTL operation that will occur if any of the pins has not yet been configured as an input.
resultThe input states.
reqThe request object with the input pins.

Definition at line 118 of file GpioDevPort.cpp.

Referenced by duds::hardware::interface::linux::SingleGpioRequest::inputState(), duds::hardware::interface::linux::IoGpioRequest::inputState(), duds::hardware::interface::linux::SingleGpioRequest::read(), and duds::hardware::interface::linux::IoGpioRequest::read().

◆ InitGpioHandleReq()

static void duds::hardware::interface::linux::InitGpioHandleReq ( gpiohandle_request &  req,
const std::string &  consumer 
)
static

Initializes a gpiohandle_request structure.

Parameters
reqThe gpiohandle_request structure to be initialized.
consumerThe consumer name to place inside the gpiohandle_request.

Definition at line 25 of file GpioDevPort.cpp.

Referenced by duds::hardware::interface::linux::IoGpioRequest::IoGpioRequest(), and duds::hardware::interface::linux::SingleGpioRequest::SingleGpioRequest().

◆ RemoveOffset()

static bool duds::hardware::interface::linux::RemoveOffset ( gpiohandle_request &  req,
std::uint32_t  offset 
)
static

Removes a GPIO line offset from a gpiohandle_request object.

Parameters
reqThe request object that holds the offset.
offsetThe offset to remove. The offset at the end will take its place.
Returns
True if the item was found and removed, false otherwise.

Definition at line 74 of file GpioDevPort.cpp.

Referenced by duds::hardware::interface::linux::IoGpioRequest::inputOffset(), duds::hardware::interface::linux::IoGpioRequest::outputOffset(), and duds::hardware::interface::linux::IoGpioRequest::outputState().

◆ SetOutput()

static void duds::hardware::interface::linux::SetOutput ( int  chipFd,
gpiohandle_request &  req 
)
static

Sets the output states for all the pins in the request object.

If the request for using output rather than input has not yet been made, it will be made here. This is because it is valid to have set an output state, lose the access object, then create a new access object for the same pins, and assume the pins are still outputs. The request to use them as outputs, however, must be made again to the kernel.

Parameters
chipFdThe file descriptor for the GPIO device. Needed for the GPIO_GET_LINEHANDLE_IOCTL operation that will occur if any of the pins has not yet been configured as an output.
reqThe request object with the output pins and states. The default_values field is used for the output states, even when the pins are already configured as outputs.

Definition at line 151 of file GpioDevPort.cpp.

Referenced by duds::hardware::interface::linux::SingleGpioRequest::write(), and duds::hardware::interface::linux::IoGpioRequest::write().

Variable Documentation

◆ prefix [1/2]

const char* duds::hardware::interface::linux::prefix = "/sys/class/gpio/gpio"
static

Definition at line 17 of file SysFsPort.cpp.

◆ prefix [2/2]

const char* duds::hardware::interface::linux::prefix = "/sys/class/pwm/pwmchip"
static

Definition at line 20 of file SysPwm.cpp.