-
Notifications
You must be signed in to change notification settings - Fork 46
/
canoneos.cpp
312 lines (236 loc) · 7.17 KB
/
canoneos.cpp
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
/* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved.
This software may be distributed and modified under the terms of the GNU
General Public License version 2 (GPL2) as published by the Free Software
Foundation and appearing in the file GPL2.TXT included in the packaging of
this file. Please note that GPL2 Section 2[b] requires that all works based
on this software must also be made publicly available under the terms of
the GPL2 ("Copyleft").
Contact information
-------------------
Circuits At Home, LTD
Web : http://www.circuitsathome.com
e-mail : [email protected]
*/
#include "canoneos.h"
void EOSStateHandlers::OnSessionOpenedState(PTP *ptp)
{
uint16_t ret;
ret = ((CanonEOS*)ptp)->SetPCConnectMode(1);
if (FAILED(ret))
{
PTPTRACE2("SetPCConnectMode failed", ret);
return;
}
ret = ((CanonEOS*)ptp)->SetExtendedEventInfo(1);
if (FAILED(ret))
{
PTPTRACE2("SetExtendedEventInfo failed", ret);
return;
}
PTPTRACE("Init complete\r\n");
ptp->SetState(PTP_STATE_DEVICE_INITIALIZED);
//if (!FAILED(((CanonEOS*)ptp)->SetPCConnectMode(1)) && !FAILED(((CanonEOS*)ptp)->SetExtendedEventInfo(1)))
// ptp->SetState(PTP_STATE_DEVICE_INITIALIZED);
}
uint32_t ImgQualitySupplier::GetDataSize()
{
return ((pictFormat & 0xFFFF0000) ? 0x0000002C : 0x0000001C);
}
void ImgQualitySupplier::GetData(const uint16_t len __attribute__ ((unused)), uint8_t *pbuf)
{
uint8_t num_files = (pictFormat & 0xFFFF0000) ? 2 : 1;
((uint32_t*)pbuf)[0] = (num_files == 2) ? 0x0000002C : 0x0000001C;
((uint32_t*)pbuf)[1] = (uint32_t) EOS_DPC_ImageQuality;
((uint32_t*)pbuf)[2] = (uint32_t) num_files;
uint32_t format = pictFormat;
for (uint8_t i=0, pos=3; i<num_files; i++)
{
((uint32_t*)pbuf)[pos++] = 0x00000010;
for (uint8_t j=0; j<3; j++, format >>= 4)
((uint32_t*)pbuf)[pos++] = (uint32_t)(format & 0xF);
}
}
CanonEOS::CanonEOS(USB *pusb, PTPStateHandlers *s)
: PTP(pusb, s)
{
}
uint8_t CanonEOS::Init(uint8_t parent, uint8_t port, bool lowspeed)
{
uint8_t buf[10];
USB_DEVICE_DESCRIPTOR *udd =
reinterpret_cast<USB_DEVICE_DESCRIPTOR*>(buf);
uint8_t rcode;
UsbDevice *p = NULL;
EpInfo *oldep_ptr = NULL;
PTPTRACE("EOS Init\r\n");
AddressPool &addrPool = pUsb->GetAddressPool();
if (devAddress)
return USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE;
// Get pointer to pseudo device with address 0 assigned
p = addrPool.GetUsbDevicePtr(0);
if (!p)
return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL;
if (!p->epinfo)
{
PTPTRACE("epinfo\r\n");
return USB_ERROR_EPINFO_IS_NULL;
}
// Save old pointer to EP_RECORD of address 0
oldep_ptr = p->epinfo;
// Temporary assign new pointer to epInfo to p->epinfo in order to avoid toggle inconsistence
p->epinfo = epInfo;
// Get device descriptor
rcode = pUsb->getDevDescr( 0, 0, 10, (uint8_t*)buf );
// Restore p->epinfo
p->epinfo = oldep_ptr;
if( rcode )
{
PTPTRACE2("getDevDesc:", rcode);
return rcode;
}
if (udd->idVendor == 0x04A9)
return PTP::Init(parent, port, lowspeed);
else
{
PTPTRACE("Camera isn't Canon\r\n");
return USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED;
}
}
uint16_t CanonEOS::SetImageQuality(uint32_t format)
{
uint16_t ptp_error = PTP_RC_GeneralError;
OperFlags flags = { 0, 0, 1, 1, 1, 0 };
ImgQualitySupplier sup;
sup.SetPictureFormat(format);
if ( (ptp_error = Transaction(EOS_OC_SetDevicePropValue, &flags, NULL, (void*)&sup)) != PTP_RC_OK)
PTPTRACE2("SetImageQuality error", ptp_error);
return ptp_error;
}
uint16_t CanonEOS::SetPCConnectMode(uint8_t mode)
{
uint32_t params[1];
params[0] = (uint32_t) mode;
return Operation(EOS_OC_SetPCConnectMode, 1, params);
}
uint16_t CanonEOS::SetExtendedEventInfo(uint8_t mode)
{
uint32_t params[1];
params[0] = (uint32_t) mode;
return Operation(EOS_OC_SetExtendedEventInfo, 1, params);
}
uint16_t CanonEOS::StartBulb()
{
uint32_t params[3];
params[0] = 0xfffffff8;
params[1] = 0x00001000;
params[2] = 0x00000000;
Operation(0x911A, 3, params);
Operation(0x911B, 0, NULL);
Operation(0x9125, 0, NULL);
return PTP_RC_OK;
}
uint16_t CanonEOS::StopBulb()
{
uint32_t params[3];
params[0] = 0xffffffff;
params[1] = 0x00001000;
params[2] = 0x00000000;
Operation(0x911A, 3, params);
params[0] = 0xfffffffc;
Operation(0x911A, 3, params);
Operation(0x9126, 0, NULL);
Operation(0x911C, 0, NULL);
return PTP_RC_OK;
}
uint16_t CanonEOS::CancelTransfer(uint32_t object_id)
{
uint32_t params[1];
params[0] = object_id;
return Operation(EOS_OC_CancelTransfer, 1, params);
}
uint16_t CanonEOS::ResetTransfer(uint32_t object_id)
{
uint32_t params[1];
params[0] = object_id;
return Operation(EOS_OC_ResetTransfer, 1, params);
}
uint16_t CanonEOS::SwitchLiveView(bool on)
{
uint16_t ptp_error = PTP_RC_GeneralError;
if ((ptp_error = SetProperty(EOS_DPC_LiveView, (on) ? 2 : 0)) == PTP_RC_OK)
{
if (on)
{
if ((ptp_error = SetProperty(0xD1B3, 0)) != PTP_RC_OK)
{
PTPTRACE2("LiveView start failure:", ptp_error);
SetProperty(EOS_DPC_LiveView, 0);
return PTP_RC_GeneralError;
}
}
}
return ptp_error;
}
uint16_t CanonEOS::MoveFocus(uint16_t step)
{
uint16_t ptp_error = PTP_RC_GeneralError;
OperFlags flags = { 1, 0, 0, 0, 0, 0 };
uint32_t params[1];
params[0] = (uint32_t) step;
if ( (ptp_error = Transaction(EOS_OC_MoveFocus, &flags, params, NULL)) != PTP_RC_OK)
PTPTRACE2("MoveFocus error: ", ptp_error);
return ptp_error;
}
uint16_t CanonEOS::EventCheck(PTPReadParser *parser)
{
uint16_t ptp_error = PTP_RC_GeneralError;
OperFlags flags = { 0, 0, 0, 1, 1, 0 };
if ( (ptp_error = Transaction(0x9116, &flags, NULL, parser)) != PTP_RC_OK)
PTPTRACE2("EOSEventCheck error:", ptp_error);
return ptp_error;
}
uint16_t CanonEOS::Capture()
{
return Operation(EOS_OC_Capture, 0, NULL);
}
uint16_t CanonEOS::SetProperty(uint16_t prop, uint32_t val)
{
uint16_t ptp_error = PTP_RC_GeneralError;
OperFlags flags = { 0, 0, 1, 1, 3, 12 };
uint32_t params[3];
params[0] = 0x0000000C;
params[1] = (uint32_t)prop;
params[2] = val;
if ( (ptp_error = Transaction(EOS_OC_SetDevicePropValue, &flags, NULL, (void*)params)) != PTP_RC_OK)
PTPTRACE2("SetProperty error:", ptp_error);
return ptp_error;
}
uint16_t CanonEOS::GetProperty(uint16_t prop, PTPReadParser *parser)
{
uint16_t ptp_error = PTP_RC_GeneralError;
OperFlags flags = { 1, 0, 0, 1, 1, 0 };
uint32_t params[1];
params[0] = (uint32_t)prop;
if ( (ptp_error = Transaction(EOS_OC_GetDevicePropValue, &flags, params, (void*)parser)) != PTP_RC_OK)
PTPTRACE2("GetProperty error:", ptp_error);
return ptp_error;
}
uint16_t CanonEOS::GetDeviceInfoEx(PTPReadParser *parser)
{
uint16_t ptp_error = PTP_RC_GeneralError;
OperFlags flags = { 0, 0, 0, 1, 1, 0 };
if ( (ptp_error = Transaction(EOS_OC_GetDeviceInfoEx, &flags, NULL, (void*)parser)) != PTP_RC_OK)
PTPTRACE2("GetDeviceInfo error:", ptp_error);
return ptp_error;
}
uint16_t CanonEOS::GetObject(uint32_t object_id, uint32_t parent_id, PTPReadParser *parser)
{
uint16_t ptp_error = PTP_RC_GeneralError;
OperFlags flags = { 2, 0, 0, 1, 1, 0 };
uint32_t params[2];
params[0] = object_id;
params[1] = parent_id;
if ( (ptp_error = Transaction(EOS_OC_GetObject, &flags, params, (void*)parser)) != PTP_RC_OK)
PTPTRACE2("GetObject error:", ptp_error);
return ptp_error;
}