Forum Menu




 


Log in Problems?
New User? Sign Up!
AVR Freaks Forum Index

Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
Aviraj
PostPosted: Apr 17, 2012 - 09:00 AM
Newbie


Joined: Apr 17, 2012
Posts: 4


I am trying to make the Mister Gloves project from the cornell website:
https://courses.cit.cornell.edu/ee476/F ... index.html

I have completed the whole hardware part, and all the parts except for usb seem to be working fine. The problem is that the code got compiled perfectly but still the device isn't getting recognized on PC when i burn it on my uC. The codes are there on the site. Have used it as it is. I am using WinAVR Software. Also the uC used is ATMega16. I have tried using 16Mhz crystal and also the 12Mhz crystal. But it was of no use. I have already spent around 3 months working on this project and need to complete it in few days now. So plzzzz help... Sad
 
 View user's profile Send private message  
Reply with quote Back to top
Aviraj
PostPosted: Apr 17, 2012 - 11:16 AM
Newbie


Joined: Apr 17, 2012
Posts: 4


And btw... i havent used usb cable to interface with uC. I have just used normal usb header soldered to normal wires. Does it make any difference???
 
 View user's profile Send private message  
Reply with quote Back to top
dak664
PostPosted: Apr 17, 2012 - 12:09 PM
Posting Freak


Joined: Jun 15, 2008
Posts: 1755
Location: North Carolina USA

V-USB is pretty robust but that writeup says Windows failed to recognize their device until the wireless receiver was moved to another MCU. So I would suspect potential timing issues with other parts of the code as well; can you turn all of those off temporarily?
 
 View user's profile Send private message  
Reply with quote Back to top
Aviraj
PostPosted: Apr 17, 2012 - 04:48 PM
Newbie


Joined: Apr 17, 2012
Posts: 4


I will try that and tell about it then... Smile thnxs
Do u suspect using wire of any other kind than normal usb is creating problem??
 
 View user's profile Send private message  
Reply with quote Back to top
dak664
PostPosted: Apr 17, 2012 - 10:16 PM
Posting Freak


Joined: Jun 15, 2008
Posts: 1755
Location: North Carolina USA

Not sure what normal wire is but I pull 921600 baud ports off my motherboard with a half meter of ribbon cable that way.
 
 View user's profile Send private message  
Reply with quote Back to top
Aviraj
PostPosted: Apr 18, 2012 - 05:25 AM
Newbie


Joined: Apr 17, 2012
Posts: 4


i tried commenting the rest of the part and using the code but still the device ain't getting recognized.. Sad

Code:


/* Sean Chen (ssc88@cornell.edu)
 * Evan Levine (egl27@cornell.edu)
 * ECE4760 Final Project
 * Mister Gloves - A Wireless USB Gesture Input System
 * 5 May 2010
 */

/* Base Station USB */

/* Name: main.c
 * Project: HID-Test
 * Author: Christian Starkjohann
 * Creation Date: 2006-02-02
 * Tabsize: 4
 * Copyright: (c) 2006 by OBJECTIVE DEVELOPMENT Software GmbH
 * License: GNU GPL v2 (see License.txt) or proprietary (CommercialLicense.txt)
 * This Revision: $Id: main.c 299 2007-03-29 17:07:19Z cs $
 */

#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include <avr/wdt.h>

#include <util/delay.h>

#include <stdlib.h>

#include "usbdrv.h"
#include "oddebug.h"

uchar reportBufferK[8] = { 1, 0, 0, 0, 0, 0, 0, 0 }; // Keyboard report buffer
uchar reportBufferM[5] = { 2, 0, 0, 0, 0 }; // Mouse report buffer

// Key conversion table
char keyMapConversion[57] = { 0, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
      17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34,
      35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 51, 52, 53, 54,
      55, 56, 74, 75, 76, 77, 78 };

