makes GPIO_PIN_RST optional for the sx1276
[ExpressLRS.git] / src / lib / FIFO / FIFO.h
blob6e845d886dea839d0c2caf0a4ff43f4ff4d95222
1 /*
2 * FIFO Buffer
3 * Implementation uses arrays to conserve memory
5 * The MIT License (MIT)
7 * Copyright (c) 2015 Daniel Eisterhold
9 * Permission is hereby granted, free of charge, to any person obtaining a copy
10 * of this software and associated documentation files (the "Software"), to deal
11 * in the Software without restriction, including without limitation the rights
12 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 * copies of the Software, and to permit persons to whom the Software is
14 * furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice shall be included in all
17 * copies or substantial portions of the Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 * SOFTWARE.
29 * Modified/Ammended by Alessandro Carcione 2020
32 #pragma once
34 #include "targets.h"
36 // If this is 256 then the compiler can optimise out the modulo because the head/tail are uint8_t types
37 #define FIFO_SIZE 256
39 class FIFO
41 private:
42 uint8_t head;
43 uint8_t tail;
44 uint16_t numElements;
45 uint8_t buffer[FIFO_SIZE] = {0};
47 public:
48 FIFO();
49 ~FIFO();
50 void ICACHE_RAM_ATTR push(const uint8_t data);
51 void ICACHE_RAM_ATTR pushBytes(const uint8_t *data, int len);
52 uint8_t ICACHE_RAM_ATTR pop();
53 void ICACHE_RAM_ATTR popBytes(uint8_t *data, int len);
54 uint8_t ICACHE_RAM_ATTR peek();
55 uint16_t ICACHE_RAM_ATTR size();
56 void ICACHE_RAM_ATTR flush();