8000 Split out BluetoothHCI for shared usage (#2194) · TGralla/arduino-pico@f786583 · GitHub
[go: up one dir, main page]

8000 Skip to content

Commit f786583

Browse files
Split out BluetoothHCI for shared usage (earlephilhower#2194)
1 parent 5f6fb75 commit f786583

File tree

13 files changed

+96
-30
lines changed

13 files changed

+96
-30
lines changed

libraries/BluetoothAudio/keywords.txt

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77
#######################################
88

99
BluetoothAudio KEYWORD1
10-
BluetoothHCI KEYWORD1
1110
A2DPSource KEYWORD1
12-
BTDeviceInfo KEYWORD1
1311
BluetoothAudioConsumer KEYWORD1
1412
BluetoothAudioConsumerI2S KEYWORD1
1513
BluetoothAudioConsumerPWM KEYWORD1
@@ -18,6 +16,7 @@ A2DPSink KEYWORD1
1816
#######################################
1917
# Methods and Functions (KEYWORD2)
2018
#######################################
19+
scan KEYWORD2
2120
begin KEYWORD2
2221
end KEYWORD2
2322

@@ -52,13 +51,6 @@ onVolume KEYWORD2
5251
onConnect KEYWORD2
5352
onPlaybackStatus KEYWORD2
5453

55-
# BTDeviceInfo
56-
deviceClass KEYWORD2
57-
address KEYWORD2
58-
addressString KEYWORD2
59-
rssi KEYWORD2
60-
name KEYWORD2
61-
6254
#######################################
6355
# Constants (LITERAL1)
6456
#######################################

libraries/BluetoothAudio/library.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ category=Communication
88
url=http://github.com/earlephilhower/arduino-pico
99
architectures=rp2040
1010
dot_a_linkage=true
11+
depends=BluetoothHCI

libraries/BluetoothAudio/src/A2DPSink.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
#pragma once
2222

2323
#include <Arduino.h>
24-
#include "BluetoothHCI.h"
25-
#include "BluetoothLock.h"
24+
#include <BluetoothHCI.h>
25+
#include <BluetoothLock.h>
2626
#include "BluetoothAudioConsumer.h"
2727
#include "BluetoothMediaConfigurationSBC.h"
2828

@@ -231,7 +231,7 @@ class A2DPSink : public Stream {
231231
void avrcp_target_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size);
232232
void a2dp_sink_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size);
233233

234-
BluetoothHCI_ _hci;
234+
BluetoothHCI _hci;
235235
BluetoothAudioConsumer_ *_consumer = nullptr;
236236
bool _running = false;
237237
bool _connected = false;

libraries/BluetoothAudio/src/A2DPSource.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
#pragma once
2222

2323
#include <Arduino.h>
24-
#include "BluetoothHCI.h"
25-
#include "BluetoothLock.h"
24+
#include <BluetoothHCI.h>
25+
#include <BluetoothLock.h>
2626
#include "BluetoothMediaConfigurationSBC.h"
2727
#include <functional>
2828
#include <list>
@@ -104,7 +104,7 @@ class A2DPSource : public Stream {
104104

105105
bool begin();
106106

107-
std::list<BTDeviceInfo> scan(uint32_t mask = BluetoothHCI_::speaker_cod, int scanTimeSec = 5, bool async = false) {
107+
std::list<BTDeviceInfo> scan(uint32_t mask = BluetoothHCI::speaker_cod, int scanTimeSec = 5, bool async = false) {
108108
return _hci.scan(mask, scanTimeSec, async);
109109
}
110110

@@ -144,7 +144,7 @@ class A2DPSource : public Stream {
144144

145145

146146
private:
147-
BluetoothHCI_ _hci;
147+
BluetoothHCI _hci;
148148
bool _running = false;
149149
bool _connected = false;
150150

libraries/BluetoothAudio/src/BluetoothAudio.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#include "BluetoothLock.h"
2-
#include "BluetoothDevice.h"
3-
#include "BluetoothHCI.h"
1+
#include <BluetoothLock.h>
2+
#include <BluetoothDevice.h>
3+
#include <BluetoothHCI.h>
44
#include "BluetoothMediaConfigurationSBC.h"
55
#include "A2DPSource.h"
66
#include "A2DPSink.h"
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include <BluetoothHCI.h>
2+
3+
BluetoothHCI hci;
4+
5+
void BTBasicSetup() {
6+
l2cap_init();
7+
sm_init();
8+
gap_set_default_link_policy_settings(LM_LINK_POLICY_ENABLE_SNIFF_MODE | LM_LINK_POLICY_ENABLE_ROLE_SWITCH);
9+
hci_set_master_slave_policy(HCI_ROLE_MASTER);
10+
hci_set_inquiry_mode(INQUIRY_MODE_RSSI_AND_EIR);
11+
12+
hci.install();
13+
hci.begin();
14+
}
15+
16+
void setup() {
17+
delay(5000);
18+
BTBasicSetup();
19+
}
20+
21+
void loop() {
22+
Serial.printf("BEGIN SCAN @%lu ...", millis());
23+
auto l = hci.scan(BluetoothHCI::any_cod);
24+
Serial.printf("END SCAN @%lu\n\n", millis());
25+
Serial.printf("%-8s | %-17s | %-4s | %s\n", "Class", "Address", "RSSI", "Name");
26+
Serial.printf("%-8s | %-17s | %-4s | %s\n", "--------", "-----------------", "----", "----------------");
27+
for (auto e : l) {
28+
Serial.printf("%08lx | %17s | %4d | %s\n", e.deviceClass(), e.addressString(), e.rssi(), e.name());
29+
}
30+
Serial.printf("\n\n\n");
31+
}

libraries/BluetoothHCI/keywords.txt

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#######################################
2+
# Syntax Coloring Map
3+
#######################################
4+
5+
#######################################
6+
# Datatypes (KEYWORD1)
7+
#######################################
8+
9+
BluetoothHCI KEYWORD1
10+
BTDeviceInfo KEYWORD1
11+
BluetoothLock KEYWORD1
12+
13+
#######################################
14+
# Methods and Functions (KEYWORD2)
15+
#######################################
16+
begin KEYWORD2
17+
end KEYWORD2
18+
19+
scan KEYWORD2
20+
scanAsyncDone KEYWORD2
21+
scanAsyncResult KEYWORD2
22+
23+
# BTDeviceInfo
24+
deviceClass KEYWORD2
25+
address KEYWORD2
26+
addressString KEYWORD2
27+
rssi KEYWORD2
28+
name KEYWORD2
29+
30+
#######################################
31+
# Constants (LITERAL1)
32+
#######################################
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name=BluetoothHCI
2+
version=1.0
3+
author=Earle F. Philhower, III <earlephilhower@yahoo.com>
4+
maintainer=Earle F. Philhower, III <earlephilhower@yahoo.com>
5+
sentence=Classic Bluetooth HCI functionality
6+
paragraph=Classic Bluetooth HCI functionality
7+
category=Communication
8+
url=http://github.com/earlephilhower/arduino-pico
9+
architectures=rp2040
10+
dot_a_linkage=true

libraries/BluetoothAudio/src/BluetoothHCI.cpp renamed to libraries/BluetoothHCI/src/BluetoothHCI.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,28 +35,28 @@
3535
static_cast<btstack_packet_handler_t>(_BTHCICB<void(uint8_t, uint16_t, uint8_t*, uint16_t), __COUNTER__ - 1>::callback))
3636

3737

38-
void BluetoothHCI_::install() {
38+
void BluetoothHCI::install() {
3939
// Register for HCI events.
40-
hci_event_callback_registration.callback = PACKETHANDLERCB(BluetoothHCI_, hci_packet_handler);
40+
hci_event_callback_registration.callback = PACKETHANDLERCB(BluetoothHCI, hci_packet_handler);
4141
hci_add_event_handler(&hci_event_callback_registration);
4242
}
4343

44-
void BluetoothHCI_::begin() {
44+
void BluetoothHCI::begin() {
4545
_running = true;
4646
hci_power_control(HCI_POWER_ON);
4747
}
4848

49-
void BluetoothHCI_::uninstall() {
49+
void BluetoothHCI::uninstall() {
5050
BluetoothLock b;
5151
hci_remove_event_handler(&hci_event_callback_registration);
5252
_running = false;
5353
}
5454

55-
bool BluetoothHCI_::running() {
55+
bool BluetoothHCI::running() {
5656
return _hciRunning;
5757
}
5858

59-
std::list<BTDeviceInfo> BluetoothHCI_::scan(uint32_t mask, int scanTimeSec, bool async) {
59+
std::list<BTDeviceInfo> BluetoothHCI::scan(uint32_t mask, int scanTimeSec, bool async) {
6060
_scanMask = mask;
6161
_btdList.clear();
6262
if (!_running) {
@@ -88,15 +88,15 @@ std::list<BTDeviceInfo> BluetoothHCI_::scan(uint32_t mask, int scanTimeSec, bool
8888
return _btdList;
8989
}
9090

91-
bool BluetoothHCI_::scanAsyncDone() {
91+
bool BluetoothHCI::scanAsyncDone() {
9292
return _scanning;
9393
}
94-
std::list<BTDeviceInfo> BluetoothHCI_::scanAsyncResult() {
94+
std::list<BTDeviceInfo> BluetoothHCI::scanAsyncResult() {
9595
return _btdList;
9696
}
9797

9898

99-
void BluetoothHCI_::hci_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size) {
99+
void BluetoothHCI::hci_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size) {
100100
(void)channel;
101101
(void)size;
102102

0 commit comments

Comments
 (0)
0