fix: Pi 4 Bluetooth - hold RTS deasserted across BT_ON power-on, require Read Local Version to sync, mini UART no flow control first

This commit is contained in:
daniel committed 2026-10-26 07:46:49 +01:00
1 parent 93d8becce3
commit 3310b3d6de
11 files changed
+210 -38

No files matched your search

+31
View File
@@ -1837,6 +1837,36 @@ namespace Drivers::Bluetooth::A2dp {
// ConfigureStream
// =========================================================================
// A UART transport has a hard byte budget: at 460800 baud it carries
// 46 KB/s, and SBC at bitpool 53 / 48 kHz needs ~46 KB/s with its
// headers, so the stream fell behind whenever anything else crossed the
// link and the sink played concealment. Keep the stream within three
// quarters of the line rate by lowering the bitpool (any value in the
// negotiated range is valid per frame). Over USB nothing changes.
static void FitBitpoolToTransport(uint32_t sampleRate) {
uint32_t budget = Hci::TransportBytesPerSecond() / 4 * 3;
if (budget == 0) return;
uint32_t rate = sampleRate ? sampleRate : 48000;
uint8_t minBitpool = g_cfgSbc[2] < 2 ? 2 : g_cfgSbc[2];
uint8_t original = g_sbcEncoder.Bitpool;
auto bytesPerSecond = [&]() {
// H4 + ACL + L2CAP + RTP + SCMS-T + SBC headers (23 bytes) per
// packet, spread over the ~4-5 frames bundled into each.
uint32_t frameCost = Sbc::GetFrameSize(&g_sbcEncoder) + 6;
return (uint64_t)frameCost * rate / Sbc::GetSamplesPerFrame(&g_sbcEncoder);
};
while (g_sbcEncoder.Bitpool > minBitpool && bytesPerSecond() > budget) {
Sbc::Configure(&g_sbcEncoder, g_cfgSbc[0], g_cfgSbc[1],
(uint8_t)(g_sbcEncoder.Bitpool - 1));
}
if (g_sbcEncoder.Bitpool != original) {
KernelLogStream(INFO, "BT-A2DP") << "Bitpool " << (uint64_t)original << " -> "
<< (uint64_t)g_sbcEncoder.Bitpool << " to fit the transport ("
<< bytesPerSecond() << " of " << (uint64_t)Hci::TransportBytesPerSecond()
<< " bytes/s)";
}
}
bool ConfigureStream(uint32_t sampleRate, uint8_t channels, uint8_t bitsPerSample) {
// Encoder configuration and PumpMedia both mutate the SBC encoder.
// Device switching normally configures an Open stream, but explicitly
@@ -1851,6 +1881,7 @@ namespace Drivers::Bluetooth::A2dp {
// agreed to (Init's defaults may differ from the negotiated subset).
if (g_cfgSbc[0] || g_cfgSbc[1]) {
Sbc::Configure(&g_sbcEncoder, g_cfgSbc[0], g_cfgSbc[1], g_cfgSbc[3]);
FitBitpoolToTransport(sampleRate);
}
g_sbcInitialized = true;
g_seqNum = 0;