4 #include "drivers/io_pca9685.h"
7 #include "fc/runtime_config.h"
9 #include "config/feature.h"
11 #define PWM_DRIVER_IMPLEMENTATION_COUNT 1
12 #define PWM_DRIVER_MAX_CYCLE 4
14 static bool driverEnabled
= false;
15 static uint8_t driverImplementationIndex
= 0;
18 bool (*initFunction
)(void);
19 void (*writeFunction
)(uint8_t servoIndex
, uint16_t off
);
20 void (*setFrequencyFunction
)(uint16_t freq
);
21 void (*syncFunction
)(uint8_t cycleIndex
);
24 pwmDriverDriver_t pwmDrivers
[PWM_DRIVER_IMPLEMENTATION_COUNT
] = {
26 .initFunction
= pca9685Initialize
,
27 .writeFunction
= pca9685setServoPulse
,
28 .setFrequencyFunction
= pca9685setPWMFreq
,
29 .syncFunction
= pca9685sync
33 bool isPwmDriverEnabled() {
37 void pwmDriverSetPulse(uint8_t servoIndex
, uint16_t length
) {
38 (pwmDrivers
[driverImplementationIndex
].writeFunction
)(servoIndex
, length
);
41 void pwmDriverInitialize(void) {
42 driverEnabled
= (pwmDrivers
[driverImplementationIndex
].initFunction
)();
45 ENABLE_STATE(PWM_DRIVER_AVAILABLE
);
47 DISABLE_STATE(PWM_DRIVER_AVAILABLE
);
52 void pwmDriverSync(void) {
53 static uint8_t cycle
= 0;
55 (pwmDrivers
[driverImplementationIndex
].syncFunction
)(cycle
);
58 if (cycle
== PWM_DRIVER_MAX_CYCLE
) {