// Keyboard keys
#define KEY_A       4
#define KEY_B       5
#define KEY_C       6
#define KEY_D       7
#define KEY_E       8
#define KEY_F       9
#define KEY_G       10
#define KEY_H       11
#define KEY_I       12
#define KEY_J       13
#define KEY_K       14
#define KEY_L       15
#define KEY_M       16
#define KEY_N       17
#define KEY_O       18
#define KEY_P       19
#define KEY_Q       20   
#define KEY_R       21
#define KEY_S       22
#define KEY_T       23
#define KEY_U       24
#define KEY_V       25
#define KEY_W       26
#define KEY_X       27
#define KEY_Y       28
#define KEY_Z       29
#define KEY_1       30
#define KEY_2       31
#define KEY_3       32
#define KEY_4       33
#define KEY_5       34
#define KEY_6       35
#define KEY_7       36
#define KEY_8       37
#define KEY_9       38
#define KEY_0       39
#define KEY_PGUP 75
#define KEY_PGDN 78
#define KEY_HOME 74
#define   KEY_DEL 76
#define KEY_SPACE 44
#define KEY_BACK 42
#define KEY_PER 55
#define KEY_COMMA 54
#define KEY_SEMI 51
#define KEY_ENTER 40
#define KEY_ESC 41
#define KEY_TAB 43
#define KEY_LBRACKET 47
#define KEY_RBRACKET 48
#define KEY_SLASH 56
#define KEY_QUOTE 52
#define KEY_PLUS 46
#define KEY_MINUS 45
#define KEY_END 77
#define KEY_TILDE 53

char unlocked;

char keyMap[5][15] = { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 0,
      KEY_B, KEY_V, KEY_G, KEY_F, KEY_PGDN, KEY_C, KEY_D, KEY_END, KEY_X,
      KEY_S, KEY_ESC, KEY_Z, KEY_A, KEY_SPACE }, { 0, KEY_P, KEY_O, KEY_T,
      KEY_R, KEY_PGUP, KEY_I, KEY_E, KEY_HOME, KEY_U, KEY_W, KEY_DEL, KEY_Y,
      KEY_Q, KEY_BACK }, { 0, KEY_SLASH, KEY_PER, KEY_SEMI, KEY_L,
      KEY_LBRACKET, KEY_COMMA, KEY_K, KEY_RBRACKET, KEY_M, KEY_J, KEY_QUOTE,
      KEY_N, KEY_H, KEY_TAB }, { 0, KEY_6, KEY_7, KEY_1, KEY_2, KEY_PLUS,
      KEY_8, KEY_3, KEY_MINUS, KEY_9, KEY_4, KEY_TILDE, KEY_0, KEY_5,
      KEY_ENTER } };

char lastKey; // The last key pressed
char newKey; // The new key to be sent to the computer
char alreadySent = 1;

static uchar idleRate = 0;
//static uchar selectReport = 0; // 0 to send keyboard report, 1 to send mouse report

/* Initialize I/O Pins, Reset USB */
static void initIO() {
   uchar i, j;

   PORTD = 0xeb; // Activate pull-ups except on USB lines
   DDRD = 0x16; // All pins input except USB (-> USB reset)
   j = 0;
   while (--j) { // USB Reset by device only required on Watchdog Reset
      i = 0;
      while (--i)
         ; // Delay >10ms for USB reset
   }
   DDRD = 0x02; // Remove USB reset condition
}

