bbhw

package module
v0.0.0-...-d30b01e Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2018 License: MIT Imports: 15 Imported by: 5

README

go-BeagleBone Hardware

BeagleBone Hardware Controls (GPIO,PWM,TTY,DTO) for the go language (and for other Linux Embedded Devices)

About

This is a small library to make dealing with Linux embedded devices in go easier. It is mainly written for the BeagleBone Black but with the exception of the Memory Mapped Fast GPIO, is works well on the Raspberry or other embedded Linux devices (e.g.: TP-Link, PC-Engines) as well.

The library currently does three things:

  • It implements memory mapped GPIOs for the AM335xx, the beagle bone CPU, which allows us to toggle about 800 times faster than sysfs controlled GPIOs.
  • For other Linux embedded devices it implements a comprehensive normal GPIO library
  • It provides an extensive interface to the BeagleBone's PWM control
  • It provides tools to interface with character oriented rawtty serial devices (as opposed to line oriented)

Before writing it, I had a look at aqua's raspberry lib, which was too basic for my needs, but which is why the SysFSGPIO Interface looks similar. You should check out his repository if you are looking for go-support for OneWire / DS18x20 devices.

I've also written two blogs about using PINS on the BeagleBone Black and making Device-Tree Overlays to configure the BeagleBone Black.

Usage

%> go get github.com/btittelbach/go-bbhw
import "github.com/btittelbach/go-bbhw"

bbhw.

View the API docs here

Using GPIOs

Control GPIOs using the GPIOControllablePin interface for which four implemenations are provided

type GPIOControllablePin interface {
    SetState(bool) error
    SetStateNow(bool) error
    GetState() (bool, error)
    CheckDirection() (int, error)
    SetActiveLow(bool) error
}

Fake GPIO

Use FakeGPIO for testing and debugging. Does not actually toogle GPIOs and works even on your normal computer.

func NewFakeGPIO(gpionum uint, direction int) (gpio *FakeGPIO)
    same signature as all the other New*GPIO implementations. logs to
    FakeGPIODefaultLogTarget_ which is an exported field and thus you can
    set it to point to the log.Logger of your choice
func NewFakeNamedGPIO(name string, direction int, logTarget *log.Logger) (gpio *FakeGPIO)
    slightly more fancy FakeGPIO for debugging. takes a name for easy
    recognition in debugging output and an optional logger (or nil) of your
    choice, thus you could route debug output of different GPIOs to
    different destinations

SysFS GPIO

Uses the /sys/class/gpio/**/* file-interface provided by the linux kernel. Slightly slower than mmapped implementations but will work on any linux system with GPIOs.

func NewSysfsGPIO(number uint, direction int) (gpio *SysfsGPIO, err error)
    Instantinate a new GPIO to control through sysfs. Takes GPIO numer (same
    as in sysfs) and direction bbhw.IN or bbhw.OUT
func NewSysfsGPIOOrPanic(number uint, direction int) (gpio *SysfsGPIO)
    Wrapper around NewSysfsGPIO. Does not return an error but panics
    instead. Useful to avoid multiple return values. This is the function
    with the same signature as all the other New*GPIO*s
MemoryMapped GPIO

Uses the memory mapped IO to directly interface with AM335x registers. Toggles GPIOs about 800 times faster than SysFS.

func NewMMappedGPIO(number uint, direction int) (gpio *MMappedGPIO)
    Instantinate a new and fast GPIO controlled using direct access to
    AM335x registers. Takes GPIO numer (same as in sysfs) and direction
    bbhw.IN or bbhw.OUT Only works on AM335x and address compatible SoCs
Collection of MemoryMapped GPIOs

Same as MMappedGPIO, but part of a collection of GPIOs you can set all at once using database-like transactions. Records SetState() calls after BeginTransactionRecordSetStates() has been called and delays their effect until EndTransactionApplySetStates() is called. Use it to toggle many GPIOs in the very same instant.

