Skip to content

Commit 93315a9

Browse files
add support for silabs core
1 parent 98ff550 commit 93315a9

7 files changed

+181
-1
lines changed

Diff for: src/BLECharacteristic.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424

2525
#include "BLECharacteristic.h"
2626

27+
extern "C" int strcasecmp(char const *a, char const *b);
28+
2729
BLECharacteristic::BLECharacteristic() :
2830
BLECharacteristic((BLELocalCharacteristic*)NULL)
2931
{

Diff for: src/BLEDevice.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525

2626
#include "BLEDevice.h"
2727

28+
extern "C" int strcasecmp(char const *a, char const *b);
29+
2830
BLEDevice::BLEDevice() :
2931
_advertisementTypeMask(0),
3032
_eirDataLength(0),

Diff for: src/BLEService.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222

2323
#include "BLEService.h"
2424

25+
extern "C" int strcasecmp(char const *a, char const *b);
26+
2527
BLEService::BLEService() :
2628
BLEService((BLELocalService*)NULL)
2729
{

Diff for: src/utility/ATT.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434

3535
#include "ATT.h"
3636

37+
extern "C" int strcasecmp(char const *a, char const *b);
38+
3739
#define ATT_OP_ERROR 0x01
3840
#define ATT_OP_MTU_REQ 0x02
3941
#define ATT_OP_MTU_RESP 0x03

Diff for: src/utility/HCISilabsTransport.cpp

+130
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
/*
2+
This file is part of the ArduinoBLE library.
3+
Copyright (c) 2024 Arduino SA. All rights reserved.
4+
5+
This library is free software; you can redistribute it and/or
6+
modify it under the terms of the GNU Lesser General Public
7+
License as published by the Free Software Foundation; either
8+
version 2.1 of the License, or (at your option) any later version.
9+
10+
This library is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
Lesser General Public License for more details.
14+
15+
You should have received a copy of the GNU Lesser General Public
16+
License along with this library; if not, write to the Free Software
17+
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18+
*/
19+
20+
#if defined(ARDUINO_SILABS)
21+
22+
#include "HCISilabsTransport.h"
23+
#include "sl_string.h"
24+
25+
extern "C" {
26+
#include "sl_btctrl_linklayer.h"
27+
#include "sl_hci_common_transport.h"
28+
}
29+
30+
extern "C" int strcasecmp(char const *a, char const *b) {
31+
return sl_strcasecmp(a, b);
32+
}
33+
34+
static RingBufferN<512> buf;
35+
36+
HCISilabsTransportClass::HCISilabsTransportClass()
37+
{
38+
}
39+
40+
HCISilabsTransportClass::~HCISilabsTransportClass()
41+
{
42+
}
43+
44+
int HCISilabsTransportClass::begin()
45+
{
46+
if(!sl_btctrl_is_initialized()) {
47+
sl_bt_controller_init();
48+
}
49+
50+
/* Initialize adv & scan components */
51+
sl_btctrl_init_adv();
52+
sl_btctrl_init_scan();
53+
sl_btctrl_init_conn();
54+
sl_btctrl_init_adv_ext();
55+
sl_btctrl_init_scan_ext();
56+
57+
/* Initialize HCI controller */
58+
sl_bthci_init_upper();
59+
sl_btctrl_hci_parser_init_default();
60+
sl_btctrl_hci_parser_init_conn();
61+
sl_btctrl_hci_parser_init_adv();
62+
sl_btctrl_hci_parser_init_phy();
63+
64+
return 1;
65+
}
66+
67+
void HCISilabsTransportClass::end()
68+
{
69+
sl_bt_controller_deinit();
70+
}
71+
72+
void HCISilabsTransportClass::wait(unsigned long timeout)
73+
{
74+
for (unsigned long start = millis(); (millis() - start) < timeout;) {
75+
if (available()) {
76+
break;
77+
}
78+
}
79+
}
80+
81+
int HCISilabsTransportClass::available()
82+
{
83+
return buf.available();
84+
}
85+
86+
int HCISilabsTransportClass::peek()
87+
{
88+
return buf.peek();
89+
}
90+
91+
int HCISilabsTransportClass::read()
92+
{
93+
return buf.read_char();
94+
}
95+
96+
size_t HCISilabsTransportClass::write(const uint8_t* data, size_t len)
97+
{
98+
int ret = 0;
99+
ret = hci_common_transport_receive((uint8_t *)data, len, true);
100+
101+
if (ret == 0) return len;
102+
103+
return 0;
104+
}
105+
106+
extern "C" {
107+
/**
108+
* @brief Transmit HCI message using the currently used transport layer.
109+
* The HCI calls this function to transmit a full HCI message.
110+
* @param[in] data Packet type followed by HCI packet data.
111+
* @param[in] len Length of the `data` parameter
112+
* @return 0 - on success, or non-zero on failure.
113+
*/
114+
uint32_t hci_common_transport_transmit(uint8_t *data, int16_t len)
115+
{
116+
for (int i = 0; i < len; i++) {
117+
buf.store_char(data[i]);
118+
if (buf.isFull()) return SL_STATUS_FAIL;
119+
}
120+
121+
sl_btctrl_hci_transmit_complete(0);
122+
return 0;
123+
}
124+
}
125+
126+
HCISilabsTransportClass HCISilabsTransport;
127+
128+
HCITransportInterface& HCITransport = HCISilabsTransport;
129+
130+
#endif

Diff for: src/utility/HCISilabsTransport.h

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
This file is part of the ArduinoBLE library.
3+
Copyright (c) 2018 Arduino SA. All rights reserved.
4+
5+
This library is free software; you can redistribute it and/or
6+
modify it under the terms of the GNU Lesser General Public
7+
License as published by the Free Software Foundation; either
8+
version 2.1 of the License, or (at your option) any later version.
9+
10+
This library is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
Lesser General Public License for more details.
14+
15+
You should have received a copy of the GNU Lesser General Public
16+
License along with this library; if not, write to the Free Software
17+
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18+
*/
19+
20+
#ifndef _HCI_SILABS_TRANSPORT_H_
21+
#define _HCI_SILABS_TRANSPORT_H_
22+
23+
#include "HCITransport.h"
24+
25+
class HCISilabsTransportClass : public HCITransportInterface {
26+
public:
27+
HCISilabsTransportClass();
28+
virtual ~HCISilabsTransportClass();
29+
30+
virtual int begin();
31+
virtual void end();
32+
33+
virtual void wait(unsigned long timeout);
34+
35+
virtual int available();
36+
virtual int peek();
37+
virtual int read();
38+
39+
virtual size_t write(const uint8_t* data, size_t length);
40+
};
41+
42+
#endif

Diff for: src/utility/HCIUartTransport.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1818
*/
1919

20-
#if !defined(ARDUINO_ARCH_MBED) && !defined(ESP32) && !defined(ARDUINO_UNOR4_WIFI) || defined(TARGET_NANO_RP2040_CONNECT) //|| defined(CORE_CM4)
20+
#if !defined(ARDUINO_ARCH_MBED) && !defined(ESP32) && !defined(ARDUINO_SILABS) && !defined(ARDUINO_UNOR4_WIFI) || defined(TARGET_NANO_RP2040_CONNECT) //|| defined(CORE_CM4)
2121

2222
#include "HCIUartTransport.h"
2323

0 commit comments

Comments
 (0)