Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added USB_NAK_NOWAIT

  • Loading branch information...
commit 13535b080de8be3267d76f9516bc981b96e1f8a0 1 parent 063af40
@felis authored
Showing with 87 additions and 46 deletions.
  1. +47 −25 Max3421e.cpp
  2. +13 −2 Max3421e.h
  3. +13 −6 Max3421e_constants.h
  4. +3 −2 Usb.h
  5. +11 −11 ch9.h
View
72 Max3421e.cpp
@@ -5,35 +5,56 @@
static byte vbusState;
+ uint8_t _ss_pin; //slave select
+ uint8_t _int_pin; //interrupt
+ uint8_t _reset_pin; //reset
+
/* Functions */
/* Constructor */
-MAX3421E::MAX3421E()
+MAX3421E::MAX3421E( uint8_t _ss, uint8_t _int, uint8_t _reset )
{
+ /* assign pins */
+ _ss_pin = _ss;
+ _int_pin = _int;
+ _reset_pin = _reset;
+
+// Serial.println( _ss_pin, DEC );
+// Serial.println( _int_pin, DEC );
+// Serial.println( _reset_pin, DEC );
+
+ /* setup pins */
+ pinMode( _int_pin, INPUT);
+ pinMode( _ss_pin, OUTPUT );
+ digitalWrite(_ss_pin,HIGH); //deselect MAX3421E
+ pinMode( _reset_pin, OUTPUT );
+ digitalWrite( _reset_pin, HIGH ); //release MAX3421E from reset
+
+
//Serial.begin( 9600 );
- init();
+ //init();
//powerOn();
}
byte MAX3421E::getVbusState( void )
{
return( vbusState );
}
+byte MAX3421E::getvar( void )
+{
+ return( _int_pin );
+}
/* initialization */
void MAX3421E::init()
{
/* setup pins */
- pinMode( MAX_INT, INPUT);
- // pinMode( MAX_GPX, INPUT );
- pinMode( MAX_SS, OUTPUT );
- //pinMode( BPNT_0, OUTPUT );
- //pinMode( BPNT_1, OUTPUT );
- //digitalWrite( BPNT_0, LOW );
- //digitalWrite( BPNT_1, LOW );
- Deselect_MAX3421E;
- pinMode( MAX_RESET, OUTPUT );
- digitalWrite( MAX_RESET, HIGH ); //release MAX3421E from reset
+// pinMode( MAX_INT, INPUT);
+// pinMode( MAX_SS, OUTPUT );
+// Deselect_MAX3421E;
+// pinMode( MAX_RESET, OUTPUT );
+// digitalWrite( MAX_RESET, HIGH ); //release MAX3421E from reset
}
+/* toggles breakpoint pin during debug */
void MAX3421E::toggle( byte pin )
{
digitalWrite( pin, HIGH );
@@ -44,26 +65,26 @@ void MAX3421E::regWr( byte reg, byte val)
{
uint8_t SaveSREG = SREG; //save interrupt flag
cli(); //disable interrupts
- Select_MAX3421E;
+ digitalWrite(_ss_pin,LOW);
Spi.transfer( reg + 2 ); //set WR bit and send register number
Spi.transfer( val );
- Deselect_MAX3421E;
+ digitalWrite(_ss_pin,HIGH);
SREG = SaveSREG; //restore interrupt flag
}
/* multiple-byte write */
/* returns a pointer to a memory position after last written */
-char * MAX3421E::bytesWr( byte reg, byte nbytes, char * data )
+char* MAX3421E::bytesWr( byte reg, byte nbytes, char * data )
{
- uint8_t SaveSREG = SREG; //save interrupt flag
- cli(); //disable interrupts
- Select_MAX3421E; //assert SS
+ uint8_t SaveSREG = SREG; //save interrupt flag
+ cli(); //disable interrupts
+ digitalWrite(_ss_pin,LOW); //assert SS
Spi.transfer ( reg + 2 ); //set W/R bit and select register
while( nbytes ) {
Spi.transfer( *data ); // send the next data byte
data++; // advance the pointer
nbytes--;
}
- Deselect_MAX3421E; //deassert SS
+ digitalWrite(_ss_pin,HIGH); //deassert SS
SREG = SaveSREG; //restore interrupt flag
return( data );
}
@@ -84,10 +105,10 @@ byte MAX3421E::regRd( byte reg )
byte tmp;
uint8_t SaveSREG = SREG; //save interrupt flag
cli(); //disable interrupts
- Select_MAX3421E;
+ digitalWrite(_ss_pin,LOW);
Spi.transfer ( reg ); //send register number
tmp = Spi.transfer ( 0x00 ); //send empty byte, read register contents
- Deselect_MAX3421E;
+ digitalWrite(_ss_pin,HIGH);
SREG = SaveSREG; //restore interrupt flag
return (tmp);
}
@@ -97,14 +118,14 @@ char * MAX3421E::bytesRd ( byte reg, byte nbytes, char * data )
{
uint8_t SaveSREG = SREG; //save interrupt flag
cli(); //disable interrupts
- Select_MAX3421E; //assert SS
+ digitalWrite(_ss_pin,LOW); //assert SS
Spi.transfer ( reg ); //send register number
while( nbytes ) {
*data = Spi.transfer ( 0x00 ); //send empty byte, read register contents
data++;
nbytes--;
}
- Deselect_MAX3421E; //deassert SS
+ digitalWrite(_ss_pin,HIGH); //deassert SS
SREG = SaveSREG; //restore interrupt flag
return( data );
}
@@ -212,7 +233,8 @@ void MAX3421E::powerOn()
regWr(rHCTL,bmSAMPLEBUS); // update the JSTATUS and KSTATUS bits
busprobe(); //check if anything is connected
regWr( rHIRQ, bmCONDETIRQ ); //clear connection detect interrupt
- regWr( rCPUCTL, 0x01 ); //enable interrupt pin
+ //regWr( rHIRQ, 0xff );
+ regWr( rCPUCTL, bmIE ); //enable interrupt pin
}
/* MAX3421 state change task and interrupt handler */
byte MAX3421E::Task( void )
@@ -220,7 +242,7 @@ byte MAX3421E::Task( void )
byte rcode = 0;
byte pinvalue;
- pinvalue = digitalRead( MAX_INT );
+ pinvalue = digitalRead( _int_pin );
if( pinvalue == LOW ) {
rcode = IntHandler();
}
View
15 Max3421e.h
@@ -11,7 +11,8 @@
class MAX3421E : public SPI {
// byte vbusState;
public:
- MAX3421E( void );
+ MAX3421E( uint8_t _ss = MAX_SS, uint8_t _int = MAX_INT, uint8_t _reset = MAX_RESET );
+ byte getvar( void );
byte getVbusState( void );
void toggle( byte pin );
static void regWr( byte, byte );
@@ -27,9 +28,19 @@ class MAX3421E : public SPI {
byte IntHandler();
byte GpxHandler();
byte Task();
+ //void max_select();
private:
void init();
- friend class Max_LCD;
+ //void max_select();
+ friend class Max_LCD;
+
+
};
+// int8_t _ss_pin; //slave select
+// uint8_t _int_pin; //interrupt
+// uint8_t _reset_pin; //reset
+
+//inline void MAX3421E::max_select() { digitalWrite(_ss_pin,LOW); }
+
#endif //_MAX3421E_H_
View
19 Max3421e_constants.h
@@ -3,17 +3,24 @@
#ifndef _MAX3421Econstants_h_
#define _MAX3421Econstants_h_
-/* Arduino pin definitions */
+//#define BLACKWIDOW
+
+/* Arduino pin definitions for USB Host Shield signals. They can be changed here or while calling constructor */
#define MAX_SS 10
#define MAX_INT 9
-#define MAX_GPX 3
+//#define MAX_GPX 8
#define MAX_RESET 7
-#define BPNT_0 3
-#define BPNT_1 2
+#ifdef BLACKWIDOW
+#define MAX_SS 6
+#define MAX_INT 3
+#endif
+
+//#define BPNT_0 3
+//#define BPNT_1 2
-#define Select_MAX3421E digitalWrite(MAX_SS,LOW)
-#define Deselect_MAX3421E digitalWrite(MAX_SS,HIGH)
+//#define Select_MAX3421E digitalWrite(_ss_pin,LOW)
+//#define Deselect_MAX3421E digitalWrite(_ss_pin,HIGH)
/* */
View
5 Usb.h
@@ -14,10 +14,11 @@
#define bmREQ_HIDIN USB_SETUP_DEVICE_TO_HOST|USB_SETUP_TYPE_CLASS|USB_SETUP_RECIPIENT_INTERFACE
#define bmREQ_HIDREPORT USB_SETUP_DEVICE_TO_HOST|USB_SETUP_TYPE_STANDARD|USB_SETUP_RECIPIENT_INTERFACE
-#define USB_XFER_TIMEOUT 5000 //USB transfer timeout in milliseconds
-#define USB_NAK_LIMIT 32000 //NAK limit for a transfer. o meand NAKs are not counted
+#define USB_XFER_TIMEOUT 5000 //USB transfer timeout in milliseconds, per section 9.2.6.1 of USB 2.0 spec
+#define USB_NAK_LIMIT 32000 //NAK limit for a transfer. o meand NAKs are not counted
#define USB_RETRY_LIMIT 3 //retry limit for a transfer
#define USB_SETTLE_DELAY 200 //settle delay in milliseconds
+#define USB_NAK_NOWAIT 1 //used in Richard's PS2/Wiimote code
#define USB_NUMDEVICES 2 //number of USB devices
View
22 ch9.h
@@ -50,10 +50,6 @@
#define USB_DESCRIPTOR_INTERFACE_POWER 0x08 // bDescriptorType for Interface Power.
#define USB_DESCRIPTOR_OTG 0x09 // bDescriptorType for an OTG Descriptor.
-/* Class Descriptors */
-
-
-
/* OTG SET FEATURE Constants */
#define OTG_FEATURE_B_HNP_ENABLE 3 // SET FEATURE OTG - Enable B device to perform HNP
#define OTG_FEATURE_A_HNP_SUPPORT 4 // SET FEATURE OTG - A device supports HNP
@@ -154,13 +150,17 @@ typedef struct
} USB_ENDPOINT_DESCRIPTOR;
/* HID descriptor */
typedef struct {
- byte bLength;
- byte bDescriptorType;
- unsigned int bcdHID;
- byte bCountryCode;
- byte bNumDescriptors;
- byte bDescrType;
- unsigned int wDescriptorLength;
+ uint8_t bLength;
+ uint8_t bDescriptorType;
+ uint16_t bcdHID;
+ uint8_t bCountryCode;
+ uint8_t bNumDescriptors;
+ /* at least one descriptor follows, 3 bytes - descritor type, descriptor length */
} USB_HID_DESCRIPTOR;
+/* HID Class descriptor format in HID descriptor */
+typedef struct {
+ uint8_t bDescriptorType;
+ uint16_t wDescriptorLength;
+} HID_CLASS;
#endif // _ch9_h_
Please sign in to comment.
Something went wrong with that request. Please try again.