Skip to content

Commit

Permalink
Update demo code for usb hid demo
Browse files Browse the repository at this point in the history
  • Loading branch information
cnlohr committed Nov 25, 2023
1 parent f666a99 commit d9e9683
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 11 deletions.
2 changes: 1 addition & 1 deletion tools/sandbox_test/usbhid_test/sandbox.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ int16_t sandboxAdvancedUSB(uint8_t* buffer, uint16_t length, uint8_t isGet)
buffer[1] = 0x55;
buffer[2] = 0xaa;
buffer[3] = 0x55;
return 64;
return 254;
}
else
{
Expand Down
12 changes: 11 additions & 1 deletion tools/sandbox_test/usbhid_test/test/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
all : hidtest

ifeq ($(shell uname), Linux)
CFLAGS:=-g -O0
LDFLAGS:=-ludev
CC:=gcc
else
CFLAGS:=-Os -s
CC:=gcc
LDFLAGS:=C:/windows/system32/setupapi.dll
endif

hidtest : hidtest.c
gcc -o $@ $^ -ludev
$(CC) -o $@ $^ $(CFLAGS) $(LDFLAGS)

clean :
rm -rf hidtest
Expand Down
21 changes: 12 additions & 9 deletions tools/sandbox_test/usbhid_test/test/hidtest.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include <stdio.h>
#include <stdint.h>
#include <unistd.h>
#include <sys/stat.h>
#include <time.h>

Expand All @@ -12,9 +11,12 @@
#define PID 0x4004

#ifdef WIN32
const int reg_packet_length = 65;
const int reg_packet_length = 255;
const int reg_back_rest = 256;
#else
const int reg_packet_length = 64;
#include <unistd.h>
const int reg_packet_length = 254;
const int reg_back_rest = 254;
#endif

hid_device * hd;
Expand All @@ -28,7 +30,7 @@ int main( int argc, char ** argv )
if( !hd ) { fprintf( stderr, "Could not open USB\n" ); return -94; }

// Disable tick.
uint8_t rdata[65] = { 0 };
uint8_t rdata[256] = { 0 };
rdata[0] = 173;
r = hid_get_feature_report( hd, rdata, reg_packet_length );
printf( "Got data: %d bytes\n", r );
Expand All @@ -43,13 +45,14 @@ int main( int argc, char ** argv )
for( i = 0; i < 1024; i++ )
{
r = hid_get_feature_report( hd, rdata, reg_packet_length );
if( r != reg_packet_length )
rdata[0] = 173;
if( r != reg_back_rest )
{
fprintf( stderr, "Error reading message (%d)\n", r );
}
}
double dEnd = OGGetAbsoluteTime();
printf( "Reads: %5.0f/sec / %3.2f kB/s\n", 1024.0/(dEnd - dStart), (63)/(dEnd - dStart));
printf( "Reads: %5.0f/sec / %3.2f kB/s\n", 1024.0/(dEnd - dStart), (reg_packet_length)/(dEnd - dStart));

dStart = OGGetAbsoluteTime();
for( i = 0; i < 1024; i++ )
Expand All @@ -59,11 +62,11 @@ int main( int argc, char ** argv )
r = hid_send_feature_report( hd, rdata, reg_packet_length );
if( r != reg_packet_length )
{
fprintf( stderr, "Error reading message (%d)\n", r );
fprintf( stderr, "Error writing message (%d)\n", r );
}
}
dEnd = OGGetAbsoluteTime();
printf( "Writes: %5.0f/sec / %3.2f kB/s\n", 1024.0/(dEnd - dStart), (63)/(dEnd - dStart) );
printf( "Writes: %5.0f/sec / %3.2f kB/s\n", 1024.0/(dEnd - dStart), (reg_packet_length)/(dEnd - dStart) );

rdata[0] = 173;
rdata[1] = 0x00;
Expand All @@ -78,7 +81,7 @@ int main( int argc, char ** argv )
int f;
for( f = 0; f < 10; f++ )
{
for( y = 0; y < 240; y++ )
for( y = 0; y < 240; y+=10 )
{
for( x = 0; x < 280; x += 56 )
{
Expand Down
1 change: 1 addition & 0 deletions tools/sandbox_test/usbhid_test/test/winbuild.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tcc hidtest.c C:/windows/system32/setupapi.dll

0 comments on commit d9e9683

Please sign in to comment.