Enabling servo usage on boards with PWM current control
timer5 is used by some boards like the Mini Rambo for controlling motor current via PWM, see stepper.cpp.
```cpp
#ifdef MOTOR_CURRENT_PWM_XY_PIN
pinMode(MOTOR_CURRENT_PWM_XY_PIN, OUTPUT);
pinMode(MOTOR_CURRENT_PWM_Z_PIN, OUTPUT);
pinMode(MOTOR_CURRENT_PWM_E_PIN, OUTPUT);
digipot_current(0, motor_current_setting[0]);
digipot_current(1, motor_current_setting[1]);
digipot_current(2, motor_current_setting[2]);
//Set timer5 to 31khz so the PWM of the motor power is as constant as possible. (removes a buzzing noise)
TCCR5B = (TCCR5B & ~(_BV(CS50) | _BV(CS51) | _BV(CS52))) | _BV(CS50);
#endif
}
```
Using the same timer for controlling servos results in loss of motor control. So use timer4/3 for those boards instead.
[See discussion here.](http://shop.prusa3d.com/forum/software-f13/enabling-auto-leveling-in-firmware-t416-s40.html)
Just set up the pin. Don't move to a random position.
Simplify servo::move()
* servo::move() does not need the pin parameter - The pin is set during servo_init() with attach().
* servo::move() does not need a return value.
SERVO_LEVELING is the wrong condition to deactivate the servos.
Remove some temporary (Servo *) variables.
SanityCheck for the servo indexes.
- Have `Servo::attach` explicitly return -1 if it fails
- Check for -1 in `Servo::move` because `servoIndex` might be 0
- Make `attach` / `detach` calls conditional on `SERVO_LEVELING`
- Move `SERVO_LEVELING` define to `Conditionals.h`
move(pin, angel) - Sequence of attach(pin), write(angel),
if DEACTIVATE_SERVOS_AFTER_MOVE is defined waits SERVO_DEACTIVATION_DELAY, than detaches.
As we have jitter on the servos during moves of the steppers, and detaching them improves this behaviour,
the usual sequence to handle a servo movement is:
attach(pin)
write(angel)
delay(until the servo finished the move)
detache()
Here a function to handle the complete sequence.