Paparazzi UAS  v5.14.0_stable-0-g3f680d1
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) (1000000 * _t / PWM_FREQUENCY)
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 
128  /*---------------
129  * Configure PWM
130  *---------------*/
131 #if PWM_CONF_TIM1
132  pwmStart(&PWMD1, &pwmcfg1);
133 #endif
134 #if PWM_CONF_TIM2
135  pwmStart(&PWMD2, &pwmcfg2);
136 #endif
137 #if PWM_CONF_TIM3
138  pwmStart(&PWMD3, &pwmcfg3);
139 #endif
140 #if PWM_CONF_TIM4
141  pwmStart(&PWMD4, &pwmcfg4);
142 #endif
143 #if PWM_CONF_TIM5
144  pwmStart(&PWMD5, &pwmcfg5);
145 #endif
146 #if PWM_CONF_TIM8
147  pwmStart(&PWMD8, &pwmcfg8);
148 #endif
149 #if PWM_CONF_TIM9
150  pwmStart(&PWMD9, &pwmcfg9);
151 #endif
152 }
153 
154 
156 {
157 #ifdef PWM_SERVO_0
159 #endif
160 #ifdef PWM_SERVO_1
162 #endif
163 #ifdef PWM_SERVO_2
165 #endif
166 #ifdef PWM_SERVO_3
168 #endif
169 #ifdef PWM_SERVO_4
171 #endif
172 #ifdef PWM_SERVO_5
174 #endif
175 #ifdef PWM_SERVO_6
177 #endif
178 #ifdef PWM_SERVO_7
179  pwmEnableChannel(&PWM_SERVO_7_DRIVER, PWM_SERVO_7_CHANNEL, PWM_CMD_TO_US(actuators_pwm_values[PWM_SERVO_7]));
180 #endif
181 #ifdef PWM_SERVO_8
182  pwmEnableChannel(&PWM_SERVO_8_DRIVER, PWM_SERVO_8_CHANNEL, PWM_CMD_TO_US(actuators_pwm_values[PWM_SERVO_8]));
183 #endif
184 #ifdef PWM_SERVO_9
185  pwmEnableChannel(&PWM_SERVO_9_DRIVER, PWM_SERVO_9_CHANNEL, PWM_CMD_TO_US(actuators_pwm_values[PWM_SERVO_9]));
186 #endif
187 #ifdef PWM_SERVO_10
188  pwmEnableChannel(&PWM_SERVO_10_DRIVER, PWM_SERVO_10_CHANNEL, PWM_CMD_TO_US(actuators_pwm_values[PWM_SERVO_10]));
189 #endif
190 #ifdef PWM_SERVO_11
191  pwmEnableChannel(&PWM_SERVO_11_DRIVER, PWM_SERVO_11_CHANNEL, PWM_CMD_TO_US(actuators_pwm_values[PWM_SERVO_11]));
192 #endif
193 }
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:242
#define PWM_SERVO_4_AF
Definition: board.h:272
#define PWM_SERVO_0
Definition: board.h:209
#define PWM_SERVO_9
Definition: krooz_sd.h:328
#define PWM_SERVO_1_PIN
Definition: board.h:226
#define PWM_SERVO_0_GPIO
Definition: board.h:210
#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:225
Some architecture independent helper functions for GPIOs.
#define PWM_SERVO_2_PIN
Definition: board.h:241
#define PWM_SERVO_3_DRIVER
Definition: board.h:258
#define PWM_SERVO_5_GPIO
Definition: board.h:285
#define PWM_SERVO_8_PIN
Definition: krooz_sd.h:319
#define PWM_SERVO_3_AF
Definition: board.h:257
#define PWM_SERVO_10
Definition: opa_ftd_1.0.h:348
#define PWM_SERVO_1
Definition: board.h:224
#define PWM_CONF5_DEF
Definition: board.h:477
#define PWM_SERVO_5_CHANNEL
Definition: board.h:289
#define PWM_SERVO_10_PIN
Definition: opa_ftd_1.0.h:351
#define PWM_SERVO_0_PIN
Definition: board.h:211
#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:288
#define PWM_SERVO_2_GPIO
Definition: board.h:240
#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:229
#define PWM_SERVO_0_AF
Definition: board.h:212
#define PWM_CONF3_DEF
Definition: board.h:332
#define PWM_SERVO_5_AF
Definition: board.h:287
#define PWM_CONF2_DEF
Definition: board.h:313
#define PWM_SERVO_3
Definition: board.h:254
#define PWM_SERVO_7_GPIO
Definition: krooz_sd.h:306
#define ACTUATORS_PWM_NB
#define PWM_SERVO_0_CHANNEL
Definition: board.h:214
#define PWM_SERVO_2_CHANNEL
Definition: board.h:244
#define PWM_SERVO_4_CHANNEL
Definition: board.h:274
#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:239
signed long int32_t
Definition: types.h:19
#define PWM_SERVO_5
Definition: board.h:284
#define PWM_SERVO_3_PIN
Definition: board.h:256
#define PWM_SERVO_1_AF
Definition: board.h:227
#define PWM_SERVO_4
Definition: board.h:269
#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:286
#define PWM_SERVO_9_GPIO
Definition: krooz_sd.h:330
#define PWM_SERVO_2_DRIVER
Definition: board.h:243
void actuators_pwm_commit(void)
#define PWM_SERVO_4_PIN
Definition: board.h:271
#define PWM_SERVO_3_GPIO
Definition: board.h:255
#define PWM_SERVO_4_DRIVER
Definition: board.h:273
#define PWM_SERVO_10_GPIO
Definition: opa_ftd_1.0.h:350
#define PWM_SERVO_4_GPIO
Definition: board.h:270
#define PWM_SERVO_7
Definition: krooz_sd.h:304
#define PWM_SERVO_1_DRIVER
Definition: board.h:228
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:259
#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:213
int32_t actuators_pwm_values[ACTUATORS_PWM_NB]