Mercurial > ~darius > hgwebdir.cgi > avr
annotate usb.h @ 62:e955aa7047ed
Don't update the temperature we make decisions if it is invalid.
author | darius@Inchoate |
---|---|
date | Thu, 30 Oct 2008 20:09:02 +1030 |
parents | fed32b382de2 |
children |
rev | line source |
---|---|
23 | 1 /* |
2 * Copyright (c) 2003 Bernd Walter | |
3 * All rights reserved. | |
4 */ | |
5 | |
6 /* Example Source Code for USB Enumeration using a PDIUSBD11 connected to a PIC16F87x | |
7 * Copyright 2001 Craig Peacock, Craig.Peacock@beyondlogic.org | |
8 * 31th December 2001 http://www.beyondlogic.org | |
9 */ | |
10 | |
11 typedef struct { | |
12 uint8_t bmRequestType; | |
13 uint8_t bRequest; | |
14 uint16_t wValue; | |
15 uint16_t wIndex; | |
16 uint16_t wLength; | |
31 | 17 } __attribute__ ((packed)) USB_SETUP_REQUEST; |
23 | 18 |
19 typedef struct { | |
20 uint8_t bLength; | |
21 uint8_t bDescriptorType; | |
22 uint16_t bcdUSB; | |
23 uint8_t bDeviceClass; | |
24 uint8_t bDeviceSubClass; | |
25 uint8_t bDeviceProtocol; | |
26 uint8_t bMaxPacketSize0; | |
27 uint16_t idVendor; | |
28 uint16_t idProduct; | |
29 uint16_t bcdDevice; | |
30 uint8_t iManufacturer; | |
31 uint8_t iProduct; | |
32 uint8_t iSerialNumber; | |
33 uint8_t bNumConfigurations; | |
31 | 34 } __attribute__ ((packed)) USB_DEVICE_DESCRIPTOR; |
23 | 35 |
36 typedef struct { | |
37 uint8_t bLength; | |
38 uint8_t bDescriptorType; | |
39 uint8_t bEndpointAddress; | |
40 uint8_t bmAttributes; | |
41 uint16_t wMaxPacketSize; | |
42 uint8_t bInterval; | |
31 | 43 } __attribute__ ((packed)) USB_ENDPOINT_DESCRIPTOR; |
23 | 44 |
45 typedef struct { | |
46 uint8_t bLength; | |
47 uint8_t bDescriptorType; | |
48 uint16_t wTotalLength; | |
49 uint8_t bNumInterfaces; | |
50 uint8_t bConfigurationValue; | |
51 uint8_t iConfiguration; | |
52 uint8_t bmAttributes; | |
53 uint8_t MaxPower; | |
31 | 54 } __attribute__ ((packed)) USB_CONFIGURATION_DESCRIPTOR; |
23 | 55 |
56 typedef struct { | |
57 uint8_t bLength; | |
58 uint8_t bDescriptorType; | |
59 uint8_t bInterfaceNumber; | |
60 uint8_t bAlternateSetting; | |
61 uint8_t bNumEndpoints; | |
62 uint8_t bInterfaceClass; | |
63 uint8_t bInterfaceSubClass; | |
64 uint8_t bInterfaceProtocol; | |
65 uint8_t iInterface; | |
31 | 66 } __attribute__ ((packed)) USB_INTERFACE_DESCRIPTOR; |
23 | 67 |
68 typedef struct { | |
69 uint8_t bLength; | |
70 uint8_t bDescriptorType; | |
71 uint16_t wHIDClassSpecComp; | |
72 uint8_t bCountry; | |
73 uint8_t bNumDescriptors; | |
74 uint8_t b1stDescType; | |
75 uint16_t w1stDescLength; | |
31 | 76 } __attribute__ ((packed)) USB_HID_DESCRIPTOR; |
23 | 77 |
78 typedef struct { | |
79 USB_CONFIGURATION_DESCRIPTOR ConfigDescriptor; | |
80 USB_INTERFACE_DESCRIPTOR InterfaceDescriptor0; | |
81 USB_ENDPOINT_DESCRIPTOR EndpointDescriptor00; | |
82 USB_ENDPOINT_DESCRIPTOR EndpointDescriptor01; | |
83 USB_INTERFACE_DESCRIPTOR InterfaceDescriptor1; | |
84 USB_ENDPOINT_DESCRIPTOR EndpointDescriptor10; | |
85 USB_ENDPOINT_DESCRIPTOR EndpointDescriptor11; | |
31 | 86 } __attribute__ ((packed)) USB_CONFIG_DATA; |
23 | 87 |
88 typedef struct { | |
89 uint8_t bLength; | |
90 uint8_t bDescriptorType; | |
91 char bString[]; | |
31 | 92 } __attribute__ ((packed)) STRING_DESCRIPTOR; |
23 | 93 |
94 typedef struct { | |
95 uint8_t bLength; | |
96 uint8_t bDescriptorType; | |
97 uint16_t wLANGID0; | |
31 | 98 } __attribute__ ((packed)) LANGID_DESCRIPTOR; |
23 | 99 |
35
fed32b382de2
Tidy up, hide details behind macros to make it more obvious what we
darius
parents:
31
diff
changeset
|
100 #define D12_SET_ADDRESS_ENABLE 0xd0 |
fed32b382de2
Tidy up, hide details behind macros to make it more obvious what we
darius
parents:
31
diff
changeset
|
101 #define D12_SET_ENDPOINT_ENABLE 0xd8 |
fed32b382de2
Tidy up, hide details behind macros to make it more obvious what we
darius
parents:
31
diff
changeset
|
102 #define D12_SET_MODE 0xf3 |
fed32b382de2
Tidy up, hide details behind macros to make it more obvious what we
darius
parents:
31
diff
changeset
|
103 #define D12_SET_DMA 0xfb |
fed32b382de2
Tidy up, hide details behind macros to make it more obvious what we
darius
parents:
31
diff
changeset
|
104 #define D12_READ_INTERRUPT_REGISTER 0xf4 |
fed32b382de2
Tidy up, hide details behind macros to make it more obvious what we
darius
parents:
31
diff
changeset
|
105 #define D12_READ_BUFFER 0xf0 |
fed32b382de2
Tidy up, hide details behind macros to make it more obvious what we
darius
parents:
31
diff
changeset
|
106 #define D12_WRITE_BUFFER 0xf0 |
fed32b382de2
Tidy up, hide details behind macros to make it more obvious what we
darius
parents:
31
diff
changeset
|
107 #define D12_ACK_SETUP 0xf2 |
fed32b382de2
Tidy up, hide details behind macros to make it more obvious what we
darius
parents:
31
diff
changeset
|
108 #define D12_CLEAR_BUFFER 0xf2 |
fed32b382de2
Tidy up, hide details behind macros to make it more obvious what we
darius
parents:
31
diff
changeset
|
109 #define D12_VALIDATE_BUFFER 0xfa |
23 | 110 #define D12_READ_LAST_TRANSACTION 0x40 |
111 #define D12_SET_ENDPOINT_STATUS 0x40 | |
112 #define D12_READ_ENDPOINT_STATUS 0x80 | |
35
fed32b382de2
Tidy up, hide details behind macros to make it more obvious what we
darius
parents:
31
diff
changeset
|
113 #define D12_READ_CHIP_ID 0xfd |
23 | 114 |
115 #define D12_ENDPOINT_EP0_OUT 0x00 | |
116 #define D12_ENDPOINT_EP0_IN 0x01 | |
117 #define D12_ENDPOINT_EP1_OUT 0x02 | |
118 #define D12_ENDPOINT_EP1_IN 0x03 | |
119 #define D12_ENDPOINT_EP2_OUT 0x04 | |
120 #define D12_ENDPOINT_EP2_IN 0x05 | |
121 | |
122 #define D12_INT_EP0_OUT 0x01 | |
123 #define D12_INT_EP0_IN 0x02 | |
124 #define D12_INT_EP1_OUT 0x04 | |
125 #define D12_INT_EP1_IN 0x08 | |
126 #define D12_INT_EP2_OUT 0x10 | |
127 #define D12_INT_EP2_IN 0x20 | |
128 #define D12_INT_BUS_RESET 0x40 | |
129 #define D12_INT_SUSPEND 0x80 | |
130 | |
31 | 131 #define D12_LAST_TRAN_OK 0x01 |
132 #define D12_LAST_TRAN_ERRMSK 0x1e | |
23 | 133 #define D12_LAST_TRAN_SETUP 0x20 |
31 | 134 #define D12_LAST_TRAN_DATA 0x40 |
135 #define D12_LAST_TRAN_OFLOW 0x80 | |
23 | 136 |
137 #define STANDARD_DEVICE_REQUEST 0x00 | |
138 #define STANDARD_INTERFACE_REQUEST 0x01 | |
139 #define STANDARD_ENDPOINT_REQUEST 0x02 | |
140 #define VENDOR_DEVICE_REQUEST 0x40 | |
141 #define VENDOR_INTERFACE_REQUEST 0x41 | |
142 #define VENDOR_ENDPOINT_REQUEST 0x42 | |
143 | |
144 #define GET_STATUS 0 | |
145 #define CLEAR_FEATURE 1 | |
146 #define SET_FEATURE 3 | |
147 #define SET_ADDRESS 5 | |
148 #define GET_DESCRIPTOR 6 | |
149 #define SET_DESCRIPTOR 7 | |
150 #define GET_CONFIGURATION 8 | |
151 #define SET_CONFIGURATION 9 | |
152 #define GET_INTERFACE 10 | |
153 #define SET_INTERFACE 11 | |
154 #define SYNCH_FRAME 12 | |
155 | |
31 | 156 #define VENDOR_DOTEMP 125 |
23 | 157 #define VENDOR_UPDATE 126 |
158 #define VENDOR_RESET 127 | |
159 | |
160 #define ENDPOINT_HALT 0 | |
161 | |
162 #define TYPE_DEVICE_DESCRIPTOR 1 | |
163 #define TYPE_CONFIGURATION_DESCRIPTOR 2 | |
164 #define TYPE_STRING_DESCRIPTOR 3 | |
165 #define TYPE_INTERFACE_DESCRIPTOR 4 | |
166 #define TYPE_ENDPOINT_DESCRIPTOR 5 | |
167 #define TYPE_HID_DESCRIPTOR 0x21 | |
168 | |
169 #define USB_ENDPOINT_TYPE_CONTROL 0x00 | |
170 #define USB_ENDPOINT_TYPE_ISOCHRONOUS 0x01 | |
171 #define USB_ENDPOINT_TYPE_BULK 0x02 | |
172 #define USB_ENDPOINT_TYPE_INTERRUPT 0x03 | |
173 | |
174 /* Function prototypes */ | |
175 uint8_t d12_get_data(void); | |
176 void d12_set_data(uint8_t data); | |
177 void d12_set_cmd(uint8_t cmd); | |
178 void d12_write_cmd(uint8_t command, const uint8_t *buffer, uint8_t count); | |
179 void d12_read_cmd(uint8_t command, uint8_t *buffer, uint8_t count); | |
180 uint8_t d12_read_endpt(uint8_t endpt, uint8_t *buffer); | |
181 | |
182 void d12_ep0_irq(void); | |
31 | 183 void d12_handle_setup(void); |
184 void d12_getdescriptor(USB_SETUP_REQUEST *setuppkt); | |
185 void d12_stallendpt(uint8_t ep); | |
23 | 186 uint8_t d12_read_endpt(uint8_t endpt, uint8_t *buffer); |
187 void d12_write_endpt(uint8_t endpt, const uint8_t *buffer, uint8_t bytes); | |
31 | 188 void d12_send_data_ep0(void); |
189 void d12_receive_data_ep1(void); | |
23 | 190 void d12_send_data_ep2(void); |
191 void d12_receive_data_ep2(void); | |
192 | |
35
fed32b382de2
Tidy up, hide details behind macros to make it more obvious what we
darius
parents:
31
diff
changeset
|
193 void reset(void); |
23 | 194 |
195 void usb_init(void); | |
196 void usb_intr(void); | |
197 void usb_gendata(void); | |
35
fed32b382de2
Tidy up, hide details behind macros to make it more obvious what we
darius
parents:
31
diff
changeset
|
198 |
fed32b382de2
Tidy up, hide details behind macros to make it more obvious what we
darius
parents:
31
diff
changeset
|
199 /* |
fed32b382de2
Tidy up, hide details behind macros to make it more obvious what we
darius
parents:
31
diff
changeset
|
200 * The PDIUSBD12 is wired up like so |
fed32b382de2
Tidy up, hide details behind macros to make it more obvious what we
darius
parents:
31
diff
changeset
|
201 * |
fed32b382de2
Tidy up, hide details behind macros to make it more obvious what we
darius
parents:
31
diff
changeset
|
202 * PDI AVR |
fed32b382de2
Tidy up, hide details behind macros to make it more obvious what we
darius
parents:
31
diff
changeset
|
203 * ====================== |
fed32b382de2
Tidy up, hide details behind macros to make it more obvious what we
darius
parents:
31
diff
changeset
|
204 * D7:0 <=> PA7:0 |
fed32b382de2
Tidy up, hide details behind macros to make it more obvious what we
darius
parents:
31
diff
changeset
|
205 * RD_N <= PB0 |
fed32b382de2
Tidy up, hide details behind macros to make it more obvious what we
darius
parents:
31
diff
changeset
|
206 * INT_N => PB1 |
fed32b382de2
Tidy up, hide details behind macros to make it more obvious what we
darius
parents:
31
diff
changeset
|
207 * WR_N <= PB2 |
fed32b382de2
Tidy up, hide details behind macros to make it more obvious what we
darius
parents:
31
diff
changeset
|
208 * A0 <= PB3 (0 = data, 1 = cmd) |
fed32b382de2
Tidy up, hide details behind macros to make it more obvious what we
darius
parents:
31
diff
changeset
|
209 * SUSPEND <=> PB4 |
fed32b382de2
Tidy up, hide details behind macros to make it more obvious what we
darius
parents:
31
diff
changeset
|
210 */ |
fed32b382de2
Tidy up, hide details behind macros to make it more obvious what we
darius
parents:
31
diff
changeset
|
211 |
fed32b382de2
Tidy up, hide details behind macros to make it more obvious what we
darius
parents:
31
diff
changeset
|
212 #define PDIPORT PORTA |
fed32b382de2
Tidy up, hide details behind macros to make it more obvious what we
darius
parents:
31
diff
changeset
|
213 #define PDIDDR PORTA |
fed32b382de2
Tidy up, hide details behind macros to make it more obvious what we
darius
parents:
31
diff
changeset
|
214 #define PDICTL PORTB |
fed32b382de2
Tidy up, hide details behind macros to make it more obvious what we
darius
parents:
31
diff
changeset
|
215 #define PDIRD PB0 |
fed32b382de2
Tidy up, hide details behind macros to make it more obvious what we
darius
parents:
31
diff
changeset
|
216 #define PDIINT PB1 |
fed32b382de2
Tidy up, hide details behind macros to make it more obvious what we
darius
parents:
31
diff
changeset
|
217 #define PDIWR PB2 |
fed32b382de2
Tidy up, hide details behind macros to make it more obvious what we
darius
parents:
31
diff
changeset
|
218 #define PDIA0 PB3 |
fed32b382de2
Tidy up, hide details behind macros to make it more obvious what we
darius
parents:
31
diff
changeset
|
219 #define PDISUSP PB4 |
fed32b382de2
Tidy up, hide details behind macros to make it more obvious what we
darius
parents:
31
diff
changeset
|
220 |