Skip to content

Commit 76aed2b

Browse files
committed
refactor(analog): move get_pwm_channel to timer api
Moved from analog.* to timer.*. Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
1 parent bcf0574 commit 76aed2b

File tree

4 files changed

+30
-27
lines changed

4 files changed

+30
-27
lines changed

cores/arduino/stm32/analog.h

-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ uint16_t adc_read_value(PinName pin, uint32_t resolution);
5656
void pwm_start(PinName pin, uint32_t clock_freq, uint32_t value, TimerCompareFormat_t resolution);
5757
void pwm_stop(PinName pin);
5858
#endif
59-
uint32_t get_pwm_channel(PinName pin);
6059

6160
#ifdef __cplusplus
6261
}

cores/arduino/stm32/timer.h

+2
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,8 @@ uint8_t getTimerClkSrc(TIM_TypeDef *tim);
284284
IRQn_Type getTimerUpIrq(TIM_TypeDef *tim);
285285
IRQn_Type getTimerCCIrq(TIM_TypeDef *tim);
286286

287+
uint32_t get_pwm_channel(PinName pin);
288+
287289
#endif /* HAL_TIM_MODULE_ENABLED && !HAL_TIM_MODULE_ONLY */
288290

289291
#ifdef __cplusplus

libraries/SrcWrapper/src/stm32/analog.cpp

-26
Original file line numberDiff line numberDiff line change
@@ -270,32 +270,6 @@ static uint32_t get_adc_internal_channel(PinName pin)
270270
}
271271
#endif /* HAL_ADC_MODULE_ENABLED && !HAL_ADC_MODULE_ONLY */
272272

273-
#if defined(HAL_TIM_MODULE_ENABLED) && !defined(HAL_TIM_MODULE_ONLY)
274-
uint32_t get_pwm_channel(PinName pin)
275-
{
276-
uint32_t function = pinmap_function(pin, PinMap_TIM);
277-
uint32_t channel = 0;
278-
switch (STM_PIN_CHANNEL(function)) {
279-
case 1:
280-
channel = TIM_CHANNEL_1;
281-
break;
282-
case 2:
283-
channel = TIM_CHANNEL_2;
284-
break;
285-
case 3:
286-
channel = TIM_CHANNEL_3;
287-
break;
288-
case 4:
289-
channel = TIM_CHANNEL_4;
290-
break;
291-
default:
292-
channel = 0;
293-
break;
294-
}
295-
return channel;
296-
}
297-
#endif /* HAL_TIM_MODULE_ENABLED && !HAL_TIM_MODULE_ONLY */
298-
299273
#if defined(HAL_DAC_MODULE_ENABLED) && !defined(HAL_DAC_MODULE_ONLY)
300274
static uint32_t get_dac_channel(PinName pin)
301275
{

libraries/SrcWrapper/src/stm32/timer.c

+28
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,34 @@ uint8_t getTimerClkSrc(TIM_TypeDef *tim)
715715
return clkSrc;
716716
}
717717

718+
/**
719+
* @brief Return HAL timer channel linked to a PinName
720+
* @param pin: PinName
721+
* @retval HAL channel. return 0 if pin has no timer
722+
*/
723+
uint32_t get_pwm_channel(PinName pin)
724+
{
725+
uint32_t function = pinmap_function(pin, PinMap_TIM);
726+
uint32_t channel = 0;
727+
switch (STM_PIN_CHANNEL(function)) {
728+
case 1:
729+
channel = TIM_CHANNEL_1;
730+
break;
731+
case 2:
732+
channel = TIM_CHANNEL_2;
733+
break;
734+
case 3:
735+
channel = TIM_CHANNEL_3;
736+
break;
737+
case 4:
738+
channel = TIM_CHANNEL_4;
739+
break;
740+
default:
741+
channel = 0;
742+
break;
743+
}
744+
return channel;
745+
}
718746

719747
#endif /* HAL_TIM_MODULE_ENABLED && !HAL_TIM_MODULE_ONLY */
720748

0 commit comments

Comments
 (0)