diff options
| author | Joel Challis <git@zvecr.com> | 2020-05-03 01:25:39 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-05-03 01:25:39 +0100 |
| commit | 5f82b0782f90645eee5926691dcc0ec617d0dff4 (patch) | |
| tree | a741b6b432d31c477d3781bde487b13ffb2b3d8a /tmk_core/ring_buffer.h | |
| parent | 2e6959ed874f19a5db9ee2b4db08c2bc9ec815d2 (diff) | |
| download | qmk_firmware-5f82b0782f90645eee5926691dcc0ec617d0dff4.tar.gz qmk_firmware-5f82b0782f90645eee5926691dcc0ec617d0dff4.zip | |
Initial vusb console support (#8559)
Diffstat (limited to 'tmk_core/ring_buffer.h')
| -rw-r--r-- | tmk_core/ring_buffer.h | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/tmk_core/ring_buffer.h b/tmk_core/ring_buffer.h index 6bea3509b..25fab638e 100644 --- a/tmk_core/ring_buffer.h +++ b/tmk_core/ring_buffer.h | |||
| @@ -3,21 +3,26 @@ | |||
| 3 | /*-------------------------------------------------------------------- | 3 | /*-------------------------------------------------------------------- |
| 4 | * Ring buffer to store scan codes from keyboard | 4 | * Ring buffer to store scan codes from keyboard |
| 5 | *------------------------------------------------------------------*/ | 5 | *------------------------------------------------------------------*/ |
| 6 | #define RBUF_SIZE 32 | 6 | #ifndef RBUF_SIZE |
| 7 | # define RBUF_SIZE 32 | ||
| 8 | #endif | ||
| 7 | #include <util/atomic.h> | 9 | #include <util/atomic.h> |
| 10 | #include <stdint.h> | ||
| 11 | #include <stdbool.h> | ||
| 8 | static uint8_t rbuf[RBUF_SIZE]; | 12 | static uint8_t rbuf[RBUF_SIZE]; |
| 9 | static uint8_t rbuf_head = 0; | 13 | static uint8_t rbuf_head = 0; |
| 10 | static uint8_t rbuf_tail = 0; | 14 | static uint8_t rbuf_tail = 0; |
| 11 | static inline void rbuf_enqueue(uint8_t data) { | 15 | static inline bool rbuf_enqueue(uint8_t data) { |
| 16 | bool ret = false; | ||
| 12 | ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { | 17 | ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { |
| 13 | uint8_t next = (rbuf_head + 1) % RBUF_SIZE; | 18 | uint8_t next = (rbuf_head + 1) % RBUF_SIZE; |
| 14 | if (next != rbuf_tail) { | 19 | if (next != rbuf_tail) { |
| 15 | rbuf[rbuf_head] = data; | 20 | rbuf[rbuf_head] = data; |
| 16 | rbuf_head = next; | 21 | rbuf_head = next; |
| 17 | } else { | 22 | ret = true; |
| 18 | print("rbuf: full\n"); | ||
| 19 | } | 23 | } |
| 20 | } | 24 | } |
| 25 | return ret; | ||
| 21 | } | 26 | } |
| 22 | static inline uint8_t rbuf_dequeue(void) { | 27 | static inline uint8_t rbuf_dequeue(void) { |
| 23 | uint8_t val = 0; | 28 | uint8_t val = 0; |
