Documentation
¶
Overview ¶
The drivers include GPIO (digital), analog (via ads1115), serial, I2C at this point.
I have to admit these drivers are not the cleanest of interfaces that they could perhaps be.
Each of the said drivers can be put into mock mode for testing and development on a non-raspberry pi.
Index ¶
- Constants
- Variables
- func GetI2CDriver(bus string, addr int) (device *i2c.Device, err error)
- func ResetGPIO()
- func SetEventHandler(handler func(gpiocdev.LineEvent))
- type AnalogPin
- type DigitalPin
- type EventType
- type GPIO
- type GPIOCDev
- type GPIOCDevPin
- func (p *GPIOCDevPin) Close() error
- func (p *GPIOCDevPin) EventLoop(done chan any, callback func(evt gpiocdev.LineEvent))
- func (p *GPIOCDevPin) Get() (int, error)
- func (p *GPIOCDevPin) ID() string
- func (p *GPIOCDevPin) Index() int
- func (p *GPIOCDevPin) Off() error
- func (p *GPIOCDevPin) On() error
- func (p *GPIOCDevPin) Options() PinOptions
- func (p *GPIOCDevPin) Reconfigure(opts ...gpiocdev.LineConfigOption) error
- func (p *GPIOCDevPin) Set(value int) error
- func (p *GPIOCDevPin) Toggle() error
- type Pin
- type PinOptions
- type Serial
- type Transaction
- type VPIO
- func (v *VPIO[T]) ClearTransactions()
- func (v *VPIO[T]) Close() error
- func (v *VPIO[T]) Get(i int) (T, error)
- func (v *VPIO[T]) GetTransactions() []*Transaction[T]
- func (v *VPIO[T]) Open() error
- func (v *VPIO[T]) PlayTransactions(f func())
- func (v *VPIO[T]) Set(i int, val T) error
- func (v *VPIO[T]) SetPin(id string, i int, opts ...PinOptions) (Pin[T], error)
- func (v *VPIO[T]) StartRecording()
- func (v *VPIO[T]) StopRecording()
- type VPin
- type Value
Constants ¶
const PIN_COUNT = 64
PIN_COUNT provides the number of pins per VPIO bank
Variables ¶
var ( ErrOutOfRange = errors.New("pin out of range") ErrPinIsAnOutput = errors.New("can not set input pin") )
Functions ¶
func ResetGPIO ¶ added in v0.0.2
func ResetGPIO()
ResetGPIO clears all singleton instances (useful for testing)
func SetEventHandler ¶ added in v0.0.2
Types ¶
type GPIO ¶
type GPIOCDev ¶ added in v0.0.2
type GPIOCDev struct {
Chipname string
// contains filtered or unexported fields
}
GPIOCDev implements a GPIO controller using go-gpiocdev for real hardware
func GetGPIOCdev ¶ added in v0.0.2
func GetGPIOCdev() *GPIOCDev
GetGPIOCdev treats the GPIOCdev device as a singleton
func NewGPIOCDev ¶ added in v0.0.2
NewGPIOCDev creates a new GPIOCDev instance chipname should be "gpiochip0" for Raspberry Pi Zero or "gpiochip4" for Raspberry Pi 5
func (*GPIOCDev) SetPin ¶ added in v0.0.2
func (g *GPIOCDev) SetPin(name string, pinIndex int, options PinOptions) (*GPIOCDevPin, error)
Pin initializes and returns a GPIO pin
type GPIOCDevPin ¶ added in v0.0.2
type GPIOCDevPin struct {
// contains filtered or unexported fields
}
GPIOCDevPin implements the Pin interface for hardware GPIO pins
func (*GPIOCDevPin) Close ¶ added in v0.0.2
func (p *GPIOCDevPin) Close() error
Close releases the pin resources
func (*GPIOCDevPin) EventLoop ¶ added in v0.0.2
func (p *GPIOCDevPin) EventLoop(done chan any, callback func(evt gpiocdev.LineEvent))
EventLoop processes GPIO events
func (*GPIOCDevPin) Get ¶ added in v0.0.2
func (p *GPIOCDevPin) Get() (int, error)
Get reads the current value of the pin
func (*GPIOCDevPin) ID ¶ added in v0.0.2
func (p *GPIOCDevPin) ID() string
ID returns the pin identifier
func (*GPIOCDevPin) Index ¶ added in v0.0.2
func (p *GPIOCDevPin) Index() int
Index returns the pin index/offset
func (*GPIOCDevPin) Off ¶ added in v0.0.2
func (p *GPIOCDevPin) Off() error
Off sets the pin low (0)
func (*GPIOCDevPin) Options ¶ added in v0.0.2
func (p *GPIOCDevPin) Options() PinOptions
Direction returns the pin direction
func (*GPIOCDevPin) Reconfigure ¶ added in v0.0.2
func (p *GPIOCDevPin) Reconfigure(opts ...gpiocdev.LineConfigOption) error
Reconfigure changes the pin configuration
func (*GPIOCDevPin) Set ¶ added in v0.0.2
func (p *GPIOCDevPin) Set(value int) error
Set writes a value to the pin
func (*GPIOCDevPin) Toggle ¶ added in v0.0.2
func (p *GPIOCDevPin) Toggle() error
Toggle flips the pin value
type PinOptions ¶ added in v0.0.2
type PinOptions int
const ( PinInput PinOptions = 1 << 0 PinOutput PinOptions = 1 << 1 PinOutputLow PinOptions = 1 << 2 PinOutputHigh PinOptions = 1 << 3 PinPullUp PinOptions = 1 << 4 PinPullDown PinOptions = 1 << 5 PinRisingEdge PinOptions = 1 << 6 PinFallingEdge PinOptions = 1 << 7 PinBothEdges PinOptions = 1 << 8 )
type Serial ¶
type Transaction ¶ added in v0.0.2
type VPIO ¶ added in v0.0.2
type VPIO[T Value] struct { // contains filtered or unexported fields }
func (*VPIO[T]) ClearTransactions ¶ added in v0.0.2
func (v *VPIO[T]) ClearTransactions()
ClearTransactions removes all recorded transactions
func (*VPIO[T]) GetTransactions ¶ added in v0.0.2
func (v *VPIO[T]) GetTransactions() []*Transaction[T]
GetTransactions returns all recorded transactions
func (*VPIO[T]) PlayTransactions ¶ added in v0.0.2
func (v *VPIO[T]) PlayTransactions(f func())
PlayTranactions takes a function that will set values in the VPIO accordingly
func (*VPIO[T]) StartRecording ¶ added in v0.0.2
func (v *VPIO[T]) StartRecording()
StartRecording enables transaction recording
func (*VPIO[T]) StopRecording ¶ added in v0.0.2
func (v *VPIO[T]) StopRecording()
StopRecording disables transaction recording
type VPin ¶ added in v0.0.2
type VPin[T Value] struct { // contains filtered or unexported fields }
func (*VPin[T]) Options ¶ added in v0.0.2
func (p *VPin[T]) Options() []PinOptions
Direction returns the pin direction
func (*VPin[T]) ReadContinuous ¶ added in v0.0.2
func (v *VPin[T]) ReadContinuous() <-chan T