1
0
Fork 0
mirror of https://github.com/kidoman/embd synced 2025-07-04 20:37:46 +02:00

Initial attempt to implemented GPIO Interrupts

Basicly imported Dave Cheney's code from
http://github.com/davecheney/gpio
This commit is contained in:
SjB 2014-04-08 23:09:21 -04:00
parent 5c0ae1c83a
commit a54e7dc7ff
3 changed files with 154 additions and 4 deletions

37
gpio.go
View file

@ -23,6 +23,16 @@ const (
High
)
type Edge string
type IRQEvent func(pin DigitalPin)
const (
EdgeNone Edge = "none"
EdgeRising Edge = "rising"
EdgeFalling Edge = "falling"
EdgeBoth Edge = "both"
)
// DigitalPin implements access to a digital IO capable GPIO pin.
type DigitalPin interface {
// N returns the logical GPIO number.
@ -50,6 +60,11 @@ type DigitalPin interface {
// PullDown pulls the pin down.
PullDown() error
Watch(edge Edge, callback IRQEvent) error
StopWatching() error
Signal()
// Close releases the resources associated with the pin.
Close() error
}
@ -103,6 +118,12 @@ type PWMPin interface {
// GPIODriver implements a generic GPIO driver.
type GPIODriver interface {
// Register a pin as an interrupt pin
RegisterInterrupt(fd int, p DigitalPin) error
// Unregister the file handler from the Interrupt handler
UnregisterInterrupt(fd int) error
// Unregister unregisters the pin from the driver. Should be called when the pin is closed.
Unregister(string) error
@ -209,6 +230,22 @@ func PullDown(key interface{}) error {
return pin.PullDown()
}
func Watch(key interface{}, edge Edge, callback IRQEvent) error {
pin, err := NewDigitalPin(key)
if err != nil {
return err
}
return pin.Watch(edge, callback)
}
func StopWatching(key interface{}) error {
pin, err := NewDigitalPin(key)
if err != nil {
return err
}
return pin.StopWatching()
}
// NewAnalogPin returns a AnalogPin interface which allows control over
// the analog GPIO pin.
func NewAnalogPin(key interface{}) (AnalogPin, error) {