sam: return an error when an incorrect PWM pin is used

Previously it would trigger a nil pointer panic.
This commit is contained in:
Ayke van Laethem
2020-05-11 16:02:00 +02:00
committed by Ron Evans
parent b5f028e1f7
commit 38fc340802
7 changed files with 84 additions and 51 deletions
+2 -1
View File
@@ -79,13 +79,14 @@ func InitPWM() {
}
// Configure configures a PWM pin for output.
func (pwm PWM) Configure() {
func (pwm PWM) Configure() error {
switch pwm.Pin / 8 {
case 0: // port B
avr.DDRB.SetBits(1 << uint8(pwm.Pin))
case 2: // port D
avr.DDRD.SetBits(1 << uint8(pwm.Pin-16))
}
return nil
}
// Set turns on the duty cycle for a PWM pin using the provided value. On the AVR this is normally a