Skip to content

Commit ed02e83

Browse files
committed
Merge branch 'feature/add_adc_interface' into 'master'
feature(adc): add adc interface See merge request sdk/ESP8266_RTOS_SDK!681
2 parents b78277d + bc0700a commit ed02e83

File tree

2 files changed

+89
-0
lines changed

2 files changed

+89
-0
lines changed

components/esp8266/driver/adc.c

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
#pragma once
16+
17+
#include <stdint.h>
18+
#include "esp_err.h"
19+
20+
#ifdef __cplusplus
21+
extern "C" {
22+
#endif
23+
24+
25+
/**
26+
* @brief Measure the input voltage of TOUT pin 6, unit : 1/1023 V.
27+
*
28+
* @return Input voltage of TOUT pin 6, unit : 1/1023 V
29+
*/
30+
uint16_t adc_read();
31+
32+
#ifdef __cplusplus
33+
}
34+
#endif

0 commit comments

Comments
 (0)