5
#include <gtest/gtest.h>
15
typedef typename Pin::Port Port;
16
typedef typename Pin::ConfigPort ConfigPort;
17
typedef typename Port::DataT DataT;
18
const DataT mask = 1 << Pin::Number;
20
cout << __FUNCTION__ << "\tPort: " << (char)Port::Id << "\tPinNumber: " << Pin::Number;
23
Port::template SetConfiguration<DataT(-1), Port::In>();
24
EXPECT_EQ(0u, Port::OutReg);
26
EXPECT_EQ(mask, Port::OutReg);
28
EXPECT_EQ(0u, Port::OutReg);
30
EXPECT_EQ(mask, Port::OutReg);
32
EXPECT_EQ(0u, Port::OutReg);
34
EXPECT_EQ(mask, Port::OutReg);
36
EXPECT_EQ(0u, Port::OutReg);
39
EXPECT_EQ(0u, Port::DirReg);
41
EXPECT_EQ(mask, Port::DirReg);
44
EXPECT_EQ(0u, Port::DirReg);
46
EXPECT_EQ(mask, Port::DirReg);
48
Pin::SetConfiguration(Port::In);
49
EXPECT_EQ(0u, Port::DirReg);
50
Pin::SetConfiguration(Port::Out);
51
EXPECT_EQ(mask, Port::DirReg);
53
Pin::template SetConfiguration<Port::In>();
54
EXPECT_EQ(0u, Port::DirReg);
55
Pin:: template SetConfiguration<Port::Out>();
56
EXPECT_EQ(mask, Port::DirReg);
59
EXPECT_FALSE(Pin::IsSet());
62
EXPECT_TRUE(Pin::IsSet());
64
cout << "\tOK" << endl;
70
template<class List, int index>
75
Iterator<List, index-1>::Print();
76
typedef typename List:: template Pin<index-1> CurrentPin;
77
if(index == List::Length)
78
std::cout << (char)CurrentPin::Port::Id << CurrentPin::Number;
80
std::cout << (char)CurrentPin::Port::Id << CurrentPin::Number << ", ";
85
struct Iterator<List, 0>
93
std::cout << "PinList<";
94
Iterator<Pins, Pins::Length>::Print();
101
void TestOnePortPinList(unsigned listValue, unsigned portValue)
103
typedef typename Pins::template Pin<0>::Port Port;
104
typename Pins::DataType val;
105
cout << __FUNCTION__ << "\t";
106
PrintPinList<Pins>::Print();
110
Pins::Write(listValue);
111
EXPECT_EQ(Port::OutReg, portValue);
113
EXPECT_EQ(listValue, val);
116
Pins::SetConfiguration(listValue, Pins::Out);
117
EXPECT_EQ(portValue, Port::DirReg);
122
Port::InReg = portValue;
123
val = Pins::PinRead();
124
EXPECT_EQ(listValue, val);
127
val = Pins::PinRead();
131
EXPECT_EQ(0u, Port::OutReg);
133
Pins::Set(listValue);
134
EXPECT_EQ(portValue, Port::OutReg);
136
Pins::Clear(listValue);
137
EXPECT_EQ(0u, Port::OutReg);
139
Pins::SetConfiguration(Pins::In);
140
EXPECT_EQ(0u, Port::DirReg);
142
cout << "\tOK" << endl;
145
template<class Pins, unsigned listValue, unsigned portValue>
146
void TestOnePortConstIface()
148
typedef typename Pins::template Pin<0>::Port Port;
149
typename Pins::DataType val;
150
cout << __FUNCTION__ << "\t";
151
PrintPinList<Pins>::Print();
153
Port::template Write<0>();
155
Pins::template Write<listValue>();
156
EXPECT_EQ(Port::OutReg, portValue);
158
EXPECT_EQ(listValue, val);
161
Pins::template SetConfiguration<listValue, Pins::Out>();
162
EXPECT_EQ(portValue, Port::DirReg);
164
Port::template Write<0>();
167
Port::InReg = portValue;
168
val = Pins::PinRead();
169
EXPECT_EQ(listValue, val);
172
val = Pins::PinRead();
175
Port::template Write<0>();
176
EXPECT_EQ(0u, Port::OutReg);
178
Pins::template Set<listValue>();
179
EXPECT_EQ(portValue, Port::OutReg);
181
Pins::template Clear<listValue>();
182
EXPECT_EQ(0u, Port::OutReg);
184
Pins::template SetConfiguration<0xff, Pins::In>();
185
EXPECT_EQ(0u, Port::DirReg);
187
cout << "\tOK" << endl;
190
template<class Pins, class Port1, class Port2>
191
void Test2PortConfiguration(unsigned listValue, unsigned portValue, unsigned portValue2)
193
typename Pins::DataType val;
194
cout << __FUNCTION__ << "\t";
201
PrintPinList<Pins>::Print();
202
Pins::Write(listValue);
203
EXPECT_EQ(portValue, Port1::OutReg);
204
EXPECT_EQ(portValue2, Port2::OutReg);
206
EXPECT_EQ(listValue, val);
209
Pins::Set(listValue);
210
EXPECT_EQ(portValue, Port1::OutReg);
211
EXPECT_EQ(portValue2, Port2::OutReg);
213
EXPECT_EQ(listValue, val);
215
Pins::Clear(listValue);
216
EXPECT_EQ(0u, Port1::OutReg);
217
EXPECT_EQ(0u, Port2::OutReg);
221
Pins::SetConfiguration(listValue, Pins::Out);
222
EXPECT_EQ(portValue, Port1::DirReg);
223
EXPECT_EQ(portValue2, Port2::DirReg);
224
cout << "\tOK" << endl;
263
TEST(GPIO, PinListTest)
265
for(int i=0; i< 16; i++)
267
cout << "Writing value: " << i << endl;
268
TestOnePortPinList<PinList<Pa0, Pa1, Pa2, Pa3> >(i, i);
269
TestOnePortPinList<PinList<Pa1, Pa2, Pa3, Pa4> >(i, i << 1);
270
TestOnePortPinList<PinList<Pa2, Pa3, Pa4, Pa5> >(i, i << 2);
273
TestOnePortPinList<PinList<Pa1, Pa3, Pa2, Pa0> >(0x0f, 0x0f);
274
TestOnePortPinList<PinList<Pa0, Pa2, Pa1, Pa3> >(0x0f, 0x0f);
275
TestOnePortPinList<PinList<Pa2, Pa1, Pa3, Pa4, Pa6> >(0x1f, 0x5e);
277
TestOnePortPinList<PinList<Pa5, Pa6, Pa7, Pa0, Pa1, Pa2, Pa3, Pa4> >(0xff, 0xff);
279
TestOnePortPinList<PinList<Pa2, Pa1, Pa3, Pa4, Pa6, Pa8, Pa7, Pa0, Pa5> >(0x1ff, 0x1ff);
281
TestOnePortPinList<PinList<Pa0, Pa1, Pa2, Pa3, Pa4, Pa5, Pa6, Pa7, Pa8>::Slice<5, 4> >(0x1e0, 0x1e0);
282
cout << "Length = \t" <<PinList<Pa0, Pa1, Pa2, Pa3, Pa4, Pa5, Pa6, Pa7, Pa8>::Slice<5, 4>::Length << std::endl;
283
TestOnePortPinList<PinList<Pa0, Pa1, Pa2, Pa3, Pa4, Pa5, Pa6, Pa7, Pa8>::Slice<0, 4> >(0x0f, 0x0f);
285
TestOnePortPinList<PinList<Pa4, Pa1, Pa6, Pa3, Pa7, Pa5, Pa0 > >(0x7f, 0xfb);
286
TestOnePortPinList<PinList<Pa4, Pa1, Pa6, Pa3, Pa2, Pa5, Pa0, Pa7 > >(0xaa, 0xaa);
287
TestOnePortPinList<PinList<Pa4, Pa1, Pa6, Pa3, Pa2, Pa5, Pa0, Pa7 > >(0x55, 0x55);
289
TestOnePortPinList<PinList<Pa1, Pa2, Pa14, Pa15> >(0x0f, (0x3 << 1) | (0x3 << 14));
291
typedef PinList<Pa2, Pa1, Pa3, Pa4, Pa6> Pins1;
292
typedef PinList<Pins1::Pin<0>, Pins1::Pin<1>, Pins1::Pin<2>, Pins1::Pin<3>, Pins1::Pin<4> > Pins1Clone;
294
TestOnePortPinList<Pins1Clone >(0x1f, 0x5e);
296
TestOnePortPinList<PinList<Pa1, Pa3, NullPin, Pa0> >(0x0b, 0x0b);
298
TestOnePortConstIface<PinList<Pa1, Pa3, Pa2, Pa0>, 0x0f, 0x0f>();
299
TestOnePortConstIface<PinList<Pa0, Pa2, Pa1, Pa3>, 0x0f, 0x0f>();
300
TestOnePortConstIface<PinList<Pa2, Pa1, Pa3, Pa4, Pa6>, 0x1f, 0x5e>();
301
TestOnePortConstIface<PinList<Pa5, Pa6, Pa7, Pa0, Pa1, Pa2, Pa3, Pa4>, 0xff, 0xff>();
302
TestOnePortConstIface<PinList<Pa2, Pa1, Pa3, Pa4, Pa6, Pa8, Pa7, Pa0, Pa5>, 0x1ff, 0x1ff>();
303
TestOnePortConstIface<PinList<Pa0, Pa1, Pa2, Pa3, Pa4, Pa5, Pa6, Pa7, Pa8>::Slice<5, 4>, 0x1e0, 0x1e0>();
304
TestOnePortConstIface<PinList<Pa0, Pa1, Pa2, Pa3, Pa4, Pa5, Pa6, Pa7, Pa8>::Slice<0, 4>, 0x0f, 0x0f>();
305
TestOnePortConstIface<Pins1Clone, 0x1f, 0x5e>();
307
Test2PortConfiguration<PinList<Pa1, Pa3, Pa2, Pa0, Pb1, Pb3, Pb2, Pb0>, Porta, Portb>(0xff, 0x0f, 0x0f);
308
Test2PortConfiguration<PinList<Pa1, Pa2, Pa3, Pa0, Pb0, Pb1, Pb2, Pb3>, Porta, Portb>(0xff, 0x0f, 0x0f);
318
NullPin::SetConfiguration(NullPin::Port::Out);
319
NullPin::SetConfiguration(Mcucpp::IO::NativePortBase::Out);
320
NullPin::Port::Enable();
321
NullPin::Port::Disable();
322
EXPECT_FALSE(NullPin::IsSet());