2020-06-02 21:24:40 +00:00
|
|
|
#pragma once
|
|
|
|
#include <stratosphere.hpp>
|
|
|
|
#include <switch.h>
|
|
|
|
|
|
|
|
#define BLUETOOTH_CIRCBUFFER_SIZE 10000
|
|
|
|
|
|
|
|
namespace ams::bluetooth {
|
|
|
|
|
|
|
|
enum CircularBufferType {
|
2020-07-30 20:10:37 +00:00
|
|
|
CircularBufferType_Other,
|
|
|
|
CircularBufferType_HidReport,
|
2020-06-02 21:24:40 +00:00
|
|
|
CircularBufferType_Bluetooth,
|
|
|
|
CircularBufferType_Ble,
|
|
|
|
CircularBufferType_BleCore,
|
|
|
|
CircularBufferType_BleHid,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct CircularBufferPacketHeader{
|
2020-07-27 21:33:07 +00:00
|
|
|
u8 type;
|
|
|
|
os::Tick timestamp;
|
|
|
|
u64 size;
|
2020-06-02 21:24:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct CircularBufferPacket{
|
|
|
|
CircularBufferPacketHeader header;
|
2020-07-11 11:43:21 +00:00
|
|
|
BluetoothHidReportData data;
|
2020-06-02 21:24:40 +00:00
|
|
|
};
|
|
|
|
|
2020-07-27 21:33:07 +00:00
|
|
|
class CircularBuffer {
|
|
|
|
|
|
|
|
public:
|
2020-06-02 21:24:40 +00:00
|
|
|
CircularBuffer(void);
|
|
|
|
|
2020-06-15 09:07:00 +00:00
|
|
|
void Initialize(const char *name); // 10.0.0+, previously took event argument
|
2020-06-02 21:24:40 +00:00
|
|
|
void Finalize(void);
|
|
|
|
bool IsInitialized(void);
|
2020-07-30 20:10:37 +00:00
|
|
|
u64 GetWriteableSize(void);
|
2020-07-05 12:10:45 +00:00
|
|
|
void SetWriteCompleteEvent(os::EventType *event);
|
2020-07-30 20:10:37 +00:00
|
|
|
u64 Write(u8 type, void *data, size_t size);
|
|
|
|
void DiscardOldPackets(u8 type, u32 ageLimit);
|
|
|
|
CircularBufferPacket *Read(void);
|
|
|
|
u64 Free(void);
|
2020-06-02 21:24:40 +00:00
|
|
|
|
2020-07-27 21:33:07 +00:00
|
|
|
private:
|
2020-06-02 21:24:40 +00:00
|
|
|
void _setReadOffset(u32 offset);
|
|
|
|
void _setWriteOffset(u32 offset);
|
|
|
|
u32 _getWriteOffset(void);
|
|
|
|
u32 _getReadOffset(void);
|
|
|
|
u64 _write(u8 type, void *data, size_t size);
|
|
|
|
void _updateUtilization(void);
|
2020-07-30 20:10:37 +00:00
|
|
|
CircularBufferPacket *_read(void);
|
2020-06-02 21:24:40 +00:00
|
|
|
|
2020-06-11 14:03:41 +00:00
|
|
|
os::SdkMutex mutex;
|
|
|
|
os::EventType *event;
|
2020-06-02 21:24:40 +00:00
|
|
|
|
|
|
|
u8 data[BLUETOOTH_CIRCBUFFER_SIZE];
|
|
|
|
u32 writeOffset;
|
|
|
|
u32 readOffset;
|
|
|
|
s64 size;
|
|
|
|
char name[16];
|
|
|
|
u8 _unk1;
|
|
|
|
bool isInitialized;
|
|
|
|
u8 _unk2[6];
|
2020-07-27 21:33:07 +00:00
|
|
|
|
|
|
|
public:
|
2020-06-15 09:07:00 +00:00
|
|
|
CircularBufferType type;
|
2020-06-02 21:24:40 +00:00
|
|
|
bool _unk3;
|
|
|
|
//u8 _unk3[4];
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|