Skip to content

Commit

Permalink
reports btstack version. compiles with older btstack versions
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardoquesada committed Dec 20, 2024
1 parent 1c69553 commit 12b6f0e
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 3 deletions.
2 changes: 1 addition & 1 deletion external/btstack
16 changes: 14 additions & 2 deletions src/components/bluepad32/include/uni_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,25 @@
#define UNI_VERSION_H

// String version
#define UNI_VERSION "4.1.0"
#define UNI_VERSION "4.2.0"

// Number version, in case a 3rd party needs to check it
#define UNI_VERSION_MAJOR 4
#define UNI_VERSION_MINOR 1
#define UNI_VERSION_MINOR 2
#define UNI_VERSION_PATCH 0

extern const char* uni_version;

// btstack_version.h was included in v1.6.2
#if defined __has_include
#if __has_include(<btstack_version.h>)
#include <btstack_version.h>
#else
#define BTSTACK_VERSION_MAJOR 1
#define BTSTACK_VERSION_MINOR 6
#define BTSTACK_VERSION_PATCH 1
#define BTSTACK_VERSION_STRING "1.6.1"
#endif
#endif

#endif // UNI_VERSION_H
17 changes: 17 additions & 0 deletions src/components/bluepad32/parser/uni_hid_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,18 @@
#include "hid_usage.h"
#include "uni_hid_device.h"
#include "uni_log.h"
#include "uni_version.h"

// HID Usage Tables:
// https://www.usb.org/sites/default/files/documents/hut1_12v2.pdf

// Minimum version is 1.6.1
#if BTSTACK_VERSION_MAJOR > 1 || BTSTACK_VERSION_MINOR > 6 || BTSTACK_VERSION_PATCH > 1
#define USE_NEW_PARSER_API 1
#else
#define USE_NEW_PARSER_API 0
#endif

void uni_hid_parse_input_report(struct uni_hid_device_s* d, const uint8_t* report, uint16_t report_len) {
btstack_hid_parser_t parser;

Expand Down Expand Up @@ -40,12 +48,21 @@ void uni_hid_parse_input_report(struct uni_hid_device_s* d, const uint8_t* repor

// Save globals, since they are destroyed by btstack_hid_parser_get_field()
// see: https://github.com/bluekitchen/btstack/issues/187
#if USE_NEW_PARSER_API
globals.logical_minimum = parser.usage_iterator.global_logical_minimum;
globals.logical_maximum = parser.usage_iterator.global_logical_maximum;
globals.report_count = parser.usage_iterator.global_report_count;
globals.report_id = parser.usage_iterator.global_report_id;
globals.report_size = parser.usage_iterator.global_report_size;
globals.usage_page = parser.usage_iterator.global_usage_page;
#else
globals.logical_minimum = parser.global_logical_minimum;
globals.logical_maximum = parser.global_logical_maximum;
globals.report_count = parser.global_report_count;
globals.report_id = parser.global_report_id;
globals.report_size = parser.global_report_size;
globals.usage_page = parser.global_usage_page;
#endif

btstack_hid_parser_get_field(&parser, &usage_page, &usage, &value);

Expand Down
1 change: 1 addition & 0 deletions src/components/bluepad32/uni_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ int uni_init(int argc, const char** argv) {

// Honoring BTstack license
loge("BTstack: Copyright (C) 2017 BlueKitchen GmbH.\n");
loge("Version: v" BTSTACK_VERSION_STRING "\n");

uni_property_init();
uni_platform_init(argc, argv);
Expand Down

0 comments on commit 12b6f0e

Please sign in to comment.