This defines operation modes (IDLE, RX and TX) and allows defining up to
to three pins to be controlled. For each mode a value can be specified
for each pin a table.
Compared to the previous handling, this:
- Allows up to three pins instead of only two.
- Gives more control over output pin values (e.g. to simply change
polarity or support more complex control logic).
In addition, the modes are treated as opaque by the Module code,
allowing radio classes to define their own modes if needed.
Some notes regarding the implementation:
- The number of pins is limited at three, since most boards seem to need
only two pins and only the Nucleo STM32WL55 board needs three. If
more pins are needed in the future, the setRfSwitchTable()
can be overloaded to accept either a 3-element or e.g. 4-element pins
array, to allow new and old code to work as-is.
Note that there is a RFSWITCH_MAX_PINS constant defined, but it is
not recommended for sketches to use this constant when defining
a rfswitch pins array, to prevent issues when this value is ever
increased and such an array gets extra zero elements (that will be
interpreted as pin 0).
Note that this is not a problem for the RfSwitchMode_t values array,
since any extra values in there will only be used if a valid pin was
set in the pins array.
- The pins array is passed by reference, so the compiler complains if
the array passed is not the expected size. Since a reference to an
array without a length is not supported (at least not by the gcc
7 used by the AVR core - gcc 10 for STM32 seems to accept it), the
table array is passed as a pointer instead (but because arrays and
pointers are reasonably interchangeable, the caller does not see the
difference).
- The existing setRfSwitchPins() method is still supported as before.
Internally it creates a table with the right values and pins and
passes those to setRfSwitchTable.
- For easier review, this commit does not modify all calls to
setRfSwitchState() in all radio modules yet, but has a compatibility
wrapper to delay this change until the next commit. Similarly, the
setRfSwitchTable() method is now defined on Module only, a wrapper
for it will be defined in all radios that already have the
setRfSwitchPins() wrapper in another commit.
- To allow future radios to define any number of modes, the modes table
does not have a fixed length, but instead is terminated by a special
value. This is a bit fragile (if the terminator is omitted, the code
will read past the end of the array), but rather flexible. One
alternative to this approach would be to make setRfSwitchTable
a template that deduces the array size from a template argument and
then stores the size explicitly, but using templates probably reduces
code clarity.
All radios that support RfSwitch define this method that simply forwards
to the `Module::setRfSwitchPins()` method. Previously, all these methods
duplicated the documentation as well, but this uses the doxygen \copydoc
to remove this duplication.
In commit a1f94d9f ([SX126x] Set DIO2 to RF switch by default), this was
changed for LoRa modulation in begin(), but since this is really
a board-specific attribute, independent of the modulation used, there is
no reason to have a different default for FSK (so this was probably just
forgotten).
This:
- Updates syncWord comments after changing it from uint16_t to uint8_t
in commit 55aff74a ([SX126x] Changed pin mapping, added reset,
changed LoRa sync word to 1B).
- Adds missing useRegulatorLDO comments forgoten in commit ea85a663
([SX126x] Pass useRegulatorLDO to SX1262/SX1261/SX1268).
- Makes useRegulatorLDO comments the same in all places (using the more
explicit version).
- Fixes a typo in the doxygen \parma -> \param command.
- all `begin()` now use macros for init values
- addressed other styling comments as per PR#612 review
Signed-off-by: Federico Maggi <federico.maggi@gmail.com>