]> git.gir.st - tmk_keyboard.git/blob - tmk_core/protocol/lufa/LUFA-git/Projects/Magstripe/Lib/CircularBitBuffer.h
remove experimental return, cleanup slash_question key
[tmk_keyboard.git] / tmk_core / protocol / lufa / LUFA-git / Projects / Magstripe / Lib / CircularBitBuffer.h
1 /*
2 LUFA Library
3 Copyright (C) Dean Camera, 2014.
4
5 dean [at] fourwalledcubicle [dot] com
6 www.lufa-lib.org
7 */
8
9 /*
10 Copyright 2010 Denver Gingerich (denver [at] ossguy [dot] com)
11 Copyright 2014 Dean Camera (dean [at] fourwalledcubicle [dot] com)
12
13 Permission to use, copy, modify, distribute, and sell this
14 software and its documentation for any purpose is hereby granted
15 without fee, provided that the above copyright notice appear in
16 all copies and that both that the copyright notice and this
17 permission notice and warranty disclaimer appear in supporting
18 documentation, and that the name of the author not be used in
19 advertising or publicity pertaining to distribution of the
20 software without specific, written prior permission.
21
22 The author disclaims all warranties with regard to this
23 software, including all implied warranties of merchantability
24 and fitness. In no event shall the author be liable for any
25 special, indirect or consequential damages or any damages
26 whatsoever resulting from loss of use, data or profits, whether
27 in an action of contract, negligence or other tortious action,
28 arising out of or in connection with the use or performance of
29 this software.
30 */
31
32 /** \file
33 *
34 * Header file for CircularBitBuffer.c.
35 */
36
37 #ifndef _CIRCULARBITBUFFER_H_
38 #define _CIRCULARBITBUFFER_H_
39
40 /* Includes: */
41 #include <avr/io.h>
42 #include <stdbool.h>
43
44 #include <LUFA/Common/Common.h>
45
46 /* Macros: */
47 #if (defined(__AVR_AT90USB1287__) || defined(__AVR_AT90USB647__) || \
48 defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB646__)) || defined(__DOXYGEN__)
49 /** Maximum number of bits which can be stored into a bit buffer. The memory usage is one eighth of this value per buffer. */
50 #define MAX_BITS 8192
51 #else
52 #define MAX_BITS 1024
53 #endif
54
55 /* Type Defines: */
56 /** Type define for a pointer to a bit in a bit buffer. */
57 typedef struct
58 {
59 uint8_t* CurrentByte; /**< Pointer to the current byte in the buffer */
60 uint8_t ByteMask; /**< Mask of the current bit in the buffer */
61 } BitBufferPointer_t;
62
63 /** Type define for a circular packet bit buffer. */
64 typedef struct
65 {
66 uint8_t Data[MAX_BITS / 8]; /**< Buffer to hold the stored bits in packed form */
67 uint16_t Elements; /**< Number of stored bits in the bit buffer */
68
69 BitBufferPointer_t In; /**< Bit pointer to the next storage location in the buffer */
70 BitBufferPointer_t Out; /**< Bit pointer to the next retrieval location in the buffer */
71 } BitBuffer_t;
72
73 /* Function Prototypes: */
74 /** Initializes or resets a given bit buffer, ready to store new bits.
75 *
76 * \param[in,out] Buffer Bit buffer to initialize
77 */
78 void BitBuffer_Init(BitBuffer_t* const Buffer) ATTR_NON_NULL_PTR_ARG(1);
79
80 /** Stores a bit into the next location inside a given bit buffer.
81 *
82 * \param[in,out] Buffer Bit buffer to store a bit into
83 * \param[in] Bit Bit to store into the buffer
84 */
85 void BitBuffer_StoreNextBit(BitBuffer_t* const Buffer,
86 const bool Bit) ATTR_NON_NULL_PTR_ARG(1);
87
88 /** Retrieves a bit from the next location inside a given bit buffer.
89 *
90 * \param[in,out] Buffer Bit buffer to retrieve a bit from
91 *
92 * \return Next bit from the buffer
93 */
94 bool BitBuffer_GetNextBit(BitBuffer_t* const Buffer) ATTR_NON_NULL_PTR_ARG(1);
95
96 #endif
97
Imprint / Impressum