aboutsummaryrefslogtreecommitdiff
path: root/tmk_core/ring_buffer.h
diff options
context:
space:
mode:
Diffstat (limited to 'tmk_core/ring_buffer.h')
-rw-r--r--tmk_core/ring_buffer.h45
1 files changed, 0 insertions, 45 deletions
diff --git a/tmk_core/ring_buffer.h b/tmk_core/ring_buffer.h
deleted file mode 100644
index 8f887c8f7..000000000
--- a/tmk_core/ring_buffer.h
+++ /dev/null
@@ -1,45 +0,0 @@
1#pragma once
2
3/*--------------------------------------------------------------------
4 * Ring buffer to store scan codes from keyboard
5 *------------------------------------------------------------------*/
6#ifndef RBUF_SIZE
7# define RBUF_SIZE 32
8#endif
9#include <util/atomic.h>
10#include <stdint.h>
11#include <stdbool.h>
12static uint8_t rbuf[RBUF_SIZE];
13static uint8_t rbuf_head = 0;
14static uint8_t rbuf_tail = 0;
15static inline bool rbuf_enqueue(uint8_t data) {
16 bool ret = false;
17 ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
18 uint8_t next = (rbuf_head + 1) % RBUF_SIZE;
19 if (next != rbuf_tail) {
20 rbuf[rbuf_head] = data;
21 rbuf_head = next;
22 ret = true;
23 }
24 }
25 return ret;
26}
27static inline uint8_t rbuf_dequeue(void) {
28 uint8_t val = 0;
29 ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
30 if (rbuf_head != rbuf_tail) {
31 val = rbuf[rbuf_tail];
32 rbuf_tail = (rbuf_tail + 1) % RBUF_SIZE;
33 }
34 }
35
36 return val;
37}
38static inline bool rbuf_has_data(void) {
39 bool has_data;
40 ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { has_data = (rbuf_head != rbuf_tail); }
41 return has_data;
42}
43static inline void rbuf_clear(void) {
44 ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { rbuf_head = rbuf_tail = 0; }
45}