Debian Codegraph @

src/dfu.h

raw
1 /*
2 * dfu-programmer
3 *
4 * $Id: dfu.h,v 1.2 2005/09/25 01:27:42 schmidtw Exp $
5 *
6 * This program 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 of the License, or
9 * (at your option) any later version.
10 *
11 * This program 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 this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21 #ifndef DFU_H
22 #define DFU_H
23
24 #include <libusb.h>
25 #include "usb_dfu.h"
26 #include "dfuse_mem.h"
27
28 /* DFU states */
29 #define STATE_APP_IDLE 0x00
30 #define STATE_APP_DETACH 0x01
31 #define STATE_DFU_IDLE 0x02
32 #define STATE_DFU_DOWNLOAD_SYNC 0x03
33 #define STATE_DFU_DOWNLOAD_BUSY 0x04
34 #define STATE_DFU_DOWNLOAD_IDLE 0x05
35 #define STATE_DFU_MANIFEST_SYNC 0x06
36 #define STATE_DFU_MANIFEST 0x07
37 #define STATE_DFU_MANIFEST_WAIT_RESET 0x08
38 #define STATE_DFU_UPLOAD_IDLE 0x09
39 #define STATE_DFU_ERROR 0x0a
40
41
42 /* DFU status */
43 #define DFU_STATUS_OK 0x00
44 #define DFU_STATUS_ERROR_TARGET 0x01
45 #define DFU_STATUS_ERROR_FILE 0x02
46 #define DFU_STATUS_ERROR_WRITE 0x03
47 #define DFU_STATUS_ERROR_ERASE 0x04
48 #define DFU_STATUS_ERROR_CHECK_ERASED 0x05
49 #define DFU_STATUS_ERROR_PROG 0x06
50 #define DFU_STATUS_ERROR_VERIFY 0x07
51 #define DFU_STATUS_ERROR_ADDRESS 0x08
52 #define DFU_STATUS_ERROR_NOTDONE 0x09
53 #define DFU_STATUS_ERROR_FIRMWARE 0x0a
54 #define DFU_STATUS_ERROR_VENDOR 0x0b
55 #define DFU_STATUS_ERROR_USBR 0x0c
56 #define DFU_STATUS_ERROR_POR 0x0d
57 #define DFU_STATUS_ERROR_UNKNOWN 0x0e
58 #define DFU_STATUS_ERROR_STALLEDPKT 0x0f
59
60 /* DFU commands */
61 #define DFU_DETACH 0
62 #define DFU_DNLOAD 1
63 #define DFU_UPLOAD 2
64 #define DFU_GETSTATUS 3
65 #define DFU_CLRSTATUS 4
66 #define DFU_GETSTATE 5
67 #define DFU_ABORT 6
68
69 /* DFU interface */
70 #define DFU_IFF_DFU 0x0001 /* DFU Mode, (not Runtime) */
71 #define DFU_IFF_ALT 0x0002 /* Multiple alternate settings */
72
73 /* This is based off of DFU_GETSTATUS
74 *
75 * 1 unsigned byte bStatus
76 * 3 unsigned byte bwPollTimeout
77 * 1 unsigned byte bState
78 * 1 unsigned byte iString
79 */
80
81 struct dfu_status {
82 unsigned char bStatus;
83 unsigned int bwPollTimeout;
84 unsigned char bState;
85 unsigned char iString;
86 };
87
88 struct dfu_if {
89 struct usb_dfu_func_descriptor func_dfu;
90 uint16_t quirks;
91 uint16_t busnum;
92 uint16_t devnum;
93 uint16_t vendor;
94 uint16_t product;
95 uint16_t bcdDevice;
96 uint8_t configuration;
97 uint8_t interface;
98 uint8_t altsetting;
99 uint8_t flags;
100 uint8_t bMaxPacketSize0;
101 char *alt_name;
102 char *serial_name;
103 libusb_device *dev;
104 libusb_device_handle *dev_handle;
105 struct dfu_if *next;
106 struct memsegment *mem_layout; /* for DfuSe */
107 };
108
109 int dfu_detach( libusb_device_handle *device,
110 const unsigned short interface,
111 const unsigned short timeout );
112 int dfu_download( libusb_device_handle *device,
113 const unsigned short interface,
114 const unsigned short length,
115 const unsigned short transaction,
116 unsigned char* data );
117 int dfu_upload( libusb_device_handle *device,
118 const unsigned short interface,
119 const unsigned short length,
120 const unsigned short transaction,
121 unsigned char* data );
122 int dfu_get_status( struct dfu_if *dif,
123 struct dfu_status *status );
124 int dfu_clear_status( libusb_device_handle *device,
125 const unsigned short interface );
126 int dfu_get_state( libusb_device_handle *device,
127 const unsigned short interface );
128 int dfu_abort( libusb_device_handle *device,
129 const unsigned short interface );
130 int dfu_abort_to_idle( struct dfu_if *dif);
131
132 const char *dfu_state_to_string( int state );
133
134 const char *dfu_status_to_string( int status );
135
136 #endif /* DFU_H */