12#include <hardware/sync.h>
36 bool notify)
override {
55 static_assert(
sizeof(sig_atomic_t) >
sizeof(uint16_t));
61 constexpr static size_t alignment =
alignof(sig_atomic_t);
65 auto state = save_and_disable_interrupts();
67 restore_interrupts(state);
68 std::atomic_signal_fence(std::memory_order_acquire);
72 std::atomic_signal_fence(std::memory_order_release);
73 auto state = save_and_disable_interrupts();
75 restore_interrupts(state);
78 std::atomic_signal_fence(std::memory_order_release);
79 auto state = save_and_disable_interrupts();
81 restore_interrupts(state);
97 return parser.popMessage(incomingMessage);
103 midi_ble_btstack::init(*
this, ble_settings);
119 midi_ble_btstack::notify(
Type definitions and callback interfaces for communication between the low-level BLE stacks and highe...
BLEDataLifetime
Should a buffer of BLEData be consumed immediately inside of the callback, or can we hold on to it an...
#define BEGIN_CS_NAMESPACE
Callable that returns the next chunk of data from a BLE packet when called.
Raspberry Pi Pico BTstack background backend intended to be plugged into GenericBLEMIDI_Interface.
void handleConnect(BLEConnectionHandle conn_handle) override
Called by the BLE stack when a connection is established.
BufferedBLEMIDIParser< 1024, VolatileSize > parser
Contains incoming BLE MIDI data to be parsed.
void handleMTU(BLEConnectionHandle, uint16_t mtu) override
Called by the BLE stack when the maximum transmission unit for the connection changes.
void sendData(BLEDataView data)
Send the given MIDI BLE packet.
void handleData(BLEConnectionHandle, BLEDataGenerator &&data, BLEDataLifetime) override
Called by the BLE stack when the central writes data to the MIDI GATT characteristic.
volatile sig_atomic_t connected
Are we connected to a BLE Central?
void begin(BLESettings ble_settings)
Initialize the BLE stack etc.
bool isConnected() const
Returns true if we are connected to a BLE Central device.
volatile sig_atomic_t subscribed
Did the BLE Central subscribe to be notified for the MIDI characteristic?
void end()
Deinitialize the BLE stack.
bool popMessage(IncomingMIDIMessage &incomingMessage)
Retrieve and remove a single incoming MIDI message from the buffer.
void handleDisconnect(BLEConnectionHandle) override
Called by the BLE stack when a connection is terminated.
void handleSubscribe(BLEConnectionHandle, BLECharacteristicHandle char_handle, bool notify) override
Called by the BLE stack when the central subscribes to receive notifications for the MIDI GATT charac...
FIFO buffer that you can push BLE packets into, and pop MIDI messages out of.
Defines the interface for callback functions registered by the low-level BLE code.
Class that buffers MIDI BLE packets.
BLEMIDIPacketBuilder packet
View of the data to send.
uint16_t getMinMTU() const
Get the minimum MTU of all connected clients.
void setTimeout(std::chrono::milliseconds timeout)
Set the timeout, the number of milliseconds to buffer the outgoing MIDI messages.
void forceMinMTU(uint16_t mtu)
Force the MTU to an artificially small value (used for testing).
ProtectedBuilder acquirePacket()
Acquire exclusive access to the buffer.
void releasePacketAndNotify(ProtectedBuilder &lck)
Release exclusive access to the buffer and notify the sender thread that data is available.
void updateMTU(uint16_t mtu)
Set the maximum transmission unit of the Bluetooth link.
void sendNow(ProtectedBuilder &lck)
Sends the data immediately without waiting for the timeout.
#define DEBUGREF(x)
Print an expression and its location (file and line number) to the debug output if debugging is enabl...
MIDI message variant type (with timestamp).
Represents a handle to a local GATT characteristic.
Represents a handle to the connection to another device.
Non-owning, std::span-style read-only view of BLE data.
Configuration options for the low-level BLE code.
sig_atomic_t load_acquire() const
volatile sig_atomic_t value
void add_release(sig_atomic_t t)
VolatileSize(sig_atomic_t value)
static constexpr size_t alignment
void sub_release(sig_atomic_t t)