/*
* Change Logs:
* Date          Author      Notes
* 2023­06­07  weijiac     the first version
* 2023-06-26    weijiac     add interface for drv_asi.c
*/

#ifndef _COMPLEXITY_HID_H
#define _COMPLEXITY_HID_H

#include "usb_common.h"
#include "hal_usbd.h"
#include "hal_usbd_init.h"
#include "hal_usbd_reg.h"
#include "usb_device.h"
#include "debug.h"
#include "board.h"

/*
    从hid报文来看，总共有三个report id, 0x03(3), 0x4B(75), 0x01(1)
    report id：03 为audio hid，用于切换下一首，音量加减，audio hid仅在ep in 即hid_send_data中使用。
    report id：0x4b 为hid_protocol，如通过hid进入烧录模式使用该report id；在hid_send_data以及hid_recv_data 都会用上。
    report id: 0x01 未知

 */

typedef enum hid_send_status
{
    hid_send_uninit,
    //上一次数据没有传输完毕，不要往缓冲区写数据
    hid_sending,
    //上一次数据已传输完毕
    hid_sent,
} hid_send_status;

typedef enum hid_recv_status
{
    hid_receive_uninit,
    //接收到数据
    hid_received,
    //没有接收到数据
    hid_free,
} hid_recv_status;

struct hid_protocol
{
    uint8_t      report_id;
    uint8_t      bRequestType;
    uint8_t      bCode;
    uint8_t      bLength;
    uint8_t      pay_load[60];
} __attribute__((packed, aligned(4)));

struct audio_hid
{
    uint8_t     report_id;
    uint8_t     audio_cmd;
} __attribute__((packed, aligned(4)));

struct hid_send_ctl
{
    hid_send_status send_status;
    uint8_t _ep_addr;
    union   /* union needed to comply with C99 pointer aliasing rules */
    {
        struct audio_hid    audio_hid_pro;
        struct hid_protocol hid_pro;
    } hid_buffer;
} __attribute__((packed, aligned(4)));

struct hid_recv_ctl
{
    hid_recv_status recv_status;
    uint8_t _ep_addr;
    struct hid_protocol hid_pro;
} __attribute__((packed, aligned(4)));

ufunction_t rt_usbd_function_hid_create(udevice_t device);

rt_size_t hid_get_recv_data(uint8_t *buff);
rt_err_t hid_send_data(uint8_t *buff, uint32_t len);

#endif /* _COMPLEXITY_HID_H */