📄 fx2hid.lst
字号:
C51 COMPILER V7.50 FX2HID 05/27/2006 13:40:49 PAGE 1
C51 COMPILER V7.50, COMPILATION OF MODULE FX2HID
OBJECT MODULE PLACED IN fx2hid.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE fx2hid.c NOAREGS DEBUG OBJECTEXTEND
line level source
1 #pragma NOIV // Do not generate interrupt vectors
2 /*
3 -----------------------------------------------------------------------------
4 File: usbhidio_fx2.c
5 Contents: Hooks required to implement USB peripheral function.
6
7 This is an adaptation of the Cypress example FX2_Hid_Keyboard.c,
8 which was in turn adapted from Cypress's bulkloop.c
9 (and is available on request from Cypress).
10
11 The application communicates with the usbhdio host applications available from:
12
13 www.Lvr.com/hidpage.htm
14
15 This code requires the full (not evaluation) version of the Keil compiler.
16 Additions to the keyboard code are labeled with "usbhidio start" and "usbhidio end"
17 Unneeded keyboard code is commented out.
18
19 Copyright (c) 2000 Cypress Semiconductor All rights reserved
20 with some changes by Jan Axelson (jan@Lvr.com)
21 -----------------------------------------------------------------------------
22 */
23
24 #include "fx2.h"
25 #include "fx2regs.h"
26 #include "fx2sdly.h" // SYNCDELAY macro
27
28 extern BOOL GotSUD; // Received setup data flag
29 extern BOOL Sleep;
30 extern BOOL Rwuen;
31 extern BOOL Selfpwr;
32
33 #define min(a,b) (((a)<(b))?(a):(b))
34
35 #define GD_HID 0x21
36 #define GD_REPORT 0x22
37 #define CR_SET_REPORT 0x09
38 #define HID_OUTPUT_REPORT 2
39
40 #define BTN_ADDR 0x71
41 #define LED_ADDR 0x72
42
43 #define PF_IDLE 0
44 #define PF_GETKEYS 1
45
46 #define KEY_WAKEUP 0
47 #define KEY_F1 1
48 #define KEY_F2 2
49 #define KEY_F3 3
50
51 WORD pHIDDscr;
52 WORD pReportDscr;
53 WORD pReportDscrEnd;
54 extern code HIDDscr;
55 extern code ReportDscr;
C51 COMPILER V7.50 FX2HID 05/27/2006 13:40:49 PAGE 2
56 extern code ReportDscrEnd;
57
58 BYTE Configuration; // Current configuration
59 BYTE AlternateSetting; // Alternate settings
60
61 BYTE Configuration; // Current configuration
62 BYTE AlternateSetting; // Alternate settings
63
64 BYTE buttons;
65 BYTE oldbuttons;
66 BYTE leds = 0xFF;
67
68 BYTE read_buttons (void);
69 void write_leds (BYTE d);
70
71 #define VR_NAKALL_ON 0xD0
72 #define VR_NAKALL_OFF 0xD1
73 //-----------------------------------------------------------------------------
74 // Task Dispatcher hooks
75 // The following hooks are called by the task dispatcher.
76 //-----------------------------------------------------------------------------
77
78 // read_buttons and write_leds are unused by usbhidio
79
80 BYTE read_buttons (void)
81 {
82 1 BYTE d;
83 1
84 1 while (I2CS & 0x40); //Wait for stop to be done
85 1 I2CS = 0x80; //Set start condition
86 1 I2DAT = BTN_ADDR; //Write button address
87 1 while (!(I2CS & 0x01)); //Wait for done
88 1 I2CS = 0x20; //Set last read
89 1 d = I2DAT; //Dummy read
90 1 while (!(I2CS & 0x01)); //Wait for done
91 1 I2CS = 0x40; //Set stop bit
92 1 return(I2DAT); //Read the data
93 1 }
94
95 /*
96 void write_leds (BYTE d)
97 {
98 while (I2CS & 0x40); //Wait for stop to be done
99 I2CS = 0x80; //Set start condition
100 I2DAT = LED_ADDR; //Write led address
101 while (!(I2CS & 0x01)); //Wait for done
102 I2DAT = d; //Write data
103 while (!(I2CS & 0x01)); //Wait for done
104 I2CS = 0x40; //Set stop bit
105 }
106
107 */
108
109 void TD_Init(void) // Called once at startup
110 {
111 1 // set the CPU clock to 48MHz
112 1 CPUCS = ((CPUCS & ~bmCLKSPD) | bmCLKSPD1) ;
113 1
114 1 // set the slave FIFO interface to 48MHz
115 1 IFCONFIG |= 0x40;
116 1
117 1 // Registers which require a synchronization delay, see section 15.14
C51 COMPILER V7.50 FX2HID 05/27/2006 13:40:49 PAGE 3
118 1 // FIFORESET FIFOPINPOLAR
119 1 // INPKTEND OUTPKTEND
120 1 // EPxBCH:L REVCTL
121 1 // GPIFTCB3 GPIFTCB2
122 1 // GPIFTCB1 GPIFTCB0
123 1 // EPxFIFOPFH:L EPxAUTOINLENH:L
124 1 // EPxFIFOCFG EPxGPIFFLGSEL
125 1 // PINFLAGSxx EPxFIFOIRQ
126 1 // EPxFIFOIE GPIFIRQ
127 1 // GPIFIE GPIFADRH:L
128 1 // UDMACRCH:L EPxGPIFTRIG
129 1 // GPIFTRIG
130 1
131 1 // Note: The pre-REVE EPxGPIFTCH/L register are affected, as well...
132 1 // ...these have been replaced by GPIFTC[B3:B0] registers
133 1
134 1 // default: all endpoints have their VALID bit set
135 1 // default: TYPE1 = 1 and TYPE0 = 0 --> BULK
136 1 // default: EP2 and EP4 DIR bits are 0 (OUT direction)
137 1 // default: EP6 and EP8 DIR bits are 1 (IN direction)
138 1 // default: EP2, EP4, EP6, and EP8 are double buffered
139 1
140 1 // we are just using the default values, yes this is not necessary...
141 1 EP1OUTCFG = 0xA0;
142 1 EP1INCFG = 0xA0;
143 1 SYNCDELAY; // see TRM section 15.14
144 1 EP2CFG = 0xA2;
145 1 SYNCDELAY;
146 1 EP4CFG = 0xA0;
147 1 SYNCDELAY;
148 1 EP6CFG = 0xE2;
149 1 SYNCDELAY;
150 1 EP8CFG = 0xE0;
151 1
152 1 // out endpoints do not come up armed
153 1
154 1 // since the defaults are double buffered we must write dummy byte counts twice
155 1 SYNCDELAY;
156 1 EP2BCL = 0x80; // arm EP2OUT by writing byte count w/skip.
157 1 SYNCDELAY;
158 1 EP2BCL = 0x80;
159 1 SYNCDELAY;
160 1 EP4BCL = 0x80; // arm EP4OUT by writing byte count w/skip.
161 1 SYNCDELAY;
162 1 EP4BCL = 0x80;
163 1
164 1 // enable dual autopointer feature
165 1 AUTOPTRSETUP |= 0x01;
166 1
167 1 Rwuen = TRUE; // Enable remote-wakeup
168 1
169 1 }
170
171
172 void TD_Poll(void) // Called repeatedly while the device is idle
173 {
174 1 if( !(EP1INCS & 0x02) ) // Is the EP1INBUF available,
175 1 {
176 2
177 2 // This keyboard code is unneeded
178 2
179 2 buttons = read_buttons();
C51 COMPILER V7.50 FX2HID 05/27/2006 13:40:49 PAGE 4
180 2 if (buttons == read_buttons()) //Debounce
181 2 {
182 3 buttons &= 0x0F;
183 3 if ((oldbuttons - buttons) != 0) //Change in button state
184 3 {
185 4 if (buttons & 1) //Shift
186 4 EP1INBUF[0] = 0;
187 4 else
188 4 EP1INBUF[0] = 2;
189 4 if (buttons & 2) //a
190 4 EP1INBUF[2] = 0;
191 4 else
192 4 EP1INBUF[2] = 4;
193 4 if (buttons & 4) //b
194 4 EP1INBUF[3] = 0;
195 4 else
196 4 EP1INBUF[3] = 5;
197 4 if (buttons & 8) //c
198 4 EP1INBUF[4] = 0;
199 4 else
200 4 EP1INBUF[4] = 6;
201 4 EP1INBUF[1] = 0;
202 4 EP1INBC = 5;
203 4 }
204 3 oldbuttons = buttons;
205 3 }
206 2
207 2 }
208 1 /* if( !(EP1OUTCS & 0x02) ) // Is there something available in EP1OUTBUF
209 1 {
210 1
211 1 // This keyboard code is unneeded by usbhidio
212 1
213 1 leds = 0xFF; //Turn all off
214 1 if (EP1OUTBUF[0] & 0x02) //Caps
215 1 leds &= 0xBF;
216 1 if (EP1OUTBUF[0] & 0x01) //Scroll
217 1 leds &= 0xF7;
218 1 if (EP1OUTBUF[0] & 0x04) //Num
219 1 leds &= 0xFE;
220 1 write_leds (leds);
221 1
222 1
223 1 // usbhidio code start
224 1
225 1 // Copy bytes received on the OUT endpoint to the IN endpoint.
226 1 // EP1INBUF[0] = EP1OUTBUF[0];
227 1 // EP1INBUF[1] = EP1OUTBUF[1];
228 1
229 1 // Rearm the IN endpoint buffer to enable sending a report.
230 1 // The value equals the report size.
231 1 // EP1INBC = 2;
232 1
233 1 // usbhidiocode end
234 1
235 1 // EP1OUTBC = 0; //Rearm the OUT endpoint buffer to enable receiving a report.
236 1
237 1 } */
238 1 }
239
240 BOOL TD_Suspend(void) // Called before the device goes into suspend mode
241 {
C51 COMPILER V7.50 FX2HID 05/27/2006 13:40:49 PAGE 5
242 1 return(TRUE);
243 1 }
244
245 BOOL TD_Resume(void) // Called after the device resumes
246 {
247 1 return(TRUE);
248 1 }
249
250 //-----------------------------------------------------------------------------
251 // Device Request hooks
252 // The following hooks are called by the end point 0 device request parser.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -