1 /*--------------------------------------------------------------------
2 * Ring buffer to store scan codes from keyboard
3 *------------------------------------------------------------------*/
11 static uint16_t pbuf[PBUF_SIZE];
12 static uint16_t pbuf_head = 0;
13 static uint16_t pbuf_tail = 0;
14 static inline void pbuf_enqueue(uint16_t data)
18 uint16_t next = (pbuf_head + 1) % PBUF_SIZE;
19 if (next != pbuf_tail) {
20 pbuf[pbuf_head] = data;
23 print("pbuf: full\n");
27 static inline uint16_t pbuf_dequeue(void)
33 if (pbuf_head != pbuf_tail) {
34 val = pbuf[pbuf_tail];
35 pbuf_tail = (pbuf_tail + 1) % PBUF_SIZE;
41 static inline bool pbuf_has_data(void)
45 bool has_data = (pbuf_head != pbuf_tail);
49 static inline void pbuf_clear(void)
53 pbuf_head = pbuf_tail = 0;