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 ¶
- type ADCDriver
- type Bias
- type DACDriver
- type Driver
- type GPIODriver
- type PWMDriver
- type Registry
- func (r *Registry) ADC(id string) (ADCDriver, error)
- func (r *Registry) CloseAll() error
- func (r *Registry) DAC(id string) (DACDriver, error)
- func (r *Registry) GPIO(id string) (GPIODriver, error)
- func (r *Registry) PWM(id string) (PWMDriver, error)
- func (r *Registry) Serial(id string) (SerialDriver, error)
- type SerialDriver
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
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".
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.
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.
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.
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.