/***
 * @Author: mbw
 * @Date: 2024-12-03 10:31:59
 * @LastEditors: mbw && 1600520629@qq.com
 * @LastEditTime: 2024-12-10 14:51:37
 * @FilePath: \ble_bjq_ch303rct6_ml307\bsp\inc\bsp_bt.h
 * @Description:
 * @
 * @Copyright (c) 2024 by ${git_name_email}, All Rights Reserved.
 */
#ifndef __BSP_BT_H__
#define __BSP_BT_H__

#include "rtthread.h"
#include "board.h"
#include "drv_gpio.h"

#define BT_FRAME_HEAD_LEN  (2)
#define BT_FRAME_TAIL_LEN  (2)
#define BT_FRAME_MAX_LEN   (32)
#define BT_FRAME_HEAD_DATA (0xAA)
#define BT_FRAME_TAIL_DATA (0x55)

typedef enum
{
    WirelessValveClose = 0x01,
    WirelessValveOpen,
} WireLessState;

typedef enum
{
    kValveCmdCtr = 0X01,
    kValveCmdReg,
    kValveCmdRem,
    kValveCmdRep,
    kValveCmdRemAll,
    kValveCmdMax
} ValveCmdType;

/*事件类型: 1: 阀门控制响应
            2: 阀门注册响应
            3:阀门移除响应
            4: 阀门更换响应
            5：阀门状态上报
*/
typedef enum
{
    kValveEventCtr = 0x01,
    kValveEventReg,//阀门注册
    kValveEventRem,//阀门移除
    kValveEventRep,//阀门更换
    kValveEventRemAll,//移除所有，此时不看阀门是否对应，直接删除全部
    kValveEventStatus,//阀门主动上报信息
    kValveEventConnect,//阀门连接状态上报，未实现
    kValveEventMax
}ValveEventType;

typedef struct __attribute__((packed))
{
    rt_uint8_t cmd;
    uint8_t buf[];
} BtData_t;

typedef struct __attribute__((packed))
{
    rt_uint8_t len;
    rt_uint8_t buf[256];
} BTFrameData;

extern struct rt_semaphore bt_ctr_sem; //控制阀门信号量
extern struct rt_semaphore bt_reg_sem; //注册阀门信号量
extern struct rt_semaphore bt_rem_sem; //移除阀门信号量
extern struct rt_semaphore bt_rep_sem; //更换阀门信号量

int BSP_Bt_Init(void);
int Bt_Valve_Handler(ValveCmdType type, rt_uint8_t id, rt_uint8_t *data);
#endif // BSP_BT_H__
