RP2040 Helper Class
===================

Some of the core functionality of the RP2040 chip powering the Raspberry Pi
Pico is exposed in the RP2040 class variable ``rp2040``.

Core Internals
--------------

int rp2040.f_cpu()
~~~~~~~~~~~~~~~~~~
Returns the current frequency of the core clock.  This is read at runtime,
versus the constant ``F_CPU`` macro that is also available.  This is useful
in cases where your code changes the core clock (i.e. low power modes, etc.)

int rp2040.cpuid()
~~~~~~~~~~~~~~~~~~
Returns the current core ID (0 or 1) of the executing task.

uint32_t rp2040.getCycleCount()
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Returns a 32-bit cycle count from then the core started running.  Because it
is only 32-bits, and the Pico runs at 133MHz, this value can loop around
in a matter of seconds.

uint64_t rp2040.getCycleCount64()
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Returns a 64-bit cycle count from then the core started running.  This value
should never loop around in normal mode (at 133MHz it would take over 4,000
years to overflow).

uint32_t rp2040.hwrand32()
~~~~~~~~~~~~~~~~~~~~~~~~~~
Returns a 32-bit value derived from the CPU cycle counter and the ROSC
oscillator.  Because the ROSC bit is not a true random number generator, the
values returned may not meet the most stringent random tests.  **If your
application needs absolute bulletproof random numbers, consider using
dedicated external hardware.**

void rp2040.reboot()
~~~~~~~~~~~~~~~~~~~~
Forces a hardware reboot of the Pico.

Hardware Watchdog
-----------------

void rp2040.wdt_begin(uint32_t delay_ms)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Enables the hardware watchdog timer with a delay value of delay_ms
milliseconds. Note that on the RP2040, once this function has called, the
hardware watchdog can _not_ be disabled.

The maximum ``delay_ms`` allowed in this call is ``8300``, corresponding
to 8.3 seconds.  Any higher values will be truncated by the hardware.

void rp2040.wdt_reset()
~~~~~~~~~~~~~~~~~~~~~~~
Reloads the watchdog's counter with the amount of time set by wdt_begin.


Memory Information
------------------

int rp2040.getFreeHeap()
~~~~~~~~~~~~~~~~~~~~~~~~
Returns the number of bytes free for heap allocation (i.e. malloc, new).  Note
that because there is some overhead, and there may be heap fragmentation,
this number is an *upper bound* and you generally will only be able to allocate
less than this returned number.

int rp2040.getUsedHeap()
~~~~~~~~~~~~~~~~~~~~~~~~
Returns the number of bytes allocated out of the heap.

int rp2040.getTotalHeap()
~~~~~~~~~~~~~~~~~~~~~~~~~
Returns the total heap that was available to this program at compile time (i.e.
the Pico RAM size minus things like the ``.data`` and ``.bss`` sections and other
overhead).

Hardware Identification
-----------------------

bool rp2040.isPicoW()
~~~~~~~~~~~~~~~~~~~~~
Returns the core's best guess if this code is running on a Raspberry Pi Pico W.
This would let you, possibly, use the same UF2 for Pico and PicoW by simply not
doing any WiFi calls.

Bootloader
----------

void rp2040.enableDoubleResetBootloader()
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Add a call anywhere in the sketch to ``rp2040.enableDoubleResetBootloader()`` and
the core will check for a double-tap on reset, and if found will start the USB
bootloader.

void rp2040.rebootToBootloader()
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Will reboot the RP2040 into USB UF2 upload mode.
