Skip to content

Commit 8e26152

Browse files
committed
📝 Add Microchip Transparent UART
1 parent 113a1f3 commit 8e26152

File tree

3 files changed

+102
-0
lines changed

3 files changed

+102
-0
lines changed

.github/workflows/platformio-ci.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,18 @@ jobs:
2121
os: [ ubuntu-latest ]
2222
example:
2323
- "SerialToSerialBLE"
24+
- "SerialToSerialBLE_TransparentUART"
25+
- "SerialToSerialBLE_TransparentUART-NimBLE"
2426
boards:
2527
- [ esp32dev, esp32-s3-devkitc-1, esp32-c3-devkitm-1 ]
2628
nimble: [ false, true ]
2729

30+
exclude:
31+
- example: "SerialToSerialBLE_TransparentUART"
32+
nimble: true
33+
- example: "SerialToSerialBLE_TransparentUART-NimBLE"
34+
nimble: false
35+
2836
steps:
2937
- uses: actions/checkout@v4
3038

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#include <BLESerial.h>
2+
3+
// FOR ETL: Uncomment the following lines
4+
// #include <Embedded_Template_Library.h>
5+
// #include <etl/queue.h>
6+
// #include <etl/circular_buffer.h>
7+
8+
BLESerial SerialBLE;
9+
// If you are using older version of Arduino IDE, you may need to use
10+
// empty template argument (<>), due to the old C++ compiler version (<=std=c++17).
11+
// https://www.cppreference.com/w/cpp/language/ctad.html
12+
//
13+
// Uncomment the line below if you are using an older version of Arduino IDE/C++ compiler
14+
// BLESerial<> SerialBLE;
15+
16+
// FOR ETL: Uncomment one of the following lines
17+
// BLESerial<etl::queue<uint8_t, 255, etl::memory_model::MEMORY_MODEL_SMALL>> SerialBLE;
18+
// OR
19+
// BLESerial<etl::circular_buffer<uint8_t, 255>> SerialBLE;
20+
21+
void setup() {
22+
BLEDevice::init("ESP32-BLE-Slave");
23+
24+
BLEServer* pServer = BLEDevice::createServer();
25+
26+
// Transparent UART Service
27+
// https://developerhelp.microchip.com/xwiki/bin/view/applications/ble/android-development-for-bm70rn4870/transparent-uart-service-for-bm70rn4870/
28+
auto pService = pServer->createService("49535343-FE7D-4AE5-8FA9-9FAFD205E455");
29+
30+
auto pRxCharacteristic = pService->createCharacteristic("49535343-1E4D-4BD9-BA61-23C647249616", NIMBLE_PROPERTY::WRITE | NIMBLE_PROPERTY::WRITE_NR | NIMBLE_PROPERTY::NOTIFY);
31+
auto pTxCharacteristic = pService->createCharacteristic("49535343-8841-43F4-A8D4-ECBE34729BB3", NIMBLE_PROPERTY::READ | NIMBLE_PROPERTY::NOTIFY);
32+
33+
SerialBLE.begin(pRxCharacteristic, pTxCharacteristic);
34+
35+
BLEAdvertising* pAdvertising = pServer->getAdvertising();
36+
pAdvertising->start();
37+
}
38+
39+
void loop() {
40+
if (Serial.available()) {
41+
SerialBLE.write(Serial.read());
42+
SerialBLE.flush();
43+
}
44+
if (SerialBLE.available()) {
45+
Serial.write(SerialBLE.read());
46+
}
47+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#include <BLESerial.h>
2+
3+
// FOR ETL: Uncomment the following lines
4+
// #include <Embedded_Template_Library.h>
5+
// #include <etl/queue.h>
6+
// #include <etl/circular_buffer.h>
7+
8+
BLESerial SerialBLE;
9+
// If you are using older version of Arduino IDE, you may need to use
10+
// empty template argument (<>), due to the old C++ compiler version (<=std=c++17).
11+
// https://www.cppreference.com/w/cpp/language/ctad.html
12+
//
13+
// Uncomment the line below if you are using an older version of Arduino IDE/C++ compiler
14+
// BLESerial<> SerialBLE;
15+
16+
// FOR ETL: Uncomment one of the following lines
17+
// BLESerial<etl::queue<uint8_t, 255, etl::memory_model::MEMORY_MODEL_SMALL>> SerialBLE;
18+
// OR
19+
// BLESerial<etl::circular_buffer<uint8_t, 255>> SerialBLE;
20+
21+
void setup() {
22+
BLEDevice::init("ESP32-BLE-Slave");
23+
24+
BLEServer* pServer = BLEDevice::createServer();
25+
26+
// Transparent UART Service
27+
// https://developerhelp.microchip.com/xwiki/bin/view/applications/ble/android-development-for-bm70rn4870/transparent-uart-service-for-bm70rn4870/
28+
auto pService = pServer->createService("49535343-FE7D-4AE5-8FA9-9FAFD205E455");
29+
30+
auto pRxCharacteristic = pService->createCharacteristic("49535343-1E4D-4BD9-BA61-23C647249616", BLECharacteristic::PROPERTY_WRITE | BLECharacteristic::PROPERTY_WRITE_NR | BLECharacteristic::PROPERTY_NOTIFY);
31+
auto pTxCharacteristic = pService->createCharacteristic("49535343-8841-43F4-A8D4-ECBE34729BB3", BLECharacteristic::PROPERTY_READ | BLECharacteristic::PROPERTY_NOTIFY);
32+
33+
SerialBLE.begin(pRxCharacteristic, pTxCharacteristic);
34+
35+
BLEAdvertising* pAdvertising = pServer->getAdvertising();
36+
pAdvertising->start();
37+
}
38+
39+
void loop() {
40+
if (Serial.available()) {
41+
SerialBLE.write(Serial.read());
42+
SerialBLE.flush();
43+
}
44+
if (SerialBLE.available()) {
45+
Serial.write(SerialBLE.read());
46+
}
47+
}

0 commit comments

Comments
 (0)