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