Skip to content

Commit 5b00eba

Browse files
committed
Provide selection between A0 and VCC (#443, #338)
1 parent 50d56f8 commit 5b00eba

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

README.md

+10
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,16 @@ Several APIs may be used to get flash chip info:
169169

170170
```ESP.getCycleCount()``` returns the cpu instruction cycle count since start as an unsigned 32-bit. This is useful for accurate timing of very short actions like bit banging.
171171

172+
```ESP.getVcc()``` may be used to measure supply voltage. ESP needs to reconfigure the ADC
173+
at startup in order for this feature to be available. Add the following line to the top
174+
of your sketch to use ```getVcc```:
175+
```
176+
ADC_MODE(ADC_VCC);
177+
```
178+
TOUT pin has to be disconnected in this mode.
179+
180+
Note that by default ADC is configured to read from TOUT pin using ```analogRead(A0)```, and
181+
```ESP.getVCC()``` is not available.
172182

173183
#### OneWire (from https://www.pjrc.com/teensy/td_libs_OneWire.html) ####
174184

hardware/esp8266com/esp8266/cores/esp8266/Esp.h

+9
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,15 @@ enum RFMode {
6161
#define WAKE_NO_RFCAL RF_NO_CAL
6262
#define WAKE_RF_DISABLED RF_DISABLED
6363

64+
enum ADCMode {
65+
ADC_TOUT = 33,
66+
ADC_TOUT_3V3 = 33,
67+
ADC_VCC = 255,
68+
ADC_VDD = 255
69+
};
70+
71+
#define ADC_MODE(mode) extern "C" int __get_adc_mode() { return (int) (mode); }
72+
6473
typedef enum {
6574
FM_QIO = 0x00,
6675
FM_QOUT = 0x01,

hardware/esp8266com/esp8266/cores/esp8266/core_esp8266_phy.c

+6-1
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ static uint8_t phy_init_data[128] =
224224

225225
extern int __real_register_chipv6_phy(uint8_t* init_data);
226226
extern int __wrap_register_chipv6_phy(uint8_t* unused) {
227+
phy_init_data[107] = __get_adc_mode();
227228
return __real_register_chipv6_phy(phy_init_data);
228229
}
229230

@@ -243,6 +244,10 @@ extern int __get_rf_mode()
243244
return 0; // default mode
244245
}
245246

246-
247+
extern int __get_adc_mode() __attribute__((weak));
248+
extern int __get_adc_mode()
249+
{
250+
return 33; // default ADC mode
251+
}
247252

248253

0 commit comments

Comments
 (0)