/* Set Up Report Descriptors */
PROGMEM char usbHidReportDescriptor[95] = {
// Keyboard
      0x05, 0x01, // Usage Page (Generic Desktop)
      0x09, 0x06, // Usage (Keyboard)
      0xA1, 0x01, // Collection (Application)
      0x85, 0x01, // Report Id (1)
      0x05, 0x07, // Usage (Key Codes)
      0x19, 0xE0, // Usage Minimum (234)
      0x29, 0xE7, // Usage Maximum (231)
      0x15, 0x00, // Logical Minimum (0)
      0x25, 0x01, // Logical Maximum (1)
      0x75, 0x01, // Report Size (1)
      0x95, 0x08, // Report Coumt (8)
      0x81, 0x02, // Input (Data, Var, Abs)
      0x95, 0x06, // Report Count(6)
      0x75, 0x08, // Report Size (8)
      0x15, 0x00, // Logical Minimum (0)
      0x25, 0x65, // Logical Maximum (101)
      0x05, 0x07, // Usage Page (Key Codes)
      0x19, 0x00, // Usage Minimum (0)
      0x29, 0x65, // Usage Maximum (101)
      0x81, 0x00, // Input (Data, Array, Abs)
      0xC0, // End Collection
// Mouse
      0x05, 0x01, // Usage Page (Generic Desktop)
      0x09, 0x02, // Usage (Mouse)
      0xA1, 0x01, // Collection (Application)
      0x09, 0x01, // Usage (Pointer)
      0xA1, 0x00, // Collection (Physical)
      0x85, 0x02, // Report Id (2)
      0x05, 0x09, // Usage Page (Buttons)
      0x19, 0x01, // Usage Minimum (1)
      0x29, 0x03, // Usage Maximum (3)
      0x15, 0x00, // Logical Minimum (0)
      0x25, 0x01, // Logical Maximum (1)
      0x95, 0x03, // Report Count (3)
      0x75, 0x01, // Report Size (1)
      0x81, 0x02, // Input (Data, Var, Abs)
      0x95, 0x01, // Report Count (1)
      0x75, 0x05, // Report Size (5)
      0x81, 0x03, // Input (Const, Var, Abs)
      0x05, 0x01, // Usage Page (Generic Desktop)
      0x09, 0x30, // Usage (X)
      0x09, 0x31, // Usage (Y)
      0x09, 0x38, // Usage (Wheel)
      0x15, 0x81, // Logical Minimum (-127)
      0x25, 0x7F, // Logical Maximum (127)
      0x75, 0x08, // Report Size (8)
      0x95, 0x03, // Report Count (3)
      0x81, 0x06, // Input (Data, Var, Rel)
      0xC0, // End Collection
      0xC0, // End Collection
      };

uchar usbFunctionSetup(uchar data[8]) {
   usbRequest_t *rq = (void *) data;
   usbMsgPtr = reportBufferK;
   if ((rq->bmRequestType & USBRQ_TYPE_MASK) == USBRQ_TYPE_CLASS) {
      if (rq->bRequest == USBRQ_HID_GET_REPORT) {
         if (rq->wValue.bytes[0] == 1) {
            usbMsgPtr = reportBufferK;
            return sizeof(reportBufferK);
         } else if (rq->wValue.bytes[0] == 2) {
            usbMsgPtr = reportBufferM;
            return sizeof(reportBufferM);
         }
         return 0;
      } else if (rq->bRequest == USBRQ_HID_GET_IDLE) {
         usbMsgPtr = &idleRate;
         return 1;
      } else if (rq->bRequest == USBRQ_HID_SET_IDLE) {
         idleRate = rq->wValue.bytes[1];
      }

   }
   return 0;
}

/* Return the contact related to the requested key */
char getContact(char keyQuery) {
   for (int i = 0; i < 15; i++) {
      for (int j = 0; j < 5; j++) {
         if (keyMap[j][i] == keyQuery) {
            return i;
         }
      }
   }
   return 0;

}

