mirror of
https://github.com/kidoman/embd
synced 2025-07-04 20:37:46 +02:00
Refactored Interruptable GPIO codes
Created two new Interface and hid implementation details as much as possible.
This commit is contained in:
parent
a54e7dc7ff
commit
919b01a3a2
3 changed files with 43 additions and 16 deletions
40
gpio.go
40
gpio.go
|
@ -23,9 +23,13 @@ const (
|
|||
High
|
||||
)
|
||||
|
||||
// Edge trigger for GPIO Interrupt
|
||||
type Edge string
|
||||
|
||||
// IRQ event function definition
|
||||
type IRQEvent func(pin DigitalPin)
|
||||
|
||||
// Available Edge trigger for Interrupt
|
||||
const (
|
||||
EdgeNone Edge = "none"
|
||||
EdgeRising Edge = "rising"
|
||||
|
@ -33,8 +37,25 @@ const (
|
|||
EdgeBoth Edge = "both"
|
||||
)
|
||||
|
||||
// InterruptPin implements access to a Interruptable capable GPIO pin.
|
||||
type InterruptPin interface {
|
||||
// return file handler for GPIO
|
||||
Fd() int
|
||||
|
||||
// Start watching this pin for interrupt
|
||||
Watch(edge Edge, callback IRQEvent) error
|
||||
|
||||
// Stop watching this pin for interrupt
|
||||
StopWatching() error
|
||||
|
||||
// Signal that an Interrupt has happened
|
||||
Signal()
|
||||
}
|
||||
|
||||
// DigitalPin implements access to a digital IO capable GPIO pin.
|
||||
type DigitalPin interface {
|
||||
InterruptPin
|
||||
|
||||
// N returns the logical GPIO number.
|
||||
N() int
|
||||
|
||||
|
@ -60,11 +81,6 @@ 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
|
||||
}
|
||||
|
@ -116,13 +132,17 @@ type PWMPin interface {
|
|||
Close() error
|
||||
}
|
||||
|
||||
type GPIOInterrupt interface {
|
||||
// Register a pin as an interrupt
|
||||
RegisterInterrupt(p InterruptPin) error
|
||||
|
||||
// Unregister a pin as an interrupt
|
||||
UnregisterInterrupt(p InterruptPin) error
|
||||
}
|
||||
|
||||
// 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
|
||||
GPIOInterrupt
|
||||
|
||||
// Unregister unregisters the pin from the driver. Should be called when the pin is closed.
|
||||
Unregister(string) error
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue