adaptors

package
v2.5.0 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2025 License: Apache-2.0 Imports: 12 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithDigitalPinDebug added in v2.5.0

func WithDigitalPinDebug() digitalPinsDebugOption

WithDigitalPinDebug can be used to switch on debugging for SPI implementation.

func WithDigitalPinInitializer

func WithDigitalPinInitializer(pc digitalPinInitializer) digitalPinsInitializeOption

WithDigitalPinInitializer can be used to substitute the default initializer.

func WithGpioCdevAccess added in v2.5.0

func WithGpioCdevAccess() digitalPinsSystemSysfsOption

WithGpioCdevAccess can be used to change the default legacy sysfs implementation to the character device Kernel ABI, provided by the go-gpiocdev package.

func WithGpioDebounce

func WithGpioDebounce(pin string, period time.Duration) digitalPinsDebounceOption

WithGpioDebounce prepares the given input pin to be debounced on next initialize. This is working for inputs since Kernel 5.10, but will be ignored for outputs or with sysfs ABI.

func WithGpioEventOnBothEdges

func WithGpioEventOnBothEdges(pin string, handler func(lineOffset int, timestamp time.Duration, detectedEdge string,
	seqno uint32, lseqno uint32),
) digitalPinsEventOnBothEdgesOption

WithGpioEventOnBothEdges prepares the given input pin to be generate an event on rising and falling edges. This is working for inputs since Kernel 5.10, but will be ignored for outputs or with sysfs ABI.

func WithGpioEventOnFallingEdge

func WithGpioEventOnFallingEdge(pin string, handler func(lineOffset int, timestamp time.Duration, detectedEdge string,
	seqno uint32, lseqno uint32),
) digitalPinsEventOnFallingEdgeOption

WithGpioEventOnFallingEdge prepares the given input pin to be generate an event on falling edge. This is working for inputs since Kernel 5.10, but will be ignored for outputs or with sysfs ABI.

func WithGpioEventOnRisingEdge

func WithGpioEventOnRisingEdge(pin string, handler func(lineOffset int, timestamp time.Duration, detectedEdge string,
	seqno uint32, lseqno uint32),
) digitalPinsEventOnRisingEdgeOption

WithGpioEventOnRisingEdge prepares the given input pin to be generate an event on rising edge. This is working for inputs since Kernel 5.10, but will be ignored for outputs or with sysfs ABI.

func WithGpioPollForEdgeDetection added in v2.2.0

func WithGpioPollForEdgeDetection(
	pin string,
	pollInterval time.Duration,
	pollQuitChan chan struct{},
) digitalPinsPollForEdgeDetectionOption

WithGpioPollForEdgeDetection prepares the given input pin to use a discrete input pin polling function together with edge detection.

func WithGpioSysfsAccess added in v2.5.0

func WithGpioSysfsAccess() digitalPinsSystemSysfsOption

WithGpioSysfsAccess can be used to change the default character device implementation, provided by the go-gpiocdev package, to the legacy sysfs Kernel ABI.

func WithGpiosActiveLow

func WithGpiosActiveLow(pin string, otherPins ...string) digitalPinsActiveLowOption

WithGpiosActiveLow prepares the given pins for inverse reaction on next initialize. This is working for inputs and outputs.

func WithGpiosOpenDrain

func WithGpiosOpenDrain(pin string, otherPins ...string) digitalPinsOpenDrainOption

WithGpiosOpenDrain prepares the given output pins to be driven with open drain/collector on next initialize. This will be ignored for inputs or with sysfs ABI.

func WithGpiosOpenSource

func WithGpiosOpenSource(pin string, otherPins ...string) digitalPinsOpenSourceOption

WithGpiosOpenSource prepares the given output pins to be driven with open source/emitter on next initialize. This will be ignored for inputs or with sysfs ABI.

func WithGpiosPullDown

func WithGpiosPullDown(pin string, otherPins ...string) digitalPinsPullDownOption

WithGpiosPullDown prepares the given pins to be pulled down (high impedance to GND) on next initialize. This is working for inputs and outputs since Kernel 5.5, but will be ignored with sysfs ABI.

func WithGpiosPullUp

func WithGpiosPullUp(pin string, otherPins ...string) digitalPinsPullUpOption

WithGpiosPullUp prepares the given pins to be pulled up (high impedance to VDD) on next initialize. This is working for inputs and outputs since Kernel 5.5, but will be ignored with sysfs ABI.

