Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

added USB_NAK_NOWAIT

  • Loading branch information...
commit 13535b080de8be3267d76f9516bc981b96e1f8a0 1 parent 063af40
Oleg Mazurov authored April 15, 2010
72  Max3421e.cpp
@@ -5,35 +5,56 @@
5 5
 
6 6
 static byte vbusState;
7 7
 
  8
+    uint8_t _ss_pin;     //slave select
  9
+    uint8_t _int_pin;    //interrupt
  10
+    uint8_t _reset_pin;  //reset      
  11
+
8 12
 /* Functions    */
9 13
 
10 14
 /* Constructor */
11  
-MAX3421E::MAX3421E()
  15
+MAX3421E::MAX3421E( uint8_t _ss, uint8_t _int, uint8_t _reset )
12 16
 {
  17
+    /* assign pins */
  18
+    _ss_pin = _ss;   
  19
+    _int_pin = _int;
  20
+    _reset_pin = _reset;
  21
+    
  22
+//    Serial.println( _ss_pin, DEC );
  23
+//    Serial.println( _int_pin, DEC );
  24
+//    Serial.println( _reset_pin, DEC );
  25
+    
  26
+    /* setup pins */
  27
+    pinMode( _int_pin, INPUT);
  28
+    pinMode( _ss_pin, OUTPUT );
  29
+    digitalWrite(_ss_pin,HIGH);   //deselect MAX3421E              
  30
+    pinMode( _reset_pin, OUTPUT );
  31
+    digitalWrite( _reset_pin, HIGH );  //release MAX3421E from reset
  32
+    
  33
+    
13 34
     //Serial.begin( 9600 );
14  
-    init();
  35
+    //init();
15 36
     //powerOn();
16 37
 }
17 38
 byte MAX3421E::getVbusState( void )
18 39
 { 
19 40
     return( vbusState );
20 41
 }
  42
+byte MAX3421E::getvar( void )
  43
+{
  44
+  return( _int_pin );
  45
+}    
21 46
 /* initialization */
22 47
 void MAX3421E::init()
23 48
 {
24 49
     /* setup pins */
25  
-    pinMode( MAX_INT, INPUT);
26  
-    // pinMode( MAX_GPX, INPUT );
27  
-    pinMode( MAX_SS, OUTPUT );
28  
-    //pinMode( BPNT_0, OUTPUT );
29  
-    //pinMode( BPNT_1, OUTPUT );
30  
-    //digitalWrite( BPNT_0, LOW );
31  
-    //digitalWrite( BPNT_1, LOW );
32  
-    Deselect_MAX3421E;              
33  
-    pinMode( MAX_RESET, OUTPUT );
34  
-    digitalWrite( MAX_RESET, HIGH );  //release MAX3421E from reset
  50
+//    pinMode( MAX_INT, INPUT);
  51
+//    pinMode( MAX_SS, OUTPUT );
  52
+//    Deselect_MAX3421E;              
  53
+//    pinMode( MAX_RESET, OUTPUT );
  54
+//    digitalWrite( MAX_RESET, HIGH );  //release MAX3421E from reset
35 55
 }
36 56
 
  57
+/* toggles breakpoint pin during debug */
37 58
 void MAX3421E::toggle( byte pin )
38 59
 {
39 60
     digitalWrite( pin, HIGH );
@@ -44,26 +65,26 @@ void MAX3421E::regWr( byte reg, byte val)
44 65
 {
45 66
   uint8_t SaveSREG = SREG;       //save interrupt flag
46 67
       cli();                        //disable interrupts
47  
-      Select_MAX3421E;
  68
+      digitalWrite(_ss_pin,LOW);
48 69
       Spi.transfer( reg + 2 ); //set WR bit and send register number
49 70
       Spi.transfer( val );
50  
-      Deselect_MAX3421E;
  71
+      digitalWrite(_ss_pin,HIGH);
51 72
       SREG = SaveSREG;              //restore interrupt flag 
52 73
 }
53 74
 /* multiple-byte write */
54 75
 /* returns a pointer to a memory position after last written */
55  
-char * MAX3421E::bytesWr( byte reg, byte nbytes, char * data )
  76
+char* MAX3421E::bytesWr( byte reg, byte nbytes, char * data )
56 77
 {
57  
- uint8_t SaveSREG = SREG;       //save interrupt flag
58  
-  cli();                        //disable interrupts   
59  
-    Select_MAX3421E;            //assert SS
  78
+ uint8_t SaveSREG = SREG;         //save interrupt flag
  79
+  cli();                          //disable interrupts   
  80
+    digitalWrite(_ss_pin,LOW);    //assert SS
60 81
     Spi.transfer ( reg + 2 );   //set W/R bit and select register   
61 82
     while( nbytes ) {                
62 83
         Spi.transfer( *data );  // send the next data byte
63 84
         data++;                 // advance the pointer
64 85
         nbytes--;
65 86
     }
66  
-    Deselect_MAX3421E;          //deassert SS
  87
+    digitalWrite(_ss_pin,HIGH);          //deassert SS
67 88
     SREG = SaveSREG;              //restore interrupt flag 
68 89
     return( data );
69 90
 }
@@ -84,10 +105,10 @@ byte MAX3421E::regRd( byte reg )
84 105
   byte tmp;
85 106
   uint8_t SaveSREG = SREG;       //save interrupt flag
86 107
     cli();                        //disable interrupts
87  
-    Select_MAX3421E;
  108
+    digitalWrite(_ss_pin,LOW);
88 109
     Spi.transfer ( reg );         //send register number
89 110
     tmp = Spi.transfer ( 0x00 );  //send empty byte, read register contents
90  
-    Deselect_MAX3421E;
  111
+    digitalWrite(_ss_pin,HIGH);
91 112
     SREG = SaveSREG;              //restore interrupt flag 
92 113
     return (tmp);
93 114
 }
