-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
gpio_cam_ctrl.c
165 lines (147 loc) · 3.66 KB
/
gpio_cam_ctrl.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/*
* Copyright (C) 2010-2014 The Paparazzi Team
*
* This file is part of paparazzi.
*
* paparazzi is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* paparazzi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with paparazzi; see the file COPYING. If not, write to
* the Free Software Foundation, 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
/**
* @file modules/digital_cam/gpio_cam_ctrl.c
* Control the camera via GPIO pins.
*
* Configuration (DC_SHUTTER is mandatory, others optional):
* @code{.xml}
* <define name="DC_SHUTTER_GPIO" value="GPIOC,GPIO12"/>
* <define name="DC_ZOOM_IN_GPIO" value="GPIOC,GPIO2"/>
* <define name="DC_ZOOM_OUT_GPIO" value="GPIOC,GPIO5"/>
* <define name="DC_POWER_GPIO" value="GPIOB,GPIO1"/>
* <define name="DC_POWER_OFF_GPIO" value="GPIOC,GPIO1"/>
* @endcode
*/
#include "gpio_cam_ctrl.h"
#include "generated/airframe.h"
// Include Standard Camera Control Interface
#include "dc.h"
#include "mcu_periph/gpio.h"
#ifndef DC_PUSH
#define DC_PUSH gpio_set
#endif
#ifndef DC_RELEASE
#define DC_RELEASE gpio_clear
#endif
#ifndef DC_SHUTTER_DELAY
#define DC_SHUTTER_DELAY 2 /* 4Hz -> 0.5s */
#endif
#ifndef DC_POWER_OFF_DELAY
#define DC_POWER_OFF_DELAY 3
#endif
#ifdef DC_SHUTTER_LED
#warning DC_SHUTTER_LED is obsolete, please use DC_SHUTTER_GPIO
#endif
#ifndef DC_SHUTTER_GPIO
#error DC: Please specify at least a DC_SHUTTER_GPIO (e.g. <define name="DC_SHUTTER_GPIO" value="GPIOC,GPIO12"/>)
#endif
// Button Timer
uint8_t dc_timer;
void gpio_cam_ctrl_init(void)
{
// Call common DC init
dc_init();
// Do gpio specific DC init
dc_timer = 0;
gpio_setup_output(DC_SHUTTER_GPIO);
DC_RELEASE(DC_SHUTTER_GPIO);
#ifdef DC_ZOOM_IN_GPIO
gpio_setup_output(DC_ZOOM_IN_GPIO);
DC_RELEASE(DC_ZOOM_IN_GPIO);
#endif
#ifdef DC_ZOOM_OUT_GPIO
gpio_setup_output(DC_ZOOM_OUT_GPIO);
DC_RELEASE(DC_ZOOM_OUT_GPIO);
#endif
#ifdef DC_POWER_GPIO
gpio_setup_output(DC_POWER_GPIO);
DC_RELEASE(DC_POWER_GPIO);
#endif
#ifdef DC_POWER_OFF_GPIO
gpio_setup_output(DC_POWER_OFF_GPIO);
DC_RELEASE(DC_POWER_OFF_GPIO);
#endif
}
void gpio_cam_ctrl_periodic( void )
{
#ifdef DC_SHOOT_ON_BUTTON_RELEASE
if (dc_timer==1) {
dc_send_shot_position();
}
#endif
if (dc_timer) {
dc_timer--;
} else {
DC_RELEASE(DC_SHUTTER_GPIO);
#ifdef DC_ZOOM_IN_GPIO
DC_RELEASE(DC_ZOOM_IN_GPIO);
#endif
#ifdef DC_ZOOM_OUT_GPIO
DC_RELEASE(DC_ZOOM_OUT_GPIO);
#endif
#ifdef DC_POWER_GPIO
DC_RELEASE(DC_POWER_GPIO);
#endif
#ifdef DC_POWER_OFF_GPIO
DC_RELEASE(DC_POWER_OFF_GPIO);
#endif
}
// Common DC Periodic task
dc_periodic_4Hz();
}
/* Command The Camera */
void dc_send_command(uint8_t cmd)
{
dc_timer = DC_SHUTTER_DELAY;
switch (cmd)
{
case DC_SHOOT:
DC_PUSH(DC_SHUTTER_GPIO);
#ifndef DC_SHOOT_ON_BUTTON_RELEASE
dc_send_shot_position();
#endif
break;
#ifdef DC_ZOOM_IN_GPIO
case DC_TALLER:
DC_PUSH(DC_ZOOM_IN_GPIO);
break;
#endif
#ifdef DC_ZOOM_OUT_GPIO
case DC_WIDER:
DC_PUSH(DC_ZOOM_OUT_GPIO);
break;
#endif
#ifdef DC_POWER_GPIO
case DC_ON:
DC_PUSH(DC_POWER_GPIO);
break;
#endif
#ifdef DC_POWER_OFF_GPIO
case DC_OFF:
DC_PUSH(DC_POWER_OFF_GPIO);
dc_timer = DC_POWER_OFF_DELAY;
break;
#endif
default:
break;
}
}