-
Notifications
You must be signed in to change notification settings - Fork 63
/
usb.c
136 lines (118 loc) · 3.12 KB
/
usb.c
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
/*
* This file is part of the DSLogic-fw project.
*
* Copyright (C) 2012 Uwe Hermann <[email protected]>
* Copyright (C) 2012 Joel Holdsworth <[email protected]>
* Copyright (C) 2014 DreamSourceLab <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <fx2regs.h>
#include <fx2macros.h>
#include <setupdat.h>
#include <eputils.h>
#include <DSLogic.h>
/* ... */
extern volatile __bit recv_setup;
extern BYTE command;
BOOL handle_vendorcommand(BYTE cmd)
{
/* Protocol implementation */
switch (cmd) {
case CMD_GET_FW_VERSION:
EP0BUF[0] = DSLOGICFW_VER_MAJOR;
EP0BUF[1] = DSLOGICFW_VER_MINOR;
EP0BCH = 0;
EP0BCL = 2;
return TRUE;
break;
case CMD_GET_REVID_VERSION:
EP0BUF[0] = REVID;
EP0BCH = 0;
EP0BCL = 1;
return TRUE;
break;
case CMD_START:
case CMD_SETTING:
case CMD_CONTROL:
command = cmd;
EP0BCL = 0;
return TRUE;
break;
case CMD_CONFIG:
IOA |= 0x03;
command = cmd;
EP0BCL = 0;
return TRUE;
break;
}
return FALSE;
}
BOOL handle_get_interface(BYTE ifc, BYTE *alt_ifc)
{
/* We only support interface 0, alternate interface 0. */
if (ifc != 0)
return FALSE;
*alt_ifc = 0;
return TRUE;
}
BOOL handle_set_interface(BYTE ifc, BYTE alt_ifc)
{
/* We only support interface 0, alternate interface 0. */
if (ifc != 0 || alt_ifc != 0)
return FALSE;
/* Perform procedure from TRM, section 2.3.7: */
/* (1) TODO. */
/* (2) Reset data toggles of the EPs in the interface. */
/* Note: RESETTOGGLE() gets the EP number WITH bit 7 set/cleared. */
RESETTOGGLE(0x86);
RESETTOGGLE(0x02);
/* (3) Restore EPs to their default conditions. */
/* Note: RESETFIFO() gets the EP number WITHOUT bit 7 set/cleared. */
RESETFIFO(0x06);
RESETFIFO(0x02);
/* TODO */
/* (4) Clear the HSNAK bit. Not needed, fx2lib does this. */
return TRUE;
}
BYTE handle_get_configuration(void)
{
/* Only support configuration 1. */
return 1;
}
BOOL handle_set_configuration(BYTE cfg)
{
/* Only support configuration 1. */
return (cfg == 1) ? TRUE : FALSE;
}
void sudav_isr(void) __interrupt SUDAV_ISR
{
recv_setup = TRUE;
CLEAR_SUDAV();
}
void sof_isr(void) __interrupt SOF_ISR __using 1
{
CLEAR_SOF();
}
void usbreset_isr(void) __interrupt USBRESET_ISR
{
handle_hispeed(FALSE);
CLEAR_USBRESET();
}
void hispeed_isr(void) __interrupt HISPEED_ISR
{
handle_hispeed(TRUE);
CLEAR_HISPEED();
}