|
@@ -3,6 +3,9 @@
|
|
|
*
|
|
*
|
|
|
* Thank you to Willy-JL for providing this code and making it available under the https://github.com/Flipper-XFW/Xtreme-Apps repository.
|
|
* Thank you to Willy-JL for providing this code and making it available under the https://github.com/Flipper-XFW/Xtreme-Apps repository.
|
|
|
* Your contribution has been invaluable for this project.
|
|
* Your contribution has been invaluable for this project.
|
|
|
|
|
+ *
|
|
|
|
|
+ * Based on <targets/f7/ble_glue/profiles/serial_profile.c>
|
|
|
|
|
+ * and on <lib/ble_profile/extra_profiles/hid_profile.c>
|
|
|
*/
|
|
*/
|
|
|
|
|
|
|
|
#include "ble_serial.h"
|
|
#include "ble_serial.h"
|
|
@@ -40,7 +43,13 @@ static void ble_profile_serial_stop(FuriHalBleProfileBase* profile) {
|
|
|
ble_svc_serial_stop(serial_profile->serial_svc);
|
|
ble_svc_serial_stop(serial_profile->serial_svc);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-static GapConfig serial_template_config = {
|
|
|
|
|
|
|
+// AN5289: 4.7, in order to use flash controller interval must be at least 25ms + advertisement, which is 30 ms
|
|
|
|
|
+// Since we don't use flash controller anymore interval can be lowered to 7.5ms
|
|
|
|
|
+#define CONNECTION_INTERVAL_MIN (0x06)
|
|
|
|
|
+// Up to 45 ms
|
|
|
|
|
+#define CONNECTION_INTERVAL_MAX (0x24)
|
|
|
|
|
+
|
|
|
|
|
+static const GapConfig serial_template_config = {
|
|
|
.adv_service =
|
|
.adv_service =
|
|
|
{
|
|
{
|
|
|
.UUID_Type = UUID_TYPE_16,
|
|
.UUID_Type = UUID_TYPE_16,
|
|
@@ -50,8 +59,8 @@ static GapConfig serial_template_config = {
|
|
|
.bonding_mode = true,
|
|
.bonding_mode = true,
|
|
|
.pairing_method = GapPairingPinCodeShow,
|
|
.pairing_method = GapPairingPinCodeShow,
|
|
|
.conn_param = {
|
|
.conn_param = {
|
|
|
- .conn_int_min = 0x18, // 30 ms
|
|
|
|
|
- .conn_int_max = 0x24, // 45 ms
|
|
|
|
|
|
|
+ .conn_int_min = CONNECTION_INTERVAL_MIN,
|
|
|
|
|
+ .conn_int_max = CONNECTION_INTERVAL_MAX,
|
|
|
.slave_latency = 0,
|
|
.slave_latency = 0,
|
|
|
.supervisor_timeout = 0,
|
|
.supervisor_timeout = 0,
|
|
|
}};
|
|
}};
|
|
@@ -65,7 +74,7 @@ static void
|
|
|
// Set mac address
|
|
// Set mac address
|
|
|
memcpy(config->mac_address, furi_hal_version_get_ble_mac(), sizeof(config->mac_address));
|
|
memcpy(config->mac_address, furi_hal_version_get_ble_mac(), sizeof(config->mac_address));
|
|
|
|
|
|
|
|
- // Change MAC address for HID profile
|
|
|
|
|
|
|
+ // Change MAC address for Serial profile
|
|
|
config->mac_address[2]++;
|
|
config->mac_address[2]++;
|
|
|
if(serial_profile_params) {
|
|
if(serial_profile_params) {
|
|
|
config->mac_address[0] ^= serial_profile_params->mac_xor;
|
|
config->mac_address[0] ^= serial_profile_params->mac_xor;
|
|
@@ -73,23 +82,17 @@ static void
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Set advertise name
|
|
// Set advertise name
|
|
|
- memset(config->adv_name, 0, sizeof(config->adv_name));
|
|
|
|
|
-
|
|
|
|
|
const char* clicker_str = "Serial";
|
|
const char* clicker_str = "Serial";
|
|
|
if(serial_profile_params && serial_profile_params->device_name_prefix) {
|
|
if(serial_profile_params && serial_profile_params->device_name_prefix) {
|
|
|
clicker_str = serial_profile_params->device_name_prefix;
|
|
clicker_str = serial_profile_params->device_name_prefix;
|
|
|
}
|
|
}
|
|
|
- // We don't have Flipper in BLE name, use printf instead of replace
|
|
|
|
|
- FuriString* name = furi_string_alloc_printf(
|
|
|
|
|
|
|
+ snprintf(
|
|
|
|
|
+ config->adv_name,
|
|
|
|
|
+ sizeof(config->adv_name),
|
|
|
"%c%s %s",
|
|
"%c%s %s",
|
|
|
furi_hal_version_get_ble_local_device_name_ptr()[0],
|
|
furi_hal_version_get_ble_local_device_name_ptr()[0],
|
|
|
clicker_str,
|
|
clicker_str,
|
|
|
- furi_hal_version_get_ble_local_device_name_ptr() + 1);
|
|
|
|
|
- if(furi_string_size(name) >= sizeof(config->adv_name)) {
|
|
|
|
|
- furi_string_left(name, sizeof(config->adv_name) - 1);
|
|
|
|
|
- }
|
|
|
|
|
- memcpy(config->adv_name, furi_string_get_cstr(name), furi_string_size(name));
|
|
|
|
|
- furi_string_free(name);
|
|
|
|
|
|
|
+ furi_hal_version_get_name_ptr());
|
|
|
|
|
|
|
|
config->adv_service.UUID_Type = UUID_TYPE_16;
|
|
config->adv_service.UUID_Type = UUID_TYPE_16;
|
|
|
config->adv_service.Service_UUID_16 |= furi_hal_version_get_hw_color();
|
|
config->adv_service.Service_UUID_16 |= furi_hal_version_get_hw_color();
|
|
@@ -101,7 +104,7 @@ static const FuriHalBleProfileTemplate profile_callbacks = {
|
|
|
.get_gap_config = ble_profile_serial_get_config,
|
|
.get_gap_config = ble_profile_serial_get_config,
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
-const FuriHalBleProfileTemplate* ble_profile_serial = &profile_callbacks;
|
|
|
|
|
|
|
+const FuriHalBleProfileTemplate* const ble_profile_serial = &profile_callbacks;
|
|
|
|
|
|
|
|
void ble_profile_serial_set_event_callback(
|
|
void ble_profile_serial_set_event_callback(
|
|
|
FuriHalBleProfileBase* profile,
|
|
FuriHalBleProfileBase* profile,
|