#ifndef USBHID_INTERFACE_H_
#define USBHID_INTERFACE_H_

#define TASK_REPORT_STACK_SIZE				(512/sizeof(portSTACK_TYPE))
#define TASK_REPORT_PRIORITY				( ( UBaseType_t ) 1U )

#define MIN_REPORT_RATE			(10) // Delay between reports in millisec. Maximum rate = 1/.01 = 100Hz
#define DEFAULT_HID_WAIT_TIME	50	// Clock to the RTT is about 10kHz. This is roughly 5ms

typedef enum hid_errors {
	Hid_Success = 0,
	Hid_Invalid_Arg = 1,
	Hid_Unsupported = 2,
	Hid_Unknown_Error = 3,
	Hid_Busy_Error = 4,
	Hid_Timeout_Error = 6
} Hid_Error_T;

// HID Feature Report codes for PC->HMD requests
#define HID_CODE_FOR_SW_VER				('*')
#define HID_CODE_FOR_SERIAL_NUM			('%')
#define HID_CODE_FOR_HMD_SERIAL_NUM		('&')
#define HID_CODE_FOR_TRACKING_SERIAL	('~')
#define HID_CODE_FOR_USAGE_TIMER_GET	('Z')
#define HID_CODE_FOR_USAGE_TIMER_SET	('z')
#define HID_CODE_FOR_STEREO				('S')
#define HID_CODE_FOR_GAIN				('G')
#define HID_CODE_FOR_FRAC_GAIN			('g')
#define HID_CODE_FOR_FAN				('F')
#define HID_CODE_FOR_RATE				('R')
#define HID_CODE_FOR_OLED_FLIP			('P')
#define HID_CODE_FOR_OLED_BRIGHNTESS	('I')
#define HID_CODE_FOR_OLED_ID			('^')
#define HID_CODE_FOR_BOOTLOADER			('B')
#define HID_CODE_FOR_RESET				('C')
#define HID_CODE_FOR_READ_SIG			('U')
#define HID_CODE_FOR_RGB_LED			('L')
#define HID_CODE_FOR_WRITE_SIG			('W')
#define HID_CODE_FOR_SAVE_SIG			('V')
#define HID_CODE_FOR_PROX_SETTINGS		('M')
#define HID_CODE_FOR_CHECK_VXR_CONNECTION	('X')
#define HID_CODE_FOR_VXR_CHECKSUM		('K')
#define HID_CODE_FOR_VXR_TAGS			('T')
#define HID_CODE_FOR_VXR_DELETE			('D')
#define HID_CODE_FOR_VXR_PROGRAM		('A')
#define HID_CODE_FOR_VXR_RESET			('Y')
#define HID_CODE_FOR_VXR_FWNAME			('N')
#define HID_CODE_FOR_HW_TEST			('J')
#define HID_CODE_FOR_FATP_MODE			('@')
#define HID_CODE_FOR_OLED_COMMAND		('o')
#define HID_CODE_FOR_EDID_SWITCH		('d')
#define HID_CODE_FOR_PROX_DISABLE		('p')
#define HID_CODE_FOR_PROX_ENABLE		('[')
#define HID_CODE_FOR_COLORBARPATTERN	('=')
#define HID_CODE_FOR_STACK_LEVELS		('s')

/* Debugging tools. Triggers a crash
 * for testing out the crash handler.
 */
#define HID_CODE_FOR_HARDFAULT			(',')
#define HID_CODE_FOR_UNUSED_IRQ			('.')
#define HID_CODE_FOR_STACK_OVERFLOW		('>')

#define HID_SIG_XFER_LENGTH			(32u) // Writes/Reads 32 bytes of the signature region per transfer
#define VXR_CHECKSUM_LENGTH			(4u) // Checksum is always a 4-byte / 32-bit value

