forked from PAWPAW-Mirror/lib_xua
Merge pull request #2 from michaelb/pendragon
HID -- Interrupt integration
This commit is contained in:
@@ -2,14 +2,41 @@
|
||||
|
||||
|
||||
/* These defines relate to the HID report desc - do not mod */
|
||||
#define HID_CONTROL_PLAYPAUSE_SHIFT 0x00
|
||||
#define HID_CONTROL_NEXT_SHIFT 0x01
|
||||
#define HID_CONTROL_PREV_SHIFT 0x02
|
||||
#define HID_CONTROL_VOLUP_SHIFT 0x03
|
||||
#define HID_CONTROL_VOLDN_SHIFT 0x04
|
||||
#define HID_CONTROL_MUTE_SHIFT 0x05
|
||||
#define HID_CONTROL_PLAYPAUSE_SHIFT 0x00
|
||||
#define HID_CONTROL_NEXT_SHIFT 0x01
|
||||
#define HID_CONTROL_PREV_SHIFT 0x02
|
||||
#define HID_CONTROL_VOLUP_SHIFT 0x03
|
||||
#define HID_CONTROL_VOLDN_SHIFT 0x04
|
||||
#define HID_CONTROL_MUTE_SHIFT 0x05
|
||||
|
||||
#define HID_DATA_SIZE 1
|
||||
|
||||
void UserReadHIDData(unsigned char hidData[HID_DATA_SIZE]);
|
||||
#ifndef HID_SIMULATE_INTERRUPTS
|
||||
#define HID_SIMULATE_INTERRUPTS 0
|
||||
#endif
|
||||
|
||||
#ifndef INTERRUPT_ASSERT_LEVEL
|
||||
#define INTERRUPT_ASSERT_LEVEL 0
|
||||
#endif
|
||||
|
||||
#if( 0 < HID_CONTROLS )
|
||||
|
||||
#if( 0 < INTERRUPT_ASSERT_LEVEL )
|
||||
#define INT_ASSERT_LEVEL 1
|
||||
#define INT_DEASSERT_LEVEL 0
|
||||
#else
|
||||
#define INT_ASSERT_LEVEL 0
|
||||
#define INT_DEASSERT_LEVEL 1
|
||||
#endif
|
||||
|
||||
#if( 0 < HID_SIMULATE_INTERRUPTS )
|
||||
#define HID_DEASSERT_COUNT 10000
|
||||
#define HID_INTERRUPT_COUNT 1000000000
|
||||
#endif
|
||||
|
||||
select UserHIDTrigger( unsigned* hidValueLatched );
|
||||
void UserInitHIDData( void );
|
||||
void UserReadHIDData( unsigned char hidData[ HID_DATA_SIZE ]);
|
||||
void UserSetHIDData( const unsigned hidData );
|
||||
|
||||
#endif /* ( 0 < HID_CONTROLS ) */
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
// Copyright (c) 2019, XMOS Ltd, All rights reserved
|
||||
#include <stdint.h>
|
||||
#include <limits.h>
|
||||
#include <xs1.h>
|
||||
#include "user_hid.h"
|
||||
|
||||
#define HID_DEASSERT_COUNT 10000000
|
||||
#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 ])
|
||||
{
|
||||
timer tmr;
|
||||
|
||||
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 ) && ( tick_count <= ( HID_INTERRUPT_COUNT + HID_DEASSERT_COUNT ))) {
|
||||
for( unsigned idx = 0; idx < HID_DATA_SIZE; ++idx ) {
|
||||
hidData[ idx ] = HID_REPORT_DATA;
|
||||
}
|
||||
} else {
|
||||
for( unsigned idx = 0; idx < HID_DATA_SIZE; ++idx ) {
|
||||
hidData[ idx ] = 0x00;
|
||||
}
|
||||
|
||||
if (( HID_INTERRUPT_COUNT + HID_DEASSERT_COUNT ) <= tick_count ) {
|
||||
tick_count = 0;
|
||||
}
|
||||
}
|
||||
|
||||
last_time = curr_time;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user