2 * Copyright (C) 2009 Ubixum, Inc.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 #include <fx2macros.h>
24 #include <autovector.h>
32 #define SYNCDELAY() SYNCDELAY4;
41 REVCTL = 0; // not using advanced endpoint controls
46 REVCTL = 0x03; // DYN_OUT=1, ENH_PKT=1
52 sio0_init(57600); // needed for printf on sio0
66 //printf ( "sud is %d\n" , dosud );
78 #define VC_EEPROM 0xb1
80 BOOL handle_vendorcommand(BYTE cmd) {
81 WORD addr=SETUP_VALUE(),len=SETUP_LENGTH();
82 printf ( "Handle Vendor Command %02x, addr %d, len %d\n" , cmd, addr, len );
86 // wait for ep0 not busy
89 while (len) { // still have bytes to read
90 BYTE cur_read = len > 64 ? 64 : len; // can't read more than 64 bytes at a time
91 while (EP0CS&bmEPBUSY); // can't do this until EP0 is ready
92 eeprom_read(0x51, addr, cur_read, EP0BUF );
103 // printf ( "Len More Bytes %d\n" , len );
104 EP0BCL = 0; // allow pc transfer in
105 while(EP0CS & bmEPBUSY); // wait
107 // printf ( "Writing %d Bytes to %d..\n", cur_write, addr );
108 if ( !eeprom_write(0x51, addr, cur_write, EP0BUF ) ) return FALSE;
114 return FALSE; // bad type
117 printf ( "All OK\n" );
125 // set *alt_ifc to the current alt interface for ifc
126 BOOL handle_get_interface(BYTE ifc, BYTE* alt_ifc) {
130 // return TRUE if you set the interface requested
131 // NOTE this function should reconfigure and reset the endpoints
132 // according to the interface descriptors you provided.
133 BOOL handle_set_interface(BYTE ifc,BYTE alt_ifc) {
134 //return ifc==0&&alt_ifc==0;
135 printf ( "Host wants to set interface: %d\n", alt_ifc );
139 // handle getting and setting the configuration
140 // 0 is the default. If you support more than one config
141 // keep track of the config number and return the correct number
142 // config numbers are set int the dscr file.
143 volatile BYTE config=1;
144 BYTE handle_get_configuration() {
147 // return TRUE if you handle this request
148 // NOTE changing config requires the device to reset all the endpoints
149 BOOL handle_set_configuration(BYTE cfg) {
150 printf ( "host wants config: %d\n" , cfg );
156 void sudav_isr() interrupt SUDAV_ISR {
161 void usbreset_isr() interrupt USBRESET_ISR {
162 handle_hispeed(FALSE);
165 void hispeed_isr() interrupt HISPEED_ISR {
166 handle_hispeed(TRUE);