-
Notifications
You must be signed in to change notification settings - Fork 0
/
EABase_NodeMCUv10.h
164 lines (148 loc) · 3.83 KB
/
EABase_NodeMCUv10.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
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
#ifndef __EABase_NodeMCUv10_H
#define __EABase_NodeMCUv10_H
#include "EABase.h"
#include "EABase_Chip.h"
#if ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
class EABase_NodeMCUv10 : public EABase_ChipIO
{
private:
uint8_t getPinNo(uint8_t pin)
{
switch (pin)
{ // D GPIO
case 0: return 16;
case 1: return 5;
case 2: return 4;
case 3: return 0;
case 4: return 2;
case 5: return 14;
case 6: return 12;
case 7: return 13;
case 8: return 15;
case 9: return 3;
case 10: return 1;
}
}
public:
EABase_NodeMCUv10(EABase *eabase) : EABase_ChipIO(eabase)
{
setIgnores( new (EABase_PINNO[3]) { 2, 9, 10 } );
}
void setIgnoreI2C(EABase_PINNO SDA, EABase_PINNO SCL)
{
setIgnore(SDA); // SDA pin number
setIgnore(SCL); // SCL pin number
}
void setIgnoreSPI()
{
setIgnores( new (EABase_PINNO[4]) { 3, 7,6,5 } ); // MOSI, MISO, SCK
}
void setup()
{
Direction = 0;
PullUp = 0;
Invert = 0;
Output = 0;
for (EABase_PINNO i = 0; i < maxPins(); i++)
{
if (getPin(Ignore, i) == false)
{
pinMode(getPinNo(i), OUTPUT);
digitalWrite(getPinNo(i), false);
}
}
}
void loop() { }
uint8_t maxPins() {
return 11;
}
void setMode(EABase_PINNO pin, int value, bool invert)
{
if (getPin(Ignore, pin) == true)
{ // Simulate output
Direction = setPin(Direction, pin, false);
PullUp = setPin(PullUp, pin, false);
Invert = setPin(Invert, pin, false);
return;
}
switch (value)
{
case INPUT:
Direction = setPin(Direction, pin, true);
PullUp = setPin(PullUp, pin, false);
Invert = setPin(Invert, pin, invert);
pinMode(getPinNo(pin), value);
break;
case INPUT_PULLUP:
Direction = setPin(Direction, pin, true);
PullUp = setPin(PullUp, pin, true);
Invert = setPin(Invert, pin, invert);
pinMode(getPinNo(pin), value);
break;
case OUTPUT:
Direction = setPin(Direction, pin, false);
PullUp = setPin(PullUp, pin, false);
Invert = setPin(Invert, pin, false);
pinMode(getPinNo(pin), value);
break;
}
}
void setMode(EABase_PINNO *pins, int value, bool invert)
{
for (EABase_PINNO i = 0; i < pins[0]; i++)
setMode(pins[i + 1], value, invert);
}
void pinWrite(EABase_PINNO pin, bool value)
{
if (pin >= 0 && pin < maxPins())
{
if (getPin(Direction, pin) == false)
{
Output = setPin(Output, pin, value);
if (getPin(Ignore, pin) == false)
digitalWrite(getPinNo(pin), value);
}
}
}
void pinWrite(EABase_PINNO *pins, EABase_PINDATA values)
{
EABase_PINDATA work = values;
bool value;
for (EABase_PINNO i = 1; i <= pins[0]; i++)
{
if (getPin(Direction, pins[i]) == false)
{
value = (work & 1) > 0;
Output = setPin(Output, pins[i], value);
if (getPin(Ignore, pins[i]) == false)
digitalWrite(getPinNo(pins[i]), value);
}
work = work >> 1;
}
}
bool pinRead(EABase_PINNO pin)
{
if (getPin(Direction, pin) == false)
return getPin(Output, pin);
else
return (getPin(Invert, pin) ? !digitalRead(getPinNo(pin)) : digitalRead(getPinNo(pin)));
return false;
}
EABase_PINDATA pinRead(EABase_PINNO *pins)
{
EABase_PINDATA value = 0;
for (EABase_PINNO i = 1; i <= pins[0]; i++)
{
value = value << 1;
//if (digitalRead(getPinNo(pins[i])) != getPin(Invert, pins[i]))
if (pinRead(pins[i])==true)
value |= 1;
}
return value;
}
};
#endif