remove examples
Change-Id: Ifebc01667dc1a5cc6dd8105b825722220f2d247e
diff --git a/USB_Host_Shield/examples/LCDkbd.pde b/USB_Host_Shield/examples/LCDkbd.pde
deleted file mode 100644
index 0f4dba1..0000000
--- a/USB_Host_Shield/examples/LCDkbd.pde
+++ /dev/null
@@ -1,335 +0,0 @@
-/* MAX3421E USB Host controller LCD/keyboard demonstration */
-#include <Spi.h>
-#include <Max3421e.h>
-#include <Usb.h>
-#include <Max_LCD.h>
-
-/* keyboard data taken from configuration descriptor */
-#define KBD_ADDR 1
-#define KBD_EP 1
-#define KBD_IF 0
-#define EP_MAXPKTSIZE 8
-#define EP_POLL 0x0a
-/**/
-//******************************************************************************
-// macros to identify special charaters(other than Digits and Alphabets)
-//******************************************************************************
-#define BANG (0x1E)
-#define AT (0x1F)
-#define POUND (0x20)
-#define DOLLAR (0x21)
-#define PERCENT (0x22)
-#define CAP (0x23)
-#define AND (0x24)
-#define STAR (0x25)
-#define OPENBKT (0x26)
-#define CLOSEBKT (0x27)
-
-#define RETURN (0x28)
-#define ESCAPE (0x29)
-#define BACKSPACE (0x2A)
-#define TAB (0x2B)
-#define SPACE (0x2C)
-#define HYPHEN (0x2D)
-#define EQUAL (0x2E)
-#define SQBKTOPEN (0x2F)
-#define SQBKTCLOSE (0x30)
-#define BACKSLASH (0x31)
-#define SEMICOLON (0x33)
-#define INVCOMMA (0x34)
-#define TILDE (0x35)
-#define COMMA (0x36)
-#define PERIOD (0x37)
-#define FRONTSLASH (0x38)
-#define DELETE (0x4c)
-/**/
-/* Modifier masks. One for both modifiers */
-#define SHIFT 0x22
-#define CTRL 0x11
-#define ALT 0x44
-#define GUI 0x88
-/**/
-/* "Sticky keys */
-#define CAPSLOCK (0x39)
-#define NUMLOCK (0x53)
-#define SCROLLLOCK (0x47)
-/* Sticky keys output report bitmasks */
-#define bmNUMLOCK 0x01
-#define bmCAPSLOCK 0x02
-#define bmSCROLLLOCK 0x04
-/**/
-EP_RECORD ep_record[ 2 ]; //endpoint record structure for the keyboard
-
-char buf[ 8 ] = { 0 }; //keyboard buffer
-char old_buf[ 8 ] = { 0 }; //last poll
-/* Sticky key state */
-bool numLock = false;
-bool capsLock = false;
-bool scrollLock = false;
-bool line = false;
-
-void setup();
-void loop();
-
-MAX3421E Max;
-USB Usb;
-Max_LCD LCD;
-
-void setup() {
- // set up the LCD's number of rows and columns:
- LCD.begin(16, 2);
- LCD.home();
- Serial.begin( 9600 );
- Serial.println("Start");
- Max.powerOn();
- delay( 200 );
-}
-
-void loop() {
- Max.Task();
- Usb.Task();
- if( Usb.getUsbTaskState() == USB_STATE_CONFIGURING ) { //wait for addressing state
- kbd_init();
- Usb.setUsbTaskState( USB_STATE_RUNNING );
- }
- if( Usb.getUsbTaskState() == USB_STATE_RUNNING ) { //poll the keyboard
- kbd_poll();
- }
-}
-/* Initialize keyboard */
-void kbd_init( void )
-{
- byte rcode = 0; //return code
-/**/
- /* Initialize data structures */
- ep_record[ 0 ] = *( Usb.getDevTableEntry( 0,0 )); //copy endpoint 0 parameters
- ep_record[ 1 ].MaxPktSize = EP_MAXPKTSIZE;
- ep_record[ 1 ].Interval = EP_POLL;
- ep_record[ 1 ].sndToggle = bmSNDTOG0;
- ep_record[ 1 ].rcvToggle = bmRCVTOG0;
- Usb.setDevTableEntry( 1, ep_record ); //plug kbd.endpoint parameters to devtable
- /* Configure device */
- rcode = Usb.setConf( KBD_ADDR, 0, 1 );
- if( rcode ) {
- Serial.print("Error attempting to configure keyboard. Return code :");
- Serial.println( rcode, HEX );
- while(1); //stop
- }
- /* Set boot protocol */
- rcode = Usb.setProto( KBD_ADDR, 0, 0, 0 );
- if( rcode ) {
- Serial.print("Error attempting to configure boot protocol. Return code :");
- Serial.println( rcode, HEX );
- while( 1 ); //stop
- }
- LCD.print("Keyboard initialized");
- delay(2000);
- LCD.clear();
- LCD.home();
- Serial.println("Keyboard initialized");
-}
-
-/* Poll keyboard and print result */
-/* buffer starts at position 2, 0 is modifier key state and 1 is irrelevant */
-void kbd_poll( void )
-{
- char i;
- static char leds = 0;
- byte rcode = 0; //return code
- /* poll keyboard */
- rcode = Usb.inTransfer( KBD_ADDR, KBD_EP, 8, buf );
- if( rcode != 0 ) {
- return;
- }//if ( rcode..
- for( i = 2; i < 8; i++ ) {
- if( buf[ i ] == 0 ) { //end of non-empty space
- break;
- }
- if( buf_compare( buf[ i ] ) == false ) { //if new key
- switch( buf[ i ] ) {
- case CAPSLOCK:
- capsLock =! capsLock;
- leds = ( capsLock ) ? leds |= bmCAPSLOCK : leds &= ~bmCAPSLOCK; // set or clear bit 1 of LED report byte
- break;
- case NUMLOCK:
- numLock =! numLock;
- leds = ( numLock ) ? leds |= bmNUMLOCK : leds &= ~bmNUMLOCK; // set or clear bit 0 of LED report byte
- break;
- case SCROLLLOCK:
- scrollLock =! scrollLock;
- leds = ( scrollLock ) ? leds |= bmSCROLLLOCK : leds &= ~bmSCROLLLOCK; // set or clear bit 2 of LED report byte
- break;
- case DELETE:
- LCD.clear();
- LCD.home();
- line = false;
- break;
- case RETURN:
- line =! line;
- LCD.setCursor( 0, line );
- break;
- default:
- //LCD.print("A"); //output
- LCD.print( HIDtoA( buf[ i ], buf[ 0 ] ));
- Serial.print(HIDtoA( buf[ i ], buf[ 0 ] ));
- break;
- }//switch( buf[ i ...
- rcode = Usb.setReport( KBD_ADDR, 0, 1, KBD_IF, 0x02, 0, &leds );
- if( rcode ) {
- Serial.print("Set report error: ");
- Serial.println( rcode, HEX );
- }//if( rcode ...
- }//if( buf_compare( buf[ i ] ) == false ...
- }//for( i = 2...
- for( i = 2; i < 8; i++ ) { //copy new buffer to old
- old_buf[ i ] = buf[ i ];
- }
-}
-/* compare byte against bytes in old buffer */
-bool buf_compare( byte data )
-{
- char i;
- for( i = 2; i < 8; i++ ) {
- if( old_buf[ i ] == data ) {
- return( true );
- }
- }
- return( false );
-}
-
-/* HID to ASCII converter. Takes HID keyboard scancode, returns ASCII code */
-byte HIDtoA( byte HIDbyte, byte mod )
-{
- /* upper row of the keyboard, numbers and special symbols */
- if( HIDbyte >= 0x1e && HIDbyte <= 0x27 ) {
- if(( mod & SHIFT ) || numLock ) { //shift key pressed
- switch( HIDbyte ) {
- case BANG: return( 0x21 );
- case AT: return( 0x40 );
- case POUND: return( 0x23 );
- case DOLLAR: return( 0x24 );
- case PERCENT: return( 0x25 );
- case CAP: return( 0x5e );
- case AND: return( 0x26 );
- case STAR: return( 0x2a );
- case OPENBKT: return( 0x28 );
- case CLOSEBKT: return( 0x29 );
- }//switch( HIDbyte...
- }
- else { //numbers
- if( HIDbyte == 0x27 ) { //zero
- return( 0x30 );
- }
- else {
- return( HIDbyte + 0x13 );
- }
- }//numbers
- }//if( HIDbyte >= 0x1e && HIDbyte <= 0x27
- /**/
- /* number pad. Arrows are not supported */
- if(( HIDbyte >= 0x59 && HIDbyte <= 0x61 ) && ( numLock == true )) { // numbers 1-9
- return( HIDbyte - 0x28 );
- }
- if(( HIDbyte == 0x62 ) && ( numLock == true )) { //zero
- return( 0x30 );
- }
- /* Letters a-z */
- if( HIDbyte >= 0x04 && HIDbyte <= 0x1d ) {
- if((( capsLock == true ) && ( mod & SHIFT ) == 0 ) || (( capsLock == false ) && ( mod & SHIFT ))) { //upper case
- return( HIDbyte + 0x3d );
- }
- else { //lower case
- return( HIDbyte + 0x5d );
- }
- }//if( HIDbyte >= 0x04 && HIDbyte <= 0x1d...
- /* Other special symbols */
- if( HIDbyte >= 0x2c && HIDbyte <= 0x38 ) {
- switch( HIDbyte ) {
- case SPACE: return( 0x20 );
- case HYPHEN:
- if(( mod & SHIFT ) == false ) {
- return( 0x2d );
- }
- else {
- return( 0x5f );
- }
- case EQUAL:
- if(( mod & SHIFT ) == false ) {
- return( 0x3d );
- }
- else {
- return( 0x2b );
- }
- case SQBKTOPEN:
- if(( mod & SHIFT ) == false ) {
- return( 0x5b );
- }
- else {
- return( 0x7b );
- }
- case SQBKTCLOSE:
- if(( mod & SHIFT ) == false ) {
- return( 0x5d );
- }
- else {
- return( 0x7d );
- }
- case BACKSLASH:
- if(( mod & SHIFT ) == false ) {
- return( 0x5c );
- }
- else {
- return( 0x7c );
- }
- case SEMICOLON:
- if(( mod & SHIFT ) == false ) {
- return( 0x3b );
- }
- else {
- return( 0x3a );
- }
- case INVCOMMA:
- if(( mod & SHIFT ) == false ) {
- return( 0x27 );
- }
- else {
- return( 0x22 );
- }
- case TILDE:
- if(( mod & SHIFT ) == false ) {
- return( 0x60 );
- }
- else {
- return( 0x7e );
- }
- case COMMA:
- if(( mod & SHIFT ) == false ) {
- return( 0x2c );
- }
- else {
- return( 0x3c );
- }
- case PERIOD:
- if(( mod & SHIFT ) == false ) {
- return( 0x2e );
- }
- else {
- return( 0x3e );
- }
- case FRONTSLASH:
- if(( mod & SHIFT ) == false ) {
- return( 0x2f );
- }
- else {
- return( 0x3f );
- }
- default:
- break;
- }//switch( HIDbyte..
- }//if( HIDbye >= 0x2d && HIDbyte <= 0x38..
- return( 0 );
-}
-
-
-
-
diff --git a/USB_Host_Shield/examples/PS3LCD.pde b/USB_Host_Shield/examples/PS3LCD.pde
deleted file mode 100644
index ae103e0..0000000
--- a/USB_Host_Shield/examples/PS3LCD.pde
+++ /dev/null
@@ -1,566 +0,0 @@
-
-
-/* MAX3421E USB Host controller LCD/PS3 demonstration */
-#include <Spi.h>
-#include <Max3421e.h>
-#include <Usb.h>
-#include <Max_LCD.h>
-#include <MemoryFree.h>
-#include <avr/pgmspace.h>
-
-/*The application will work in reduced host mode, so we can save program and data
-memory space. After verifying the PID and VID we will use known values for the
-configuration values for device, interface, endpoints and HID */
-
-/* PS3 data taken from descriptors */
-#define PS3_ADDR 1
-#define PS3_VID_LO 0x4c // Sony VID
-#define PS3_VID_HI 0x05
-#define PS3_PID_LO 0x68 // Batch Device
-#define PS3_PID_HI 0x02
-#define PS3_CONFIGURATION 1
-#define PS3_IF 0
-#define PS3_NUM_EP 3
-#define EP_MAXPKTSIZE 64
-#define EP_INTERRUPT 0x03
-#define EP_POLL 0x01
-#define CONTROL_EP 0
-#define OUTPUT_EP 1
-#define REPORT_EP 2
-
-
-#define PS3_F4_REPORT_LEN 4
-#define PS3_F5_REPORT_LEN 8
-#define PS3_01_REPORT_LEN 48
-#define HID_REPORT_FEATURE 3
-#define HID_REPORT_OUTPUT 2
-#define PS3_F4_REPORT_ID 0xF4
-#define PS3_01_REPORT_ID 0x01
-#define PS3_F5_REPORT_ID 0xF5
-
-/* Defines for the PS3 Data in the HID Report
-*/
-#define LAnalogX buf[6]
-#define LAnalogY buf[7]
-#define RAnalogX buf[8]
-#define RAnalogY buf[9]
-#define buttons1 buf[2]
-#define buttons2 buf[3]
-#define buttons3 buf[4]
-#define buttonchange ((buttons1 != oldbuttons1) | (buttons2 != oldbuttons2))
-#define buSelect (buttons1 & 0x01)
-#define buLAnalog (buttons1 & 0x02)
-#define buRAnalog (buttons1 & 0x04)
-#define buStart (buttons1 & 0x08)
-#define buUp (buttons1 & 0x10)
-#define buRight (buttons1 & 0x20)
-#define buDown (buttons1 & 0x40)
-#define buLeft (buttons1 & 0x80)
-#define buL2 (buttons2 & 0x01)
-#define buR2 (buttons2 & 0x02)
-#define buL1 (buttons2 & 0x04)
-#define buR1 (buttons2 & 0x08)
-#define buTriangle (buttons2 & 0x10)
-#define buCircle (buttons2 & 0x20)
-#define buCross (buttons2 & 0x40)
-#define buSquare (buttons2 & 0x80)
-#define buPS (buttons3 & 0x01)
-#define AnalogUp buf[14]
-#define AnalogRight buf[15]
-#define AnalogDown buf[16]
-#define AnalogLeft buf[17]
-#define AnalogL2 buf[18]
-#define AnalogR2 buf[19]
-#define AnalogL1 buf[20]
-#define AnalogR1 buf[21]
-#define AnalogTriangle buf[22]
-#define AnalogCircle buf[23]
-#define AnalogCross buf[24]
-#define AnalogSquare buf[25]
-#define AccelX (((unsigned char)buf[42] | (unsigned char)buf[41] << 8)-512)
-#define AccelY (((unsigned char)buf[44] | (unsigned char)buf[43] << 8)-512)
-#define AccelZ (((unsigned char)buf[46] | (unsigned char)buf[45] << 8)-512)
-#define GyroX (((unsigned char)buf[48] | (unsigned char)buf[47] << 8)-512)
-
-
-
-/*Menu screens
-
-*/
-#define Root 0
-#define Basic 1
-#define Buttons 2
-#define Joystick 3
-#define Pressure 4
-#define Accelerometer 5
-#define LED 6
-#define Bdaddr 7
-#define Freememory 8
-
-
-/* Menu Text
-*/
-
-prog_char menutext_0[] PROGMEM = "Select Test";
-prog_char menutext_1[] PROGMEM = "Basic Tests";
-prog_char menutext_2[] PROGMEM = "Buttons Test";
-prog_char menutext_3[] PROGMEM = "Joystick Test";
-prog_char menutext_4[] PROGMEM = "Pressure Test";
-prog_char menutext_5[] PROGMEM = "Motion Test";
-prog_char menutext_6[] PROGMEM = "LED/Rumble Test";
-prog_char menutext_7[] PROGMEM = "Bluetooth Addr";
-prog_char menutext_8[] PROGMEM = "Free Memory";
-
-
-PROGMEM const char *menu_table[] =
-{
- menutext_0,
- menutext_1,
- menutext_2,
- menutext_3,
- menutext_4,
- menutext_5,
- menutext_6,
- menutext_7,
- menutext_8 };
-
-prog_char output_01_report[] PROGMEM = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x02, 0xff, 0x27, 0x10, 0x00, 0x32, 0xff,
- 0x27, 0x10, 0x00, 0x32, 0xff, 0x27, 0x10, 0x00,
- 0x32, 0xff, 0x27, 0x10, 0x00, 0x32, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
-};
-
-prog_char feature_F4_report[] PROGMEM = {0x42, 0x0c, 0x00, 0x00};
-
-EP_RECORD ep_record[ PS3_NUM_EP ]; //endpoint record structure for the PS3 controller
-
-char buf[ 64 ] = { 0 }; //General purpose buffer for usb data
-char oldbuttons1, oldbuttons2;
-char screen, selscreen;
-char lcdbuffer[17];
-unsigned char bdaddr[6];
-char bdcursor;
-char ledrum;
-char lrcursor;
-
-
-void setup();
-void loop();
-
-MAX3421E Max;
-USB Usb;
-Max_LCD LCD;
-
-void setup() {
- // set up the LCD's number of rows and columns:
- LCD.begin(16, 2);
- LCD.home();
- LCD.print("PS3 Controller");
- LCD.setCursor(0,1);
- LCD.print("Wait for connect");
- Serial.begin( 9600 );
- Serial.println("PS3 Controller Start");
- Serial.print("freeMemory() reports ");
- Serial.println( freeMemory() );
- Max.powerOn();
- delay(200);
-}
-
-void loop() {
-
-
- Max.Task();
- Usb.Task();
- if( Usb.getUsbTaskState() == USB_STATE_CONFIGURING ) { //wait for addressing state
- PS3_init();
- process_report();
- Usb.setUsbTaskState( USB_STATE_RUNNING );
- }
- if( Usb.getUsbTaskState() == USB_STATE_RUNNING ) { //poll the PS3 Controller
- PS3_poll();
- }
-}
-/* Initialize PS3 Controller */
-void PS3_init( void )
-{
- byte rcode = 0; //return code
- byte i;
-/**/
-
- /* Initialize data structures for endpoints of device 1*/
- ep_record[ CONTROL_EP ] = *( Usb.getDevTableEntry( 0,0 )); //copy endpoint 0 parameters
- ep_record[ OUTPUT_EP ].epAddr = 0x02; // PS3 output endpoint
- ep_record[ OUTPUT_EP ].Attr = EP_INTERRUPT;
- ep_record[ OUTPUT_EP ].MaxPktSize = EP_MAXPKTSIZE;
- ep_record[ OUTPUT_EP ].Interval = EP_POLL;
- ep_record[ OUTPUT_EP ].sndToggle = bmSNDTOG0;
- ep_record[ OUTPUT_EP ].rcvToggle = bmRCVTOG0;
- ep_record[ REPORT_EP ].epAddr = 0x01; // PS3 report endpoint
- ep_record[ REPORT_EP ].Attr = EP_INTERRUPT;
- ep_record[ REPORT_EP ].MaxPktSize = EP_MAXPKTSIZE;
- ep_record[ REPORT_EP ].Interval = EP_POLL;
- ep_record[ REPORT_EP ].sndToggle = bmSNDTOG0;
- ep_record[ REPORT_EP ].rcvToggle = bmRCVTOG0;
-
- Usb.setDevTableEntry( PS3_ADDR, ep_record ); //plug kbd.endpoint parameters to devtable
-
- /* read the device descriptor and check VID and PID*/
- rcode = Usb.getDevDescr( PS3_ADDR, ep_record[ CONTROL_EP ].epAddr, DEV_DESCR_LEN , buf );
- if( rcode ) {
- Serial.print("Error attempting read device descriptor. Return code :");
- Serial.println( rcode, HEX );
- while(1); //stop
- }
- if((buf[ 8 ] != PS3_VID_LO) || (buf[ 9 ] != PS3_VID_HI) || (buf[ 10 ] != PS3_PID_LO) || (buf[ 11 ] != PS3_PID_HI) ) {
- Serial.print("Unsupported USB Device");
- while(1); //stop
- }
-
- /* Configure device */
- rcode = Usb.setConf( PS3_ADDR, ep_record[ CONTROL_EP ].epAddr, PS3_CONFIGURATION );
- if( rcode ) {
- Serial.print("Error attempting to configure PS3 controller. Return code :");
- Serial.println( rcode, HEX );
- while(1); //stop
- }
-
-
- /* Set the PS3 controller to send reports */
- for (i=0; i < PS3_F4_REPORT_LEN; i++) buf[i] = pgm_read_byte_near( feature_F4_report + i);
- rcode = Usb.setReport( PS3_ADDR, ep_record[ CONTROL_EP ].epAddr, PS3_F4_REPORT_LEN, PS3_IF, HID_REPORT_FEATURE, PS3_F4_REPORT_ID , buf );
- if( rcode ) {
- Serial.print("Set report error: ");
- Serial.println( rcode, HEX );
- while(1); //stop
-
- }
-
- /* Set the PS3 controller LED 1 On */
- for (i=0; i < PS3_01_REPORT_LEN; i++) buf[i] = pgm_read_byte_near( output_01_report + i);
- rcode = Usb.setReport( PS3_ADDR, ep_record[ CONTROL_EP ].epAddr, PS3_01_REPORT_LEN, PS3_IF, HID_REPORT_OUTPUT, PS3_01_REPORT_ID , buf );
- if( rcode ) {
- Serial.print("Set report error: ");
- Serial.println( rcode, HEX );
- while(1); //stop
-
- }
-
- LCD.print("PS3 initialized");
- Serial.println("PS3 initialized");
- delay(200);
- screen = Root;
- selscreen = Basic;
- LCD.clear();
- LCD.home();
- LCD.print("Main Menu");
- LCD.setCursor(0,1);
- strcpy_P(lcdbuffer, (char*)pgm_read_word(&(menu_table[selscreen])));
- LCD.print(lcdbuffer);
-
-
-}
-
-/* Poll PS3 and print result */
-
-void PS3_poll( void )
-{
-
- byte rcode = 0; //return code
- /* poll PS3 */
- rcode = Usb.inTransfer(PS3_ADDR, ep_record[ REPORT_EP ].epAddr, PS3_01_REPORT_LEN, buf );
- if( rcode != 0 ) {
- return;
- }
- process_report();
- return;
-}
-
-void process_report(void)
-{
- byte i, j, mask;
- if(buPS){
- screen = Root;
- selscreen = Basic;
- LCD.clear();
- LCD.home();
- LCD.print("Main Menu");
- LCD.setCursor(0,1);
- strcpy_P(lcdbuffer, (char*)pgm_read_word(&(menu_table[selscreen])));
- LCD.print(lcdbuffer);
- oldbuttons1 = buttons1;
- oldbuttons2 = buttons2;
-
- }
-
- switch (screen){
-
- case Root:
- if(buttonchange){
- if(buDown) selscreen--;
- else if(buUp | buSelect) selscreen++;
- else if(buStart) {
- screen = selscreen;
- LCD.clear();
- oldbuttons1 = buttons1;
- oldbuttons2 = buttons2;
- break;
- }
- else {
- oldbuttons1 = buttons1;
- oldbuttons2 = buttons2;
- break;
-
- }
- if (selscreen == 0) selscreen = 1;
- if (selscreen > 8) selscreen = 1;
- LCD.clear();
- LCD.home();
- LCD.print("Main Menu:");
- LCD.setCursor(0,1);
- strcpy_P(lcdbuffer, (char*)pgm_read_word(&(menu_table[selscreen])));
- LCD.print(lcdbuffer);
- oldbuttons1 = buttons1;
- oldbuttons2 = buttons2;
- }
- break;
-
- case Basic:
- if(buttonchange){
- LCD.home();
- if (buL1) LCD.print('X');
- else LCD.print(' ');
- LCD.print(" Test L/R");
- LCD.setCursor(0,1);
- if (buL2) LCD.print('X');
- else LCD.print(' ');
- LCD.print(" Buttons");
- LCD.setCursor(15,0);
- if (buR1) LCD.print('X');
- else LCD.print(' ');
-
- LCD.setCursor(15,1);
- if (buR2) LCD.print('X');
- else LCD.print(' ');
- }
-
- break;
-
- case Buttons:
- if(buttonchange){
- LCD.home();
- LCD.print("0123456789ABCDEF");
- LCD.setCursor(0,1);
- mask = 1;
- for( i = 0; i < 8; i++){
- if (buttons1 & mask) lcdbuffer[i] = '^';
- else lcdbuffer[i] = ' ';
- mask <<= 1;
- }
- mask = 1;
- for( i = 0; i < 8; i++){
- if (buttons2 & mask) lcdbuffer[i+8] = '^';
- else lcdbuffer[i+8] = ' ';
- mask <<= 1;
- }
- LCD.print(lcdbuffer);
- oldbuttons1 = buttons1;
- oldbuttons2 = buttons2;
-
- }
-
- break;
-
- case Joystick:
- LCD.home();
- LCD.print('^');
- LCD.print((unsigned char)LAnalogY, DEC);
- LCD.print(" ");
- LCD.setCursor(8,0);
- LCD.print('^');
- LCD.print((unsigned char)RAnalogY, DEC);
- LCD.print(" ");
- LCD.setCursor(0,1);
- LCD.print('>');
- LCD.print((unsigned char)LAnalogX, DEC);
- LCD.print(" ");
- LCD.setCursor(8,1);
- LCD.print('>');
- LCD.print((unsigned char)RAnalogX, DEC);
- LCD.print(" ");
- break;
-
- case Pressure:
- LCD.home();
- LCD.print((unsigned char)AnalogUp, DEC);
- LCD.print(" ");
- LCD.print((unsigned char)AnalogDown, DEC);
- LCD.print(" ");
- LCD.print((unsigned char)AnalogLeft, DEC);
- LCD.print(" ");
- LCD.print((unsigned char)AnalogRight, DEC);
- LCD.print(" ");
- LCD.print((unsigned char)AnalogL1, DEC);
- LCD.print(" ");
- LCD.print((unsigned char)AnalogR1, DEC);
- LCD.print(" ");
-
- LCD.setCursor(0,1);
- LCD.print((unsigned char)AnalogCircle, DEC);
- LCD.print(" ");
- LCD.print((unsigned char)AnalogTriangle, DEC);
- LCD.print(" ");
- LCD.print((unsigned char)AnalogSquare, DEC);
- LCD.print(" ");
- LCD.print((unsigned char)AnalogCross, DEC);
- LCD.print(" ");
- LCD.print((unsigned char)AnalogL2, DEC);
- LCD.print(" ");
- LCD.print((unsigned char)AnalogR2, DEC);
- LCD.print(" ");
-
- break;
-
- case Accelerometer:
- LCD.home();
- LCD.print('X');
- LCD.print(AccelX, DEC);
- LCD.print(" ");
- LCD.setCursor(8,0);
- LCD.print('Y');
- LCD.print(AccelY, DEC);
- LCD.print(" ");
- LCD.setCursor(0,1);
- LCD.print('Z');
- LCD.print(AccelZ, DEC);
- LCD.print(" ");
- LCD.setCursor(8,1);
- LCD.print('G');
- LCD.print(GyroX, DEC);
- LCD.print(" ");
- break;
-
- case LED:
- if(buttonchange){
- oldbuttons1 = buttons1;
- oldbuttons2 = buttons2;
- if (buRight) lrcursor++;
- else if (buLeft) lrcursor--;
- else if (buUp) ledrum |= 1 << lrcursor;
- else if (buDown) ledrum &= ~(1 << lrcursor);
- if (lrcursor > 7) lrcursor = 0;
- if (lrcursor < 0) lrcursor = 7;
- }
- LCD.home();
- LCD.print("1 2 3 4 S W ");
- LCD.setCursor(0,1);
- j = 0;
- for (i=0; i < 6; i++){
- if(ledrum & 1 << i) lcdbuffer[j] = 'X';
- else lcdbuffer[j] = ' ';
- j++; ;
- lcdbuffer[j] = ' ';
- j++;
- }
- lcdbuffer[j] = 0;
- LCD.print(lcdbuffer);
- LCD.setCursor((lrcursor * 2),1);
- LCD.cursor();
- /* default buffer values */
- for (i=0; i < PS3_01_REPORT_LEN; i++) buf[i] = pgm_read_byte_near( output_01_report + i);
- /* LED setings */
- buf[9] = (ledrum & 0x0f) << 1;
- /* rumble settings */
- if (ledrum & 0x30){
- buf[1] = buf[3] = 0xfe;
- if (ledrum & 0x10) buf[4] = 0xff;
- else buf[2] = 0xff;
- }
-
- Usb.setReport( PS3_ADDR, ep_record[ CONTROL_EP ].epAddr, PS3_01_REPORT_LEN, PS3_IF, HID_REPORT_OUTPUT, PS3_01_REPORT_ID , buf );
-
- delay(100);
- LCD.noCursor();
- break;
-
- case Bdaddr:
- if(buttonchange){
- oldbuttons1 = buttons1;
- oldbuttons2 = buttons2;
-
- if (buRight) bdcursor++;
- else if (buLeft) bdcursor--;
- if (bdcursor > 11) bdcursor = 0;
- if (bdcursor < 0) bdcursor = 11;
- if(buUp){
- if(bdcursor % 2){
- if ((bdaddr[bdcursor /2] & 0x0f) == 0x0f) bdaddr[bdcursor /2] &= 0xf0;
- bdaddr[bdcursor / 2] += 0x1;
- }
- else{
- if ((bdaddr[bdcursor /2] & 0xf0) == 0xf0) bdaddr[bdcursor /2] &= 0x0f;
- bdaddr[bdcursor / 2] += 0x10;
- }
-
- }
- else if (buDown){
- if(bdcursor % 2){
- if ((bdaddr[bdcursor /2] & 0x0f) == 0x0) bdaddr[bdcursor /2] |= 0x0f;
- bdaddr[bdcursor / 2] -= 0x1;
- }
- else{
- if ((bdaddr[bdcursor /2] & 0xf0) == 0x0) bdaddr[bdcursor /2] |= 0xf0;
- bdaddr[bdcursor / 2] -= 0x10;
- }
-
- }
- if( buCross){
- buf[0] = 0x01;
- buf[1] = 0x00;
- for (i=0; i < 6; i++){
- buf[i+2] = bdaddr[i];
- }
- Serial.println( "bdaddr");
- Usb.setReport( PS3_ADDR, ep_record[ CONTROL_EP ].epAddr, PS3_F5_REPORT_LEN, PS3_IF, HID_REPORT_FEATURE, PS3_F5_REPORT_ID , buf );
- }
- }
- LCD.home();
- LCD.print("R: ");
- Usb.getReport( PS3_ADDR, ep_record[ CONTROL_EP ].epAddr, PS3_F5_REPORT_LEN, PS3_IF, HID_REPORT_FEATURE, PS3_F5_REPORT_ID , buf );
- for( i=0; i < 6; i++){
- if ((unsigned char)buf[i+2] < 16) LCD.print ('0');
- LCD.print((unsigned char)buf[i + 2], HEX);
- }
-
- LCD.setCursor(0,1);
- LCD.print("W: ");
- for( i=0; i < 6; i++){
- if (bdaddr[i] < 16) LCD.print ('0');
- LCD.print(bdaddr[i], HEX);
- }
- LCD.setCursor(3 + bdcursor ,1);
- LCD.cursor();
-
- delay(100);
- LCD.noCursor();
- break;
-
- case Freememory:
- LCD.home();
- LCD.print("Free Memory ");
- LCD.print( freeMemory(), DEC );
- LCD.setCursor(0,1);
- break;
-
- default:
- break;
-
- }
-
- return;
-}
-
-
-
-
diff --git a/USB_Host_Shield/examples/arm_mouse.pde b/USB_Host_Shield/examples/arm_mouse.pde
deleted file mode 100644
index e934354..0000000
--- a/USB_Host_Shield/examples/arm_mouse.pde
+++ /dev/null
@@ -1,284 +0,0 @@
-/* AL5D robotic arm manual control using USB mouse. Servo controller by Renbotics with some pins swapped, USB Host Shield by Circuits At Home */
-#include <ServoShield.h>
-#include <Spi.h>
-#include <Max3421e.h>
-#include <Usb.h>
-
-#define DEVADDR 1
-#define CONFVALUE 1
-
-
-
-
-/* Arm dimensions( mm ) */
-#define BASE_HGT 67.31 //base hight 2.65"
-#define HUMERUS 146.05 //shoulder-to-elbow "bone" 5.75"
-#define ULNA 187.325 //elbow-to-wrist "bone" 7.375"
-#define GRIPPER 100.00 //gripper (incl.heavy duty wrist rotate mechanism) length 3.94"
-
-#define ftl(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5)) //float to long conversion
-
-/* Servo names/numbers */
-/* Base servo HS-485HB */
-#define BAS_SERVO 0
-/* Shoulder Servo HS-5745-MG */
-#define SHL_SERVO 1
-/* Elbow Servo HS-5745-MG */
-#define ELB_SERVO 2
-/* Wrist servo HS-645MG */
-#define WRI_SERVO 3
-/* Wrist rotate servo HS-485HB */
-#define WRO_SERVO 4
-/* Gripper servo HS-422 */
-#define GRI_SERVO 5
-
-//#define ARM_PARK set_arm( -50, 140, 100, 0 ) //arm parking position
-
-/* pre-calculations */
-float hum_sq = HUMERUS*HUMERUS;
-float uln_sq = ULNA*ULNA;
-
-void setup();
-void loop();
-
-ServoShield servos; //ServoShield object
-MAX3421E Max;
-USB Usb;
-//ServoShield servos; //ServoShield object
-
-/* Arm data structure */
-struct {
- float x_coord; // X coordinate of the gripper tip
- float y_coord; // Y coordinate of the gripper tip
- float z_coord; //Z coordinate of the gripper tip
- float gripper_angle; //gripper angle
- int16_t gripper_servo; //gripper servo pulse duration
- int16_t wrist_rotate; //wrist rotate servo pulse duration
-} armdata;
-
-void setup()
-{
- /* set servo end points */
- servos.setbounds( BAS_SERVO, 900, 2100 );
- servos.setbounds( SHL_SERVO, 1000, 2100 );
- servos.setbounds( ELB_SERVO, 900, 2100 );
- servos.setbounds( WRI_SERVO, 600, 2400 );
- servos.setbounds( WRO_SERVO, 600, 2400 );
- servos.setbounds( GRI_SERVO, 890, 2100 );
- /**/
-// servo_park();
- arm_park();
-
- servos.start(); //Start the servo shield
- Max.powerOn();
- Serial.begin( 115200 );
- Serial.println("Start");
- delay( 500 );
- //ARM_PARK;
-}
-
-void loop()
-{
-byte rcode;
- //delay( 10 );
- set_arm( armdata.x_coord, armdata.y_coord, armdata.z_coord, armdata.gripper_angle );
- servos.setposition( WRO_SERVO, armdata.wrist_rotate );
- servos.setposition( GRI_SERVO, armdata.gripper_servo );
- //ARM_PARK;
- // circle();
- Max.Task();
- Usb.Task();
- if( Usb.getUsbTaskState() == USB_STATE_CONFIGURING ) {
- mouse_init();
- }//if( Usb.getUsbTaskState() == USB_STATE_CONFIGURING...
- if( Usb.getUsbTaskState() == USB_STATE_RUNNING ) { //poll the keyboard
- rcode = mouse_poll();
- if( rcode ) {
- Serial.print("Mouse Poll Error: ");
- Serial.println( rcode, HEX );
- }//if( rcode...
- }//if( Usb.getUsbTaskState() == USB_STATE_RUNNING...
- //Serial.println( armdata.gripper_servo, DEC );
-}
-
-/* Initialize mouse */
-void mouse_init( void )
-{
- byte rcode = 0; //return code
- /**/
- Usb.setDevTableEntry( 1, Usb.getDevTableEntry( 0,0 ) ); //copy device 0 endpoint information to device 1
- /* Configure device */
- rcode = Usb.setConf( DEVADDR, 0, CONFVALUE );
- if( rcode ) {
- Serial.print("Error configuring mouse. Return code : ");
- Serial.println( rcode, HEX );
- while(1); //stop
- }//if( rcode...
- Usb.setUsbTaskState( USB_STATE_RUNNING );
- return;
-}
-
-/* Poll mouse using Get Report and fill arm data structure */
-byte mouse_poll( void )
-{
- byte rcode;
- char buf[ 4 ]; //mouse buffer
- static uint16_t delay = 500; //delay before park
-
- /* poll mouse */
- rcode = Usb.getReport( DEVADDR, 0, 4, 0, 1, 0, buf );
- if( rcode ) { //error
- return( rcode );
- }
- // todo: add arm limit check
- armdata.x_coord += ( buf[ 1 ] * -0.1 );
- armdata.y_coord += ( buf[ 2 ] * -0.1 );
- switch( buf[ 0 ] ) { //read buttons
- case 0x00: //no buttons pressed
- armdata.z_coord += ( buf[ 3 ] * -2 ) ;
- break;
- case 0x01: //button 1 pressed. Wheel sets gripper angle
- armdata.gripper_servo += ( buf[ 3 ] * -20 );
- /* check gripper boundaries */
- if( armdata.gripper_servo < 1000 ) {
- armdata.gripper_servo = 1000;
- }
- if( armdata.gripper_servo > 2100 ) {
- armdata.gripper_servo = 2100;
- }
- break;
- case 0x02: //button 2 pressed. Wheel sets wrist rotate
- armdata.wrist_rotate += ( buf[ 3 ] * -10 );
- /* check wrist rotate boundaries */
- if( armdata.wrist_rotate < 600 ) {
- armdata.wrist_rotate = 600;
- }
- if( armdata.wrist_rotate > 2400 ) {
- armdata.wrist_rotate = 2400;
- }
- break;
- case 0x04: //wheel button pressed. Wheel controls gripper
- armdata.gripper_angle += ( buf[ 3 ] * -1 );
- /* check gripper angle boundaries */
- if( armdata.gripper_angle < -90 ) {
- armdata.gripper_angle = -90;
- }
- if( armdata.gripper_angle > 90 ) {
- armdata.gripper_angle = 90;
- }
- break;
- case 0x07: //all 3 buttons pressed. Park the arm
- arm_park();
- break;
- }//switch( buf[ 0 ...
- Serial.println( armdata.wrist_rotate, DEC );
-}
-
-
-/* arm positioning routine utilizing inverse kinematics */
-/* z is height, y is distance from base center out, x is side to side. y,z can only be positive */
-//void set_arm( uint16_t x, uint16_t y, uint16_t z, uint16_t grip_angle )
-void set_arm( float x, float y, float z, float grip_angle_d )
-{
- float grip_angle_r = radians( grip_angle_d ); //grip angle in radians for use in calculations
- /* Base angle and radial distance from x,y coordinates */
- float bas_angle_r = atan2( x, y );
- float rdist = sqrt(( x * x ) + ( y * y ));
- /* rdist is y coordinate for the arm */
- y = rdist;
- /* Grip offsets calculated based on grip angle */
- float grip_off_z = ( sin( grip_angle_r )) * GRIPPER;
- float grip_off_y = ( cos( grip_angle_r )) * GRIPPER;
- /* Wrist position */
- float wrist_z = ( z - grip_off_z ) - BASE_HGT;
- float wrist_y = y - grip_off_y;
- /* Shoulder to wrist distance ( AKA sw ) */
- float s_w = ( wrist_z * wrist_z ) + ( wrist_y * wrist_y );
- float s_w_sqrt = sqrt( s_w );
- /* s_w angle to ground */
- //float a1 = atan2( wrist_y, wrist_z );
- float a1 = atan2( wrist_z, wrist_y );
- /* s_w angle to humerus */
- float a2 = acos((( hum_sq - uln_sq ) + s_w ) / ( 2 * HUMERUS * s_w_sqrt ));
- /* shoulder angle */
- float shl_angle_r = a1 + a2;
- float shl_angle_d = degrees( shl_angle_r );
- /* elbow angle */
- float elb_angle_r = acos(( hum_sq + uln_sq - s_w ) / ( 2 * HUMERUS * ULNA ));
- float elb_angle_d = degrees( elb_angle_r );
- float elb_angle_dn = -( 180.0 - elb_angle_d );
- /* wrist angle */
- float wri_angle_d = ( grip_angle_d - elb_angle_dn ) - shl_angle_d;
-
- /* Servo pulses */
- float bas_servopulse = 1500.0 - (( degrees( bas_angle_r )) * 11.11 );
- float shl_servopulse = 1500.0 + (( shl_angle_d - 90.0 ) * 6.6 );
- float elb_servopulse = 1500.0 - (( elb_angle_d - 90.0 ) * 6.6 );
- float wri_servopulse = 1500 + ( wri_angle_d * 11.1 );
-
- /* Set servos */
- servos.setposition( BAS_SERVO, ftl( bas_servopulse ));
- servos.setposition( WRI_SERVO, ftl( wri_servopulse ));
- servos.setposition( SHL_SERVO, ftl( shl_servopulse ));
- servos.setposition( ELB_SERVO, ftl( elb_servopulse ));
-
-}
-
-/* moves the arm to parking position */
-void arm_park()
-{
- set_arm( armdata.x_coord = -50, armdata.y_coord = 140, armdata.z_coord = 100, armdata.gripper_angle = 0 );
- servos.setposition( WRO_SERVO, armdata.wrist_rotate = 600 );
- servos.setposition( GRI_SERVO, armdata.gripper_servo = 900 );
-}
-
-/* move servos to parking position */
-void servo_park()
-{
- servos.setposition( BAS_SERVO, 1715 );
- servos.setposition( SHL_SERVO, 2100 );
- servos.setposition( ELB_SERVO, 2100 );
- servos.setposition( WRI_SERVO, 1800 );
- servos.setposition( WRO_SERVO, 600 );
- servos.setposition( GRI_SERVO, 900 );
- return;
-}
-
-void zero_x()
-{
- for( double yaxis = 150.0; yaxis < 356.0; yaxis += 1 ) {
- set_arm( 0, yaxis, 127.0, 0 );
- delay( 10 );
- }
- for( double yaxis = 356.0; yaxis > 150.0; yaxis -= 1 ) {
- set_arm( 0, yaxis, 127.0, 0 );
- delay( 10 );
- }
-}
-
-/* moves arm in a straight line */
-void line()
-{
- for( double xaxis = -100.0; xaxis < 100.0; xaxis += 0.5 ) {
- set_arm( xaxis, 250, 100, 0 );
- delay( 10 );
- }
- for( float xaxis = 100.0; xaxis > -100.0; xaxis -= 0.5 ) {
- set_arm( xaxis, 250, 100, 0 );
- delay( 10 );
- }
-}
-
-void circle()
-{
- #define RADIUS 80.0
- //float angle = 0;
- float zaxis,yaxis;
- for( float angle = 0.0; angle < 360.0; angle += 1.0 ) {
- yaxis = RADIUS * sin( radians( angle )) + 200;
- zaxis = RADIUS * cos( radians( angle )) + 200;
- set_arm( 0, yaxis, zaxis, 0 );
- delay( 1 );
- }
-}
-
diff --git a/USB_Host_Shield/examples/board_test/board_test.h b/USB_Host_Shield/examples/board_test/board_test.h
deleted file mode 100644
index 7435d7d..0000000
--- a/USB_Host_Shield/examples/board_test/board_test.h
+++ /dev/null
@@ -1,21 +0,0 @@
-/* USB Host Shield board test sketch header */
-#ifndef _BOARD_TEST_H_
-#define _BOARD_TEST_H_
-
-/* PGMSPACE */
-#include <inttypes.h>
-#include <avr/pgmspace.h>
-
-/* Messages */
-const char startBanner [] PROGMEM = "\r\nCircuits At Home 2010"
- "\r\nUSB Host Shield QC test routine\r\n";
-const char anykey_msg [] PROGMEM = "\r\nPress any key to continue...";
-const char testpassed_msg [] PROGMEM = "\r\nTest PASSED";
-const char testfailed_msg [] PROGMEM = "\r\nTest FAILED*!*";
-const char osctest_oscstate_msg [] PROGMEM = " Oscillator state is ";
-const char test_halted_msg [] PROGMEM = "\r\nTest Halted."
- "\r\n0x55 pattern is being transmitted via SPI to aid in troubleshooting";
-const char spitest_fail_msg [] PROGMEM = "\r\nSPI transmit/receive mismatch"
- "\r\nValue written: ";
-
-#endif
diff --git a/USB_Host_Shield/examples/board_test/board_test.pde b/USB_Host_Shield/examples/board_test/board_test.pde
deleted file mode 100644
index 1188fbf..0000000
--- a/USB_Host_Shield/examples/board_test/board_test.pde
+++ /dev/null
@@ -1,296 +0,0 @@
-/* USB Host Shield Board test routine. Runs after assembly to check board functionality */
-
-/* USB related */
-//#include <Spi.h>
-#include <Max3421e.h>
-#include <Max3421e_constants.h>
-#include <Usb.h>
-
-#include "board_test.h" /* Board test messages */
-
-//#define MAX_SS 10
-
-void setup();
-void loop();
-
-MAX3421E Max;
-USB Usb;
-
-void setup()
-{
- Serial.begin( 115200 );
- //Serial.println("Start");
- //Serial.println( SCK_PIN, DEC );
- Max.powerOn();
- printProgStr( startBanner );
- printProgStr( anykey_msg );
- //Serial.print( Max.getvar(), DEC);
-}
-
-void loop()
-{
- while( Serial.available() == 0 ); //wait for input
- Serial.read(); //empty input buffer
- /* start tests */
- /* SPI short test */
- if (!revregcheck()) test_halted();
- /* GPIO test */
- if (!gpiocheck()) printProgStr(PSTR("\r\nGPIO check failed. Make sure GPIO loopback adapter is installed"));
- /* SPI long test */
- if (!spitest()) test_halted(); //test SPI for transmission errors
- if (!osctest()) printProgStr(PSTR("OSCOK test failed. Check the oscillator"));
- if (!usbtest()) printProgStr(PSTR("USB connection test failed. Check traces from USB connector to MAX3421E, as well as VBUS")); //never gets here
- /* All tests passed */
- printProgStr( anykey_msg );
-}
-
-/* SPI short test. Checks connectivity to MAX3421E by reading REVISION register. */
-/* Die rev.1 returns 0x01, rev.2 0x12, rev.3 0x13. Any other value is considered communication error */
-bool revregcheck()
-{
- byte tmpbyte;
- printProgStr(PSTR("\r\nReading REVISION register...Die revision "));
- tmpbyte = Max.regRd( rREVISION );
- switch( tmpbyte ) {
- case( 0x01 ): //rev.01
- printProgStr(PSTR("01"));
- break;
- case( 0x12 ): //rev.02
- printProgStr(PSTR("02"));
- break;
- case( 0x13 ): //rev.03
- printProgStr(PSTR("03"));
- break;
- default:
- printProgStr(PSTR("invalid. Value returned: "));
- print_hex( tmpbyte, 8 );
- printProgStr( testfailed_msg );
- return( false );
- break;
- }//switch( tmpbyte )...
- printProgStr( testpassed_msg );
- return( true );
-}
-/* SPI long test */
-bool spitest()
-{
- byte l = 0;
- byte k = 0;
- byte gpinpol_copy = Max.regRd( rGPINPOL );
- printProgStr(PSTR("\r\nSPI test. Each '.' indicates 64K transferred. Stops after transferring 1MB (16 dots)\r\n"));
- /**/
- for( byte j = 0; j < 16; j++ ) {
- for( word i = 0; i < 65535; i++ ) {
- Max.regWr( rGPINPOL, k );
- l = Max.regRd( rGPINPOL);
- if( l != k ) {
- printProgStr( spitest_fail_msg );
- print_hex( k, 8);
- printProgStr(PSTR("Value read: "));
- print_hex( l, 8 );
- return( false ); //test failed
- }
- k++;
- }//for( i = 0; i < 65535; i++
- Serial.print(".");
- }//for j = 0; j < 16...
- Max.regWr( rGPINPOL, gpinpol_copy );
- printProgStr(testpassed_msg);
- return( true );
-}
-/* Oscillator test */
-bool osctest()
-{
- printProgStr(PSTR("\r\nOscillator start/stop test."));
- printProgStr( osctest_oscstate_msg );
- check_OSCOKIRQ(); //print OSCOK state
- printProgStr(PSTR("\r\nSetting CHIP RESET."));
- Max.regWr( rUSBCTL, bmCHIPRES ); //Chip reset. This stops the oscillator
- printProgStr( osctest_oscstate_msg );
- check_OSCOKIRQ(); //print OSCOK state
- printProgStr(PSTR("\r\nClearing CHIP RESET. "));
- Max.regWr( rUSBCTL, 0x00 ); //Chip reset release
- for( word i = 0; i < 65535; i++) {
- if( Max.regRd( rUSBIRQ ) & bmOSCOKIRQ ) {
- printProgStr(PSTR("PLL is stable. Time to stabilize - "));
- Serial.print( i, DEC );
- printProgStr(PSTR(" cycles"));
- printProgStr( testpassed_msg );
- return( true );
- }
- }//for i =
- return(false);
-}
-/* Stop/start oscillator */
-void check_OSCOKIRQ()
-{
- if( Max.regRd( rUSBIRQ ) & bmOSCOKIRQ ) { //checking oscillator state
- printProgStr(PSTR("ON"));
- }
- else {
- printProgStr(PSTR("OFF"));
- }
-}
-/* Test USB connectivity */
-bool usbtest()
-{
- byte rcode;
- byte usbstate;
- Max.powerOn();
- delay( 200 );
- printProgStr(PSTR("\r\nUSB Connectivity test. Waiting for device connection... "));
- while( 1 ) {
- delay( 200 );
- Max.Task();
- Usb.Task();
- usbstate = Usb.getUsbTaskState();
- switch( usbstate ) {
- case( USB_ATTACHED_SUBSTATE_RESET_DEVICE ):
- printProgStr(PSTR("\r\nDevice connected. Resetting"));
- break;
- case( USB_ATTACHED_SUBSTATE_WAIT_SOF ):
- printProgStr(PSTR("\r\nReset complete. Waiting for the first SOF..."));
- //delay( 1000 );
- break;
- case( USB_ATTACHED_SUBSTATE_GET_DEVICE_DESCRIPTOR_SIZE ):
- printProgStr(PSTR("\r\nSOF generation started. Enumerating device."));
- break;
- case( USB_STATE_ADDRESSING ):
- printProgStr(PSTR("\r\nSetting device address"));
- //delay( 100 );
- break;
- case( USB_STATE_CONFIGURING ):
- //delay( 1000 );
- printProgStr(PSTR("\r\nGetting device descriptor"));
- rcode = getdevdescr( 1 );
- if( rcode ) {
- printProgStr(PSTR("\r\nError reading device descriptor. Error code "));
- print_hex( rcode, 8 );
- }
- else {
- printProgStr(PSTR("\r\n\nAll tests passed. Press RESET to restart test"));
- while(1);
- }
- break;
- case( USB_STATE_ERROR ):
- printProgStr(PSTR("\r\nUSB state machine reached error state"));
- break;
- default:
- break;
- }//switch
- }//while(1)
-}
-/* Get device descriptor */
-byte getdevdescr( byte addr )
-{
- USB_DEVICE_DESCRIPTOR buf;
- byte rcode;
- rcode = Usb.getDevDescr( addr, 0, 0x12, ( char *)&buf );
- if( rcode ) {
- return( rcode );
- }
- printProgStr(PSTR("\r\nDevice descriptor: "));
- printProgStr(PSTR("\r\nDescriptor Length:\t"));
- print_hex( buf.bLength, 8 );
- printProgStr(PSTR("\r\nDescriptor type:\t"));
- print_hex( buf.bDescriptorType, 8 );
- printProgStr(PSTR("\r\nUSB version:\t"));
- print_hex( buf.bcdUSB, 16 );
- printProgStr(PSTR("\r\nDevice class:\t"));
- print_hex( buf.bDeviceClass, 8 );
- printProgStr(PSTR("\r\nDevice Subclass:\t"));
- print_hex( buf.bDeviceSubClass, 8 );
- printProgStr(PSTR("\r\nDevice Protocol:\t"));
- print_hex( buf.bDeviceProtocol, 8 );
- printProgStr(PSTR("\r\nMax.packet size:\t"));
- print_hex( buf.bMaxPacketSize0, 8 );
- printProgStr(PSTR("\r\nVendor ID:\t"));
- print_hex( buf.idVendor, 16 );
- printProgStr(PSTR("\r\nProduct ID:\t"));
- print_hex( buf.idProduct, 16 );
- printProgStr(PSTR("\r\nRevision ID:\t"));
- print_hex( buf.bcdDevice, 16 );
- printProgStr(PSTR("\r\nMfg.string index:\t"));
- print_hex( buf.iManufacturer, 8 );
- printProgStr(PSTR("\r\nProd.string index:\t"));
- print_hex( buf.iProduct, 8 );
- printProgStr(PSTR("\r\nSerial number index:\t"));
- print_hex( buf.iSerialNumber, 8 );
- printProgStr(PSTR("\r\nNumber of conf.:\t"));
- print_hex( buf.bNumConfigurations, 8 );
- return( 0 );
-}
-
-/* GPIO lines check. A loopback adapter connecting GPIN to GPOUT is assumed */
-bool gpiocheck()
-{
- byte tmpbyte = 0;
- printProgStr(PSTR("\r\nChecking GPIO lines. Install GPIO loopback adapter and press any key to continue..."));
- while( Serial.available() == 0 ); //wait for input
- Serial.read(); //empty input buffer
- for( byte i = 0; i < 255; i++ ) {
- Max.gpioWr( i );
- tmpbyte = Max.gpioRd();
- if( tmpbyte != i ) {
- printProgStr(PSTR("GPIO read/write mismatch. Write: "));
- Serial.print(i, HEX);
- printProgStr(PSTR(" Read: "));
- Serial.println( tmpbyte, HEX );
- return( false );
- }//if( tmpbyte != i )
- }//for( i= 0...
- printProgStr( testpassed_msg );
- return( true );
-}
-/* Test halted state. Generates 0x55 to aid in SPI troubleshooting */
-void test_halted()
-{
- printProgStr( test_halted_msg );
- printProgStr(PSTR("\r\nPress RESET to restart test"));
- while( 1 ) { //System Stop. Generating pattern to keep SCLK, MISO, MOSI, SS busy
- digitalWrite(MAX_SS,LOW);
- Max.regWr( 0x55, 0x55 );
-// Spi.transfer( 0x55 );
- digitalWrite(MAX_SS,HIGH);
- }
-}
-/* given a PROGMEM string, use Serial.print() to send it out */
-/* Some non-intuitive casting necessary: */
-/* printProgStr(PSTR("Func.Mode:\t0x")); */
-/* printProgStr((char*)pgm_read_word(&mtpopNames[(op & 0xFF)])); */
-void printProgStr(const char* str )
-{
- if(!str) {
- return;
- }
- char c;
- while((c = pgm_read_byte(str++))) {
- Serial.print(c,BYTE);
- }
-}
-/* prints hex numbers with leading zeroes */
-// copyright, Peter H Anderson, Baltimore, MD, Nov, '07
-// source: http://www.phanderson.com/arduino/arduino_display.html
-void print_hex(int v, int num_places)
-{
- int mask=0, n, num_nibbles, digit;
-
- for (n=1; n<=num_places; n++)
- {
- mask = (mask << 1) | 0x0001;
- }
- v = v & mask; // truncate v to specified number of places
-
- num_nibbles = num_places / 4;
- if ((num_places % 4) != 0)
- {
- ++num_nibbles;
- }
-
- do
- {
- digit = ((v >> (num_nibbles-1) * 4)) & 0x0f;
- Serial.print(digit, HEX);
- }
- while(--num_nibbles);
-}
diff --git a/USB_Host_Shield/examples/conf_descr_dump.pde b/USB_Host_Shield/examples/conf_descr_dump.pde
deleted file mode 100644
index 56d7a58..0000000
--- a/USB_Host_Shield/examples/conf_descr_dump.pde
+++ /dev/null
@@ -1,181 +0,0 @@
-/* MAX3421E USB Host controller get configuration descriptor */
-#include <Spi.h>
-#include <Max3421e.h>
-#include <Usb.h>
-
-#define LOBYTE(x) ((char*)(&(x)))[0]
-#define HIBYTE(x) ((char*)(&(x)))[1]
-#define BUFSIZE 256 //buffer size
-
-void setup();
-void loop();
-
-MAX3421E Max;
-USB Usb;
-
-void setup()
-{
- byte tmpdata = 0;
- Serial.begin( 9600 );
- Serial.println("Start");
- Max.powerOn();
- delay( 200 );
-}
-
-void loop()
-{
- byte rcode;
- byte tmpbyte;
- Max.Task();
- Usb.Task();
- if( Usb.getUsbTaskState() >= USB_STATE_CONFIGURING ) { //state configuring or higher
- /* entering configuration number to decode. Restricted to first 10 configurations */
- Serial.print("Enter configuration number: ");
- while( Serial.available() == 0 ); //wait for input
- tmpbyte = Serial.read();
- Serial.println( tmpbyte );
- tmpbyte -= 0x30; //convert to number
- if( tmpbyte > 9 ) {
- Serial.println("Not a number. Assuming configuration 0");
- tmpbyte = 0;
- }
- rcode = getconfdescr( 1, tmpbyte ); //get configuration descriptor
- if( rcode ) {
- Serial.println( rcode, HEX );
- }
-// while( 1 ); //stop
- }
-}
-
-byte getconfdescr( byte addr, byte conf )
-{
- char buf[ BUFSIZE ];
- char* buf_ptr = buf;
- byte rcode;
- byte descr_length;
- byte descr_type;
- unsigned int total_length;
- rcode = Usb.getConfDescr( addr, 0, 4, conf, buf ); //get total length
- LOBYTE( total_length ) = buf[ 2 ];
- HIBYTE( total_length ) = buf[ 3 ];
- if( total_length > BUFSIZE ) { //check if total length is larger than buffer
- Serial.println("Total length truncated to 256 bytes");
- total_length = BUFSIZE;
- }
- rcode = Usb.getConfDescr( addr, 0, total_length, conf, buf ); //get the whole descriptor
- while( buf_ptr < buf + total_length ) { //parsing descriptors
- descr_length = *( buf_ptr );
- descr_type = *( buf_ptr + 1 );
- switch( descr_type ) {
- case( USB_DESCRIPTOR_CONFIGURATION ):
- printconfdescr( buf_ptr );
- break;
- case( USB_DESCRIPTOR_INTERFACE ):
- printintfdescr( buf_ptr );
- break;
- case( USB_DESCRIPTOR_ENDPOINT ):
- printepdescr( buf_ptr );
- break;
- default:
- printunkdescr( buf_ptr );
- break;
- }//switch( descr_type
- Serial.println("");
- buf_ptr = ( buf_ptr + descr_length ); //advance buffer pointer
- }//while( buf_ptr <=...
- return( 0 );
-}
-/* prints hex numbers with leading zeroes */
-// copyright, Peter H Anderson, Baltimore, MD, Nov, '07
-// source: http://www.phanderson.com/arduino/arduino_display.html
-void print_hex(int v, int num_places)
-{
- int mask=0, n, num_nibbles, digit;
-
- for (n=1; n<=num_places; n++) {
- mask = (mask << 1) | 0x0001;
- }
- v = v & mask; // truncate v to specified number of places
-
- num_nibbles = num_places / 4;
- if ((num_places % 4) != 0) {
- ++num_nibbles;
- }
- do {
- digit = ((v >> (num_nibbles-1) * 4)) & 0x0f;
- Serial.print(digit, HEX);
- }
- while(--num_nibbles);
-}
-/* function to print configuration descriptor */
-void printconfdescr( char* descr_ptr )
-{
- USB_CONFIGURATION_DESCRIPTOR* conf_ptr = ( USB_CONFIGURATION_DESCRIPTOR* )descr_ptr;
- Serial.println("Configuration descriptor:");
- Serial.print("Total length:\t");
- print_hex( conf_ptr->wTotalLength, 16 );
- Serial.print("\r\nNum.intf:\t\t");
- print_hex( conf_ptr->bNumInterfaces, 8 );
- Serial.print("\r\nConf.value:\t");
- print_hex( conf_ptr->bConfigurationValue, 8 );
- Serial.print("\r\nConf.string:\t");
- print_hex( conf_ptr->iConfiguration, 8 );
- Serial.print("\r\nAttr.:\t\t");
- print_hex( conf_ptr->bmAttributes, 8 );
- Serial.print("\r\nMax.pwr:\t\t");
- print_hex( conf_ptr->bMaxPower, 8 );
- return;
-}
-/* function to print interface descriptor */
-void printintfdescr( char* descr_ptr )
-{
- USB_INTERFACE_DESCRIPTOR* intf_ptr = ( USB_INTERFACE_DESCRIPTOR* )descr_ptr;
- Serial.println("\r\nInterface descriptor:");
- Serial.print("Intf.number:\t");
- print_hex( intf_ptr->bInterfaceNumber, 8 );
- Serial.print("\r\nAlt.:\t\t");
- print_hex( intf_ptr->bAlternateSetting, 8 );
- Serial.print("\r\nEndpoints:\t\t");
- print_hex( intf_ptr->bNumEndpoints, 8 );
- Serial.print("\r\nClass:\t\t");
- print_hex( intf_ptr->bInterfaceClass, 8 );
- Serial.print("\r\nSubclass:\t\t");
- print_hex( intf_ptr->bInterfaceSubClass, 8 );
- Serial.print("\r\nProtocol:\t\t");
- print_hex( intf_ptr->bInterfaceProtocol, 8 );
- Serial.print("\r\nIntf.string:\t");
- print_hex( intf_ptr->iInterface, 8 );
- return;
-}
-/* function to print endpoint descriptor */
-void printepdescr( char* descr_ptr )
-{
- USB_ENDPOINT_DESCRIPTOR* ep_ptr = ( USB_ENDPOINT_DESCRIPTOR* )descr_ptr;
- Serial.println("\r\nEndpoint descriptor:");
- Serial.print("Endpoint address:\t");
- print_hex( ep_ptr->bEndpointAddress, 8 );
- Serial.print("\r\nAttr.:\t\t");
- print_hex( ep_ptr->bmAttributes, 8 );
- Serial.print("\r\nMax.pkt size:\t");
- print_hex( ep_ptr->wMaxPacketSize, 16 );
- Serial.print("\r\nPolling interval:\t");
- print_hex( ep_ptr->bInterval, 8 );
- return;
-}
-/*function to print unknown descriptor */
-void printunkdescr( char* descr_ptr )
-{
- byte length = *descr_ptr;
- byte i;
- Serial.println("\r\nUnknown descriptor:");
- Serial. print("Length:\t\t");
- print_hex( *descr_ptr, 8 );
- Serial.print("\r\nType:\t\t");
- print_hex( *(descr_ptr + 1 ), 8 );
- Serial.print("\r\nContents:\t");
- descr_ptr += 2;
- for( i = 0; i < length; i++ ) {
- print_hex( *descr_ptr, 8 );
- descr_ptr++;
- }
-}
diff --git a/USB_Host_Shield/examples/descriptor_parser/descriptor_parser.h b/USB_Host_Shield/examples/descriptor_parser/descriptor_parser.h
deleted file mode 100644
index 7570841..0000000
--- a/USB_Host_Shield/examples/descriptor_parser/descriptor_parser.h
+++ /dev/null
@@ -1,284 +0,0 @@
-#ifndef _DESCRIPTOR_PARSER_
-#define _DESCRIPTOR_PARSER_
-
-/* PGMSPACE */
-#include <inttypes.h>
-#include <avr/pgmspace.h>
-
-typedef void (*PARSE)( uint8_t bytes );
-
-/* Common Messages */
-
-const char descr_len [] PROGMEM = "\r\nDescriptor Length:\t";
-const char descr_type [] PROGMEM = "\r\nDescriptor type:\t";
-const char class_str [] PROGMEM = "\r\nClass:\t\t\t";
-const char subclass_str [] PROGMEM = "\r\nSubclass:\t\t";
-const char protocol_str [] PROGMEM = "\r\nProtocol:\t\t";
-const char maxpktsize_str [] PROGMEM = "\r\nMax.packet size:\t";
-const char unk_msg [] PROGMEM = " Unknown";
-const char reserved_msg [] PROGMEM = "Reserved";
-const char rcode_error_msg [] PROGMEM = "\r\nRequest error. Reurn code: ";
-
-/* Endpoint attributes */
-
-const char control_tr [] PROGMEM = "Control";
-const char iso_tr [] PROGMEM = "Isochronous";
-const char bulk_tr [] PROGMEM = "Bulk";
-const char int_tr [] PROGMEM = "Interrupt";
-
-const char* transfer_types [] PROGMEM =
-{
- control_tr,
- iso_tr,
- bulk_tr,
- int_tr
-};
-
-const char nosync_type [] PROGMEM = "No Synchronization";
-const char async_type [] PROGMEM = "Asynchronous";
-const char adaptive_type [] PROGMEM = "Adaptive";
-const char sync_type [] PROGMEM = "Synchronous";
-
-const char* sync_types [] PROGMEM =
-{
- nosync_type,
- async_type,
- adaptive_type,
- sync_type
-};
-
-const char data_usage [] PROGMEM = "Data";
-const char feedback_usage [] PROGMEM = "Feedback";
-const char implicit_usage [] PROGMEM = "Implicit Feedback Data";
-const char reserved_usage [] PROGMEM = "Reserved";
-
-const char* usage_types [] PROGMEM =
-{
- data_usage,
- feedback_usage,
- implicit_usage,
- reserved_usage
-};
-
-/* HID Country Codes */
-
-const char notsupported_cc [] PROGMEM = "Not Supported";
-const char arabic_cc [] PROGMEM = "Arabic";
-const char belgian_cc [] PROGMEM = "Belgian";
-const char canadianbi_cc [] PROGMEM = "Canadian-Bilingual";
-const char canadianfr_cc [] PROGMEM = "Canadian-French";
-const char czech_cc [] PROGMEM = "Czech Republic";
-const char danish_cc [] PROGMEM = "Danish";
-const char finnish_cc [] PROGMEM = "Finnish";
-const char french_cc [] PROGMEM = "French";
-const char german_cc [] PROGMEM = "German";
-const char greek_cc [] PROGMEM = "Greek";
-const char hebrew_cc [] PROGMEM = "Hebrew";
-const char hungary_cc [] PROGMEM = "Hungary";
-const char intl_cc [] PROGMEM = "International (ISO)";
-const char italian_cc [] PROGMEM = "Italian";
-const char japan_cc [] PROGMEM = "Japan (Katakana)";
-const char korean_cc [] PROGMEM = "Korean";
-const char latam_cc [] PROGMEM = "Latin American";
-const char dutch_cc [] PROGMEM = "Netherlands/Dutch";
-const char norwegian_cc [] PROGMEM = "Norwegian";
-const char persian_cc [] PROGMEM = "Persian (Farsi)";
-const char poland_cc [] PROGMEM = "Poland";
-const char portuguese_cc [] PROGMEM = "Portuguese";
-const char russia_cc [] PROGMEM = "Russia";
-const char slovakia_cc [] PROGMEM = "Slovakia";
-const char spanish_cc [] PROGMEM = "Spanish";
-const char swedish_cc [] PROGMEM = "Swedish";
-const char swiss_fr_cc [] PROGMEM = "Swiss/French";
-const char swiss_ger_cc [] PROGMEM = "Swiss/German";
-const char swiss_cc [] PROGMEM = "Switzerland";
-const char taiwan_cc [] PROGMEM = "Taiwan";
-const char turkish_q_cc [] PROGMEM = "Turkish-Q";
-const char uk_cc [] PROGMEM = "UK";
-const char us_cc [] PROGMEM = "US";
-const char yugo_cc [] PROGMEM = "Yugoslavia";
-const char turkish_f_cc [] PROGMEM = "Turkish-F";
-
-const char* HID_Country_Codes [] PROGMEM =
-{
-notsupported_cc,
-arabic_cc,
-belgian_cc,
-canadianbi_cc,
-canadianfr_cc,
-czech_cc,
-danish_cc,
-finnish_cc,
-french_cc,
-german_cc,
-greek_cc,
-hebrew_cc,
-hungary_cc,
-intl_cc,
-italian_cc,
-japan_cc,
-korean_cc,
-latam_cc,
-dutch_cc,
-norwegian_cc,
-persian_cc,
-poland_cc,
-portuguese_cc,
-russia_cc,
-slovakia_cc,
-spanish_cc,
-swedish_cc,
-swiss_fr_cc,
-swiss_ger_cc,
-swiss_cc,
-taiwan_cc,
-turkish_q_cc,
-uk_cc,
-us_cc,
-yugo_cc,
-turkish_f_cc
-};
-
-/* HID report descriptor parser string definitions */
-/* Item type strings */
-const char btype_main [] PROGMEM = "Main";
-const char btype_global [] PROGMEM = "Global";
-const char btype_local [] PROGMEM = "Local";
-const char btype_reserved [] PROGMEM = "Reserved";
-/* Item types strings array. Array index corresponds to bType */
-const char* btypes [] PROGMEM =
-{
- btype_main,
- btype_global,
- btype_local,
- btype_reserved
-};
-/* Main Item Tag Strings */
-const char main_tag_input [] PROGMEM = "Input\t\t";
-const char main_tag_output [] PROGMEM = "Output\t\t";
-const char main_tag_collection [] PROGMEM = "Collection\t\t";
-const char main_tag_feature [] PROGMEM = "Feature\t\t";
-const char main_tag_endcoll [] PROGMEM = "End Collection\t";
-/* Main Item Tags Strings Array */
-const char* maintags [] PROGMEM =
-{
- main_tag_input,
- main_tag_output,
- main_tag_collection,
- main_tag_feature,
- main_tag_endcoll
-};
-/* Global Item Tag Strings */
-const char global_tag_usagepage [] PROGMEM = "Usage Page\t\t";
-const char global_tag_logmin [] PROGMEM = "Logical Minimum\t";
-const char global_tag_logmax [] PROGMEM = "Logical Maximum\t";
-const char global_tag_physmin [] PROGMEM = "Physical Minimum\t";
-const char global_tag_physmax [] PROGMEM = "Physical Maximum\t";
-const char global_tag_unitexp [] PROGMEM = "Unit Exponent\t";
-const char global_tag_unit [] PROGMEM = "Unit\t\t";
-const char global_tag_repsize [] PROGMEM = "Report Size\t";
-const char global_tag_repid [] PROGMEM = "Report ID\t\t";
-const char global_tag_repcount [] PROGMEM = "Report Count\t";
-const char global_tag_push [] PROGMEM = "Push\t\t";
-const char global_tag_pop [] PROGMEM = "Pop\t\t";
-/* Global Item Tag Strings Array */
-const char* globaltags [] PROGMEM =
-{
- global_tag_usagepage,
- global_tag_logmin,
- global_tag_logmax,
- global_tag_physmin,
- global_tag_physmax,
- global_tag_unitexp,
- global_tag_unit,
- global_tag_repsize,
- global_tag_repid,
- global_tag_repcount,
- global_tag_push,
- global_tag_pop
-};
-/* Local Item Tag Strings */
-const char local_tag_usage [] PROGMEM = "Usage\t\t";
-const char local_tag_usagemin [] PROGMEM = "Usage Minimum\t";
-const char local_tag_usagemax [] PROGMEM = "Usage Maximum\t";
-const char local_tag_desidx [] PROGMEM = "Designator Index\t";
-const char local_tag_desmin [] PROGMEM = "Designator Minimum\t";
-const char local_tag_desmax [] PROGMEM = "Designator Maximum\t";
-const char local_tag_stridx [] PROGMEM = "String Index\t";
-const char local_tag_strmin [] PROGMEM = "String Minimum\t";
-const char local_tag_strmax [] PROGMEM = "String Maximum\t";
-const char local_tag_delimiter [] PROGMEM = "Delimiter\t";
-/* Local Item Tag Strings Array */
-const char* localtags [] PROGMEM =
-{
- local_tag_usage,
- local_tag_usagemin,
- local_tag_usagemax,
- local_tag_desidx,
- local_tag_desmin,
- local_tag_desmax,
- local_tag_stridx,
- local_tag_strmin,
- local_tag_strmax,
- local_tag_delimiter
-};
-/* Collection Types Strings */
-const char coll_phy [] PROGMEM = "Physical (group of axes)";
-const char coll_app [] PROGMEM = "Application (mouse, keyboard)";
-const char coll_log [] PROGMEM = "Logical (interrelated data)";
-const char coll_rep [] PROGMEM = "Report";
-const char coll_arr [] PROGMEM = "Named Array";
-const char coll_usw [] PROGMEM = "Usage Switch";
-const char coll_umod [] PROGMEM = "Usage Modifier";
-/* Collection Types Strings Array */
-const char* collections [] PROGMEM =
-{
- coll_phy,
- coll_app,
- coll_log,
- coll_rep,
- coll_arr,
- coll_usw,
- coll_umod
-};
-/* Usage Pages Strings */
-const char up_undef [] PROGMEM = "Undefined";
-const char up_gendesk [] PROGMEM = "Generic Desktop Controls";
-const char up_sim [] PROGMEM = "Simulation Controls";
-const char up_vr [] PROGMEM = "VR Controls";
-const char up_sport [] PROGMEM = "Sport Controls";
-const char up_game [] PROGMEM = "Game Controls";
-const char up_gendev [] PROGMEM = "Generic Device Controls";
-const char up_kbd [] PROGMEM = "Keyboard/Keypad";
-const char up_led [] PROGMEM = "LEDs";
-const char up_button [] PROGMEM = "Button";
-const char up_ord [] PROGMEM = "Ordinal";
-const char up_tele [] PROGMEM = "Telephony";
-const char up_cons [] PROGMEM = "Consumer";
-const char up_dig [] PROGMEM = "Digitizer";
-//const char up_res [] PROGMEM = "Reserved";
-const char up_pid [] PROGMEM = "PID Page";
-const char up_uni [] PROGMEM = "Unicode";
-/* Usage Pages Strings Array */
-const char * usage_pages [] PROGMEM =
-{
- up_undef,
- up_gendesk,
- up_sim,
- up_vr,
- up_sport,
- up_game,
- up_gendev,
- up_kbd,
- up_led,
- up_button,
- up_ord,
- up_tele,
- up_cons,
- up_dig,
- reserved_msg,
- up_pid,
- up_uni
-};
-
-#endif //_DESCRIPTOR_PARSER_
diff --git a/USB_Host_Shield/examples/descriptor_parser/descriptor_parser.pde b/USB_Host_Shield/examples/descriptor_parser/descriptor_parser.pde
deleted file mode 100644
index d417e76..0000000
--- a/USB_Host_Shield/examples/descriptor_parser/descriptor_parser.pde
+++ /dev/null
@@ -1,720 +0,0 @@
-/* MAX3421E USB Host controller configuration descriptor parser */
-#include <Spi.h>
-#include <Max3421e.h>
-#include <Usb.h>
-#include "descriptor_parser.h"
-
-#define LOBYTE(x) ((char*)(&(x)))[0]
-#define HIBYTE(x) ((char*)(&(x)))[1]
-#define BUFSIZE 256 //buffer size
-#define DEVADDR 1
-
-#define getReportDescr( addr, ep, nbytes, parse_func, nak_limit ) ctrlXfer( addr, ep, bmREQ_HIDREPORT, USB_REQUEST_GET_DESCRIPTOR, 0x00, HID_DESCRIPTOR_REPORT, 0x0000, nbytes, parse_func, nak_limit )
-#define getReport( addr, ep, nbytes, interface, report_type, report_id, parse_func, nak_limit ) ctrlXfer( addr, ep, bmREQ_HIDIN, HID_REQUEST_GET_REPORT, report_id, report_type, interface, nbytes, parse_func, nak_limit )
-
-/* Foeward declarations */
-void setup();
-void loop();
-byte ctrlXfer( byte addr, byte ep, byte bmReqType, byte bRequest, byte wValLo, byte wValHi, unsigned int wInd, uint16_t nbytes, PARSE parse_func, uint16_t nak_limit );
-void HIDreport_parse( uint8_t* buf, uint8_t* head, uint8_t* tail);
-
-typedef struct {
- uint8_t bDescriptorType;
- uint16_t wDescriptorLength;
-} HID_CLASS_DESCRIPTOR;
-
-
-//typedef void (*PARSE)( int8_t*, int8_t*, int8_t );
-
-MAX3421E Max;
-USB Usb;
-
-void setup()
-{
- Serial.begin( 115200 );
- printProgStr(PSTR("\r\nStart"));
- Max.powerOn();
- delay( 200 );
-}
-
-void loop()
-{
- uint8_t rcode;
- uint8_t tmpbyte = 0;
- //PARSE pf = &HIDreport_parse;
- /**/
- Max.Task();
- Usb.Task();
- if( Usb.getUsbTaskState() >= USB_STATE_CONFIGURING ) { //state configuring or higher
- /* printing device descriptor */
- printProgStr(PSTR("\r\nDevice addressed... "));
- printProgStr(PSTR("Requesting device descriptor."));
- tmpbyte = getdevdescr( DEVADDR ); //number of configurations, 0 if error
- if( tmpbyte == 0 ) {
- printProgStr(PSTR("\r\nDevice descriptor cannot be retrieved. Program Halted\r\n"));
- while( 1 ); //stop
- }//if( tmpbyte
- /* print configuration descriptors for all configurations */
- for( uint8_t i = 0; i < tmpbyte; i++ ) {
- getconfdescr( DEVADDR, i );
- }
- /* Stop */
- while( 1 ); //stop
- }
-}
-
-/* Prints device descriptor. Returns number of configurations or zero if request error occured */
-byte getdevdescr( byte addr )
-{
- USB_DEVICE_DESCRIPTOR buf;
- byte rcode;
- //Max.toggle( BPNT_0 );
- rcode = Usb.getDevDescr( addr, 0, 0x12, ( char *)&buf );
- if( rcode ) {
- printProgStr( rcode_error_msg );
- print_hex( rcode, 8 );
- return( 0 );
- }
- printProgStr(PSTR("\r\nDevice descriptor: \r\n"));
- //Descriptor length
- printProgStr( descr_len );
- print_hex( buf.bLength, 8 );
- //Descriptor type
-// printProgStr( descr_type );
-// print_hex( buf.bDescriptorType, 8 );
-// printProgStr( descrtype_parse( buf.bDescriptorType ));
- //USB Version
- printProgStr(PSTR("\r\nUSB version:\t\t"));
- Serial.print(( HIBYTE( buf.bcdUSB )), HEX );
- Serial.print(".");
- Serial.print(( LOBYTE( buf.bcdUSB )), HEX );
- //Device class
- printProgStr( class_str );
- print_hex( buf.bDeviceClass, 8 );
- printProgStr( classname_parse( buf.bDeviceClass ));
- //Device Subclass
- printProgStr( subclass_str );
- print_hex( buf.bDeviceSubClass, 8 );
- //Device Protocol
- printProgStr( protocol_str );
- print_hex( buf.bDeviceProtocol, 8 );
- //Max.packet size
- printProgStr( maxpktsize_str );
- print_hex( buf.bMaxPacketSize0, 8 );
- //VID
- printProgStr(PSTR("\r\nVendor ID:\t\t"));
- print_hex( buf.idVendor, 16 );
- //PID
- printProgStr(PSTR("\r\nProduct ID:\t\t"));
- print_hex( buf.idProduct, 16 );
- //Revision
- printProgStr(PSTR("\r\nRevision ID:\t\t"));
- print_hex( buf.bcdDevice, 16 );
- //Mfg.string
- printProgStr (PSTR("\r\nMfg.string index:\t"));
- print_hex( buf.iManufacturer, 8 );
- getstrdescr( addr, buf.iManufacturer );
- //Prod.string
- printProgStr(PSTR("\r\nProd.string index:\t"));
- print_hex( buf.iProduct, 8 );
- //printProgStr( str_cont );
- getstrdescr( addr, buf.iProduct );
- //Serial number string
- printProgStr(PSTR("\r\nSerial number index:\t"));
- print_hex( buf.iSerialNumber, 8 );
- //printProgStr( str_cont );
- getstrdescr( addr, buf.iSerialNumber );
- //Number of configurations
- printProgStr(PSTR("\r\nNumber of conf.:\t"));
- print_hex( buf.bNumConfigurations, 8 );
- return( buf.bNumConfigurations );
-}
-/* Get string descriptor. Takes device address and string index */
-byte getstrdescr( byte addr, byte idx )
-{
- char buf[ BUFSIZE ];
- byte rcode;
- byte length;
- byte i;
- unsigned int langid;
- if( idx == 0 ) { //don't try to get index zero
- return( 0 );
- }
- rcode = Usb.getStrDescr( addr, 0, 1, 0, 0, buf ); //get language table length
- if( rcode ) {
- printProgStr(PSTR("\r\nError retrieving LangID table length"));
- return( rcode );
- }
- length = buf[ 0 ]; //length is the first byte
- rcode = Usb.getStrDescr( addr, 0, length, 0, 0, buf ); //get language table
- if( rcode ) {
- printProgStr(PSTR("\r\nError retrieving LangID table"));
- return( rcode );
- }
- HIBYTE( langid ) = buf[ 3 ]; //get first langid
- LOBYTE( langid ) = buf[ 2 ]; //bytes are swapped to account for endiannes
- //printProgStr(PSTR("\r\nLanguage ID: "));
- //print_hex( langid, 16 );
- rcode = Usb.getStrDescr( addr, 0, 1, idx, langid, buf );
- if( rcode ) {
- printProgStr(PSTR("\r\nError retrieving string length"));
- return( rcode );
- }
- length = ( buf[ 0 ] < 254 ? buf[ 0 ] : 254 );
- printProgStr(PSTR(" Length: "));
- Serial.print( length, DEC );
- rcode = Usb.getStrDescr( addr, 0, length, idx, langid, buf );
- if( rcode ) {
- printProgStr(PSTR("\r\nError retrieveing string"));
- return( rcode );
- }
- printProgStr(PSTR(" Contents: "));
- for( i = 2; i < length; i+=2 ) {
- Serial.print( buf[ i ] );
- }
- return( idx );
-}
-/* Returns string to class name */
-const char* classname_parse( byte class_number )
-{
- switch( class_number ) {
- case 0x00:
- return PSTR(" Use class information in the Interface Descriptor");
- case 0x01:
- return PSTR(" Audio");
- case 0x02:
- return PSTR(" Communications and CDC Control");
- case 0x03:
- return PSTR(" HID (Human Interface Device)");
- case 0x05:
- return PSTR(" Physical");
- case 0x06:
- return PSTR(" Image");
- case 0x07:
- return PSTR(" Printer");
- case 0x08:
- return PSTR(" Mass Storage");
- case 0x09:
- return PSTR(" Hub");
- case 0x0a:
- return PSTR(" CDC-Data");
- case 0x0b:
- return PSTR(" Smart Card");
- case 0x0d:
- return PSTR(" Content Security");
- case 0x0e:
- return PSTR(" Video");
- case 0x0f:
- return PSTR(" Personal Healthcare");
- case 0xdc:
- return PSTR("Diagnostic Device");
- case 0xe0:
- return PSTR(" Wireless Controller");
- case 0xef:
- return PSTR(" Miscellaneous");
- case 0xfe:
- return PSTR(" Application Specific");
- case 0xff:
- return PSTR(" Vendor Specific");
- default:
- return unk_msg;
- }//switch( class_number
-}
-/* Getting configuration descriptor */
-byte getconfdescr( byte addr, byte conf )
-{
- char buf[ BUFSIZE ];
- char* buf_ptr = buf;
- byte rcode;
- byte descr_length;
- byte descr_type;
- unsigned int total_length;
- printProgStr(PSTR("\r\n\nConfiguration number "));
- Serial.print( conf, HEX );
- rcode = Usb.getConfDescr( addr, 0, 4, conf, buf ); //get total length
- if( rcode ) {
- printProgStr(PSTR("Error retrieving configuration length. Error code "));
- Serial.println( rcode, HEX );
- return( 0 );
- }//if( rcode
- LOBYTE( total_length ) = buf[ 2 ];
- HIBYTE( total_length ) = buf[ 3 ];
- printProgStr(PSTR("\r\nTotal configuration length: "));
- Serial.print( total_length, DEC );
- printProgStr(PSTR(" bytes"));
- if( total_length > BUFSIZE ) { //check if total length is larger than buffer
- printProgStr(PSTR("Total length truncated to "));
- Serial.print( BUFSIZE, DEC);
- printProgStr(PSTR("bytes"));
- total_length = BUFSIZE;
- }
- rcode = Usb.getConfDescr( addr, 0, total_length, conf, buf ); //get the whole descriptor
- while( buf_ptr < buf + total_length ) { //parsing descriptors
- descr_length = *( buf_ptr );
- descr_type = *( buf_ptr + 1 );
- switch( descr_type ) {
- case( USB_DESCRIPTOR_CONFIGURATION ):
- printconfdescr( buf_ptr );
- break;
- case( USB_DESCRIPTOR_INTERFACE ):
- printintfdescr( buf_ptr );
- break;
- case( USB_DESCRIPTOR_ENDPOINT ):
- printepdescr( buf_ptr );
- break;
- case( HID_DESCRIPTOR_HID ):
- printhid_descr( buf_ptr );
- break;
- default:
- printunkdescr( buf_ptr );
- break;
- }//switch( descr_type
- Serial.println("");
- buf_ptr = ( buf_ptr + descr_length ); //advance buffer pointer
- }//while( buf_ptr <=...
- return( 0 );
-}
-/* function to print configuration descriptor */
-void printconfdescr( char* descr_ptr )
-{
- USB_CONFIGURATION_DESCRIPTOR* conf_ptr = ( USB_CONFIGURATION_DESCRIPTOR* )descr_ptr;
- uint8_t tmpbyte;
- printProgStr(PSTR("\r\n\nConfiguration descriptor:"));
- printProgStr(PSTR("\r\nTotal length:\t\t"));
- print_hex( conf_ptr->wTotalLength, 16 );
- printProgStr(PSTR("\r\nNumber of interfaces:\t"));
- print_hex( conf_ptr->bNumInterfaces, 8 );
- printProgStr(PSTR("\r\nConfiguration value:\t"));
- print_hex( conf_ptr->bConfigurationValue, 8 );
- printProgStr(PSTR("\r\nConfiguration string:\t"));
- tmpbyte = conf_ptr->iConfiguration;
- print_hex( tmpbyte, 8 );
- getstrdescr( DEVADDR, tmpbyte );
- printProgStr(PSTR("\r\nAttributes:\t\t"));
- tmpbyte = conf_ptr->bmAttributes;
- print_hex( tmpbyte, 8 );
- if( tmpbyte & 0x40 ) { //D6
- printProgStr(PSTR(" Self-powered"));
- }
- if( tmpbyte & 0x20 ) { //D5
- printProgStr(PSTR(" Remote Wakeup"));
- }
- printProgStr(PSTR("\r\nMax.power:\t\t"));
- tmpbyte = conf_ptr->bMaxPower;
- print_hex( tmpbyte, 8 );
- printProgStr(PSTR(" "));
- Serial.print(( tmpbyte * 2 ), DEC);
- printProgStr(PSTR("ma"));
- return;
-}
-/* function to print interface descriptor */
-void printintfdescr( char* descr_ptr )
-{
- USB_INTERFACE_DESCRIPTOR* intf_ptr = ( USB_INTERFACE_DESCRIPTOR* )descr_ptr;
- uint8_t tmpbyte;
- printProgStr(PSTR("\r\nInterface descriptor:"));
- printProgStr(PSTR("\r\nInterface number:\t"));
- print_hex( intf_ptr->bInterfaceNumber, 8 );
- printProgStr(PSTR("\r\nAlternate setting:\t"));
- print_hex( intf_ptr->bAlternateSetting, 8 );
- printProgStr(PSTR("\r\nEndpoints:\t\t"));
- print_hex( intf_ptr->bNumEndpoints, 8 );
- printProgStr( class_str );
- tmpbyte = intf_ptr->bInterfaceClass;
- print_hex( tmpbyte, 8 );
- printProgStr(classname_parse( tmpbyte ));
- printProgStr( subclass_str );
- print_hex( intf_ptr->bInterfaceSubClass, 8 );
- printProgStr( protocol_str );
- print_hex( intf_ptr->bInterfaceProtocol, 8 );
- printProgStr(PSTR("\r\nInterface string:\t"));
- tmpbyte = intf_ptr->iInterface;
- print_hex( tmpbyte, 8 );
- getstrdescr( DEVADDR, tmpbyte );
- return;
-}
-/* function to print endpoint descriptor */
-void printepdescr( char* descr_ptr )
-{
- USB_ENDPOINT_DESCRIPTOR* ep_ptr = ( USB_ENDPOINT_DESCRIPTOR* )descr_ptr;
- uint8_t tmpbyte;
- printProgStr(PSTR("\r\nEndpoint descriptor:"));
- printProgStr(PSTR("\r\nEndpoint address:\t"));
- tmpbyte = ep_ptr->bEndpointAddress;
- print_hex( tmpbyte & 0x0f, 8 );
- printProgStr(PSTR(" Direction: "));
- ( tmpbyte & 0x80 ) ? printProgStr(PSTR("IN")) : printProgStr(PSTR("OUT"));
- printProgStr(PSTR("\r\nAttributes:\t\t"));
- tmpbyte = ep_ptr->bmAttributes;
- print_hex( tmpbyte, 8 );
- printProgStr(PSTR(" Transfer type: "));
- printProgStr((char*)pgm_read_word(&transfer_types[(tmpbyte & 0x03)]));
- if(( tmpbyte & 0x03 ) == 1 ) { //Isochronous Transfer
- printProgStr(PSTR(", Sync Type: "));
- printProgStr((char*)pgm_read_word(&sync_types[(tmpbyte & 0x0c)]));
- printProgStr(PSTR(", Usage Type: "));
- printProgStr((char*)pgm_read_word(&usage_types[(tmpbyte & 0x30)]));
- }//if( tmpbyte & 0x01
- printProgStr( maxpktsize_str );
- print_hex( ep_ptr->wMaxPacketSize, 16 );
- printProgStr(PSTR("\r\nPolling interval:\t"));
- tmpbyte = ep_ptr->bInterval;
- print_hex( tmpbyte, 8 );
- printProgStr(PSTR(" "));
- Serial.print( tmpbyte, DEC );
- printProgStr(PSTR(" ms"));
- return;
-}
-/* function to print HID descriptor */
-void printhid_descr( char* descr_ptr )
-{
- PARSE pf = &HIDreport_parse;
- USB_HID_DESCRIPTOR* hid_ptr = ( USB_HID_DESCRIPTOR* )descr_ptr;
- uint8_t tmpbyte;
- /**/
- printProgStr(PSTR("\r\nHID descriptor:"));
- printProgStr(PSTR("\r\nDescriptor length:\t"));
- tmpbyte = hid_ptr->bLength;
- print_hex( tmpbyte, 8 );
- printProgStr(PSTR(" "));
- Serial.print( tmpbyte, DEC );
- printProgStr(PSTR(" bytes"));
- printProgStr(PSTR("\r\nHID version:\t\t"));
- Serial.print(( HIBYTE( hid_ptr->bcdHID )), HEX );
- Serial.print(".");
- Serial.print(( LOBYTE( hid_ptr->bcdHID )), HEX );
- tmpbyte = hid_ptr->bCountryCode;
- printProgStr(PSTR("\r\nCountry Code:\t\t"));
- Serial.print( tmpbyte, DEC );
- printProgStr(PSTR(" "));
- ( tmpbyte > 35 ) ? printProgStr(PSTR("Reserved")) : printProgStr((char*)pgm_read_word(&HID_Country_Codes[ tmpbyte ]));
- tmpbyte = hid_ptr->bNumDescriptors;
- printProgStr(PSTR("\r\nClass Descriptors:\t"));
- Serial.print( tmpbyte, DEC );
- //Printing class descriptors
- descr_ptr += 6; //advance buffer pointer
- for( uint8_t i = 0; i < tmpbyte; i++ ) {
- uint8_t tmpdata;
- HID_CLASS_DESCRIPTOR* hidclass_ptr = ( HID_CLASS_DESCRIPTOR* )descr_ptr;
- tmpdata = hidclass_ptr->bDescriptorType;
- printProgStr(PSTR("\r\nClass Descriptor Type:\t"));
- Serial.print( tmpdata, HEX );
- if(( tmpdata < 0x21 ) || ( tmpdata > 0x2f )) {
- printProgStr(PSTR(" Invalid"));
- }
- switch( tmpdata ) {
- case 0x21:
- printProgStr(PSTR(" HID"));
- break;
- case 0x22:
- printProgStr(PSTR(" Report"));
- break;
- case 0x23:
- printProgStr(PSTR(" Physical"));
- break;
- default:
- printProgStr(PSTR(" Reserved"));
- break;
- }//switch( tmpdata
- printProgStr(PSTR("\r\nClass Descriptor Length:"));
- Serial.print( hidclass_ptr->wDescriptorLength );
- printProgStr(PSTR(" bytes"));
- printProgStr(PSTR("\r\n\nHID report descriptor:\r\n"));
- getReportDescr( DEVADDR, 0 , hidclass_ptr->wDescriptorLength, pf, USB_NAK_LIMIT );
- descr_ptr += 3; //advance to the next record
- }//for( uint8_t i=...
- return;
-}
-/*function to print unknown descriptor */
-void printunkdescr( char* descr_ptr )
-{
- byte length = *descr_ptr;
- byte i;
- printProgStr(PSTR("\r\nUnknown descriptor:"));
- printProgStr(PSTR("Length:\t\t"));
- print_hex( *descr_ptr, 8 );
- printProgStr(PSTR("\r\nType:\t\t"));
- print_hex( *(descr_ptr + 1 ), 8 );
- printProgStr(PSTR("\r\nContents:\t"));
- descr_ptr += 2;
- for( i = 0; i < length; i++ ) {
- print_hex( *descr_ptr, 8 );
- descr_ptr++;
- }
-}
-/* Control-IN transfer with callback. Sets address, endpoint, fills control packet with necessary data, dispatches control packet, and initiates bulk IN transfer */
-/* Control, data, and setup stages combined from standard USB library to be able to read large data blocks. Restricted to control-IN transfers with data stage */
-/* data read and MAX3421E RECV FIFO buffer release shall be performed by parse_func callback */
-/* return codes: */
-/* 00 = success */
-/* 01-0f = non-zero HRSLT */
-byte ctrlXfer( byte addr, byte ep, byte bmReqType, byte bRequest, byte wValLo, byte wValHi, unsigned int wInd, uint16_t nbytes, PARSE parse_func, uint16_t nak_limit = USB_NAK_LIMIT )
-{
- byte rcode;
- SETUP_PKT sp;
- EP_RECORD* ep_rec = Usb.getDevTableEntry( addr, ep );
- byte pktsize;
- byte maxpktsize = ep_rec->MaxPktSize;
- unsigned int xfrlen = 0;
- /**/
- Max.regWr( rPERADDR, addr ); //set peripheral address
- /* fill in setup packet */
- sp.ReqType_u.bmRequestType = bmReqType;
- sp.bRequest = bRequest;
- sp.wVal_u.wValueLo = wValLo;
- sp.wVal_u.wValueHi = wValHi;
- sp.wIndex = wInd;
- sp.wLength = nbytes;
- Max.bytesWr( rSUDFIFO, 8, ( char *)&sp ); //transfer to setup packet FIFO
- rcode = Usb.dispatchPkt( tokSETUP, ep, nak_limit ); //dispatch packet
- //Serial.println("Setup packet"); //DEBUG
- if( rcode ) { //return HRSLT if not zero
- printProgStr(PSTR("\r\nSetup packet error: "));
- Serial.print( rcode, HEX );
- return( rcode );
- }
- /* Data stage */
- //ep_rec->rcvToggle = bmRCVTOG1;
- Max.regWr( rHCTL, bmRCVTOG1 ); //set toggle
- while( 1 ) { //exited by break
- /* request data */
- rcode = Usb.dispatchPkt( tokIN, ep, nak_limit );
- if( rcode ) {
- printProgStr(PSTR("\r\nData Stage Error: "));
- Serial.print( rcode, HEX );
- return( rcode );
- }
- /* check for RCVDAVIRQ and generate error if not present */
- /* the only case when absense of RCVDAVIRQ makes sense is when toggle error occured. Need to add handling for that */
- if(( Max.regRd( rHIRQ ) & bmRCVDAVIRQ ) == 0 ) {
- printProgStr(PSTR("\r\nData Toggle error."));
- return ( 0xf0 );
- }
- pktsize = Max.regRd( rRCVBC ); //get received bytes count
- parse_func( pktsize ); //call parse function. Parse is expected to read the FIFO completely
- Max.regWr( rHIRQ, bmRCVDAVIRQ ); // Clear the IRQ & free the buffer
- xfrlen += pktsize; // add this packet's byte count to total transfer length
- /* The transfer is complete under two conditions: */
- /* 1. The device sent a short packet (L.T. maxPacketSize) */
- /* 2. 'nbytes' have been transferred. */
- if (( pktsize < maxpktsize ) || (xfrlen >= nbytes )) { // have we transferred 'nbytes' bytes?
- break;
- }
- }//while( 1 )
- rcode = Usb.dispatchPkt( tokOUTHS, ep, nak_limit );
- if( rcode ) { //return error
- printProgStr(PSTR("Status packet error: "));
- Serial.print( rcode, HEX );
- }
- return( rcode );
-}
-/* Parses bitfields in main items */
-void print_mainbitfield( uint8_t byte_toparse )
-{
- ( byte_toparse & 0x01 ) ? printProgStr(PSTR("Constant,")) : printProgStr(PSTR("Data,")); //bit 0
- ( byte_toparse & 0x02 ) ? printProgStr(PSTR("Variable,")) : printProgStr(PSTR("Array,")); //bit 1
- ( byte_toparse & 0x04 ) ? printProgStr(PSTR("Relative,")) : printProgStr(PSTR("Absolute,")); //...
- ( byte_toparse & 0x08 ) ? printProgStr(PSTR("Wrap,")) : printProgStr(PSTR("No Wrap,"));
- ( byte_toparse & 0x10 ) ? printProgStr(PSTR("Non Linear,")) : printProgStr(PSTR("Linear,"));
- ( byte_toparse & 0x20 ) ? printProgStr(PSTR("No preferred,")) : printProgStr(PSTR("Preferred State,"));
- ( byte_toparse & 0x40 ) ? printProgStr(PSTR("Null State,")) : printProgStr(PSTR("No Null Position,")); //bit 6
- ( byte_toparse & 0x40 ) ? printProgStr(PSTR("Volatile( ignore for Input),")) : printProgStr(PSTR("Non-volatile(Ignore for Input),")); //bit 7
-}
-/* HID Report Desriptor Parser Callback */
-/* called repeatedly from Control transfer function */
-void HIDreport_parse( uint8_t pkt_size )
-{
-#define B_SIZE 0x03 //bSize bitmask
-#define B_TYPE 0x0c //bType bitmask
-#define B_TAG 0xf0 //bTag bitmask
- /* parser states */
- enum STATE { ITEM_START, DATA_PARSE };
- static STATE state = ITEM_START;
- static uint8_t databytes_left = 0;
- static uint8_t prefix; //item prefix - type and tag
- uint8_t byte_toparse;
- uint8_t bType;
- uint8_t tmpbyte;
- /**/
- while( 1 ) {
- if( pkt_size ) {
- byte_toparse = Max.regRd( rRCVFIFO ); //read a byte from FIFO
- pkt_size--;
- }
- else {
- return; //all bytes read
- }
- switch( state ) {
- case ITEM_START: //start of the record
- prefix = byte_toparse >>2; //store prefix for databyte parsing
- tmpbyte = byte_toparse & B_SIZE;
- /* get item length */
- ( tmpbyte == 0x03 ) ? databytes_left = 4 : databytes_left = tmpbyte;
- if( databytes_left ) {
- state = DATA_PARSE; //read bytes after prefix
- }
- printProgStr(PSTR("\r\nLength: "));
- Serial.print( databytes_left, DEC );
- /* get item type */
- bType = ( byte_toparse & B_TYPE ) >>2;
- printProgStr(PSTR(" Type: "));
- printProgStr((char*)pgm_read_word(&btypes[ bType ]));
- /* get item tag */
- printProgStr(PSTR("\t\tTag: "));
- tmpbyte = ( byte_toparse & B_TAG ) >>4 ;
- switch( bType ) {
- case 0: //Main
- if( tmpbyte < 0x08 ) {
- printProgStr(PSTR("Invalid Tag"));
- }
- else if( tmpbyte > 0x0c ) {
- printProgStr( reserved_msg );
- }
- else {
- printProgStr((char*)pgm_read_word(&maintags[ tmpbyte - 8 /* & 0x03 */]));
- //Serial.print("Byte: ");
- //Serial.println( tmpbyte, HEX );
- }
- break;//case 0 Main
- case 1: //Global
- ( tmpbyte > 0x0b ) ? printProgStr( reserved_msg ) : printProgStr((char*)pgm_read_word(&globaltags[ tmpbyte ]));
- break;//case 1 Global
- case 2: //Local
- ( tmpbyte > 0x0a ) ? printProgStr( reserved_msg ) : printProgStr((char*)pgm_read_word(&localtags[ tmpbyte ]));
- break;//case 2 Local
- default:
- break;
- }//switch( bType...
- break;//case ITEM_START
- case DATA_PARSE:
- switch( prefix ) {
- case 0x20: //Main Input
- case 0x24: //Main Output
- case 0x2c: //Main Feature
- /* todo: add parsing 8th bit */
- print_mainbitfield( byte_toparse );
- break;
- case 0x28: //Main Collection
- if(( byte_toparse > 0x06 ) && ( byte_toparse < 0x80 )) {
- printProgStr( reserved_msg );
- }
- else if(( byte_toparse > 0x7f ) && ( byte_toparse <= 0xff )) {
- printProgStr(PSTR("Vendor-defined"));
- }
- else {
- printProgStr((char*)pgm_read_word(&collections[ byte_toparse ]));
- }
- break;//case 0x28 Main Collection
- //case 0x30: //Main End Collection
- case 0x01: //Global Usage Page
- switch( byte_toparse ) { //see HID Usage Tables doc v.1.12 page 14
- case 0x00:
- case 0x01:
- case 0x02:
- case 0x03:
- case 0x04:
- case 0x05:
- case 0x06:
- case 0x07:
- case 0x08:
- case 0x09:
- case 0x0a:
- case 0x0b:
- case 0x0c:
- case 0x0d:
- case 0x0e:
- case 0x0f:
- case 0x10:
- printProgStr((char*)pgm_read_word(&usage_pages[ byte_toparse ]));
- break;
- case 0x14:
- printProgStr(PSTR("Alphanumeric Display"));
- break;
- case 0x40:
- printProgStr(PSTR("Medical Instruments"));
- break;
- case 0x80:
- case 0x81:
- case 0x82:
- case 0x83:
- printProgStr(PSTR("Monitor page"));
- break;
- case 0x84:
- case 0x85:
- case 0x86:
- case 0x87:
- printProgStr(PSTR("Power page"));
- break;
- case 0x8c:
- printProgStr(PSTR("Bar Code Scanner page"));
- break;
- case 0x8d:
- printProgStr(PSTR("Scale page"));
- break;
- case 0x8e:
- printProgStr(PSTR("Magnetic Stripe Reading (MSR) Devices"));
- break;
- case 0x8f:
- printProgStr(PSTR("Reserved Point of Sale pages"));
- break;
- case 0x90:
- printProgStr(PSTR("Camera Control Page"));
- break;
- case 0x91:
- printProgStr(PSTR("Arcade Page"));
- break;
- default:
-// printProgStr(PSTR("Data: "));
-// print_hex( byte_toparse, 8 );
- //databytes_left--;
- break;
- }//switch case 0x01: //Global Usage Page
- }//switch( prefix ...
- printProgStr(PSTR(" Data: "));
- print_hex( byte_toparse, 8 );
- databytes_left--;
- if( !databytes_left ) {
- state = ITEM_START;
- }
- break;
- }//switch( state...
- }//while( 1 ...
-}
-/* prints hex numbers with leading zeroes */
-// copyright, Peter H Anderson, Baltimore, MD, Nov, '07
-// source: http://www.phanderson.com/arduino/arduino_display.html
-void print_hex(int v, int num_places)
-{
- int mask=0, n, num_nibbles, digit;
-
- for (n=1; n<=num_places; n++) {
- mask = (mask << 1) | 0x0001;
- }
- v = v & mask; // truncate v to specified number of places
-
- num_nibbles = num_places / 4;
- if ((num_places % 4) != 0) {
- ++num_nibbles;
- }
- do {
- digit = ((v >> (num_nibbles-1) * 4)) & 0x0f;
- Serial.print(digit, HEX);
- }
- while(--num_nibbles);
-}
-
-/* given a PROGMEM string, use Serial.print() to send it out */
-/* Some non-intuitive casting necessary: */
-/* printProgStr(PSTR("Func.Mode:\t0x")); */
-/* printProgStr((char*)pgm_read_word(&mtpopNames[(op & 0xFF)])); */
-void printProgStr(const char* str)
-{
- if(!str) {
- return;
- }
- char c;
- while((c = pgm_read_byte(str++))) {
- Serial.print(c,BYTE);
- }
- return;
-}