/*static void buildReport() {

    // Check enable line from receiver MCU
   if (PIND & 0x80) {
      unlocked = 1;
   }

    // Do nothing if not unlocked
   if (unlocked) {

      char keyIndex = ((~PINA) & 0x7F);
      char thisKey = keyMapConversion[keyIndex];

      reportBufferM[2] = ~PINB;
      reportBufferM[3] = ~PINC;
      
      // If processing keyboard report
      if (~selectReport) {

         // Do not debounce arrow keys
         if (keyIndex == 58) {
            newKey = 79;

         } else if (keyIndex == 59) {

            newKey = 80;

         } else if (keyIndex == 60) {

            newKey = 81;

         } else if (keyIndex == 61) {

            newKey = 82;

           
         // Do not allow a key to be sent more than once within debounce timeout
         } else if ((getContact(thisKey) != getContact(lastKey)) && (thisKey
               != 0)) { // Different key
            newKey = thisKey;
            lastKey = thisKey;
            alreadySent = 1;
            TCNT1 = 0;
         } else if ((getContact(thisKey) == getContact(lastKey)) && (thisKey
               != 0) && alreadySent) { // Same key, timeout reached
            newKey = thisKey;
            alreadySent--;
         } else if ((getContact(thisKey) == getContact(lastKey)) && (thisKey
               != 0) && !alreadySent) { // Same key, timeout not reached yet
            newKey = 0;
         } else {
            newKey = thisKey;
         }

         reportBufferK[1] = ((~PIND) >> 5) & 0x07; // Modifier keys
         reportBufferK[2] = newKey; // Normal keys
         
      } else {
         reportBufferK[1] = 0;
         reportBufferK[2] = 0;
      }

      // Process mouse buttons, scrolling
      // Cursor mode
      if ((~PINA & 0x80) && (~PINA & 0x40)) {
         reportBufferM[1] = 0;

            // Scrolling
         if ((~PINA & 0x3F) == 1) { // Scroll up
            reportBufferM[4] = 1;
         } else if ((~PINA & 0x3F) == 2) { // Scroll down
            reportBufferM[4] = -1;
         } else {
            reportBufferM[4] = 0;
         }
         
        // Check mouse buttons
      } else if ((~PINA) & 0x80) { // Left click
         reportBufferM[1] = 1;
         reportBufferM[4] = 0;
      } else if ((~PINA) & 0x40) { // Right click
         reportBufferM[1] = 2;
         reportBufferM[4] = 0;
      } else {
         reportBufferM[1] = 0;
         reportBufferM[4] = 0;
      }

   } else { // If locked, clear everything just to be sure
      reportBufferM[1] = 0;
      reportBufferM[2] = 0;
      reportBufferM[3] = 0;
      reportBufferM[4] = 0;
      reportBufferK[1] = 0;
      reportBufferK[2] = 0;

   }

}*/

int main(void) {

   DDRA = 0x00;
   DDRB = 0x00;
   DDRC = 0x00;

   TCCR1B = 0x03; // Set prescaler of 64
   TIMSK |= (1 << OCIE1A) | (1 << OCIE1B); // Enable both compare interrupts
   OCR1A = 65535;
   OCR1B = 32768;

   wdt_enable(WDTO_2S);
   initIO();
   //initUART();
   odDebugInit();
   usbInit();
   sei();
   DBG1(0x00, 0, 0);

   for (;;) { // Alternate between sending keyboard/mouse reports

      wdt_reset();
      usbPoll();
      if (usbInterruptIsReady()) {
         /*buildReport(); // Set up mouse, keyboard buffers
         if (selectReport) {
            usbSetInterrupt(reportBufferM, sizeof(reportBufferM)); // Send mouse report
         } else {
            usbSetInterrupt(reportBufferK, sizeof(reportBufferK)); // Send keyboard report
         }
         selectReport = ~selectReport;*/
      }
   }
}

/* Debounce button timeout */
ISR(TIMER1_COMPA_vect) {
   lastKey = 0;
}

/* Debounce button timeout for spacebar, backspace */
ISR(TIMER1_COMPB_vect) {
   if ((lastKey == KEY_SPACE) || (lastKey == KEY_BACK)) {
      lastKey = 0;
   }
}
 
 View user's profile Send private message  
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT + 1 Hour
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2006 The PNphpBB Group
Credits