Documentation ¶
Overview ¶
/ Author: Bernhard Tittelbach, btittelbach@github (c) 2015
/ Author: Bernhard Tittelbach, btittelbach@github (c) 2018
Index ¶
- Constants
- Variables
- func AddDeviceTreeOverlay(dtb_name string) (err error)
- func AddDeviceTreeOverlayIfNotAlreadyLoaded(dtb_name string) (err error)
- func CheckDirectionOrPanic(gpio GPIOControllablePin) int
- func FindDeviceTreeOverlaySlot(dtb_name string) (slotnum int64, err error)
- func GetCPUInfos() (map[string][]string, error)
- func GetPWMFreqDuty(pwm PWMPin) (freq_hz, fraction float64)
- func GetStateOrPanic(gpio GPIOControllablePin) bool
- func GetStepperRPM(pwm PWMPin, stepsperrot float64) float64
- func LoadOverlayForSysfsADC() error
- func LoadOverlayForSysfsPWM() error
- func MMappedGPIOCleanup()
- func OpenAndHandleSerial(filename string, serspeed uint) (chan string, chan string, error)
- func OpenAndHandleStrangeSerial(filename string, serspeed uint, delim byte) (chan string, chan string, error)
- func RemoveDeviceTreeOverlay(dtb_name string) (err error)
- func SetDuty(pwm PWMPin, fraction float64)
- func SetOverlayState(dtb_name, state string) (err error)
- func SetPWMFreq(pwm PWMPin, freq_hz float64)
- func SetPWMFreqDuty(pwm PWMPin, freq_hz, fraction float64)
- func SetRawFd(ttyfd uintptr) (syscall.Termios, error)
- func SetRawFile(f *os.File) (syscall.Termios, error)
- func SetSpeedFd(ttyfd uintptr, speed uint32) (err error)
- func SetSpeedFile(f *os.File, speed uint32) error
- func SetStepperRPM(pwm PWMPin, rpm, stepsperrot float64)
- func SetTermiosFd(termios syscall.Termios, ttyfd uintptr) error
- func Step(gpio GPIOControllablePin, steps uint32, delay time.Duration, ...) (c uint32, err error)
- func WaitUntilSysFSADCRunning() error
- type ADC
- type BBPWMPin
- func (pwm *BBPWMPin) Close()
- func (pwm *BBPWMPin) DisablePWM()
- func (pwm *BBPWMPin) GetPWM() (period, duty time.Duration)
- func (pwm *BBPWMPin) GetPWMFreqDuty() (freq_hz, fraction float64)
- func (pwm *BBPWMPin) GetStepperRPM(stepsperrot float64) float64
- func (pwm *BBPWMPin) SetDuty(fraction float64)
- func (pwm *BBPWMPin) SetPWM(period, duty time.Duration)
- func (pwm *BBPWMPin) SetPWMFreq(freq_hz float64)
- func (pwm *BBPWMPin) SetPWMFreqDuty(freq_hz, fraction float64)
- func (pwm *BBPWMPin) SetPolarity(p bool)
- func (pwm *BBPWMPin) SetStepperRPM(rpm, stepsperrot float64)
- type FakeADC
- type FakeGPIO
- func (gpio *FakeGPIO) CheckDirection() (direction int, err error)
- func (gpio *FakeGPIO) Close()
- func (gpio *FakeGPIO) ConnectTo(conn ...*FakeGPIO)
- func (gpio *FakeGPIO) FakeInput(state bool) error
- func (gpio *FakeGPIO) GetState() (state bool, err error)
- func (gpio *FakeGPIO) SetActiveLow(activelow bool) error
- func (gpio *FakeGPIO) SetDirection(direction int) error
- func (gpio *FakeGPIO) SetState(state bool) error
- func (gpio *FakeGPIO) SetStateNow(state bool) error
- type FakeGPIOCollectionFactory
- func (gpiocf *FakeGPIOCollectionFactory) BeginTransactionRecordSetStates()
- func (gpiocf *FakeGPIOCollectionFactory) EndTransactionApplySetStates()
- func (gpiocf *FakeGPIOCollectionFactory) NewFakeGPIO(number uint, direction int) (gpio *FakeGPIOInCollection)
- func (gpiocf *FakeGPIOCollectionFactory) NewFakeNamedGPIO(name string, direction int, logTarget *log.Logger) (gpio *FakeGPIOInCollection)
- func (gpiocf *FakeGPIOCollectionFactory) NewGPIO(number uint, direction int) GPIOControllablePinInCollection
- type FakeGPIOInCollection
- func (gpio *FakeGPIOInCollection) GetFutureState() (state_known, state bool, err error)
- func (gpio *FakeGPIOInCollection) SetActiveLow(activelow bool) (err error)
- func (gpio *FakeGPIOInCollection) SetFutureState(state bool) error
- func (gpio *FakeGPIOInCollection) SetState(state bool) error
- func (gpio *FakeGPIOInCollection) SetStateNow(state bool) error
- type FakeGPIONullWriter
- type FakePWMPin
- type GPIOCollectionFactory
- type GPIOControllablePin
- type GPIOControllablePinInCollection
- type MMappedGPIO
- func (gpio *MMappedGPIO) CheckDirection() (direction int, err error)
- func (gpio *MMappedGPIO) Close()
- func (gpio *MMappedGPIO) GetState() (state bool, err error)
- func (gpio *MMappedGPIO) SetActiveLow(activelow bool) error
- func (gpio *MMappedGPIO) SetDebounce(enable_debounce bool) error
- func (gpio *MMappedGPIO) SetState(state bool) error
- func (gpio *MMappedGPIO) SetStateNow(state bool) error
- type MMappedGPIOCollectionFactory
- func (gpiocf *MMappedGPIOCollectionFactory) BeginTransactionRecordSetStates()
- func (gpiocf *MMappedGPIOCollectionFactory) EndTransactionApplySetStates()
- func (gpiocf *MMappedGPIOCollectionFactory) NewGPIO(number uint, direction int) GPIOControllablePinInCollection
- func (gpiocf *MMappedGPIOCollectionFactory) NewMMappedGPIO(number uint, direction int) (gpio *MMappedGPIOInCollection)
- type MMappedGPIOInCollection
- func (gpio *MMappedGPIOInCollection) GetFutureState() (state_known, state bool, err error)
- func (gpio *MMappedGPIOInCollection) SetActiveLow(activelow bool) (err error)
- func (gpio *MMappedGPIOInCollection) SetFutureState(state bool) error
- func (gpio *MMappedGPIOInCollection) SetState(state bool) error
- func (gpio *MMappedGPIOInCollection) SetStateNow(state bool) error
- type PWMPin
- type SysfsADC
- type SysfsGPIO
- func (gpio *SysfsGPIO) CheckDirection() (direction int, err error)
- func (gpio *SysfsGPIO) Close()
- func (gpio *SysfsGPIO) GetState() (state bool, err error)
- func (gpio *SysfsGPIO) ReOpen() (err error)
- func (gpio *SysfsGPIO) SetActiveLow(activelow bool) error
- func (gpio *SysfsGPIO) SetDirection(direction int) error
- func (gpio *SysfsGPIO) SetState(state bool) error
- func (gpio *SysfsGPIO) SetStateNow(state bool) error
Constants ¶
const ( IN = iota OUT IN_PULLDOWN IN_PULLUP )
const (
BYTES_IN_UINT32 = 4 // bytes
)
Variables ¶
var ERROR_DTO_ALREADY_LOADED error
var FakeGPIODefaultLogTarget_ *log.Logger
Functions ¶
func AddDeviceTreeOverlay ¶
func CheckDirectionOrPanic ¶
func CheckDirectionOrPanic(gpio GPIOControllablePin) int
func GetCPUInfos ¶
/ 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 GetStateOrPanic ¶
func GetStateOrPanic(gpio GPIOControllablePin) bool
func GetStepperRPM ¶
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 RemoveDeviceTreeOverlay ¶
func SetOverlayState ¶
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 SetPWMFreqDuty ¶
func SetSpeedFd ¶
func SetStepperRPM ¶
func WaitUntilSysFSADCRunning ¶
func WaitUntilSysFSADCRunning() error
Types ¶
type BBPWMPin ¶
type BBPWMPin struct {
// contains filtered or unexported fields
}
func NewBBBPWMOrPanic ¶
Wrapper around NewBBBPWM. Does not return an error but panics instead. Useful to avoid multiple return values.
func NewPWMChipPWM ¶
func (*BBPWMPin) DisablePWM ¶
func (pwm *BBPWMPin) DisablePWM()
func (*BBPWMPin) GetPWMFreqDuty ¶
func (*BBPWMPin) GetStepperRPM ¶
func (*BBPWMPin) SetPWMFreq ¶
func (*BBPWMPin) SetPWMFreqDuty ¶
func (*BBPWMPin) SetPolarity ¶
func (*BBPWMPin) SetStepperRPM ¶
type FakeADC ¶
type FakeADC struct { Number uint // contains filtered or unexported fields }
func NewFakeADC ¶
Instantinate a new Fake ADC for Simulation
func NewFakeADCOrPanic ¶
func (*FakeADC) CheckErrorOccurred ¶
func (*FakeADC) ReadValueCheckError ¶
func (*FakeADC) SimulateValue ¶
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 ¶
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 ¶
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 (*FakeGPIO) SetActiveLow ¶
this inverts the meaning of virtual 0 and 1
func (*FakeGPIO) SetDirection ¶
func (*FakeGPIO) SetStateNow ¶
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{}
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 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 SysfsADC ¶
type SysfsADC struct { Number uint // contains filtered or unexported fields }
func NewSysfsADC ¶
Instantinate a new ADC to read through sysfs. Takes ADC AIN numer (same as in sysfs)
func NewSysfsADCOrPanic ¶
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 (*SysfsADC) ReadValue ¶
returns raw SysFs Value. In case of new kernel 4.4 that means raw value which we convert to actual mV
func (*SysfsADC) ReadValueCheckError ¶
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 ¶
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 ¶
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 (*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) SetActiveLow ¶
this inverts the meaning of 0 and 1 in /sys/class/gpio/gpio*/value