Paparazzi UAS  v6.0_unstable-53-gfe8bbd3-dirty
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
actuators_pwm_arch.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2013 AggieAir, A Remote Sensing Unmanned Aerial System for Scientific Applications
3  * Utah State University, http://aggieair.usu.edu/
4  *
5  * Michal Podhradsky (michal.podhradsky@aggiemail.usu.edu)
6  * Calvin Coopmans (c.r.coopmans@ieee.org)
7  *
8  *
9  * This file is part of paparazzi.
10  *
11  * paparazzi is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2, or (at your option)
14  * any later version.
15  *
16  * paparazzi is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with paparazzi; see the file COPYING. If not, write to
23  * the Free Software Foundation, 59 Temple Place - Suite 330,
24  * Boston, MA 02111-1307, USA.
25  */
33 #include "subsystems/actuators/actuators_pwm_arch.h"
35 #include "mcu_periph/gpio.h"
36 
37 
46 #ifndef PWM_CMD_TO_US
47 #define PWM_CMD_TO_US(_t) (PWM_FREQUENCY * _t / 1000000)
48 #endif
49 
51 
61  __attribute__((unused)) static void pwmpcb(PWMDriver *pwmp __attribute__((unused))) {}
62 
63 #if PWM_CONF_TIM1
64 static PWMConfig pwmcfg1 = PWM_CONF1_DEF;
65 #endif
66 #if PWM_CONF_TIM2
67 static PWMConfig pwmcfg2 = PWM_CONF2_DEF;
68 #endif
69 #if PWM_CONF_TIM3
70 static PWMConfig pwmcfg3 = PWM_CONF3_DEF;
71 #endif
72 #if PWM_CONF_TIM4
73 static PWMConfig pwmcfg4 = PWM_CONF4_DEF;
74 #endif
75 #if PWM_CONF_TIM5
76 static PWMConfig pwmcfg5 = PWM_CONF5_DEF;
77 #endif
78 #if PWM_CONF_TIM8
79 static PWMConfig pwmcfg8 = PWM_CONF8_DEF;
80 #endif
81 #if PWM_CONF_TIM9
82 static PWMConfig pwmcfg9 = PWM_CONF9_DEF;
83 #endif
84 #if PWM_CONF_TIM10
85 static PWMConfig pwmcfg10 = PWM_CONF10_DEF;
86 #endif
87 #if PWM_CONF_TIM11
88 static PWMConfig pwmcfg11 = PWM_CONF11_DEF;
89 #endif
90 #if PWM_CONF_TIM12
91 static PWMConfig pwmcfg12 = PWM_CONF12_DEF;
92 #endif
93 
94 
96 {
97  /*----------------
98  * Configure GPIO
99  *----------------*/
100 #ifdef PWM_SERVO_0
102 #endif
103 #ifdef PWM_SERVO_1
105 #endif
106 #ifdef PWM_SERVO_2
108 #endif
109 #ifdef PWM_SERVO_3
111 #endif
112 #ifdef PWM_SERVO_4
114 #endif
115 #ifdef PWM_SERVO_5
117 #endif
118 #ifdef PWM_SERVO_6
120 #endif
121 #ifdef PWM_SERVO_7
123 #endif
124 #ifdef PWM_SERVO_8
126 #endif
127 #ifdef PWM_SERVO_9
129 #endif
130 #ifdef PWM_SERVO_10
132 #endif
133 #ifdef PWM_SERVO_11
134  gpio_setup_pin_af(PWM_SERVO_11_GPIO, PWM_SERVO_11_PIN, PWM_SERVO_11_AF, true);
135 #endif
136 #ifdef PWM_SERVO_12
137  gpio_setup_pin_af(PWM_SERVO_12_GPIO, PWM_SERVO_12_PIN, PWM_SERVO_12_AF, true);
138 #endif
139 #ifdef PWM_SERVO_13
140  gpio_setup_pin_af(PWM_SERVO_13_GPIO, PWM_SERVO_13_PIN, PWM_SERVO_13_AF, true);
141 #endif
142 #ifdef PWM_SERVO_14
143  gpio_setup_pin_af(PWM_SERVO_14_GPIO, PWM_SERVO_14_PIN, PWM_SERVO_14_AF, true);
144 #endif
145 #ifdef PWM_SERVO_15
146  gpio_setup_pin_af(PWM_SERVO_15_GPIO, PWM_SERVO_15_PIN, PWM_SERVO_15_AF, true);
147 #endif
148 #ifdef PWM_SERVO_16
149  gpio_setup_pin_af(PWM_SERVO_16_GPIO, PWM_SERVO_16_PIN, PWM_SERVO_16_AF, true);
150 #endif
151 
152  /*---------------
153  * Configure PWM
154  *---------------*/
155 #if PWM_CONF_TIM1
156  pwmStart(&PWMD1, &pwmcfg1);
157 #endif
158 #if PWM_CONF_TIM2
159  pwmStart(&PWMD2, &pwmcfg2);
160 #endif
161 #if PWM_CONF_TIM3
162  pwmStart(&PWMD3, &pwmcfg3);
163 #endif
164 #if PWM_CONF_TIM4
165  pwmStart(&PWMD4, &pwmcfg4);
166 #endif
167 #if PWM_CONF_TIM5
168  pwmStart(&PWMD5, &pwmcfg5);
169 #endif
170 #if PWM_CONF_TIM8
171  pwmStart(&PWMD8, &pwmcfg8);
172 #endif
173 #if PWM_CONF_TIM9
174  pwmStart(&PWMD9, &pwmcfg9);
175 #endif
176 #if PWM_CONF_TIM10
177  pwmStart(&PWMD10, &pwmcfg10);
178 #endif
179 #if PWM_CONF_TIM11
180  pwmStart(&PWMD11, &pwmcfg11);
181 #endif
182 #if PWM_CONF_TIM12
183  pwmStart(&PWMD12, &pwmcfg12);
184 #endif
185 }
186 
187 
189 {
190 #ifdef PWM_SERVO_0
192 #endif
193 #ifdef PWM_SERVO_1
195 #endif
196 #ifdef PWM_SERVO_2
198 #endif
199 #ifdef PWM_SERVO_3
201 #endif
202 #ifdef PWM_SERVO_4
204 #endif
205 #ifdef PWM_SERVO_5
207 #endif
208 #ifdef PWM_SERVO_6
210 #endif
211 #ifdef PWM_SERVO_7
213 #endif
214 #ifdef PWM_SERVO_8
216 #endif
217 #ifdef PWM_SERVO_9
219 #endif
220 #ifdef PWM_SERVO_10
222 #endif
223 #ifdef PWM_SERVO_11
224  pwmEnableChannel(&PWM_SERVO_11_DRIVER, PWM_SERVO_11_CHANNEL, PWM_CMD_TO_US(actuators_pwm_values[PWM_SERVO_11]));
225 #endif
226 #ifdef PWM_SERVO_12
227  pwmEnableChannel(&PWM_SERVO_12_DRIVER, PWM_SERVO_12_CHANNEL, PWM_CMD_TO_US(actuators_pwm_values[PWM_SERVO_12]));
228 #endif
229 #ifdef PWM_SERVO_13
230  pwmEnableChannel(&PWM_SERVO_13_DRIVER, PWM_SERVO_13_CHANNEL, PWM_CMD_TO_US(actuators_pwm_values[PWM_SERVO_13]));
231 #endif
232 #ifdef PWM_SERVO_14
233  pwmEnableChannel(&PWM_SERVO_14_DRIVER, PWM_SERVO_14_CHANNEL, PWM_CMD_TO_US(actuators_pwm_values[PWM_SERVO_14]));
234 #endif
235 #ifdef PWM_SERVO_15
236  pwmEnableChannel(&PWM_SERVO_15_DRIVER, PWM_SERVO_15_CHANNEL, PWM_CMD_TO_US(actuators_pwm_values[PWM_SERVO_15]));
237 #endif
238 #ifdef PWM_SERVO_16
239  pwmEnableChannel(&PWM_SERVO_16_DRIVER, PWM_SERVO_16_CHANNEL, PWM_CMD_TO_US(actuators_pwm_values[PWM_SERVO_16]));
240 #endif
241 }
void gpio_setup_pin_af(ioportid_t port, uint16_t pin, uint8_t af, bool is_output)
Setup a gpio for input or output with alternate function.
Definition: gpio_arch.c:61
#define PWM_SERVO_2_AF
Definition: board.h:245
#define PWM_SERVO_4_AF
Definition: board.h:275
#define PWM_SERVO_0
Definition: board.h:212
#define PWM_SERVO_10
#define PWM_SERVO_9
Definition: krooz_sd.h:328
#define PWM_SERVO_1_PIN
Definition: board.h:229
#define PWM_SERVO_0_GPIO
Definition: board.h:213
#define PWM_SERVO_7_AF
Definition: krooz_sd.h:308
#define PWM_CONF5_DEF
#define PWM_SERVO_6
Definition: chimera.h:307
#define PWM_CONF1_DEF
void actuators_pwm_arch_init(void)
Arch dependent init file.
#define PWM_SERVO_8_GPIO
Definition: krooz_sd.h:318
#define PWM_SERVO_1_GPIO
Definition: board.h:228
Some architecture independent helper functions for GPIOs.
#define PWM_SERVO_9_CHANNEL
#define PWM_SERVO_2_PIN
Definition: board.h:244
#define PWM_SERVO_3_DRIVER
Definition: board.h:261
#define PWM_SERVO_5_GPIO
Definition: board.h:288
#define PWM_SERVO_10_AF
#define PWM_SERVO_8_PIN
Definition: krooz_sd.h:319
#define PWM_SERVO_3_AF
Definition: board.h:260
#define PWM_SERVO_1
Definition: board.h:227
#define PWM_SERVO_5_CHANNEL
Definition: board.h:292
#define PWM_SERVO_0_PIN
Definition: board.h:214
#define PWM_CONF4_DEF
Definition: chimera.h:359
#define PWM_SERVO_8_AF
Definition: krooz_sd.h:320
#define PWM_SERVO_7_CHANNEL
#define PWM_SERVO_10_CHANNEL
#define PWM_SERVO_6_CHANNEL
Definition: chimera.h:312
#define PWM_SERVO_5_DRIVER
Definition: board.h:291
#define PWM_SERVO_2_GPIO
Definition: board.h:243
#define PWM_SERVO_10_DRIVER
#define PWM_SERVO_8
Definition: krooz_sd.h:316
#define PWM_SERVO_6_PIN
Definition: chimera.h:309
#define PWM_SERVO_1_CHANNEL
Definition: board.h:232
#define PWM_CONF8_DEF
#define PWM_SERVO_0_AF
Definition: board.h:215
#define PWM_CONF3_DEF
Definition: board.h:335
#define PWM_SERVO_10_GPIO
#define PWM_SERVO_5_AF
Definition: board.h:290
#define PWM_CONF2_DEF
Definition: board.h:316
#define PWM_SERVO_3
Definition: board.h:257
#define PWM_SERVO_7_GPIO
Definition: krooz_sd.h:306
#define ACTUATORS_PWM_NB
int int32_t
Typedef defining 32 bit int type.
Definition: vl53l1_types.h:83
#define PWM_SERVO_0_CHANNEL
Definition: board.h:217
#define PWM_SERVO_8_CHANNEL
#define PWM_CONF9_DEF
#define PWM_SERVO_2_CHANNEL
Definition: board.h:247
#define PWM_SERVO_4_CHANNEL
Definition: board.h:277
#define PWM_SERVO_7_PIN
Definition: krooz_sd.h:307
#define PWM_SERVO_9_PIN
Definition: krooz_sd.h:331
#define PWM_SERVO_2
Definition: board.h:242
#define PWM_SERVO_5
Definition: board.h:287
#define PWM_SERVO_8_DRIVER
#define PWM_SERVO_3_PIN
Definition: board.h:259
#define PWM_SERVO_1_AF
Definition: board.h:230
#define PWM_SERVO_4
Definition: board.h:272
#define PWM_SERVO_6_AF
Definition: chimera.h:310
#define PWM_SERVO_9_AF
Definition: krooz_sd.h:332
#define PWM_SERVO_5_PIN
Definition: board.h:289
#define PWM_SERVO_9_GPIO
Definition: krooz_sd.h:330
#define PWM_SERVO_2_DRIVER
Definition: board.h:246
void actuators_pwm_commit(void)
#define PWM_SERVO_4_PIN
Definition: board.h:274
#define PWM_SERVO_3_GPIO
Definition: board.h:258
#define PWM_SERVO_4_DRIVER
Definition: board.h:276
#define PWM_SERVO_9_DRIVER
#define PWM_SERVO_4_GPIO
Definition: board.h:273
#define PWM_SERVO_7
Definition: krooz_sd.h:304
#define PWM_SERVO_7_DRIVER
#define PWM_SERVO_1_DRIVER
Definition: board.h:231
static void pwmpcb(PWMDriver *pwmp)
PWM callback function.
#define PWM_CONF12_DEF
Definition: px4fmu.h:315
#define PWM_SERVO_6_DRIVER
Definition: chimera.h:311
#define PWM_SERVO_3_CHANNEL
Definition: board.h:262
#define PWM_CMD_TO_US(_t)
CMD_TO_US() is depending on architecture and on the hardware settings (clock speed etc...
#define PWM_SERVO_6_GPIO
Definition: chimera.h:308
#define PWM_SERVO_0_DRIVER
Definition: board.h:216
int32_t actuators_pwm_values[ACTUATORS_PWM_NB]
#define PWM_SERVO_10_PIN