func NewMMappedGPIOCollectionFactory() (gpiocf *MMappedGPIOCollectionFactory)
    Create a collection of GPIOs. Doubles as factory for the
    MMappedGPIOInCollection type.
func (gpiocf *MMappedGPIOCollectionFactory) NewMMappedGPIO(number uint, direction int) (gpio *MMappedGPIOInCollection)
    Same as NewMMappedGPIO but part of a MMappedGPIOCollectionFactory

Keywords

go golang raspberry beaglebone black white GPIO PWM fast mmap memory mapped am33xx am335xx serial tty serial raw rawtty pinmux 0x194 0x190 0x44E07000 cleardataout setdataout

Documentation

Overview

/ Author: Bernhard Tittelbach, btittelbach@github (c) 2015

/ Author: Bernhard Tittelbach, btittelbach@github (c) 2018

Index

Constants

View Source
const (
	IN = iota
	OUT
	IN_PULLDOWN
	IN_PULLUP
)
View Source
const (
	BYTES_IN_UINT32 = 4 // bytes
)

Variables

View Source
var ERROR_DTO_ALREADY_LOADED error
View Source
var FakeGPIODefaultLogTarget_ *log.Logger

Functions

func AddDeviceTreeOverlay

func AddDeviceTreeOverlay(dtb_name string) (err error)

func AddDeviceTreeOverlayIfNotAlreadyLoaded

func AddDeviceTreeOverlayIfNotAlreadyLoaded(dtb_name string) (err error)

func CheckDirectionOrPanic

func CheckDirectionOrPanic(gpio GPIOControllablePin) int

func FindDeviceTreeOverlaySlot

func FindDeviceTreeOverlaySlot(dtb_name string) (slotnum int64, err error)

func GetCPUInfos

func GetCPUInfos() (map[string][]string, error)

/ return info from /proc/cpuinfo as map of keys to array of strings / e.g. / m["processor"]=["0","1"] / m["BogoMIPS"]=["38.40","38.40"] / m["Serial"]=["00000000001"]

func GetPWMFreqDuty

func GetPWMFreqDuty(pwm PWMPin) (freq_hz, fraction float64)

func GetStateOrPanic

func GetStateOrPanic(gpio GPIOControllablePin) bool

func GetStepperRPM

func GetStepperRPM(pwm PWMPin, stepsperrot float64) float64

func LoadOverlayForSysfsADC

func LoadOverlayForSysfsADC() error

func LoadOverlayForSysfsPWM

func LoadOverlayForSysfsPWM() error

func MMappedGPIOCleanup

func MMappedGPIOCleanup()

careful with this function! never call it if there's a chance some routine might still be using fast gpios If in Doubt: Never Call It

func OpenAndHandleSerial

func OpenAndHandleSerial(filename string, serspeed uint) (chan string, chan string, error)

func OpenAndHandleStrangeSerial

func OpenAndHandleStrangeSerial(filename string, serspeed uint, delim byte) (chan string, chan string, error)

func RemoveDeviceTreeOverlay

func RemoveDeviceTreeOverlay(dtb_name string) (err error)

func SetDuty

func SetDuty(pwm PWMPin, fraction float64)

set PWM duty to fraction between 0.0 and 1.0

func SetOverlayState

func SetOverlayState(dtb_name, state string) (err error)

Newer Universal Overlays allow the pinmux to be set by writing "gpio", "pwm", "default", "spi", "i2c", .. to the state file for a certain pin

while overlays like PyBBIO-gpio.* can, once loaded, be configured using file /sys/devices/ocp.\d/PyBBIO-gpio.*.\d\d/state usually the following values can be written to configure the state: "mode_0b00101111" => INPUT, No Pullup/down "mode_0b00110111" => INPUT, Pullup "mode_0b00100111" => INPUT, Pulldown "mode_0b00001111" => OUTPUT, No Pullup/down "mode_0b00010111" => OUTPUT, Pullup "mode_0b00000111" => OUTPUT, Pulldown

