// Copyright 2013-2024 XMOS LIMITED.
// This Software is subject to the terms of the XMOS Public Licence: Version 1.

/**
 * @brief Human Interface Device (HID) API
 *
 * This file defines the Application Programming Interface (API) used to record HID
 * events and retrieve a HID Report for sending to a host.
 * The using application has the responsibility to fulfill this API.
 * Document section numbers refer to the HID Device Class Definition, version 1.11.
 */

#ifndef _USER_HID_H_
#define _USER_HID_H_

#include <stddef.h>

/**
 *  \brief  HID event
 *
 *  This struct identifies:
 *  - the HID Report that reports an event, i.e., the ID,
 *  - the location within the HID Report for the event, i.e., the byte and bit, and
 *  - the value to report for that location (typically interpreted as a Boolean).
 *  It assumes only single bit flags within the HID Report.
 */
typedef struct hidEvent_t {
  unsigned bit;
  unsigned byte;
  unsigned id;
  unsigned value;
} hidEvent_t;


#define HID_MAX_DATA_BYTES ( 64 )
#define HID_MAX_OUT_BYTES  ( 65 ) 
#define HID_EVENT_INVALID_ID ( 0x100 )


/**
 *  \brief  Get the data for the next HID Report
 *
 *  \param[in]  id       The HID Report ID (see 5.6, 6.2.2.7, 8.1 and 8.2 of the USB Device Class Definition for HID 1.11)
 *                       Set to zero if the application provides only one HID Report
 *                       which does not include a Report ID
 *  \param[out] hidData  The HID data
 *                       If using Report IDs, this function places the Report ID in
 *                       the first element; otherwise the first element holds the
 *                       first byte of HID event data.
 *
 *  \returns  The length of the HID Report in the \a hidData argument
 *  \retval   Zero means no new HID event data has been recorded for the given \a id
 */
size_t UserHIDGetData( const unsigned id, unsigned char hidData[ HID_MAX_DATA_BYTES ]);

/* 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

void UserReadHIDButtons(unsigned char hidData[]);
void UserReadHIDPass(unsigned char hidPassData[]);
void UserReadHIDLog(unsigned char hidLogData[]);
void user_read_hid_status(unsigned char hidPassData[]);

/**
 *  \brief  Initialize HID processing
 */
void UserHIDInit( void );

#endif /* _USER_HID_H_ */
