Skip to content

Commit 6ed6990

Browse files
Julia-Hathawaydpgeorge
authored andcommitted
docs/library/zephyr: Add libraries specific to the Zephyr port.
Includes documentation for Zephyr specific modules (zephyr and zsensor), classes (DiskAccess and FlashArea), and functions. Signed-off-by: Julia Hathaway <[email protected]>
1 parent 333e165 commit 6ed6990

File tree

5 files changed

+271
-0
lines changed

5 files changed

+271
-0
lines changed

docs/library/index.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,3 +176,13 @@ The following libraries are specific to the RP2040, as used in the Raspberry Pi
176176
:maxdepth: 2
177177

178178
rp2.rst
179+
180+
Libraries specific to Zephyr
181+
----------------------------
182+
183+
The following libraries are specific to the Zephyr port.
184+
185+
.. toctree::
186+
:maxdepth: 2
187+
188+
zephyr.rst

docs/library/zephyr.DiskAccess.rst

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
.. currentmodule:: zephyr
2+
.. _zephyr.DiskAccess:
3+
4+
class DiskAccess -- access to disk storage
5+
==========================================
6+
7+
Uses `Zephyr Disk Access API <https://docs.zephyrproject.org/latest/reference/storage/disk/access.html>`_.
8+
9+
This class allows access to storage devices on the board, such as support for SD card controllers and
10+
interfacing with SD cards via SPI. Disk devices are automatically detected and initialized on boot using
11+
Zephyr devicetree data.
12+
13+
The Zephyr disk access class enables the transfer of data between a disk device and an accessible memory buffer given a disk name,
14+
buffer, starting disk block, and number of sectors to read. MicroPython reads as many blocks as necessary to fill the buffer, so
15+
the number of sectors to read is found by dividing the buffer length by block size of the disk.
16+
17+
Constructors
18+
------------
19+
20+
.. class:: DiskAccess(disk_name)
21+
22+
Gets an object for accessing disk memory of the specific disk.
23+
For accessing an SD card on the mimxrt1050_evk, ``disk_name`` would be ``SDHC``. See board documentation and
24+
devicetree for usable disk names for your board (ex. RT boards use style USDHC#).
25+
26+
Methods
27+
-------
28+
29+
.. method:: DiskAccess.readblocks(block_num, buf)
30+
DiskAccess.readblocks(block_num, buf, offset)
31+
.. method:: DiskAccess.writeblocks(block_num, buf)
32+
DiskAccess.writeblocks(block_num, buf, offset)
33+
.. method:: DiskAccess.ioctl(cmd, arg)
34+
35+
These methods implement the simple and extended
36+
:ref:`block protocol <block-device-interface>` defined by
37+
:class:`uos.AbstractBlockDev`.
38+

docs/library/zephyr.FlashArea.rst

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
.. currentmodule:: zephyr
2+
.. _zephyr.FlashArea:
3+
4+
class FlashArea -- access to built-in flash storage
5+
===================================================
6+
7+
Uses `Zephyr flash map API <https://docs.zephyrproject.org/latest/reference/storage/flash_map/flash_map.html#flash-map>`_.
8+
9+
This class allows access to device flash partition data.
10+
Flash area structs consist of a globally unique ID number, the name of the flash device the partition is in,
11+
the start offset (expressed in relation to the flash memory beginning address per partition),
12+
and the size of the partition that the device represents. For fixed flash partitions, data from the device
13+
tree is used; however, fixed flash partitioning is not enforced in MicroPython because MCUBoot is not enabled.
14+
15+
Constructors
16+
------------
17+
18+
.. class:: FlashArea(id, block_size)
19+
20+
Gets an object for accessing flash memory at partition specified by ``id`` and with block size of ``block_size``.
21+
22+
``id`` values are integers correlating to fixed flash partitions defined in the devicetree.
23+
A commonly used partition is the designated flash storage area defined as ``FlashArea.STORAGE`` if
24+
``FLASH_AREA_LABEL_EXISTS(storage)`` returns true at boot.
25+
Zephyr devicetree fixed flash partitions are ``boot_partition``, ``slot0_partition``, ``slot1_partition``, and
26+
``scratch_partition``. Because MCUBoot is not enabled by default for MicroPython, these fixed partitions can be accessed by
27+
ID integer values 1, 2, 3, and 4, respectively.
28+
29+
Methods
30+
-------
31+
32+
.. method:: FlashArea.readblocks(block_num, buf)
33+
FlashArea.readblocks(block_num, buf, offset)
34+
.. method:: FlashArea.writeblocks(block_num, buf)
35+
FlashArea.writeblocks(block_num, buf, offset)
36+
.. method:: FlashArea.ioctl(cmd, arg)
37+
38+
These methods implement the simple and extended
39+
:ref:`block protocol <block-device-interface>` defined by
40+
:class:`uos.AbstractBlockDev`.

docs/library/zephyr.rst

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
.. currentmodule:: zephyr
2+
3+
:mod:`zephyr` --- functionality specific to the Zephyr port
4+
===========================================================
5+
6+
.. module:: zephyr
7+
:synopsis: functionality specific to Zephyr
8+
9+
The ``zephyr`` module contains functions and classes specific to the Zephyr port.
10+
11+
Functions
12+
---------
13+
14+
.. function:: is_preempt_thread()
15+
16+
Returns true if the current thread is a preemptible thread.
17+
18+
Zephyr preemptible threads are those with non-negative priority values (low priority levels), which therefore,
19+
can be supplanted as soon as a higher or equal priority thread becomes ready.
20+
21+
.. function:: current_tid()
22+
23+
Returns the thread id of the current thread, which is used to reference the thread.
24+
25+
.. function:: thread_analyze()
26+
27+
Runs the Zephyr debug thread analyzer on the current thread and prints stack size statistics in the format:
28+
29+
"``thread_name``-20s: STACK: unused ``available_stack_space`` usage ``stack_space_used``
30+
/ ``stack_size`` (``percent_stack_space_used`` %); CPU: ``cpu_utilization`` %"
31+
32+
* *CPU utilization is only printed if runtime statistics are configured via the ``CONFIG_THREAD_RUNTIME_STATS`` kconfig*
33+
34+
This function can only be accessed if ``CONFIG_THREAD_ANALYZER`` is configured for the port in ``zephyr/prj.conf``.
35+
For more infomation, see documentation for Zephyr `thread analyzer
36+
<https://docs.zephyrproject.org/latest/guides/debug_tools/thread-analyzer.html#thread-analyzer>`_.
37+
38+
.. function:: shell_exec(cmd_in)
39+
40+
Executes the given command on an UART backend. This function can only be accessed if ``CONFIG_SHELL_BACKEND_SERIAL``
41+
is configured for the port in ``zephyr/prj.conf``.
42+
43+
A list of possible commands can be found in the documentation for Zephyr `shell commands <https://docs.zephyrproject.org/latest/reference/shell/index.html?highlight=shell_execute_cmd#commands>`_.
44+
45+
Classes
46+
-------
47+
48+
.. toctree::
49+
:maxdepth: 1
50+
51+
zephyr.DiskAccess.rst
52+
zephyr.FlashArea.rst
53+
54+
Additional Modules
55+
------------------
56+
57+
.. toctree::
58+
:maxdepth: 1
59+
60+
zephyr.zsensor.rst

docs/library/zephyr.zsensor.rst

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
.. currentmodule:: zsensor
2+
3+
:mod:`zsensor` --- Zephyr sensor bindings
4+
=========================================
5+
6+
.. module:: zsensor
7+
:synopsis: zephyr sensor bindings
8+
9+
The ``zsensor`` module contains a class for using sensors with Zephyr.
10+
11+
.. _zsensor.Sensor:
12+
13+
class Sensor --- sensor control for the Zephyr port
14+
---------------------------------------------------
15+
16+
Use this class to access data from sensors on your board.
17+
See Zephyr documentation for sensor usage here: `Sensors
18+
<https://docs.zephyrproject.org/latest/reference/peripherals/sensor.html?highlight=sensor#sensors>`_.
19+
20+
Sensors are defined in the Zephyr devicetree for each board. The quantities that a given sensor can
21+
measure are called a sensor channels. Sensors can have multiple channels to represent different axes
22+
of one property or different properties a sensor can measure. See `Channels`_ below for defined sensor
23+
channels.
24+
25+
Constructor
26+
~~~~~~~~~~~
27+
28+
.. class:: Sensor(device_name)
29+
30+
Device names are defined in the devicetree for your board.
31+
For example, the device name for the accelerometer in the FRDM-k64f board is "FXOS8700".
32+
33+
Methods
34+
~~~~~~~
35+
36+
.. method:: Sensor.measure()
37+
38+
Obtains a measurement sample from the sensor device using Zephyr sensor_sample_fetch and
39+
stores it in an internal driver buffer as a useful value, a pair of (integer part of value,
40+
fractional part of value in 1-millionths).
41+
Returns none if successful or OSError value if failure.
42+
43+
.. method:: Sensor.get_float(sensor_channel)
44+
45+
Returns the value of the sensor measurement sample as a float.
46+
47+
.. method:: Sensor.get_micros(sensor_channel)
48+
49+
Returns the value of the sensor measurement sample in millionths.
50+
(Ex. value of ``(1, 500000)`` returns as ``1500000``)
51+
52+
.. method:: Sensor.get_millis(sensor_channel)
53+
54+
Returns the value of sensor measurement sample in thousandths.
55+
(Ex. value of ``(1, 500000)`` returns as ``1500``)
56+
57+
.. method:: Sensor.get_int(sensor_channel)
58+
59+
Returns only the integer value of the measurement sample.
60+
(Ex. value of ``(1, 500000)`` returns as ``1``)
61+
62+
Channels
63+
~~~~~~~~
64+
65+
.. data:: ACCEL_X
66+
67+
Acceleration on the X axis, in m/s^2.
68+
69+
.. data:: ACCEL_Y
70+
71+
Acceleration on the Y axis, in m/s^2.
72+
73+
.. data:: ACCEL_Z
74+
75+
Acceleration on the Z axis, in m/s^2.
76+
77+
.. data:: GYRO_X
78+
79+
Angular velocity around the X axis, in radians/s.
80+
81+
.. data:: GYRO_Y
82+
83+
Angular velocity around the Y axis, in radians/s.
84+
85+
.. data:: GYRO_Z
86+
87+
Angular velocity around the Z axis, in radians/s.
88+
89+
.. data:: MAGN_X
90+
91+
Magnetic field on the X axis, in Gauss.
92+
93+
.. data:: MAGN_Y
94+
95+
Magnetic field on the Y axis, in Gauss.
96+
97+
.. data:: MAGN_Z
98+
99+
Magnetic field on the Z axis, in Gauss.
100+
101+
.. data:: DIE_TEMP
102+
103+
Device die temperature in degrees Celsius.
104+
105+
.. data:: PRESS
106+
107+
Pressure in kilopascal.
108+
109+
.. data:: PROX
110+
111+
Proximity. Dimensionless. A value of 1 indicates that an object is close.
112+
113+
.. data:: HUMIDITY
114+
115+
Humidity, in percent.
116+
117+
.. data:: LIGHT
118+
119+
Illuminance in visible spectrum, in lux.
120+
121+
.. data:: ALTITUDE
122+
123+
Altitude, in meters.

0 commit comments

Comments
 (0)