func SetPWMFreq

func SetPWMFreq(pwm PWMPin, freq_hz float64)

func SetPWMFreqDuty

func SetPWMFreqDuty(pwm PWMPin, freq_hz, fraction float64)

func SetRawFd

func SetRawFd(ttyfd uintptr) (syscall.Termios, error)

---------- Termios Code ----------------

func SetRawFile

func SetRawFile(f *os.File) (syscall.Termios, error)

func SetSpeedFd

func SetSpeedFd(ttyfd uintptr, speed uint32) (err error)

func SetSpeedFile

func SetSpeedFile(f *os.File, speed uint32) error

func SetStepperRPM

func SetStepperRPM(pwm PWMPin, rpm, stepsperrot float64)

func SetTermiosFd

func SetTermiosFd(termios syscall.Termios, ttyfd uintptr) error

func Step

func Step(gpio GPIOControllablePin, steps uint32, delay time.Duration, abortcheck func() bool) (c uint32, err error)

func WaitUntilSysFSADCRunning

func WaitUntilSysFSADCRunning() error

Types

type ADC

type ADC interface {
	ReadValue() uint16
	CheckErrorOccurred() error
	ReadValueCheckError() (uint16, error)
}

type BBPWMPin

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

func NewBBBPWM

func NewBBBPWM(bbb_pin string) (pwm *BBPWMPin, err error)

Example: StepperPWM, err = NewBBBPWM("P9_16")

func NewBBBPWMOrPanic

func NewBBBPWMOrPanic(bbb_pin string) *BBPWMPin

Wrapper around NewBBBPWM. Does not return an error but panics instead. Useful to avoid multiple return values.

func NewPWMChipPWM

func NewPWMChipPWM(chipid, pwmid int) (pwm *BBPWMPin, err error)

func (*BBPWMPin) Close

func (pwm *BBPWMPin) Close()

func (*BBPWMPin) DisablePWM

func (pwm *BBPWMPin) DisablePWM()

func (*BBPWMPin) GetPWM

func (pwm *BBPWMPin) GetPWM() (period, duty time.Duration)

func (*BBPWMPin) GetPWMFreqDuty

func (pwm *BBPWMPin) GetPWMFreqDuty() (freq_hz, fraction float64)

func (*BBPWMPin) GetStepperRPM

func (pwm *BBPWMPin) GetStepperRPM(stepsperrot float64) float64

func (*BBPWMPin) SetDuty

func (pwm *BBPWMPin) SetDuty(fraction float64)

set PWM duty to fraction between 0.0 and 1.0

func (*BBPWMPin) SetPWM

func (pwm *BBPWMPin) SetPWM(period, duty time.Duration)

func (*BBPWMPin) SetPWMFreq

func (pwm *BBPWMPin) SetPWMFreq(freq_hz float64)

func (*BBPWMPin) SetPWMFreqDuty

func (pwm *BBPWMPin) SetPWMFreqDuty(freq_hz, fraction float64)

func (*BBPWMPin) SetPolarity

func (pwm *BBPWMPin) SetPolarity(p bool)

func (*BBPWMPin) SetStepperRPM

func (pwm *BBPWMPin) SetStepperRPM(rpm, stepsperrot float64)

type FakeADC

type FakeADC struct {
	Number uint
	// contains filtered or unexported fields
}

func NewFakeADC

func NewFakeADC(number uint) (adc *FakeADC, err error)

Instantinate a new Fake ADC for Simulation

func NewFakeADCOrPanic

func NewFakeADCOrPanic(number uint) (adc *FakeADC)

func (*FakeADC) CheckErrorOccurred

func (adc *FakeADC) CheckErrorOccurred() error

func (*FakeADC) ReadValue

func (adc *FakeADC) ReadValue() (value uint16)

func (*FakeADC) ReadValueCheckError

