RADLib
RADical C++ application framework

RADDevice covers common embedded Linux device control surfaces through file-descriptor and ioctl-friendly wrappers in the RADDevice namespace. Each class targets a standard Linux sysfs/devfs surface, and all of them accept a DevicePaths struct so real device roots can be swapped for test fixtures.

GpioPin drives sysfs GPIO export/unexport, direction (GpioDirection), edge mode (GpioEdge), and value read/write. I2CDevice opens /dev/i2c-* and selects a 7-bit address via the I2C_SLAVE ioctl for read()/write(). SPIDevice opens /dev/spidev*, applies mode/bits/speed with configure(), and runs full-duplex transfer() calls through SPI_IOC_MESSAGE. PwmChannel exports a sysfs PWM channel and sets period, duty cycle, and enable state. AdcChannel reads IIO raw, scale, and scaled samples. Watchdog opens /dev/watchdogN and issues keepAlive() pings, and Led reads and writes sysfs LED brightness. The free functions listLeds() and listIioDevices() enumerate available LED and IIO device names.

Read-style calls that can fail return RADCore::RADResult<T> (for example GpioPin::readValue(), AdcChannel::readRaw(), Led::brightness()), while setup calls take an optional std::string* error out-parameter.

Core features

  • GpioPin for sysfs GPIO export, direction, edge, and value.
  • I2CDevice for /dev/i2c-* with I2C_SLAVE ioctl.
  • SPIDevice for /dev/spidev* with SPI ioctl configuration and transfers.
  • PwmChannel for sysfs PWM period, duty, and enable.
  • AdcChannel for IIO raw, scale, and scaled samples.
  • Watchdog for /dev/watchdog* keepalive ioctl.
  • Led for sysfs LED brightness, plus listLeds()/listIioDevices().

The public API is intentionally file-descriptor and ioctl friendly so future RADKernel drivers can expose the same application-facing model.

Example:

std::string error;
led.exportPin(&error);
led.setDirection(RADDevice::GpioDirection::Out, &error);
led.writeValue(true, &error);
if (sensor.open(1, 0x76, {}, &error)) {
sensor.write({0xF7});
std::vector<uint8_t> pressure = sensor.read(3);
}
GPIO sysfs helper.
Definition: RADDevice.h:104
Parity-free I2C device wrapper using /dev/i2c-* and I2C_SLAVE ioctl.
Definition: RADDevice.h:54
bool open(int bus, int address, const DevicePaths &paths={}, std::string *error=nullptr)
Opens bus number and selects 7-bit address.
ssize_t write(const std::vector< uint8_t > &bytes)
Writes bytes to the selected device.
std::vector< uint8_t > read(size_t count)
Reads bytes from the selected device.