From 3dee42b5ca737601671af0ca57c243d44ed69ebf Mon Sep 17 00:00:00 2001 From: Mohammed Kabir Date: Tue, 11 Apr 2017 12:23:53 +0200 Subject: [PATCH] stm32 : deconflict pwm_get_rate_group from all other timer modes --- src/drivers/stm32/drv_io_timer.c | 6 ++---- src/drivers/stm32/drv_pwm_servo.c | 16 +++++++++++----- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/drivers/stm32/drv_io_timer.c b/src/drivers/stm32/drv_io_timer.c index f4ae16beb9..9f3c0d2a64 100644 --- a/src/drivers/stm32/drv_io_timer.c +++ b/src/drivers/stm32/drv_io_timer.c @@ -125,8 +125,8 @@ #else #define CCER_C1_INIT GTIM_CCER_CC1E #endif -// NotUsed PWMOut PWMIn Capture OneShot -io_timer_channel_allocation_t channel_allocations[IOTimerChanModeSize] = { UINT8_MAX, 0, 0, 0, 0 }; +// NotUsed PWMOut PWMIn Capture OneShot Trigger +io_timer_channel_allocation_t channel_allocations[IOTimerChanModeSize] = { UINT8_MAX, 0, 0, 0, 0, 0 }; typedef uint8_t io_timer_allocation_t; /* big enough to hold MAX_IO_TIMERS */ @@ -578,7 +578,6 @@ int io_timer_set_rate(unsigned timer, unsigned rate) /* Check that all channels are either in PWM or Oneshot */ if ((channels & (channel_allocations[IOTimerChanMode_PWMOut] | - channel_allocations[IOTimerChanMode_Trigger] | channel_allocations[IOTimerChanMode_OneShot] | channel_allocations[IOTimerChanMode_NotUsed])) == channels) { @@ -813,7 +812,6 @@ int io_timer_set_enable(bool state, io_timer_channel_mode_t mode, io_timer_chann rvalue |= action_cache[actions].dier_setbits; _REG32(action_cache[actions].base, STM32_GTIM_DIER_OFFSET) = rvalue; - /* Any On ?*/ if (after != 0) { diff --git a/src/drivers/stm32/drv_pwm_servo.c b/src/drivers/stm32/drv_pwm_servo.c index 5dfe9690ff..b75772ebc4 100644 --- a/src/drivers/stm32/drv_pwm_servo.c +++ b/src/drivers/stm32/drv_pwm_servo.c @@ -76,9 +76,10 @@ servo_position_t up_pwm_servo_get(unsigned channel) int up_pwm_servo_init(uint32_t channel_mask) { /* Init channels */ - uint32_t current = io_timer_get_mode_channels(IOTimerChanMode_PWMOut); + uint32_t current = io_timer_get_mode_channels(IOTimerChanMode_PWMOut) | + io_timer_get_mode_channels(IOTimerChanMode_OneShot); - // First free the current set of PWMs + /* First free the current set of PWMs */ for (unsigned channel = 0; current != 0 && channel < MAX_TIMER_IO_CHANNELS; channel++) { if (current & (1 << channel)) { @@ -88,17 +89,19 @@ int up_pwm_servo_init(uint32_t channel_mask) } - // Now allocate the new set + /* Now allocate the new set */ for (unsigned channel = 0; channel_mask != 0 && channel < MAX_TIMER_IO_CHANNELS; channel++) { if (channel_mask & (1 << channel)) { - // First free any that were not PWM mode before + /* First free any that were not PWM mode before */ if (-EBUSY == io_timer_is_channel_free(channel)) { io_timer_free_channel(channel); } + /* OneShot is set later, with the set_rate_group_update call. Init to PWM mode for now */ + io_timer_channel_init(channel, IOTimerChanMode_PWMOut, NULL, NULL); channel_mask &= ~(1 << channel); } @@ -153,7 +156,10 @@ int up_pwm_servo_set_rate(unsigned rate) uint32_t up_pwm_servo_get_rate_group(unsigned group) { - return io_timer_get_group(group); + /* only return the set of channels in the group which we own */ + return (io_timer_get_mode_channels(IOTimerChanMode_PWMOut) | + io_timer_get_mode_channels(IOTimerChanMode_OneShot)) & + io_timer_get_group(group); } void