Skip to content

Commit a44b061

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

File tree

5 files changed

+108
-2
lines changed

5 files changed

+108
-2
lines changed

.github/workflows/arduino-ci.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ jobs:
3131
- "esp32:esp32:esp32"
3232
- "esp32:esp32:esp32s3"
3333
- "esp32:esp32:esp32c3"
34-
nimble: [ false, true ]
34+
nimble:
35+
- false
36+
- true
3537
fail-fast: false
3638

3739
steps:
@@ -40,6 +42,8 @@ jobs:
4042
- uses: arduino/compile-sketches@v1
4143
with:
4244
fqbn: ${{ matrix.fqbn }}
45+
sketch-paths: |
46+
- examples/SerialToSerialBLE
4347
libraries: |
4448
- source-path: ./
4549
- name: NimBLE-Arduino

.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

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ This library allows using Nordic UART Service (NUS) with ESP32 Arduino.
1111
[![GitHub release](https://img.shields.io/github/v/release/senseshift/arduino-ble-serial)](https://github.com/senseshift/arduino-ble-serial/releases/latest)
1212

1313
[![PlatformIO CI](https://github.com/senseshift/arduino-ble-serial/actions/workflows/platformio-ci.yml/badge.svg)](https://github.com/senseshift/arduino-ble-serial/actions/workflows/platformio-ci.yml)
14-
[![PlatformIO CI](https://github.com/senseshift/arduino-ble-serial/actions/workflows/arduino-ci.yml/badge.svg)](https://github.com/senseshift/arduino-ble-serial/actions/workflows/arduino-ci.yml)
14+
[![Arduino CI](https://github.com/senseshift/arduino-ble-serial/actions/workflows/arduino-ci.yml/badge.svg)](https://github.com/senseshift/arduino-ble-serial/actions/workflows/arduino-ci.yml)
1515

1616
[![MIT](https://img.shields.io/github/license/senseshift/arduino-ble-serial)](/LICENSE)
1717
[![GitHub contributors](https://img.shields.io/github/contributors/senseshift/arduino-ble-serial)](https://github.com/senseshift/arduino-ble-serial/graphs/contributors)
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)