📄 fx2hid.lst
字号:
C51 COMPILER V7.50 FX2HID 05/29/2006 13:56:14 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 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/29/2006 13:56:14 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/29/2006 13:56:14 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 /*buttons &= 0x0F;
172 IN2BUF[0] = 0x00; // clear button state as seen by the host
173 if ((oldbuttons - buttons) != 0) //Change in button state
174 {
175
176 if ( !(buttons & 1) ) // left click
177 {
178 IN2BUF[0] |= 0x01;
179 }
C51 COMPILER V7.50 FX2HID 05/29/2006 13:56:14 PAGE 4
180
181 if ( !(buttons & 2) ) // right click
182 {
183 IN2BUF[0] |= 0x02;
184 }
185
186 if (buttons & 4) // Advance in x direction
187 IN2BUF[1] = 0x00;
188 else
189 IN2BUF[1] = 0x0A;
190
191 if (buttons & 8) // Advance in y direction
192 IN2BUF[2] = 0x00;
193 else
194 IN2BUF[2] = 0x0A;
195
196 IN2BC = 3;
197 }
198 oldbuttons = buttons;
199
200 */
201 void TD_Poll(void) // Called repeatedly while the device is idle
202 {
203 1 if( !(EP1INCS & 0x02) ) // Is the EP1INBUF available,
204 1 {
205 2
206 2 // This keyboard code is unneeded
207 2
208 2 buttons = read_buttons();
209 2 if (buttons == read_buttons()) //Debounce
210 2 {
211 3 buttons &= 0x0F;
212 3 EP1INBUF[0] = 0;
213 3 if ((oldbuttons - buttons) != 0) //Change in button state
214 3 {
215 4 if (!(buttons & 1)) // left click
216 4 {
217 5 EP1INBUF[0]|= 0x01;
218 5 }
219 4 if (!(buttons & 2)) //// right click
220 4 {
221 5 EP1INBUF[0] |= 0x02;
222 5 }
223 4 if (buttons & 4) //// Advance in x direction
224 4 EP1INBUF[1] = 0;
225 4 else
226 4 EP1INBUF[1] = 0x0A;
227 4 if (buttons & 8) //// Advance in y direction
228 4 EP1INBUF[2] = 0;
229 4 else
230 4 EP1INBUF[2] =0x0A;
231 4
232 4 EP1INBC = 3;
233 4 }
234 3 oldbuttons = buttons;
235 3 }
236 2
237 2 }
238 1 /* if( !(EP1OUTCS & 0x02) ) // Is there something available in EP1OUTBUF
239 1 {
240 1
241 1 // This keyboard code is unneeded by usbhidio
C51 COMPILER V7.50 FX2HID 05/29/2006 13:56:14 PAGE 5
242 1
243 1 leds = 0xFF; //Turn all off
244 1 if (EP1OUTBUF[0] & 0x02) //Caps
245 1 leds &= 0xBF;
246 1 if (EP1OUTBUF[0] & 0x01) //Scroll
247 1 leds &= 0xF7;
248 1 if (EP1OUTBUF[0] & 0x04) //Num
249 1 leds &= 0xFE;
250 1 write_leds (leds);
251 1
252 1
253 1 // usbhidio code start
254 1
255 1 // Copy bytes received on the OUT endpoint to the IN endpoint.
256 1 // EP1INBUF[0] = EP1OUTBUF[0];
257 1 // EP1INBUF[1] = EP1OUTBUF[1];
258 1
259 1 // Rearm the IN endpoint buffer to enable sending a report.
260 1 // The value equals the report size.
261 1 // EP1INBC = 2;
262 1
263 1 // usbhidiocode end
264 1
265 1 // EP1OUTBC = 0; //Rearm the OUT endpoint buffer to enable receiving a report.
266 1
267 1 } */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -