Einzelnen Beitrag anzeigen

pcsquirrel

Registriert seit: 19. Okt 2006
1 Beiträge
 
#3

Re: Starthilfe zu JvHidController-Komponente

  Alt 28. Feb 2010, 17:43
hallo,

ich mach das ganze auch gerade. allerdings mit erfolg .

also als tip kann ich der geben, daß du Get bzw. SetFeatureReport nehmen mußt, wenn die mittels FeatureReport kommunizieren willst. was du laut deinem Reportdescriptor ja vor hast.
meine sourcen sind sehr unaufgeräumt als bringts nix wenn ich sie hier poste.

Mein ReportDeskriptor:

Code:
PROGMEM char usbHidReportDescriptor[33] = {   
    0x06, 0x00, 0xff,             // USAGE_PAGE (Generic Desktop)
    0x09, 0x01,                   // USAGE (Vendor Usage 1)
    0xa1, 0x01,                   // COLLECTION (Application)
    0x15, 0x00,                   //   LOGICAL_MINIMUM (0)
    0x26, 0xff, 0x00,             //   LOGICAL_MAXIMUM (255)
    0x75, 0x08,                   //   REPORT_SIZE (8)
    0x85, 0x01,                   //   REPORT_ID (1)
    0x95, 0x02,                   //   REPORT_COUNT (2)
    0x09, 0x00,                   //   USAGE (Undefined)
    0xb2, 0x02, 0x01,             //   FEATURE (Data,Var,Abs,Buf)
    0x85, 0x02,                   //   REPORT_ID (2)
    0x95, 0x01,                   //   REPORT_COUNT (1)
    0x09, 0x00,                   //   USAGE (Undefined)
    0xb2, 0x02, 0x01,             //   FEATURE (Data,Var,Abs,Buf)
    0xc0                           // END_COLLECTION
};
Meine USBSetupFunction:

(Achtung ich habe REport mit weniger als 9 Byte, also kann man es in der Setuptfunktion machen. wenns mehr sind, so wie bei dir mußte du aus der Setupfunktion es an die USBFunctionRead weiterleiten - das ist aber beim OBDEV Sample gut beschrieben)
Code:
uchar  usbFunctionSetup(uchar data[8])
{
static uchar   replyBuf[3];
usbRequest_t   *rq = (void *)data;

    usbMsgPtr = replyBuf;
    DBG1(0x49, &rq->bmRequestType, 1);  /* debug output: print our request */
    if((rq->bmRequestType & USBRQ_TYPE_MASK) == USBRQ_TYPE_CLASS){    /* class request type */
        DBG1(0x50, &rq->bRequest, 1);  /* debug output: print our request */
        if(rq->bRequest == USBRQ_HID_GET_REPORT){  /* wValue: ReportType (highbyte), ReportID (lowbyte) */
            if(rq->wValue.bytes[0] == 1){   /* ReportID 1 */
                replyBuf[0] = rq->wValue.bytes[0];
                replyBuf[1] = LOWBYTE(ledWord);
                replyBuf[2] = HIGHBYTE(ledWord);
                return 3;
            }else if(rq->wValue.bytes[0] == 2){ /* ReportID 2 */
                replyBuf[0] = rq->wValue.bytes[0];
                replyBuf[1] = PINC;
      return 2;
            }
        }else if(rq->bRequest == USBRQ_HID_SET_REPORT){
            if(rq->wValue.bytes[0] == 1){   /* ReportID "SET ADDRESS" */
                usbWriteLen = 0xff;        /* indicates "address" */
                return 0xff;               /* use usbFunctionWrite() */
            }else if(rq->wValue.bytes[0] == 2){ /* ReportID "SET 128 bytes block" */
                usbWriteLen = 129;
                return 0xff;               /* use usbFunctionWrite() */
            }
        }
    }else{
        if(data[1] == 0){       /* ECHO, for testing */
            replyBuf[0] = data[2];
            replyBuf[1] = data[3];
            return 2;
        }
    }
    return 0;
}


/* Writing to the EEPROM may take 7 * 8.5ms = 59.9ms which is slightly more
 * than the allowable <50ms. We usually get away with that.
 */
uchar  usbFunctionWrite(uchar *data, uchar len)
{
    if(usbWriteLen == 0)
        return 1;
    if(usbWriteLen == 0xff){    /* expecting address */
        usbWriteLen = 0;
        if(len < 3)
            return 0xff;       /* stall */
        LOWBYTE(ledWord) = data[1];
        HIGHBYTE(ledWord) = data[2];
        return 1;
    }
    if(usbWriteLen == 129){ /* first byte is report ID */
        data++;
        len--;
        usbWriteLen--;
    }
    if(len > usbWriteLen)
        len = usbWriteLen;
    eeprom_write_block(data, (uchar *)0 + usbAddress, len);
    if(usbAddress < 2){
        codeEepromSize = eeprom_read_word(0);  /* refresh RAM copy of code size */
        if(codeEepromSize > sizeof(code.data))
            codeEepromSize = 0;
    }
    usbAddress += len;
    usbWriteLen -= len;
    return usbWriteLen == 0;
}
Und so wird aus delphi aufs device geschrieben:

Delphi-Quellcode:
  TLCD = packed record
    ID: byte;
    text: array[0..2] of char;
  end;

procedure TMainForm.Button4Click(Sender: TObject);
var
rep:TLCD;
i:integer;
begin
    rep.id:=1;
    rep.text[0] := char(32);
    rep.text[1] := char(0);
    CurrentDevice.SetFeature(rep,sizeOf(rep));

end;
Und so gelesen

Delphi-Quellcode:

procedure TMainForm.Button6Click(Sender: TObject);
var
rep:TLCD;
i:integer;
begin
  rep.ID := 1;
  rep.text[0] := char(0);
  CurrentDevice.GetFeature(rep, SIZEOF(rep));
  Button6.Caption := IntToStr(Integer(rep.text[0]));
end;
Nicht schön, aber ich hoffe es hilft.

p.c.squirrel
  Mit Zitat antworten Zitat