func WithPWMDefaultPeriod added in v2.3.0

func WithPWMDefaultPeriod(periodNanoSec uint32) pwmPinsPeriodDefaultOption

WithPWMDefaultPeriod substitute the default period of 10 ms (100 Hz) for all created pins.

func WithPWMDefaultPeriodForPin added in v2.3.0

func WithPWMDefaultPeriodForPin(pin string, periodNanoSec uint32) pwmPinsDefaultPeriodForPinOption

WithPWMDefaultPeriodForPin substitute the default period of 10 ms (100 Hz) for the given pin. This option also overrides a default period given by the WithPWMDefaultPeriod() option. This is often needed for servo applications, where the default period is 50Hz (20.000.000 ns).

func WithPWMMinimumDutyRate added in v2.3.0

func WithPWMMinimumDutyRate(dutyRate float64) pwmPinsDutyRateMinimumOption

WithPWMMinimumDutyRate substitute the default minimum duty rate of 1/period. The given limit only come into effect, if the rate is > 0, because a rate of 0.0 is always allowed.

func WithPWMMinimumPeriod added in v2.3.0

func WithPWMMinimumPeriod(periodNanoSec uint32) pwmPinsPeriodMinimumOption

WithPWMMinimumPeriod substitute the default minimum period limit of 0 nanoseconds.

func WithPWMNoDutyCycleAdjustment added in v2.3.0

func WithPWMNoDutyCycleAdjustment() pwmPinsAdjustDutyOnSetPeriodOption

WithPWMNoDutyCycleAdjustment switch off the automatic adjustment of duty cycle on setting the period.

func WithPWMPinInitializer

func WithPWMPinInitializer(pc pwmPinInitializer) pwmPinsInitializeOption

WithPWMPinInitializer substitute the default initializer.

func WithPWMPolarityInvertedIdentifier added in v2.3.0

func WithPWMPolarityInvertedIdentifier(identifier string) pwmPinsPolarityInvertedIdentifierOption

WithPWMPolarityInvertedIdentifier use the given identifier, which will replace the default "inversed".

func WithPWMServoAngleRangeForPin added in v2.3.0

func WithPWMServoAngleRangeForPin(pin string, minimum, maximum float64) pwmPinsServoAngleScaleForPinOption

WithPWMServoAngleRangeForPin set new values for range of angle for servo calls, which replaces the default 0.0-180.0° range.

func WithPWMServoDutyCycleRangeForPin added in v2.3.0

func WithPWMServoDutyCycleRangeForPin(pin string, minimum, maximum time.Duration) pwmPinsServoDutyScaleForPinOption

WithPWMServoDutyCycleRangeForPin set new values for range of duty cycle for servo calls, which replaces the default 0.5-2.5 ms range. The given duration values will be internally converted to nanoseconds.

func WithPWMUsePiBlaster added in v2.3.0

func WithPWMUsePiBlaster() pwmPinsUsePiBlasterPinOption

WithPWMUsePiBlaster substitute the default sysfs-implementation for PWM-pins by the implementation for pi-blaster.

func WithSpiDebug added in v2.5.0

func WithSpiDebug() spiBusDebugOption

WithSpiDebug can be used to switch on debugging for SPI implementation.

func WithSpiGpioAccess

func WithSpiGpioAccess(sclkPin, ncsPin, sdoPin, sdiPin string) spiBusDigitalPinsForSystemSpiOption

WithSpiGpioAccess can be used to switch the default SPI implementation to GPIO usage.

Types

type AnalogPinDefinition added in v2.5.0

type AnalogPinDefinition struct {
	Path       string
	W          bool   // writable
	ReadBufLen uint16 // readable if buffer > 0
}

type AnalogPinDefinitions added in v2.5.0

type AnalogPinDefinitions map[string]AnalogPinDefinition

type AnalogPinTranslator added in v2.5.0

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

func NewAnalogPinTranslator added in v2.5.0

func NewAnalogPinTranslator(sys *system.Accesser, pinDefinitions AnalogPinDefinitions) *AnalogPinTranslator

NewAnalogPinTranslator creates a new instance of a translator for analog pins, suitable for the most cases.

func (*AnalogPinTranslator) Translate added in v2.5.0

func (pt *AnalogPinTranslator) Translate(id string) (string, bool, uint16, error)

Translate returns the sysfs path for the given id.

type AnalogPinsAdaptor added in v2.3.0

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

