From 09bb75874deb95c22b4c09e63b842fc1f89eebc3 Mon Sep 17 00:00:00 2001 From: ficeto Date: Tue, 19 May 2015 15:30:46 +0300 Subject: [PATCH] better analogRead --- .../esp8266/core_esp8266_wiring_analog.c | 27 +++---------------- 1 file changed, 3 insertions(+), 24 deletions(-) diff --git a/hardware/esp8266com/esp8266/cores/esp8266/core_esp8266_wiring_analog.c b/hardware/esp8266com/esp8266/cores/esp8266/core_esp8266_wiring_analog.c index bb51510187..53451b7134 100644 --- a/hardware/esp8266com/esp8266/cores/esp8266/core_esp8266_wiring_analog.c +++ b/hardware/esp8266com/esp8266/cores/esp8266/core_esp8266_wiring_analog.c @@ -21,34 +21,13 @@ #include "wiring_private.h" #include "pins_arduino.h" +extern uint16_t readvdd33(void); + void analogReference(uint8_t mode) {} extern int __analogRead(uint8_t pin) { if(pin == 17){ - //return system_adc_read(); - uint8_t i; - uint16_t data[8]; - - rom_i2c_writeReg_Mask(0x6C,2,0,5,5,1); - - ESP8266_REG(0xD5C) |= (1 << 21); - while ((ESP8266_REG(0xD50) & (7 << 24)) > 0); - ESP8266_REG(0xD50) &= ~(1 << 1); - ESP8266_REG(0xD50) |= (1 << 1); - delayMicroseconds(2); - while ((ESP8266_REG(0xD50) & (7 << 24)) > 0); - - read_sar_dout(data); - rom_i2c_writeReg_Mask(0x6C,2,0,5,5,1); - - while ((ESP8266_REG(0xD50) & (7 << 24)) > 0); - ESP8266_REG(0xD5C) &= ~(1 << 21); - ESP8266_REG(0xD60) |= (1 << 0); - ESP8266_REG(0xD60) &= ~(1 << 0); - - uint16_t tout = 0; - for (i = 0; i < 8; i++) tout += data[i]; - return tout >> 4;//tout is 10 bits fraction + return readvdd33() >> 2; // readvdd33 is 12 bit } return digitalRead(pin) * 1023; }