]>
git.gir.st - tmk_keyboard.git/blob - tmk_core/ring_buffer.h
3 /*--------------------------------------------------------------------
4 * Ring buffer to store scan codes from keyboard
5 *------------------------------------------------------------------*/
7 static uint8_t rbuf
[RBUF_SIZE
];
8 static uint8_t rbuf_head
= 0;
9 static uint8_t rbuf_tail
= 0;
10 static inline void rbuf_enqueue(uint8_t data
)
14 uint8_t next
= (rbuf_head
+ 1) % RBUF_SIZE
;
15 if (next
!= rbuf_tail
) {
16 rbuf
[rbuf_head
] = data
;
19 print("rbuf: full\n");
23 static inline uint8_t rbuf_dequeue(void)
29 if (rbuf_head
!= rbuf_tail
) {
30 val
= rbuf
[rbuf_tail
];
31 rbuf_tail
= (rbuf_tail
+ 1) % RBUF_SIZE
;
37 static inline bool rbuf_has_data(void)
41 bool has_data
= (rbuf_head
!= rbuf_tail
);
45 static inline void rbuf_clear(void)
49 rbuf_head
= rbuf_tail
= 0;
53 #endif /* RING_BUFFER_H */