25
25
// / Interface for JeeNode Ports - see the wiki docs for
26
26
// / [JeeNodes](http://jeelabs.net/projects/hardware/wiki/JeeNode) and
27
27
// / [pinouts](http://jeelabs.net/projects/hardware/wiki/Pinouts).
28
+ // / The Ports class is a thin wrapper around the Arduino's digitalRead(),
29
+ // / digitalWrite(), analogRead(), etc. functions. It was designed to simplify
30
+ // / the use of the four standard port headers on JeeNodes.
28
31
class Port {
29
32
protected:
30
33
// / The port number is a small integer mathing the hardware port used.
@@ -65,8 +68,9 @@ class Port {
65
68
66
69
// DIO pin
67
70
68
- // / Set the pin mode of a Port's D pin.
69
- // / @param value Input or Output.
71
+ // / Set the pin mode of a Port's D pin. The mode() function member sets the
72
+ // / I/O data direction of the DIO pin associated with a specific port.
73
+ // / @param value INPUT or OUTPUT.
70
74
inline void mode (uint8_t value) const
71
75
{ pinMode (digiPin (), value); }
72
76
// / Reads the value of a Port's D pin.
@@ -81,14 +85,21 @@ class Port {
81
85
inline void anaWrite (uint8_t val) const
82
86
{ analogWrite (digiPin (), val); }
83
87
// / Applies the Arduino pulseIn() function on a Port's D pin.
88
+ // / Measure the length of a pulse in microseconds on the DIO (pulse) or
89
+ // / AIO (pulse2) line. The optional timeout value specifies how many
90
+ // / microseconds to wait for a pulse - of none is received, 0 is returned.
84
91
// / See: http://arduino.cc/en/Reference/pulseIn for more details.
92
+ // / @param state Polarity of the pulse to wait for - HIGH (1) or LOW (0).
93
+ // / @param timeout Max number of microseconds to wait. \
94
+ /// Default is 1,000,000, i.e. 1 second.
85
95
inline uint32_t pulse (uint8_t state, uint32_t timeout =1000000L ) const
86
96
{ return pulseIn (digiPin (), state, timeout); }
87
97
88
98
// AIO pin
89
99
90
- // / Set the pin mode of a Port's A pin.
91
- // / @param value Input or Output.
100
+ // / Set the pin mode of a Port's A pin. The mode2() function member sets
101
+ // / the I/O data direction of the AIO pin associated with a specific port.
102
+ // / @param value INPUT or OUTPUT.
92
103
inline void mode2 (uint8_t value) const
93
104
{ pinMode (digiPin2 (), value); }
94
105
// / Reads an analog value from a Port's A pin.
@@ -110,8 +121,10 @@ class Port {
110
121
111
122
// IRQ pin (INT1, shared across all ports)
112
123
113
- // / Set the pin mode of the I pin on all Ports.
114
- // / @param value Input or Output.
124
+ // / Set the pin mode of the I pin on all Ports. The mode3() function member
125
+ // / sets the I/O direction of the IRQ pin associated with a specific port.
126
+ // / Note that this is the same pin on all ports.
127
+ // / @param value INPUT or OUTPUT.
115
128
static void mode3 (uint8_t value)
116
129
{ pinMode (digiPin3 (), value); }
117
130
// / Reads the value of the I pin on all Ports.
@@ -130,6 +143,16 @@ class Port {
130
143
131
144
// / Applies Arduino shiftOut() on a with data on the D and clock on A pin
132
145
// / of the Port. See: http://arduino.cc/en/Tutorial/ShiftOut
146
+ // / This can be used to send out a pulse sequence of bits or to read such
147
+ // / a pulse sequence in. The AIO line is cycled while the value bits are
148
+ // / "shifted" and written out to (shift, shiftWrite) or read in from
149
+ // / (shiftRead) the DIO pin.
150
+ // / @param bitOrder How to shift bits in or out: either LSBFIRST (0) or
151
+ // / MSBFIRST (1), where LSB stands for Least Significant
152
+ // / Bit and MSB for Most Significant Bit.
153
+ // / @param value The value to shift out, with as many lower bits as needed.
154
+ // / This argument is a byte for shift() and a word for the more general
155
+ // / shiftWrite() function.
133
156
inline void shift (uint8_t bitOrder, uint8_t value) const
134
157
{ shiftOut (digiPin (), digiPin2 (), bitOrder, value); }
135
158
uint16_t shiftRead (uint8_t bitOrder, uint8_t count =8 ) const ;
@@ -189,6 +212,15 @@ class RemotePort : protected Port {
189
212
};
190
213
191
214
// / Can be used to drive a software (bit-banged) I2C bus via a Port interface.
215
+ // / The PortI2C class is a special version of class Port implementing the I2C /
216
+ // / Two-Wire Interface (TWI) protocol. Allows using any port as I2C bus master.
217
+ // / When used for I2C, DIO is used as SDA and AIO as SCL.
218
+ // / Unlike the Wire library for the Arduino, which is a more advanced solution
219
+ // / for the hardware I2C lines of an ATmega, the PortI2C class is implemented
220
+ // / entirely in software using "bit-banging". Another difference is that
221
+ // / PortI2C does not use interrupts and will keep the microcontroller occupied
222
+ // / while it is performing I/O transfers.
223
+ // / @see DeviceI2C
192
224
class PortI2C : public Port {
193
225
uint8_t uswait;
194
226
#if 0
0 commit comments