func (adc *FakeADC) ReadValueCheckError() (value uint16, err error)

func (*FakeADC) SimulateValue

func (adc *FakeADC) SimulateValue(value uint16, err error)

type FakeGPIO

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

Use FakeGPIO for testing and debugging. Does not actually toogle GPIOs and works even on your normal computer.

func NewFakeGPIO

func NewFakeGPIO(gpionum uint, direction int) (gpio *FakeGPIO)

same signature as all the other New*GPIO implementations. logs to FakeGPIODefaultLogTarget_ which is an exported field and thus you can set it to point to the log.Logger of your choice

func NewFakeNamedGPIO

func NewFakeNamedGPIO(name string, direction int, logTarget *log.Logger) (gpio *FakeGPIO)

slightly more fancy FakeGPIO for debugging. takes a name for easy recognition in debugging output and an optional logger (or nil) of your choice, thus you could route debug output of different GPIOs to different destinations

func (*FakeGPIO) CheckDirection

func (gpio *FakeGPIO) CheckDirection() (direction int, err error)

func (*FakeGPIO) Close

func (gpio *FakeGPIO) Close()

func (*FakeGPIO) ConnectTo

func (gpio *FakeGPIO) ConnectTo(conn ...*FakeGPIO)

func (*FakeGPIO) FakeInput

func (gpio *FakeGPIO) FakeInput(state bool) error

func (*FakeGPIO) GetState

func (gpio *FakeGPIO) GetState() (state bool, err error)

func (*FakeGPIO) SetActiveLow

func (gpio *FakeGPIO) SetActiveLow(activelow bool) error

this inverts the meaning of virtual 0 and 1

func (*FakeGPIO) SetDirection

func (gpio *FakeGPIO) SetDirection(direction int) error

func (*FakeGPIO) SetState

func (gpio *FakeGPIO) SetState(state bool) error

func (*FakeGPIO) SetStateNow

func (gpio *FakeGPIO) SetStateNow(state bool) error

type FakeGPIOCollectionFactory

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

Collection of GPIOs. Records SetState() calls after BeginTransactionRecordSetStates() has been called and delays their effect until EndTransactionApplySetStates() is called. Use it to toggle many GPIOs in the very same instant.

func NewFakeGPIOCollectionFactory

func NewFakeGPIOCollectionFactory() (gpiocf *FakeGPIOCollectionFactory)

Create a collection of GPIOs. Doubles as factory for the FakeGPIOInCollection type.

func (*FakeGPIOCollectionFactory) BeginTransactionRecordSetStates

func (gpiocf *FakeGPIOCollectionFactory) BeginTransactionRecordSetStates()

Begin recording calls to SetState for later

func (*FakeGPIOCollectionFactory) EndTransactionApplySetStates

func (gpiocf *FakeGPIOCollectionFactory) EndTransactionApplySetStates()

Apply States recorded with BeginTransactionRecordSetStates

func (*FakeGPIOCollectionFactory) NewFakeGPIO

func (gpiocf *FakeGPIOCollectionFactory) NewFakeGPIO(number uint, direction int) (gpio *FakeGPIOInCollection)

Same as FakeGPIO but part of a FakeGPIOCollectionFactory unfortunately, can't rename this function as it would not be readily interchangeable anymore

func (*FakeGPIOCollectionFactory) NewFakeNamedGPIO

func (gpiocf *FakeGPIOCollectionFactory) NewFakeNamedGPIO(name string, direction int, logTarget *log.Logger) (gpio *FakeGPIOInCollection)

slightly more fancy FakeGPIO for debugging. takes a name for easy recognition in debugging output and an optional logger (or nil) of your choice, thus you could route debug output of different GPIOs to different destinations

func (*FakeGPIOCollectionFactory) NewGPIO

func (gpiocf *FakeGPIOCollectionFactory) NewGPIO(number uint, direction int) GPIOControllablePinInCollection

type FakeGPIOInCollection

