Пример #1
0
/*
 * @brief Should take an integer 0-255 and create a PWM signal with a duty cycle from 0-100%
 * and frequency from 1 to 65535 Hz.
 */
void analogWrite(pin_t pin, uint16_t value, uint16_t pwm_frequency)
{
    // Safety check
    if (!pinAvailable(pin))
    {
        return;
    }

    if (HAL_Validate_Pin_Function(pin, PF_TIMER) == PF_TIMER)
    {
        PinMode mode = HAL_Get_Pin_Mode(pin);

        if (mode != OUTPUT && mode != AF_OUTPUT_PUSHPULL)
        {
            return;
        }

        HAL_PWM_Write_With_Frequency(pin, value, pwm_frequency);
    }
}
Пример #2
0
void HAL_Servo_Attach(uint16_t pin) {
    // Set PWM frequency to 50Hz
    HAL_PWM_Write_With_Frequency(pin, 0, SERVO_TIM_PWM_FREQ);
}