1 /*******************************************************************
2 Copyright (C) 2009 FreakLabs
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions
9 1. Redistributions of source code must retain the above copyright
10 notice, this list of conditions and the following disclaimer.
11 2. Redistributions in binary form must reproduce the above copyright
12 notice, this list of conditions and the following disclaimer in the
13 documentation and/or other materials provided with the distribution.
14 3. Neither the name of the the copyright holder nor the names of its contributors
15 may be used to endorse or promote products derived from this software
16 without specific prior written permission.
18 THIS SOFTWARE IS PROVIDED BY THE THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
19 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
22 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 Originally written by Christopher Wang aka Akiba.
31 Please post support questions to the FreakLabs forum.
33 *******************************************************************/
38 /*******************************************************************/
53 #define FLASHMEM PROGMEM ///< AVR Specific for storing data in flash
54 #define MAX_RX_ENTRIES 5
55 #define MAX_EPS 7 ///< AVR Specific for AT90USB USB controller
56 #define POWER_SRC BUS_POWERED
57 #define MAX_REQUEST_SIZE 32
58 #define CTRL_IN_REQ_SZ 8
91 #define PKTTYP_SETUP 0
96 #define GET_STATUS 0x00
97 #define GET_DESCRIPTOR 0x06
98 #define GET_CONFIGURATION 0x08
99 #define GET_INTERFACE 0x0A
100 #define SYNC_FRAME 0x0C
103 #define SET_FEATURE 0x03
104 #define SET_ADDRESS 0x05
105 #define SET_DESCRIPTOR 0x07
106 #define SET_CONFIGURATION 0x09
107 #define SET_INTERFACE 0x0B
108 #define CLEAR_FEATURE 0x01
116 #define DEV_QUAL_DESCR 6
119 #define HOST_TO_DEVICE 0x00
120 #define DEVICE_TO_HOST 0x80
121 #define TYPE_STD 0x00
122 #define TYPE_CLASS 0x20
123 #define TYPE_VENDOR 0x40
124 #define RECIPIENT_DEV 0x00
125 #define RECIPIENT_INTF 0x01
126 #define RECIPIENT_EP 0x02
128 // get status requests
129 #define GET_DEVICE_STATUS 0x80
130 #define GET_INTF_STATUS 0x81
131 #define GET_EP_STATUS 0x82
134 #define LANG_DESC_IDX 0
135 #define MANUF_DESC_IDX 1
136 #define PROD_DESC_IDX 2
137 #define SERIAL_DESC_IDX 3
140 #define ENDPOINT_HALT 0
141 #define REMOTE_WAKEUP 1
144 #define RX_DATA_AVAIL 0
145 #define TX_DATA_AVAIL 1
146 #define SETUP_DATA_AVAIL 2
147 #define REMOTE_WAKEUP_ENB 3
151 #define SELF_POWERED 1
152 #define BUS_POWERED 0
165 // buffer used for circular fifo
166 typedef struct _usb_buffer_t
169 volatile U8 len
; // this may change in an interrupt and the value would be required
175 // protocol control block
176 typedef struct _usb_pcb_t
184 usb_buffer_t fifo
[NUM_EPS
];
185 void (*class_init
)();
186 void (*class_req_handler
)(req_t
*req
);
187 void (*class_rx_handler
)();
194 usb_pcb_t
*usb_pcb_get();
195 void usb_reg_class_drvr(void (*class_cfg_init
)(),
196 void (*class_req_handler
)(),
197 void (*class_rx_handler
)());
205 void ep_select(U8 ep_num
);
206 void ep_write_from_flash(U8 ep_num
, U8
*data
, U8 len
);
207 void ep_write(U8 ep_num
);
208 void ep_write_ctrl(U8
*data
, U8 len
, bool read_from_flash
);
209 void ep_read(U8 ep_num
);
210 void ep_set_addr(U8 addr
);
211 U8
ep_intp_get_num();
212 U8
ep_intp_get_src();
213 void ep_set_stall(U8 ep_num
);
214 void ep_clear_stall(U8 ep_num
);
215 void ep_reset_toggle(U8 ep_num
);
216 void ep_send_zlp(U8 ep_num
);
217 void ep_config(U8 ep_num
, U8 type
, U8 dir
, U8 size
);
221 U8
desc_dev_get_len();
223 U8
desc_cfg_get_len();
224 U8
*desc_dev_qual_get();
225 U8
desc_dev_qual_get_len();
226 U8
*desc_str_get(U8 index
);
227 U8
desc_str_get_len(U8 index
);
230 void usb_buf_init(U8 ep_num
, U8 ep_dir
);
231 U8
usb_buf_read(U8 ep_num
);
232 void usb_buf_write(U8 ep_num
, U8 data
);
233 void usb_buf_clear_fifo(U8 ep_num
);
234 U8
usb_buf_data_pending(U8 ep_dir
);
237 //void dbg_led_init();
238 //void dbg_led_enb(U8 led_num);
239 //void dbg_led_dis(U8 led_num);
240 //void dbg_joystick_init();
241 //U8 dbg_joystick_get_status();
242 //void dbg_hwb_init();
243 //bool dbg_hwb_get_status();