|
@@ -71,6 +71,8 @@ void set_pwm_duty(const pin_t pin, const uint16_t v, const uint16_t v_size/*=255
|
71
|
71
|
void set_pwm_frequency(const pin_t pin, int f_desired) {
|
72
|
72
|
if (!PWM_PIN(pin)) return; // Don't proceed if no hardware timer
|
73
|
73
|
|
|
74
|
+ const PinName pin_name = digitalPinToPinName(pin);
|
|
75
|
+ TIM_TypeDef * const Instance = (TIM_TypeDef *)pinmap_peripheral(pin_name, PinMap_PWM); // Get HAL timer instance
|
74
|
76
|
uint32_t index = get_timer_index(Instance);
|
75
|
77
|
|
76
|
78
|
// Protect used timers
|
|
@@ -80,8 +82,6 @@ void set_pwm_frequency(const pin_t pin, int f_desired) {
|
80
|
82
|
#endif
|
81
|
83
|
) return;
|
82
|
84
|
|
83
|
|
- const PinName pin_name = digitalPinToPinName(pin);
|
84
|
|
- TIM_TypeDef * const Instance = (TIM_TypeDef *)pinmap_peripheral(pin_name, PinMap_PWM); // Get HAL timer instance
|
85
|
85
|
if (HardwareTimer_Handle[index] == nullptr) // If frequency is set before duty we need to create a handle here.
|
86
|
86
|
HardwareTimer_Handle[index]->__this = new HardwareTimer((TIM_TypeDef *)pinmap_peripheral(pin_name, PinMap_PWM));
|
87
|
87
|
HardwareTimer * const HT = (HardwareTimer *)(HardwareTimer_Handle[index]->__this);
|