Commit graph

144 commits

Author SHA1 Message Date
jgromes
5ba6f41230 [MOD] Convert end of RF switch mode to macro (https://github.com/jgromes/RadioLib/actions/runs/4337180408) 2023-03-05 19:16:37 +01:00
jgromes
e920e1bf07 [MOD] Fixed some signed comparison warnings 2023-03-05 19:14:14 +01:00
jgromes
3c92219488 [MOD] Fixed print format (#685) 2023-03-01 21:50:40 +01:00
jgromes
32a42ee2c6 [MOD] Fixed format type 2023-02-25 13:28:52 +01:00
jgromes
b014a1f748 [MOD] Improved regdump and hexdump 2023-02-25 13:20:30 +01:00
jgromes
d8c50ae8ad [MOD] Remove default arguments from implementations 2023-02-19 17:12:05 +01:00
jgromes
6bf9cebc43 [MOD] Added SPI stream read/write 2023-02-19 16:59:03 +01:00
jgromes
a8d35f7881 [MOD] Use SPI stream for register read/write 2023-02-19 14:22:30 +01:00
jgromes
308ad87320 [MOD] Port 16-bit address from ax5x43 dev 2023-02-19 12:41:49 +01:00
jgromes
e07d1d9dc1 [MOD] Added stream SPI transfer 2023-02-19 12:32:17 +01:00
Matthijs Kooijman
4c712c1f2c [MOD] Remove constexpr usage
This was introduced when STM32WL support was added. Using constexpr for
the END_OF_MODE_TABLE constant allows it to be initialized in the class
declaration, but this needs C++11. This moves the initialization out of
the class declaration to the .cpp file, which does not need constexpr.
It also lets STM32WLx::END_OF_MODE_TABLE define its value directly
(instead of aliasing Module::END_OF_MODE_TABLE) to prevent reduce
runtime overhead (see below).

The downside of this change is that the value of the END_OF_MODE_TABLE
is no longer visible in other compilation units and thus cannot be
inlined into the rfswitch_table (if used).

For example, on STM32, this means that instead of having a pre-cooked
rfswitch_table that lives in the .rodata section (so can be read
directly from flash), the table lives in RAM and is initialized at
runtime (the actual modes and pins are copied from flash to RAM by the
standard startup loop that copies all of the .data section, and the
END_OF_MODE_TABLE value is copied by a bit of new generated code). This
means a little more runtime overhead, but the cost is mostly in RAM size
(80 bytes for the SMT32WL sketches, 16 per mode plus 16 for the
END_OF_MODE_TABLE).

In a first attempt at this commit, STM32WLx::END_OF_MODE_TABLE was still
initialized using the Module::END_OF_MODE_TABLE value, but since the
latter is also not available at compiletime, this meant initialization
of the former also needed to happen at runtime, adding even more code
overhead (and possibly leading to ordering issues as well). To avoid
this, the STM32WLx::END_OF_MODE_TABLE initialization now just duplicates
that of Module::END_OF_MODE_TABLE.

On AVR, the impact is not so much: Since AVR cannot address flash
directly, the table was already copied from flash to RAM at startup, so
the extra RAM usage is just 4 bytes because END_OF_MODE_TABLE is now
also present in RAM, to be copied into rfswitch_table at startup.

Options for avoiding this overhead (not implemented in this commit)
could be (in no particular order):

1. Use a macro instead of a constant. Downside is that these cannot be
   scoped inside the Module/STM32WLx classes like now, so this requires
   changes to sketches that use a rfswitch_table (and reduced scoping
   and using macros adds more opportunity for conflicts and weird
   errors).
2. Apply the change in this commit only when C++11 is not available.
   Downside is that the initialization value of these constants must be
   duplicated in the .h and .cpp file for C++ and older versions
   respectively.
3. Let sketches just use `{Module::MODE_END_OF_TABLE, {}}` explicitly
   instead of `Module::END_OF_MODE_TABLE`. Downside of this is that this
   requires sketches to be modified and that it lets the sketch encode
   more of the table structure, potentially making future API changes
   harder (but it probably does not really matter in practice).
4. Turn END_OF_MODE_TABLE into a static method, which *can* then be
   defined in the class declaration and inlined. The method can then be
   conditionally marked as constexpr, which allows C++11 compilers to
   completely resolve the rfswitch_table value at compiletime, producing
   a binary identical to before this commit. When constexpr is omitted
   (e.g. on older compilers), some runtime overhead is added (pretty
   much the same as the result from this commit).  Downside is that
   sketches must be modified, and the `END_OF_MODE_TABLE` "constant"
   must now be called, e.g.  `END_OF_MODE_TABLE()` which might be a bit
   unexpected syntax.
2023-02-03 12:42:49 +01:00
Matthijs Kooijman
83ff964b66 [MOD] Generalize rfswitch pin handling
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.
2023-01-09 09:46:39 +01:00
jgromes
04357cb306 [MOD] Added support for interrupt-based timing 2022-11-18 17:03:34 +01:00
jgromes
2980d8dbf1 [MOD] Fixed signed/unsigned comparison warning 2022-09-18 16:20:16 +02:00
jgromes
a8c079f85e [MOD] Fixed hexdump printing when length is not divisible by 16 2022-08-18 20:48:51 +02:00
jgromes
ec94177c2a [MOD] Cache tone value on ESP32 (#553) 2022-08-09 20:20:19 +02:00
jgromes
655dfaae45 Added missing pulsein callback set 2022-08-07 09:57:41 +02:00
Peter Lawrence
4bdec52f88 remedy Module when RADIOLIB_BUILD_ARDUINO is not defined 2022-08-04 17:46:58 -05:00
jgromes
8675f13e5d [Morse] Added basic Morse receive support (#545) CI_BUILD_ALL 2022-07-30 08:53:57 +02:00
jgromes
8ae092ac81 [MOD] Added regdump function 2022-07-04 15:30:37 +02:00
jgromes
f8f73d2ccb [MOD] Added helper hexdump function 2022-07-03 11:05:56 +02:00
jgromes
61a593c6f7 Fixed incorrect macro guards CI_BUILD_ALL 2021-12-19 13:09:42 +01:00
jgromes
1d42f1a0ff [MOD] Use custom tone() on Arduino mbed boards (#407) 2021-12-04 17:04:59 +01:00
jgromes
8111bc058f Added HAL 2021-11-14 11:33:35 +01:00
jgromes
e3ff5affc6 Fix possible issues in CubeCell 1.3.0 (#397) 2021-10-30 21:22:36 +02:00
jgromes
81e8de8324 Drop references to I2C CI_BUILD_ALL 2021-10-28 00:15:02 +02:00
jgromes
2bdec154ad Added CubeCell support 2021-10-27 21:15:46 +02:00
jgromes
5bb9887364 Swapped SerialModule rst and serial arguments 2021-09-24 08:48:23 +02:00
jgromes
0f1140e5ad Added SerialModule wrapper class (#305) 2021-09-05 12:00:30 +02:00
jgromes
5c0b4dbb10 Extract common bit reflection methods 2021-06-14 20:59:16 +02:00
jgromes
d49a107c7e Added SPI readout check bitmask 2021-04-15 19:34:53 +02:00
jgromes
9a9af85fdc Added option to disable "paranoid" SPI mode (enabled by default) 2021-02-12 21:03:49 +01:00
jgromes
533131f83f Fixed unitialized variable warning 2020-12-25 14:17:07 +01:00
jgromes
4cdbcb60c5 Changed ESP32 tone emulation channel to 1 2020-10-29 07:53:51 +01:00
jgromes
5d92240f89 Added support for tone on ESP32 (#190) 2020-10-28 11:24:05 +01:00
jgromes
59c44d3883 Added Module overrides for all Arduino core functions 2020-08-01 16:33:25 +02:00
jgromes
7f31cdab8f Test doxygen TODOs 2020-07-10 08:20:45 +02:00
jgromes
37a94494b4 Added TODOs 2020-07-06 18:30:36 +02:00
jgromes
b8de06288c Added copy ctor and assignment operator 2020-07-05 10:05:54 +02:00
jgromes
c439b097d8 Switched to initializer lists 2020-07-04 16:05:56 +02:00
jgromes
7e62dbd1d8 Fixes from cppcheck scan 2020-07-04 13:43:39 +02:00
jgromes
56360a2a05 Changed setRfSwitchState to directly change switch pins 2020-06-20 16:59:20 +02:00
jgromes
78022ce6ad Added external
RF switch control base
2020-06-18 16:31:38 +02:00
jgromes
da177c9b2a Added interface argument to termination method 2020-05-17 20:26:57 +02:00
jgromes
86da5780c3 Added missing RADIOLIB_DEFAULT_SPI parameter 2020-05-12 16:04:29 +02:00
jgromes
50cc06021b Only stopping hardware interface on automated initialization (#143) 2020-05-12 16:00:13 +02:00
jgromes
6215330858 Added tone support 2020-04-30 17:07:28 +02:00
jgromes
39c259848c Added support for Nano 33 BLE 2020-03-27 14:10:45 +01:00
jgromes
d3cec5d3b4 [Module] Removed String class from AT commands 2020-03-22 08:14:03 +01:00
jgromes
c12cd6a53d [Module] Removed debug-only delays 2020-03-13 21:16:10 +01:00