mirror of
https://github.com/stianeikeland/go-rpio.git
synced 2025-01-23 10:41:03 +01:00
Use /mem/dev primarily - it is needed for clock settings to work
This commit is contained in:
parent
95bb91625f
commit
ec703e92e8
10
rpio.go
10
rpio.go
|
@ -358,9 +358,7 @@ func SetFreq(pin Pin, freq int) {
|
||||||
|
|
||||||
clkMem[clkCtlReg] = PASSWORD | mash | src | enab // finally start clock
|
clkMem[clkCtlReg] = PASSWORD | mash | src | enab // finally start clock
|
||||||
|
|
||||||
for clkMem[clkCtlReg]&busy == 0 {
|
// NOTE without root permission this changes will simply do nothing successfully
|
||||||
time.Sleep(time.Microsecond * 10)
|
|
||||||
} // ... and wait for busy, just to be sure
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Open and memory map GPIO memory range from /dev/mem .
|
// Open and memory map GPIO memory range from /dev/mem .
|
||||||
|
@ -368,10 +366,10 @@ func SetFreq(pin Pin, freq int) {
|
||||||
func Open() (err error) {
|
func Open() (err error) {
|
||||||
var file *os.File
|
var file *os.File
|
||||||
|
|
||||||
// Open fd for rw mem access; try gpiomem first
|
// Open fd for rw mem access; try dev/mem first (need root)
|
||||||
file, err = os.OpenFile("/dev/gpiomem", os.O_RDWR|os.O_SYNC, 0)
|
|
||||||
if os.IsNotExist(err) { // try mem (need root)
|
|
||||||
file, err = os.OpenFile("/dev/mem", os.O_RDWR|os.O_SYNC, 0)
|
file, err = os.OpenFile("/dev/mem", os.O_RDWR|os.O_SYNC, 0)
|
||||||
|
if os.IsPermission(err) { // try gpiomem otherwise (some extra functions like clock setting wont work)
|
||||||
|
file, err = os.OpenFile("/dev/gpiomem", os.O_RDWR|os.O_SYNC, 0)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in New Issue
Block a user