diff options
author | Ryan <fauxpark@gmail.com> | 2021-09-21 19:58:46 +1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-21 19:58:46 +1000 |
commit | 20ea5f3fb5ba108153148e57981a7e804fd4be61 (patch) | |
tree | c6ff504e55d223df435ca439673e4771d480f079 /tmk_core/protocol/lufa/ringbuffer.hpp | |
parent | c38a7308054f2072d234ee0d44d3bea9f809a63d (diff) |
Relocate Adafruit BLE code (#14530)
Diffstat (limited to 'tmk_core/protocol/lufa/ringbuffer.hpp')
-rw-r--r-- | tmk_core/protocol/lufa/ringbuffer.hpp | 66 |
1 files changed, 0 insertions, 66 deletions
diff --git a/tmk_core/protocol/lufa/ringbuffer.hpp b/tmk_core/protocol/lufa/ringbuffer.hpp deleted file mode 100644 index 70a3c4881d..0000000000 --- a/tmk_core/protocol/lufa/ringbuffer.hpp +++ /dev/null @@ -1,66 +0,0 @@ -#pragma once -// A simple ringbuffer holding Size elements of type T -template <typename T, uint8_t Size> -class RingBuffer { - protected: - T buf_[Size]; - uint8_t head_{0}, tail_{0}; - public: - inline uint8_t nextPosition(uint8_t position) { - return (position + 1) % Size; - } - - inline uint8_t prevPosition(uint8_t position) { - if (position == 0) { - return Size - 1; - } - return position - 1; - } - - inline bool enqueue(const T &item) { - static_assert(Size > 1, "RingBuffer size must be > 1"); - uint8_t next = nextPosition(head_); - if (next == tail_) { - // Full - return false; - } - - buf_[head_] = item; - head_ = next; - return true; - } - - inline bool get(T &dest, bool commit = true) { - auto tail = tail_; - if (tail == head_) { - // No more data - return false; - } - - dest = buf_[tail]; - tail = nextPosition(tail); - - if (commit) { - tail_ = tail; - } - return true; - } - - inline bool empty() const { return head_ == tail_; } - - inline uint8_t size() const { - int diff = head_ - tail_; - if (diff >= 0) { - return diff; - } - return Size + diff; - } - - inline T& front() { - return buf_[tail_]; - } - - inline bool peek(T &item) { - return get(item, false); - } -}; |