AnalogPinsAdaptor is a adaptor for analog pins, normally used for composition in platforms. It is also usable for general sysfs access.

func NewAnalogPinsAdaptor added in v2.3.0

func NewAnalogPinsAdaptor(sys *system.Accesser, t analogPinTranslator) *AnalogPinsAdaptor

NewAnalogPinsAdaptor provides the access to analog pins of the board. Usually sysfs system drivers are used. The translator is used to adapt the pin header naming, which is given by user, to the internal file name nomenclature. This varies by each platform.

func (*AnalogPinsAdaptor) AnalogRead added in v2.3.0

func (a *AnalogPinsAdaptor) AnalogRead(id string) (int, error)

AnalogRead returns an analog value from specified pin or identifier, defined by the translation function.

func (*AnalogPinsAdaptor) AnalogWrite added in v2.3.0

func (a *AnalogPinsAdaptor) AnalogWrite(id string, val int) error

AnalogWrite writes an analog value to the specified pin or identifier, defined by the translation function.

func (*AnalogPinsAdaptor) Connect added in v2.3.0

func (a *AnalogPinsAdaptor) Connect() error

Connect prepare new connection to analog pins.

func (*AnalogPinsAdaptor) Finalize added in v2.3.0

func (a *AnalogPinsAdaptor) Finalize() error

Finalize closes connection to analog pins

type BusNumberValidator added in v2.5.0

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

func NewBusNumberValidator added in v2.5.0

func NewBusNumberValidator(validNumbers []int) *BusNumberValidator

NewBusNumberValidator creates a new instance for a bus number validator, used for I2C and SPI.

func (*BusNumberValidator) Validate added in v2.5.0

func (bnv *BusNumberValidator) Validate(busNr int) error

type CdevPin added in v2.5.0

type CdevPin struct {
	Chip uint8
	Line uint8
}

type DigitalPinDefinition added in v2.5.0

type DigitalPinDefinition struct {
	Sysfs int
	Cdev  CdevPin
}

type DigitalPinDefinitions added in v2.5.0

type DigitalPinDefinitions map[string]DigitalPinDefinition

type DigitalPinTranslator added in v2.5.0

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

func NewDigitalPinTranslator added in v2.5.0

func NewDigitalPinTranslator(sys *system.Accesser, pinDefinitions DigitalPinDefinitions) *DigitalPinTranslator

NewDigitalPinTranslator creates a new instance of a translator for digital GPIO pins, suitable for the most cases.

func (*DigitalPinTranslator) Translate added in v2.5.0

func (pt *DigitalPinTranslator) Translate(id string) (string, int, error)

Translate returns the chip and the line or for legacy sysfs usage the pin number from the given id.

type DigitalPinsAdaptor

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

DigitalPinsAdaptor is a adaptor for digital pins, normally used for composition in platforms.

func NewDigitalPinsAdaptor

func NewDigitalPinsAdaptor(
	sys *system.Accesser,
	t digitalPinTranslator,
	opts ...DigitalPinsOptionApplier,
) *DigitalPinsAdaptor

NewDigitalPinsAdaptor provides the access to digital pins of the board. It supports sysfs and cdev system drivers. This is decided by the given accesser. The translator is used to adapt the pin header naming, which is given by user, to the internal file name or chip/line nomenclature. This varies by each platform. If for some reasons the default initializer is not suitable, it can be given by the option "WithDigitalPinInitializer()". This is especially needed, if some values needs to be adjusted after the pin was created but before the pin is exported.

func (*DigitalPinsAdaptor) Connect

func (a *DigitalPinsAdaptor) Connect() error

Connect prepare new connection to digital pins.

func (*DigitalPinsAdaptor) DigitalPin

func (a *DigitalPinsAdaptor) DigitalPin(id string) (gobot.DigitalPinner, error)

DigitalPin returns a digital pin. If the pin is initially acquired, it is an input. Pin direction and other options can be changed afterwards by pin.ApplyOptions() at any time.

func (*DigitalPinsAdaptor) DigitalRead

func (a *DigitalPinsAdaptor) DigitalRead(id string) (int, error)

DigitalRead reads digital value from pin

func (*DigitalPinsAdaptor) DigitalWrite

func (a *DigitalPinsAdaptor) DigitalWrite(id string, val byte) error

DigitalWrite writes digital value to specified pin

func (*DigitalPinsAdaptor) Finalize