// HID Feature Report codes for HMD->PC feedback
#define HID_CODE_FOR_DATA_REPLY				('#')
#define HID_CODE_FOR_SW_VER_REPLY			HID_CODE_FOR_SW_VER
#define HID_CODE_FOR_SERIAL_NUM_REPLY		HID_CODE_FOR_SERIAL_NUM
#define HID_CODE_FOR_HMD_SERIAL_REPLY		HID_CODE_FOR_HMD_SERIAL_NUM
#define HID_CODE_FOR_TRACKING_SERIAL_REPLY	HID_CODE_FOR_TRACKING_SERIAL
#define HID_CODE_FOR_USAGE_TIMER_REPLY		HID_CODE_FOR_USAGE_TIMER_GET
#define HID_CODE_FOR_SIG_REPLY				HID_CODE_FOR_READ_SIG
#define HID_CODE_FOR_VXR_CHECKSUM_REPLY		HID_CODE_FOR_VXR_CHECKSUM
#define HID_CODE_FOR_VXR_TAGS_REPLY			HID_CODE_FOR_VXR_TAGS
#define HID_CODE_FOR_VXR_FWNAME_REPLY		HID_CODE_FOR_VXR_FWNAME
#define HID_CODE_FOR_HW_TEST_REPLY			HID_CODE_FOR_HW_TEST
#define HID_CODE_FOR_OLED_ID_REPLY			HID_CODE_FOR_OLED_ID
#define HID_CODE_FOR_STACK_LEVELS_REPLY		HID_CODE_FOR_STACK_LEVELS
#define HID_CODE_FOR_SUCCESS_REPLY			('$')
#define HID_CODE_FOR_ERROR_REPLY			('E')

// Task notification codes for the HID report reply
#define HID_REPORT_TASK_CODE_FOR_SW_VER				HID_CODE_FOR_SW_VER
#define HID_REPORT_TASK_CODE_FOR_SERIAL				HID_CODE_FOR_SERIAL_NUM
#define	HID_REPORT_TASK_CODE_FOR_HMD_SERIAL			HID_CODE_FOR_HMD_SERIAL_NUM
#define HID_REPORT_TASK_CODE_FOR_TRACKING_SERIAL	HID_CODE_FOR_TRACKING_SERIAL
#define HID_REPORT_TASK_CODE_FOR_USAGE_TIMER_GET	HID_CODE_FOR_USAGE_TIMER_GET
#define HID_REPORT_TASK_CODE_FOR_USAGE_TIMER_SET	HID_CODE_FOR_USAGE_TIMER_SET
#define HID_REPORT_TASK_CODE_FOR_BOOTLOADER			HID_CODE_FOR_BOOTLOADER
#define HID_REPORT_TASK_CODE_FOR_RESET				HID_CODE_FOR_RESET
#define HID_REPORT_TASK_CODE_FOR_OLED_ID			HID_CODE_FOR_OLED_ID
#define HID_REPORT_TASK_CODE_FOR_SIG				HID_CODE_FOR_READ_SIG
#define HID_REPORT_TASK_CODE_FOR_VXR_CHECKSUM		HID_CODE_FOR_VXR_CHECKSUM
#define HID_REPORT_TASK_CODE_FOR_VXR_TAGS			HID_CODE_FOR_VXR_TAGS
#define HID_REPORT_TASK_CODE_FOR_VXR_DELETE			HID_CODE_FOR_VXR_DELETE
#define HID_REPORT_TASK_CODE_FOR_VXR_PROGRAM		HID_CODE_FOR_VXR_PROGRAM
#define HID_REPORT_TASK_CODE_FOR_VXR_FWNAME			HID_CODE_FOR_VXR_FWNAME
#define HID_REPORT_TASK_CODE_FOR_HW_TEST			HID_CODE_FOR_HW_TEST
#define HID_REPORT_TASK_CODE_FOR_SUCCESS			HID_CODE_FOR_SUCCESS_REPLY
#define HID_REPORT_TASK_CODE_FOR_ERROR				HID_CODE_FOR_ERROR_REPLY
#define HID_REPORT_TASK_CODE_FOR_COLORBARPATTERN	HID_CODE_FOR_COLORBARPATTERN
#define HID_REPORT_TASK_CODE_FOR_STACK_LEVELS		HID_CODE_FOR_STACK_LEVELS


void start_usbhid_task(void);
void send_code_to_hid_task(uint32_t code);
void send_code_to_hid_task_fromISR(uint32_t code);
void usbhid_set_feature(uint8_t* report);



#endif /* USBHID_INTERFACE_H_ */
