1# Copyright 2015-2021 Espressif Systems (Shanghai) CO LTD
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#     http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14#
15# This file contains values (e.g. delay time, ...) that are different for each chip for a particular action.
16# If adding a new device, set only values that are different from the default, e.g.:
17#                                       'esp32s2': {
18#                                               0: {
19#                                                   'reset': 0.35,
20#                                               }
21#                                           },
22#
23# for more information see the method "handle_commands" in idf_monitor.py
24
25
26conf = {
27    # the default values were previously hardcoded in idf_monitor.py (taken from esptool.py)
28    'default': {
29        0: {
30            'reset': 0.2,
31            'enter_boot_set': 0.1,
32            'enter_boot_unset': 0.05,
33        }
34    },
35    'esp32': {
36        0: {
37            'reset': 0.2,
38            'enter_boot_set': 1.3,
39            'enter_boot_unset': 0.45,
40        },
41        1: {
42            'reset': 0.2,
43            'enter_boot_set': 0.1,
44            'enter_boot_unset': 0.05,
45        }
46    },
47
48}
49
50
51def get_chip_config(chip, revision=0):
52    # type: (str, int) -> dict
53
54    # If the config is not set in the `conf` dict for a specific chip, the `default` will be used.
55    # In case if only some values are specified, others are used from the `default`.
56    # If chip is set in `conf` but the specific revision R is missing,
57    # the values from highest revision lower than R are used.
58    # If some fields are missing, they will be taken from next lower revision or from the `default`.
59    default = dict(conf['default'][0])
60    rev_number = int(revision)
61    if chip not in conf.keys():
62        return default
63    chip_revisions = sorted(list(conf[chip].keys()), key=int)
64    for rev in chip_revisions:
65        if int(rev) > rev_number:
66            break
67        for key in conf[chip][rev].keys():
68            default[key] = conf[chip][rev][key]
69
70    return default
71