func (a *DigitalPinsAdaptor) Finalize() error

Finalize closes connection to digital pins

type DigitalPinsOptionApplier added in v2.5.0

type DigitalPinsOptionApplier interface {
	// contains filtered or unexported methods
}

DigitalPinsOptionApplier is the interface for digital adaptors options. This provides the possibility for change the platform behavior by the user when creating the platform, e.g. by "NewAdaptor()". The interface needs to be implemented by each configurable option type.

type I2cBusAdaptor

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

I2cBusAdaptor is a adaptor for i2c bus, normally used for composition in platforms.

func NewI2cBusAdaptor

func NewI2cBusAdaptor(sys *system.Accesser, v i2cBusNumberValidator, defaultBusNr int) *I2cBusAdaptor

NewI2cBusAdaptor provides the access to i2c buses of the board. The validator is used to check the bus number, which is given by user, to the abilities of the board.

func (*I2cBusAdaptor) Connect

func (a *I2cBusAdaptor) Connect() error

Connect prepares the connection to i2c buses.

func (*I2cBusAdaptor) DefaultI2cBus

func (a *I2cBusAdaptor) DefaultI2cBus() int

DefaultI2cBus returns the default i2c bus number for this platform.

func (*I2cBusAdaptor) Finalize

func (a *I2cBusAdaptor) Finalize() error

Finalize closes all i2c buses.

func (*I2cBusAdaptor) GetI2cConnection

func (a *I2cBusAdaptor) GetI2cConnection(address int, busNum int) (i2c.Connection, error)

GetI2cConnection returns a connection to a device on a specified i2c bus

type OneWireBusAdaptor added in v2.5.0

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

OneWireBusAdaptor is a adaptor for the 1-wire bus, normally used for composition in platforms. note: currently only one controller is supported by most platforms, but it would be possible to activate more, see https://forums.raspberrypi.com/viewtopic.php?t=65137

func NewOneWireBusAdaptor added in v2.5.0

func NewOneWireBusAdaptor(sys *system.Accesser) *OneWireBusAdaptor

NewOneWireBusAdaptor provides the access to 1-wire devices of the board.

func (*OneWireBusAdaptor) Connect added in v2.5.0

func (a *OneWireBusAdaptor) Connect() error

Connect prepares the connection to 1-wire devices.

func (*OneWireBusAdaptor) Finalize added in v2.5.0

func (a *OneWireBusAdaptor) Finalize() error

Finalize closes all 1-wire connections.

func (*OneWireBusAdaptor) GetOneWireConnection added in v2.5.0

func (a *OneWireBusAdaptor) GetOneWireConnection(familyCode byte, serialNumber uint64) (onewire.Connection, error)

GetOneWireConnection returns a 1-wire connection to a device with the given family code and serial number.

type PWMPinDefinition added in v2.5.0

type PWMPinDefinition struct {
	Dir       string
	DirRegexp string
	Channel   int
}

func (PWMPinDefinition) FindPWMDir added in v2.5.0

func (p PWMPinDefinition) FindPWMDir(sys *system.Accesser) (string, error)

type PWMPinDefinitions added in v2.5.0

type PWMPinDefinitions map[string]PWMPinDefinition

type PWMPinTranslator added in v2.5.0

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

func NewPWMPinTranslator added in v2.5.0

func NewPWMPinTranslator(sys *system.Accesser, pinDefinitions PWMPinDefinitions) *PWMPinTranslator

NewPWMPinTranslator creates a new instance of a PWM pin translator, suitable for the most cases.

func (*PWMPinTranslator) Translate added in v2.5.0

func (pt *PWMPinTranslator) Translate(id string) (string, int, error)

Translate returns the sysfs path and channel for the given id.

type PWMPinsAdaptor

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

PWMPinsAdaptor is a adaptor for PWM pins, normally used for composition in platforms.

func NewPWMPinsAdaptor

func NewPWMPinsAdaptor(sys *system.Accesser, t pwmPinTranslator, opts ...PwmPinsOptionApplier) *PWMPinsAdaptor

NewPWMPinsAdaptor provides the access to PWM pins of the board. It uses sysfs system drivers. The translator is used to adapt the pin header naming, which is given by user, to the internal file name nomenclature. This varies by each platform. If for some reasons the default initializer is not suitable, it can be given by the option "WithPWMPinInitializer()".

Further options:

