-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPins.hpp
214 lines (177 loc) · 7.17 KB
/
Pins.hpp
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#pragma once
//I/O pins
#include <cstdint>
#include "Reg.hpp"
struct Pins : private Reg {
//helper enum
enum : uint8_t {
PTSHIFT = 4, PTMASK = 7,
PNSHIFT = 0, PNMASK = 15,
//RPSHIFT = 6, RPMASK = 31,
ANSHIFT = 12, ANMASK = 15,
CNSHIFT = 7, CNMASK = 31,
NO_CN = 29
};
//PIN11 (physical), A0, RP1, AN0 - use any
enum RPN : uint16_t {
// encode as- 0xaaaacccccpppnnnn - | ANn | CNn | PORT | PIN |
// aaaa = ANn = 0-15
// ppp = port A=0,B=1,C=2,D=3, E=4, F=5, G=6
// nnnn = pin = 0-15
// ccccc = CNn = 1-21
// NOTE: pins without AN (analog in) will be set to use AVss (29) as AN input
// (since AN0 is 0, we need something other than 0 to signify no AN for pin, so
// we will just give it something that will result in no result if ever used
// adcval() by mistake)
// NOTE: pins without CN (change notice) will be set to use AVss (29) as CN nr
//A0 - A-15
A0 = 0|NO_CN<<CNSHIFT, A1 = 1|NO_CN<<CNSHIFT,
A2 = 2|NO_CN<<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D15
D0 = 48|NO_CN<<CNSHIFT, D1 = 49|NO_CN<<CNSHIFT,
D2 = 50|NO_CN<<CNSHIFT, D3 = 51|NO_CN<<CNSHIFT,
D4 = 52|13<<CNSHIFT, D5 = 53|14<<CNSHIFT,
D6 = 54|15<<CNSHIFT, D7 = 55|16<<CNSHIFT,
D8 = 56|NO_CN<<CNSHIFT, D9 = 57|NO_CN<<CNSHIFT,
D10 = 58|NO_CN<<CNSHIFT, D11 = 59|NO_CN<<CNSHIFT,
D12 = 60|NO_CN<<CNSHIFT, D13 = 61|19<<CNSHIFT,
D14 = 62|20<<CNSHIFT, D15 = 63|21<<CNSHIFT,
//E0-E9
E0 = 64|NO_CN<<CNSHIFT, E1 = 65|NO_CN<<CNSHIFT,
E2 = 66|NO_CN<<CNSHIFT, E3 = 67|NO_CN<<CNSHIFT,
E4 = 68|NO_CN<<CNSHIFT, E5 = 69|NO_CN<<CNSHIFT,
E6 = 70|NO_CN<<CNSHIFT, E7 = 71|NO_CN<<CNSHIFT,
E8 = 72|NO_CN<<CNSHIFT, E9 = 73|NO_CN<<CNSHIFT,
/*no E10 = 74, E11 = 75,
E12 = 76, E13 = 77,
E14 = 78, E15 = 79,*/
//F0-F13
F0 = 80|NO_CN<<CNSHIFT, F1 = 81|NO_CN<<CNSHIFT,
F2 = 82|NO_CN<<CNSHIFT, F3 = 83|NO_CN<<CNSHIFT,
F4 = 84|17<<CNSHIFT, F5 = 85|18<<CNSHIFT,
/*no F6 = 86, F7 = 87,*/
F8 = 88|NO_CN<<CNSHIFT, /*F9 = 89,
F10 = 90, F11 = 91,*/
F12 = 92|NO_CN<<CNSHIFT, F13 = 93|NO_CN<<CNSHIFT,
/*no F14 = 94, F15 = 95,*/
//G0-G13
G0 = 96|NO_CN<<CNSHIFT, G1 = 97|NO_CN<<CNSHIFT,
G2 = 98|NO_CN<<CNSHIFT, G3 = 99|NO_CN<<CNSHIFT,
/*G4 = 100, G5 = 101,*/
G6 = 102|8<<CNSHIFT, G7 = 103|9<<CNSHIFT,
G8 = 104|10<<CNSHIFT, G9 = 105|11<<CNSHIFT,
/* no G10 = 106, G11 = 107,*/
G12 = 108|NO_CN<<CNSHIFT, G13 = 109|NO_CN<<CNSHIFT,
G14 = 110|NO_CN<<CNSHIFT, G15 = 111|NO_CN<<CNSHIFT,
//ANn 0-19
AN0 = B0, AN1 = B1, AN2 = B2, AN3 = B3, AN4 = B4,
AN5 = B5, AN6 = B6, AN7 = B7, AN8 = B8, AN9 = B9,
AN10 = B10, AN11 = B11, AN12 = B12, AN13 = B13,
AN14 = B14, AN15 = B15,
//CNn 0-21
CN0 = C14, CN1 = C13, CN2 = B0, CN3 = B1, CN4 = B2,
CN5 = B3, CN6 = B4, CN7 = B5, CN8 = G6, CN9 = G7,
CN10 = G8, CN11 = G9, CN12 = B15, CN13 = D4, CN14 = D5,
CN15 = D6, CN16 = D7, CN17 = F4, CN18 = F5, CN19 = D13,
CN20 = D14, CN21 = D15,
//PINn 1-64
PIN1 = G15, /*PIN2 = Vdd,*/ PIN3 = E5, PIN4 = E6, PIN5 = E7,
PIN6 = C1, PIN7 = C2, PIN8 = C3, PIN9 = C4, PIN10 = G6,
PIN11 = G7, PIN12 = G8, /*PIN13 = MCLR,*/ PIN14 = G9, /*PIN15 = Vss,
PIN16 = Vdd,*/ PIN17 = A0, PIN18 = E8, PIN19 = E9, PIN20 = B5,
PIN21 = B4, PIN22 = B3, PIN23 = B2, PIN24 = B1, PIN25 = B0,
PIN26 = B6, PIN27 = B7, PIN28 = A9, PIN29 = A10, /*PIN30 = AVdd,
PIN31 = AVss,*/ PIN32 = B8, PIN33 = B9, PIN34 = B10, PIN35 = B11,
/*PIN36 = Vss, PIN37 = Vdd,*/ PIN38 = A1, PIN39 = F13, PIN40 = F12,
PIN41 = B12, PIN42 = B13, PIN43 = B14, PIN44 = B15, /*PIN45 = Vss,
PIN46 = Vdd,*/ PIN47 = D14, PIN48 = D15, PIN49 = F4, PIN50 = F5,
PIN51 = F3, PIN52 = F2, PIN53 = F8, /*PIN54 = VBUS, PIN55 = Vusb3v3,*/
PIN56 = G3, PIN57 = G2, PIN58 = A2, PIN59 = A3, PIN60 = A4,
PIN61 = A5, /*PIN62 = Vdd,*/ PIN63 = C12, PIN64 = C15, /*PIN65 = Vss*/
PIN66 = A14, PIN67 = A15, PIN68 = D8, PIN69 = D9, PIN70 = D10,
PIN71 = D11, PIN72 = D0, PIN73 = C13, PIN74 = C14, /*PIN75 = Vss,*/
PIN76 = D1, PIN77 = D2, PIN78 = D3, PIN79 = D12, PIN80 = D13,
PIN81 = D4, PIN82 = D5, PIN83 = D6, PIN84 = D7, /*PIN85 = Vcap,
PIN86 = Vdd,*/ PIN87 = F0, PIN88 = F1, PIN89 = G1, PIN90 = G0,
PIN91 = A6, PIN92 = A7, PIN93 = E0, PIN94 = E1, PIN95 = G14,
PIN96 = G12, PIN97 = G13, PIN98 = E2, PIN99 = E3, PIN100 = E4
};
enum
IOMODE : uint8_t {
AIN = 0,
IN = 1, INPU = 1<<3|1<<2|IN, INPD = 1<<4|IN, INL = 1<<2|IN,
OUT = 2, OUTL = 1<<2|OUT
};
Pins (RPN, IOMODE = AIN);
//r/w pins
auto
pinval () -> bool;
auto
latval () -> bool;
auto
latval (bool) -> void;
auto
adcval () -> uint16_t;
auto
low () -> void;
auto
high () -> void;
auto
invert () -> void;
auto
on () -> void;
auto
off () -> void;
auto
ison () -> bool;
//pin modes
auto
lowison (bool) -> void;
auto
digital_in () -> void;
auto
analog_in () -> void;
auto
digital_out () -> void;
auto
odrain (bool) -> void;
auto
pullup (bool) -> void;
//icn
auto
icn (bool) -> void;
auto
an_num () -> uint8_t; //get adc #
auto
cn_num () -> uint8_t; //get cn #
private:
volatile uint32_t* m_pt; //base address
const uint16_t m_pn; //pin mask
bool m_lowison; //pin on val is low
const uint8_t m_an; //ANn value
const uint8_t m_cn; //CNn value
};