Paparazzi UAS  v5.15_devel-230-gc96ce27
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 
85 
87 {
88  /*----------------
89  * Configure GPIO
90  *----------------*/
91 #ifdef PWM_SERVO_0
93 #endif
94 #ifdef PWM_SERVO_1
96 #endif
97 #ifdef PWM_SERVO_2
99 #endif
100 #ifdef PWM_SERVO_3
102 #endif
103 #ifdef PWM_SERVO_4
105 #endif
106 #ifdef PWM_SERVO_5
108 #endif
109 #ifdef PWM_SERVO_6
111 #endif
112 #ifdef PWM_SERVO_7
114 #endif
115 #ifdef PWM_SERVO_8
117 #endif
118 #ifdef PWM_SERVO_9
120 #endif
121 #ifdef PWM_SERVO_10
123 #endif
124 #ifdef PWM_SERVO_11
125  gpio_setup_pin_af(PWM_SERVO_11_GPIO, PWM_SERVO_11_PIN, PWM_SERVO_11_AF, true);
126 #endif
127 #ifdef PWM_SERVO_12
128  gpio_setup_pin_af(PWM_SERVO_12_GPIO, PWM_SERVO_12_PIN, PWM_SERVO_12_AF, true);
129 #endif
130 #ifdef PWM_SERVO_13
131  gpio_setup_pin_af(PWM_SERVO_13_GPIO, PWM_SERVO_13_PIN, PWM_SERVO_13_AF, true);
132 #endif
133 #ifdef PWM_SERVO_14
134  gpio_setup_pin_af(PWM_SERVO_14_GPIO, PWM_SERVO_14_PIN, PWM_SERVO_14_AF, true);
135 #endif
136 #ifdef PWM_SERVO_15
137  gpio_setup_pin_af(PWM_SERVO_15_GPIO, PWM_SERVO_15_PIN, PWM_SERVO_15_AF, true);
138 #endif
139 #ifdef PWM_SERVO_16
140  gpio_setup_pin_af(PWM_SERVO_16_GPIO, PWM_SERVO_16_PIN, PWM_SERVO_16_AF, true);
141 #endif
142 
143  /*---------------
144  * Configure PWM
145  *---------------*/
146 #if PWM_CONF_TIM1
147  pwmStart(&PWMD1, &pwmcfg1);
148 #endif
149 #if PWM_CONF_TIM2
150  pwmStart(&PWMD2, &pwmcfg2);
151 #endif
152 #if PWM_CONF_TIM3
153  pwmStart(&PWMD3, &pwmcfg3);
154 #endif
155 #if PWM_CONF_TIM4
156  pwmStart(&PWMD4, &pwmcfg4);
157 #endif
158 #if PWM_CONF_TIM5
159  pwmStart(&PWMD5, &pwmcfg5);
160 #endif
161 #if PWM_CONF_TIM8
162  pwmStart(&PWMD8, &pwmcfg8);
163 #endif
164 #if PWM_CONF_TIM9
165  pwmStart(&PWMD9, &pwmcfg9);
166 #endif
167 }
168 
169 
171 {
172 #ifdef PWM_SERVO_0
174 #endif
175 #ifdef PWM_SERVO_1
177 #endif
178 #ifdef PWM_SERVO_2
180 #endif
181 #ifdef PWM_SERVO_3
183 #endif
184 #ifdef PWM_SERVO_4
186 #endif
187 #ifdef PWM_SERVO_5
189 #endif
190 #ifdef PWM_SERVO_6
192 #endif
193 #ifdef PWM_SERVO_7
194  pwmEnableChannel(&PWM_SERVO_7_DRIVER, PWM_SERVO_7_CHANNEL, PWM_CMD_TO_US(actuators_pwm_values[PWM_SERVO_7]));
195 #endif
196 #ifdef PWM_SERVO_8
197  pwmEnableChannel(&PWM_SERVO_8_DRIVER, PWM_SERVO_8_CHANNEL, PWM_CMD_TO_US(actuators_pwm_values[PWM_SERVO_8]));
198 #endif
199 #ifdef PWM_SERVO_9
200  pwmEnableChannel(&PWM_SERVO_9_DRIVER, PWM_SERVO_9_CHANNEL, PWM_CMD_TO_US(actuators_pwm_values[PWM_SERVO_9]));
201 #endif
202 #ifdef PWM_SERVO_10
203  pwmEnableChannel(&PWM_SERVO_10_DRIVER, PWM_SERVO_10_CHANNEL, PWM_CMD_TO_US(actuators_pwm_values[PWM_SERVO_10]));
204 #endif
205 #ifdef PWM_SERVO_11
206  pwmEnableChannel(&PWM_SERVO_11_DRIVER, PWM_SERVO_11_CHANNEL, PWM_CMD_TO_US(actuators_pwm_values[PWM_SERVO_11]));
207 #endif
208 #ifdef PWM_SERVO_12
209  pwmEnableChannel(&PWM_SERVO_12_DRIVER, PWM_SERVO_12_CHANNEL, PWM_CMD_TO_US(actuators_pwm_values[PWM_SERVO_12]));
210 #endif
211 #ifdef PWM_SERVO_13
212  pwmEnableChannel(&PWM_SERVO_13_DRIVER, PWM_SERVO_13_CHANNEL, PWM_CMD_TO_US(actuators_pwm_values[PWM_SERVO_13]));
213 #endif
214 #ifdef PWM_SERVO_14
215  pwmEnableChannel(&PWM_SERVO_14_DRIVER, PWM_SERVO_14_CHANNEL, PWM_CMD_TO_US(actuators_pwm_values[PWM_SERVO_14]));
216 #endif
217 #ifdef PWM_SERVO_15
218  pwmEnableChannel(&PWM_SERVO_15_DRIVER, PWM_SERVO_15_CHANNEL, PWM_CMD_TO_US(actuators_pwm_values[PWM_SERVO_15]));
219 #endif
220 #ifdef PWM_SERVO_16
221  pwmEnableChannel(&PWM_SERVO_16_DRIVER, PWM_SERVO_16_CHANNEL, PWM_CMD_TO_US(actuators_pwm_values[PWM_SERVO_16]));
222 #endif
223 }
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_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_SERVO_6
Definition: chimera.h:307
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_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_8_PIN
Definition: krooz_sd.h:319
#define PWM_SERVO_3_AF
Definition: board.h:260
#define PWM_SERVO_10
Definition: opa_ftd_1.0.h:348
#define PWM_SERVO_1
Definition: board.h:227
#define PWM_CONF5_DEF
Definition: board.h:477
#define PWM_SERVO_5_CHANNEL
Definition: board.h:292
#define PWM_SERVO_10_PIN
Definition: opa_ftd_1.0.h:351
#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_10_AF
Definition: opa_ftd_1.0.h:352
#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_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_SERVO_0_AF
Definition: board.h:215
#define PWM_CONF3_DEF
Definition: board.h:335
#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
#define PWM_SERVO_0_CHANNEL
Definition: board.h:217
#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
signed long int32_t
Definition: types.h:19
#define PWM_SERVO_5
Definition: board.h:287
#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_10_GPIO
Definition: opa_ftd_1.0.h:350
#define PWM_SERVO_4_GPIO
Definition: board.h:273
#define PWM_SERVO_7
Definition: krooz_sd.h:304
#define PWM_CONF1_DEF
Definition: px4fmu.h:199
#define PWM_SERVO_1_DRIVER
Definition: board.h:231
static void pwmpcb(PWMDriver *pwmp)
PWM callback function.
#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 (e.g STM32 vs LPC), and on the hardware settings (clock spee...
#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]