Sending structs as reports

General discussions about V-USB, our firmware-only implementation of a low speed USB device on Atmel's AVR microcontrollers
Post Reply
xSmurf
Posts: 7
Joined: Sat Jan 24, 2009 6:18 am

Sending structs as reports

Post by xSmurf » Sat Jan 24, 2009 6:22 am

Hello guys, first thanks for this excellent piece of code!

I'm trying to send a struct as a report. You can see the main part of the code right now. I can send straight bytes no problem. I was able to send two bytes from a buffer and reconstruct it in a struct as a uint16_t on the host side. How ever, when I pass along the pointer for the struct, the data on the host site is garbage (never changes). The struct is malloc'ed so it's definitely available at all time. I really don't get this 0.o

Code: Select all

   typedef struct t_configHolder {
      uint8_t tempWanted;
      uint8_t selectMode;
      uint8_t lowHeatDifference;
      uint8_t saverDifference;
      uint8_t saverEnabled;
      uint8_t lightDarkThreshold;
      int8_t saverThreshold;
   }configHolder;


usbMsgLen_t usbFunctionSetup(uint8_t data[8])
{
   usbRequest_t   *rq = (usbRequest_t *)((void *)data);
   
   /* HID class request */
   if ((rq->bmRequestType & USBRQ_TYPE_MASK) == USBRQ_TYPE_CLASS) {
      if (rq->bRequest == USBRQ_HID_GET_REPORT) {
         /* wValue: ReportType (highbyte), ReportID (lowbyte) */
         switch (rq->wValue.bytes[0]) {
            case USB_REPORTID_CALENDAR:
               bytesRemaining = EEPROM_CALENDAR_SIZE;
               currentAddress = (uint16_t) &EECalendar;
               return USB_NO_MSG;   /* use usbFunctionRead() to obtain data */
            break;
            case USB_REPORTID_STATUS:
               usbMsgPtr = (uint8_t*)&systemStatus;
               return sizeof(t_statusHolder);
            break;
            case USB_REPORTID_CONFIG:
               usbMsgPtr = (uint8_t *)&systemConfig;
               return sizeof(t_configHolder);
            break;
         }
      }
   } else {
      /* ignore vendor type requests, we don't use any */
   }
   
   return 0;
}


Thanks

Guest

Post by Guest » Sat Jan 24, 2009 5:51 pm

Oh yeah I forgot to post the HID descriptor, if it's any help...


Code: Select all

Low Speed device @ 8 (0x1D130000): .............................................   Composite device: "DigiTherm"
    Device Descriptor   
        Descriptor Version Number:   0x0110
        Device Class:   0   (Composite)
        Device Subclass:   0
        Device Protocol:   0
        Device MaxPacketSize:   8
        Device VendorID/ProductID:   0x16C0/0x05DF   (unknown vendor)
        Device Version Number:   0x0100
        Number of Configurations:   1
        Manufacturer String:   1 "mlalonde.net"
        Product String:   2 "DigiTherm"
        Serial Number String:   0 (none)
    Configuration Descriptor   
        Length (and contents):   34
        Number of Interfaces:   1
        Configuration Value:   1
        Attributes:   0x40 (self-powered)
        MaxPower:   20 ma
        Interface #0 - HID   
            Alternate Setting   0
            Number of Endpoints   1
            Interface Class:   3   (HID)
            Interface Subclass;   0
            Interface Protocol:   0
            HID Descriptor   
                Descriptor Version Number:   0x0101
                Country Code:   0
                Descriptor Count:   1
                Descriptor 1   
                    Type:   0x22  (Report Descriptor)
                    Length (and contents):   24
                    Parsed Report Descriptor:   
                          Usage Page    (65280)
                          Usage 1 (0x1)   
                              Collection (Application)   
                                ReportID................    (2) 
                                Logical Minimum.........    (0) 
                                Logical Maximum.........    (255) 
                                Report Size.............    (8) 
                                Report Count............    (7) 
                                Usage 0 (0x0)   
                                Feature.................   (Data, Variable, Absolute, No Wrap, Linear, Preferred State, No Null Position, Nonvolatile, Buffered bytes)
                              End Collection     
            Endpoint 0x81 - Interrupt Input   
                Address:   0x81  (IN)
                Attributes:   0x03  (Interrupt no synchronization data endpoint)
                Max Packet Size:   8
                Polling Interval:   100 ms

xSmurf
Posts: 7
Joined: Sat Jan 24, 2009 6:18 am

Post by xSmurf » Sat Jan 24, 2009 7:54 pm

Well, just scrap that I've been an idiot all this time. I had forgotten about a routine which reads back data from the eeprom into the struct! That's where my "random" data came from!

Post Reply