|
| 1 | +========================================== |
| 2 | +``npzero`` nPZero G1S power-saving example |
| 3 | +========================================== |
| 4 | + |
| 5 | +This example uses the nPZero G1S driver |
| 6 | +(:doc:`/os/drivers/special/power/npzero`) with the sensors of the nPZero G1S |
| 7 | +Development Kit (:doc:`/platforms/arm/stm32l0/boards/npzero-g1s-dk/index`), |
| 8 | +like the example of the Nanopower driver API: |
| 9 | + |
| 10 | +- a LIS2DW12 accelerometer on peripheral 3 (SPI, PMOD 3), read every 5 s; it |
| 11 | + wakes the host up when the X acceleration is above about 61 mg, |
| 12 | +- an AS6212 temperature sensor on peripheral 4 (I2C, PMOD 4), read every 30 s; |
| 13 | + it wakes the host up when the temperature is above 25 C or below 10 C. |
| 14 | + |
| 15 | +The host is also woken up by the global time-out, after 300 s. |
| 16 | + |
| 17 | +At each boot of the host, the example: |
| 18 | + |
| 19 | +#. reads and shows the ID of the nPZero and the wake-up reason (STA1 and |
| 20 | + STA2), with the last value of each peripheral that triggered it and the |
| 21 | + ADC values when an ADC channel triggered it, |
| 22 | +#. sends the configuration (``NPZEROIOC_CONFIGURE``), |
| 23 | +#. waits ``CONFIG_EXAMPLES_NPZERO_IDLE_DELAY`` milliseconds, which leaves time |
| 24 | + to connect a debugger, |
| 25 | +#. sends the Idle command (``NPZEROIOC_IDLE``): the nPZero switches the host |
| 26 | + off until the next wake-up. |
| 27 | + |
| 28 | +Usage:: |
| 29 | + |
| 30 | + npzero [-s] |
| 31 | + |
| 32 | +``-s`` shows the ID and the status only, without configuring the nPZero nor |
| 33 | +entering Idle state. |
| 34 | + |
| 35 | +The AS6212 board shares the I2C bus with the host, and an unpowered AS6212 |
| 36 | +board blocks the bus (see *Shared I2C bus* in |
| 37 | +:doc:`/os/drivers/special/power/npzero`). So the example keeps both sensors |
| 38 | +powered while the host is on (``pswint``), and the ``npzero-g1s-dk`` board |
| 39 | +powers them after a reset of the nPZero |
| 40 | +(``CONFIG_NPZERO_G1S_DK_PMOD_POWER``). Without this, ``/dev/npzero0`` is not |
| 41 | +registered (``npzero_register()`` fails with ``-EAGAIN``) and the example |
| 42 | +fails to open it. Do not plug the sensor boards while the host is running. |
| 43 | + |
| 44 | +Configuration |
| 45 | +============= |
| 46 | + |
| 47 | +- ``CONFIG_EXAMPLES_NPZERO``: enables the example. It needs ``CONFIG_NPZERO``. |
| 48 | +- ``CONFIG_EXAMPLES_NPZERO_DEVPATH``: path of the device, ``/dev/npzero0`` by |
| 49 | + default. |
| 50 | +- ``CONFIG_EXAMPLES_NPZERO_IDLE_DELAY``: delay before the Idle command, in |
| 51 | + milliseconds (1000 by default). |
| 52 | + |
| 53 | +The example can be the entry point of the system |
| 54 | +(``CONFIG_INIT_ENTRYPOINT="npzero_main"``), as in the ``npzero-g1s-dk:npzero`` |
| 55 | +configuration, since the host restarts at each wake-up. |
0 commit comments