Skip to content

Commit

Permalink
Provide selection between A0 and VCC (esp8266#443, esp8266#338)
Browse files Browse the repository at this point in the history
  • Loading branch information
igrr committed Jun 24, 2015
1 parent 9f67167 commit 9dce0c4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,16 @@ Several APIs may be used to get flash chip info:

```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.

```ESP.getVcc()``` may be used to measure supply voltage. ESP needs to reconfigure the ADC
at startup in order for this feature to be available. Add the following line to the top
of your sketch to use ```getVcc```:
```
ADC_MODE(ADC_VCC);
```
TOUT pin has to be disconnected in this mode.

Note that by default ADC is configured to read from TOUT pin using ```analogRead(A0)```, and
```ESP.getVCC()``` is not available.

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

Expand Down
9 changes: 9 additions & 0 deletions cores/esp8266/Esp.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@ enum RFMode {
#define WAKE_NO_RFCAL RF_NO_CAL
#define WAKE_RF_DISABLED RF_DISABLED

enum ADCMode {
ADC_TOUT = 33,
ADC_TOUT_3V3 = 33,
ADC_VCC = 255,
ADC_VDD = 255
};

#define ADC_MODE(mode) extern "C" int __get_adc_mode() { return (int) (mode); }

typedef enum {
FM_QIO = 0x00,
FM_QOUT = 0x01,
Expand Down
7 changes: 6 additions & 1 deletion cores/esp8266/core_esp8266_phy.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ static uint8_t phy_init_data[128] =

extern int __real_register_chipv6_phy(uint8_t* init_data);
extern int __wrap_register_chipv6_phy(uint8_t* unused) {
phy_init_data[107] = __get_adc_mode();
return __real_register_chipv6_phy(phy_init_data);
}

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


extern int __get_adc_mode() __attribute__((weak));
extern int __get_adc_mode()
{
return 33; // default ADC mode
}


0 comments on commit 9dce0c4

Please sign in to comment.