"WithPWMDefaultPeriod"
"WithPWMPolarityInvertedIdentifier"
"WithPWMNoDutyCycleAdjustment"
"WithPWMDefaultPeriodForPin"
"WithPWMServoDutyCycleRangeForPin"
"WithPWMServoAngleRangeForPin"

func (*PWMPinsAdaptor) Connect

func (a *PWMPinsAdaptor) Connect() error

Connect prepare new connection to PWM pins.

func (*PWMPinsAdaptor) Finalize

func (a *PWMPinsAdaptor) Finalize() error

Finalize closes connection to PWM pins.

func (*PWMPinsAdaptor) PWMPin

func (a *PWMPinsAdaptor) PWMPin(id string) (gobot.PWMPinner, error)

PWMPin initializes the pin for PWM and returns matched pwmPin for specified pin number. It implements the PWMPinnerProvider interface.

func (*PWMPinsAdaptor) PwmWrite

func (a *PWMPinsAdaptor) PwmWrite(id string, val byte) error

PwmWrite writes a PWM signal to the specified pin. The given value is between 0 and 255.

func (*PWMPinsAdaptor) ServoWrite

func (a *PWMPinsAdaptor) ServoWrite(id string, angle byte) error

ServoWrite writes a servo signal to the specified pin. The given angle is between 0 and 180°.

func (*PWMPinsAdaptor) SetPeriod

func (a *PWMPinsAdaptor) SetPeriod(id string, period uint32) error

SetPeriod adjusts the period of the specified PWM pin immediately. If duty cycle is already set, also this value will be adjusted in the same ratio.

type PwmPinsOptionApplier added in v2.3.0

type PwmPinsOptionApplier interface {
	// contains filtered or unexported methods
}

PwmPinsOptionApplier needs to be implemented by each configurable option type

type SpiBusAdaptor

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

SpiBusAdaptor is a adaptor for SPI bus, normally used for composition in platforms.

func NewSpiBusAdaptor

func NewSpiBusAdaptor(
	sys *system.Accesser,
	v spiBusNumberValidator,
	busNum, chipNum, mode, bits int,
	maxSpeed int64,
	spiGpioPinnerProvider gobot.DigitalPinnerProvider,
	opts ...SpiBusOptionApplier,
) *SpiBusAdaptor

NewSpiBusAdaptor provides the access to SPI buses of the board. The validator is used to check the bus number (given by user) to the abilities of the board.

func (*SpiBusAdaptor) Connect

func (a *SpiBusAdaptor) Connect() error

Connect prepares the connection to SPI buses.

func (*SpiBusAdaptor) Finalize

func (a *SpiBusAdaptor) Finalize() error

Finalize closes all SPI connections.

func (*SpiBusAdaptor) GetSpiConnection

func (a *SpiBusAdaptor) GetSpiConnection(busNum, chipNum, mode, bits int, maxSpeed int64) (spi.Connection, error)

GetSpiConnection returns an spi connection to a device on a specified bus. Valid bus numbers range between 0 and 65536, valid chip numbers are 0 ... 255.

func (*SpiBusAdaptor) SpiDefaultBitCount

func (a *SpiBusAdaptor) SpiDefaultBitCount() int

SpiDefaultBitCount returns the default number of bits used for this platform.

func (*SpiBusAdaptor) SpiDefaultBusNumber

func (a *SpiBusAdaptor) SpiDefaultBusNumber() int

SpiDefaultBusNumber returns the default bus number for this platform.

func (*SpiBusAdaptor) SpiDefaultChipNumber

func (a *SpiBusAdaptor) SpiDefaultChipNumber() int

SpiDefaultChipNumber returns the default chip number for this platform.

func (*SpiBusAdaptor) SpiDefaultMaxSpeed

func (a *SpiBusAdaptor) SpiDefaultMaxSpeed() int64

SpiDefaultMaxSpeed returns the default maximal speed for this platform.

func (*SpiBusAdaptor) SpiDefaultMode

func (a *SpiBusAdaptor) SpiDefaultMode() int

SpiDefaultMode returns the default SPI mode for this platform.

type SpiBusOptionApplier added in v2.5.0

type SpiBusOptionApplier interface {
	// contains filtered or unexported methods
}

SpiBusOptionApplier is the interface for spi bus adaptor options. This provides the possibility for change the platform behavior by the user when creating the platform, e.g. by "NewAdaptor()". The interface needs to be implemented by each configurable option type.

Jump to

Keyboard shortcuts

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