forked from mmarchetti/DirectIO
-
Notifications
You must be signed in to change notification settings - Fork 0
/
base.h
87 lines (74 loc) · 2.13 KB
/
base.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
base.h - Type definitions for Direct IO and other libraries.
Copyright (c) 2015 Michael Marchetti. All right reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _DirectIO_Base_
#define _DirectIO_Base_
#include <Arduino.h>
#if ARDUINO >= 150
// for u8, u16, u32
#include <USBAPI.h>
#else
typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
#endif
typedef int8_t i8;
typedef int16_t i16;
typedef int32_t i32;
// Define std C++ style "<<" operator for writing to output streams.
template<class T> inline Print &operator << (Print& obj, T arg)
{
obj.print(arg); return obj;
}
// bits_type(N) gives the smallest type that will hold N bits (0 <= N <= 32)
#define bits_type(N) typename _nbits_t<N>::bits_t
// A little ugly infrastructure to make it work
template <int N> class _nbits_t {};
#define _nbits(N, T) template<> class _nbits_t<N> { public: typedef T bits_t; };
_nbits(0, u8);
_nbits(1, u8);
_nbits(2, u8);
_nbits(3, u8);
_nbits(4, u8);
_nbits(5, u8);
_nbits(6, u8);
_nbits(7, u8);
_nbits(8, u8);
_nbits(9, u16);
_nbits(10, u16);
_nbits(11, u16);
_nbits(12, u16);
_nbits(13, u16);
_nbits(14, u16);
_nbits(15, u16);
_nbits(16, u16);
_nbits(17, u32);
_nbits(18, u32);
_nbits(19, u32);
_nbits(20, u32);
_nbits(21, u32);
_nbits(22, u32);
_nbits(23, u32);
_nbits(24, u32);
_nbits(25, u32);
_nbits(26, u32);
_nbits(27, u32);
_nbits(28, u32);
_nbits(29, u32);
_nbits(30, u32);
_nbits(31, u32);
_nbits(32, u32);
#undef _nbits
#endif // _DirectIO_Base_