mirror of
https://github.com/kidoman/embd
synced 2025-07-03 03:47:33 +02:00
gpio: analog pin support for the bbb
This commit is contained in:
parent
f667c93b7a
commit
d64682bf34
8 changed files with 354 additions and 40 deletions
34
gpio.go
34
gpio.go
|
@ -13,6 +13,8 @@ const (
|
|||
)
|
||||
|
||||
type DigitalPin interface {
|
||||
N() int
|
||||
|
||||
Write(val int) error
|
||||
Read() (int, error)
|
||||
|
||||
|
@ -25,8 +27,18 @@ type DigitalPin interface {
|
|||
Close() error
|
||||
}
|
||||
|
||||
type AnalogPin interface {
|
||||
N() int
|
||||
|
||||
Write(val int) error
|
||||
Read() (int, error)
|
||||
|
||||
Close() error
|
||||
}
|
||||
|
||||
type GPIO interface {
|
||||
DigitalPin(key interface{}) (DigitalPin, error)
|
||||
AnalogPin(key interface{}) (AnalogPin, error)
|
||||
|
||||
Close() error
|
||||
}
|
||||
|
@ -87,3 +99,25 @@ func ActiveLow(key interface{}, b bool) error {
|
|||
|
||||
return pin.ActiveLow(b)
|
||||
}
|
||||
|
||||
func NewAnalogPin(key interface{}) (AnalogPin, error) {
|
||||
return gpioInstance.AnalogPin(key)
|
||||
}
|
||||
|
||||
func AnalogWrite(key interface{}, val int) error {
|
||||
pin, err := NewAnalogPin(key)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return pin.Write(val)
|
||||
}
|
||||
|
||||
func AnalogRead(key interface{}) (int, error) {
|
||||
pin, err := NewAnalogPin(key)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return pin.Read()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue