Skip to content

Commit 65bc4f4

Browse files
[wip] doc: add driver index
We have thorough existing documentation on the abstract driver model. We have some documentation on individual APIs (though the generated content is not very useful and should probably be looked at; I suspect 99.9% of users are just reading the doxygen comments in the source code instead of looking at these pages). We do not, however, have documentation for actual device drivers, or information about what devicetree compatibles and Kconfig options they are associated with. This patch is a proof of concept showing how the previous patches in the series can be stitched together into an index of existing drivers that cross-references DT and Kconfig as needed, with content coming from the sources. Signed-off-by: Martí Bolívar <[email protected]>
1 parent 383c3ea commit 65bc4f4

File tree

4 files changed

+528
-2
lines changed

4 files changed

+528
-2
lines changed

doc/CMakeLists.txt

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,16 @@ set(I18NSPHINXOPTS ${SPHINXOPTS})
9292
set(DOXYFILE_IN ${CMAKE_CURRENT_LIST_DIR}/zephyr.doxyfile.in)
9393
set(DOXYFILE_OUT ${CMAKE_CURRENT_BINARY_DIR}/zephyr.doxyfile)
9494
set(DOXY_OUT ${CMAKE_CURRENT_BINARY_DIR}/doxygen)
95+
set(DOXY_XML_OUT ${DOXY_OUT}/xml)
9596
set(RST_OUT ${CMAKE_CURRENT_BINARY_DIR}/rst)
9697
set(DOC_LOG ${CMAKE_CURRENT_BINARY_DIR}/doc.log)
9798
set(DOXY_LOG ${CMAKE_CURRENT_BINARY_DIR}/doxy.log)
9899
set(SPHINX_LOG ${CMAKE_CURRENT_BINARY_DIR}/sphinx.log)
99100
set(DOC_WARN ${CMAKE_CURRENT_BINARY_DIR}/doc.warnings)
100101
set(CONTENT_OUTPUTS ${CMAKE_CURRENT_BINARY_DIR}/extracted-content.txt)
101102

103+
# TODO: need to pass all the modules which have drivers/
104+
# subdirectories in here too
102105
configure_file(${DOXYFILE_IN} ${DOXYFILE_OUT} @ONLY)
103106

104107
# This command is used to copy all documentation source files from the
@@ -300,6 +303,48 @@ add_custom_target(
300303

301304
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${GEN_DEVICETREE_REST_SCRIPT})
302305

306+
#
307+
# Generated device driver .rst documents.
308+
#
309+
# The device drivers discovered in ${DRIVER_MODULES} are parsed and
310+
# documentation for them is generated in the directory ${DRIVERS_RST_OUT}.
311+
# Defaults:
312+
#
313+
# - DRIVER_MODULES: ZEPHYR_BASE
314+
# - DRIVERS_RST_OUT: ${RST_OUT}/doc/drivers
315+
316+
set(GEN_DRIVER_REST_SCRIPT ${CMAKE_CURRENT_LIST_DIR}/scripts/gen_driver_rest.py)
317+
318+
if(NOT DRIVER_MODULES)
319+
set(DRIVER_MODULES ${ZEPHYR_BASE})
320+
endif()
321+
322+
set(DRIVER_MODULES_ARGS)
323+
foreach(module ${DRIVER_MODULES})
324+
list(APPEND DRIVER_MODULES_ARGS --module ${module})
325+
endforeach()
326+
327+
if(NOT DRIVERS_RST_OUT)
328+
set(DRIVERS_RST_OUT ${RST_OUT}/doc/drivers)
329+
endif()
330+
331+
add_custom_target(
332+
drivers
333+
COMMAND ${CMAKE_COMMAND} -E env
334+
${PYTHON_EXECUTABLE} ${GEN_DRIVER_REST_SCRIPT}
335+
--doxygen-xml ${DOXY_XML_OUT}
336+
${DRIVER_MODULES_ARGS}
337+
${DRIVERS_RST_OUT}
338+
VERBATIM
339+
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
340+
COMMENT "Running gen_drivers_rest.py ${DRIVERS_RST_OUT}"
341+
USES_TERMINAL
342+
)
343+
344+
add_dependencies(drivers doxy_real_modified_times)
345+
346+
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${GEN_DRIVER_REST_SCRIPT})
347+
303348
#
304349
# HTML section
305350
#
@@ -414,7 +459,7 @@ endif()
414459
#
415460
# Dependencies and final targets
416461
#
417-
add_dependencies(html content doxy_real_modified_times kconfig devicetree)
462+
add_dependencies(html content doxy_real_modified_times kconfig devicetree drivers)
418463

419464
add_custom_target(
420465
htmldocs
@@ -427,7 +472,7 @@ add_custom_target(
427472
)
428473
add_dependencies(doxygen doxy_real_modified_times)
429474

430-
add_dependencies(latex content doxy_real_modified_times kconfig devicetree)
475+
add_dependencies(latex content doxy_real_modified_times kconfig devicetree drivers)
431476

432477
add_custom_target(
433478
latexdocs

doc/drivers/index.rst

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
.. _device_drivers:
2+
3+
Device Drivers
4+
##############
5+
6+
This page is an index of device drivers. Each device driver implements a Zephyr
7+
:ref:`API <api_overview>`. Device drivers are responsible for creating the
8+
:c:struct:`device` structures at the heart of Zephyr's :ref:`device and driver
9+
model <device_model_api>`.
10+
11+
To enable a device driver -- i.e. compile and link the driver source code into
12+
your Zephyr :ref:`application <application>` -- you will typically need to:
13+
14+
- enable the driver using :ref:`Kconfig <kconfig>`
15+
- configure one or more devices using :ref:`devicetree <dt-guide>`
16+
17+
In order to use the device driver, you will need a pointer to a ``struct
18+
device`` created by the driver source. This is done with the
19+
:c:func:`device_get_binding` function, which requires the name of the device.
20+
For help getting a pointer to a device configured in the devicetree, see
21+
:ref:`dt-get-device`.
22+
23+
.. Note: there's nothing else in this directory because the toctree is pulling
24+
in files created by gen_driver_rest.py.
25+
26+
.. TODO: figure out how to glob this; "*/index.rst" didn't work with plain :glob:
27+
28+
.. toctree::
29+
30+
adc/index.rst
31+
clock_control/index.rst
32+
counter/index.rst
33+
entropy/index.rst
34+
flash/index.rst
35+
gpio/index.rst
36+
hwinfo/index.rst
37+
i2c/index.rst
38+
ipm/index.rst
39+
pwm/index.rst
40+
sensor/index.rst
41+
serial/index.rst
42+
spi/index.rst
43+
usb/index.rst
44+
watchdog/index.rst

doc/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ licensing, as described in :ref:`Zephyr_Licensing`.
114114
development_process/index.rst
115115
application/index.rst
116116
reference/index.rst
117+
drivers/index.rst
117118
guides/index.rst
118119
security/index.rst
119120
samples/index.rst

0 commit comments

Comments
 (0)