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
|
/*
* IoPort.cpp
*
* Created on: 30 Sep 2017
* Author: David
*/
#include "IoPort.h"
#include "RepRap.h"
#include "Platform.h"
#include "Configuration.h"
#ifdef DUET_NG
# include "DuetNG/DueXn.h"
#endif
// members of class IoPort
IoPort::IoPort()
{
Clear();
}
void IoPort::Clear()
{
logicalPort = NoLogicalPin;
pin = NoPin;
invert = false;
}
bool IoPort::Set(LogicalPin lp, PinAccess access)
{
const bool ret = reprap.GetPlatform().GetFirmwarePin(lp, access, pin, invert);
if (!ret)
{
Clear();
}
return ret;
}
/*static*/ void IoPort::SetPinMode(Pin pin, PinMode mode)
{
#ifdef DUET_NG
if (pin >= DueXnExpansionStart)
{
DuetExpansion::SetPinMode(pin, mode);
}
else
{
pinMode(pin, mode);
}
#else
pinMode(pin, mode);
#endif
}
/*static*/ bool IoPort::ReadPin(Pin pin)
{
#ifdef DUET_NG
if (pin >= DueXnExpansionStart)
{
return DuetExpansion::DigitalRead(pin);
}
else
{
return digitalRead(pin);
}
#else
return digitalRead(pin);
#endif
}
/*static*/ void IoPort::WriteDigital(Pin pin, bool high)
{
#ifdef DUET_NG
if (pin >= DueXnExpansionStart)
{
DuetExpansion::DigitalWrite(pin, high);
}
else
{
digitalWrite(pin, high);
}
#else
digitalWrite(pin, high);
#endif
}
/*static*/ void IoPort::WriteAnalog(Pin pin, float pwm, uint16_t freq)
{
#ifdef DUET_NG
if (pin >= DueXnExpansionStart)
{
DuetExpansion::AnalogOut(pin, pwm);
}
else
{
AnalogOut(pin, pwm, freq);
}
#else
AnalogOut(pin, pwm, freq);
#endif
}
// Members of class PwmPort
PwmPort::PwmPort()
{
frequency = DefaultPinWritePwmFreq;
}
void PwmPort::SetFrequency(float freq)
{
frequency = (uint16_t)constrain<float>(freq, 1.0, 65535);
}
// End
|