mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-05-14 08:08:36 -07:00
Fix led descriptor?
This commit is contained in:
@@ -12,6 +12,7 @@ typedef enum {
|
|||||||
HidSvcGattCharacteristicReportMap,
|
HidSvcGattCharacteristicReportMap,
|
||||||
HidSvcGattCharacteristicInfo,
|
HidSvcGattCharacteristicInfo,
|
||||||
HidSvcGattCharacteristicCtrlPoint,
|
HidSvcGattCharacteristicCtrlPoint,
|
||||||
|
HidSvcGattCharacteristicLed,
|
||||||
HidSvcGattCharacteristicCount,
|
HidSvcGattCharacteristicCount,
|
||||||
} HidSvcGattCharacteristicId;
|
} HidSvcGattCharacteristicId;
|
||||||
|
|
||||||
@@ -49,6 +50,17 @@ static bool
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static FlipperGattCharacteristicDescriptorParams hid_svc_char_descr_led = {
|
||||||
|
.uuid_type = UUID_TYPE_16,
|
||||||
|
.uuid.Char_UUID_16 = REPORT_REFERENCE_DESCRIPTOR_UUID,
|
||||||
|
.max_length = HID_SVC_REPORT_REF_LEN,
|
||||||
|
.data_callback.fn = hid_svc_char_desc_data_callback,
|
||||||
|
.security_permissions = ATTR_PERMISSION_NONE,
|
||||||
|
.access_permissions = ATTR_ACCESS_READ_WRITE,
|
||||||
|
.gatt_evt_mask = GATT_DONT_NOTIFY_EVENTS,
|
||||||
|
.is_variable = CHAR_VALUE_LEN_CONSTANT,
|
||||||
|
};
|
||||||
|
|
||||||
static const FlipperGattCharacteristicParams hid_svc_chars[HidSvcGattCharacteristicCount] = {
|
static const FlipperGattCharacteristicParams hid_svc_chars[HidSvcGattCharacteristicCount] = {
|
||||||
[HidSvcGattCharacteristicProtocolMode] =
|
[HidSvcGattCharacteristicProtocolMode] =
|
||||||
{.name = "Protocol Mode",
|
{.name = "Protocol Mode",
|
||||||
@@ -92,6 +104,20 @@ static const FlipperGattCharacteristicParams hid_svc_chars[HidSvcGattCharacteris
|
|||||||
.security_permissions = ATTR_PERMISSION_NONE,
|
.security_permissions = ATTR_PERMISSION_NONE,
|
||||||
.gatt_evt_mask = GATT_NOTIFY_ATTRIBUTE_WRITE,
|
.gatt_evt_mask = GATT_NOTIFY_ATTRIBUTE_WRITE,
|
||||||
.is_variable = CHAR_VALUE_LEN_CONSTANT},
|
.is_variable = CHAR_VALUE_LEN_CONSTANT},
|
||||||
|
[HidSvcGattCharacteristicLed] =
|
||||||
|
{
|
||||||
|
.name = "HID LED State",
|
||||||
|
.data_prop_type = FlipperGattCharacteristicDataFixed,
|
||||||
|
.data.fixed.length = 1,
|
||||||
|
.uuid.Char_UUID_16 = REPORT_CHAR_UUID,
|
||||||
|
.uuid_type = UUID_TYPE_16,
|
||||||
|
.char_properties = CHAR_PROP_READ | CHAR_PROP_WRITE_WITHOUT_RESP | CHAR_PROP_WRITE,
|
||||||
|
.security_permissions = ATTR_PERMISSION_NONE,
|
||||||
|
.gatt_evt_mask = GATT_NOTIFY_ATTRIBUTE_WRITE |
|
||||||
|
GATT_NOTIFY_WRITE_REQ_AND_WAIT_FOR_APPL_RESP,
|
||||||
|
.is_variable = CHAR_VALUE_LEN_CONSTANT,
|
||||||
|
.descriptor_params = &hid_svc_char_descr_led,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
static const FlipperGattCharacteristicDescriptorParams hid_svc_char_descr_template = {
|
static const FlipperGattCharacteristicDescriptorParams hid_svc_char_descr_template = {
|
||||||
@@ -124,6 +150,9 @@ typedef struct {
|
|||||||
FlipperGattCharacteristicInstance input_report_chars[HID_SVC_INPUT_REPORT_COUNT];
|
FlipperGattCharacteristicInstance input_report_chars[HID_SVC_INPUT_REPORT_COUNT];
|
||||||
FlipperGattCharacteristicInstance output_report_chars[HID_SVC_OUTPUT_REPORT_COUNT];
|
FlipperGattCharacteristicInstance output_report_chars[HID_SVC_OUTPUT_REPORT_COUNT];
|
||||||
FlipperGattCharacteristicInstance feature_report_chars[HID_SVC_FEATURE_REPORT_COUNT];
|
FlipperGattCharacteristicInstance feature_report_chars[HID_SVC_FEATURE_REPORT_COUNT];
|
||||||
|
// led state
|
||||||
|
HidLedStateEventCallback led_state_event_callback;
|
||||||
|
void* led_state_ctx;
|
||||||
} HIDSvc;
|
} HIDSvc;
|
||||||
|
|
||||||
static HIDSvc* hid_svc = NULL;
|
static HIDSvc* hid_svc = NULL;
|
||||||
@@ -140,6 +169,32 @@ static SVCCTL_EvtAckStatus_t hid_svc_event_handler(void* event) {
|
|||||||
} else if(blecore_evt->ecode == ACI_GATT_SERVER_CONFIRMATION_VSEVT_CODE) {
|
} else if(blecore_evt->ecode == ACI_GATT_SERVER_CONFIRMATION_VSEVT_CODE) {
|
||||||
// Process notification confirmation
|
// Process notification confirmation
|
||||||
ret = SVCCTL_EvtAckFlowEnable;
|
ret = SVCCTL_EvtAckFlowEnable;
|
||||||
|
} else if(blecore_evt->ecode == ACI_GATT_WRITE_PERMIT_REQ_VSEVT_CODE) {
|
||||||
|
// Process write request
|
||||||
|
aci_gatt_write_permit_req_event_rp0* req =
|
||||||
|
(aci_gatt_write_permit_req_event_rp0*)blecore_evt->data;
|
||||||
|
|
||||||
|
furi_check(hid_svc->led_state_event_callback && hid_svc->led_state_ctx);
|
||||||
|
|
||||||
|
// this check is likely to be incorrect, it will actually work in our case
|
||||||
|
// but we need to investigate gatt api to see what is the rules
|
||||||
|
// that specify attibute handle value from char handle (or the reverse)
|
||||||
|
if(req->Attribute_Handle == (hid_svc->chars[HidSvcGattCharacteristicLed].handle + 1)) {
|
||||||
|
hid_svc->led_state_event_callback(req->Data[0], hid_svc->led_state_ctx);
|
||||||
|
aci_gatt_write_resp(
|
||||||
|
req->Connection_Handle,
|
||||||
|
req->Attribute_Handle,
|
||||||
|
0x00, /* write_status = 0 (no error))*/
|
||||||
|
0x00, /* err_code */
|
||||||
|
req->Data_Length,
|
||||||
|
req->Data);
|
||||||
|
aci_gatt_write_char_value(
|
||||||
|
req->Connection_Handle,
|
||||||
|
hid_svc->chars[HidSvcGattCharacteristicLed].handle,
|
||||||
|
req->Data_Length,
|
||||||
|
req->Data);
|
||||||
|
ret = SVCCTL_EvtAckFlowEnable;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
@@ -163,8 +218,8 @@ void hid_svc_start() {
|
|||||||
PRIMARY_SERVICE,
|
PRIMARY_SERVICE,
|
||||||
2 + /* protocol mode */
|
2 + /* protocol mode */
|
||||||
(4 * HID_SVC_INPUT_REPORT_COUNT) + (3 * HID_SVC_OUTPUT_REPORT_COUNT) +
|
(4 * HID_SVC_INPUT_REPORT_COUNT) + (3 * HID_SVC_OUTPUT_REPORT_COUNT) +
|
||||||
(3 * HID_SVC_FEATURE_REPORT_COUNT) + 1 + 2 + 2 +
|
(3 * HID_SVC_FEATURE_REPORT_COUNT) + 1 + 2 + 2 + 2 +
|
||||||
2, /* Service + Report Map + HID Information + HID Control Point */
|
4, /* Service + Report Map + HID Information + HID Control Point + LED state */
|
||||||
&hid_svc->svc_handle);
|
&hid_svc->svc_handle);
|
||||||
if(status) {
|
if(status) {
|
||||||
FURI_LOG_E(TAG, "Failed to add HID service: %d", status);
|
FURI_LOG_E(TAG, "Failed to add HID service: %d", status);
|
||||||
@@ -250,6 +305,15 @@ bool hid_svc_update_info(uint8_t* data) {
|
|||||||
hid_svc->svc_handle, &hid_svc->chars[HidSvcGattCharacteristicInfo], &data);
|
hid_svc->svc_handle, &hid_svc->chars[HidSvcGattCharacteristicInfo], &data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void hid_svc_register_led_state_callback(HidLedStateEventCallback callback, void* context) {
|
||||||
|
furi_assert(hid_svc);
|
||||||
|
furi_assert(callback);
|
||||||
|
furi_assert(context);
|
||||||
|
|
||||||
|
hid_svc->led_state_event_callback = callback;
|
||||||
|
hid_svc->led_state_ctx = context;
|
||||||
|
}
|
||||||
|
|
||||||
bool hid_svc_is_started() {
|
bool hid_svc_is_started() {
|
||||||
return hid_svc != NULL;
|
return hid_svc != NULL;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,8 @@
|
|||||||
#define HID_SVC_REPORT_COUNT \
|
#define HID_SVC_REPORT_COUNT \
|
||||||
(HID_SVC_INPUT_REPORT_COUNT + HID_SVC_OUTPUT_REPORT_COUNT + HID_SVC_FEATURE_REPORT_COUNT)
|
(HID_SVC_INPUT_REPORT_COUNT + HID_SVC_OUTPUT_REPORT_COUNT + HID_SVC_FEATURE_REPORT_COUNT)
|
||||||
|
|
||||||
|
typedef uint16_t (*HidLedStateEventCallback)(uint8_t state, void* ctx);
|
||||||
|
|
||||||
void hid_svc_start();
|
void hid_svc_start();
|
||||||
|
|
||||||
void hid_svc_stop();
|
void hid_svc_stop();
|
||||||
@@ -27,3 +29,5 @@ bool hid_svc_update_input_report(uint8_t input_report_num, uint8_t* data, uint16
|
|||||||
|
|
||||||
// Expects data to be of length HID_SVC_INFO_LEN (4 bytes)
|
// Expects data to be of length HID_SVC_INFO_LEN (4 bytes)
|
||||||
bool hid_svc_update_info(uint8_t* data);
|
bool hid_svc_update_info(uint8_t* data);
|
||||||
|
|
||||||
|
void hid_svc_register_led_state_callback(HidLedStateEventCallback callback, void* context);
|
||||||
|
|||||||
Reference in New Issue
Block a user