1// Copyright 2016 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#pragma once
6
7#include <zircon/compiler.h>
8#include <zircon/types.h>
9
10#include <stdbool.h>
11#include <stddef.h>
12#include <stdint.h>
13#include <sys/types.h>
14#include <threads.h>
15
16__BEGIN_CDECLS;
17
18#ifndef HID_FIFO_SIZE
19#define HID_FIFO_SIZE 4096
20#endif
21#define HID_FIFO_MASK (HID_FIFO_SIZE-1)
22
23typedef struct {
24    uint8_t buf[HID_FIFO_SIZE];
25    uint32_t head;
26    uint32_t tail;
27    bool empty;
28    mtx_t lock;
29} zx_hid_fifo_t;
30
31zx_status_t zx_hid_fifo_create(zx_hid_fifo_t** fifo);
32void zx_hid_fifo_init(zx_hid_fifo_t* fifo);
33size_t zx_hid_fifo_size(zx_hid_fifo_t* fifo);
34ssize_t zx_hid_fifo_peek(zx_hid_fifo_t* fifo, void* out);
35ssize_t zx_hid_fifo_read(zx_hid_fifo_t* fifo, void* buf, size_t len);
36ssize_t zx_hid_fifo_write(zx_hid_fifo_t* fifo, const void* buf, size_t len);
37
38void zx_hid_fifo_dump(zx_hid_fifo_t* fifo);
39
40__END_CDECLS;
41