Post
by dima_hz » Fri May 14, 2010 5:04 pm
Hello everyone here. Nice work i have found here. I also have a little time and just tried something from here. Also i know about this site from long time ago. Sincerely i like everything which is here.
Now i would like to ask something about increasing lenght from 254 to 512 or 1024... maximum which i could try was 254 bytes. If i try to put something bigger it returns strange values... In one word the result is not satisfactory. I am speaking about hiddata example. so there is what i have done:
1. increased the report count
PROGMEM char usbHidReportDescriptor[23] = { /* USB report descriptor */
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)
// 0x95, 0x80, // REPORT_COUNT (128)
// 0x95, 0xFF, // REPORT_COUNT (255)
// 0x96, 0x00, 0x01, // REPORT_COUNT (256)
0x96, 0x00, 0x02, // REPORT_COUNT (512)
0x09, 0x00, // USAGE (Undefined)
0xb2, 0x02, 0x01, // FEATURE (Data,Var,Abs,Buf)
0xc0 // END_COLLECTION
};
2. changed usbHidReportDescriptor[23] from 22 to 23
3. changed the same value at usbconfig.h
#define USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH 23
3. changed long transfers in usbconfig.h
#define USB_CFG_LONG_TRANSFERS 1
4. created one #define in main.c (firmware code) to work much easier and to not look everywere for values... and used this define everywhere in the code where was indicated 128 (original value) and replaced.
#define EEP_BITES 255 // number of bytes remaining. Original 128
usbMsgLen_t usbFunctionSetup(uchar data[8])
{
usbRequest_t *rq = (void *)data;
if((rq->bmRequestType & USBRQ_TYPE_MASK) == USBRQ_TYPE_CLASS){ /* HID class request */
if(rq->bRequest == USBRQ_HID_GET_REPORT){ /* wValue: ReportType (highbyte), ReportID (lowbyte) */
/* since we have only one report type, we can ignore the report-ID */
bytesRemaining = EEP_BITES;
currentAddress = 0;
return USB_NO_MSG; /* use usbFunctionRead() to obtain data */
}else if(rq->bRequest == USBRQ_HID_SET_REPORT){
/* since we have only one report type, we can ignore the report-ID */
bytesRemaining = EEP_BITES;
currentAddress = 0;
return USB_NO_MSG; /* use usbFunctionWrite() to receive data from host */
}
}else{
//..... case 0.1.2....
}
5. Now speaking about hidtool.exe
i have changed lenght from 129 (128+1) to 513 (512+1)
int main(int argc, char **argv)
{
usbDevice_t *dev;
char buffer[513]; /* room for dummy report ID*/
int err;
if(argc < 2){
usage(argv[0]);
exit(1);
}
if((dev = openDevice()) == NULL)
exit(1);
if(strcasecmp(argv[1], "read") == 0){
int len = sizeof(buffer);
if((err = usbhidGetReport(dev, 0, buffer, &len)) != 0){
fprintf(stderr, "error reading data: %s\n", usbErrorMessage(err));
}else{
hexdump(buffer + 1, sizeof(buffer) - 1);
}
}else if(strcasecmp(argv[1], "write") == 0){
int i, pos;
memset(buffer, 0, sizeof(buffer));
for(pos = 1, i = 2; i < argc && pos < sizeof(buffer); i++){
pos += hexread(buffer + pos, argv[i], sizeof(buffer) - pos);
}
if((err = usbhidSetReport(dev, buffer, sizeof(buffer))) != 0) /* add a dummy report ID */
fprintf(stderr, "error writing data: %s\n", usbErrorMessage(err));
}else{
usage(argv[0]);
exit(1);
}
usbhidCloseDevice(dev);
return 0;
}
compiled with MinGW. everything work fine device reads 512 bytes. but correctly it reads only first 255 because in main.c there is (#define EEP_BITES 255 // number of bytes remaining. Original 128)
now when i try to increase this to 256 or much much more it doesn`t read even first 255 bytes. I guess it sends command in hex format like 0xFF (254 bytes) or maybe i am wrong why i can`t get it work???
should i increase this too in HidDescriptors: PROGMEM -->>>> 0x26, 0xff, 0x00, // LOGICAL_MAXIMUM (255) to 511 or bigger? any ideea please
I have increased it to read from 128 to 255 but how to do it for much more??? Now devices have bigger eeprom sizes. Thanks!!! and sorry for my long long message. I appreciate that from you! Soon i will post some examples which i have developed in C++ builder 2009 based on powerswitch... opening, closing ports ; read write some bits to eeprom ; controlling LCD in the same time, etc All with GUI interface.