type FakeGPIOInCollection struct {
	FakeGPIO
	// contains filtered or unexported fields
}

Uses the memory mapped IO to directly interface with AM335x registers. Same as FakeGPIO, but part of a collection of GPIOs you can set all at once using database-like transactions.

func (*FakeGPIOInCollection) GetFutureState

func (gpio *FakeGPIOInCollection) GetFutureState() (state_known, state bool, err error)

func (*FakeGPIOInCollection) SetActiveLow

func (gpio *FakeGPIOInCollection) SetActiveLow(activelow bool) (err error)

func (*FakeGPIOInCollection) SetFutureState

func (gpio *FakeGPIOInCollection) SetFutureState(state bool) error

func (*FakeGPIOInCollection) SetState

func (gpio *FakeGPIOInCollection) SetState(state bool) error

func (*FakeGPIOInCollection) SetStateNow

func (gpio *FakeGPIOInCollection) SetStateNow(state bool) error

type FakeGPIONullWriter

type FakeGPIONullWriter struct{}

func (*FakeGPIONullWriter) Write

func (n *FakeGPIONullWriter) Write(p []byte) (int, error)

type FakePWMPin

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

func NewFakePWM

func NewFakePWM(name string) (pwm *FakePWMPin, err error)

Example: StepperPWM, err = NewBBBPWM("P9_16")

func NewFakePWMOrPanic

func NewFakePWMOrPanic(bbb_pin string) *FakePWMPin

Wrapper around NewFakePWM. Does not return an error but panics instead. Useful to avoid multiple return values.

func (*FakePWMPin) Close

func (pwm *FakePWMPin) Close()

func (*FakePWMPin) DisablePWM

func (pwm *FakePWMPin) DisablePWM()

func (*FakePWMPin) GetPWM

func (pwm *FakePWMPin) GetPWM() (period, duty time.Duration)

func (*FakePWMPin) SetPWM

func (pwm *FakePWMPin) SetPWM(period, duty time.Duration)

func (*FakePWMPin) SetPolarity

func (pwm *FakePWMPin) SetPolarity(p bool)

type GPIOCollectionFactory

type GPIOCollectionFactory interface {
	EndTransactionApplySetStates()
	BeginTransactionRecordSetStates()
	NewGPIO(uint, int) GPIOControllablePinInCollection
}

type GPIOControllablePin

type GPIOControllablePin interface {
	SetState(bool) error
	SetStateNow(bool) error
	GetState() (bool, error)
	CheckDirection() (int, error)
	SetActiveLow(bool) error
}

type GPIOControllablePinInCollection

type GPIOControllablePinInCollection interface {
	SetState(bool) error
	SetStateNow(bool) error
	GetState() (bool, error)
	CheckDirection() (int, error)
	SetActiveLow(bool) error
	SetFutureState(state bool) error
	GetFutureState() (state_known, state bool, err error)
}

type MMappedGPIO

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

Uses the memory mapped IO to directly interface with AM335x registers. Toggles GPIOs about 800 times faster than SysFS.

func NewMMappedGPIO

func NewMMappedGPIO(number uint, direction int) (gpio *MMappedGPIO)

Instantinate a new and fast GPIO controlled using direct access to AM335x registers. Takes GPIO numer (same as in sysfs) and direction bbhw.IN or bbhw.OUT Only works on AM335x and address compatible SoCs

See http://kilobaser.com/blog/2014-07-15-beaglebone-black-gpios#1gpiopin regarding the numbering of GPIO pins.

func (*MMappedGPIO) CheckDirection

func (gpio *MMappedGPIO) CheckDirection() (direction int, err error)

func (*MMappedGPIO) Close

func (gpio *MMappedGPIO) Close()

not really necessary, but nice to keep same interface as SysfsGPIO

func (*MMappedGPIO) GetState

func (gpio *MMappedGPIO) GetState() (state bool, err error)

