Files
MuditaOS/module-bsp/board/rt1051/bluetooth/BlueKitchen.cpp
Lefucjusz 2e04d268c4 [MOS-1068] Fix A2DP stream not restarting after song changes
Workaround for the issue that A2DP stream
would sometimes not restart when music
player changes song to the next one.
2024-05-29 17:33:30 +02:00

72 lines
1.8 KiB
C++

// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
#include "bsp/bluetooth/Bluetooth.hpp"
#include <log/log.hpp>
#include "FreeRTOS.h"
#if DEBUG_BLUETOOTH_HCI_COMS == 1
#define logHciStack(...) LOG_DEBUG(__VA_ARGS__)
#else
#define logHciStack(...)
#endif
using namespace bsp;
BlueKitchen::BlueKitchen()
{
readBuffer = nullptr;
readReadyCallback = nullptr;
writeDoneCallback = nullptr;
}
BlueKitchen::~BlueKitchen() = default;
BlueKitchen &BlueKitchen::getInstance()
{
static std::unique_ptr<BlueKitchen> instance;
if (instance == nullptr) {
instance = std::make_unique<BlueKitchen>();
}
return *instance;
}
BTDevice::Error BlueKitchen::read(std::uint8_t *buf, std::size_t size)
{
logHciStack("BlueKitchen requested to read %d bytes", size);
std::uint8_t val;
readBuffer = buf;
readLength = size;
if (BluetoothCommon::read(buf, size) == BTDevice::Error::Success) {
val = bluetooth::Message::EvtReceiving;
xQueueSend(qHandle, &val, portMAX_DELAY);
return BTDevice::Error::Success;
}
else {
val = bluetooth::Message::EvtReceivingError;
xQueueSend(qHandle, &val, portMAX_DELAY);
return BTDevice::Error::ErrorBSP;
}
}
BTDevice::Error BlueKitchen::write(const std::uint8_t *buf, std::size_t size)
{
logHciStack("BlueKitchen sends %d bytes", size);
std::uint8_t val;
if (BluetoothCommon::write(buf, size) == BTDevice::Error::Success) {
val = bluetooth::Message::EvtSending;
xQueueSend(qHandle, &val, portMAX_DELAY);
return BTDevice::Error::Success;
}
else {
val = bluetooth::Message::EvtSendingError;
xQueueSend(qHandle, &val, portMAX_DELAY);
return BTDevice::Error::ErrorBSP;
}
}