1 // Copyright 2017-2018 Espressif Systems (Shanghai) PTE 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 #pragma once
16 
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20 
21 #include <stdbool.h>
22 #include <stdint.h>
23 #include "esp_err.h"
24 #include "sdkconfig.h"
25 
26 #define RTCCALIB_ESP32S2_ADCCOUNT 2
27 #define RTCCALIB_ESP32S2_ATTENCOUNT 4
28 
29 #define RTCCALIB_V1_PARAM_VLOW 0
30 #define RTCCALIB_V1_PARAM_VHIGH 1
31 #define RTCCALIB_V2_PARAM_VHIGH 0
32 #define RTCCALIB_V2_PARAM_VINIT 1
33 
34 // these are the tags. Either use them directly or use esp_efuse_rtc_table_get_tag to calculate
35 // the corresponding tag.
36 #define RTCCALIB_V1IDX_A10L 1
37 #define RTCCALIB_V1IDX_A11L 2
38 #define RTCCALIB_V1IDX_A12L 3
39 #define RTCCALIB_V1IDX_A13L 4
40 #define RTCCALIB_V1IDX_A20L 5
41 #define RTCCALIB_V1IDX_A21L 6
42 #define RTCCALIB_V1IDX_A22L 7
43 #define RTCCALIB_V1IDX_A23L 8
44 #define RTCCALIB_V1IDX_A10H 9
45 #define RTCCALIB_V1IDX_A11H 10
46 #define RTCCALIB_V1IDX_A12H 11
47 #define RTCCALIB_V1IDX_A13H 12
48 #define RTCCALIB_V1IDX_A20H 13
49 #define RTCCALIB_V1IDX_A21H 14
50 #define RTCCALIB_V1IDX_A22H 15
51 #define RTCCALIB_V1IDX_A23H 16
52 #define RTCCALIB_V2IDX_A10H 17
53 #define RTCCALIB_V2IDX_A11H 18
54 #define RTCCALIB_V2IDX_A12H 19
55 #define RTCCALIB_V2IDX_A13H 20
56 #define RTCCALIB_V2IDX_A20H 21
57 #define RTCCALIB_V2IDX_A21H 22
58 #define RTCCALIB_V2IDX_A22H 23
59 #define RTCCALIB_V2IDX_A23H 24
60 #define RTCCALIB_V2IDX_A10I 25
61 #define RTCCALIB_V2IDX_A11I 26
62 #define RTCCALIB_V2IDX_A12I 27
63 #define RTCCALIB_V2IDX_A13I 28
64 #define RTCCALIB_V2IDX_A20I 29
65 #define RTCCALIB_V2IDX_A21I 30
66 #define RTCCALIB_V2IDX_A22I 31
67 #define RTCCALIB_V2IDX_A23I 32
68 #define RTCCALIB_IDX_TMPSENSOR 33
69 
70 /**
71  * @brief Get rtc calibration version.
72  */
73 int esp_efuse_rtc_table_read_calib_version(void);
74 
75 /**
76  * @brief Helper function to calculate a tag from human-readable parameters.
77  * Tag is used to index the desired data from the efuse.
78  * For example, (1, 1, 3, 1) yields the tag RTCCALIB_V1IDX_A13H
79  * extra params are used for identification when a adc_num-atten combination has
80  * multiple efuse values.
81  * @param adc_channel_num verbatim numbering of the ADC channel. For channel 1, use 1 and not 0.
82  * @param atten attenuation. use the enum value.
83  * @param version the version of the scheme to index for.
84  * @param extra_params defined differently for each version.
85  * */
86 int esp_efuse_rtc_table_get_tag(int version, int adc_channel_num, int atten, int extra_params);
87 
88 /**
89  * @brief Fetches a raw value from efuse and does signed bit parsing
90  * @param tag tag obtained with esp_efuse_rtc_table_get_tag
91  *
92  * */
93 int esp_efuse_rtc_table_get_raw_efuse_value(int tag);
94 
95 /**
96  * @brief Fetches a raw value from efuse and resolve it to get
97  * the original number that it meant to represent.
98  *
99  * @param tag tag obtained with esp_efuse_rtc_table_get_tag
100  * @param use_zero_inputs Does not perform the raw value fetching before resolving the number,
101  * but proceed as if all zeros were read from efuse.
102  *
103  * */
104 int esp_efuse_rtc_table_get_parsed_efuse_value(int tag, bool skip_efuse_reading);
105 
106 #ifdef __cplusplus
107 }
108 #endif
109