Implement servo support for STM32F1 (#11580)
Implement servo support for STM32F1. Original code was incomplete and depended on Servo library from stm32duino which conflicts with `module/servo.h`.
This commit is contained in:
@@ -24,19 +24,34 @@
|
||||
#ifndef HAL_SERVO_STM32F1_H
|
||||
#define HAL_SERVO_STM32F1_H
|
||||
|
||||
// Path needed, otherwise HAL version is used
|
||||
#include <../../libraries/Servo/src/Servo.h>
|
||||
// Pin number of unattached pins
|
||||
#define NOT_ATTACHED (-1)
|
||||
#define INVALID_SERVO 255
|
||||
|
||||
// Inherit and expand on the official library
|
||||
class libServo : public Servo {
|
||||
public:
|
||||
int8_t attach(const int pin);
|
||||
int8_t attach(const int pin, const int min, const int max);
|
||||
void move(const int value);
|
||||
private:
|
||||
uint16_t min_ticks;
|
||||
uint16_t max_ticks;
|
||||
#ifndef MAX_SERVOS
|
||||
#define MAX_SERVOS 3
|
||||
#endif
|
||||
|
||||
#define SERVO_DEFAULT_MIN_PW 544
|
||||
#define SERVO_DEFAULT_MAX_PW 2400
|
||||
#define SERVO_DEFAULT_MIN_ANGLE 0
|
||||
#define SERVO_DEFAULT_MAX_ANGLE 180
|
||||
|
||||
#define HAL_SERVO_LIB libServo
|
||||
|
||||
class libServo {
|
||||
public:
|
||||
libServo();
|
||||
bool attach(const int32_t pin, const int32_t minAngle=SERVO_DEFAULT_MIN_ANGLE, const int32_t maxAngle=SERVO_DEFAULT_MAX_ANGLE);
|
||||
bool attached() const { return this->pin != NOT_ATTACHED; }
|
||||
bool detach();
|
||||
void move(const int32_t value);
|
||||
int32_t read() const;
|
||||
private:
|
||||
uint8_t servoIndex; // index into the channel data for this servo
|
||||
int32_t pin = NOT_ATTACHED;
|
||||
int32_t minAngle;
|
||||
int32_t maxAngle;
|
||||
};
|
||||
|
||||
#endif // HAL_SERVO_STM32F1_H
|
||||
|
||||
Reference in New Issue
Block a user