Skip to content

Commit 9e7f658

Browse files
committed
a bit more docs
1 parent f57da01 commit 9e7f658

File tree

5 files changed

+81
-32
lines changed

5 files changed

+81
-32
lines changed

Ports.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@
2222
#define PWM_CHANGE 0x30 // an analog (pwm) value was changed on port 2..3
2323
#define ANA_MASK 0x0F // an analog read was requested on port 1..4
2424

25+
/// Shift a number of bites in to read them.
26+
/// @param bitOrder How to shift bits in or out: either LSBFIRST (0) or
27+
/// MSBFIRST (1), where LSB stands for Least Significant
28+
/// Bit and MSB for Most Significant Bit.
29+
/// @param count The number of bits to shift in or out. Must be in the
30+
/// range 1 .. 16, the default is 8.
2531
uint16_t Port::shiftRead(uint8_t bitOrder, uint8_t count) const {
2632
uint16_t value = 0, mask = bit(LSBFIRST ? 0 : count - 1);
2733
for (uint8_t i = 0; i < count; ++i) {
@@ -39,6 +45,16 @@ uint16_t Port::shiftRead(uint8_t bitOrder, uint8_t count) const {
3945
return value;
4046
}
4147

48+
/// The shiftWrite() call is similar but more general than the shift() call
49+
/// in that it allows an adjustable number of bits to be sent, not just 8.
50+
/// @param bitOrder How to shift bits in or out: either LSBFIRST (0) or
51+
/// MSBFIRST (1), where LSB stands for Least Significant
52+
/// Bit and MSB for Most Significant Bit.
53+
/// @param value The value to shift out, with as many lower bits as needed.
54+
/// This argument is a byte for shift() and a word for the more general
55+
/// shiftWrite() function.
56+
/// @param count The number of bits to shift in or out. Must be in the
57+
/// range 1 .. 16, the default is 8.
4258
void Port::shiftWrite(uint8_t bitOrder, uint16_t value, uint8_t count) const {
4359
uint16_t mask = bit(LSBFIRST ? 0 : count - 1);
4460
for (uint8_t i = 0; i < count; ++i) {

Ports.h

+38-6
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
/// Interface for JeeNode Ports - see the wiki docs for
2626
/// [JeeNodes](http://jeelabs.net/projects/hardware/wiki/JeeNode) and
2727
/// [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.
2831
class Port {
2932
protected:
3033
/// The port number is a small integer mathing the hardware port used.
@@ -65,8 +68,9 @@ class Port {
6568

6669
// DIO pin
6770

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.
7074
inline void mode(uint8_t value) const
7175
{ pinMode(digiPin(), value); }
7276
/// Reads the value of a Port's D pin.
@@ -81,14 +85,21 @@ class Port {
8185
inline void anaWrite(uint8_t val) const
8286
{ analogWrite(digiPin(), val); }
8387
/// 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.
8491
/// 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.
8595
inline uint32_t pulse(uint8_t state, uint32_t timeout =1000000L) const
8696
{ return pulseIn(digiPin(), state, timeout); }
8797

8898
// AIO pin
8999

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.
92103
inline void mode2(uint8_t value) const
93104
{ pinMode(digiPin2(), value); }
94105
/// Reads an analog value from a Port's A pin.
@@ -110,8 +121,10 @@ class Port {
110121

111122
// IRQ pin (INT1, shared across all ports)
112123

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.
115128
static void mode3(uint8_t value)
116129
{ pinMode(digiPin3(), value); }
117130
/// Reads the value of the I pin on all Ports.
@@ -130,6 +143,16 @@ class Port {
130143

131144
/// Applies Arduino shiftOut() on a with data on the D and clock on A pin
132145
/// 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.
133156
inline void shift(uint8_t bitOrder, uint8_t value) const
134157
{ shiftOut(digiPin(), digiPin2(), bitOrder, value); }
135158
uint16_t shiftRead(uint8_t bitOrder, uint8_t count =8) const;
@@ -189,6 +212,15 @@ class RemotePort : protected Port {
189212
};
190213

191214
/// 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
192224
class PortI2C : public Port {
193225
uint8_t uswait;
194226
#if 0

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ JeeLib {#index}
22
======
33

44
JeeLib is an Arduino [IDE][1] library for the "ports" on [JeeNodes][2], the
5-
%RF12 wireless driver library, timers, low-power code, and several interface
5+
RF12.h wireless driver library, timers, low-power code, and several interface
66
classes. With examples for many sensor & interface boards made by [JeeLabs][3].
77

88
The latest source code for this project is maintained on [GitHub][6].

RF12.h

+25-24
Original file line numberDiff line numberDiff line change
@@ -8,50 +8,51 @@
88

99
#include <stdint.h>
1010

11-
/// RF12 Protocol version.
11+
/// RFM12B Protocol version.
1212
/// Version 1 did not include the group code in the crc.
1313
/// Version 2 does include the group code in the crc.
1414
#define RF12_VERSION 2
1515

16-
/// Shorthand for RF12 group byte in rf12_buf.
16+
/// Shorthand for RFM12B group byte in rf12_buf.
1717
#define rf12_grp rf12_buf[0]
18-
/// Shorthand for RF12 header byte in rf12_buf.
18+
/// Shorthand for RFM12B header byte in rf12_buf.
1919
#define rf12_hdr rf12_buf[1]
20-
/// Shorthand for RF12 length byte in rf12_buf.
20+
/// Shorthand for RFM12B length byte in rf12_buf.
2121
#define rf12_len rf12_buf[2]
22-
/// Shorthand for first RF12 data byte in rf12_buf.
22+
/// Shorthand for first RFM12B data byte in rf12_buf.
2323
#define rf12_data (rf12_buf + 3)
2424

25-
/// RF12 CTL bit mask.
25+
/// RFM12B CTL bit mask.
2626
#define RF12_HDR_CTL 0x80
27-
/// RF12 DST bit mask.
27+
/// RFM12B DST bit mask.
2828
#define RF12_HDR_DST 0x40
29-
/// RF12 ACK bit mask.
29+
/// RFM12B ACK bit mask.
3030
#define RF12_HDR_ACK 0x20
31-
/// RF12 HDR bit mask.
31+
/// RFM12B HDR bit mask.
3232
#define RF12_HDR_MASK 0x1F
3333

34-
/// RF12 Maximum message size in bytes.
34+
/// RFM12B Maximum message size in bytes.
3535
#define RF12_MAXDATA 66
3636

37-
#define RF12_433MHZ 1
38-
#define RF12_868MHZ 2
39-
#define RF12_915MHZ 3
37+
#define RF12_433MHZ 1 ///< RFM12B 433 MHz frequency band.
38+
#define RF12_868MHZ 2 ///< RFM12B 868 MHz frequency band.
39+
#define RF12_915MHZ 3 ///< RFM12B 915 MHz frequency band.
4040

4141
// EEPROM address range used by the rf12_config() code
42-
#define RF12_EEPROM_ADDR ((uint8_t*) 0x20)
43-
#define RF12_EEPROM_SIZE 32
44-
#define RF12_EEPROM_EKEY (RF12_EEPROM_ADDR + RF12_EEPROM_SIZE)
45-
#define RF12_EEPROM_ELEN 16
42+
#define RF12_EEPROM_ADDR ((uint8_t*) 0x20) ///< Starting offset.
43+
#define RF12_EEPROM_SIZE 32 ///< Number of bytes.
44+
#define RF12_EEPROM_EKEY (RF12_EEPROM_ADDR + RF12_EEPROM_SIZE) ///< EE start.
45+
#define RF12_EEPROM_ELEN 16 ///< EE number of bytes.
4646

47-
// shorthands to simplify sending out the proper ACK when requested
47+
/// Shorthand to simplify detecting a request for an ACK.
4848
#define RF12_WANTS_ACK ((rf12_hdr & RF12_HDR_ACK) && !(rf12_hdr & RF12_HDR_CTL))
49+
/// Shorthand to simplify sending out the proper ACK reply.
4950
#define RF12_ACK_REPLY (rf12_hdr & RF12_HDR_DST ? RF12_HDR_CTL : \
5051
RF12_HDR_CTL | RF12_HDR_DST | (rf12_hdr & RF12_HDR_MASK))
5152

5253
// options for RF12_sleep()
53-
#define RF12_SLEEP 0
54-
#define RF12_WAKEUP -1
54+
#define RF12_SLEEP 0 ///< Enter sleep mode.
55+
#define RF12_WAKEUP -1 ///< Wake up from sleep mode.
5556

5657
/// Running crc value, should be zero at end.
5758
extern volatile uint16_t rf12_crc;
@@ -64,13 +65,13 @@ extern long rf12_seq;
6465
/// Set to Dig10 by default for JeeNode. Can be Dig10, Dig9 or Dig8
6566
void rf12_set_cs(uint8_t pin);
6667

67-
/// Only needed if you want to init the SPI bus before rf12_initialize does it.
68+
/// Only needed if you want to init the SPI bus before rf12_initialize() does.
6869
void rf12_spiInit(void);
6970

7071
/// Call this once with the node ID, frequency band, and optional group.
7172
uint8_t rf12_initialize(uint8_t id, uint8_t band, uint8_t group=0xD4);
7273

73-
/// Initialize the RF12 module from settings stored in EEPROM by "RF12demo"
74+
/// Initialize the RFM12B module from settings stored in EEPROM by "RF12demo"
7475
/// don't call rf12_initialize() if you init the hardware with rf12_config().
7576
/// @return the node ID as 1..31 value (1..26 correspond to nodes 'A'..'Z').
7677
uint8_t rf12_config(uint8_t show =1);
@@ -97,8 +98,8 @@ void rf12_sendWait(uint8_t mode);
9798
/// Use this only when the radio was initialized with a fake zero node ID.
9899
void rf12_onOff(uint8_t value);
99100

100-
/// Power off the RF12, ms > 0 sets watchdog to wake up again after N * 32 ms.
101-
/// @note once off, calling this with -1 can be used to bring the RF12 back up.
101+
/// Power off the RFM12B, ms > 0 sets watchdog to wake up again after N * 32 ms.
102+
/// @note if off, calling this with -1 can be used to bring the RFM12B back up.
102103
void rf12_sleep(char n);
103104

104105
/// @return true if the supply voltage is below 3.1V.

RF12sio.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// 2009-05-07 <[email protected]> http://opensource.org/licenses/mit-license.php
22

33
/// @file
4-
/// Streaming I/O layer on top of RF12 driver
4+
/// Streaming I/O layer on top of the RF12.h driver.
55

66
/// This class is NOT the %RF12 driver. It provides a way to construct packets.
77
class RF12 {

0 commit comments

Comments
 (0)