59 lines
1.8 KiB
Markdown
59 lines
1.8 KiB
Markdown
# MIDI over BLE
|
|
|
|
> Original: [MIDI over BLE](https://tttapa.github.io/Control-Surface/Doxygen/db/d99/md_pages_MIDI-over-BLE.html)
|
|
|
|
BLE MIDI uses BTstack to advertise a standard MIDI BLE service. Compatible with macOS, iOS, Windows 10+, and Android.
|
|
|
|
## Backend
|
|
|
|
cs-midi uses the `BTstackBackgroundBackend`, which runs BLE asynchronously but requires periodic `update()` calls for outgoing message buffering.
|
|
|
|
The convenience typedef:
|
|
|
|
```cpp pico
|
|
using BluetoothMIDI_Interface = GenericBLEMIDI_Interface<BTstackBackgroundBackend>;
|
|
```
|
|
|
|
## Basic usage
|
|
|
|
```cpp pico
|
|
#include "pico/stdlib.h"
|
|
#include "pico/cyw43_arch.h"
|
|
#include <cs_midi.h>
|
|
|
|
using namespace cs;
|
|
|
|
BluetoothMIDI_Interface midi;
|
|
|
|
NoteButton button {5, {MIDI_Notes::C[4], Channel_1}};
|
|
|
|
int main() {
|
|
stdio_init_all();
|
|
if (cyw43_arch_init()) return 1;
|
|
Control_Surface.begin();
|
|
while (true) {
|
|
Control_Surface.loop();
|
|
sleep_ms(1);
|
|
}
|
|
}
|
|
```
|
|
|
|
`cyw43_arch_init()` is required to bring up the radio before BLE operations.
|
|
|
|
## HID keyboard + Battery Service
|
|
|
|
Build with `CS_MIDI_HID_KEYBOARD=ON` to advertise as a BLE HID keyboard alongside MIDI:
|
|
|
|
1. **Auto-reconnect** — the host OS auto-reconnects to bonded HID peripherals on power-up, bringing up the MIDI service without manual intervention.
|
|
2. **Battery level** — the standard Battery Service (UUID 0x180F) reports charge level. Update with:
|
|
|
|
```cpp pico
|
|
setBLEBatteryLevel(percent);
|
|
```
|
|
|
|
No keyboard input is sent — the HID descriptor exists solely to trigger OS auto-connect behavior and surface the battery indicator.
|
|
|
|
## Radio module
|
|
|
|
The BLE transport requires a CYW43 radio. Only the **Infineon RM2 module** has been tested. A board file for the Waveshare RP2350B Plus W (RM2-equipped) is provided at `boards/waveshare_rp2350b_plus_w.h`.
|