NinjaFlight
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
pwm_mapping.h
Go to the documentation of this file.
1 /*
2  * This file is part of Ninjaflight.
3  *
4  * Ninjaflight is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * Ninjaflight is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with Ninjaflight. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #pragma once
19 #include "gpio.h"
20 #include "timer.h"
21 
22 #if USE_QUAD_MIXER_ONLY == 1
23 #define MAX_PWM_MOTORS 4
24 #define MAX_PWM_SERVOS 1
25 #define MAX_MOTORS 4
26 #define MAX_SERVOS 1
27 
28 #elif defined(TARGET_MOTOR_COUNT)
29 #define MAX_PWM_MOTORS TARGET_MOTOR_COUNT
30 #define MAX_PWM_SERVOS 8
31 #define MAX_MOTORS TARGET_MOTOR_COUNT
32 #define MAX_SERVOS 8
33 
34 #else
35 #define MAX_PWM_MOTORS 12
36 #define MAX_PWM_SERVOS 8
37 #define MAX_MOTORS 12
38 #define MAX_SERVOS 8
39 #endif
40 
41 
42 #define PULSE_1MS (1000) // 1ms pulse width
43 
44 #define MAX_INPUTS 8
45 
46 #define PWM_TIMER_MHZ 1
47 #define ONESHOT125_TIMER_MHZ 8
48 #define PWM_BRUSHED_TIMER_MHZ 8
49 
50 
51 typedef struct sonarGPIOConfig_s {
53  uint16_t triggerPin;
54  uint16_t echoPin;
56 
57 typedef struct drv_pwm_config_s {
59  bool usePPM;
61  bool useRSSIADC;
63 #if defined(USE_UART2)
64  bool useUART2;
65 #endif
66 #if defined(USE_UART3)
67  bool useUART3;
68 #endif
69 #if defined(USE_UART4)
70  bool useUART4;
71 #endif
72 #if defined(USE_UART5)
73  bool useUART5;
74 #endif
75  bool useVbat;
76  bool useOneshot;
79 #ifdef SONAR
80  bool useSonar;
81 #endif
82 #ifdef USE_SERVOS
83  bool useServos;
84  bool useChannelForwarding; // configure additional channels as servos
85  uint16_t servoPwmRate;
86  uint16_t servoCenterPulse;
87 #endif
88  bool airplane; // fixed wing hardware config, lots of servos etc
89  uint16_t motorPwmRate;
90  uint16_t idlePulse; // PWM value to use when initializing the driver. set this to either PULSE_1MS (regular pwm),
91  // some higher value (used by 3d mode), or 0, for brushed pwm drivers.
94 
95 
96 typedef enum {
98  PWM_PF_MOTOR = (1 << 0),
99  PWM_PF_SERVO = (1 << 1),
103  PWM_PF_PPM = (1 << 5),
104  PWM_PF_PWM = (1 << 6)
106 
107 
108 typedef struct pwmPortConfiguration_s {
109  uint8_t index;
113 
114 typedef struct pwmIOConfiguration_s {
115  uint8_t servoCount;
116  uint8_t motorCount;
117  uint8_t ioCount;
118  uint8_t pwmInputCount;
119  uint8_t ppmInputCount;
122 
123 // This indexes into the read-only hardware definition structure, timerHardware_t
124 enum {
125  PWM1 = 0,
141 };
142 
143 // TODO: this variable needs to be refactored. Just use it for now as a static flag but later move it into an object.
144 extern bool pwmUseInputFiltering;
145 
146 struct pwm_input_config;
149 
Definition: pwm_mapping.h:130
Definition: pwm_mapping.h:135
Definition: pwm_mapping.h:136
Definition: pwm_mapping.h:133
Definition: timer.h:60
Definition: config.h:81
bool useSoftSerial
Definition: pwm_mapping.h:77
pwmPortFlags_e
Definition: pwm_mapping.h:96
Definition: pwm_mapping.h:132
uint16_t servoCenterPulse
Definition: mixer.h:16
Definition: pwm_mapping.h:139
pwmPortConfiguration_t ioConfigurations[USABLE_TIMER_CHANNEL_COUNT]
Definition: pwm_mapping.h:120
Definition: pwm_mapping.h:129
bool useCurrentMeterADC
Definition: pwm_mapping.h:62
Definition: pwm_mapping.h:128
uint16_t triggerPin
Definition: pwm_mapping.h:53
uint8_t motorCount
Definition: pwm_mapping.h:116
Definition: pwm_mapping.h:51
bool useVbat
Definition: pwm_mapping.h:75
bool useLEDStrip
Definition: pwm_mapping.h:78
bool usePPM
Definition: pwm_mapping.h:59
pwmPortFlags_e flags
Definition: pwm_mapping.h:110
pwmIOConfiguration_t * pwmGetOutputConfiguration(void)
Definition: pwm_mapping.c:637
Definition: pwm_mapping.h:138
Definition: platform.h:43
Definition: pwm_mapping.h:131
GPIO_TypeDef * gpio
Definition: pwm_mapping.h:52
const timerHardware_t * timerHardware
Definition: pwm_mapping.h:111
struct pwmIOConfiguration_s pwmIOConfiguration_t
uint8_t ioCount
Definition: pwm_mapping.h:117
Definition: pwm_mapping.h:108
Definition: pwm_mapping.h:103
uint16_t echoPin
Definition: pwm_mapping.h:54
uint8_t ppmInputCount
Definition: pwm_mapping.h:119
Definition: pwm_rx.h:29
Definition: pwm_mapping.h:127
Definition: pwm_mapping.h:104
bool useRSSIADC
Definition: pwm_mapping.h:61
bool useSerialRx
Definition: pwm_mapping.h:60
Definition: pwm_mapping.h:97
bool airplane
Definition: pwm_mapping.h:88
Definition: pwm_mapping.h:134
Definition: pwm_mapping.h:57
Definition: pwm_mapping.h:114
Definition: pwm_mapping.h:101
struct pwmPortConfiguration_s pwmPortConfiguration_t
struct drv_pwm_config_s drv_pwm_config_t
Definition: pwm_mapping.h:140
Definition: pwm_mapping.h:125
bool useParallelPWM
Definition: pwm_mapping.h:58
bool useOneshot
Definition: pwm_mapping.h:76
Definition: pwm_mapping.h:100
Definition: pwm_mapping.h:126
bool pwmUseInputFiltering
Definition: pwm_mapping.c:645
struct sonarGPIOConfig_s sonarGPIOConfig_t
Definition: pwm_mapping.h:102
Definition: pwm_mapping.h:137
uint16_t idlePulse
Definition: pwm_mapping.h:90
#define USABLE_TIMER_CHANNEL_COUNT
Definition: timer.h:21
sonarGPIOConfig_t * sonarGPIOConfig
Definition: pwm_mapping.h:92
uint8_t pwmInputCount
Definition: pwm_mapping.h:118
Definition: pwm_mapping.h:99
pwmIOConfiguration_t * pwmInit(drv_pwm_config_t *init, const struct pwm_input_config *config)
Definition: pwm_mapping.c:647
uint16_t motorPwmRate
Definition: pwm_mapping.h:89
uint8_t servoCount
Definition: pwm_mapping.h:115
Definition: pwm_mapping.h:98
uint8_t index
Definition: pwm_mapping.h:109