mirror of
https://github.com/stianeikeland/go-rpio.git
synced 2025-01-23 10:41:03 +01:00
Fix pwmMem and some pwm Regs
This commit is contained in:
parent
7445bb69a5
commit
b1c90c6087
17
rpio.go
17
rpio.go
|
@ -363,7 +363,7 @@ func SetFreq(pin Pin, freq int) {
|
||||||
case 12, 13, 40, 41, 45, 18, 19: // pwm_clk - shared clk for both pwm chanels
|
case 12, 13, 40, 41, 45, 18, 19: // pwm_clk - shared clk for both pwm chanels
|
||||||
clkCtlReg += 12
|
clkCtlReg += 12
|
||||||
clkDivReg += 13
|
clkDivReg += 13
|
||||||
StopPwm()
|
StopPwm() // pwm clk busy wont go down without stopping pwm first
|
||||||
defer StartPwm()
|
defer StartPwm()
|
||||||
default:
|
default:
|
||||||
return
|
return
|
||||||
|
@ -418,11 +418,11 @@ func SetDutyCycle(pin Pin, dutyLen, cycleLen uint32) {
|
||||||
|
|
||||||
switch pin {
|
switch pin {
|
||||||
case 12, 18, 40: // chanel pwm0
|
case 12, 18, 40: // chanel pwm0
|
||||||
pwmDatReg = 4
|
pwmRngReg = 4
|
||||||
pwmRngReg = 5
|
pwmDatReg = 5
|
||||||
shift = 0
|
shift = 0
|
||||||
case 13, 19, 41, 45: // chanel pwm1
|
case 13, 19, 41, 45: // chanel pwm1
|
||||||
pwmDatReg = 8
|
pwmRngReg = 8
|
||||||
pwmDatReg = 9
|
pwmDatReg = 9
|
||||||
shift = 8
|
shift = 8
|
||||||
default:
|
default:
|
||||||
|
@ -430,14 +430,17 @@ func SetDutyCycle(pin Pin, dutyLen, cycleLen uint32) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const ctlMask = 255 // ctl setting has 8 bits for each chanel
|
const ctlMask = 255 // ctl setting has 8 bits for each chanel
|
||||||
|
const pwen = 1 << 0 // enable pwm
|
||||||
const msen = 1 << 7 // use M/S transition instead of pwm algorithm
|
const msen = 1 << 7 // use M/S transition instead of pwm algorithm
|
||||||
|
|
||||||
// reset settings
|
// reset settings
|
||||||
pwmMem[pwmCtlReg] = pwmMem[pwmCtlReg]&^(ctlMask<<shift) | msen<<shift
|
pwmMem[pwmCtlReg] = pwmMem[pwmCtlReg]&^(ctlMask<<shift) | msen<<shift | pwen <<shift
|
||||||
// set duty cycle
|
// set duty cycle
|
||||||
pwmMem[pwmDatReg] = dutyLen
|
pwmMem[pwmDatReg] = dutyLen
|
||||||
pwmMem[pwmRngReg] = cycleLen
|
pwmMem[pwmRngReg] = cycleLen
|
||||||
time.Sleep(time.Microsecond * 10)
|
time.Sleep(time.Microsecond * 10)
|
||||||
|
|
||||||
|
// NOTE without root permission this changes will simply do nothing successfully
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stop pwm for both chanels
|
// Stop pwm for both chanels
|
||||||
|
@ -447,7 +450,7 @@ func StopPwm() {
|
||||||
pwmMem[pwmCtlReg] = pwmMem[pwmCtlReg] &^ (pwen<<8 | pwen)
|
pwmMem[pwmCtlReg] = pwmMem[pwmCtlReg] &^ (pwen<<8 | pwen)
|
||||||
}
|
}
|
||||||
|
|
||||||
// start pwm for both chanels
|
// Start pwm for both chanels
|
||||||
func StartPwm() {
|
func StartPwm() {
|
||||||
const pwmCtlReg = 0
|
const pwmCtlReg = 0
|
||||||
const pwen = 1
|
const pwen = 1
|
||||||
|
@ -485,7 +488,7 @@ func Open() (err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
pwmMem, pwmMem8, err = memMap(file.Fd(), clkBase)
|
pwmMem, pwmMem8, err = memMap(file.Fd(), pwmBase)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user