Control Surface main
MIDI Control Surface library for Arduino
Loading...
Searching...
No Matches
advertising.cpp
Go to the documentation of this file.
1#if defined(ARDUINO_RASPBERRY_PI_PICO_W) && ENABLE_BLE
2
3#include <btstack.h>
4
5#include "advertising.hpp"
6
7#include <cstring>
8
9namespace cs::midi_ble_btstack {
10
11namespace {
12
14 // Flags general discoverable
15 0x02, BLUETOOTH_DATA_TYPE_FLAGS, 0x06,
16 // Connection interval range
18 0x00,
19 // Service UUID
21 0x00, 0xc7, 0xc4, 0x4e, 0xe3, 0x6c, 0x51, 0xa7, 0x33, 0x4b, 0xe8, 0xed,
22 0x5a, 0x0e, 0xb8, 0x03};
23static_assert(sizeof(adv_data) <= LE_ADVERTISING_DATA_SIZE);
25 // Name header
27 // Name value
28 'C', 'o', 'n', 't', 'r', 'o', 'l', ' ', 'S', 'u', 'r', 'f', 'a', 'c', 'e',
29 ' ', 'M', 'I', 'D', 'I'};
30uint8_t adv_rsp_data_len() { return adv_rsp_data[0] + 1; }
31
34 slave_itvl_range[0] = (min_itvl >> 0) & 0xFF;
35 slave_itvl_range[1] = (min_itvl >> 8) & 0xFF;
36 slave_itvl_range[2] = (max_itvl >> 0) & 0xFF;
37 slave_itvl_range[3] = (max_itvl >> 8) & 0xFF;
38}
39
40void set_adv_name(const char *name) {
41 auto len = std::min(std::strlen(name), sizeof(adv_rsp_data) - 2);
44 std::memcpy(adv_name, name, len);
45 *adv_name_len = static_cast<uint8_t>(len + 1);
46}
47
48} // namespace
49
50void le_midi_setup_adv(const BLESettings &ble_settings) {
51 set_adv_name(ble_settings.device_name);
53 ble_settings.connection_interval.maximum);
54 uint16_t adv_int_min = 0x0020; // 20 ms (multiple of 0.625ms)
55 uint16_t adv_int_max = 0x0040; // 40 ms (multiple of 0.625ms)
56 uint8_t adv_type = 0;
58 uint8_t channel_map = 0x07; // All channels
59 uint8_t filter_policy = 0x00; // Allow any
65}
66
67} // namespace cs::midi_ble_btstack
68
69#endif
Array< T, N > copyAs(const Array< U, N > &src)
Copy an Array to an Array of a different type.
void le_midi_setup_adv(const BLESettings &ble_settings)
Configuration options for the low-level BLE code.
Definition BLEAPI.hpp:150
struct BLESettings::@4 connection_interval
Connection intervals as multiples of 1.25 milliseconds (e.g.0x000C = 15 ms).
uint16_t maximum
Definition BLEAPI.hpp:157
const char * device_name
Device name (used for advertising)
Definition BLEAPI.hpp:152
uint16_t minimum
Definition BLEAPI.hpp:156