driver

package
v1.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 1, 2026 License: AGPL-3.0 Imports: 17 Imported by: 0

Documentation

Overview

Package driver is the OS-level abstraction for I/O resources. Each driver instance owns one opened kernel handle (a GPIO chip, an IIO device, a PWM chip, a serial port) and any thread that produces events from it. Implementations are build-tag-selected and created via family-specific constructors.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ADCDriver

type ADCDriver interface {
	Driver
	ReadAnalog(channel int) (float64, error)
}

ADCDriver handles analog inputs. Channels do not need per-channel acquisition.

func OpenADC

func OpenADC(devicePath string) (ADCDriver, error)

OpenADC opens the IIO device at devicePath (a sysfs directory). The path must exist and be a directory; the device's name file is read for logging but not required.

type Bias

type Bias string

Bias is the internal pull-resistor configuration of a GPIO input. "none" is a real electrical state (floating), not a sentinel for "unset".

const (
	BiasNone     Bias = "none"
	BiasPullup   Bias = "pullup"
	BiasPulldown Bias = "pulldown"
)

type DACDriver

type DACDriver interface {
	Driver
	// WriteAnalog writes the given voltage (millivolts) to the channel.
	WriteAnalog(channel int, mV float64) error
}

DACDriver handles true analog outputs (Digital-to-Analog Converter). Distinct from PWMDriver: a DAC sets a real voltage, while PWM produces a switched square wave whose average looks analog only after low-pass filtering by the connected load. Channels do not need per-channel acquisition — same shape as ADC, just inverse direction.

func OpenDAC

func OpenDAC(devicePath string) (DACDriver, error)

OpenDAC opens the IIO device at devicePath (a sysfs directory). The path must exist and be a directory; the device's name file is read for logging but not required.

type Driver

type Driver interface {
	Close() error // Close releases the kernel handle and any associated resources.
}

Driver is the base contract for interacting with hardware resources

type GPIODriver

type GPIODriver interface {
	Driver
	// ConfigureInput requests the line as input. Bias and debounceMs are line-wide properties.
	// Pass onEvent for edge reporting (always reports rising and falling); nil keeps the line event-free.
	ConfigureInput(line int, bias Bias, debounceMs int, onEvent func(rising bool)) error
	// ConfigureOutput requests the line as output.
	ConfigureOutput(line int) error
	ReadDigital(line int) (bool, error)
	WriteDigital(line int, value bool) error
}

GPIODriver handles digital I/O lines.

func OpenGPIO

func OpenGPIO(chipName string) (GPIODriver, error)

OpenGPIO acquires the chip handle for the named chip and returns a live cdev-backed GPIODriver. gpiocdev.NewChip accepts either a short name ("gpiochip0") or a full path ("/dev/gpiochip0").

type PWMDriver

type PWMDriver interface {
	Driver
	// Configure must be called once per channel before channel can be written to
	Configure(channel int, freqHz int) error
	// WriteAnalog takes duty cycle in [0.0, 1.0] (clampes outside the range)
	WriteAnalog(channel int, duty float64) error
}

PWMDriver handles analog outputs via pulse-width modulation.

func OpenPWM

func OpenPWM(chipDir string) (PWMDriver, error)

OpenPWM opens the PWM chip at chipDir (a sysfs directory). The path must exist and be a directory; individual channels are exported lazily in Configure.

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

Registry owns the set of opened drivers for one Engine, keyed by instance ID. Typed per family so a miswired manifest (e.g. GPIO id looked up as ADC) fails at registration, not at first runtime use.

func NewRegistry

func NewRegistry(m *engine.DeviceManifest) (*Registry, error)

NewRegistry opens every driver declared in the manifest. On any failure, drivers opened so far are closed before returning, so callers never see a partially-initialised Registry.

func (*Registry) ADC

func (r *Registry) ADC(id string) (ADCDriver, error)

func (*Registry) CloseAll

func (r *Registry) CloseAll() error

CloseAll shuts down every driver. Returns the first error encountered; keeps going on failures so no handle leaks.

func (*Registry) DAC

func (r *Registry) DAC(id string) (DACDriver, error)

func (*Registry) GPIO

func (r *Registry) GPIO(id string) (GPIODriver, error)

func (*Registry) PWM

func (r *Registry) PWM(id string) (PWMDriver, error)

func (*Registry) Serial

func (r *Registry) Serial(id string) (SerialDriver, error)

type SerialDriver

type SerialDriver interface {
	Driver
	// Read blocks until one line arrives (therefore takes context). Errors if another Read is in flight.
	Read(ctx context.Context) (string, error)
	// WatchRead installs onLine as the permanent line callback; onLine must be non-blocking.
	WatchRead(onLine func(line string)) error
	// Flush discards buffered input.
	Flush() error
	Write(data string) error
}

SerialDriver handles one serial port. Read and WatchRead share the same line stream with stealing semantics — an in-flight Read takes a line before the WatchRead callback.

func OpenSerial

func OpenSerial(port string, baud int) (SerialDriver, error)

OpenSerial opens the named port (8N1, 115200 if baud=0) and starts the reader goroutine.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL