-
Notifications
You must be signed in to change notification settings - Fork 13
/
NXC_DataMaps.h
55 lines (48 loc) · 2.04 KB
/
NXC_DataMaps.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
/*
* Project Nintendo Extension Controller Library
* @author David Madison
* @link github.com/dmadison/NintendoExtensionCtrl
* @license LGPLv3 - Copyright (c) 2018 David Madison
*
* This file is part of the Nintendo Extension Controller Library.
*
* This program 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 3 of the License, or
* (at your option) any later version.
*
* This program 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 program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef NXC_DATAMAPS_H
#define NXC_DATAMAPS_H
namespace NintendoExtensionCtrl {
// Map data alias for single byte data, using the full byte
using IndexMap = uint8_t;
// Map data struct for single *byte* data, using a portion of a byte
struct ByteMap {
constexpr ByteMap(
uint8_t index, // Index in the control data array
uint8_t size, // Size of the data block, in bits
uint8_t position, // Start position of the data block, in bits from right
uint8_t offset) // Amount to shift the final data to the right
: index(index), mask(BuildMask(size <= 8 ? size : 8, position)), offset(offset) {}
const uint8_t index;
const uint8_t mask; // Data mask for bitwise operations, formed from size and start position
const uint8_t offset;
constexpr static uint8_t BuildMask(uint8_t size, uint8_t startPos) {
return (0xFF >> (8 - size)) << startPos; // Bitmask, to size and position of the data
}
};
// Map data struct for single *bit* data (with inversion)
struct BitMap {
const uint8_t index; // Index in the control data array
const uint8_t position; // Position of the bit, from right
};
}
#endif