diff options
author | px4dev <px4@purgatory.org> | 2012-11-04 16:44:06 -0800 |
---|---|---|
committer | px4dev <px4@purgatory.org> | 2012-11-04 16:44:06 -0800 |
commit | 06e17eae5d6942e3d2c96f3e313707723b217b18 (patch) | |
tree | c2e57cea1266aaeebbb7560eefed357484ea1a5c /apps | |
parent | 487597b3859ee6bee9b0efda1069d15afb7bb29d (diff) | |
download | px4-firmware-06e17eae5d6942e3d2c96f3e313707723b217b18.tar.gz px4-firmware-06e17eae5d6942e3d2c96f3e313707723b217b18.tar.bz2 px4-firmware-06e17eae5d6942e3d2c96f3e313707723b217b18.zip |
Fix off-by-one reading PWM output values. Minor robustness tweaks.
Diffstat (limited to 'apps')
-rw-r--r-- | apps/drivers/stm32/drv_pwm_servo.c | 14 |
1 files changed, 5 insertions, 9 deletions
diff --git a/apps/drivers/stm32/drv_pwm_servo.c b/apps/drivers/stm32/drv_pwm_servo.c index e3801a417..50aa34d81 100644 --- a/apps/drivers/stm32/drv_pwm_servo.c +++ b/apps/drivers/stm32/drv_pwm_servo.c @@ -171,10 +171,8 @@ pwm_channel_init(unsigned channel) int up_pwm_servo_set(unsigned channel, servo_position_t value) { - if (channel >= PWM_SERVO_MAX_CHANNELS) { - lldbg("pwm_channel_set: bogus channel %u\n", channel); + if (channel >= PWM_SERVO_MAX_CHANNELS) return -1; - } unsigned timer = pwm_channels[channel].timer_index; @@ -214,17 +212,15 @@ up_pwm_servo_set(unsigned channel, servo_position_t value) servo_position_t up_pwm_servo_get(unsigned channel) { - if (channel >= PWM_SERVO_MAX_CHANNELS) { - lldbg("pwm_channel_get: bogus channel %u\n", channel); + if (channel >= PWM_SERVO_MAX_CHANNELS) return 0; - } unsigned timer = pwm_channels[channel].timer_index; servo_position_t value = 0; /* test timer for validity */ if ((pwm_timers[timer].base == 0) || - (pwm_channels[channel].gpio == 0)) + (pwm_channels[channel].timer_channel == 0)) return 0; /* configure the channel */ @@ -246,7 +242,7 @@ up_pwm_servo_get(unsigned channel) break; } - return value; + return value + 1; } int @@ -261,7 +257,7 @@ up_pwm_servo_init(uint32_t channel_mask) /* now init channels */ for (unsigned i = 0; i < PWM_SERVO_MAX_CHANNELS; i++) { /* don't do init for disabled channels; this leaves the pin configs alone */ - if (((1 << i) & channel_mask) && (pwm_channels[i].gpio != 0)) + if (((1 << i) & channel_mask) && (pwm_channels[i].timer_channel != 0)) pwm_channel_init(i); } |