1
0
Fork 0
mirror of https://github.com/iNavFlight/inav.git synced 2025-07-26 01:35:35 +03:00

PCA9685 PWM driver support (#261)

* 1st stage of PCA9685 PWM driver support
* Servo output to PCA9685 in NAZE target.
* FEATURE_PWM_SERVO_DRIVER introduced
* task for PWM driver
* abstraction layer for pwm drivers
* feature enabled only on target with >128 flash
This commit is contained in:
Paweł Spychalski 2016-09-15 11:59:27 +02:00 committed by Konstantin Sharlaimov
parent 46fee424be
commit 425c6e6499
16 changed files with 270 additions and 5 deletions

View file

@ -0,0 +1,57 @@
#include <stdbool.h>
#include <stdint.h>
#include "drivers/io_pca9685.h"
#include "config/config.h"
#include "fc/runtime_config.h"
#include "config/feature.h"
#define PWM_DRIVER_IMPLEMENTATION_COUNT 1
#define PWM_DRIVER_MAX_CYCLE 4
static bool driverEnabled = false;
static uint8_t driverImplementationIndex = 0;
typedef struct {
bool (*initFunction)(void);
void (*writeFunction)(uint8_t servoIndex, uint16_t off);
void (*setFrequencyFunction)(float freq);
void (*syncFunction)(uint8_t cycleIndex);
} pwmDriverDriver_t;
pwmDriverDriver_t pwmDrivers[PWM_DRIVER_IMPLEMENTATION_COUNT] = {
[0] = {
.initFunction = pca9685Initialize,
.writeFunction = pca9685setServoPulse,
.setFrequencyFunction = pca9685setPWMFreq,
.syncFunction = pca9685sync
}
};
bool isPwmDriverEnabled() {
return driverEnabled;
}
void pwmDriverSetPulse(uint8_t servoIndex, uint16_t length) {
(pwmDrivers[driverImplementationIndex].writeFunction)(servoIndex, length);
}
void pwmDriverInitialize(void) {
driverEnabled = (pwmDrivers[driverImplementationIndex].initFunction)();
if (!driverEnabled) {
featureClear(FEATURE_PWM_SERVO_DRIVER);
}
}
void pwmDriverSync(void) {
static uint8_t cycle = 0;
(pwmDrivers[driverImplementationIndex].syncFunction)(cycle);
cycle++;
if (cycle == PWM_DRIVER_MAX_CYCLE) {
cycle = 0;
}
}