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