Merge pull request #11297 from SteveCEvans/baro_state
[betaflight.git] / src / main / drivers / pwm_output.h
blob21b7de0078dbc0495a7a0df94401cdcfa50b4aeb
1 /*
2 * This file is part of Cleanflight and Betaflight.
4 * Cleanflight and Betaflight are free software. You can redistribute
5 * this software and/or modify this software under the terms of the
6 * GNU General Public License as published by the Free Software
7 * Foundation, either version 3 of the License, or (at your option)
8 * any later version.
10 * Cleanflight and Betaflight are distributed in the hope that they
11 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
12 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this software.
18 * If not, see <http://www.gnu.org/licenses/>.
21 #pragma once
23 #include "platform.h"
25 #include "common/time.h"
27 #include "drivers/dma.h"
28 #include "drivers/io_types.h"
29 #include "drivers/motor.h"
30 #include "drivers/timer.h"
32 #define BRUSHED_MOTORS_PWM_RATE 16000
33 #define BRUSHLESS_MOTORS_PWM_RATE 480
35 #define ALL_MOTORS 255
37 #define MOTOR_OUTPUT_LIMIT_PERCENT_MIN 1
38 #define MOTOR_OUTPUT_LIMIT_PERCENT_MAX 100
40 #define PWM_TIMER_1MHZ MHZ_TO_HZ(1)
42 struct timerHardware_s;
44 typedef struct {
45 volatile timCCR_t *ccr;
46 TIM_TypeDef *tim;
47 } timerChannel_t;
49 typedef struct {
50 timerChannel_t channel;
51 float pulseScale;
52 float pulseOffset;
53 bool forceOverflow;
54 bool enabled;
55 IO_t io;
56 } pwmOutputPort_t;
58 extern FAST_DATA_ZERO_INIT pwmOutputPort_t motors[MAX_SUPPORTED_MOTORS];
60 struct motorDevConfig_s;
61 motorDevice_t *motorPwmDevInit(const struct motorDevConfig_s *motorDevConfig, uint16_t idlePulse, uint8_t motorCount, bool useUnsyncedPwm);
63 typedef struct servoDevConfig_s {
64 // PWM values, in milliseconds, common range is 1000-2000 (1ms to 2ms)
65 uint16_t servoCenterPulse; // This is the value for servos when they should be in the middle. e.g. 1500.
66 uint16_t servoPwmRate; // The update rate of servo outputs (50-498Hz)
67 ioTag_t ioTags[MAX_SUPPORTED_SERVOS];
68 } servoDevConfig_t;
70 void servoDevInit(const servoDevConfig_t *servoDevConfig);
72 void pwmServoConfig(const struct timerHardware_s *timerHardware, uint8_t servoIndex, uint16_t servoPwmRate, uint16_t servoCenterPulse);
74 void pwmOutConfig(timerChannel_t *channel, const timerHardware_t *timerHardware, uint32_t hz, uint16_t period, uint16_t value, uint8_t inversion);
76 void pwmWriteServo(uint8_t index, float value);
78 pwmOutputPort_t *pwmGetMotors(void);
79 bool pwmIsSynced(void);