IRremote
LongUnion.h
Go to the documentation of this file.
1 /*
2  * LongUnion.h
3  *
4  * Copyright (C) 2020-2022 Armin Joachimsmeyer
5  * Email: armin.joachimsmeyer@gmail.com
6  *
7  * This file is part of Arduino-Utils https://github.com/ArminJo/Arduino-Utils.
8  *
9  * Arduino-Utils is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17  * See the GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <http://www.gnu.org/licenses/gpl.html>.
21  *
22  */
23 
24 #if !defined(_WORD_UNION_H) || !defined(_LONG_UNION_H) || !defined(_LONG_LONG_UNION_H)
25 
26 #include <stdint.h>
27 
28 #ifndef _WORD_UNION_H
29 #define _WORD_UNION_H
30 
36 union WordUnion {
37  struct {
38  uint8_t LowByte;
39  uint8_t HighByte;
40  } UByte;
41  struct {
42  int8_t LowByte;
43  int8_t HighByte;
44  } Byte;
45  uint8_t UBytes[2]; // UBytes[0] is LowByte
46  int8_t Bytes[2];
47  uint16_t UWord;
48  int16_t Word;
49  uint8_t *BytePointer;
50 };
51 #endif // _WORD_UNION_H
52 
53 #ifndef _LONG_UNION_H
54 #define _LONG_UNION_H
55 
59 union LongUnion {
60  struct {
61  uint8_t LowByte;
62  uint8_t MidLowByte;
63  uint8_t MidHighByte;
64  uint8_t HighByte;
65  } UByte;
66  struct {
67  int8_t LowByte;
68  int8_t MidLowByte;
69  int8_t MidHighByte;
70  int8_t HighByte;
71  } Byte;
72  /* Does not work for STM32
73  struct {
74  uint8_t LowByte;
75  uint16_t MidWord;
76  uint8_t HighByte;
77  } UByteWord;
78  */
79  struct {
80  uint16_t LowWord;
81  uint16_t HighWord;
82  } UWord;
83  struct {
84  int16_t LowWord;
85  int16_t HighWord;
86  } Word;
87  struct {
91  uint8_t UBytes[4]; // seems to have the same code size as using struct UByte
92  int8_t Bytes[4]; // Bytes[0] is LowByte
93  uint16_t UWords[2];
94  int16_t Words[2];
95  uint32_t ULong;
96  int32_t Long;
97  float Float;
98 };
99 #endif // _LONG_UNION_H
100 
101 #ifndef _LONG_LONG_UNION_H
102 #define _LONG_LONG_UNION_H
103 
108  struct {
109  uint16_t LowWord;
110  uint16_t MidLowWord;
111  uint16_t MidHighWord;
112  uint16_t HighWord;
113  } UWord;
114  struct {
115  int16_t LowWord;
116  int16_t MidLowWord;
117  int16_t MidHighWord;
118  int16_t HighWord;
119  } Word;
120  struct {
126  struct {
127  uint32_t LowLong;
128  uint32_t HighLong;
129  } ULong;
130  struct {
131  int32_t LowLong;
132  int32_t HighLong;
133  } Long;
134  struct {
138  uint8_t UBytes[8]; // seems to have the same code size as using struct UByte
139  int8_t Bytes[8];
140  uint16_t UWords[4];
141  int16_t Words[4];
142  uint64_t ULongLong;
143  int64_t LongLong;
144 #if __DBL_MANT_DIG__== 24
145  float Floats[2]; // 32 bit double, as for AVR
146 #else
147  // 64 bit double
148  double Double;
149 #endif
150 };
151 #endif // _LONG_LONG_UNION_H
152 
153 #endif // !defined(_WORD_UNION_H) || !defined(_LONG_UNION_H) || !defined(_LONG_LONG_UNION_H)
LongLongUnion::UBytes
uint8_t UBytes[8]
Definition: LongUnion.h:138
LongUnion
Union to specify parts / manifestations of a 32 bit Long without casts and shifts.
Definition: LongUnion.h:59
LongLongUnion::MidLowWord
uint16_t MidLowWord
Definition: LongUnion.h:110
LongLongUnion::Word
struct LongLongUnion::@10 Word
WordUnion
Union to specify parts / manifestations of a 16 bit Word without casts and shifts.
Definition: LongUnion.h:36
LongLongUnion::LowWord
int16_t LowWord
Definition: LongUnion.h:115
WordUnion::UByte
struct WordUnion::@2 UByte
WordUnion::HighByte
uint8_t HighByte
Definition: LongUnion.h:39
LongUnion::TwoWordUnions
struct LongUnion::@8 TwoWordUnions
LongLongUnion::MidHighWord
int16_t MidHighWord
Definition: LongUnion.h:117
LongUnion::UByte
struct LongUnion::@4 UByte
LongLongUnion::HighWord
uint16_t HighWord
Definition: LongUnion.h:112
LongUnion::Byte
struct LongUnion::@5 Byte
WordUnion::LowByte
int8_t LowByte
Definition: LongUnion.h:42
LongUnion::Float
float Float
Definition: LongUnion.h:97
LongLongUnion::Words
int16_t Words[4]
Definition: LongUnion.h:141
LongUnion::UBytes
uint8_t UBytes[4]
Definition: LongUnion.h:91
WordUnion::UBytes
uint8_t UBytes[2]
Definition: LongUnion.h:45
LongUnion::Words
int16_t Words[2]
Definition: LongUnion.h:94
LongUnion::LowByte
uint8_t LowByte
Definition: LongUnion.h:61
LongUnion::HighByte
uint8_t HighByte
Definition: LongUnion.h:64
LongLongUnion::HighWord
WordUnion HighWord
Definition: LongUnion.h:124
LongUnion::LowWord
uint16_t LowWord
Definition: LongUnion.h:80
LongLongUnion
Union to specify parts / manifestations of a 64 bit LongLong without casts and shifts.
Definition: LongUnion.h:107
LongUnion::MidLowByte
uint8_t MidLowByte
Definition: LongUnion.h:62
LongLongUnion::Bytes
int8_t Bytes[8]
Definition: LongUnion.h:139
LongLongUnion::LowLong
LongUnion LowLong
Definition: LongUnion.h:135
LongUnion::HighWord
uint16_t HighWord
Definition: LongUnion.h:81
LongUnion::Word
struct LongUnion::@7 Word
LongLongUnion::ULong
struct LongLongUnion::@12 ULong
LongLongUnion::HighLong
uint32_t HighLong
Definition: LongUnion.h:128
WordUnion::HighByte
int8_t HighByte
Definition: LongUnion.h:43
WordUnion::Byte
struct WordUnion::@3 Byte
LongLongUnion::MidLowWord
WordUnion MidLowWord
Definition: LongUnion.h:122
WordUnion::Bytes
int8_t Bytes[2]
Definition: LongUnion.h:46
LongLongUnion::HighLong
LongUnion HighLong
Definition: LongUnion.h:136
LongLongUnion::LowWord
uint16_t LowWord
Definition: LongUnion.h:109
LongUnion::Long
int32_t Long
Definition: LongUnion.h:96
LongLongUnion::TwoLongUnions
struct LongLongUnion::@14 TwoLongUnions
LongUnion::ULong
uint32_t ULong
Definition: LongUnion.h:95
LongLongUnion::LongLong
int64_t LongLong
Definition: LongUnion.h:143
LongUnion::HighWord
WordUnion HighWord
Definition: LongUnion.h:89
LongLongUnion::FourWordUnions
struct LongLongUnion::@11 FourWordUnions
LongUnion::LowWord
WordUnion LowWord
Definition: LongUnion.h:88
LongLongUnion::Double
double Double
Definition: LongUnion.h:148
LongLongUnion::HighWord
int16_t HighWord
Definition: LongUnion.h:118
LongLongUnion::UWords
uint16_t UWords[4]
Definition: LongUnion.h:140
LongLongUnion::ULongLong
uint64_t ULongLong
Definition: LongUnion.h:142
WordUnion::Word
int16_t Word
Definition: LongUnion.h:48
WordUnion::BytePointer
uint8_t * BytePointer
Definition: LongUnion.h:49
LongLongUnion::UWord
struct LongLongUnion::@9 UWord
LongUnion::Bytes
int8_t Bytes[4]
Definition: LongUnion.h:92
LongLongUnion::MidLowWord
int16_t MidLowWord
Definition: LongUnion.h:116
LongUnion::MidHighByte
uint8_t MidHighByte
Definition: LongUnion.h:63
LongUnion::UWords
uint16_t UWords[2]
Definition: LongUnion.h:93
LongUnion::LowWord
int16_t LowWord
Definition: LongUnion.h:84
LongUnion::UWord
struct LongUnion::@6 UWord
LongLongUnion::Long
struct LongLongUnion::@13 Long
LongUnion::HighByte
int8_t HighByte
Definition: LongUnion.h:70
WordUnion::LowByte
uint8_t LowByte
Definition: LongUnion.h:38
LongLongUnion::MidHighWord
WordUnion MidHighWord
Definition: LongUnion.h:123
WordUnion::UWord
uint16_t UWord
Definition: LongUnion.h:47
LongLongUnion::MidHighWord
uint16_t MidHighWord
Definition: LongUnion.h:111
LongLongUnion::LowLong
int32_t LowLong
Definition: LongUnion.h:131
LongLongUnion::LowLong
uint32_t LowLong
Definition: LongUnion.h:127
LongUnion::MidHighByte
int8_t MidHighByte
Definition: LongUnion.h:69
LongUnion::LowByte
int8_t LowByte
Definition: LongUnion.h:67
LongLongUnion::LowWord
WordUnion LowWord
Definition: LongUnion.h:121
LongUnion::HighWord
int16_t HighWord
Definition: LongUnion.h:85
LongUnion::MidLowByte
int8_t MidLowByte
Definition: LongUnion.h:68
LongLongUnion::HighLong
int32_t HighLong
Definition: LongUnion.h:132