forked from PAWPAW-Mirror/lib_xua
Add demo HID code that simulates an interrupt roughly every 10 seconds.
This commit is contained in:
@@ -4,9 +4,38 @@
|
|||||||
#include <xs1.h>
|
#include <xs1.h>
|
||||||
#include "user_hid.h"
|
#include "user_hid.h"
|
||||||
|
|
||||||
|
#define HID_INTERRUPT_COUNT 1000000000
|
||||||
|
#define HID_REPORT_DATA 0x01
|
||||||
|
|
||||||
|
static unsigned char initialised = 0;
|
||||||
|
|
||||||
|
static unsigned int curr_time = 0;
|
||||||
|
static unsigned int last_time = 0;
|
||||||
|
static unsigned int tick_count = 0;
|
||||||
|
|
||||||
void UserReadHIDData( unsigned char hidData[ HID_DATA_SIZE ])
|
void UserReadHIDData( unsigned char hidData[ HID_DATA_SIZE ])
|
||||||
{
|
{
|
||||||
for( unsigned idx = 0; idx < HID_DATA_SIZE; ++idx ) {
|
timer tmr;
|
||||||
hidData[ idx ] = 1;
|
|
||||||
|
if( !initialised ) {
|
||||||
|
tmr :> last_time;
|
||||||
|
initialised = 1;
|
||||||
|
} else {
|
||||||
|
tmr :> curr_time;
|
||||||
|
tick_count += ( last_time < curr_time ) ? curr_time - last_time : curr_time + ( UINT_MAX - last_time );
|
||||||
|
|
||||||
|
if( HID_INTERRUPT_COUNT <= tick_count ) {
|
||||||
|
for( unsigned idx = 0; idx < HID_DATA_SIZE; ++idx ) {
|
||||||
|
hidData[ idx ] = HID_REPORT_DATA;
|
||||||
|
}
|
||||||
|
|
||||||
|
tick_count = 0;
|
||||||
|
} else {
|
||||||
|
for( unsigned idx = 0; idx < HID_DATA_SIZE; ++idx ) {
|
||||||
|
hidData[ idx ] = 0x00;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
last_time = curr_time;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user