returns true if pin is HIGH and false if pin is LOW i.e. HIGH/LOW signal on input pin note that SetActiveLow inverts return value internal note: in contrast to SysFS we need to query two different registers depending on the pin direction

func (*MMappedGPIO) SetActiveLow

func (gpio *MMappedGPIO) SetActiveLow(activelow bool) error

this inverts the meaning of 0 and 1 just like in SysFS, this has an immediate effect on the physical output

func (*MMappedGPIO) SetDebounce

func (gpio *MMappedGPIO) SetDebounce(enable_debounce bool) error

func (*MMappedGPIO) SetState

func (gpio *MMappedGPIO) SetState(state bool) error

This should be about 800 times faster than SysFS GPIOs SetState However, even though you can toggle a pin via SysFS, setting its state via the memory registers might stop working, once a DeviceTreeOverlay for that pin has been loaded (even after you have removed the Overlay) in this case: reboot

func (*MMappedGPIO) SetStateNow

func (gpio *MMappedGPIO) SetStateNow(state bool) error

type MMappedGPIOCollectionFactory

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

Collection of GPIOs. Records SetState() calls after BeginTransactionRecordSetStates() has been called and delays their effect until EndTransactionApplySetStates() is called. Use it to toggle many GPIOs in the very same instant.

func NewMMappedGPIOCollectionFactory

func NewMMappedGPIOCollectionFactory() (gpiocf *MMappedGPIOCollectionFactory)

Create a collection of GPIOs. Doubles as factory for the MMappedGPIOInCollection type.

func (*MMappedGPIOCollectionFactory) BeginTransactionRecordSetStates

func (gpiocf *MMappedGPIOCollectionFactory) BeginTransactionRecordSetStates()

Begin recording calls to SetState for later

func (*MMappedGPIOCollectionFactory) EndTransactionApplySetStates

func (gpiocf *MMappedGPIOCollectionFactory) EndTransactionApplySetStates()

Quickly and concurrently (i.e. faster than GPIOChips can react) applies new state by writing a 32 bit value to the corresponding CLEARDATA and SETDATA registers for each of the four gpio chips.

Note that at LEAST one gpio for each gpiochip has to be exported in sysfs in order to active the corresponding gpiochip otherwise clocksource of gpiochip remains gated and we hang on receiving SIGBUS immediately after trying to write that register see: https://groups.google.com/forum/#!msg/beagleboard/OYFp4EXawiI/Mq6s3sg14HoJ

func (*MMappedGPIOCollectionFactory) NewGPIO

func (gpiocf *MMappedGPIOCollectionFactory) NewGPIO(number uint, direction int) GPIOControllablePinInCollection

func (*MMappedGPIOCollectionFactory) NewMMappedGPIO

func (gpiocf *MMappedGPIOCollectionFactory) NewMMappedGPIO(number uint, direction int) (gpio *MMappedGPIOInCollection)

Same as NewMMappedGPIO but part of a MMappedGPIOCollectionFactory

type MMappedGPIOInCollection

type MMappedGPIOInCollection struct {
	MMappedGPIO
	// contains filtered or unexported fields
}

Uses the memory mapped IO to directly interface with AM335x registers. Same as MMappedGPIO, but part of a collection of GPIOs you can set all at once using database-like transactions.

func (*MMappedGPIOInCollection) GetFutureState

func (gpio *MMappedGPIOInCollection) GetFutureState() (state_known, state bool, err error)

/ Checks if State was Set during a transaction but not yet applied / state_known returns true if state was set (i.e. either a corresponding bit is set in either clear- or set-register) / state returns the future state (i.e. which bit was set) / SetActiveLow inverts state but obviously not state_known / err returns nil

func (*MMappedGPIOInCollection) SetActiveLow

func (gpio *MMappedGPIOInCollection) SetActiveLow(activelow bool) (err error)

