Firmware
drv_pwm_output.h
1 /****************************************************************************
2  *
3  * Copyright (c) 2012-2015, 2017 PX4 Development Team. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in
13  * the documentation and/or other materials provided with the
14  * distribution.
15  * 3. Neither the name PX4 nor the names of its contributors may be
16  * used to endorse or promote products derived from this software
17  * without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
26  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  *
32  ****************************************************************************/
33 
43 #pragma once
44 
45 #include <px4_defines.h>
46 
47 #include <stdint.h>
48 #include <sys/ioctl.h>
49 #include <board_config.h>
50 
51 #include "drv_orb_dev.h"
52 
53 __BEGIN_DECLS
54 
62 #define PWM_OUTPUT_BASE_DEVICE_PATH "/dev/pwm_output"
63 #define PWM_OUTPUT0_DEVICE_PATH "/dev/pwm_output0"
64 
65 #define PWM_OUTPUT_MAX_CHANNELS 16
66 
68  uint32_t channel_count;
69  uint16_t values[16];
70 };
71 
75 //#define PWM_OUTPUT_MAX_CHANNELS 16
76 
77 /* Use defaults unless the board override the defaults by providing
78  * PX4_PWM_ALTERNATE_RANGES and a replacement set of
79  * constants
80  */
81 #if !defined(PX4_PWM_ALTERNATE_RANGES)
82 
86 #define PWM_LOWEST_MIN 90
87 
91 #define PWM_MOTOR_OFF 900
92 
96 #define PWM_DEFAULT_MIN 1000
97 
101 #define PWM_HIGHEST_MIN 1600
102 
106 #define PWM_HIGHEST_MAX 2150
107 
111 #define PWM_DEFAULT_MAX 2000
112 
116 #define PWM_DEFAULT_TRIM 0
117 
121 #define PWM_LOWEST_MAX 200
122 
123 #endif // not PX4_PWM_ALTERNATE_RANGES
124 
128 #define PWM_IGNORE_THIS_CHANNEL UINT16_MAX
129 
134 typedef uint16_t servo_position_t;
135 
143  uint8_t channel;
144  uint16_t rc_min;
145  uint16_t rc_trim;
146  uint16_t rc_max;
147  uint16_t rc_dz;
148  uint16_t rc_assignment;
149  bool rc_reverse;
150 };
151 
152 /*
153  * ioctl() definitions
154  *
155  * Note that ioctls and ORB updates should not be mixed, as the
156  * behaviour of the system in this case is not defined.
157  */
158 #define _PWM_SERVO_BASE 0x2a00
159 
161 #define PWM_SERVO_ARM _PX4_IOC(_PWM_SERVO_BASE, 0)
162 
164 #define PWM_SERVO_DISARM _PX4_IOC(_PWM_SERVO_BASE, 1)
165 
167 #define PWM_SERVO_GET_DEFAULT_UPDATE_RATE _PX4_IOC(_PWM_SERVO_BASE, 2)
168 
170 #define PWM_SERVO_SET_UPDATE_RATE _PX4_IOC(_PWM_SERVO_BASE, 3)
171 
173 #define PWM_SERVO_GET_UPDATE_RATE _PX4_IOC(_PWM_SERVO_BASE, 4)
174 
176 #define PWM_SERVO_GET_COUNT _PX4_IOC(_PWM_SERVO_BASE, 5)
177 
179 #define PWM_SERVO_SET_SELECT_UPDATE_RATE _PX4_IOC(_PWM_SERVO_BASE, 6)
180 
182 #define PWM_SERVO_GET_SELECT_UPDATE_RATE _PX4_IOC(_PWM_SERVO_BASE, 7)
183 
185 #define PWM_SERVO_SET_ARM_OK _PX4_IOC(_PWM_SERVO_BASE, 8)
186 
188 #define PWM_SERVO_CLEAR_ARM_OK _PX4_IOC(_PWM_SERVO_BASE, 9)
189 
191 #define DSM_BIND_START _PX4_IOC(_PWM_SERVO_BASE, 10)
192 
194 #define DSM_BIND_POWER_UP _PX4_IOC(_PWM_SERVO_BASE, 11)
195 
197 #define PWM_SERVO_SET_FAILSAFE_PWM _PX4_IOC(_PWM_SERVO_BASE, 12)
198 
200 #define PWM_SERVO_GET_FAILSAFE_PWM _PX4_IOC(_PWM_SERVO_BASE, 13)
201 
203 #define PWM_SERVO_SET_DISARMED_PWM _PX4_IOC(_PWM_SERVO_BASE, 14)
204 
206 #define PWM_SERVO_GET_DISARMED_PWM _PX4_IOC(_PWM_SERVO_BASE, 15)
207 
209 #define PWM_SERVO_SET_MIN_PWM _PX4_IOC(_PWM_SERVO_BASE, 16)
210 
212 #define PWM_SERVO_GET_MIN_PWM _PX4_IOC(_PWM_SERVO_BASE, 17)
213 
215 #define PWM_SERVO_SET_MAX_PWM _PX4_IOC(_PWM_SERVO_BASE, 18)
216 
218 #define PWM_SERVO_GET_MAX_PWM _PX4_IOC(_PWM_SERVO_BASE, 19)
219 
221 #define PWM_SERVO_SET_TRIM_PWM _PX4_IOC(_PWM_SERVO_BASE, 20)
222 
224 #define PWM_SERVO_GET_TRIM_PWM _PX4_IOC(_PWM_SERVO_BASE, 21)
225 
228 #define PWM_SERVO_SET_COUNT _PX4_IOC(_PWM_SERVO_BASE, 22)
229 
231 #define PWM_SERVO_SET_DISABLE_LOCKDOWN _PX4_IOC(_PWM_SERVO_BASE, 23)
232 
234 #define PWM_SERVO_GET_DISABLE_LOCKDOWN _PX4_IOC(_PWM_SERVO_BASE, 24)
235 
237 #define PWM_SERVO_SET_FORCE_SAFETY_OFF _PX4_IOC(_PWM_SERVO_BASE, 25)
238 
240 #define PWM_SERVO_SET_FORCE_FAILSAFE _PX4_IOC(_PWM_SERVO_BASE, 26)
241 
243 #define PWM_SERVO_SET_TERMINATION_FAILSAFE _PX4_IOC(_PWM_SERVO_BASE, 27)
244 
246 #define PWM_SERVO_SET_FORCE_SAFETY_ON _PX4_IOC(_PWM_SERVO_BASE, 28)
247 
249 #define PWM_SERVO_SET_OVERRIDE_IMMEDIATE _PX4_IOC(_PWM_SERVO_BASE, 32)
250 
252 #define PWM_SERVO_SET_SBUS_RATE _PX4_IOC(_PWM_SERVO_BASE, 33)
253 
255 #define PWM_SERVO_MODE_NONE 0
256 #define PWM_SERVO_MODE_1PWM 1
257 #define PWM_SERVO_MODE_2PWM 2
258 #define PWM_SERVO_MODE_2PWM2CAP 3
259 #define PWM_SERVO_MODE_3PWM 4
260 #define PWM_SERVO_MODE_3PWM1CAP 5
261 #define PWM_SERVO_MODE_4PWM 6
262 #define PWM_SERVO_MODE_4PWM1CAP 7
263 #define PWM_SERVO_MODE_4PWM2CAP 8
264 #define PWM_SERVO_MODE_5PWM 9
265 #define PWM_SERVO_MODE_5PWM1CAP 10
266 #define PWM_SERVO_MODE_6PWM 11
267 #define PWM_SERVO_MODE_8PWM 12
268 #define PWM_SERVO_MODE_14PWM 13
269 #define PWM_SERVO_MODE_4CAP 14
270 #define PWM_SERVO_MODE_5CAP 15
271 #define PWM_SERVO_MODE_6CAP 16
272 #define PWM_SERVO_ENTER_TEST_MODE 17
273 #define PWM_SERVO_EXIT_TEST_MODE 18
274 #define PWM_SERVO_SET_MODE _PX4_IOC(_PWM_SERVO_BASE, 34)
275 
276 /*
277  *
278  *
279  * WARNING WARNING WARNING! DO NOT EXCEED 47 IN IOC INDICES HERE!
280  *
281  *
282  */
283 
285 #define PWM_SERVO_SET(_servo) _PX4_IOC(_PWM_SERVO_BASE, 0x30 + _servo)
286 
288 #define PWM_SERVO_GET(_servo) _PX4_IOC(_PWM_SERVO_BASE, 0x50 + _servo)
289 
293 #define PWM_SERVO_GET_RATEGROUP(_n) _PX4_IOC(_PWM_SERVO_BASE, 0x70 + _n)
294 
295 /*
296  * Low-level PWM output interface.
297  *
298  * This is the low-level API to the platform-specific PWM driver.
299  */
300 
309 __EXPORT extern int up_pwm_servo_init(uint32_t channel_mask);
310 
314 __EXPORT extern void up_pwm_servo_deinit(void);
315 
327 __EXPORT extern void up_pwm_servo_arm(bool armed);
328 
335 __EXPORT extern int up_pwm_servo_set_rate(unsigned rate);
336 
345 __EXPORT extern uint32_t up_pwm_servo_get_rate_group(unsigned group);
346 
354 __EXPORT extern int up_pwm_servo_set_rate_group_update(unsigned group, unsigned rate);
355 
362 __EXPORT extern void up_pwm_update(void);
363 
370 __EXPORT extern int up_pwm_servo_set(unsigned channel, servo_position_t value);
371 
379 __EXPORT extern servo_position_t up_pwm_servo_get(unsigned channel);
380 
381 __END_DECLS
uORB published object driver.
RC config values for a channel.
Definition: drv_pwm_output.h:142
Generally used magic defines.
Definition: drv_pwm_output.h:67
Definition: I2C.hpp:51