@@ -97,14 +118,14 @@ char * MAX3421E::bytesRd ( byte reg, byte nbytes, char  * data )
97 118
 {
98 119
   uint8_t SaveSREG = SREG;       //save interrupt flag
99 120
     cli();                        //disable interrupts
100  
-    Select_MAX3421E;    //assert SS
  121
+    digitalWrite(_ss_pin,LOW);    //assert SS
101 122
     Spi.transfer ( reg );     //send register number
102 123
     while( nbytes ) {
103 124
         *data = Spi.transfer ( 0x00 );    //send empty byte, read register contents
104 125
         data++;
105 126
         nbytes--;
106 127
     }
107  
-    Deselect_MAX3421E;  //deassert SS
  128
+    digitalWrite(_ss_pin,HIGH);  //deassert SS
108 129
     SREG = SaveSREG;              //restore interrupt flag
109 130
     return( data );   
110 131
 }
@@ -212,7 +233,8 @@ void MAX3421E::powerOn()
212 233
     regWr(rHCTL,bmSAMPLEBUS);                                               // update the JSTATUS and KSTATUS bits
213 234
     busprobe();                                                             //check if anything is connected
214 235
     regWr( rHIRQ, bmCONDETIRQ );                                            //clear connection detect interrupt                 
215  
-    regWr( rCPUCTL, 0x01 );                                                 //enable interrupt pin
  236
+    //regWr( rHIRQ, 0xff );
  237
+    regWr( rCPUCTL, bmIE );                                                 //enable interrupt pin
216 238
 }
217 239
 /* MAX3421 state change task and interrupt handler */
218 240
 byte MAX3421E::Task( void )
@@ -220,7 +242,7 @@ byte MAX3421E::Task( void )
220 242
  byte rcode = 0;
221 243
  byte pinvalue;
222 244
 
223  
-    pinvalue = digitalRead( MAX_INT );    
  245
+    pinvalue = digitalRead( _int_pin );    
224 246
     if( pinvalue  == LOW ) {
225 247
         rcode = IntHandler();
226 248
     }