this inverts the meaning of 0 and 1 just like in SysFS, this has an immediate effect on the physical output unless BeginTransactionRecordSetStates() was called beforehand in which case its effect is delayed until EndTransactionApplySetStates()

func (*MMappedGPIOInCollection) SetFutureState

func (gpio *MMappedGPIOInCollection) SetFutureState(state bool) error

func (*MMappedGPIOInCollection) SetState

func (gpio *MMappedGPIOInCollection) SetState(state bool) error

func (*MMappedGPIOInCollection) SetStateNow

func (gpio *MMappedGPIOInCollection) SetStateNow(state bool) error

type PWMPin

type PWMPin interface {
	SetPolarity(p bool)
	SetPWM(time.Duration, time.Duration)
	GetPWM() (time.Duration, time.Duration)
	DisablePWM()
	Close()
}

type SysfsADC

type SysfsADC struct {
	Number uint
	// contains filtered or unexported fields
}

func NewSysfsADC

func NewSysfsADC(number uint) (adc *SysfsADC, err error)

Instantinate a new ADC to read through sysfs. Takes ADC AIN numer (same as in sysfs)

func NewSysfsADCOrPanic

func NewSysfsADCOrPanic(number uint) (adc *SysfsADC)

Wrapper around NewSysfsGPIO. Does not return an error but panics instead. Useful to avoid multiple return values. This is the function with the same signature as all the other New*GPIO*s

func (*SysfsADC) CheckErrorOccurred

func (adc *SysfsADC) CheckErrorOccurred() error

func (*SysfsADC) ReadValue

func (adc *SysfsADC) ReadValue() (value uint16)

returns raw SysFs Value. In case of new kernel 4.4 that means raw value which we convert to actual mV

func (*SysfsADC) ReadValueCheckError

func (adc *SysfsADC) ReadValueCheckError() (value uint16, err error)

type SysfsGPIO

type SysfsGPIO struct {
	Number uint
	// contains filtered or unexported fields
}

Uses the /sys/class/gpio/**/* file-interface provided by the linux kernel. Slightly slower than mmapped implementations but will work on any linux system with GPIOs.

func NewSysfsGPIO

func NewSysfsGPIO(number uint, direction int) (gpio *SysfsGPIO, err error)

Instantinate a new GPIO to control through sysfs. Takes GPIO numer (same as in sysfs) and direction bbhw.IN or bbhw.OUT

See http://kilobaser.com/blog/2014-07-15-beaglebone-black-gpios#1gpiopin regarding the numbering of GPIO pins.

func NewSysfsGPIOOrPanic

func NewSysfsGPIOOrPanic(number uint, direction int) (gpio *SysfsGPIO)

Wrapper around NewSysfsGPIO. Does not return an error but panics instead. Useful to avoid multiple return values. This is the function with the same signature as all the other New*GPIO*s

func (*SysfsGPIO) CheckDirection

func (gpio *SysfsGPIO) CheckDirection() (direction int, err error)

func (*SysfsGPIO) Close

func (gpio *SysfsGPIO) Close()

closes filedescriptor does NOT unexport gpio, since gpio_mmap_collection and gpio_mmap depend on the gpio remaining exported and the gpiobank activated

func (*SysfsGPIO) GetState

func (gpio *SysfsGPIO) GetState() (state bool, err error)

func (*SysfsGPIO) ReOpen

func (gpio *SysfsGPIO) ReOpen() (err error)

func (*SysfsGPIO) SetActiveLow

func (gpio *SysfsGPIO) SetActiveLow(activelow bool) error

this inverts the meaning of 0 and 1 in /sys/class/gpio/gpio*/value

func (*SysfsGPIO) SetDirection

func (gpio *SysfsGPIO) SetDirection(direction int) error

func (*SysfsGPIO) SetState

func (gpio *SysfsGPIO) SetState(state bool) error

func (*SysfsGPIO) SetStateNow

func (gpio *SysfsGPIO) SetStateNow(state bool) error

Jump to

Keyboard shortcuts

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