Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
gpio_cam_ctrl.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2010-2014 The Paparazzi Team
3  *
4  * This file is part of paparazzi.
5  *
6  * paparazzi is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2, or (at your option)
9  * any later version.
10  *
11  * paparazzi is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with paparazzi; see the file COPYING. If not, write to
18  * the Free Software Foundation, 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21 
36 #include "gpio_cam_ctrl.h"
37 #include "generated/airframe.h"
38 #include "generated/modules.h"
39 
40 // Include Standard Camera Control Interface
41 #include "dc.h"
42 
43 #include "mcu_periph/gpio.h"
44 
45 #ifndef DC_PUSH
46 #define DC_PUSH gpio_set
47 #endif
48 
49 #ifndef DC_RELEASE
50 #define DC_RELEASE gpio_clear
51 #endif
52 
54 #ifndef DC_SHUTTER_DELAY
55 #define DC_SHUTTER_DELAY 0.5
56 #endif
57 
59 #ifndef DC_POWER_OFF_DELAY
60 #define DC_POWER_OFF_DELAY 0.75
61 #endif
62 
63 #ifdef DC_SHUTTER_LED
64 #warning DC_SHUTTER_LED is obsolete, please use DC_SHUTTER_GPIO
65 #endif
66 #ifndef DC_SHUTTER_GPIO
67 #error DC: Please specify at least a DC_SHUTTER_GPIO (e.g. <define name="DC_SHUTTER_GPIO" value="GPIOC,GPIO12"/>)
68 #endif
69 
70 
71 // Button Timer
73 
75 {
76  // Do gpio specific DC init
77  dc_timer = 0;
78 
79  gpio_setup_output(DC_SHUTTER_GPIO);
80  DC_RELEASE(DC_SHUTTER_GPIO);
81 #ifdef DC_ZOOM_IN_GPIO
82  gpio_setup_output(DC_ZOOM_IN_GPIO);
83  DC_RELEASE(DC_ZOOM_IN_GPIO);
84 #endif
85 #ifdef DC_ZOOM_OUT_GPIO
86  gpio_setup_output(DC_ZOOM_OUT_GPIO);
87  DC_RELEASE(DC_ZOOM_OUT_GPIO);
88 #endif
89 #ifdef DC_POWER_GPIO
90  gpio_setup_output(DC_POWER_GPIO);
91  DC_RELEASE(DC_POWER_GPIO);
92 #endif
93 #ifdef DC_POWER_OFF_GPIO
94  gpio_setup_output(DC_POWER_OFF_GPIO);
95  DC_RELEASE(DC_POWER_OFF_GPIO);
96 #endif
97 }
98 
100 {
101 #ifdef DC_SHOOT_ON_BUTTON_RELEASE
102  if (dc_timer == 1) {
104  }
105 #endif
106 
107  if (dc_timer) {
108  dc_timer--;
109  } else {
110  DC_RELEASE(DC_SHUTTER_GPIO);
111 #ifdef DC_ZOOM_IN_GPIO
112  DC_RELEASE(DC_ZOOM_IN_GPIO);
113 #endif
114 #ifdef DC_ZOOM_OUT_GPIO
115  DC_RELEASE(DC_ZOOM_OUT_GPIO);
116 #endif
117 #ifdef DC_POWER_GPIO
118  DC_RELEASE(DC_POWER_GPIO);
119 #endif
120 #ifdef DC_POWER_OFF_GPIO
121  DC_RELEASE(DC_POWER_OFF_GPIO);
122 #endif
123  }
124 
125  // Common DC Periodic task
126  dc_periodic();
127 }
128 
129 /* Command The Camera */
131 {
132  dc_timer = DC_SHUTTER_DELAY * GPIO_CAM_CTRL_PERIODIC_FREQ;
133 
134  switch (cmd) {
135  case DC_SHOOT:
136  DC_PUSH(DC_SHUTTER_GPIO);
137 #ifndef DC_SHOOT_ON_BUTTON_RELEASE
139 #endif
140  break;
141 #ifdef DC_ZOOM_IN_GPIO
142  case DC_TALLER:
143  DC_PUSH(DC_ZOOM_IN_GPIO);
144  break;
145 #endif
146 #ifdef DC_ZOOM_OUT_GPIO
147  case DC_WIDER:
148  DC_PUSH(DC_ZOOM_OUT_GPIO);
149  break;
150 #endif
151 #ifdef DC_POWER_GPIO
152  case DC_ON:
153  DC_PUSH(DC_POWER_GPIO);
154  break;
155 #endif
156 #ifdef DC_POWER_OFF_GPIO
157  case DC_OFF:
158  DC_PUSH(DC_POWER_OFF_GPIO);
159  dc_timer = DC_POWER_OFF_DELAY * GPIO_CAM_CTRL_PERIODIC_FREQ;
160  break;
161 #endif
162  default:
163  break;
164  }
165 
166  // call command send_command function
168 }
void gpio_setup_output(ioportid_t port, uint16_t gpios)
Setup one or more pins of the given GPIO port as outputs.
Definition: gpio_arch.c:33
void dc_periodic(void)
periodic function
Definition: dc.c:279
void dc_send_command_common(uint8_t cmd)
Command sending function.
Definition: dc.c:192
void dc_send_shot_position(void)
Send Down the coordinates of where the photo was taken.
Definition: dc.c:106
Standard Digital Camera Control Interface.
@ DC_OFF
Definition: dc.h:118
@ DC_WIDER
Definition: dc.h:104
@ DC_SHOOT
Definition: dc.h:102
@ DC_TALLER
Definition: dc.h:105
@ DC_ON
Definition: dc.h:117
Some architecture independent helper functions for GPIOs.
#define DC_POWER_OFF_DELAY
how long to send power off in seconds
Definition: gpio_cam_ctrl.c:60
#define DC_PUSH
Definition: gpio_cam_ctrl.c:46
void dc_send_command(uint8_t cmd)
Send Command To Camera.
void gpio_cam_ctrl_init(void)
Definition: gpio_cam_ctrl.c:74
#define DC_SHUTTER_DELAY
how long to push shutter in seconds
Definition: gpio_cam_ctrl.c:55
void gpio_cam_ctrl_periodic(void)
Periodic.
Definition: gpio_cam_ctrl.c:99
uint8_t dc_timer
Definition: gpio_cam_ctrl.c:72
#define DC_RELEASE
Definition: gpio_cam_ctrl.c:50
Digital Camera Control.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
Definition: vl53l1_types.h:98