mirror of
https://github.com/stianeikeland/go-rpio.git
synced 2025-01-23 02:31:05 +01:00
add func ReadMode、ReadPinMode。
get gpio mod
This commit is contained in:
parent
acc952dac3
commit
842c7d503f
22
rpio.go
22
rpio.go
|
@ -286,6 +286,11 @@ func (pin Pin) EdgeDetected() bool {
|
|||
return EdgeDetected(pin)
|
||||
}
|
||||
|
||||
// Get gpio mode
|
||||
func (pin Pin) ReadMode() uint32 {
|
||||
return ReadPinMode(pin)
|
||||
}
|
||||
|
||||
// PinMode sets the mode of a given pin (Input, Output, Clock, Pwm or Spi)
|
||||
//
|
||||
// Clock is possible only for pins 4, 5, 6, 20, 21.
|
||||
|
@ -366,6 +371,21 @@ func PinMode(pin Pin, mode Mode) {
|
|||
gpioMem[fselReg] = (gpioMem[fselReg] &^ (pinMask << shift)) | (f << shift)
|
||||
}
|
||||
|
||||
// Read pin Mod status。(gpio readall)
|
||||
// const in = 0 // 000
|
||||
// const out = 1 // 001
|
||||
// const alt0 = 4 // 100
|
||||
// const alt1 = 5 // 101
|
||||
// const alt2 = 6 // 110
|
||||
// const alt3 = 7 // 111
|
||||
// const alt4 = 3 // 011
|
||||
// const alt5 = 2 // 010
|
||||
func ReadPinMode(pin Pin) uint32 {
|
||||
fselReg := uint8(pin) / 10
|
||||
shift := (uint8(pin) % 10) * 3
|
||||
return gpioMem[fselReg] >> shift & 7
|
||||
}
|
||||
|
||||
// WritePin sets a given pin High or Low
|
||||
// by setting the clear or set registers respectively
|
||||
func WritePin(pin Pin, state State) {
|
||||
|
@ -497,7 +517,7 @@ func PullMode(pin Pin, pull Pull) {
|
|||
case PullUp:
|
||||
p = 1
|
||||
case PullDown:
|
||||
p = 2;
|
||||
p = 2
|
||||
}
|
||||
|
||||
// This is verbatim C code from raspi-gpio.c
|
||||
|
|
Loading…
Reference in New Issue
Block a user