1
+ // Copyright 2018-2025 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
+
16
+ #include <stdio.h>
17
+ #include <stdint.h>
18
+
19
+ #include "esp_attr.h"
20
+ #include "esp_err.h"
21
+ #include "esp_log.h"
22
+
23
+ #include "driver/adc.h"
24
+
25
+ #define ENTER_CRITICAL () portENTER_CRITICAL()
26
+ #define EXIT_CRITICAL () portEXIT_CRITICAL()
27
+
28
+ static const char * TAG = "adc" ;
29
+
30
+ #define ADC_CHECK (a , str , ret_val ) \
31
+ if (!(a)) { \
32
+ ESP_LOGE(TAG,"%s(%d): %s", __FUNCTION__, __LINE__, str); \
33
+ return (ret_val); \
34
+ }
35
+
36
+ extern uint16_t test_tout ();
37
+ extern void phy_adc_read_fast (uint16_t * adc_addr , uint16_t adc_num , uint8_t adc_clk_div );
38
+ extern uint16_t phy_get_vdd33 ();
39
+
40
+ uint16_t adc_read ()
41
+ {
42
+ uint16_t ret = test_tout (0 );
43
+
44
+ if (ret != 0xFFFF ) {
45
+ // The working voltage of ADC is designed according to 1.1v. Later, the actual working voltage of ADC is increased to 1.2v, so this scale is added.
46
+ ret = ret * 12 / 11 ;
47
+
48
+ if (ret > 1023 ) {
49
+ // 10-bit precision ADC
50
+ ret = 1023 ;
51
+ }
52
+ }
53
+
54
+ return ret ;
55
+ }
0 commit comments