Skip to content

Commit 09bb758

Browse files
ficetoficeto
ficeto
authored and
ficeto
committed
better analogRead
1 parent fbd86a2 commit 09bb758

File tree

1 file changed

+3
-24
lines changed

1 file changed

+3
-24
lines changed

hardware/esp8266com/esp8266/cores/esp8266/core_esp8266_wiring_analog.c

+3-24
Original file line numberDiff line numberDiff line change
@@ -21,34 +21,13 @@
2121
#include "wiring_private.h"
2222
#include "pins_arduino.h"
2323

24+
extern uint16_t readvdd33(void);
25+
2426
void analogReference(uint8_t mode) {}
2527

2628
extern int __analogRead(uint8_t pin) {
2729
if(pin == 17){
28-
//return system_adc_read();
29-
uint8_t i;
30-
uint16_t data[8];
31-
32-
rom_i2c_writeReg_Mask(0x6C,2,0,5,5,1);
33-
34-
ESP8266_REG(0xD5C) |= (1 << 21);
35-
while ((ESP8266_REG(0xD50) & (7 << 24)) > 0);
36-
ESP8266_REG(0xD50) &= ~(1 << 1);
37-
ESP8266_REG(0xD50) |= (1 << 1);
38-
delayMicroseconds(2);
39-
while ((ESP8266_REG(0xD50) & (7 << 24)) > 0);
40-
41-
read_sar_dout(data);
42-
rom_i2c_writeReg_Mask(0x6C,2,0,5,5,1);
43-
44-
while ((ESP8266_REG(0xD50) & (7 << 24)) > 0);
45-
ESP8266_REG(0xD5C) &= ~(1 << 21);
46-
ESP8266_REG(0xD60) |= (1 << 0);
47-
ESP8266_REG(0xD60) &= ~(1 << 0);
48-
49-
uint16_t tout = 0;
50-
for (i = 0; i < 8; i++) tout += data[i];
51-
return tout >> 4;//tout is 10 bits fraction
30+
return readvdd33() >> 2; // readvdd33 is 12 bit
5231
}
5332
return digitalRead(pin) * 1023;
5433
}

0 commit comments

Comments
 (0)