15  Max3421e.h
@@ -11,7 +11,8 @@
11 11
 class MAX3421E : public SPI {
12 12
     // byte vbusState;
13 13
     public:
14  
-        MAX3421E( void );
  14
+        MAX3421E( uint8_t _ss = MAX_SS, uint8_t _int = MAX_INT, uint8_t _reset = MAX_RESET );
  15
+        byte getvar( void );
15 16
         byte getVbusState( void );
16 17
         void toggle( byte pin );
17 18
         static void regWr( byte, byte );
@@ -27,9 +28,19 @@ class MAX3421E : public SPI {
27 28
         byte IntHandler();
28 29
         byte GpxHandler();
29 30
         byte Task();
  31
+        //void max_select();
30 32
     private:
31 33
         void init();
32  
-    friend class Max_LCD;        
  34
+        //void max_select();
  35
+    friend class Max_LCD;
  36
+    
  37
+    
33 38
 };
34 39
 
  40
+//    int8_t _ss_pin;     //slave select
  41
+//    uint8_t _int_pin;    //interrupt
  42
+//    uint8_t _reset_pin;  //reset      
  43
+
  44
+//inline void MAX3421E::max_select() { digitalWrite(_ss_pin,LOW); }
  45
+
35 46
 #endif //_MAX3421E_H_
19  Max3421e_constants.h
@@ -3,17 +3,24 @@
3 3
 #ifndef _MAX3421Econstants_h_
4 4
 #define _MAX3421Econstants_h_
5 5
 
6  
-/* Arduino pin definitions */
  6
+//#define BLACKWIDOW
  7
+
  8
+/* Arduino pin definitions for USB Host Shield signals. They can be changed here or while calling constructor */
7 9
 #define MAX_SS    10
8 10
 #define MAX_INT   9
9  
-#define MAX_GPX   3
  11
+//#define MAX_GPX   8
10 12
 #define MAX_RESET 7
11 13
 
12  
-#define BPNT_0      3
13  
-#define BPNT_1      2
  14
+#ifdef BLACKWIDOW
  15
+#define MAX_SS 6
  16
+#define MAX_INT 3
  17
+#endif
  18
+
  19
+//#define BPNT_0      3
  20
+//#define BPNT_1      2
14 21
      
15  
-#define Select_MAX3421E     digitalWrite(MAX_SS,LOW)
16  
-#define Deselect_MAX3421E   digitalWrite(MAX_SS,HIGH)
  22
+//#define Select_MAX3421E     digitalWrite(_ss_pin,LOW)
  23
+//#define Deselect_MAX3421E   digitalWrite(_ss_pin,HIGH)
17 24
 
18 25
 /* */
19 26
 
5  Usb.h
@@ -14,10 +14,11 @@
14 14
 #define bmREQ_HIDIN         USB_SETUP_DEVICE_TO_HOST|USB_SETUP_TYPE_CLASS|USB_SETUP_RECIPIENT_INTERFACE 
15 15
 #define bmREQ_HIDREPORT     USB_SETUP_DEVICE_TO_HOST|USB_SETUP_TYPE_STANDARD|USB_SETUP_RECIPIENT_INTERFACE
16 16
 
17  
-#define USB_XFER_TIMEOUT    5000    //USB transfer timeout in milliseconds
18  
-#define USB_NAK_LIMIT       32000     //NAK limit for a transfer. o meand NAKs are not counted
  17
+#define USB_XFER_TIMEOUT    5000    //USB transfer timeout in milliseconds, per section 9.2.6.1 of USB 2.0 spec
  18
+#define USB_NAK_LIMIT       32000   //NAK limit for a transfer. o meand NAKs are not counted
19 19
 #define USB_RETRY_LIMIT     3       //retry limit for a transfer
20 20
 #define USB_SETTLE_DELAY    200     //settle delay in milliseconds
  21
+#define USB_NAK_NOWAIT      1       //used in Richard's PS2/Wiimote code
21 22
 
22 23
 #define USB_NUMDEVICES  2           //number of USB devices
23 24
 
22  ch9.h
@@ -50,10 +50,6 @@
50 50
 #define USB_DESCRIPTOR_INTERFACE_POWER  0x08    // bDescriptorType for Interface Power.
51 51
 #define USB_DESCRIPTOR_OTG              0x09    // bDescriptorType for an OTG Descriptor.
52 52
 
53  
-/* Class Descriptors */
54  
-
55  
-
56  
-
57 53
 /* OTG SET FEATURE Constants    */
58 54
 #define OTG_FEATURE_B_HNP_ENABLE                3       // SET FEATURE OTG - Enable B device to perform HNP
59 55
 #define OTG_FEATURE_A_HNP_SUPPORT               4       // SET FEATURE OTG - A device supports HNP
@@ -154,13 +150,17 @@ typedef struct
154 150
 } USB_ENDPOINT_DESCRIPTOR;
155 151
 /* HID descriptor */
156 152
 typedef struct {
157  
-    byte bLength;			
158  
-	byte bDescriptorType;	
159  
-	unsigned int bcdHID;			
160  
-    byte bCountryCode;		
161  
-	byte bNumDescriptors;
162  
-	byte bDescrType;			
163  
-    unsigned int wDescriptorLength;
  153
+  uint8_t bLength;			
  154
+  uint8_t bDescriptorType;	
  155
+  uint16_t bcdHID;			
  156
+  uint8_t bCountryCode;		
  157
+  uint8_t bNumDescriptors;
  158
+  /* at least one descriptor follows, 3 bytes - descritor type, descriptor length */
164 159
 } USB_HID_DESCRIPTOR;
  160
+/* HID Class descriptor format in HID descriptor */
  161
+typedef struct {
  162
+  uint8_t bDescriptorType;
  163
+  uint16_t wDescriptorLength;
  164
+} HID_CLASS;
165 165
 
166 166
 #endif // _ch9_h_

0 notes on commit 13535b0

Please sign in to comment.
Something went wrong with that request. Please try again.