1# -*- coding: utf-8 -*-
2#
3# Common (non-language-specific) configuration for Read The Docs & Sphinx
4#
5# Based on a Read the Docs Template documentation build configuration file,
6# created by sphinx-quickstart on Tue Aug 26 14:19:49 2014.
7#
8# This file is imported from a language-specific conf.py (ie en/conf.py or
9# zh_CN/conf.py)
10#
11# Note that not all possible configuration values are present in this
12# autogenerated file.
13#
14# All configuration values have a default; values that are commented out
15# serve to show the default.
16
17from __future__ import print_function, unicode_literals
18
19import os
20import os.path
21import re
22import subprocess
23import sys
24
25from get_github_rev import get_github_rev
26from idf_extensions.util import download_file_if_missing
27from sanitize_version import sanitize_version
28
29# build_docs on the CI server sometimes fails under Python3. This is a workaround:
30sys.setrecursionlimit(3500)
31
32config_dir = os.path.abspath(os.path.dirname(__file__))
33
34# http://stackoverflow.com/questions/12772927/specifying-an-online-image-in-sphinx-restructuredtext-format
35#
36suppress_warnings = ['image.nonlocal_uri']
37
38# -- General configuration ------------------------------------------------
39
40# If your documentation needs a minimal Sphinx version, state it here.
41# needs_sphinx = '1.0'
42
43# Add any Sphinx extension module names here, as strings. They can be
44# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
45# ones.
46extensions = ['breathe',
47
48              'sphinx.ext.todo',
49              'sphinx_copybutton',
50              'sphinx_idf_theme',
51              'sphinxcontrib.blockdiag',
52              'sphinxcontrib.seqdiag',
53              'sphinxcontrib.actdiag',
54              'sphinxcontrib.nwdiag',
55              'sphinxcontrib.rackdiag',
56              'sphinxcontrib.packetdiag',
57              'sphinxcontrib.cairosvgconverter',
58
59              'extensions.html_redirects',
60              'extensions.toctree_filter',
61              'extensions.list_filter',
62
63              # Note: order is important here, events must
64              # be registered by one extension before they can be
65              # connected to another extension
66
67              'idf_extensions.include_build_file',
68              'idf_extensions.link_roles',
69              'idf_extensions.build_system',
70              'idf_extensions.esp_err_definitions',
71              'idf_extensions.gen_toolchain_links',
72              'idf_extensions.gen_version_specific_includes',
73              'idf_extensions.kconfig_reference',
74              'idf_extensions.gen_defines',
75              'idf_extensions.run_doxygen',
76              'idf_extensions.gen_idf_tools_links',
77              'idf_extensions.format_idf_target',
78              'idf_extensions.latex_builder',
79              'idf_extensions.exclude_docs',
80
81              # from https://github.com/pfalcon/sphinx_selective_exclude
82              'sphinx_selective_exclude.eager_only',
83              # TODO: determine if we need search_auto_exclude
84              # 'sphinx_selective_exclude.search_auto_exclude',
85              ]
86
87# sphinx.ext.todo extension parameters
88# If the below parameter is True, the extension
89# produces output, else it produces nothing.
90todo_include_todos = False
91
92# Enabling this fixes cropping of blockdiag edge labels
93seqdiag_antialias = True
94
95# Add any paths that contain templates here, relative to this directory.
96templates_path = ['_templates']
97
98# The suffix of source filenames.
99source_suffix = ['.rst', '.md']
100
101source_parsers = {'.md': 'recommonmark.parser.CommonMarkParser',
102                  }
103
104# The encoding of source files.
105# source_encoding = 'utf-8-sig'
106
107# The master toctree document.
108master_doc = 'index'
109
110
111# The version info for the project you're documenting, acts as replacement for
112# |version| and |release|, also used in various other places throughout the
113# built documents.
114#
115
116# This is the full exact version, canonical git version description
117# visible when you open index.html.
118version = subprocess.check_output(['git', 'describe']).strip().decode('utf-8')
119
120# The 'release' version is the same as version for non-CI builds, but for CI
121# builds on a branch then it's replaced with the branch name
122release = sanitize_version(version)
123
124print('Version: {0}  Release: {1}'.format(version, release))
125
126# There are two options for replacing |today|: either, you set today to some
127# non-false value, then it is used:
128# today = ''
129# Else, today_fmt is used as the format for a strftime call.
130# today_fmt = '%B %d, %Y'
131
132# List of patterns, relative to source directory, that match files and
133# directories to ignore when looking for source files.
134exclude_patterns = ['**/inc/**', '_static/', '_build/**']
135
136BT_DOCS = ['api-guides/blufi.rst',
137           'api-guides/esp-ble-mesh/**',
138           'api-reference/bluetooth/**']
139
140SDMMC_DOCS = ['api-reference/peripherals/sdmmc_host.rst',
141              'api-reference/peripherals/sd_pullup_requirements.rst']
142
143SDIO_SLAVE_DOCS = ['api-reference/peripherals/sdio_slave.rst',
144                   'api-reference/protocols/esp_sdio_slave_protocol.rst']
145
146MCPWM_DOCS = ['api-reference/peripherals/mcpwm.rst']
147
148DEDIC_GPIO_DOCS = ['api-reference/peripherals/dedic_gpio.rst']
149
150PCNT_DOCS = ['api-reference/peripherals/pcnt.rst']
151
152DAC_DOCS = ['api-reference/peripherals/dac.rst']
153
154TOUCH_SENSOR_DOCS = ['api-reference/peripherals/touch_pad.rst']
155
156SPIRAM_DOCS = ['api-guides/external-ram.rst']
157
158LEGACY_DOCS = ['api-guides/build-system-legacy.rst',
159               'gnu-make-legacy.rst',
160               'api-guides/ulp-legacy.rst',
161               'api-guides/unit-tests-legacy.rst',
162               'get-started-legacy/**']
163
164USB_DOCS = ['api-reference/peripherals/usb.rst',
165            'api-guides/usb-console.rst',
166            'api-guides/dfu.rst']
167
168FTDI_JTAG_DOCS = ['api-guides/jtag-debugging/configure-ft2232h-jtag.rst']
169
170BUILTIN_JTAG_DOCS = ['api-guides/jtag-debugging/configure-builtin-jtag.rst']
171
172ULP_DOCS = ['api-guides/ulp.rst', 'api-guides/ulp_macros.rst']
173
174RISCV_COPROC_DOCS = ['api-guides/ulp-risc-v.rst',]
175
176XTENSA_DOCS = ['api-guides/hlinterrupts.rst',
177               'api-reference/system/perfmon.rst']
178
179RISCV_DOCS = []
180
181ESP32_DOCS = ['api-guides/ulp_instruction_set.rst',
182              'api-reference/system/himem.rst',
183              'api-guides/RF_calibration.rst',
184              'api-guides/romconsole.rst',
185              'api-reference/system/ipc.rst',
186              'security/secure-boot-v1.rst',
187              'api-reference/peripherals/secure_element.rst',
188              'api-reference/peripherals/dac.rst',
189              'hw-reference/esp32/**'] + LEGACY_DOCS + FTDI_JTAG_DOCS
190
191ESP32S2_DOCS = ['hw-reference/esp32s2/**',
192                'api-guides/ulps2_instruction_set.rst',
193                'api-guides/usb-console.rst',
194                'api-reference/peripherals/hmac.rst',
195                'api-reference/peripherals/ds.rst',
196                'api-reference/peripherals/spi_slave_hd.rst',
197                'api-reference/peripherals/temp_sensor.rst',
198                'api-reference/system/async_memcpy.rst',
199                'api-reference/peripherals/touch_element.rst',
200                'api-reference/peripherals/dac.rst'] + FTDI_JTAG_DOCS
201
202ESP32C3_DOCS = ['hw-reference/esp32c3/**'] + BUILTIN_JTAG_DOCS
203
204# format: {tag needed to include: documents to included}, tags are parsed from sdkconfig and peripheral_caps.h headers
205conditional_include_dict = {'SOC_BT_SUPPORTED':BT_DOCS,
206                            'SOC_SDMMC_HOST_SUPPORTED':SDMMC_DOCS,
207                            'SOC_SDIO_SLAVE_SUPPORTED':SDIO_SLAVE_DOCS,
208                            'SOC_MCPWM_SUPPORTED':MCPWM_DOCS,
209                            'SOC_USB_SUPPORTED':USB_DOCS,
210                            'SOC_DEDICATED_GPIO_SUPPORTED':DEDIC_GPIO_DOCS,
211                            'SOC_SPIRAM_SUPPORTED':SPIRAM_DOCS,
212                            'SOC_PCNT_SUPPORTED':PCNT_DOCS,
213                            'SOC_DAC_PERIPH_NUM':DAC_DOCS,
214                            'SOC_TOUCH_SENSOR_NUM':TOUCH_SENSOR_DOCS,
215                            'SOC_ULP_SUPPORTED':ULP_DOCS,
216                            'SOC_RISCV_COPROC_SUPPORTED':RISCV_COPROC_DOCS,
217                            'SOC_DIG_SIGN_SUPPORTED':['api-reference/peripherals/ds.rst'],
218                            'SOC_HMAC_SUPPORTED':['api-reference/peripherals/hmac.rst'],
219                            'SOC_ASYNC_MEMCPY_SUPPORTED':['api-reference/system/async_memcpy.rst'],
220                            'CONFIG_IDF_TARGET_ARCH_XTENSA':XTENSA_DOCS,
221                            'CONFIG_IDF_TARGET_ARCH_RISCV':RISCV_DOCS,
222                            'esp32':ESP32_DOCS,
223                            'esp32s2':ESP32S2_DOCS,
224                            'esp32c3':ESP32C3_DOCS}
225
226# The reST default role (used for this markup: `text`) to use for all
227# documents.
228# default_role = None
229
230# If true, '()' will be appended to :func: etc. cross-reference text.
231# add_function_parentheses = True
232
233# If true, the current module name will be prepended to all description
234# unit titles (such as .. function::).
235# add_module_names = True
236
237# If true, sectionauthor and moduleauthor directives will be shown in the
238# output. They are ignored by default.
239# show_authors = False
240
241# The name of the Pygments (syntax highlighting) style to use.
242pygments_style = 'sphinx'
243
244# A list of ignored prefixes for module index sorting.
245# modindex_common_prefix = []
246
247# If true, keep warnings as "system message" paragraphs in the built documents.
248# keep_warnings = False
249
250
251# Extra options required by sphinx_idf_theme
252project_slug = 'esp-idf'
253versions_url = 'https://dl.espressif.com/dl/esp-idf/idf_versions.js'
254
255idf_targets = ['esp32', 'esp32s2', 'esp32c3']
256languages = ['en', 'zh_CN']
257
258project_homepage = 'https://github.com/espressif/esp-idf'
259
260# -- Options for HTML output ----------------------------------------------
261
262# Custom added feature to allow redirecting old URLs
263#
264# Redirects should be listed in page_redirects.xt
265#
266with open('../page_redirects.txt') as f:
267    lines = [re.sub(' +', ' ', line.strip()) for line in f.readlines() if line.strip() != '' and not line.startswith('#')]
268    for line in lines:  # check for well-formed entries
269        if len(line.split(' ')) != 2:
270            raise RuntimeError('Invalid line in page_redirects.txt: %s' % line)
271html_redirect_pages = [tuple(line.split(' ')) for line in lines]
272
273# The theme to use for HTML and HTML Help pages.  See the documentation for
274# a list of builtin themes.
275
276html_theme = 'sphinx_idf_theme'
277
278# context used by sphinx_idf_theme
279html_context = {
280    'display_github': True,  # Add 'Edit on Github' link instead of 'View page source'
281    'github_user': 'espressif',
282    'github_repo': 'esp-idf',
283    'github_version': get_github_rev(),
284}
285
286# Theme options are theme-specific and customize the look and feel of a theme
287# further.  For a list of options available for each theme, see the
288# documentation.
289# html_theme_options = {}
290
291# Add any paths that contain custom themes here, relative to this directory.
292# html_theme_path = []
293
294# The name for this set of Sphinx documents.  If None, it defaults to
295# "<project> v<release> documentation".
296# html_title = None
297
298# A shorter title for the navigation bar.  Default is the same as html_title.
299# html_short_title = None
300
301# The name of an image file (relative to this directory) to place at the top
302# of the sidebar.
303html_logo = '../_static/espressif-logo.svg'
304
305
306# The name of an image file (within the static path) to use as favicon of the
307# docs.  This file should be a Windows icon file (.ico) being 16x16 or 32x32
308# pixels large.
309# html_favicon = None
310
311# Add any paths that contain custom static files (such as style sheets) here,
312# relative to this directory. They are copied after the builtin static files,
313# so a file named "default.css" will overwrite the builtin "default.css".
314html_static_path = ['../_static']
315
316# Add any extra paths that contain custom files (such as robots.txt or
317# .htaccess) here, relative to this directory. These files are copied
318# directly to the root of the documentation.
319# html_extra_path = []
320
321# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
322# using the given strftime format.
323# html_last_updated_fmt = '%b %d, %Y'
324
325# If true, SmartyPants will be used to convert quotes and dashes to
326# typographically correct entities.
327# html_use_smartypants = True
328
329# Custom sidebar templates, maps document names to template names.
330# html_sidebars = {}
331
332# Additional templates that should be rendered to pages, maps page names to
333# template names.
334# html_additional_pages = {}
335
336# If false, no module index is generated.
337# html_domain_indices = True
338
339# If false, no index is generated.
340# html_use_index = True
341
342# If true, the index is split into individual pages for each letter.
343# html_split_index = False
344
345# If true, links to the reST sources are added to the pages.
346# html_show_sourcelink = True
347
348# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
349# html_show_sphinx = True
350
351# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
352# html_show_copyright = True
353
354# If true, an OpenSearch description file will be output, and all pages will
355# contain a <link> tag referring to it.  The value of this option must be the
356# base URL from which the finished HTML is served.
357# html_use_opensearch = ''
358
359# This is the file name suffix for HTML files (e.g. ".xhtml").
360# html_file_suffix = None
361
362# Output file base name for HTML help builder.
363htmlhelp_basename = 'ReadtheDocsTemplatedoc'
364
365# -- Options for LaTeX output ---------------------------------------------
366
367latex_template_dir = os.path.join(config_dir, 'latex_templates')
368
369preamble = ''
370with open(os.path.join(latex_template_dir, 'preamble.tex')) as f:
371    preamble = f.read()
372
373titlepage = ''
374with open(os.path.join(latex_template_dir, 'titlepage.tex')) as f:
375    titlepage = f.read()
376
377
378latex_elements = {
379    'papersize': 'a4paper',
380
381    # Latex figure (float) alignment
382    'figure_align':'htbp',
383
384    'pointsize': '10pt',
385
386    # Additional stuff for the LaTeX preamble.
387    'fncychap': '\\usepackage[Sonny]{fncychap}',
388
389    'preamble': preamble,
390
391    'maketitle': titlepage,
392}
393
394# The name of an image file (relative to this directory) to place at the bottom of
395# the title page.
396latex_logo = '../_static/espressif2.pdf'
397latex_engine = 'xelatex'
398latex_use_xindy = False
399
400# -- Options for manual page output ---------------------------------------
401
402# One entry per manual page. List of tuples
403# (source start file, name, description, authors, manual section).
404man_pages = [
405    ('index', 'readthedocstemplate', u'Read the Docs Template Documentation',
406     [u'Read the Docs'], 1)
407]
408
409# If true, show URL addresses after external links.
410# man_show_urls = False
411
412
413# -- Options for Texinfo output -------------------------------------------
414
415# Grouping the document tree into Texinfo files. List of tuples
416# (source start file, target name, title, author,
417#  dir menu entry, description, category)
418texinfo_documents = [
419    ('index', 'ReadtheDocsTemplate', u'Read the Docs Template Documentation',
420     u'Read the Docs', 'ReadtheDocsTemplate', 'One line description of project.',
421     'Miscellaneous'),
422]
423
424# Documents to append as an appendix to all manuals.
425# texinfo_appendices = []
426
427# If false, no module index is generated.
428# texinfo_domain_indices = True
429
430# How to display URL addresses: 'footnote', 'no', or 'inline'.
431# texinfo_show_urls = 'footnote'
432
433# If true, do not generate a @detailmenu in the "Top" node's menu.
434# texinfo_no_detailmenu = False
435
436
437# Override RTD CSS theme to introduce the theme corrections
438# https://github.com/rtfd/sphinx_rtd_theme/pull/432
439def setup(app):
440    app.add_stylesheet('theme_overrides.css')
441
442    # these two must be pushed in by build_docs.py
443    if 'idf_target' not in app.config:
444        app.add_config_value('idf_target', None, 'env')
445        app.add_config_value('idf_targets', None, 'env')
446
447    app.add_config_value('conditional_include_dict', None, 'env')
448    app.add_config_value('docs_to_build', None, 'env')
449
450    # Breathe extension variables (depend on build_dir)
451    # note: we generate into xml_in and then copy_if_modified to xml dir
452    app.config.breathe_projects = {'esp32-idf': os.path.join(app.config.build_dir, 'xml_in/')}
453    app.config.breathe_default_project = 'esp32-idf'
454
455    setup_diag_font(app)
456
457    # Config values pushed by -D using the cmdline is not available when setup is called
458    app.connect('config-inited',  setup_config_values)
459    app.connect('config-inited',  setup_html_context)
460
461
462def setup_config_values(app, config):
463    # Sets up global config values needed by other extensions
464    idf_target_title_dict = {
465        'esp32': 'ESP32',
466        'esp32s2': 'ESP32-S2',
467        'esp32c3': 'ESP32-C3'
468    }
469
470    app.add_config_value('idf_target_title_dict', idf_target_title_dict, 'env')
471
472    pdf_name = 'esp-idf-{}-{}-{}'.format(app.config.language, app.config.version, app.config.idf_target)
473    app.add_config_value('pdf_file', pdf_name, 'env')
474
475
476def setup_html_context(app, config):
477    # Setup path for 'edit on github'-link
478    config.html_context['conf_py_path'] = '/docs/{}/'.format(app.config.language)
479
480
481def setup_diag_font(app):
482    # blockdiag and other tools require a font which supports their character set
483    # the font file is stored on the download server to save repo size
484
485    font_name = {
486        'en': 'DejaVuSans.ttf',
487        'zh_CN': 'NotoSansSC-Regular.otf',
488    }[app.config.language]
489
490    font_dir = os.path.join(config_dir, '_static')
491    assert os.path.exists(font_dir)
492
493    print('Downloading font file %s for %s' % (font_name, app.config.language))
494    download_file_if_missing('https://dl.espressif.com/dl/esp-idf/docs/_static/{}'.format(font_name), font_dir)
495
496    font_path = os.path.abspath(os.path.join(font_dir, font_name))
497    assert os.path.exists(font_path)
498
499    app.config.blockdiag_fontpath = font_path
500    app.config.seqdiag_fontpath = font_path
501    app.config.actdiag_fontpath = font_path
502    app.config.nwdiag_fontpath = font_path
503    app.config.rackdiag_fontpath = font_path
504    app.config.packetdiag_fontpath = font_path
505