#pragma once

#ifdef __cplusplus
extern "C" {
#endif

/* Includes ----------------------------------------------------------------- */
#include <cmsis_os2.h>

#include "component/user_math.h"
#include "device/device.h"

/* Exported constants ------------------------------------------------------- */
#define DEVICE_LIGHTBRIDGE2_FRAME_LEN 25u   

/* Exported types ----------------------------------------------------------- */
typedef struct __attribute__((packed))
{
    int16_t ch[4];   //摇杆
    int16_t sw[8];   //开关
} DEVICE_LIGHTBRIDGE2_Raw_t;

/* ???? */
typedef enum {
  LIGHTBRIDGE2_CMD_SW_ERR = 0,
  LIGHTBRIDGE2_CMD_SW_UP = 1,
  LIGHTBRIDGE2_CMD_SW_MID = 3,
  LIGHTBRIDGE2_CMD_SW_DOWN = 2,
} COMP_LIGHTBRIDGE2_CMD_SwitchPos_t;

typedef  struct
{
    float ch_l_x;   //左摇杆X轴
    float ch_l_y;   //左摇杆Y轴
    float ch_r_x;   //右摇杆X轴
    float ch_r_y;   //右摇杆Y轴

    //按键
    COMP_LIGHTBRIDGE2_CMD_SwitchPos_t key_A;
	  COMP_LIGHTBRIDGE2_CMD_SwitchPos_t key_B;
    COMP_LIGHTBRIDGE2_CMD_SwitchPos_t key_C;
  	COMP_LIGHTBRIDGE2_CMD_SwitchPos_t key_D;
    COMP_LIGHTBRIDGE2_CMD_SwitchPos_t key_E;
    COMP_LIGHTBRIDGE2_CMD_SwitchPos_t key_F;
    COMP_LIGHTBRIDGE2_CMD_SwitchPos_t key_G;
    COMP_LIGHTBRIDGE2_CMD_SwitchPos_t key_H;
    float knob_left;
    float knob_right;
	  float back_left;
	  float back_right;
} DEVICE_LIGHTBRIDGE2_Data_t;

typedef struct
{	bool online;
  DEVICE_LIGHTBRIDGE2_Data_t data;
} DEVICE_LIGHTBRIDGE2_t;

/* Exported functions prototypes -------------------------------------------- */
int8_t  DEVICE_LIGHTBRIDGE2_Init(DEVICE_LIGHTBRIDGE2_t *lightbridge2);
int8_t  DEVICE_LIGHTBRIDGE2_Restart(void);
int8_t  DEVICE_LIGHTBRIDGE2_StartDmaRecv(uint8_t *cmd_buffer);
bool    DEVICE_LIGHTBRIDGE2_WaitDmaCplt(uint32_t timeout);
void    DEVICE_LIGHTBRIDGE2_ParseRaw(const uint8_t raw[DEVICE_LIGHTBRIDGE2_FRAME_LEN], DEVICE_LIGHTBRIDGE2_t *out);

#ifdef __cplusplus
}
#endif