4 #include "drivers/io_pca9685.h"
7 #include "fc/runtime_config.h"
9 #include "config/feature.h"
12 #ifdef USE_PWM_SERVO_DRIVER
14 #define PWM_DRIVER_IMPLEMENTATION_COUNT 1
15 #define PWM_DRIVER_MAX_CYCLE 4
17 static bool driverEnabled
= false;
18 static uint8_t driverImplementationIndex
= 0;
21 bool (*initFunction
)(void);
22 void (*writeFunction
)(uint8_t servoIndex
, uint16_t off
);
23 void (*setFrequencyFunction
)(uint16_t freq
);
24 void (*syncFunction
)(uint8_t cycleIndex
);
27 pwmDriverDriver_t pwmDrivers
[PWM_DRIVER_IMPLEMENTATION_COUNT
] = {
29 .initFunction
= pca9685Initialize
,
30 .writeFunction
= pca9685setServoPulse
,
31 .setFrequencyFunction
= pca9685setPWMFreq
,
32 .syncFunction
= pca9685sync
36 bool isPwmDriverEnabled(void) {
40 void pwmDriverSetPulse(uint8_t servoIndex
, uint16_t length
) {
41 (pwmDrivers
[driverImplementationIndex
].writeFunction
)(servoIndex
, length
);
44 void pwmDriverInitialize(void) {
45 driverEnabled
= (pwmDrivers
[driverImplementationIndex
].initFunction
)();
48 ENABLE_STATE(PWM_DRIVER_AVAILABLE
);
50 DISABLE_STATE(PWM_DRIVER_AVAILABLE
);
55 void pwmDriverSync(void) {
56 if (!STATE(PWM_DRIVER_AVAILABLE
)) {
60 static uint8_t cycle
= 0;
62 (pwmDrivers
[driverImplementationIndex
].syncFunction
)(cycle
);
65 if (cycle
== PWM_DRIVER_MAX_CYCLE
) {